From 18c45321f4550d1dfbc88d7134684a93f74f7a67 Mon Sep 17 00:00:00 2001 From: Stefan Csomor Date: Tue, 13 Apr 2021 17:34:34 +0200 Subject: [PATCH] Return bool from wxWidgetCocoaImpl::doCommandBySelector() This allows to determine whether the event was handled by wx code and perform further processing by feeding things back to native code if not. --- include/wx/osx/cocoa/private.h | 3 ++- src/osx/cocoa/window.mm | 14 +++++++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/include/wx/osx/cocoa/private.h b/include/wx/osx/cocoa/private.h index eafd4ab3a3..bf2c243a4a 100644 --- a/include/wx/osx/cocoa/private.h +++ b/include/wx/osx/cocoa/private.h @@ -199,7 +199,8 @@ public : virtual void cursorUpdate(WX_NSEvent event, WXWidget slf, void* _cmd); 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); + // Returns true if the event was processed by a user-defined event handler. + virtual bool doCommandBySelector(void* sel, 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/window.mm b/src/osx/cocoa/window.mm index b322e582c5..d5bfe85661 100644 --- a/src/osx/cocoa/window.mm +++ b/src/osx/cocoa/window.mm @@ -2129,7 +2129,7 @@ void wxWidgetCocoaImpl::insertText(NSString* text, WXWidget slf, void *_cmd) } } -void wxWidgetCocoaImpl::doCommandBySelector(void* sel, WXWidget slf, void* WXUNUSED(_cmd)) +bool wxWidgetCocoaImpl::doCommandBySelector(void* sel, WXWidget slf, void* WXUNUSED(_cmd)) { wxLogTrace(TRACE_KEYS, "Selector %s for %s", wxDumpSelector((SEL)sel), wxDumpNSView(slf)); @@ -2139,23 +2139,25 @@ void wxWidgetCocoaImpl::doCommandBySelector(void* sel, WXWidget slf, void* WXUNU // it is also possible to map 1 keystroke to multiple commands, eg Ctrl-O on mac is translated to the bash-equivalent of // execute and move back in history, since this results in two commands, Ctrl-O was sent twice as a wx key down event. // we now track the sending of the events to avoid duplicates. - + + bool handled = false; + if ( IsInNativeKeyDown() && !WasKeyDownSent()) { // If we have a corresponding key event, send wxEVT_KEY_DOWN now. // (see also: wxWidgetCocoaImpl::DoHandleKeyEvent) wxKeyEvent wxevent(wxEVT_KEY_DOWN); SetupKeyEvent( wxevent, GetLastNativeKeyDownEvent() ); - bool result = GetWXPeer()->OSXHandleKeyEvent(wxevent); + handled = GetWXPeer()->OSXHandleKeyEvent(wxevent); - if (!result) + if (!handled) { // Generate wxEVT_CHAR if wxEVT_KEY_DOWN is not handled. wxKeyEvent wxevent2(wxevent) ; wxevent2.SetEventType(wxEVT_CHAR); SetupKeyEvent( wxevent2, GetLastNativeKeyDownEvent() ); - GetWXPeer()->OSXHandleKeyEvent(wxevent2); + handled = GetWXPeer()->OSXHandleKeyEvent(wxevent2); } SetKeyDownSent(); } @@ -2163,6 +2165,8 @@ void wxWidgetCocoaImpl::doCommandBySelector(void* sel, WXWidget slf, void* WXUNU { wxLogTrace(TRACE_KEYS, "Doing nothing in doCommandBySelector:"); } + + return handled; } bool wxWidgetCocoaImpl::acceptsFirstResponder(WXWidget slf, void *_cmd)