HighlightCondition.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. using System.Drawing;
  2. using System.ComponentModel;
  3. using FastReport.Utils;
  4. using System.Drawing.Design;
  5. namespace FastReport
  6. {
  7. /// <summary>
  8. /// Represents a single highlight condition used by the <see cref="TextObject.Highlight"/> property
  9. /// of the <see cref="TextObject"/>.
  10. /// </summary>
  11. public class HighlightCondition : StyleBase
  12. {
  13. #region Fields
  14. private string expression;
  15. private bool visible;
  16. #endregion
  17. #region Properties
  18. /// <summary>
  19. /// Gets or sets a highlight expression.
  20. /// </summary>
  21. /// <remarks>
  22. /// This property can contain any valid boolean expression. If value of this expression is <b>true</b>,
  23. /// the fill and font settings will be applied to the <b>TextObject</b>.
  24. /// </remarks>
  25. [Editor("FastReport.TypeEditors.ExpressionEditor, FastReport", typeof(UITypeEditor))]
  26. public string Expression
  27. {
  28. get { return expression; }
  29. set { expression = value; }
  30. }
  31. /// <summary>
  32. /// Gets or sets the visibility flag.
  33. /// </summary>
  34. /// <remarks>
  35. /// If this property is set to <b>false</b>, the Text object will be hidden if the
  36. /// condition is met.
  37. /// </remarks>
  38. public bool Visible
  39. {
  40. get { return visible; }
  41. set { visible = value; }
  42. }
  43. #endregion
  44. #region Public Methods
  45. /// <inheritdoc/>
  46. public override void Serialize(FRWriter writer)
  47. {
  48. HighlightCondition c = writer.DiffObject as HighlightCondition;
  49. writer.ItemName = "Condition";
  50. if (Expression != c.Expression)
  51. writer.WriteStr("Expression", Expression);
  52. if (Visible != c.Visible)
  53. writer.WriteBool("Visible", Visible);
  54. base.Serialize(writer);
  55. }
  56. /// <inheritdoc/>
  57. public override void Assign(StyleBase source)
  58. {
  59. base.Assign(source);
  60. Expression = (source as HighlightCondition).Expression;
  61. Visible = (source as HighlightCondition).Visible;
  62. }
  63. /// <summary>
  64. /// Creates exact copy of this condition.
  65. /// </summary>
  66. /// <returns>A copy of this condition.</returns>
  67. public HighlightCondition Clone()
  68. {
  69. HighlightCondition result = new HighlightCondition();
  70. result.Assign(this);
  71. return result;
  72. }
  73. /// <inheritdoc/>
  74. public override bool Equals(object obj)
  75. {
  76. HighlightCondition c = obj as HighlightCondition;
  77. return c != null && Expression == c.Expression && Border.Equals(c.Border) && Fill.Equals(c.Fill) &&
  78. TextFill.Equals(c.TextFill) && Font.Equals(c.Font) && Visible == c.Visible &&
  79. ApplyBorder == c.ApplyBorder && ApplyFill == c.ApplyFill && ApplyTextFill == c.ApplyTextFill &&
  80. ApplyFont == c.ApplyFont;
  81. }
  82. /// <inheritdoc/>
  83. public override int GetHashCode()
  84. {
  85. return base.GetHashCode();
  86. }
  87. #endregion
  88. /// <summary>
  89. /// Initializes a new instance of the <see cref="HighlightCondition"/> class with default settings.
  90. /// </summary>
  91. public HighlightCondition()
  92. {
  93. Expression = "";
  94. TextFill = new SolidFill(Color.Red);
  95. Visible = true;
  96. ApplyBorder = false;
  97. ApplyFill = false;
  98. ApplyTextFill = true;
  99. ApplyFont = false;
  100. }
  101. }
  102. }