diff --git a/src/osx/cocoa/menuitem.mm b/src/osx/cocoa/menuitem.mm index 13e14f6df8..7f920b4224 100644 --- a/src/osx/cocoa/menuitem.mm +++ b/src/osx/cocoa/menuitem.mm @@ -86,9 +86,11 @@ SEL wxOSXGetSelectorFromID(int menuId ) wxUnusedVar(sender); if ( impl ) { - wxMenuItem* menuitem = impl->GetWXPeer(); - if ( menuitem->GetMenu()->HandleCommandProcess(menuitem) == false ) + if ( wxMenuItem* menuitem = impl->GetWXPeer() ) { + // Ignore the return value as there doesn't seem anything to do + // with it here. + menuitem->GetMenu()->HandleCommandProcess(menuitem); } } } diff --git a/src/osx/cocoa/nonownedwnd.mm b/src/osx/cocoa/nonownedwnd.mm index 9abd24f748..f10ca3b0a5 100644 --- a/src/osx/cocoa/nonownedwnd.mm +++ b/src/osx/cocoa/nonownedwnd.mm @@ -367,8 +367,8 @@ extern int wxOSXGetIdFromSelector(SEL action ); wxMenuItemImpl* impl = [nsMenuItem implementation]; if ( impl ) { - wxMenuItem* menuitem = impl->GetWXPeer(); - return menuitem->GetMenu()->HandleCommandProcess(menuitem); + if ( wxMenuItem* menuitem = impl->GetWXPeer() ) + return menuitem->GetMenu()->HandleCommandProcess(menuitem); } } // otherwise feed back command into common menubar diff --git a/src/osx/menu_osx.cpp b/src/osx/menu_osx.cpp index b28c1617e5..8729a74acd 100644 --- a/src/osx/menu_osx.cpp +++ b/src/osx/menu_osx.cpp @@ -359,25 +359,30 @@ bool wxMenu::HandleCommandUpdateStatus( wxMenuItem* item ) bool wxMenu::HandleCommandProcess( wxMenuItem* item ) { - int menuid = item ? item->GetId() : 0; + wxCHECK_MSG( item, false, "must have a valid item" ); + + int menuid = item->GetId(); bool processed = false; if (item->IsCheckable()) item->Check( !item->IsChecked() ) ; - if ( SendEvent( menuid , item->IsCheckable() ? item->IsChecked() : -1 ) ) - processed = true ; - - if(!processed && item) - { - processed = item->GetPeer()->DoDefault(); - } - + // A bit counterintuitively, we call OSXAfterMenuEvent() _before_ calling + // the user defined handler. This is done to account for the case when this + // handler deletes the window, as it can possibly do. if (wxWindow* const w = GetInvokingWindow()) { // Let the invoking window update itself if necessary. w->OSXAfterMenuEvent(); } + if ( SendEvent( menuid , item->IsCheckable() ? item->IsChecked() : -1 ) ) + processed = true ; + + if(!processed) + { + processed = item->GetPeer()->DoDefault(); + } + return processed; }