]> git.saurik.com Git - wxWidgets.git/blob - include/wx/generic/calctrlg.h
Generalized wxScrolledWindow into wxScrolled<T> that can derive from
[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 // all functions in this section are for generic version only
62 bool SetLowerDateLimit(const wxDateTime& date = wxDefaultDateTime);
63 const wxDateTime& GetLowerDateLimit() const { return m_lowdate; }
64 bool SetUpperDateLimit(const wxDateTime& date = wxDefaultDateTime);
65 const wxDateTime& GetUpperDateLimit() const { return m_highdate; }
66
67 bool SetDateRange(const wxDateTime& lowerdate = wxDefaultDateTime,
68 const wxDateTime& upperdate = wxDefaultDateTime);
69
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_MONTH_CHANGE bit
79 virtual bool EnableMonthChange(bool enable = true);
80
81 // corresponds to wxCAL_NO_YEAR_CHANGE bit, deprecated, generic only
82 void EnableYearChange(bool enable = true);
83
84 // corresponds to wxCAL_SHOW_HOLIDAYS bit, generic only
85 void EnableHolidayDisplay(bool display = 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 void SetHeaderColours(const wxColour& colFg, const wxColour& colBg)
97 {
98 m_colHeaderFg = colFg;
99 m_colHeaderBg = colBg;
100 }
101
102 const wxColour& GetHeaderColourFg() const { return m_colHeaderFg; }
103 const wxColour& GetHeaderColourBg() const { return m_colHeaderBg; }
104
105 // highlight colour is used for the currently selected date
106 void SetHighlightColours(const wxColour& colFg, const wxColour& colBg)
107 {
108 m_colHighlightFg = colFg;
109 m_colHighlightBg = colBg;
110 }
111
112 const wxColour& GetHighlightColourFg() const { return m_colHighlightFg; }
113 const wxColour& GetHighlightColourBg() const { return m_colHighlightBg; }
114
115 // holiday colour is used for the holidays (if style & wxCAL_SHOW_HOLIDAYS)
116 void SetHolidayColours(const wxColour& colFg, const wxColour& colBg)
117 {
118 m_colHolidayFg = colFg;
119 m_colHolidayBg = colBg;
120 }
121
122 const wxColour& GetHolidayColourFg() const { return m_colHolidayFg; }
123 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 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 DoGetPosition(int *x, int *y) const;
169 virtual void DoGetSize(int *width, int *height) const;
170 virtual void DoSetSize(int x, int y, int width, int height, int sizeFlags);
171 virtual void DoMoveWindow(int x, int y, int width, int height);
172
173 private:
174 // common part of all ctors
175 void Init();
176
177 // startup colours and reinitialization after colour changes in system
178 void InitColours();
179
180 // event handlers
181 void OnPaint(wxPaintEvent& event);
182 void OnClick(wxMouseEvent& event);
183 void OnDClick(wxMouseEvent& event);
184 void OnChar(wxKeyEvent& event);
185 void OnMonthChange(wxCommandEvent& event);
186 void OnYearChange(wxCommandEvent& event);
187 void OnYearTextChange(wxCommandEvent& event);
188
189 // (re)calc m_widthCol and m_heightRow
190 void RecalcGeometry();
191
192 // set the date and send the notification
193 void SetDateAndNotify(const wxDateTime& date);
194
195 // get the week (row, in range 1..6) for the given date
196 size_t GetWeek(const wxDateTime& date) const;
197
198 // get the date from which we start drawing days
199 wxDateTime GetStartDate() const;
200
201 // is this date shown?
202 bool IsDateShown(const wxDateTime& date) const;
203
204 // is this date in the given range?
205 bool IsDateInRange(const wxDateTime& date) const;
206
207 // range helpers
208 bool ChangeYear(wxDateTime* target) const;
209 bool ChangeMonth(wxDateTime* target) const;
210
211 // redraw the given date
212 void RefreshDate(const wxDateTime& date);
213
214 // change the date inside the same month/year
215 void ChangeDay(const wxDateTime& date);
216
217 // set the attributes for the holidays if needed
218 void SetHolidayAttrs();
219
220 // reset all holidays
221 void ResetHolidayAttrs();
222
223 // deprecated
224 bool AllowYearChange() const
225 {
226 return !(GetWindowStyle() & wxCAL_NO_YEAR_CHANGE);
227 }
228
229 // show the correct controls
230 void ShowCurrentControls();
231
232 // create the month combo and year spin controls
233 void CreateMonthComboBox();
234 void CreateYearSpinCtrl();
235
236 public:
237 // get the currently shown control for month/year
238 wxControl *GetMonthControl() const;
239 wxControl *GetYearControl() const;
240
241 private:
242 // OnPaint helper-methods
243
244 // Highlight the [fromdate : todate] range using pen and brush
245 void HighlightRange(wxPaintDC* dc, const wxDateTime& fromdate, const wxDateTime& todate, const wxPen* pen, const wxBrush* brush);
246
247 // Get the "coordinates" for the date relative to the month currently displayed.
248 // using (day, week): upper left coord is (1, 1), lower right coord is (7, 6)
249 // if the date isn't visible (-1, -1) is put in (day, week) and false is returned
250 bool GetDateCoord(const wxDateTime& date, int *day, int *week) const;
251
252 // Set the flag for SetDate(): otherwise it would overwrite the year
253 // typed in by the user
254 void SetUserChangedYear() { m_userChangedYear = true; }
255
256 // the subcontrols
257 wxStaticText *m_staticMonth;
258 wxComboBox *m_comboMonth;
259
260 wxStaticText *m_staticYear;
261 wxSpinCtrl *m_spinYear;
262
263 // the current selection
264 wxDateTime m_date;
265
266 // the date-range
267 wxDateTime m_lowdate;
268 wxDateTime m_highdate;
269
270 // default attributes
271 wxColour m_colHighlightFg,
272 m_colHighlightBg,
273 m_colHolidayFg,
274 m_colHolidayBg,
275 m_colHeaderFg,
276 m_colHeaderBg,
277 m_colBackground,
278 m_colSorrounding;
279
280 // the attributes for each of the month days
281 wxCalendarDateAttr *m_attrs[31];
282
283 // the width and height of one column/row in the calendar
284 wxCoord m_widthCol,
285 m_heightRow,
286 m_rowOffset;
287
288 wxRect m_leftArrowRect,
289 m_rightArrowRect;
290
291 // the week day names
292 wxString m_weekdays[7];
293
294 // true if SetDate() is being called as the result of changing the year in
295 // the year control
296 bool m_userChangedYear;
297
298 DECLARE_DYNAMIC_CLASS(wxGenericCalendarCtrl)
299 DECLARE_EVENT_TABLE()
300 DECLARE_NO_COPY_CLASS(wxGenericCalendarCtrl)
301 };
302
303 #endif // _WX_GENERIC_CALCTRLG_H