From 87bba02fef2896104a983509b1d480ebf442c7b6 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 27 Oct 2019 00:02:29 +0200 Subject: [PATCH] Stop handling performKeyEquivalent: in wxOSX We can't handle the accelerators (known as "key equivalents" in Cocoa) in this function because it is called for the views in top to bottom order, while wx semantics is for accelerators to be handled in the accelerator table closest to the focused window. So just remove this code and rely on accelerator handling happening in wxWindowMac::OSXHandleKeyEvent() instead. Closes #13937. --- include/wx/osx/cocoa/private.h | 1 - src/osx/cocoa/textctrl.mm | 6 ---- src/osx/cocoa/window.mm | 50 ---------------------------------- 3 files changed, 57 deletions(-) diff --git a/include/wx/osx/cocoa/private.h b/include/wx/osx/cocoa/private.h index 0f8bff0b67..7e35c0e43c 100644 --- a/include/wx/osx/cocoa/private.h +++ b/include/wx/osx/cocoa/private.h @@ -185,7 +185,6 @@ public : virtual void keyEvent(WX_NSEvent event, WXWidget slf, void* _cmd); virtual void insertText(NSString* text, WXWidget slf, void* _cmd); virtual void doCommandBySelector(void* sel, WXWidget slf, void* _cmd); - virtual bool performKeyEquivalent(WX_NSEvent event, WXWidget slf, void* _cmd); virtual bool acceptsFirstResponder(WXWidget slf, void* _cmd); virtual bool becomeFirstResponder(WXWidget slf, void* _cmd); virtual bool resignFirstResponder(WXWidget slf, void* _cmd); diff --git a/src/osx/cocoa/textctrl.mm b/src/osx/cocoa/textctrl.mm index c27e2eaf81..d4d18a5200 100644 --- a/src/osx/cocoa/textctrl.mm +++ b/src/osx/cocoa/textctrl.mm @@ -368,12 +368,6 @@ NSView* wxMacEditHelper::ms_viewCurrentlyEdited = nil; [super flagsChanged:event]; } -- (BOOL) performKeyEquivalent:(NSEvent*) event -{ - BOOL retval = [super performKeyEquivalent:event]; - return retval; -} - - (void) insertText:(id) str { // We should never generate char events for the text being inserted diff --git a/src/osx/cocoa/window.mm b/src/osx/cocoa/window.mm index 1385439843..eaa006113f 100644 --- a/src/osx/cocoa/window.mm +++ b/src/osx/cocoa/window.mm @@ -1197,15 +1197,6 @@ void wxOSX_touchesEnded(NSView* self, SEL _cmd, NSEvent *event) } #endif // MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_10 -BOOL wxOSX_performKeyEquivalent(NSView* self, SEL _cmd, NSEvent *event) -{ - wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self ); - if (impl == NULL) - return NO; - - return impl->performKeyEquivalent(event, self, _cmd); -} - BOOL wxOSX_acceptsFirstResponder(NSView* self, SEL _cmd) { wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self ); @@ -2212,45 +2203,6 @@ void wxWidgetCocoaImpl::doCommandBySelector(void* sel, WXWidget slf, void* _cmd) } } -bool wxWidgetCocoaImpl::performKeyEquivalent(WX_NSEvent event, WXWidget slf, void *_cmd) -{ - wxLogTrace(TRACE_KEYS, "Got %s for %s", - wxDumpSelector((SEL)_cmd), wxDumpNSView(slf)); - - 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 -#if wxUSE_ACCEL - int command = m_wxPeer->GetAcceleratorTable()->GetCommand( wxevent ); - if (command != -1) - { - wxEvtHandler * const handler = m_wxPeer->GetEventHandler(); - - wxCommandEvent command_event( wxEVT_MENU, command ); - command_event.SetEventObject( wxevent.GetEventObject() ); - handled = handler->ProcessEvent( command_event ); - - if ( !handled ) - { - // accelerators can also be used with buttons, try them too - command_event.SetEventType(wxEVT_BUTTON); - handled = handler->ProcessEvent( command_event ); - } - } -#endif // wxUSE_ACCEL - - if ( !handled ) - { - wxOSX_PerformKeyEventHandlerPtr superimpl = (wxOSX_PerformKeyEventHandlerPtr) [[slf superclass] instanceMethodForSelector:(SEL)_cmd]; - return superimpl(slf, (SEL)_cmd, event); - } - return YES; -} - bool wxWidgetCocoaImpl::acceptsFirstResponder(WXWidget slf, void *_cmd) { if ( HasUserKeyHandling() ) @@ -2531,8 +2483,6 @@ void wxOSXCocoaClassAddWXMethods(Class c, wxOSXSkipOverrides skipFlags) wxOSX_CLASS_ADD_METHOD(c, @selector(insertText:), (IMP) wxOSX_insertText, "v@:@" ) - wxOSX_CLASS_ADD_METHOD(c, @selector(performKeyEquivalent:), (IMP) wxOSX_performKeyEquivalent, "c@:@" ) - wxOSX_CLASS_ADD_METHOD(c, @selector(acceptsFirstResponder), (IMP) wxOSX_acceptsFirstResponder, "c@:" ) wxOSX_CLASS_ADD_METHOD(c, @selector(becomeFirstResponder), (IMP) wxOSX_becomeFirstResponder, "c@:" ) wxOSX_CLASS_ADD_METHOD(c, @selector(resignFirstResponder), (IMP) wxOSX_resignFirstResponder, "c@:" )