示例#1
0
        /// <summary>
        /// Open the <see cref="MenuItems"/> menu items.
        /// </summary>
        public void Show()
        {
            if (menuBar != null)
            {
                Hide();
            }
            container          = Application.Current;
            container.Closing += Container_Closing;
            container.Resized += Container_Resized;
            var frame    = container.Frame;
            var position = Position;

            if (Host != null)
            {
                Host.ViewToScreen(container.Frame.X, container.Frame.Y, out int x, out int y);
                var pos = new Point(x, y);
                pos.Y += Host.Frame.Height - 1;
                if (position != pos)
                {
                    Position = position = pos;
                }
            }
            var rect = Menu.MakeFrame(position.X, position.Y, MenuItems.Children);

            if (rect.Right >= frame.Right)
            {
                if (frame.Right - rect.Width >= 0 || !ForceMinimumPosToZero)
                {
                    position.X = frame.Right - rect.Width;
                }
                else if (ForceMinimumPosToZero)
                {
                    position.X = 0;
                }
            }
            else if (ForceMinimumPosToZero && position.X < 0)
            {
                position.X = 0;
            }
            if (rect.Bottom >= frame.Bottom)
            {
                if (frame.Bottom - rect.Height - 1 >= 0 || !ForceMinimumPosToZero)
                {
                    if (Host == null)
                    {
                        position.Y = frame.Bottom - rect.Height - 1;
                    }
                    else
                    {
                        Host.ViewToScreen(container.Frame.X, container.Frame.Y, out int x, out int y);
                        var pos = new Point(x, y);
                        position.Y = pos.Y - rect.Height - 1;
                    }
                }
                else if (ForceMinimumPosToZero)
                {
                    position.Y = 0;
                }
            }
            else if (ForceMinimumPosToZero && position.Y < 0)
            {
                position.Y = 0;
            }

            menuBar = new MenuBar(new [] { MenuItems })
            {
                X      = position.X,
                Y      = position.Y,
                Width  = 0,
                Height = 0,
                UseSubMenusSingleFrame = UseSubMenusSingleFrame
            };

            menuBar.isContextMenuLoading = true;
            menuBar.MenuAllClosed       += MenuBar_MenuAllClosed;
            IsShow = true;
            menuBar.OpenMenu();
        }
示例#2
0
        public override bool ProcessKey(KeyEvent kb)
        {
            bool disabled;

            switch (kb.Key)
            {
            case Key.CursorUp:
                if (current == -1)
                {
                    break;
                }
                do
                {
                    disabled = false;
                    current--;
                    if (host.UseKeysUpDownAsKeysLeftRight)
                    {
                        if (current == -1 && barItems.Children [current + 1].IsFromSubMenu && host.selectedSub > -1)
                        {
                            current++;
                            host.PreviousMenu(true);
                            break;
                        }
                    }
                    if (current < 0)
                    {
                        current = barItems.Children.Length - 1;
                    }
                    var item = barItems.Children [current];
                    if (item == null || !item.IsEnabled())
                    {
                        disabled = true;
                    }
                } while (barItems.Children [current] == null || disabled);
                SetNeedsDisplay();
                break;

            case Key.CursorDown:
                do
                {
                    current++;
                    disabled = false;
                    if (current == barItems.Children.Length)
                    {
                        current = 0;
                    }
                    var item = barItems.Children [current];
                    if (item == null || !item.IsEnabled())
                    {
                        disabled = true;
                    }
                    if (host.UseKeysUpDownAsKeysLeftRight && barItems.Children [current]?.SubMenu != null &&
                        !disabled && !host.isMenuClosed)
                    {
                        CheckSubMenu();
                        break;
                    }
                    if (host.isMenuClosed)
                    {
                        host.OpenMenu(host.selected);
                    }
                } while (barItems.Children [current] == null || disabled);
                SetNeedsDisplay();
                break;

            case Key.CursorLeft:
                host.PreviousMenu(true);
                break;

            case Key.CursorRight:
                host.NextMenu(barItems.Children [current].IsFromSubMenu ? true : false);
                break;

            case Key.Esc:
                Application.UngrabMouse();
                host.CloseAllMenus();
                break;

            case Key.Enter:
                CheckSubMenu();
                Run(barItems.Children [current].Action);
                break;

            default:
                // TODO: rune-ify
                if (Char.IsLetterOrDigit((char)kb.KeyValue))
                {
                    var x = Char.ToUpper((char)kb.KeyValue);

                    foreach (var item in barItems.Children)
                    {
                        if (item == null)
                        {
                            continue;
                        }
                        if (item.IsEnabled() && item.HotKey == x)
                        {
                            host.CloseMenu();
                            Run(item.Action);
                            return(true);
                        }
                    }
                }
                break;
            }
            return(true);
        }