ReportPage.PreviewExt.cs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. using System.Drawing;
  2. using System.ComponentModel;
  3. using System.Drawing.Printing;
  4. using FastReport.Utils;
  5. namespace FastReport
  6. {
  7. partial class ReportPage
  8. {
  9. #region Fields
  10. private int firstPageSource;
  11. private int otherPagesSource;
  12. private int lastPageSource;
  13. private Duplex duplex;
  14. #endregion
  15. #region Properties
  16. /// <summary>
  17. /// Gets or sets the paper source for the first printed page.
  18. /// </summary>
  19. /// <remarks>
  20. /// <para>
  21. /// This property represents the paper source (printer tray) that will be used when printing
  22. /// the first page. To set the source for other pages, use
  23. /// <see cref="LastPageSource"/> and <see cref="OtherPagesSource"/> properties.
  24. /// </para>
  25. /// <para>
  26. /// Note: This property uses the <b>raw</b> number of the paper source.
  27. /// </para>
  28. /// </remarks>
  29. [DefaultValue(7)]
  30. [Category("Print")]
  31. public int FirstPageSource
  32. {
  33. get { return firstPageSource; }
  34. set { firstPageSource = value; }
  35. }
  36. /// <summary>
  37. /// Gets or sets the paper source for all printed pages except the first one.
  38. /// </summary>
  39. /// <remarks>
  40. /// <para>
  41. /// This property represents the paper source (printer tray) that will be used when printing
  42. /// all pages except the first one and the last one. To set source for first and last pages, use
  43. /// <see cref="FirstPageSource"/> and <see cref="LastPageSource"/> properties.
  44. /// </para>
  45. /// <para>
  46. /// Note: This property uses the <b>raw</b> number of the paper source.
  47. /// </para>
  48. /// </remarks>
  49. [DefaultValue(7)]
  50. [Category("Print")]
  51. public int OtherPagesSource
  52. {
  53. get { return otherPagesSource; }
  54. set { otherPagesSource = value; }
  55. }
  56. /// <summary>
  57. /// Gets or sets the paper source for the last printed page.
  58. /// </summary>
  59. /// <remarks>
  60. /// <para>
  61. /// This property represents the paper source (printer tray) that will be used when printing
  62. /// the last page. To set the source for other pages, use
  63. /// <see cref="FirstPageSource"/> and <see cref="OtherPagesSource"/> properties.
  64. /// </para>
  65. /// <para>
  66. /// Note: This property uses the <b>raw</b> number of the paper source.
  67. /// </para>
  68. /// </remarks>
  69. [DefaultValue(7)]
  70. [Category("Print")]
  71. public int LastPageSource
  72. {
  73. get { return lastPageSource; }
  74. set { lastPageSource = value; }
  75. }
  76. /// <summary>
  77. /// Gets or sets the printer duplex mode that will be used when printing this page.
  78. /// </summary>
  79. [DefaultValue(Duplex.Default)]
  80. [Category("Print")]
  81. public Duplex Duplex
  82. {
  83. get { return duplex; }
  84. set { duplex = value; }
  85. }
  86. #endregion
  87. #region Public Methods
  88. internal void DrawSearchHighlight(FRPaintEventArgs e, int objIndex, CharacterRange range)
  89. {
  90. IGraphics g = e.Graphics;
  91. float leftMargin = LeftMargin * Units.Millimeters * e.ScaleX;
  92. float topMargin = TopMargin * Units.Millimeters * e.ScaleY;
  93. ObjectCollection allObjects = AllObjects;
  94. if (objIndex < 0 && objIndex >= allObjects.Count)
  95. return;
  96. ISearchable obj = allObjects[objIndex] as ISearchable;
  97. if (obj != null)
  98. {
  99. g.TranslateTransform(leftMargin, topMargin);
  100. try
  101. {
  102. obj.DrawSearchHighlight(e, range);
  103. }
  104. finally
  105. {
  106. g.TranslateTransform(-leftMargin, -topMargin);
  107. }
  108. }
  109. }
  110. internal void Print(FRPaintEventArgs e)
  111. {
  112. try
  113. {
  114. SetPrinting(true);
  115. SetDesigning(false);
  116. Draw(e);
  117. }
  118. finally
  119. {
  120. SetPrinting(false);
  121. }
  122. }
  123. internal ReportComponentBase HitTest(PointF mouse)
  124. {
  125. mouse.X -= LeftMargin * Units.Millimeters;
  126. mouse.Y -= TopMargin * Units.Millimeters;
  127. ObjectCollection allObjects = AllObjects;
  128. for (int i = allObjects.Count - 1; i >= 0; i--)
  129. {
  130. ReportComponentBase c = allObjects[i] as ReportComponentBase;
  131. if (c != null)
  132. {
  133. if (c.PointInObject(mouse))
  134. return c;
  135. }
  136. }
  137. return null;
  138. }
  139. #endregion
  140. private void AssignPreview(ReportPage src)
  141. {
  142. FirstPageSource = src.FirstPageSource;
  143. OtherPagesSource = src.OtherPagesSource;
  144. LastPageSource = src.LastPageSource;
  145. Duplex = src.Duplex;
  146. }
  147. private void WritePreview(FRWriter writer, ReportPage c)
  148. {
  149. if (FirstPageSource != c.FirstPageSource)
  150. writer.WriteInt("FirstPageSource", FirstPageSource);
  151. if (OtherPagesSource != c.OtherPagesSource)
  152. writer.WriteInt("OtherPagesSource", OtherPagesSource);
  153. if (LastPageSource != c.LastPageSource)
  154. writer.WriteInt("LastPageSource", LastPageSource);
  155. if (Duplex != c.Duplex)
  156. writer.WriteValue("Duplex", Duplex);
  157. }
  158. private void InitPreview()
  159. {
  160. firstPageSource = 7;
  161. otherPagesSource = 7;
  162. lastPageSource = 7;
  163. duplex = Duplex.Default;
  164. }
  165. }
  166. }