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