/// <summary>
 /// Get automationelement by name, filtered by classname - mouse click if found
 /// </summary>
 /// <param name="parent"></param>
 /// <param name="automationName">case-insensitive automation name</param>
 /// <param name="controlType"></param>
 /// <param name="controlType2"></param>
 /// <exception cref="ApplicationException">if matching element not found</exception>
 /// <exception cref="ApplicationException">if specified element is not enabled</exception>
 public static void FindElementByNameFilteredByControlTypeAndMouseClick(AutomationElement parent, string automationName, ControlType controlType, ControlType controlType2, TimeSpan mouseClickDelay, TreeScope treeScope)
 {
     FindElementByNameFilteredByControlTypeWithTimeoutAndMouseClick(parent, automationName, controlType, controlType2,
             AddinTestUtility.FindRibbonButtonsTimeout, //findDelay
             mouseClickDelay,
             treeScope);
 }
Exemple #2
0
        public static void AddAutomationPropertyChangedEventHandler(AutomationElement element, TreeScope scope, AutomationPropertyChangedEventHandler eventHandler, params AutomationProperty[] properties)
        {
            Utility.ValidateArgumentNonNull(element, "element");
            Utility.ValidateArgumentNonNull(eventHandler, "eventHandler");
            Utility.ValidateArgumentNonNull(properties, "properties");
            if (properties.Length == 0)
            {
                throw new ArgumentException("AtLeastOnePropertyMustBeSpecified");
            }
            int[] propertyIdArray = new int[properties.Length];
            for (int i = 0; i < properties.Length; ++i)
            {
                Utility.ValidateArgumentNonNull(properties[i], "properties");
                propertyIdArray[i] = properties[i].Id;
            }

            try
            {
                PropertyEventListener listener = new PropertyEventListener(AutomationElement.StructureChangedEvent, element, eventHandler);
                Factory.AddPropertyChangedEventHandler(
                    element.NativeElement,
                    (UIAutomationClient.TreeScope)scope,
                    CacheRequest.CurrentNativeCacheRequest,
                    listener,
                    propertyIdArray);
                ClientEventList.Add(listener);
            }
            catch (System.Runtime.InteropServices.COMException e)
            {
                Exception newEx; if (Utility.ConvertException(e, out newEx)) { throw newEx; } else { throw; }
            }
        }
 public AutomationElementCollection GetAllChildNodes(AutomationElement element, AutomationProperty automationProperty, object value, TreeScope treeScope)
 {
     var allChildNodes = element.FindAll(treeScope, GetPropertyCondition(automationProperty, value));
     if (allChildNodes == null)
         throw new ElementNotAvailableException("Not able to find the child nodes of the element");
     return allChildNodes;
 }
 internal static IEnumerable<AutomationElement> FindAll(
     AutomationElement parent, 
     TreeScope scope, 
     Condition condition)
 {
     return FindAll(parent, scope, condition, FindTimeout);
 }
        /// <summary>
        ///     Responds to button click; saves options and starts
        ///     the UI Automation worker thread.
        /// </summary>
        /// <param name="sender">Object that raised the event.</param>
        /// <param name="e">Event arguments.</param>
        private void btnProps_Click(object sender, EventArgs e)
        {
            // Convert Drawing.Point to Windows.Point.
            var drawingPoint = Cursor.Position;
            _targetPoint = new Point(drawingPoint.X, drawingPoint.Y);

            // Save caching settings in member variables so UI isn't accessed 
            // directly by the other thread.

            _elementMode = rbFull.Checked ? AutomationElementMode.Full : AutomationElementMode.None;

            // For simplicity, always include Element in scope.
            _cacheScope = TreeScope.Element;
            if (cbDescendants.Checked)
            {
                _cacheScope |= TreeScope.Descendants;
            }
            // Note: if descendants are specified, children 
            // are automatically included.
            else if (cbChildren.Checked)
            {
                _cacheScope |= TreeScope.Children;
            }

            _fetcher = new UiAutomationFetcher(this, _targetPoint,
                _cacheScope, _elementMode);

            // Start another thread to do the UI Automation work.
            var threadDelegate = new ThreadStart(StartWorkerThread);
            _workerThread = new Thread(threadDelegate) {Priority = ThreadPriority.Highest};
            _workerThread.Start();
            OutputResults("Wait..." + Environment.NewLine);
        }
 public static CacheRequest BuildCacheRequest(TreeScope treeScope, params AutomationProperty[] properties)
 {
     var cr = new CacheRequest { TreeScope = treeScope };
      foreach (var property in properties)
     cr.Add(property);
      return cr;
 }
        public static AutomationElement TryElementByCondition(this AutomationElement element, TreeScope scope, Condition condition)
        {
            var result = scope == TreeScope.Parent || scope == TreeScope.Ancestors ?
                        new TreeWalker(condition).GetParent(element) :
                        element.FindFirst(scope, condition);

            return result;
        } 
Exemple #8
0
		public static void AddAutomationEventHandler (AutomationEvent eventId,
			IRawElementProviderSimple provider, TreeScope scope,
			AutomationEventHandler eventHandler)
		{
			var entry = new AutomationEventEntry (eventId, provider, scope, eventHandler);
			lock (automationEventEntries)
				automationEventEntries.Add (entry);
		}
Exemple #9
0
		public static void AddStructureChangedEventHandler (
			IRawElementProviderSimple provider, TreeScope scope,
			StructureChangedEventHandler eventHandler)
		{
			var entry = new StructureChangedEventEntry (provider, scope, eventHandler);
			lock (structureChangedEventEntries)
				structureChangedEventEntries.Add (entry);
		}
 /// <summary>
 ///     Constructor.
 /// </summary>
 /// <param name="form">The application form.</param>
 /// <param name="targetPoint">The screen coordinates of the cursor.</param>
 /// <param name="scope">The TreeScope for caching.</param>
 /// <param name="mode">The mode for caching.</param>
 public UiAutomationFetcher(FetchTimerForm form,
     Point targetPt,
     TreeScope scope, AutomationElementMode cacheMode)
 {
     _appForm = form;
     _treeScope = scope;
     _targetPoint = targetPt;
     _mode = cacheMode;
 }
Exemple #11
0
		public static void AddAutomationPropertyChangedEventHandler (
			IRawElementProviderSimple provider, TreeScope scope,
			AutomationPropertyChangedEventHandler eventHandler,
			int [] properties)
		{
			var entry = new PropertyChangedEventEntry (provider, scope, properties, eventHandler);
			lock (propertyChangedEventEntries)
				propertyChangedEventEntries.Add (entry);
		}
Exemple #12
0
        public static AutomationElement getAutomationElement(AutomationElement parent, TreeScope scope, ControlType type, string name)
        {
            var element = parent.FindFirst(scope, new AndCondition(
                new PropertyCondition(AutomationElement.ControlTypeProperty, type),
                new PropertyCondition(AutomationElement.NameProperty, name),
                Automation.ControlViewCondition));

            return element;
        }
Exemple #13
0
	internal static async Task<AutomationEventArgs> Event(
		AutomationEvent eventId, 
		AutomationElement element = null, 
		TreeScope scope = TreeScope.Descendants)
	{
		using (var waitr = new Waiter(eventId, element, scope))
		{
			await waitr.Completion.Task;
			return waitr.EvtArgs;
		}
	}
        public AutomationElement GetElement(AutomationElement rootElement, AutomationProperty property, object value, TreeScope searchScope)
        {
            AutomationElement aeMainWindow = null;

            int numWaits = 0;
            do
            {
                aeMainWindow = rootElement.FindFirst(searchScope, new PropertyCondition(property, value));
                ++numWaits;
                Thread.Sleep(200);
            } while (aeMainWindow == null && numWaits < 50);
            return aeMainWindow;
        }
		public void AddAutomationPropertyChangedEventHandler (IElement element, TreeScope scope, AutomationPropertyChangedEventHandler eventHandler, AutomationProperty[] properties)
		{
			if (element == null)
				return;
			ClientElement clientElement = element as ClientElement;
			if (clientElement == null) {
				Log.Error ("[ClientAutomationSource.AddAutomationPropertyChangedEventHandler] Not ClientElement");
				return;
			}
			int [] propertyIds = Array.ConvertAll (properties, p => p.Id);
			ClientEventManager.AddAutomationPropertyChangedEventHandler (
				clientElement.Provider, scope, eventHandler, propertyIds);
		}
Exemple #16
0
        /// <summary>
        /// Extract Window from parent window
        /// </summary>
        /// <param name="parent"></param>
        /// <param name="titleName"></param>
        /// <returns></returns>
        public static AutomationElement ExtractElement(AutomationElement parent, string nameValue, TreeScope treeScope)
        {
            ValidateArgumentNotNull(parent, "Extract Window from parent window");
            Condition condition = new PropertyCondition(AutomationElement.NameProperty, nameValue);
            AutomationElement appElement;
            DateTime timeOut = DateTime.Now.AddMilliseconds(TimeOutMillSec);
            do
            {
                appElement = parent.FindFirst(treeScope, condition);
            } while (appElement == null && DateTime.Now < timeOut);

            return appElement;
        }
		public void AddAutomationEventHandler (AutomationEvent eventId, IElement element, TreeScope scope, AutomationEventHandler eventHandler)
		{
			if (element == null)
				// elements from local providers are not descendants of the RootElement.
				return;
			ClientElement clientElement = element as ClientElement;
			if (clientElement == null) {
				Log.Error ("[ClientAutomationSource.AddAutomationEventHandler] Not ClientElement");
				return;
			}
			ClientEventManager.AddAutomationEventHandler (eventId,
				clientElement.Provider, scope, eventHandler);
		}
Exemple #18
0
        //------------------------------------------------------
        //
        //  Constructors
        //
        //------------------------------------------------------
 
        #region Constructors

        // full ctor
        internal EventListener(
            AutomationEvent eventId, 
            TreeScope scope, 
            AutomationProperty [] properties,
            UiaCoreApi.UiaCacheRequest cacheRequest
            )
        {
            _eventId = eventId;
            _scope = scope;
            if (properties != null)
                _properties = (AutomationProperty[])properties.Clone();
            else
                _properties = null;
            _cacheRequest = cacheRequest;
        }
        public IEnumerable<WiniumElement> Find(TreeScope scope, Predicate<FrameworkElement> predicate)
        {
            if (!Enum.IsDefined(typeof(TreeScope), scope))
            {
                throw new ArgumentException("One of TreeScope.Children or TreeScope.Descendants should be set");
            }

            foreach (var descendant in IterDescendants(this.Element, !scope.HasFlag(TreeScope.Descendants)))
            {
                if (predicate(descendant))
                {
                    yield return new WiniumElement(descendant);
                }
            }
        }
 public AutomationElementCollection ExpandComboBoxViewAndReturnChildren(AutomationElement element, AutomationProperty property, object value, TreeScope searchScope)
 {
     try
     {
         var comboBox = GetFirstChildNode(element, AutomationElement.AutomationIdProperty, value, searchScope);
         var expandPattern = GetExpandCollapsePattern(comboBox, AutomationElement.ControlTypeProperty, ControlType.ComboBox, TreeScope.Element);
         if (expandPattern == null)
             throw new ElementNotAvailableException("Couldnt Find Expand Pattern in combobox");
         expandPattern.Expand();
         return this.GetAllChildNodes(comboBox, AutomationElement.ControlTypeProperty, ControlType.ListItem, TreeScope.Children);
     }
     catch (Exception e1)
     {
         throw e1;
     }
 }
Exemple #21
0
		internal Waiter(AutomationEvent eventId, 
						AutomationElement element = null, 
						TreeScope scope = TreeScope.Descendants)
		{
			this._eventId = eventId;
			this._element = element ?? AutomationElement.RootElement;
			this._scope   = scope;
			this._handler = new AutomationEventHandler((src, e) => 
			{
				this.EvtArgs = e;
				this.Completion.SetResult(true);
			});

			Automation.AddAutomationEventHandler(
				this._eventId, this._element,
				this._scope,   this._handler);
		}
 public ExpandCollapsePattern GetExpandCollapsePattern(AutomationElement element, AutomationProperty property, object value, TreeScope searchScope)
 {
     AutomationElement aeExpanderElement;
     int numWaits = 0;
     do
     {
         aeExpanderElement = GetFirstChildNode(element, property, value, searchScope);
         ++numWaits;
         Thread.Sleep(300);
     } while (aeExpanderElement == null && numWaits < 75);
     object objPattern;
     ExpandCollapsePattern togPattern;
     if (true == aeExpanderElement.TryGetCurrentPattern(ExpandCollapsePattern.Pattern, out objPattern))
     {
         togPattern = objPattern as ExpandCollapsePattern;
         return togPattern;
     }
     else
         return null;
 }
        internal static IEnumerable<AutomationElement> FindAll(
            AutomationElement parent, 
            TreeScope scope, 
            Condition condition, 
            int timeout)
        {
            var dtn = DateTime.Now.AddMilliseconds(timeout);

            // ReSharper disable once LoopVariableIsNeverChangedInsideLoop
            while (DateTime.Now <= dtn)
            {
                var elements = parent.FindAll(scope, condition);
                if (elements.Count > 0)
                {
                    return elements.Cast<AutomationElement>();
                }
            }

            return Enumerable.Empty<AutomationElement>();
        }
        internal static AutomationElement FindFirst(
            AutomationElement parent, 
            TreeScope scope, 
            Condition condition, 
            int timeout)
        {
            var dtn = DateTime.Now.AddMilliseconds(timeout);

            // ReSharper disable once LoopVariableIsNeverChangedInsideLoop
            while (DateTime.Now <= dtn)
            {
                var element = parent.FindFirst(scope, condition);
                if (element != null)
                {
                    return element;
                }
            }

            return null;
        }
Exemple #25
0
		private static void ScopeDecision(TreeScope scope, AutomationElement root, AutomationElement parent, AutomationElement element, out bool considerNode, out bool visitChildren) {
         	switch(scope) {
				case TreeScope.Subtree:
					considerNode = true;
					visitChildren = true;
					break;
         		case TreeScope.Children:
         			considerNode = (parent == root);
         			visitChildren = (parent == null);
         			break;
         		case TreeScope.Descendants:
         			considerNode = (parent != null);
         			visitChildren = true;
         			break;
         		case TreeScope.Element:
         			considerNode = (parent == null);
         			visitChildren = false;
         			break;
         		default:
         			throw new Exception("TreeScope.Ancestors and TreeScope.Parent not supported");
         	}			
		}
        public IEnumerable<WiniumElement> Find(TreeScope scope, Predicate<FrameworkElement> predicate)
        {
            if (!Enum.IsDefined(typeof(TreeScope), scope))
            {
                throw new ArgumentException("One of TreeScope.Children or TreeScope.Descendants should be set");
            }

            // yield main visual tree
            if (predicate(this.VisualRoot.Element))
            {
                yield return this.VisualRoot;
            }

            if (scope.HasFlag(TreeScope.Descendants))
            {
                foreach (var element in this.VisualRoot.Find(scope, predicate))
                {
                    yield return element;
                }
            }

            // yield popups (AppBar, etc.)
            foreach (var popupChild in this.OpenPopups)
            {
                if (predicate(popupChild.Element))
                {
                    yield return popupChild;
                }

                if (scope.HasFlag(TreeScope.Descendants))
                {
                    foreach (var popupElement in popupChild.Find(scope, predicate))
                    {
                        yield return popupElement;
                    }
                }
            }
        }
Exemple #27
0
        public static void AddAutomationEventHandler(AutomationEvent eventId, AutomationElement element, TreeScope scope, AutomationEventHandler eventHandler)
        {
            Utility.ValidateArgumentNonNull(element, "element");
            Utility.ValidateArgumentNonNull(eventHandler, "eventHandler");
            Utility.ValidateArgument(eventId != AutomationElement.AutomationFocusChangedEvent, "Use FocusChange notification instead");
            Utility.ValidateArgument(eventId != AutomationElement.StructureChangedEvent, "Use StructureChange notification instead");
            Utility.ValidateArgument(eventId != AutomationElement.AutomationPropertyChangedEvent, "Use PropertyChange notification instead");

            try
            {
                BasicEventListener listener = new BasicEventListener(eventId, element, eventHandler);
                Factory.AddAutomationEventHandler(
                    eventId.Id,
                    element.NativeElement,
                    (UIAutomationClient.TreeScope)scope,
                    CacheRequest.CurrentNativeCacheRequest,
                    listener);
                ClientEventList.Add(listener);
            }
            catch (System.Runtime.InteropServices.COMException e)
            {
                Exception newEx; if (Utility.ConvertException(e, out newEx)) { throw newEx; } else { throw; }
            }
        }
 /// <summary>
 /// Registers a structure changed event.
 /// </summary>
 public IDisposable SubscribeToStructureChangedEvent(TreeScope treeScope, Action <UiElement, StructureChangedEventArgs> action)
 {
     return(this.AutomationElement.SubscribeToStructureChangedEvent(
                treeScope,
                (sender, args) => action(FromAutomationElement((AutomationElement)sender), args)));
 }
 public override IAutomationStructureChangedEventHandler RegisterStructureChangedEvent(TreeScope treeScope, Action <AutomationElement, StructureChangeType, int[]> action)
 {
     throw new NotImplementedException();
 }
 /// <inheritdoc />
 public NotificationEventHandlerBase RegisterNotificationEvent(TreeScope treeScope, Action <AutomationElement, NotificationKind, NotificationProcessing, string, string> action)
 {
     return(FrameworkAutomationElement.RegisterNotificationEvent(treeScope, action));
 }
 /// <inheritdoc />
 public ActiveTextPositionChangedEventHandlerBase RegisterActiveTextPositionChangedEvent(TreeScope treeScope, Action <AutomationElement, ITextRange> action)
 {
     return(FrameworkAutomationElement.RegisterActiveTextPositionChangedEvent(treeScope, action));
 }
 /// <inheritdoc />
 public override NotificationEventHandlerBase RegisterNotificationEvent(TreeScope treeScope, Action <AutomationElement, NotificationKind, NotificationProcessing, string, string> action)
 {
     throw new NotSupportedByFrameworkException();
 }
 /// <inheritdoc />
 public override ActiveTextPositionChangedEventHandlerBase RegisterActiveTextPositionChangedEvent(TreeScope treeScope, Action <AutomationElement, ITextRange> action)
 {
     throw new NotImplementedException();
 }
 public IAutomationStructureChangedEventHandler RegisterStructureChangedEvent(TreeScope treeScope, Action <AutomationElement, StructureChangeType, int[]> action)
 {
     return(BasicAutomationElement.RegisterStructureChangedEvent(treeScope, action));
 }
 /// <inheritdoc />
 public override AutomationElement[] FindAllWithOptions(TreeScope treeScope, ConditionBase condition,
                                                        TreeTraversalOptions traversalOptions, AutomationElement root)
 {
     throw new NotSupportedByFrameworkException();
 }
 public IAutomationEventHandler RegisterEvent(EventId @event, TreeScope treeScope, Action <AutomationElement, EventId> action)
 {
     return(BasicAutomationElement.RegisterEvent(@event, treeScope, action));
 }
 public IAutomationPropertyChangedEventHandler RegisterPropertyChangedEvent(TreeScope treeScope, Action <AutomationElement, PropertyId, object> action, params PropertyId[] properties)
 {
     return(BasicAutomationElement.RegisterPropertyChangedEvent(treeScope, action, properties));
 }
 /// <summary>
 /// Finds the first element which is in the given treescope and matches the condition
 /// </summary>
 public AutomationElement FindFirst(TreeScope treeScope, ConditionBase condition)
 {
     return(FindFirst(treeScope, condition, Retry.DefaultRetryFor));
 }
 public override IAutomationPropertyChangedEventHandler RegisterPropertyChangedEvent(TreeScope treeScope, Action <AutomationElement, PropertyId, object> action, PropertyId[] properties)
 {
     throw new NotImplementedException();
 }
Exemple #40
0
        /// <summary>
        /// Called by a client to add a listener for property changed events.
        /// </summary>
        /// <param name="element">Element on which to listen for property changed events.</param>
        /// <param name="scope">Specifies whether to listen to property changes events on the specified element, and/or its ancestors and children.</param>
        /// <param name="eventHandler">Callback object to call when a specified property change occurs.</param>
        /// <param name="properties">Params array of properties to listen for changes in.</param>
        /// 
        /// <outside_see conditional="false">
        /// This API does not work inside the secure execution environment.
        /// <exception cref="System.Security.Permissions.SecurityPermission"/>
        /// </outside_see>
        public static void AddAutomationPropertyChangedEventHandler(
            AutomationElement element,            // reference element for listening to the event
            TreeScope scope,                   // scope to listen to
            AutomationPropertyChangedEventHandler eventHandler,    // callback object
            params AutomationProperty [] properties           // listen for changes to these properties
            )
        {
            Misc.ValidateArgumentNonNull(element, "element" );
            Misc.ValidateArgumentNonNull(eventHandler, "eventHandler" );
            Misc.ValidateArgumentNonNull(properties, "properties" );
            if (properties.Length == 0)
            {
                throw new ArgumentException( SR.Get(SRID.AtLeastOnePropertyMustBeSpecified) );
            }

            // Check that no properties are interpreted properties
            // 

            foreach (AutomationProperty property in properties)
            {
                Misc.ValidateArgumentNonNull(property, "properties" );
            }

            // Add a client-side listener for for this event request
            EventListener l = new EventListener(AutomationElement.AutomationPropertyChangedEvent, scope, properties, CacheRequest.CurrentUiaCacheRequest);
            ClientEventManager.AddListener(element, eventHandler, l);
        }
Exemple #41
0
 public abstract AutomationElement[] FindAll(TreeScope treeScope, ConditionBase condition);
Exemple #42
0
 /// <summary>
 /// Find all matching elements in the specified order.
 /// </summary>
 public AutomationElement[] FindAllWithOptions(TreeScope treeScope, ConditionBase condition,
                                               TreeTraversalOptions traversalOptions, AutomationElement root)
 {
     return(FrameworkAutomationElement.FindAllWithOptions(treeScope, condition, traversalOptions, root));
 }
        /// <summary>
        /// Return the parent automation element
        /// </summary>
        private AutomationElement getAutomationElement(AutomationElement parent, Condition condition, TreeScope scope)
        {
            AutomationElement element;
            DateTime          timeBound = DateTime.Now + TimeSpan.FromSeconds(20);

            do
            {
                element = parent.FindFirst(scope, condition);
                Thread.Sleep(TimeSpan.FromSeconds(1));
            } while (element == null && timeBound > DateTime.Now);

            return(element);
        }
 public override IAutomationEventHandler RegisterEvent(EventId @event, TreeScope treeScope, Action <AutomationElement, EventId> action)
 {
     throw new NotImplementedException();
 }
 /// <inheritdoc />
 public override TextEditTextChangedEventHandlerBase RegisterTextEditTextChangedEventHandler(TreeScope treeScope, TextEditChangeType textEditChangeType, Action <AutomationElement, TextEditChangeType, string[]> action)
 {
     throw new NotSupportedByFrameworkException();
 }
 public override AutomationElement FindFirst(TreeScope treeScope, ConditionBase condition)
 {
     throw new NotImplementedException();
 }
        /// <inheritdoc />
        public override AutomationEventHandlerBase RegisterAutomationEvent(EventId @event, TreeScope treeScope, Action <AutomationElement, EventId> action)
        {
            var eventHandler = new UIA2AutomationEventHandler(this, @event, action);

            UIA.Automation.AddAutomationEventHandler(UIA.AutomationEvent.LookupById(@event.Id), NativeElement, (UIA.TreeScope)treeScope, eventHandler.EventHandler);
            return(eventHandler);
        }
Exemple #48
0
 public abstract IAutomationStructureChangedEventHandler RegisterStructureChangedEvent(TreeScope treeScope, Action <AutomationElement, StructureChangeType, int[]> action);
 /// <inheritdoc />
 public TextEditTextChangedEventHandlerBase RegisterTextEditTextChangedEventHandler(TreeScope treeScope, TextEditChangeType textEditChangeType, Action <AutomationElement, TextEditChangeType, string[]> action)
 {
     return(FrameworkAutomationElement.RegisterTextEditTextChangedEventHandler(treeScope, textEditChangeType, action));
 }
Exemple #50
0
 public abstract IAutomationPropertyChangedEventHandler RegisterPropertyChangedEvent(TreeScope treeScope, Action <AutomationElement, PropertyId, object> action, PropertyId[] properties);
 /// <inheritdoc />
 public StructureChangedEventHandlerBase RegisterStructureChangedEvent(TreeScope treeScope, Action <AutomationElement, StructureChangeType, int[]> action)
 {
     return(FrameworkAutomationElement.RegisterStructureChangedEvent(treeScope, action));
 }
Exemple #52
0
 public abstract IAutomationEventHandler RegisterEvent(EventId @event, TreeScope treeScope, Action <AutomationElement, EventId> action);
 /// <summary>
 /// Ctor to create an event handler (with CUIAutomation) and register it.
 /// </summary>
 protected EventListenerBase(CUIAutomation uia, IUIAutomationElement element, TreeScope scope, int eventId, HandleUIAutomationEventMessage peDelegate)
     : this(element, scope, eventId, peDelegate)
 {
     this.UIAutomation = uia;
 }
Exemple #54
0
 public abstract AutomationElement FindFirst(TreeScope treeScope, ConditionBase condition);
Exemple #55
0
        public override AutomationElement[] FindAll(TreeScope treeScope, ConditionBase condition)
        {
            var nativeFoundElements = NativeElement.FindAll((UIA.TreeScope)treeScope, ConditionConverter.ToNative(condition));

            return(AutomationElementConverter.NativeArrayToManaged(Automation, nativeFoundElements));
        }
Exemple #56
0
        public override IAutomationStructureChangedEventHandler RegisterStructureChangedEvent(TreeScope treeScope, Action <AutomationElement, StructureChangeType, int[]> action)
        {
            var eventHandler = new UIA2StructureChangedEventHandler(Automation, action);

            UIA.Automation.AddStructureChangedEventHandler(NativeElement, (UIA.TreeScope)treeScope, eventHandler.EventHandler);
            return(eventHandler);
        }
Exemple #57
0
        /// <summary>
        /// Called by a client to add a listener for pattern or custom events.
        /// </summary>
        /// <param name="eventId">A control pattern or custom event identifier.</param>
        /// <param name="element">Element on which to listen for control pattern or custom events.</param>
        /// <param name="scope">Specifies whether to listen to property changes events on the specified element, and/or its ancestors and children.</param>
        /// <param name="eventHandler">Delegate to call when the specified event occurs.</param>
        /// 
        /// <outside_see conditional="false">
        /// This API does not work inside the secure execution environment.
        /// <exception cref="System.Security.Permissions.SecurityPermission"/>
        /// </outside_see>
        public static void AddAutomationEventHandler(
            AutomationEvent eventId,
            AutomationElement element,
            TreeScope scope,
            AutomationEventHandler eventHandler
            )
        {
            Misc.ValidateArgumentNonNull(element, "element" );
            Misc.ValidateArgumentNonNull(eventHandler, "eventHandler" );
            Misc.ValidateArgument( eventId != AutomationElement.AutomationFocusChangedEvent, SRID.EventIdMustNotBeAutomationFocusChanged );
            Misc.ValidateArgument( eventId != AutomationElement.StructureChangedEvent,SRID.EventIdMustNotBeStructureChanged );
            Misc.ValidateArgument( eventId != AutomationElement.AutomationPropertyChangedEvent, SRID.EventIdMustNotBeAutomationPropertyChanged );

            if (eventId == WindowPattern.WindowClosedEvent)
            {
                // Once a window closes and the hwnd is destroyed we won't be able to determine where it was in the 
                // Automation tree; therefore only support WindowClosed events for all windows (eg. src==root and scope 
                // is descendants) or a specific WindowPattern element (src==root of a Window and scope is the element).
                // Also handle odd combinations (eg. src==specific element and scope is subtree|ancestors).

                bool paramsValidated = false;

                if ( Misc.Compare( element, AutomationElement.RootElement ) )
                {
                    // For root element need to have Descendants scope set (Note: Subtree includes Descendants)
                    if ( ( scope & TreeScope.Descendants ) == TreeScope.Descendants )
                    {
                        paramsValidated = true;
                    }
                }
                else
                {
                    // otherwise non-root elements must have the entire tree (Anscestors, Element and Descendants)...
                    if ( ( scope & ( TreeScope.Ancestors | TreeScope.Element | TreeScope.Descendants ) ) == ( TreeScope.Ancestors | TreeScope.Element | TreeScope.Descendants ) )
                    {
                        paramsValidated = true;
                    }
                    else if ( ( scope & TreeScope.Element ) == TreeScope.Element )
                    {
                        // ...OR Element where the element implements WindowPattern
                        // PRESHARP will flag this as warning 56506/6506:Parameter 'element' to this public method must be validated: A null-dereference can occur here.
                        // False positive, element is checked, see above
#pragma warning suppress 6506
                        object val = element.GetCurrentPropertyValue(AutomationElement.NativeWindowHandleProperty);
                        if ( val != null && val is int && (int)val != 0 )
                        {
                            if ( HwndProxyElementProvider.IsWindowPatternWindow( NativeMethods.HWND.Cast( new IntPtr( (int)val ) ) ) )
                            {
                                paramsValidated = true;
                            }
                        }
                    }
                }

                if ( !paramsValidated )
                {
                    throw new ArgumentException( SR.Get( SRID.ParamsNotApplicableToWindowClosedEvent ) );
                }
            }

            // Add a client-side Handler for for this event request
            EventListener l = new EventListener(eventId, scope, null, CacheRequest.CurrentUiaCacheRequest);
            ClientEventManager.AddListener(element, eventHandler, l);
        }
Exemple #58
0
        public override AutomationElement FindFirst(TreeScope treeScope, ConditionBase condition)
        {
            var nativeFoundElement = NativeElement.FindFirst((UIA.TreeScope)treeScope, ConditionConverter.ToNative(condition));

            return(AutomationElementConverter.NativeToManaged(Automation, nativeFoundElement));
        }
Exemple #59
0
        /// <summary>
        /// Called by a client to add a listener for structure change events.
        /// </summary>
        /// <param name="element">Element on which to listen for structure change events.</param>
        /// <param name="scope">Specifies whether to listen to property changes events on the specified element, and/or its ancestors and children.</param>
        /// <param name="eventHandler">Delegate to call when a structure change event occurs.</param>
        /// 
        /// <outside_see conditional="false">
        /// This API does not work inside the secure execution environment.
        /// <exception cref="System.Security.Permissions.SecurityPermission"/>
        /// </outside_see>
        public static void AddStructureChangedEventHandler(AutomationElement element, TreeScope scope, StructureChangedEventHandler eventHandler)
        {
            Misc.ValidateArgumentNonNull(element, "element");
            Misc.ValidateArgumentNonNull(eventHandler, "eventHandler");

            // Add a client-side listener for for this event request
            EventListener l = new EventListener(AutomationElement.StructureChangedEvent, scope, null, CacheRequest.CurrentUiaCacheRequest);

            ClientEventManager.AddListener(element, eventHandler, l);
        }
Exemple #60
0
        public override IAutomationPropertyChangedEventHandler RegisterPropertyChangedEvent(TreeScope treeScope, Action <AutomationElement, PropertyId, object> action, PropertyId[] properties)
        {
            var eventHandler = new UIA2PropertyChangedEventHandler(Automation, action);

            UIA.Automation.AddAutomationPropertyChangedEventHandler(NativeElement, (UIA.TreeScope)treeScope, eventHandler.EventHandler);
            return(eventHandler);
        }