using System; using System.Windows.Forms; using System.Drawing; using System.ComponentModel; using FastReport.Design; using FastReport.Utils; #if !MONO using FastReport.DevComponents.DotNetBar; #endif namespace FastReport { /// /// The base class for the context menu item. /// [ToolboxItem(false)] public class ContextMenuItem #if !MONO : ButtonItem { /// /// Gets a collection of menu items. /// public SubItemsCollection DropDownItems { get { return SubItems; } } /// /// Gets or sets "Check on click" property. /// public bool CheckOnClick { get { return AutoCheckOnClick; } set { AutoCheckOnClick = value; } } /// /// Sets bold font. /// public void SetFontBold() { FontBold = true; HotFontBold = true; } } #else : ToolStripMenuItem { private bool beginGroup; private bool visibleInternal = true; /// /// Gets or sets a value indicating that a separator is needed before this menu item. /// public bool BeginGroup { get { return beginGroup; } set { beginGroup = value; } } /// /// Gets or sets the internal visibility value. /// public new bool Visible { // Visible flag is always false when menu is not displayed get { return visibleInternal; } set { visibleInternal = value; base.Visible = value; } } /// /// Sets bold font. /// public void SetFontBold() { Font = new Font(Font, FontStyle.Bold); } } #endif /// /// The base class for the context menu of the report component. /// /// /// This class represents a context menu of the report component that is displayed when the object /// is right-clicked in the designer. /// [ToolboxItem(false)] public class ContextMenuBase #if !MONO : ContextMenuBar #else : ContextMenuStrip #endif { #region Fields private Designer designer; #if !MONO private ContextMenuItem mnuContextRoot; #endif #endregion #region Properties /// /// The reference to the report designer. /// public Designer Designer { get { return designer; } } #if !MONO /// /// Gets a collection of menu items. /// /// /// You should add new items to this collection. /// public new SubItemsCollection Items { get { return mnuContextRoot.SubItems; } } #endif #endregion #region Private Methods #endregion #region Protected Methods /// /// This method is called to reflect changes in the designer. /// protected virtual void Change() { Designer.SetModified(null, "Change"); } /// /// Creates a new menu item. /// /// Item's text. /// New item. protected ContextMenuItem CreateMenuItem(string text) { return CreateMenuItem(-1, text, null); } /// /// Creates a new menu item. /// /// Item's text. /// Click handler. /// New item. protected ContextMenuItem CreateMenuItem(string text, EventHandler click) { return CreateMenuItem(-1, text, click); } /// /// Creates a new menu item. /// /// Item's image index. /// Item's text. /// Click handler. /// New item. protected ContextMenuItem CreateMenuItem(int imageIndex, string text, EventHandler click) { ContextMenuItem item = new ContextMenuItem(); if (imageIndex != -1) item.Image = Designer.GetImage(imageIndex); item.Text = text; #if MONO item.Font = DrawUtils.DefaultFont; // workaround Mono behavior #endif if (click != null) item.Click += click; return item; } #endregion #if !MONO /// /// Displays context menu. /// /// Parent control. /// Location. public void Show(Control parent, Point location) { mnuContextRoot.PopupMenu(parent.PointToScreen(location)); } #else /// /// Displays context menu. /// /// Parent control. /// Location. public new void Show(Control parent, Point location) { // convert item.BeginGroup to a separator for (int i = 0; i < Items.Count; i++) { ContextMenuItem item = Items[i] as ContextMenuItem; if (i > 0 && item != null && item.Visible && item.BeginGroup) { Items.Insert(i, new ToolStripSeparator()); i++; } } base.Show(parent, location); } #endif /// /// Initializes a new instance of the ComponentBaseMenu class with default settings. /// /// The reference to a report designer. public ContextMenuBase(Designer designer) : base() { this.designer = designer; #if !MONO Style = UIStyleUtils.GetDotNetBarStyle(Designer.UIStyle); Font = Designer.LogicalToDevice(DrawUtils.DefaultFont); mnuContextRoot = new ContextMenuItem(); base.Items.Add(mnuContextRoot); #else Font = DrawUtils.DefaultFont; Renderer = UIStyleUtils.GetToolStripRenderer(Designer.UIStyle); #endif } } }