ToolWindowBase.Mono.cs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. using FastReport.Controls;
  2. using FastReport.Forms;
  3. using FastReport.Utils;
  4. using System;
  5. using System.Windows.Forms;
  6. namespace FastReport.Design.ToolWindows
  7. {
  8. /// <summary>
  9. /// Base class for all tool windows such as "Properties", "Data Dictionary" etc.
  10. /// </summary>
  11. /// <remarks>
  12. /// <para>Use this class to create own tool window. To do this:</para>
  13. /// <para>- in the constructor, set the <b>Name</b> and <b>Image</b> properties and create necessary controls.
  14. /// The <b>Name</b> will be used to restore window's state;</para>
  15. /// <para>- override the <b>SelectionChanged</b> method. This method is called when current selection
  16. /// is changed. In this method, you should update buttons state to reflect the current selection.
  17. /// Selected objects can be accessed via <b>Designer.SelectedObjects</b> property;</para>
  18. /// <para>- override the <b>UpdateContent</b> method. This method is called when the report
  19. /// content was changed. Typically you need to do the same actions in <b>SelectionChanged</b> and
  20. /// <b>UpdateContent</b> methods;</para>
  21. /// <para>- to register a toolwindow, add its type to the <see cref="DesignerPlugins"/> global collection:
  22. /// <code>
  23. /// DesignerPlugins.Add(typeof(MyToolWindow));
  24. /// </code>
  25. /// </para>
  26. /// </remarks>
  27. public class ToolWindowBase : PageControlPage, IDesignerPlugin
  28. {
  29. #region Properties
  30. /// <summary>
  31. /// Gets the report designer.
  32. /// </summary>
  33. public Designer Designer { get; }
  34. /// <summary>
  35. /// Gets a value indicating that window is locked.
  36. /// </summary>
  37. public bool Locked { get; private set; }
  38. /// <inheritdoc/>
  39. public string PluginName => Name;
  40. private ControlStorageService storage;
  41. /// <summary>
  42. /// Gets storage service.
  43. /// </summary>
  44. public ControlStorageService Storage
  45. {
  46. get
  47. {
  48. if (storage == null)
  49. storage = new ControlStorageService(this, "Designer," + Name);
  50. return storage;
  51. }
  52. }
  53. #endregion
  54. #region Public Methods
  55. internal ToolbarButton AddButton(int imageIndex, EventHandler click) => AddButton(imageIndex, false, click);
  56. internal ToolbarButton AddButton(int imageIndex, bool imageAndText, EventHandler click)
  57. {
  58. var btn = new ToolbarButton("", imageIndex, click);
  59. btn.Image = this.GetImage(imageIndex);
  60. btn.ImageIndex = imageIndex;
  61. if (imageAndText)
  62. btn.DisplayStyle = ToolStripItemDisplayStyle.ImageAndText;
  63. return btn;
  64. }
  65. internal ContextMenuItem AddMenuItem(int imageIndex, EventHandler click)
  66. {
  67. var mi = new ContextMenuItem();
  68. #if !(WPF || AVALONIA)
  69. // Mono: setting ImageIndex does not work in Mono/Linux; Mono/Win displays strange artifacts
  70. mi.Image = this.GetImage(imageIndex);
  71. #else
  72. // WPF: works well, also updates on dpi change
  73. mi.ImageIndex = imageIndex;
  74. #endif
  75. mi.Click += click;
  76. return mi;
  77. }
  78. internal ContextMenuItem AddMenuItem(EventHandler click)
  79. {
  80. return AddMenuItem(-1, click);
  81. }
  82. #endregion
  83. #region IDesignerPlugin
  84. /// <inheritdoc/>
  85. public virtual void SaveState()
  86. {
  87. }
  88. /// <inheritdoc/>
  89. public virtual void RestoreState()
  90. {
  91. }
  92. /// <inheritdoc/>
  93. public virtual void SelectionChanged()
  94. {
  95. }
  96. /// <inheritdoc/>
  97. public virtual void UpdateContent()
  98. {
  99. }
  100. /// <inheritdoc/>
  101. public virtual void Lock()
  102. {
  103. Locked = true;
  104. }
  105. /// <inheritdoc/>
  106. public virtual void Unlock()
  107. {
  108. Locked = false;
  109. UpdateContent();
  110. }
  111. /// <inheritdoc/>
  112. public virtual void Localize()
  113. {
  114. }
  115. /// <summary>
  116. /// Implements <see cref="IDesignerPlugin.GetOptionsPage"/> method.
  117. /// </summary>
  118. /// <returns>The options page, if implemented; otherwise, <b>null</b>.</returns>
  119. public virtual DesignerOptionsPage GetOptionsPage()
  120. {
  121. return null;
  122. }
  123. /// <inheritdoc/>
  124. public virtual void UpdateUIStyle()
  125. {
  126. }
  127. /// <inheritdoc/>
  128. public virtual void UpdateDpiDependencies()
  129. {
  130. }
  131. #endregion
  132. /// <summary>
  133. /// Initializes a new instance of the <see cref="ToolWindowBase"/> class with default settings.
  134. /// </summary>
  135. /// <param name="designer">The report designer.</param>
  136. /// <remarks>
  137. /// You don't need to call this constructor. The designer will do this automatically.
  138. /// </remarks>
  139. public ToolWindowBase(Designer designer) : base()
  140. {
  141. Designer = designer;
  142. }
  143. }
  144. }