1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: common/calctrlcmn.cpp
3 // Author: Marcin Wojdyr
6 // Copyright: (C) Marcin Wojdyr
7 // Licence: wxWindows licence
8 ///////////////////////////////////////////////////////////////////////////////
10 #include "wx/wxprec.h"
19 #if wxUSE_CALENDARCTRL || wxUSE_DATEPICKCTRL
21 #include "wx/dateevt.h"
22 IMPLEMENT_DYNAMIC_CLASS(wxDateEvent
, wxCommandEvent
)
23 DEFINE_EVENT_TYPE(wxEVT_DATE_CHANGED
)
25 #endif // wxUSE_CALENDARCTRL || wxUSE_DATEPICKCTRL
28 #if wxUSE_CALENDARCTRL
30 #include "wx/calctrl.h"
32 // ----------------------------------------------------------------------------
34 // ----------------------------------------------------------------------------
35 IMPLEMENT_DYNAMIC_CLASS(wxCalendarEvent
, wxDateEvent
)
37 DEFINE_EVENT_TYPE(wxEVT_CALENDAR_SEL_CHANGED
)
38 DEFINE_EVENT_TYPE(wxEVT_CALENDAR_PAGE_CHANGED
)
39 DEFINE_EVENT_TYPE(wxEVT_CALENDAR_DOUBLECLICKED
)
40 DEFINE_EVENT_TYPE(wxEVT_CALENDAR_WEEKDAY_CLICKED
)
43 DEFINE_EVENT_TYPE(wxEVT_CALENDAR_DAY_CHANGED
)
44 DEFINE_EVENT_TYPE(wxEVT_CALENDAR_MONTH_CHANGED
)
45 DEFINE_EVENT_TYPE(wxEVT_CALENDAR_YEAR_CHANGED
)
48 wxCalendarDateAttr
wxCalendarDateAttr::m_mark(wxCAL_BORDER_SQUARE
);
50 bool wxCalendarCtrlBase::EnableMonthChange(bool enable
)
52 const long styleOrig
= GetWindowStyle();
53 long style
= enable
? styleOrig
& ~wxCAL_NO_MONTH_CHANGE
54 : styleOrig
| wxCAL_NO_MONTH_CHANGE
;
55 if ( style
== styleOrig
)
58 SetWindowStyle(style
);
63 bool wxCalendarCtrlBase::GenerateAllChangeEvents(const wxDateTime
& dateOld
)
65 const wxDateTime::Tm tm1
= dateOld
.GetTm(),
66 tm2
= GetDate().GetTm();
68 bool pageChanged
= false;
70 GenerateEvent(wxEVT_CALENDAR_SEL_CHANGED
);
71 if ( tm1
.year
!= tm2
.year
|| tm1
.mon
!= tm2
.mon
)
73 GenerateEvent(wxEVT_CALENDAR_PAGE_CHANGED
);
78 // send also one of the deprecated events
79 if ( tm1
.year
!= tm2
.year
)
80 GenerateEvent(wxEVT_CALENDAR_YEAR_CHANGED
);
81 else if ( tm1
.mon
!= tm2
.mon
)
82 GenerateEvent(wxEVT_CALENDAR_MONTH_CHANGED
);
84 GenerateEvent(wxEVT_CALENDAR_DAY_CHANGED
);
89 void wxCalendarCtrlBase::EnableHolidayDisplay(bool display
)
91 long style
= GetWindowStyle();
93 style
|= wxCAL_SHOW_HOLIDAYS
;
95 style
&= ~wxCAL_SHOW_HOLIDAYS
;
97 if ( style
== GetWindowStyle() )
100 SetWindowStyle(style
);
110 bool wxCalendarCtrlBase::SetHolidayAttrs()
112 if ( !HasFlag(wxCAL_SHOW_HOLIDAYS
) )
117 wxDateTime::Tm tm
= GetDate().GetTm();
118 wxDateTime
dtStart(1, tm
.mon
, tm
.year
),
119 dtEnd
= dtStart
.GetLastMonthDay();
122 wxDateTimeHolidayAuthority::GetHolidaysInRange(dtStart
, dtEnd
, hol
);
124 const size_t count
= hol
.GetCount();
125 for ( size_t n
= 0; n
< count
; n
++ )
127 SetHoliday(hol
[n
].GetDay());
133 #endif // wxUSE_CALENDARCTRL