From 1b88c4e4a6ee616da3309e28b7500fa80fbd5240 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 3 Aug 2009 20:37:03 +0000 Subject: [PATCH] Correct week day returned from wxCalendarCtrl::HitTest() on header click. 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 | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/msw/calctrl.cpp b/src/msw/calctrl.cpp index 5618ebf933..3fcc49f0c1 100644 --- a/src/msw/calctrl.cpp +++ b/src/msw/calctrl.cpp @@ -220,7 +220,26 @@ wxCalendarCtrl::HitTest(const wxPoint& pos, case MCHT_CALENDARDAY: if ( wd ) { - *wd = static_cast(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(day); } return wxCAL_HITTEST_HEADER; -- 2.45.2