
namespace GMLC01HerramientasCad.Logica
{
    using System;
    using System.Windows.Forms;
    using GMLC01HerramientasCad.Logica;

    /// <summary>
    /// 
    /// </summary>
    public partial class BaseForm : Form, ILocalizable 
    {
        private bool loaded;

        /// <summary>
        /// 
        /// </summary>
        public BaseForm()
        {
            try
            {
                InitializeComponent();
                Localizador.Instance.CulturaChanged += delegate { this.DoActualizarIdiomaInterfaz(); };
            }
            catch (Exception e)
            {
                Log.RegisterError(e);
                throw new ExcepcionGMLC(e.Message, e);
            }
        }
        /// <summary>
        /// 
        /// </summary>
        protected static string NombreCultura
        {
            get
            {
                return Localizador.Instance.NombreCultura;
            }

            set
            {
                Localizador.Instance.NombreCultura = value;
            }
        }
        /// <summary>
        /// 
        /// </summary>
        public virtual void ActualizarIdiomaInterfaz()
        {
            try
            {

            }
            catch (Exception e)
            {
                Log.RegisterError(e);
                throw new ExcepcionGMLC(e.Message, e);
            }
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="e"></param>
        protected override void OnLoad(EventArgs e)
        {
            this.loaded = true;

            this.ActualizarIdiomaInterfaz();

            base.OnLoad(e);

        }

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

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

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