123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- using FastReport.Design;
- using FastReport.DevComponents.DotNetBar;
- using FastReport.Utils;
- using System.ComponentModel;
- namespace FastReport.Controls
- {
- /// <summary>
- /// Base class for all toolbars.
- /// </summary>
- [ToolboxItem(false)]
- public class ToolbarBase : Bar
- {
- #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)
- {
- GrabHandleStyle = eGrabHandleStyle.None;
- RoundCorners = false;
- }
- else
- {
- GrabHandleStyle = eGrabHandleStyle.Office2003;
- RoundCorners = true;
- }
- }
- }
- internal CustomizeItem CustomizeItem { get; }
- #endregion
- #region Public Methods
- /// <summary>
- /// Updates UI style of the toolbar.
- /// </summary>
- public virtual void UpdateUIStyle()
- {
- Style = UIStyleUtils.GetDotNetBarStyle(Designer.UIStyle);
- }
- /// <summary>
- /// Updates layout on dpi change.
- /// </summary>
- public new virtual void UpdateDpiDependencies()
- {
- SuspendLayout();
- Font = Designer.LogicalToDevice(DrawUtils.DefaultFont);
- base.UpdateDpiDependencies();
- foreach (BaseItem item in Items)
- {
- ButtonItem b = item as ButtonItem;
- if (b != null && b.ImageIndex != -1)
- {
- // looks like this is the only way to completely refresh the image displayed (including disabled images).
- b.Image = Designer.GetImage(b.ImageIndex);
- }
- }
- ResumeLayout();
- }
- internal void SetItemText(BaseItem item, string text)
- {
- item.Tooltip = text;
- item.Text = text;
- }
- /// <summary>
- /// Adds items to this toolbar.
- /// </summary>
- /// <param name="items">Items to add.</param>
- public void AddItems(params IToolbarItem[] items)
- {
- foreach (var item in items)
- {
- Items.Add(item as BaseItem);
- }
- if (!Fixed)
- Items.Add(CustomizeItem);
- }
- #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;
- GrabHandleStyle = eGrabHandleStyle.Office2003;
- CustomizeItem = new CustomizeItem();
- CustomizeItem.CustomizeItemVisible = false;
- }
- }
- }
|