public virtual bool CanTheoreticallyAcceptBlocks(DragQuery draggedBlocks) { if (AcceptableBlockTypes == null || AcceptableBlockTypes.Count == 0) { return(false); } if (!draggedBlocks.ShouldCopyInsteadOfMove) { foreach (Block dragged in draggedBlocks) { ContainerBlock draggedContainer = dragged as ContainerBlock; if (dragged != null && this.IsInSubtreeOf(draggedContainer)) { return(false); } } } foreach (Block dragged in draggedBlocks) { bool foundAssignable = false; foreach (Type acceptableType in AcceptableBlockTypes) { if (acceptableType.IsAssignableFrom(dragged.GetType())) { foundAssignable = true; } } if (!foundAssignable) { return(false); } } return(true); }
private void AdjustPotentialDropTarget( DragQuery request, DragQueryResult result) { if (result.IsDropPointInTheUpperHalfOfDropTarget) { result.HowToDrop = DropTargetInfo.DropBeforeTarget; } else { result.HowToDrop = DropTargetInfo.DropAfterTarget; } result.AdjustDropOnSeparator(); if (request.CanDropHere(result)) { return; } if (request.IsDropPointAboveDragStartPoint) { result.HowToDrop = DropTargetInfo.DropBeforeTarget; result.AdjustDropOnSeparator(); while (result.DropTarget != null && !request.CanDropHere(result)) { result.DropTarget = result.DropTarget.Prev; result.AdjustDropOnSeparator(); } if (result.DropTarget == null) { return; } } else { result.HowToDrop = DropTargetInfo.DropAfterTarget; result.AdjustDropOnSeparator(); while (result.DropTarget != null && !request.CanDropHere(result)) { result.DropTarget = result.DropTarget.Next; result.AdjustDropOnSeparator(); } if (result.DropTarget == null) { return; } } }
public DragQueryResult CanAcceptBlocks(DragQuery draggedBlocks) { if (!CanTheoreticallyAcceptBlocks(draggedBlocks) || !this.MyControl.Bounds.HitTest(draggedBlocks.DropPoint)) { return(null); } DragQueryResult result = FindAPlaceToDrop(draggedBlocks); if (result != null && draggedBlocks.IsTargetNearSource(result)) { return(null); } return(result); }
public void AcceptBlocks(DragQuery draggedBlocks, DragQueryResult whereTo) { if (whereTo.DropTargetContainer.CanAcceptBlocks(draggedBlocks) == null) { return; } IEnumerable <Block> toDrop; if (draggedBlocks.ShouldCopyInsteadOfMove) { toDrop = BlockActions.Clone(draggedBlocks); toDrop = IntersperseWithSeparators(toDrop, whereTo); if (whereTo.HowToDrop == DropTargetInfo.DropBeforeTarget) { whereTo.DropTarget.PrependBlocks(toDrop); } else { whereTo.DropTarget.AppendBlocks(toDrop); } } else { using (Root.Transaction()) { foreach (Block b in draggedBlocks) { b.Delete(); } toDrop = IntersperseWithSeparators(draggedBlocks, whereTo); if (whereTo.HowToDrop == DropTargetInfo.DropBeforeTarget) { whereTo.DropTarget.PrependBlocks(toDrop); } else { whereTo.DropTarget.AppendBlocks(toDrop); } } } }
private void Draw(IRenderer renderer) { //if (this.CurrentSelection != null) //{ // Renderer.DrawOperations.DrawRectangle( // CurrentSelection.Bounds, // Color.Blue, // 3); //} if (DragState != null) { DragQuery query = DragState.Query; if (DragState.DragStarted) { dragRect.Location.Set( DragState.Query.DropPoint + 24); renderer.DrawOperations.DrawDotRectangle( dragRect, Color.DarkGray); } if (DragState.Result != null) { DragQueryResult result = DragState.Result; dropRect.Set(result.DropTarget.MyControl.Bounds.AddMargins( result.DropTarget.MyControl.Box.MouseSensitivityArea)); if (result.HowToDrop == DropTargetInfo.DropBeforeTarget) { dropRect.Size.Y = 3; } else if (result.HowToDrop == DropTargetInfo.DropAfterTarget) { dropRect.Location.Y += dropRect.Size.Y; dropRect.Size.Y = 3; } renderer.DrawOperations.DrawRectangle( dropRect, Color.DeepSkyBlue, 2); } } }
public DragInfo(Block b, int x, int y) { Query = new DragQuery(b, x, y); }
public virtual DragQueryResult FindAPlaceToDrop(DragQuery draggedBlocks) { Point dropPoint = draggedBlocks.DropPoint; Block foundReferenceBlock = null; DragQueryResult result; int minDistance = int.MaxValue; int distance; if (this.Orientation == OrientationType.Horizontal) { foreach (Block child in this.Children) { if (!child.MyControl.Bounds.HitTestWithMarginX( dropPoint.X, child.MyControl.Box.MouseSensitivityArea)) { continue; } if (child is ISeparatorBlock) { return(new DragQueryResult(child, DropTargetInfo.DropAfterSeparator)); } else { distance = child.MyControl.Bounds.CenterX - dropPoint.X; if (Math.Abs(distance) < Math.Abs(minDistance)) { minDistance = distance; foundReferenceBlock = child; } } } } else { foreach (Block child in this.Children) { if (!child.MyControl.Bounds.HitTestWithMarginY( dropPoint.Y, child.MyControl.Box.MouseSensitivityArea)) { continue; } if (child is ISeparatorBlock) { return(new DragQueryResult(child, DropTargetInfo.DropAfterSeparator)); } else { distance = child.MyControl.Bounds.CenterY - dropPoint.Y; if (Math.Abs(distance) < Math.Abs(minDistance)) { minDistance = distance; foundReferenceBlock = child; } } } } if (foundReferenceBlock == null) { return(null); } result = new DragQueryResult(foundReferenceBlock); result.IsDropPointInTheUpperHalfOfDropTarget = minDistance > 0; AdjustPotentialDropTarget(draggedBlocks, result); if (result.DropTarget == null) { return(null); } return(result); }