Base.DesignExt.cs 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. using System;
  2. using System.IO;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using System.Windows.Forms;
  6. using System.Drawing;
  7. using System.Drawing.Design;
  8. using System.ComponentModel;
  9. using FastReport.Utils;
  10. namespace FastReport
  11. {
  12. /// <summary>
  13. /// Specifies an origin where the new objects inserted from.
  14. /// </summary>
  15. public enum InsertFrom
  16. {
  17. /// <summary>
  18. /// Specifies that a new object was inserted from the "Objects" toolbar or "Insert" menu.
  19. /// </summary>
  20. NewObject,
  21. /// <summary>
  22. /// Specifies that a new object was dragged from the "Dictionary" window.
  23. /// </summary>
  24. Dictionary,
  25. /// <summary>
  26. /// Specifies that a new object was pasted from the clipboard.
  27. /// </summary>
  28. Clipboard
  29. }
  30. partial class Base
  31. {
  32. #region Properties
  33. /// <summary>
  34. /// Gets a value indicating whether the object is selected in the designer.
  35. /// </summary>
  36. [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  37. public virtual bool IsSelected
  38. {
  39. get { return Report != null && Report.Designer != null && Report.Designer.SelectedObjects.IndexOf(this) != -1; }
  40. }
  41. /// <summary>
  42. /// Gets a value indicating whether one of the object's parent is selected in the designer.
  43. /// </summary>
  44. [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  45. public bool IsParentSelected
  46. {
  47. get
  48. {
  49. if (Report.Designer == null)
  50. return false;
  51. Base parent = Parent;
  52. while (parent != null)
  53. {
  54. if (Report.Designer.SelectedObjects.IndexOf(parent) != -1)
  55. return true;
  56. parent = parent.Parent;
  57. }
  58. return false;
  59. }
  60. }
  61. #endregion
  62. #region Public Methods
  63. /// <summary>
  64. /// Deletes the object in the designer.
  65. /// </summary>
  66. /// <remarks>
  67. /// <para>This method is called when you delete the object in the designer.</para>
  68. /// <para>Typically this method calls the <see cref="Dispose"/> method to delete the object and all
  69. /// its children. You may override it to delete the object only, and keep children.</para>
  70. /// </remarks>
  71. public virtual void Delete()
  72. {
  73. Dispose();
  74. }
  75. /// <summary>
  76. /// Called before inserting a new object in the designer.
  77. /// </summary>
  78. /// <remarks>
  79. /// <para>Do not call this method directly. You may override it if you are developing a
  80. /// new component for FastReport.</para>
  81. /// <para>
  82. /// Some objects are registered in the designer several times with the same object
  83. /// type, but different flags. For example, the <see cref="ShapeObject"/>
  84. /// represents different shapes: rectangle, roundrect, ellipse and so on. All these
  85. /// shapes are registered in the designer using flags (the last parameter in this
  86. /// code):
  87. /// <code>
  88. /// RegisteredObjects.Add(typeof(ShapeObject), "ReportPage,Shapes", 108, "Objects,Shapes,Rectangle", 0);
  89. /// RegisteredObjects.Add(typeof(ShapeObject), "ReportPage,Shapes", 109, "Objects,Shapes,RoundRectangle", 1);
  90. /// RegisteredObjects.Add(typeof(ShapeObject), "ReportPage,Shapes", 110, "Objects,Shapes,Ellipse", 2);
  91. /// </code>
  92. /// <para>When we put the "Ellipse" object on a band, the designer creates the
  93. /// <b>ShapeObject</b> instance and calls its <b>OnBeforeInsert</b> method with
  94. /// <b>flags</b> value set to 2. In turn, the <b>OnBeforeInsert</b> method converts the
  95. /// int value of the flags to the shape kind:</para>
  96. /// <code>
  97. /// public override void OnBeforeInsert(int flags)
  98. /// {
  99. /// FShape = (ShapeKind)flags;
  100. /// }
  101. /// </code>
  102. /// </para>
  103. /// </remarks>
  104. /// <param name="flags">Object's flags.</param>
  105. public virtual void OnBeforeInsert(int flags)
  106. {
  107. }
  108. /// <summary>
  109. /// Called after the new object was inserted in the designer.
  110. /// </summary>
  111. /// <remarks>
  112. /// <para>Do not call this method directly. You may override it if you are developing a new component
  113. /// for FastReport.</para>
  114. /// <para>This method is called when new object is inserted, pasted from clipboard or dragged from
  115. /// "Dictionary" window. You may override this method if you need to perform some actions when object
  116. /// is inserted. Typical implementation invokes the object's editor if "Edit after insert" flag is set
  117. /// in the designer options.</para>
  118. /// </remarks>
  119. /// <param name="source">The insertion source.</param>
  120. public virtual void OnAfterInsert(InsertFrom source)
  121. {
  122. }
  123. /// <summary>
  124. /// Called when the user selects another object in the designer.
  125. /// </summary>
  126. /// <remarks>
  127. /// This method is typically used by the in-place object's editor to check if selection was changed and close
  128. /// the editor.
  129. /// </remarks>
  130. public virtual void SelectionChanged()
  131. {
  132. }
  133. /// <summary>
  134. /// Gets the object's context menu.
  135. /// </summary>
  136. /// <returns>Null reference if object does not have a menu.</returns>
  137. /// <remarks>
  138. /// <para>Do not call this method directly. You may override it if you are developing a new component
  139. /// for FastReport.</para>
  140. /// <para>You may use base menu classes such as <see cref="ComponentBaseMenu"/>,
  141. /// <see cref="ReportComponentBaseMenu"/> to create own context menus.</para>
  142. /// </remarks>
  143. public virtual ContextMenuBase GetContextMenu()
  144. {
  145. return null;
  146. }
  147. /// <summary>
  148. /// Gets an image index for this component to display it in the Report Tree.
  149. /// </summary>
  150. /// <returns>The image index or -1 if no image is associated with this component.</returns>
  151. public virtual int GetImageIndex()
  152. {
  153. ObjectInfo objItem = RegisteredObjects.FindObject(this);
  154. if (objItem != null)
  155. return objItem.ImageIndex;
  156. return -1;
  157. }
  158. #endregion
  159. private string ExtractDefaultMacrosInternal(Dictionary<string, object> macroValues, string text)
  160. {
  161. string[] copyNames = Report.PrintSettings.CopyNames;
  162. string copyName = "";
  163. if (copyNames.Length > 0)
  164. {
  165. // get zero-based index of printed copy. In the preview, use the first copy name
  166. int copyIndex = 0;
  167. if (macroValues.ContainsKey("Copy#"))
  168. copyIndex = (int)macroValues["Copy#"];
  169. // get appropriate copy name
  170. if (copyIndex >= copyNames.Length)
  171. copyIndex = copyNames.Length - 1;
  172. copyName = copyNames[copyIndex];
  173. }
  174. return text.Replace("[COPYNAME#]", copyName);
  175. }
  176. }
  177. }