No real changes, just cleanup week days handling in wxGenericCalendarCtrl.

Use helper GetWeek{Start,End}() functions instead of repeating tests for
wxCAL_MONDAY_FIRST over and over again.

Also replace some occurrences of GetWindowStyle() with shorter and more clear
HasFlag().

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@65902 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2010-10-24 22:40:47 +00:00
parent 3c9863aca7
commit 0bb84570ce
2 changed files with 25 additions and 25 deletions

View File

@@ -199,6 +199,20 @@ private:
// get the date from which we start drawing days // get the date from which we start drawing days
wxDateTime GetStartDate() const; wxDateTime GetStartDate() const;
// get the first/last days of the week corresponding to the current style
wxDateTime::WeekDay GetWeekStart() const
{
return HasFlag(wxCAL_MONDAY_FIRST) ? wxDateTime::Mon
: wxDateTime::Sun;
}
wxDateTime::WeekDay GetWeekEnd() const
{
return HasFlag(wxCAL_MONDAY_FIRST) ? wxDateTime::Sun
: wxDateTime::Sat;
}
// is this date shown? // is this date shown?
bool IsDateShown(const wxDateTime& date) const; bool IsDateShown(const wxDateTime& date) const;

View File

@@ -648,8 +648,7 @@ wxDateTime wxGenericCalendarCtrl::GetStartDate() const
wxDateTime date = wxDateTime(1, tm.mon, tm.year); wxDateTime date = wxDateTime(1, tm.mon, tm.year);
// rewind back // rewind back
date.SetToPrevWeekDay(GetWindowStyle() & wxCAL_MONDAY_FIRST date.SetToPrevWeekDay(GetWeekStart());
? wxDateTime::Mon : wxDateTime::Sun);
if ( GetWindowStyle() & wxCAL_SHOW_SURROUNDING_WEEKS ) if ( GetWindowStyle() & wxCAL_SHOW_SURROUNDING_WEEKS )
{ {
@@ -701,7 +700,7 @@ bool wxGenericCalendarCtrl::AdjustDateToRange(wxDateTime *date) const
size_t wxGenericCalendarCtrl::GetWeek(const wxDateTime& date) const size_t wxGenericCalendarCtrl::GetWeek(const wxDateTime& date) const
{ {
size_t retval = date.GetWeekOfMonth(GetWindowStyle() & wxCAL_MONDAY_FIRST size_t retval = date.GetWeekOfMonth(HasFlag(wxCAL_MONDAY_FIRST)
? wxDateTime::Monday_First ? wxDateTime::Monday_First
: wxDateTime::Sunday_First); : wxDateTime::Sunday_First);
@@ -713,8 +712,7 @@ size_t wxGenericCalendarCtrl::GetWeek(const wxDateTime& date) const
wxDateTime datetest = wxDateTime(1, tm.mon, tm.year); wxDateTime datetest = wxDateTime(1, tm.mon, tm.year);
// rewind back // rewind back
datetest.SetToPrevWeekDay(GetWindowStyle() & wxCAL_MONDAY_FIRST datetest.SetToPrevWeekDay(GetWeekStart());
? wxDateTime::Mon : wxDateTime::Sun);
if ( datetest.GetDay() == 1 ) if ( datetest.GetDay() == 1 )
{ {
@@ -972,7 +970,7 @@ void wxGenericCalendarCtrl::OnPaint(wxPaintEvent& WXUNUSED(event))
dc.SetPen(wxPen(m_colHeaderBg, 1, wxPENSTYLE_SOLID)); dc.SetPen(wxPen(m_colHeaderBg, 1, wxPENSTYLE_SOLID));
dc.DrawRectangle(0, y, GetClientSize().x, m_heightRow); dc.DrawRectangle(0, y, GetClientSize().x, m_heightRow);
bool startOnMonday = (GetWindowStyle() & wxCAL_MONDAY_FIRST) != 0; bool startOnMonday = HasFlag(wxCAL_MONDAY_FIRST);
for ( int wd = 0; wd < 7; wd++ ) for ( int wd = 0; wd < 7; wd++ )
{ {
size_t n; size_t n;
@@ -1319,7 +1317,7 @@ bool wxGenericCalendarCtrl::GetDateCoord(const wxDateTime& date, int *day, int *
if ( IsDateShown(date) ) if ( IsDateShown(date) )
{ {
bool startOnMonday = ( GetWindowStyle() & wxCAL_MONDAY_FIRST ) != 0; bool startOnMonday = HasFlag(wxCAL_MONDAY_FIRST);
// Find day // Find day
*day = date.GetWeekDay(); *day = date.GetWeekDay();
@@ -1530,7 +1528,7 @@ wxCalendarHitTestResult wxGenericCalendarCtrl::HitTest(const wxPoint& pos,
*date += wxDateSpan::Week() * (( pos.y - m_rowOffset ) / m_heightRow - 1 ); *date += wxDateSpan::Week() * (( pos.y - m_rowOffset ) / m_heightRow - 1 );
} }
if ( wd ) if ( wd )
*wd = ( GetWindowStyle() & wxCAL_MONDAY_FIRST ) ? wxDateTime::Mon : wxDateTime::Sun; *wd = GetWeekStart();
return wxCAL_HITTEST_WEEK; return wxCAL_HITTEST_WEEK;
} }
else // early exit -> the rest of the function checks for clicks on days else // early exit -> the rest of the function checks for clicks on days
@@ -1547,7 +1545,7 @@ wxCalendarHitTestResult wxGenericCalendarCtrl::HitTest(const wxPoint& pos,
{ {
if ( wd ) if ( wd )
{ {
if ( GetWindowStyle() & wxCAL_MONDAY_FIRST ) if ( HasFlag(wxCAL_MONDAY_FIRST) )
{ {
wday = wday == 6 ? 0 : wday + 1; wday = wday == 6 ? 0 : wday + 1;
} }
@@ -1698,14 +1696,8 @@ void wxGenericCalendarCtrl::OnChar(wxKeyEvent& event)
case WXK_RIGHT: case WXK_RIGHT:
if ( event.ControlDown() ) if ( event.ControlDown() )
{ {
wxDateTime wxDateTime target = m_date.SetToNextWeekDay(GetWeekEnd());
target = m_date.SetToNextWeekDay( AdjustDateToRange(&target);
GetWindowStyle() & wxCAL_MONDAY_FIRST
? wxDateTime::Sun : wxDateTime::Sat);
if ( !IsDateInRange(target) )
{
target = GetUpperDateLimit();
}
SetDateAndNotify(target); SetDateAndNotify(target);
} }
else else
@@ -1715,14 +1707,8 @@ void wxGenericCalendarCtrl::OnChar(wxKeyEvent& event)
case WXK_LEFT: case WXK_LEFT:
if ( event.ControlDown() ) if ( event.ControlDown() )
{ {
wxDateTime wxDateTime target = m_date.SetToPrevWeekDay(GetWeekStart());
target = m_date.SetToPrevWeekDay( AdjustDateToRange(&target);
GetWindowStyle() & wxCAL_MONDAY_FIRST
? wxDateTime::Mon : wxDateTime::Sun);
if ( !IsDateInRange(target) )
{
target = GetLowerDateLimit();
}
SetDateAndNotify(target); SetDateAndNotify(target);
} }
else else