From d406f23e6787240cafc36b091fb6e5fbe2381e0b Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 30 Jul 2018 22:05:32 +0200 Subject: [PATCH] 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 d6781628fda216a01fa99ae3e49805b1a98b6ef2), but it seemed to be reversed, as it only set the date to invalid if the control did not have this style. --- src/generic/datectlg.cpp | 37 ++++++++++++++++++++++++++----------- 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/src/generic/datectlg.cpp b/src/generic/datectlg.cpp index 94f5906fed..f50a1bba65 100644 --- a/src/generic/datectlg.cpp +++ b/src/generic/datectlg.cpp @@ -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()); + } } }