public override IDisposable SubscribeToStructureChangedEvent(TreeScope treeScope, Action <AutomationElement, StructureChangeType, int[]> action)
        {
            var eventHandler = new UIA3StructureChangedEventHandler(this.Automation, action);

            this.Automation.NativeAutomation.AddStructureChangedEventHandler(this.NativeElement, (Interop.UIAutomationClient.TreeScope)treeScope, null, eventHandler);
            return(Disposable.Create(() => this.Automation.NativeAutomation.RemoveStructureChangedEventHandler(this.NativeElement, (UIA3StructureChangedEventHandler)eventHandler)));
        }
        public override IDisposable SubscribeToEvent(EventId @event, TreeScope treeScope, Action <AutomationElement, EventId> action)
        {
            var eventHandler = new UIA3BasicEventHandler(this.Automation, action);

            this.Automation.NativeAutomation.AddAutomationEventHandler(@event.Id, this.NativeElement, (Interop.UIAutomationClient.TreeScope)treeScope, null, eventHandler);
            return(Disposable.Create(() => this.Automation.NativeAutomation.RemoveAutomationEventHandler(@event.Id, this.NativeElement, eventHandler)));
        }
        public override AutomationElement FindFirst(TreeScope treeScope, ConditionBase condition)
        {
            var nativeElement = this.FindFirstNative(
                treeScope,
                condition.ToNative(this.Automation.NativeAutomation));

            return(AutomationElementConverter.NativeToManaged(this.Automation, nativeElement));
        }
        public override IReadOnlyList <AutomationElement> FindAll(TreeScope treeScope, ConditionBase condition)
        {
            var nativeFoundElements = CacheRequest.IsCachingActive
                ? this.NativeElement.FindAllBuildCache((Interop.UIAutomationClient.TreeScope)treeScope, condition.ToNative(this.Automation.NativeAutomation), CacheRequest.Current.ToNative(this.Automation))
                : this.NativeElement.FindAll((Interop.UIAutomationClient.TreeScope)treeScope, condition.ToNative(this.Automation.NativeAutomation));

            return(AutomationElementConverter.NativeArrayToManaged(this.Automation, nativeFoundElements));
        }
        public override IDisposable SubscribeToPropertyChangedEvent(TreeScope treeScope, Action <AutomationElement, PropertyId, object> action, PropertyId[] properties)
        {
            var eventHandler = new UIA3PropertyChangedEventHandler(this.Automation, action);
            var propertyIds  = properties.Select(p => p.Id).ToArray();

            this.Automation.NativeAutomation.AddPropertyChangedEventHandler(
                this.NativeElement,
                (Interop.UIAutomationClient.TreeScope)treeScope,
                null,
                eventHandler,
                propertyIds);
            return(Disposable.Create(() => this.Automation.NativeAutomation.RemovePropertyChangedEventHandler(this.NativeElement, (UIA3PropertyChangedEventHandler)eventHandler)));
        }
        public override AutomationElement FindIndexed(TreeScope treeScope, ConditionBase condition, int index)
        {
            var nativeFoundElements = CacheRequest.IsCachingActive
                ? this.NativeElement.FindAllBuildCache((Interop.UIAutomationClient.TreeScope)treeScope, condition.ToNative(this.Automation.NativeAutomation), CacheRequest.Current.ToNative(this.Automation))
                : this.NativeElement.FindAll((Interop.UIAutomationClient.TreeScope)treeScope, condition.ToNative(this.Automation.NativeAutomation));
            var nativeElement = nativeFoundElements.GetElement(index);

            if (nativeElement == null)
            {
                return(null);
            }

            return(AutomationElementConverter.NativeToManaged(this.Automation, nativeElement));
        }
        public override T FindFirst <T>(TreeScope treeScope, ConditionBase condition, Func <BasicAutomationElementBase, T> wrap)
        {
            var nativeElement = this.FindFirstNative(
                treeScope,
                condition.ToNative(this.Automation.NativeAutomation));

            if (nativeElement == null)
            {
                return(null);
            }

            var basicElement = new UIA3BasicAutomationElement(this.Automation, nativeElement);

            return(wrap(basicElement));
        }
        public override IReadOnlyList <T> FindAll <T>(TreeScope treeScope, ConditionBase condition, Func <BasicAutomationElementBase, T> wrap)
        {
            var nativeFoundElements = CacheRequest.IsCachingActive
                ? this.NativeElement.FindAllBuildCache((Interop.UIAutomationClient.TreeScope)treeScope, condition.ToNative(this.Automation.NativeAutomation), CacheRequest.Current.ToNative(this.Automation))
                : this.NativeElement.FindAll((Interop.UIAutomationClient.TreeScope)treeScope, condition.ToNative(this.Automation.NativeAutomation));
            var result = new T[nativeFoundElements.Length];

            for (var i = 0; i < nativeFoundElements.Length; i++)
            {
                var nativeElement = nativeFoundElements.GetElement(i);
                var basicElement  = new UIA3BasicAutomationElement(this.Automation, nativeElement);
                result[i] = wrap(basicElement);
            }

            return(result);
        }
        public override T FindIndexed <T>(TreeScope treeScope, ConditionBase condition, int index, Func <BasicAutomationElementBase, T> wrap)
        {
            var nativeFoundElements = CacheRequest.IsCachingActive
                ? this.NativeElement.FindAllBuildCache((Interop.UIAutomationClient.TreeScope)treeScope, condition.ToNative(this.Automation.NativeAutomation), CacheRequest.Current.ToNative(this.Automation))
                : this.NativeElement.FindAll((Interop.UIAutomationClient.TreeScope)treeScope, condition.ToNative(this.Automation.NativeAutomation));

            if (nativeFoundElements == null ||
                index >= nativeFoundElements.Length)
            {
                return(null);
            }

            var nativeElement = nativeFoundElements.GetElement(index);

            if (nativeElement == null)
            {
                return(null);
            }

            var basicElement = new UIA3BasicAutomationElement(this.Automation, nativeElement);

            return(wrap(basicElement));
        }
 public IUIAutomationElement FindFirstNative(TreeScope treeScope, IUIAutomationCondition condition)
 {
     return(CacheRequest.IsCachingActive
         ? this.NativeElement.FindFirstBuildCache((Interop.UIAutomationClient.TreeScope)treeScope, condition, CacheRequest.Current.ToNative(this.Automation))
         : this.NativeElement.FindFirst((Interop.UIAutomationClient.TreeScope)treeScope, condition));
 }