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 wxCalendarCtrlBase
*DoCreateCalendar(const wxDateTime
& dt
, long style
);
107 void RecreateCalendar(long style
);
109 wxCalendarCtrlBase
*m_calendar
;
110 wxStaticText
*m_date
;
116 DECLARE_EVENT_TABLE()
119 // Define a new frame type: this is going to be our main frame
120 class MyFrame
: public wxFrame
124 MyFrame(const wxString
& title
, const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& size
= wxDefaultSize
);
126 // event handlers (these functions should _not_ be virtual)
127 void OnAbout(wxCommandEvent
& event
);
128 void OnClearLog(wxCommandEvent
& event
);
129 void OnQuit(wxCommandEvent
& event
);
131 #if wxUSE_DATEPICKCTRL
132 void OnAskDate(wxCommandEvent
& event
);
134 void OnUpdateUIStartWithNone(wxUpdateUIEvent
& event
);
135 #endif // wxUSE_DATEPICKCTRL
137 #ifdef wxHAS_NATIVE_CALENDARCTRL
138 void OnCalGeneric(wxCommandEvent
& WXUNUSED(event
))
140 m_panel
->ToggleUseGeneric();
142 #endif // wxHAS_NATIVE_CALENDARCTRL
144 void OnCalMonday(wxCommandEvent
& event
);
145 void OnCalHolidays(wxCommandEvent
& event
);
146 void OnCalSpecial(wxCommandEvent
& event
);
148 void OnCalAllowMonth(wxCommandEvent
& event
);
150 void OnCalSeqMonth(wxCommandEvent
& event
);
151 void OnCalShowSurroundingWeeks(wxCommandEvent
& event
);
152 void OnCalShowWeekNumbers(wxCommandEvent
& event
);
154 void OnSetDate(wxCommandEvent
& event
);
155 void OnToday(wxCommandEvent
& event
);
156 void OnBeginDST(wxCommandEvent
& event
);
158 void OnCalToggleResizable(wxCommandEvent
& event
);
160 void OnUpdateUIGenericOnly(wxUpdateUIEvent
& event
)
162 event
.Enable(m_panel
->IsUsingGeneric());
165 void OnCalRClick(wxMouseEvent
& event
);
169 wxTextCtrl
*m_logWindow
;
171 // any class wishing to process wxWidgets events must use this macro
172 DECLARE_EVENT_TABLE()
175 #if wxUSE_DATEPICKCTRL
177 // Define a simple modal dialog which asks the user for a date
178 class MyDialog
: public wxDialog
181 MyDialog(wxWindow
*parent
, const wxDateTime
& dt
, int dtpStyle
);
183 wxDateTime
GetDate() const { return m_datePicker
->GetValue(); }
186 void OnDateChange(wxDateEvent
& event
);
189 wxDatePickerCtrlBase
*m_datePicker
;
193 DECLARE_EVENT_TABLE()
196 #endif // wxUSE_DATEPICKCTRL
198 // ----------------------------------------------------------------------------
200 // ----------------------------------------------------------------------------
202 // IDs for the controls and the menu commands
206 Calendar_File_About
= wxID_ABOUT
,
207 Calendar_File_ClearLog
= wxID_CLEAR
,
208 Calendar_File_Quit
= wxID_EXIT
,
209 Calendar_Cal_Generic
= 200,
211 Calendar_Cal_Holidays
,
212 Calendar_Cal_Special
,
214 Calendar_Cal_SeqMonth
,
215 Calendar_Cal_SurroundWeeks
,
216 Calendar_Cal_WeekNumbers
,
217 Calendar_Cal_SetDate
,
219 Calendar_Cal_BeginDST
,
220 Calendar_Cal_Resizable
,
221 #if wxUSE_DATEPICKCTRL
222 Calendar_DatePicker_AskDate
= 300,
223 Calendar_DatePicker_ShowCentury
,
224 Calendar_DatePicker_DropDown
,
225 Calendar_DatePicker_AllowNone
,
226 Calendar_DatePicker_StartWithNone
,
227 #if wxUSE_DATEPICKCTRL_GENERIC
228 Calendar_DatePicker_Generic
,
229 #endif // wxUSE_DATEPICKCTRL_GENERIC
230 #endif // wxUSE_DATEPICKCTRL
231 Calendar_CalCtrl
= 1000
234 // ----------------------------------------------------------------------------
235 // event tables and other macros for wxWidgets
236 // ----------------------------------------------------------------------------
238 // the event tables connect the wxWidgets events with the functions (event
239 // handlers) which process them. It can be also done at run-time, but for the
240 // simple menu events like this the static method is much simpler.
241 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
242 EVT_MENU(Calendar_File_About
, MyFrame::OnAbout
)
243 EVT_MENU(Calendar_File_ClearLog
, MyFrame::OnClearLog
)
244 EVT_MENU(Calendar_File_Quit
, MyFrame::OnQuit
)
246 #if wxUSE_DATEPICKCTRL
247 EVT_MENU(Calendar_DatePicker_AskDate
, MyFrame::OnAskDate
)
249 EVT_UPDATE_UI(Calendar_DatePicker_StartWithNone
,
250 MyFrame::OnUpdateUIStartWithNone
)
251 #endif // wxUSE_DATEPICKCTRL
253 #ifdef wxHAS_NATIVE_CALENDARCTRL
254 EVT_MENU(Calendar_Cal_Generic
, MyFrame::OnCalGeneric
)
255 #endif // wxHAS_NATIVE_CALENDARCTRL
257 EVT_MENU(Calendar_Cal_Monday
, MyFrame::OnCalMonday
)
258 EVT_MENU(Calendar_Cal_Holidays
, MyFrame::OnCalHolidays
)
259 EVT_MENU(Calendar_Cal_Special
, MyFrame::OnCalSpecial
)
261 EVT_MENU(Calendar_Cal_Month
, MyFrame::OnCalAllowMonth
)
263 EVT_MENU(Calendar_Cal_SeqMonth
, MyFrame::OnCalSeqMonth
)
264 EVT_MENU(Calendar_Cal_SurroundWeeks
, MyFrame::OnCalShowSurroundingWeeks
)
265 EVT_MENU(Calendar_Cal_WeekNumbers
, MyFrame::OnCalShowWeekNumbers
)
267 EVT_MENU(Calendar_Cal_SetDate
, MyFrame::OnSetDate
)
268 EVT_MENU(Calendar_Cal_Today
, MyFrame::OnToday
)
269 EVT_MENU(Calendar_Cal_BeginDST
, MyFrame::OnBeginDST
)
271 EVT_MENU(Calendar_Cal_Resizable
, MyFrame::OnCalToggleResizable
)
274 EVT_UPDATE_UI(Calendar_Cal_SeqMonth
, MyFrame::OnUpdateUIGenericOnly
)
276 EVT_UPDATE_UI(Calendar_Cal_Monday
, MyFrame::OnUpdateUIGenericOnly
)
278 EVT_UPDATE_UI(Calendar_Cal_Holidays
, MyFrame::OnUpdateUIGenericOnly
)
279 EVT_UPDATE_UI(Calendar_Cal_Special
, MyFrame::OnUpdateUIGenericOnly
)
280 EVT_UPDATE_UI(Calendar_Cal_SurroundWeeks
, MyFrame::OnUpdateUIGenericOnly
)
283 BEGIN_EVENT_TABLE(MyPanel
, wxPanel
)
284 EVT_CALENDAR(Calendar_CalCtrl
, MyPanel::OnCalendar
)
285 EVT_CALENDAR_PAGE_CHANGED(Calendar_CalCtrl
, MyPanel::OnCalMonthChange
)
286 EVT_CALENDAR_SEL_CHANGED(Calendar_CalCtrl
, MyPanel::OnCalendarChange
)
287 EVT_CALENDAR_WEEKDAY_CLICKED(Calendar_CalCtrl
, MyPanel::OnCalendarWeekDayClick
)
290 #if wxUSE_DATEPICKCTRL
292 BEGIN_EVENT_TABLE(MyDialog
, wxDialog
)
293 EVT_DATE_CHANGED(wxID_ANY
, MyDialog::OnDateChange
)
296 #endif // wxUSE_DATEPICKCTRL
298 // Create a new application object: this macro will allow wxWidgets to create
299 // the application object during program execution (it's better than using a
300 // static object for many reasons) and also declares the accessor function
301 // wxGetApp() which will return the reference of the right type (i.e. MyApp and
305 // ============================================================================
307 // ============================================================================
309 // ----------------------------------------------------------------------------
310 // the application class
311 // ----------------------------------------------------------------------------
313 // `Main program' equivalent: the program execution "starts" here
316 if ( !wxApp::OnInit() )
319 // Create the main application window
320 MyFrame
*frame
= new MyFrame(_T("Calendar wxWidgets sample")
322 ,wxPoint(50, 50), wxSize(450, 340)
328 // success: wxApp::OnRun() will be called which will enter the main message
329 // loop and the application will run. If we returned false here, the
330 // application would exit immediately.
334 // ----------------------------------------------------------------------------
336 // ----------------------------------------------------------------------------
339 MyFrame::MyFrame(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
)
340 : wxFrame((wxFrame
*)NULL
, wxID_ANY
, title
, pos
, size
)
342 // set the frame icon
343 SetIcon(wxIcon(sample_xpm
));
346 wxMenu
*menuFile
= new wxMenu
;
347 menuFile
->Append(Calendar_File_About
, _T("&About...\tCtrl-A"), _T("Show about dialog"));
348 menuFile
->AppendSeparator();
349 menuFile
->Append(Calendar_File_ClearLog
, _T("&Clear log\tCtrl-L"));
350 menuFile
->AppendSeparator();
351 menuFile
->Append(Calendar_File_Quit
, _T("E&xit\tAlt-X"), _T("Quit this program"));
353 wxMenu
*menuCal
= new wxMenu
;
354 #ifdef wxHAS_NATIVE_CALENDARCTRL
355 menuCal
->AppendCheckItem(Calendar_Cal_Generic
, "Use &generic version\tCtrl-G",
356 "Toggle between native and generic control");
357 menuCal
->AppendSeparator();
358 #endif // wxHAS_NATIVE_CALENDARCTRL
359 menuCal
->Append(Calendar_Cal_Monday
,
360 _T("Monday &first weekday\tCtrl-F"),
361 _T("Toggle between Mon and Sun as the first week day"),
363 menuCal
->Append(Calendar_Cal_Holidays
, _T("Show &holidays\tCtrl-H"),
364 _T("Toggle highlighting the holidays"),
366 menuCal
->Append(Calendar_Cal_Special
, _T("Highlight &special dates\tCtrl-S"),
367 _T("Test custom highlighting"),
369 menuCal
->Append(Calendar_Cal_SurroundWeeks
,
370 _T("Show s&urrounding weeks\tCtrl-W"),
371 _T("Show the neighbouring weeks in the prev/next month"),
373 menuCal
->Append(Calendar_Cal_WeekNumbers
,
374 _T("Show &week numbers"),
375 _T("Toggle week numbers"),
377 menuCal
->AppendSeparator();
378 menuCal
->Append(Calendar_Cal_SeqMonth
,
379 _T("Toggle month selector st&yle\tCtrl-Y"),
380 _T("Use another style for the calendar controls"),
382 menuCal
->Append(Calendar_Cal_Month
, _T("&Month can be changed\tCtrl-M"),
383 _T("Allow changing the month in the calendar"),
385 menuCal
->AppendSeparator();
386 menuCal
->Append(Calendar_Cal_SetDate
, _T("Call &SetDate(2005-12-24)"), _T("Set date to 2005-12-24."));
387 menuCal
->Append(Calendar_Cal_Today
, _T("Call &Today()"), _T("Set to the current date."));
388 menuCal
->Append(Calendar_Cal_BeginDST
, "Call SetDate(GetBeginDST())");
389 menuCal
->AppendSeparator();
390 menuCal
->AppendCheckItem(Calendar_Cal_Resizable
, _T("Make &resizable\tCtrl-R"));
392 #if wxUSE_DATEPICKCTRL
393 wxMenu
*menuDate
= new wxMenu
;
394 menuDate
->AppendCheckItem(Calendar_DatePicker_ShowCentury
,
395 _T("Al&ways show century"));
396 menuDate
->AppendCheckItem(Calendar_DatePicker_DropDown
,
397 _T("Use &drop down control"));
398 menuDate
->AppendCheckItem(Calendar_DatePicker_AllowNone
,
399 _T("Allow &no date"));
400 menuDate
->AppendCheckItem(Calendar_DatePicker_StartWithNone
,
401 _T("Start &with no date"));
402 #if wxUSE_DATEPICKCTRL_GENERIC
403 menuDate
->AppendCheckItem(Calendar_DatePicker_Generic
,
404 _T("Use &generic version of the control"));
405 #endif // wxUSE_DATEPICKCTRL_GENERIC
406 menuDate
->AppendSeparator();
407 menuDate
->Append(Calendar_DatePicker_AskDate
, _T("&Choose date...\tCtrl-D"), _T("Show dialog with wxDatePickerCtrl"));
408 #endif // wxUSE_DATEPICKCTRL
410 // now append the freshly created menu to the menu bar...
411 wxMenuBar
*menuBar
= new wxMenuBar
;
412 menuBar
->Append(menuFile
, _T("&File"));
413 menuBar
->Append(menuCal
, _T("&Calendar"));
414 #if wxUSE_DATEPICKCTRL
415 menuBar
->Append(menuDate
, _T("&Date picker"));
416 #endif // wxUSE_DATEPICKCTRL
418 menuBar
->Check(Calendar_Cal_Monday
, true);
419 menuBar
->Check(Calendar_Cal_Holidays
, true);
420 menuBar
->Check(Calendar_Cal_Month
, true);
422 #if wxUSE_DATEPICKCTRL
423 menuBar
->Check(Calendar_DatePicker_ShowCentury
, true);
424 #endif // wxUSE_DATEPICKCTRL
426 // ... and attach this menu bar to the frame
429 wxSplitterWindow
*splitter
= new wxSplitterWindow(this, wxID_ANY
,
430 wxDefaultPosition
, wxDefaultSize
,
432 m_panel
= new MyPanel(splitter
);
433 m_logWindow
= new wxTextCtrl(splitter
, wxID_ANY
, wxEmptyString
,
434 wxDefaultPosition
, wxDefaultSize
,
435 wxTE_READONLY
| wxTE_MULTILINE
);
436 splitter
->SplitHorizontally(m_panel
, m_logWindow
);
437 splitter
->SetMinimumPaneSize(20);
438 wxLog::SetActiveTarget(new wxLogTextCtrl(m_logWindow
));
441 void MyFrame::OnQuit(wxCommandEvent
& WXUNUSED(event
))
443 // true is to force the frame to close
447 void MyFrame::OnAbout(wxCommandEvent
& WXUNUSED(event
))
449 wxMessageBox(_T("wxCalendarCtrl sample\n(c) 2000--2008 Vadim Zeitlin"),
450 _T("About Calendar"), wxOK
| wxICON_INFORMATION
, this);
453 void MyFrame::OnClearLog(wxCommandEvent
& WXUNUSED(event
))
455 m_logWindow
->Clear();
458 void MyFrame::OnCalMonday(wxCommandEvent
& event
)
460 m_panel
->ToggleCalStyle(event
.IsChecked(), wxCAL_MONDAY_FIRST
);
463 void MyFrame::OnCalHolidays(wxCommandEvent
& event
)
465 m_panel
->GetCal()->EnableHolidayDisplay(event
.IsChecked());
468 void MyFrame::OnCalSpecial(wxCommandEvent
& event
)
470 m_panel
->HighlightSpecial(GetMenuBar()->IsChecked(event
.GetId()));
473 void MyFrame::OnCalAllowMonth(wxCommandEvent
& event
)
475 m_panel
->GetCal()->EnableMonthChange(event
.IsChecked());
478 void MyFrame::OnCalSeqMonth(wxCommandEvent
& event
)
480 m_panel
->ToggleCalStyle(event
.IsChecked(),
481 wxCAL_SEQUENTIAL_MONTH_SELECTION
);
484 void MyFrame::OnCalShowSurroundingWeeks(wxCommandEvent
& event
)
486 m_panel
->ToggleCalStyle(event
.IsChecked(), wxCAL_SHOW_SURROUNDING_WEEKS
);
489 void MyFrame::OnCalShowWeekNumbers(wxCommandEvent
& event
)
491 m_panel
->ToggleCalStyle(event
.IsChecked(), wxCAL_SHOW_WEEK_NUMBERS
);
494 void MyFrame::OnSetDate(wxCommandEvent
&WXUNUSED(event
))
496 m_panel
->SetDate(wxDateTime(24, wxDateTime::Dec
, 2005, 22, 00, 00));
499 void MyFrame::OnToday(wxCommandEvent
&WXUNUSED(event
))
501 m_panel
->SetDate(wxDateTime::Today());
504 void MyFrame::OnBeginDST(wxCommandEvent
&WXUNUSED(event
))
506 m_panel
->SetDate(wxDateTime::GetBeginDST(m_panel
->GetDate().GetYear()));
509 void MyFrame::OnCalToggleResizable(wxCommandEvent
& event
)
511 wxSizer
* const sizer
= m_panel
->GetSizer();
512 wxSizerItem
* const item
= sizer
->GetItem(m_panel
->GetCal());
513 if ( event
.IsChecked() )
515 item
->SetProportion(1);
516 item
->SetFlag(wxEXPAND
);
518 else // not resizable
520 item
->SetProportion(0);
521 item
->SetFlag(wxALIGN_CENTER
);
527 void MyFrame::OnCalRClick(wxMouseEvent
& event
)
530 wxDateTime::WeekDay wd
;
532 const wxPoint pt
= event
.GetPosition();
533 wxString msg
= wxString::Format("Point (%d, %d) is ", pt
.x
, pt
.y
);
535 switch ( m_panel
->GetCal()->HitTest(pt
, &dt
, &wd
) )
538 wxFAIL_MSG( "unexpected" );
541 case wxCAL_HITTEST_NOWHERE
:
545 case wxCAL_HITTEST_HEADER
:
546 msg
+= wxString::Format("over %s", wxDateTime::GetWeekDayName(wd
));
549 case wxCAL_HITTEST_DAY
:
550 msg
+= wxString::Format("over %s", dt
.FormatISODate());
553 case wxCAL_HITTEST_INCMONTH
:
554 msg
+= "over next month button";
557 case wxCAL_HITTEST_DECMONTH
:
558 msg
+= "over previous month button";
561 case wxCAL_HITTEST_SURROUNDING_WEEK
:
562 msg
+= "over a day from another month";
566 wxLogMessage("%s", msg
);
569 #if wxUSE_DATEPICKCTRL
571 void MyFrame::OnUpdateUIStartWithNone(wxUpdateUIEvent
& event
)
573 // it only makes sense to start with invalid date if we can have no date
574 event
.Enable( GetMenuBar()->IsChecked(Calendar_DatePicker_AllowNone
) );
577 void MyFrame::OnAskDate(wxCommandEvent
& WXUNUSED(event
))
579 wxDateTime dt
= m_panel
->GetCal()->GetDate();
581 int style
= wxDP_DEFAULT
;
582 if ( GetMenuBar()->IsChecked(Calendar_DatePicker_ShowCentury
) )
583 style
|= wxDP_SHOWCENTURY
;
584 if ( GetMenuBar()->IsChecked(Calendar_DatePicker_DropDown
) )
585 style
|= wxDP_DROPDOWN
;
586 if ( GetMenuBar()->IsChecked(Calendar_DatePicker_AllowNone
) )
588 style
|= wxDP_ALLOWNONE
;
590 if ( GetMenuBar()->IsChecked(Calendar_DatePicker_StartWithNone
) )
591 dt
= wxDefaultDateTime
;
594 MyDialog
dlg(this, dt
, style
);
595 if ( dlg
.ShowModal() == wxID_OK
)
600 const wxDateTime today
= wxDateTime::Today();
602 if ( dt
.GetDay() == today
.GetDay() &&
603 dt
.GetMonth() == today
.GetMonth() )
605 wxMessageBox(_T("Happy birthday!"), _T("Calendar Sample"));
608 m_panel
->SetDate(dt
);
610 wxLogStatus(_T("Changed the date to your input"));
614 wxLogStatus(_T("No date entered"));
619 #endif // wxUSE_DATEPICKCTRL
621 // ----------------------------------------------------------------------------
623 // ----------------------------------------------------------------------------
625 MyPanel::MyPanel(wxWindow
*parent
)
626 : wxPanel(parent
, wxID_ANY
)
628 #ifdef wxHAS_NATIVE_CALENDARCTRL
629 m_usingGeneric
= false;
631 m_usingGeneric
= true;
635 date
.Printf(wxT("Selected date: %s"),
636 wxDateTime::Today().FormatISODate().c_str());
637 m_date
= new wxStaticText(this, wxID_ANY
, date
);
638 m_calendar
= DoCreateCalendar(wxDefaultDateTime
,
639 wxCAL_MONDAY_FIRST
| wxCAL_SHOW_HOLIDAYS
);
641 // adjust to vertical/horizontal display, check mostly dedicated to WinCE
642 bool horizontal
= ( wxSystemSettings::GetMetric(wxSYS_SCREEN_X
) > wxSystemSettings::GetMetric(wxSYS_SCREEN_Y
) );
643 m_sizer
= new wxBoxSizer( horizontal
? wxHORIZONTAL
: wxVERTICAL
);
645 m_sizer
->Add(m_date
, 0, wxALIGN_CENTER
| wxALL
, 10 );
646 m_sizer
->Add(m_calendar
, 0, wxALIGN_CENTER
| wxALIGN_LEFT
);
649 m_sizer
->SetSizeHints( this );
652 void MyPanel::OnCalendar(wxCalendarEvent
& event
)
654 // clicking the same date twice unmarks it (convenient for testing)
655 static wxDateTime s_dateLast
;
656 const bool mark
= !s_dateLast
.IsValid() || event
.GetDate() != s_dateLast
;
658 s_dateLast
= event
.GetDate();
660 m_calendar
->Mark(event
.GetDate().GetDay(), mark
);
661 wxLogMessage(wxT("Selected (and %smarked) %s from calendar."),
662 mark
? "" : "un", s_dateLast
.FormatISODate().c_str());
665 void MyPanel::OnCalendarChange(wxCalendarEvent
& event
)
668 s
.Printf(wxT("Selected date: %s"), event
.GetDate().FormatISODate().c_str());
674 void MyPanel::OnCalMonthChange(wxCalendarEvent
& event
)
676 wxLogStatus(wxT("Calendar month changed to %s %d"),
677 wxDateTime::GetMonthName(event
.GetDate().GetMonth()),
678 event
.GetDate().GetYear());
681 void MyPanel::OnCalendarWeekDayClick(wxCalendarEvent
& event
)
683 wxLogMessage(wxT("Clicked on %s"),
684 wxDateTime::GetWeekDayName(event
.GetWeekDay()).c_str());
687 wxCalendarCtrlBase
*MyPanel::DoCreateCalendar(const wxDateTime
& dt
, long style
)
689 wxCalendarCtrlBase
*calendar
;
690 #ifdef wxHAS_NATIVE_CALENDARCTRL
691 if ( m_usingGeneric
)
692 calendar
= new wxGenericCalendarCtrl(this, Calendar_CalCtrl
,
698 #endif // wxHAS_NATIVE_CALENDARCTRL
699 calendar
= new wxCalendarCtrl(this, Calendar_CalCtrl
,
705 calendar
->Connect(wxEVT_RIGHT_DOWN
,
706 wxMouseEventHandler(MyFrame::OnCalRClick
),
708 wxGetTopLevelParent(this));
713 void MyPanel::RecreateCalendar(long style
)
715 wxCalendarCtrlBase
*calendar
= DoCreateCalendar(m_calendar
->GetDate(), style
);
717 m_sizer
->Replace(m_calendar
, calendar
);
719 m_calendar
= calendar
;
724 void MyPanel::ToggleCalStyle(bool on
, int flag
)
726 long style
= m_calendar
->GetWindowStyle();
732 if ( flag
== wxCAL_SEQUENTIAL_MONTH_SELECTION
733 || flag
== wxCAL_SHOW_WEEK_NUMBERS
)
735 // changing this style requires recreating the control
736 RecreateCalendar(style
);
738 else // just changing the style is enough
740 m_calendar
->SetWindowStyle(style
);
742 m_calendar
->Refresh();
746 void MyPanel::HighlightSpecial(bool on
)
751 *attrRedCircle
= new wxCalendarDateAttr(wxCAL_BORDER_ROUND
, *wxRED
),
752 *attrGreenSquare
= new wxCalendarDateAttr(wxCAL_BORDER_SQUARE
, *wxGREEN
),
753 *attrHeaderLike
= new wxCalendarDateAttr(*wxBLUE
, *wxLIGHT_GREY
);
755 m_calendar
->SetAttr(17, attrRedCircle
);
756 m_calendar
->SetAttr(29, attrGreenSquare
);
757 m_calendar
->SetAttr(13, attrHeaderLike
);
761 m_calendar
->ResetAttr(17);
762 m_calendar
->ResetAttr(29);
763 m_calendar
->ResetAttr(13);
766 m_calendar
->Refresh();
770 // ----------------------------------------------------------------------------
772 // ----------------------------------------------------------------------------
774 #if wxUSE_DATEPICKCTRL
776 MyDialog::MyDialog(wxWindow
*parent
, const wxDateTime
& dt
, int dtpStyle
)
777 : wxDialog(parent
, wxID_ANY
, wxString(_T("Calendar: Choose a date")))
779 wxStdDialogButtonSizer
*sizerBtns
= new wxStdDialogButtonSizer
;
780 sizerBtns
->AddButton(new wxButton(this, wxID_OK
));
781 sizerBtns
->AddButton(new wxButton(this, wxID_CANCEL
));
782 sizerBtns
->Realize();
784 wxSizer
*sizerText
= new wxBoxSizer(wxHORIZONTAL
);
785 sizerText
->Add(new wxStaticText(this, wxID_ANY
, _T("Date in ISO format: ")),
786 wxSizerFlags().Border().Align(wxALIGN_CENTRE_VERTICAL
));
787 m_text
= new wxTextCtrl(this, wxID_ANY
);
788 sizerText
->Add(m_text
, wxSizerFlags().
789 Expand().Border().Align(wxALIGN_CENTRE_VERTICAL
));
791 wxSizer
*sizerTop
= new wxBoxSizer(wxVERTICAL
);
792 sizerTop
->Add(new wxStaticText
795 _T("Enter your birthday date (not before 20th century):")
797 wxSizerFlags().Border());
799 #if wxUSE_DATEPICKCTRL_GENERIC
800 wxFrame
*frame
= (wxFrame
*)wxGetTopLevelParent(parent
);
801 if ( frame
&& frame
->GetMenuBar()->IsChecked(Calendar_DatePicker_Generic
) )
802 m_datePicker
= new wxDatePickerCtrlGeneric(this, wxID_ANY
, dt
,
807 #endif // wxUSE_DATEPICKCTRL_GENERIC
808 m_datePicker
= new wxDatePickerCtrl(this, wxID_ANY
, dt
,
809 wxDefaultPosition
, wxDefaultSize
,
811 m_datePicker
->SetRange(wxDateTime(1, wxDateTime::Jan
, 1900),
813 sizerTop
->Add(m_datePicker
, wxSizerFlags().Expand().Border());
815 sizerTop
->AddStretchSpacer(1);
816 sizerTop
->Add(sizerText
);
818 sizerTop
->Add(sizerBtns
, wxSizerFlags().Centre().Border());
820 SetSizerAndFit(sizerTop
);
824 void MyDialog::OnDateChange(wxDateEvent
& event
)
826 const wxDateTime dt
= event
.GetDate();
828 m_text
->SetValue(dt
.FormatISODate());
830 m_text
->SetValue(wxEmptyString
);
833 #endif // wxUSE_DATEPICKCTRL