Almost there: progress indicator in table view
Almost there: progress indicator in table view
- Subject: Almost there: progress indicator in table view
- From: Gerben Wierda <email@hidden>
- Date: Thu, 29 Aug 2002 10:40:27 +0200
Thanks to tips and information from people on the macosx-dev list
(thanks!) I have an almost working setup with a progress indicator in a
table view. I created an NSCell subclass that contains an off screen
window and an off screen progress indicator in that window. My table
source is supposed to return NSNumbers in a range between 0.0 and 1.0.
When it delivers a negative number, the progress bar is supposed to be
indeterminate.
I have two problems left, one not so important for me, and one that
needs to be solved before this actually works:
1. The display is gray, not blue as in what you get with a non-key
window (not important)
2. Only 2 updates are actually displayed, after that the progress
indicator in the table view stays where it is. I tried many different
things, with display, setNeedsDisplay, buffering and whatnot, but to no
avail. Any ideas on how to solve this? Here is the code for the NSCell
subclass:
//
// GWProgressCell.m
// i-Installer
//
// Created by Gerben Wierda on Mon Aug 26 2002.
// Copyright (c) 2002 Gerben Wierda. All rights reserved.
//
#import "GWProgressCell.h"
@implementation GWProgressCell
- (void) dealloc
{
[_offScreenWindow release]; _offScreenWindow = nil;
[_offScreenProgressIndicator release]; _offScreenProgressIndicator =
nil;
}
- (id) init
{
NSLog( @"Progress bar: Init");
self = [super init];
_offScreenWindow = [[NSWindow alloc]
initWithContentRect:NSMakeRect(0,0,200,200)
styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered
defer:NO];
_offScreenProgressIndicator = [[NSProgressIndicator alloc]
initWithFrame:NSMakeRect(0,0,80,14)];
[_offScreenProgressIndicator setIndeterminate: NO];
[_offScreenProgressIndicator setMinValue:0.0];
[_offScreenProgressIndicator setMaxValue:1.0];
[[_offScreenWindow contentView]
addSubview:_offScreenProgressIndicator];
return self;
}
-(void)setObjectValue:(id)object
{
double doubleValue = [object doubleValue];
if(doubleValue < 0) {
//NSLog( @"Progress bar: Indeterminate");
[_offScreenProgressIndicator setIndeterminate: YES];
[_offScreenProgressIndicator setDoubleValue: 0.0];
} else {
//NSLog( @"Progress bar: Determinate %f", doubleValue);
[_offScreenProgressIndicator setIndeterminate: NO];
[_offScreenProgressIndicator setDoubleValue: doubleValue];
}
}
- (void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView
{
NSBitmapImageRep *rep = 0;
NSImage *image = [[NSImage alloc]
initWithSize:cellFrame.size];
[_offScreenWindow setContentSize: cellFrame.size];
[_offScreenProgressIndicator setFrameSize: cellFrame.size];
[[_offScreenWindow contentView] lockFocus];
rep = [[NSBitmapImageRep alloc] initWithFocusedViewRect:
NSOffsetRect(cellFrame, -cellFrame.origin.x, -cellFrame.origin.y)];
[[_offScreenWindow contentView] unlockFocus];
[image addRepresentation: rep];
[image compositeToPoint: NSMakePoint( cellFrame.origin.x,
cellFrame.origin.y + cellFrame.size.height) operation:NSCompositeCopy];
[image release];
[rep release];
sleep(1); // Let me see what happens as my test processes are
rather quick/small
}
@end
_______________________________________________
MacOSX-dev mailing list
email@hidden
http://www.omnigroup.com/mailman/listinfo/macosx-dev
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.