DesignerToolbarBase.Mono.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. using FastReport.Controls;
  2. using FastReport.Forms;
  3. using FastReport.Utils;
  4. using System.ComponentModel;
  5. namespace FastReport.Design.Toolbars
  6. {
  7. /// <summary>
  8. /// Base class for all designer toolbars.
  9. /// </summary>
  10. /// <remarks>
  11. /// Use this class to write own designer's toolbar. To do this:
  12. /// <para>- in the constructor, set the <b>Name</b> property and create toolbar buttons.
  13. /// The <b>Name</b> will be used to restore toolbar's state;</para>
  14. /// <para>- override the <b>SelectionChanged</b> method. This method is called when current selection
  15. /// is changed. In this method, you should update buttons state to reflect the current selection.
  16. /// Selected objects can be accessed via <b>Designer.SelectedObjects</b> property;</para>
  17. /// <para>- override the <b>UpdateContent</b> method. This method is called when the report
  18. /// content was changed. Typically you need to do the same actions in <b>SelectionChanged</b> and
  19. /// <b>UpdateContent</b> methods;</para>
  20. /// <para>- to register a toolbar, add its type to the <see cref="DesignerPlugins"/> global collection:
  21. /// <code>
  22. /// DesignerPlugins.Add(typeof(MyToolbar));
  23. /// </code>
  24. /// </para>
  25. /// </remarks>
  26. [ToolboxItem(false)]
  27. public class DesignerToolbarBase : ToolbarBase, IDesignerPlugin
  28. {
  29. #region Properties
  30. /// <inheritdoc/>
  31. public string PluginName => Name;
  32. private ControlStorageService storage;
  33. /// <summary>
  34. /// Gets storage service.
  35. /// </summary>
  36. public ControlStorageService Storage
  37. {
  38. get
  39. {
  40. if (storage == null)
  41. storage = new ControlStorageService(this, "Designer," + Name);
  42. return storage;
  43. }
  44. }
  45. #endregion
  46. #region IDesignerPlugin
  47. /// <inheritdoc/>
  48. public virtual void SaveState()
  49. {
  50. Storage.SetBool("Visible", Visible);
  51. Storage.SetDip("Left", Left);
  52. Storage.SetDip("Top", Top);
  53. }
  54. /// <inheritdoc/>
  55. public virtual void RestoreState()
  56. {
  57. Visible = Storage.GetBool("Visible", true);
  58. if (Storage.HasProperties)
  59. {
  60. Left = Storage.GetDip("Left");
  61. Top = Storage.GetDip("Top");
  62. }
  63. }
  64. /// <inheritdoc/>
  65. public virtual void SelectionChanged()
  66. {
  67. }
  68. /// <inheritdoc/>
  69. public virtual void UpdateContent()
  70. {
  71. }
  72. /// <inheritdoc/>
  73. public void Lock()
  74. {
  75. }
  76. /// <inheritdoc/>
  77. public void Unlock()
  78. {
  79. UpdateContent();
  80. }
  81. /// <inheritdoc/>
  82. public virtual void Localize()
  83. {
  84. }
  85. /// <inheritdoc/>
  86. public virtual DesignerOptionsPage GetOptionsPage()
  87. {
  88. return null;
  89. }
  90. #endregion
  91. /// <summary>
  92. /// Initializes a new instance of the <see cref="DesignerToolbarBase"/> class with default settings.
  93. /// </summary>
  94. /// <param name="designer">The report designer.</param>
  95. /// <remarks>
  96. /// You don't need to call this constructor. The designer will do this automatically.
  97. /// </remarks>
  98. public DesignerToolbarBase(Designer designer) : base(designer)
  99. {
  100. }
  101. }
  102. }