Esempio n. 1
0
        internal IEnumerable <NodeControlInfo> GetNodeControls(TreeNodeAdv node, Rectangle rowRect)
        {
            if (node == null)
            {
                yield break;
            }

            int y     = rowRect.Y;
            int x     = (node.Level - 1) * _indent + LeftMargin;
            int width = 0;

            if (node.Row == 0 && ShiftFirstNode)
            {
                x -= _indent;
            }
            Rectangle rect = Rectangle.Empty;

            if (ShowPlusMinus)
            {
                width = _plusMinus.GetActualSize(node, _measureContext).Width;
                rect  = new Rectangle(x, y, width, rowRect.Height);
                if (UseColumns && Columns.Count > 0 && Columns[0].Width < rect.Right)
                {
                    rect.Width = Columns[0].Width - x;
                }

                yield return(new NodeControlInfo(_plusMinus, rect, node));

                x += width;
            }

            if (!UseColumns)
            {
                foreach (NodeControl c in NodeControls)
                {
                    Size s = c.GetActualSize(node, _measureContext);
                    if (!s.IsEmpty)
                    {
                        width = s.Width;
                        rect  = new Rectangle(x, y, width, rowRect.Height);
                        x    += rect.Width;
                        yield return(new NodeControlInfo(c, rect, node));
                    }
                }
            }
            else
            {
                int right = 0;
                foreach (TreeColumn col in Columns)
                {
                    if (col.IsVisible && col.Width > 0)
                    {
                        right += col.Width;
                        for (int i = 0; i < NodeControls.Count; i++)
                        {
                            NodeControl nc = NodeControls[i];
                            if (nc.ParentColumn == col)
                            {
                                Size s = nc.GetActualSize(node, _measureContext);
                                if (!s.IsEmpty)
                                {
                                    bool isLastControl = true;
                                    for (int k = i + 1; k < NodeControls.Count; k++)
                                    {
                                        if (NodeControls[k].ParentColumn == col)
                                        {
                                            isLastControl = false;
                                            break;
                                        }
                                    }

                                    width = right - x;
                                    if (!isLastControl)
                                    {
                                        width = s.Width;
                                    }
                                    int maxWidth = Math.Max(0, right - x);
                                    rect = new Rectangle(x, y, Math.Min(maxWidth, width), rowRect.Height);
                                    x   += width;
                                    yield return(new NodeControlInfo(nc, rect, node));
                                }
                            }
                        }
                        x = right;
                    }
                }
            }
        }
Esempio n. 2
0
        internal IEnumerable <NodeControlInfo> GetNodeControls(TreeNodeAdv node, Rectangle rowRect)
        {
            if (node == null)
            {
                yield break;
            }

            int       y = rowRect.Y;
            int       x = (node.Level - 1) * _indent + LeftMargin;
            int       width;
            Rectangle rect;

            if (ShowPlusMinus)
            {
                width = _plusMinus.GetActualSize(node, _measureContext).Width;
                rect  = new Rectangle(x, y, width, rowRect.Height);

                if (this.Columns.Count > 0 && this.Columns[0].Width < rect.Right)
                {
                    rect.Width = this.Columns[0].Width - x;
                }

                yield return(new NodeControlInfo(_plusMinus, rect, node));

                x += width;
            }


            int right = 0;

            foreach (TreeColumn col in this.Columns)
            {
                if (!col.IsVisible || col.Width <= 0)
                {
                    continue;
                }

                right += col.Width;

                for (int i = 0; i < this.NodeControls.Count; i++)
                {
                    NodeControl nc = this.NodeControls[i];

                    if (nc.ParentColumn != col)
                    {
                        continue;
                    }

                    Size s = nc.GetActualSize(node, _measureContext);

                    if (s.IsEmpty)
                    {
                        continue;
                    }

                    bool isLastControl = true;

                    for (int k = i + 1; k < this.NodeControls.Count; k++)
                    {
                        if (this.NodeControls[k].ParentColumn == col)
                        {
                            isLastControl = false;
                            break;
                        }
                    }

                    width = right - x;

                    if (!isLastControl)
                    {
                        width = s.Width;
                    }

                    int maxWidth = Math.Max(0, right - x);
                    rect = new Rectangle(x, y, Math.Min(maxWidth, width), rowRect.Height);
                    x   += width;

                    yield return(new NodeControlInfo(nc, rect, node));
                }
                x = right;
            }
        }