Example #1
0
 public RecursiveNodesEnumerator(NodeCollection collection, bool mustBeVisible)
 {
     m_enumerator = new NodeCollIterator(collection, mustBeVisible);
 }
Example #2
0
        protected override void OnKeyDown(KeyEventArgs e)
        {
            Node newnode = null;

            if (e.KeyCode == Keys.PageUp)
            {
                int remainder = 0;
                int diff      = MaxVisibleRows(out remainder) - 1;
                newnode = NodeCollection.GetNextNode(FocusedNode, -diff);
                if (newnode == null)
                {
                    newnode = Nodes.FirstVisibleNode();
                }
            }
            if (e.KeyCode == Keys.PageDown)
            {
                int remainder = 0;
                int diff      = MaxVisibleRows(out remainder) - 1;
                newnode = NodeCollection.GetNextNode(FocusedNode, diff);
                if (newnode == null)
                {
                    newnode = Nodes.LastVisibleNode(true);
                }
            }

            if (e.KeyCode == Keys.Down)
            {
                newnode = NodeCollection.GetNextNode(FocusedNode, 1);
            }
            if (e.KeyCode == Keys.Up)
            {
                newnode = NodeCollection.GetNextNode(FocusedNode, -1);
            }
            if (e.KeyCode == Keys.Home)
            {
                newnode = Nodes.FirstNode;
            }
            if (e.KeyCode == Keys.End)
            {
                newnode = Nodes.LastVisibleNode(true);
            }
            if (e.KeyValue == 109) // Touche (-) numérique
            {
                if (FocusedNode != null)
                {
                    if (FocusedNode.Expanded)
                    {
                        FocusedNode.Collapse();
                        EnsureVisible(FocusedNode);
                        return;
                    }
                }
            }
            if (e.KeyCode == Keys.Left)
            {
                if (FocusedNode != null)
                {
                    if (FocusedNode.Expanded)
                    {
                        FocusedNode.Collapse();
                        EnsureVisible(FocusedNode);
                        return;
                    }
                    if (FocusedNode.Parent != null)
                    {
                        FocusedNode = FocusedNode.Parent;
                        EnsureVisible(FocusedNode);
                    }
                }
            }
            if (e.KeyValue == 107) // Touche (+) numérique
            {
                if (FocusedNode != null)
                {
                    if (FocusedNode.Expanded == false && FocusedNode.HasChildren)
                    {
                        FocusedNode.Expand();
                        EnsureVisible(FocusedNode);
                        return;
                    }
                }
            }
            if (e.KeyCode == Keys.Right)
            {
                if (FocusedNode != null)
                {
                    if (FocusedNode.Expanded == false && FocusedNode.HasChildren)
                    {
                        FocusedNode.Expand();
                        EnsureVisible(FocusedNode);
                        return;
                    }
                    if (FocusedNode.Expanded == true && FocusedNode.HasChildren)
                    {
                        FocusedNode = FocusedNode.Nodes.FirstNode;
                        EnsureVisible(FocusedNode);
                    }
                }
            }
            if (e.KeyValue == 106) // Touche (*) numérique
            {
                if (FocusedNode != null)
                {
                    if (FocusedNode.Expanded == false && FocusedNode.HasChildren)
                    {
                        FocusedNode.ExpandAll();
                        EnsureVisible(FocusedNode);
                        return;
                    }
                }
            }

            if (newnode != null)
            {
                if (MultiSelect)
                {
                    // tree behavior is
                    // keys none,		the selected node is added as the focused and selected node
                    // keys control,	only focused node is moved, the selected nodes collection is not modified
                    // keys shift,		selection from first selected node to current node is done
                    if (Control.ModifierKeys == Keys.Control)
                    {
                        FocusedNode = newnode;
                    }
                    else
                    {
                        MultiSelectAdd(newnode, Control.ModifierKeys);
                    }
                }
                else
                {
                    FocusedNode = newnode;
                }
                EnsureVisible(FocusedNode);
            }
            base.OnKeyDown(e);
        }
Example #3
0
 public NodeCollIterator(NodeCollection collection, bool mustBeVisible)
 {
     m_firstNode = collection.FirstNode;
     m_visible   = mustBeVisible;
 }
Example #4
0
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            int hScrollOffset = HScrollValue();
            int remainder     = 0;
            int visiblerows   = MaxVisibleRows(out remainder);

            if (remainder > 0)
            {
                visiblerows++;
            }

            bool drawColumnHeaders = true;

            // draw columns
            if (drawColumnHeaders)
            {
                Rectangle headerRect = e.ClipRectangle;
                Columns.Draw(e.Graphics, headerRect, hScrollOffset);
            }
            // draw vertical grid lines
            if (ViewOptions.ShowGridLines)
            {
                // visible row count
                int remainRows = Nodes.VisibleNodeCount - m_vScroll.Value;
                if (visiblerows > remainRows)
                {
                    visiblerows = remainRows;
                }

                Rectangle fullRect = ClientRectangle;
                if (drawColumnHeaders)
                {
                    fullRect.Y += Columns.Options.HeaderHeight;
                }
                fullRect.Height = visiblerows * RowOptions.ItemHeight;
                Columns.Painter.DrawVerticalGridLines(Columns, e.Graphics, fullRect, hScrollOffset);
            }

            int visibleRowIndex = 0;

            TreeListColumn[] visibleColumns = this.Columns.VisibleColumns;
            int columnsWidth = Columns.ColumnsWidth;

            foreach (Node node in NodeCollection.ForwardNodeIterator(m_firstVisibleNode, true))
            {
                Rectangle rowRect = CalcRowRecangle(visibleRowIndex);
                if (rowRect == Rectangle.Empty || rowRect.Bottom <= e.ClipRectangle.Top || rowRect.Top >= e.ClipRectangle.Bottom)
                {
                    if (visibleRowIndex > visiblerows)
                    {
                        break;
                    }
                    visibleRowIndex++;
                    continue;
                }
                rowRect.X     = RowHeaderWidth() - hScrollOffset;
                rowRect.Width = columnsWidth;

                // draw horizontal grid line for current node
                if (ViewOptions.ShowGridLines)
                {
                    Rectangle r = rowRect;
                    r.X     = RowHeaderWidth();
                    r.Width = columnsWidth - hScrollOffset;
                    m_rowPainter.DrawHorizontalGridLine(e.Graphics, r);
                }

                // draw the current node
                PaintNode(e.Graphics, rowRect, node, visibleColumns, visibleRowIndex);

                // drow row header for current node
                Rectangle headerRect = rowRect;
                headerRect.X     = 0;
                headerRect.Width = RowHeaderWidth();

                int absoluteRowIndex = visibleRowIndex + VScrollValue();
                headerRect.Width = RowHeaderWidth();

                PaintRowHeader(e.Graphics, headerRect, node, absoluteRowIndex == m_hotrow);

                visibleRowIndex++;
            }
        }