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