]> git.saurik.com Git - wxWidgets.git/blame - interface/calctrl.h
Mention wxDataViewTreeCtrl in wxTreeCtrl
[wxWidgets.git] / interface / calctrl.h
CommitLineData
23324ae1
FM
1/////////////////////////////////////////////////////////////////////////////
2// Name: calctrl.h
49d37022 3// Purpose: interface of wxCalendarCtrl
23324ae1
FM
4// Author: wxWidgets team
5// RCS-ID: $Id$
6// Licence: wxWindows license
7/////////////////////////////////////////////////////////////////////////////
8
9/**
10 @class wxCalendarEvent
11 @wxheader{calctrl.h}
7c913512 12
49d37022 13 The wxCalendarEvent class is used together with wxCalendarCtrl.
7c913512 14
23324ae1
FM
15 @library{wxadv}
16 @category{events}
7c913512 17
e54c96f1 18 @see wxCalendarCtrl
23324ae1
FM
19*/
20class wxCalendarEvent : public wxDateEvent
21{
22public:
23 /**
7c913512 24 Returns the week day on which the user clicked in
23324ae1
FM
25 @c EVT_CALENDAR_WEEKDAY_CLICKED handler. It doesn't make sense to call
26 this function in other handlers.
27 */
328f5751 28 wxDateTime::WeekDay GetWeekDay() const;
23324ae1
FM
29
30 /**
49d37022
BP
31 Sets the week day carried by the event, normally only used by the
32 library internally.
23324ae1
FM
33 */
34 void SetWeekDay(wxDateTime::WeekDay day);
35};
36
37
e54c96f1 38
49d37022
BP
39/**
40 Possible kinds of borders which may be used to decorate a date using
41 wxCalendarDateAttr.
42*/
43enum wxCalendarDateBorder
44{
45 wxCAL_BORDER_NONE, ///< No Border (Default)
46 wxCAL_BORDER_SQUARE, ///< Rectangular Border
47 wxCAL_BORDER_ROUND ///< Round Border
48};
49
23324ae1
FM
50/**
51 @class wxCalendarDateAttr
52 @wxheader{calctrl.h}
7c913512 53
49d37022
BP
54 wxCalendarDateAttr is a custom attributes for a calendar date. The objects
55 of this class are used with wxCalendarCtrl.
7c913512 56
23324ae1
FM
57 @library{wxadv}
58 @category{misc}
7c913512 59
e54c96f1 60 @see wxCalendarCtrl
23324ae1 61*/
7c913512 62class wxCalendarDateAttr
23324ae1
FM
63{
64public:
23324ae1 65 /**
49d37022 66 Default constructor.
23324ae1
FM
67 */
68 wxCalendarDateAttr();
49d37022
BP
69
70 /**
71 Constructor for specifying all wxCalendarDateAttr properties.
72 */
7c913512
FM
73 wxCalendarDateAttr(const wxColour& colText,
74 const wxColour& colBack = wxNullColour,
75 const wxColour& colBorder = wxNullColour,
76 const wxFont& font = wxNullFont,
77 wxCalendarDateBorder border = wxCAL_BORDER_NONE);
49d37022
BP
78
79 /**
80 Constructor using default properties except the given border.
81 */
7c913512
FM
82 wxCalendarDateAttr(wxCalendarDateBorder border,
83 const wxColour& colBorder = wxNullColour);
23324ae1
FM
84
85 /**
49d37022 86 Returns the background colour set for the calendar date.
23324ae1 87 */
328f5751 88 const wxColour GetBackgroundColour() const;
23324ae1
FM
89
90 /**
49d37022 91 Returns the border set for the calendar date.
23324ae1 92 */
328f5751 93 wxCalendarDateBorder GetBorder() const;
23324ae1
FM
94
95 /**
49d37022 96 Returns the border colour set for the calendar date.
23324ae1 97 */
328f5751 98 const wxColour GetBorderColour() const;
23324ae1
FM
99
100 /**
49d37022 101 Returns the font set for the calendar date.
23324ae1 102 */
328f5751 103 const wxFont GetFont() const;
23324ae1
FM
104
105 /**
49d37022 106 Returns the text colour set for the calendar date.
23324ae1 107 */
328f5751 108 const wxColour GetTextColour() const;
23324ae1
FM
109
110 /**
49d37022 111 Returns @true if a non-default text background colour is set.
23324ae1 112 */
328f5751 113 bool HasBackgroundColour() const;
23324ae1
FM
114
115 /**
49d37022 116 Returns @true if a non-default (i.e. any) border is set.
23324ae1 117 */
328f5751 118 bool HasBorder() const;
23324ae1
FM
119
120 /**
49d37022 121 Returns @true if a non-default border colour is set.
23324ae1 122 */
328f5751 123 bool HasBorderColour() const;
23324ae1
FM
124
125 /**
49d37022 126 Returns @true if a non-default font is set.
23324ae1 127 */
328f5751 128 bool HasFont() const;
23324ae1
FM
129
130 /**
49d37022 131 Returns @true if a non-default text foreground colour is set.
23324ae1 132 */
328f5751 133 bool HasTextColour() const;
23324ae1
FM
134
135 /**
49d37022 136 Returns @true if this calendar day is displayed as a holiday.
23324ae1 137 */
328f5751 138 bool IsHoliday() const;
23324ae1
FM
139
140 /**
141 Sets the text background colour to use.
142 */
143 void SetBackgroundColour(const wxColour& colBack);
144
145 /**
49d37022 146 Sets the border to use.
23324ae1
FM
147 */
148 void SetBorder(wxCalendarDateBorder border);
149
150 /**
151 Sets the border colour to use.
152 */
153 void SetBorderColour(const wxColour& col);
154
155 /**
156 Sets the font to use.
157 */
158 void SetFont(const wxFont& font);
159
160 /**
49d37022
BP
161 If @a holiday is @true, this calendar day will be displayed as a
162 holiday.
23324ae1
FM
163 */
164 void SetHoliday(bool holiday);
165
166 /**
167 Sets the text (foreground) colour to use.
168 */
169 void SetTextColour(const wxColour& colText);
628e155d
VZ
170
171 /**
49d37022 172 Used (internally) by the generic wxCalendarCtrl::Mark().
628e155d
VZ
173 */
174 static const wxCalendarDateAttr& GetMark();
175
176 /**
49d37022
BP
177 Set the attributes that will be used to Mark() days on the generic
178 wxCalendarCtrl.
628e155d
VZ
179 */
180 static void SetMark(wxCalendarDateAttr const& m);
23324ae1
FM
181};
182
183
e54c96f1 184
49d37022
BP
185/**
186 Possible return values from wxCalendarCtrl::HitTest().
187*/
188enum wxCalendarHitTestResult
189{
190 wxCAL_HITTEST_NOWHERE, ///< Hit outside of anything.
191 wxCAL_HITTEST_HEADER, ///< Hit on the header (weekdays).
192 wxCAL_HITTEST_DAY ///< Hit on a day in the calendar.
193};
194
23324ae1
FM
195/**
196 @class wxCalendarCtrl
197 @wxheader{calctrl.h}
7c913512 198
628e155d 199 The calendar control allows the user to pick a date. The user can move the
7c913512 200 current selection using the keyboard and select the date (generating
49d37022 201 @c EVT_CALENDAR event) by pressing @c @<Return@> or double clicking it.
7c913512 202
628e155d 203 Generic calendar has advanced possibilities for the customization of its
49d37022
BP
204 display, described below. If you want to use these possibilities on every
205 platform, use wxGenericCalendarCtrl instead of wxCalendarCtrl.
628e155d 206
49d37022
BP
207 All global settings (such as colours and fonts used) can, of course, be
208 changed. But also, the display style for each day in the month can be set
209 independently using wxCalendarDateAttr class.
7c913512 210
23324ae1 211 An item without custom attributes is drawn with the default colours and
49d37022
BP
212 font and without border, but setting custom attributes with SetAttr()
213 allows to modify its appearance. Just create a custom attribute object and
214 set it for the day you want to be displayed specially (note that the
215 control will take ownership of the pointer, i.e. it will delete it itself).
628e155d 216 A day may be marked as being a holiday, even if it is not recognized as
49d37022 217 one by wxDateTime using the wxCalendarDateAttr::SetHoliday() method.
7c913512 218
49d37022
BP
219 As the attributes are specified for each day, they may change when the
220 month is changed, so you will often want to update them in
628e155d 221 @c EVT_CALENDAR_PAGE_CHANGED event handler.
7c913512 222
23324ae1 223 @beginStyleTable
8c6791e4 224 @style{wxCAL_SUNDAY_FIRST}
db0b0942 225 Show Sunday as the first day in the week (not in wxGTK)
8c6791e4 226 @style{wxCAL_MONDAY_FIRST}
db0b0942 227 Show Monday as the first day in the week (not in wxGTK)
8c6791e4 228 @style{wxCAL_SHOW_HOLIDAYS}
628e155d 229 Highlight holidays in the calendar (only generic)
8c6791e4 230 @style{wxCAL_NO_YEAR_CHANGE}
628e155d 231 Disable the year changing (deprecated, only generic)
8c6791e4 232 @style{wxCAL_NO_MONTH_CHANGE}
23324ae1 233 Disable the month (and, implicitly, the year) changing
8c6791e4 234 @style{wxCAL_SHOW_SURROUNDING_WEEKS}
23324ae1 235 Show the neighbouring weeks in the previous and next months
db0b0942 236 (only generic, always on for the native controls)
8c6791e4 237 @style{wxCAL_SEQUENTIAL_MONTH_SELECTION}
23324ae1 238 Use alternative, more compact, style for the month and year
628e155d 239 selection controls. (only generic)
7b0ccb8a
RR
240 @style{wxCAL_SHOW_WEEK_NUMBERS}
241 Show week numbers on the left side of the calendar. (not in generic)
23324ae1 242 @endStyleTable
7c913512 243
1f1d2182 244 @beginEventTable{wxCalendarEvent}
8c6791e4 245 @event{EVT_CALENDAR(id, func)}
628e155d 246 A day was double clicked in the calendar.
8c6791e4 247 @event{EVT_CALENDAR_SEL_CHANGED(id, func)}
628e155d 248 The selected date changed.
8c6791e4 249 @event{EVT_CALENDAR_PAGE_CHANGED(id, func)}
628e155d 250 The selected month (and/or year) changed.
8c6791e4 251 @event{EVT_CALENDAR_WEEKDAY_CLICKED(id, func)}
628e155d
VZ
252 User clicked on the week day header (only generic).
253 @endEventTable
254
49d37022
BP
255 @note Changing the selected date will trigger an EVT_CALENDAR_DAY, MONTH or
256 YEAR event as well as an EVT_CALENDAR_SEL_CHANGED event.
257
23324ae1
FM
258 @library{wxadv}
259 @category{ctrl}
49d37022 260 <!-- @appearance{calendarctrl.png} -->
7c913512 261
7b0ccb8a 262 @nativeimpl{wxgtk,wxmsw}
628e155d 263
1f1d2182
FM
264 @see @ref page_samples_calendar, wxCalendarDateAttr, wxCalendarEvent,
265 wxDatePickerCtrl
23324ae1
FM
266*/
267class wxCalendarCtrl : public wxControl
268{
269public:
23324ae1 270 /**
49d37022 271 Default constructor.
23324ae1
FM
272 */
273 wxCalendarCtrl();
49d37022
BP
274
275 /**
276 Does the same as Create() method.
277 */
7c913512
FM
278 wxCalendarCtrl(wxWindow* parent, wxWindowID id,
279 const wxDateTime& date = wxDefaultDateTime,
280 const wxPoint& pos = wxDefaultPosition,
281 const wxSize& size = wxDefaultSize,
282 long style = wxCAL_SHOW_HOLIDAYS,
283 const wxString& name = wxCalendarNameStr);
23324ae1
FM
284
285 /**
286 Destroys the control.
287 */
288 ~wxCalendarCtrl();
289
290 /**
49d37022
BP
291 Creates the control. See wxWindow::wxWindow() for the meaning of the
292 parameters and the control overview for the possible styles.
23324ae1
FM
293 */
294 bool Create(wxWindow* parent, wxWindowID id,
295 const wxDateTime& date = wxDefaultDateTime,
296 const wxPoint& pos = wxDefaultPosition,
297 const wxSize& size = wxDefaultSize,
298 long style = wxCAL_SHOW_HOLIDAYS,
299 const wxString& name = wxCalendarNameStr);
300
301 /**
302 This function should be used instead of changing @c wxCAL_SHOW_HOLIDAYS
49d37022
BP
303 style bit directly. It enables or disables the special highlighting of
304 the holidays.
23324ae1 305 */
4cc4bfaf 306 void EnableHolidayDisplay(bool display = true);
23324ae1
FM
307
308 /**
7c913512 309 This function should be used instead of changing
23324ae1 310 @c wxCAL_NO_MONTH_CHANGE style bit. It allows or disallows the user to
49d37022
BP
311 change the month interactively. Note that if the month can not be
312 changed, the year can not be changed neither.
628e155d 313
49d37022
BP
314 @return @true if the value of this option really changed or @false if
315 it was already set to the requested value.
23324ae1 316 */
628e155d 317 bool EnableMonthChange(bool enable = true);
23324ae1
FM
318
319 /**
628e155d
VZ
320 @deprecated
321
49d37022
BP
322 This function should be used instead of changing
323 @c wxCAL_NO_YEAR_CHANGE style bit directly. It allows or disallows the
324 user to change the year interactively. Only in generic wxCalendarCtrl.
23324ae1 325 */
4cc4bfaf 326 void EnableYearChange(bool enable = true);
23324ae1
FM
327
328 /**
49d37022
BP
329 Returns the attribute for the given date (should be in the range
330 1...31). The returned pointer may be @NULL. Only in generic
331 wxCalendarCtrl.
23324ae1 332 */
328f5751 333 wxCalendarDateAttr* GetAttr(size_t day) const;
23324ae1
FM
334
335 /**
336 Gets the currently selected date.
337 */
328f5751 338 const wxDateTime GetDate() const;
23324ae1
FM
339
340 /**
341 Gets the background colour of the header part of the calendar window.
3c4f71cc 342
bf956fac
VZ
343 This method is currently only implemented in generic wxCalendarCtrl and
344 always returns @c wxNullColour in the native versions.
345
4cc4bfaf 346 @see SetHeaderColours()
23324ae1 347 */
328f5751 348 const wxColour GetHeaderColourBg() const;
23324ae1
FM
349
350 /**
351 Gets the foreground colour of the header part of the calendar window.
bf956fac
VZ
352
353 This method is currently only implemented in generic wxCalendarCtrl and
354 always returns @c wxNullColour in the native versions.
3c4f71cc 355
4cc4bfaf 356 @see SetHeaderColours()
23324ae1 357 */
328f5751 358 const wxColour GetHeaderColourFg() const;
23324ae1
FM
359
360 /**
628e155d 361 Gets the background highlight colour. Only in generic wxCalendarCtrl.
3c4f71cc 362
bf956fac
VZ
363 This method is currently only implemented in generic wxCalendarCtrl and
364 always returns @c wxNullColour in the native versions.
365
4cc4bfaf 366 @see SetHighlightColours()
23324ae1 367 */
328f5751 368 const wxColour GetHighlightColourBg() const;
23324ae1
FM
369
370 /**
628e155d 371 Gets the foreground highlight colour. Only in generic wxCalendarCtrl.
3c4f71cc 372
bf956fac
VZ
373 This method is currently only implemented in generic wxCalendarCtrl and
374 always returns @c wxNullColour in the native versions.
375
4cc4bfaf 376 @see SetHighlightColours()
23324ae1 377 */
328f5751 378 const wxColour GetHighlightColourFg() const;
23324ae1
FM
379
380 /**
381 Return the background colour currently used for holiday highlighting.
bf956fac
VZ
382
383 Only useful with generic wxCalendarCtrl as native versions currently
49d37022
BP
384 don't support holidays display at all and always return
385 @c wxNullColour.
3c4f71cc 386
4cc4bfaf 387 @see SetHolidayColours()
23324ae1 388 */
328f5751 389 const wxColour GetHolidayColourBg() const;
23324ae1
FM
390
391 /**
392 Return the foreground colour currently used for holiday highlighting.
bf956fac
VZ
393
394 Only useful with generic wxCalendarCtrl as native versions currently
49d37022
BP
395 don't support holidays display at all and always return
396 @c wxNullColour.
3c4f71cc 397
4cc4bfaf 398 @see SetHolidayColours()
23324ae1 399 */
328f5751 400 const wxColour GetHolidayColourFg() const;
23324ae1
FM
401
402 /**
49d37022
BP
403 Returns one of wxCalendarHitTestResult constants and fills either
404 @a date or @a wd pointer with the corresponding value depending on the
db0b0942
VZ
405 hit test code.
406
407 Not implemented in wxGTK currently.
23324ae1
FM
408 */
409 wxCalendarHitTestResult HitTest(const wxPoint& pos,
4cc4bfaf
FM
410 wxDateTime* date = NULL,
411 wxDateTime::WeekDay* wd = NULL);
23324ae1
FM
412
413 /**
414 Clears any attributes associated with the given day (in the range
49d37022 415 1...31). Only in generic wxCalendarCtrl.
23324ae1
FM
416 */
417 void ResetAttr(size_t day);
418
419 /**
420 Associates the attribute with the specified date (in the range 1...31).
49d37022
BP
421 If the pointer is @NULL, the items attribute is cleared. Only in
422 generic wxCalendarCtrl.
23324ae1
FM
423 */
424 void SetAttr(size_t day, wxCalendarDateAttr* attr);
425
426 /**
427 Sets the current date.
db0b0942
VZ
428
429 The @a date parameter must be valid.
23324ae1
FM
430 */
431 void SetDate(const wxDateTime& date);
432
433 /**
49d37022
BP
434 Set the colours used for painting the weekdays at the top of the
435 control.
bf956fac
VZ
436
437 This method is currently only implemented in generic wxCalendarCtrl and
438 does nothing in the native versions.
23324ae1
FM
439 */
440 void SetHeaderColours(const wxColour& colFg,
441 const wxColour& colBg);
442
443 /**
49d37022
BP
444 Set the colours to be used for highlighting the currently selected
445 date.
bf956fac
VZ
446
447 This method is currently only implemented in generic wxCalendarCtrl and
448 does nothing in the native versions.
23324ae1
FM
449 */
450 void SetHighlightColours(const wxColour& colFg,
451 const wxColour& colBg);
452
453 /**
454 Marks the specified day as being a holiday in the current month.
bf956fac
VZ
455
456 This method is only implemented in the generic version of the control
457 and does nothing in the native ones.
23324ae1
FM
458 */
459 void SetHoliday(size_t day);
460
461 /**
bf956fac
VZ
462 Sets the colours to be used for the holidays highlighting.
463
464 This method is only implemented in the generic version of the control
465 and does nothing in the native ones. It should also only be called if
466 the window style includes @c wxCAL_SHOW_HOLIDAYS flag or
467 EnableHolidayDisplay() had been called.
468
23324ae1
FM
469 */
470 void SetHolidayColours(const wxColour& colFg,
471 const wxColour& colBg);
628e155d
VZ
472
473 /**
49d37022
BP
474 Mark or unmark the day. This day of month will be marked in every
475 month. In generic wxCalendarCtrl,
628e155d
VZ
476 */
477 void Mark(size_t day, bool mark);
51317496 478
51317496 479 /**
49d37022 480 @name Date Range Functions
51317496
VZ
481
482 The functions in this section are currently implemented in the generic
483 and MSW versions and do nothing in the native GTK implementation.
484 */
485 //@{
486
487 /**
488 Restrict the dates shown by the control to the specified range.
489
490 If either date is set, the corresponding limit will be enforced and
491 @true returned. If none are set, the existing restrictions are removed
492 and @false is returned.
493
49d37022
BP
494 @see GetDateRange()
495
51317496 496 @param lowerdate
49d37022
BP
497 The low limit for the dates shown by the control or
498 @c wxDefaultDateTime.
51317496 499 @param highlighting
49d37022
BP
500 The high limit for the dates shown by the control or
501 @c wxDefaultDateTime.
51317496
VZ
502 @return
503 @true if either limit is valid, @false otherwise
504 */
505 virtual bool SetDateRange(const wxDateTime& lowerdate = wxDefaultDateTime,
49d37022 506 const wxDateTime& upperdate = wxDefaultDateTime);
51317496
VZ
507
508 /**
509 Returns the limits currently being used.
510
511 @see SetDateRange()
512
513 @param lowerdate
49d37022 514 If non-@NULL, the value of the low limit for the dates shown by the
51317496 515 control is returned (which may be @c wxDefaultDateTime if no limit
49d37022 516 is set).
51317496 517 @param upperdate
49d37022
BP
518 If non-@NULL, the value of the upper limit for the dates shown by
519 the control is returned (which may be @c wxDefaultDateTime if no
520 limit is set).
51317496
VZ
521 @return
522 @true if either limit is set, @false otherwise
523 */
49d37022
BP
524 virtual bool GetDateRange(wxDateTime *lowerdate,
525 wxDateTime *upperdate) const;
51317496
VZ
526
527 //@}
23324ae1 528};
e54c96f1 529