using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DevExpress.Utils.Menu;
using System.Reflection;

namespace HaloControls
{
    public partial class Enum : UserControl
    {
        int SelectedIndex = 0;
        public int Index;
        public object Val;
        Type t;

        public Enum(string Description, string[] Options, object Value, int BitCount, int Index)
        {
            InitializeComponent();
            this.Index = Index;
            label1.Text = Description;
            Val = Value;
            SelectedIndex = (int)Value;
            dropDownButton1.Location = new Point((label1.Location.Y + label1.Size.Width) + 5, 5);

            if (BitCount == 8)
                t = typeof(byte);
            else if (BitCount == 16)
                t = typeof(short);
            else if (BitCount == 32)
                t = typeof(int);

            DXPopupMenu menu = new DXPopupMenu();
            for (int i = 0; i < Options.Length; i++)
            {
                menu.Items.Add(new DXMenuItem(Options[i].Replace("_", " ").Replace("OP", ""), Enum_Click));
                menu.Items[i].Tag = i;
            }
            try { dropDownButton1.Text = Options[SelectedIndex].Replace("_", " ").Replace("OP", ""); }
            catch { }
            dropDownButton1.DropDownControl = menu;
        }

        void Enum_Click(object sender, EventArgs e)
        {
            DXMenuItem item = (DXMenuItem)sender;
            SelectedIndex = (int)item.Tag;
            dropDownButton1.Text = item.Caption;
        }

        public void Reload(object Value)
        {
            //this.Info = Info;
            SelectedIndex = Convert.ToInt32(Value);
            DXPopupMenu menu = (DXPopupMenu)dropDownButton1.DropDownControl;
            try { dropDownButton1.Text = menu.Items[SelectedIndex].Caption; }
            catch { dropDownButton1.Text = ""; }
        }

        public object Save()
        {
            DXPopupMenu menu = (DXPopupMenu)dropDownButton1.DropDownControl;
            try { return menu.Items[SelectedIndex].Tag; }
            catch { return Val; }
        }
    }
}
