From: Robert Roebling Date: Thu, 17 Apr 2008 15:31:50 +0000 (+0000) Subject: [ 1936700 ] wxCAL_SHOW_WEEK_NUMBERS, slightly modified X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/7b0ccb8a603b4f97740acc65d9429bb58f7ba1bd [ 1936700 ] wxCAL_SHOW_WEEK_NUMBERS, slightly modified git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@53247 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/include/wx/calctrl.h b/include/wx/calctrl.h index b4144a2d1b..4d800cd3a5 100644 --- a/include/wx/calctrl.h +++ b/include/wx/calctrl.h @@ -48,7 +48,10 @@ enum wxCAL_SEQUENTIAL_MONTH_SELECTION = 0x0010, // show the neighbouring weeks in the previous and next month - wxCAL_SHOW_SURROUNDING_WEEKS = 0x0020 + wxCAL_SHOW_SURROUNDING_WEEKS = 0x0020, + + // show week numbers on the left side of the calendar. + wxCAL_SHOW_WEEK_NUMBERS = 0x0040 }; // ---------------------------------------------------------------------------- diff --git a/include/wx/gtk/calctrl.h b/include/wx/gtk/calctrl.h index 73b3d916ae..764bf6a069 100644 --- a/include/wx/gtk/calctrl.h +++ b/include/wx/gtk/calctrl.h @@ -42,6 +42,10 @@ public: virtual void Mark(size_t day, bool mark); + // implementation + // -------------- + wxDateTime m_selectedDate; + private: DECLARE_DYNAMIC_CLASS(wxGtkCalendarCtrl) DECLARE_NO_COPY_CLASS(wxGtkCalendarCtrl) diff --git a/interface/calctrl.h b/interface/calctrl.h index bb1f25fcb7..397b4760ef 100644 --- a/interface/calctrl.h +++ b/interface/calctrl.h @@ -237,6 +237,8 @@ enum wxCalendarHitTestResult @style{wxCAL_SEQUENTIAL_MONTH_SELECTION} Use alternative, more compact, style for the month and year selection controls. (only generic) + @style{wxCAL_SHOW_WEEK_NUMBERS} + Show week numbers on the left side of the calendar. (not in generic) @endStyleTable @beginEventTable{wxCalendarEvent} @@ -257,7 +259,7 @@ enum wxCalendarHitTestResult @category{ctrl} - @nativeimpl{wxgtk} + @nativeimpl{wxgtk,wxmsw} @see @ref page_samples_calendar, wxCalendarDateAttr, wxCalendarEvent, wxDatePickerCtrl diff --git a/samples/calendar/calendar.cpp b/samples/calendar/calendar.cpp index 586a955659..f81a70385b 100644 --- a/samples/calendar/calendar.cpp +++ b/samples/calendar/calendar.cpp @@ -149,6 +149,7 @@ public: void OnCalSeqMonth(wxCommandEvent& event); void OnCalShowSurroundingWeeks(wxCommandEvent& event); + void OnCalShowWeekNumbers(wxCommandEvent& event); void OnSetDate(wxCommandEvent& event); void OnToday(wxCommandEvent& event); @@ -212,6 +213,7 @@ enum Calendar_Cal_Month, Calendar_Cal_SeqMonth, Calendar_Cal_SurroundWeeks, + Calendar_Cal_WeekNumbers, Calendar_Cal_SetDate, Calendar_Cal_Today, Calendar_Cal_BeginDST, @@ -260,6 +262,7 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame) EVT_MENU(Calendar_Cal_SeqMonth, MyFrame::OnCalSeqMonth) EVT_MENU(Calendar_Cal_SurroundWeeks, MyFrame::OnCalShowSurroundingWeeks) + EVT_MENU(Calendar_Cal_WeekNumbers, MyFrame::OnCalShowWeekNumbers) EVT_MENU(Calendar_Cal_SetDate, MyFrame::OnSetDate) EVT_MENU(Calendar_Cal_Today, MyFrame::OnToday) @@ -367,6 +370,10 @@ MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size) _T("Show s&urrounding weeks\tCtrl-W"), _T("Show the neighbouring weeks in the prev/next month"), true); + menuCal->Append(Calendar_Cal_WeekNumbers, + _T("Show &week numbers"), + _T("Toggle week numbers"), + true); menuCal->AppendSeparator(); menuCal->Append(Calendar_Cal_SeqMonth, _T("Toggle month selector st&yle\tCtrl-Y"), @@ -479,6 +486,11 @@ void MyFrame::OnCalShowSurroundingWeeks(wxCommandEvent& event) m_panel->ToggleCalStyle(event.IsChecked(), wxCAL_SHOW_SURROUNDING_WEEKS); } +void MyFrame::OnCalShowWeekNumbers(wxCommandEvent& event) +{ + m_panel->ToggleCalStyle(event.IsChecked(), wxCAL_SHOW_WEEK_NUMBERS); +} + void MyFrame::OnSetDate(wxCommandEvent &WXUNUSED(event)) { m_panel->SetDate(wxDateTime(24, wxDateTime::Dec, 2005, 22, 00, 00)); @@ -717,7 +729,8 @@ void MyPanel::ToggleCalStyle(bool on, int flag) else style &= ~flag; - if ( flag == wxCAL_SEQUENTIAL_MONTH_SELECTION ) + if ( flag == wxCAL_SEQUENTIAL_MONTH_SELECTION + || flag == wxCAL_SHOW_WEEK_NUMBERS) { // changing this style requires recreating the control RecreateCalendar(style); diff --git a/src/gtk/calctrl.cpp b/src/gtk/calctrl.cpp index 9c5b2a1717..313a3e3dc6 100644 --- a/src/gtk/calctrl.cpp +++ b/src/gtk/calctrl.cpp @@ -28,7 +28,14 @@ extern "C" { static void gtk_day_selected_callback(GtkWidget *WXUNUSED(widget), wxGtkCalendarCtrl *cal) { + wxDateTime date = cal->GetDate(); + if (cal->m_selectedDate == date) + return; + + cal->m_selectedDate = date; + cal->GenerateEvent(wxEVT_CALENDAR_SEL_CHANGED); + // send deprecated event cal->GenerateEvent(wxEVT_CALENDAR_DAY_CHANGED); } @@ -85,6 +92,8 @@ bool wxGtkCalendarCtrl::Create(wxWindow *parent, if (style & wxCAL_NO_MONTH_CHANGE) g_object_set (G_OBJECT (m_widget), "no-month-change", true, NULL); + if (style & wxCAL_SHOW_WEEK_NUMBERS) + g_object_set (G_OBJECT (m_widget), "show-week-numbers", true, NULL); g_signal_connect_after(m_widget, "day-selected", G_CALLBACK (gtk_day_selected_callback), @@ -127,13 +136,22 @@ bool wxGtkCalendarCtrl::EnableMonthChange(bool enable) return true; } + bool wxGtkCalendarCtrl::SetDate(const wxDateTime& date) { + g_signal_handlers_block_by_func(m_widget, + (gpointer) gtk_day_selected_callback, this); + + m_selectedDate = date; int year = date.GetYear(); int month = date.GetMonth(); int day = date.GetDay(); gtk_calendar_select_month(GTK_CALENDAR(m_widget), month, year); gtk_calendar_select_day(GTK_CALENDAR(m_widget), day); + + g_signal_handlers_unblock_by_func( m_widget, + (gpointer) gtk_day_selected_callback, this); + return true; }