1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: generic/calctrl.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 license
10 ///////////////////////////////////////////////////////////////////////////////
13 #pragma interface "calctrl.h"
16 #ifndef _WX_GENERIC_CALCTRL_H
17 #define _WX_GENERIC_CALCTRL_H
19 #include "wx/control.h" // the base class
21 #include "wx/datetime.h" // for m_date
22 #include "wx/combobox.h" // for m_comboMonth
23 #include "wx/spinctrl.h" // for m_spinYear
25 #define wxCalendarNameStr _T("CalendarCtrl")
27 // ----------------------------------------------------------------------------
28 // wxCalendarCtrl: a control allowing the user to pick a date interactively
29 // ----------------------------------------------------------------------------
31 class WXDLLEXPORT wxCalendarCtrl
: public wxControl
35 wxCalendarCtrl() { Init(); }
36 wxCalendarCtrl(wxWindow
*parent
,
38 const wxDateTime
& date
= wxDefaultDateTime
,
39 const wxPoint
& pos
= wxDefaultPosition
,
40 const wxSize
& size
= wxDefaultSize
,
42 const wxString
& name
= wxCalendarNameStr
)
43 : wxControl(parent
, id
, pos
, size
,
44 style
| wxWANTS_CHARS
, wxDefaultValidator
, name
)
48 (void)Create(parent
, id
, date
, pos
, size
, style
, name
);
51 bool Create(wxWindow
*parent
,
53 const wxDateTime
& date
= wxDefaultDateTime
,
54 const wxPoint
& pos
= wxDefaultPosition
,
55 const wxSize
& size
= wxDefaultSize
,
57 const wxString
& name
= wxCalendarNameStr
);
59 virtual ~wxCalendarCtrl();
61 // set/get the current date
62 void SetDate(const wxDateTime
& date
);
63 const wxDateTime
& GetDate() const { return m_date
; }
65 // returns TRUE if the given point is on a day and fills date with its
67 bool HitTest(const wxPoint
& pos
, wxDateTime
*date
);
69 // implementation only from now on
70 // -------------------------------
72 // forward these functions to all subcontrols
73 virtual bool Enable(bool enable
= TRUE
);
74 virtual bool Show(bool show
= TRUE
);
77 void OnPaint(wxPaintEvent
& event
);
78 void OnClick(wxMouseEvent
& event
);
79 void OnChar(wxKeyEvent
& event
);
80 void OnMonthChange(wxCommandEvent
& event
);
81 void OnYearChange(wxSpinEvent
& event
);
84 // common part of all ctors
87 // override some base class virtuals
88 virtual wxSize
DoGetBestSize() const;
89 virtual void DoGetPosition(int *x
, int *y
) const;
90 virtual void DoGetSize(int *width
, int *height
) const;
91 virtual void DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
);
92 virtual void DoMoveWindow(int x
, int y
, int width
, int height
);
94 // (re)calc m_widthCol and m_heightRow
95 void RecalcGeometry();
97 // set the date and send the notification
98 void SetDateAndNotify(const wxDateTime
& date
);
100 // get the week (row, in range 1..6) for the given date
101 size_t GetWeek(const wxDateTime
& date
) const;
103 // get the date from which we start drawing days
104 wxDateTime
GetStartDate() const;
106 // is this date shown?
107 bool IsDateShown(const wxDateTime
& date
) const;
109 // redraw the given date
110 void RefreshDate(const wxDateTime
& date
);
112 // change the date inside the same month/year
113 void ChangeDay(const wxDateTime
& date
);
115 // generate a calendar event
116 void GenerateEvent(wxEventType type
);
119 wxComboBox
*m_comboMonth
;
120 wxSpinCtrl
*m_spinYear
;
124 // the width and height of one column/row in the calendar
128 // the week day names
129 wxString m_weekdays
[7];
131 DECLARE_DYNAMIC_CLASS(wxCalendarCtrl
)
132 DECLARE_EVENT_TABLE()
135 #endif // _WX_GENERIC_CALCTRL_H