]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: calendar.i | |
3 | // Purpose: SWIG definitions for the wxCalendarCtrl | |
4 | // | |
5 | // Author: Robin Dunn | |
6 | // | |
7 | // Created: 23-May-2000 | |
8 | // RCS-ID: $Id$ | |
9 | // Copyright: (c) 2000 by Total Control Software | |
10 | // Licence: wxWindows license | |
11 | ///////////////////////////////////////////////////////////////////////////// | |
12 | ||
13 | %module calendar | |
14 | ||
15 | ||
16 | %{ | |
17 | #include "wx/wxPython/wxPython.h" | |
18 | #include "wx/wxPython/pyclasses.h" | |
19 | ||
20 | #include <wx/calctrl.h> | |
21 | %} | |
22 | ||
23 | //---------------------------------------------------------------------- | |
24 | ||
25 | %import misc.i | |
26 | %pythoncode { wx = core } | |
27 | ||
28 | %include _calendar_rename.i | |
29 | ||
30 | //--------------------------------------------------------------------------- | |
31 | ||
32 | enum { | |
33 | wxCAL_SUNDAY_FIRST, | |
34 | wxCAL_MONDAY_FIRST, | |
35 | wxCAL_SHOW_HOLIDAYS, | |
36 | wxCAL_NO_YEAR_CHANGE, | |
37 | wxCAL_NO_MONTH_CHANGE, | |
38 | wxCAL_SEQUENTIAL_MONTH_SELECTION, | |
39 | wxCAL_SHOW_SURROUNDING_WEEKS, | |
40 | }; | |
41 | ||
42 | ||
43 | enum wxCalendarHitTestResult | |
44 | { | |
45 | wxCAL_HITTEST_NOWHERE, // outside of anything | |
46 | wxCAL_HITTEST_HEADER, // on the header (weekdays) | |
47 | wxCAL_HITTEST_DAY, // on a day in the calendar | |
48 | wxCAL_HITTEST_INCMONTH, | |
49 | wxCAL_HITTEST_DECMONTH, | |
50 | wxCAL_HITTEST_SURROUNDING_WEEK | |
51 | }; | |
52 | ||
53 | // border types for a date | |
54 | enum wxCalendarDateBorder | |
55 | { | |
56 | wxCAL_BORDER_NONE, // no border (default) | |
57 | wxCAL_BORDER_SQUARE, // a rectangular border | |
58 | wxCAL_BORDER_ROUND // a round border | |
59 | }; | |
60 | ||
61 | //--------------------------------------------------------------------------- | |
62 | ||
63 | DocStr(wxCalendarDateAttr, | |
64 | "A set of customization attributes for a calendar date, which can be used to | |
65 | control the look of the Calendar object."); | |
66 | ||
67 | class wxCalendarDateAttr | |
68 | { | |
69 | public: | |
70 | DocStr(wxCalendarDateAttr, | |
71 | "Create a CalendarDateAttr."); | |
72 | wxCalendarDateAttr(const wxColour& colText = wxNullColour, | |
73 | const wxColour& colBack = wxNullColour, | |
74 | const wxColour& colBorder = wxNullColour, | |
75 | const wxFont& font = wxNullFont, | |
76 | wxCalendarDateBorder border = wxCAL_BORDER_NONE); | |
77 | ||
78 | ||
79 | // setters | |
80 | void SetTextColour(const wxColour& colText); | |
81 | void SetBackgroundColour(const wxColour& colBack); | |
82 | void SetBorderColour(const wxColour& col); | |
83 | void SetFont(const wxFont& font); | |
84 | void SetBorder(wxCalendarDateBorder border); | |
85 | void SetHoliday(bool holiday); | |
86 | ||
87 | // accessors | |
88 | bool HasTextColour() const; | |
89 | bool HasBackgroundColour() const; | |
90 | bool HasBorderColour() const; | |
91 | bool HasFont() const; | |
92 | bool HasBorder() const; | |
93 | ||
94 | bool IsHoliday() const; | |
95 | ||
96 | wxColour GetTextColour() const; | |
97 | wxColour GetBackgroundColour() const; | |
98 | wxColour GetBorderColour() const; | |
99 | wxFont GetFont() const; | |
100 | wxCalendarDateBorder GetBorder() const; | |
101 | }; | |
102 | ||
103 | //--------------------------------------------------------------------------- | |
104 | ||
105 | class wxCalendarCtrl; | |
106 | ||
107 | class wxCalendarEvent : public wxCommandEvent | |
108 | { | |
109 | public: | |
110 | wxCalendarEvent(wxCalendarCtrl *cal, wxEventType type); | |
111 | ||
112 | const wxDateTime GetDate() const; | |
113 | void SetDate(const wxDateTime &date); | |
114 | void SetWeekDay(const wxDateTime::WeekDay wd); | |
115 | wxDateTime::WeekDay GetWeekDay() const; | |
116 | ||
117 | }; | |
118 | ||
119 | ||
120 | %constant wxEventType wxEVT_CALENDAR_DOUBLECLICKED; | |
121 | %constant wxEventType wxEVT_CALENDAR_SEL_CHANGED; | |
122 | %constant wxEventType wxEVT_CALENDAR_DAY_CHANGED; | |
123 | %constant wxEventType wxEVT_CALENDAR_MONTH_CHANGED; | |
124 | %constant wxEventType wxEVT_CALENDAR_YEAR_CHANGED; | |
125 | %constant wxEventType wxEVT_CALENDAR_WEEKDAY_CLICKED; | |
126 | ||
127 | ||
128 | %pythoncode { | |
129 | EVT_CALENDAR = wx.PyEventBinder( wxEVT_CALENDAR_DOUBLECLICKED, 1) | |
130 | EVT_CALENDAR_SEL_CHANGED = wx.PyEventBinder( wxEVT_CALENDAR_SEL_CHANGED, 1) | |
131 | EVT_CALENDAR_DAY = wx.PyEventBinder( wxEVT_CALENDAR_DAY_CHANGED, 1) | |
132 | EVT_CALENDAR_MONTH = wx.PyEventBinder( wxEVT_CALENDAR_MONTH_CHANGED, 1) | |
133 | EVT_CALENDAR_YEAR = wx.PyEventBinder( wxEVT_CALENDAR_YEAR_CHANGED, 1) | |
134 | EVT_CALENDAR_WEEKDAY_CLICKED = wx.PyEventBinder( wxEVT_CALENDAR_WEEKDAY_CLICKED, 1) | |
135 | } | |
136 | ||
137 | ||
138 | //--------------------------------------------------------------------------- | |
139 | ||
140 | MAKE_CONST_WXSTRING(CalendarNameStr); | |
141 | ||
142 | ||
143 | DocStr(wxCalendarCtrl, | |
144 | "The calendar control allows the user to pick a date interactively."); | |
145 | ||
146 | RefDoc(wxCalendarCtrl, | |
147 | ||
148 | "The CalendarCtrl displays a window containing several parts: the control to | |
149 | pick the month and the year at the top (either or both of them may be | |
150 | disabled) and a month area below them which shows all the days in the | |
151 | month. The user can move the current selection using the keyboard and select | |
152 | the date (generating EVT_CALENDAR event) by pressing <Return> or double | |
153 | clicking it. | |
154 | ||
155 | It has advanced possibilities for the customization of its display. All global | |
156 | settings (such as colours and fonts used) can, of course, be changed. But | |
157 | also, the display style for each day in the month can be set independently | |
158 | using CalendarDateAttr class. | |
159 | ||
160 | An item without custom attributes is drawn with the default colours and font | |
161 | and without border, but setting custom attributes with SetAttr allows to | |
162 | modify its appearance. Just create a custom attribute object and set it for | |
163 | the day you want to be displayed specially A day may be marked as being a | |
164 | holiday, (even if it is not recognized as one by wx.DateTime) by using the | |
165 | SetHoliday method. | |
166 | ||
167 | As the attributes are specified for each day, they may change when the month | |
168 | is changed, so you will often want to update them in an EVT_CALENDAR_MONTH | |
169 | event handler. | |
170 | ||
171 | Styles | |
172 | CAL_SUNDAY_FIRST: Show Sunday as the first day in the week | |
173 | CAL_MONDAY_FIRST: Show Monday as the first day in the week | |
174 | CAL_SHOW_HOLIDAYS: Highlight holidays in the calendar | |
175 | CAL_NO_YEAR_CHANGE: Disable the year changing | |
176 | CAL_NO_MONTH_CHANGE: Disable the month (and, implicitly, the year) changing | |
177 | CAL_SHOW_SURROUNDING_WEEKS: Show the neighbouring weeks in the previous and next months | |
178 | CAL_SEQUENTIAL_MONTH_SELECTION: Use alternative, more compact, style for the month and year selection controls. | |
179 | ||
180 | The default calendar style is wxCAL_SHOW_HOLIDAYS. | |
181 | ||
182 | Events | |
183 | EVT_CALENDAR: A day was double clicked in the calendar. | |
184 | EVT_CALENDAR_SEL_CHANGED: The selected date changed. | |
185 | EVT_CALENDAR_DAY: The selected day changed. | |
186 | EVT_CALENDAR_MONTH: The selected month changed. | |
187 | EVT_CALENDAR_YEAR: The selected year changed. | |
188 | EVT_CALENDAR_WEEKDAY_CLICKED: User clicked on the week day header | |
189 | ||
190 | Note that changing the selected date will result in either of | |
191 | EVT_CALENDAR_DAY, MONTH or YEAR events and an EVT_CALENDAR_SEL_CHANGED event. | |
192 | ||
193 | "); | |
194 | ||
195 | ||
196 | class wxCalendarCtrl : public wxControl | |
197 | { | |
198 | public: | |
199 | %pythonAppend wxCalendarCtrl "self._setOORInfo(self)" | |
200 | %pythonAppend wxCalendarCtrl() "" | |
201 | ||
202 | DocStr(wxCalendarCtrl, "Create and show a calendar control."); | |
203 | RefDoc(wxCalendarCtrl, ""); // turn it off for the ctors | |
204 | ||
205 | wxCalendarCtrl(wxWindow *parent, | |
206 | wxWindowID id, | |
207 | const wxDateTime& date = wxDefaultDateTime, | |
208 | const wxPoint& pos = wxDefaultPosition, | |
209 | const wxSize& size = wxDefaultSize, | |
210 | long style = wxCAL_SHOW_HOLIDAYS | wxWANTS_CHARS, | |
211 | const wxString& name = wxPyCalendarNameStr); | |
212 | ||
213 | ||
214 | DocStr(wxCalendarCtrl(), "Precreate a CalendarCtrl for 2-phase creation."); | |
215 | %name(PreCalendarCtrl)wxCalendarCtrl(); | |
216 | ||
217 | DocStr(Create, "Acutally create the GUI portion of the CalendarCtrl for 2-phase creation."); | |
218 | bool Create(wxWindow *parent, | |
219 | wxWindowID id, | |
220 | const wxDateTime& date = wxDefaultDateTime, | |
221 | const wxPoint& pos = wxDefaultPosition, | |
222 | const wxSize& size = wxDefaultSize, | |
223 | long style = wxCAL_SHOW_HOLIDAYS | wxWANTS_CHARS, | |
224 | const wxString& name = wxPyCalendarNameStr); | |
225 | ||
226 | ||
227 | DocDeclStr( | |
228 | void, SetDate(const wxDateTime& date), | |
229 | "Sets the current date."); | |
230 | ||
231 | DocDeclStr( | |
232 | const wxDateTime&, GetDate() const, | |
233 | "Gets the currently selected date."); | |
234 | ||
235 | ||
236 | ||
237 | DocDeclStr( | |
238 | bool, SetLowerDateLimit(const wxDateTime& date = wxDefaultDateTime), | |
239 | "set the range in which selection can occur"); | |
240 | ||
241 | DocDeclStr( | |
242 | bool, SetUpperDateLimit(const wxDateTime& date = wxDefaultDateTime), | |
243 | "set the range in which selection can occur"); | |
244 | ||
245 | DocDeclStr( | |
246 | const wxDateTime&, GetLowerDateLimit() const, | |
247 | "get the range in which selection can occur"); | |
248 | ||
249 | DocDeclStr( | |
250 | const wxDateTime&, GetUpperDateLimit() const, | |
251 | "get the range in which selection can occur"); | |
252 | ||
253 | DocDeclStr( | |
254 | bool, SetDateRange(const wxDateTime& lowerdate = wxDefaultDateTime, | |
255 | const wxDateTime& upperdate = wxDefaultDateTime), | |
256 | "set the range in which selection can occur"); | |
257 | ||
258 | ||
259 | ||
260 | ||
261 | DocDeclStr( | |
262 | void, EnableYearChange(bool enable = True), | |
263 | "This function should be used instead of changing CAL_NO_YEAR_CHANGE\n" | |
264 | "style bit directly. It allows or disallows the user to change the year\n" | |
265 | "interactively."); | |
266 | ||
267 | DocDeclStr( | |
268 | void, EnableMonthChange(bool enable = True), | |
269 | "This function should be used instead of changing CAL_NO_MONTH_CHANGE style\n" | |
270 | "bit. It allows or disallows the user to change the month interactively. Note\n" | |
271 | "that if the month can not be changed, the year can not be changed either."); | |
272 | ||
273 | DocDeclStr( | |
274 | void, EnableHolidayDisplay(bool display = True), | |
275 | "This function should be used instead of changing CAL_SHOW_HOLIDAYS style\n" | |
276 | "bit directly. It enables or disables the special highlighting of the holidays."); | |
277 | ||
278 | ||
279 | ||
280 | DocDeclStr( | |
281 | void, SetHeaderColours(const wxColour& colFg, const wxColour& colBg), | |
282 | "header colours are used for painting the weekdays at the top"); | |
283 | ||
284 | DocDeclStr( | |
285 | wxColour, GetHeaderColourFg() const, | |
286 | "header colours are used for painting the weekdays at the top"); | |
287 | ||
288 | DocDeclStr( | |
289 | wxColour, GetHeaderColourBg() const, | |
290 | "header colours are used for painting the weekdays at the top"); | |
291 | ||
292 | ||
293 | ||
294 | DocDeclStr( | |
295 | void, SetHighlightColours(const wxColour& colFg, const wxColour& colBg), | |
296 | "highlight colour is used for the currently selected date"); | |
297 | ||
298 | DocDeclStr( | |
299 | wxColour, GetHighlightColourFg() const, | |
300 | "highlight colour is used for the currently selected date"); | |
301 | ||
302 | DocDeclStr( | |
303 | wxColour, GetHighlightColourBg() const, | |
304 | "highlight colour is used for the currently selected date"); | |
305 | ||
306 | ||
307 | ||
308 | DocDeclStr( | |
309 | void, SetHolidayColours(const wxColour& colFg, const wxColour& colBg), | |
310 | "holiday colour is used for the holidays (if CAL_SHOW_HOLIDAYS style is used)"); | |
311 | ||
312 | DocDeclStr( | |
313 | wxColour, GetHolidayColourFg() const, | |
314 | "holiday colour is used for the holidays (if CAL_SHOW_HOLIDAYS style is used)"); | |
315 | ||
316 | DocDeclStr( | |
317 | wxColour, GetHolidayColourBg() const, | |
318 | "holiday colour is used for the holidays (if CAL_SHOW_HOLIDAYS style is used)"); | |
319 | ||
320 | ||
321 | ||
322 | DocDeclStr( | |
323 | wxCalendarDateAttr*, GetAttr(size_t day) const, | |
324 | "Returns the attribute for the given date (should be in the range 1...31).\n" | |
325 | "The returned value may be None"); | |
326 | ||
327 | DocDeclStr( | |
328 | void, SetAttr(size_t day, wxCalendarDateAttr *attr), | |
329 | "Associates the attribute with the specified date (in the range 1...31).\n" | |
330 | "If the attribute passed is None, the items attribute is cleared."); | |
331 | ||
332 | DocDeclStr( | |
333 | void, SetHoliday(size_t day), | |
334 | "Marks the specified day as being a holiday in the current month."); | |
335 | ||
336 | DocDeclStr( | |
337 | void, ResetAttr(size_t day), | |
338 | "Clears any attributes associated with the given day (in the range 1...31)."); | |
339 | ||
340 | ||
341 | ||
342 | DocAStr(HitTest, | |
343 | "HitTest(Point pos) -> (result, date, weekday)", | |
344 | "Returns 3-tuple with information about the given position on the calendar | |
345 | control. The first value of the tuple is a result code and determines the | |
346 | validity of the remaining two values. The result codes are: | |
347 | ||
348 | CAL_HITTEST_NOWHERE: hit outside of anything | |
349 | CAL_HITTEST_HEADER: hit on the header, weekday is valid | |
350 | CAL_HITTEST_DAY: hit on a day in the calendar, date is set. | |
351 | "); | |
352 | %extend { | |
353 | PyObject* HitTest(const wxPoint& pos) { | |
354 | wxDateTime* date = new wxDateTime; | |
355 | wxDateTime::WeekDay wd; | |
356 | wxCalendarHitTestResult result = self->HitTest(pos, date, &wd); | |
357 | bool blocked = wxPyBeginBlockThreads(); | |
358 | PyObject* tup = PyTuple_New(3); | |
359 | PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(result)); | |
360 | PyTuple_SET_ITEM(tup, 1, wxPyConstructObject(date, wxT("wxDateTime"), 1)); | |
361 | PyTuple_SET_ITEM(tup, 2, PyInt_FromLong(wd)); | |
362 | wxPyEndBlockThreads(blocked); | |
363 | return tup; | |
364 | } | |
365 | } | |
366 | ||
367 | DocDeclStr( | |
368 | wxControl*, GetMonthControl() const, | |
369 | "get the currently shown control for month"); | |
370 | ||
371 | DocDeclStr( | |
372 | wxControl*, GetYearControl() const, | |
373 | "get the currently shown control for year"); | |
374 | }; | |
375 | ||
376 | ||
377 | //--------------------------------------------------------------------------- | |
378 | ||
379 | %init %{ | |
380 | %} | |
381 | ||
382 | //--------------------------------------------------------------------------- | |
383 |