From e9963abca14fbad8ff6c215e5c9d6b45652b38dc Mon Sep 17 00:00:00 2001 From: jpbruyere Date: Fri, 5 Aug 2016 07:05:13 +0200 Subject: [PATCH] * ListBox.cs: * TemplatedControl.cs: set ItemTemplate as public * IMLStream.cs: copy ItemTemplates in tree hierarchy * TreeView.crow: add scrolling * treeList.crow: simple list template for tree children * testTreeView.crow: update test * Tests.csproj: update tests --- Templates/TreeView.crow | 12 ++++++---- Tests/Interfaces/Unsorted/testTreeView.crow | 26 +++++++-------------- Tests/Interfaces/treeList.crow | 3 +++ Tests/Tests.csproj | 1 + src/GraphicObjects/ListBox.cs | 14 +++++------ src/GraphicObjects/TemplatedControl.cs | 10 ++++---- src/IMLStream.cs | 15 +++++++++--- 7 files changed, 43 insertions(+), 38 deletions(-) create mode 100755 Tests/Interfaces/treeList.crow diff --git a/Templates/TreeView.crow b/Templates/TreeView.crow index 8915e154..5bad322d 100644 --- a/Templates/TreeView.crow +++ b/Templates/TreeView.crow @@ -1,7 +1,9 @@ - - - + + + + diff --git a/Tests/Interfaces/Unsorted/testTreeView.crow b/Tests/Interfaces/Unsorted/testTreeView.crow index c3bfabc6..ca5ae138 100755 --- a/Tests/Interfaces/Unsorted/testTreeView.crow +++ b/Tests/Interfaces/Unsorted/testTreeView.crow @@ -1,27 +1,13 @@  - - + + + + \ No newline at end of file diff --git a/Tests/Interfaces/treeList.crow b/Tests/Interfaces/treeList.crow new file mode 100755 index 00000000..61ee12a4 --- /dev/null +++ b/Tests/Interfaces/treeList.crow @@ -0,0 +1,3 @@ + + \ No newline at end of file diff --git a/Tests/Tests.csproj b/Tests/Tests.csproj index 56e6a1ec..e60faad5 100644 --- a/Tests/Tests.csproj +++ b/Tests/Tests.csproj @@ -370,6 +370,7 @@ + diff --git a/src/GraphicObjects/ListBox.cs b/src/GraphicObjects/ListBox.cs index c4f9e0e1..24ceb618 100644 --- a/src/GraphicObjects/ListBox.cs +++ b/src/GraphicObjects/ListBox.cs @@ -112,10 +112,10 @@ namespace Crow } #endregion void loading(){ - if (itemTemplates == null) - itemTemplates = new Dictionary (); - if (!itemTemplates.ContainsKey ("default")) - itemTemplates["default"] = new ItemTemplate (ItemTemplate); + if (ItemTemplates == null) + ItemTemplates = new Dictionary (); + if (!ItemTemplates.ContainsKey ("default")) + ItemTemplates["default"] = new ItemTemplate (ItemTemplate); for (int i = 1; i <= (data.Count / itemPerPage) + 1; i++) { if (cancelLoading) @@ -163,10 +163,10 @@ namespace Crow ItemTemplate itemStream = null; Type dataType = data [i].GetType (); - if (itemTemplates.ContainsKey (dataType.FullName)) - itemStream = itemTemplates [dataType.FullName]; + if (ItemTemplates.ContainsKey (dataType.FullName)) + itemStream = ItemTemplates [dataType.FullName]; else - itemStream = itemTemplates ["default"]; + itemStream = ItemTemplates ["default"]; lock (Interface.CurrentInterface.LayoutMutex) { g = Interface.Load (itemStream); diff --git a/src/GraphicObjects/TemplatedControl.cs b/src/GraphicObjects/TemplatedControl.cs index b04fe204..744cd329 100644 --- a/src/GraphicObjects/TemplatedControl.cs +++ b/src/GraphicObjects/TemplatedControl.cs @@ -64,7 +64,7 @@ namespace Crow string _template; string _itemTemplate; - protected Dictionary itemTemplates; + public Dictionary ItemTemplates; [XmlAttributeAttribute][DefaultValue(null)] public string Template { @@ -150,12 +150,12 @@ namespace Crow xr.MoveToElement (); itemTmp = xr.ReadInnerXml (); - if (itemTemplates == null) - itemTemplates = new Dictionary (); + if (ItemTemplates == null) + ItemTemplates = new Dictionary (); //TODO:check encoding - itemTemplates[dataType] = new ItemTemplate (Encoding.UTF8.GetBytes(itemTmp)); + ItemTemplates[dataType] = new ItemTemplate (Encoding.UTF8.GetBytes(itemTmp)); if (!string.IsNullOrEmpty (datas)) - itemTemplates [dataType].CreateExpandDelegate(dataType, datas); + ItemTemplates [dataType].CreateExpandDelegate(this, dataType, datas); continue; } diff --git a/src/IMLStream.cs b/src/IMLStream.cs index c7e26d5d..ccc09f45 100644 --- a/src/IMLStream.cs +++ b/src/IMLStream.cs @@ -46,9 +46,9 @@ namespace Crow public ItemTemplate(Byte[] b) : base(b){} - public void CreateExpandDelegate (string strDataType, string method){ + public void CreateExpandDelegate (TemplatedControl host, string strDataType, string method){ Type dataType = Type.GetType(strDataType); - Type hostType = typeof(ItemTemplate);//not sure is the best place to put the dyn method + Type hostType = typeof(TemplatedControl);//not sure is the best place to put the dyn method Type evtType = typeof(EventHandler); Type listBoxType = typeof(ListBox); @@ -65,13 +65,22 @@ namespace Crow #region IL generation ILGenerator il = dm.GetILGenerator (256); + il.DeclareLocal(typeof(GraphicObject)); il.Emit (OpCodes.Ldarg_1); MethodInfo miFindByName = typeof(GraphicObject).GetMethod("FindByName"); il.Emit(OpCodes.Ldstr, "List"); il.Emit (OpCodes.Callvirt, miFindByName); + il.Emit (OpCodes.Stloc_0); + FieldInfo fiTemplates = typeof(TemplatedControl).GetField("ItemTemplates"); + il.Emit (OpCodes.Ldloc_0); + il.Emit (OpCodes.Ldarg_0); + il.Emit (OpCodes.Ldfld, fiTemplates); + il.Emit (OpCodes.Stfld, fiTemplates); + + il.Emit (OpCodes.Ldloc_0); il.Emit (OpCodes.Ldarg_1); il.Emit (OpCodes.Callvirt, typeof(GraphicObject).GetProperty("DataSource").GetGetMethod ()); @@ -84,7 +93,7 @@ namespace Crow #endregion - Expand = (EventHandler)dm.CreateDelegate (evtType, this); + Expand = (EventHandler)dm.CreateDelegate (evtType, host); } } } -- 2.47.3