Exemple #1
0
        protected void HandleApplicationMouseLUp(Point mousePos)
        {
            // If we released the mouse button while we were dragging a torn tab, put that tab into a new window
            if (m_tornTab != null)
            {
                TitleBarTabItem tabToRelease = null;

                lock (m_tornTabLock)
                {
                    if (m_tornTab != null)
                    {
                        tabToRelease = m_tornTab;
                        m_tornTab    = null;
                    }
                }

                if (tabToRelease != null)
                {
                    TitleBarTabMainForm newWindow = (TitleBarTabMainForm)Activator.CreateInstance(m_parentForm.GetType());

                    // Set the initial window position and state properly
                    if (newWindow.WindowState == FormWindowState.Maximized)
                    {
                        Screen screen = Screen.AllScreens.First(s => s.WorkingArea.Contains(Cursor.Position));

                        newWindow.StartPosition = FormStartPosition.Manual;
                        newWindow.WindowState   = FormWindowState.Normal;
                        newWindow.Left          = screen.WorkingArea.Left;
                        newWindow.Top           = screen.WorkingArea.Top;
                        newWindow.Width         = screen.WorkingArea.Width;
                        newWindow.Height        = screen.WorkingArea.Height;
                    }

                    else
                    {
                        newWindow.Left = Cursor.Position.X;
                        newWindow.Top  = Cursor.Position.Y;
                    }

                    tabToRelease.Parent = newWindow;
                    m_parentForm.ApplicationContext.OpenWindow(newWindow);

                    newWindow.Show();
                    newWindow.Tabs.Add(tabToRelease);
                    newWindow.SelectedTabIndex = 0;
                    newWindow.ResizeTabContents();

                    m_tornTabForm.Close();
                    m_tornTabForm = null;

                    if (m_parentForm.Tabs.Count == 0)
                    {
                        m_parentForm.Close();
                    }
                }
            }

            OnMouseUp(new MouseEventArgs(MouseButtons.Left, 1, Cursor.Position.X, Cursor.Position.Y, 0));
        }
Exemple #2
0
        /// <summary>
        /// Called when a torn tab is dragged into the <see cref="TitleBarTabMainForm.TabDropArea" /> of <see cref="_parentWindow" />.  Places the tab in the list and
        /// sets <see cref="IsTabRepositioning" /> to true to simulate the user continuing to drag the tab around in the window.
        /// </summary>
        /// <param name="tab">Tab that was dragged into this window.</param>
        /// <param name="cursorLocation">Location of the user's cursor.</param>
        internal virtual void CombineTab(TitleBarTabItem tab, Point cursorLocation)
        {
            // Stop rendering to prevent weird stuff from happening like the wrong tab being focused
            _suspendRendering = true;

            // Find out where to insert the tab in the list
            int dropIndex = _parentWindow.Tabs.FindIndex(t => t.Area.Left <= cursorLocation.X && t.Area.Right >= cursorLocation.X);

            // Simulate the user having clicked in the middle of the tab when they started dragging it so that the tab will move correctly within the window
            // when the user continues to move the mouse
            if (_parentWindow.Tabs.Count > 0)
            {
                _tabClickOffset = _parentWindow.Tabs.First().Area.Width / 2;
            }
            else
            {
                _tabClickOffset = 0;
            }
            IsTabRepositioning = true;

            tab.Parent = _parentWindow;

            if (dropIndex == -1)
            {
                _parentWindow.Tabs.Add(tab);
                dropIndex = _parentWindow.Tabs.Count - 1;
            }

            else
            {
                _parentWindow.Tabs.Insert(dropIndex, tab);
            }

            // Resume rendering
            _suspendRendering = false;

            _parentWindow.SelectedTabIndex = dropIndex;
            _parentWindow.ResizeTabContents();
        }