BreakableComponent.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. using System;
  2. using System.ComponentModel;
  3. using System.Drawing.Design;
  4. using FastReport.Utils;
  5. namespace FastReport
  6. {
  7. /// <summary>
  8. /// Base class for report components that can break across pages.
  9. /// </summary>
  10. public class BreakableComponent : ReportComponentBase
  11. {
  12. #region Fields
  13. private bool canBreak;
  14. private BreakableComponent breakTo;
  15. #endregion
  16. #region Properties
  17. /// <summary>
  18. /// Gets or sets a value that determines if the component can break its contents across pages.
  19. /// </summary>
  20. [DefaultValue(true)]
  21. [Category("Behavior")]
  22. public bool CanBreak
  23. {
  24. get { return canBreak; }
  25. set { canBreak = value; }
  26. }
  27. /// <summary>
  28. /// Gets or sets a reference to another similar object that will be used for displaying the
  29. /// text that not fit in this object.
  30. /// </summary>
  31. [Category("Behavior")]
  32. [TypeConverter(typeof(FastReport.TypeConverters.ComponentRefConverter))]
  33. [Editor("FastReport.TypeEditors.BandComponentRefEditor, FastReport", typeof(UITypeEditor))]
  34. public BreakableComponent BreakTo
  35. {
  36. get { return breakTo; }
  37. set
  38. {
  39. if (breakTo != value)
  40. {
  41. if (breakTo != null)
  42. breakTo.Disposed -= new EventHandler(BreakTo_Disposed);
  43. if (value != null)
  44. value.Disposed += new EventHandler(BreakTo_Disposed);
  45. }
  46. breakTo = value;
  47. }
  48. }
  49. #endregion
  50. #region Private Methods
  51. private void BreakTo_Disposed(object sender, EventArgs e)
  52. {
  53. breakTo = null;
  54. }
  55. #endregion
  56. #region Public Methods
  57. /// <inheritdoc/>
  58. public override void Assign(Base source)
  59. {
  60. base.Assign(source);
  61. BreakableComponent src = source as BreakableComponent;
  62. CanBreak = src.CanBreak;
  63. BreakTo = src.BreakTo;
  64. }
  65. /// <inheritdoc/>
  66. public override void Serialize(FRWriter writer)
  67. {
  68. BreakableComponent c = writer.DiffObject as BreakableComponent;
  69. base.Serialize(writer);
  70. if (CanBreak != c.CanBreak)
  71. writer.WriteBool("CanBreak", CanBreak);
  72. if (writer.SerializeTo != SerializeTo.Preview && writer.SerializeTo != SerializeTo.SourcePages &&
  73. BreakTo != c.BreakTo)
  74. writer.WriteRef("BreakTo", BreakTo);
  75. }
  76. /// <summary>
  77. /// Breaks the contents of the object.
  78. /// </summary>
  79. /// <param name="breakTo">Object to put the part of content to that does not fit in this object. These two
  80. /// objects must have the same type.</param>
  81. /// <returns><b>true</b> if there is enough space in this object to display at least one text line.</returns>
  82. /// <remarks>
  83. /// <para>
  84. /// Do not call this method directly, it is used by the report engine. You should override it if
  85. /// you are writing a new FastReport object.
  86. /// </para>
  87. /// <para>
  88. /// This method must break the contents of the object. The part of content that fit in current object's
  89. /// bounds should remain in this object, the part that does not fit should be transferred to <b>breakTo</b>
  90. /// object.
  91. /// </para>
  92. /// </remarks>
  93. public virtual bool Break(BreakableComponent breakTo)
  94. {
  95. return false;
  96. }
  97. #endregion
  98. /// <summary>
  99. /// Initializes a new instance of the <b>BreakableComponent</b> class with default settings.
  100. /// </summary>
  101. public BreakableComponent()
  102. {
  103. CanBreak = true;
  104. }
  105. }
  106. }