diff --git a/docs/changes.txt b/docs/changes.txt index 5d2d9d12cd..b5242e5681 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -114,6 +114,9 @@ Changes in behaviour not resulting in compilation errors - wxChoice::GetString() now consistently asserts when passed an invalid index. +- wxSpinCtrlDouble now always resets its value to GetMin() if an invalid text + string is passed to its SetValue() after its creation. + Changes in behaviour which may result in build errors ----------------------------------------------------- diff --git a/interface/wx/spinctrl.h b/interface/wx/spinctrl.h index 55353ef86d..6371aeec7c 100644 --- a/interface/wx/spinctrl.h +++ b/interface/wx/spinctrl.h @@ -197,10 +197,10 @@ public: Sets the value of the spin control. It is recommended to use the overload taking an integer value instead. - The behaviour of this function when @a text doesn't represent a valid - number currently differs between the platforms, however passing an - empty string does clear the text part contents, without affecting the - value returned by GetValue(), under all of them. + If @a text doesn't represent a valid number, it may not be shown in the + text part of the control at all (only empty string is guaranteed to be + supported under all platforms) and the numeric value will be changed to + GetMin(). Notice that, unlike wxTextCtrl::SetValue(), but like most of the other setter methods in wxWidgets, calling this method does not generate any diff --git a/src/generic/spinctlg.cpp b/src/generic/spinctlg.cpp index aa99410c35..7255045e24 100644 --- a/src/generic/spinctlg.cpp +++ b/src/generic/spinctlg.cpp @@ -522,6 +522,8 @@ void wxSpinCtrlGenericBase::SetValue(const wxString& text) } else // not a number at all or out of range { + m_value = m_min; + m_textCtrl->ChangeValue(text); m_textCtrl->SelectAll(); } diff --git a/tests/controls/spinctrldbltest.cpp b/tests/controls/spinctrldbltest.cpp index a4fe967942..a028dbe977 100644 --- a/tests/controls/spinctrldbltest.cpp +++ b/tests/controls/spinctrldbltest.cpp @@ -179,7 +179,7 @@ TEST_CASE_METHOD(SpinCtrlDoubleTestCase, m_spin->SetValue(""); CHECK( m_spin->GetTextValue() == "" ); - CHECK( m_spin->GetValue() == 57.3 ); + CHECK( m_spin->GetValue() == 0 ); } #if wxUSE_UIACTIONSIMULATOR diff --git a/tests/controls/spinctrltest.cpp b/tests/controls/spinctrltest.cpp index ec46aada54..a6624066e2 100644 --- a/tests/controls/spinctrltest.cpp +++ b/tests/controls/spinctrltest.cpp @@ -278,6 +278,7 @@ TEST_CASE_METHOD(SpinCtrlTestCase2, "SpinCtrl::Value", "[spinctrl]") m_spin->SetValue(""); CHECK( m_spin->GetTextValue() == "" ); + CHECK( m_spin->GetValue() == 0 ); } TEST_CASE_METHOD(SpinCtrlTestCase2, "SpinCtrl::Base", "[spinctrl]")