using System.Drawing;
using System.Windows.Forms;
using Microsoft.Drawing;
namespace Microsoft.Windows.Forms.Layout
{
///
/// 布局数据
///
public sealed class LayoutData : DisposableMini
{
///
/// 测试用绘图对象
///
public Graphics Graphics;
///
/// 区域
///
public Rectangle ClientRectangle;
///
/// 边距
///
public Padding Padding;
///
/// 文本图片相对位置
///
public TextImageRelation TextImageRelation;
///
/// 左右反转样式
///
public RightToLeft RightToLeft;
///
/// 图片大小
///
public Size ImageSize;
///
/// 图片对齐方式
///
public ContentAlignment ImageAlign;
///
/// 图片偏移量
///
public Point ImageOffset;
///
/// 文本
///
public string Text;
///
/// 字体
///
public Font Font;
///
/// 文本对齐方式
///
public ContentAlignment TextAlign;
///
/// 文本偏移量
///
public Point TextOffset;
///
/// 输出-图片区域(必须先调用Layout()方法)
///
public Rectangle OutImageBounds;//[OUT]
///
/// 输出-文本区域(必须先调用Layout()方法)
///
public Rectangle OutTextBounds;//[OUT]
//==================
private bool m_IsLayouted;
///
/// 是否执行过布局操作
///
public bool IsLayouted
{
get
{
return this.m_IsLayouted;
}
}
private Rectangle? m_CurrentClientRectangle;
///
/// 当前区域,已减去边距
///
public Rectangle CurrentClientRectangle
{
get
{
if (this.m_CurrentClientRectangle == null)
this.m_CurrentClientRectangle = RectangleEx.Subtract(this.ClientRectangle, this.Padding);
return this.m_CurrentClientRectangle.Value;
}
}
private TextImageRelation? m_CurrentTextImageRelation;
///
/// 当前文本图片相对位置,已通过左右反转样式翻译
///
public TextImageRelation CurrentTextImageRelation
{
get
{
if (this.m_CurrentTextImageRelation == null)
this.m_CurrentTextImageRelation = LayoutOptions.RtlTranslateRelation(this.TextImageRelation, this.RightToLeft);
return this.m_CurrentTextImageRelation.Value;
}
}
private StringFormat m_CurrentStringFormat;
///
/// 当前文本格式,渲染文本时使用
///
public StringFormat CurrentStringFormat
{
get
{
if (this.m_CurrentStringFormat == null)
this.m_CurrentStringFormat = LayoutOptions.GetStringFormat(this.TextAlign, this.RightToLeft);
return this.m_CurrentStringFormat;
}
}
private ContentAlignment? m_CurrentImageAlign;
///
/// 当前图片对齐方式,已通过左右反转样式翻译
///
public ContentAlignment CurrentImageAlign
{
get
{
if (this.m_CurrentImageAlign == null)
this.m_CurrentImageAlign = LayoutOptions.RtlTranslateAlignment(this.ImageAlign, this.RightToLeft);
return this.m_CurrentImageAlign.Value;
}
}
private ContentAlignment? m_CurrentTextAlign;
///
/// 当前文本对齐方式,已通过左右反转样式翻译
///
public ContentAlignment CurrentTextAlign
{
get
{
if (this.m_CurrentTextAlign == null)
this.m_CurrentTextAlign = LayoutOptions.RtlTranslateAlignment(this.TextAlign, this.RightToLeft);
return this.m_CurrentTextAlign.Value;
}
}
///
/// 构造函数
///
public LayoutData()
{
}
///
/// 布局文本和图片.该方法可被调用多次,但再生命周期内布局操作只会被执行一次.
///
public void DoLayout()
{
if (this.m_IsLayouted)
return;
this.m_IsLayouted = true;
LayoutOptions.LayoutTextAndImage(this);
}
///
/// 释放资源
///
/// 释放托管资源为true,否则为false
protected override void Dispose(bool disposing)
{
if (this.m_CurrentStringFormat != null)
{
this.m_CurrentStringFormat.Dispose();
this.m_CurrentStringFormat = null;
}
}
}
}