123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166 |
- using FastReport.Controls;
- using FastReport.Forms;
- using FastReport.Utils;
- using System;
- using System.Windows.Forms;
- namespace FastReport.Design.ToolWindows
- {
- /// <summary>
- /// Base class for all tool windows such as "Properties", "Data Dictionary" etc.
- /// </summary>
- /// <remarks>
- /// <para>Use this class to create own tool window. To do this:</para>
- /// <para>- in the constructor, set the <b>Name</b> and <b>Image</b> properties and create necessary controls.
- /// The <b>Name</b> will be used to restore window's state;</para>
- /// <para>- override the <b>SelectionChanged</b> 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 <b>Designer.SelectedObjects</b> property;</para>
- /// <para>- override the <b>UpdateContent</b> method. This method is called when the report
- /// content was changed. Typically you need to do the same actions in <b>SelectionChanged</b> and
- /// <b>UpdateContent</b> methods;</para>
- /// <para>- to register a toolwindow, add its type to the <see cref="DesignerPlugins"/> global collection:
- /// <code>
- /// DesignerPlugins.Add(typeof(MyToolWindow));
- /// </code>
- /// </para>
- /// </remarks>
- public class ToolWindowBase : PageControlPage, IDesignerPlugin
- {
- #region Properties
- /// <summary>
- /// Gets the report designer.
- /// </summary>
- public Designer Designer { get; }
- /// <summary>
- /// Gets a value indicating that window is locked.
- /// </summary>
- public bool Locked { get; private set; }
- /// <inheritdoc/>
- public string PluginName => Name;
- private ControlStorageService storage;
- /// <summary>
- /// Gets storage service.
- /// </summary>
- 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
- /// <inheritdoc/>
- public virtual void SaveState()
- {
- }
- /// <inheritdoc/>
- public virtual void RestoreState()
- {
- }
- /// <inheritdoc/>
- public virtual void SelectionChanged()
- {
- }
- /// <inheritdoc/>
- public virtual void UpdateContent()
- {
- }
- /// <inheritdoc/>
- public virtual void Lock()
- {
- Locked = true;
- }
- /// <inheritdoc/>
- public virtual void Unlock()
- {
- Locked = false;
- UpdateContent();
- }
- /// <inheritdoc/>
- public virtual void Localize()
- {
- }
- /// <summary>
- /// Implements <see cref="IDesignerPlugin.GetOptionsPage"/> method.
- /// </summary>
- /// <returns>The options page, if implemented; otherwise, <b>null</b>.</returns>
- public virtual DesignerOptionsPage GetOptionsPage()
- {
- return null;
- }
- /// <inheritdoc/>
- public virtual void UpdateUIStyle()
- {
- }
- /// <inheritdoc/>
- public virtual void UpdateDpiDependencies()
- {
- }
- #endregion
- /// <summary>
- /// Initializes a new instance of the <see cref="ToolWindowBase"/> class with default settings.
- /// </summary>
- /// <param name="designer">The report designer.</param>
- /// <remarks>
- /// You don't need to call this constructor. The designer will do this automatically.
- /// </remarks>
- public ToolWindowBase(Designer designer) : base()
- {
- Designer = designer;
- }
- }
- }
|