]> git.saurik.com Git - wxWidgets.git/blob - src/common/calctrlcmn.cpp
attempt to get the 'new focus' window parameter of a focus kill event set correctly
[wxWidgets.git] / src / common / calctrlcmn.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/common/calctrlcmn.cpp
3 // Author: Marcin Wojdyr
4 // Created: 2008-03-26
5 // RCS-ID: $Id$
6 // Copyright: (C) Marcin Wojdyr
7 // Licence: wxWindows licence
8 ///////////////////////////////////////////////////////////////////////////////
9
10 #include "wx/wxprec.h"
11
12 #ifdef __BORLANDC__
13 #pragma hdrstop
14 #endif
15
16 #ifndef WX_PRECOMP
17 #endif //WX_PRECOMP
18
19 #if wxUSE_CALENDARCTRL || wxUSE_DATEPICKCTRL || wxUSE_TIMEPICKCTRL
20
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);
25
26 #endif // wxUSE_CALENDARCTRL || wxUSE_DATEPICKCTRL || wxUSE_TIMEPICKCTRL
27
28
29 #if wxUSE_CALENDARCTRL
30
31 #include "wx/calctrl.h"
32
33 // ----------------------------------------------------------------------------
34 // XTI
35 // ----------------------------------------------------------------------------
36
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)
47
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)
55
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)
65
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)
73
74 wxEND_FLAGS( wxCalendarCtrlStyle )
75
76 wxIMPLEMENT_DYNAMIC_CLASS_XTI(wxCalendarCtrl, wxControl, "wx/calctrl.h")
77
78 wxBEGIN_PROPERTIES_TABLE(wxCalendarCtrl)
79 wxEVENT_RANGE_PROPERTY( Updated, wxEVT_CALENDAR_SEL_CHANGED, \
80 wxEVT_CALENDAR_WEEKDAY_CLICKED, wxCalendarEvent )
81
82 wxHIDE_PROPERTY( Children )
83
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()
91
92 wxEMPTY_HANDLERS_TABLE(wxCalendarCtrl)
93
94 wxCONSTRUCTOR_6( wxCalendarCtrl, wxWindow*, Parent, wxWindowID, Id, \
95 wxDateTime, Date, wxPoint, Position, wxSize, Size, long, WindowStyle )
96
97 // ----------------------------------------------------------------------------
98 // events
99 // ----------------------------------------------------------------------------
100 IMPLEMENT_DYNAMIC_CLASS(wxCalendarEvent, wxDateEvent)
101
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 );
107
108 // deprecated events
109 wxDEFINE_EVENT( wxEVT_CALENDAR_DAY_CHANGED, wxCalendarEvent );
110 wxDEFINE_EVENT( wxEVT_CALENDAR_MONTH_CHANGED, wxCalendarEvent );
111 wxDEFINE_EVENT( wxEVT_CALENDAR_YEAR_CHANGED, wxCalendarEvent );
112
113
114 wxCalendarDateAttr wxCalendarDateAttr::m_mark(wxCAL_BORDER_SQUARE);
115
116 bool wxCalendarCtrlBase::EnableMonthChange(bool enable)
117 {
118 const long styleOrig = GetWindowStyle();
119 long style = enable ? styleOrig & ~wxCAL_NO_MONTH_CHANGE
120 : styleOrig | wxCAL_NO_MONTH_CHANGE;
121 if ( style == styleOrig )
122 return false;
123
124 SetWindowStyle(style);
125
126 return true;
127 }
128
129 bool wxCalendarCtrlBase::GenerateAllChangeEvents(const wxDateTime& dateOld)
130 {
131 const wxDateTime::Tm tm1 = dateOld.GetTm(),
132 tm2 = GetDate().GetTm();
133
134 bool pageChanged = false;
135
136 GenerateEvent(wxEVT_CALENDAR_SEL_CHANGED);
137 if ( tm1.year != tm2.year || tm1.mon != tm2.mon )
138 {
139 GenerateEvent(wxEVT_CALENDAR_PAGE_CHANGED);
140
141 pageChanged = true;
142 }
143
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);
149 else
150 GenerateEvent(wxEVT_CALENDAR_DAY_CHANGED);
151
152 return pageChanged;
153 }
154
155 void wxCalendarCtrlBase::EnableHolidayDisplay(bool display)
156 {
157 long style = GetWindowStyle();
158 if ( display )
159 style |= wxCAL_SHOW_HOLIDAYS;
160 else
161 style &= ~wxCAL_SHOW_HOLIDAYS;
162
163 if ( style == GetWindowStyle() )
164 return;
165
166 SetWindowStyle(style);
167
168 if ( display )
169 SetHolidayAttrs();
170 else
171 ResetHolidayAttrs();
172
173 RefreshHolidays();
174 }
175
176 bool wxCalendarCtrlBase::SetHolidayAttrs()
177 {
178 if ( !HasFlag(wxCAL_SHOW_HOLIDAYS) )
179 return false;
180
181 ResetHolidayAttrs();
182
183 wxDateTime::Tm tm = GetDate().GetTm();
184 wxDateTime dtStart(1, tm.mon, tm.year),
185 dtEnd = dtStart.GetLastMonthDay();
186
187 wxDateTimeArray hol;
188 wxDateTimeHolidayAuthority::GetHolidaysInRange(dtStart, dtEnd, hol);
189
190 const size_t count = hol.GetCount();
191 for ( size_t n = 0; n < count; n++ )
192 {
193 SetHoliday(hol[n].GetDay());
194 }
195
196 return true;
197 }
198
199 #endif // wxUSE_CALENDARCTRL
200