]> git.saurik.com Git - wxWidgets.git/blobdiff - samples/calendar/calendar.cpp
remove wxNewEventFunctor() overload which allowed calls to "Bind(evt, &WrongClass...
[wxWidgets.git] / samples / calendar / calendar.cpp
index 586a9556595d0b2839c61155746a6424e796a343..47d7dbae302346407ddd2333ec8f798e0ab6b71b 100644 (file)
@@ -81,6 +81,7 @@ public:
 
     void OnCalendar(wxCalendarEvent& event);
     void OnCalendarWeekDayClick(wxCalendarEvent& event);
+    void OnCalendarWeekClick(wxCalendarEvent& event);
     void OnCalendarChange(wxCalendarEvent& event);
     void OnCalMonthChange(wxCalendarEvent& event);
 
@@ -149,6 +150,7 @@ public:
 
     void OnCalSeqMonth(wxCommandEvent& event);
     void OnCalShowSurroundingWeeks(wxCommandEvent& event);
+    void OnCalShowWeekNumbers(wxCommandEvent& event);
 
     void OnSetDate(wxCommandEvent& event);
     void OnToday(wxCommandEvent& event);
@@ -212,6 +214,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 +263,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)
@@ -271,8 +275,8 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame)
     EVT_UPDATE_UI(Calendar_Cal_SeqMonth, MyFrame::OnUpdateUIGenericOnly)
 #ifdef __WXGTK20__
     EVT_UPDATE_UI(Calendar_Cal_Monday, MyFrame::OnUpdateUIGenericOnly)
-#endif
     EVT_UPDATE_UI(Calendar_Cal_Holidays, MyFrame::OnUpdateUIGenericOnly)
+#endif
     EVT_UPDATE_UI(Calendar_Cal_Special, MyFrame::OnUpdateUIGenericOnly)
     EVT_UPDATE_UI(Calendar_Cal_SurroundWeeks, MyFrame::OnUpdateUIGenericOnly)
 END_EVENT_TABLE()
@@ -282,6 +286,7 @@ BEGIN_EVENT_TABLE(MyPanel, wxPanel)
     EVT_CALENDAR_PAGE_CHANGED(Calendar_CalCtrl, MyPanel::OnCalMonthChange)
     EVT_CALENDAR_SEL_CHANGED(Calendar_CalCtrl, MyPanel::OnCalendarChange)
     EVT_CALENDAR_WEEKDAY_CLICKED(Calendar_CalCtrl, MyPanel::OnCalendarWeekDayClick)
+    EVT_CALENDAR_WEEK_CLICKED(Calendar_CalCtrl,  MyPanel::OnCalendarWeekClick)
 END_EVENT_TABLE()
 
 #if wxUSE_DATEPICKCTRL
@@ -318,7 +323,7 @@ bool MyApp::OnInit()
 #ifndef __WXWINCE__
                                  ,wxPoint(50, 50), wxSize(450, 340)
 #endif
-                                                                );
+                                 );
 
     frame->Show(true);
 
@@ -367,6 +372,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 +488,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));
@@ -672,6 +686,11 @@ void MyPanel::OnCalendarWeekDayClick(wxCalendarEvent& event)
                  wxDateTime::GetWeekDayName(event.GetWeekDay()).c_str());
 }
 
+void MyPanel::OnCalendarWeekClick(wxCalendarEvent& event)
+{
+    wxLogMessage(wxT("Clicked on week %d"), event.GetDate().GetWeekOfYear());
+}
+
 wxCalendarCtrlBase *MyPanel::DoCreateCalendar(const wxDateTime& dt, long style)
 {
     wxCalendarCtrlBase *calendar;
@@ -693,7 +712,7 @@ wxCalendarCtrlBase *MyPanel::DoCreateCalendar(const wxDateTime& dt, long style)
     calendar->Connect(wxEVT_RIGHT_DOWN,
                       wxMouseEventHandler(MyFrame::OnCalRClick),
                       NULL,
-                      wxGetTopLevelParent(this));
+                      ( MyFrame * )wxGetTopLevelParent(this));
 
     return calendar;
 }
@@ -717,7 +736,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);