SelectedReportComponents.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Drawing;
  5. using System.Drawing.Drawing2D;
  6. using FastReport.Design;
  7. using System.Windows.Forms;
  8. using FastReport.Forms;
  9. namespace FastReport
  10. {
  11. /// <summary>
  12. /// Holds the list of <see cref="ReportComponentBase"/> objects currently selected in the designer.
  13. /// </summary>
  14. /// <remarks>
  15. /// This class is used by the "Border and Fill" toolbar. Use methods of this class to perform some
  16. /// operations on the selected objects.
  17. /// <para/>Note: after calling any method in this class, call the
  18. /// <see cref="Designer.SetModified()">Designer.SetModified</see> method to reflect changes.
  19. /// <para/>Note: this list contains only objects of <see cref="ReportComponentBase"/> type.
  20. /// If you want to access all selected objects, use the <see cref="Designer.SelectedObjects"/> property.
  21. /// </remarks>
  22. public class SelectedReportComponents
  23. {
  24. private List<ReportComponentBase> list;
  25. private Designer designer;
  26. /// <summary>
  27. /// Gets the first selected object.
  28. /// </summary>
  29. public ReportComponentBase First
  30. {
  31. get { return list.Count > 0 ? list[0] : null; }
  32. }
  33. /// <summary>
  34. /// Gets the number of selected objects.
  35. /// </summary>
  36. public int Count
  37. {
  38. get { return list.Count; }
  39. }
  40. /// <summary>
  41. /// Gets a value indicating whether the operations are enabled.
  42. /// </summary>
  43. public bool Enabled
  44. {
  45. get
  46. {
  47. return Count > 1 || (Count == 1 && !First.HasRestriction(Restrictions.DontModify));
  48. }
  49. }
  50. /// <summary>
  51. /// Gets a value indicating whether the object with simple border is selected.
  52. /// </summary>
  53. /// <remarks>
  54. /// When the object has a simple border, you cannot change individual border lines.
  55. /// Example of such an object is the "Shape" and "Line" objects.
  56. /// </remarks>
  57. public bool SimpleBorder
  58. {
  59. get
  60. {
  61. foreach (ReportComponentBase c in list)
  62. {
  63. if (!c.FlagSimpleBorder)
  64. return false;
  65. }
  66. return true;
  67. }
  68. }
  69. /// <summary>
  70. /// Gets a value indicating whether the border operations are enabled.
  71. /// </summary>
  72. public bool BorderEnabled
  73. {
  74. get
  75. {
  76. foreach (ReportComponentBase c in list)
  77. {
  78. if (c.FlagUseBorder)
  79. return true;
  80. }
  81. return false;
  82. }
  83. }
  84. /// <summary>
  85. /// Gets a value indicating whether the fill operations are enabled.
  86. /// </summary>
  87. public bool FillEnabled
  88. {
  89. get
  90. {
  91. foreach (ReportComponentBase c in list)
  92. {
  93. if (c.FlagUseFill)
  94. return true;
  95. }
  96. return false;
  97. }
  98. }
  99. private List<ReportComponentBase> ModifyList
  100. {
  101. get { return list.FindAll(CanModify); }
  102. }
  103. private bool CanModify(ReportComponentBase c)
  104. {
  105. return !c.HasRestriction(Restrictions.DontModify);
  106. }
  107. internal void Update()
  108. {
  109. list.Clear();
  110. if (designer.SelectedObjects != null)
  111. {
  112. foreach (Base c in designer.SelectedObjects)
  113. {
  114. if (c is ReportComponentBase)
  115. list.Add(c as ReportComponentBase);
  116. }
  117. }
  118. }
  119. /// <summary>
  120. /// Sets the solid fill color for the selected objects.
  121. /// </summary>
  122. /// <param name="color">Fill color.</param>
  123. public void SetColor(Color color)
  124. {
  125. foreach (ReportComponentBase c in ModifyList)
  126. {
  127. c.Fill = new SolidFill(color);
  128. }
  129. designer.LastFormatting.Fill = new SolidFill(color);
  130. designer.SetModified();
  131. }
  132. /// <summary>
  133. /// Sets the fill for the selected objects.
  134. /// </summary>
  135. /// <param name="fill">Fill.</param>
  136. public void SetFill(FillBase fill)
  137. {
  138. foreach (ReportComponentBase c in ModifyList)
  139. {
  140. c.Fill = fill.Clone();
  141. }
  142. designer.LastFormatting.Fill = fill.Clone();
  143. designer.SetModified();
  144. }
  145. /// <summary>
  146. /// Sets the style for the selected objects.
  147. /// </summary>
  148. /// <param name="style">Style name.</param>
  149. public void SetStyle(string style)
  150. {
  151. foreach (ReportComponentBase c in ModifyList)
  152. {
  153. c.Style = style;
  154. }
  155. designer.SetModified();
  156. }
  157. /// <summary>
  158. /// Sets the hyperlink for the selected objects.
  159. /// </summary>
  160. /// <param name="hyperlink">Hyperlink.</param>
  161. /// <param name="modifyAppearance">Indicates whether to modify the object's appearance.</param>
  162. /// <param name="setModified">Indicates whether it is necessary to change designer's modified state.</param>
  163. public void SetHyperlink(Hyperlink hyperlink, bool modifyAppearance, bool setModified)
  164. {
  165. foreach (ReportComponentBase c in ModifyList)
  166. {
  167. c.Hyperlink.Assign(hyperlink);
  168. if (modifyAppearance)
  169. {
  170. c.Cursor = Cursors.Hand;
  171. if (c is TextObject)
  172. {
  173. (c as TextObject).TextFill = new SolidFill(Color.Blue);
  174. (c as TextObject).Font = new Font((c as TextObject).Font, (c as TextObject).Font.Style | FontStyle.Underline);
  175. }
  176. }
  177. }
  178. if (setModified)
  179. designer.SetModified();
  180. }
  181. /// <summary>
  182. /// Sets the CanGrow flag for the selected objects.
  183. /// </summary>
  184. /// <param name="value">Flag value.</param>
  185. public void SetCanGrow(bool value)
  186. {
  187. foreach (ReportComponentBase c in ModifyList)
  188. {
  189. c.CanGrow = value;
  190. }
  191. designer.SetModified();
  192. }
  193. /// <summary>
  194. /// Sets the CanShrink flag for the selected objects.
  195. /// </summary>
  196. /// <param name="value">Flag value.</param>
  197. public void SetCanShrink(bool value)
  198. {
  199. foreach (ReportComponentBase c in ModifyList)
  200. {
  201. c.CanShrink = value;
  202. }
  203. designer.SetModified();
  204. }
  205. /// <summary>
  206. /// Sets the GrowToBottom flag for the selected objects.
  207. /// </summary>
  208. /// <param name="value">Flag value.</param>
  209. public void SetGrowToBottom(bool value)
  210. {
  211. foreach (ReportComponentBase c in ModifyList)
  212. {
  213. c.GrowToBottom = value;
  214. }
  215. designer.SetModified();
  216. }
  217. /// <summary>
  218. /// Toggles the specified border line for the selected objects.
  219. /// </summary>
  220. /// <param name="line">Border line.</param>
  221. /// <param name="toggle">Toggle value.</param>
  222. public void ToggleLine(BorderLines line, bool toggle)
  223. {
  224. foreach (ReportComponentBase c in ModifyList)
  225. {
  226. if (toggle)
  227. c.Border.Lines |= line;
  228. else
  229. c.Border.Lines &= ~line;
  230. }
  231. designer.LastFormatting.Border.Lines = First.Border.Lines;
  232. designer.SetModified();
  233. }
  234. /// <summary>
  235. /// Sets the border color for the selected objects.
  236. /// </summary>
  237. /// <param name="color">Border color.</param>
  238. public void SetLineColor(Color color)
  239. {
  240. foreach (ReportComponentBase c in ModifyList)
  241. {
  242. c.Border.Color = color;
  243. }
  244. designer.LastFormatting.Border.Color = color;
  245. designer.SetModified();
  246. }
  247. /// <summary>
  248. /// Sets the border width for the selected objects.
  249. /// </summary>
  250. /// <param name="width">Border width.</param>
  251. public void SetWidth(float width)
  252. {
  253. foreach (ReportComponentBase c in ModifyList)
  254. {
  255. c.Border.Width = width;
  256. }
  257. designer.LastFormatting.Border.Width = width;
  258. designer.SetModified();
  259. }
  260. /// <summary>
  261. /// Sets the border style for the selected objects.
  262. /// </summary>
  263. /// <param name="style">Border style.</param>
  264. public void SetLineStyle(LineStyle style)
  265. {
  266. foreach (ReportComponentBase c in ModifyList)
  267. {
  268. c.Border.Style = style;
  269. }
  270. designer.LastFormatting.Border.Style = style;
  271. designer.SetModified();
  272. }
  273. /// <summary>
  274. /// Sets the border for the selected objects.
  275. /// </summary>
  276. /// <param name="border">Border.</param>
  277. public void SetBorder(Border border)
  278. {
  279. foreach (ReportComponentBase c in ModifyList)
  280. {
  281. c.Border = border.Clone();
  282. }
  283. designer.LastFormatting.Border = border.Clone();
  284. designer.SetModified();
  285. }
  286. /// <summary>
  287. /// Invokes the fill editor for the selected objects.
  288. /// </summary>
  289. /// <returns><b>true</b> if editor was closed by the OK button.</returns>
  290. public bool InvokeFillEditor()
  291. {
  292. using (FillEditorForm editor = new FillEditorForm())
  293. {
  294. editor.Fill = First.Fill.Clone();
  295. if (editor.ShowDialog() == DialogResult.OK)
  296. {
  297. SetFill(editor.Fill);
  298. return true;
  299. }
  300. }
  301. return false;
  302. }
  303. /// <summary>
  304. /// Invokes the border editor for the selected objects.
  305. /// </summary>
  306. /// <returns><b>true</b> if editor was closed by the OK button.</returns>
  307. public bool InvokeBorderEditor()
  308. {
  309. using (BorderEditorForm editor = new BorderEditorForm())
  310. {
  311. editor.Border = First.Border.Clone();
  312. if (editor.ShowDialog() == DialogResult.OK)
  313. {
  314. SetBorder(editor.Border);
  315. return true;
  316. }
  317. }
  318. return false;
  319. }
  320. /// <summary>
  321. /// Invokes the hyperlink editor for the selected objects.
  322. /// </summary>
  323. /// <returns><b>true</b> if editor was closed by the OK button.</returns>
  324. public bool InvokeHyperlinkEditor()
  325. {
  326. using (HyperlinkEditorForm form = new HyperlinkEditorForm())
  327. {
  328. form.ReportComponent = First;
  329. if (form.ShowDialog() == DialogResult.OK)
  330. {
  331. SetHyperlink(form.Hyperlink, form.ModifyAppearance, true);
  332. return true;
  333. }
  334. }
  335. return false;
  336. }
  337. internal SelectedReportComponents(Designer designer)
  338. {
  339. this.designer = designer;
  340. list = new List<ReportComponentBase>();
  341. }
  342. }
  343. }