]>
Commit | Line | Data |
---|---|---|
74a533f7 VZ |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: calendar.cpp | |
3 | // Purpose: wxCalendarCtrl sample | |
4 | // Author: Vadim Zeitlin | |
4e6bceff | 5 | // Modified by: |
74a533f7 VZ |
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 | ||
788233da | 20 | #if defined(__GNUG__) && !defined(__APPLE__) |
74a533f7 VZ |
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 | ||
273b7ed9 | 32 | // for all others, include the necessary headers |
74a533f7 VZ |
33 | #ifndef WX_PRECOMP |
34 | #include "wx/app.h" | |
788233da | 35 | #include "wx/log.h" |
74a533f7 | 36 | #include "wx/frame.h" |
273b7ed9 VZ |
37 | #include "wx/panel.h" |
38 | #include "wx/stattext.h" | |
39 | #include "wx/menu.h" | |
40 | #include "wx/layout.h" | |
41 | #include "wx/msgdlg.h" | |
74a533f7 VZ |
42 | #endif |
43 | ||
9230b621 | 44 | #include "wx/sizer.h" |
feb72429 VZ |
45 | #include "wx/textctrl.h" |
46 | ||
74a533f7 | 47 | #include "wx/calctrl.h" |
feb72429 VZ |
48 | #include "wx/datectrl.h" |
49 | ||
74a533f7 VZ |
50 | // ---------------------------------------------------------------------------- |
51 | // private classes | |
52 | // ---------------------------------------------------------------------------- | |
53 | ||
54 | // Define a new application type, each program should derive a class from wxApp | |
55 | class MyApp : public wxApp | |
56 | { | |
57 | public: | |
58 | // override base class virtuals | |
59 | // ---------------------------- | |
60 | ||
61 | // this one is called on application startup and is a good place for the app | |
62 | // initialization (doing it here and not in the ctor allows to have an error | |
63 | // return: if OnInit() returns false, the application terminates) | |
64 | virtual bool OnInit(); | |
65 | }; | |
66 | ||
67 | class MyPanel : public wxPanel | |
68 | { | |
69 | public: | |
70 | MyPanel(wxFrame *frame); | |
71 | ||
72 | void OnCalendar(wxCalendarEvent& event); | |
73 | void OnCalendarWeekDayClick(wxCalendarEvent& event); | |
74 | void OnCalendarChange(wxCalendarEvent& event); | |
0de868d9 VZ |
75 | void OnCalMonthChange(wxCalendarEvent& event); |
76 | void OnCalYearChange(wxCalendarEvent& event); | |
74a533f7 | 77 | |
bc385ba9 VZ |
78 | wxCalendarCtrl *GetCal() const { return m_calendar; } |
79 | ||
37df1f33 VZ |
80 | // turn on/off the specified style bit on the calendar control |
81 | void ToggleCalStyle(bool on, int style); | |
82 | ||
74a533f7 VZ |
83 | void HighlightSpecial(bool on); |
84 | ||
605dfd91 JS |
85 | void SetDate(); |
86 | void Today(); | |
87 | ||
74a533f7 VZ |
88 | private: |
89 | wxCalendarCtrl *m_calendar; | |
90 | wxStaticText *m_date; | |
91 | ||
92 | DECLARE_EVENT_TABLE() | |
93 | }; | |
94 | ||
95 | // Define a new frame type: this is going to be our main frame | |
96 | class MyFrame : public wxFrame | |
97 | { | |
98 | public: | |
99 | // ctor(s) | |
100 | MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size); | |
101 | ||
102 | // event handlers (these functions should _not_ be virtual) | |
103 | void OnQuit(wxCommandEvent& event); | |
104 | void OnAbout(wxCommandEvent& event); | |
105 | ||
ac78ab7b | 106 | #if wxUSE_DATEPICKCTRL |
feb72429 | 107 | void OnAskDate(wxCommandEvent& event); |
ac78ab7b | 108 | #endif // wxUSE_DATEPICKCTRL |
feb72429 | 109 | |
74a533f7 VZ |
110 | void OnCalMonday(wxCommandEvent& event); |
111 | void OnCalHolidays(wxCommandEvent& event); | |
112 | void OnCalSpecial(wxCommandEvent& event); | |
113 | ||
bc385ba9 VZ |
114 | void OnCalAllowMonth(wxCommandEvent& event); |
115 | void OnCalAllowYear(wxCommandEvent& event); | |
116 | ||
37df1f33 VZ |
117 | void OnCalSeqMonth(wxCommandEvent& event); |
118 | void OnCalShowSurroundingWeeks(wxCommandEvent& event); | |
119 | ||
605dfd91 JS |
120 | void OnSetDate(wxCommandEvent& event); |
121 | void OnToday(wxCommandEvent& event); | |
122 | ||
bc385ba9 VZ |
123 | void OnAllowYearUpdate(wxUpdateUIEvent& event); |
124 | ||
74a533f7 VZ |
125 | private: |
126 | MyPanel *m_panel; | |
127 | ||
be5a51fb | 128 | // any class wishing to process wxWidgets events must use this macro |
74a533f7 VZ |
129 | DECLARE_EVENT_TABLE() |
130 | }; | |
131 | ||
ac78ab7b | 132 | #if wxUSE_DATEPICKCTRL |
feb72429 VZ |
133 | |
134 | // Define a simple modal dialog which asks the user for a date | |
135 | class MyDialog : public wxDialog | |
136 | { | |
137 | public: | |
138 | MyDialog(wxWindow *parent, const wxDateTime& dt); | |
139 | ||
140 | wxDateTime GetDate() const { return m_datePicker->GetValue(); } | |
141 | ||
142 | private: | |
143 | void OnDateChange(wxDateEvent& event); | |
144 | ||
145 | ||
146 | wxDatePickerCtrl *m_datePicker; | |
147 | wxTextCtrl *m_text; | |
148 | ||
149 | ||
150 | DECLARE_EVENT_TABLE() | |
151 | }; | |
152 | ||
ac78ab7b | 153 | #endif // wxUSE_DATEPICKCTRL |
feb72429 | 154 | |
74a533f7 VZ |
155 | // ---------------------------------------------------------------------------- |
156 | // constants | |
157 | // ---------------------------------------------------------------------------- | |
158 | ||
159 | // IDs for the controls and the menu commands | |
160 | enum | |
161 | { | |
162 | // menu items | |
feb72429 VZ |
163 | Calendar_File_About = wxID_ABOUT, |
164 | Calendar_File_Quit = wxID_EXIT, | |
ac78ab7b | 165 | #if wxUSE_DATEPICKCTRL |
feb72429 | 166 | Calendar_File_AskDate = 100, |
ac78ab7b | 167 | #endif // wxUSE_DATEPICKCTRL |
74a533f7 VZ |
168 | Calendar_Cal_Monday = 200, |
169 | Calendar_Cal_Holidays, | |
170 | Calendar_Cal_Special, | |
bc385ba9 VZ |
171 | Calendar_Cal_Month, |
172 | Calendar_Cal_Year, | |
37df1f33 VZ |
173 | Calendar_Cal_SeqMonth, |
174 | Calendar_Cal_SurroundWeeks, | |
605dfd91 JS |
175 | Calendar_Cal_SetDate, |
176 | Calendar_Cal_Today, | |
e9561b3b | 177 | Calendar_CalCtrl = 1000 |
74a533f7 VZ |
178 | }; |
179 | ||
180 | // ---------------------------------------------------------------------------- | |
be5a51fb | 181 | // event tables and other macros for wxWidgets |
74a533f7 VZ |
182 | // ---------------------------------------------------------------------------- |
183 | ||
be5a51fb | 184 | // the event tables connect the wxWidgets events with the functions (event |
74a533f7 VZ |
185 | // handlers) which process them. It can be also done at run-time, but for the |
186 | // simple menu events like this the static method is much simpler. | |
187 | BEGIN_EVENT_TABLE(MyFrame, wxFrame) | |
188 | EVT_MENU(Calendar_File_Quit, MyFrame::OnQuit) | |
189 | EVT_MENU(Calendar_File_About, MyFrame::OnAbout) | |
190 | ||
ac78ab7b | 191 | #if wxUSE_DATEPICKCTRL |
feb72429 | 192 | EVT_MENU(Calendar_File_AskDate, MyFrame::OnAskDate) |
ac78ab7b | 193 | #endif // wxUSE_DATEPICKCTRL |
feb72429 | 194 | |
74a533f7 VZ |
195 | EVT_MENU(Calendar_Cal_Monday, MyFrame::OnCalMonday) |
196 | EVT_MENU(Calendar_Cal_Holidays, MyFrame::OnCalHolidays) | |
197 | EVT_MENU(Calendar_Cal_Special, MyFrame::OnCalSpecial) | |
bc385ba9 VZ |
198 | |
199 | EVT_MENU(Calendar_Cal_Month, MyFrame::OnCalAllowMonth) | |
200 | EVT_MENU(Calendar_Cal_Year, MyFrame::OnCalAllowYear) | |
201 | ||
37df1f33 VZ |
202 | EVT_MENU(Calendar_Cal_SeqMonth, MyFrame::OnCalSeqMonth) |
203 | EVT_MENU(Calendar_Cal_SurroundWeeks, MyFrame::OnCalShowSurroundingWeeks) | |
204 | ||
605dfd91 JS |
205 | EVT_MENU(Calendar_Cal_SetDate, MyFrame::OnSetDate) |
206 | EVT_MENU(Calendar_Cal_Today, MyFrame::OnToday) | |
207 | ||
208 | ||
bc385ba9 | 209 | EVT_UPDATE_UI(Calendar_Cal_Year, MyFrame::OnAllowYearUpdate) |
74a533f7 VZ |
210 | END_EVENT_TABLE() |
211 | ||
212 | BEGIN_EVENT_TABLE(MyPanel, wxPanel) | |
213 | EVT_CALENDAR (Calendar_CalCtrl, MyPanel::OnCalendar) | |
0de868d9 VZ |
214 | EVT_CALENDAR_MONTH (Calendar_CalCtrl, MyPanel::OnCalMonthChange) |
215 | EVT_CALENDAR_YEAR (Calendar_CalCtrl, MyPanel::OnCalYearChange) | |
74a533f7 VZ |
216 | EVT_CALENDAR_SEL_CHANGED(Calendar_CalCtrl, MyPanel::OnCalendarChange) |
217 | EVT_CALENDAR_WEEKDAY_CLICKED(Calendar_CalCtrl, MyPanel::OnCalendarWeekDayClick) | |
218 | END_EVENT_TABLE() | |
219 | ||
ac78ab7b | 220 | #if wxUSE_DATEPICKCTRL |
feb72429 VZ |
221 | |
222 | BEGIN_EVENT_TABLE(MyDialog, wxDialog) | |
223 | EVT_DATE_CHANGED(wxID_ANY, MyDialog::OnDateChange) | |
224 | END_EVENT_TABLE() | |
225 | ||
ac78ab7b | 226 | #endif // wxUSE_DATEPICKCTRL |
feb72429 | 227 | |
be5a51fb | 228 | // Create a new application object: this macro will allow wxWidgets to create |
74a533f7 VZ |
229 | // the application object during program execution (it's better than using a |
230 | // static object for many reasons) and also declares the accessor function | |
231 | // wxGetApp() which will return the reference of the right type (i.e. MyApp and | |
232 | // not wxApp) | |
233 | IMPLEMENT_APP(MyApp) | |
234 | ||
235 | // ============================================================================ | |
236 | // implementation | |
237 | // ============================================================================ | |
238 | ||
239 | // ---------------------------------------------------------------------------- | |
240 | // the application class | |
241 | // ---------------------------------------------------------------------------- | |
242 | ||
243 | // `Main program' equivalent: the program execution "starts" here | |
244 | bool MyApp::OnInit() | |
245 | { | |
246 | // Create the main application window | |
be5a51fb | 247 | MyFrame *frame = new MyFrame(_T("Calendar wxWidgets sample"), |
4e6bceff | 248 | wxPoint(50, 50), wxSize(450, 340)); |
74a533f7 | 249 | |
9230b621 | 250 | frame->Show(true); |
74a533f7 VZ |
251 | |
252 | // success: wxApp::OnRun() will be called which will enter the main message | |
5014bb3a | 253 | // loop and the application will run. If we returned false here, the |
74a533f7 | 254 | // application would exit immediately. |
9230b621 | 255 | return true; |
74a533f7 VZ |
256 | } |
257 | ||
258 | // ---------------------------------------------------------------------------- | |
259 | // main frame | |
260 | // ---------------------------------------------------------------------------- | |
261 | ||
262 | // frame constructor | |
263 | MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size) | |
9230b621 | 264 | : wxFrame((wxFrame *)NULL, wxID_ANY, title, pos, size) |
74a533f7 VZ |
265 | { |
266 | // create a menu bar | |
267 | wxMenu *menuFile = new wxMenu; | |
268 | ||
ac78ab7b | 269 | #if wxUSE_DATEPICKCTRL |
feb72429 VZ |
270 | menuFile->Append(Calendar_File_AskDate, _T("&Choose date...\tCtrl-D"), _T("Show dialog with wxDatePickerCtrl")); |
271 | menuFile->AppendSeparator(); | |
ac78ab7b | 272 | #endif // wxUSE_DATEPICKCTRL |
feb72429 | 273 | |
9f84eccd | 274 | menuFile->Append(Calendar_File_About, _T("&About...\tCtrl-A"), _T("Show about dialog")); |
74a533f7 | 275 | menuFile->AppendSeparator(); |
9f84eccd | 276 | menuFile->Append(Calendar_File_Quit, _T("E&xit\tAlt-X"), _T("Quit this program")); |
74a533f7 VZ |
277 | |
278 | wxMenu *menuCal = new wxMenu; | |
279 | menuCal->Append(Calendar_Cal_Monday, | |
9f84eccd MB |
280 | _T("Monday &first weekday\tCtrl-F"), |
281 | _T("Toggle between Mon and Sun as the first week day"), | |
9230b621 | 282 | true); |
9f84eccd MB |
283 | menuCal->Append(Calendar_Cal_Holidays, _T("Show &holidays\tCtrl-H"), |
284 | _T("Toggle highlighting the holidays"), | |
9230b621 | 285 | true); |
9f84eccd MB |
286 | menuCal->Append(Calendar_Cal_Special, _T("Highlight &special dates\tCtrl-S"), |
287 | _T("Test custom highlighting"), | |
9230b621 | 288 | true); |
37df1f33 | 289 | menuCal->Append(Calendar_Cal_SurroundWeeks, |
9f84eccd MB |
290 | _T("Show s&urrounding weeks\tCtrl-W"), |
291 | _T("Show the neighbouring weeks in the prev/next month"), | |
9230b621 | 292 | true); |
bc385ba9 | 293 | menuCal->AppendSeparator(); |
37df1f33 | 294 | menuCal->Append(Calendar_Cal_SeqMonth, |
9f84eccd MB |
295 | _T("To&ggle month selector style\tCtrl-G"), |
296 | _T("Use another style for the calendar controls"), | |
9230b621 | 297 | true); |
9f84eccd MB |
298 | menuCal->Append(Calendar_Cal_Month, _T("&Month can be changed\tCtrl-M"), |
299 | _T("Allow changing the month in the calendar"), | |
9230b621 | 300 | true); |
9f84eccd MB |
301 | menuCal->Append(Calendar_Cal_Year, _T("&Year can be changed\tCtrl-Y"), |
302 | _T("Allow changing the year in the calendar"), | |
9230b621 | 303 | true); |
605dfd91 | 304 | menuCal->AppendSeparator(); |
529b7f71 JS |
305 | menuCal->Append(Calendar_Cal_SetDate, _T("SetDate()"), _T("Set date to 2005-12-24.")); |
306 | menuCal->Append(Calendar_Cal_Today, _T("Today()"), _T("Set the current date.")); | |
74a533f7 VZ |
307 | |
308 | // now append the freshly created menu to the menu bar... | |
309 | wxMenuBar *menuBar = new wxMenuBar; | |
9f84eccd MB |
310 | menuBar->Append(menuFile, _T("&File")); |
311 | menuBar->Append(menuCal, _T("&Calendar")); | |
74a533f7 | 312 | |
9230b621 VS |
313 | menuBar->Check(Calendar_Cal_Monday, true); |
314 | menuBar->Check(Calendar_Cal_Holidays, true); | |
315 | menuBar->Check(Calendar_Cal_Month, true); | |
316 | menuBar->Check(Calendar_Cal_Year, true); | |
74a533f7 VZ |
317 | |
318 | // ... and attach this menu bar to the frame | |
319 | SetMenuBar(menuBar); | |
320 | ||
321 | m_panel = new MyPanel(this); | |
322 | ||
323 | #if wxUSE_STATUSBAR | |
324 | // create a status bar just for fun (by default with 1 pane only) | |
9898fcda | 325 | CreateStatusBar(2); |
be5a51fb | 326 | SetStatusText(_T("Welcome to wxWidgets!")); |
74a533f7 VZ |
327 | #endif // wxUSE_STATUSBAR |
328 | } | |
329 | ||
330 | void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event)) | |
331 | { | |
5014bb3a | 332 | // true is to force the frame to close |
9230b621 | 333 | Close(true); |
74a533f7 VZ |
334 | } |
335 | ||
336 | void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event)) | |
337 | { | |
749bfe9a | 338 | wxMessageBox(_T("wxCalendarCtrl sample\n(c) 2000 Vadim Zeitlin"), |
74a533f7 VZ |
339 | _T("About Calendar"), wxOK | wxICON_INFORMATION, this); |
340 | } | |
341 | ||
342 | void MyFrame::OnCalMonday(wxCommandEvent& event) | |
343 | { | |
37df1f33 VZ |
344 | bool enable = GetMenuBar()->IsChecked(event.GetId()); |
345 | ||
346 | m_panel->ToggleCalStyle(enable, wxCAL_MONDAY_FIRST); | |
74a533f7 VZ |
347 | } |
348 | ||
349 | void MyFrame::OnCalHolidays(wxCommandEvent& event) | |
350 | { | |
89a0a322 | 351 | bool enable = GetMenuBar()->IsChecked(event.GetId()); |
37df1f33 | 352 | |
bc385ba9 | 353 | m_panel->GetCal()->EnableHolidayDisplay(enable); |
74a533f7 VZ |
354 | } |
355 | ||
356 | void MyFrame::OnCalSpecial(wxCommandEvent& event) | |
357 | { | |
89a0a322 | 358 | m_panel->HighlightSpecial(GetMenuBar()->IsChecked(event.GetId())); |
bc385ba9 VZ |
359 | } |
360 | ||
361 | void MyFrame::OnCalAllowMonth(wxCommandEvent& event) | |
362 | { | |
89a0a322 | 363 | bool allow = GetMenuBar()->IsChecked(event.GetId()); |
bc385ba9 VZ |
364 | |
365 | m_panel->GetCal()->EnableMonthChange(allow); | |
366 | } | |
367 | ||
368 | void MyFrame::OnCalAllowYear(wxCommandEvent& event) | |
369 | { | |
89a0a322 | 370 | bool allow = GetMenuBar()->IsChecked(event.GetId()); |
bc385ba9 VZ |
371 | |
372 | m_panel->GetCal()->EnableYearChange(allow); | |
373 | } | |
374 | ||
37df1f33 VZ |
375 | void MyFrame::OnCalSeqMonth(wxCommandEvent& event) |
376 | { | |
377 | bool allow = GetMenuBar()->IsChecked(event.GetId()); | |
378 | ||
379 | m_panel->ToggleCalStyle(allow, wxCAL_SEQUENTIAL_MONTH_SELECTION); | |
380 | } | |
381 | ||
382 | void MyFrame::OnCalShowSurroundingWeeks(wxCommandEvent& event) | |
383 | { | |
384 | bool allow = GetMenuBar()->IsChecked(event.GetId()); | |
385 | ||
386 | m_panel->ToggleCalStyle(allow, wxCAL_SHOW_SURROUNDING_WEEKS); | |
387 | } | |
388 | ||
bc385ba9 VZ |
389 | void MyFrame::OnAllowYearUpdate(wxUpdateUIEvent& event) |
390 | { | |
391 | event.Enable( GetMenuBar()->IsChecked(Calendar_Cal_Month)); | |
74a533f7 VZ |
392 | } |
393 | ||
87728739 | 394 | void MyFrame::OnSetDate(wxCommandEvent &WXUNUSED(event)) |
605dfd91 JS |
395 | { |
396 | m_panel->SetDate(); | |
397 | } | |
398 | ||
87728739 | 399 | void MyFrame::OnToday(wxCommandEvent &WXUNUSED(event)) |
605dfd91 JS |
400 | { |
401 | m_panel->Today(); | |
402 | } | |
403 | ||
ac78ab7b | 404 | #if wxUSE_DATEPICKCTRL |
feb72429 VZ |
405 | |
406 | void MyFrame::OnAskDate(wxCommandEvent& WXUNUSED(event)) | |
407 | { | |
408 | MyDialog dlg(this, m_panel->GetCal()->GetDate()); | |
409 | if ( dlg.ShowModal() == wxID_OK ) | |
410 | { | |
411 | const wxDateTime dt = dlg.GetDate(), | |
412 | today = wxDateTime::Today(); | |
413 | ||
414 | if ( dt.GetDay() == today.GetDay() && | |
415 | dt.GetMonth() == today.GetMonth() ) | |
416 | { | |
417 | wxMessageBox(_T("Happy birthday!"), _T("Calendar Sample")); | |
418 | } | |
419 | ||
420 | m_panel->GetCal()->SetDate(dt); | |
421 | ||
422 | wxLogStatus(_T("Changed the date to your birthday")); | |
423 | } | |
424 | } | |
425 | ||
ac78ab7b | 426 | #endif // wxUSE_DATEPICKCTRL |
feb72429 | 427 | |
74a533f7 VZ |
428 | // ---------------------------------------------------------------------------- |
429 | // MyPanel | |
430 | // ---------------------------------------------------------------------------- | |
431 | ||
432 | MyPanel::MyPanel(wxFrame *frame) | |
9230b621 | 433 | : wxPanel(frame, wxID_ANY) |
74a533f7 | 434 | { |
4e6bceff | 435 | wxString date; |
4693b20c | 436 | date.Printf(wxT("Selected date: %s"), |
74a533f7 | 437 | wxDateTime::Today().FormatISODate().c_str()); |
9230b621 | 438 | m_date = new wxStaticText(this, wxID_ANY, date); |
74a533f7 VZ |
439 | m_calendar = new wxCalendarCtrl(this, Calendar_CalCtrl, |
440 | wxDefaultDateTime, | |
441 | wxDefaultPosition, | |
442 | wxDefaultSize, | |
bc385ba9 VZ |
443 | wxCAL_MONDAY_FIRST | |
444 | wxCAL_SHOW_HOLIDAYS | | |
445 | wxRAISED_BORDER); | |
74a533f7 | 446 | |
9230b621 | 447 | wxBoxSizer *m_sizer = new wxBoxSizer( wxHORIZONTAL ); |
4e6bceff | 448 | |
9230b621 VS |
449 | m_sizer->Add(m_date, 0, wxALIGN_CENTER | wxALL, 10 ); |
450 | m_sizer->Add(m_calendar, 0, wxALIGN_CENTER | wxALIGN_LEFT); | |
4e6bceff | 451 | |
9230b621 VS |
452 | SetSizer( m_sizer ); |
453 | m_sizer->SetSizeHints( this ); | |
74a533f7 VZ |
454 | } |
455 | ||
456 | void MyPanel::OnCalendar(wxCalendarEvent& event) | |
457 | { | |
4693b20c | 458 | wxLogMessage(wxT("Selected %s from calendar"), |
74a533f7 VZ |
459 | event.GetDate().FormatISODate().c_str()); |
460 | } | |
461 | ||
462 | void MyPanel::OnCalendarChange(wxCalendarEvent& event) | |
463 | { | |
464 | wxString s; | |
4693b20c | 465 | s.Printf(wxT("Selected date: %s"), event.GetDate().FormatISODate().c_str()); |
74a533f7 VZ |
466 | |
467 | m_date->SetLabel(s); | |
468 | } | |
469 | ||
0de868d9 VZ |
470 | void MyPanel::OnCalMonthChange(wxCalendarEvent& WXUNUSED(event)) |
471 | { | |
4693b20c | 472 | wxLogStatus(wxT("Calendar month changed")); |
0de868d9 VZ |
473 | } |
474 | ||
475 | void MyPanel::OnCalYearChange(wxCalendarEvent& WXUNUSED(event)) | |
476 | { | |
4693b20c | 477 | wxLogStatus(wxT("Calendar year changed")); |
0de868d9 VZ |
478 | } |
479 | ||
74a533f7 VZ |
480 | void MyPanel::OnCalendarWeekDayClick(wxCalendarEvent& event) |
481 | { | |
4693b20c | 482 | wxLogMessage(wxT("Clicked on %s"), |
74a533f7 VZ |
483 | wxDateTime::GetWeekDayName(event.GetWeekDay()).c_str()); |
484 | } | |
485 | ||
37df1f33 | 486 | void MyPanel::ToggleCalStyle(bool on, int flag) |
74a533f7 VZ |
487 | { |
488 | long style = m_calendar->GetWindowStyle(); | |
489 | if ( on ) | |
37df1f33 | 490 | style |= flag; |
74a533f7 | 491 | else |
37df1f33 | 492 | style &= ~flag; |
74a533f7 VZ |
493 | |
494 | m_calendar->SetWindowStyle(style); | |
495 | ||
496 | m_calendar->Refresh(); | |
497 | } | |
498 | ||
74a533f7 VZ |
499 | void MyPanel::HighlightSpecial(bool on) |
500 | { | |
501 | if ( on ) | |
502 | { | |
503 | wxCalendarDateAttr | |
504 | *attrRedCircle = new wxCalendarDateAttr(wxCAL_BORDER_ROUND, *wxRED), | |
505 | *attrGreenSquare = new wxCalendarDateAttr(wxCAL_BORDER_SQUARE, *wxGREEN), | |
506 | *attrHeaderLike = new wxCalendarDateAttr(*wxBLUE, *wxLIGHT_GREY); | |
507 | ||
508 | m_calendar->SetAttr(17, attrRedCircle); | |
509 | m_calendar->SetAttr(29, attrGreenSquare); | |
510 | m_calendar->SetAttr(13, attrHeaderLike); | |
511 | } | |
512 | else // off | |
513 | { | |
514 | m_calendar->ResetAttr(17); | |
515 | m_calendar->ResetAttr(29); | |
516 | m_calendar->ResetAttr(13); | |
517 | } | |
518 | ||
519 | m_calendar->Refresh(); | |
520 | } | |
605dfd91 JS |
521 | |
522 | void MyPanel::SetDate() | |
523 | { | |
524 | wxDateTime date(24, wxDateTime::Dec, 2005, 23, 59, 59); | |
525 | m_calendar->SetDate(date); | |
526 | } | |
527 | ||
528 | void MyPanel::Today() | |
529 | { | |
530 | m_calendar->SetDate(wxDateTime::Today()); | |
531 | } | |
feb72429 VZ |
532 | |
533 | // ---------------------------------------------------------------------------- | |
534 | // MyDialog | |
535 | // ---------------------------------------------------------------------------- | |
536 | ||
ac78ab7b | 537 | #if wxUSE_DATEPICKCTRL |
feb72429 VZ |
538 | |
539 | MyDialog::MyDialog(wxWindow *parent, const wxDateTime& dt) | |
540 | : wxDialog(parent, -1, wxString(_T("Calendar: Choose a date"))) | |
541 | { | |
542 | wxStdDialogButtonSizer *sizerBtns = new wxStdDialogButtonSizer; | |
543 | sizerBtns->AddButton(new wxButton(this, wxID_OK)); | |
544 | sizerBtns->AddButton(new wxButton(this, wxID_CANCEL)); | |
545 | sizerBtns->Finalise(); | |
546 | ||
547 | wxSizer *sizerText = new wxBoxSizer(wxHORIZONTAL); | |
548 | sizerText->Add(new wxStaticText(this, -1, _T("Date in ISO format: ")), | |
549 | wxSizerFlags().Border()); | |
550 | m_text = new wxTextCtrl(this, -1); | |
551 | sizerText->Add(m_text, wxSizerFlags().Expand().Border()); | |
552 | ||
553 | wxSizer *sizerTop = new wxBoxSizer(wxVERTICAL); | |
554 | sizerTop->Add(new wxStaticText | |
555 | ( | |
556 | this, -1, | |
557 | _T("Enter your birthday date (not before 20th century):") | |
558 | ), | |
559 | wxSizerFlags().Border()); | |
560 | ||
561 | m_datePicker = new wxDatePickerCtrl(this, -1, dt); | |
562 | m_datePicker->SetRange(wxDateTime(1, wxDateTime::Jan, 1900), | |
563 | wxDefaultDateTime); | |
564 | sizerTop->Add(m_datePicker, wxSizerFlags().Expand().Border()); | |
565 | ||
566 | sizerTop->AddStretchSpacer(1); | |
567 | sizerTop->Add(sizerText); | |
568 | ||
569 | sizerTop->Add(sizerBtns, wxSizerFlags().Centre().Border()); | |
570 | ||
571 | SetSizerAndFit(sizerTop); | |
572 | Layout(); | |
573 | } | |
574 | ||
575 | void MyDialog::OnDateChange(wxDateEvent& event) | |
576 | { | |
577 | m_text->SetValue(event.GetDate().FormatISODate()); | |
578 | } | |
579 | ||
ac78ab7b | 580 | #endif // wxUSE_DATEPICKCTRL |
feb72429 | 581 |