ReportPage.cs 38 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142
  1. using System;
  2. using System.Drawing;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using FastReport.Utils;
  6. using System.Drawing.Design;
  7. namespace FastReport
  8. {
  9. /// <summary>
  10. /// Represents a report page.
  11. /// </summary>
  12. /// <remarks>
  13. /// To get/set a paper size and orientation, use the <see cref="PaperWidth"/>, <see cref="PaperHeight"/>
  14. /// and <see cref="Landscape"/> properties. Note that paper size is measured in millimeters.
  15. /// <para/>Report page can contain one or several bands with report objects. Use the <see cref="ReportTitle"/>,
  16. /// <see cref="ReportSummary"/>, <see cref="PageHeader"/>, <see cref="PageFooter"/>,
  17. /// <see cref="ColumnHeader"/>, <see cref="ColumnFooter"/>, <see cref="Overlay"/> properties
  18. /// to get/set the page bands. The <see cref="Bands"/> property holds the list of data bands or groups.
  19. /// Thus you may add several databands to this property to create master-master reports, for example.
  20. /// <note type="caution">
  21. /// Report page can contain bands only. You cannot place report objects such as <b>TextObject</b> on a page.
  22. /// </note>
  23. /// </remarks>
  24. /// <example>
  25. /// This example shows how to create a page with one <b>ReportTitleBand</b> and <b>DataBand</b> bands and add
  26. /// it to the report.
  27. /// <code>
  28. /// ReportPage page = new ReportPage();
  29. /// // set the paper in millimeters
  30. /// page.PaperWidth = 210;
  31. /// page.PaperHeight = 297;
  32. /// // create report title
  33. /// page.ReportTitle = new ReportTitleBand();
  34. /// page.ReportTitle.Name = "ReportTitle1";
  35. /// page.ReportTitle.Height = Units.Millimeters * 10;
  36. /// // create data band
  37. /// DataBand data = new DataBand();
  38. /// data.Name = "Data1";
  39. /// data.Height = Units.Millimeters * 10;
  40. /// // add data band to the page
  41. /// page.Bands.Add(data);
  42. /// // add page to the report
  43. /// report.Pages.Add(page);
  44. /// </code>
  45. /// </example>
  46. public partial class ReportPage : PageBase, IParent
  47. {
  48. #region Constants
  49. private const float MAX_PAPER_SIZE_MM = 2000000000;
  50. #endregion // Constants
  51. #region Fields
  52. private string exportAlias;
  53. private float paperWidth;
  54. private float paperHeight;
  55. private int rawPaperSize;
  56. private bool landscape;
  57. private float leftMargin;
  58. private float topMargin;
  59. private float rightMargin;
  60. private float bottomMargin;
  61. private bool mirrorMargins;
  62. private PageColumns columns;
  63. private FloatCollection guides;
  64. private Border border;
  65. private FillBase fill;
  66. private Watermark watermark;
  67. private bool titleBeforeHeader;
  68. private string outlineExpression;
  69. private bool printOnPreviousPage;
  70. private bool resetPageNumber;
  71. private bool extraDesignWidth;
  72. private bool startOnOddPage;
  73. private bool backPage;
  74. private SubreportObject subreport;
  75. private PageHeaderBand pageHeader;
  76. private ReportTitleBand reportTitle;
  77. private ColumnHeaderBand columnHeader;
  78. private BandCollection bands;
  79. private ReportSummaryBand reportSummary;
  80. private ColumnFooterBand columnFooter;
  81. private PageFooterBand pageFooter;
  82. private OverlayBand overlay;
  83. private string startPageEvent;
  84. private string finishPageEvent;
  85. private string manualBuildEvent;
  86. private bool unlimitedHeight;
  87. private bool printOnRollPaper;
  88. private bool unlimitedWidth;
  89. private float unlimitedHeightValue;
  90. private float unlimitedWidthValue;
  91. #endregion
  92. #region Properties
  93. /// <summary>
  94. /// This event occurs when the report engine starts this page.
  95. /// </summary>
  96. public event EventHandler StartPage;
  97. /// <summary>
  98. /// This event occurs when the report engine finished this page.
  99. /// </summary>
  100. public event EventHandler FinishPage;
  101. /// <summary>
  102. /// This event occurs when the report engine is about to print databands in this page.
  103. /// </summary>
  104. public event EventHandler ManualBuild;
  105. /// <summary>
  106. /// Gets or sets a width of the paper, in millimeters.
  107. /// </summary>
  108. [Category("Paper")]
  109. [TypeConverter("FastReport.TypeConverters.PaperConverter, FastReport")]
  110. public float PaperWidth
  111. {
  112. get { return paperWidth; }
  113. set { paperWidth = value; }
  114. }
  115. /// <summary>
  116. /// Gets or sets the page name on export
  117. /// </summary>
  118. [Category("Paper")]
  119. public string ExportAlias
  120. {
  121. get { return exportAlias; }
  122. set { exportAlias = value; }
  123. }
  124. /// <summary>
  125. /// Gets or sets a height of the paper, in millimeters.
  126. /// </summary>
  127. [Category("Paper")]
  128. [TypeConverter("FastReport.TypeConverters.PaperConverter, FastReport")]
  129. public float PaperHeight
  130. {
  131. get { return paperHeight; }
  132. set { paperHeight = value; }
  133. }
  134. /// <summary>
  135. /// Gets or sets the raw index of a paper size.
  136. /// </summary>
  137. /// <remarks>
  138. /// This property stores the RawKind value of a selected papersize. It is used to distiguish
  139. /// between several papers with the same size (for ex. "A3" and "A3 with no margins") used in some
  140. /// printer drivers.
  141. /// <para/>It is not obligatory to set this property. FastReport will select the
  142. /// necessary paper using the <b>PaperWidth</b> and <b>PaperHeight</b> values.
  143. /// </remarks>
  144. [Category("Paper")]
  145. [DefaultValue(0)]
  146. public int RawPaperSize
  147. {
  148. get { return rawPaperSize; }
  149. set { rawPaperSize = value; }
  150. }
  151. /// <summary>
  152. /// Gets or sets a value indicating whether the page has unlimited height.
  153. /// </summary>
  154. [DefaultValue(false)]
  155. [Category("Paper")]
  156. public bool UnlimitedHeight
  157. {
  158. get { return unlimitedHeight; }
  159. set
  160. {
  161. unlimitedHeight = value;
  162. if (!unlimitedHeight)
  163. printOnRollPaper = false;
  164. }
  165. }
  166. /// <summary>
  167. /// Gets or sets the value indicating whether the unlimited page should be printed on roll paper.
  168. /// </summary>
  169. [DefaultValue(false)]
  170. [Category("Paper")]
  171. public bool PrintOnRollPaper
  172. {
  173. get { return printOnRollPaper; }
  174. set
  175. {
  176. if (unlimitedHeight)
  177. printOnRollPaper = value;
  178. }
  179. }
  180. /// <summary>
  181. /// Gets or sets a value indicating whether the page has unlimited width.
  182. /// </summary>
  183. [DefaultValue(false)]
  184. [Category("Paper")]
  185. public bool UnlimitedWidth
  186. {
  187. get { return unlimitedWidth; }
  188. set { unlimitedWidth = value; }
  189. }
  190. /// <summary>
  191. /// Get or set the current height of unlimited page.
  192. /// </summary>
  193. [Browsable(false)]
  194. public float UnlimitedHeightValue
  195. {
  196. get { return unlimitedHeightValue; }
  197. set
  198. {
  199. unlimitedHeightValue = value;
  200. if (printOnRollPaper)
  201. PaperHeight = unlimitedHeightValue / Units.Millimeters;
  202. }
  203. }
  204. /// <summary>
  205. /// Get or set the current width of unlimited page.
  206. /// </summary>
  207. [Browsable(false)]
  208. public float UnlimitedWidthValue
  209. {
  210. get { return unlimitedWidthValue; }
  211. set { unlimitedWidthValue = value; }
  212. }
  213. /// <summary>
  214. /// Gets the current page height in pixels.
  215. /// </summary>
  216. [Browsable(false)]
  217. public float HeightInPixels
  218. {
  219. get
  220. {
  221. return UnlimitedHeight ? UnlimitedHeightValue : PaperHeight * Units.Millimeters;
  222. }
  223. }
  224. /// <summary>
  225. /// Gets the current page width in pixels.
  226. /// </summary>
  227. [Browsable(false)]
  228. public float WidthInPixels
  229. {
  230. get
  231. {
  232. if (UnlimitedWidth)
  233. {
  234. if (!IsDesigning)
  235. {
  236. return UnlimitedWidthValue;
  237. }
  238. }
  239. return PaperWidth * Units.Millimeters;
  240. }
  241. }
  242. /// <summary>
  243. /// Gets or sets a value indicating that page should be in landscape orientation.
  244. /// </summary>
  245. /// <remarks>
  246. /// When you change this property, it will automatically swap paper width and height, as well as paper margins.
  247. /// </remarks>
  248. [DefaultValue(false)]
  249. [Category("Paper")]
  250. public bool Landscape
  251. {
  252. get { return landscape; }
  253. set
  254. {
  255. if (landscape != value)
  256. {
  257. float e = paperWidth;
  258. paperWidth = paperHeight;
  259. paperHeight = e;
  260. float m1 = leftMargin; // m3
  261. float m2 = rightMargin; // m1 m2
  262. float m3 = topMargin; // m4
  263. float m4 = bottomMargin; //
  264. if (value)
  265. {
  266. leftMargin = m3; // rotate counter-clockwise
  267. rightMargin = m4;
  268. topMargin = m2;
  269. bottomMargin = m1;
  270. }
  271. else
  272. {
  273. leftMargin = m4; // rotate clockwise
  274. rightMargin = m3;
  275. topMargin = m1;
  276. bottomMargin = m2;
  277. }
  278. }
  279. landscape = value;
  280. }
  281. }
  282. /// <summary>
  283. /// Gets or sets the left page margin, in millimeters.
  284. /// </summary>
  285. [Category("Paper")]
  286. [TypeConverter("FastReport.TypeConverters.PaperConverter, FastReport")]
  287. public float LeftMargin
  288. {
  289. get { return leftMargin; }
  290. set { leftMargin = value; }
  291. }
  292. /// <summary>
  293. /// Gets or sets the top page margin, in millimeters.
  294. /// </summary>
  295. [Category("Paper")]
  296. [TypeConverter("FastReport.TypeConverters.PaperConverter, FastReport")]
  297. public float TopMargin
  298. {
  299. get { return topMargin; }
  300. set { topMargin = value; }
  301. }
  302. /// <summary>
  303. /// Gets or sets the right page margin, in millimeters.
  304. /// </summary>
  305. [Category("Paper")]
  306. [TypeConverter("FastReport.TypeConverters.PaperConverter, FastReport")]
  307. public float RightMargin
  308. {
  309. get { return rightMargin; }
  310. set { rightMargin = value; }
  311. }
  312. /// <summary>
  313. /// Gets or sets the bottom page margin, in millimeters.
  314. /// </summary>
  315. [Category("Paper")]
  316. [TypeConverter("FastReport.TypeConverters.PaperConverter, FastReport")]
  317. public float BottomMargin
  318. {
  319. get { return bottomMargin; }
  320. set { bottomMargin = value; }
  321. }
  322. /// <summary>
  323. /// Gets or sets a value indicating that even pages should swap its left and right margins when
  324. /// previewed or printed.
  325. /// </summary>
  326. [DefaultValue(false)]
  327. [Category("Behavior")]
  328. public bool MirrorMargins
  329. {
  330. get { return mirrorMargins; }
  331. set { mirrorMargins = value; }
  332. }
  333. /// <summary>
  334. /// Gets the page columns settings.
  335. /// </summary>
  336. [Category("Appearance")]
  337. public PageColumns Columns
  338. {
  339. get { return columns; }
  340. }
  341. /// <summary>
  342. /// Gets or sets the page border that will be printed inside the page printing area.
  343. /// </summary>
  344. [Category("Appearance")]
  345. public Border Border
  346. {
  347. get { return border; }
  348. set { border = value; }
  349. }
  350. /// <summary>
  351. /// Gets or sets the page background fill.
  352. /// </summary>
  353. [Category("Appearance")]
  354. [Editor("FastReport.TypeEditors.FillEditor, FastReport", typeof(UITypeEditor))]
  355. public FillBase Fill
  356. {
  357. get { return fill; }
  358. set
  359. {
  360. if (value == null)
  361. throw new ArgumentNullException("Fill");
  362. fill = value;
  363. }
  364. }
  365. /// <summary>
  366. /// Gets or sets the page watermark.
  367. /// </summary>
  368. /// <remarks>
  369. /// To enabled watermark, set its <b>Enabled</b> property to <b>true</b>.
  370. /// </remarks>
  371. [Category("Appearance")]
  372. public Watermark Watermark
  373. {
  374. get { return watermark; }
  375. set
  376. {
  377. if (watermark != value)
  378. if (watermark != null)
  379. watermark.Dispose();
  380. watermark = value;
  381. }
  382. }
  383. /// <summary>
  384. /// Gets or sets a value indicating that <b>ReportTitle</b> band should be printed before the
  385. /// <b>PageHeader</b> band.
  386. /// </summary>
  387. [DefaultValue(true)]
  388. [Category("Behavior")]
  389. public bool TitleBeforeHeader
  390. {
  391. get { return titleBeforeHeader; }
  392. set { titleBeforeHeader = value; }
  393. }
  394. /// <summary>
  395. /// Gets or sets an outline expression.
  396. /// </summary>
  397. /// <remarks>
  398. /// For more information, see <see cref="BandBase.OutlineExpression"/> property.
  399. /// </remarks>
  400. [Category("Data")]
  401. [Editor("FastReport.TypeEditors.ExpressionEditor, FastReport", typeof(UITypeEditor))]
  402. public string OutlineExpression
  403. {
  404. get { return outlineExpression; }
  405. set { outlineExpression = value; }
  406. }
  407. /// <summary>
  408. /// Gets or sets a value indicating whether to start to print this page on a free space of the previous page.
  409. /// </summary>
  410. /// <remarks>
  411. /// This property can be used if you have two or more pages in the report template.
  412. /// </remarks>
  413. [DefaultValue(false)]
  414. [Category("Behavior")]
  415. public bool PrintOnPreviousPage
  416. {
  417. get { return printOnPreviousPage; }
  418. set { printOnPreviousPage = value; }
  419. }
  420. /// <summary>
  421. /// Gets or sets a value indicating that FastReport engine must reset page numbers before printing this page.
  422. /// </summary>
  423. /// <remarks>
  424. /// This property can be used if you have two or more pages in the report template.
  425. /// </remarks>
  426. [DefaultValue(false)]
  427. [Category("Behavior")]
  428. public bool ResetPageNumber
  429. {
  430. get { return resetPageNumber; }
  431. set { resetPageNumber = value; }
  432. }
  433. /// <summary>
  434. /// Gets or sets a value indicating whether the page has extra width in the report designer.
  435. /// </summary>
  436. /// <remarks>
  437. /// This property may be useful if you work with such objects as Matrix and Table.
  438. /// </remarks>
  439. [DefaultValue(false)]
  440. [Category("Design")]
  441. public bool ExtraDesignWidth
  442. {
  443. get { return extraDesignWidth; }
  444. set { extraDesignWidth = value; }
  445. }
  446. /// <summary>
  447. /// Gets or sets a value indicating whether this page will start on an odd page only.
  448. /// </summary>
  449. /// <remarks>
  450. /// This property is useful to print booklet-type reports. Setting this property to <b>true</b>
  451. /// means that this page will start to print on an odd page only. If necessary, an empty page
  452. /// will be added to the prepared report before this page will be printed.
  453. /// </remarks>
  454. [DefaultValue(false)]
  455. [Category("Behavior")]
  456. public bool StartOnOddPage
  457. {
  458. get { return startOnOddPage; }
  459. set { startOnOddPage = value; }
  460. }
  461. /// <summary>
  462. /// Uses this page as a back page for previously printed pages.
  463. /// </summary>
  464. [DefaultValue(false)]
  465. [Category("Behavior")]
  466. public bool BackPage
  467. {
  468. get { return backPage; }
  469. set { backPage = value; }
  470. }
  471. /// <summary>
  472. /// Gets or sets a report title band.
  473. /// </summary>
  474. [Browsable(false)]
  475. public ReportTitleBand ReportTitle
  476. {
  477. get { return reportTitle; }
  478. set
  479. {
  480. SetProp(reportTitle, value);
  481. reportTitle = value;
  482. }
  483. }
  484. /// <summary>
  485. /// Gets or sets a report summary band.
  486. /// </summary>
  487. [Browsable(false)]
  488. public ReportSummaryBand ReportSummary
  489. {
  490. get { return reportSummary; }
  491. set
  492. {
  493. SetProp(reportSummary, value);
  494. reportSummary = value;
  495. }
  496. }
  497. /// <summary>
  498. /// Gets or sets a page header band.
  499. /// </summary>
  500. [Browsable(false)]
  501. public PageHeaderBand PageHeader
  502. {
  503. get { return pageHeader; }
  504. set
  505. {
  506. SetProp(pageHeader, value);
  507. pageHeader = value;
  508. }
  509. }
  510. /// <summary>
  511. /// Gets or sets a page footer band.
  512. /// </summary>
  513. [Browsable(false)]
  514. public PageFooterBand PageFooter
  515. {
  516. get { return pageFooter; }
  517. set
  518. {
  519. SetProp(pageFooter, value);
  520. pageFooter = value;
  521. }
  522. }
  523. /// <summary>
  524. /// Gets or sets a column header band.
  525. /// </summary>
  526. [Browsable(false)]
  527. public ColumnHeaderBand ColumnHeader
  528. {
  529. get { return columnHeader; }
  530. set
  531. {
  532. SetProp(columnHeader, value);
  533. columnHeader = value;
  534. }
  535. }
  536. /// <summary>
  537. /// Gets or sets a column footer band.
  538. /// </summary>
  539. [Browsable(false)]
  540. public ColumnFooterBand ColumnFooter
  541. {
  542. get { return columnFooter; }
  543. set
  544. {
  545. SetProp(columnFooter, value);
  546. columnFooter = value;
  547. }
  548. }
  549. /// <summary>
  550. /// Gets or sets an overlay band.
  551. /// </summary>
  552. [Browsable(false)]
  553. public OverlayBand Overlay
  554. {
  555. get { return overlay; }
  556. set
  557. {
  558. SetProp(overlay, value);
  559. overlay = value;
  560. }
  561. }
  562. /// <summary>
  563. /// Gets the collection of data bands or group header bands.
  564. /// </summary>
  565. /// <remarks>
  566. /// The <b>Bands</b> property holds the list of data bands or group headers.
  567. /// Thus you may add several databands to this property to create master-master reports, for example.
  568. /// </remarks>
  569. [Browsable(false)]
  570. public BandCollection Bands
  571. {
  572. get { return bands; }
  573. }
  574. /// <summary>
  575. /// Gets or sets the page guidelines.
  576. /// </summary>
  577. /// <remarks>
  578. /// This property hold all vertical guidelines. The horizontal guidelines are owned by the bands (see
  579. /// <see cref="BandBase.Guides"/> property).
  580. /// </remarks>
  581. [Browsable(false)]
  582. public FloatCollection Guides
  583. {
  584. get { return guides; }
  585. set { guides = value; }
  586. }
  587. /// <summary>
  588. /// Gets or sets the reference to a parent <b>SubreportObject</b> that owns this page.
  589. /// </summary>
  590. /// <remarks>
  591. /// This property is <b>null</b> for regular report pages. See the <see cref="SubreportObject"/> for details.
  592. /// </remarks>
  593. [Browsable(false)]
  594. public SubreportObject Subreport
  595. {
  596. get { return subreport; }
  597. set { subreport = value; }
  598. }
  599. /// <summary>
  600. /// Gets or sets a script event name that will be fired when the report engine starts this page.
  601. /// </summary>
  602. [Category("Build")]
  603. public string StartPageEvent
  604. {
  605. get { return startPageEvent; }
  606. set { startPageEvent = value; }
  607. }
  608. /// <summary>
  609. /// Gets or sets a script event name that will be fired when the report engine finished this page.
  610. /// </summary>
  611. [Category("Build")]
  612. public string FinishPageEvent
  613. {
  614. get { return finishPageEvent; }
  615. set { finishPageEvent = value; }
  616. }
  617. /// <summary>
  618. /// Gets or sets a script event name that will be fired when the report engine is about
  619. /// to print databands in this page.
  620. /// </summary>
  621. [Category("Build")]
  622. public string ManualBuildEvent
  623. {
  624. get { return manualBuildEvent; }
  625. set { manualBuildEvent = value; }
  626. }
  627. internal bool IsManualBuild
  628. {
  629. get { return !String.IsNullOrEmpty(manualBuildEvent) || ManualBuild != null; }
  630. }
  631. #endregion
  632. #region Private Methods
  633. private void DrawBackground(FRPaintEventArgs e, RectangleF rect)
  634. {
  635. rect.Width *= e.ScaleX;
  636. rect.Height *= e.ScaleY;
  637. Brush brush = null;
  638. if (Fill is SolidFill)
  639. brush = e.Cache.GetBrush((Fill as SolidFill).Color);
  640. else
  641. brush = Fill.CreateBrush(rect, e.ScaleX, e.ScaleY);
  642. e.Graphics.FillRectangle(brush, rect.Left, rect.Top, rect.Width, rect.Height);
  643. if (!(Fill is SolidFill))
  644. brush.Dispose();
  645. }
  646. #endregion
  647. #region Protected Methods
  648. /// <inheritdoc/>
  649. protected override void Dispose(bool disposing)
  650. {
  651. if (disposing)
  652. {
  653. if (Subreport != null)
  654. {
  655. Subreport.ReportPage = null;
  656. }
  657. if (Watermark != null)
  658. {
  659. Watermark.Dispose();
  660. Watermark = null;
  661. }
  662. }
  663. base.Dispose(disposing);
  664. }
  665. #endregion
  666. #region IParent
  667. /// <inheritdoc/>
  668. public virtual void GetChildObjects(ObjectCollection list)
  669. {
  670. if (TitleBeforeHeader)
  671. {
  672. list.Add(reportTitle);
  673. list.Add(pageHeader);
  674. }
  675. else
  676. {
  677. list.Add(pageHeader);
  678. list.Add(reportTitle);
  679. }
  680. list.Add(columnHeader);
  681. foreach (BandBase band in bands)
  682. {
  683. list.Add(band);
  684. }
  685. list.Add(reportSummary);
  686. list.Add(columnFooter);
  687. list.Add(pageFooter);
  688. list.Add(overlay);
  689. }
  690. /// <inheritdoc/>
  691. public virtual bool CanContain(Base child)
  692. {
  693. if (IsRunning)
  694. return child is BandBase;
  695. return (child is PageHeaderBand || child is ReportTitleBand || child is ColumnHeaderBand ||
  696. child is DataBand || child is GroupHeaderBand || child is ColumnFooterBand ||
  697. child is ReportSummaryBand || child is PageFooterBand || child is OverlayBand);
  698. }
  699. /// <inheritdoc/>
  700. public virtual void AddChild(Base child)
  701. {
  702. if (IsRunning)
  703. {
  704. bands.Add(child as BandBase);
  705. return;
  706. }
  707. if (child is PageHeaderBand)
  708. PageHeader = child as PageHeaderBand;
  709. if (child is ReportTitleBand)
  710. ReportTitle = child as ReportTitleBand;
  711. if (child is ColumnHeaderBand)
  712. ColumnHeader = child as ColumnHeaderBand;
  713. if (child is DataBand || child is GroupHeaderBand)
  714. bands.Add(child as BandBase);
  715. if (child is ReportSummaryBand)
  716. ReportSummary = child as ReportSummaryBand;
  717. if (child is ColumnFooterBand)
  718. ColumnFooter = child as ColumnFooterBand;
  719. if (child is PageFooterBand)
  720. PageFooter = child as PageFooterBand;
  721. if (child is OverlayBand)
  722. Overlay = child as OverlayBand;
  723. }
  724. /// <inheritdoc/>
  725. public virtual void RemoveChild(Base child)
  726. {
  727. if (IsRunning)
  728. {
  729. bands.Remove(child as BandBase);
  730. return;
  731. }
  732. if (child is PageHeaderBand && pageHeader == child as PageHeaderBand)
  733. PageHeader = null;
  734. if (child is ReportTitleBand && reportTitle == child as ReportTitleBand)
  735. ReportTitle = null;
  736. if (child is ColumnHeaderBand && columnHeader == child as ColumnHeaderBand)
  737. ColumnHeader = null;
  738. if (child is DataBand || child is GroupHeaderBand)
  739. bands.Remove(child as BandBase);
  740. if (child is ReportSummaryBand && reportSummary == child as ReportSummaryBand)
  741. ReportSummary = null;
  742. if (child is ColumnFooterBand && columnFooter == child as ColumnFooterBand)
  743. ColumnFooter = null;
  744. if (child is PageFooterBand && pageFooter == child as PageFooterBand)
  745. PageFooter = null;
  746. if (child is OverlayBand && overlay == child as OverlayBand)
  747. Overlay = null;
  748. }
  749. /// <inheritdoc/>
  750. public virtual int GetChildOrder(Base child)
  751. {
  752. return bands.IndexOf(child as BandBase);
  753. }
  754. /// <inheritdoc/>
  755. public virtual void SetChildOrder(Base child, int order)
  756. {
  757. if (order > bands.Count)
  758. order = bands.Count;
  759. int oldOrder = child.ZOrder;
  760. if (oldOrder != -1 && order != -1 && oldOrder != order)
  761. {
  762. if (oldOrder <= order)
  763. order--;
  764. bands.Remove(child as BandBase);
  765. bands.Insert(order, child as BandBase);
  766. }
  767. }
  768. /// <inheritdoc/>
  769. public virtual void UpdateLayout(float dx, float dy)
  770. {
  771. // do nothing
  772. }
  773. #endregion
  774. #region Public Methods
  775. /// <inheritdoc/>
  776. public override void Assign(Base source)
  777. {
  778. base.Assign(source);
  779. ReportPage src = source as ReportPage;
  780. ExportAlias = src.ExportAlias;
  781. Landscape = src.Landscape;
  782. PaperWidth = src.PaperWidth;
  783. PaperHeight = src.PaperHeight;
  784. RawPaperSize = src.RawPaperSize;
  785. LeftMargin = src.LeftMargin;
  786. TopMargin = src.TopMargin;
  787. RightMargin = src.RightMargin;
  788. BottomMargin = src.BottomMargin;
  789. MirrorMargins = src.MirrorMargins;
  790. AssignPreview(src);
  791. Columns.Assign(src.Columns);
  792. Guides.Assign(src.Guides);
  793. Border = src.Border.Clone();
  794. Fill = src.Fill.Clone();
  795. Watermark.Assign(src.Watermark);
  796. TitleBeforeHeader = src.TitleBeforeHeader;
  797. OutlineExpression = src.OutlineExpression;
  798. PrintOnPreviousPage = src.PrintOnPreviousPage;
  799. ResetPageNumber = src.ResetPageNumber;
  800. ExtraDesignWidth = src.ExtraDesignWidth;
  801. BackPage = src.BackPage;
  802. StartOnOddPage = src.StartOnOddPage;
  803. StartPageEvent = src.StartPageEvent;
  804. FinishPageEvent = src.FinishPageEvent;
  805. ManualBuildEvent = src.ManualBuildEvent;
  806. UnlimitedHeight = src.UnlimitedHeight;
  807. PrintOnRollPaper = src.PrintOnRollPaper;
  808. UnlimitedWidth = src.UnlimitedWidth;
  809. UnlimitedHeightValue = src.UnlimitedHeightValue;
  810. UnlimitedWidthValue = src.UnlimitedWidthValue;
  811. }
  812. /// <inheritdoc/>
  813. public override void Serialize(FRWriter writer)
  814. {
  815. ReportPage c = writer.DiffObject as ReportPage;
  816. base.Serialize(writer);
  817. if (ExportAlias != c.ExportAlias)
  818. writer.WriteStr("ExportAlias", ExportAlias);
  819. if (Landscape != c.Landscape)
  820. writer.WriteBool("Landscape", Landscape);
  821. if (FloatDiff(PaperWidth, c.PaperWidth) || Landscape != c.Landscape)
  822. writer.WriteFloat("PaperWidth", PaperWidth);
  823. if (FloatDiff(PaperHeight, c.PaperHeight) || Landscape != c.Landscape)
  824. writer.WriteFloat("PaperHeight", PaperHeight);
  825. if (RawPaperSize != c.RawPaperSize)
  826. writer.WriteInt("RawPaperSize", RawPaperSize);
  827. if (FloatDiff(LeftMargin, c.LeftMargin))
  828. writer.WriteFloat("LeftMargin", LeftMargin);
  829. if (FloatDiff(TopMargin, c.TopMargin))
  830. writer.WriteFloat("TopMargin", TopMargin);
  831. if (FloatDiff(RightMargin, c.RightMargin))
  832. writer.WriteFloat("RightMargin", RightMargin);
  833. if (FloatDiff(BottomMargin, c.BottomMargin))
  834. writer.WriteFloat("BottomMargin", BottomMargin);
  835. if (MirrorMargins != c.MirrorMargins)
  836. writer.WriteBool("MirrorMargins", MirrorMargins);
  837. WritePreview(writer, c);
  838. Columns.Serialize(writer, c.Columns);
  839. if (Guides.Count > 0)
  840. writer.WriteValue("Guides", Guides);
  841. Border.Serialize(writer, "Border", c.Border);
  842. Fill.Serialize(writer, "Fill", c.Fill);
  843. Watermark.Serialize(writer, "Watermark", c.Watermark);
  844. if (TitleBeforeHeader != c.TitleBeforeHeader)
  845. writer.WriteBool("TitleBeforeHeader", TitleBeforeHeader);
  846. if (OutlineExpression != c.OutlineExpression)
  847. writer.WriteStr("OutlineExpression", OutlineExpression);
  848. if (PrintOnPreviousPage != c.PrintOnPreviousPage)
  849. writer.WriteBool("PrintOnPreviousPage", PrintOnPreviousPage);
  850. if (ResetPageNumber != c.ResetPageNumber)
  851. writer.WriteBool("ResetPageNumber", ResetPageNumber);
  852. if (ExtraDesignWidth != c.ExtraDesignWidth)
  853. writer.WriteBool("ExtraDesignWidth", ExtraDesignWidth);
  854. if (StartOnOddPage != c.StartOnOddPage)
  855. writer.WriteBool("StartOnOddPage", StartOnOddPage);
  856. if (BackPage != c.BackPage)
  857. writer.WriteBool("BackPage", BackPage);
  858. if (StartPageEvent != c.StartPageEvent)
  859. writer.WriteStr("StartPageEvent", StartPageEvent);
  860. if (FinishPageEvent != c.FinishPageEvent)
  861. writer.WriteStr("FinishPageEvent", FinishPageEvent);
  862. if (ManualBuildEvent != c.ManualBuildEvent)
  863. writer.WriteStr("ManualBuildEvent", ManualBuildEvent);
  864. if (UnlimitedHeight != c.UnlimitedHeight)
  865. writer.WriteBool("UnlimitedHeight", UnlimitedHeight);
  866. if (PrintOnRollPaper != c.PrintOnRollPaper)
  867. writer.WriteBool("PrintOnRollPaper", PrintOnRollPaper);
  868. if (UnlimitedWidth != c.UnlimitedWidth)
  869. writer.WriteBool("UnlimitedWidth", UnlimitedWidth);
  870. if (FloatDiff(UnlimitedHeightValue, c.UnlimitedHeightValue))
  871. writer.WriteFloat("UnlimitedHeightValue", UnlimitedHeightValue);
  872. if (FloatDiff(UnlimitedWidthValue, c.UnlimitedWidthValue))
  873. writer.WriteFloat("UnlimitedWidthValue", UnlimitedWidthValue);
  874. }
  875. /// <inheritdoc/>
  876. public override void Draw(FRPaintEventArgs e)
  877. {
  878. if (IsDesigning)
  879. return;
  880. IGraphics g = e.Graphics;
  881. RectangleF pageRect = new RectangleF(0, 0,
  882. WidthInPixels - 1 / e.ScaleX, HeightInPixels - 1 / e.ScaleY);
  883. RectangleF printableRect = new RectangleF(
  884. LeftMargin * Units.Millimeters,
  885. TopMargin * Units.Millimeters,
  886. (PaperWidth - LeftMargin - RightMargin) * Units.Millimeters,
  887. (PaperHeight - TopMargin - BottomMargin) * Units.Millimeters);
  888. // Fix System.OverflowException when drawing unlimited page without preparing.
  889. if ((UnlimitedHeight || UnlimitedWidth) && !(IsRunning || IsPrinting))
  890. {
  891. pageRect = printableRect;
  892. }
  893. DrawBackground(e, pageRect);
  894. Border.Draw(e, printableRect);
  895. if (Watermark.Enabled)
  896. {
  897. if (!Watermark.ShowImageOnTop)
  898. Watermark.DrawImage(e, pageRect, Report, IsPrinting);
  899. if (!Watermark.ShowTextOnTop)
  900. Watermark.DrawText(e, pageRect, Report, IsPrinting);
  901. }
  902. float leftMargin = (int)Math.Round(LeftMargin * Units.Millimeters * e.ScaleX);
  903. float topMargin = (int)Math.Round(TopMargin * Units.Millimeters * e.ScaleY);
  904. g.TranslateTransform(leftMargin, topMargin);
  905. try
  906. {
  907. foreach (Base c in AllObjects)
  908. {
  909. if (c is ReportComponentBase && c.HasFlag(Flags.CanDraw))
  910. {
  911. ReportComponentBase obj = c as ReportComponentBase;
  912. if (!IsPrinting)
  913. {
  914. #if !MONO
  915. if (!obj.IsVisible(e))
  916. continue;
  917. #endif
  918. }
  919. else
  920. {
  921. if (!obj.Printable)
  922. continue;
  923. else if (obj.Parent is BandBase && !(obj.Parent as BandBase).Printable)
  924. continue;
  925. }
  926. obj.SetDesigning(false);
  927. obj.SetPrinting(IsPrinting);
  928. obj.Draw(e);
  929. obj.SetPrinting(false);
  930. }
  931. }
  932. }
  933. finally
  934. {
  935. g.TranslateTransform(-leftMargin, -topMargin);
  936. }
  937. if (Watermark.Enabled)
  938. {
  939. if (Watermark.ShowImageOnTop)
  940. Watermark.DrawImage(e, pageRect, Report, IsPrinting);
  941. if (Watermark.ShowTextOnTop)
  942. Watermark.DrawText(e, pageRect, Report, IsPrinting);
  943. }
  944. }
  945. internal void InitializeComponents()
  946. {
  947. ObjectCollection allObjects = AllObjects;
  948. foreach (Base obj in allObjects)
  949. {
  950. if (obj is ReportComponentBase)
  951. (obj as ReportComponentBase).InitializeComponent();
  952. }
  953. }
  954. internal void FinalizeComponents()
  955. {
  956. ObjectCollection allObjects = AllObjects;
  957. foreach (Base obj in allObjects)
  958. {
  959. if (obj is ReportComponentBase)
  960. (obj as ReportComponentBase).FinalizeComponent();
  961. }
  962. }
  963. /// <inheritdoc/>
  964. public override string[] GetExpressions()
  965. {
  966. List<string> expressions = new List<string>();
  967. if (!String.IsNullOrEmpty(OutlineExpression))
  968. expressions.Add(OutlineExpression);
  969. return expressions.ToArray();
  970. }
  971. /// <inheritdoc/>
  972. public override void ExtractMacros()
  973. {
  974. Watermark.Text = ExtractDefaultMacros(Watermark.Text);
  975. }
  976. /// <summary>
  977. /// This method fires the <b>StartPage</b> event and the script code connected to the <b>StartPageEvent</b>.
  978. /// </summary>
  979. public void OnStartPage(EventArgs e)
  980. {
  981. if (StartPage != null)
  982. StartPage(this, e);
  983. InvokeEvent(StartPageEvent, e);
  984. }
  985. /// <summary>
  986. /// This method fires the <b>FinishPage</b> event and the script code connected to the <b>FinishPageEvent</b>.
  987. /// </summary>
  988. public void OnFinishPage(EventArgs e)
  989. {
  990. if (FinishPage != null)
  991. FinishPage(this, e);
  992. InvokeEvent(FinishPageEvent, e);
  993. }
  994. /// <summary>
  995. /// This method fires the <b>ManualBuild</b> event and the script code connected to the <b>ManualBuildEvent</b>.
  996. /// </summary>
  997. public void OnManualBuild(EventArgs e)
  998. {
  999. if (ManualBuild != null)
  1000. ManualBuild(this, e);
  1001. InvokeEvent(ManualBuildEvent, e);
  1002. }
  1003. /// <summary>
  1004. /// Updates width of all bands on this page according to page's paper settings.
  1005. /// </summary>
  1006. public void UpdateBandsWidth()
  1007. {
  1008. float pageWidth = (PaperWidth - LeftMargin - RightMargin) * Units.Millimeters;
  1009. float columnWidth = Columns.Width * Units.Millimeters;
  1010. foreach (Base c in AllObjects)
  1011. {
  1012. BandBase b = c as BandBase;
  1013. if (b != null)
  1014. {
  1015. if (Columns.Count > 1 && b.IsColumnDependentBand)
  1016. b.Width = columnWidth;
  1017. else
  1018. b.Width = pageWidth;
  1019. }
  1020. }
  1021. }
  1022. #endregion
  1023. /// <summary>
  1024. /// Initializes a new instance of the <see cref="ReportPage"/> class with default settings.
  1025. /// </summary>
  1026. public ReportPage()
  1027. {
  1028. paperWidth = 210;
  1029. paperHeight = 297;
  1030. leftMargin = 10;
  1031. topMargin = 10;
  1032. rightMargin = 10;
  1033. bottomMargin = 10;
  1034. InitPreview();
  1035. bands = new BandCollection(this);
  1036. guides = new FloatCollection();
  1037. columns = new PageColumns(this);
  1038. border = new Border();
  1039. fill = new SolidFill(Color.White);
  1040. watermark = new Watermark();
  1041. titleBeforeHeader = true;
  1042. startPageEvent = "";
  1043. finishPageEvent = "";
  1044. manualBuildEvent = "";
  1045. BaseName = "Page";
  1046. unlimitedHeight = false;
  1047. printOnRollPaper = false;
  1048. unlimitedWidth = false;
  1049. unlimitedHeightValue = MAX_PAPER_SIZE_MM * Units.Millimeters;
  1050. unlimitedWidthValue = MAX_PAPER_SIZE_MM * Units.Millimeters;
  1051. }
  1052. }
  1053. }