Пример #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
            private AutomationElement GetPreviousDirectSibling(AutomationElement element)
            {
                AutomationElement parent      = TreeWalker.RawViewWalker.GetParent(element);
                AutomationElement prevSibling = null;

                if (parent == AutomationElement.RootElement)
                {
                    lock (TreeWalker.RawViewWalker.directChildrenLock) {
                        int prevIndex = TreeWalker.RawViewWalker.directChildren.IndexOf(element) - 1;
                        if (prevIndex > -1)
                        {
                            prevSibling = TreeWalker.RawViewWalker.directChildren [prevIndex];
                        }
                        else
                        {
                            prevSibling = null;
                        }
                    }
                }
                else
                {
                    prevSibling = SourceManager.GetOrCreateAutomationElement(element.SourceElement.PreviousSibling);
                }

                return(prevSibling);
            }
Пример #3
0
            private AutomationElement GetNextDirectSibling(AutomationElement element)
            {
                AutomationElement parent      = TreeWalker.RawViewWalker.GetParent(element);
                AutomationElement nextSibling = null;

                if (parent == AutomationElement.RootElement)
                {
                    lock (TreeWalker.RawViewWalker.directChildrenLock) {
                        int nextIndex = TreeWalker.RawViewWalker.directChildren.IndexOf(element) + 1;
                        if (nextIndex > -1 && nextIndex < TreeWalker.RawViewWalker.directChildren.Count)
                        {
                            nextSibling = TreeWalker.RawViewWalker.directChildren [nextIndex];
                        }
                        else
                        {
                            nextSibling = null;
                        }
                    }
                }
                else
                {
                    nextSibling = SourceManager.GetOrCreateAutomationElement(element.SourceElement.NextSibling);
                }

                return(nextSibling);
            }
Пример #4
0
            public AutomationElement GetParent(AutomationElement element)
            {
                if (element == null)
                {
                    throw new ArgumentNullException("element");
                }
                else if (element == AutomationElement.RootElement)
                {
                    return(null);
                }
                AutomationElement ancestor =
                    SourceManager.GetOrCreateAutomationElement(element.SourceElement.Parent);

                lock (TreeWalker.RawViewWalker.directChildrenLock)
                    if (ancestor == null && RawViewWalker.directChildren.Contains(element))
                    {
                        ancestor = SourceManager.GetOrCreateAutomationElement(AutomationElement.RootElement.SourceElement);
                    }

                if (ancestor != null && !condition.AppliesTo(ancestor))
                {
                    return(GetParent(ancestor));
                }
                return(ancestor);
            }
Пример #5
0
        public static AutomationElement FromPoint(Point pt)
        {
            IntPtr handle = NativeMethods.WindowAtPosition((int)pt.X, (int)pt.Y);

            if (handle == IntPtr.Zero)
            {
                return(RootElement);
            }
            AutomationElement startElement = null;

            try {
                startElement = FromHandle(handle);
            } catch (ElementNotAvailableException) {
                return(RootElement);
            }
            if (startElement == RootElement)
            {
                return(RootElement);
            }
            //Keep searching the descendant element which are not native window
            var sourceElement = startElement.SourceElement.
                                GetDescendantFromPoint(pt.X, pt.Y);

            return(SourceManager.GetOrCreateAutomationElement(sourceElement));
        }
Пример #6
0
 public static void RemoveAllEventHandlers()
 {
     lock (focusHandlerMapping)
         focusHandlerMapping.Clear();
     foreach (var source in SourceManager.GetAutomationSources())
     {
         source.RemoveAllEventHandlers();
     }
     AddAutomationFocusChangedEventHandler(AutomationElement.OnFocusChanged);
 }
Пример #7
0
        public AutomationElement GetUpdatedCache(CacheRequest request)
        {
            if (request == null)
            {
                throw new ArgumentNullException("request");
            }

            var updated = SourceManager.GetOrCreateAutomationElement(sourceElement);

            if (request == CacheRequest.DefaultRequest)
            {
                return(updated);
            }

            if ((request.TreeScope & TreeScope.Element) == TreeScope.Element)
            {
                foreach (var property in request.CachedProperties)
                {
                    updated.propertyCache [property.Id] =
                        new CachedValue(updated.GetCurrentPropertyValue(property),
                                        updated.sourceElement.SupportsProperty(property));
                }
                updated.mode         = request.AutomationElementMode;
                updated.CacheRequest = request.Clone();
            }

            if ((request.TreeScope & TreeScope.Children) == TreeScope.Children ||
                (request.TreeScope & TreeScope.Descendants) == TreeScope.Descendants)
            {
                // Modify scope to make sure children include
                // themselves, and only include their own
                // children if specified by original scope
                var childRequest = request.Clone();
                childRequest.TreeScope |= TreeScope.Element;
                if ((request.TreeScope & TreeScope.Descendants) != TreeScope.Descendants)
                {
                    childRequest.TreeScope ^= TreeScope.Children;
                }

                updated.cachedChildren = new List <AutomationElement> ();
                var child = TreeWalker.RawViewWalker.GetFirstChild(updated, childRequest);
                while (child != null)
                {
                    if (childRequest.TreeFilter.AppliesTo(child))
                    {
                        child.cachedParent = updated;
                        updated.cachedChildren.Add(child);
                    }
                    child = TreeWalker.RawViewWalker.GetNextSibling(child, childRequest);
                }
            }

            return(updated);
        }
Пример #8
0
        // TODO: This approach will completely break when the
        //       MoonUiaDbusBridge work is committed. This code
        //       will be replaced with proper source tree merging,
        //       which requires updates to gtk-sharp.
        private static void AddUniqueRootElements(List <AutomationElement> rootElements,
                                                  IAutomationSource source,
                                                  Dictionary <int, IElement> pidElementMapping)
        {
            const string at_spi = "at-spi";

            foreach (IElement sourceElement in source.GetRootElements())
            {
                int    pid;
                string sourceFid;
                try {
                    pid       = sourceElement.ProcessId;
                    sourceFid = sourceElement.FrameworkId;
                } catch { continue; }                 // TODO: ElementNotAvailableException

                // NOTE: This is not a complete mapping, since
                //       one process could generate multiple root
                //       elements. But it's sufficient to catch
                //       that at least one element exists for
                //       a given PID.
                if (pidElementMapping.TryGetValue(pid, out IElement found))
                {
                    string foundFid;
                    try {
                        foundFid = found.FrameworkId;
                    } catch { continue; }                     // TODO: ElementNotAvailableException

                    // Ignore at-spi elements when elements
                    // for this process from a preferred
                    // framework exist
                    if (sourceFid == at_spi &&
                        foundFid != at_spi)
                    {
                        continue;
                    }
                    // Remove at-spi elements when elements
                    // for this process from a preferred
                    // framework exist
                    else if (sourceFid != at_spi &&
                             foundFid == at_spi)
                    {
                        // TODO: When we fix ElementNotAvailableException,
                        //       we'll need to mark these
                        //       elements as unavailable.
                        rootElements.RemoveAll(e => e.Current.ProcessId == pid &&
                                               e.Current.FrameworkId == at_spi);
                    }
                }

                rootElements.Add(SourceManager.GetOrCreateAutomationElement(sourceElement));
                pidElementMapping [pid] = sourceElement;
            }
        }
Пример #9
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);
         }
     }
 }
Пример #10
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);
                    }
                }
            }
        }
Пример #11
0
            private AutomationElement GetLastDirectChild(AutomationElement element)
            {
                AutomationElement lastChild = null;

                if (element == AutomationElement.RootElement)
                {
                    lock (TreeWalker.RawViewWalker.directChildrenLock) {
                        lastChild = TreeWalker.RawViewWalker.directChildren.Count > 0 ?
                                    TreeWalker.RawViewWalker.directChildren [TreeWalker.RawViewWalker.directChildren.Count - 1] :
                                    null;
                    }
                }
                else
                {
                    lastChild = SourceManager.GetOrCreateAutomationElement(element.SourceElement.LastChild);
                }

                return(lastChild);
            }
Пример #12
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);
            }
        }
Пример #13
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);
            }
        }
Пример #14
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);
            }
        }
Пример #15
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);
            }
        }
Пример #16
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);
        }
Пример #17
0
 public AutomationElement GetItem(int row, int column)
 {
     return(SourceManager.GetOrCreateAutomationElement(Source.GetItem(row, column)));
 }
Пример #18
0
        public Object GetCurrentPropertyValue(AutomationProperty property,
                                              bool ignoreDefaultValue)
        {
            // TODO: Is this tested? Also, add message
            if (mode == AutomationElementMode.None)
            {
                throw new InvalidOperationException("Cannot request a property or pattern that is not cached");
            }

            object pattern;

            // TODO: Throw ElementNotAvailableException if element no longer exists

            // Default values already handled in IElement implementation
            if (ignoreDefaultValue && !sourceElement.SupportsProperty(property))
            {
                return(NotSupported);
            }

            if (property == AEIds.AcceleratorKeyProperty)
            {
                return(sourceElement.AcceleratorKey);
            }
            else if (property == AEIds.AccessKeyProperty)
            {
                return(sourceElement.AccessKey);
            }
            else if (property == AEIds.AutomationIdProperty)
            {
                return(sourceElement.AutomationId);
            }
            else if (property == AEIds.BoundingRectangleProperty)
            {
                return(sourceElement.BoundingRectangle);
            }
            else if (property == AEIds.ClassNameProperty)
            {
                return(sourceElement.ClassName);
            }
            else if (property == AEIds.ClickablePointProperty)
            {
                Point clickablePoint;
                if (TryGetClickablePoint(out clickablePoint))
                {
                    return(clickablePoint);
                }
                return(null);
            }
            else if (property == AEIds.ControlTypeProperty)
            {
                return(sourceElement.ControlType);
            }
            else if (property == AEIds.CultureProperty)
            {
                return(null);                   // TODO: Implement (new IElement member? not used in UIAutomationWinforms)
            }
            else if (property == AEIds.FrameworkIdProperty)
            {
                return(sourceElement.FrameworkId);
            }
            else if (property == AEIds.HasKeyboardFocusProperty)
            {
                return(sourceElement.HasKeyboardFocus);
            }
            else if (property == AEIds.HelpTextProperty)
            {
                return(sourceElement.HelpText);
            }
            else if (property == AEIds.IsContentElementProperty)
            {
                return(sourceElement.IsContentElement);
            }
            else if (property == AEIds.IsControlElementProperty)
            {
                return(sourceElement.IsControlElement);
            }
            else if (property == AEIds.IsDockPatternAvailableProperty)
            {
                return(TryGetCurrentPattern(DockPatternIdentifiers.Pattern, out pattern));
            }
            else if (property == AEIds.IsEnabledProperty)
            {
                return(sourceElement.IsEnabled);
            }
            else if (property == AEIds.IsExpandCollapsePatternAvailableProperty)
            {
                return(TryGetCurrentPattern(ExpandCollapsePatternIdentifiers.Pattern, out pattern));
            }
            else if (property == AEIds.IsGridItemPatternAvailableProperty)
            {
                return(TryGetCurrentPattern(GridItemPatternIdentifiers.Pattern, out pattern));
            }
            else if (property == AEIds.IsGridPatternAvailableProperty)
            {
                return(TryGetCurrentPattern(GridPatternIdentifiers.Pattern, out pattern));
            }
            else if (property == AEIds.IsInvokePatternAvailableProperty)
            {
                return(TryGetCurrentPattern(InvokePatternIdentifiers.Pattern, out pattern));
            }
            else if (property == AEIds.IsKeyboardFocusableProperty)
            {
                return(sourceElement.IsKeyboardFocusable);
            }
            else if (property == AEIds.IsMultipleViewPatternAvailableProperty)
            {
                return(TryGetCurrentPattern(MultipleViewPatternIdentifiers.Pattern, out pattern));
            }
            else if (property == AEIds.IsOffscreenProperty)
            {
                return(sourceElement.IsOffscreen);
            }
            else if (property == AEIds.IsPasswordProperty)
            {
                return(sourceElement.IsPassword);
            }
            else if (property == AEIds.IsRangeValuePatternAvailableProperty)
            {
                return(TryGetCurrentPattern(RangeValuePatternIdentifiers.Pattern, out pattern));
            }
            else if (property == AEIds.IsRequiredForFormProperty)
            {
                return(sourceElement.IsRequiredForForm);
            }
            else if (property == AEIds.IsScrollItemPatternAvailableProperty)
            {
                return(TryGetCurrentPattern(ScrollItemPatternIdentifiers.Pattern, out pattern));
            }
            else if (property == AEIds.IsScrollPatternAvailableProperty)
            {
                return(TryGetCurrentPattern(ScrollPatternIdentifiers.Pattern, out pattern));
            }
            else if (property == AEIds.IsSelectionItemPatternAvailableProperty)
            {
                return(TryGetCurrentPattern(SelectionItemPatternIdentifiers.Pattern, out pattern));
            }
            else if (property == AEIds.IsSelectionPatternAvailableProperty)
            {
                return(TryGetCurrentPattern(SelectionPatternIdentifiers.Pattern, out pattern));
            }
            else if (property == AEIds.IsTableItemPatternAvailableProperty)
            {
                return(TryGetCurrentPattern(TableItemPatternIdentifiers.Pattern, out pattern));
            }
            else if (property == AEIds.IsTablePatternAvailableProperty)
            {
                return(TryGetCurrentPattern(TablePatternIdentifiers.Pattern, out pattern));
            }
            else if (property == AEIds.IsTextPatternAvailableProperty)
            {
                return(TryGetCurrentPattern(TextPatternIdentifiers.Pattern, out pattern));
            }
            else if (property == AEIds.IsTogglePatternAvailableProperty)
            {
                return(TryGetCurrentPattern(TogglePatternIdentifiers.Pattern, out pattern));
            }
            else if (property == AEIds.IsTransformPatternAvailableProperty)
            {
                return(TryGetCurrentPattern(TransformPatternIdentifiers.Pattern, out pattern));
            }
            else if (property == AEIds.IsValuePatternAvailableProperty)
            {
                return(TryGetCurrentPattern(ValuePatternIdentifiers.Pattern, out pattern));
            }
            else if (property == AEIds.IsWindowPatternAvailableProperty)
            {
                return(TryGetCurrentPattern(WindowPatternIdentifiers.Pattern, out pattern));
            }
            else if (property == AEIds.ItemStatusProperty)
            {
                return(sourceElement.ItemStatus);
            }
            else if (property == AEIds.ItemTypeProperty)
            {
                return(sourceElement.ItemType);
            }
            else if (property == AEIds.LabeledByProperty)
            {
                // TODO: Caching behavior here should be tested more
                return(SourceManager.GetOrCreateAutomationElement(sourceElement.LabeledBy));
            }
            else if (property == AEIds.LocalizedControlTypeProperty)
            {
                return(sourceElement.LocalizedControlType);
            }
            else if (property == AEIds.NameProperty)
            {
                return(sourceElement.Name);
            }
            else if (property == AEIds.NativeWindowHandleProperty)
            {
                return(sourceElement.NativeWindowHandle);
            }
            else if (property == AEIds.OrientationProperty)
            {
                return(sourceElement.Orientation);
            }
            else if (property == AEIds.ProcessIdProperty)
            {
                return(sourceElement.ProcessId);
            }
            else if (property == AEIds.RuntimeIdProperty)
            {
                return(GetRuntimeId());
            }
            else if (property == DockPatternIdentifiers.DockPositionProperty)
            {
                return(TryGetCurrentPattern(DockPatternIdentifiers.Pattern, out pattern)? ((DockPattern)pattern).Source.DockPosition: DockPosition.None);
            }
            else if (property == ExpandCollapsePatternIdentifiers.ExpandCollapseStateProperty)
            {
                return(TryGetCurrentPattern(ExpandCollapsePatternIdentifiers.Pattern, out pattern)? ((ExpandCollapsePattern)pattern).Source.ExpandCollapseState: ExpandCollapseState.LeafNode);
            }
            else if (property == GridItemPatternIdentifiers.ColumnProperty)
            {
                return(TryGetCurrentPattern(GridItemPatternIdentifiers.Pattern, out pattern)? ((GridItemPattern)pattern).Source.Column: 0);
            }
            else if (property == GridItemPatternIdentifiers.ColumnSpanProperty)
            {
                return(TryGetCurrentPattern(GridItemPatternIdentifiers.Pattern, out pattern)? ((GridItemPattern)pattern).Source.ColumnSpan: 1);
            }
            else if (property == GridItemPatternIdentifiers.ContainingGridProperty)
            {
                return(TryGetCurrentPattern(GridItemPatternIdentifiers.Pattern, out pattern)? SourceManager.GetOrCreateAutomationElement(((GridItemPattern)pattern).Source.ContainingGrid): null);
            }
            else if (property == GridItemPatternIdentifiers.RowProperty)
            {
                return(TryGetCurrentPattern(GridItemPatternIdentifiers.Pattern, out pattern)? ((GridItemPattern)pattern).Source.Row: 0);
            }
            else if (property == GridItemPatternIdentifiers.RowSpanProperty)
            {
                return(TryGetCurrentPattern(GridItemPatternIdentifiers.Pattern, out pattern)? ((GridItemPattern)pattern).Source.RowSpan: 1);
            }
            else if (property == GridPatternIdentifiers.ColumnCountProperty)
            {
                return(TryGetCurrentPattern(GridPatternIdentifiers.Pattern, out pattern)? ((GridPattern)pattern).Source.ColumnCount: 0);
            }
            else if (property == GridPatternIdentifiers.RowCountProperty)
            {
                return(TryGetCurrentPattern(GridPatternIdentifiers.Pattern, out pattern)? ((GridPattern)pattern).Source.RowCount: 0);
            }
            else if (property == MultipleViewPatternIdentifiers.CurrentViewProperty)
            {
                return(TryGetCurrentPattern(MultipleViewPatternIdentifiers.Pattern, out pattern)? ((MultipleViewPattern)pattern).Source.CurrentView: 0);
            }
            else if (property == MultipleViewPatternIdentifiers.SupportedViewsProperty)
            {
                return(TryGetCurrentPattern(MultipleViewPatternIdentifiers.Pattern, out pattern)? ((MultipleViewPattern)pattern).Source.GetSupportedViews(): new int [0]);
            }
            else if (property == RangeValuePatternIdentifiers.IsReadOnlyProperty)
            {
                return(TryGetCurrentPattern(RangeValuePatternIdentifiers.Pattern, out pattern)? ((RangeValuePattern)pattern).Source.IsReadOnly: true);
            }
            else if (property == RangeValuePatternIdentifiers.LargeChangeProperty)
            {
                return(TryGetCurrentPattern(RangeValuePatternIdentifiers.Pattern, out pattern)? ((RangeValuePattern)pattern).Source.LargeChange: 0);
            }
            else if (property == RangeValuePatternIdentifiers.MaximumProperty)
            {
                return(TryGetCurrentPattern(RangeValuePatternIdentifiers.Pattern, out pattern)? ((RangeValuePattern)pattern).Source.Maximum: 0);
            }
            else if (property == RangeValuePatternIdentifiers.MinimumProperty)
            {
                return(TryGetCurrentPattern(RangeValuePatternIdentifiers.Pattern, out pattern)? ((RangeValuePattern)pattern).Source.Minimum: 0);
            }
            else if (property == RangeValuePatternIdentifiers.SmallChangeProperty)
            {
                return(TryGetCurrentPattern(RangeValuePatternIdentifiers.Pattern, out pattern)? ((RangeValuePattern)pattern).Source.SmallChange: 0);
            }
            else if (property == RangeValuePatternIdentifiers.ValueProperty)
            {
                return(TryGetCurrentPattern(RangeValuePatternIdentifiers.Pattern, out pattern)? ((RangeValuePattern)pattern).Source.Value: 0);
            }
            else if (property == ScrollPatternIdentifiers.HorizontallyScrollableProperty)
            {
                return(TryGetCurrentPattern(ScrollPatternIdentifiers.Pattern, out pattern)? ((ScrollPattern)pattern).Source.HorizontallyScrollable: false);
            }
            else if (property == ScrollPatternIdentifiers.HorizontalScrollPercentProperty)
            {
                return(TryGetCurrentPattern(ScrollPatternIdentifiers.Pattern, out pattern)? ((ScrollPattern)pattern).Source.HorizontalScrollPercent: 0);
            }
            else if (property == ScrollPatternIdentifiers.HorizontalViewSizeProperty)
            {
                return(TryGetCurrentPattern(ScrollPatternIdentifiers.Pattern, out pattern)? ((ScrollPattern)pattern).Source.HorizontalViewSize: 100);
            }
            else if (property == ScrollPatternIdentifiers.VerticallyScrollableProperty)
            {
                return(TryGetCurrentPattern(ScrollPatternIdentifiers.Pattern, out pattern)? ((ScrollPattern)pattern).Source.VerticallyScrollable: false);
            }
            else if (property == ScrollPatternIdentifiers.VerticalScrollPercentProperty)
            {
                return(TryGetCurrentPattern(ScrollPatternIdentifiers.Pattern, out pattern)? ((ScrollPattern)pattern).Source.VerticalScrollPercent: 0);
            }
            else if (property == ScrollPatternIdentifiers.VerticalViewSizeProperty)
            {
                return(TryGetCurrentPattern(ScrollPatternIdentifiers.Pattern, out pattern)? ((ScrollPattern)pattern).Source.VerticalViewSize: 100);
            }
            else if (property == SelectionItemPatternIdentifiers.IsSelectedProperty)
            {
                return(TryGetCurrentPattern(SelectionItemPatternIdentifiers.Pattern, out pattern)? ((SelectionItemPattern)pattern).Source.IsSelected: false);
            }
            else if (property == SelectionItemPatternIdentifiers.SelectionContainerProperty)
            {
                return(TryGetCurrentPattern(SelectionItemPatternIdentifiers.Pattern, out pattern)? SourceManager.GetOrCreateAutomationElement(((SelectionItemPattern)pattern).Source.SelectionContainer): null);
            }
            else if (property == SelectionPatternIdentifiers.CanSelectMultipleProperty)
            {
                return(TryGetCurrentPattern(SelectionPatternIdentifiers.Pattern, out pattern)? ((SelectionPattern)pattern).Source.CanSelectMultiple: false);
            }
            else if (property == SelectionPatternIdentifiers.IsSelectionRequiredProperty)
            {
                return(TryGetCurrentPattern(SelectionPatternIdentifiers.Pattern, out pattern)? ((SelectionPattern)pattern).Source.IsSelectionRequired: false);
            }
            else if (property == SelectionPatternIdentifiers.SelectionProperty)
            {
                return(TryGetCurrentPattern(SelectionPatternIdentifiers.Pattern, out pattern)? SourceManager.GetOrCreateAutomationElements(((SelectionPattern)pattern).Source.GetSelection()): new AutomationElement [0]);
            }
            else if (property == TableItemPatternIdentifiers.ColumnHeaderItemsProperty)
            {
                return(TryGetCurrentPattern(TableItemPatternIdentifiers.Pattern, out pattern)? SourceManager.GetOrCreateAutomationElements(((TableItemPattern)pattern).Source.GetColumnHeaderItems()): new AutomationElement [0]);
            }
            else if (property == TableItemPatternIdentifiers.RowHeaderItemsProperty)
            {
                return(TryGetCurrentPattern(TableItemPatternIdentifiers.Pattern, out pattern)? SourceManager.GetOrCreateAutomationElements(((TableItemPattern)pattern).Source.GetRowHeaderItems()): new AutomationElement [0]);
            }
            else if (property == TablePatternIdentifiers.ColumnHeadersProperty)
            {
                return(TryGetCurrentPattern(TablePatternIdentifiers.Pattern, out pattern)? SourceManager.GetOrCreateAutomationElements(((TablePattern)pattern).Source.GetColumnHeaders()): new AutomationElement [0]);
            }
            else if (property == TablePatternIdentifiers.RowHeadersProperty)
            {
                return(TryGetCurrentPattern(TablePatternIdentifiers.Pattern, out pattern)? SourceManager.GetOrCreateAutomationElements(((TablePattern)pattern).Source.GetRowHeaders()): new AutomationElement [0]);
            }
            else if (property == TablePatternIdentifiers.RowOrColumnMajorProperty)
            {
                return(TryGetCurrentPattern(TablePatternIdentifiers.Pattern, out pattern)? ((TablePattern)pattern).Source.RowOrColumnMajor: RowOrColumnMajor.Indeterminate);
            }
            else if (property == TogglePatternIdentifiers.ToggleStateProperty)
            {
                return(TryGetCurrentPattern(TogglePatternIdentifiers.Pattern, out pattern)? ((TogglePattern)pattern).Source.ToggleState: ToggleState.Indeterminate);
            }
            else if (property == TransformPatternIdentifiers.CanMoveProperty)
            {
                return(TryGetCurrentPattern(TransformPatternIdentifiers.Pattern, out pattern)? (bool)((TransformPattern)pattern).Source.CanMove: false);
            }
            else if (property == TransformPatternIdentifiers.CanResizeProperty)
            {
                return(TryGetCurrentPattern(TransformPatternIdentifiers.Pattern, out pattern)? ((TransformPattern)pattern).Source.CanResize: false);
            }
            else if (property == TransformPatternIdentifiers.CanRotateProperty)
            {
                return(TryGetCurrentPattern(TransformPatternIdentifiers.Pattern, out pattern)? ((TransformPattern)pattern).Source.CanRotate: false);
            }
            else if (property == ValuePatternIdentifiers.IsReadOnlyProperty)
            {
                return(TryGetCurrentPattern(ValuePatternIdentifiers.Pattern, out pattern)? ((ValuePattern)pattern).Source.IsReadOnly: true);
            }
            else if (property == ValuePatternIdentifiers.ValueProperty)
            {
                return(TryGetCurrentPattern(ValuePatternIdentifiers.Pattern, out pattern)? ((ValuePattern)pattern).Source.Value: String.Empty);
            }
            else if (property == WindowPatternIdentifiers.CanMaximizeProperty)
            {
                return(TryGetCurrentPattern(WindowPatternIdentifiers.Pattern, out pattern)? (bool)((WindowPattern)pattern).Source.CanMaximize: false);
            }
            else if (property == WindowPatternIdentifiers.CanMinimizeProperty)
            {
                return(TryGetCurrentPattern(WindowPatternIdentifiers.Pattern, out pattern)? (bool)((WindowPattern)pattern).Source.CanMinimize: false);
            }
            else if (property == WindowPatternIdentifiers.IsModalProperty)
            {
                return(TryGetCurrentPattern(WindowPatternIdentifiers.Pattern, out pattern)? ((WindowPattern)pattern).Source.IsModal: false);
            }
            else if (property == WindowPatternIdentifiers.IsTopmostProperty)
            {
                return(TryGetCurrentPattern(WindowPatternIdentifiers.Pattern, out pattern)? ((WindowPattern)pattern).Source.IsTopmost: false);
            }
            else if (property == WindowPatternIdentifiers.WindowInteractionStateProperty)
            {
                return(TryGetCurrentPattern(WindowPatternIdentifiers.Pattern, out pattern)? ((WindowPattern)pattern).Source.WindowInteractionState: WindowInteractionState.Running);
            }
            else if (property == WindowPatternIdentifiers.WindowVisualStateProperty)
            {
                return(TryGetCurrentPattern(WindowPatternIdentifiers.Pattern, out pattern)? ((WindowPattern)pattern).Source.WindowVisualState: WindowVisualState.Normal);
            }
            Log.Debug("GetCurrentPropertyValue not implemented for: " + property.ProgrammaticName);
            return(NotSupported);
        }