Report.DesignExt.cs 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. using System;
  2. using System.Windows.Forms;
  3. using System.Drawing;
  4. using System.ComponentModel;
  5. using System.ComponentModel.Design.Serialization;
  6. using FastReport.Utils;
  7. using FastReport.Design;
  8. using FastReport.Forms;
  9. using FastReport.Design.StandardDesigner;
  10. namespace FastReport
  11. {
  12. [ToolboxItem(true), ToolboxBitmap(typeof(Report), "Resources.Report.bmp")]
  13. [Designer("FastReport.VSDesign.ReportComponentDesigner, FastReport.VSDesign, Version=1.0.0.0, Culture=neutral, PublicKeyToken=db7e5ce63278458c, processorArchitecture=MSIL")]
  14. [DesignerSerializer("FastReport.VSDesign.ReportCodeDomSerializer, FastReport.VSDesign, Version=1.0.0.0, Culture=neutral, PublicKeyToken=db7e5ce63278458c, processorArchitecture=MSIL", "System.ComponentModel.Design.Serialization.CodeDomSerializer, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
  15. partial class Report
  16. {
  17. #region Fields
  18. private Designer designer;
  19. private BaseForm designerForm;
  20. #if !MONO
  21. private SplashForm splashForm;
  22. #endif
  23. #endregion
  24. #region Properties
  25. /// <summary>
  26. /// Gets a reference to the report designer.
  27. /// </summary>
  28. /// <remarks>
  29. /// This property can be used when report is designing. In other cases it returns <b>null</b>.
  30. /// </remarks>
  31. [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  32. public Designer Designer
  33. {
  34. get { return designer; }
  35. set { designer = value; }
  36. }
  37. internal bool IsVSDesignMode
  38. {
  39. get { return DesignMode; }
  40. }
  41. #endregion
  42. #region Private Methods
  43. private void DisposeDesignerForm()
  44. {
  45. designerForm.Dispose();
  46. designerForm = null;
  47. designer = null;
  48. foreach (Base c in AllObjects)
  49. c.SetDesigning(false);
  50. }
  51. private void OnCloseDesigner(Object sender, FormClosedEventArgs e)
  52. {
  53. DisposeDesignerForm();
  54. }
  55. #if !MONO
  56. private void ShowSplashScreen()
  57. {
  58. splashForm = new SplashForm();
  59. Application.AddMessageFilter(splashForm);
  60. splashForm.Show();
  61. Config.DesignerSettings.DesignerLoaded += HideSplashScreen;
  62. }
  63. private void HideSplashScreen(object sender, EventArgs e)
  64. {
  65. Config.DesignerSettings.DesignerLoaded -= HideSplashScreen;
  66. splashForm.Hide();
  67. // without message filter and delay all events that were triggered on the splashscreen will be redirected to the main form
  68. Timer t = new Timer();
  69. t.Interval = 500;
  70. t.Tick += delegate (object sender_, EventArgs e_)
  71. {
  72. t.Stop();
  73. Application.RemoveMessageFilter(splashForm);
  74. };
  75. t.Start();
  76. }
  77. #endif
  78. #endregion
  79. #region Public Methods
  80. /// <summary>
  81. /// Runs the report designer.
  82. /// </summary>
  83. /// <returns><b>true</b> if report was modified, otherwise <b>false</b>.</returns>
  84. public bool Design()
  85. {
  86. return Design(true);
  87. }
  88. /// <summary>
  89. /// Runs the report designer.
  90. /// </summary>
  91. /// <param name="modal">A value indicates whether the designer should run modally.</param>
  92. /// <returns><b>true</b> if report was modified, otherwise <b>false</b>.</returns>
  93. public bool Design(bool modal)
  94. {
  95. return Design(modal, null);
  96. }
  97. /// <summary>
  98. /// Runs the report designer.
  99. /// </summary>
  100. /// <param name="mdiParent">The main MDI form which will be a parent for the designer.</param>
  101. /// <returns><b>true</b> if report was modified, otherwise <b>false</b>.</returns>
  102. public bool Design(Form mdiParent)
  103. {
  104. return Design(false, mdiParent);
  105. }
  106. private bool Design(bool modal, Form mdiParent)
  107. {
  108. if (designer != null)
  109. return false;
  110. EnsureInit();
  111. #if !MONO
  112. if (Config.SplashScreenEnabled)
  113. ShowSplashScreen();
  114. #endif
  115. designerForm = new DesignerForm(true);
  116. (designerForm as DesignerForm).Designer.Report = this;
  117. designerForm.MdiParent = mdiParent;
  118. designerForm.ShowInTaskbar = Config.DesignerSettings.ShowInTaskbar;
  119. if (modal)
  120. {
  121. designerForm.ShowDialog();
  122. bool modified = designer.Modified;
  123. DisposeDesignerForm();
  124. return modified;
  125. }
  126. else
  127. {
  128. designerForm.FormClosed += new FormClosedEventHandler(OnCloseDesigner);
  129. designerForm.Show();
  130. }
  131. return false;
  132. }
  133. internal bool DesignPreviewPage()
  134. {
  135. Designer saveDesigner = Designer;
  136. Form designerForm = new DesignerForm(
  137. #if MONO
  138. false
  139. #endif
  140. );
  141. designer = (designerForm as DesignerForm).Designer;
  142. bool modified = false;
  143. try
  144. {
  145. designer.Restrictions.DontChangePageOptions = true;
  146. designer.Restrictions.DontChangeReportOptions = true;
  147. designer.Restrictions.DontCreatePage = true;
  148. designer.Restrictions.DontCreateReport = true;
  149. designer.Restrictions.DontDeletePage = true;
  150. designer.Restrictions.DontCopyPage = true;
  151. designer.Restrictions.DontEditData = true;
  152. designer.Restrictions.DontInsertBand = true;
  153. designer.Restrictions.DontLoadReport = true;
  154. designer.Restrictions.DontPreviewReport = true;
  155. designer.Restrictions.DontShowRecentFiles = true;
  156. designer.IsPreviewPageDesigner = true;
  157. designer.Report = this;
  158. designer.SelectionChanged(null);
  159. designerForm.ShowDialog();
  160. }
  161. finally
  162. {
  163. modified = designer.Modified;
  164. designerForm.Dispose();
  165. designer = saveDesigner;
  166. }
  167. return modified;
  168. }
  169. #endregion
  170. private string ShowPaswordForm(string password)
  171. {
  172. using (AskPasswordForm form = new AskPasswordForm())
  173. {
  174. if (form.ShowDialog() == DialogResult.OK)
  175. return form.Password;
  176. }
  177. return password;
  178. }
  179. private void SerializeDesign(FRWriter writer, Report c)
  180. {
  181. PrintSettings.Serialize(writer, c.PrintSettings);
  182. EmailSettings.Serialize(writer, c.EmailSettings);
  183. }
  184. private void InitDesign()
  185. {
  186. printSettings = new PrintSettings();
  187. emailSettings = new EmailSettings();
  188. }
  189. private void ClearDesign()
  190. {
  191. PrintSettings.Clear();
  192. EmailSettings.Clear();
  193. }
  194. private void DisposeDesign()
  195. {
  196. printSettings.Dispose();
  197. }
  198. }
  199. }