Example #1
0
        public static ICommandSource BindCommand([NotNull] this ToolStripOverflowButton control, [NotNull] CommandBinding binding, [CanBeNull] object commandParameter = null)
        {
            var source = control.CreateCommandSourceBuilder().WithCommandBinding(binding).WithCommandParameter(commandParameter).Build();

            CommandSources[control] = source;

            return(source);
        }
Example #2
0
        public void ToolStripOverflowButtonAccessibleObject_Ctor_Default()
        {
            using ToolStrip toolStrip = new ToolStrip();
            ToolStripOverflowButton toolStripOverflowButton          = new ToolStripOverflowButton(toolStrip);
            ToolStripOverflowButtonAccessibleObject accessibleObject = new ToolStripOverflowButtonAccessibleObject(toolStripOverflowButton);

            Assert.Equal(toolStripOverflowButton, accessibleObject.Owner);
            Assert.False(toolStrip.IsHandleCreated);
        }
Example #3
0
        public void ToolStripOverflowButtonAccessibleObject_Role_IsMenuItem_ByDefault()
        {
            using ToolStrip toolStrip = new ToolStrip();
            ToolStripOverflowButton toolStripOverflowButton = new ToolStripOverflowButton(toolStrip);
            // AccessibleRole is not set = Default

            AccessibleRole actual = toolStripOverflowButton.AccessibilityObject.Role;

            Assert.Equal(AccessibleRole.MenuItem, actual);
            Assert.False(toolStrip.IsHandleCreated);
        }
Example #4
0
        public void ToolStripOverflowButtonAccessibleObject_ControlType_IsMenuItem_IfAccessibleRoleIsDefault()
        {
            using ToolStrip toolStrip = new ToolStrip();
            ToolStripOverflowButton toolStripOverflowButton = new ToolStripOverflowButton(toolStrip);
            // AccessibleRole is not set = Default

            object actual = toolStripOverflowButton.AccessibilityObject.GetPropertyValue(UiaCore.UIA.ControlTypePropertyId);

            Assert.Equal(UiaCore.UIA.MenuItemControlTypeId, actual);
            Assert.False(toolStrip.IsHandleCreated);
        }
Example #5
0
        public void ToolStripOverflowButtonAccessibleObject_GetPropertyValue_ControlType_IsExpected_ForCustomRole(AccessibleRole role)
        {
            using ToolStrip toolStrip = new ToolStrip();
            ToolStripOverflowButton toolStripOverflowButton = new ToolStripOverflowButton(toolStrip);

            toolStripOverflowButton.AccessibleRole = role;

            object actual = toolStripOverflowButton.AccessibilityObject.GetPropertyValue(UiaCore.UIA.ControlTypePropertyId);

            UiaCore.UIA expected = AccessibleRoleControlTypeMap.GetControlType(role);

            Assert.Equal(expected, actual);
        }
        public void Size2()
        {
            Form f = new Form();

            f.ShowInTaskbar = false;
            f.Show();

            ToolStrip ts = new ToolStrip();

            f.Controls.Add(ts);
            ToolStripOverflowButton tsi = ts.OverflowButton;

            Assert.AreEqual(new Size(16, 25), tsi.Size, "B1");
            Assert.AreEqual(false, tsi.Visible, "B3");
            ToolStripItem test = ts.Items.Add("test");

            test.Overflow = ToolStripItemOverflow.Always;
            ts.PerformLayout();

            Assert.AreEqual(Size.Empty, tsi.Size, "B2");
            f.Hide();
        }
        public void ToolStripDropDownMenuAccessible_FragmentNavigate_ReturnExpected_WithoutItem_ToolStripOverflowButton(bool createControl)
        {
            using ToolStrip toolStrip = new();

            if (createControl)
            {
                toolStrip.CreateControl();
            }

            ToolStripOverflowButton item = toolStrip.OverflowButton;

            AccessibleObject accessibleObject = item.DropDown.AccessibilityObject;

            Assert.Equal(item.AccessibilityObject, accessibleObject.FragmentNavigate(NavigateDirection.Parent));
            Assert.Null(accessibleObject.FragmentNavigate(NavigateDirection.NextSibling));
            Assert.Null(accessibleObject.FragmentNavigate(NavigateDirection.PreviousSibling));
            Assert.Null(accessibleObject.FragmentNavigate(NavigateDirection.FirstChild));
            Assert.Null(accessibleObject.FragmentNavigate(NavigateDirection.LastChild));

            Assert.Null(item.AccessibilityObject.FragmentNavigate(NavigateDirection.FirstChild));
            Assert.Null(item.AccessibilityObject.FragmentNavigate(NavigateDirection.LastChild));
            Assert.Equal(createControl, toolStrip.IsHandleCreated);
        }
Example #8
0
        public void RenderOverflowBackground(ToolStripItemRenderEventArgs e, bool rightToLeft)
        {
            bool      flag2;
            Color     empty              = Color.Empty;
            Graphics  g                  = e.Graphics;
            ToolStrip toolStrip          = e.ToolStrip;
            ToolStripOverflowButton item = e.Item as ToolStripOverflowButton;
            Rectangle bounds             = new Rectangle(Point.Empty, item.Size);
            Rectangle withinBounds       = bounds;
            bool      flag               = !(item.GetCurrentParent() is MenuStrip);

            if (flag2 = toolStrip.Orientation == Orientation.Horizontal)
            {
                bounds.X    += (bounds.Width - 12) + 1;
                bounds.Width = 12;
                if (rightToLeft)
                {
                    bounds = LayoutUtils.RTLTranslate(bounds, withinBounds);
                }
            }
            else
            {
                bounds.Y      = (bounds.Height - 12) + 1;
                bounds.Height = 12;
            }
            if (item.Pressed)
            {
                empty = this.ColorTable.ItemPressed;
            }
            else if (item.Selected)
            {
                empty = this.ColorTable.ItemHover;
            }
            else
            {
                empty = this.ColorTable.Base;
            }
            if (flag)
            {
                using (Pen pen = new Pen(this.ColorTable.Base))
                {
                    Point point  = new Point(bounds.Left - 1, bounds.Height - 2);
                    Point point2 = new Point(bounds.Left, bounds.Height - 2);
                    if (rightToLeft)
                    {
                        point.X  = bounds.Right + 1;
                        point2.X = bounds.Right;
                    }
                    g.DrawLine(pen, point, point2);
                }
            }
            LinearGradientMode mode = flag2 ? LinearGradientMode.Vertical : LinearGradientMode.Horizontal;

            RenderHelperStrip.RenderBackgroundInternal(g, bounds, empty, this.ColorTable.ItemBorder, this.ColorTable.Back, RoundStyle.None, 0, 0.35f, false, false, mode);
            if (flag)
            {
                using (Brush brush = new SolidBrush(this.ColorTable.Base))
                {
                    if (flag2)
                    {
                        Point point3 = new Point(bounds.X - 2, 0);
                        Point point4 = new Point(bounds.X - 1, 1);
                        if (rightToLeft)
                        {
                            point3.X = bounds.Right + 1;
                            point4.X = bounds.Right;
                        }
                        g.FillRectangle(brush, point3.X, point3.Y, 1, 1);
                        g.FillRectangle(brush, point4.X, point4.Y, 1, 1);
                    }
                    else
                    {
                        g.FillRectangle(brush, bounds.Width - 3, bounds.Top - 1, 1, 1);
                        g.FillRectangle(brush, bounds.Width - 2, bounds.Top - 2, 1, 1);
                    }
                }
                using (Brush brush2 = new SolidBrush(this.ColorTable.Base))
                {
                    if (flag2)
                    {
                        Rectangle rect = new Rectangle(bounds.X - 1, 0, 1, 1);
                        if (rightToLeft)
                        {
                            rect.X = bounds.Right;
                        }
                        g.FillRectangle(brush2, rect);
                    }
                    else
                    {
                        g.FillRectangle(brush2, bounds.X, bounds.Top - 1, 1, 1);
                    }
                }
            }
        }
Example #9
0
        internal void RenderOverflowBackground(ToolStripItemRenderEventArgs e, bool rightToLeft)
        {
            Color     color              = Color.Empty;
            Graphics  graphics           = e.Graphics;
            ToolStrip toolStrip          = e.ToolStrip;
            ToolStripOverflowButton item = e.Item as ToolStripOverflowButton;
            Rectangle bounds             = new Rectangle(Point.Empty, item.Size);
            Rectangle withinBounds       = bounds;
            bool      bParentIsMenuStrip = !(item.GetCurrentParent() is MenuStrip);
            bool      bHorizontal        = toolStrip.Orientation == Orientation.Horizontal;

            if (bHorizontal)
            {
                bounds.X    += (bounds.Width - 12) + 1;
                bounds.Width = 12;
                if (rightToLeft)
                {
                    bounds = GraphicsHelper.RTLTranslate(bounds, withinBounds);
                }
            }
            else
            {
                bounds.Y      = (bounds.Height - 12) + 1;
                bounds.Height = 12;
            }

            if (item.Pressed)
            {
                color = StyleSheet.HeadToolStripItemPressedBackColor;
            }
            else if (item.Selected)
            {
                color = StyleSheet.HeadToolStripItemHoveringBackColor;
            }
            else
            {
                color = StyleSheet.HeadToolStripBackColor;
            }
            if (bParentIsMenuStrip)
            {
                using (Pen pen = new Pen(StyleSheet.HeadToolStripBackColor))
                {
                    Point point  = new Point(bounds.Left - 1, bounds.Height - 2);
                    Point point2 = new Point(bounds.Left, bounds.Height - 2);
                    if (rightToLeft)
                    {
                        point.X  = bounds.Right + 1;
                        point2.X = bounds.Right;
                    }
                    graphics.DrawLine(pen, point, point2);
                }
            }

            LinearGradientMode mode = bHorizontal ? LinearGradientMode.Vertical : LinearGradientMode.Horizontal;

            GraphicsHelper.DrawBackground(
                graphics,
                bounds,
                color,
                StyleSheet.HeadToolStripItemBorderColor,
                StyleSheet.HeadToolStripItemInnerBorderColor,
                RoundStyle.None,
                0,
                .35f,
                false,
                false,
                mode);

            if (bParentIsMenuStrip)
            {
                using (Brush brush = new SolidBrush(StyleSheet.HeadToolStripBackColor))
                {
                    if (bHorizontal)
                    {
                        Point point3 = new Point(bounds.X - 2, 0);
                        Point point4 = new Point(bounds.X - 1, 1);
                        if (rightToLeft)
                        {
                            point3.X = bounds.Right + 1;
                            point4.X = bounds.Right;
                        }
                        graphics.FillRectangle(brush, point3.X, point3.Y, 1, 1);
                        graphics.FillRectangle(brush, point4.X, point4.Y, 1, 1);
                    }
                    else
                    {
                        graphics.FillRectangle(brush, bounds.Width - 3, bounds.Top - 1, 1, 1);
                        graphics.FillRectangle(brush, bounds.Width - 2, bounds.Top - 2, 1, 1);
                    }
                }
                using (Brush brush = new SolidBrush(StyleSheet.HeadToolStripBackColor))
                {
                    if (bHorizontal)
                    {
                        Rectangle rect = new Rectangle(bounds.X - 1, 0, 1, 1);
                        if (rightToLeft)
                        {
                            rect.X = bounds.Right;
                        }
                        graphics.FillRectangle(brush, rect);
                    }
                    else
                    {
                        graphics.FillRectangle(brush, bounds.X, bounds.Top - 1, 1, 1);
                    }
                }
            }
        }
        public void ToolStripDropDownMenuAccessible_FragmentNavigate_ReturnExpected_ToolStripOverflowButton(Type parentType, Type childType)
        {
            using ToolStrip toolStrip = new();
            toolStrip.CreateControl();

            using ToolStripDropDownItem parentItem1 = ReflectionHelper.InvokePublicConstructor <ToolStripDropDownItem>(parentType);
            using ToolStripDropDownItem parentItem2 = ReflectionHelper.InvokePublicConstructor <ToolStripDropDownItem>(parentType);
            using ToolStripDropDownItem childItem1  = ReflectionHelper.InvokePublicConstructor <ToolStripDropDownItem>(childType);
            using ToolStripDropDownItem childItem2  = ReflectionHelper.InvokePublicConstructor <ToolStripDropDownItem>(childType);
            using ToolStripDropDownItem childItem3  = ReflectionHelper.InvokePublicConstructor <ToolStripDropDownItem>(childType);
            using ToolStripDropDownItem childItem4  = ReflectionHelper.InvokePublicConstructor <ToolStripDropDownItem>(childType);

            toolStrip.Items.Add(parentItem1);
            toolStrip.Items.Add(parentItem2);

            parentItem1.DropDownItems.Add(childItem1);
            parentItem1.DropDownItems.Add(childItem2);
            parentItem2.DropDownItems.Add(childItem3);
            parentItem2.DropDownItems.Add(childItem4);

            using ToolStripOverflowButton ownerItem = toolStrip.OverflowButton;
            toolStrip.OverflowItems.Add(parentItem1);
            toolStrip.OverflowItems.Add(parentItem2);

            AccessibleObject accessibleObject = ownerItem.DropDown.AccessibilityObject;

            Assert.Equal(ownerItem.AccessibilityObject, accessibleObject.FragmentNavigate(NavigateDirection.Parent));
            Assert.Null(accessibleObject.FragmentNavigate(NavigateDirection.NextSibling));
            Assert.Null(accessibleObject.FragmentNavigate(NavigateDirection.PreviousSibling));
            Assert.Equal(parentItem1.AccessibilityObject, accessibleObject.FragmentNavigate(NavigateDirection.FirstChild));
            Assert.Equal(parentItem2.AccessibilityObject, accessibleObject.FragmentNavigate(NavigateDirection.LastChild));

            Assert.Equal(accessibleObject, ownerItem.AccessibilityObject.FragmentNavigate(NavigateDirection.FirstChild));
            Assert.Equal(accessibleObject, ownerItem.AccessibilityObject.FragmentNavigate(NavigateDirection.LastChild));
            Assert.Equal(accessibleObject, parentItem1.AccessibilityObject.FragmentNavigate(NavigateDirection.Parent));
            Assert.Equal(accessibleObject, parentItem2.AccessibilityObject.FragmentNavigate(NavigateDirection.Parent));

            AccessibleObject accessibleObject1 = parentItem1.DropDown.AccessibilityObject;

            Assert.Equal(parentItem1.AccessibilityObject, accessibleObject1.FragmentNavigate(NavigateDirection.Parent));
            Assert.Null(accessibleObject1.FragmentNavigate(NavigateDirection.NextSibling));
            Assert.Null(accessibleObject1.FragmentNavigate(NavigateDirection.PreviousSibling));
            Assert.Equal(childItem1.AccessibilityObject, accessibleObject1.FragmentNavigate(NavigateDirection.FirstChild));
            Assert.Equal(childItem2.AccessibilityObject, accessibleObject1.FragmentNavigate(NavigateDirection.LastChild));

            Assert.Equal(accessibleObject1, parentItem1.AccessibilityObject.FragmentNavigate(NavigateDirection.FirstChild));
            Assert.Equal(accessibleObject1, parentItem1.AccessibilityObject.FragmentNavigate(NavigateDirection.LastChild));
            Assert.Equal(accessibleObject1, childItem1.AccessibilityObject.FragmentNavigate(NavigateDirection.Parent));
            Assert.Equal(accessibleObject1, childItem2.AccessibilityObject.FragmentNavigate(NavigateDirection.Parent));

            AccessibleObject accessibleObject2 = parentItem2.DropDown.AccessibilityObject;

            Assert.Equal(parentItem2.AccessibilityObject, accessibleObject2.FragmentNavigate(NavigateDirection.Parent));
            Assert.Null(accessibleObject2.FragmentNavigate(NavigateDirection.NextSibling));
            Assert.Null(accessibleObject2.FragmentNavigate(NavigateDirection.PreviousSibling));
            Assert.Equal(childItem3.AccessibilityObject, accessibleObject2.FragmentNavigate(NavigateDirection.FirstChild));
            Assert.Equal(childItem4.AccessibilityObject, accessibleObject2.FragmentNavigate(NavigateDirection.LastChild));

            Assert.Equal(accessibleObject2, parentItem2.AccessibilityObject.FragmentNavigate(NavigateDirection.FirstChild));
            Assert.Equal(accessibleObject2, parentItem2.AccessibilityObject.FragmentNavigate(NavigateDirection.LastChild));
            Assert.Equal(accessibleObject2, childItem3.AccessibilityObject.FragmentNavigate(NavigateDirection.Parent));
            Assert.Equal(accessibleObject2, childItem4.AccessibilityObject.FragmentNavigate(NavigateDirection.Parent));
        }
Example #11
0
        public void ToolStripDropDownMenuAccessible_FragmentNavigate_ReturnExpected_ToolStripOverflowButton(Type parentType, Type childType)
        {
            using ToolStrip toolStrip = new();
            toolStrip.CreateControl();

            using ToolStripDropDownItem parentItem1 = ReflectionHelper.InvokePublicConstructor <ToolStripDropDownItem>(parentType);
            using ToolStripDropDownItem parentItem2 = ReflectionHelper.InvokePublicConstructor <ToolStripDropDownItem>(parentType);
            using ToolStripDropDownItem childItem1  = ReflectionHelper.InvokePublicConstructor <ToolStripDropDownItem>(childType);
            using ToolStripDropDownItem childItem2  = ReflectionHelper.InvokePublicConstructor <ToolStripDropDownItem>(childType);
            using ToolStripDropDownItem childItem3  = ReflectionHelper.InvokePublicConstructor <ToolStripDropDownItem>(childType);
            using ToolStripDropDownItem childItem4  = ReflectionHelper.InvokePublicConstructor <ToolStripDropDownItem>(childType);

            parentItem1.DropDownItems.Add(childItem1);
            parentItem1.DropDownItems.Add(childItem2);
            parentItem2.DropDownItems.Add(childItem3);
            parentItem2.DropDownItems.Add(childItem4);

            using ToolStripOverflowButton ownerItem = toolStrip.OverflowButton;
            toolStrip.OverflowItems.Add(parentItem1);
            toolStrip.OverflowItems.Add(parentItem2);

            // ToolStripSplitStackLayout does it in runtime when Layout method is working.
            // Use this way as a workaround in tests.
            // It should be reset in the end of the test to avoid Dispose method errors.
            parentItem1.ParentInternal = ownerItem.DropDown;
            parentItem2.ParentInternal = ownerItem.DropDown;

            ownerItem.DropDown.Show();
            AccessibleObject accessibleObject = ownerItem.DropDown.AccessibilityObject;

            Assert.Equal(ownerItem.AccessibilityObject, accessibleObject.FragmentNavigate(NavigateDirection.Parent));
            Assert.Null(accessibleObject.FragmentNavigate(NavigateDirection.NextSibling));
            Assert.Null(accessibleObject.FragmentNavigate(NavigateDirection.PreviousSibling));
            Assert.Equal(parentItem1.AccessibilityObject, accessibleObject.FragmentNavigate(NavigateDirection.FirstChild));
            Assert.Equal(parentItem2.AccessibilityObject, accessibleObject.FragmentNavigate(NavigateDirection.LastChild));

            Assert.Equal(accessibleObject, ownerItem.AccessibilityObject.FragmentNavigate(NavigateDirection.FirstChild));
            Assert.Equal(accessibleObject, ownerItem.AccessibilityObject.FragmentNavigate(NavigateDirection.LastChild));
            Assert.Equal(accessibleObject, parentItem1.AccessibilityObject.FragmentNavigate(NavigateDirection.Parent));
            Assert.Equal(accessibleObject, parentItem2.AccessibilityObject.FragmentNavigate(NavigateDirection.Parent));

            parentItem1.DropDown.Show();
            AccessibleObject accessibleObject1 = parentItem1.DropDown.AccessibilityObject;

            Assert.Equal(parentItem1.AccessibilityObject, accessibleObject1.FragmentNavigate(NavigateDirection.Parent));
            Assert.Null(accessibleObject1.FragmentNavigate(NavigateDirection.NextSibling));
            Assert.Null(accessibleObject1.FragmentNavigate(NavigateDirection.PreviousSibling));
            Assert.Equal(childItem1.AccessibilityObject, accessibleObject1.FragmentNavigate(NavigateDirection.FirstChild));
            Assert.Equal(childItem2.AccessibilityObject, accessibleObject1.FragmentNavigate(NavigateDirection.LastChild));

            Assert.Equal(accessibleObject1, parentItem1.AccessibilityObject.FragmentNavigate(NavigateDirection.FirstChild));
            Assert.Equal(accessibleObject1, parentItem1.AccessibilityObject.FragmentNavigate(NavigateDirection.LastChild));
            Assert.Equal(accessibleObject1, childItem1.AccessibilityObject.FragmentNavigate(NavigateDirection.Parent));
            Assert.Equal(accessibleObject1, childItem2.AccessibilityObject.FragmentNavigate(NavigateDirection.Parent));

            parentItem2.DropDown.Show();
            AccessibleObject accessibleObject2 = parentItem2.DropDown.AccessibilityObject;

            Assert.Equal(parentItem2.AccessibilityObject, accessibleObject2.FragmentNavigate(NavigateDirection.Parent));
            Assert.Null(accessibleObject2.FragmentNavigate(NavigateDirection.NextSibling));
            Assert.Null(accessibleObject2.FragmentNavigate(NavigateDirection.PreviousSibling));
            Assert.Equal(childItem3.AccessibilityObject, accessibleObject2.FragmentNavigate(NavigateDirection.FirstChild));
            Assert.Equal(childItem4.AccessibilityObject, accessibleObject2.FragmentNavigate(NavigateDirection.LastChild));

            Assert.Equal(accessibleObject2, parentItem2.AccessibilityObject.FragmentNavigate(NavigateDirection.FirstChild));
            Assert.Equal(accessibleObject2, parentItem2.AccessibilityObject.FragmentNavigate(NavigateDirection.LastChild));
            Assert.Equal(accessibleObject2, childItem3.AccessibilityObject.FragmentNavigate(NavigateDirection.Parent));
            Assert.Equal(accessibleObject2, childItem4.AccessibilityObject.FragmentNavigate(NavigateDirection.Parent));

            // Reset the parent to avoid errors when disposing.
            parentItem1.ParentInternal = null;
            parentItem2.ParentInternal = null;
        }
Example #12
0
 public ToolStripOverflowButtonAccessibleObject(ToolStripOverflowButton owner) : base(owner)
 {
 }