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