From 8ee3394e5e1d29d4beff8da430b8580b3ca548c6 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 27 Jan 2018 13:38:47 +0100 Subject: [PATCH 1/4] Declare wxSearchCtrl::{Set,Get}DescriptiveText() in the base class Fix a trivial "TODO" remaining from 2.8 days and declare the functions that are part of the public control API as pure virtuals in the base class. No real changes. --- include/wx/generic/srchctlg.h | 5 ++--- include/wx/osx/srchctrl.h | 5 ++--- include/wx/srchctrl.h | 3 +++ 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/include/wx/generic/srchctlg.h b/include/wx/generic/srchctlg.h index a3d0ce86fe..ebcae90e78 100644 --- a/include/wx/generic/srchctlg.h +++ b/include/wx/generic/srchctlg.h @@ -61,9 +61,8 @@ public: virtual void ShowCancelButton( bool show ) wxOVERRIDE; virtual bool IsCancelButtonVisible() const wxOVERRIDE; - // TODO: In 2.9 these should probably be virtual, and declared in the base class... - void SetDescriptiveText(const wxString& text); - wxString GetDescriptiveText() const; + virtual void SetDescriptiveText(const wxString& text) wxOVERRIDE; + virtual wxString GetDescriptiveText() const wxOVERRIDE; // accessors // --------- diff --git a/include/wx/osx/srchctrl.h b/include/wx/osx/srchctrl.h index 4a4d88af47..2bef62b75e 100644 --- a/include/wx/osx/srchctrl.h +++ b/include/wx/osx/srchctrl.h @@ -54,9 +54,8 @@ public: virtual void ShowCancelButton( bool show ) wxOVERRIDE; virtual bool IsCancelButtonVisible() const wxOVERRIDE; - // TODO: In 2.9 these should probably be virtual, and declared in the base class... - void SetDescriptiveText(const wxString& text); - wxString GetDescriptiveText() const; + virtual void SetDescriptiveText(const wxString& text) wxOVERRIDE; + virtual wxString GetDescriptiveText() const wxOVERRIDE; virtual bool HandleSearchFieldSearchHit() ; virtual bool HandleSearchFieldCancelHit() ; diff --git a/include/wx/srchctrl.h b/include/wx/srchctrl.h index b28d3912d1..791fcb8092 100644 --- a/include/wx/srchctrl.h +++ b/include/wx/srchctrl.h @@ -68,6 +68,9 @@ public: virtual void ShowCancelButton( bool show ) = 0; virtual bool IsCancelButtonVisible() const = 0; + virtual void SetDescriptiveText(const wxString& text) = 0; + virtual wxString GetDescriptiveText() const = 0; + private: // implement wxTextEntry pure virtual method virtual wxWindow *GetEditableWindow() wxOVERRIDE { return this; } From 652b4eb8ed940f1a57e38d4b9d949b34e886d53d Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 27 Jan 2018 13:46:54 +0100 Subject: [PATCH 2/4] Add "hint" property to wxSearchCtrl XRC handler This is similar to wxTextCtrl property of the same name and maps naturally to wxSearchCtrl descriptive text attribute. --- docs/changes.txt | 1 + docs/doxygen/overviews/xrc_format.h | 3 +++ src/xrc/xh_srchctrl.cpp | 4 ++++ 3 files changed, 8 insertions(+) diff --git a/docs/changes.txt b/docs/changes.txt index 27f23deb7e..421f13d163 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -176,6 +176,7 @@ All (GUI): - Add wxFontPickerCtrl::SetMinPointSize() (Andreas Falkenhahn). - Add Set/GetFooter/Text/Icon() to wxRichMessageDialog (Tobias Taschner) - Add wxFloatingPointValidator::SetFactor(). +- Add "hint" property to wxSearchCtrl XRC handler. wxGTK: diff --git a/docs/doxygen/overviews/xrc_format.h b/docs/doxygen/overviews/xrc_format.h index 75a9f54815..92cea1ff7c 100644 --- a/docs/doxygen/overviews/xrc_format.h +++ b/docs/doxygen/overviews/xrc_format.h @@ -1950,6 +1950,9 @@ child and the second one for right/bottom child window. @hdr3col{property, type, description} @row3col{value, @ref overview_xrcformat_type_text, Initial value of the control (default: empty).} +@row3col{hint, @ref overview_xrcformat_type_text, + Descriptive text shown in the empty control (default: "Search"). This + property is new since wxWidgets 3.1.1.} @endTable diff --git a/src/xrc/xh_srchctrl.cpp b/src/xrc/xh_srchctrl.cpp index dbaafdedde..122d38cfbc 100644 --- a/src/xrc/xh_srchctrl.cpp +++ b/src/xrc/xh_srchctrl.cpp @@ -49,6 +49,10 @@ wxObject *wxSearchCtrlXmlHandler::DoCreateResource() SetupWindow(ctrl); + const wxString& hint = GetText(wxS("hint")); + if ( !hint.empty() ) + ctrl->SetDescriptiveText(hint); + return ctrl; } From 981697079739c4a920dc2d2cb261ca57dc2169f6 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 27 Jan 2018 14:01:58 +0100 Subject: [PATCH 3/4] Fix getting wxEVT_TEXT_ENTER from wxSearchCtrl wxSearchCtrl never generated this event, at least under MSW, even though the code to forward it from wxSearchTextCtrl was present in it, because it was never generated in the first place without wxTE_PROCESS_ENTER. Fix this by simply always using this style in wxSearchTextCtrl. --- src/generic/srchctlg.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/generic/srchctlg.cpp b/src/generic/srchctlg.cpp index 9264d8def9..5ad5654fe4 100644 --- a/src/generic/srchctlg.cpp +++ b/src/generic/srchctlg.cpp @@ -49,7 +49,7 @@ class wxSearchTextCtrl : public wxTextCtrl public: wxSearchTextCtrl(wxSearchCtrl *search, const wxString& value, int style) : wxTextCtrl(search, wxID_ANY, value, wxDefaultPosition, wxDefaultSize, - (style & ~wxBORDER_MASK) | wxNO_BORDER) + (style & ~wxBORDER_MASK) | wxNO_BORDER | wxTE_PROCESS_ENTER) { m_search = search; From 44a089b295c557c1ffbbae6fd3c36504140e92b0 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 27 Jan 2018 15:49:46 +0100 Subject: [PATCH 4/4] Fix handling TAB in wxSearchCtrl in wxMSW Check whether wxTextCtrl has focus using Win32 ::GetFocus() instead of by comparing FindFocus() with "this" pointer, as the latter fails when wxTextCtrl is part of a composite control, such as wxSearchCtrl. This is enough to make pressing TAB in wxSearchCtrl correctly go to the next control instead of just beeping. Note that we could also use DoFindFocus() here, but this would be needlessly less efficient as we don't really need to find wxWindow corresponding to the focused HWND, as that function does. But we can't use HasFocus() here as it wouldn't work correctly here when the focus is on another sub-window of a composite control also containing this wxTextCtrl. --- src/msw/textctrl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/msw/textctrl.cpp b/src/msw/textctrl.cpp index 2f7bc4d21a..686435b620 100644 --- a/src/msw/textctrl.cpp +++ b/src/msw/textctrl.cpp @@ -2078,7 +2078,7 @@ void wxTextCtrl::OnChar(wxKeyEvent& event) // forces at the moment unfortunately if ( !(m_windowStyle & wxTE_PROCESS_TAB)) { - if ( FindFocus() == this ) + if ( ::GetFocus() == GetHwnd() ) { int flags = 0; if (!event.ShiftDown())