using System; using System.Collections.Generic; using System.Text; using System.ComponentModel; using System.Drawing; using System.Windows.Forms; namespace DevComponents.DotNetBar.Layout { [TypeConverter(typeof(System.ComponentModel.ExpandableObjectConverter))] public class SimpleStyle : INotifyPropertyChanged, IDisposable { #region Constructor /// /// Initializes a new instance of the SimpleStyle class. /// public SimpleStyle() { _Background.PropertyChanged += BackgroundPropertyChanged; _BorderPattern.PropertyChanged += BorderPatternPropertyChanged; } #endregion #region Implementation /// /// Gets whether any properties on the style have been set that would cause style to be painted. /// [Browsable(false)] public bool IsPainted { get { return _Background.IsBackgroundSet || !_BorderColors.IsEmpty && !_BorderThickness.IsZero || _Font != null; } } private Background _Background = new Background(); /// /// Gets or sets the style background. /// [Description("Indicates the style background")] public Background Background { get { return _Background; } set { if (_Background != value) { if (_Background != null) _Background.PropertyChanged -= BackgroundPropertyChanged; _Background = value; if (_Background != null) _Background.PropertyChanged += BackgroundPropertyChanged; OnPropertyChanged(new PropertyChangedEventArgs("Background")); } } } private void BackgroundPropertyChanged(object sender, PropertyChangedEventArgs e) { OnPropertyChanged(new PropertyChangedEventArgs("Background." + e.PropertyName)); } /// /// Gets whether property should be serialized. /// [EditorBrowsable(EditorBrowsableState.Never)] private bool ShouldSerializeBackground() { return (_Background != null && !_Background.IsEmpty); } /// /// Resets property to its default value. /// [EditorBrowsable(EditorBrowsableState.Never)] private void ResetBackground() { Background = new Background(); } private Color _TextColor = Color.Empty; /// /// Gets or sets text color. /// [Category("Appearance"), Description("Indicates text color.")] public Color TextColor { get { return _TextColor; } set { _TextColor = value; OnPropertyChanged(new PropertyChangedEventArgs("TextColor")); } } /// /// Gets whether property should be serialized. /// [EditorBrowsable(EditorBrowsableState.Never)] public bool ShouldSerializeTextColor() { return !_TextColor.IsEmpty; } /// /// Resets property to its default value. /// [EditorBrowsable(EditorBrowsableState.Never)] public void ResetTextColor() { this.TextColor = Color.Empty; } private Font _Font = null; /// /// Indicates the text font. /// [DefaultValue(null), Category("Appearance"), Description("Indicates the text font.")] public Font Font { get { return _Font; } set { if (value != _Font) { Font oldValue = _Font; _Font = value; OnFontChanged(oldValue, value); } } } /// /// Called when Font property has changed. /// /// Old property value /// New property value protected virtual void OnFontChanged(Font oldValue, Font newValue) { OnPropertyChanged(new PropertyChangedEventArgs("Font")); } private BorderPattern _BorderPattern = new BorderPattern(); /// /// Indicates the border line pattern. /// [Category("Appearance"), Description("Indicates the border line pattern.")] public BorderPattern BorderPattern { get { return _BorderPattern; } set { if (value != _BorderPattern) { BorderPattern oldValue = _BorderPattern; _BorderPattern = value; OnBorderPatternChanged(oldValue, value); } } } [EditorBrowsable(EditorBrowsableState.Never)] public bool ShouldSerializeBorderPattern() { return !_BorderPattern.IsEmpty; } [EditorBrowsable(EditorBrowsableState.Never)] public void ResetBorderPattern() { this.BorderPattern = new BorderPattern(); } /// /// Called when BorderPattern property has changed. /// /// Old property value /// New property value protected virtual void OnBorderPatternChanged(BorderPattern oldValue, BorderPattern newValue) { if (oldValue != null) oldValue.PropertyChanged -= BorderPatternPropertyChanged; if (newValue != null) newValue.PropertyChanged += BorderPatternPropertyChanged; OnPropertyChanged(new PropertyChangedEventArgs("BorderPattern")); } private void BorderPatternPropertyChanged(object sender, PropertyChangedEventArgs e) { OnPropertyChanged(new PropertyChangedEventArgs("BorderPattern" + e.PropertyName)); } private BorderColors _BorderColors = new BorderColors(); /// /// Gets or sets the border color. /// [Category("Appearance"), Description("Indicates border color.")] public BorderColors BorderColors { get { return _BorderColors; } set { _BorderColors = value; OnPropertyChanged(new PropertyChangedEventArgs("BorderColors")); } } /// /// Gets whether property should be serialized. /// [EditorBrowsable(EditorBrowsableState.Never)] public bool ShouldSerializeBorderColors() { return !_BorderColors.IsEmpty; } /// /// Resets property to its default value. /// [EditorBrowsable(EditorBrowsableState.Never)] public void ResetBorderColors() { this.BorderColors = new BorderColors(); } private Thickness _BorderThickness = new Thickness(); /// /// Indicates the border thickness. /// [Category("Appearance"), Description("Indicates the border thickness")] public Thickness BorderThickness { get { return _BorderThickness; } set { if (value != _BorderThickness) { Thickness oldValue = _BorderThickness; _BorderThickness = value; OnBorderThicknessChanged(oldValue, value); } } } [EditorBrowsable(EditorBrowsableState.Never)] public bool ShouldSerializeBorderThickness() { return _BorderThickness.Bottom != 0 || _BorderThickness.Top != 0 || _BorderThickness.Left != 0 || _BorderThickness.Right != 0; } [EditorBrowsable(EditorBrowsableState.Never)] public void ResetBorderThickness() { _BorderThickness = new Thickness(0); } /// /// Called when BorderThickness property has changed. /// /// Old property value /// New property value protected virtual void OnBorderThicknessChanged(Thickness oldValue, Thickness newValue) { OnPropertyChanged(new PropertyChangedEventArgs("BorderThickness")); } private Padding _Margin = new Padding(0); /// /// Gets or sets spacing between the edge of the item and the border and background. This does not influence the actual layout or size of the item rather applies to rendering of the style only. /// [Browsable(true), Category("Appearance"), Description("Indicates spacing between the edge of the item and the border and background. This does not influence the actual layout or size of the item rather applies to rendering of the style only."), DesignerSerializationVisibility(DesignerSerializationVisibility.Content)] public Padding Margin { get { return _Margin; } set { if (_Margin != value) { Padding oldValue = _Margin; _Margin = value; OnMarginChanged(oldValue, value); } } } [EditorBrowsable(EditorBrowsableState.Never)] public bool ShouldSerializeMargin() { return _Margin.Bottom != 0 || _Margin.Top != 0 || _Margin.Left != 0 || _Margin.Right != 0; } [EditorBrowsable(EditorBrowsableState.Never)] public void ResetMargin() { _Margin = new Padding(0); } /// /// Called when Margin property has changed. /// /// Old property value /// New property value protected virtual void OnMarginChanged(Padding oldValue, Padding newValue) { OnPropertyChanged(new PropertyChangedEventArgs("Margin")); } #endregion #region IDisposable Members protected virtual void OnDispose() { } public void Dispose() { OnDispose(); } #endregion #region INotifyPropertyChanged Members /// /// Raises the PropertyChanged event. /// /// Provides event arguments. protected virtual void OnPropertyChanged(PropertyChangedEventArgs e) { PropertyChangedEventHandler handler = PropertyChanged; if (handler != null) handler(this, e); } /// /// Occurs when property on object has changed. /// [Description("Occurs when property on object has changed.")] public event PropertyChangedEventHandler PropertyChanged; #endregion } }