779 lines
22 KiB
C#

using System.ComponentModel;
using System.Drawing;
namespace DevComponents.DotNetBar.Charts.Style
{
/// <summary>
/// Represents the visual style of an element.
/// </summary>
[TypeConverter(typeof(VisualStylesConverter))]
public class CrosshairVisualStyle : BaseVisualStyle
{
#region Private variables
private Background _Background;
private Color _BorderColor = Color.Empty;
private LinePattern _BorderPattern = LinePattern.NotSet;
private int _BorderThickness;
private Color _TextColor = Color.Empty;
private ChartLineVisualStyle _ValueXLineStyle;
private ChartLineVisualStyle _ValueYLineStyle;
private Font _GroupHeaderFont;
private Color _GroupHeaderTextColor = Color.Empty;
private Font _Font;
private Padding _Margin;
private Padding _Padding;
#endregion
#region Public properties
#region Background
/// <summary>
/// Gets or sets the style background.
/// </summary>
[Description("Indicates the style background")]
public Background Background
{
get
{
if (_Background == null)
{
_Background = Background.Empty;
UpdateChangeHandler(null, _Background);
}
return (_Background);
}
set
{
if (_Background != value)
{
UpdateChangeHandler(_Background, value);
_Background = value;
OnPropertyChangedEx("Background", VisualChangeType.Render);
}
}
}
/// <summary>
/// Gets whether property should be serialized.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
private bool ShouldSerializeBackground()
{
return (_Background != null && _Background.IsEmpty == false);
}
/// <summary>
/// Resets property to its default value.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
private void ResetBackground()
{
Background = null;
}
#endregion
#region BorderColor
/// <summary>
/// Gets or sets the style border color.
/// </summary>
[Description("Indicates the style Border Color")]
public Color BorderColor
{
get { return (_BorderColor); }
set
{
if (_BorderColor != value)
{
_BorderColor = value;
OnPropertyChangedEx("BorderColor", VisualChangeType.Render);
}
}
}
/// <summary>
/// Gets whether property should be serialized.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
private bool ShouldSerializeBorderColor()
{
return (_BorderColor.IsEmpty == false);
}
/// <summary>
/// Resets property to its default value.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
private void ResetBorderColor()
{
BorderColor = Color.Empty;
}
#endregion
#region BorderPattern
/// <summary>
/// Gets or sets the style border pattern (Solid, Dash, ...)
/// </summary>
[DefaultValue(LinePattern.NotSet)]
[Description("Indicates the style border pattern (Solid, Dash, ...)")]
public LinePattern BorderPattern
{
get { return (_BorderPattern); }
set
{
if (_BorderPattern != value)
{
_BorderPattern = value;
OnPropertyChangedEx("BorderPattern", VisualChangeType.Render);
}
}
}
#endregion
#region BorderThickness
/// <summary>
/// Gets or sets the style border thickness.
/// </summary>
[DefaultValue(0)]
[Description("Indicates the style border thickness")]
public int BorderThickness
{
get { return (_BorderThickness); }
set
{
if (_BorderThickness != value)
{
_BorderThickness = value;
OnPropertyChangedEx("BorderThickness", VisualChangeType.Render);
}
}
}
#endregion
#region GroupHeaderFont
/// <summary>
/// Gets or sets the GroupHeader Font
/// </summary>
[DefaultValue(null)]
[Description("Indicates the GroupHeader Font")]
public Font GroupHeaderFont
{
get { return (_GroupHeaderFont); }
set
{
if (_GroupHeaderFont != value)
{
_GroupHeaderFont = value;
OnPropertyChangedEx("GroupHeaderFont", VisualChangeType.Render);
}
}
}
#endregion
#region GroupHeaderTextColor
/// <summary>
/// Gets or sets the Color of the GroupHeaderText.
/// </summary>
[Category("Appearance")]
[Description("Indicates the Color of the GroupHeaderText.")]
public Color GroupHeaderTextColor
{
get { return (_GroupHeaderTextColor); }
set
{
if (_GroupHeaderTextColor != value)
{
_GroupHeaderTextColor = value;
OnPropertyChangedEx("GroupHeaderTextColor", VisualChangeType.Render);
}
}
}
/// <summary>
/// Gets whether property should be serialized.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
private bool ShouldSerializeGroupHeaderTextColor()
{
return (_GroupHeaderTextColor.IsEmpty == false);
}
/// <summary>
/// Resets property to its default value.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
private void ResetGroupHeaderTextColor()
{
GroupHeaderTextColor = Color.Empty;
}
#endregion
#region Font
/// <summary>
/// Gets or sets the Font
/// </summary>
[DefaultValue(null)]
[Description("Indicates the Font")]
public Font Font
{
get { return (_Font); }
set
{
if (_Font != value)
{
_Font = value;
OnPropertyChangedEx("Font", VisualChangeType.Render);
}
}
}
#endregion
#region Margin
/// <summary>
/// Gets or sets the spacing between the border and outside content.
/// </summary>
[Description("Indicates the spacing between the border and outside content")]
public Padding Margin
{
get
{
if (_Margin == null)
{
_Margin = Padding.Empty;
UpdateChangeHandler(null, _Margin);
}
return (_Margin);
}
set
{
if (_Margin != value)
{
UpdateChangeHandler(_Margin, value);
_Margin = value;
OnPropertyChangedEx("Margin", VisualChangeType.Layout);
}
}
}
/// <summary>
/// Gets whether property should be serialized.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
private bool ShouldSerializeMargin()
{
return (_Margin != null && _Margin.IsEmpty == false);
}
/// <summary>
/// Resets property to its default value.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
private void ResetMargin()
{
Margin = null;
}
#endregion
#region Padding
/// <summary>
/// Gets or sets spacing between the content and edges of the element.
/// </summary>
[Description("Indicates the spacing between the content and edges of the element")]
public Padding Padding
{
get
{
if (_Padding == null)
{
_Padding = Padding.Empty;
UpdateChangeHandler(null, _Padding);
}
return (_Padding);
}
set
{
if (_Padding != value)
{
UpdateChangeHandler(_Padding, value);
_Padding = value;
OnPropertyChangedEx("Padding", VisualChangeType.Render);
}
}
}
/// <summary>
/// Gets whether property should be serialized.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
private bool ShouldSerializePadding()
{
return (_Padding != null && _Padding.IsEmpty == false);
}
/// <summary>
/// Resets property to its default value.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
private void ResetPadding()
{
Padding = null;
}
#endregion
#region TextColor
/// <summary>
/// Gets or sets the Text color
/// </summary>
[Description("Indicates the Text color")]
public Color TextColor
{
get { return (_TextColor); }
set
{
if (_TextColor != value)
{
_TextColor = value;
OnPropertyChangedEx("TextColor", VisualChangeType.Render);
}
}
}
/// <summary>
/// Gets whether property should be serialized.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
private bool ShouldSerializeTextColor()
{
return (_TextColor.IsEmpty == false);
}
/// <summary>
/// Resets property to its default value.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
private void ResetTextColor()
{
TextColor = Color.Empty;
}
#endregion
#region ValueXLineStyle
/// <summary>
/// Gets or sets the visual style for the X Value Line.
/// </summary>
[Category("Style")]
[Description("Indicates the visual style for the X Value Line.")]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public ChartLineVisualStyle ValueXLineStyle
{
get
{
if (_ValueXLineStyle == null)
{
_ValueXLineStyle = new ChartLineVisualStyle();
UpdateChangeHandler(null, _ValueXLineStyle);
}
return (_ValueXLineStyle);
}
set
{
if (_ValueXLineStyle != value)
{
ChartLineVisualStyle oldValue = _ValueXLineStyle;
_ValueXLineStyle = value;
OnStyleChanged("ValueXLineStyle", oldValue, value);
if (oldValue != null)
oldValue.Dispose();
}
}
}
#endregion
#region ValueYLineStyle
/// <summary>
/// Gets or sets the visual style for the Y Value Line.
/// </summary>
[Category("Style")]
[Description("Indicates the visual style for the Y Value Line.")]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public ChartLineVisualStyle ValueYLineStyle
{
get
{
if (_ValueYLineStyle == null)
{
_ValueYLineStyle = new ChartLineVisualStyle();
UpdateChangeHandler(null, _ValueYLineStyle);
}
return (_ValueYLineStyle);
}
set
{
if (_ValueYLineStyle != value)
{
ChartLineVisualStyle oldValue = _ValueYLineStyle;
_ValueYLineStyle = value;
OnStyleChanged("ValueYLineStyle", oldValue, value);
if (oldValue != null)
oldValue.Dispose();
}
}
}
#endregion
#region IsEmpty
/// <summary>
/// Gets whether the style is logically Empty.
/// </summary>
[Browsable(false)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
[Description("Gets whether the style is logically Empty.")]
public override bool IsEmpty
{
get
{
return ((_Background == null || _Background.IsEmpty == true) &&
(_BorderColor.IsEmpty == true) &&
(_BorderPattern == LinePattern.NotSet) &&
(_BorderThickness <= 0) &&
(_GroupHeaderFont == null) &&
(_Font == null) &&
(_GroupHeaderTextColor.IsEmpty == true) &&
(_Margin == null || _Margin.IsEmpty == true) &&
(_Padding == null || _Padding.IsEmpty == true) &&
(_TextColor.IsEmpty == true) &&
(_ValueXLineStyle == null || _ValueXLineStyle.IsEmpty) &&
(_ValueYLineStyle == null || _ValueYLineStyle.IsEmpty) &&
(base.IsEmpty == true));
}
}
#endregion
#endregion
#region ApplyStyle
/// <summary>
/// Applies the style to instance of this style.
/// </summary>
/// <param name="style">Style to apply.</param>
public void ApplyStyle(CrosshairVisualStyle style)
{
if (style != null)
{
base.ApplyStyle(style);
if (style._Background != null && style._Background.IsEmpty == false)
Background = style._Background.Copy();
if (style._BorderColor.IsEmpty == false)
BorderColor = style._BorderColor;
if (style._BorderPattern != LinePattern.NotSet)
BorderPattern = style._BorderPattern;
if (style._BorderThickness > 0)
BorderThickness = style._BorderThickness;
if (style.GroupHeaderFont != null)
GroupHeaderFont = style.GroupHeaderFont;
if (style._Font != null)
Font = style.Font;
if (style.GroupHeaderTextColor.IsEmpty == false)
GroupHeaderTextColor = style.GroupHeaderTextColor;
if (style._Margin != null && style._Margin.IsEmpty == false)
Margin = style.Margin.Copy();
if (style._Padding != null && style._Padding.IsEmpty == false)
Padding = style.Padding.Copy();
if (style._TextColor.IsEmpty == false)
TextColor = style._TextColor;
if (style._ValueXLineStyle != null && style.ValueXLineStyle.IsEmpty == false)
ValueXLineStyle.ApplyStyle(style.ValueXLineStyle);
if (style._ValueYLineStyle != null && style.ValueYLineStyle.IsEmpty == false)
ValueYLineStyle.ApplyStyle(style.ValueYLineStyle);
}
}
#endregion
#region Copy
/// <summary>
/// Returns the copy of the style.
/// </summary>
/// <returns>Copy of the style.</returns>
public new CrosshairVisualStyle Copy()
{
CrosshairVisualStyle style = new CrosshairVisualStyle();
CopyTo(style);
return (style);
}
#endregion
#region CopyTo
/// <summary>
/// Returns the copy of the style.
/// </summary>
/// <returns>Copy of the style.</returns>
public void CopyTo(CrosshairVisualStyle style)
{
base.CopyTo(style);
style.Background = (_Background != null) ? _Background.Copy() : null;
style.BorderColor = _BorderColor;
style.BorderPattern = _BorderPattern;
style.BorderThickness = _BorderThickness;
style.GroupHeaderFont = (_GroupHeaderFont != null) ? (Font)_GroupHeaderFont.Clone() : null;
style.GroupHeaderTextColor = _GroupHeaderTextColor;
style.Font = (_Font != null) ? (Font)_Font.Clone() : null;
style.Margin = (_Margin != null) ? _Margin.Copy() : null;
style.Padding = (_Padding != null) ? _Padding.Copy() : null;
style.TextColor = _TextColor;
style.ValueXLineStyle = (_ValueXLineStyle != null) ? _ValueXLineStyle.Copy() : null;
style.ValueYLineStyle = (_ValueYLineStyle != null) ? _ValueYLineStyle.Copy() : null;
}
#endregion
#region GetSerialData
internal override SerialElementCollection GetSerialData(string serialName)
{
SerialElementCollection sec = new SerialElementCollection();
if (serialName != null)
{
if (serialName.Equals("") == true)
serialName = "CrosshairVisualStyle";
sec.AddStartElement(serialName);
}
if (_Background != null && _Background.IsEmpty == false)
sec.AddElement(_Background.GetSerialData("Background"));
sec.AddValue("BorderColor", BorderColor, Color.Empty);
sec.AddValue("BorderPattern", BorderPattern, LinePattern.NotSet);
sec.AddValue("BorderThickness", BorderThickness, 0);
if (_GroupHeaderFont != null)
sec.AddValue("GroupHeaderFont", XmlSerializableFont.ConvertToString(GroupHeaderFont));
sec.AddValue("GroupHeaderTextColor", GroupHeaderTextColor, Color.Empty);
if (_Font != null)
sec.AddValue("Font", XmlSerializableFont.ConvertToString(Font));
if (_Margin != null && _Margin.IsEmpty == false)
sec.AddElement(_Margin.GetSerialData("Margin"));
if (_Padding != null && _Padding.IsEmpty == false)
sec.AddElement(_Padding.GetSerialData("Padding"));
sec.AddValue("TextColor", TextColor, Color.Empty);
if (_ValueXLineStyle != null && _ValueXLineStyle.IsEmpty == false)
sec.AddElement(_ValueXLineStyle.GetSerialData("ValueXLineStyle"));
if (_ValueYLineStyle != null && _ValueYLineStyle.IsEmpty == false)
sec.AddElement(_ValueYLineStyle.GetSerialData("ValueYLineStyle"));
sec.AddElement(base.GetSerialData(null));
if (serialName != null)
sec.AddEndElement(serialName);
return (sec);
}
#endregion
#region PutSerialData
#region ProcessValue
internal override void ProcessValue(SerialElement se)
{
switch (se.Name)
{
case "BorderColor":
BorderColor = se.GetValueColor();
break;
case "BorderPattern":
BorderPattern = (LinePattern)se.GetValueEnum(typeof(LinePattern));
break;
case "BorderThickness":
BorderThickness = int.Parse(se.StringValue);
break;
case "GroupHeaderFont":
GroupHeaderFont = XmlSerializableFont.ConvertFromString(se.StringValue);
break;
case "GroupHeaderTextColor":
GroupHeaderTextColor = se.GetValueColor();
break;
case "Font":
Font = XmlSerializableFont.ConvertFromString(se.StringValue);
break;
case "TextColor":
TextColor = se.GetValueColor();
break;
default:
base.ProcessValue(se);
break;
}
}
#endregion
#region ProcessCollection
internal override void ProcessCollection(SerialElement se)
{
SerialElementCollection sec = se.Sec;
switch (se.Name)
{
case "Background":
sec.PutSerialData(Background);
break;
case "Margin":
sec.PutSerialData(Margin);
break;
case "Padding":
sec.PutSerialData(Padding);
break;
case "ValueXLineStyle":
sec.PutSerialData(ValueXLineStyle);
break;
case "ValueYLineStyle":
sec.PutSerialData(ValueYLineStyle);
break;
default:
base.ProcessCollection(se);
break;
}
}
#endregion
#endregion
#region IDisposable
/// <summary>
/// Dispose
/// </summary>
public override void Dispose()
{
Margin = null;
Padding = null;
ValueXLineStyle = null;
ValueYLineStyle = null;
base.Dispose();
}
#endregion
}
}