Fix inheritance hierarchy of wxTimePickerCtrlGeneric

This class must not derive from the native wxDatePickerCtrl, as it
doesn't make much sense and resulted in the need for an ugly hack with
either overriding unused and inapplicable pure virtual methods in this
class itself, as was originally done in 569c7d8ccb (Add wxTimePickerCtrl
class., 2011-09-29) when it was introduced, or not making these methods
pure virtual in the first place, as was done in d0da5061ce (Dirty hack
to allow generic wxDatePickerCtrl to compile under MSW., 2011-10-20),
but didn't really fix the problem.

Do fix it now by using different hierarchies for the native and generic
classes. The main disadvantage of doing it is that there is no common
base class for wxTimePickerCtrl and wxTimePickerCtrlGeneric providing
SetTime() and GetTime() methods any more, but this seems like a
relatively small price to pay because real applications won't be using
these two classes simultaneously, as the calendar sample does, anyhow.
This commit is contained in:
Vadim Zeitlin
2020-11-04 22:59:11 +01:00
parent c2a488ca42
commit 8a64b6acea
4 changed files with 46 additions and 36 deletions

View File

@@ -218,12 +218,24 @@ class MyTimeDialog : public wxDialog
public:
MyTimeDialog(wxWindow* parent);
wxDateTime GetTime() const { return m_timePicker->GetValue(); }
wxDateTime GetTime() const
{
#if wxUSE_TIMEPICKCTRL_GENERIC
if ( m_timePickerGeneric )
return m_timePickerGeneric->GetValue();
#endif // wxUSE_TIMEPICKCTRL_GENERIC
return m_timePicker->GetValue();
}
private:
void OnTimeChange(wxDateEvent& event);
wxTimePickerCtrlBase* m_timePicker;
wxTimePickerCtrl* m_timePicker;
#if wxUSE_TIMEPICKCTRL_GENERIC
wxTimePickerCtrlGeneric* m_timePickerGeneric;
#endif // wxUSE_TIMEPICKCTRL_GENERIC
wxStaticText* m_timeText;
wxDECLARE_EVENT_TABLE();
@@ -987,20 +999,31 @@ wxEND_EVENT_TABLE()
MyTimeDialog::MyTimeDialog(wxWindow *parent)
: wxDialog(parent, wxID_ANY, wxString("Calendar: Choose time"))
{
wxWindow* timePickerWindow = NULL;
#if wxUSE_TIMEPICKCTRL_GENERIC
m_timePickerGeneric = NULL;
m_timePicker = NULL;
wxFrame *frame = (wxFrame *)wxGetTopLevelParent(parent);
if ( frame && frame->GetMenuBar()->IsChecked(Calendar_TimePicker_Generic) )
m_timePicker = new wxTimePickerCtrlGeneric(this, wxID_ANY);
{
m_timePickerGeneric = new wxTimePickerCtrlGeneric(this, wxID_ANY);
timePickerWindow = m_timePickerGeneric;
}
else
#endif // wxUSE_TIMEPICKCTRL_GENERIC
m_timePicker = new wxTimePickerCtrl(this, wxID_ANY);
m_timeText = new wxStaticText(this, wxID_ANY,
m_timePicker->GetValue().FormatISOTime());
if ( !timePickerWindow )
timePickerWindow = m_timePicker;
m_timeText = new wxStaticText(this, wxID_ANY, GetTime().FormatISOTime());
const wxSizerFlags flags = wxSizerFlags().Centre().Border();
wxFlexGridSizer* const sizerMain = new wxFlexGridSizer(2);
sizerMain->Add(new wxStaticText(this, wxID_ANY, "Enter &time:"), flags);
sizerMain->Add(m_timePicker, flags);
sizerMain->Add(timePickerWindow, flags);
sizerMain->Add(new wxStaticText(this, wxID_ANY, "Time in ISO format:"),
flags);