1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: generic/calctrl.h
3 // Purpose: generic implementation of date-picker control
4 // Author: Vadim Zeitlin
8 // Copyright: (c) 1999 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
9 // Licence: wxWindows license
10 ///////////////////////////////////////////////////////////////////////////////
13 #pragma interface "calctrl.h"
16 #ifndef _WX_GENERIC_CALCTRL_H
17 #define _WX_GENERIC_CALCTRL_H
19 #include "wx/control.h" // the base class
21 #include "wx/spinctrl.h" // for wxSpinEvent
23 class WXDLLEXPORT wxComboBox
;
25 #define wxCalendarNameStr _T("CalendarCtrl")
27 // ----------------------------------------------------------------------------
28 // wxCalendarCtrl: a control allowing the user to pick a date interactively
29 // ----------------------------------------------------------------------------
31 class WXDLLEXPORT wxCalendarCtrl
: public wxControl
33 friend class wxMonthComboBox
;
34 friend class wxYearSpinCtrl
;
38 wxCalendarCtrl() { Init(); }
39 wxCalendarCtrl(wxWindow
*parent
,
41 const wxDateTime
& date
= wxDefaultDateTime
,
42 const wxPoint
& pos
= wxDefaultPosition
,
43 const wxSize
& size
= wxDefaultSize
,
44 long style
= wxCAL_SHOW_HOLIDAYS
,
45 const wxString
& name
= wxCalendarNameStr
)
46 : wxControl(parent
, id
, pos
, size
,
47 style
| wxWANTS_CHARS
, wxDefaultValidator
, name
)
51 (void)Create(parent
, id
, date
, pos
, size
, style
, name
);
54 bool Create(wxWindow
*parent
,
56 const wxDateTime
& date
= wxDefaultDateTime
,
57 const wxPoint
& pos
= wxDefaultPosition
,
58 const wxSize
& size
= wxDefaultSize
,
59 long style
= wxCAL_SHOW_HOLIDAYS
,
60 const wxString
& name
= wxCalendarNameStr
);
62 virtual ~wxCalendarCtrl();
64 // set/get the current date
65 // ------------------------
67 void SetDate(const wxDateTime
& date
);
68 const wxDateTime
& GetDate() const { return m_date
; }
73 // header colours are used for painting the weekdays at the top
74 void SetHeaderColours(const wxColour
& colFg
, const wxColour
& colBg
)
76 m_colHeaderFg
= colFg
;
77 m_colHeaderBg
= colBg
;
80 const wxColour
& GetHeaderColourFg() const { return m_colHeaderFg
; }
81 const wxColour
& GetHeaderColourBg() const { return m_colHeaderBg
; }
83 // highlight colour is used for the currently selected date
84 void SetHighlightColours(const wxColour
& colFg
, const wxColour
& colBg
)
86 m_colHighlightFg
= colFg
;
87 m_colHighlightBg
= colBg
;
90 const wxColour
& GetHighlightColourFg() const { return m_colHighlightFg
; }
91 const wxColour
& GetHighlightColourBg() const { return m_colHighlightBg
; }
93 // holiday colour is used for the holidays (if style & wxCAL_SHOW_HOLIDAYS)
94 void SetHolidayColours(const wxColour
& colFg
, const wxColour
& colBg
)
96 m_colHolidayFg
= colFg
;
97 m_colHolidayBg
= colBg
;
100 const wxColour
& GetHolidayColourFg() const { return m_colHolidayFg
; }
101 const wxColour
& GetHolidayColourBg() const { return m_colHolidayBg
; }
103 // this function should be called instead of directly changing the
104 // wxCAL_SHOW_HOLIDAYS bit in the control style after the control creation
106 void EnableHolidayDisplay(bool display
= TRUE
);
108 // an item without custom attributes is drawn with the default colours and
109 // font and without border, setting custom attributes allows to modify this
111 // the day parameter should be in 1..31 range, for days 29, 30, 31 the
112 // corresponding attribute is just unused if there is no such day in the
115 wxCalendarDateAttr
*GetAttr(size_t day
) const
117 wxCHECK_MSG( day
> 0 && day
< 32, NULL
, _T("invalid day") );
119 return m_attrs
[day
- 1];
122 void SetAttr(size_t day
, wxCalendarDateAttr
*attr
)
124 wxCHECK_RET( day
> 0 && day
< 32, _T("invalid day") );
126 delete m_attrs
[day
- 1];
127 m_attrs
[day
- 1] = attr
;
130 void SetHoliday(size_t day
);
132 void ResetAttr(size_t day
) { SetAttr(day
, (wxCalendarDateAttr
*)NULL
); }
134 // returns one of wxCAL_HITTEST_XXX constants and fills either date or wd
135 // with the corresponding value (none for NOWHERE, the date for DAY and wd
137 wxCalendarHitTestResult
HitTest(const wxPoint
& pos
,
138 wxDateTime
*date
= NULL
,
139 wxDateTime::WeekDay
*wd
= NULL
);
141 // implementation only from now on
142 // -------------------------------
144 // forward these functions to all subcontrols
145 virtual bool Enable(bool enable
= TRUE
);
146 virtual bool Show(bool show
= TRUE
);
149 // common part of all ctors
153 void OnPaint(wxPaintEvent
& event
);
154 void OnClick(wxMouseEvent
& event
);
155 void OnDClick(wxMouseEvent
& event
);
156 void OnChar(wxKeyEvent
& event
);
157 void OnMonthChange(wxCommandEvent
& event
);
158 void OnYearChange(wxSpinEvent
& event
);
159 void OnCalMonthChange(wxCalendarEvent
& event
);
161 // override some base class virtuals
162 virtual wxSize
DoGetBestSize() const;
163 virtual void DoGetPosition(int *x
, int *y
) const;
164 virtual void DoGetSize(int *width
, int *height
) const;
165 virtual void DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
);
166 virtual void DoMoveWindow(int x
, int y
, int width
, int height
);
168 // (re)calc m_widthCol and m_heightRow
169 void RecalcGeometry();
171 // set the date and send the notification
172 void SetDateAndNotify(const wxDateTime
& date
);
174 // get the week (row, in range 1..6) for the given date
175 size_t GetWeek(const wxDateTime
& date
) const;
177 // get the date from which we start drawing days
178 wxDateTime
GetStartDate() const;
180 // is this date shown?
181 bool IsDateShown(const wxDateTime
& date
) const;
183 // redraw the given date
184 void RefreshDate(const wxDateTime
& date
);
186 // change the date inside the same month/year
187 void ChangeDay(const wxDateTime
& date
);
189 // set the attributes for the holidays if needed
190 void SetHolidayAttrs();
192 // reset all holidays
193 void ResetHolidayAttrs();
195 // generate the given calendar event(s)
196 void GenerateEvent(wxEventType type
)
198 wxCalendarEvent
event(this, type
);
199 (void)GetEventHandler()->ProcessEvent(event
);
202 void GenerateEvents(wxEventType type1
, wxEventType type2
)
204 GenerateEvent(type1
);
205 GenerateEvent(type2
);
209 wxComboBox
*m_comboMonth
;
210 wxSpinCtrl
*m_spinYear
;
212 // the current selection
215 // default attributes
216 wxColour m_colHighlightFg
,
223 // the attributes for each of the month days
224 wxCalendarDateAttr
*m_attrs
[31];
226 // the width and height of one column/row in the calendar
230 // the week day names
231 wxString m_weekdays
[7];
233 DECLARE_DYNAMIC_CLASS(wxCalendarCtrl
)
234 DECLARE_EVENT_TABLE()
237 #endif // _WX_GENERIC_CALCTRL_H