-//
-// 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;
-//
-// 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
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){
-//
-// 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;
}
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
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
-//
-// 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;
#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)]
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)
-//
-// 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;
-//
-// 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(){}
-//
-// 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;
#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++) {
}
#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);
Checked.Raise (this, null);
else
Unchecked.Raise (this, null);
- }
- }
+ }
+ }
}
}
public TemplatedControl (Interface iface) : base(iface){}
#endregion
- string _template;
+ string _template = "NOT_SET";
string caption;
/// <summary>
}
#region GraphicObject overrides
-
- public override void Initialize ()
- {
- loadTemplate ();
- base.Initialize ();
- }
/// <summary>
/// override search method from GraphicObject to prevent
/// searching inside template
/// <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
}
}
- 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
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);
}