DesignerForm.cs 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. using FastReport.Forms;
  2. using FastReport.Utils;
  3. using System;
  4. using System.Windows.Forms;
  5. namespace FastReport.Design.RibbonDesigner
  6. {
  7. /// <summary>
  8. /// Represents Ribbon 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. var ct = UIStyleUtils.GetColorTable(Designer.UIStyle);
  58. this.window.Resources["Title.Background"] = Helper.GetBrush(ct.WindowTitle.GradientBegin);
  59. this.window.Resources["Border.Foreground"] = Helper.GetBrush(ct.WindowTitle.BorderColor);
  60. this.window.Resources["Button.MouseOver.Background"] = Helper.GetBrush(ct.WindowTitle.HighlightButton);
  61. this.window.Resources["Button.Static.Foreground"] = this.window.Resources["Button.MouseOver.Foreground"] = this.window.Resources["Title.Foreground"] = Helper.GetBrush(ct.WindowTitle.ForeColor);
  62. }
  63. private void DesignerForm_FormClosed(object sender, FormClosedEventArgs e)
  64. {
  65. Config.DesignerSettings.OnDesignerClosed(Designer, EventArgs.Empty);
  66. Designer.StopAutoSave();
  67. }
  68. /// <inheritdoc/>
  69. public override void UpdateDpiDependencies()
  70. {
  71. base.UpdateDpiDependencies();
  72. Designer.UpdateDpiDependencies(this);
  73. }
  74. /// <summary>
  75. /// Creates a new instance of the <see cref="DesignerForm"/> class with default settings.
  76. /// </summary>
  77. public DesignerForm(bool fakeArg)
  78. {
  79. InitializeComponent();
  80. RightToLeft = Config.RightToLeft ? RightToLeft.Yes : RightToLeft.No;
  81. var designer = new DesignerControl();
  82. Designer = designer;
  83. designer.Dock = DockStyle.Fill;
  84. designer.UIStyle = Config.UIStyle;
  85. Controls.Add(designer);
  86. Font = DrawUtils.DefaultFont;
  87. Icon = Config.DesignerSettings.Icon;
  88. Shown += (s, e) => designer.UpdateFirstDialogPage();
  89. if (IsCustomWindowChrome)
  90. {
  91. (this.window as IForm).ExtendedAppArea = true;
  92. // to avoid title flicker at startup
  93. (this.window as IForm).ExtendedAppAreaSize = 10000;
  94. designer.MainMenu.AutoSize = true;
  95. var menu = designer.MainMenu.menu;
  96. menu.Padding = new System.Windows.Thickness(menu.Padding.Left + 25, 3, menu.Padding.Right + 4, 3);
  97. menu.LayoutUpdated += (s, e) =>
  98. {
  99. if (menu.IsVisible)
  100. (this.window as IForm).ExtendedAppAreaSize = menu.DesiredSize.Width;
  101. };
  102. }
  103. Designer.UIStyleChanged += (s, e) =>
  104. {
  105. UpdateUIStyle();
  106. };
  107. #if Demo
  108. Shown += (s, e) => Throttle.Execute(() => FRMessageBox.Information("Demo version"), 1500);
  109. #endif
  110. UpdateDpiDependencies();
  111. UpdateUIStyle();
  112. }
  113. }
  114. }