]>
Commit | Line | Data |
---|---|---|
9d9b7755 VZ |
1 | /////////////////////////////////////////////////////////////////////////////// |
2 | // Name: wx/calctrl.h | |
3 | // Purpose: date-picker control | |
4 | // Author: Vadim Zeitlin | |
5 | // Modified by: | |
6 | // Created: 29.12.99 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) 1999 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr> | |
65571936 | 9 | // Licence: wxWindows licence |
9d9b7755 VZ |
10 | /////////////////////////////////////////////////////////////////////////////// |
11 | ||
1e6feb95 VZ |
12 | #ifndef _WX_CALCTRL_H_ |
13 | #define _WX_CALCTRL_H_ | |
14 | ||
15 | #include "wx/defs.h" | |
16 | ||
17 | #if wxUSE_CALENDARCTRL | |
9d9b7755 | 18 | |
feb72429 | 19 | #include "wx/dateevt.h" |
b1ef887a VS |
20 | #include "wx/colour.h" |
21 | #include "wx/font.h" | |
628e155d | 22 | #include "wx/control.h" |
4f6aed9c | 23 | |
37df1f33 VZ |
24 | // ---------------------------------------------------------------------------- |
25 | // wxCalendarCtrl flags | |
26 | // ---------------------------------------------------------------------------- | |
27 | ||
28 | enum | |
29 | { | |
30 | // show Sunday as the first day of the week (default) | |
31 | wxCAL_SUNDAY_FIRST = 0x0000, | |
32 | ||
33 | // show Monder as the first day of the week | |
34 | wxCAL_MONDAY_FIRST = 0x0001, | |
35 | ||
36 | // highlight holidays | |
37 | wxCAL_SHOW_HOLIDAYS = 0x0002, | |
38 | ||
39 | // disable the year change control, show only the month change one | |
628e155d | 40 | // deprecated |
37df1f33 VZ |
41 | wxCAL_NO_YEAR_CHANGE = 0x0004, |
42 | ||
43 | // don't allow changing neither month nor year (implies | |
44 | // wxCAL_NO_YEAR_CHANGE) | |
45 | wxCAL_NO_MONTH_CHANGE = 0x000c, | |
46 | ||
47 | // use MS-style month-selection instead of combo-spin combination | |
48 | wxCAL_SEQUENTIAL_MONTH_SELECTION = 0x0010, | |
49 | ||
50 | // show the neighbouring weeks in the previous and next month | |
51 | wxCAL_SHOW_SURROUNDING_WEEKS = 0x0020 | |
52 | }; | |
53 | ||
0185cd09 VZ |
54 | // ---------------------------------------------------------------------------- |
55 | // constants | |
56 | // ---------------------------------------------------------------------------- | |
57 | ||
58 | // return values for the HitTest() method | |
59 | enum wxCalendarHitTestResult | |
60 | { | |
61 | wxCAL_HITTEST_NOWHERE, // outside of anything | |
62 | wxCAL_HITTEST_HEADER, // on the header (weekdays) | |
37df1f33 VZ |
63 | wxCAL_HITTEST_DAY, // on a day in the calendar |
64 | wxCAL_HITTEST_INCMONTH, | |
65 | wxCAL_HITTEST_DECMONTH, | |
66 | wxCAL_HITTEST_SURROUNDING_WEEK | |
0185cd09 VZ |
67 | }; |
68 | ||
4f6aed9c VZ |
69 | // border types for a date |
70 | enum wxCalendarDateBorder | |
71 | { | |
72 | wxCAL_BORDER_NONE, // no border (default) | |
73 | wxCAL_BORDER_SQUARE, // a rectangular border | |
74 | wxCAL_BORDER_ROUND // a round border | |
75 | }; | |
76 | ||
0185cd09 | 77 | // ---------------------------------------------------------------------------- |
4f6aed9c | 78 | // wxCalendarDateAttr: custom attributes for a calendar date |
0185cd09 VZ |
79 | // ---------------------------------------------------------------------------- |
80 | ||
12f190b0 | 81 | class WXDLLIMPEXP_ADV wxCalendarDateAttr |
4f6aed9c VZ |
82 | { |
83 | public: | |
84 | // ctors | |
628e155d | 85 | wxCalendarDateAttr(const wxColour& colText = wxNullColour, |
4f6aed9c VZ |
86 | const wxColour& colBack = wxNullColour, |
87 | const wxColour& colBorder = wxNullColour, | |
88 | const wxFont& font = wxNullFont, | |
89 | wxCalendarDateBorder border = wxCAL_BORDER_NONE) | |
90 | : m_colText(colText), m_colBack(colBack), | |
91 | m_colBorder(colBorder), m_font(font) | |
92 | { | |
93 | Init(border); | |
94 | } | |
95 | wxCalendarDateAttr(wxCalendarDateBorder border, | |
96 | const wxColour& colBorder = wxNullColour) | |
97 | : m_colBorder(colBorder) | |
98 | { | |
99 | Init(border); | |
100 | } | |
101 | ||
102 | // setters | |
103 | void SetTextColour(const wxColour& colText) { m_colText = colText; } | |
104 | void SetBackgroundColour(const wxColour& colBack) { m_colBack = colBack; } | |
105 | void SetBorderColour(const wxColour& col) { m_colBorder = col; } | |
106 | void SetFont(const wxFont& font) { m_font = font; } | |
107 | void SetBorder(wxCalendarDateBorder border) { m_border = border; } | |
108 | void SetHoliday(bool holiday) { m_holiday = holiday; } | |
109 | ||
110 | // accessors | |
111 | bool HasTextColour() const { return m_colText.Ok(); } | |
112 | bool HasBackgroundColour() const { return m_colBack.Ok(); } | |
113 | bool HasBorderColour() const { return m_colBorder.Ok(); } | |
114 | bool HasFont() const { return m_font.Ok(); } | |
115 | bool HasBorder() const { return m_border != wxCAL_BORDER_NONE; } | |
116 | ||
117 | bool IsHoliday() const { return m_holiday; } | |
118 | ||
119 | const wxColour& GetTextColour() const { return m_colText; } | |
120 | const wxColour& GetBackgroundColour() const { return m_colBack; } | |
121 | const wxColour& GetBorderColour() const { return m_colBorder; } | |
122 | const wxFont& GetFont() const { return m_font; } | |
123 | wxCalendarDateBorder GetBorder() const { return m_border; } | |
628e155d VZ |
124 | |
125 | // get or change the "mark" attribute, i.e. the one used for the items | |
126 | // marked with wxCalendarCtrl::Mark() | |
127 | static const wxCalendarDateAttr& GetMark() { return m_mark; } | |
128 | static void SetMark(wxCalendarDateAttr const& m) { m_mark = m; } | |
129 | ||
006713a2 | 130 | protected: |
006713a2 DW |
131 | void Init(wxCalendarDateBorder border = wxCAL_BORDER_NONE) |
132 | { | |
133 | m_border = border; | |
68379eaf | 134 | m_holiday = false; |
006713a2 | 135 | } |
628e155d | 136 | |
4f6aed9c | 137 | private: |
628e155d VZ |
138 | static wxCalendarDateAttr m_mark; |
139 | ||
4f6aed9c VZ |
140 | wxColour m_colText, |
141 | m_colBack, | |
142 | m_colBorder; | |
143 | wxFont m_font; | |
144 | wxCalendarDateBorder m_border; | |
145 | bool m_holiday; | |
146 | }; | |
9d9b7755 VZ |
147 | |
148 | // ---------------------------------------------------------------------------- | |
149 | // wxCalendarCtrl events | |
150 | // ---------------------------------------------------------------------------- | |
151 | ||
b5dbe15d | 152 | class WXDLLIMPEXP_FWD_ADV wxCalendarCtrl; |
4f6aed9c | 153 | |
feb72429 | 154 | class WXDLLIMPEXP_ADV wxCalendarEvent : public wxDateEvent |
9d9b7755 VZ |
155 | { |
156 | public: | |
628e155d VZ |
157 | wxCalendarEvent() : m_wday(wxDateTime::Inv_WeekDay) { } |
158 | wxCalendarEvent(wxWindow *win, const wxDateTime& dt, wxEventType type) | |
159 | : wxDateEvent(win, dt, type), | |
160 | m_wday(wxDateTime::Inv_WeekDay) | |
161 | { | |
162 | } | |
9d9b7755 | 163 | |
12ac619f | 164 | void SetWeekDay(const wxDateTime::WeekDay wd) { m_wday = wd; } |
0185cd09 VZ |
165 | wxDateTime::WeekDay GetWeekDay() const { return m_wday; } |
166 | ||
9d9b7755 | 167 | private: |
0185cd09 | 168 | wxDateTime::WeekDay m_wday; |
f6bcfd97 | 169 | |
fc7a2a60 | 170 | DECLARE_DYNAMIC_CLASS_NO_COPY(wxCalendarEvent) |
9d9b7755 VZ |
171 | }; |
172 | ||
628e155d VZ |
173 | // ---------------------------------------------------------------------------- |
174 | // wxCalendarCtrlBase | |
175 | // ---------------------------------------------------------------------------- | |
176 | ||
177 | class WXDLLIMPEXP_ADV wxCalendarCtrlBase : public wxControl | |
178 | { | |
179 | public: | |
180 | // do we allow changing the month/year? | |
181 | bool AllowMonthChange() const { return !HasFlag(wxCAL_NO_MONTH_CHANGE); } | |
182 | ||
183 | // get/set the current date | |
184 | virtual wxDateTime GetDate() const = 0; | |
185 | virtual bool SetDate(const wxDateTime& date) = 0; | |
186 | ||
187 | ||
188 | // returns one of wxCAL_HITTEST_XXX constants and fills either date or wd | |
189 | // with the corresponding value (none for NOWHERE, the date for DAY and wd | |
190 | // for HEADER) | |
191 | // | |
192 | // notice that this is not implemented in all versions | |
193 | virtual wxCalendarHitTestResult | |
194 | HitTest(const wxPoint& WXUNUSED(pos), | |
195 | wxDateTime* WXUNUSED(date) = NULL, | |
196 | wxDateTime::WeekDay* WXUNUSED(wd) = NULL) | |
197 | { | |
198 | return wxCAL_HITTEST_NOWHERE; | |
199 | } | |
200 | ||
201 | // allow or disable changing the current month (and year), return true if | |
202 | // the value of this option really changed or false if it was already set | |
203 | // to the required value | |
204 | // | |
205 | // NB: we provide implementation for this pure virtual function, derived | |
206 | // classes should call it | |
207 | virtual bool EnableMonthChange(bool enable) = 0; | |
208 | ||
209 | ||
210 | // an item without custom attributes is drawn with the default colours and | |
211 | // font and without border, setting custom attributes allows to modify this | |
212 | // | |
213 | // the day parameter should be in 1..31 range, for days 29, 30, 31 the | |
214 | // corresponding attribute is just unused if there is no such day in the | |
215 | // current month | |
216 | // | |
217 | // notice that currently arbitrary attributes are supported only in the | |
218 | // generic version, the native controls only support Mark() which assigns | |
219 | // some special appearance (which can be customized using SetMark() for the | |
220 | // generic version) to the given day | |
221 | ||
222 | virtual void Mark(size_t day, bool mark) = 0; | |
223 | ||
224 | virtual wxCalendarDateAttr *GetAttr(size_t WXUNUSED(day)) const | |
225 | { return NULL; } | |
226 | virtual void SetAttr(size_t WXUNUSED(day), wxCalendarDateAttr *attr) | |
227 | { delete attr; } | |
228 | virtual void ResetAttr(size_t WXUNUSED(day)) { } | |
229 | ||
230 | ||
231 | // implementation only from now on | |
232 | ||
233 | // generate the given calendar event(s) | |
234 | void GenerateEvent(wxEventType type) | |
235 | { | |
236 | wxCalendarEvent event(this, GetDate(), type); | |
237 | HandleWindowEvent(event); | |
238 | } | |
239 | }; | |
240 | ||
4f6aed9c VZ |
241 | // ---------------------------------------------------------------------------- |
242 | // wxCalendarCtrl | |
243 | // ---------------------------------------------------------------------------- | |
244 | ||
628e155d | 245 | #define wxCalendarNameStr "CalendarCtrl" |
4f6aed9c | 246 | |
628e155d VZ |
247 | #if defined(__WXGTK20__) && !defined(__WXUNIVERSAL__) |
248 | #define wxHAS_NATIVE_CALENDARCTRL | |
249 | #include "wx/gtk/calctrl.h" | |
250 | #define wxCalendarCtrl wxGtkCalendarCtrl | |
251 | #else | |
252 | #include "wx/generic/calctrlg.h" | |
253 | #define wxCalendarCtrl wxGenericCalendarCtrl | |
254 | #endif | |
feb72429 | 255 | |
feb72429 | 256 | |
4f6aed9c | 257 | // ---------------------------------------------------------------------------- |
2e4df4bf | 258 | // calendar event types and macros for handling them |
4f6aed9c VZ |
259 | // ---------------------------------------------------------------------------- |
260 | ||
c058cafa | 261 | extern WXDLLIMPEXP_ADV const wxEventType wxEVT_CALENDAR_SEL_CHANGED; |
628e155d VZ |
262 | extern WXDLLIMPEXP_ADV const wxEventType wxEVT_CALENDAR_PAGE_CHANGED; |
263 | extern WXDLLIMPEXP_ADV const wxEventType wxEVT_CALENDAR_DOUBLECLICKED; | |
264 | extern WXDLLIMPEXP_ADV const wxEventType wxEVT_CALENDAR_WEEKDAY_CLICKED; | |
265 | ||
266 | // deprecated events | |
c058cafa VZ |
267 | extern WXDLLIMPEXP_ADV const wxEventType wxEVT_CALENDAR_DAY_CHANGED; |
268 | extern WXDLLIMPEXP_ADV const wxEventType wxEVT_CALENDAR_MONTH_CHANGED; | |
269 | extern WXDLLIMPEXP_ADV const wxEventType wxEVT_CALENDAR_YEAR_CHANGED; | |
2e4df4bf | 270 | |
457e6c54 JS |
271 | typedef void (wxEvtHandler::*wxCalendarEventFunction)(wxCalendarEvent&); |
272 | ||
7fa03f04 | 273 | #define wxCalendarEventHandler(func) \ |
8bc3ec1f | 274 | (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxCalendarEventFunction, &func) |
7fa03f04 VZ |
275 | |
276 | #define wx__DECLARE_CALEVT(evt, id, fn) \ | |
277 | wx__DECLARE_EVT1(wxEVT_CALENDAR_ ## evt, id, wxCalendarEventHandler(fn)) | |
278 | ||
279 | #define EVT_CALENDAR(id, fn) wx__DECLARE_CALEVT(DOUBLECLICKED, id, fn) | |
280 | #define EVT_CALENDAR_SEL_CHANGED(id, fn) wx__DECLARE_CALEVT(SEL_CHANGED, id, fn) | |
628e155d VZ |
281 | #define EVT_CALENDAR_PAGE_CHANGED(id, fn) wx__DECLARE_CALEVT(PAGE_CHANGED, id, fn) |
282 | #define EVT_CALENDAR_WEEKDAY_CLICKED(id, fn) wx__DECLARE_CALEVT(WEEKDAY_CLICKED, id, fn) | |
283 | ||
284 | // deprecated events | |
7fa03f04 VZ |
285 | #define EVT_CALENDAR_DAY(id, fn) wx__DECLARE_CALEVT(DAY_CHANGED, id, fn) |
286 | #define EVT_CALENDAR_MONTH(id, fn) wx__DECLARE_CALEVT(MONTH_CHANGED, id, fn) | |
287 | #define EVT_CALENDAR_YEAR(id, fn) wx__DECLARE_CALEVT(YEAR_CHANGED, id, fn) | |
9d9b7755 | 288 | |
1e6feb95 VZ |
289 | #endif // wxUSE_CALENDARCTRL |
290 | ||
291 | #endif // _WX_CALCTRL_H_ | |
292 |