DragInfo.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. using System;
  2. using System.Drawing;
  3. using FastReport.Table;
  4. namespace FastReport.AdvMatrix
  5. {
  6. internal enum DragPosition
  7. {
  8. Left,
  9. Right,
  10. Top,
  11. Bottom,
  12. Inside
  13. }
  14. internal enum HeaderInsertPosition
  15. {
  16. Before,
  17. After,
  18. Parent,
  19. Child,
  20. Inside
  21. }
  22. internal class DragInfo
  23. {
  24. public TableCell SelectedCell;
  25. public MatrixElement Source;
  26. public TableCell TargetCell;
  27. public MatrixElement Target;
  28. public DragPosition Position;
  29. public RectangleF Indicator;
  30. public bool DragSelectedCell;
  31. public HeaderInsertPosition InsertPosition
  32. {
  33. get
  34. {
  35. switch (Position)
  36. {
  37. case DragPosition.Left:
  38. return Target == MatrixElement.Column ? HeaderInsertPosition.Before : HeaderInsertPosition.Parent;
  39. case DragPosition.Right:
  40. return Target == MatrixElement.Column ? HeaderInsertPosition.After : HeaderInsertPosition.Child;
  41. case DragPosition.Top:
  42. return Target == MatrixElement.Column ? HeaderInsertPosition.Parent : HeaderInsertPosition.Before;
  43. case DragPosition.Bottom:
  44. return Target == MatrixElement.Column ? HeaderInsertPosition.Child : HeaderInsertPosition.After;
  45. }
  46. return HeaderInsertPosition.Inside;
  47. }
  48. }
  49. public void SetDragPosition(TableCell cell, PointF point)
  50. {
  51. if (point.X < cell.AbsLeft + cell.Width / 4)
  52. {
  53. Position = DragPosition.Left;
  54. Indicator = new RectangleF(cell.Left, cell.Top, 0, cell.Height);
  55. }
  56. else if (point.X > cell.AbsRight - cell.Width / 4)
  57. {
  58. Position = DragPosition.Right;
  59. Indicator = new RectangleF(cell.Right, cell.Top, 0, cell.Height);
  60. }
  61. else if (point.Y < cell.AbsTop + cell.Height / 3)
  62. {
  63. Position = DragPosition.Top;
  64. Indicator = new RectangleF(cell.Left, cell.Top, cell.Width, 0);
  65. }
  66. else if (point.Y > cell.AbsBottom - cell.Height / 3)
  67. {
  68. Position = DragPosition.Bottom;
  69. Indicator = new RectangleF(cell.Left, cell.Bottom, cell.Width, 0);
  70. }
  71. else
  72. {
  73. Position = DragPosition.Inside;
  74. Indicator = RectangleF.Empty;
  75. }
  76. }
  77. public void SetHeaderTargetInfo(TableCell cell, PointF point)
  78. {
  79. HeaderDescriptor descr = cell.GetHeaderDescriptor();
  80. Target = descr.IsColumn ? MatrixElement.Column : MatrixElement.Row;
  81. TargetCell = cell;
  82. if (descr.IsEmpty())
  83. {
  84. // dragging into empty dummy cell
  85. Position = DragPosition.Inside;
  86. Indicator = RectangleF.Empty;
  87. return;
  88. }
  89. SetDragPosition(cell, point);
  90. if (Position == DragPosition.Inside && Source != MatrixElement.None)
  91. {
  92. // do not allow this drag if dragged not from Data window
  93. Target = MatrixElement.None;
  94. TargetCell = null;
  95. }
  96. }
  97. public void SetCellTargetInfo(TableCell cell, PointF point)
  98. {
  99. Target = MatrixElement.Cell;
  100. TargetCell = cell;
  101. if (String.IsNullOrEmpty(cell.Text))
  102. {
  103. // dragging into empty dummy cell
  104. Position = DragPosition.Inside;
  105. Indicator = RectangleF.Empty;
  106. return;
  107. }
  108. SetDragPosition(cell, point);
  109. }
  110. }
  111. }