PageDesignerBase.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. using FastReport.Forms;
  2. using FastReport.Utils;
  3. using System.Windows.Forms;
  4. namespace FastReport.Design.PageDesigners
  5. {
  6. internal class PageDesignerBase : Panel, IDesignerPlugin
  7. {
  8. #region Properties
  9. public PageBase Page { get; set; }
  10. public Designer Designer { get; }
  11. public bool Locked { get; private set; }
  12. public bool IsInsertingObject { get; set; }
  13. public virtual Report Report => Page.Report;
  14. public string PluginName => Name;
  15. public virtual float Zoom
  16. {
  17. get { return 1; }
  18. set { }
  19. }
  20. private ControlStorageService storage;
  21. /// <summary>
  22. /// Gets storage service.
  23. /// </summary>
  24. public ControlStorageService Storage
  25. {
  26. get
  27. {
  28. if (storage == null)
  29. {
  30. // pass Designer as a control to get dpi from it (case: Avalonia can't get dpi correctly after disposing the control)
  31. storage = new ControlStorageService(Designer, "Designer," + Name);
  32. }
  33. return storage;
  34. }
  35. }
  36. #endregion
  37. #region Public Methods
  38. // this method is called when the page becomes active. You may, for example, modify the main menu
  39. // in this method.
  40. public virtual void PageActivated()
  41. {
  42. }
  43. // this method is called when the page becomes inactive. You should remove items added to the main menu
  44. // in this method.
  45. public virtual void PageDeactivated()
  46. {
  47. }
  48. public virtual void FillObjects(bool resetSelection)
  49. {
  50. Designer.Objects.Clear();
  51. Designer.Objects.Add(Page.Report);
  52. Designer.Objects.Add(Page);
  53. foreach (Base b in Page.AllObjects)
  54. {
  55. Designer.Objects.Add(b);
  56. }
  57. if (resetSelection)
  58. {
  59. Designer.SelectedObjects.Clear();
  60. Designer.SelectedObjects.Add(Page);
  61. }
  62. }
  63. public virtual bool CanCopy()
  64. {
  65. if (Designer.SelectedObjects.Count > 0)
  66. {
  67. // if at least one object can be copied, allow the operation
  68. foreach (Base c in Designer.SelectedObjects)
  69. {
  70. if (c.HasFlag(Flags.CanCopy))
  71. return true;
  72. }
  73. }
  74. return false;
  75. }
  76. public virtual void Copy()
  77. {
  78. Designer.Clipboard.Copy();
  79. }
  80. public virtual void Cut()
  81. {
  82. Designer.Clipboard.Cut();
  83. }
  84. public virtual bool CanPaste() => Designer.Clipboard.CanPaste;
  85. public virtual void Paste()
  86. {
  87. Designer.Clipboard.Paste();
  88. }
  89. public virtual bool CanUndo() => false;
  90. public virtual void Undo()
  91. {
  92. }
  93. public virtual bool CanRedo() => false;
  94. public virtual void Redo()
  95. {
  96. }
  97. public virtual void Paste(ObjectCollection list, InsertFrom source)
  98. {
  99. }
  100. public virtual void CancelPaste()
  101. {
  102. }
  103. public virtual void ResetModified()
  104. {
  105. }
  106. public virtual void SelectAll()
  107. {
  108. }
  109. public virtual void ZoomPageWidth()
  110. {
  111. }
  112. public virtual void ZoomWholePage()
  113. {
  114. }
  115. protected override void Dispose(bool disposing)
  116. {
  117. base.Dispose(disposing);
  118. if (disposing)
  119. SaveState();
  120. }
  121. #endregion
  122. #region IDesignerPlugin
  123. public virtual void Localize()
  124. {
  125. }
  126. public virtual void SaveState()
  127. {
  128. }
  129. public virtual void RestoreState()
  130. {
  131. }
  132. public virtual void SelectionChanged()
  133. {
  134. }
  135. public virtual void UpdateContent()
  136. {
  137. }
  138. public virtual void Lock()
  139. {
  140. Locked = true;
  141. }
  142. public virtual void Unlock()
  143. {
  144. Locked = false;
  145. UpdateContent();
  146. }
  147. public virtual DesignerOptionsPage GetOptionsPage()
  148. {
  149. return null;
  150. }
  151. public virtual void UpdateUIStyle()
  152. {
  153. }
  154. public virtual void UpdateDpiDependencies()
  155. {
  156. }
  157. #endregion
  158. public PageDesignerBase(Designer designer) : base()
  159. {
  160. Designer = designer;
  161. IsInsertingObject = false;
  162. }
  163. }
  164. }