private void FloatingPane_Closed(object sender, EventArgs e) { FloatingPane floatingPane = sender as FloatingPane; if (floatingPane.IViewContainer is InternalViewContainer) { ((InternalViewContainer)(floatingPane.IViewContainer)).Clear(); } int count = floatingPane.IViewContainer.GetUserControlCount(); for (int index = count - 1; index > -1; --index) { FrameworkElement userControl = floatingPane.IViewContainer.GetUserControl(index); IFloatingPaneHost.RemoveViewModel(userControl.DataContext as IViewModel); } if ((sender is FloatingToolPaneGroup) && (FloatingToolPaneGroups.Contains(sender as FloatingToolPaneGroup))) { FloatingToolPaneGroups.Remove(sender as FloatingToolPaneGroup); } if ((sender is FloatingDocumentPaneGroup) && (FloatingDocumentPaneGroups.Contains(sender as FloatingDocumentPaneGroup))) { FloatingDocumentPaneGroups.Remove(sender as FloatingDocumentPaneGroup); } CancelSelection(); }
private FloatingPane UnGroupFloatingPane(FloatingPane floatingPane, int index, double left, double top) { if (floatingPane == null) { return(null); } FrameworkElement userControl = floatingPane.IViewContainer.ExtractUserControl(index); if (userControl == null) { return(null); } FloatingPane newFloatingPane = null; if (floatingPane is FloatingToolPaneGroup) { newFloatingPane = ILayoutFactory.MakeFloatingToolPaneGroup(); } else { newFloatingPane = ILayoutFactory.MakeFloatingDocumentPaneGroup(); } newFloatingPane.Left = left; newFloatingPane.Top = top; newFloatingPane.IViewContainer.AddUserControl(userControl); return(floatingPane); }
private void Float(DockPane dockPane, bool drag, bool selectedTabOnly) { if (!selectedTabOnly || (dockPane.IViewContainer.GetUserControlCount() == 1)) { ExtractDockPane(dockPane, out FrameworkElement frameworkElement); } Point mainWindowLocation = Application.Current.MainWindow.PointToScreen(new Point(0, 0)); FloatingPane floatingPane = null; if (dockPane is ToolPaneGroup) { floatingPane = ILayoutFactory.MakeFloatingToolPaneGroup(); } else { floatingPane = ILayoutFactory.MakeFloatingDocumentPaneGroup(); } int index = selectedTabOnly ? dockPane.IViewContainer.SelectedIndex : 0; while (true) { UserControl userControl = dockPane.IViewContainer.ExtractUserControl(index); if (userControl == null) { break; } floatingPane.IViewContainer.AddUserControl(userControl); if (selectedTabOnly) { floatingPane.IViewContainer.SelectedIndex = 0; break; } } if (drag) { IntPtr hWnd = new System.Windows.Interop.WindowInteropHelper(Application.Current.MainWindow).EnsureHandle(); OpenControls.Wpf.DockManager.Controls.Utilities.SendLeftMouseButtonUp(hWnd); // Ensure the floated window can be dragged by the user hWnd = new System.Windows.Interop.WindowInteropHelper(floatingPane).EnsureHandle(); OpenControls.Wpf.DockManager.Controls.Utilities.SendLeftMouseButtonDown(hWnd); } Point cursorPositionOnScreen = OpenControls.Wpf.DockManager.Controls.Utilities.GetCursorPosition(); floatingPane.Left = cursorPositionOnScreen.X - 30; floatingPane.Top = cursorPositionOnScreen.Y - 30; floatingPane.Width = dockPane.ActualWidth; floatingPane.Height = dockPane.ActualHeight; }
private void FloatingPane_UngroupCurrent(object sender, EventArgs e) { System.Diagnostics.Trace.Assert(sender is FloatingPane); FloatingPane floatingPane = sender as FloatingPane; int index = floatingPane.IViewContainer.SelectedIndex; if (index > -1) { UnGroupFloatingPane(floatingPane, index, floatingPane.Left + 10, floatingPane.Top + 10); } }
private void RegisterFloatingPane(FloatingPane floatingPane) { floatingPane.LocationChanged += FloatingWindow_LocationChanged; floatingPane.Closed += FloatingPane_Closed; floatingPane.Ungroup += FloatingPane_Ungroup; floatingPane.UngroupCurrent += FloatingPane_UngroupCurrent; floatingPane.FloatTabRequest += FloatingPane_FloatTabRequest; floatingPane.TabClosed += FloatingPane_TabClosed; floatingPane.DataContext = new FloatingViewModel(); (floatingPane.DataContext as FloatingViewModel).Title = floatingPane.Title; floatingPane.EndDrag += FloatingPane_EndDrag; // Ensure the window remains on top of the main window floatingPane.Owner = Application.Current.MainWindow; floatingPane.Show(); }
private void FloatingPane_EndDrag(object sender, EventArgs e) { System.Diagnostics.Trace.Assert(sender is FloatingPane, System.Reflection.MethodBase.GetCurrentMethod().Name + ": sender not a FloatingPane"); Application.Current.Dispatcher.Invoke(delegate { FloatingPane floatingPane = sender as FloatingPane; if ( (floatingPane == null) || ((SelectedPane != null) && !(SelectedPane is FloatingPane) && !(SelectedPane.Parent is SplitterPane) && !(SelectedPane.Parent is DocumentPanel) && (SelectedPane.Parent != IFloatingPaneHost.RootGrid)) || (_insertionIndicatorManager == null) || (_insertionIndicatorManager.WindowLocation == WindowLocation.None) ) { if (floatingPane != null) { floatingPane.Close(); } CancelSelection(); return; } ISelectablePane selectedPane = SelectedPane; WindowLocation windowLocation = _insertionIndicatorManager.WindowLocation; CancelSelection(); if (selectedPane is FloatingPane) { IFloatingPane selectedFloatingPane = selectedPane as IFloatingPane; selectedFloatingPane.IViewContainer.ExtractDocuments(floatingPane.IViewContainer); if (floatingPane is FloatingToolPaneGroup) { FloatingToolPaneGroups.Remove(floatingPane); } else { FloatingDocumentPaneGroups.Remove(floatingPane); } floatingPane.Close(); } else { IFloatingPaneHost.Unfloat(floatingPane, selectedPane as SelectablePane, windowLocation); } Application.Current.MainWindow.Activate(); }); }
private void FloatingPane_FloatTabRequest(object sender, EventArgs e) { System.Diagnostics.Trace.Assert(sender is FloatingPane); FloatingPane floatingPane = sender as FloatingPane; if (floatingPane.IViewContainer.GetUserControlCount() == 1) { return; } FloatingPane newFloatingPane = null; if (sender is FloatingToolPaneGroup) { newFloatingPane = ILayoutFactory.MakeFloatingToolPaneGroup(); } else { newFloatingPane = ILayoutFactory.MakeFloatingDocumentPaneGroup(); } int index = floatingPane.IViewContainer.SelectedIndex; FrameworkElement userControl = floatingPane.IViewContainer.ExtractUserControl(index); System.Diagnostics.Trace.Assert(userControl != null); newFloatingPane.IViewContainer.AddUserControl(userControl); IntPtr hWnd = new System.Windows.Interop.WindowInteropHelper(Application.Current.MainWindow).EnsureHandle(); OpenControls.Wpf.Utilities.Windows.SendLeftMouseButtonUp(hWnd); // Ensure the floated window can be dragged by the user hWnd = new System.Windows.Interop.WindowInteropHelper(newFloatingPane).EnsureHandle(); OpenControls.Wpf.Utilities.Windows.SendLeftMouseButtonDown(hWnd); Point cursorPositionOnScreen = OpenControls.Wpf.Utilities.Windows.GetCursorPosition(); newFloatingPane.Left = cursorPositionOnScreen.X - 30; newFloatingPane.Top = cursorPositionOnScreen.Y - 30; newFloatingPane.Width = floatingPane.ActualWidth; newFloatingPane.Height = floatingPane.ActualHeight; }
private void FloatingPane_Ungroup(object sender, EventArgs e) { System.Diagnostics.Trace.Assert(sender is FloatingPane); FloatingPane floatingPane = sender as FloatingPane; int viewCount = floatingPane.IViewContainer.GetUserControlCount(); double left = floatingPane.Left; double top = floatingPane.Top; // Warning warning => off screen? for (int index = 1; index < viewCount; ++index) { left += 10; top += 10; if (UnGroupFloatingPane(floatingPane, 1, left, top) == null) { return; } } }
void IFloatingPaneHost.Unfloat(FloatingPane floatingPane, SelectablePane selectedPane, WindowLocation windowLocation) { IDockPaneManager.Unfloat(floatingPane, selectedPane, windowLocation); }
public void Unfloat(FloatingPane floatingPane, SelectablePane selectedPane, WindowLocation windowLocation) { Application.Current.Dispatcher.Invoke((Action) delegate { if ( (floatingPane == null) || ((selectedPane != null) && !(selectedPane.Parent is SplitterPane) && !(selectedPane.Parent is DocumentPanel) && (selectedPane.Parent != IDockPaneHost)) ) { return; } SplitterPane parentSplitterPane = null; DockPane dockPane = null; switch (windowLocation) { case WindowLocation.BottomSide: case WindowLocation.TopSide: case WindowLocation.LeftSide: case WindowLocation.RightSide: if (floatingPane is FloatingToolPaneGroup) { dockPane = ILayoutFactory.MakeToolPaneGroup(); } else { dockPane = ILayoutFactory.MakeDocumentPaneGroup(); } dockPane.IViewContainer.ExtractDocuments(floatingPane.IViewContainer); floatingPane.Close(); parentSplitterPane = ILayoutFactory.MakeSplitterPane((windowLocation == WindowLocation.TopSide) || (windowLocation == WindowLocation.BottomSide)); bool isFirst = (windowLocation == WindowLocation.TopSide) || (windowLocation == WindowLocation.LeftSide); parentSplitterPane.AddChild(dockPane, isFirst); if (IDockPaneHost.Children.Count == 0) { IDockPaneHost.Children.Add(parentSplitterPane); } else { Grid rootPane = IDockPaneHost.RootPane; IDockPaneHost.RootPane = parentSplitterPane; parentSplitterPane.AddChild(rootPane, !isFirst); } break; case WindowLocation.Right: case WindowLocation.Left: case WindowLocation.Top: case WindowLocation.Bottom: if (floatingPane is FloatingToolPaneGroup) { dockPane = ILayoutFactory.MakeToolPaneGroup(); } else { dockPane = ILayoutFactory.MakeDocumentPaneGroup(); } dockPane.IViewContainer.ExtractDocuments(floatingPane.IViewContainer); floatingPane.Close(); SplitterPane newGrid = ILayoutFactory.MakeSplitterPane((windowLocation == WindowLocation.Top) || (windowLocation == WindowLocation.Bottom)); if (selectedPane.Parent is DocumentPanel) { DocumentPanel documentPanel = selectedPane.Parent as DocumentPanel; documentPanel.Children.Remove(selectedPane); documentPanel.Children.Add(newGrid); } else { parentSplitterPane = (selectedPane.Parent as SplitterPane); parentSplitterPane.Children.Remove(selectedPane); parentSplitterPane.Children.Add(newGrid); Grid.SetRow(newGrid, Grid.GetRow(selectedPane)); Grid.SetColumn(newGrid, Grid.GetColumn(selectedPane)); } bool isTargetFirst = (windowLocation == WindowLocation.Right) || (windowLocation == WindowLocation.Bottom); newGrid.AddChild(selectedPane, isTargetFirst); newGrid.AddChild(dockPane, !isTargetFirst); break; case WindowLocation.Middle: if (selectedPane is DockPane) { (selectedPane as DockPane).IViewContainer.ExtractDocuments(floatingPane.IViewContainer); floatingPane.Close(); } else if (selectedPane is DocumentPanel) { DocumentPaneGroup documentPaneGroup = ILayoutFactory.MakeDocumentPaneGroup(); selectedPane.Children.Add(documentPaneGroup); documentPaneGroup.IViewContainer.ExtractDocuments(floatingPane.IViewContainer); floatingPane.Close(); } break; } Application.Current.MainWindow.Activate(); }); }
private void Float(DockPane dockPane, bool drag, bool selectedTabOnly) { if (!selectedTabOnly || (dockPane.IViewContainer.GetUserControlCount() == 1)) { //ExtractDockPane(dockPane, out FrameworkElement frameworkElement); } Point mainWindowLocation = Application.Current.MainWindow.PointToScreen(new Point(0, 0)); FloatingPane floatingPane = null; if (dockPane is ToolPaneGroup) { floatingPane = ILayoutFactory.MakeFloatingToolPaneGroup(); } else { floatingPane = ILayoutFactory.MakeFloatingDocumentPaneGroup(); } int index = selectedTabOnly ? dockPane.IViewContainer.SelectedIndex : 0; ListBox listBox = ((ViewContainer)dockPane.IViewContainer).TabHeaderControl.ListBox; var currItem = listBox.ItemContainerGenerator.ContainerFromIndex(index) as ListBoxItem; floatingPane.Width = currItem.ActualWidth; floatingPane.Height = currItem.ActualHeight; while (true) { FrameworkElement userControl = dockPane.IViewContainer.GetUserControl(index); if (userControl == null) { break; } floatingPane.IViewContainer.AddUserControl(userControl); if (selectedTabOnly) { floatingPane.Title = dockPane.IViewContainer.Title; floatingPane.IViewContainer.SelectedIndex = 0; break; } else { floatingPane.Title = "..."; } index++; } if (drag) { IntPtr hWnd = new System.Windows.Interop.WindowInteropHelper(Application.Current.MainWindow).EnsureHandle(); OpenControls.Wpf.Utilities.Windows.SendLeftMouseButtonUp(hWnd); // Ensure the floated window can be dragged by the user hWnd = new System.Windows.Interop.WindowInteropHelper(floatingPane).EnsureHandle(); OpenControls.Wpf.Utilities.Windows.SendLeftMouseButtonDown(hWnd); } Point cursorPositionOnScreen = Windows.ScaleByDpi(Windows.GetCursorPosition()); floatingPane.Left = cursorPositionOnScreen.X - 30; floatingPane.Top = cursorPositionOnScreen.Y - 30; }