ToolbarBase.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. using FastReport.Design;
  2. using FastReport.DevComponents.DotNetBar;
  3. using FastReport.Utils;
  4. using System.ComponentModel;
  5. namespace FastReport.Controls
  6. {
  7. /// <summary>
  8. /// Base class for all toolbars.
  9. /// </summary>
  10. [ToolboxItem(false)]
  11. public class ToolbarBase : Bar
  12. {
  13. #region Properties
  14. /// <summary>
  15. /// Gets the report designer.
  16. /// </summary>
  17. public Designer Designer { get; }
  18. private bool _fixed;
  19. /// <summary>
  20. /// Gets or sets a value that determines whether the toolbar is fixed, i.e. can't float.
  21. /// </summary>
  22. public bool Fixed
  23. {
  24. get => _fixed;
  25. set
  26. {
  27. _fixed = value;
  28. if (_fixed)
  29. {
  30. GrabHandleStyle = eGrabHandleStyle.None;
  31. RoundCorners = false;
  32. }
  33. else
  34. {
  35. GrabHandleStyle = eGrabHandleStyle.Office2003;
  36. RoundCorners = true;
  37. }
  38. }
  39. }
  40. internal CustomizeItem CustomizeItem { get; }
  41. #endregion
  42. #region Public Methods
  43. /// <summary>
  44. /// Updates UI style of the toolbar.
  45. /// </summary>
  46. public virtual void UpdateUIStyle()
  47. {
  48. Style = UIStyleUtils.GetDotNetBarStyle(Designer.UIStyle);
  49. }
  50. /// <summary>
  51. /// Updates layout on dpi change.
  52. /// </summary>
  53. public new virtual void UpdateDpiDependencies()
  54. {
  55. SuspendLayout();
  56. Font = Designer.LogicalToDevice(DrawUtils.DefaultFont);
  57. base.UpdateDpiDependencies();
  58. foreach (BaseItem item in Items)
  59. {
  60. ButtonItem b = item as ButtonItem;
  61. if (b != null && b.ImageIndex != -1)
  62. {
  63. // looks like this is the only way to completely refresh the image displayed (including disabled images).
  64. b.Image = Designer.GetImage(b.ImageIndex);
  65. }
  66. }
  67. ResumeLayout();
  68. }
  69. internal void SetItemText(BaseItem item, string text)
  70. {
  71. item.Tooltip = text;
  72. item.Text = text;
  73. }
  74. /// <summary>
  75. /// Adds items to this toolbar.
  76. /// </summary>
  77. /// <param name="items">Items to add.</param>
  78. public void AddItems(params IToolbarItem[] items)
  79. {
  80. foreach (var item in items)
  81. {
  82. Items.Add(item as BaseItem);
  83. }
  84. if (!Fixed)
  85. Items.Add(CustomizeItem);
  86. }
  87. #endregion
  88. /// <summary>
  89. /// Initializes a new instance of the <see cref="ToolbarBase"/> class with default settings.
  90. /// </summary>
  91. /// <param name="designer">The report designer.</param>
  92. public ToolbarBase(Designer designer) : base()
  93. {
  94. Designer = designer;
  95. GrabHandleStyle = eGrabHandleStyle.Office2003;
  96. CustomizeItem = new CustomizeItem();
  97. CustomizeItem.CustomizeItemVisible = false;
  98. }
  99. }
  100. }