diff --git a/AppKit/CPAlert.j b/AppKit/CPAlert.j index 24180055d..142a81ae7 100644 --- a/AppKit/CPAlert.j +++ b/AppKit/CPAlert.j @@ -91,7 +91,7 @@ CPCriticalAlertStyle = 2; id _modalDelegate; } -+ (CPString)themeClass ++ (CPString)defaultThemeClass { return @"alert"; } diff --git a/AppKit/CPButton.j b/AppKit/CPButton.j index 59b5b5156..717995ce8 100644 --- a/AppKit/CPButton.j +++ b/AppKit/CPButton.j @@ -120,7 +120,7 @@ CPButtonImageOffset = 3.0; return button; } -+ (CPString)themeClass ++ (CPString)defaultThemeClass { return @"button"; } diff --git a/AppKit/CPButtonBar.j b/AppKit/CPButtonBar.j index 138fffc71..73873dc5f 100644 --- a/AppKit/CPButtonBar.j +++ b/AppKit/CPButtonBar.j @@ -50,7 +50,7 @@ return button; } -+ (CPString)themeClass ++ (CPString)defaultThemeClass { return @"button-bar"; } diff --git a/AppKit/CPCheckBox.j b/AppKit/CPCheckBox.j index 8db4b492d..3e6ac7e8b 100644 --- a/AppKit/CPCheckBox.j +++ b/AppKit/CPCheckBox.j @@ -38,7 +38,7 @@ CPCheckBoxImageOffset = 4.0; return [self buttonWithTitle:aTitle]; } -+ (CPString)themeClass ++ (CPString)defaultThemeClass { return @"check-box"; } diff --git a/AppKit/CPPopUpButton.j b/AppKit/CPPopUpButton.j index 27f4a6a7b..6cb3150b8 100644 --- a/AppKit/CPPopUpButton.j +++ b/AppKit/CPPopUpButton.j @@ -46,7 +46,7 @@ CPPopUpButtonStatePullsDown = CPThemeState("pulls-down"); CPMenu _menu; } -+ (CPString)themeClass ++ (CPString)defaultThemeClass { return "popup-button"; } diff --git a/AppKit/CPRadio.j b/AppKit/CPRadio.j index 773c317c7..59d6f76d4 100644 --- a/AppKit/CPRadio.j +++ b/AppKit/CPRadio.j @@ -89,7 +89,7 @@ CPRadioImageOffset = 4.0; return button; } -+ (CPString)themeClass ++ (CPString)defaultThemeClass { return @"radio"; } diff --git a/AppKit/CPScrollView.j b/AppKit/CPScrollView.j index dd2e57ed8..9af371f5f 100644 --- a/AppKit/CPScrollView.j +++ b/AppKit/CPScrollView.j @@ -60,7 +60,7 @@ CPBorderType _borderType; } -+ (CPString)themeClass ++ (CPString)defaultThemeClass { return @"scrollview" } diff --git a/AppKit/CPScroller.j b/AppKit/CPScroller.j index 664c42305..8709fc537 100644 --- a/AppKit/CPScroller.j +++ b/AppKit/CPScroller.j @@ -72,7 +72,7 @@ NAMES_FOR_PARTS[CPScrollerKnob] = @"knob"; CGPoint _trackingStartPoint; } -+ (CPString)themeClass ++ (CPString)defaultThemeClass { return "scroller"; } diff --git a/AppKit/CPSearchField.j b/AppKit/CPSearchField.j index 5e91386c5..f38f3cc19 100644 --- a/AppKit/CPSearchField.j +++ b/AppKit/CPSearchField.j @@ -68,7 +68,7 @@ var RECENT_SEARCH_PREFIX = @" "; CPTimer _partialStringTimer; } -+ (CPString)themeClass ++ (CPString)defaultThemeClass { return @"searchfield" } diff --git a/AppKit/CPSegmentedControl.j b/AppKit/CPSegmentedControl.j index 6670bf8ae..edcf3226d 100644 --- a/AppKit/CPSegmentedControl.j +++ b/AppKit/CPSegmentedControl.j @@ -49,7 +49,7 @@ CPSegmentSwitchTrackingMomentary = 2; BOOL _trackingHighlighted; } -+ (CPString)themeClass ++ (CPString)defaultThemeClass { return "segmented-control"; } diff --git a/AppKit/CPSlider.j b/AppKit/CPSlider.j index a9b41c3b8..96f2c44e6 100644 --- a/AppKit/CPSlider.j +++ b/AppKit/CPSlider.j @@ -42,7 +42,7 @@ CPCircularSlider = 1; BOOL _isVertical; } -+ (CPString)themeClass ++ (CPString)defaultThemeClass { return "slider"; } diff --git a/AppKit/CPSplitView.j b/AppKit/CPSplitView.j index c23a66373..e90ea195a 100644 --- a/AppKit/CPSplitView.j +++ b/AppKit/CPSplitView.j @@ -61,7 +61,7 @@ var CPSplitViewHorizontalImage = nil, CPArray _buttonBars; } -+ (CPString)themeClass ++ (CPString)defaultThemeClass { return @"splitview"; } diff --git a/AppKit/CPTableHeaderView.j b/AppKit/CPTableHeaderView.j index 84272017a..254c2c582 100644 --- a/AppKit/CPTableHeaderView.j +++ b/AppKit/CPTableHeaderView.j @@ -33,7 +33,7 @@ _CPImageAndTextView _textField; } -+ (CPString)themeClass ++ (CPString)defaultThemeClass { return @"columnHeader"; } @@ -168,7 +168,7 @@ var _CPTableColumnHeaderViewStringValueKey = @"_CPTableColumnHeaderViewStringVal CPTableView _tableView @accessors(property=tableView); } -+ (CPString)themeClass ++ (CPString)defaultThemeClass { return @"tableHeaderRow"; } diff --git a/AppKit/CPTableView.j b/AppKit/CPTableView.j index 194296455..3db9479f5 100644 --- a/AppKit/CPTableView.j +++ b/AppKit/CPTableView.j @@ -221,7 +221,7 @@ CPTableViewFirstColumnOnlyAutoresizingStyle = 5; CPArray _differedColumnDataToRemove; } -+ (CPString)themeClass ++ (CPString)defaultThemeClass { return @"tableview"; } diff --git a/AppKit/CPTextField.j b/AppKit/CPTextField.j index f144eb11e..83ec81440 100644 --- a/AppKit/CPTextField.j +++ b/AppKit/CPTextField.j @@ -158,7 +158,7 @@ CPTextFieldStatePlaceholder = CPThemeState("placeholder"); return textField; } -+ (CPString)themeClass ++ (CPString)defaultThemeClass { return "textfield"; } diff --git a/AppKit/CPTheme.j b/AppKit/CPTheme.j index f930cb1ed..5098db017 100644 --- a/AppKit/CPTheme.j +++ b/AppKit/CPTheme.j @@ -100,7 +100,7 @@ var CPThemesByName = { }, ThemeDescriptors.j file. NOTE: The names are not class names (such as "CPButton"), but the names returned - by the class' +themeClass method. For example, the name for CPCheckBox is "check-box", + by the class' +defaultThemeClass method. For example, the name for CPCheckBox is "check-box", as defined in CPCheckBox::themeClass. */ - (CPArray)classNames @@ -140,8 +140,13 @@ var CPThemesByName = { }, { if ([aClass isKindOfClass:[CPView class]]) { - if ([aClass respondsToSelector:@selector(themeClass)]) + if ([aClass respondsToSelector:@selector(defaultThemeClass)]) + className = [aClass defaultThemeClass]; + else if ([aClass respondsToSelector:@selector(themeClass)]) + { + CPLog.warn(@"%@ themeClass is deprecated in favor of defaultThemeClass",CPStringFromClass([anObject class])); className = [aClass themeClass]; + } else return nil; } @@ -247,7 +252,7 @@ var CPThemesByName = { }, var attributes = [anObject _themeAttributeDictionary], attributeName = nil, attributeNames = [attributes keyEnumerator], - objectThemeClass = [[anObject class] themeClass]; + objectThemeClass = [anObject themeClass]; while (attributeName = [attributeNames nextObject]) [self _recordAttribute:[attributes objectForKey:attributeName] forClass:objectThemeClass]; diff --git a/AppKit/CPTokenField.j b/AppKit/CPTokenField.j index 70e70c2c0..76199dc5f 100755 --- a/AppKit/CPTokenField.j +++ b/AppKit/CPTokenField.j @@ -87,7 +87,7 @@ var CPThemeStateAutoCompleting = @"CPThemeStateAutoCompleting", return [CPCharacterSet characterSetWithCharactersInString:@","]; } -+ (CPString)themeClass ++ (CPString)defaultThemeClass { return "tokenfield"; } @@ -1146,7 +1146,7 @@ var CPThemeStateAutoCompleting = @"CPThemeStateAutoCompleting", CPTokenField _tokenField; } -+ (CPString)themeClass ++ (CPString)defaultThemeClass { return "tokenfield-token"; } @@ -1243,7 +1243,7 @@ var CPThemeStateAutoCompleting = @"CPThemeStateAutoCompleting", return attributes; } -+ (CPString)themeClass ++ (CPString)defaultThemeClass { return "tokenfield-token-close-button"; } diff --git a/AppKit/CPView.j b/AppKit/CPView.j index d78204687..b70293882 100644 --- a/AppKit/CPView.j +++ b/AppKit/CPView.j @@ -179,6 +179,7 @@ var CPViewFlags = { }, // Theming Support CPTheme _theme; + CPString _themeClass; JSObject _themeAttributes; unsigned _themeState; @@ -1004,7 +1005,7 @@ var CPViewFlags = { }, { var mask = [self autoresizingMask]; - if(mask == CPViewNotSizable) + if (mask == CPViewNotSizable) return; var frame = _superview._frame, @@ -1160,7 +1161,7 @@ var CPViewFlags = { }, { aFlag = !!aFlag; - if(_isHidden === aFlag) + if (_isHidden === aFlag) return; // FIXME: Should we return to visibility? This breaks in FireFox, Opera, and IE. @@ -1352,7 +1353,7 @@ var CPViewFlags = { }, */ - (CPView)hitTest:(CPPoint)aPoint { - if(_isHidden || !_hitTests || !CPRectContainsPoint(_frame, aPoint)) + if (_isHidden || !_hitTests || !CPRectContainsPoint(_frame, aPoint)) return nil; var view = nil, @@ -1960,7 +1961,7 @@ setBoundsOrigin: var superview = _superview, clipViewClass = [CPClipView class]; - while(superview && ![superview isKindOfClass:clipViewClass]) + while (superview && ![superview isKindOfClass:clipViewClass]) superview = superview._superview; return superview; @@ -2056,7 +2057,7 @@ setBoundsOrigin: var superview = _superview, scrollViewClass = [CPScrollView class]; - while(superview && ![superview isKindOfClass:scrollViewClass]) + while (superview && ![superview isKindOfClass:scrollViewClass]) superview = superview._superview; return superview; @@ -2252,11 +2253,29 @@ setBoundsOrigin: #pragma mark Theme Attributes -+ (CPString)themeClass ++ (CPString)defaultThemeClass { return nil; } +- (CPString)themeClass +{ + if (_themeClass) + return _themeClass; + + return [[self class] defaultThemeClass]; +} + +- (void)setThemeClass:(CPString)theClass +{ + _themeClass = theClass; + + [self _loadThemeAttributes]; + + [self setNeedsLayout]; + [self setNeedsDisplay:YES]; +} + + (CPDictionary)themeAttributes { return nil; @@ -2315,7 +2334,7 @@ setBoundsOrigin: return; var theme = [self theme], - themeClass = [theClass themeClass]; + themeClass = [self themeClass]; _themeAttributes = {}; @@ -2351,7 +2370,7 @@ setBoundsOrigin: return; var theme = [self theme], - themeClass = [[self class] themeClass]; + themeClass = [self themeClass]; for (var attributeName in _themeAttributes) if (_themeAttributes.hasOwnProperty(attributeName)) @@ -2502,6 +2521,7 @@ var CPViewAutoresizingMaskKey = @"CPViewAutoresizingMask", CPViewSubviewsKey = @"CPViewSubviewsKey", CPViewSuperviewKey = @"CPViewSuperviewKey", CPViewTagKey = @"CPViewTagKey", + CPViewThemeClassKey = @"CPViewThemeClassKey", CPViewThemeStateKey = @"CPViewThemeStateKey", CPViewWindowKey = @"CPViewWindowKey", CPViewNextKeyViewKey = @"CPViewNextKeyViewKey", @@ -2581,11 +2601,12 @@ var CPViewAutoresizingMaskKey = @"CPViewAutoresizingMask", [self setupViewFlags]; _theme = [CPTheme defaultTheme]; + _themeClass = [aCoder decodeObjectForKey:CPViewThemeClassKey]; _themeState = CPThemeState([aCoder decodeIntForKey:CPViewThemeStateKey]); _themeAttributes = {}; var theClass = [self class], - themeClass = [theClass themeClass], + themeClass = [self themeClass], attributes = [theClass _themeAttributes], count = attributes.length; @@ -2668,6 +2689,7 @@ var CPViewAutoresizingMaskKey = @"CPViewAutoresizingMask", if (previousKeyView !== nil) [aCoder encodeConditionalObject:previousKeyView forKey:CPViewPreviousKeyViewKey]; + [aCoder encodeObject:[self themeClass] forKey:CPViewThemeClassKey]; [aCoder encodeInt:CPThemeStateName(_themeState) forKey:CPViewThemeStateKey]; for (var attributeName in _themeAttributes) diff --git a/AppKit/_CPCornerView.j b/AppKit/_CPCornerView.j index 0c3582f3f..b1a4ff7bd 100644 --- a/AppKit/_CPCornerView.j +++ b/AppKit/_CPCornerView.j @@ -26,7 +26,7 @@ { } -+ (CPString)themeClass ++ (CPString)defaultThemeClass { return @"cornerview"; }