X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/0ca3c231fbc905b8e7dbd466c9f645305842ba57..f5766910b6731eb03e82371416e9778203396ce7:/src/msw/spinctrl.cpp?ds=sidebyside diff --git a/src/msw/spinctrl.cpp b/src/msw/spinctrl.cpp index 67083e3f1e..14bdda9ae0 100644 --- a/src/msw/spinctrl.cpp +++ b/src/msw/spinctrl.cpp @@ -29,12 +29,12 @@ #include "wx/spinctrl.h" #ifndef WX_PRECOMP + #include "wx/msw/wrapcctl.h" // include "properly" #include "wx/event.h" #include "wx/textctrl.h" #endif #include "wx/msw/private.h" -#include "wx/msw/wrapcctl.h" #if wxUSE_TOOLTIPS #include "wx/tooltip.h" @@ -253,8 +253,8 @@ void wxSpinCtrl::OnChar(wxKeyEvent& event) void wxSpinCtrl::OnKillFocus(wxFocusEvent& event) { - // ensure that the value is shown correctly - SetValue(GetValue()) ; + // ensure that a correct value is shown by the control + NormalizeValue(); event.Skip(); } @@ -267,6 +267,20 @@ void wxSpinCtrl::OnSetFocus(wxFocusEvent& event) event.Skip(); } +void wxSpinCtrl::NormalizeValue() +{ + int value = GetValue(); + SetValue( value ); + if (value != m_oldValue) + { + wxCommandEvent event( wxEVT_COMMAND_SPINCTRL_UPDATED, GetId() ); + event.SetEventObject( this ); + event.SetInt( value ); + GetEventHandler()->ProcessEvent( event ); + m_oldValue = value; + } +} + // ---------------------------------------------------------------------------- // construction // ---------------------------------------------------------------------------- @@ -354,6 +368,8 @@ bool wxSpinCtrl::Create(wxWindow *parent, SetRange(min, max); SetValue(initial); + + m_oldValue = initial; // subclass the text ctrl to be able to intercept some events wxSetWindowUserData(GetBuddyHwnd(), this); @@ -433,6 +449,8 @@ void wxSpinCtrl::SetValue(int val) // current value in the control, so do it manually ::SetWindowText(GetBuddyHwnd(), wxString::Format(_T("%d"), val)); } + + m_oldValue = GetValue(); } int wxSpinCtrl::GetValue() const @@ -530,14 +548,18 @@ void wxSpinCtrl::OnSpinChange(wxSpinEvent& eventSpin) { wxCommandEvent event(wxEVT_COMMAND_SPINCTRL_UPDATED, GetId()); event.SetEventObject(this); - event.SetInt(eventSpin.GetPosition()); - - (void)GetEventHandler()->ProcessEvent(event); + int value = eventSpin.GetPosition(); + event.SetInt( value ); + + if (value != m_oldValue) + (void)GetEventHandler()->ProcessEvent(event); if ( eventSpin.GetSkipped() ) { event.Skip(); } + + m_oldValue = value; } // ----------------------------------------------------------------------------