From 00ee56c01d802efcd0cf0959bb4d35c455a083f9 Mon Sep 17 00:00:00 2001 From: Quin Gillespie Date: Fri, 25 Sep 2026 17:19:49 -0600 Subject: [PATCH] Allow opening wxSearchCtrl menu from keyboard with Alt-Down The search menu could only be opened by clicking the button showing it, which doesn't accept focus from the keyboard on purpose, so keyboard and screen reader users couldn't use it at all. Handle Alt-Down in the text part of the control and show the menu from there, as suggested in the comments of the original ticket. Fixes #18457. Closes #27093. --- include/wx/generic/srchctlg.h | 1 + interface/wx/srchctrl.h | 3 +++ src/generic/srchctlg.cpp | 20 ++++++++++++++++++++ 3 files changed, 24 insertions(+) diff --git a/include/wx/generic/srchctlg.h b/include/wx/generic/srchctlg.h index f1d186b751..37f59df29d 100644 --- a/include/wx/generic/srchctlg.h +++ b/include/wx/generic/srchctlg.h @@ -169,6 +169,7 @@ protected: private: friend class wxSearchButton; + friend class wxSearchTextCtrl; #if defined(__WXMSW__) && !defined(__WXUNIVERSAL__) // Implement wxMSW-specific pure virtual function by forwarding it to the diff --git a/interface/wx/srchctrl.h b/interface/wx/srchctrl.h index 8d5ff4efdb..866fb7f4a2 100644 --- a/interface/wx/srchctrl.h +++ b/interface/wx/srchctrl.h @@ -139,6 +139,9 @@ public: Sets the search control's menu object. If there is already a menu associated with the search control it is deleted. + In the ports using the generic implementation of this control, e.g. + wxMSW, the menu can be opened from the keyboard using Alt-Down. + @param menu Menu to attach to the search control. */ diff --git a/src/generic/srchctlg.cpp b/src/generic/srchctlg.cpp index 8956d91e2b..a4c6f87d04 100644 --- a/src/generic/srchctlg.cpp +++ b/src/generic/srchctlg.cpp @@ -81,6 +81,23 @@ protected: m_search->GetEventHandler()->ProcessEvent(event); } +#if wxUSE_MENUS + void OnKeyDown(wxKeyEvent& event) + { + // Alt-Down is the usual way of opening a drop-down menu and the only + // way of opening the search menu from the keyboard, as the button + // showing it doesn't accept focus. + if ( event.GetKeyCode() == WXK_DOWN && event.AltDown() && + m_search->HasMenu() ) + { + m_search->PopupSearchMenu(); + return; + } + + event.Skip(); + } +#endif // wxUSE_MENUS + void OnTextEnter(wxCommandEvent& WXUNUSED(event)) { if ( !IsEmpty() ) @@ -135,6 +152,9 @@ private: }; wxBEGIN_EVENT_TABLE(wxSearchTextCtrl, wxTextCtrl) +#if wxUSE_MENUS + EVT_KEY_DOWN(wxSearchTextCtrl::OnKeyDown) +#endif // wxUSE_MENUS EVT_TEXT(wxID_ANY, wxSearchTextCtrl::OnText) EVT_TEXT_ENTER(wxID_ANY, wxSearchTextCtrl::OnTextEnter) EVT_TEXT_MAXLEN(wxID_ANY, wxSearchTextCtrl::OnText)