DialogControl.DesignExt.cs 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. using System;
  2. using System.Drawing;
  3. using System.Windows.Forms;
  4. using System.Drawing.Drawing2D;
  5. using FastReport.Utils;
  6. namespace FastReport.Dialog
  7. {
  8. partial class DialogControl : IHasEditor
  9. {
  10. #region Protected Methods
  11. /// <summary>
  12. /// Determines whether is necessary to serialize the <b>BackColor</b> property.
  13. /// </summary>
  14. /// <returns><b>true</b> if serialization is necessary.</returns>
  15. protected virtual bool ShouldSerializeBackColor()
  16. {
  17. return BackColor != SystemColors.Control;
  18. }
  19. /// <summary>
  20. /// Determines whether is necessary to serialize the <b>Cursor</b> property.
  21. /// </summary>
  22. /// <returns><b>true</b> if serialization is necessary.</returns>
  23. protected virtual bool ShouldSerializeCursor()
  24. {
  25. return Cursor != Cursors.Default;
  26. }
  27. /// <summary>
  28. /// Determines whether is necessary to serialize the <b>Font</b> property.
  29. /// </summary>
  30. /// <returns><b>true</b> if serialization is necessary.</returns>
  31. protected virtual bool ShouldSerializeFont()
  32. {
  33. return !Font.Equals(Control.Parent.Font);
  34. }
  35. /// <summary>
  36. /// Determines whether is necessary to serialize the <b>ForeColor</b> property.
  37. /// </summary>
  38. /// <returns><b>true</b> if serialization is necessary.</returns>
  39. protected virtual bool ShouldSerializeForeColor()
  40. {
  41. return ForeColor != SystemColors.ControlText;
  42. }
  43. /// <inheritdoc/>
  44. protected override SelectionPoint[] GetSelectionPoints()
  45. {
  46. return new SelectionPoint[] {
  47. new SelectionPoint(AbsLeft - 2, AbsTop - 2, SizingPoint.LeftTop),
  48. new SelectionPoint(AbsLeft + Width + 1, AbsTop - 2, SizingPoint.RightTop),
  49. new SelectionPoint(AbsLeft - 2, AbsTop + Height + 1, SizingPoint.LeftBottom),
  50. new SelectionPoint(AbsLeft + Width + 1, AbsTop + Height + 1, SizingPoint.RightBottom),
  51. new SelectionPoint(AbsLeft + Width / 2, AbsTop - 2, SizingPoint.TopCenter),
  52. new SelectionPoint(AbsLeft + Width / 2, AbsTop + Height + 1, SizingPoint.BottomCenter),
  53. new SelectionPoint(AbsLeft - 2, AbsTop + Height / 2, SizingPoint.LeftCenter),
  54. new SelectionPoint(AbsLeft + Width + 1, AbsTop + Height / 2, SizingPoint.RightCenter) };
  55. }
  56. /// <summary>
  57. /// Draws the selection point.
  58. /// </summary>
  59. /// <param name="g"><b>Graphics</b> object to draw on.</param>
  60. /// <param name="p"><see cref="Pen"/> object.</param>
  61. /// <param name="b"><see cref="Brush"/> object.</param>
  62. /// <param name="x">Left coordinate.</param>
  63. /// <param name="y">Top coordinate.</param>
  64. protected void DrawSelectionPoint(Graphics g, Pen p, Brush b, float x, float y)
  65. {
  66. x = (int)x;
  67. y = (int)y;
  68. g.FillRectangle(b, x - 2, y - 2, 5, 5);
  69. g.DrawLine(p, x - 2, y - 3, x + 2, y - 3);
  70. g.DrawLine(p, x - 2, y + 3, x + 2, y + 3);
  71. g.DrawLine(p, x - 3, y - 2, x - 3, y + 2);
  72. g.DrawLine(p, x + 3, y - 2, x + 3, y + 2);
  73. }
  74. #endregion
  75. #region Public Methods
  76. /// <inheritdoc/>
  77. public override void CheckParent(bool immediately)
  78. {
  79. if (!IsSelected || IsAncestor || !HasFlag(Flags.CanChangeParent))
  80. return;
  81. if (immediately || (!(Parent is DialogPage) && (
  82. Left < 0 || Left > (Parent as ComponentBase).Width || Top < 0 || Top > (Parent as ComponentBase).Height)))
  83. {
  84. ObjectCollection list = Page.AllObjects;
  85. int i = 0;
  86. while (i < list.Count)
  87. {
  88. if (list[i] is ParentControl && list[i] != this)
  89. i++;
  90. else
  91. list.RemoveAt(i);
  92. }
  93. list.Insert(0, Page);
  94. for (i = list.Count - 1; i >= 0; i--)
  95. {
  96. ComponentBase c = list[i] as ComponentBase;
  97. if ((c as IParent).CanContain(this))
  98. if (AbsLeft > c.AbsLeft - 1e-4 && AbsLeft < c.AbsRight - 1e-4 &&
  99. AbsTop > c.AbsTop - 1e-4 && AbsTop < c.AbsBottom - 1e-4)
  100. {
  101. if (Parent != c)
  102. {
  103. Left = (int)Math.Round((AbsLeft - c.AbsLeft) / Page.SnapSize.Width) * Page.SnapSize.Width;
  104. Top = (int)Math.Round((AbsTop - c.AbsTop) / Page.SnapSize.Height) * Page.SnapSize.Height;
  105. Parent = c;
  106. }
  107. break;
  108. }
  109. }
  110. }
  111. }
  112. /// <inheritdoc/>
  113. public override void DrawSelection(FRPaintEventArgs e)
  114. {
  115. float m = Report?.Designer?.DpiMultiplier() ?? 1;
  116. Pen pen = e.Cache.GetPen(Color.Gray, m, DashStyle.Dot);
  117. e.Graphics.DrawRectangle(pen, AbsLeft - 2 * m, AbsTop - 2 * m, Width + 3.5f * m, Height + 3.5f * m);
  118. base.DrawSelection(e);
  119. }
  120. /// <summary>
  121. /// Creates the empty event handler for the <b>ClickEvent</b> event in the report's script.
  122. /// </summary>
  123. /// <returns><b>true</b> if event handler was created successfully.</returns>
  124. public bool InvokeEditor()
  125. {
  126. Report.Designer.ActiveReportTab.SwitchToCode();
  127. if (String.IsNullOrEmpty(ClickEvent))
  128. {
  129. string newEventName = Name + "_Click";
  130. if (Report.CodeHelper.AddHandler(typeof(EventHandler), newEventName))
  131. {
  132. ClickEvent = newEventName;
  133. return true;
  134. }
  135. else
  136. return false;
  137. }
  138. else
  139. {
  140. Report.CodeHelper.LocateHandler(ClickEvent);
  141. }
  142. return false;
  143. }
  144. /// <inheritdoc/>
  145. public override void OnBeforeInsert(int flags)
  146. {
  147. base.OnBeforeInsert(flags);
  148. try
  149. {
  150. Text = BaseName;
  151. }
  152. catch
  153. {
  154. }
  155. }
  156. #endregion
  157. }
  158. }