Further CPView/CPMenuItem cleanup.

Reviewed by me.
This commit is contained in:
Francisco Tolmasky committed 2009-05-15 22:16:15 -07:00
1 parent 8c1f6f3014
commit 4588d1db08
2 files changed
+49 -39

No files matched your search

+36 -34
View File
@@ -113,11 +113,11 @@
{
if ([_menu autoenablesItems])
return;
_isEnabled = isEnabled;
[_menuItemView setDirty];
[_menu itemChanged:self];
}
@@ -686,7 +686,7 @@ CPControlKeyMask
*/
- (void)setView:(CPView)aView
{
if (_view == aView)
if (_view === aView)
return;
_view = aView;
@@ -754,19 +754,23 @@ CPControlKeyMask
var CPMenuItemTitleKey = @"CPMenuItemTitleKey",
CPMenuItemTargetKey = @"CPMenuItemTargetKey",
CPMenuItemActionKey = @"CPMenuItemActionKey",
CPMenuItemIsEnabledKey = @"CPMenuItemIsEnabledKey",
CPMenuItemIsHiddenKey = @"CPMenuItemIsHiddenKey",
CPMenuItemTagKey = @"CPMenuItemTagKey",
CPMenuItemImageKey = @"CPMenuItemImageKey",
CPMenuItemAlternateImageKey = @"CPMenuItemAlternateImageKey",
CPMenuItemSubmenuKey = @"CPMenuItemSubmenuKey",
CPMenuItemMenuKey = @"CPMenuItemMenuKey",
CPMenuItemRepresentedObjectKey = @"CPMenuItemRepresentedObjectKey";
CPMenuItemRepresentedObjectKey = @"CPMenuItemRepresentedObjectKey",
CPMenuItemViewKey = @"CPMenuItemViewKey";
#define DEFAULT_VALUE(aKey, aDefaultValue) [aCoder containsValueForKey:(aKey)] ? [aCoder decodeObjectForKey:(aKey)] : (aDefaultValue)
#define ENCODE_IFNOT(aKey, aValue, aDefaultValue) if ((aValue) !== (aDefaultValue)) [aCoder encodeObject:(aValue) forKey:(aKey)];
@implementation CPMenuItem (CPCoding)
/*!
@@ -787,22 +791,21 @@ var CPMenuItemTitleKey = @"CPMenuItemTitleKey",
_target = [aCoder decodeObjectForKey:CPMenuItemTargetKey];
_action = [aCoder decodeObjectForKey:CPMenuItemActionKey];
_isEnabled = [aCoder decodeObjectForKey:CPMenuItemIsEnabledKey];
_isHidden = [aCoder decodeObjectForKey:CPMenuItemIsHiddenKey];
_tag = [aCoder containsValueForKey:CPMenuItemTagKey] ? [aCoder decodeObjectForKey:CPMenuItemTagKey] : 0;
_isEnabled = DEFAULT_VALUE(CPMenuItemIsEnabledKey, YES);
_isHidden = DEFAULT_VALUE(CPMenuItemIsHiddenKey, NO);
_tag = DEFAULT_VALUE(CPMenuItemTagKey, 0);
// int _state;
_image = [aCoder decodeObjectForKey:CPMenuItemImageKey];
_alternateImage = [aCoder decodeObjectForKey:CPMenuItemAlternateImageKey];
_image = DEFAULT_VALUE(CPMenuItemImageKey, nil);
_alternateImage = DEFAULT_VALUE(CPMenuItemAlternateImageKey, nil);
// CPImage _onStateImage;
// CPImage _offStateImage;
// CPImage _mixedStateImage;
_submenu = [aCoder decodeObjectForKey:CPMenuItemSubmenuKey];
_menu = [aCoder decodeObjectForKey:CPMenuItemMenuKey];
_submenu = DEFAULT_VALUE(CPMenuItemSubmenuKey, nil);
_menu = DEFAULT_VALUE(CPMenuItemMenuKey, nil);
// CPString _keyEquivalent;
// unsigned _keyEquivalentModifierMask;
@@ -810,12 +813,11 @@ var CPMenuItemTitleKey = @"CPMenuItemTitleKey",
// BOOL _isAlternate;
// int _indentationLevel;
// CPString _toolTip;
_representedObject = [aCoder decodeObjectForKey:CPMenuItemRepresentedObjectKey];
// id _representedObject;
// CPView _view;
_representedObject = DEFAULT_VALUE(CPMenuItemRepresentedObjectKey, nil);
_view = DEFAULT_VALUE(CPMenuItemViewKey, nil);
}
return self;
@@ -832,19 +834,19 @@ var CPMenuItemTitleKey = @"CPMenuItemTitleKey",
[aCoder encodeObject:_target forKey:CPMenuItemTargetKey];
[aCoder encodeObject:_action forKey:CPMenuItemActionKey];
[aCoder encodeObject:_isEnabled forKey:CPMenuItemIsEnabledKey];
[aCoder encodeObject:_isHidden forKey:CPMenuItemIsHiddenKey];
ENCODE_IFNOT(CPMenuItemIsEnabledKey, _isEnabled, YES);
ENCODE_IFNOT(CPMenuItemIsHiddenKey, _isHidden, NO);
if (_tag !== 0)
[aCoder encodeObject:_tag forKey:CPMenuItemTagKey];
ENCODE_IFNOT(CPMenuItemTagKey, _tag, 0);
[aCoder encodeObject:_image forKey:CPMenuItemImageKey];
[aCoder encodeObject:_alternateImage forKey:CPMenuItemAlternateImageKey];
ENCODE_IFNOT(CPMenuItemImageKey, _image, nil);
ENCODE_IFNOT(CPMenuItemAlternateImageKey, _alternateImage, nil);
[aCoder encodeObject:_submenu forKey:CPMenuItemSubmenuKey];
[aCoder encodeObject:_menu forKey:CPMenuItemMenuKey];
[aCoder encodeObject:_representedObject forKey:CPMenuItemRepresentedObjectKey];
ENCODE_IFNOT(CPMenuItemSubmenuKey, _submenu, nil);
ENCODE_IFNOT(CPMenuItemMenuKey, _menu, nil);
ENCODE_IFNOT(CPMenuItemRepresentedObjectKey, _representedObject, nil);
ENCODE_IFNOT(CPMenuItemViewKey, _view, nil)
}
@end
+13 -5
View File
@@ -2221,7 +2221,12 @@ var CPViewAutoresizingMaskKey = @"CPViewAutoresizingMask",
_tag = [aCoder decodeIntForKey:CPViewTagKey];
_window = [aCoder decodeObjectForKey:CPViewWindowKey];
_subviews = [aCoder decodeObjectForKey:CPViewSubviewsKey];
if ([aCoder containsValueForKey:CPViewSubviewsKey])
_subviews = [aCoder decodeObjectForKey:CPViewSubviewsKey];
else
_subviews = [];
_superview = [aCoder decodeObjectForKey:CPViewSuperviewKey];
_autoresizingMask = [aCoder decodeIntForKey:CPViewAutoresizingMaskKey] || 0;
@@ -2252,7 +2257,7 @@ var CPViewAutoresizingMaskKey = @"CPViewAutoresizingMask",
[self setBackgroundColor:[aCoder decodeObjectForKey:CPViewBackgroundColorKey]];
_theme = [CPTheme defaultTheme];
_themeState = [aCoder decodeIntForKey:CPViewThemeStateKey];
_themeState = CPThemeState([aCoder decodeIntForKey:CPViewThemeStateKey]);
_themeAttributes = {};
var theClass = [self class],
@@ -2286,14 +2291,17 @@ var CPViewAutoresizingMaskKey = @"CPViewAutoresizingMask",
{
[super encodeWithCoder:aCoder];
if (_tag != -1)
if (_tag !== -1)
[aCoder encodeInt:_tag forKey:CPViewTagKey];
[aCoder encodeRect:_frame forKey:CPViewFrameKey];
[aCoder encodeRect:_bounds forKey:CPViewBoundsKey];
[aCoder encodeConditionalObject:_window forKey:CPViewWindowKey];
[aCoder encodeObject:_subviews forKey:CPViewSubviewsKey];
if (_subviews.length > 0)
[aCoder encodeObject:_subviews forKey:CPViewSubviewsKey];
[aCoder encodeConditionalObject:_superview forKey:CPViewSuperviewKey];
[aCoder encodeInt:_autoresizingMask forKey:CPViewAutoresizingMaskKey];
@@ -2310,7 +2318,7 @@ var CPViewAutoresizingMaskKey = @"CPViewAutoresizingMask",
[aCoder encodeConditionalObject:[self nextKeyView] forKey:CPViewNextKeyViewKey];
[aCoder encodeConditionalObject:[self previousKeyView] forKey:CPViewPreviousKeyViewKey];
[aCoder encodeInt:_themeState forKey:CPViewThemeStateKey];
[aCoder encodeInt:CPThemeStateName(_themeState) forKey:CPViewThemeStateKey];
for (var attributeName in _themeAttributes)
if (_themeAttributes.hasOwnProperty(attributeName))