Applied patch [ 650511 ] wxCalendarCtrl - year does not change
authorJulian Smart <julian@anthemion.co.uk>
Sun, 1 Jun 2003 16:46:49 +0000 (16:46 +0000)
committerJulian Smart <julian@anthemion.co.uk>
Sun, 1 Jun 2003 16:46:49 +0000 (16:46 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@20828 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/generic/calctrl.h
samples/calendar/calendar.cpp
src/generic/calctrl.cpp

index fdd9b4dd076ef85cd9a1f04add1f96e22bd92943..8c7666012563b703932b0476140a02924a24111b 100644 (file)
@@ -256,6 +256,10 @@ private:
     // if the date isn't visible (-1, -1) is put in (day, week) and false is returned
     bool GetDateCoord(const wxDateTime& date, int *day, int *week) const;
 
+    // Set the flag for SetDate(): otherwise it would overwrite the year
+    // typed in by the user
+    void SetUserChangedYear() { m_userChangedYear = TRUE; }
+
     // the subcontrols
     wxStaticText *m_staticMonth;
     wxComboBox *m_comboMonth;
index 0d1e45626505586f1c233fc202fcaf76f77112aa..710a20b00b4d61faf50b7ca17d480a171c2637e1 100644 (file)
@@ -78,6 +78,9 @@ public:
 
     void HighlightSpecial(bool on);
 
+    void SetDate();
+    void Today();
+    
 private:
     wxCalendarCtrl *m_calendar;
     wxStaticText   *m_date;
@@ -106,6 +109,9 @@ public:
     void OnCalSeqMonth(wxCommandEvent& event);
     void OnCalShowSurroundingWeeks(wxCommandEvent& event);
 
+    void OnSetDate(wxCommandEvent& event);
+    void OnToday(wxCommandEvent& event);
+
     void OnAllowYearUpdate(wxUpdateUIEvent& event);
 
 private:
@@ -132,6 +138,8 @@ enum
     Calendar_Cal_Year,
     Calendar_Cal_SeqMonth,
     Calendar_Cal_SurroundWeeks,
+    Calendar_Cal_SetDate,
+    Calendar_Cal_Today,
     Calendar_CalCtrl = 1000
 };
 
@@ -156,6 +164,10 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame)
     EVT_MENU(Calendar_Cal_SeqMonth, MyFrame::OnCalSeqMonth)
     EVT_MENU(Calendar_Cal_SurroundWeeks, MyFrame::OnCalShowSurroundingWeeks)
 
+    EVT_MENU(Calendar_Cal_SetDate, MyFrame::OnSetDate)
+    EVT_MENU(Calendar_Cal_Today, MyFrame::OnToday)
+
+
     EVT_UPDATE_UI(Calendar_Cal_Year, MyFrame::OnAllowYearUpdate)
 END_EVENT_TABLE()
 
@@ -238,6 +250,9 @@ MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
     menuCal->Append(Calendar_Cal_Year, _T("&Year can be changed\tCtrl-Y"),
                     _T("Allow changing the year in the calendar"),
                     TRUE);
+    menuCal->AppendSeparator();
+    menuCal->Append(Calendar_Cal_SetDate, "SetDate()", "Set date to 2005-12-24.");
+    menuCal->Append(Calendar_Cal_Today, "Today()", "Set the current date.");
 
     // now append the freshly created menu to the menu bar...
     wxMenuBar *menuBar = new wxMenuBar;
@@ -325,6 +340,16 @@ void MyFrame::OnAllowYearUpdate(wxUpdateUIEvent& event)
     event.Enable( GetMenuBar()->IsChecked(Calendar_Cal_Month));
 }
 
+void MyFrame::OnSetDate(wxCommandEvent &event)
+{
+    m_panel->SetDate();
+}
+
+void MyFrame::OnToday(wxCommandEvent &event)
+{
+    m_panel->Today();
+}
+
 // ----------------------------------------------------------------------------
 // MyPanel
 // ----------------------------------------------------------------------------
@@ -428,3 +453,14 @@ void MyPanel::HighlightSpecial(bool on)
 
     m_calendar->Refresh();
 }
+
+void MyPanel::SetDate()
+{
+    wxDateTime date(24, wxDateTime::Dec, 2005, 23, 59, 59);
+    m_calendar->SetDate(date);
+}
+
+void MyPanel::Today()
+{
+    m_calendar->SetDate(wxDateTime::Today());
+}
index 084b32340ba32d8f7e8c992aebf45f7f1ea16c7e..bf61e814056db670d06e4c0115ef682995c27006 100644 (file)
@@ -68,7 +68,11 @@ class wxYearSpinCtrl : public wxSpinCtrl
 public:
     wxYearSpinCtrl(wxCalendarCtrl *cal);
 
-    void OnYearTextChange(wxCommandEvent& event) { m_cal->OnYearChange(event); }
+    void OnYearTextChange(wxCommandEvent& event) 
+    {
+        m_cal->SetUserChangedYear();
+        m_cal->OnYearChange(event);
+    }
     void OnYearChange(wxSpinEvent& event) { m_cal->OnYearChange(event); }
 
 private:
@@ -449,8 +453,6 @@ bool wxCalendarCtrl::SetDate(const wxDateTime& date)
                     {
                         if ( !m_userChangedYear )
                             m_spinYear->SetValue(m_date.Format(_T("%Y")));
-                        else // don't overwrite what the user typed in
-                            m_userChangedYear = FALSE;
                     }
                 }
 
@@ -468,6 +470,8 @@ bool wxCalendarCtrl::SetDate(const wxDateTime& date)
         }
     }
 
+    m_userChangedYear = FALSE;
+    
     return retval;
 }
 
@@ -1569,10 +1573,6 @@ void wxCalendarCtrl::OnYearChange(wxCommandEvent& event)
         return;
     }
 
-    // set the flag for SetDate(): otherwise it would overwrite the year
-    // typed in by the user
-    m_userChangedYear = TRUE;
-
     wxDateTime::Tm tm = m_date.GetTm();
 
     if ( tm.mday > wxDateTime::GetNumberOfDays(tm.mon, year) )