Fix assert failures with wxDP_ALLOWNONE in the widgets sample
DatePickerWidgetsPage::OnDateChanged() must check whether the wxDateTime value received from the control or event is valid before formatting it, as this may not be the case when wxDP_ALLOWNONE is on, and trying to format an invalid date results in assertion failures (and random junk in the output).
This commit is contained in:
@@ -327,11 +327,19 @@ void DatePickerWidgetsPage::OnButtonSetRange(wxCommandEvent& WXUNUSED(event))
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Helper function which has to be used here because the controls with
|
||||||
|
// wxDP_ALLOWNONE style can have invalid date, both in the control itself and
|
||||||
|
// in the event it generates.
|
||||||
|
static wxString FormatPossiblyInvalidDate(const wxDateTime& dt)
|
||||||
|
{
|
||||||
|
return dt.IsValid() ? dt.FormatISOCombined() : wxString("[none]");
|
||||||
|
}
|
||||||
|
|
||||||
void DatePickerWidgetsPage::OnDateChanged(wxDateEvent& event)
|
void DatePickerWidgetsPage::OnDateChanged(wxDateEvent& event)
|
||||||
{
|
{
|
||||||
wxLogMessage("Date changed, now is %s (control value is %s).",
|
wxLogMessage("Date changed, now is %s (control value is %s).",
|
||||||
event.GetDate().FormatISOCombined(),
|
FormatPossiblyInvalidDate(event.GetDate()),
|
||||||
m_datePicker->GetValue().FormatISOCombined());
|
FormatPossiblyInvalidDate(m_datePicker->GetValue()));
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // wxUSE_DATEPICKCTRL
|
#endif // wxUSE_DATEPICKCTRL
|
||||||
|
Reference in New Issue
Block a user