// Operations: bool wxTaskBarIcon::SetIcon(const wxIcon& icon, const wxString& tooltip) { wxBitmap bmp( icon ) ; OSStatus err = noErr ; CGImageRef pImage; #if 0 // is always available under OSX now -- crashes on 10.2 in CFRetain() - RN pImage = (CGImageRef) bmp.CGImageCreate() ; #else WXHBITMAP iconport ; WXHBITMAP maskport ; iconport = bmp.GetHBITMAP( &maskport ) ; if (!maskport) { // Make a mask with no transparent pixels wxBitmap mbmp(icon.GetWidth(), icon.GetHeight()); wxMemoryDC dc; dc.SelectObject(mbmp); dc.SetBackground(*wxBLACK_BRUSH); dc.Clear(); dc.SelectObject(wxNullBitmap); bmp.SetMask( new wxMask(mbmp, *wxWHITE) ) ; iconport = bmp.GetHBITMAP( &maskport ) ; } //create the icon from the bitmap and mask bitmap contained within err = CreateCGImageFromPixMaps( GetGWorldPixMap(MAC_WXHBITMAP(iconport)), GetGWorldPixMap(MAC_WXHBITMAP(maskport)), &pImage ); wxASSERT(err == 0); #endif wxASSERT(pImage != NULL ); err = SetApplicationDockTileImage(pImage); wxASSERT(err == 0); if (pImage != NULL) CGImageRelease(pImage); return m_iconAdded = err == noErr; }
/******************************************************************************* ** TileBadge *******************************************************************************/ void TileBadge( Boolean inRestoreTileBeforeBadging ) { OSStatus theErr; PicHandle theBadge; PicHandle theBadgeMask; GWorldPtr theBadgeWorld; GWorldPtr theBadgeMaskWorld; Rect theRect = { 0, 0, 128, 128 }; CGImageRef theBadgeImage; GDHandle theSavedDevice; GrafPtr theSavedPort; // *** // // PITFALL! // // Rebadging the tile will composite over the old one! // You might want to restore the tile before badging. // // *** if ( inRestoreTileBeforeBadging ) RestoreApplicationDockTileImage(); // Load the pictures theBadge = GetPicture( kBadge ); require( theBadge != NULL, CantLoadBadge ); theBadgeMask = GetPicture( kBadgeMask ); require( theBadgeMask != NULL, CantLoadBadgeMask ); // Make some GWorlds theErr = NewGWorld( &theBadgeWorld, 32, &theRect, NULL, NULL, 0 ); require_noerr( theErr, CantMakeBadgeWorld ); theErr = NewGWorld( &theBadgeMaskWorld, 32, &theRect, NULL, NULL, 0 ); require_noerr( theErr, CantMakeBadgeMaskWorld ); // Draw the pictures into the GWorlds GetGWorld( &theSavedPort, &theSavedDevice ); SetGWorld( theBadgeWorld, NULL ); DrawPicture( theBadge, &theRect ); SetGWorld( theBadgeMaskWorld, NULL ); DrawPicture( theBadgeMask, &theRect ); SetGWorld( theSavedPort, theSavedDevice ); // *** // // Make a CGImage from the GWorlds' pixmaps // // *** theErr = CreateCGImageFromPixMaps( GetGWorldPixMap( theBadgeWorld ), GetGWorldPixMap( theBadgeMaskWorld ), &theBadgeImage ); if ( theErr != noErr ) SysBeep( 0 ); require_noerr( theErr, CantMakeBadgeImage ); // *** // // Badge the tile // // *** theErr = OverlayApplicationDockTileImage( theBadgeImage ); if ( theBadgeImage != NULL ) CGImageRelease( theBadgeImage ); CantMakeBadgeImage: DisposeGWorld( theBadgeMaskWorld ); CantMakeBadgeMaskWorld: DisposeGWorld( theBadgeWorld ); CantMakeBadgeWorld: ReleaseResource( (Handle) theBadgeMask ); CantLoadBadgeMask: ReleaseResource( (Handle) theBadge ); CantLoadBadge: ; }