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
This commit is contained in:
@@ -550,6 +550,7 @@ wxMSW:
|
|||||||
- Add support for CURRENCY and SCODE types to OLE Automation helpers (PB).
|
- Add support for CURRENCY and SCODE types to OLE Automation helpers (PB).
|
||||||
- Allow setting LCID used by wxAutomationObject (PB).
|
- Allow setting LCID used by wxAutomationObject (PB).
|
||||||
- Fix calling Iconize(false) on hidden top level windows (Christian Walther).
|
- 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)
|
2.9.4: (released 2012-07-09)
|
||||||
|
@@ -131,6 +131,11 @@ public:
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
Sets range of allowable values.
|
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);
|
void SetRange(int minVal, int maxVal);
|
||||||
|
|
||||||
|
@@ -494,6 +494,14 @@ void wxSpinCtrl::SetSelection(long from, long to)
|
|||||||
|
|
||||||
void wxSpinCtrl::SetRange(int minVal, int maxVal)
|
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);
|
wxSpinButton::SetRange(minVal, maxVal);
|
||||||
|
|
||||||
// this control is used for numeric entry so restrict the input to numeric
|
// this control is used for numeric entry so restrict the input to numeric
|
||||||
|
@@ -165,7 +165,18 @@ void SpinCtrlTestCase::Range()
|
|||||||
CPPUNIT_ASSERT_EQUAL(0, m_spin->GetMin());
|
CPPUNIT_ASSERT_EQUAL(0, m_spin->GetMin());
|
||||||
CPPUNIT_ASSERT_EQUAL(100, m_spin->GetMax());
|
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);
|
m_spin->SetRange(-10, 10);
|
||||||
|
|
||||||
CPPUNIT_ASSERT_EQUAL(-10, m_spin->GetMin());
|
CPPUNIT_ASSERT_EQUAL(-10, m_spin->GetMin());
|
||||||
|
Reference in New Issue
Block a user