From c714e75555cae40ff5014b6fa61f18483c19bac3 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 24 Jan 2021 21:01:09 +0100 Subject: [PATCH] Generate wxEVT_CHAR_HOOK events before accelerators This is more consistent with the other ports and allows to use wxEVT_CHAR_HOOK handler to preempt processing of the accelerators (but notice that under macOS this only works for accelerators that are part of wxAcceleratorTable and not those associated with the menu items, as the latter ones are not handled by this code at all). Also simplify the code structure a little by getting rid of an unnecessary and more confusing than helpful "handled" variable. --- src/osx/window_osx.cpp | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/src/osx/window_osx.cpp b/src/osx/window_osx.cpp index b3609f8026..ef60bef9da 100644 --- a/src/osx/window_osx.cpp +++ b/src/osx/window_osx.cpp @@ -2568,9 +2568,8 @@ bool wxWindowMac::OSXHandleKeyEvent( wxKeyEvent& event ) : "unknown", wxDumpWindow(this)); - bool handled = false; - - // moved the ordinary key event sending AFTER the accel evaluation + if ( HandleWindowEvent(event) ) + return true; #if wxUSE_ACCEL if (event.GetEventType() == wxEVT_CHAR_HOOK) @@ -2584,16 +2583,16 @@ bool wxWindowMac::OSXHandleKeyEvent( wxKeyEvent& event ) wxEvtHandler * const handler = ancestor->GetEventHandler(); wxCommandEvent command_event( wxEVT_MENU, command ); - handled = handler->ProcessEvent( command_event ); - - if ( !handled ) + if ( !handler->ProcessEvent( command_event ) ) { // accelerators can also be used with buttons, try them too command_event.SetEventType(wxEVT_BUTTON); - handled = handler->ProcessEvent( command_event ); + handler->ProcessEvent( command_event ); } - break; + // In any case, the event was handled as it triggered an + // accelerator. + return true; } if (ancestor->IsTopNavigationDomain(wxWindow::Navigation_Accel)) @@ -2604,10 +2603,7 @@ bool wxWindowMac::OSXHandleKeyEvent( wxKeyEvent& event ) } #endif // wxUSE_ACCEL - if ( !handled ) - handled = HandleWindowEvent( event ) ; - - return handled ; + return false; } /* static */