]> git.saurik.com Git - wxWidgets.git/commitdiff
fixed refresh problem with holidays in wxCalendarCtrl
authorVadim Zeitlin <vadim@wxwidgets.org>
Tue, 11 Jan 2000 19:12:47 +0000 (19:12 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Tue, 11 Jan 2000 19:12:47 +0000 (19:12 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@5345 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/generic/calctrl.h
samples/calendar/calendar.cpp
samples/console/console.cpp
src/common/datetime.cpp
src/generic/calctrl.cpp

index 073767fa58372896a5bcef34d0955bc5646f09b8..feabc86fa4166c5bf4c6373fc3d76193fb0e3b7d 100644 (file)
@@ -168,7 +168,6 @@ private:
     void OnChar(wxKeyEvent& event);
     void OnMonthChange(wxCommandEvent& event);
     void OnYearChange(wxSpinEvent& event);
     void OnChar(wxKeyEvent& event);
     void OnMonthChange(wxCommandEvent& event);
     void OnYearChange(wxSpinEvent& event);
-    void OnCalMonthChange(wxCalendarEvent& event);
 
     // override some base class virtuals
     virtual wxSize DoGetBestSize() const;
 
     // override some base class virtuals
     virtual wxSize DoGetBestSize() const;
index 31c28a57a70bbaa9b1ba7d1332159340c5311551..fd5162b094977c484e87796310c216c4d452b374 100644 (file)
@@ -67,6 +67,8 @@ public:
     void OnCalendar(wxCalendarEvent& event);
     void OnCalendarWeekDayClick(wxCalendarEvent& event);
     void OnCalendarChange(wxCalendarEvent& event);
     void OnCalendar(wxCalendarEvent& event);
     void OnCalendarWeekDayClick(wxCalendarEvent& event);
     void OnCalendarChange(wxCalendarEvent& event);
+    void OnCalMonthChange(wxCalendarEvent& event);
+    void OnCalYearChange(wxCalendarEvent& event);
 
     wxCalendarCtrl *GetCal() const { return m_calendar; }
 
 
     wxCalendarCtrl *GetCal() const { return m_calendar; }
 
@@ -148,6 +150,8 @@ END_EVENT_TABLE()
 
 BEGIN_EVENT_TABLE(MyPanel, wxPanel)
     EVT_CALENDAR            (Calendar_CalCtrl,   MyPanel::OnCalendar)
 
 BEGIN_EVENT_TABLE(MyPanel, wxPanel)
     EVT_CALENDAR            (Calendar_CalCtrl,   MyPanel::OnCalendar)
+    EVT_CALENDAR_MONTH      (Calendar_CalCtrl,   MyPanel::OnCalMonthChange)
+    EVT_CALENDAR_YEAR       (Calendar_CalCtrl,   MyPanel::OnCalYearChange)
     EVT_CALENDAR_SEL_CHANGED(Calendar_CalCtrl,   MyPanel::OnCalendarChange)
     EVT_CALENDAR_WEEKDAY_CLICKED(Calendar_CalCtrl, MyPanel::OnCalendarWeekDayClick)
 END_EVENT_TABLE()
     EVT_CALENDAR_SEL_CHANGED(Calendar_CalCtrl,   MyPanel::OnCalendarChange)
     EVT_CALENDAR_WEEKDAY_CLICKED(Calendar_CalCtrl, MyPanel::OnCalendarWeekDayClick)
 END_EVENT_TABLE()
@@ -340,6 +344,16 @@ void MyPanel::OnCalendarChange(wxCalendarEvent& event)
     m_date->SetLabel(s);
 }
 
     m_date->SetLabel(s);
 }
 
+void MyPanel::OnCalMonthChange(wxCalendarEvent& WXUNUSED(event))
+{
+    wxLogStatus("Calendar month changed");
+}
+
+void MyPanel::OnCalYearChange(wxCalendarEvent& WXUNUSED(event))
+{
+    wxLogStatus("Calendar year changed");
+}
+
 void MyPanel::OnCalendarWeekDayClick(wxCalendarEvent& event)
 {
     wxLogMessage("Clicked on %s",
 void MyPanel::OnCalendarWeekDayClick(wxCalendarEvent& event)
 {
     wxLogMessage("Clicked on %s",
index e3c75ec71d2de895f2eef872ffcd01c6988b943a..e01cf964bf4935a097787f79a15863177b5b2afd 100644 (file)
@@ -1349,6 +1349,31 @@ static void TestTimeArithmetics()
     }
 }
 
     }
 }
 
+static void TestTimeHolidays()
+{
+    puts("\n*** testing wxDateTimeHolidayAuthority ***\n");
+
+    wxDateTime::Tm tm = wxDateTime(29, wxDateTime::May, 2000).GetTm();
+    wxDateTime dtStart(1, tm.mon, tm.year),
+               dtEnd = dtStart.GetLastMonthDay();
+
+    wxDateTimeArray hol;
+    wxDateTimeHolidayAuthority::GetHolidaysInRange(dtStart, dtEnd, hol);
+
+    const wxChar *format = "%d-%b-%Y (%a)";
+
+    printf("All holidays between %s and %s:\n",
+           dtStart.Format(format).c_str(), dtEnd.Format(format).c_str());
+
+    size_t count = hol.GetCount();
+    for ( size_t n = 0; n < count; n++ )
+    {
+        printf("\t%s\n", hol[n].Format(format).c_str());
+    }
+
+    puts("");
+}
+
 #if 0
 
 // test compatibility with the old wxDate/wxTime classes
 #if 0
 
 // test compatibility with the old wxDate/wxTime classes
@@ -1737,6 +1762,11 @@ int main(int argc, char **argv)
         fprintf(stderr, "Failed to initialize the wxWindows library, aborting.");
     }
 
         fprintf(stderr, "Failed to initialize the wxWindows library, aborting.");
     }
 
+#ifdef TEST_USLEEP
+    puts("Sleeping for 3 seconds... z-z-z-z-z...");
+    wxUsleep(3000);
+#endif // TEST_USLEEP
+
 #ifdef TEST_CMDLINE
     static const wxCmdLineEntryDesc cmdLineDesc[] =
     {
 #ifdef TEST_CMDLINE
     static const wxCmdLineEntryDesc cmdLineDesc[] =
     {
@@ -1883,7 +1913,7 @@ int main(int argc, char **argv)
 #endif // TEST_MIME
 
 #ifdef TEST_TIME
 #endif // TEST_MIME
 
 #ifdef TEST_TIME
-    if ( 1 )
+    if ( 0 )
     {
         TestTimeSet();
         TestTimeStatic();
     {
         TestTimeSet();
         TestTimeStatic();
@@ -1898,6 +1928,7 @@ int main(int argc, char **argv)
         TestTimeFormat();
         TestTimeArithmetics();
     }
         TestTimeFormat();
         TestTimeArithmetics();
     }
+    TestTimeHolidays();
     if ( 0 )
         TestInteractive();
 #endif // TEST_TIME
     if ( 0 )
         TestInteractive();
 #endif // TEST_TIME
index e9b1e7c677f93ea9c4b10c00e79f86a49b8b58ee..650f65bf1bbf24f74d69d4ac1e6a83f196fd6593 100644 (file)
@@ -190,7 +190,7 @@ wxDateTime::Country wxDateTime::ms_country = wxDateTime::Country_Unknown;
 #ifdef __WXDEBUG__
 extern const wxChar *wxDumpDate(const wxDateTime* dt)
 {
 #ifdef __WXDEBUG__
 extern const wxChar *wxDumpDate(const wxDateTime* dt)
 {
-    static wxChar buf[20];
+    static wxChar buf[128];
 
     wxStrcpy(buf, dt->Format(_T("%Y-%m-%d (%a) %H:%M:%S")));
 
 
     wxStrcpy(buf, dt->Format(_T("%Y-%m-%d (%a) %H:%M:%S")));
 
index df8e2d745d37951bc5a4d7ec9cade0538adfe6e6..a0aae271449525f6408d1b7d806bbaa230cf5050 100644 (file)
@@ -81,9 +81,6 @@ BEGIN_EVENT_TABLE(wxCalendarCtrl, wxControl)
 
     EVT_LEFT_DOWN(wxCalendarCtrl::OnClick)
     EVT_LEFT_DCLICK(wxCalendarCtrl::OnDClick)
 
     EVT_LEFT_DOWN(wxCalendarCtrl::OnClick)
     EVT_LEFT_DCLICK(wxCalendarCtrl::OnDClick)
-
-    EVT_CALENDAR_MONTH(-1, wxCalendarCtrl::OnCalMonthChange)
-    EVT_CALENDAR_YEAR(-1, wxCalendarCtrl::OnCalMonthChange)
 END_EVENT_TABLE()
 
 BEGIN_EVENT_TABLE(wxMonthComboBox, wxComboBox)
 END_EVENT_TABLE()
 
 BEGIN_EVENT_TABLE(wxMonthComboBox, wxComboBox)
@@ -359,6 +356,9 @@ void wxCalendarCtrl::SetDate(const wxDateTime& date)
             m_spinYear->SetValue(m_date.Format(_T("%Y")));
         }
 
             m_spinYear->SetValue(m_date.Format(_T("%Y")));
         }
 
+        // as the month changed, holidays did too
+        SetHolidayAttrs();
+
         // update the calendar
         Refresh();
     }
         // update the calendar
         Refresh();
     }
@@ -861,9 +861,7 @@ void wxCalendarCtrl::OnMonthChange(wxCommandEvent& event)
         tm.mday = wxDateTime::GetNumberOfDays(mon, tm.year);
     }
 
         tm.mday = wxDateTime::GetNumberOfDays(mon, tm.year);
     }
 
-    SetDate(wxDateTime(tm.mday, mon, tm.year));
-
-    GenerateEvents(wxEVT_CALENDAR_MONTH_CHANGED, wxEVT_CALENDAR_SEL_CHANGED);
+    SetDateAndNotify(wxDateTime(tm.mday, mon, tm.year));
 }
 
 void wxCalendarCtrl::OnYearChange(wxSpinEvent& event)
 }
 
 void wxCalendarCtrl::OnYearChange(wxSpinEvent& event)
@@ -876,9 +874,7 @@ void wxCalendarCtrl::OnYearChange(wxSpinEvent& event)
         tm.mday = wxDateTime::GetNumberOfDays(tm.mon, year);
     }
 
         tm.mday = wxDateTime::GetNumberOfDays(tm.mon, year);
     }
 
-    SetDate(wxDateTime(tm.mday, tm.mon, year));
-
-    GenerateEvents(wxEVT_CALENDAR_YEAR_CHANGED, wxEVT_CALENDAR_SEL_CHANGED);
+    SetDateAndNotify(wxDateTime(tm.mday, tm.mon, year));
 }
 
 // ----------------------------------------------------------------------------
 }
 
 // ----------------------------------------------------------------------------
@@ -957,13 +953,6 @@ void wxCalendarCtrl::OnChar(wxKeyEvent& event)
 // holidays handling
 // ----------------------------------------------------------------------------
 
 // holidays handling
 // ----------------------------------------------------------------------------
 
-void wxCalendarCtrl::OnCalMonthChange(wxCalendarEvent& event)
-{
-    SetHolidayAttrs();
-
-    event.Skip();
-}
-
 void wxCalendarCtrl::EnableHolidayDisplay(bool display)
 {
     long style = GetWindowStyle();
 void wxCalendarCtrl::EnableHolidayDisplay(bool display)
 {
     long style = GetWindowStyle();