]> O.S.I.I.S - jp/crow.git/commitdiff
Group layouting debug (x positionning of children sized with fit)
authorjpbruyere <jp.bruyere@hotmail.com>
Wed, 23 Dec 2015 11:41:41 +0000 (12:41 +0100)
committerjpbruyere <jp.bruyere@hotmail.com>
Wed, 23 Dec 2015 11:41:41 +0000 (12:41 +0100)
Prevent multiple loading of template and default values while creating XmlSerializer(type)
Removed DynamicClass functions, not used for now.
Divers debug

16 files changed:
GOLib.csproj
Tests/GOLIBTest_Listbox.cs
Tests/GOLIBTest_TypeViewer.cs
Tests/GOLIBTests.cs
Tests/Interfaces/testAll.goml [new file with mode: 0755]
Tests/Interfaces/testTypeViewer.goml
Tests/Interfaces/test_Listbox.goml
Tests/Tests.csproj
src/GraphicObjects/GraphicObject.cs
src/GraphicObjects/Group.cs
src/GraphicObjects/ListBox.cs
src/GraphicObjects/PrivateContainer.cs
src/GraphicObjects/TemplatedControl.cs
src/Interface.cs
src/LayoutingQueueItem.cs
src/OpenTKGameWindow.cs

index 652fccc8eedeff13be4c6411d2b5e5c2968d04ad..35bd69dc7dcbf736511cadc60126aa4df157e5a3 100644 (file)
@@ -46,7 +46,7 @@
   </PropertyGroup>\r
   <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">\r
     <OutputPath>bin\Debug</OutputPath>\r
-    <DefineConstants>TRACE;DEBUG;__linux__;DEBUG_LOAD_TIME=1</DefineConstants>\r
+    <DefineConstants>TRACE;DEBUG;__linux__;DEBUG_LOAD_TIME;DEBUG_LAYOUTING</DefineConstants>\r
   </PropertyGroup>\r
   <!--  <PropertyGroup Condition=" '$(Platform)' == 'Linux_x86' ">\r
     <DefineConstants>__linux__</DefineConstants>\r
index 1c19338e64c778c280ac3efffcd92c156b04393b..b3cda6c575c5476dab705b31859a06a5bb0f2187 100644 (file)
@@ -64,22 +64,23 @@ namespace test
 //                             new ClsItem("string 2"),\r
 //                             new ClsItem("string 3")\r
 //                     });\r
-               public List<string> TestList = new List<string>( new string[] \r
+               public List<string> TestList;/* = new List<string>( new string[] \r
                        {\r
                                "string 1",\r
                                "string 2",\r
                                "string 3"\r
-                       });     \r
+                       });     */\r
 \r
                protected override void OnLoad (EventArgs e)\r
                {\r
                        base.OnLoad (e);\r
 \r
-                       //TestList = Directory.GetFileSystemEntries("/mnt/data/MagicCardDataBase/a/", "*.txt",SearchOption.AllDirectories).ToList();\r
-                       LoadInterface("Interfaces/test_Listbox.goml");\r
+                       TestList = Directory.GetFileSystemEntries("/home/jp/tmp/mtgdata/a", "*.txt",SearchOption.AllDirectories).ToList();\r
+                       GraphicObject tlb = LoadInterface("Interfaces/test_Listbox.goml");\r
+                       tlb.DataSource = this;\r
 \r
 //                     TestList [1].Field = "test string";\r
-//                     ValueChanged.Raise(this, new ValueChangeEventArgs ("TestList", null, TestList));\r
+//                     ValueChanged.Raise(this, new ValueChangeEventArgs ("TestList", TestList));\r
 \r
 \r
                }\r
@@ -88,7 +89,11 @@ namespace test
                {\r
                        base.OnUpdateFrame (e);\r
                }\r
-\r
+               protected override void OnKeyDown (KeyboardKeyEventArgs e)\r
+               {\r
+                       TestList.Add ("newly added list item");\r
+                       ValueChanged.Raise(this, new ValueChangeEventArgs ("TestList", TestList));\r
+               }\r
                [STAThread]\r
                static void Main ()\r
                {\r
index 1980f5821de5e61ad5b2e174cf133d70e4557038..b0e4df4292d9f610586a8fbc4a2bb27d378c5ea3 100644 (file)
@@ -32,8 +32,9 @@ namespace test
                        base.OnLoad (e);\r
                        type = new TypeContainer(typeof (GraphicObject));\r
 \r
-                       this.AddWidget(Interface.Load ("Interfaces/testTypeViewer.goml", type));\r
-                       //LoadInterface("Interfaces/testTypeViewer.goml", out g);\r
+                       //this.AddWidget(Interface.Load ("Interfaces/testTypeViewer.goml", type));\r
+                       GraphicObject go = LoadInterface("Interfaces/testTypeViewer.goml");\r
+                       go.DataSource = type;\r
                }\r
 \r
                protected override void OnRenderFrame (FrameEventArgs e)\r
index 0b0fba69e206d54ab9a3bf2711a0b7b0086bebbf..2e8e29ccfe432f3f3d1d025bdedbaf0aab33edfb 100644 (file)
@@ -28,7 +28,7 @@ namespace test
                #endregion\r
 \r
                public GOLIBTests ()\r
-                       : base(600, 500,"test: press spacebar to toogle test files")\r
+                       : base(800, 600,"test: press spacebar to toogle test files")\r
                {\r
                        VSync = VSyncMode.Off;\r
                }\r
@@ -36,6 +36,8 @@ namespace test
                int frameCpt = 0;\r
                int idx = 0;\r
                string[] testFiles = {\r
+                       "testAll.goml",\r
+                       "test4.goml",\r
 //                     "testSpinner.goml",\r
 //                     "test_Listbox.goml",\r
                        "testRadioButton2.goml",\r
@@ -53,7 +55,6 @@ namespace test
                        "testMsgBox.goml",\r
                        "testGrid.goml",\r
                        "testMeter.goml",\r
-//                     "test4.goml",\r
 //                     "testCombobox.goml",\r
                };\r
 \r
diff --git a/Tests/Interfaces/testAll.goml b/Tests/Interfaces/testAll.goml
new file mode 100755 (executable)
index 0000000..c2b3079
--- /dev/null
@@ -0,0 +1,46 @@
+<?xml version="1.0"?>\r
+<!--<VerticalStack Background="Blue" Fit="true" >-->\r
+<!--   <TextRun Text="text run test"/>\r
+       <Label Text="label test"/>\r
+       <TextBoxWidget Text="Text box test"/>\r
+       <Checkbox Caption="Checkbox test"/>\r
+       <RadioButton Caption="Radio button test"/>-->\r
+<!--   <Groupbox Margin="0" Fit="true">                \r
+               <VerticalStack Fit="true" Background="Red" Margin="0">\r
+                       <TextRun Text="text run test" />\r
+                       <TextRun Text="text run test" />\r
+                       <TextRun Text="text run test"/>\r
+               </VerticalStack>\r
+       </Groupbox>-->\r
+       <Groupbox  Background="DarkGreen">              \r
+<!--           <Template>\r
+                       <Group Height="{../TemplatedHeight}" Width="{../TemplatedWidth}">\r
+                               <Border CornerRadius="5" BorderWidth="1" Margin="6"\r
+                                       Height="{../../TemplatedHeight}" Width="{../../TemplatedWidth}">\r
+                                       <Container Name="Content" Margin="10"\r
+                                                       Height="{../../../TemplatedHeight}" Width="{../../../TemplatedWidth}"/>\r
+                               </Border>\r
+                               <Label Text="{../../Title}" VerticalAlignment="Top" Left="15"\r
+                                       Background="Clear" Margin="1"/>\r
+                       </Group>\r
+               </Template>-->\r
+               <VerticalStack Fit="true" Background="Red" Margin="0">\r
+                       <TextRun Text="text run test" />\r
+                       <TextRun Text="text run test" />\r
+                       <TextRun Text="text run test"/>\r
+               </VerticalStack>\r
+       </Groupbox>\r
+<!--   <Group Fit="true">\r
+               <Border CornerRadius="5" BorderWidth="1" Margin="6" Fit="true">\r
+                       <Container Name="Content" Margin="10" Fit="true">\r
+                               <VerticalStack Fit="true" Background="Red" Margin="0">\r
+                                       <TextRun Text="text run test" />\r
+                                       <TextRun Text="text run test" />\r
+                                       <TextRun Text="text run test"/>\r
+                               </VerticalStack>\r
+                       </Container>\r
+               </Border>\r
+               <Label Text="test" VerticalAlignment="Top" Left="15"\r
+                       Background="Clear" Margin="1"/>\r
+       </Group>-->\r
+<!--</VerticalStack>-->
\ No newline at end of file
index 8055d5028b745b4cc54567b67291f2692c9792cc..a700993dd5b3b162d966f017bdcd288761b7a742 100755 (executable)
@@ -2,7 +2,7 @@
 
        <VerticalStack Height="-1" Width="250" Name="hstack" Margin="0" Spacing="0">
                <Border Height="-1" Width="0" BorderWidth="2" CornerRadius="10">
-                       <Label Name="labName" Text="{Name}" Width="0" Height="-1"/>
+                       <Label Name="labName" Text="{Name}" Width="0" Height="-1" Margin="1"/>
                </Border>
                <ListBox Data="{Members}" Width="0" Height="400" ItemTemplate="Interfaces/tmpMembers.goml" Focusable="true">
                        
index 9f7645ab2605e07c7344e31551127461b70259b2..33380cb902e720f96cb7a40c749bd552d3375cf2 100755 (executable)
@@ -1,22 +1,20 @@
 <?xml version="1.0"?>\r
 <!--<ListBox Data="{TestList}" Focusable="true"/>-->\r
 <ListBox Data="{TestList}" Background="0,5;0,5;0,5;0,5"\r
-                        HorizontalAlignment="Left" Width="-1" Height="-1" Margin="50">\r
-<!--   <Template>\r
-               <Border BorderWidth="1" Margin="1" MinimumSize="100;100" Width="0" Height="0" >\r
-                       <Scroller  Name="scroller1" Margin="1" VerticalScrolling="true" \r
-                               Height="0" Width="0">\r
-                               <VerticalStack Height="-1" Name="List" Margin="0" VerticalAlignment="Top"/>\r
-                       </Scroller>\r
+                        HorizontalAlignment="Left" Width="0" Height="0" Margin="5">\r
+       <Template>\r
+               <Border BorderWidth="1" MinimumSize="20;20" Height="{../TemplatedHeight}" Width="{../TemplatedWidth}">\r
+                       <HorizontalStack Margin="1" Height="{../../TemplatedHeight}" Width="{../../TemplatedWidth}">\r
+                               <Scroller Name="scroller1" Height="{../../../TemplatedHeight}" Width="{../../../TemplatedWidth}" \r
+                                               Margin="2" VerticalScrolling="true" ScrollY="{../scrollbar1.Scroll}">\r
+                                       <VerticalStack Width="{../../../../TemplatedWidth}" Height="-1" \r
+                                               Name="List" Margin="0" VerticalAlignment="Top" />\r
+                               </Scroller>\r
+                               <Scrollbar Name="scrollbar1" Scroll="{../scroller1.ScrollY}" \r
+                                       MaximumScroll="{../scroller1.MaximumScroll}" Orientation="Vertical" \r
+                                       Width="10" Height="{../../../TemplatedHeight}" />\r
+                       </HorizontalStack>\r
                </Border>\r
-       </Template>-->\r
-<!--   <Template>\r
-               <Border BorderWidth="1" Margin="1" MinimumSize="100;100" Height="{TemplatedHeight}" Width="{TemplatedWidth}" >\r
-                       <Scroller  Name="scroller1" Margin="1" VerticalScrolling="true" \r
-                               Height="{TemplatedHeight}" Width="{TemplatedWidth}">\r
-                               <VerticalStack Height="-1" Width="{TemplatedWidth}" Name="List" Margin="0" VerticalAlignment="Top"/>\r
-                       </Scroller>\r
-               </Border>\r
-       </Template>-->\r
+       </Template>\r
 </ListBox>\r
 \r
index e12e092ee86546d3c3367bdec0d43a4318b9b1f3..d9a5ebc8cba5182966cd7457e66067378b978c13 100644 (file)
     <None Include="Interfaces\testRadioButton2.goml">
       <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
     </None>
+    <None Include="Interfaces\testAll.goml">
+      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+    </None>
   </ItemGroup>
   <ItemGroup>
     <Folder Include="Interfaces\" />
index 1496e0e5f25bec5a5668025811a9f24e5268c7c3..0374527ddfe88c20267d959d136e087719c6b3a5 100644 (file)
@@ -23,13 +23,11 @@ namespace go
 {              \r
        public class GraphicObject : IXmlSerializable, ILayoutable, IValueChange\r
        {\r
-               internal List<string> DynamicMethodIds\r
-               {\r
-                       get { return Bindings.\r
-                               Where(bi=>!string.IsNullOrEmpty(bi.DynMethodId)).\r
-                               Select (b => b.DynMethodId).ToList ();\r
-                       }\r
-               }\r
+               #if DEBUG_LAYOUTING\r
+               internal static ulong currentUid = 0;\r
+               internal ulong uid = 0;\r
+               #endif\r
+\r
                internal List<Binding> Bindings = new List<Binding> ();\r
 \r
                #region IValueChange implementation\r
@@ -43,11 +41,22 @@ namespace go
                #region CTOR\r
                public GraphicObject ()\r
                {\r
+                       #if DEBUG_LAYOUTING\r
+                       uid = currentUid;\r
+                       currentUid++;\r
+                       #endif\r
+\r
+                       if (Interface.XmlSerializerInit)\r
+                               return;\r
+\r
                        loadDefaultValues ();\r
                        registerForGraphicUpdate ();\r
                }\r
                public GraphicObject (Rectangle _bounds)\r
                {\r
+                       if (Interface.XmlSerializerInit)\r
+                               return;\r
+                       \r
                        loadDefaultValues ();\r
                        Bounds = _bounds;\r
                        registerForGraphicUpdate ();\r
@@ -531,29 +540,50 @@ namespace go
                {\r
                        if (Parent==null)\r
                                return;\r
-\r
-                       //Debug.WriteLine ("Layout change: " + this.ToString () + ":" + LastSlots.ToString() + "=>" + Slot.ToString ());\r
+                       #if DEBUG_LAYOUTING\r
+                       Debug.WriteLine ("Layout change: " + this.ToString () + ":" + LastSlots.ToString() + "=>" + Slot.ToString ());\r
+                       #endif\r
                        \r
                        switch (layoutType) {\r
                        case LayoutingType.Width:                               \r
-                               if (Parent.getBounds ().Width < 0)\r
+                               if (Parent.getBounds ().Width < 0) {\r
+                                       Group gw = Parent as Group;\r
+                                       if (gw != null) {\r
+                                               if (Slot.Width > gw.maxChildrenWidth)\r
+                                                       gw.maxChildrenWidth = Slot.Width;\r
+                                       }\r
                                        this.Parent.RegisterForLayouting ((int)LayoutingType.Width);\r
-                               else if (Width != 0) //update position in parent\r
+                               }else if (Width != 0) //update position in parent\r
                                        this.RegisterForLayouting ((int)LayoutingType.X);\r
-                               if (!(Parent is GenericStack))\r
-                                       break;\r
-                               if ((Parent as GenericStack).Orientation == Orientation.Horizontal)\r
+                               GenericStack gsw = Parent as GenericStack;\r
+                               if (gsw == null)\r
+                                       break;  \r
+                               if ((Parent as GenericStack).Orientation == Orientation.Horizontal) {\r
+//                                     ulong idx = (ulong)gsw.Children.IndexOf (this);\r
+//                                     if (idx < gsw.stackingUpdateStartIndex)\r
+//                                             gsw.stackingUpdateStartIndex = idx;\r
                                        this.Parent.RegisterForLayouting ((int)LayoutingType.PositionChildren);\r
+                               }\r
                                break;\r
                        case LayoutingType.Height:\r
-                               if (Parent.getBounds().Height < 0)\r
-                                       this.Parent.RegisterForLayouting((int)LayoutingType.Height);\r
-                               else if (Height != 0) //update position in parent\r
+                               if (Parent.getBounds ().Height < 0) {\r
+                                       Group gh = Parent as Group;\r
+                                       if (gh != null) {\r
+                                               if (Slot.Width > gh.maxChildrenHeight)\r
+                                                       gh.maxChildrenHeight = Slot.Height;\r
+                                       }\r
+                                       this.Parent.RegisterForLayouting ((int)LayoutingType.Height);\r
+                               }else if (Height != 0) //update position in parent\r
                                        this.RegisterForLayouting ((int)LayoutingType.Y);\r
-                               if (!(Parent is GenericStack))\r
-                                       break;\r
-                               if ((Parent as GenericStack).Orientation == Orientation.Vertical)\r
+                               GenericStack gsh = Parent as GenericStack;\r
+                               if (gsh==null)\r
+                                       break;                          \r
+                               if (gsh.Orientation == Orientation.Vertical) {\r
+//                                     ulong idx = (ulong)gsh.Children.IndexOf (this);\r
+//                                     if (idx < gsh.stackingUpdateStartIndex)\r
+//                                             gsh.stackingUpdateStartIndex = idx;\r
                                        this.Parent.RegisterForLayouting ((int)LayoutingType.PositionChildren);\r
+                               }\r
                                break;\r
                        }\r
                        LayoutChanged.Raise (this, new LayoutChangeEventArgs (layoutType));\r
@@ -684,7 +714,7 @@ namespace go
                }\r
 \r
                /// <summary>\r
-               /// Interfal drawing context creation on a chached surface limited to slot size\r
+               /// Interfal drawing context creation on a cached surface limited to slot size\r
                /// this trigger the effective drawing routine </summary>\r
                protected virtual void UpdateGraphic ()\r
                {\r
@@ -732,8 +762,7 @@ namespace go
 \r
         #region Keyboard handling\r
                public virtual void onKeyDown(object sender, KeyboardKeyEventArgs e){\r
-                       if (KeyDown != null)\r
-                               KeyDown (sender, e);\r
+                       KeyDown.Raise (sender, e);\r
                }\r
         #endregion\r
 \r
@@ -803,9 +832,14 @@ namespace go
                public override string ToString ()\r
                {\r
                        string tmp ="";\r
+\r
                        if (Parent != null)\r
                                tmp = Parent.ToString () + tmp;\r
+                       #if DEBUG_LAYOUTING\r
+                       return Name == "unamed" ? tmp + "." + this.GetType ().Name + uid.ToString(): tmp + "." + Name;\r
+                       #else\r
                        return Name == "unamed" ? tmp + "." + this.GetType ().Name : tmp + "." + Name;\r
+                       #endif\r
                }\r
 \r
                #region Binding\r
@@ -855,11 +889,6 @@ namespace go
                                System.Reflection.Emit.Label[] jumpTable = null;\r
                                System.Reflection.Emit.Label endMethod = new System.Reflection.Emit.Label();\r
 \r
-                               LocalBuilder lbMemberName = null;\r
-                               LocalBuilder lbValue = null;\r
-\r
-\r
-\r
                                #region Retrieve EventHandler parameter type\r
                                EventInfo ei = targetType.GetEvent ("ValueChanged");\r
                                //no dynamic update if ValueChanged interface is not implemented\r
@@ -876,12 +905,8 @@ namespace go
                                                args,\r
                                                sourceType,true);\r
 \r
-\r
-                                       \r
-\r
                                        il = dm.GetILGenerator(256);\r
 \r
-\r
                                        endMethod = il.DefineLabel();\r
                                        jumpTable = new System.Reflection.Emit.Label[grouped.Length];\r
                                        for (i = 0; i < grouped.Length; i++)\r
@@ -1162,7 +1187,7 @@ namespace go
                                \r
                                MemberInfo mi = thisType.GetMember (attName).FirstOrDefault();\r
                                if (mi == null) {\r
-                                       Debug.WriteLine (Interface.CurrentGOMLPath + "=>GOML: Unknown attribute in " + thisType.ToString() + " : " + attName);\r
+                                       Debug.WriteLine ("GOML: Unknown attribute in " + thisType.ToString() + " : " + attName);\r
                                        continue;\r
                                }\r
                                if (mi.MemberType == MemberTypes.Event) {\r
index bf04617d18ea739fe24e4a477b8eab7356b6701d..b2e341da9057772c6dc24f194b98d22d9d351946 100644 (file)
@@ -23,6 +23,9 @@ namespace go
                public event EventHandler<EventArgs> ChildrenCleared;\r
                #endregion\r
 \r
+               internal int maxChildrenWidth = 0;\r
+               internal int maxChildrenHeight = 0;\r
+\r
         bool _multiSelect = false;\r
                List<GraphicObject> children = new List<GraphicObject>();\r
 \r
@@ -30,9 +33,7 @@ namespace go
 \r
         public virtual List<GraphicObject> Children {\r
                        get { return children; }\r
-                       set { \r
-                               children = value; \r
-                       }\r
+                       set { children = value; }\r
                }\r
                [XmlAttributeAttribute()][DefaultValue(false)]\r
         public bool MultiSelect\r
@@ -128,17 +129,18 @@ namespace go
                }\r
                protected override Size measureRawSize ()\r
                {\r
-                       Size tmp = new Size ();\r
-\r
-                       foreach (GraphicObject c in Children.Where(ch=>ch.Visible)) {\r
-                               tmp.Width = Math.Max (tmp.Width, c.Slot.Right);\r
-                               tmp.Height = Math.Max (tmp.Height, c.Slot.Bottom);\r
-                       }\r
-\r
-                       tmp.Width += 2*Margin;\r
-                       tmp.Height += 2*Margin;\r
-\r
-                       return tmp;\r
+//                     Size tmp = new Size ();\r
+//\r
+//                     foreach (GraphicObject c in Children.Where(ch=>ch.Visible)) {\r
+//                             tmp.Width = Math.Max (tmp.Width, c.Slot.Right);\r
+//                             tmp.Height = Math.Max (tmp.Height, c.Slot.Bottom);\r
+//                     }\r
+//\r
+//                     tmp.Width += 2*Margin;\r
+//                     tmp.Height += 2*Margin;\r
+//\r
+//                     return tmp;\r
+                       return new Size(maxChildrenWidth + 2 * Margin, maxChildrenHeight + 2 * Margin);\r
                }\r
                        \r
                public override void OnLayoutChanges (LayoutingType layoutType)\r
@@ -150,7 +152,7 @@ namespace go
                        case LayoutingType.Width:                               \r
                                if (Width < 0) {\r
                                        int crw = ClientRectangle.Width;\r
-                                       foreach (GraphicObject c in Children.Where(ch => ch.Slot.Width != crw && ch.Visible))\r
+                                       foreach (GraphicObject c in Children.Where(ch => ch.Visible))\r
                                                c.RegisterForLayouting ((int)LayoutingType.X);                                          \r
                                } else {\r
                                        foreach (GraphicObject c in Children.Where(ch => ch.Width == 0 && ch.Visible))\r
@@ -160,7 +162,7 @@ namespace go
                        case LayoutingType.Height:\r
                                if (Height < 0) {\r
                                        int crh = ClientRectangle.Height;\r
-                                       foreach (GraphicObject c in Children.Where(ch => ch.Slot.Height != crh && ch.Visible))\r
+                                       foreach (GraphicObject c in Children.Where(ch => ch.Visible))\r
                                                c.RegisterForLayouting ((int)LayoutingType.Y);                                          \r
                                } else {\r
                                        foreach (GraphicObject c in Children.Where(ch => ch.Height == 0 && ch.Visible))\r
index 5f1b8eda12e13259d7ccc82d9051f780bbbf4b41..1778e3403991de993d0ac1acfa726f33739f0259 100644 (file)
@@ -218,7 +218,7 @@ namespace go
                                                }
                                        }                               
                                } else
-                                       loadTemplate (Interface.Load (template, this, !Interface.DontResoveGOML));
+                                       loadTemplate (Interface.Load (template, this));
 
 
                                //normal xml read
index 6cc444c53e31d0641d612a1cb1c027b3b17501d7..a412a7070d00edb170845cf1ec557d09cb7b86b5 100644 (file)
@@ -96,9 +96,10 @@ namespace go
 
                public override void OnLayoutChanges (LayoutingType layoutType)
                {
+                       base.OnLayoutChanges (layoutType);
+
                        switch (layoutType) {
-                       case LayoutingType.Width:                               
-                               base.OnLayoutChanges (layoutType);
+                       case LayoutingType.Width:                                                               
                                if (child != null) {
                                        if (child.getBounds ().Width == 0)
                                                child.RegisterForLayouting ((int)LayoutingType.Width);
@@ -107,7 +108,6 @@ namespace go
                                }
                                break;
                        case LayoutingType.Height:
-                               base.OnLayoutChanges (layoutType);
                                if (child != null) {
                                        if (child.getBounds ().Height == 0)
                                                child.RegisterForLayouting ((int)LayoutingType.Height);
index de688d2cf0bbb639d9961e0116535b889d5fb518..4ab3a362478cb57b6c72e4e69aba49b4ab3f3287 100644 (file)
@@ -165,7 +165,7 @@ namespace go
                                                }
                                        }                               
                                } else
-                                       loadTemplate (Interface.Load (template, this, !Interface.DontResoveGOML));
+                                       loadTemplate (Interface.Load (template, this));
                                
 
                                //normal xml read
index 1b6f24374948ef21de2647f652f1520e4da446fa..7836b9036224577dcf67a85878638b77b8f0327b 100644 (file)
@@ -35,12 +35,16 @@ namespace go
 {
        public static class Interface
        {
+               /// <summary> Used to prevent spurious loading of templates </summary>
+               internal static bool XmlSerializerInit = false;
+               /// <summary> keep ressource path for debug msg </summary>
+               internal static string CurrentGOMLPath = "";
+
                public static int TabSize = 4;
                public static string LineBreak = "\r\n";
                public static bool ReplaceTabsWithSpace = false;
                /// <summary> Allow rendering of interface in development environment </summary>
                public static bool DesignerMode = false;
-               public static bool DontResoveGOML = false;
                /// <summary> Threshold to catch borders for sizing </summary>
                public static int BorderThreshold = 5;
 
@@ -128,20 +132,12 @@ namespace go
                public static Type GetTopContainerOfGOMLStream (Stream stream)
                {
                        string root = "Object";
-                       string ClassName = "";
                        stream.Seek (0, SeekOrigin.Begin);
                        using (XmlReader reader = XmlReader.Create (stream)) {
                                while (reader.Read ()) {
                                        // first element is the root element
                                        if (reader.NodeType == XmlNodeType.Element) {
                                                root = reader.Name;
-                                               ClassName = reader.GetAttribute ("Class");
-                                               if (!string.IsNullOrEmpty (ClassName))
-                                                       break;
-                                               if (CurrentGOMLPath.StartsWith ("#"))
-                                                       ClassName = Path.GetFileNameWithoutExtension (CurrentGOMLPath.Substring (1));
-                                               else
-                                                       ClassName = Path.GetFileNameWithoutExtension (CurrentGOMLPath);
                                                break;
                                        }
                                }
@@ -149,285 +145,23 @@ namespace go
 
                        Type t = Type.GetType ("go." + root);
 
-                       //t = CreateDynamicType (ClassName, t);
-
                        stream.Seek (0, SeekOrigin.Begin);
                        return t;
                }
 
 
-
-
-               static AssemblyBuilder assemblyBuilder;
-               static ModuleBuilder moduleBuilder;
-
-               public static void InitDynamicAssembly ()
-               {
-                       AssemblyName an = new AssemblyName ("DynamicGraphicObjects");
-                       assemblyBuilder = AppDomain.CurrentDomain.DefineDynamicAssembly (an, AssemblyBuilderAccess.RunAndSave);
-                       moduleBuilder = assemblyBuilder.DefineDynamicModule ("MainModule");
-               }
-
-               public static void TerminateDynamicAssembly ()
-               {
-               }
-
-               public static CodeCompileUnit CompileUnit;
-               public static CodeTypeDeclaration GOTypeDecl;
-
-               public static CodeTypeDeclaration GenCodeType (string newTypeName, Type baseType)
-               {
-                       CompileUnit = new CodeCompileUnit ();
-                       CodeNamespace cns = null;
-
-                       int idxLastDot = newTypeName.LastIndexOf ('.');
-                       string typeName = newTypeName;
-                       if (idxLastDot < 0)
-                               cns = new CodeNamespace ("go");
-                       else {
-                               typeName = newTypeName.Substring (idxLastDot + 1);
-                               cns = new CodeNamespace (newTypeName.Substring (0, idxLastDot));
-                       }
-                       CompileUnit.Namespaces.Add (new CodeNamespace ());
-                       CompileUnit.Namespaces.Add (cns);
-                       CompileUnit.Namespaces [0].Imports.Add (new CodeNamespaceImport ("System"));
-                       CodeTypeDeclaration GOTypeDecl = new CodeTypeDeclaration (typeName);
-                       GOTypeDecl.IsClass = true;
-                       GOTypeDecl.IsPartial = true;
-                       GOTypeDecl.TypeAttributes |= TypeAttributes.Public;
-                       GOTypeDecl.BaseTypes.Add (baseType.Name);
-                       cns.Types.Add (GOTypeDecl);
-                       return GOTypeDecl;
-               }
-
-               static void GenNewClassFromGOML (string path)
-               {
-                       string root = null;
-                       string newClassName = "";
-
-                       using (Stream stream = GetStreamFromPath (path)) {
-                               using (XmlReader reader = XmlReader.Create (stream)) {
-                                       CodeTypeDeclaration GOTypeDecl = null;
-                                       CodeConstructor constructor = null;
-
-                                       CodeExpression curRef = null;
-                                       Type curType = null;
-                                       Stack<CodeExpression> curRefStack = new Stack<CodeExpression> ();
-                                       Stack<Type> curTypeStack = new Stack<Type> ();
-
-                                       int arrayIndex = -1;
-                                       int localVarCpt = 0;
-                                       
-                                       while (reader.Read ()) {
-                                               switch (reader.NodeType) {
-                                               case XmlNodeType.Element:                                                       
-                                                       if (string.IsNullOrEmpty (root)) {
-                                                               //create the new base class
-                                                               // first element is the root element
-                                                               root = reader.Name;
-                                                               newClassName = reader.GetAttribute ("Class");
-                                                               if (string.IsNullOrEmpty (newClassName)) {
-                                                                       if (path.StartsWith ("#"))
-                                                                               newClassName = Path.GetFileNameWithoutExtension (path.Substring (1));
-                                                                       else
-                                                                               newClassName = Path.GetFileNameWithoutExtension (path);
-                                                               }
-                                                               curType = Type.GetType ("go." + root);
-
-                                                               GOTypeDecl = GenCodeType (newClassName, curType);
-                                                               // Declares a constructor.
-                                                               constructor = new CodeConstructor ();
-                                                               constructor.Attributes = MemberAttributes.Public;
-                                                               GOTypeDecl.Members.Add (constructor);
-
-                                                               curRef = new CodeThisReferenceExpression ();
-                                                       } else if (reader.Name == "Template") {
-                                                       }else{
-                                                               Type childType = Type.GetType ("go." + reader.Name);
-                                                               localVarCpt++;
-                                                               string localVarName = childType.Name + localVarCpt;
-                                                               constructor.Statements.Add (
-                                                                       new CodeVariableDeclarationStatement (
-                                                                               childType, 
-                                                                               localVarName,
-                                                                               new CodeObjectCreateExpression (childType)
-                                                                       )
-                                                               );
-                                                               if (curType == typeof(go.Container) || curType.IsSubclassOf (typeof(go.Container))) {
-                                                                       constructor.Statements.Add (
-                                                                               new CodeMethodInvokeExpression (
-                                                                                       curRef, 
-                                                                                       "SetChild",
-                                                                                       new CodeVariableReferenceExpression (localVarName)
-                                                                               )
-                                                                       );
-                                                               } else if (curType == typeof(go.Group) || curType.IsSubclassOf (typeof(go.Group))) {                                                                    
-                                                                       constructor.Statements.Add (
-                                                                               new CodeMethodInvokeExpression (curRef, "addChild",
-                                                                                       new CodeVariableReferenceExpression (localVarName)
-                                                                               )
-                                                                       );
-                                                               }
-                                                               curTypeStack.Push (curType);
-                                                               curRefStack.Push (curRef);
-                                                               curRef = new CodeVariableReferenceExpression (localVarName);
-                                                               curType = childType;
-                                                       }
-                                                       while (reader.MoveToNextAttribute ()) {
-                                                               string attName = reader.Name;
-                                                               string attValue = reader.Value;
-
-                                                               if (string.IsNullOrEmpty (attValue))
-                                                                       continue;
-
-                                                               MemberInfo mi = curType.GetMember (attName).FirstOrDefault ();
-                                                               if (mi == null) {
-                                                                       Debug.WriteLine (Interface.CurrentGOMLPath + "=>GOML: Unknown attribute in " + curType.ToString () + " : " + attName);
-                                                                       continue;
-                                                               }
-                                                               if (mi.MemberType == MemberTypes.Event) {
-                                                                       //TODO: handle events
-                                                                       continue;
-                                                               }
-                                                               if (mi.MemberType == MemberTypes.Property) {
-                                                                       PropertyInfo pi = mi as PropertyInfo;
-
-                                                                       if (pi.GetSetMethod () == null) {
-                                                                               Debug.WriteLine (Interface.CurrentGOMLPath + "=>GOML: Read only property in " + curType.ToString () + " : " + attName);
-                                                                               continue;
-                                                                       }
-
-                                                                       if (attValue.StartsWith("{")) {
-                                                                               if (Interface.DontResoveGOML)
-                                                                                       continue;
-                                                                               //binding
-                                                                               if (!attValue.EndsWith("}"))
-                                                                                       throw new Exception (string.Format("GOML:Malformed binding: {0}", attValue));
-
-                                                                               string strBinding = attValue.Substring (1, attValue.Length - 2);
-
-                                                                               continue;
-                                                                       }
-
-                                                                       CodeExpression val = null;
-                                                                       if (pi.PropertyType == typeof(string)) {
-                                                                               val = new CodePrimitiveExpression (attValue);
-                                                                       } else if (pi.PropertyType.IsPrimitive) {
-                                                                               MethodInfo me = pi.PropertyType.GetMethod ("Parse", new Type[] { typeof(string) });
-                                                                               val = new CodePrimitiveExpression (
-                                                                                       me.Invoke (null, new string[] { attValue }));
-                                                                       } else if (pi.PropertyType.IsEnum || (pi.PropertyType == typeof(go.Color) && Char.IsLetter (attValue [0]))) {
-                                                                               val = new CodeFieldReferenceExpression (new CodeTypeReferenceExpression (pi.PropertyType), attValue);
-                                                                       }else if (pi.PropertyType == typeof(go.Color) || pi.PropertyType == typeof(go.Font)) {
-                                                                               val = new CodeCastExpression(pi.PropertyType,
-                                                                                       new CodeMethodInvokeExpression (
-                                                                                               new CodeTypeReferenceExpression (pi.PropertyType),
-                                                                                               "Parse", 
-                                                                                               new CodePrimitiveExpression (attValue)
-                                                                                       )
-                                                                               );
-                                                                       } else {
-                                                                               val = new CodeMethodInvokeExpression (new CodeTypeReferenceExpression (pi.PropertyType),
-                                                                                       "Parse", new CodePrimitiveExpression (attValue));
-
-                                                                       }
-                                                                       constructor.Statements.Add (
-                                                                               new CodeAssignStatement (
-                                                                                       new CodePropertyReferenceExpression (curRef, attName),
-                                                                                       val
-                                                                               )
-                                                                       );
-                                                               }                                                               
-                                                       }
-                                                       reader.MoveToElement ();
-                                                       if (reader.IsEmptyElement) {
-                                                               curType = curTypeStack.Pop ();
-                                                               curRef = curRefStack.Pop ();
-                                                       }
-                                                       break;
-                                               case XmlNodeType.EndElement:
-                                                       if (curTypeStack.Count < 1)//GOML last closing tag                                                              
-                                                               break;
-                                                       curType = curTypeStack.Pop ();
-                                                       curRef = curRefStack.Pop ();
-                                                       if (curType.IsSubclassOf (typeof(go.Container)))
-                                                               arrayIndex = -1;
-                                                       break;
-                                               }                                               
-                                       }
-                               }
-                       }
-                               
-
-
-
-                       GenerateCSharpCode (CompileUnit, path + ".cs");
-               }
-
-               static void GenerateCSharpCode (CodeCompileUnit codeBase, string file)
-               {
-                       CodeDomProvider codeDomProvider = new CSharpCodeProvider ();
-                       //On définit les options de génération de code
-                       CodeGeneratorOptions options = new CodeGeneratorOptions ();
-                       //On demande a ce que le code généré soit dans le même ordre que le code inséré
-                       options.VerbatimOrder = false;
-                       //options.BracingStyle = "C";
-                       //options.BracingStyle = "C";
-                       options.ElseOnClosing = true;
-                       options.BlankLinesBetweenMembers = false;
-
-                       using (IndentedTextWriter itw = new IndentedTextWriter (new StreamWriter (file, false), "\t")) {
-                               //On demande la génération proprement dite
-                               codeDomProvider.GenerateCodeFromCompileUnit (codeBase, itw, options);
-                               itw.Flush ();
-                       }
-                       Console.WriteLine ("C# code generated: " + file);
-               }
-
-               public static Type CreateDynamicType (string newTypeName, Type baseType)
+               public static GraphicObject Load (string path, object hostClass = null)
                {
-                       if (moduleBuilder == null)
-                               InitDynamicAssembly ();
-                       TypeBuilder tb = moduleBuilder.DefineType (newTypeName
-                               , TypeAttributes.Public |
-                                        TypeAttributes.Class |
-                                        TypeAttributes.AutoClass |
-                                        TypeAttributes.AnsiClass |
-                                        TypeAttributes.BeforeFieldInit |
-                                        TypeAttributes.AutoLayout
-                               , baseType);
-                       
-                       ConstructorBuilder constructor = tb.DefineDefaultConstructor (MethodAttributes.Public | MethodAttributes.SpecialName | MethodAttributes.RTSpecialName);
-
-                       ConstructorInfo cn = typeof(XmlRootAttribute).GetConstructor (new Type[] { typeof(string) });
-                       CustomAttributeBuilder cab = new CustomAttributeBuilder (cn, new object[] { baseType.Name });
-
-                       tb.SetCustomAttribute (cab);
-
-
-
-
-                       Type tmp = tb.CreateType ();
-                       //assemblyBuilder.Save ("newAssembly.dll",PortableExecutableKinds.ILOnly,ImageFileMachine.I386);
-                       return tmp;
-               }
-
-               public static string CurrentGOMLPath;
-
-               public static GraphicObject Load (string path, object hostClass = null, bool resolveGOML = true)
-               {               
-//                     GenNewClassFromGOML (path);
-//                     return null;
                        CurrentGOMLPath = path;
                        using (Stream stream = GetStreamFromPath (path)) {
-                               return Load(stream, GetTopContainerOfGOMLStream(stream), hostClass, resolveGOML);
+                               return Load(stream, GetTopContainerOfGOMLStream(stream), hostClass);
                        }
                        CurrentGOMLPath = "";
                }
 
 
 
-               public static GraphicObject Load (Stream stream, Type type, object hostClass = null, bool resolve = true)
+               public static GraphicObject Load (Stream stream, Type type, object hostClass = null)
                {
                        #if DEBUG_LOAD_TIME
                        Stopwatch loadingTime = new Stopwatch ();
@@ -439,17 +173,23 @@ namespace go
 
                        XmlSerializerNamespaces xn = new XmlSerializerNamespaces ();
                        xn.Add ("", "");
+
+                       XmlSerializerInit = true;
                        XmlSerializer xs = new XmlSerializer (type);
+                       XmlSerializerInit = false;
 
                        result = (GraphicObject)xs.Deserialize (stream);
                        //result.DataSource = hostClass;
 
                        #if DEBUG_LOAD_TIME
+                       FileStream fs = stream as FileStream;
+                       if (fs!=null)
+                               CurrentGOMLPath = fs.Name;
                        loadingTime.Stop ();
-                       Debug.WriteLine ("GOML Loading ({2}): {0} ticks \t, {1} ms",
+                       Debug.WriteLine ("GOML Loading ({2}->{3}): {0} ticks, {1} ms",
                                loadingTime.ElapsedTicks,
                                loadingTime.ElapsedMilliseconds,
-                               CurrentGOMLPath);
+                       CurrentGOMLPath, result.ToString());
                        #endif
 
                        return result;
index 417a70ff7a54ac349871cc2b46260e26e9de0206..8e8f8a9842fbbebef3be6e13579eae5754b2b998 100644 (file)
@@ -48,7 +48,9 @@ namespace go
                }
                public void ProcessLayouting()
                {
-                       //Debug.WriteLine ("Layouting => " + this.ToString ());
+                       #if DEBUG_LAYOUTING
+                       Debug.WriteLine ("Layouting => " + this.ToString ());
+                       #endif
                        try {
                                GraphicObject.UpdateLayout (LayoutType);
                        } catch (Exception ex) {
index 0329250a977c4293045e5430636789f4ab0eb00a..5fbcd9c19a847a15f3c026065afa7716f5ccf4de 100755 (executable)
@@ -45,12 +45,6 @@ namespace go
                }        \r
                #endregion\r
 \r
-               #if _WIN32 || _WIN64\r
-               public const string rootDir = @"d:\";\r
-               #elif __linux__\r
-               public const string rootDir = @"/mnt/data/";\r
-               #endif\r
-\r
                public List<GraphicObject> GraphicObjects = new List<GraphicObject>();\r
                public Color Background = Color.Transparent;\r
 \r