From 3e0055cbe0f8ef9e30d29695bbaa1562a02bf85b Mon Sep 17 00:00:00 2001 From: Charlie Fenton Date: Fri, 8 Jul 2011 08:26:11 +0000 Subject: [PATCH] Mac: Refine big fix for menubar icon menu not working after changing skin svn path=/trunk/boinc/; revision=23819 --- checkin_notes | 8 ++++++++ clientgui/BOINCTaskBar.cpp | 3 ++- clientgui/mac/MacSysMenu.cpp | 23 +++++++++++++++-------- clientgui/mac/MacSysMenu.h | 8 +++++--- 4 files changed, 30 insertions(+), 12 deletions(-) diff --git a/checkin_notes b/checkin_notes index 7b7bd6d031..e4a8665e6e 100644 --- a/checkin_notes +++ b/checkin_notes @@ -3960,3 +3960,11 @@ David 7 July 2011 client/ client_types.cpp + +Charlie 8 July 2011 + - Mac: Refine big fix for menubar icon menu not working after changing skin. + + clientgui/ + BOINCTaskBar.cpp + mac/ + MacSysMenu.cpp, .h diff --git a/clientgui/BOINCTaskBar.cpp b/clientgui/BOINCTaskBar.cpp index 3a7b0b1123..c7e513544e 100644 --- a/clientgui/BOINCTaskBar.cpp +++ b/clientgui/BOINCTaskBar.cpp @@ -325,7 +325,8 @@ void CTaskBarIcon::OnReloadSkin(CTaskbarEvent& WXUNUSED(event)) { m_iconTaskBarSnooze = *pSkinAdvanced->GetApplicationSnoozeIcon(); #ifdef __WXMAC__ - wxGetApp().GetMacSystemMenu()->BuildMenu(); + // For unknown reasons, menus won't work if we call BuildMenu() here + wxGetApp().GetMacSystemMenu()->SetNeedToRebuildMenu(); #endif } diff --git a/clientgui/mac/MacSysMenu.cpp b/clientgui/mac/MacSysMenu.cpp index 003dde8862..5c98701783 100644 --- a/clientgui/mac/MacSysMenu.cpp +++ b/clientgui/mac/MacSysMenu.cpp @@ -121,7 +121,8 @@ CMacSystemMenu::CMacSystemMenu(wxString title, wxIcon* icon, wxIcon* iconDisconn : CTaskBarIcon(title, icon, iconDisconnected, iconSnooze) { CFBundleRef SysMenuBundle = NULL; - m_OpeningAboutDlg = false; + m_bOpeningAboutDlg = false; + m_bNeedRebuildMenu = false; LoadPrivateFrameworkBundle( CFSTR("SystemMenu.bundle"), &SysMenuBundle ); if ( SysMenuBundle != NULL ) @@ -163,17 +164,23 @@ CMacSystemMenu::~CMacSystemMenu() { // Set the System Menu Icon from XPM data bool CMacSystemMenu::SetIcon(const wxIcon& icon) { wxBitmap theBits; - CMainDocument* pDoc = wxGetApp().GetDocument(); - wxASSERT(pDoc); - wxASSERT(wxDynamicCast(pDoc, CMainDocument)); - theBits.CopyFromIcon(icon); - CGImageRef imageRef = (CGImageRef)theBits.CGImageCreate(); - if ( (SetSystemMenuIcon != NULL ) && (imageRef != NULL) ) { - if (pDoc->IsConnected()) { + // For unknown reasons, menus won't work if we call BuildMenu() directly + // from CTaskBarIcon::OnReloadSkin(), so it sets a flag to call it here + if (m_bNeedRebuildMenu) { + CMainDocument* pDoc = wxGetApp().GetDocument(); + wxASSERT(pDoc); + wxASSERT(wxDynamicCast(pDoc, CMainDocument)); + if (pDoc->IsConnected() && m_bNeedRebuildMenu) { // For unknown reasons, Menubar Icon menu doesn't work without this BuildMenu(); } + } + m_bNeedRebuildMenu = false; + + theBits.CopyFromIcon(icon); + CGImageRef imageRef = (CGImageRef)theBits.CGImageCreate(); + if ( (SetSystemMenuIcon != NULL) && (imageRef != NULL) ) { SetSystemMenuIcon(imageRef); CGImageRelease( imageRef ); return true; diff --git a/clientgui/mac/MacSysMenu.h b/clientgui/mac/MacSysMenu.h index 5f40e41c87..67b8ea1e34 100644 --- a/clientgui/mac/MacSysMenu.h +++ b/clientgui/mac/MacSysMenu.h @@ -42,8 +42,9 @@ public: SetUpSystemMenuProc SetUpSystemMenu; SetSystemMenuIconProc SetSystemMenuIcon; - bool IsOpeningAboutDlg() { return m_OpeningAboutDlg; } - void SetOpeningAboutDlg(bool b) { m_OpeningAboutDlg = b; } + bool IsOpeningAboutDlg() { return m_bOpeningAboutDlg; } + void SetOpeningAboutDlg(bool b) { m_bOpeningAboutDlg = b; } + void SetNeedToRebuildMenu() { m_bNeedRebuildMenu = true; } void BuildMenu(void); #if wxCHECK_VERSION(2,8,0) wxMenu *GetCurrentMenu(); @@ -51,7 +52,8 @@ public: private: - bool m_OpeningAboutDlg; + bool m_bOpeningAboutDlg; + bool m_bNeedRebuildMenu; };