diff --git a/ChangeLog b/ChangeLog index 2304474ae..205ae8679 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2009-11-09 Fred Kiefer + + * Source/NSControl.m, + * Headers/AppKit/NSStepper.h, + * Headers/AppKit/NSStepperCell.h, + * Source/NSStepper.m: White space changes and cleanup. + * Source/NSStepperCell.m, + * Headers/Additions/GNUstepGUI/GSTheme.h, + * Source/GSThemeDrawing.m: Move stepper drawing code into GSTheme. + 2009-11-09 Richard Frith-Macdonald * Source/NSScroller.m: make offset of buttons inside scroller adjustable diff --git a/Headers/Additions/GNUstepGUI/GSTheme.h b/Headers/Additions/GNUstepGUI/GSTheme.h index 4a031b4af..2478ed6ff 100644 --- a/Headers/Additions/GNUstepGUI/GSTheme.h +++ b/Headers/Additions/GNUstepGUI/GSTheme.h @@ -652,26 +652,40 @@ APPKIT_EXPORT NSString *GSThemeWillDeactivateNotification; - (BOOL) toolbarIsOpaque; // Methods to deal with steppers.. +/** + * Draw a stepper cell + */ +- (void) drawStepperCell: (NSCell*)cell + withFrame: (NSRect)cellFrame + inView: (NSView*)controlView + highlightUp: (BOOL)highlightUp + highlightDown: (BOOL)highlightDown; + +// Stepper cell helper methods +- (NSRect) stepperUpButtonRectWithFrame: (NSRect)frame; +- (NSRect) stepperDownButtonRectWithFrame: (NSRect)frame; +- (void) drawStepperBorder: (NSRect)frame; + /** * Draw light colored stepper using the border and clip rects */ -- (NSRect) drawStepperLightButton: (NSRect) border :(NSRect) clip; +- (NSRect) drawStepperLightButton: (NSRect)border : (NSRect)clip; /** * Draw normal stepper up button. */ -- (void) drawStepperUpButton: (NSRect) aRect; +- (void) drawStepperUpButton: (NSRect)aRect; /** * Draw highlighted up stepper button. */ -- (void) drawStepperHighlightUpButton: (NSRect) aRect; +- (void) drawStepperHighlightUpButton: (NSRect)aRect; /** * Draw down button for stepper */ -- (void) drawStepperDownButton: (NSRect) aRect; +- (void) drawStepperDownButton: (NSRect)aRect; /** * Draw highlighted stepper down button */ -- (void) drawStepperHighlightDownButton: (NSRect) aRect; +- (void) drawStepperHighlightDownButton: (NSRect)aRect; /** * In some themes it may be necessary to override the drawing diff --git a/Headers/AppKit/NSStepper.h b/Headers/AppKit/NSStepper.h index fb2dcbc62..7d3a54e96 100644 --- a/Headers/AppKit/NSStepper.h +++ b/Headers/AppKit/NSStepper.h @@ -30,18 +30,18 @@ #ifndef _GNUstep_H_NSStepper #define _GNUstep_H_NSStepper -#include +#import @interface NSStepper : NSControl { // Attributes } -- (double) maxValue; -- (void) setMaxValue: (double)maxValue; -- (double) minValue; -- (void) setMinValue: (double)minValue; -- (double) increment; -- (void) setIncrement: (double)increment; +- (double)maxValue; +- (void)setMaxValue: (double)maxValue; +- (double)minValue; +- (void)setMinValue: (double)minValue; +- (double)increment; +- (void)setIncrement: (double)increment; - (BOOL)autorepeat; - (void)setAutorepeat: (BOOL)autorepeat; diff --git a/Headers/AppKit/NSStepperCell.h b/Headers/AppKit/NSStepperCell.h index 3803d92ba..896ceb7a4 100644 --- a/Headers/AppKit/NSStepperCell.h +++ b/Headers/AppKit/NSStepperCell.h @@ -28,7 +28,7 @@ #ifndef _GNUstep_H_NSStepperCell #define _GNUstep_H_NSStepperCell -#include +#import @interface NSStepperCell : NSActionCell { diff --git a/Source/GSThemeDrawing.m b/Source/GSThemeDrawing.m index ab5af6b16..69b870301 100644 --- a/Source/GSThemeDrawing.m +++ b/Source/GSThemeDrawing.m @@ -483,7 +483,50 @@ } } -- (NSRect) drawStepperLightButton: (NSRect) border :(NSRect) clip +// NSStepperCell drawing +// Hard coded values for button sizes +#define STEPPER_WIDTH 15 +#define STEPPER_HEIGHT 11 + +- (NSRect) stepperUpButtonRectWithFrame: (NSRect)frame +{ + NSRect upRect; + + upRect.size.width = STEPPER_WIDTH; + upRect.size.height = STEPPER_HEIGHT; + upRect.origin.x = NSMaxX(frame) - STEPPER_WIDTH - 1; + upRect.origin.y = NSMinY(frame) + ((int)frame.size.height / 2) + 1; + return upRect; +} + +- (NSRect) stepperDownButtonRectWithFrame: (NSRect)frame +{ + NSRect downRect; + + downRect.size.width = STEPPER_WIDTH; + downRect.size.height = STEPPER_HEIGHT; + downRect.origin.x = NSMaxX(frame) - STEPPER_WIDTH - 1; + downRect.origin.y = NSMinY(frame) + ((int)frame.size.height / 2) - STEPPER_HEIGHT + 1; + return downRect; +} + +- (void) drawStepperBorder: (NSRect)frame +{ + NSRectEdge up_sides[] = {NSMaxXEdge, NSMinYEdge}; + NSColor *black = [NSColor controlDarkShadowColor]; + NSColor *grays[] = {black, black}; + NSRect twoButtons; + + twoButtons.origin.x = NSMaxX(frame) - STEPPER_WIDTH - 1; + twoButtons.origin.y = NSMinY(frame) + ((int)frame.size.height / 2) - STEPPER_HEIGHT; + twoButtons.size.width = STEPPER_WIDTH + 1; + twoButtons.size.height = 2 * STEPPER_HEIGHT + 1; + + NSDrawColorTiledRects(twoButtons, NSZeroRect, + up_sides, grays, 2); +} + +- (NSRect) drawStepperLightButton: (NSRect)border : (NSRect)clip { /* NSRect highlightRect = NSInsetRect(border, 1., 1.); @@ -509,9 +552,9 @@ } } -- (void) drawStepperUpButton: (NSRect) aRect +- (void) drawStepperUpButton: (NSRect)aRect { - NSRect unHighlightRect = [self drawStepperLightButton: aRect :NSZeroRect]; + NSRect unHighlightRect = [self drawStepperLightButton: aRect : NSZeroRect]; [[NSColor controlBackgroundColor] set]; NSRectFill(unHighlightRect); @@ -530,9 +573,9 @@ PSstroke(); } -- (void) drawStepperHighlightUpButton: (NSRect) aRect +- (void) drawStepperHighlightUpButton: (NSRect)aRect { - NSRect highlightRect = [self drawStepperLightButton: aRect :NSZeroRect]; + NSRect highlightRect = [self drawStepperLightButton: aRect : NSZeroRect]; [[NSColor selectedControlColor] set]; NSRectFill(highlightRect); @@ -551,9 +594,9 @@ PSstroke(); } -- (void) drawStepperDownButton: (NSRect) aRect +- (void) drawStepperDownButton: (NSRect)aRect { - NSRect unHighlightRect = [self drawStepperLightButton: aRect :NSZeroRect]; + NSRect unHighlightRect = [self drawStepperLightButton: aRect : NSZeroRect]; [[NSColor controlBackgroundColor] set]; NSRectFill(unHighlightRect); @@ -572,9 +615,9 @@ PSstroke(); } -- (void) drawStepperHighlightDownButton: (NSRect) aRect +- (void) drawStepperHighlightDownButton: (NSRect)aRect { - NSRect highlightRect = [self drawStepperLightButton: aRect :NSZeroRect]; + NSRect highlightRect = [self drawStepperLightButton: aRect : NSZeroRect]; [[NSColor selectedControlColor] set]; NSRectFill(highlightRect); @@ -593,6 +636,31 @@ PSstroke(); } +- (void) drawStepperCell: (NSCell*)cell + withFrame: (NSRect)cellFrame + inView: (NSView*)controlView + highlightUp: (BOOL)highlightUp + highlightDown: (BOOL)highlightDown +{ + NSRect upRect; + NSRect downRect; + + [self drawStepperBorder: cellFrame]; + + upRect = [self stepperUpButtonRectWithFrame: cellFrame]; + downRect = [self stepperDownButtonRectWithFrame: cellFrame]; + + if (highlightUp) + [self drawStepperHighlightUpButton: upRect]; + else + [self drawStepperUpButton: upRect]; + + if (highlightDown) + [self drawStepperHighlightDownButton: downRect]; + else + [self drawStepperDownButton: downRect]; +} + - (void) drawImage: (NSImage *)image inButtonCell: (NSButtonCell *) cell withFrame: (NSRect) aRect diff --git a/Source/NSControl.m b/Source/NSControl.m index ef7de2109..d5b27475d 100644 --- a/Source/NSControl.m +++ b/Source/NSControl.m @@ -828,12 +828,12 @@ static NSNotificationCenter *nc; [_cell performClickWithFrame: [self bounds] inView: self]; } -- (BOOL)refusesFirstResponder +- (BOOL) refusesFirstResponder { return [[self selectedCell] refusesFirstResponder]; } -- (void)setRefusesFirstResponder:(BOOL)flag +- (void) setRefusesFirstResponder:(BOOL)flag { [[self selectedCell] setRefusesFirstResponder: flag]; } diff --git a/Source/NSStepper.m b/Source/NSStepper.m index 8d6567849..5814026a5 100644 --- a/Source/NSStepper.m +++ b/Source/NSStepper.m @@ -26,14 +26,9 @@ #include "config.h" -#include -#include -#include "AppKit/NSStepper.h" -#include "AppKit/NSControl.h" -#include "AppKit/NSEvent.h" -#include "AppKit/NSWindow.h" -#include "AppKit/NSApplication.h" -#include "AppKit/NSStepperCell.h" +#import "AppKit/NSStepper.h" +#import "AppKit/NSEvent.h" +#import "AppKit/NSStepperCell.h" // // class variables diff --git a/Source/NSStepperCell.m b/Source/NSStepperCell.m index 126fa73f8..de1563901 100644 --- a/Source/NSStepperCell.m +++ b/Source/NSStepperCell.m @@ -28,20 +28,13 @@ #include "config.h" -#include "AppKit/NSApplication.h" -#include "AppKit/NSColor.h" -#include "AppKit/NSControl.h" -#include "AppKit/NSEvent.h" -#include "AppKit/NSGraphics.h" -#include "AppKit/NSGraphicsContext.h" -#include "AppKit/NSStepperCell.h" -#include "AppKit/NSWindow.h" +#import "AppKit/NSApplication.h" +#import "AppKit/NSControl.h" +#import "AppKit/NSEvent.h" +#import "AppKit/NSStepperCell.h" +#import "AppKit/NSWindow.h" #include "GNUstepGUI/GSTheme.h" -// Hard coded values for button sizes -#define STEPPER_WIDTH 15 -#define STEPPER_HEIGHT 11 - @interface NSStepperCell (Private) - (void) _increment; - (void) _decrement; @@ -49,8 +42,6 @@ upButton: (BOOL)upButton withFrame: (NSRect)frame inView: (NSView*)controlView; -- (NSRect) upButtonRectWithFrame: (NSRect)frame; -- (NSRect) downButtonRectWithFrame: (NSRect)frame; @end @implementation NSStepperCell @@ -74,6 +65,8 @@ - (id) init { self = [super init]; + if (!self) + return nil; [self setIntValue: 0]; [self setAlignment: NSRightTextAlignment]; @@ -120,22 +113,22 @@ _increment = increment; } -- (BOOL)autorepeat +- (BOOL) autorepeat { return _autorepeat; } -- (void)setAutorepeat: (BOOL)autorepeat +- (void) setAutorepeat: (BOOL)autorepeat { _autorepeat = autorepeat; } -- (BOOL)valueWraps +- (BOOL) valueWraps { return _valueWraps; } -- (void)setValueWraps: (BOOL)valueWraps +- (void) setValueWraps: (BOOL)valueWraps { _valueWraps = valueWraps; } @@ -143,36 +136,11 @@ - (void) drawInteriorWithFrame: (NSRect)cellFrame inView: (NSView*)controlView { - NSRect upRect; - NSRect downRect; - NSRect twoButtons; - - upRect = [self upButtonRectWithFrame: cellFrame]; - downRect = [self downButtonRectWithFrame: cellFrame]; - - twoButtons = downRect; - twoButtons.origin.y--; - twoButtons.size.width++; - twoButtons.size.height = 2 * STEPPER_HEIGHT + 1; - - if (highlightUp) - [[GSTheme theme] drawStepperHighlightUpButton: upRect]; - else - [[GSTheme theme] drawStepperUpButton: upRect]; - - if (highlightDown) - [[GSTheme theme] drawStepperHighlightDownButton: downRect]; - else - [[GSTheme theme] drawStepperDownButton: downRect]; - - { - NSRectEdge up_sides[] = {NSMaxXEdge, NSMinYEdge}; - NSColor *black = [NSColor controlDarkShadowColor]; - NSColor *grays[] = {black, black}; - - NSDrawColorTiledRects(twoButtons, NSZeroRect, - up_sides, grays, 2); - } + [[GSTheme theme] drawStepperCell: self + withFrame: cellFrame + inView: controlView + highlightUp: highlightUp + highlightDown: highlightDown]; } - (void) getPeriodicDelay: (float*)delay interval: (float*)interval @@ -214,8 +182,8 @@ if ([theEvent type] != NSLeftMouseDown) return NO; - upRect = [self upButtonRectWithFrame: cellFrame]; - downRect = [self downButtonRectWithFrame: cellFrame]; + upRect = [[GSTheme theme] stepperUpButtonRectWithFrame: cellFrame]; + downRect = [[GSTheme theme] stepperDownButtonRectWithFrame: cellFrame]; // Did the mouse go down in the up or in the down part? if (NSMouseInRect(point, upRect, NO)) @@ -475,26 +443,4 @@ [controlView setNeedsDisplayInRect: frame]; } -- (NSRect) upButtonRectWithFrame: (NSRect)frame -{ - NSRect upRect; - - upRect.size.width = STEPPER_WIDTH; - upRect.size.height = STEPPER_HEIGHT; - upRect.origin.x = NSMaxX(frame) - STEPPER_WIDTH - 1; - upRect.origin.y = NSMinY(frame) + ((int)frame.size.height / 2) + 1; - return upRect; -} - -- (NSRect) downButtonRectWithFrame: (NSRect)frame -{ - NSRect downRect; - - downRect.size.width = STEPPER_WIDTH; - downRect.size.height = STEPPER_HEIGHT; - downRect.origin.x = NSMaxX(frame) - STEPPER_WIDTH - 1; - downRect.origin.y = NSMinY(frame) + ((int)frame.size.height / 2) - STEPPER_HEIGHT + 1; - return downRect; -} - @end