Esempio n. 1
0
        /// <summary>Raises the <see cref="E:System.Windows.Forms.Control.MouseDown"/> event.</summary>
        /// <param name="e">A <see cref="T:System.Windows.Forms.MouseEventArgs"/> that contains the event data.</param>
        protected override void OnMouseDown(MouseEventArgs e)
        {
            _mdX = e.X;
            _mdY = e.Y;
            Rectangle bounds;

            _areaMouseDown = HitTestArea(e.X, e.Y);
            switch (_areaMouseDown)
            {
            case 0:
                _leftButtons.OnMouseDown(e.X, e.Y, e.Button);
                break;

            case 1:
                int tabId = HitTestTab(_mdX, _mdY, out bounds);
                if (tabId != -1)
                {
                    _floatId = tabId;
                    int x   = e.X - bounds.X;
                    int y   = e.Y - bounds.Y;
                    var tab = _tabs[tabId];
                    _tabs[tabId].OnMouseDown(x, y, e.Button);
                    if (_tabs.Count <= tabId || _tabs[tabId] != tab)
                    {
                        _floatId = -1;
                    }
                    else
                    {
                        _readyToFloat = e.Button == MouseButtons.Left &&
                                        _tabs[tabId].Buttons.PressedButton == null;
                    }
                }
                else
                {
                    _viewHost.Focus();
                }
                break;

            case 2:
                _rightButtons.OnMouseDown(e.X - (Width - _rightButtons.Width), e.Y, e.Button);
                break;

            default:
                _viewHost.Focus();
                break;
            }
            base.OnMouseDown(e);
        }
Esempio n. 2
0
        /// <summary>Raises the <see cref="E:System.Windows.Forms.Control.MouseMove"/> event.</summary>
        /// <param name="e">A <see cref="T:System.Windows.Forms.MouseEventArgs"/> that contains the event data.</param>
        protected override void OnMouseMove(MouseEventArgs e)
        {
            if (_readyToFloat)
            {
                if (Math.Abs(_mdX - e.X) >= ViewConstants.ViewFloatDragMargin ||
                    Math.Abs(_mdY - e.Y) >= ViewConstants.ViewFloatDragMargin)
                {
                    var form = ViewHost.GetRootOwnerForm();
                    _readyToFloat = false;
                    var tab = _tabs[_floatId];
                    ViewHost.RemoveView(tab.View);
                    var host         = new ViewHost(ViewHost.Grid, false, false, new[] { tab.View });
                    var floatingForm = host.PrepareFloatingMode();
                    Capture = false;
                    ViewHost.Focus();
                    floatingForm.Show(form);
                    floatingForm.Shown += (sender, args) =>
                                          ((ViewHost)((Form)sender).Controls[0]).StartMoving(e.X, e.Y);
                    _floatId = -1;
                }
            }
            int areaId = _areaMouseDown;
            int tabId;
            int offset;

            if (areaId == -1)
            {
                areaId = HitTestArea(e.X, e.Y);
            }
            if (areaId == -1)
            {
                _areaHover.Drop();
            }
            else
            {
                _areaHover.Track(areaId, null);
            }
            if (areaId == -1)
            {
                _areaHover.Drop();
                tabId  = -1;
                offset = 0;
            }
            else
            {
                if (_floatId == -1)
                {
                    if (areaId == 1)
                    {
                        tabId = HitTestTab(e.X, e.Y, out var bounds);
                        if (tabId == -1)
                        {
                            _tabHover.Drop();
                        }
                        offset = bounds.X;
                    }
                    else
                    {
                        tabId  = -1;
                        offset = 0;
                    }
                }
                else
                {
                    areaId = 1;
                    tabId  = _floatId;
                    offset = GetTabOffset(_floatId);
                }
            }
            switch (areaId)
            {
            case 0:
                LeftButtons.OnMouseMove(e.X, e.Y, e.Button);
                break;

            case 1:
                if (tabId != -1)
                {
                    _tabHover.Track(tabId, _tabs[tabId]);
                    int x = e.X;
                    int y = e.Y;
                    switch (Side)
                    {
                    case AnchorStyles.Top:
                    case AnchorStyles.Bottom:
                        x -= offset;
                        break;

                    case AnchorStyles.Left:
                    case AnchorStyles.Right:
                        y -= offset;
                        break;
                    }
                    _tabs[tabId].OnMouseMove(x, y, e.Button);
                }
                break;

            case 2:
                RightButtons.OnMouseMove(e.X - (Width - RightButtons.Width), e.Y, e.Button);
                break;
            }
            base.OnMouseMove(e);
        }