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