namespace InstrumentationControls
{
	using System.ComponentModel;
    using System.Drawing;

    [ToolboxBitmap(typeof(SkinButton))]
    public class SkinButton : MultimediaButtonBase
    {
        private Image disabledImage = null;
        private Image hoverImage = null;
        private ImageMode imageMode = InstrumentationControls.ImageMode.Stretch;
        private SkinButton masterButton = null;
        private Image normalImage = null;
        private Image pushedDisabledImage = null;
        private Image pushedHoverImage = null;
        private Image pushedImage = null;

        protected override void Draw(Graphics g, Rectangle r)
        {
            base.Draw(g, r);
            Rectangle rect = this.DisplayRectangle;
            rect.Width--;
            rect.Height--;
            this.PaintSkinnedButton(g, rect);
        }

        private void PaintSkinnedButton(Graphics g, Rectangle rect)
        {
            Image normalImage = this.NormalImage;
            if (base.Enabled)
            {
                if (base.Highlighted && (this.HoverImage != null))
                {
                    normalImage = this.HoverImage;
                }
                if (base.Pressed && (this.PushedImage != null))
                {
                    normalImage = this.PushedImage;
                }
                if ((base.Pressed && base.Highlighted) && (this.PushedHoverImage != null))
                {
                    normalImage = this.PushedHoverImage;
                }
            }
            else
            {
                if (this.DisabledImage != null)
                {
                    normalImage = this.DisabledImage;
                }
                if (base.Pressed && (this.PushedDisabledImage != null))
                {
                    normalImage = this.PushedDisabledImage;
                }
            }
            if (normalImage != null)
            {
                if (this.ImageMode == InstrumentationControls.ImageMode.Stretch)
                {
                    g.DrawImage(normalImage, rect);
                }
                else
                {
                    int num = (base.Width / 2) - (normalImage.Width / 2);
                    int num2 = (base.Height / 2) - (normalImage.Height / 2);
                    g.DrawImageUnscaled(normalImage, num, num2);
                }
            }
            base.DrawCaption(g, rect);
        }

        [EditorBrowsable(EditorBrowsableState.Never)]
        public bool ShouldSerializeDisabledImage()
        {
            return ((this.disabledImage != null) && (this.masterButton == null));
        }

        [EditorBrowsable(EditorBrowsableState.Never)]
        public bool ShouldSerializeHoverImage()
        {
            return ((this.hoverImage != null) && (this.masterButton == null));
        }

        [EditorBrowsable(EditorBrowsableState.Never)]
        public bool ShouldSerializeNormalImage()
        {
            return ((this.normalImage != null) && (this.masterButton == null));
        }

        [EditorBrowsable(EditorBrowsableState.Never)]
        public bool ShouldSerializePushedDisabledImage()
        {
            return ((this.pushedDisabledImage != null) && (this.masterButton == null));
        }

        [EditorBrowsable(EditorBrowsableState.Never)]
        public bool ShouldSerializePushedHoverImage()
        {
            return ((this.pushedHoverImage != null) && (this.masterButton == null));
        }

        [EditorBrowsable(EditorBrowsableState.Never)]
        public bool ShouldSerializePushedImage()
        {
            return ((this.pushedImage != null) && (this.masterButton == null));
        }

        [Description("Image for disabled state"), Category("Skin")]
        public Image DisabledImage
        {
            get
            {
                if (this.masterButton == null)
                {
                    return this.disabledImage;
                }
                return this.masterButton.disabledImage;
            }
            set
            {
                if (this.disabledImage != value)
                {
                    this.disabledImage = value;
                    base.Invalidate();
                }
            }
        }

        [Description("Image for hover state"), Category("Skin")]
        public Image HoverImage
        {
            get
            {
                if (this.masterButton == null)
                {
                    return this.hoverImage;
                }
                return this.masterButton.hoverImage;
            }
            set
            {
                if (this.hoverImage != value)
                {
                    this.hoverImage = value;
                    base.Invalidate();
                }
            }
        }

        [DefaultValue(0)]
        public ImageMode ImageMode
        {
            get
            {
                return this.imageMode;
            }
            set
            {
                this.imageMode = value;
                base.Invalidate();
            }
        }

        [DefaultValue((string) null), Category("Appearance")]
        public SkinButton MasterButton
        {
            get
            {
                return this.masterButton;
            }
            set
            {
                if (((this.masterButton != value) && (this.masterButton != this)) && ((this.masterButton == null) || (this.masterButton.MasterButton == null)))
                {
                    this.masterButton = value;
                    base.Invalidate();
                }
            }
        }

        [Description("Image for normal state."), Category("Skin")]
        public Image NormalImage
        {
            get
            {
                if (this.masterButton == null)
                {
                    return this.normalImage;
                }
                return this.masterButton.NormalImage;
            }
            set
            {
                if (this.normalImage != value)
                {
                    this.normalImage = value;
                    base.Invalidate();
                }
            }
        }

        [Category("Skin"), Description("Image for PushedDisabled state")]
        public Image PushedDisabledImage
        {
            get
            {
                if (this.masterButton == null)
                {
                    return this.pushedDisabledImage;
                }
                return this.masterButton.PushedDisabledImage;
            }
            set
            {
                if (this.pushedDisabledImage != value)
                {
                    this.pushedDisabledImage = value;
                    base.Invalidate();
                }
            }
        }

        [Category("Skin"), Description("Image for pushed state")]
        public Image PushedHoverImage
        {
            get
            {
                if (this.masterButton == null)
                {
                    return this.pushedHoverImage;
                }
                return this.masterButton.pushedHoverImage;
            }
            set
            {
                if (this.pushedHoverImage != value)
                {
                    this.pushedHoverImage = value;
                    base.Invalidate();
                }
            }
        }

        [Description("Image for pushed state"), Category("Skin")]
        public Image PushedImage
        {
            get
            {
                if (this.masterButton == null)
                {
                    return this.pushedImage;
                }
                return this.masterButton.pushedImage;
            }
            set
            {
                if (this.pushedImage != value)
                {
                    this.pushedImage = value;
                    base.Invalidate();
                }
            }
        }
    }
}
