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 wxCalendarCtrlBase
* cal
= m_panel
->GetCal();
453 #ifdef wxHAS_NATIVE_CALENDARCTRL
454 wxStaticCast(cal
, wxGenericCalendarCtrl
)
458 ->EnableHolidayDisplay(event
.IsChecked());
461 void MyFrame
::OnCalSpecial(wxCommandEvent
& event
)
463 m_panel
->HighlightSpecial(GetMenuBar()->IsChecked(event
.GetId()));
466 void MyFrame
::OnCalAllowMonth(wxCommandEvent
& event
)
468 m_panel
->GetCal()->EnableMonthChange(event
.IsChecked());
471 void MyFrame
::OnCalSeqMonth(wxCommandEvent
& event
)
473 m_panel
->ToggleCalStyle(event
.IsChecked(),
474 wxCAL_SEQUENTIAL_MONTH_SELECTION
);
477 void MyFrame
::OnCalShowSurroundingWeeks(wxCommandEvent
& event
)
479 m_panel
->ToggleCalStyle(event
.IsChecked(), wxCAL_SHOW_SURROUNDING_WEEKS
);
482 void MyFrame
::OnSetDate(wxCommandEvent
&WXUNUSED(event
))
484 m_panel
->SetDate(wxDateTime(24, wxDateTime
::Dec
, 2005, 22, 00, 00));
487 void MyFrame
::OnToday(wxCommandEvent
&WXUNUSED(event
))
489 m_panel
->SetDate(wxDateTime
::Today());
492 void MyFrame
::OnBeginDST(wxCommandEvent
&WXUNUSED(event
))
494 m_panel
->SetDate(wxDateTime
::GetBeginDST(m_panel
->GetDate().GetYear()));
497 void MyFrame
::OnCalToggleResizable(wxCommandEvent
& event
)
499 wxSizer
* const sizer
= m_panel
->GetSizer();
500 wxSizerItem
* const item
= sizer
->GetItem(m_panel
->GetCal());
501 if ( event
.IsChecked() )
503 item
->SetProportion(1);
504 item
->SetFlag(wxEXPAND
);
506 else // not resizable
508 item
->SetProportion(0);
509 item
->SetFlag(wxALIGN_CENTER
);
515 #if wxUSE_DATEPICKCTRL
517 void MyFrame
::OnUpdateUIStartWithNone(wxUpdateUIEvent
& event
)
519 // it only makes sense to start with invalid date if we can have no date
520 event
.Enable( GetMenuBar()->IsChecked(Calendar_DatePicker_AllowNone
) );
523 void MyFrame
::OnAskDate(wxCommandEvent
& WXUNUSED(event
))
525 wxDateTime dt
= m_panel
->GetCal()->GetDate();
527 int style
= wxDP_DEFAULT
;
528 if ( GetMenuBar()->IsChecked(Calendar_DatePicker_ShowCentury
) )
529 style
|= wxDP_SHOWCENTURY
;
530 if ( GetMenuBar()->IsChecked(Calendar_DatePicker_DropDown
) )
531 style
|= wxDP_DROPDOWN
;
532 if ( GetMenuBar()->IsChecked(Calendar_DatePicker_AllowNone
) )
534 style
|= wxDP_ALLOWNONE
;
536 if ( GetMenuBar()->IsChecked(Calendar_DatePicker_StartWithNone
) )
537 dt
= wxDefaultDateTime
;
540 MyDialog
dlg(this, dt
, style
);
541 if ( dlg
.ShowModal() == wxID_OK
)
546 const wxDateTime today
= wxDateTime
::Today();
548 if ( dt
.GetDay() == today
.GetDay() &&
549 dt
.GetMonth() == today
.GetMonth() )
551 wxMessageBox(_T("Happy birthday!"), _T("Calendar Sample"));
554 m_panel
->SetDate(dt
);
556 wxLogStatus(_T("Changed the date to your input"));
560 wxLogStatus(_T("No date entered"));
565 #endif // wxUSE_DATEPICKCTRL
567 // ----------------------------------------------------------------------------
569 // ----------------------------------------------------------------------------
571 MyPanel
::MyPanel(wxWindow
*parent
)
572 : wxPanel(parent
, wxID_ANY
)
574 #ifdef wxHAS_NATIVE_CALENDARCTRL
575 m_usingGeneric
= false;
577 m_usingGeneric
= true;
581 date
.Printf(wxT("Selected date: %s"),
582 wxDateTime
::Today().FormatISODate().c_str());
583 m_date
= new wxStaticText(this, wxID_ANY
, date
);
584 m_calendar
= new wxCalendarCtrl(this, Calendar_CalCtrl
,
589 wxCAL_SHOW_HOLIDAYS
|
592 // adjust to vertical/horizontal display, check mostly dedicated to WinCE
593 bool horizontal
= ( wxSystemSettings
::GetMetric(wxSYS_SCREEN_X
) > wxSystemSettings
::GetMetric(wxSYS_SCREEN_Y
) );
594 m_sizer
= new wxBoxSizer( horizontal ? wxHORIZONTAL
: wxVERTICAL
);
596 m_sizer
->Add(m_date
, 0, wxALIGN_CENTER
| wxALL
, 10 );
597 m_sizer
->Add(m_calendar
, 0, wxALIGN_CENTER
| wxALIGN_LEFT
);
600 m_sizer
->SetSizeHints( this );
603 void MyPanel
::OnCalendar(wxCalendarEvent
& event
)
605 m_calendar
->Mark(event
.GetDate().GetDay(), true);
606 wxLogMessage(wxT("Selected (and marked) %s from calendar."),
607 event
.GetDate().FormatISODate().c_str());
610 void MyPanel
::OnCalendarChange(wxCalendarEvent
& event
)
613 s
.Printf(wxT("Selected date: %s"), event
.GetDate().FormatISODate().c_str());
619 void MyPanel
::OnCalMonthChange(wxCalendarEvent
& event
)
621 wxLogStatus(wxT("Calendar month changed to %s %d"),
622 wxDateTime
::GetMonthName(event
.GetDate().GetMonth()),
623 event
.GetDate().GetYear());
626 void MyPanel
::OnCalendarWeekDayClick(wxCalendarEvent
& event
)
628 wxLogMessage(wxT("Clicked on %s"),
629 wxDateTime
::GetWeekDayName(event
.GetWeekDay()).c_str());
632 void MyPanel
::RecreateCalendar(long style
)
634 wxCalendarCtrlBase
*calendar
;
635 #ifdef wxHAS_NATIVE_CALENDARCTRL
636 if ( m_usingGeneric
)
637 calendar
= new wxGenericCalendarCtrl(this, Calendar_CalCtrl
,
638 m_calendar
->GetDate(),
643 #endif // wxHAS_NATIVE_CALENDARCTRL
644 calendar
= new wxCalendarCtrl(this, Calendar_CalCtrl
,
645 m_calendar
->GetDate(),
650 m_sizer
->Replace(m_calendar
, calendar
);
652 m_calendar
= calendar
;
657 void MyPanel
::ToggleCalStyle(bool on
, int flag
)
659 long style
= m_calendar
->GetWindowStyle();
665 if ( flag
== wxCAL_SEQUENTIAL_MONTH_SELECTION
)
667 // changing this style requires recreating the control
668 RecreateCalendar(style
);
670 else // just changing the style is enough
672 m_calendar
->SetWindowStyle(style
);
674 m_calendar
->Refresh();
678 void MyPanel
::HighlightSpecial(bool on
)
683 *attrRedCircle
= new wxCalendarDateAttr(wxCAL_BORDER_ROUND
, *wxRED
),
684 *attrGreenSquare
= new wxCalendarDateAttr(wxCAL_BORDER_SQUARE
, *wxGREEN
),
685 *attrHeaderLike
= new wxCalendarDateAttr(*wxBLUE
, *wxLIGHT_GREY
);
687 m_calendar
->SetAttr(17, attrRedCircle
);
688 m_calendar
->SetAttr(29, attrGreenSquare
);
689 m_calendar
->SetAttr(13, attrHeaderLike
);
693 m_calendar
->ResetAttr(17);
694 m_calendar
->ResetAttr(29);
695 m_calendar
->ResetAttr(13);
698 m_calendar
->Refresh();
702 // ----------------------------------------------------------------------------
704 // ----------------------------------------------------------------------------
706 #if wxUSE_DATEPICKCTRL
708 MyDialog
::MyDialog(wxWindow
*parent
, const wxDateTime
& dt
, int dtpStyle
)
709 : wxDialog(parent
, wxID_ANY
, wxString(_T("Calendar: Choose a date")))
711 wxStdDialogButtonSizer
*sizerBtns
= new wxStdDialogButtonSizer
;
712 sizerBtns
->AddButton(new wxButton(this, wxID_OK
));
713 sizerBtns
->AddButton(new wxButton(this, wxID_CANCEL
));
714 sizerBtns
->Realize();
716 wxSizer
*sizerText
= new wxBoxSizer(wxHORIZONTAL
);
717 sizerText
->Add(new wxStaticText(this, wxID_ANY
, _T("Date in ISO format: ")),
718 wxSizerFlags().Border().Align(wxALIGN_CENTRE_VERTICAL
));
719 m_text
= new wxTextCtrl(this, wxID_ANY
);
720 sizerText
->Add(m_text
, wxSizerFlags().
721 Expand().Border().Align(wxALIGN_CENTRE_VERTICAL
));
723 wxSizer
*sizerTop
= new wxBoxSizer(wxVERTICAL
);
724 sizerTop
->Add(new wxStaticText
727 _T("Enter your birthday date (not before 20th century):")
729 wxSizerFlags().Border());
731 #if wxUSE_DATEPICKCTRL_GENERIC
732 wxFrame
*frame
= (wxFrame
*)wxGetTopLevelParent(parent
);
733 if ( frame
&& frame
->GetMenuBar()->IsChecked(Calendar_DatePicker_Generic
) )
734 m_datePicker
= new wxDatePickerCtrlGeneric(this, wxID_ANY
, dt
,
739 #endif // wxUSE_DATEPICKCTRL_GENERIC
740 m_datePicker
= new wxDatePickerCtrl(this, wxID_ANY
, dt
,
741 wxDefaultPosition
, wxDefaultSize
,
743 m_datePicker
->SetRange(wxDateTime(1, wxDateTime
::Jan
, 1900),
745 sizerTop
->Add(m_datePicker
, wxSizerFlags().Expand().Border());
747 sizerTop
->AddStretchSpacer(1);
748 sizerTop
->Add(sizerText
);
750 sizerTop
->Add(sizerBtns
, wxSizerFlags().Centre().Border());
752 SetSizerAndFit(sizerTop
);
756 void MyDialog
::OnDateChange(wxDateEvent
& event
)
758 const wxDateTime dt
= event
.GetDate();
760 m_text
->SetValue(dt
.FormatISODate());
762 m_text
->SetValue(wxEmptyString
);
765 #endif // wxUSE_DATEPICKCTRL