123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131 |
- using FastReport.Forms;
- using FastReport.Utils;
- using System;
- using System.Windows.Forms;
- namespace FastReport.Design.RibbonDesigner
- {
- /// <summary>
- /// Represents Ribbon designer's form.
- /// </summary>
- /// <remarks>
- /// This form contains the <see cref="DesignerControl"/>. Use the <see cref="Designer"/>
- /// property to get access to this control.
- /// <para/>Usually you don't need to create an instance of this class. The designer can be called
- /// using the <see cref="FastReport.Report.Design()"/> method of
- /// the <see cref="FastReport.Report"/> instance.
- /// <para/>If you decided to use this class, you need:
- /// <list type="bullet">
- /// <item>
- /// <description>create an instance of this class;</description>
- /// </item>
- /// <item>
- /// <description>set the <b>Designer.Report</b> property to report that you need to design;</description>
- /// </item>
- /// <item>
- /// <description>call either <b>ShowModal</b> or <b>Show</b> methods to display a form.</description>
- /// </item>
- /// </list>
- /// </remarks>
- public partial class DesignerForm : BaseForm, IDesignerForm
- {
- /// <summary>
- /// Gets a reference to the <see cref="DesignerControl"/> control which is actually a designer.
- /// </summary>
- public Designer Designer { get; }
- private void DesignerForm_Load(object sender, EventArgs e)
- {
- // bug/inconsistent behavior in .Net: if we set WindowState to Maximized, the
- // Load event will be fired *after* the form is shown.
- bool maximized = Storage.RestoreFormState(true);
- Designer.RestoreConfig();
-
- if (maximized)
- WindowState = FormWindowState.Maximized;
- Config.DesignerSettings.OnDesignerLoaded(Designer, EventArgs.Empty);
- Designer.StartAutoSave();
- }
- private void DesignerForm_FormClosing(object sender, FormClosingEventArgs e)
- {
- Designer.ParentFormClosing(e);
- if (!e.Cancel)
- {
- Storage.SaveFormState();
- Designer.SaveConfig();
- }
- }
- private void UpdateUIStyle()
- {
- var ct = UIStyleUtils.GetColorTable(Designer.UIStyle);
- this.window.Resources["Title.Background"] = Helper.GetBrush(ct.WindowTitle.GradientBegin);
- this.window.Resources["Border.Foreground"] = Helper.GetBrush(ct.WindowTitle.BorderColor);
- this.window.Resources["Button.MouseOver.Background"] = Helper.GetBrush(ct.WindowTitle.HighlightButton);
- this.window.Resources["Button.Static.Foreground"] = this.window.Resources["Button.MouseOver.Foreground"] = this.window.Resources["Title.Foreground"] = Helper.GetBrush(ct.WindowTitle.ForeColor);
- }
- private void DesignerForm_FormClosed(object sender, FormClosedEventArgs e)
- {
- Config.DesignerSettings.OnDesignerClosed(Designer, EventArgs.Empty);
- Designer.StopAutoSave();
- }
- /// <inheritdoc/>
- public override void UpdateDpiDependencies()
- {
- base.UpdateDpiDependencies();
- Designer.UpdateDpiDependencies(this);
- }
- /// <summary>
- /// Creates a new instance of the <see cref="DesignerForm"/> class with default settings.
- /// </summary>
- public DesignerForm(bool fakeArg)
- {
- InitializeComponent();
- RightToLeft = Config.RightToLeft ? RightToLeft.Yes : RightToLeft.No;
- var designer = new DesignerControl();
- Designer = designer;
- designer.Dock = DockStyle.Fill;
- designer.UIStyle = Config.UIStyle;
- Controls.Add(designer);
- Font = DrawUtils.DefaultFont;
- Icon = Config.DesignerSettings.Icon;
- Shown += (s, e) => designer.UpdateFirstDialogPage();
- if (IsCustomWindowChrome)
- {
- (this.window as IForm).ExtendedAppArea = true;
- // to avoid title flicker at startup
- (this.window as IForm).ExtendedAppAreaSize = 10000;
- designer.MainMenu.AutoSize = true;
- var menu = designer.MainMenu.menu;
- menu.Padding = new System.Windows.Thickness(menu.Padding.Left + 25, 3, menu.Padding.Right + 4, 3);
- menu.LayoutUpdated += (s, e) =>
- {
- if (menu.IsVisible)
- (this.window as IForm).ExtendedAppAreaSize = menu.DesiredSize.Width;
- };
- }
- Designer.UIStyleChanged += (s, e) =>
- {
- UpdateUIStyle();
- };
- #if Demo
- Shown += (s, e) => Throttle.Execute(() => FRMessageBox.Information("Demo version"), 1500);
- #endif
- UpdateDpiDependencies();
- UpdateUIStyle();
- }
- }
- }
|