コード例 #1
0
        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;
                }
            }
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        private DragQueryResult CanDropAt(Block current)
        {
            IPotentialDropTarget target = current as IPotentialDropTarget;

            if (target == null)
            {
                return(null);
            }
            DragQueryResult result = target.CanAcceptBlocks(DragState.Query);

            if (result != null)
            {
                result.DropTargetContainer = target;
            }
            return(result);
        }
コード例 #4
0
        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);
                    }
                }
            }
        }
コード例 #5
0
ファイル: RootBlock.cs プロジェクト: orb1t/StructuredEditor
        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);
                }
            }
        }
コード例 #6
0
        public DragQueryResult FindDropTarget()
        {
            Block current = FindBlockAtPoint(
                DragState.Query.DropPoint.X,
                DragState.Query.DropPoint.Y);

            if (current == null)
            {
                return(null);
            }
            if (IsTargetWithinSource(current))
            {
                return(null);
            }
            DragQueryResult result = CanDropAt(current);

            while (current != null && result == null)
            {
                current = current.Parent;
                result  = CanDropAt(current);
            }

            return(result);
        }
コード例 #7
0
        public IEnumerable <Block> IntersperseWithSeparators(IEnumerable <Block> draggedBlocks, DragQueryResult whereTo)
        {
            List <Block> blocks           = new List <Block>();
            bool         weHaveSeparators = HasSeparators;

            foreach (Block dragged in draggedBlocks)
            {
                if (dragged is ISeparatorBlock)
                {
                    if (weHaveSeparators)
                    {
                        blocks.Add(CreateSeparator());
                    }
                }
                else
                {
                    if (blocks.Count > 0 &&
                        !(blocks[blocks.Count - 1] is ISeparatorBlock) &&
                        weHaveSeparators)
                    {
                        blocks.Add(CreateSeparator());
                    }
                    blocks.Add(dragged);
                }
            }

            if (blocks.Count > 0 &&
                !(blocks[blocks.Count - 1] is ISeparatorBlock) &&
                weHaveSeparators)
            {
                blocks.Add(CreateSeparator());
            }

            return(blocks);
        }
コード例 #8
0
        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);
        }