private void EnumerateInternal(ICollection <IHUDItem> results)
        {
            var element = AutomationElement.FocusedElement;

            if (element == null)
            {
                return;
            }

            var info = element.Current;
            var type = info.ControlType;

            if (type.IsContainer())
            {
                if (type == ControlType.ComboBox)
                {
                    element.ExpandComboBox();
                }
                else
                {
                    element.TryExpand();
                }
            }
            else if (type.IsItem())
            {
                element = element.GetParent();
            }
            else
            {
                element = element.GetParent();
                info    = element.Current;
                type    = info.ControlType;
                if (!type.IsContainer())
                {
                    return;
                }
                if (type == ControlType.ComboBox)
                {
                    element.ExpandComboBox();
                }
            }

            var children = element?.FindAll(TreeScope.Descendants, Condition.TrueCondition).Cast <AutomationElement>();

            foreach (var child in children)
            {
                var childInfo = child.Current;
                if (!childInfo.ControlType.IsItem())
                {
                    continue;
                }
                var item = new ItemInContainer(childInfo.Name, childInfo.BoundingRectangle, childInfo.IsEnabled, child, element);
                results.Add(item);
            }
        }
Example #2
0
        // TODO: Experimental
        internal void Expand()
        {
            Cancel();
            var selectedItem = UIAssistantAPI.ViewAPI.DefaultHUD.SelectedItem as SearchByTextItem;

            if (selectedItem == null || !selectedItem.IsEnabled || !selectedItem.CanExpand)
            {
                return;
            }

            var activeWindow = UIAssistantAPI.WindowAPI.ActiveWindow;

            // show popup
            selectedItem.Prepare();
            if (selectedItem is UIRibbonItem)
            {
                selectedItem.Execute();
                System.Threading.Thread.Sleep(300);
            }
            else
            {
                var element = selectedItem.GetCurrentElement(activeWindow.Element);
                element.SetFocus();
                element.TryExpand();
            }
            var popup = activeWindow.LastActivePopup;

            UIAssistantAPI.ViewAPI.DefaultHUD.Initialize();
            _sourceForFiltering.Clear();

            UIAssistantAPI.ViewAPI.TopMost = true;

            // Win32
            if (popup.WindowHandle == activeWindow.WindowHandle)
            {
                new SearchContainer().Enumerate(_sourceForFiltering);
                UIAssistantAPI.ViewAPI.DefaultHUD.Items = _sourceForFiltering;
                return;
            }

            // WPF etc.
            var elements = popup.Element.FindAll(TreeScope.Descendants | TreeScope.Element, Condition.TrueCondition).Cast <AutomationElement>().ToList();

            elements.ForEach(x =>
            {
                var info         = x.Current;
                var internalName = info.Name;

                if (!string.IsNullOrEmpty(internalName))
                {
                    var displayName = internalName.Trim();
                    if (_enumerator is SearchForText)
                    {
                        var item = new ItemInContainer(displayName, info.BoundingRectangle, info.IsEnabled, popup.Element, popup.Element);
                        _sourceForFiltering.Add(item);
                    }
                    else
                    {
                        var item = new UIRibbonItem(internalName, displayName, info.BoundingRectangle, info.IsEnabled, false, null, popup.Element);
                        _sourceForFiltering.Add(item);
                    }
                }
            });
            UIAssistantAPI.ViewAPI.DefaultHUD.Items = _sourceForFiltering;
        }