1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: wx/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
;
21 class WXDLLIMPEXP_FWD_CORE wxSpinEvent
;
23 // ----------------------------------------------------------------------------
24 // wxGenericCalendarCtrl
25 // ----------------------------------------------------------------------------
27 class WXDLLIMPEXP_ADV wxGenericCalendarCtrl
: public wxCalendarCtrlBase
31 wxGenericCalendarCtrl() { Init(); }
32 wxGenericCalendarCtrl(wxWindow
*parent
,
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
);
40 bool Create(wxWindow
*parent
,
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
);
48 virtual ~wxGenericCalendarCtrl();
50 virtual bool Destroy();
52 // set/get the current date
53 // ------------------------
55 virtual bool SetDate(const wxDateTime
& date
);
56 virtual wxDateTime
GetDate() const { return m_date
; }
59 // set/get the range in which selection can occur
60 // ---------------------------------------------
62 virtual bool SetDateRange(const wxDateTime
& lowerdate
= wxDefaultDateTime
,
63 const wxDateTime
& upperdate
= wxDefaultDateTime
);
65 virtual bool GetDateRange(wxDateTime
*lowerdate
, wxDateTime
*upperdate
) const;
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
; }
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
82 // corresponds to wxCAL_NO_MONTH_CHANGE bit
83 virtual bool EnableMonthChange(bool enable
= true);
85 // corresponds to wxCAL_NO_YEAR_CHANGE bit, deprecated, generic only
86 void EnableYearChange(bool enable
= true);
92 virtual void Mark(size_t day
, bool mark
);
94 // all other functions in this section are for generic version only
96 // header colours are used for painting the weekdays at the top
97 virtual void SetHeaderColours(const wxColour
& colFg
, const wxColour
& colBg
)
99 m_colHeaderFg
= colFg
;
100 m_colHeaderBg
= colBg
;
103 virtual const wxColour
& GetHeaderColourFg() const { return m_colHeaderFg
; }
104 virtual const wxColour
& GetHeaderColourBg() const { return m_colHeaderBg
; }
106 // highlight colour is used for the currently selected date
107 virtual void SetHighlightColours(const wxColour
& colFg
, const wxColour
& colBg
)
109 m_colHighlightFg
= colFg
;
110 m_colHighlightBg
= colBg
;
113 virtual const wxColour
& GetHighlightColourFg() const { return m_colHighlightFg
; }
114 virtual const wxColour
& GetHighlightColourBg() const { return m_colHighlightBg
; }
116 // holiday colour is used for the holidays (if style & wxCAL_SHOW_HOLIDAYS)
117 virtual void SetHolidayColours(const wxColour
& colFg
, const wxColour
& colBg
)
119 m_colHolidayFg
= colFg
;
120 m_colHolidayBg
= colBg
;
123 virtual const wxColour
& GetHolidayColourFg() const { return m_colHolidayFg
; }
124 virtual const wxColour
& GetHolidayColourBg() const { return m_colHolidayBg
; }
126 virtual wxCalendarDateAttr
*GetAttr(size_t day
) const
128 wxCHECK_MSG( day
> 0 && day
< 32, NULL
, wxT("invalid day") );
130 return m_attrs
[day
- 1];
133 virtual void SetAttr(size_t day
, wxCalendarDateAttr
*attr
)
135 wxCHECK_RET( day
> 0 && day
< 32, wxT("invalid day") );
137 delete m_attrs
[day
- 1];
138 m_attrs
[day
- 1] = attr
;
141 virtual void ResetAttr(size_t day
) { SetAttr(day
, NULL
); }
143 virtual void SetHoliday(size_t day
);
145 virtual wxCalendarHitTestResult
HitTest(const wxPoint
& pos
,
146 wxDateTime
*date
= NULL
,
147 wxDateTime::WeekDay
*wd
= NULL
);
149 // implementation only from now on
150 // -------------------------------
152 // forward these functions to all subcontrols
153 virtual bool Enable(bool enable
= true);
154 virtual bool Show(bool show
= true);
156 virtual void SetWindowStyleFlag(long style
);
158 virtual wxVisualAttributes
GetDefaultAttributes() const
159 { return GetClassDefaultAttributes(GetWindowVariant()); }
161 static wxVisualAttributes
162 GetClassDefaultAttributes(wxWindowVariant variant
= wxWINDOW_VARIANT_NORMAL
);
164 void OnSysColourChanged(wxSysColourChangedEvent
& event
);
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;
173 // common part of all ctors
176 // startup colours and reinitialization after colour changes in system
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
);
186 void HandleYearChange(wxCommandEvent
& event
);
187 void OnYearChange(wxSpinEvent
& 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 // get the first/last days of the week corresponding to the current style
203 wxDateTime::WeekDay
GetWeekStart() const
205 return HasFlag(wxCAL_MONDAY_FIRST
) ? wxDateTime::Mon
209 wxDateTime::WeekDay
GetWeekEnd() const
211 return HasFlag(wxCAL_MONDAY_FIRST
) ? wxDateTime::Sun
216 // is this date shown?
217 bool IsDateShown(const wxDateTime
& date
) const;
219 // is this date in the currently allowed range?
220 bool IsDateInRange(const wxDateTime
& date
) const;
222 // adjust the date to the currently allowed range, return true if it was
224 bool AdjustDateToRange(wxDateTime
*date
) const;
226 // redraw the given date
227 void RefreshDate(const wxDateTime
& date
);
229 // change the date inside the same month/year
230 void ChangeDay(const wxDateTime
& date
);
233 bool AllowYearChange() const
235 return !(GetWindowStyle() & wxCAL_NO_YEAR_CHANGE
);
238 // show the correct controls
239 void ShowCurrentControls();
241 // create the month combo and year spin controls
242 void CreateMonthComboBox();
243 void CreateYearSpinCtrl();
246 // get the currently shown control for month/year
247 wxControl
*GetMonthControl() const;
248 wxControl
*GetYearControl() const;
251 virtual void ResetHolidayAttrs();
252 virtual void RefreshHolidays() { Refresh(); }
254 // OnPaint helper-methods
256 // Highlight the [fromdate : todate] range using pen and brush
257 void HighlightRange(wxPaintDC
* dc
, const wxDateTime
& fromdate
, const wxDateTime
& todate
, const wxPen
* pen
, const wxBrush
* brush
);
259 // Get the "coordinates" for the date relative to the month currently displayed.
260 // using (day, week): upper left coord is (1, 1), lower right coord is (7, 6)
261 // if the date isn't visible (-1, -1) is put in (day, week) and false is returned
262 bool GetDateCoord(const wxDateTime
& date
, int *day
, int *week
) const;
264 // Set the flag for SetDate(): otherwise it would overwrite the year
265 // typed in by the user
266 void SetUserChangedYear() { m_userChangedYear
= true; }
270 wxStaticText
*m_staticMonth
;
271 wxComboBox
*m_comboMonth
;
273 wxStaticText
*m_staticYear
;
274 wxSpinCtrl
*m_spinYear
;
276 // the current selection
280 wxDateTime m_lowdate
;
281 wxDateTime m_highdate
;
283 // default attributes
284 wxColour m_colHighlightFg
,
293 // the attributes for each of the month days
294 wxCalendarDateAttr
*m_attrs
[31];
296 // the width and height of one column/row in the calendar
302 wxRect m_leftArrowRect
,
305 // the week day names
306 wxString m_weekdays
[7];
308 // true if SetDate() is being called as the result of changing the year in
310 bool m_userChangedYear
;
312 DECLARE_DYNAMIC_CLASS(wxGenericCalendarCtrl
)
313 DECLARE_EVENT_TABLE()
314 wxDECLARE_NO_COPY_CLASS(wxGenericCalendarCtrl
);
317 #endif // _WX_GENERIC_CALCTRLG_H