diff options
| author | jpbruyere <jp.bruyere@hotmail.com> | 2017-01-24 12:46:43 +0100 |
|---|---|---|
| committer | jpbruyere <jp.bruyere@hotmail.com> | 2017-01-24 12:46:43 +0100 |
| commit | d8acaa909ce73e150827db9846cd8690fb93d68e (patch) | |
| tree | c22aab77a5851aad79505a49dc6ac91ca4b0a106 /src | |
| parent | e39ac936765e88382d858ee6922293315a18b60d (diff) | |
| parent | 1a4fe8bd37ed4a3e3324a134df4f90c14b315918 (diff) | |
Merge branch 'master' into CrowIDE
Diffstat (limited to 'src')
| -rw-r--r-- | src/Colors.cs | 3 | ||||
| -rw-r--r-- | src/CompilerServices/CompilerServices.cs | 442 | ||||
| -rw-r--r-- | src/Fill/Fill.cs | 5 | ||||
| -rw-r--r-- | src/GraphicObjects/ColorSelector.cs | 30 | ||||
| -rw-r--r-- | src/GraphicObjects/GraphicObject.cs | 33 | ||||
| -rw-r--r-- | src/GraphicObjects/HueSelector.cs | 12 | ||||
| -rw-r--r-- | src/GraphicObjects/Label.cs | 135 | ||||
| -rw-r--r-- | src/GraphicObjects/SaturationValueSelector.cs | 15 | ||||
| -rw-r--r-- | src/IML/BindingMember.cs | 160 | ||||
| -rw-r--r-- | src/IML/Node.cs | 12 | ||||
| -rw-r--r-- | src/IML/NodeAddress.cs | 76 | ||||
| -rw-r--r-- | src/Instantiator.cs | 57 | ||||
| -rw-r--r-- | src/SolidColor.cs | 6 | ||||
| -rw-r--r-- | src/rsvg/DimensionData.cs | 9 | ||||
| -rw-r--r-- | src/rsvg/Handle.cs | 187 | ||||
| -rw-r--r-- | src/rsvg/Pixbuf.cs | 133 | ||||
| -rw-r--r-- | src/rsvg/RsvgSharp.SizeFuncNative.cs | 94 | ||||
| -rw-r--r-- | src/rsvg/SizeFunc.cs | 10 |
18 files changed, 621 insertions, 798 deletions
diff --git a/src/Colors.cs b/src/Colors.cs index f55c4187..66d2613a 100644 --- a/src/Colors.cs +++ b/src/Colors.cs @@ -83,9 +83,6 @@ namespace Crow // { // return new Color (v.X, v.Y, v.Z, v.W); // } - public static implicit operator Fill(Color c){ - return new SolidColor (c) as Fill; - } public static bool operator ==(Color left, Color right) diff --git a/src/CompilerServices/CompilerServices.cs b/src/CompilerServices/CompilerServices.cs index e0d6c1e0..31b29fb2 100644 --- a/src/CompilerServices/CompilerServices.cs +++ b/src/CompilerServices/CompilerServices.cs @@ -32,15 +32,18 @@ namespace Crow internal static MethodInfo miGetColCount = typeof(System.Collections.ICollection).GetProperty("Count").GetGetMethod(); internal static MethodInfo miGetDelegateListItem = typeof(List<Delegate>).GetMethod("get_Item", new Type[] { typeof(Int32) }); - internal static MethodInfo miCompileDynEventHandler = typeof(CompilerServices).GetMethod ("compileDynEventHandler", BindingFlags.Static | BindingFlags.Public); - internal static MethodInfo miRemEvtHdlByName = typeof(CompilerServices).GetMethod("RemoveEventHandlerByName", BindingFlags.Static | BindingFlags.Public); - internal static MethodInfo miRemEvtHdlByTarget = typeof(CompilerServices).GetMethod("RemoveEventHandlerByTarget", BindingFlags.Static | BindingFlags.Public); - internal static MethodInfo miGetMethInfoWithRefx = typeof(CompilerServices).GetMethod ("getMethodInfoWithReflexion", BindingFlags.Static | BindingFlags.Public); - internal static MethodInfo miGetMembIinfoWithRefx = typeof(CompilerServices).GetMethod("getMemberInfoWithReflexion", BindingFlags.Static | BindingFlags.Public); - internal static MethodInfo miSetValWithRefx = typeof(CompilerServices).GetMethod("setValueWithReflexion", BindingFlags.Static | BindingFlags.Public); - internal static MethodInfo miGetValWithRefx = typeof(CompilerServices).GetMethod("getValueWithReflexion", BindingFlags.Static | BindingFlags.Public); + internal static MethodInfo miCompileDynEventHandler = typeof(CompilerServices).GetMethod ("compileDynEventHandler", BindingFlags.Static | BindingFlags.NonPublic); + internal static MethodInfo miRemEvtHdlByName = typeof(CompilerServices).GetMethod("removeEventHandlerByName", BindingFlags.Static | BindingFlags.NonPublic); + internal static MethodInfo miRemEvtHdlByTarget = typeof(CompilerServices).GetMethod("removeEventHandlerByTarget", BindingFlags.Static | BindingFlags.NonPublic); + internal static MethodInfo miGetMethInfoWithRefx = typeof(CompilerServices).GetMethod ("getMethodInfoWithReflexion", BindingFlags.Static | BindingFlags.NonPublic); + internal static MethodInfo miGetMembIinfoWithRefx = typeof(CompilerServices).GetMethod("getMemberInfoWithReflexion", BindingFlags.Static | BindingFlags.NonPublic); + internal static MethodInfo miSetValWithRefx = typeof(CompilerServices).GetMethod("setValueWithReflexion", BindingFlags.Static | BindingFlags.NonPublic); + internal static MethodInfo miGetValWithRefx = typeof(CompilerServices).GetMethod("getValueWithReflexion", BindingFlags.Static | BindingFlags.NonPublic); internal static MethodInfo miCreateDel = typeof(CompilerServices).GetMethod ("createDel", BindingFlags.Static | BindingFlags.NonPublic); - internal static MethodInfo miGetImplOp = typeof(CompilerServices).GetMethod ("getImplicitOp", BindingFlags.Static | BindingFlags.Public); + internal static MethodInfo miGetImplOp = typeof(CompilerServices).GetMethod ("getImplicitOp", BindingFlags.Static | BindingFlags.NonPublic); + + + internal static MethodInfo miGoUpLevels = typeof(CompilerServices).GetMethod("goUpNbLevels", BindingFlags.Static | BindingFlags.NonPublic); internal static FieldInfo fiCachedDel = typeof(Instantiator).GetField("cachedDelegates", BindingFlags.Instance | BindingFlags.NonPublic); internal static FieldInfo fiTemplateBinding = typeof(Instantiator).GetField("templateBinding", BindingFlags.Instance | BindingFlags.NonPublic); @@ -236,76 +239,20 @@ namespace Crow } #endregion - /// <summary> - /// retrieve event handler in class or ancestors - /// </summary> - public static FieldInfo GetEventHandlerField (Type type, string eventName) - { - FieldInfo fi; - Type ty = type; - do { - fi = ty.GetField (eventName, - BindingFlags.NonPublic | - BindingFlags.Instance | - BindingFlags.GetField); - ty = ty.BaseType; - if (ty == null) - break; - } while (fi == null); - return fi; - } - - /// <summary> - /// Gets extension methods defined in assembley for extendedType - /// </summary> - /// <returns>Extension methods enumerable</returns> - /// <param name="assembly">Assembly</param> - /// <param name="extendedType">Extended type to search for</param> - public static IEnumerable<MethodInfo> GetExtensionMethods (Assembly assembly, - Type extendedType) - { - IEnumerable<MethodInfo> query = null; - Type curType = extendedType; - - do { - query = from type in assembly.GetTypes () - where type.IsSealed && !type.IsGenericType && !type.IsNested - from method in type.GetMethods (BindingFlags.Static - | BindingFlags.Public | BindingFlags.NonPublic) - where method.IsDefined (typeof (ExtensionAttribute), false) - where method.GetParameters () [0].ParameterType == curType - select method; - - if (query.Count () > 0) - break; - - curType = curType.BaseType; - } while (curType != null); - - return query; - } - - public static MethodInfo SearchExtMethod(Type t, string methodName){ - MethodInfo mi = null; - mi = GetExtensionMethods (Assembly.GetEntryAssembly(), t) - .Where (em => em.Name == methodName).FirstOrDefault (); - if (mi != null) - return mi; - - return GetExtensionMethods (Assembly.GetExecutingAssembly(), t) - .Where (em => em.Name == methodName).FirstOrDefault (); + #region Reflexion helpers + static MemberInfo getMemberInfoWithReflexion(object instance, string member){ + return instance.GetType ().GetMember (member)?.FirstOrDefault(); } - - public static MemberInfo getMemberInfoWithReflexion(object instance, string member){ - return instance.GetType ().GetMember (member).FirstOrDefault(); - } - public static MethodInfo getMethodInfoWithReflexion(object instance, string method){ + static MethodInfo getMethodInfoWithReflexion(object instance, string method){ return instance.GetType ().GetMethod (method, BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public); } - public static Type getEventHandlerType(object instance, string eventName){ - return instance.GetType ().GetEvent (eventName).EventHandlerType; - } - public static void setValueWithReflexion(object dest, object value, string destMember){ + /// <summary> + /// set value, convert if required + /// </summary> + /// <param name="dest">Destination instance</param> + /// <param name="value">Value</param> + /// <param name="destMember">Destination member</param> + static void setValueWithReflexion(object dest, object value, string destMember){ Type destType = null; Type origType = null; object convertedVal = null; @@ -323,13 +270,17 @@ namespace Crow destType =(miDest as FieldInfo).FieldType; if (value != null) { - origType = value.GetType (); - if (destType.IsAssignableFrom (origType)) - convertedVal = Convert.ChangeType (value, destType); - else if (origType.IsPrimitive & destType.IsPrimitive) - convertedVal = GetConvertMethod (destType).Invoke (null, new Object[] { value }); - else - convertedVal = getImplicitOp (origType, destType).Invoke (value, null); + if (destType == TObject)//TODO: check that test of destType is not causing problems + convertedVal = value; + else { + origType = value.GetType (); + if (destType.IsAssignableFrom (origType)) + convertedVal = Convert.ChangeType (value, destType); + else if (origType.IsPrimitive & destType.IsPrimitive) + convertedVal = GetConvertMethod (destType).Invoke (null, new Object[] { value }); + else + convertedVal = getImplicitOp (origType, destType).Invoke (value, null); + } } if (miDest.MemberType == MemberTypes.Property) @@ -337,7 +288,11 @@ namespace Crow else if (miDest.MemberType == MemberTypes.Field) (miDest as FieldInfo).SetValue (dest, convertedVal); } - public static object getValueWithReflexion(object instance, MemberInfo mi){ + /// <summary> + /// Gets value with reflexion, return empty string ("") for string and object and return + /// default value for valueType data. + /// </summary> + static object getValueWithReflexion(object instance, MemberInfo mi){ object tmp = null; Type dstType = null; if (mi == null) @@ -361,7 +316,93 @@ namespace Crow return null; } - public static void emitGetInstance (ILGenerator il, NodeAddress orig, NodeAddress dest){ + /// <summary> + /// Gets all extension methods defined in assembly for Type + /// </summary> + /// <returns>Extension methods enumerable</returns> + /// <param name="assembly">Assembly</param> + /// <param name="extendedType">Extended type to search for</param> + internal static IEnumerable<MethodInfo> GetExtensionMethods (Assembly assembly, + Type extendedType) + { + IEnumerable<MethodInfo> query = null; + Type curType = extendedType; + + do { + query = from type in assembly.GetTypes () + where type.IsSealed && !type.IsGenericType && !type.IsNested + from method in type.GetMethods (BindingFlags.Static + | BindingFlags.Public | BindingFlags.NonPublic) + where method.IsDefined (typeof (ExtensionAttribute), false) + where method.GetParameters () [0].ParameterType == curType + select method; + + if (query.Count () > 0) + break; + + curType = curType.BaseType; + } while (curType != null); + + return query; + } + /// <summary> + /// search for extentions method in entry assembly then in crow assembly + /// </summary> + /// <returns>Extention MethodInfo</returns> + /// <param name="t">Extended type</param> + /// <param name="methodName">Extention method name</param> + internal static MethodInfo SearchExtMethod(Type t, string methodName){ + MethodInfo mi = null; + mi = GetExtensionMethods (Assembly.GetEntryAssembly(), t) + .Where (em => em.Name == methodName).FirstOrDefault (); + if (mi != null) + return mi; + + return GetExtensionMethods (Assembly.GetExecutingAssembly(), t) + .Where (em => em.Name == methodName).FirstOrDefault (); + } + /// <summary> + /// retrieve event handler in class or ancestors + /// </summary> + static FieldInfo getEventHandlerField (Type type, string eventName) + { + FieldInfo fi; + Type ty = type; + do { + fi = ty.GetField (eventName, + BindingFlags.NonPublic | + BindingFlags.Instance | + BindingFlags.GetField); + ty = ty.BaseType; + if (ty == null) + break; + } while (fi == null); + return fi; + } + /// <summary> + /// search for an implicit conversion method in origine or destination classes + /// </summary> + static MethodInfo getImplicitOp(Type origType, Type dstType){ + foreach(MethodInfo mi in origType.GetMethods(BindingFlags.Public|BindingFlags.Static)){ + if (mi.Name == "op_Implicit") { + if (mi.ReturnType == dstType && mi.GetParameters ().FirstOrDefault ().ParameterType == origType) + return mi; + } + } + foreach(MethodInfo mi in dstType.GetMethods(BindingFlags.Public|BindingFlags.Static)){ + if (mi.Name == "op_Implicit") { + if (mi.ReturnType == dstType && mi.GetParameters ().FirstOrDefault ().ParameterType == origType) + return mi; + } + } + return null; + } + #endregion + + /// <summary> + /// Emits tree parsing command to fetch dest instance starting from orig node + /// </summary> + internal static void emitGetInstance (ILGenerator il, NodeAddress orig, NodeAddress dest){ int ptr = 0; while (orig [ptr] == dest [ptr]) { ptr++; @@ -375,13 +416,24 @@ namespace Crow ptr++; } } - public static void emitGetInstance (ILGenerator il, NodeAddress dest){ + /// <summary> + /// Emits tree parsing commands to get child starting at root node + /// </summary> + /// <param name="il">MSIL generator</param> + /// <param name="dest">Absolute Node Address of the instance to get</param> + internal static void emitGetInstance (ILGenerator il, NodeAddress dest){ if (dest == null) return; for (int i = 0; i < dest.Count - 1; i++) emitGetChild (il, dest [i].CrowType, dest [i + 1].Index); } - public static void emitGetChild(ILGenerator il, Type parentType, int index){ + /// <summary> + /// Emits msil to fetch chil instance of current GraphicObject on the stack + /// </summary> + /// <param name="il">Il generator</param> + /// <param name="parentType">Parent type</param> + /// <param name="index">Index of child, -1 for template root</param> + internal static void emitGetChild(ILGenerator il, Type parentType, int index){ if (typeof (Group).IsAssignableFrom (parentType)) { il.Emit (OpCodes.Ldfld, fiChildren); il.Emit(OpCodes.Ldc_I4, index); @@ -403,10 +455,11 @@ namespace Crow return; } } + /// <summary> - /// Emit conversion from orig type to dest type + /// Emit MSIL for conversion from orig type to dest type /// </summary> - public static void emitConvert(ILGenerator il, Type origType, Type destType){ + internal static void emitConvert(ILGenerator il, Type origType, Type destType){ if (destType == CompilerServices.TObject) return; if (destType == typeof(string)) { @@ -439,7 +492,7 @@ namespace Crow /// check type of current object on the stack and convert to dest type, /// use loc_0 so store it as object!!! /// </summary> - public static void emitConvert(ILGenerator il, Type dstType){ + internal static void emitConvert(ILGenerator il, Type dstType){ System.Reflection.Emit.Label endConvert = il.DefineLabel (); System.Reflection.Emit.Label convert = il.DefineLabel (); @@ -500,30 +553,13 @@ namespace Crow il.MarkLabel (endConvert); } - /// <summary> - /// search for an implicit conversion method in origine or destination classes - /// </summary> - public static MethodInfo getImplicitOp(Type origType, Type dstType){ - foreach(MethodInfo mi in origType.GetMethods(BindingFlags.Public|BindingFlags.Static)){ - if (mi.Name == "op_Implicit") { - if (mi.ReturnType == dstType && mi.GetParameters ().FirstOrDefault ().ParameterType == origType) - return mi; - } - } - foreach(MethodInfo mi in dstType.GetMethods(BindingFlags.Public|BindingFlags.Static)){ - if (mi.Name == "op_Implicit") { - if (mi.ReturnType == dstType && mi.GetParameters ().FirstOrDefault ().ParameterType == origType) - return mi; - } - } - return null; - } + /// <summary> /// Removes delegate from event handler by name /// </summary> - public static void RemoveEventHandlerByName(object instance, string eventName, string delegateName){ + static void removeEventHandlerByName(object instance, string eventName, string delegateName){ Type t = instance.GetType (); - FieldInfo fiEvt = CompilerServices.GetEventHandlerField (t, eventName); + FieldInfo fiEvt = getEventHandlerField (t, eventName); if (fiEvt == null) { Debug.WriteLine ("RemoveHandlerByName: Event '" + eventName + "' not found in " + instance); return; @@ -544,9 +580,9 @@ namespace Crow /// <summary> /// Removes delegate from event handler by searching for the object they are bond to /// </summary> - public static void RemoveEventHandlerByTarget(object instance, string eventName, object target){ + static void removeEventHandlerByTarget(object instance, string eventName, object target){ Type t = instance.GetType (); - FieldInfo fiEvt = CompilerServices.GetEventHandlerField (t, eventName); + FieldInfo fiEvt = getEventHandlerField (t, eventName); EventInfo eiEvt = t.GetEvent (eventName); MulticastDelegate multiDel = fiEvt.GetValue (instance) as MulticastDelegate; if (multiDel != null) { @@ -560,7 +596,10 @@ namespace Crow } } } - internal static Delegate createDel(Type eventType, object instance, string method){ + /// <summary> + /// create delegate helper + /// </summary> + static Delegate createDel(Type eventType, object instance, string method){ Type t = instance.GetType (); MethodInfo mi = t.GetMethod (method, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance); if (mi == null) { @@ -569,7 +608,8 @@ namespace Crow } return Delegate.CreateDelegate (eventType, instance, mi); } - public static Delegate compileDynEventHandler(EventInfo sourceEvent, string expression, NodeAddress currentNode = null){ + + internal static Delegate compileDynEventHandler(EventInfo sourceEvent, string expression, NodeAddress currentNode = null){ #if DEBUG_BINDING Debug.WriteLine ("\tCompile Event {0}: {1}", sourceEvent.Name, expression); #endif @@ -597,100 +637,102 @@ namespace Crow string [] srcLines = expression.Trim ().Split (new char [] { ';' }); foreach (string srcLine in srcLines) { - string statement = srcLine.Trim (); - - string [] operandes = statement.Split (new char [] { '=' }); - if (operandes.Length < 2) //not an affectation - { - //maybe we could handle here handler function name + if (string.IsNullOrEmpty (srcLine)) continue; - } - - string rop = operandes [operandes.Length - 1].Trim (); - - #region LEFT OPERANDES - string [] lopParts = operandes [0].Trim ().Split ('/'); - MemberInfo lopMI = null; - - il.Emit (OpCodes.Ldarg_0); //load sender ref onto the stack - - if (lopParts.Length > 1) { - NodeAddress lopNA = getNodeAdressFromBindingExp (currentNode, lopParts); - CompilerServices.emitGetInstance (il, currentNode, lopNA); - lopType = lopNA.NodeType; - } + string [] operandes = srcLine.Trim ().Split (new char [] { '=' }); + if (operandes.Length != 2) //not an affectation + throw new NotSupportedException (); - string [] bindTrg = lopParts.Last().Split ('.'); + System.Reflection.Emit.Label cancel = il.DefineLabel (); + System.Reflection.Emit.Label cancelFinalSet = il.DefineLabel (); + System.Reflection.Emit.Label success = il.DefineLabel (); - if (bindTrg.Length == 1) - lopMI = lopType.GetMember (bindTrg [0]).FirstOrDefault(); - else if (bindTrg.Length == 2) { - //named target - //TODO: - il.Emit(OpCodes.Ldstr, bindTrg[0]); - il.Emit(OpCodes.Callvirt, miFindByName); - lopMI = lopType.GetMember (bindTrg [1]).FirstOrDefault(); - } else - throw new Exception ("Syntax error in binding, expected 'go dot member'"); + BindingMember lop = new BindingMember (operandes [0].Trim ()); + BindingMember rop = new BindingMember (operandes [1].Trim ()); + il.Emit (OpCodes.Ldarg_0); //load sender ref onto the stack, the current node - if (lopMI == null) - throw new Exception (string.Format ("IML BINDING: Member not found")); + #region Left operande + PropertyInfo lopPI = null; - OpCode lopSetOpCode; - dynamic lopSetMI; - Type lopT = null; - switch (lopMI.MemberType) { - case MemberTypes.Property: - lopSetOpCode = OpCodes.Callvirt; - PropertyInfo lopPi = lopMI as PropertyInfo; - lopT = lopPi.PropertyType; - lopSetMI = lopPi.GetSetMethod (); - break; - case MemberTypes.Field: - lopSetOpCode = OpCodes.Stfld; - FieldInfo dstFi = lopMI as FieldInfo; - lopT = dstFi.FieldType; - lopSetMI = dstFi; - break; - default: - throw new Exception (string.Format ("GOML:member type not handle")); - } + //in dyn handler, no datasource binding, so single name in expression are also handled as current node property + if (lop.IsSingleName) + lopPI = lopType.GetProperty (lop.Tokens [0]); + else if (lop.IsCurrentNodeProperty) + lopPI = lopType.GetProperty (lop.Tokens [1]); + else + lop.emitGetTarget (il, cancel); #endregion #region RIGHT OPERANDES - if (rop.StartsWith ("\'")) { - if (!rop.EndsWith ("\'")) - throw new Exception (string.Format - ("GOML:malformed string constant in handler: {0}", rop)); - string strcst = rop.Substring (1, rop.Length - 2); - - il.Emit (OpCodes.Ldstr, strcst); - - } else { - if (lopT.IsEnum) - throw new NotImplementedException (); + if (rop.IsStringConstant){ + il.Emit (OpCodes.Ldstr, rop.Tokens[0]); + lop.emitSetProperty (il); + }else if (rop.IsSingleName && rop.Tokens[0] == "this"){ + il.Emit (OpCodes.Ldarg_0); //load sender ref onto the stack, the current node + lop.emitSetProperty (il); + }else if (rop.LevelsUp ==0 && !string.IsNullOrEmpty(rop.Tokens[0])) {//parsable constant depending on lop type + //if left operand is member of current node, it's easy to fetch type, else we should use reflexion in msil + if (lopPI == null){//accept GraphicObj members, but it's restricive + //TODO: we should get the parse method by reflexion, or something else + lopPI = typeof(GraphicObject).GetProperty (lop.Tokens [lop.Tokens.Length-1]); + if (lopPI == null) + throw new NotSupportedException (); + } - MethodInfo lopParseMi = lopT.GetMethod ("Parse"); + MethodInfo lopParseMi = lopPI.PropertyType.GetMethod ("Parse"); if (lopParseMi == null) throw new Exception (string.Format - ("GOML:no parse method found in: {0}", lopT.Name)); - il.Emit (OpCodes.Ldstr, rop); + ("IML: no static 'Parse' method found in: {0}", lopPI.PropertyType.Name)); + + il.Emit (OpCodes.Ldstr, operandes [1].Trim ()); il.Emit (OpCodes.Callvirt, lopParseMi); - il.Emit (OpCodes.Unbox_Any, lopT); - } + il.Emit (OpCodes.Unbox_Any, lopPI.PropertyType); + //emit left operand assignment + il.Emit (OpCodes.Callvirt, lopPI.GetSetMethod()); + } else {//tree parsing and propert gets + il.Emit (OpCodes.Ldarg_0); //load sender ref onto the stack, the current node + + rop.emitGetTarget (il, cancelFinalSet); + rop.emitGetProperty (il, cancelFinalSet); + lop.emitSetProperty (il); + } #endregion - //emit left operand assignment - il.Emit (lopSetOpCode, lopSetMI); + il.Emit (OpCodes.Br, success); + + il.MarkLabel (cancelFinalSet); + il.Emit (OpCodes.Pop); //pop null MemberInfo on the stack causing cancelation + il.MarkLabel (cancel); + il.Emit (OpCodes.Pop); //pop null instance on the stack causing cancelation + il.MarkLabel (success); } il.Emit (OpCodes.Ret); return dm.CreateDelegate (sourceEvent.EventHandlerType); } - public static string[] splitOnSemiColumnOutsideAccolades (string expression){ + + /// <summary> + /// MSIL helper, go n levels up + /// </summary> + /// <returns><c>true</c>, if logical parents are not null</returns> + /// <param name="instance">Start Instance</param> + /// <param name="levelCount">Levels to go upward</param> + internal static ILayoutable goUpNbLevels(ILayoutable instance, int levelCount){ + ILayoutable tmp = instance; + int i = 0; + while (tmp != null && i < levelCount) { + tmp = tmp.LogicalParent; + i++; + } + return tmp; + } + /// <summary> + /// Splits expression on semicolon but ignore those between accolades + /// </summary> + internal static string[] splitOnSemiColumnOutsideAccolades (string expression){ List<String> exps = new List<string>(); int accCount = 0; int expPtr = 0; @@ -714,36 +756,6 @@ namespace Crow exps.Add(expression); return exps.ToArray (); } - /// <summary> - /// Gets the node adress from binding expression splitted with '/' starting at a given node - /// </summary> - public static NodeAddress getNodeAdressFromBindingExp(NodeAddress sourceAddr, string[] bindingExp){ - int ptr = sourceAddr.Count - 1; - - //if exp start with '/' => Graphic tree parsing start at source - if (string.IsNullOrEmpty (bindingExp [0])) { - //TODO: - } else if (bindingExp [0] == ".") { //search template root - ptr--; - while (ptr >= 0) { - if (typeof(TemplatedControl).IsAssignableFrom (sourceAddr [ptr].CrowType)) - break; - ptr--; - } - } else if (bindingExp [0] == "..") { //search starting at current node - int levelUp = bindingExp.Length - 1; - if (levelUp > ptr + 1) - throw new Exception ("Binding error: try to bind outside IML source"); - ptr -= levelUp; - } - //TODO:change Template special address identified with Nodecount = 0 to something not using array count to 0, - //here linq is working without limits checking in compile option - //but defining a 0 capacity array with limits cheking enabled, cause 'out of memory' error - return new NodeAddress (sourceAddr.Take(ptr+1).ToArray());//[ptr+1]; - //Array.Copy (sourceAddr.ToArray (), targetNode, ptr + 1); - //return new NodeAddress (targetNode); - } - } } diff --git a/src/Fill/Fill.cs b/src/Fill/Fill.cs index 322fa5ae..1f455419 100644 --- a/src/Fill/Fill.cs +++ b/src/Fill/Fill.cs @@ -22,7 +22,10 @@ namespace Crow return (SolidColor)SolidColor.Parse (s); } - + public static implicit operator Color(Fill c){ + SolidColor sc = c as SolidColor; + return sc == null ? default(Color) : sc.color; + } public static implicit operator Fill(Color c){ return new SolidColor (c); } diff --git a/src/GraphicObjects/ColorSelector.cs b/src/GraphicObjects/ColorSelector.cs index 13a588ce..672eea73 100644 --- a/src/GraphicObjects/ColorSelector.cs +++ b/src/GraphicObjects/ColorSelector.cs @@ -54,36 +54,10 @@ namespace Crow mousePos = mPos - r.Position; mousePos.X = Math.Max(cb.X, mousePos.X); - mousePos.X = Math.Min(cb.Right-1, mousePos.X); + mousePos.X = Math.Min(cb.Right, mousePos.X); mousePos.Y = Math.Max(cb.Y, mousePos.Y); - mousePos.Y = Math.Min(cb.Bottom-1, mousePos.Y); + mousePos.Y = Math.Min(cb.Bottom, mousePos.Y); } -// virtual protected void updateColorFromPicking(bool redraw = true){ -// SelectedColor = new SolidColor(getPixelAt(mousePos.X, mousePos.Y)); -// -// updateHSV (); -// -// NotifyValueChanged ("R", R); -// NotifyValueChanged ("G", G); -// NotifyValueChanged ("B", B); -// NotifyValueChanged ("A", A); -// -// if (redraw) -// RegisterForRedraw (); -// } -// -// protected Color getPixelAt(int x, int y){ -// if (bmp == null) -// return Color.Transparent; -// -// int ptr = y * Slot.Width * 4 + x * 4; -// -// return new Color( -// (double)bmp[ptr + 2] * colDiv, -// (double)bmp[ptr + 1] * colDiv, -// (double)bmp[ptr] * colDiv, -// (double)bmp[ptr + 3] * colDiv); -// } } } diff --git a/src/GraphicObjects/GraphicObject.cs b/src/GraphicObjects/GraphicObject.cs index e7ff3d81..070a221a 100644 --- a/src/GraphicObjects/GraphicObject.cs +++ b/src/GraphicObjects/GraphicObject.cs @@ -82,6 +82,7 @@ namespace Crow bool clipToClientRect = true; protected object dataSource; string style; + object tag; #endregion #region public fields @@ -103,8 +104,6 @@ namespace Crow public Rectangle LastPaintedSlot; /// <summary>Prevent requeuing multiple times the same widget</summary> public bool IsQueueForRedraw = false; - /// <summary>Random value placeholder</summary> - public object Tag; /// <summary>drawing Cache, if null, a redraw is done, cached or not</summary> public byte[] bmp; public bool IsDirty = true; @@ -195,7 +194,22 @@ namespace Crow #endregion #region public properties - [XmlAttributeAttribute()][DefaultValue(true)] + /// <summary>Random value placeholder</summary> + [XmlAttributeAttribute] + public object Tag { + get { return tag; } + set { + if (tag == value) + return; + tag = value; + NotifyValueChanged ("Tag", tag); + } + } + /// <summary> + /// If enabled, resulting bitmap of graphic object is cached in an byte array + /// speeding up rendering of complex object. Default is enabled. + /// </summary> + [XmlAttributeAttribute][DefaultValue(true)] public virtual bool CacheEnabled { get { return cacheEnabled; } set { @@ -205,7 +219,10 @@ namespace Crow NotifyValueChanged ("CacheEnabled", cacheEnabled); } } - [XmlAttributeAttribute()][DefaultValue(true)] + /// <summary> + /// If true, rendering of GraphicObject is clipped inside client rectangle + /// </summary> + [XmlAttributeAttribute][DefaultValue(true)] public virtual bool ClipToClientRect { get { return clipToClientRect; } set { @@ -216,7 +233,10 @@ namespace Crow this.RegisterForRedraw (); } } - [XmlAttributeAttribute()][DefaultValue(null)] + /// <summary> + /// Name is used in binding to reference other GraphicObjects inside the graphic tree + /// </summary> + [XmlAttributeAttribute][DefaultValue(null)] public virtual string Name { get { #if DEBUG @@ -682,7 +702,7 @@ namespace Crow string expression; if (!getDefaultEvent(ei, styling, out expression)) continue; - //TODO:dynEventHandler could be cached somewhere, maybe a style instanciato class holding the styling delegate and bound to it. + //TODO:dynEventHandler could be cached somewhere, maybe a style instanciator class holding the styling delegate and bound to it. foreach (string exp in CompilerServices.splitOnSemiColumnOutsideAccolades(expression)) { string trimed = exp.Trim(); if (trimed.StartsWith ("{", StringComparison.OrdinalIgnoreCase)){ @@ -695,6 +715,7 @@ namespace Crow il.Emit (OpCodes.Call, CompilerServices.miGetEvent); //push expression as 2nd arg of compile il.Emit (OpCodes.Ldstr, trimed.Substring (1, trimed.Length - 2)); + //push null as 3rd arg, currentNode, not known when instanciing il.Emit (OpCodes.Ldnull); il.Emit (OpCodes.Callvirt, CompilerServices.miCompileDynEventHandler); il.Emit (OpCodes.Castclass, ei.EventHandlerType); diff --git a/src/GraphicObjects/HueSelector.cs b/src/GraphicObjects/HueSelector.cs index ec0a6f2c..ba1d856b 100644 --- a/src/GraphicObjects/HueSelector.cs +++ b/src/GraphicObjects/HueSelector.cs @@ -53,9 +53,9 @@ namespace Crow if (hue == value) return; hue = value; - notifyHueChanged (); updateMousePosFromHue (); + RegisterForRedraw (); } } protected override void onDraw (Cairo.Context gr) @@ -95,11 +95,11 @@ namespace Crow ctx.SetSourceColor (Color.White); Rectangle r = ClientRectangle; if (Orientation == Orientation.Horizontal) { - r.Width = 5; - r.X = mousePos.X; + r.Width = 4; + r.X = mousePos.X - 2; } else { - r.Height = 5; - r.Y = mousePos.Y; + r.Height = 4; + r.Y = mousePos.Y - 2; } CairoHelpers.CairoRectangle (ctx, r, 2); @@ -126,13 +126,13 @@ namespace Crow else hue = (double)mousePos.Y / (double)ClientRectangle.Height; notifyHueChanged (); + RegisterForRedraw (); } void updateMousePosFromHue(){ if (Orientation == Orientation.Horizontal) mousePos.X = (int)Math.Floor(hue * (double)ClientRectangle.Width); else mousePos.Y = (int)Math.Floor(hue * (double)ClientRectangle.Height); - CurrentInterface.EnqueueForRepaint (this); } void notifyHueChanged(){ NotifyValueChanged ("Hue", hue); diff --git a/src/GraphicObjects/Label.cs b/src/GraphicObjects/Label.cs index e55a4b18..38367348 100644 --- a/src/GraphicObjects/Label.cs +++ b/src/GraphicObjects/Label.cs @@ -29,12 +29,12 @@ using System.Xml.Serialization; using System.ComponentModel; namespace Crow -{ +{ public class Label : GraphicObject { #region CTOR public Label() - { + { } public Label(string _text) @@ -45,7 +45,7 @@ namespace Crow #endregion //TODO:change protected to private - + #region private and protected fields string _text = "label"; Alignment _textAlignment; @@ -55,7 +55,7 @@ namespace Crow bool _multiline; Color selBackground; Color selForeground; - Point mouseLocalPos = -1;//mouse coord in widget space, filled only when clicked + Point mouseLocalPos = -1;//mouse coord in widget space, filled only when clicked int _currentCol; //0 based cursor position in string int _currentLine; Point _selBegin = -1; //selection start (row,column) @@ -98,10 +98,10 @@ namespace Crow public Alignment TextAlignment { get { return _textAlignment; } - set { + set { if (value == _textAlignment) return; - _textAlignment = value; + _textAlignment = value; RegisterForRedraw (); NotifyValueChanged ("TextAlignment", _textAlignment); } @@ -112,7 +112,7 @@ namespace Crow set { if (horizontalStretch == value) return; - horizontalStretch = value; + horizontalStretch = value; RegisterForRedraw (); NotifyValueChanged ("HorizontalStretch", horizontalStretch); } @@ -123,23 +123,23 @@ namespace Crow set { if (verticalStretch == value) return; - verticalStretch = value; + verticalStretch = value; RegisterForRedraw (); NotifyValueChanged ("VerticalStretch", verticalStretch); } - } + } [XmlAttributeAttribute][DefaultValue("label")] public string Text { - get { - return lines == null ? + get { + return lines == null ? _text : lines.Aggregate((i, j) => i + Interface.LineBreak + j); } set { if (string.Equals (value, _text, StringComparison.Ordinal)) return; - + _text = value; if (string.IsNullOrEmpty(_text)) @@ -182,7 +182,7 @@ namespace Crow [XmlAttributeAttribute][DefaultValue(0)] public int CurrentColumn{ get { return _currentCol; } - set { + set { if (value == _currentCol) return; if (value < 0) @@ -197,11 +197,11 @@ namespace Crow [XmlAttributeAttribute][DefaultValue(0)] public int CurrentLine{ get { return _currentLine; } - set { + set { if (value == _currentLine) return; if (value >= lines.Count) - _currentLine = lines.Count-1; + _currentLine = lines.Count-1; else if (value < 0) _currentLine = 0; else @@ -232,7 +232,7 @@ namespace Crow NotifyValueChanged ("SelBegin", _selBegin); NotifyValueChanged ("SelectedText", SelectedText); } - } + } [XmlAttributeAttribute][DefaultValue("-1")] public Point SelRelease { get { @@ -260,24 +260,24 @@ namespace Crow /// </summary> [XmlIgnore]protected Point selectionStart { - get { - return SelRelease < 0 || SelBegin.Y < SelRelease.Y ? SelBegin : + get { + return SelRelease < 0 || SelBegin.Y < SelRelease.Y ? SelBegin : SelBegin.Y > SelRelease.Y ? SelRelease : SelBegin.X < SelRelease.X ? SelBegin : SelRelease; } } [XmlIgnore]public Point selectionEnd - { - get { - return SelRelease < 0 || SelBegin.Y > SelRelease.Y ? SelBegin : + { + get { + return SelRelease < 0 || SelBegin.Y > SelRelease.Y ? SelBegin : SelBegin.Y < SelRelease.Y ? SelRelease : SelBegin.X > SelRelease.X ? SelBegin : SelRelease; - } + } } [XmlIgnore]public string SelectedText - { + { get { - + if (SelRelease < 0 || SelBegin < 0) return ""; if (selectionStart.Y == selectionEnd.Y) @@ -289,14 +289,14 @@ namespace Crow } tmp += Interface.LineBreak + lines [selectionEnd.Y].Substring (0, selectionEnd.X); return tmp; - } + } } [XmlIgnore]public bool selectionIsEmpty { get { return SelRelease < 0; } } List<string> lines; List<string> getLines { - get { + get { return _multiline ? Regex.Split (_text, "\r\n|\r|\n|\\\\n").ToList() : new List<string>(new string[] { _text }); @@ -355,7 +355,7 @@ namespace Crow } public void DeleteChar() { - if (selectionIsEmpty) { + if (selectionIsEmpty) { if (CurrentColumn == 0) { if (CurrentLine == 0 && lines.Count == 1) return; @@ -368,7 +368,7 @@ namespace Crow } CurrentColumn--; lines [CurrentLine] = lines [CurrentLine].Remove (CurrentColumn, 1); - } else { + } else { int linesToRemove = selectionEnd.Y - selectionStart.Y + 1; int l = selectionStart.Y; @@ -380,7 +380,7 @@ namespace Crow lines.RemoveAt (l); CurrentLine = selectionStart.Y; CurrentColumn = selectionStart.X; - } else + } else lines [l] = lines [l].Remove (selectionStart.X, selectionEnd.X - selectionStart.X); CurrentColumn = selectionStart.X; SelBegin = -1; @@ -425,10 +425,10 @@ namespace Crow #region GraphicObject overrides protected override int measureRawSize(LayoutingType lt) - { + { if (lines == null) lines = getLines; - + using (ImageSurface img = new ImageSurface (Format.Argb32, 10, 10)) { using (Context gr = new Context (img)) { //Cairo.FontFace cf = gr.GetContextFontFace (); @@ -444,8 +444,8 @@ namespace Crow int lc = lines.Count; //ensure minimal height = text line height if (lc == 0) - lc = 1; - + lc = 1; + return (int)Math.Ceiling(fe.Height * lc) + Margin * 2; } @@ -494,7 +494,7 @@ namespace Crow if (!horizontalStretch) widthRatio = heightRatio; } - + rText.Width = (int)(widthRatio * (float)rText.Width); rText.Height = (int)(heightRatio * (float)rText.Height); @@ -504,7 +504,7 @@ namespace Crow rText.X = cb.X; rText.Y = cb.Y; break; - case Alignment.Top: //ok + case Alignment.Top: //ok rText.Y = cb.Y; rText.X = cb.X + cb.Width / 2 - rText.Width / 2; break; @@ -560,7 +560,7 @@ namespace Crow SelRelease = -1; else SelEndCursorPos = textCursorPos; - } + } } }else computeTextCursorPosition(gr); @@ -578,8 +578,8 @@ namespace Crow // gr.Color = Color.Green; // Rectangle R = new Rectangle ( // rText.X + (int)SelEndCursorPos - 2, -// rText.Y + (int)(SelRelease.Y * fe.Height), -// 4, +// rText.Y + (int)(SelRelease.Y * fe.Height), +// 4, // (int)fe.Height); // gr.Rectangle (R); // gr.Fill (); @@ -588,20 +588,20 @@ namespace Crow // gr.Color = Color.UnmellowYellow; // Rectangle R = new Rectangle ( // rText.X + (int)SelStartCursorPos - 2, -// rText.Y + (int)(SelBegin.Y * fe.Height), -// 4, +// rText.Y + (int)(SelBegin.Y * fe.Height), +// 4, // (int)fe.Height); // gr.Rectangle (R); // gr.Fill (); // } //******************* - for (int i = 0; i < lines.Count; i++) { + for (int i = 0; i < lines.Count; i++) { string l = lines [i].Replace ("\t", new String (' ', Interface.TabSize)); int lineLength = (int)gr.TextExtents (l).XAdvance; Rectangle lineRect = new Rectangle ( rText.X, - rText.Y + (int)Math.Ceiling(i * fe.Height), + rText.Y + (int)Math.Ceiling(i * fe.Height), lineLength, (int)Math.Ceiling(fe.Height)); @@ -613,35 +613,36 @@ namespace Crow // TextAlignment == Alignment.TopRight || // TextAlignment == Alignment.BottomRight) // lineRect.X += (rText.Width - lineLength); - - if (SelRelease >= 0 && i >= selectionStart.Y && i <= selectionEnd.Y) { - gr.SetSourceColor(selBackground); + if (Selectable) { + if (SelRelease >= 0 && i >= selectionStart.Y && i <= selectionEnd.Y) { + gr.SetSourceColor (selBackground); - Rectangle selRect = lineRect ; + Rectangle selRect = lineRect; - int cpStart = (int)SelStartCursorPos, + int cpStart = (int)SelStartCursorPos, cpEnd = (int)SelEndCursorPos; - if (SelBegin.Y > SelRelease.Y) { - cpStart = cpEnd; - cpEnd = (int)SelStartCursorPos; - } + if (SelBegin.Y > SelRelease.Y) { + cpStart = cpEnd; + cpEnd = (int)SelStartCursorPos; + } - if (i == selectionStart.Y) { - selRect.Width -= cpStart; - selRect.Left += cpStart; - } - if (i == selectionEnd.Y) - selRect.Width -= (lineLength - cpEnd); + if (i == selectionStart.Y) { + selRect.Width -= cpStart; + selRect.Left += cpStart; + } + if (i == selectionEnd.Y) + selRect.Width -= (lineLength - cpEnd); - gr.Rectangle (selRect); - gr.Fill (); - } + gr.Rectangle (selRect); + gr.Fill (); + } + } if (string.IsNullOrWhiteSpace (l)) continue; - Foreground.SetAsSource (gr); + Foreground.SetAsSource (gr); gr.MoveTo (lineRect.X, rText.Y + fe.Ascent + fe.Height * i); gr.ShowText (l); gr.Fill (); @@ -698,14 +699,14 @@ namespace Crow RegisterForRedraw(); } public override void onMouseDown (object sender, MouseButtonEventArgs e) - { + { if (this.HasFocus && _selectable){ updatemouseLocalPos (e.Position); SelBegin = -1; SelRelease = -1; SelectionInProgress = true; RegisterForRedraw();//TODO:should put it in properties - } + } //done at the end to set 'hasFocus' value after testing it base.onMouseDown (sender, e); @@ -716,7 +717,7 @@ namespace Crow if (!SelectionInProgress) return; - + updatemouseLocalPos (e.Position); SelectionInProgress = false; RegisterForRedraw (); @@ -739,7 +740,7 @@ namespace Crow /// from mouseLocalPos /// </summary> void computeTextCursor(Context gr) - { + { TextExtents te; double cPos = 0f; @@ -755,7 +756,7 @@ namespace Crow string c = lines [CurrentLine].Substring (i, 1); if (c == "\t") c = new string (' ', Interface.TabSize); - + te = gr.TextExtents(c); double halfWidth = te.XAdvance / 2; @@ -778,7 +779,7 @@ namespace Crow } /// <summary> Computes offsets in cairo units </summary> void computeTextCursorPosition(Context gr) - { + { if (SelBegin >= 0) SelStartCursorPos = GetXFromTextPointer (gr, SelBegin); if (SelRelease >= 0) diff --git a/src/GraphicObjects/SaturationValueSelector.cs b/src/GraphicObjects/SaturationValueSelector.cs index b71fa7ef..a1ddc5b4 100644 --- a/src/GraphicObjects/SaturationValueSelector.cs +++ b/src/GraphicObjects/SaturationValueSelector.cs @@ -42,7 +42,7 @@ namespace Crow NotifyValueChanged ("V", v); mousePos.Y = (int)Math.Floor((1.0-v) * (double)ClientRectangle.Height); - CurrentInterface.EnqueueForRepaint (this); + RegisterForRedraw (); } } [XmlAttributeAttribute()] @@ -54,7 +54,8 @@ namespace Crow s = value; NotifyValueChanged ("S", s); mousePos.X = (int)Math.Floor(s * (double)ClientRectangle.Width); - CurrentInterface.EnqueueForRepaint (this); + + RegisterForRedraw (); } } protected override void onDraw (Cairo.Context gr) @@ -62,8 +63,6 @@ namespace Crow base.onDraw (gr); Rectangle r = ClientRectangle; - Rectangle rGrad = r; - rGrad.Inflate (-1); if (Foreground != null) {//TODO:test if null should be removed Foreground.SetAsSource (gr, r); @@ -74,13 +73,13 @@ namespace Crow Crow.Gradient grad = new Gradient (Gradient.Type.Horizontal); grad.Stops.Add (new Gradient.ColorStop (0, new Color (1, 1, 1, 1))); grad.Stops.Add (new Gradient.ColorStop (1, new Color (1, 1, 1, 0))); - grad.SetAsSource (gr, rGrad); + grad.SetAsSource (gr, r); CairoHelpers.CairoRectangle (gr, r, CornerRadius); gr.Fill(); grad = new Gradient (Gradient.Type.Vertical); grad.Stops.Add (new Gradient.ColorStop (0, new Color (0, 0, 0, 0))); grad.Stops.Add (new Gradient.ColorStop (1, new Color (0, 0, 0, 1))); - grad.SetAsSource (gr, rGrad); + grad.SetAsSource (gr, r); CairoHelpers.CairoRectangle (gr, r, CornerRadius); gr.Fill(); } @@ -95,7 +94,7 @@ namespace Crow ctx.Translate (rb.X, rb.Y); ctx.SetSourceColor (Color.White); - ctx.Arc (mousePos.X, mousePos.Y, 3.0, 0, Math.PI * 2.0); + ctx.Arc (mousePos.X, mousePos.Y, 3.5, 0, Math.PI * 2.0); ctx.LineWidth = 1.0; ctx.Stroke (); @@ -111,6 +110,8 @@ namespace Crow v = 1.0 - (double)mousePos.Y / (double)cb.Height; NotifyValueChanged ("S", s); NotifyValueChanged ("V", v); + + RegisterForRedraw (); } public override void OnLayoutChanges (LayoutingType layoutType) { diff --git a/src/IML/BindingMember.cs b/src/IML/BindingMember.cs new file mode 100644 index 00000000..f643d10b --- /dev/null +++ b/src/IML/BindingMember.cs @@ -0,0 +1,160 @@ +// +// BindingMember.cs +// +// Author: +// Jean-Philippe Bruyère <jp.bruyere@hotmail.com> +// +// Copyright (c) 2017 jp +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see <http://www.gnu.org/licenses/>. +using System; +using System.Reflection.Emit; + +namespace Crow +{ + /// <summary> + /// Expression token, a variable, a string constant or a parsable constant (having a static Parse method) + /// '../' => 1 level up in graphic tree + /// './' or '/' => template root level + /// '.Name1.Name2' current level properties + /// 'name.prop' named descendant in graphic tree, search with 'FindByName' method of GraphicObject + /// </summary> + public class BindingMember + { + /// <summary> + /// true if expression was enclosed in ' + /// </summary> + public bool IsStringConstant = false; + /// <summary> + /// Nb level to go up, '-1' for template root + /// </summary> + public int LevelsUp; + /// <summary> + /// Remaining string after '/' split, splitted on '.' + /// </summary> + public string[] Tokens; + + /// <summary> + /// Target the template's root node, expression was in the form './name[.name[...]]' or '/name[.name[...]]' + /// </summary> + public bool IsTemplateBinding { get { return LevelsUp < 0; }} + + /// <summary> + /// No level change and expression was '.name' + /// </summary> + /// <value><c>true</c> if this instance is current node property; otherwise, <c>false</c>.</value> + public bool IsCurrentNodeProperty { + get { + return LevelsUp == 0 && ( Tokens.Length == 2 && string.IsNullOrEmpty(Tokens[0])); + } + } + /// <summary> + /// no level change, and only a single name in Tokens[], that's dataSource member if property binding + /// </summary> + public bool IsSingleName { get { return LevelsUp == 0 && Tokens.Length == 1; }} + + #region CTOR + public BindingMember (){} + public BindingMember (string expression){ + if (string.IsNullOrEmpty (expression)) + return; + + string[] splitedExp = expression.Trim().Split ('/'); + + int ptr = 0; + if (splitedExp.Length == 1) { + if (splitedExp [0].StartsWith ("\'")) { + if (!splitedExp [0].EndsWith ("\'")) + throw new Exception (string.Format + ("IML:malformed string constant in binding expression: {0}", splitedExp [0])); + Tokens = new string[] { splitedExp [0].Substring (1, splitedExp [0].Length - 2) }; + IsStringConstant = true; + return; + } + } else { + if (string.IsNullOrEmpty (splitedExp [0]) || splitedExp [0] == ".") {//template root + LevelsUp = -1; + ptr++; + } else { + while (splitedExp [ptr] == "..") + ptr++; + LevelsUp = ptr; + } + } + if (ptr != splitedExp.Length - 1) + throw new Exception ("invalid expresion: " + expression); + Tokens = splitedExp [ptr].Split ('.'); + } + #endregion + + public void emitGetTarget(ILGenerator il, System.Reflection.Emit.Label cancel){ + + if (IsTemplateBinding) { + System.Reflection.Emit.Label nextLogicParent = il.DefineLabel (); + il.MarkLabel (nextLogicParent); + il.Emit (OpCodes.Callvirt, CompilerServices.miGetLogicalParent); + il.Emit (OpCodes.Dup); + il.Emit (OpCodes.Brfalse, cancel); + il.Emit (OpCodes.Isinst, typeof(TemplatedControl)); + il.Emit (OpCodes.Dup); + il.Emit (OpCodes.Brfalse, nextLogicParent); + } else if (LevelsUp > 0) {//go upward in logical tree + il.Emit (OpCodes.Ldc_I4, LevelsUp);//push arg 2 of goUpLevels + il.Emit (OpCodes.Callvirt, CompilerServices.miGoUpLevels); + //test if null + il.Emit (OpCodes.Dup); + il.Emit (OpCodes.Brfalse, cancel); + } + + if (!string.IsNullOrEmpty (Tokens [0])) {//find by name + il.Emit (OpCodes.Ldstr, Tokens [0]); + il.Emit (OpCodes.Callvirt, CompilerServices.miFindByName); + il.Emit (OpCodes.Dup); + il.Emit (OpCodes.Brfalse, cancel); + } + + for (int i = 1; i < Tokens.Length -1; i++) { + System.Reflection.Emit.Label miOK = il.DefineLabel (); + il.Emit (OpCodes.Dup);//duplicate instance + il.Emit (OpCodes.Ldstr, Tokens [i]);//load member name + il.Emit (OpCodes.Call, CompilerServices.miGetMembIinfoWithRefx); + il.Emit (OpCodes.Dup); + il.Emit (OpCodes.Brtrue, miOK); + il.Emit (OpCodes.Pop);//pop dup instance + il.Emit (OpCodes.Br, cancel); + il.MarkLabel (miOK); + il.Emit (OpCodes.Call, CompilerServices.miGetValWithRefx); + il.Emit (OpCodes.Dup); + il.Emit (OpCodes.Brfalse, cancel); + } + } + public void emitGetProperty(ILGenerator il, System.Reflection.Emit.Label cancel) { + System.Reflection.Emit.Label miOK = il.DefineLabel (); + il.Emit (OpCodes.Dup);//duplicate instance + il.Emit (OpCodes.Ldstr, Tokens [Tokens.Length -1]);//load member name + il.Emit (OpCodes.Call, CompilerServices.miGetMembIinfoWithRefx); + il.Emit (OpCodes.Dup); + il.Emit (OpCodes.Brtrue, miOK); + il.Emit (OpCodes.Pop);//pop dup instance + il.Emit (OpCodes.Br, cancel); + il.MarkLabel (miOK); + il.Emit (OpCodes.Call, CompilerServices.miGetValWithRefx); + } + public void emitSetProperty(ILGenerator il) { + il.Emit (OpCodes.Ldstr, Tokens [Tokens.Length -1]);//load member name + il.Emit (OpCodes.Call, CompilerServices.miSetValWithRefx); + } + } +} + diff --git a/src/IML/Node.cs b/src/IML/Node.cs index 4ba61c03..29f204f5 100644 --- a/src/IML/Node.cs +++ b/src/IML/Node.cs @@ -30,16 +30,18 @@ namespace Crow.IML /// </summary> public struct Node { - /// <summary> Current node type</summary> - public Type CrowType; - /// <summary> Index in parent, -1 for template</summary> - public int Index; - + #region CTOR public Node (Type crowType, int _index = 0) { CrowType = crowType; Index = _index; } + #endregion + + /// <summary> Current node type</summary> + public Type CrowType; + /// <summary> Index in parent, -1 for template</summary> + public int Index; public MethodInfo GetAddMethod(int childIdx){ if (typeof (Group).IsAssignableFrom (CrowType)) diff --git a/src/IML/NodeAddress.cs b/src/IML/NodeAddress.cs index 460998da..c81a7f66 100644 --- a/src/IML/NodeAddress.cs +++ b/src/IML/NodeAddress.cs @@ -26,13 +26,83 @@ using System.Reflection.Emit; namespace Crow.IML { + /// <summary> + /// Node address is a list of nodes from root to leaf defining a unique node + /// </summary> public class NodeAddress : List<Node> { - public NodeAddress (Node[] nodes) : base(nodes) { - } + #region CTOR + public NodeAddress (Node[] nodes) : base(nodes) {} + #endregion public Type NodeType { get { return Count == 0 ? null : this[this.Count -1].CrowType; }} + /// <summary> + /// Gets the node adress from binding expression starting from this node + /// and return in expression remaining part + /// </summary> + public NodeAddress ResolveExpression (ref string expression){ + int ptr = this.Count - 1; + string[] splitedExp = expression.Split ('/'); + + if (splitedExp.Length < 2)//dataSource binding + return null; + + if (string.IsNullOrEmpty (splitedExp [0]) || splitedExp [0] == ".") {//search template root + ptr--; + while (ptr >= 0) { + if (typeof(TemplatedControl).IsAssignableFrom (this [ptr].CrowType)) + break; + ptr--; + } + } else if (splitedExp [0] == "..") { //search starting at current node + int levelUp = splitedExp.Length - 1; + if (levelUp > ptr + 1) + throw new Exception ("Binding error: try to bind outside IML source"); + ptr -= levelUp; + } + expression = splitedExp [splitedExp.Length - 1]; + //TODO:change Template special address identified with Nodecount = 0 to something not using array count to 0, + //here linq is working without limits checking in compile option + //but defining a 0 capacity array with limits cheking enabled, cause 'out of memory' error + return new NodeAddress (this.Take(ptr+1).ToArray());//[ptr+1]; + //Array.Copy (sourceAddr.ToArray (), targetNode, ptr + 1); + //return new NodeAddress (targetNode); + } + /// <summary> + /// get BindingDefinition from binding expression + /// </summary> + public BindingDefinition GetBindingDef(string sourceMember, string expression){ + BindingDefinition bindingDef = new BindingDefinition(this, sourceMember); + if (string.IsNullOrEmpty (expression)) { + return bindingDef; + } else { + if (expression.StartsWith ("²")) { + bindingDef.TwoWay = true; + expression = expression.Substring (1); + } + + string exp = expression; + bindingDef.TargetNA = this.ResolveExpression (ref exp); + + string [] bindTrg = exp.Split ('.'); + + if (bindTrg.Length == 0) + throw new Exception ("invalid binding expression: " + expression); + if (bindTrg.Length == 1) + bindingDef.TargetMember = bindTrg [0]; + else { + if (!string.IsNullOrEmpty(bindTrg[0]))//searchByName + bindingDef.TargetName = bindTrg[0]; + + bindingDef.TargetMember = exp.Substring (bindTrg[0].Length + 1); + } + } + + return bindingDef; + } + + #region Object overrides public override bool Equals (object obj) { if (obj == null) @@ -50,7 +120,6 @@ namespace Crow.IML return hash; } } - public override string ToString () { string tmp = ""; @@ -58,6 +127,7 @@ namespace Crow.IML tmp += string.Format ("{0};", n.Index); return tmp; } + #endregion } public class NamedNodeAddress : NodeAddress { diff --git a/src/Instantiator.cs b/src/Instantiator.cs index 6aaa7483..6e94ae17 100644 --- a/src/Instantiator.cs +++ b/src/Instantiator.cs @@ -87,7 +87,7 @@ namespace Crow } #endregion - public GraphicObject CreateInstance(Interface iface){ + public GraphicObject CreateInstance(Interface iface){ return loader (iface) as GraphicObject; } @@ -356,7 +356,7 @@ namespace Crow void readPropertyBinding (Context ctx, string sourceMember, string expression) { NodeAddress sourceNA = ctx.CurrentNodeAddress; - BindingDefinition bindingDef = splitBindingExp (sourceNA, sourceMember, expression); + BindingDefinition bindingDef = sourceNA.GetBindingDef (sourceMember, expression); #if DEBUG_BINDING Debug.WriteLine("Property Binding: " + bindingDef.ToString()); @@ -368,44 +368,6 @@ namespace Crow ctx.StorePropertyBinding (bindingDef); } - /// <summary> - /// Splits the binding expression - /// </summary> - /// <returns><c>true</c>, if it's a two way binding, <c>false</c> otherwise.</returns> - /// <param name="sourceNA">Source Node address</param> - /// <param name="expression">Expression.</param> - /// <param name="targetNA">Target Node Address</param> - /// <param name="targetMember">Target member name</param> - /// <param name="targetName">Target node name</param> - BindingDefinition splitBindingExp(NodeAddress sourceNA, string sourceMember, string expression){ - BindingDefinition bindingDef = new BindingDefinition(sourceNA, sourceMember); - if (string.IsNullOrEmpty (expression)) { - return bindingDef; - } else { - if (expression.StartsWith ("²")) { - bindingDef.TwoWay = true; - expression = expression.Substring (1); - } - string[] bindingExp = expression.Split ('/'); - - if (bindingExp.Length > 1) - bindingDef.TargetNA = CompilerServices.getNodeAdressFromBindingExp (sourceNA, bindingExp); - - string [] bindTrg = bindingExp.Last().Split ('.'); - - if (bindTrg.Length == 1) - bindingDef.TargetMember = bindTrg [0]; - else if (bindTrg.Length == 2) { - //named target - bindingDef.TargetName = bindTrg[0]; - bindingDef.TargetMember = bindTrg [1]; - } else - throw new Exception ("Syntax error in binding, expected 'go dot member'"); - } - - return bindingDef; - } - #region Emit Helper void dataSourceChangedEmitHelper(object dscSource, object dataSource, int dynMethIdx){ if (dataSource is IValueChange) @@ -429,7 +391,7 @@ namespace Crow /// <summary> Emits handler method bindings </summary> void emitHandlerBinding (Context ctx, EventInfo sourceEvent, string expression){ NodeAddress currentNode = ctx.CurrentNodeAddress; - BindingDefinition bindingDef = splitBindingExp (currentNode, sourceEvent.Name, expression); + BindingDefinition bindingDef = currentNode.GetBindingDef (sourceEvent.Name, expression); #if DEBUG_BINDING Debug.WriteLine("Event Binding: " + bindingDef.ToString()); @@ -437,7 +399,7 @@ namespace Crow if (bindingDef.IsTemplateBinding | bindingDef.IsDataSourceBinding) { //we need to bind datasource method to source event - DynamicMethod dm = new DynamicMethod ("dyn_dschangedForHandler" + NewId, + DynamicMethod dm = new DynamicMethod ("dyn_dsORtmpChangedForHandler" + NewId, typeof(void), CompilerServices.argsBoundDSChange, true); @@ -822,7 +784,7 @@ namespace Crow //the actual value of the origin member of the datasource and then will bind the value changed //dyn methode. //dm is bound to the instanciator instance to have access to cached dyn meth and delegates - dm = new DynamicMethod ("dyn_dschanged", + dm = new DynamicMethod ("dyn_dschanged" + NewId, typeof (void), CompilerServices.argsBoundDSChange, true); @@ -846,10 +808,10 @@ namespace Crow il.Emit (OpCodes.Brfalse, cancelRemove);//old parent is null //remove handler + il.Emit (OpCodes.Ldarg_1);//3d arg: instance bound to delegate (the source) + il.Emit (OpCodes.Ldstr, "ValueChanged");//2nd arg event name il.Emit (OpCodes.Ldarg_2);//1st arg load old datasource il.Emit (OpCodes.Ldfld, CompilerServices.fiDSCOldDS); - il.Emit (OpCodes.Ldstr, "ValueChanged");//2nd arg event name - il.Emit (OpCodes.Ldarg_1);//3d arg: instance bound to delegate (the source) il.Emit (OpCodes.Call, CompilerServices.miRemEvtHdlByTarget); il.MarkLabel(cancelRemove); } @@ -929,6 +891,11 @@ namespace Crow PropertyInfo piOrig = tOrig.GetProperty (origMember); PropertyInfo piDest = tDest.GetProperty (destMember); + if (piDest == null) { + Debug.WriteLine ("Member '{0}' not found in new DataSource '{1}' of '{2}'", destMember, dest, orig); + return; + } + #region ValueChanged emit DynamicMethod dm = new DynamicMethod ("dyn_valueChanged" + NewId, typeof (void), CompilerServices.argsBoundValueChange, true); diff --git a/src/SolidColor.cs b/src/SolidColor.cs index d214f592..bbb27067 100644 --- a/src/SolidColor.cs +++ b/src/SolidColor.cs @@ -43,11 +43,13 @@ namespace Crow } public static bool operator ==(SolidColor left, SolidColor right) { - return left.color == right.color ? true : false; + return left is SolidColor ? right is SolidColor ? true : false : + left.color == right.color ? true : false; } public static bool operator !=(SolidColor left, SolidColor right) { - return left.color == right.color ? false : true; + return left is SolidColor ? right is SolidColor ? false : true : + left.color == right.color ? false : true; } public override int GetHashCode () diff --git a/src/rsvg/DimensionData.cs b/src/rsvg/DimensionData.cs index 20da1aab..83e5c6ef 100644 --- a/src/rsvg/DimensionData.cs +++ b/src/rsvg/DimensionData.cs @@ -1,13 +1,9 @@ -// This file was generated by the Gtk# code generator. -// Any changes made will be lost if regenerated. - namespace Rsvg { using System; using System.Collections; using System.Runtime.InteropServices; -#region Autogenerated code [StructLayout(LayoutKind.Sequential)] public struct DimensionData { @@ -23,10 +19,5 @@ namespace Rsvg { return Rsvg.DimensionData.Zero; return (Rsvg.DimensionData) Marshal.PtrToStructure (raw, typeof (Rsvg.DimensionData)); } - - private static GLib.GType GType { - get { return GLib.GType.Pointer; } - } -#endregion } } diff --git a/src/rsvg/Handle.cs b/src/rsvg/Handle.cs index 51eec1fb..97196269 100644 --- a/src/rsvg/Handle.cs +++ b/src/rsvg/Handle.cs @@ -1,131 +1,62 @@ -// This file was generated by the Gtk# code generator. -// Any changes made will be lost if regenerated. - namespace Rsvg { using System; using System.Collections; using System.Runtime.InteropServices; -#region Autogenerated code - public class Handle : GLib.Object { + public class Handle { - public Handle(IntPtr raw) : base(raw) {} + public IntPtr Raw; [DllImport("rsvg-2")] static extern IntPtr rsvg_handle_new(); - public Handle () : base (IntPtr.Zero) + public Handle () { - if (GetType () != typeof (Handle)) { - CreateNativeObject (new string [0], new GLib.Value[0]); - return; - } Raw = rsvg_handle_new(); } [DllImport("rsvg-2")] static extern unsafe IntPtr rsvg_handle_new_from_data(byte[] data, UIntPtr n_data, out IntPtr error); - public unsafe Handle (byte[] data) : base (IntPtr.Zero) + public unsafe Handle (byte[] data) { if (GetType () != typeof (Handle)) { throw new InvalidOperationException ("Can't override this constructor."); } IntPtr error = IntPtr.Zero; Raw = rsvg_handle_new_from_data(data, new UIntPtr ((ulong) (data == null ? 0 : data.Length)), out error); - if (error != IntPtr.Zero) throw new GLib.GException (error); + if (error != IntPtr.Zero) throw new Exception (error.ToString()); } [DllImport("rsvg-2")] - static extern unsafe IntPtr rsvg_handle_new_from_file(IntPtr file_name, out IntPtr error); + static extern unsafe IntPtr rsvg_handle_new_from_file(string file_name, out IntPtr error); - public unsafe Handle (string file_name) : base (IntPtr.Zero) + public unsafe Handle (string file_name) { - if (GetType () != typeof (Handle)) { - throw new InvalidOperationException ("Can't override this constructor."); - } - IntPtr native_file_name = GLib.Marshaller.StringToPtrGStrdup (file_name); IntPtr error = IntPtr.Zero; - Raw = rsvg_handle_new_from_file(native_file_name, out error); - GLib.Marshaller.Free (native_file_name); - if (error != IntPtr.Zero) throw new GLib.GException (error); - } - - [DllImport("rsvg-2")] - static extern IntPtr rsvg_handle_get_pixbuf(IntPtr raw); - - public Gdk.Pixbuf Pixbuf { - get { - IntPtr raw_ret = rsvg_handle_get_pixbuf(Handle); - Gdk.Pixbuf ret = GLib.Object.GetObject(raw_ret) as Gdk.Pixbuf; - return ret; - } + Raw = rsvg_handle_new_from_file(file_name, out error); + if (error != IntPtr.Zero) throw new Exception (error.ToString()); } [DllImport("rsvg-2")] static extern IntPtr rsvg_handle_get_base_uri(IntPtr raw); [DllImport("rsvg-2")] - static extern void rsvg_handle_set_base_uri(IntPtr raw, IntPtr base_uri); - - public string BaseUri { - get { - IntPtr raw_ret = rsvg_handle_get_base_uri(Handle); - string ret = GLib.Marshaller.Utf8PtrToString (raw_ret); - return ret; - } - set { - IntPtr native_value = GLib.Marshaller.StringToPtrGStrdup (value); - rsvg_handle_set_base_uri(Handle, native_value); - GLib.Marshaller.Free (native_value); - } - } - - [DllImport("rsvg-2")] static extern void rsvg_handle_set_dpi(IntPtr raw, double dpi); public double Dpi { set { - rsvg_handle_set_dpi(Handle, value); + rsvg_handle_set_dpi(Raw, value); } } [DllImport("rsvg-2")] - static extern unsafe bool rsvg_handle_write(IntPtr raw, byte[] buf, UIntPtr n_buf, out IntPtr error); - - public unsafe bool Write(byte[] buf) { - IntPtr error = IntPtr.Zero; - bool raw_ret = rsvg_handle_write(Handle, buf, new UIntPtr ((ulong) (buf == null ? 0 : buf.Length)), out error); - bool ret = raw_ret; - if (error != IntPtr.Zero) throw new GLib.GException (error); - return ret; - } - - [DllImport("rsvg-2")] static extern void rsvg_handle_render_cairo(IntPtr raw, IntPtr cr); public void RenderCairo(Cairo.Context cr) { - rsvg_handle_render_cairo(Handle, cr == null ? IntPtr.Zero : cr.Handle); - } - - [DllImport("rsvg-2")] - static extern void rsvg_handle_set_size_callback(IntPtr raw, RsvgSharp.SizeFuncNative size_func, IntPtr user_data, GLib.DestroyNotify user_data_destroy); - - [Obsolete] - public Rsvg.SizeFunc SizeCallback { - set { - RsvgSharp.SizeFuncWrapper value_wrapper = new RsvgSharp.SizeFuncWrapper (value); - IntPtr user_data; - GLib.DestroyNotify user_data_destroy; - if (value == null) { - user_data = IntPtr.Zero; - user_data_destroy = null; - } else { - user_data = (IntPtr) GCHandle.Alloc (value_wrapper); - user_data_destroy = GLib.DestroyHelper.NotifyHandler; - } - rsvg_handle_set_size_callback(Handle, value_wrapper.NativeDelegate, user_data, user_data_destroy); + unsafe{ + rsvg_handle_render_cairo (Raw, cr == null ? IntPtr.Zero : cr.Handle); } } @@ -133,7 +64,7 @@ namespace Rsvg { static extern void rsvg_handle_set_dpi_x_y(IntPtr raw, double dpi_x, double dpi_y); public void SetDpiXY(double dpi_x, double dpi_y) { - rsvg_handle_set_dpi_x_y(Handle, dpi_x, dpi_y); + rsvg_handle_set_dpi_x_y(Raw, dpi_x, dpi_y); } [DllImport("rsvg-2")] @@ -143,7 +74,7 @@ namespace Rsvg { get { Rsvg.DimensionData dimension_data; IntPtr native_dimension_data = Marshal.AllocHGlobal (Marshal.SizeOf (typeof (Rsvg.DimensionData))); - rsvg_handle_get_dimensions(Handle, native_dimension_data); + rsvg_handle_get_dimensions(Raw, native_dimension_data); dimension_data = Rsvg.DimensionData.New (native_dimension_data); Marshal.FreeHGlobal (native_dimension_data); return dimension_data; @@ -155,43 +86,9 @@ namespace Rsvg { public unsafe bool Close() { IntPtr error = IntPtr.Zero; - bool raw_ret = rsvg_handle_close(Handle, out error); - bool ret = raw_ret; - if (error != IntPtr.Zero) throw new GLib.GException (error); - return ret; - } - - [DllImport("rsvg-2")] - static extern IntPtr rsvg_handle_get_pixbuf_sub(IntPtr raw, IntPtr id); - - public Gdk.Pixbuf GetPixbufSub(string id) { - IntPtr native_id = GLib.Marshaller.StringToPtrGStrdup (id); - IntPtr raw_ret = rsvg_handle_get_pixbuf_sub(Handle, native_id); - Gdk.Pixbuf ret = GLib.Object.GetObject(raw_ret) as Gdk.Pixbuf; - GLib.Marshaller.Free (native_id); - return ret; - } - - [DllImport("rsvg-2")] - static extern IntPtr rsvg_handle_get_desc(IntPtr raw); - - public string Desc { - get { - IntPtr raw_ret = rsvg_handle_get_desc(Handle); - string ret = GLib.Marshaller.Utf8PtrToString (raw_ret); - return ret; - } - } - - [DllImport("rsvg-2")] - static extern IntPtr rsvg_handle_get_type(); - - public static new GLib.GType GType { - get { - IntPtr raw_ret = rsvg_handle_get_type(); - GLib.GType ret = new GLib.GType(raw_ret); - return ret; - } + bool raw_ret = rsvg_handle_close(Raw, out error); + if (error != IntPtr.Zero) throw new Exception (error.ToString()); + return raw_ret; } [DllImport("rsvg-2")] @@ -199,19 +96,16 @@ namespace Rsvg { public string Title { get { - IntPtr raw_ret = rsvg_handle_get_title(Handle); - string ret = GLib.Marshaller.Utf8PtrToString (raw_ret); - return ret; + IntPtr raw_ret = rsvg_handle_get_title(Raw); + return "not supported"; } } [DllImport("rsvg-2")] - static extern void rsvg_handle_render_cairo_sub(IntPtr raw, IntPtr cr, IntPtr id); + static extern void rsvg_handle_render_cairo_sub(IntPtr raw, IntPtr cr, string id); public void RenderCairoSub(Cairo.Context cr, string id) { - IntPtr native_id = GLib.Marshaller.StringToPtrGStrdup (id); - rsvg_handle_render_cairo_sub(Handle, cr == null ? IntPtr.Zero : cr.Handle, native_id); - GLib.Marshaller.Free (native_id); + rsvg_handle_render_cairo_sub(Raw, cr == null ? IntPtr.Zero : cr.Handle, id); } [DllImport("rsvg-2")] @@ -219,44 +113,9 @@ namespace Rsvg { public string Metadata { get { - IntPtr raw_ret = rsvg_handle_get_metadata(Handle); - string ret = GLib.Marshaller.Utf8PtrToString (raw_ret); - return ret; + IntPtr raw_ret = rsvg_handle_get_metadata(Raw); + return "not supported"; } } - -#endregion -#region Customized extensions -#line 1 "Handle.custom" -// Rsvg.Handle.custom - Rsvg Handle class customizations -// -// Copyright (C) 2007 Novell, Inc. -// -// This code is inserted after the automatically generated code. -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of version 2 of the Lesser GNU General -// Public License as published by the Free Software Foundation. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this program; if not, write to the -// Free Software Foundation, Inc., 59 Temple Place - Suite 330, -// Boston, MA 02111-1307, USA. - - public unsafe bool Write (byte[] buf, ulong count) - { - IntPtr error; - bool result = rsvg_handle_write (Handle, buf, new UIntPtr (count), out error); - if (error != IntPtr.Zero) throw new GLib.GException (error); - return result; - } - - -#endregion } } diff --git a/src/rsvg/Pixbuf.cs b/src/rsvg/Pixbuf.cs deleted file mode 100644 index 690d454a..00000000 --- a/src/rsvg/Pixbuf.cs +++ /dev/null @@ -1,133 +0,0 @@ -// This file was generated by the Gtk# code generator. -// Any changes made will be lost if regenerated. - -namespace Rsvg { - - using System; - using System.Runtime.InteropServices; - -#region Autogenerated code - public class Pixbuf { - - [DllImport("rsvg-2")] - static extern unsafe IntPtr rsvg_pixbuf_from_file(IntPtr file_name, out IntPtr error); - - [Obsolete] - public static unsafe Gdk.Pixbuf FromFile(string file_name) { - IntPtr native_file_name = GLib.Marshaller.StringToPtrGStrdup (file_name); - IntPtr error = IntPtr.Zero; - IntPtr raw_ret = rsvg_pixbuf_from_file(native_file_name, out error); - Gdk.Pixbuf ret = GLib.Object.GetObject(raw_ret) as Gdk.Pixbuf; - GLib.Marshaller.Free (native_file_name); - if (error != IntPtr.Zero) throw new GLib.GException (error); - return ret; - } - - [DllImport("rsvg-2")] - static extern unsafe IntPtr rsvg_pixbuf_from_file_at_size(IntPtr file_name, int width, int height, out IntPtr error); - - [Obsolete] - public static unsafe Gdk.Pixbuf FromFileAtSize(string file_name, int width, int height) { - IntPtr native_file_name = GLib.Marshaller.StringToPtrGStrdup (file_name); - IntPtr error = IntPtr.Zero; - IntPtr raw_ret = rsvg_pixbuf_from_file_at_size(native_file_name, width, height, out error); - Gdk.Pixbuf ret = GLib.Object.GetObject(raw_ret) as Gdk.Pixbuf; - GLib.Marshaller.Free (native_file_name); - if (error != IntPtr.Zero) throw new GLib.GException (error); - return ret; - } - - [DllImport("rsvg-2")] - static extern unsafe IntPtr rsvg_pixbuf_from_file_at_zoom(IntPtr file_name, double x_zoom, double y_zoom, out IntPtr error); - - [Obsolete] - public static unsafe Gdk.Pixbuf FromFileAtZoom(string file_name, double x_zoom, double y_zoom) { - IntPtr native_file_name = GLib.Marshaller.StringToPtrGStrdup (file_name); - IntPtr error = IntPtr.Zero; - IntPtr raw_ret = rsvg_pixbuf_from_file_at_zoom(native_file_name, x_zoom, y_zoom, out error); - Gdk.Pixbuf ret = GLib.Object.GetObject(raw_ret) as Gdk.Pixbuf; - GLib.Marshaller.Free (native_file_name); - if (error != IntPtr.Zero) throw new GLib.GException (error); - return ret; - } - - [DllImport("rsvg-2")] - static extern unsafe IntPtr rsvg_pixbuf_from_file_at_zoom_with_max(IntPtr file_name, double x_zoom, double y_zoom, int max_width, int max_height, out IntPtr error); - - [Obsolete] - public static unsafe Gdk.Pixbuf FromFileAtZoomWithMax(string file_name, double x_zoom, double y_zoom, int max_width, int max_height) { - IntPtr native_file_name = GLib.Marshaller.StringToPtrGStrdup (file_name); - IntPtr error = IntPtr.Zero; - IntPtr raw_ret = rsvg_pixbuf_from_file_at_zoom_with_max(native_file_name, x_zoom, y_zoom, max_width, max_height, out error); - Gdk.Pixbuf ret = GLib.Object.GetObject(raw_ret) as Gdk.Pixbuf; - GLib.Marshaller.Free (native_file_name); - if (error != IntPtr.Zero) throw new GLib.GException (error); - return ret; - } - - [DllImport("rsvg-2")] - static extern unsafe IntPtr rsvg_pixbuf_from_file_at_max_size(IntPtr file_name, int max_width, int max_height, out IntPtr error); - - [Obsolete] - public static unsafe Gdk.Pixbuf FromFileAtMaxSize(string file_name, int max_width, int max_height) { - IntPtr native_file_name = GLib.Marshaller.StringToPtrGStrdup (file_name); - IntPtr error = IntPtr.Zero; - IntPtr raw_ret = rsvg_pixbuf_from_file_at_max_size(native_file_name, max_width, max_height, out error); - Gdk.Pixbuf ret = GLib.Object.GetObject(raw_ret) as Gdk.Pixbuf; - GLib.Marshaller.Free (native_file_name); - if (error != IntPtr.Zero) throw new GLib.GException (error); - return ret; - } - -#endregion -#region Customized extensions -#line 1 "Pixbuf.custom" -// Rsvg.Pixbuf.custom - Rsvg Pixbuf class customizations -// -// Author: John Luke <jluke@cfl.rr.com> -// -// Copyright (C) 2004 Novell, Inc. -// -// This code is inserted after the automatically generated code. -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of version 2 of the Lesser GNU General -// Public License as published by the Free Software Foundation. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this program; if not, write to the -// Free Software Foundation, Inc., 59 Temple Place - Suite 330, -// Boston, MA 02111-1307, USA. - - public static Gdk.Pixbuf LoadFromResource (string resource) - { - if (resource == null) - throw new ArgumentNullException ("resource"); - - System.IO.Stream s = System.Reflection.Assembly.GetCallingAssembly ().GetManifestResourceStream (resource); - if (s == null) - throw new ArgumentException ("resource must be a valid resource name of 'assembly'."); - - return LoadFromStream (s); - } - - public static Gdk.Pixbuf LoadFromStream (System.IO.Stream input) - { - Handle loader = new Handle (); - byte [] buffer = new byte [8192]; - int n; - while ((n = input.Read (buffer, 0, 8192)) != 0) - loader.Write (buffer, (uint) n); - - loader.Close (); - return loader.Pixbuf; - } - -#endregion - } -} diff --git a/src/rsvg/RsvgSharp.SizeFuncNative.cs b/src/rsvg/RsvgSharp.SizeFuncNative.cs deleted file mode 100644 index 43bf5b4e..00000000 --- a/src/rsvg/RsvgSharp.SizeFuncNative.cs +++ /dev/null @@ -1,94 +0,0 @@ -// This file was generated by the Gtk# code generator. -// Any changes made will be lost if regenerated. - -namespace RsvgSharp { - - using System; - using System.Runtime.InteropServices; - -#region Autogenerated code - - internal delegate void SizeFuncNative(out int width, out int height, IntPtr user_data); - - internal class SizeFuncInvoker { - - SizeFuncNative native_cb; - IntPtr __data; - GLib.DestroyNotify __notify; - - ~SizeFuncInvoker () - { - if (__notify == null) - return; - __notify (__data); - } - - internal SizeFuncInvoker (SizeFuncNative native_cb) : this (native_cb, IntPtr.Zero, null) {} - - internal SizeFuncInvoker (SizeFuncNative native_cb, IntPtr data) : this (native_cb, data, null) {} - - internal SizeFuncInvoker (SizeFuncNative native_cb, IntPtr data, GLib.DestroyNotify notify) - { - this.native_cb = native_cb; - __data = data; - __notify = notify; - } - - internal Rsvg.SizeFunc Handler { - get { - return new Rsvg.SizeFunc(InvokeNative); - } - } - - void InvokeNative (out int width, out int height) - { - native_cb (out width, out height, __data); - } - } - - internal class SizeFuncWrapper { - - public void NativeCallback (out int width, out int height, IntPtr user_data) - { - try { - managed (out width, out height); - if (release_on_call) - gch.Free (); - } catch (Exception e) { - GLib.ExceptionManager.RaiseUnhandledException (e, true); - // NOTREACHED: Above call does not return. - throw e; - } - } - - bool release_on_call = false; - GCHandle gch; - - public void PersistUntilCalled () - { - release_on_call = true; - gch = GCHandle.Alloc (this); - } - - internal SizeFuncNative NativeDelegate; - Rsvg.SizeFunc managed; - - public SizeFuncWrapper (Rsvg.SizeFunc managed) - { - this.managed = managed; - if (managed != null) - NativeDelegate = new SizeFuncNative (NativeCallback); - } - - public static Rsvg.SizeFunc GetManagedDelegate (SizeFuncNative native) - { - if (native == null) - return null; - SizeFuncWrapper wrapper = (SizeFuncWrapper) native.Target; - if (wrapper == null) - return null; - return wrapper.managed; - } - } -#endregion -} diff --git a/src/rsvg/SizeFunc.cs b/src/rsvg/SizeFunc.cs deleted file mode 100644 index 4c84738b..00000000 --- a/src/rsvg/SizeFunc.cs +++ /dev/null @@ -1,10 +0,0 @@ -// This file was generated by the Gtk# code generator. -// Any changes made will be lost if regenerated. - -namespace Rsvg { - - using System; - - public delegate void SizeFunc(out int width, out int height); - -} |