25 @
typedef CPProgressIndicatorStyle
58 CPControlSize _controlSize;
61 CPProgressIndicatorStyle _style;
65 BOOL _isDisplayedWhenStoppedSet;
66 BOOL _isDisplayedWhenStopped;
71 return @"progress-indicator";
79 @"default-height": 20,
87 + (Class)_binderClassForBinding:(
CPString)aBinding
89 if (aBinding ===
CPValueBinding || aBinding ===
@"isIndeterminate")
90 return [_CPProgressIndicatorBinder class];
92 return [
super _binderClassForBinding:aBinding];
95 - (id)initWithFrame:(CGRect)aFrame
107 _isDisplayedWhenStoppedSet = NO;
120 - (void)setUsesThreadedAnimation:(BOOL)aFlag
128 - (void)startAnimation:(
id)aSender
132 [
self _hideOrDisplay];
139 - (void)stopAnimation:(
id)aSender
143 [
self _hideOrDisplay];
149 - (BOOL)usesThreadedAnimation
159 - (void)incrementBy:(
double)aValue
167 - (void)setDoubleValue:(
double)aValue
169 _doubleValue = MIN(MAX(aValue, _minValue), _maxValue);
177 - (double)doubleValue
186 - (void)setMinValue:(
double)aValue
203 - (void)setMaxValue:(
double)aValue
221 - (void)setControlSize:(CPControlSize)aControlSize
223 if (_controlSize == aControlSize)
226 _controlSize = aControlSize;
234 - (CPControlSize)controlSize
242 - (void)setControlTint:(CPControlTint)aControlTint
249 - (CPControlTint)controlTint
257 - (void)setBezeled:(BOOL)isBezeled
273 - (void)setIndeterminate:(BOOL)indeterminate
275 if (_indeterminate == indeterminate)
278 _indeterminate = indeterminate;
286 - (BOOL)isIndeterminate
288 return _indeterminate;
295 - (void)setStyle:(CPProgressIndicatorStyle)aStyle
297 if (_style == aStyle)
313 [
self setFrameSize:[[CPProgressIndicatorSpinningStyleColors[_controlSize] patternImage] size]];
323 - (void)setDisplayedWhenStopped:(BOOL)isDisplayedWhenStopped
325 if (_isDisplayedWhenStoppedSet && _isDisplayedWhenStopped == isDisplayedWhenStopped)
328 _isDisplayedWhenStoppedSet = YES;
330 _isDisplayedWhenStopped = isDisplayedWhenStopped;
332 [
self _hideOrDisplay];
338 - (BOOL)isDisplayedWhenStopped
340 if (_isDisplayedWhenStoppedSet)
341 return _isDisplayedWhenStopped;
350 - (void)_hideOrDisplay
352 [
self setHidden:!_isAnimating && ![
self isDisplayedWhenStopped]];
355 - (void)setFrameSize:(CGSize)aSize
370 return [[
CPView alloc] initWithFrame:CGRectMakeZero()];
373 - (CGRect)rectForEphemeralSubviewNamed:(
CPString)aViewName
378 barWidth = width * ((_doubleValue - _minValue) / (_maxValue - _minValue));
380 if (barWidth > 0.0 && barWidth < 4.0)
386 return CGRectMake(0, 0, barWidth, [
self valueForThemeAttribute:
@"default-height"]);
393 - (void)updateBackgroundColor
405 - (void)layoutSubviews
443 if (
self = [super initWithCoder:aCoder])
445 _minValue = [aCoder decodeObjectForKey:@"_minValue"];
446 _maxValue = [aCoder decodeObjectForKey:@"_maxValue"];
447 _doubleValue = [aCoder decodeObjectForKey:@"_doubleValue"];
448 _controlSize = [aCoder decodeObjectForKey:@"_controlSize"];
449 _indeterminate = [aCoder decodeObjectForKey:@"_indeterminate"];
450 _style = [aCoder decodeIntForKey:@"_style"];
451 _isAnimating = [aCoder decodeObjectForKey:@"_isAnimating"];
452 _isDisplayedWhenStoppedSet = [aCoder decodeObjectForKey:@"_isDisplayedWhenStoppedSet"];
453 _isDisplayedWhenStopped = [aCoder decodeObjectForKey:@"_isDisplayedWhenStopped"];
470 [aCoder encodeObject:_minValue forKey:@"_minValue"];
471 [aCoder encodeObject:_maxValue forKey:@"_maxValue"];
472 [aCoder encodeObject:_doubleValue forKey:@"_doubleValue"];
473 [aCoder encodeObject:_controlSize forKey:@"_controlSize"];
474 [aCoder encodeObject:_indeterminate forKey:@"_indeterminate"];
475 [aCoder encodeInt:_style forKey:@"_style"];
476 [aCoder encodeObject:_isAnimating forKey:@"_isAnimating"];
477 [aCoder encodeObject:_isDisplayedWhenStoppedSet forKey:@"_isDisplayedWhenStoppedSet"];
478 [aCoder encodeObject:_isDisplayedWhenStopped forKey:@"_isDisplayedWhenStopped"];
482 @implementation _CPProgressIndicatorBinder :
CPBinder
491 [
self _setPlaceholder:value forMarker:CPMultipleValuesMarker isDefault:YES];
492 [
self _setPlaceholder:value forMarker:CPNoSelectionMarker isDefault:YES];
493 [
self _setPlaceholder:value forMarker:CPNotApplicableMarker isDefault:YES];
494 [
self _setPlaceholder:value forMarker:CPNullMarker isDefault:YES];
497 - (id)valueForBinding:(
CPString)aBinding
500 return [_source doubleValue];
501 else if (aBinding ===
@"isIndeterminate")
502 [_source isIndeterminate];
504 return [
super valueForBinding:aBinding];
507 - (BOOL)_setValue:(
id)aValue forBinding:(
CPString)aBinding
510 [_source setDoubleValue:aValue];
511 else if (aBinding ===
@"isIndeterminate")
512 [_source setIndeterminate:aValue];
519 - (void)setValue:(
id)aValue forBinding:(
CPString)aBinding
521 if (![
self _setValue:aValue forBinding:aBinding])
522 [
super setValue:aValue forBinding:aBinding];
525 - (void)setPlaceholderValue:(
id)aValue withMarker:(
CPString)aMarker forBinding:(
CPString)aBinding
527 if (![
self _setValue:aValue forBinding:aBinding])
528 [
super setPlaceholderValue:aValue withMarker:aMarker forBinding:aBinding];