From 3a71210569f5cefca56cc2244d4a244e2649a8df Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 6 May 2010 12:58:32 +0000 Subject: [PATCH] Don't send wxEVT_COMMAND_SPINCTRLDOUBLE_UPDATED when nothing changed. 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 | 9 +++++++-- src/generic/spinctlg.cpp | 32 +++++++++++++++----------------- 2 files changed, 22 insertions(+), 19 deletions(-) diff --git a/include/wx/generic/spinctlg.h b/include/wx/generic/spinctlg.h index 41fc00cb1b..9d8fe791c5 100644 --- a/include/wx/generic/spinctlg.h +++ b/include/wx/generic/spinctlg.h @@ -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; diff --git a/src/generic/spinctlg.cpp b/src/generic/spinctlg.cpp index 56f39de773..d030487543 100644 --- a/src/generic/spinctlg.cpp +++ b/src/generic/spinctlg.cpp @@ -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); } // ---------------------------------------------------------------------------- -- 2.45.2