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
This commit is contained in:
@@ -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;
|
||||
|
||||
|
Reference in New Issue
Block a user