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
* WXUNUSED(parent
),
184 wxWindowID
WXUNUSED(id
),
185 const wxDateTime
& date
,
186 const wxPoint
& WXUNUSED(pos
),
189 const wxString
& WXUNUSED(name
))
191 // needed to get the arrow keys normally used for the dialog navigation
192 SetWindowStyle(style
| wxWANTS_CHARS
);
194 m_date
= date
.IsValid() ? date
: wxDateTime::Today();
196 m_spinYear
= new wxYearSpinCtrl(this);
197 m_staticYear
= new wxStaticText(GetParent(), -1, m_date
.Format(_T("%Y")),
198 wxDefaultPosition
, wxDefaultSize
,
201 m_comboMonth
= new wxMonthComboBox(this);
202 m_staticMonth
= new wxStaticText(GetParent(), -1, m_date
.Format(_T("%B")),
203 wxDefaultPosition
, wxDefaultSize
,
206 ShowCurrentControls();
209 if ( size
.x
== -1 || size
.y
== -1 )
211 sizeReal
= DoGetBestSize();
224 SetBackgroundColour(*wxWHITE
);
225 SetFont(*wxSWISS_FONT
);
232 wxCalendarCtrl::~wxCalendarCtrl()
234 for ( size_t n
= 0; n
< WXSIZEOF(m_attrs
); n
++ )
240 // ----------------------------------------------------------------------------
241 // forward wxWin functions to subcontrols
242 // ----------------------------------------------------------------------------
244 bool wxCalendarCtrl::Show(bool show
)
246 if ( !wxControl::Show(show
) )
251 GetMonthControl()->Show(show
);
252 GetYearControl()->Show(show
);
257 bool wxCalendarCtrl::Enable(bool enable
)
259 if ( !wxControl::Enable(enable
) )
264 GetMonthControl()->Enable(enable
);
265 GetYearControl()->Enable(enable
);
270 // ----------------------------------------------------------------------------
271 // enable/disable month/year controls
272 // ----------------------------------------------------------------------------
274 void wxCalendarCtrl::ShowCurrentControls()
276 if ( AllowMonthChange() )
278 m_comboMonth
->Show();
279 m_staticMonth
->Hide();
281 if ( AllowYearChange() )
284 m_staticYear
->Hide();
292 m_comboMonth
->Hide();
293 m_staticMonth
->Show();
296 // year change not allowed here
298 m_staticYear
->Show();
301 wxControl
*wxCalendarCtrl::GetMonthControl() const
303 return AllowMonthChange() ? (wxControl
*)m_comboMonth
: (wxControl
*)m_staticMonth
;
306 wxControl
*wxCalendarCtrl::GetYearControl() const
308 return AllowYearChange() ? (wxControl
*)m_spinYear
: (wxControl
*)m_staticYear
;
311 void wxCalendarCtrl::EnableYearChange(bool enable
)
313 if ( enable
!= AllowYearChange() )
315 long style
= GetWindowStyle();
317 style
&= ~wxCAL_NO_YEAR_CHANGE
;
319 style
|= wxCAL_NO_YEAR_CHANGE
;
320 SetWindowStyle(style
);
322 ShowCurrentControls();
326 void wxCalendarCtrl::EnableMonthChange(bool enable
)
328 if ( enable
!= AllowMonthChange() )
330 long style
= GetWindowStyle();
332 style
&= ~wxCAL_NO_MONTH_CHANGE
;
334 style
|= wxCAL_NO_MONTH_CHANGE
;
335 SetWindowStyle(style
);
337 ShowCurrentControls();
341 // ----------------------------------------------------------------------------
343 // ----------------------------------------------------------------------------
345 void wxCalendarCtrl::SetDate(const wxDateTime
& date
)
347 bool sameMonth
= m_date
.GetMonth() == date
.GetMonth(),
348 sameYear
= m_date
.GetYear() == date
.GetYear();
350 if ( sameMonth
&& sameYear
)
352 // just change the day
357 if ( !AllowMonthChange() || (!AllowYearChange() && !sameYear
) )
366 // update the controls
367 m_comboMonth
->SetSelection(m_date
.GetMonth());
369 if ( AllowYearChange() )
371 m_spinYear
->SetValue(m_date
.Format(_T("%Y")));
374 // as the month changed, holidays did too
377 // update the calendar
382 void wxCalendarCtrl::ChangeDay(const wxDateTime
& date
)
384 if ( m_date
!= date
)
386 // we need to refresh the row containing the old date and the one
387 // containing the new one
388 wxDateTime dateOld
= m_date
;
391 RefreshDate(dateOld
);
393 // if the date is in the same row, it was already drawn correctly
394 if ( GetWeek(m_date
) != GetWeek(dateOld
) )
401 void wxCalendarCtrl::SetDateAndNotify(const wxDateTime
& date
)
403 wxDateTime::Tm tm1
= m_date
.GetTm(),
407 if ( tm1
.year
!= tm2
.year
)
408 type
= wxEVT_CALENDAR_YEAR_CHANGED
;
409 else if ( tm1
.mon
!= tm2
.mon
)
410 type
= wxEVT_CALENDAR_MONTH_CHANGED
;
411 else if ( tm1
.mday
!= tm2
.mday
)
412 type
= wxEVT_CALENDAR_DAY_CHANGED
;
418 GenerateEvents(type
, wxEVT_CALENDAR_SEL_CHANGED
);
421 // ----------------------------------------------------------------------------
423 // ----------------------------------------------------------------------------
425 wxDateTime
wxCalendarCtrl::GetStartDate() const
427 wxDateTime::Tm tm
= m_date
.GetTm();
429 wxDateTime date
= wxDateTime(1, tm
.mon
, tm
.year
);
432 date
.SetToPrevWeekDay(GetWindowStyle() & wxCAL_MONDAY_FIRST
433 ? wxDateTime::Mon
: wxDateTime::Sun
);
438 bool wxCalendarCtrl::IsDateShown(const wxDateTime
& date
) const
440 return date
.GetMonth() == m_date
.GetMonth();
443 size_t wxCalendarCtrl::GetWeek(const wxDateTime
& date
) const
445 return date
.GetWeekOfMonth(GetWindowStyle() & wxCAL_MONDAY_FIRST
446 ? wxDateTime::Monday_First
447 : wxDateTime::Sunday_First
);
450 // ----------------------------------------------------------------------------
452 // ----------------------------------------------------------------------------
454 // this is a composite control and it must arrange its parts each time its
455 // size or position changes: the combobox and spinctrl are along the top of
456 // the available area and the calendar takes up therest of the space
458 // the static controls are supposed to be always smaller than combo/spin so we
459 // always use the latter for size calculations and position the static to take
462 // the constants used for the layout
463 #define VERT_MARGIN 5 // distance between combo and calendar
464 #define HORZ_MARGIN 15 // spin
466 wxSize
wxCalendarCtrl::DoGetBestSize() const
468 // calc the size of the calendar
469 ((wxCalendarCtrl
*)this)->RecalcGeometry(); // const_cast
471 wxCoord width
= 7*m_widthCol
,
472 height
= 7*m_heightRow
;
474 // the combobox doesn't report its height correctly (it returns the
475 // height including the drop down list) so don't use it
476 height
+= VERT_MARGIN
+ m_spinYear
->GetBestSize().y
;
478 if ( GetWindowStyle() & (wxRAISED_BORDER
| wxSUNKEN_BORDER
) )
480 // the border would clip the last line otherwise
484 return wxSize(width
, height
);
487 void wxCalendarCtrl::DoSetSize(int x
, int y
,
488 int width
, int height
,
491 wxControl::DoSetSize(x
, y
, width
, height
, sizeFlags
);
494 void wxCalendarCtrl::DoMoveWindow(int x
, int y
, int width
, int height
)
496 wxSize sizeCombo
= m_comboMonth
->GetSize();
497 wxSize sizeStatic
= m_staticMonth
->GetSize();
499 int dy
= (sizeCombo
.y
- sizeStatic
.y
) / 2;
500 m_comboMonth
->Move(x
, y
);
501 m_staticMonth
->SetSize(x
, y
+ dy
, sizeCombo
.x
, sizeStatic
.y
);
503 int xDiff
= sizeCombo
.x
+ HORZ_MARGIN
;
504 m_spinYear
->SetSize(x
+ xDiff
, y
, width
- xDiff
, sizeCombo
.y
);
505 m_staticYear
->SetSize(x
+ xDiff
, y
+ dy
, width
- xDiff
, sizeStatic
.y
);
507 wxSize sizeSpin
= m_spinYear
->GetSize();
508 int yDiff
= wxMax(sizeSpin
.y
, sizeCombo
.y
) + VERT_MARGIN
;
510 wxControl::DoMoveWindow(x
, y
+ yDiff
, width
, height
- yDiff
);
513 void wxCalendarCtrl::DoGetPosition(int *x
, int *y
) const
515 wxControl::DoGetPosition(x
, y
);
517 // our real top corner is not in this position
520 *y
-= GetMonthControl()->GetSize().y
+ VERT_MARGIN
;
524 void wxCalendarCtrl::DoGetSize(int *width
, int *height
) const
526 wxControl::DoGetSize(width
, height
);
528 // our real height is bigger
531 *height
+= GetMonthControl()->GetSize().y
+ VERT_MARGIN
;
535 void wxCalendarCtrl::RecalcGeometry()
537 if ( m_widthCol
!= 0 )
544 // determine the column width (we assume that the weekday names are always
545 // wider (in any language) than the numbers)
547 wxDateTime::WeekDay wd
;
548 for ( wd
= wxDateTime::Sun
; wd
< wxDateTime::Inv_WeekDay
; wxNextWDay(wd
) )
551 dc
.GetTextExtent(m_weekdays
[wd
], &width
, &m_heightRow
);
552 if ( width
> m_widthCol
)
558 // leave some margins
563 // ----------------------------------------------------------------------------
565 // ----------------------------------------------------------------------------
567 void wxCalendarCtrl::OnPaint(wxPaintEvent
& WXUNUSED(event
))
576 wxLogDebug("--- starting to paint, selection: %s, week %u\n",
577 m_date
.Format("%a %d-%m-%Y %H:%M:%S").c_str(),
581 // first draw the week days
582 if ( IsExposed(0, 0, 7*m_widthCol
, m_heightRow
) )
585 wxLogDebug("painting the header");
588 dc
.SetBackgroundMode(wxTRANSPARENT
);
589 dc
.SetTextForeground(m_colHeaderFg
);
590 dc
.SetBrush(wxBrush(m_colHeaderBg
, wxSOLID
));
591 dc
.SetPen(wxPen(m_colHeaderBg
, 1, wxSOLID
));
592 dc
.DrawRectangle(0, 0, 7*m_widthCol
, m_heightRow
);
594 bool startOnMonday
= (GetWindowStyle() & wxCAL_MONDAY_FIRST
) != 0;
595 for ( size_t wd
= 0; wd
< 7; wd
++ )
599 n
= wd
== 6 ? 0 : wd
+ 1;
603 dc
.DrawText(m_weekdays
[n
], wd
*m_widthCol
+ 1, 0);
607 // then the calendar itself
608 dc
.SetTextForeground(*wxBLACK
);
609 //dc.SetFont(*wxNORMAL_FONT);
611 wxCoord y
= m_heightRow
;
613 wxDateTime date
= GetStartDate();
615 wxLogDebug("starting calendar from %s\n",
616 date
.Format("%a %d-%m-%Y %H:%M:%S").c_str());
619 dc
.SetBackgroundMode(wxSOLID
);
620 for ( size_t nWeek
= 1; nWeek
<= 6; nWeek
++, y
+= m_heightRow
)
622 // if the update region doesn't intersect this row, don't paint it
623 if ( !IsExposed(0, y
, 7*m_widthCol
, m_heightRow
- 1) )
625 date
+= wxDateSpan::Week();
631 wxLogDebug("painting week %d at y = %d\n", nWeek
, y
);
634 for ( size_t wd
= 0; wd
< 7; wd
++ )
636 if ( IsDateShown(date
) )
638 // don't use wxDate::Format() which prepends 0s
639 unsigned int day
= date
.GetDay();
640 wxString dayStr
= wxString::Format(_T("%u"), day
);
642 dc
.GetTextExtent(dayStr
, &width
, (wxCoord
*)NULL
);
644 bool changedColours
= FALSE
,
647 wxCalendarDateAttr
*attr
= m_attrs
[day
- 1];
649 bool isSel
= date
.IsSameDate(m_date
);
652 dc
.SetTextForeground(m_colHighlightFg
);
653 dc
.SetTextBackground(m_colHighlightBg
);
655 changedColours
= TRUE
;
659 wxColour colFg
, colBg
;
661 if ( attr
->IsHoliday() )
663 colFg
= m_colHolidayFg
;
664 colBg
= m_colHolidayBg
;
668 colFg
= attr
->GetTextColour();
669 colBg
= attr
->GetBackgroundColour();
674 dc
.SetTextForeground(colFg
);
675 changedColours
= TRUE
;
680 dc
.SetTextBackground(colBg
);
681 changedColours
= TRUE
;
684 if ( attr
->HasFont() )
686 dc
.SetFont(attr
->GetFont());
691 wxCoord x
= wd
*m_widthCol
+ (m_widthCol
- width
) / 2;
692 dc
.DrawText(dayStr
, x
, y
+ 1);
694 if ( !isSel
&& attr
&& attr
->HasBorder() )
697 if ( attr
->HasBorderColour() )
699 colBorder
= attr
->GetBorderColour();
703 colBorder
= m_foregroundColour
;
706 wxPen
pen(colBorder
, 1, wxSOLID
);
708 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
710 switch ( attr
->GetBorder() )
712 case wxCAL_BORDER_SQUARE
:
713 dc
.DrawRectangle(x
- 2, y
,
714 width
+ 4, m_heightRow
);
717 case wxCAL_BORDER_ROUND
:
718 dc
.DrawEllipse(x
- 2, y
,
719 width
+ 4, m_heightRow
);
723 wxFAIL_MSG(_T("unknown border type"));
727 if ( changedColours
)
729 dc
.SetTextForeground(m_foregroundColour
);
730 dc
.SetTextBackground(m_backgroundColour
);
738 //else: just don't draw it
740 date
+= wxDateSpan::Day();
744 wxLogDebug("+++ finished painting");
748 void wxCalendarCtrl::RefreshDate(const wxDateTime
& date
)
754 // always refresh the whole row at once because our OnPaint() will draw
755 // the whole row anyhow - and this allows the small optimisation in
756 // OnClick() below to work
758 rect
.y
= m_heightRow
* GetWeek(date
);
759 rect
.width
= 7*m_widthCol
;
760 rect
.height
= m_heightRow
;
763 // VZ: for some reason, the selected date seems to occupy more space under
764 // MSW - this is probably some bug in the font size calculations, but I
765 // don't know where exactly. This fix is ugly and leads to more
766 // refreshes than really needed, but without it the selected days
767 // leaves even more ugly underscores on screen.
772 wxLogDebug("*** refreshing week %d at (%d, %d)-(%d, %d)\n",
775 rect
.x
+ rect
.width
, rect
.y
+ rect
.height
);
778 Refresh(TRUE
, &rect
);
781 // ----------------------------------------------------------------------------
783 // ----------------------------------------------------------------------------
785 void wxCalendarCtrl::OnDClick(wxMouseEvent
& event
)
787 if ( HitTest(event
.GetPosition()) != wxCAL_HITTEST_DAY
)
793 GenerateEvent(wxEVT_CALENDAR_DOUBLECLICKED
);
797 void wxCalendarCtrl::OnClick(wxMouseEvent
& event
)
800 wxDateTime::WeekDay wday
;
801 switch ( HitTest(event
.GetPosition(), &date
, &wday
) )
803 case wxCAL_HITTEST_DAY
:
806 GenerateEvents(wxEVT_CALENDAR_DAY_CHANGED
,
807 wxEVT_CALENDAR_SEL_CHANGED
);
810 case wxCAL_HITTEST_HEADER
:
812 wxCalendarEvent
event(this, wxEVT_CALENDAR_WEEKDAY_CLICKED
);
814 (void)GetEventHandler()->ProcessEvent(event
);
819 wxFAIL_MSG(_T("unknown hittest code"));
822 case wxCAL_HITTEST_NOWHERE
:
828 wxCalendarHitTestResult
wxCalendarCtrl::HitTest(const wxPoint
& pos
,
830 wxDateTime::WeekDay
*wd
)
834 int wday
= pos
.x
/ m_widthCol
;
837 if ( y
< m_heightRow
)
841 if ( GetWindowStyle() & wxCAL_MONDAY_FIRST
)
843 wday
= wday
== 6 ? 0 : wday
+ 1;
846 *wd
= (wxDateTime::WeekDay
)wday
;
849 return wxCAL_HITTEST_HEADER
;
852 int week
= (y
- m_heightRow
) / m_heightRow
;
853 if ( week
>= 6 || wday
>= 7 )
855 return wxCAL_HITTEST_NOWHERE
;
858 wxDateTime dt
= GetStartDate() + wxDateSpan::Days(7*week
+ wday
);
860 if ( IsDateShown(dt
) )
865 return wxCAL_HITTEST_DAY
;
869 return wxCAL_HITTEST_NOWHERE
;
873 // ----------------------------------------------------------------------------
874 // subcontrols events handling
875 // ----------------------------------------------------------------------------
877 void wxCalendarCtrl::OnMonthChange(wxCommandEvent
& event
)
879 wxDateTime::Tm tm
= m_date
.GetTm();
881 wxDateTime::Month mon
= (wxDateTime::Month
)event
.GetInt();
882 if ( tm
.mday
> wxDateTime::GetNumberOfDays(mon
, tm
.year
) )
884 tm
.mday
= wxDateTime::GetNumberOfDays(mon
, tm
.year
);
887 SetDateAndNotify(wxDateTime(tm
.mday
, mon
, tm
.year
));
890 void wxCalendarCtrl::OnYearChange(wxSpinEvent
& event
)
892 wxDateTime::Tm tm
= m_date
.GetTm();
894 int year
= (int)event
.GetInt();
895 if ( tm
.mday
> wxDateTime::GetNumberOfDays(tm
.mon
, year
) )
897 tm
.mday
= wxDateTime::GetNumberOfDays(tm
.mon
, year
);
900 SetDateAndNotify(wxDateTime(tm
.mday
, tm
.mon
, year
));
903 // ----------------------------------------------------------------------------
904 // keyboard interface
905 // ----------------------------------------------------------------------------
907 void wxCalendarCtrl::OnChar(wxKeyEvent
& event
)
909 switch ( event
.KeyCode() )
913 SetDateAndNotify(m_date
+ wxDateSpan::Year());
918 SetDateAndNotify(m_date
- wxDateSpan::Year());
922 SetDateAndNotify(m_date
- wxDateSpan::Month());
926 SetDateAndNotify(m_date
+ wxDateSpan::Month());
930 if ( event
.ControlDown() )
931 SetDateAndNotify(wxDateTime(m_date
).SetToNextWeekDay(
932 GetWindowStyle() & wxCAL_MONDAY_FIRST
933 ? wxDateTime::Sun
: wxDateTime::Sat
));
935 SetDateAndNotify(m_date
+ wxDateSpan::Day());
939 if ( event
.ControlDown() )
940 SetDateAndNotify(wxDateTime(m_date
).SetToPrevWeekDay(
941 GetWindowStyle() & wxCAL_MONDAY_FIRST
942 ? wxDateTime::Mon
: wxDateTime::Sun
));
944 SetDateAndNotify(m_date
- wxDateSpan::Day());
948 SetDateAndNotify(m_date
- wxDateSpan::Week());
952 SetDateAndNotify(m_date
+ wxDateSpan::Week());
956 if ( event
.ControlDown() )
957 SetDateAndNotify(wxDateTime::Today());
959 SetDateAndNotify(wxDateTime(1, m_date
.GetMonth(), m_date
.GetYear()));
963 SetDateAndNotify(wxDateTime(m_date
).SetToLastMonthDay());
967 GenerateEvent(wxEVT_CALENDAR_DOUBLECLICKED
);
975 // ----------------------------------------------------------------------------
977 // ----------------------------------------------------------------------------
979 void wxCalendarCtrl::EnableHolidayDisplay(bool display
)
981 long style
= GetWindowStyle();
983 style
|= wxCAL_SHOW_HOLIDAYS
;
985 style
&= ~wxCAL_SHOW_HOLIDAYS
;
987 SetWindowStyle(style
);
997 void wxCalendarCtrl::SetHolidayAttrs()
999 if ( GetWindowStyle() & wxCAL_SHOW_HOLIDAYS
)
1001 ResetHolidayAttrs();
1003 wxDateTime::Tm tm
= m_date
.GetTm();
1004 wxDateTime
dtStart(1, tm
.mon
, tm
.year
),
1005 dtEnd
= dtStart
.GetLastMonthDay();
1007 wxDateTimeArray hol
;
1008 wxDateTimeHolidayAuthority::GetHolidaysInRange(dtStart
, dtEnd
, hol
);
1010 size_t count
= hol
.GetCount();
1011 for ( size_t n
= 0; n
< count
; n
++ )
1013 SetHoliday(hol
[n
].GetDay());
1018 void wxCalendarCtrl::SetHoliday(size_t day
)
1020 wxCHECK_RET( day
> 0 && day
< 32, _T("invalid day in SetHoliday") );
1022 wxCalendarDateAttr
*attr
= GetAttr(day
);
1025 attr
= new wxCalendarDateAttr
;
1028 attr
->SetHoliday(TRUE
);
1030 // can't use SetAttr() because it would delete this pointer
1031 m_attrs
[day
- 1] = attr
;
1034 void wxCalendarCtrl::ResetHolidayAttrs()
1036 for ( size_t day
= 0; day
< 31; day
++ )
1040 m_attrs
[day
]->SetHoliday(FALSE
);
1045 // ----------------------------------------------------------------------------
1047 // ----------------------------------------------------------------------------
1049 void wxCalendarEvent::Init()
1051 m_wday
= wxDateTime::Inv_WeekDay
;
1054 wxCalendarEvent::wxCalendarEvent(wxCalendarCtrl
*cal
, wxEventType type
)
1055 : wxCommandEvent(type
, cal
->GetId())
1057 m_date
= cal
->GetDate();
1060 #endif // wxUSE_CALENDARCTRL