1 ///////////////////////////////////////////////////////////////////////////////
3 // Purpose: date-picker control
4 // Author: Vadim Zeitlin
8 // Copyright: (c) 1999 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
15 1. implement multiple selections for date ranges
16 2. background bitmap for the calendar?
19 #ifndef _WX_CALCTRL_H_
20 #define _WX_CALCTRL_H_
24 #if wxUSE_CALENDARCTRL
26 #include "wx/dateevt.h"
27 #include "wx/colour.h"
30 // ----------------------------------------------------------------------------
31 // wxCalendarCtrl flags
32 // ----------------------------------------------------------------------------
36 // show Sunday as the first day of the week (default)
37 wxCAL_SUNDAY_FIRST
= 0x0000,
39 // show Monder as the first day of the week
40 wxCAL_MONDAY_FIRST
= 0x0001,
43 wxCAL_SHOW_HOLIDAYS
= 0x0002,
45 // disable the year change control, show only the month change one
46 wxCAL_NO_YEAR_CHANGE
= 0x0004,
48 // don't allow changing neither month nor year (implies
49 // wxCAL_NO_YEAR_CHANGE)
50 wxCAL_NO_MONTH_CHANGE
= 0x000c,
52 // use MS-style month-selection instead of combo-spin combination
53 wxCAL_SEQUENTIAL_MONTH_SELECTION
= 0x0010,
55 // show the neighbouring weeks in the previous and next month
56 wxCAL_SHOW_SURROUNDING_WEEKS
= 0x0020
59 // ----------------------------------------------------------------------------
61 // ----------------------------------------------------------------------------
63 // return values for the HitTest() method
64 enum wxCalendarHitTestResult
66 wxCAL_HITTEST_NOWHERE
, // outside of anything
67 wxCAL_HITTEST_HEADER
, // on the header (weekdays)
68 wxCAL_HITTEST_DAY
, // on a day in the calendar
69 wxCAL_HITTEST_INCMONTH
,
70 wxCAL_HITTEST_DECMONTH
,
71 wxCAL_HITTEST_SURROUNDING_WEEK
74 // border types for a date
75 enum wxCalendarDateBorder
77 wxCAL_BORDER_NONE
, // no border (default)
78 wxCAL_BORDER_SQUARE
, // a rectangular border
79 wxCAL_BORDER_ROUND
// a round border
82 // ----------------------------------------------------------------------------
83 // wxCalendarDateAttr: custom attributes for a calendar date
84 // ----------------------------------------------------------------------------
86 class WXDLLIMPEXP_ADV wxCalendarDateAttr
88 #if !defined(__VISAGECPP__)
90 // This has to be before the use of Init(), for MSVC++ 1.5
91 // But dorks up Visualage!
92 void Init(wxCalendarDateBorder border
= wxCAL_BORDER_NONE
)
100 wxCalendarDateAttr() { Init(); }
101 wxCalendarDateAttr(const wxColour
& colText
,
102 const wxColour
& colBack
= wxNullColour
,
103 const wxColour
& colBorder
= wxNullColour
,
104 const wxFont
& font
= wxNullFont
,
105 wxCalendarDateBorder border
= wxCAL_BORDER_NONE
)
106 : m_colText(colText
), m_colBack(colBack
),
107 m_colBorder(colBorder
), m_font(font
)
111 wxCalendarDateAttr(wxCalendarDateBorder border
,
112 const wxColour
& colBorder
= wxNullColour
)
113 : m_colBorder(colBorder
)
119 void SetTextColour(const wxColour
& colText
) { m_colText
= colText
; }
120 void SetBackgroundColour(const wxColour
& colBack
) { m_colBack
= colBack
; }
121 void SetBorderColour(const wxColour
& col
) { m_colBorder
= col
; }
122 void SetFont(const wxFont
& font
) { m_font
= font
; }
123 void SetBorder(wxCalendarDateBorder border
) { m_border
= border
; }
124 void SetHoliday(bool holiday
) { m_holiday
= holiday
; }
127 bool HasTextColour() const { return m_colText
.Ok(); }
128 bool HasBackgroundColour() const { return m_colBack
.Ok(); }
129 bool HasBorderColour() const { return m_colBorder
.Ok(); }
130 bool HasFont() const { return m_font
.Ok(); }
131 bool HasBorder() const { return m_border
!= wxCAL_BORDER_NONE
; }
133 bool IsHoliday() const { return m_holiday
; }
135 const wxColour
& GetTextColour() const { return m_colText
; }
136 const wxColour
& GetBackgroundColour() const { return m_colBack
; }
137 const wxColour
& GetBorderColour() const { return m_colBorder
; }
138 const wxFont
& GetFont() const { return m_font
; }
139 wxCalendarDateBorder
GetBorder() const { return m_border
; }
140 #if defined(__VISAGECPP__)
142 // This has to be here for VisualAge
143 void Init(wxCalendarDateBorder border
= wxCAL_BORDER_NONE
)
154 wxCalendarDateBorder m_border
;
158 // ----------------------------------------------------------------------------
159 // wxCalendarCtrl events
160 // ----------------------------------------------------------------------------
162 class WXDLLIMPEXP_ADV wxCalendarCtrl
;
164 class WXDLLIMPEXP_ADV wxCalendarEvent
: public wxDateEvent
166 friend class wxCalendarCtrl
;
168 wxCalendarEvent() { Init(); }
169 wxCalendarEvent(wxCalendarCtrl
*cal
, wxEventType type
);
171 void SetWeekDay(const wxDateTime::WeekDay wd
) { m_wday
= wd
; }
172 wxDateTime::WeekDay
GetWeekDay() const { return m_wday
; }
177 m_wday
= wxDateTime::Inv_WeekDay
;
181 wxDateTime::WeekDay m_wday
;
183 DECLARE_DYNAMIC_CLASS_NO_COPY(wxCalendarEvent
)
186 // ----------------------------------------------------------------------------
188 // ----------------------------------------------------------------------------
190 // so far we only have a generic version, so keep it simple
191 #include "wx/generic/calctrl.h"
194 // now we can define the inline ctor using wxCalendarCtrl
196 wxCalendarEvent::wxCalendarEvent(wxCalendarCtrl
*cal
, wxEventType type
)
197 : wxDateEvent(cal
, cal
->GetDate(), type
)
201 // ----------------------------------------------------------------------------
202 // calendar event types and macros for handling them
203 // ----------------------------------------------------------------------------
205 BEGIN_DECLARE_EVENT_TYPES()
206 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV
, wxEVT_CALENDAR_SEL_CHANGED
, 950)
207 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV
, wxEVT_CALENDAR_DAY_CHANGED
, 951)
208 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV
, wxEVT_CALENDAR_MONTH_CHANGED
, 952)
209 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV
, wxEVT_CALENDAR_YEAR_CHANGED
, 953)
210 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV
, wxEVT_CALENDAR_DOUBLECLICKED
, 954)
211 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV
, wxEVT_CALENDAR_WEEKDAY_CLICKED
, 955)
212 END_DECLARE_EVENT_TYPES()
214 typedef void (wxEvtHandler::*wxCalendarEventFunction
)(wxCalendarEvent
&);
216 #define wxCalendarEventHandler(func) \
217 (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxCalendarEventFunction, &func)
219 #define wx__DECLARE_CALEVT(evt, id, fn) \
220 wx__DECLARE_EVT1(wxEVT_CALENDAR_ ## evt, id, wxCalendarEventHandler(fn))
222 #define EVT_CALENDAR(id, fn) wx__DECLARE_CALEVT(DOUBLECLICKED, id, fn)
223 #define EVT_CALENDAR_SEL_CHANGED(id, fn) wx__DECLARE_CALEVT(SEL_CHANGED, id, fn)
224 #define EVT_CALENDAR_DAY(id, fn) wx__DECLARE_CALEVT(DAY_CHANGED, id, fn)
225 #define EVT_CALENDAR_MONTH(id, fn) wx__DECLARE_CALEVT(MONTH_CHANGED, id, fn)
226 #define EVT_CALENDAR_YEAR(id, fn) wx__DECLARE_CALEVT(YEAR_CHANGED, id, fn)
227 #define EVT_CALENDAR_WEEKDAY_CLICKED(id, fn) wx__DECLARE_CALEVT(WEEKDAY_CLICKED, id, fn)
229 #endif // wxUSE_CALENDARCTRL
231 #endif // _WX_CALCTRL_H_