Re: Finder Icon Badging...
Re: Finder Icon Badging...
- Subject: Re: Finder Icon Badging...
- From: Scott Anguish <email@hidden>
- Date: Tue, 3 Feb 2004 03:48:00 -0500
On Feb 2, 2004, at 7:28 PM, Rainer Brockerhoff wrote:
>
>
Here's the code I use, it seems to work well. Of course this has
>
little to do with Cocoa, you must do
>
#include <Carbon/Carbon.h>
>
>
A Cocoa solution to this problem was presented in the Cocoa Tips and
Tricks session at WWDC. The code is available to attendees on the ADC
site, and has been submitted to sample code (so everyone can have it).
Anyways, here is the relevant method from the DotView class.
- (void)updateApplicationBadge {
NSImage *appImage, *newAppImage;
NSSize newAppImageSize;
NSRect badgeRect;
// Grab the unmodified application image.
appImage = [[NSWorkspace sharedWorkspace] iconForFile:[[NSBundle
mainBundle] bundlePath]];
// Application icons should be 128 x 128
newAppImageSize = NSMakeSize(kApplicationIconImageSize,
kApplicationIconImageSize);
newAppImage = [[NSImage alloc] initWithSize:newAppImageSize];
// Compute a location for the badge. Put the badge in the upper,
right one-third of the full image.
badgeRect.size = NSMakeSize(floor((newAppImageSize.width / 3.0) +
.5), floor((newAppImageSize.height / 3.0) + .5));
badgeRect.origin = NSMakePoint(newAppImageSize.width -
NSWidth(badgeRect), newAppImageSize.height - NSHeight(badgeRect));
// Draw into the new image (the badged image)
[newAppImage lockFocus];
// First draw the unmodified app image.
[appImage drawInRect:NSMakeRect(0, 0, newAppImageSize.width,
newAppImageSize.height)
fromRect:NSMakeRect(0, 0, [appImage size].width,
[appImage size].height)
operation:NSCompositeCopy
fraction:1.0];
// Now draw the badge, (it should look like a color swatch with a
black border).
[color set];
NSRectFill(badgeRect);
[[NSColor blackColor] set];
NSFrameRect(badgeRect);
[newAppImage unlockFocus];
// Set the new icon: a badged icon.
[NSApp setApplicationIconImage:newAppImage];
[newAppImage release];
// Now that we've modified the application image that is being used
by the dock, we need to clean up the icon before the application
terminates.
if (!registeredForTerminate) {
// If we've never registered to hear about application termination, do
that now.
registeredForTerminate = YES;
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(appWillTerminateNotification:)
name:NSApplicationWillTerminateNotification object:NSApp];
}
}
[demime 0.98b removed an attachment of type application/pkcs7-signature which had a name of smime.p7s]
_______________________________________________
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.