Report.DesignExt.cs 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  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.Cloud.FastReport.ListViewCloud;
  10. using System.Threading.Tasks;
  11. namespace FastReport
  12. {
  13. [ToolboxItem(true), ToolboxBitmap(typeof(Report), "Resources.Report.bmp")]
  14. [Designer("FastReport.VSDesign.ReportComponentDesigner, FastReport.VSDesign, Version=1.0.0.0, Culture=neutral, PublicKeyToken=db7e5ce63278458c, processorArchitecture=MSIL")]
  15. [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")]
  16. partial class Report
  17. {
  18. #region Fields
  19. private Designer designer;
  20. private Form designerForm;
  21. #if !MONO
  22. private SplashForm splashForm;
  23. #endif
  24. #endregion
  25. #region Properties
  26. /// <summary>
  27. /// Gets a reference to the report designer.
  28. /// </summary>
  29. /// <remarks>
  30. /// This property can be used when report is designing. In other cases it returns <b>null</b>.
  31. /// </remarks>
  32. [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  33. public Designer Designer
  34. {
  35. get { return designer; }
  36. set { designer = value; }
  37. }
  38. internal bool IsVSDesignMode
  39. {
  40. get { return DesignMode; }
  41. }
  42. /// <summary>
  43. /// Indicates whether the report is opened from Cloud or not
  44. /// </summary>
  45. internal bool IsOpenedFromCloud => CloudFileInfo != null;
  46. /// <summary>
  47. /// Cloud file info (set if report was opened from Cloud).
  48. /// </summary>
  49. internal CloudFileInfo CloudFileInfo { get; set; }
  50. #endregion
  51. #region Private Methods
  52. private void DisposeDesignerForm()
  53. {
  54. designerForm.Dispose();
  55. designerForm = null;
  56. designer = null;
  57. foreach (Base c in AllObjects)
  58. c.SetDesigning(false);
  59. }
  60. private void OnCloseDesigner(Object sender, FormClosedEventArgs e)
  61. {
  62. DisposeDesignerForm();
  63. }
  64. #if !MONO
  65. private void ShowSplashScreen()
  66. {
  67. splashForm = new SplashForm();
  68. Application.AddMessageFilter(splashForm);
  69. splashForm.Show();
  70. Config.DesignerSettings.DesignerLoaded += HideSplashScreen;
  71. }
  72. private void HideSplashScreen(object sender, EventArgs e)
  73. {
  74. Config.DesignerSettings.DesignerLoaded -= HideSplashScreen;
  75. splashForm.Hide();
  76. // without message filter and delay all events that were triggered on the splashscreen will be redirected to the main form
  77. Timer t = new Timer();
  78. t.Interval = 500;
  79. t.Tick += delegate (object sender_, EventArgs e_)
  80. {
  81. t.Stop();
  82. Application.RemoveMessageFilter(splashForm);
  83. };
  84. t.Start();
  85. }
  86. #endif
  87. #endregion
  88. #region Public Methods
  89. /// <summary>
  90. /// Runs the report designer.
  91. /// </summary>
  92. /// <returns><b>true</b> if report was modified, otherwise <b>false</b>.</returns>
  93. public bool Design()
  94. {
  95. return Design(true);
  96. }
  97. /// <summary>
  98. /// Runs the report designer.
  99. /// </summary>
  100. /// <param name="modal">A value indicates whether the designer should run modally.</param>
  101. /// <returns><b>true</b> if report was modified, otherwise <b>false</b>.</returns>
  102. public bool Design(bool modal)
  103. {
  104. return Design(modal, null);
  105. }
  106. /// <summary>
  107. /// Runs the report designer.
  108. /// </summary>
  109. /// <param name="mdiParent">The main MDI form which will be a parent for the designer.</param>
  110. /// <returns><b>true</b> if report was modified, otherwise <b>false</b>.</returns>
  111. public bool Design(Form mdiParent)
  112. {
  113. return Design(false, mdiParent);
  114. }
  115. private Form CreateDesignerForm(bool welcomeEnabled)
  116. {
  117. #if (WPF || AVALONIA)
  118. bool saveUseCustomWindowChrome = Form.UseCustomWindowChrome;
  119. if (Config.UseCompactMenu)
  120. Form.UseCustomWindowChrome = true;
  121. #endif
  122. try
  123. {
  124. #if (WPF || AVALONIA)
  125. if (Config.UseRibbon)
  126. return new FastReport.Design.RibbonDesigner.DesignerForm(welcomeEnabled);
  127. return new FastReport.Design.StandardDesigner.DesignerForm(welcomeEnabled);
  128. #else
  129. return new FastReport.Design.StandardDesigner.DesignerForm(welcomeEnabled);
  130. #endif
  131. }
  132. finally
  133. {
  134. #if (WPF || AVALONIA)
  135. Form.UseCustomWindowChrome = saveUseCustomWindowChrome;
  136. #endif
  137. }
  138. }
  139. private bool Design(bool modal, Form mdiParent)
  140. {
  141. if (designer != null)
  142. return false;
  143. EnsureInit();
  144. #if !MONO
  145. if (Config.SplashScreenEnabled)
  146. ShowSplashScreen();
  147. #endif
  148. designerForm = CreateDesignerForm(true);
  149. (designerForm as IDesignerForm).Designer.Report = this;
  150. designerForm.MdiParent = mdiParent;
  151. designerForm.ShowInTaskbar = Config.DesignerSettings.ShowInTaskbar;
  152. if (modal)
  153. {
  154. designerForm.ShowDialog();
  155. bool modified = designer.Modified;
  156. DisposeDesignerForm();
  157. return modified;
  158. }
  159. else
  160. {
  161. designerForm.FormClosed += new FormClosedEventHandler(OnCloseDesigner);
  162. designerForm.Show();
  163. }
  164. return false;
  165. }
  166. #if AVALONIA
  167. /// <summary>
  168. /// Runs the report designer async way.
  169. /// </summary>
  170. /// <returns><b>true</b> if report was modified, otherwise <b>false</b>.</returns>
  171. public async Task<bool> DesignAsync()
  172. {
  173. if (designer != null)
  174. return false;
  175. EnsureInit();
  176. designerForm = CreateDesignerForm(true);
  177. (designerForm as IDesignerForm).Designer.Report = this;
  178. designerForm.ShowInTaskbar = Config.DesignerSettings.ShowInTaskbar;
  179. await designerForm.ShowDialogAsync();
  180. bool modified = designer.Modified;
  181. DisposeDesignerForm();
  182. return modified;
  183. }
  184. #endif
  185. internal async Task<bool> DesignPreviewPage()
  186. {
  187. Designer saveDesigner = Designer;
  188. Form designerForm = CreateDesignerForm(false);
  189. designer = (designerForm as IDesignerForm).Designer;
  190. bool modified = false;
  191. try
  192. {
  193. designer.Restrictions.DontChangePageOptions = true;
  194. designer.Restrictions.DontChangeReportOptions = true;
  195. designer.Restrictions.DontCreatePage = true;
  196. designer.Restrictions.DontCreateReport = true;
  197. designer.Restrictions.DontDeletePage = true;
  198. designer.Restrictions.DontCopyPage = true;
  199. designer.Restrictions.DontEditData = true;
  200. designer.Restrictions.DontInsertBand = true;
  201. designer.Restrictions.DontLoadReport = true;
  202. designer.Restrictions.DontPreviewReport = true;
  203. designer.Restrictions.DontShowRecentFiles = true;
  204. designer.IsPreviewPageDesigner = true;
  205. designer.Report = this;
  206. designer.SelectionChanged(null);
  207. #if AVALONIA
  208. await designerForm.ShowDialogAsync();
  209. #else
  210. designerForm.ShowDialog();
  211. #endif
  212. }
  213. finally
  214. {
  215. modified = designer.Modified;
  216. designerForm.Dispose();
  217. designer = saveDesigner;
  218. }
  219. return modified;
  220. }
  221. #endregion
  222. /// <summary>
  223. /// Prompts user for a password.
  224. /// </summary>
  225. /// <returns>A password if dialog was closed with OK button; otherwise, an empty string.</returns>
  226. public string ShowPasswordForm()
  227. {
  228. using (AskPasswordForm form = new AskPasswordForm())
  229. {
  230. if (form.ShowDialog() == DialogResult.OK)
  231. return form.Password;
  232. }
  233. return string.Empty;
  234. }
  235. private void SerializeDesign(FRWriter writer, Report c)
  236. {
  237. PrintSettings.Serialize(writer, c.PrintSettings);
  238. EmailSettings.Serialize(writer, c.EmailSettings);
  239. }
  240. private void InitDesign()
  241. {
  242. printSettings = new PrintSettings();
  243. emailSettings = new EmailSettings();
  244. }
  245. private void ClearDesign()
  246. {
  247. PrintSettings.Clear();
  248. EmailSettings.Clear();
  249. }
  250. private void DisposeDesign()
  251. {
  252. printSettings.Dispose();
  253. }
  254. }
  255. }