]> git.saurik.com Git - wxWidgets.git/blob - include/wx/generic/calctrl.h
Don't set a normal cursor for the frame, set the NULL cursor, else
[wxWidgets.git] / include / wx / generic / calctrl.h
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 #include "wx/dcclient.h" // for wxPaintDC
21 #include "wx/spinctrl.h" // for wxSpinEvent
22
23 class WXDLLEXPORT wxComboBox;
24 class WXDLLEXPORT wxStaticText;
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 {
34 friend class wxMonthComboBox;
35 friend class wxYearSpinCtrl;
36
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,
45 long style = wxCAL_SHOW_HOLIDAYS | wxWANTS_CHARS,
46 const wxString& name = wxCalendarNameStr)
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,
58 long style = wxCAL_SHOW_HOLIDAYS | wxWANTS_CHARS,
59 const wxString& name = wxCalendarNameStr);
60
61 virtual ~wxCalendarCtrl();
62
63 virtual bool Destroy();
64
65 // set/get the current date
66 // ------------------------
67
68 bool SetDate(const wxDateTime& date); // we need to be able to control if the event should be sent in SetDateAndNotify(...)
69 const wxDateTime& GetDate() const { return m_date; }
70
71 // set/get the range in which selection can occur
72 // ---------------------------------------------
73
74 bool SetLowerDateLimit(const wxDateTime& date = wxDefaultDateTime);
75 const wxDateTime& GetLowerDateLimit() const { return m_lowdate; }
76 bool SetUpperDateLimit(const wxDateTime& date = wxDefaultDateTime);
77 const wxDateTime& GetUpperDateLimit() const { return m_highdate; }
78
79 bool SetDateRange(const wxDateTime& lowerdate = wxDefaultDateTime, const wxDateTime& upperdate = wxDefaultDateTime);
80
81 // calendar mode
82 // -------------
83
84 // some calendar styles can't be changed after the control creation by
85 // just using SetWindowStyle() and Refresh() and the functions below
86 // should be used instead for them
87
88 // corresponds to wxCAL_NO_YEAR_CHANGE bit
89 void EnableYearChange(bool enable = TRUE);
90
91 // corresponds to wxCAL_NO_MONTH_CHANGE bit
92 void EnableMonthChange(bool enable = TRUE);
93
94 // corresponds to wxCAL_SHOW_HOLIDAYS bit
95 void EnableHolidayDisplay(bool display = TRUE);
96
97 // customization
98 // -------------
99
100 // header colours are used for painting the weekdays at the top
101 void SetHeaderColours(const wxColour& colFg, const wxColour& colBg)
102 {
103 m_colHeaderFg = colFg;
104 m_colHeaderBg = colBg;
105 }
106
107 const wxColour& GetHeaderColourFg() const { return m_colHeaderFg; }
108 const wxColour& GetHeaderColourBg() const { return m_colHeaderBg; }
109
110 // highlight colour is used for the currently selected date
111 void SetHighlightColours(const wxColour& colFg, const wxColour& colBg)
112 {
113 m_colHighlightFg = colFg;
114 m_colHighlightBg = colBg;
115 }
116
117 const wxColour& GetHighlightColourFg() const { return m_colHighlightFg; }
118 const wxColour& GetHighlightColourBg() const { return m_colHighlightBg; }
119
120 // holiday colour is used for the holidays (if style & wxCAL_SHOW_HOLIDAYS)
121 void SetHolidayColours(const wxColour& colFg, const wxColour& colBg)
122 {
123 m_colHolidayFg = colFg;
124 m_colHolidayBg = colBg;
125 }
126
127 const wxColour& GetHolidayColourFg() const { return m_colHolidayFg; }
128 const wxColour& GetHolidayColourBg() const { return m_colHolidayBg; }
129
130 // an item without custom attributes is drawn with the default colours and
131 // font and without border, setting custom attributes allows to modify this
132 //
133 // the day parameter should be in 1..31 range, for days 29, 30, 31 the
134 // corresponding attribute is just unused if there is no such day in the
135 // current month
136
137 wxCalendarDateAttr *GetAttr(size_t day) const
138 {
139 wxCHECK_MSG( day > 0 && day < 32, NULL, _T("invalid day") );
140
141 return m_attrs[day - 1];
142 }
143
144 void SetAttr(size_t day, wxCalendarDateAttr *attr)
145 {
146 wxCHECK_RET( day > 0 && day < 32, _T("invalid day") );
147
148 delete m_attrs[day - 1];
149 m_attrs[day - 1] = attr;
150 }
151
152 void SetHoliday(size_t day);
153
154 void ResetAttr(size_t day) { SetAttr(day, (wxCalendarDateAttr *)NULL); }
155
156 // returns one of wxCAL_HITTEST_XXX constants and fills either date or wd
157 // with the corresponding value (none for NOWHERE, the date for DAY and wd
158 // for HEADER)
159 wxCalendarHitTestResult HitTest(const wxPoint& pos,
160 wxDateTime *date = NULL,
161 wxDateTime::WeekDay *wd = NULL);
162
163 // implementation only from now on
164 // -------------------------------
165
166 // forward these functions to all subcontrols
167 virtual bool Enable(bool enable = TRUE);
168 virtual bool Show(bool show = TRUE);
169
170 private:
171 // common part of all ctors
172 void Init();
173
174 // event handlers
175 void OnPaint(wxPaintEvent& event);
176 void OnClick(wxMouseEvent& event);
177 void OnDClick(wxMouseEvent& event);
178 void OnChar(wxKeyEvent& event);
179 void OnMonthChange(wxCommandEvent& event);
180 void OnYearChange(wxSpinEvent& event);
181
182 // override some base class virtuals
183 virtual wxSize DoGetBestSize() const;
184 virtual void DoGetPosition(int *x, int *y) const;
185 virtual void DoGetSize(int *width, int *height) const;
186 virtual void DoSetSize(int x, int y, int width, int height, int sizeFlags);
187 virtual void DoMoveWindow(int x, int y, int width, int height);
188
189 // (re)calc m_widthCol and m_heightRow
190 void RecalcGeometry();
191
192 // set the date and send the notification
193 void SetDateAndNotify(const wxDateTime& date);
194
195 // get the week (row, in range 1..6) for the given date
196 size_t GetWeek(const wxDateTime& date) const;
197
198 // get the date from which we start drawing days
199 wxDateTime GetStartDate() const;
200
201 // is this date shown?
202 bool IsDateShown(const wxDateTime& date) const;
203
204 // is this date in the given range?
205 bool IsDateInRange(const wxDateTime& date) const;
206
207 // range helpers
208 bool ChangeYear(wxDateTime* target) const;
209 bool ChangeMonth(wxDateTime* target) const;
210
211 // redraw the given date
212 void RefreshDate(const wxDateTime& date);
213
214 // change the date inside the same month/year
215 void ChangeDay(const wxDateTime& date);
216
217 // set the attributes for the holidays if needed
218 void SetHolidayAttrs();
219
220 // reset all holidays
221 void ResetHolidayAttrs();
222
223 // generate the given calendar event(s)
224 void GenerateEvent(wxEventType type)
225 {
226 wxCalendarEvent event(this, type);
227 (void)GetEventHandler()->ProcessEvent(event);
228 }
229
230 void GenerateEvents(wxEventType type1, wxEventType type2)
231 {
232 GenerateEvent(type1);
233 GenerateEvent(type2);
234 }
235
236 // do we allow changing the month/year?
237 bool AllowMonthChange() const
238 {
239 return (GetWindowStyle() & wxCAL_NO_MONTH_CHANGE)
240 != wxCAL_NO_MONTH_CHANGE;
241 }
242 bool AllowYearChange() const
243 {
244 return !(GetWindowStyle() & wxCAL_NO_YEAR_CHANGE);
245 }
246
247 // show the correct controls
248 void ShowCurrentControls();
249
250 // get the currently shown control for month/year
251 wxControl *GetMonthControl() const;
252 wxControl *GetYearControl() const;
253
254 // OnPaint helper-methods
255
256 // Highlight the [fromdate : todate] range using pen and brush
257 void HighlightRange(wxPaintDC* dc, const wxDateTime& fromdate, const wxDateTime& todate, wxPen* pen, wxBrush* brush);
258
259 // Get the "coordinates" for the date relative to the month currently displayed.
260 // using (day, week): upper left coord is (1, 1), lower right coord is (7, 6)
261 // if the date isn't visible (-1, -1) is put in (day, week) and false is returned
262 bool GetDateCoord(const wxDateTime& date, int *day, int *week) const;
263
264 // the subcontrols
265 wxStaticText *m_staticMonth;
266 wxComboBox *m_comboMonth;
267
268 wxStaticText *m_staticYear;
269 wxSpinCtrl *m_spinYear;
270
271 // the current selection
272 wxDateTime m_date;
273
274 // the date-range
275 wxDateTime m_lowdate;
276 wxDateTime m_highdate;
277
278 // default attributes
279 wxColour m_colHighlightFg,
280 m_colHighlightBg,
281 m_colHolidayFg,
282 m_colHolidayBg,
283 m_colHeaderFg,
284 m_colHeaderBg;
285
286 // the attributes for each of the month days
287 wxCalendarDateAttr *m_attrs[31];
288
289 // the width and height of one column/row in the calendar
290 wxCoord m_widthCol,
291 m_heightRow,
292 m_rowOffset;
293
294 wxRect m_leftArrowRect,
295 m_rightArrowRect;
296
297 // the week day names
298 wxString m_weekdays[7];
299
300 DECLARE_DYNAMIC_CLASS(wxCalendarCtrl)
301 DECLARE_EVENT_TABLE()
302 };
303
304 #endif // _WX_GENERIC_CALCTRL_H