X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/8907154c1a8a6882c6797d1f16393ddfb23e7f3a..db9db9cd182e0a48b20078505ce198339dde26fc:/src/mac/carbon/app.cpp diff --git a/src/mac/carbon/app.cpp b/src/mac/carbon/app.cpp index 45a5dea76b..4bd1eea596 100644 --- a/src/mac/carbon/app.cpp +++ b/src/mac/carbon/app.cpp @@ -439,11 +439,23 @@ static pascal OSStatus wxMacAppCommandEventHandler( EventHandlerCallRef handler wxMenuItem* item = NULL ; MenuCommand id = command.commandID ; - // for items we don't really control - if ( id == kHICommandPreferences ) - { - id = wxApp::s_macPreferencesMenuItemId ; + // for 'standard' commands + if ( id == kHICommandPreferences || id == kHICommandQuit || id == kHICommandAbout ) + { + switch ( id ) + { + case kHICommandPreferences : + id = wxApp::s_macPreferencesMenuItemId ; + break ; + case kHICommandQuit : + id = wxApp::s_macExitMenuItemId ; + break ; + case kHICommandAbout : + id = wxApp::s_macAboutMenuItemId ; + break ; + } + wxMenuBar* mbar = wxMenuBar::MacGetInstalledMenuBar() ; if ( mbar ) { @@ -453,7 +465,39 @@ static pascal OSStatus wxMacAppCommandEventHandler( EventHandlerCallRef handler } else if ( id != 0 && command.menu.menuRef != 0 && command.menu.menuItemIndex != 0 ) { - GetMenuItemRefCon( command.menu.menuRef , command.menu.menuItemIndex , (UInt32*) &item ) ; + // make sure it is one of our own menus, or of the 'synthetic' apple and help menus , otherwise don't touch + MenuItemIndex firstUserHelpMenuItem ; + static MenuHandle mh = NULL ; + if ( mh == NULL ) + { + if ( UMAGetHelpMenu( &mh , &firstUserHelpMenuItem) != noErr ) + { + mh = NULL ; + } + } + + // is it part of the application or the help menu, then look for the id directly + if ( ( GetMenuHandle( kwxMacAppleMenuId ) != NULL && command.menu.menuRef == GetMenuHandle( kwxMacAppleMenuId ) ) || + ( mh != NULL && command.menu.menuRef == mh ) ) + { + wxMenuBar* mbar = wxMenuBar::MacGetInstalledMenuBar() ; + if ( mbar ) + { + wxMenu* menu = NULL ; + item = mbar->FindItem( id , &menu ) ; + } + } + else + { + wxMenu* itsMenu = NULL ; + UInt32 refCon ; + GetMenuItemRefCon( command.menu.menuRef , command.menu.menuItemIndex , &refCon ) ; + itsMenu = wxFindMenuFromMacMenu( command.menu.menuRef ) ; + if ( itsMenu != NULL ) + { + item = (wxMenuItem*) refCon ; + } + } } if ( item )