]>
Commit | Line | Data |
---|---|---|
1 | /////////////////////////////////////////////////////////////////////////////// | |
2 | // Name: wx/timectrl.h | |
3 | // Purpose: Declaration of wxTimePickerCtrl class. | |
4 | // Author: Vadim Zeitlin | |
5 | // Created: 2011-09-22 | |
6 | // Copyright: (c) 2011 Vadim Zeitlin <vadim@wxwidgets.org> | |
7 | // Licence: wxWindows licence | |
8 | /////////////////////////////////////////////////////////////////////////////// | |
9 | ||
10 | #ifndef _WX_TIMECTRL_H_ | |
11 | #define _WX_TIMECTRL_H_ | |
12 | ||
13 | #include "wx/defs.h" | |
14 | ||
15 | #if wxUSE_TIMEPICKCTRL | |
16 | ||
17 | #include "wx/datetimectrl.h" | |
18 | ||
19 | #define wxTimePickerCtrlNameStr wxS("timectrl") | |
20 | ||
21 | // No special styles are currently defined for this control but still define a | |
22 | // symbolic constant for the default style for consistency. | |
23 | enum | |
24 | { | |
25 | wxTP_DEFAULT = 0 | |
26 | }; | |
27 | ||
28 | // ---------------------------------------------------------------------------- | |
29 | // wxTimePickerCtrl: Allow the user to enter the time. | |
30 | // ---------------------------------------------------------------------------- | |
31 | ||
32 | class WXDLLIMPEXP_ADV wxTimePickerCtrlBase : public wxDateTimePickerCtrl | |
33 | { | |
34 | public: | |
35 | /* | |
36 | The derived classes should implement ctor and Create() method with the | |
37 | following signature: | |
38 | ||
39 | bool Create(wxWindow *parent, | |
40 | wxWindowID id, | |
41 | const wxDateTime& dt = wxDefaultDateTime, | |
42 | const wxPoint& pos = wxDefaultPosition, | |
43 | const wxSize& size = wxDefaultSize, | |
44 | long style = wxTP_DEFAULT, | |
45 | const wxValidator& validator = wxDefaultValidator, | |
46 | const wxString& name = wxTimePickerCtrlNameStr); | |
47 | */ | |
48 | ||
49 | /* | |
50 | We also inherit Set/GetValue() methods from the base class which define | |
51 | our public API. Notice that the date portion of the date passed as | |
52 | input or received as output is or should be ignored, only the time part | |
53 | of wxDateTime objects is really significant here. Use Set/GetTime() | |
54 | below for possibly simpler interface. | |
55 | */ | |
56 | ||
57 | // Set the given time. | |
58 | bool SetTime(int hour, int min, int sec) | |
59 | { | |
60 | // Notice that we should use a date on which DST doesn't change to | |
61 | // avoid any problems with time discontinuity so use a fixed date (on | |
62 | // which nobody changes DST) instead of e.g. today. | |
63 | wxDateTime dt(1, wxDateTime::Jan, 2012, hour, min, sec); | |
64 | if ( !dt.IsValid() ) | |
65 | { | |
66 | // No need to assert here, wxDateTime already does it for us. | |
67 | return false; | |
68 | } | |
69 | ||
70 | SetValue(dt); | |
71 | ||
72 | return true; | |
73 | } | |
74 | ||
75 | // Get the current time components. All pointers must be non-NULL. | |
76 | bool GetTime(int* hour, int* min, int* sec) const | |
77 | { | |
78 | wxCHECK_MSG( hour && min && sec, false, | |
79 | wxS("Time component pointers must be non-NULL") ); | |
80 | ||
81 | const wxDateTime::Tm tm = GetValue().GetTm(); | |
82 | *hour = tm.hour; | |
83 | *min = tm.min; | |
84 | *sec = tm.sec; | |
85 | ||
86 | return true; | |
87 | } | |
88 | }; | |
89 | ||
90 | #if defined(__WXMSW__) && !defined(__WXUNIVERSAL__) | |
91 | #include "wx/msw/timectrl.h" | |
92 | ||
93 | #define wxHAS_NATIVE_TIMEPICKERCTRL | |
94 | #elif defined(__WXOSX_COCOA__) && !defined(__WXUNIVERSAL__) | |
95 | #include "wx/osx/timectrl.h" | |
96 | ||
97 | #define wxHAS_NATIVE_TIMEPICKERCTRL | |
98 | #else | |
99 | #include "wx/generic/timectrl.h" | |
100 | ||
101 | class WXDLLIMPEXP_ADV wxTimePickerCtrl : public wxTimePickerCtrlGeneric | |
102 | { | |
103 | public: | |
104 | wxTimePickerCtrl() { } | |
105 | wxTimePickerCtrl(wxWindow *parent, | |
106 | wxWindowID id, | |
107 | const wxDateTime& date = wxDefaultDateTime, | |
108 | const wxPoint& pos = wxDefaultPosition, | |
109 | const wxSize& size = wxDefaultSize, | |
110 | long style = wxTP_DEFAULT, | |
111 | const wxValidator& validator = wxDefaultValidator, | |
112 | const wxString& name = wxTimePickerCtrlNameStr) | |
113 | : wxTimePickerCtrlGeneric(parent, id, date, pos, size, style, validator, name) | |
114 | { | |
115 | } | |
116 | ||
117 | private: | |
118 | wxDECLARE_DYNAMIC_CLASS_NO_COPY(wxTimePickerCtrl); | |
119 | }; | |
120 | #endif | |
121 | ||
122 | #endif // wxUSE_TIMEPICKCTRL | |
123 | ||
124 | #endif // _WX_TIMECTRL_H_ |