using System.ComponentModel;
using System.Drawing;
namespace DevComponents.DotNetBar.Charts.Style
{
    ///
    /// ScrollBarVisualStyle
    ///
    [TypeConverter(typeof(VisualStylesConverter))]
    public class ScrollBarVisualStyles : VisualStyles
    {
        #region Copy
        /// 
        /// Returns the copy of the style.
        /// 
        /// Copy of the style.
        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
    }
    /// 
    /// Represents the visual style of a ScrollBar element.
    /// 
    [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
        /// 
        /// Gets or sets the Background of the Increase/Decrease Arrow elements of the ScrollBar.
        /// 
        [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);
                }
            }
        }
        /// 
        /// Gets whether property should be serialized.
        /// 
        [EditorBrowsable(EditorBrowsableState.Never)]
        private bool ShouldSerializeArrowBackground()
        {
            return (_ArrowBackground != null && _ArrowBackground.IsEmpty == false);
        }
        /// 
        /// Resets property to its default value.
        /// 
        [EditorBrowsable(EditorBrowsableState.Never)]
        private void ResetArrowBackground()
        {
            ArrowBackground = null;
        }
        #endregion
        #region ArrowBorderColor
        /// 
        /// Gets or sets the Arrow Increase/Decrease border color.
        /// 
        [Description("Indicates the Arrow Increase/Decrease border color")]
        public Color ArrowBorderColor
        {
            get { return (_ArrowBorderColor); }
            set
            {
                if (value != _ArrowBorderColor)
                {
                    _ArrowBorderColor = value;
                    OnPropertyChangedEx("ArrowBorderColor", VisualChangeType.Render);
                }
            }
        }
        /// 
        /// Gets whether property should be serialized.
        /// 
        [EditorBrowsable(EditorBrowsableState.Never)]
        private bool ShouldSerializeArrowBorderColor()
        {
            return (_ArrowBorderColor.IsEmpty == false);
        }
        /// 
        /// Resets property to its default value.
        /// 
        [EditorBrowsable(EditorBrowsableState.Never)]
        private void ResetArrowBorderColor()
        {
            ArrowBorderColor = Color.Empty;
        }
        #endregion
        
        #region ArrowColor
        /// 
        /// Gets or sets the Color of the Increase/Decrease Arrow elements of the scrollBar.
        /// 
        [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);
                }
            }
        }
        /// 
        /// Gets whether property should be serialized.
        /// 
        [EditorBrowsable(EditorBrowsableState.Never)]
        private bool ShouldSerializeArrowColor()
        {
            return (_ArrowColor.IsEmpty == false);
        }
        /// 
        /// Resets property to its default value.
        /// 
        [EditorBrowsable(EditorBrowsableState.Never)]
        private void ResetArrowColor()
        {
            ArrowColor = Color.Empty;
        }
        #endregion
        #region BorderColor
        /// 
        /// Gets or sets the border color of the scrollBar.
        /// 
        [Description("Indicates the Border Color of the scrollBar")]
        public Color BorderColor
        {
            get { return (_BorderColor); }
            set
            {
                if (value != _BorderColor)
                {
                    _BorderColor = value;
                    OnPropertyChangedEx("BorderColor", VisualChangeType.Render);
                }
            }
        }
        /// 
        /// Gets whether property should be serialized.
        /// 
        [EditorBrowsable(EditorBrowsableState.Never)]
        private bool ShouldSerializeBorderColor()
        {
            return (_BorderColor.IsEmpty == false);
        }
        /// 
        /// Resets property to its default value.
        /// 
        [EditorBrowsable(EditorBrowsableState.Never)]
        private void ResetBorderColor()
        {
            BorderColor = Color.Empty;
        }
        #endregion
        #region NoAlphaOnMouseOver
        /// 
        /// Gets or sets whether color alpha values are ignored when the mouse is over the scrollbar.
        /// 
        [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
        /// 
        /// Gets or sets the Background of the Thumb element of the ScrollBar.
        /// 
        [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);
                }
            }
        }
        /// 
        /// Gets whether property should be serialized.
        /// 
        [EditorBrowsable(EditorBrowsableState.Never)]
        private bool ShouldSerializeThumbBackground()
        {
            return (_ThumbBackground != null && _ThumbBackground.IsEmpty == false);
        }
        /// 
        /// Resets property to its default value.
        /// 
        [EditorBrowsable(EditorBrowsableState.Never)]
        private void ResetThumbBackground()
        {
            ThumbBackground = null;
        }
        #endregion
        #region ThumbBorderColor
        /// 
        /// Gets or sets the Thumb border color.
        /// 
        [Description("Indicates the Thumb border color")]
        public Color ThumbBorderColor
        {
            get { return (_ThumbBorderColor); }
            set
            {
                if (value != _ThumbBorderColor)
                {
                    _ThumbBorderColor = value;
                    OnPropertyChangedEx("ThumbBorderColor", VisualChangeType.Render);
                }
            }
        }
        /// 
        /// Gets whether property should be serialized.
        /// 
        [EditorBrowsable(EditorBrowsableState.Never)]
        private bool ShouldSerializeThumbBorderColor()
        {
            return (_ThumbBorderColor.IsEmpty == false);
        }
        /// 
        /// Resets property to its default value.
        /// 
        [EditorBrowsable(EditorBrowsableState.Never)]
        private void ResetThumbBorderColor()
        {
            ThumbBorderColor = Color.Empty;
        }
        #endregion
        #region ThumbColor
        /// 
        /// Gets or sets the Color of the Thumb content element (hash marks) of the scrollBar.
        /// 
        [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);
                }
            }
        }
        /// 
        /// Gets whether property should be serialized.
        /// 
        [EditorBrowsable(EditorBrowsableState.Never)]
        private bool ShouldSerializeThumbColor()
        {
            return (_ThumbColor.IsEmpty == false);
        }
        /// 
        /// Resets property to its default value.
        /// 
        [EditorBrowsable(EditorBrowsableState.Never)]
        private void ResetThumbColor()
        {
            ThumbColor = Color.Empty;
        }
        #endregion
        #region TrackBackground
        /// 
        /// Gets or sets the Background of the Increase/Decrease Track elements of the ScrollBar.
        /// 
        [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);
                }
            }
        }
        /// 
        /// Gets whether property should be serialized.
        /// 
        [EditorBrowsable(EditorBrowsableState.Never)]
        private bool ShouldSerializeTrackBackground()
        {
            return (_TrackBackground != null && _TrackBackground.IsEmpty == false);
        }
        /// 
        /// Resets property to its default value.
        /// 
        [EditorBrowsable(EditorBrowsableState.Never)]
        private void ResetTrackBackground()
        {
            TrackBackground = null;
        }
        #endregion
        #region IsEmpty
        /// 
        /// Gets whether the style is logically Empty.
        /// 
        [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
        /// 
        /// Applies the style to instance of this style.
        /// 
        /// Style to apply.
        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
        /// 
        /// Returns the copy of the style.
        /// 
        /// Copy of the style.
        public new ScrollBarVisualStyle Copy()
        {
            ScrollBarVisualStyle style = new ScrollBarVisualStyle();
            CopyTo(style);
            return (style);
        }
        #endregion
        #region CopyTo
        /// 
        /// Returns the copy of the style.
        /// 
        /// Copy of the style.
        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
    }
}