Ensure that new value sent in EVT_SPIN_UP/DOWN is never out the range (wxMSW)
The new value sent in the event cannot be just set to the current value +/- 1. Wrapping and actual limits has to be taken into account. See #17957.
This commit is contained in:
@@ -251,13 +251,31 @@ bool wxSpinButton::MSWOnNotify(int WXUNUSED(idCtrl), WXLPARAM lParam, WXLPARAM *
|
|||||||
{
|
{
|
||||||
NM_UPDOWN *lpnmud = (NM_UPDOWN *)lParam;
|
NM_UPDOWN *lpnmud = (NM_UPDOWN *)lParam;
|
||||||
|
|
||||||
if (lpnmud->hdr.hwndFrom != GetHwnd()) // make sure it is the right control
|
if ( lpnmud->hdr.hwndFrom != GetHwnd() || // make sure it is the right control
|
||||||
|
lpnmud->hdr.code != UDN_DELTAPOS ) // and the right notification
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
int newVal = lpnmud->iPos + lpnmud->iDelta;
|
||||||
|
if ( newVal < m_min )
|
||||||
|
{
|
||||||
|
newVal = HasFlag(wxSP_WRAP) ? m_max : m_min;
|
||||||
|
}
|
||||||
|
else if ( newVal > m_max )
|
||||||
|
{
|
||||||
|
newVal = HasFlag(wxSP_WRAP) ? m_min : m_max;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Don't send an event if the value hasn't actually changed (for compatibility with wxGTK and wxOSX).
|
||||||
|
if ( newVal == lpnmud->iPos )
|
||||||
|
{
|
||||||
|
*result = 1;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
wxSpinEvent event(lpnmud->iDelta > 0 ? wxEVT_SCROLL_LINEUP
|
wxSpinEvent event(lpnmud->iDelta > 0 ? wxEVT_SCROLL_LINEUP
|
||||||
: wxEVT_SCROLL_LINEDOWN,
|
: wxEVT_SCROLL_LINEDOWN,
|
||||||
m_windowId);
|
m_windowId);
|
||||||
event.SetPosition(lpnmud->iPos + lpnmud->iDelta);
|
event.SetPosition(newVal);
|
||||||
event.SetEventObject(this);
|
event.SetEventObject(this);
|
||||||
|
|
||||||
bool processed = HandleWindowEvent(event);
|
bool processed = HandleWindowEvent(event);
|
||||||
|
Reference in New Issue
Block a user