using FastReport.Forms;
using FastReport.Utils;
using System;
using System.Windows.Forms;
namespace FastReport.Design.RibbonDesigner
{
///
/// Represents Ribbon designer's form.
///
///
/// This form contains the . Use the
/// property to get access to this control.
/// Usually you don't need to create an instance of this class. The designer can be called
/// using the method of
/// the instance.
/// If you decided to use this class, you need:
///
/// -
/// create an instance of this class;
///
/// -
/// set the Designer.Report property to report that you need to design;
///
/// -
/// call either ShowModal or Show methods to display a form.
///
///
///
public partial class DesignerForm : BaseForm, IDesignerForm
{
///
/// Gets a reference to the control which is actually a designer.
///
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();
}
///
public override void UpdateDpiDependencies()
{
base.UpdateDpiDependencies();
Designer.UpdateDpiDependencies(this);
}
///
/// Creates a new instance of the class with default settings.
///
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();
}
}
}