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(ResourceHelper.GetString("DockPane.DockState.InvalidState")); if (content == null) throw new ArgumentNullException(ResourceHelper.GetString("DockPane.Constructor.NullContent")); if (content.DockHandler.DockPanel == null) throw new ArgumentException(ResourceHelper.GetString("DockPane.Constructor.NullDockPanel")); SuspendLayout(); SetStyle(ControlStyles.Selectable, false); m_isFloat = (dockState == DockState.Float); m_contents = new DockContentCollection(); m_displayingContents = new DockContentCollection(this); m_tabs = new DockPaneTabCollection(this); m_dockPanel = content.DockHandler.DockPanel; m_dockPanel.AddPane(this); m_splitter = new DockPaneSplitter(this); m_nestedDockingStatus = new NestedDockingStatus(this); m_autoHidePane = DockPanel.AutoHidePaneFactory.CreateAutoHidePane(this); m_captionControl = DockPanel.DockPaneCaptionFactory.CreateDockPaneCaption(this); m_tabStripControl = DockPanel.DockPaneStripFactory.CreateDockPaneStrip(this); Controls.AddRange(new Control[] { m_captionControl, m_tabStripControl }); DockPanel.SuspendLayout(true); if (flagBounds) FloatWindow = DockPanel.FloatWindowFactory.CreateFloatWindow(DockPanel, this, floatWindowBounds); else if (prevPane != null) AddToDockList(prevPane.DockListContainer, prevPane, alignment, proportion); SetDockState(dockState); if (show) content.DockHandler.Pane = this; else if (this.IsFloat) content.DockHandler.FloatPane = this; else content.DockHandler.PanelPane = this; ResumeLayout(); DockPanel.ResumeLayout(true, true); }
public static void SaveAsXml(DockPanel dockPanel, Stream stream, Encoding encoding, bool upstream) { XmlTextWriter xmlOut = new XmlTextWriter(stream, encoding); // Use indenting for readability xmlOut.Formatting = Formatting.Indented; if (!upstream) { xmlOut.WriteStartDocument(); } // Always begin file with identification and warning xmlOut.WriteComment(" DockPanel configuration file. Author: Weifen Luo, all rights reserved. "); xmlOut.WriteComment(" !!! AUTOMATICALLY GENERATED FILE. DO NOT MODIFY !!! "); // Associate a version number with the root element so that future version of the code // will be able to be backwards compatible or at least recognise out of date versions xmlOut.WriteStartElement("DockPanel"); xmlOut.WriteAttributeString("FormatVersion", ConfigFileVersion); xmlOut.WriteAttributeString("DockLeftPortion", dockPanel.DockLeftPortion.ToString(CultureInfo.InvariantCulture)); xmlOut.WriteAttributeString("DockRightPortion", dockPanel.DockRightPortion.ToString(CultureInfo.InvariantCulture)); xmlOut.WriteAttributeString("DockTopPortion", dockPanel.DockTopPortion.ToString(CultureInfo.InvariantCulture)); xmlOut.WriteAttributeString("DockBottomPortion", dockPanel.DockBottomPortion.ToString(CultureInfo.InvariantCulture)); xmlOut.WriteAttributeString("ActiveDocumentPane", dockPanel.Panes.IndexOf(dockPanel.ActiveDocumentPane).ToString()); xmlOut.WriteAttributeString("ActivePane", dockPanel.Panes.IndexOf(dockPanel.ActivePane).ToString()); // Contents xmlOut.WriteStartElement("Contents"); xmlOut.WriteAttributeString("Count", dockPanel.Contents.Count.ToString()); foreach (IDockContent content in dockPanel.Contents) { xmlOut.WriteStartElement("Content"); xmlOut.WriteAttributeString("ID", dockPanel.Contents.IndexOf(content).ToString()); xmlOut.WriteAttributeString("PersistString", content.DockHandler.PersistString); xmlOut.WriteAttributeString("AutoHidePortion", content.DockHandler.AutoHidePortion.ToString(CultureInfo.InvariantCulture)); xmlOut.WriteAttributeString("IsHidden", content.DockHandler.IsHidden.ToString()); xmlOut.WriteAttributeString("IsFloat", content.DockHandler.IsFloat.ToString()); xmlOut.WriteEndElement(); } xmlOut.WriteEndElement(); // Panes xmlOut.WriteStartElement("Panes"); xmlOut.WriteAttributeString("Count", dockPanel.Panes.Count.ToString()); foreach (DockPane pane in dockPanel.Panes) { xmlOut.WriteStartElement("Pane"); xmlOut.WriteAttributeString("ID", dockPanel.Panes.IndexOf(pane).ToString()); xmlOut.WriteAttributeString("DockState", pane.DockState.ToString()); xmlOut.WriteAttributeString("ActiveContent", dockPanel.Contents.IndexOf(pane.ActiveContent).ToString()); xmlOut.WriteStartElement("Contents"); xmlOut.WriteAttributeString("Count", pane.Contents.Count.ToString()); foreach (IDockContent content in pane.Contents) { xmlOut.WriteStartElement("Content"); xmlOut.WriteAttributeString("ID", pane.Contents.IndexOf(content).ToString()); xmlOut.WriteAttributeString("RefID", dockPanel.Contents.IndexOf(content).ToString()); xmlOut.WriteEndElement(); } xmlOut.WriteEndElement(); xmlOut.WriteEndElement(); } xmlOut.WriteEndElement(); // DockWindows xmlOut.WriteStartElement("DockWindows"); int dockWindowId = 0; foreach (DockWindow dw in dockPanel.DockWindows) { xmlOut.WriteStartElement("DockWindow"); xmlOut.WriteAttributeString("ID", dockWindowId.ToString()); dockWindowId++; xmlOut.WriteAttributeString("DockState", dw.DockState.ToString()); xmlOut.WriteAttributeString("ZOrderIndex", dockPanel.Controls.IndexOf(dw).ToString()); xmlOut.WriteStartElement("DockList"); xmlOut.WriteAttributeString("Count", dw.DockList.Count.ToString()); foreach (DockPane pane in dw.DockList) { xmlOut.WriteStartElement("Pane"); xmlOut.WriteAttributeString("ID", dw.DockList.IndexOf(pane).ToString()); xmlOut.WriteAttributeString("RefID", dockPanel.Panes.IndexOf(pane).ToString()); NestedDockingStatus status = pane.NestedDockingStatus; xmlOut.WriteAttributeString("PrevPane", dockPanel.Panes.IndexOf(status.PrevPane).ToString()); xmlOut.WriteAttributeString("Alignment", status.Alignment.ToString()); xmlOut.WriteAttributeString("Proportion", status.Proportion.ToString(CultureInfo.InvariantCulture)); xmlOut.WriteEndElement(); } xmlOut.WriteEndElement(); xmlOut.WriteEndElement(); } xmlOut.WriteEndElement(); // FloatWindows RectangleConverter rectConverter = new RectangleConverter(); xmlOut.WriteStartElement("FloatWindows"); xmlOut.WriteAttributeString("Count", dockPanel.FloatWindows.Count.ToString()); foreach (FloatWindow fw in dockPanel.FloatWindows) { xmlOut.WriteStartElement("FloatWindow"); xmlOut.WriteAttributeString("ID", dockPanel.FloatWindows.IndexOf(fw).ToString()); xmlOut.WriteAttributeString("Bounds", rectConverter.ConvertToInvariantString(fw.Bounds)); xmlOut.WriteAttributeString("AllowRedocking", fw.AllowRedocking.ToString()); xmlOut.WriteAttributeString("ZOrderIndex", fw.DockPanel.FloatWindows.IndexOf(fw).ToString()); xmlOut.WriteStartElement("DockList"); xmlOut.WriteAttributeString("Count", fw.DockList.Count.ToString()); foreach (DockPane pane in fw.DockList) { xmlOut.WriteStartElement("Pane"); xmlOut.WriteAttributeString("ID", fw.DockList.IndexOf(pane).ToString()); xmlOut.WriteAttributeString("RefID", dockPanel.Panes.IndexOf(pane).ToString()); NestedDockingStatus status = pane.NestedDockingStatus; xmlOut.WriteAttributeString("PrevPane", dockPanel.Panes.IndexOf(status.PrevPane).ToString()); xmlOut.WriteAttributeString("Alignment", status.Alignment.ToString()); xmlOut.WriteAttributeString("Proportion", status.Proportion.ToString(CultureInfo.InvariantCulture)); xmlOut.WriteEndElement(); } xmlOut.WriteEndElement(); xmlOut.WriteEndElement(); } xmlOut.WriteEndElement(); // </FloatWindows> xmlOut.WriteEndElement(); if (!upstream) { xmlOut.WriteEndDocument(); xmlOut.Close(); } else { xmlOut.Flush(); } }
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(ResourceHelper.GetString("DockPane.DockState.InvalidState")); } if (content == null) { throw new ArgumentNullException(ResourceHelper.GetString("DockPane.Constructor.NullContent")); } if (content.DockHandler.DockPanel == null) { throw new ArgumentException(ResourceHelper.GetString("DockPane.Constructor.NullDockPanel")); } SuspendLayout(); SetStyle(ControlStyles.Selectable, false); m_isFloat = (dockState == DockState.Float); m_contents = new DockContentCollection(); m_displayingContents = new DockContentCollection(this); m_tabs = new DockPaneTabCollection(this); m_dockPanel = content.DockHandler.DockPanel; m_dockPanel.AddPane(this); m_splitter = new DockPaneSplitter(this); m_nestedDockingStatus = new NestedDockingStatus(this); m_autoHidePane = DockPanel.AutoHidePaneFactory.CreateAutoHidePane(this); m_captionControl = DockPanel.DockPaneCaptionFactory.CreateDockPaneCaption(this); m_tabStripControl = DockPanel.DockPaneStripFactory.CreateDockPaneStrip(this); Controls.AddRange(new Control[] { m_captionControl, m_tabStripControl }); DockPanel.SuspendLayout(true); if (flagBounds) { FloatWindow = DockPanel.FloatWindowFactory.CreateFloatWindow(DockPanel, this, floatWindowBounds); } else if (prevPane != null) { AddToDockList(prevPane.DockListContainer, prevPane, alignment, proportion); } SetDockState(dockState); if (show) { content.DockHandler.Pane = this; } else if (this.IsFloat) { content.DockHandler.FloatPane = this; } else { content.DockHandler.PanelPane = this; } ResumeLayout(); DockPanel.ResumeLayout(true, true); }