Correct the initial value setting in wxMSW wxSpinCtrl.

Always use value argument for the text control contents and also override the
initial numeric value with it if it's numeric.

This seems to be the only consistent thing to do, so document this behaviour
and add a unit test checking for it.

Closes #13589.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@71387 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2012-05-09 14:24:20 +00:00
parent 8087e6c942
commit 6e36db5eca
3 changed files with 44 additions and 10 deletions

View File

@@ -389,22 +389,25 @@ bool wxSpinCtrl::Create(wxWindow *parent,
// associate the text window with the spin button
(void)::SendMessage(GetHwnd(), UDM_SETBUDDY, (WPARAM)m_hwndBuddy, 0);
// If the initial text value is actually a number, it overrides the
// "initial" argument specified later.
long initialFromText;
if ( value.ToLong(&initialFromText) )
initial = initialFromText;
SetValue(initial);
m_oldValue = initial;
// Set the range in the native control
SetRange(min, max);
// If necessary, set the textual value. Don't do it if it's the same as the
// numeric value though.
if ( value != wxString::Format("%d", initial) )
{
// Also set the text part of the control if it was specified independently
// but don't generate an event for this, it would be unexpected.
m_blockEvent = true;
if ( !value.empty() )
SetValue(value);
m_oldValue = (int) wxAtol(value);
}
else
{
m_oldValue = initial;
}
m_blockEvent = false;
return true;
}