43 #pragma mark Initialization 52 + (id)stepperWithInitialValue:(
float)aValue minValue:(
float)aMinValue maxValue:(
float)aMaxValue
54 var stepper = [[
self alloc] initWithFrame:CGRectMakeZero()];
56 [
stepper setDoubleValue:aValue];
57 [
stepper setMinValue:aMinValue];
58 [
stepper setMaxValue:aMaxValue];
79 + (Class)_binderClassForBinding:(
CPString)aBinding
81 if (aBinding === CPValueBinding || aBinding === CPMinValueBinding || aBinding === CPMaxValueBinding)
82 return [_CPStepperValueBinder class];
84 return [
super _binderClassForBinding:aBinding];
89 if (aBinding === CPValueBinding)
90 return @"doubleValue";
92 return [
super _replacementKeyPathForBinding:aBinding];
100 - (id)initWithFrame:(CGRect)aFrame
102 if (
self = [super initWithFrame:aFrame])
121 _buttonUp = [[
CPButton alloc] initWithFrame:CGRectMakeZero()];
122 [_buttonUp setContinuous:_autorepeat];
123 [_buttonUp setTarget:self];
124 [_buttonUp setAction:@selector(_buttonDidClick:)];
125 [_buttonUp setAutoresizingMask:CPViewNotSizable];
126 [
self addSubview:_buttonUp];
128 _buttonDown = [[
CPButton alloc] initWithFrame:CGRectMakeZero()];
129 [_buttonDown setContinuous:_autorepeat];
130 [_buttonDown setTarget:self];
131 [_buttonDown setAction:@selector(_buttonDidClick:)];
132 [_buttonDown setAutoresizingMask:CPViewNotSizable];
134 [
self setContinuous:_autorepeat];
135 [
self addSubview:_buttonDown];
138 [
self setNeedsLayout];
141 - (void)setControlSize:(CPControlSize)aControlSize
148 #pragma mark Superclass overrides 154 - (void)setEnabled:(BOOL)shouldEnabled
158 [_buttonUp setEnabled:shouldEnabled];
159 [_buttonDown setEnabled:shouldEnabled];
163 - (void)setFrame:(CGRect)aFrame
165 var upSize = [
self currentValueForThemeAttribute:@"up-button-size"],
166 downSize = [
self currentValueForThemeAttribute:@"down-button-size"],
167 minSize = CGSizeMake(upSize.width, upSize.height + downSize.height),
168 frame = CGRectMakeCopy(aFrame);
170 frame.size.width = MAX(minSize.width,
frame.size.width);
171 frame.size.height = MAX(minSize.height,
frame.size.height);
176 - (void)layoutSubviews
178 var controlSizeThemeState = [
self _controlSizeThemeState],
179 aFrame = [
self frame],
180 upSize = [
self valueForThemeAttribute:@"up-button-size" inState:controlSizeThemeState],
181 downSize = [
self valueForThemeAttribute:@"down-button-size" inState:controlSizeThemeState],
182 upFrame = CGRectMake(0, 0, upSize.width, upSize.height),
183 downFrame = CGRectMake(0, upSize.height, downSize.width, downSize.height);
185 [_buttonUp setFrame:upFrame];
186 [_buttonDown setFrame:downFrame];
188 [_buttonUp setValue:[
self valueForThemeAttribute:@"bezel-color-up-button" inStates:[controlSizeThemeState, CPThemeStateBordered]] forThemeAttribute:@"bezel-color" inState:CPThemeStateBordered];
189 [_buttonUp setValue:[
self valueForThemeAttribute:@"bezel-color-up-button" inStates:[controlSizeThemeState, CPThemeStateBordered, CPThemeStateDisabled]] forThemeAttribute:@"bezel-color" inStates:[CPThemeStateBordered, CPThemeStateDisabled]];
190 [_buttonUp setValue:[
self valueForThemeAttribute:@"bezel-color-up-button" inStates:[controlSizeThemeState, CPThemeStateBordered, CPThemeStateHighlighted]] forThemeAttribute:@"bezel-color" inStates:[CPThemeStateBordered, CPThemeStateHighlighted]];
191 [_buttonDown setValue:[
self valueForThemeAttribute:@"bezel-color-down-button" inStates:[controlSizeThemeState, CPThemeStateBordered]] forThemeAttribute:@"bezel-color" inState:CPThemeStateBordered];
192 [_buttonDown setValue:[
self valueForThemeAttribute:@"bezel-color-down-button" inStates:[controlSizeThemeState, CPThemeStateBordered, CPThemeStateDisabled]] forThemeAttribute:@"bezel-color" inStates:[CPThemeStateBordered, CPThemeStateDisabled]];
193 [_buttonDown setValue:[
self valueForThemeAttribute:@"bezel-color-down-button" inStates:[controlSizeThemeState, CPThemeStateBordered, CPThemeStateHighlighted]] forThemeAttribute:@"bezel-color" inStates:[CPThemeStateBordered, CPThemeStateHighlighted]];
198 [
self setFrame:CGRectMake([
self frameOrigin].x, [
self frameOrigin].y, 0, 0)];
205 - (void)setAutorepeat:(BOOL)shouldAutoRepeat
207 if (shouldAutoRepeat !== _autorepeat)
209 [_buttonUp setContinuous:shouldAutoRepeat];
210 [_buttonDown setContinuous:shouldAutoRepeat];
220 - (void)setDoubleValue:(
double)aValue
222 if (aValue > _maxValue)
223 [
super setDoubleValue:_valueWraps ? _minValue : _maxValue];
224 else if (aValue < _minValue)
225 [
super setDoubleValue:_valueWraps ? _maxValue : _minValue];
234 - (IBAction)_buttonDidClick:(
id)aSender
236 if (![
self isEnabled])
239 if (aSender === _buttonUp)
240 [
self setDoubleValue:([
self doubleValue] + _increment)];
242 [
self setDoubleValue:([
self doubleValue] - _increment)];
244 [
self sendAction:[
self action] to:[
self target]];
251 - (IBAction)performClickUp:(
id)aSender
253 [_buttonUp performClick:aSender];
260 - (IBAction)performClickDown:(
id)aSender
262 [_buttonDown performClick:aSender];
279 @"up-button-size": CGSizeMakeZero(),
280 @"down-button-size": CGSizeMakeZero(),
285 @implementation _CPStepperValueBinder :
CPBinder 292 var placeholder = (aBinding === CPMaxValueBinding) ? [_source maxValue] : [_source minValue];
294 [
super _updatePlaceholdersWithOptions:options];
296 [
self _setPlaceholder:placeholder forMarker:CPMultipleValuesMarker isDefault:YES];
297 [
self _setPlaceholder:placeholder forMarker:CPNoSelectionMarker isDefault:YES];
298 [
self _setPlaceholder:placeholder forMarker:CPNotApplicableMarker isDefault:YES];
299 [
self _setPlaceholder:placeholder forMarker:CPNullMarker isDefault:YES];
314 if (
self = [super initWithCoder:aCoder])
316 _increment = [aCoder decodeIntForKey:CPStepperIncrement];
317 _minValue = [aCoder decodeIntForKey:CPStepperMinValue];
318 _maxValue = [aCoder decodeIntForKey:CPStepperMaxValue];
319 _valueWraps = [aCoder decodeBoolForKey:CPStepperValueWraps];
320 _autorepeat = [aCoder decodeBoolForKey:CPStepperAutorepeat];
332 [aCoder encodeInt:_increment forKey:CPStepperIncrement];
335 [aCoder encodeInt:_minValue forKey:CPStepperMinValue];
337 [aCoder encodeInt:_maxValue forKey:CPStepperMaxValue];
339 [aCoder encodeBool:_valueWraps forKey:CPStepperValueWraps];
341 [aCoder encodeBool:_autorepeat forKey:CPStepperAutorepeat];
359 - (void)setValueWraps:(BOOL)aValue
361 _valueWraps = aValue;
383 - (void)setIncrement:(
int)aValue
399 - (void)setMaxValue:(
int)aValue
415 - (void)setMinValue:(
int)aValue
void setContinuous:(BOOL flag)
An object representation of nil.
void setFrame:(CGRect aFrame)
void setControlSize:(CPControlSize aControlSize)
void setEnabled:(BOOL isEnabled)
A mutable key-value pair collection.
An immutable string (collection of characters).
Defines methods for use when archiving & restoring (enc/decoding).
void setDoubleValue:(double anObject)
id stepperWithInitialValue:minValue:maxValue:(float aValue, [minValue] float aMinValue, [maxValue] float aMaxValue)
void encodeWithCoder:(CPCoder aCoder)
CompletionHandlerAgent prototype increment
void setDoubleValue:(double aValue)