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
9816970797 which were, finally, misguided
and so are undone by this commit.

Closes #17911.
This commit is contained in:
Vadim Zeitlin
2018-01-30 01:42:06 +01:00
parent e5a1931b64
commit ea08b8539a
4 changed files with 21 additions and 9 deletions

View File

@@ -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:

View File

@@ -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
{

View File

@@ -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()