123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- using FastReport.Design;
- using FastReport.Utils;
- using System.ComponentModel;
- using System.Windows.Forms;
- namespace FastReport.Controls
- {
- /// <summary>
- /// Base class for all toolbars.
- /// </summary>
- [ToolboxItem(false)]
- public class ToolbarBase : ToolStrip
- {
- #region Properties
- /// <summary>
- /// Gets the report designer.
- /// </summary>
- public Designer Designer { get; }
- private bool _fixed;
- /// <summary>
- /// Gets or sets a value that determines whether the toolbar is fixed, i.e. can't float.
- /// </summary>
- 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;
- }
- /// <summary>
- /// Adds items to this toolbar.
- /// </summary>
- /// <param name="items">Items to add.</param>
- 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);
- }
- }
- /// <inheritdoc/>
- public virtual void UpdateUIStyle()
- {
- Renderer = UIStyleUtils.GetToolStripRenderer(Designer.UIStyle);
- }
- /// <inheritdoc/>
- 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
- /// <summary>
- /// Initializes a new instance of the <see cref="ToolbarBase"/> class with default settings.
- /// </summary>
- /// <param name="designer">The report designer.</param>
- public ToolbarBase(Designer designer) : base()
- {
- Designer = designer;
- Dock = DockStyle.None;
- AutoSize = true;
- }
- }
- }
|