using System.ComponentModel;
using System.Drawing;
namespace DevComponents.DotNetBar.SuperGrid.Style
{
    /// 
    /// Represents the visual style of a Row.
    /// 
    [ToolboxItem(false), DesignTimeVisible(false)]
    [TypeConverter(typeof(BlankExpandableObjectConverter))]
    public class BaseRowHeaderVisualStyle : BaseVisualStyle
    {
        #region Static data
        ///
        /// Empty
        ///
        public static BaseRowHeaderVisualStyle Empty
        {
            get { return (new BaseRowHeaderVisualStyle()); }
        }
        #endregion
        #region Private variables
        private Background _Background;
        private Color _BorderHighlightColor = Color.Empty;
        private Font _Font;
        private Color _TextColor = Color.Empty;
        private Tbool _AllowWrap = Tbool.NotSet;
        private Alignment _TextAlignment = Alignment.NotSet;
        #endregion
        #region Public properties
        #region AllowWrap
        /// 
        /// Gets or sets whether text wrapping is permitted
        /// 
        [DefaultValue(Tbool.NotSet), Category("Appearance")]
        [Description("Indicates whether text wrapping is permitted.")]
        public Tbool AllowWrap
        {
            get { return (_AllowWrap); }
            set
            {
                if (_AllowWrap != value)
                {
                    _AllowWrap = value;
                    OnPropertyChangedEx("AllowWrap", VisualChangeType.Render);
                }
            }
        }
        #endregion
        #region Background
        /// 
        /// Gets or sets the style background.
        /// 
        [Description("Indicates whether 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);
                }
            }
        }
        /// 
        /// Gets whether property should be serialized.
        /// 
        [EditorBrowsable(EditorBrowsableState.Never)]
        private bool ShouldSerializeBackground()
        {
            return (_Background != null && _Background.IsEmpty == false);
        }
        /// 
        /// Resets property to its default value.
        /// 
        [EditorBrowsable(EditorBrowsableState.Never)]
        private void ResetBackground()
        {
            Background = null;
        }
        #endregion
        #region BorderHighlightColor
        /// 
        /// Gets or sets the border Highlight color.
        /// 
        [Description("Indicates whether the border Highlight color")]
        public Color BorderHighlightColor
        {
            get { return (_BorderHighlightColor); }
            set
            {
                if (_BorderHighlightColor != value)
                {
                    _BorderHighlightColor = value;
                    OnPropertyChangedEx("BorderHighlightColor", VisualChangeType.Render);
                }
            }
        }
        /// 
        /// Gets whether property should be serialized.
        /// 
        [EditorBrowsable(EditorBrowsableState.Never)]
        private bool ShouldSerializeBorderHighlightColor()
        {
            return (_BorderHighlightColor.IsEmpty == false);
        }
        /// 
        /// Resets property to its default value.
        /// 
        [EditorBrowsable(EditorBrowsableState.Never)]
        private void ResetBorderHighlightColor()
        {
            _BorderHighlightColor = Color.Empty;
        }
        #endregion
        #region Font
        /// 
        /// Gets or sets the style Font.
        /// 
        [DefaultValue(null)]
        [Description("Indicates the RowHeader Font")]
        public Font Font
        {
            get { return (_Font); }
            set
            {
                if (_Font != value)
                {
                    _Font = value;
                    OnPropertyChangedEx("Font", VisualChangeType.Layout);
                }
            }
        }
        #endregion
        #region IsEmpty
        ///
        /// IsEmpty
        ///
        [Browsable(false)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public override bool IsEmpty
        {
            get
            {
                return ((_Background == null || _Background.IsEmpty) &&
                        _BorderHighlightColor == Color.Empty &&
                        _Font == null && TextColor == Color.Empty && base.IsEmpty);
            }
        }
        #endregion
        #region TextAlignment
        /// 
        /// Gets or sets the alignment of the header text
        /// 
        [DefaultValue(Alignment.NotSet), Category("Appearance")]
        [Description("Indicates the alignment of the header text.")]
        public Alignment TextAlignment
        {
            get { return (_TextAlignment); }
            set
            {
                if (_TextAlignment != value)
                {
                    _TextAlignment = value;
                    OnPropertyChangedEx("TextAlignment", VisualChangeType.Render);
                }
            }
        }
        #endregion
        #region TextColor
        /// 
        /// Gets or sets the Text color
        /// 
        [Description("Indicates the Text color")]
        public Color TextColor
        {
            get { return (_TextColor); }
            set
            {
                if (_TextColor != value)
                {
                    _TextColor = value;
                    OnPropertyChangedEx("TextColor", VisualChangeType.Render);
                }
            }
        }
        /// 
        /// Gets whether property should be serialized.
        /// 
        [EditorBrowsable(EditorBrowsableState.Never)]
        private bool ShouldSerializeTextColor()
        {
            return (_TextColor.IsEmpty == false);
        }
        /// 
        /// Resets property to its default value.
        /// 
        [EditorBrowsable(EditorBrowsableState.Never)]
        private void ResetTextColor()
        {
            _TextColor = Color.Empty;
        }
        #endregion
        #endregion
        #region GetTextFormatFlags
        internal eTextFormat GetTextFormatFlags()
        {
            eTextFormat tf = eTextFormat.WordEllipsis |
                eTextFormat.NoPadding | eTextFormat.NoPrefix;
            if (AllowWrap == Tbool.True)
                tf |= eTextFormat.WordBreak;
            switch (TextAlignment)
            {
                case Alignment.TopCenter:
                    tf |= eTextFormat.HorizontalCenter;
                    break;
                case Alignment.TopRight:
                    tf |= eTextFormat.Right;
                    break;
                case Alignment.MiddleLeft:
                    tf |= eTextFormat.VerticalCenter;
                    break;
                case Alignment.NotSet:
                case Alignment.MiddleCenter:
                    tf |= eTextFormat.HorizontalCenter;
                    tf |= eTextFormat.VerticalCenter;
                    break;
                case Alignment.MiddleRight:
                    tf |= eTextFormat.Right;
                    tf |= eTextFormat.VerticalCenter;
                    break;
                case Alignment.BottomLeft:
                    tf |= eTextFormat.Bottom;
                    break;
                case Alignment.BottomCenter:
                    tf |= eTextFormat.Bottom;
                    tf |= eTextFormat.HorizontalCenter;
                    break;
                case Alignment.BottomRight:
                    tf |= eTextFormat.Bottom;
                    tf |= eTextFormat.Right;
                    break;
            }
            return (tf);
        }
        #endregion
        #region ApplyStyle
        /// 
        /// Applies the style to instance of this style.
        /// 
        /// Style to apply.
        public void ApplyStyle(BaseRowHeaderVisualStyle style)
        {
            if (style != null)
            {
                base.ApplyStyle(style);
                if (style.Font != null)
                    _Font = style.Font;
                if (style.TextColor.IsEmpty == false)
                    _TextColor = style._TextColor;
                if (style.Background != null && style.Background.IsEmpty == false)
                    Background = style.Background.Copy();
                if (style.BorderHighlightColor.IsEmpty == false)
                    BorderHighlightColor = style.BorderHighlightColor;
                if (style.AllowWrap != Tbool.NotSet)
                    _AllowWrap = style.AllowWrap;
                if (style.TextAlignment != Alignment.NotSet)
                    _TextAlignment = style.TextAlignment;
            }
        }
        #endregion
        #region Copy
        /// 
        /// Returns the copy of the style.
        /// 
        /// Copy of the style.
        public new BaseRowHeaderVisualStyle Copy()
        {
            BaseRowHeaderVisualStyle style = new BaseRowHeaderVisualStyle();
            CopyTo(style);
            return (style);
        }
        #endregion
        #region CopyTo
        /// 
        /// Returns the copy of the style.
        /// 
        /// Copy of the style.
        public void CopyTo(BaseRowHeaderVisualStyle copy)
        {
            base.CopyTo(copy);
            if (_Font != null)
                copy.Font = (Font)_Font.Clone();
            if (_TextColor.IsEmpty == false)
                copy.TextColor = _TextColor;
            copy.BorderHighlightColor = BorderHighlightColor;
            if (_Background != null)
                copy.Background = _Background.Copy();
            copy.TextAlignment = _TextAlignment;
            copy.AllowWrap = _AllowWrap;
        }
        #endregion
        #region IDisposable
        /// 
        /// Dispose
        /// 
        public override void Dispose()
        {
            Background = null;
            base.Dispose();
        }
        #endregion
    }
}