From 21823bd37a02f601f879039b3971ca2e7fc99516 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 29 Jan 2018 18:29:34 +0100 Subject: [PATCH 01/12] Log focus messages for the search control in the widgets sample This makes it easier to test various issues related to focus events for composite controls, such as wxSearchCtrl. --- samples/widgets/searchctrl.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/samples/widgets/searchctrl.cpp b/samples/widgets/searchctrl.cpp index 23750f7a46..7586ffef10 100644 --- a/samples/widgets/searchctrl.cpp +++ b/samples/widgets/searchctrl.cpp @@ -86,6 +86,9 @@ protected: void OnSearch(wxCommandEvent& event); void OnSearchCancel(wxCommandEvent& event); + void OnSetFocus(wxFocusEvent& event); + void OnKillFocus(wxFocusEvent& event); + wxMenu* CreateTestMenu(); // (re)create the control @@ -171,6 +174,9 @@ void SearchCtrlWidgetsPage::CreateControl() m_srchCtrl = new wxSearchCtrl(this, -1, wxEmptyString, wxDefaultPosition, wxSize(150, -1), style); + + m_srchCtrl->Bind(wxEVT_SET_FOCUS, &SearchCtrlWidgetsPage::OnSetFocus, this); + m_srchCtrl->Bind(wxEVT_KILL_FOCUS, &SearchCtrlWidgetsPage::OnKillFocus, this); } void SearchCtrlWidgetsPage::RecreateWidget() @@ -239,4 +245,18 @@ void SearchCtrlWidgetsPage::OnSearchCancel(wxCommandEvent& event) event.Skip(); } +void SearchCtrlWidgetsPage::OnSetFocus(wxFocusEvent& event) +{ + wxLogMessage("Search control got focus"); + + event.Skip(); +} + +void SearchCtrlWidgetsPage::OnKillFocus(wxFocusEvent& event) +{ + wxLogMessage("Search control lost focus"); + + event.Skip(); +} + #endif // wxUSE_SEARCHCTRL From 3b40ff0d4135076ef7811a98687e14c7b21cd1a4 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 29 Jan 2018 18:32:54 +0100 Subject: [PATCH 02/12] Send wxEVT_SET_FOCUS for composite window when a child gets focus wxCompositeWindow already connected to child wxEVT_KILL_FOCUS events and generated the same event for the composite window itself, but didn't do it for wxEVT_SET_FOCUS, resulting in not getting these events for the main window as expected. E.g. this resulted in never getting any wxEVT_SET_FOCUS events for wxSearchCtrl when using its generic version (i.e. not under Mac). Fix this by connecting to wxEVT_SET_FOCUS events for the children too. Note that this relies on having a correct "previously focused window" in these events, if this doesn't work reliably for some ports, we might need to maintain a "bool m_hasFocus" field in wxCompositeWindow itself instead. Also note that we might avoid having all this code in wxCompositeWindow if we translated the underlying native focus event to wxFocusEvents for both the real window and its GetMainWindowOfCompositeControl() if it's different. This could potentially be simpler and would definitely be more efficient, but would require more changes. Closes #15569. --- include/wx/compositewin.h | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/include/wx/compositewin.h b/include/wx/compositewin.h index 567d0e8999..c9a339ac44 100644 --- a/include/wx/compositewin.h +++ b/include/wx/compositewin.h @@ -193,7 +193,10 @@ private: if ( child == this ) return; // not a child, we don't want to Connect() to ourselves - // Always capture wxEVT_KILL_FOCUS: + child->Connect(wxEVT_SET_FOCUS, + wxFocusEventHandler(wxCompositeWindow::OnSetFocus), + NULL, this); + child->Connect(wxEVT_KILL_FOCUS, wxFocusEventHandler(wxCompositeWindow::OnKillFocus), NULL, this); @@ -221,6 +224,27 @@ private: event.Skip(); } + void OnSetFocus(wxFocusEvent& event) + { + event.Skip(); + + // When a child of a composite window gains focus, the entire composite + // focus gains focus as well -- unless it had it already. + // + // We suppose that we hadn't had focus if the event doesn't carry the + // previously focused window as it normally means that it comes from + // outside of this program. + wxWindow* const oldFocus = event.GetWindow(); + if ( !oldFocus || oldFocus->GetMainWindowOfCompositeControl() != this ) + { + wxFocusEvent eventThis(wxEVT_SET_FOCUS, this->GetId()); + eventThis.SetEventObject(this); + eventThis.SetWindow(event.GetWindow()); + + this->ProcessWindowEvent(eventThis); + } + } + void OnKillFocus(wxFocusEvent& event) { // Ignore focus changes within the composite control: From 99dea2e2e06d6ccab88f7766cbf9d4dd89523458 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 29 Jan 2018 18:45:45 +0100 Subject: [PATCH 03/12] Remove unnecessary wxSearchCtrl::OnSetFocus() This was useless as wxCompositeWindow, from which the generic wxSearchCtrl derives, already sets focus to its first child and, since the last commit, even harmful as it now resulted in calls to SetFocus() from inside wxEVT_SET_FOCUS handler which is forbidden at least under MSW. See #15569. --- include/wx/generic/srchctlg.h | 1 - src/generic/srchctlg.cpp | 9 --------- 2 files changed, 10 deletions(-) diff --git a/include/wx/generic/srchctlg.h b/include/wx/generic/srchctlg.h index ebcae90e78..67d0c99ca2 100644 --- a/include/wx/generic/srchctlg.h +++ b/include/wx/generic/srchctlg.h @@ -223,7 +223,6 @@ protected: void OnCancelButton( wxCommandEvent& event ); - void OnSetFocus( wxFocusEvent& event ); void OnSize( wxSizeEvent& event ); bool HasMenu() const diff --git a/src/generic/srchctlg.cpp b/src/generic/srchctlg.cpp index 5ad5654fe4..01acd68ea9 100644 --- a/src/generic/srchctlg.cpp +++ b/src/generic/srchctlg.cpp @@ -241,7 +241,6 @@ wxEND_EVENT_TABLE() wxBEGIN_EVENT_TABLE(wxSearchCtrl, wxSearchCtrlBase) EVT_SEARCHCTRL_CANCEL_BTN(wxID_ANY, wxSearchCtrl::OnCancelButton) - EVT_SET_FOCUS(wxSearchCtrl::OnSetFocus) EVT_SIZE(wxSearchCtrl::OnSize) wxEND_EVENT_TABLE() @@ -1235,14 +1234,6 @@ void wxSearchCtrl::OnCancelButton( wxCommandEvent& event ) event.Skip(); } -void wxSearchCtrl::OnSetFocus( wxFocusEvent& /*event*/ ) -{ - if ( m_text ) - { - m_text->SetFocus(); - } -} - void wxSearchCtrl::OnSize( wxSizeEvent& WXUNUSED(event) ) { LayoutControls(); From 05ebeb6bac8df809cc65f7de1e6960b04c22676d Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 29 Jan 2018 19:04:47 +0100 Subject: [PATCH 04/12] Get rid of CppUnit compatibility macros in wxSearchCtrl unit test No real changes, just remove all the CppUnit machinery not needed any longer and replace it with a simple test function. --- tests/controls/searchctrltest.cpp | 53 +++++++++++-------------------- 1 file changed, 18 insertions(+), 35 deletions(-) diff --git a/tests/controls/searchctrltest.cpp b/tests/controls/searchctrltest.cpp index a9bfb68103..2c8e5b821b 100644 --- a/tests/controls/searchctrltest.cpp +++ b/tests/controls/searchctrltest.cpp @@ -20,50 +20,33 @@ #include "wx/srchctrl.h" -class SearchCtrlTestCase : public CppUnit::TestCase +class SearchCtrlTestCase { public: - SearchCtrlTestCase() { } + SearchCtrlTestCase() + : m_search(new wxSearchCtrl(wxTheApp->GetTopWindow(), wxID_ANY)) + { + } - virtual void setUp(); - virtual void tearDown(); + ~SearchCtrlTestCase() + { + delete m_search; + } -private: - CPPUNIT_TEST_SUITE( SearchCtrlTestCase ); - CPPUNIT_TEST( Focus ); - CPPUNIT_TEST_SUITE_END(); - - void Focus(); - - wxSearchCtrl* m_search; - - wxDECLARE_NO_COPY_CLASS(SearchCtrlTestCase); +protected: + wxSearchCtrl* const m_search; }; -// register in the unnamed registry so that these tests are run by default -CPPUNIT_TEST_SUITE_REGISTRATION( SearchCtrlTestCase ); +#define SEARCH_CTRL_TEST_CASE(name, tags) \ + TEST_CASE_METHOD(SearchCtrlTestCase, name, tags) -// also include in its own registry so that these tests can be run alone -CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( SearchCtrlTestCase, "SearchCtrlTestCase" ); - -void SearchCtrlTestCase::setUp() -{ - m_search = new wxSearchCtrl(wxTheApp->GetTopWindow(), wxID_ANY); -} - -void SearchCtrlTestCase::tearDown() -{ - delete m_search; - m_search = NULL; -} - -void SearchCtrlTestCase::Focus() -{ - // TODO OS X test only passes when run solo ... +// TODO OS X test only passes when run solo ... #ifndef __WXOSX__ +SEARCH_CTRL_TEST_CASE("wxSearchCtrl::Focus", "[wxSearchCtrl][focus]") +{ m_search->SetFocus(); - CPPUNIT_ASSERT( m_search->HasFocus() ); -#endif + CHECK( m_search->HasFocus() ); } +#endif // !__WXOSX__ #endif // wxUSE_SEARCHCTRL From 58ac3d3690f05c98c2a377a7fe92c14ed11e9ca8 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 29 Jan 2018 19:33:29 +0100 Subject: [PATCH 05/12] Fix wxSearchCtrl::ChangeValue() to actually change value This was broken because wxSearchCtrl inherited the base class version of ChangeValue() which didn't really work for it due to the poor way in which wxTextEntry is designed (see #18071). Closes #16998. --- include/wx/generic/srchctlg.h | 2 ++ src/generic/srchctlg.cpp | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/include/wx/generic/srchctlg.h b/include/wx/generic/srchctlg.h index 67d0c99ca2..188a92aa2e 100644 --- a/include/wx/generic/srchctlg.h +++ b/include/wx/generic/srchctlg.h @@ -88,6 +88,8 @@ public: // operations // ---------- + virtual void ChangeValue(const wxString& value) wxOVERRIDE; + // editing virtual void Clear() wxOVERRIDE; virtual void Replace(long from, long to, const wxString& value) wxOVERRIDE; diff --git a/src/generic/srchctlg.cpp b/src/generic/srchctlg.cpp index 01acd68ea9..93b2321b05 100644 --- a/src/generic/srchctlg.cpp +++ b/src/generic/srchctlg.cpp @@ -915,6 +915,14 @@ wxTextCtrl& operator<<(double d); wxTextCtrl& operator<<(const wxChar c); #endif +// Note that overriding DoSetValue() is currently insufficient because the base +// class ChangeValue() only updates m_hintData of this object (which is null +// anyhow), instead of updating m_text->m_hintData, see #16998. +void wxSearchCtrl::ChangeValue(const wxString& value) +{ + m_text->ChangeValue(value); +} + void wxSearchCtrl::DoSetValue(const wxString& value, int flags) { m_text->DoSetValue(value, flags); From f24872f6f419db6567bc514e7f9755dd0529dfd1 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 29 Jan 2018 19:08:16 +0100 Subject: [PATCH 06/12] Add unit test for wxSearchCtrl::ChangeValue() Verify that it actually does change the value. See #16998. --- tests/controls/searchctrltest.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/controls/searchctrltest.cpp b/tests/controls/searchctrltest.cpp index 2c8e5b821b..31dc748322 100644 --- a/tests/controls/searchctrltest.cpp +++ b/tests/controls/searchctrltest.cpp @@ -49,4 +49,12 @@ SEARCH_CTRL_TEST_CASE("wxSearchCtrl::Focus", "[wxSearchCtrl][focus]") } #endif // !__WXOSX__ +SEARCH_CTRL_TEST_CASE("wxSearchCtrl::ChangeValue", "[wxSearchCtrl][text]") +{ + CHECK( m_search->GetValue() == wxString() ); + + m_search->ChangeValue("foo"); + CHECK( m_search->GetValue() == "foo" ); +} + #endif // wxUSE_SEARCHCTRL From f079f11736a1e9d7a08d38b046fe06ee8ccf62bf Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 29 Jan 2018 19:40:03 +0100 Subject: [PATCH 07/12] Log EVT_TEXT_ENTER events for wxSearchCtrl in the widgets sample This is convenient for checking that the behaviour is consistent among different platforms. See #17911. --- samples/widgets/searchctrl.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/samples/widgets/searchctrl.cpp b/samples/widgets/searchctrl.cpp index 7586ffef10..77cf9238ea 100644 --- a/samples/widgets/searchctrl.cpp +++ b/samples/widgets/searchctrl.cpp @@ -83,6 +83,8 @@ protected: void OnToggleCancelButton(wxCommandEvent&); void OnToggleSearchMenu(wxCommandEvent&); + void OnTextEnter(wxCommandEvent& event); + void OnSearch(wxCommandEvent& event); void OnSearchCancel(wxCommandEvent& event); @@ -114,6 +116,8 @@ wxBEGIN_EVENT_TABLE(SearchCtrlWidgetsPage, WidgetsPage) EVT_CHECKBOX(ID_CANCEL_CB, SearchCtrlWidgetsPage::OnToggleCancelButton) EVT_CHECKBOX(ID_MENU_CB, SearchCtrlWidgetsPage::OnToggleSearchMenu) + EVT_TEXT_ENTER(wxID_ANY, SearchCtrlWidgetsPage::OnTextEnter) + EVT_SEARCHCTRL_SEARCH_BTN(wxID_ANY, SearchCtrlWidgetsPage::OnSearch) EVT_SEARCHCTRL_CANCEL_BTN(wxID_ANY, SearchCtrlWidgetsPage::OnSearchCancel) wxEND_EVENT_TABLE() @@ -233,6 +237,12 @@ void SearchCtrlWidgetsPage::OnToggleSearchMenu(wxCommandEvent&) m_srchCtrl->SetMenu(NULL); } +void SearchCtrlWidgetsPage::OnTextEnter(wxCommandEvent& event) +{ + wxLogMessage("Search control: enter pressed, contents is \"%s\".", + event.GetString()); +} + void SearchCtrlWidgetsPage::OnSearch(wxCommandEvent& event) { wxLogMessage("Search button: search for \"%s\".", event.GetString()); From e5a1931b64d2272b24c8fcbef41efa3c9de91d84 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 29 Jan 2018 23:14:44 +0100 Subject: [PATCH 08/12] Log wxEVT_TEXT events for wxSearchCtrl in widgets sample This is useful to check that these events are generated under all platforms. --- samples/widgets/searchctrl.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/samples/widgets/searchctrl.cpp b/samples/widgets/searchctrl.cpp index 77cf9238ea..a647835ed8 100644 --- a/samples/widgets/searchctrl.cpp +++ b/samples/widgets/searchctrl.cpp @@ -83,6 +83,7 @@ protected: void OnToggleCancelButton(wxCommandEvent&); void OnToggleSearchMenu(wxCommandEvent&); + void OnText(wxCommandEvent& event); void OnTextEnter(wxCommandEvent& event); void OnSearch(wxCommandEvent& event); @@ -116,6 +117,7 @@ wxBEGIN_EVENT_TABLE(SearchCtrlWidgetsPage, WidgetsPage) EVT_CHECKBOX(ID_CANCEL_CB, SearchCtrlWidgetsPage::OnToggleCancelButton) EVT_CHECKBOX(ID_MENU_CB, SearchCtrlWidgetsPage::OnToggleSearchMenu) + EVT_TEXT(wxID_ANY, SearchCtrlWidgetsPage::OnText) EVT_TEXT_ENTER(wxID_ANY, SearchCtrlWidgetsPage::OnTextEnter) EVT_SEARCHCTRL_SEARCH_BTN(wxID_ANY, SearchCtrlWidgetsPage::OnSearch) @@ -237,6 +239,12 @@ void SearchCtrlWidgetsPage::OnToggleSearchMenu(wxCommandEvent&) m_srchCtrl->SetMenu(NULL); } +void SearchCtrlWidgetsPage::OnText(wxCommandEvent& event) +{ + wxLogMessage("Search control: text changes, contents is \"%s\".", + event.GetString()); +} + void SearchCtrlWidgetsPage::OnTextEnter(wxCommandEvent& event) { wxLogMessage("Search control: enter pressed, contents is \"%s\".", From ea08b8539adcf1b9d6f9c8f5e283c80f00123202 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 30 Jan 2018 01:42:06 +0100 Subject: [PATCH 09/12] 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 From 784a397348da3289117324a88fad4f345f3ca702 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 30 Jan 2018 01:45:28 +0100 Subject: [PATCH 10/12] Remove wxEVT_TEXT_URL generation from wxSearchCtrl This event doesn't make any sense for this control, was never generated by the native macOS version and couldn't be generated under MSW neither as it's only supported by the multiline control and not the single-line version used here, so having this code in wxSearchCtrl just made no sense at all. --- src/generic/srchctlg.cpp | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/src/generic/srchctlg.cpp b/src/generic/srchctlg.cpp index ce82d7875d..a0bcf165fa 100644 --- a/src/generic/srchctlg.cpp +++ b/src/generic/srchctlg.cpp @@ -104,21 +104,6 @@ protected: } } - void OnTextUrl(wxTextUrlEvent& eventText) - { - // copy constructor is disabled for some reason? - //wxTextUrlEvent event(eventText); - wxTextUrlEvent event( - m_search->GetId(), - eventText.GetMouseEvent(), - eventText.GetURLStart(), - eventText.GetURLEnd() - ); - event.SetEventObject(m_search); - - m_search->GetEventHandler()->ProcessEvent(event); - } - #ifdef __WXMSW__ // We increase the text control height to be the same as for the controls // with border as this is what we actually need here because even though @@ -162,7 +147,6 @@ private: wxBEGIN_EVENT_TABLE(wxSearchTextCtrl, wxTextCtrl) EVT_TEXT(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() From ce43f772a9833d458fb4deb053ece681e62eeed5 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 30 Jan 2018 01:47:47 +0100 Subject: [PATCH 11/12] Don't erase background of wxSearchCtrl buttons twice Set background style to indicate that wxSearchButton is painted entirely by its wxEVT_PAINT handler. This should eliminate potential flicker under MSW. --- src/generic/srchctlg.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/generic/srchctlg.cpp b/src/generic/srchctlg.cpp index a0bcf165fa..6775f9bcae 100644 --- a/src/generic/srchctlg.cpp +++ b/src/generic/srchctlg.cpp @@ -162,7 +162,9 @@ public: m_search(search), m_eventType(eventType), m_bmp(bmp) - { } + { + SetBackgroundStyle(wxBG_STYLE_PAINT); + } void SetBitmapLabel(const wxBitmap& label) { From 94620f6c5944fe5b953cbb36652406b959b55a40 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 30 Jan 2018 02:01:40 +0100 Subject: [PATCH 12/12] Use simple wxEVT_SEARCH[_CANCEL] names for wxSearchCtrl events The old wxEVT_SEARCHCTRL_{SEARCH,CANCEL}_BTN event names were unwieldy and misleading because both of these events can be generated without using the buttons, but by pressing Enter or Esc (the latter currently works under macOS only, but this could change in the future). --- docs/changes.txt | 3 ++- include/wx/srchctrl.h | 21 ++++++++++++++------- interface/wx/srchctrl.h | 20 ++++++++++---------- samples/widgets/searchctrl.cpp | 4 ++-- src/common/srchcmn.cpp | 4 ++-- src/generic/srchctlg.cpp | 12 ++++++------ src/osx/srchctrl_osx.cpp | 4 ++-- 7 files changed, 38 insertions(+), 30 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index d6ae9203dc..03fbc91981 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -177,7 +177,8 @@ 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. +- Add wxEVT_SEARCH[_CANCEL] synonyms for wxSearchCtrl events. +- Generate wxEVT_SEARCH on Enter under all platforms. wxGTK: diff --git a/include/wx/srchctrl.h b/include/wx/srchctrl.h index 791fcb8092..8a0fa4da73 100644 --- a/include/wx/srchctrl.h +++ b/include/wx/srchctrl.h @@ -41,8 +41,8 @@ extern WXDLLIMPEXP_DATA_CORE(const char) wxSearchCtrlNameStr[]; -wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_SEARCHCTRL_CANCEL_BTN, wxCommandEvent); -wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_SEARCHCTRL_SEARCH_BTN, wxCommandEvent); +wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_SEARCH_CANCEL, wxCommandEvent); +wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_SEARCH, wxCommandEvent); // ---------------------------------------------------------------------------- // a search ctrl is a text control with a search button and a cancel button @@ -90,13 +90,20 @@ private: // macros for handling search events // ---------------------------------------------------------------------------- -#define EVT_SEARCHCTRL_CANCEL_BTN(id, fn) \ - wx__DECLARE_EVT1(wxEVT_SEARCHCTRL_CANCEL_BTN, id, wxCommandEventHandler(fn)) +#define EVT_SEARCH_CANCEL(id, fn) \ + wx__DECLARE_EVT1(wxEVT_SEARCH_CANCEL, id, wxCommandEventHandler(fn)) -#define EVT_SEARCHCTRL_SEARCH_BTN(id, fn) \ - wx__DECLARE_EVT1(wxEVT_SEARCHCTRL_SEARCH_BTN, id, wxCommandEventHandler(fn)) +#define EVT_SEARCH(id, fn) \ + wx__DECLARE_EVT1(wxEVT_SEARCH, id, wxCommandEventHandler(fn)) -// old wxEVT_COMMAND_* constants +// old synonyms +#define wxEVT_SEARCHCTRL_CANCEL_BTN wxEVT_SEARCH_CANCEL +#define wxEVT_SEARCHCTRL_SEARCH_BTN wxEVT_SEARCH + +#define EVT_SEARCHCTRL_CANCEL_BTN(id, fn) EVT_SEARCH_CANCEL(id, fn) +#define EVT_SEARCHCTRL_SEARCH_BTN(id, fn) EVT_SEARCH(id, fn) + +// even older wxEVT_COMMAND_* constants #define wxEVT_COMMAND_SEARCHCTRL_CANCEL_BTN wxEVT_SEARCHCTRL_CANCEL_BTN #define wxEVT_COMMAND_SEARCHCTRL_SEARCH_BTN wxEVT_SEARCHCTRL_SEARCH_BTN diff --git a/interface/wx/srchctrl.h b/interface/wx/srchctrl.h index d888d581fa..975a137703 100644 --- a/interface/wx/srchctrl.h +++ b/interface/wx/srchctrl.h @@ -35,19 +35,19 @@ @endStyleTable @beginEventEmissionTable{wxCommandEvent} - To react to the changes in the control contents, use EVT_TEXT event, just + To react to the changes in the control contents, use wxEVT_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 + wxEVT_SEARCH to actually start searching to avoid doing it too soon, while + the user is still typing (note that wxEVT_SEARCH is also triggered by + pressing Enter in the control). + @event{EVT_SEARCH(id, func)} + Respond to a @c wxEVT_SEARCH event, generated when the search button is clicked. Note that this does not initiate a search on its own, you need to perform the appropriate action in your event handler. You may use @code event.GetString() @endcode to retrieve the string to search for in the event handler code. - @event{EVT_SEARCHCTRL_CANCEL_BTN(id, func)} - Respond to a @c wxEVT_SEARCHCTRL_CANCEL_BTN event, generated when the + @event{EVT_SEARCH_CANCEL(id, func)} + Respond to a @c wxEVT_SEARCH_CANCEL event, generated when the cancel button is clicked. @endEventTable @@ -161,5 +161,5 @@ public: }; -wxEventType wxEVT_SEARCHCTRL_CANCEL_BTN; -wxEventType wxEVT_SEARCHCTRL_SEARCH_BTN; +wxEventType wxEVT_SEARCH_CANCEL; +wxEventType wxEVT_SEARCH; diff --git a/samples/widgets/searchctrl.cpp b/samples/widgets/searchctrl.cpp index a647835ed8..7252ab078d 100644 --- a/samples/widgets/searchctrl.cpp +++ b/samples/widgets/searchctrl.cpp @@ -120,8 +120,8 @@ wxBEGIN_EVENT_TABLE(SearchCtrlWidgetsPage, WidgetsPage) EVT_TEXT(wxID_ANY, SearchCtrlWidgetsPage::OnText) EVT_TEXT_ENTER(wxID_ANY, SearchCtrlWidgetsPage::OnTextEnter) - EVT_SEARCHCTRL_SEARCH_BTN(wxID_ANY, SearchCtrlWidgetsPage::OnSearch) - EVT_SEARCHCTRL_CANCEL_BTN(wxID_ANY, SearchCtrlWidgetsPage::OnSearchCancel) + EVT_SEARCH(wxID_ANY, SearchCtrlWidgetsPage::OnSearch) + EVT_SEARCH_CANCEL(wxID_ANY, SearchCtrlWidgetsPage::OnSearchCancel) wxEND_EVENT_TABLE() // ============================================================================ diff --git a/src/common/srchcmn.cpp b/src/common/srchcmn.cpp index 1e524b5394..788b466937 100644 --- a/src/common/srchcmn.cpp +++ b/src/common/srchcmn.cpp @@ -34,8 +34,8 @@ const char wxSearchCtrlNameStr[] = "searchCtrl"; -wxDEFINE_EVENT(wxEVT_SEARCHCTRL_CANCEL_BTN, wxCommandEvent); -wxDEFINE_EVENT(wxEVT_SEARCHCTRL_SEARCH_BTN, wxCommandEvent); +wxDEFINE_EVENT(wxEVT_SEARCH_CANCEL, wxCommandEvent); +wxDEFINE_EVENT(wxEVT_SEARCH, wxCommandEvent); #endif // wxUSE_SEARCHCTRL diff --git a/src/generic/srchctlg.cpp b/src/generic/srchctlg.cpp index 6775f9bcae..074bee8722 100644 --- a/src/generic/srchctlg.cpp +++ b/src/generic/srchctlg.cpp @@ -96,7 +96,7 @@ protected: { if ( !IsEmpty() ) { - wxCommandEvent event(wxEVT_SEARCHCTRL_SEARCH_BTN, m_search->GetId()); + wxCommandEvent event(wxEVT_SEARCH, m_search->GetId()); event.SetEventObject(m_search); event.SetString(m_search->GetValue()); @@ -196,7 +196,7 @@ protected: wxCommandEvent event(m_eventType, m_search->GetId()); event.SetEventObject(m_search); - if ( m_eventType == wxEVT_SEARCHCTRL_SEARCH_BTN ) + if ( m_eventType == wxEVT_SEARCH ) { // it's convenient to have the string to search for directly in the // event instead of having to retrieve it from the control in the @@ -209,7 +209,7 @@ protected: m_search->SetFocus(); #if wxUSE_MENUS - if ( m_eventType == wxEVT_SEARCHCTRL_SEARCH_BTN ) + if ( m_eventType == wxEVT_SEARCH ) { // this happens automatically, just like on Mac OS X m_search->PopupSearchMenu(); @@ -238,7 +238,7 @@ wxBEGIN_EVENT_TABLE(wxSearchButton, wxControl) wxEND_EVENT_TABLE() wxBEGIN_EVENT_TABLE(wxSearchCtrl, wxSearchCtrlBase) - EVT_SEARCHCTRL_CANCEL_BTN(wxID_ANY, wxSearchCtrl::OnCancelButton) + EVT_SEARCH_CANCEL(wxID_ANY, wxSearchCtrl::OnCancelButton) EVT_SIZE(wxSearchCtrl::OnSize) wxEND_EVENT_TABLE() @@ -322,10 +322,10 @@ bool wxSearchCtrl::Create(wxWindow *parent, wxWindowID id, m_text = new wxSearchTextCtrl(this, value, style); m_searchButton = new wxSearchButton(this, - wxEVT_SEARCHCTRL_SEARCH_BTN, + wxEVT_SEARCH, m_searchBitmap); m_cancelButton = new wxSearchButton(this, - wxEVT_SEARCHCTRL_CANCEL_BTN, + wxEVT_SEARCH_CANCEL, m_cancelBitmap); SetBackgroundColour( m_text->GetBackgroundColour() ); diff --git a/src/osx/srchctrl_osx.cpp b/src/osx/srchctrl_osx.cpp index 928bb9340e..fa3101f42e 100644 --- a/src/osx/srchctrl_osx.cpp +++ b/src/osx/srchctrl_osx.cpp @@ -209,7 +209,7 @@ bool wxSearchCtrl::Create(wxWindow *parent, wxWindowID id, bool wxSearchCtrl::HandleSearchFieldSearchHit() { - wxCommandEvent event(wxEVT_SEARCHCTRL_SEARCH_BTN, m_windowId ); + wxCommandEvent event(wxEVT_SEARCH, m_windowId ); event.SetEventObject(this); // provide the string to search for directly in the event, this is more @@ -221,7 +221,7 @@ bool wxSearchCtrl::HandleSearchFieldSearchHit() bool wxSearchCtrl::HandleSearchFieldCancelHit() { - wxCommandEvent event(wxEVT_SEARCHCTRL_CANCEL_BTN, m_windowId ); + wxCommandEvent event(wxEVT_SEARCH_CANCEL, m_windowId ); event.SetEventObject(this); return ProcessCommand(event); }