public static void PaintText(NodeCellRendererEventArgs ci) { Cell cell = ci.Cell; if (cell.HostedControl == null && cell.HostedItem == null && (cell.DisplayText == "" || ci.Style.TextColor.IsEmpty) || cell.TextContentBounds.IsEmpty) return; Rectangle bounds = ci.Cell.TextContentBounds; bounds.Offset(ci.CellOffset); Graphics g = ci.Graphics; if (cell.HostedControl != null) { if (!cell.HostedControl.Visible) cell.HostedControl.Visible = true; return; } else if (cell.HostedItem != null) { BaseItem item = cell.HostedItem; if (item.ItemAlignment == eItemAlignment.Near) item.LeftInternal = bounds.X; else if (item.ItemAlignment == eItemAlignment.Far) item.LeftInternal = bounds.X + (bounds.Width - item.WidthInternal); else if (item.ItemAlignment == eItemAlignment.Center) item.LeftInternal = bounds.X + (bounds.Width - item.WidthInternal) / 2; if (item.DisplayRectangle.Height < bounds.Height) item.TopInternal = bounds.Y + (bounds.Height - item.DisplayRectangle.Height) / 2; else item.TopInternal = bounds.Y; item.Displayed = true; Region oldClip = g.Clip; Rectangle cb = bounds; cb.Inflate(2, 1); g.SetClip(cb, CombineMode.Intersect); item.Paint(ci.ItemPaintArgs); if (oldClip != null) { g.Clip = oldClip; oldClip.Dispose(); } return; } Font font = ci.Style.Font; if (bounds.Width > 1 && bounds.Height > 1) { //eTextFormat textFormat = ci.Style.TextFormat; //textFormat = textFormat & ~(textFormat & eTextFormat.HidePrefix); //textFormat |= eTextFormat.NoPrefix; if (cell.TextMarkupBody == null) { TextDrawing.DrawString(g, cell.DisplayText, font, ci.Style.TextColor, bounds, ci.Style.TextFormat); } else { DevComponents.DotNetBar.TextMarkup.MarkupDrawContext d = new DevComponents.DotNetBar.TextMarkup.MarkupDrawContext(g, font, ci.Style.TextColor, false); d.HotKeyPrefixVisible = !((ci.Style.TextFormat & eTextFormat.HidePrefix) == eTextFormat.HidePrefix); Rectangle mr = Rectangle.Empty; eStyleTextAlignment lineAlignment = ci.Style.TextLineAlignment; if (lineAlignment == eStyleTextAlignment.Center) { mr = new Rectangle(bounds.X, bounds.Y + (bounds.Height - cell.TextMarkupBody.Bounds.Height) / 2, cell.TextMarkupBody.Bounds.Width, cell.TextMarkupBody.Bounds.Height); } else if (lineAlignment == eStyleTextAlignment.Near) { mr = new Rectangle(bounds.X, bounds.Y, cell.TextMarkupBody.Bounds.Width, cell.TextMarkupBody.Bounds.Height); } else // Far { mr = new Rectangle(bounds.X, bounds.Y + (bounds.Height - cell.TextMarkupBody.Bounds.Height), cell.TextMarkupBody.Bounds.Width, cell.TextMarkupBody.Bounds.Height); } cell.TextMarkupBody.Bounds = mr; cell.TextMarkupBody.Render(d); } } }
protected virtual void LayoutSingleTileCell(LayoutCellInfo info) { Size textSize = Size.Empty; Font font = info.Font; int fontHeight = info.FontHeight; int height = 0; if (info.LayoutStyle.Font != null) { font = info.LayoutStyle.Font; fontHeight = font.Height; } info.ContextCell.OnLayoutCell(); if (info.ContextCell.Images.LargestImageSize.IsEmpty && HasImage(info.ContextCell)) info.ContextCell.Images.RefreshLargestImageSize(); if (info.ContextCell.HostedControl != null) { Size controlSize = info.ContextCell.HostedControl.Size; if (!info.ContextCell.HostedControlSize.IsEmpty) controlSize = info.ContextCell.HostedControlSize; if (info.CellWidth == 0) textSize = new Size(controlSize.Width, controlSize.Height); else { int availTextWidth = info.CellWidth - ElementStyleLayout.HorizontalStyleWhiteSpace(info.LayoutStyle); textSize = new Size(availTextWidth, controlSize.Height); } } else if (info.ContextCell.HostedItem != null) { if (info.CellWidth != 0) info.ContextCell.HostedItem.WidthInternal = info.CellWidth; info.ContextCell.HostedItem.RecalcSize(); Size controlSize = info.ContextCell.HostedItem.Size; if (info.CellWidth == 0) textSize = new Size(controlSize.Width, controlSize.Height); else { int availTextWidth = info.CellWidth - ElementStyleLayout.HorizontalStyleWhiteSpace(info.LayoutStyle); textSize = new Size(availTextWidth, controlSize.Height); info.ContextCell.HostedItem.WidthInternal = availTextWidth; } } else { // Calculate Text Width and Height if (info.CellWidth == 0) { if (info.ContextCell.TextMarkupBody == null) { string text = info.ContextCell.DisplayText; if (text != "") { if (info.LayoutStyle.WordWrap && info.LayoutStyle.MaximumWidth > 0) textSize = TextDrawing.MeasureString(info.Graphics, text, font, info.LayoutStyle.MaximumWidth); else if (info.ContextCell.Parent != null && info.ContextCell.Parent.Style != null && info.ContextCell.Parent.Style.WordWrap && info.ContextCell.Parent.Style.MaximumWidth > 0) textSize = TextDrawing.MeasureString(info.Graphics, text, font, info.ContextCell.Parent.Style.MaximumWidth); else textSize = TextDrawing.MeasureString(info.Graphics, text, font, 0, eTextFormat.Left | eTextFormat.LeftAndRightPadding | eTextFormat.GlyphOverhangPadding | eTextFormat.NoPrefix); #if (FRAMEWORK20) if (!BarFunctions.IsVista && BarUtilities.UseTextRenderer) textSize.Width += 4; #endif } else if (info.ContextCell.Images.LargestImageSize.IsEmpty && !info.ContextCell.CheckBoxVisible) { textSize = new Size(5, fontHeight); } } else { Size availSize = new Size(1600, 1); if (info.LayoutStyle.WordWrap && info.LayoutStyle.MaximumWidth > 0) availSize.Width = info.LayoutStyle.MaximumWidth; else if (info.ContextCell.Parent != null && info.ContextCell.Parent.Style != null && info.ContextCell.Parent.Style.WordWrap && info.ContextCell.Parent.Style.MaximumWidth > 0) availSize.Width = info.ContextCell.Parent.Style.MaximumWidth; DevComponents.DotNetBar.TextMarkup.MarkupDrawContext d = new DevComponents.DotNetBar.TextMarkup.MarkupDrawContext(info.Graphics, font, Color.Empty, false); info.ContextCell.TextMarkupBody.Measure(availSize, d); availSize = info.ContextCell.TextMarkupBody.Bounds.Size; d.RightToLeft = !info.LeftToRight; info.ContextCell.TextMarkupBody.Arrange(new Rectangle(0, 0, availSize.Width, availSize.Height), d); textSize = info.ContextCell.TextMarkupBody.Bounds.Size; } } else { int availTextWidth = info.CellWidth - ElementStyleLayout.HorizontalStyleWhiteSpace(info.LayoutStyle); availTextWidth -= info.ContextCell.Images.LargestImageSize.Width + (info.ContextCell.Images.LargestImageSize.Width > 0 ? ImageTextSpacing * 2 : 0); if (info.ContextCell.CheckBoxVisible) availTextWidth -= CheckBoxSize.Width + ImageTextSpacing * 2; int cellHeight = fontHeight; if (info.LayoutStyle.WordWrap || info.ContextCell.TextMarkupBody != null) { cellHeight = info.LayoutStyle.MaximumHeight - info.LayoutStyle.MarginTop - info.LayoutStyle.MarginBottom - info.LayoutStyle.PaddingTop - info.LayoutStyle.PaddingBottom; if (info.ContextCell.TextMarkupBody == null) { if (availTextWidth > 0) { if (cellHeight > 0) textSize = TextDrawing.MeasureString(info.Graphics, info.ContextCell.DisplayText, font, new Size(availTextWidth, cellHeight), info.LayoutStyle.TextFormat); else textSize = TextDrawing.MeasureString(info.Graphics, info.ContextCell.DisplayText, font, availTextWidth, info.LayoutStyle.TextFormat); } } else { Size availSize = new Size(availTextWidth, 1); DevComponents.DotNetBar.TextMarkup.MarkupDrawContext d = new DevComponents.DotNetBar.TextMarkup.MarkupDrawContext(info.Graphics, font, Color.Empty, false); info.ContextCell.TextMarkupBody.Measure(availSize, d); availSize = info.ContextCell.TextMarkupBody.Bounds.Size; availSize.Width = availTextWidth; d.RightToLeft = !info.LeftToRight; info.ContextCell.TextMarkupBody.Arrange(new Rectangle(0, 0, availSize.Width, availSize.Height), d); textSize = info.ContextCell.TextMarkupBody.Bounds.Size; } } else textSize = new Size(availTextWidth, cellHeight); } } if (info.LayoutStyle.WordWrap) info.ContextCell.WordWrap = true; else info.ContextCell.WordWrap = false; height = (int)Math.Max(height, Math.Ceiling((double)textSize.Height)); if (info.VerticalPartAlignment) { if (info.ContextCell.Images.LargestImageSize.Height > 0) height += info.ContextCell.Images.LargestImageSize.Height + this.ImageTextSpacing; if (info.ContextCell.CheckBoxVisible) height += CheckBoxSize.Height + this.ImageCheckBoxSpacing; } else { if (info.ContextCell.Images.LargestImageSize.Height > height) height = info.ContextCell.Images.LargestImageSize.Height; if (info.ContextCell.CheckBoxVisible && CheckBoxSize.Height > height) height = CheckBoxSize.Height; } Rectangle r = new Rectangle(info.Left + ElementStyleLayout.LeftWhiteSpace(info.LayoutStyle), info.Top + ElementStyleLayout.TopWhiteSpace(info.LayoutStyle) , info.CellWidth, height); if (r.Width == 0) { if (info.VerticalPartAlignment) { r.Width = (int)Math.Ceiling((double)textSize.Width); if (info.ContextCell.Images.LargestImageSize.Width > r.Width) r.Width = (info.ContextCell.Images.LargestImageSize.Width + this.ImageTextSpacing); if (info.ContextCell.CheckBoxVisible && CheckBoxSize.Width > r.Width) r.Width += (CheckBoxSize.Width + this.ImageTextSpacing); } else { r.Width = (int)Math.Ceiling((double)textSize.Width); if (info.ContextCell.Images.LargestImageSize.Width > 0) r.Width += (info.ContextCell.Images.LargestImageSize.Width + this.ImageTextSpacing); if (info.ContextCell.CheckBoxVisible) r.Width += (CheckBoxSize.Width + this.ImageTextSpacing); } } // Now that we have cell bounds store them Rectangle rCellBounds = new Rectangle(info.Left, info.Top, info.CellWidth, r.Height + info.LayoutStyle.MarginTop + info.LayoutStyle.MarginBottom + info.LayoutStyle.PaddingTop + info.LayoutStyle.PaddingBottom); if (rCellBounds.Width == 0) rCellBounds.Width = r.Width + ElementStyleLayout.HorizontalStyleWhiteSpace(info.LayoutStyle); info.ContextCell.SetBounds(rCellBounds); // Set position of the check box if (info.ContextCell.CheckBoxVisible && rCellBounds.Width >= this.CheckBoxSize.Width) { eVerticalAlign va = GetCheckBoxVerticalAlign(info.ContextCell.CheckBoxAlignment, info.View); eHorizontalAlign ha = GetCheckBoxHorizontalAlign(info.ContextCell.CheckBoxAlignment, info.LeftToRight, info.View); if (ha == eHorizontalAlign.Center && (!string.IsNullOrEmpty(info.ContextCell.Text) || !info.ContextCell.Images.LargestImageSize.IsEmpty)) ha = eHorizontalAlign.Left; if (info.VerticalPartAlignment) info.ContextCell.SetCheckBoxBounds(AlignContentVertical(this.CheckBoxSize, ref r, ha, va, this.ImageTextSpacing)); else info.ContextCell.SetCheckBoxBounds(AlignContent(this.CheckBoxSize, ref r, ha, va, this.ImageTextSpacing)); } else info.ContextCell.SetCheckBoxBounds(Rectangle.Empty); // Set Position of the image if (!info.ContextCell.Images.LargestImageSize.IsEmpty && rCellBounds.Width >= info.ContextCell.Images.LargestImageSize.Width) { eVerticalAlign va = GetVerticalAlign(info.ContextCell.ImageAlignment, info.View); eHorizontalAlign ha = GetHorizontalAlign(info.ContextCell.ImageAlignment, info.LeftToRight, info.View); if (ha == eHorizontalAlign.Center && (!string.IsNullOrEmpty(info.ContextCell.Text) || info.ContextCell.CheckBoxVisible)) ha = eHorizontalAlign.Left; if (info.VerticalPartAlignment) info.ContextCell.SetImageBounds(AlignContentVertical(info.ContextCell.Images.LargestImageSize, ref r, ha, va, this.ImageTextSpacing)); else info.ContextCell.SetImageBounds(AlignContent(info.ContextCell.Images.LargestImageSize, ref r, ha, va, this.ImageTextSpacing)); } else info.ContextCell.SetImageBounds(Rectangle.Empty); // Set position of the text //info.ContextCell.SetTextBounds(Rectangle.Empty); if (!textSize.IsEmpty) { if (info.CellWidth > 0) r.Width -= 2; if (info.View == eView.Tile && info.CellIndex == 0) info.ContextCell.TextContentBounds = new Rectangle(r.X, r.Y, textSize.Width, textSize.Height + 1); else info.ContextCell.TextContentBounds = r; } else info.ContextCell.TextContentBounds = Rectangle.Empty; }
private void ArrangeMarkup(int specifiedWidth) { System.Windows.Forms.Control objCtrl = this.ContainerControl as System.Windows.Forms.Control; if (!IsHandleValid(objCtrl)) return; using (Graphics g = BarFunctions.CreateGraphics(objCtrl)) { Font objCurrentFont = null; if (m_Font != null) objCurrentFont = m_Font; else objCurrentFont = GetFont(); CompositeImage image = this.GetImage(); Size availableSize = GetMarkupAvailableSize(g, specifiedWidth); TextMarkup.MarkupDrawContext d = new DevComponents.DotNetBar.TextMarkup.MarkupDrawContext(g, objCurrentFont, this.ForeColor, false); d.HotKeyPrefixVisible = !((GetStringFormat() & eTextFormat.HidePrefix) == eTextFormat.HidePrefix); TextMarkupBody.Measure(availableSize, d); d.RightToLeft = (objCtrl.RightToLeft == System.Windows.Forms.RightToLeft.Yes); if (specifiedWidth == 0 && m_Width == 0) availableSize = TextMarkupBody.Bounds.Size; TextMarkupBody.Arrange(new Rectangle(Point.Empty, availableSize), d); } }