1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/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 // ----------------------------------------------------------------------------
36 wxDEFINE_FLAGS( wxCalendarCtrlStyle
)
37 wxBEGIN_FLAGS( wxCalendarCtrlStyle
)
38 // new style border flags, we put them first to
39 // use them for streaming out
40 wxFLAGS_MEMBER(wxBORDER_SIMPLE
)
41 wxFLAGS_MEMBER(wxBORDER_SUNKEN
)
42 wxFLAGS_MEMBER(wxBORDER_DOUBLE
)
43 wxFLAGS_MEMBER(wxBORDER_RAISED
)
44 wxFLAGS_MEMBER(wxBORDER_STATIC
)
45 wxFLAGS_MEMBER(wxBORDER_NONE
)
47 // old style border flags
48 wxFLAGS_MEMBER(wxSIMPLE_BORDER
)
49 wxFLAGS_MEMBER(wxSUNKEN_BORDER
)
50 wxFLAGS_MEMBER(wxDOUBLE_BORDER
)
51 wxFLAGS_MEMBER(wxRAISED_BORDER
)
52 wxFLAGS_MEMBER(wxSTATIC_BORDER
)
53 wxFLAGS_MEMBER(wxBORDER
)
55 // standard window styles
56 wxFLAGS_MEMBER(wxTAB_TRAVERSAL
)
57 wxFLAGS_MEMBER(wxCLIP_CHILDREN
)
58 wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW
)
59 wxFLAGS_MEMBER(wxWANTS_CHARS
)
60 wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE
)
61 wxFLAGS_MEMBER(wxALWAYS_SHOW_SB
)
62 wxFLAGS_MEMBER(wxVSCROLL
)
63 wxFLAGS_MEMBER(wxHSCROLL
)
65 wxFLAGS_MEMBER(wxCAL_SUNDAY_FIRST
)
66 wxFLAGS_MEMBER(wxCAL_MONDAY_FIRST
)
67 wxFLAGS_MEMBER(wxCAL_SHOW_HOLIDAYS
)
68 wxFLAGS_MEMBER(wxCAL_NO_YEAR_CHANGE
)
69 wxFLAGS_MEMBER(wxCAL_NO_MONTH_CHANGE
)
70 wxFLAGS_MEMBER(wxCAL_SEQUENTIAL_MONTH_SELECTION
)
71 wxFLAGS_MEMBER(wxCAL_SHOW_SURROUNDING_WEEKS
)
73 wxEND_FLAGS( wxCalendarCtrlStyle
)
75 wxIMPLEMENT_DYNAMIC_CLASS_XTI(wxCalendarCtrl
, wxControl
, "wx/calctrl.h")
77 wxBEGIN_PROPERTIES_TABLE(wxCalendarCtrl
)
78 wxEVENT_RANGE_PROPERTY( Updated
, wxEVT_CALENDAR_SEL_CHANGED
, \
79 wxEVT_CALENDAR_WEEKDAY_CLICKED
, wxCalendarEvent
)
81 wxHIDE_PROPERTY( Children
)
83 wxPROPERTY( Date
,wxDateTime
, SetDate
, GetDate
, wxEMPTY_PARAMETER_VALUE
, \
84 0 /*flags*/, wxT("Helpstring"), wxT("group"))
85 wxPROPERTY_FLAGS( WindowStyle
, wxCalendarCtrlStyle
, long, \
86 SetWindowStyleFlag
, GetWindowStyleFlag
, \
87 wxEMPTY_PARAMETER_VALUE
, 0 /*flags*/, wxT("Helpstring"), \
88 wxT("group")) // style
89 wxEND_PROPERTIES_TABLE()
91 wxEMPTY_HANDLERS_TABLE(wxCalendarCtrl
)
93 wxCONSTRUCTOR_6( wxCalendarCtrl
, wxWindow
*, Parent
, wxWindowID
, Id
, \
94 wxDateTime
, Date
, wxPoint
, Position
, wxSize
, Size
, long, WindowStyle
)
96 // ----------------------------------------------------------------------------
98 // ----------------------------------------------------------------------------
99 IMPLEMENT_DYNAMIC_CLASS(wxCalendarEvent
, wxDateEvent
)
101 wxDEFINE_EVENT( wxEVT_CALENDAR_SEL_CHANGED
, wxCalendarEvent
);
102 wxDEFINE_EVENT( wxEVT_CALENDAR_PAGE_CHANGED
, wxCalendarEvent
);
103 wxDEFINE_EVENT( wxEVT_CALENDAR_DOUBLECLICKED
, wxCalendarEvent
);
104 wxDEFINE_EVENT( wxEVT_CALENDAR_WEEKDAY_CLICKED
, wxCalendarEvent
);
105 wxDEFINE_EVENT( wxEVT_CALENDAR_WEEK_CLICKED
, wxCalendarEvent
);
108 wxDEFINE_EVENT( wxEVT_CALENDAR_DAY_CHANGED
, wxCalendarEvent
);
109 wxDEFINE_EVENT( wxEVT_CALENDAR_MONTH_CHANGED
, wxCalendarEvent
);
110 wxDEFINE_EVENT( wxEVT_CALENDAR_YEAR_CHANGED
, wxCalendarEvent
);
113 wxCalendarDateAttr
wxCalendarDateAttr::m_mark(wxCAL_BORDER_SQUARE
);
115 bool wxCalendarCtrlBase::EnableMonthChange(bool enable
)
117 const long styleOrig
= GetWindowStyle();
118 long style
= enable
? styleOrig
& ~wxCAL_NO_MONTH_CHANGE
119 : styleOrig
| wxCAL_NO_MONTH_CHANGE
;
120 if ( style
== styleOrig
)
123 SetWindowStyle(style
);
128 bool wxCalendarCtrlBase::GenerateAllChangeEvents(const wxDateTime
& dateOld
)
130 const wxDateTime::Tm tm1
= dateOld
.GetTm(),
131 tm2
= GetDate().GetTm();
133 bool pageChanged
= false;
135 GenerateEvent(wxEVT_CALENDAR_SEL_CHANGED
);
136 if ( tm1
.year
!= tm2
.year
|| tm1
.mon
!= tm2
.mon
)
138 GenerateEvent(wxEVT_CALENDAR_PAGE_CHANGED
);
143 // send also one of the deprecated events
144 if ( tm1
.year
!= tm2
.year
)
145 GenerateEvent(wxEVT_CALENDAR_YEAR_CHANGED
);
146 else if ( tm1
.mon
!= tm2
.mon
)
147 GenerateEvent(wxEVT_CALENDAR_MONTH_CHANGED
);
149 GenerateEvent(wxEVT_CALENDAR_DAY_CHANGED
);
154 void wxCalendarCtrlBase::EnableHolidayDisplay(bool display
)
156 long style
= GetWindowStyle();
158 style
|= wxCAL_SHOW_HOLIDAYS
;
160 style
&= ~wxCAL_SHOW_HOLIDAYS
;
162 if ( style
== GetWindowStyle() )
165 SetWindowStyle(style
);
175 bool wxCalendarCtrlBase::SetHolidayAttrs()
177 if ( !HasFlag(wxCAL_SHOW_HOLIDAYS
) )
182 wxDateTime::Tm tm
= GetDate().GetTm();
183 wxDateTime
dtStart(1, tm
.mon
, tm
.year
),
184 dtEnd
= dtStart
.GetLastMonthDay();
187 wxDateTimeHolidayAuthority::GetHolidaysInRange(dtStart
, dtEnd
, hol
);
189 const size_t count
= hol
.GetCount();
190 for ( size_t n
= 0; n
< count
; n
++ )
192 SetHoliday(hol
[n
].GetDay());
198 #endif // wxUSE_CALENDARCTRL