]> git.saurik.com Git - wxWidgets.git/blobdiff - src/msw/spinctrl.cpp
Minor header cleaning.
[wxWidgets.git] / src / msw / spinctrl.cpp
index da8bb856f66a7a26563ba0e154f380c038406415..14bdda9ae059d05c6383ceaf83cd907167e1c246 100644 (file)
@@ -1,5 +1,5 @@
 /////////////////////////////////////////////////////////////////////////////
-// Name:        msw/spinctrl.cpp
+// Name:        src/msw/spinctrl.cpp
 // Purpose:     wxSpinCtrl class implementation for Win32
 // Author:      Vadim Zeitlin
 // Modified by:
     #pragma hdrstop
 #endif
 
-#ifndef WX_PRECOMP
-    #include "wx/wx.h"
-#endif
-
 #if wxUSE_SPINCTRL
 
 #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"
@@ -198,28 +200,14 @@ wxSpinCtrl *wxSpinCtrl::GetSpinForTextCtrl(WXHWND hwndBuddy)
 // process a WM_COMMAND generated by the buddy text control
 bool wxSpinCtrl::ProcessTextCommand(WXWORD cmd, WXWORD WXUNUSED(id))
 {
-    switch (cmd)
+    if ( cmd == EN_CHANGE )
     {
-    case EN_CHANGE:
-        {
-            wxCommandEvent event(wxEVT_COMMAND_TEXT_UPDATED, GetId());
-            event.SetEventObject(this);
-            wxString val = wxGetWindowText(m_hwndBuddy);
-            event.SetString(val);
-            event.SetInt(GetValue());
-            return GetEventHandler()->ProcessEvent(event);
-        }
-    case EN_SETFOCUS:
-    case EN_KILLFOCUS:
-        {
-            wxFocusEvent event(cmd == EN_KILLFOCUS ? wxEVT_KILL_FOCUS
-                    : wxEVT_SET_FOCUS,
-                    m_windowId);
-            event.SetEventObject( this );
-            return GetEventHandler()->ProcessEvent(event);
-        }
-     default:
-        break;
+        wxCommandEvent event(wxEVT_COMMAND_TEXT_UPDATED, GetId());
+        event.SetEventObject(this);
+        wxString val = wxGetWindowText(m_hwndBuddy);
+        event.SetString(val);
+        event.SetInt(GetValue());
+        return GetEventHandler()->ProcessEvent(event);
     }
 
     // not processed
@@ -265,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();
 }
 
@@ -279,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
 // ----------------------------------------------------------------------------
@@ -366,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);
@@ -443,8 +447,10 @@ void  wxSpinCtrl::SetValue(int val)
         // text control is currently empty, the spin button seems to be happy
         // to leave it like this, while we really want to always show the
         // current value in the control, so do it manually
-        ::SetWindowText(GetBuddyHwnd(), wxString::Format(_T("%ld"), val));
+        ::SetWindowText(GetBuddyHwnd(), wxString::Format(_T("%d"), val));
     }
+    
+    m_oldValue = GetValue();
 }
 
 int wxSpinCtrl::GetValue() const
@@ -542,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;
 }
 
 // ----------------------------------------------------------------------------
@@ -622,4 +632,3 @@ void wxSpinCtrl::DoGetPosition(int *x, int *y) const
 }
 
 #endif // wxUSE_SPINCTRL
-