From c6a59d7c59b7043f939fcd0c53ed7d2b33925f8a Mon Sep 17 00:00:00 2001 From: Alexandre Wilhelm Date: Sun, 31 Mar 2013 23:31:02 -0700 Subject: [PATCH] Fixed: CPMenuBar theming Previously it wasn't possible to theme the main menu of the app. With this fix the user can either theme the main menu with the theming system or with the method +setMenuBarAttributes from CPMenu. --- AppKit/CPMenu/_CPMenuBarWindow.j | 8 ++- AppKit/CPMenuItem/_CPMenuItemMenuBarView.j | 81 ++++++++++++++++++---- AppKit/CPMenuItem/_CPMenuItemView.j | 30 ++++++++ AppKit/Themes/Aristo/ThemeDescriptors.j | 8 ++- AppKit/Themes/Aristo2/ThemeDescriptors.j | 4 +- 5 files changed, 111 insertions(+), 20 deletions(-) diff --git a/AppKit/CPMenu/_CPMenuBarWindow.j b/AppKit/CPMenu/_CPMenuBarWindow.j index f02011e7d..2c6c2bcaa 100644 --- a/AppKit/CPMenu/_CPMenuBarWindow.j +++ b/AppKit/CPMenu/_CPMenuBarWindow.j @@ -143,6 +143,7 @@ _textColor = aColor; [_menuItemViews makeObjectsPerformSelector:@selector(setTextColor:) withObject:_textColor]; + [_menuItemViews makeObjectsPerformSelector:@selector(setParentMenuTextColor:) withObject:_textColor]; } - (void)setTitleColor:(CPColor)aColor @@ -163,6 +164,7 @@ _textShadowColor = aColor; [_menuItemViews makeObjectsPerformSelector:@selector(setTextShadowColor:) withObject:_textShadowColor]; + [_menuItemViews makeObjectsPerformSelector:@selector(setParentMenuTextShadowColor:) withObject:_textShadowColor]; } - (void)setTitleShadowColor:(CPColor)aColor @@ -181,6 +183,8 @@ return; _highlightColor = aColor; + + [_menuItemViews makeObjectsPerformSelector:@selector(setParentMenuHighlightColor:) withObject:_highlightColor]; } - (void)setHighlightTextColor:(CPColor)aColor @@ -190,7 +194,7 @@ _highlightTextColor = aColor; -// [_menuItemViews makeObjectsPerformSelector:@selector(setActivateColor:) withObject:_highlightTextColor]; + [_menuItemViews makeObjectsPerformSelector:@selector(setParentMenuHighlightTextColor:) withObject:_highlightTextColor]; } - (void)setHighlightTextShadowColor:(CPColor)aColor @@ -200,7 +204,7 @@ _highlightTextShadowColor = aColor; -// [_menuItemViews makeObjectsPerformSelector:@selector(setActivateShadowColor:) withObject:_highlightTextShadowColor]; + [_menuItemViews makeObjectsPerformSelector:@selector(setParentMenuHighlightTextShadowColor:) withObject:_highlightTextShadowColor]; } - (void)setMenu:(CPMenu)aMenu diff --git a/AppKit/CPMenuItem/_CPMenuItemMenuBarView.j b/AppKit/CPMenuItem/_CPMenuItemMenuBarView.j index 06f997fb7..8d213511d 100644 --- a/AppKit/CPMenuItem/_CPMenuItemMenuBarView.j +++ b/AppKit/CPMenuItem/_CPMenuItemMenuBarView.j @@ -28,13 +28,18 @@ @implementation _CPMenuItemMenuBarView : CPView { + CPColor _highlightColor @accessors(property=highlightColor); + CPColor _textColor @accessors(property=textColor); + CPColor _textShadowColor @accessors(property=textShadowColor); + CPColor _highlightTextColor @accessors(property=highlightTextColor); + CPColor _highlightTextShadowColor @accessors(property=highlightTextShadowColor); + CPMenuItem _menuItem @accessors(property=menuItem); CPFont _font; - CPColor _textColor; - CPColor _textShadowColor; BOOL _isDirty; + BOOL _shouldHighlight; _CPImageAndTextView _imageAndTextView; } @@ -47,8 +52,6 @@ + (id)themeAttributes { return @{ - @"menu-item-selection-color": [CPNull null], - @"menu-item-text-shadow-color": [CPNull null], @"horizontal-margin": 9.0, @"submenu-indicator-margin": 3.0, @"vertical-margin": 4.0, @@ -81,12 +84,36 @@ return self; } +- (CPColor)setTextColor:(CPColor)aColor +{ + _textColor = aColor; + [self setNeedsLayout]; +} + +- (CPColor)setTextShadowColor:(CPColor)aColor +{ + _textShadowColor = aColor; + [self setNeedsLayout]; +} + +- (CPColor)setHighlightTextColor:(CPColor)aColor +{ + _highlightTextColor = aColor; + [self setNeedsLayout]; +} + +- (CPColor)setHighlightTextShadowColor:(CPColor)aColor +{ + _highlightTextShadowColor = aColor; + [self setNeedsLayout]; +} + - (CPColor)textColor { if (![_menuItem isEnabled]) return [CPColor lightGrayColor]; - return _textColor || [CPColor colorWithCalibratedRed:70.0 / 255.0 green:69.0 / 255.0 blue:69.0 / 255.0 alpha:1.0]; + return _textColor || [[CPTheme defaultTheme] valueForAttributeWithName:@"menu-bar-text-color" forClass:_CPMenuView]; } - (CPColor)textShadowColor @@ -94,7 +121,28 @@ if (![_menuItem isEnabled]) return [CPColor clearColor]; - return _textShadowColor || [CPColor colorWithWhite:1.0 alpha:0.8]; + return _textShadowColor || [[CPTheme defaultTheme] valueForAttributeWithName:@"menu-bar-text-shadow-color" forClass:_CPMenuView]; +} + +- (CPColor)highlightTextColor +{ + if (![_menuItem isEnabled]) + return [CPColor lightGrayColor]; + + return _highlightTextColor || [[CPTheme defaultTheme] valueForAttributeWithName:@"menu-bar-highlight-text-color" forClass:_CPMenuView]; +} + +- (CPColor)highlightTextShadowColor +{ + if (![_menuItem isEnabled]) + return [CPColor clearColor]; + + return _highlightTextShadowColor || [[CPTheme defaultTheme] valueForAttributeWithName:@"menu-bar-highlight-text-shadow-color" forClass:_CPMenuView]; +} + +- (CPColor)highlightColor +{ + return _highlightColor || [[CPTheme defaultTheme] valueForAttributeWithName:@"menu-bar-window-background-selected-color" forClass:_CPMenuView]; } - (void)update @@ -102,13 +150,11 @@ var x = [self valueForThemeAttribute:@"horizontal-margin"], height = 0.0; + [_imageAndTextView setText:[_menuItem title]]; [_imageAndTextView setFont:[_menuItem font] || [_CPMenuBarWindow font]]; [_imageAndTextView setVerticalAlignment:CPCenterVerticalTextAlignment]; - [_imageAndTextView setImage:[_menuItem image]]; - [_imageAndTextView setText:[_menuItem title]]; - [_imageAndTextView setTextColor:[self textColor]]; - [_imageAndTextView setTextShadowColor:[self textShadowColor]]; [_imageAndTextView setTextShadowOffset:CGSizeMake(0.0, 1.0)]; + [_imageAndTextView setImage:[_menuItem image]]; [_imageAndTextView sizeToFit]; var imageAndTextViewFrame = [_imageAndTextView frame]; @@ -123,6 +169,7 @@ [self setAutoresizesSubviews:NO]; [self setFrameSize:CGSizeMake(x + [self valueForThemeAttribute:@"horizontal-margin"], height)]; [self setAutoresizesSubviews:YES]; + [self setNeedsLayout]; } - (void)highlight:(BOOL)shouldHighlight @@ -131,14 +178,20 @@ if (![_menuItem isEnabled]) shouldHighlight = NO; - if (shouldHighlight) + _shouldHighlight = shouldHighlight; + [self setNeedsLayout]; +} + +- (void)layoutSubviews +{ + if (_shouldHighlight) { if (![_menuItem _isMenuBarButton]) - [self setBackgroundColor:[[CPTheme defaultTheme] valueForAttributeWithName:@"menu-bar-window-background-selected-color" forClass:_CPMenuView]]; + [self setBackgroundColor:[self highlightColor]]; [_imageAndTextView setImage:[_menuItem alternateImage] || [_menuItem image]]; - [_imageAndTextView setTextColor:[CPColor whiteColor]]; - [_imageAndTextView setTextShadowColor:[self valueForThemeAttribute:@"menu-item-text-shadow-color"]]; + [_imageAndTextView setTextColor:[self highlightTextColor]]; + [_imageAndTextView setTextShadowColor:[self highlightTextShadowColor]]; } else { diff --git a/AppKit/CPMenuItem/_CPMenuItemView.j b/AppKit/CPMenuItem/_CPMenuItemView.j index a0311b333..9dc244b44 100644 --- a/AppKit/CPMenuItem/_CPMenuItemView.j +++ b/AppKit/CPMenuItem/_CPMenuItemView.j @@ -220,6 +220,36 @@ return [_menuItem isEnabled] ? (_textShadowColor ? _textShadowColor : [CPColor colorWithWhite:1.0 alpha:0.8]) : [CPColor colorWithWhite:0.8 alpha:0.8]; } +- (void)setParentMenuHighlightColor:(CPColor)aColor +{ + if ([_view respondsToSelector:@selector(setHighlightColor:)]) + [_view setHighlightColor:aColor]; +} + +- (void)setParentMenuHighlightTextColor:(CPColor)aColor +{ + if ([_view respondsToSelector:@selector(setHighlightTextColor:)]) + [_view setHighlightTextColor:aColor]; +} + +- (void)setParentMenuHighlightTextShadowColor:(CPColor)aColor +{ + if ([_view respondsToSelector:@selector(setHighlightTextShadowColor:)]) + [_view setHighlightTextShadowColor:aColor]; +} + +- (void)setParentMenuTextColor:(CPColor)aColor +{ + if ([_view respondsToSelector:@selector(setTextColor:)]) + [_view setTextColor:aColor]; +} + +- (void)setParentMenuTextShadowColor:(CPColor)aColor +{ + if ([_view respondsToSelector:@selector(setTextShadowColor:)]) + [_view setTextShadowColor:aColor]; +} + @end @implementation _CPMenuItemArrowView : CPView diff --git a/AppKit/Themes/Aristo/ThemeDescriptors.j b/AppKit/Themes/Aristo/ThemeDescriptors.j index 8f8771bbc..43f949628 100755 --- a/AppKit/Themes/Aristo/ThemeDescriptors.j +++ b/AppKit/Themes/Aristo/ThemeDescriptors.j @@ -2585,8 +2585,12 @@ var themedButtonValues = nil, themeValues = [ - [@"menu-item-selection-color", [CPColor colorWithHexString:@"5C85D8"]], - [@"menu-item-text-shadow-color", [CPColor colorWithCalibratedRed:26.0 / 255.0 green: 73.0 / 255.0 blue:109.0 / 255.0 alpha:1.0]], + // [@"menu-item-text-color", [CPColor colorWithRed:0.051 green:0.2 blue:0.275 alpha:1.0]], + // [@"menu-item-text-shadow-color", [CPColor whiteColor]], + // [@"menu-item-selection-text-color", [CPColor whiteColor]], + // [@"menu-item-selection-text-shadow-color", [CPColor blackColor]], + // [@"menu-item-selection-color", [CPColor colorWithHexString:@"5C85D8"]], + // [@"menu-item-text-shadow-color", [CPColor colorWithCalibratedRed:26.0 / 255.0 green: 73.0 / 255.0 blue:109.0 / 255.0 alpha:1.0]], [@"horizontal-margin", 12.0], [@"submenu-indicator-margin", 3.0], [@"vertical-margin", 4.0] diff --git a/AppKit/Themes/Aristo2/ThemeDescriptors.j b/AppKit/Themes/Aristo2/ThemeDescriptors.j index b9229297b..22216e7f6 100644 --- a/AppKit/Themes/Aristo2/ThemeDescriptors.j +++ b/AppKit/Themes/Aristo2/ThemeDescriptors.j @@ -2021,8 +2021,8 @@ var themedButtonValues = nil, themeValues = [ - [@"menu-item-selection-color", [CPColor colorWithHexString:@"5C85D8"]], - [@"menu-item-text-shadow-color", [CPColor colorWithCalibratedRed:26.0 / 255.0 green: 73.0 / 255.0 blue:109.0 / 255.0 alpha:1.0]], + // [@"menu-item-selection-color", [CPColor colorWithHexString:@"5C85D8"]], +// [@"menu-item-text-shadow-color", [CPColor colorWithCalibratedRed:26.0 / 255.0 green: 73.0 / 255.0 blue:109.0 / 255.0 alpha:1.0]], [@"horizontal-margin", 9.0], [@"submenu-indicator-margin", 3.0], [@"vertical-margin", 4.0]