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
);
153 void OnSetDate(wxCommandEvent
& event
);
154 void OnToday(wxCommandEvent
& event
);
155 void OnBeginDST(wxCommandEvent
& event
);
157 void OnCalToggleResizable(wxCommandEvent
& event
);
159 void OnUpdateUIGenericOnly(wxUpdateUIEvent
& event
)
161 event
.Enable(m_panel
->IsUsingGeneric());
164 void OnCalRClick(wxMouseEvent
& event
);
168 wxTextCtrl
*m_logWindow
;
170 // any class wishing to process wxWidgets events must use this macro
171 DECLARE_EVENT_TABLE()
174 #if wxUSE_DATEPICKCTRL
176 // Define a simple modal dialog which asks the user for a date
177 class MyDialog
: public wxDialog
180 MyDialog(wxWindow
*parent
, const wxDateTime
& dt
, int dtpStyle
);
182 wxDateTime
GetDate() const { return m_datePicker
->GetValue(); }
185 void OnDateChange(wxDateEvent
& event
);
188 wxDatePickerCtrlBase
*m_datePicker
;
192 DECLARE_EVENT_TABLE()
195 #endif // wxUSE_DATEPICKCTRL
197 // ----------------------------------------------------------------------------
199 // ----------------------------------------------------------------------------
201 // IDs for the controls and the menu commands
205 Calendar_File_About
= wxID_ABOUT
,
206 Calendar_File_ClearLog
= wxID_CLEAR
,
207 Calendar_File_Quit
= wxID_EXIT
,
208 Calendar_Cal_Generic
= 200,
210 Calendar_Cal_Holidays
,
211 Calendar_Cal_Special
,
213 Calendar_Cal_SeqMonth
,
214 Calendar_Cal_SurroundWeeks
,
215 Calendar_Cal_SetDate
,
217 Calendar_Cal_BeginDST
,
218 Calendar_Cal_Resizable
,
219 #if wxUSE_DATEPICKCTRL
220 Calendar_DatePicker_AskDate
= 300,
221 Calendar_DatePicker_ShowCentury
,
222 Calendar_DatePicker_DropDown
,
223 Calendar_DatePicker_AllowNone
,
224 Calendar_DatePicker_StartWithNone
,
225 #if wxUSE_DATEPICKCTRL_GENERIC
226 Calendar_DatePicker_Generic
,
227 #endif // wxUSE_DATEPICKCTRL_GENERIC
228 #endif // wxUSE_DATEPICKCTRL
229 Calendar_CalCtrl
= 1000
232 // ----------------------------------------------------------------------------
233 // event tables and other macros for wxWidgets
234 // ----------------------------------------------------------------------------
236 // the event tables connect the wxWidgets events with the functions (event
237 // handlers) which process them. It can be also done at run-time, but for the
238 // simple menu events like this the static method is much simpler.
239 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
240 EVT_MENU(Calendar_File_About
, MyFrame::OnAbout
)
241 EVT_MENU(Calendar_File_ClearLog
, MyFrame::OnClearLog
)
242 EVT_MENU(Calendar_File_Quit
, MyFrame::OnQuit
)
244 #if wxUSE_DATEPICKCTRL
245 EVT_MENU(Calendar_DatePicker_AskDate
, MyFrame::OnAskDate
)
247 EVT_UPDATE_UI(Calendar_DatePicker_StartWithNone
,
248 MyFrame::OnUpdateUIStartWithNone
)
249 #endif // wxUSE_DATEPICKCTRL
251 #ifdef wxHAS_NATIVE_CALENDARCTRL
252 EVT_MENU(Calendar_Cal_Generic
, MyFrame::OnCalGeneric
)
253 #endif // wxHAS_NATIVE_CALENDARCTRL
255 EVT_MENU(Calendar_Cal_Monday
, MyFrame::OnCalMonday
)
256 EVT_MENU(Calendar_Cal_Holidays
, MyFrame::OnCalHolidays
)
257 EVT_MENU(Calendar_Cal_Special
, MyFrame::OnCalSpecial
)
259 EVT_MENU(Calendar_Cal_Month
, MyFrame::OnCalAllowMonth
)
261 EVT_MENU(Calendar_Cal_SeqMonth
, MyFrame::OnCalSeqMonth
)
262 EVT_MENU(Calendar_Cal_SurroundWeeks
, MyFrame::OnCalShowSurroundingWeeks
)
264 EVT_MENU(Calendar_Cal_SetDate
, MyFrame::OnSetDate
)
265 EVT_MENU(Calendar_Cal_Today
, MyFrame::OnToday
)
266 EVT_MENU(Calendar_Cal_BeginDST
, MyFrame::OnBeginDST
)
268 EVT_MENU(Calendar_Cal_Resizable
, MyFrame::OnCalToggleResizable
)
271 EVT_UPDATE_UI(Calendar_Cal_SeqMonth
, MyFrame::OnUpdateUIGenericOnly
)
272 EVT_UPDATE_UI(Calendar_Cal_Monday
, MyFrame::OnUpdateUIGenericOnly
)
273 EVT_UPDATE_UI(Calendar_Cal_Holidays
, MyFrame::OnUpdateUIGenericOnly
)
274 EVT_UPDATE_UI(Calendar_Cal_Special
, MyFrame::OnUpdateUIGenericOnly
)
275 EVT_UPDATE_UI(Calendar_Cal_SurroundWeeks
, MyFrame::OnUpdateUIGenericOnly
)
278 BEGIN_EVENT_TABLE(MyPanel
, wxPanel
)
279 EVT_CALENDAR(Calendar_CalCtrl
, MyPanel::OnCalendar
)
280 EVT_CALENDAR_PAGE_CHANGED(Calendar_CalCtrl
, MyPanel::OnCalMonthChange
)
281 EVT_CALENDAR_SEL_CHANGED(Calendar_CalCtrl
, MyPanel::OnCalendarChange
)
282 EVT_CALENDAR_WEEKDAY_CLICKED(Calendar_CalCtrl
, MyPanel::OnCalendarWeekDayClick
)
285 #if wxUSE_DATEPICKCTRL
287 BEGIN_EVENT_TABLE(MyDialog
, wxDialog
)
288 EVT_DATE_CHANGED(wxID_ANY
, MyDialog::OnDateChange
)
291 #endif // wxUSE_DATEPICKCTRL
293 // Create a new application object: this macro will allow wxWidgets to create
294 // the application object during program execution (it's better than using a
295 // static object for many reasons) and also declares the accessor function
296 // wxGetApp() which will return the reference of the right type (i.e. MyApp and
300 // ============================================================================
302 // ============================================================================
304 // ----------------------------------------------------------------------------
305 // the application class
306 // ----------------------------------------------------------------------------
308 // `Main program' equivalent: the program execution "starts" here
311 if ( !wxApp::OnInit() )
314 // Create the main application window
315 MyFrame
*frame
= new MyFrame(_T("Calendar wxWidgets sample")
317 ,wxPoint(50, 50), wxSize(450, 340)
323 // success: wxApp::OnRun() will be called which will enter the main message
324 // loop and the application will run. If we returned false here, the
325 // application would exit immediately.
329 // ----------------------------------------------------------------------------
331 // ----------------------------------------------------------------------------
334 MyFrame::MyFrame(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
)
335 : wxFrame((wxFrame
*)NULL
, wxID_ANY
, title
, pos
, size
)
337 // set the frame icon
338 SetIcon(wxIcon(sample_xpm
));
341 wxMenu
*menuFile
= new wxMenu
;
342 menuFile
->Append(Calendar_File_About
, _T("&About...\tCtrl-A"), _T("Show about dialog"));
343 menuFile
->AppendSeparator();
344 menuFile
->Append(Calendar_File_ClearLog
, _T("&Clear log\tCtrl-L"));
345 menuFile
->AppendSeparator();
346 menuFile
->Append(Calendar_File_Quit
, _T("E&xit\tAlt-X"), _T("Quit this program"));
348 wxMenu
*menuCal
= new wxMenu
;
349 #ifdef wxHAS_NATIVE_CALENDARCTRL
350 menuCal
->AppendCheckItem(Calendar_Cal_Generic
, "Use &generic version\tCtrl-G",
351 "Toggle between native and generic control");
352 menuCal
->AppendSeparator();
353 #endif // wxHAS_NATIVE_CALENDARCTRL
354 menuCal
->Append(Calendar_Cal_Monday
,
355 _T("Monday &first weekday\tCtrl-F"),
356 _T("Toggle between Mon and Sun as the first week day"),
358 menuCal
->Append(Calendar_Cal_Holidays
, _T("Show &holidays\tCtrl-H"),
359 _T("Toggle highlighting the holidays"),
361 menuCal
->Append(Calendar_Cal_Special
, _T("Highlight &special dates\tCtrl-S"),
362 _T("Test custom highlighting"),
364 menuCal
->Append(Calendar_Cal_SurroundWeeks
,
365 _T("Show s&urrounding weeks\tCtrl-W"),
366 _T("Show the neighbouring weeks in the prev/next month"),
368 menuCal
->AppendSeparator();
369 menuCal
->Append(Calendar_Cal_SeqMonth
,
370 _T("Toggle month selector st&yle\tCtrl-Y"),
371 _T("Use another style for the calendar controls"),
373 menuCal
->Append(Calendar_Cal_Month
, _T("&Month can be changed\tCtrl-M"),
374 _T("Allow changing the month in the calendar"),
376 menuCal
->AppendSeparator();
377 menuCal
->Append(Calendar_Cal_SetDate
, _T("Call &SetDate(2005-12-24)"), _T("Set date to 2005-12-24."));
378 menuCal
->Append(Calendar_Cal_Today
, _T("Call &Today()"), _T("Set to the current date."));
379 menuCal
->Append(Calendar_Cal_BeginDST
, "Call SetDate(GetBeginDST())");
380 menuCal
->AppendSeparator();
381 menuCal
->AppendCheckItem(Calendar_Cal_Resizable
, _T("Make &resizable\tCtrl-R"));
383 #if wxUSE_DATEPICKCTRL
384 wxMenu
*menuDate
= new wxMenu
;
385 menuDate
->AppendCheckItem(Calendar_DatePicker_ShowCentury
,
386 _T("Al&ways show century"));
387 menuDate
->AppendCheckItem(Calendar_DatePicker_DropDown
,
388 _T("Use &drop down control"));
389 menuDate
->AppendCheckItem(Calendar_DatePicker_AllowNone
,
390 _T("Allow &no date"));
391 menuDate
->AppendCheckItem(Calendar_DatePicker_StartWithNone
,
392 _T("Start &with no date"));
393 #if wxUSE_DATEPICKCTRL_GENERIC
394 menuDate
->AppendCheckItem(Calendar_DatePicker_Generic
,
395 _T("Use &generic version of the control"));
396 #endif // wxUSE_DATEPICKCTRL_GENERIC
397 menuDate
->AppendSeparator();
398 menuDate
->Append(Calendar_DatePicker_AskDate
, _T("&Choose date...\tCtrl-D"), _T("Show dialog with wxDatePickerCtrl"));
399 #endif // wxUSE_DATEPICKCTRL
401 // now append the freshly created menu to the menu bar...
402 wxMenuBar
*menuBar
= new wxMenuBar
;
403 menuBar
->Append(menuFile
, _T("&File"));
404 menuBar
->Append(menuCal
, _T("&Calendar"));
405 #if wxUSE_DATEPICKCTRL
406 menuBar
->Append(menuDate
, _T("&Date picker"));
407 #endif // wxUSE_DATEPICKCTRL
409 menuBar
->Check(Calendar_Cal_Monday
, true);
410 menuBar
->Check(Calendar_Cal_Holidays
, true);
411 menuBar
->Check(Calendar_Cal_Month
, true);
413 #if wxUSE_DATEPICKCTRL
414 menuBar
->Check(Calendar_DatePicker_ShowCentury
, true);
415 #endif // wxUSE_DATEPICKCTRL
417 // ... and attach this menu bar to the frame
420 wxSplitterWindow
*splitter
= new wxSplitterWindow(this, wxID_ANY
,
421 wxDefaultPosition
, wxDefaultSize
,
423 m_panel
= new MyPanel(splitter
);
424 m_logWindow
= new wxTextCtrl(splitter
, wxID_ANY
, wxEmptyString
,
425 wxDefaultPosition
, wxDefaultSize
,
426 wxTE_READONLY
| wxTE_MULTILINE
);
427 splitter
->SplitHorizontally(m_panel
, m_logWindow
);
428 splitter
->SetMinimumPaneSize(20);
429 wxLog::SetActiveTarget(new wxLogTextCtrl(m_logWindow
));
432 void MyFrame::OnQuit(wxCommandEvent
& WXUNUSED(event
))
434 // true is to force the frame to close
438 void MyFrame::OnAbout(wxCommandEvent
& WXUNUSED(event
))
440 wxMessageBox(_T("wxCalendarCtrl sample\n(c) 2000--2008 Vadim Zeitlin"),
441 _T("About Calendar"), wxOK
| wxICON_INFORMATION
, this);
444 void MyFrame::OnClearLog(wxCommandEvent
& WXUNUSED(event
))
446 m_logWindow
->Clear();
449 void MyFrame::OnCalMonday(wxCommandEvent
& event
)
451 m_panel
->ToggleCalStyle(event
.IsChecked(), wxCAL_MONDAY_FIRST
);
454 void MyFrame::OnCalHolidays(wxCommandEvent
& event
)
456 m_panel
->GetCal()->EnableHolidayDisplay(event
.IsChecked());
459 void MyFrame::OnCalSpecial(wxCommandEvent
& event
)
461 m_panel
->HighlightSpecial(GetMenuBar()->IsChecked(event
.GetId()));
464 void MyFrame::OnCalAllowMonth(wxCommandEvent
& event
)
466 m_panel
->GetCal()->EnableMonthChange(event
.IsChecked());
469 void MyFrame::OnCalSeqMonth(wxCommandEvent
& event
)
471 m_panel
->ToggleCalStyle(event
.IsChecked(),
472 wxCAL_SEQUENTIAL_MONTH_SELECTION
);
475 void MyFrame::OnCalShowSurroundingWeeks(wxCommandEvent
& event
)
477 m_panel
->ToggleCalStyle(event
.IsChecked(), wxCAL_SHOW_SURROUNDING_WEEKS
);
480 void MyFrame::OnSetDate(wxCommandEvent
&WXUNUSED(event
))
482 m_panel
->SetDate(wxDateTime(24, wxDateTime::Dec
, 2005, 22, 00, 00));
485 void MyFrame::OnToday(wxCommandEvent
&WXUNUSED(event
))
487 m_panel
->SetDate(wxDateTime::Today());
490 void MyFrame::OnBeginDST(wxCommandEvent
&WXUNUSED(event
))
492 m_panel
->SetDate(wxDateTime::GetBeginDST(m_panel
->GetDate().GetYear()));
495 void MyFrame::OnCalToggleResizable(wxCommandEvent
& event
)
497 wxSizer
* const sizer
= m_panel
->GetSizer();
498 wxSizerItem
* const item
= sizer
->GetItem(m_panel
->GetCal());
499 if ( event
.IsChecked() )
501 item
->SetProportion(1);
502 item
->SetFlag(wxEXPAND
);
504 else // not resizable
506 item
->SetProportion(0);
507 item
->SetFlag(wxALIGN_CENTER
);
513 void MyFrame::OnCalRClick(wxMouseEvent
& event
)
516 wxDateTime::WeekDay wd
;
518 const wxPoint pt
= event
.GetPosition();
519 wxString msg
= wxString::Format("Point (%d, %d) is ", pt
.x
, pt
.y
);
521 switch ( m_panel
->GetCal()->HitTest(pt
, &dt
, &wd
) )
524 wxFAIL_MSG( "unexpected" );
527 case wxCAL_HITTEST_NOWHERE
:
531 case wxCAL_HITTEST_HEADER
:
532 msg
+= wxString::Format("over %s", wxDateTime::GetWeekDayName(wd
));
535 case wxCAL_HITTEST_DAY
:
536 msg
+= wxString::Format("over %s", dt
.FormatISODate());
539 case wxCAL_HITTEST_INCMONTH
:
540 msg
+= "over next month button";
543 case wxCAL_HITTEST_DECMONTH
:
544 msg
+= "over previous month button";
547 case wxCAL_HITTEST_SURROUNDING_WEEK
:
548 msg
+= "over a day from another month";
552 wxLogMessage("%s", msg
);
555 #if wxUSE_DATEPICKCTRL
557 void MyFrame::OnUpdateUIStartWithNone(wxUpdateUIEvent
& event
)
559 // it only makes sense to start with invalid date if we can have no date
560 event
.Enable( GetMenuBar()->IsChecked(Calendar_DatePicker_AllowNone
) );
563 void MyFrame::OnAskDate(wxCommandEvent
& WXUNUSED(event
))
565 wxDateTime dt
= m_panel
->GetCal()->GetDate();
567 int style
= wxDP_DEFAULT
;
568 if ( GetMenuBar()->IsChecked(Calendar_DatePicker_ShowCentury
) )
569 style
|= wxDP_SHOWCENTURY
;
570 if ( GetMenuBar()->IsChecked(Calendar_DatePicker_DropDown
) )
571 style
|= wxDP_DROPDOWN
;
572 if ( GetMenuBar()->IsChecked(Calendar_DatePicker_AllowNone
) )
574 style
|= wxDP_ALLOWNONE
;
576 if ( GetMenuBar()->IsChecked(Calendar_DatePicker_StartWithNone
) )
577 dt
= wxDefaultDateTime
;
580 MyDialog
dlg(this, dt
, style
);
581 if ( dlg
.ShowModal() == wxID_OK
)
586 const wxDateTime today
= wxDateTime::Today();
588 if ( dt
.GetDay() == today
.GetDay() &&
589 dt
.GetMonth() == today
.GetMonth() )
591 wxMessageBox(_T("Happy birthday!"), _T("Calendar Sample"));
594 m_panel
->SetDate(dt
);
596 wxLogStatus(_T("Changed the date to your input"));
600 wxLogStatus(_T("No date entered"));
605 #endif // wxUSE_DATEPICKCTRL
607 // ----------------------------------------------------------------------------
609 // ----------------------------------------------------------------------------
611 MyPanel::MyPanel(wxWindow
*parent
)
612 : wxPanel(parent
, wxID_ANY
)
614 #ifdef wxHAS_NATIVE_CALENDARCTRL
615 m_usingGeneric
= false;
617 m_usingGeneric
= true;
621 date
.Printf(wxT("Selected date: %s"),
622 wxDateTime::Today().FormatISODate().c_str());
623 m_date
= new wxStaticText(this, wxID_ANY
, date
);
624 m_calendar
= DoCreateCalendar(wxDefaultDateTime
,
625 wxCAL_MONDAY_FIRST
| wxCAL_SHOW_HOLIDAYS
);
627 // adjust to vertical/horizontal display, check mostly dedicated to WinCE
628 bool horizontal
= ( wxSystemSettings::GetMetric(wxSYS_SCREEN_X
) > wxSystemSettings::GetMetric(wxSYS_SCREEN_Y
) );
629 m_sizer
= new wxBoxSizer( horizontal
? wxHORIZONTAL
: wxVERTICAL
);
631 m_sizer
->Add(m_date
, 0, wxALIGN_CENTER
| wxALL
, 10 );
632 m_sizer
->Add(m_calendar
, 0, wxALIGN_CENTER
| wxALIGN_LEFT
);
635 m_sizer
->SetSizeHints( this );
638 void MyPanel::OnCalendar(wxCalendarEvent
& event
)
640 m_calendar
->Mark(event
.GetDate().GetDay(), true);
641 wxLogMessage(wxT("Selected (and marked) %s from calendar."),
642 event
.GetDate().FormatISODate().c_str());
645 void MyPanel::OnCalendarChange(wxCalendarEvent
& event
)
648 s
.Printf(wxT("Selected date: %s"), event
.GetDate().FormatISODate().c_str());
654 void MyPanel::OnCalMonthChange(wxCalendarEvent
& event
)
656 wxLogStatus(wxT("Calendar month changed to %s %d"),
657 wxDateTime::GetMonthName(event
.GetDate().GetMonth()),
658 event
.GetDate().GetYear());
661 void MyPanel::OnCalendarWeekDayClick(wxCalendarEvent
& event
)
663 wxLogMessage(wxT("Clicked on %s"),
664 wxDateTime::GetWeekDayName(event
.GetWeekDay()).c_str());
667 wxCalendarCtrlBase
*MyPanel::DoCreateCalendar(const wxDateTime
& dt
, long style
)
669 wxCalendarCtrlBase
*calendar
;
670 #ifdef wxHAS_NATIVE_CALENDARCTRL
671 if ( m_usingGeneric
)
672 calendar
= new wxGenericCalendarCtrl(this, Calendar_CalCtrl
,
678 #endif // wxHAS_NATIVE_CALENDARCTRL
679 calendar
= new wxCalendarCtrl(this, Calendar_CalCtrl
,
685 calendar
->Connect(wxEVT_RIGHT_DOWN
,
686 wxMouseEventHandler(MyFrame::OnCalRClick
),
688 wxGetTopLevelParent(this));
693 void MyPanel::RecreateCalendar(long style
)
695 wxCalendarCtrlBase
*calendar
= DoCreateCalendar(m_calendar
->GetDate(), style
);
697 m_sizer
->Replace(m_calendar
, calendar
);
699 m_calendar
= calendar
;
704 void MyPanel::ToggleCalStyle(bool on
, int flag
)
706 long style
= m_calendar
->GetWindowStyle();
712 if ( flag
== wxCAL_SEQUENTIAL_MONTH_SELECTION
)
714 // changing this style requires recreating the control
715 RecreateCalendar(style
);
717 else // just changing the style is enough
719 m_calendar
->SetWindowStyle(style
);
721 m_calendar
->Refresh();
725 void MyPanel::HighlightSpecial(bool on
)
730 *attrRedCircle
= new wxCalendarDateAttr(wxCAL_BORDER_ROUND
, *wxRED
),
731 *attrGreenSquare
= new wxCalendarDateAttr(wxCAL_BORDER_SQUARE
, *wxGREEN
),
732 *attrHeaderLike
= new wxCalendarDateAttr(*wxBLUE
, *wxLIGHT_GREY
);
734 m_calendar
->SetAttr(17, attrRedCircle
);
735 m_calendar
->SetAttr(29, attrGreenSquare
);
736 m_calendar
->SetAttr(13, attrHeaderLike
);
740 m_calendar
->ResetAttr(17);
741 m_calendar
->ResetAttr(29);
742 m_calendar
->ResetAttr(13);
745 m_calendar
->Refresh();
749 // ----------------------------------------------------------------------------
751 // ----------------------------------------------------------------------------
753 #if wxUSE_DATEPICKCTRL
755 MyDialog::MyDialog(wxWindow
*parent
, const wxDateTime
& dt
, int dtpStyle
)
756 : wxDialog(parent
, wxID_ANY
, wxString(_T("Calendar: Choose a date")))
758 wxStdDialogButtonSizer
*sizerBtns
= new wxStdDialogButtonSizer
;
759 sizerBtns
->AddButton(new wxButton(this, wxID_OK
));
760 sizerBtns
->AddButton(new wxButton(this, wxID_CANCEL
));
761 sizerBtns
->Realize();
763 wxSizer
*sizerText
= new wxBoxSizer(wxHORIZONTAL
);
764 sizerText
->Add(new wxStaticText(this, wxID_ANY
, _T("Date in ISO format: ")),
765 wxSizerFlags().Border().Align(wxALIGN_CENTRE_VERTICAL
));
766 m_text
= new wxTextCtrl(this, wxID_ANY
);
767 sizerText
->Add(m_text
, wxSizerFlags().
768 Expand().Border().Align(wxALIGN_CENTRE_VERTICAL
));
770 wxSizer
*sizerTop
= new wxBoxSizer(wxVERTICAL
);
771 sizerTop
->Add(new wxStaticText
774 _T("Enter your birthday date (not before 20th century):")
776 wxSizerFlags().Border());
778 #if wxUSE_DATEPICKCTRL_GENERIC
779 wxFrame
*frame
= (wxFrame
*)wxGetTopLevelParent(parent
);
780 if ( frame
&& frame
->GetMenuBar()->IsChecked(Calendar_DatePicker_Generic
) )
781 m_datePicker
= new wxDatePickerCtrlGeneric(this, wxID_ANY
, dt
,
786 #endif // wxUSE_DATEPICKCTRL_GENERIC
787 m_datePicker
= new wxDatePickerCtrl(this, wxID_ANY
, dt
,
788 wxDefaultPosition
, wxDefaultSize
,
790 m_datePicker
->SetRange(wxDateTime(1, wxDateTime::Jan
, 1900),
792 sizerTop
->Add(m_datePicker
, wxSizerFlags().Expand().Border());
794 sizerTop
->AddStretchSpacer(1);
795 sizerTop
->Add(sizerText
);
797 sizerTop
->Add(sizerBtns
, wxSizerFlags().Centre().Border());
799 SetSizerAndFit(sizerTop
);
803 void MyDialog::OnDateChange(wxDateEvent
& event
)
805 const wxDateTime dt
= event
.GetDate();
807 m_text
->SetValue(dt
.FormatISODate());
809 m_text
->SetValue(wxEmptyString
);
812 #endif // wxUSE_DATEPICKCTRL