ReportPage.cs 44 KB

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