]> O.S.I.I.S - jp/crow.git/commitdiff
ItemTemplate class derived from IMLStream.
authorjpbruyere <jp.bruyere@hotmail.com>
Fri, 5 Aug 2016 01:59:33 +0000 (03:59 +0200)
committerjpbruyere <jp.bruyere@hotmail.com>
Fri, 5 Aug 2016 01:59:33 +0000 (03:59 +0200)
replace xmlLoadingCount by xmlLoading.
modifié :         src/GraphicObjects/ListBox.cs
modifié :         src/GraphicObjects/TemplatedControl.cs
modifié :         src/IMLStream.cs
modifié :         src/Interface.cs

src/GraphicObjects/ListBox.cs
src/GraphicObjects/TemplatedControl.cs
src/IMLStream.cs
src/Interface.cs

index fdb3960f21c1326eb64b75c78a6b55a9e3c71456..c4f9e0e19382ad72899b8145e2a0ecf2b821772e 100644 (file)
@@ -113,9 +113,9 @@ namespace Crow
                #endregion
                void loading(){
                        if (itemTemplates == null)
-                               itemTemplates = new Dictionary<string, IMLStream> ();
+                               itemTemplates = new Dictionary<string, ItemTemplate> ();
                        if (!itemTemplates.ContainsKey ("default"))
-                               itemTemplates["default"] = new IMLStream (ItemTemplate);
+                               itemTemplates["default"] = new ItemTemplate (ItemTemplate);
 
                        for (int i = 1; i <= (data.Count / itemPerPage) + 1; i++) {
                                if (cancelLoading)
@@ -160,7 +160,7 @@ namespace Crow
                                        return;
                                
                                GraphicObject g = null;
-                               IMLStream itemStream = null;
+                               ItemTemplate itemStream = null;
                                Type dataType = data [i].GetType ();
 
                                if (itemTemplates.ContainsKey (dataType.FullName))
@@ -174,8 +174,8 @@ namespace Crow
                                        g.DataSource = data [i];
                                }
                                g.MouseClick += itemClick;
-                               if (!string.IsNullOrEmpty (itemStream.Datas)) {
-
+                               if (itemStream.Expand != null && g is Expandable) {
+                                       (g as Expandable).Expand += itemStream.Expand;
                                }
                                //g.LogicalParent = this;
                        }
index 590ca84ba858c88444d06a2b1eb207d29b960840..d3feb1d26e30b0f03cfc5dfb37d23149a0f5b563 100644 (file)
@@ -56,7 +56,7 @@ namespace Crow
                #region CTOR
                public TemplatedControl () : base()
                {
-                       if (Interface.XmlLoaderCount > 0)
+                       if (Interface.CurrentInterface.XmlLoading)
                                return;
                        loadTemplate ();
                }
@@ -64,7 +64,7 @@ namespace Crow
 
                string _template;
                string _itemTemplate;
-               protected Dictionary<string, IMLStream> itemTemplates;
+               protected Dictionary<string, ItemTemplate> itemTemplates;
 
                [XmlAttributeAttribute][DefaultValue(null)]
                public string Template {
@@ -151,10 +151,10 @@ namespace Crow
                                                                itemTmp = xr.ReadInnerXml ();
 
                                                                if (itemTemplates == null)
-                                                                       itemTemplates = new Dictionary<string, IMLStream> ();
+                                                                       itemTemplates = new Dictionary<string, ItemTemplate> ();
                                                                //TODO:check encoding
-                                                               itemTemplates[dataType] = new IMLStream (Encoding.UTF8.GetBytes(itemTmp));
-                                                               itemTemplates [dataType].Datas = datas;
+                                                               itemTemplates[dataType] = new ItemTemplate (Encoding.UTF8.GetBytes(itemTmp));
+                                                               itemTemplates [dataType].CreateExpandDelegate(dataType, datas);
 
                                                                continue;
                                                        }
index 7207327d5393cff24a2f6d95384eaa7652d5e6fc..142625950bacd6a69c03f93fc3a078745add2a31 100644 (file)
 //  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 using System;
 using System.IO;
+using System.Reflection;
+using System.Reflection.Emit;
 
 namespace Crow
 {
        public class IMLStream : MemoryStream {
+               public string Path;
                public Type RootType;
-               //TODO:this has nothing to do in there, I should derive IMLStream
-               public string Datas;
                public IMLStream(string path) : base (){
+                       Path = path;
                        using (Stream stream = Interface.GetStreamFromPath (path))
                                stream.CopyTo (this);
                        RootType = Interface.GetTopContainerOfXMLStream (this);
@@ -36,5 +38,39 @@ namespace Crow
                        RootType = Interface.GetTopContainerOfXMLStream (this);
                }
        }
+       public class ItemTemplate : IMLStream {         
+               public EventHandler Expand;
+
+               public ItemTemplate(string path)
+                       : base(path){}
+               public ItemTemplate(Byte[] b)
+                       : base(b){}
+
+               public void CreateExpandDelegate (string strDataType, string method){
+                       Type dataType = Type.GetType(strDataType);
+                       Type host_type = typeof(ItemTemplate);//not sure is the best place to put the dyn method
+                       Type evt_type = typeof(EventHandler);
+
+                       MethodInfo evtInvoke = evt_type.GetMethod ("Invoke");
+                       ParameterInfo [] evtParams = evtInvoke.GetParameters ();
+                       Type handlerArgsType = evtParams [1].ParameterType;
+
+                       Type [] args = { typeof (object), typeof (object), handlerArgsType };
+                       DynamicMethod dm = new DynamicMethod ("dyn_expand_" + method,
+                               typeof (void),
+                               args,
+                               host_type);
+
+
+                       #region IL generation
+                       ILGenerator il = dm.GetILGenerator (256);
+
+                       il.Emit (OpCodes.Ret);
+
+                       #endregion
+
+                       Expand = (EventHandler)dm.CreateDelegate (evt_type, this);
+               }
+       }
 }
 
index ca5cb28f689dbffc10561549570cdda85c1a0064..3233cdfeb26bdf3ce948722aea1fd8e864196d09 100644 (file)
@@ -59,11 +59,6 @@ namespace Crow
                #endregion
 
                #region Static and constants
-               /// <summary> keep ressource path for debug msg </summary>
-               internal static string CurrentGOMLPath = "";
-               //used in templatedControl
-               internal static int XmlLoaderCount = 0;
-
                public static int TabSize = 4;
                public static string LineBreak = "\r\n";
                //TODO: shold be declared in graphicObject
@@ -227,17 +222,14 @@ namespace Crow
                        System.Globalization.CultureInfo savedCulture = Thread.CurrentThread.CurrentCulture;
                        Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture;
 
-                       Interface.XmlLoaderCount ++;
-                       CurrentGOMLPath = path;
                        GraphicObject tmp = null;
                        try {
                                using (Stream stream = GetStreamFromPath (path)) {
                                        tmp = Load(stream, GetTopContainerOfXMLStream(stream), hostClass);
                                }
                        } catch (Exception ex) {
-                               throw new Exception ("Error loading <" + CurrentGOMLPath + ">:", ex);
+                               throw new Exception ("Error loading <" + path + ">:", ex);
                        }
-                       Interface.XmlLoaderCount --;
 
                        Thread.CurrentThread.CurrentCulture = savedCulture;