]> git.saurik.com Git - wxWidgets.git/commitdiff
Don't send wxEVT_COMMAND_SPINCTRLDOUBLE_UPDATED when nothing changed.
authorVadim Zeitlin <vadim@wxwidgets.org>
Thu, 6 May 2010 12:58:32 +0000 (12:58 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Thu, 6 May 2010 12:58:32 +0000 (12:58 +0000)
The generic double spin control sent UPDATED events whenever it lost focus,
whether anything changed or not.

Don't send events unless the controls value has really changed.

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

include/wx/generic/spinctlg.h
src/generic/spinctlg.cpp

index 41fc00cb1b339980c2373f9fe19971dcd4b8ed6f..9d8fe791c5ab1d025b504a0e57bed5bddf8538e8 100644 (file)
@@ -105,8 +105,13 @@ protected:
     void DoSetRange(double min_val, double max_val);
     void DoSetIncrement(double inc);
 
-    // Ensure that the textctrl shows correct value
-    void SyncSpinToText();
+    // update our value to reflect the text control contents (if it has been
+    // modified by user, do nothing otherwise)
+    //
+    // can also change the text control if its value is invalid
+    //
+    // return true if our value has changed
+    bool SyncSpinToText();
 
     // Send the correct event type
     virtual void DoSendEvent() = 0;
index 56f39de773c5efa7b4642205566722b6ba189939..d0304875436f5884e4edb4f3ca3ca98d1a0dff02 100644 (file)
@@ -93,8 +93,8 @@ public:
     {
         if (m_spin)
         {
-            m_spin->SyncSpinToText();
-            m_spin->DoSendEvent();
+            if ( m_spin->SyncSpinToText() )
+                m_spin->DoSendEvent();
         }
 
         event.Skip();
@@ -328,8 +328,7 @@ void wxSpinCtrlGenericBase::OnSpinButton(wxSpinEvent& event)
 
     // Sync the textctrl since the user expects that the button will modify
     // what they see in the textctrl.
-    if ( m_textCtrl && m_textCtrl->IsModified() )
-        SyncSpinToText();
+    SyncSpinToText();
 
     int spin_value = event.GetPosition();
     double step = (event.GetEventType() == wxEVT_SCROLL_LINEUP) ? 1 : -1;
@@ -395,8 +394,7 @@ void wxSpinCtrlGenericBase::OnTextChar(wxKeyEvent& event)
 
     value = AdjustToFitInRange(value);
 
-    if ( m_textCtrl && m_textCtrl->IsModified() )
-        SyncSpinToText();
+    SyncSpinToText();
 
     if ( DoSetValue(value) )
         DoSendEvent();
@@ -406,10 +404,10 @@ void wxSpinCtrlGenericBase::OnTextChar(wxKeyEvent& event)
 // Textctrl functions
 // ----------------------------------------------------------------------------
 
-void wxSpinCtrlGenericBase::SyncSpinToText()
+bool wxSpinCtrlGenericBase::SyncSpinToText()
 {
-    if (!m_textCtrl)
-        return;
+    if ( !m_textCtrl || !m_textCtrl->IsModified() )
+        return false;
 
     double textValue;
     if ( m_textCtrl->GetValue().ToDouble(&textValue) )
@@ -418,17 +416,17 @@ void wxSpinCtrlGenericBase::SyncSpinToText()
             textValue = m_max;
         else if (textValue < m_min)
             textValue = m_min;
-
-        // we must always set the value here, even if it's equal to m_value, as
-        // otherwise we could be left with an out of range value when leaving
-        // the text control and the current value is already m_max for example
-        DoSetValue(textValue);
     }
-    else
+    else // text contents is not a valid number at all
     {
-        // textctrl is out of sync, discard and reset
-        DoSetValue(m_value);
+        // replace its contents with the last valid value
+        textValue = m_value;
     }
+
+    // we must always set the value here, even if it's equal to m_value, as
+    // otherwise we could be left with an out of range value when leaving the
+    // text control and the current value is already m_max for example
+    return DoSetValue(textValue);
 }
 
 // ----------------------------------------------------------------------------