X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/908f8fc481c0503bf8be5002e5d5208666da7649..a0232aa5207651deaf980c68f79546eed6327af7:/samples/calendar/calendar.cpp diff --git a/samples/calendar/calendar.cpp b/samples/calendar/calendar.cpp index cac040b249..719f4b2f1e 100644 --- a/samples/calendar/calendar.cpp +++ b/samples/calendar/calendar.cpp @@ -93,6 +93,7 @@ public: private: wxCalendarCtrl *m_calendar; wxStaticText *m_date; + wxSizer *m_sizer; DECLARE_EVENT_TABLE() }; @@ -127,6 +128,8 @@ public: void OnSetDate(wxCommandEvent& event); void OnToday(wxCommandEvent& event); + void OnCalToggleResizable(wxCommandEvent& event); + void OnAllowYearUpdate(wxUpdateUIEvent& event); private: @@ -178,6 +181,7 @@ enum Calendar_Cal_SurroundWeeks, Calendar_Cal_SetDate, Calendar_Cal_Today, + Calendar_Cal_Resizable, #if wxUSE_DATEPICKCTRL Calendar_DatePicker_AskDate = 300, Calendar_DatePicker_ShowCentury, @@ -222,6 +226,8 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame) EVT_MENU(Calendar_Cal_SetDate, MyFrame::OnSetDate) EVT_MENU(Calendar_Cal_Today, MyFrame::OnToday) + EVT_MENU(Calendar_Cal_Resizable, MyFrame::OnCalToggleResizable) + EVT_UPDATE_UI(Calendar_Cal_Year, MyFrame::OnAllowYearUpdate) END_EVENT_TABLE() @@ -321,6 +327,8 @@ MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size) menuCal->AppendSeparator(); menuCal->Append(Calendar_Cal_SetDate, _T("Call &SetDate(2005-12-24)"), _T("Set date to 2005-12-24.")); menuCal->Append(Calendar_Cal_Today, _T("Call &Today()"), _T("Set the current date.")); + menuCal->AppendSeparator(); + menuCal->AppendCheckItem(Calendar_Cal_Resizable, _T("Make &resizable\tCtrl-R")); #if wxUSE_DATEPICKCTRL wxMenu *menuDate = new wxMenu; @@ -443,6 +451,24 @@ void MyFrame::OnToday(wxCommandEvent &WXUNUSED(event)) m_panel->Today(); } +void MyFrame::OnCalToggleResizable(wxCommandEvent& event) +{ + wxSizer * const sizer = m_panel->GetSizer(); + wxSizerItem * const item = sizer->GetItem(m_panel->GetCal()); + if ( event.IsChecked() ) + { + item->SetProportion(1); + item->SetFlag(wxEXPAND); + } + else // not resizable + { + item->SetProportion(0); + item->SetFlag(wxALIGN_CENTER); + } + + sizer->Layout(); +} + #if wxUSE_DATEPICKCTRL void MyFrame::OnUpdateUIStartWithNone(wxUpdateUIEvent& event) @@ -516,7 +542,7 @@ MyPanel::MyPanel(wxFrame *frame) // adjust to vertical/horizontal display, check mostly dedicated to WinCE bool horizontal = ( wxSystemSettings::GetMetric(wxSYS_SCREEN_X) > wxSystemSettings::GetMetric(wxSYS_SCREEN_Y) ); - wxBoxSizer *m_sizer = new wxBoxSizer( horizontal ? wxHORIZONTAL : wxVERTICAL ); + m_sizer = new wxBoxSizer( horizontal ? wxHORIZONTAL : wxVERTICAL ); m_sizer->Add(m_date, 0, wxALIGN_CENTER | wxALL, 10 ); m_sizer->Add(m_calendar, 0, wxALIGN_CENTER | wxALIGN_LEFT); @@ -563,9 +589,26 @@ void MyPanel::ToggleCalStyle(bool on, int flag) else style &= ~flag; - m_calendar->SetWindowStyle(style); + if ( flag == wxCAL_SEQUENTIAL_MONTH_SELECTION ) + { + // changing this style requires recreating the control + wxCalendarCtrl *calendar = new wxCalendarCtrl(this, Calendar_CalCtrl, + m_calendar->GetDate(), + wxDefaultPosition, + wxDefaultSize, + style); + m_sizer->Replace(m_calendar, calendar); + delete m_calendar; + m_calendar = calendar; + + m_sizer->Layout(); + } + else // just changing the style is enough + { + m_calendar->SetWindowStyle(style); - m_calendar->Refresh(); + m_calendar->Refresh(); + } } void MyPanel::HighlightSpecial(bool on)