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