using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.ComponentModel;
using System.Windows.Forms;
namespace DevComponents.DotNetBar
{
    /// 
    /// Manages whether ambient property settings (BackColor, ForeColor etc.) are applied to child controls of the form when StyleManager component changes style.
    /// 
    [ToolboxBitmap(typeof(StyleManagerAmbient), "StyleManager.ico"), ToolboxItem(true)]
    [ProvideProperty("EnableAmbientSettings", typeof(Control))]
    public class StyleManagerAmbient : Component, IExtenderProvider
    {
        #region Constructor
        /// 
        /// Initializes a new instance of the StyleManagerAmbient class.
        /// 
        public StyleManagerAmbient()
        {
            StyleManager.RegisterAmbientManager(this);
        }
        /// 
        /// Initializes a new instance of the StyleManagerAmbient class with the specified container.
        /// 
        /// An IContainer that represents the container for the command.
        public StyleManagerAmbient(IContainer container)
            : this()
        {
            container.Add(this);
        }
        protected override void Dispose(bool disposing)
        {
            StyleManager.UnregisterAmbientManager(this);
            base.Dispose(disposing);
        }
        #endregion
        #region Implementation
        private Dictionary _Settings = new Dictionary();
        /// 
        /// Gets ambient settings StyleManager is allowed to change on the control.
        /// 
        [DefaultValue(eAmbientSettings.All), Description("Indicates ambient settings StyleManager is allowed to change on the control.")]
        [System.ComponentModel.Editor("DevComponents.DotNetBar.Design.FlagEnumUIEditor, DevComponents.DotNetBar.Design, Version=14.1.0.37, Culture=neutral,  PublicKeyToken=90f470f34c89ccaf", typeof(System.Drawing.Design.UITypeEditor))]
        public eAmbientSettings GetEnableAmbientSettings(Control c)
        {
            eAmbientSettings settings = eAmbientSettings.All;
            if (_Settings.TryGetValue(c, out settings))
                return settings;
            return eAmbientSettings.All;
        }
        /// 
        /// Sets the ambient settings StyleManager is allowed to change on component.
        /// 
        /// Reference to supported component.
        /// Ambient settings that StyleManager may change.
        public void SetEnableAmbientSettings(Control c, eAmbientSettings ambientSettings)
        {
            if (_Settings.ContainsKey(c))
            {
                if (ambientSettings == eAmbientSettings.All)
                    _Settings.Remove(c);
                else
                    _Settings[c] = ambientSettings;
            }
            else if (ambientSettings != eAmbientSettings.All)
            {
                _Settings.Add(c, ambientSettings);
            }
        }
        internal bool Contains(Control c)
        {
            return _Settings.ContainsKey(c);
        }
        #endregion
        #region IExtenderProvider Members
        public bool CanExtend(object extendee)
        {
            if (extendee is Control)
                return true;
            return false;
        }
        #endregion
    }
    /// 
    /// Specifies ambient settings enabled on the control for StyleManager.
    /// 
    [Flags]
    public enum eAmbientSettings
    {
        /// 
        /// All ambient settings are allowed to change.
        /// 
        All = BackColor | ForeColor | ChildControls,
        /// 
        /// StyleManager cannot change ambient settings.
        /// 
        None = 0,
        /// 
        /// StyleManager should process child controls.
        /// 
        ChildControls = 1,
        /// 
        /// StyleManager should change BackColor.
        /// 
        BackColor = 2,
        /// 
        /// StyleManager should change ForeColor.
        /// 
        ForeColor = 4
    }
}