Exemplo n.º 1
0
        public void ContextMenu_ProcessCmdKey_HasItemWithShoutcutKey_ReturnsExpected(MenuItem menuItem, Control control, bool expectedResult, int expectedOnClickCallCount, int expectedOnPopupCallCount)
        {
            int onClickCallCount = 0;

            menuItem.Click += (sender, e) =>
            {
                onClickCallCount++;
                Assert.Same(menuItem, sender);
                Assert.Equal(EventArgs.Empty, e);
            };

            int onPopupCallCount = 0;

            menuItem.Popup += (sender, e) =>
            {
                onPopupCallCount++;
                Assert.Same(menuItem, sender);
                Assert.Equal(EventArgs.Empty, e);
            };

            using var menu = new SubContextMenu(new MenuItem[] { menuItem });
            var msg = new Message();

            Assert.Equal(expectedResult, menu.ProcessCmdKey(ref msg, Keys.Control | Keys.A, control));
            Assert.Same(control, menu.SourceControl);
            Assert.Equal(expectedOnClickCallCount, onClickCallCount);
            Assert.Equal(expectedOnPopupCallCount, onPopupCallCount);
        }
Exemplo n.º 2
0
        public void ShowSubMenu(SubContextMenu contextMenu)
        {
            ContextMenuOpenType openType;

            if (contextMenu.ActualWidth > SpaceForSubMenuX)
            {
                if ((contextMenu.ActualHeight + contextMenu.Location.Top) > (ActualHeight + SpaceForSubMenuY))
                {
                    openType = ContextMenuOpenType.LeftTop;
                }
                else
                {
                    openType = ContextMenuOpenType.LeftBottom;
                }
            }
            else
            {
                if ((contextMenu.ActualHeight + contextMenu.Location.Top) > (ActualHeight + SpaceForSubMenuY))
                {
                    openType = ContextMenuOpenType.RightTop;
                }
                else
                {
                    openType = ContextMenuOpenType.RightBottom;
                }
            }

            switch (openType)
            {
            case ContextMenuOpenType.RightBottom:
                contextMenu.Margin = contextMenu.Location;
                break;

            case ContextMenuOpenType.RightTop:
                var locationRightTop = contextMenu.Location;
                locationRightTop.Top -= (contextMenu.ActualHeight - 30);
                contextMenu.Margin    = locationRightTop;
                break;

            case ContextMenuOpenType.LeftBottom:
                var locationLeftBottom = contextMenu.Location;
                locationLeftBottom.Left -= (ActualWidth + contextMenu.ActualWidth - 10);
                contextMenu.Margin       = locationLeftBottom;
                break;

            case ContextMenuOpenType.LeftTop:
                var locationLeftTop = contextMenu.Location;
                locationLeftTop.Left -= (ActualWidth + contextMenu.ActualWidth - 10);
                locationLeftTop.Top  -= (contextMenu.ActualHeight - 30);
                contextMenu.Margin    = locationLeftTop;
                break;
            }

            contextMenu.Visibility = Visibility.Visible;
        }
Exemplo n.º 3
0
        public void ShowSubMenu(SubContextMenu contextMenu)
        {
            ContextMenuOpenType openType;
            if (contextMenu.ActualWidth > SpaceForSubMenuX)
            {
                if ((contextMenu.ActualHeight + contextMenu.Location.Top) > (ActualHeight + SpaceForSubMenuY))
                {
                    openType = ContextMenuOpenType.LeftTop;
                }
                else
                {
                    openType = ContextMenuOpenType.LeftBottom;
                }
            }
            else
            {
                if ((contextMenu.ActualHeight + contextMenu.Location.Top) > (ActualHeight + SpaceForSubMenuY))
                {
                    openType = ContextMenuOpenType.RightTop;
                }
                else
                {
                    openType = ContextMenuOpenType.RightBottom;
                }
            }

            switch (openType)
            {
                case ContextMenuOpenType.RightBottom:
                    contextMenu.Margin = contextMenu.Location;
                    break;
                case ContextMenuOpenType.RightTop:
                    var locationRightTop = contextMenu.Location;
                    locationRightTop.Top -= (contextMenu.ActualHeight - 30);
                    contextMenu.Margin = locationRightTop;
                    break;
                case ContextMenuOpenType.LeftBottom:
                    var locationLeftBottom = contextMenu.Location;
                    locationLeftBottom.Left -= (ActualWidth + contextMenu.ActualWidth - 10);
                    contextMenu.Margin = locationLeftBottom;
                    break;
                case ContextMenuOpenType.LeftTop:
                    var locationLeftTop = contextMenu.Location;
                    locationLeftTop.Left -= (ActualWidth + contextMenu.ActualWidth - 10);
                    locationLeftTop.Top -= (contextMenu.ActualHeight - 30);
                    contextMenu.Margin = locationLeftTop;
                    break;
            }

            contextMenu.Visibility = Visibility.Visible;
        }
Exemplo n.º 4
0
 public void ContextMenu_Ctor_Default()
 {
     using var menu = new SubContextMenu();
     Assert.True(menu.CanRaiseEvents);
     Assert.Null(menu.Container);
     Assert.False(menu.DesignMode);
     Assert.NotNull(menu.Events);
     Assert.Same(menu.Events, menu.Events);
     Assert.False(menu.IsParent);
     Assert.Empty(menu.MenuItems);
     Assert.Same(menu.MenuItems, menu.MenuItems);
     Assert.Empty(menu.Name);
     Assert.Equal(RightToLeft.No, menu.RightToLeft);
     Assert.Null(menu.Site);
     Assert.Null(menu.SourceControl);
     Assert.Null(menu.Tag);
 }
Exemplo n.º 5
0
        public void ContextMenu_OnPopup_Invoke_CallsPopup(EventArgs eventArgs)
        {
            using var menu = new SubContextMenu();
            int          callCount = 0;
            EventHandler handler   = (sender, e) =>
            {
                Assert.Same(menu, sender);
                Assert.Same(eventArgs, e);
                callCount++;
            };

            // Call with handler.
            menu.Popup += handler;
            menu.OnPopup(eventArgs);
            Assert.Equal(1, callCount);

            // Remove handler.
            menu.Popup -= handler;
            menu.OnPopup(eventArgs);
            Assert.Equal(1, callCount);
        }
Exemplo n.º 6
0
 public void ContextMenu_Ctor_MenuItemArray(MenuItem[] items, bool expectedIsParent, MenuItem[] expectedItems)
 {
     using var menu = new SubContextMenu(items);
     Assert.True(menu.CanRaiseEvents);
     Assert.Null(menu.Container);
     Assert.False(menu.DesignMode);
     Assert.NotNull(menu.Events);
     Assert.Same(menu.Events, menu.Events);
     Assert.Equal(expectedIsParent, menu.IsParent);
     Assert.Equal(expectedItems, menu.MenuItems.Cast <MenuItem>());
     for (int i = 0; i < menu.MenuItems.Count; i++)
     {
         Assert.Equal(i, menu.MenuItems[i].Index);
         Assert.Equal(menu, menu.MenuItems[i].Parent);
     }
     Assert.Same(menu.MenuItems, menu.MenuItems);
     Assert.Empty(menu.Name);
     Assert.Equal(RightToLeft.No, menu.RightToLeft);
     Assert.Null(menu.Site);
     Assert.Null(menu.SourceControl);
     Assert.Null(menu.Tag);
 }
Exemplo n.º 7
0
 public ContextMenu Item(string text, SubContextMenu subContextMenu)
 {
     Items.Add(new ContextMenuItem { Text = text, Items = subContextMenu});
     return this;
 }