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 wxDEFINE_EVENT(wxEVT_DATE_CHANGED
, wxDateEvent
);
25 #endif // wxUSE_CALENDARCTRL || wxUSE_DATEPICKCTRL
28 #if wxUSE_CALENDARCTRL
30 #include "wx/calctrl.h"
32 // ----------------------------------------------------------------------------
34 // ----------------------------------------------------------------------------
35 IMPLEMENT_DYNAMIC_CLASS(wxCalendarEvent
, wxDateEvent
)
37 wxDEFINE_EVENT( wxEVT_CALENDAR_SEL_CHANGED
, wxCalendarEvent
)
38 wxDEFINE_EVENT( wxEVT_CALENDAR_PAGE_CHANGED
, wxCalendarEvent
)
39 wxDEFINE_EVENT( wxEVT_CALENDAR_DOUBLECLICKED
, wxCalendarEvent
)
40 wxDEFINE_EVENT( wxEVT_CALENDAR_WEEKDAY_CLICKED
, wxCalendarEvent
)
41 wxDEFINE_EVENT( wxEVT_CALENDAR_WEEK_CLICKED
, wxCalendarEvent
)
44 wxDEFINE_EVENT( wxEVT_CALENDAR_DAY_CHANGED
, wxCalendarEvent
)
45 wxDEFINE_EVENT( wxEVT_CALENDAR_MONTH_CHANGED
, wxCalendarEvent
)
46 wxDEFINE_EVENT( wxEVT_CALENDAR_YEAR_CHANGED
, wxCalendarEvent
)
49 wxCalendarDateAttr
wxCalendarDateAttr::m_mark(wxCAL_BORDER_SQUARE
);
51 bool wxCalendarCtrlBase::EnableMonthChange(bool enable
)
53 const long styleOrig
= GetWindowStyle();
54 long style
= enable
? styleOrig
& ~wxCAL_NO_MONTH_CHANGE
55 : styleOrig
| wxCAL_NO_MONTH_CHANGE
;
56 if ( style
== styleOrig
)
59 SetWindowStyle(style
);
64 bool wxCalendarCtrlBase::GenerateAllChangeEvents(const wxDateTime
& dateOld
)
66 const wxDateTime::Tm tm1
= dateOld
.GetTm(),
67 tm2
= GetDate().GetTm();
69 bool pageChanged
= false;
71 GenerateEvent(wxEVT_CALENDAR_SEL_CHANGED
);
72 if ( tm1
.year
!= tm2
.year
|| tm1
.mon
!= tm2
.mon
)
74 GenerateEvent(wxEVT_CALENDAR_PAGE_CHANGED
);
79 // send also one of the deprecated events
80 if ( tm1
.year
!= tm2
.year
)
81 GenerateEvent(wxEVT_CALENDAR_YEAR_CHANGED
);
82 else if ( tm1
.mon
!= tm2
.mon
)
83 GenerateEvent(wxEVT_CALENDAR_MONTH_CHANGED
);
85 GenerateEvent(wxEVT_CALENDAR_DAY_CHANGED
);
90 void wxCalendarCtrlBase::EnableHolidayDisplay(bool display
)
92 long style
= GetWindowStyle();
94 style
|= wxCAL_SHOW_HOLIDAYS
;
96 style
&= ~wxCAL_SHOW_HOLIDAYS
;
98 if ( style
== GetWindowStyle() )
101 SetWindowStyle(style
);
111 bool wxCalendarCtrlBase::SetHolidayAttrs()
113 if ( !HasFlag(wxCAL_SHOW_HOLIDAYS
) )
118 wxDateTime::Tm tm
= GetDate().GetTm();
119 wxDateTime
dtStart(1, tm
.mon
, tm
.year
),
120 dtEnd
= dtStart
.GetLastMonthDay();
123 wxDateTimeHolidayAuthority::GetHolidaysInRange(dtStart
, dtEnd
, hol
);
125 const size_t count
= hol
.GetCount();
126 for ( size_t n
= 0; n
< count
; n
++ )
128 SetHoliday(hol
[n
].GetDay());
134 #endif // wxUSE_CALENDARCTRL