ReportComponentBase.cs 39 KB

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