DesignerForm.cs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. using FastReport.Forms;
  2. using FastReport.Utils;
  3. using System;
  4. using System.Windows.Forms;
  5. namespace FastReport.Design.StandardDesigner
  6. {
  7. /// <summary>
  8. /// Represents standard designer's form.
  9. /// </summary>
  10. /// <remarks>
  11. /// This form contains the <see cref="DesignerControl"/>. Use the <see cref="Designer"/>
  12. /// property to get access to this control.
  13. /// <para/>Usually you don't need to create an instance of this class. The designer can be called
  14. /// using the <see cref="FastReport.Report.Design()"/> method of
  15. /// the <see cref="FastReport.Report"/> instance.
  16. /// <para/>If you decided to use this class, you need:
  17. /// <list type="bullet">
  18. /// <item>
  19. /// <description>create an instance of this class;</description>
  20. /// </item>
  21. /// <item>
  22. /// <description>set the <b>Designer.Report</b> property to report that you need to design;</description>
  23. /// </item>
  24. /// <item>
  25. /// <description>call either <b>ShowModal</b> or <b>Show</b> methods to display a form.</description>
  26. /// </item>
  27. /// </list>
  28. /// </remarks>
  29. public partial class DesignerForm : BaseForm, IDesignerForm
  30. {
  31. /// <summary>
  32. /// Gets a reference to the <see cref="DesignerControl"/> control which is actually a designer.
  33. /// </summary>
  34. public Designer Designer { get; }
  35. private void DesignerForm_Load(object sender, EventArgs e)
  36. {
  37. // bug/inconsistent behavior in .Net: if we set WindowState to Maximized, the
  38. // Load event will be fired *after* the form is shown.
  39. bool maximized = Storage.RestoreFormState(true);
  40. Designer.RestoreConfig();
  41. if (maximized)
  42. WindowState = FormWindowState.Maximized;
  43. Config.DesignerSettings.OnDesignerLoaded(Designer, EventArgs.Empty);
  44. Designer.StartAutoSave();
  45. }
  46. private void DesignerForm_FormClosing(object sender, FormClosingEventArgs e)
  47. {
  48. Designer.ParentFormClosing(e);
  49. if (!e.Cancel)
  50. {
  51. Storage.SaveFormState();
  52. Designer.SaveConfig();
  53. }
  54. }
  55. private void UpdateUIStyle()
  56. {
  57. #if (WPF || AVALONIA)
  58. var ct = UIStyleUtils.GetColorTable(Designer.UIStyle);
  59. this.window.Resources["Title.Background"] = Helper.GetBrush(ct.WindowTitle.GradientBegin);
  60. this.window.Resources["Border.Foreground"] = Helper.GetBrush(ct.WindowTitle.BorderColor);
  61. this.window.Resources["Button.MouseOver.Background"] = Helper.GetBrush(ct.WindowTitle.HighlightButton);
  62. this.window.Resources["Button.Static.Foreground"] = this.window.Resources["Button.MouseOver.Foreground"] = this.window.Resources["Title.Foreground"] = Helper.GetBrush(ct.WindowTitle.ForeColor);
  63. #endif
  64. }
  65. private void DesignerForm_FormClosed(object sender, FormClosedEventArgs e)
  66. {
  67. Config.DesignerSettings.OnDesignerClosed(Designer, EventArgs.Empty);
  68. Designer.StopAutoSave();
  69. }
  70. /// <inheritdoc/>
  71. public override void UpdateDpiDependencies()
  72. {
  73. base.UpdateDpiDependencies();
  74. Designer.UpdateDpiDependencies(this);
  75. }
  76. /// <summary>
  77. /// Creates a new instance of the <see cref="DesignerForm"/> class with default settings.
  78. /// </summary>
  79. public DesignerForm(bool fakeArg)
  80. {
  81. InitializeComponent();
  82. RightToLeft = Config.RightToLeft ? RightToLeft.Yes : RightToLeft.No;
  83. var designer = new DesignerControl();
  84. Designer = designer;
  85. designer.Dock = DockStyle.Fill;
  86. designer.UIStyle = Config.UIStyle;
  87. Controls.Add(designer);
  88. Font = DrawUtils.DefaultFont;
  89. Icon = Config.DesignerSettings.Icon;
  90. #if (WPF || AVALONIA)
  91. Shown += (s, e) => designer.UpdateFirstDialogPage();
  92. if (IsCustomWindowChrome)
  93. {
  94. (this.window as IForm).ExtendedAppArea = true;
  95. // to avoid title flicker at startup
  96. (this.window as IForm).ExtendedAppAreaSize = 10000;
  97. designer.MainMenu.AutoSize = true;
  98. var menu = designer.MainMenu.menu;
  99. #if WPF
  100. menu.Padding = new System.Windows.Thickness(28, 3, 4, 3);
  101. #elif AVALONIA
  102. menu.Padding = new Avalonia.Thickness(28, 3, 4, 3);
  103. #endif
  104. menu.LayoutUpdated += (s, e) =>
  105. {
  106. if (menu.IsVisible)
  107. (this.window as IForm).ExtendedAppAreaSize = menu.DesiredSize.Width;
  108. };
  109. }
  110. designer.UIStyleChanged += (s, e) =>
  111. {
  112. UpdateUIStyle();
  113. };
  114. #endif
  115. #if Demo && !AVALONIA
  116. Shown += (s, e) => Throttle.Execute(() => FRMessageBox.Information("Demo version"), 1500);
  117. #endif
  118. UpdateDpiDependencies();
  119. UpdateUIStyle();
  120. }
  121. }
  122. }