From d2b5c1ca0813b7cc0a6a105fba4ceb514759e4c6 Mon Sep 17 00:00:00 2001 From: Charlie Fenton Date: Wed, 19 Dec 2007 11:38:05 +0000 Subject: [PATCH] Mac MGR: Fix code drawing menubar icon with newer versions of wxwidgets svn path=/trunk/boinc/; revision=14410 --- checkin_notes | 9 +++++++++ clientgui/mac/MacSysMenu.cpp | 24 +++++++++++------------- clientgui/mac/MacSysMenu.h | 4 ++-- clientgui/mac/SystemMenu.m | 26 +++++++++++++++++++------- 4 files changed, 41 insertions(+), 22 deletions(-) diff --git a/checkin_notes b/checkin_notes index ebfe47c13d..b804874e67 100644 --- a/checkin_notes +++ b/checkin_notes @@ -12338,3 +12338,12 @@ Charlie 18 Dec 07 clientgui/ sg_ViewTabPage.cpp + +Charlie 19 Dec 07 + - Mac MGR: Fix code which draws menubar icon to properly use alpha + channel with newer versions of wxwidgets. + + clientgui/ + mac/ + SystemMenu.m + MacSysMenu.cpp,h diff --git a/clientgui/mac/MacSysMenu.cpp b/clientgui/mac/MacSysMenu.cpp index c3b71d2e0c..bbe9569d9a 100644 --- a/clientgui/mac/MacSysMenu.cpp +++ b/clientgui/mac/MacSysMenu.cpp @@ -165,8 +165,6 @@ CMacSystemMenu::~CMacSystemMenu() { // Set the System Menu Icon from XPM data bool CMacSystemMenu::SetIcon(const wxIcon& icon, const wxString&) { - wxBitmapRefData * theBitsRefData; - PicHandle thePICT; wxBitmap theBits; if (&icon == currentIcon) @@ -175,19 +173,20 @@ bool CMacSystemMenu::SetIcon(const wxIcon& icon, const wxString&) { currentIcon = &icon; theBits.CopyFromIcon(icon); - theBitsRefData = theBits.GetBitmapData(); - thePICT = theBitsRefData->GetPictHandle(); - if ( (SetSystemMenuIcon != NULL ) && (thePICT != NULL) ) { - SetSystemMenuIcon(thePICT); + CGImageRef imageRef = (CGImageRef)theBits.CGImageCreate(); + if ( (SetSystemMenuIcon != NULL ) && (imageRef != NULL) ) { + SetSystemMenuIcon(imageRef); + CGImageRelease( imageRef ); return true; } + + if(imageRef != NULL) CGImageRelease( imageRef ); + return false; } void CMacSystemMenu::BuildMenu() { - wxBitmapRefData * theBitsRefData; - PicHandle thePICT; wxBitmap theBits; wxMenu *themenu; CSkinAdvanced* pSkinAdvanced = wxGetApp().GetSkinManager()->GetAdvanced(); @@ -200,10 +199,8 @@ void CMacSystemMenu::BuildMenu() { m_iconTaskBarSnooze = *pSkinAdvanced->GetApplicationSnoozeIcon(); theBits.CopyFromIcon(m_iconTaskBarNormal); - theBitsRefData = theBits.GetBitmapData(); - thePICT = theBitsRefData->GetPictHandle(); - - if ( (SetUpSystemMenu != NULL ) && (thePICT != NULL) ) { + CGImageRef imageRef = (CGImageRef)theBits.CGImageCreate(); + if ( (SetUpSystemMenu != NULL ) && (imageRef != NULL) ) { // Currently, the system menu is the same as the Dock menu with the addition of // the Quit menu item. If in the future you wish to make the system menu different // from the Dock menu, override CTaskBarIcon::BuildContextMenu() and @@ -224,10 +221,11 @@ void CMacSystemMenu::BuildMenu() { themenu->SetEventHandler(this); - SetUpSystemMenu((MenuRef)(themenu->GetHMenu()), thePICT); + SetUpSystemMenu((MenuRef)(themenu->GetHMenu()), imageRef); currentIcon = NULL; } + if(imageRef != NULL) CGImageRelease( imageRef ); } diff --git a/clientgui/mac/MacSysMenu.h b/clientgui/mac/MacSysMenu.h index eb53f47e60..7ff635be80 100644 --- a/clientgui/mac/MacSysMenu.h +++ b/clientgui/mac/MacSysMenu.h @@ -38,8 +38,8 @@ public: void LoadPrivateFrameworkBundle( CFStringRef framework, CFBundleRef *bundlePtr ); // Function pointer prototypes to the Mach-O Cocoa wrappers - typedef void (*SetUpSystemMenuProc)(MenuRef menuToCopy, PicHandle theIcon); - typedef void (*SetSystemMenuIconProc)(PicHandle theIcon); + typedef void (*SetUpSystemMenuProc)(MenuRef menuToCopy, CGImageRef theIcon); + typedef void (*SetSystemMenuIconProc)(CGImageRef theIcon); SetUpSystemMenuProc SetUpSystemMenu; SetSystemMenuIconProc SetSystemMenuIcon; diff --git a/clientgui/mac/SystemMenu.m b/clientgui/mac/SystemMenu.m index 6a36b51c4a..2929f48a0c 100644 --- a/clientgui/mac/SystemMenu.m +++ b/clientgui/mac/SystemMenu.m @@ -42,7 +42,7 @@ SystemMenu *gSystemMenu = NULL; NSStatusItem *gStatusItem = NULL; -void SetSystemMenuIcon(PicHandle theIcon); +void SetSystemMenuIcon(CGImageRef theIcon); static OSStatus LoadFrameworkBundle(CFStringRef framework, CFBundleRef *bundlePtr); /* @@ -83,7 +83,7 @@ FallbackMethod: /* */ -void SetUpSystemMenu(MenuRef menuToCopy, PicHandle theIcon) { +void SetUpSystemMenu(MenuRef menuToCopy, CGImageRef theIcon) { NSAutoreleasePool* pool; if (gSystemMenu == NULL) @@ -199,7 +199,7 @@ void SetUpSystemMenu(MenuRef menuToCopy, PicHandle theIcon) { } -void SetSystemMenuIcon(PicHandle theIcon) +void SetSystemMenuIcon(CGImageRef theIcon) { if (theIcon == NULL) { @@ -213,14 +213,26 @@ void SetSystemMenuIcon(PicHandle theIcon) return; } - unsigned theLength = GetHandleSize((Handle)theIcon); - NSData* theData = [[NSData alloc] initWithBytes:*theIcon length:theLength]; - NSImage* theImage = [[NSImage alloc] initWithData:theData]; + NSRect imageRect = NSMakeRect(0.0, 0.0, 0.0, 0.0); + CGContextRef imageContext = nil; + NSImage* theImage = nil; + + // Get the image dimensions. + imageRect.size.height = CGImageGetHeight(theIcon); + imageRect.size.width = CGImageGetWidth(theIcon); + + // Create a new image to receive the Quartz image data. + theImage = [[NSImage alloc] initWithSize:imageRect.size]; + [theImage lockFocus]; + + // Get the Quartz context and draw. + imageContext = (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort]; + CGContextDrawImage(imageContext, *(CGRect*)&imageRect, theIcon); + [theImage unlockFocus]; [gStatusItem setImage:theImage]; [theImage release]; - [theData release]; return; }