using System;
using System.Text;
using System.Drawing;
using System.ComponentModel;
using System.Windows.Forms;
namespace DevComponents.DotNetBar.Controls
{
    /// 
    /// Represents the stand-alone progress bar control.
    /// 
    [ToolboxBitmap(typeof(ProgressBarX), "Controls.ProgressBarX.ico"), ToolboxItem(true), DefaultEvent("Click"), System.Runtime.InteropServices.ComVisible(false)]
    public class ProgressBarX : BaseItemControl
    {
        #region Private Variables
        private ProgressBarItem m_ProgressBar = null;
        #endregion
        #region Constructor, Dispose
        public ProgressBarX()
        {
            m_ProgressBar = new ProgressBarItem();
            m_ProgressBar.Style = eDotNetBarStyle.Office2007;
            m_ProgressBar.Minimum = 0;
            m_ProgressBar.Maximum = 100;
            m_ProgressBar.Value = 0;
            m_ProgressBar.BackStyle = this.BackgroundStyle;
            this.HostItem = m_ProgressBar;
        }
        #endregion
        #region Internal Implementation
        protected override void PaintBackground(PaintEventArgs e)
        {
            // ProgressBarItem shares same background style as control so it will paint itself. This avoids double painting...
            Graphics g = e.Graphics;
            Rectangle r = this.ClientRectangle;
            ElementStyle style = this.GetBackgroundStyle();
            if ((!style.Custom || style.BackColor.IsEmpty)&& !this.BackColor.IsEmpty && this.BackColor!=Color.Transparent)
            {
                DisplayHelp.FillRectangle(g, r, this.BackColor);
            }
        }
        /// 
        /// Gets or sets the maximum value of the range of the control.
        /// 
        [Browsable(true), Description("Gets or sets the maximum value of the range of the control."), Category("Behavior"), DefaultValue(100)]
        public int Maximum
        {
            get
            {
                return m_ProgressBar.Maximum;
            }
            set
            {
                m_ProgressBar.Maximum = value;
            }
        }
        /// 
        /// Gets or sets the minimum value of the range of the control.
        /// 
        [DevCoBrowsable(true), Browsable(true), Description("Gets or sets the minimum value of the range of the control."), Category("Behavior"), DefaultValue(0)]
        public int Minimum
        {
            get
            {
                return m_ProgressBar.Minimum;
            }
            set
            {
                m_ProgressBar.Minimum = value;
            }
        }
        /// 
        /// Gets or sets the current position of the progress bar.
        /// 
        [DevCoBrowsable(true), Browsable(true), Description("Gets or sets the current position of the progress bar."), Category("Behavior"), DefaultValue(0)]
        public int Value
        {
            get { return m_ProgressBar.Value; }
            set
            {
                m_ProgressBar.Value = value;
                //this.Invalidate();
                //this.Update();
            }
        }
        /// 
        /// Gets or sets the amount by which a call to the PerformStep method increases the current position of the progress bar.
        /// 
        [DevCoBrowsable(true), Browsable(true), Description("Gets or sets the amount by which a call to the PerformStep method increases the current position of the progress bar."), Category("Behavior"), DefaultValue(1)]
        public int Step
        {
            get
            {
                return m_ProgressBar.Step;
            }
            set
            {
                m_ProgressBar.Step = value;
            }
        }
        /// 
        /// Advances the current position of the progress bar by the amount of the Step property.
        /// 
        public void PerformStep()
        {
            this.Value += m_ProgressBar.Step;
        }
        /// 
        /// Advances the current position of the progress bar by the specified amount.
        /// 
        /// The amount by which to increment the progress bar's current position. 
        public void Increment(int value)
        {
            this.Value += value;
        }
        /// 
        /// Gets or sets the color of the progress chunk.
        /// 
        [Browsable(true), DevCoBrowsable(true), Category("Appearance"), Description("Gets or sets the color of the progress chunk.")]
        public Color ChunkColor
        {
            get
            {
                return m_ProgressBar.ChunkColor;
            }
            set
            {
                m_ProgressBar.ChunkColor = value;
                this.Invalidate();
            }
        }
        /// 
        /// Gets whether ChunkColor property should be serialized.
        /// 
        [EditorBrowsable(EditorBrowsableState.Never)]
        public bool ShouldSerializeChunkColor()
        {
            return (!m_ProgressBar.ChunkColor.IsEmpty);
        }
        /// 
        /// Resets the ChunkColor property to its default value.
        /// 
        [EditorBrowsable(EditorBrowsableState.Never)]
        public void ResetChunkColor()
        {
            m_ProgressBar.ChunkColor = Color.Empty;
        }
        /// 
        /// Gets or sets the target gradient color of the progress chunk.
        /// 
        [Browsable(true), DevCoBrowsable(true), Category("Appearance"), Description("Gets or sets the target gradient color of the progress chunk.")]
        public Color ChunkColor2
        {
            get
            {
                return m_ProgressBar.ChunkColor2;
            }
            set
            {
                m_ProgressBar.ChunkColor2 = value;
                this.Invalidate();
            }
        }
        /// 
        /// Gets whether ChunkColor property should be serialized.
        /// 
        [EditorBrowsable(EditorBrowsableState.Never)]
        public bool ShouldSerializeChunkColor2()
        {
            return (!m_ProgressBar.ChunkColor2.IsEmpty);
        }
        /// 
        /// Resets the ChunkColor property to its default value.
        /// 
        [EditorBrowsable(EditorBrowsableState.Never)]
        public void ResetChunkColor2()
        {
            m_ProgressBar.ChunkColor2 = Color.Empty;
        }
        /// 
        /// Gets or sets the gradient angle of the progress chunk.
        /// 
        [Browsable(true), DevCoBrowsable(true), Category("Appearance"), Description("Gets or sets the gradient angle of the progress chunk."), DefaultValue(0)]
        public int ChunkGradientAngle
        {
            get
            {
                return (int)m_ProgressBar.ChunkGradientAngle;
            }
            set
            {
                m_ProgressBar.ChunkGradientAngle = value;
                this.Invalidate();
            }
        }
        /// 
        /// Gets or sets whether the text inside the progress bar is displayed.
        /// 
        [Browsable(true), Description("Gets or sets whether the text inside the progress bar is displayed."), Category("Behavior"), DefaultValue(false)]
        public bool TextVisible
        {
            get
            {
                return m_ProgressBar.TextVisible;
            }
            set
            {
                m_ProgressBar.TextVisible = value;
                this.Invalidate();
            }
        }
        /// 
        /// Gets or sets the type of progress bar used to indicate progress. The Standard style displays the progress based on Minimum, Maximum and current Value.
        /// The Marquee type is automatically moving progress bar that is used to indicate an ongoing operation for which the actual duration cannot be estimated.
        /// 
        [Browsable(true), Category("Behavior"), DefaultValue(eProgressItemType.Standard), Description("Indicates type of progress bar used to indicate progress.")]
        public eProgressItemType ProgressType
        {
            get { return m_ProgressBar.ProgressType; }
            set { m_ProgressBar.ProgressType = value; }
        }
        /// 
        /// Gets or sets the marquee animation speed in milliseconds.
        /// 
        [Browsable(true), DefaultValue(100), Category("Behavior"), Description("Indicates marquee animation speed in milliseconds.")]
        public int MarqueeAnimationSpeed
        {
            get { return m_ProgressBar.MarqueeAnimationSpeed; }
            set { m_ProgressBar.MarqueeAnimationSpeed = value; }
        }
        /// 
        /// Gets or sets the predefined color state table for progress bar. Color specified applies to items with Office 2007 style only. It does not have
        /// any effect on other styles. You can use ColorTable to indicate the state of the operation that Progress Bar is tracking. Default value is eProgressBarItemColor.Normal.
        /// 
        [Browsable(true), DevCoBrowsable(false), DefaultValue(eProgressBarItemColor.Normal), Category("Appearance"), Description("Indicates predefined color of item when Office 2007 style is used.")]
        public eProgressBarItemColor ColorTable
        {
            get { return m_ProgressBar.ColorTable; }
            set
            {
                m_ProgressBar.ColorTable = value;
            }
        }
        [DefaultValue(eOrientation.Horizontal)]
        public eOrientation Orientation
        {
            get { return m_ProgressBar.Orientation; }
            set
            {
                if (m_ProgressBar.Orientation != value)
                {
                    m_ProgressBar.Orientation = value;
                    this.Invalidate();
                }
            }
        }
        /// 
        /// Gets the underlying ProgressBarItem
        /// 
        internal ProgressBarItem ProgressBarItem
        {
            get { return (m_ProgressBar); }
        }
        #endregion
    }
}