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 in
aae5ec8bbe0b14bd2f43708186428e3c09d10739 (and cherry-picked to master as
d6781628fd), 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:
Vadim Zeitlin 2018-07-30 22:05:32 +02:00
parent b8401d2fb5
commit d406f23e67

View File

@ -180,18 +180,33 @@ private:
dt = dtOld; dt = dtOld;
} }
m_combo->SetText(GetStringValueFor(dt)); if ( dt.IsValid() )
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() ) // Set it at wxCalendarCtrl level.
SetDate(dt); SetDate(dt);
SendDateEvent(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());
}
} }
} }