X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/03647350fc7cd141953c72e0284e928847d30f44..bb996f289574defb0ae4339ae8e46ff3cf6fa54c:/src/osx/carbon/menu.cpp?ds=sidebyside diff --git a/src/osx/carbon/menu.cpp b/src/osx/carbon/menu.cpp index 3b258bba5c..76f34d84e0 100644 --- a/src/osx/carbon/menu.cpp +++ b/src/osx/carbon/menu.cpp @@ -56,7 +56,7 @@ public : MenuItemIndex i = FindMenuItemIndex() ; if ( i > 0 ) { - if ( bitmap.Ok() ) + if ( bitmap.IsOk() ) { #if wxUSE_BMPBUTTON ControlButtonContentInfo info ; @@ -151,7 +151,7 @@ public : { m_parentMenuRef = parentMenuRef; if ( m_parentMenuRef && index > 0 ) - SetMenuItemRefCon( m_parentMenuRef, index, (URefCon) this ); + SetMenuItemRefCon( m_parentMenuRef, index, (URefCon) m_peer ); } MenuItemIndex FindMenuItemIndex() @@ -163,7 +163,7 @@ public : { URefCon storedRef = 0; GetMenuItemRefCon(m_parentMenuRef, i, &storedRef ); - if ( storedRef == (URefCon) this ) + if ( storedRef == (URefCon) m_peer ) { hit = i; break; @@ -183,7 +183,8 @@ protected : class wxMenuCarbonImpl : public wxMenuImpl { public : - wxMenuCarbonImpl( wxMenu* peer , MenuRef menu) : wxMenuImpl(peer), m_osxMenu(menu) + wxMenuCarbonImpl( wxMenu* peer , MenuRef menu , MenuRef oldMenu , SInt16 menuId) + : wxMenuImpl(peer), m_osxMenu(menu), m_oldMenuRef(oldMenu), m_menuId(menuId) { } @@ -280,6 +281,8 @@ public : static wxMenuImpl* CreateRootMenu( wxMenu* peer ); protected : wxCFRef m_osxMenu; + MenuRef m_oldMenuRef; + SInt16 m_menuId; } ; // static const short kwxMacAppleMenuId = 1 ; @@ -325,21 +328,35 @@ void wxRemoveMacMenuAssociation(wxMenu *menu) wxMenuCarbonImpl::~wxMenuCarbonImpl() { wxRemoveMacMenuAssociation( GetWXPeer() ); + // restore previous menu + m_osxMenu.reset(); + if ( m_menuId > 0 ) + MacDeleteMenu(m_menuId); + if ( m_oldMenuRef ) + MacInsertMenu(m_oldMenuRef, -1); } wxMenuImpl* wxMenuImpl::Create( wxMenu* peer, const wxString& title ) { // create the menu static SInt16 s_macNextMenuId = 3; + SInt16 menuId = s_macNextMenuId++; + // save existing menu in case we're embedding into an application + // or sharing outside UI elements. + WXHMENU oldMenu = GetMenuHandle(menuId); + if ( oldMenu ) + MacDeleteMenu(menuId); WXHMENU menu = NULL; - CreateNewMenu( s_macNextMenuId++ , 0 , &menu ) ; + CreateNewMenu( menuId , 0 , &menu ) ; if ( !menu ) { wxLogLastError(wxT("CreateNewMenu failed")); + if ( oldMenu ) + MacInsertMenu(oldMenu, -1); return NULL; } - wxMenuImpl* c = new wxMenuCarbonImpl( peer, menu ); + wxMenuImpl* c = new wxMenuCarbonImpl( peer, menu, oldMenu, menuId ); c->SetTitle(title); wxAssociateMenuWithMacMenu( menu , peer ) ; return c;