#region COPYRIGHT
//
//     THIS IS GENERATED BY TEMPLATE
//     
//     AUTHOR  :     ROYE
//     DATE       :     2010
//
//     COPYRIGHT (C) 2010, TIANXIAHOTEL TECHNOLOGIES CO., LTD. ALL RIGHTS RESERVED.
//
#endregion

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Security.Permissions;

namespace System.Windows.Forms
{
    [
    ToolboxBitmap(typeof(System.Windows.Forms.ComboBox)), 
    ToolboxItem(false), 
    ToolboxItemFilter("System.Windows.Forms"), 
    Description("Displays an editable text box with a drop-down list of permitted values.")
    ]
    public partial class PopupComboBox : ComboBox
    {
        protected Popup PopupDropDown;
        private Control _DropDownControl;

        public PopupComboBox()
        {
            InitializeComponent();
            base.DropDownHeight = base.DropDownWidth = 1;
            base.IntegralHeight = false;
        }

        public PopupComboBox(IContainer container)
        {
            container.Add(this);
            InitializeComponent();
        }

        public void ShowDropDown()
        {
            if (PopupDropDown != null)
            {
                PopupDropDown.Show(this);
                PopupDropDown.BringToFront();
            }
        }

        public void HideDropDown()
        {
            if (PopupDropDown != null)
            {
                PopupDropDown.Hide();
            }
        }

        [SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.UnmanagedCode)]
        protected override void WndProc(ref Message m)
        {
            if (m.Msg == (Popup.NativeMethods.WM_REFLECT + Popup.NativeMethods.WM_COMMAND))
            {
                if (Popup.NativeMethods.HIWORD(m.WParam) == Popup.NativeMethods.CBN_DROPDOWN)
                {
                    TimeSpan TimeSpan = DateTime.Now.Subtract(PopupDropDown.LastClosedTimeStamp);
                    if (TimeSpan.TotalMilliseconds > 500)
                        ShowDropDown();
                    return;
                }
            }
            base.WndProc(ref m);
        }

        [
        Browsable(false), 
        DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), 
        EditorBrowsable(EditorBrowsableState.Never)
        ]
        public new int DropDownWidth
        {
            get { return base.DropDownWidth; }
            set { base.DropDownWidth = value; }
        }

        [
        Browsable(true), 
        DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), 
        EditorBrowsable(EditorBrowsableState.Never)
        ]
        public new int DropDownHeight
        {
            get { return base.DropDownHeight; }
            set
            {
                PopupDropDown.Height = value;
                base.DropDownHeight = value;
            }
        }

        [
        Browsable(false), 
        DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), 
        EditorBrowsable(EditorBrowsableState.Never)
        ]
        public new bool IntegralHeight
        {
            get { return base.IntegralHeight; }
            set { base.IntegralHeight = value; }
        }

        [
        Browsable(false), 
        DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), 
        EditorBrowsable(EditorBrowsableState.Never)
        ]
        public new ObjectCollection Items
        {
            get { return base.Items; }
        }

        [
        Browsable(false), 
        DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), 
        EditorBrowsable(EditorBrowsableState.Never)
        ]
        public new int ItemHeight
        {
            get { return base.ItemHeight; }
            set { base.ItemHeight = value; }
        }

        public Control DropDownControl
        {
            get
            {
                return _DropDownControl;
            }
            set
            {
                if (_DropDownControl == value)
                    return;
                _DropDownControl = value;
                PopupDropDown = new Popup(value);
            }
        }
    }
}
