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