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