#include "wx/spinctrl.h"
#ifndef WX_PRECOMP
+ #include "wx/msw/wrapcctl.h" // include <commctrl.h> "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"
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();
}
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
// ----------------------------------------------------------------------------
SetRange(min, max);
SetValue(initial);
+
+ m_oldValue = initial;
// subclass the text ctrl to be able to intercept some events
wxSetWindowUserData(GetBuddyHwnd(), this);
sizeText.y = EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy);
}
- SetBestSize(size);
+ SetInitialSize(size);
(void)::ShowWindow(GetBuddyHwnd(), SW_SHOW);
// current value in the control, so do it manually
::SetWindowText(GetBuddyHwnd(), wxString::Format(_T("%d"), val));
}
+
+ m_oldValue = GetValue();
}
int wxSpinCtrl::GetValue() const
{
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;
}
// ----------------------------------------------------------------------------