]> O.S.I.I.S - jp/crow.git/commitdiff
LogicalParent use in all bindings; Resolved boolean in Binding class to avoid multipl...
authorjpbruyere <jp.bruyere@hotmail.com>
Tue, 9 Feb 2016 17:48:58 +0000 (18:48 +0100)
committerjpbruyere <jp.bruyere@hotmail.com>
Tue, 9 Feb 2016 17:49:44 +0000 (18:49 +0100)
resoved all tree in templated control, to allow complex bindings outside template content

src/CompilerServices/CompilerServices.cs
src/GraphicObjects/GraphicObject.cs
src/GraphicObjects/ILayoutable.cs
src/GraphicObjects/TemplatedControl.cs
src/OpenTKGameWindow.cs

index b640a6283ec17925099bc9b5121cfe0d3f119ddb..4c5da03d37d1a3477d62072bdd77ff68061af15e 100644 (file)
@@ -60,7 +60,7 @@ namespace Crow
                public string DynMethodId {
                        get { return dynMethodId; }
                }
-                               
+               public bool Resolved = false;
 
                public MemberReference Source;
                public MemberReference Target;
@@ -103,7 +103,7 @@ namespace Crow
                                        if (tmp == null)
                                                return false;
                                        if (bindingExp [ptr] == "..")
-                                               tmp = tmp.Parent as ILayoutable;
+                                               tmp = tmp.LogicalParent;
                                        else if (bindingExp [ptr] == ".") {
                                                if (ptr > 0)
                                                        throw new Exception ("Syntax error in binding, './' may only appear in first position");                                                
@@ -143,6 +143,11 @@ namespace Crow
                {
                        Target = null;
                        dynMethodId = "";
+                       Resolved = false;
+               }
+               public override string ToString ()
+               {
+                       return string.Format ("[Binding: {0}.{1} <= {2}]", Source.Instance, Source.Member.Name, Expression);
                }
        }
 
index 09b1776d6bfa7cba42b67c0dd984b82f3f065f22..93fa85bbe6fd89b7a72b5924f747270efa70faaa 100644 (file)
@@ -66,6 +66,7 @@ namespace Crow
 
                #region private fields
                LayoutingType registeredLayoutings = LayoutingType.None;
+               ILayoutable logicalParent;
                ILayoutable _parent;
                string _name = "unamed";
                Fill _background = Color.Transparent;
@@ -86,10 +87,6 @@ namespace Crow
 
                #region public fields
                /// <summary>
-               /// The logical parent (used mainly for bindings) as opposed to the parent in the graphic tree
-               /// </summary>
-               public GraphicObject LogicalParent;
-               /// <summary>
                /// Original size and position 0=Stretched; -1=Fit
                /// </summary>
                public Rectangle Bounds;
@@ -135,6 +132,10 @@ namespace Crow
                        }
                }
 
+               public ILayoutable LogicalParent {
+                       get { return logicalParent == null ? Parent : logicalParent; }
+                       set { logicalParent = value; }
+               }
 
                [XmlIgnore]public virtual Rectangle ClientRectangle {
                        get {
@@ -422,8 +423,7 @@ namespace Crow
                        }
                        get {                           
                                return dataSource == null ? 
-                                       LogicalParent == null ?
-                                       Parent is GraphicObject ? (Parent as GraphicObject).DataSource : null :  LogicalParent.DataSource : dataSource;
+                                       (LogicalParent as GraphicObject).DataSource : dataSource;
                        }
                }
                #endregion
@@ -905,10 +905,11 @@ namespace Crow
                        #if DEBUG_BINDING
                        Debug.WriteLine ("ResolveBinding => " + this.ToString ());
                        #endif
-
+                       if (Bindings.Count == 0)
+                               return;
                        Dictionary<object,List<Binding>> resolved = new Dictionary<object, List<Binding>>();
                        foreach (Binding b in Bindings) {
-                               if (!string.IsNullOrEmpty (b.DynMethodId))
+                               if (b.Resolved)
                                        continue;
                                if (b.Source.Member.MemberType == MemberTypes.Event) {
                                        if (b.Expression.StartsWith("{")){
@@ -928,6 +929,7 @@ namespace Crow
                                        MethodInfo addHandler = b.Source.Event.GetAddMethod ();
                                        Delegate del = Delegate.CreateDelegate (b.Source.Event.EventHandlerType, b.Target.Instance, b.Target.Method);
                                        addHandler.Invoke (this, new object[] { del });
+                                       b.Resolved = true;
                                        continue;
                                }
                                List<Binding> bindings = null;
@@ -936,6 +938,7 @@ namespace Crow
                                        resolved [b.Target.Instance] = bindings;
                                }
                                bindings.Add (b);
+                               b.Resolved = true;
                        }
 
                        MethodInfo stringEquals = typeof(string).GetMethod
@@ -1072,7 +1075,12 @@ namespace Crow
                                                        throw new Exception ("unhandle target member type in binding");
                                        }
 
-                                       if (!targetValueType.IsValueType)
+                                       if (b.Source.Property.PropertyType == typeof(string)) {
+                                               MemberReference tostring = new MemberReference (b.Source.Instance);
+                                               if (!tostring.FindMember ("ToString"))
+                                                       throw new Exception ("ToString method not found");
+                                               il.Emit (OpCodes.Callvirt, tostring.Method);
+                                       }else if (!targetValueType.IsValueType)
                                                il.Emit(OpCodes.Castclass, targetValueType);
                                        else if (b.Source.Property.PropertyType != targetValueType)
                                                il.Emit(OpCodes.Callvirt, CompilerServices.GetConvertMethod( b.Source.Property.PropertyType ));
@@ -1215,6 +1223,8 @@ namespace Crow
                        Delegate del = dm.CreateDelegate(binding.Source.Event.EventHandlerType,this);
                        MethodInfo addHandler = binding.Source.Event.GetAddMethod ();
                        addHandler.Invoke(this, new object[] {del});
+
+                       binding.Resolved = true;
                }
                /// <summary>
                /// Remove dynamic delegates by ids from dataSource
index edddedd7033ebf30e5577466a727d2f18dc5cca6..54e54f034291aa25bac322c1bfc7732532cf1c21 100644 (file)
@@ -5,8 +5,13 @@ namespace Crow
 {
        public interface ILayoutable
        {
+               /// <summary> Unsuccessfull UpdateLayout and requeueing count </summary>
                int LayoutingTries { get; set; }
+               /// <summary> Parent in the graphic tree </summary>
                ILayoutable Parent { get; set; }
+               /// <summary> The logical parent (used mainly for bindings) as opposed
+               ///  to the parent in the graphic tree </summary>
+               ILayoutable LogicalParent { get; set; }
 
                Rectangle ClientRectangle { get; }
                Rectangle getSlot();
index 1f527bc3ff48f249ca2b41ef28562cef82709cdf..9dacd4665eb54ef8294a31b9ff9a71a65d145ac6 100644 (file)
@@ -103,10 +103,6 @@ namespace Crow
                        //prevent name searching in template
                        return nameToFind == this.Name ? this : null;
                }
-               public override void ResolveBindings ()
-               {
-                       base.ResolveBindingsWithNoRecurse ();
-               }
                #endregion
 
                protected virtual void loadTemplate(GraphicObject template = null)
@@ -117,7 +113,7 @@ namespace Crow
                        }else
                                this.SetChild (template);
                        
-                       this.child.ResolveBindings ();
+                       this.ResolveBindings ();
                }
                        
                #region IXmlSerializable
index 3b70d92e6517a72acc98474ba4f1eee44f56bb23..ac3cd75cd7826a43ca156599297de6e6e5693228 100644 (file)
@@ -562,19 +562,18 @@ namespace Crow
                {
                        return r;
                }
-               public Rectangle ScreenCoordinates (Rectangle r)
-               {
-                       return r;
-               }
+               public Rectangle ScreenCoordinates (Rectangle r) => r;
 
                public ILayoutable Parent {
-                       get {
-                               return null;
-                       }
-                       set {
-                               throw new NotImplementedException ();
-                       }
+                       get { return null; }
+                       set { throw new NotImplementedException (); }
+               }
+
+               public ILayoutable LogicalParent {
+                       get { return null; }
+                       set { throw new NotImplementedException (); }
                }
+
                Rectangle ILayoutable.ClientRectangle {
                        get { return new Size(this.ClientRectangle.Size.Width,this.ClientRectangle.Size.Height); }
                }