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
, style
, wxDefaultValidator
, name
)
47 (void)Create(parent
, id
, date
, pos
, size
, style
, name
);
50 bool Create(wxWindow
*parent
,
52 const wxDateTime
& date
= wxDefaultDateTime
,
53 const wxPoint
& pos
= wxDefaultPosition
,
54 const wxSize
& size
= wxDefaultSize
,
56 const wxString
& name
= wxCalendarNameStr
);
58 // set/get the current date
59 void SetDate(const wxDateTime
& date
);
60 const wxDateTime
& GetDate() const { return m_date
; }
62 // returns TRUE if the given point is on a day and fills date with its
64 bool HitTest(const wxPoint
& pos
, wxDateTime
*date
);
67 // common part of all ctors
70 // override some base class virtuals
71 virtual wxSize
DoGetBestSize() const;
72 virtual void DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
);
73 virtual void DoMoveWindow(int x
, int y
, int width
, int height
);
75 // (re)calc m_widthCol and m_heightRow
76 void RecalcGeometry();
79 void OnPaint(wxPaintEvent
& event
);
80 void OnClick(wxMouseEvent
& event
);
81 void OnChar(wxKeyEvent
& event
);
82 void OnMonthChange(wxCommandEvent
& event
);
83 void OnYearChange(wxSpinEvent
& event
);
85 // set the date and send the notification
86 void SetDateAndNotify(const wxDateTime
& date
);
88 // get the week (row, in range 1..6) for the given date
89 size_t GetWeek(const wxDateTime
& date
) const;
91 // get the date from which we start drawing days
92 wxDateTime
GetStartDate() const;
94 // is this date shown?
95 bool IsDateShown(const wxDateTime
& date
) const;
97 // redraw the given date
98 void RefreshDate(const wxDateTime
& date
);
100 // change the date inside the same month/year
101 void ChangeDay(const wxDateTime
& date
);
103 // generate a calendar event
104 void GenerateEvent(wxEventType type
);
107 wxComboBox
*m_comboMonth
;
108 wxSpinCtrl
*m_spinYear
;
112 // the width and height of one column/row in the calendar
116 // the week day names
117 wxString m_weekdays
[7];
119 DECLARE_DYNAMIC_CLASS(wxCalendarCtrl
)
120 DECLARE_EVENT_TABLE()
123 #endif // _WX_GENERIC_CALCTRL_H