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

@@ -29,7 +29,10 @@ enum
// wxTimePickerCtrl: Allow the user to enter the time.
// ----------------------------------------------------------------------------
class WXDLLIMPEXP_ADV wxTimePickerCtrlBase : public wxDateTimePickerCtrl
// The template argument must be a class deriving from wxDateTimePickerCtrlBase
// (i.e. in practice either this class itself or wxDateTimePickerCtrl).
template <typename Base>
class wxTimePickerCtrlCommonBase : public Base
{
public:
/*
@@ -67,7 +70,7 @@ public:
return false;
}
SetValue(dt);
this->SetValue(dt);
return true;
}
@@ -78,7 +81,7 @@ public:
wxCHECK_MSG( hour && min && sec, false,
wxS("Time component pointers must be non-NULL") );
const wxDateTime::Tm tm = GetValue().GetTm();
const wxDateTime::Tm tm = this->GetValue().GetTm();
*hour = tm.hour;
*min = tm.min;
*sec = tm.sec;
@@ -87,6 +90,10 @@ public:
}
};
// This class is defined mostly for compatibility and is used as the base class
// by native wxTimePickerCtrl implementations.
typedef wxTimePickerCtrlCommonBase<wxDateTimePickerCtrl> wxTimePickerCtrlBase;
#if defined(__WXMSW__) && !defined(__WXUNIVERSAL__)
#include "wx/msw/timectrl.h"