+wxCalendarHitTestResult
+wxCalendarCtrl::HitTest(const wxPoint& pos,
+ wxDateTime *date,
+ wxDateTime::WeekDay *wd)
+{
+ WinStruct<MCHITTESTINFO> hti;
+
+ // Vista and later SDKs add a few extra fields to MCHITTESTINFO which are
+ // not supported by the previous versions, as we don't use them anyhow we
+ // should pretend that we always use the old struct format to make the call
+ // below work on pre-Vista systems (see #11057)
+#ifdef MCHITTESTINFO_V1_SIZE
+ hti.cbSize = MCHITTESTINFO_V1_SIZE;
+#endif
+
+ hti.pt.x = pos.x;
+ hti.pt.y = pos.y;
+ switch ( MonthCal_HitTest(GetHwnd(), &hti) )
+ {
+ default:
+ case MCHT_CALENDARWEEKNUM:
+ wxFAIL_MSG( "unexpected" );
+ // fall through
+
+ case MCHT_NOWHERE:
+ case MCHT_CALENDARBK:
+ case MCHT_TITLEBK:
+ case MCHT_TITLEMONTH:
+ case MCHT_TITLEYEAR:
+ return wxCAL_HITTEST_NOWHERE;
+
+ case MCHT_CALENDARDATE:
+ if ( date )
+ date->SetFromMSWSysTime(hti.st);
+ return wxCAL_HITTEST_DAY;
+
+ case MCHT_CALENDARDAY:
+ if ( wd )
+ {
+ 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;
+
+ case MCHT_TITLEBTNNEXT:
+ return wxCAL_HITTEST_INCMONTH;
+
+ case MCHT_TITLEBTNPREV:
+ return wxCAL_HITTEST_DECMONTH;
+
+ case MCHT_CALENDARDATENEXT:
+ case MCHT_CALENDARDATEPREV:
+ return wxCAL_HITTEST_SURROUNDING_WEEK;
+ }
+}
+