Пример #1
0
        public void AddMenuItems(System.Windows.Forms.ContextMenu m, int x, int y)
        {
            FlatMenuItem curr;
            EventHandler evh;

            if (st == null || st.Deleted)
            {
                parent.AddItem(m, "Enter new name", ToolBarIcons.None, false, new EventHandler(RestoreName));
                return;
            }

            // Display Options
            evh  = new EventHandler(DisplayOptions);
            curr = new FlatMenuItem("Display &Options...", null, 0, false);
            parent.AddItem(curr, "&Attributes", ToolBarIcons.show_attrs, show_vars, evh);
            parent.AddItem(curr, "&Operations", ToolBarIcons.show_opers, show_members, evh);
            parent.AddItem(curr, "&Properties", ToolBarIcons.show_properties, show_properties, evh);
            parent.AddItem(curr, "Show full &qualified name", ToolBarIcons.show_qual, show_full_qual, evh);
            parent.AddItem(curr, "Show operations &signature", ToolBarIcons.oper_signature, show_method_signatures, evh);
            parent.AddItem(curr, "Only public", ToolBarIcons.None, show_only_public, evh);
            m.MenuItems.Add(curr);

            evh  = new EventHandler(Import);
            curr = new FlatMenuItem("Import", parent.proj.icon_list, (int)ToolBarIcons.add_related, false);
            parent.AddItem(curr, "Import ancestor && interfaces", ToolBarIcons.None, false, evh);
            parent.AddItem(curr, "Import successors", ToolBarIcons.None, false, evh);
            m.MenuItems.Add(curr);

            m.MenuItems.Add(new StereoTypeHelper(this).GetStereoMenu());

            parent.AddItem(m, "Show/Hide Members", ToolBarIcons.None, false, new EventHandler(showhide));
        }
Пример #2
0
        /// <summary>
        /// Draw the popup menu.
        /// </summary>
        /// <param name="g">Graphics object to draw with.</param>
        protected override void DrawMenu(Graphics g)
        {
            // Draw the menu background.
            DrawBackground(g, this.ClientRectangle, this.BackColor);
            if (this.HasCheckOrRadioItems())
            {
                // Draw background for a left column area.
                Rectangle r = new Rectangle(this.ClientRectangle.X, this.ClientRectangle.Y,
                                            FlatPopupMenu.checkAreaWidth + 4, this.ClientRectangle.Height);

                var color = this.BackColor;
                DrawBackground(g, r, color);
            }

            // Draw the menu border.
            if (this.EnableBorderDrawing)
            {
                DrawBorder(g, this.ClientRectangle, this.BorderColor);
            }
            if (this.ParentMenu != null && !this.ParentMenu.IsPopupMenu)
            {
                DrawPartialLine(g);
            }

            // Draw each menu item.
            for (int i = 0; i < this.MenuItems.Count; ++i)
            {
                FlatMenuItem item = this.MenuItems.GetAt(i);
                Debug.Assert(item != null);

                DrawMenuItem(g, item);
            }
        }
Пример #3
0
        public FlatMenuItem GetStereoMenu()
        {
            FlatMenuItem curr;
            EventHandler evh;

            // Display Options
            evh  = new EventHandler(set_stereo);
            curr = new FlatMenuItem("Stereotype", null, 0, false);
            parent.AddItem(curr, "Other", ToolBarIcons.None, false, evh);
            parent.AddItem(curr, "Clear", ToolBarIcons.None, false, evh);
            parent.AddItem(curr, "-", ToolBarIcons.None, false, null);
            hashed_stereo_list = obj.StereoList;
            foreach (string s in hashed_stereo_list)
            {
                if (s != null)
                {
                    parent.AddItem(curr, "\x00AB" + s + "\xBB", ToolBarIcons.None, false, evh);
                }
                else
                {
                    parent.AddItem(curr, "-", ToolBarIcons.None, false, null);
                }
            }

            return(curr);
        }
Пример #4
0
        /// <summary>
        /// Re-calculate menu item rects for this menu.
        /// Also adjusts the menu size if needed.
        /// </summary>
        /// <param name="g">Graphics object needed to calculate
        /// text rects using MeasureString.</param>
        protected override void RepositionMenuItems(Graphics g)
        {
            int xoffset = this.LeftMargin;
            int yoffset = this.TopMargin;

            if (this.HasCheckOrRadioItems())
            {
                xoffset += FlatPopupMenu.checkAreaWidth + 3;
            }

            // Set the client rect for each menu item. The rect will
            // be a bit larger than the text rect based on MeasureString.
            for (int i = 0; i < this.MenuItems.Count; ++i)
            {
                FlatMenuItem item = this.MenuItems.GetAt(i);
                Debug.Assert(item != null);

                string text = item.Text;
                if (text == String.Empty)
                {
                    text = " ";
                }
                SizeF     textSize      = g.MeasureString(text, this.Font);
                SizeF     hoverTextSize = g.MeasureString(text, this.HoverFont);
                Rectangle rect          = new Rectangle(xoffset, yoffset,
                                                        (int)(Math.Max(textSize.Width, hoverTextSize.Width) + 0.5),
                                                        (int)(Math.Max(textSize.Height, hoverTextSize.Height) + 0.5));

                AdjustMenuItemRect(ref rect);
                if (item.Style == FlatMenuItemStyle.Separator)
                {
                    rect.Offset(0, -this.MenuItemSpacing / 2);
                    rect.Height = 3;
                }
                item.ClientRectangle = rect;

                if (item.Style == FlatMenuItemStyle.Separator)
                {
                    yoffset += rect.Height;
                }
                else
                {
                    yoffset += (this.MenuItemSpacing + (int)rect.Height);
                }
            }

            // Now adjust the overall menu size given the updated item sizes.
            AdjustMenuSize();

            // Now adjust each menu item again so that each rect is the
            // same width and extends towards the right border of the menu.
            for (int j = 0; j < this.MenuItems.Count; ++j)
            {
                FlatMenuItem item = this.MenuItems.GetAt(j);
                Rectangle    rect = item.ClientRectangle;
                rect.Width           = this.ClientRectangle.Width - rect.X - 4;
                item.ClientRectangle = rect;
            }
        }
Пример #5
0
        public void AddMenuItems(System.Windows.Forms.ContextMenu m, int x, int y)
        {
            FlatMenuItem curr;
            EventHandler evh;

            // Display Options
            evh  = new EventHandler(DisplayOptions);
            curr = new FlatMenuItem("Display &Options...", null, 0, false);
            parent.AddItem(curr, "Show full &qualified name", ToolBarIcons.show_qual, show_full_qual, evh);
            parent.AddItem(curr, "&Show members", ToolBarIcons.None, show_members, evh);
            m.MenuItems.Add(curr);
        }
Пример #6
0
        /// <summary>
        /// Draw a small arrow indicating the menu item
        /// has a submenu (e.g., child menu items of its own).
        /// </summary>
        /// <param name="g">Graphics object to draw with.</param>
        /// <param name="item">Menu item for which to draw the arrow.</param>
        /// <param name="color">Arrow color.</param>
        private void DrawSubMenuArrow(Graphics g, FlatMenuItem item, Color color)
        {
            int x = item.ClientRectangle.Right - 8;
            int y = item.ClientRectangle.Top + item.ClientRectangle.Height / 2 - 2;

            using (Pen pen = new Pen(color, 0))
            {
                g.DrawLine(pen, x, y, x, y + 4);
                g.DrawLine(pen, x + 1, y + 1, x + 1, y + 3);
                g.DrawLine(pen, x + 2, y + 2, x + 1, y + 2);
            }
        }
Пример #7
0
        /// <summary>
        /// Draw the given menu item.
        /// </summary>
        /// <param name="g">Graphics object to draw with.</param>
        /// <param name="item">Menu item to draw.</param>
        private void DrawMenuItem(Graphics g, FlatMenuItem item)
        {
            if (item.ClientRectangle.Width < 2)
            {
                return;
            }

            if (item.Style == FlatMenuItemStyle.Separator)
            {
                int x  = (item.ClientRectangle.Left + item.ClientRectangle.Right) / 2;
                int y1 = item.ClientRectangle.Top + 3;
                int y2 = item.ClientRectangle.Bottom - 3;
                this.DrawSeparator(g, this.SeparatorColor, x, y1, x, y2);
            }
            else if (this.currMenuItem == item && !this.ignoreNextMouseMove)
            {
                if (this.IsPopupMenuVisible() && this.currMenuItem.MenuItems.Count > 0)
                {
                    this.DrawBackground(g, item.ClientRectangle, this.popupMenu.BackColor);
                    if (this.EnableBorderDrawing)
                    {
                        this.DrawBorder(g, item.ClientRectangle, this.popupMenu.BorderColor);
                    }
                    this.DrawMenuItemTextR(g, item.Text, this.Font, this.popupMenu.TextColor,
                                           item.ClientRectangle);
                }
                else
                {
                    if (this.EnableHoverBackDrawing)
                    {
                        this.DrawBackground(g, item.ClientRectangle, this.HoverBackColor);
                    }
                    if (this.EnableHoverBorderDrawing)
                    {
                        this.DrawBorder(g, item.ClientRectangle, this.HoverBorderColor);
                    }
                    this.DrawMenuItemTextR(g, item.Text, this.HoverFont, this.HoverTextColor,
                                           item.ClientRectangle);
                }
            }
            else
            {
                Color color = this.TextColor;
                if (!item.Enabled)
                {
                    color = this.DisabledTextColor;
                }

                this.DrawMenuItemTextR(g, item.Text, this.Font, color,
                                       item.ClientRectangle);
            }
        }
Пример #8
0
        public void AddMenuItems(System.Windows.Forms.ContextMenu m, int x, int y)
        {
            FlatMenuItem curr;
            EventHandler evh;

            // Style
            curr = new FlatMenuItem("Style", null, 0, false);
            evh  = new EventHandler(ChangeStyleClick);
            parent.AddItem(curr, "Line", ToolBarIcons.straight_conn, this.style == GuiConnectionStyle.Line, evh);
            parent.AddItem(curr, "Segmented", ToolBarIcons.segmented_conn, this.style == GuiConnectionStyle.Segmented, evh);
            parent.AddItem(curr, "Quadric", ToolBarIcons.quadric_conn, this.style == GuiConnectionStyle.Quadric, evh);
            parent.AddItem(curr, "Bezier", ToolBarIcons.curved_conn, this.style == GuiConnectionStyle.Besier, null);
            m.MenuItems.Add(curr);

            // Type
            evh  = new EventHandler(ChangeTypeClick);
            curr = new FlatMenuItem("Type", null, 0, false);
            parent.AddItem(curr, "Inheritance", ToolBarIcons.conn_inher, this.type == UmlRelationType.Inheritance, evh);
            parent.AddItem(curr, "Association", ToolBarIcons.conn_assoc, this.type == UmlRelationType.Association, evh);
            parent.AddItem(curr, "Aggregation", ToolBarIcons.conn_aggregation, this.type == UmlRelationType.Aggregation, evh);
            parent.AddItem(curr, "Composition", ToolBarIcons.conn_composition, this.type == UmlRelationType.Composition, evh);
            parent.AddItem(curr, "Attachment", ToolBarIcons.conn_attachm, this.type == UmlRelationType.Attachment, evh);
            parent.AddItem(curr, "Dependancy/Usage", ToolBarIcons.conn_dependence, this.type == UmlRelationType.Dependency, evh);
            parent.AddItem(curr, "Realization", ToolBarIcons.conn_realiz, this.type == UmlRelationType.Realization, evh);
            m.MenuItems.Add(curr);

            // Navigation
            evh  = new EventHandler(ChangeNavigationClick);
            curr = new FlatMenuItem("Navigation", null, 0, false);
            parent.AddItem(curr, "None", ToolBarIcons.None, this.nav == GuiConnectionNavigation.None, evh);
            parent.AddItem(curr, "Left", ToolBarIcons.None, this.nav == GuiConnectionNavigation.Left, evh);
            parent.AddItem(curr, "Right", ToolBarIcons.None, this.nav == GuiConnectionNavigation.Right, evh);
            curr.Enabled = (this.type == UmlRelationType.Association || this.type == UmlRelationType.Aggregation || this.type == UmlRelationType.Composition);
            m.MenuItems.Add(curr);

            // Display Options
            evh  = new EventHandler(DisplayOptions);
            curr = new FlatMenuItem("Display &Options...", null, 0, false);
            parent.AddItem(curr, "Show roles", ToolBarIcons.None, ShowRoles, evh);
            parent.AddItem(curr, "Show connection name", ToolBarIcons.None, conn_name.Visible, evh);
            parent.AddItem(curr, "Show stereotype", ToolBarIcons.None, conn_stereo.Visible, evh);
            parent.AddItem(curr, "-", ToolBarIcons.None, false, null);
            parent.AddItem(curr, "Show all", ToolBarIcons.None, false, evh);
            parent.AddItem(curr, "Hide all", ToolBarIcons.None, false, evh);
            m.MenuItems.Add(curr);

            parent.AddItem(m, "Hide connection", ToolBarIcons.None, false, new EventHandler(Hide));
        }
Пример #9
0
        /// <summary>
        /// Re-calculate the size of the menu based on the
        /// menu item rects. Then do the resizing as well.
        /// </summary>
        private void AdjustMenuSize()
        {
            if (this.MenuItems.Count == 0)
            {
                return;
            }

            // Compute a new width and height for the menu.
            int newWidth = 80;

            if (this.ParentMenu != null && !this.ParentMenu.IsPopupMenu)
            {
                newWidth = Math.Max(newWidth, this.ParentMenuItem.ClientRectangle.Width + 10);
            }
            int newHeight = 0;

            int  xpad       = 9;
            int  ypad       = 4;
            bool hasSubMenu = false;

            if (this.HasCheckOrRadioItems())
            {
                xpad += FlatPopupMenu.checkAreaWidth + 3;
            }

            for (int i = 0; i < this.MenuItems.Count; ++i)
            {
                FlatMenuItem item = this.MenuItems.GetAt(i);
                newWidth = Math.Max(newWidth, item.ClientRectangle.Width + xpad);
                if (item.MenuItems.Count > 0)
                {
                    hasSubMenu = true;
                }
                newHeight = Math.Max(newHeight, item.ClientRectangle.Bottom);
            }
            if (hasSubMenu)
            {
                newWidth += 10;
            }
            newHeight += ypad;

            // Resize ourselves if needed.
            if (this.ClientRectangle.Width != newWidth ||
                this.ClientRectangle.Height != newHeight)
            {
                this.Size = new Size(newWidth, newHeight);
            }
        }
Пример #10
0
        void TryDropDownMenu(int x, int y, object obj, TreeNode n)
        {
            MenuItem[] mi = null;

            if (obj is UMLDes.GUI.View)
            {
                mi = new FlatMenuItem[] { FlatMenuItem.Create("Rename", null, 0, false, new EventHandler(RenameNode), n) };
            }

            if (mi == null)
            {
                return;
            }
            ContextMenu m = new ContextMenu(mi);

            m.Show(ProjectTree, new Point(x, y));
        }
Пример #11
0
        private void InitializeFlatMenu()
        {
            // File menu item.
            var fileItem = new FlatMenuItem {
                Text = "File"
            };

            var exitItem = new FlatMenuItem {
                Text = "Exit"
            };

            exitItem.Click += (sender, args) => CloseForm();
            fileItem.MenuItems.Add(exitItem);

            flatMenuBar1.MenuItems.Add(fileItem);
            flatMenuBar1.Popup.BackColor = Color.FromArgb(230, 90, 60);
        }
Пример #12
0
        public void AddMenuItems(System.Windows.Forms.ContextMenu m, int x, int y)
        {
            if (!source_dependant)
            {
                parent.AddItem(m, "Rename package", ToolBarIcons.None, false, new EventHandler(Rename_click));
            }

            FlatMenuItem curr;
            EventHandler evh;

            // Display Options
            evh  = new EventHandler(DisplayOptions);
            curr = new FlatMenuItem("Display &Options...", null, 0, false);
            parent.AddItem(curr, "Show full &qualified name", ToolBarIcons.show_qual, show_full_qual, evh);
            parent.AddItem(curr, "&Show members", ToolBarIcons.None, show_members, evh);
            m.MenuItems.Add(curr);

            m.MenuItems.Add(new StereoTypeHelper(this).GetStereoMenu());
        }
Пример #13
0
        /// <summary>
        /// Draw a radio button (if needed).
        /// </summary>
        /// <param name="g">Graphics object to draw with.</param>
        /// <param name="color">Radio button color.</param>
        /// <param name="item">Radio menu item.</param>
        private void DrawRadio(Graphics g, Color color, FlatMenuItem item)
        {
            if (!item.Radio)
            {
                return;
            }

            const int size = 5;

            int x = item.ClientRectangle.X - FlatPopupMenu.checkAreaWidth / 2 - size / 2 - 5;
            int y = item.ClientRectangle.Y + item.ClientRectangle.Height / 2 - size / 2;

            Rectangle r = new Rectangle(x, y, size, size);

            using (Brush brush = new SolidBrush(color))
            {
                g.FillRectangle(brush, r);
            }
        }
Пример #14
0
        /// <summary>
        /// Re-calculate the menu item rects.
        /// </summary>
        /// <param name="g">Graphics object needed to use
        /// MeasureString.</param>
        protected override void RepositionMenuItems(Graphics g)
        {
            int xoffset = this.LeftMargin;
            int yoffset = this.TopMargin;

            for (int i = 0; i < this.MenuItems.Count; ++i)
            {
                FlatMenuItem item = this.MenuItems.GetAt(i);
                Debug.Assert(item != null);

                string text = item.Text;
                if (text == String.Empty)
                {
                    text = " ";
                }
                SizeF     textSize      = g.MeasureString(text, this.Font);
                SizeF     hoverTextSize = g.MeasureString(text, this.HoverFont);
                Rectangle rect          = new Rectangle(xoffset, yoffset,
                                                        (int)(Math.Max(textSize.Width, hoverTextSize.Width) + 0.5),
                                                        (int)(Math.Max(textSize.Height, hoverTextSize.Height) + 0.5));

                AdjustMenuItemRect(ref rect);
                if (item.Style == FlatMenuItemStyle.Separator)
                {
                    rect.Offset(-this.MenuItemSpacing / 2, 0);
                    rect.Width = 3;
                }
                item.ClientRectangle = rect;

                if (item.Style == FlatMenuItemStyle.Separator)
                {
                    xoffset += rect.Width;
                }
                else
                {
                    xoffset += (this.MenuItemSpacing + rect.Width);
                }
            }
        }
Пример #15
0
        /// <summary>
        /// Draw a checkmark.
        /// </summary>
        /// <param name="g">Graphics object to draw with.</param>
        /// <param name="color">Color for the checkmark.</param>
        /// <param name="item">Checked menu item.</param>
        private void DrawCheck(Graphics g, Color color, FlatMenuItem item)
        {
            const int size = 11;

            int x = item.ClientRectangle.X - FlatPopupMenu.checkAreaWidth - 3;
            int y = item.ClientRectangle.Y + item.ClientRectangle.Height / 2 - size / 2;

            Rectangle r = new Rectangle(x, y, size, size);

            this.DrawBackground(g, r, this.BackColor);

            using (Pen pen = new Pen(color, 0))
            {
                g.DrawRectangle(pen, r);
                if (item.Checked)
                {
                    SmoothingMode oldMode = g.SmoothingMode;
                    g.SmoothingMode = SmoothingMode.AntiAlias;
                    g.DrawLine(pen, x + 2, y + 7, x + 4, y + 9);
                    g.DrawLine(pen, x + 4, y + 9, x + 9, y + 4);
                    g.SmoothingMode = oldMode;
                }
            }
        }
Пример #16
0
        /// <summary>
        /// Draw the given menu item.
        /// </summary>
        /// <param name="g">Graphics object to draw with.</param>
        /// <param name="item">Menu item to draw.</param>
        private void DrawMenuItem(Graphics g, FlatMenuItem item)
        {
            if (item.ClientRectangle.Width < 2)
            {
                return;
            }

            if (item.Style == FlatMenuItemStyle.Separator)
            {
                // Draw separator.
                int y  = (item.ClientRectangle.Top + item.ClientRectangle.Bottom) / 2;
                int x1 = item.ClientRectangle.Left;
                int x2 = item.ClientRectangle.Right - 1;
                this.DrawSeparator(g, this.SeparatorColor, x1, y, x2, y);
            }
            else
            {
                // Draw checkmark or radio indicator if needed.
                Color tcolor = this.TextColor;
                if (!item.Enabled)
                {
                    tcolor = this.DisabledTextColor;
                }
                if (item.Style == FlatMenuItemStyle.Check)
                {
                    this.DrawCheck(g, tcolor, item);
                }
                else if (item.Style == FlatMenuItemStyle.Radio)
                {
                    this.DrawRadio(g, tcolor, item);
                }

                // Draw the text portion of menu item.
                if (this.currMenuItem == item)
                {
                    // Draw text in hover state.
                    if (this.EnableHoverBackDrawing)
                    {
                        this.DrawBackground(g, item.ClientRectangle, this.HoverBackColor);
                    }
                    if (this.EnableHoverBorderDrawing)
                    {
                        this.DrawBorder(g, item.ClientRectangle, this.HoverBorderColor);
                    }
                    this.DrawMenuItemTextR(g, item.Text, this.HoverFont, this.HoverTextColor,
                                           item.ClientRectangle);
                    if (item.MenuItems.Count > 0)
                    {
                        this.DrawSubMenuArrow(g, item, this.HoverTextColor);
                    }
                }
                else
                {
                    // Draw text in regular, unhighlighted state.
                    this.DrawMenuItemTextR(g, item.Text, this.Font, tcolor,
                                           item.ClientRectangle);
                    if (item.MenuItems.Count > 0)
                    {
                        this.DrawSubMenuArrow(g, item, tcolor);
                    }
                }
            }
        }