]> git.saurik.com Git - wxWidgets.git/blob - include/wx/generic/calctrl.h
a3c4617964a1bfd82012334792c41f821a819f9c
[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 friend class wxMonthComboBox;
34 friend class wxYearSpinCtrl;
35
36 public:
37 // construction
38 wxCalendarCtrl() { Init(); }
39 wxCalendarCtrl(wxWindow *parent,
40 wxWindowID id,
41 const wxDateTime& date = wxDefaultDateTime,
42 const wxPoint& pos = wxDefaultPosition,
43 const wxSize& size = wxDefaultSize,
44 long style = 0,
45 const wxString& name = wxCalendarNameStr)
46 : wxControl(parent, id, pos, size,
47 style | wxWANTS_CHARS, wxDefaultValidator, name)
48 {
49 Init();
50
51 (void)Create(parent, id, date, pos, size, style, name);
52 }
53
54 bool Create(wxWindow *parent,
55 wxWindowID id,
56 const wxDateTime& date = wxDefaultDateTime,
57 const wxPoint& pos = wxDefaultPosition,
58 const wxSize& size = wxDefaultSize,
59 long style = 0,
60 const wxString& name = wxCalendarNameStr);
61
62 virtual ~wxCalendarCtrl();
63
64 // set/get the current date
65 void SetDate(const wxDateTime& date);
66 const wxDateTime& GetDate() const { return m_date; }
67
68 // returns one of wxCAL_HITTEST_XXX constants and fills either date or wd
69 // with the corresponding value (none for NOWHERE, the date for DAY and wd
70 // for HEADER)
71 wxCalendarHitTestResult HitTest(const wxPoint& pos,
72 wxDateTime *date = NULL,
73 wxDateTime::WeekDay *wd = NULL);
74
75 // implementation only from now on
76 // -------------------------------
77
78 // forward these functions to all subcontrols
79 virtual bool Enable(bool enable = TRUE);
80 virtual bool Show(bool show = TRUE);
81
82 private:
83 // common part of all ctors
84 void Init();
85
86 // event handlers
87 void OnPaint(wxPaintEvent& event);
88 void OnClick(wxMouseEvent& event);
89 void OnDClick(wxMouseEvent& event);
90 void OnChar(wxKeyEvent& event);
91 void OnMonthChange(wxCommandEvent& event);
92 void OnYearChange(wxSpinEvent& event);
93
94 // override some base class virtuals
95 virtual wxSize DoGetBestSize() const;
96 virtual void DoGetPosition(int *x, int *y) const;
97 virtual void DoGetSize(int *width, int *height) const;
98 virtual void DoSetSize(int x, int y, int width, int height, int sizeFlags);
99 virtual void DoMoveWindow(int x, int y, int width, int height);
100
101 // (re)calc m_widthCol and m_heightRow
102 void RecalcGeometry();
103
104 // set the date and send the notification
105 void SetDateAndNotify(const wxDateTime& date);
106
107 // get the week (row, in range 1..6) for the given date
108 size_t GetWeek(const wxDateTime& date) const;
109
110 // get the date from which we start drawing days
111 wxDateTime GetStartDate() const;
112
113 // is this date shown?
114 bool IsDateShown(const wxDateTime& date) const;
115
116 // redraw the given date
117 void RefreshDate(const wxDateTime& date);
118
119 // change the date inside the same month/year
120 void ChangeDay(const wxDateTime& date);
121
122 // generate the given calendar event and a "selection changed" one if
123 // selChanged is TRUE
124 void GenerateEvent(wxEventType type, bool selChanged = TRUE);
125
126 // the subcontrols
127 wxComboBox *m_comboMonth;
128 wxSpinCtrl *m_spinYear;
129
130 wxDateTime m_date;
131
132 // the width and height of one column/row in the calendar
133 wxCoord m_widthCol,
134 m_heightRow;
135
136 // the week day names
137 wxString m_weekdays[7];
138
139 DECLARE_DYNAMIC_CLASS(wxCalendarCtrl)
140 DECLARE_EVENT_TABLE()
141 };
142
143 #endif // _WX_GENERIC_CALCTRL_H