Problem displaying progress indicator in dock icon
Problem displaying progress indicator in dock icon
- Subject: Problem displaying progress indicator in dock icon
- From: Tim Hewett <email@hidden>
- Date: Tue, 14 Aug 2012 16:39:22 +0100
My app has been displaying a progress indicator superimposed over the dock icon successfully until more recent MacOS versions. With the latter it appears as a black bar instead of blue (currently testing on Mountain Lion but suspect Lion has the same problem, Snow Leopard and previous ones are ok).
Previously to get it to work it was necessary to subclass NSPanel and override the isKey selector to always return YES, to make sure that the image generated from the progress indicator (using the dataWithPDFInsideRect: selector) was blue and not grey. The panel itself is never displayed, it is just a dummy one to give the indicator a "key" window to be part of to allow it to show a blue bar.
The NSView drawRect: selector has been tried instead to fill in the image in place of dataWithPDFInsideRect:, now it is grey and no longer updates after the first progress increment. This alternative approach works fine on 10.5.8 as does the original one, but not on Mountain Lion again.
If the progress indicator is temporarily added to the content view of a normal key window instead of the dummy one then it displays fine as a blue bar in the dock icon, so the challenge seems to be to get the NSPanel subclass to spoof a key window and get the indicator to display its blue bar. Somehow that seems to have been lost.
I've tried overriding the panel isVisible and isMainWindow selectors to always return YES, to no effect.
N.B. the progress indicator is also subclassed to allow control over the wave animation, saved a lot of CPU time on older Macs.
Anyone solved this one on Mountain Lion/Lion?
(Also slightly OT, I need to find out how to download Lion to keep it available as a bootable volume for testing. It never showed in App Store as I never purchased it there due to my Mac coming with it pre-installed, and still doesn't show now even when option-clicking on the Purchases icon. Is there a way to get a (legitimate and official) copy down somehow?)
Regards,
Tim.
Code snippets:
Initialisation:
// *** Create/init an off-screen progress indicator - has no window or superview.
// *** Set the width to 128 to match that of the dock icon.
dockProgressBar = [[MyStaticProgressIndicator alloc] init];
NSRect rect = {{0.0,0.0},{128.0,12.0}};
[dockProgressBar setFrame:rect];
[dockProgressBar setIndeterminate:NO];
[dockProgressBar setControlTint:NSBlueControlTint];
[dockProgressBar setControlSize:NSSmallControlSize];
dockProgressBarWindow = [[MyAlwaysKeyPanel alloc] init];
[dockProgressBarWindow setContentView:dockProgressBar];
Use:
[dockProgressBar setDoubleValue:0.0L]; // needed for OS 10.6.1 Snow Leopard or else progress bar doesn't update beyond first step
[dockProgressBar setDoubleValue:barValue];
// *** Snap the progress indicator into an image (NSView dataWithPDFInsideRect: selector - very useful).
NSImage *dockProgressBarImage = [[NSImage alloc] initWithData:[dockProgressBar dataWithPDFInsideRect:[dockProgressBar frame]]];
// *** Get the app's default icon.
NSImage *mainIcon = [dockIcon copy];
// *** Lock image ops onto the default icon.
[mainIcon lockFocus];
// *** composite the progress indicator image onto the dock icon.
NSPoint point = { 0.0, 0.0 };
[dockProgressBarImage drawAtPoint:point fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:1.0];
[mainIcon unlockFocus];
// *** Replace the dock icon with the image containing the progress bar.
[NSApp setApplicationIconImage:mainIcon];
[dockProgressBarImage release];
[mainIcon release];
lastDockBarValue = barValue;
NSPanel subclass:
// This is needed for the progress bars used in the dock icon and the floating progress panel, so they are given
// a dummy window (which never gets displayed) which they think is key, and so show the blue colour (grey is less
// visible hence all this effort)
@implementation MyAlwaysKeyPanel
- (BOOL)isKeyWindow
{
return TRUE;
}
@end
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden