using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.Drawing;
using System.Windows.Forms;

namespace DockableUI.Tabs
{
    [ToolboxItem(true)]
    public class TabButton : ToolStripButton
    {
        public DockingForm AssignedControl;

        //public event EventHandler MouseDragAway;

        //private Point mouseDownPosition;
        private bool isMouseDown = false;

        public ContextMenuStrip ContextMenuStrip { get; set; }

        protected override void OnMouseDown(MouseEventArgs e)
        {
            //mouseDownPosition = e.Location;
            base.OnMouseDown(e);
            if (e.Button == MouseButtons.Right)
            {
                isMouseDown = true;
            }
        }

        protected override void OnMouseUp(MouseEventArgs e)
        {
            base.OnMouseUp(e);
            if (e.Button == MouseButtons.Right)
            {
                if (isMouseDown && ContextMenuStrip != null)
                {
                    ContextMenuStrip.Show(Parent.PointToScreen(e.Location));
                }
            isMouseDown = false;
            }
        }

        //protected override void OnMouseMove(MouseEventArgs mea)
        //{
        //    base.OnMouseMove(mea);
        //    if (mea.Button == MouseButtons.Left && isMouseDown && mea.Location != mouseDownPosition)
        //    {
        //        MouseDragAway(this, EventArgs.Empty);
        //    }
        //}

        public new Boolean Checked
        {
            get { return base.Checked; }
            set
            {
                if (value)
                {
                    base.Overflow = ToolStripItemOverflow.Never;
                }
                else
                {
                    base.Overflow = ToolStripItemOverflow.AsNeeded;
                }
                base.Checked = value;
            }
        }
    }
}
