From 532324df237338fafaddfc83d987b372f361c4b5 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Wed, 15 Aug 2012 23:34:10 +0000 Subject: [PATCH] Don't generate events from wxSpinCtrl::SetRange() in wxMSW. Other ports don't send wxEVT_COMMAND_SPINCTRL_UPDATED from SetRange() even if the value changed because it was adjusted to fit into the new range and this makes sense as this change is not due to a user action, so don't send this event under wxMSW neither. Also add a unit test checking for this behaviour. Closes #14583. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@72341 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/changes.txt | 1 + interface/wx/spinctrl.h | 5 +++++ src/msw/spinctrl.cpp | 8 ++++++++ tests/controls/spinctrltest.cpp | 13 ++++++++++++- 4 files changed, 26 insertions(+), 1 deletion(-) 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()); -- 2.45.2