1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: generic/calctrlg.h
3 // Purpose: generic implementation of date-picker control
4 // Author: Vadim Zeitlin
8 // Copyright: (c) 1999 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_GENERIC_CALCTRLG_H
13 #define _WX_GENERIC_CALCTRLG_H
15 #include "wx/control.h" // the base class
16 #include "wx/dcclient.h" // for wxPaintDC
18 class WXDLLIMPEXP_FWD_CORE wxComboBox
;
19 class WXDLLIMPEXP_FWD_CORE wxStaticText
;
20 class WXDLLIMPEXP_FWD_CORE wxSpinCtrl
;
22 // ----------------------------------------------------------------------------
23 // wxGenericCalendarCtrl
24 // ----------------------------------------------------------------------------
26 class WXDLLIMPEXP_ADV wxGenericCalendarCtrl
: public wxCalendarCtrlBase
30 wxGenericCalendarCtrl() { Init(); }
31 wxGenericCalendarCtrl(wxWindow
*parent
,
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
);
39 bool Create(wxWindow
*parent
,
41 const wxDateTime
& date
= wxDefaultDateTime
,
42 const wxPoint
& pos
= wxDefaultPosition
,
43 const wxSize
& size
= wxDefaultSize
,
44 long style
= wxCAL_SHOW_HOLIDAYS
,
45 const wxString
& name
= wxCalendarNameStr
);
47 virtual ~wxGenericCalendarCtrl();
49 virtual bool Destroy();
51 // set/get the current date
52 // ------------------------
54 virtual bool SetDate(const wxDateTime
& date
);
55 virtual wxDateTime
GetDate() const { return m_date
; }
58 // set/get the range in which selection can occur
59 // ---------------------------------------------
61 virtual bool SetDateRange(const wxDateTime
& lowerdate
= wxDefaultDateTime
,
62 const wxDateTime
& upperdate
= wxDefaultDateTime
);
64 virtual bool GetDateRange(wxDateTime
*lowerdate
, wxDateTime
*upperdate
) const;
66 // these functions are for generic version only, don't use them but use the
67 // Set/GetDateRange() above instead
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
; }
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
81 // corresponds to wxCAL_NO_MONTH_CHANGE bit
82 virtual bool EnableMonthChange(bool enable
= true);
84 // corresponds to wxCAL_NO_YEAR_CHANGE bit, deprecated, generic only
85 void EnableYearChange(bool enable
= true);
87 // corresponds to wxCAL_SHOW_HOLIDAYS bit, generic only
88 virtual void EnableHolidayDisplay(bool display
= true);
94 virtual void Mark(size_t day
, bool mark
);
96 // all other functions in this section are for generic version only
98 // header colours are used for painting the weekdays at the top
99 virtual void SetHeaderColours(const wxColour
& colFg
, const wxColour
& colBg
)
101 m_colHeaderFg
= colFg
;
102 m_colHeaderBg
= colBg
;
105 virtual const wxColour
& GetHeaderColourFg() const { return m_colHeaderFg
; }
106 virtual const wxColour
& GetHeaderColourBg() const { return m_colHeaderBg
; }
108 // highlight colour is used for the currently selected date
109 virtual void SetHighlightColours(const wxColour
& colFg
, const wxColour
& colBg
)
111 m_colHighlightFg
= colFg
;
112 m_colHighlightBg
= colBg
;
115 virtual const wxColour
& GetHighlightColourFg() const { return m_colHighlightFg
; }
116 virtual const wxColour
& GetHighlightColourBg() const { return m_colHighlightBg
; }
118 // holiday colour is used for the holidays (if style & wxCAL_SHOW_HOLIDAYS)
119 virtual void SetHolidayColours(const wxColour
& colFg
, const wxColour
& colBg
)
121 m_colHolidayFg
= colFg
;
122 m_colHolidayBg
= colBg
;
125 virtual const wxColour
& GetHolidayColourFg() const { return m_colHolidayFg
; }
126 virtual const wxColour
& GetHolidayColourBg() const { return m_colHolidayBg
; }
128 virtual wxCalendarDateAttr
*GetAttr(size_t day
) const
130 wxCHECK_MSG( day
> 0 && day
< 32, NULL
, _T("invalid day") );
132 return m_attrs
[day
- 1];
135 virtual void SetAttr(size_t day
, wxCalendarDateAttr
*attr
)
137 wxCHECK_RET( day
> 0 && day
< 32, _T("invalid day") );
139 delete m_attrs
[day
- 1];
140 m_attrs
[day
- 1] = attr
;
143 virtual void ResetAttr(size_t day
) { SetAttr(day
, NULL
); }
145 virtual void SetHoliday(size_t day
);
147 virtual wxCalendarHitTestResult
HitTest(const wxPoint
& pos
,
148 wxDateTime
*date
= NULL
,
149 wxDateTime::WeekDay
*wd
= NULL
);
151 // implementation only from now on
152 // -------------------------------
154 // forward these functions to all subcontrols
155 virtual bool Enable(bool enable
= true);
156 virtual bool Show(bool show
= true);
158 virtual void SetWindowStyleFlag(long style
);
160 virtual wxVisualAttributes
GetDefaultAttributes() const
161 { return GetClassDefaultAttributes(GetWindowVariant()); }
163 static wxVisualAttributes
164 GetClassDefaultAttributes(wxWindowVariant variant
= wxWINDOW_VARIANT_NORMAL
);
166 void OnSysColourChanged(wxSysColourChangedEvent
& event
);
169 // override some base class virtuals
170 virtual wxSize
DoGetBestSize() const;
171 virtual void DoMoveWindow(int x
, int y
, int width
, int height
);
172 virtual void DoGetSize(int *width
, int *height
) const;
175 // common part of all ctors
178 // startup colours and reinitialization after colour changes in system
182 void OnPaint(wxPaintEvent
& event
);
183 void OnClick(wxMouseEvent
& event
);
184 void OnDClick(wxMouseEvent
& event
);
185 void OnChar(wxKeyEvent
& event
);
186 void OnMonthChange(wxCommandEvent
& event
);
187 void OnYearChange(wxCommandEvent
& event
);
188 void OnYearTextChange(wxCommandEvent
& event
);
190 // (re)calc m_widthCol and m_heightRow
191 void RecalcGeometry();
193 // set the date and send the notification
194 void SetDateAndNotify(const wxDateTime
& date
);
196 // get the week (row, in range 1..6) for the given date
197 size_t GetWeek(const wxDateTime
& date
) const;
199 // get the date from which we start drawing days
200 wxDateTime
GetStartDate() const;
202 // is this date shown?
203 bool IsDateShown(const wxDateTime
& date
) const;
205 // is this date in the given range?
206 bool IsDateInRange(const wxDateTime
& date
) const;
209 bool ChangeYear(wxDateTime
* target
) const;
210 bool ChangeMonth(wxDateTime
* target
) const;
212 // redraw the given date
213 void RefreshDate(const wxDateTime
& date
);
215 // change the date inside the same month/year
216 void ChangeDay(const wxDateTime
& date
);
218 // set the attributes for the holidays if needed
219 void SetHolidayAttrs();
221 // reset all holidays
222 void ResetHolidayAttrs();
225 bool AllowYearChange() const
227 return !(GetWindowStyle() & wxCAL_NO_YEAR_CHANGE
);
230 // show the correct controls
231 void ShowCurrentControls();
233 // create the month combo and year spin controls
234 void CreateMonthComboBox();
235 void CreateYearSpinCtrl();
238 // get the currently shown control for month/year
239 wxControl
*GetMonthControl() const;
240 wxControl
*GetYearControl() const;
243 // OnPaint helper-methods
245 // Highlight the [fromdate : todate] range using pen and brush
246 void HighlightRange(wxPaintDC
* dc
, const wxDateTime
& fromdate
, const wxDateTime
& todate
, const wxPen
* pen
, const wxBrush
* brush
);
248 // Get the "coordinates" for the date relative to the month currently displayed.
249 // using (day, week): upper left coord is (1, 1), lower right coord is (7, 6)
250 // if the date isn't visible (-1, -1) is put in (day, week) and false is returned
251 bool GetDateCoord(const wxDateTime
& date
, int *day
, int *week
) const;
253 // Set the flag for SetDate(): otherwise it would overwrite the year
254 // typed in by the user
255 void SetUserChangedYear() { m_userChangedYear
= true; }
259 wxStaticText
*m_staticMonth
;
260 wxComboBox
*m_comboMonth
;
262 wxStaticText
*m_staticYear
;
263 wxSpinCtrl
*m_spinYear
;
265 // the current selection
269 wxDateTime m_lowdate
;
270 wxDateTime m_highdate
;
272 // default attributes
273 wxColour m_colHighlightFg
,
282 // the attributes for each of the month days
283 wxCalendarDateAttr
*m_attrs
[31];
285 // the width and height of one column/row in the calendar
290 wxRect m_leftArrowRect
,
293 // the week day names
294 wxString m_weekdays
[7];
296 // true if SetDate() is being called as the result of changing the year in
298 bool m_userChangedYear
;
300 DECLARE_DYNAMIC_CLASS(wxGenericCalendarCtrl
)
301 DECLARE_EVENT_TABLE()
302 DECLARE_NO_COPY_CLASS(wxGenericCalendarCtrl
)
305 #endif // _WX_GENERIC_CALCTRLG_H