]> git.saurik.com Git - wxWidgets.git/blob - src/common/calctrlcmn.cpp
fixing osx_cocoa
[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
20
21 #include "wx/dateevt.h"
22 IMPLEMENT_DYNAMIC_CLASS(wxDateEvent, wxCommandEvent)
23 wxDEFINE_EVENT(wxEVT_DATE_CHANGED, wxDateEvent);
24
25 #endif // wxUSE_CALENDARCTRL || wxUSE_DATEPICKCTRL
26
27
28 #if wxUSE_CALENDARCTRL
29
30 #include "wx/calctrl.h"
31
32 // ----------------------------------------------------------------------------
33 // XTI
34 // ----------------------------------------------------------------------------
35
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)
46
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)
54
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)
64
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)
72
73 wxEND_FLAGS( wxCalendarCtrlStyle )
74
75 wxIMPLEMENT_DYNAMIC_CLASS_XTI(wxCalendarCtrl, wxControl, "wx/calctrl.h")
76
77 wxBEGIN_PROPERTIES_TABLE(wxCalendarCtrl)
78 wxEVENT_RANGE_PROPERTY( Updated, wxEVT_CALENDAR_SEL_CHANGED, \
79 wxEVT_CALENDAR_WEEKDAY_CLICKED, wxCalendarEvent )
80
81 wxHIDE_PROPERTY( Children )
82
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()
90
91 wxEMPTY_HANDLERS_TABLE(wxCalendarCtrl)
92
93 wxCONSTRUCTOR_6( wxCalendarCtrl, wxWindow*, Parent, wxWindowID, Id, \
94 wxDateTime, Date, wxPoint, Position, wxSize, Size, long, WindowStyle )
95
96 // ----------------------------------------------------------------------------
97 // events
98 // ----------------------------------------------------------------------------
99 IMPLEMENT_DYNAMIC_CLASS(wxCalendarEvent, wxDateEvent)
100
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 );
106
107 // deprecated events
108 wxDEFINE_EVENT( wxEVT_CALENDAR_DAY_CHANGED, wxCalendarEvent );
109 wxDEFINE_EVENT( wxEVT_CALENDAR_MONTH_CHANGED, wxCalendarEvent );
110 wxDEFINE_EVENT( wxEVT_CALENDAR_YEAR_CHANGED, wxCalendarEvent );
111
112
113 wxCalendarDateAttr wxCalendarDateAttr::m_mark(wxCAL_BORDER_SQUARE);
114
115 bool wxCalendarCtrlBase::EnableMonthChange(bool enable)
116 {
117 const long styleOrig = GetWindowStyle();
118 long style = enable ? styleOrig & ~wxCAL_NO_MONTH_CHANGE
119 : styleOrig | wxCAL_NO_MONTH_CHANGE;
120 if ( style == styleOrig )
121 return false;
122
123 SetWindowStyle(style);
124
125 return true;
126 }
127
128 bool wxCalendarCtrlBase::GenerateAllChangeEvents(const wxDateTime& dateOld)
129 {
130 const wxDateTime::Tm tm1 = dateOld.GetTm(),
131 tm2 = GetDate().GetTm();
132
133 bool pageChanged = false;
134
135 GenerateEvent(wxEVT_CALENDAR_SEL_CHANGED);
136 if ( tm1.year != tm2.year || tm1.mon != tm2.mon )
137 {
138 GenerateEvent(wxEVT_CALENDAR_PAGE_CHANGED);
139
140 pageChanged = true;
141 }
142
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);
148 else
149 GenerateEvent(wxEVT_CALENDAR_DAY_CHANGED);
150
151 return pageChanged;
152 }
153
154 void wxCalendarCtrlBase::EnableHolidayDisplay(bool display)
155 {
156 long style = GetWindowStyle();
157 if ( display )
158 style |= wxCAL_SHOW_HOLIDAYS;
159 else
160 style &= ~wxCAL_SHOW_HOLIDAYS;
161
162 if ( style == GetWindowStyle() )
163 return;
164
165 SetWindowStyle(style);
166
167 if ( display )
168 SetHolidayAttrs();
169 else
170 ResetHolidayAttrs();
171
172 RefreshHolidays();
173 }
174
175 bool wxCalendarCtrlBase::SetHolidayAttrs()
176 {
177 if ( !HasFlag(wxCAL_SHOW_HOLIDAYS) )
178 return false;
179
180 ResetHolidayAttrs();
181
182 wxDateTime::Tm tm = GetDate().GetTm();
183 wxDateTime dtStart(1, tm.mon, tm.year),
184 dtEnd = dtStart.GetLastMonthDay();
185
186 wxDateTimeArray hol;
187 wxDateTimeHolidayAuthority::GetHolidaysInRange(dtStart, dtEnd, hol);
188
189 const size_t count = hol.GetCount();
190 for ( size_t n = 0; n < count; n++ )
191 {
192 SetHoliday(hol[n].GetDay());
193 }
194
195 return true;
196 }
197
198 #endif // wxUSE_CALENDARCTRL
199