]> git.saurik.com Git - wxWidgets.git/blob - include/wx/generic/calctrl.h
c685deeb4846a4348b94faf05c767909fc5e52b7
[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,
44 style | wxWANTS_CHARS, wxDefaultValidator, name)
45 {
46 Init();
47
48 (void)Create(parent, id, date, pos, size, style, name);
49 }
50
51 bool Create(wxWindow *parent,
52 wxWindowID id,
53 const wxDateTime& date = wxDefaultDateTime,
54 const wxPoint& pos = wxDefaultPosition,
55 const wxSize& size = wxDefaultSize,
56 long style = 0,
57 const wxString& name = wxCalendarNameStr);
58
59 virtual ~wxCalendarCtrl();
60
61 // set/get the current date
62 void SetDate(const wxDateTime& date);
63 const wxDateTime& GetDate() const { return m_date; }
64
65 // returns TRUE if the given point is on a day and fills date with its
66 // value
67 bool HitTest(const wxPoint& pos, wxDateTime *date);
68
69 // implementation only from now on
70 // -------------------------------
71
72 // forward these functions to all subcontrols
73 virtual bool Enable(bool enable = TRUE);
74 virtual bool Show(bool show = TRUE);
75
76 // event handlers
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);
82
83 private:
84 // common part of all ctors
85 void Init();
86
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);
93
94 // (re)calc m_widthCol and m_heightRow
95 void RecalcGeometry();
96
97 // set the date and send the notification
98 void SetDateAndNotify(const wxDateTime& date);
99
100 // get the week (row, in range 1..6) for the given date
101 size_t GetWeek(const wxDateTime& date) const;
102
103 // get the date from which we start drawing days
104 wxDateTime GetStartDate() const;
105
106 // is this date shown?
107 bool IsDateShown(const wxDateTime& date) const;
108
109 // redraw the given date
110 void RefreshDate(const wxDateTime& date);
111
112 // change the date inside the same month/year
113 void ChangeDay(const wxDateTime& date);
114
115 // generate a calendar event
116 void GenerateEvent(wxEventType type);
117
118 // the subcontrols
119 wxComboBox *m_comboMonth;
120 wxSpinCtrl *m_spinYear;
121
122 wxDateTime m_date;
123
124 // the width and height of one column/row in the calendar
125 wxCoord m_widthCol,
126 m_heightRow;
127
128 // the week day names
129 wxString m_weekdays[7];
130
131 DECLARE_DYNAMIC_CLASS(wxCalendarCtrl)
132 DECLARE_EVENT_TABLE()
133 };
134
135 #endif // _WX_GENERIC_CALCTRL_H