On Sat, Jul 25, 2009 at 4:04 PM, Jay Reynolds Freeman<jay_reynolds_free...@mac.com> wrote: > Kyle, I read you loud and clear, or at least I think I do, but the behavior > you describe for the app icon image in the dock is not what I am seeing. I > am running my application now, with my bitmap-hacking code in place, > and it has passed the point where the modified NSImage has been > passed to -setApplicationIconImage: . The icon in the dock has indeed > changed to the modified version, but when I look at other places where > I expect the unmodified icon to show up, I still see the unmodified > icon. That includes all views of folders where the application is > stored (those views having been opened or refreshed since > starting the application), the window produced by my application's > "About" menu item, and the Apple "Recent Items" menu, for example.
As far as the Finder or Recent Items are concerned, they are always going to get the icon from the bundle, never from a running application. So I wouldn't expect them to change. I would, however, expect your About panel's icon to change. Though since it doesn't, it shows that I was incorrect. > The only appearance I am trying to alter is the appearance of the > application icon that sits in the dock when the program is running, > and that seems to be all that -setApplicationIconImage: is changing. > (My own code doesn't happen to call [NSImage > imageNamed:@"NSApplicationIcon"]. > Perhaps there are library or framework routines that are calling it on > my behalf, whose outputs I should review?) The default About panel does, I believe. As does NSAlert (which then does its own badging on top of that). > Furthermore, I only want this change to persist while the program is > active. The change I am making is like the red circle with a number in > it that sits on the "Mail" icon and shows how many new EMails you have. > I would use the published interface to that feature, except that a bright > red color is a bit too strident for my purposes. The way I would do this would be to use an NSImage view as a custom dock tile view, and have that view display an image I draw myself. This is because of what I assumed -setApplicationIconImage: would imply for users of +[NSImage imageNamed:]. You have since demonstrated me wrong on this second point. >> There is no such thing as "modifying an image" in Quartz. > > Maybe so, but you can certainly grab the bits you have drawn, using > -[NSBitmapImageRep initWithFocusedViewRect:], and then add that instance > of NSBitmapImageRep to a new instance of NSImage, using > -[NSImage addRepresentation:], and then use the new instance of NSImage > for whatever purpose you like. That is what I am doing, albeit with > rather more hackery of the bitmap than I would wish. What I mean is that you can't draw some stuff and change what you drew later. You are always drawing on a fresh canvas. What you want to do is take an existing bitmap image, draw it into a graphics context, and draw your custom badge on top of it in that same graphics context (a process known as "composition"). This writes the pixel data out to the graphics context's backing bitmap image, which you turn around and set as your application's image. I was suggesting instead to add a custom view to the dock tile and perform the same process in the graphics context attached to that view. My motivation was to avoid the problems I believed were associated with -setApplicationIconImage:, but even though those are moot you still have the benefit of the view having done all of the graphics context setup for you. If you want to redraw the icon, call -setNeedsDisplay on it, just like any other NSView. Within -drawRect:, you can start with the image returned by +[NSImage imageNamed:@"NSApplicationIcon"], draw that into the view's graphics context, and draw your badge atop it. Or you can do all of this in an offscreen graphics context and use that offscreen context's bitmap image representation to create an NSImage which you pass to an NSImageView that is the custom view of your dock tile. Maybe now it makes more sense? --Kyle Sluder _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com