]> O.S.I.I.S - jp/crow.git/commitdiff
improve style and templates loading sync, prevent 2x loading in some case
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Sun, 26 Jan 2020 03:22:20 +0000 (04:22 +0100)
committerJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Sun, 26 Jan 2020 03:22:20 +0000 (04:22 +0100)
Crow/src/CompilerServices/CompilerServices.cs
Crow/src/Fill/Fill.cs
Crow/src/IML/IMLContext.cs
Crow/src/Instantiator.cs
Crow/src/Style.cs
Crow/src/Widgets/EnumSelector.cs
Crow/src/Widgets/Group.cs
Crow/src/Widgets/HorizontalStack.cs
Crow/src/Widgets/RadioButton.cs
Crow/src/Widgets/TemplatedControl.cs
Crow/src/Widgets/Widget.cs

index 6637185c9adefe54bdef7024a9a1b9d6fe3f4b2a..86e7a7a9ac06c95600b004afa0a4a2378977e5bd 100644 (file)
@@ -1,28 +1,6 @@
-//
-// CompilerServices.cs
+// Copyright (c) 2013-2020  Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
 //
-// Author:
-//       Jean-Philippe Bruyère <jp.bruyere@hotmail.com>
-//
-// Copyright (c) 2013-2017 Jean-Philippe Bruyère
-//
-// Permission is hereby granted, free of charge, to any person obtaining a copy
-// of this software and associated documentation files (the "Software"), to deal
-// in the Software without restriction, including without limitation the rights
-// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-// copies of the Software, and to permit persons to whom the Software is
-// furnished to do so, subject to the following conditions:
-//
-// The above copyright notice and this permission notice shall be included in
-// all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-// THE SOFTWARE.
+// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
 
 using System;
 using System.Reflection.Emit;
index 7d521045cbb5086f2aac43c6562df86c71341d23..719002d2bb0fcde76823f2f76d375ad692a512b9 100644 (file)
@@ -1,31 +1,8 @@
-//
-// Fill.cs
+// Copyright (c) 2013-2020  Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
 //
-// Author:
-//       Jean-Philippe Bruyère <jp.bruyere@hotmail.com>
-//
-// Copyright (c) 2013-2017 Jean-Philippe Bruyère
-//
-// Permission is hereby granted, free of charge, to any person obtaining a copy
-// of this software and associated documentation files (the "Software"), to deal
-// in the Software without restriction, including without limitation the rights
-// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-// copies of the Software, and to permit persons to whom the Software is
-// furnished to do so, subject to the following conditions:
-//
-// The above copyright notice and this permission notice shall be included in
-// all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-// THE SOFTWARE.
+// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
 
 using System;
-using System.Collections.Generic;
 using Crow.Cairo;
 
 namespace Crow
@@ -45,16 +22,15 @@ namespace Crow
                        if (string.IsNullOrEmpty (s))
                                return null;
                        if (s.Substring (1).StartsWith ("gradient", StringComparison.Ordinal))
-                               return (Gradient)Gradient.Parse (s);
-                       if (s.EndsWith (".svg", true, System.Globalization.CultureInfo.InvariantCulture))
-                               return Parse (s);
-                       if (s.EndsWith (".png", true, System.Globalization.CultureInfo.InvariantCulture) ||
+                               return (Gradient)Gradient.Parse (s);                            
+                       if (s.EndsWith (".svg", true, System.Globalization.CultureInfo.InvariantCulture) ||
+                               s.EndsWith (".png", true, System.Globalization.CultureInfo.InvariantCulture) ||
                            s.EndsWith (".jpg", true, System.Globalization.CultureInfo.InvariantCulture) ||
-                           s.EndsWith (".jpeg", true, System.Globalization.CultureInfo.InvariantCulture) ||
+                           s.EndsWith (".jpeg", true, System.Globalization.CultureInfo.InvariantCulture)||
                            s.EndsWith (".bmp", true, System.Globalization.CultureInfo.InvariantCulture) ||
                            s.EndsWith (".gif", true, System.Globalization.CultureInfo.InvariantCulture))
-                               return Parse (s);
-                       
+                               return Picture.Parse (s);
+
                        return (SolidColor)SolidColor.Parse (s);
                }
                public static implicit operator Color(Fill c){
index 6773de426e86f143a8b2576c9458434dda9dc0e5..3aab2158cd7689d97c591731b87c67d739bd385c 100644 (file)
@@ -1,28 +1,6 @@
-//
-// Context.cs
+// Copyright (c) 2013-2020  Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
 //
-// Author:
-//       Jean-Philippe Bruyère <jp.bruyere@hotmail.com>
-//
-// Copyright (c) 2013-2017 Jean-Philippe Bruyère
-//
-// Permission is hereby granted, free of charge, to any person obtaining a copy
-// of this software and associated documentation files (the "Software"), to deal
-// in the Software without restriction, including without limitation the rights
-// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-// copies of the Software, and to permit persons to whom the Software is
-// furnished to do so, subject to the following conditions:
-//
-// The above copyright notice and this permission notice shall be included in
-// all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-// THE SOFTWARE.
+// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
 
 using System;
 using System.Collections.Generic;
index 1952006c3a1e39c6288cdf6b22b2f46f385cfa65..20ca1ff8033b3590d56e6586a9ecf5b1c957aa4c 100644 (file)
@@ -306,19 +306,19 @@ namespace Crow.IML {
                                }
 
                                if (!inlineTemplate) {//load from path or default template
-                                       ctx.il.Emit (OpCodes.Ldloc_0);//Load  current templatedControl ref
-                                       if (string.IsNullOrEmpty (templatePath)) {
-                                               ctx.il.Emit (OpCodes.Ldnull);//default template loading
-                                       } else {
+
+                                       if (!string.IsNullOrEmpty (templatePath)) {
+                                               ctx.il.Emit (OpCodes.Ldloc_0);//Load  current templatedControl ref
+                                               //      ctx.il.Emit (OpCodes.Ldnull);//default template loading
+                                               //} else {
                                                ctx.il.Emit (OpCodes.Ldarg_1);//load currentInterface
                                                ctx.il.Emit (OpCodes.Ldstr, templatePath); //Load template path string
                                                //get declaring type for search fallback assembly
                                                ctx.il.Emit (OpCodes.Ldloc_0);
                                                ctx.il.Emit (OpCodes.Call, CompilerServices.miGetType);
-                                               ctx.il.Emit (OpCodes.Callvirt,
-                                                       CompilerServices.miIFaceCreateTemplateInst);
+                                               ctx.il.Emit (OpCodes.Callvirt, CompilerServices.miIFaceCreateTemplateInst);
+                                               ctx.il.Emit (OpCodes.Callvirt, CompilerServices.miLoadTmp);//load template
                                        }
-                                       ctx.il.Emit (OpCodes.Callvirt, CompilerServices.miLoadTmp);//load template
                                }
                                if (itemTemplateIds.Count == 0) {
                                        //try to load ItemTemplate(s) from ItemTemplate attribute of TemplatedGroup
@@ -454,7 +454,7 @@ namespace Crow.IML {
                                if (reader.HasAttributes) {
 
                                        while (reader.MoveToNextAttribute ()) {
-                                               if (reader.Name == "Style" || reader.Name == "DataSourceType")
+                                               if (reader.Name == "Style" || reader.Name == "DataSourceType" || reader.Name == "Template")
                                                        continue;
 
                                                #if DESIGN_MODE
index 5ca434a0732511e20c1cb003e25c88d1bc0ac114..ded06b604e5e7f6cd8d2d4a7705d9ef48b658bb1 100644 (file)
@@ -1,28 +1,6 @@
-//
-// Style.cs
+// Copyright (c) 2013-2020  Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
 //
-// Author:
-//       Jean-Philippe Bruyère <jp.bruyere@hotmail.com>
-//
-// Copyright (c) 2013-2017 Jean-Philippe Bruyère
-//
-// Permission is hereby granted, free of charge, to any person obtaining a copy
-// of this software and associated documentation files (the "Software"), to deal
-// in the Software without restriction, including without limitation the rights
-// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-// copies of the Software, and to permit persons to whom the Software is
-// furnished to do so, subject to the following conditions:
-//
-// The above copyright notice and this permission notice shall be included in
-// all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-// THE SOFTWARE.
+// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
 
 using System;
 using System.Collections.Generic;
index 70985f2a37cd9d87f2dc4acc53db1eb77bba585e..fa43e3b35d4b25f1d4e4a72102d0e663a65480af 100644 (file)
@@ -31,10 +31,33 @@ namespace Crow
                #region private fields
                Enum enumValue;
                Type enumType;
+               string rbStyle;
+               IML.Instantiator radioButtonITor;
                #endregion
 
                #region public properties
                /// <summary>
+               /// Enum values are presented with RadioButton controls. Here you may specify a template to use
+               /// for the radio buttons.
+               /// </summary>
+               [DefaultValue (null)]
+               public string RadioButtonStyle {
+                       get { return rbStyle; }
+                       set {
+                               if (rbStyle == value)
+                                       return;
+                               rbStyle = value;
+                               radioButtonITor = null;
+                               //force refresh to use new template if values are already displayed
+                               if (enumValue != null) {
+                                       Enum tmp = enumValue;
+                                       enumValue = null;
+                                       EnumValue = tmp;
+                               }
+                               NotifyValueChanged ("RadioButtonStyle", rbStyle);
+                       }
+               }
+               /// <summary>
                /// use to define the colors of the 3d border
                /// </summary>
                [DefaultValue(null)]
@@ -45,13 +68,16 @@ namespace Crow
                                        return;
 
                                enumValue = value;
+                               if (radioButtonITor == null)
+                                       radioButtonITor = IFace.CreateITorFromIMLFragment ($"<RadioButton Style='{rbStyle}'/>");
 
                                if (enumValue != null) {
                                        if (enumType != enumValue.GetType ()) {
                                                enumValueContainer.ClearChildren ();
                                                enumType = enumValue.GetType ();
                                                foreach (string en in enumType.GetEnumNames ()) {
-                                                       RadioButton rb = new RadioButton (IFace);
+
+                                                       RadioButton rb = radioButtonITor.CreateInstance<RadioButton> ();
                                                        rb.Caption = en;
                                                        rb.LogicalParent = this;
                                                        if (enumValue.ToString () == en)
index a992e5af6ab63dd4073bbb568651fba58f5e07de..3e3997344786a4f1a8ab2eb3f529949eab609512 100644 (file)
@@ -1,36 +1,11 @@
-//
-// Group.cs
+// Copyright (c) 2013-2020  Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
 //
-// Author:
-//       Jean-Philippe Bruyère <jp.bruyere@hotmail.com>
-//
-// Copyright (c) 2013-2017 Jean-Philippe Bruyère
-//
-// Permission is hereby granted, free of charge, to any person obtaining a copy
-// of this software and associated documentation files (the "Software"), to deal
-// in the Software without restriction, including without limitation the rights
-// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-// copies of the Software, and to permit persons to whom the Software is
-// furnished to do so, subject to the following conditions:
-//
-// The above copyright notice and this permission notice shall be included in
-// all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-// THE SOFTWARE.
+// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
 
 using System;
 using System.Collections.Generic;
 using System.ComponentModel;
-using System.Xml.Serialization;
 using Crow.Cairo;
-using System.Diagnostics;
-using System.Reflection;
 using System.Threading;
 
 
index 64d7cae5756b65ca49aa016223ca4fa564ea220f..a6b0fd56354ce0e7f01dda2346e5134770076073 100644 (file)
@@ -1,41 +1,14 @@
-//
-// HorizontalStack.cs
+// Copyright (c) 2013-2020  Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
 //
-// Author:
-//       Jean-Philippe Bruyère <jp.bruyere@hotmail.com>
-//
-// Copyright (c) 2013-2017 Jean-Philippe Bruyère
-//
-// Permission is hereby granted, free of charge, to any person obtaining a copy
-// of this software and associated documentation files (the "Software"), to deal
-// in the Software without restriction, including without limitation the rights
-// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-// copies of the Software, and to permit persons to whom the Software is
-// furnished to do so, subject to the following conditions:
-//
-// The above copyright notice and this permission notice shall be included in
-// all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-// THE SOFTWARE.
+// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
 
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Xml.Serialization;
 
 namespace Crow
 {
        /// <summary>
        /// group control stacking its children horizontally
        /// </summary>
-    public class HorizontalStack : GenericStack
+       public class HorizontalStack : GenericStack
     {
                #region CTOR
                protected HorizontalStack () : base(){}
index d18971a27ae3f550e9d528f0630fd65b84f77428..ef2c6e93bf012fd9bbe33138aa49dd090ea00c53 100644 (file)
@@ -1,42 +1,23 @@
-//
-// RadioButton.cs
+// Copyright (c) 2013-2020  Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
 //
-// Author:
-//       Jean-Philippe Bruyère <jp.bruyere@hotmail.com>
-//
-// Copyright (c) 2013-2017 Jean-Philippe Bruyère
-//
-// Permission is hereby granted, free of charge, to any person obtaining a copy
-// of this software and associated documentation files (the "Software"), to deal
-// in the Software without restriction, including without limitation the rights
-// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-// copies of the Software, and to permit persons to whom the Software is
-// furnished to do so, subject to the following conditions:
-//
-// The above copyright notice and this permission notice shall be included in
-// all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-// THE SOFTWARE.
+// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
 
 using System;
 using System.ComponentModel;
-using System.Xml.Serialization;
 
 namespace Crow
 {
-    public class RadioButton : TemplatedControl
-    {                  
+       /// <summary>
+       /// Bistate templated control. Several occurences in one Group constrol will allow
+       /// only one checked RadioButton, other are automatically disabled.
+       /// </summary>
+       public class RadioButton : TemplatedControl
+       {
                bool isChecked;
 
                #region CTOR
-               protected RadioButton () : base(){}
-               public RadioButton(Interface iface) : base(iface){}     
+               protected RadioButton () : base () { }
+               public RadioButton (Interface iface) : base (iface) { }
                #endregion
 
                public event EventHandler Checked;
@@ -44,7 +25,7 @@ namespace Crow
 
                #region GraphicObject overrides
                public override void onMouseDown (object sender, MouseButtonEventArgs e)
-               {                                               
+               {
                        Group pg = Parent as Group;
                        if (pg != null) {
                                for (int i = 0; i < pg.Children.Count; i++) {
@@ -60,15 +41,13 @@ namespace Crow
                }
                #endregion
 
-        [DefaultValue(false)]
-        public bool IsChecked
-        {
+               [DefaultValue (false)]
+               public bool IsChecked {
                        get { return isChecked; }
-            set
-            {
+                       set {
                                if (isChecked == value)
                                        return;
-                               
+
                                isChecked = value;
 
                                NotifyValueChanged ("IsChecked", value);
@@ -77,7 +56,7 @@ namespace Crow
                                        Checked.Raise (this, null);
                                else
                                        Unchecked.Raise (this, null);
-            }
-        }
+                       }
+               }
        }
 }
index 563fc0a67668a56a8fb49103389c53075d42e8e6..962337de46ff402767ca08196e16e34bb054bf80 100644 (file)
@@ -36,7 +36,7 @@ namespace Crow
                public TemplatedControl (Interface iface) : base(iface){}
                #endregion
 
-               string _template;
+               string _template = "NOT_SET";
                string caption;
 
                /// <summary>
@@ -72,12 +72,6 @@ namespace Crow
                }
 
                #region GraphicObject overrides
-
-               public override void Initialize ()
-               {
-                       loadTemplate ();
-                       base.Initialize ();
-               }
                /// <summary>
                /// override search method from GraphicObject to prevent
                /// searching inside template
index 4fe87abe544aa7846fac7895cd03967ad2037de1..fee189b7b2e1522c44a28e3b530399ed66c80528 100644 (file)
@@ -247,7 +247,7 @@ namespace Crow
                /// <summary>
                /// Initialize this Graphic object instance by setting style and default values and loading template if required
                /// </summary>
-               public virtual void Initialize(){
+               public void Initialize(){
                        loadDefaultValues ();
                }
                #region private fields
@@ -1134,56 +1134,24 @@ namespace Crow
                                }
                        }
 
-                       foreach (PropertyInfo pi in thisType.GetProperties(BindingFlags.Public | BindingFlags.Instance)) {
-                               if (pi.GetSetMethod () == null)
-                                       continue;
-                               XmlIgnoreAttribute xia = (XmlIgnoreAttribute)pi.GetCustomAttribute (typeof(XmlIgnoreAttribute));
-                               if (xia != null)
-                                       continue;
-
-                               object defaultValue;
-
-                               int styleIndex = -1;
-                               if (styling.Count > 0){
-                                       for (int i = 0; i < styling.Count; i++) {
-                                               if (styling[i].ContainsKey (pi.Name)){
-                                                       styleIndex = i;
-                                                       break;
-                                               }
-                                       }
-                               }
-                               if (styleIndex >= 0){
-                                       if (pi.PropertyType.IsEnum)//maybe should be in parser..
-                                               defaultValue = Enum.Parse(pi.PropertyType, (string)styling[styleIndex] [pi.Name], true);
-                                       else
-                                               defaultValue = styling[styleIndex] [pi.Name];
-
-                                       #if DESIGN_MODE
-                                       if (defaultValue != null){
-                                               FileLocation fl = styling[styleIndex].Locations[pi.Name];
-                                               il.Emit (OpCodes.Ldloc_0);
-                                               il.Emit (OpCodes.Ldstr, pi.Name);
-                                               il.Emit (OpCodes.Ldstr, fl.FilePath);
-                                               il.Emit (OpCodes.Ldc_I4, fl.Line);
-                                               il.Emit (OpCodes.Ldc_I4, fl.Column);
-                                               il.Emit (OpCodes.Call, miDesignAddDefLoc);
+                       //first set template if it exists
+                       PropertyInfo piTmp = thisType.GetProperty ("Template");
+                       if (piTmp != null) {
+                               //if template has been declared in IML, cancel style or default loading
+                               System.Reflection.Emit.Label cancelTemplateLoad = il.DefineLabel ();
+                               il.Emit (OpCodes.Ldloc_0);//load target widget
+                               il.Emit (OpCodes.Ldfld, typeof (PrivateContainer).GetField ("child", BindingFlags.Instance | BindingFlags.NonPublic));
+                               il.Emit (OpCodes.Brtrue, cancelTemplateLoad);
 
-                                               il.Emit (OpCodes.Ldloc_0);
-                                               il.Emit (OpCodes.Ldfld, typeof(Widget).GetField("design_style_values"));
-                                               il.Emit (OpCodes.Ldstr, pi.Name);
-                                               il.Emit (OpCodes.Ldstr, defaultValue.ToString());
-                                               il.Emit (OpCodes.Call, CompilerServices.miDicStrStrAdd);
-                                       }
-                                       #endif
+                               setDefaultValue (il, piTmp, ref styling);
 
-                               }else {
-                                       DefaultValueAttribute dv = (DefaultValueAttribute)pi.GetCustomAttribute (typeof (DefaultValueAttribute));
-                                       if (dv == null)
-                                               continue;
-                                       defaultValue = dv.Value;
-                               }
+                               il.MarkLabel (cancelTemplateLoad);
+                       }
 
-                               CompilerServices.EmitSetValue (il, pi, defaultValue);
+                       foreach (PropertyInfo pi in thisType.GetProperties(BindingFlags.Public | BindingFlags.Instance)) {
+                               if (pi.Name == "Template")
+                                       continue;
+                               setDefaultValue (il, pi, ref styling);
                        }
                        il.Emit(OpCodes.Ret);
                        #endregion
@@ -1201,6 +1169,59 @@ namespace Crow
 
                        onInitialized (this, null);
                }
+               void setDefaultValue (ILGenerator il, PropertyInfo pi, ref List<Style> styling)
+               {
+                       if (pi.GetSetMethod () == null)
+                               return;
+                       XmlIgnoreAttribute xia = (XmlIgnoreAttribute)pi.GetCustomAttribute (typeof (XmlIgnoreAttribute));
+                       if (xia != null)
+                               return;
+
+                       object defaultValue;
+
+                       int styleIndex = -1;
+                       if (styling.Count > 0) {
+                               for (int i = 0; i < styling.Count; i++) {
+                                       if (styling [i].ContainsKey (pi.Name)) {
+                                               styleIndex = i;
+                                               break;
+                                       }
+                               }
+                       }
+                       if (styleIndex >= 0) {
+                               if (pi.PropertyType.IsEnum)//maybe should be in parser..
+                                       defaultValue = Enum.Parse (pi.PropertyType, (string)styling [styleIndex] [pi.Name], true);
+                               else
+                                       defaultValue = styling [styleIndex] [pi.Name];
+
+#if DESIGN_MODE
+                               if (defaultValue != null) {
+                                       FileLocation fl = styling [styleIndex].Locations [pi.Name];
+                                       il.Emit (OpCodes.Ldloc_0);
+                                       il.Emit (OpCodes.Ldstr, pi.Name);
+                                       il.Emit (OpCodes.Ldstr, fl.FilePath);
+                                       il.Emit (OpCodes.Ldc_I4, fl.Line);
+                                       il.Emit (OpCodes.Ldc_I4, fl.Column);
+                                       il.Emit (OpCodes.Call, miDesignAddDefLoc);
+
+                                       il.Emit (OpCodes.Ldloc_0);
+                                       il.Emit (OpCodes.Ldfld, typeof (Widget).GetField ("design_style_values"));
+                                       il.Emit (OpCodes.Ldstr, pi.Name);
+                                       il.Emit (OpCodes.Ldstr, defaultValue.ToString ());
+                                       il.Emit (OpCodes.Call, CompilerServices.miDicStrStrAdd);
+                               }
+#endif
+
+                       } else {
+                               DefaultValueAttribute dv = (DefaultValueAttribute)pi.GetCustomAttribute (typeof (DefaultValueAttribute));
+                               if (dv == null)
+                                       return;
+                               defaultValue = dv.Value;
+                       }
+
+                       CompilerServices.EmitSetValue (il, pi, defaultValue);
+               }
+
                protected virtual void onInitialized (object sender, EventArgs e){
                        Initialized.Raise(sender, e);
                }