From: Vadim Zeitlin Date: Sun, 20 Jan 2013 02:09:14 +0000 (+0000) Subject: Fix setting initial wxSpinCtrl value outside 0..100 range in wxMSW. X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/fe218f1e4ba6548606a15e231f2982c9f25d77b7 Fix setting initial wxSpinCtrl value outside 0..100 range in wxMSW. Set the range before setting the initial value when creating wxSpinCtrl, as otherwise the value was wrongly limited to the default 0..100 range instead of the one really specified. Closes #14894. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@73394 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/docs/changes.txt b/docs/changes.txt index 47d27b629b..8406f7ecf4 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -623,6 +623,7 @@ wxMSW: - Fix calling Iconize(false) on hidden top level windows (Christian Walther). - Don't send any events from wxSpinCtrl::SetRange() even if the value changed. - Display system drag images during drag and drop if available (PeterO). +- Fix setting initial wxSpinCtrl value outside 0..100 range (joim). wxOSX/Cocoa: diff --git a/src/msw/spinctrl.cpp b/src/msw/spinctrl.cpp index 4625a25b49..a034cda2ee 100644 --- a/src/msw/spinctrl.cpp +++ b/src/msw/spinctrl.cpp @@ -399,12 +399,11 @@ bool wxSpinCtrl::Create(wxWindow *parent, if ( value.ToLong(&initialFromText) ) initial = initialFromText; - SetValue(initial); - - m_oldValue = initial; - - // Set the range in the native control + // Set the range in the native control: notice that we must do it before + // calling SetValue() to use the correct validity checks for the initial + // value. SetRange(min, max); + SetValue(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. diff --git a/tests/controls/spinctrltest.cpp b/tests/controls/spinctrltest.cpp index a1e29cf3bd..2338bb4248 100644 --- a/tests/controls/spinctrltest.cpp +++ b/tests/controls/spinctrltest.cpp @@ -83,6 +83,14 @@ void SpinCtrlTestCase::Initial() 0, 100, 17); CPPUNIT_ASSERT_EQUAL( 17, m_spin->GetValue() ); + // Recreate the control with another "initial" outside of standard spin + // ctrl range. + delete m_spin; + m_spin = new wxSpinCtrl(parent, wxID_ANY, "", + wxDefaultPosition, wxDefaultSize, 0, + 0, 200, 150); + CPPUNIT_ASSERT_EQUAL( 150, m_spin->GetValue() ); + // But if the text string is specified, it takes precedence. delete m_spin; m_spin = new wxSpinCtrl(parent, wxID_ANY, "99",