Update the text hint display correctly when ChangeValue() is called.

wxTextEntry::ChangeValue() doesn't generate any events so we need to
explicitly update the text stored by wxTextEntryHintData when it is called to
ensure that it corresponds to the real controls value.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@65552 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2010-09-15 22:10:20 +00:00
parent a7aeddacf9
commit 7bfc104bba
2 changed files with 26 additions and 7 deletions

View File

@@ -38,8 +38,7 @@ public:
// SetValue() generates a text change event, ChangeValue() doesn't // SetValue() generates a text change event, ChangeValue() doesn't
virtual void SetValue(const wxString& value) virtual void SetValue(const wxString& value)
{ DoSetValue(value, SetValue_SendEvent); } { DoSetValue(value, SetValue_SendEvent); }
virtual void ChangeValue(const wxString& value) virtual void ChangeValue(const wxString& value);
{ DoSetValue(value, SetValue_NoEvent); }
// writing text inserts it at the current position replacing any current // writing text inserts it at the current position replacing any current
// selection, appending always inserts it at the end and doesn't remove any // selection, appending always inserts it at the end and doesn't remove any

View File

@@ -75,6 +75,20 @@ public:
const wxString& GetHintString() const { return m_hint; } const wxString& GetHintString() const { return m_hint; }
// This is called whenever the text control contents changes.
//
// We call it ourselves when this change generates an event but it's also
// necessary to call it explicitly from wxTextEntry::ChangeValue() as it,
// by design, does not generate any events.
void HandleTextUpdate(const wxString& text)
{
m_text = text;
// If we're called because of a call to Set or ChangeValue(), the
// control may still have the hint text colour, reset it in this case.
RestoreTextColourIfNecessary();
}
private: private:
// Show the hint in the window if we should do it, i.e. if the window // Show the hint in the window if we should do it, i.e. if the window
// doesn't have any text of its own. // doesn't have any text of its own.
@@ -133,11 +147,7 @@ private:
// which uses it internally because this would just forward back to us // which uses it internally because this would just forward back to us
// so go directly to the private method which returns the real control // so go directly to the private method which returns the real control
// contents. // contents.
m_text = m_entry->DoGetValue(); HandleTextUpdate(m_entry->DoGetValue());
// If this event is generated because of calling SetValue(), the
// control may still have the hint text colour, reset it in this case.
RestoreTextColourIfNecessary();
event.Skip(); event.Skip();
} }
@@ -195,6 +205,16 @@ wxString wxTextEntryBase::GetRange(long from, long to) const
// text operations // text operations
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
void wxTextEntryBase::ChangeValue(const wxString& value)
{
DoSetValue(value, SetValue_NoEvent);
// As we didn't generate any events for wxTextEntryHintData to catch,
// notify it explicitly about our changed contents.
if ( m_hintData )
m_hintData->HandleTextUpdate(value);
}
void wxTextEntryBase::AppendText(const wxString& text) void wxTextEntryBase::AppendText(const wxString& text)
{ {
SetInsertionPointEnd(); SetInsertionPointEnd();