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); } }
public BasicEventListener(AutomationEvent eventKind, AutomationElement element, AutomationEventHandler handler) : base(eventKind.Id, element.GetRuntimeId(), handler) { Debug.Assert(handler != null); this._basicHandler = handler; }
// 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; } } } }
public override void RaiseAutomationEvent(AutomationEvent eventId, AutomationEventArgs e) { // TODO }
public override void RaiseAutomationEvent(AutomationEvent eventId, AutomationEventArgs args) { base.RaiseAutomationEvent(eventId, args); }
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 }); }
protected virtual void OnAutomationEvent(AutomationEventEventArgs e) { AutomationEvent?.Invoke(this, e); }
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) { }
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))); }
internal static void RaiseAutomationEvent(IElement element, AutomationEvent eventId) { AutomationEventArgs e = new AutomationEventArgs(eventId); RaiseAutomationEvent(element, e); }
internal static void RaiseAutomationEvent(Accessible accessible, AutomationEvent eventId) { IElement element = Element.GetElement(accessible); RaiseAutomationEvent(element, eventId); }
public OrdinaryEvent(AutomationEvent eventId, TreeScope scope) { _scope = scope; _eventId = eventId; }
public void RaiseAutomationEvent(AutomationEvent eventId, object provider, AutomationEventArgs e) { app.RaiseAutomationEvent(eventId, provider as IRawElementProviderSimple, e); }
public PropertyEventListener(AutomationEvent eventKind, AutomationElement element, AutomationPropertyChangedEventHandler handler) : base(AutomationElement.AutomationPropertyChangedEvent.Id, element.GetRuntimeId(), handler) { Debug.Assert(handler != null); this._propChangeHandler = handler; }
public StructureEventListener(AutomationEvent eventKind, AutomationElement element, StructureChangedEventHandler handler) : base(AutomationElement.StructureChangedEvent.Id, element.GetRuntimeId(), handler) { Debug.Assert(handler != null); this._structureChangeHandler = handler; }
// 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) }); }
// Methods public AutomationEventArgsMapping(AutomationEvent aEvent, Type argsType) { this.Event = aEvent; this.EventArgsType = argsType; }
public EventWrapper(AutomationWrapper automationWrapper, AutomationEvent automationEvent, AutomationEventHandler eventHandler) { _automationWrapper = automationWrapper; AutomationEvent = automationEvent; _eventHandler = eventHandler; }