1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: wx/generic/calctrlg.h
3 // Purpose: generic implementation of date-picker control
4 // Author: Vadim Zeitlin
7 // Copyright: (c) 1999 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
11 #ifndef _WX_GENERIC_CALCTRLG_H
12 #define _WX_GENERIC_CALCTRLG_H
14 #include "wx/control.h" // the base class
15 #include "wx/dcclient.h" // for wxPaintDC
17 class WXDLLIMPEXP_FWD_CORE wxComboBox
;
18 class WXDLLIMPEXP_FWD_CORE wxStaticText
;
19 class WXDLLIMPEXP_FWD_CORE wxSpinCtrl
;
20 class WXDLLIMPEXP_FWD_CORE wxSpinEvent
;
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);
91 virtual void Mark(size_t day
, bool mark
);
93 // all other functions in this section are for generic version only
95 // header colours are used for painting the weekdays at the top
96 virtual void SetHeaderColours(const wxColour
& colFg
, const wxColour
& colBg
)
98 m_colHeaderFg
= colFg
;
99 m_colHeaderBg
= colBg
;
102 virtual const wxColour
& GetHeaderColourFg() const { return m_colHeaderFg
; }
103 virtual const wxColour
& GetHeaderColourBg() const { return m_colHeaderBg
; }
105 // highlight colour is used for the currently selected date
106 virtual void SetHighlightColours(const wxColour
& colFg
, const wxColour
& colBg
)
108 m_colHighlightFg
= colFg
;
109 m_colHighlightBg
= colBg
;
112 virtual const wxColour
& GetHighlightColourFg() const { return m_colHighlightFg
; }
113 virtual const wxColour
& GetHighlightColourBg() const { return m_colHighlightBg
; }
115 // holiday colour is used for the holidays (if style & wxCAL_SHOW_HOLIDAYS)
116 virtual void SetHolidayColours(const wxColour
& colFg
, const wxColour
& colBg
)
118 m_colHolidayFg
= colFg
;
119 m_colHolidayBg
= colBg
;
122 virtual const wxColour
& GetHolidayColourFg() const { return m_colHolidayFg
; }
123 virtual const wxColour
& GetHolidayColourBg() const { return m_colHolidayBg
; }
125 virtual wxCalendarDateAttr
*GetAttr(size_t day
) const
127 wxCHECK_MSG( day
> 0 && day
< 32, NULL
, wxT("invalid day") );
129 return m_attrs
[day
- 1];
132 virtual void SetAttr(size_t day
, wxCalendarDateAttr
*attr
)
134 wxCHECK_RET( day
> 0 && day
< 32, wxT("invalid day") );
136 delete m_attrs
[day
- 1];
137 m_attrs
[day
- 1] = attr
;
140 virtual void ResetAttr(size_t day
) { SetAttr(day
, NULL
); }
142 virtual void SetHoliday(size_t day
);
144 virtual wxCalendarHitTestResult
HitTest(const wxPoint
& pos
,
145 wxDateTime
*date
= NULL
,
146 wxDateTime::WeekDay
*wd
= NULL
);
148 // implementation only from now on
149 // -------------------------------
151 // forward these functions to all subcontrols
152 virtual bool Enable(bool enable
= true);
153 virtual bool Show(bool show
= true);
155 virtual void SetWindowStyleFlag(long style
);
157 virtual wxVisualAttributes
GetDefaultAttributes() const
158 { return GetClassDefaultAttributes(GetWindowVariant()); }
160 static wxVisualAttributes
161 GetClassDefaultAttributes(wxWindowVariant variant
= wxWINDOW_VARIANT_NORMAL
);
163 void OnSysColourChanged(wxSysColourChangedEvent
& event
);
166 // override some base class virtuals
167 virtual wxSize
DoGetBestSize() const;
168 virtual void DoMoveWindow(int x
, int y
, int width
, int height
);
169 virtual void DoGetSize(int *width
, int *height
) const;
172 // common part of all ctors
175 // startup colours and reinitialization after colour changes in system
179 void OnPaint(wxPaintEvent
& event
);
180 void OnClick(wxMouseEvent
& event
);
181 void OnDClick(wxMouseEvent
& event
);
182 void OnChar(wxKeyEvent
& event
);
183 void OnMonthChange(wxCommandEvent
& event
);
185 void HandleYearChange(wxCommandEvent
& event
);
186 void OnYearChange(wxSpinEvent
& event
);
187 void OnYearTextChange(wxCommandEvent
& event
);
189 // (re)calc m_widthCol and m_heightRow
190 void RecalcGeometry();
192 // set the date and send the notification
193 void SetDateAndNotify(const wxDateTime
& date
);
195 // get the week (row, in range 1..6) for the given date
196 size_t GetWeek(const wxDateTime
& date
) const;
198 // get the date from which we start drawing days
199 wxDateTime
GetStartDate() const;
201 // get the first/last days of the week corresponding to the current style
202 wxDateTime::WeekDay
GetWeekStart() const
204 return HasFlag(wxCAL_MONDAY_FIRST
) ? wxDateTime::Mon
208 wxDateTime::WeekDay
GetWeekEnd() const
210 return HasFlag(wxCAL_MONDAY_FIRST
) ? wxDateTime::Sun
215 // is this date shown?
216 bool IsDateShown(const wxDateTime
& date
) const;
218 // is this date in the currently allowed range?
219 bool IsDateInRange(const wxDateTime
& date
) const;
221 // adjust the date to the currently allowed range, return true if it was
223 bool AdjustDateToRange(wxDateTime
*date
) const;
225 // redraw the given date
226 void RefreshDate(const wxDateTime
& date
);
228 // change the date inside the same month/year
229 void ChangeDay(const wxDateTime
& date
);
232 bool AllowYearChange() const
234 return !(GetWindowStyle() & wxCAL_NO_YEAR_CHANGE
);
237 // show the correct controls
238 void ShowCurrentControls();
240 // create the month combo and year spin controls
241 void CreateMonthComboBox();
242 void CreateYearSpinCtrl();
245 // get the currently shown control for month/year
246 wxControl
*GetMonthControl() const;
247 wxControl
*GetYearControl() const;
250 virtual void ResetHolidayAttrs();
251 virtual void RefreshHolidays() { Refresh(); }
253 // OnPaint helper-methods
255 // Highlight the [fromdate : todate] range using pen and brush
256 void HighlightRange(wxPaintDC
* dc
, const wxDateTime
& fromdate
, const wxDateTime
& todate
, const wxPen
* pen
, const wxBrush
* brush
);
258 // Get the "coordinates" for the date relative to the month currently displayed.
259 // using (day, week): upper left coord is (1, 1), lower right coord is (7, 6)
260 // if the date isn't visible (-1, -1) is put in (day, week) and false is returned
261 bool GetDateCoord(const wxDateTime
& date
, int *day
, int *week
) const;
263 // Set the flag for SetDate(): otherwise it would overwrite the year
264 // typed in by the user
265 void SetUserChangedYear() { m_userChangedYear
= true; }
269 wxStaticText
*m_staticMonth
;
270 wxComboBox
*m_comboMonth
;
272 wxStaticText
*m_staticYear
;
273 wxSpinCtrl
*m_spinYear
;
275 // the current selection
279 wxDateTime m_lowdate
;
280 wxDateTime m_highdate
;
282 // default attributes
283 wxColour m_colHighlightFg
,
292 // the attributes for each of the month days
293 wxCalendarDateAttr
*m_attrs
[31];
295 // the width and height of one column/row in the calendar
301 wxRect m_leftArrowRect
,
304 // the week day names
305 wxString m_weekdays
[7];
307 // true if SetDate() is being called as the result of changing the year in
309 bool m_userChangedYear
;
311 DECLARE_DYNAMIC_CLASS(wxGenericCalendarCtrl
)
312 DECLARE_EVENT_TABLE()
313 wxDECLARE_NO_COPY_CLASS(wxGenericCalendarCtrl
);
316 #endif // _WX_GENERIC_CALCTRLG_H