]>
Commit | Line | Data |
---|---|---|
2ef31e80 VZ |
1 | /////////////////////////////////////////////////////////////////////////////// |
2 | // Name: generic/calctrl.h | |
3 | // Purpose: generic implementation of 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 license | |
10 | /////////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #ifdef __GNUG__ | |
13 | #pragma interface "calctrl.h" | |
14 | #endif | |
15 | ||
16 | #ifndef _WX_GENERIC_CALCTRL_H | |
17 | #define _WX_GENERIC_CALCTRL_H | |
18 | ||
19 | #include "wx/control.h" // the base class | |
20 | ||
4f6aed9c VZ |
21 | #include "wx/spinctrl.h" // for wxSpinEvent |
22 | ||
23 | class WXDLLEXPORT wxComboBox; | |
bc385ba9 | 24 | class WXDLLEXPORT wxStaticText; |
2ef31e80 VZ |
25 | |
26 | #define wxCalendarNameStr _T("CalendarCtrl") | |
27 | ||
28 | // ---------------------------------------------------------------------------- | |
29 | // wxCalendarCtrl: a control allowing the user to pick a date interactively | |
30 | // ---------------------------------------------------------------------------- | |
31 | ||
32 | class WXDLLEXPORT wxCalendarCtrl : public wxControl | |
33 | { | |
0185cd09 VZ |
34 | friend class wxMonthComboBox; |
35 | friend class wxYearSpinCtrl; | |
36 | ||
2ef31e80 VZ |
37 | public: |
38 | // construction | |
39 | wxCalendarCtrl() { Init(); } | |
40 | wxCalendarCtrl(wxWindow *parent, | |
41 | wxWindowID id, | |
42 | const wxDateTime& date = wxDefaultDateTime, | |
43 | const wxPoint& pos = wxDefaultPosition, | |
44 | const wxSize& size = wxDefaultSize, | |
4965c3d7 | 45 | long style = wxCAL_SHOW_HOLIDAYS | wxWANTS_CHARS, |
2ef31e80 | 46 | const wxString& name = wxCalendarNameStr) |
2ef31e80 VZ |
47 | { |
48 | Init(); | |
49 | ||
50 | (void)Create(parent, id, date, pos, size, style, name); | |
51 | } | |
52 | ||
53 | bool Create(wxWindow *parent, | |
54 | wxWindowID id, | |
55 | const wxDateTime& date = wxDefaultDateTime, | |
56 | const wxPoint& pos = wxDefaultPosition, | |
57 | const wxSize& size = wxDefaultSize, | |
4965c3d7 | 58 | long style = wxCAL_SHOW_HOLIDAYS | wxWANTS_CHARS, |
2ef31e80 VZ |
59 | const wxString& name = wxCalendarNameStr); |
60 | ||
882a8f40 VZ |
61 | virtual ~wxCalendarCtrl(); |
62 | ||
2ef31e80 | 63 | // set/get the current date |
4f6aed9c VZ |
64 | // ------------------------ |
65 | ||
2ef31e80 VZ |
66 | void SetDate(const wxDateTime& date); |
67 | const wxDateTime& GetDate() const { return m_date; } | |
68 | ||
bc385ba9 VZ |
69 | // calendar mode |
70 | // ------------- | |
71 | ||
72 | // some calendar styles can't be changed after the control creation by | |
73 | // just using SetWindowStyle() and Refresh() and the functions below | |
74 | // should be used instead for them | |
75 | ||
76 | // corresponds to wxCAL_NO_YEAR_CHANGE bit | |
77 | void EnableYearChange(bool enable = TRUE); | |
78 | ||
79 | // corresponds to wxCAL_NO_MONTH_CHANGE bit | |
80 | void EnableMonthChange(bool enable = TRUE); | |
81 | ||
82 | // corresponds to wxCAL_SHOW_HOLIDAYS bit | |
83 | void EnableHolidayDisplay(bool display = TRUE); | |
84 | ||
4f6aed9c VZ |
85 | // customization |
86 | // ------------- | |
87 | ||
88 | // header colours are used for painting the weekdays at the top | |
89 | void SetHeaderColours(const wxColour& colFg, const wxColour& colBg) | |
90 | { | |
91 | m_colHeaderFg = colFg; | |
92 | m_colHeaderBg = colBg; | |
93 | } | |
94 | ||
95 | const wxColour& GetHeaderColourFg() const { return m_colHeaderFg; } | |
96 | const wxColour& GetHeaderColourBg() const { return m_colHeaderBg; } | |
97 | ||
98 | // highlight colour is used for the currently selected date | |
99 | void SetHighlightColours(const wxColour& colFg, const wxColour& colBg) | |
100 | { | |
101 | m_colHighlightFg = colFg; | |
102 | m_colHighlightBg = colBg; | |
103 | } | |
104 | ||
105 | const wxColour& GetHighlightColourFg() const { return m_colHighlightFg; } | |
106 | const wxColour& GetHighlightColourBg() const { return m_colHighlightBg; } | |
107 | ||
108 | // holiday colour is used for the holidays (if style & wxCAL_SHOW_HOLIDAYS) | |
109 | void SetHolidayColours(const wxColour& colFg, const wxColour& colBg) | |
110 | { | |
111 | m_colHolidayFg = colFg; | |
112 | m_colHolidayBg = colBg; | |
113 | } | |
114 | ||
115 | const wxColour& GetHolidayColourFg() const { return m_colHolidayFg; } | |
116 | const wxColour& GetHolidayColourBg() const { return m_colHolidayBg; } | |
117 | ||
4f6aed9c VZ |
118 | // an item without custom attributes is drawn with the default colours and |
119 | // font and without border, setting custom attributes allows to modify this | |
120 | // | |
121 | // the day parameter should be in 1..31 range, for days 29, 30, 31 the | |
122 | // corresponding attribute is just unused if there is no such day in the | |
123 | // current month | |
124 | ||
125 | wxCalendarDateAttr *GetAttr(size_t day) const | |
126 | { | |
127 | wxCHECK_MSG( day > 0 && day < 32, NULL, _T("invalid day") ); | |
128 | ||
129 | return m_attrs[day - 1]; | |
130 | } | |
131 | ||
132 | void SetAttr(size_t day, wxCalendarDateAttr *attr) | |
133 | { | |
134 | wxCHECK_RET( day > 0 && day < 32, _T("invalid day") ); | |
135 | ||
136 | delete m_attrs[day - 1]; | |
137 | m_attrs[day - 1] = attr; | |
138 | } | |
139 | ||
140 | void SetHoliday(size_t day); | |
141 | ||
142 | void ResetAttr(size_t day) { SetAttr(day, (wxCalendarDateAttr *)NULL); } | |
143 | ||
0185cd09 VZ |
144 | // returns one of wxCAL_HITTEST_XXX constants and fills either date or wd |
145 | // with the corresponding value (none for NOWHERE, the date for DAY and wd | |
146 | // for HEADER) | |
147 | wxCalendarHitTestResult HitTest(const wxPoint& pos, | |
148 | wxDateTime *date = NULL, | |
149 | wxDateTime::WeekDay *wd = NULL); | |
2ef31e80 | 150 | |
882a8f40 VZ |
151 | // implementation only from now on |
152 | // ------------------------------- | |
153 | ||
154 | // forward these functions to all subcontrols | |
155 | virtual bool Enable(bool enable = TRUE); | |
156 | virtual bool Show(bool show = TRUE); | |
157 | ||
0185cd09 VZ |
158 | private: |
159 | // common part of all ctors | |
160 | void Init(); | |
161 | ||
882a8f40 VZ |
162 | // event handlers |
163 | void OnPaint(wxPaintEvent& event); | |
164 | void OnClick(wxMouseEvent& event); | |
0185cd09 | 165 | void OnDClick(wxMouseEvent& event); |
882a8f40 VZ |
166 | void OnChar(wxKeyEvent& event); |
167 | void OnMonthChange(wxCommandEvent& event); | |
168 | void OnYearChange(wxSpinEvent& event); | |
169 | ||
2ef31e80 VZ |
170 | // override some base class virtuals |
171 | virtual wxSize DoGetBestSize() const; | |
882a8f40 VZ |
172 | virtual void DoGetPosition(int *x, int *y) const; |
173 | virtual void DoGetSize(int *width, int *height) const; | |
2ef31e80 VZ |
174 | virtual void DoSetSize(int x, int y, int width, int height, int sizeFlags); |
175 | virtual void DoMoveWindow(int x, int y, int width, int height); | |
176 | ||
9d9b7755 VZ |
177 | // (re)calc m_widthCol and m_heightRow |
178 | void RecalcGeometry(); | |
179 | ||
9d9b7755 VZ |
180 | // set the date and send the notification |
181 | void SetDateAndNotify(const wxDateTime& date); | |
182 | ||
183 | // get the week (row, in range 1..6) for the given date | |
184 | size_t GetWeek(const wxDateTime& date) const; | |
185 | ||
2ef31e80 VZ |
186 | // get the date from which we start drawing days |
187 | wxDateTime GetStartDate() const; | |
188 | ||
189 | // is this date shown? | |
190 | bool IsDateShown(const wxDateTime& date) const; | |
191 | ||
9d9b7755 VZ |
192 | // redraw the given date |
193 | void RefreshDate(const wxDateTime& date); | |
194 | ||
195 | // change the date inside the same month/year | |
196 | void ChangeDay(const wxDateTime& date); | |
197 | ||
4f6aed9c VZ |
198 | // set the attributes for the holidays if needed |
199 | void SetHolidayAttrs(); | |
200 | ||
201 | // reset all holidays | |
202 | void ResetHolidayAttrs(); | |
203 | ||
204 | // generate the given calendar event(s) | |
205 | void GenerateEvent(wxEventType type) | |
206 | { | |
207 | wxCalendarEvent event(this, type); | |
208 | (void)GetEventHandler()->ProcessEvent(event); | |
209 | } | |
210 | ||
211 | void GenerateEvents(wxEventType type1, wxEventType type2) | |
212 | { | |
213 | GenerateEvent(type1); | |
214 | GenerateEvent(type2); | |
215 | } | |
9d9b7755 | 216 | |
bc385ba9 VZ |
217 | // do we allow changing the month/year? |
218 | bool AllowMonthChange() const | |
219 | { | |
220 | return (GetWindowStyle() & wxCAL_NO_MONTH_CHANGE) | |
221 | != wxCAL_NO_MONTH_CHANGE; | |
222 | } | |
223 | bool AllowYearChange() const | |
224 | { | |
225 | return !(GetWindowStyle() & wxCAL_NO_YEAR_CHANGE); | |
226 | } | |
227 | ||
228 | // show the correct controls | |
229 | void ShowCurrentControls(); | |
230 | ||
231 | // get the currently shown control for month/year | |
232 | wxControl *GetMonthControl() const; | |
233 | wxControl *GetYearControl() const; | |
234 | ||
2ef31e80 | 235 | // the subcontrols |
bc385ba9 | 236 | wxStaticText *m_staticMonth; |
2ef31e80 | 237 | wxComboBox *m_comboMonth; |
bc385ba9 VZ |
238 | |
239 | wxStaticText *m_staticYear; | |
2ef31e80 VZ |
240 | wxSpinCtrl *m_spinYear; |
241 | ||
4f6aed9c | 242 | // the current selection |
2ef31e80 VZ |
243 | wxDateTime m_date; |
244 | ||
4f6aed9c VZ |
245 | // default attributes |
246 | wxColour m_colHighlightFg, | |
247 | m_colHighlightBg, | |
248 | m_colHolidayFg, | |
249 | m_colHolidayBg, | |
250 | m_colHeaderFg, | |
251 | m_colHeaderBg; | |
252 | ||
253 | // the attributes for each of the month days | |
254 | wxCalendarDateAttr *m_attrs[31]; | |
255 | ||
2ef31e80 VZ |
256 | // the width and height of one column/row in the calendar |
257 | wxCoord m_widthCol, | |
258 | m_heightRow; | |
259 | ||
9d9b7755 VZ |
260 | // the week day names |
261 | wxString m_weekdays[7]; | |
262 | ||
2ef31e80 VZ |
263 | DECLARE_DYNAMIC_CLASS(wxCalendarCtrl) |
264 | DECLARE_EVENT_TABLE() | |
265 | }; | |
266 | ||
267 | #endif // _WX_GENERIC_CALCTRL_H |