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 || wxUSE_TIMEPICKCTRL
21 #include "wx/dateevt.h"
22 IMPLEMENT_DYNAMIC_CLASS(wxDateEvent
, wxCommandEvent
)
23 wxDEFINE_EVENT(wxEVT_DATE_CHANGED
, wxDateEvent
);
24 wxDEFINE_EVENT(wxEVT_TIME_CHANGED
, wxDateEvent
);
26 #endif // wxUSE_CALENDARCTRL || wxUSE_DATEPICKCTRL || wxUSE_TIMEPICKCTRL
29 #if wxUSE_CALENDARCTRL
31 #include "wx/calctrl.h"
33 // ----------------------------------------------------------------------------
35 // ----------------------------------------------------------------------------
37 wxDEFINE_FLAGS( wxCalendarCtrlStyle
)
38 wxBEGIN_FLAGS( wxCalendarCtrlStyle
)
39 // new style border flags, we put them first to
40 // use them for streaming out
41 wxFLAGS_MEMBER(wxBORDER_SIMPLE
)
42 wxFLAGS_MEMBER(wxBORDER_SUNKEN
)
43 wxFLAGS_MEMBER(wxBORDER_DOUBLE
)
44 wxFLAGS_MEMBER(wxBORDER_RAISED
)
45 wxFLAGS_MEMBER(wxBORDER_STATIC
)
46 wxFLAGS_MEMBER(wxBORDER_NONE
)
48 // old style border flags
49 wxFLAGS_MEMBER(wxSIMPLE_BORDER
)
50 wxFLAGS_MEMBER(wxSUNKEN_BORDER
)
51 wxFLAGS_MEMBER(wxDOUBLE_BORDER
)
52 wxFLAGS_MEMBER(wxRAISED_BORDER
)
53 wxFLAGS_MEMBER(wxSTATIC_BORDER
)
54 wxFLAGS_MEMBER(wxBORDER
)
56 // standard window styles
57 wxFLAGS_MEMBER(wxTAB_TRAVERSAL
)
58 wxFLAGS_MEMBER(wxCLIP_CHILDREN
)
59 wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW
)
60 wxFLAGS_MEMBER(wxWANTS_CHARS
)
61 wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE
)
62 wxFLAGS_MEMBER(wxALWAYS_SHOW_SB
)
63 wxFLAGS_MEMBER(wxVSCROLL
)
64 wxFLAGS_MEMBER(wxHSCROLL
)
66 wxFLAGS_MEMBER(wxCAL_SUNDAY_FIRST
)
67 wxFLAGS_MEMBER(wxCAL_MONDAY_FIRST
)
68 wxFLAGS_MEMBER(wxCAL_SHOW_HOLIDAYS
)
69 wxFLAGS_MEMBER(wxCAL_NO_YEAR_CHANGE
)
70 wxFLAGS_MEMBER(wxCAL_NO_MONTH_CHANGE
)
71 wxFLAGS_MEMBER(wxCAL_SEQUENTIAL_MONTH_SELECTION
)
72 wxFLAGS_MEMBER(wxCAL_SHOW_SURROUNDING_WEEKS
)
74 wxEND_FLAGS( wxCalendarCtrlStyle
)
76 wxIMPLEMENT_DYNAMIC_CLASS_XTI(wxCalendarCtrl
, wxControl
, "wx/calctrl.h")
78 wxBEGIN_PROPERTIES_TABLE(wxCalendarCtrl
)
79 wxEVENT_RANGE_PROPERTY( Updated
, wxEVT_CALENDAR_SEL_CHANGED
, \
80 wxEVT_CALENDAR_WEEKDAY_CLICKED
, wxCalendarEvent
)
82 wxHIDE_PROPERTY( Children
)
84 wxPROPERTY( Date
,wxDateTime
, SetDate
, GetDate
, wxEMPTY_PARAMETER_VALUE
, \
85 0 /*flags*/, wxT("Helpstring"), wxT("group"))
86 wxPROPERTY_FLAGS( WindowStyle
, wxCalendarCtrlStyle
, long, \
87 SetWindowStyleFlag
, GetWindowStyleFlag
, \
88 wxEMPTY_PARAMETER_VALUE
, 0 /*flags*/, wxT("Helpstring"), \
89 wxT("group")) // style
90 wxEND_PROPERTIES_TABLE()
92 wxEMPTY_HANDLERS_TABLE(wxCalendarCtrl
)
94 wxCONSTRUCTOR_6( wxCalendarCtrl
, wxWindow
*, Parent
, wxWindowID
, Id
, \
95 wxDateTime
, Date
, wxPoint
, Position
, wxSize
, Size
, long, WindowStyle
)
97 // ----------------------------------------------------------------------------
99 // ----------------------------------------------------------------------------
100 IMPLEMENT_DYNAMIC_CLASS(wxCalendarEvent
, wxDateEvent
)
102 wxDEFINE_EVENT( wxEVT_CALENDAR_SEL_CHANGED
, wxCalendarEvent
);
103 wxDEFINE_EVENT( wxEVT_CALENDAR_PAGE_CHANGED
, wxCalendarEvent
);
104 wxDEFINE_EVENT( wxEVT_CALENDAR_DOUBLECLICKED
, wxCalendarEvent
);
105 wxDEFINE_EVENT( wxEVT_CALENDAR_WEEKDAY_CLICKED
, wxCalendarEvent
);
106 wxDEFINE_EVENT( wxEVT_CALENDAR_WEEK_CLICKED
, wxCalendarEvent
);
109 wxDEFINE_EVENT( wxEVT_CALENDAR_DAY_CHANGED
, wxCalendarEvent
);
110 wxDEFINE_EVENT( wxEVT_CALENDAR_MONTH_CHANGED
, wxCalendarEvent
);
111 wxDEFINE_EVENT( wxEVT_CALENDAR_YEAR_CHANGED
, wxCalendarEvent
);
114 wxCalendarDateAttr
wxCalendarDateAttr::m_mark(wxCAL_BORDER_SQUARE
);
116 bool wxCalendarCtrlBase::EnableMonthChange(bool enable
)
118 const long styleOrig
= GetWindowStyle();
119 long style
= enable
? styleOrig
& ~wxCAL_NO_MONTH_CHANGE
120 : styleOrig
| wxCAL_NO_MONTH_CHANGE
;
121 if ( style
== styleOrig
)
124 SetWindowStyle(style
);
129 bool wxCalendarCtrlBase::GenerateAllChangeEvents(const wxDateTime
& dateOld
)
131 const wxDateTime::Tm tm1
= dateOld
.GetTm(),
132 tm2
= GetDate().GetTm();
134 bool pageChanged
= false;
136 GenerateEvent(wxEVT_CALENDAR_SEL_CHANGED
);
137 if ( tm1
.year
!= tm2
.year
|| tm1
.mon
!= tm2
.mon
)
139 GenerateEvent(wxEVT_CALENDAR_PAGE_CHANGED
);
144 // send also one of the deprecated events
145 if ( tm1
.year
!= tm2
.year
)
146 GenerateEvent(wxEVT_CALENDAR_YEAR_CHANGED
);
147 else if ( tm1
.mon
!= tm2
.mon
)
148 GenerateEvent(wxEVT_CALENDAR_MONTH_CHANGED
);
150 GenerateEvent(wxEVT_CALENDAR_DAY_CHANGED
);
155 void wxCalendarCtrlBase::EnableHolidayDisplay(bool display
)
157 long style
= GetWindowStyle();
159 style
|= wxCAL_SHOW_HOLIDAYS
;
161 style
&= ~wxCAL_SHOW_HOLIDAYS
;
163 if ( style
== GetWindowStyle() )
166 SetWindowStyle(style
);
176 bool wxCalendarCtrlBase::SetHolidayAttrs()
178 if ( !HasFlag(wxCAL_SHOW_HOLIDAYS
) )
183 wxDateTime::Tm tm
= GetDate().GetTm();
184 wxDateTime
dtStart(1, tm
.mon
, tm
.year
),
185 dtEnd
= dtStart
.GetLastMonthDay();
188 wxDateTimeHolidayAuthority::GetHolidaysInRange(dtStart
, dtEnd
, hol
);
190 const size_t count
= hol
.GetCount();
191 for ( size_t n
= 0; n
< count
; n
++ )
193 SetHoliday(hol
[n
].GetDay());
199 #endif // wxUSE_CALENDARCTRL