From 01ed0842ff0d57c2aed6f0712c0688a4f8d0a31a Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Wed, 27 Mar 2019 15:39:39 +0100 Subject: [PATCH 1/2] Set mnemonics for the closest preceding label Due to a wrong "else" in RealizeTabOrder() implementation, we could set the mnemonic widget for a previous widget using mnemonics (i.e. wxStaticText or wxStaticBox) rather than the one closest to the actual control activated by the mnemonic. --- src/gtk/window.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/gtk/window.cpp b/src/gtk/window.cpp index 375912170f..5010c5994a 100644 --- a/src/gtk/window.cpp +++ b/src/gtk/window.cpp @@ -4786,7 +4786,8 @@ void wxWindowGTK::RealizeTabOrder() } } } - else if ( win->GTKWidgetNeedsMnemonic() ) + + if ( win->GTKWidgetNeedsMnemonic() ) { mnemonicWindow = win; } From b0133392b7df8649b2aabb272bc0982f38b962a4 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Wed, 27 Mar 2019 15:41:53 +0100 Subject: [PATCH 2/2] Fall back on the main widget if connect one isn't focusable If neither main widget nor connect widget is focusable (which notably happens when they're the same anyhow, as is the case for wxChoice, for example), still use the main widget as mnemonic instead of not using any mnemonic at all. This fixes activation of a wxChoice preceded by wxStaticText by pressing the key combination corresponding to the label mnemonic, which didn't work previously. --- src/gtk/window.cpp | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/gtk/window.cpp b/src/gtk/window.cpp index 5010c5994a..510b337ac4 100644 --- a/src/gtk/window.cpp +++ b/src/gtk/window.cpp @@ -4768,22 +4768,21 @@ void wxWindowGTK::RealizeTabOrder() { if ( focusableFromKeyboard ) { - // wxComboBox et al. needs to focus on on a different - // widget than m_widget, so if the main widget isn't - // focusable try the connect widget + // We may need to focus on the connect widget if the + // main one isn't focusable, but note that we still use + // the main widget if neither it nor connect widget is + // focusable, without this using a wxStaticText before + // wxChoice wouldn't work at all, for example. GtkWidget* w = win->m_widget; if ( !gtk_widget_get_can_focus(w) ) { - w = win->GetConnectWidget(); - if ( !gtk_widget_get_can_focus(w) ) - w = NULL; + GtkWidget* const cw = win->GetConnectWidget(); + if ( cw != w && gtk_widget_get_can_focus(cw) ) + w = cw; } - if ( w ) - { - mnemonicWindow->GTKWidgetDoSetMnemonic(w); - mnemonicWindow = NULL; - } + mnemonicWindow->GTKWidgetDoSetMnemonic(w); + mnemonicWindow = NULL; } }