]>
Commit | Line | Data |
---|---|---|
74a533f7 VZ |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: calendar.cpp | |
3 | // Purpose: wxCalendarCtrl sample | |
4 | // Author: Vadim Zeitlin | |
5 | // Modified by: | |
6 | // Created: 02.01.00 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Vadim Zeitlin | |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | // ============================================================================ | |
13 | // declarations | |
14 | // ============================================================================ | |
15 | ||
16 | // ---------------------------------------------------------------------------- | |
17 | // headers | |
18 | // ---------------------------------------------------------------------------- | |
19 | ||
20 | #ifdef __GNUG__ | |
21 | #pragma implementation "calendar.cpp" | |
22 | #pragma interface "calendar.cpp" | |
23 | #endif | |
24 | ||
25 | // For compilers that support precompilation, includes "wx/wx.h". | |
26 | #include "wx/wxprec.h" | |
27 | ||
28 | #ifdef __BORLANDC__ | |
29 | #pragma hdrstop | |
30 | #endif | |
31 | ||
32 | // for all others, include the necessary headers (this file is usually all you | |
33 | // need because it includes almost all "standard" wxWindows headers | |
34 | #ifndef WX_PRECOMP | |
35 | #include "wx/app.h" | |
36 | #include "wx/frame.h" | |
37 | #endif | |
38 | ||
39 | #include "wx/calctrl.h" | |
40 | ||
41 | // ---------------------------------------------------------------------------- | |
42 | // private classes | |
43 | // ---------------------------------------------------------------------------- | |
44 | ||
45 | // Define a new application type, each program should derive a class from wxApp | |
46 | class MyApp : public wxApp | |
47 | { | |
48 | public: | |
49 | // override base class virtuals | |
50 | // ---------------------------- | |
51 | ||
52 | // this one is called on application startup and is a good place for the app | |
53 | // initialization (doing it here and not in the ctor allows to have an error | |
54 | // return: if OnInit() returns false, the application terminates) | |
55 | virtual bool OnInit(); | |
56 | }; | |
57 | ||
58 | class MyPanel : public wxPanel | |
59 | { | |
60 | public: | |
61 | MyPanel(wxFrame *frame); | |
62 | ||
63 | void OnCalendar(wxCalendarEvent& event); | |
64 | void OnCalendarWeekDayClick(wxCalendarEvent& event); | |
65 | void OnCalendarChange(wxCalendarEvent& event); | |
66 | ||
67 | void StartWithMonday(bool on); | |
68 | void ShowHolidays(bool on); | |
69 | void HighlightSpecial(bool on); | |
70 | ||
71 | private: | |
72 | wxCalendarCtrl *m_calendar; | |
73 | wxStaticText *m_date; | |
74 | ||
75 | DECLARE_EVENT_TABLE() | |
76 | }; | |
77 | ||
78 | // Define a new frame type: this is going to be our main frame | |
79 | class MyFrame : public wxFrame | |
80 | { | |
81 | public: | |
82 | // ctor(s) | |
83 | MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size); | |
84 | ||
85 | // event handlers (these functions should _not_ be virtual) | |
86 | void OnQuit(wxCommandEvent& event); | |
87 | void OnAbout(wxCommandEvent& event); | |
88 | ||
89 | void OnCalMonday(wxCommandEvent& event); | |
90 | void OnCalHolidays(wxCommandEvent& event); | |
91 | void OnCalSpecial(wxCommandEvent& event); | |
92 | ||
93 | private: | |
94 | MyPanel *m_panel; | |
95 | ||
96 | // any class wishing to process wxWindows events must use this macro | |
97 | DECLARE_EVENT_TABLE() | |
98 | }; | |
99 | ||
100 | // ---------------------------------------------------------------------------- | |
101 | // constants | |
102 | // ---------------------------------------------------------------------------- | |
103 | ||
104 | // IDs for the controls and the menu commands | |
105 | enum | |
106 | { | |
107 | // menu items | |
108 | Calendar_File_About = 100, | |
109 | Calendar_File_Quit, | |
110 | Calendar_Cal_Monday = 200, | |
111 | Calendar_Cal_Holidays, | |
112 | Calendar_Cal_Special, | |
113 | Calendar_CalCtrl = 1000, | |
114 | }; | |
115 | ||
116 | // ---------------------------------------------------------------------------- | |
117 | // event tables and other macros for wxWindows | |
118 | // ---------------------------------------------------------------------------- | |
119 | ||
120 | // the event tables connect the wxWindows events with the functions (event | |
121 | // handlers) which process them. It can be also done at run-time, but for the | |
122 | // simple menu events like this the static method is much simpler. | |
123 | BEGIN_EVENT_TABLE(MyFrame, wxFrame) | |
124 | EVT_MENU(Calendar_File_Quit, MyFrame::OnQuit) | |
125 | EVT_MENU(Calendar_File_About, MyFrame::OnAbout) | |
126 | ||
127 | EVT_MENU(Calendar_Cal_Monday, MyFrame::OnCalMonday) | |
128 | EVT_MENU(Calendar_Cal_Holidays, MyFrame::OnCalHolidays) | |
129 | EVT_MENU(Calendar_Cal_Special, MyFrame::OnCalSpecial) | |
130 | END_EVENT_TABLE() | |
131 | ||
132 | BEGIN_EVENT_TABLE(MyPanel, wxPanel) | |
133 | EVT_CALENDAR (Calendar_CalCtrl, MyPanel::OnCalendar) | |
134 | EVT_CALENDAR_SEL_CHANGED(Calendar_CalCtrl, MyPanel::OnCalendarChange) | |
135 | EVT_CALENDAR_WEEKDAY_CLICKED(Calendar_CalCtrl, MyPanel::OnCalendarWeekDayClick) | |
136 | END_EVENT_TABLE() | |
137 | ||
138 | // Create a new application object: this macro will allow wxWindows to create | |
139 | // the application object during program execution (it's better than using a | |
140 | // static object for many reasons) and also declares the accessor function | |
141 | // wxGetApp() which will return the reference of the right type (i.e. MyApp and | |
142 | // not wxApp) | |
143 | IMPLEMENT_APP(MyApp) | |
144 | ||
145 | // ============================================================================ | |
146 | // implementation | |
147 | // ============================================================================ | |
148 | ||
149 | // ---------------------------------------------------------------------------- | |
150 | // the application class | |
151 | // ---------------------------------------------------------------------------- | |
152 | ||
153 | // `Main program' equivalent: the program execution "starts" here | |
154 | bool MyApp::OnInit() | |
155 | { | |
156 | // Create the main application window | |
157 | MyFrame *frame = new MyFrame("Minimal wxWindows App", | |
158 | wxPoint(50, 50), wxSize(450, 340)); | |
159 | ||
160 | // Show it and tell the application that it's our main window | |
161 | // @@@ what does it do exactly, in fact? is it necessary here? | |
162 | frame->Show(TRUE); | |
163 | SetTopWindow(frame); | |
164 | ||
165 | // success: wxApp::OnRun() will be called which will enter the main message | |
166 | // loop and the application will run. If we returned FALSE here, the | |
167 | // application would exit immediately. | |
168 | return TRUE; | |
169 | } | |
170 | ||
171 | // ---------------------------------------------------------------------------- | |
172 | // main frame | |
173 | // ---------------------------------------------------------------------------- | |
174 | ||
175 | // frame constructor | |
176 | MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size) | |
177 | : wxFrame((wxFrame *)NULL, -1, title, pos, size) | |
178 | { | |
179 | // create a menu bar | |
180 | wxMenu *menuFile = new wxMenu; | |
181 | ||
182 | menuFile->Append(Calendar_File_About, "&About...\tCtrl-A", "Show about dialog"); | |
183 | menuFile->AppendSeparator(); | |
184 | menuFile->Append(Calendar_File_Quit, "E&xit\tAlt-X", "Quit this program"); | |
185 | ||
186 | wxMenu *menuCal = new wxMenu; | |
187 | menuCal->Append(Calendar_Cal_Monday, | |
188 | "&Monday first weekday\tCtrl-M", | |
189 | "Toggle between Mon and Sun as the first week day", | |
190 | TRUE); | |
191 | menuCal->Append(Calendar_Cal_Holidays, "Show &holidays\tCtrl-H", | |
192 | "Toggle highlighting the holidays", | |
193 | TRUE); | |
194 | menuCal->Append(Calendar_Cal_Special, "Highlight &special dates\tCtrl-S", | |
195 | "Test custom highlighting", | |
196 | TRUE); | |
197 | ||
198 | // now append the freshly created menu to the menu bar... | |
199 | wxMenuBar *menuBar = new wxMenuBar; | |
200 | menuBar->Append(menuFile, "&File"); | |
201 | menuBar->Append(menuCal, "&Calendar"); | |
202 | ||
203 | menuBar->Check(Calendar_Cal_Monday, TRUE); | |
204 | menuBar->Check(Calendar_Cal_Holidays, TRUE); | |
205 | ||
206 | // ... and attach this menu bar to the frame | |
207 | SetMenuBar(menuBar); | |
208 | ||
209 | m_panel = new MyPanel(this); | |
210 | ||
211 | #if wxUSE_STATUSBAR | |
212 | // create a status bar just for fun (by default with 1 pane only) | |
213 | CreateStatusBar(2); | |
214 | SetStatusText("Welcome to wxWindows!"); | |
215 | #endif // wxUSE_STATUSBAR | |
216 | } | |
217 | ||
218 | void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event)) | |
219 | { | |
220 | // TRUE is to force the frame to close | |
221 | Close(TRUE); | |
222 | } | |
223 | ||
224 | void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event)) | |
225 | { | |
226 |