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