]> git.saurik.com Git - wxWidgets.git/commitdiff
No real changes, just cleanup week days handling in wxGenericCalendarCtrl.
authorVadim Zeitlin <vadim@wxwidgets.org>
Sun, 24 Oct 2010 22:40:47 +0000 (22:40 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Sun, 24 Oct 2010 22:40:47 +0000 (22:40 +0000)
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

include/wx/generic/calctrlg.h
src/generic/calctrlg.cpp

index 7e75370ed4687582c81c10a13854c1f7693ded47..02abe012107b098ecbd06b05aa3eb90ee64a95b9 100644 (file)
@@ -199,6 +199,20 @@ private:
     // get the date from which we start drawing days
     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?
     bool IsDateShown(const wxDateTime& date) const;
 
index 25ab8cdad0f41f1b7d2cfa21971b5a98632ef09f..367de68c36fbf6ebdff513a8c9e9471a8b94d8e4 100644 (file)
@@ -648,8 +648,7 @@ wxDateTime wxGenericCalendarCtrl::GetStartDate() const
     wxDateTime date = wxDateTime(1, tm.mon, tm.year);
 
     // rewind back
-    date.SetToPrevWeekDay(GetWindowStyle() & wxCAL_MONDAY_FIRST
-                          ? wxDateTime::Mon : wxDateTime::Sun);
+    date.SetToPrevWeekDay(GetWeekStart());
 
     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 retval = date.GetWeekOfMonth(GetWindowStyle() & wxCAL_MONDAY_FIRST
+    size_t retval = date.GetWeekOfMonth(HasFlag(wxCAL_MONDAY_FIRST)
                                    ? wxDateTime::Monday_First
                                    : wxDateTime::Sunday_First);
 
@@ -713,8 +712,7 @@ size_t wxGenericCalendarCtrl::GetWeek(const wxDateTime& date) const
         wxDateTime datetest = wxDateTime(1, tm.mon, tm.year);
 
         // rewind back
-        datetest.SetToPrevWeekDay(GetWindowStyle() & wxCAL_MONDAY_FIRST
-                              ? wxDateTime::Mon : wxDateTime::Sun);
+        datetest.SetToPrevWeekDay(GetWeekStart());
 
         if ( datetest.GetDay() == 1 )
         {
@@ -972,7 +970,7 @@ void wxGenericCalendarCtrl::OnPaint(wxPaintEvent& WXUNUSED(event))
         dc.SetPen(wxPen(m_colHeaderBg, 1, wxPENSTYLE_SOLID));
         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++ )
         {
             size_t n;
@@ -1319,7 +1317,7 @@ bool wxGenericCalendarCtrl::GetDateCoord(const wxDateTime& date, int *day, int *
 
     if ( IsDateShown(date) )
     {
-        bool startOnMonday = ( GetWindowStyle() & wxCAL_MONDAY_FIRST ) != 0;
+        bool startOnMonday = HasFlag(wxCAL_MONDAY_FIRST);
 
         // Find day
         *day = date.GetWeekDay();
@@ -1530,7 +1528,7 @@ wxCalendarHitTestResult wxGenericCalendarCtrl::HitTest(const wxPoint& pos,
                 *date += wxDateSpan::Week() * (( pos.y - m_rowOffset ) / m_heightRow - 1 );
             }
             if ( wd )
-                *wd = ( GetWindowStyle() & wxCAL_MONDAY_FIRST ) ? wxDateTime::Mon : wxDateTime::Sun;
+                *wd = GetWeekStart();
             return wxCAL_HITTEST_WEEK;
         }
         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 ( GetWindowStyle() & wxCAL_MONDAY_FIRST )
+                if ( HasFlag(wxCAL_MONDAY_FIRST) )
                 {
                     wday = wday == 6 ? 0 : wday + 1;
                 }
@@ -1698,14 +1696,8 @@ void wxGenericCalendarCtrl::OnChar(wxKeyEvent& event)
         case WXK_RIGHT:
             if ( event.ControlDown() )
             {
-                wxDateTime
-                    target = m_date.SetToNextWeekDay(
-                                 GetWindowStyle() & wxCAL_MONDAY_FIRST
-                                 ? wxDateTime::Sun : wxDateTime::Sat);
-                if ( !IsDateInRange(target) )
-                {
-                    target = GetUpperDateLimit();
-                }
+                wxDateTime target = m_date.SetToNextWeekDay(GetWeekEnd());
+                AdjustDateToRange(&target);
                 SetDateAndNotify(target);
             }
             else
@@ -1715,14 +1707,8 @@ void wxGenericCalendarCtrl::OnChar(wxKeyEvent& event)
         case WXK_LEFT:
             if ( event.ControlDown() )
             {
-                wxDateTime
-                    target = m_date.SetToPrevWeekDay(
-                                 GetWindowStyle() & wxCAL_MONDAY_FIRST
-                                 ? wxDateTime::Mon : wxDateTime::Sun);
-                if ( !IsDateInRange(target) )
-                {
-                    target = GetLowerDateLimit();
-                }
+                wxDateTime target = m_date.SetToPrevWeekDay(GetWeekStart());
+                AdjustDateToRange(&target);
                 SetDateAndNotify(target);
             }
             else