// if the date isn't visible (-1, -1) is put in (day, week) and false is returned
bool GetDateCoord(const wxDateTime& date, int *day, int *week) const;
+ // Set the flag for SetDate(): otherwise it would overwrite the year
+ // typed in by the user
+ void SetUserChangedYear() { m_userChangedYear = TRUE; }
+
// the subcontrols
wxStaticText *m_staticMonth;
wxComboBox *m_comboMonth;
void HighlightSpecial(bool on);
+ void SetDate();
+ void Today();
+
private:
wxCalendarCtrl *m_calendar;
wxStaticText *m_date;
void OnCalSeqMonth(wxCommandEvent& event);
void OnCalShowSurroundingWeeks(wxCommandEvent& event);
+ void OnSetDate(wxCommandEvent& event);
+ void OnToday(wxCommandEvent& event);
+
void OnAllowYearUpdate(wxUpdateUIEvent& event);
private:
Calendar_Cal_Year,
Calendar_Cal_SeqMonth,
Calendar_Cal_SurroundWeeks,
+ Calendar_Cal_SetDate,
+ Calendar_Cal_Today,
Calendar_CalCtrl = 1000
};
EVT_MENU(Calendar_Cal_SeqMonth, MyFrame::OnCalSeqMonth)
EVT_MENU(Calendar_Cal_SurroundWeeks, MyFrame::OnCalShowSurroundingWeeks)
+ EVT_MENU(Calendar_Cal_SetDate, MyFrame::OnSetDate)
+ EVT_MENU(Calendar_Cal_Today, MyFrame::OnToday)
+
+
EVT_UPDATE_UI(Calendar_Cal_Year, MyFrame::OnAllowYearUpdate)
END_EVENT_TABLE()
menuCal->Append(Calendar_Cal_Year, _T("&Year can be changed\tCtrl-Y"),
_T("Allow changing the year in the calendar"),
TRUE);
+ menuCal->AppendSeparator();
+ menuCal->Append(Calendar_Cal_SetDate, "SetDate()", "Set date to 2005-12-24.");
+ menuCal->Append(Calendar_Cal_Today, "Today()", "Set the current date.");
// now append the freshly created menu to the menu bar...
wxMenuBar *menuBar = new wxMenuBar;
event.Enable( GetMenuBar()->IsChecked(Calendar_Cal_Month));
}
+void MyFrame::OnSetDate(wxCommandEvent &event)
+{
+ m_panel->SetDate();
+}
+
+void MyFrame::OnToday(wxCommandEvent &event)
+{
+ m_panel->Today();
+}
+
// ----------------------------------------------------------------------------
// MyPanel
// ----------------------------------------------------------------------------
m_calendar->Refresh();
}
+
+void MyPanel::SetDate()
+{
+ wxDateTime date(24, wxDateTime::Dec, 2005, 23, 59, 59);
+ m_calendar->SetDate(date);
+}
+
+void MyPanel::Today()
+{
+ m_calendar->SetDate(wxDateTime::Today());
+}
public:
wxYearSpinCtrl(wxCalendarCtrl *cal);
- void OnYearTextChange(wxCommandEvent& event) { m_cal->OnYearChange(event); }
+ void OnYearTextChange(wxCommandEvent& event)
+ {
+ m_cal->SetUserChangedYear();
+ m_cal->OnYearChange(event);
+ }
void OnYearChange(wxSpinEvent& event) { m_cal->OnYearChange(event); }
private:
{
if ( !m_userChangedYear )
m_spinYear->SetValue(m_date.Format(_T("%Y")));
- else // don't overwrite what the user typed in
- m_userChangedYear = FALSE;
}
}
}
}
+ m_userChangedYear = FALSE;
+
return retval;
}
return;
}
- // set the flag for SetDate(): otherwise it would overwrite the year
- // typed in by the user
- m_userChangedYear = TRUE;
-
wxDateTime::Tm tm = m_date.GetTm();
if ( tm.mday > wxDateTime::GetNumberOfDays(tm.mon, year) )