using FastReport.Controls; using FastReport.DevComponents.DotNetBar; 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 : DockContainerItem, 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; /// /// Gets or sets shortcut keys used to show this toolwindow. /// public eShortcut Shortcut { get; set; } /// /// Gets or sets a value indicating that the toolwindow can be closed by the x button. /// public bool CanHide { get => Bar.CanHide; set => Bar.CanHide = value; } internal Bar Bar { get { BaseItem item = this; while (item.Parent != null) item = item.Parent; return item.ContainerControl as Bar; } } /// /// Gets the control collection. /// public Control.ControlCollection Controls => Control.Controls; private ControlStorageService storage; public ControlStorageService Storage => storage ?? new ControlStorageService(Control, "Designer," + Name); #endregion #region Private Methods private Bar CreateBar() { Bar bar = new Bar(); bar.Name = Name + "Bar"; bar.CanHide = true; bar.CloseSingleTab = true; bar.GrabHandleStyle = eGrabHandleStyle.Caption; bar.LayoutType = eLayoutType.DockContainer; bar.Stretch = true; bar.AutoSyncBarCaption = true; DockTo(bar); return bar; } #endregion #region Public Methods internal void DoDefaultDock() { DockTo(Designer.DotNetBarManager.RightDockSite, Designer.DataWindow, eDockSide.Top); } internal void DockTo(DockSite site) { site.GetDocumentUIManager().Dock(CreateBar()); } internal void DockTo(DockSite site, ToolWindowBase referenceWindow, eDockSide side) { site.GetDocumentUIManager().Dock(referenceWindow.Bar, CreateBar(), side); } internal void DockTo(ToolWindowBase win) { DockTo(win.Bar); } internal void DockTo(Bar bar) { bar.Controls.Add(Control); bar.Items.Add(this); } /// /// Shows the toolwindow. /// public void Show() { // force SetDockContainerVisible to do the work Visible = false; BarUtilities.SetDockContainerVisible(this, true); Activate(); } /// /// Hides the toolwindow. /// public void Hide() { BarUtilities.SetDockContainerVisible(this, false); } internal void Close() { Bar bar = Bar; if (bar != null) bar.CloseDockTab(this); } internal void Activate() { Bar bar = Bar; if (bar != null) { bar.SelectedDockContainerItem = this; if (bar.AutoHide) bar.AutoHide = false; } } internal ToolbarButton AddButton(int imageIndex, EventHandler click) => AddButton(imageIndex, false, click); internal ToolbarButton AddButton(int imageIndex, bool imageAndText, EventHandler click) { var button = new ToolbarButton("", imageIndex, click); if (imageAndText) button.ButtonStyle = eButtonStyle.ImageAndText; return button; } internal ContextMenuItem AddMenuItem(int imageIndex, EventHandler click) { var mi = new ContextMenuItem(); mi.Image = Designer.GetImage(imageIndex); mi.ImageIndex = imageIndex; 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 new virtual void UpdateDpiDependencies() { if (Bar != null) { Bar.UpdateDpiDependencies(); // this will take effect if high dpi is not enabled in DpiHelper Bar.DockTabStripHeight = Designer.LogicalToDevice(25); Bar.PaddingLeft = -2; Bar.PaddingRight = -2; Bar.PaddingTop = -2; Bar.PaddingBottom = -2; } base.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; Shortcut = eShortcut.None; Control = new PanelDockContainer(); } } }