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 // Can only use wxSpinEvent if this is enabled
42 #include "wx/calctrl.h"
46 // ----------------------------------------------------------------------------
48 // ----------------------------------------------------------------------------
50 class wxMonthComboBox
: public wxComboBox
53 wxMonthComboBox(wxCalendarCtrl
*cal
);
55 void OnMonthChange(wxCommandEvent
& event
) { m_cal
->OnMonthChange(event
); }
58 wxCalendarCtrl
*m_cal
;
63 class wxYearSpinCtrl
: public wxSpinCtrl
66 wxYearSpinCtrl(wxCalendarCtrl
*cal
);
68 void OnYearChange(wxSpinEvent
& event
) { m_cal
->OnYearChange(event
); }
71 wxCalendarCtrl
*m_cal
;
76 // ----------------------------------------------------------------------------
78 // ----------------------------------------------------------------------------
80 BEGIN_EVENT_TABLE(wxCalendarCtrl
, wxControl
)
81 EVT_PAINT(wxCalendarCtrl::OnPaint
)
83 EVT_CHAR(wxCalendarCtrl::OnChar
)
85 EVT_LEFT_DOWN(wxCalendarCtrl::OnClick
)
86 EVT_LEFT_DCLICK(wxCalendarCtrl::OnDClick
)
89 BEGIN_EVENT_TABLE(wxMonthComboBox
, wxComboBox
)
90 EVT_COMBOBOX(-1, wxMonthComboBox::OnMonthChange
)
93 BEGIN_EVENT_TABLE(wxYearSpinCtrl
, wxSpinCtrl
)
94 EVT_SPINCTRL(-1, wxYearSpinCtrl::OnYearChange
)
97 IMPLEMENT_DYNAMIC_CLASS(wxCalendarCtrl
, wxControl
)
98 IMPLEMENT_DYNAMIC_CLASS(wxCalendarEvent
, wxCommandEvent
)
100 // ----------------------------------------------------------------------------
102 // ----------------------------------------------------------------------------
104 DEFINE_EVENT_TYPE(wxEVT_CALENDAR_SEL_CHANGED
)
105 DEFINE_EVENT_TYPE(wxEVT_CALENDAR_DAY_CHANGED
)
106 DEFINE_EVENT_TYPE(wxEVT_CALENDAR_MONTH_CHANGED
)
107 DEFINE_EVENT_TYPE(wxEVT_CALENDAR_YEAR_CHANGED
)
108 DEFINE_EVENT_TYPE(wxEVT_CALENDAR_DOUBLECLICKED
)
109 DEFINE_EVENT_TYPE(wxEVT_CALENDAR_WEEKDAY_CLICKED
)
111 // ============================================================================
113 // ============================================================================
115 // ----------------------------------------------------------------------------
116 // wxMonthComboBox and wxYearSpinCtrl
117 // ----------------------------------------------------------------------------
119 wxMonthComboBox::wxMonthComboBox(wxCalendarCtrl
*cal
)
120 : wxComboBox(cal
->GetParent(), -1,
130 for ( m
= wxDateTime::Jan
; m
< wxDateTime::Inv_Month
; wxNextMonth(m
) )
132 Append(wxDateTime::GetMonthName(m
));
135 SetSelection(m_cal
->GetDate().GetMonth());
136 SetSize(-1, -1, -1, -1, wxSIZE_AUTO_WIDTH
|wxSIZE_AUTO_HEIGHT
);
139 wxYearSpinCtrl::wxYearSpinCtrl(wxCalendarCtrl
*cal
)
140 : wxSpinCtrl(cal
->GetParent(), -1,
141 cal
->GetDate().Format(_T("%Y")),
145 -4300, 10000, cal
->GetDate().GetYear())
150 // ----------------------------------------------------------------------------
152 // ----------------------------------------------------------------------------
154 void wxCalendarCtrl::Init()
162 wxDateTime::WeekDay wd
;
163 for ( wd
= wxDateTime::Sun
; wd
< wxDateTime::Inv_WeekDay
; wxNextWDay(wd
) )
165 m_weekdays
[wd
] = wxDateTime::GetWeekDayName(wd
, wxDateTime::Name_Abbr
);
168 for ( size_t n
= 0; n
< WXSIZEOF(m_attrs
); n
++ )
174 m_colHighlightFg
= ss
.GetSystemColour(wxSYS_COLOUR_HIGHLIGHTTEXT
);
175 m_colHighlightBg
= ss
.GetSystemColour(wxSYS_COLOUR_HIGHLIGHT
);
177 m_colHolidayFg
= *wxRED
;
178 // don't set m_colHolidayBg - by default, same as our bg colour
180 m_colHeaderFg
= *wxBLUE
;
181 m_colHeaderBg
= *wxLIGHT_GREY
;
184 bool wxCalendarCtrl::Create(wxWindow
* WXUNUSED(parent
),
185 wxWindowID
WXUNUSED(id
),
186 const wxDateTime
& date
,
187 const wxPoint
& WXUNUSED(pos
),
190 const wxString
& WXUNUSED(name
))
192 // needed to get the arrow keys normally used for the dialog navigation
193 SetWindowStyle(style
| wxWANTS_CHARS
);
195 m_date
= date
.IsValid() ? date
: wxDateTime::Today();
197 m_spinYear
= new wxYearSpinCtrl(this);
198 m_staticYear
= new wxStaticText(GetParent(), -1, m_date
.Format(_T("%Y")),
199 wxDefaultPosition
, wxDefaultSize
,
202 m_comboMonth
= new wxMonthComboBox(this);
203 m_staticMonth
= new wxStaticText(GetParent(), -1, m_date
.Format(_T("%B")),
204 wxDefaultPosition
, wxDefaultSize
,
207 ShowCurrentControls();
210 if ( size
.x
== -1 || size
.y
== -1 )
212 sizeReal
= DoGetBestSize();
225 SetBackgroundColour(*wxWHITE
);
226 SetFont(*wxSWISS_FONT
);
233 wxCalendarCtrl::~wxCalendarCtrl()
235 for ( size_t n
= 0; n
< WXSIZEOF(m_attrs
); n
++ )
241 // ----------------------------------------------------------------------------
242 // forward wxWin functions to subcontrols
243 // ----------------------------------------------------------------------------
245 bool wxCalendarCtrl::Show(bool show
)
247 if ( !wxControl::Show(show
) )
252 GetMonthControl()->Show(show
);
253 GetYearControl()->Show(show
);
258 bool wxCalendarCtrl::Enable(bool enable
)
260 if ( !wxControl::Enable(enable
) )
265 GetMonthControl()->Enable(enable
);
266 GetYearControl()->Enable(enable
);
271 // ----------------------------------------------------------------------------
272 // enable/disable month/year controls
273 // ----------------------------------------------------------------------------
275 void wxCalendarCtrl::ShowCurrentControls()
277 if ( AllowMonthChange() )
279 m_comboMonth
->Show();
280 m_staticMonth
->Hide();
282 if ( AllowYearChange() )
285 m_staticYear
->Hide();
293 m_comboMonth
->Hide();
294 m_staticMonth
->Show();
297 // year change not allowed here
299 m_staticYear
->Show();
302 wxControl
*wxCalendarCtrl::GetMonthControl() const
304 return AllowMonthChange() ? (wxControl
*)m_comboMonth
: (wxControl
*)m_staticMonth
;
307 wxControl
*wxCalendarCtrl::GetYearControl() const
309 return AllowYearChange() ? (wxControl
*)m_spinYear
: (wxControl
*)m_staticYear
;
312 void wxCalendarCtrl::EnableYearChange(bool enable
)
314 if ( enable
!= AllowYearChange() )
316 long style
= GetWindowStyle();
318 style
&= ~wxCAL_NO_YEAR_CHANGE
;
320 style
|= wxCAL_NO_YEAR_CHANGE
;
321 SetWindowStyle(style
);
323 ShowCurrentControls();
327 void wxCalendarCtrl::EnableMonthChange(bool enable
)
329 if ( enable
!= AllowMonthChange() )
331 long style
= GetWindowStyle();
333 style
&= ~wxCAL_NO_MONTH_CHANGE
;
335 style
|= wxCAL_NO_MONTH_CHANGE
;
336 SetWindowStyle(style
);
338 ShowCurrentControls();
342 // ----------------------------------------------------------------------------
344 // ----------------------------------------------------------------------------
346 void wxCalendarCtrl::SetDate(const wxDateTime
& date
)
348 bool sameMonth
= m_date
.GetMonth() == date
.GetMonth(),
349 sameYear
= m_date
.GetYear() == date
.GetYear();
351 if ( sameMonth
&& sameYear
)
353 // just change the day
358 if ( !AllowMonthChange() || (!AllowYearChange() && !sameYear
) )
367 // update the controls
368 m_comboMonth
->SetSelection(m_date
.GetMonth());
370 if ( AllowYearChange() )
372 m_spinYear
->SetValue(m_date
.Format(_T("%Y")));
375 // as the month changed, holidays did too
378 // update the calendar
383 void wxCalendarCtrl::ChangeDay(const wxDateTime
& date
)
385 if ( m_date
!= date
)
387 // we need to refresh the row containing the old date and the one
388 // containing the new one
389 wxDateTime dateOld
= m_date
;
392 RefreshDate(dateOld
);
394 // if the date is in the same row, it was already drawn correctly
395 if ( GetWeek(m_date
) != GetWeek(dateOld
) )
402 void wxCalendarCtrl::SetDateAndNotify(const wxDateTime
& date
)
404 wxDateTime::Tm tm1
= m_date
.GetTm(),
408 if ( tm1
.year
!= tm2
.year
)
409 type
= wxEVT_CALENDAR_YEAR_CHANGED
;
410 else if ( tm1
.mon
!= tm2
.mon
)
411 type
= wxEVT_CALENDAR_MONTH_CHANGED
;
412 else if ( tm1
.mday
!= tm2
.mday
)
413 type
= wxEVT_CALENDAR_DAY_CHANGED
;
419 GenerateEvents(type
, wxEVT_CALENDAR_SEL_CHANGED
);
422 // ----------------------------------------------------------------------------
424 // ----------------------------------------------------------------------------
426 wxDateTime
wxCalendarCtrl::GetStartDate() const
428 wxDateTime::Tm tm
= m_date
.GetTm();
430 wxDateTime date
= wxDateTime(1, tm
.mon
, tm
.year
);
433 date
.SetToPrevWeekDay(GetWindowStyle() & wxCAL_MONDAY_FIRST
434 ? wxDateTime::Mon
: wxDateTime::Sun
);
439 bool wxCalendarCtrl::IsDateShown(const wxDateTime
& date
) const
441 return date
.GetMonth() == m_date
.GetMonth();
444 size_t wxCalendarCtrl::GetWeek(const wxDateTime
& date
) const
446 return date
.GetWeekOfMonth(GetWindowStyle() & wxCAL_MONDAY_FIRST
447 ? wxDateTime::Monday_First
448 : wxDateTime::Sunday_First
);
451 // ----------------------------------------------------------------------------
453 // ----------------------------------------------------------------------------
455 // this is a composite control and it must arrange its parts each time its
456 // size or position changes: the combobox and spinctrl are along the top of
457 // the available area and the calendar takes up therest of the space
459 // the static controls are supposed to be always smaller than combo/spin so we
460 // always use the latter for size calculations and position the static to take
463 // the constants used for the layout
464 #define VERT_MARGIN 5 // distance between combo and calendar
465 #define HORZ_MARGIN 15 // spin
467 wxSize
wxCalendarCtrl::DoGetBestSize() const
469 // calc the size of the calendar
470 ((wxCalendarCtrl
*)this)->RecalcGeometry(); // const_cast
472 wxCoord width
= 7*m_widthCol
,
473 height
= 7*m_heightRow
;
475 wxSize sizeCombo
= m_comboMonth
->GetBestSize(),
476 sizeSpin
= m_spinYear
->GetBestSize();
478 height
+= VERT_MARGIN
+ wxMax(sizeCombo
.y
, sizeSpin
.y
);
480 if ( GetWindowStyle() & (wxRAISED_BORDER
| wxSUNKEN_BORDER
) )
482 // the border would clip the last line otherwise
486 return wxSize(width
, height
);
489 void wxCalendarCtrl::DoSetSize(int x
, int y
,
490 int width
, int height
,
493 wxControl::DoSetSize(x
, y
, width
, height
, sizeFlags
);
496 void wxCalendarCtrl::DoMoveWindow(int x
, int y
, int width
, int height
)
498 wxSize sizeCombo
= m_comboMonth
->GetSize();
499 wxSize sizeStatic
= m_staticMonth
->GetSize();
501 int dy
= (sizeCombo
.y
- sizeStatic
.y
) / 2;
502 m_comboMonth
->Move(x
, y
);
503 m_staticMonth
->SetSize(x
, y
+ dy
, sizeCombo
.x
, sizeStatic
.y
);
505 int xDiff
= sizeCombo
.x
+ HORZ_MARGIN
;
506 m_spinYear
->SetSize(x
+ xDiff
, y
, width
- xDiff
, sizeCombo
.y
);
507 m_staticYear
->SetSize(x
+ xDiff
, y
+ dy
, width
- xDiff
, sizeStatic
.y
);
509 wxSize sizeSpin
= m_spinYear
->GetSize();
510 int yDiff
= wxMax(sizeSpin
.y
, sizeCombo
.y
) + VERT_MARGIN
;
512 wxControl::DoMoveWindow(x
, y
+ yDiff
, width
, height
- yDiff
);
515 void wxCalendarCtrl::DoGetPosition(int *x
, int *y
) const
517 wxControl::DoGetPosition(x
, y
);
519 // our real top corner is not in this position
522 *y
-= GetMonthControl()->GetSize().y
+ VERT_MARGIN
;
526 void wxCalendarCtrl::DoGetSize(int *width
, int *height
) const
528 wxControl::DoGetSize(width
, height
);
530 // our real height is bigger
533 *height
+= GetMonthControl()->GetSize().y
+ VERT_MARGIN
;
537 void wxCalendarCtrl::RecalcGeometry()
539 if ( m_widthCol
!= 0 )
546 // determine the column width (we assume that the weekday names are always
547 // wider (in any language) than the numbers)
549 wxDateTime::WeekDay wd
;
550 for ( wd
= wxDateTime::Sun
; wd
< wxDateTime::Inv_WeekDay
; wxNextWDay(wd
) )
553 dc
.GetTextExtent(m_weekdays
[wd
], &width
, &m_heightRow
);
554 if ( width
> m_widthCol
)
560 // leave some margins
565 // ----------------------------------------------------------------------------
567 // ----------------------------------------------------------------------------
569 void wxCalendarCtrl::OnPaint(wxPaintEvent
& WXUNUSED(event
))
578 wxLogDebug("--- starting to paint, selection: %s, week %u\n",
579 m_date
.Format("%a %d-%m-%Y %H:%M:%S").c_str(),
583 // first draw the week days
584 if ( IsExposed(0, 0, 7*m_widthCol
, m_heightRow
) )
587 wxLogDebug("painting the header");
590 dc
.SetBackgroundMode(wxTRANSPARENT
);
591 dc
.SetTextForeground(m_colHeaderFg
);
592 dc
.SetBrush(wxBrush(m_colHeaderBg
, wxSOLID
));
593 dc
.SetPen(wxPen(m_colHeaderBg
, 1, wxSOLID
));
594 dc
.DrawRectangle(0, 0, 7*m_widthCol
, m_heightRow
);
596 bool startOnMonday
= (GetWindowStyle() & wxCAL_MONDAY_FIRST
) != 0;
597 for ( size_t wd
= 0; wd
< 7; wd
++ )
601 n
= wd
== 6 ? 0 : wd
+ 1;
605 dc
.DrawText(m_weekdays
[n
], wd
*m_widthCol
+ 1, 0);
609 // then the calendar itself
610 dc
.SetTextForeground(*wxBLACK
);
611 //dc.SetFont(*wxNORMAL_FONT);
613 wxCoord y
= m_heightRow
;
615 wxDateTime date
= GetStartDate();
617 wxLogDebug("starting calendar from %s\n",
618 date
.Format("%a %d-%m-%Y %H:%M:%S").c_str());
621 dc
.SetBackgroundMode(wxSOLID
);
622 for ( size_t nWeek
= 1; nWeek
<= 6; nWeek
++, y
+= m_heightRow
)
624 // if the update region doesn't intersect this row, don't paint it
625 if ( !IsExposed(0, y
, 7*m_widthCol
, m_heightRow
- 1) )
627 date
+= wxDateSpan::Week();
633 wxLogDebug("painting week %d at y = %d\n", nWeek
, y
);
636 for ( size_t wd
= 0; wd
< 7; wd
++ )
638 if ( IsDateShown(date
) )
640 // don't use wxDate::Format() which prepends 0s
641 unsigned int day
= date
.GetDay();
642 wxString dayStr
= wxString::Format(_T("%u"), day
);
644 dc
.GetTextExtent(dayStr
, &width
, (wxCoord
*)NULL
);
646 bool changedColours
= FALSE
,
649 wxCalendarDateAttr
*attr
= m_attrs
[day
- 1];
651 bool isSel
= date
.IsSameDate(m_date
);
654 dc
.SetTextForeground(m_colHighlightFg
);
655 dc
.SetTextBackground(m_colHighlightBg
);
657 changedColours
= TRUE
;
661 wxColour colFg
, colBg
;
663 if ( attr
->IsHoliday() )
665 colFg
= m_colHolidayFg
;
666 colBg
= m_colHolidayBg
;
670 colFg
= attr
->GetTextColour();
671 colBg
= attr
->GetBackgroundColour();
676 dc
.SetTextForeground(colFg
);
677 changedColours
= TRUE
;
682 dc
.SetTextBackground(colBg
);
683 changedColours
= TRUE
;
686 if ( attr
->HasFont() )
688 dc
.SetFont(attr
->GetFont());
693 wxCoord x
= wd
*m_widthCol
+ (m_widthCol
- width
) / 2;
694 dc
.DrawText(dayStr
, x
, y
+ 1);
696 if ( !isSel
&& attr
&& attr
->HasBorder() )
699 if ( attr
->HasBorderColour() )
701 colBorder
= attr
->GetBorderColour();
705 colBorder
= m_foregroundColour
;
708 wxPen
pen(colBorder
, 1, wxSOLID
);
710 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
712 switch ( attr
->GetBorder() )
714 case wxCAL_BORDER_SQUARE
:
715 dc
.DrawRectangle(x
- 2, y
,
716 width
+ 4, m_heightRow
);
719 case wxCAL_BORDER_ROUND
:
720 dc
.DrawEllipse(x
- 2, y
,
721 width
+ 4, m_heightRow
);
725 wxFAIL_MSG(_T("unknown border type"));
729 if ( changedColours
)
731 dc
.SetTextForeground(m_foregroundColour
);
732 dc
.SetTextBackground(m_backgroundColour
);
740 //else: just don't draw it
742 date
+= wxDateSpan::Day();
746 wxLogDebug("+++ finished painting");
750 void wxCalendarCtrl::RefreshDate(const wxDateTime
& date
)
756 // always refresh the whole row at once because our OnPaint() will draw
757 // the whole row anyhow - and this allows the small optimisation in
758 // OnClick() below to work
760 rect
.y
= m_heightRow
* GetWeek(date
);
761 rect
.width
= 7*m_widthCol
;
762 rect
.height
= m_heightRow
;
765 // VZ: for some reason, the selected date seems to occupy more space under
766 // MSW - this is probably some bug in the font size calculations, but I
767 // don't know where exactly. This fix is ugly and leads to more
768 // refreshes than really needed, but without it the selected days
769 // leaves even more ugly underscores on screen.
774 wxLogDebug("*** refreshing week %d at (%d, %d)-(%d, %d)\n",
777 rect
.x
+ rect
.width
, rect
.y
+ rect
.height
);
780 Refresh(TRUE
, &rect
);
783 // ----------------------------------------------------------------------------
785 // ----------------------------------------------------------------------------
787 void wxCalendarCtrl::OnDClick(wxMouseEvent
& event
)
789 if ( HitTest(event
.GetPosition()) != wxCAL_HITTEST_DAY
)
795 GenerateEvent(wxEVT_CALENDAR_DOUBLECLICKED
);
799 void wxCalendarCtrl::OnClick(wxMouseEvent
& event
)
802 wxDateTime::WeekDay wday
;
803 switch ( HitTest(event
.GetPosition(), &date
, &wday
) )
805 case wxCAL_HITTEST_DAY
:
808 GenerateEvents(wxEVT_CALENDAR_DAY_CHANGED
,
809 wxEVT_CALENDAR_SEL_CHANGED
);
812 case wxCAL_HITTEST_HEADER
:
814 wxCalendarEvent
event(this, wxEVT_CALENDAR_WEEKDAY_CLICKED
);
816 (void)GetEventHandler()->ProcessEvent(event
);
821 wxFAIL_MSG(_T("unknown hittest code"));
824 case wxCAL_HITTEST_NOWHERE
:
830 wxCalendarHitTestResult
wxCalendarCtrl::HitTest(const wxPoint
& pos
,
832 wxDateTime::WeekDay
*wd
)
836 int wday
= pos
.x
/ m_widthCol
;
839 if ( y
< m_heightRow
)
843 if ( GetWindowStyle() & wxCAL_MONDAY_FIRST
)
845 wday
= wday
== 6 ? 0 : wday
+ 1;
848 *wd
= (wxDateTime::WeekDay
)wday
;
851 return wxCAL_HITTEST_HEADER
;
854 int week
= (y
- m_heightRow
) / m_heightRow
;
855 if ( week
>= 6 || wday
>= 7 )
857 return wxCAL_HITTEST_NOWHERE
;
860 wxDateTime dt
= GetStartDate() + wxDateSpan::Days(7*week
+ wday
);
862 if ( IsDateShown(dt
) )
867 return wxCAL_HITTEST_DAY
;
871 return wxCAL_HITTEST_NOWHERE
;
875 // ----------------------------------------------------------------------------
876 // subcontrols events handling
877 // ----------------------------------------------------------------------------
879 void wxCalendarCtrl::OnMonthChange(wxCommandEvent
& event
)
881 wxDateTime::Tm tm
= m_date
.GetTm();
883 wxDateTime::Month mon
= (wxDateTime::Month
)event
.GetInt();
884 if ( tm
.mday
> wxDateTime::GetNumberOfDays(mon
, tm
.year
) )
886 tm
.mday
= wxDateTime::GetNumberOfDays(mon
, tm
.year
);
889 SetDateAndNotify(wxDateTime(tm
.mday
, mon
, tm
.year
));
892 void wxCalendarCtrl::OnYearChange(wxSpinEvent
& event
)
894 wxDateTime::Tm tm
= m_date
.GetTm();
896 int year
= (int)event
.GetInt();
897 if ( tm
.mday
> wxDateTime::GetNumberOfDays(tm
.mon
, year
) )
899 tm
.mday
= wxDateTime::GetNumberOfDays(tm
.mon
, year
);
902 SetDateAndNotify(wxDateTime(tm
.mday
, tm
.mon
, year
));
905 // ----------------------------------------------------------------------------
906 // keyboard interface
907 // ----------------------------------------------------------------------------
909 void wxCalendarCtrl::OnChar(wxKeyEvent
& event
)
911 switch ( event
.KeyCode() )
915 SetDateAndNotify(m_date
+ wxDateSpan::Year());
920 SetDateAndNotify(m_date
- wxDateSpan::Year());
924 SetDateAndNotify(m_date
- wxDateSpan::Month());
928 SetDateAndNotify(m_date
+ wxDateSpan::Month());
932 if ( event
.ControlDown() )
933 SetDateAndNotify(wxDateTime(m_date
).SetToNextWeekDay(
934 GetWindowStyle() & wxCAL_MONDAY_FIRST
935 ? wxDateTime::Sun
: wxDateTime::Sat
));
937 SetDateAndNotify(m_date
+ wxDateSpan::Day());
941 if ( event
.ControlDown() )
942 SetDateAndNotify(wxDateTime(m_date
).SetToPrevWeekDay(
943 GetWindowStyle() & wxCAL_MONDAY_FIRST
944 ? wxDateTime::Mon
: wxDateTime::Sun
));
946 SetDateAndNotify(m_date
- wxDateSpan::Day());
950 SetDateAndNotify(m_date
- wxDateSpan::Week());
954 SetDateAndNotify(m_date
+ wxDateSpan::Week());
958 if ( event
.ControlDown() )
959 SetDateAndNotify(wxDateTime::Today());
961 SetDateAndNotify(wxDateTime(1, m_date
.GetMonth(), m_date
.GetYear()));
965 SetDateAndNotify(wxDateTime(m_date
).SetToLastMonthDay());
969 GenerateEvent(wxEVT_CALENDAR_DOUBLECLICKED
);
977 // ----------------------------------------------------------------------------
979 // ----------------------------------------------------------------------------
981 void wxCalendarCtrl::EnableHolidayDisplay(bool display
)
983 long style
= GetWindowStyle();
985 style
|= wxCAL_SHOW_HOLIDAYS
;
987 style
&= ~wxCAL_SHOW_HOLIDAYS
;
989 SetWindowStyle(style
);
999 void wxCalendarCtrl::SetHolidayAttrs()
1001 if ( GetWindowStyle() & wxCAL_SHOW_HOLIDAYS
)
1003 ResetHolidayAttrs();
1005 wxDateTime::Tm tm
= m_date
.GetTm();
1006 wxDateTime
dtStart(1, tm
.mon
, tm
.year
),
1007 dtEnd
= dtStart
.GetLastMonthDay();
1009 wxDateTimeArray hol
;
1010 wxDateTimeHolidayAuthority::GetHolidaysInRange(dtStart
, dtEnd
, hol
);
1012 size_t count
= hol
.GetCount();
1013 for ( size_t n
= 0; n
< count
; n
++ )
1015 SetHoliday(hol
[n
].GetDay());
1020 void wxCalendarCtrl::SetHoliday(size_t day
)
1022 wxCHECK_RET( day
> 0 && day
< 32, _T("invalid day in SetHoliday") );
1024 wxCalendarDateAttr
*attr
= GetAttr(day
);
1027 attr
= new wxCalendarDateAttr
;
1030 attr
->SetHoliday(TRUE
);
1032 // can't use SetAttr() because it would delete this pointer
1033 m_attrs
[day
- 1] = attr
;
1036 void wxCalendarCtrl::ResetHolidayAttrs()
1038 for ( size_t day
= 0; day
< 31; day
++ )
1042 m_attrs
[day
]->SetHoliday(FALSE
);
1047 // ----------------------------------------------------------------------------
1049 // ----------------------------------------------------------------------------
1051 void wxCalendarEvent::Init()
1053 m_wday
= wxDateTime::Inv_WeekDay
;
1056 wxCalendarEvent::wxCalendarEvent(wxCalendarCtrl
*cal
, wxEventType type
)
1057 : wxCommandEvent(type
, cal
->GetId())
1059 m_date
= cal
->GetDate();
1062 #endif // wxUSE_SPINBTN