ReportComponentBase.cs 38 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Drawing;
  4. using System.ComponentModel;
  5. using FastReport.Utils;
  6. using System.Windows.Forms;
  7. using System.Drawing.Design;
  8. namespace FastReport
  9. {
  10. /// <summary>
  11. /// The automatic shift mode.
  12. /// </summary>
  13. public enum ShiftMode
  14. {
  15. /// <summary>
  16. /// Do not shift the object.
  17. /// </summary>
  18. Never,
  19. /// <summary>
  20. /// Shift the object up or down if any object above it shrinks or grows.
  21. /// </summary>
  22. Always,
  23. /// <summary>
  24. /// Shift the object up or down if any object above it shrinks or grows.
  25. /// Objects must have overlapped x-coordinates.
  26. /// </summary>
  27. WhenOverlapped
  28. }
  29. /// <summary>
  30. /// Specifies where to print an object.
  31. /// </summary>
  32. [Flags]
  33. [TypeConverter(typeof(FastReport.TypeConverters.FlagConverter))]
  34. public enum PrintOn
  35. {
  36. /// <summary>
  37. /// Do not print the object.
  38. /// </summary>
  39. None = 0,
  40. /// <summary>
  41. /// Print the object on the first page. If this flag is not set, the object will not
  42. /// be printed on the first page.
  43. /// </summary>
  44. FirstPage = 1,
  45. /// <summary>
  46. /// Print the object on the last page. If this flag is not set, the object will not
  47. /// be printed on the last page. You should set the report's double pass option to make
  48. /// it work correctly.
  49. /// </summary>
  50. LastPage = 2,
  51. /// <summary>
  52. /// Print the object on odd pages only.
  53. /// </summary>
  54. OddPages = 4,
  55. /// <summary>
  56. /// Print the object on even pages only.
  57. /// </summary>
  58. EvenPages = 8,
  59. /// <summary>
  60. /// Print the object on band with "Repeat on Every Page" flag when that band is repeated.
  61. /// </summary>
  62. RepeatedBand = 16,
  63. /// <summary>
  64. /// Print the object if the report has single page only.
  65. /// </summary>
  66. SinglePage = 32
  67. }
  68. /// <summary>
  69. /// Specifies the style properties to use when style is applied.
  70. /// </summary>
  71. public enum StylePriority
  72. {
  73. /// <summary>
  74. /// Use the fill property of the style.
  75. /// </summary>
  76. UseFill,
  77. /// <summary>
  78. /// Use all style properties.
  79. /// </summary>
  80. UseAll
  81. }
  82. /// <summary>
  83. /// Base class for all report objects.
  84. /// </summary>
  85. public abstract partial class ReportComponentBase : ComponentBase
  86. {
  87. #region Fields
  88. private bool exportable;
  89. private string exportableExpression;
  90. private Border border;
  91. private FillBase fill;
  92. private string bookmark;
  93. private Hyperlink hyperlink;
  94. private bool canGrow;
  95. private bool canShrink;
  96. private bool growToBottom;
  97. private ShiftMode shiftMode;
  98. private string style;
  99. private string evenStyle;
  100. private string hoverStyle;
  101. private StylePriority evenStylePriority;
  102. private bool pageBreak;
  103. private PrintOn printOn;
  104. private string beforePrintEvent;
  105. private string afterPrintEvent;
  106. private string afterDataEvent;
  107. private string clickEvent;
  108. private bool flagSimpleBorder;
  109. private bool flagUseBorder;
  110. private bool flagUseFill;
  111. private bool flagPreviewVisible;
  112. private bool flagSerializeStyle;
  113. private bool flagProvidesHyperlinkValue;
  114. private RectangleF savedBounds;
  115. private bool savedVisible;
  116. private string savedBookmark;
  117. private Border savedBorder;
  118. private FillBase savedFill;
  119. private Cursor cursor;
  120. private string mouseMoveEvent;
  121. private string mouseUpEvent;
  122. private string mouseDownEvent;
  123. private string mouseEnterEvent;
  124. private string mouseLeaveEvent;
  125. #endregion
  126. #region Properties
  127. /// <summary>
  128. /// This event occurs before the object is added to the preview pages.
  129. /// </summary>
  130. public event EventHandler BeforePrint;
  131. /// <summary>
  132. /// This event occurs after the object was added to the preview pages.
  133. /// </summary>
  134. public event EventHandler AfterPrint;
  135. /// <summary>
  136. /// This event occurs after the object was filled with data.
  137. /// </summary>
  138. public event EventHandler AfterData;
  139. /// <summary>
  140. /// This event occurs when the user clicks the object in the preview window.
  141. /// </summary>
  142. public event EventHandler Click;
  143. /// <summary>
  144. /// Gets or sets a value that determines if the object can be exported.
  145. /// </summary>
  146. [DefaultValue(true)]
  147. [Category("Behavior")]
  148. public bool Exportable
  149. {
  150. get { return exportable; }
  151. set { exportable = value; }
  152. }
  153. /// <summary>
  154. /// Gets or sets a string containing expression that determines should be object exported.
  155. /// </summary>
  156. [DefaultValue("")]
  157. [Category("Behavior")]
  158. [Editor("FastReport.TypeEditors.ExpressionEditor, FastReport", typeof(UITypeEditor))]
  159. public virtual string ExportableExpression
  160. {
  161. get { return exportableExpression; }
  162. set { exportableExpression = value; }
  163. }
  164. /// <summary>
  165. /// Gets or sets an object's border.
  166. /// </summary>
  167. [Category("Appearance")]
  168. public virtual Border Border
  169. {
  170. get { return border; }
  171. set
  172. {
  173. border = value;
  174. if (!String.IsNullOrEmpty(Style))
  175. Style = "";
  176. }
  177. }
  178. /// <summary>
  179. /// Gets or sets an object's fill.
  180. /// </summary>
  181. /// <remarks>
  182. /// The fill can be one of the following types: <see cref="SolidFill"/>, <see cref="LinearGradientFill"/>,
  183. /// <see cref="PathGradientFill"/>, <see cref="HatchFill"/>.
  184. /// <para/>To set the solid fill color, use the simpler <see cref="FillColor"/> property.
  185. /// </remarks>
  186. /// <example>This example shows how to set the new fill and change its properties:
  187. /// <code>
  188. /// textObject1.Fill = new SolidFill(Color.Green);
  189. /// (textObject1.Fill as SolidFill).Color = Color.Red;
  190. /// </code>
  191. /// </example>
  192. [Category("Appearance")]
  193. [EditorAttribute("FastReport.TypeEditors.FillEditor, FastReport", typeof(UITypeEditor))]
  194. public virtual FillBase Fill
  195. {
  196. get
  197. {
  198. return fill;
  199. }
  200. set
  201. {
  202. if (value == null)
  203. throw new ArgumentNullException("Fill");
  204. fill = value;
  205. if (!String.IsNullOrEmpty(Style))
  206. Style = "";
  207. }
  208. }
  209. /// <summary>
  210. /// Gets or sets the fill color in a simple manner.
  211. /// </summary>
  212. /// <remarks>
  213. /// This property can be used in a report script to change the fill color of the object. It is
  214. /// equivalent to: <code>reportComponent1.Fill = new SolidFill(color);</code>
  215. /// </remarks>
  216. [Browsable(false)]
  217. public Color FillColor
  218. {
  219. get { return Fill is SolidFill ? (Fill as SolidFill).Color : Color.Transparent; }
  220. set { Fill = new SolidFill(value); }
  221. }
  222. /// <summary>
  223. /// Gets or sets a bookmark expression.
  224. /// </summary>
  225. /// <remarks>
  226. /// This property can contain any valid expression that returns a bookmark name. This can be, for example,
  227. /// a data column. To navigate to a bookmark, you have to use the <see cref="Hyperlink"/> property.
  228. /// </remarks>
  229. [Category("Navigation")]
  230. [Editor("FastReport.TypeEditors.ExpressionEditor, FastReport", typeof(UITypeEditor))]
  231. public string Bookmark
  232. {
  233. get { return bookmark; }
  234. set { bookmark = value; }
  235. }
  236. /// <summary>
  237. /// Gets or sets a hyperlink.
  238. /// </summary>
  239. /// <remarks>
  240. /// <para>The hyperlink is used to define clickable objects in the preview.
  241. /// When you click such object, you may navigate to the external url, the page number,
  242. /// the bookmark defined by other report object, or display the external report.
  243. /// Set the <b>Kind</b> property of the hyperlink to select appropriate behavior.</para>
  244. /// <para>Usually you should set the <b>Expression</b> property of the hyperlink to
  245. /// any valid expression that will be calculated when this object is about to print.
  246. /// The value of an expression will be used for navigation.</para>
  247. /// <para>If you want to navigate to
  248. /// something fixed (URL or page number, for example) you also may set the <b>Value</b>
  249. /// property instead of <b>Expression</b>.</para>
  250. /// </remarks>
  251. [Category("Navigation")]
  252. [Editor("FastReport.TypeEditors.HyperlinkEditor, FastReport", typeof(UITypeEditor))]
  253. public Hyperlink Hyperlink
  254. {
  255. get { return hyperlink; }
  256. set { hyperlink = value; }
  257. }
  258. /// <summary>
  259. /// Determines if the object can grow.
  260. /// </summary>
  261. /// <remarks>
  262. /// This property is applicable to the bands or text objects that can contain several text lines.
  263. /// If the property is set to <b>true</b>, object will grow to display all the information that it contains.
  264. /// </remarks>
  265. [DefaultValue(false)]
  266. [Category("Behavior")]
  267. public bool CanGrow
  268. {
  269. get { return canGrow; }
  270. set { canGrow = value; }
  271. }
  272. /// <summary>
  273. /// Determines if the object can shrink.
  274. /// </summary>
  275. /// <remarks>
  276. /// This property is applicable to the bands or text objects that can contain several text lines.
  277. /// If the property is set to true, object can shrink to remove the unused space.
  278. /// </remarks>
  279. [DefaultValue(false)]
  280. [Category("Behavior")]
  281. public bool CanShrink
  282. {
  283. get { return canShrink; }
  284. set { canShrink = value; }
  285. }
  286. /// <summary>
  287. /// Determines if the object must grow to the band's bottom side.
  288. /// </summary>
  289. /// <remarks>
  290. /// If the property is set to true, object grows to the bottom side of its parent. This is useful if
  291. /// you have several objects on a band, and some of them can grow or shrink.
  292. /// </remarks>
  293. [DefaultValue(false)]
  294. [Category("Behavior")]
  295. public bool GrowToBottom
  296. {
  297. get { return growToBottom; }
  298. set { growToBottom = value; }
  299. }
  300. /// <summary>
  301. /// Gets or sets a shift mode of the object.
  302. /// </summary>
  303. /// <remarks>
  304. /// See <see cref="FastReport.ShiftMode"/> enumeration for details.
  305. /// </remarks>
  306. [DefaultValue(ShiftMode.Always)]
  307. [Category("Behavior")]
  308. public ShiftMode ShiftMode
  309. {
  310. get { return shiftMode; }
  311. set { shiftMode = value; }
  312. }
  313. /// <summary>
  314. /// Gets or sets the style name.
  315. /// </summary>
  316. /// <remarks>
  317. /// Style is a set of common properties such as border, fill, font, text color. The <b>Report</b>
  318. /// has a set of styles in the <see cref="Report.Styles"/> property.
  319. /// </remarks>
  320. [Category("Appearance")]
  321. [Editor("FastReport.TypeEditors.StyleEditor, FastReport", typeof(UITypeEditor))]
  322. public string Style
  323. {
  324. get { return style; }
  325. set
  326. {
  327. ApplyStyle(value);
  328. style = value;
  329. }
  330. }
  331. /// <summary>
  332. /// Gets or sets a style name that will be applied to even band rows.
  333. /// </summary>
  334. /// <remarks>
  335. /// Style with this name must exist in the <see cref="Report.Styles"/> collection.
  336. /// </remarks>
  337. [Category("Appearance")]
  338. [Editor("FastReport.TypeEditors.StyleEditor, FastReport", typeof(UITypeEditor))]
  339. public string EvenStyle
  340. {
  341. get { return evenStyle; }
  342. set { evenStyle = value; }
  343. }
  344. /// <summary>
  345. /// Gets or sets a style name that will be applied to this object when the mouse pointer is over it.
  346. /// </summary>
  347. /// <remarks>
  348. /// Style with this name must exist in the <see cref="Report.Styles"/> collection.
  349. /// </remarks>
  350. [Category("Appearance")]
  351. [Editor("FastReport.TypeEditors.StyleEditor, FastReport", typeof(UITypeEditor))]
  352. public string HoverStyle
  353. {
  354. get { return hoverStyle; }
  355. set { hoverStyle = value; }
  356. }
  357. /// <summary>
  358. /// Gets or sets a value that determines which properties of the even style to use.
  359. /// </summary>
  360. /// <remarks>
  361. /// Usually you will need only the Fill property of the even style to be applied. If you want to
  362. /// apply all style settings, set this property to <b>StylePriority.UseAll</b>.
  363. /// </remarks>
  364. [DefaultValue(StylePriority.UseFill)]
  365. [Category("Appearance")]
  366. public StylePriority EvenStylePriority
  367. {
  368. get { return evenStylePriority; }
  369. set { evenStylePriority = value; }
  370. }
  371. /// <summary>
  372. /// Gets or sets a value that determines whether to insert the hard page break before processing this object.
  373. /// </summary>
  374. [Browsable(false)]
  375. [DefaultValue(false)]
  376. [Category("Behavior")]
  377. public bool PageBreak
  378. {
  379. get { return pageBreak; }
  380. set { pageBreak = value; }
  381. }
  382. /// <summary>
  383. /// Gets or sets a value that determines where to print the object.
  384. /// </summary>
  385. /// <remarks>
  386. /// See the <see cref="FastReport.PrintOn"/> enumeration for details.
  387. /// </remarks>
  388. [DefaultValue(PrintOn.FirstPage | PrintOn.LastPage | PrintOn.OddPages | PrintOn.EvenPages | PrintOn.RepeatedBand | PrintOn.SinglePage)]
  389. [Category("Behavior")]
  390. [Editor("FastReport.TypeEditors.FlagsEditor, FastReport", typeof(UITypeEditor))]
  391. public PrintOn PrintOn
  392. {
  393. get { return printOn; }
  394. set { printOn = value; }
  395. }
  396. /// <summary>
  397. /// Gets or sets a script event name that will be fired before the object will be printed in the preview page.
  398. /// </summary>
  399. [Category("Build")]
  400. public string BeforePrintEvent
  401. {
  402. get { return beforePrintEvent; }
  403. set { beforePrintEvent = value; }
  404. }
  405. /// <summary>
  406. /// Gets or sets a script event name that will be fired after the object was printed in the preview page.
  407. /// </summary>
  408. [Category("Build")]
  409. public string AfterPrintEvent
  410. {
  411. get { return afterPrintEvent; }
  412. set { afterPrintEvent = value; }
  413. }
  414. /// <summary>
  415. /// Gets or sets a script event name that will be fired after the object was filled with data.
  416. /// </summary>
  417. [Category("Build")]
  418. public string AfterDataEvent
  419. {
  420. get { return afterDataEvent; }
  421. set { afterDataEvent = value; }
  422. }
  423. /// <summary>
  424. /// Gets or sets a script event name that will be fired when the user click the object in the preview window.
  425. /// </summary>
  426. [Category("Preview")]
  427. public string ClickEvent
  428. {
  429. get { return clickEvent; }
  430. set { clickEvent = value; }
  431. }
  432. /// <summary>
  433. /// Determines if the object has custom border and use only <b>Border.Width</b>, <b>Border.Style</b> and
  434. /// <b>Border.Color</b> properties.
  435. /// </summary>
  436. /// <remarks>
  437. /// This flag is used to disable some toolbar buttons when such object is selected. Applicable to the
  438. /// ShapeObject and LineObject.
  439. /// </remarks>
  440. [Browsable(false)]
  441. public bool FlagSimpleBorder
  442. {
  443. get { return flagSimpleBorder; }
  444. set { flagSimpleBorder = value; }
  445. }
  446. /// <summary>
  447. /// Determines if the object uses the <b>Border</b>.
  448. /// </summary>
  449. /// <remarks>
  450. /// This flag is used to disable some toolbar buttons when such object is selected.
  451. /// </remarks>
  452. [Browsable(false)]
  453. public bool FlagUseBorder
  454. {
  455. get { return flagUseBorder; }
  456. set { flagUseBorder = value; }
  457. }
  458. /// <summary>
  459. /// Determines if the object uses the fill.
  460. /// </summary>
  461. /// <remarks>
  462. /// This flag is used to disable some toolbar buttons when such object is selected.
  463. /// </remarks>
  464. [Browsable(false)]
  465. public bool FlagUseFill
  466. {
  467. get { return flagUseFill; }
  468. set { flagUseFill = value; }
  469. }
  470. /// <summary>
  471. /// Gets or sets a value indicates that object should not be added to the preview.
  472. /// </summary>
  473. [Browsable(false)]
  474. public bool FlagPreviewVisible
  475. {
  476. get { return flagPreviewVisible; }
  477. set { flagPreviewVisible = value; }
  478. }
  479. /// <summary>
  480. /// Determines if serializing the Style property is needed.
  481. /// </summary>
  482. /// <remarks>
  483. /// The <b>Style</b> property must be serialized last. Some ancestor classes may turn off the standard Style
  484. /// serialization and serialize it by themselves.
  485. /// </remarks>
  486. [Browsable(false)]
  487. public bool FlagSerializeStyle
  488. {
  489. get { return flagSerializeStyle; }
  490. set { flagSerializeStyle = value; }
  491. }
  492. /// <summary>
  493. /// Determines if an object can provide the hyperlink value automatically.
  494. /// </summary>
  495. /// <remarks>
  496. /// This flag is used in complex objects such as Matrix or Chart. These objects can provide
  497. /// a hyperlink value automatically, depending on where you click.
  498. /// </remarks>
  499. [Browsable(false)]
  500. public bool FlagProvidesHyperlinkValue
  501. {
  502. get { return flagProvidesHyperlinkValue; }
  503. set { flagProvidesHyperlinkValue = value; }
  504. }
  505. /// <summary>
  506. /// Gets an object's parent band.
  507. /// </summary>
  508. internal BandBase Band
  509. {
  510. get
  511. {
  512. if (this is BandBase)
  513. return this as BandBase;
  514. Base c = Parent;
  515. while (c != null)
  516. {
  517. if (c is BandBase)
  518. return c as BandBase;
  519. c = c.Parent;
  520. }
  521. return null;
  522. }
  523. }
  524. /// <summary>
  525. /// Gets an object's parent data band.
  526. /// </summary>
  527. internal DataBand DataBand
  528. {
  529. get
  530. {
  531. if (this is DataBand)
  532. return this as DataBand;
  533. Base c = Parent;
  534. while (c != null)
  535. {
  536. if (c is DataBand)
  537. return c as DataBand;
  538. c = c.Parent;
  539. }
  540. ObjectCollection pageBands = Page.AllObjects;
  541. foreach (Base c1 in pageBands)
  542. {
  543. if (c1 is DataBand)
  544. return c1 as DataBand;
  545. }
  546. return null;
  547. }
  548. }
  549. [Browsable(false)]
  550. protected internal virtual bool IsCompilationNeeded => false;
  551. /// <summary>
  552. /// Gets or sets an object's cursor shape.
  553. /// </summary>
  554. /// <remarks>
  555. /// This property is used in the preview mode.
  556. /// </remarks>
  557. [Category("Appearance")]
  558. public Cursor Cursor
  559. {
  560. get { return cursor; }
  561. set { cursor = value; }
  562. }
  563. /// <summary>
  564. /// Gets or sets a script event name that will be fired when the user
  565. /// moves the mouse over the object in the preview window.
  566. /// </summary>
  567. [Category("Preview")]
  568. public string MouseMoveEvent
  569. {
  570. get { return mouseMoveEvent; }
  571. set { mouseMoveEvent = value; }
  572. }
  573. /// <summary>
  574. /// Gets or sets a script event name that will be fired when the user
  575. /// releases the mouse button in the preview window.
  576. /// </summary>
  577. [Category("Preview")]
  578. public string MouseUpEvent
  579. {
  580. get { return mouseUpEvent; }
  581. set { mouseUpEvent = value; }
  582. }
  583. /// <summary>
  584. /// Gets or sets a script event name that will be fired when the user
  585. /// clicks the mouse button in the preview window.
  586. /// </summary>
  587. [Category("Preview")]
  588. public string MouseDownEvent
  589. {
  590. get { return mouseDownEvent; }
  591. set { mouseDownEvent = value; }
  592. }
  593. /// <summary>
  594. /// Gets or sets a script event name that will be fired when the
  595. /// mouse enters the object's bounds in the preview window.
  596. /// </summary>
  597. [Category("Preview")]
  598. public string MouseEnterEvent
  599. {
  600. get { return mouseEnterEvent; }
  601. set { mouseEnterEvent = value; }
  602. }
  603. /// <summary>
  604. /// Gets or sets a script event name that will be fired when the
  605. /// mouse leaves the object's bounds in the preview window.
  606. /// </summary>
  607. [Category("Preview")]
  608. public string MouseLeaveEvent
  609. {
  610. get { return mouseLeaveEvent; }
  611. set { mouseLeaveEvent = value; }
  612. }
  613. #endregion
  614. #region Public Methods
  615. /// <inheritdoc/>
  616. public override void Assign(Base source)
  617. {
  618. base.Assign(source);
  619. ReportComponentBase src = source as ReportComponentBase;
  620. Exportable = src.Exportable;
  621. ExportableExpression = src.ExportableExpression;
  622. Border = src.Border.Clone();
  623. Fill = src.Fill.Clone();
  624. Bookmark = src.Bookmark;
  625. Hyperlink.Assign(src.Hyperlink);
  626. CanGrow = src.CanGrow;
  627. CanShrink = src.CanShrink;
  628. GrowToBottom = src.GrowToBottom;
  629. ShiftMode = src.ShiftMode;
  630. style = src.Style;
  631. EvenStyle = src.EvenStyle;
  632. HoverStyle = src.HoverStyle;
  633. EvenStylePriority = src.EvenStylePriority;
  634. PageBreak = src.PageBreak;
  635. PrintOn = src.PrintOn;
  636. BeforePrintEvent = src.BeforePrintEvent;
  637. AfterPrintEvent = src.AfterPrintEvent;
  638. AfterDataEvent = src.AfterDataEvent;
  639. ClickEvent = src.ClickEvent;
  640. Cursor = src.Cursor;
  641. MouseMoveEvent = src.MouseMoveEvent;
  642. MouseUpEvent = src.MouseUpEvent;
  643. MouseDownEvent = src.MouseDownEvent;
  644. MouseEnterEvent = src.MouseEnterEvent;
  645. MouseLeaveEvent = src.MouseLeaveEvent;
  646. }
  647. /// <summary>
  648. /// Applies the style settings.
  649. /// </summary>
  650. /// <param name="style">Style to apply.</param>
  651. public virtual void ApplyStyle(Style style)
  652. {
  653. if (style.ApplyBorder)
  654. Border = style.Border.Clone();
  655. if (style.ApplyFill)
  656. Fill = style.Fill.Clone();
  657. }
  658. internal void ApplyStyle(string style)
  659. {
  660. if (!String.IsNullOrEmpty(style) && Report != null)
  661. {
  662. StyleCollection styles = Report.Styles;
  663. int index = styles.IndexOf(style);
  664. if (index != -1)
  665. ApplyStyle(styles[index]);
  666. }
  667. }
  668. internal void ApplyEvenStyle()
  669. {
  670. if (!String.IsNullOrEmpty(EvenStyle) && Report != null)
  671. {
  672. StyleCollection styles = Report.Styles;
  673. int index = styles.IndexOf(EvenStyle);
  674. if (index != -1)
  675. {
  676. Style style = styles[index];
  677. if (EvenStylePriority == StylePriority.UseFill)
  678. Fill = style.Fill.Clone();
  679. else
  680. ApplyStyle(style);
  681. }
  682. }
  683. }
  684. /// <summary>
  685. /// Saves the current style.
  686. /// </summary>
  687. public virtual void SaveStyle()
  688. {
  689. savedBorder = Border;
  690. savedFill = Fill;
  691. }
  692. /// <summary>
  693. /// Restores the current style.
  694. /// </summary>
  695. public virtual void RestoreStyle()
  696. {
  697. Border = savedBorder;
  698. Fill = savedFill;
  699. }
  700. /// <summary>
  701. /// Draws the object's background.
  702. /// </summary>
  703. /// <param name="e">Draw event arguments.</param>
  704. public void DrawBackground(FRPaintEventArgs e)
  705. {
  706. if (Width < 0.01 || Height < 0.01)
  707. return;
  708. Fill.Draw(e, AbsBounds);
  709. }
  710. /// <inheritdoc/>
  711. public override void Draw(FRPaintEventArgs e)
  712. {
  713. DrawBackground(e);
  714. base.Draw(e);
  715. }
  716. /// <summary>
  717. /// Determines if the object is visible on current drawing surface.
  718. /// </summary>
  719. /// <param name="e">Draw event arguments.</param>
  720. public virtual bool IsVisible(FRPaintEventArgs e)
  721. {
  722. RectangleF objRect = new RectangleF(AbsLeft * e.ScaleX, AbsTop * e.ScaleY,
  723. Width * e.ScaleX + 1, Height * e.ScaleY + 1);
  724. return e.Graphics.IsVisible(objRect);
  725. }
  726. /// <summary>
  727. /// Validate this object.
  728. /// </summary>
  729. /// <returns>List of errors</returns>
  730. public virtual List<ValidationError> Validate()
  731. {
  732. List<ValidationError> listError = new List<ValidationError>();
  733. if (Height <= 0 || Width <= 0)
  734. listError.Add(new ValidationError(Name, ValidationError.ErrorLevel.Error, Res.Get("Messages,Validator,IncorrectSize"), this));
  735. if (Name == "")
  736. listError.Add(new ValidationError(Name, ValidationError.ErrorLevel.Error, Res.Get("Messages,Validator,UnnamedObject"), this));
  737. if (Parent is ReportComponentBase && !Validator.RectContainInOtherRect((Parent as ReportComponentBase).AbsBounds, this.AbsBounds))
  738. listError.Add(new ValidationError(Name, ValidationError.ErrorLevel.Error, Res.Get("Messages,Validator,OutOfBounds"), this));
  739. return listError;
  740. }
  741. /// <inheritdoc/>
  742. public override void Serialize(FRWriter writer)
  743. {
  744. ReportComponentBase c = writer.DiffObject as ReportComponentBase;
  745. base.Serialize(writer);
  746. if (Exportable != c.Exportable)
  747. writer.WriteBool("Exportable", Exportable);
  748. if (ExportableExpression != c.ExportableExpression)
  749. writer.WriteStr("ExportableExpression", ExportableExpression);
  750. Border.Serialize(writer, "Border", c.Border);
  751. //if(Fill != c.Fill)
  752. Fill.Serialize(writer, "Fill", c.Fill);
  753. if (Cursor != c.Cursor && !Config.WebMode)
  754. writer.WriteValue("Cursor", Cursor);
  755. Hyperlink.Serialize(writer, c.Hyperlink);
  756. if (Bookmark != c.Bookmark)
  757. writer.WriteStr("Bookmark", Bookmark);
  758. if (writer.SerializeTo != SerializeTo.Preview)
  759. {
  760. if (CanGrow != c.CanGrow)
  761. writer.WriteBool("CanGrow", CanGrow);
  762. if (CanShrink != c.CanShrink)
  763. writer.WriteBool("CanShrink", CanShrink);
  764. if (GrowToBottom != c.GrowToBottom)
  765. writer.WriteBool("GrowToBottom", GrowToBottom);
  766. if (ShiftMode != c.ShiftMode)
  767. writer.WriteValue("ShiftMode", ShiftMode);
  768. if (FlagSerializeStyle && Style != c.Style)
  769. writer.WriteStr("Style", Style);
  770. if (EvenStyle != c.EvenStyle)
  771. writer.WriteStr("EvenStyle", EvenStyle);
  772. if (EvenStylePriority != c.EvenStylePriority)
  773. writer.WriteValue("EvenStylePriority", EvenStylePriority);
  774. if (HoverStyle != c.HoverStyle)
  775. writer.WriteStr("HoverStyle", HoverStyle);
  776. if (PageBreak != c.PageBreak)
  777. writer.WriteBool("PageBreak", PageBreak);
  778. if (PrintOn != c.PrintOn)
  779. writer.WriteValue("PrintOn", PrintOn);
  780. if (BeforePrintEvent != c.BeforePrintEvent)
  781. writer.WriteStr("BeforePrintEvent", BeforePrintEvent);
  782. if (AfterPrintEvent != c.AfterPrintEvent)
  783. writer.WriteStr("AfterPrintEvent", AfterPrintEvent);
  784. if (AfterDataEvent != c.AfterDataEvent)
  785. writer.WriteStr("AfterDataEvent", AfterDataEvent);
  786. if (ClickEvent != c.ClickEvent)
  787. writer.WriteStr("ClickEvent", ClickEvent);
  788. if (MouseMoveEvent != c.MouseMoveEvent)
  789. writer.WriteStr("MouseMoveEvent", MouseMoveEvent);
  790. if (MouseUpEvent != c.MouseUpEvent)
  791. writer.WriteStr("MouseUpEvent", MouseUpEvent);
  792. if (MouseDownEvent != c.MouseDownEvent)
  793. writer.WriteStr("MouseDownEvent", MouseDownEvent);
  794. if (MouseEnterEvent != c.MouseEnterEvent)
  795. writer.WriteStr("MouseEnterEvent", MouseEnterEvent);
  796. if (MouseLeaveEvent != c.MouseLeaveEvent)
  797. writer.WriteStr("MouseLeaveEvent", MouseLeaveEvent);
  798. }
  799. }
  800. /// <summary>
  801. ///
  802. /// </summary>
  803. /// <param name="reader"></param>
  804. public override void Deserialize(FRReader reader)
  805. {
  806. base.Deserialize(reader);
  807. Fill.Deserialize(reader, "Fill");
  808. }
  809. /// <summary>
  810. /// This method fires the <b>Click</b> event and the script code connected to the <b>ClickEvent</b>.
  811. /// </summary>
  812. /// <param name="e">Event data.</param>
  813. public virtual void OnClick(EventArgs e)
  814. {
  815. if (Click != null)
  816. Click(this, e);
  817. InvokeEvent(ClickEvent, e);
  818. }
  819. /// <inheritdoc/>
  820. public override void OnAfterLoad()
  821. {
  822. // if hyperlink is set to external report, we need to fix relative path to report
  823. Hyperlink.OnAfterLoad();
  824. }
  825. /// <summary>
  826. /// Checks if there are any listeners to the Click event.
  827. /// </summary>
  828. public bool HasClickListeners()
  829. {
  830. return Click != null;
  831. }
  832. #endregion
  833. #region Report Engine
  834. /// <summary>
  835. /// Resets the data from the previous report run.
  836. /// </summary>
  837. public virtual void ResetData()
  838. {
  839. }
  840. /// <summary>
  841. /// Initializes the object before running a report.
  842. /// </summary>
  843. /// <remarks>
  844. /// This method is used by the report engine, do not call it directly.
  845. /// </remarks>
  846. public virtual void InitializeComponent()
  847. {
  848. // update the component's style
  849. Style = Style;
  850. Fill.InitializeComponent();
  851. }
  852. /// <summary>
  853. /// Performs a finalization after the report is finished.
  854. /// </summary>
  855. /// <remarks>
  856. /// This method is used by the report engine, do not call it directly.
  857. /// </remarks>
  858. public virtual void FinalizeComponent()
  859. {
  860. Fill.FinalizeComponent();
  861. }
  862. /// <summary>
  863. /// Saves the object's state before printing it.
  864. /// </summary>
  865. /// <remarks>
  866. /// This method is called by the report engine before processing the object.
  867. /// <para/>Do not call it directly. You may override it if you are developing a new FastReport component.
  868. /// In this method you should save any object properties that may be changed during the object printing.
  869. /// The standard implementation saves the object's bounds, visibility, bookmark and hyperlink.
  870. /// </remarks>
  871. public virtual void SaveState()
  872. {
  873. savedBounds = Bounds;
  874. savedVisible = Visible;
  875. savedBookmark = Bookmark;
  876. savedBorder = Border;
  877. savedFill = Fill;
  878. Hyperlink.SaveState();
  879. }
  880. /// <summary>
  881. /// Restores the object's state after printing it.
  882. /// </summary>
  883. /// <remarks>
  884. /// This method is called by the report engine after processing the object.
  885. /// <para/>Do not call it directly. You may override it if you are developing a new FastReport component.
  886. /// In this method you should restore the object properties that were saved by the <see cref="SaveState"/> method.
  887. /// </remarks>
  888. public virtual void RestoreState()
  889. {
  890. Bounds = savedBounds;
  891. Visible = savedVisible;
  892. Bookmark = savedBookmark;
  893. Hyperlink.RestoreState();
  894. Border = savedBorder;
  895. Fill = savedFill;
  896. }
  897. /// <summary>
  898. /// Calculates the object's height.
  899. /// </summary>
  900. /// <returns>Actual object's height, in pixels.</returns>
  901. /// <remarks>
  902. /// Applicable to objects that contain several text lines, such as TextObject. Returns the height needed
  903. /// to display all the text lines.
  904. /// </remarks>
  905. public virtual float CalcHeight()
  906. {
  907. return Height;
  908. }
  909. /// <summary>
  910. /// Gets the data from a datasource that the object is connected to.
  911. /// </summary>
  912. /// <remarks>
  913. /// This method is called by the report engine before processing the object.
  914. /// <para/>Do not call it directly. You may override it if you are developing a new FastReport component.
  915. /// In this method you should get the data from a datasource that the object is connected to.
  916. /// </remarks>
  917. public virtual void GetData()
  918. {
  919. Hyperlink.Calculate();
  920. if (!String.IsNullOrEmpty(Bookmark))
  921. {
  922. object value = Report.Calc(Bookmark);
  923. Bookmark = value == null ? "" : value.ToString();
  924. }
  925. }
  926. /// <inheritdoc/>
  927. public override string[] GetExpressions()
  928. {
  929. List<string> expressions = new List<string>();
  930. string[] baseExpressions = base.GetExpressions();
  931. if (baseExpressions != null)
  932. {
  933. expressions.AddRange(baseExpressions);
  934. }
  935. if (!String.IsNullOrEmpty(Hyperlink.Expression))
  936. expressions.Add(Hyperlink.Expression);
  937. if (!String.IsNullOrEmpty(Bookmark))
  938. expressions.Add(Bookmark);
  939. if (!String.IsNullOrEmpty(ExportableExpression))
  940. {
  941. string expression = Code.CodeUtils.FixExpressionWithBrackets(ExportableExpression);
  942. if (expression.ToLower() == "true" || expression.ToLower() == "false")
  943. {
  944. expression = expression.ToLower();
  945. }
  946. expressions.Add(expression);
  947. }
  948. return expressions.ToArray();
  949. }
  950. /// <summary>
  951. /// This method fires the <b>BeforePrint</b> event and the script code connected to the <b>BeforePrintEvent</b>.
  952. /// </summary>
  953. /// <param name="e">Event data.</param>
  954. public virtual void OnBeforePrint(EventArgs e)
  955. {
  956. if (BeforePrint != null)
  957. BeforePrint(this, e);
  958. InvokeEvent(BeforePrintEvent, e);
  959. }
  960. /// <summary>
  961. /// This method fires the <b>AfterPrint</b> event and the script code connected to the <b>AfterPrintEvent</b>.
  962. /// </summary>
  963. /// <param name="e">Event data.</param>
  964. public virtual void OnAfterPrint(EventArgs e)
  965. {
  966. if (AfterPrint != null)
  967. AfterPrint(this, e);
  968. InvokeEvent(AfterPrintEvent, e);
  969. }
  970. /// <summary>
  971. /// This method fires the <b>AfterData</b> event and the script code connected to the <b>AfterDataEvent</b>.
  972. /// </summary>
  973. /// <param name="e">Event data.</param>
  974. public virtual void OnAfterData(EventArgs e)
  975. {
  976. if (AfterData != null)
  977. AfterData(this, e);
  978. InvokeEvent(AfterDataEvent, e);
  979. }
  980. internal void OnAfterData()
  981. {
  982. OnAfterData(EventArgs.Empty);
  983. }
  984. #endregion
  985. /// <summary>
  986. /// Initializes a new instance of the <see cref="ReportComponentBase"/> class with default settings.
  987. /// </summary>
  988. public ReportComponentBase()
  989. {
  990. border = new Border();
  991. fill = new SolidFill();
  992. hyperlink = new Hyperlink(this);
  993. bookmark = "";
  994. exportable = true;
  995. exportableExpression = "";
  996. flagUseFill = true;
  997. flagUseBorder = true;
  998. flagPreviewVisible = true;
  999. flagSerializeStyle = true;
  1000. shiftMode = ShiftMode.Always;
  1001. style = "";
  1002. evenStyle = "";
  1003. hoverStyle = "";
  1004. printOn = PrintOn.FirstPage | PrintOn.LastPage | PrintOn.OddPages | PrintOn.EvenPages | PrintOn.RepeatedBand | PrintOn.SinglePage;
  1005. beforePrintEvent = "";
  1006. afterPrintEvent = "";
  1007. afterDataEvent = "";
  1008. clickEvent = "";
  1009. cursor = Cursors.Default;
  1010. mouseMoveEvent = "";
  1011. mouseUpEvent = "";
  1012. mouseDownEvent = "";
  1013. mouseEnterEvent = "";
  1014. mouseLeaveEvent = "";
  1015. SetFlags(Flags.CanGroup, true);
  1016. if (BaseName.EndsWith("Object"))
  1017. BaseName = ClassName.Substring(0, ClassName.Length - 6);
  1018. }
  1019. }
  1020. }