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