}
void HighlightSpecial(bool on);
+ void LimitDateRange(bool on);
wxDateTime GetDate() const { return m_calendar->GetDate(); }
void SetDate(const wxDateTime& dt) { m_calendar->SetDate(dt); }
void OnCalSpecial(wxCommandEvent& event);
void OnCalAllowMonth(wxCommandEvent& event);
-
+ void OnCalLimitDates(wxCommandEvent& event);
void OnCalSeqMonth(wxCommandEvent& event);
void OnCalShowSurroundingWeeks(wxCommandEvent& event);
void OnCalShowWeekNumbers(wxCommandEvent& event);
Calendar_Cal_Holidays,
Calendar_Cal_Special,
Calendar_Cal_Month,
+ Calendar_Cal_LimitDates,
Calendar_Cal_SeqMonth,
Calendar_Cal_SurroundWeeks,
Calendar_Cal_WeekNumbers,
EVT_MENU(Calendar_Cal_Month, MyFrame::OnCalAllowMonth)
+ EVT_MENU(Calendar_Cal_LimitDates, MyFrame::OnCalLimitDates)
+
EVT_MENU(Calendar_Cal_SeqMonth, MyFrame::OnCalSeqMonth)
EVT_MENU(Calendar_Cal_SurroundWeeks, MyFrame::OnCalShowSurroundingWeeks)
EVT_MENU(Calendar_Cal_WeekNumbers, MyFrame::OnCalShowWeekNumbers)
#ifdef __WXGTK20__
EVT_UPDATE_UI(Calendar_Cal_Monday, MyFrame::OnUpdateUIGenericOnly)
EVT_UPDATE_UI(Calendar_Cal_Holidays, MyFrame::OnUpdateUIGenericOnly)
+ EVT_UPDATE_UI(Calendar_Cal_LimitDates, MyFrame::OnUpdateUIGenericOnly)
#endif
EVT_UPDATE_UI(Calendar_Cal_Special, MyFrame::OnUpdateUIGenericOnly)
EVT_UPDATE_UI(Calendar_Cal_SurroundWeeks, MyFrame::OnUpdateUIGenericOnly)
menuCal->Append(Calendar_Cal_Month, wxT("&Month can be changed\tCtrl-M"),
wxT("Allow changing the month in the calendar"),
true);
+ menuCal->AppendCheckItem(Calendar_Cal_LimitDates, wxT("Toggle date ra&nge\tCtrl-N"),
+ wxT("Limit the valid dates"));
menuCal->AppendSeparator();
menuCal->Append(Calendar_Cal_SetDate, wxT("Call &SetDate(2005-12-24)"), wxT("Set date to 2005-12-24."));
menuCal->Append(Calendar_Cal_Today, wxT("Call &Today()"), wxT("Set to the current date."));
menuBar->Check(Calendar_Cal_Monday, true);
menuBar->Check(Calendar_Cal_Holidays, true);
menuBar->Check(Calendar_Cal_Month, true);
+ menuBar->Check(Calendar_Cal_LimitDates, false);
#if wxUSE_DATEPICKCTRL
menuBar->Check(Calendar_DatePicker_ShowCentury, true);
m_panel->HighlightSpecial(GetMenuBar()->IsChecked(event.GetId()));
}
+void MyFrame::OnCalLimitDates(wxCommandEvent& event)
+{
+ m_panel->LimitDateRange(GetMenuBar()->IsChecked(event.GetId()));
+}
+
void MyFrame::OnCalAllowMonth(wxCommandEvent& event)
{
m_panel->GetCal()->EnableMonthChange(event.IsChecked());
m_calendar->Refresh();
}
+// Toggle a restricted date range to the six months centered on today's date.
+void MyPanel::LimitDateRange(bool on)
+{
+ if ( on )
+ {
+ // limit the choice of date to 3 months around today
+ const wxDateSpan diff = wxDateSpan::Months(3);
+ const wxDateTime today = wxDateTime::Today();
+
+ // Set the restricted date range.
+ if ( m_calendar->SetDateRange(today - diff, today + diff) )
+ {
+ wxLogStatus("Date range limited to 3 months around today.");
+ }
+ else
+ {
+ wxLogWarning("Date range not supported.");
+ }
+ }
+ else // off
+ {
+ // Remove the date restrictions.
+ if ( m_calendar->SetDateRange() )
+ {
+ wxLogStatus("Date choice is unlimited now.");
+ }
+ else
+ {
+ wxLogWarning("Date range not supported.");
+ }
+ }
+
+ m_calendar->Refresh();
+}
// ----------------------------------------------------------------------------
// MyDialog