static WindowPatternIdentifiers () { Pattern = new AutomationPattern (PatternId, "WindowPatternIdentifiers.Pattern"); CanMaximizeProperty = new AutomationProperty (CanMaximizePropertyId, "WindowPatternIdentifiers.CanMaximizeProperty"); CanMinimizeProperty = new AutomationProperty (CanMinimizePropertyId, "WindowPatternIdentifiers.CanMinimizeProperty"); IsModalProperty = new AutomationProperty (IsModalPropertyId, "WindowPatternIdentifiers.IsModalProperty"); IsTopmostProperty = new AutomationProperty (IsTopmostPropertyId, "WindowPatternIdentifiers.IsTopmostProperty"); WindowInteractionStateProperty = new AutomationProperty (WindowInteractionStatePropertyId, "WindowPatternIdentifiers.WindowInteractionStateProperty"); WindowVisualStateProperty = new AutomationProperty (WindowVisualStatePropertyId, "WindowPatternIdentifiers.WindowVisualStateProperty"); WindowClosedEvent = new AutomationEvent (WindowClosedEventId, "WindowPatternIdentifiers.WindowClosedProperty"); WindowOpenedEvent = new AutomationEvent (WindowOpenedEventId, "WindowPatternIdentifiers.WindowOpenedProperty"); }
//------------------------------------------------------ // // Patterns Implementation // //------------------------------------------------------ #region ProxyHwnd Methods // ------------------------------------------------------ // // Internal Methods // // ------------------------------------------------------ // Advises proxy that an event has been added. // Maps the Automation Events into WinEvents and add those to the list of WinEvents notification hooks internal virtual void AdviseEventAdded (AutomationEvent eventId, AutomationProperty [] aidProps) { // No RawElementBase creation callback, exit from here if (_createOnEvent == null) { return; } int cEvents = 0; WinEventTracker.EvtIdProperty [] aEvents; // Gets an Array of WinEvents to trap on a per window handle basis if (eventId == AutomationElement.AutomationPropertyChangedEvent) { aEvents = PropertyToWinEvent (aidProps, out cEvents); } else { aEvents = EventToWinEvent (eventId, out cEvents); } // If we have WinEvents to trap, add those to the list of WinEvent // notification list if (cEvents > 0) { WinEventTracker.AddToNotificationList (_hwnd, _createOnEvent, aEvents, cEvents); } }
public void RaiseAutomationEvent (AutomationEvent eventId, object provider, AutomationEventArgs e) { var providerSimple = provider as IRawElementProviderSimple; if (providerSimple == null) return; ClientEventManager.RaiseAutomationEvent (eventId, providerSimple, e); }
public override void RaiseAutomationEvent (AutomationEvent eventId, AutomationEventArgs e) { if (eventId == GridPatternIdentifiers.ColumnReorderedEvent) EmitSignal ("column_reordered"); else base.RaiseAutomationEvent (eventId, e); // TODO }
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); }
public static void RemoveAutomationEventHandler (AutomationEvent eventId, IRawElementProviderSimple provider, AutomationEventHandler eventHandler) { lock (automationEventEntries) automationEventEntries.RemoveAll (e => e.EventId == eventId && e.Provider == provider && e.Handler == eventHandler); }
public override void RaiseAutomationEvent (AutomationEvent eventId, AutomationEventArgs e) { if (eventId != AutomationElementIdentifiers.MenuClosedEvent) base.RaiseAutomationEvent (eventId, e); TopLevelRootItem.Instance.RemoveChild (Parent); ((ParentAdapter)Parent).RemoveChild (this); AutomationBridge.HandleTotalElementRemoval (this.Provider); }
static InvokePatternIdentifiers () { InvokedEvent = new AutomationEvent (InvokedEventId, "InvokePatternIdentifiers.InvokedEvent"); Pattern = new AutomationPattern (PatternId, "InvokePatternIdentifiers.Pattern"); }
public override void RaiseAutomationEvent (AutomationEvent eventId, AutomationEventArgs e) { if (eventId == AutomationElementIdentifiers.AsyncContentLoadedEvent) { // TODO: Handle AsyncContentLoadedEvent } else if (eventId == AutomationElementIdentifiers.StructureChangedEvent) { // TODO: Handle StructureChangedEvent } else base.RaiseAutomationEvent (eventId, e); }
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 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); }
//------------------------------------------------------ // // 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; }
private void AddEventHandler( AutomationEvent automationEvent, AutomationEventHandler eventHandler) { _currentElement = AutomationElement.FocusedElement; if (_currentElement != null) { Automation.AddAutomationEventHandler( automationEvent, _currentElement, TreeScope.Element, eventHandler); } else this.UiFeedback("(no element)"); }
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 static EventListener Remove(AutomationEvent eventId, AutomationElement element, Delegate handler) { // Create a prototype to seek int[] runtimeId = (element == null) ? null : element.GetRuntimeId(); EventListener prototype = new EventListener(eventId.Id, runtimeId, handler); lock (_events) { LinkedListNode<EventListener> node = _events.Find(prototype); if (node == null) { throw new ArgumentException("event handler not found"); } EventListener result = node.Value; _events.Remove(node); return result; } }
static GridPatternIdentifiers () { Pattern = new AutomationPattern (PatternId, "GridPatternIdentifiers.Pattern"); RowCountProperty = new AutomationProperty (RowCountPropertyId, "GridPatternIdentifiers.RowCountProperty"); ColumnCountProperty = new AutomationProperty (ColumnCountPropertyId, "GridPatternIdentifiers.ColumnCountProperty"); ColumnReorderedEvent = new AutomationEvent (ColumnReorderedEventId, "GridPatternIdentifiers.ColumnReorderedEvent"); }
// a client is listening for an event on object(s) in the specified window. internal void AdviseEventAdded(IntPtr hwnd, AutomationEvent eventId, AutomationProperty[] properties) { // // we have a two-level table structure. the top-level table maps an hwnd to another table. // the second-level table maps an event (or a property in the case of property-changed-event) // in that hwnd to a reference count of the number of clients listening for that event. // use a lock to update our tables in one atomic operation. lock (this) { // if we aren't listening for WinEvents then start listening. if (_hwndTable.Count == 0) { //Debug.WriteLine("Starting listening for WinEvents.", "NativeMsaaProxy"); // Posting an item to the queue to start listening for WinEvents. This makes sure it is done on the proper thread // Notably the same thread WinEventTracker uses, which guarantees the thread that SetWinEventHook is called on is // actively pumping messages, which is required for SetWinEventHook to function properly. WinEventTracker.GetCallbackQueue().PostSyncWorkItem(new QueueItem.MSAAWinEventItem(StartListening)); } // if we already have a 2-nd level table for this hwnd then simply update the 2nd-level table. // otherwise we need to create a 2-nd level table. Hashtable eventTable; if (_hwndTable.ContainsKey(hwnd)) { eventTable = (Hashtable)(_hwndTable[hwnd]); } else { eventTable = new Hashtable(); _hwndTable[hwnd] = eventTable; } // for the single event or each of possibly multiple properties increment the reference counter. foreach (AutomationIdentifier key in EventKeys(eventId, properties)) { eventTable[key] = eventTable.ContainsKey(key) ? (int)eventTable[key] + 1 : 1; } } }
static SelectionPatternIdentifiers () { Pattern = new AutomationPattern (PatternId, "SelectionPatternIdentifiers.Pattern"); CanSelectMultipleProperty = new AutomationProperty (CanSelectMultiplePropertyId, "SelectionPatternIdentifiers.CanSelectMultipleProperty"); IsSelectionRequiredProperty = new AutomationProperty (IsSelectionRequiredPropertyId, "SelectionPatternIdentifiers.IsSelectionRequiredProperty"); SelectionProperty = new AutomationProperty (SelectionPropertyId, "SelectionPatternIdentifiers.SelectionProperty"); InvalidatedEvent = new AutomationEvent (InvalidatedEventId, "SelectionPatternIdentifiers.InvalidatedEvent"); }
static SelectionItemPatternIdentifiers () { Pattern = new AutomationPattern (PatternId, "SelectionItemPatternIdentifiers.Pattern"); ElementAddedToSelectionEvent = new AutomationEvent (ElementAddedToSelectionEventId, "SelectionItemPatternIdentifiers.ElementAddedToSelectionEvent"); ElementRemovedFromSelectionEvent = new AutomationEvent (ElementRemovedFromSelectionEventId, "SelectionItemPatternIdentifiers.ElementRemovedFromSelectionEvent"); ElementSelectedEvent = new AutomationEvent (ElementSelectedEventId, "SelectionItemPatternIdentifiers.ElementSelectedEvent"); IsSelectedProperty = new AutomationProperty (IsSelectedPropertyId, "SelectionItemPatternIdentifiers.IsSelectedProperty"); SelectionContainerProperty = new AutomationProperty (SelectionContainerPropertyId, "SelectionItemPatternIdentifiers.SelectionContainerProperty"); }
internal override void AdviseEventRemoved (AutomationEvent eventId, AutomationProperty [] aidProps) { // we need to create the menu proxy so that the global event for menu will be listened for. // This proxy will get advise of events needed for menus ProxyHwnd menuProxy = CreateNonClientMenu(); if (menuProxy == null) { // If the window does not have a menu, it at least has a system menu. WindowsTitleBar titleBar = (WindowsTitleBar)CreateNonClientChild(NonClientItem.TitleBar); if (titleBar != null) { menuProxy = (ProxyHwnd)titleBar.CreateTitleBarChild(WindowsTitleBar._systemMenu); } } if (menuProxy != null) { menuProxy.AdviseEventRemoved(eventId, aidProps); } base.AdviseEventRemoved(eventId, aidProps); }
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; } } }
// IsListeningFor - called by UIAccess client during removal of listeners. Returns // true if rid, eventId and clientCallback represent this listener instance. internal bool IsListeningFor(AutomationEvent eventId, AutomationElement el, Delegate clientCallback) { // Removing the event handler using the element RuntimeId prevents problems with dead elements int[] rid = null; try { rid = el.GetRuntimeId(); } catch( ElementNotAvailableException ) { // This can't be the element this instance is holding because when // creating this instance we caused the RuntimeId to be cached. return false; } if( !Misc.Compare( _refRid, rid ) ) return false; if( _eventListener.EventId != eventId ) return false; if (_clientCallback != clientCallback) return false; return true; }
// Builds a list of Win32 WinEvents to process a UIAutomation Event. // Returns an array of Events to Set. The number of valid entries in this array pass back in cEvent. protected override WinEventTracker.EvtIdProperty [] EventToWinEvent (AutomationEvent idEvent, out int cEvent) { if (idEvent == AutomationElement.StructureChangedEvent) { cEvent = 3; return new WinEventTracker.EvtIdProperty [3] { new WinEventTracker.EvtIdProperty (NativeMethods.EventObjectStateChange, idEvent), new WinEventTracker.EvtIdProperty (NativeMethods.EventObjectCreate, idEvent), new WinEventTracker.EvtIdProperty (NativeMethods.EventObjectDestroy, idEvent) }; } return base.EventToWinEvent (idEvent, out cEvent); }
public override void RaiseAutomationEvent (AutomationEvent eventId, AutomationEventArgs args) { base.RaiseAutomationEvent (eventId, args); }
public static void RemoveAutomationEventHandler(AutomationEvent eventId, AutomationElement element, 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 = (BasicEventListener)ClientEventList.Remove(eventId, element, eventHandler); Factory.RemoveAutomationEventHandler(eventId.Id, element.NativeElement, listener); } catch (System.Runtime.InteropServices.COMException e) { Exception newEx; if (Utility.ConvertException(e, out newEx)) { throw newEx; } else { throw; } } }
/// <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); }
internal static AutomationIdentifier Register(UiaCoreIds.AutomationIdType type, Guid guid, string programmaticName) { int id = UiaCoreIds.UiaLookupId(type, ref guid); if (id == 0) { return null; } lock (_identifierDirectory) { AutomationIdentifier identifier = (AutomationIdentifier)_identifierDirectory[guid]; if (identifier == null) { switch (type) { case UiaCoreIds.AutomationIdType.Property: identifier = new AutomationProperty(id, guid, programmaticName); break; case UiaCoreIds.AutomationIdType.Pattern: identifier = new AutomationPattern(id, guid, programmaticName); break; case UiaCoreIds.AutomationIdType.Event: identifier = new AutomationEvent(id, guid, programmaticName); break; case UiaCoreIds.AutomationIdType.ControlType: identifier = new ControlType(id, guid, programmaticName); break; case UiaCoreIds.AutomationIdType.TextAttribute: identifier = new AutomationTextAttribute(id, guid, programmaticName); break; default: throw new InvalidOperationException("Invalid type specified for AutomationIdentifier"); } _identifierDirectory[id] = identifier; } return identifier; } }
internal override void AdviseEventRemoved( AutomationEvent eventId, AutomationProperty[] aidProps) { if (eventId == AutomationElementIdentifiers.AutomationPropertyChangedEvent && aidProps.Length > 0 && aidProps[0] == ScrollPatternIdentifiers.HorizontalScrollPercentProperty) { IntPtr upDownHwnd = GetUpDownHwnd(); if (upDownHwnd != IntPtr.Zero) { WinEventTracker.RemoveToNotificationList( upDownHwnd, _upDownEvents, null, 1); } } base.AdviseEventRemoved(eventId, aidProps); }
static TextPatternIdentifiers () { MixedAttributeValue = new object (); Pattern = new AutomationPattern (PatternId, "TextPatternIdentifiers.Pattern"); CaretMovedEvent = new AutomationEvent (CaretMovedEventId, "TextPatternIdentifiers.CaretMovedEvent"); TextChangedEvent = new AutomationEvent (TextChangedEventId, "TextPatternIdentifiers.TextChangedEvent"); TextSelectionChangedEvent = new AutomationEvent (TextSelectionChangedEventId, "TextPatternIdentifiers.TextSelectionChangedEvent"); AnimationStyleAttribute = new AutomationTextAttribute (AnimationStyleAttributeId, "TextPatternIdentifiers.AnimationStyleAttribute"); BackgroundColorAttribute = new AutomationTextAttribute (BackgroundColorAttributeId, "TextPatternIdentifiers.BackgroundColorAttribute"); BulletStyleAttribute = new AutomationTextAttribute (BulletStyleAttributeId, "TextPatternIdentifiers.BulletStyleAttribute"); CapStyleAttribute = new AutomationTextAttribute (CapStyleAttributeId, "TextPatternIdentifiers.CapStyleAttribute"); CultureAttribute = new AutomationTextAttribute (CultureAttributeId, "TextPatternIdentifiers.CultureAttribute"); FontNameAttribute = new AutomationTextAttribute (FontNameAttributeId, "TextPatternIdentifiers.FontNameAttribute"); FontSizeAttribute = new AutomationTextAttribute (FontSizeAttributeId, "TextPatternIdentifiers.FontSizeAttribute"); FontWeightAttribute = new AutomationTextAttribute (FontWeightAttributeId, "TextPatternIdentifiers.FontWeightAttribute"); ForegroundColorAttribute = new AutomationTextAttribute (ForegroundColorAttributeId, "TextPatternIdentifiers.ForegroundColorAttribute"); HorizontalTextAlignmentAttribute = new AutomationTextAttribute (HorizontalTextAlignmentAttributeId, "TextPatternIdentifiers.HorizontalTextAlignmentAttribute"); IndentationFirstLineAttribute = new AutomationTextAttribute (IndentationFirstLineAttributeId, "TextPatternIdentifiers.IndentationFirstLineAttribute"); IndentationLeadingAttribute = new AutomationTextAttribute (IndentationLeadingAttributeId, "TextPatternIdentifiers.IndentationLeadingAttribute"); IndentationTrailingAttribute = new AutomationTextAttribute (IndentationTrailingAttributeId, "TextPatternIdentifiers.IndentationTrailingAttribute"); IsHiddenAttribute = new AutomationTextAttribute (IsHiddenAttributeId, "TextPatternIdentifiers.IsHiddenAttribute"); IsItalicAttribute = new AutomationTextAttribute (IsItalicAttributeId, "TextPatternIdentifiers.IsItalicAttribute"); IsReadOnlyAttribute = new AutomationTextAttribute (IsReadOnlyAttributeId, "TextPatternIdentifiers.IsReadOnlyAttribute"); IsSubscriptAttribute = new AutomationTextAttribute (IsSubscriptAttributeId, "TextPatternIdentifiers.IsSubscriptAttribute"); IsSuperscriptAttribute = new AutomationTextAttribute (IsSuperscriptAttributeId, "TextPatternIdentifiers.IsSuperscriptAttribute"); MarginBottomAttribute = new AutomationTextAttribute (MarginBottomAttributeId, "TextPatternIdentifiers.MarginBottomAttribute"); MarginLeadingAttribute = new AutomationTextAttribute (MarginLeadingAttributeId, "TextPatternIdentifiers.MarginLeadingAttribute"); MarginTopAttribute = new AutomationTextAttribute (MarginTopAttributeId, "TextPatternIdentifiers.MarginTopAttribute"); MarginTrailingAttribute = new AutomationTextAttribute (MarginTrailingAttributeId, "TextPatternIdentifiers.MarginTrailingAttribute"); OutlineStylesAttribute = new AutomationTextAttribute (OutlineStylesAttributeId, "TextPatternIdentifiers.OutlineStylesAttribute"); OverlineColorAttribute = new AutomationTextAttribute (OverlineColorAttributeId, "TextPatternIdentifiers.OverlineColorAttribute"); OverlineStyleAttribute = new AutomationTextAttribute (OverlineStyleAttributeId, "TextPatternIdentifiers.OverlineStyleAttribute"); StrikethroughColorAttribute = new AutomationTextAttribute (StrikethroughColorAttributeId, "TextPatternIdentifiers.StrikethroughColorAttribute"); StrikethroughStyleAttribute = new AutomationTextAttribute (StrikethroughStyleAttributeId, "TextPatternIdentifiers.StrikethroughStyleAttribute"); TabsAttribute = new AutomationTextAttribute (TabsAttributeId, "TextPatternIdentifiers.TabsAttribute"); TextFlowDirectionsAttribute = new AutomationTextAttribute (TextFlowDirectionsAttributeId, "TextPatternIdentifiers.TextFlowDirectionsAttribute"); UnderlineColorAttribute = new AutomationTextAttribute (UnderlineColorAttributeId, "TextPatternIdentifiers.UnderlineColorAttribute"); UnderlineStyleAttribute = new AutomationTextAttribute (UnderlineStyleAttributeId, "TextPatternIdentifiers.UnderlineStyleAttribute"); }
static AutomationElementIdentifiers() { NotSupported = new object(); // Automation Properties HasNativeAccessibilityObjectProperty = new AutomationProperty(HasNativeAccessibilityObjectPropertyId, "AutomationElementIdentifiers.HasNativeAccessibilityObjectProperty"); NativeAccessibilityObjectProperty = new AutomationProperty(NativeAccessibilityObjectPropertyId, "AutomationElementIdentifiers.NativeAccessibilityObjectProperty"); IsNotifyIconProperty = new AutomationProperty(IsNotifyIconPropertyId, "AutomationElementIdentifiers.IsNotifyIconProperty"); AcceleratorKeyProperty = new AutomationProperty(AcceleratorKeyPropertyId, "AutomationElementIdentifiers.AcceleratorKeyProperty"); AccessKeyProperty = new AutomationProperty(AccessKeyPropertyId, "AutomationElementIdentifiers.AccessKeyProperty"); AutomationIdProperty = new AutomationProperty(AutomationIdPropertyId, "AutomationElementIdentifiers.AutomationIdProperty"); BoundingRectangleProperty = new AutomationProperty(BoundingRectanglePropertyId, "AutomationElementIdentifiers.BoundingRectangleProperty"); ClassNameProperty = new AutomationProperty(ClassNamePropertyId, "AutomationElementIdentifiers.ClassNameProperty"); ClickablePointProperty = new AutomationProperty(ClickablePointPropertyId, "AutomationElementIdentifiers.ClickablePointProperty"); ControlTypeProperty = new AutomationProperty(ControlTypePropertyId, "AutomationElementIdentifiers.ControlTypeProperty"); CultureProperty = new AutomationProperty(CulturePropertyId, "AutomationElementIdentifiers.CultureProperty"); FrameworkIdProperty = new AutomationProperty(FrameworkIdPropertyId, "AutomationElementIdentifiers.FrameworkIdProperty"); HasKeyboardFocusProperty = new AutomationProperty(HasKeyboardFocusPropertyId, "AutomationElementIdentifiers.HasKeyboardFocusProperty"); HelpTextProperty = new AutomationProperty(HelpTextPropertyId, "AutomationElementIdentifiers.HelpTextProperty"); IsContentElementProperty = new AutomationProperty(IsContentElementPropertyId, "AutomationElementIdentifiers.IsContentElementProperty"); IsControlElementProperty = new AutomationProperty(IsControlElementPropertyId, "AutomationElementIdentifiers.IsControlElementProperty"); IsDockPatternAvailableProperty = new AutomationProperty(IsDockPatternAvailablePropertyId, "AutomationElementIdentifiers.IsDockPatternAvailableProperty"); IsEnabledProperty = new AutomationProperty(IsEnabledPropertyId, "AutomationElementIdentifiers.IsEnabledProperty"); IsExpandCollapsePatternAvailableProperty = new AutomationProperty(IsExpandCollapsePatternAvailablePropertyId, "AutomationElementIdentifiers.IsExpandCollapsePatternAvailableProperty"); IsGridItemPatternAvailableProperty = new AutomationProperty(IsGridItemPatternAvailablePropertyId, "AutomationElementIdentifiers.IsGridItemPatternAvailableProperty"); IsGridPatternAvailableProperty = new AutomationProperty(IsGridPatternAvailablePropertyId, "AutomationElementIdentifiers.IsGridPatternAvailableProperty"); IsInvokePatternAvailableProperty = new AutomationProperty(IsInvokePatternAvailablePropertyId, "AutomationElementIdentifiers.IsInvokePatternAvailableProperty"); IsKeyboardFocusableProperty = new AutomationProperty(IsKeyboardFocusablePropertyId, "AutomationElementIdentifiers.IsKeyboardFocusableProperty"); IsLegacyIAccessiblePatternAvailableProperty = new AutomationProperty(IsLegacyIAccessiblePatternAvailablePropertyId, "AutomationElementIdentifiers.IsLegacyIAccessiblePatternAvailableProperty"); IsMultipleViewPatternAvailableProperty = new AutomationProperty(IsMultipleViewPatternAvailablePropertyId, "AutomationElementIdentifiers.IsMultipleViewPatternAvailableProperty"); IsOffscreenProperty = new AutomationProperty(IsOffscreenPropertyId, "AutomationElementIdentifiers.IsOffscreenProperty"); IsPasswordProperty = new AutomationProperty(IsPasswordPropertyId, "AutomationElementIdentifiers.IsPasswordProperty"); IsRangeValuePatternAvailableProperty = new AutomationProperty(IsRangeValuePatternAvailablePropertyId, "AutomationElementIdentifiers.IsRangeValuePatternAvailableProperty"); IsRequiredForFormProperty = new AutomationProperty(IsRequiredForFormPropertyId, "AutomationElementIdentifiers.IsRequiredForFormProperty"); IsScrollItemPatternAvailableProperty = new AutomationProperty(IsScrollItemPatternAvailablePropertyId, "AutomationElementIdentifiers.IsScrollItemPatternAvailableProperty"); IsScrollPatternAvailableProperty = new AutomationProperty(IsScrollPatternAvailablePropertyId, "AutomationElementIdentifiers.IsScrollPatternAvailableProperty"); IsSelectionItemPatternAvailableProperty = new AutomationProperty(IsSelectionItemPatternAvailablePropertyId, "AutomationElementIdentifiers.IsSelectionItemPatternAvailableProperty"); IsSelectionPatternAvailableProperty = new AutomationProperty(IsSelectionPatternAvailablePropertyId, "AutomationElementIdentifiers.IsSelectionPatternAvailableProperty"); IsTableItemPatternAvailableProperty = new AutomationProperty(IsTableItemPatternAvailablePropertyId, "AutomationElementIdentifiers.IsTableItemPatternAvailableProperty"); IsTablePatternAvailableProperty = new AutomationProperty(IsTablePatternAvailablePropertyId, "AutomationElementIdentifiers.IsTablePatternAvailableProperty"); IsTextPatternAvailableProperty = new AutomationProperty(IsTextPatternAvailablePropertyId, "AutomationElementIdentifiers.IsTextPatternAvailableProperty"); IsTogglePatternAvailableProperty = new AutomationProperty(IsTogglePatternAvailablePropertyId, "AutomationElementIdentifiers.IsTogglePatternAvailableProperty"); IsTransformPatternAvailableProperty = new AutomationProperty(IsTransformPatternAvailablePropertyId, "AutomationElementIdentifiers.IsTransformPatternAvailableProperty"); IsValuePatternAvailableProperty = new AutomationProperty(IsValuePatternAvailablePropertyId, "AutomationElementIdentifiers.IsValuePatternAvailableProperty"); IsWindowPatternAvailableProperty = new AutomationProperty(IsWindowPatternAvailablePropertyId, "AutomationElementIdentifiers.IsWindowPatternAvailableProperty"); ItemStatusProperty = new AutomationProperty(ItemStatusPropertyId, "AutomationElementIdentifiers.ItemStatusProperty"); ItemTypeProperty = new AutomationProperty(ItemTypePropertyId, "AutomationElementIdentifiers.ItemTypeProperty"); LabeledByProperty = new AutomationProperty(LabeledByPropertyId, "AutomationElementIdentifiers.LabeledByProperty"); LocalizedControlTypeProperty = new AutomationProperty(LocalizedControlTypePropertyId, "AutomationElementIdentifiers.LocalizedControlTypeProperty"); NameProperty = new AutomationProperty(NamePropertyId, "AutomationElementIdentifiers.NameProperty"); NativeWindowHandleProperty = new AutomationProperty(NativeWindowHandlePropertyId, "AutomationElementIdentifiers.NativeWindowHandleProperty"); OrientationProperty = new AutomationProperty(OrientationPropertyId, "AutomationElementIdentifiers.OrientationProperty"); ProcessIdProperty = new AutomationProperty(ProcessIdPropertyId, "AutomationElementIdentifiers.ProcessIdProperty"); RuntimeIdProperty = new AutomationProperty(RuntimeIdPropertyId, "AutomationElementIdentifiers.RuntimeIdProperty"); // Automation Events WindowDeactivatedEvent = new AutomationEvent(WindowDeactivatedEventId, "AutomationElementIdentifiers.WindowDeactivatedEvent"); KeyEvent = new AutomationEvent(KeyEventId, "AutomationElementIdentifiers.KeyEvent"); AsyncContentLoadedEvent = new AutomationEvent(AsyncContentLoadedEventId, "AutomationElementIdentifiers.AsyncContentLoadedEvent"); AutomationFocusChangedEvent = new AutomationEvent(AutomationFocusChangedEventId, "AutomationElementIdentifiers.AutomationFocusChangedEvent"); AutomationPropertyChangedEvent = new AutomationEvent(AutomationPropertyChangedEventId, "AutomationElementIdentifiers.AutomationPropertyChangedEvent"); LayoutInvalidatedEvent = new AutomationEvent(LayoutInvalidatedEventId, "AutomationElementIdentifiers.LayoutInvalidatedEvent"); MenuClosedEvent = new AutomationEvent(MenuClosedEventId, "AutomationElementIdentifiers.MenuClosedEvent"); MenuOpenedEvent = new AutomationEvent(MenuOpenedEventId, "AutomationElementIdentifiers.MenuOpenedEvent"); StructureChangedEvent = new AutomationEvent(StructureChangedEventId, "AutomationElementIdentifiers.StructureChangedEvent"); ToolTipClosedEvent = new AutomationEvent(ToolTipClosedEventId, "AutomationElementIdentifiers.ToolTipClosedEvent"); ToolTipOpenedEvent = new AutomationEvent(ToolTipOpenedEventId, "AutomationElementIdentifiers.ToolTipOpenedEvent"); }
public AutomationEventArgs(AutomationEvent eventId) { this._eventId = eventId; }
/// <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); }
internal static AutomationIdentifier Register(UiaCoreTypesApi.AutomationIdType type, Guid guid, string programmaticName) { int num = UiaCoreTypesApi.UiaLookupId(type, ref guid); if (num == 0) { if ((!AutomationIdentifier.IsWin7OnlyPatternGuid(guid) && Environment.OSVersion.Version.Major <= 6) || Environment.OSVersion.Version.Major >= 7) { int num2 = 1; while (num == 0 && num2 < 1000) { Thread.Sleep(num2); num = UiaCoreTypesApi.UiaLookupId(type, ref guid); num2 *= 2; } } if (num == 0) { return(null); } } Hashtable idTable = AutomationIdentifier._idTable; AutomationIdentifier result; lock (idTable) { AutomationIdentifier automationIdentifier = (AutomationIdentifier)AutomationIdentifier._idTable[guid]; if (automationIdentifier != null) { result = automationIdentifier; } else { switch (type) { case UiaCoreTypesApi.AutomationIdType.Property: automationIdentifier = new AutomationProperty(num, guid, programmaticName); break; case UiaCoreTypesApi.AutomationIdType.Pattern: automationIdentifier = new AutomationPattern(num, guid, programmaticName); break; case UiaCoreTypesApi.AutomationIdType.Event: automationIdentifier = new AutomationEvent(num, guid, programmaticName); break; case UiaCoreTypesApi.AutomationIdType.ControlType: automationIdentifier = new ControlType(num, guid, programmaticName); break; case UiaCoreTypesApi.AutomationIdType.TextAttribute: automationIdentifier = new AutomationTextAttribute(num, guid, programmaticName); break; default: throw new InvalidOperationException("Invalid type specified for AutomationIdentifier"); } AutomationIdentifier._idTable[num] = automationIdentifier; result = automationIdentifier; } } return(result); }
static TextPatternIdentifiers() { MixedAttributeValue = new object(); Pattern = new AutomationPattern(PatternId, "TextPatternIdentifiers.Pattern"); CaretMovedEvent = new AutomationEvent(CaretMovedEventId, "TextPatternIdentifiers.CaretMovedEvent"); TextChangedEvent = new AutomationEvent(TextChangedEventId, "TextPatternIdentifiers.TextChangedEvent"); TextSelectionChangedEvent = new AutomationEvent(TextSelectionChangedEventId, "TextPatternIdentifiers.TextSelectionChangedEvent"); AnimationStyleAttribute = new AutomationTextAttribute(AnimationStyleAttributeId, "TextPatternIdentifiers.AnimationStyleAttribute"); BackgroundColorAttribute = new AutomationTextAttribute(BackgroundColorAttributeId, "TextPatternIdentifiers.BackgroundColorAttribute"); BulletStyleAttribute = new AutomationTextAttribute(BulletStyleAttributeId, "TextPatternIdentifiers.BulletStyleAttribute"); CapStyleAttribute = new AutomationTextAttribute(CapStyleAttributeId, "TextPatternIdentifiers.CapStyleAttribute"); CultureAttribute = new AutomationTextAttribute(CultureAttributeId, "TextPatternIdentifiers.CultureAttribute"); FontNameAttribute = new AutomationTextAttribute(FontNameAttributeId, "TextPatternIdentifiers.FontNameAttribute"); FontSizeAttribute = new AutomationTextAttribute(FontSizeAttributeId, "TextPatternIdentifiers.FontSizeAttribute"); FontWeightAttribute = new AutomationTextAttribute(FontWeightAttributeId, "TextPatternIdentifiers.FontWeightAttribute"); ForegroundColorAttribute = new AutomationTextAttribute(ForegroundColorAttributeId, "TextPatternIdentifiers.ForegroundColorAttribute"); HorizontalTextAlignmentAttribute = new AutomationTextAttribute(HorizontalTextAlignmentAttributeId, "TextPatternIdentifiers.HorizontalTextAlignmentAttribute"); IndentationFirstLineAttribute = new AutomationTextAttribute(IndentationFirstLineAttributeId, "TextPatternIdentifiers.IndentationFirstLineAttribute"); IndentationLeadingAttribute = new AutomationTextAttribute(IndentationLeadingAttributeId, "TextPatternIdentifiers.IndentationLeadingAttribute"); IndentationTrailingAttribute = new AutomationTextAttribute(IndentationTrailingAttributeId, "TextPatternIdentifiers.IndentationTrailingAttribute"); IsHiddenAttribute = new AutomationTextAttribute(IsHiddenAttributeId, "TextPatternIdentifiers.IsHiddenAttribute"); IsItalicAttribute = new AutomationTextAttribute(IsItalicAttributeId, "TextPatternIdentifiers.IsItalicAttribute"); IsReadOnlyAttribute = new AutomationTextAttribute(IsReadOnlyAttributeId, "TextPatternIdentifiers.IsReadOnlyAttribute"); IsSubscriptAttribute = new AutomationTextAttribute(IsSubscriptAttributeId, "TextPatternIdentifiers.IsSubscriptAttribute"); IsSuperscriptAttribute = new AutomationTextAttribute(IsSuperscriptAttributeId, "TextPatternIdentifiers.IsSuperscriptAttribute"); MarginBottomAttribute = new AutomationTextAttribute(MarginBottomAttributeId, "TextPatternIdentifiers.MarginBottomAttribute"); MarginLeadingAttribute = new AutomationTextAttribute(MarginLeadingAttributeId, "TextPatternIdentifiers.MarginLeadingAttribute"); MarginTopAttribute = new AutomationTextAttribute(MarginTopAttributeId, "TextPatternIdentifiers.MarginTopAttribute"); MarginTrailingAttribute = new AutomationTextAttribute(MarginTrailingAttributeId, "TextPatternIdentifiers.MarginTrailingAttribute"); OutlineStylesAttribute = new AutomationTextAttribute(OutlineStylesAttributeId, "TextPatternIdentifiers.OutlineStylesAttribute"); OverlineColorAttribute = new AutomationTextAttribute(OverlineColorAttributeId, "TextPatternIdentifiers.OverlineColorAttribute"); OverlineStyleAttribute = new AutomationTextAttribute(OverlineStyleAttributeId, "TextPatternIdentifiers.OverlineStyleAttribute"); StrikethroughColorAttribute = new AutomationTextAttribute(StrikethroughColorAttributeId, "TextPatternIdentifiers.StrikethroughColorAttribute"); StrikethroughStyleAttribute = new AutomationTextAttribute(StrikethroughStyleAttributeId, "TextPatternIdentifiers.StrikethroughStyleAttribute"); TabsAttribute = new AutomationTextAttribute(TabsAttributeId, "TextPatternIdentifiers.TabsAttribute"); TextFlowDirectionsAttribute = new AutomationTextAttribute(TextFlowDirectionsAttributeId, "TextPatternIdentifiers.TextFlowDirectionsAttribute"); UnderlineColorAttribute = new AutomationTextAttribute(UnderlineColorAttributeId, "TextPatternIdentifiers.UnderlineColorAttribute"); UnderlineStyleAttribute = new AutomationTextAttribute(UnderlineStyleAttributeId, "TextPatternIdentifiers.UnderlineStyleAttribute"); }
/// <summary> /// Called by a client to remove a listener for pattern or custom events. /// </summary> /// <param name="eventId">a UIAccess or custom event identifier.</param> /// <param name="element">Element to remove listener for</param> /// <param name="eventHandler">The handler object that was passed to AddEventListener</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 RemoveAutomationEventHandler( AutomationEvent eventId, AutomationElement element, 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 ); //CASRemoval:AutomationPermission.Demand( AutomationPermissionFlag.Read ); // Remove the client-side listener for for this event ClientEventManager.RemoveListener( eventId, element, eventHandler ); }
void IUIAutomationEventHandler.HandleAutomationEvent( IUIAutomationElement sender, int eventId) { AutomationElement automationElement = null; if (sender != null) { automationElement = new AutomationElement(autoElement: sender); } if (eventId == 20017) { this._handlingDelegate(sender: automationElement, e: new WindowClosedEventArgs(runtimeId: automationElement.GetRuntimeId())); } else { this._handlingDelegate(sender: automationElement, e: new AutomationEventArgs(eventId: AutomationEvent.LookupById(id: eventId))); } }