public static void RaiseAutomationEvent(AutomationEvent eventId, IRawElementProviderSimple provider, AutomationEventArgs e)
 {
     Utility.ValidateArgumentNonNull(eventId, "eventId");
     Utility.ValidateArgumentNonNull(provider, "provider");
     Utility.ValidateArgumentNonNull(e, "e");
     if (e.EventId == AutomationElementIdentifiers.AsyncContentLoadedEvent)
     {
         AsyncContentLoadedEventArgs args = e as AsyncContentLoadedEventArgs;
         if (args == null)
         {
             throw new ArgumentException("e");
         }
         UiaCoreProviderApi.UiaRaiseAsyncContentLoadedEvent(provider, args.AsyncContentLoadedState, args.PercentComplete);
     }
     else
     {
         if ((e.EventId == WindowPatternIdentifiers.WindowClosedEvent) && !(e is WindowClosedEventArgs))
         {
             throw new ArgumentException("e");
         }
         UiaCoreProviderApi.UiaRaiseAutomationEvent(provider, eventId.Id);
     }
 }
Esempio n. 2
0
 internal static void UiaRaiseAutomationEvent(IRawElementProviderSimple provider, int eventId)
 {
     CheckError(RawUiaRaiseAutomationEvent(provider, eventId));
 }
Esempio n. 3
0
 private static extern IntPtr RawUiaReturnRawElementProvider(IntPtr hwnd, IntPtr wParam, IntPtr lParam, IRawElementProviderSimple el);
Esempio n. 4
0
 ITextRangeProvider ITextProvider.RangeFromChild(IRawElementProviderSimple childElement)
 {
     //return new ScreenDisplayRangeProvider(terminal.ContentText, this);
     return new ScreenDisplayRangeProvider(string.Empty, this);
 }
 public static extern int UiaRaiseAutomationEvent(IRawElementProviderSimple el, int eventId);
Esempio n. 6
0
        /// <summary>
        /// Retrieves the range of a child object.
        /// </summary>
        /// <param name="childElementProvider">The child element.  A provider should check that the
        /// passed element is a child of the text container, and should throw an
        /// InvalidOperationException if it is not.</param>
        /// <returns>A range that spans the child element.</returns>
        ITextRangeProvider ITextProvider.RangeFromChild(IRawElementProviderSimple childElementProvider)
        {
            if (childElementProvider == null)
            {
                throw new ArgumentNullException("childElementProvider");
            }

            // Retrieve DependencyObject from AutomationElement
            DependencyObject childElement;

            if (_textPeer is TextAutomationPeer)
            {
                childElement = ((TextAutomationPeer)_textPeer).ElementFromProvider(childElementProvider);
            }
            else
            {
                childElement = ((ContentTextAutomationPeer)_textPeer).ElementFromProvider(childElementProvider);
            }

            TextRangeAdaptor range = null;

            if (childElement != null)
            {
                ITextPointer rangeStart = null;
                ITextPointer rangeEnd   = null;

                // Retrieve start and end positions for given element.
                // If element is TextElement, retrieve its Element Start and End positions.
                // If element is UIElement hosted by UIContainer (Inlien of Block),
                // retrieve content Start and End positions of the container.
                // Otherwise scan ITextContainer to find a range for given element.
                if (childElement is TextElement)
                {
                    rangeStart = ((TextElement)childElement).ElementStart;
                    rangeEnd   = ((TextElement)childElement).ElementEnd;
                }
                else
                {
                    DependencyObject parent = LogicalTreeHelper.GetParent(childElement);
                    if (parent is InlineUIContainer || parent is BlockUIContainer)
                    {
                        rangeStart = ((TextElement)parent).ContentStart;
                        rangeEnd   = ((TextElement)parent).ContentEnd;
                    }
                    else
                    {
                        ITextPointer position = _textContainer.Start.CreatePointer();
                        while (position.CompareTo(_textContainer.End) < 0)
                        {
                            TextPointerContext context = position.GetPointerContext(LogicalDirection.Forward);
                            if (context == TextPointerContext.ElementStart)
                            {
                                if (childElement == position.GetAdjacentElement(LogicalDirection.Forward))
                                {
                                    rangeStart = position.CreatePointer(LogicalDirection.Forward);
                                    position.MoveToElementEdge(ElementEdge.AfterEnd);
                                    rangeEnd = position.CreatePointer(LogicalDirection.Backward);
                                    break;
                                }
                            }
                            else if (context == TextPointerContext.EmbeddedElement)
                            {
                                if (childElement == position.GetAdjacentElement(LogicalDirection.Forward))
                                {
                                    rangeStart = position.CreatePointer(LogicalDirection.Forward);
                                    position.MoveToNextContextPosition(LogicalDirection.Forward);
                                    rangeEnd = position.CreatePointer(LogicalDirection.Backward);
                                    break;
                                }
                            }
                            position.MoveToNextContextPosition(LogicalDirection.Forward);
                        }
                    }
                }
                // Create range
                if (rangeStart != null && rangeEnd != null)
                {
                    range = new TextRangeAdaptor(this, rangeStart, rangeEnd, _textPeer);
                }
            }
            if (range == null)
            {
                throw new InvalidOperationException(SR.Get(SRID.TextProvider_InvalidChildElement));
            }
            return(range);
        }
Esempio n. 7
0
 public ITextRangeProvider RangeFromChild(IRawElementProviderSimple childElement)
 {
     //Debug.WriteLine("TextAreaAutomationPeer.RangeFromChild()");
     throw new NotImplementedException();
 }
Esempio n. 8
0
 public ITextRangeProvider RangeFromChild(IRawElementProviderSimple childElement)
 {
     throw new NotImplementedException();
 }
Esempio n. 9
0
 public SimpleProviderWrapper(Component component, IRawElementProviderSimple simpleProvider)
     : base(component)
 {
     wrappedProvider = simpleProvider;
 }
Esempio n. 10
0
        public ITextRangeProvider RangeFromChild(IRawElementProviderSimple childElement)
        {
            if (childElement == null)
            {
                throw new ArgumentNullException();
            }

            return new MockTextRangeProvider(this, "fromChild");
        }
Esempio n. 11
0
        public ITextRangeProvider RangeFromAnnotation(IRawElementProviderSimple annotation)
        {
            if (annotation == null)
            {
                throw new ArgumentNullException();
            }

            return new MockTextRangeProvider(this, "fromAnnotation");
        }
Esempio n. 12
0
        //------------------------------------------------------
        //
        //  Private Methods
        //
        //------------------------------------------------------

        #region Private Methods

        // Get a proxy for a given hwnd
        // (Also used as an entry by RESW to get proxy for a parent to check if it supports overrides)
        internal static IRawElementProviderSimple ProxyProviderFromHwnd(NativeMethods.HWND hwnd, int idChild, int idObject)
        {
            // The precedence that proxies are chosen is as follows:
            //
            // All entries in the table passed into RegisterWindowHandlers that do not specify AllowSubstringMatch
            // are tried first.  If the class name of the current hwnd matches the ClassName in the entery then
            // the image name is checked for a match if it was specified.
            //
            // If no match is found then the real class name is checked for a match unless NoBaseMatching flag is on.
            // this allows class name ThunderRT6CommandButton to match Button becuse it subclasses button.
            // If more than one entry has the same ClassName the first one in the table is tried first.
            //
            // If no exact match if found, all the entries that specified AllowSubstringMatch are tried in the order
            // they occur in the table.  If a match is found and the ImageName was specified that is checked to see
            // if it matches the current image.
            //
            // If no substring matches are found entries that have specifed only the ImageName are tried.
            //
            // If there still is no match entries that have no ClassName and no ImageName are tried.
            //
            // If this fails the default hwnd proxy is used.
            //
            // If RegisterWindowHandlers is called again those entries occur before the earlier ones in the table.
            if (hwnd == NativeMethods.HWND.NULL)
            {
                return(null);
            }

            LoadDefaultProxies();

            string className            = GetClassName(hwnd).ToLower(CultureInfo.InvariantCulture);
            object proxyDescOrArrayList = null;

            lock (_lockObj)
            {
                proxyDescOrArrayList = _classHandlers[className];
            }
            string imageName = null;
            IRawElementProviderSimple proxy = FindProxyInEntryOrArrayList(ProxyScoping.ExactMatchApparentClassName, proxyDescOrArrayList, ref imageName, hwnd, idChild, idObject, null);

            // If we don't have a proxy for the class try to match the real class
            string baseClassName = null;

            if (proxy == null)
            {
                baseClassName = GetBaseClassName(hwnd);
                if (baseClassName == className)
                {
                    baseClassName = null;
                }

                if (!String.IsNullOrEmpty(baseClassName))
                {
                    lock (_lockObj)
                    {
                        proxyDescOrArrayList = _classHandlers[baseClassName];
                    }
                    proxy = FindProxyInEntryOrArrayList(ProxyScoping.ExactMatchRealClassName, proxyDescOrArrayList, ref imageName, hwnd, idChild, idObject, null);
                }
            }

            // If we don't have a proxy yet look for a partial match if there are any
            if (proxy == null && _partialClassHandlers.Count > 0)
            {
                proxy = FindProxyInEntryOrArrayList(ProxyScoping.PartialMatchApparentClassName, _partialClassHandlers, ref imageName, hwnd, idChild, idObject, className);

                if (proxy == null && !String.IsNullOrEmpty(baseClassName))
                {
                    proxy = FindProxyInEntryOrArrayList(ProxyScoping.PartialMatchRealClassName, _partialClassHandlers, ref imageName, hwnd, idChild, idObject, baseClassName);
                }
            }

            // There is no match yet look for entry that just specified an image name
            // this is like a fallback proxy for a particular image
            if (proxy == null)
            {
                proxy = FindProxyFromImageFallback(ref imageName, hwnd, idChild, idObject);
            }

            // use the fallback proxy if there is one
            if (proxy == null)
            {
                proxy = FindProxyInEntryOrArrayList(ProxyScoping.FallbackHandlers, _fallbackHandlers, ref imageName, hwnd, idChild, idObject, null);
            }

            // may be null if no proxy found
            return(proxy);
        }
 ITextRangeProvider ITextProvider.RangeFromChild(IRawElementProviderSimple childElement)
 {
     return new CustomStackPanelRangeProvider(customStackPanel.ContentText, this);
 }
Esempio n. 14
0
 ITextRangeProvider ITextProvider.RangeFromChild(IRawElementProviderSimple childElement)
 {
     return(new CustomControl2RangeProvider(customInputBox.ContentText, this));
 }
Esempio n. 15
0
 internal static void UiaRaiseStructureChangedEvent(IRawElementProviderSimple provider, StructureChangeType structureChangeType, int[] runtimeId)
 {
     CheckError(RawUiaRaiseStructureChangedEvent(provider, structureChangeType, runtimeId, (runtimeId == null) ? 0 : runtimeId.Length));
 }
 public static extern HRESULT UiaHostProviderFromHwnd(IntPtr hwnd, out IRawElementProviderSimple ppProvider);
Esempio n. 17
0
 HRESULT IAccessibleEx.ConvertReturnedElement(IRawElementProviderSimple pIn, out IAccessibleEx?ppRetValOut)
 => publicIAccessibleEx.ConvertReturnedElement(pIn, out ppRetValOut);
 private static extern int RawUiaRaiseAsyncContentLoadedEvent(IRawElementProviderSimple provider, System.Windows.Automation.AsyncContentLoadedState asyncContentLoadedState, double PercentComplete);
Esempio n. 19
0
        IRawElementProviderSimple IItemContainerProvider.FindItemByProperty(IRawElementProviderSimple startAfter, int propertyId, object value)
        {
            ResetChildrenCache();
            // Checks if propertyId is valid else throws ArgumentException to notify it as invalid argument is being passed
            if (propertyId != 0)
            {
                if (!SelectorAutomationPeer.IsPropertySupportedByControlForFindItemInternal(propertyId))
                {
                    throw new ArgumentException(SR.Get(SRID.PropertyNotSupported));
                }
            }


            IList <DataGridColumn> columns = OwningDataGrid.Columns;

            if (columns != null && columns.Count > 0)
            {
                DataGridCellItemAutomationPeer startAfterItem = null;
                if (startAfter != null)
                {
                    // get the peer corresponding to this provider
                    startAfterItem = PeerFromProvider(startAfter) as DataGridCellItemAutomationPeer;
                }

                // startIndex refers to the index of the item just after startAfterItem
                int startIndex = 0;
                if (startAfterItem != null)
                {
                    if (startAfterItem.Column == null)
                    {
                        throw new InvalidOperationException(SR.Get(SRID.InavalidStartItem));
                    }

                    // To find the index of the item in items collection which occurs
                    // immidiately after startAfterItem.Item
                    startIndex = columns.IndexOf(startAfterItem.Column) + 1;
                    if (startIndex == 0 || startIndex == columns.Count)
                    {
                        return(null);
                    }
                }

                if (propertyId == 0 && startIndex < columns.Count)
                {
                    return(ProviderFromPeer(GetOrCreateCellItemPeer(columns[startIndex])));
                }

                DataGridCellItemAutomationPeer currentItemPeer;
                object currentValue = null;
                for (int i = startIndex; i < columns.Count; i++)
                {
                    currentItemPeer = GetOrCreateCellItemPeer(columns[i]);
                    if (currentItemPeer == null)
                    {
                        continue;
                    }
                    try
                    {
                        currentValue = SelectorAutomationPeer.GetSupportedPropertyValueInternal(currentItemPeer, propertyId);
                    }
                    catch (Exception ex)
                    {
                        if (ex is ElementNotAvailableException)
                        {
                            continue;
                        }
                    }

                    if (value == null || currentValue == null)
                    {
                        // Accept null as value corresponding to the property if it finds an item with null as the value of corresponding property else ignore.
                        if (currentValue == null && value == null)
                        {
                            return(ProviderFromPeer(currentItemPeer));
                        }
                        else
                        {
                            continue;
                        }
                    }

                    // Match is found within the specified criterion of search
                    if (value.Equals(currentValue))
                    {
                        return(ProviderFromPeer(currentItemPeer));
                    }
                }
            }
            return(null);
        }
 private static extern int RawUiaRaiseAutomationEvent(IRawElementProviderSimple provider, int id);
Esempio n. 21
0
 internal static IntPtr UiaReturnRawElementProvider(IntPtr hwnd, IntPtr wParam, IntPtr lParam, IRawElementProviderSimple el)
 {
     return(RawUiaReturnRawElementProvider(hwnd, wParam, lParam, el));
 }
 private static extern int RawUiaRaiseAutomationPropertyChangedEvent(IRawElementProviderSimple provider, int id, object oldValue, object newValue);
 public static void RaiseStructureChangedEvent(IRawElementProviderSimple provider, StructureChangedEventArgs e)
 {
     Utility.ValidateArgumentNonNull(provider, "provider");
     Utility.ValidateArgumentNonNull(e, "e");
     UiaCoreProviderApi.UiaRaiseStructureChangedEvent(provider, (UIAutomationClient.StructureChangeType)e.StructureChangeType, e.GetRuntimeId());
 }
 private static extern int RawUiaRaiseStructureChangedEvent(IRawElementProviderSimple provider, StructureChangeType structureChangeType, int[] runtimeId, int runtimeIdLen);
 public static extern IntPtr UiaReturnRawElementProvider(IntPtr hwnd, IntPtr wParam, IntPtr lParam, IRawElementProviderSimple el);
 private static extern IntPtr RawUiaReturnRawElementProvider(IntPtr hwnd, IntPtr wParam, IntPtr lParam, IRawElementProviderSimple el);
Esempio n. 27
0
 protected void GetProviderAndControl(out IRawElementProviderSimple provider,
                                      out T textBoxBase)
 {
     textBoxBase = GetTextBoxBase();
     provider    = ProviderFactory.GetProvider(textBoxBase);
 }
 internal static void UiaRaiseAsyncContentLoadedEvent(IRawElementProviderSimple provider, System.Windows.Automation.AsyncContentLoadedState asyncContentLoadedState, double PercentComplete)
 {
     CheckError(RawUiaRaiseAsyncContentLoadedEvent(provider, asyncContentLoadedState, PercentComplete));
 }
Esempio n. 29
0
 internal static void UiaRaiseAsyncContentLoadedEvent(IRawElementProviderSimple provider, System.Windows.Automation.AsyncContentLoadedState asyncContentLoadedState, double PercentComplete)
 {
     CheckError(RawUiaRaiseAsyncContentLoadedEvent(provider, asyncContentLoadedState, PercentComplete));
 }
 internal static void UiaRaiseAutomationEvent(IRawElementProviderSimple provider, int eventId)
 {
     CheckError(RawUiaRaiseAutomationEvent(provider, eventId));
 }
Esempio n. 31
0
 internal static void UiaRaiseAutomationPropertyChangedEvent(IRawElementProviderSimple provider, int propertyId, object oldValue, object newValue)
 {
     CheckError(RawUiaRaiseAutomationPropertyChangedEvent(provider, propertyId, oldValue, newValue));
 }
 internal static void UiaRaiseAutomationPropertyChangedEvent(IRawElementProviderSimple provider, int propertyId, object oldValue, object newValue)
 {
     CheckError(RawUiaRaiseAutomationPropertyChangedEvent(provider, propertyId, oldValue, newValue));
 }
Esempio n. 33
0
 ITextRangeProvider ITextProvider.RangeFromChild(IRawElementProviderSimple childElement)
 {
     // we don't have any children so this call must be in error.
     throw new InvalidOperationException(SR.Get(SRID.EditControlsHaveNoChildren, GetType().FullName));
 }
 internal static void UiaRaiseStructureChangedEvent(IRawElementProviderSimple provider, StructureChangeType structureChangeType, int[] runtimeId)
 {
     CheckError(RawUiaRaiseStructureChangedEvent(provider, structureChangeType, runtimeId, (runtimeId == null) ? 0 : runtimeId.Length));
 }
Esempio n. 35
0
 //FIXME: consider to add a new param here: Adapter parent; in order to have the parent always accessible, and
 //       prevent workarounds such as using provider navigation (like in the UiaAtkBridge.Window or
 //       UiaAtkBridge.ComboBox cases)
 public Adapter(IRawElementProviderSimple provider)
 {
     Provider = provider;
     // Avoid setting the name.  Not sure why this is needed.
 }
 internal static IntPtr UiaReturnRawElementProvider(IntPtr hwnd, IntPtr wParam, IntPtr lParam, IRawElementProviderSimple el)
 {
     return RawUiaReturnRawElementProvider(hwnd, wParam, lParam, el);
 }
Esempio n. 37
0
        private object RangeFromChild(object arg)
        {
            IRawElementProviderSimple childElement = (IRawElementProviderSimple)arg;

            return(TextRangeProviderWrapper.WrapArgument(_iface.RangeFromChild(childElement), _peer));
        }
Esempio n. 38
0
 public Separator(IRawElementProviderSimple provider) : base(provider)
 {
     Role = Atk.Role.Separator;
 }
Esempio n. 39
0
        public void BasicPropertiesTest()
        {
            // default is PushButton style
            IRawElementProviderSimple provider =
                ProviderFactory.GetProvider(toolBarButton);

            TestProperty(provider,
                         AutomationElementIdentifiers.ControlTypeProperty,
                         ControlType.Button.Id);
            TestProperty(provider,
                         AutomationElementIdentifiers.LocalizedControlTypeProperty,
                         "button");

            // DropDownButton style
            ToolBarButton dropDownButton = new ToolBarButton();

            dropDownButton.Style        = ToolBarButtonStyle.DropDownButton;
            dropDownButton.DropDownMenu = new ContextMenu();
            dropDownButton.DropDownMenu.MenuItems.Add("item 1");
            toolBar.Buttons.Add(dropDownButton);
            IRawElementProviderSimple dropDownProvider =
                ProviderFactory.GetProvider(dropDownButton);

            TestProperty(dropDownProvider,
                         AutomationElementIdentifiers.ControlTypeProperty,
                         ControlType.SplitButton.Id);
            TestProperty(dropDownProvider,
                         AutomationElementIdentifiers.LocalizedControlTypeProperty,
                         "split button");
            // Use this instead when expanding ContextMenu doesn't
            // cause test to hang:
            //TestSplitButtonPatterns (dropDownProvider);
            Assert.IsTrue((bool)dropDownProvider.GetPropertyValue(AutomationElementIdentifiers.IsExpandCollapsePatternAvailableProperty.Id),
                          "SplitButton ControlType must support IExpandCollapseProvider");
            Assert.IsTrue((bool)dropDownProvider.GetPropertyValue(AutomationElementIdentifiers.IsInvokePatternAvailableProperty.Id),
                          "SplitButton ControlType must support IInvokeProvider");

            // ToggleButton style
            ToolBarButton toggleButton = new ToolBarButton();

            toggleButton.Style = ToolBarButtonStyle.ToggleButton;
            toolBar.Buttons.Add(toggleButton);
            IRawElementProviderSimple toggleProvider =
                ProviderFactory.GetProvider(toggleButton);

            TestProperty(toggleProvider,
                         AutomationElementIdentifiers.ControlTypeProperty,
                         ControlType.Button.Id);
            TestProperty(toggleProvider,
                         AutomationElementIdentifiers.LocalizedControlTypeProperty,
                         "button");

            // Separator style
            ToolBarButton separatorButton = new ToolBarButton();

            separatorButton.Style = ToolBarButtonStyle.Separator;
            toolBar.Buttons.Add(dropDownButton);
            IRawElementProviderSimple separatorProvider =
                ProviderFactory.GetProvider(separatorButton);

            TestProperty(separatorProvider,
                         AutomationElementIdentifiers.ControlTypeProperty,
                         ControlType.Separator.Id);
            TestProperty(separatorProvider,
                         AutomationElementIdentifiers.LocalizedControlTypeProperty,
                         "separator");

            string value = "ToolBarButton Name Property";

            toolBarButton.Text = value;
            TestProperty(provider,
                         AutomationElementIdentifiers.NameProperty,
                         value);
            TestProperty(provider,
                         AutomationElementIdentifiers.IsEnabledProperty,
                         toolBarButton.Enabled);

            toolBarButton.Enabled = false;
            TestProperty(provider,
                         AutomationElementIdentifiers.IsEnabledProperty,
                         false);
            toolBarButton.Enabled = true;
        }
Esempio n. 40
0
        IRawElementProviderSimple UIAutomationClient.IUIAutomationProxyFactory.CreateProvider(IntPtr hwnd, int idObject, int idChild)
        {
            IRawElementProviderSimple provider = _callback(hwnd, idChild, idObject);

            return(provider);
        }
 public static extern HRESULT UiaRaiseAutomationEvent(IRawElementProviderSimple provider, UIA id);
        ///<summary>
        /// Find Childrend Peers based on Automation Properties.
        /// Used to enable virtualization with automation.
        ///
        /// GetChildrenCore and FindItemByProperty are almost straight copies of the
        /// ItemControlAutomationPeer code; however since DataGridColumHeaderPresenter
        /// returns the Column.Header's as the items some specialized code was needed to
        /// create and store peers.
        ///</summary>
        IRawElementProviderSimple IItemContainerProvider.FindItemByProperty(IRawElementProviderSimple startAfter, int propertyId, object value)
        {
            ResetChildrenCache();
            // Checks if propertyId is valid else throws ArgumentException to notify it as invalid argument is being passed
            if (propertyId != 0)
            {
                if (!IsPropertySupportedByControlForFindItem(propertyId))
                {
                    throw new ArgumentException(SR.Get(SRID.PropertyNotSupported));
                }
            }

            ItemsControl owner = (ItemsControl)Owner;

            IList items = null;

            if (owner != null)
            {
                items = OwningDataGrid.Columns;
            }

            if (items != null && items.Count > 0)
            {
                DataGridColumnHeaderItemAutomationPeer startAfterItem = null;
                if (startAfter != null)
                {
                    // get the peer corresponding to this provider
                    startAfterItem = PeerFromProvider(startAfter) as DataGridColumnHeaderItemAutomationPeer;
                    if (startAfterItem == null)
                    {
                        return(null);
                    }
                }

                // startIndex refers to the index of the item just after startAfterItem
                int startIndex = 0;
                if (startAfterItem != null)
                {
                    if (startAfterItem.Item == null)
                    {
                        throw new InvalidOperationException(SR.Get(SRID.InavalidStartItem));
                    }

                    // To find the index of the column items collection which occurs
                    // immidiately after startAfterItem.Item
                    startIndex = items.IndexOf(startAfterItem.Column) + 1;
                    if (startIndex == 0 || startIndex == items.Count)
                    {
                        return(null);
                    }
                }

                if (propertyId == 0)
                {
                    for (int i = startIndex; i < items.Count; i++)
                    {
                        // This is to handle the case of when dataItems are just plain strings and have duplicates,
                        // only the first occurence of duplicate Items will be returned. It has also been used couple more times below.
                        if (items.IndexOf(items[i]) != i)
                        {
                            continue;
                        }
                        return(ProviderFromPeer(FindOrCreateItemAutomationPeer(items[i])));
                    }
                }

                ItemAutomationPeer currentItemPeer;
                object             currentValue = null;
                for (int i = startIndex; i < items.Count; i++)
                {
                    currentItemPeer = FindOrCreateItemAutomationPeer(items[i]);
                    if (currentItemPeer == null)
                    {
                        continue;
                    }
                    try
                    {
                        currentValue = GetSupportedPropertyValue(currentItemPeer, propertyId);
                    }
                    catch (Exception ex)
                    {
                        if (ex is ElementNotAvailableException)
                        {
                            continue;
                        }
                    }

                    if (value == null || currentValue == null)
                    {
                        // Accept null as value corresponding to the property if it finds an item with null as the value of corresponding property else ignore.
                        if (currentValue == null && value == null && items.IndexOf(items[i]) == i)
                        {
                            return(ProviderFromPeer(currentItemPeer));
                        }
                        else
                        {
                            continue;
                        }
                    }

                    // Match is found within the specified criterion of search
                    if (value.Equals(currentValue) && items.IndexOf(items[i]) == i)
                    {
                        return(ProviderFromPeer(currentItemPeer));
                    }
                }
            }
            return(null);
        }
Esempio n. 43
0
 private static extern int RawUiaHostProviderFromHwnd(IntPtr hwnd, [MarshalAs(UnmanagedType.Interface)] out IRawElementProviderSimple provider);
Esempio n. 44
0
        protected virtual object GetProviderPropertyValue(int propertyId)
        {
            if (propertyId == AutomationElementIdentifiers.IsExpandCollapsePatternAvailableProperty.Id)
            {
                return(IsBehaviorEnabled(ExpandCollapsePatternIdentifiers.Pattern));
            }
            else if (propertyId == AutomationElementIdentifiers.IsGridPatternAvailableProperty.Id)
            {
                return(IsBehaviorEnabled(GridPatternIdentifiers.Pattern));
            }
            else if (propertyId == AutomationElementIdentifiers.IsInvokePatternAvailableProperty.Id)
            {
                return(IsBehaviorEnabled(InvokePatternIdentifiers.Pattern));
            }
            else if (propertyId == AutomationElementIdentifiers.IsMultipleViewPatternAvailableProperty.Id)
            {
                return(IsBehaviorEnabled(MultipleViewPatternIdentifiers.Pattern));
            }
            else if (propertyId == AutomationElementIdentifiers.IsRangeValuePatternAvailableProperty.Id)
            {
                return(IsBehaviorEnabled(RangeValuePatternIdentifiers.Pattern));
            }
            else if (propertyId == AutomationElementIdentifiers.IsScrollItemPatternAvailableProperty.Id)
            {
                return(IsBehaviorEnabled(ScrollItemPatternIdentifiers.Pattern));
            }
            else if (propertyId == AutomationElementIdentifiers.IsScrollPatternAvailableProperty.Id)
            {
                return(IsBehaviorEnabled(ScrollPatternIdentifiers.Pattern));
            }
            else if (propertyId == AutomationElementIdentifiers.IsSelectionItemPatternAvailableProperty.Id)
            {
                return(IsBehaviorEnabled(SelectionItemPatternIdentifiers.Pattern));
            }
            else if (propertyId == AutomationElementIdentifiers.IsSelectionPatternAvailableProperty.Id)
            {
                return(IsBehaviorEnabled(SelectionPatternIdentifiers.Pattern));
            }
            else if (propertyId == AutomationElementIdentifiers.IsTablePatternAvailableProperty.Id)
            {
                return(IsBehaviorEnabled(TablePatternIdentifiers.Pattern));
            }
            else if (propertyId == AutomationElementIdentifiers.IsTextPatternAvailableProperty.Id)
            {
                return(IsBehaviorEnabled(TextPatternIdentifiers.Pattern));
            }
            else if (propertyId == AutomationElementIdentifiers.IsTogglePatternAvailableProperty.Id)
            {
                return(IsBehaviorEnabled(TogglePatternIdentifiers.Pattern));
            }
            else if (propertyId == AutomationElementIdentifiers.IsTransformPatternAvailableProperty.Id)
            {
                return(IsBehaviorEnabled(TransformPatternIdentifiers.Pattern));
            }
            else if (propertyId == AutomationElementIdentifiers.IsValuePatternAvailableProperty.Id)
            {
                return(IsBehaviorEnabled(ValuePatternIdentifiers.Pattern));
            }
            else if (propertyId == AutomationElementIdentifiers.IsWindowPatternAvailableProperty.Id)
            {
                return(IsBehaviorEnabled(WindowPatternIdentifiers.Pattern));
            }
            else if (propertyId == AutomationElementIdentifiers.IsDockPatternAvailableProperty.Id)
            {
                return(IsBehaviorEnabled(DockPatternIdentifiers.Pattern));
            }
            else if (propertyId == AutomationElementIdentifiers.IsGridItemPatternAvailableProperty.Id)
            {
                return(IsBehaviorEnabled(GridItemPatternIdentifiers.Pattern));
            }
            else if (propertyId == AutomationElementIdentifiers.IsTableItemPatternAvailableProperty.Id)
            {
                return(IsBehaviorEnabled(TableItemPatternIdentifiers.Pattern));
            }
            else if (propertyId == AutomationElementIdentifiers.AutomationIdProperty.Id)
            {
                if (runtimeId == -1)
                {
                    runtimeId = Helper.GetUniqueRuntimeId();
                }

                return(runtimeId);
            }
            else if (propertyId == AutomationElementIdentifiers.IsControlElementProperty.Id)
            {
                return(true);
            }
            else if (propertyId == AutomationElementIdentifiers.IsContentElementProperty.Id)
            {
                return(true);
            }
            else if (propertyId == AutomationElementIdentifiers.IsPasswordProperty.Id)
            {
                return(false);
            }
            else if (propertyId == AutomationElementIdentifiers.LocalizedControlTypeProperty.Id)
            {
                object controlTypeIdObj =
                    GetPropertyValue(AutomationElementIdentifiers.ControlTypeProperty.Id);
                if (controlTypeIdObj != null)
                {
                    int controlTypeId = (int)controlTypeIdObj;
                    //On Win7, for DataGrid, DataItem and List, the ControlType.LocalizedControlType
                    //is inconsistent with the element's LocalizedControlType property.
                    if (controlTypeId == ControlType.DataGrid.Id)
                    {
                        return(Catalog.GetString("data grid"));
                    }
                    else if (controlTypeId == ControlType.DataItem.Id)
                    {
                        return(Catalog.GetString("data item"));
                    }
                    else if (controlTypeId == ControlType.List.Id)
                    {
                        return(Catalog.GetString("list"));
                    }
                    else
                    {
                        var ct = ControlType.LookupById(controlTypeId);
                        return(ct != null ? ct.LocalizedControlType : null);
                    }
                }
                else
                {
                    return(null);
                }
            }
            else if (propertyId == AutomationElementIdentifiers.IsOffscreenProperty.Id)
            {
                Rect bounds = (Rect)
                              GetPropertyValue(AEIds.BoundingRectangleProperty.Id);
                if (Control == null)
                {
                    return(Helper.IsOffScreen(Helper.RectToRectangle(bounds)));
                }
                return(Helper.IsOffScreen(bounds, Control));
            }
            else if (propertyId == AutomationElementIdentifiers.BoundingRectangleProperty.Id)
            {
                return(BoundingRectangleProperty);
            }

            //Control-like properties
            if (Control == null)
            {
                return(null);
            }
            else if (propertyId == AutomationElementIdentifiers.IsEnabledProperty.Id)
            {
                return(Control.Enabled);
            }
            else if (propertyId == AutomationElementIdentifiers.NameProperty.Id)
            {
                if (!string.IsNullOrEmpty(Control.AccessibleName))
                {
                    return(Control.AccessibleName);
                }

                IRawElementProviderSimple label =
                    GetPropertyValue(AutomationElementIdentifiers.LabeledByProperty.Id)
                    as IRawElementProviderSimple;
                if (label == null)
                {
                    int controlType = (int)GetPropertyValue(AutomationElementIdentifiers.ControlTypeProperty.Id);
                    // http://msdn.microsoft.com/en-us/library/ms748367.aspx
                    // "The Name property should never contain the textual contents of the edit control."
                    if (controlType == ControlType.Edit.Id || controlType == ControlType.Document.Id)
                    {
                        return(string.Empty);
                    }
                    else
                    {
                        return(Helper.StripAmpersands(Control.Text));
                    }
                }
                else
                {
                    return(label.GetPropertyValue(AutomationElementIdentifiers.NameProperty.Id));
                }
            }
            else if (propertyId == AutomationElementIdentifiers.LabeledByProperty.Id)
            {
                IRawElementProviderFragment sibling = this as IRawElementProviderFragment;
                if (sibling == null)
                {
                    return(null);
                }
                IRawElementProviderFragment parent = sibling.Navigate(NavigateDirection.Parent);
                if (parent == null || parent == sibling)
                {
                    return(null);
                }
                IRawElementProviderFragment closestLabel = null;
                double closestLabelDistance = double.MaxValue;
                for (sibling = parent.Navigate(NavigateDirection.FirstChild);
                     sibling != null;
                     sibling = sibling.Navigate(NavigateDirection.NextSibling))
                {
                    if (sibling == this)
                    {
                        continue;
                    }
                    if ((int)sibling.GetPropertyValue(AutomationElementIdentifiers.ControlTypeProperty.Id) == ControlType.Text.Id)
                    {
                        double siblingDistance;
                        if ((siblingDistance = DistanceFrom(sibling)) < closestLabelDistance)
                        {
                            closestLabel         = sibling;
                            closestLabelDistance = siblingDistance;
                        }
                    }
                }

                return(closestLabel);
            }
            else if (propertyId == AutomationElementIdentifiers.IsKeyboardFocusableProperty.Id)
            {
                return(Control.CanFocus && Control.CanSelect);
            }
            else if (propertyId == AutomationElementIdentifiers.HasKeyboardFocusProperty.Id)
            {
                return(Control.Focused);
            }
            else if (propertyId == AutomationElementIdentifiers.ClickablePointProperty.Id)
            {
                return(Helper.GetClickablePoint(this));
            }
            else if (propertyId == AEIds.FrameworkIdProperty.Id)
            {
                return("WinForm");                // TODO: Localizable?
            }
            else if (propertyId == AutomationElementIdentifiers.HelpTextProperty.Id)
            {
                if (ToolTip == null)
                {
                    return(Control.AccessibleDescription ?? string.Empty);
                }
                else
                {
                    return(ToolTip.GetToolTip(Control));
                }
            }
            else if (propertyId == AutomationElementIdentifiers.AccessKeyProperty.Id)
            {
                if (!Control.Text.Contains("&"))
                {
                    return(null);
                }
                else
                {
                    int index = Control.Text.LastIndexOf('&') + 1;
                    return("Alt+" + Control.Text.Substring(index, 1));
                }
            }
            else if (propertyId == AEIds.ProcessIdProperty.Id)
            {
                // TODO: Write test for this property
                if (!pid.HasValue)
                {
                    pid = System.Diagnostics.Process.GetCurrentProcess().Id;
                }
                return(pid.Value);
            }
            else if (propertyId == AutomationElementIdentifiers.NativeWindowHandleProperty.Id)
            {
                return(Control.Handle);                // TODO: Should be int, maybe?
            }
            else
            {
                return(null);
            }
        }
 public static void RaiseAutomationPropertyChangedEvent(IRawElementProviderSimple element, AutomationPropertyChangedEventArgs e)
 {
     Utility.ValidateArgumentNonNull(element, "element");
     Utility.ValidateArgumentNonNull(e, "e");
     UiaCoreProviderApi.UiaRaiseAutomationPropertyChangedEvent(element, e.Property.Id, e.OldValue, e.NewValue);
 }
Esempio n. 46
0
 private static extern int RawUiaRaiseAsyncContentLoadedEvent(IRawElementProviderSimple provider, System.Windows.Automation.AsyncContentLoadedState asyncContentLoadedState, double PercentComplete);
 public static IntPtr ReturnRawElementProvider(IntPtr hwnd, IntPtr wParam, IntPtr lParam, IRawElementProviderSimple el)
 {
     Utility.ValidateArgument(hwnd != IntPtr.Zero, "HWND must not be null");
     Utility.ValidateArgumentNonNull(el, "el");
     return UiaCoreProviderApi.UiaReturnRawElementProvider(hwnd, wParam, lParam, el);
 }
Esempio n. 48
0
 private static extern int RawUiaRaiseAutomationEvent(IRawElementProviderSimple provider, int id);
 public static extern int UiaRaiseAutomationPropertyChangedEvent(IRawElementProviderSimple el, int propertyId, object oldValue, object newValue);
Esempio n. 50
0
 private static extern int RawUiaRaiseAutomationPropertyChangedEvent(IRawElementProviderSimple provider, int id, object oldValue, object newValue);
 ITextRangeProvider ITextProvider.RangeFromChild(IRawElementProviderSimple childElement)
 {
     return new CustomControl2RangeProvider(customInputBox.ContentText, this);
 }
Esempio n. 52
0
 private static extern int RawUiaRaiseStructureChangedEvent(IRawElementProviderSimple provider, StructureChangeType structureChangeType, int[] runtimeId, int runtimeIdLen);
 public TestPatternProvider(IRawElementProviderSimple hostElement)
 {
     _hostElement = hostElement;
 }
        ///// <summary>
        ///// Gets the collection of child elements of the
        ///// <see cref="T:WinRTXamlToolkit.Controls.TreeView" /> that is associated
        ///// with this
        ///// <see cref="T:System.Windows.Automation.Peers.TreeViewAutomationPeer" />.
        ///// </summary>
        ///// <returns>The collection of child elements.</returns>
        //[SuppressMessage("Microsoft.Design", "CA1002:DoNotExposeGenericLists", Justification = "Required by automation")]
        //protected override List<AutomationPeer> GetChildrenCore()
        //{
        //    TreeView owner = OwnerTreeView;
            
        //    ItemCollection items = owner.Items;
        //    if (items.Count <= 0)
        //    {
        //        return null;
        //    }

        //    List<AutomationPeer> peers = new List<AutomationPeer>(items.Count);
        //    for (int i = 0; i < items.Count; i++)
        //    {
        //        TreeViewItem element = owner.ItemContainerGenerator.ContainerFromIndex(i) as TreeViewItem;
        //        if (element != null)
        //        {
        //            peers.Add(
        //                FrameworkElementAutomationPeer.FromElement(element) ??
        //                FrameworkElementAutomationPeer.CreatePeerForElement(element));
        //        }
        //    }

        //    return peers;
        //}

        /// <summary>
        /// Retrieves a UI automation provider for each child element that is
        /// selected.
        /// </summary>
        /// <returns>An array of UI automation providers.</returns>
        /// <remarks>
        /// This API supports the .NET Framework infrastructure and is not 
        /// intended to be used directly from your code.
        /// </remarks>
        IRawElementProviderSimple[] ISelectionProvider.GetSelection()
        {
            IRawElementProviderSimple[] selection = null;

            TreeViewItem selectedItem = OwnerTreeView.SelectedContainer;
            if (selectedItem != null)
            {
                AutomationPeer peer = FrameworkElementAutomationPeer.FromElement(selectedItem);
                if (peer != null)
                {
                    selection = new IRawElementProviderSimple[] { ProviderFromPeer(peer) };
                }
            }

            return selection ?? new IRawElementProviderSimple[] { };
        }