]> git.saurik.com Git - wxWidgets.git/blob - include/wx/generic/calctrl.h
1. corrections for compilation of the wxBase apps with wxApp
[wxWidgets.git] / include / wx / generic / calctrl.h
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: generic/calctrl.h
3 // Purpose: generic implementation of date-picker control
4 // Author: Vadim Zeitlin
5 // Modified by:
6 // Created: 29.12.99
7 // RCS-ID: $Id$
8 // Copyright: (c) 1999 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
9 // Licence: wxWindows license
10 ///////////////////////////////////////////////////////////////////////////////
11
12 #ifdef __GNUG__
13 #pragma interface "calctrl.h"
14 #endif
15
16 #ifndef _WX_GENERIC_CALCTRL_H
17 #define _WX_GENERIC_CALCTRL_H
18
19 #include "wx/control.h" // the base class
20
21 #include "wx/spinctrl.h" // for wxSpinEvent
22
23 class WXDLLEXPORT wxComboBox;
24 class WXDLLEXPORT wxStaticText;
25
26 #define wxCalendarNameStr _T("CalendarCtrl")
27
28 // ----------------------------------------------------------------------------
29 // wxCalendarCtrl: a control allowing the user to pick a date interactively
30 // ----------------------------------------------------------------------------
31
32 class WXDLLEXPORT wxCalendarCtrl : public wxControl
33 {
34 friend class wxMonthComboBox;
35 friend class wxYearSpinCtrl;
36
37 public:
38 // construction
39 wxCalendarCtrl() { Init(); }
40 wxCalendarCtrl(wxWindow *parent,
41 wxWindowID id,
42 const wxDateTime& date = wxDefaultDateTime,
43 const wxPoint& pos = wxDefaultPosition,
44 const wxSize& size = wxDefaultSize,
45 long style = wxCAL_SHOW_HOLIDAYS,
46 const wxString& name = wxCalendarNameStr)
47 : wxControl(parent, id, pos, size,
48 style | wxWANTS_CHARS, wxDefaultValidator, name)
49 {
50 Init();
51
52 (void)Create(parent, id, date, pos, size, style, name);
53 }
54
55 bool Create(wxWindow *parent,
56 wxWindowID id,
57 const wxDateTime& date = wxDefaultDateTime,
58 const wxPoint& pos = wxDefaultPosition,
59 const wxSize& size = wxDefaultSize,
60 long style = wxCAL_SHOW_HOLIDAYS,
61 const wxString& name = wxCalendarNameStr);
62
63 virtual ~wxCalendarCtrl();
64
65 // set/get the current date
66 // ------------------------
67
68 void SetDate(const wxDateTime& date);
69 const wxDateTime& GetDate() const { return m_date; }
70
71 // calendar mode
72 // -------------
73
74 // some calendar styles can't be changed after the control creation by
75 // just using SetWindowStyle() and Refresh() and the functions below
76 // should be used instead for them
77
78 // corresponds to wxCAL_NO_YEAR_CHANGE bit
79 void EnableYearChange(bool enable = TRUE);
80
81 // corresponds to wxCAL_NO_MONTH_CHANGE bit
82 void EnableMonthChange(bool enable = TRUE);
83
84 // corresponds to wxCAL_SHOW_HOLIDAYS bit
85 void EnableHolidayDisplay(bool display = TRUE);
86
87 // customization
88 // -------------
89
90 // header colours are used for painting the weekdays at the top
91 void SetHeaderColours(const wxColour& colFg, const wxColour& colBg)
92 {
93 m_colHeaderFg = colFg;
94 m_colHeaderBg = colBg;
95 }
96
97 const wxColour& GetHeaderColourFg() const { return m_colHeaderFg; }
98 const wxColour& GetHeaderColourBg() const { return m_colHeaderBg; }
99
100 // highlight colour is used for the currently selected date
101 void SetHighlightColours(const wxColour& colFg, const wxColour& colBg)
102 {
103 m_colHighlightFg = colFg;
104 m_colHighlightBg = colBg;
105 }
106
107 const wxColour& GetHighlightColourFg() const { return m_colHighlightFg; }
108 const wxColour& GetHighlightColourBg() const { return m_colHighlightBg; }
109
110 // holiday colour is used for the holidays (if style & wxCAL_SHOW_HOLIDAYS)
111 void SetHolidayColours(const wxColour& colFg, const wxColour& colBg)
112 {
113 m_colHolidayFg = colFg;
114 m_colHolidayBg = colBg;
115 }
116
117 const wxColour& GetHolidayColourFg() const { return m_colHolidayFg; }
118 const wxColour& GetHolidayColourBg() const { return m_colHolidayBg; }
119
120 // an item without custom attributes is drawn with the default colours and
121 // font and without border, setting custom attributes allows to modify this
122 //
123 // the day parameter should be in 1..31 range, for days 29, 30, 31 the
124 // corresponding attribute is just unused if there is no such day in the
125 // current month
126
127 wxCalendarDateAttr *GetAttr(size_t day) const
128 {
129 wxCHECK_MSG( day > 0 && day < 32, NULL, _T("invalid day") );
130
131 return m_attrs[day - 1];
132 }
133
134 void SetAttr(size_t day, wxCalendarDateAttr *attr)
135 {
136 wxCHECK_RET( day > 0 && day < 32, _T("invalid day") );
137
138 delete m_attrs[day - 1];
139 m_attrs[day - 1] = attr;
140 }
141
142 void SetHoliday(size_t day);
143
144 void ResetAttr(size_t day) { SetAttr(day, (wxCalendarDateAttr *)NULL); }
145
146 // returns one of wxCAL_HITTEST_XXX constants and fills either date or wd
147 // with the corresponding value (none for NOWHERE, the date for DAY and wd
148 // for HEADER)
149 wxCalendarHitTestResult HitTest(const wxPoint& pos,
150 wxDateTime *date = NULL,
151 wxDateTime::WeekDay *wd = NULL);
152
153 // implementation only from now on
154 // -------------------------------
155
156 // forward these functions to all subcontrols
157 virtual bool Enable(bool enable = TRUE);
158 virtual bool Show(bool show = TRUE);
159
160 private:
161 // common part of all ctors
162 void Init();
163
164 // event handlers
165 void OnPaint(wxPaintEvent& event);
166 void OnClick(wxMouseEvent& event);
167 void OnDClick(wxMouseEvent& event);
168 void OnChar(wxKeyEvent& event);
169 void OnMonthChange(wxCommandEvent& event);
170 void OnYearChange(wxSpinEvent& event);
171 void OnCalMonthChange(wxCalendarEvent& event);
172
173 // override some base class virtuals
174 virtual wxSize DoGetBestSize() const;
175 virtual void DoGetPosition(int *x, int *y) const;
176 virtual void DoGetSize(int *width, int *height) const;
177 virtual void DoSetSize(int x, int y, int width, int height, int sizeFlags);
178 virtual void DoMoveWindow(int x, int y, int width, int height);
179
180 // (re)calc m_widthCol and m_heightRow
181 void RecalcGeometry();
182
183 // set the date and send the notification
184 void SetDateAndNotify(const wxDateTime& date);
185
186 // get the week (row, in range 1..6) for the given date
187 size_t GetWeek(const wxDateTime& date) const;
188
189 // get the date from which we start drawing days
190 wxDateTime GetStartDate() const;
191
192 // is this date shown?
193 bool IsDateShown(const wxDateTime& date) const;
194
195 // redraw the given date
196 void RefreshDate(const wxDateTime& date);
197
198 // change the date inside the same month/year
199 void ChangeDay(const wxDateTime& date);
200
201 // set the attributes for the holidays if needed
202 void SetHolidayAttrs();
203
204 // reset all holidays
205 void ResetHolidayAttrs();
206
207 // generate the given calendar event(s)
208 void GenerateEvent(wxEventType type)
209 {
210 wxCalendarEvent event(this, type);
211 (void)GetEventHandler()->ProcessEvent(event);
212 }
213
214 void GenerateEvents(wxEventType type1, wxEventType type2)
215 {
216 GenerateEvent(type1);
217 GenerateEvent(type2);
218 }
219
220 // do we allow changing the month/year?
221 bool AllowMonthChange() const
222 {
223 return (GetWindowStyle() & wxCAL_NO_MONTH_CHANGE)
224 != wxCAL_NO_MONTH_CHANGE;
225 }
226 bool AllowYearChange() const
227 {
228 return !(GetWindowStyle() & wxCAL_NO_YEAR_CHANGE);
229 }
230
231 // show the correct controls
232 void ShowCurrentControls();
233
234 // get the currently shown control for month/year
235 wxControl *GetMonthControl() const;
236 wxControl *GetYearControl() const;
237
238 // the subcontrols
239 wxStaticText *m_staticMonth;
240 wxComboBox *m_comboMonth;
241
242 wxStaticText *m_staticYear;
243 wxSpinCtrl *m_spinYear;
244
245 // the current selection
246 wxDateTime m_date;
247
248 // default attributes
249 wxColour m_colHighlightFg,
250 m_colHighlightBg,
251 m_colHolidayFg,
252 m_colHolidayBg,
253 m_colHeaderFg,
254 m_colHeaderBg;
255
256 // the attributes for each of the month days
257 wxCalendarDateAttr *m_attrs[31];
258
259 // the width and height of one column/row in the calendar
260 wxCoord m_widthCol,
261 m_heightRow;
262
263 // the week day names
264 wxString m_weekdays[7];
265
266 DECLARE_DYNAMIC_CLASS(wxCalendarCtrl)
267 DECLARE_EVENT_TABLE()
268 };
269
270 #endif // _WX_GENERIC_CALCTRL_H