fixed refresh problem with holidays in wxCalendarCtrl

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@5345 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2000-01-11 19:12:47 +00:00
parent c2754d2903
commit 0de868d9dd
5 changed files with 52 additions and 19 deletions

View File

@@ -168,7 +168,6 @@ private:
void OnChar(wxKeyEvent& event); void OnChar(wxKeyEvent& event);
void OnMonthChange(wxCommandEvent& event); void OnMonthChange(wxCommandEvent& event);
void OnYearChange(wxSpinEvent& event); void OnYearChange(wxSpinEvent& event);
void OnCalMonthChange(wxCalendarEvent& event);
// override some base class virtuals // override some base class virtuals
virtual wxSize DoGetBestSize() const; virtual wxSize DoGetBestSize() const;

View File

@@ -67,6 +67,8 @@ public:
void OnCalendar(wxCalendarEvent& event); void OnCalendar(wxCalendarEvent& event);
void OnCalendarWeekDayClick(wxCalendarEvent& event); void OnCalendarWeekDayClick(wxCalendarEvent& event);
void OnCalendarChange(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) BEGIN_EVENT_TABLE(MyPanel, wxPanel)
EVT_CALENDAR (Calendar_CalCtrl, MyPanel::OnCalendar) 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_SEL_CHANGED(Calendar_CalCtrl, MyPanel::OnCalendarChange)
EVT_CALENDAR_WEEKDAY_CLICKED(Calendar_CalCtrl, MyPanel::OnCalendarWeekDayClick) EVT_CALENDAR_WEEKDAY_CLICKED(Calendar_CalCtrl, MyPanel::OnCalendarWeekDayClick)
END_EVENT_TABLE() 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) void MyPanel::OnCalendarWeekDayClick(wxCalendarEvent& event)
{ {
wxLogMessage("Clicked on %s", wxLogMessage("Clicked on %s",

View 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 #if 0
// test compatibility with the old wxDate/wxTime classes // 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 #ifdef TEST_CMDLINE
static const wxCmdLineEntryDesc cmdLineDesc[] = static const wxCmdLineEntryDesc cmdLineDesc[] =
{ {
@@ -1883,7 +1913,7 @@ int main(int argc, char **argv)
#endif // TEST_MIME #endif // TEST_MIME
#ifdef TEST_TIME #ifdef TEST_TIME
if ( 1 ) if ( 0 )
{ {
TestTimeSet(); TestTimeSet();
TestTimeStatic(); TestTimeStatic();
@@ -1898,6 +1928,7 @@ int main(int argc, char **argv)
TestTimeFormat(); TestTimeFormat();
TestTimeArithmetics(); TestTimeArithmetics();
} }
TestTimeHolidays();
if ( 0 ) if ( 0 )
TestInteractive(); TestInteractive();
#endif // TEST_TIME #endif // TEST_TIME

View File

@@ -190,7 +190,7 @@ wxDateTime::Country wxDateTime::ms_country = wxDateTime::Country_Unknown;
#ifdef __WXDEBUG__ #ifdef __WXDEBUG__
extern const wxChar *wxDumpDate(const wxDateTime* dt) 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")));

View File

@@ -81,9 +81,6 @@ BEGIN_EVENT_TABLE(wxCalendarCtrl, wxControl)
EVT_LEFT_DOWN(wxCalendarCtrl::OnClick) EVT_LEFT_DOWN(wxCalendarCtrl::OnClick)
EVT_LEFT_DCLICK(wxCalendarCtrl::OnDClick) EVT_LEFT_DCLICK(wxCalendarCtrl::OnDClick)
EVT_CALENDAR_MONTH(-1, wxCalendarCtrl::OnCalMonthChange)
EVT_CALENDAR_YEAR(-1, wxCalendarCtrl::OnCalMonthChange)
END_EVENT_TABLE() END_EVENT_TABLE()
BEGIN_EVENT_TABLE(wxMonthComboBox, wxComboBox) 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 // update the calendar
Refresh(); 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)); SetDateAndNotify(wxDateTime(tm.mday, mon, tm.year));
GenerateEvents(wxEVT_CALENDAR_MONTH_CHANGED, wxEVT_CALENDAR_SEL_CHANGED);
} }
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)); SetDateAndNotify(wxDateTime(tm.mday, tm.mon, year));
GenerateEvents(wxEVT_CALENDAR_YEAR_CHANGED, wxEVT_CALENDAR_SEL_CHANGED);
} }
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@@ -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) void wxCalendarCtrl::EnableHolidayDisplay(bool display)
{ {
long style = GetWindowStyle(); long style = GetWindowStyle();