public override Size LayoutCells(NodeLayoutContextInfo layoutInfo, int x, int y) { eCellLayout layout = layoutInfo.CellLayout; if (layoutInfo.ContextNode.CellLayout != layoutInfo.CellLayout && layoutInfo.ContextNode.CellLayout != eCellLayout.Default) layout = layoutInfo.ContextNode.CellLayout; if (layout == eCellLayout.Default && !(layoutInfo.ContextNode.HasChildNodes && layoutInfo.IsViewGroupping) && layoutInfo.ContextNode.ImageAlignment == eCellPartAlignment.Default) { return TileLayout(layoutInfo, x, y); } else return base.LayoutCells(layoutInfo, x, y); }
//private int _ExpandAreaWidth = 24; ///// <summary> ///// Returns width of the expand button area. Default is 24 pixels. ///// </summary> //public virtual int ExpandAreaWidth //{ // get { return _ExpandAreaWidth; } // set // { // _ExpandAreaWidth = value; // } //} ///// <summary> ///// Gets or sets width of command button area. Default is 8 pixels. ///// </summary> //public virtual int CommandAreaWidth //{ // get {return m_CommandAreaWidth;} // set {m_CommandAreaWidth=value;} //} /// <summary> /// Sets the position and size of the node command button. /// </summary> /// <param name="layoutInfo">Node layout context information</param> protected virtual void LayoutCommandPart(NodeLayoutContextInfo layoutInfo, ElementStyle nodeStyle) { // Command part is right-aligned just before the node border Rectangle bounds = new Rectangle(layoutInfo.ContextNode.ContentBounds.Right - this.LayoutSettings.CommandAreaWidth - ElementStyleLayout.StyleSpacing(nodeStyle,eSpacePart.Border,eStyleSide.Right),layoutInfo.ContextNode.ContentBounds.Y+ ElementStyleLayout.StyleSpacing(nodeStyle,eSpacePart.Border,eStyleSide.Top), this.LayoutSettings.CommandAreaWidth, layoutInfo.ContextNode.ContentBounds.Height - ElementStyleLayout.StyleSpacing(nodeStyle,eSpacePart.Border,eStyleSide.Top)- ElementStyleLayout.StyleSpacing(nodeStyle,eSpacePart.Border,eStyleSide.Bottom)); // Rectangle bounds=new Rectangle(layoutInfo.ContextNode.ContentBounds.Right-this.CommandAreaWidth- // ElementStyleLayout.StyleSpacing(nodeStyle,eSpacePart.Border,eStyleSide.Right),layoutInfo.ContextNode.ContentBounds.Y, // this.CommandAreaWidth, layoutInfo.ContextNode.ContentBounds.Height); layoutInfo.ContextNode.CommandBoundsRelative=bounds; }
private Size TileLayout(NodeLayoutContextInfo layoutInfo, int x, int y) { Node node = layoutInfo.ContextNode; int height = 0, width = 0, realHeight = 0; //eHorizontalAlign align = eHorizontalAlign.Left; Size tileSize = layoutInfo.TileSize; int iVisibleCells = 0; int cellCount = node.Cells.Count; bool isVerticalOverflow = false; for (int i = 0; i < cellCount; i++) { Cell cell = node.Cells[i]; bool bCellVisible = isVerticalOverflow ? false : true; // Setup cell layout helper class LayoutCellInfo cellLayout = this.GetLayoutCellInfo(); cellLayout.Top = y; cellLayout.Left = x; cellLayout.CellWidth = tileSize.Width; cellLayout.ContextCell = cell; cellLayout.Graphics = layoutInfo.Graphics; cellLayout.LeftToRight = layoutInfo.LeftToRight; cellLayout.Font = layoutInfo.DefaultFont; cellLayout.View = layoutInfo.View; cellLayout.CellIndex = i; if (cell.Layout != eCellPartLayout.Default) cellLayout.VerticalPartAlignment = (cell.Layout == eCellPartLayout.Vertical); else if (layoutInfo.CellPartLayout != eCellPartLayout.Default) cellLayout.VerticalPartAlignment = (layoutInfo.CellPartLayout == eCellPartLayout.Vertical); // Prepare union style if (cell.StyleNormal != null) cellLayout.LayoutStyle = cell.StyleNormal; else cellLayout.LayoutStyle = layoutInfo.DefaultCellStyle; this.LayoutSingleTileCell(cellLayout); if (bCellVisible && y + cell.BoundsRelative.Height > tileSize.Height && i > 0) { isVerticalOverflow = true; bCellVisible = false; } cell.SetVisible(bCellVisible); if (bCellVisible) { iVisibleCells++; y += cell.BoundsRelative.Height; height += cell.BoundsRelative.Height; if (cell.BoundsRelative.Height > 0) { y += this.CellVerticalSpacing; height += this.CellVerticalSpacing; } if (cell.BoundsRelative.Width > width) width = cell.BoundsRelative.Width; if (i == 0) { realHeight += cell.BoundsRelative.Height; if (cell.BoundsRelative.Height > 0) realHeight += this.CellVerticalSpacing; } else realHeight = Math.Max(realHeight, height); // Align other cells under the text of the first cell and to the right of the image, if any if (i == 0 && !cell.Images.LargestImageSize.IsEmpty && cellCount > 1) { if (cell.TextContentBounds.IsEmpty) x += cell.Images.LargestImageSize.Width + this.ImageTextSpacing; else x += (cell.TextContentBounds.X - x); tileSize.Width = cell.TextContentBounds.Width; height -= cell.BoundsRelative.Height; height += cell.TextContentBounds.Height; y -= cell.BoundsRelative.Height; y += cell.TextContentBounds.Height; } } } // Take last added spacing off y -= this.CellVerticalSpacing; height -= this.CellVerticalSpacing; realHeight -= this.CellVerticalSpacing; if (node.Cells[0].BoundsRelative.Height > height && !node.Cells[0].Images.LargestImageSize.IsEmpty) { int textOffset = ((realHeight - height) / iVisibleCells) / 2; if (textOffset > 0) { foreach (Cell cell in node.Cells) { if (!cell.IsVisible) continue; cell.TextContentBounds = new Rectangle(cell.TextContentBounds.X, cell.TextContentBounds.Y + textOffset, cell.TextContentBounds.Width, cell.TextContentBounds.Height); } } } else if(iVisibleCells == 1) { Rectangle rtc = node.Cells[0].TextContentBounds; node.Cells[0].TextContentBounds = new Rectangle(rtc.X, rtc.Y, rtc.Width, node.Cells[0].BoundsRelative.Height); } // Additional pass needed if horizontal alignment is other than left and there is more than one cell visible //if (align != eHorizontalAlign.Left && iVisibleCells > 1) //{ // foreach (Cell cell in node.Cells) // { // if (!cell.IsVisible) // continue; // if (align == eHorizontalAlign.Center) // this.Offset(cell, (width - cell.BoundsRelative.Width) / 2, 0); // else // Right aligned cells // this.Offset(cell, width - cell.BoundsRelative.Width, 0); // } //} if (width < layoutInfo.TileSize.Width) width = layoutInfo.TileSize.Width; if (realHeight < layoutInfo.TileSize.Height) realHeight = layoutInfo.TileSize.Height; return new Size(width, realHeight); }
public virtual Size LayoutCells(NodeLayoutContextInfo layoutInfo, int x, int y) { eCellLayout layout=layoutInfo.CellLayout; if (layoutInfo.ContextNode.CellLayout != layoutInfo.CellLayout && layoutInfo.ContextNode.CellLayout != eCellLayout.Default) layout = layoutInfo.ContextNode.CellLayout; if (layout == eCellLayout.Horizontal || layout == eCellLayout.Default && layoutInfo.View == eView.Tree || layoutInfo.View == eView.Tile && layoutInfo.IsViewGroupping && layoutInfo.ContextNode.HasChildNodes) return this.LayoutCellsHorizontal(layoutInfo, x, y); else return this.LayoutCellsVertical(layoutInfo, x, y); }
private Rectangle ProcessChildNodes(NodeLayoutContextInfo layoutInfo, Node node, int nodeVerticalSpacing, NodeColumnInfo childColumns) { Rectangle childNodesBounds = new Rectangle(layoutInfo.Left, layoutInfo.Top, 0, 0); foreach (Node childNode in node.Nodes) { if (!childNode.Visible) continue; layoutInfo.ContextNode = childNode; layoutInfo.ChildColumns = childColumns; ProcessNode(layoutInfo); childNodesBounds.Width = Math.Max(childNodesBounds.Width, Math.Max(childNode.BoundsRelative.Width, (childNode.Expanded && childNode.ChildNodesBounds.Width > 0 ? childNode.ChildNodesBounds.Right - childNodesBounds.X : 0))); childNodesBounds.Height += childNode.BoundsRelative.Height + (childNode.Expanded ? childNode.ChildNodesBounds.Height + childNode.ColumnHeaderHeight : 0) + nodeVerticalSpacing; } return childNodesBounds; }
/// <summary> /// Returns true if given node has expand part. /// </summary> /// <param name="layoutInfo">Layout context information.</param> /// <returns></returns> protected virtual bool HasExpandPart(NodeLayoutContextInfo layoutInfo) { Node node=layoutInfo.ContextNode; if(node.ExpandVisibility==eNodeExpandVisibility.Auto) { if(IsRootNode(node) && !RootHasExpandedPart || !NodeOperations.GetAnyVisibleNodes(node)) return false; return true; } else return (node.ExpandVisibility==eNodeExpandVisibility.Visible); }
protected virtual NodeLayoutContextInfo GetDefaultNodeLayoutContextInfo(System.Drawing.Graphics graphics) { NodeLayoutContextInfo layoutInfo=new NodeLayoutContextInfo(); layoutInfo.ClientRectangle=m_ClientArea; layoutInfo.DefaultColumns=this.GetDefaultColumnInfo(); layoutInfo.ChildColumns=null; layoutInfo.Indent = m_Tree.Indent; layoutInfo.Left=0; layoutInfo.Top=0; // TODO: Include Columns if visible into this... layoutInfo.DefaultFont=m_Tree.Font; layoutInfo.LeftToRight=(this.LeftRight==System.Windows.Forms.LeftRightAlignment.Left); layoutInfo.Graphics=graphics; layoutInfo.Styles=m_Tree.Styles; layoutInfo.FullRowBackgroundNodes = new ArrayList(); if(m_Tree.CellLayout!=eCellLayout.Default) layoutInfo.CellLayout=m_Tree.CellLayout; if(m_Tree.CellPartLayout!=eCellPartLayout.Default) layoutInfo.CellPartLayout=m_Tree.CellPartLayout; if(m_Tree.NodeStyle!=null) layoutInfo.DefaultNodeStyle=m_Tree.NodeStyle; if(m_Tree.CellStyleDefault!=null) layoutInfo.DefaultCellStyle=m_Tree.CellStyleDefault; else layoutInfo.DefaultCellStyle=ElementStyle.GetDefaultCellStyle(layoutInfo.DefaultNodeStyle); // Determine size of the default Column Header if(m_Tree.ColumnStyleNormal!=null) { ElementStyleLayout.CalculateStyleSize(m_Tree.ColumnStyleNormal,layoutInfo.DefaultFont); layoutInfo.DefaultHeaderSize=m_Tree.ColumnStyleNormal.Size; } if(layoutInfo.DefaultHeaderSize.IsEmpty) layoutInfo.DefaultHeaderSize.Height=layoutInfo.DefaultFont.Height+4; layoutInfo.ExpandPartWidth = this.Tree.ExpandWidth; layoutInfo.View = this.Tree.View; layoutInfo.TileSize = this.Tree.TileSize; layoutInfo.ColumnStyle = this.Tree.ColumnStyleNormal; return layoutInfo; }
private void ProcessNode(NodeLayoutContextInfo layoutInfo) { Node node=layoutInfo.ContextNode; if (!node.Visible || node.Cells.Count == 0) return; if (node.SizeChanged || _Groupping && node.HasChildNodes) { // Calculate size of the node itself... LayoutNode(layoutInfo); } if (node.FullRowBackground) layoutInfo.FullRowBackgroundNodes.Add(node); // Position the node if (_Groupping && node.HasChildNodes) { if (layoutInfo.CurrentLineHeight > 0) layoutInfo.Top += layoutInfo.CurrentLineHeight + this.LayoutSettings.NodeVerticalSpacing; layoutInfo.CurrentLineHeight = 0; } else { if (layoutInfo.Left + node.BoundsRelative.Width > this.ClientArea.Right) { layoutInfo.Left = layoutInfo.CurrentLevelLeft; layoutInfo.Top += layoutInfo.CurrentLineHeight + this.LayoutSettings.NodeVerticalSpacing; layoutInfo.CurrentLineHeight = 0; } } layoutInfo.CurrentLineHeight = Math.Max(layoutInfo.CurrentLineHeight, node.BoundsRelative.Height); if (node.BoundsRelative.X != layoutInfo.Left || node.BoundsRelative.Y != layoutInfo.Top) { // Adjust top position node.SetBounds(new Rectangle(layoutInfo.Left,layoutInfo.Top,node.BoundsRelative.Width,node.BoundsRelative.Height)); } // Position the node if (_Groupping && node.HasChildNodes) { if (layoutInfo.CurrentLineHeight > 0) layoutInfo.Top += layoutInfo.CurrentLineHeight + this.LayoutSettings.NodeVerticalSpacing; layoutInfo.CurrentLineHeight = 0; } int nodeVerticalSpacing = this.LayoutSettings.NodeVerticalSpacing; // Need to set the Top position properly //layoutInfo.Top += (node.BoundsRelative.Height + nodeVerticalSpacing); // No columns in tile view //if (DevComponents.AdvTree.Display.NodeDisplay.HasColumnsVisible(node)) // layoutInfo.Top += node.ColumnHeaderHeight; if(_Groupping && node.HasChildNodes && node.Expanded) { int originalLevelOffset=layoutInfo.Left; int originalLevelLeft = layoutInfo.CurrentLevelLeft; int childNodesTop = layoutInfo.Top; layoutInfo.Left += this.NodeLevelOffset + node.NodesIndent; layoutInfo.CurrentLevelLeft = layoutInfo.Left; NodeColumnInfo parentColumns = layoutInfo.ChildColumns; NodeColumnInfo childColumns = GetNodeColumnInfo(node); Rectangle childNodesBounds = ProcessChildNodes(layoutInfo, node, nodeVerticalSpacing, childColumns); //if (childColumns != null && childColumns.HasAutoSizeColumn) //{ // foreach (ColumnInfo columnInfo in childColumns.ColumnInfo) // { // if (columnInfo.AutoSize) // { // columnInfo.Width = columnInfo.MaxWidth; // columnInfo.ColumnHeader.Width.SetAutoSizeWidth(columnInfo.MaxWidth); // columnInfo.AutoSize = false; // columnInfo.MaxWidth = 0; // } // } // layoutInfo.Top = originalTop; // layoutInfo.Left = originalLevelOffset; // layoutInfo.ContextNode = node; // layoutInfo.ChildColumns = null; // LayoutNode(layoutInfo); // layoutInfo.Top = childNodesTop; // layoutInfo.Left += this.NodeLevelOffset + node.NodesIndent; // childNodesBounds = ProcessChildNodes(layoutInfo, node, nodeVerticalSpacing, childColumns); //} node.ChildNodesBounds = childNodesBounds; layoutInfo.ChildColumns=parentColumns; layoutInfo.ContextNode=node; layoutInfo.Left=originalLevelOffset; layoutInfo.CurrentLevelLeft = originalLevelLeft; } else node.ChildNodesBounds = Rectangle.Empty; }
/// <summary> /// Returns true if given node has expand part. /// </summary> /// <param name="layoutInfo">Layout context information.</param> /// <returns></returns> protected override bool HasExpandPart(NodeLayoutContextInfo layoutInfo) { Node node = layoutInfo.ContextNode; if (node.ExpandVisibility == eNodeExpandVisibility.Auto) { if (!_Groupping || !NodeOperations.GetAnyVisibleNodes(node)) return false; return true; } else return (node.ExpandVisibility == eNodeExpandVisibility.Visible); }
private Rectangle ProcessTopLevelNodes(Rectangle area, NodeLayoutContextInfo layoutInfo, Node[] topLevelNodes) { layoutInfo.CurrentLevelLeft = layoutInfo.Left; bool isPreviousGroupNode = false; foreach (Node childNode in topLevelNodes) { layoutInfo.ContextNode = childNode; if (childNode.Visible) { if (_Groupping && childNode.HasChildNodes) { if (layoutInfo.CurrentLineHeight > 0) layoutInfo.Top += layoutInfo.CurrentLineHeight + this.LayoutSettings.NodeVerticalSpacing; layoutInfo.CurrentLineHeight = 0; layoutInfo.Left = layoutInfo.CurrentLevelLeft; isPreviousGroupNode = true; } else { if (isPreviousGroupNode) { if (layoutInfo.CurrentLineHeight > 0) layoutInfo.Top += layoutInfo.CurrentLineHeight + this.LayoutSettings.NodeVerticalSpacing; layoutInfo.CurrentLineHeight = 0; layoutInfo.Left = layoutInfo.CurrentLevelLeft; } isPreviousGroupNode = false; } } ProcessNode(layoutInfo); if (childNode.Visible) { area = Rectangle.Union(area, childNode.BoundsRelative); if (childNode.Expanded && childNode.HasChildNodes) area = Rectangle.Union(area, childNode.ChildNodesBounds); if (!(_Groupping && childNode.HasChildNodes)) layoutInfo.Left += childNode.BoundsRelative.Width + this.LayoutSettings.NodeHorizontalSpacing; } } return area; }
private Rectangle ProcessChildNodes(NodeLayoutContextInfo layoutInfo, Node node, int nodeVerticalSpacing, NodeColumnInfo childColumns) { Rectangle childNodesBounds = new Rectangle(layoutInfo.Left, layoutInfo.Top, 0, 0); bool isPreviousGroupNode = false; foreach (Node childNode in node.Nodes) { if (!childNode.Visible) continue; if (_Groupping && childNode.HasChildNodes) { if (layoutInfo.CurrentLineHeight > 0) layoutInfo.Top += layoutInfo.CurrentLineHeight + this.LayoutSettings.NodeVerticalSpacing; layoutInfo.CurrentLineHeight = 0; layoutInfo.Left = layoutInfo.CurrentLevelLeft; isPreviousGroupNode = true; } else { if (isPreviousGroupNode) { if (layoutInfo.CurrentLineHeight > 0) layoutInfo.Top += layoutInfo.CurrentLineHeight + this.LayoutSettings.NodeVerticalSpacing; layoutInfo.CurrentLineHeight = 0; layoutInfo.Left = layoutInfo.CurrentLevelLeft; isPreviousGroupNode = false; } } layoutInfo.ContextNode = childNode; layoutInfo.ChildColumns = childColumns; ProcessNode(layoutInfo); if (!(_Groupping && childNode.HasChildNodes)) layoutInfo.Left += childNode.BoundsRelative.Width + this.LayoutSettings.NodeHorizontalSpacing; if (isPreviousGroupNode) { childNodesBounds.Width = Math.Max(childNodesBounds.Width, Math.Max(childNode.BoundsRelative.Width, (childNode.Expanded && childNode.ChildNodesBounds.Width > 0 ? childNode.ChildNodesBounds.Right - childNodesBounds.X : 0))); childNodesBounds.Height += childNode.BoundsRelative.Height + (childNode.Expanded ? childNode.ChildNodesBounds.Height + childNode.ColumnHeaderHeight : 0) + nodeVerticalSpacing; } else { childNodesBounds = Rectangle.Union(childNodesBounds, childNode.BoundsRelative); } } return childNodesBounds; }
private void LayoutTopLevelColumns(NodeLayoutContextInfo layoutInfo) { // There are no columns in Tile view this.Tree.SetColumnHeaderControlVisibility(false); }
protected virtual Size LayoutCellsVertical(NodeLayoutContextInfo layoutInfo, int x, int y) { Node node=layoutInfo.ContextNode; int height=0, width=0; eHorizontalAlign align = node.VerticalCellLayoutAlignment; // eHorizontalAlign.Center; int iVisibleCells=0; int cellCount = node.Cells.Count; for(int i=0;i<cellCount;i++) { Cell cell = null; if (layoutInfo.ChildColumns != null && layoutInfo.ChildColumns.ColumnInfo.Count == cellCount) cell = node.Cells[layoutInfo.ChildColumns.ColumnInfo[i].AbsoluteIndex]; else if(layoutInfo.DefaultColumns.ColumnInfo.Count == cellCount) cell = node.Cells[layoutInfo.DefaultColumns.ColumnInfo[i].AbsoluteIndex]; else cell = node.Cells[i]; bool bCellVisible=true; // Setup cell layout helper class LayoutCellInfo cellLayout=this.GetLayoutCellInfo(); cellLayout.Top=y; cellLayout.Left=x; cellLayout.CellWidth=0; cellLayout.ContextCell=cell; cellLayout.Graphics=layoutInfo.Graphics; cellLayout.LeftToRight=layoutInfo.LeftToRight; cellLayout.Font=layoutInfo.DefaultFont; if(cell.Layout!=eCellPartLayout.Default) cellLayout.VerticalPartAlignment=(cell.Layout==eCellPartLayout.Vertical); else if(layoutInfo.CellPartLayout!=eCellPartLayout.Default) cellLayout.VerticalPartAlignment=(layoutInfo.CellPartLayout==eCellPartLayout.Vertical); if (layoutInfo.DefaultColumns.ColumnInfo.Count > 0 || layoutInfo.ChildColumns != null && layoutInfo.ChildColumns.ColumnInfo.Count > 0) { ColumnInfo ci=null; if (layoutInfo.ChildColumns != null && layoutInfo.ChildColumns.ColumnInfo.Count > 0) ci=layoutInfo.ChildColumns.ColumnInfo[i] as ColumnInfo; else ci=layoutInfo.DefaultColumns.ColumnInfo[i] as ColumnInfo; bCellVisible=ci.Visible; cellLayout.CellWidth=ci.Width; } else if (layoutInfo.View == eView.Tile) { cellLayout.CellWidth = layoutInfo.TileSize.Width; cellLayout.CellHeight = layoutInfo.TileSize.Height; } // Prepare union style if(cell.StyleNormal!=null) cellLayout.LayoutStyle=cell.StyleNormal; else cellLayout.LayoutStyle=layoutInfo.DefaultCellStyle; this.LayoutSingleCell(cellLayout); cell.SetVisible(bCellVisible); if(bCellVisible) { iVisibleCells++; y+=cell.BoundsRelative.Height; height+=cell.BoundsRelative.Height; if(cell.BoundsRelative.Height>0) { y+=this.CellVerticalSpacing; height+=this.CellVerticalSpacing; } if(cell.BoundsRelative.Width>width) width=cell.BoundsRelative.Width; } } // Take last added spacing off y-=this.CellVerticalSpacing; height-=this.CellVerticalSpacing; // Additional pass needed if horizontal alignment is other than left and there is more than one cell visible if(align!=eHorizontalAlign.Left && iVisibleCells>1) { foreach(Cell cell in node.Cells) { if(!cell.IsVisible) continue; if(align==eHorizontalAlign.Center) this.Offset(cell,(width-cell.BoundsRelative.Width)/2,0); else // Right aligned cells this.Offset(cell,width-cell.BoundsRelative.Width,0); } } return new Size(width,height); }
protected virtual Size LayoutCellsHorizontal(NodeLayoutContextInfo layoutInfo, int x, int y) { Node node=layoutInfo.ContextNode; int height=0, width=0; bool adjustHeight = false; int cellCount = node.Cells.Count; bool firstVisible = true; for(int i=0;i<cellCount;i++) { Cell cell = null; if (layoutInfo.ChildColumns != null && layoutInfo.ChildColumns.ColumnInfo.Count == cellCount) cell = node.Cells[layoutInfo.ChildColumns.ColumnInfo[i].AbsoluteIndex]; else if (layoutInfo.DefaultColumns.ColumnInfo.Count == cellCount) cell = node.Cells[layoutInfo.DefaultColumns.ColumnInfo[i].AbsoluteIndex]; else cell = node.Cells[i]; bool bCellVisible=true; // Setup cell layout helper class LayoutCellInfo cellLayout=this.GetLayoutCellInfo(); cellLayout.View = layoutInfo.View; cellLayout.Top=y; cellLayout.Left=x; cellLayout.CellWidth=0; cellLayout.CellHeight = 0; cellLayout.ContextCell=cell; cellLayout.Graphics=layoutInfo.Graphics; cellLayout.LeftToRight=layoutInfo.LeftToRight; cellLayout.Font=layoutInfo.DefaultFont; if(cell.Layout!=eCellPartLayout.Default) cellLayout.VerticalPartAlignment=(cell.Layout==eCellPartLayout.Vertical); else if(layoutInfo.CellPartLayout!=eCellPartLayout.Default) cellLayout.VerticalPartAlignment=(layoutInfo.CellPartLayout==eCellPartLayout.Vertical); ColumnInfo ci = null; if ((layoutInfo.DefaultColumns.ColumnInfo.Count > 0 || layoutInfo.ChildColumns != null && layoutInfo.ChildColumns.ColumnInfo.Count > 0) && (node.Cells.Count > 1 || node.Cells.Count == layoutInfo.DefaultColumns.ColumnInfo.Count || layoutInfo.ChildColumns != null && layoutInfo.ChildColumns.ColumnInfo.Count == node.Cells.Count)) { bool usingTopLevelColumns = false; if (layoutInfo.ChildColumns != null && layoutInfo.ChildColumns.ColumnInfo.Count > 0 && i < layoutInfo.ChildColumns.ColumnInfo.Count) ci = layoutInfo.ChildColumns.ColumnInfo[i] as ColumnInfo; else if (i < layoutInfo.DefaultColumns.ColumnInfo.Count) { ci = layoutInfo.DefaultColumns.ColumnInfo[i] as ColumnInfo; usingTopLevelColumns = true; } if (ci != null) { bCellVisible = ci.Visible; if (ci.AutoSize && cell.HostedControl == null) cellLayout.CellWidth = 0; else { cellLayout.CellWidth = ci.Width; if (firstVisible && usingTopLevelColumns && cellLayout.CellWidth > 0) { cellLayout.CellWidth = Math.Max(-1, cellLayout.CellWidth - (layoutInfo.Left + x)); if (cellLayout.CellWidth == 0) cellLayout.CellWidth = -1; // this ensures that cell content is not visible since 0 indicates to take as much space as needed } } } } else if (layoutInfo.View == eView.Tile) { if (layoutInfo.IsViewGroupping && node.HasChildNodes) { cellLayout.CellWidth = layoutInfo.ClientRectangle.Width - layoutInfo.Left - layoutInfo.ExpandPartWidth - 1; } else { cellLayout.CellWidth = layoutInfo.TileSize.Width; cellLayout.CellHeight = layoutInfo.TileSize.Height; } } // Prepare union style if(cell.StyleNormal!=null) cellLayout.LayoutStyle=cell.StyleNormal; else { if(layoutInfo.ContextNode.Style!=null) { ElementStyle styleCopy = layoutInfo.DefaultCellStyle.Copy(); styleCopy.ApplyStyle(layoutInfo.ContextNode.Style); cellLayout.LayoutStyle = styleCopy; } else cellLayout.LayoutStyle=layoutInfo.DefaultCellStyle; } this.LayoutSingleCell(cellLayout); cell.SetVisible(bCellVisible); if(bCellVisible) { if (ci != null && ci.AutoSize && cell.HostedControl==null) { if (ci.ColumnHeader.Parent.ParentNode == null && firstVisible) ci.MaxWidth = Math.Max(ci.MaxWidth, cell.BoundsRelative.Width + (layoutInfo.Left + x) + this.LayoutSettings.CellHorizontalSpacing); else ci.MaxWidth = Math.Max(ci.MaxWidth, cell.BoundsRelative.Width + this.LayoutSettings.CellHorizontalSpacing); } x+=cell.BoundsRelative.Width; width+=cell.BoundsRelative.Width; if(cell.BoundsRelative.Width>0) { x += this.LayoutSettings.CellHorizontalSpacing; width += this.LayoutSettings.CellHorizontalSpacing; } if (cell.BoundsRelative.Height > height) { if (height != 0) adjustHeight = true; height = cell.BoundsRelative.Height; } else if (!firstVisible && cell.BoundsRelative.Height < height && !cell.TextContentBounds.IsEmpty) adjustHeight = true; firstVisible = false; } } // Apply the uniform cell text height to all cells if (adjustHeight) { for (int i = 0; i < node.Cells.Count; i++) { Cell cell = node.Cells[i]; if (cell.BoundsRelative.Height != height && !cell.TextContentBounds.IsEmpty) { cell.TextContentBounds = new Rectangle(cell.TextContentBounds.X, cell.TextContentBounds.Y, cell.TextContentBounds.Width, cell.TextContentBounds.Height + (height - cell.BoundsRelative.Height)); int diff = height - cell.BoundsRelative.Height; if (!cell.CheckBoxBoundsRelative.IsEmpty) { eVerticalAlign va = GetCheckBoxVerticalAlign(cell.CheckBoxAlignment, layoutInfo.View); if (va == eVerticalAlign.Middle) cell.SetCheckBoxBounds(new Rectangle(cell.CheckBoxBoundsRelative.X, cell.CheckBoxBoundsRelative.Y + (int)Math.Ceiling((double)diff / 2), cell.CheckBoxBoundsRelative.Width, cell.CheckBoxBoundsRelative.Height)); if (va == eVerticalAlign.Bottom) cell.SetCheckBoxBounds(new Rectangle(cell.CheckBoxBoundsRelative.X, cell.CheckBoxBoundsRelative.Y + diff, cell.CheckBoxBoundsRelative.Width, cell.CheckBoxBoundsRelative.Height)); } if (!cell.ImageBoundsRelative.IsEmpty) { eVerticalAlign va = GetVerticalAlign(cell.ImageAlignment, layoutInfo.View); if(va== eVerticalAlign.Middle) cell.SetImageBounds(new Rectangle(cell.ImageBoundsRelative.X, cell.ImageBoundsRelative.Y + (int)Math.Ceiling((double)diff / 2), cell.ImageBoundsRelative.Width, cell.ImageBoundsRelative.Height)); else if (va == eVerticalAlign.Bottom) cell.SetImageBounds(new Rectangle(cell.ImageBoundsRelative.X, cell.ImageBoundsRelative.Y + diff, cell.ImageBoundsRelative.Width, cell.ImageBoundsRelative.Height)); } cell.SetBounds(new Rectangle(cell.BoundsRelative.X, cell.BoundsRelative.Y, cell.BoundsRelative.Width, height)); } } } // Take last added spacing off x -= this.LayoutSettings.CellHorizontalSpacing; width -= this.LayoutSettings.CellHorizontalSpacing; return new Size(width,height); }
/// <summary> /// Determines the rectangle of the +/- part of the tree node that is used to expand node. /// </summary> /// <param name="layoutInfo">Node layout context information</param> protected virtual void LayoutExpandPart(NodeLayoutContextInfo layoutInfo, bool bLeftNode, int x) { Node node=layoutInfo.ContextNode; Size partSize=GetExpandPartSize(); Rectangle bounds=new Rectangle(x,0,partSize.Width,partSize.Height); bounds.Y=(node.BoundsRelative.Height-bounds.Height)/2; if (bLeftNode || layoutInfo.ExpandPartAlignedLeft && layoutInfo.LeftToRight) bounds.X += (this.LayoutSettings.ExpandAreaWidth - bounds.Width) / 2; else bounds.X = node.BoundsRelative.Right - this.LayoutSettings.ExpandAreaWidth + (this.LayoutSettings.ExpandAreaWidth - partSize.Width) / 2; node.SetExpandPartRectangle(bounds); }
private void LayoutTopLevelColumns(NodeLayoutContextInfo layoutInfo) { // Layout tree columns if (this.Tree.Columns.Count > 0) { Rectangle columnsBounds = DevComponents.DotNetBar.ElementStyleLayout.GetInnerRect(this.Tree.BackgroundStyle, this.Tree.ClientRectangle); if (this.Tree.VScrollBar != null) columnsBounds.Width -= this.Tree.VScrollBar.Width; layoutInfo.TreeColumns = this.Tree.Columns; int columnHeight = Layout.ColumnHeaderLayout.LayoutColumnHeader(layoutInfo, 0, 0, columnsBounds.Width, this.GetCellLayout().LayoutSettings.CellHorizontalSpacing); columnHeight += this.LayoutSettings.NodeVerticalSpacing; if (this.Tree.ColumnsVisible) { Rectangle headerBounds = layoutInfo.TreeColumns.Bounds; if (headerBounds.Width > 0 && headerBounds.Width < columnsBounds.Width) { headerBounds.Width = columnsBounds.Width; layoutInfo.TreeColumns.SetBounds(headerBounds); } layoutInfo.Top += columnHeight; this.Tree.SetColumnHeaderControlVisibility(true); } else this.Tree.SetColumnHeaderControlVisibility(false); layoutInfo.TreeColumns = null; } else this.Tree.SetColumnHeaderControlVisibility(false); }
///// <summary> ///// Gets or sets the size of the expand part that is expanding/collapsing the node. Default value is 8,8. ///// </summary> //public System.Drawing.Size ExpandPartSize //{ // get {return m_ExpandPartSize;} // set {m_ExpandPartSize=value;} //} /// <summary> /// Provides the layout for single node. /// </summary> /// <param name="layoutInfo">Layout information.</param> protected virtual void LayoutNode(NodeLayoutContextInfo layoutInfo) { bool bHasExpandPart=this.HasExpandPart(layoutInfo); bool bHasCommandPart=this.HasCommandPart(layoutInfo); Node node=layoutInfo.ContextNode; Rectangle nodeRect = new Rectangle(layoutInfo.Left, layoutInfo.Top, 0, 0); Rectangle nodeContentRect=Rectangle.Empty; // Node content rect excludes expand rect int height=0, width=0; // Left node relative to the main root node... bool bLeftNode = layoutInfo.LeftToRight; // (layoutInfo.MapPositionNear && layoutInfo.LeftToRight); layoutInfo.LayoutNodeExpandPartWidth = 0; if(bLeftNode && bHasExpandPart || this.ReserveExpandPartSpace) { layoutInfo.LayoutNodeExpandPartWidth = (this.LayoutSettings.ExpandAreaWidth + this.GetCellLayout().CellPartSpacing); width += (this.LayoutSettings.ExpandAreaWidth + this.GetCellLayout().CellPartSpacing); } int x=width; // relative to 0,0 of the node int y=0; // Relative to 0,0 of the node // Apply node style ElementStyle nodeStyle=null; if(node.Expanded && node.StyleExpanded!=null) nodeStyle=node.StyleExpanded; else if(node.Style!=null) nodeStyle=node.Style; else nodeStyle=layoutInfo.DefaultNodeStyle; nodeContentRect.X=x; if(nodeStyle!=null) { x+=ElementStyleLayout.LeftWhiteSpace(nodeStyle); y+=ElementStyleLayout.TopWhiteSpace(nodeStyle); nodeContentRect.X+=nodeStyle.MarginLeft; nodeContentRect.Y+=nodeStyle.MarginTop; } Size size = this.GetCellLayout().LayoutCells(layoutInfo, x, y); node.SetCellsBounds(new Rectangle(x, y, size.Width, size.Height)); height=size.Height; width+=size.Width; nodeContentRect.Width=size.Width; nodeContentRect.Height=size.Height; if(nodeStyle!=null) { nodeContentRect.Width+=(ElementStyleLayout.StyleSpacing(nodeStyle,eSpacePart.Padding | eSpacePart.Border,eStyleSide.Left)+ ElementStyleLayout.StyleSpacing(nodeStyle,eSpacePart.Padding | eSpacePart.Border,eStyleSide.Right)); nodeContentRect.Height+=(ElementStyleLayout.StyleSpacing(nodeStyle,eSpacePart.Padding | eSpacePart.Border,eStyleSide.Top)+ ElementStyleLayout.StyleSpacing(nodeStyle,eSpacePart.Padding | eSpacePart.Border,eStyleSide.Bottom)); width+=(ElementStyleLayout.HorizontalStyleWhiteSpace(nodeStyle)); height+=(ElementStyleLayout.VerticalStyleWhiteSpace(nodeStyle)); } if (!bLeftNode && bHasExpandPart && !this.ReserveExpandPartSpace) width += this.LayoutSettings.ExpandAreaWidth; if(bHasCommandPart) { width += this.LayoutSettings.CommandAreaWidth; nodeContentRect.Width += this.LayoutSettings.CommandAreaWidth; } nodeRect.Height=height; nodeRect.Width=width; node.SetBounds(nodeRect); node.SetContentBounds(nodeContentRect); if(bHasCommandPart) LayoutCommandPart(layoutInfo, nodeStyle); else node.CommandBoundsRelative=Rectangle.Empty; if (bHasExpandPart || this.ReserveExpandPartSpace) LayoutExpandPart(layoutInfo,bLeftNode, 0); else node.SetExpandPartRectangle(Rectangle.Empty); node.SizeChanged=false; // Calculate size and location of node column header if any //if(node.NodesColumnHeaderVisible) { //layoutInfo.Left+=this.NodeLevelOffset; LayoutColumnHeader(layoutInfo); //layoutInfo.Left-=this.NodeLevelOffset; } }
private Rectangle ProcessTopLevelNodes(Rectangle area, NodeLayoutContextInfo layoutInfo, Node[] topLevelNodes) { foreach (Node childNode in topLevelNodes) { layoutInfo.ContextNode = childNode; ProcessNode(layoutInfo); if (childNode.Visible) { area = Rectangle.Union(area, childNode.BoundsRelative); if (childNode.Expanded) area = Rectangle.Union(area, childNode.ChildNodesBounds); } } return area; }
/// <summary> /// Returns whether given node has command part. /// </summary> /// <param name="layoutInfo">Layout context information.</param> /// <returns>True if command part should be drawn otherwise false.</returns> protected virtual bool HasCommandPart(NodeLayoutContextInfo layoutInfo) { return layoutInfo.ContextNode.CommandButton; }
private void ProcessNode(NodeLayoutContextInfo layoutInfo) { Node node=layoutInfo.ContextNode; if (!node.Visible) return; int originalTop = layoutInfo.Top; if (node.SizeChanged || node.HasColumns || layoutInfo.DefaultColumns!=null && layoutInfo.DefaultColumns.HasAutoSizeColumn || layoutInfo.ChildColumns!=null && layoutInfo.ChildColumns.HasAutoSizeColumn) { // Calculate size of the node itself... LayoutNode(layoutInfo); } if (node.FullRowBackground) layoutInfo.FullRowBackgroundNodes.Add(node); if (node.BoundsRelative.X != layoutInfo.Left || node.BoundsRelative.Y != layoutInfo.Top) { // Adjust top position node.SetBounds(new Rectangle(layoutInfo.Left,layoutInfo.Top,node.BoundsRelative.Width,node.BoundsRelative.Height)); //foreach(Cell c in node.Cells) // c.SetBounds(new Rectangle(c.BoundsRelative.X + layoutInfo.Left, c.BoundsRelative.Y+layoutInfo.Top, c.BoundsRelative.Width, c.BoundsRelative.Height)); } int nodeVerticalSpacing = this.LayoutSettings.NodeVerticalSpacing; // Need to set the Top position properly layoutInfo.Top += (node.BoundsRelative.Height + nodeVerticalSpacing); if (DevComponents.AdvTree.Display.NodeDisplay.HasColumnsVisible(node)) layoutInfo.Top += node.ColumnHeaderHeight; if(node.Expanded) { int originalLevelOffset=layoutInfo.Left; int childNodesTop = layoutInfo.Top; layoutInfo.Left += this.NodeLevelOffset + node.NodesIndent; NodeColumnInfo parentColumns = layoutInfo.ChildColumns; NodeColumnInfo childColumns = GetNodeColumnInfo(node); Rectangle childNodesBounds = ProcessChildNodes(layoutInfo, node, nodeVerticalSpacing, childColumns); if (childColumns != null && childColumns.HasAutoSizeColumn) { bool hasMinColumnAutoSizeWidth = false; foreach (ColumnInfo columnInfo in childColumns.ColumnInfo) { if (columnInfo.AutoSize) { columnInfo.Width = columnInfo.MaxWidth; columnInfo.ColumnHeader.Width.SetAutoSizeWidth(columnInfo.MaxWidth); columnInfo.AutoSize = false; columnInfo.MaxWidth = 0; if (columnInfo.ColumnHeader.Width.AutoSizeMinHeader) hasMinColumnAutoSizeWidth = true; } } layoutInfo.Top = originalTop; layoutInfo.Left = originalLevelOffset; layoutInfo.ContextNode = node; layoutInfo.ChildColumns = parentColumns; LayoutNode(layoutInfo); layoutInfo.Top = childNodesTop; layoutInfo.Left += this.NodeLevelOffset + node.NodesIndent; // Adjust the of auto sized columns in case minimum header width is used if (hasMinColumnAutoSizeWidth) { foreach (ColumnInfo columnInfo in childColumns.ColumnInfo) { if (columnInfo.ColumnHeader.Width.AutoSize && columnInfo.ColumnHeader.Width.AutoSizeMinHeader) { columnInfo.Width = columnInfo.ColumnHeader.Bounds.Width; } } } childNodesBounds = ProcessChildNodes(layoutInfo, node, nodeVerticalSpacing, childColumns); } node.ChildNodesBounds = childNodesBounds; layoutInfo.ChildColumns=parentColumns; layoutInfo.ContextNode=node; layoutInfo.Left=originalLevelOffset; } }
// Assumes that layoutInfo is up-to-date and that Node that is connected with // columns is already processed and it's size and location calculated. // layoutInfo.Top member reflects the next position below the node // layoutInfo.LevelOffset should reflect the X offset for the child nodes. public void LayoutColumnHeader(NodeLayoutContextInfo layoutInfo) { Node node=layoutInfo.ContextNode; if (!node.HasColumns || !node.Expanded) { node.ColumnHeaderHeight = 0; return; } int spacing = 2; int x = layoutInfo.Left + this.NodeLevelOffset + node.NodesIndent; int y=layoutInfo.ContextNode.BoundsRelative.Bottom + spacing; bool bLeftNode=(layoutInfo.MapPositionNear && layoutInfo.LeftToRight); int expandPartWidth = this.LayoutSettings.ExpandAreaWidth; int cellPartSpacing=GetCellLayout().CellPartSpacing; if (!bLeftNode) x += (expandPartWidth + cellPartSpacing); int clientWidth = layoutInfo.ClientRectangle.Width - (layoutInfo.Left + expandPartWidth); if (clientWidth <= 0) clientWidth = layoutInfo.ClientRectangle.Width; node.ColumnHeaderHeight = Layout.ColumnHeaderLayout.LayoutColumnHeader(layoutInfo, x, y, clientWidth, this.GetCellLayout().LayoutSettings.CellHorizontalSpacing) + spacing; if (!node.NodesColumnsHeaderVisible) node.ColumnHeaderHeight = 0; }
// Assumes that layoutInfo is up-to-date and that Node that is connected with // columns is already processed and it's size and location calculated. // layoutInfo.Top member reflects the next position below the node // layoutInfo.LevelOffset should reflect the X offset for the child nodes. public static int LayoutColumnHeader(NodeLayoutContextInfo layoutInfo,int x, int y, int clientWidth, int cellHorizontalSpacing) { ColumnHeaderCollection columns = null; Node node=layoutInfo.ContextNode; if (node == null) columns = layoutInfo.TreeColumns; else columns = node.NodesColumns; columns.UsesRelativeSize = false; int height=0; bool adjustHeight = false; Rectangle totalBounds = Rectangle.Empty; ColumnHeader lastVisibleColumn = null; ColumnHeader stretchToFillColumn = null; bool allRelative = true; bool firstVisible = true; for (int i = 0; i < columns.Count; i++) { ColumnHeader col = columns.ColumnAtDisplayIndex(i); col.IsLastVisible = false; if(!col.Visible) continue; col.IsFirstVisible = firstVisible; firstVisible = false; //if(col.SizeChanged) { // Column for child nodes is always placed below the current node and // is not included in the node's rectangle Rectangle bounds=Rectangle.Empty; bounds.X=x; bounds.Y=y; if (col.Width.AutoSize) { int autoWidth = col.Width.AutoSizeWidth; if (col.Width.AutoSizeMinHeader) { Font headerFont = layoutInfo.DefaultFont; if (!string.IsNullOrEmpty(col.StyleNormal)) { ElementStyle style = layoutInfo.Styles[col.StyleNormal]; if (style != null && style.Font != null) headerFont = style.Font; } else if (layoutInfo.ColumnStyle != null && layoutInfo.ColumnStyle.Font != null) headerFont = layoutInfo.ColumnStyle.Font; if (headerFont != null) { int columnHeaderTextWidth = (int)Math.Ceiling(layoutInfo.Graphics.MeasureString(col.Text, headerFont).Width) + 2; autoWidth = Math.Max(autoWidth, columnHeaderTextWidth); } } bounds.Width = autoWidth; allRelative = false; } else if (col.Width.Absolute > 0) { bounds.Width = col.Width.Absolute; allRelative = false; } else if (col.Width.Absolute == -1) { bounds.Width = 0; allRelative = false; } else if (col.Width.Relative > 0) { if (col.IsFirstVisible) { clientWidth -= layoutInfo.ExpandPartWidth; bounds.Width = (clientWidth * col.Width.Relative) / 100 - cellHorizontalSpacing; bounds.Width += layoutInfo.ExpandPartWidth; } else bounds.Width = (clientWidth * col.Width.Relative) / 100 - cellHorizontalSpacing; columns.UsesRelativeSize = true; } lastVisibleColumn = col; if (col.StretchToFill) { stretchToFillColumn = col; columns.UsesRelativeSize = true; } if(col.StyleNormal=="" && col.StyleMouseDown=="" && col.StyleMouseOver=="") { bounds.Height=layoutInfo.DefaultHeaderSize.Height; } else { Size sz=Size.Empty; if(col.StyleNormal!="") { ElementStyleLayout.CalculateStyleSize(layoutInfo.Styles[col.StyleNormal],layoutInfo.DefaultFont); sz=layoutInfo.Styles[col.StyleNormal].Size; } if(sz.Height==0) bounds.Height=layoutInfo.DefaultHeaderSize.Height; else bounds.Height=sz.Height; } if (col.Image != null && col.Image.Height+4>bounds.Height) { bounds.Height = col.Image.Height + 4; } col.SetBounds(bounds); col.SizeChanged=false; x += (bounds.Width + cellHorizontalSpacing); if (bounds.Height > height) { if (height > 0) adjustHeight = true; height = bounds.Height; } else if (bounds.Height < height) adjustHeight = true; } if (totalBounds.IsEmpty) totalBounds = col.Bounds; else totalBounds = Rectangle.Union(totalBounds, col.Bounds); } if (adjustHeight) { foreach (ColumnHeader col in columns) { col.SetBounds(new Rectangle(col.Bounds.X, col.Bounds.Y, col.Bounds.Width, height)); } } if (lastVisibleColumn != null && allRelative) { lastVisibleColumn.SetBounds(new Rectangle(lastVisibleColumn.Bounds.X, lastVisibleColumn.Bounds.Y, lastVisibleColumn.Bounds.Width + cellHorizontalSpacing, lastVisibleColumn.Bounds.Height)); totalBounds = Rectangle.Union(totalBounds, lastVisibleColumn.Bounds); } if (lastVisibleColumn != null) lastVisibleColumn.IsLastVisible = true; if (stretchToFillColumn != null && totalBounds.Width < clientWidth) { int stretch = clientWidth - totalBounds.Width; if (stretchToFillColumn.IsFirstVisible && stretchToFillColumn.IsLastVisible) // Single column visible only case stretch -= layoutInfo.Indent; else if (stretchToFillColumn.Parent != null && stretchToFillColumn.Parent.ParentNode != null) stretch -= layoutInfo.Indent; stretchToFillColumn.SetBounds(new Rectangle(stretchToFillColumn.Bounds.X, stretchToFillColumn.Bounds.Y, stretchToFillColumn.Bounds.Width + stretch, stretchToFillColumn.Bounds.Height)); totalBounds = Rectangle.Union(totalBounds, stretchToFillColumn.Bounds); if (!stretchToFillColumn.IsLastVisible) // Offset columns to the right if this was not last visible column { int startIndex = columns.GetDisplayIndex(stretchToFillColumn) + 1; for (int i = startIndex; i < columns.Count; i++) { ColumnHeader col = columns.ColumnAtDisplayIndex(i); if (!col.Visible) continue; col.SetBounds(new Rectangle(col.Bounds.X + stretch, col.Bounds.Y, col.Bounds.Width, col.Bounds.Height)); totalBounds = Rectangle.Union(totalBounds, col.Bounds); } } } columns.SetBounds(totalBounds); return height; }