From af81f8a91474ff3e8fddb6535114e74c97c4b8d1 Mon Sep 17 00:00:00 2001 From: ericwa Date: Fri, 29 Jan 2010 03:11:43 +0000 Subject: [PATCH] NSSegmentedCell themeing support git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@29435 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 11 +++++++ Headers/Additions/GNUstepGUI/GSTheme.h | 12 ++++++++ Headers/AppKit/NSSegmentedCell.h | 14 +++++++-- Headers/AppKit/NSSegmentedControl.h | 19 +++++++++++- Source/GSThemeDrawing.m | 17 +++++++++++ Source/NSSegmentedCell.m | 40 ++++++++++++++++++++++---- Source/NSSegmentedControl.m | 11 +++++++ 7 files changed, 115 insertions(+), 9 deletions(-) diff --git a/ChangeLog b/ChangeLog index 859f2405e..21c8f06c3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2010-01-28 Eric Wasylishen + + * Source/GSThemeDrawing.m: + * Source/NSSegmentedCell.m: + * Source/NSSegmentedControl.m: + * Headers/AppKit/NSSegmentedCell.h: + * Headers/AppKit/NSSegmentedControl.h: + * Headers/Additions/GNUstepGUI/GSTheme.h: + Add GSTheme method for NSSegmentedCell drawing. + Implemented segmentStyle and setSegmentStyle: methods. + 2010-01-28 Eric Wasylishen * Source/NSButtonCell.m -isOpaque: Return NO if the button cell has a diff --git a/Headers/Additions/GNUstepGUI/GSTheme.h b/Headers/Additions/GNUstepGUI/GSTheme.h index aa81b8a5e..bd2ce6c72 100644 --- a/Headers/Additions/GNUstepGUI/GSTheme.h +++ b/Headers/Additions/GNUstepGUI/GSTheme.h @@ -224,6 +224,8 @@ #include // For scroller constants #include +// For segmented control style constants +#include #if OS_API_VERSION(GS_API_NONE,GS_API_NONE) @class NSArray; @@ -823,6 +825,16 @@ APPKIT_EXPORT NSString *GSThemeWillDeactivateNotification; */ - (void) drawStepperHighlightDownButton: (NSRect)aRect; +// NSSegmentedControl drawing methods + +- (void) drawSegmentedControlSegment: (NSCell *)cell + withFrame: (NSRect)cellFrame + inView: (NSView *)controlView + style: (NSSegmentStyle)style + state: (GSThemeControlState)state + roundedLeft: (BOOL)roundedLeft + roundedRight: (BOOL)roundedRight; + /** * In some themes it may be necessary to override the drawing * of an image a button cell and replace it with a rendered diff --git a/Headers/AppKit/NSSegmentedCell.h b/Headers/AppKit/NSSegmentedCell.h index 7c513e51d..202b3ffc7 100644 --- a/Headers/AppKit/NSSegmentedCell.h +++ b/Headers/AppKit/NSSegmentedCell.h @@ -27,6 +27,7 @@ #define _GNUstep_H_NSSegmentedCell #include +#include // tracking types... typedef enum { @@ -52,9 +53,11 @@ typedef enum { unsigned int _tracking_mode:3; unsigned int _trimmed_labels:1; unsigned int _drawing:1; - unsigned int _style:1; + unsigned int unused1:2; unsigned int _recalcToolTips:1; - unsigned int unused:24; + unsigned int unused2:3; + unsigned int _style:8; + unsigned int unused3:13; } _segmentCellFlags; } @@ -95,5 +98,12 @@ typedef enum { - (void) drawSegment: (int)segment inFrame: (NSRect)frame withView: (NSView *)view; + +// Setting the style of the segments +#if OS_API_VERSION(GS_API_MACOSX, GS_API_LATEST) +- (void)setSegmentStyle:(NSSegmentStyle)style; +- (NSSegmentStyle)segmentStyle; +#endif + @end #endif diff --git a/Headers/AppKit/NSSegmentedControl.h b/Headers/AppKit/NSSegmentedControl.h index 39afce9e1..10c44358b 100644 --- a/Headers/AppKit/NSSegmentedControl.h +++ b/Headers/AppKit/NSSegmentedControl.h @@ -27,7 +27,18 @@ #define _GNUstep_H_NSSegmentedControl #include -#include + +#if OS_API_VERSION(GS_API_MACOSX, GS_API_LATEST) +typedef enum _NSSegmentStyle { + NSSegmentStyleAutomatic = 0, + NSSegmentStyleRounded = 1, + NSSegmentStyleTexturedRounded = 2, + NSSegmentStyleRoundRect = 3, + NSSegmentStyleTexturedSquare = 4, + NSSegmentStyleCapsule = 5, + NSSegmentStyleSmallSquare = 6 +} NSSegmentStyle; +#endif @interface NSSegmentedControl : NSControl @@ -54,5 +65,11 @@ - (void) setEnabled: (BOOL)flag forSegment: (int)segment; - (BOOL) isEnabledForSegment: (int)segment; +// Setting the style of the segments +#if OS_API_VERSION(GS_API_MACOSX, GS_API_LATEST) +- (void)setSegmentStyle:(NSSegmentStyle)style; +- (NSSegmentStyle)segmentStyle; +#endif + @end #endif diff --git a/Source/GSThemeDrawing.m b/Source/GSThemeDrawing.m index 2bc9a427f..5df6867a8 100644 --- a/Source/GSThemeDrawing.m +++ b/Source/GSThemeDrawing.m @@ -660,6 +660,23 @@ [self drawStepperDownButton: downRect]; } +// NSSegmentedControl drawing methods + +- (void) drawSegmentedControlSegment: (NSCell *)cell + withFrame: (NSRect)cellFrame + inView: (NSView *)controlView + style: (NSSegmentStyle)style + state: (GSThemeControlState)state + roundedLeft: (BOOL)roundedLeft + roundedRight: (BOOL)roundedRight +{ + [[GSTheme theme] drawButton: cellFrame + in: cell + view: controlView + style: NSRegularSquareBezelStyle + state: state]; +} + - (void) drawImage: (NSImage *)image inButtonCell: (NSButtonCell *) cell withFrame: (NSRect) aRect diff --git a/Source/NSSegmentedCell.m b/Source/NSSegmentedCell.m index 74c200d16..43237c939 100644 --- a/Source/NSSegmentedCell.m +++ b/Source/NSSegmentedCell.m @@ -545,6 +545,8 @@ NSRect textFrame = frame; float x_offset = (frame.size.width - textSize.width) / 2; GSThemeControlState state = GSThemeNormalState; + BOOL roundedLeft = NO; + BOOL roundedRight = NO; textFrame.origin.x += x_offset; textFrame.size.width -= x_offset; @@ -555,12 +557,19 @@ state = GSThemeSelectedState; } - [[GSTheme theme] drawButton: frame - in: self - view: [self controlView] - style: NSRegularSquareBezelStyle - state: state]; + if (seg == 0) + roundedLeft = YES; + if (seg == ([_items count] - 1)) + roundedRight = YES; + + [[GSTheme theme] drawSegmentedControlSegment: self + withFrame: frame + inView: [self controlView] + style: [self segmentStyle] + state: state + roundedLeft: roundedLeft + roundedRight: roundedRight]; [self _drawText: [segment label] inFrame: textFrame]; } @@ -587,6 +596,17 @@ } } +// Setting the style of the segments +- (void)setSegmentStyle:(NSSegmentStyle)style +{ + _segmentCellFlags._style = style; +} + +- (NSSegmentStyle)segmentStyle +{ + return _segmentCellFlags._style; +} + - (void) encodeWithCoder: (NSCoder*)aCoder { [super encodeWithCoder: aCoder]; @@ -596,11 +616,15 @@ [aCoder encodeObject: _items forKey: @"NSSegmentImages"]; if (_selected_segment != -1) [aCoder encodeInt: _selected_segment forKey: @"NSSelectedSegment"]; + [aCoder encodeInt: _segmentCellFlags._style forKey: @"NSSegmentStyle"]; } else { + int style; [aCoder encodeObject: _items]; [aCoder encodeValueOfObjCType: @encode(int) at: &_selected_segment]; + style = _segmentCellFlags._style; + [aCoder encodeValueOfObjCType: @encode(int) at: &style]; } } @@ -615,12 +639,16 @@ if ([aDecoder containsValueForKey: @"NSSegmentImages"]) ASSIGN(_items, [aDecoder decodeObjectForKey: @"NSSegmentImages"]); if ([aDecoder containsValueForKey: @"NSSelectedSegment"]) - _selected_segment = [aDecoder decodeIntForKey: @"NSSelectedSegment"]; + _selected_segment = [aDecoder decodeIntForKey: @"NSSelectedSegment"]; + _segmentCellFlags._style = [aDecoder decodeIntForKey: @"NSSegmentStyle"]; } else { + int style; ASSIGN(_items,[aDecoder decodeObject]); [aDecoder decodeValueOfObjCType: @encode(int) at: &_selected_segment]; + [aDecoder decodeValueOfObjCType: @encode(int) at: &style]; + _segmentCellFlags._style = style; } return self; } diff --git a/Source/NSSegmentedControl.m b/Source/NSSegmentedControl.m index 3d7112f2f..7205b7b40 100644 --- a/Source/NSSegmentedControl.m +++ b/Source/NSSegmentedControl.m @@ -25,6 +25,7 @@ #include #include +#include #include static Class segmentedControlCellClass; @@ -133,6 +134,16 @@ static Class segmentedControlCellClass; return [_cell isEnabledForSegment: segment]; } +- (void)setSegmentStyle:(NSSegmentStyle)style +{ + [_cell setSegmentStyle: style]; +} + +- (NSSegmentStyle)segmentStyle +{ + return [_cell segmentStyle]; +} + /* - (void) mouseDown: (NSEvent *)event {