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
This commit is contained in:
Vadim Zeitlin
2014-12-25 01:32:00 +00:00
parent 73a38319d8
commit e8374a47fe
7 changed files with 12 additions and 16 deletions

View File

@@ -159,6 +159,7 @@ protected:
virtual bool UseGTKStyleBase() const wxOVERRIDE { return true; } virtual bool UseGTKStyleBase() const wxOVERRIDE { return true; }
virtual void DoSetValue(const wxString &value, int flags = 0) wxOVERRIDE; 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 // Override this to use either GtkEntry or GtkTextView IME depending on the
// kind of control we are. // kind of control we are.

View File

@@ -731,9 +731,6 @@ public:
wxTextEntry::SetValue(value); wxTextEntry::SetValue(value);
} }
// wxTextEntry overrides
virtual bool SetHint(const wxString& hint) wxOVERRIDE;
// wxWindow overrides // wxWindow overrides
virtual wxVisualAttributes GetDefaultAttributes() const wxOVERRIDE virtual wxVisualAttributes GetDefaultAttributes() const wxOVERRIDE
{ {

View File

@@ -473,9 +473,9 @@ public:
focus and wxEVT_TEXT events, you must call wxEvent::Skip() on them focus and wxEVT_TEXT events, you must call wxEvent::Skip() on them
so that the generic implementation works correctly. so that the generic implementation works correctly.
@remarks Hints can only be used for single line text controls, @remarks Hints can be used for single line text controls under all
native multi-line text controls don't support hints under any platforms, but only MSW and GTK+ 2 support them for multi-line text
platform and hence wxWidgets doesn't provide them neither. controls, they are ignored for them under the other platforms.
@since 2.9.0 @since 2.9.0
*/ */

View File

@@ -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"), 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); 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 // a little hack to use the command line argument for encoding testing
if ( wxTheApp->argc == 2 ) if ( wxTheApp->argc == 2 )

View File

@@ -1178,14 +1178,6 @@ bool wxTextCtrlBase::EmulateKeyPress(const wxKeyEvent& event)
// Other miscellaneous stuff // 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 // do the window-specific processing after processing the update event
void wxTextCtrlBase::DoUpdateWindowUI(wxUpdateUIEvent& event) void wxTextCtrlBase::DoUpdateWindowUI(wxUpdateUIEvent& event)
{ {

View File

@@ -986,6 +986,11 @@ wxString wxTextCtrl::GetValue() const
{ {
wxCHECK_MSG( m_text != NULL, wxEmptyString, wxT("invalid text ctrl") ); wxCHECK_MSG( m_text != NULL, wxEmptyString, wxT("invalid text ctrl") );
return wxTextEntry::GetValue();
}
wxString wxTextCtrl::DoGetValue() const
{
if ( IsMultiLine() ) if ( IsMultiLine() )
{ {
GtkTextIter start; GtkTextIter start;
@@ -998,7 +1003,7 @@ wxString wxTextCtrl::GetValue() const
} }
else // single line else // single line
{ {
return wxTextEntry::GetValue(); return wxTextEntry::DoGetValue();
} }
} }

View File

@@ -521,7 +521,7 @@ bool wxTextEntry::SetHint(const wxString& hint)
{ {
#if GTK_CHECK_VERSION(3,2,0) #if GTK_CHECK_VERSION(3,2,0)
GtkEntry *entry = GetEntry(); 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)); gtk_entry_set_placeholder_text(entry, wxGTK_CONV(hint));
return true; return true;