using FastReport.Design; using FastReport.Utils; using System.ComponentModel; using System.Windows.Forms; namespace FastReport.Controls { /// /// Base class for all toolbars. /// [ToolboxItem(false)] public class ToolbarBase : ToolStrip { #region Properties /// /// Gets the report designer. /// public Designer Designer { get; } private bool _fixed; /// /// Gets or sets a value that determines whether the toolbar is fixed, i.e. can't float. /// public bool Fixed { get => _fixed; set { _fixed = value; if (_fixed) { AutoSize = false; GripStyle = ToolStripGripStyle.Hidden; } else { AutoSize = true; GripStyle = ToolStripGripStyle.Visible; } } } #endregion #region Public Methods internal void SetItemText(ToolStripItem item, string text) { item.ToolTipText = text; item.Text = text; } /// /// Adds items to this toolbar. /// /// Items to add. public void AddItems(params IToolbarItem[] items) { // convert item.BeginGroup to a separator foreach (var item in items) { if (item.BeginGroup && Items.Count > 0) Items.Add(new ToolStripSeparator()); Items.Add(item as ToolStripItem); } } /// public virtual void UpdateUIStyle() { Renderer = UIStyleUtils.GetToolStripRenderer(Designer.UIStyle); } /// public virtual void UpdateDpiDependencies() { SuspendLayout(); Font = Designer.LogicalToDevice(DrawUtils.DefaultFont); foreach (ToolStripItem item in Items) { #if (WPF || AVALONIA) if (item.DisplayStyle == ToolStripItemDisplayStyle.Image) { if (item is ToolStripButton) { item.AutoSize = false; item.Size = Designer.LogicalToDevice(new System.Drawing.Size(23, 22)); } if (item is ToolStripSplitButton || item is ToolStripDropDownButton) { item.AutoSize = false; item.Size = Designer.LogicalToDevice(new System.Drawing.Size(35, 22)); } } #endif if (item.ImageIndex != -1) item.Image = Designer.GetImage(item.ImageIndex); // note this will reset the ImageIndex. Not an issue in WPF/Avalonia } ResumeLayout(); } #endregion /// /// Initializes a new instance of the class with default settings. /// /// The report designer. public ToolbarBase(Designer designer) : base() { Designer = designer; Dock = DockStyle.None; AutoSize = true; } } }