From 6ad037e4694c9f2c4043ccc7e4ed8f1256f00aa0 Mon Sep 17 00:00:00 2001 From: Francisco Tolmasky Date: Wed, 18 Feb 2009 02:22:10 -0800 Subject: [PATCH] Fix for major theme state bug. Reviewed by me. --- AppKit/CPButton.j | 3 +- AppKit/CPControl.j | 9 +- AppKit/CPPopUpButton.j | 98 ++++------ AppKit/CPSlider.j | 22 ++- AppKit/CPTheme.j | 67 ++++--- .../{CPThemedValue.j => CPThemedAttribute.j} | 179 +++++++++--------- 6 files changed, 189 insertions(+), 189 deletions(-) rename AppKit/{CPThemedValue.j => CPThemedAttribute.j} (60%) diff --git a/AppKit/CPButton.j b/AppKit/CPButton.j index 8228470f6..cbe3fc8c7 100644 --- a/AppKit/CPButton.j +++ b/AppKit/CPButton.j @@ -24,7 +24,6 @@ @import "CGGeometry.j" @import "CPControl.j" -@import "CPThemedValue.j" #include "CoreGraphics/CGGeometry.h" @@ -528,7 +527,7 @@ var _CPButtonClassName = nil, } else return [[_CPImageAndTextView alloc] initWithFrame:_CGRectMakeZero()]; - + return [super createEphemeralSubviewNamed:aName]; } diff --git a/AppKit/CPControl.j b/AppKit/CPControl.j index 5a18147cb..5aed551e7 100644 --- a/AppKit/CPControl.j +++ b/AppKit/CPControl.j @@ -23,7 +23,6 @@ @import "CPFont.j" @import "CPShadow.j" @import "CPView.j" -@import "CPThemedValue.j" #include "CoreGraphics/CGGeometry.h" #include "Platform/Platform.h" @@ -600,8 +599,8 @@ var __Deprecated__CPImageViewImageKey = @"CPImageViewImageKey"; /* [self setTarget:[aCoder decodeObjectForKey:CPControlTargetKey]]; - [self setAction:[aCoder decodeObjectForKey:CPControlActionKey]]; - [self sendActionOn:[aCoder decodeIntForKey:CPControlSendActionOnKey]];*/ + [self setAction:[aCoder decodeObjectForKey:CPControlActionKey]];*/ + [self sendActionOn:[aCoder decodeIntForKey:CPControlSendActionOnKey]]; } return self; @@ -637,8 +636,8 @@ var __Deprecated__CPImageViewImageKey = @"CPImageViewImageKey"; [aCoder encodeConditionalObject:_target forKey:CPControlTargetKey]; [aCoder encodeObject:_action forKey:CPControlActionKey]; - - [aCoder encodeInt:_sendActionOn forKey:CPControlSendActionOnKey];*/ + */ + [aCoder encodeInt:_sendActionOn forKey:CPControlSendActionOnKey]; } @end diff --git a/AppKit/CPPopUpButton.j b/AppKit/CPPopUpButton.j index 36341556f..a2049230b 100644 --- a/AppKit/CPPopUpButton.j +++ b/AppKit/CPPopUpButton.j @@ -25,10 +25,12 @@ @import "CPMenu.j" @import "CPMenuItem.j" +#include "CoreGraphics/CGGeometry.h" + var VISIBLE_MARGIN = 7.0; -var CPPopUpButtonArrowsImage = nil; +CPPopUpButtonStatePullsDown = 1 << 12; /*! @class CPPopUpButton @@ -36,12 +38,9 @@ var CPPopUpButtonArrowsImage = nil; */ @implementation CPPopUpButton : CPButton { - BOOL _pullsDown; int _selectedIndex; CPRectEdge _preferredEdge; - CPImageView _arrowsView; - CPMenu _menu; } @@ -57,7 +56,6 @@ var CPPopUpButtonArrowsImage = nil; if (self) { - _pullsDown = shouldPullDown; _selectedIndex = CPNotFound; _preferredEdge = CPMaxYEdge; @@ -66,6 +64,8 @@ var CPPopUpButtonArrowsImage = nil; [self setValue:CPLineBreakByTruncatingTail forThemedAttributeName:@"line-break-mode"]; [self setMenu:[[CPMenu alloc] initWithTitle:@""]]; + + [self setPullsDown:shouldPullDown]; } return self; @@ -76,33 +76,6 @@ var CPPopUpButtonArrowsImage = nil; return [self initWithFrame:aFrame pullsDown:NO]; } -- (void)setBordered:(BOOL)shouldBeBordered -{ - if (shouldBeBordered) - { - var bounds = [self bounds]; - - _arrowsView = [[CPImageView alloc] initWithFrame:CGRectMake(CGRectGetWidth(bounds) - 10.0, (CGRectGetHeight(bounds) - 8.0) / 2.0, 5.0, 8.0)]; - - if (!CPPopUpButtonArrowsImage) - CPPopUpButtonArrowsImage = [[CPImage alloc] initWithContentsOfFile:[[CPBundle bundleForClass:[CPPopUpButton class]] pathForResource:@"CPPopUpButton/CPPopUpButtonArrows.png"] size:CGSizeMake(5.0, 8.0)]; - - [_arrowsView setImage:CPPopUpButtonArrowsImage]; - [_arrowsView setAutoresizingMask:CPViewMaxXMargin | CPViewMinYMargin | CPViewMaxYMargin]; - - - [self addSubview:_arrowsView]; - } - else - { - [_arrowsView removeFromSuperview]; - - _arrowsView = nil; - } - - [super setBordered:shouldBeBordered]; -} - // Setting the Type of Menu /*! @@ -112,17 +85,20 @@ var CPPopUpButtonArrowsImage = nil; */ - (void)setPullsDown:(BOOL)shouldPullDown { - if (_pullsDown == shouldPullDown) + if ((!!(_controlState & CPPopUpButtonStatePullsDown)) === shouldPullDown) return; - _pullsDown = shouldPullDown; + if (shouldPullDown) + _controlState |= CPPopUpButtonStatePullsDown; + else + _controlState &= ~CPPopUpButtonStatePullsDown; var items = [_menu itemArray]; if (items.length <= 0) return; - - [items[0] setHidden:_pullsDown]; + + [items[0] setHidden:[self pullsDown]]; [self synchronizeTitleAndSelectedItem]; } @@ -132,7 +108,7 @@ var CPPopUpButtonArrowsImage = nil; */ - (BOOL)pullsDown { - return _pullsDown; + return _controlState & CPPopUpButtonStatePullsDown; } // Inserting and Deleting Items @@ -271,12 +247,12 @@ var CPPopUpButtonArrowsImage = nil; if (_selectedIndex == anIndex) return; - if (_selectedIndex >= 0 && !_pullsDown) + if (_selectedIndex >= 0 && ![self pullsDown]) [[self selectedItem] setState:CPOffState]; _selectedIndex = anIndex; - if (_selectedIndex >= 0 && !_pullsDown) + if (_selectedIndex >= 0 && ![self pullsDown]) [[self selectedItem] setState:CPOnState]; [self synchronizeTitleAndSelectedItem]; @@ -323,7 +299,7 @@ var CPPopUpButtonArrowsImage = nil; */ - (void)setMenu:(CPMenu)aMenu { - if (_menu == aMenu) + if (_menu === aMenu) return; var defaultCenter = [CPNotificationCenter defaultCenter]; @@ -520,10 +496,18 @@ var CPPopUpButtonArrowsImage = nil; if ([self title] == aTitle) return; - if (_pullsDown) + if ([self pullsDown]) { - [_items[0] setTitle:aTitle]; - [self synchronizeTitleAndSelectedItem]; + var items = [_menu itemArray]; + + if (items.length <= 0) + [self addItemWithTitle:aTitle]; + + else + { + [items[0] setTitle:aTitle]; + [self synchronizeTitleAndSelectedItem]; + } } else { @@ -560,7 +544,7 @@ var CPPopUpButtonArrowsImage = nil; { var item = nil; - if (_pullsDown) + if ([self pullsDown]) { var items = [_menu itemArray]; @@ -592,7 +576,7 @@ var CPPopUpButtonArrowsImage = nil; else if (index < _selectedIndex) ++_selectedIndex; - if (index == 0 && _pullsDown) + if (index == 0 && [self pullsDown]) { var items = [_menu itemArray]; @@ -620,10 +604,10 @@ var CPPopUpButtonArrowsImage = nil; { var index = [[aNotification userInfo] objectForKey:@"CPMenuItemIndex"]; - if (_pullsDown && index != 0) + if ([self pullsDown] && index != 0) return; - if (!_pullsDown && index != _selectedIndex) + if (![self pullsDown] && index != _selectedIndex) return; [self synchronizeTitleAndSelectedItem]; @@ -656,7 +640,7 @@ var CPPopUpButtonArrowsImage = nil; [menuWindow setBackgroundStyle:_CPMenuWindowPopUpBackgroundStyle]; // Pull Down Menus show up directly below their buttons. - if (_pullsDown) + if ([self pullsDown]) var menuOrigin = [theWindow convertBaseToBridge:[self convertPoint:CGPointMake(0.0, CGRectGetMaxY([self bounds])) toView:nil]]; // Pop Up Menus attempt to show up "on top" of the selected item. @@ -681,7 +665,7 @@ var CPPopUpButtonArrowsImage = nil; buttonMaxX = [theWindow convertBaseToBridge:CGPointMake(CGRectGetMaxX([self convertRect:[self bounds] toView:nil]), 0.0)].x; if (menuMaxX < buttonMaxX) - [menuWindow setMinWidth:CGRectGetWidth([menuWindow frame]) + buttonMaxX - menuMaxX - VISIBLE_MARGIN]; + [menuWindow setMinWidth:CGRectGetWidth([menuWindow frame]) + buttonMaxX - menuMaxX - ([self pullsDown] ? 0.0 : VISIBLE_MARGIN)]; [menuWindow orderFront:self]; [menuWindow beginTrackingWithEvent:anEvent sessionDelegate:self didEndSelector:@selector(menuWindowDidFinishTracking:highlightedItem:)]; @@ -711,20 +695,6 @@ var CPPopUpButtonArrowsImage = nil; [self sendAction:[self action] to:[self target]]; } -- (CGRect)contentRectForBounds:(CGRect)bounds -{ - var contentRect = [super contentRectForBounds:bounds]; - - if ([self isBordered]) - { - contentRect.size.width -= 20.0; - - return contentRect; - } - - return contentRect; -} - @end var CPPopUpButtonMenuKey = @"CPPopUpButtonMenuKey", @@ -750,7 +720,6 @@ var CPPopUpButtonMenuKey = @"CPPopUpButtonMenuKey", [self setMenu:[aCoder decodeObjectForKey:CPPopUpButtonMenuKey]]; [self selectItemAtIndex:[aCoder decodeObjectForKey:CPPopUpButtonSelectedIndexKey]]; - [self setPullsDown:[aCoder decodeBoolForKey:CPPopUpButtonPullsDownKey]]; } return self; @@ -767,7 +736,6 @@ var CPPopUpButtonMenuKey = @"CPPopUpButtonMenuKey", [aCoder encodeObject:_menu forKey:CPPopUpButtonMenuKey]; [aCoder encodeInt:_selectedIndex forKey:CPPopUpButtonSelectedIndexKey]; - [aCoder encodeBool:_pullsDown forKey:CPPopUpButtonPullsDownKey]; } @end diff --git a/AppKit/CPSlider.j b/AppKit/CPSlider.j index d080718cf..9565af161 100644 --- a/AppKit/CPSlider.j +++ b/AppKit/CPSlider.j @@ -1,6 +1,26 @@ +/* + * CPSlider.j + * AppKit + * + * Created by Francisco Tolmasky. + * Copyright 2009, 280 North, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ @import "CPControl.j" -@import "CPThemedValue.j" #include "CoreGraphics/CGGeometry.h" diff --git a/AppKit/CPTheme.j b/AppKit/CPTheme.j index e53fd9dde..acbe1cee5 100644 --- a/AppKit/CPTheme.j +++ b/AppKit/CPTheme.j @@ -1,9 +1,30 @@ +/* + * CPTheme.j + * AppKit + * + * Created by Francisco Tolmasky. + * Copyright 2009, 280 North, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ @import @import @import -@import "CPThemedValue.j" +@import "CPThemedAttribute.j" var CPThemesByName = nil, @@ -116,12 +137,7 @@ var CPThemesByName = nil, return _activeClass; } -- (id)valueForKey:(CPString)aKey -{ - return [self valueForKey:aKey inClass:_activeClass]; -} - -- (id)valueForKey:(CPString)aKey inClass:(CPClass)aClass +- (id)valueForAttributeName:(CPString)anAttributeName inClass:(CPClass)aClass { if (!aClass) return nil; @@ -132,7 +148,7 @@ var CPThemesByName = nil, if (!table) return nil; - var value = table[aKey]; + var value = table[anAttributeName]; if (!value) return nil; @@ -140,28 +156,23 @@ var CPThemesByName = nil, return value; } -- (id)valueForIdentifier:(CPString)anIdentifier inClass:(Class)aClass -{ - return [self valueForKey:anIdentifier inClass:aClass]; -} - - (void)takeThemeFromObject:(id)anObject { - var values = [anObject themedValues], - key = nil, - keys = [values keyEnumerator], + var attributes = [anObject _themedAttributes], + attributeName = nil, + attributeNames = [attributes keyEnumerator], objectClass = [anObject class]; - while (key = [keys nextObject]) - [self addValue:[values objectForKey:key] forKey:key inClass:objectClass]; + while (attributeName = [attributeNames nextObject]) + [self addValue:[attributes objectForKey:attributeName] forAttributeName:attributeName inClass:objectClass]; } -- (void)setDefaultValue:(id)aValue forKey:(CPString)aKey +- (void)setDefaultValue:(id)aValue forAttributeName:(CPString)anAttributeName { - [self addValue:aValue forKey:aKey inClass:[self class]]; + [self addValue:aValue forAttributeName:anAttributeName inClass:[self class]]; } -- (void)addValue:(id)aValue forKey:(CPString)aKey inClass:(Class)aClass +- (void)addValue:(id)aValue forAttributeName:(CPString)anAttributeName inClass:(Class)aClass { if (!aValue) return; @@ -197,11 +208,13 @@ var CPThemesByName = nil, table = _classTable[className]; } } - - if (table[aKey] !== aValue) -// { -// if (table.hasOwnProperty(aKey) - table[aKey] = aValue; + + var existingAttribute = table[anAttributeName]; + + if (existingAttribute) + table[anAttributeName] = [existingAttribute themedAttributeMergedWithThemedAttribute:aValue]; + else + table[anAttributeName] = aValue; } @end @@ -237,7 +250,7 @@ var CPThemeNameKey = @"CPThemeNameKey", { var key = keys[keyCount]; - [self addValue:[values objectForKey:key] forKey:key inClass:theClass]; + [self addValue:[values objectForKey:key] forAttributeName:key inClass:theClass]; } } } diff --git a/AppKit/CPThemedValue.j b/AppKit/CPThemedAttribute.j similarity index 60% rename from AppKit/CPThemedValue.j rename to AppKit/CPThemedAttribute.j index 59454b099..5ab3f08b5 100644 --- a/AppKit/CPThemedValue.j +++ b/AppKit/CPThemedAttribute.j @@ -6,10 +6,15 @@ CPControlStateNormal = 0, CPControlStateHighlighted = 1 << 0, CPControlStateDisabled = 1 << 1, CPControlStateSelected = 1 << 2, -CPControlStateDefault = 1 << 3; +CPControlStateDefault = 1 << 3, +CPControlStateBordered = 1 << 4, +CPControlStateBezeled = 1 << 5, +CPControlStateVertical = 1 << 6; -var BIT_COUNT = [ 0 /*0000*/, 1 /*0001*/, 1 /*0010*/, 2 /*0011*/, 1 /*0100*/, 2 /*0101*/, 2 /*0110*/, 3 /*0111*/, - 1 /*1000*/, 2 /*1001*/, 2 /*1010*/, 3 /*1011*/, 2 /*1100*/, 3 /*1101*/, 3 /*1110*/, 4 /*1111*/], +var BIT_COUNT = [ 0 /*00000*/, 1 /*00001*/, 1 /*00010*/, 2 /*00011*/, 1 /*00100*/, 2 /*00101*/, 2 /*00110*/, 3 /*00111*/, + 1 /*01000*/, 2 /*01001*/, 2 /*01010*/, 3 /*01011*/, 2 /*01100*/, 3 /*01101*/, 3 /*01110*/, 4 /*01111*/, + 1 /*10000*/, 2 /*10001*/, 2 /*10010*/, 3 /*10011*/, 2 /*10100*/, 3 /*10101*/, 3 /*10110*/, 4 /*10111*/, + 2 /*11000*/, 3 /*11001*/, 3 /*11010*/, 4 /*11011*/, 3 /*11100*/, 4 /*11101*/, 4 /*11110*/, 5 /*11111*/], bit_count = function(bits) { var count = 0; @@ -23,65 +28,63 @@ var BIT_COUNT = [ 0 /*0000*/, 1 /*0001*/, 1 /*0010*/, 2 /*0011*/, 1 /*0100*/, return count ; } -@implementation CPThemedValue : CPObject +@implementation CPThemedAttribute : CPObject { BOOL _isSingularObject; - CPTheme _theme; - CPString _identifier; - Class _themedClass; - + CPString _name; id _defaultValue; + CPTheme _theme; + Class _themedClass; + id _values; id _valueFromTheme; } -- (id)initWithDefaultValue:(id)aDefaultValue identifier:(CPString)anIdentifier theme:(CPTheme)aTheme class:(Class)aClass +- (id)initWithName:(CPString)aName defaultValue:(id)aDefaultValue theme:(CPTheme)aTheme class:(Class)aClass { self = [super init]; if (self) { + _name = aName; + + _defaultValue = aDefaultValue; + _theme = aTheme; _themedClass = aClass; - _identifier = anIdentifier; - _defaultValue = aDefaultValue; _isSingularObject = YES; _values = nil; - _valueFromTheme = [_theme valueForIdentifier:_identifier inClass:_themedClass]; + _valueFromTheme = [_theme valueForAttributeName:_name inClass:_themedClass]; } return self; } +- (void)setName:(CPString)aName +{ + _name = aName; +} + +- (CPString)name +{ + return _name; +} + - (void)setDefaultValue:(id)aValue { _defaultValue = aValue; } -- (void)setIdentifier:(CPString)anIdentifier -{ - if (_identifier === anIdentifier) - return; - - _identifier = anIdentifier; - _valueFromTheme = [_theme valueForIdentifier:_identifier inClass:_themedClass]; -} - -- (CPString)identifier -{ - return _identifier; -} - - (void)setTheme:(CPTheme)aTheme { if (_theme === aTheme) return; _theme = aTheme; - _valueFromTheme = [_theme valueForIdentifier:_identifier inClass:_themedClass]; + _valueFromTheme = [_theme valueForName:_name inClass:_themedClass]; } - (void)setThemedClass:(Class)aClass @@ -90,7 +93,7 @@ var BIT_COUNT = [ 0 /*0000*/, 1 /*0001*/, 1 /*0010*/, 2 /*0011*/, 1 /*0100*/, return; _themedClass = aClass; - _valueFromTheme = [_theme valueForIdentifier:_identifier inClass:_themedClass]; + _valueFromTheme = [_theme valueForName:_name inClass:_themedClass]; } - (void)setValue:(id)aValue @@ -151,7 +154,7 @@ var BIT_COUNT = [ 0 /*0000*/, 1 /*0001*/, 1 /*0010*/, 2 /*0011*/, 1 /*0100*/, if ((value === undefined || value === nil) && aState > 0) { // If this is a composite state, find the closest partial subset match. - if (!(aState & (aState - 1))) + if (aState & (aState - 1)) { var highestBitCount = 0; @@ -160,6 +163,9 @@ var BIT_COUNT = [ 0 /*0000*/, 1 /*0001*/, 1 /*0010*/, 2 /*0011*/, 1 /*0100*/, if (!_values.hasOwnProperty(state)) continue; + // state is a string! + state = Number(state); + // A & B = A iff A < B if ((state & aState) === state) { @@ -188,6 +194,40 @@ var BIT_COUNT = [ 0 /*0000*/, 1 /*0001*/, 1 /*0010*/, 2 /*0011*/, 1 /*0100*/, return value; } +- (CPThemedAttribute)themedAttributeMergedWithThemedAttribute:(CPThemedAttribute)aThemedAttribute +{ + var themedAttribute = CPThemedAttributeMake(_name, _defaultValue, _theme, _themedClass); + + themedAttribute._isSingularObject = NO; + themedAttribute._values = {}; + + if (_isSingularObject) + themedAttribute._values[CPControlStateNormal] = _values; + + else + { + var values = _values; + + for (state in _values) + if (_values.hasOwnProperty(state)) + themedAttribute._values[state] = _values[state]; + } + + if (aThemedAttribute._isSingularObject) + themedAttribute._values[CPControlStateNormal] = aThemedAttribute._values; + + else + { + var values = aThemedAttribute._values; + + for (state in values) + if (values.hasOwnProperty(state)) + themedAttribute._values[state] = values[state]; + } + + return themedAttribute; +} + - (id)initWithCoder:(CPCoder)aCoder { self = [super init]; @@ -244,87 +284,48 @@ var BIT_COUNT = [ 0 /*0000*/, 1 /*0001*/, 1 /*0010*/, 2 /*0011*/, 1 /*0100*/, @end -function CPThemedValueMake(aDefaultValue, anIdentifier, aTheme, aClass) +function CPThemedAttributeMake(aName, aDefaultValue, aTheme, aClass) { - return [[CPThemedValue alloc] initWithDefaultValue:aDefaultValue identifier:anIdentifier theme:aTheme class:aClass]; + return [[CPThemedAttribute alloc] initWithName:aName defaultValue:aDefaultValue theme:aTheme class:aClass]; } -function CPThemedValueEncode(aCoder, aKey, aThemedValue) +function CPThemedAttributeEncode(aCoder, aThemedAttribute) { - if (aThemedValue._isSingularObject) + if (aThemedAttribute._isSingularObject) { - var actualValue = aThemedValue._values; - - if (aThemedValue._values) - [aCoder encodeObject:actualValue forKey:aKey]; + var actualValue = aThemedAttribute._values; + + if (aThemedAttribute._values) + [aCoder encodeObject:actualValue forKey:"$a" + [aThemedAttribute name]]; } else - [aCoder encodeObject:aThemedValue forKey:aKey]; + [aCoder encodeObject:aThemedAttribute forKey:"$a" + [aThemedAttribute name]]; } -function CPThemedValueDecode(aCoder, aKey, aDefaultValue, anIdentifier, aTheme, aClass) -{ - if (![aCoder containsValueForKey:aKey]) - return CPThemedValueMake(aDefaultValue, anIdentifier, aTheme, aClass); - - var value = [aCoder decodeObjectForKey:aKey]; - - if (![value isKindOfClass:[CPThemedValue class]]) - { - var themedValue = CPThemedValueMake(aDefaultValue, anIdentifier, aTheme, aClass); - - [themedValue setValue:value]; - - value = themedValue; - } - else - { - [value setDefaultValue:aDefaultValue]; - [value setTheme:aTheme]; - [value setIdentifier:anIdentifier]; - [value setThemedClass:aClass]; - } - - return value; -} - -function CPThemedValueEncode2(aCoder, aThemedValue) -{ - if (aThemedValue._isSingularObject) - { - var actualValue = aThemedValue._values; - - if (aThemedValue._values) - [aCoder encodeObject:actualValue forKey:"$a" + [aThemedValue identifier]]; - } - else - [aCoder encodeObject:aThemedValue forKey:"$a" + [aThemedValue identifier]]; -} - -function CPThemedValueDecode2(aCoder, anAttributeName, aDefaultValue, aTheme, aClass) +function CPThemedAttributeDecode(aCoder, anAttributeName, aDefaultValue, aTheme, aClass) { var key = "$a" + anAttributeName; if (![aCoder containsValueForKey:key]) - return CPThemedValueMake(aDefaultValue, anAttributeName, aTheme, aClass); + return CPThemedAttributeMake(anAttributeName, aDefaultValue, aTheme, aClass); - var value = [aCoder decodeObjectForKey:key]; + var attribute = [aCoder decodeObjectForKey:key]; - if (![value isKindOfClass:[CPThemedValue class]]) + if (![attribute isKindOfClass:[CPThemedAttribute class]]) { - var themedValue = CPThemedValueMake(aDefaultValue, anAttributeName, aTheme, aClass); + var themedAttribute = CPThemedAttributeMake(anAttributeName, aDefaultValue, aTheme, aClass); - [themedValue setValue:value]; + [themedAttribute setValue:attribute]; - value = themedValue; + attribute = themedAttribute; } else { - [value setDefaultValue:aDefaultValue]; - [value setTheme:aTheme]; - [value setIdentifier:anAttributeName]; - [value setThemedClass:aClass]; + [attribute setName:anAttributeName]; + [attribute setDefaultValue:aDefaultValue]; + [attribute setTheme:aTheme]; + [attribute setThemedClass:aClass]; } - return value; + return attribute; }