1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: generic/calctrl.cpp
3 // Purpose: implementation fo the generic wxCalendarCtrl
4 // Author: Vadim Zeitlin
8 // Copyright: (c) 1999 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
9 // Licence: wxWindows license
10 ///////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
21 #pragma implementation "calctrl.h"
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
32 #include "wx/dcclient.h"
33 #include "wx/settings.h"
35 #include "wx/combobox.h"
36 #include "wx/stattext.h"
39 #if wxUSE_CALENDARCTRL
41 #include "wx/calctrl.h"
45 // ----------------------------------------------------------------------------
47 // ----------------------------------------------------------------------------
49 class wxMonthComboBox
: public wxComboBox
52 wxMonthComboBox(wxCalendarCtrl
*cal
);
54 void OnMonthChange(wxCommandEvent
& event
) { m_cal
->OnMonthChange(event
); }
57 wxCalendarCtrl
*m_cal
;
62 class wxYearSpinCtrl
: public wxSpinCtrl
65 wxYearSpinCtrl(wxCalendarCtrl
*cal
);
67 void OnYearChange(wxSpinEvent
& event
) { m_cal
->OnYearChange(event
); }
70 wxCalendarCtrl
*m_cal
;
75 // ----------------------------------------------------------------------------
77 // ----------------------------------------------------------------------------
79 BEGIN_EVENT_TABLE(wxCalendarCtrl
, wxControl
)
80 EVT_PAINT(wxCalendarCtrl::OnPaint
)
82 EVT_CHAR(wxCalendarCtrl::OnChar
)
84 EVT_LEFT_DOWN(wxCalendarCtrl::OnClick
)
85 EVT_LEFT_DCLICK(wxCalendarCtrl::OnDClick
)
88 BEGIN_EVENT_TABLE(wxMonthComboBox
, wxComboBox
)
89 EVT_COMBOBOX(-1, wxMonthComboBox::OnMonthChange
)
92 BEGIN_EVENT_TABLE(wxYearSpinCtrl
, wxSpinCtrl
)
93 EVT_SPINCTRL(-1, wxYearSpinCtrl::OnYearChange
)
96 IMPLEMENT_DYNAMIC_CLASS(wxCalendarCtrl
, wxControl
)
97 IMPLEMENT_DYNAMIC_CLASS(wxCalendarEvent
, wxCommandEvent
)
99 // ----------------------------------------------------------------------------
101 // ----------------------------------------------------------------------------
103 DEFINE_EVENT_TYPE(wxEVT_CALENDAR_SEL_CHANGED
)
104 DEFINE_EVENT_TYPE(wxEVT_CALENDAR_DAY_CHANGED
)
105 DEFINE_EVENT_TYPE(wxEVT_CALENDAR_MONTH_CHANGED
)
106 DEFINE_EVENT_TYPE(wxEVT_CALENDAR_YEAR_CHANGED
)
107 DEFINE_EVENT_TYPE(wxEVT_CALENDAR_DOUBLECLICKED
)
108 DEFINE_EVENT_TYPE(wxEVT_CALENDAR_WEEKDAY_CLICKED
)
110 // ============================================================================
112 // ============================================================================
114 // ----------------------------------------------------------------------------
115 // wxMonthComboBox and wxYearSpinCtrl
116 // ----------------------------------------------------------------------------
118 wxMonthComboBox::wxMonthComboBox(wxCalendarCtrl
*cal
)
119 : wxComboBox(cal
->GetParent(), -1,
129 for ( m
= wxDateTime::Jan
; m
< wxDateTime::Inv_Month
; wxNextMonth(m
) )
131 Append(wxDateTime::GetMonthName(m
));
134 SetSelection(m_cal
->GetDate().GetMonth());
135 SetSize(-1, -1, -1, -1, wxSIZE_AUTO_WIDTH
|wxSIZE_AUTO_HEIGHT
);
138 wxYearSpinCtrl::wxYearSpinCtrl(wxCalendarCtrl
*cal
)
139 : wxSpinCtrl(cal
->GetParent(), -1,
140 cal
->GetDate().Format(_T("%Y")),
144 -4300, 10000, cal
->GetDate().GetYear())
149 // ----------------------------------------------------------------------------
151 // ----------------------------------------------------------------------------
153 void wxCalendarCtrl::Init()
161 wxDateTime::WeekDay wd
;
162 for ( wd
= wxDateTime::Sun
; wd
< wxDateTime::Inv_WeekDay
; wxNextWDay(wd
) )
164 m_weekdays
[wd
] = wxDateTime::GetWeekDayName(wd
, wxDateTime::Name_Abbr
);
167 for ( size_t n
= 0; n
< WXSIZEOF(m_attrs
); n
++ )
173 m_colHighlightFg
= ss
.GetSystemColour(wxSYS_COLOUR_HIGHLIGHTTEXT
);
174 m_colHighlightBg
= ss
.GetSystemColour(wxSYS_COLOUR_HIGHLIGHT
);
176 m_colHolidayFg
= *wxRED
;
177 // don't set m_colHolidayBg - by default, same as our bg colour
179 m_colHeaderFg
= *wxBLUE
;
180 m_colHeaderBg
= *wxLIGHT_GREY
;
183 bool wxCalendarCtrl::Create(wxWindow
*parent
,
185 const wxDateTime
& date
,
189 const wxString
& name
)
191 if ( !wxControl::Create(parent
, id
, pos
, size
,
192 style
| wxWANTS_CHARS
, wxDefaultValidator
, name
) )
197 // needed to get the arrow keys normally used for the dialog navigation
198 SetWindowStyle(style
| wxWANTS_CHARS
);
200 m_date
= date
.IsValid() ? date
: wxDateTime::Today();
202 m_spinYear
= new wxYearSpinCtrl(this);
203 m_staticYear
= new wxStaticText(GetParent(), -1, m_date
.Format(_T("%Y")),
204 wxDefaultPosition
, wxDefaultSize
,
207 m_comboMonth
= new wxMonthComboBox(this);
208 m_staticMonth
= new wxStaticText(GetParent(), -1, m_date
.Format(_T("%B")),
209 wxDefaultPosition
, wxDefaultSize
,
212 ShowCurrentControls();
215 if ( size
.x
== -1 || size
.y
== -1 )
217 sizeReal
= DoGetBestSize();
230 SetBackgroundColour(*wxWHITE
);
231 SetFont(*wxSWISS_FONT
);
238 wxCalendarCtrl::~wxCalendarCtrl()
240 for ( size_t n
= 0; n
< WXSIZEOF(m_attrs
); n
++ )
246 // ----------------------------------------------------------------------------
247 // forward wxWin functions to subcontrols
248 // ----------------------------------------------------------------------------
250 bool wxCalendarCtrl::Show(bool show
)
252 if ( !wxControl::Show(show
) )
257 GetMonthControl()->Show(show
);
258 GetYearControl()->Show(show
);
263 bool wxCalendarCtrl::Enable(bool enable
)
265 if ( !wxControl::Enable(enable
) )
270 GetMonthControl()->Enable(enable
);
271 GetYearControl()->Enable(enable
);
276 // ----------------------------------------------------------------------------
277 // enable/disable month/year controls
278 // ----------------------------------------------------------------------------
280 void wxCalendarCtrl::ShowCurrentControls()
282 if ( AllowMonthChange() )
284 m_comboMonth
->Show();
285 m_staticMonth
->Hide();
287 if ( AllowYearChange() )
290 m_staticYear
->Hide();
298 m_comboMonth
->Hide();
299 m_staticMonth
->Show();
302 // year change not allowed here
304 m_staticYear
->Show();
307 wxControl
*wxCalendarCtrl::GetMonthControl() const
309 return AllowMonthChange() ? (wxControl
*)m_comboMonth
: (wxControl
*)m_staticMonth
;
312 wxControl
*wxCalendarCtrl::GetYearControl() const
314 return AllowYearChange() ? (wxControl
*)m_spinYear
: (wxControl
*)m_staticYear
;
317 void wxCalendarCtrl::EnableYearChange(bool enable
)
319 if ( enable
!= AllowYearChange() )
321 long style
= GetWindowStyle();
323 style
&= ~wxCAL_NO_YEAR_CHANGE
;
325 style
|= wxCAL_NO_YEAR_CHANGE
;
326 SetWindowStyle(style
);
328 ShowCurrentControls();
332 void wxCalendarCtrl::EnableMonthChange(bool enable
)
334 if ( enable
!= AllowMonthChange() )
336 long style
= GetWindowStyle();
338 style
&= ~wxCAL_NO_MONTH_CHANGE
;
340 style
|= wxCAL_NO_MONTH_CHANGE
;
341 SetWindowStyle(style
);
343 ShowCurrentControls();
347 // ----------------------------------------------------------------------------
349 // ----------------------------------------------------------------------------
351 void wxCalendarCtrl::SetDate(const wxDateTime
& date
)
353 bool sameMonth
= m_date
.GetMonth() == date
.GetMonth(),
354 sameYear
= m_date
.GetYear() == date
.GetYear();
356 if ( sameMonth
&& sameYear
)
358 // just change the day
363 if ( !AllowMonthChange() || (!AllowYearChange() && !sameYear
) )
372 // update the controls
373 m_comboMonth
->SetSelection(m_date
.GetMonth());
375 if ( AllowYearChange() )
377 m_spinYear
->SetValue(m_date
.Format(_T("%Y")));
380 // as the month changed, holidays did too
383 // update the calendar
388 void wxCalendarCtrl::ChangeDay(const wxDateTime
& date
)
390 if ( m_date
!= date
)
392 // we need to refresh the row containing the old date and the one
393 // containing the new one
394 wxDateTime dateOld
= m_date
;
397 RefreshDate(dateOld
);
399 // if the date is in the same row, it was already drawn correctly
400 if ( GetWeek(m_date
) != GetWeek(dateOld
) )
407 void wxCalendarCtrl::SetDateAndNotify(const wxDateTime
& date
)
409 wxDateTime::Tm tm1
= m_date
.GetTm(),
413 if ( tm1
.year
!= tm2
.year
)
414 type
= wxEVT_CALENDAR_YEAR_CHANGED
;
415 else if ( tm1
.mon
!= tm2
.mon
)
416 type
= wxEVT_CALENDAR_MONTH_CHANGED
;
417 else if ( tm1
.mday
!= tm2
.mday
)
418 type
= wxEVT_CALENDAR_DAY_CHANGED
;
424 GenerateEvents(type
, wxEVT_CALENDAR_SEL_CHANGED
);
427 // ----------------------------------------------------------------------------
429 // ----------------------------------------------------------------------------
431 wxDateTime
wxCalendarCtrl::GetStartDate() const
433 wxDateTime::Tm tm
= m_date
.GetTm();
435 wxDateTime date
= wxDateTime(1, tm
.mon
, tm
.year
);
438 date
.SetToPrevWeekDay(GetWindowStyle() & wxCAL_MONDAY_FIRST
439 ? wxDateTime::Mon
: wxDateTime::Sun
);
444 bool wxCalendarCtrl::IsDateShown(const wxDateTime
& date
) const
446 return date
.GetMonth() == m_date
.GetMonth();
449 size_t wxCalendarCtrl::GetWeek(const wxDateTime
& date
) const
451 return date
.GetWeekOfMonth(GetWindowStyle() & wxCAL_MONDAY_FIRST
452 ? wxDateTime::Monday_First
453 : wxDateTime::Sunday_First
);
456 // ----------------------------------------------------------------------------
458 // ----------------------------------------------------------------------------
460 // this is a composite control and it must arrange its parts each time its
461 // size or position changes: the combobox and spinctrl are along the top of
462 // the available area and the calendar takes up therest of the space
464 // the static controls are supposed to be always smaller than combo/spin so we
465 // always use the latter for size calculations and position the static to take
468 // the constants used for the layout
469 #define VERT_MARGIN 5 // distance between combo and calendar
470 #define HORZ_MARGIN 15 // spin
472 wxSize
wxCalendarCtrl::DoGetBestSize() const
474 // calc the size of the calendar
475 ((wxCalendarCtrl
*)this)->RecalcGeometry(); // const_cast
477 wxCoord width
= 7*m_widthCol
,
478 height
= 7*m_heightRow
;
480 // the combobox doesn't report its height correctly (it returns the
481 // height including the drop down list) so don't use it
482 height
+= VERT_MARGIN
+ m_spinYear
->GetBestSize().y
;
484 if ( GetWindowStyle() & (wxRAISED_BORDER
| wxSUNKEN_BORDER
) )
486 // the border would clip the last line otherwise
490 return wxSize(width
, height
);
493 void wxCalendarCtrl::DoSetSize(int x
, int y
,
494 int width
, int height
,
497 wxControl::DoSetSize(x
, y
, width
, height
, sizeFlags
);
500 void wxCalendarCtrl::DoMoveWindow(int x
, int y
, int width
, int height
)
502 wxSize sizeCombo
= m_comboMonth
->GetSize();
503 wxSize sizeStatic
= m_staticMonth
->GetSize();
505 int dy
= (sizeCombo
.y
- sizeStatic
.y
) / 2;
506 m_comboMonth
->Move(x
, y
);
507 m_staticMonth
->SetSize(x
, y
+ dy
, sizeCombo
.x
, sizeStatic
.y
);
509 int xDiff
= sizeCombo
.x
+ HORZ_MARGIN
;
510 m_spinYear
->SetSize(x
+ xDiff
, y
, width
- xDiff
, sizeCombo
.y
);
511 m_staticYear
->SetSize(x
+ xDiff
, y
+ dy
, width
- xDiff
, sizeStatic
.y
);
513 wxSize sizeSpin
= m_spinYear
->GetSize();
514 int yDiff
= wxMax(sizeSpin
.y
, sizeCombo
.y
) + VERT_MARGIN
;
516 wxControl::DoMoveWindow(x
, y
+ yDiff
, width
, height
- yDiff
);
519 void wxCalendarCtrl::DoGetPosition(int *x
, int *y
) const
521 wxControl::DoGetPosition(x
, y
);
523 // our real top corner is not in this position
526 *y
-= GetMonthControl()->GetSize().y
+ VERT_MARGIN
;
530 void wxCalendarCtrl::DoGetSize(int *width
, int *height
) const
532 wxControl::DoGetSize(width
, height
);
534 // our real height is bigger
537 *height
+= GetMonthControl()->GetSize().y
+ VERT_MARGIN
;
541 void wxCalendarCtrl::RecalcGeometry()
543 if ( m_widthCol
!= 0 )
550 // determine the column width (we assume that the weekday names are always
551 // wider (in any language) than the numbers)
553 wxDateTime::WeekDay wd
;
554 for ( wd
= wxDateTime::Sun
; wd
< wxDateTime::Inv_WeekDay
; wxNextWDay(wd
) )
557 dc
.GetTextExtent(m_weekdays
[wd
], &width
, &m_heightRow
);
558 if ( width
> m_widthCol
)
564 // leave some margins
569 // ----------------------------------------------------------------------------
571 // ----------------------------------------------------------------------------
573 void wxCalendarCtrl::OnPaint(wxPaintEvent
& WXUNUSED(event
))
582 wxLogDebug("--- starting to paint, selection: %s, week %u\n",
583 m_date
.Format("%a %d-%m-%Y %H:%M:%S").c_str(),
587 // first draw the week days
588 if ( IsExposed(0, 0, 7*m_widthCol
, m_heightRow
) )
591 wxLogDebug("painting the header");
594 dc
.SetBackgroundMode(wxTRANSPARENT
);
595 dc
.SetTextForeground(m_colHeaderFg
);
596 dc
.SetBrush(wxBrush(m_colHeaderBg
, wxSOLID
));
597 dc
.SetPen(wxPen(m_colHeaderBg
, 1, wxSOLID
));
598 dc
.DrawRectangle(0, 0, 7*m_widthCol
, m_heightRow
);
600 bool startOnMonday
= (GetWindowStyle() & wxCAL_MONDAY_FIRST
) != 0;
601 for ( size_t wd
= 0; wd
< 7; wd
++ )
605 n
= wd
== 6 ? 0 : wd
+ 1;
609 dc
.DrawText(m_weekdays
[n
], wd
*m_widthCol
+ 1, 0);
613 // then the calendar itself
614 dc
.SetTextForeground(*wxBLACK
);
615 //dc.SetFont(*wxNORMAL_FONT);
617 wxCoord y
= m_heightRow
;
619 wxDateTime date
= GetStartDate();
621 wxLogDebug("starting calendar from %s\n",
622 date
.Format("%a %d-%m-%Y %H:%M:%S").c_str());
625 dc
.SetBackgroundMode(wxSOLID
);
626 for ( size_t nWeek
= 1; nWeek
<= 6; nWeek
++, y
+= m_heightRow
)
628 // if the update region doesn't intersect this row, don't paint it
629 if ( !IsExposed(0, y
, 7*m_widthCol
, m_heightRow
- 1) )
631 date
+= wxDateSpan::Week();
637 wxLogDebug("painting week %d at y = %d\n", nWeek
, y
);
640 for ( size_t wd
= 0; wd
< 7; wd
++ )
642 if ( IsDateShown(date
) )
644 // don't use wxDate::Format() which prepends 0s
645 unsigned int day
= date
.GetDay();
646 wxString dayStr
= wxString::Format(_T("%u"), day
);
648 dc
.GetTextExtent(dayStr
, &width
, (wxCoord
*)NULL
);
650 bool changedColours
= FALSE
,
653 wxCalendarDateAttr
*attr
= m_attrs
[day
- 1];
655 bool isSel
= date
.IsSameDate(m_date
);
658 dc
.SetTextForeground(m_colHighlightFg
);
659 dc
.SetTextBackground(m_colHighlightBg
);
661 changedColours
= TRUE
;
665 wxColour colFg
, colBg
;
667 if ( attr
->IsHoliday() )
669 colFg
= m_colHolidayFg
;
670 colBg
= m_colHolidayBg
;
674 colFg
= attr
->GetTextColour();
675 colBg
= attr
->GetBackgroundColour();
680 dc
.SetTextForeground(colFg
);
681 changedColours
= TRUE
;
686 dc
.SetTextBackground(colBg
);
687 changedColours
= TRUE
;
690 if ( attr
->HasFont() )
692 dc
.SetFont(attr
->GetFont());
697 wxCoord x
= wd
*m_widthCol
+ (m_widthCol
- width
) / 2;
698 dc
.DrawText(dayStr
, x
, y
+ 1);
700 if ( !isSel
&& attr
&& attr
->HasBorder() )
703 if ( attr
->HasBorderColour() )
705 colBorder
= attr
->GetBorderColour();
709 colBorder
= m_foregroundColour
;
712 wxPen
pen(colBorder
, 1, wxSOLID
);
714 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
716 switch ( attr
->GetBorder() )
718 case wxCAL_BORDER_SQUARE
:
719 dc
.DrawRectangle(x
- 2, y
,
720 width
+ 4, m_heightRow
);
723 case wxCAL_BORDER_ROUND
:
724 dc
.DrawEllipse(x
- 2, y
,
725 width
+ 4, m_heightRow
);
729 wxFAIL_MSG(_T("unknown border type"));
733 if ( changedColours
)
735 dc
.SetTextForeground(m_foregroundColour
);
736 dc
.SetTextBackground(m_backgroundColour
);
744 //else: just don't draw it
746 date
+= wxDateSpan::Day();
750 wxLogDebug("+++ finished painting");
754 void wxCalendarCtrl::RefreshDate(const wxDateTime
& date
)
760 // always refresh the whole row at once because our OnPaint() will draw
761 // the whole row anyhow - and this allows the small optimisation in
762 // OnClick() below to work
764 rect
.y
= m_heightRow
* GetWeek(date
);
765 rect
.width
= 7*m_widthCol
;
766 rect
.height
= m_heightRow
;
769 // VZ: for some reason, the selected date seems to occupy more space under
770 // MSW - this is probably some bug in the font size calculations, but I
771 // don't know where exactly. This fix is ugly and leads to more
772 // refreshes than really needed, but without it the selected days
773 // leaves even more ugly underscores on screen.
778 wxLogDebug("*** refreshing week %d at (%d, %d)-(%d, %d)\n",
781 rect
.x
+ rect
.width
, rect
.y
+ rect
.height
);
784 Refresh(TRUE
, &rect
);
787 // ----------------------------------------------------------------------------
789 // ----------------------------------------------------------------------------
791 void wxCalendarCtrl::OnDClick(wxMouseEvent
& event
)
793 if ( HitTest(event
.GetPosition()) != wxCAL_HITTEST_DAY
)
799 GenerateEvent(wxEVT_CALENDAR_DOUBLECLICKED
);
803 void wxCalendarCtrl::OnClick(wxMouseEvent
& event
)
806 wxDateTime::WeekDay wday
;
807 switch ( HitTest(event
.GetPosition(), &date
, &wday
) )
809 case wxCAL_HITTEST_DAY
:
812 GenerateEvents(wxEVT_CALENDAR_DAY_CHANGED
,
813 wxEVT_CALENDAR_SEL_CHANGED
);
816 case wxCAL_HITTEST_HEADER
:
818 wxCalendarEvent
event(this, wxEVT_CALENDAR_WEEKDAY_CLICKED
);
820 (void)GetEventHandler()->ProcessEvent(event
);
825 wxFAIL_MSG(_T("unknown hittest code"));
828 case wxCAL_HITTEST_NOWHERE
:
834 wxCalendarHitTestResult
wxCalendarCtrl::HitTest(const wxPoint
& pos
,
836 wxDateTime::WeekDay
*wd
)
840 int wday
= pos
.x
/ m_widthCol
;
843 if ( y
< m_heightRow
)
847 if ( GetWindowStyle() & wxCAL_MONDAY_FIRST
)
849 wday
= wday
== 6 ? 0 : wday
+ 1;
852 *wd
= (wxDateTime::WeekDay
)wday
;
855 return wxCAL_HITTEST_HEADER
;
858 int week
= (y
- m_heightRow
) / m_heightRow
;
859 if ( week
>= 6 || wday
>= 7 )
861 return wxCAL_HITTEST_NOWHERE
;
864 wxDateTime dt
= GetStartDate() + wxDateSpan::Days(7*week
+ wday
);
866 if ( IsDateShown(dt
) )
871 return wxCAL_HITTEST_DAY
;
875 return wxCAL_HITTEST_NOWHERE
;
879 // ----------------------------------------------------------------------------
880 // subcontrols events handling
881 // ----------------------------------------------------------------------------
883 void wxCalendarCtrl::OnMonthChange(wxCommandEvent
& event
)
885 wxDateTime::Tm tm
= m_date
.GetTm();
887 wxDateTime::Month mon
= (wxDateTime::Month
)event
.GetInt();
888 if ( tm
.mday
> wxDateTime::GetNumberOfDays(mon
, tm
.year
) )
890 tm
.mday
= wxDateTime::GetNumberOfDays(mon
, tm
.year
);
893 SetDateAndNotify(wxDateTime(tm
.mday
, mon
, tm
.year
));
896 void wxCalendarCtrl::OnYearChange(wxSpinEvent
& event
)
898 wxDateTime::Tm tm
= m_date
.GetTm();
900 int year
= (int)event
.GetInt();
901 if ( tm
.mday
> wxDateTime::GetNumberOfDays(tm
.mon
, year
) )
903 tm
.mday
= wxDateTime::GetNumberOfDays(tm
.mon
, year
);
906 SetDateAndNotify(wxDateTime(tm
.mday
, tm
.mon
, year
));
909 // ----------------------------------------------------------------------------
910 // keyboard interface
911 // ----------------------------------------------------------------------------
913 void wxCalendarCtrl::OnChar(wxKeyEvent
& event
)
915 switch ( event
.KeyCode() )
919 SetDateAndNotify(m_date
+ wxDateSpan::Year());
924 SetDateAndNotify(m_date
- wxDateSpan::Year());
928 SetDateAndNotify(m_date
- wxDateSpan::Month());
932 SetDateAndNotify(m_date
+ wxDateSpan::Month());
936 if ( event
.ControlDown() )
937 SetDateAndNotify(wxDateTime(m_date
).SetToNextWeekDay(
938 GetWindowStyle() & wxCAL_MONDAY_FIRST
939 ? wxDateTime::Sun
: wxDateTime::Sat
));
941 SetDateAndNotify(m_date
+ wxDateSpan::Day());
945 if ( event
.ControlDown() )
946 SetDateAndNotify(wxDateTime(m_date
).SetToPrevWeekDay(
947 GetWindowStyle() & wxCAL_MONDAY_FIRST
948 ? wxDateTime::Mon
: wxDateTime::Sun
));
950 SetDateAndNotify(m_date
- wxDateSpan::Day());
954 SetDateAndNotify(m_date
- wxDateSpan::Week());
958 SetDateAndNotify(m_date
+ wxDateSpan::Week());
962 if ( event
.ControlDown() )
963 SetDateAndNotify(wxDateTime::Today());
965 SetDateAndNotify(wxDateTime(1, m_date
.GetMonth(), m_date
.GetYear()));
969 SetDateAndNotify(wxDateTime(m_date
).SetToLastMonthDay());
973 GenerateEvent(wxEVT_CALENDAR_DOUBLECLICKED
);
981 // ----------------------------------------------------------------------------
983 // ----------------------------------------------------------------------------
985 void wxCalendarCtrl::EnableHolidayDisplay(bool display
)
987 long style
= GetWindowStyle();
989 style
|= wxCAL_SHOW_HOLIDAYS
;
991 style
&= ~wxCAL_SHOW_HOLIDAYS
;
993 SetWindowStyle(style
);
1003 void wxCalendarCtrl::SetHolidayAttrs()
1005 if ( GetWindowStyle() & wxCAL_SHOW_HOLIDAYS
)
1007 ResetHolidayAttrs();
1009 wxDateTime::Tm tm
= m_date
.GetTm();
1010 wxDateTime
dtStart(1, tm
.mon
, tm
.year
),
1011 dtEnd
= dtStart
.GetLastMonthDay();
1013 wxDateTimeArray hol
;
1014 wxDateTimeHolidayAuthority::GetHolidaysInRange(dtStart
, dtEnd
, hol
);
1016 size_t count
= hol
.GetCount();
1017 for ( size_t n
= 0; n
< count
; n
++ )
1019 SetHoliday(hol
[n
].GetDay());
1024 void wxCalendarCtrl::SetHoliday(size_t day
)
1026 wxCHECK_RET( day
> 0 && day
< 32, _T("invalid day in SetHoliday") );
1028 wxCalendarDateAttr
*attr
= GetAttr(day
);
1031 attr
= new wxCalendarDateAttr
;
1034 attr
->SetHoliday(TRUE
);
1036 // can't use SetAttr() because it would delete this pointer
1037 m_attrs
[day
- 1] = attr
;
1040 void wxCalendarCtrl::ResetHolidayAttrs()
1042 for ( size_t day
= 0; day
< 31; day
++ )
1046 m_attrs
[day
]->SetHoliday(FALSE
);
1051 // ----------------------------------------------------------------------------
1053 // ----------------------------------------------------------------------------
1055 void wxCalendarEvent::Init()
1057 m_wday
= wxDateTime::Inv_WeekDay
;
1060 wxCalendarEvent::wxCalendarEvent(wxCalendarCtrl
*cal
, wxEventType type
)
1061 : wxCommandEvent(type
, cal
->GetId())
1063 m_date
= cal
->GetDate();
1066 #endif // wxUSE_CALENDARCTRL