/// <summary>
        /// Removes existing placeholders and draws a new one according to the given location.
        /// </summary>
        /// <param name="location">Location of the placeholder to draw</param>
        /// <param name="node">Node we're over (set null if location is None)</param>
        /// <param name="parent">Parent node (only relevent to leaf bottom location, set
        /// null otherwise)</param>
        private void SetPlaceholders(PlaceholderLocation location, TreeNode node, TreeNode parent)
        {
            // Clear placeholders
            if (_placeholdersVisible)
            {
                Refresh();
            }

            // Set placeholder flag
            _placeholdersVisible = location != PlaceholderLocation.None;

            // Draw the proper one
            switch (location)
            {
            case PlaceholderLocation.LeafTop:
                DrawLeafTopPlaceholders(node);
                break;

            case PlaceholderLocation.LeafBottom:
                DrawLeafBottomPlaceholders(node, parent);
                break;

            case PlaceholderLocation.FolderTop:
                DrawFolderTopPlaceholders(node);
                break;

            case PlaceholderLocation.FolderAdd:
                DrawAddToFolderPlaceholder(node);
                break;

            case PlaceholderLocation.FolderBottom:
                DrawFolderBottomPlaceholders(node);
                break;
            }
        }
Beispiel #2
0
        /// <summary>
        /// This method handles the <see cref="TreeView.DragOver"/> event for a <see cref="TreeViewControl"/>.
        /// </summary>
        /// <param name="treeView">The <see cref="TreeView"/> of the <see cref="TreeViewControl"/>.</param>
        /// <param name="e">The arguments of the <see cref="TreeView.DragOver"/> event.</param>
        /// <param name="getTreeNodeInfoForData">A function for obtaining the <see cref="TreeNodeInfo"/> object corresponding to a provided data object.</param>
        public void HandleDragOver(FormsTreeView treeView, DragEventArgs e, Func <object, TreeNodeInfo> getTreeNodeInfoForData)
        {
            if (lastDragOverPoint.X == e.X && lastDragOverPoint.Y == e.Y)
            {
                return;
            }

            lastDragOverPoint = new Point(e.X, e.Y);

            Point    point       = treeView.PointToClient(lastDragOverPoint);
            TreeNode nodeOver    = treeView.GetNodeAt(point);
            TreeNode draggedNode = GetDraggedNodeData(e);

            if (draggedNode == null || nodeOver == null || nodeOver == draggedNode || IsDropTargetChildOfDraggedNode(nodeOver, draggedNode))
            {
                RemovePlaceHolder(treeView);
                e.Effect = DragDropEffects.None;
                return;
            }

            ScrollIntoView(point, nodeOver, treeView);

            PlaceholderLocation placeholderLocation = GetPlaceHoldersLocation(treeView, draggedNode, nodeOver, getTreeNodeInfoForData);

            if (nodeDropTarget == null)
            {
                return;
            }

            TreeNodeInfo treeNodeInfo = getTreeNodeInfoForData(nodeDropTarget.Tag);
            bool         canDrop      = treeNodeInfo.CanDrop != null && treeNodeInfo.CanDrop(draggedNode.Tag, nodeDropTarget.Tag);

            e.Effect = canDrop ? DragDropEffects.Move : DragDropEffects.None;

            if (placeholderLocation == PlaceholderLocation.None)
            {
                RemovePlaceHolder(treeView);
                e.Effect = DragDropEffects.None;

                return;
            }

            if (canDrop)
            {
                CreatePlaceholder(treeView, nodeOver, placeholderLocation);
            }
            else
            {
                RemovePlaceHolder(treeView);

                e.Effect = DragDropEffects.None;
            }
        }
Beispiel #3
0
        private void CreatePlaceholder(FormsTreeView treeView, TreeNode node, PlaceholderLocation placeHolderLocation)
        {
            if (lastPlaceholderNode == node && lastPlaceholderLocation == placeHolderLocation)
            {
                return;
            }

            RemovePlaceHolder(treeView);

            lastPlaceholderNode     = node;
            lastPlaceholderLocation = placeHolderLocation;

            placeHolderGraphics = treeView.CreateGraphics();
            DrawPlaceHolder(node, placeHolderLocation, treeView.CreateGraphics());
        }
Beispiel #4
0
        private static void DrawPlaceHolder(TreeNode node, PlaceholderLocation location, Graphics graphics)
        {
            Point[] rightTriangle = MakePlaceHoldeTriangle(node, AnchorStyles.Right, location);

            graphics.FillPolygon(Brushes.Black, rightTriangle);

            if (location == PlaceholderLocation.Middle)
            {
                return;
            }

            Point[] leftTriangle = MakePlaceHoldeTriangle(node, AnchorStyles.Left, location);
            graphics.FillPolygon(Brushes.Black, leftTriangle);

            int yLine = location == PlaceholderLocation.Top
                            ? node.Bounds.Top
                            : node.Bounds.Bottom;

            graphics.DrawLine(new Pen(Color.Black, 1), new Point(GetImageLeft(node), yLine), new Point(node.Bounds.Right, yLine));
        }
Beispiel #5
0
        private static Point[] MakePlaceHoldeTriangle(TreeNode node, AnchorStyles anchor, PlaceholderLocation location)
        {
            const int placeHolderWidth  = 4;
            const int placeHolderHeight = 8;

            int       xPos, yPos;
            Rectangle bounds = node.Bounds;

            switch (anchor)
            {
            case AnchorStyles.Left:
                xPos = GetImageLeft(node) - placeHolderWidth;
                break;

            case AnchorStyles.Right:
                xPos = bounds.Right;
                break;

            default:
                throw new NotSupportedException();
            }

            switch (location)
            {
            case PlaceholderLocation.Top:
                yPos = bounds.Top;
                break;

            case PlaceholderLocation.Bottom:
                yPos = bounds.Bottom;
                break;

            case PlaceholderLocation.Middle:
                yPos = bounds.Top + bounds.Height / 2;
                break;

            default:
                throw new NotSupportedException();
            }

            return(CreateTrianglePoints(new Rectangle(xPos, yPos - placeHolderWidth, placeHolderWidth, placeHolderHeight), anchor));
        }