]> git.saurik.com Git - wxWidgets.git/blob - include/wx/generic/calctrlg.h
Forward port event handler fixes to trunk.
[wxWidgets.git] / include / wx / generic / calctrlg.h
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: generic/calctrlg.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 licence
10 ///////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_GENERIC_CALCTRLG_H
13 #define _WX_GENERIC_CALCTRLG_H
14
15 #include "wx/control.h" // the base class
16 #include "wx/dcclient.h" // for wxPaintDC
17
18 class WXDLLIMPEXP_FWD_CORE wxComboBox;
19 class WXDLLIMPEXP_FWD_CORE wxStaticText;
20 class WXDLLIMPEXP_FWD_CORE wxSpinCtrl;
21
22 // ----------------------------------------------------------------------------
23 // wxGenericCalendarCtrl
24 // ----------------------------------------------------------------------------
25
26 class WXDLLIMPEXP_ADV wxGenericCalendarCtrl : public wxCalendarCtrlBase
27 {
28 public:
29 // construction
30 wxGenericCalendarCtrl() { Init(); }
31 wxGenericCalendarCtrl(wxWindow *parent,
32 wxWindowID id,
33 const wxDateTime& date = wxDefaultDateTime,
34 const wxPoint& pos = wxDefaultPosition,
35 const wxSize& size = wxDefaultSize,
36 long style = wxCAL_SHOW_HOLIDAYS,
37 const wxString& name = wxCalendarNameStr);
38
39 bool Create(wxWindow *parent,
40 wxWindowID id,
41 const wxDateTime& date = wxDefaultDateTime,
42 const wxPoint& pos = wxDefaultPosition,
43 const wxSize& size = wxDefaultSize,
44 long style = wxCAL_SHOW_HOLIDAYS,
45 const wxString& name = wxCalendarNameStr);
46
47 virtual ~wxGenericCalendarCtrl();
48
49 virtual bool Destroy();
50
51 // set/get the current date
52 // ------------------------
53
54 virtual bool SetDate(const wxDateTime& date);
55 virtual wxDateTime GetDate() const { return m_date; }
56
57
58 // set/get the range in which selection can occur
59 // ---------------------------------------------
60
61 virtual bool SetDateRange(const wxDateTime& lowerdate = wxDefaultDateTime,
62 const wxDateTime& upperdate = wxDefaultDateTime);
63
64 virtual bool GetDateRange(wxDateTime *lowerdate, wxDateTime *upperdate) const;
65
66 // these functions are for generic version only, don't use them but use the
67 // Set/GetDateRange() above instead
68 bool SetLowerDateLimit(const wxDateTime& date = wxDefaultDateTime);
69 const wxDateTime& GetLowerDateLimit() const { return m_lowdate; }
70 bool SetUpperDateLimit(const wxDateTime& date = wxDefaultDateTime);
71 const wxDateTime& GetUpperDateLimit() const { return m_highdate; }
72
73
74 // calendar mode
75 // -------------
76
77 // some calendar styles can't be changed after the control creation by
78 // just using SetWindowStyle() and Refresh() and the functions below
79 // should be used instead for them
80
81 // corresponds to wxCAL_NO_MONTH_CHANGE bit
82 virtual bool EnableMonthChange(bool enable = true);
83
84 // corresponds to wxCAL_NO_YEAR_CHANGE bit, deprecated, generic only
85 void EnableYearChange(bool enable = true);
86
87
88 // customization
89 // -------------
90
91 virtual void Mark(size_t day, bool mark);
92
93 // all other functions in this section are for generic version only
94
95 // header colours are used for painting the weekdays at the top
96 virtual void SetHeaderColours(const wxColour& colFg, const wxColour& colBg)
97 {
98 m_colHeaderFg = colFg;
99 m_colHeaderBg = colBg;
100 }
101
102 virtual const wxColour& GetHeaderColourFg() const { return m_colHeaderFg; }
103 virtual const wxColour& GetHeaderColourBg() const { return m_colHeaderBg; }
104
105 // highlight colour is used for the currently selected date
106 virtual void SetHighlightColours(const wxColour& colFg, const wxColour& colBg)
107 {
108 m_colHighlightFg = colFg;
109 m_colHighlightBg = colBg;
110 }
111
112 virtual const wxColour& GetHighlightColourFg() const { return m_colHighlightFg; }
113 virtual const wxColour& GetHighlightColourBg() const { return m_colHighlightBg; }
114
115 // holiday colour is used for the holidays (if style & wxCAL_SHOW_HOLIDAYS)
116 virtual void SetHolidayColours(const wxColour& colFg, const wxColour& colBg)
117 {
118 m_colHolidayFg = colFg;
119 m_colHolidayBg = colBg;
120 }
121
122 virtual const wxColour& GetHolidayColourFg() const { return m_colHolidayFg; }
123 virtual const wxColour& GetHolidayColourBg() const { return m_colHolidayBg; }
124
125 virtual wxCalendarDateAttr *GetAttr(size_t day) const
126 {
127 wxCHECK_MSG( day > 0 && day < 32, NULL, _T("invalid day") );
128
129 return m_attrs[day - 1];
130 }
131
132 virtual void SetAttr(size_t day, wxCalendarDateAttr *attr)
133 {
134 wxCHECK_RET( day > 0 && day < 32, _T("invalid day") );
135
136 delete m_attrs[day - 1];
137 m_attrs[day - 1] = attr;
138 }
139
140 virtual void ResetAttr(size_t day) { SetAttr(day, NULL); }
141
142 virtual void SetHoliday(size_t day);
143
144 virtual wxCalendarHitTestResult HitTest(const wxPoint& pos,
145 wxDateTime *date = NULL,
146 wxDateTime::WeekDay *wd = NULL);
147
148 // implementation only from now on
149 // -------------------------------
150
151 // forward these functions to all subcontrols
152 virtual bool Enable(bool enable = true);
153 virtual bool Show(bool show = true);
154
155 virtual void SetWindowStyleFlag(long style);
156
157 virtual wxVisualAttributes GetDefaultAttributes() const
158 { return GetClassDefaultAttributes(GetWindowVariant()); }
159
160 static wxVisualAttributes
161 GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL);
162
163 void OnSysColourChanged(wxSysColourChangedEvent& event);
164
165 protected:
166 // override some base class virtuals
167 virtual wxSize DoGetBestSize() const;
168 virtual void DoMoveWindow(int x, int y, int width, int height);
169 virtual void DoGetSize(int *width, int *height) const;
170
171 private:
172 // common part of all ctors
173 void Init();
174
175 // startup colours and reinitialization after colour changes in system
176 void InitColours();
177
178 // event handlers
179 void OnPaint(wxPaintEvent& event);
180 void OnClick(wxMouseEvent& event);
181 void OnDClick(wxMouseEvent& event);
182 void OnChar(wxKeyEvent& event);
183 void OnMonthChange(wxCommandEvent& event);
184 void OnYearChange(wxCommandEvent& event);
185 void OnYearTextChange(wxCommandEvent& event);
186
187 // (re)calc m_widthCol and m_heightRow
188 void RecalcGeometry();
189
190 // set the date and send the notification
191 void SetDateAndNotify(const wxDateTime& date);
192
193 // get the week (row, in range 1..6) for the given date
194 size_t GetWeek(const wxDateTime& date) const;
195
196 // get the date from which we start drawing days
197 wxDateTime GetStartDate() const;
198
199 // is this date shown?
200 bool IsDateShown(const wxDateTime& date) const;
201
202 // is this date in the given range?
203 bool IsDateInRange(const wxDateTime& date) const;
204
205 // range helpers
206 bool ChangeYear(wxDateTime* target) const;
207 bool ChangeMonth(wxDateTime* target) const;
208
209 // redraw the given date
210 void RefreshDate(const wxDateTime& date);
211
212 // change the date inside the same month/year
213 void ChangeDay(const wxDateTime& date);
214
215 // deprecated
216 bool AllowYearChange() const
217 {
218 return !(GetWindowStyle() & wxCAL_NO_YEAR_CHANGE);
219 }
220
221 // show the correct controls
222 void ShowCurrentControls();
223
224 // create the month combo and year spin controls
225 void CreateMonthComboBox();
226 void CreateYearSpinCtrl();
227
228 public:
229 // get the currently shown control for month/year
230 wxControl *GetMonthControl() const;
231 wxControl *GetYearControl() const;
232
233 private:
234 virtual void ResetHolidayAttrs();
235 virtual void RefreshHolidays() { Refresh(); }
236
237 // OnPaint helper-methods
238
239 // Highlight the [fromdate : todate] range using pen and brush
240 void HighlightRange(wxPaintDC* dc, const wxDateTime& fromdate, const wxDateTime& todate, const wxPen* pen, const wxBrush* brush);
241
242 // Get the "coordinates" for the date relative to the month currently displayed.
243 // using (day, week): upper left coord is (1, 1), lower right coord is (7, 6)
244 // if the date isn't visible (-1, -1) is put in (day, week) and false is returned
245 bool GetDateCoord(const wxDateTime& date, int *day, int *week) const;
246
247 // Set the flag for SetDate(): otherwise it would overwrite the year
248 // typed in by the user
249 void SetUserChangedYear() { m_userChangedYear = true; }
250
251
252 // the subcontrols
253 wxStaticText *m_staticMonth;
254 wxComboBox *m_comboMonth;
255
256 wxStaticText *m_staticYear;
257 wxSpinCtrl *m_spinYear;
258
259 // the current selection
260 wxDateTime m_date;
261
262 // the date-range
263 wxDateTime m_lowdate;
264 wxDateTime m_highdate;
265
266 // default attributes
267 wxColour m_colHighlightFg,
268 m_colHighlightBg,
269 m_colHolidayFg,
270 m_colHolidayBg,
271 m_colHeaderFg,
272 m_colHeaderBg,
273 m_colBackground,
274 m_colSurrounding;
275
276 // the attributes for each of the month days
277 wxCalendarDateAttr *m_attrs[31];
278
279 // the width and height of one column/row in the calendar
280 wxCoord m_widthCol,
281 m_heightRow,
282 m_rowOffset;
283
284 wxRect m_leftArrowRect,
285 m_rightArrowRect;
286
287 // the week day names
288 wxString m_weekdays[7];
289
290 // true if SetDate() is being called as the result of changing the year in
291 // the year control
292 bool m_userChangedYear;
293
294 DECLARE_DYNAMIC_CLASS(wxGenericCalendarCtrl)
295 DECLARE_EVENT_TABLE()
296 DECLARE_NO_COPY_CLASS(wxGenericCalendarCtrl)
297 };
298
299 #endif // _WX_GENERIC_CALCTRLG_H