]> git.saurik.com Git - wxWidgets.git/commitdiff
move accel handling in front of the normal keyDown handling, support non-command...
authorStefan Csomor <csomor@advancedconcepts.ch>
Wed, 2 Mar 2011 16:23:57 +0000 (16:23 +0000)
committerStefan Csomor <csomor@advancedconcepts.ch>
Wed, 2 Mar 2011 16:23:57 +0000 (16:23 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@67110 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

src/osx/cocoa/window.mm

index f7cbe4fb7cf55cdbb668cd1caa0052d82cb29958..8bbb6b62261e9b0f9bd9b2c7ab28fe633af3f616 100644 (file)
@@ -999,7 +999,15 @@ void wxWidgetCocoaImpl::mouseEvent(WX_NSEvent event, WXWidget slf, void *_cmd)
 void wxWidgetCocoaImpl::keyEvent(WX_NSEvent event, WXWidget slf, void *_cmd)
 {
     if ( [event type] == NSKeyDown )
+    {
+        // there are key equivalents that are not command-combos and therefore not handled by cocoa automatically, 
+        // therefore we call the menubar directly here, exit if the menu is handling the shortcut
+        if ( [[[NSApplication sharedApplication] mainMenu] performKeyEquivalent:event] )
+            return;
+    
         m_lastKeyDownEvent = event;
+    }
+    
     if ( GetFocusedViewInWindow([slf window]) != slf || m_hasEditor || !DoHandleKeyEvent(event) )
     {
         wxOSX_EventHandlerPtr superimpl = (wxOSX_EventHandlerPtr) [[slf superclass] instanceMethodForSelector:(SEL)_cmd];
@@ -1020,7 +1028,31 @@ void wxWidgetCocoaImpl::insertText(NSString* text, WXWidget slf, void *_cmd)
 
 bool wxWidgetCocoaImpl::performKeyEquivalent(WX_NSEvent event, WXWidget slf, void *_cmd)
 {
-    if ( GetFocusedViewInWindow([slf window]) != slf || m_hasEditor || !DoHandleKeyEvent(event) )
+    bool handled = false;
+    
+    wxKeyEvent wxevent(wxEVT_KEY_DOWN);
+    SetupKeyEvent( wxevent, event );
+   
+    // because performKeyEquivalent is going up the entire view hierarchy, we don't have to
+    // walk up the ancestors ourselves but let cocoa do it
+    
+    int command = m_wxPeer->GetAcceleratorTable()->GetCommand( wxevent );
+    if (command != -1)
+    {
+        wxEvtHandler * const handler = m_wxPeer->GetEventHandler();
+        
+        wxCommandEvent command_event( wxEVT_COMMAND_MENU_SELECTED, command );
+        handled = handler->ProcessEvent( command_event );
+        
+        if ( !handled )
+        {
+            // accelerators can also be used with buttons, try them too
+            command_event.SetEventType(wxEVT_COMMAND_BUTTON_CLICKED);
+            handled = handler->ProcessEvent( command_event );
+        }
+    }
+    
+    if ( !handled )
     {
         wxOSX_PerformKeyEventHandlerPtr superimpl = (wxOSX_PerformKeyEventHandlerPtr) [[slf superclass] instanceMethodForSelector:(SEL)_cmd];
         return superimpl(slf, (SEL)_cmd, event);