]> git.saurik.com Git - wxWidgets.git/blame - include/wx/generic/calctrlg.h
Make wxComboCtrlBase::Set*groundColour() methods public.
[wxWidgets.git] / include / wx / generic / calctrlg.h
CommitLineData
2ef31e80 1///////////////////////////////////////////////////////////////////////////////
80fdcdb9 2// Name: wx/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
2ef31e80 7// Copyright: (c) 1999 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
65571936 8// Licence: wxWindows licence
2ef31e80
VZ
9///////////////////////////////////////////////////////////////////////////////
10
628e155d
VZ
11#ifndef _WX_GENERIC_CALCTRLG_H
12#define _WX_GENERIC_CALCTRLG_H
2ef31e80
VZ
13
14#include "wx/control.h" // the base class
49a47c50 15#include "wx/dcclient.h" // for wxPaintDC
4f6aed9c 16
b5dbe15d
VS
17class WXDLLIMPEXP_FWD_CORE wxComboBox;
18class WXDLLIMPEXP_FWD_CORE wxStaticText;
19class WXDLLIMPEXP_FWD_CORE wxSpinCtrl;
3c778901 20class WXDLLIMPEXP_FWD_CORE wxSpinEvent;
2ef31e80 21
2ef31e80 22// ----------------------------------------------------------------------------
628e155d 23// wxGenericCalendarCtrl
2ef31e80
VZ
24// ----------------------------------------------------------------------------
25
628e155d 26class WXDLLIMPEXP_ADV wxGenericCalendarCtrl : public wxCalendarCtrlBase
2ef31e80
VZ
27{
28public:
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
628e155d 87
4f6aed9c
VZ
88 // customization
89 // -------------
90
628e155d
VZ
91 virtual void Mark(size_t day, bool mark);
92
93 // all other functions in this section are for generic version only
94
4f6aed9c 95 // header colours are used for painting the weekdays at the top
bf956fac 96 virtual void SetHeaderColours(const wxColour& colFg, const wxColour& colBg)
4f6aed9c
VZ
97 {
98 m_colHeaderFg = colFg;
99 m_colHeaderBg = colBg;
100 }
101
bf956fac
VZ
102 virtual const wxColour& GetHeaderColourFg() const { return m_colHeaderFg; }
103 virtual const wxColour& GetHeaderColourBg() const { return m_colHeaderBg; }
4f6aed9c
VZ
104
105 // highlight colour is used for the currently selected date
bf956fac 106 virtual void SetHighlightColours(const wxColour& colFg, const wxColour& colBg)
4f6aed9c
VZ
107 {
108 m_colHighlightFg = colFg;
109 m_colHighlightBg = colBg;
110 }
111
bf956fac
VZ
112 virtual const wxColour& GetHighlightColourFg() const { return m_colHighlightFg; }
113 virtual const wxColour& GetHighlightColourBg() const { return m_colHighlightBg; }
4f6aed9c
VZ
114
115 // holiday colour is used for the holidays (if style & wxCAL_SHOW_HOLIDAYS)
bf956fac 116 virtual void SetHolidayColours(const wxColour& colFg, const wxColour& colBg)
4f6aed9c
VZ
117 {
118 m_colHolidayFg = colFg;
119 m_colHolidayBg = colBg;
120 }
121
bf956fac
VZ
122 virtual const wxColour& GetHolidayColourFg() const { return m_colHolidayFg; }
123 virtual const wxColour& GetHolidayColourBg() const { return m_colHolidayBg; }
4f6aed9c 124
628e155d 125 virtual wxCalendarDateAttr *GetAttr(size_t day) const
4f6aed9c 126 {
9a83f860 127 wxCHECK_MSG( day > 0 && day < 32, NULL, wxT("invalid day") );
4f6aed9c
VZ
128
129 return m_attrs[day - 1];
130 }
131
628e155d 132 virtual void SetAttr(size_t day, wxCalendarDateAttr *attr)
4f6aed9c 133 {
9a83f860 134 wxCHECK_RET( day > 0 && day < 32, wxT("invalid day") );
4f6aed9c
VZ
135
136 delete m_attrs[day - 1];
137 m_attrs[day - 1] = attr;
138 }
139
628e155d 140 virtual void ResetAttr(size_t day) { SetAttr(day, NULL); }
4f6aed9c 141
bf956fac 142 virtual void SetHoliday(size_t day);
4f6aed9c 143
628e155d
VZ
144 virtual wxCalendarHitTestResult HitTest(const wxPoint& pos,
145 wxDateTime *date = NULL,
146 wxDateTime::WeekDay *wd = NULL);
2ef31e80 147
882a8f40
VZ
148 // implementation only from now on
149 // -------------------------------
150
151 // forward these functions to all subcontrols
ca65c044
WS
152 virtual bool Enable(bool enable = true);
153 virtual bool Show(bool show = true);
882a8f40 154
b5f842a9
VZ
155 virtual void SetWindowStyleFlag(long style);
156
ab473127
RD
157 virtual wxVisualAttributes GetDefaultAttributes() const
158 { return GetClassDefaultAttributes(GetWindowVariant()); }
159
160 static wxVisualAttributes
161 GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL);
162
d9170b47
WS
163 void OnSysColourChanged(wxSysColourChangedEvent& event);
164
6f02a879
VZ
165protected:
166 // override some base class virtuals
167 virtual wxSize DoGetBestSize() const;
6f02a879 168 virtual void DoMoveWindow(int x, int y, int width, int height);
d7b20621 169 virtual void DoGetSize(int *width, int *height) const;
6f02a879 170
0185cd09
VZ
171private:
172 // common part of all ctors
173 void Init();
174
d9170b47
WS
175 // startup colours and reinitialization after colour changes in system
176 void InitColours();
177
882a8f40
VZ
178 // event handlers
179 void OnPaint(wxPaintEvent& event);
180 void OnClick(wxMouseEvent& event);
0185cd09 181 void OnDClick(wxMouseEvent& event);
882a8f40
VZ
182 void OnChar(wxKeyEvent& event);
183 void OnMonthChange(wxCommandEvent& event);
3c778901
VZ
184
185 void HandleYearChange(wxCommandEvent& event);
186 void OnYearChange(wxSpinEvent& 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
0bb84570
VZ
201 // get the first/last days of the week corresponding to the current style
202 wxDateTime::WeekDay GetWeekStart() const
203 {
204 return HasFlag(wxCAL_MONDAY_FIRST) ? wxDateTime::Mon
205 : wxDateTime::Sun;
206 }
207
208 wxDateTime::WeekDay GetWeekEnd() const
209 {
210 return HasFlag(wxCAL_MONDAY_FIRST) ? wxDateTime::Sun
211 : wxDateTime::Sat;
212 }
213
214
2ef31e80
VZ
215 // is this date shown?
216 bool IsDateShown(const wxDateTime& date) const;
217
3c9863ac 218 // is this date in the currently allowed range?
37df1f33 219 bool IsDateInRange(const wxDateTime& date) const;
f0d5e7a2 220
3c9863ac
VZ
221 // adjust the date to the currently allowed range, return true if it was
222 // changed
223 bool AdjustDateToRange(wxDateTime *date) const;
37df1f33 224
9d9b7755
VZ
225 // redraw the given date
226 void RefreshDate(const wxDateTime& date);
227
228 // change the date inside the same month/year
229 void ChangeDay(const wxDateTime& date);
230
628e155d 231 // deprecated
bc385ba9
VZ
232 bool AllowYearChange() const
233 {
234 return !(GetWindowStyle() & wxCAL_NO_YEAR_CHANGE);
235 }
236
237 // show the correct controls
238 void ShowCurrentControls();
239
61581d48
MW
240 // create the month combo and year spin controls
241 void CreateMonthComboBox();
242 void CreateYearSpinCtrl();
243
b6fa290b 244public:
bc385ba9
VZ
245 // get the currently shown control for month/year
246 wxControl *GetMonthControl() const;
247 wxControl *GetYearControl() const;
248
b6fa290b 249private:
6d9b6716
VZ
250 virtual void ResetHolidayAttrs();
251 virtual void RefreshHolidays() { Refresh(); }
252
37df1f33 253 // OnPaint helper-methods
f0d5e7a2 254
37df1f33 255 // Highlight the [fromdate : todate] range using pen and brush
f516d986 256 void HighlightRange(wxPaintDC* dc, const wxDateTime& fromdate, const wxDateTime& todate, const wxPen* pen, const wxBrush* brush);
f0d5e7a2 257
37df1f33
VZ
258 // Get the "coordinates" for the date relative to the month currently displayed.
259 // using (day, week): upper left coord is (1, 1), lower right coord is (7, 6)
260 // if the date isn't visible (-1, -1) is put in (day, week) and false is returned
261 bool GetDateCoord(const wxDateTime& date, int *day, int *week) const;
262
605dfd91
JS
263 // Set the flag for SetDate(): otherwise it would overwrite the year
264 // typed in by the user
ca65c044 265 void SetUserChangedYear() { m_userChangedYear = true; }
605dfd91 266
c3a899dd 267
2ef31e80 268 // the subcontrols
bc385ba9 269 wxStaticText *m_staticMonth;
2ef31e80 270 wxComboBox *m_comboMonth;
bc385ba9
VZ
271
272 wxStaticText *m_staticYear;
2ef31e80
VZ
273 wxSpinCtrl *m_spinYear;
274
4f6aed9c 275 // the current selection
2ef31e80
VZ
276 wxDateTime m_date;
277
37df1f33
VZ
278 // the date-range
279 wxDateTime m_lowdate;
280 wxDateTime m_highdate;
281
4f6aed9c
VZ
282 // default attributes
283 wxColour m_colHighlightFg,
284 m_colHighlightBg,
285 m_colHolidayFg,
286 m_colHolidayBg,
287 m_colHeaderFg,
d9170b47
WS
288 m_colHeaderBg,
289 m_colBackground,
ddf13afc 290 m_colSurrounding;
4f6aed9c
VZ
291
292 // the attributes for each of the month days
293 wxCalendarDateAttr *m_attrs[31];
294
2ef31e80
VZ
295 // the width and height of one column/row in the calendar
296 wxCoord m_widthCol,
37df1f33 297 m_heightRow,
232b2162
VZ
298 m_rowOffset,
299 m_calendarWeekWidth;
37df1f33
VZ
300
301 wxRect m_leftArrowRect,
f0d5e7a2 302 m_rightArrowRect;
2ef31e80 303
9d9b7755
VZ
304 // the week day names
305 wxString m_weekdays[7];
306
ca65c044 307 // true if SetDate() is being called as the result of changing the year in
f0d5e7a2
VZ
308 // the year control
309 bool m_userChangedYear;
310
628e155d 311 DECLARE_DYNAMIC_CLASS(wxGenericCalendarCtrl)
2ef31e80 312 DECLARE_EVENT_TABLE()
c0c133e1 313 wxDECLARE_NO_COPY_CLASS(wxGenericCalendarCtrl);
2ef31e80
VZ
314};
315
628e155d 316#endif // _WX_GENERIC_CALCTRLG_H