]> git.saurik.com Git - wxWidgets.git/commitdiff
Made MSW wxSpinCtrl emit UPDATE event when validating
authorRobert Roebling <robert@roebling.de>
Wed, 20 Sep 2006 14:15:14 +0000 (14:15 +0000)
committerRobert Roebling <robert@roebling.de>
Wed, 20 Sep 2006 14:15:14 +0000 (14:15 +0000)
   the value in the text field upon kill focus.
 Documented this behaviour.
 This is in line with the GTK+ control.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@41316 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

docs/latex/wx/spinctrl.tex
include/wx/msw/spinbutt.h
include/wx/msw/spinctrl.h
src/msw/spinbutt.cpp
src/msw/spinctrl.cpp

index fe9243cee201a4315ad7374851e353d871bfd46c..f6aacc08bd32b1cd03d7131499d07760440a967b 100644 (file)
@@ -43,6 +43,12 @@ the corresponding events will not be generated under all platforms. Finally, if
 the user modifies the text in the edit part of the spin control directly, the
 {\tt EVT\_TEXT} is generated, like for the \helpref{wxTextCtrl}{wxtextctrl}.
 
+When the use enters text into the text area, the text is not
+validated until the control loses focus (e.g. by using the TAB
+key). The value is then adjusted to the range and a 
+\helpref{wxSpinEvent}{wxspinevent} sent then if the value
+is different from the last value sent.
+
 \wxheading{See also}
 
 \helpref{Event handling overview}{eventhandlingoverview},
index b8eeefe3dc51d17ee6d9db35518a12d3f819a139..56e69f30b816af38f52e90de39c62fdd571142b7 100644 (file)
@@ -61,7 +61,7 @@ protected:
    virtual wxSize DoGetBestSize() const;
 
    // ensure that the control displays a value in the current range
-   void NormalizeValue() { SetValue(GetValue()); }
+   virtual void NormalizeValue();
 
 private:
     DECLARE_DYNAMIC_CLASS_NO_COPY(wxSpinButton)
index bd4e0c5f30240fabcc909ed68391cc79bbecb903..edcb026f761b6a57105a8ccaed25fccc3f9fdfa9 100644 (file)
@@ -104,6 +104,9 @@ protected:
     void OnSetFocus(wxFocusEvent& event);
     void OnKillFocus(wxFocusEvent& event);
 
+    int m_oldValue;
+    virtual void NormalizeValue();
+   
     // the data for the "buddy" text ctrl
     WXHWND     m_hwndBuddy;
     WXFARPROC  m_wndProcBuddy;
index d4e20e76a544cf62dc4755bccb4bedc1c0a12bb2..b4b9cfb1e76fc6d8852c3d16c4c7b3b5e7ca0d91 100644 (file)
@@ -256,6 +256,11 @@ void wxSpinButton::SetValue(int val)
     }
 }
 
+void wxSpinButton::NormalizeValue()
+{ 
+    SetValue( GetValue() );
+}
+
 void wxSpinButton::SetRange(int minVal, int maxVal)
 {
     const bool hadRange = m_min < m_max;
index 58673b0e3b38931d4213247b5da8eb40f459a7b2..8f4bd81c896034bc9b94088593fc03be62d1f794 100644 (file)
@@ -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);
@@ -530,14 +546,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;
 }
 
 // ----------------------------------------------------------------------------