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."
17 %module(package="wx", docstring=DOCSTRING) calendar
21 #include "wx/wxPython/wxPython.h"
22 #include "wx/wxPython/pyclasses.h"
24 #include <wx/calctrl.h>
27 //----------------------------------------------------------------------
30 %pythoncode { wx = _core }
31 %pythoncode { __docfilter__ = wx.__DocFilter(globals()) }
33 %include _calendar_rename.i
35 //---------------------------------------------------------------------------
42 wxCAL_NO_MONTH_CHANGE,
43 wxCAL_SEQUENTIAL_MONTH_SELECTION,
44 wxCAL_SHOW_SURROUNDING_WEEKS,
48 enum wxCalendarHitTestResult
50 wxCAL_HITTEST_NOWHERE, // outside of anything
51 wxCAL_HITTEST_HEADER, // on the header (weekdays)
52 wxCAL_HITTEST_DAY, // on a day in the calendar
53 wxCAL_HITTEST_INCMONTH,
54 wxCAL_HITTEST_DECMONTH,
55 wxCAL_HITTEST_SURROUNDING_WEEK
58 // border types for a date
59 enum wxCalendarDateBorder
61 wxCAL_BORDER_NONE, // no border (default)
62 wxCAL_BORDER_SQUARE, // a rectangular border
63 wxCAL_BORDER_ROUND // a round border
66 //---------------------------------------------------------------------------
68 DocStr(wxCalendarDateAttr,
69 "A set of customization attributes for a calendar date, which can be
70 used to control the look of the Calendar object.", "");
72 class wxCalendarDateAttr
75 DocStr(wxCalendarDateAttr,
76 "Create a CalendarDateAttr.", "");
77 wxCalendarDateAttr(const wxColour& colText = wxNullColour,
78 const wxColour& colBack = wxNullColour,
79 const wxColour& colBorder = wxNullColour,
80 const wxFont& font = wxNullFont,
81 wxCalendarDateBorder border = wxCAL_BORDER_NONE);
85 void SetTextColour(const wxColour& colText);
86 void SetBackgroundColour(const wxColour& colBack);
87 void SetBorderColour(const wxColour& col);
88 void SetFont(const wxFont& font);
89 void SetBorder(wxCalendarDateBorder border);
90 void SetHoliday(bool holiday);
93 bool HasTextColour() const;
94 bool HasBackgroundColour() const;
95 bool HasBorderColour() const;
97 bool HasBorder() const;
99 bool IsHoliday() const;
101 wxColour GetTextColour() const;
102 wxColour GetBackgroundColour() const;
103 wxColour GetBorderColour() const;
104 wxFont GetFont() const;
105 wxCalendarDateBorder GetBorder() const;
108 //---------------------------------------------------------------------------
110 class wxCalendarCtrl;
112 class wxCalendarEvent : public wxCommandEvent
115 wxCalendarEvent(wxCalendarCtrl *cal, wxEventType type);
117 const wxDateTime GetDate() const;
118 void SetDate(const wxDateTime &date);
119 void SetWeekDay(const wxDateTime::WeekDay wd);
120 wxDateTime::WeekDay GetWeekDay() const;
125 %constant wxEventType wxEVT_CALENDAR_DOUBLECLICKED;
126 %constant wxEventType wxEVT_CALENDAR_SEL_CHANGED;
127 %constant wxEventType wxEVT_CALENDAR_DAY_CHANGED;
128 %constant wxEventType wxEVT_CALENDAR_MONTH_CHANGED;
129 %constant wxEventType wxEVT_CALENDAR_YEAR_CHANGED;
130 %constant wxEventType wxEVT_CALENDAR_WEEKDAY_CLICKED;
134 EVT_CALENDAR = wx.PyEventBinder( wxEVT_CALENDAR_DOUBLECLICKED, 1)
135 EVT_CALENDAR_SEL_CHANGED = wx.PyEventBinder( wxEVT_CALENDAR_SEL_CHANGED, 1)
136 EVT_CALENDAR_DAY = wx.PyEventBinder( wxEVT_CALENDAR_DAY_CHANGED, 1)
137 EVT_CALENDAR_MONTH = wx.PyEventBinder( wxEVT_CALENDAR_MONTH_CHANGED, 1)
138 EVT_CALENDAR_YEAR = wx.PyEventBinder( wxEVT_CALENDAR_YEAR_CHANGED, 1)
139 EVT_CALENDAR_WEEKDAY_CLICKED = wx.PyEventBinder( wxEVT_CALENDAR_WEEKDAY_CLICKED, 1)
143 //---------------------------------------------------------------------------
145 MAKE_CONST_WXSTRING(CalendarNameStr);
148 DocStr(wxCalendarCtrl,
149 "The calendar control allows the user to pick a date interactively.
151 The CalendarCtrl displays a window containing several parts: the
152 control to pick the month and the year at the top (either or both of
153 them may be disabled) and a month area below them which shows all the
154 days in the month. The user can move the current selection using the
155 keyboard and select the date (generating EVT_CALENDAR event) by
156 pressing <Return> or double clicking it.
158 It has advanced possibilities for the customization of its
159 display. All global settings (such as colours and fonts used) can, of
160 course, be changed. But also, the display style for each day in the
161 month can be set independently using CalendarDateAttr class.
163 An item without custom attributes is drawn with the default colours
164 and font and without border, but setting custom attributes with
165 SetAttr allows to modify its appearance. Just create a custom
166 attribute object and set it for the day you want to be displayed
167 specially A day may be marked as being a holiday, (even if it is not
168 recognized as one by wx.DateTime) by using the SetHoliday method.
170 As the attributes are specified for each day, they may change when the
171 month is changed, so you will often want to update them in an
172 EVT_CALENDAR_MONTH event handler.", "
176 ============================== ============================
177 CAL_SUNDAY_FIRST Show Sunday as the first day
179 CAL_MONDAY_FIRST Show Monday as the first day
181 CAL_SHOW_HOLIDAYS Highlight holidays in the
183 CAL_NO_YEAR_CHANGE Disable the year changing
184 CAL_NO_MONTH_CHANGE Disable the month (and,
185 implicitly, the year) changing
186 CAL_SHOW_SURROUNDING_WEEKS Show the neighbouring weeks in
187 the previous and next months
188 CAL_SEQUENTIAL_MONTH_SELECTION Use alternative, more compact,
189 style for the month and year
191 ============================== ============================
193 The default calendar style is CAL_SHOW_HOLIDAYS.
197 ============================= ==============================
198 EVT_CALENDAR A day was double clicked in the
200 EVT_CALENDAR_SEL_CHANGED The selected date changed.
201 EVT_CALENDAR_DAY The selected day changed.
202 EVT_CALENDAR_MONTH The selected month changed.
203 EVT_CALENDAR_YEAR The selected year changed.
204 EVT_CALENDAR_WEEKDAY_CLICKED User clicked on the week day
206 ============================= ==============================
208 Note that changing the selected date will result in one of
209 EVT_CALENDAR_DAY, MONTH or YEAR events and an EVT_CALENDAR_SEL_CHANGED
215 MustHaveApp(wxCalendarCtrl);
217 class wxCalendarCtrl : public wxControl
220 %pythonAppend wxCalendarCtrl "self._setOORInfo(self)"
221 %pythonAppend wxCalendarCtrl() ""
224 wxCalendarCtrl(wxWindow *parent,
226 const wxDateTime& date = wxDefaultDateTime,
227 const wxPoint& pos = wxDefaultPosition,
228 const wxSize& size = wxDefaultSize,
229 long style = wxCAL_SHOW_HOLIDAYS | wxWANTS_CHARS,
230 const wxString& name = wxPyCalendarNameStr),
231 "Create and show a calendar control.", "");
235 "Precreate a CalendarCtrl for 2-phase creation.", "",
239 bool , Create(wxWindow *parent,
241 const wxDateTime& date = wxDefaultDateTime,
242 const wxPoint& pos = wxDefaultPosition,
243 const wxSize& size = wxDefaultSize,
244 long style = wxCAL_SHOW_HOLIDAYS | wxWANTS_CHARS,
245 const wxString& name = wxPyCalendarNameStr),
246 "Acutally create the GUI portion of the CalendarCtrl for 2-phase
252 void, SetDate(const wxDateTime& date),
253 "Sets the current date.", "");
256 const wxDateTime&, GetDate() const,
257 "Gets the currently selected date.", "");
262 bool, SetLowerDateLimit(const wxDateTime& date = wxDefaultDateTime),
263 "set the range in which selection can occur", "");
266 bool, SetUpperDateLimit(const wxDateTime& date = wxDefaultDateTime),
267 "set the range in which selection can occur", "");
270 const wxDateTime&, GetLowerDateLimit() const,
271 "get the range in which selection can occur", "");
274 const wxDateTime&, GetUpperDateLimit() const,
275 "get the range in which selection can occur", "");
278 bool, SetDateRange(const wxDateTime& lowerdate = wxDefaultDateTime,
279 const wxDateTime& upperdate = wxDefaultDateTime),
280 "set the range in which selection can occur", "");
286 void, EnableYearChange(bool enable = True),
287 "This function should be used instead of changing CAL_NO_YEAR_CHANGE
288 style bit directly. It allows or disallows the user to change the year
289 interactively.", "");
292 void, EnableMonthChange(bool enable = True),
293 "This function should be used instead of changing CAL_NO_MONTH_CHANGE
294 style bit. It allows or disallows the user to change the month
295 interactively. Note that if the month can not be changed, the year can
296 not be changed either.", "");
299 void, EnableHolidayDisplay(bool display = True),
300 "This function should be used instead of changing CAL_SHOW_HOLIDAYS
301 style bit directly. It enables or disables the special highlighting of
307 void, SetHeaderColours(const wxColour& colFg, const wxColour& colBg),
308 "Header colours are used for painting the weekdays at the top.", "");
311 wxColour, GetHeaderColourFg() const,
312 "Header colours are used for painting the weekdays at the top.", "");
315 wxColour, GetHeaderColourBg() const,
316 "Header colours are used for painting the weekdays at the top.", "");
321 void, SetHighlightColours(const wxColour& colFg, const wxColour& colBg),
322 "Highlight colour is used for the currently selected date.", "");
325 wxColour, GetHighlightColourFg() const,
326 "Highlight colour is used for the currently selected date.", "");
329 wxColour, GetHighlightColourBg() const,
330 "Highlight colour is used for the currently selected date.", "");
335 void, SetHolidayColours(const wxColour& colFg, const wxColour& colBg),
336 "Holiday colour is used for the holidays (if CAL_SHOW_HOLIDAYS style is
340 wxColour, GetHolidayColourFg() const,
341 "Holiday colour is used for the holidays (if CAL_SHOW_HOLIDAYS style is
345 wxColour, GetHolidayColourBg() const,
346 "Holiday colour is used for the holidays (if CAL_SHOW_HOLIDAYS style is
352 wxCalendarDateAttr*, GetAttr(size_t day) const,
353 "Returns the attribute for the given date (should be in the range
354 1...31). The returned value may be None", "");
357 void, SetAttr(size_t day, wxCalendarDateAttr *attr),
358 "Associates the attribute with the specified date (in the range
359 1...31). If the attribute passed is None, the items attribute is
363 void, SetHoliday(size_t day),
364 "Marks the specified day as being a holiday in the current month.", "");
367 void, ResetAttr(size_t day),
368 "Clears any attributes associated with the given day (in the range
374 "HitTest(Point pos) -> (result, date, weekday)",
375 "Returns 3-tuple with information about the given position on the
376 calendar control. The first value of the tuple is a result code and
377 determines the validity of the remaining two values.",
379 The result codes are:
381 =================== ============================================
382 CAL_HITTEST_NOWHERE hit outside of anything
383 CAL_HITTEST_HEADER hit on the header, weekday is valid
384 CAL_HITTEST_DAY hit on a day in the calendar, date is set.
385 =================== ============================================
388 PyObject* HitTest(const wxPoint& pos) {
389 wxDateTime* date = new wxDateTime;
390 wxDateTime::WeekDay wd;
391 wxCalendarHitTestResult result = self->HitTest(pos, date, &wd);
392 bool blocked = wxPyBeginBlockThreads();
393 PyObject* tup = PyTuple_New(3);
394 PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(result));
395 PyTuple_SET_ITEM(tup, 1, wxPyConstructObject(date, wxT("wxDateTime"), 1));
396 PyTuple_SET_ITEM(tup, 2, PyInt_FromLong(wd));
397 wxPyEndBlockThreads(blocked);
403 wxControl*, GetMonthControl() const,
404 "Get the currently shown control for month.", "");
407 wxControl*, GetYearControl() const,
408 "Get the currently shown control for year.", "");
410 static wxVisualAttributes
411 GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL);
415 //---------------------------------------------------------------------------
420 //---------------------------------------------------------------------------