Example #1
0
        private void drawDragBar(DropPositionEnum position)
        {
            if (previousNode != targetNode)
            {
                Refresh();
            }

            Point upperLeft   = new Point(targetNode.Bounds.Left, targetNode.Bounds.Top);
            Point bottomRight = new Point(targetNode.Bounds.Right, targetNode.Bounds.Bottom);

            // reset previous node highlight color
            if (highlightedNode != null)
            {
                highlightedNode.ForeColor = originalForeColor;
                highlightedNode.BackColor = originalBackColor;
                highlightedNode           = null;
            }

            int leftPos, rightPos, vertPos;

            leftPos  = upperLeft.X - 22;
            rightPos = treeView.Width - 4;

            if (position == DropPositionEnum.Before)
            {
                vertPos = upperLeft.Y;
            }
            else
            {
                vertPos = bottomRight.Y;
            }

            // edge marker
            Point[] LeftTriangle = new Point[5] {
                new Point(leftPos, vertPos - 3),
                new Point(leftPos, vertPos + 3),
                new Point(leftPos + 3, vertPos),
                new Point(leftPos + 3, vertPos - 1),
                new Point(leftPos, vertPos - 4)
            };

            Point[] RightTriangle = new Point[5] {
                new Point(rightPos, vertPos - 3),
                new Point(rightPos, vertPos + 3),
                new Point(rightPos - 3, vertPos),
                new Point(rightPos - 3, vertPos - 1),
                new Point(rightPos, vertPos - 4)
            };

            Graphics g = treeView.CreateGraphics();

            g.FillPolygon(System.Drawing.Brushes.Black, LeftTriangle);
            g.FillPolygon(System.Drawing.Brushes.Black, RightTriangle);
            g.DrawLine(new System.Drawing.Pen(Color.Black, 2),
                       new Point(leftPos, vertPos),
                       new Point(rightPos, vertPos));

            dragBarVisible = true;
        }
        public void UpdateTarget(MouseDevice mouseDevice, FrameworkElement target, Orientation orientation)
        {
            Point  itemsControlTestPoint = mouseDevice.GetPosition(AdornedElement);
            Point  targetTestPoint       = mouseDevice.GetPosition(target);
            Vector offset = itemsControlTestPoint - targetTestPoint;
            double width  = target.ActualWidth;
            double height = target.ActualHeight;

            this.leftTop     = new Point(offset.X, offset.Y);
            this.topRight    = new Point(offset.X + width, offset.Y);
            this.rightBottom = new Point(offset.X + width, offset.Y + height);
            this.bottomLeft  = new Point(offset.X, offset.Y + height);

            double centerWidth = width / 2d;
            double centerHight = height / 2d;

            this.direction = DirectionEnum.None;
            switch (orientation)
            {
            case Orientation.Horizontal:
            {
                this.direction |= DirectionEnum.Top;
                this.direction |= DirectionEnum.Bottom;
                if (targetTestPoint.X <= centerWidth)
                {
                    this.direction |= DirectionEnum.Left;
                }
                else
                {
                    this.direction |= DirectionEnum.Right;
                }
            }
            break;

            default:
            case Orientation.Vertical:
            {
                this.direction |= DirectionEnum.Right;
                this.direction |= DirectionEnum.Left;
                if (targetTestPoint.Y <= centerHight)
                {
                    this.direction |= DirectionEnum.Top;
                }
                else
                {
                    this.direction |= DirectionEnum.Bottom;
                }
            }
            break;
            }

            if ((this.direction & DirectionEnum.TopLine) == DirectionEnum.TopLine)
            {
                DropPosition = DropPositionEnum.Before;
            }

            if ((this.direction & DirectionEnum.RightLine) == DirectionEnum.RightLine)
            {
                DropPosition = DropPositionEnum.After;
            }

            if ((this.direction & DirectionEnum.BottomLine) == DirectionEnum.BottomLine)
            {
                DropPosition = DropPositionEnum.After;
            }

            if ((this.direction & DirectionEnum.LeftLine) == DirectionEnum.LeftLine)
            {
                DropPosition = DropPositionEnum.Before;
            }

            InvalidateVisual();
        }
Example #3
0
        private void treeView_DragOver(object sender, DragEventArgs e)
        {
            // grab the item being moved
            movingNode = (TreeNode)e.Data.GetData(typeof(TreeNode));
            if (movingNode == null)
            {
                return;
            }

            // grab the node currently being hovered over
            Point mousePos = treeView.PointToClient(new Point(e.X, e.Y));

            targetNode = treeView.GetNodeAt(mousePos);

            // bounds for the current node being hovered over (if one exists)
            Point upperLeft   = new Point();
            Point bottomRight = new Point();

            if (targetNode != null)
            {
                upperLeft   = new Point(targetNode.Bounds.Left, targetNode.Bounds.Top);
                bottomRight = new Point(targetNode.Bounds.Right, targetNode.Bounds.Bottom);
            }

            // if we are hovering over a real node, it's not a child of the one we are moving, and the parent
            // of the current node is not dynamic, then it's okay for a border drop (before or after a node)
            bool borderDropOk = targetNode != null &&
                                targetNode != movingNode &&
                                targetNode.Tag is DBNode <T> &&
                                !isChild(movingNode, targetNode) &&
                                !((DBNode <T>)targetNode.Tag).AutoGenerated;

            // if we are hovering over a real node that is not the one we are moving or it's parent, child
            // or grandchild and it is not a dynamic node, then it's okay for an inner drop
            bool innerDropOk = targetNode != null &&
                               targetNode != movingNode &&
                               targetNode != movingNode.Parent &&
                               !isChild(movingNode, targetNode) &&
                               targetNode.Tag is DBNode <T> &&
                               !((DBNode <T>)targetNode.Tag).DynamicNode &&
                               !((DBNode <T>)targetNode.Tag).AutoGenerated;


            // determine the action to be taken based on current status
            if (borderDropOk && mousePos.Y < upperLeft.Y + 4)
            {
                dropPosition = DropPositionEnum.Before;
            }
            else if (borderDropOk && !targetNode.IsExpanded && mousePos.Y > bottomRight.Y - 4)
            {
                dropPosition = DropPositionEnum.After;
            }
            else if (innerDropOk)
            {
                dropPosition = DropPositionEnum.Inside;
            }
            else
            {
                dropPosition = DropPositionEnum.None;
            }

            switch (dropPosition)
            {
            case DropPositionEnum.None:
                e.Effect = DragDropEffects.None;
                clearDragDropMarkup();
                break;

            case DropPositionEnum.Before:
            case DropPositionEnum.After:
                e.Effect = DragDropEffects.Move;
                drawDragBar(dropPosition);
                break;

            case DropPositionEnum.Inside:
                e.Effect = DragDropEffects.Move;
                highlightCurrentNode();
                break;
            }

            previousNode = targetNode;
        }