From ea08b8539adcf1b9d6f9c8f5e283c80f00123202 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 30 Jan 2018 01:42:06 +0100 Subject: [PATCH] Generate wxEVT_SEARCHCTRL_SEARCH_BTN when Enter is pressed Make it possible to bind to just wxEVT_SEARCHCTRL_SEARCH_BTN under all platforms: previously, it was also necessary to bind to wxEVT_TEXT_ENTER when using the generic implementation, as pressing Enter in the text control didn't generate the dedicated SEARCH event. It does now, and, to avoid any confusion, the control does not generate wxEVT_TEXT_ENTER events at all any more. This is not really incompatible, as wxOSX never generated these events anyhow and the generic version only did for a couple of days, since the changes of 981697079739c4a920dc2d2cb261ca57dc2169f6 which were, finally, misguided and so are undone by this commit. Closes #17911. --- docs/changes.txt | 1 + interface/wx/srchctrl.h | 13 ++++++------- src/generic/srchctlg.cpp | 14 +++++++++++++- src/tiff | 2 +- 4 files changed, 21 insertions(+), 9 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index 42f60e8942..d6ae9203dc 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -177,6 +177,7 @@ All (GUI): - Add Set/GetFooter/Text/Icon() to wxRichMessageDialog (Tobias Taschner) - Add wxFloatingPointValidator::SetFactor(). - Add "hint" property to wxSearchCtrl XRC handler. +- Generate wxEVT_SEARCHCTRL_SEARCH_BTN on Enter under all platforms. wxGTK: diff --git a/interface/wx/srchctrl.h b/interface/wx/srchctrl.h index 51410de7bb..d888d581fa 100644 --- a/interface/wx/srchctrl.h +++ b/interface/wx/srchctrl.h @@ -12,10 +12,6 @@ control, and a cancel button. @beginStyleTable - @style{wxTE_PROCESS_ENTER} - The control will generate the event @c wxEVT_TEXT_ENTER - (otherwise pressing Enter key is either processed internally by the - control or used for navigation between dialog controls). @style{wxTE_PROCESS_TAB} The control will receive @c wxEVT_CHAR events for TAB pressed - normally, TAB is used for passing to the next control in a dialog @@ -39,8 +35,11 @@ @endStyleTable @beginEventEmissionTable{wxCommandEvent} - To retrieve actual search queries, use EVT_TEXT and EVT_TEXT_ENTER events, - just as you would with wxTextCtrl. + To react to the changes in the control contents, use EVT_TEXT event, just + as you would do with wxTextCtrl. However it is recommended to use + EVT_SEARCHCTRL_SEARCH_BTN to actually start searching to avoid doing it too + soon, while the user is still typing (note that EVT_SEARCHCTRL_SEARCH_BTN + is also triggered by pressing Enter in the control). @event{EVT_SEARCHCTRL_SEARCH_BTN(id, func)} Respond to a @c wxEVT_SEARCHCTRL_SEARCH_BTN event, generated when the search button is clicked. Note that this does not initiate a search on @@ -56,7 +55,7 @@ @category{ctrl} @appearance{searchctrl} - @see wxTextCtrl::Create, wxValidator + @see wxTextCtrl */ class wxSearchCtrl : public wxTextCtrl { diff --git a/src/generic/srchctlg.cpp b/src/generic/srchctlg.cpp index 93b2321b05..ce82d7875d 100644 --- a/src/generic/srchctlg.cpp +++ b/src/generic/srchctlg.cpp @@ -92,6 +92,18 @@ protected: m_search->GetEventHandler()->ProcessEvent(event); } + void OnTextEnter(wxCommandEvent& WXUNUSED(event)) + { + if ( !IsEmpty() ) + { + wxCommandEvent event(wxEVT_SEARCHCTRL_SEARCH_BTN, m_search->GetId()); + event.SetEventObject(m_search); + event.SetString(m_search->GetValue()); + + m_search->ProcessWindowEvent(event); + } + } + void OnTextUrl(wxTextUrlEvent& eventText) { // copy constructor is disabled for some reason? @@ -149,7 +161,7 @@ private: wxBEGIN_EVENT_TABLE(wxSearchTextCtrl, wxTextCtrl) EVT_TEXT(wxID_ANY, wxSearchTextCtrl::OnText) - EVT_TEXT_ENTER(wxID_ANY, wxSearchTextCtrl::OnText) + EVT_TEXT_ENTER(wxID_ANY, wxSearchTextCtrl::OnTextEnter) EVT_TEXT_URL(wxID_ANY, wxSearchTextCtrl::OnTextUrl) EVT_TEXT_MAXLEN(wxID_ANY, wxSearchTextCtrl::OnText) wxEND_EVENT_TABLE() diff --git a/src/tiff b/src/tiff index 3c7e58ef64..aa65abe076 160000 --- a/src/tiff +++ b/src/tiff @@ -1 +1 @@ -Subproject commit 3c7e58ef646090569de1a35cdc93abce2c547172 +Subproject commit aa65abe0762209d40ec5d4343ec426a4d67caf2d