Used to represent a drag from one place in the tree view to another. This is the only kind of drag currently supported.
Пример #1
0
        void tree_MouseMove(object sender, MouseEventArgs e)
        {
            if ((e.Button & MouseButtons.Left) != MouseButtons.Left)
            {
                return;
            }
            var tree = sender as TreeView;

            if (tree == null)
            {
                return;
            }
            // The location here is always different than the one in tree_MouseDown.
            // Sometimes, the difference is great enough to choose an adjacent item!
            // See LT-10295.  So we'll use the location stored in tree_MouseDown.
            // (The sample code in MSDN uses the item/location information in MouseDown
            // establish the item to drag in MouseMove.)
            TreeNode selItem = tree.GetNodeAt(m_mouseDownLocation);

            if (selItem == null)
            {
                return;
            }
            var item = new LocalDragItem(this, selItem);

            tree.DoDragDrop(item, DragDropEffects.Move);
            ClearDragHilite();
        }
Пример #2
0
        private bool OkToDrop(object sender, DragEventArgs e, out TreeNode destNode)
        {
            destNode = null;
            // Don't allow drop in non-hierarchical lists.
            if (m_list.OwningObject is CmPossibilityList && (m_list.OwningObject as CmPossibilityList).Depth < 2)
            {
                return(false);
            }
            TreeView tree = sender as TreeView;

            if (tree == null)
            {
                return(false);
            }
            if (!e.Data.GetDataPresent(typeof(LocalDragItem)))
            {
                return(false);
            }
            destNode = tree.GetNodeAt(tree.PointToClient(new Point(e.X, e.Y)));
            LocalDragItem item = (LocalDragItem)e.Data.GetData(typeof(LocalDragItem));

            if (item.SourceNode == destNode)
            {
                return(false);
            }
            int hvoMove = (int)item.SourceNode.Tag;
            int hvoDest = 0;

            if (destNode != null)
            {
                hvoDest = (int)destNode.Tag;
            }
            // It must not be that hvoMove owns hvoDest
            FdoCache cache = (FdoCache)m_mediator.PropertyTable.GetValue("cache");

            for (int hvoOwner = hvoDest; hvoOwner != 0; hvoOwner = cache.GetOwnerOfObject(hvoOwner))
            {
                if (hvoOwner == hvoMove)
                {
                    return(false);
                }
            }
            return(true);
        }
Пример #3
0
        private bool OkToDrop(object sender, DragEventArgs e, out TreeNode destNode)
        {
            destNode = null;
            // Don't allow drop in non-hierarchical lists.
            if (m_list.OwningObject is ICmPossibilityList && (m_list.OwningObject as ICmPossibilityList).Depth < 2)
            {
                return(false);
            }
            TreeView tree = sender as TreeView;

            if (tree == null)
            {
                return(false);
            }
            if (!e.Data.GetDataPresent(typeof(LocalDragItem)))
            {
                return(false);
            }
            destNode = tree.GetNodeAt(tree.PointToClient(new Point(e.X, e.Y)));
            LocalDragItem item = (LocalDragItem)e.Data.GetData(typeof(LocalDragItem));

            if (item.SourceNode == destNode)
            {
                return(false);
            }
            int hvoMove = (int)item.SourceNode.Tag;
            int hvoDest = 0;

            if (destNode != null)
            {
                hvoDest = (int)destNode.Tag;
            }
            if (hvoDest <= 0)
            {
                return(false);
            }
            // It must not be that hvoMove owns hvoDest
            var destObj = m_objRepo.GetObject(hvoDest);
            var moveObj = m_objRepo.GetObject(hvoMove);

            return(!destObj.IsOwnedBy(moveObj));
        }
Пример #4
0
        /// <summary>
        /// Currently we only know how to move our own items.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void tree_DragDrop(object sender, DragEventArgs e)
        {
            TreeNode destNode;

            if (!OkToDrop(sender, e, out destNode))
            {
                return;
            }
            // Notification also gets sent to inactive handlers, which should ignore it.
            LocalDragItem item = (LocalDragItem)e.Data.GetData(typeof(LocalDragItem));

            if (item.Handler != this)
            {
                return;
            }
            if (e.Effect != DragDropEffects.Move)
            {
                return;
            }
            MoveItem(sender, destNode, item.SourceNode);
        }
Пример #5
0
        void tree_DragOver(object sender, DragEventArgs e)
        {
            if (!e.Data.GetDataPresent(typeof(LocalDragItem)))
            {
                e.Effect = DragDropEffects.None;                 // not my sort of data at all, can't drop
                return;
            }
            // An inactive handler is unfortunately also being notified. Don't express any
            // opinion at all about drag effects.
            LocalDragItem item = (LocalDragItem)e.Data.GetData(typeof(LocalDragItem));

            if (item.Handler != this)
            {
                return;
            }

            TreeNode destNode;

            if (OkToDrop(sender, e, out destNode))
            {
                e.Effect = DragDropEffects.Move;
            }
            else
            {
                e.Effect = DragDropEffects.None;
            }
            if (destNode != m_dragHiliteNode)
            {
                ClearDragHilite();
                m_dragHiliteNode = destNode;
                if (m_dragHiliteNode != null)
                {
                    m_dragHiliteNode.BackColor = Color.Gray;
                }
            }
        }
Пример #6
0
		void tree_MouseMove(object sender, MouseEventArgs e)
		{
			if ((e.Button & MouseButtons.Left) != MouseButtons.Left)
				return;
			var tree = sender as TreeView;
			if (tree == null)
				return;
			// The location here is always different than the one in tree_MouseDown.
			// Sometimes, the difference is great enough to choose an adjacent item!
			// See LT-10295.  So we'll use the location stored in tree_MouseDown.
			// (The sample code in MSDN uses the item/location information in MouseDown
			// establish the item to drag in MouseMove.)
			TreeNode selItem = tree.GetNodeAt(m_mouseDownLocation);
			if (selItem == null)
				return;
			var item = new LocalDragItem(this, selItem);
			tree.DoDragDrop(item, DragDropEffects.Move);
			ClearDragHilite();
		}