Add wxDateTimePickerCtrl::SetNullText()

This allows to customize the string shown when there is no valid date
under MSW (only, for now) and can be notably used to suppress the
unused date completely, which can be useful to lighten up the display
when there are many controls.

Add UI elements to the widgets sample allowing to test the new function.
This commit is contained in:
Vadim Zeitlin
2020-11-05 01:21:26 +01:00
parent 6d4ce92c20
commit 02f1ee3987
5 changed files with 120 additions and 1 deletions

View File

@@ -54,6 +54,7 @@ enum
DatePickerPage_Reset = wxID_HIGHEST,
DatePickerPage_Set,
DatePickerPage_SetRange,
DatePickerPage_SetNullText,
DatePickerPage_Picker
};
@@ -78,6 +79,7 @@ protected:
void OnButtonSet(wxCommandEvent& event);
void OnButtonSetRange(wxCommandEvent& event);
void OnButtonSetNullText(wxCommandEvent& event);
void OnButtonReset(wxCommandEvent& event);
// reset the date picker parameters
@@ -96,6 +98,7 @@ protected:
wxTextCtrl *m_textCur;
wxTextCtrl *m_textMin;
wxTextCtrl *m_textMax;
wxTextCtrl *m_textNull;
wxRadioBox* m_radioKind;
wxCheckBox* m_chkStyleCentury;
@@ -117,6 +120,7 @@ wxBEGIN_EVENT_TABLE(DatePickerWidgetsPage, WidgetsPage)
EVT_BUTTON(DatePickerPage_Reset, DatePickerWidgetsPage::OnButtonReset)
EVT_BUTTON(DatePickerPage_Set, DatePickerWidgetsPage::OnButtonSet)
EVT_BUTTON(DatePickerPage_SetRange, DatePickerWidgetsPage::OnButtonSetRange)
EVT_BUTTON(DatePickerPage_SetNullText, DatePickerWidgetsPage::OnButtonSetNullText)
EVT_DATE_CHANGED(wxID_ANY, DatePickerWidgetsPage::OnDateChanged)
wxEND_EVENT_TABLE()
@@ -197,6 +201,20 @@ void DatePickerWidgetsPage::CreateContent()
sizerMiddle->Add(new wxButton(this, DatePickerPage_SetRange, "Set &range"),
wxSizerFlags().Centre().Border());
sizerMiddle->AddSpacer(10);
sizerMiddle->Add(CreateSizerWithTextAndLabel
(
"&Null text",
wxID_ANY,
&m_textNull
),
wxSizerFlags().Expand().Border());
sizerMiddle->Add(new wxButton(this, DatePickerPage_SetNullText,
"Set &null text"),
wxSizerFlags().Centre().Border());
// right pane: control itself
wxSizer *sizerRight = new wxBoxSizer(wxHORIZONTAL);
@@ -327,6 +345,11 @@ void DatePickerWidgetsPage::OnButtonSetRange(wxCommandEvent& WXUNUSED(event))
}
}
void DatePickerWidgetsPage::OnButtonSetNullText(wxCommandEvent& WXUNUSED(event))
{
m_datePicker->SetNullText(m_textNull->GetValue());
}
// 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.