740 lines
21 KiB
C#

using System.ComponentModel;
using System.Drawing;
namespace DevComponents.DotNetBar.Charts.Style
{
///<summary>
/// ScrollBarVisualStyle
///</summary>
[TypeConverter(typeof(VisualStylesConverter))]
public class ScrollBarVisualStyles : VisualStyles<ScrollBarVisualStyle>
{
#region Copy
/// <summary>
/// Returns the copy of the style.
/// </summary>
/// <returns>Copy of the style.</returns>
public ScrollBarVisualStyles Copy()
{
ScrollBarVisualStyles styles = new ScrollBarVisualStyles();
for (int i = 0; i < Styles.Length; i++)
{
ScrollBarVisualStyle vstyle = Styles[i];
if (vstyle != null)
styles.Styles[i] = vstyle.Copy();
}
return (styles);
}
#endregion
}
/// <summary>
/// Represents the visual style of a ScrollBar element.
/// </summary>
[TypeConverter(typeof(VisualStylesConverter))]
public class ScrollBarVisualStyle : BaseVisualStyle
{
#region Private variables
private Color _ArrowColor;
private Color _ArrowBorderColor;
private Background _ArrowBackground;
private Color _ThumbColor;
private Color _ThumbBorderColor;
private Background _ThumbBackground;
private Color _BorderColor;
private Background _TrackBackground;
private Tbool _NoAlphaOnMouseOver = Tbool.NotSet;
#endregion
#region Public properties
#region ArrowBackground
/// <summary>
/// Gets or sets the Background of the Increase/Decrease Arrow elements of the ScrollBar.
/// </summary>
[Description("Indicates the Background of the Increase/Decrease Arrow elements of the ScrollBar")]
public Background ArrowBackground
{
get
{
if (_ArrowBackground == null)
{
_ArrowBackground = Background.Empty;
UpdateChangeHandler(null, _ArrowBackground);
}
return (_ArrowBackground);
}
set
{
if (value != _ArrowBackground)
{
UpdateChangeHandler(_ArrowBackground, value);
_ArrowBackground = value;
OnPropertyChangedEx("ArrowBackground", VisualChangeType.Render);
}
}
}
/// <summary>
/// Gets whether property should be serialized.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
private bool ShouldSerializeArrowBackground()
{
return (_ArrowBackground != null && _ArrowBackground.IsEmpty == false);
}
/// <summary>
/// Resets property to its default value.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
private void ResetArrowBackground()
{
ArrowBackground = null;
}
#endregion
#region ArrowBorderColor
/// <summary>
/// Gets or sets the Arrow Increase/Decrease border color.
/// </summary>
[Description("Indicates the Arrow Increase/Decrease border color")]
public Color ArrowBorderColor
{
get { return (_ArrowBorderColor); }
set
{
if (value != _ArrowBorderColor)
{
_ArrowBorderColor = value;
OnPropertyChangedEx("ArrowBorderColor", VisualChangeType.Render);
}
}
}
/// <summary>
/// Gets whether property should be serialized.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
private bool ShouldSerializeArrowBorderColor()
{
return (_ArrowBorderColor.IsEmpty == false);
}
/// <summary>
/// Resets property to its default value.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
private void ResetArrowBorderColor()
{
ArrowBorderColor = Color.Empty;
}
#endregion
#region ArrowColor
/// <summary>
/// Gets or sets the Color of the Increase/Decrease Arrow elements of the scrollBar.
/// </summary>
[Description("Indicates the Color of the Increase/Decrease Arrow elements of the scrollBar")]
public Color ArrowColor
{
get { return (_ArrowColor); }
set
{
if (value != _ArrowColor)
{
_ArrowColor = value;
OnPropertyChangedEx("ArrowColor", VisualChangeType.Render);
}
}
}
/// <summary>
/// Gets whether property should be serialized.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
private bool ShouldSerializeArrowColor()
{
return (_ArrowColor.IsEmpty == false);
}
/// <summary>
/// Resets property to its default value.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
private void ResetArrowColor()
{
ArrowColor = Color.Empty;
}
#endregion
#region BorderColor
/// <summary>
/// Gets or sets the border color of the scrollBar.
/// </summary>
[Description("Indicates the Border Color of the scrollBar")]
public Color BorderColor
{
get { return (_BorderColor); }
set
{
if (value != _BorderColor)
{
_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 NoAlphaOnMouseOver
/// <summary>
/// Gets or sets whether color alpha values are ignored when the mouse is over the scrollbar.
/// </summary>
[DefaultValue(Tbool.NotSet)]
[Description("Indicates whether color alpha values are ignored when the mouse is over the scrollbar.")]
public Tbool NoAlphaOnMouseOver
{
get { return (_NoAlphaOnMouseOver); }
set
{
if (value != _NoAlphaOnMouseOver)
{
_NoAlphaOnMouseOver = value;
OnPropertyChangedEx("NoAlphaOnMouseOver", VisualChangeType.Render);
}
}
}
#endregion
#region ThumbBackground
/// <summary>
/// Gets or sets the Background of the Thumb element of the ScrollBar.
/// </summary>
[Description("Indicates the Background of the Thumb element of the ScrollBar")]
public Background ThumbBackground
{
get
{
if (_ThumbBackground == null)
{
_ThumbBackground = Background.Empty;
UpdateChangeHandler(null, _ThumbBackground);
}
return (_ThumbBackground);
}
set
{
if (value != _ThumbBackground)
{
UpdateChangeHandler(_ThumbBackground, value);
_ThumbBackground = value;
OnPropertyChangedEx("ThumbBackground", VisualChangeType.Render);
}
}
}
/// <summary>
/// Gets whether property should be serialized.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
private bool ShouldSerializeThumbBackground()
{
return (_ThumbBackground != null && _ThumbBackground.IsEmpty == false);
}
/// <summary>
/// Resets property to its default value.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
private void ResetThumbBackground()
{
ThumbBackground = null;
}
#endregion
#region ThumbBorderColor
/// <summary>
/// Gets or sets the Thumb border color.
/// </summary>
[Description("Indicates the Thumb border color")]
public Color ThumbBorderColor
{
get { return (_ThumbBorderColor); }
set
{
if (value != _ThumbBorderColor)
{
_ThumbBorderColor = value;
OnPropertyChangedEx("ThumbBorderColor", VisualChangeType.Render);
}
}
}
/// <summary>
/// Gets whether property should be serialized.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
private bool ShouldSerializeThumbBorderColor()
{
return (_ThumbBorderColor.IsEmpty == false);
}
/// <summary>
/// Resets property to its default value.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
private void ResetThumbBorderColor()
{
ThumbBorderColor = Color.Empty;
}
#endregion
#region ThumbColor
/// <summary>
/// Gets or sets the Color of the Thumb content element (hash marks) of the scrollBar.
/// </summary>
[Description("Indicates the Color of the Thumb content element (hash marks) of the scrollBar")]
public Color ThumbColor
{
get { return (_ThumbColor); }
set
{
if (value != _ThumbColor)
{
_ThumbColor = value;
OnPropertyChangedEx("ThumbColor", VisualChangeType.Render);
}
}
}
/// <summary>
/// Gets whether property should be serialized.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
private bool ShouldSerializeThumbColor()
{
return (_ThumbColor.IsEmpty == false);
}
/// <summary>
/// Resets property to its default value.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
private void ResetThumbColor()
{
ThumbColor = Color.Empty;
}
#endregion
#region TrackBackground
/// <summary>
/// Gets or sets the Background of the Increase/Decrease Track elements of the ScrollBar.
/// </summary>
[Description("Indicates the Background of the Increase/Decrease Track elements of the ScrollBar")]
public Background TrackBackground
{
get
{
if (_TrackBackground == null)
{
_TrackBackground = Background.Empty;
UpdateChangeHandler(null, _TrackBackground);
}
return (_TrackBackground);
}
set
{
if (_TrackBackground != value)
{
UpdateChangeHandler(_TrackBackground, value);
_TrackBackground = value;
OnPropertyChangedEx("TrackBackground", VisualChangeType.Render);
}
}
}
/// <summary>
/// Gets whether property should be serialized.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
private bool ShouldSerializeTrackBackground()
{
return (_TrackBackground != null && _TrackBackground.IsEmpty == false);
}
/// <summary>
/// Resets property to its default value.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
private void ResetTrackBackground()
{
TrackBackground = null;
}
#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 ((_ArrowBackground == null || _ArrowBackground.IsEmpty) &&
(_ArrowBorderColor.IsEmpty) &&
(_ArrowColor.IsEmpty) &&
(_BorderColor.IsEmpty) &&
(_NoAlphaOnMouseOver == Tbool.NotSet) &&
(_ThumbBackground == null || _ThumbBackground.IsEmpty) &&
(_ThumbBorderColor.IsEmpty) &&
(_ThumbColor.IsEmpty) &&
(_TrackBackground == null || _TrackBackground.IsEmpty) &&
(base.IsEmpty == true));
}
}
#endregion
#endregion
#region GetColor
internal Color GetColor(Color color, bool noAlpha)
{
if (noAlpha == false)
return (color);
uint argb = (uint)color.ToArgb() | 0xff000000;
return (Color.FromArgb((int)argb));
}
#endregion
#region ApplyStyle
/// <summary>
/// Applies the style to instance of this style.
/// </summary>
/// <param name="style">Style to apply.</param>
public void ApplyStyle(ScrollBarVisualStyle style)
{
if (style != null)
{
base.ApplyStyle(style);
if (style.ArrowBackground.IsEmpty == false)
ArrowBackground = style.ArrowBackground.Copy();
if (style.ArrowBorderColor.IsEmpty == false)
ArrowBorderColor = style.ArrowBorderColor;
if (style.ArrowColor.IsEmpty == false)
ArrowColor = style.ArrowColor;
if (style.BorderColor.IsEmpty == false)
BorderColor = style.BorderColor;
if (style.NoAlphaOnMouseOver != Tbool.NotSet)
NoAlphaOnMouseOver = style.NoAlphaOnMouseOver;
if (style.ThumbBackground.IsEmpty == false)
ThumbBackground = style.ThumbBackground.Copy();
if (style.ThumbBorderColor.IsEmpty == false)
ThumbBorderColor = style.ThumbBorderColor;
if (style.ThumbColor.IsEmpty == false)
ThumbColor = style.ThumbColor;
if (style.TrackBackground.IsEmpty == false)
TrackBackground = style.TrackBackground.Copy();
}
}
#endregion
#region ApplyDefaults
public override void ApplyDefaults()
{
if (ArrowBackground.IsEmpty)
ArrowBackground = new Background(Color.Gainsboro);
if (ThumbBackground.IsEmpty)
ThumbBackground = new Background(Color.White, Color.Gainsboro);
if (TrackBackground.IsEmpty)
TrackBackground = new Background(Color.Gainsboro);
if (BorderColor.IsEmpty)
BorderColor = Color.Gray;
if (ThumbBorderColor.IsEmpty)
ThumbBorderColor = Color.Gray;
if (ArrowColor.IsEmpty)
ArrowColor = Color.DimGray;
if (ThumbColor.IsEmpty)
ThumbColor = Color.Black;
if (ArrowBorderColor.IsEmpty)
ArrowBorderColor = Color.Gray;
if (NoAlphaOnMouseOver == Tbool.NotSet)
NoAlphaOnMouseOver = Tbool.False;
base.ApplyDefaults();
}
#endregion
#region Copy
/// <summary>
/// Returns the copy of the style.
/// </summary>
/// <returns>Copy of the style.</returns>
public new ScrollBarVisualStyle Copy()
{
ScrollBarVisualStyle style = new ScrollBarVisualStyle();
CopyTo(style);
return (style);
}
#endregion
#region CopyTo
/// <summary>
/// Returns the copy of the style.
/// </summary>
/// <returns>Copy of the style.</returns>
public void CopyTo(ScrollBarVisualStyle style)
{
base.CopyTo(style);
style.ArrowBackground = (_ArrowBackground != null ? _ArrowBackground.Copy() : null);
style.ArrowBorderColor = _ArrowBorderColor;
style.ArrowColor = _ArrowColor;
style.BorderColor = _BorderColor;
style.NoAlphaOnMouseOver = _NoAlphaOnMouseOver;
style.ThumbBackground = (_ThumbBackground != null ? _ThumbBackground.Copy() : null);
style.ThumbBorderColor = _ThumbBorderColor;
style.ThumbColor = _ThumbColor;
style.TrackBackground = (_TrackBackground != null ? _TrackBackground.Copy() : null);
}
#endregion
#region GetSerialData
internal override SerialElementCollection GetSerialData(string serialName)
{
SerialElementCollection sec = new SerialElementCollection();
if (serialName != null)
{
if (serialName.Equals("") == true)
serialName = "ScrollBarVisualStyle";
sec.AddStartElement(serialName);
}
if (_ArrowBackground != null && _ArrowBackground.IsEmpty == false)
sec.AddElement(_ArrowBackground.GetSerialData("ArrowBackground"));
sec.AddValue("ArrowBorderColor", ArrowBorderColor, Color.Empty);
sec.AddValue("ArrowColor", ArrowColor, Color.Empty);
sec.AddValue("BorderColor", BorderColor, Color.Empty);
sec.AddValue("NoAlphaOnMouseOver", NoAlphaOnMouseOver, Tbool.NotSet);
if (_ThumbBackground != null && _ThumbBackground.IsEmpty == false)
sec.AddElement(_ThumbBackground.GetSerialData("ThumbBackground"));
sec.AddValue("ThumbBorderColor", ThumbBorderColor, Color.Empty);
sec.AddValue("ThumbColor", ThumbColor, Color.Empty);
if (_TrackBackground != null && _TrackBackground.IsEmpty == false)
sec.AddElement(_TrackBackground.GetSerialData("TrackBackground"));
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 "ArrowBorderColor":
ArrowBorderColor = se.GetValueColor();
break;
case "ArrowColor":
ArrowColor = se.GetValueColor();
break;
case "BorderColor":
BorderColor = se.GetValueColor();
break;
case "NoAlphaOnMouseOver":
NoAlphaOnMouseOver = (Tbool)se.GetValueEnum(typeof(Tbool));
break;
case "ThumbBorderColor":
ThumbBorderColor = se.GetValueColor();
break;
case "ThumbColor":
ThumbColor = 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 "ArrowBackground":
sec.PutSerialData(ArrowBackground);
break;
case "ThumbBackground":
sec.PutSerialData(ThumbBackground);
break;
case "TrackBackground":
sec.PutSerialData(TrackBackground);
break;
default:
base.ProcessCollection(se);
break;
}
}
#endregion
#endregion
#region IDisposable
public override void Dispose()
{
ArrowBackground = null;
ThumbBackground = null;
TrackBackground = null;
base.Dispose();
}
#endregion
}
}