public static void AddAutomationEventHandler(AutomationEvent eventId, AutomationElement element, TreeScope scope, AutomationEventHandler eventHandler) { CheckAutomationEventId(eventId); ArgumentCheck.NotNull(element, "element"); ArgumentCheck.NotNull(eventHandler, "eventHandler"); //TODO In theory we shall also check scope not equals to Parent or Ancestors, //but .Net didn't test/throw exceptions for "scope" if (element == AutomationElement.RootElement) { foreach (var source in SourceManager.GetAutomationSources()) { source.AddAutomationEventHandler( eventId, null, scope, eventHandler); } } else { var source = element.SourceElement.AutomationSource; source.AddAutomationEventHandler( eventId, element.SourceElement, scope, eventHandler); } }
public static void RemoveAllEventHandlers() { lock (focusHandlerMapping) focusHandlerMapping.Clear(); foreach (var source in SourceManager.GetAutomationSources()) { source.RemoveAllEventHandlers(); } AddAutomationFocusChangedEventHandler(AutomationElement.OnFocusChanged); }
private static void InitializeRootElements() { lock (RawViewWalker.directChildrenLock) { var pidElementMapping = new Dictionary <int, IElement> (); RawViewWalker.directChildren = new List <AutomationElement> (); foreach (IAutomationSource source in SourceManager.GetAutomationSources()) { AddUniqueRootElements(RawViewWalker.directChildren, source, pidElementMapping); source.RootElementsChanged += (s, e) => OnSourceRootElementChanged((IAutomationSource)s); } } }
public static void RemoveAutomationFocusChangedEventHandler(AutomationFocusChangedEventHandler eventHandler) { ArgumentCheck.NotNull(eventHandler, "eventHandler"); MUS.FocusChangedEventHandler sourceHandler; lock (focusHandlerMapping) { if (focusHandlerMapping.TryGetValue(eventHandler, out sourceHandler)) { focusHandlerMapping.Remove(eventHandler); foreach (var source in SourceManager.GetAutomationSources()) { source.RemoveAutomationFocusChangedEventHandler(sourceHandler); } } } }
public static void AddAutomationFocusChangedEventHandler(AutomationFocusChangedEventHandler eventHandler) { ArgumentCheck.NotNull(eventHandler, "eventHandler"); MUS.FocusChangedEventHandler sourceHandler; //according to the spec, all static methods in the UIA lib shall be thread safe. lock (focusHandlerMapping) { if (!focusHandlerMapping.TryGetValue(eventHandler, out sourceHandler)) { sourceHandler = (element, objectId, childId) => eventHandler( SourceManager.GetOrCreateAutomationElement(element), new AutomationFocusChangedEventArgs(objectId, childId)); focusHandlerMapping.Add(eventHandler, sourceHandler); } } foreach (var source in SourceManager.GetAutomationSources()) { source.AddAutomationFocusChangedEventHandler(sourceHandler); } }
public static void RemoveStructureChangedEventHandler( AutomationElement element, StructureChangedEventHandler eventHandler) { ArgumentCheck.NotNull(element, "element"); ArgumentCheck.NotNull(eventHandler, "eventHandler"); if (element == AutomationElement.RootElement) { foreach (var source in SourceManager.GetAutomationSources()) { source.RemoveStructureChangedEventHandler( null, eventHandler); } } else { var source = element.SourceElement.AutomationSource; source.RemoveStructureChangedEventHandler( element.SourceElement, eventHandler); } }
public static void RemoveAutomationEventHandler( AutomationEvent eventId, AutomationElement element, AutomationEventHandler eventHandler) { CheckAutomationEventId(eventId); ArgumentCheck.NotNull(element, "element"); ArgumentCheck.NotNull(eventHandler, "eventHandler"); if (element == AutomationElement.RootElement) { foreach (var source in SourceManager.GetAutomationSources()) { source.RemoveAutomationEventHandler( eventId, element.SourceElement, eventHandler); } } else { var source = element.SourceElement.AutomationSource; source.RemoveAutomationEventHandler(eventId, element.SourceElement, eventHandler); } }
public static void AddAutomationPropertyChangedEventHandler(AutomationElement element, TreeScope scope, AutomationPropertyChangedEventHandler eventHandler, params AutomationProperty [] properties) { ArgumentCheck.NotNull(element, "element"); ArgumentCheck.NotNull(eventHandler, "eventHandler"); if (element == AutomationElement.RootElement) { foreach (var source in SourceManager.GetAutomationSources()) { source.AddAutomationPropertyChangedEventHandler( null, scope, eventHandler, properties); } } else { var source = element.SourceElement.AutomationSource; source.AddAutomationPropertyChangedEventHandler( element.SourceElement, scope, eventHandler, properties); } }
public static AutomationElement FromHandle(IntPtr hwnd) { ArgumentCheck.Assert(hwnd, (h => h != IntPtr.Zero), "hwnd"); if (hwnd == NativeMethods.RootWindowHandle) { return(RootElement); } AutomationElement element = null; foreach (var source in SourceManager.GetAutomationSources()) { var sourceElement = source.GetElementFromHandle(hwnd); if (sourceElement != null) { element = SourceManager.GetOrCreateAutomationElement(sourceElement); break; } } if (element == null) { throw new ElementNotAvailableException(); } return(element); }