]> git.saurik.com Git - wxWidgets.git/blame - include/wx/generic/calctrl.h
added wxDynamicLibrary::GetSymbolAorW()
[wxWidgets.git] / include / wx / generic / calctrl.h
CommitLineData
2ef31e80
VZ
1///////////////////////////////////////////////////////////////////////////////
2// Name: generic/calctrl.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>
65571936 9// Licence: wxWindows licence
2ef31e80
VZ
10///////////////////////////////////////////////////////////////////////////////
11
12028905 12#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
2ef31e80
VZ
13 #pragma interface "calctrl.h"
14#endif
15
16#ifndef _WX_GENERIC_CALCTRL_H
17#define _WX_GENERIC_CALCTRL_H
18
19#include "wx/control.h" // the base class
49a47c50 20#include "wx/dcclient.h" // for wxPaintDC
4f6aed9c
VZ
21
22class WXDLLEXPORT wxComboBox;
bc385ba9 23class WXDLLEXPORT wxStaticText;
f0d5e7a2 24class WXDLLEXPORT wxSpinCtrl;
2ef31e80
VZ
25
26#define wxCalendarNameStr _T("CalendarCtrl")
27
28// ----------------------------------------------------------------------------
29// wxCalendarCtrl: a control allowing the user to pick a date interactively
30// ----------------------------------------------------------------------------
31
12f190b0 32class WXDLLIMPEXP_ADV wxCalendarCtrl : public wxControl
2ef31e80
VZ
33{
34public:
35 // construction
36 wxCalendarCtrl() { Init(); }
37 wxCalendarCtrl(wxWindow *parent,
38 wxWindowID id,
39 const wxDateTime& date = wxDefaultDateTime,
40 const wxPoint& pos = wxDefaultPosition,
41 const wxSize& size = wxDefaultSize,
4965c3d7 42 long style = wxCAL_SHOW_HOLIDAYS | wxWANTS_CHARS,
2b5f62a0 43 const wxString& name = wxCalendarNameStr);
2ef31e80
VZ
44
45 bool Create(wxWindow *parent,
46 wxWindowID id,
47 const wxDateTime& date = wxDefaultDateTime,
48 const wxPoint& pos = wxDefaultPosition,
49 const wxSize& size = wxDefaultSize,
4965c3d7 50 long style = wxCAL_SHOW_HOLIDAYS | wxWANTS_CHARS,
2ef31e80
VZ
51 const wxString& name = wxCalendarNameStr);
52
882a8f40
VZ
53 virtual ~wxCalendarCtrl();
54
b70462f4
MB
55 virtual bool Destroy();
56
2ef31e80 57 // set/get the current date
4f6aed9c
VZ
58 // ------------------------
59
37df1f33 60 bool SetDate(const wxDateTime& date); // we need to be able to control if the event should be sent in SetDateAndNotify(...)
2ef31e80
VZ
61 const wxDateTime& GetDate() const { return m_date; }
62
37df1f33
VZ
63 // set/get the range in which selection can occur
64 // ---------------------------------------------
65
66 bool SetLowerDateLimit(const wxDateTime& date = wxDefaultDateTime);
67 const wxDateTime& GetLowerDateLimit() const { return m_lowdate; }
68 bool SetUpperDateLimit(const wxDateTime& date = wxDefaultDateTime);
69 const wxDateTime& GetUpperDateLimit() const { return m_highdate; }
70
71 bool SetDateRange(const wxDateTime& lowerdate = wxDefaultDateTime, const wxDateTime& upperdate = wxDefaultDateTime);
f0d5e7a2 72
bc385ba9
VZ
73 // calendar mode
74 // -------------
75
76 // some calendar styles can't be changed after the control creation by
77 // just using SetWindowStyle() and Refresh() and the functions below
78 // should be used instead for them
79
80 // corresponds to wxCAL_NO_YEAR_CHANGE bit
ca65c044 81 void EnableYearChange(bool enable = true);
bc385ba9
VZ
82
83 // corresponds to wxCAL_NO_MONTH_CHANGE bit
ca65c044 84 void EnableMonthChange(bool enable = true);
bc385ba9
VZ
85
86 // corresponds to wxCAL_SHOW_HOLIDAYS bit
ca65c044 87 void EnableHolidayDisplay(bool display = true);
bc385ba9 88
4f6aed9c
VZ
89 // customization
90 // -------------
91
92 // header colours are used for painting the weekdays at the top
93 void SetHeaderColours(const wxColour& colFg, const wxColour& colBg)
94 {
95 m_colHeaderFg = colFg;
96 m_colHeaderBg = colBg;
97 }
98
99 const wxColour& GetHeaderColourFg() const { return m_colHeaderFg; }
100 const wxColour& GetHeaderColourBg() const { return m_colHeaderBg; }
101
102 // highlight colour is used for the currently selected date
103 void SetHighlightColours(const wxColour& colFg, const wxColour& colBg)
104 {
105 m_colHighlightFg = colFg;
106 m_colHighlightBg = colBg;
107 }
108
109 const wxColour& GetHighlightColourFg() const { return m_colHighlightFg; }
110 const wxColour& GetHighlightColourBg() const { return m_colHighlightBg; }
111
112 // holiday colour is used for the holidays (if style & wxCAL_SHOW_HOLIDAYS)
113 void SetHolidayColours(const wxColour& colFg, const wxColour& colBg)
114 {
115 m_colHolidayFg = colFg;
116 m_colHolidayBg = colBg;
117 }
118
119 const wxColour& GetHolidayColourFg() const { return m_colHolidayFg; }
120 const wxColour& GetHolidayColourBg() const { return m_colHolidayBg; }
121
4f6aed9c
VZ
122 // an item without custom attributes is drawn with the default colours and
123 // font and without border, setting custom attributes allows to modify this
124 //
125 // the day parameter should be in 1..31 range, for days 29, 30, 31 the
126 // corresponding attribute is just unused if there is no such day in the
127 // current month
128
129 wxCalendarDateAttr *GetAttr(size_t day) const
130 {
131 wxCHECK_MSG( day > 0 && day < 32, NULL, _T("invalid day") );
132
133 return m_attrs[day - 1];
134 }
135
136 void SetAttr(size_t day, wxCalendarDateAttr *attr)
137 {
138 wxCHECK_RET( day > 0 && day < 32, _T("invalid day") );
139
140 delete m_attrs[day - 1];
141 m_attrs[day - 1] = attr;
142 }
143
144 void SetHoliday(size_t day);
145
146 void ResetAttr(size_t day) { SetAttr(day, (wxCalendarDateAttr *)NULL); }
147
0185cd09
VZ
148 // returns one of wxCAL_HITTEST_XXX constants and fills either date or wd
149 // with the corresponding value (none for NOWHERE, the date for DAY and wd
150 // for HEADER)
151 wxCalendarHitTestResult HitTest(const wxPoint& pos,
152 wxDateTime *date = NULL,
153 wxDateTime::WeekDay *wd = NULL);
2ef31e80 154
882a8f40
VZ
155 // implementation only from now on
156 // -------------------------------
157
158 // forward these functions to all subcontrols
ca65c044
WS
159 virtual bool Enable(bool enable = true);
160 virtual bool Show(bool show = true);
882a8f40 161
ab473127
RD
162 virtual wxVisualAttributes GetDefaultAttributes() const
163 { return GetClassDefaultAttributes(GetWindowVariant()); }
164
165 static wxVisualAttributes
166 GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL);
167
0185cd09
VZ
168private:
169 // common part of all ctors
170 void Init();
171
882a8f40
VZ
172 // event handlers
173 void OnPaint(wxPaintEvent& event);
174 void OnClick(wxMouseEvent& event);
0185cd09 175 void OnDClick(wxMouseEvent& event);
882a8f40
VZ
176 void OnChar(wxKeyEvent& event);
177 void OnMonthChange(wxCommandEvent& event);
f0d5e7a2 178 void OnYearChange(wxCommandEvent& event);
61581d48 179 void OnYearTextChange(wxCommandEvent& event);
882a8f40 180
2ef31e80
VZ
181 // override some base class virtuals
182 virtual wxSize DoGetBestSize() const;
882a8f40
VZ
183 virtual void DoGetPosition(int *x, int *y) const;
184 virtual void DoGetSize(int *width, int *height) const;
2ef31e80
VZ
185 virtual void DoSetSize(int x, int y, int width, int height, int sizeFlags);
186 virtual void DoMoveWindow(int x, int y, int width, int height);
187
9d9b7755
VZ
188 // (re)calc m_widthCol and m_heightRow
189 void RecalcGeometry();
190
9d9b7755
VZ
191 // set the date and send the notification
192 void SetDateAndNotify(const wxDateTime& date);
193
194 // get the week (row, in range 1..6) for the given date
195 size_t GetWeek(const wxDateTime& date) const;
196
2ef31e80
VZ
197 // get the date from which we start drawing days
198 wxDateTime GetStartDate() const;
199
200 // is this date shown?
201 bool IsDateShown(const wxDateTime& date) const;
202
37df1f33
VZ
203 // is this date in the given range?
204 bool IsDateInRange(const wxDateTime& date) const;
f0d5e7a2 205
37df1f33
VZ
206 // range helpers
207 bool ChangeYear(wxDateTime* target) const;
208 bool ChangeMonth(wxDateTime* target) const;
209
9d9b7755
VZ
210 // redraw the given date
211 void RefreshDate(const wxDateTime& date);
212
213 // change the date inside the same month/year
214 void ChangeDay(const wxDateTime& date);
215
4f6aed9c
VZ
216 // set the attributes for the holidays if needed
217 void SetHolidayAttrs();
218
219 // reset all holidays
220 void ResetHolidayAttrs();
221
222 // generate the given calendar event(s)
223 void GenerateEvent(wxEventType type)
224 {
225 wxCalendarEvent event(this, type);
226 (void)GetEventHandler()->ProcessEvent(event);
227 }
228
229 void GenerateEvents(wxEventType type1, wxEventType type2)
230 {
231 GenerateEvent(type1);
232 GenerateEvent(type2);
233 }
9d9b7755 234
bc385ba9
VZ
235 // do we allow changing the month/year?
236 bool AllowMonthChange() const
237 {
238 return (GetWindowStyle() & wxCAL_NO_MONTH_CHANGE)
239 != wxCAL_NO_MONTH_CHANGE;
240 }
241 bool AllowYearChange() const
242 {
243 return !(GetWindowStyle() & wxCAL_NO_YEAR_CHANGE);
244 }
245
246 // show the correct controls
247 void ShowCurrentControls();
248
61581d48
MW
249 // create the month combo and year spin controls
250 void CreateMonthComboBox();
251 void CreateYearSpinCtrl();
252
b6fa290b 253public:
bc385ba9
VZ
254 // get the currently shown control for month/year
255 wxControl *GetMonthControl() const;
256 wxControl *GetYearControl() const;
257
b6fa290b 258private:
37df1f33 259 // OnPaint helper-methods
f0d5e7a2 260
37df1f33
VZ
261 // Highlight the [fromdate : todate] range using pen and brush
262 void HighlightRange(wxPaintDC* dc, const wxDateTime& fromdate, const wxDateTime& todate, wxPen* pen, wxBrush* brush);
f0d5e7a2 263
37df1f33
VZ
264 // Get the "coordinates" for the date relative to the month currently displayed.
265 // using (day, week): upper left coord is (1, 1), lower right coord is (7, 6)
266 // if the date isn't visible (-1, -1) is put in (day, week) and false is returned
267 bool GetDateCoord(const wxDateTime& date, int *day, int *week) const;
268
605dfd91
JS
269 // Set the flag for SetDate(): otherwise it would overwrite the year
270 // typed in by the user
ca65c044 271 void SetUserChangedYear() { m_userChangedYear = true; }
605dfd91 272
2ef31e80 273 // the subcontrols
bc385ba9 274 wxStaticText *m_staticMonth;
2ef31e80 275 wxComboBox *m_comboMonth;
bc385ba9
VZ
276
277 wxStaticText *m_staticYear;
2ef31e80
VZ
278 wxSpinCtrl *m_spinYear;
279
4f6aed9c 280 // the current selection
2ef31e80
VZ
281 wxDateTime m_date;
282
37df1f33
VZ
283 // the date-range
284 wxDateTime m_lowdate;
285 wxDateTime m_highdate;
286
4f6aed9c
VZ
287 // default attributes
288 wxColour m_colHighlightFg,
289 m_colHighlightBg,
290 m_colHolidayFg,
291 m_colHolidayBg,
292 m_colHeaderFg,
293 m_colHeaderBg;
294
295 // the attributes for each of the month days
296 wxCalendarDateAttr *m_attrs[31];
297
2ef31e80
VZ
298 // the width and height of one column/row in the calendar
299 wxCoord m_widthCol,
37df1f33
VZ
300 m_heightRow,
301 m_rowOffset;
302
303 wxRect m_leftArrowRect,
f0d5e7a2 304 m_rightArrowRect;
2ef31e80 305
9d9b7755
VZ
306 // the week day names
307 wxString m_weekdays[7];
308
ca65c044 309 // true if SetDate() is being called as the result of changing the year in
f0d5e7a2
VZ
310 // the year control
311 bool m_userChangedYear;
312
2ef31e80
VZ
313 DECLARE_DYNAMIC_CLASS(wxCalendarCtrl)
314 DECLARE_EVENT_TABLE()
22f3361e 315 DECLARE_NO_COPY_CLASS(wxCalendarCtrl)
2ef31e80
VZ
316};
317
318#endif // _WX_GENERIC_CALCTRL_H