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
)
273 EVT_UPDATE_UI(Calendar_Cal_Monday
, MyFrame::OnUpdateUIGenericOnly
)
275 EVT_UPDATE_UI(Calendar_Cal_Holidays
, MyFrame::OnUpdateUIGenericOnly
)
276 EVT_UPDATE_UI(Calendar_Cal_Special
, MyFrame::OnUpdateUIGenericOnly
)
277 EVT_UPDATE_UI(Calendar_Cal_SurroundWeeks
, MyFrame::OnUpdateUIGenericOnly
)
280 BEGIN_EVENT_TABLE(MyPanel
, wxPanel
)
281 EVT_CALENDAR(Calendar_CalCtrl
, MyPanel::OnCalendar
)
282 EVT_CALENDAR_PAGE_CHANGED(Calendar_CalCtrl
, MyPanel::OnCalMonthChange
)
283 EVT_CALENDAR_SEL_CHANGED(Calendar_CalCtrl
, MyPanel::OnCalendarChange
)
284 EVT_CALENDAR_WEEKDAY_CLICKED(Calendar_CalCtrl
, MyPanel::OnCalendarWeekDayClick
)
287 #if wxUSE_DATEPICKCTRL
289 BEGIN_EVENT_TABLE(MyDialog
, wxDialog
)
290 EVT_DATE_CHANGED(wxID_ANY
, MyDialog::OnDateChange
)
293 #endif // wxUSE_DATEPICKCTRL
295 // Create a new application object: this macro will allow wxWidgets to create
296 // the application object during program execution (it's better than using a
297 // static object for many reasons) and also declares the accessor function
298 // wxGetApp() which will return the reference of the right type (i.e. MyApp and
302 // ============================================================================
304 // ============================================================================
306 // ----------------------------------------------------------------------------
307 // the application class
308 // ----------------------------------------------------------------------------
310 // `Main program' equivalent: the program execution "starts" here
313 if ( !wxApp::OnInit() )
316 // Create the main application window
317 MyFrame
*frame
= new MyFrame(_T("Calendar wxWidgets sample")
319 ,wxPoint(50, 50), wxSize(450, 340)
325 // success: wxApp::OnRun() will be called which will enter the main message
326 // loop and the application will run. If we returned false here, the
327 // application would exit immediately.
331 // ----------------------------------------------------------------------------
333 // ----------------------------------------------------------------------------
336 MyFrame::MyFrame(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
)
337 : wxFrame((wxFrame
*)NULL
, wxID_ANY
, title
, pos
, size
)
339 // set the frame icon
340 SetIcon(wxIcon(sample_xpm
));
343 wxMenu
*menuFile
= new wxMenu
;
344 menuFile
->Append(Calendar_File_About
, _T("&About...\tCtrl-A"), _T("Show about dialog"));
345 menuFile
->AppendSeparator();
346 menuFile
->Append(Calendar_File_ClearLog
, _T("&Clear log\tCtrl-L"));
347 menuFile
->AppendSeparator();
348 menuFile
->Append(Calendar_File_Quit
, _T("E&xit\tAlt-X"), _T("Quit this program"));
350 wxMenu
*menuCal
= new wxMenu
;
351 #ifdef wxHAS_NATIVE_CALENDARCTRL
352 menuCal
->AppendCheckItem(Calendar_Cal_Generic
, "Use &generic version\tCtrl-G",
353 "Toggle between native and generic control");
354 menuCal
->AppendSeparator();
355 #endif // wxHAS_NATIVE_CALENDARCTRL
356 menuCal
->Append(Calendar_Cal_Monday
,
357 _T("Monday &first weekday\tCtrl-F"),
358 _T("Toggle between Mon and Sun as the first week day"),
360 menuCal
->Append(Calendar_Cal_Holidays
, _T("Show &holidays\tCtrl-H"),
361 _T("Toggle highlighting the holidays"),
363 menuCal
->Append(Calendar_Cal_Special
, _T("Highlight &special dates\tCtrl-S"),
364 _T("Test custom highlighting"),
366 menuCal
->Append(Calendar_Cal_SurroundWeeks
,
367 _T("Show s&urrounding weeks\tCtrl-W"),
368 _T("Show the neighbouring weeks in the prev/next month"),
370 menuCal
->AppendSeparator();
371 menuCal
->Append(Calendar_Cal_SeqMonth
,
372 _T("Toggle month selector st&yle\tCtrl-Y"),
373 _T("Use another style for the calendar controls"),
375 menuCal
->Append(Calendar_Cal_Month
, _T("&Month can be changed\tCtrl-M"),
376 _T("Allow changing the month in the calendar"),
378 menuCal
->AppendSeparator();
379 menuCal
->Append(Calendar_Cal_SetDate
, _T("Call &SetDate(2005-12-24)"), _T("Set date to 2005-12-24."));
380 menuCal
->Append(Calendar_Cal_Today
, _T("Call &Today()"), _T("Set to the current date."));
381 menuCal
->Append(Calendar_Cal_BeginDST
, "Call SetDate(GetBeginDST())");
382 menuCal
->AppendSeparator();
383 menuCal
->AppendCheckItem(Calendar_Cal_Resizable
, _T("Make &resizable\tCtrl-R"));
385 #if wxUSE_DATEPICKCTRL
386 wxMenu
*menuDate
= new wxMenu
;
387 menuDate
->AppendCheckItem(Calendar_DatePicker_ShowCentury
,
388 _T("Al&ways show century"));
389 menuDate
->AppendCheckItem(Calendar_DatePicker_DropDown
,
390 _T("Use &drop down control"));
391 menuDate
->AppendCheckItem(Calendar_DatePicker_AllowNone
,
392 _T("Allow &no date"));
393 menuDate
->AppendCheckItem(Calendar_DatePicker_StartWithNone
,
394 _T("Start &with no date"));
395 #if wxUSE_DATEPICKCTRL_GENERIC
396 menuDate
->AppendCheckItem(Calendar_DatePicker_Generic
,
397 _T("Use &generic version of the control"));
398 #endif // wxUSE_DATEPICKCTRL_GENERIC
399 menuDate
->AppendSeparator();
400 menuDate
->Append(Calendar_DatePicker_AskDate
, _T("&Choose date...\tCtrl-D"), _T("Show dialog with wxDatePickerCtrl"));
401 #endif // wxUSE_DATEPICKCTRL
403 // now append the freshly created menu to the menu bar...
404 wxMenuBar
*menuBar
= new wxMenuBar
;
405 menuBar
->Append(menuFile
, _T("&File"));
406 menuBar
->Append(menuCal
, _T("&Calendar"));
407 #if wxUSE_DATEPICKCTRL
408 menuBar
->Append(menuDate
, _T("&Date picker"));
409 #endif // wxUSE_DATEPICKCTRL
411 menuBar
->Check(Calendar_Cal_Monday
, true);
412 menuBar
->Check(Calendar_Cal_Holidays
, true);
413 menuBar
->Check(Calendar_Cal_Month
, true);
415 #if wxUSE_DATEPICKCTRL
416 menuBar
->Check(Calendar_DatePicker_ShowCentury
, true);
417 #endif // wxUSE_DATEPICKCTRL
419 // ... and attach this menu bar to the frame
422 wxSplitterWindow
*splitter
= new wxSplitterWindow(this, wxID_ANY
,
423 wxDefaultPosition
, wxDefaultSize
,
425 m_panel
= new MyPanel(splitter
);
426 m_logWindow
= new wxTextCtrl(splitter
, wxID_ANY
, wxEmptyString
,
427 wxDefaultPosition
, wxDefaultSize
,
428 wxTE_READONLY
| wxTE_MULTILINE
);
429 splitter
->SplitHorizontally(m_panel
, m_logWindow
);
430 splitter
->SetMinimumPaneSize(20);
431 wxLog::SetActiveTarget(new wxLogTextCtrl(m_logWindow
));
434 void MyFrame::OnQuit(wxCommandEvent
& WXUNUSED(event
))
436 // true is to force the frame to close
440 void MyFrame::OnAbout(wxCommandEvent
& WXUNUSED(event
))
442 wxMessageBox(_T("wxCalendarCtrl sample\n(c) 2000--2008 Vadim Zeitlin"),
443 _T("About Calendar"), wxOK
| wxICON_INFORMATION
, this);
446 void MyFrame::OnClearLog(wxCommandEvent
& WXUNUSED(event
))
448 m_logWindow
->Clear();
451 void MyFrame::OnCalMonday(wxCommandEvent
& event
)
453 m_panel
->ToggleCalStyle(event
.IsChecked(), wxCAL_MONDAY_FIRST
);
456 void MyFrame::OnCalHolidays(wxCommandEvent
& event
)
458 m_panel
->GetCal()->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 void MyFrame::OnCalRClick(wxMouseEvent
& event
)
518 wxDateTime::WeekDay wd
;
520 const wxPoint pt
= event
.GetPosition();
521 wxString msg
= wxString::Format("Point (%d, %d) is ", pt
.x
, pt
.y
);
523 switch ( m_panel
->GetCal()->HitTest(pt
, &dt
, &wd
) )
526 wxFAIL_MSG( "unexpected" );
529 case wxCAL_HITTEST_NOWHERE
:
533 case wxCAL_HITTEST_HEADER
:
534 msg
+= wxString::Format("over %s", wxDateTime::GetWeekDayName(wd
));
537 case wxCAL_HITTEST_DAY
:
538 msg
+= wxString::Format("over %s", dt
.FormatISODate());
541 case wxCAL_HITTEST_INCMONTH
:
542 msg
+= "over next month button";
545 case wxCAL_HITTEST_DECMONTH
:
546 msg
+= "over previous month button";
549 case wxCAL_HITTEST_SURROUNDING_WEEK
:
550 msg
+= "over a day from another month";
554 wxLogMessage("%s", msg
);
557 #if wxUSE_DATEPICKCTRL
559 void MyFrame::OnUpdateUIStartWithNone(wxUpdateUIEvent
& event
)
561 // it only makes sense to start with invalid date if we can have no date
562 event
.Enable( GetMenuBar()->IsChecked(Calendar_DatePicker_AllowNone
) );
565 void MyFrame::OnAskDate(wxCommandEvent
& WXUNUSED(event
))
567 wxDateTime dt
= m_panel
->GetCal()->GetDate();
569 int style
= wxDP_DEFAULT
;
570 if ( GetMenuBar()->IsChecked(Calendar_DatePicker_ShowCentury
) )
571 style
|= wxDP_SHOWCENTURY
;
572 if ( GetMenuBar()->IsChecked(Calendar_DatePicker_DropDown
) )
573 style
|= wxDP_DROPDOWN
;
574 if ( GetMenuBar()->IsChecked(Calendar_DatePicker_AllowNone
) )
576 style
|= wxDP_ALLOWNONE
;
578 if ( GetMenuBar()->IsChecked(Calendar_DatePicker_StartWithNone
) )
579 dt
= wxDefaultDateTime
;
582 MyDialog
dlg(this, dt
, style
);
583 if ( dlg
.ShowModal() == wxID_OK
)
588 const wxDateTime today
= wxDateTime::Today();
590 if ( dt
.GetDay() == today
.GetDay() &&
591 dt
.GetMonth() == today
.GetMonth() )
593 wxMessageBox(_T("Happy birthday!"), _T("Calendar Sample"));
596 m_panel
->SetDate(dt
);
598 wxLogStatus(_T("Changed the date to your input"));
602 wxLogStatus(_T("No date entered"));
607 #endif // wxUSE_DATEPICKCTRL
609 // ----------------------------------------------------------------------------
611 // ----------------------------------------------------------------------------
613 MyPanel::MyPanel(wxWindow
*parent
)
614 : wxPanel(parent
, wxID_ANY
)
616 #ifdef wxHAS_NATIVE_CALENDARCTRL
617 m_usingGeneric
= false;
619 m_usingGeneric
= true;
623 date
.Printf(wxT("Selected date: %s"),
624 wxDateTime::Today().FormatISODate().c_str());
625 m_date
= new wxStaticText(this, wxID_ANY
, date
);
626 m_calendar
= DoCreateCalendar(wxDefaultDateTime
,
627 wxCAL_MONDAY_FIRST
| wxCAL_SHOW_HOLIDAYS
);
629 // adjust to vertical/horizontal display, check mostly dedicated to WinCE
630 bool horizontal
= ( wxSystemSettings::GetMetric(wxSYS_SCREEN_X
) > wxSystemSettings::GetMetric(wxSYS_SCREEN_Y
) );
631 m_sizer
= new wxBoxSizer( horizontal
? wxHORIZONTAL
: wxVERTICAL
);
633 m_sizer
->Add(m_date
, 0, wxALIGN_CENTER
| wxALL
, 10 );
634 m_sizer
->Add(m_calendar
, 0, wxALIGN_CENTER
| wxALIGN_LEFT
);
637 m_sizer
->SetSizeHints( this );
640 void MyPanel::OnCalendar(wxCalendarEvent
& event
)
642 // clicking the same date twice unmarks it (convenient for testing)
643 static wxDateTime s_dateLast
;
644 const bool mark
= !s_dateLast
.IsValid() || event
.GetDate() != s_dateLast
;
646 s_dateLast
= event
.GetDate();
648 m_calendar
->Mark(event
.GetDate().GetDay(), mark
);
649 wxLogMessage(wxT("Selected (and %smarked) %s from calendar."),
650 mark
? "" : "un", s_dateLast
.FormatISODate().c_str());
653 void MyPanel::OnCalendarChange(wxCalendarEvent
& event
)
656 s
.Printf(wxT("Selected date: %s"), event
.GetDate().FormatISODate().c_str());
662 void MyPanel::OnCalMonthChange(wxCalendarEvent
& event
)
664 wxLogStatus(wxT("Calendar month changed to %s %d"),
665 wxDateTime::GetMonthName(event
.GetDate().GetMonth()),
666 event
.GetDate().GetYear());
669 void MyPanel::OnCalendarWeekDayClick(wxCalendarEvent
& event
)
671 wxLogMessage(wxT("Clicked on %s"),
672 wxDateTime::GetWeekDayName(event
.GetWeekDay()).c_str());
675 wxCalendarCtrlBase
*MyPanel::DoCreateCalendar(const wxDateTime
& dt
, long style
)
677 wxCalendarCtrlBase
*calendar
;
678 #ifdef wxHAS_NATIVE_CALENDARCTRL
679 if ( m_usingGeneric
)
680 calendar
= new wxGenericCalendarCtrl(this, Calendar_CalCtrl
,
686 #endif // wxHAS_NATIVE_CALENDARCTRL
687 calendar
= new wxCalendarCtrl(this, Calendar_CalCtrl
,
693 calendar
->Connect(wxEVT_RIGHT_DOWN
,
694 wxMouseEventHandler(MyFrame::OnCalRClick
),
696 wxGetTopLevelParent(this));
701 void MyPanel::RecreateCalendar(long style
)
703 wxCalendarCtrlBase
*calendar
= DoCreateCalendar(m_calendar
->GetDate(), style
);
705 m_sizer
->Replace(m_calendar
, calendar
);
707 m_calendar
= calendar
;
712 void MyPanel::ToggleCalStyle(bool on
, int flag
)
714 long style
= m_calendar
->GetWindowStyle();
720 if ( flag
== wxCAL_SEQUENTIAL_MONTH_SELECTION
)
722 // changing this style requires recreating the control
723 RecreateCalendar(style
);
725 else // just changing the style is enough
727 m_calendar
->SetWindowStyle(style
);
729 m_calendar
->Refresh();
733 void MyPanel::HighlightSpecial(bool on
)
738 *attrRedCircle
= new wxCalendarDateAttr(wxCAL_BORDER_ROUND
, *wxRED
),
739 *attrGreenSquare
= new wxCalendarDateAttr(wxCAL_BORDER_SQUARE
, *wxGREEN
),
740 *attrHeaderLike
= new wxCalendarDateAttr(*wxBLUE
, *wxLIGHT_GREY
);
742 m_calendar
->SetAttr(17, attrRedCircle
);
743 m_calendar
->SetAttr(29, attrGreenSquare
);
744 m_calendar
->SetAttr(13, attrHeaderLike
);
748 m_calendar
->ResetAttr(17);
749 m_calendar
->ResetAttr(29);
750 m_calendar
->ResetAttr(13);
753 m_calendar
->Refresh();
757 // ----------------------------------------------------------------------------
759 // ----------------------------------------------------------------------------
761 #if wxUSE_DATEPICKCTRL
763 MyDialog::MyDialog(wxWindow
*parent
, const wxDateTime
& dt
, int dtpStyle
)
764 : wxDialog(parent
, wxID_ANY
, wxString(_T("Calendar: Choose a date")))
766 wxStdDialogButtonSizer
*sizerBtns
= new wxStdDialogButtonSizer
;
767 sizerBtns
->AddButton(new wxButton(this, wxID_OK
));
768 sizerBtns
->AddButton(new wxButton(this, wxID_CANCEL
));
769 sizerBtns
->Realize();
771 wxSizer
*sizerText
= new wxBoxSizer(wxHORIZONTAL
);
772 sizerText
->Add(new wxStaticText(this, wxID_ANY
, _T("Date in ISO format: ")),
773 wxSizerFlags().Border().Align(wxALIGN_CENTRE_VERTICAL
));
774 m_text
= new wxTextCtrl(this, wxID_ANY
);
775 sizerText
->Add(m_text
, wxSizerFlags().
776 Expand().Border().Align(wxALIGN_CENTRE_VERTICAL
));
778 wxSizer
*sizerTop
= new wxBoxSizer(wxVERTICAL
);
779 sizerTop
->Add(new wxStaticText
782 _T("Enter your birthday date (not before 20th century):")
784 wxSizerFlags().Border());
786 #if wxUSE_DATEPICKCTRL_GENERIC
787 wxFrame
*frame
= (wxFrame
*)wxGetTopLevelParent(parent
);
788 if ( frame
&& frame
->GetMenuBar()->IsChecked(Calendar_DatePicker_Generic
) )
789 m_datePicker
= new wxDatePickerCtrlGeneric(this, wxID_ANY
, dt
,
794 #endif // wxUSE_DATEPICKCTRL_GENERIC
795 m_datePicker
= new wxDatePickerCtrl(this, wxID_ANY
, dt
,
796 wxDefaultPosition
, wxDefaultSize
,
798 m_datePicker
->SetRange(wxDateTime(1, wxDateTime::Jan
, 1900),
800 sizerTop
->Add(m_datePicker
, wxSizerFlags().Expand().Border());
802 sizerTop
->AddStretchSpacer(1);
803 sizerTop
->Add(sizerText
);
805 sizerTop
->Add(sizerBtns
, wxSizerFlags().Centre().Border());
807 SetSizerAndFit(sizerTop
);
811 void MyDialog::OnDateChange(wxDateEvent
& event
)
813 const wxDateTime dt
= event
.GetDate();
815 m_text
->SetValue(dt
.FormatISODate());
817 m_text
->SetValue(wxEmptyString
);
820 #endif // wxUSE_DATEPICKCTRL