]> git.saurik.com Git - wxWidgets.git/blobdiff - samples/calendar/calendar.cpp
Fixed problems caused by duplicated names across different style types.
[wxWidgets.git] / samples / calendar / calendar.cpp
index 2215b95d6671c6e534b2a7c8f103fd27cb6b2e9e..74963223326f6e3fc7b4b0e08df983f3b2532160 100644 (file)
@@ -98,6 +98,7 @@ public:
     }
 
     void HighlightSpecial(bool on);
     }
 
     void HighlightSpecial(bool on);
+    void LimitDateRange(bool on);
 
     wxDateTime GetDate() const { return m_calendar->GetDate(); }
     void SetDate(const wxDateTime& dt) { m_calendar->SetDate(dt); }
 
     wxDateTime GetDate() const { return m_calendar->GetDate(); }
     void SetDate(const wxDateTime& dt) { m_calendar->SetDate(dt); }
@@ -147,7 +148,7 @@ public:
     void OnCalSpecial(wxCommandEvent& event);
 
     void OnCalAllowMonth(wxCommandEvent& event);
     void OnCalSpecial(wxCommandEvent& event);
 
     void OnCalAllowMonth(wxCommandEvent& event);
-
+    void OnCalLimitDates(wxCommandEvent& event);
     void OnCalSeqMonth(wxCommandEvent& event);
     void OnCalShowSurroundingWeeks(wxCommandEvent& event);
     void OnCalShowWeekNumbers(wxCommandEvent& event);
     void OnCalSeqMonth(wxCommandEvent& event);
     void OnCalShowSurroundingWeeks(wxCommandEvent& event);
     void OnCalShowWeekNumbers(wxCommandEvent& event);
@@ -212,6 +213,7 @@ enum
     Calendar_Cal_Holidays,
     Calendar_Cal_Special,
     Calendar_Cal_Month,
     Calendar_Cal_Holidays,
     Calendar_Cal_Special,
     Calendar_Cal_Month,
+    Calendar_Cal_LimitDates,
     Calendar_Cal_SeqMonth,
     Calendar_Cal_SurroundWeeks,
     Calendar_Cal_WeekNumbers,
     Calendar_Cal_SeqMonth,
     Calendar_Cal_SurroundWeeks,
     Calendar_Cal_WeekNumbers,
@@ -261,6 +263,8 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame)
 
     EVT_MENU(Calendar_Cal_Month, MyFrame::OnCalAllowMonth)
 
 
     EVT_MENU(Calendar_Cal_Month, MyFrame::OnCalAllowMonth)
 
+    EVT_MENU(Calendar_Cal_LimitDates, MyFrame::OnCalLimitDates)
+
     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_SeqMonth, MyFrame::OnCalSeqMonth)
     EVT_MENU(Calendar_Cal_SurroundWeeks, MyFrame::OnCalShowSurroundingWeeks)
     EVT_MENU(Calendar_Cal_WeekNumbers, MyFrame::OnCalShowWeekNumbers)
@@ -276,6 +280,7 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame)
 #ifdef __WXGTK20__
     EVT_UPDATE_UI(Calendar_Cal_Monday, MyFrame::OnUpdateUIGenericOnly)
     EVT_UPDATE_UI(Calendar_Cal_Holidays, MyFrame::OnUpdateUIGenericOnly)
 #ifdef __WXGTK20__
     EVT_UPDATE_UI(Calendar_Cal_Monday, MyFrame::OnUpdateUIGenericOnly)
     EVT_UPDATE_UI(Calendar_Cal_Holidays, MyFrame::OnUpdateUIGenericOnly)
+    EVT_UPDATE_UI(Calendar_Cal_LimitDates, MyFrame::OnUpdateUIGenericOnly)
 #endif
     EVT_UPDATE_UI(Calendar_Cal_Special, MyFrame::OnUpdateUIGenericOnly)
     EVT_UPDATE_UI(Calendar_Cal_SurroundWeeks, MyFrame::OnUpdateUIGenericOnly)
 #endif
     EVT_UPDATE_UI(Calendar_Cal_Special, MyFrame::OnUpdateUIGenericOnly)
     EVT_UPDATE_UI(Calendar_Cal_SurroundWeeks, MyFrame::OnUpdateUIGenericOnly)
@@ -342,7 +347,7 @@ MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
        : wxFrame((wxFrame *)NULL, wxID_ANY, title, pos, size)
 {
     // set the frame icon
        : wxFrame((wxFrame *)NULL, wxID_ANY, title, pos, size)
 {
     // set the frame icon
-    SetIcon(wxIcon(sample_xpm));
+    SetIcon(wxICON(sample));
 
     // create a menu bar
     wxMenu *menuFile = new wxMenu;
 
     // create a menu bar
     wxMenu *menuFile = new wxMenu;
@@ -384,6 +389,8 @@ MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
     menuCal->Append(Calendar_Cal_Month, wxT("&Month can be changed\tCtrl-M"),
                     wxT("Allow changing the month in the calendar"),
                     true);
     menuCal->Append(Calendar_Cal_Month, wxT("&Month can be changed\tCtrl-M"),
                     wxT("Allow changing the month in the calendar"),
                     true);
+    menuCal->AppendCheckItem(Calendar_Cal_LimitDates, wxT("Toggle date ra&nge\tCtrl-N"),
+                    wxT("Limit the valid dates"));
     menuCal->AppendSeparator();
     menuCal->Append(Calendar_Cal_SetDate, wxT("Call &SetDate(2005-12-24)"), wxT("Set date to 2005-12-24."));
     menuCal->Append(Calendar_Cal_Today, wxT("Call &Today()"), wxT("Set to the current date."));
     menuCal->AppendSeparator();
     menuCal->Append(Calendar_Cal_SetDate, wxT("Call &SetDate(2005-12-24)"), wxT("Set date to 2005-12-24."));
     menuCal->Append(Calendar_Cal_Today, wxT("Call &Today()"), wxT("Set to the current date."));
@@ -420,6 +427,7 @@ MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
     menuBar->Check(Calendar_Cal_Monday, true);
     menuBar->Check(Calendar_Cal_Holidays, true);
     menuBar->Check(Calendar_Cal_Month, true);
     menuBar->Check(Calendar_Cal_Monday, true);
     menuBar->Check(Calendar_Cal_Holidays, true);
     menuBar->Check(Calendar_Cal_Month, true);
+    menuBar->Check(Calendar_Cal_LimitDates, false);
 
 #if wxUSE_DATEPICKCTRL
     menuBar->Check(Calendar_DatePicker_ShowCentury, true);
 
 #if wxUSE_DATEPICKCTRL
     menuBar->Check(Calendar_DatePicker_ShowCentury, true);
@@ -472,6 +480,11 @@ void MyFrame::OnCalSpecial(wxCommandEvent& event)
     m_panel->HighlightSpecial(GetMenuBar()->IsChecked(event.GetId()));
 }
 
     m_panel->HighlightSpecial(GetMenuBar()->IsChecked(event.GetId()));
 }
 
+void MyFrame::OnCalLimitDates(wxCommandEvent& event)
+{
+    m_panel->LimitDateRange(GetMenuBar()->IsChecked(event.GetId()));
+}
+
 void MyFrame::OnCalAllowMonth(wxCommandEvent& event)
 {
     m_panel->GetCal()->EnableMonthChange(event.IsChecked());
 void MyFrame::OnCalAllowMonth(wxCommandEvent& event)
 {
     m_panel->GetCal()->EnableMonthChange(event.IsChecked());
@@ -773,6 +786,52 @@ void MyPanel::HighlightSpecial(bool on)
     m_calendar->Refresh();
 }
 
     m_calendar->Refresh();
 }
 
+// Toggle a restricted date range to the six months centered on today's date.
+void MyPanel::LimitDateRange(bool on)
+{
+    if ( on )
+    {
+        // limit the choice of date to 3 months around today
+        const wxDateSpan diff = wxDateSpan::Months(3);
+        const wxDateTime today = wxDateTime::Today();
+
+        // Set the restricted date range.
+        if ( m_calendar->SetDateRange(today - diff, today + diff) )
+        {
+            wxLogStatus("Date range limited to 3 months around today.");
+            wxDateTime firstValidDate;
+            wxDateTime lastValidDate;
+            if ( m_calendar->GetDateRange(&firstValidDate, &lastValidDate) )
+            {
+                wxLogMessage("First valid date: %s, last valid date: %s",
+                             firstValidDate.FormatISODate(),
+                             lastValidDate.FormatISODate());
+            }
+            else
+            {
+                wxLogWarning("Failed to get back the valid dates range.");
+            }
+        }
+        else
+        {
+            wxLogWarning("Date range not supported.");
+        }
+    }
+    else // off
+    {
+        // Remove the date restrictions.
+        if ( m_calendar->SetDateRange() )
+        {
+            wxLogStatus("Date choice is unlimited now.");
+        }
+        else
+        {
+            wxLogWarning("Date range not supported.");
+        }
+    }
+
+    m_calendar->Refresh();
+}
 
 // ----------------------------------------------------------------------------
 // MyDialog
 
 // ----------------------------------------------------------------------------
 // MyDialog