using System;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Design;
using CustomControls.Pattern.DataModels;
using DevExpress.Utils.Serializing;
using DevExpress.XtraPrinting;
using DevExpress.XtraReports;
using DevExpress.XtraReports.Expressions;
using DevExpress.XtraReports.UI;
using DevExpress.XtraReports.UserDesigner;
namespace CustomControls.Pattern
{
///
/// 控件
///
[ToolboxItem(true)]
[XRDesigner("CustomControls.Design.XRPatternDesigner,CustomControls.Design")]
[Designer("CustomControls.Design._XRPatternDesigner,CustomControls.Design")]
[XRToolboxSubcategory(0, 7)]
[DefaultBindableProperty(nameof(StringData))]
public class XRPattern : XRControl
{
PatternDataItem patternDataItem = new PatternDataItem();
#region 隐藏属性
[Browsable(false)]
[EditorBrowsable(EditorBrowsableState.Never)]
[XtraSerializableProperty(XtraSerializationVisibility.Hidden)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public override string Text
{
get => base.Text;
set => base.Text = value;
}
[Browsable(false)]
[EditorBrowsable(EditorBrowsableState.Never)]
[XtraSerializableProperty(XtraSerializationVisibility.Hidden)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public override string TextFormatString
{
get => base.TextFormatString;
set => base.TextFormatString = value;
}
[Browsable(false)]
[EditorBrowsable(EditorBrowsableState.Never)]
[XtraSerializableProperty(XtraSerializationVisibility.Hidden)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public override string XlsxFormatString
{
get => base.XlsxFormatString;
set => base.XlsxFormatString = value;
}
[Browsable(false)]
[EditorBrowsable(EditorBrowsableState.Never)]
[XtraSerializableProperty(XtraSerializationVisibility.Hidden)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public override bool WordWrap
{
get => base.WordWrap;
set => base.WordWrap = value;
}
[Browsable(false)]
[EditorBrowsable(EditorBrowsableState.Never)]
[XtraSerializableProperty(XtraSerializationVisibility.Hidden)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public override bool KeepTogether
{
get => base.KeepTogether;
set => base.KeepTogether = value;
}
[Browsable(false)]
[EditorBrowsable(EditorBrowsableState.Never)]
[XtraSerializableProperty(XtraSerializationVisibility.Hidden)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public override HorizontalAnchorStyles AnchorHorizontal
{
get => base.AnchorHorizontal;
set => base.AnchorHorizontal = value;
}
[Browsable(false)]
[EditorBrowsable(EditorBrowsableState.Never)]
[XtraSerializableProperty(XtraSerializationVisibility.Hidden)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public override VerticalAnchorStyles AnchorVertical
{
get => base.AnchorVertical;
set => base.AnchorVertical = value;
}
[Browsable(false)]
[EditorBrowsable(EditorBrowsableState.Never)]
[XtraSerializableProperty(XtraSerializationVisibility.Hidden)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public override bool CanPublish
{
get => base.CanPublish;
set => base.CanPublish = value;
}
[Browsable(false)]
[EditorBrowsable(EditorBrowsableState.Never)]
[XtraSerializableProperty(XtraSerializationVisibility.Hidden)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public override Color BackColor
{
get => base.BackColor;
set => base.BackColor = value;
}
[Browsable(false)]
[EditorBrowsable(EditorBrowsableState.Never)]
[XtraSerializableProperty(XtraSerializationVisibility.Hidden)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public override Color BorderColor
{
get => base.BorderColor;
set => base.BorderColor = value;
}
[Browsable(false)]
[EditorBrowsable(EditorBrowsableState.Never)]
[XtraSerializableProperty(XtraSerializationVisibility.Hidden)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public override BorderDashStyle BorderDashStyle
{
get => base.BorderDashStyle;
set => base.BorderDashStyle = value;
}
[Browsable(false)]
[EditorBrowsable(EditorBrowsableState.Never)]
[XtraSerializableProperty(XtraSerializationVisibility.Hidden)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public override float BorderWidth
{
get => base.BorderWidth;
set => base.BorderWidth = value;
}
[Browsable(false)]
[EditorBrowsable(EditorBrowsableState.Never)]
[XtraSerializableProperty(XtraSerializationVisibility.Hidden)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public override BorderSide Borders
{
get => base.Borders;
set => base.Borders = value;
}
[Browsable(false)]
[EditorBrowsable(EditorBrowsableState.Never)]
[XtraSerializableProperty(XtraSerializationVisibility.Hidden)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public override Font Font
{
get => base.Font;
set => base.Font = value;
}
[Browsable(false)]
[EditorBrowsable(EditorBrowsableState.Never)]
[XtraSerializableProperty(XtraSerializationVisibility.Hidden)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public override Color ForeColor
{
get => base.ForeColor;
set => base.ForeColor = value;
}
[Browsable(false)]
[EditorBrowsable(EditorBrowsableState.Never)]
[XtraSerializableProperty(XtraSerializationVisibility.Hidden)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public override PaddingInfo Padding
{
get => base.Padding;
set => base.Padding = value;
}
[Browsable(false)]
[EditorBrowsable(EditorBrowsableState.Never)]
[XtraSerializableProperty(XtraSerializationVisibility.Hidden)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public override StylePriority StylePriority => base.StylePriority;
[Browsable(false)]
[EditorBrowsable(EditorBrowsableState.Never)]
[XtraSerializableProperty(XtraSerializationVisibility.Hidden)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public override XRControlStyles Styles => base.Styles;
[Browsable(false)]
[EditorBrowsable(EditorBrowsableState.Never)]
[XtraSerializableProperty(XtraSerializationVisibility.Hidden)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public override TextAlignment TextAlignment
{
get => base.TextAlignment;
set => base.TextAlignment = value;
}
[Bindable(false), EditorBrowsable(EditorBrowsableState.Never)]
public override event BindingEventHandler EvaluateBinding
{
add { }
remove { }
}
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
public override event PrintOnPageEventHandler PrintOnPage
{
add { }
remove { }
}
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
public override event PreviewMouseEventHandler PreviewMouseMove
{
add { }
remove { }
}
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
public override event PreviewMouseEventHandler PreviewMouseDown
{
add { }
remove { }
}
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
public override event PreviewMouseEventHandler PreviewMouseUp
{
add { }
remove { }
}
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
public override event PreviewMouseEventHandler PreviewClick
{
add { }
remove { }
}
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
public override event PreviewMouseEventHandler PreviewDoubleClick
{
add { }
remove { }
}
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
public override event DrawEventHandler Draw
{
add { }
remove { }
}
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
public override event HtmlEventHandler HtmlItemCreated
{
add { }
remove { }
}
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
public override event EventHandler TextChanged
{
add { }
remove { }
}
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
public override event DevExpress.XtraReports.UI.ChangeEventHandler SizeChanged
{
add { }
remove { }
}
#endregion
#region 属性和方法
public new XRPatternScripts Scripts => (XRPatternScripts)fEventScripts;
[DisplayName("String Data")]
[Description("String Data description")]
[Category("Data")]
[XtraSerializableProperty(XtraSerializationVisibility.Hidden)]
[RefreshProperties(RefreshProperties.All)]
public string StringData
{
get => patternDataItem.PatternData;
set => patternDataItem.PatternData = value;
}
bool ShouldSerializeStringData() => false;
[DisplayName("Row Space")]
[Description("Row Space description")]
[Category("Data")]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
[XtraSerializableProperty(XtraSerializationVisibility.Content)]
public int RowSpace
{
get => patternDataItem.RowSpace;
set => patternDataItem.RowSpace = value;
}
[DisplayName("Column Space")]
[Description("Column Space description")]
[Category("Data")]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
[XtraSerializableProperty(XtraSerializationVisibility.Content)]
public int ColumnSpace
{
get => patternDataItem.ColumnSpace;
set => patternDataItem.ColumnSpace = value;
}
[DisplayName("Is Draw Horizontal Line")]
[Description("Is Draw Horizontal Line description")]
[Category("Data")]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
[XtraSerializableProperty(XtraSerializationVisibility.Content)]
public bool IsDrawHorizontalLine
{
get => patternDataItem.IsDrawHorizontalLine;
set => patternDataItem.IsDrawHorizontalLine = value;
}
[DisplayName("Code Options")]
[Description("Code Options description")]
[Category("Data")]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
[XtraSerializableProperty(XtraSerializationVisibility.Content)]
public CodeOptions CodeOptions { get; } = new CodeOptions();
#endregion
#region 构造函数
static XRPattern()
{
ExpressionBindingDescriptor.SetPropertyDescription(typeof(XRPattern), nameof(StringData), new ExpressionBindingDescription(new string[] { "BeforePrint" }, 1000, new string[0]));
}
public XRPattern()
{
}
#endregion
#region 重写属性和方法
///
/// 固定模块大小
///
//public override RectangleF BoundsF
//{
// get => AdaptBounds(base.BoundsF);
// set => base.BoundsF = value;
//}
RectangleF AdaptBounds(RectangleF rect)
{
if (RootReport != null)
{
rect.Size = GraphicsUnitConverter.Convert(GetActualSize(), GraphicsDpi.Millimeter, Dpi);
}
return rect;
}
SizeF GetActualSize() => Constants.Bounds.Size;
protected override XRControlScripts CreateScripts() => new XRPatternScripts(this);
protected override int DefaultHeight =>
ConvertFromMMToDpi(Constants.Bounds.Height, GraphicsDpi.HundredthsOfAnInch);
protected override int DefaultWidth =>
ConvertFromMMToDpi(Constants.Bounds.Width, GraphicsDpi.HundredthsOfAnInch);
int ConvertFromMMToDpi(float mmValue, float targetDpi) => (int)GraphicsUnitConverter.Convert(mmValue, GraphicsDpi.Millimeter, targetDpi);
protected override VisualBrick CreateBrick(VisualBrick[] childrenBricks) => new PatternBrick(this);
protected override void PutStateToBrick(VisualBrick brick, PrintingSystemBase ps)
{
base.PutStateToBrick(brick, ps);
if (!(brick is PatternBrick patternBrick)) return;
patternBrick.CodeOptions.Assign(CodeOptions);
patternBrick.GenerateContent(patternDataItem);
}
protected override void GetStateFromBrick(VisualBrick brick) => base.GetStateFromBrick(brick);
#endregion
}
}