Adopted to changes in header and added some code for displaying

indeterminate progress.


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@11094 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
FredKiefer 2001-10-06 22:26:28 +00:00
parent d896247680
commit 34a2fe8cb7

View file

@ -24,127 +24,200 @@
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/ */
#import <AppKit/NSProgressIndicator.h> #include <AppKit/NSProgressIndicator.h>
#import <AppKit/NSGraphics.h> #include <AppKit/NSGraphics.h>
#import <AppKit/NSColor.h> #include <AppKit/NSWindow.h>
#import <AppKit/NSWindow.h>
// #import <AppKit/NSDPSContext.h>
@interface NSProgressIndicator(PrivateMethods)
- (void)_update;
@end
@implementation NSProgressIndicator @implementation NSProgressIndicator
NSColor *fillColour = nil;
#define maxCount 1
NSImage *images[maxCount];
+ (void) initialize
{
if (self == [NSProgressIndicator class])
{
[self setVersion: 1];
// FIXME: Should come from defaults and should be reset when defaults change
fillColour = [NSColor blueColor];
// FIXME: Load the images and set maxCount
}
}
- (id)initWithFrame:(NSRect)frameRect - (id)initWithFrame:(NSRect)frameRect
{ {
self = [super initWithFrame:frameRect]; self = [super initWithFrame: frameRect];
isIndeterminate = NO; // This should be changed to YES, to conform _isIndeterminate = YES;
isBezeled = YES; _isBezeled = YES;
isVertical = NO; _isVertical = NO;
usesThreadedAnimation = NO; _usesThreadedAnimation = NO;
animationDelay = 5.0 / 60.0; // 1 fifth a a second _animationDelay = 5.0 / 60.0; // 1 twelfth a a second
doubleValue = 0.0; _doubleValue = 0.0;
minValue = 0.0; _minValue = 0.0;
maxValue = 100.0; _maxValue = 100.0;
return self; return self;
} }
- (void)dealloc - (void)dealloc
{ {
// Nothing to dealloc at this stage TEST_RELEASE(_timer);
[super dealloc]; [super dealloc];
} }
- (void)animate:(id)sender - (void)animate:(id)sender
{ {
// Not implemented if (!_isIndeterminate)
return;
_count++;
if (_count == maxCount)
_count = 0;
[self setNeedsDisplay:YES];
} }
- (NSTimeInterval)animationDelay { return animationDelay; } - (NSTimeInterval)animationDelay { return _animationDelay; }
- (void)setAnimimationDelay:(NSTimeInterval)delay - (void)setAnimimationDelay:(NSTimeInterval)delay
{ {
animationDelay = delay; _animationDelay = delay;
} }
- (void)startAnimation:(id)sender - (void)startAnimation:(id)sender
{ {
// Not implemented if (!_isIndeterminate)
return;
if (!_usesThreadedAnimation)
{
ASSIGN(_timer, [NSTimer scheduledTimerWithTimeInterval: _animationDelay
target: self
selector: @selector(animate:)
userInfo: nil
repeats: YES]);
}
else
{
// Not implemented
}
_isRunning = YES;
} }
- (void)stopAnimation:(id)sender - (void)stopAnimation:(id)sender
{ {
// Not implemented if (!_isIndeterminate || !_isRunning)
return;
if (!_usesThreadedAnimation)
{
[_timer invalidate];
DESTROY(_timer);
}
else
{
// Not implemented
}
_isRunning = NO;
} }
- (BOOL)usesThreadedAnimation - (BOOL)usesThreadedAnimation
{ {
return usesThreadedAnimation; return _usesThreadedAnimation;
} }
- (void)setUsesThreadedAnimation:(BOOL)flag - (void)setUsesThreadedAnimation:(BOOL)flag
{ {
usesThreadedAnimation = flag; if (_usesThreadedAnimation != flag)
// This method should be expanded to enable threading {
BOOL wasRunning = _isRunning;
if (wasRunning)
[self stopAnimation: self];
_usesThreadedAnimation = flag;
if (wasRunning)
[self startAnimation: self];
}
} }
- (void)incrementBy:(double)delta - (void)incrementBy:(double)delta
{ {
doubleValue += delta; _doubleValue += delta;
[self setNeedsDisplay:YES]; [self setNeedsDisplay:YES];
[self _update];
} }
- (double)doubleValue { return doubleValue; } - (double)doubleValue { return _doubleValue; }
- (void)setDoubleValue:(double)aValue - (void)setDoubleValue:(double)aValue
{ {
if (doubleValue != aValue) if (_doubleValue != aValue)
{ {
doubleValue = aValue; _doubleValue = aValue;
[self setNeedsDisplay:YES]; [self setNeedsDisplay:YES];
[self _update]; }
}
} }
- (double)minValue { return minValue; } - (double)minValue { return _minValue; }
- (void)setMinValue:(double)newMinimum - (void)setMinValue:(double)newMinimum
{ {
if (minValue != newMinimum) if (_minValue != newMinimum)
{ {
minValue = newMinimum; _minValue = newMinimum;
[self setNeedsDisplay:YES]; [self setNeedsDisplay:YES];
[self _update]; }
}
} }
- (double)maxValue { return maxValue; } - (double)maxValue { return _maxValue; }
- (void)setMaxValue:(double)newMaximum - (void)setMaxValue:(double)newMaximum
{ {
if (maxValue != newMaximum) if (_maxValue != newMaximum)
{ {
maxValue = newMaximum; _maxValue = newMaximum;
[self setNeedsDisplay:YES]; [self setNeedsDisplay:YES];
[self _update]; }
}
} }
- (BOOL)isBezeled { return isBezeled; } - (BOOL)isBezeled { return _isBezeled; }
- (void)setBezeled:(BOOL)flag - (void)setBezeled:(BOOL)flag
{ {
if (isBezeled != flag) if (_isBezeled != flag)
{ {
isBezeled = flag; _isBezeled = flag;
[self setNeedsDisplay:YES]; [self setNeedsDisplay:YES];
[self _update]; }
}
} }
- (BOOL)isIndeterminate { return isIndeterminate; } - (BOOL)isIndeterminate { return _isIndeterminate; }
- (void)setIndeterminate:(BOOL)flag - (void)setIndeterminate:(BOOL)flag
{ {
isIndeterminate = flag; _isIndeterminate = flag;
isIndeterminate = NO; // Just for now
// Maybe we need more functionality here when we implement indeterminate // Maybe we need more functionality here when we implement indeterminate
if (flag == NO && _isRunning)
[self stopAnimation: self];
}
- (NSControlSize)controlSize
{
// FIXME
return NSRegularControlSize;
}
- (void)setControlSize:(NSControlSize)size
{
// FIXME
}
- (NSControlTint)controlTint
{
// FIXME
return NSDefaultControlTint;
}
- (void)setControlTint:(NSControlTint)tint
{
// FIXME
} }
- (void)drawRect:(NSRect)rect - (void)drawRect:(NSRect)rect
@ -152,42 +225,44 @@
NSRect r; NSRect r;
// Draw the Bezel // Draw the Bezel
if (isBezeled) if (_isBezeled)
NSDrawGrayBezel(_bounds,rect); {
NSSize borderSize = _sizeForBorderType (NSBezelBorder);
// Calc the inside rect to be drawn NSDrawGrayBezel(_bounds, rect);
if (isBezeled) // Calc the inside rect to be drawn
{ r = NSInsetRect(_bounds, borderSize.width, borderSize.height);
r = NSMakeRect(NSMinX(_bounds) + 2.0, }
NSMinY(_bounds) + 2.0,
NSWidth(_bounds) - 4.0,
NSHeight(_bounds) - 4.0);
}
else else
r = _bounds; r = _bounds;
if (isIndeterminate) // Draw indeterminate if (_isIndeterminate) // Draw indeterminate
{ {
// Do nothing at this stage // FIXME: Do nothing at this stage
} }
else // Draw determinate else // Draw determinate
{ {
if (doubleValue > minValue) if (_doubleValue > _minValue)
{ {
if (isVertical) double val;
r.size.height =
NSHeight(r) * (doubleValue / (maxValue - minValue)); if (_doubleValue > _maxValue)
else val = _maxValue - _minValue;
r.size.width = else
NSWidth(r) * (doubleValue / (maxValue - minValue)); val = _doubleValue - _minValue;
r = NSIntersectionRect(r,rect);
if (!NSIsEmptyRect(r)) if (_isVertical)
{ r.size.height = NSHeight(r) * (val / (_maxValue - _minValue));
[[NSColor blueColor] set]; else
NSRectFill(r); r.size.width = NSWidth(r) * (val / (_maxValue - _minValue));
r = NSIntersectionRect(r,rect);
if (!NSIsEmptyRect(r))
{
[fillColour set];
NSRectFill(r);
}
} }
} }
}
} }
// It does not seem that Gnustep has a copyWithZone: on NSView, it is private // It does not seem that Gnustep has a copyWithZone: on NSView, it is private
@ -199,14 +274,14 @@
NSProgressIndicator *newInd; NSProgressIndicator *newInd;
newInd = [super copyWithZone:zone]; newInd = [super copyWithZone:zone];
[newInd setIndeterminate:isIndeterminate]; [newInd setIndeterminate:_isIndeterminate];
[newInd setBezeled:isBezeled]; [newInd setBezeled:_isBezeled];
[newInd setUsesThreadedAnimation:usesThreadedAnimation]; [newInd setUsesThreadedAnimation:_usesThreadedAnimation];
[newInd setAnimimationDelay:animationDelay]; [newInd setAnimimationDelay:_animationDelay];
[newInd setDoubleValue:doubleValue]; [newInd setDoubleValue:_doubleValue];
[newInd setMinValue:minValue]; [newInd setMinValue:_minValue];
[newInd setMaxValue:maxValue]; [newInd setMaxValue:_maxValue];
[newInd setVertical:isVertical]; [newInd setVertical:_isVertical];
return newInd; return newInd;
} }
*/ */
@ -215,28 +290,28 @@
- (void)encodeWithCoder:(NSCoder *)aCoder - (void)encodeWithCoder:(NSCoder *)aCoder
{ {
[super encodeWithCoder:aCoder]; [super encodeWithCoder:aCoder];
[aCoder encodeValueOfObjCType: @encode(BOOL) at:&isIndeterminate]; [aCoder encodeValueOfObjCType: @encode(BOOL) at:&_isIndeterminate];
[aCoder encodeValueOfObjCType: @encode(BOOL) at:&isBezeled]; [aCoder encodeValueOfObjCType: @encode(BOOL) at:&_isBezeled];
[aCoder encodeValueOfObjCType: @encode(BOOL) at:&usesThreadedAnimation]; [aCoder encodeValueOfObjCType: @encode(BOOL) at:&_usesThreadedAnimation];
[aCoder encodeValueOfObjCType: @encode(NSTimeInterval) at:&animationDelay]; [aCoder encodeValueOfObjCType: @encode(NSTimeInterval) at:&_animationDelay];
[aCoder encodeValueOfObjCType: @encode(double) at:&doubleValue]; [aCoder encodeValueOfObjCType: @encode(double) at:&_doubleValue];
[aCoder encodeValueOfObjCType: @encode(double) at:&minValue]; [aCoder encodeValueOfObjCType: @encode(double) at:&_minValue];
[aCoder encodeValueOfObjCType: @encode(double) at:&maxValue]; [aCoder encodeValueOfObjCType: @encode(double) at:&_maxValue];
[aCoder encodeValueOfObjCType: @encode(BOOL) at:&isVertical]; [aCoder encodeValueOfObjCType: @encode(BOOL) at:&_isVertical];
} }
- (id)initWithCoder:(NSCoder *)aDecoder - (id)initWithCoder:(NSCoder *)aDecoder
{ {
self = [super initWithCoder:aDecoder]; self = [super initWithCoder:aDecoder];
[aDecoder decodeValueOfObjCType: @encode(BOOL) at:&isIndeterminate]; [aDecoder decodeValueOfObjCType: @encode(BOOL) at:&_isIndeterminate];
[aDecoder decodeValueOfObjCType: @encode(BOOL) at:&isBezeled]; [aDecoder decodeValueOfObjCType: @encode(BOOL) at:&_isBezeled];
[aDecoder decodeValueOfObjCType: @encode(BOOL) at:&usesThreadedAnimation]; [aDecoder decodeValueOfObjCType: @encode(BOOL) at:&_usesThreadedAnimation];
[aDecoder decodeValueOfObjCType: @encode(NSTimeInterval) [aDecoder decodeValueOfObjCType: @encode(NSTimeInterval)
at:&animationDelay]; at:&_animationDelay];
[aDecoder decodeValueOfObjCType: @encode(double) at:&doubleValue]; [aDecoder decodeValueOfObjCType: @encode(double) at:&_doubleValue];
[aDecoder decodeValueOfObjCType: @encode(double) at:&minValue]; [aDecoder decodeValueOfObjCType: @encode(double) at:&_minValue];
[aDecoder decodeValueOfObjCType: @encode(double) at:&maxValue]; [aDecoder decodeValueOfObjCType: @encode(double) at:&_maxValue];
[aDecoder decodeValueOfObjCType: @encode(BOOL) at:&isVertical]; [aDecoder decodeValueOfObjCType: @encode(BOOL) at:&_isVertical];
return self; return self;
} }
@ -244,29 +319,14 @@
@implementation NSProgressIndicator (GNUstepExtensions) @implementation NSProgressIndicator (GNUstepExtensions)
- (BOOL)isVertical { return isVertical; } - (BOOL)isVertical { return _isVertical; }
- (void)setVertical:(BOOL)flag - (void)setVertical:(BOOL)flag
{ {
if (isVertical != flag) if (_isVertical != flag)
{ {
isVertical = flag; _isVertical = flag;
[self setNeedsDisplay:YES]; [self setNeedsDisplay:YES];
[self _update]; }
}
}
@end
@implementation NSProgressIndicator(PrivateMethods)
- (void)_update
{
if (_window != nil)
if ([_window isVisible])
{
[_window display];
[GSCurrentContext() flush];
}
} }
@end @end