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