Ejemplo n.º 1
0
      internal void EnsureSelectionVisible(EnsureSelectionVisibleAction action)
      {
         if (_selectedNodes.Count == 0 || action == EnsureSelectionVisibleAction.None)
            return;

         Boolean ensureSelVisible = false;

         if ((action & EnsureSelectionVisibleAction.SelectionChanged) == EnsureSelectionVisibleAction.SelectionChanged)
            ensureSelVisible = true;
         else if ((action & EnsureSelectionVisibleAction.HierarchyChanged) == EnsureSelectionVisibleAction.HierarchyChanged)
            ensureSelVisible = true;
         else if ((action & EnsureSelectionVisibleAction.LayerChanged) == EnsureSelectionVisibleAction.LayerChanged)
            ensureSelVisible = true;
         else if ((action & EnsureSelectionVisibleAction.MaterialChanged) == EnsureSelectionVisibleAction.MaterialChanged)
            ensureSelVisible = true;

         if (ensureSelVisible)
         {
            List<TreeNode> selectedTreeNodes = new List<TreeNode>(_selectedNodes.Count);
            ExpandPolicy expPolicy = ExpandPolicy.Never;
            if (ListMode == OutlinerListMode.Hierarchy)
            {
               if (AutoExpandHierarchy)
                  expPolicy = ExpandPolicy.Always;
               else
                  expPolicy = ExpandSelectionPolicyHierarchy;
            }
            else if (ListMode == OutlinerListMode.Layer)
            {
               if (AutoExpandLayer)
                  expPolicy = ExpandPolicy.Always;
               else
                  expPolicy = ExpandSelectionPolicyLayer;
            }
            else if (ListMode == OutlinerListMode.Material)
            {
               if (AutoExpandMaterial)
                  expPolicy = ExpandPolicy.Always;
               else
                  expPolicy = ExpandSelectionPolicyMaterial;
            }


            _internalExpandCollapse = true;
            Boolean shouldExpandSelection = true;
            foreach (OutlinerNode n in _selectedNodes)
            {
               TreeNode tn;
               if (_treeNodes.TryGetValue(n, out tn))
               {
                  selectedTreeNodes.Add(tn);

                  if (expPolicy == ExpandPolicy.WhenNecessary && !hasCollapsedParents(tn))
                     shouldExpandSelection = false;
                  else if (expPolicy == ExpandPolicy.Always && hasCollapsedParents(tn))
                  {
                     TreeNode p = tn.Parent;
                     while (p != null)
                     {
                        p.Expand();
                        p = p.Parent;
                     }
                  }
               }
            }


            if (expPolicy == ExpandPolicy.WhenNecessary && shouldExpandSelection && selectedTreeNodes.Count > 0)
            {
               TreeNode tn = selectedTreeNodes[0].Parent;
               while (tn != null)
               {
                  tn.Expand();
                  tn = tn.Parent;
               }
            }

            _internalExpandCollapse = false;


            List<Rectangle> treeNodeBounds = new List<Rectangle>(_selectedNodes.Count);
            TreeNode highestNode = null;
            Int32 highestNodeY = Int32.MaxValue;
            foreach (TreeNode tn in selectedTreeNodes)
            {
               Rectangle bounds = tn.Bounds;
               treeNodeBounds.Add(bounds);
               if (bounds.Y < highestNodeY && !hasCollapsedParents(tn))
               {
                  highestNode = tn;
                  highestNodeY = bounds.Y;
               }
            }

            if (highestNode != null)
            {
               highestNode.EnsureVisible();
               TreeNode lowestNode = null;
               Int32 lowestNodeY = Int32.MinValue;
               for (Int32 i = 0; i < selectedTreeNodes.Count; i++)
               {
                  TreeNode tn = selectedTreeNodes[i];
                  if (tn != highestNode)
                  {
                     Rectangle bounds = treeNodeBounds[i];
                     if (((bounds.Y + bounds.Height) - highestNodeY) < ClientRectangle.Height && bounds.Y > lowestNodeY && !hasCollapsedParents(tn))
                     {
                        lowestNode = tn;
                        lowestNodeY = bounds.Y;
                     }
                  }
               }

               if (lowestNode != null)
               {
                  lowestNode.EnsureVisible();
               }
            }
         }
      }
Ejemplo n.º 2
0
 internal void BeginTimedEnsureSelectionVisible(EnsureSelectionVisibleAction action)
 {
    _ensureSelectionVisibleAction |= action;
    if (!_ensureSelectionVisibleTimer.Enabled)
       _ensureSelectionVisibleTimer.Start();
 }
Ejemplo n.º 3
0
 void _ensureSelectionVisibleTimer_Tick(object sender, EventArgs e)
 {
    _ensureSelectionVisibleTimer.Stop();
    if (!_sortTimer.Enabled)
    {
       EnsureSelectionVisible(_ensureSelectionVisibleAction);
       _ensureSelectionVisibleAction = EnsureSelectionVisibleAction.None;
    }
    else
       _ensureSelectionVisibleWaitingForSort = true;
 }
Ejemplo n.º 4
0
      public TreeView()
      {
         InitializeComponent();

         this.SetStyle(ControlStyles.UserPaint, true);
         this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
         this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);

         AllowDrop = true;

         Scene = new OutlinerScene();
         Style = new TreeStyle(this);
         Filter = new OutlinerFilter(this);

         ListMode = OutlinerListMode.Hierarchy;

         IconClickAction = IconClickAction.Hide;
         ShowNodeHideButton = true;
         InvertNodeHideButton = false;
         ShowNodeFreezeButton = true;
         ShowNodeBoxModeButton = false;

         HighlighLastSelectedObject = false;

         AutoExpandHierarchy = false;
         AutoExpandLayer = false;
         AutoExpandMaterial = false;

         ExpandHierarchyKey = Keys.Control;
         DragMouseButton = MouseButtons.Middle;
         DoubleClickAction = DoubleClickAction.Rename;


         _treeNodes = new Dictionary<OutlinerNode, TreeNode>();
         _selectedNodes = new HashSet<OutlinerNode>();
         _expandedNodeHandles = new HashSet<Int32>();

         _treeDragDropHandler = new TreeDragDropHandler(this, Scene);

         _updateTimer = new Timer();
         _updateTimer.Interval = 40;
         _updateTimer.Tick += new EventHandler(updateTimer_Tick);

         _sortTimer = new Timer();
         _sortTimer.Interval = 60;
         _sortTimer.Tick += new EventHandler(sortTimer_Tick);

         _updateWaitingForSort = false;

         _ensureSelectionVisibleTimer = new Timer();
         _ensureSelectionVisibleTimer.Interval = 50;
         _ensureSelectionVisibleTimer.Tick += new EventHandler(_ensureSelectionVisibleTimer_Tick);
         _ensureSelectionVisibleAction = EnsureSelectionVisibleAction.None;
         _ensureSelectionVisibleWaitingForSort = false;
      }