This is MiscProgressView.m in view mode; [Download] [Up]
// // MiscProgressView.m -- a simple view class for displaying progress // Written originally by Don Yacktman Copyright (c) 1993 by James Heiser. // Modified from an example in the NeXT documentation. // This file is maintained by James Heiser, jheiser@adobe.com. // Version 1.0. All rights reserved. // // This notice may not be removed from this source code. // // This object is included in the MiscKit by permission from the author // and its use is governed by the MiscKit license, found in the file // "LICENSE.rtf" in the MiscKit distribution. Please refer to that file // for a list of all applicable permissions and restrictions. // #import "MiscProgressView.h" @implementation MiscProgressView - initWithFrame:(NSRect)frameRect { [super initWithFrame:frameRect]; bg = [NSColor lightGrayColor]; fg = [NSColor darkGrayColor]; bd = [NSColor blackColor]; total = MISC_PROGRESS_MAXSIZE; stepSize = MISC_PROGRESS_DEFAULTSTEPSIZE; count = 0; ratio = 0.0; return self; } - renderBackground { [bg set]; NSRectFill([self bounds]); return self; } - renderBar { if ((ratio > 0) && (ratio <= 1.0)) { NSRect r = [self bounds]; r.size.width = [self bounds].size.width * ratio; [fg set]; NSRectFill(r); } return self; } - renderBorder { [bd set]; NSFrameRect([self bounds]); return self; } - (void)drawRect:(NSRect)rects { // Note from Don on why this -drawSelf: is split up -- // The three separate rendering methods make things a little less efficient, // but make it a lot easier to subclass and retain parts of the original // rendering. I wish NeXT had done something like this with the various // control classes so that subclasses could override parts of the steps // in the rendering process...or insert things at certain points in time. [self renderBackground]; [self renderBar]; [self renderBorder]; } - setStepSize:(int)value { stepSize = value; return self; } - (int)stepSize { return stepSize; } - (NSColor *)backgroundColor { return bg; } - (NSColor *)foregroundColor { return fg; } - (NSColor *)borderColor { return bd; } - (void)setBackgroundColor:(NSColor *)color { bg = color; } - setForegroundColor:(NSColor *)color { fg = color; return self; } - setBorderColor:(NSColor *)color { bd = color; return self; } - setRatio:(float)newRatio { if (newRatio > 1.0) newRatio = 1.0; if (ratio != newRatio) { ratio = newRatio; [self display]; } return self; } - (void)takeIntValueFrom:sender { int temp = [sender intValue]; if ((temp < 0) || (temp > total)) return; count = temp; [self setRatio:(float)count/(float)total]; } - increment:sender { count += stepSize; [self setRatio:(float)count/(float)total]; return self; } - (void)takeFloatValueFrom:(id)sender { [self setRatio:[sender floatValue]]; count = ceil(ratio * (float)total); } - (NSString *)inspectorClassName { return @"MiscProgressViewInspector"; } - (void)clear:(id)sender { count = 0; [self setRatio: 0]; } - (id)initWithCoder:(NSCoder *)aDecoder { [super initWithCoder:aDecoder]; [aDecoder decodeValuesOfObjCTypes:"ii", &total, &stepSize]; bg = [[aDecoder decodeObject] retain]; fg = [[aDecoder decodeObject] retain]; bd = [[aDecoder decodeObject] retain]; return self; } - (void)encodeWithCoder:(NSCoder *)aCoder { [super encodeWithCoder:aCoder]; [aCoder encodeValuesOfObjCTypes:"ii", &total, &stepSize]; [aCoder encodeObject:bg]; [aCoder encodeObject:fg]; [aCoder encodeObject:bd]; } @end
These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.