From e8374a47fe277b01c93b07ab00d39b2cd294ea0a Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 25 Dec 2014 01:32:00 +0000 Subject: [PATCH] Allow setting hints for multi-line wxTextCtrl when supported. Don't prevent people from using hints in wxMSW and wxGTK2, where they work with multiline text controls too, even though they do not work with wxGTK3 nor wxOSX. Closes #14456. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@78316 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/gtk/textctrl.h | 1 + include/wx/textctrl.h | 3 --- interface/wx/textentry.h | 6 +++--- samples/text/text.cpp | 1 + src/common/textcmn.cpp | 8 -------- src/gtk/textctrl.cpp | 7 ++++++- src/gtk/textentry.cpp | 2 +- 7 files changed, 12 insertions(+), 16 deletions(-) diff --git a/include/wx/gtk/textctrl.h b/include/wx/gtk/textctrl.h index d1eaaec20a..e54668b108 100644 --- a/include/wx/gtk/textctrl.h +++ b/include/wx/gtk/textctrl.h @@ -159,6 +159,7 @@ protected: virtual bool UseGTKStyleBase() const wxOVERRIDE { return true; } virtual void DoSetValue(const wxString &value, int flags = 0) wxOVERRIDE; + virtual wxString DoGetValue() const wxOVERRIDE; // Override this to use either GtkEntry or GtkTextView IME depending on the // kind of control we are. diff --git a/include/wx/textctrl.h b/include/wx/textctrl.h index bbf4ff6b3d..c69954f99d 100644 --- a/include/wx/textctrl.h +++ b/include/wx/textctrl.h @@ -731,9 +731,6 @@ public: wxTextEntry::SetValue(value); } - // wxTextEntry overrides - virtual bool SetHint(const wxString& hint) wxOVERRIDE; - // wxWindow overrides virtual wxVisualAttributes GetDefaultAttributes() const wxOVERRIDE { diff --git a/interface/wx/textentry.h b/interface/wx/textentry.h index 85b0f7a275..a8c518f18f 100644 --- a/interface/wx/textentry.h +++ b/interface/wx/textentry.h @@ -473,9 +473,9 @@ public: focus and wxEVT_TEXT events, you must call wxEvent::Skip() on them so that the generic implementation works correctly. - @remarks Hints can only be used for single line text controls, - native multi-line text controls don't support hints under any - platform and hence wxWidgets doesn't provide them neither. + @remarks Hints can be used for single line text controls under all + platforms, but only MSW and GTK+ 2 support them for multi-line text + controls, they are ignored for them under the other platforms. @since 2.9.0 */ diff --git a/samples/text/text.cpp b/samples/text/text.cpp index a32b2aa7aa..70c3cfe63b 100644 --- a/samples/text/text.cpp +++ b/samples/text/text.cpp @@ -1091,6 +1091,7 @@ MyPanel::MyPanel( wxFrame *frame, int x, int y, int w, int h ) m_horizontal = new MyTextCtrl( this, wxID_ANY, wxT("Multiline text control with a horizontal scrollbar.\n"), wxPoint(10,170), wxSize(140,70), wxTE_MULTILINE | wxHSCROLL); + m_horizontal->SetHint("Enter multiline text here"); // a little hack to use the command line argument for encoding testing if ( wxTheApp->argc == 2 ) diff --git a/src/common/textcmn.cpp b/src/common/textcmn.cpp index c1f1c45256..2ee51c6fe6 100644 --- a/src/common/textcmn.cpp +++ b/src/common/textcmn.cpp @@ -1178,14 +1178,6 @@ bool wxTextCtrlBase::EmulateKeyPress(const wxKeyEvent& event) // Other miscellaneous stuff // ---------------------------------------------------------------------------- -bool wxTextCtrlBase::SetHint(const wxString& hint) -{ - wxCHECK_MSG( IsSingleLine(), false, - wxS("Hints can only be set for single line text controls") ); - - return wxTextEntry::SetHint(hint); -} - // do the window-specific processing after processing the update event void wxTextCtrlBase::DoUpdateWindowUI(wxUpdateUIEvent& event) { diff --git a/src/gtk/textctrl.cpp b/src/gtk/textctrl.cpp index 227f7c362b..b0b3bf9774 100644 --- a/src/gtk/textctrl.cpp +++ b/src/gtk/textctrl.cpp @@ -986,6 +986,11 @@ wxString wxTextCtrl::GetValue() const { wxCHECK_MSG( m_text != NULL, wxEmptyString, wxT("invalid text ctrl") ); + return wxTextEntry::GetValue(); +} + +wxString wxTextCtrl::DoGetValue() const +{ if ( IsMultiLine() ) { GtkTextIter start; @@ -998,7 +1003,7 @@ wxString wxTextCtrl::GetValue() const } else // single line { - return wxTextEntry::GetValue(); + return wxTextEntry::DoGetValue(); } } diff --git a/src/gtk/textentry.cpp b/src/gtk/textentry.cpp index 804c381f45..c066fb3c84 100644 --- a/src/gtk/textentry.cpp +++ b/src/gtk/textentry.cpp @@ -521,7 +521,7 @@ bool wxTextEntry::SetHint(const wxString& hint) { #if GTK_CHECK_VERSION(3,2,0) GtkEntry *entry = GetEntry(); - if (entry && gtk_check_version(3,2,0) == NULL) + if (entry && GTK_IS_ENTRY(entry) && gtk_check_version(3,2,0) == NULL) { gtk_entry_set_placeholder_text(entry, wxGTK_CONV(hint)); return true;