44 #pragma mark Initialization
53 + (
CPStepper)stepperWithInitialValue:(
float)aValue minValue:(
float)aMinValue maxValue:(
float)aMaxValue
55 var stepper = [[
CPStepper alloc] initWithFrame:CGRectMakeZero()];
80 + (Class)_binderClassForBinding:(
CPString)aBinding
82 if (aBinding == CPValueBinding || aBinding == CPMinValueBinding || aBinding == CPMaxValueBinding)
83 return [_CPStepperValueBinder class];
85 return [
super _binderClassForBinding:aBinding];
90 if (aBinding == CPValueBinding)
91 return @"doubleValue";
93 return [
super _replacementKeyPathForBinding:aBinding];
101 - (id)initWithFrame:(CGRect)aFrame
103 if (
self = [super initWithFrame:aFrame])
122 _buttonUp = [[
CPButton alloc] initWithFrame:CGRectMakeZero()];
123 [_buttonUp setContinuous:_autorepeat];
124 [_buttonUp setTarget:self];
125 [_buttonUp setAction:@selector(_buttonDidClick:)];
126 [_buttonUp setAutoresizingMask:CPViewNotSizable];
127 [
self addSubview:_buttonUp];
129 _buttonDown = [[
CPButton alloc] initWithFrame:CGRectMakeZero()];
130 [_buttonDown setContinuous:_autorepeat];
131 [_buttonDown setTarget:self];
132 [_buttonDown setAction:@selector(_buttonDidClick:)];
133 [_buttonDown setAutoresizingMask:CPViewNotSizable];
135 [
self setContinuous:_autorepeat];
136 [
self addSubview:_buttonDown];
138 [
self setNeedsLayout];
142 #pragma mark Superclass overrides
148 - (void)setEnabled:(BOOL)shouldEnabled
152 [_buttonUp setEnabled:shouldEnabled];
153 [_buttonDown setEnabled:shouldEnabled];
157 - (void)setFrame:(CGRect)aFrame
159 var upSize = [
self valueForThemeAttribute:@"up-button-size"],
160 downSize = [
self valueForThemeAttribute:@"down-button-size"],
161 minSize = CGSizeMake(upSize.width, upSize.height + downSize.height),
162 frame = CGRectMakeCopy(aFrame);
164 frame.size.width = MAX(minSize.width,
frame.size.width);
165 frame.size.height = MAX(minSize.height,
frame.size.height);
166 [
super setFrame:frame];
170 - (void)layoutSubviews
172 var aFrame = [
self frame],
173 upSize = [
self valueForThemeAttribute:@"up-button-size"],
174 downSize = [
self valueForThemeAttribute:@"down-button-size"],
175 upFrame = CGRectMake(aFrame.size.width - upSize.width, 0, upSize.width, upSize.height),
176 downFrame = CGRectMake(aFrame.size.width - downSize.width, upSize.height, downSize.width, downSize.height);
178 [_buttonUp setFrame:upFrame];
179 [_buttonDown setFrame:downFrame];
181 [_buttonUp setValue:[
self valueForThemeAttribute:@"bezel-color-up-button" inState:CPThemeStateBordered] forThemeAttribute:@"bezel-color" inState:CPThemeStateBordered];
182 [_buttonUp setValue:[
self valueForThemeAttribute:@"bezel-color-up-button" inState:CPThemeStateBordered | CPThemeStateDisabled] forThemeAttribute:@"bezel-color" inState:CPThemeStateBordered | CPThemeStateDisabled];
183 [_buttonUp setValue:[
self valueForThemeAttribute:@"bezel-color-up-button" inState:CPThemeStateBordered | CPThemeStateHighlighted] forThemeAttribute:@"bezel-color" inState:CPThemeStateBordered | CPThemeStateHighlighted];
184 [_buttonDown setValue:[
self valueForThemeAttribute:@"bezel-color-down-button" inState:CPThemeStateBordered] forThemeAttribute:@"bezel-color" inState:CPThemeStateBordered];
185 [_buttonDown setValue:[
self valueForThemeAttribute:@"bezel-color-down-button" inState:CPThemeStateBordered | CPThemeStateDisabled] forThemeAttribute:@"bezel-color" inState:CPThemeStateBordered | CPThemeStateDisabled];
186 [_buttonDown setValue:[
self valueForThemeAttribute:@"bezel-color-down-button" inState:CPThemeStateBordered | CPThemeStateHighlighted] forThemeAttribute:@"bezel-color" inState:CPThemeStateBordered | CPThemeStateHighlighted];
191 [
self setFrame:CGRectMake([
self frameOrigin].x, [
self frameOrigin].y, 0, 0)];
198 - (void)setAutorepeat:(BOOL)shouldAutoRepeat
200 if (shouldAutoRepeat !== _autorepeat)
202 [_buttonUp setContinuous:shouldAutoRepeat];
203 [_buttonDown setContinuous:shouldAutoRepeat];
213 - (void)setDoubleValue:(
double)aValue
215 if (aValue > _maxValue)
216 [
super setDoubleValue:_valueWraps ? _minValue : _maxValue];
217 else if (aValue < _minValue)
218 [
super setDoubleValue:_valueWraps ? _maxValue : _minValue];
227 - (IBAction)_buttonDidClick:(
id)aSender
229 if (![
self isEnabled])
232 if (aSender == _buttonUp)
233 [
self setDoubleValue:([
self doubleValue] + _increment)];
235 [
self setDoubleValue:([
self doubleValue] - _increment)];
237 [
self sendAction:[
self action] to:[
self target]];
244 - (IBAction)performClickUp:(
id)aSender
246 [_buttonUp performClick:aSender];
253 - (IBAction)performClickDown:(
id)aSender
255 [_buttonDown performClick:aSender];
272 @"up-button-size": CGSizeMakeZero(),
273 @"down-button-size": CGSizeMakeZero(),
278 @implementation _CPStepperValueBinder :
CPBinder
285 var placeholder = (aBinding == CPMaxValueBinding) ? [_source maxValue] : [_source minValue];
287 [
super _updatePlaceholdersWithOptions:options];
289 [
self _setPlaceholder:placeholder forMarker:CPMultipleValuesMarker isDefault:YES];
290 [
self _setPlaceholder:placeholder forMarker:CPNoSelectionMarker isDefault:YES];
291 [
self _setPlaceholder:placeholder forMarker:CPNotApplicableMarker isDefault:YES];
292 [
self _setPlaceholder:placeholder forMarker:CPNullMarker isDefault:YES];
307 if (
self = [super initWithCoder:aCoder])
309 _increment = [aCoder decodeIntForKey:CPStepperIncrement];
310 _minValue = [aCoder decodeIntForKey:CPStepperMinValue];
311 _maxValue = [aCoder decodeIntForKey:CPStepperMaxValue];
312 _valueWraps = [aCoder decodeBoolForKey:CPStepperValueWraps];
313 _autorepeat = [aCoder decodeBoolForKey:CPStepperAutorepeat];
325 [aCoder encodeInt:_increment forKey:CPStepperIncrement];
328 [aCoder encodeInt:_minValue forKey:CPStepperMinValue];
330 [aCoder encodeInt:_maxValue forKey:CPStepperMaxValue];
332 [aCoder encodeBool:_valueWraps forKey:CPStepperValueWraps];
334 [aCoder encodeBool:_autorepeat forKey:CPStepperAutorepeat];
352 - (void)setValueWraps:(BOOL)aValue
354 _valueWraps = aValue;
376 - (void)setIncrement:(
int)aValue
392 - (void)setMaxValue:(
int)aValue
408 - (void)setMinValue:(
int)aValue