diff --git a/src/msw/spinctrl.cpp b/src/msw/spinctrl.cpp index fbb9e2b387..058e08ed3d 100644 --- a/src/msw/spinctrl.cpp +++ b/src/msw/spinctrl.cpp @@ -244,6 +244,7 @@ void wxSpinCtrl::NormalizeValue() if ( changed ) { + m_oldValue = value; SendSpinUpdate(value); } } @@ -666,10 +667,7 @@ void wxSpinCtrl::SendSpinUpdate(int value) wxSpinEvent event(wxEVT_SPINCTRL, GetId()); event.SetEventObject(this); event.SetInt(value); - (void)HandleWindowEvent(event); - - m_oldValue = value; } bool wxSpinCtrl::MSWOnScroll(int WXUNUSED(orientation), WXWORD wParam, @@ -687,7 +685,10 @@ bool wxSpinCtrl::MSWOnScroll(int WXUNUSED(orientation), WXWORD wParam, // might be using 32 bit range. int new_value = GetValue(); if (m_oldValue != new_value) - SendSpinUpdate( new_value ); + { + m_oldValue = new_value; + SendSpinUpdate(new_value); + } return true; } diff --git a/tests/controls/spinctrltest.cpp b/tests/controls/spinctrltest.cpp index da4df9363f..e91079de3c 100644 --- a/tests/controls/spinctrltest.cpp +++ b/tests/controls/spinctrltest.cpp @@ -38,6 +38,7 @@ private: WXUISIM_TEST( Wrap ); CPPUNIT_TEST( Range ); CPPUNIT_TEST( Value ); + WXUISIM_TEST( SetValueInsideEventHandler ); CPPUNIT_TEST_SUITE_END(); void Initial(); @@ -46,6 +47,10 @@ private: void Wrap(); void Range(); void Value(); + void SetValueInsideEventHandler(); + + // Helper event handler for SetValueInsideEventHandler() test. + void OnSpinSetValue(wxSpinEvent &e); wxSpinCtrl* m_spin; @@ -224,4 +229,41 @@ void SpinCtrlTestCase::Value() CPPUNIT_ASSERT_EQUAL(0, updatedText.GetCount()); } +void SpinCtrlTestCase::OnSpinSetValue(wxSpinEvent &e) +{ + // Constrain the value to be in the 1..16 range or 32. + int newVal = e.GetValue(); + + if ( newVal == 31 ) + m_spin->SetValue(16); + else if ( newVal > 16 ) + m_spin->SetValue(32); +} + +void SpinCtrlTestCase::SetValueInsideEventHandler() +{ +#if wxUSE_UIACTIONSIMULATOR + m_spin->Bind(wxEVT_SPINCTRL, &SpinCtrlTestCase::OnSpinSetValue, this); + + wxUIActionSimulator sim; + + // run multiple times to make sure there are no issues with keeping old value + for ( size_t i = 0; i < 2; i++ ) + { + m_spin->SetFocus(); + wxYield(); + + sim.Char(WXK_DELETE); + sim.Char(WXK_DELETE); + sim.Text("20"); + wxYield(); + + wxTheApp->GetTopWindow()->SetFocus(); + wxYield(); + + CPPUNIT_ASSERT_EQUAL(32, m_spin->GetValue()); + } +#endif // wxUSE_UIACTIONSIMULATOR +} + #endif