GetAutomationSources() static private method

static private GetAutomationSources ( ) : IAutomationSource[]
return IAutomationSource[]
示例#1
0
        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);
            }
        }
示例#2
0
 public static void RemoveAllEventHandlers()
 {
     lock (focusHandlerMapping)
         focusHandlerMapping.Clear();
     foreach (var source in SourceManager.GetAutomationSources())
     {
         source.RemoveAllEventHandlers();
     }
     AddAutomationFocusChangedEventHandler(AutomationElement.OnFocusChanged);
 }
示例#3
0
 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);
         }
     }
 }
示例#4
0
        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);
                    }
                }
            }
        }
示例#5
0
        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);
            }
        }
示例#6
0
        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);
            }
        }
示例#7
0
        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);
            }
        }
示例#8
0
        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);
            }
        }
示例#9
0
        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);
        }