From fb88a3f3eb1c0d2729a34f0aad36fc800e2b2f95 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 23 Apr 2021 23:43:49 +0200 Subject: [PATCH] Don't use last valid value in wxGTK wxSpinCtrl with text override This partially undoes the recent changes to wxGTK wxSpinCtrl and reverts to the previous behaviour, which was actually compatible with wxMSW, and returns the minimum value when the text of the control is set to an invalid string. --- src/gtk/spinctrl.cpp | 27 +++++---------------------- 1 file changed, 5 insertions(+), 22 deletions(-) diff --git a/src/gtk/spinctrl.cpp b/src/gtk/spinctrl.cpp index b9f72eda28..637fb60592 100644 --- a/src/gtk/spinctrl.cpp +++ b/src/gtk/spinctrl.cpp @@ -130,13 +130,9 @@ private: class wxSpinCtrlGTKTextOverride { public: - wxSpinCtrlGTKTextOverride() - : m_value(0.0) - { - } - + // Text value used instead of the text representation of the actual numeric + // value. Notice that this string may be empty. wxString m_text; - double m_value; }; //----------------------------------------------------------------------------- @@ -160,19 +156,8 @@ wxSpinCtrlGTKBase::~wxSpinCtrlGTKBase() void wxSpinCtrlGTKBase::GTKSetTextOverride(const wxString& text) { if ( !m_textOverride ) - { - // Remember the original numeric value, that we're going to keep using - // it while this override is valid, and do it before initializing - // m_textOverride as our own "input" handler called from GTKGetValue() - // would use it if it were non-null. - const double value = GTKGetValue(); - m_textOverride = new wxSpinCtrlGTKTextOverride(); - m_textOverride->m_value = value; - } - //else: No need to change the value, it stays the same anyhow. - // Update the text in any case. m_textOverride->m_text = text; } @@ -258,10 +243,8 @@ bool wxSpinCtrlGTKBase::Create(wxWindow *parent, wxWindowID id, double wxSpinCtrlGTKBase::DoGetValue() const { // While using a text override, the text value is fixed by the program and - // shouldn't be used, just return the numeric value we had had before, as - // the text override is reset whenever it changes, so it must not have - // changed yet. - return m_textOverride ? m_textOverride->m_value : GTKGetValue(); + // shouldn't be used, just return the minimum value (which is 0 by default). + return m_textOverride ? DoGetMin() : GTKGetValue(); } double wxSpinCtrlGTKBase::GTKGetValue() const @@ -512,7 +495,7 @@ wxSpinCtrlGTKBase::GTKInputResult wxSpinCtrlGTKBase::GTKInput(double* value) con { if ( m_textOverride ) { - *value = m_textOverride->m_value; + *value = DoGetMin(); return GTKInput_Converted; }