]> git.saurik.com Git - wxWidgets.git/blob - include/wx/calctrl.h
By default, align renderers as column header under GTK+, too.
[wxWidgets.git] / include / wx / calctrl.h
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>
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_CALCTRL_H_
13 #define _WX_CALCTRL_H_
14
15 #include "wx/defs.h"
16
17 #if wxUSE_CALENDARCTRL
18
19 #include "wx/dateevt.h"
20 #include "wx/colour.h"
21 #include "wx/font.h"
22 #include "wx/control.h"
23
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
40 // deprecated
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
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)
63 wxCAL_HITTEST_DAY, // on a day in the calendar
64 wxCAL_HITTEST_INCMONTH,
65 wxCAL_HITTEST_DECMONTH,
66 wxCAL_HITTEST_SURROUNDING_WEEK
67 };
68
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
77 // ----------------------------------------------------------------------------
78 // wxCalendarDateAttr: custom attributes for a calendar date
79 // ----------------------------------------------------------------------------
80
81 class WXDLLIMPEXP_ADV wxCalendarDateAttr
82 {
83 public:
84 // ctors
85 wxCalendarDateAttr(const wxColour& colText = wxNullColour,
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; }
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
130 protected:
131 void Init(wxCalendarDateBorder border = wxCAL_BORDER_NONE)
132 {
133 m_border = border;
134 m_holiday = false;
135 }
136
137 private:
138 static wxCalendarDateAttr m_mark;
139
140 wxColour m_colText,
141 m_colBack,
142 m_colBorder;
143 wxFont m_font;
144 wxCalendarDateBorder m_border;
145 bool m_holiday;
146 };
147
148 // ----------------------------------------------------------------------------
149 // wxCalendarCtrl events
150 // ----------------------------------------------------------------------------
151
152 class WXDLLIMPEXP_FWD_ADV wxCalendarCtrl;
153
154 class WXDLLIMPEXP_ADV wxCalendarEvent : public wxDateEvent
155 {
156 public:
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 }
163
164 void SetWeekDay(const wxDateTime::WeekDay wd) { m_wday = wd; }
165 wxDateTime::WeekDay GetWeekDay() const { return m_wday; }
166
167 private:
168 wxDateTime::WeekDay m_wday;
169
170 DECLARE_DYNAMIC_CLASS_NO_COPY(wxCalendarEvent)
171 };
172
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 // restricting the dates shown by the control to the specified range: only
189 // implemented in the generic and MSW versions for now
190
191 // if either date is set, the corresponding limit will be enforced and true
192 // returned; if none are set, the existing restrictions are removed and
193 // false is returned
194 virtual bool
195 SetDateRange(const wxDateTime& WXUNUSED(lowerdate) = wxDefaultDateTime,
196 const wxDateTime& WXUNUSED(upperdate) = wxDefaultDateTime)
197 {
198 return false;
199 }
200
201 // retrieves the limits currently in use (wxDefaultDateTime if none) in the
202 // provided pointers (which may be NULL) and returns true if there are any
203 // limits or false if none
204 virtual bool
205 GetDateRange(wxDateTime *lowerdate, wxDateTime *upperdate) const
206 {
207 if ( lowerdate )
208 *lowerdate = wxDefaultDateTime;
209 if ( upperdate )
210 *upperdate = wxDefaultDateTime;
211 return false;
212 }
213
214 // returns one of wxCAL_HITTEST_XXX constants and fills either date or wd
215 // with the corresponding value (none for NOWHERE, the date for DAY and wd
216 // for HEADER)
217 //
218 // notice that this is not implemented in all versions
219 virtual wxCalendarHitTestResult
220 HitTest(const wxPoint& WXUNUSED(pos),
221 wxDateTime* WXUNUSED(date) = NULL,
222 wxDateTime::WeekDay* WXUNUSED(wd) = NULL)
223 {
224 return wxCAL_HITTEST_NOWHERE;
225 }
226
227 // allow or disable changing the current month (and year), return true if
228 // the value of this option really changed or false if it was already set
229 // to the required value
230 //
231 // NB: we provide implementation for this pure virtual function, derived
232 // classes should call it
233 virtual bool EnableMonthChange(bool enable) = 0;
234
235
236 // an item without custom attributes is drawn with the default colours and
237 // font and without border, setting custom attributes allows to modify this
238 //
239 // the day parameter should be in 1..31 range, for days 29, 30, 31 the
240 // corresponding attribute is just unused if there is no such day in the
241 // current month
242 //
243 // notice that currently arbitrary attributes are supported only in the
244 // generic version, the native controls only support Mark() which assigns
245 // some special appearance (which can be customized using SetMark() for the
246 // generic version) to the given day
247
248 virtual void Mark(size_t day, bool mark) = 0;
249
250 virtual wxCalendarDateAttr *GetAttr(size_t WXUNUSED(day)) const
251 { return NULL; }
252 virtual void SetAttr(size_t WXUNUSED(day), wxCalendarDateAttr *attr)
253 { delete attr; }
254 virtual void ResetAttr(size_t WXUNUSED(day)) { }
255
256
257 // holidays support
258 //
259 // currently all functions in this section are implemented in the generic
260 // version of the control only and are simply ignored by native ones
261
262 // equivalent to changing wxCAL_SHOW_HOLIDAYS flag but should be called
263 // instead of just changing it
264 virtual void EnableHolidayDisplay(bool WXUNUSED(display) = true) { }
265
266 // set/get the colours to use for holidays (if they're enabled)
267 virtual void SetHolidayColours(const wxColour& WXUNUSED(colFg),
268 const wxColour& WXUNUSED(colBg)) { }
269
270 virtual const wxColour& GetHolidayColourFg() const { return wxNullColour; }
271 virtual const wxColour& GetHolidayColourBg() const { return wxNullColour; }
272
273 // mark the given day of the current month as being a holiday
274 virtual void SetHoliday(size_t WXUNUSED(day)) { }
275
276
277 // customizing the colours of the controls
278 //
279 // most of the methods in this section are only implemented by the native
280 // version of the control and do nothing in the native ones
281
282 // set/get the colours to use for the display of the week day names at the
283 // top of the controls
284 virtual void SetHeaderColours(const wxColour& WXUNUSED(colFg),
285 const wxColour& WXUNUSED(colBg)) { }
286
287 virtual const wxColour& GetHeaderColourFg() const { return wxNullColour; }
288 virtual const wxColour& GetHeaderColourBg() const { return wxNullColour; }
289
290 // set/get the colours used for the currently selected date
291 virtual void SetHighlightColours(const wxColour& WXUNUSED(colFg),
292 const wxColour& WXUNUSED(colBg)) { }
293
294 virtual const wxColour& GetHighlightColourFg() const { return wxNullColour; }
295 virtual const wxColour& GetHighlightColourBg() const { return wxNullColour; }
296
297
298 // implementation only from now on
299
300 // generate the given calendar event, return true if it was processed
301 //
302 // NB: this is public because it's used from GTK+ callbacks
303 bool GenerateEvent(wxEventType type)
304 {
305 wxCalendarEvent event(this, GetDate(), type);
306 return HandleWindowEvent(event);
307 }
308
309 protected:
310 // generate all the events for the selection change from dateOld to current
311 // date: SEL_CHANGED, PAGE_CHANGED if necessary and also one of (deprecated)
312 // YEAR/MONTH/DAY_CHANGED ones
313 void GenerateAllChangeEvents(const wxDateTime& dateOld);
314 };
315
316 // ----------------------------------------------------------------------------
317 // wxCalendarCtrl
318 // ----------------------------------------------------------------------------
319
320 #define wxCalendarNameStr "CalendarCtrl"
321
322 #ifndef __WXUNIVERSAL__
323 #if defined(__WXGTK20__)
324 #define wxHAS_NATIVE_CALENDARCTRL
325 #include "wx/gtk/calctrl.h"
326 #define wxCalendarCtrl wxGtkCalendarCtrl
327 #elif defined(__WXMSW__)
328 #define wxHAS_NATIVE_CALENDARCTRL
329 #include "wx/msw/calctrl.h"
330 #endif
331 #endif // !__WXUNIVERSAL__
332
333 #ifndef wxHAS_NATIVE_CALENDARCTRL
334 #include "wx/generic/calctrlg.h"
335 #define wxCalendarCtrl wxGenericCalendarCtrl
336 #endif
337
338 // ----------------------------------------------------------------------------
339 // calendar event types and macros for handling them
340 // ----------------------------------------------------------------------------
341
342 extern WXDLLIMPEXP_ADV const wxEventType wxEVT_CALENDAR_SEL_CHANGED;
343 extern WXDLLIMPEXP_ADV const wxEventType wxEVT_CALENDAR_PAGE_CHANGED;
344 extern WXDLLIMPEXP_ADV const wxEventType wxEVT_CALENDAR_DOUBLECLICKED;
345 extern WXDLLIMPEXP_ADV const wxEventType wxEVT_CALENDAR_WEEKDAY_CLICKED;
346
347 // deprecated events
348 extern WXDLLIMPEXP_ADV const wxEventType wxEVT_CALENDAR_DAY_CHANGED;
349 extern WXDLLIMPEXP_ADV const wxEventType wxEVT_CALENDAR_MONTH_CHANGED;
350 extern WXDLLIMPEXP_ADV const wxEventType wxEVT_CALENDAR_YEAR_CHANGED;
351
352 typedef void (wxEvtHandler::*wxCalendarEventFunction)(wxCalendarEvent&);
353
354 #define wxCalendarEventHandler(func) \
355 (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxCalendarEventFunction, &func)
356
357 #define wx__DECLARE_CALEVT(evt, id, fn) \
358 wx__DECLARE_EVT1(wxEVT_CALENDAR_ ## evt, id, wxCalendarEventHandler(fn))
359
360 #define EVT_CALENDAR(id, fn) wx__DECLARE_CALEVT(DOUBLECLICKED, id, fn)
361 #define EVT_CALENDAR_SEL_CHANGED(id, fn) wx__DECLARE_CALEVT(SEL_CHANGED, id, fn)
362 #define EVT_CALENDAR_PAGE_CHANGED(id, fn) wx__DECLARE_CALEVT(PAGE_CHANGED, id, fn)
363 #define EVT_CALENDAR_WEEKDAY_CLICKED(id, fn) wx__DECLARE_CALEVT(WEEKDAY_CLICKED, id, fn)
364
365 // deprecated events
366 #define EVT_CALENDAR_DAY(id, fn) wx__DECLARE_CALEVT(DAY_CHANGED, id, fn)
367 #define EVT_CALENDAR_MONTH(id, fn) wx__DECLARE_CALEVT(MONTH_CHANGED, id, fn)
368 #define EVT_CALENDAR_YEAR(id, fn) wx__DECLARE_CALEVT(YEAR_CHANGED, id, fn)
369
370 #endif // wxUSE_CALENDARCTRL
371
372 #endif // _WX_CALCTRL_H_
373