using System; using System.Drawing; using System.ComponentModel; using System.Windows.Forms; using FastReport.Utils; using FastReport.Forms; #if !MONO using FastReport.DevComponents.DotNetBar; #endif namespace FastReport.Design.Toolbars { /// /// Base class for all designer toolbars. /// /// /// Use this class to write own designer's toolbar. To do this: /// - in the constructor, set the Name property and create toolbar buttons. /// The Name will be used to restore toolbar'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 toolbar, add its type to the global collection: /// /// DesignerPlugins.Add(typeof(MyToolbar)); /// /// /// [ToolboxItem(false)] #if !MONO public class ToolbarBase : Bar, IDesignerPlugin #else public class ToolbarBase : ToolStrip, IDesignerPlugin #endif { #region Fields private Designer designer; #if !MONO private CustomizeItem customizeItem; #endif #endregion #region Properties /// /// Gets the report designer. /// public Designer Designer { get { return designer; } } /// public string PluginName { get { return Name; } } #if !MONO internal CustomizeItem CustomizeItem { get { return customizeItem; } } #endif #endregion #region IDesignerPlugin /// public virtual void SaveState() { #if MONO XmlItem xi = Config.Root.FindItem("Designer").FindItem(Name); xi.SetProp("Visible", Visible ? "1" : "0"); // xi.SetProp("Left", Location.X.ToString()); // xi.SetProp("Top", Location.Y.ToString()); #endif } /// public virtual void RestoreState() { #if MONO XmlItem xi = Config.Root.FindItem("Designer").FindItem(Name); Visible = xi.GetProp("Visible") != "0"; // string left = xi.GetProp("Left"); // string top = xi.GetProp("Top"); // if (left != "" && top != "") // Location = new Point(int.Parse(left), int.Parse(top)); #endif } /// public virtual void SelectionChanged() { } /// public virtual void UpdateContent() { } /// public void Lock() { } /// public void Unlock() { UpdateContent(); } /// public virtual void Localize() { #if !MONO customizeItem.Text = Res.Get("Designer,Toolbar,AddOrRemove"); #endif } /// public virtual DesignerOptionsPage GetOptionsPage() { return null; } /// public virtual void UpdateUIStyle() { #if !MONO Style = UIStyleUtils.GetDotNetBarStyle(Designer.UIStyle); #else Renderer = UIStyleUtils.GetToolStripRenderer(Designer.UIStyle); #endif } /// public new virtual void UpdateDpiDependencies() { SuspendLayout(); Font = Designer.LogicalToDevice(DrawUtils.DefaultFont); #if !MONO base.UpdateDpiDependencies(); foreach (BaseItem item in Items) { ButtonItem b = item as ButtonItem; if (b != null && b.ImageIndex != -1) { // looks like this is the only way to completely refresh the image displayed (including disabled images). b.Image = Designer.GetImage(b.ImageIndex); } } #endif ResumeLayout(); } #endregion #region Public Methods #if !MONO /// /// Creates a new button. /// /// Button's name. /// Button's image index. /// Click handler. /// New button. public ButtonItem CreateButton(string name, int imageIndex, EventHandler click) { return CreateButton(name, imageIndex, "", click); } /// /// Creates a new button. /// /// Button's name. /// Button's image index. /// Button's tooltip text. /// Click handler. /// New button. public ButtonItem CreateButton(string name, int imageIndex, string tooltip, EventHandler click) { ButtonItem item = new ButtonItem(); item.Name = name; item.ImageIndex = imageIndex; item.Tooltip = tooltip; if (click != null) item.Click += click; return item; } internal void SetItemText(BaseItem item, string text) { item.Tooltip = text; item.Text = text; } #else /// /// Creates a new button. /// /// Button's name. /// Button's image index. /// Click handler. /// New button. public ToolStripButton CreateButton(string name, int imageIndex, EventHandler click) { ToolStripButton item = new ToolStripButton(); item.Name = name; item.Image = this.GetImage(imageIndex); item.DisplayStyle = ToolStripItemDisplayStyle.Image; item.AutoSize = false; item.Size = new Size(23, 22); if (click != null) item.Click += click; return item; } /// /// Creates a new split button. /// /// Button's name. /// Button's image index. /// Click handler. /// New split button. public ToolStripSplitButton CreateSplitButton(string name, int imageIndex, EventHandler click) { ToolStripSplitButton item = new ToolStripSplitButton(); item.Name = name; item.Image = this.GetImage(imageIndex); item.DisplayStyle = ToolStripItemDisplayStyle.Image; if (click != null) item.Click += click; return item; } internal void SetItemText(ToolStripItem item, string text) { item.ToolTipText = text; item.Text = text; } #endif #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 ToolbarBase(Designer designer) : base() { this.designer = designer; #if !MONO GrabHandleStyle = eGrabHandleStyle.Office2003; customizeItem = new CustomizeItem(); customizeItem.CustomizeItemVisible = false; #else Dock = DockStyle.None; #endif } } }