using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Design;
using System.Windows.Forms.Design;

namespace OliviaAddIn
{
    
    public partial class FormCampos : Form
    {
        //////////////////////////////////////////////////////////////
        //variables para los botones
        int top_buttons;
        int bottom_props;
        int right_props;
        //////////////////////////////////////////////////////////////
        /**
         * Clase para el tipo combo Sí/No de las propiedades
         */
        public class Prop_si_no : TypeConverter
        {
            public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
            {
                if (sourceType == typeof(string))
                    return true;
                return base.CanConvertFrom(context, sourceType);
            }

            public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
            {
                if (destinationType == typeof(string))
                    return true;
                return base.CanConvertTo(context, destinationType);
            }

            public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
            {
                if (value.GetType() == typeof(string))
                {
                    if (((string)value).ToLower() == "si")
                        return true;
                    if (((string)value).ToLower() == "no")
                        return false;
                    throw new Exception("Values must be \"Yes\" or \"No\"");
                }
                return base.ConvertFrom(context, culture, value);
            }

            public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType)
            {
                if (destinationType == typeof(string))
                {
                    if (value == null)
                        return false;
                    else
                        return (((bool)value) ? "Si" : "No");
                }
                return base.ConvertTo(context, culture, value, destinationType);
            }

            public override bool GetStandardValuesSupported(ITypeDescriptorContext context)
            {
                return true;
            }

            public override System.ComponentModel.TypeConverter.StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
            {
                bool[] bools = new bool[] { true, false };
                System.ComponentModel.TypeConverter.StandardValuesCollection svc = new System.ComponentModel.TypeConverter.StandardValuesCollection(bools);
                return svc;
            }

        }

        public FormCampos()
        {
            InitializeComponent();
            top_buttons = ClientSize.Height - button_guardar.Top;
            bottom_props = ClientSize.Height - propertyGrid.Bottom;
            right_props = ClientSize.Width - propertyGrid.Right;
        }

        protected virtual void button_guardar_Click(object sender, EventArgs e)
        {
            string err_str;
            if (!OliviaGlob.guarda_ini_gen(out err_str))
            {
                MessageBox.Show(err_str, "Olivia", MessageBoxButtons.OK, MessageBoxIcon.Error);                
            }
        }

        protected virtual void btn_acept_Click(object sender, EventArgs e)
        {

        }

        protected virtual void button_reset_Click(object sender, EventArgs e)
        {

        }

        private void FormCampos_Resize(object sender, EventArgs e)
        {
            //mover button_aceptar, button_reset, button_guardar, bottom del property
            button_guardar.Top = ClientSize.Height - top_buttons;
            button_reset.Top = ClientSize.Height - top_buttons;
            btn_acept.Top = ClientSize.Height - top_buttons;
            propertyGrid.Size = new Size(ClientSize.Width - right_props, ClientSize.Height - bottom_props);
        }
    }
}
