]> git.saurik.com Git - wxWidgets.git/blobdiff - src/mac/carbon/app.cpp
Finally removes occurences of OnMenuCommand and closes bug #1164678
[wxWidgets.git] / src / mac / carbon / app.cpp
index cf429f727eb75efc3ec52dc959710b7a780214c5..4bd1eea596e530f47242b3bf7b3be26ce7043166 100644 (file)
@@ -9,10 +9,6 @@
 // Licence:     wxWindows licence
 /////////////////////////////////////////////////////////////////////////////
 
-#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
-#pragma implementation "app.h"
-#endif
-
 #include "wx/wxprec.h"
 
 #include "wx/window.h"
@@ -443,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 )
         {
@@ -457,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 )
@@ -565,7 +605,7 @@ DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacAppEventHandler )
 WXIMPORT char std::__throws_bad_alloc ;
 #endif
 
-#if __WXDEBUG__
+#ifdef __WXDEBUG__
 
 pascal static void wxMacAssertOutputHandler(OSType componentSignature, UInt32 options,
     const char *assertionString, const char *exceptionLabelString,
@@ -619,7 +659,7 @@ bool wxApp::Initialize(int& argc, wxChar **argv)
 {
     // Mac-specific
 
-#if __WXDEBUG__
+#ifdef __WXDEBUG__
     InstallDebugAssertOutputHandler ( NewDebugAssertOutputHandlerUPP( wxMacAssertOutputHandler ) );
 #endif
     UMAInitToolbox( 4, sm_isEmbedded ) ;
@@ -1443,7 +1483,7 @@ bool wxApp::MacSendKeyDownEvent( wxWindow* focus , long keymessage , long modifi
                      event.SetEventObject(def);
                      def->Command(event);
                      return true ;
-                }
+                 }
             }
             /* generate wxID_CANCEL if command-. or <esc> has been pressed (typically in dialogs) */
             else if (keyval == WXK_ESCAPE || (keyval == '.' && modifiers & cmdKey ) )