diff --git a/include/wx/gtk/spinctrl.h b/include/wx/gtk/spinctrl.h index 611f859382..267bd94de5 100644 --- a/include/wx/gtk/spinctrl.h +++ b/include/wx/gtk/spinctrl.h @@ -102,10 +102,17 @@ protected: // override this and return true. virtual bool UseGTKStyleBase() const wxOVERRIDE { return true; } - // Set or reset m_textOverride. + // Set m_textOverride to use the given text instead of the numeric value. void GTKSetTextOverride(const wxString& text); + + // Reset the override and changing the value to correspond to the + // previously overridden numeric value. void GTKResetTextOverride(); + // Just reset the override, without touching the value, returning true if + // we did it. In most cases, the function above should be used instead. + bool GTKResetTextOverrideOnly(); + private: // This function does _not_ take into account m_textOverride, so it is // private and normally shouldn't be used -- use DoGetValue() instead. diff --git a/src/gtk/spinctrl.cpp b/src/gtk/spinctrl.cpp index 6e709e7e17..b9f72eda28 100644 --- a/src/gtk/spinctrl.cpp +++ b/src/gtk/spinctrl.cpp @@ -176,14 +176,22 @@ void wxSpinCtrlGTKBase::GTKSetTextOverride(const wxString& text) m_textOverride->m_text = text; } -void wxSpinCtrlGTKBase::GTKResetTextOverride() +bool wxSpinCtrlGTKBase::GTKResetTextOverrideOnly() { if ( !m_textOverride ) - return; + return false; delete m_textOverride; m_textOverride = NULL; + return true; +} + +void wxSpinCtrlGTKBase::GTKResetTextOverride() +{ + if ( !GTKResetTextOverrideOnly() ) + return; + // Update the text part to reflect the numeric value now that we don't // override it any longer, otherwise we'd keep showing the old one because // the text is updated by GTK before "value" is generated. @@ -524,7 +532,10 @@ bool wxSpinCtrlGTKBase::GTKOutput(wxString* text) const void wxSpinCtrlGTKBase::GTKTextChanged() { - GTKResetTextOverride(); + // We can't use GTKResetTextOverride() itself here because it would also + // reset the value and we do not want this to happen -- the value is being + // changed to correspond to the new text. + GTKResetTextOverrideOnly(); wxCommandEvent event( wxEVT_TEXT, GetId() ); event.SetEventObject( this );