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 // ----------------------------------------------------------------------------
105 // wxMonthComboBox and wxYearSpinCtrl
106 // ----------------------------------------------------------------------------
108 wxMonthComboBox::wxMonthComboBox(wxCalendarCtrl
*cal
)
109 : wxComboBox(cal
->GetParent(), -1,
119 for ( m
= wxDateTime::Jan
; m
< wxDateTime::Inv_Month
; wxNextMonth(m
) )
121 Append(wxDateTime::GetMonthName(m
));
124 SetSelection(m_cal
->GetDate().GetMonth());
125 SetSize(-1, -1, -1, -1, wxSIZE_AUTO_WIDTH
|wxSIZE_AUTO_HEIGHT
);
128 wxYearSpinCtrl::wxYearSpinCtrl(wxCalendarCtrl
*cal
)
129 : wxSpinCtrl(cal
->GetParent(), -1,
130 cal
->GetDate().Format(_T("%Y")),
134 -4300, 10000, cal
->GetDate().GetYear())
139 // ----------------------------------------------------------------------------
141 // ----------------------------------------------------------------------------
143 void wxCalendarCtrl::Init()
151 wxDateTime::WeekDay wd
;
152 for ( wd
= wxDateTime::Sun
; wd
< wxDateTime::Inv_WeekDay
; wxNextWDay(wd
) )
154 m_weekdays
[wd
] = wxDateTime::GetWeekDayName(wd
, wxDateTime::Name_Abbr
);
157 for ( size_t n
= 0; n
< WXSIZEOF(m_attrs
); n
++ )
163 m_colHighlightFg
= ss
.GetSystemColour(wxSYS_COLOUR_HIGHLIGHTTEXT
);
164 m_colHighlightBg
= ss
.GetSystemColour(wxSYS_COLOUR_HIGHLIGHT
);
166 m_colHolidayFg
= *wxRED
;
167 // don't set m_colHolidayBg - by default, same as our bg colour
169 m_colHeaderFg
= *wxBLUE
;
170 m_colHeaderBg
= *wxLIGHT_GREY
;
173 bool wxCalendarCtrl::Create(wxWindow
* WXUNUSED(parent
),
174 wxWindowID
WXUNUSED(id
),
175 const wxDateTime
& date
,
176 const wxPoint
& WXUNUSED(pos
),
179 const wxString
& WXUNUSED(name
))
181 // needed to get the arrow keys normally used for the dialog navigation
182 SetWindowStyle(style
| wxWANTS_CHARS
);
184 m_date
= date
.IsValid() ? date
: wxDateTime::Today();
186 m_spinYear
= new wxYearSpinCtrl(this);
187 m_staticYear
= new wxStaticText(GetParent(), -1, m_date
.Format(_T("%Y")),
188 wxDefaultPosition
, wxDefaultSize
,
191 m_comboMonth
= new wxMonthComboBox(this);
192 m_staticMonth
= new wxStaticText(GetParent(), -1, m_date
.Format(_T("%B")),
193 wxDefaultPosition
, wxDefaultSize
,
196 ShowCurrentControls();
199 if ( size
.x
== -1 || size
.y
== -1 )
201 sizeReal
= DoGetBestSize();
214 SetBackgroundColour(*wxWHITE
);
215 SetFont(*wxSWISS_FONT
);
222 wxCalendarCtrl::~wxCalendarCtrl()
224 for ( size_t n
= 0; n
< WXSIZEOF(m_attrs
); n
++ )
230 // ----------------------------------------------------------------------------
231 // forward wxWin functions to subcontrols
232 // ----------------------------------------------------------------------------
234 bool wxCalendarCtrl::Show(bool show
)
236 if ( !wxControl::Show(show
) )
241 GetMonthControl()->Show(show
);
242 GetYearControl()->Show(show
);
247 bool wxCalendarCtrl::Enable(bool enable
)
249 if ( !wxControl::Enable(enable
) )
254 GetMonthControl()->Enable(enable
);
255 GetYearControl()->Enable(enable
);
260 // ----------------------------------------------------------------------------
261 // enable/disable month/year controls
262 // ----------------------------------------------------------------------------
264 void wxCalendarCtrl::ShowCurrentControls()
266 if ( AllowMonthChange() )
268 m_comboMonth
->Show();
269 m_staticMonth
->Hide();
271 if ( AllowYearChange() )
274 m_staticYear
->Hide();
282 m_comboMonth
->Hide();
283 m_staticMonth
->Show();
286 // year change not allowed here
288 m_staticYear
->Show();
291 wxControl
*wxCalendarCtrl::GetMonthControl() const
293 return AllowMonthChange() ? (wxControl
*)m_comboMonth
: (wxControl
*)m_staticMonth
;
296 wxControl
*wxCalendarCtrl::GetYearControl() const
298 return AllowYearChange() ? (wxControl
*)m_spinYear
: (wxControl
*)m_staticYear
;
301 void wxCalendarCtrl::EnableYearChange(bool enable
)
303 if ( enable
!= AllowYearChange() )
305 long style
= GetWindowStyle();
307 style
&= ~wxCAL_NO_YEAR_CHANGE
;
309 style
|= wxCAL_NO_YEAR_CHANGE
;
310 SetWindowStyle(style
);
312 ShowCurrentControls();
316 void wxCalendarCtrl::EnableMonthChange(bool enable
)
318 if ( enable
!= AllowMonthChange() )
320 long style
= GetWindowStyle();
322 style
&= ~wxCAL_NO_MONTH_CHANGE
;
324 style
|= wxCAL_NO_MONTH_CHANGE
;
325 SetWindowStyle(style
);
327 ShowCurrentControls();
331 // ----------------------------------------------------------------------------
333 // ----------------------------------------------------------------------------
335 void wxCalendarCtrl::SetDate(const wxDateTime
& date
)
337 bool sameMonth
= m_date
.GetMonth() == date
.GetMonth(),
338 sameYear
= m_date
.GetYear() == date
.GetYear();
340 if ( sameMonth
&& sameYear
)
342 // just change the day
347 if ( !AllowMonthChange() || (!AllowYearChange() && !sameYear
) )
356 // update the controls
357 m_comboMonth
->SetSelection(m_date
.GetMonth());
359 if ( AllowYearChange() )
361 m_spinYear
->SetValue(m_date
.Format(_T("%Y")));
364 // as the month changed, holidays did too
367 // update the calendar
372 void wxCalendarCtrl::ChangeDay(const wxDateTime
& date
)
374 if ( m_date
!= date
)
376 // we need to refresh the row containing the old date and the one
377 // containing the new one
378 wxDateTime dateOld
= m_date
;
381 RefreshDate(dateOld
);
383 // if the date is in the same row, it was already drawn correctly
384 if ( GetWeek(m_date
) != GetWeek(dateOld
) )
391 void wxCalendarCtrl::SetDateAndNotify(const wxDateTime
& date
)
393 wxDateTime::Tm tm1
= m_date
.GetTm(),
397 if ( tm1
.year
!= tm2
.year
)
398 type
= wxEVT_CALENDAR_YEAR_CHANGED
;
399 else if ( tm1
.mon
!= tm2
.mon
)
400 type
= wxEVT_CALENDAR_MONTH_CHANGED
;
401 else if ( tm1
.mday
!= tm2
.mday
)
402 type
= wxEVT_CALENDAR_DAY_CHANGED
;
408 GenerateEvents(type
, wxEVT_CALENDAR_SEL_CHANGED
);
411 // ----------------------------------------------------------------------------
413 // ----------------------------------------------------------------------------
415 wxDateTime
wxCalendarCtrl::GetStartDate() const
417 wxDateTime::Tm tm
= m_date
.GetTm();
419 wxDateTime date
= wxDateTime(1, tm
.mon
, tm
.year
);
422 date
.SetToPrevWeekDay(GetWindowStyle() & wxCAL_MONDAY_FIRST
423 ? wxDateTime::Mon
: wxDateTime::Sun
);
428 bool wxCalendarCtrl::IsDateShown(const wxDateTime
& date
) const
430 return date
.GetMonth() == m_date
.GetMonth();
433 size_t wxCalendarCtrl::GetWeek(const wxDateTime
& date
) const
435 return date
.GetWeekOfMonth(GetWindowStyle() & wxCAL_MONDAY_FIRST
436 ? wxDateTime::Monday_First
437 : wxDateTime::Sunday_First
);
440 // ----------------------------------------------------------------------------
442 // ----------------------------------------------------------------------------
444 // this is a composite control and it must arrange its parts each time its
445 // size or position changes: the combobox and spinctrl are along the top of
446 // the available area and the calendar takes up therest of the space
448 // the static controls are supposed to be always smaller than combo/spin so we
449 // always use the latter for size calculations and position the static to take
452 // the constants used for the layout
453 #define VERT_MARGIN 5 // distance between combo and calendar
454 #define HORZ_MARGIN 15 // spin
456 wxSize
wxCalendarCtrl::DoGetBestSize() const
458 // calc the size of the calendar
459 ((wxCalendarCtrl
*)this)->RecalcGeometry(); // const_cast
461 wxCoord width
= 7*m_widthCol
,
462 height
= 7*m_heightRow
;
464 wxSize sizeCombo
= m_comboMonth
->GetBestSize(),
465 sizeSpin
= m_spinYear
->GetBestSize();
467 height
+= VERT_MARGIN
+ wxMax(sizeCombo
.y
, sizeSpin
.y
);
469 if ( GetWindowStyle() & (wxRAISED_BORDER
| wxSUNKEN_BORDER
) )
471 // the border would clip the last line otherwise
475 return wxSize(width
, height
);
478 void wxCalendarCtrl::DoSetSize(int x
, int y
,
479 int width
, int height
,
482 wxControl::DoSetSize(x
, y
, width
, height
, sizeFlags
);
485 void wxCalendarCtrl::DoMoveWindow(int x
, int y
, int width
, int height
)
487 wxSize sizeCombo
= m_comboMonth
->GetSize();
488 wxSize sizeStatic
= m_staticMonth
->GetSize();
490 int dy
= (sizeCombo
.y
- sizeStatic
.y
) / 2;
491 m_comboMonth
->Move(x
, y
);
492 m_staticMonth
->SetSize(x
, y
+ dy
, sizeCombo
.x
, sizeStatic
.y
);
494 int xDiff
= sizeCombo
.x
+ HORZ_MARGIN
;
495 m_spinYear
->SetSize(x
+ xDiff
, y
, width
- xDiff
, sizeCombo
.y
);
496 m_staticYear
->SetSize(x
+ xDiff
, y
+ dy
, width
- xDiff
, sizeStatic
.y
);
498 wxSize sizeSpin
= m_spinYear
->GetSize();
499 int yDiff
= wxMax(sizeSpin
.y
, sizeCombo
.y
) + VERT_MARGIN
;
501 wxControl::DoMoveWindow(x
, y
+ yDiff
, width
, height
- yDiff
);
504 void wxCalendarCtrl::DoGetPosition(int *x
, int *y
) const
506 wxControl::DoGetPosition(x
, y
);
508 // our real top corner is not in this position
511 *y
-= GetMonthControl()->GetSize().y
+ VERT_MARGIN
;
515 void wxCalendarCtrl::DoGetSize(int *width
, int *height
) const
517 wxControl::DoGetSize(width
, height
);
519 // our real height is bigger
522 *height
+= GetMonthControl()->GetSize().y
+ VERT_MARGIN
;
526 void wxCalendarCtrl::RecalcGeometry()
528 if ( m_widthCol
!= 0 )
535 // determine the column width (we assume that the weekday names are always
536 // wider (in any language) than the numbers)
538 wxDateTime::WeekDay wd
;
539 for ( wd
= wxDateTime::Sun
; wd
< wxDateTime::Inv_WeekDay
; wxNextWDay(wd
) )
542 dc
.GetTextExtent(m_weekdays
[wd
], &width
, &m_heightRow
);
543 if ( width
> m_widthCol
)
549 // leave some margins
554 // ----------------------------------------------------------------------------
556 // ----------------------------------------------------------------------------
558 void wxCalendarCtrl::OnPaint(wxPaintEvent
& WXUNUSED(event
))
567 wxLogDebug("--- starting to paint, selection: %s, week %u\n",
568 m_date
.Format("%a %d-%m-%Y %H:%M:%S").c_str(),
572 // first draw the week days
573 if ( IsExposed(0, 0, 7*m_widthCol
, m_heightRow
) )
576 wxLogDebug("painting the header");
579 dc
.SetBackgroundMode(wxTRANSPARENT
);
580 dc
.SetTextForeground(m_colHeaderFg
);
581 dc
.SetBrush(wxBrush(m_colHeaderBg
, wxSOLID
));
582 dc
.SetPen(wxPen(m_colHeaderBg
, 1, wxSOLID
));
583 dc
.DrawRectangle(0, 0, 7*m_widthCol
, m_heightRow
);
585 bool startOnMonday
= (GetWindowStyle() & wxCAL_MONDAY_FIRST
) != 0;
586 for ( size_t wd
= 0; wd
< 7; wd
++ )
590 n
= wd
== 6 ? 0 : wd
+ 1;
594 dc
.DrawText(m_weekdays
[n
], wd
*m_widthCol
+ 1, 0);
598 // then the calendar itself
599 dc
.SetTextForeground(*wxBLACK
);
600 //dc.SetFont(*wxNORMAL_FONT);
602 wxCoord y
= m_heightRow
;
604 wxDateTime date
= GetStartDate();
606 wxLogDebug("starting calendar from %s\n",
607 date
.Format("%a %d-%m-%Y %H:%M:%S").c_str());
610 dc
.SetBackgroundMode(wxSOLID
);
611 for ( size_t nWeek
= 1; nWeek
<= 6; nWeek
++, y
+= m_heightRow
)
613 // if the update region doesn't intersect this row, don't paint it
614 if ( !IsExposed(0, y
, 7*m_widthCol
, m_heightRow
- 1) )
616 date
+= wxDateSpan::Week();
622 wxLogDebug("painting week %d at y = %d\n", nWeek
, y
);
625 for ( size_t wd
= 0; wd
< 7; wd
++ )
627 if ( IsDateShown(date
) )
629 // don't use wxDate::Format() which prepends 0s
630 unsigned int day
= date
.GetDay();
631 wxString dayStr
= wxString::Format(_T("%u"), day
);
633 dc
.GetTextExtent(dayStr
, &width
, (wxCoord
*)NULL
);
635 bool changedColours
= FALSE
,
638 wxCalendarDateAttr
*attr
= m_attrs
[day
- 1];
640 bool isSel
= m_date
== date
;
643 dc
.SetTextForeground(m_colHighlightFg
);
644 dc
.SetTextBackground(m_colHighlightBg
);
646 changedColours
= TRUE
;
650 wxColour colFg
, colBg
;
652 if ( attr
->IsHoliday() )
654 colFg
= m_colHolidayFg
;
655 colBg
= m_colHolidayBg
;
659 colFg
= attr
->GetTextColour();
660 colBg
= attr
->GetBackgroundColour();
665 dc
.SetTextForeground(colFg
);
666 changedColours
= TRUE
;
671 dc
.SetTextBackground(colBg
);
672 changedColours
= TRUE
;
675 if ( attr
->HasFont() )
677 dc
.SetFont(attr
->GetFont());
682 wxCoord x
= wd
*m_widthCol
+ (m_widthCol
- width
) / 2;
683 dc
.DrawText(dayStr
, x
, y
+ 1);
685 if ( !isSel
&& attr
&& attr
->HasBorder() )
688 if ( attr
->HasBorderColour() )
690 colBorder
= attr
->GetBorderColour();
694 colBorder
= m_foregroundColour
;
697 wxPen
pen(colBorder
, 1, wxSOLID
);
699 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
701 switch ( attr
->GetBorder() )
703 case wxCAL_BORDER_SQUARE
:
704 dc
.DrawRectangle(x
- 2, y
,
705 width
+ 4, m_heightRow
);
708 case wxCAL_BORDER_ROUND
:
709 dc
.DrawEllipse(x
- 2, y
,
710 width
+ 4, m_heightRow
);
714 wxFAIL_MSG(_T("unknown border type"));
718 if ( changedColours
)
720 dc
.SetTextForeground(m_foregroundColour
);
721 dc
.SetTextBackground(m_backgroundColour
);
729 //else: just don't draw it
731 date
+= wxDateSpan::Day();
735 wxLogDebug("+++ finished painting");
739 void wxCalendarCtrl::RefreshDate(const wxDateTime
& date
)
745 // always refresh the whole row at once because our OnPaint() will draw
746 // the whole row anyhow - and this allows the small optimisation in
747 // OnClick() below to work
749 rect
.y
= m_heightRow
* GetWeek(date
);
750 rect
.width
= 7*m_widthCol
;
751 rect
.height
= m_heightRow
;
754 // VZ: for some reason, the selected date seems to occupy more space under
755 // MSW - this is probably some bug in the font size calculations, but I
756 // don't know where exactly. This fix is ugly and leads to more
757 // refreshes than really needed, but without it the selected days
758 // leaves even more ugly underscores on screen.
763 wxLogDebug("*** refreshing week %d at (%d, %d)-(%d, %d)\n",
766 rect
.x
+ rect
.width
, rect
.y
+ rect
.height
);
769 Refresh(TRUE
, &rect
);
772 // ----------------------------------------------------------------------------
774 // ----------------------------------------------------------------------------
776 void wxCalendarCtrl::OnDClick(wxMouseEvent
& event
)
778 if ( HitTest(event
.GetPosition()) != wxCAL_HITTEST_DAY
)
784 GenerateEvent(wxEVT_CALENDAR_DOUBLECLICKED
);
788 void wxCalendarCtrl::OnClick(wxMouseEvent
& event
)
791 wxDateTime::WeekDay wday
;
792 switch ( HitTest(event
.GetPosition(), &date
, &wday
) )
794 case wxCAL_HITTEST_DAY
:
797 GenerateEvents(wxEVT_CALENDAR_DAY_CHANGED
,
798 wxEVT_CALENDAR_SEL_CHANGED
);
801 case wxCAL_HITTEST_HEADER
:
803 wxCalendarEvent
event(this, wxEVT_CALENDAR_WEEKDAY_CLICKED
);
805 (void)GetEventHandler()->ProcessEvent(event
);
810 wxFAIL_MSG(_T("unknown hittest code"));
813 case wxCAL_HITTEST_NOWHERE
:
819 wxCalendarHitTestResult
wxCalendarCtrl::HitTest(const wxPoint
& pos
,
821 wxDateTime::WeekDay
*wd
)
825 int wday
= pos
.x
/ m_widthCol
;
828 if ( y
< m_heightRow
)
832 if ( GetWindowStyle() & wxCAL_MONDAY_FIRST
)
834 wday
= wday
== 6 ? 0 : wday
+ 1;
837 *wd
= (wxDateTime::WeekDay
)wday
;
840 return wxCAL_HITTEST_HEADER
;
843 int week
= (y
- m_heightRow
) / m_heightRow
;
844 if ( week
>= 6 || wday
>= 7 )
846 return wxCAL_HITTEST_NOWHERE
;
849 wxDateTime dt
= GetStartDate() + wxDateSpan::Days(7*week
+ wday
);
851 if ( IsDateShown(dt
) )
856 return wxCAL_HITTEST_DAY
;
860 return wxCAL_HITTEST_NOWHERE
;
864 // ----------------------------------------------------------------------------
865 // subcontrols events handling
866 // ----------------------------------------------------------------------------
868 void wxCalendarCtrl::OnMonthChange(wxCommandEvent
& event
)
870 wxDateTime::Tm tm
= m_date
.GetTm();
872 wxDateTime::Month mon
= (wxDateTime::Month
)event
.GetInt();
873 if ( tm
.mday
> wxDateTime::GetNumberOfDays(mon
, tm
.year
) )
875 tm
.mday
= wxDateTime::GetNumberOfDays(mon
, tm
.year
);
878 SetDateAndNotify(wxDateTime(tm
.mday
, mon
, tm
.year
));
881 void wxCalendarCtrl::OnYearChange(wxSpinEvent
& event
)
883 wxDateTime::Tm tm
= m_date
.GetTm();
885 int year
= (int)event
.GetInt();
886 if ( tm
.mday
> wxDateTime::GetNumberOfDays(tm
.mon
, year
) )
888 tm
.mday
= wxDateTime::GetNumberOfDays(tm
.mon
, year
);
891 SetDateAndNotify(wxDateTime(tm
.mday
, tm
.mon
, year
));
894 // ----------------------------------------------------------------------------
895 // keyboard interface
896 // ----------------------------------------------------------------------------
898 void wxCalendarCtrl::OnChar(wxKeyEvent
& event
)
900 switch ( event
.KeyCode() )
904 SetDateAndNotify(m_date
+ wxDateSpan::Year());
909 SetDateAndNotify(m_date
- wxDateSpan::Year());
913 SetDateAndNotify(m_date
- wxDateSpan::Month());
917 SetDateAndNotify(m_date
+ wxDateSpan::Month());
921 if ( event
.ControlDown() )
922 SetDateAndNotify(wxDateTime(m_date
).SetToNextWeekDay(
923 GetWindowStyle() & wxCAL_MONDAY_FIRST
924 ? wxDateTime::Sun
: wxDateTime::Sat
));
926 SetDateAndNotify(m_date
+ wxDateSpan::Day());
930 if ( event
.ControlDown() )
931 SetDateAndNotify(wxDateTime(m_date
).SetToPrevWeekDay(
932 GetWindowStyle() & wxCAL_MONDAY_FIRST
933 ? wxDateTime::Mon
: wxDateTime::Sun
));
935 SetDateAndNotify(m_date
- wxDateSpan::Day());
939 SetDateAndNotify(m_date
- wxDateSpan::Week());
943 SetDateAndNotify(m_date
+ wxDateSpan::Week());
947 if ( event
.ControlDown() )
948 SetDateAndNotify(wxDateTime::Today());
950 SetDateAndNotify(wxDateTime(1, m_date
.GetMonth(), m_date
.GetYear()));
954 SetDateAndNotify(wxDateTime(m_date
).SetToLastMonthDay());
958 GenerateEvent(wxEVT_CALENDAR_DOUBLECLICKED
);
966 // ----------------------------------------------------------------------------
968 // ----------------------------------------------------------------------------
970 void wxCalendarCtrl::EnableHolidayDisplay(bool display
)
972 long style
= GetWindowStyle();
974 style
|= wxCAL_SHOW_HOLIDAYS
;
976 style
&= ~wxCAL_SHOW_HOLIDAYS
;
978 SetWindowStyle(style
);
988 void wxCalendarCtrl::SetHolidayAttrs()
990 if ( GetWindowStyle() & wxCAL_SHOW_HOLIDAYS
)
994 wxDateTime::Tm tm
= m_date
.GetTm();
995 wxDateTime
dtStart(1, tm
.mon
, tm
.year
),
996 dtEnd
= dtStart
.GetLastMonthDay();
999 wxDateTimeHolidayAuthority::GetHolidaysInRange(dtStart
, dtEnd
, hol
);
1001 size_t count
= hol
.GetCount();
1002 for ( size_t n
= 0; n
< count
; n
++ )
1004 SetHoliday(hol
[n
].GetDay());
1009 void wxCalendarCtrl::SetHoliday(size_t day
)
1011 wxCHECK_RET( day
> 0 && day
< 32, _T("invalid day in SetHoliday") );
1013 wxCalendarDateAttr
*attr
= GetAttr(day
);
1016 attr
= new wxCalendarDateAttr
;
1019 attr
->SetHoliday(TRUE
);
1021 // can't use SetAttr() because it would delete this pointer
1022 m_attrs
[day
- 1] = attr
;
1025 void wxCalendarCtrl::ResetHolidayAttrs()
1027 for ( size_t day
= 0; day
< 31; day
++ )
1031 m_attrs
[day
]->SetHoliday(FALSE
);
1036 // ----------------------------------------------------------------------------
1038 // ----------------------------------------------------------------------------
1040 void wxCalendarEvent::Init()
1042 m_wday
= wxDateTime::Inv_WeekDay
;
1045 wxCalendarEvent::wxCalendarEvent(wxCalendarCtrl
*cal
, wxEventType type
)
1046 : wxCommandEvent(type
, cal
->GetId())
1048 m_date
= cal
->GetDate();
1051 #endif // wxUSE_SPINBTN