Exemple #1
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;
        }
Exemple #2
0
        private void GetElements(AutomationElement element, bool root, string parent, AutomationElement group, AutomationElement ribbonRootElement)
        {
            PropertyCondition propCondition = new PropertyCondition(AutomationElement.IsContentElementProperty, true);
            var col = element.FindAll(TreeScope.Children, propCondition).Cast <AutomationElement>();

            foreach (var el in col)
            {
                try
                {
                    var         elementInfo = el.Current;
                    string      addName     = elementInfo.Name;
                    ControlType elementType = elementInfo.ControlType;
                    // コンボボックスのエディットボックスが、リボン UI のウィンドウ直下に表示されるときがあるので、それを除外する
                    if (elementType == ControlType.Pane)
                    {
                        if (elementInfo.NativeWindowHandle != IntPtr.Zero)
                        {
                            return;
                        }
                    }

                    if (addName != null && addName.Length != 0)
                    {
                        string itemName = addName.Clone() as string;
                        string fullpath;
                        string shortcutKey;
                        bool   canExpand;
                        if (FormatName(parent, elementType, el, ref addName, out fullpath, out shortcutKey, out canExpand))
                        {
                            if (shortcutKey == null || shortcutKey == "")
                            {
                                shortcutKey = el.GetAceessKeys();
                            }

                            //System.Diagnostics.Debug.Print($"{fullpath}");
                            var result = new UIRibbonItem(itemName, fullpath, elementInfo.BoundingRectangle, elementInfo.IsEnabled, canExpand, group, ribbonRootElement);
                            _results.Add(result);
                        }
                    }
                    else
                    {
                        addName = parent;
                    }

                    if (elementType == ControlType.ComboBox)
                    {
                        return;
                    }

                    bool tmpRoot = root;
                    if (root && elementType == ControlType.Pane)
                    {
                        return;
                    }
                    if (root && elementType == ControlType.TabItem)
                    {
                        if (el.IsSelected())
                        {
                            _initialPane = el;
                        }
                        else
                        {
                            tmpRoot = false;
                            _tabPane.Add(el);
                        }
                    }

                    AutomationElement rootElement;
                    if (ribbonRootElement == null)
                    {
                        rootElement = el;
                    }
                    else
                    {
                        rootElement = ribbonRootElement;
                    }
                    if (group == null && _initialPane != null)
                    {
                        GetElements(el, tmpRoot, addName, _initialPane, rootElement);
                    }
                    else
                    {
                        GetElements(el, tmpRoot, addName, group, rootElement);
                    }
                }
                catch (Exception e)
                {
                    System.Diagnostics.Debug.Print("GetMenus: {0}", e.Message);
                }
            }
        }