1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxCalendarCtrl sample
4 // Author: Vadim Zeitlin
8 // Copyright: (c) Vadim Zeitlin
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx/wx.h".
21 #include "wx/wxprec.h"
27 // for all others, include the necessary headers
33 #include "wx/stattext.h"
35 #include "wx/layout.h"
36 #include "wx/msgdlg.h"
38 #include "wx/button.h"
40 #include "wx/textctrl.h"
41 #include "wx/settings.h"
44 #include "wx/calctrl.h"
45 #include "wx/splitter.h"
47 #if wxUSE_DATEPICKCTRL
48 #include "wx/datectrl.h"
49 #if wxUSE_DATEPICKCTRL_GENERIC
50 #include "wx/generic/datectrl.h"
51 #endif // wxUSE_DATEPICKCTRL_GENERIC
52 #endif // wxUSE_DATEPICKCTRL
54 #include "../sample.xpm"
56 #ifdef wxHAS_NATIVE_CALENDARCTRL
57 #include "wx/generic/calctrlg.h"
60 // ----------------------------------------------------------------------------
62 // ----------------------------------------------------------------------------
64 // Define a new application type, each program should derive a class from wxApp
65 class MyApp
: public wxApp
68 // override base class virtuals
69 // ----------------------------
71 // this one is called on application startup and is a good place for the app
72 // initialization (doing it here and not in the ctor allows to have an error
73 // return: if OnInit() returns false, the application terminates)
74 virtual bool OnInit();
77 class MyPanel
: public wxPanel
80 MyPanel(wxWindow
*parent
);
82 void OnCalendar(wxCalendarEvent
& event
);
83 void OnCalendarWeekDayClick(wxCalendarEvent
& event
);
84 void OnCalendarChange(wxCalendarEvent
& event
);
85 void OnCalMonthChange(wxCalendarEvent
& event
);
87 wxCalendarCtrlBase
*GetCal() const { return m_calendar
; }
89 // turn on/off the specified style bit on the calendar control
90 void ToggleCalStyle(bool on
, int style
);
92 bool IsUsingGeneric() const { return m_usingGeneric
; }
93 void ToggleUseGeneric()
95 m_usingGeneric
= !m_usingGeneric
;
96 RecreateCalendar(m_calendar
->GetWindowStyle());
99 void HighlightSpecial(bool on
);
101 wxDateTime
GetDate() const { return m_calendar
->GetDate(); }
102 void SetDate(const wxDateTime
& dt
) { m_calendar
->SetDate(dt
); }
105 void RecreateCalendar(long style
);
107 wxCalendarCtrlBase
*m_calendar
;
108 wxStaticText
*m_date
;
114 DECLARE_EVENT_TABLE()
117 // Define a new frame type: this is going to be our main frame
118 class MyFrame
: public wxFrame
122 MyFrame(const wxString
& title
, const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& size
= wxDefaultSize
);
124 // event handlers (these functions should _not_ be virtual)
125 void OnAbout(wxCommandEvent
& event
);
126 void OnClearLog(wxCommandEvent
& event
);
127 void OnQuit(wxCommandEvent
& event
);
129 #if wxUSE_DATEPICKCTRL
130 void OnAskDate(wxCommandEvent
& event
);
132 void OnUpdateUIStartWithNone(wxUpdateUIEvent
& event
);
133 #endif // wxUSE_DATEPICKCTRL
135 #ifdef wxHAS_NATIVE_CALENDARCTRL
136 void OnCalGeneric(wxCommandEvent
& WXUNUSED(event
))
138 m_panel
->ToggleUseGeneric();
140 #endif // wxHAS_NATIVE_CALENDARCTRL
142 void OnCalMonday(wxCommandEvent
& event
);
143 void OnCalHolidays(wxCommandEvent
& event
);
144 void OnCalSpecial(wxCommandEvent
& event
);
146 void OnCalAllowMonth(wxCommandEvent
& event
);
148 void OnCalSeqMonth(wxCommandEvent
& event
);
149 void OnCalShowSurroundingWeeks(wxCommandEvent
& event
);
151 void OnSetDate(wxCommandEvent
& event
);
152 void OnToday(wxCommandEvent
& event
);
153 void OnBeginDST(wxCommandEvent
& event
);
155 void OnCalToggleResizable(wxCommandEvent
& event
);
157 void OnUpdateUIGenericOnly(wxUpdateUIEvent
& event
)
159 event
.Enable(m_panel
->IsUsingGeneric());
164 wxTextCtrl
*m_logWindow
;
166 // any class wishing to process wxWidgets events must use this macro
167 DECLARE_EVENT_TABLE()
170 #if wxUSE_DATEPICKCTRL
172 // Define a simple modal dialog which asks the user for a date
173 class MyDialog
: public wxDialog
176 MyDialog(wxWindow
*parent
, const wxDateTime
& dt
, int dtpStyle
);
178 wxDateTime
GetDate() const { return m_datePicker
->GetValue(); }
181 void OnDateChange(wxDateEvent
& event
);
184 wxDatePickerCtrlBase
*m_datePicker
;
188 DECLARE_EVENT_TABLE()
191 #endif // wxUSE_DATEPICKCTRL
193 // ----------------------------------------------------------------------------
195 // ----------------------------------------------------------------------------
197 // IDs for the controls and the menu commands
201 Calendar_File_About
= wxID_ABOUT
,
202 Calendar_File_ClearLog
= wxID_CLEAR
,
203 Calendar_File_Quit
= wxID_EXIT
,
204 Calendar_Cal_Generic
= 200,
206 Calendar_Cal_Holidays
,
207 Calendar_Cal_Special
,
209 Calendar_Cal_SeqMonth
,
210 Calendar_Cal_SurroundWeeks
,
211 Calendar_Cal_SetDate
,
213 Calendar_Cal_BeginDST
,
214 Calendar_Cal_Resizable
,
215 #if wxUSE_DATEPICKCTRL
216 Calendar_DatePicker_AskDate
= 300,
217 Calendar_DatePicker_ShowCentury
,
218 Calendar_DatePicker_DropDown
,
219 Calendar_DatePicker_AllowNone
,
220 Calendar_DatePicker_StartWithNone
,
221 #if wxUSE_DATEPICKCTRL_GENERIC
222 Calendar_DatePicker_Generic
,
223 #endif // wxUSE_DATEPICKCTRL_GENERIC
224 #endif // wxUSE_DATEPICKCTRL
225 Calendar_CalCtrl
= 1000
228 // ----------------------------------------------------------------------------
229 // event tables and other macros for wxWidgets
230 // ----------------------------------------------------------------------------
232 // the event tables connect the wxWidgets events with the functions (event
233 // handlers) which process them. It can be also done at run-time, but for the
234 // simple menu events like this the static method is much simpler.
235 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
236 EVT_MENU(Calendar_File_About
, MyFrame
::OnAbout
)
237 EVT_MENU(Calendar_File_ClearLog
, MyFrame
::OnClearLog
)
238 EVT_MENU(Calendar_File_Quit
, MyFrame
::OnQuit
)
240 #if wxUSE_DATEPICKCTRL
241 EVT_MENU(Calendar_DatePicker_AskDate
, MyFrame
::OnAskDate
)
243 EVT_UPDATE_UI(Calendar_DatePicker_StartWithNone
,
244 MyFrame
::OnUpdateUIStartWithNone
)
245 #endif // wxUSE_DATEPICKCTRL
247 #ifdef wxHAS_NATIVE_CALENDARCTRL
248 EVT_MENU(Calendar_Cal_Generic
, MyFrame
::OnCalGeneric
)
249 #endif // wxHAS_NATIVE_CALENDARCTRL
251 EVT_MENU(Calendar_Cal_Monday
, MyFrame
::OnCalMonday
)
252 EVT_MENU(Calendar_Cal_Holidays
, MyFrame
::OnCalHolidays
)
253 EVT_MENU(Calendar_Cal_Special
, MyFrame
::OnCalSpecial
)
255 EVT_MENU(Calendar_Cal_Month
, MyFrame
::OnCalAllowMonth
)
257 EVT_MENU(Calendar_Cal_SeqMonth
, MyFrame
::OnCalSeqMonth
)
258 EVT_MENU(Calendar_Cal_SurroundWeeks
, MyFrame
::OnCalShowSurroundingWeeks
)
260 EVT_MENU(Calendar_Cal_SetDate
, MyFrame
::OnSetDate
)
261 EVT_MENU(Calendar_Cal_Today
, MyFrame
::OnToday
)
262 EVT_MENU(Calendar_Cal_BeginDST
, MyFrame
::OnBeginDST
)
264 EVT_MENU(Calendar_Cal_Resizable
, MyFrame
::OnCalToggleResizable
)
267 EVT_UPDATE_UI(Calendar_Cal_SeqMonth
, MyFrame
::OnUpdateUIGenericOnly
)
268 EVT_UPDATE_UI(Calendar_Cal_Monday
, MyFrame
::OnUpdateUIGenericOnly
)
269 EVT_UPDATE_UI(Calendar_Cal_Holidays
, MyFrame
::OnUpdateUIGenericOnly
)
270 EVT_UPDATE_UI(Calendar_Cal_Special
, MyFrame
::OnUpdateUIGenericOnly
)
271 EVT_UPDATE_UI(Calendar_Cal_SurroundWeeks
, MyFrame
::OnUpdateUIGenericOnly
)
274 BEGIN_EVENT_TABLE(MyPanel
, wxPanel
)
275 EVT_CALENDAR(Calendar_CalCtrl
, MyPanel
::OnCalendar
)
276 EVT_CALENDAR_PAGE_CHANGED(Calendar_CalCtrl
, MyPanel
::OnCalMonthChange
)
277 EVT_CALENDAR_SEL_CHANGED(Calendar_CalCtrl
, MyPanel
::OnCalendarChange
)
278 EVT_CALENDAR_WEEKDAY_CLICKED(Calendar_CalCtrl
, MyPanel
::OnCalendarWeekDayClick
)
281 #if wxUSE_DATEPICKCTRL
283 BEGIN_EVENT_TABLE(MyDialog
, wxDialog
)
284 EVT_DATE_CHANGED(wxID_ANY
, MyDialog
::OnDateChange
)
287 #endif // wxUSE_DATEPICKCTRL
289 // Create a new application object: this macro will allow wxWidgets to create
290 // the application object during program execution (it's better than using a
291 // static object for many reasons) and also declares the accessor function
292 // wxGetApp() which will return the reference of the right type (i.e. MyApp and
296 // ============================================================================
298 // ============================================================================
300 // ----------------------------------------------------------------------------
301 // the application class
302 // ----------------------------------------------------------------------------
304 // `Main program' equivalent: the program execution "starts" here
307 if ( !wxApp
::OnInit() )
310 // Create the main application window
311 MyFrame
*frame
= new MyFrame(_T("Calendar wxWidgets sample")
313 ,wxPoint(50, 50), wxSize(450, 340)
319 // success: wxApp::OnRun() will be called which will enter the main message
320 // loop and the application will run. If we returned false here, the
321 // application would exit immediately.
325 // ----------------------------------------------------------------------------
327 // ----------------------------------------------------------------------------
330 MyFrame
::MyFrame(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
)
331 : wxFrame((wxFrame
*)NULL
, wxID_ANY
, title
, pos
, size
)
333 // set the frame icon
334 SetIcon(wxIcon(sample_xpm
));
337 wxMenu
*menuFile
= new wxMenu
;
338 menuFile
->Append(Calendar_File_About
, _T("&About...\tCtrl-A"), _T("Show about dialog"));
339 menuFile
->AppendSeparator();
340 menuFile
->Append(Calendar_File_ClearLog
, _T("&Clear log\tCtrl-L"));
341 menuFile
->AppendSeparator();
342 menuFile
->Append(Calendar_File_Quit
, _T("E&xit\tAlt-X"), _T("Quit this program"));
344 wxMenu
*menuCal
= new wxMenu
;
345 #ifdef wxHAS_NATIVE_CALENDARCTRL
346 menuCal
->AppendCheckItem(Calendar_Cal_Generic
, "Use &generic version\tCtrl-G",
347 "Toggle between native and generic control");
348 menuCal
->AppendSeparator();
349 #endif // wxHAS_NATIVE_CALENDARCTRL
350 menuCal
->Append(Calendar_Cal_Monday
,
351 _T("Monday &first weekday\tCtrl-F"),
352 _T("Toggle between Mon and Sun as the first week day"),
354 menuCal
->Append(Calendar_Cal_Holidays
, _T("Show &holidays\tCtrl-H"),
355 _T("Toggle highlighting the holidays"),
357 menuCal
->Append(Calendar_Cal_Special
, _T("Highlight &special dates\tCtrl-S"),
358 _T("Test custom highlighting"),
360 menuCal
->Append(Calendar_Cal_SurroundWeeks
,
361 _T("Show s&urrounding weeks\tCtrl-W"),
362 _T("Show the neighbouring weeks in the prev/next month"),
364 menuCal
->AppendSeparator();
365 menuCal
->Append(Calendar_Cal_SeqMonth
,
366 _T("Toggle month selector st&yle\tCtrl-Y"),
367 _T("Use another style for the calendar controls"),
369 menuCal
->Append(Calendar_Cal_Month
, _T("&Month can be changed\tCtrl-M"),
370 _T("Allow changing the month in the calendar"),
372 menuCal
->AppendSeparator();
373 menuCal
->Append(Calendar_Cal_SetDate
, _T("Call &SetDate(2005-12-24)"), _T("Set date to 2005-12-24."));
374 menuCal
->Append(Calendar_Cal_Today
, _T("Call &Today()"), _T("Set to the current date."));
375 menuCal
->Append(Calendar_Cal_BeginDST
, "Call SetDate(GetBeginDST())");
376 menuCal
->AppendSeparator();
377 menuCal
->AppendCheckItem(Calendar_Cal_Resizable
, _T("Make &resizable\tCtrl-R"));
379 #if wxUSE_DATEPICKCTRL
380 wxMenu
*menuDate
= new wxMenu
;
381 menuDate
->AppendCheckItem(Calendar_DatePicker_ShowCentury
,
382 _T("Al&ways show century"));
383 menuDate
->AppendCheckItem(Calendar_DatePicker_DropDown
,
384 _T("Use &drop down control"));
385 menuDate
->AppendCheckItem(Calendar_DatePicker_AllowNone
,
386 _T("Allow &no date"));
387 menuDate
->AppendCheckItem(Calendar_DatePicker_StartWithNone
,
388 _T("Start &with no date"));
389 #if wxUSE_DATEPICKCTRL_GENERIC
390 menuDate
->AppendCheckItem(Calendar_DatePicker_Generic
,
391 _T("Use &generic version of the control"));
392 #endif // wxUSE_DATEPICKCTRL_GENERIC
393 menuDate
->AppendSeparator();
394 menuDate
->Append(Calendar_DatePicker_AskDate
, _T("&Choose date...\tCtrl-D"), _T("Show dialog with wxDatePickerCtrl"));
395 #endif // wxUSE_DATEPICKCTRL
397 // now append the freshly created menu to the menu bar...
398 wxMenuBar
*menuBar
= new wxMenuBar
;
399 menuBar
->Append(menuFile
, _T("&File"));
400 menuBar
->Append(menuCal
, _T("&Calendar"));
401 #if wxUSE_DATEPICKCTRL
402 menuBar
->Append(menuDate
, _T("&Date picker"));
403 #endif // wxUSE_DATEPICKCTRL
405 menuBar
->Check(Calendar_Cal_Monday
, true);
406 menuBar
->Check(Calendar_Cal_Holidays
, true);
407 menuBar
->Check(Calendar_Cal_Month
, true);
409 #if wxUSE_DATEPICKCTRL
410 menuBar
->Check(Calendar_DatePicker_ShowCentury
, true);
411 #endif // wxUSE_DATEPICKCTRL
413 // ... and attach this menu bar to the frame
416 wxSplitterWindow
*splitter
= new wxSplitterWindow(this, wxID_ANY
,
417 wxDefaultPosition
, wxDefaultSize
,
419 m_panel
= new MyPanel(splitter
);
420 m_logWindow
= new wxTextCtrl(splitter
, wxID_ANY
, wxEmptyString
,
421 wxDefaultPosition
, wxDefaultSize
,
422 wxTE_READONLY
| wxTE_MULTILINE
);
423 splitter
->SplitHorizontally(m_panel
, m_logWindow
);
424 splitter
->SetMinimumPaneSize(20);
425 wxLog
::SetActiveTarget(new wxLogTextCtrl(m_logWindow
));
428 void MyFrame
::OnQuit(wxCommandEvent
& WXUNUSED(event
))
430 // true is to force the frame to close
434 void MyFrame
::OnAbout(wxCommandEvent
& WXUNUSED(event
))
436 wxMessageBox(_T("wxCalendarCtrl sample\n(c) 2000--2008 Vadim Zeitlin"),
437 _T("About Calendar"), wxOK
| wxICON_INFORMATION
, this);
440 void MyFrame
::OnClearLog(wxCommandEvent
& WXUNUSED(event
))
442 m_logWindow
->Clear();
445 void MyFrame
::OnCalMonday(wxCommandEvent
& event
)
447 m_panel
->ToggleCalStyle(event
.IsChecked(), wxCAL_MONDAY_FIRST
);
450 void MyFrame
::OnCalHolidays(wxCommandEvent
& event
)
452 m_panel
->GetCal()->EnableHolidayDisplay(event
.IsChecked());
455 void MyFrame
::OnCalSpecial(wxCommandEvent
& event
)
457 m_panel
->HighlightSpecial(GetMenuBar()->IsChecked(event
.GetId()));
460 void MyFrame
::OnCalAllowMonth(wxCommandEvent
& event
)
462 m_panel
->GetCal()->EnableMonthChange(event
.IsChecked());
465 void MyFrame
::OnCalSeqMonth(wxCommandEvent
& event
)
467 m_panel
->ToggleCalStyle(event
.IsChecked(),
468 wxCAL_SEQUENTIAL_MONTH_SELECTION
);
471 void MyFrame
::OnCalShowSurroundingWeeks(wxCommandEvent
& event
)
473 m_panel
->ToggleCalStyle(event
.IsChecked(), wxCAL_SHOW_SURROUNDING_WEEKS
);
476 void MyFrame
::OnSetDate(wxCommandEvent
&WXUNUSED(event
))
478 m_panel
->SetDate(wxDateTime(24, wxDateTime
::Dec
, 2005, 22, 00, 00));
481 void MyFrame
::OnToday(wxCommandEvent
&WXUNUSED(event
))
483 m_panel
->SetDate(wxDateTime
::Today());
486 void MyFrame
::OnBeginDST(wxCommandEvent
&WXUNUSED(event
))
488 m_panel
->SetDate(wxDateTime
::GetBeginDST(m_panel
->GetDate().GetYear()));
491 void MyFrame
::OnCalToggleResizable(wxCommandEvent
& event
)
493 wxSizer
* const sizer
= m_panel
->GetSizer();
494 wxSizerItem
* const item
= sizer
->GetItem(m_panel
->GetCal());
495 if ( event
.IsChecked() )
497 item
->SetProportion(1);
498 item
->SetFlag(wxEXPAND
);
500 else // not resizable
502 item
->SetProportion(0);
503 item
->SetFlag(wxALIGN_CENTER
);
509 #if wxUSE_DATEPICKCTRL
511 void MyFrame
::OnUpdateUIStartWithNone(wxUpdateUIEvent
& event
)
513 // it only makes sense to start with invalid date if we can have no date
514 event
.Enable( GetMenuBar()->IsChecked(Calendar_DatePicker_AllowNone
) );
517 void MyFrame
::OnAskDate(wxCommandEvent
& WXUNUSED(event
))
519 wxDateTime dt
= m_panel
->GetCal()->GetDate();
521 int style
= wxDP_DEFAULT
;
522 if ( GetMenuBar()->IsChecked(Calendar_DatePicker_ShowCentury
) )
523 style
|= wxDP_SHOWCENTURY
;
524 if ( GetMenuBar()->IsChecked(Calendar_DatePicker_DropDown
) )
525 style
|= wxDP_DROPDOWN
;
526 if ( GetMenuBar()->IsChecked(Calendar_DatePicker_AllowNone
) )
528 style
|= wxDP_ALLOWNONE
;
530 if ( GetMenuBar()->IsChecked(Calendar_DatePicker_StartWithNone
) )
531 dt
= wxDefaultDateTime
;
534 MyDialog
dlg(this, dt
, style
);
535 if ( dlg
.ShowModal() == wxID_OK
)
540 const wxDateTime today
= wxDateTime
::Today();
542 if ( dt
.GetDay() == today
.GetDay() &&
543 dt
.GetMonth() == today
.GetMonth() )
545 wxMessageBox(_T("Happy birthday!"), _T("Calendar Sample"));
548 m_panel
->SetDate(dt
);
550 wxLogStatus(_T("Changed the date to your input"));
554 wxLogStatus(_T("No date entered"));
559 #endif // wxUSE_DATEPICKCTRL
561 // ----------------------------------------------------------------------------
563 // ----------------------------------------------------------------------------
565 MyPanel
::MyPanel(wxWindow
*parent
)
566 : wxPanel(parent
, wxID_ANY
)
568 #ifdef wxHAS_NATIVE_CALENDARCTRL
569 m_usingGeneric
= false;
571 m_usingGeneric
= true;
575 date
.Printf(wxT("Selected date: %s"),
576 wxDateTime
::Today().FormatISODate().c_str());
577 m_date
= new wxStaticText(this, wxID_ANY
, date
);
578 m_calendar
= new wxCalendarCtrl(this, Calendar_CalCtrl
,
583 wxCAL_SHOW_HOLIDAYS
|
586 // adjust to vertical/horizontal display, check mostly dedicated to WinCE
587 bool horizontal
= ( wxSystemSettings
::GetMetric(wxSYS_SCREEN_X
) > wxSystemSettings
::GetMetric(wxSYS_SCREEN_Y
) );
588 m_sizer
= new wxBoxSizer( horizontal ? wxHORIZONTAL
: wxVERTICAL
);
590 m_sizer
->Add(m_date
, 0, wxALIGN_CENTER
| wxALL
, 10 );
591 m_sizer
->Add(m_calendar
, 0, wxALIGN_CENTER
| wxALIGN_LEFT
);
594 m_sizer
->SetSizeHints( this );
597 void MyPanel
::OnCalendar(wxCalendarEvent
& event
)
599 m_calendar
->Mark(event
.GetDate().GetDay(), true);
600 wxLogMessage(wxT("Selected (and marked) %s from calendar."),
601 event
.GetDate().FormatISODate().c_str());
604 void MyPanel
::OnCalendarChange(wxCalendarEvent
& event
)
607 s
.Printf(wxT("Selected date: %s"), event
.GetDate().FormatISODate().c_str());
613 void MyPanel
::OnCalMonthChange(wxCalendarEvent
& event
)
615 wxLogStatus(wxT("Calendar month changed to %s %d"),
616 wxDateTime
::GetMonthName(event
.GetDate().GetMonth()),
617 event
.GetDate().GetYear());
620 void MyPanel
::OnCalendarWeekDayClick(wxCalendarEvent
& event
)
622 wxLogMessage(wxT("Clicked on %s"),
623 wxDateTime
::GetWeekDayName(event
.GetWeekDay()).c_str());
626 void MyPanel
::RecreateCalendar(long style
)
628 wxCalendarCtrlBase
*calendar
;
629 #ifdef wxHAS_NATIVE_CALENDARCTRL
630 if ( m_usingGeneric
)
631 calendar
= new wxGenericCalendarCtrl(this, Calendar_CalCtrl
,
632 m_calendar
->GetDate(),
637 #endif // wxHAS_NATIVE_CALENDARCTRL
638 calendar
= new wxCalendarCtrl(this, Calendar_CalCtrl
,
639 m_calendar
->GetDate(),
644 m_sizer
->Replace(m_calendar
, calendar
);
646 m_calendar
= calendar
;
651 void MyPanel
::ToggleCalStyle(bool on
, int flag
)
653 long style
= m_calendar
->GetWindowStyle();
659 if ( flag
== wxCAL_SEQUENTIAL_MONTH_SELECTION
)
661 // changing this style requires recreating the control
662 RecreateCalendar(style
);
664 else // just changing the style is enough
666 m_calendar
->SetWindowStyle(style
);
668 m_calendar
->Refresh();
672 void MyPanel
::HighlightSpecial(bool on
)
677 *attrRedCircle
= new wxCalendarDateAttr(wxCAL_BORDER_ROUND
, *wxRED
),
678 *attrGreenSquare
= new wxCalendarDateAttr(wxCAL_BORDER_SQUARE
, *wxGREEN
),
679 *attrHeaderLike
= new wxCalendarDateAttr(*wxBLUE
, *wxLIGHT_GREY
);
681 m_calendar
->SetAttr(17, attrRedCircle
);
682 m_calendar
->SetAttr(29, attrGreenSquare
);
683 m_calendar
->SetAttr(13, attrHeaderLike
);
687 m_calendar
->ResetAttr(17);
688 m_calendar
->ResetAttr(29);
689 m_calendar
->ResetAttr(13);
692 m_calendar
->Refresh();
696 // ----------------------------------------------------------------------------
698 // ----------------------------------------------------------------------------
700 #if wxUSE_DATEPICKCTRL
702 MyDialog
::MyDialog(wxWindow
*parent
, const wxDateTime
& dt
, int dtpStyle
)
703 : wxDialog(parent
, wxID_ANY
, wxString(_T("Calendar: Choose a date")))
705 wxStdDialogButtonSizer
*sizerBtns
= new wxStdDialogButtonSizer
;
706 sizerBtns
->AddButton(new wxButton(this, wxID_OK
));
707 sizerBtns
->AddButton(new wxButton(this, wxID_CANCEL
));
708 sizerBtns
->Realize();
710 wxSizer
*sizerText
= new wxBoxSizer(wxHORIZONTAL
);
711 sizerText
->Add(new wxStaticText(this, wxID_ANY
, _T("Date in ISO format: ")),
712 wxSizerFlags().Border().Align(wxALIGN_CENTRE_VERTICAL
));
713 m_text
= new wxTextCtrl(this, wxID_ANY
);
714 sizerText
->Add(m_text
, wxSizerFlags().
715 Expand().Border().Align(wxALIGN_CENTRE_VERTICAL
));
717 wxSizer
*sizerTop
= new wxBoxSizer(wxVERTICAL
);
718 sizerTop
->Add(new wxStaticText
721 _T("Enter your birthday date (not before 20th century):")
723 wxSizerFlags().Border());
725 #if wxUSE_DATEPICKCTRL_GENERIC
726 wxFrame
*frame
= (wxFrame
*)wxGetTopLevelParent(parent
);
727 if ( frame
&& frame
->GetMenuBar()->IsChecked(Calendar_DatePicker_Generic
) )
728 m_datePicker
= new wxDatePickerCtrlGeneric(this, wxID_ANY
, dt
,
733 #endif // wxUSE_DATEPICKCTRL_GENERIC
734 m_datePicker
= new wxDatePickerCtrl(this, wxID_ANY
, dt
,
735 wxDefaultPosition
, wxDefaultSize
,
737 m_datePicker
->SetRange(wxDateTime(1, wxDateTime
::Jan
, 1900),
739 sizerTop
->Add(m_datePicker
, wxSizerFlags().Expand().Border());
741 sizerTop
->AddStretchSpacer(1);
742 sizerTop
->Add(sizerText
);
744 sizerTop
->Add(sizerBtns
, wxSizerFlags().Centre().Border());
746 SetSizerAndFit(sizerTop
);
750 void MyDialog
::OnDateChange(wxDateEvent
& event
)
752 const wxDateTime dt
= event
.GetDate();
754 m_text
->SetValue(dt
.FormatISODate());
756 m_text
->SetValue(wxEmptyString
);
759 #endif // wxUSE_DATEPICKCTRL