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 /////////////////////////////////////////////////////////////////////////////
17 #include "wx/wxPython/wxPython.h"
18 #include "wx/wxPython/pyclasses.h"
20 #include <wx/calctrl.h>
23 //----------------------------------------------------------------------
26 %pythoncode { wx = _core }
27 %pythoncode { __docfilter__ = wx.__DocFilter(globals()) }
29 %include _calendar_rename.i
31 //---------------------------------------------------------------------------
38 wxCAL_NO_MONTH_CHANGE,
39 wxCAL_SEQUENTIAL_MONTH_SELECTION,
40 wxCAL_SHOW_SURROUNDING_WEEKS,
44 enum wxCalendarHitTestResult
46 wxCAL_HITTEST_NOWHERE, // outside of anything
47 wxCAL_HITTEST_HEADER, // on the header (weekdays)
48 wxCAL_HITTEST_DAY, // on a day in the calendar
49 wxCAL_HITTEST_INCMONTH,
50 wxCAL_HITTEST_DECMONTH,
51 wxCAL_HITTEST_SURROUNDING_WEEK
54 // border types for a date
55 enum wxCalendarDateBorder
57 wxCAL_BORDER_NONE, // no border (default)
58 wxCAL_BORDER_SQUARE, // a rectangular border
59 wxCAL_BORDER_ROUND // a round border
62 //---------------------------------------------------------------------------
64 DocStr(wxCalendarDateAttr,
65 "A set of customization attributes for a calendar date, which can be
66 used to control the look of the Calendar object.", "");
68 class wxCalendarDateAttr
71 DocStr(wxCalendarDateAttr,
72 "Create a CalendarDateAttr.", "");
73 wxCalendarDateAttr(const wxColour& colText = wxNullColour,
74 const wxColour& colBack = wxNullColour,
75 const wxColour& colBorder = wxNullColour,
76 const wxFont& font = wxNullFont,
77 wxCalendarDateBorder border = wxCAL_BORDER_NONE);
81 void SetTextColour(const wxColour& colText);
82 void SetBackgroundColour(const wxColour& colBack);
83 void SetBorderColour(const wxColour& col);
84 void SetFont(const wxFont& font);
85 void SetBorder(wxCalendarDateBorder border);
86 void SetHoliday(bool holiday);
89 bool HasTextColour() const;
90 bool HasBackgroundColour() const;
91 bool HasBorderColour() const;
93 bool HasBorder() const;
95 bool IsHoliday() const;
97 wxColour GetTextColour() const;
98 wxColour GetBackgroundColour() const;
99 wxColour GetBorderColour() const;
100 wxFont GetFont() const;
101 wxCalendarDateBorder GetBorder() const;
104 //---------------------------------------------------------------------------
106 class wxCalendarCtrl;
108 class wxCalendarEvent : public wxCommandEvent
111 wxCalendarEvent(wxCalendarCtrl *cal, wxEventType type);
113 const wxDateTime GetDate() const;
114 void SetDate(const wxDateTime &date);
115 void SetWeekDay(const wxDateTime::WeekDay wd);
116 wxDateTime::WeekDay GetWeekDay() const;
121 %constant wxEventType wxEVT_CALENDAR_DOUBLECLICKED;
122 %constant wxEventType wxEVT_CALENDAR_SEL_CHANGED;
123 %constant wxEventType wxEVT_CALENDAR_DAY_CHANGED;
124 %constant wxEventType wxEVT_CALENDAR_MONTH_CHANGED;
125 %constant wxEventType wxEVT_CALENDAR_YEAR_CHANGED;
126 %constant wxEventType wxEVT_CALENDAR_WEEKDAY_CLICKED;
130 EVT_CALENDAR = wx.PyEventBinder( wxEVT_CALENDAR_DOUBLECLICKED, 1)
131 EVT_CALENDAR_SEL_CHANGED = wx.PyEventBinder( wxEVT_CALENDAR_SEL_CHANGED, 1)
132 EVT_CALENDAR_DAY = wx.PyEventBinder( wxEVT_CALENDAR_DAY_CHANGED, 1)
133 EVT_CALENDAR_MONTH = wx.PyEventBinder( wxEVT_CALENDAR_MONTH_CHANGED, 1)
134 EVT_CALENDAR_YEAR = wx.PyEventBinder( wxEVT_CALENDAR_YEAR_CHANGED, 1)
135 EVT_CALENDAR_WEEKDAY_CLICKED = wx.PyEventBinder( wxEVT_CALENDAR_WEEKDAY_CLICKED, 1)
139 //---------------------------------------------------------------------------
141 MAKE_CONST_WXSTRING(CalendarNameStr);
144 DocStr(wxCalendarCtrl,
145 "The calendar control allows the user to pick a date interactively.
147 The CalendarCtrl displays a window containing several parts: the
148 control to pick the month and the year at the top (either or both of
149 them may be disabled) and a month area below them which shows all the
150 days in the month. The user can move the current selection using the
151 keyboard and select the date (generating EVT_CALENDAR event) by
152 pressing <Return> or double clicking it.
154 It has advanced possibilities for the customization of its
155 display. All global settings (such as colours and fonts used) can, of
156 course, be changed. But also, the display style for each day in the
157 month can be set independently using CalendarDateAttr class.
159 An item without custom attributes is drawn with the default colours
160 and font and without border, but setting custom attributes with
161 SetAttr allows to modify its appearance. Just create a custom
162 attribute object and set it for the day you want to be displayed
163 specially A day may be marked as being a holiday, (even if it is not
164 recognized as one by wx.DateTime) by using the SetHoliday method.
166 As the attributes are specified for each day, they may change when the
167 month is changed, so you will often want to update them in an
168 EVT_CALENDAR_MONTH event handler.", "
172 ============================== ============================
173 CAL_SUNDAY_FIRST Show Sunday as the first day
175 CAL_MONDAY_FIRST Show Monday as the first day
177 CAL_SHOW_HOLIDAYS Highlight holidays in the
179 CAL_NO_YEAR_CHANGE Disable the year changing
180 CAL_NO_MONTH_CHANGE Disable the month (and,
181 implicitly, the year) changing
182 CAL_SHOW_SURROUNDING_WEEKS Show the neighbouring weeks in
183 the previous and next months
184 CAL_SEQUENTIAL_MONTH_SELECTION Use alternative, more compact,
185 style for the month and year
188 The default calendar style is CAL_SHOW_HOLIDAYS.
192 =========================== ==============================
193 EVT_CALENDAR A day was double clicked in the
195 EVT_CALENDAR_SEL_CHANGED The selected date changed.
196 EVT_CALENDAR_DAY The selected day changed.
197 EVT_CALENDAR_MONTH The selected month changed.
198 EVT_CALENDAR_YEAR The selected year changed.
199 EVT_CALENDAR_WEEKDAY_CLICKED User clicked on the week day
202 Note that changing the selected date will result in one of
203 EVT_CALENDAR_DAY, MONTH or YEAR events and an EVT_CALENDAR_SEL_CHANGED
209 class wxCalendarCtrl : public wxControl
212 %pythonAppend wxCalendarCtrl "self._setOORInfo(self)"
213 %pythonAppend wxCalendarCtrl() ""
216 wxCalendarCtrl(wxWindow *parent,
218 const wxDateTime& date = wxDefaultDateTime,
219 const wxPoint& pos = wxDefaultPosition,
220 const wxSize& size = wxDefaultSize,
221 long style = wxCAL_SHOW_HOLIDAYS | wxWANTS_CHARS,
222 const wxString& name = wxPyCalendarNameStr),
223 "Create and show a calendar control.", "");
227 "Precreate a CalendarCtrl for 2-phase creation.", "",
231 bool , Create(wxWindow *parent,
233 const wxDateTime& date = wxDefaultDateTime,
234 const wxPoint& pos = wxDefaultPosition,
235 const wxSize& size = wxDefaultSize,
236 long style = wxCAL_SHOW_HOLIDAYS | wxWANTS_CHARS,
237 const wxString& name = wxPyCalendarNameStr),
238 "Acutally create the GUI portion of the CalendarCtrl for 2-phase
244 void, SetDate(const wxDateTime& date),
245 "Sets the current date.", "");
248 const wxDateTime&, GetDate() const,
249 "Gets the currently selected date.", "");
254 bool, SetLowerDateLimit(const wxDateTime& date = wxDefaultDateTime),
255 "set the range in which selection can occur", "");
258 bool, SetUpperDateLimit(const wxDateTime& date = wxDefaultDateTime),
259 "set the range in which selection can occur", "");
262 const wxDateTime&, GetLowerDateLimit() const,
263 "get the range in which selection can occur", "");
266 const wxDateTime&, GetUpperDateLimit() const,
267 "get the range in which selection can occur", "");
270 bool, SetDateRange(const wxDateTime& lowerdate = wxDefaultDateTime,
271 const wxDateTime& upperdate = wxDefaultDateTime),
272 "set the range in which selection can occur", "");
278 void, EnableYearChange(bool enable = True),
279 "This function should be used instead of changing CAL_NO_YEAR_CHANGE
280 style bit directly. It allows or disallows the user to change the year
281 interactively.", "");
284 void, EnableMonthChange(bool enable = True),
285 "This function should be used instead of changing CAL_NO_MONTH_CHANGE
286 style bit. It allows or disallows the user to change the month
287 interactively. Note that if the month can not be changed, the year can
288 not be changed either.", "");
291 void, EnableHolidayDisplay(bool display = True),
292 "This function should be used instead of changing CAL_SHOW_HOLIDAYS
293 style bit directly. It enables or disables the special highlighting of
299 void, SetHeaderColours(const wxColour& colFg, const wxColour& colBg),
300 "Header colours are used for painting the weekdays at the top.", "");
303 wxColour, GetHeaderColourFg() const,
304 "Header colours are used for painting the weekdays at the top.", "");
307 wxColour, GetHeaderColourBg() const,
308 "Header colours are used for painting the weekdays at the top.", "");
313 void, SetHighlightColours(const wxColour& colFg, const wxColour& colBg),
314 "Highlight colour is used for the currently selected date.", "");
317 wxColour, GetHighlightColourFg() const,
318 "Highlight colour is used for the currently selected date.", "");
321 wxColour, GetHighlightColourBg() const,
322 "Highlight colour is used for the currently selected date.", "");
327 void, SetHolidayColours(const wxColour& colFg, const wxColour& colBg),
328 "Holiday colour is used for the holidays (if CAL_SHOW_HOLIDAYS style is
332 wxColour, GetHolidayColourFg() const,
333 "Holiday colour is used for the holidays (if CAL_SHOW_HOLIDAYS style is
337 wxColour, GetHolidayColourBg() const,
338 "Holiday colour is used for the holidays (if CAL_SHOW_HOLIDAYS style is
344 wxCalendarDateAttr*, GetAttr(size_t day) const,
345 "Returns the attribute for the given date (should be in the range
346 1...31). The returned value may be None", "");
349 void, SetAttr(size_t day, wxCalendarDateAttr *attr),
350 "Associates the attribute with the specified date (in the range
351 1...31). If the attribute passed is None, the items attribute is
355 void, SetHoliday(size_t day),
356 "Marks the specified day as being a holiday in the current month.", "");
359 void, ResetAttr(size_t day),
360 "Clears any attributes associated with the given day (in the range
366 "HitTest(Point pos) -> (result, date, weekday)",
367 "Returns 3-tuple with information about the given position on the
368 calendar control. The first value of the tuple is a result code and
369 determines the validity of the remaining two values.",
371 The result codes are:
373 =================== ============================================
374 CAL_HITTEST_NOWHERE hit outside of anything
375 CAL_HITTEST_HEADER hit on the header, weekday is valid
376 CAL_HITTEST_DAY hit on a day in the calendar, date is set.
377 =================== ============================================
380 PyObject* HitTest(const wxPoint& pos) {
381 wxDateTime* date = new wxDateTime;
382 wxDateTime::WeekDay wd;
383 wxCalendarHitTestResult result = self->HitTest(pos, date, &wd);
384 bool blocked = wxPyBeginBlockThreads();
385 PyObject* tup = PyTuple_New(3);
386 PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(result));
387 PyTuple_SET_ITEM(tup, 1, wxPyConstructObject(date, wxT("wxDateTime"), 1));
388 PyTuple_SET_ITEM(tup, 2, PyInt_FromLong(wd));
389 wxPyEndBlockThreads(blocked);
395 wxControl*, GetMonthControl() const,
396 "Get the currently shown control for month.", "");
399 wxControl*, GetYearControl() const,
400 "Get the currently shown control for year.", "");
402 static wxVisualAttributes
403 GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL);
407 //---------------------------------------------------------------------------
412 //---------------------------------------------------------------------------