Reset wxSpinCtrl value to GetMin() if text string is invalid
Previously, wxSpinCtrl (using native control) and wxSpinCtrlDouble (using the generic implementation) behaved differently in this case, with the former changing its value but the latter keeping the last valid value instead. Make them behave the same by resetting the value in both cases and document this behaviour.
This commit is contained in:
@@ -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
|
||||
-----------------------------------------------------
|
||||
|
@@ -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
|
||||
|
@@ -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();
|
||||
}
|
||||
|
@@ -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
|
||||
|
@@ -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]")
|
||||
|
Reference in New Issue
Block a user