Prevent multiple loading of template and default values while creating XmlSerializer(type)
Removed DynamicClass functions, not used for now.
Divers debug
</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
// 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
{\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
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
#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
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
"testMsgBox.goml",\r
"testGrid.goml",\r
"testMeter.goml",\r
-// "test4.goml",\r
// "testCombobox.goml",\r
};\r
\r
--- /dev/null
+<?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
<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">
<?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
<None Include="Interfaces\testRadioButton2.goml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
+ <None Include="Interfaces\testAll.goml">
+ <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+ </None>
</ItemGroup>
<ItemGroup>
<Folder Include="Interfaces\" />
{ \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
#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
{\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
}\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
\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
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
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
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
\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
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
\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
}\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
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
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
}
}
} else
- loadTemplate (Interface.Load (template, this, !Interface.DontResoveGOML));
+ loadTemplate (Interface.Load (template, this));
//normal xml read
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);
}
break;
case LayoutingType.Height:
- base.OnLayoutChanges (layoutType);
if (child != null) {
if (child.getBounds ().Height == 0)
child.RegisterForLayouting ((int)LayoutingType.Height);
}
}
} else
- loadTemplate (Interface.Load (template, this, !Interface.DontResoveGOML));
+ loadTemplate (Interface.Load (template, this));
//normal xml read
{
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;
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;
}
}
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 ();
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;
}
public void ProcessLayouting()
{
- //Debug.WriteLine ("Layouting => " + this.ToString ());
+ #if DEBUG_LAYOUTING
+ Debug.WriteLine ("Layouting => " + this.ToString ());
+ #endif
try {
GraphicObject.UpdateLayout (LayoutType);
} catch (Exception ex) {
} \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