]> git.saurik.com Git - wxWidgets.git/blob - include/wx/generic/calctrl.h
5bde99940d39b6f6799c06b4702af9e75a7280b2
[wxWidgets.git] / include / wx / generic / calctrl.h
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: generic/calctrl.h
3 // Purpose: generic implementation of date-picker control
4 // Author: Vadim Zeitlin
5 // Modified by:
6 // Created: 29.12.99
7 // RCS-ID: $Id$
8 // Copyright: (c) 1999 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
9 // Licence: wxWindows license
10 ///////////////////////////////////////////////////////////////////////////////
11
12 #ifdef __GNUG__
13 #pragma interface "calctrl.h"
14 #endif
15
16 #ifndef _WX_GENERIC_CALCTRL_H
17 #define _WX_GENERIC_CALCTRL_H
18
19 #include "wx/control.h" // the base class
20
21 #include "wx/datetime.h" // for m_date
22 #include "wx/combobox.h" // for m_comboMonth
23 #include "wx/spinctrl.h" // for m_spinYear
24
25 #define wxCalendarNameStr _T("CalendarCtrl")
26
27 // ----------------------------------------------------------------------------
28 // wxCalendarCtrl: a control allowing the user to pick a date interactively
29 // ----------------------------------------------------------------------------
30
31 class WXDLLEXPORT wxCalendarCtrl : public wxControl
32 {
33 public:
34 // construction
35 wxCalendarCtrl() { Init(); }
36 wxCalendarCtrl(wxWindow *parent,
37 wxWindowID id,
38 const wxDateTime& date = wxDefaultDateTime,
39 const wxPoint& pos = wxDefaultPosition,
40 const wxSize& size = wxDefaultSize,
41 long style = 0,
42 const wxString& name = wxCalendarNameStr)
43 : wxControl(parent, id, pos, size, style, wxDefaultValidator, name)
44 {
45 Init();
46
47 (void)Create(parent, id, date, pos, size, style, name);
48 }
49
50 bool Create(wxWindow *parent,
51 wxWindowID id,
52 const wxDateTime& date = wxDefaultDateTime,
53 const wxPoint& pos = wxDefaultPosition,
54 const wxSize& size = wxDefaultSize,
55 long style = 0,
56 const wxString& name = wxCalendarNameStr);
57
58 // set/get the current date
59 void SetDate(const wxDateTime& date);
60 const wxDateTime& GetDate() const { return m_date; }
61
62 // returns TRUE if the given point is on a day and fills date with its
63 // value
64 bool HitTest(const wxPoint& pos, wxDateTime *date);
65
66 private:
67 // common part of all ctors
68 void Init();
69
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);
74
75 // (re)calc m_widthCol and m_heightRow
76 void RecalcGeometry();
77
78 // event handlers
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);
84
85 // set the date and send the notification
86 void SetDateAndNotify(const wxDateTime& date);
87
88 // get the week (row, in range 1..6) for the given date
89 size_t GetWeek(const wxDateTime& date) const;
90
91 // get the date from which we start drawing days
92 wxDateTime GetStartDate() const;
93
94 // is this date shown?
95 bool IsDateShown(const wxDateTime& date) const;
96
97 // redraw the given date
98 void RefreshDate(const wxDateTime& date);
99
100 // change the date inside the same month/year
101 void ChangeDay(const wxDateTime& date);
102
103 // generate a calendar event
104 void GenerateEvent(wxEventType type);
105
106 // the subcontrols
107 wxComboBox *m_comboMonth;
108 wxSpinCtrl *m_spinYear;
109
110 wxDateTime m_date;
111
112 // the width and height of one column/row in the calendar
113 wxCoord m_widthCol,
114 m_heightRow;
115
116 // the week day names
117 wxString m_weekdays[7];
118
119 DECLARE_DYNAMIC_CLASS(wxCalendarCtrl)
120 DECLARE_EVENT_TABLE()
121 };
122
123 #endif // _WX_GENERIC_CALCTRL_H