DotNet 4.8.1 build of DotNetBar
This commit is contained in:
226
PROMS/DotNetBar Source Code/TextMarkup/Div.cs
Normal file
226
PROMS/DotNetBar Source Code/TextMarkup/Div.cs
Normal file
@@ -0,0 +1,226 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
using System.Drawing;
|
||||
using System.Xml;
|
||||
|
||||
#if AdvTree
|
||||
namespace DevComponents.Tree.TextMarkup
|
||||
#elif DOTNETBAR
|
||||
using DevComponents.UI.ContentManager;
|
||||
namespace DevComponents.DotNetBar.TextMarkup
|
||||
#elif SUPERGRID
|
||||
namespace DevComponents.SuperGrid.TextMarkup
|
||||
#elif LAYOUT
|
||||
namespace DevComponents.DotNetBar.Layout.TextMarkup
|
||||
#endif
|
||||
{
|
||||
internal class Div : ContainerElement
|
||||
{
|
||||
#region Private Variables
|
||||
private eParagraphAlignment m_Align = eParagraphAlignment.Left;
|
||||
private eParagraphVerticalAlignment m_VAlign = eParagraphVerticalAlignment.Top;
|
||||
private int m_Width = 0;
|
||||
private int m_Height = 0;
|
||||
private Padding m_Padding = new Padding(0, 0, 0, 0);
|
||||
private Color m_BackColor = Color.Empty;
|
||||
#endregion
|
||||
|
||||
#region Internal Implementation
|
||||
public override void Render(MarkupDrawContext d)
|
||||
{
|
||||
Rectangle r = this.Bounds;
|
||||
r.Offset(d.Offset);
|
||||
if (!m_BackColor.IsEmpty)
|
||||
{
|
||||
DisplayHelp.FillRectangle(d.Graphics, r, m_BackColor);
|
||||
}
|
||||
|
||||
base.Render(d);
|
||||
}
|
||||
|
||||
public eParagraphAlignment Align
|
||||
{
|
||||
get { return m_Align; }
|
||||
set { m_Align = value; }
|
||||
}
|
||||
|
||||
protected override SerialContentLayoutManager GetLayoutManager(bool multiLine)
|
||||
{
|
||||
SerialContentLayoutManager sm = base.GetLayoutManager(multiLine);
|
||||
if (m_Align == eParagraphAlignment.Left)
|
||||
sm.ContentAlignment = eContentAlignment.Left;
|
||||
else if (m_Align == eParagraphAlignment.Right)
|
||||
sm.ContentAlignment = eContentAlignment.Right;
|
||||
else if (m_Align == eParagraphAlignment.Center)
|
||||
sm.ContentAlignment = eContentAlignment.Center;
|
||||
|
||||
if (m_VAlign != eParagraphVerticalAlignment.Top)
|
||||
{
|
||||
sm.EvenHeight = false;
|
||||
sm.ContentVerticalAlignment = (m_VAlign == eParagraphVerticalAlignment.Bottom ? eContentVerticalAlignment.Bottom : eContentVerticalAlignment.Middle);
|
||||
//sm.BlockLineAlignment = (m_VAlign == eParagraphVerticalAlignment.Bottom ? eContentVerticalAlignment.Bottom : eContentVerticalAlignment.Middle);
|
||||
}
|
||||
|
||||
return sm;
|
||||
}
|
||||
|
||||
protected override Point GetContainerOffset()
|
||||
{
|
||||
if (m_Padding.Left == 0 && m_Padding.Top == 0)
|
||||
return base.GetContainerOffset();
|
||||
|
||||
Point p = base.GetContainerOffset();
|
||||
p.X += m_Padding.Left;
|
||||
p.Y += m_Padding.Top;
|
||||
return p;
|
||||
}
|
||||
|
||||
protected override void ArrangeInternal(Rectangle bounds, MarkupDrawContext d)
|
||||
{
|
||||
Rectangle r = bounds;
|
||||
int width = Dpi.Width(m_Width);
|
||||
if (width > 0)
|
||||
r.Width = width;
|
||||
int height = Dpi.Height(m_Height);
|
||||
if (height > 0)
|
||||
r.Height = height;
|
||||
Padding padding = Dpi.Size(m_Padding);
|
||||
if (padding.IsEmpty)
|
||||
{
|
||||
base.ArrangeInternal(r, d);
|
||||
if (width > 0)
|
||||
this.Bounds = new Rectangle(this.Bounds.X, this.Bounds.Y, width, height > 0 ? height : this.Bounds.Height + padding.Bottom);
|
||||
else if(height>0)
|
||||
this.Bounds = new Rectangle(this.Bounds.X, this.Bounds.Y, this.Bounds.Width, height);
|
||||
}
|
||||
else
|
||||
{
|
||||
r.X += padding.Left;
|
||||
r.Y += padding.Top;
|
||||
r.Width -= padding.Horizontal;
|
||||
r.Height -= padding.Vertical;
|
||||
base.ArrangeInternal(r, d);
|
||||
|
||||
r = new Rectangle(bounds.X, bounds.Y, this.Bounds.Width + padding.Horizontal, this.Bounds.Height + padding.Vertical);
|
||||
if (width > 0)
|
||||
r.Width = width;
|
||||
if (height > 0)
|
||||
r.Height = height;
|
||||
|
||||
this.Bounds = r;
|
||||
}
|
||||
}
|
||||
|
||||
public override void ReadAttributes(XmlTextReader reader)
|
||||
{
|
||||
for (int i = 0; i < reader.AttributeCount; i++)
|
||||
{
|
||||
reader.MoveToAttribute(i);
|
||||
if (reader.Name.ToLower() == "align")
|
||||
{
|
||||
string s = reader.Value.ToLower();
|
||||
if (s == "left")
|
||||
m_Align = eParagraphAlignment.Left;
|
||||
else if (s == "right")
|
||||
m_Align = eParagraphAlignment.Right;
|
||||
else if (s == "center")
|
||||
m_Align = eParagraphAlignment.Center;
|
||||
}
|
||||
else if (reader.Name.ToLower() == "valign")
|
||||
{
|
||||
string s = reader.Value.ToLower();
|
||||
if (s == "top")
|
||||
m_VAlign = eParagraphVerticalAlignment.Top;
|
||||
else if (s == "middle")
|
||||
m_VAlign = eParagraphVerticalAlignment.Middle;
|
||||
else if (s == "bottom")
|
||||
m_VAlign = eParagraphVerticalAlignment.Bottom;
|
||||
}
|
||||
else if (reader.Name.ToLower() == "width")
|
||||
{
|
||||
try
|
||||
{
|
||||
m_Width = Int32.Parse(reader.Value);
|
||||
}
|
||||
catch
|
||||
{
|
||||
m_Width = 0;
|
||||
}
|
||||
}
|
||||
else if (reader.Name.ToLower() == "height")
|
||||
{
|
||||
try
|
||||
{
|
||||
m_Height = Int32.Parse(reader.Value);
|
||||
}
|
||||
catch
|
||||
{
|
||||
m_Height = 0;
|
||||
}
|
||||
}
|
||||
else if (reader.Name.ToLower() == "padding")
|
||||
{
|
||||
try
|
||||
{
|
||||
string[] values = reader.Value.Split(',');
|
||||
if (values.Length > 0)
|
||||
m_Padding.Left = Int32.Parse(values[0]);
|
||||
if (values.Length > 1)
|
||||
m_Padding.Right = Int32.Parse(values[1]);
|
||||
if (values.Length > 2)
|
||||
m_Padding.Top = Int32.Parse(values[2]);
|
||||
if (values.Length > 3)
|
||||
m_Padding.Bottom = Int32.Parse(values[3]);
|
||||
}
|
||||
catch
|
||||
{
|
||||
m_Padding = new Padding(0,0,0,0);
|
||||
}
|
||||
}
|
||||
else if (reader.Name.ToLower() == "bgcolor")
|
||||
{
|
||||
try
|
||||
{
|
||||
string s = reader.Value;
|
||||
if (s.StartsWith("#"))
|
||||
{
|
||||
if (s.Length == 7)
|
||||
m_BackColor = ColorScheme.GetColor(s.Substring(1));
|
||||
}
|
||||
else
|
||||
{
|
||||
m_BackColor = Color.FromName(s);
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
m_BackColor = Color.Empty;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
||||
#region eParagraphAlignment
|
||||
/// <summary>
|
||||
/// Indicates paragraph content alignment
|
||||
/// </summary>
|
||||
internal enum eParagraphAlignment
|
||||
{
|
||||
Left,
|
||||
Right,
|
||||
Center
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Indicates paragraph content alignment
|
||||
/// </summary>
|
||||
internal enum eParagraphVerticalAlignment
|
||||
{
|
||||
Top,
|
||||
Middle,
|
||||
Bottom
|
||||
}
|
||||
#endregion
|
||||
}
|
Reference in New Issue
Block a user