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