namespace GMLL00ImportadorXsd.Presentacion
{
    using System;
    using System.Windows.Forms;
    using GMLL00ImportadorXsd.Utilidades.Localizacion;

    internal class BaseForm : Form, ILocalizable
    {
        private bool loaded;

        protected BaseForm()
        {
            /*
             * Nos suscribimos al evento de cambio de cultura.
             */
            Localizador.Instance.CulturaChanged += delegate { this.DoActualizarIdiomaInterfaz(); };
        }

        protected static string NombreCultura
        {
            get
            {
                return Localizador.Instance.NombreCultura;
            }

            set
            {
                Localizador.Instance.NombreCultura = value;
            }
        }

        public virtual void ActualizarIdiomaInterfaz()
        {
        }

        protected override void OnLoad(EventArgs e)
        {
            this.loaded = true;

            base.OnLoad(e);

            this.ActualizarIdiomaInterfaz();
        }

        private void DoActualizarIdiomaInterfaz()
        {
            if (this.loaded)
            {
                this.ActualizarIdiomaInterfaz();

                foreach (Control control in this.Controls)
                {
                    var localizableControl = control as ILocalizable;

                    if (localizableControl != null)
                    {
                        localizableControl.ActualizarIdiomaInterfaz();
                    }
                }
            }
        }

        private void InitializeComponent()
        {
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(BaseForm));
            this.SuspendLayout();
            // 
            // BaseForm
            // 
            this.ClientSize = new System.Drawing.Size(292, 269);
            this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
            this.Name = "BaseForm";
            this.ResumeLayout(false);

        }
    }
}