public static void RaiseAutomationEvent(AutomationEvent eventId, IRawElementProviderSimple provider, AutomationEventArgs e)
 {
     Utility.ValidateArgumentNonNull(eventId, "eventId");
     Utility.ValidateArgumentNonNull(provider, "provider");
     Utility.ValidateArgumentNonNull(e, "e");
     if (e.EventId == AutomationElementIdentifiers.AsyncContentLoadedEvent)
     {
         AsyncContentLoadedEventArgs args = e as AsyncContentLoadedEventArgs;
         if (args == null)
         {
             throw new ArgumentException("e");
         }
         UiaCoreProviderApi.UiaRaiseAsyncContentLoadedEvent(provider, args.AsyncContentLoadedState, args.PercentComplete);
     }
     else
     {
         if ((e.EventId == WindowPatternIdentifiers.WindowClosedEvent) && !(e is WindowClosedEventArgs))
         {
             throw new ArgumentException("e");
         }
         UiaCoreProviderApi.UiaRaiseAutomationEvent(provider, eventId.Id);
     }
 }
Esempio n. 2
0
 public BasicEventListener(AutomationEvent eventKind, AutomationElement element, AutomationEventHandler handler) :
     base(eventKind.Id, element.GetRuntimeId(), handler)
 {
     Debug.Assert(handler != null);
     this._basicHandler = handler;
 }
Esempio n. 3
0
        // RemoveListener - Removes a listener from this client and notifies the UIAutomation server-side
        internal static void RemoveListener(AutomationEvent eventId, AutomationElement el, Delegate eventCallback)
        {
            lock ( _classLock )
            {
                if (_listeners != null)
                {
                    bool boundingRectListeners       = false; // if not removing BoundingRect listeners no need to do check below
                    bool menuListeners               = false; // if not removing MenuOpenedOrClosed listeners no need to do check below
                    bool windowInteracationListeners = false; // if not removing WindowsIntercation listeners no need to do check below
                    bool windowVisualListeners       = false; // if not removing WindowsVisual listeners no need to do check below

                    for (int i = _listeners.Count - 1; i >= 0; i--)
                    {
                        EventListenerClientSide ec = (EventListenerClientSide)_listeners[i];
                        if (ec.IsListeningFor(eventId, el, eventCallback))
                        {
                            EventListener l = ec.EventListener;

                            // Only advise UI contexts of events being removed if the event might be raised by
                            // a provider.  TopLevelWindow event is raised by UI Automation framework.
                            if (ShouldAdviseProviders(eventId))
                            {
                                // Notify the server-side that this event is no longer interesting
                                try
                                {
                                    ec.EventHandle.Dispose(); // Calls UiaCoreApi.UiaRemoveEvent
                                }
// PRESHARP: Warning - Catch statements should not have empty bodies
#pragma warning disable 6502
                                catch (ElementNotAvailableException)
                                {
                                    // the element is gone already; continue on and remove the listener
                                }
#pragma warning restore 6502
                                finally
                                {
                                    ec.Dispose();
                                }
                            }

                            // before removing, check if this delegate was listening for the below events
                            // and see if we can stop clientside WinEvent trackers.
                            if (HasProperty(AutomationElement.BoundingRectangleProperty, l.Properties))
                            {
                                boundingRectListeners = true;
                            }

                            if (eventId == AutomationElement.MenuOpenedEvent || eventId == AutomationElement.MenuClosedEvent)
                            {
                                menuListeners = true;
                            }

                            if (HasProperty(WindowPattern.WindowInteractionStateProperty, l.Properties))
                            {
                                windowInteracationListeners = true;
                            }

                            if (HasProperty(WindowPattern.WindowVisualStateProperty, l.Properties))
                            {
                                windowVisualListeners = true;
                            }

                            // delete this one
                            _listeners.RemoveAt(i);
                        }
                    }

                    // Check listeners bools to see if clientside listeners can be removed
                    if (boundingRectListeners)
                    {
                        RemovePropertyTracker(AutomationElement.BoundingRectangleProperty, Tracker.BoundingRect);
                    }

                    if (menuListeners)
                    {
                        RemoveMenuListeners();
                    }

                    if (windowInteracationListeners)
                    {
                        RemovePropertyTracker(WindowPattern.WindowInteractionStateProperty, Tracker.WindowInteractionState);
                    }

                    if (windowVisualListeners)
                    {
                        RemovePropertyTracker(WindowPattern.WindowVisualStateProperty, Tracker.WindowVisualState);
                    }

                    // See if we can cleanup completely
                    if (_listeners.Count == 0)
                    {
                        // as long as OnWindowShowOrOpen is static can just use new here and get same object instance
                        // (if there's no WindowShowOrOpen listener, this method just returns)
                        RemoveWinEventListener(Tracker.WindowShowOrOpen, new WindowShowOrOpenHandler(OnWindowShowOrOpen));
                        RemoveWinEventListener(Tracker.WindowHideOrClose, new WindowHideOrCloseHandler(OnWindowHideOrClose));

                        _listeners = null;
                    }
                }
            }
        }
Esempio n. 4
0
 public override void RaiseAutomationEvent(AutomationEvent eventId, AutomationEventArgs e)
 {
     // TODO
 }
Esempio n. 5
0
 public override void RaiseAutomationEvent(AutomationEvent eventId, AutomationEventArgs args)
 {
     base.RaiseAutomationEvent(eventId, args);
 }
Esempio n. 6
0
 public static IDisposable SubscribeToEvent(this AutomationElement element, AutomationEvent automationEvent, TreeScope treeScope, AutomationEventHandler handler)
 {
     return(Subscribe.ToEvent(element, automationEvent, treeScope, handler));
 }
        //------------------------------------------------------
        //
        //  Private Methods
        //
        //------------------------------------------------------

        #region Private Methods

        // turns a single event or an array of properties into an array of automation ids so either case
        // can be treated uniformly.
        private AutomationIdentifier[] EventKeys(AutomationEvent eventId, AutomationProperty[] properties)
        {
            return(eventId == AutomationElement.AutomationPropertyChangedEvent ? properties : new AutomationIdentifier[] { eventId });
        }
Esempio n. 8
0
 protected virtual void OnAutomationEvent(AutomationEventEventArgs e)
 {
     AutomationEvent?.Invoke(this, e);
 }
Esempio n. 9
0
 public static IDisposable RegisterHandler(AutomationEvent automationEvent, AutomationElement automationElement, AutomationEventHandler automationEventHandler)
 {
     return(new Handler(automationEvent, automationElement, automationEventHandler));
 }
 public AutomationEventWaiter(AutomationEvent eventId, UIObject uiObject, Scope scope)
     : this(eventId : eventId, uiObject : uiObject, scope : scope, condition : UICondition.True)
 {
 }
Esempio n. 11
0
 public static IDisposable ToEvent(AutomationElement element, AutomationEvent automationEvent, TreeScope treeScope, AutomationEventHandler handler)
 {
     Automation.AddAutomationEventHandler(automationEvent, element, treeScope, handler);
     return(Disposable.Create(() => Automation.RemoveAutomationEventHandler(automationEvent, element, handler)));
 }
Esempio n. 12
0
        internal static void RaiseAutomationEvent(IElement element, AutomationEvent eventId)
        {
            AutomationEventArgs e = new AutomationEventArgs(eventId);

            RaiseAutomationEvent(element, e);
        }
Esempio n. 13
0
        internal static void RaiseAutomationEvent(Accessible accessible, AutomationEvent eventId)
        {
            IElement element = Element.GetElement(accessible);

            RaiseAutomationEvent(element, eventId);
        }
Esempio n. 14
0
 public OrdinaryEvent(AutomationEvent eventId, TreeScope scope)
 {
     _scope   = scope;
     _eventId = eventId;
 }
Esempio n. 15
0
 public void RaiseAutomationEvent(AutomationEvent eventId, object provider, AutomationEventArgs e)
 {
     app.RaiseAutomationEvent(eventId, provider as IRawElementProviderSimple, e);
 }
Esempio n. 16
0
 public PropertyEventListener(AutomationEvent eventKind, AutomationElement element, AutomationPropertyChangedEventHandler handler) :
     base(AutomationElement.AutomationPropertyChangedEvent.Id, element.GetRuntimeId(), handler)
 {
     Debug.Assert(handler != null);
     this._propChangeHandler = handler;
 }
Esempio n. 17
0
 public StructureEventListener(AutomationEvent eventKind, AutomationElement element, StructureChangedEventHandler handler) :
     base(AutomationElement.StructureChangedEvent.Id, element.GetRuntimeId(), handler)
 {
     Debug.Assert(handler != null);
     this._structureChangeHandler = handler;
 }
Esempio n. 18
0
        // Builds a list of Win32 WinEvents to process a UIAutomation Event.
        protected virtual WinEventTracker.EvtIdProperty [] EventToWinEvent(AutomationEvent idEvent, out int cEvent)
        {
            // Fill this variable with a WinEvent id if found
            int idWinEvent = 0;

            if (idEvent == SelectionItemPattern.ElementSelectedEvent)
            {
                cEvent = 2;
                return(new WinEventTracker.EvtIdProperty[2]
                {
                    new WinEventTracker.EvtIdProperty(NativeMethods.EventObjectSelection, idEvent),
                    new WinEventTracker.EvtIdProperty(NativeMethods.EventObjectStateChange, idEvent)
                });
            }
            else if (idEvent == SelectionItemPattern.ElementAddedToSelectionEvent)
            {
                // For some control, the Event Selection is sent instead of SelectionAdd
                // Trap both.
                cEvent = 2;
                return(new WinEventTracker.EvtIdProperty [2]
                {
                    new WinEventTracker.EvtIdProperty(NativeMethods.EventObjectSelectionAdd, idEvent),
                    new WinEventTracker.EvtIdProperty(NativeMethods.EventObjectSelection, idEvent)
                });
            }
            else if (idEvent == SelectionItemPattern.ElementRemovedFromSelectionEvent)
            {
                idWinEvent = NativeMethods.EventObjectSelectionRemove;
            }
            else if (idEvent == SelectionPattern.InvalidatedEvent)
            {
                idWinEvent = NativeMethods.EventObjectSelectionWithin;
            }
            else if (idEvent == InvokePattern.InvokedEvent)
            {
                cEvent = 4;
                return(new WinEventTracker.EvtIdProperty[4] {
                    new WinEventTracker.EvtIdProperty(NativeMethods.EventSystemCaptureEnd, idEvent),  // For SysHeaders
                    new WinEventTracker.EvtIdProperty(NativeMethods.EventObjectStateChange, idEvent),
                    new WinEventTracker.EvtIdProperty(NativeMethods.EventObjectValueChange, idEvent), // For WindowsScrollBarBits
                    new WinEventTracker.EvtIdProperty(NativeMethods.EventObjectInvoke, idEvent)
                });
            }
            else if (idEvent == AutomationElement.StructureChangedEvent)
            {
                cEvent = 3;
                return(new WinEventTracker.EvtIdProperty[3] {
                    new WinEventTracker.EvtIdProperty(NativeMethods.EventObjectCreate, idEvent),
                    new WinEventTracker.EvtIdProperty(NativeMethods.EventObjectDestroy, idEvent),
                    new WinEventTracker.EvtIdProperty(NativeMethods.EventObjectReorder, idEvent)
                });
            }
            else if (idEvent == TextPattern.TextSelectionChangedEvent)
            {
                cEvent = 2;
                return(new WinEventTracker.EvtIdProperty[2] {
                    new WinEventTracker.EvtIdProperty(NativeMethods.EventObjectLocationChange, idEvent),
                    new WinEventTracker.EvtIdProperty(NativeMethods.EventObjectTextSelectionChanged, idEvent)
                });
            }
            else
            {
                cEvent = 0;
                return(null);
            }

            // found one and only one
            cEvent = 1;
            return(new WinEventTracker.EvtIdProperty [1] {
                new WinEventTracker.EvtIdProperty(idWinEvent, idEvent)
            });
        }
Esempio n. 19
0
 // Methods
 public AutomationEventArgsMapping(AutomationEvent aEvent, Type argsType)
 {
     this.Event         = aEvent;
     this.EventArgsType = argsType;
 }
Esempio n. 20
0
 public EventWrapper(AutomationWrapper automationWrapper, AutomationEvent automationEvent, AutomationEventHandler eventHandler)
 {
     _automationWrapper = automationWrapper;
     AutomationEvent    = automationEvent;
     _eventHandler      = eventHandler;
 }