Fix behaviour on focus loss in generic wxDatePickerCtrl
Don't send any events if the date is invalid when leaving the control. Also, for the controls without wxDP_ALLOWNONE style, ensure that we revert to the valid date we had before when this happens, as such controls must, by definition, always have a valid sate. Note that there already was a check for wxDP_ALLOWNONE, added back inaae5ec8bbe
(and cherry-picked to master asd6781628fd
), but it seemed to be reversed, as it only set the date to invalid if the control did not have this style.
This commit is contained in:
@@ -180,18 +180,33 @@ private:
|
||||
dt = dtOld;
|
||||
}
|
||||
|
||||
m_combo->SetText(GetStringValueFor(dt));
|
||||
|
||||
if ( !dt.IsValid() && HasDPFlag(wxDP_ALLOWNONE) )
|
||||
return;
|
||||
|
||||
// notify that we had to change the date after validation
|
||||
if ( (dt.IsValid() && (!dtOld.IsValid() || dt != dtOld)) ||
|
||||
(!dt.IsValid() && dtOld.IsValid()) )
|
||||
if ( dt.IsValid() )
|
||||
{
|
||||
if ( dt.IsValid() )
|
||||
SetDate(dt);
|
||||
SendDateEvent(dt);
|
||||
// Set it at wxCalendarCtrl level.
|
||||
SetDate(dt);
|
||||
|
||||
// And show it in the text field.
|
||||
m_combo->SetText(GetStringValue());
|
||||
|
||||
// And if the date has really changed, send an event about it.
|
||||
if ( dt != dtOld )
|
||||
SendDateEvent(dt);
|
||||
}
|
||||
else // Invalid date currently entered.
|
||||
{
|
||||
if ( HasDPFlag(wxDP_ALLOWNONE) )
|
||||
{
|
||||
// Clear the text part to indicate that the date is invalid.
|
||||
// Would it be better to indicate this in some more clear way,
|
||||
// e.g. maybe by using "[none]" or something like this?
|
||||
m_combo->SetText(wxString());
|
||||
}
|
||||
else
|
||||
{
|
||||
// Restore the original value, as we can't have invalid value
|
||||
// in this control.
|
||||
m_combo->SetText(GetStringValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user