ToolWindowBase.cs 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  1. using System;
  2. using System.Drawing;
  3. using System.Windows.Forms;
  4. using FastReport.Controls;
  5. using FastReport.Forms;
  6. using FastReport.Utils;
  7. #if !MONO
  8. using FastReport.DevComponents.DotNetBar;
  9. #endif
  10. namespace FastReport.Design.ToolWindows
  11. {
  12. /// <summary>
  13. /// Base class for all tool windows such as "Properties", "Data Dictionary" etc.
  14. /// </summary>
  15. /// <remarks>
  16. /// <para>Use this class to create own tool window. To do this:</para>
  17. /// <para>- in the constructor, set the <b>Name</b> and <b>Image</b> properties and create necessary controls.
  18. /// The <b>Name</b> will be used to restore window's state;</para>
  19. /// <para>- override the <b>SelectionChanged</b> method. This method is called when current selection
  20. /// is changed. In this method, you should update buttons state to reflect the current selection.
  21. /// Selected objects can be accessed via <b>Designer.SelectedObjects</b> property;</para>
  22. /// <para>- override the <b>UpdateContent</b> method. This method is called when the report
  23. /// content was changed. Typically you need to do the same actions in <b>SelectionChanged</b> and
  24. /// <b>UpdateContent</b> methods;</para>
  25. /// <para>- to register a toolwindow, add its type to the <see cref="DesignerPlugins"/> global collection:
  26. /// <code>
  27. /// DesignerPlugins.Add(typeof(MyToolWindow));
  28. /// </code>
  29. /// </para>
  30. /// </remarks>
  31. #if !MONO
  32. public class ToolWindowBase : DockContainerItem, IDesignerPlugin
  33. #else
  34. public class ToolWindowBase : PageControlPage, IDesignerPlugin
  35. #endif
  36. {
  37. #region Fields
  38. private Designer designer;
  39. private bool locked;
  40. #if !MONO
  41. private eShortcut shortcut;
  42. #endif
  43. #endregion
  44. #region Properties
  45. /// <summary>
  46. /// Gets the report designer.
  47. /// </summary>
  48. public Designer Designer
  49. {
  50. get { return designer; }
  51. }
  52. /// <summary>
  53. /// Gets a value indicating that window is locked.
  54. /// </summary>
  55. public bool Locked
  56. {
  57. get { return locked; }
  58. }
  59. /// <inheritdoc/>
  60. public string PluginName
  61. {
  62. get { return Name; }
  63. }
  64. #if !MONO
  65. /// <summary>
  66. /// Gets or sets shortcut keys used to show this toolwindow.
  67. /// </summary>
  68. public eShortcut Shortcut
  69. {
  70. get { return shortcut; }
  71. set { shortcut = value; }
  72. }
  73. /// <summary>
  74. /// Gets or sets a value indicating that the toolwindow can be closed by the x button.
  75. /// </summary>
  76. public bool CanHide
  77. {
  78. get { return Bar.CanHide; }
  79. set { Bar.CanHide = value; }
  80. }
  81. internal Bar Bar
  82. {
  83. get
  84. {
  85. BaseItem item = this;
  86. while (item.Parent != null)
  87. item = item.Parent;
  88. return item.ContainerControl as Bar;
  89. }
  90. }
  91. /// <summary>
  92. /// Gets a parent control that contains all controls.
  93. /// </summary>
  94. /// <remarks>
  95. /// Add your control to the parent control Controls collection.
  96. /// </remarks>
  97. public Control ParentControl
  98. {
  99. get { return Control; }
  100. }
  101. #endif
  102. #endregion
  103. #region Private Methods
  104. #if !MONO
  105. private Bar CreateBar()
  106. {
  107. Bar bar = new Bar();
  108. bar.Name = Name + "Bar";
  109. bar.CanHide = true;
  110. bar.CloseSingleTab = true;
  111. bar.GrabHandleStyle = eGrabHandleStyle.Caption;
  112. bar.LayoutType = eLayoutType.DockContainer;
  113. bar.Stretch = true;
  114. bar.AutoSyncBarCaption = true;
  115. DockTo(bar);
  116. return bar;
  117. }
  118. #endif
  119. #endregion
  120. #region Public Methods
  121. #if !MONO
  122. internal void DoDefaultDock()
  123. {
  124. DockTo(Designer.DotNetBarManager.RightDockSite, Designer.DataWindow, eDockSide.Top);
  125. }
  126. internal void DockTo(DockSite site)
  127. {
  128. site.GetDocumentUIManager().Dock(CreateBar());
  129. }
  130. internal void DockTo(DockSite site, ToolWindowBase referenceWindow, eDockSide side)
  131. {
  132. site.GetDocumentUIManager().Dock(referenceWindow.Bar, CreateBar(), side);
  133. }
  134. internal void DockTo(ToolWindowBase win)
  135. {
  136. DockTo(win.Bar);
  137. }
  138. internal void DockTo(Bar bar)
  139. {
  140. bar.Controls.Add(Control);
  141. bar.Items.Add(this);
  142. }
  143. /// <summary>
  144. /// Shows the toolwindow.
  145. /// </summary>
  146. public void Show()
  147. {
  148. // force SetDockContainerVisible to do the work
  149. Visible = false;
  150. BarUtilities.SetDockContainerVisible(this, true);
  151. Activate();
  152. }
  153. /// <summary>
  154. /// Hides the toolwindow.
  155. /// </summary>
  156. public void Hide()
  157. {
  158. BarUtilities.SetDockContainerVisible(this, false);
  159. }
  160. internal void Close()
  161. {
  162. Bar bar = Bar;
  163. if (bar != null)
  164. bar.CloseDockTab(this);
  165. }
  166. internal void Activate()
  167. {
  168. Bar bar = Bar;
  169. if (bar != null)
  170. {
  171. bar.SelectedDockContainerItem = this;
  172. if (bar.AutoHide)
  173. bar.AutoHide = false;
  174. }
  175. }
  176. internal ButtonItem AddButton(EventHandler click)
  177. {
  178. return AddButton(-1, click);
  179. }
  180. internal ButtonItem AddButton(int imageIndex, EventHandler click)
  181. {
  182. ButtonItem button = new ButtonItem();
  183. button.ImageIndex = imageIndex;
  184. if (click != null)
  185. button.Click += click;
  186. return button;
  187. }
  188. internal void UpdateImages(SubItemsCollection items)
  189. {
  190. foreach (BaseItem item in items)
  191. {
  192. ButtonItem b = item as ButtonItem;
  193. if (b != null && b.ImageIndex != -1)
  194. b.Image = Designer.GetImage(b.ImageIndex);
  195. UpdateImages(item.SubItems);
  196. }
  197. }
  198. #else
  199. internal ToolStripButton AddButton(int imageIndex, EventHandler click)
  200. {
  201. ToolStripButton btn = new ToolStripButton();
  202. btn.Image = this.GetImage(imageIndex);
  203. btn.Click += click;
  204. return btn;
  205. }
  206. internal ToolStripMenuItem AddMenuItem(int imageIndex, EventHandler click)
  207. {
  208. ToolStripMenuItem mi = new ToolStripMenuItem();
  209. mi.Image = this.GetImage(imageIndex);
  210. mi.Click += click;
  211. return mi;
  212. }
  213. internal ToolStripMenuItem AddMenuItem(EventHandler click)
  214. {
  215. return AddMenuItem(-1, click);
  216. }
  217. #endif
  218. #endregion
  219. #region IDesignerPlugin
  220. /// <inheritdoc/>
  221. public virtual void SaveState()
  222. {
  223. }
  224. /// <inheritdoc/>
  225. public virtual void RestoreState()
  226. {
  227. }
  228. /// <inheritdoc/>
  229. public virtual void SelectionChanged()
  230. {
  231. }
  232. /// <inheritdoc/>
  233. public virtual void UpdateContent()
  234. {
  235. }
  236. /// <inheritdoc/>
  237. public virtual void Lock()
  238. {
  239. locked = true;
  240. }
  241. /// <inheritdoc/>
  242. public virtual void Unlock()
  243. {
  244. locked = false;
  245. UpdateContent();
  246. }
  247. /// <inheritdoc/>
  248. public virtual void Localize()
  249. {
  250. }
  251. /// <summary>
  252. /// Implements <see cref="IDesignerPlugin.GetOptionsPage"/> method.
  253. /// </summary>
  254. /// <returns>The options page, if implemented; otherwise, <b>null</b>.</returns>
  255. public virtual DesignerOptionsPage GetOptionsPage()
  256. {
  257. return null;
  258. }
  259. /// <inheritdoc/>
  260. public virtual void UpdateUIStyle()
  261. {
  262. }
  263. /// <inheritdoc/>
  264. #if !MONO
  265. public new virtual void UpdateDpiDependencies()
  266. {
  267. if (Bar != null)
  268. {
  269. Bar.UpdateDpiDependencies();
  270. // this will take effect if high dpi is not enabled in DpiHelper
  271. Bar.DockTabStripHeight = Designer.LogicalToDevice(25);
  272. Bar.PaddingLeft = -2;
  273. Bar.PaddingRight = -2;
  274. Bar.PaddingTop = -2;
  275. Bar.PaddingBottom = -2;
  276. }
  277. base.UpdateDpiDependencies();
  278. }
  279. #else
  280. public virtual void UpdateDpiDependencies()
  281. {
  282. }
  283. #endif
  284. #endregion
  285. /// <summary>
  286. /// Initializes a new instance of the <see cref="ToolWindowBase"/> class with default settings.
  287. /// </summary>
  288. /// <param name="designer">The report designer.</param>
  289. /// <remarks>
  290. /// You don't need to call this constructor. The designer will do this automatically.
  291. /// </remarks>
  292. public ToolWindowBase(Designer designer) : base()
  293. {
  294. this.designer = designer;
  295. #if !MONO
  296. shortcut = eShortcut.None;
  297. Control = new PanelDockContainer();
  298. #endif
  299. }
  300. }
  301. }