public static int GetVisibleNodeIndex(TLNode node)
        {
            if (node == null || node.IsVisible() == false || node.GetRootCollection() == null)
            {
                return(-1);
            }

            // Finding the node index is done by searching up the tree and use the visible node count from each node.
            // First all previous siblings are searched, then when first sibling in the node collection is reached
            // the node is switch to the parent node and the again a search is done up the sibling list.
            // This way only higher up the tree are being iterated while nodes at the same level are skipped.
            // Worst case scenario is if all nodes are at the same level. In that case the search is a linear search.

            // adjust count for the visible count of the current node.
            int count = -node.VisibleNodeCount;

            while (node != null)
            {
                count += node.VisibleNodeCount;
                if (node.PrevSibling != null)
                {
                    node = node.PrevSibling;
                }
                else
                {
                    node = node.Parent;
                    if (node != null)
                    {
                        count -= node.VisibleNodeCount - 1; // -1 is for the node itself
                    }
                }
            }
            return(count);
        }
Beispiel #2
0
 public override void NotifyBeforeExpand(TLNode nodeToExpand, bool expanding)
 {
     if (!m_tree.DesignMode)
     {
         m_tree.OnNotifyBeforeExpand(nodeToExpand, expanding);
     }
 }
 public static TLNode GetNextNode(TLNode startingNode, int searchOffset)
 {
     if (searchOffset == 0)
     {
         return(startingNode);
     }
     if (searchOffset > 0)
     {
         ForwardNodeEnumerator iterator = new ForwardNodeEnumerator(startingNode, true);
         while (searchOffset-- >= 0 && iterator.MoveNext())
         {
             ;
         }
         return(iterator.Current);
     }
     if (searchOffset < 0)
     {
         ReverseNodeEnumerator iterator = new ReverseNodeEnumerator(startingNode, true);
         while (searchOffset++ <= 0 && iterator.MoveNext())
         {
             ;
         }
         return(iterator.Current);
     }
     return(null);
 }
Beispiel #4
0
        public override TLNode Add(TLNode newnode)
        {
            var node = base.Add(newnode);

            m_tree.RecalcLayout();
            return(node);
        }
Beispiel #5
0
 protected virtual void raiseAfterSelect(TLNode node)
 {
     if (AfterSelect != null)
     {
         AfterSelect(this, new TreeViewEventArgs(null));
     }
 }
Beispiel #6
0
        protected override void OnMouseDown(MouseEventArgs e)
        {
            this.Focus();
            if (e.Button == MouseButtons.Right)
            {
                Point  mousePoint  = new Point(e.X, e.Y);
                TLNode clickedNode = CalcHitNode(mousePoint);
                if (clickedNode != null)
                {
                    // if multi select the selection is cleard if clicked node is not in selection
                    if (MultiSelect)
                    {
                        if (NodesSelection.Contains(clickedNode) == false)
                        {
                            MultiSelectAdd(clickedNode, Control.ModifierKeys);
                        }
                    }
                    FocusedNode = clickedNode;
                    Invalidate();
                }
                BeforeShowContextMenu();
            }

            if (e.Button == MouseButtons.Left)
            {
                HitInfo info = Columns.CalcHitInfo(new Point(e.X, e.Y), HScrollValue());
                if ((int)(info.HitType & HitInfo.eHitType.kColumnHeaderResize) > 0)
                {
                    m_resizingColumn             = info.Column;
                    m_resizingColumnScrollOffset = HScrollValue();
                    return;
                }
            }
            base.OnMouseDown(e);
        }
Beispiel #7
0
 protected virtual void raiseNotifyBeforeExpand(TLNode node, bool isExpanding)
 {
     if (NotifyBeforeExpand != null)
     {
         NotifyBeforeExpand(node, isExpanding);
     }
 }
Beispiel #8
0
 protected virtual void raiseNotifyAfterExpand(TLNode node, bool isExpanded)
 {
     if (NotifyAfterExpand != null)
     {
         NotifyAfterExpand(node, isExpanded);
     }
 }
 internal static void SetHasChildren(TLNode node, bool hasChildren)
 {
     if (node != null)
     {
         node.m_hasChildren = hasChildren;
     }
 }
Beispiel #10
0
        public virtual void PaintCell(Graphics dc,
                                      Rectangle cellRect,
                                      TLNode node,
                                      TreeListColumn column,
                                      TreeList.TextFormatting format,
                                      object data)
        {
            if (format.BackColor != Color.Transparent)
            {
                Rectangle r = cellRect;
                r.X     = column.CalculatedRect.X;
                r.Width = column.CalculatedRect.Width;
                using (SolidBrush brush = new SolidBrush(format.BackColor))
                    dc.FillRectangle(brush, r);
            }
            if (data != null)
            {
                cellRect = ColumnHeaderPainter.AdjustRectangle(cellRect, format.Padding);
                //dc.DrawRectangle(Pens.Black, cellRect);

                Color color = format.ForeColor;
                if (m_owner.FocusedNode == node && Application.RenderWithVisualStyles == false)
                {
                    color = SystemColors.HighlightText;
                }
                TextFormatFlags flags = TextFormatFlags.EndEllipsis | TextFormatFlags.NoPrefix | format.GetFormattingFlags();
                TextRenderer.DrawText(dc, data.ToString(), m_owner.Font, cellRect, color, flags);
            }
        }
Beispiel #11
0
 protected virtual void PaintImage(Graphics dc, Rectangle imageRect, TLNode node, Image image)
 {
     if (image != null)
     {
         dc.DrawImageUnscaled(image, imageRect);
     }
 }
Beispiel #12
0
 public virtual void DrawSelectionBackground(Graphics dc, Rectangle nodeRect, TLNode node)
 {
     if (m_owner.NodesSelection.Contains(node) || m_owner.FocusedNode == node)
     {
         if (!Application.RenderWithVisualStyles)
         {
             // have to fill the solid background only before the node is painted
             dc.FillRectangle(SystemBrushes.FromSystemColor(SystemColors.Highlight), nodeRect);
         }
         else
         {
             // have to draw the transparent background after the node is painted
             VisualStyleItemBackground.Style style = VisualStyleItemBackground.Style.Normal;
             if (m_owner.Focused == false)
             {
                 style = VisualStyleItemBackground.Style.Inactive;
             }
             VisualStyleItemBackground rendere = new VisualStyleItemBackground(style);
             rendere.DrawBackground(m_owner, dc, nodeRect);
         }
     }
     if (m_owner.Focused && (m_owner.FocusedNode == node))
     {
         nodeRect.Height += 1;
         nodeRect.Inflate(-1, -1);
         ControlPaint.DrawFocusRectangle(dc, nodeRect);
     }
 }
 public void InsertAfter(TLNode node, TLNode insertAfter)
 {
     m_version++;
     ClearInternalArray();
     Debug.Assert(node.Owner == null, "node.Owner == null");
     if (insertAfter == null)
     {
         node.InsertBefore(m_firstNode, this);
         m_firstNode = node;
     }
     else
     {
         node.InsertAfter(insertAfter, this);
     }
     if (m_lastNode == insertAfter)
     {
         m_lastNode = node;
         node.Id    = m_nextId++;
     }
     else
     {
         m_IdDirty++;
     }
     m_count++;
 }
        public virtual void Remove(TLNode node)
        {
            if (m_lastNode == null)
            {
                return;
            }
            m_version++;
            ClearInternalArray();
            //Debug.Assert(node != null && object.ReferenceEquals(node.Owner, this), "Remove(Node node)");

            TLNode prev = node.PrevSibling;
            TLNode next = node.NextSibling;

            node.Remove();

            if (prev == null) // first node
            {
                m_firstNode = next;
            }
            if (next == null) // last node
            {
                m_lastNode = prev;
            }
            m_IdDirty++;
            m_count--;
            TLNode.SetHasChildren(m_owner, m_count != 0);
        }
Beispiel #15
0
        protected override void OnMouseClick(MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                Point  mousePoint  = new Point(e.X, e.Y);
                TLNode clickedNode = CalcHitNode(mousePoint);
                if (clickedNode != null && Columns.Count > 0)
                {
                    int       clickedRow = CalcHitRow(mousePoint);
                    Rectangle glyphRect  = GetPlusMinusRectangle(clickedNode, Columns.VisibleColumns[0], clickedRow);
                    if (clickedNode.HasChildren && glyphRect != Rectangle.Empty && glyphRect.Contains(mousePoint))
                    {
                        clickedNode.Expanded = !clickedNode.Expanded;
                    }

                    if (MultiSelect)
                    {
                        MultiSelectAdd(clickedNode, Control.ModifierKeys);
                    }
                    else
                    {
                        FocusedNode = clickedNode;
                    }
                }
            }
            base.OnMouseClick(e);
        }
Beispiel #16
0
 protected virtual object GetData(TLNode node, TreeListColumn column)
 {
     if (node[column.Index] != null)
     {
         return(node[column.Index]);
     }
     return(null);
 }
Beispiel #17
0
 protected virtual Image GetNodeBitmap(TLNode node)
 {
     if (Images != null && node.ImageId >= 0 && node.ImageId < Images.Images.Count)
     {
         return(Images.Images[node.ImageId]);
     }
     return(null);
 }
Beispiel #18
0
 void MultiSelectAdd(TLNode clickedNode, Keys modifierKeys)
 {
     if (Control.ModifierKeys == Keys.None)
     {
         foreach (TLNode node in NodesSelection)
         {
             int newrow = NodeCollection.GetVisibleNodeIndex(node);
             InvalidateRow(newrow);
         }
         NodesSelection.Clear();
         NodesSelection.Add(clickedNode);
     }
     if (Control.ModifierKeys == Keys.Shift)
     {
         if (NodesSelection.Count == 0)
         {
             NodesSelection.Add(clickedNode);
         }
         else
         {
             int startrow = NodeCollection.GetVisibleNodeIndex(NodesSelection[0]);
             int currow   = NodeCollection.GetVisibleNodeIndex(clickedNode);
             if (currow > startrow)
             {
                 TLNode startingNode = NodesSelection[0];
                 NodesSelection.Clear();
                 foreach (TLNode node in NodeCollection.ForwardNodeIterator(startingNode, clickedNode, true))
                 {
                     NodesSelection.Add(node);
                 }
                 Invalidate();
             }
             if (currow < startrow)
             {
                 TLNode startingNode = NodesSelection[0];
                 NodesSelection.Clear();
                 foreach (TLNode node in NodeCollection.ReverseNodeIterator(startingNode, clickedNode, true))
                 {
                     NodesSelection.Add(node);
                 }
                 Invalidate();
             }
         }
     }
     if (Control.ModifierKeys == Keys.Control)
     {
         if (NodesSelection.Contains(clickedNode))
         {
             NodesSelection.Remove(clickedNode);
         }
         else
         {
             NodesSelection.Add(clickedNode);
         }
     }
     InvalidateRow(NodeCollection.GetVisibleNodeIndex(clickedNode));
     FocusedNode = clickedNode;
 }
        public static IEnumerable ForwardNodeIterator(TLNode firstNode, bool mustBeVisible)
        {
            ForwardNodeEnumerator iterator = new ForwardNodeEnumerator(firstNode, mustBeVisible);

            while (iterator.MoveNext())
            {
                yield return(iterator.Current);
            }
        }
        /// <summary>
        /// MakeVisible will expand all the parents up the tree.
        /// </summary>
        public void MakeVisible()
        {
            TLNode parent = Parent;

            while (parent != null)
            {
                parent.Expanded = true;
                parent          = parent.Parent;
            }
        }
        public TLNode NodeAtIndex(int index)
        {
            TLNode node = FirstNode;

            while (index-- > 0 && node != null)
            {
                node = node.NextSibling;
            }
            return(node);
        }
        public TLNode GetRoot()
        {
            TLNode parent = this;

            while (parent.Parent != null)
            {
                parent = parent.Parent;
            }
            return(parent);
        }
Beispiel #23
0
        object GetDataDesignMode(TLNode node, TreeListColumn column)
        {
            string id = string.Empty;

            while (node != null)
            {
                id   = node.Owner.GetNodeIndex(node).ToString() + ":" + id;
                node = node.Parent;
            }
            return("<temp>" + id);
        }
Beispiel #24
0
        protected override void OnMouseDoubleClick(MouseEventArgs e)
        {
            base.OnMouseDoubleClick(e);
            Point  mousePoint  = new Point(e.X, e.Y);
            TLNode clickedNode = CalcHitNode(mousePoint);

            if (clickedNode != null && clickedNode.HasChildren)
            {
                clickedNode.Expanded = !clickedNode.Expanded;
            }
        }
Beispiel #25
0
 protected virtual void PaintCell(Graphics dc, Rectangle cellRect, TLNode node, TreeListColumn column)
 {
     if (this.DesignMode)
     {
         CellPainter.PaintCell(dc, cellRect, node, column, GetFormatting(node, column), GetDataDesignMode(node, column));
     }
     else
     {
         CellPainter.PaintCell(dc, cellRect, node, column, GetFormatting(node, column), GetData(node, column));
     }
 }
Beispiel #26
0
        protected virtual int GetIndentSize(TLNode node)
        {
            int    indent = 0;
            TLNode parent = node.Parent;

            while (parent != null)
            {
                indent += ViewOptions.Indent;
                parent  = parent.Parent;
            }
            return(indent);
        }
 public static TLNode FindNodesBottomLeaf(TLNode node, bool mustBeVisible)
 {
     if (mustBeVisible && node.Expanded == false)
     {
         return(node);
     }
     if (node.HasChildren == false || node.Nodes.LastNode == null)
     {
         return(node);
     }
     node = node.Nodes.LastNode;
     return(FindNodesBottomLeaf(node, mustBeVisible));
 }
Beispiel #28
0
        void OnVScroll(object sender, ScrollEventArgs e)
        {
            int diff = e.NewValue - e.OldValue;

            //assumedScrollPos += diff;
            if (e.NewValue == 0)
            {
                m_firstVisibleNode = Nodes.FirstNode;
                diff = 0;
            }
            m_firstVisibleNode = NodeCollection.GetNextNode(m_firstVisibleNode, diff);
            Invalidate();
        }
 public bool MoveNext()
 {
     if (m_firstNode == null)
     {
         return(false);
     }
     if (m_current == null)
     {
         m_current = m_firstNode;
         return(true);
     }
     m_current = m_current.NextSibling;
     return(m_current != null);
 }
Beispiel #30
0
        public void EnsureVisible(TLNode node)
        {
            int screenvisible = MaxVisibleRows() - 1;
            int visibleIndex  = NodeCollection.GetVisibleNodeIndex(node);

            if (visibleIndex < VScrollValue())
            {
                SetVScrollValue(visibleIndex);
            }
            if (visibleIndex > VScrollValue() + screenvisible)
            {
                SetVScrollValue(visibleIndex - screenvisible);
            }
        }