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:
@@ -105,8 +105,13 @@ protected:
|
|||||||
void DoSetRange(double min_val, double max_val);
|
void DoSetRange(double min_val, double max_val);
|
||||||
void DoSetIncrement(double inc);
|
void DoSetIncrement(double inc);
|
||||||
|
|
||||||
// Ensure that the textctrl shows correct value
|
// update our value to reflect the text control contents (if it has been
|
||||||
void SyncSpinToText();
|
// 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
|
// Send the correct event type
|
||||||
virtual void DoSendEvent() = 0;
|
virtual void DoSendEvent() = 0;
|
||||||
|
@@ -93,8 +93,8 @@ public:
|
|||||||
{
|
{
|
||||||
if (m_spin)
|
if (m_spin)
|
||||||
{
|
{
|
||||||
m_spin->SyncSpinToText();
|
if ( m_spin->SyncSpinToText() )
|
||||||
m_spin->DoSendEvent();
|
m_spin->DoSendEvent();
|
||||||
}
|
}
|
||||||
|
|
||||||
event.Skip();
|
event.Skip();
|
||||||
@@ -328,8 +328,7 @@ void wxSpinCtrlGenericBase::OnSpinButton(wxSpinEvent& event)
|
|||||||
|
|
||||||
// Sync the textctrl since the user expects that the button will modify
|
// Sync the textctrl since the user expects that the button will modify
|
||||||
// what they see in the textctrl.
|
// what they see in the textctrl.
|
||||||
if ( m_textCtrl && m_textCtrl->IsModified() )
|
SyncSpinToText();
|
||||||
SyncSpinToText();
|
|
||||||
|
|
||||||
int spin_value = event.GetPosition();
|
int spin_value = event.GetPosition();
|
||||||
double step = (event.GetEventType() == wxEVT_SCROLL_LINEUP) ? 1 : -1;
|
double step = (event.GetEventType() == wxEVT_SCROLL_LINEUP) ? 1 : -1;
|
||||||
@@ -395,8 +394,7 @@ void wxSpinCtrlGenericBase::OnTextChar(wxKeyEvent& event)
|
|||||||
|
|
||||||
value = AdjustToFitInRange(value);
|
value = AdjustToFitInRange(value);
|
||||||
|
|
||||||
if ( m_textCtrl && m_textCtrl->IsModified() )
|
SyncSpinToText();
|
||||||
SyncSpinToText();
|
|
||||||
|
|
||||||
if ( DoSetValue(value) )
|
if ( DoSetValue(value) )
|
||||||
DoSendEvent();
|
DoSendEvent();
|
||||||
@@ -406,10 +404,10 @@ void wxSpinCtrlGenericBase::OnTextChar(wxKeyEvent& event)
|
|||||||
// Textctrl functions
|
// Textctrl functions
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
void wxSpinCtrlGenericBase::SyncSpinToText()
|
bool wxSpinCtrlGenericBase::SyncSpinToText()
|
||||||
{
|
{
|
||||||
if (!m_textCtrl)
|
if ( !m_textCtrl || !m_textCtrl->IsModified() )
|
||||||
return;
|
return false;
|
||||||
|
|
||||||
double textValue;
|
double textValue;
|
||||||
if ( m_textCtrl->GetValue().ToDouble(&textValue) )
|
if ( m_textCtrl->GetValue().ToDouble(&textValue) )
|
||||||
@@ -418,17 +416,17 @@ void wxSpinCtrlGenericBase::SyncSpinToText()
|
|||||||
textValue = m_max;
|
textValue = m_max;
|
||||||
else if (textValue < m_min)
|
else if (textValue < m_min)
|
||||||
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
|
// replace its contents with the last valid value
|
||||||
DoSetValue(m_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);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
Reference in New Issue
Block a user