From 3b0a539045a2feacbc8a62509049cd40e3ce0d71 Mon Sep 17 00:00:00 2001 From: Artur Wieczorek Date: Fri, 22 Sep 2017 15:30:05 +0200 Subject: [PATCH] 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. --- src/msw/spinbutt.cpp | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/msw/spinbutt.cpp b/src/msw/spinbutt.cpp index 9c7959d8d5..9e9ecb7238 100644 --- a/src/msw/spinbutt.cpp +++ b/src/msw/spinbutt.cpp @@ -251,13 +251,31 @@ bool wxSpinButton::MSWOnNotify(int WXUNUSED(idCtrl), WXLPARAM lParam, WXLPARAM * { 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; + 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 : wxEVT_SCROLL_LINEDOWN, m_windowId); - event.SetPosition(lpnmud->iPos + lpnmud->iDelta); + event.SetPosition(newVal); event.SetEventObject(this); bool processed = HandleWindowEvent(event);