Ejemplo n.º 1
0
        static Accessible GetUiElement(Accessible acc, Point pt)
        {
            if (acc == null)
            {
                return(null);
            }

            var type = acc.Type;
            var loc  = acc.Location;

            if (type != UIElementType.None && loc.Contains((int)pt.X, (int)pt.Y))
            {
                return(acc);
            }
            else
            {
                Accessible parent = acc.Parent;

                if (parent != null)
                {
                    return(GetUiElement(parent, pt));
                }
                else
                {
                    return(null);
                }
            }
        }
Ejemplo n.º 2
0
        void GetParentTree(List <Accessible> buf, Accessible acc)
        {
            buf.Add(acc);
            var parent = acc.Parent;

            if (parent != null)
            {
                GetParentTree(buf, parent);
            }
        }
Ejemplo n.º 3
0
        public int Children(out Accessible[] accessible)
        {
            accessible = null;
            if (ChildId != NativeMethods.CHILD_SELF)
            {
                accessible = new Accessible[] { };
                return(NativeMethods.S_OK);
            }

            int childrenCount = IAccessible.accChildCount;

            if (childrenCount < 0)
            {
                throw new ChildCountInvalidException(childrenCount);
            }

            object[] children = new object[childrenCount];

            int hr = NativeMethods.AccessibleChildren(IAccessible, 0, childrenCount, children, out childrenCount);

            if (hr == NativeMethods.S_OK)
            {
                accessible = new Accessible[childrenCount];
                int i = 0;
                foreach (object child in children)
                {
                    if (child != null)
                    {
                        if (child is IAccessible)
                        {
                            accessible[i++] = new Accessible((IAccessible)child, NativeMethods.CHILD_SELF);
                        }
                        else if (child is int)
                        {
                            accessible[i++] = new Accessible(IAccessible, (int)child);
                        }
                    }
                }

                // null children don't occur very often but if they do it stops us from going on
                // So keep track of them so we can reallocate the array if necessary
                if (childrenCount != i)
                {
                    // if we had some null chilren create a smaller array to send the
                    // children back in.
                    Accessible[] accessibleNew = new Accessible[i];
                    Array.Copy(accessible, accessibleNew, i);
                    accessible = accessibleNew;
                }
            }

            return(hr);
        }
Ejemplo n.º 4
0
        public static int FromEvent(IntPtr hwnd, int idObject, int idChild, out Accessible accessible)
        {
            accessible = null;
            object      childId = null;
            IAccessible acc     = null;
            int         hr      = NativeMethods.AccessibleObjectFromEvent(hwnd, idObject, idChild, ref acc, ref childId);

            if (acc != null)
            {
                accessible = new Accessible(acc, (int)childId);
            }

            return(hr);
        }
Ejemplo n.º 5
0
        public static int FromWindow(IntPtr hwnd, out Accessible accessible)
        {
            accessible = null;
            Guid guid = NativeMethods.IID_IAccessible;

            object obj = null;
            int    hr  = NativeMethods.AccessibleObjectFromWindow(hwnd, NativeMethods.ObjIdWindow, ref guid, ref obj);

            if (obj is IAccessible acc)
            {
                accessible = new Accessible(acc, 0);
            }

            return(hr);
        }
Ejemplo n.º 6
0
        public bool Compare(Accessible acc)
        {
            if (acc == null)
            {
                return(false);
            }

            var loc     = acc.Location;
            var thisLoc = Location;

            if (!thisLoc.Equals(loc))
            {
                return(false);
            }

            var name     = acc.Name;
            var thisName = Name;

            if (thisName != name)
            {
                return(false);
            }

            var role     = acc.Role;
            var thisRole = Role;

            if (thisRole != role)
            {
                return(false);
            }

            var value     = acc.Value;
            var thisValue = Value;

            if (thisValue != value)
            {
                return(false);
            }

            return(true);
        }
Ejemplo n.º 7
0
        static bool CheckParentClassIs(Accessible acc, string key)
        {
            var name = acc.ClassName;

            if (name == key)
            {
                return(true);
            }
            else
            {
                var parent = acc.Parent;
                if (parent != null)
                {
                    return(CheckParentClassIs(parent, key));
                }
                else
                {
                    return(false);
                }
            }
        }
Ejemplo n.º 8
0
        public void UpdateParent()
        {
            object parent = null;

            if (ChildId == NativeMethods.CHILD_SELF)
            {
                IAccessible parentIAccessible = IAccessible.accParent as IAccessible;
                if (parentIAccessible == null)
                {
                    parent = null;
                }
                else
                {
                    parent = new Accessible(parentIAccessible, NativeMethods.CHILD_SELF);
                }
            }
            else
            {
                parent = new Accessible(IAccessible, NativeMethods.CHILD_SELF);
            }

            Parent = parent as Accessible;
        }
Ejemplo n.º 9
0
        public static int FromPoint(Point pt, out Accessible accessible)
        {
            accessible = null;
            IAccessible acc     = null;
            object      childId = null;
            int         hr      = NativeMethods.AccessibleObjectFromPoint(new NativeMethods.POINT(pt), ref acc, ref childId);

            if (hr == NativeMethods.S_OK && acc != null)
            {
                if (childId == null)
                {
                    childId = 0;
                }
                if (!(childId is int))
                {
                    throw new VariantNotIntException(childId);
                }

                accessible = new Accessible(acc, (int)childId);
            }

            return(hr);
        }
Ejemplo n.º 10
0
 public static Accessible GetHit(Point pt)
 {
     return(Accessible.FromPoint(pt));
 }
Ejemplo n.º 11
0
        public static UIElementType GetTypeFromRole(Accessible acc)
        {
            var role      = acc.Role;
            var name      = acc.Name;
            var state     = acc.State;
            var className = acc.ClassName;

            switch (acc.Role)
            {
            case 0x01:     //제목 표시줄
                return(UIElementType.TitleBar);

            case 0x3:    // 스크롤 막대
            case 0x33:   //슬라이더
            case 33:     // 목록
                if (className == "SysListView32" && (CheckParentClassIs(acc, "WorkerW") || CheckParentClassIs(acc, "Progman")))
                {
                    return(UIElementType.None);
                }
                return(UIElementType.ScrollViewer);

            case 0x9:     //창
                if (name == "Chrome Legacy Window" || className.StartsWith("Chrome_"))
                {
                    return(UIElementType.Chrome);
                }
                else if (className == "SysTreeView32")
                {
                    return(UIElementType.ScrollViewer);
                }
                return(UIElementType.None);

            case 0x24:     //윤곽항목
                if (className == "SysTreeView32")
                {
                    return(UIElementType.Button);
                }
                return(UIElementType.None);

            case 42:             //편집가능한 텍스트
                if ((state & 0x40) != 0x40 &&  //사용불가
                    state != 0x0 //보통
                    )
                {
                    return(UIElementType.TextBox);
                }
                return(UIElementType.None);

            case 0x2C:   //확인란
            case 0x19:   //열머리글
            case 0x2E:   //콤보박스
            case 0x2D:   //라디오 단추
            case 34:     //목록 항목
            case 58:     //그리드 드랍다운 단추
            case 0x38:   //드랍다운 단추
            case 37:     //페이지탭
            case 0x3E:   //분활단추
            case 0xC:    //메뉴항목
            case 0x39:   //메뉴단추
            case 0x2B:   //누름단추
            case 0x1E:   //링크
                return(UIElementType.Button);

            default:
                return(UIElementType.None);
            }
        }