1 | using System;
|
---|
2 | using System.ComponentModel;
|
---|
3 | using System.Drawing;
|
---|
4 | using System.Globalization;
|
---|
5 | using System.IO;
|
---|
6 | using System.Text;
|
---|
7 | using System.Xml;
|
---|
8 |
|
---|
9 | namespace WeifenLuo.WinFormsUI.Docking {
|
---|
10 | partial class DockPanel {
|
---|
11 | private static class Persistor {
|
---|
12 | private const string ConfigFileVersion = "1.0";
|
---|
13 | private static string[] CompatibleConfigFileVersions = new string[] { };
|
---|
14 |
|
---|
15 | private class DummyContent : DockContent {
|
---|
16 | }
|
---|
17 |
|
---|
18 | private struct DockPanelStruct {
|
---|
19 | private double m_dockLeftPortion;
|
---|
20 | public double DockLeftPortion {
|
---|
21 | get { return m_dockLeftPortion; }
|
---|
22 | set { m_dockLeftPortion = value; }
|
---|
23 | }
|
---|
24 |
|
---|
25 | private double m_dockRightPortion;
|
---|
26 | public double DockRightPortion {
|
---|
27 | get { return m_dockRightPortion; }
|
---|
28 | set { m_dockRightPortion = value; }
|
---|
29 | }
|
---|
30 |
|
---|
31 | private double m_dockTopPortion;
|
---|
32 | public double DockTopPortion {
|
---|
33 | get { return m_dockTopPortion; }
|
---|
34 | set { m_dockTopPortion = value; }
|
---|
35 | }
|
---|
36 |
|
---|
37 | private double m_dockBottomPortion;
|
---|
38 | public double DockBottomPortion {
|
---|
39 | get { return m_dockBottomPortion; }
|
---|
40 | set { m_dockBottomPortion = value; }
|
---|
41 | }
|
---|
42 |
|
---|
43 | private int m_indexActiveDocumentPane;
|
---|
44 | public int IndexActiveDocumentPane {
|
---|
45 | get { return m_indexActiveDocumentPane; }
|
---|
46 | set { m_indexActiveDocumentPane = value; }
|
---|
47 | }
|
---|
48 |
|
---|
49 | private int m_indexActivePane;
|
---|
50 | public int IndexActivePane {
|
---|
51 | get { return m_indexActivePane; }
|
---|
52 | set { m_indexActivePane = value; }
|
---|
53 | }
|
---|
54 | }
|
---|
55 |
|
---|
56 | private struct ContentStruct {
|
---|
57 | private string m_persistString;
|
---|
58 | public string PersistString {
|
---|
59 | get { return m_persistString; }
|
---|
60 | set { m_persistString = value; }
|
---|
61 | }
|
---|
62 |
|
---|
63 | private double m_autoHidePortion;
|
---|
64 | public double AutoHidePortion {
|
---|
65 | get { return m_autoHidePortion; }
|
---|
66 | set { m_autoHidePortion = value; }
|
---|
67 | }
|
---|
68 |
|
---|
69 | private bool m_isHidden;
|
---|
70 | public bool IsHidden {
|
---|
71 | get { return m_isHidden; }
|
---|
72 | set { m_isHidden = value; }
|
---|
73 | }
|
---|
74 |
|
---|
75 | private bool m_isFloat;
|
---|
76 | public bool IsFloat {
|
---|
77 | get { return m_isFloat; }
|
---|
78 | set { m_isFloat = value; }
|
---|
79 | }
|
---|
80 | }
|
---|
81 |
|
---|
82 | private struct PaneStruct {
|
---|
83 | private DockState m_dockState;
|
---|
84 | public DockState DockState {
|
---|
85 | get { return m_dockState; }
|
---|
86 | set { m_dockState = value; }
|
---|
87 | }
|
---|
88 |
|
---|
89 | private int m_indexActiveContent;
|
---|
90 | public int IndexActiveContent {
|
---|
91 | get { return m_indexActiveContent; }
|
---|
92 | set { m_indexActiveContent = value; }
|
---|
93 | }
|
---|
94 |
|
---|
95 | private int[] m_indexContents;
|
---|
96 | public int[] IndexContents {
|
---|
97 | get { return m_indexContents; }
|
---|
98 | set { m_indexContents = value; }
|
---|
99 | }
|
---|
100 |
|
---|
101 | private int m_zOrderIndex;
|
---|
102 | public int ZOrderIndex {
|
---|
103 | get { return m_zOrderIndex; }
|
---|
104 | set { m_zOrderIndex = value; }
|
---|
105 | }
|
---|
106 | }
|
---|
107 |
|
---|
108 | private struct NestedPane {
|
---|
109 | private int m_indexPane;
|
---|
110 | public int IndexPane {
|
---|
111 | get { return m_indexPane; }
|
---|
112 | set { m_indexPane = value; }
|
---|
113 | }
|
---|
114 |
|
---|
115 | private int m_indexPrevPane;
|
---|
116 | public int IndexPrevPane {
|
---|
117 | get { return m_indexPrevPane; }
|
---|
118 | set { m_indexPrevPane = value; }
|
---|
119 | }
|
---|
120 |
|
---|
121 | private DockAlignment m_alignment;
|
---|
122 | public DockAlignment Alignment {
|
---|
123 | get { return m_alignment; }
|
---|
124 | set { m_alignment = value; }
|
---|
125 | }
|
---|
126 |
|
---|
127 | private double m_proportion;
|
---|
128 | public double Proportion {
|
---|
129 | get { return m_proportion; }
|
---|
130 | set { m_proportion = value; }
|
---|
131 | }
|
---|
132 | }
|
---|
133 |
|
---|
134 | private struct DockWindowStruct {
|
---|
135 | private DockState m_dockState;
|
---|
136 | public DockState DockState {
|
---|
137 | get { return m_dockState; }
|
---|
138 | set { m_dockState = value; }
|
---|
139 | }
|
---|
140 |
|
---|
141 | private int m_zOrderIndex;
|
---|
142 | public int ZOrderIndex {
|
---|
143 | get { return m_zOrderIndex; }
|
---|
144 | set { m_zOrderIndex = value; }
|
---|
145 | }
|
---|
146 |
|
---|
147 | private NestedPane[] m_nestedPanes;
|
---|
148 | public NestedPane[] NestedPanes {
|
---|
149 | get { return m_nestedPanes; }
|
---|
150 | set { m_nestedPanes = value; }
|
---|
151 | }
|
---|
152 | }
|
---|
153 |
|
---|
154 | private struct FloatWindowStruct {
|
---|
155 | private Rectangle m_bounds;
|
---|
156 | public Rectangle Bounds {
|
---|
157 | get { return m_bounds; }
|
---|
158 | set { m_bounds = value; }
|
---|
159 | }
|
---|
160 |
|
---|
161 | private int m_zOrderIndex;
|
---|
162 | public int ZOrderIndex {
|
---|
163 | get { return m_zOrderIndex; }
|
---|
164 | set { m_zOrderIndex = value; }
|
---|
165 | }
|
---|
166 |
|
---|
167 | private NestedPane[] m_nestedPanes;
|
---|
168 | public NestedPane[] NestedPanes {
|
---|
169 | get { return m_nestedPanes; }
|
---|
170 | set { m_nestedPanes = value; }
|
---|
171 | }
|
---|
172 | }
|
---|
173 |
|
---|
174 | public static void SaveAsXml(DockPanel dockPanel, string fileName) {
|
---|
175 | SaveAsXml(dockPanel, fileName, Encoding.Unicode);
|
---|
176 | }
|
---|
177 |
|
---|
178 | public static void SaveAsXml(DockPanel dockPanel, string fileName, Encoding encoding) {
|
---|
179 | FileStream fs = new FileStream(fileName, FileMode.Create);
|
---|
180 | try {
|
---|
181 | SaveAsXml(dockPanel, fs, encoding);
|
---|
182 | }
|
---|
183 | finally {
|
---|
184 | fs.Close();
|
---|
185 | }
|
---|
186 | }
|
---|
187 |
|
---|
188 | public static void SaveAsXml(DockPanel dockPanel, Stream stream, Encoding encoding) {
|
---|
189 | SaveAsXml(dockPanel, stream, encoding, false);
|
---|
190 | }
|
---|
191 |
|
---|
192 | public static void SaveAsXml(DockPanel dockPanel, Stream stream, Encoding encoding, bool upstream) {
|
---|
193 | XmlTextWriter xmlOut = new XmlTextWriter(stream, encoding);
|
---|
194 |
|
---|
195 | // Use indenting for readability
|
---|
196 | xmlOut.Formatting = Formatting.Indented;
|
---|
197 |
|
---|
198 | if (!upstream)
|
---|
199 | xmlOut.WriteStartDocument();
|
---|
200 |
|
---|
201 | // Always begin file with identification and warning
|
---|
202 | xmlOut.WriteComment(Strings.DockPanel_Persistor_XmlFileComment1);
|
---|
203 | xmlOut.WriteComment(Strings.DockPanel_Persistor_XmlFileComment2);
|
---|
204 |
|
---|
205 | // Associate a version number with the root element so that future version of the code
|
---|
206 | // will be able to be backwards compatible or at least recognise out of date versions
|
---|
207 | xmlOut.WriteStartElement("DockPanel");
|
---|
208 | xmlOut.WriteAttributeString("FormatVersion", ConfigFileVersion);
|
---|
209 | xmlOut.WriteAttributeString("DockLeftPortion", dockPanel.DockLeftPortion.ToString(CultureInfo.InvariantCulture));
|
---|
210 | xmlOut.WriteAttributeString("DockRightPortion", dockPanel.DockRightPortion.ToString(CultureInfo.InvariantCulture));
|
---|
211 | xmlOut.WriteAttributeString("DockTopPortion", dockPanel.DockTopPortion.ToString(CultureInfo.InvariantCulture));
|
---|
212 | xmlOut.WriteAttributeString("DockBottomPortion", dockPanel.DockBottomPortion.ToString(CultureInfo.InvariantCulture));
|
---|
213 | xmlOut.WriteAttributeString("ActiveDocumentPane", dockPanel.Panes.IndexOf(dockPanel.ActiveDocumentPane).ToString(CultureInfo.InvariantCulture));
|
---|
214 | xmlOut.WriteAttributeString("ActivePane", dockPanel.Panes.IndexOf(dockPanel.ActivePane).ToString(CultureInfo.InvariantCulture));
|
---|
215 |
|
---|
216 | // Contents
|
---|
217 | xmlOut.WriteStartElement("Contents");
|
---|
218 | xmlOut.WriteAttributeString("Count", dockPanel.Contents.Count.ToString(CultureInfo.InvariantCulture));
|
---|
219 | foreach (IDockContent content in dockPanel.Contents) {
|
---|
220 | xmlOut.WriteStartElement("Content");
|
---|
221 | xmlOut.WriteAttributeString("ID", dockPanel.Contents.IndexOf(content).ToString(CultureInfo.InvariantCulture));
|
---|
222 | xmlOut.WriteAttributeString("PersistString", content.DockHandler.PersistString);
|
---|
223 | xmlOut.WriteAttributeString("AutoHidePortion", content.DockHandler.AutoHidePortion.ToString(CultureInfo.InvariantCulture));
|
---|
224 | xmlOut.WriteAttributeString("IsHidden", content.DockHandler.IsHidden.ToString(CultureInfo.InvariantCulture));
|
---|
225 | xmlOut.WriteAttributeString("IsFloat", content.DockHandler.IsFloat.ToString(CultureInfo.InvariantCulture));
|
---|
226 | xmlOut.WriteEndElement();
|
---|
227 | }
|
---|
228 | xmlOut.WriteEndElement();
|
---|
229 |
|
---|
230 | // Panes
|
---|
231 | xmlOut.WriteStartElement("Panes");
|
---|
232 | xmlOut.WriteAttributeString("Count", dockPanel.Panes.Count.ToString(CultureInfo.InvariantCulture));
|
---|
233 | foreach (DockPane pane in dockPanel.Panes) {
|
---|
234 | xmlOut.WriteStartElement("Pane");
|
---|
235 | xmlOut.WriteAttributeString("ID", dockPanel.Panes.IndexOf(pane).ToString(CultureInfo.InvariantCulture));
|
---|
236 | xmlOut.WriteAttributeString("DockState", pane.DockState.ToString());
|
---|
237 | xmlOut.WriteAttributeString("ActiveContent", dockPanel.Contents.IndexOf(pane.ActiveContent).ToString(CultureInfo.InvariantCulture));
|
---|
238 | xmlOut.WriteStartElement("Contents");
|
---|
239 | xmlOut.WriteAttributeString("Count", pane.Contents.Count.ToString(CultureInfo.InvariantCulture));
|
---|
240 | foreach (IDockContent content in pane.Contents) {
|
---|
241 | xmlOut.WriteStartElement("Content");
|
---|
242 | xmlOut.WriteAttributeString("ID", pane.Contents.IndexOf(content).ToString(CultureInfo.InvariantCulture));
|
---|
243 | xmlOut.WriteAttributeString("RefID", dockPanel.Contents.IndexOf(content).ToString(CultureInfo.InvariantCulture));
|
---|
244 | xmlOut.WriteEndElement();
|
---|
245 | }
|
---|
246 | xmlOut.WriteEndElement();
|
---|
247 | xmlOut.WriteEndElement();
|
---|
248 | }
|
---|
249 | xmlOut.WriteEndElement();
|
---|
250 |
|
---|
251 | // DockWindows
|
---|
252 | xmlOut.WriteStartElement("DockWindows");
|
---|
253 | int dockWindowId = 0;
|
---|
254 | foreach (DockWindow dw in dockPanel.DockWindows) {
|
---|
255 | xmlOut.WriteStartElement("DockWindow");
|
---|
256 | xmlOut.WriteAttributeString("ID", dockWindowId.ToString(CultureInfo.InvariantCulture));
|
---|
257 | dockWindowId++;
|
---|
258 | xmlOut.WriteAttributeString("DockState", dw.DockState.ToString());
|
---|
259 | xmlOut.WriteAttributeString("ZOrderIndex", dockPanel.Controls.IndexOf(dw).ToString(CultureInfo.InvariantCulture));
|
---|
260 | xmlOut.WriteStartElement("NestedPanes");
|
---|
261 | xmlOut.WriteAttributeString("Count", dw.NestedPanes.Count.ToString(CultureInfo.InvariantCulture));
|
---|
262 | foreach (DockPane pane in dw.NestedPanes) {
|
---|
263 | xmlOut.WriteStartElement("Pane");
|
---|
264 | xmlOut.WriteAttributeString("ID", dw.NestedPanes.IndexOf(pane).ToString(CultureInfo.InvariantCulture));
|
---|
265 | xmlOut.WriteAttributeString("RefID", dockPanel.Panes.IndexOf(pane).ToString(CultureInfo.InvariantCulture));
|
---|
266 | NestedDockingStatus status = pane.NestedDockingStatus;
|
---|
267 | xmlOut.WriteAttributeString("PrevPane", dockPanel.Panes.IndexOf(status.PreviousPane).ToString(CultureInfo.InvariantCulture));
|
---|
268 | xmlOut.WriteAttributeString("Alignment", status.Alignment.ToString());
|
---|
269 | xmlOut.WriteAttributeString("Proportion", status.Proportion.ToString(CultureInfo.InvariantCulture));
|
---|
270 | xmlOut.WriteEndElement();
|
---|
271 | }
|
---|
272 | xmlOut.WriteEndElement();
|
---|
273 | xmlOut.WriteEndElement();
|
---|
274 | }
|
---|
275 | xmlOut.WriteEndElement();
|
---|
276 |
|
---|
277 | // FloatWindows
|
---|
278 | RectangleConverter rectConverter = new RectangleConverter();
|
---|
279 | xmlOut.WriteStartElement("FloatWindows");
|
---|
280 | xmlOut.WriteAttributeString("Count", dockPanel.FloatWindows.Count.ToString(CultureInfo.InvariantCulture));
|
---|
281 | foreach (FloatWindow fw in dockPanel.FloatWindows) {
|
---|
282 | xmlOut.WriteStartElement("FloatWindow");
|
---|
283 | xmlOut.WriteAttributeString("ID", dockPanel.FloatWindows.IndexOf(fw).ToString(CultureInfo.InvariantCulture));
|
---|
284 | xmlOut.WriteAttributeString("Bounds", rectConverter.ConvertToInvariantString(fw.Bounds));
|
---|
285 | xmlOut.WriteAttributeString("ZOrderIndex", fw.DockPanel.FloatWindows.IndexOf(fw).ToString(CultureInfo.InvariantCulture));
|
---|
286 | xmlOut.WriteStartElement("NestedPanes");
|
---|
287 | xmlOut.WriteAttributeString("Count", fw.NestedPanes.Count.ToString(CultureInfo.InvariantCulture));
|
---|
288 | foreach (DockPane pane in fw.NestedPanes) {
|
---|
289 | xmlOut.WriteStartElement("Pane");
|
---|
290 | xmlOut.WriteAttributeString("ID", fw.NestedPanes.IndexOf(pane).ToString(CultureInfo.InvariantCulture));
|
---|
291 | xmlOut.WriteAttributeString("RefID", dockPanel.Panes.IndexOf(pane).ToString(CultureInfo.InvariantCulture));
|
---|
292 | NestedDockingStatus status = pane.NestedDockingStatus;
|
---|
293 | xmlOut.WriteAttributeString("PrevPane", dockPanel.Panes.IndexOf(status.PreviousPane).ToString(CultureInfo.InvariantCulture));
|
---|
294 | xmlOut.WriteAttributeString("Alignment", status.Alignment.ToString());
|
---|
295 | xmlOut.WriteAttributeString("Proportion", status.Proportion.ToString(CultureInfo.InvariantCulture));
|
---|
296 | xmlOut.WriteEndElement();
|
---|
297 | }
|
---|
298 | xmlOut.WriteEndElement();
|
---|
299 | xmlOut.WriteEndElement();
|
---|
300 | }
|
---|
301 | xmlOut.WriteEndElement(); // </FloatWindows>
|
---|
302 |
|
---|
303 | xmlOut.WriteEndElement();
|
---|
304 |
|
---|
305 | if (!upstream) {
|
---|
306 | xmlOut.WriteEndDocument();
|
---|
307 | xmlOut.Close();
|
---|
308 | } else
|
---|
309 | xmlOut.Flush();
|
---|
310 | }
|
---|
311 |
|
---|
312 | public static void LoadFromXml(DockPanel dockPanel, string fileName, DeserializeDockContent deserializeContent) {
|
---|
313 | FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read);
|
---|
314 | try {
|
---|
315 | LoadFromXml(dockPanel, fs, deserializeContent);
|
---|
316 | }
|
---|
317 | finally {
|
---|
318 | fs.Close();
|
---|
319 | }
|
---|
320 | }
|
---|
321 |
|
---|
322 | public static void LoadFromXml(DockPanel dockPanel, Stream stream, DeserializeDockContent deserializeContent) {
|
---|
323 | LoadFromXml(dockPanel, stream, deserializeContent, true);
|
---|
324 | }
|
---|
325 |
|
---|
326 | private static ContentStruct[] LoadContents(XmlTextReader xmlIn) {
|
---|
327 | int countOfContents = Convert.ToInt32(xmlIn.GetAttribute("Count"), CultureInfo.InvariantCulture);
|
---|
328 | ContentStruct[] contents = new ContentStruct[countOfContents];
|
---|
329 | MoveToNextElement(xmlIn);
|
---|
330 | for (int i = 0; i < countOfContents; i++) {
|
---|
331 | int id = Convert.ToInt32(xmlIn.GetAttribute("ID"), CultureInfo.InvariantCulture);
|
---|
332 | if (xmlIn.Name != "Content" || id != i)
|
---|
333 | throw new ArgumentException(Strings.DockPanel_LoadFromXml_InvalidXmlFormat);
|
---|
334 |
|
---|
335 | contents[i].PersistString = xmlIn.GetAttribute("PersistString");
|
---|
336 | contents[i].AutoHidePortion = Convert.ToDouble(xmlIn.GetAttribute("AutoHidePortion"), CultureInfo.InvariantCulture);
|
---|
337 | contents[i].IsHidden = Convert.ToBoolean(xmlIn.GetAttribute("IsHidden"), CultureInfo.InvariantCulture);
|
---|
338 | contents[i].IsFloat = Convert.ToBoolean(xmlIn.GetAttribute("IsFloat"), CultureInfo.InvariantCulture);
|
---|
339 | MoveToNextElement(xmlIn);
|
---|
340 | }
|
---|
341 |
|
---|
342 | return contents;
|
---|
343 | }
|
---|
344 |
|
---|
345 | private static PaneStruct[] LoadPanes(XmlTextReader xmlIn) {
|
---|
346 | EnumConverter dockStateConverter = new EnumConverter(typeof(DockState));
|
---|
347 | int countOfPanes = Convert.ToInt32(xmlIn.GetAttribute("Count"), CultureInfo.InvariantCulture);
|
---|
348 | PaneStruct[] panes = new PaneStruct[countOfPanes];
|
---|
349 | MoveToNextElement(xmlIn);
|
---|
350 | for (int i = 0; i < countOfPanes; i++) {
|
---|
351 | int id = Convert.ToInt32(xmlIn.GetAttribute("ID"), CultureInfo.InvariantCulture);
|
---|
352 | if (xmlIn.Name != "Pane" || id != i)
|
---|
353 | throw new ArgumentException(Strings.DockPanel_LoadFromXml_InvalidXmlFormat);
|
---|
354 |
|
---|
355 | panes[i].DockState = (DockState)dockStateConverter.ConvertFrom(xmlIn.GetAttribute("DockState"));
|
---|
356 | panes[i].IndexActiveContent = Convert.ToInt32(xmlIn.GetAttribute("ActiveContent"), CultureInfo.InvariantCulture);
|
---|
357 | panes[i].ZOrderIndex = -1;
|
---|
358 |
|
---|
359 | MoveToNextElement(xmlIn);
|
---|
360 | if (xmlIn.Name != "Contents")
|
---|
361 | throw new ArgumentException(Strings.DockPanel_LoadFromXml_InvalidXmlFormat);
|
---|
362 | int countOfPaneContents = Convert.ToInt32(xmlIn.GetAttribute("Count"), CultureInfo.InvariantCulture);
|
---|
363 | panes[i].IndexContents = new int[countOfPaneContents];
|
---|
364 | MoveToNextElement(xmlIn);
|
---|
365 | for (int j = 0; j < countOfPaneContents; j++) {
|
---|
366 | int id2 = Convert.ToInt32(xmlIn.GetAttribute("ID"), CultureInfo.InvariantCulture);
|
---|
367 | if (xmlIn.Name != "Content" || id2 != j)
|
---|
368 | throw new ArgumentException(Strings.DockPanel_LoadFromXml_InvalidXmlFormat);
|
---|
369 |
|
---|
370 | panes[i].IndexContents[j] = Convert.ToInt32(xmlIn.GetAttribute("RefID"), CultureInfo.InvariantCulture);
|
---|
371 | MoveToNextElement(xmlIn);
|
---|
372 | }
|
---|
373 | }
|
---|
374 |
|
---|
375 | return panes;
|
---|
376 | }
|
---|
377 |
|
---|
378 | private static DockWindowStruct[] LoadDockWindows(XmlTextReader xmlIn, DockPanel dockPanel) {
|
---|
379 | EnumConverter dockStateConverter = new EnumConverter(typeof(DockState));
|
---|
380 | EnumConverter dockAlignmentConverter = new EnumConverter(typeof(DockAlignment));
|
---|
381 | int countOfDockWindows = dockPanel.DockWindows.Count;
|
---|
382 | DockWindowStruct[] dockWindows = new DockWindowStruct[countOfDockWindows];
|
---|
383 | MoveToNextElement(xmlIn);
|
---|
384 | for (int i = 0; i < countOfDockWindows; i++) {
|
---|
385 | int id = Convert.ToInt32(xmlIn.GetAttribute("ID"), CultureInfo.InvariantCulture);
|
---|
386 | if (xmlIn.Name != "DockWindow" || id != i)
|
---|
387 | throw new ArgumentException(Strings.DockPanel_LoadFromXml_InvalidXmlFormat);
|
---|
388 |
|
---|
389 | dockWindows[i].DockState = (DockState)dockStateConverter.ConvertFrom(xmlIn.GetAttribute("DockState"));
|
---|
390 | dockWindows[i].ZOrderIndex = Convert.ToInt32(xmlIn.GetAttribute("ZOrderIndex"), CultureInfo.InvariantCulture);
|
---|
391 | MoveToNextElement(xmlIn);
|
---|
392 | if (xmlIn.Name != "DockList" && xmlIn.Name != "NestedPanes")
|
---|
393 | throw new ArgumentException(Strings.DockPanel_LoadFromXml_InvalidXmlFormat);
|
---|
394 | int countOfNestedPanes = Convert.ToInt32(xmlIn.GetAttribute("Count"), CultureInfo.InvariantCulture);
|
---|
395 | dockWindows[i].NestedPanes = new NestedPane[countOfNestedPanes];
|
---|
396 | MoveToNextElement(xmlIn);
|
---|
397 | for (int j = 0; j < countOfNestedPanes; j++) {
|
---|
398 | int id2 = Convert.ToInt32(xmlIn.GetAttribute("ID"), CultureInfo.InvariantCulture);
|
---|
399 | if (xmlIn.Name != "Pane" || id2 != j)
|
---|
400 | throw new ArgumentException(Strings.DockPanel_LoadFromXml_InvalidXmlFormat);
|
---|
401 | dockWindows[i].NestedPanes[j].IndexPane = Convert.ToInt32(xmlIn.GetAttribute("RefID"), CultureInfo.InvariantCulture);
|
---|
402 | dockWindows[i].NestedPanes[j].IndexPrevPane = Convert.ToInt32(xmlIn.GetAttribute("PrevPane"), CultureInfo.InvariantCulture);
|
---|
403 | dockWindows[i].NestedPanes[j].Alignment = (DockAlignment)dockAlignmentConverter.ConvertFrom(xmlIn.GetAttribute("Alignment"));
|
---|
404 | dockWindows[i].NestedPanes[j].Proportion = Convert.ToDouble(xmlIn.GetAttribute("Proportion"), CultureInfo.InvariantCulture);
|
---|
405 | MoveToNextElement(xmlIn);
|
---|
406 | }
|
---|
407 | }
|
---|
408 |
|
---|
409 | return dockWindows;
|
---|
410 | }
|
---|
411 |
|
---|
412 | private static FloatWindowStruct[] LoadFloatWindows(XmlTextReader xmlIn) {
|
---|
413 | EnumConverter dockAlignmentConverter = new EnumConverter(typeof(DockAlignment));
|
---|
414 | RectangleConverter rectConverter = new RectangleConverter();
|
---|
415 | int countOfFloatWindows = Convert.ToInt32(xmlIn.GetAttribute("Count"), CultureInfo.InvariantCulture);
|
---|
416 | FloatWindowStruct[] floatWindows = new FloatWindowStruct[countOfFloatWindows];
|
---|
417 | MoveToNextElement(xmlIn);
|
---|
418 | for (int i = 0; i < countOfFloatWindows; i++) {
|
---|
419 | int id = Convert.ToInt32(xmlIn.GetAttribute("ID"), CultureInfo.InvariantCulture);
|
---|
420 | if (xmlIn.Name != "FloatWindow" || id != i)
|
---|
421 | throw new ArgumentException(Strings.DockPanel_LoadFromXml_InvalidXmlFormat);
|
---|
422 |
|
---|
423 | floatWindows[i].Bounds = (Rectangle)rectConverter.ConvertFromInvariantString(xmlIn.GetAttribute("Bounds"));
|
---|
424 | floatWindows[i].ZOrderIndex = Convert.ToInt32(xmlIn.GetAttribute("ZOrderIndex"), CultureInfo.InvariantCulture);
|
---|
425 | MoveToNextElement(xmlIn);
|
---|
426 | if (xmlIn.Name != "DockList" && xmlIn.Name != "NestedPanes")
|
---|
427 | throw new ArgumentException(Strings.DockPanel_LoadFromXml_InvalidXmlFormat);
|
---|
428 | int countOfNestedPanes = Convert.ToInt32(xmlIn.GetAttribute("Count"), CultureInfo.InvariantCulture);
|
---|
429 | floatWindows[i].NestedPanes = new NestedPane[countOfNestedPanes];
|
---|
430 | MoveToNextElement(xmlIn);
|
---|
431 | for (int j = 0; j < countOfNestedPanes; j++) {
|
---|
432 | int id2 = Convert.ToInt32(xmlIn.GetAttribute("ID"), CultureInfo.InvariantCulture);
|
---|
433 | if (xmlIn.Name != "Pane" || id2 != j)
|
---|
434 | throw new ArgumentException(Strings.DockPanel_LoadFromXml_InvalidXmlFormat);
|
---|
435 | floatWindows[i].NestedPanes[j].IndexPane = Convert.ToInt32(xmlIn.GetAttribute("RefID"), CultureInfo.InvariantCulture);
|
---|
436 | floatWindows[i].NestedPanes[j].IndexPrevPane = Convert.ToInt32(xmlIn.GetAttribute("PrevPane"), CultureInfo.InvariantCulture);
|
---|
437 | floatWindows[i].NestedPanes[j].Alignment = (DockAlignment)dockAlignmentConverter.ConvertFrom(xmlIn.GetAttribute("Alignment"));
|
---|
438 | floatWindows[i].NestedPanes[j].Proportion = Convert.ToDouble(xmlIn.GetAttribute("Proportion"), CultureInfo.InvariantCulture);
|
---|
439 | MoveToNextElement(xmlIn);
|
---|
440 | }
|
---|
441 | }
|
---|
442 |
|
---|
443 | return floatWindows;
|
---|
444 | }
|
---|
445 |
|
---|
446 | public static void LoadFromXml(DockPanel dockPanel, Stream stream, DeserializeDockContent deserializeContent, bool closeStream) {
|
---|
447 |
|
---|
448 | if (dockPanel.Contents.Count != 0)
|
---|
449 | throw new InvalidOperationException(Strings.DockPanel_LoadFromXml_AlreadyInitialized);
|
---|
450 |
|
---|
451 | XmlTextReader xmlIn = new XmlTextReader(stream);
|
---|
452 | xmlIn.WhitespaceHandling = WhitespaceHandling.None;
|
---|
453 | xmlIn.MoveToContent();
|
---|
454 |
|
---|
455 | while (!xmlIn.Name.Equals("DockPanel")) {
|
---|
456 | if (!MoveToNextElement(xmlIn))
|
---|
457 | throw new ArgumentException(Strings.DockPanel_LoadFromXml_InvalidXmlFormat);
|
---|
458 | }
|
---|
459 |
|
---|
460 | string formatVersion = xmlIn.GetAttribute("FormatVersion");
|
---|
461 | if (!IsFormatVersionValid(formatVersion))
|
---|
462 | throw new ArgumentException(Strings.DockPanel_LoadFromXml_InvalidFormatVersion);
|
---|
463 |
|
---|
464 | DockPanelStruct dockPanelStruct = new DockPanelStruct();
|
---|
465 | dockPanelStruct.DockLeftPortion = Convert.ToDouble(xmlIn.GetAttribute("DockLeftPortion"), CultureInfo.InvariantCulture);
|
---|
466 | dockPanelStruct.DockRightPortion = Convert.ToDouble(xmlIn.GetAttribute("DockRightPortion"), CultureInfo.InvariantCulture);
|
---|
467 | dockPanelStruct.DockTopPortion = Convert.ToDouble(xmlIn.GetAttribute("DockTopPortion"), CultureInfo.InvariantCulture);
|
---|
468 | dockPanelStruct.DockBottomPortion = Convert.ToDouble(xmlIn.GetAttribute("DockBottomPortion"), CultureInfo.InvariantCulture);
|
---|
469 | dockPanelStruct.IndexActiveDocumentPane = Convert.ToInt32(xmlIn.GetAttribute("ActiveDocumentPane"), CultureInfo.InvariantCulture);
|
---|
470 | dockPanelStruct.IndexActivePane = Convert.ToInt32(xmlIn.GetAttribute("ActivePane"), CultureInfo.InvariantCulture);
|
---|
471 |
|
---|
472 | // Load Contents
|
---|
473 | MoveToNextElement(xmlIn);
|
---|
474 | if (xmlIn.Name != "Contents")
|
---|
475 | throw new ArgumentException(Strings.DockPanel_LoadFromXml_InvalidXmlFormat);
|
---|
476 | ContentStruct[] contents = LoadContents(xmlIn);
|
---|
477 |
|
---|
478 | // Load Panes
|
---|
479 | if (xmlIn.Name != "Panes")
|
---|
480 | throw new ArgumentException(Strings.DockPanel_LoadFromXml_InvalidXmlFormat);
|
---|
481 | PaneStruct[] panes = LoadPanes(xmlIn);
|
---|
482 |
|
---|
483 | // Load DockWindows
|
---|
484 | if (xmlIn.Name != "DockWindows")
|
---|
485 | throw new ArgumentException(Strings.DockPanel_LoadFromXml_InvalidXmlFormat);
|
---|
486 | DockWindowStruct[] dockWindows = LoadDockWindows(xmlIn, dockPanel);
|
---|
487 |
|
---|
488 | // Load FloatWindows
|
---|
489 | if (xmlIn.Name != "FloatWindows")
|
---|
490 | throw new ArgumentException(Strings.DockPanel_LoadFromXml_InvalidXmlFormat);
|
---|
491 | FloatWindowStruct[] floatWindows = LoadFloatWindows(xmlIn);
|
---|
492 |
|
---|
493 | if (closeStream)
|
---|
494 | xmlIn.Close();
|
---|
495 |
|
---|
496 | dockPanel.SuspendLayout(true);
|
---|
497 |
|
---|
498 | dockPanel.DockLeftPortion = dockPanelStruct.DockLeftPortion;
|
---|
499 | dockPanel.DockRightPortion = dockPanelStruct.DockRightPortion;
|
---|
500 | dockPanel.DockTopPortion = dockPanelStruct.DockTopPortion;
|
---|
501 | dockPanel.DockBottomPortion = dockPanelStruct.DockBottomPortion;
|
---|
502 |
|
---|
503 | // Set DockWindow ZOrders
|
---|
504 | int prevMaxDockWindowZOrder = int.MaxValue;
|
---|
505 | for (int i = 0; i < dockWindows.Length; i++) {
|
---|
506 | int maxDockWindowZOrder = -1;
|
---|
507 | int index = -1;
|
---|
508 | for (int j = 0; j < dockWindows.Length; j++) {
|
---|
509 | if (dockWindows[j].ZOrderIndex > maxDockWindowZOrder && dockWindows[j].ZOrderIndex < prevMaxDockWindowZOrder) {
|
---|
510 | maxDockWindowZOrder = dockWindows[j].ZOrderIndex;
|
---|
511 | index = j;
|
---|
512 | }
|
---|
513 | }
|
---|
514 |
|
---|
515 | dockPanel.DockWindows[dockWindows[index].DockState].BringToFront();
|
---|
516 | prevMaxDockWindowZOrder = maxDockWindowZOrder;
|
---|
517 | }
|
---|
518 |
|
---|
519 | // Create Contents
|
---|
520 | for (int i = 0; i < contents.Length; i++) {
|
---|
521 | IDockContent content = deserializeContent(contents[i].PersistString);
|
---|
522 | if (content == null)
|
---|
523 | content = new DummyContent();
|
---|
524 | content.DockHandler.DockPanel = dockPanel;
|
---|
525 | content.DockHandler.AutoHidePortion = contents[i].AutoHidePortion;
|
---|
526 | content.DockHandler.IsHidden = true;
|
---|
527 | content.DockHandler.IsFloat = contents[i].IsFloat;
|
---|
528 | }
|
---|
529 |
|
---|
530 | // Create panes
|
---|
531 | for (int i = 0; i < panes.Length; i++) {
|
---|
532 | DockPane pane = null;
|
---|
533 | for (int j = 0; j < panes[i].IndexContents.Length; j++) {
|
---|
534 | IDockContent content = dockPanel.Contents[panes[i].IndexContents[j]];
|
---|
535 | if (j == 0)
|
---|
536 | pane = dockPanel.DockPaneFactory.CreateDockPane(content, panes[i].DockState, false);
|
---|
537 | else if (panes[i].DockState == DockState.Float)
|
---|
538 | content.DockHandler.FloatPane = pane;
|
---|
539 | else
|
---|
540 | content.DockHandler.PanelPane = pane;
|
---|
541 | }
|
---|
542 | }
|
---|
543 |
|
---|
544 | // Assign Panes to DockWindows
|
---|
545 | for (int i = 0; i < dockWindows.Length; i++) {
|
---|
546 | for (int j = 0; j < dockWindows[i].NestedPanes.Length; j++) {
|
---|
547 | DockWindow dw = dockPanel.DockWindows[dockWindows[i].DockState];
|
---|
548 | int indexPane = dockWindows[i].NestedPanes[j].IndexPane;
|
---|
549 | DockPane pane = dockPanel.Panes[indexPane];
|
---|
550 | int indexPrevPane = dockWindows[i].NestedPanes[j].IndexPrevPane;
|
---|
551 | DockPane prevPane = (indexPrevPane == -1) ? dw.NestedPanes.GetDefaultPreviousPane(pane) : dockPanel.Panes[indexPrevPane];
|
---|
552 | DockAlignment alignment = dockWindows[i].NestedPanes[j].Alignment;
|
---|
553 | double proportion = dockWindows[i].NestedPanes[j].Proportion;
|
---|
554 | pane.DockTo(dw, prevPane, alignment, proportion);
|
---|
555 | if (panes[indexPane].DockState == dw.DockState)
|
---|
556 | panes[indexPane].ZOrderIndex = dockWindows[i].ZOrderIndex;
|
---|
557 | }
|
---|
558 | }
|
---|
559 |
|
---|
560 | // Create float windows
|
---|
561 | for (int i = 0; i < floatWindows.Length; i++) {
|
---|
562 | FloatWindow fw = null;
|
---|
563 | for (int j = 0; j < floatWindows[i].NestedPanes.Length; j++) {
|
---|
564 | int indexPane = floatWindows[i].NestedPanes[j].IndexPane;
|
---|
565 | DockPane pane = dockPanel.Panes[indexPane];
|
---|
566 | if (j == 0)
|
---|
567 | fw = dockPanel.FloatWindowFactory.CreateFloatWindow(dockPanel, pane, floatWindows[i].Bounds);
|
---|
568 | else {
|
---|
569 | int indexPrevPane = floatWindows[i].NestedPanes[j].IndexPrevPane;
|
---|
570 | DockPane prevPane = indexPrevPane == -1 ? null : dockPanel.Panes[indexPrevPane];
|
---|
571 | DockAlignment alignment = floatWindows[i].NestedPanes[j].Alignment;
|
---|
572 | double proportion = floatWindows[i].NestedPanes[j].Proportion;
|
---|
573 | pane.DockTo(fw, prevPane, alignment, proportion);
|
---|
574 | }
|
---|
575 |
|
---|
576 | if (panes[indexPane].DockState == fw.DockState)
|
---|
577 | panes[indexPane].ZOrderIndex = floatWindows[i].ZOrderIndex;
|
---|
578 | }
|
---|
579 | }
|
---|
580 |
|
---|
581 | // sort IDockContent by its Pane's ZOrder
|
---|
582 | int[] sortedContents = null;
|
---|
583 | if (contents.Length > 0) {
|
---|
584 | sortedContents = new int[contents.Length];
|
---|
585 | for (int i = 0; i < contents.Length; i++)
|
---|
586 | sortedContents[i] = i;
|
---|
587 |
|
---|
588 | int lastDocument = contents.Length;
|
---|
589 | for (int i = 0; i < contents.Length - 1; i++) {
|
---|
590 | for (int j = i + 1; j < contents.Length; j++) {
|
---|
591 | DockPane pane1 = dockPanel.Contents[sortedContents[i]].DockHandler.Pane;
|
---|
592 | int ZOrderIndex1 = pane1 == null ? 0 : panes[dockPanel.Panes.IndexOf(pane1)].ZOrderIndex;
|
---|
593 | DockPane pane2 = dockPanel.Contents[sortedContents[j]].DockHandler.Pane;
|
---|
594 | int ZOrderIndex2 = pane2 == null ? 0 : panes[dockPanel.Panes.IndexOf(pane2)].ZOrderIndex;
|
---|
595 | if (ZOrderIndex1 > ZOrderIndex2) {
|
---|
596 | int temp = sortedContents[i];
|
---|
597 | sortedContents[i] = sortedContents[j];
|
---|
598 | sortedContents[j] = temp;
|
---|
599 | }
|
---|
600 | }
|
---|
601 | }
|
---|
602 | }
|
---|
603 |
|
---|
604 | // show non-document IDockContent first to avoid screen flickers
|
---|
605 | for (int i = 0; i < contents.Length; i++) {
|
---|
606 | IDockContent content = dockPanel.Contents[sortedContents[i]];
|
---|
607 | if (content.DockHandler.Pane != null && content.DockHandler.Pane.DockState != DockState.Document)
|
---|
608 | content.DockHandler.IsHidden = contents[sortedContents[i]].IsHidden;
|
---|
609 | }
|
---|
610 |
|
---|
611 | // after all non-document IDockContent, show document IDockContent
|
---|
612 | for (int i = 0; i < contents.Length; i++) {
|
---|
613 | IDockContent content = dockPanel.Contents[sortedContents[i]];
|
---|
614 | if (content.DockHandler.Pane != null && content.DockHandler.Pane.DockState == DockState.Document)
|
---|
615 | content.DockHandler.IsHidden = contents[sortedContents[i]].IsHidden;
|
---|
616 | }
|
---|
617 |
|
---|
618 | for (int i = 0; i < panes.Length; i++)
|
---|
619 | dockPanel.Panes[i].ActiveContent = panes[i].IndexActiveContent == -1 ? null : dockPanel.Contents[panes[i].IndexActiveContent];
|
---|
620 |
|
---|
621 | if (dockPanelStruct.IndexActiveDocumentPane != -1)
|
---|
622 | dockPanel.Panes[dockPanelStruct.IndexActiveDocumentPane].Activate();
|
---|
623 |
|
---|
624 | if (dockPanelStruct.IndexActivePane != -1)
|
---|
625 | dockPanel.Panes[dockPanelStruct.IndexActivePane].Activate();
|
---|
626 |
|
---|
627 | for (int i = dockPanel.Contents.Count - 1; i >= 0; i--)
|
---|
628 | if (dockPanel.Contents[i] is DummyContent)
|
---|
629 | dockPanel.Contents[i].DockHandler.Form.Close();
|
---|
630 |
|
---|
631 | dockPanel.ResumeLayout(true, true);
|
---|
632 | }
|
---|
633 |
|
---|
634 | private static bool MoveToNextElement(XmlTextReader xmlIn) {
|
---|
635 | if (!xmlIn.Read())
|
---|
636 | return false;
|
---|
637 |
|
---|
638 | while (xmlIn.NodeType == XmlNodeType.EndElement) {
|
---|
639 | if (!xmlIn.Read())
|
---|
640 | return false;
|
---|
641 | }
|
---|
642 |
|
---|
643 | return true;
|
---|
644 | }
|
---|
645 |
|
---|
646 | private static bool IsFormatVersionValid(string formatVersion) {
|
---|
647 | if (formatVersion == ConfigFileVersion)
|
---|
648 | return true;
|
---|
649 |
|
---|
650 | foreach (string s in CompatibleConfigFileVersions)
|
---|
651 | if (s == formatVersion)
|
---|
652 | return true;
|
---|
653 |
|
---|
654 | return false;
|
---|
655 | }
|
---|
656 | }
|
---|
657 |
|
---|
658 | public void SaveAsXml(string fileName) {
|
---|
659 | Persistor.SaveAsXml(this, fileName);
|
---|
660 | }
|
---|
661 |
|
---|
662 | public void SaveAsXml(string fileName, Encoding encoding) {
|
---|
663 | Persistor.SaveAsXml(this, fileName, encoding);
|
---|
664 | }
|
---|
665 |
|
---|
666 | public void SaveAsXml(Stream stream, Encoding encoding) {
|
---|
667 | Persistor.SaveAsXml(this, stream, encoding);
|
---|
668 | }
|
---|
669 |
|
---|
670 | public void SaveAsXml(Stream stream, Encoding encoding, bool upstream) {
|
---|
671 | Persistor.SaveAsXml(this, stream, encoding, upstream);
|
---|
672 | }
|
---|
673 |
|
---|
674 | public void LoadFromXml(string fileName, DeserializeDockContent deserializeContent) {
|
---|
675 | Persistor.LoadFromXml(this, fileName, deserializeContent);
|
---|
676 | }
|
---|
677 |
|
---|
678 | public void LoadFromXml(Stream stream, DeserializeDockContent deserializeContent) {
|
---|
679 | Persistor.LoadFromXml(this, stream, deserializeContent);
|
---|
680 | }
|
---|
681 |
|
---|
682 | public void LoadFromXml(Stream stream, DeserializeDockContent deserializeContent, bool closeStream) {
|
---|
683 | Persistor.LoadFromXml(this, stream, deserializeContent, closeStream);
|
---|
684 | }
|
---|
685 | }
|
---|
686 | }
|
---|