LayoutToolbar.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347
  1. using System;
  2. using System.IO;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using System.Windows.Forms;
  6. using System.Drawing;
  7. using System.ComponentModel;
  8. using FastReport.Utils;
  9. #if !MONO
  10. using FastReport.DevComponents.DotNetBar;
  11. #endif
  12. namespace FastReport.Design.Toolbars
  13. {
  14. internal class LayoutToolbar : ToolbarBase
  15. {
  16. #region Fields
  17. #if !MONO
  18. public ButtonItem btnAlignToGrid;
  19. public ButtonItem btnLeft;
  20. public ButtonItem btnCenter;
  21. public ButtonItem btnRight;
  22. public ButtonItem btnTop;
  23. public ButtonItem btnMiddle;
  24. public ButtonItem btnBottom;
  25. public ButtonItem btnSameWidth;
  26. public ButtonItem btnSameHeight;
  27. public ButtonItem btnSameSize;
  28. public ButtonItem btnSizeToGrid;
  29. public ButtonItem btnSpaceHorizontally;
  30. public ButtonItem btnIncreaseHorizontalSpacing;
  31. public ButtonItem btnDecreaseHorizontalSpacing;
  32. public ButtonItem btnRemoveHorizontalSpacing;
  33. public ButtonItem btnSpaceVertically;
  34. public ButtonItem btnIncreaseVerticalSpacing;
  35. public ButtonItem btnDecreaseVerticalSpacing;
  36. public ButtonItem btnRemoveVerticalSpacing;
  37. public ButtonItem btnCenterHorizontally;
  38. public ButtonItem btnCenterVertically;
  39. public ButtonItem btnBringToFront;
  40. public ButtonItem btnSendToBack;
  41. #else
  42. public ToolStripButton btnAlignToGrid;
  43. public ToolStripButton btnLeft;
  44. public ToolStripButton btnCenter;
  45. public ToolStripButton btnRight;
  46. public ToolStripButton btnTop;
  47. public ToolStripButton btnMiddle;
  48. public ToolStripButton btnBottom;
  49. public ToolStripButton btnSameWidth;
  50. public ToolStripButton btnSameHeight;
  51. public ToolStripButton btnSameSize;
  52. public ToolStripButton btnSizeToGrid;
  53. public ToolStripButton btnSpaceHorizontally;
  54. public ToolStripButton btnIncreaseHorizontalSpacing;
  55. public ToolStripButton btnDecreaseHorizontalSpacing;
  56. public ToolStripButton btnRemoveHorizontalSpacing;
  57. public ToolStripButton btnSpaceVertically;
  58. public ToolStripButton btnIncreaseVerticalSpacing;
  59. public ToolStripButton btnDecreaseVerticalSpacing;
  60. public ToolStripButton btnRemoveVerticalSpacing;
  61. public ToolStripButton btnCenterHorizontally;
  62. public ToolStripButton btnCenterVertically;
  63. public ToolStripButton btnBringToFront;
  64. public ToolStripButton btnSendToBack;
  65. #endif
  66. #endregion
  67. #region Private Methods
  68. private void UpdateControls()
  69. {
  70. bool oneObjSelected = Designer.SelectedComponents.Count > 0;
  71. bool threeObjSelected = Designer.SelectedComponents.Count >= 3;
  72. bool severalObjSelected = Designer.SelectedComponents.Count > 1;
  73. bool canChangeOrder = Designer.SelectedComponents.Count > 0 &&
  74. Designer.SelectedComponents.First.HasFlag(Flags.CanChangeOrder);
  75. bool canMove = Designer.SelectedComponents.Count > 0 &&
  76. Designer.SelectedComponents.First.HasFlag(Flags.CanMove);
  77. bool canResize = Designer.SelectedComponents.Count > 0 &&
  78. Designer.SelectedComponents.First.HasFlag(Flags.CanResize);
  79. btnAlignToGrid.Enabled = oneObjSelected && canMove;
  80. btnLeft.Enabled = severalObjSelected && canMove;
  81. btnCenter.Enabled = severalObjSelected && canMove;
  82. btnRight.Enabled = severalObjSelected && canMove;
  83. btnTop.Enabled = severalObjSelected && canMove;
  84. btnMiddle.Enabled = severalObjSelected && canMove;
  85. btnBottom.Enabled = severalObjSelected && canMove;
  86. btnSameWidth.Enabled = severalObjSelected && canResize;
  87. btnSameHeight.Enabled = severalObjSelected && canResize;
  88. btnSameSize.Enabled = severalObjSelected && canResize;
  89. btnSizeToGrid.Enabled = oneObjSelected && canResize;
  90. btnSpaceHorizontally.Enabled = threeObjSelected && canMove;
  91. btnIncreaseHorizontalSpacing.Enabled = severalObjSelected && canMove;
  92. btnDecreaseHorizontalSpacing.Enabled = severalObjSelected && canMove;
  93. btnRemoveHorizontalSpacing.Enabled = severalObjSelected && canMove;
  94. btnSpaceVertically.Enabled = threeObjSelected && canMove;
  95. btnIncreaseVerticalSpacing.Enabled = severalObjSelected && canMove;
  96. btnDecreaseVerticalSpacing.Enabled = severalObjSelected && canMove;
  97. btnRemoveVerticalSpacing.Enabled = severalObjSelected && canMove;
  98. btnCenterHorizontally.Enabled = oneObjSelected && canMove;
  99. btnCenterVertically.Enabled = oneObjSelected && canMove;
  100. btnBringToFront.Enabled = canChangeOrder;
  101. btnSendToBack.Enabled = canChangeOrder;
  102. }
  103. private void btnAlignToGrid_Click(object sender, EventArgs e)
  104. {
  105. Designer.SelectedComponents.AlignToGrid();
  106. }
  107. private void btnLeft_Click(object sender, EventArgs e)
  108. {
  109. Designer.SelectedComponents.AlignLeft();
  110. }
  111. private void btnCenter_Click(object sender, EventArgs e)
  112. {
  113. Designer.SelectedComponents.AlignCenter();
  114. }
  115. private void btnRight_Click(object sender, EventArgs e)
  116. {
  117. Designer.SelectedComponents.AlignRight();
  118. }
  119. private void btnTop_Click(object sender, EventArgs e)
  120. {
  121. Designer.SelectedComponents.AlignTop();
  122. }
  123. private void btnMiddle_Click(object sender, EventArgs e)
  124. {
  125. Designer.SelectedComponents.AlignMiddle();
  126. }
  127. private void btnBottom_Click(object sender, EventArgs e)
  128. {
  129. Designer.SelectedComponents.AlignBottom();
  130. }
  131. private void btnSameWidth_Click(object sender, EventArgs e)
  132. {
  133. Designer.SelectedComponents.SameWidth();
  134. }
  135. private void btnSameHeight_Click(object sender, EventArgs e)
  136. {
  137. Designer.SelectedComponents.SameHeight();
  138. }
  139. private void btnSameSize_Click(object sender, EventArgs e)
  140. {
  141. Designer.SelectedComponents.SameSize();
  142. }
  143. private void btnCenterHorizontally_Click(object sender, EventArgs e)
  144. {
  145. Designer.SelectedComponents.CenterHorizontally();
  146. }
  147. private void btnCenterVertically_Click(object sender, EventArgs e)
  148. {
  149. Designer.SelectedComponents.CenterVertically();
  150. }
  151. private void btnSizeToGrid_Click(object sender, EventArgs e)
  152. {
  153. Designer.SelectedComponents.SizeToGrid();
  154. }
  155. private void btnSpaceHorizontally_Click(object sender, EventArgs e)
  156. {
  157. Designer.SelectedComponents.SpaceHorizontally();
  158. }
  159. private void btnIncreaseHorizontalSpacing_Click(object sender, EventArgs e)
  160. {
  161. Designer.SelectedComponents.IncreaseHorizontalSpacing();
  162. }
  163. private void btnDecreaseHorizontalSpacing_Click(object sender, EventArgs e)
  164. {
  165. Designer.SelectedComponents.DecreaseHorizontalSpacing();
  166. }
  167. private void btnRemoveHorizontalSpacing_Click(object sender, EventArgs e)
  168. {
  169. Designer.SelectedComponents.RemoveHorizontalSpacing();
  170. }
  171. private void btnSpaceVertically_Click(object sender, EventArgs e)
  172. {
  173. Designer.SelectedComponents.SpaceVertically();
  174. }
  175. private void btnIncreaseVerticalSpacing_Click(object sender, EventArgs e)
  176. {
  177. Designer.SelectedComponents.IncreaseVerticalSpacing();
  178. }
  179. private void btnDecreaseVerticalSpacing_Click(object sender, EventArgs e)
  180. {
  181. Designer.SelectedComponents.DecreaseVerticalSpacing();
  182. }
  183. private void btnRemoveVerticalSpacing_Click(object sender, EventArgs e)
  184. {
  185. Designer.SelectedComponents.RemoveVerticalSpacing();
  186. }
  187. #endregion
  188. #region Public Methods
  189. public override void SelectionChanged()
  190. {
  191. base.SelectionChanged();
  192. UpdateControls();
  193. }
  194. public override void UpdateContent()
  195. {
  196. base.UpdateContent();
  197. UpdateControls();
  198. }
  199. public override void Localize()
  200. {
  201. base.Localize();
  202. MyRes res = new MyRes("Designer,Toolbar,Layout");
  203. Text = res.Get("");
  204. SetItemText(btnAlignToGrid, res.Get("AlignToGrid"));
  205. SetItemText(btnLeft, res.Get("Left"));
  206. SetItemText(btnCenter, res.Get("Center"));
  207. SetItemText(btnRight, res.Get("Right"));
  208. SetItemText(btnTop, res.Get("Top"));
  209. SetItemText(btnMiddle, res.Get("Middle"));
  210. SetItemText(btnBottom, res.Get("Bottom"));
  211. SetItemText(btnSameWidth, res.Get("SameWidth"));
  212. SetItemText(btnSameHeight, res.Get("SameHeight"));
  213. SetItemText(btnSameSize, res.Get("SameSize"));
  214. SetItemText(btnSizeToGrid, res.Get("SizeToGrid"));
  215. SetItemText(btnSpaceHorizontally, res.Get("SpaceHorizontally"));
  216. SetItemText(btnIncreaseHorizontalSpacing, res.Get("IncreaseHorizontalSpacing"));
  217. SetItemText(btnDecreaseHorizontalSpacing, res.Get("DecreaseHorizontalSpacing"));
  218. SetItemText(btnRemoveHorizontalSpacing, res.Get("RemoveHorizontalSpacing"));
  219. SetItemText(btnSpaceVertically, res.Get("SpaceVertically"));
  220. SetItemText(btnIncreaseVerticalSpacing, res.Get("IncreaseVerticalSpacing"));
  221. SetItemText(btnDecreaseVerticalSpacing, res.Get("DecreaseVerticalSpacing"));
  222. SetItemText(btnRemoveVerticalSpacing, res.Get("RemoveVerticalSpacing"));
  223. SetItemText(btnCenterHorizontally, res.Get("CenterHorizontally"));
  224. SetItemText(btnCenterVertically, res.Get("CenterVertically"));
  225. SetItemText(btnBringToFront, res.Get("BringToFront"));
  226. SetItemText(btnSendToBack, res.Get("SendToBack"));
  227. }
  228. #endregion
  229. public LayoutToolbar(Designer designer)
  230. : base(designer)
  231. {
  232. Name = "LayoutToolbar";
  233. #if !MONO
  234. btnAlignToGrid = CreateButton("btnLayoutAlignToGrid", 98, btnAlignToGrid_Click);
  235. btnSizeToGrid = CreateButton("btnLayoutSizeToGrid", 57, btnSizeToGrid_Click);
  236. btnLeft = CreateButton("btnLayoutLeft", 41, btnLeft_Click);
  237. btnLeft.BeginGroup = true;
  238. btnCenter = CreateButton("btnLayoutCenter", 42, btnCenter_Click);
  239. btnRight = CreateButton("btnLayoutRight", 45, btnRight_Click);
  240. btnTop = CreateButton("btnLayoutTop", 46, btnTop_Click);
  241. btnTop.BeginGroup = true;
  242. btnMiddle = CreateButton("btnLayoutMiddle", 47, btnMiddle_Click);
  243. btnBottom = CreateButton("btnLayoutBottom", 50, btnBottom_Click);
  244. btnSameWidth = CreateButton("btnLayoutSameWidth", 83, btnSameWidth_Click);
  245. btnSameWidth.BeginGroup = true;
  246. btnSameHeight = CreateButton("btnLayoutSameHeight", 84, btnSameHeight_Click);
  247. btnSameSize = CreateButton("btnLayoutSameSize", 91, btnSameSize_Click);
  248. btnSpaceHorizontally = CreateButton("btnLayoutSpaceHorizontally", 44, btnSpaceHorizontally_Click);
  249. btnSpaceHorizontally.BeginGroup = true;
  250. btnIncreaseHorizontalSpacing = CreateButton("btnLayoutIncreaseHorizontalSpacing", 92, btnIncreaseHorizontalSpacing_Click);
  251. btnDecreaseHorizontalSpacing = CreateButton("btnLayoutDecreaseHorizontalSpacing", 93, btnDecreaseHorizontalSpacing_Click);
  252. btnRemoveHorizontalSpacing = CreateButton("btnLayoutRemoveHorizontalSpacing", 94, btnRemoveHorizontalSpacing_Click);
  253. btnSpaceVertically = CreateButton("btnLayoutSpaceVertically", 49, btnSpaceVertically_Click);
  254. btnSpaceVertically.BeginGroup = true;
  255. btnIncreaseVerticalSpacing = CreateButton("btnLayoutIncreaseVerticalSpacing", 95, btnIncreaseVerticalSpacing_Click);
  256. btnDecreaseVerticalSpacing = CreateButton("btnLayoutDecreaseVerticalSpacing", 96, btnDecreaseVerticalSpacing_Click);
  257. btnRemoveVerticalSpacing = CreateButton("btnLayoutRemoveVerticalSpacing", 97, btnRemoveVerticalSpacing_Click);
  258. btnCenterHorizontally = CreateButton("btnLayoutCenterHorizontally", 43, btnCenterHorizontally_Click);
  259. btnCenterHorizontally.BeginGroup = true;
  260. btnCenterVertically = CreateButton("btnLayoutCenterVertically", 48, btnCenterVertically_Click);
  261. btnBringToFront = CreateButton("btnLayoutBringToFront", 14, Designer.cmdBringToFront.Invoke);
  262. btnBringToFront.BeginGroup = true;
  263. btnSendToBack = CreateButton("btnLayoutSendToBack", 15, Designer.cmdSendToBack.Invoke);
  264. Items.AddRange(new BaseItem[] {
  265. btnAlignToGrid, btnSizeToGrid,
  266. btnLeft, btnCenter, btnRight,
  267. btnTop, btnMiddle, btnBottom,
  268. btnSameWidth, btnSameHeight, btnSameSize,
  269. btnSpaceHorizontally, btnIncreaseHorizontalSpacing, btnDecreaseHorizontalSpacing, btnRemoveHorizontalSpacing,
  270. btnSpaceVertically, btnIncreaseVerticalSpacing, btnDecreaseVerticalSpacing, btnRemoveVerticalSpacing,
  271. btnCenterHorizontally, btnCenterVertically,
  272. btnBringToFront, btnSendToBack, CustomizeItem });
  273. #else
  274. btnAlignToGrid = CreateButton("btnLayoutAlignToGrid", 98, btnAlignToGrid_Click);
  275. btnSizeToGrid = CreateButton("btnLayoutSizeToGrid", 57, btnSizeToGrid_Click);
  276. btnLeft = CreateButton("btnLayoutLeft", 41, btnLeft_Click);
  277. btnCenter = CreateButton("btnLayoutCenter", 42, btnCenter_Click);
  278. btnRight = CreateButton("btnLayoutRight", 45, btnRight_Click);
  279. btnTop = CreateButton("btnLayoutTop", 46, btnTop_Click);
  280. btnMiddle = CreateButton("btnLayoutMiddle", 47, btnMiddle_Click);
  281. btnBottom = CreateButton("btnLayoutBottom", 50, btnBottom_Click);
  282. btnSameWidth = CreateButton("btnLayoutSameWidth", 83, btnSameWidth_Click);
  283. btnSameHeight = CreateButton("btnLayoutSameHeight", 84, btnSameHeight_Click);
  284. btnSameSize = CreateButton("btnLayoutSameSize", 91, btnSameSize_Click);
  285. btnSpaceHorizontally = CreateButton("btnLayoutSpaceHorizontally", 44, btnSpaceHorizontally_Click);
  286. btnIncreaseHorizontalSpacing = CreateButton("btnLayoutIncreaseHorizontalSpacing", 92, btnIncreaseHorizontalSpacing_Click);
  287. btnDecreaseHorizontalSpacing = CreateButton("btnLayoutDecreaseHorizontalSpacing", 93, btnDecreaseHorizontalSpacing_Click);
  288. btnRemoveHorizontalSpacing = CreateButton("btnLayoutRemoveHorizontalSpacing", 94, btnRemoveHorizontalSpacing_Click);
  289. btnSpaceVertically = CreateButton("btnLayoutSpaceVertically", 49, btnSpaceVertically_Click);
  290. btnIncreaseVerticalSpacing = CreateButton("btnLayoutIncreaseVerticalSpacing", 95, btnIncreaseVerticalSpacing_Click);
  291. btnDecreaseVerticalSpacing = CreateButton("btnLayoutDecreaseVerticalSpacing", 96, btnDecreaseVerticalSpacing_Click);
  292. btnRemoveVerticalSpacing = CreateButton("btnLayoutRemoveVerticalSpacing", 97, btnRemoveVerticalSpacing_Click);
  293. btnCenterHorizontally = CreateButton("btnLayoutCenterHorizontally", 43, btnCenterHorizontally_Click);
  294. btnCenterVertically = CreateButton("btnLayoutCenterVertically", 48, btnCenterVertically_Click);
  295. btnBringToFront = CreateButton("btnLayoutBringToFront", 14, Designer.cmdBringToFront.Invoke);
  296. btnSendToBack = CreateButton("btnLayoutSendToBack", 15, Designer.cmdSendToBack.Invoke);
  297. Items.AddRange(new ToolStripItem[] {
  298. btnAlignToGrid, btnSizeToGrid, new ToolStripSeparator(),
  299. btnLeft, btnCenter, btnRight, new ToolStripSeparator(),
  300. btnTop, btnMiddle, btnBottom, new ToolStripSeparator(),
  301. btnSameWidth, btnSameHeight, btnSameSize, new ToolStripSeparator(),
  302. btnSpaceHorizontally, btnIncreaseHorizontalSpacing, btnDecreaseHorizontalSpacing, btnRemoveHorizontalSpacing, new ToolStripSeparator(),
  303. btnSpaceVertically, btnIncreaseVerticalSpacing, btnDecreaseVerticalSpacing, btnRemoveVerticalSpacing, new ToolStripSeparator(),
  304. btnCenterHorizontally, btnCenterVertically, new ToolStripSeparator(),
  305. btnBringToFront, btnSendToBack });
  306. #endif
  307. Localize();
  308. UpdateDpiDependencies();
  309. }
  310. }
  311. }