Пример #1
0
 public DockPane CreateDockPane(IDockContent content, DockPane prevPane, DockAlignment alignment,
                                double proportion, bool show)
 {
     return(new DockPane(content, prevPane, alignment, proportion, show));
 }
Пример #2
0
 public DockPaneCaption CreateDockPaneCaption(DockPane pane)
 {
     return(new DockPaneCaption(pane));
 }
Пример #3
0
 public DockPaneStrip CreateDockPaneStrip(DockPane pane)
 {
     return(new DockPaneStrip(pane));
 }
Пример #4
0
 public FloatWindow CreateFloatWindow(DockPanel dockPanel, DockPane pane)
 {
     return(new FloatWindow(dockPanel, pane));
 }
Пример #5
0
 public FloatWindow CreateFloatWindow(DockPanel dockPanel, DockPane pane, Rectangle bounds)
 {
     return(new FloatWindow(dockPanel, pane, bounds));
 }
Пример #6
0
            public static void LoadFromXml(DockPanel dockPanel, Stream stream, DeserializeDockContent deserializeContent, bool closeStream = true)
            {
                if (dockPanel.Contents.Count != 0)
                {
                    throw new InvalidOperationException(Strings.DockPanel_LoadFromXml_AlreadyInitialized);
                }

                DockPanelStruct dockPanelStruct;

                ContentStruct[]     contents;
                PaneStruct[]        panes;
                DockWindowStruct[]  dockWindows;
                FloatWindowStruct[] floatWindows;
                using (var xmlIn = new XmlTextReader(stream)
                {
                    WhitespaceHandling = WhitespaceHandling.None
                })
                {
                    xmlIn.MoveToContent();

                    while (!xmlIn.Name.Equals("DockPanel"))
                    {
                        if (!MoveToNextElement(xmlIn))
                        {
                            throw new ArgumentException(Strings.DockPanel_LoadFromXml_InvalidXmlFormat);
                        }
                    }

                    string formatVersion = xmlIn.GetAttribute("FormatVersion");
                    if (!IsFormatVersionValid(formatVersion))
                    {
                        throw new ArgumentException(Strings.DockPanel_LoadFromXml_InvalidFormatVersion);
                    }

                    dockPanelStruct = new DockPanelStruct
                    {
                        DockLeftPortion =
                            Convert.ToDouble(xmlIn.GetAttribute("DockLeftPortion"), CultureInfo.InvariantCulture),
                        DockRightPortion =
                            Convert.ToDouble(xmlIn.GetAttribute("DockRightPortion"), CultureInfo.InvariantCulture),
                        DockTopPortion =
                            Convert.ToDouble(xmlIn.GetAttribute("DockTopPortion"), CultureInfo.InvariantCulture),
                        DockBottomPortion =
                            Convert.ToDouble(xmlIn.GetAttribute("DockBottomPortion"), CultureInfo.InvariantCulture),
                        IndexActiveDocumentPane =
                            Convert.ToInt32(xmlIn.GetAttribute("ActiveDocumentPane"), CultureInfo.InvariantCulture),
                        IndexActivePane =
                            Convert.ToInt32(xmlIn.GetAttribute("ActivePane"), CultureInfo.InvariantCulture)
                    };

                    // Load Contents
                    MoveToNextElement(xmlIn);
                    if (xmlIn.Name != "Contents")
                    {
                        throw new ArgumentException(Strings.DockPanel_LoadFromXml_InvalidXmlFormat);
                    }
                    contents = LoadContents(xmlIn);

                    // Load Panes
                    if (xmlIn.Name != "Panes")
                    {
                        throw new ArgumentException(Strings.DockPanel_LoadFromXml_InvalidXmlFormat);
                    }
                    panes = LoadPanes(xmlIn);

                    // Load DockWindows
                    if (xmlIn.Name != "DockWindows")
                    {
                        throw new ArgumentException(Strings.DockPanel_LoadFromXml_InvalidXmlFormat);
                    }
                    dockWindows = LoadDockWindows(xmlIn, dockPanel);

                    // Load FloatWindows
                    if (xmlIn.Name != "FloatWindows")
                    {
                        throw new ArgumentException(Strings.DockPanel_LoadFromXml_InvalidXmlFormat);
                    }
                    floatWindows = LoadFloatWindows(xmlIn);

                    if (closeStream)
                    {
                        xmlIn.Close();
                    }
                }

                dockPanel.SuspendLayout(true);

                dockPanel.DockLeftPortion   = dockPanelStruct.DockLeftPortion;
                dockPanel.DockRightPortion  = dockPanelStruct.DockRightPortion;
                dockPanel.DockTopPortion    = dockPanelStruct.DockTopPortion;
                dockPanel.DockBottomPortion = dockPanelStruct.DockBottomPortion;

                // Set DockWindow ZOrders
                int prevMaxDockWindowZOrder = int.MaxValue;

                for (int i = 0; i < dockWindows.Length; i++)
                {
                    int maxDockWindowZOrder = -1;
                    int index = -1;
                    for (int j = 0; j < dockWindows.Length; j++)
                    {
                        if (dockWindows[j].ZOrderIndex > maxDockWindowZOrder && dockWindows[j].ZOrderIndex < prevMaxDockWindowZOrder)
                        {
                            maxDockWindowZOrder = dockWindows[j].ZOrderIndex;
                            index = j;
                        }
                    }

                    dockPanel.DockWindows[dockWindows[index].DockState].BringToFront();
                    prevMaxDockWindowZOrder = maxDockWindowZOrder;
                }

                // Create Contents
                for (int i = 0; i < contents.Length; i++)
                {
                    var content = deserializeContent(contents[i].PersistString) ?? new DummyContent();
                    content.DockHandler.DockPanel       = dockPanel;
                    content.DockHandler.AutoHidePortion = contents[i].AutoHidePortion;
                    content.DockHandler.IsHidden        = true;
                    content.DockHandler.IsFloat         = contents[i].IsFloat;
                }

                // Create panes
                for (int i = 0; i < panes.Length; i++)
                {
                    DockPane pane = null;
                    for (int j = 0; j < panes[i].IndexContents.Length; j++)
                    {
                        IDockContent content = dockPanel.Contents[panes[i].IndexContents[j]];
                        if (j == 0)
                        {
                            pane = dockPanel.DockPaneFactory.CreateDockPane(content, panes[i].DockState, false);
                        }
                        else if (panes[i].DockState == DockState.Float)
                        {
                            content.DockHandler.FloatPane = pane;
                        }
                        else
                        {
                            content.DockHandler.PanelPane = pane;
                        }
                    }
                }

                // Assign Panes to DockWindows
                for (int i = 0; i < dockWindows.Length; i++)
                {
                    for (int j = 0; j < dockWindows[i].NestedPanes.Length; j++)
                    {
                        DockWindow    dw            = dockPanel.DockWindows[dockWindows[i].DockState];
                        int           indexPane     = dockWindows[i].NestedPanes[j].IndexPane;
                        DockPane      pane          = dockPanel.Panes[indexPane];
                        int           indexPrevPane = dockWindows[i].NestedPanes[j].IndexPrevPane;
                        DockPane      prevPane      = indexPrevPane == -1 ? dw.NestedPanes.GetDefaultPreviousPane(pane) : dockPanel.Panes[indexPrevPane];
                        DockAlignment alignment     = dockWindows[i].NestedPanes[j].Alignment;
                        double        proportion    = dockWindows[i].NestedPanes[j].Proportion;
                        pane.DockTo(dw, prevPane, alignment, proportion);
                        if (panes[indexPane].DockState == dw.DockState)
                        {
                            panes[indexPane].ZOrderIndex = dockWindows[i].ZOrderIndex;
                        }
                    }
                }

                // Create float windows
                for (var i = 0; i < floatWindows.Length; i++)
                {
                    FloatWindow fw = null;
                    for (int j = 0; j < floatWindows[i].NestedPanes.Length; j++)
                    {
                        int      indexPane = floatWindows[i].NestedPanes[j].IndexPane;
                        DockPane pane      = dockPanel.Panes[indexPane];
                        if (j == 0)
                        {
                            fw = dockPanel.FloatWindowFactory.CreateFloatWindow(dockPanel, pane, floatWindows[i].Bounds);
                        }
                        else
                        {
                            int           indexPrevPane = floatWindows[i].NestedPanes[j].IndexPrevPane;
                            DockPane      prevPane      = indexPrevPane == -1 ? null : dockPanel.Panes[indexPrevPane];
                            DockAlignment alignment     = floatWindows[i].NestedPanes[j].Alignment;
                            double        proportion    = floatWindows[i].NestedPanes[j].Proportion;
                            pane.DockTo(fw, prevPane, alignment, proportion);
                        }

                        if (panes[indexPane].DockState == fw.DockState)
                        {
                            panes[indexPane].ZOrderIndex = floatWindows[i].ZOrderIndex;
                        }
                    }
                }

                // sort IDockContent by its Pane's ZOrder
                int[] sortedContents = null;
                if (contents.Length > 0)
                {
                    sortedContents = new int[contents.Length];
                    for (int i = 0; i < contents.Length; i++)
                    {
                        sortedContents[i] = i;
                    }

                    for (int i = 0; i < contents.Length - 1; i++)
                    {
                        for (int j = i + 1; j < contents.Length; j++)
                        {
                            var pane1        = dockPanel.Contents[sortedContents[i]].DockHandler.Pane;
                            var zOrderIndex1 = pane1 == null ? 0 : panes[dockPanel.Panes.IndexOf(pane1)].ZOrderIndex;
                            var pane2        = dockPanel.Contents[sortedContents[j]].DockHandler.Pane;
                            var zOrderIndex2 = pane2 == null ? 0 : panes[dockPanel.Panes.IndexOf(pane2)].ZOrderIndex;
                            if (zOrderIndex1 <= zOrderIndex2)
                            {
                                continue;
                            }
                            var temp = sortedContents[i];
                            sortedContents[i] = sortedContents[j];
                            sortedContents[j] = temp;
                        }
                    }
                }

                // show non-document IDockContent first to avoid screen flickers
                for (int i = 0; i < contents.Length; i++)
                {
                    IDockContent content = dockPanel.Contents[sortedContents[i]];
                    if (content.DockHandler.Pane != null && content.DockHandler.Pane.DockState != DockState.Document)
                    {
                        content.DockHandler.IsHidden = contents[sortedContents[i]].IsHidden;
                    }
                }

                // after all non-document IDockContent, show document IDockContent
                for (int i = 0; i < contents.Length; i++)
                {
                    IDockContent content = dockPanel.Contents[sortedContents[i]];
                    if (content.DockHandler.Pane != null && content.DockHandler.Pane.DockState == DockState.Document)
                    {
                        content.DockHandler.IsHidden = contents[sortedContents[i]].IsHidden;
                    }
                }

                for (int i = 0; i < panes.Length; i++)
                {
                    dockPanel.Panes[i].ActiveContent = panes[i].IndexActiveContent == -1 ? null : dockPanel.Contents[panes[i].IndexActiveContent];
                }

                if (dockPanelStruct.IndexActiveDocumentPane != -1)
                {
                    dockPanel.Panes[dockPanelStruct.IndexActiveDocumentPane].Activate();
                }

                if (dockPanelStruct.IndexActivePane != -1)
                {
                    dockPanel.Panes[dockPanelStruct.IndexActivePane].Activate();
                }

                for (int i = dockPanel.Contents.Count - 1; i >= 0; i--)
                {
                    if (dockPanel.Contents[i] is DummyContent)
                    {
                        dockPanel.Contents[i].DockHandler.Form.Close();
                    }
                }

                dockPanel.ResumeLayout(true, true);
            }
Пример #7
0
 public DockPane.SplitterControlBase CreateSplitterControl(DockPane pane)
 {
     return(new DockPane.DefaultSplitterControl(pane));
 }
Пример #8
0
        private void InternalConstruct(IDockContent content, DockState dockState, bool flagBounds, Rectangle floatWindowBounds, DockPane prevPane, DockAlignment alignment, double proportion, bool show)
        {
            if (dockState == DockState.Hidden || dockState == DockState.Unknown)
            {
                throw new ArgumentException(Strings.DockPane_SetDockState_InvalidState);
            }

            if (content == null)
            {
                throw new ArgumentNullException(Strings.DockPane_Constructor_NullContent);
            }

            if (content.DockHandler.DockPanel == null)
            {
                throw new ArgumentException(Strings.DockPane_Constructor_NullDockPanel);
            }


            SuspendLayout();
            SetStyle(ControlStyles.Selectable, false);

            IsFloat = dockState == DockState.Float;

            Contents           = new DockContentCollection();
            DisplayingContents = new DockContentCollection(this);
            DockPanel          = content.DockHandler.DockPanel;
            DockPanel.AddPane(this);

            Splitter = content.DockHandler.DockPanel.Extender.DockPaneSplitterControlFactory.CreateSplitterControl(this);

            NestedDockingStatus = new NestedDockingStatus(this);

            CaptionControl  = DockPanel.DockPaneCaptionFactory.CreateDockPaneCaption(this);
            TabStripControl = DockPanel.DockPaneStripFactory.CreateDockPaneStrip(this);
            Controls.AddRange(new Control[] { CaptionControl, TabStripControl });

            DockPanel.SuspendLayout(true);
            if (flagBounds)
            {
                FloatWindow = DockPanel.FloatWindowFactory.CreateFloatWindow(DockPanel, this, floatWindowBounds);
            }
            else if (prevPane != null)
            {
                DockTo(prevPane.NestedPanesContainer, prevPane, alignment, proportion);
            }

            SetDockState(dockState);
            if (show)
            {
                content.DockHandler.Pane = this;
            }
            else if (IsFloat)
            {
                content.DockHandler.FloatPane = this;
            }
            else
            {
                content.DockHandler.PanelPane = this;
            }

            ResumeLayout();
            DockPanel.ResumeLayout(true, true);
        }
Пример #9
0
 private void SetVisibleContentsToPane(DockPane pane)
 {
     SetVisibleContentsToPane(pane, ActiveContent);
 }
Пример #10
0
 public void DockTo(DockPane paneTo, DockStyle dockStyle, int contentIndex)
 {
     DockHandler.DockTo(paneTo, dockStyle, contentIndex);
 }
Пример #11
0
 public void Show(DockPane previousPane, DockAlignment alignment, double proportion)
 {
     DockHandler.Show(previousPane, alignment, proportion);
 }
Пример #12
0
 public void Show(DockPane pane, IDockContent beforeContent)
 {
     DockHandler.Show(pane, beforeContent);
 }