Make updating the value in wxEVT_SPINCTRL work in wxMSW

In wxMSW, the value of the control was modified after executing the
user-defined wxEVT_SPINCTRL handler which meant that any calls to
SetValue() there were effectively ignored.

Fix this and add a unit test checking for the described scenario.

Closes https://github.com/wxWidgets/wxWidgets/pull/1027

Closes #18187.
This commit is contained in:
oleksii.vorobiov
2018-11-19 13:17:32 +02:00
committed by Vadim Zeitlin
parent facb06a1b8
commit fd5c62bc41
2 changed files with 47 additions and 4 deletions

View File

@@ -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