]> git.saurik.com Git - wxWidgets.git/blame - wxPython/src/calendar.i
little tweaks
[wxWidgets.git] / wxPython / src / calendar.i
CommitLineData
f6bcfd97
BP
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
c8fac2b6
RD
13%define DOCSTRING
14"Classes for an interactive Calendar control."
15%enddef
b2eb030f
RD
16
17%module(package="wx", docstring=DOCSTRING) calendar
f6bcfd97
BP
18
19
20%{
d14a1e28
RD
21#include "wx/wxPython/wxPython.h"
22#include "wx/wxPython/pyclasses.h"
23
f6bcfd97
BP
24#include <wx/calctrl.h>
25%}
26
27//----------------------------------------------------------------------
28
f6bcfd97 29%import misc.i
54f9ee45 30%pythoncode { wx = _core }
99109c0f 31%pythoncode { __docfilter__ = wx.__DocFilter(globals()) }
f6bcfd97 32
d14a1e28 33%include _calendar_rename.i
f6bcfd97
BP
34
35//---------------------------------------------------------------------------
36
37enum {
38 wxCAL_SUNDAY_FIRST,
39 wxCAL_MONDAY_FIRST,
40 wxCAL_SHOW_HOLIDAYS,
41 wxCAL_NO_YEAR_CHANGE,
42 wxCAL_NO_MONTH_CHANGE,
ab11ebfa
RD
43 wxCAL_SEQUENTIAL_MONTH_SELECTION,
44 wxCAL_SHOW_SURROUNDING_WEEKS,
f6bcfd97
BP
45};
46
47
48enum wxCalendarHitTestResult
49{
50 wxCAL_HITTEST_NOWHERE, // outside of anything
51 wxCAL_HITTEST_HEADER, // on the header (weekdays)
b66824a5 52 wxCAL_HITTEST_DAY, // on a day in the calendar
ab11ebfa
RD
53 wxCAL_HITTEST_INCMONTH,
54 wxCAL_HITTEST_DECMONTH,
55 wxCAL_HITTEST_SURROUNDING_WEEK
f6bcfd97
BP
56};
57
58// border types for a date
59enum wxCalendarDateBorder
60{
61 wxCAL_BORDER_NONE, // no border (default)
62 wxCAL_BORDER_SQUARE, // a rectangular border
63 wxCAL_BORDER_ROUND // a round border
64};
65
66//---------------------------------------------------------------------------
67
856bf319 68DocStr(wxCalendarDateAttr,
dce2bd22 69"A set of customization attributes for a calendar date, which can be
d07d2bc9 70used to control the look of the Calendar object.", "");
f6bcfd97
BP
71
72class wxCalendarDateAttr
73{
74public:
856bf319 75 DocStr(wxCalendarDateAttr,
d07d2bc9 76 "Create a CalendarDateAttr.", "");
856bf319 77 wxCalendarDateAttr(const wxColour& colText = wxNullColour,
f6bcfd97
BP
78 const wxColour& colBack = wxNullColour,
79 const wxColour& colBorder = wxNullColour,
80 const wxFont& font = wxNullFont,
81 wxCalendarDateBorder border = wxCAL_BORDER_NONE);
82
856bf319 83
f6bcfd97
BP
84 // setters
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);
91
92 // accessors
93 bool HasTextColour() const;
94 bool HasBackgroundColour() const;
95 bool HasBorderColour() const;
96 bool HasFont() const;
97 bool HasBorder() const;
98
99 bool IsHoliday() const;
100
c5943253
RD
101 wxColour GetTextColour() const;
102 wxColour GetBackgroundColour() const;
103 wxColour GetBorderColour() const;
104 wxFont GetFont() const;
f6bcfd97
BP
105 wxCalendarDateBorder GetBorder() const;
106};
107
108//---------------------------------------------------------------------------
109
110class wxCalendarCtrl;
111
112class wxCalendarEvent : public wxCommandEvent
113{
114public:
115 wxCalendarEvent(wxCalendarCtrl *cal, wxEventType type);
116
ae5343ec 117 const wxDateTime GetDate() const;
3f0ff538
RD
118 void SetDate(const wxDateTime &date);
119 void SetWeekDay(const wxDateTime::WeekDay wd);
f6bcfd97
BP
120 wxDateTime::WeekDay GetWeekDay() const;
121
122};
123
f6bcfd97 124
d14a1e28
RD
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;
f6bcfd97 131
f6bcfd97 132
d14a1e28
RD
133%pythoncode {
134EVT_CALENDAR = wx.PyEventBinder( wxEVT_CALENDAR_DOUBLECLICKED, 1)
135EVT_CALENDAR_SEL_CHANGED = wx.PyEventBinder( wxEVT_CALENDAR_SEL_CHANGED, 1)
136EVT_CALENDAR_DAY = wx.PyEventBinder( wxEVT_CALENDAR_DAY_CHANGED, 1)
137EVT_CALENDAR_MONTH = wx.PyEventBinder( wxEVT_CALENDAR_MONTH_CHANGED, 1)
138EVT_CALENDAR_YEAR = wx.PyEventBinder( wxEVT_CALENDAR_YEAR_CHANGED, 1)
139EVT_CALENDAR_WEEKDAY_CLICKED = wx.PyEventBinder( wxEVT_CALENDAR_WEEKDAY_CLICKED, 1)
140}
f6bcfd97 141
f6bcfd97
BP
142
143//---------------------------------------------------------------------------
144
b2dc1044 145MAKE_CONST_WXSTRING(CalendarNameStr);
137b5242 146
d14a1e28 147
856bf319 148DocStr(wxCalendarCtrl,
dce2bd22
RD
149"The calendar control allows the user to pick a date interactively.
150
151The CalendarCtrl displays a window containing several parts: the
152control to pick the month and the year at the top (either or both of
153them may be disabled) and a month area below them which shows all the
154days in the month. The user can move the current selection using the
155keyboard and select the date (generating EVT_CALENDAR event) by
156pressing <Return> or double clicking it.
157
158It has advanced possibilities for the customization of its
159display. All global settings (such as colours and fonts used) can, of
160course, be changed. But also, the display style for each day in the
161month can be set independently using CalendarDateAttr class.
162
163An item without custom attributes is drawn with the default colours
164and font and without border, but setting custom attributes with
165SetAttr allows to modify its appearance. Just create a custom
166attribute object and set it for the day you want to be displayed
167specially A day may be marked as being a holiday, (even if it is not
168recognized as one by wx.DateTime) by using the SetHoliday method.
169
170As the attributes are specified for each day, they may change when the
171month is changed, so you will often want to update them in an
d07d2bc9 172EVT_CALENDAR_MONTH event handler.", "
dce2bd22
RD
173
174Window Styles
175-------------
176 ============================== ============================
177 CAL_SUNDAY_FIRST Show Sunday as the first day
178 in the week
179 CAL_MONDAY_FIRST Show Monday as the first day
180 in the week
181 CAL_SHOW_HOLIDAYS Highlight holidays in the
182 calendar
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
190 selection controls.
c8fac2b6 191 ============================== ============================
dce2bd22
RD
192
193The default calendar style is CAL_SHOW_HOLIDAYS.
194
195Events
196-------
c8fac2b6 197 ============================= ==============================
dce2bd22
RD
198 EVT_CALENDAR A day was double clicked in the
199 calendar.
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
205 header
c8fac2b6 206 ============================= ==============================
dce2bd22
RD
207
208Note that changing the selected date will result in one of
209EVT_CALENDAR_DAY, MONTH or YEAR events and an EVT_CALENDAR_SEL_CHANGED
210event.
856bf319
RD
211
212");
213
214
ab1f7d2a
RD
215MustHaveApp(wxCalendarCtrl);
216
f6bcfd97
BP
217class wxCalendarCtrl : public wxControl
218{
219public:
2b9048c5
RD
220 %pythonAppend wxCalendarCtrl "self._setOORInfo(self)"
221 %pythonAppend wxCalendarCtrl() ""
d14a1e28 222
dce2bd22
RD
223 DocCtorStr(
224 wxCalendarCtrl(wxWindow *parent,
225 wxWindowID id=-1,
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),
d07d2bc9 231 "Create and show a calendar control.", "");
dce2bd22
RD
232
233 DocCtorStrName(
234 wxCalendarCtrl(),
d07d2bc9 235 "Precreate a CalendarCtrl for 2-phase creation.", "",
dce2bd22 236 PreCalendarCtrl);
09f3d4e6 237
dce2bd22
RD
238 DocDeclStr(
239 bool , Create(wxWindow *parent,
240 wxWindowID id,
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
d07d2bc9 247creation.", "");
dce2bd22 248
f6bcfd97 249
0122b7e3 250
856bf319
RD
251 DocDeclStr(
252 void, SetDate(const wxDateTime& date),
d07d2bc9 253 "Sets the current date.", "");
856bf319
RD
254
255 DocDeclStr(
256 const wxDateTime&, GetDate() const,
d07d2bc9 257 "Gets the currently selected date.", "");
856bf319
RD
258
259
260
261 DocDeclStr(
262 bool, SetLowerDateLimit(const wxDateTime& date = wxDefaultDateTime),
d07d2bc9 263 "set the range in which selection can occur", "");
856bf319
RD
264
265 DocDeclStr(
266 bool, SetUpperDateLimit(const wxDateTime& date = wxDefaultDateTime),
d07d2bc9 267 "set the range in which selection can occur", "");
856bf319
RD
268
269 DocDeclStr(
270 const wxDateTime&, GetLowerDateLimit() const,
d07d2bc9 271 "get the range in which selection can occur", "");
856bf319
RD
272
273 DocDeclStr(
274 const wxDateTime&, GetUpperDateLimit() const,
d07d2bc9 275 "get the range in which selection can occur", "");
856bf319
RD
276
277 DocDeclStr(
278 bool, SetDateRange(const wxDateTime& lowerdate = wxDefaultDateTime,
279 const wxDateTime& upperdate = wxDefaultDateTime),
d07d2bc9 280 "set the range in which selection can occur", "");
856bf319
RD
281
282
283
284
285 DocDeclStr(
286 void, EnableYearChange(bool enable = True),
dce2bd22
RD
287 "This function should be used instead of changing CAL_NO_YEAR_CHANGE
288style bit directly. It allows or disallows the user to change the year
d07d2bc9 289interactively.", "");
856bf319
RD
290
291 DocDeclStr(
292 void, EnableMonthChange(bool enable = True),
dce2bd22
RD
293 "This function should be used instead of changing CAL_NO_MONTH_CHANGE
294style bit. It allows or disallows the user to change the month
295interactively. Note that if the month can not be changed, the year can
d07d2bc9 296not be changed either.", "");
856bf319
RD
297
298 DocDeclStr(
299 void, EnableHolidayDisplay(bool display = True),
dce2bd22
RD
300 "This function should be used instead of changing CAL_SHOW_HOLIDAYS
301style bit directly. It enables or disables the special highlighting of
d07d2bc9 302the holidays.", "");
856bf319
RD
303
304
305
306 DocDeclStr(
307 void, SetHeaderColours(const wxColour& colFg, const wxColour& colBg),
d07d2bc9 308 "Header colours are used for painting the weekdays at the top.", "");
856bf319
RD
309
310 DocDeclStr(
311 wxColour, GetHeaderColourFg() const,
d07d2bc9 312 "Header colours are used for painting the weekdays at the top.", "");
856bf319
RD
313
314 DocDeclStr(
315 wxColour, GetHeaderColourBg() const,
d07d2bc9 316 "Header colours are used for painting the weekdays at the top.", "");
856bf319
RD
317
318
319
320 DocDeclStr(
321 void, SetHighlightColours(const wxColour& colFg, const wxColour& colBg),
d07d2bc9 322 "Highlight colour is used for the currently selected date.", "");
856bf319
RD
323
324 DocDeclStr(
325 wxColour, GetHighlightColourFg() const,
d07d2bc9 326 "Highlight colour is used for the currently selected date.", "");
856bf319
RD
327
328 DocDeclStr(
329 wxColour, GetHighlightColourBg() const,
d07d2bc9 330 "Highlight colour is used for the currently selected date.", "");
856bf319
RD
331
332
333
334 DocDeclStr(
335 void, SetHolidayColours(const wxColour& colFg, const wxColour& colBg),
dce2bd22 336 "Holiday colour is used for the holidays (if CAL_SHOW_HOLIDAYS style is
d07d2bc9 337used).", "");
856bf319
RD
338
339 DocDeclStr(
340 wxColour, GetHolidayColourFg() const,
dce2bd22 341 "Holiday colour is used for the holidays (if CAL_SHOW_HOLIDAYS style is
d07d2bc9 342used).", "");
856bf319
RD
343
344 DocDeclStr(
345 wxColour, GetHolidayColourBg() const,
dce2bd22 346 "Holiday colour is used for the holidays (if CAL_SHOW_HOLIDAYS style is
d07d2bc9 347used).", "");
856bf319
RD
348
349
350
351 DocDeclStr(
352 wxCalendarDateAttr*, GetAttr(size_t day) const,
dce2bd22 353 "Returns the attribute for the given date (should be in the range
d07d2bc9 3541...31). The returned value may be None", "");
856bf319
RD
355
356 DocDeclStr(
357 void, SetAttr(size_t day, wxCalendarDateAttr *attr),
dce2bd22
RD
358 "Associates the attribute with the specified date (in the range
3591...31). If the attribute passed is None, the items attribute is
d07d2bc9 360cleared.", "");
856bf319
RD
361
362 DocDeclStr(
363 void, SetHoliday(size_t day),
d07d2bc9 364 "Marks the specified day as being a holiday in the current month.", "");
856bf319
RD
365
366 DocDeclStr(
367 void, ResetAttr(size_t day),
dce2bd22 368 "Clears any attributes associated with the given day (in the range
d07d2bc9 3691...31).", "");
856bf319
RD
370
371
372
373 DocAStr(HitTest,
374 "HitTest(Point pos) -> (result, date, weekday)",
dce2bd22
RD
375"Returns 3-tuple with information about the given position on the
376calendar control. The first value of the tuple is a result code and
d07d2bc9
RD
377determines the validity of the remaining two values.",
378"
379The result codes are:
dce2bd22
RD
380
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 =================== ============================================
856bf319
RD
386");
387 %extend {
388 PyObject* HitTest(const wxPoint& pos) {
389 wxDateTime* date = new wxDateTime;
390 wxDateTime::WeekDay wd;
391 wxCalendarHitTestResult result = self->HitTest(pos, date, &wd);
da32eb53 392 bool blocked = wxPyBeginBlockThreads();
856bf319
RD
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));
da32eb53 397 wxPyEndBlockThreads(blocked);
856bf319
RD
398 return tup;
399 }
400 }
401
402 DocDeclStr(
403 wxControl*, GetMonthControl() const,
d07d2bc9 404 "Get the currently shown control for month.", "");
856bf319
RD
405
406 DocDeclStr(
407 wxControl*, GetYearControl() const,
d07d2bc9 408 "Get the currently shown control for year.", "");
880715c9
RD
409
410 static wxVisualAttributes
411 GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL);
f6bcfd97
BP
412};
413
414
415//---------------------------------------------------------------------------
e508a2b6
RD
416
417%init %{
e508a2b6
RD
418%}
419
f6bcfd97
BP
420//---------------------------------------------------------------------------
421