]>
Commit | Line | Data |
---|---|---|
2ef31e80 | 1 | /////////////////////////////////////////////////////////////////////////////// |
628e155d | 2 | // Name: generic/calctrlg.h |
2ef31e80 VZ |
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> | |
65571936 | 9 | // Licence: wxWindows licence |
2ef31e80 VZ |
10 | /////////////////////////////////////////////////////////////////////////////// |
11 | ||
628e155d VZ |
12 | #ifndef _WX_GENERIC_CALCTRLG_H |
13 | #define _WX_GENERIC_CALCTRLG_H | |
2ef31e80 VZ |
14 | |
15 | #include "wx/control.h" // the base class | |
49a47c50 | 16 | #include "wx/dcclient.h" // for wxPaintDC |
4f6aed9c | 17 | |
b5dbe15d VS |
18 | class WXDLLIMPEXP_FWD_CORE wxComboBox; |
19 | class WXDLLIMPEXP_FWD_CORE wxStaticText; | |
20 | class WXDLLIMPEXP_FWD_CORE wxSpinCtrl; | |
2ef31e80 | 21 | |
2ef31e80 | 22 | // ---------------------------------------------------------------------------- |
628e155d | 23 | // wxGenericCalendarCtrl |
2ef31e80 VZ |
24 | // ---------------------------------------------------------------------------- |
25 | ||
628e155d | 26 | class WXDLLIMPEXP_ADV wxGenericCalendarCtrl : public wxCalendarCtrlBase |
2ef31e80 VZ |
27 | { |
28 | public: | |
29 | // construction | |
628e155d VZ |
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); | |
2ef31e80 VZ |
38 | |
39 | bool Create(wxWindow *parent, | |
40 | wxWindowID id, | |
41 | const wxDateTime& date = wxDefaultDateTime, | |
42 | const wxPoint& pos = wxDefaultPosition, | |
43 | const wxSize& size = wxDefaultSize, | |
628e155d | 44 | long style = wxCAL_SHOW_HOLIDAYS, |
2ef31e80 VZ |
45 | const wxString& name = wxCalendarNameStr); |
46 | ||
628e155d | 47 | virtual ~wxGenericCalendarCtrl(); |
882a8f40 | 48 | |
b70462f4 MB |
49 | virtual bool Destroy(); |
50 | ||
2ef31e80 | 51 | // set/get the current date |
4f6aed9c VZ |
52 | // ------------------------ |
53 | ||
628e155d VZ |
54 | virtual bool SetDate(const wxDateTime& date); |
55 | virtual wxDateTime GetDate() const { return m_date; } | |
56 | ||
2ef31e80 | 57 | |
37df1f33 VZ |
58 | // set/get the range in which selection can occur |
59 | // --------------------------------------------- | |
60 | ||
51317496 VZ |
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 | |
37df1f33 VZ |
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 | ||
f0d5e7a2 | 73 | |
bc385ba9 VZ |
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 | ||
bc385ba9 | 81 | // corresponds to wxCAL_NO_MONTH_CHANGE bit |
628e155d | 82 | virtual bool EnableMonthChange(bool enable = true); |
bc385ba9 | 83 | |
628e155d VZ |
84 | // corresponds to wxCAL_NO_YEAR_CHANGE bit, deprecated, generic only |
85 | void EnableYearChange(bool enable = true); | |
86 | ||
87 | // corresponds to wxCAL_SHOW_HOLIDAYS bit, generic only | |
bf956fac | 88 | virtual void EnableHolidayDisplay(bool display = true); |
bc385ba9 | 89 | |
628e155d | 90 | |
4f6aed9c VZ |
91 | // customization |
92 | // ------------- | |
93 | ||
628e155d VZ |
94 | virtual void Mark(size_t day, bool mark); |
95 | ||
96 | // all other functions in this section are for generic version only | |
97 | ||
4f6aed9c | 98 | // header colours are used for painting the weekdays at the top |
bf956fac | 99 | virtual void SetHeaderColours(const wxColour& colFg, const wxColour& colBg) |
4f6aed9c VZ |
100 | { |
101 | m_colHeaderFg = colFg; | |
102 | m_colHeaderBg = colBg; | |
103 | } | |
104 | ||
bf956fac VZ |
105 | virtual const wxColour& GetHeaderColourFg() const { return m_colHeaderFg; } |
106 | virtual const wxColour& GetHeaderColourBg() const { return m_colHeaderBg; } | |
4f6aed9c VZ |
107 | |
108 | // highlight colour is used for the currently selected date | |
bf956fac | 109 | virtual void SetHighlightColours(const wxColour& colFg, const wxColour& colBg) |
4f6aed9c VZ |
110 | { |
111 | m_colHighlightFg = colFg; | |
112 | m_colHighlightBg = colBg; | |
113 | } | |
114 | ||
bf956fac VZ |
115 | virtual const wxColour& GetHighlightColourFg() const { return m_colHighlightFg; } |
116 | virtual const wxColour& GetHighlightColourBg() const { return m_colHighlightBg; } | |
4f6aed9c VZ |
117 | |
118 | // holiday colour is used for the holidays (if style & wxCAL_SHOW_HOLIDAYS) | |
bf956fac | 119 | virtual void SetHolidayColours(const wxColour& colFg, const wxColour& colBg) |
4f6aed9c VZ |
120 | { |
121 | m_colHolidayFg = colFg; | |
122 | m_colHolidayBg = colBg; | |
123 | } | |
124 | ||
bf956fac VZ |
125 | virtual const wxColour& GetHolidayColourFg() const { return m_colHolidayFg; } |
126 | virtual const wxColour& GetHolidayColourBg() const { return m_colHolidayBg; } | |
4f6aed9c | 127 | |
628e155d | 128 | virtual wxCalendarDateAttr *GetAttr(size_t day) const |
4f6aed9c VZ |
129 | { |
130 | wxCHECK_MSG( day > 0 && day < 32, NULL, _T("invalid day") ); | |
131 | ||
132 | return m_attrs[day - 1]; | |
133 | } | |
134 | ||
628e155d | 135 | virtual void SetAttr(size_t day, wxCalendarDateAttr *attr) |
4f6aed9c VZ |
136 | { |
137 | wxCHECK_RET( day > 0 && day < 32, _T("invalid day") ); | |
138 | ||
139 | delete m_attrs[day - 1]; | |
140 | m_attrs[day - 1] = attr; | |
141 | } | |
142 | ||
628e155d | 143 | virtual void ResetAttr(size_t day) { SetAttr(day, NULL); } |
4f6aed9c | 144 | |
bf956fac | 145 | virtual void SetHoliday(size_t day); |
4f6aed9c | 146 | |
628e155d VZ |
147 | virtual wxCalendarHitTestResult HitTest(const wxPoint& pos, |
148 | wxDateTime *date = NULL, | |
149 | wxDateTime::WeekDay *wd = NULL); | |
2ef31e80 | 150 | |
882a8f40 VZ |
151 | // implementation only from now on |
152 | // ------------------------------- | |
153 | ||
154 | // forward these functions to all subcontrols | |
ca65c044 WS |
155 | virtual bool Enable(bool enable = true); |
156 | virtual bool Show(bool show = true); | |
882a8f40 | 157 | |
b5f842a9 VZ |
158 | virtual void SetWindowStyleFlag(long style); |
159 | ||
ab473127 RD |
160 | virtual wxVisualAttributes GetDefaultAttributes() const |
161 | { return GetClassDefaultAttributes(GetWindowVariant()); } | |
162 | ||
163 | static wxVisualAttributes | |
164 | GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL); | |
165 | ||
d9170b47 WS |
166 | void OnSysColourChanged(wxSysColourChangedEvent& event); |
167 | ||
6f02a879 VZ |
168 | protected: |
169 | // override some base class virtuals | |
170 | virtual wxSize DoGetBestSize() const; | |
6f02a879 VZ |
171 | virtual void DoMoveWindow(int x, int y, int width, int height); |
172 | ||
0185cd09 VZ |
173 | private: |
174 | // common part of all ctors | |
175 | void Init(); | |
176 | ||
d9170b47 WS |
177 | // startup colours and reinitialization after colour changes in system |
178 | void InitColours(); | |
179 | ||
882a8f40 VZ |
180 | // event handlers |
181 | void OnPaint(wxPaintEvent& event); | |
182 | void OnClick(wxMouseEvent& event); | |
0185cd09 | 183 | void OnDClick(wxMouseEvent& event); |
882a8f40 VZ |
184 | void OnChar(wxKeyEvent& event); |
185 | void OnMonthChange(wxCommandEvent& event); | |
f0d5e7a2 | 186 | void OnYearChange(wxCommandEvent& event); |
61581d48 | 187 | void OnYearTextChange(wxCommandEvent& event); |
882a8f40 | 188 | |
9d9b7755 VZ |
189 | // (re)calc m_widthCol and m_heightRow |
190 | void RecalcGeometry(); | |
191 | ||
9d9b7755 VZ |
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 | ||
2ef31e80 VZ |
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 | ||
37df1f33 VZ |
204 | // is this date in the given range? |
205 | bool IsDateInRange(const wxDateTime& date) const; | |
f0d5e7a2 | 206 | |
37df1f33 VZ |
207 | // range helpers |
208 | bool ChangeYear(wxDateTime* target) const; | |
209 | bool ChangeMonth(wxDateTime* target) const; | |
210 | ||
9d9b7755 VZ |
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 | ||
4f6aed9c VZ |
217 | // set the attributes for the holidays if needed |
218 | void SetHolidayAttrs(); | |
219 | ||
220 | // reset all holidays | |
221 | void ResetHolidayAttrs(); | |
222 | ||
628e155d | 223 | // deprecated |
bc385ba9 VZ |
224 | bool AllowYearChange() const |
225 | { | |
226 | return !(GetWindowStyle() & wxCAL_NO_YEAR_CHANGE); | |
227 | } | |
228 | ||
229 | // show the correct controls | |
230 | void ShowCurrentControls(); | |
231 | ||
61581d48 MW |
232 | // create the month combo and year spin controls |
233 | void CreateMonthComboBox(); | |
234 | void CreateYearSpinCtrl(); | |
235 | ||
b6fa290b | 236 | public: |
bc385ba9 VZ |
237 | // get the currently shown control for month/year |
238 | wxControl *GetMonthControl() const; | |
239 | wxControl *GetYearControl() const; | |
240 | ||
b6fa290b | 241 | private: |
37df1f33 | 242 | // OnPaint helper-methods |
f0d5e7a2 | 243 | |
37df1f33 | 244 | // Highlight the [fromdate : todate] range using pen and brush |
f516d986 | 245 | void HighlightRange(wxPaintDC* dc, const wxDateTime& fromdate, const wxDateTime& todate, const wxPen* pen, const wxBrush* brush); |
f0d5e7a2 | 246 | |
37df1f33 VZ |
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 | ||
605dfd91 JS |
252 | // Set the flag for SetDate(): otherwise it would overwrite the year |
253 | // typed in by the user | |
ca65c044 | 254 | void SetUserChangedYear() { m_userChangedYear = true; } |
605dfd91 | 255 | |
c3a899dd | 256 | |
2ef31e80 | 257 | // the subcontrols |
bc385ba9 | 258 | wxStaticText *m_staticMonth; |
2ef31e80 | 259 | wxComboBox *m_comboMonth; |
bc385ba9 VZ |
260 | |
261 | wxStaticText *m_staticYear; | |
2ef31e80 VZ |
262 | wxSpinCtrl *m_spinYear; |
263 | ||
4f6aed9c | 264 | // the current selection |
2ef31e80 VZ |
265 | wxDateTime m_date; |
266 | ||
37df1f33 VZ |
267 | // the date-range |
268 | wxDateTime m_lowdate; | |
269 | wxDateTime m_highdate; | |
270 | ||
4f6aed9c VZ |
271 | // default attributes |
272 | wxColour m_colHighlightFg, | |
273 | m_colHighlightBg, | |
274 | m_colHolidayFg, | |
275 | m_colHolidayBg, | |
276 | m_colHeaderFg, | |
d9170b47 WS |
277 | m_colHeaderBg, |
278 | m_colBackground, | |
ddf13afc | 279 | m_colSurrounding; |
4f6aed9c VZ |
280 | |
281 | // the attributes for each of the month days | |
282 | wxCalendarDateAttr *m_attrs[31]; | |
283 | ||
2ef31e80 VZ |
284 | // the width and height of one column/row in the calendar |
285 | wxCoord m_widthCol, | |
37df1f33 VZ |
286 | m_heightRow, |
287 | m_rowOffset; | |
288 | ||
289 | wxRect m_leftArrowRect, | |
f0d5e7a2 | 290 | m_rightArrowRect; |
2ef31e80 | 291 | |
9d9b7755 VZ |
292 | // the week day names |
293 | wxString m_weekdays[7]; | |
294 | ||
ca65c044 | 295 | // true if SetDate() is being called as the result of changing the year in |
f0d5e7a2 VZ |
296 | // the year control |
297 | bool m_userChangedYear; | |
298 | ||
628e155d | 299 | DECLARE_DYNAMIC_CLASS(wxGenericCalendarCtrl) |
2ef31e80 | 300 | DECLARE_EVENT_TABLE() |
628e155d | 301 | DECLARE_NO_COPY_CLASS(wxGenericCalendarCtrl) |
2ef31e80 VZ |
302 | }; |
303 | ||
628e155d | 304 | #endif // _WX_GENERIC_CALCTRLG_H |