]> O.S.I.I.S - jp/crow.git/commitdiff
ItemTemplate instantiator, basic listbox ok
authorjpbruyere <jp.bruyere@hotmail.com>
Wed, 10 Aug 2016 05:13:14 +0000 (07:13 +0200)
committerjpbruyere <jp.bruyere@hotmail.com>
Wed, 10 Aug 2016 05:13:40 +0000 (07:13 +0200)
1  2 
Crow.csproj
Tests/Interfaces/basicTests/8.crow
src/CompilerServices/Bindings.cs
src/GraphicObjects/TemplatedControl.cs
src/IMLReader.cs
src/Interface.cs
src/LayoutingQueueItem.cs

diff --cc Crow.csproj
Simple merge
index 0000000000000000000000000000000000000000,0000000000000000000000000000000000000000..a20e1ac514ab9bd6c62349f4073a8d7cfe8f7a2d
new file mode 100755 (executable)
--- /dev/null
--- /dev/null
@@@ -1,0 -1,0 +1,34 @@@
++<?xml version="1.0"?>
++<Slider Background="Blue" Width="100" Height="20"/>
++<!--<ScrollBar Orientation="Vertical" Maximum="100" Value="10"
++                                      Width="14" Height="300"/>-->
++<!--<ListBox Data="{TestList}" Width="50%" ItemTemplate="#Tests.Interfaces.colorItem.crow">
++      <Template>
++              <Border BorderWidth="1" Height="{../HeightPolicy}" Width="{../WidthPolicy}">
++                      <HorizontalStack Margin="1" Height="{../../HeightPolicy}" Width="{../../WidthPolicy}" >
++                              <Scroller Name="scroller1" Height="{../../../HeightPolicy}" Width="{../../../WidthPolicy}" 
++                                              Margin="2" VerticalScrolling="true" ScrollY="{../scrollbar1.Value}"
++                                              ValueChanged="../../../_scroller_ValueChanged">
++                                      <VerticalStack Width="{../../../../WidthPolicy}" Height="Fit" MinimumSize="10,10"
++                                              Name="List" Margin="0"
++                                              VerticalAlignment="Top"
++                                              HorizontalAlignment="Left"
++                                              LayoutChanged="../../../../_list_LayoutChanged"/>
++                              </Scroller>
++                              <ScrollBar Name="scrollbar1" Value="{../scroller1.ScrollY}" 
++                                      Maximum="{../scroller1.MaximumScroll}" Orientation="Vertical" 
++                                      Width="14" Height="{../../../HeightPolicy}" />
++                      </HorizontalStack>
++              </Border>
++      </Template>
++</ListBox>-->
++<!--<ItemTemplate>
++<HorizontalStack
++                      HorizontalAlignment="Left"
++                      Height="Fit"  Margin="1" Focusable="true"
++                      MouseEnter="{Background=hgradient|0:DarkRed|1:Mantis}"
++                      MouseLeave="{Background=Transparent}">
++      <GraphicObject Height="12" Width="20" Background="{}" Margin="0" CornerRadius="3"/>
++      <Label Text="{Name}" Margin="0" Width="Stretched"/>
++</HorizontalStack>
++</ItemTemplate>-->
index 953f1492d5f3c3b562e8c77cfe640ed6d3e6fa6e,953f1492d5f3c3b562e8c77cfe640ed6d3e6fa6e..64f412f6cd0fd961c328a349aeb0688e46083558
@@@ -128,10 -128,10 +128,12 @@@ namespace Cro
                                //datasource binding
                                object dataSource = (Source.Instance as GraphicObject).DataSource;
                                if (dataSource == null) {
++                                      #if DEBUG_BINDING
                                        Debug.WriteLine ("\tDataSource is null => " + this.ToString());
++                                      #endif
                                        return false;
                                }
--                                      
++
                                Target = new MemberReference (dataSource);
                                memberName = bindingExp [0];
                        } else {
                                while (ptr < bindingExp.Length - 1) {
                                        if (tmpTarget == null) {
  #if DEBUG_BINDING
--                                              Debug.WriteLine ("\tERROR: target not found => " + this.ToString());
++                                              Debug.WriteLine ("\tTarget not found => " + this.ToString());
  #endif
                                                return false;
                                        }
                                }
  
                                if (tmpTarget == null) {
--#if DEBUG_BINDING
--                                      Debug.WriteLine ("\tERROR: Binding Target not found => " + this.ToString());
--#endif
++                                      #if DEBUG_BINDING
++                                      Debug.WriteLine ("\tBinding Target not found => " + this.ToString());
++                                      #endif
                                        return false;
                                }
  
--                              Target = new MemberReference (tmpTarget);
--
                                string [] bindTrg = bindingExp [ptr].Split ('.');
  
                                if (bindTrg.Length == 1)
                                } else
                                        throw new Exception ("Syntax error in binding, expected 'go dot member'");
  
++                              if (tmpTarget == null) {
++                                      #if DEBUG_BINDING
++                                      Debug.WriteLine ("\tBinding Target not found => " + this.ToString());
++                                      #endif
++                                      return false;
++                              }
++
++                              Target = new MemberReference (tmpTarget);
                        }
  
                        if (Target.TryFindMember (memberName)) {
index b325a0d28e676ae5a0c0204ad1491dbb2469fbaa,f78173d263ff93ef77d47d20884a6a84a6274ad8..63bdbb2192907c42969ad859e218f1175d45e6b0
@@@ -65,8 -65,9 +65,8 @@@ namespace Cro
  
                string _template;
                string _itemTemplate;
-               public Dictionary<string, ItemTemplate> ItemTemplates;
+               public Dictionary<string, ItemTemplate> ItemTemplates = new Dictionary<string, Crow.ItemTemplate>();//TODO: dont instantiate if not used
+                                                                                                                                                                                                       //but then i should test if null in msil gen
 -
                [XmlAttributeAttribute][DefaultValue(null)]
                public string Template {
                        get { return _template; }
index c1238081792915d1fd4af1864f27cbd9384c337d,0474fdc0581db1cd09b5c8c18cdf707460c86199..7792de4dee309214d8934cef39a2a91684608bf5
@@@ -92,58 -108,69 +108,71 @@@ namespace Cro
                                //if its a template, first read template elements
                                using (IMLReader reader = new IMLReader (il, tmpXml)) {
  
-                                       string template = reader.GetAttribute ("Template");
+                                       string templatePath = reader.GetAttribute ("Template");
+                                       //string itemTemplatePath = reader.GetAttribute ("ItemTemplate");
  
                                        bool inlineTemplate = false;
-                                       if (string.IsNullOrEmpty (template)) {
 -                                      if (string.IsNullOrEmpty (templatePath)) {
--                                              reader.Read ();
--
--                                              while (reader.Read ()) {
--                                                      if (!reader.IsStartElement ())
--                                                              continue;
--                                                      if (reader.Name == "Template") {
--                                                              inlineTemplate = true;
--                                                              reader.Read ();
--
--                                                              readChildren (reader, crowType);
--                                                              continue;
-                                                       }else if (reader.Name == "ItemTemplate") {
 -                                                      } else if (reader.Name == "ItemTemplate") {
--                                                              reader.Skip ();
-                                                               //                                                              string dataType = "default", datas = "", itemTmp;
-                                                               //                                                              while (reader.MoveToNextAttribute ()) {
-                                                               //                                                                      if (reader.Name == "DataType")
-                                                               //                                                                              dataType = reader.Value;
-                                                               //                                                                      else if (reader.Name == "Data")
-                                                               //                                                                              datas = reader.Value;
-                                                               //                                                              }
-                                                               //
-                                                               //                                                              reader.Read();
-                                                               //                                                              itemTmp = .ReadInnerXml ();
-                                                               //
-                                                               //                                                              if (ItemTemplates == null)
-                                                               //                                                                      ItemTemplates = new Dictionary<string, ItemTemplate> ();
-                                                               //                                                              //TODO:check encoding
-                                                               //                                                              ItemTemplates[dataType] = new ItemTemplate (Encoding.UTF8.GetBytes(itemTmp));
-                                                               //                                                              if (!string.IsNullOrEmpty (datas))
-                                                               //                                                                      ItemTemplates [dataType].CreateExpandDelegate(this, dataType, datas);
--                                                              continue;
 -
 -                                                              string dataType = "default", datas = "", path = "";
 -                                                              while (reader.MoveToNextAttribute ()) {
 -                                                                      if (reader.Name == "DataType")
 -                                                                              dataType = reader.Value;
 -                                                                      else if (reader.Name == "Data")
 -                                                                              datas = reader.Value;
 -                                                                      else if (reader.Name == "Path")
 -                                                                              path = reader.Value;
 -                                                              }
 -
 -                                                              using (IMLReader iTmp = new IMLReader (null, reader.ReadInnerXml ())) {
 -                                                                      string uid = Guid.NewGuid ().ToString ();
 -                                                                      Interface.Instantiators [uid] =
 -                                                                      new ItemTemplate (iTmp.RootType, iTmp.GetLoader ());
 -                                                                      reader.il.Emit (OpCodes.Ldstr, dataType);
 -                                                                      reader.il.Emit (OpCodes.Ldstr, uid);
 -                                                                      reader.il.Emit (OpCodes.Callvirt,
 -                                                                              typeof(Interface).GetMethod ("GetItemTemplate"));
 -                                                                      reader.il.Emit (OpCodes.Callvirt,
 -                                                                              typeof(Dictionary<string, ItemTemplate>).GetMethod ("Add",
 -                                                                                      new Type[] { typeof(string), typeof(ItemTemplate) }));
 -                                                              }
 -//                                                    if (!string.IsNullOrEmpty (datas))
 -//                                                            ItemTemplates [dataType].CreateExpandDelegate(this, dataType, datas);
++                                      reader.Read ();
 -                                                              continue;
++                                      while (reader.Read ()) {
++                                              if (!reader.IsStartElement ())
++                                                      continue;
++                                              if (reader.Name == "Template") {
++                                                      inlineTemplate = true;
++                                                      reader.Read ();
++
++                                                      readChildren (reader, crowType);
++                                                      continue;
++                                              } else if (reader.Name == "ItemTemplate") {
++                                                      string dataType = "default", datas = "", path = "";
++                                                      while (reader.MoveToNextAttribute ()) {
++                                                              if (reader.Name == "DataType")
++                                                                      dataType = reader.Value;
++                                                              else if (reader.Name == "Data")
++                                                                      datas = reader.Value;
++                                                              else if (reader.Name == "Path")
++                                                                      path = reader.Value;
                                                        }
-                                               }
-                                               if (!inlineTemplate) {
-                                                       DefaultTemplate dt = (DefaultTemplate)crowType.GetCustomAttributes (typeof(DefaultTemplate), true).FirstOrDefault();
-                                                       template = dt.Path;
 -                                                      if (!inlineTemplate) {
 -                                                              DefaultTemplate dt = (DefaultTemplate)crowType.GetCustomAttributes (typeof(DefaultTemplate), true).FirstOrDefault ();
 -                                                              templatePath = dt.Path;
++                                                      using (IMLReader iTmp = new IMLReader (null, reader.ReadInnerXml ())) {
++                                                              string uid = Guid.NewGuid ().ToString ();
++                                                              Interface.Instantiators [uid] =
++                                                              new ItemTemplate (iTmp.RootType, iTmp.GetLoader ());
++                                                              reader.il.Emit (OpCodes.Ldloc_0);//load TempControl ref
++                                                              reader.il.Emit (OpCodes.Ldfld,//load ItemTemplates dic field
++                                                                      typeof(TemplatedControl).GetField("ItemTemplates"));
++                                                              reader.il.Emit (OpCodes.Ldstr, dataType);//load key
++                                                              reader.il.Emit (OpCodes.Ldstr, uid);//load value
++                                                              reader.il.Emit (OpCodes.Callvirt,
++                                                                      typeof(Interface).GetMethod ("GetItemTemplate"));
++                                                              reader.il.Emit (OpCodes.Callvirt,
++                                                                      typeof(Dictionary<string, ItemTemplate>).GetMethod ("set_Item",
++                                                                              new Type[] { typeof(string), typeof(ItemTemplate) }));
+                                                       }
++//                                                    if (!string.IsNullOrEmpty (datas))
++//                                                            ItemTemplates [dataType].CreateExpandDelegate(this, dataType, datas);
++
++                                                      continue;
                                                }
                                        }
++
                                        if (!inlineTemplate) {
--                                              reader.il.Emit (OpCodes.Ldloc_0);//Load  this templateControl ref
++                                              if (string.IsNullOrEmpty (templatePath)) {
++                                                      DefaultTemplate dt = (DefaultTemplate)crowType.GetCustomAttributes (typeof(DefaultTemplate), true).FirstOrDefault ();
++                                                      if (dt!=null)
++                                                              templatePath = dt.Path;
++                                              }
 -                                              reader.il.Emit (OpCodes.Ldstr, templatePath); //Load template path string
 -                                              reader.il.Emit (OpCodes.Callvirt,//call Interface.Load(path)
 -                                                      typeof(Interface).GetMethod ("Load", BindingFlags.Static | BindingFlags.Public));
++                                              if (!string.IsNullOrEmpty (templatePath)) {
++                                                      reader.il.Emit (OpCodes.Ldloc_0);//Load  this templateControl ref
 +
-                                               reader.il.Emit (OpCodes.Ldstr, template); //Load template path string
-                                               reader.il.Emit (OpCodes.Callvirt,//call Interface.Load(path)
-                                                       typeof(Interface).GetMethod ("Load", BindingFlags.Static | BindingFlags.Public));
++                                                      reader.il.Emit (OpCodes.Ldstr, templatePath); //Load template path string
++                                                      reader.il.Emit (OpCodes.Callvirt,//call Interface.Load(path)
++                                                              typeof(Interface).GetMethod ("Load", BindingFlags.Static | BindingFlags.Public));
++                                                      reader.il.Emit (OpCodes.Callvirt,//add child
++                                                              crowType.GetMethod ("loadTemplate", BindingFlags.Instance | BindingFlags.NonPublic));
++                                              }
                                        }
--                                      reader.il.Emit (OpCodes.Callvirt,//add child
--                                              crowType.GetMethod ("loadTemplate", BindingFlags.Instance | BindingFlags.NonPublic));
                                }
                        }
  
                                                CompilerServices.EmitSetValue (reader.il, pi, style);
                                        }
                                }
++                              reader.il.Emit (OpCodes.Ldloc_0);
++                              reader.il.Emit (OpCodes.Callvirt, typeof(GraphicObject).GetMethod ("loadDefaultValues"));
++
                                if (reader.HasAttributes) {
--                                      reader.il.Emit (OpCodes.Ldloc_0);
--                                      reader.il.Emit (OpCodes.Callvirt, typeof(GraphicObject).GetMethod ("loadDefaultValues"));
  
                                        MethodInfo miAddBinding = typeof(GraphicObject).GetMethod ("BindMember");
  
                                                        miAddChild = typeof(Container).GetMethod ("SetChild");
                                                else if (typeof(TemplatedContainer).IsAssignableFrom (crowType))
                                                        miAddChild = typeof(TemplatedContainer).GetProperty("Content").GetSetMethod();
++                                              else if (typeof(TemplatedControl).IsAssignableFrom (crowType))
++                                                      miAddChild = typeof(TemplatedControl).GetMethod ("loadTemplate",
++                                                              BindingFlags.Instance | BindingFlags.NonPublic);                                                
                                                else if (typeof(PrivateContainer).IsAssignableFrom (crowType))
                                                        miAddChild = typeof(PrivateContainer).GetMethod ("SetChild",
                                                                BindingFlags.Instance | BindingFlags.NonPublic);
index f3d8c73bc98b98442f5739bb372034b23d021458,517d481afc493a0b5dcb3af7ce63effe0557e924..ba9769b14384ea37f8ada50ef14487a9fdfabcf0
@@@ -82,7 -84,7 +84,7 @@@ namespace Cro
                public static FontOptions FontRenderingOptions;
                #endregion
  
--              internal bool XmlLoading = false;
++              internal bool XmlLoading = true;
  
                public Dictionary<string,object> Ressources = new Dictionary<string, object>();
                public Queue<LayoutingQueueItem> LayoutingQueue = new Queue<LayoutingQueueItem> ();
index b2a5f3caf1a7675fe36e2a8953c4f654666ea060,b2a5f3caf1a7675fe36e2a8953c4f654666ea060..a7909022354ee835bda44192401a5ce6560ec36c
@@@ -107,10 -107,10 +107,10 @@@ namespace Cro
                                        Layoutable.RegisteredLayoutings |= LayoutType;
                                        Interface.CurrentInterface.DiscardQueue.Enqueue (this);
                                }
--                              //#if DEBUG_LAYOUTING
++                              #if DEBUG_LAYOUTING
                                else
                                        Debug.WriteLine ("\tDELETED    => " + this.ToString ());
--                              //#endif
++                              #endif
                        }
                        #if DEBUG_LAYOUTING
                        currentLQI = null;