ToolbarItems.cs 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. using FastReport.Design;
  2. using FastReport.DevComponents.DotNetBar;
  3. using FastReport.DevComponents.DotNetBar.Controls;
  4. using FastReport.Utils;
  5. using System;
  6. using System.Drawing;
  7. using System.Windows.Forms;
  8. namespace FastReport.Controls
  9. {
  10. public interface IToolbarItem
  11. {
  12. bool BeginGroup { get; set; }
  13. }
  14. public class ToolbarButton : ButtonItem, IToolbarItem
  15. {
  16. public bool CheckOnClick { get => AutoCheckOnClick; set => AutoCheckOnClick = value; }
  17. public string ToolTipText { get => Tooltip; set => Tooltip = value; }
  18. public ToolbarButton(string name, int imageIndex, EventHandler click)
  19. {
  20. Name = name;
  21. ImageIndex = imageIndex;
  22. Click += click;
  23. }
  24. }
  25. public class ToolbarDropDownButton : ButtonItem, IToolbarItem
  26. {
  27. /// <summary>
  28. /// Not relevant to this class.
  29. /// </summary>
  30. public Font Font { get; set; }
  31. /// <summary>
  32. /// Updates dropdown images on dpi change.
  33. /// </summary>
  34. /// <param name="designer">The designer.</param>
  35. public void UpdateDpiDependencies(Designer designer)
  36. {
  37. foreach (BaseItem item in SubItems)
  38. {
  39. ButtonItem b = item as ButtonItem;
  40. if (b != null && b.ImageIndex != -1)
  41. {
  42. // looks like this is the only way to completely refresh the image displayed (including disabled images).
  43. b.Image = designer.GetImage(b.ImageIndex);
  44. }
  45. }
  46. }
  47. /// <summary>
  48. /// Adds items to the dropdown menu.
  49. /// </summary>
  50. /// <param name="items">Items to add.</param>
  51. public void AddDropDownItems(params IToolbarItem[] items)
  52. {
  53. foreach (var item in items)
  54. {
  55. SubItems.Add(item as BaseItem);
  56. }
  57. }
  58. public ToolbarDropDownButton(string name, int imageIndex, EventHandler dropDownOpening)
  59. {
  60. Name = name;
  61. AutoExpandOnClick = true;
  62. ImageIndex = imageIndex;
  63. PopupOpen += (s, e) => dropDownOpening?.Invoke(this, EventArgs.Empty);
  64. }
  65. }
  66. internal class ToolbarColorButton : ColorButtonItem, IToolbarItem
  67. {
  68. public event EventHandler ButtonClick;
  69. public ToolbarColorButton(string name, int imageIndex, Color color, EventHandler click) : base(imageIndex, color)
  70. {
  71. Name = name;
  72. Click += click;
  73. }
  74. }
  75. internal class ToolbarLineWidthButton : LineWidthButtonItem, IToolbarItem
  76. {
  77. public ToolbarLineWidthButton(Control control, string name, int imageIndex, EventHandler widthSelected) : base()
  78. {
  79. Name = name;
  80. ImageIndex = imageIndex;
  81. WidthSelected += widthSelected;
  82. }
  83. }
  84. internal class ToolbarLineStyleButton : LineStyleButtonItem, IToolbarItem
  85. {
  86. public ToolbarLineStyleButton(Control control, string name, int imageIndex, EventHandler styleSelected) : base()
  87. {
  88. Name = name;
  89. ImageIndex = imageIndex;
  90. StyleSelected += styleSelected;
  91. }
  92. }
  93. internal class ToolbarOpenButton : OpenButtonItem, IToolbarItem
  94. {
  95. public ToolbarOpenButton(Designer designer, string name, int imageIndex) : base(designer)
  96. {
  97. Name = name;
  98. ImageIndex = imageIndex;
  99. }
  100. }
  101. internal class ToolbarUndoButton : UndoButtonItem, IToolbarItem
  102. {
  103. public ToolbarUndoButton(Designer designer, string name, int imageIndex) : base(designer)
  104. {
  105. Name = name;
  106. ImageIndex = imageIndex;
  107. }
  108. }
  109. internal class ToolbarRedoButton : RedoButtonItem, IToolbarItem
  110. {
  111. public ToolbarRedoButton(Designer designer, string name, int imageIndex) : base(designer)
  112. {
  113. Name = name;
  114. ImageIndex = imageIndex;
  115. }
  116. }
  117. internal class ToolbarStyleComboBox : StyleComboBoxItem, IToolbarItem
  118. {
  119. public int Width { get => ComboWidth; set => ComboWidth = value; }
  120. public ToolbarStyleComboBox(string name, EventHandler styleSelected)
  121. {
  122. Name = name;
  123. StyleSelected += styleSelected;
  124. }
  125. }
  126. internal class ToolbarFontComboBox : FontComboBoxItem, IToolbarItem
  127. {
  128. public int Width { get => ComboWidth; set => ComboWidth = value; }
  129. public ToolbarFontComboBox(string name, EventHandler fontSelected)
  130. {
  131. Name = name;
  132. FontSelected += fontSelected;
  133. }
  134. }
  135. internal class ToolbarFontSizeComboBox : FontSizeComboBoxItem, IToolbarItem
  136. {
  137. public int Width { get => ComboWidth; set => ComboWidth = value; }
  138. public ToolbarFontSizeComboBox(string name, EventHandler sizeSelected)
  139. {
  140. Name = name;
  141. SizeSelected += sizeSelected;
  142. }
  143. }
  144. internal class ToolbarTextAngleButton : TextAngleButtonItem, IToolbarItem
  145. {
  146. public ToolbarTextAngleButton(Designer designer, Control owner, string name, int imageIndex, EventHandler angleSelected) : base()
  147. {
  148. Name = name;
  149. ImageIndex = imageIndex;
  150. AngleChanged += angleSelected;
  151. }
  152. }
  153. internal class StyledComboBox : ComboBoxEx
  154. {
  155. public void SetStyle(UIStyle style)
  156. {
  157. Style = UIStyleUtils.GetDotNetBarStyle(style);
  158. }
  159. public StyledComboBox()
  160. {
  161. DisableInternalDrawing = true;
  162. }
  163. }
  164. internal class StyledListView : ListViewEx
  165. {
  166. public void SetStyle(UIStyle style)
  167. {
  168. }
  169. }
  170. }