From e6a7a09d9d53f87fef0c18969fa7d429076789bb Mon Sep 17 00:00:00 2001 From: Lauri Nurmi Date: Sun, 9 Jul 2017 22:34:59 +0300 Subject: [PATCH] Use automatically selected first weekday by default in calendar sample Also create a wxLocale object with wxLANGUAGE_DEFAULT so that automatic selection has a better chance of doing the right thing across different platforms. --- samples/calendar/calendar.cpp | 46 ++++++++++++++++++++++++++++++----- 1 file changed, 40 insertions(+), 6 deletions(-) diff --git a/samples/calendar/calendar.cpp b/samples/calendar/calendar.cpp index 49e8442502..e37be237dc 100644 --- a/samples/calendar/calendar.cpp +++ b/samples/calendar/calendar.cpp @@ -70,7 +70,9 @@ // Define a new application type, each program should derive a class from wxApp class MyApp : public wxApp { + wxLocale m_locale; public: + MyApp(); // override base class virtuals // ---------------------------- @@ -153,6 +155,8 @@ public: } #endif // wxHAS_NATIVE_CALENDARCTRL + void OnCalAutoWeekday(wxCommandEvent& event); + void OnCalSunday(wxCommandEvent& event); void OnCalMonday(wxCommandEvent& event); void OnCalHolidays(wxCommandEvent& event); void OnCalSpecial(wxCommandEvent& event); @@ -240,6 +244,8 @@ enum Calendar_File_ClearLog = wxID_CLEAR, Calendar_File_Quit = wxID_EXIT, Calendar_Cal_Generic = 200, + Calendar_Cal_AutoWeekday, + Calendar_Cal_Sunday, Calendar_Cal_Monday, Calendar_Cal_Holidays, Calendar_Cal_Special, @@ -298,6 +304,8 @@ wxBEGIN_EVENT_TABLE(MyFrame, wxFrame) EVT_MENU(Calendar_Cal_Generic, MyFrame::OnCalGeneric) #endif // wxHAS_NATIVE_CALENDARCTRL + EVT_MENU(Calendar_Cal_AutoWeekday, MyFrame::OnCalAutoWeekday) + EVT_MENU(Calendar_Cal_Sunday, MyFrame::OnCalSunday) EVT_MENU(Calendar_Cal_Monday, MyFrame::OnCalMonday) EVT_MENU(Calendar_Cal_Holidays, MyFrame::OnCalHolidays) EVT_MENU(Calendar_Cal_Special, MyFrame::OnCalSpecial) @@ -319,6 +327,8 @@ wxBEGIN_EVENT_TABLE(MyFrame, wxFrame) EVT_UPDATE_UI(Calendar_Cal_SeqMonth, MyFrame::OnUpdateUIGenericOnly) #ifdef __WXGTK20__ + EVT_UPDATE_UI(Calendar_Cal_AutoWeekday, MyFrame::OnUpdateUIGenericOnly) + EVT_UPDATE_UI(Calendar_Cal_Sunday, MyFrame::OnUpdateUIGenericOnly) EVT_UPDATE_UI(Calendar_Cal_Monday, MyFrame::OnUpdateUIGenericOnly) EVT_UPDATE_UI(Calendar_Cal_Holidays, MyFrame::OnUpdateUIGenericOnly) #endif @@ -349,6 +359,13 @@ wxIMPLEMENT_APP(MyApp); // the application class // ---------------------------------------------------------------------------- +MyApp::MyApp() : + // Locale affects on the language used in the calendar, and may affect + // on the first day of the week. + m_locale(wxLANGUAGE_DEFAULT) +{ +} + // `Main program' equivalent: the program execution "starts" here bool MyApp::OnInit() { @@ -396,10 +413,12 @@ MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size) "Toggle between native and generic control"); menuCal->AppendSeparator(); #endif // wxHAS_NATIVE_CALENDARCTRL - menuCal->Append(Calendar_Cal_Monday, - wxT("Monday &first weekday\tCtrl-F"), - wxT("Toggle between Mon and Sun as the first week day"), - true); + menuCal->AppendRadioItem(Calendar_Cal_AutoWeekday, + wxT("Automatic &first weekday\tCtrl-V")); + menuCal->AppendRadioItem(Calendar_Cal_Sunday, + wxT("Sunday &first weekday\tCtrl-Z")); + menuCal->AppendRadioItem(Calendar_Cal_Monday, + wxT("Monday &first weekday\tCtrl-F")); menuCal->Append(Calendar_Cal_Holidays, wxT("Show &holidays\tCtrl-H"), wxT("Toggle highlighting the holidays"), true); @@ -462,7 +481,9 @@ MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size) menuBar->Append(menuTime, wxT("&Time picker")); #endif // wxUSE_TIMEPICKCTRL - menuBar->Check(Calendar_Cal_Monday, true); + menuBar->Check(Calendar_Cal_AutoWeekday, true); + menuBar->Check(Calendar_Cal_Sunday, false); + menuBar->Check(Calendar_Cal_Monday, false); menuBar->Check(Calendar_Cal_Holidays, true); menuBar->Check(Calendar_Cal_Month, true); menuBar->Check(Calendar_Cal_LimitDates, false); @@ -503,8 +524,21 @@ void MyFrame::OnClearLog(wxCommandEvent& WXUNUSED(event)) m_logWindow->Clear(); } +void MyFrame::OnCalAutoWeekday(wxCommandEvent&) +{ + m_panel->ToggleCalStyle(false, wxCAL_SUNDAY_FIRST); + m_panel->ToggleCalStyle(false, wxCAL_MONDAY_FIRST); +} + +void MyFrame::OnCalSunday(wxCommandEvent& event) +{ + m_panel->ToggleCalStyle(false, wxCAL_MONDAY_FIRST); + m_panel->ToggleCalStyle(event.IsChecked(), wxCAL_SUNDAY_FIRST); +} + void MyFrame::OnCalMonday(wxCommandEvent& event) { + m_panel->ToggleCalStyle(false, wxCAL_SUNDAY_FIRST); m_panel->ToggleCalStyle(event.IsChecked(), wxCAL_MONDAY_FIRST); } @@ -702,7 +736,7 @@ MyPanel::MyPanel(wxWindow *parent) wxDateTime::Today().FormatISODate().c_str()); m_date = new wxStaticText(this, wxID_ANY, date); m_calendar = DoCreateCalendar(wxDefaultDateTime, - wxCAL_MONDAY_FIRST | wxCAL_SHOW_HOLIDAYS); + wxCAL_SHOW_HOLIDAYS); // adjust to vertical/horizontal display bool horizontal = ( wxSystemSettings::GetMetric(wxSYS_SCREEN_X) > wxSystemSettings::GetMetric(wxSYS_SCREEN_Y) );