using FastReport.Controls;
using FastReport.Forms;
using FastReport.Utils;
using System;
using System.Windows.Forms;
namespace FastReport.Design.ToolWindows
{
///
/// Base class for all tool windows such as "Properties", "Data Dictionary" etc.
///
///
/// Use this class to create own tool window. To do this:
/// - in the constructor, set the Name and Image properties and create necessary controls.
/// The Name will be used to restore window's state;
/// - override the SelectionChanged method. This method is called when current selection
/// is changed. In this method, you should update buttons state to reflect the current selection.
/// Selected objects can be accessed via Designer.SelectedObjects property;
/// - override the UpdateContent method. This method is called when the report
/// content was changed. Typically you need to do the same actions in SelectionChanged and
/// UpdateContent methods;
/// - to register a toolwindow, add its type to the global collection:
///
/// DesignerPlugins.Add(typeof(MyToolWindow));
///
///
///
public class ToolWindowBase : PageControlPage, IDesignerPlugin
{
#region Properties
///
/// Gets the report designer.
///
public Designer Designer { get; }
///
/// Gets a value indicating that window is locked.
///
public bool Locked { get; private set; }
///
public string PluginName => Name;
private ControlStorageService storage;
///
/// Gets storage service.
///
public ControlStorageService Storage
{
get
{
if (storage == null)
storage = new ControlStorageService(this, "Designer," + Name);
return storage;
}
}
#endregion
#region Public Methods
internal ToolbarButton AddButton(int imageIndex, EventHandler click) => AddButton(imageIndex, false, click);
internal ToolbarButton AddButton(int imageIndex, bool imageAndText, EventHandler click)
{
var btn = new ToolbarButton("", imageIndex, click);
btn.Image = this.GetImage(imageIndex);
btn.ImageIndex = imageIndex;
if (imageAndText)
btn.DisplayStyle = ToolStripItemDisplayStyle.ImageAndText;
return btn;
}
internal ContextMenuItem AddMenuItem(int imageIndex, EventHandler click)
{
var mi = new ContextMenuItem();
#if !(WPF || AVALONIA)
// Mono: setting ImageIndex does not work in Mono/Linux; Mono/Win displays strange artifacts
mi.Image = this.GetImage(imageIndex);
#else
// WPF: works well, also updates on dpi change
mi.ImageIndex = imageIndex;
#endif
mi.Click += click;
return mi;
}
internal ContextMenuItem AddMenuItem(EventHandler click)
{
return AddMenuItem(-1, click);
}
#endregion
#region IDesignerPlugin
///
public virtual void SaveState()
{
}
///
public virtual void RestoreState()
{
}
///
public virtual void SelectionChanged()
{
}
///
public virtual void UpdateContent()
{
}
///
public virtual void Lock()
{
Locked = true;
}
///
public virtual void Unlock()
{
Locked = false;
UpdateContent();
}
///
public virtual void Localize()
{
}
///
/// Implements method.
///
/// The options page, if implemented; otherwise, null.
public virtual DesignerOptionsPage GetOptionsPage()
{
return null;
}
///
public virtual void UpdateUIStyle()
{
}
///
public virtual void UpdateDpiDependencies()
{
}
#endregion
///
/// Initializes a new instance of the class with default settings.
///
/// The report designer.
///
/// You don't need to call this constructor. The designer will do this automatically.
///
public ToolWindowBase(Designer designer) : base()
{
Designer = designer;
}
}
}