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