/* * CPProgressIndicator.j * AppKit * * Created by Francisco Tolmasky. * Copyright 2008, 280 North, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ @import "CGGeometry.j" @import "CPImageView.j" @import "CPView.j" /* @global @group CPProgressIndicatorStyle */ CPProgressIndicatorBarStyle = 0; /* @global @group CPProgressIndicatorStyle */ CPProgressIndicatorSpinningStyle = 1; /* @global @group CPProgressIndicatorStyle */ CPProgressIndicatorHUDBarStyle = 2; var CPProgressIndicatorSpinningStyleColors = nil, CPProgressIndicatorClassName = nil, CPProgressIndicatorStyleIdentifiers = nil, CPProgressIndicatorStyleSizes = nil; /*! @ingroup appkit @class CPProgressIndicator This class is used in a Cappuccino GUI to display the progress of a function or task. If the duration of the task is unknown, there is also an indeterminate mode for the indicator. */ @implementation CPProgressIndicator : CPView { double _minValue; double _maxValue; double _doubleValue; CPControlSize _controlSize; BOOL _isIndeterminate; CPProgressIndicatorStyle _style; BOOL _isAnimating; BOOL _isDisplayedWhenStoppedSet; BOOL _isDisplayedWhenStopped; CPView _barView; } /* @ignore */ + (void)initialize { if (self != [CPProgressIndicator class]) return; var bundle = [CPBundle bundleForClass:self]; CPProgressIndicatorSpinningStyleColors = []; CPProgressIndicatorSpinningStyleColors[CPMiniControlSize] = [CPColor colorWithPatternImage:[[CPImage alloc] initWithContentsOfFile: [bundle pathForResource:@"CPProgressIndicator/CPProgressIndicatorSpinningStyleRegular.gif"] size:CGSizeMake(64.0, 64.0)]]; CPProgressIndicatorSpinningStyleColors[CPSmallControlSize] = [CPColor colorWithPatternImage:[[CPImage alloc] initWithContentsOfFile: [bundle pathForResource:@"CPProgressIndicator/CPProgressIndicatorSpinningStyleRegular.gif"] size:CGSizeMake(64.0, 64.0)]]; CPProgressIndicatorSpinningStyleColors[CPRegularControlSize] = [CPColor colorWithPatternImage:[[CPImage alloc] initWithContentsOfFile: [bundle pathForResource:@"CPProgressIndicator/CPProgressIndicatorSpinningStyleRegular.gif"] size:CGSizeMake(64.0, 64.0)]]; CPProgressIndicatorBezelBorderViewPool = []; var start = CPProgressIndicatorBarStyle, end = CPProgressIndicatorHUDBarStyle; for (; start <= end; ++start) { CPProgressIndicatorBezelBorderViewPool[start] = []; CPProgressIndicatorBezelBorderViewPool[start][CPMiniControlSize] = []; CPProgressIndicatorBezelBorderViewPool[start][CPSmallControlSize] = []; CPProgressIndicatorBezelBorderViewPool[start][CPRegularControlSize] = []; } CPProgressIndicatorClassName = [self className]; CPProgressIndicatorStyleIdentifiers = []; CPProgressIndicatorStyleIdentifiers[CPProgressIndicatorBarStyle] = @"Bar"; CPProgressIndicatorStyleIdentifiers[CPProgressIndicatorSpinningStyle] = @"Spinny"; CPProgressIndicatorStyleIdentifiers[CPProgressIndicatorHUDBarStyle] = @"HUDBar"; var regularIdentifier = _CPControlIdentifierForControlSize(CPRegularControlSize), smallIdentifier = _CPControlIdentifierForControlSize(CPSmallControlSize), miniIdentifier = _CPControlIdentifierForControlSize(CPMiniControlSize); CPProgressIndicatorStyleSizes = []; // Bar Sttyle var prefixes = [ CPProgressIndicatorClassName + @"BezelBorder" + CPProgressIndicatorStyleIdentifiers[CPProgressIndicatorBarStyle], CPProgressIndicatorClassName + @"Bar" + CPProgressIndicatorStyleIdentifiers[CPProgressIndicatorBarStyle], CPProgressIndicatorClassName + @"BezelBorder" + CPProgressIndicatorStyleIdentifiers[CPProgressIndicatorHUDBarStyle], CPProgressIndicatorClassName + @"Bar" + CPProgressIndicatorStyleIdentifiers[CPProgressIndicatorHUDBarStyle] ]; for (var i = 0, count = prefixes.length; i 0.0 && barWidth < 4.0) barWidth = 4.0; [_barView setFrameSize:CGSizeMake(barWidth, 16.0)]; } /* @ignore */ - (void)updateBackgroundColor { if (YES)//_isBezeled) { if (_style == CPProgressIndicatorSpinningStyle) { [_barView removeFromSuperview]; _barView = nil; [self setBackgroundColor:CPProgressIndicatorSpinningStyleColors[_controlSize]]; } else { [self setBackgroundColor:_CPControlThreePartImagePattern( NO, CPProgressIndicatorStyleSizes, CPProgressIndicatorClassName, @"BezelBorder", CPProgressIndicatorStyleIdentifiers[_style], _CPControlIdentifierForControlSize(_controlSize))]; [self drawBar]; } } else [self setBackgroundColor:nil]; } @end