From 85c9ca518f0a782e0cbc30091053ca441d8225d2 Mon Sep 17 00:00:00 2001 From: Klaas Pieter Annema Date: Mon, 25 Oct 2010 13:54:19 +0200 Subject: [PATCH 1/5] lint cleanup in CPView --- AppKit/CPView.j | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/AppKit/CPView.j b/AppKit/CPView.j index d78204687..734a7ec83 100644 --- a/AppKit/CPView.j +++ b/AppKit/CPView.j @@ -1004,7 +1004,7 @@ var CPViewFlags = { }, { var mask = [self autoresizingMask]; - if(mask == CPViewNotSizable) + if (mask == CPViewNotSizable) return; var frame = _superview._frame, @@ -1160,7 +1160,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 +1352,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 +1960,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 +2056,7 @@ setBoundsOrigin: var superview = _superview, scrollViewClass = [CPScrollView class]; - while(superview && ![superview isKindOfClass:scrollViewClass]) + while (superview && ![superview isKindOfClass:scrollViewClass]) superview = superview._superview; return superview; From 22e2bdcd25ce991c1a26b483e32833d52a03b99f Mon Sep 17 00:00:00 2001 From: Klaas Pieter Annema Date: Mon, 25 Oct 2010 13:54:39 +0200 Subject: [PATCH 2/5] make theme class runtime configurable --- AppKit/CPView.j | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/AppKit/CPView.j b/AppKit/CPView.j index 734a7ec83..449c2bc12 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; @@ -2257,6 +2258,24 @@ setBoundsOrigin: return nil; } +- (CPString)themeClass +{ + if (_themeClass) + return _themeClass; + + return [[self class] themeClass]; +} + +- (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)) @@ -2585,7 +2604,7 @@ var CPViewAutoresizingMaskKey = @"CPViewAutoresizingMask", _themeAttributes = {}; var theClass = [self class], - themeClass = [theClass themeClass], + themeClass = [self themeClass], attributes = [theClass _themeAttributes], count = attributes.length; From 6e9f82212b7aac1efe1c5b897d7a1a31046d8f6d Mon Sep 17 00:00:00 2001 From: Klaas Pieter Annema Date: Mon, 25 Oct 2010 13:58:52 +0200 Subject: [PATCH 3/5] rename CPView +themeClass to +defaultThemeClass --- AppKit/.detect_missing_imports | 0 AppKit/CPAlert.j | 2 +- AppKit/CPButton.j | 2 +- AppKit/CPButtonBar.j | 2 +- AppKit/CPCheckBox.j | 2 +- AppKit/CPPopUpButton.j | 2 +- AppKit/CPRadio.j | 2 +- AppKit/CPScrollView.j | 2 +- AppKit/CPScroller.j | 2 +- AppKit/CPSearchField.j | 2 +- AppKit/CPSegmentedControl.j | 2 +- AppKit/CPSlider.j | 2 +- AppKit/CPSplitView.j | 2 +- AppKit/CPTableHeaderView.j | 4 ++-- AppKit/CPTableView.j | 2 +- AppKit/CPTextField.j | 2 +- AppKit/CPTheme.j | 8 ++++---- AppKit/CPTokenField.j | 6 +++--- AppKit/CPView.j | 4 ++-- AppKit/_CPCornerView.j | 2 +- 20 files changed, 26 insertions(+), 26 deletions(-) create mode 100644 AppKit/.detect_missing_imports diff --git a/AppKit/.detect_missing_imports b/AppKit/.detect_missing_imports new file mode 100644 index 000000000..e69de29bb 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..a0e3d70e1 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,8 @@ var CPThemesByName = { }, { if ([aClass isKindOfClass:[CPView class]]) { - if ([aClass respondsToSelector:@selector(themeClass)]) - className = [aClass themeClass]; + if ([aClass respondsToSelector:@selector(defaultThemeClass)]) + className = [aClass defaultThemeClass]; else return nil; } @@ -247,7 +247,7 @@ var CPThemesByName = { }, var attributes = [anObject _themeAttributeDictionary], attributeName = nil, attributeNames = [attributes keyEnumerator], - objectThemeClass = [[anObject class] themeClass]; + objectThemeClass = [[anObject class] defaultThemeClass]; while (attributeName = [attributeNames nextObject]) [self _recordAttribute:[attributes objectForKey:attributeName] forClass:objectThemeClass]; diff --git a/AppKit/CPTokenField.j b/AppKit/CPTokenField.j index 85379894d..adacb1d5d 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"; } @@ -1129,7 +1129,7 @@ var CPThemeStateAutoCompleting = @"CPThemeStateAutoCompleting", CPTokenField _tokenField; } -+ (CPString)themeClass ++ (CPString)defaultThemeClass { return "tokenfield-token"; } @@ -1226,7 +1226,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 449c2bc12..ccd288648 100644 --- a/AppKit/CPView.j +++ b/AppKit/CPView.j @@ -2253,7 +2253,7 @@ setBoundsOrigin: #pragma mark Theme Attributes -+ (CPString)themeClass ++ (CPString)defaultThemeClass { return nil; } @@ -2263,7 +2263,7 @@ setBoundsOrigin: if (_themeClass) return _themeClass; - return [[self class] themeClass]; + return [[self class] defaultThemeClass]; } - (void)setThemeClass:(CPString)theClass 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"; } From c7fdad883a5240cb31983b569a0cafc6c69d06a3 Mon Sep 17 00:00:00 2001 From: Klaas Pieter Annema Date: Mon, 25 Oct 2010 16:11:24 +0200 Subject: [PATCH 4/5] add deprecation warning for class that have themeClass implemented --- AppKit/CPTheme.j | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/AppKit/CPTheme.j b/AppKit/CPTheme.j index a0e3d70e1..5098db017 100644 --- a/AppKit/CPTheme.j +++ b/AppKit/CPTheme.j @@ -142,6 +142,11 @@ var CPThemesByName = { }, { 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] defaultThemeClass]; + objectThemeClass = [anObject themeClass]; while (attributeName = [attributeNames nextObject]) [self _recordAttribute:[attributes objectForKey:attributeName] forClass:objectThemeClass]; From 0fa149b74f041280fc2e3c876d068bba6384a96e Mon Sep 17 00:00:00 2001 From: Klaas Pieter Annema Date: Mon, 25 Oct 2010 16:12:08 +0200 Subject: [PATCH 5/5] encode and decode themeClass This makes it possible to theme any themeClass without having to subclass a CPView and return something different from defaultThemeClass. Theme a custom theme class by assigning to a control within the theme descriptor ([control setThemeClass:"your-theme-class"]). --- AppKit/.detect_missing_imports | 0 AppKit/CPView.j | 3 +++ 2 files changed, 3 insertions(+) delete mode 100644 AppKit/.detect_missing_imports diff --git a/AppKit/.detect_missing_imports b/AppKit/.detect_missing_imports deleted file mode 100644 index e69de29bb..000000000 diff --git a/AppKit/CPView.j b/AppKit/CPView.j index ccd288648..b70293882 100644 --- a/AppKit/CPView.j +++ b/AppKit/CPView.j @@ -2521,6 +2521,7 @@ var CPViewAutoresizingMaskKey = @"CPViewAutoresizingMask", CPViewSubviewsKey = @"CPViewSubviewsKey", CPViewSuperviewKey = @"CPViewSuperviewKey", CPViewTagKey = @"CPViewTagKey", + CPViewThemeClassKey = @"CPViewThemeClassKey", CPViewThemeStateKey = @"CPViewThemeStateKey", CPViewWindowKey = @"CPViewWindowKey", CPViewNextKeyViewKey = @"CPViewNextKeyViewKey", @@ -2600,6 +2601,7 @@ var CPViewAutoresizingMaskKey = @"CPViewAutoresizingMask", [self setupViewFlags]; _theme = [CPTheme defaultTheme]; + _themeClass = [aCoder decodeObjectForKey:CPViewThemeClassKey]; _themeState = CPThemeState([aCoder decodeIntForKey:CPViewThemeStateKey]); _themeAttributes = {}; @@ -2687,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)