コード例 #1
0
 public virtual void DragCleanup(bool revertExpanded)
 {
     if (this.m_DropData != null)
     {
         if (this.m_DropData.expandedArrayBeforeDrag != null && revertExpanded)
         {
             this.RestoreExpanded(new List <int>(this.m_DropData.expandedArrayBeforeDrag));
         }
         this.m_DropData = new TreeViewDragging.DropData();
     }
 }
コード例 #2
0
        public virtual bool DragElement(TreeViewItem targetItem, Rect targetItemRect, int row)
        {
            bool flag = Event.current.type == EventType.DragPerform;
            bool result;

            TreeViewDragging.DropPosition dropPosition;
            if (targetItem == null)
            {
                if (this.m_DropData != null)
                {
                    this.m_DropData.dropTargetControlID = 0;
                    this.m_DropData.rowMarkerControlID  = 0;
                }
                DragAndDrop.visualMode = this.DoDrag(null, null, flag, TreeViewDragging.DropPosition.Below);
                if (DragAndDrop.visualMode != DragAndDropVisualMode.None && flag)
                {
                    this.FinalizeDragPerformed(true);
                }
                result = false;
            }
            else if (!this.TryGetDropPosition(targetItem, targetItemRect, row, out dropPosition))
            {
                result = false;
            }
            else
            {
                TreeViewItem treeViewItem = null;
                switch (dropPosition)
                {
                case TreeViewDragging.DropPosition.Upon:
                    treeViewItem = targetItem;
                    break;

                case TreeViewDragging.DropPosition.Below:
                    if (this.m_TreeView.data.IsExpanded(targetItem) && targetItem.hasChildren)
                    {
                        treeViewItem = targetItem;
                        targetItem   = targetItem.children[0];
                        dropPosition = TreeViewDragging.DropPosition.Above;
                    }
                    else
                    {
                        treeViewItem = targetItem.parent;
                    }
                    break;

                case TreeViewDragging.DropPosition.Above:
                    treeViewItem = targetItem.parent;
                    break;
                }
                DragAndDropVisualMode dragAndDropVisualMode = DragAndDropVisualMode.None;
                if (flag)
                {
                    if (dropPosition == TreeViewDragging.DropPosition.Upon)
                    {
                        dragAndDropVisualMode = this.DoDrag(targetItem, targetItem, true, dropPosition);
                    }
                    if (dragAndDropVisualMode == DragAndDropVisualMode.None && treeViewItem != null)
                    {
                        dragAndDropVisualMode = this.DoDrag(treeViewItem, targetItem, true, dropPosition);
                    }
                    if (dragAndDropVisualMode != DragAndDropVisualMode.None)
                    {
                        this.FinalizeDragPerformed(false);
                    }
                    else
                    {
                        this.DragCleanup(true);
                        this.m_TreeView.NotifyListenersThatDragEnded(null, false);
                    }
                }
                else
                {
                    if (this.m_DropData == null)
                    {
                        this.m_DropData = new TreeViewDragging.DropData();
                    }
                    this.m_DropData.dropTargetControlID = 0;
                    this.m_DropData.rowMarkerControlID  = 0;
                    int itemControlID = TreeViewController.GetItemControlID(targetItem);
                    this.HandleAutoExpansion(itemControlID, targetItem, targetItemRect);
                    if (dropPosition == TreeViewDragging.DropPosition.Upon)
                    {
                        dragAndDropVisualMode = this.DoDrag(targetItem, targetItem, false, dropPosition);
                    }
                    if (dragAndDropVisualMode != DragAndDropVisualMode.None)
                    {
                        this.m_DropData.dropTargetControlID = itemControlID;
                        DragAndDrop.visualMode = dragAndDropVisualMode;
                    }
                    else if (targetItem != null && treeViewItem != null)
                    {
                        dragAndDropVisualMode = this.DoDrag(treeViewItem, targetItem, false, dropPosition);
                        if (dragAndDropVisualMode != DragAndDropVisualMode.None)
                        {
                            this.drawRowMarkerAbove            = (dropPosition == TreeViewDragging.DropPosition.Above);
                            this.m_DropData.rowMarkerControlID = itemControlID;
                            DragAndDrop.visualMode             = dragAndDropVisualMode;
                        }
                    }
                }
                Event.current.Use();
                result = true;
            }
            return(result);
        }
コード例 #3
0
        public virtual bool DragElement(TreeViewItem targetItem, Rect targetItemRect, bool firstItem)
        {
            bool flag = Event.current.type == EventType.DragPerform;
            bool result;

            if (targetItem == null)
            {
                if (this.m_DropData != null)
                {
                    this.m_DropData.dropTargetControlID = 0;
                    this.m_DropData.rowMarkerControlID  = 0;
                }
                DragAndDrop.visualMode = this.DoDrag(null, null, flag, TreeViewDragging.DropPosition.Below);
                if (DragAndDrop.visualMode != DragAndDropVisualMode.None && flag)
                {
                    this.FinalizeDragPerformed(true);
                }
                result = false;
            }
            else
            {
                Vector2 mousePosition = Event.current.mousePosition;
                bool    flag2         = this.m_TreeView.data.CanBeParent(targetItem);
                Rect    rect          = targetItemRect;
                float   num           = (!flag2) ? (targetItemRect.height * 0.5f) : this.m_TreeView.gui.halfDropBetweenHeight;
                if (firstItem)
                {
                    rect.yMin -= num;
                }
                rect.yMax += num;
                if (!rect.Contains(mousePosition))
                {
                    result = false;
                }
                else
                {
                    TreeViewDragging.DropPosition dropPosition;
                    if (mousePosition.y >= targetItemRect.yMax - num)
                    {
                        dropPosition = TreeViewDragging.DropPosition.Below;
                    }
                    else if (firstItem && mousePosition.y <= targetItemRect.yMin + num)
                    {
                        dropPosition = TreeViewDragging.DropPosition.Above;
                    }
                    else
                    {
                        dropPosition = ((!flag2) ? TreeViewDragging.DropPosition.Above : TreeViewDragging.DropPosition.Upon);
                    }
                    TreeViewItem treeViewItem = null;
                    switch (dropPosition)
                    {
                    case TreeViewDragging.DropPosition.Upon:
                        treeViewItem = targetItem;
                        break;

                    case TreeViewDragging.DropPosition.Below:
                        if (this.m_TreeView.data.IsExpanded(targetItem) && targetItem.hasChildren)
                        {
                            treeViewItem = targetItem;
                            targetItem   = targetItem.children[0];
                            dropPosition = TreeViewDragging.DropPosition.Above;
                        }
                        else
                        {
                            treeViewItem = targetItem.parent;
                        }
                        break;

                    case TreeViewDragging.DropPosition.Above:
                        treeViewItem = targetItem.parent;
                        break;
                    }
                    DragAndDropVisualMode dragAndDropVisualMode = DragAndDropVisualMode.None;
                    if (flag)
                    {
                        if (dropPosition == TreeViewDragging.DropPosition.Upon)
                        {
                            dragAndDropVisualMode = this.DoDrag(targetItem, targetItem, true, dropPosition);
                        }
                        if (dragAndDropVisualMode == DragAndDropVisualMode.None && treeViewItem != null)
                        {
                            dragAndDropVisualMode = this.DoDrag(treeViewItem, targetItem, true, dropPosition);
                        }
                        if (dragAndDropVisualMode != DragAndDropVisualMode.None)
                        {
                            this.FinalizeDragPerformed(false);
                        }
                        else
                        {
                            this.DragCleanup(true);
                            this.m_TreeView.NotifyListenersThatDragEnded(null, false);
                        }
                    }
                    else
                    {
                        if (this.m_DropData == null)
                        {
                            this.m_DropData = new TreeViewDragging.DropData();
                        }
                        this.m_DropData.dropTargetControlID = 0;
                        this.m_DropData.rowMarkerControlID  = 0;
                        int itemControlID = TreeViewController.GetItemControlID(targetItem);
                        this.HandleAutoExpansion(itemControlID, targetItem, targetItemRect, num, mousePosition);
                        if (dropPosition == TreeViewDragging.DropPosition.Upon)
                        {
                            dragAndDropVisualMode = this.DoDrag(targetItem, targetItem, false, dropPosition);
                        }
                        if (dragAndDropVisualMode != DragAndDropVisualMode.None)
                        {
                            this.m_DropData.dropTargetControlID = itemControlID;
                            DragAndDrop.visualMode = dragAndDropVisualMode;
                        }
                        else if (targetItem != null && treeViewItem != null)
                        {
                            dragAndDropVisualMode = this.DoDrag(treeViewItem, targetItem, false, dropPosition);
                            if (dragAndDropVisualMode != DragAndDropVisualMode.None)
                            {
                                this.drawRowMarkerAbove            = (dropPosition == TreeViewDragging.DropPosition.Above);
                                this.m_DropData.rowMarkerControlID = itemControlID;
                                DragAndDrop.visualMode             = dragAndDropVisualMode;
                            }
                        }
                    }
                    Event.current.Use();
                    result = true;
                }
            }
            return(result);
        }