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)); }
protected void HandleApplicationMouseMove(Point mousePos) { bool reRender = false; if (m_tornTab != null && m_dropAreas != null) { // ReSharper disable ForCanBeConvertedToForeach for (int i = 0; i < m_dropAreas.Length; i++) // ReSharper restore ForCanBeConvertedToForeach { // If the cursor is within the drop area, combine the tab for the window that belongs to that drop area if (m_dropAreas[i].Item2.Contains(mousePos)) { TitleBarTabItem tabToCombine = null; lock (m_tornTabLock) { if (m_tornTab != null) { tabToCombine = m_tornTab; m_tornTab = null; } } if (tabToCombine != null) { int i1 = i; // In all cases where we need to affect the UI, we call Invoke so that those changes are made on the main UI thread since // we are on a separate processing thread in this case m_dropAreas[i1].Item1.TabRenderer.CombineTab(tabToCombine, mousePos); tabToCombine = null; m_tornTabForm.Close(); m_tornTabForm = null; if (m_parentForm.Tabs.Count == 0) { m_parentForm.Close(); } } } } } else if (!m_parentForm.TabRenderer.IsTabRepositioning) { // If we were over a close button previously, check to see if the cursor is still over that tab's // close button; if not, re-render if (m_isOverCloseButtonForTab != -1 && (m_isOverCloseButtonForTab >= m_parentForm.Tabs.Count || !m_parentForm.TabRenderer.IsOverCloseButton(m_parentForm.Tabs[m_isOverCloseButtonForTab], GetRelativeCursorPosition(mousePos)))) { reRender = true; m_isOverCloseButtonForTab = -1; } // Otherwise, see if any tabs' close button is being hovered over else { // ReSharper disable ForCanBeConvertedToForeach for (int i = 0; i < m_parentForm.Tabs.Count; i++) // ReSharper restore ForCanBeConvertedToForeach { if (m_parentForm.TabRenderer.IsOverCloseButton(m_parentForm.Tabs[i], GetRelativeCursorPosition(mousePos))) { m_isOverCloseButtonForTab = i; reRender = true; break; } } } } else { m_wasDragging = true; // When determining if a tab has been torn from the window while dragging, we take the drop area for this window and inflate it by the // TabTearDragDistance setting Rectangle dragArea = TabDropArea; dragArea.Inflate(m_parentForm.TabRenderer.TabTearDragDistance, m_parentForm.TabRenderer.TabTearDragDistance); // If the cursor is outside the tear area, tear it away from the current window if (!dragArea.Contains(mousePos) && m_tornTab == null) { lock (m_tornTabLock) { if (m_tornTab == null) { m_parentForm.TabRenderer.IsTabRepositioning = false; // Clear the event handler subscriptions from the tab and then create a thumbnail representation of it to use when dragging m_tornTab = m_parentForm.SelectedTab; m_tornTab.ClearSubscriptions(); m_tornTabForm = new TitleBarTornTabForm(m_tornTab, m_parentForm.TabRenderer, this); } } if (m_tornTab != null) { m_parentForm.SelectedTabIndex = (m_parentForm.SelectedTabIndex == m_parentForm.Tabs.Count - 1 ? m_parentForm.SelectedTabIndex - 1 : m_parentForm.SelectedTabIndex + 1); m_parentForm.Tabs.Remove(m_tornTab); // If this tab was the only tab in the window, hide the parent window if (m_parentForm.Tabs.Count == 0) { m_parentForm.Hide(); } m_tornTabForm.Show(); m_dropAreas = (from window in m_parentForm.ApplicationContext.OpenWindows.Where(w => w.Tabs.Count > 0) select new Tuple <TitleBarTabMainForm, Rectangle>(window, window.TabDropArea)).ToArray(); } } } OnMouseMove(new MouseEventArgs(MouseButtons.None, 0, mousePos.X, mousePos.Y, 0)); if (m_parentForm.TabRenderer.IsTabRepositioning) { reRender = true; } if (reRender) { Render(mousePos, true); } }