internal override UiaCore.IRawElementProviderFragment ElementProviderFromPoint(double x, double y)
            {
                int innerX = (int)x;
                int innerY = (int)y;

                MCHITTESTINFO hitTestInfo = GetHitTestInfo(innerX, innerY);

                switch ((MCHT)hitTestInfo.uHit)
                {
                case MCHT.TITLEBTNPREV:
                    return(GetCalendarChildAccessibleObject(_calendarIndex, CalendarChildType.PreviousButton));

                case MCHT.TITLEBTNNEXT:
                    return(GetCalendarChildAccessibleObject(_calendarIndex, CalendarChildType.NextButton));

                case MCHT.TITLE:
                case MCHT.TITLEMONTH:
                case MCHT.TITLEYEAR:
                    return(GetCalendarChildAccessibleObject(_calendarIndex, CalendarChildType.CalendarHeader));

                case MCHT.CALENDARDAY:
                case MCHT.CALENDARWEEKNUM:
                case MCHT.CALENDARDATE:
                    // Get calendar body's child.
                    CalendarBodyAccessibleObject calendarBodyAccessibleObject = (CalendarBodyAccessibleObject)GetCalendarChildAccessibleObject(_calendarIndex, CalendarChildType.CalendarBody);
                    return(calendarBodyAccessibleObject.GetFromPoint(hitTestInfo));

                case MCHT.TODAYLINK:
                    return(GetCalendarChildAccessibleObject(_calendarIndex, CalendarChildType.TodayLink));
                }

                return(base.ElementProviderFromPoint(x, y));
            }
Esempio n. 2
0
            internal MonthCalendarChildAccessibleObject GetChildFromPoint(MCHITTESTINFO hitTestInfo)
            {
                if (!_monthCalendarAccessibleObject.IsHandleCreated ||
                    CalendarBodyAccessibleObject.RowsAccessibleObjects is null)
                {
                    return(this);
                }

                CalendarRowAccessibleObject?rowAccessibleObject = null;

                foreach (CalendarRowAccessibleObject row in CalendarBodyAccessibleObject.RowsAccessibleObjects)
                {
                    if (row.Row == hitTestInfo.iRow)
                    {
                        rowAccessibleObject = row;
                        break;
                    }
                }

                if (rowAccessibleObject is null)
                {
                    return(this);
                }

                if (hitTestInfo.uHit == MCHT.CALENDARWEEKNUM)
                {
                    return(rowAccessibleObject.WeekNumberCellAccessibleObject ?? (MonthCalendarChildAccessibleObject)this);
                }

                if (rowAccessibleObject.CellsAccessibleObjects is null)
                {
                    return(this);
                }

                CalendarCellAccessibleObject?cellAccessibleObject = null;

                foreach (CalendarCellAccessibleObject cell in rowAccessibleObject.CellsAccessibleObjects)
                {
                    if (cell.Column == hitTestInfo.iCol)
                    {
                        cellAccessibleObject = cell;
                        break;
                    }
                }

                if (cellAccessibleObject is null)
                {
                    return(this);
                }

                return(cellAccessibleObject);
            }
            public unsafe MCHITTESTINFO GetHitTestInfo(int xScreen, int yScreen)
            {
                Point point = new Point(xScreen, yScreen);

                User32.MapWindowPoints(IntPtr.Zero, Handle, ref point, 1);
                var hitTestInfo = new MCHITTESTINFO
                {
                    cbSize = (uint)sizeof(MCHITTESTINFO),
                    pt     = point,
                    st     = new Kernel32.SYSTEMTIME()
                };

                User32.SendMessageW(_owner, (User32.WM)MCM.HITTEST, IntPtr.Zero, ref hitTestInfo);
                return(hitTestInfo);
            }
Esempio n. 4
0
        public ScenarioResult CalendarBodyAccessibleObject_GetFromPoint_ReturnsNull_IfMCHITTESTINFOIsIncorrect(TParams p)
        {
            using var wrapper = new MonthCalendarWrapper(this);
            Application.DoEvents();
            MonthCalendarAccessibleObject accessibleObject     = (MonthCalendarAccessibleObject)wrapper.Calendar.AccessibilityObject;
            CalendarBodyAccessibleObject  bodyAccessibleObject = new CalendarBodyAccessibleObject(accessibleObject, 0);
            MCHITTESTINFO info = new MCHITTESTINFO
            {
                uHit = MCHT.CALENDARDAY,
                iRow = -10
            };

            Application.DoEvents();
            CalendarChildAccessibleObject cell = bodyAccessibleObject.GetFromPoint(info);

            return(new ScenarioResult(cell is null));
        }
Esempio n. 5
0
        public ScenarioResult MonthCalendar_GetFromPoint_ReturnsCorrectValue(TParams p)
        {
            using var wrapper = new MonthCalendarWrapper(this);
            Application.DoEvents();
            MonthCalendarAccessibleObject accessibleObject         = (MonthCalendarAccessibleObject)wrapper.Calendar.AccessibilityObject;
            CalendarAccessibleObject      calendarAccessibleObject = new CalendarAccessibleObject(accessibleObject, 0, "Test name");
            MCHITTESTINFO info = new MCHITTESTINFO
            {
                uHit = MCHT.CALENDARDAY,
                iRow = 0
            };

            Application.DoEvents();
            MonthCalendarChildAccessibleObject cell = calendarAccessibleObject.GetChildFromPoint(info);

            return(new ScenarioResult(cell != null));
        }
            internal override UiaCore.IRawElementProviderFragment?ElementProviderFromPoint(double x, double y)
            {
                int innerX = (int)x;
                int innerY = (int)y;

                if (!_owningMonthCalendar.IsHandleCreated)
                {
                    return(base.ElementProviderFromPoint(x, y));
                }

                MCHITTESTINFO hitTestInfo = GetHitTestInfo(innerX, innerY);

                // See "uHit" kinds in the MS doc:
                // https://docs.microsoft.com/windows/win32/api/commctrl/ns-commctrl-mchittestinfo
                return(hitTestInfo.uHit switch
                {
                    MCHT.CALENDARCONTROL => this,
                    MCHT.TITLEBTNPREV or MCHT.PREV => PreviousButtonAccessibleObject,
                    MCHT.TITLEBTNNEXT or MCHT.NEXT => NextButtonAccessibleObject,
                    MCHT.CALENDARDATEMIN // The given point was over the minimum date in the calendar
                    => CalendarsAccessibleObjects?.First?.Value is CalendarAccessibleObject firstCalendar &&
                    firstCalendar.Bounds.Contains(innerX, innerY)
                            ? firstCalendar
                            : this,
                    MCHT.CALENDARDATEMAX // The given point was over the maximum date in the calendar
                    => CalendarsAccessibleObjects?.Last?.Value is CalendarAccessibleObject lastCalendar &&
                    lastCalendar.Bounds.Contains(innerX, innerY)
                            ? lastCalendar
                            : this,
                    MCHT.CALENDAR
                    // Cast "this" to AccessibleObject because "??" can't cast these operands implicitly
                    => GetCalendarFromPoint(innerX, innerY) ?? (AccessibleObject)this,
                    MCHT.TODAYLINK => TodayLinkAccessibleObject,
                    MCHT.TITLE or MCHT.TITLEMONTH or MCHT.TITLEYEAR
                    // Cast "this" to AccessibleObject because "??" can't cast these operands implicitly
                    => GetCalendarFromPoint(innerX, innerY)?.CalendarHeaderAccessibleObject ?? (AccessibleObject)this,
                    MCHT.CALENDARDAY or MCHT.CALENDARWEEKNUM or MCHT.CALENDARDATE
                    or MCHT.CALENDARDATEPREV or MCHT.CALENDARDATENEXT
                    // Get a calendar body's child.
                    // Cast "this" to AccessibleObject because "??" can't cast these operands implicitly
                    => GetCalendarFromPoint(innerX, innerY)?.GetChildFromPoint(hitTestInfo) ?? (AccessibleObject)this,
                    MCHT.NOWHERE => this,
                    _ => base.ElementProviderFromPoint(x, y)
                });
Esempio n. 7
0
            public CalendarChildAccessibleObject?GetFromPoint(MCHITTESTINFO hitTestInfo)
            {
                switch ((MCHT)hitTestInfo.uHit)
                {
                case MCHT.CALENDARDAY:
                case MCHT.CALENDARWEEKNUM:
                case MCHT.CALENDARDATE:
                    AccessibleObject?rowAccessibleObject = _calendarAccessibleObject.GetCalendarChildAccessibleObject(_calendarIndex, CalendarChildType.CalendarRow, this, hitTestInfo.iRow);

                    if (rowAccessibleObject is null)
                    {
                        return(null);
                    }

                    return(_calendarAccessibleObject.GetCalendarChildAccessibleObject(_calendarIndex, CalendarChildType.CalendarCell, rowAccessibleObject, hitTestInfo.iCol));
                }

                return(this);
            }