44 #pragma mark Initialization
53 + (
CPStepper)stepperWithInitialValue:(
float)aValue minValue:(
float)aMinValue maxValue:(
float)aMaxValue
55 var stepper = [[
CPStepper alloc] initWithFrame:_CGRectMake(0, 0, 19, 25)];
76 + (Class)_binderClassForBinding:(
CPString)theBinding
79 return [_CPStepperValueBinder class];
81 return [
super _binderClassForBinding:theBinding];
84 - (id)_replacementKeyPathForBinding:(
CPString)aBinding
87 return @"doubleValue";
89 return [
super _replacementKeyPathForBinding:aBinding];
97 - (id)initWithFrame:(CGRect)aFrame
99 if (
self = [super initWithFrame:aFrame])
118 _buttonUp = [[
CPButton alloc] initWithFrame:_CGRectMakeZero()];
119 [_buttonUp setContinuous:_autorepeat];
120 [_buttonUp setTarget:self];
121 [_buttonUp setAction:@selector(_buttonDidClick:)];
122 [_buttonUp setAutoresizingMask:CPViewNotSizable];
123 [
self addSubview:_buttonUp];
125 _buttonDown = [[
CPButton alloc] initWithFrame:_CGRectMakeZero()];
126 [_buttonDown setContinuous:_autorepeat];
127 [_buttonDown setTarget:self];
128 [_buttonDown setAction:@selector(_buttonDidClick:)];
129 [_buttonDown setAutoresizingMask:CPViewNotSizable];
131 [
self setContinuous:_autorepeat];
132 [
self addSubview:_buttonDown];
134 [
self setNeedsLayout];
138 #pragma mark Superclass overrides
144 - (void)setEnabled:(BOOL)shouldEnabled
148 [_buttonUp setEnabled:shouldEnabled];
149 [_buttonDown setEnabled:shouldEnabled];
153 - (void)setFrame:(CGRect)aFrame
157 minSize = _CGSizeMake(upSize.width, upSize.height + downSize.height),
158 frame = _CGRectMakeCopy(aFrame);
160 frame.size.width = MAX(minSize.width,
frame.size.width);
161 frame.size.height = MAX(minSize.height,
frame.size.height);
166 - (void)layoutSubviews
168 var aFrame = [
self frame],
171 upFrame = _CGRectMake(aFrame.size.width - upSize.width, 0, upSize.width, upSize.height),
172 downFrame = _CGRectMake(aFrame.size.width - downSize.width, upSize.height, downSize.width, downSize.height);
173 [_buttonUp setFrame:upFrame];
174 [_buttonDown setFrame:downFrame];
176 [_buttonUp setValue:[
self valueForThemeAttribute:@"bezel-color-up-button"
inState:CPThemeStateBordered] forThemeAttribute:@"bezel-color" inState:CPThemeStateBordered];
177 [_buttonUp setValue:[
self valueForThemeAttribute:@"bezel-color-up-button"
inState:CPThemeStateBordered | CPThemeStateDisabled] forThemeAttribute:@"bezel-color" inState:CPThemeStateBordered | CPThemeStateDisabled];
178 [_buttonUp setValue:[
self valueForThemeAttribute:@"bezel-color-up-button"
inState:CPThemeStateBordered | CPThemeStateHighlighted] forThemeAttribute:@"bezel-color" inState:CPThemeStateBordered | CPThemeStateHighlighted];
179 [_buttonDown setValue:[
self valueForThemeAttribute:@"bezel-color-down-button"
inState:CPThemeStateBordered] forThemeAttribute:@"bezel-color" inState:CPThemeStateBordered];
180 [_buttonDown setValue:[
self valueForThemeAttribute:@"bezel-color-down-button"
inState:CPThemeStateBordered | CPThemeStateDisabled] forThemeAttribute:@"bezel-color" inState:CPThemeStateBordered | CPThemeStateDisabled];
181 [_buttonDown setValue:[
self valueForThemeAttribute:@"bezel-color-down-button"
inState:CPThemeStateBordered | CPThemeStateHighlighted] forThemeAttribute:@"bezel-color" inState:CPThemeStateBordered | CPThemeStateHighlighted];
188 - (void)setAutorepeat:(BOOL)shouldAutoRepeat
190 if (shouldAutoRepeat !== _autorepeat)
192 [_buttonUp setContinuous:shouldAutoRepeat];
193 [_buttonDown setContinuous:shouldAutoRepeat];
203 - (void)setDoubleValue:(
float)aValue
205 if (aValue > _maxValue)
206 [
super setDoubleValue:_valueWraps ? _minValue : _maxValue];
207 else if (aValue < _minValue)
208 [
super setDoubleValue:_valueWraps ? _maxValue : _minValue];
217 - (IBAction)_buttonDidClick:(
id)aSender
219 if (![
self isEnabled])
222 if (aSender == _buttonUp)
223 [
self setDoubleValue:([
self doubleValue] + _increment)];
225 [
self setDoubleValue:([
self doubleValue] - _increment)];
227 [
self sendAction:[
self action] to:[
self target]];
234 - (IBAction)performClickUp:(
id)aSender
236 [_buttonUp performClick:aSender];
243 - (IBAction)performClickDown:(
id)aSender
245 [_buttonDown performClick:aSender];
257 + (id)themeAttributes
260 forKeys:[@"bezel-color-up-button", @"bezel-color-down-button", @"up-button-size", @"down-button-size"]];
264 @implementation _CPStepperValueBinder :
CPBinder
271 var placeholder = (aBinding ==
CPMaxValueBinding) ? [_source maxValue] : [_source minValue];
273 [
super _updatePlaceholdersWithOptions:options];
275 [
self _setPlaceholder:placeholder forMarker:CPMultipleValuesMarker isDefault:YES];
276 [
self _setPlaceholder:placeholder forMarker:CPNoSelectionMarker isDefault:YES];
277 [
self _setPlaceholder:placeholder forMarker:CPNotApplicableMarker isDefault:YES];
278 [
self _setPlaceholder:placeholder forMarker:CPNullMarker isDefault:YES];
293 if (
self = [super initWithCoder:aCoder])
295 _increment = [aCoder decodeIntForKey:CPStepperIncrement];
296 _minValue = [aCoder decodeIntForKey:CPStepperMinValue];
297 _maxValue = [aCoder decodeIntForKey:CPStepperMaxValue];
298 _valueWraps = [aCoder decodeBoolForKey:CPStepperValueWraps];
299 _autorepeat = [aCoder decodeBoolForKey:CPStepperAutorepeat];
311 [aCoder encodeInt:_increment forKey:CPStepperIncrement];
314 [aCoder encodeInt:_minValue forKey:CPStepperMinValue];
316 [aCoder encodeInt:_maxValue forKey:CPStepperMaxValue];
318 [aCoder encodeBool:_valueWraps forKey:CPStepperValueWraps];
320 [aCoder encodeBool:_autorepeat forKey:CPStepperAutorepeat];
338 - (void)setValueWraps:(BOOL)aValue
340 _valueWraps = aValue;
362 - (void)setIncrement:(
int)aValue
378 - (void)setMaxValue:(
int)aValue
394 - (void)setMinValue:(
int)aValue