using System;
using System.Windows.Forms;
using System.Drawing;
using System.ComponentModel;
using System.ComponentModel.Design.Serialization;
using FastReport.Utils;
using FastReport.Design;
using FastReport.Forms;
using FastReport.Cloud.FastReport.ListViewCloud;
using System.Threading.Tasks;
namespace FastReport
{
[ToolboxItem(true), ToolboxBitmap(typeof(Report), "Resources.Report.bmp")]
[Designer("FastReport.VSDesign.ReportComponentDesigner, FastReport.VSDesign, Version=1.0.0.0, Culture=neutral, PublicKeyToken=db7e5ce63278458c, processorArchitecture=MSIL")]
[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")]
partial class Report
{
#region Fields
private Designer designer;
private Form designerForm;
#if !MONO
private SplashForm splashForm;
#endif
#endregion
#region Properties
///
/// Gets a reference to the report designer.
///
///
/// This property can be used when report is designing. In other cases it returns null.
///
[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public Designer Designer
{
get { return designer; }
set { designer = value; }
}
internal bool IsVSDesignMode
{
get { return DesignMode; }
}
///
/// Indicates whether the report is opened from Cloud or not
///
internal bool IsOpenedFromCloud => CloudFileInfo != null;
///
/// Cloud file info (set if report was opened from Cloud).
///
internal CloudFileInfo CloudFileInfo { get; set; }
#endregion
#region Private Methods
private void DisposeDesignerForm()
{
designerForm.Dispose();
designerForm = null;
designer = null;
foreach (Base c in AllObjects)
c.SetDesigning(false);
}
private void OnCloseDesigner(Object sender, FormClosedEventArgs e)
{
DisposeDesignerForm();
}
#if !MONO
private void ShowSplashScreen()
{
splashForm = new SplashForm();
Application.AddMessageFilter(splashForm);
splashForm.Show();
Config.DesignerSettings.DesignerLoaded += HideSplashScreen;
}
private void HideSplashScreen(object sender, EventArgs e)
{
Config.DesignerSettings.DesignerLoaded -= HideSplashScreen;
splashForm.Hide();
// without message filter and delay all events that were triggered on the splashscreen will be redirected to the main form
Timer t = new Timer();
t.Interval = 500;
t.Tick += delegate (object sender_, EventArgs e_)
{
t.Stop();
Application.RemoveMessageFilter(splashForm);
};
t.Start();
}
#endif
#endregion
#region Public Methods
///
/// Runs the report designer.
///
/// true if report was modified, otherwise false.
public bool Design()
{
return Design(true);
}
///
/// Runs the report designer.
///
/// A value indicates whether the designer should run modally.
/// true if report was modified, otherwise false.
public bool Design(bool modal)
{
return Design(modal, null);
}
///
/// Runs the report designer.
///
/// The main MDI form which will be a parent for the designer.
/// true if report was modified, otherwise false.
public bool Design(Form mdiParent)
{
return Design(false, mdiParent);
}
private Form CreateDesignerForm(bool welcomeEnabled)
{
#if (WPF || AVALONIA)
bool saveUseCustomWindowChrome = Form.UseCustomWindowChrome;
if (Config.UseCompactMenu)
Form.UseCustomWindowChrome = true;
#endif
try
{
#if (WPF || AVALONIA)
if (Config.UseRibbon)
return new FastReport.Design.RibbonDesigner.DesignerForm(welcomeEnabled);
return new FastReport.Design.StandardDesigner.DesignerForm(welcomeEnabled);
#else
return new FastReport.Design.StandardDesigner.DesignerForm(welcomeEnabled);
#endif
}
finally
{
#if (WPF || AVALONIA)
Form.UseCustomWindowChrome = saveUseCustomWindowChrome;
#endif
}
}
private bool Design(bool modal, Form mdiParent)
{
if (designer != null)
return false;
EnsureInit();
#if !MONO
if (Config.SplashScreenEnabled)
ShowSplashScreen();
#endif
designerForm = CreateDesignerForm(true);
(designerForm as IDesignerForm).Designer.Report = this;
designerForm.MdiParent = mdiParent;
designerForm.ShowInTaskbar = Config.DesignerSettings.ShowInTaskbar;
if (modal)
{
designerForm.ShowDialog();
bool modified = designer.Modified;
DisposeDesignerForm();
return modified;
}
else
{
designerForm.FormClosed += new FormClosedEventHandler(OnCloseDesigner);
designerForm.Show();
}
return false;
}
#if AVALONIA
///
/// Runs the report designer async way.
///
/// true if report was modified, otherwise false.
public async Task DesignAsync()
{
if (designer != null)
return false;
EnsureInit();
designerForm = CreateDesignerForm(true);
(designerForm as IDesignerForm).Designer.Report = this;
designerForm.ShowInTaskbar = Config.DesignerSettings.ShowInTaskbar;
await designerForm.ShowDialogAsync();
bool modified = designer.Modified;
DisposeDesignerForm();
return modified;
}
#endif
internal async Task DesignPreviewPage()
{
Designer saveDesigner = Designer;
Form designerForm = CreateDesignerForm(false);
designer = (designerForm as IDesignerForm).Designer;
bool modified = false;
try
{
designer.Restrictions.DontChangePageOptions = true;
designer.Restrictions.DontChangeReportOptions = true;
designer.Restrictions.DontCreatePage = true;
designer.Restrictions.DontCreateReport = true;
designer.Restrictions.DontDeletePage = true;
designer.Restrictions.DontCopyPage = true;
designer.Restrictions.DontEditData = true;
designer.Restrictions.DontInsertBand = true;
designer.Restrictions.DontLoadReport = true;
designer.Restrictions.DontPreviewReport = true;
designer.Restrictions.DontShowRecentFiles = true;
designer.IsPreviewPageDesigner = true;
designer.Report = this;
designer.SelectionChanged(null);
#if AVALONIA
await designerForm.ShowDialogAsync();
#else
designerForm.ShowDialog();
#endif
}
finally
{
modified = designer.Modified;
designerForm.Dispose();
designer = saveDesigner;
}
return modified;
}
#endregion
///
/// Prompts user for a password.
///
/// A password if dialog was closed with OK button; otherwise, an empty string.
public string ShowPasswordForm()
{
using (AskPasswordForm form = new AskPasswordForm())
{
if (form.ShowDialog() == DialogResult.OK)
return form.Password;
}
return string.Empty;
}
private void SerializeDesign(FRWriter writer, Report c)
{
PrintSettings.Serialize(writer, c.PrintSettings);
EmailSettings.Serialize(writer, c.EmailSettings);
}
private void InitDesign()
{
printSettings = new PrintSettings();
emailSettings = new EmailSettings();
}
private void ClearDesign()
{
PrintSettings.Clear();
EmailSettings.Clear();
}
private void DisposeDesign()
{
printSettings.Dispose();
}
}
}