mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-09-27 04:37:41 +00:00
Refs #1527. Backwards compatibility.
If no highlight or state masks were encoded (button was encoded prior to them being added), make sure to let the default settings stand.
This commit is contained in:
+12
-6
@@ -217,17 +217,13 @@ CPButtonImageOffset = 3.0;
|
||||
{
|
||||
if (!anObjectValue || anObjectValue === @"" || ([anObjectValue intValue] === 0))
|
||||
anObjectValue = CPOffState;
|
||||
|
||||
else if (![anObjectValue isKindOfClass:[CPNumber class]])
|
||||
anObjectValue = CPOnState;
|
||||
|
||||
else if (anObjectValue >= CPOnState)
|
||||
anObjectValue = CPOnState
|
||||
|
||||
else if (anObjectValue < CPOffState)
|
||||
if ([self allowsMixedState])
|
||||
anObjectValue = CPMixedState;
|
||||
|
||||
else
|
||||
anObjectValue = CPOnState;
|
||||
|
||||
@@ -895,8 +891,18 @@ var CPButtonImageKey = @"CPButtonImageKey",
|
||||
_alternateTitle = [aCoder decodeObjectForKey:CPButtonAlternateTitleKey];
|
||||
_allowsMixedState = [aCoder decodeBoolForKey:CPButtonAllowsMixedStateKey];
|
||||
|
||||
_highlightsBy = [aCoder decodeIntForKey:CPButtonHighlightsByKey];
|
||||
_showsStateBy = [aCoder decodeIntForKey:CPButtonShowsStateByKey];
|
||||
if ([aCoder containsValueForKey:CPButtonHighlightsByKey])
|
||||
{
|
||||
// If one exists, assume both do.
|
||||
_highlightsBy = [aCoder decodeIntForKey:CPButtonHighlightsByKey];
|
||||
_showsStateBy = [aCoder decodeIntForKey:CPButtonShowsStateByKey];
|
||||
}
|
||||
else
|
||||
{
|
||||
// Backwards compatibility: if this CPButton was encoded before coding of
|
||||
// highlightsBy and showsStateBy were added, we should just use the
|
||||
// default values from _init rather than overwriting with 0, 0.
|
||||
}
|
||||
|
||||
[self setImageDimsWhenDisabled:[aCoder decodeObjectForKey:CPButtonImageDimsWhenDisabledKey]];
|
||||
|
||||
|
||||
@@ -186,6 +186,30 @@
|
||||
// The default mask should be that of CPMomentaryPushInButton.
|
||||
[self assert:CPPushInButtonMask | CPGrayButtonMask | CPBackgroundButtonMask equals:[button highlightsBy]];
|
||||
[self assert:0 equals:[button showsStateBy]];
|
||||
|
||||
[button setButtonType:CPPushOnPushOffButton];
|
||||
|
||||
[self assert:CPPushInCellMask | CPChangeGrayCellMask | CPChangeBackgroundCellMask equals:[button highlightsBy]];
|
||||
[self assert:CPChangeBackgroundCellMask | CPChangeGrayCellMask equals:[button showsStateBy]];
|
||||
|
||||
// Test archiving.
|
||||
|
||||
var archived = [CPKeyedArchiver archivedDataWithRootObject:button],
|
||||
unarchived = [CPKeyedUnarchiver unarchiveObjectWithData:archived];
|
||||
|
||||
[self assert:CPPushInCellMask | CPChangeGrayCellMask | CPChangeBackgroundCellMask equals:[button highlightsBy]];
|
||||
[self assert:CPChangeBackgroundCellMask | CPChangeGrayCellMask equals:[button showsStateBy]];
|
||||
|
||||
// Make sure that if highlightsBy and showsStateBy were explicitly set to 0 and 0 (making the button basically
|
||||
// not react to clicks), these settings are not replaced by the defaults when decoding.
|
||||
[button setHighlightsBy:0];
|
||||
[button setShowsStateBy:0];
|
||||
|
||||
archived = [CPKeyedArchiver archivedDataWithRootObject:button];
|
||||
unarchived = [CPKeyedUnarchiver unarchiveObjectWithData:archived];
|
||||
|
||||
[self assert:0 equals:[button highlightsBy]];
|
||||
[self assert:0 equals:[button showsStateBy]];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user