ToolbarBase.Mono.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. using FastReport.Design;
  2. using FastReport.Utils;
  3. using System.ComponentModel;
  4. using System.Windows.Forms;
  5. namespace FastReport.Controls
  6. {
  7. /// <summary>
  8. /// Base class for all toolbars.
  9. /// </summary>
  10. [ToolboxItem(false)]
  11. public class ToolbarBase : ToolStrip
  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. AutoSize = false;
  31. GripStyle = ToolStripGripStyle.Hidden;
  32. }
  33. else
  34. {
  35. AutoSize = true;
  36. GripStyle = ToolStripGripStyle.Visible;
  37. }
  38. }
  39. }
  40. #endregion
  41. #region Public Methods
  42. internal void SetItemText(ToolStripItem item, string text)
  43. {
  44. item.ToolTipText = text;
  45. item.Text = text;
  46. }
  47. /// <summary>
  48. /// Adds items to this toolbar.
  49. /// </summary>
  50. /// <param name="items">Items to add.</param>
  51. public void AddItems(params IToolbarItem[] items)
  52. {
  53. // convert item.BeginGroup to a separator
  54. foreach (var item in items)
  55. {
  56. if (item.BeginGroup && Items.Count > 0)
  57. Items.Add(new ToolStripSeparator());
  58. Items.Add(item as ToolStripItem);
  59. }
  60. }
  61. /// <inheritdoc/>
  62. public virtual void UpdateUIStyle()
  63. {
  64. Renderer = UIStyleUtils.GetToolStripRenderer(Designer.UIStyle);
  65. }
  66. /// <inheritdoc/>
  67. public virtual void UpdateDpiDependencies()
  68. {
  69. SuspendLayout();
  70. Font = Designer.LogicalToDevice(DrawUtils.DefaultFont);
  71. foreach (ToolStripItem item in Items)
  72. {
  73. #if (WPF || AVALONIA)
  74. if (item.DisplayStyle == ToolStripItemDisplayStyle.Image)
  75. {
  76. if (item is ToolStripButton)
  77. {
  78. item.AutoSize = false;
  79. item.Size = Designer.LogicalToDevice(new System.Drawing.Size(23, 22));
  80. }
  81. if (item is ToolStripSplitButton || item is ToolStripDropDownButton)
  82. {
  83. item.AutoSize = false;
  84. item.Size = Designer.LogicalToDevice(new System.Drawing.Size(35, 22));
  85. }
  86. }
  87. #endif
  88. if (item.ImageIndex != -1)
  89. item.Image = Designer.GetImage(item.ImageIndex); // note this will reset the ImageIndex. Not an issue in WPF/Avalonia
  90. }
  91. ResumeLayout();
  92. }
  93. #endregion
  94. /// <summary>
  95. /// Initializes a new instance of the <see cref="ToolbarBase"/> class with default settings.
  96. /// </summary>
  97. /// <param name="designer">The report designer.</param>
  98. public ToolbarBase(Designer designer) : base()
  99. {
  100. Designer = designer;
  101. Dock = DockStyle.None;
  102. AutoSize = true;
  103. }
  104. }
  105. }