Re: Progress indicator in dock icon
Re: Progress indicator in dock icon
- Subject: Re: Progress indicator in dock icon
- From: Tim Hewett <email@hidden>
- Date: Sat, 20 Mar 2004 10:54:54 +0000
Dave,
I've found a way to do this in Cocoa, never used NSImage before but
there is a way:
// *** Snap the dock icon at startup, to allow it to be restored on
quitting or
// *** when the progress bar should no longer be displayed.
NSImage *dockIcon = [[NSApp applicationIconImage] copy];
// *** Create/init an orphaned progress indicator - has no window or
superview.
// *** Set the width to 128 to match that of the dock icon.
NSProgressIndicator *dockIndicator = [[NSProgressIndicator alloc] init];
NSRect rect = {{0.0,0.0},{128.0,12.0}};
[dockIndicator setFrame:rect];
[dockIndicator setIndeterminate:NO];
[dockIndicator setControlTint:NSBlueControlTint];
[dockIndicator setControlSize:NSSmallControlSize];
[dockIndicator setDoubleValue:75.0];
// *** Snap the progress indicator into an image (NSView
dataWithPDFInsideRect: selector - very useful).
NSImage *dockIndicatorImage = [[NSImage alloc]
initWith
Data:[dockIndicator dataWithPDFInsideRect:rect]];
// *** Get the app's default icon.
NSImage *mainIcon = [NSApp applicationIconImage];
// *** Lock image ops onto the default icon.
[mainIcon lockFocus];
// *** composite the progress indicator image onto the dock icon. I
keep the dock icon
// *** on top of the progress bar using NSCompositeDestinationAtop, but
other apps may
// *** obscure too much of the bar and require NSCompositeSourceAtop
instead.
NSPoint point = {0.0,0.0};
[dockIndicatorImage compositeToPoint:point
operation:NSCompositeDestinationAtop];
[mainIcon unlockFocus];
// *** Replace the dock icon with the image containing the progress bar.
[NSApp setApplicationIconImage:mainIcon];
[dockIndicatorImage release];
// *** END
You have to restore the dock icon to the original when quitting or it
will stay stuck with a progress bar even without the app running
(surely that's a bug in the dock?).
One problem remains which is that the progress bar displays with
the faint grey of a bar in a non-active window, rather than the blue
of a bar in an active window. I guess not having a parent window
is the problem, so far no way has been found to manipulate it into
being blue. Even if the progress indicator is part of the window but
hidden somewhere off limits, it is still only blue when the window is
active. Any hints on how to fix this gratefully received...
Regards,
Tim Hewett, Coolatoola.com
On 19 Mar 2004, at 22:40, Dave MacLachlan wrote:
I did it using Carbon, but the concept should be the same. Get your
dock icon, and then overlay a progress bar on it. CoreGraphics does
this without any problems ;-) There's no actual API that I'm aware of.
Cheers,
Dave
On Mar 19, 2004, at 1:55 PM, Tim Hewett wrote:
Hi,
There doesn't seem to be any documentation or examples on
displaying a progress indicator in the dock icon (like Toast does
when burning a disc).
Is there any info and/or examples somewhere, or does anyone
here know how to do it?
Cheers,
Tim Hewett, Coolatoola.com
_______________________________________________
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.
_______________________________________________
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.