]> git.saurik.com Git - wxWidgets.git/commitdiff
[ 1936700 ] wxCAL_SHOW_WEEK_NUMBERS, slightly modified
authorRobert Roebling <robert@roebling.de>
Thu, 17 Apr 2008 15:31:50 +0000 (15:31 +0000)
committerRobert Roebling <robert@roebling.de>
Thu, 17 Apr 2008 15:31:50 +0000 (15:31 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@53247 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/calctrl.h
include/wx/gtk/calctrl.h
interface/calctrl.h
samples/calendar/calendar.cpp
src/gtk/calctrl.cpp

index b4144a2d1b7d1c115464b273e59a3d77156ff2cb..4d800cd3a557fea69c736dd4ad51e852f40233d7 100644 (file)
@@ -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
 };
 
 // ----------------------------------------------------------------------------
index 73b3d916ae8725b8b160e5ce487e0f65fb187033..764bf6a0690f181b93387deff04c84df4e8a5205 100644 (file)
@@ -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)
index bb1f25fcb7a379a30240f71c1e168fb4284221f5..397b4760ef73627783d755036866614a4b5cbe03 100644 (file)
@@ -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}
     <!-- @appearance{calendarctrl.png} -->
 
-    @nativeimpl{wxgtk}
+    @nativeimpl{wxgtk,wxmsw}
 
     @see @ref page_samples_calendar, wxCalendarDateAttr, wxCalendarEvent,
          wxDatePickerCtrl
index 586a9556595d0b2839c61155746a6424e796a343..f81a70385b546dd0accfb4ce6ec981a36786fd70 100644 (file)
@@ -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);
index 9c5b2a1717f664b2ec132fed89ed92296de99475..313a3e3dc6091498fc390fdfca6070d4e74990cb 100644 (file)
@@ -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;
 }