/// <summary> /// /// </summary> /// <returns></returns> protected bool IsMouseOverOtherGridList() { //if (_dropOnGrid == null || !(_dropOnGrid is GridList) || this.grid.Equals(_dropOnGrid)) // return false; QueryCanDropFieldEventArgs e = new QueryCanDropFieldEventArgs(Control.MousePosition, Grid[fieldIndex]); Grid.RaiseQueryCanDropField(e); _dropOnGrid = e.DropOnGrid; if (e.CanDrop && e.DropOnGrid != null) { return(true); } return(false); }
/// <override/> public override void MouseMove(MouseEventArgs e) { if (this.hitTestInfo == null) { base.MouseMove(e); return; } this.ResetClickCellsController(); QueryCanDropFieldEventArgs ea = new QueryCanDropFieldEventArgs(new Point(e.X, e.Y), Grid[fieldIndex]); Grid.RaiseQueryCanDropField(ea); _dropOnGrid = ea.DropOnGrid; ShouldOpenArrow(true); switch (GetCursorInfo()) { case -1: //Drop not allowed if (ea.CanDrop) { cursor = Cursors.Hand; } else { cursor = Cursors.No; } break; case 1: //Drop allowed cursor = Cursors.Hand; break; case 0: //Only drag allowed not drop default: cursor = Cursors.Default; break; } this.UpdateDragField(); this.UpdateRedArrowIndicator(); this.wasDragged |= DragFieldVisible; }
/// <override/> public override void MouseUp(MouseEventArgs e) { if (this.hitTestInfo == null) { base.MouseUp(e); return; } this.ResetClickCellsController(); //Set Default Cursor cursor = null; bool bv = DragFieldVisible; DragFieldVisible = false; this.CloseDragField(); this.CloseRedArrowIndicator(); grid.GetGridWindow().AutoScrolling = ScrollBars.None; grid.GetGridWindow().Capture = false; grid.PrepareViewStyleInfo -= new GridPrepareViewStyleInfoEventHandler(grid_PrepareViewStyleInfo); grid.InvalidateRange(this._cellRange); if (!wasDragged) { if (!doubleClick) { grid.RaiseCellClick(_rowIndex, _colIndex, e); } } else if (bv) { int cursorInfo = GetCursorInfo(); if (cursorInfo == 1) //between same gridlist and drag & drop is possible { //GridQueryDragColumnHeaderEventArgs ae = new GridQueryDragColumnHeaderEventArgs(this.grid, column, targetColIndex, GridQueryDragColumnHeaderReason.MouseUp); //this.grid.RaiseQueryAllowDragColumn(ae); //if (ae.AllowDrag) if (ShouldShowRedArrowIndicator()) { if (targetRowIndex > fieldIndex) { targetRowIndex--; } grid.Model.Rows.MoveRange(fieldIndex, 1, targetRowIndex); } Cursor.Current = Cursors.Default; } else if (cursorInfo == -1) //out of current grid bounds { QueryCanDropFieldEventArgs ea = new QueryCanDropFieldEventArgs(new Point(e.X, e.Y), Grid[fieldIndex]); Grid.RaiseQueryCanDropField(ea); if (ea.CanDrop) { Point pt = _dropOnGrid.GridPointToClient(Control.MousePosition); GridRangeInfo cell = _dropOnGrid.PointToRangeInfo(pt); int dropAt = dropAtRowCount ? _dropOnGrid.Model.RowCount : Math.Max(Math.Min(cell.Top, _dropOnGrid.Model.RowCount), 2); FieldDropEventArgs fdea = new FieldDropEventArgs(Grid[fieldIndex], fieldIndex, new Point(e.X, e.Y), dropAt); Grid.RaiseFieldDrop(fdea); } } } }
/// <internalonly/> public void UpdateRedArrowIndicator() { Point pt = Control.MousePosition; if (!IsMouseOverOtherGridList()) { QueryCanDropFieldEventArgs ea = new QueryCanDropFieldEventArgs(pt, Grid[fieldIndex]); Grid.RaiseQueryCanDropField(ea); if (!ea.CanDrop) { goto noArrow; } pt = grid.GridPointToClient(pt); GridControlBase gridWindow = grid.GetGridWindow(); if (pt.Y < gridWindow.GridBounds.Top || pt.Y > gridWindow.GridBounds.Bottom) { goto noArrow; } targetRowIndex = grid.GetRow(grid.ViewLayout.PointToClientRow(pt, GridCellSizeKind.ActualSize)); targetRowIndex = Math.Min(Grid.RowCount, targetRowIndex); if (this.ShouldShowRedArrowIndicator()) { Bitmap leftBitmap = IconDrawingSupport.RedLeftBitmap; Bitmap rightBitmap = IconDrawingSupport.RedRightBitmap; Point p = Point.Empty; PivotGridQueryDragFieldEventArgs ae = new PivotGridQueryDragFieldEventArgs(this.grid, _rowIndex, targetRowIndex, QueryDragFieldReason.ShowRedArrowIndicator); //this.grid.RaiseQueryAllowDragRow(ae); //if (!ae.AllowDrag) //{ // pt = hiddenPoint; //} //else { p = GetRedArrowIndicatorLocation(targetRowIndex); p.X -= rightBitmap.Width; p.Y -= rightBitmap.Height / 2; pt = grid.GridPointToClient(p); } if (redArrowIndicatorDragHelper != null) { if (pt.Y < gridWindow.GridBounds.Top - leftBitmap.Height / 2 || pt.Y > gridWindow.GridBounds.Bottom) { redArrowIndicatorDragHelper.DoDrag(hiddenPoint, DragDropEffects.Copy); } else { redArrowIndicatorDragHelper.DoDrag(p, DragDropEffects.Copy); redArrowIndicatorDragHelper.DragWindow.ShowWindowTopMost(); // Fixes an issue with transparency that occurs occasionally when shown // for the first time. if (firstShowRedArrowIndicator) { firstShowRedArrowIndicator = false; redArrowIndicatorDragHelper.DoDrag(hiddenPoint, DragDropEffects.Copy); UpdateRedArrowIndicator(); } } } return; } noArrow: if (redArrowIndicatorDragHelper != null) { redArrowIndicatorDragHelper.DoDrag(hiddenPoint, DragDropEffects.Copy); } } else if (!DropOnGrid.isFieldsGrid) { Bitmap leftBitmap = IconDrawingSupport.RedLeftBitmap; Bitmap rightBitmap = IconDrawingSupport.RedRightBitmap; int fieldNum; Rectangle screenBounds = _dropOnGrid.Parent.RectangleToScreen(_dropOnGrid.Bounds); if (!screenBounds.Contains(pt)) { fieldNum = _dropOnGrid.Model.RowCount; dropAtRowCount = true; } else { pt = _dropOnGrid.GridPointToClient(pt); GridRangeInfo cell = _dropOnGrid.PointToRangeInfo(pt); fieldNum = Math.Max(cell.Top, 1); dropAtRowCount = false; } int fnum = _rowIndex; if (redArrowIndicatorDragHelper != null) { if (!this.ShouldShowDragBitmap()) { redArrowIndicatorDragHelper.DoDrag(hiddenPoint, DragDropEffects.Copy); } else { redArrowFieldNum = fieldNum; string insertBeforeField = ""; if (redArrowFieldNum < grid.Model.RowCount) { insertBeforeField = Grid[redArrowFieldNum]; } //GridQueryAllowGroupByColumnEventArgs ae = new GridQueryAllowGroupByColumnEventArgs(this.grid, column.Name, insertBeforeColumnName, GridQueryAllowDragColumnReason.ShowRedArrowIndicator, column.AllowGroupByColumn); //this.grid.RaiseQueryAllowGroupByColumn(ae); //if (ae.AllowGroupByColumn) { int rowIndex = fieldNum; Rectangle r = _dropOnGrid.RangeInfoToRectangle(GridRangeInfo.Cell(rowIndex, gridListColIndex)); pt = grid.IsRightToLeft() ? new Point(r.Right, r.Top) : r.Location; pt = _dropOnGrid.GridPointToScreen(pt); pt.X -= leftBitmap.Width; pt.Y -= leftBitmap.Height / 2; redArrowIndicatorDragHelper.DoDrag(pt, DragDropEffects.Copy); redArrowIndicatorDragHelper.DragWindow.ShowWindowTopMost(); } } } } }