aboutsummaryrefslogtreecommitdiffstatsci
path: root/src/GraphicObjects/DockStack.cs
diff options
context:
space:
mode:
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>2018-12-04 14:09:07 +0100
committerJean-Philippe Bruyère <jp_bruyere@hotmail.com>2018-12-04 14:09:07 +0100
commit9d381671ec0b1266448eddbf4c4935cdc7d23a9f (patch)
tree34e9b4b0296eea8dba03024491934413bcd54083 /src/GraphicObjects/DockStack.cs
parenta64627699d4919d389522d92032ce4f05704d313 (diff)
docking save/restore; use image surfaces as cache for graphic object instead of backend similar which blink too much
Diffstat (limited to 'src/GraphicObjects/DockStack.cs')
-rw-r--r--src/GraphicObjects/DockStack.cs96
1 files changed, 96 insertions, 0 deletions
diff --git a/src/GraphicObjects/DockStack.cs b/src/GraphicObjects/DockStack.cs
index f2174024..aa7c33da 100644
--- a/src/GraphicObjects/DockStack.cs
+++ b/src/GraphicObjects/DockStack.cs
@@ -26,6 +26,8 @@
using System;
using Crow.IML;
using System.Linq;
+using System.Text;
+using System.IO;
namespace Crow
{
@@ -369,6 +371,100 @@ namespace Crow
if (dw != null)
dw.DockingPosition = (Orientation == Orientation.Horizontal ? Alignment.Right : Alignment.Bottom);
}
+
+ //read next value in config string until next ';'
+ string getConfAttrib (string conf, ref int i) {
+ int nextI = conf.Substring (i).IndexOf (';');
+ string tmp = conf.Substring (i, nextI);
+ i += nextI + 1;
+ return tmp;
+ }
+ /// <summary>
+ /// Imports the config.
+ /// </summary>
+ /// <param name="conf">Conf.</param>
+ /// <param name="dataSource">Data source for the docked windows</param>
+ public void ImportConfig (string conf, object dataSource = null) {
+ lock (IFace.UpdateMutex) {
+ ClearChildren ();
+ stretchedChild = null;
+ int i = 0;
+ Orientation = (Orientation)Enum.Parse (typeof(Orientation), getConfAttrib (conf, ref i));
+ importConfig (conf, ref i, dataSource);
+ }
+ }
+ public string ExportConfig () {
+ return Orientation.ToString() + ";" + exportConfig();
+ }
+ void importConfig (string conf, ref int i, object dataSource) {
+ if (conf [i++] != '(')
+ return;
+ while (i < conf.Length - 4) {
+ string sc = conf.Substring (i, 4);
+ i += 4;
+ switch (sc) {
+ case "WIN;":
+ DockWindow dw = null;
+ string wName = getConfAttrib (conf, ref i);
+ try {
+ dw = IFace.Load (wName) as DockWindow;
+ } catch {
+ dw = new DockWindow (IFace);
+ }
+
+ dw.Name = wName;
+ dw.Width = Measure.Parse (getConfAttrib (conf, ref i));
+ dw.Height = Measure.Parse (getConfAttrib (conf, ref i));
+ dw.DockingPosition = (Alignment)Enum.Parse (typeof(Alignment), getConfAttrib (conf, ref i));
+ dw.IsDocked = true;
+ dw.DataSource = dataSource;
+ this.AddChild (dw);
+
+ break;
+ case "STK;":
+ DockStack ds = new DockStack (IFace);
+ ds.Width = Measure.Parse (getConfAttrib (conf, ref i));
+ ds.Height = Measure.Parse (getConfAttrib (conf, ref i));
+ ds.Orientation = (Orientation)Enum.Parse (typeof(Orientation), getConfAttrib (conf, ref i));
+
+ this.AddChild (ds);
+
+ ds.importConfig (conf, ref i, dataSource);
+ break;
+ case "SPL;":
+ Splitter sp = new Splitter (IFace);
+ sp.Width = Measure.Parse (getConfAttrib (conf, ref i));
+ sp.Height = Measure.Parse (getConfAttrib (conf, ref i));
+ sp.Thickness = int.Parse (getConfAttrib (conf, ref i));
+ this.AddChild (sp);
+ break;
+ }
+ char nextC = conf [i++];
+ if (nextC == ')')
+ break;
+ }
+ }
+ string exportConfig () {
+ StringBuilder tmp = new StringBuilder("(");
+
+ for (int i = 0; i < Children.Count; i++) {
+ if (Children [i] is DockWindow) {
+ DockWindow dw = Children [i] as DockWindow;
+ tmp.Append (string.Format("WIN;{0};{1};{2};{3};",dw.Name, dw.Width, dw.Height, dw.DockingPosition));
+ } else if (Children [i] is DockStack) {
+ DockStack ds = Children [i] as DockStack;
+ tmp.Append (string.Format("STK;{0};{1};{2};{3}", ds.Width, ds.Height, ds.Orientation, ds.exportConfig()));
+ } else if (Children [i] is Splitter) {
+ Splitter sp = Children [i] as Splitter;
+ tmp.Append (string.Format("SPL;{0};{1};{2};", sp.Width, sp.Height, sp.Thickness));
+ }
+ if (i < Children.Count - 1)
+ tmp.Append ("|");
+ }
+
+ tmp.Append (")");
+ return tmp.ToString ();
+ }
}
}