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