623 lines
14 KiB
C#
623 lines
14 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Drawing;
|
|
using System.Globalization;
|
|
|
|
namespace DevComponents.DotNetBar.Charts.Style
|
|
{
|
|
/// <summary>
|
|
/// Represents the base visual style.
|
|
/// </summary>
|
|
[ToolboxItem(false), DesignTimeVisible(false)]
|
|
public class BaseVisualStyle : INotifyPropertyChanged, IDisposable, IProcessSerialElement
|
|
{
|
|
#region Static data
|
|
|
|
static private List<BaseVisualStyle> _StyleList;
|
|
private static StyleUpdateMode _StyleUpdateMode = StyleUpdateMode.Full;
|
|
|
|
#endregion
|
|
|
|
#region Private variables
|
|
|
|
private StyleType _StyleType;
|
|
private BaseVisualStyle _Parent;
|
|
|
|
private ushort _StyleUpdateCount;
|
|
|
|
private string _Class = "";
|
|
private object _Tag;
|
|
|
|
#endregion
|
|
|
|
#region Public properties
|
|
|
|
#region Class
|
|
|
|
/// <summary>
|
|
/// Gets or sets the class style belongs to.
|
|
/// </summary>
|
|
[Browsable(false)]
|
|
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
|
|
public string Class
|
|
{
|
|
get { return (_Class); }
|
|
|
|
set
|
|
{
|
|
if (_Class != value)
|
|
{
|
|
_Class = value;
|
|
|
|
OnPropertyChangedEx("Class", VisualChangeType.Layout);
|
|
}
|
|
}
|
|
}
|
|
|
|
#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 virtual bool IsEmpty
|
|
{
|
|
get { return (_Tag == null); }
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Tag
|
|
|
|
/// <summary>
|
|
/// Gets or sets the user defined reference Tag.
|
|
/// </summary>
|
|
[Browsable(false)]
|
|
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
|
|
[Description("User defined reference Tag.")]
|
|
public object Tag
|
|
{
|
|
get { return (_Tag); }
|
|
set { _Tag = value; }
|
|
}
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
#region Internal properties
|
|
|
|
#region StyleType
|
|
|
|
internal StyleType StyleType
|
|
{
|
|
get { return (_StyleType); }
|
|
set { _StyleType = value; }
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region StyleUpdateCount
|
|
|
|
internal ushort StyleUpdateCount
|
|
{
|
|
get { return (_StyleUpdateCount); }
|
|
set { _StyleUpdateCount = value; }
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region StyleUpdateMode
|
|
|
|
internal StyleUpdateMode StyleUpdateMode
|
|
{
|
|
get { return (_StyleUpdateMode); }
|
|
set { _StyleUpdateMode = value; }
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Parent
|
|
|
|
internal BaseVisualStyle Parent
|
|
{
|
|
get { return (_Parent); }
|
|
set { _Parent = value; }
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region StyleList
|
|
|
|
internal List<BaseVisualStyle> StyleList
|
|
{
|
|
get { return (_StyleList); }
|
|
set { _StyleList = value; }
|
|
}
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
#region ApplyStyle
|
|
|
|
/// <summary>
|
|
/// Applies the style to instance of this style.
|
|
/// </summary>
|
|
/// <param name="style">Style to apply.</param>
|
|
public void ApplyStyle(BaseVisualStyle style)
|
|
{
|
|
if (StyleList != null)
|
|
StyleList.Add(style ?? this);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region GetApplyStyleTypes
|
|
|
|
internal StyleType[] GetApplyStyleTypes(StyleType e)
|
|
{
|
|
StyleType[] css = null;
|
|
|
|
switch (e)
|
|
{
|
|
case StyleType.Default:
|
|
css = new StyleType[] { StyleType.Default};
|
|
break;
|
|
|
|
case StyleType.MouseOver:
|
|
css = new StyleType[] { StyleType.Default, e };
|
|
break;
|
|
|
|
case StyleType.Selected:
|
|
css = new StyleType[] { StyleType.Default, e };
|
|
break;
|
|
|
|
case StyleType.SelectedMouseOver:
|
|
css = new StyleType[] { StyleType.Default, StyleType.Selected, e };
|
|
break;
|
|
}
|
|
|
|
return (css);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Copy
|
|
|
|
/// <summary>
|
|
/// Returns the copy of the style.
|
|
/// </summary>
|
|
/// <returns>Copy of the style.</returns>
|
|
public BaseVisualStyle Copy()
|
|
{
|
|
BaseVisualStyle style = new BaseVisualStyle();
|
|
|
|
CopyTo(style);
|
|
|
|
return (style);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region CopyTo
|
|
|
|
/// <summary>
|
|
/// Returns the copy of the style.
|
|
/// </summary>
|
|
/// <returns>Copy of the style.</returns>
|
|
public void CopyTo(BaseVisualStyle copy)
|
|
{
|
|
copy.Class = _Class;
|
|
copy.Tag = _Tag;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region GetSerialData
|
|
|
|
internal virtual SerialElementCollection GetSerialData(string serialName)
|
|
{
|
|
if ((String.IsNullOrEmpty(Class) == false) || (Tag != null))
|
|
{
|
|
SerialElementCollection sec = new SerialElementCollection();
|
|
|
|
if (serialName != null)
|
|
{
|
|
if (serialName.Equals("") == true)
|
|
serialName = "BaseVisualStyle";
|
|
|
|
sec.AddStartElement(serialName);
|
|
}
|
|
|
|
sec.AddValue("Class", Class, "");
|
|
sec.AddValue("Tag", Tag, null);
|
|
|
|
if (serialName != null)
|
|
sec.AddEndElement(serialName);
|
|
|
|
return (sec);
|
|
}
|
|
|
|
return (null);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region PutSerialData
|
|
|
|
#region ProcessValue
|
|
|
|
void IProcessSerialElement.ProcessValue(SerialElement se)
|
|
{
|
|
ProcessValue(se);
|
|
}
|
|
|
|
internal virtual void ProcessValue(SerialElement se)
|
|
{
|
|
switch (se.Name)
|
|
{
|
|
case "Name":
|
|
Class = se.StringValue;
|
|
break;
|
|
|
|
case "Tag":
|
|
Tag = se.DataValue;
|
|
break;
|
|
|
|
default:
|
|
throw new Exception("Unknown Serial Value (" + se.Name + ")");
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region ProcessCollection
|
|
|
|
void IProcessSerialElement.ProcessCollection(SerialElement se)
|
|
{
|
|
ProcessCollection(se);
|
|
}
|
|
|
|
internal virtual void ProcessCollection(SerialElement se)
|
|
{
|
|
throw new Exception("Unknown Serial Collection (" + se.Name + ")");
|
|
}
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
#region ApplyDefaults
|
|
|
|
public virtual void ApplyDefaults()
|
|
{
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region INotifyPropertyChanged Members
|
|
|
|
/// <summary>
|
|
/// Occurs when property value has changed.
|
|
/// </summary>
|
|
public event PropertyChangedEventHandler PropertyChanged;
|
|
|
|
/// <summary>
|
|
/// Raises the PropertyChanged event.
|
|
/// </summary>
|
|
/// <param name="e">Event arguments</param>
|
|
protected virtual void OnPropertyChanged(PropertyChangedEventArgs e)
|
|
{
|
|
if ((StyleUpdateMode & StyleUpdateMode.UpdateCount) == StyleUpdateMode.UpdateCount)
|
|
StyleUpdateCount++;
|
|
|
|
if ((StyleUpdateMode & StyleUpdateMode.Notify) == StyleUpdateMode.Notify)
|
|
{
|
|
if (PropertyChanged != null)
|
|
PropertyChanged(this, e);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Default PropertyChanged processing
|
|
/// </summary>
|
|
/// <param name="s"></param>
|
|
protected void OnPropertyChanged(string s)
|
|
{
|
|
if ((StyleUpdateMode & StyleUpdateMode.UpdateCount) == StyleUpdateMode.UpdateCount)
|
|
StyleUpdateCount++;
|
|
|
|
if (PropertyChanged != null)
|
|
OnPropertyChanged(new VisualPropertyChangedEventArgs(s));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Default PropertyChanged processing
|
|
/// </summary>
|
|
/// <param name="s"></param>
|
|
/// <param name="changeType">invalidate</param>
|
|
protected void OnPropertyChangedEx(string s, VisualChangeType changeType)
|
|
{
|
|
if ((StyleUpdateMode & StyleUpdateMode.UpdateCount) == StyleUpdateMode.UpdateCount)
|
|
StyleUpdateCount++;
|
|
|
|
if (PropertyChanged != null)
|
|
OnPropertyChanged(new VisualPropertyChangedEventArgs(s, changeType));
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region UpdateChangeHandler
|
|
|
|
/// <summary>
|
|
/// UpdateChangeHandler
|
|
/// </summary>
|
|
/// <param name="oldValue"></param>
|
|
/// <param name="newValue"></param>
|
|
protected void UpdateChangeHandler(
|
|
INotifyPropertyChanged oldValue, INotifyPropertyChanged newValue)
|
|
{
|
|
if (oldValue != null)
|
|
oldValue.PropertyChanged -= ValuePropertyChanged;
|
|
|
|
if (newValue != null)
|
|
newValue.PropertyChanged += ValuePropertyChanged;
|
|
}
|
|
|
|
void ValuePropertyChanged(object sender, PropertyChangedEventArgs e)
|
|
{
|
|
OnPropertyChanged(e);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region OnStyleChanged
|
|
|
|
protected void OnStyleChanged(string property,
|
|
INotifyPropertyChanged oldValue, INotifyPropertyChanged newValue)
|
|
{
|
|
UpdateChangeHandler(oldValue, newValue);
|
|
|
|
OnPropertyChanged(property);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region IDisposable
|
|
|
|
/// <summary>
|
|
/// Dispose
|
|
/// </summary>
|
|
public virtual void Dispose()
|
|
{
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
|
|
#region enums
|
|
|
|
#region StyleState
|
|
|
|
///<summary>
|
|
/// StyleState
|
|
///</summary>
|
|
[Flags]
|
|
public enum StyleState
|
|
{
|
|
///<summary>
|
|
/// Default
|
|
///</summary>
|
|
Default = 0,
|
|
|
|
///<summary>
|
|
/// MouseOver
|
|
///</summary>
|
|
MouseOver = (1 << 0),
|
|
|
|
///<summary>
|
|
/// Selected
|
|
///</summary>
|
|
Selected = (1 << 1),
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region StyleType
|
|
|
|
///<summary>
|
|
/// StyleType
|
|
///</summary>
|
|
public enum StyleType
|
|
{
|
|
///<summary>
|
|
/// CellStyle is Not Set
|
|
///</summary>
|
|
NotSet = -1,
|
|
|
|
///<summary>
|
|
/// Default
|
|
///</summary>
|
|
Default = 0,
|
|
|
|
///<summary>
|
|
/// MouseOver
|
|
///</summary>
|
|
MouseOver,
|
|
|
|
///<summary>
|
|
/// Selected
|
|
///</summary>
|
|
Selected,
|
|
|
|
///<summary>
|
|
/// SelectedMouseOver
|
|
///</summary>
|
|
SelectedMouseOver,
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region StyleUpdateMode
|
|
|
|
[Flags]
|
|
internal enum StyleUpdateMode
|
|
{
|
|
None = 0,
|
|
|
|
Notify = (1 << 0),
|
|
UpdateCount = (1 << 1),
|
|
|
|
Full = (UpdateCount | Notify),
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Tbool
|
|
|
|
///<summary>
|
|
/// TBool - Three state boolean
|
|
///</summary>
|
|
public enum Tbool
|
|
{
|
|
///<summary>
|
|
/// NotSet
|
|
///</summary>
|
|
NotSet,
|
|
|
|
///<summary>
|
|
/// True
|
|
///</summary>
|
|
True,
|
|
|
|
///<summary>
|
|
/// False
|
|
///</summary>
|
|
False
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region VisualChangeType
|
|
|
|
/// <summary>
|
|
/// Defines visual property change type.
|
|
/// </summary>
|
|
public enum VisualChangeType
|
|
{
|
|
/// <summary>
|
|
/// Visual style has changed so Recalc is needed
|
|
/// </summary>
|
|
Recalc,
|
|
|
|
/// <summary>
|
|
/// Visual style has changed so layout is impacted, but not recalc
|
|
/// </summary>
|
|
Layout,
|
|
|
|
/// <summary>
|
|
/// Visual style has changed so visuals are impacted, but not layout
|
|
/// </summary>
|
|
Render
|
|
}
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
#region VisualPropertyChangedEventArgs
|
|
|
|
/// <summary>
|
|
/// Represents visual property changed event arguments.
|
|
/// </summary>
|
|
public class VisualPropertyChangedEventArgs : PropertyChangedEventArgs
|
|
{
|
|
#region Public data
|
|
|
|
/// <summary>
|
|
/// Gets the change type.
|
|
/// </summary>
|
|
public readonly VisualChangeType ChangeType;
|
|
|
|
#endregion
|
|
|
|
/// <summary>
|
|
/// Initializes a new instance of the VisualPropertyChangedEventArgs class.
|
|
/// </summary>
|
|
public VisualPropertyChangedEventArgs(string propertyName)
|
|
: base(propertyName)
|
|
{
|
|
ChangeType = VisualChangeType.Layout;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Initializes a new instance of the VisualPropertyChangedEventArgs class.
|
|
/// </summary>
|
|
public VisualPropertyChangedEventArgs(string propertyName, VisualChangeType changeType)
|
|
: base(propertyName)
|
|
{
|
|
ChangeType = changeType;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region VisualStylesConverter
|
|
|
|
///<summary>
|
|
/// VisualStylesConverter
|
|
///</summary>
|
|
public class VisualStylesConverter : ExpandableObjectConverter
|
|
{
|
|
/// <summary>
|
|
/// ConvertTo
|
|
/// </summary>
|
|
/// <param name="context"></param>
|
|
/// <param name="culture"></param>
|
|
/// <param name="value"></param>
|
|
/// <param name="destinationType"></param>
|
|
/// <returns></returns>
|
|
public override object ConvertTo(
|
|
ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
|
|
{
|
|
if (destinationType == typeof(string))
|
|
return (" ");
|
|
|
|
return (base.ConvertTo(context, culture, value, destinationType));
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region DefaultStyleConvertor
|
|
|
|
public class DefaultStyleConvertor : ExpandableObjectConverter
|
|
{
|
|
public override object ConvertTo(
|
|
ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
|
|
{
|
|
if (destinationType == typeof(string))
|
|
{
|
|
BaseVisualStyle bvs = value as BaseVisualStyle;
|
|
|
|
if (bvs != null)
|
|
{
|
|
ColorConverter cvt = new ColorConverter();
|
|
|
|
return ((bvs.IsEmpty == true) ? " " : "(Set)");
|
|
}
|
|
}
|
|
|
|
return (base.ConvertTo(context, culture, value, destinationType));
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
}
|