using System;
using System.Windows.Forms;
using System.ComponentModel;
using FastReport.Utils;

namespace FastReport.Controls
{
#if !DEBUG
    [DesignTimeVisible(false)]
#endif
    internal class TypeListBox : ListBox
    {
        protected override void OnDrawItem(DrawItemEventArgs e)
        {
            e.DrawBackground();
            if (e.Index >= 0)
            {
                Type type = Items[e.Index] as Type;
                this.DrawImageAndText(e, this.GetImage(DataTreeHelper.GetTypeImageIndex(type)), type.Name);
            }
        }

        public void UpdateDpiDependencies(Control owner)
        {
            Font = owner.LogicalToDevice(DrawUtils.DefaultFont);
            ItemHeight = owner.LogicalToDevice(16);
        }

        public TypeListBox()
        {
            Type[] types = new Type[] {
                typeof(Boolean),
                typeof(Byte),
                typeof(Char),
                typeof(DateTime),
                typeof(Decimal),
                typeof(Double),
                typeof(Int16),
                typeof(Int32),
                typeof(Int64),
                typeof(SByte),
                typeof(Single),
                typeof(String),
                typeof(TimeSpan),
                typeof(UInt16),
                typeof(UInt32),
                typeof(UInt64),
                typeof(Byte[]) };
            DrawMode = DrawMode.OwnerDrawFixed;
            Items.AddRange(types);
        }
    }
}
