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