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
This commit is contained in:
Vadim Zeitlin
2010-05-06 12:58:32 +00:00
parent 5afb019a0c
commit 3a71210569
2 changed files with 22 additions and 19 deletions

View 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;

View File

@@ -93,7 +93,7 @@ public:
{
if (m_spin)
{
m_spin->SyncSpinToText();
if ( m_spin->SyncSpinToText() )
m_spin->DoSendEvent();
}
@@ -328,7 +328,6 @@ 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();
int spin_value = event.GetPosition();
@@ -395,7 +394,6 @@ void wxSpinCtrlGenericBase::OnTextChar(wxKeyEvent& event)
value = AdjustToFitInRange(value);
if ( m_textCtrl && m_textCtrl->IsModified() )
SyncSpinToText();
if ( DoSetValue(value) )
@@ -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;
}
else // text contents is not a valid number at all
{
// 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
DoSetValue(textValue);
}
else
{
// textctrl is out of sync, discard and reset
DoSetValue(m_value);
}
// 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);
}
// ----------------------------------------------------------------------------