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;
        }
Exemple #3
0
        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;
        }
        public static void LoadNode(ILayoutFactory iLayoutFactory, Dictionary <string, UserControl> viewsMap, FrameworkElement rootFrameworkElement, FrameworkElement parentFrameworkElement, XmlNode xmlParentElement, bool isParentHorizontal)
        {
            int row             = 0;
            int rowIncrement    = isParentHorizontal ? 2 : 0;
            int column          = 0;
            int columnIncrement = isParentHorizontal ? 0 : 2;

            foreach (var xmlChildNode in xmlParentElement.ChildNodes)
            {
                if (xmlChildNode is XmlElement)
                {
                    if ((xmlChildNode as XmlElement).Name == "SplitterPane")
                    {
                        XmlElement xmlSplitterPane = xmlChildNode as XmlElement;

                        XmlAttribute xmlAttribute = xmlSplitterPane.Attributes.GetNamedItem("Orientation") as XmlAttribute;

                        System.Diagnostics.Trace.Assert(xmlAttribute != null, "SplitterPane element does not have an orientation attribute");

                        bool isChildHorizontal = xmlAttribute.Value == "Horizontal";

                        SplitterPane newGrid = iLayoutFactory.MakeSplitterPane(isChildHorizontal);
                        newGrid.Tag = GetGuid(xmlSplitterPane);

                        if (parentFrameworkElement == rootFrameworkElement)
                        {
                            iLayoutFactory.SetRootPane(newGrid, out row, out column);
                        }
                        else
                        {
                            System.Windows.Markup.IAddChild parentElement = (System.Windows.Markup.IAddChild)parentFrameworkElement;
                            parentElement.AddChild(newGrid);
                            Grid.SetRow(newGrid, row);
                            Grid.SetColumn(newGrid, column);
                        }
                        SetWidthOrHeight(xmlSplitterPane, parentFrameworkElement, isParentHorizontal, row, column);

                        row    += rowIncrement;
                        column += columnIncrement;

                        LoadNode(iLayoutFactory, viewsMap, rootFrameworkElement, newGrid, xmlSplitterPane, isChildHorizontal);
                    }
                    else if ((xmlChildNode as XmlElement).Name == "DocumentPanel")
                    {
                        DocumentPanel documentPanel = iLayoutFactory.MakeDocumentPanel();

                        if (parentFrameworkElement == rootFrameworkElement)
                        {
                            iLayoutFactory.SetRootPane(documentPanel, out row, out column);
                        }
                        else
                        {
                            System.Windows.Markup.IAddChild parentElement = (System.Windows.Markup.IAddChild)parentFrameworkElement;
                            parentElement.AddChild(documentPanel);
                            Grid.SetRow(documentPanel, row);
                            Grid.SetColumn(documentPanel, column);
                        }

                        XmlElement xmlDocumentPanel = xmlChildNode as XmlElement;
                        SetWidthOrHeight(xmlDocumentPanel, parentFrameworkElement, isParentHorizontal, row, column);

                        row    += rowIncrement;
                        column += columnIncrement;

                        LoadNode(iLayoutFactory, viewsMap, rootFrameworkElement, documentPanel, xmlDocumentPanel, true);
                    }
                    else if ((xmlChildNode as XmlElement).Name == "DocumentPaneGroup")
                    {
                        DocumentPaneGroup documentPaneGroup = iLayoutFactory.MakeDocumentPaneGroup();

                        System.Windows.Markup.IAddChild parentElement = (System.Windows.Markup.IAddChild)parentFrameworkElement;
                        parentElement.AddChild(documentPaneGroup);

                        XmlElement xmlDocumentGroup = xmlChildNode as XmlElement;

                        documentPaneGroup.Tag = GetGuid(xmlDocumentGroup);;
                        SetWidthOrHeight(xmlDocumentGroup, parentFrameworkElement, isParentHorizontal, row, column);

                        LoadDocuments(iLayoutFactory, viewsMap, xmlDocumentGroup, documentPaneGroup.IViewContainer);
                        Grid.SetRow(documentPaneGroup, row);
                        Grid.SetColumn(documentPaneGroup, column);
                        row    += rowIncrement;
                        column += columnIncrement;
                    }
                    else if ((xmlChildNode as XmlElement).Name == "ToolPaneGroup")
                    {
                        ToolPaneGroup toolPaneGroup = iLayoutFactory.MakeToolPaneGroup();

                        System.Windows.Markup.IAddChild parentElement = (System.Windows.Markup.IAddChild)parentFrameworkElement;
                        parentElement.AddChild(toolPaneGroup);

                        XmlElement xmlToolPaneGroup = xmlChildNode as XmlElement;

                        toolPaneGroup.Tag = GetGuid(xmlToolPaneGroup);
                        SetWidthOrHeight(xmlToolPaneGroup, parentFrameworkElement, isParentHorizontal, row, column);

                        LoadTools(viewsMap, xmlToolPaneGroup, toolPaneGroup.IViewContainer);
                        Grid.SetRow(toolPaneGroup, row);
                        Grid.SetColumn(toolPaneGroup, column);
                        row    += rowIncrement;
                        column += columnIncrement;
                    }
                    else if ((xmlChildNode as XmlElement).Name == "FloatingToolPaneGroup")
                    {
                        FloatingToolPaneGroup floatingToolPaneGroup = iLayoutFactory.MakeFloatingToolPaneGroup();
                        XmlElement            xmlfloatingTool       = xmlChildNode as XmlElement;
                        floatingToolPaneGroup.Tag = GetGuid(xmlfloatingTool);
                        SetLocationAndSize(xmlfloatingTool, floatingToolPaneGroup);
                        LoadTools(viewsMap, xmlfloatingTool, floatingToolPaneGroup.IViewContainer);
                    }
                    else if ((xmlChildNode as XmlElement).Name == "FloatingDocumentPaneGroup")
                    {
                        FloatingDocumentPaneGroup floatingDocumentPaneGroup = iLayoutFactory.MakeFloatingDocumentPaneGroup();
                        XmlElement xmlfloatingDocument = xmlChildNode as XmlElement;
                        floatingDocumentPaneGroup.Tag = GetGuid(xmlfloatingDocument);
                        SetLocationAndSize(xmlfloatingDocument, floatingDocumentPaneGroup);
                        LoadDocuments(iLayoutFactory, viewsMap, xmlfloatingDocument, floatingDocumentPaneGroup.IViewContainer);
                    }
                    else if ((xmlChildNode as XmlElement).Name == "LeftSide")
                    {
                        XmlElement xmlLeftSide = xmlChildNode as XmlElement;
                        LoadUnPinnedToolDataNodes(iLayoutFactory, viewsMap, WindowLocation.LeftSide, xmlLeftSide);
                    }
                    else if ((xmlChildNode as XmlElement).Name == "TopSide")
                    {
                        XmlElement xmlTopSide = xmlChildNode as XmlElement;
                        LoadUnPinnedToolDataNodes(iLayoutFactory, viewsMap, WindowLocation.TopSide, xmlTopSide);
                    }
                    else if ((xmlChildNode as XmlElement).Name == "RightSide")
                    {
                        XmlElement xmlRightSide = xmlChildNode as XmlElement;
                        LoadUnPinnedToolDataNodes(iLayoutFactory, viewsMap, WindowLocation.RightSide, xmlRightSide);
                    }
                    else if ((xmlChildNode as XmlElement).Name == "BottomSide")
                    {
                        XmlElement xmlBottomSide = xmlChildNode as XmlElement;
                        LoadUnPinnedToolDataNodes(iLayoutFactory, viewsMap, WindowLocation.BottomSide, xmlBottomSide);
                    }
                }

                if (parentFrameworkElement != rootFrameworkElement)
                {
                    if ((row > 2) || (column > 2))
                    {
                        // we can only have two child elements (plus a splitter) in each grid
                        break;
                    }
                }
            }
        }