]>
Commit | Line | Data |
---|---|---|
1 | /////////////////////////////////////////////////////////////////////////////// | |
2 | // Name: wx/calctrl.h | |
3 | // Purpose: date-picker control | |
4 | // Author: Vadim Zeitlin | |
5 | // Modified by: | |
6 | // Created: 29.12.99 | |
7 | // Copyright: (c) 1999 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr> | |
8 | // Licence: wxWindows licence | |
9 | /////////////////////////////////////////////////////////////////////////////// | |
10 | ||
11 | #ifndef _WX_CALCTRL_H_ | |
12 | #define _WX_CALCTRL_H_ | |
13 | ||
14 | #include "wx/defs.h" | |
15 | ||
16 | #if wxUSE_CALENDARCTRL | |
17 | ||
18 | #include "wx/dateevt.h" | |
19 | #include "wx/colour.h" | |
20 | #include "wx/font.h" | |
21 | #include "wx/control.h" | |
22 | ||
23 | // ---------------------------------------------------------------------------- | |
24 | // wxCalendarCtrl flags | |
25 | // ---------------------------------------------------------------------------- | |
26 | ||
27 | enum | |
28 | { | |
29 | // show Sunday as the first day of the week (default) | |
30 | wxCAL_SUNDAY_FIRST = 0x0000, | |
31 | ||
32 | // show Monday as the first day of the week | |
33 | wxCAL_MONDAY_FIRST = 0x0001, | |
34 | ||
35 | // highlight holidays | |
36 | wxCAL_SHOW_HOLIDAYS = 0x0002, | |
37 | ||
38 | // disable the year change control, show only the month change one | |
39 | // deprecated | |
40 | wxCAL_NO_YEAR_CHANGE = 0x0004, | |
41 | ||
42 | // don't allow changing neither month nor year (implies | |
43 | // wxCAL_NO_YEAR_CHANGE) | |
44 | wxCAL_NO_MONTH_CHANGE = 0x000c, | |
45 | ||
46 | // use MS-style month-selection instead of combo-spin combination | |
47 | wxCAL_SEQUENTIAL_MONTH_SELECTION = 0x0010, | |
48 | ||
49 | // show the neighbouring weeks in the previous and next month | |
50 | wxCAL_SHOW_SURROUNDING_WEEKS = 0x0020, | |
51 | ||
52 | // show week numbers on the left side of the calendar. | |
53 | wxCAL_SHOW_WEEK_NUMBERS = 0x0040 | |
54 | }; | |
55 | ||
56 | // ---------------------------------------------------------------------------- | |
57 | // constants | |
58 | // ---------------------------------------------------------------------------- | |
59 | ||
60 | // return values for the HitTest() method | |
61 | enum wxCalendarHitTestResult | |
62 | { | |
63 | wxCAL_HITTEST_NOWHERE, // outside of anything | |
64 | wxCAL_HITTEST_HEADER, // on the header (weekdays) | |
65 | wxCAL_HITTEST_DAY, // on a day in the calendar | |
66 | wxCAL_HITTEST_INCMONTH, | |
67 | wxCAL_HITTEST_DECMONTH, | |
68 | wxCAL_HITTEST_SURROUNDING_WEEK, | |
69 | wxCAL_HITTEST_WEEK | |
70 | }; | |
71 | ||
72 | // border types for a date | |
73 | enum wxCalendarDateBorder | |
74 | { | |
75 | wxCAL_BORDER_NONE, // no border (default) | |
76 | wxCAL_BORDER_SQUARE, // a rectangular border | |
77 | wxCAL_BORDER_ROUND // a round border | |
78 | }; | |
79 | ||
80 | // ---------------------------------------------------------------------------- | |
81 | // wxCalendarDateAttr: custom attributes for a calendar date | |
82 | // ---------------------------------------------------------------------------- | |
83 | ||
84 | class WXDLLIMPEXP_ADV wxCalendarDateAttr | |
85 | { | |
86 | public: | |
87 | // ctors | |
88 | wxCalendarDateAttr(const wxColour& colText = wxNullColour, | |
89 | const wxColour& colBack = wxNullColour, | |
90 | const wxColour& colBorder = wxNullColour, | |
91 | const wxFont& font = wxNullFont, | |
92 | wxCalendarDateBorder border = wxCAL_BORDER_NONE) | |
93 | : m_colText(colText), m_colBack(colBack), | |
94 | m_colBorder(colBorder), m_font(font) | |
95 | { | |
96 | Init(border); | |
97 | } | |
98 | wxCalendarDateAttr(wxCalendarDateBorder border, | |
99 | const wxColour& colBorder = wxNullColour) | |
100 | : m_colBorder(colBorder) | |
101 | { | |
102 | Init(border); | |
103 | } | |
104 | ||
105 | // setters | |
106 | void SetTextColour(const wxColour& colText) { m_colText = colText; } | |
107 | void SetBackgroundColour(const wxColour& colBack) { m_colBack = colBack; } | |
108 | void SetBorderColour(const wxColour& col) { m_colBorder = col; } | |
109 | void SetFont(const wxFont& font) { m_font = font; } | |
110 | void SetBorder(wxCalendarDateBorder border) { m_border = border; } | |
111 | void SetHoliday(bool holiday) { m_holiday = holiday; } | |
112 | ||
113 | // accessors | |
114 | bool HasTextColour() const { return m_colText.IsOk(); } | |
115 | bool HasBackgroundColour() const { return m_colBack.IsOk(); } | |
116 | bool HasBorderColour() const { return m_colBorder.IsOk(); } | |
117 | bool HasFont() const { return m_font.IsOk(); } | |
118 | bool HasBorder() const { return m_border != wxCAL_BORDER_NONE; } | |
119 | ||
120 | bool IsHoliday() const { return m_holiday; } | |
121 | ||
122 | const wxColour& GetTextColour() const { return m_colText; } | |
123 | const wxColour& GetBackgroundColour() const { return m_colBack; } | |
124 | const wxColour& GetBorderColour() const { return m_colBorder; } | |
125 | const wxFont& GetFont() const { return m_font; } | |
126 | wxCalendarDateBorder GetBorder() const { return m_border; } | |
127 | ||
128 | // get or change the "mark" attribute, i.e. the one used for the items | |
129 | // marked with wxCalendarCtrl::Mark() | |
130 | static const wxCalendarDateAttr& GetMark() { return m_mark; } | |
131 | static void SetMark(wxCalendarDateAttr const& m) { m_mark = m; } | |
132 | ||
133 | protected: | |
134 | void Init(wxCalendarDateBorder border = wxCAL_BORDER_NONE) | |
135 | { | |
136 | m_border = border; | |
137 | m_holiday = false; | |
138 | } | |
139 | ||
140 | private: | |
141 | static wxCalendarDateAttr m_mark; | |
142 | ||
143 | wxColour m_colText, | |
144 | m_colBack, | |
145 | m_colBorder; | |
146 | wxFont m_font; | |
147 | wxCalendarDateBorder m_border; | |
148 | bool m_holiday; | |
149 | }; | |
150 | ||
151 | // ---------------------------------------------------------------------------- | |
152 | // wxCalendarCtrl events | |
153 | // ---------------------------------------------------------------------------- | |
154 | ||
155 | class WXDLLIMPEXP_FWD_ADV wxCalendarCtrl; | |
156 | ||
157 | class WXDLLIMPEXP_ADV wxCalendarEvent : public wxDateEvent | |
158 | { | |
159 | public: | |
160 | wxCalendarEvent() : m_wday(wxDateTime::Inv_WeekDay) { } | |
161 | wxCalendarEvent(wxWindow *win, const wxDateTime& dt, wxEventType type) | |
162 | : wxDateEvent(win, dt, type), | |
163 | m_wday(wxDateTime::Inv_WeekDay) { } | |
164 | wxCalendarEvent(const wxCalendarEvent& event) | |
165 | : wxDateEvent(event), m_wday(event.m_wday) { } | |
166 | ||
167 | void SetWeekDay(const wxDateTime::WeekDay wd) { m_wday = wd; } | |
168 | wxDateTime::WeekDay GetWeekDay() const { return m_wday; } | |
169 | ||
170 | virtual wxEvent *Clone() const { return new wxCalendarEvent(*this); } | |
171 | ||
172 | private: | |
173 | wxDateTime::WeekDay m_wday; | |
174 | ||
175 | DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxCalendarEvent) | |
176 | }; | |
177 | ||
178 | // ---------------------------------------------------------------------------- | |
179 | // wxCalendarCtrlBase | |
180 | // ---------------------------------------------------------------------------- | |
181 | ||
182 | class WXDLLIMPEXP_ADV wxCalendarCtrlBase : public wxControl | |
183 | { | |
184 | public: | |
185 | // do we allow changing the month/year? | |
186 | bool AllowMonthChange() const { return !HasFlag(wxCAL_NO_MONTH_CHANGE); } | |
187 | ||
188 | // get/set the current date | |
189 | virtual wxDateTime GetDate() const = 0; | |
190 | virtual bool SetDate(const wxDateTime& date) = 0; | |
191 | ||
192 | ||
193 | // restricting the dates shown by the control to the specified range: only | |
194 | // implemented in the generic and MSW versions for now | |
195 | ||
196 | // if either date is set, the corresponding limit will be enforced and true | |
197 | // returned; if none are set, the existing restrictions are removed and | |
198 | // false is returned | |
199 | virtual bool | |
200 | SetDateRange(const wxDateTime& WXUNUSED(lowerdate) = wxDefaultDateTime, | |
201 | const wxDateTime& WXUNUSED(upperdate) = wxDefaultDateTime) | |
202 | { | |
203 | return false; | |
204 | } | |
205 | ||
206 | // retrieves the limits currently in use (wxDefaultDateTime if none) in the | |
207 | // provided pointers (which may be NULL) and returns true if there are any | |
208 | // limits or false if none | |
209 | virtual bool | |
210 | GetDateRange(wxDateTime *lowerdate, wxDateTime *upperdate) const | |
211 | { | |
212 | if ( lowerdate ) | |
213 | *lowerdate = wxDefaultDateTime; | |
214 | if ( upperdate ) | |
215 | *upperdate = wxDefaultDateTime; | |
216 | return false; | |
217 | } | |
218 | ||
219 | // returns one of wxCAL_HITTEST_XXX constants and fills either date or wd | |
220 | // with the corresponding value (none for NOWHERE, the date for DAY and wd | |
221 | // for HEADER) | |
222 | // | |
223 | // notice that this is not implemented in all versions | |
224 | virtual wxCalendarHitTestResult | |
225 | HitTest(const wxPoint& WXUNUSED(pos), | |
226 | wxDateTime* WXUNUSED(date) = NULL, | |
227 | wxDateTime::WeekDay* WXUNUSED(wd) = NULL) | |
228 | { | |
229 | return wxCAL_HITTEST_NOWHERE; | |
230 | } | |
231 | ||
232 | // allow or disable changing the current month (and year), return true if | |
233 | // the value of this option really changed or false if it was already set | |
234 | // to the required value | |
235 | // | |
236 | // NB: we provide implementation for this pure virtual function, derived | |
237 | // classes should call it | |
238 | virtual bool EnableMonthChange(bool enable = true) = 0; | |
239 | ||
240 | ||
241 | // an item without custom attributes is drawn with the default colours and | |
242 | // font and without border, setting custom attributes allows to modify this | |
243 | // | |
244 | // the day parameter should be in 1..31 range, for days 29, 30, 31 the | |
245 | // corresponding attribute is just unused if there is no such day in the | |
246 | // current month | |
247 | // | |
248 | // notice that currently arbitrary attributes are supported only in the | |
249 | // generic version, the native controls only support Mark() which assigns | |
250 | // some special appearance (which can be customized using SetMark() for the | |
251 | // generic version) to the given day | |
252 | ||
253 | virtual void Mark(size_t day, bool mark) = 0; | |
254 | ||
255 | virtual wxCalendarDateAttr *GetAttr(size_t WXUNUSED(day)) const | |
256 | { return NULL; } | |
257 | virtual void SetAttr(size_t WXUNUSED(day), wxCalendarDateAttr *attr) | |
258 | { delete attr; } | |
259 | virtual void ResetAttr(size_t WXUNUSED(day)) { } | |
260 | ||
261 | ||
262 | // holidays support | |
263 | // | |
264 | // currently only the generic version implements all functions in this | |
265 | // section; wxMSW implements simple support for holidays (they can be | |
266 | // just enabled or disabled) and wxGTK doesn't support them at all | |
267 | ||
268 | // equivalent to changing wxCAL_SHOW_HOLIDAYS flag but should be called | |
269 | // instead of just changing it | |
270 | virtual void EnableHolidayDisplay(bool display = true); | |
271 | ||
272 | // set/get the colours to use for holidays (if they're enabled) | |
273 | virtual void SetHolidayColours(const wxColour& WXUNUSED(colFg), | |
274 | const wxColour& WXUNUSED(colBg)) { } | |
275 | ||
276 | virtual const wxColour& GetHolidayColourFg() const { return wxNullColour; } | |
277 | virtual const wxColour& GetHolidayColourBg() const { return wxNullColour; } | |
278 | ||
279 | // mark the given day of the current month as being a holiday | |
280 | virtual void SetHoliday(size_t WXUNUSED(day)) { } | |
281 | ||
282 | ||
283 | // customizing the colours of the controls | |
284 | // | |
285 | // most of the methods in this section are only implemented by the native | |
286 | // version of the control and do nothing in the native ones | |
287 | ||
288 | // set/get the colours to use for the display of the week day names at the | |
289 | // top of the controls | |
290 | virtual void SetHeaderColours(const wxColour& WXUNUSED(colFg), | |
291 | const wxColour& WXUNUSED(colBg)) { } | |
292 | ||
293 | virtual const wxColour& GetHeaderColourFg() const { return wxNullColour; } | |
294 | virtual const wxColour& GetHeaderColourBg() const { return wxNullColour; } | |
295 | ||
296 | // set/get the colours used for the currently selected date | |
297 | virtual void SetHighlightColours(const wxColour& WXUNUSED(colFg), | |
298 | const wxColour& WXUNUSED(colBg)) { } | |
299 | ||
300 | virtual const wxColour& GetHighlightColourFg() const { return wxNullColour; } | |
301 | virtual const wxColour& GetHighlightColourBg() const { return wxNullColour; } | |
302 | ||
303 | ||
304 | // implementation only from now on | |
305 | ||
306 | // generate the given calendar event, return true if it was processed | |
307 | // | |
308 | // NB: this is public because it's used from GTK+ callbacks | |
309 | bool GenerateEvent(wxEventType type) | |
310 | { | |
311 | wxCalendarEvent event(this, GetDate(), type); | |
312 | return HandleWindowEvent(event); | |
313 | } | |
314 | ||
315 | protected: | |
316 | // generate all the events for the selection change from dateOld to current | |
317 | // date: SEL_CHANGED, PAGE_CHANGED if necessary and also one of (deprecated) | |
318 | // YEAR/MONTH/DAY_CHANGED ones | |
319 | // | |
320 | // returns true if page changed event was generated, false if the new date | |
321 | // is still in the same month as before | |
322 | bool GenerateAllChangeEvents(const wxDateTime& dateOld); | |
323 | ||
324 | // call SetHoliday() for all holidays in the current month | |
325 | // | |
326 | // should be called on month change, does nothing if wxCAL_SHOW_HOLIDAYS is | |
327 | // not set and returns false in this case, true if we do show them | |
328 | bool SetHolidayAttrs(); | |
329 | ||
330 | // called by SetHolidayAttrs() to forget the previously set holidays | |
331 | virtual void ResetHolidayAttrs() { } | |
332 | ||
333 | // called by EnableHolidayDisplay() | |
334 | virtual void RefreshHolidays() { } | |
335 | }; | |
336 | ||
337 | // ---------------------------------------------------------------------------- | |
338 | // wxCalendarCtrl | |
339 | // ---------------------------------------------------------------------------- | |
340 | ||
341 | #define wxCalendarNameStr "CalendarCtrl" | |
342 | ||
343 | #ifndef __WXUNIVERSAL__ | |
344 | #if defined(__WXGTK20__) | |
345 | #define wxHAS_NATIVE_CALENDARCTRL | |
346 | #include "wx/gtk/calctrl.h" | |
347 | #define wxCalendarCtrl wxGtkCalendarCtrl | |
348 | #elif defined(__WXMSW__) | |
349 | #define wxHAS_NATIVE_CALENDARCTRL | |
350 | #include "wx/msw/calctrl.h" | |
351 | #endif | |
352 | #endif // !__WXUNIVERSAL__ | |
353 | ||
354 | #ifndef wxHAS_NATIVE_CALENDARCTRL | |
355 | #include "wx/generic/calctrlg.h" | |
356 | #define wxCalendarCtrl wxGenericCalendarCtrl | |
357 | #endif | |
358 | ||
359 | // ---------------------------------------------------------------------------- | |
360 | // calendar event types and macros for handling them | |
361 | // ---------------------------------------------------------------------------- | |
362 | ||
363 | wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_CALENDAR_SEL_CHANGED, wxCalendarEvent ); | |
364 | wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_CALENDAR_PAGE_CHANGED, wxCalendarEvent ); | |
365 | wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_CALENDAR_DOUBLECLICKED, wxCalendarEvent ); | |
366 | wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_CALENDAR_WEEKDAY_CLICKED, wxCalendarEvent ); | |
367 | wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_CALENDAR_WEEK_CLICKED, wxCalendarEvent ); | |
368 | ||
369 | // deprecated events | |
370 | wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_CALENDAR_DAY_CHANGED, wxCalendarEvent ); | |
371 | wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_CALENDAR_MONTH_CHANGED, wxCalendarEvent ); | |
372 | wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_CALENDAR_YEAR_CHANGED, wxCalendarEvent ); | |
373 | ||
374 | typedef void (wxEvtHandler::*wxCalendarEventFunction)(wxCalendarEvent&); | |
375 | ||
376 | #define wxCalendarEventHandler(func) \ | |
377 | wxEVENT_HANDLER_CAST(wxCalendarEventFunction, func) | |
378 | ||
379 | #define wx__DECLARE_CALEVT(evt, id, fn) \ | |
380 | wx__DECLARE_EVT1(wxEVT_CALENDAR_ ## evt, id, wxCalendarEventHandler(fn)) | |
381 | ||
382 | #define EVT_CALENDAR(id, fn) wx__DECLARE_CALEVT(DOUBLECLICKED, id, fn) | |
383 | #define EVT_CALENDAR_SEL_CHANGED(id, fn) wx__DECLARE_CALEVT(SEL_CHANGED, id, fn) | |
384 | #define EVT_CALENDAR_PAGE_CHANGED(id, fn) wx__DECLARE_CALEVT(PAGE_CHANGED, id, fn) | |
385 | #define EVT_CALENDAR_WEEKDAY_CLICKED(id, fn) wx__DECLARE_CALEVT(WEEKDAY_CLICKED, id, fn) | |
386 | #define EVT_CALENDAR_WEEK_CLICKED(id, fn) wx__DECLARE_CALEVT(WEEK_CLICKED, id, fn) | |
387 | ||
388 | // deprecated events | |
389 | #define EVT_CALENDAR_DAY(id, fn) wx__DECLARE_CALEVT(DAY_CHANGED, id, fn) | |
390 | #define EVT_CALENDAR_MONTH(id, fn) wx__DECLARE_CALEVT(MONTH_CHANGED, id, fn) | |
391 | #define EVT_CALENDAR_YEAR(id, fn) wx__DECLARE_CALEVT(YEAR_CHANGED, id, fn) | |
392 | ||
393 | #endif // wxUSE_CALENDARCTRL | |
394 | ||
395 | #endif // _WX_CALCTRL_H_ | |
396 |