]> git.saurik.com Git - wxWidgets.git/commitdiff
Correct week day returned from wxCalendarCtrl::HitTest() on header click.
authorVadim Zeitlin <vadim@wxwidgets.org>
Mon, 3 Aug 2009 20:37:03 +0000 (20:37 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Mon, 3 Aug 2009 20:37:03 +0000 (20:37 +0000)
A combination of a wx bug in conversion from native control week days to
wxDateTime week days and a bug of native control itself when the first week
day is not Monday resulted in the day being off by one it did start with
Monday. The new code works correctly in both Monday and Sunday cases, at least
until the bug in comctl32.dll is corrected.

See comment:5 of #11057.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@61594 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

src/msw/calctrl.cpp

index 5618ebf93334a058212151226357c69ba1ad9b4d..3fcc49f0c1b8f52c4d9f5f55d81fef25dd12fa70 100644 (file)
@@ -220,7 +220,26 @@ wxCalendarCtrl::HitTest(const wxPoint& pos,
         case MCHT_CALENDARDAY:
             if ( wd )
             {
-                *wd = static_cast<wxDateTime::WeekDay>(hti.st.wDayOfWeek);
+                int day = hti.st.wDayOfWeek;
+
+                // the native control returns incorrect day of the week when
+                // the first day isn't Monday, i.e. the first column is always
+                // "Monday" even if its label is "Sunday", compensate for it
+                const int first = LOWORD(MonthCal_GetFirstDayOfWeek(GetHwnd()));
+                if ( first == MonthCal_Monday )
+                {
+                    // as MonthCal_Monday is 0 while wxDateTime::Mon is 1,
+                    // normally we need to do this to transform from MSW
+                    // convention to wx one
+                    day++;
+                    day %= 7;
+                }
+                //else: but when the first day is MonthCal_Sunday, the native
+                //      control still returns 0 (i.e. MonthCal_Monday) for the
+                //      first column which looks like a bug in it but to work
+                //      around it it's enough to not apply the correction above
+
+                *wd = static_cast<wxDateTime::WeekDay>(day);
             }
             return wxCAL_HITTEST_HEADER;