/*
			 * DoDrop
			 */

			/// <summary>
			/// Invokes service specific nodes merge operation.
			/// </summary>
			/// <exception cref="T:System.ArgumentNullException"><paramref name="selectedNodes"/> is <see langword="null"/>.</exception>
			public override void DoDrop(TreeNode targetTreeNode, List<TreeNode> selectedNodes, NuGenDropPosition dropPosition)
			{
				if (selectedNodes == null)
				{
					throw new ArgumentNullException("selectedNodes");
				}

				if (
					targetTreeNode == null
					|| this.CheckSelectedContainTarget(targetTreeNode, selectedNodes)
					|| !this.CheckParent(targetTreeNode, selectedNodes)
					)
				{
					return;
				}

				switch (dropPosition)
				{
					case NuGenDropPosition.After:
					case NuGenDropPosition.Before:
					{
						this.MoveNodes(targetTreeNode, selectedNodes, dropPosition);
						break;
					}
					case NuGenDropPosition.Inside:
					{
						this.InsertNodes(targetTreeNode, selectedNodes);
						break;
					}
				}
			}
        /*
         * DoDrop
         */

        /// <summary>
        /// Invokes service specific nodes merge operation.
        /// </summary>
        public virtual void DoDrop(
            TreeNode targetTreeNode,
            List <TreeNode> selectedNodes,
            NuGenDropPosition dropPosition
            )
        {
            return;
        }
Ejemplo n.º 3
0
        protected virtual void WmNcHitTest(ref Message m)
        {
            if (_isDragging)
            {
                Point     clientCursorPosition = this.PointToClient(Cursor.Position);
                TreeNode  targetTreeNode       = this.GetNodeAt(clientCursorPosition);
                Rectangle targetBounds         = Rectangle.Empty;

                NuGenDropPosition dropPosition = this.DragDropService.GetDropPosition(
                    targetTreeNode,
                    clientCursorPosition
                    );

                if (dropPosition != NuGenDropPosition.Nowhere)
                {
                    targetBounds = targetTreeNode.Bounds;
                }

                Point dragLineLeft  = Point.Empty;
                Point dragLineRight = Point.Empty;

                using (Graphics g = Graphics.FromHwnd(this.Handle))
                {
                    NuGenControlPaint.DrawReversibleLine(g, _oldDragLineLeft, _oldDragLineRight);

                    switch (dropPosition)
                    {
                    case NuGenDropPosition.After:
                    {
                        dragLineLeft  = new Point(this.Left, targetBounds.Bottom);
                        dragLineRight = new Point(this.Right, targetBounds.Bottom);

                        NuGenControlPaint.DrawReversibleLine(g, dragLineLeft, dragLineRight);

                        break;
                    }

                    case NuGenDropPosition.Before:
                    {
                        dragLineLeft  = new Point(this.Left, targetBounds.Top);
                        dragLineRight = new Point(this.Right, targetBounds.Top);

                        NuGenControlPaint.DrawReversibleLine(g, dragLineLeft, dragLineRight);

                        break;
                    }
                    }
                }

                _oldDragLineLeft  = dragLineLeft;
                _oldDragLineRight = dragLineRight;
            }

            base.WndProc(ref m);
        }
            /*
             * MoveNodes
             */

            /// <summary>
            /// Moves selected nodes to the new location specified by the <paramref name="targetNode"/> index.
            /// </summary>
            /// <param name="targetNode"></param>
            /// <param name="selected"></param>
            /// <param name="dropPosition"></param>
            /// <exception cref="T:System.ArgumentNullException">
            /// <paramref name="targetNode"/> is <see langword="null"/>
            /// -or-
            /// <paramref name="selected"/> is <see langword="null"/>
            /// </exception>
            private void MoveNodes(TreeNode targetNode, List <TreeNode> selected, NuGenDropPosition dropPosition)
            {
                if (targetNode == null)
                {
                    throw new ArgumentNullException("targetNode");
                }

                if (selected == null)
                {
                    throw new ArgumentNullException("selected");
                }

                int targetIndex = 0;

                if (dropPosition == NuGenDropPosition.After)
                {
                    targetIndex = targetNode.Index + 1;
                    this.RemoveNodesFromParents(selected);
                }
                else if (dropPosition == NuGenDropPosition.Before)
                {
                    this.RemoveNodesFromParents(selected);
                    targetIndex = targetNode.Index;
                }
                else
                {
                    return;
                }

                foreach (TreeNode treeNode in selected)
                {
                    if (targetNode.Parent != null)
                    {
                        targetNode.Parent.Nodes.Insert(targetIndex, treeNode);
                    }
                    else if (targetNode.TreeView != null)
                    {
                        targetNode.TreeView.Nodes.Insert(targetIndex, treeNode);
                    }
                    else
                    {
                        return;
                    }
                }
            }
Ejemplo n.º 5
0
        public void GetDropPositionTest()
        {
            Rectangle nodeBounds = this.treeNode.Bounds;

            Point             cursorPosition = new Point(nodeBounds.Left, nodeBounds.Top + nodeBounds.Height / 2);
            NuGenDropPosition dropPosition   = this.dragService.GetDropPosition(this.treeNode, cursorPosition);

            Assert.AreEqual(NuGenDropPosition.Inside, dropPosition);

            cursorPosition = new Point(nodeBounds.Left, nodeBounds.Top);
            dropPosition   = this.dragService.GetDropPosition(this.treeNode, cursorPosition);
            Assert.AreEqual(NuGenDropPosition.Before, dropPosition);

            cursorPosition = new Point(nodeBounds.Left, nodeBounds.Bottom);
            dropPosition   = this.dragService.GetDropPosition(this.treeNode, cursorPosition);
            Assert.AreEqual(NuGenDropPosition.After, dropPosition);

            cursorPosition = new Point(-10, -10);
            dropPosition   = this.dragService.GetDropPosition(this.treeNode, cursorPosition);
            Assert.AreEqual(NuGenDropPosition.Nowhere, dropPosition);
            Assert.AreEqual(NuGenDropPosition.Nowhere, this.dragService.GetDropPosition(null, cursorPosition));
        }
		/*
		 * DoDrop
		 */

		/// <summary>
		/// Invokes service specific nodes merge operation.
		/// </summary>
		public virtual void DoDrop(
			TreeNode targetTreeNode,
			IList<TreeNode> selectedNodes,
			NuGenDropPosition dropPosition
			)
		{
			return;
		}
            /*
             * DoDrop
             */

            /// <summary>
            /// Invokes service specific nodes merge operation.
            /// </summary>
            /// <exception cref="T:System.ArgumentNullException"><paramref name="selectedNodes"/> is <see langword="null"/>.</exception>
            public override void DoDrop(TreeNode targetTreeNode, IList <TreeNode> selectedNodes, NuGenDropPosition dropPosition)
            {
                if (selectedNodes == null)
                {
                    throw new ArgumentNullException("selectedNodes");
                }

                if (
                    targetTreeNode == null ||
                    DragDropService.CheckSelectedContainTarget(targetTreeNode, selectedNodes) ||
                    !DragDropService.CheckParent(targetTreeNode, selectedNodes)
                    )
                {
                    return;
                }

                switch (dropPosition)
                {
                case NuGenDropPosition.After:
                case NuGenDropPosition.Before:
                {
                    DragDropService.MoveNodes(targetTreeNode, selectedNodes, dropPosition);
                    break;
                }

                case NuGenDropPosition.Inside:
                {
                    DragDropService.InsertNodes(targetTreeNode, selectedNodes);
                    break;
                }
                }
            }
			/*
			 * MoveNodes
			 */

			/// <summary>
			/// Moves selected nodes to the new location specified by the <paramref name="targetNode"/> index.
			/// </summary>
			/// <param name="targetNode"></param>
			/// <param name="selected"></param>
			/// <param name="dropPosition"></param>
			/// <exception cref="T:System.ArgumentNullException">
			/// <paramref name="targetNode"/> is <see langword="null"/>
			/// -or-
			/// <paramref name="selected"/> is <see langword="null"/>
			/// </exception>
			private void MoveNodes(TreeNode targetNode, List<TreeNode> selected, NuGenDropPosition dropPosition)
			{
				if (targetNode == null)
				{
					throw new ArgumentNullException("targetNode");
				}

				if (selected == null)
				{
					throw new ArgumentNullException("selected");
				}

				int targetIndex = 0;

				if (dropPosition == NuGenDropPosition.After)
				{
					targetIndex = targetNode.Index + 1;
					this.RemoveNodesFromParents(selected);
				}
				else if (dropPosition == NuGenDropPosition.Before)
				{
					this.RemoveNodesFromParents(selected);
					targetIndex = targetNode.Index;
				}
				else
				{
					return;
				}

				foreach (TreeNode treeNode in selected)
				{
					if (targetNode.Parent != null)
					{
						targetNode.Parent.Nodes.Insert(targetIndex, treeNode);
					}
					else if (targetNode.TreeView != null)
					{
						targetNode.TreeView.Nodes.Insert(targetIndex, treeNode);
					}
					else
					{
						return;
					}
				}
			}
        /*
         * DoDrop
         */

        /// <summary>
        /// Invokes service specific nodes merge operation.
        /// </summary>
        /// <exception cref="T:System.ArgumentNullException"><paramref name="selectedNodes"/> is <see langword="null"/>.</exception>
        public override void DoDrop(NuGenTreeNode targetTreeNode, List <NuGenTreeNode> selectedNodes, NuGenDropPosition dropPosition)
        {
            if (selectedNodes == null)
            {
                throw new ArgumentNullException("selectedNodes");
            }

            if (
                targetTreeNode == null ||
                this.CheckSelectedContainTarget(targetTreeNode, selectedNodes) ||
                !this.CheckParent(targetTreeNode, selectedNodes)
                )
            {
                return;
            }

            switch (dropPosition)
            {
            case NuGenDropPosition.After:
            case NuGenDropPosition.Before:
            {
                this.MoveNodes(targetTreeNode, selectedNodes, dropPosition);
                break;
            }

            case NuGenDropPosition.Inside:
            {
                this.InsertNodes(targetTreeNode, this.RetrieveInsertable(selectedNodes));
                break;
            }
            }
        }