1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: SWIG definitions for the wxCalendarCtrl
7 // Created: 23-May-2000
9 // Copyright: (c) 2000 by Total Control Software
10 // Licence: wxWindows license
11 /////////////////////////////////////////////////////////////////////////////
14 "Classes for an interactive Calendar control."
16 %module(docstring=DOCSTRING) calendar
20 #include "wx/wxPython/wxPython.h"
21 #include "wx/wxPython/pyclasses.h"
23 #include <wx/calctrl.h>
26 //----------------------------------------------------------------------
29 %pythoncode { wx = _core }
30 %pythoncode { __docfilter__ = wx.__DocFilter(globals()) }
32 %include _calendar_rename.i
34 //---------------------------------------------------------------------------
41 wxCAL_NO_MONTH_CHANGE,
42 wxCAL_SEQUENTIAL_MONTH_SELECTION,
43 wxCAL_SHOW_SURROUNDING_WEEKS,
47 enum wxCalendarHitTestResult
49 wxCAL_HITTEST_NOWHERE, // outside of anything
50 wxCAL_HITTEST_HEADER, // on the header (weekdays)
51 wxCAL_HITTEST_DAY, // on a day in the calendar
52 wxCAL_HITTEST_INCMONTH,
53 wxCAL_HITTEST_DECMONTH,
54 wxCAL_HITTEST_SURROUNDING_WEEK
57 // border types for a date
58 enum wxCalendarDateBorder
60 wxCAL_BORDER_NONE, // no border (default)
61 wxCAL_BORDER_SQUARE, // a rectangular border
62 wxCAL_BORDER_ROUND // a round border
65 //---------------------------------------------------------------------------
67 DocStr(wxCalendarDateAttr,
68 "A set of customization attributes for a calendar date, which can be
69 used to control the look of the Calendar object.", "");
71 class wxCalendarDateAttr
74 DocStr(wxCalendarDateAttr,
75 "Create a CalendarDateAttr.", "");
76 wxCalendarDateAttr(const wxColour& colText = wxNullColour,
77 const wxColour& colBack = wxNullColour,
78 const wxColour& colBorder = wxNullColour,
79 const wxFont& font = wxNullFont,
80 wxCalendarDateBorder border = wxCAL_BORDER_NONE);
84 void SetTextColour(const wxColour& colText);
85 void SetBackgroundColour(const wxColour& colBack);
86 void SetBorderColour(const wxColour& col);
87 void SetFont(const wxFont& font);
88 void SetBorder(wxCalendarDateBorder border);
89 void SetHoliday(bool holiday);
92 bool HasTextColour() const;
93 bool HasBackgroundColour() const;
94 bool HasBorderColour() const;
96 bool HasBorder() const;
98 bool IsHoliday() const;
100 wxColour GetTextColour() const;
101 wxColour GetBackgroundColour() const;
102 wxColour GetBorderColour() const;
103 wxFont GetFont() const;
104 wxCalendarDateBorder GetBorder() const;
107 //---------------------------------------------------------------------------
109 class wxCalendarCtrl;
111 class wxCalendarEvent : public wxCommandEvent
114 wxCalendarEvent(wxCalendarCtrl *cal, wxEventType type);
116 const wxDateTime GetDate() const;
117 void SetDate(const wxDateTime &date);
118 void SetWeekDay(const wxDateTime::WeekDay wd);
119 wxDateTime::WeekDay GetWeekDay() const;
124 %constant wxEventType wxEVT_CALENDAR_DOUBLECLICKED;
125 %constant wxEventType wxEVT_CALENDAR_SEL_CHANGED;
126 %constant wxEventType wxEVT_CALENDAR_DAY_CHANGED;
127 %constant wxEventType wxEVT_CALENDAR_MONTH_CHANGED;
128 %constant wxEventType wxEVT_CALENDAR_YEAR_CHANGED;
129 %constant wxEventType wxEVT_CALENDAR_WEEKDAY_CLICKED;
133 EVT_CALENDAR = wx.PyEventBinder( wxEVT_CALENDAR_DOUBLECLICKED, 1)
134 EVT_CALENDAR_SEL_CHANGED = wx.PyEventBinder( wxEVT_CALENDAR_SEL_CHANGED, 1)
135 EVT_CALENDAR_DAY = wx.PyEventBinder( wxEVT_CALENDAR_DAY_CHANGED, 1)
136 EVT_CALENDAR_MONTH = wx.PyEventBinder( wxEVT_CALENDAR_MONTH_CHANGED, 1)
137 EVT_CALENDAR_YEAR = wx.PyEventBinder( wxEVT_CALENDAR_YEAR_CHANGED, 1)
138 EVT_CALENDAR_WEEKDAY_CLICKED = wx.PyEventBinder( wxEVT_CALENDAR_WEEKDAY_CLICKED, 1)
142 //---------------------------------------------------------------------------
144 MAKE_CONST_WXSTRING(CalendarNameStr);
147 DocStr(wxCalendarCtrl,
148 "The calendar control allows the user to pick a date interactively.
150 The CalendarCtrl displays a window containing several parts: the
151 control to pick the month and the year at the top (either or both of
152 them may be disabled) and a month area below them which shows all the
153 days in the month. The user can move the current selection using the
154 keyboard and select the date (generating EVT_CALENDAR event) by
155 pressing <Return> or double clicking it.
157 It has advanced possibilities for the customization of its
158 display. All global settings (such as colours and fonts used) can, of
159 course, be changed. But also, the display style for each day in the
160 month can be set independently using CalendarDateAttr class.
162 An item without custom attributes is drawn with the default colours
163 and font and without border, but setting custom attributes with
164 SetAttr allows to modify its appearance. Just create a custom
165 attribute object and set it for the day you want to be displayed
166 specially A day may be marked as being a holiday, (even if it is not
167 recognized as one by wx.DateTime) by using the SetHoliday method.
169 As the attributes are specified for each day, they may change when the
170 month is changed, so you will often want to update them in an
171 EVT_CALENDAR_MONTH event handler.", "
175 ============================== ============================
176 CAL_SUNDAY_FIRST Show Sunday as the first day
178 CAL_MONDAY_FIRST Show Monday as the first day
180 CAL_SHOW_HOLIDAYS Highlight holidays in the
182 CAL_NO_YEAR_CHANGE Disable the year changing
183 CAL_NO_MONTH_CHANGE Disable the month (and,
184 implicitly, the year) changing
185 CAL_SHOW_SURROUNDING_WEEKS Show the neighbouring weeks in
186 the previous and next months
187 CAL_SEQUENTIAL_MONTH_SELECTION Use alternative, more compact,
188 style for the month and year
190 ============================== ============================
192 The default calendar style is CAL_SHOW_HOLIDAYS.
196 ============================= ==============================
197 EVT_CALENDAR A day was double clicked in the
199 EVT_CALENDAR_SEL_CHANGED The selected date changed.
200 EVT_CALENDAR_DAY The selected day changed.
201 EVT_CALENDAR_MONTH The selected month changed.
202 EVT_CALENDAR_YEAR The selected year changed.
203 EVT_CALENDAR_WEEKDAY_CLICKED User clicked on the week day
205 ============================= ==============================
207 Note that changing the selected date will result in one of
208 EVT_CALENDAR_DAY, MONTH or YEAR events and an EVT_CALENDAR_SEL_CHANGED
214 MustHaveApp(wxCalendarCtrl);
216 class wxCalendarCtrl : public wxControl
219 %pythonAppend wxCalendarCtrl "self._setOORInfo(self)"
220 %pythonAppend wxCalendarCtrl() ""
223 wxCalendarCtrl(wxWindow *parent,
225 const wxDateTime& date = wxDefaultDateTime,
226 const wxPoint& pos = wxDefaultPosition,
227 const wxSize& size = wxDefaultSize,
228 long style = wxCAL_SHOW_HOLIDAYS | wxWANTS_CHARS,
229 const wxString& name = wxPyCalendarNameStr),
230 "Create and show a calendar control.", "");
234 "Precreate a CalendarCtrl for 2-phase creation.", "",
238 bool , Create(wxWindow *parent,
240 const wxDateTime& date = wxDefaultDateTime,
241 const wxPoint& pos = wxDefaultPosition,
242 const wxSize& size = wxDefaultSize,
243 long style = wxCAL_SHOW_HOLIDAYS | wxWANTS_CHARS,
244 const wxString& name = wxPyCalendarNameStr),
245 "Acutally create the GUI portion of the CalendarCtrl for 2-phase
251 void, SetDate(const wxDateTime& date),
252 "Sets the current date.", "");
255 const wxDateTime&, GetDate() const,
256 "Gets the currently selected date.", "");
261 bool, SetLowerDateLimit(const wxDateTime& date = wxDefaultDateTime),
262 "set the range in which selection can occur", "");
265 bool, SetUpperDateLimit(const wxDateTime& date = wxDefaultDateTime),
266 "set the range in which selection can occur", "");
269 const wxDateTime&, GetLowerDateLimit() const,
270 "get the range in which selection can occur", "");
273 const wxDateTime&, GetUpperDateLimit() const,
274 "get the range in which selection can occur", "");
277 bool, SetDateRange(const wxDateTime& lowerdate = wxDefaultDateTime,
278 const wxDateTime& upperdate = wxDefaultDateTime),
279 "set the range in which selection can occur", "");
285 void, EnableYearChange(bool enable = True),
286 "This function should be used instead of changing CAL_NO_YEAR_CHANGE
287 style bit directly. It allows or disallows the user to change the year
288 interactively.", "");
291 void, EnableMonthChange(bool enable = True),
292 "This function should be used instead of changing CAL_NO_MONTH_CHANGE
293 style bit. It allows or disallows the user to change the month
294 interactively. Note that if the month can not be changed, the year can
295 not be changed either.", "");
298 void, EnableHolidayDisplay(bool display = True),
299 "This function should be used instead of changing CAL_SHOW_HOLIDAYS
300 style bit directly. It enables or disables the special highlighting of
306 void, SetHeaderColours(const wxColour& colFg, const wxColour& colBg),
307 "Header colours are used for painting the weekdays at the top.", "");
310 wxColour, GetHeaderColourFg() const,
311 "Header colours are used for painting the weekdays at the top.", "");
314 wxColour, GetHeaderColourBg() const,
315 "Header colours are used for painting the weekdays at the top.", "");
320 void, SetHighlightColours(const wxColour& colFg, const wxColour& colBg),
321 "Highlight colour is used for the currently selected date.", "");
324 wxColour, GetHighlightColourFg() const,
325 "Highlight colour is used for the currently selected date.", "");
328 wxColour, GetHighlightColourBg() const,
329 "Highlight colour is used for the currently selected date.", "");
334 void, SetHolidayColours(const wxColour& colFg, const wxColour& colBg),
335 "Holiday colour is used for the holidays (if CAL_SHOW_HOLIDAYS style is
339 wxColour, GetHolidayColourFg() const,
340 "Holiday colour is used for the holidays (if CAL_SHOW_HOLIDAYS style is
344 wxColour, GetHolidayColourBg() const,
345 "Holiday colour is used for the holidays (if CAL_SHOW_HOLIDAYS style is
351 wxCalendarDateAttr*, GetAttr(size_t day) const,
352 "Returns the attribute for the given date (should be in the range
353 1...31). The returned value may be None", "");
356 void, SetAttr(size_t day, wxCalendarDateAttr *attr),
357 "Associates the attribute with the specified date (in the range
358 1...31). If the attribute passed is None, the items attribute is
362 void, SetHoliday(size_t day),
363 "Marks the specified day as being a holiday in the current month.", "");
366 void, ResetAttr(size_t day),
367 "Clears any attributes associated with the given day (in the range
373 "HitTest(Point pos) -> (result, date, weekday)",
374 "Returns 3-tuple with information about the given position on the
375 calendar control. The first value of the tuple is a result code and
376 determines the validity of the remaining two values.",
378 The result codes are:
380 =================== ============================================
381 CAL_HITTEST_NOWHERE hit outside of anything
382 CAL_HITTEST_HEADER hit on the header, weekday is valid
383 CAL_HITTEST_DAY hit on a day in the calendar, date is set.
384 =================== ============================================
387 PyObject* HitTest(const wxPoint& pos) {
388 wxDateTime* date = new wxDateTime;
389 wxDateTime::WeekDay wd;
390 wxCalendarHitTestResult result = self->HitTest(pos, date, &wd);
391 bool blocked = wxPyBeginBlockThreads();
392 PyObject* tup = PyTuple_New(3);
393 PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(result));
394 PyTuple_SET_ITEM(tup, 1, wxPyConstructObject(date, wxT("wxDateTime"), 1));
395 PyTuple_SET_ITEM(tup, 2, PyInt_FromLong(wd));
396 wxPyEndBlockThreads(blocked);
402 wxControl*, GetMonthControl() const,
403 "Get the currently shown control for month.", "");
406 wxControl*, GetYearControl() const,
407 "Get the currently shown control for year.", "");
409 static wxVisualAttributes
410 GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL);
414 //---------------------------------------------------------------------------
419 //---------------------------------------------------------------------------