fixes for wxDP_ALLOWNONE case
[wxWidgets.git] / samples / calendar / calendar.cpp
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 #if defined(__GNUG__) && !defined(__APPLE__)
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
33 #ifndef WX_PRECOMP
34 #include "wx/app.h"
35 #include "wx/log.h"
36 #include "wx/frame.h"
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"
42 #endif
43
44 #include "wx/sizer.h"
45 #include "wx/textctrl.h"
46
47 #include "wx/calctrl.h"
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
55
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
62 // ----------------------------------------------------------------------------
63 // private classes
64 // ----------------------------------------------------------------------------
65
66 // Define a new application type, each program should derive a class from wxApp
67 class MyApp : public wxApp
68 {
69 public:
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
79 class MyPanel : public wxPanel
80 {
81 public:
82 MyPanel(wxFrame *frame);
83
84 void OnCalendar(wxCalendarEvent& event);
85 void OnCalendarWeekDayClick(wxCalendarEvent& event);
86 void OnCalendarChange(wxCalendarEvent& event);
87 void OnCalMonthChange(wxCalendarEvent& event);
88 void OnCalYearChange(wxCalendarEvent& event);
89
90 wxCalendarCtrl *GetCal() const { return m_calendar; }
91
92 // turn on/off the specified style bit on the calendar control
93 void ToggleCalStyle(bool on, int style);
94
95 void HighlightSpecial(bool on);
96
97 void SetDate();
98 void Today();
99
100 private:
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
108 class MyFrame : public wxFrame
109 {
110 public:
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
118 #if wxUSE_DATEPICKCTRL
119 void OnAskDate(wxCommandEvent& event);
120 #endif // wxUSE_DATEPICKCTRL
121
122 void OnCalMonday(wxCommandEvent& event);
123 void OnCalHolidays(wxCommandEvent& event);
124 void OnCalSpecial(wxCommandEvent& event);
125
126 void OnCalAllowMonth(wxCommandEvent& event);
127 void OnCalAllowYear(wxCommandEvent& event);
128
129 void OnCalSeqMonth(wxCommandEvent& event);
130 void OnCalShowSurroundingWeeks(wxCommandEvent& event);
131
132 void OnSetDate(wxCommandEvent& event);
133 void OnToday(wxCommandEvent& event);
134
135 void OnAllowYearUpdate(wxUpdateUIEvent& event);
136
137 private:
138 MyPanel *m_panel;
139
140 // any class wishing to process wxWidgets events must use this macro
141 DECLARE_EVENT_TABLE()
142 };
143
144 #if wxUSE_DATEPICKCTRL
145
146 // Define a simple modal dialog which asks the user for a date
147 class MyDialog : public wxDialog
148 {
149 public:
150 MyDialog(wxWindow *parent, const wxDateTime& dt, int dtpStyle);
151
152 wxDateTime GetDate() const { return m_datePicker->GetValue(); }
153
154 private:
155 void OnDateChange(wxDateEvent& event);
156
157
158 wxDatePickerCtrlBase *m_datePicker;
159 wxTextCtrl *m_text;
160
161
162 DECLARE_EVENT_TABLE()
163 };
164
165 #endif // wxUSE_DATEPICKCTRL
166
167 // ----------------------------------------------------------------------------
168 // constants
169 // ----------------------------------------------------------------------------
170
171 // IDs for the controls and the menu commands
172 enum
173 {
174 // menu items
175 Calendar_File_About = wxID_ABOUT,
176 Calendar_File_Quit = wxID_EXIT,
177 Calendar_Cal_Monday = 200,
178 Calendar_Cal_Holidays,
179 Calendar_Cal_Special,
180 Calendar_Cal_Month,
181 Calendar_Cal_Year,
182 Calendar_Cal_SeqMonth,
183 Calendar_Cal_SurroundWeeks,
184 Calendar_Cal_SetDate,
185 Calendar_Cal_Today,
186 #if wxUSE_DATEPICKCTRL
187 Calendar_DatePicker_AskDate = 300,
188 Calendar_DatePicker_ShowCentury,
189 Calendar_DatePicker_DropDown,
190 Calendar_DatePicker_AllowNone,
191 #if wxUSE_DATEPICKCTRL_GENERIC
192 Calendar_DatePicker_Generic,
193 #endif // wxUSE_DATEPICKCTRL_GENERIC
194 #endif // wxUSE_DATEPICKCTRL
195 Calendar_CalCtrl = 1000
196 };
197
198 // ----------------------------------------------------------------------------
199 // event tables and other macros for wxWidgets
200 // ----------------------------------------------------------------------------
201
202 // the event tables connect the wxWidgets events with the functions (event
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.
205 BEGIN_EVENT_TABLE(MyFrame, wxFrame)
206 EVT_MENU(Calendar_File_Quit, MyFrame::OnQuit)
207 EVT_MENU(Calendar_File_About, MyFrame::OnAbout)
208
209 #if wxUSE_DATEPICKCTRL
210 EVT_MENU(Calendar_DatePicker_AskDate, MyFrame::OnAskDate)
211 #endif // wxUSE_DATEPICKCTRL
212
213 EVT_MENU(Calendar_Cal_Monday, MyFrame::OnCalMonday)
214 EVT_MENU(Calendar_Cal_Holidays, MyFrame::OnCalHolidays)
215 EVT_MENU(Calendar_Cal_Special, MyFrame::OnCalSpecial)
216
217 EVT_MENU(Calendar_Cal_Month, MyFrame::OnCalAllowMonth)
218 EVT_MENU(Calendar_Cal_Year, MyFrame::OnCalAllowYear)
219
220 EVT_MENU(Calendar_Cal_SeqMonth, MyFrame::OnCalSeqMonth)
221 EVT_MENU(Calendar_Cal_SurroundWeeks, MyFrame::OnCalShowSurroundingWeeks)
222
223 EVT_MENU(Calendar_Cal_SetDate, MyFrame::OnSetDate)
224 EVT_MENU(Calendar_Cal_Today, MyFrame::OnToday)
225
226
227 EVT_UPDATE_UI(Calendar_Cal_Year, MyFrame::OnAllowYearUpdate)
228 END_EVENT_TABLE()
229
230 BEGIN_EVENT_TABLE(MyPanel, wxPanel)
231 EVT_CALENDAR (Calendar_CalCtrl, MyPanel::OnCalendar)
232 EVT_CALENDAR_MONTH (Calendar_CalCtrl, MyPanel::OnCalMonthChange)
233 EVT_CALENDAR_YEAR (Calendar_CalCtrl, MyPanel::OnCalYearChange)
234 EVT_CALENDAR_SEL_CHANGED(Calendar_CalCtrl, MyPanel::OnCalendarChange)
235 EVT_CALENDAR_WEEKDAY_CLICKED(Calendar_CalCtrl, MyPanel::OnCalendarWeekDayClick)
236 END_EVENT_TABLE()
237
238 #if wxUSE_DATEPICKCTRL
239
240 BEGIN_EVENT_TABLE(MyDialog, wxDialog)
241 EVT_DATE_CHANGED(wxID_ANY, MyDialog::OnDateChange)
242 END_EVENT_TABLE()
243
244 #endif // wxUSE_DATEPICKCTRL
245
246 // Create a new application object: this macro will allow wxWidgets to create
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)
251 IMPLEMENT_APP(MyApp)
252
253 // ============================================================================
254 // implementation
255 // ============================================================================
256
257 // ----------------------------------------------------------------------------
258 // the application class
259 // ----------------------------------------------------------------------------
260
261 // `Main program' equivalent: the program execution "starts" here
262 bool MyApp::OnInit()
263 {
264 // Create the main application window
265 MyFrame *frame = new MyFrame(_T("Calendar wxWidgets sample"),
266 wxPoint(50, 50), wxSize(450, 340));
267
268 frame->Show(true);
269
270 // success: wxApp::OnRun() will be called which will enter the main message
271 // loop and the application will run. If we returned false here, the
272 // application would exit immediately.
273 return true;
274 }
275
276 // ----------------------------------------------------------------------------
277 // main frame
278 // ----------------------------------------------------------------------------
279
280 // frame constructor
281 MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
282 : wxFrame((wxFrame *)NULL, wxID_ANY, title, pos, size)
283 {
284 // set the frame icon
285 SetIcon(wxICON(sample));
286
287 // create a menu bar
288 wxMenu *menuFile = new wxMenu;
289 menuFile->Append(Calendar_File_About, _T("&About...\tCtrl-A"), _T("Show about dialog"));
290 menuFile->AppendSeparator();
291 menuFile->Append(Calendar_File_Quit, _T("E&xit\tAlt-X"), _T("Quit this program"));
292
293 wxMenu *menuCal = new wxMenu;
294 menuCal->Append(Calendar_Cal_Monday,
295 _T("Monday &first weekday\tCtrl-F"),
296 _T("Toggle between Mon and Sun as the first week day"),
297 true);
298 menuCal->Append(Calendar_Cal_Holidays, _T("Show &holidays\tCtrl-H"),
299 _T("Toggle highlighting the holidays"),
300 true);
301 menuCal->Append(Calendar_Cal_Special, _T("Highlight &special dates\tCtrl-S"),
302 _T("Test custom highlighting"),
303 true);
304 menuCal->Append(Calendar_Cal_SurroundWeeks,
305 _T("Show s&urrounding weeks\tCtrl-W"),
306 _T("Show the neighbouring weeks in the prev/next month"),
307 true);
308 menuCal->AppendSeparator();
309 menuCal->Append(Calendar_Cal_SeqMonth,
310 _T("To&ggle month selector style\tCtrl-G"),
311 _T("Use another style for the calendar controls"),
312 true);
313 menuCal->Append(Calendar_Cal_Month, _T("&Month can be changed\tCtrl-M"),
314 _T("Allow changing the month in the calendar"),
315 true);
316 menuCal->Append(Calendar_Cal_Year, _T("&Year can be changed\tCtrl-Y"),
317 _T("Allow changing the year in the calendar"),
318 true);
319 menuCal->AppendSeparator();
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."));
322
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"));
329 menuDate->AppendCheckItem(Calendar_DatePicker_AllowNone,
330 _T("Allow &no date"));
331 #if wxUSE_DATEPICKCTRL_GENERIC
332 menuDate->AppendCheckItem(Calendar_DatePicker_Generic,
333 _T("Use &generic version of the control"));
334 #endif // wxUSE_DATEPICKCTRL_GENERIC
335 menuDate->AppendSeparator();
336 menuDate->Append(Calendar_DatePicker_AskDate, _T("&Choose date...\tCtrl-D"), _T("Show dialog with wxDatePickerCtrl"));
337 #endif // wxUSE_DATEPICKCTRL
338
339 // now append the freshly created menu to the menu bar...
340 wxMenuBar *menuBar = new wxMenuBar;
341 menuBar->Append(menuFile, _T("&File"));
342 menuBar->Append(menuCal, _T("&Calendar"));
343 #if wxUSE_DATEPICKCTRL
344 menuBar->Append(menuDate, _T("&Date picker"));
345 #endif // wxUSE_DATEPICKCTRL
346
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);
351
352 #if wxUSE_DATEPICKCTRL
353 menuBar->Check(Calendar_DatePicker_ShowCentury, true);
354 #endif // wxUSE_DATEPICKCTRL
355
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)
363 CreateStatusBar(2);
364 SetStatusText(_T("Welcome to wxWidgets!"));
365 #endif // wxUSE_STATUSBAR
366 }
367
368 void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
369 {
370 // true is to force the frame to close
371 Close(true);
372 }
373
374 void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
375 {
376 wxMessageBox(_T("wxCalendarCtrl sample\n(c) 2000 Vadim Zeitlin"),
377 _T("About Calendar"), wxOK | wxICON_INFORMATION, this);
378 }
379
380 void MyFrame::OnCalMonday(wxCommandEvent& event)
381 {
382 bool enable = GetMenuBar()->IsChecked(event.GetId());
383
384 m_panel->ToggleCalStyle(enable, wxCAL_MONDAY_FIRST);
385 }
386
387 void MyFrame::OnCalHolidays(wxCommandEvent& event)
388 {
389 bool enable = GetMenuBar()->IsChecked(event.GetId());
390
391 m_panel->GetCal()->EnableHolidayDisplay(enable);
392 }
393
394 void MyFrame::OnCalSpecial(wxCommandEvent& event)
395 {
396 m_panel->HighlightSpecial(GetMenuBar()->IsChecked(event.GetId()));
397 }
398
399 void MyFrame::OnCalAllowMonth(wxCommandEvent& event)
400 {
401 bool allow = GetMenuBar()->IsChecked(event.GetId());
402
403 m_panel->GetCal()->EnableMonthChange(allow);
404 }
405
406 void MyFrame::OnCalAllowYear(wxCommandEvent& event)
407 {
408 bool allow = GetMenuBar()->IsChecked(event.GetId());
409
410 m_panel->GetCal()->EnableYearChange(allow);
411 }
412
413 void MyFrame::OnCalSeqMonth(wxCommandEvent& event)
414 {
415 bool allow = GetMenuBar()->IsChecked(event.GetId());
416
417 m_panel->ToggleCalStyle(allow, wxCAL_SEQUENTIAL_MONTH_SELECTION);
418 }
419
420 void MyFrame::OnCalShowSurroundingWeeks(wxCommandEvent& event)
421 {
422 bool allow = GetMenuBar()->IsChecked(event.GetId());
423
424 m_panel->ToggleCalStyle(allow, wxCAL_SHOW_SURROUNDING_WEEKS);
425 }
426
427 void MyFrame::OnAllowYearUpdate(wxUpdateUIEvent& event)
428 {
429 event.Enable( GetMenuBar()->IsChecked(Calendar_Cal_Month));
430 }
431
432 void MyFrame::OnSetDate(wxCommandEvent &WXUNUSED(event))
433 {
434 m_panel->SetDate();
435 }
436
437 void MyFrame::OnToday(wxCommandEvent &WXUNUSED(event))
438 {
439 m_panel->Today();
440 }
441
442 #if wxUSE_DATEPICKCTRL
443
444 void MyFrame::OnAskDate(wxCommandEvent& WXUNUSED(event))
445 {
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;
451 if ( GetMenuBar()->IsChecked(Calendar_DatePicker_AllowNone) )
452 style |= wxDP_ALLOWNONE;
453
454 MyDialog dlg(this, m_panel->GetCal()->GetDate(), style);
455 if ( dlg.ShowModal() == wxID_OK )
456 {
457 const wxDateTime dt = dlg.GetDate();
458 if ( dt.IsValid() )
459 {
460 const wxDateTime today = wxDateTime::Today();
461
462 if ( dt.GetDay() == today.GetDay() &&
463 dt.GetMonth() == today.GetMonth() )
464 {
465 wxMessageBox(_T("Happy birthday!"), _T("Calendar Sample"));
466 }
467
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 }
476 }
477 }
478
479 #endif // wxUSE_DATEPICKCTRL
480
481 // ----------------------------------------------------------------------------
482 // MyPanel
483 // ----------------------------------------------------------------------------
484
485 MyPanel::MyPanel(wxFrame *frame)
486 : wxPanel(frame, wxID_ANY)
487 {
488 wxString date;
489 date.Printf(wxT("Selected date: %s"),
490 wxDateTime::Today().FormatISODate().c_str());
491 m_date = new wxStaticText(this, wxID_ANY, date);
492 m_calendar = new wxCalendarCtrl(this, Calendar_CalCtrl,
493 wxDefaultDateTime,
494 wxDefaultPosition,
495 wxDefaultSize,
496 wxCAL_MONDAY_FIRST |
497 wxCAL_SHOW_HOLIDAYS |
498 wxRAISED_BORDER);
499
500 wxBoxSizer *m_sizer = new wxBoxSizer( wxHORIZONTAL );
501
502 m_sizer->Add(m_date, 0, wxALIGN_CENTER | wxALL, 10 );
503 m_sizer->Add(m_calendar, 0, wxALIGN_CENTER | wxALIGN_LEFT);
504
505 SetSizer( m_sizer );
506 m_sizer->SetSizeHints( this );
507 }
508
509 void MyPanel::OnCalendar(wxCalendarEvent& event)
510 {
511 wxLogMessage(wxT("Selected %s from calendar"),
512 event.GetDate().FormatISODate().c_str());
513 }
514
515 void MyPanel::OnCalendarChange(wxCalendarEvent& event)
516 {
517 wxString s;
518 s.Printf(wxT("Selected date: %s"), event.GetDate().FormatISODate().c_str());
519
520 m_date->SetLabel(s);
521 }
522
523 void MyPanel::OnCalMonthChange(wxCalendarEvent& WXUNUSED(event))
524 {
525 wxLogStatus(wxT("Calendar month changed"));
526 }
527
528 void MyPanel::OnCalYearChange(wxCalendarEvent& WXUNUSED(event))
529 {
530 wxLogStatus(wxT("Calendar year changed"));
531 }
532
533 void MyPanel::OnCalendarWeekDayClick(wxCalendarEvent& event)
534 {
535 wxLogMessage(wxT("Clicked on %s"),
536 wxDateTime::GetWeekDayName(event.GetWeekDay()).c_str());
537 }
538
539 void MyPanel::ToggleCalStyle(bool on, int flag)
540 {
541 long style = m_calendar->GetWindowStyle();
542 if ( on )
543 style |= flag;
544 else
545 style &= ~flag;
546
547 m_calendar->SetWindowStyle(style);
548
549 m_calendar->Refresh();
550 }
551
552 void 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 }
574
575 void MyPanel::SetDate()
576 {
577 wxDateTime date(24, wxDateTime::Dec, 2005, 23, 59, 59);
578 m_calendar->SetDate(date);
579 }
580
581 void MyPanel::Today()
582 {
583 m_calendar->SetDate(wxDateTime::Today());
584 }
585
586 // ----------------------------------------------------------------------------
587 // MyDialog
588 // ----------------------------------------------------------------------------
589
590 #if wxUSE_DATEPICKCTRL
591
592 MyDialog::MyDialog(wxWindow *parent, const wxDateTime& dt, int dtpStyle)
593 : wxDialog(parent, -1, wxString(_T("Calendar: Choose a date")))
594 {
595 wxStdDialogButtonSizer *sizerBtns = new wxStdDialogButtonSizer;
596 sizerBtns->AddButton(new wxButton(this, wxID_OK));
597 sizerBtns->AddButton(new wxButton(this, wxID_CANCEL));
598 sizerBtns->Finalise();
599
600 wxSizer *sizerText = new wxBoxSizer(wxHORIZONTAL);
601 sizerText->Add(new wxStaticText(this, -1, _T("Date in ISO format: ")),
602 wxSizerFlags().Border().Align(wxALIGN_CENTRE_VERTICAL));
603 m_text = new wxTextCtrl(this, -1);
604 sizerText->Add(m_text, wxSizerFlags().
605 Expand().Border().Align(wxALIGN_CENTRE_VERTICAL));
606
607 wxSizer *sizerTop = new wxBoxSizer(wxVERTICAL);
608 sizerTop->Add(new wxStaticText
609 (
610 this, -1,
611 _T("Enter your birthday date (not before 20th century):")
612 ),
613 wxSizerFlags().Border());
614
615 #if wxUSE_DATEPICKCTRL_GENERIC
616 wxFrame *frame = (wxFrame *)wxGetTopLevelParent(parent);
617 if ( frame && frame->GetMenuBar()->IsChecked(Calendar_DatePicker_Generic) )
618 m_datePicker = new wxDatePickerCtrlGeneric(this, -1, dt,
619 wxDefaultPosition,
620 wxDefaultSize,
621 dtpStyle);
622 else
623 #endif // wxUSE_DATEPICKCTRL_GENERIC
624 m_datePicker = new wxDatePickerCtrl(this, -1, dt,
625 wxDefaultPosition, wxDefaultSize,
626 dtpStyle);
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
640 void MyDialog::OnDateChange(wxDateEvent& event)
641 {
642 const wxDateTime dt = event.GetDate();
643 m_text->SetValue(dt.IsValid()? dt.FormatISODate() : wxString());
644 }
645
646 #endif // wxUSE_DATEPICKCTRL
647