Avoid using out of range value in wxSpinCtrl with inversed range.

In wxMSW it is possible that minimal allowed value is greater than maximal
allowed one and the native control works correctly in this case, however
wxSpinCtrl set m_oldValue to an invalid value which could result in an
infinite recursion if SetRange() was called from the wxEVT_SPINCTRL event
handler.

For example, if the control value was initially 0 and the event handler called
SetRange(1, 0), it would result setting the value to 1 because it was less
than the minimum, resulting in another call to the event handler which would
now set the value to 0 because it was more than the maximum resulting in
another call to the event handler and so forth.

Fix this by ensuring that the value lies between minimal and maximal values,
whatever is their relative order.
This commit is contained in:
Vadim Zeitlin
2015-05-21 01:09:55 +02:00
parent ba107a9a87
commit 5f8ac45789

View File

@@ -544,10 +544,20 @@ 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;
if ( minVal <= maxVal )
{
if ( m_oldValue < minVal )
m_oldValue = minVal;
else if ( m_oldValue > maxVal )
m_oldValue = maxVal;
}
else // reversed range
{
if ( m_oldValue > minVal )
m_oldValue = minVal;
else if ( m_oldValue < maxVal )
m_oldValue = maxVal;
}
wxSpinButton::SetRange(minVal, maxVal);