diff --git a/ChangeLog b/ChangeLog index ee8af2191..c3b5c7c3c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2010-02-01 Eric Wasylishen + + * Source/NSStepperCell.m: Correct clamping behaviour as I did to + NSSliderCell earlier. + 2010-02-01 Eric Wasylishen * Source/GSThemeDrawing.m: Preliminary support for themeing the window diff --git a/Source/NSStepperCell.m b/Source/NSStepperCell.m index de1563901..274346ef3 100644 --- a/Source/NSStepperCell.m +++ b/Source/NSStepperCell.m @@ -28,6 +28,7 @@ #include "config.h" +#import #import "AppKit/NSApplication.h" #import "AppKit/NSControl.h" #import "AppKit/NSEvent.h" @@ -73,8 +74,8 @@ [self setWraps: NO]; _autorepeat = YES; _valueWraps = YES; - _maxValue = 59; - _minValue = 0; + [self setMaxValue: 59]; + [self setMinValue: 0]; _increment = 1; highlightUp = NO; @@ -91,6 +92,8 @@ - (void) setMaxValue: (double)maxValue { _maxValue = maxValue; + if ([self doubleValue] > _maxValue) + [self setDoubleValue: _maxValue]; } - (double) minValue @@ -101,6 +104,31 @@ - (void) setMinValue: (double)minValue { _minValue = minValue; + if ([self doubleValue] < _minValue) + [self setDoubleValue: _minValue]; +} + +- (void) setObjectValue: (id)anObject +{ + // NOTE: valueWraps has no effect on setObjectValue: + // FIXME: Copied from NSSliderCell.. can we share the code somehow? + + // If the provided object doesn't respond to doubeValue, or our minValue + // is greater than our maxValue, we set our value to our minValue + // (this arbitrary choice matches OS X) + if ([anObject respondsToSelector: @selector(doubleValue)] == NO || + _minValue > _maxValue) + [super setObjectValue: [NSNumber numberWithDouble: _minValue]]; + else + { + double aDouble = [anObject doubleValue]; + if (aDouble < _minValue) + [super setObjectValue: [NSNumber numberWithDouble: _minValue]]; + else if (aDouble > _maxValue) + [super setObjectValue: [NSNumber numberWithDouble: _maxValue]]; + else + [super setObjectValue: anObject]; + } } - (double) increment @@ -391,13 +419,6 @@ else if (newValue < minValue) newValue = newValue + maxValue - minValue + 1; } - else - { - if (newValue > maxValue) - newValue = maxValue; - else if (newValue < minValue) - newValue = minValue; - } [self setDoubleValue: newValue]; } @@ -416,13 +437,6 @@ else if (newValue < minValue) newValue = newValue + maxValue - minValue + 1; } - else - { - if (newValue > maxValue) - newValue = maxValue; - else if (newValue < minValue) - newValue = minValue; - } [self setDoubleValue: newValue]; }