00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 @import <AppKit/CGGeometry.j>
00024 @import <AppKit/CPImageView.j>
00025 @import <AppKit/CPView.j>
00026
00027 #include "CoreGraphics/CGGeometry.h"
00028
00029
00030
00031
00032
00033
00034 CPProgressIndicatorBarStyle = 0;
00035
00036
00037
00038
00039 CPProgressIndicatorSpinningStyle = 1;
00040
00041
00042
00043
00044 CPProgressIndicatorHUDBarStyle = 2;
00045
00046 var CPProgressIndicatorSpinningStyleColors = nil,
00047
00048 CPProgressIndicatorClassName = nil,
00049 CPProgressIndicatorStyleIdentifiers = nil,
00050 CPProgressIndicatorStyleSizes = nil;
00051
00058 @implementation CPProgressIndicator : CPView
00059 {
00060 double _minValue;
00061 double _maxValue;
00062
00063 double _doubleValue;
00064
00065 CPControlSize _controlSize;
00066
00067 BOOL _isIndeterminate;
00068 CPProgressIndicatorStyle _style;
00069
00070 BOOL _isAnimating;
00071
00072 BOOL _isDisplayedWhenStoppedSet;
00073 BOOL _isDisplayedWhenStopped;
00074
00075 CPView _barView;
00076 }
00077
00078
00079
00080
00081 + (void)initialize
00082 {
00083 if (self != [CPProgressIndicator class])
00084 return;
00085
00086 var bundle = [CPBundle bundleForClass:self];
00087
00088 CPProgressIndicatorSpinningStyleColors = [];
00089
00090 CPProgressIndicatorSpinningStyleColors[CPMiniControlSize] = [CPColor colorWithPatternImage:[[CPImage alloc] initWithContentsOfFile:
00091 [bundle pathForResource:@"CPProgressIndicator/CPProgressIndicatorSpinningStyleRegular.gif"] size:CGSizeMake(64.0, 64.0)]];
00092 CPProgressIndicatorSpinningStyleColors[CPSmallControlSize] = [CPColor colorWithPatternImage:[[CPImage alloc] initWithContentsOfFile:
00093 [bundle pathForResource:@"CPProgressIndicator/CPProgressIndicatorSpinningStyleRegular.gif"] size:CGSizeMake(64.0, 64.0)]];
00094 CPProgressIndicatorSpinningStyleColors[CPRegularControlSize] = [CPColor colorWithPatternImage:[[CPImage alloc] initWithContentsOfFile:
00095 [bundle pathForResource:@"CPProgressIndicator/CPProgressIndicatorSpinningStyleRegular.gif"] size:CGSizeMake(64.0, 64.0)]];
00096
00097 CPProgressIndicatorBezelBorderViewPool = [];
00098
00099 var start = CPProgressIndicatorBarStyle,
00100 end = CPProgressIndicatorHUDBarStyle;
00101
00102 for (; start <= end; ++start)
00103 {
00104 CPProgressIndicatorBezelBorderViewPool[start] = [];
00105
00106 CPProgressIndicatorBezelBorderViewPool[start][CPMiniControlSize] = [];
00107 CPProgressIndicatorBezelBorderViewPool[start][CPSmallControlSize] = [];
00108 CPProgressIndicatorBezelBorderViewPool[start][CPRegularControlSize] = [];
00109 }
00110
00111 CPProgressIndicatorClassName = [self className];
00112
00113
00114 CPProgressIndicatorStyleIdentifiers = [];
00115
00116 CPProgressIndicatorStyleIdentifiers[CPProgressIndicatorBarStyle] = @"Bar";
00117 CPProgressIndicatorStyleIdentifiers[CPProgressIndicatorSpinningStyle] = @"Spinny";
00118 CPProgressIndicatorStyleIdentifiers[CPProgressIndicatorHUDBarStyle] = @"HUDBar";
00119
00120 var regularIdentifier = _CPControlIdentifierForControlSize(CPRegularControlSize),
00121 smallIdentifier = _CPControlIdentifierForControlSize(CPSmallControlSize),
00122 miniIdentifier = _CPControlIdentifierForControlSize(CPMiniControlSize);
00123
00124 CPProgressIndicatorStyleSizes = [];
00125
00126
00127 var prefix = CPProgressIndicatorClassName + @"BezelBorder" + CPProgressIndicatorStyleIdentifiers[CPProgressIndicatorBarStyle];
00128
00129 CPProgressIndicatorStyleSizes[prefix + regularIdentifier] = [_CGSizeMake(3.0, 15.0), _CGSizeMake(1.0, 15.0), _CGSizeMake(3.0, 15.0)];
00130 CPProgressIndicatorStyleSizes[prefix + smallIdentifier] = [_CGSizeMake(3.0, 15.0), _CGSizeMake(1.0, 15.0), _CGSizeMake(3.0, 15.0)];
00131 CPProgressIndicatorStyleSizes[prefix + miniIdentifier] = [_CGSizeMake(3.0, 15.0), _CGSizeMake(1.0, 15.0), _CGSizeMake(3.0, 15.0)];
00132
00133 prefix = CPProgressIndicatorClassName + @"Bar" + CPProgressIndicatorStyleIdentifiers[CPProgressIndicatorBarStyle];
00134
00135 CPProgressIndicatorStyleSizes[prefix + regularIdentifier] = _CGSizeMake(1.0, 9.0);
00136 CPProgressIndicatorStyleSizes[prefix + smallIdentifier] = _CGSizeMake(1.0, 9.0);
00137 CPProgressIndicatorStyleSizes[prefix + miniIdentifier] = _CGSizeMake(1.0, 9.0);
00138
00139
00140 prefix = CPProgressIndicatorClassName + @"BezelBorder" + CPProgressIndicatorStyleIdentifiers[CPProgressIndicatorHUDBarStyle];
00141
00142 CPProgressIndicatorStyleSizes[prefix + regularIdentifier] = [_CGSizeMake(3.0, 15.0), _CGSizeMake(1.0, 15.0), _CGSizeMake(3.0, 15.0)];
00143 CPProgressIndicatorStyleSizes[prefix + smallIdentifier] = [_CGSizeMake(3.0, 15.0), _CGSizeMake(1.0, 15.0), _CGSizeMake(3.0, 15.0)];
00144 CPProgressIndicatorStyleSizes[prefix + miniIdentifier] = [_CGSizeMake(3.0, 15.0), _CGSizeMake(1.0, 15.0), _CGSizeMake(3.0, 15.0)];
00145
00146 prefix = CPProgressIndicatorClassName + @"Bar" + CPProgressIndicatorStyleIdentifiers[CPProgressIndicatorHUDBarStyle];
00147
00148 CPProgressIndicatorStyleSizes[prefix + regularIdentifier] = _CGSizeMake(1.0, 9.0);
00149 CPProgressIndicatorStyleSizes[prefix + smallIdentifier] = _CGSizeMake(1.0, 9.0);
00150 CPProgressIndicatorStyleSizes[prefix + miniIdentifier] = _CGSizeMake(1.0, 9.0);
00151 }
00152
00153 - (id)initWithFrame:(CGRect)aFrame
00154 {
00155 self = [super initWithFrame:aFrame];
00156
00157 if (self)
00158 {
00159 _minValue = 0.0;
00160 _maxValue = 100.0;
00161
00162 _doubleValue = 0.0;
00163
00164 _style = CPProgressIndicatorBarStyle;
00165 _isDisplayedWhenStoppedSet = NO;
00166
00167 _controlSize = CPRegularControlSize;
00168
00169 [self updateBackgroundColor];
00170 [self drawBar];
00171 }
00172
00173 return self;
00174 }
00175
00176
00177
00178
00179 - (void)setUsesThreadedAnimation:(BOOL)aFlag
00180 {
00181 }
00182
00187 - (void)startAnimation:(id)aSender
00188 {
00189 _isAnimating = YES;
00190
00191 [self _hideOrDisplay];
00192 }
00193
00198 - (void)stopAnimation:(id)aSender
00199 {
00200 _isAnimating = NO;
00201
00202 [self _hideOrDisplay];
00203 }
00204
00208 - (BOOL)usesThreadedAnimation
00209 {
00210 return NO;
00211 }
00212
00213
00218 - (void)incrementBy:(double)aValue
00219 {
00220 [self setDoubleValue:_doubleValue + aValue];
00221 }
00222
00226 - (void)setDoubleValue:(double)aValue
00227 {
00228 _doubleValue = MIN(MAX(aValue, _minValue), _maxValue);
00229
00230 [self drawBar];
00231 }
00232
00236 - (double)doubleValue
00237 {
00238 return _doubleValue;
00239 }
00240
00245 - (void)setMinValue:(double)aValue
00246 {
00247 _minValue = aValue;
00248 }
00249
00253 - (double)minValue
00254 {
00255 return _minValue;
00256 }
00257
00262 - (void)setMaxValue:(double)aValue
00263 {
00264 _maxValue = aValue;
00265 }
00266
00270 - (double)maxValue
00271 {
00272 return _maxValue;
00273 }
00274
00275
00280 - (void)setControlSize:(CPControlSize)aControlSize
00281 {
00282 if (_controlSize == aControlSize)
00283 return;
00284
00285 _controlSize = aControlSize;
00286
00287 [self updateBackgroundColor];
00288 }
00289
00293 - (CPControlSize)controlSize
00294 {
00295 return _controlSize;
00296 }
00297
00298
00299
00300
00301 - (void)setControlTint:(CPControlTint)aControlTint
00302 {
00303 }
00304
00305
00306
00307
00308 - (CPControlTint)controlTint
00309 {
00310 return 0;
00311 }
00312
00313
00314
00315
00316 - (void)setBezeled:(BOOL)isBezeled
00317 {
00318 }
00319
00320
00321
00322
00323 - (BOOL)isBezeled
00324 {
00325 return YES;
00326 }
00327
00332 - (void)setIndeterminate:(BOOL)isIndeterminate
00333 {
00334 if (_isIndeterminate == isIndeterminate)
00335 return;
00336
00337 _isIndeterminate = isIndeterminate;
00338
00339 [self updateBackgroundColor];
00340 }
00341
00345 - (BOOL)isIndeterminate
00346 {
00347 return _isIndeterminate;
00348 }
00349
00354 - (void)setStyle:(CPProgressIndicatorStyle)aStyle
00355 {
00356 if (_style == aStyle)
00357 return;
00358
00359 _style = aStyle;
00360
00361 [self updateBackgroundColor];
00362 }
00363
00367 - (void)sizeToFit
00368 {
00369 if (_style == CPProgressIndicatorSpinningStyle)
00370 [self setFrameSize:[[CPProgressIndicatorSpinningStyleColors[_controlSize] patternImage] size]];
00371 else
00372 [self setFrameSize:CGSizeMake(CGRectGetWidth([self frame]), CPProgressIndicatorStyleSizes[
00373 CPProgressIndicatorClassName + @"BezelBorder" + CPProgressIndicatorStyleIdentifiers[CPProgressIndicatorBarStyle] +
00374 _CPControlIdentifierForControlSize(_controlSize)][0].height)];
00375 }
00376
00382 - (void)setDisplayedWhenStopped:(BOOL)isDisplayedWhenStopped
00383 {
00384 if (_isDisplayedWhenStoppedSet && _isDisplayedWhenStopped == isDisplayedWhenStopped)
00385 return;
00386
00387 _isDisplayedWhenStoppedSet = YES;
00388
00389 _isDisplayedWhenStopped = isDisplayedWhenStopped;
00390
00391 [self _hideOrDisplay];
00392 }
00393
00397 - (BOOL)isDisplayedWhenStopped
00398 {
00399 if (_isDisplayedWhenStoppedSet)
00400 return _isDisplayedWhenStopped;
00401
00402 if (_style == CPProgressIndicatorBarStyle || _style == CPProgressIndicatorHUDBarStyle)
00403 return YES;
00404
00405 return NO;
00406 }
00407
00408
00409 - (void)_hideOrDisplay
00410 {
00411 [self setHidden:!_isAnimating && ![self isDisplayedWhenStopped]];
00412 }
00413
00414 - (void)setFrameSize:(CGSize)aSize
00415 {
00416 [super setFrameSize:aSize];
00417
00418 [self drawBar];
00419 }
00420
00421
00422 - (void)drawBar
00423 {
00424 if (_style == CPProgressIndicatorSpinningStyle)
00425 return;
00426
00427 if (!_barView)
00428 {
00429 _barView = [[CPView alloc] initWithFrame:CGRectMake(2.0, 2.0, 0.0, 9.0)];
00430
00431 [_barView setBackgroundColor:[CPColor redColor]];
00432
00433 [self addSubview:_barView];
00434 }
00435
00436 [_barView setBackgroundColor:_CPControlColorWithPatternImage(
00437 CPProgressIndicatorStyleSizes,
00438 CPProgressIndicatorClassName,
00439 @"Bar",
00440 CPProgressIndicatorStyleIdentifiers[_style],
00441 _CPControlIdentifierForControlSize(_controlSize))];
00442
00443 [_barView setFrameSize:CGSizeMake(CGRectGetWidth([self bounds]) * (_doubleValue - _minValue) / (_maxValue - _minValue) - 4.0, 9.0)];
00444 }
00445
00446
00447 - (void)updateBackgroundColor
00448 {
00449 if (YES)
00450 {
00451 if (_style == CPProgressIndicatorSpinningStyle)
00452 {
00453 [_barView removeFromSuperview];
00454
00455 _barView = nil;
00456
00457 [self setBackgroundColor:CPProgressIndicatorSpinningStyleColors[_controlSize]];
00458 }
00459 else
00460 {
00461 [self setBackgroundColor:_CPControlThreePartImagePattern(
00462 NO,
00463 CPProgressIndicatorStyleSizes,
00464 CPProgressIndicatorClassName,
00465 @"BezelBorder",
00466 CPProgressIndicatorStyleIdentifiers[_style],
00467 _CPControlIdentifierForControlSize(_controlSize))];
00468
00469 [self drawBar];
00470 }
00471 }
00472 else
00473 [self setBackgroundColor:nil];
00474 }
00475
00476 @end