diff --git a/ChangeLog b/ChangeLog index 2095c3117..398f55d34 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2011-10-28 Quentin Mathe + + * Headers/Additions/GNUstepGUI/GSTheme.h: + * Source/GSTheme.m: + * Source/GSThemeDrawing.m (-menuSeparatorItemColor, + -drawSeparatorItemForMenuItemCell:withFrame:inView:isHorizontal:): + * Source/NSMenuItemCell.m (-drawSeparatorItemWithFrame:inView:): + Made separator menu item themable, by moving the drawing code from + NSMenuItemCell to a new method in GSThemeDrawing. + 2011-10-27 Fred Kiefer * Source/NSBitmapImageRep.m (+imageRepWithData:): Add missing AUTORELEASE. diff --git a/Headers/Additions/GNUstepGUI/GSTheme.h b/Headers/Additions/GNUstepGUI/GSTheme.h index e16663167..56a616084 100644 --- a/Headers/Additions/GNUstepGUI/GSTheme.h +++ b/Headers/Additions/GNUstepGUI/GSTheme.h @@ -276,6 +276,7 @@ APPKIT_EXPORT NSString *GSMenuHorizontalBackground; APPKIT_EXPORT NSString *GSMenuVerticalBackground; APPKIT_EXPORT NSString *GSMenuHorizontalItem; APPKIT_EXPORT NSString *GSMenuVerticalItem; +APPKIT_EXPORT NSString *GSMenuSeparatorItem; /* * Progress Indicator part names. @@ -897,6 +898,34 @@ APPKIT_EXPORT NSString *GSThemeWillDeactivateNotification; inView: (NSView *)controlView state: (GSThemeControlState)state isHorizontal: (BOOL)isHorizontal; +/** + *

Returns the color used to draw a separator line in a menu.

+ * + *

By default, looks up the color named menuSeparatorItemColor, + * otherwise returns the black color.

+ * + *

The returned color is used by + * -drawSeparatorItemForMenuItemCell:withFrame:inView:isHorizontal:

+ * + *

Can be overriden in subclasses to return a custom color.

+ */ +- (NSColor *) menuSeparatorItemColor; +/** + *

Draws a separator between normal menu items in a menu.

+ * + *

Each separator corresponds to a menu item that returns YES to + * -isSeparatorItem

+ * + *

You can provide an image tile named GSMenuSeparatoritem to + * draw the separator.
+ * Can be overriden in subclasses to customize the drawing.

+ * + *

See also -menuSeparatorItemColor

+ */ +- (void) drawSeparatorItemForMenuItemCell: (NSMenuItemCell *)cell + withFrame: (NSRect)cellFrame + inView: (NSView *)controlView + isHorizontal: (BOOL)isHorizontal; /** * Returns the class used to create the title bar in the given menu view. * diff --git a/Source/GSTheme.m b/Source/GSTheme.m index fdd30f546..035efce35 100644 --- a/Source/GSTheme.m +++ b/Source/GSTheme.m @@ -86,6 +86,7 @@ NSString *GSMenuHorizontalBackground = @"GSMenuHorizontalBackground"; NSString *GSMenuVerticalBackground = @"GSMenuVerticalBackground"; NSString *GSMenuHorizontalItem = @"GSMenuHorizontalItem"; NSString *GSMenuVerticalItem = @"GSMenuVerticalItem"; +NSString *GSMenuSeparatorItem = @"GSMenuSeparatorItem"; // Progress indicator part names NSString *GSProgressIndicatorBarDeterminate diff --git a/Source/GSThemeDrawing.m b/Source/GSThemeDrawing.m index 6c5234e5c..a15d6f421 100644 --- a/Source/GSThemeDrawing.m +++ b/Source/GSThemeDrawing.m @@ -908,6 +908,52 @@ } } +- (NSColor *) menuSeparatorItemColor +{ + NSColor *color = [self colorNamed: @"menuSeparatorItemColor" + state: GSThemeNormalState]; + if (color == nil) + { + color = [NSColor blackColor]; + } + return color; +} + +- (void) drawSeparatorItemForMenuItemCell: (NSMenuItemCell *)cell + withFrame: (NSRect)cellFrame + inView: (NSView *)controlView + isHorizontal: (BOOL)isHorizontal +{ + GSDrawTiles *tiles = [self tilesNamed: GSMenuSeparatorItem state: GSThemeNormalState]; + + if (tiles == nil) + { + NSInterfaceStyle style = NSInterfaceStyleForKey(@"NSMenuInterfaceStyle", nil); + + if (style == NSMacintoshInterfaceStyle || style == NSWindows95InterfaceStyle) + { + NSBezierPath *path = [NSBezierPath bezierPath]; + NSPoint start = NSMakePoint(3, cellFrame.size.height / 2 + + cellFrame.origin.y); + NSPoint end = NSMakePoint(cellFrame.size.width - 3, + cellFrame.size.height / 2 + cellFrame.origin.y); + + [[NSColor blackColor] set]; + + [path moveToPoint: start]; + [path lineToPoint: end]; + + [path stroke]; + } + } + else + { + [self fillRect: cellFrame + withTiles: tiles + background: [NSColor clearColor]]; + } +} + - (Class) titleViewClassForMenuView: (NSMenuView *)aMenuView { return [GSTitleView class]; diff --git a/Source/NSMenuItemCell.m b/Source/NSMenuItemCell.m index 963224a74..eac650b4a 100644 --- a/Source/NSMenuItemCell.m +++ b/Source/NSMenuItemCell.m @@ -753,34 +753,10 @@ static NSString *commandKeyString = @"#"; - (void) drawSeparatorItemWithFrame:(NSRect)cellFrame inView:(NSView *)controlView { - NSInterfaceStyle style = NSInterfaceStyleForKey(@"NSMenuInterfaceStyle", nil); - if (style == NSMacintoshInterfaceStyle - || style == NSWindows95InterfaceStyle) - { - NSBezierPath *path = [NSBezierPath bezierPath]; - NSPoint start = NSMakePoint(3, cellFrame.size.height/2 + - cellFrame.origin.y); - NSPoint end = NSMakePoint(cellFrame.size.width - 3, - cellFrame.size.height/2 + - cellFrame.origin.y); - - [[NSColor blackColor] set]; - - [path moveToPoint: start]; - [path lineToPoint: end]; - - [path stroke]; - /* - NSRect lineFrame = NSMakeRect(cellFrame.origin.x, - cellFrame.origin.y - + cellFrame.size.height/2, - cellFrame.size.width, - 1); - NSBox *line = [[NSBox alloc] initWithFrame: lineFrame]; - [controlView addSubview:line]; - RELEASE(line); - */ - } + [[GSTheme theme] drawSeparatorItemForMenuItemCell: self + withFrame: cellFrame + inView: controlView + isHorizontal: [_menuView isHorizontal]]; } - (void) drawStateImageWithFrame: (NSRect)cellFrame