diff --git a/docs/changes.txt b/docs/changes.txt index c653e9444c..9c7e7df2fe 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -550,6 +550,7 @@ wxMSW: - Add support for CURRENCY and SCODE types to OLE Automation helpers (PB). - Allow setting LCID used by wxAutomationObject (PB). - Fix calling Iconize(false) on hidden top level windows (Christian Walther). +- Don't send any events from wxSpinCtrl::SetRange() even if the value changed. 2.9.4: (released 2012-07-09) diff --git a/interface/wx/spinctrl.h b/interface/wx/spinctrl.h index 958f0869eb..3e2c6926c4 100644 --- a/interface/wx/spinctrl.h +++ b/interface/wx/spinctrl.h @@ -131,6 +131,11 @@ public: /** Sets range of allowable values. + + Notice that calling this method may change the value of the control if + it's not inside the new valid range, e.g. it will become @a minVal if + it is less than it now. However no @c wxEVT_COMMAND_SPINCTRL_UPDATED + event is generated, even if it the value does change. */ void SetRange(int minVal, int maxVal); diff --git a/src/msw/spinctrl.cpp b/src/msw/spinctrl.cpp index 921d767fb0..94baaf3809 100644 --- a/src/msw/spinctrl.cpp +++ b/src/msw/spinctrl.cpp @@ -494,6 +494,14 @@ void wxSpinCtrl::SetSelection(long from, long to) void wxSpinCtrl::SetRange(int minVal, int maxVal) { + // Manually adjust the old value to avoid an event being sent from + // NormalizeValue() called from inside the base class SetRange() as we're + // not supposed to generate any events from here. + if ( m_oldValue < minVal ) + m_oldValue = minVal; + else if ( m_oldValue > maxVal ) + m_oldValue = maxVal; + wxSpinButton::SetRange(minVal, maxVal); // this control is used for numeric entry so restrict the input to numeric diff --git a/tests/controls/spinctrltest.cpp b/tests/controls/spinctrltest.cpp index 12b68102d2..a1e29cf3bd 100644 --- a/tests/controls/spinctrltest.cpp +++ b/tests/controls/spinctrltest.cpp @@ -165,7 +165,18 @@ void SpinCtrlTestCase::Range() CPPUNIT_ASSERT_EQUAL(0, m_spin->GetMin()); CPPUNIT_ASSERT_EQUAL(100, m_spin->GetMax()); - //Test neagtive ranges + // Test that the value is adjusted to be inside the new valid range but + // that this doesn't result in any events (as this is not something done by + // the user). + { + EventCounter updated(m_spin, wxEVT_COMMAND_SPINCTRL_UPDATED); + + m_spin->SetRange(1, 10); + CPPUNIT_ASSERT_EQUAL(1, m_spin->GetValue()); + CPPUNIT_ASSERT_EQUAL(0, updated.GetCount()); + } + + //Test negative ranges m_spin->SetRange(-10, 10); CPPUNIT_ASSERT_EQUAL(-10, m_spin->GetMin());