123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- using System;
- using System.Drawing;
- using FastReport.Table;
- namespace FastReport.AdvMatrix
- {
- internal enum DragPosition
- {
- Left,
- Right,
- Top,
- Bottom,
- Inside
- }
- internal enum HeaderInsertPosition
- {
- Before,
- After,
- Parent,
- Child,
- Inside
- }
- internal class DragInfo
- {
- public TableCell SelectedCell;
- public MatrixElement Source;
- public TableCell TargetCell;
- public MatrixElement Target;
- public DragPosition Position;
- public RectangleF Indicator;
- public bool DragSelectedCell;
- public HeaderInsertPosition InsertPosition
- {
- get
- {
- switch (Position)
- {
- case DragPosition.Left:
- return Target == MatrixElement.Column ? HeaderInsertPosition.Before : HeaderInsertPosition.Parent;
- case DragPosition.Right:
- return Target == MatrixElement.Column ? HeaderInsertPosition.After : HeaderInsertPosition.Child;
- case DragPosition.Top:
- return Target == MatrixElement.Column ? HeaderInsertPosition.Parent : HeaderInsertPosition.Before;
- case DragPosition.Bottom:
- return Target == MatrixElement.Column ? HeaderInsertPosition.Child : HeaderInsertPosition.After;
- }
- return HeaderInsertPosition.Inside;
- }
- }
- public void SetDragPosition(TableCell cell, PointF point)
- {
- if (point.X < cell.AbsLeft + cell.Width / 4)
- {
- Position = DragPosition.Left;
- Indicator = new RectangleF(cell.Left, cell.Top, 0, cell.Height);
- }
- else if (point.X > cell.AbsRight - cell.Width / 4)
- {
- Position = DragPosition.Right;
- Indicator = new RectangleF(cell.Right, cell.Top, 0, cell.Height);
- }
- else if (point.Y < cell.AbsTop + cell.Height / 3)
- {
- Position = DragPosition.Top;
- Indicator = new RectangleF(cell.Left, cell.Top, cell.Width, 0);
- }
- else if (point.Y > cell.AbsBottom - cell.Height / 3)
- {
- Position = DragPosition.Bottom;
- Indicator = new RectangleF(cell.Left, cell.Bottom, cell.Width, 0);
- }
- else
- {
- Position = DragPosition.Inside;
- Indicator = RectangleF.Empty;
- }
- }
- public void SetHeaderTargetInfo(TableCell cell, PointF point)
- {
- HeaderDescriptor descr = cell.GetHeaderDescriptor();
- Target = descr.IsColumn ? MatrixElement.Column : MatrixElement.Row;
- TargetCell = cell;
- if (descr.IsEmpty())
- {
- // dragging into empty dummy cell
- Position = DragPosition.Inside;
- Indicator = RectangleF.Empty;
- return;
- }
- SetDragPosition(cell, point);
- if (Position == DragPosition.Inside && Source != MatrixElement.None)
- {
- // do not allow this drag if dragged not from Data window
- Target = MatrixElement.None;
- TargetCell = null;
- }
- }
- public void SetCellTargetInfo(TableCell cell, PointF point)
- {
- Target = MatrixElement.Cell;
- TargetCell = cell;
- if (String.IsNullOrEmpty(cell.Text))
- {
- // dragging into empty dummy cell
- Position = DragPosition.Inside;
- Indicator = RectangleF.Empty;
- return;
- }
- SetDragPosition(cell, point);
- }
- }
- }
|