aboutsummaryrefslogtreecommitdiffstatsci
path: root/src/GraphicObjects
diff options
context:
space:
mode:
Diffstat (limited to 'src/GraphicObjects')
-rw-r--r--src/GraphicObjects/Container.cs4
-rw-r--r--src/GraphicObjects/GraphicObject.cs191
-rw-r--r--src/GraphicObjects/Grid.cs5
-rw-r--r--src/GraphicObjects/Group.cs11
-rw-r--r--src/GraphicObjects/ListBox.cs14
-rw-r--r--src/GraphicObjects/PrivateContainer.cs4
-rw-r--r--src/GraphicObjects/ProgressBar.cs8
-rw-r--r--src/GraphicObjects/Scroller.cs4
-rw-r--r--src/GraphicObjects/TabView.cs4
-rw-r--r--src/GraphicObjects/TemplatedControl.cs19
-rw-r--r--src/GraphicObjects/TextBox.cs5
11 files changed, 94 insertions, 175 deletions
diff --git a/src/GraphicObjects/Container.cs b/src/GraphicObjects/Container.cs
index 69e3a3b4..fb4a7834 100644
--- a/src/GraphicObjects/Container.cs
+++ b/src/GraphicObjects/Container.cs
@@ -25,9 +25,9 @@ namespace Crow
get { return child; }
set { child = value; }
}
- public virtual T SetChild<T> (T _child)
+ public virtual void SetChild(GraphicObject _child)
{
- return base.SetChild (_child);
+ base.SetChild (_child);
}
#region IXmlSerializable
diff --git a/src/GraphicObjects/GraphicObject.cs b/src/GraphicObjects/GraphicObject.cs
index 8966acf6..88166fe6 100644
--- a/src/GraphicObjects/GraphicObject.cs
+++ b/src/GraphicObjects/GraphicObject.cs
@@ -513,7 +513,7 @@ namespace Crow
#endregion
/// <summary> Loads the default values from XML attributes default </summary>
- protected virtual void loadDefaultValues()
+ public void loadDefaultValues()
{
#if DEBUG_LOAD
Debug.WriteLine ("LoadDefValues for " + this.ToString ());
@@ -581,151 +581,70 @@ namespace Crow
typeof(void),new Type[] {typeof(object)},thisType,true);
il = dm.GetILGenerator(256);
-
+ il.DeclareLocal(typeof(GraphicObject));
il.Emit(OpCodes.Nop);
+ //set local GraphicObject to root object passed as 1st argument
+ il.Emit (OpCodes.Ldarg_0);
+ il.Emit (OpCodes.Stloc_0);
- foreach (PropertyInfo pi in thisType.GetProperties(BindingFlags.Public | BindingFlags.Instance)) {
- string name = "";
- object defaultValue = null;
-
- #region retrieve custom attributes
+ 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;
- XmlAttributeAttribute xaa = (XmlAttributeAttribute)pi.GetCustomAttribute (typeof(XmlAttributeAttribute));
- if (xaa != null) {
- if (string.IsNullOrEmpty (xaa.AttributeName))
- name = pi.Name;
- else
- name = xaa.AttributeName;
- }
-
- int styleIndex = -1;
- if (styling.Count > 0){
- for (int i = 0; i < styling.Count; i++) {
- if (styling[i].ContainsKey (name)){
- styleIndex = i;
- break;
- }
- }
- }
- if (styleIndex >= 0){
- if (pi.PropertyType.IsEnum)//maybe should be in parser..
- defaultValue = Enum.Parse(pi.PropertyType, (string)styling[styleIndex] [name], true);
- else
- defaultValue = styling[styleIndex] [name];
- }else {
- DefaultValueAttribute dv = (DefaultValueAttribute)pi.GetCustomAttribute (typeof (DefaultValueAttribute));
- if (dv == null)
- continue;
- defaultValue = dv.Value;
- }
- #endregion
-
- il.Emit (OpCodes.Ldarg_0);
-
- if (defaultValue == null) {
- il.Emit (OpCodes.Ldnull);
- il.Emit (OpCodes.Callvirt, pi.GetSetMethod ());
+ object defaultValue;
+ if (!getDefaultValue (pi, styling, out defaultValue))
continue;
- }
- Type dvType = defaultValue.GetType ();
-
- if (dvType.IsValueType) {
- if (pi.PropertyType.IsValueType) {
- if (pi.PropertyType.IsEnum) {
- if (pi.PropertyType != dvType)
- throw new Exception ("Enum mismatch in default values: " + pi.PropertyType.FullName);
- il.Emit (OpCodes.Ldc_I4, Convert.ToInt32 (defaultValue));
- } else {
- switch (Type.GetTypeCode (dvType)) {
- case TypeCode.Boolean:
- if ((bool)defaultValue == true)
- il.Emit (OpCodes.Ldc_I4_1);
- else
- il.Emit (OpCodes.Ldc_I4_0);
- break;
-// case TypeCode.Empty:
-// break;
-// case TypeCode.Object:
-// break;
-// case TypeCode.DBNull:
-// break;
-// case TypeCode.SByte:
-// break;
-// case TypeCode.Decimal:
-// break;
-// case TypeCode.DateTime:
-// break;
- case TypeCode.Char:
- il.Emit (OpCodes.Ldc_I4, Convert.ToChar (defaultValue));
- break;
- case TypeCode.Byte:
- case TypeCode.Int16:
- case TypeCode.Int32:
- il.Emit (OpCodes.Ldc_I4, Convert.ToInt32 (defaultValue));
- break;
- case TypeCode.UInt16:
- case TypeCode.UInt32:
- il.Emit (OpCodes.Ldc_I4, Convert.ToUInt32 (defaultValue));
- break;
- case TypeCode.Int64:
- il.Emit (OpCodes.Ldc_I8, Convert.ToInt64 (defaultValue));
- break;
- case TypeCode.UInt64:
- il.Emit (OpCodes.Ldc_I8, Convert.ToUInt64 (defaultValue));
- break;
- case TypeCode.Single:
- il.Emit (OpCodes.Ldc_R4, Convert.ToSingle (defaultValue));
- break;
- case TypeCode.Double:
- il.Emit (OpCodes.Ldc_R8, Convert.ToDouble (defaultValue));
- break;
- case TypeCode.String:
- il.Emit (OpCodes.Ldstr, Convert.ToString (defaultValue));
- break;
- default:
- il.Emit (OpCodes.Pop);
- continue;
- }
- }
- } else
- throw new Exception ("Expecting valuetype in default values for: " + pi.Name);
- }else{
- //surely a class or struct
- if (dvType != typeof(string))
- throw new Exception ("Expecting String in default values for: " + pi.Name);
- if (pi.PropertyType == typeof (string))
- il.Emit (OpCodes.Ldstr, Convert.ToString (defaultValue));
- else {
- MethodInfo miParse = pi.PropertyType.GetMethod
- ("Parse", BindingFlags.Static | BindingFlags.Public,
- Type.DefaultBinder, new Type [] {typeof (string)},null);
- if (miParse == null)
- throw new Exception ("no Parse method found for: " + pi.PropertyType.FullName);
- il.Emit (OpCodes.Ldstr, Convert.ToString (defaultValue));
- il.Emit (OpCodes.Callvirt, miParse);
-
- if (miParse.ReturnType != pi.PropertyType)
- il.Emit (OpCodes.Unbox_Any, pi.PropertyType);
- }
- }
- il.Emit (OpCodes.Callvirt, pi.GetSetMethod ());
+ CompilerServices.EmitSetValue (il, pi, defaultValue);
}
il.Emit(OpCodes.Ret);
#endregion
try {
- Interface.DefaultValuesLoader[styleKey] = (Interface.loadDefaultInvoker)dm.CreateDelegate(typeof(Interface.loadDefaultInvoker));
+ Interface.DefaultValuesLoader[styleKey] = (Interface.LoaderInvoker)dm.CreateDelegate(typeof(Interface.LoaderInvoker));
Interface.DefaultValuesLoader[styleKey] (this);
} catch (Exception ex) {
throw new Exception ("Error applying style <" + styleKey + ">:", ex);
}
}
+ bool getDefaultValue(PropertyInfo pi, List<Dictionary<string, object>> styling,
+ out object defaultValue){
+ defaultValue = null;
+ string name = "";
+
+ XmlIgnoreAttribute xia = (XmlIgnoreAttribute)pi.GetCustomAttribute (typeof(XmlIgnoreAttribute));
+ if (xia != null)
+ return false;
+ XmlAttributeAttribute xaa = (XmlAttributeAttribute)pi.GetCustomAttribute (typeof(XmlAttributeAttribute));
+ if (xaa != null) {
+ if (string.IsNullOrEmpty (xaa.AttributeName))
+ name = pi.Name;
+ else
+ name = xaa.AttributeName;
+ }
+
+ int styleIndex = -1;
+ if (styling.Count > 0){
+ for (int i = 0; i < styling.Count; i++) {
+ if (styling[i].ContainsKey (name)){
+ styleIndex = i;
+ break;
+ }
+ }
+ }
+ if (styleIndex >= 0){
+ if (pi.PropertyType.IsEnum)//maybe should be in parser..
+ defaultValue = Enum.Parse(pi.PropertyType, (string)styling[styleIndex] [name], true);
+ else
+ defaultValue = styling[styleIndex] [name];
+ }else {
+ DefaultValueAttribute dv = (DefaultValueAttribute)pi.GetCustomAttribute (typeof (DefaultValueAttribute));
+ if (dv == null)
+ return false;
+ defaultValue = dv.Value;
+ }
+ return true;
+ }
+
public virtual GraphicObject FindByName(string nameToFind){
return string.Equals(nameToFind, _name, StringComparison.Ordinal) ? this : null;
@@ -757,6 +676,18 @@ namespace Crow
if (RegisteredLayoutings == LayoutingType.None)
Interface.CurrentInterface.EnqueueForRepaint (this);
}
+// public Interface CurrentInterface {
+// get {
+// ILayoutable tmp = this.Parent;
+// while (tmp != null) {
+// if (tmp is Interface)
+// return tmp as Interface;
+// tmp = tmp.Parent;
+// }
+// return null;
+// }
+// }
+
#region Layouting
#if DEBUG_LAYOUTING
diff --git a/src/GraphicObjects/Grid.cs b/src/GraphicObjects/Grid.cs
index 525827e0..ed0cd986 100644
--- a/src/GraphicObjects/Grid.cs
+++ b/src/GraphicObjects/Grid.cs
@@ -29,11 +29,10 @@ namespace Crow
int _rowCount;
#endregion
- public override T AddChild<T> (T child)
+ public override void AddChild (GraphicObject child)
{
- T tmp = base.AddChild (child);
+ base.AddChild (child);
this.RegisterForLayouting (LayoutingType.ArrangeChildren);
- return tmp;
}
public override void RemoveChild (GraphicObject child)
{
diff --git a/src/GraphicObjects/Group.cs b/src/GraphicObjects/Group.cs
index a6ca5758..4c8d0537 100644
--- a/src/GraphicObjects/Group.cs
+++ b/src/GraphicObjects/Group.cs
@@ -38,19 +38,14 @@ namespace Crow
get { return _multiSelect; }
set { _multiSelect = value; }
}
-
-
- public virtual T AddChild<T>(T child)
- {
- GraphicObject g = child as GraphicObject;
+ public virtual void AddChild(GraphicObject g){
Children.Add(g);
- g.Parent = this as GraphicObject;
+ g.Parent = this;
g.ResolveBindings ();
g.RegisteredLayoutings = LayoutingType.None;
g.RegisterForLayouting (LayoutingType.Sizing | LayoutingType.ArrangeChildren);
g.LayoutChanged += OnChildLayoutChanges;
- return (T)child;
- }
+ }
public virtual void RemoveChild(GraphicObject child)
{
child.LayoutChanged -= OnChildLayoutChanges;
diff --git a/src/GraphicObjects/ListBox.cs b/src/GraphicObjects/ListBox.cs
index 58d41e0b..ab349ed4 100644
--- a/src/GraphicObjects/ListBox.cs
+++ b/src/GraphicObjects/ListBox.cs
@@ -119,7 +119,7 @@ namespace Crow
if (ItemTemplates == null)
ItemTemplates = new Dictionary<string, ItemTemplate> ();
if (!ItemTemplates.ContainsKey ("default"))
- ItemTemplates["default"] = new ItemTemplate (ItemTemplate);
+ ItemTemplates ["default"] = Interface.GetItemTemplate (ItemTemplate);
for (int i = 1; i <= (data.Count / itemPerPage) + 1; i++) {
if (cancelLoading)
@@ -164,16 +164,16 @@ namespace Crow
return;
GraphicObject g = null;
- ItemTemplate itemStream = null;
+ ItemTemplate iTemp = null;
Type dataType = data [i].GetType ();
if (ItemTemplates.ContainsKey (dataType.FullName))
- itemStream = ItemTemplates [dataType.FullName];
+ iTemp = ItemTemplates [dataType.FullName];
else
- itemStream = ItemTemplates ["default"];
+ iTemp = ItemTemplates ["default"];
lock (Interface.CurrentInterface.LayoutMutex) {
- g = itemStream.Instance;
+ g = iTemp.CreateInstance();
page.AddChild (g);
g.DataSource = data [i];
}
@@ -190,8 +190,8 @@ namespace Crow
}else
g.MouseClick += itemClick;
- if (itemStream.Expand != null && g is Expandable) {
- (g as Expandable).Expand += itemStream.Expand;
+ if (iTemp.Expand != null && g is Expandable) {
+ (g as Expandable).Expand += iTemp.Expand;
}
//g.LogicalParent = this;
}
diff --git a/src/GraphicObjects/PrivateContainer.cs b/src/GraphicObjects/PrivateContainer.cs
index 8793ba45..a6f52f29 100644
--- a/src/GraphicObjects/PrivateContainer.cs
+++ b/src/GraphicObjects/PrivateContainer.cs
@@ -47,7 +47,7 @@ namespace Crow
protected GraphicObject child;
- protected virtual T SetChild<T>(T _child)
+ internal virtual void SetChild(GraphicObject _child)
{
if (child != null) {
@@ -67,8 +67,6 @@ namespace Crow
child.RegisteredLayoutings = LayoutingType.None;
child.RegisterForLayouting (LayoutingType.Sizing);
}
-
- return (T)_child;
}
#region GraphicObject Overrides
diff --git a/src/GraphicObjects/ProgressBar.cs b/src/GraphicObjects/ProgressBar.cs
index e3f778bf..6e1ce404 100644
--- a/src/GraphicObjects/ProgressBar.cs
+++ b/src/GraphicObjects/ProgressBar.cs
@@ -9,7 +9,7 @@ using System.ComponentModel;
namespace Crow
{
- [Serializable]
+
public class ProgressBar : NumericControl
{
#region CTOR
@@ -22,12 +22,6 @@ namespace Crow
}
#region GraphicObject overrides
- [XmlAttributeAttribute()][DefaultValue("vgradient|0:BlueCrayola|0,5:SkyBlue|1:BlueCrayola")]
- public override Fill Foreground {
- get { return base.Foreground; }
- set { base.Foreground = value; }
- }
-
protected override void onDraw (Context gr)
{
base.onDraw (gr);
diff --git a/src/GraphicObjects/Scroller.cs b/src/GraphicObjects/Scroller.cs
index 3eaff5f4..c248595d 100644
--- a/src/GraphicObjects/Scroller.cs
+++ b/src/GraphicObjects/Scroller.cs
@@ -148,7 +148,7 @@ namespace Crow
ScrollY = 0;
ScrollX = 0;
}
- public override T SetChild<T> (T _child)
+ public override void SetChild (GraphicObject _child)
{
GraphicObject c = child as GraphicObject;
Group g = child as Group;
@@ -164,7 +164,7 @@ namespace Crow
if (g != null)
g.ChildrenCleared += onChildListCleared;
}
- return base.SetChild (_child);
+ base.SetChild (_child);
}
#endregion
diff --git a/src/GraphicObjects/TabView.cs b/src/GraphicObjects/TabView.cs
index d616ffc6..015f5f4f 100644
--- a/src/GraphicObjects/TabView.cs
+++ b/src/GraphicObjects/TabView.cs
@@ -100,7 +100,7 @@ namespace Crow
set { }
}
- public override T AddChild<T> (T child)
+ public override void AddChild (GraphicObject child)
{
TabItem ti = child as TabItem;
if (ti == null)
@@ -113,7 +113,7 @@ namespace Crow
SelectedTab = 0;
}
- return base.AddChild (child);
+ base.AddChild (child);
}
public override void RemoveChild (GraphicObject child)
{
diff --git a/src/GraphicObjects/TemplatedControl.cs b/src/GraphicObjects/TemplatedControl.cs
index b325a0d2..422a45ec 100644
--- a/src/GraphicObjects/TemplatedControl.cs
+++ b/src/GraphicObjects/TemplatedControl.cs
@@ -65,8 +65,8 @@ namespace Crow
string _template;
string _itemTemplate;
- public Dictionary<string, ItemTemplate> ItemTemplates;
-
+ public Dictionary<string, ItemTemplate> ItemTemplates = new Dictionary<string, Crow.ItemTemplate>();//TODO: dont instantiate if not used
+ //but then i should test if null in msil gen
[XmlAttributeAttribute][DefaultValue(null)]
public string Template {
get { return _template; }
@@ -84,7 +84,7 @@ namespace Crow
[XmlAttributeAttribute][DefaultValue("#Crow.Templates.ItemTemplate.goml")]
public string ItemTemplate {
get { return _itemTemplate; }
- set {
+ set {
if (value == _itemTemplate)
return;
@@ -146,7 +146,7 @@ namespace Crow
xr.Read (); //read first child
xr.Read (); //skip root node
- while (!xr.EOF) {
+ while (!xr.EOF) {
if (!xr.IsStartElement ()) {
xr.Read ();
continue;
@@ -164,10 +164,13 @@ namespace Crow
if (ItemTemplates == null)
ItemTemplates = new Dictionary<string, ItemTemplate> ();
- //TODO:check encoding
- ItemTemplates[dataType] = new ItemTemplate (Encoding.UTF8.GetBytes(itemTmp));
+
+ using (IMLReader iTmp = new IMLReader (null, itemTmp)) {
+ ItemTemplates [dataType] =
+ new ItemTemplate (iTmp.RootType, iTmp.GetLoader (), dataType, datas);
+ }
if (!string.IsNullOrEmpty (datas))
- ItemTemplates [dataType].CreateExpandDelegate(this, dataType, datas);
+ ItemTemplates [dataType].CreateExpandDelegate(this);
continue;
}
@@ -197,7 +200,7 @@ namespace Crow
//if no template found, load default one
if (this.child == null)
loadTemplate ();
-
+
//normal xml read
using (XmlReader xr = new XmlTextReader (tmp, XmlNodeType.Element, null)) {
xr.Read ();
diff --git a/src/GraphicObjects/TextBox.cs b/src/GraphicObjects/TextBox.cs
index 5c3772b7..81fce3e2 100644
--- a/src/GraphicObjects/TextBox.cs
+++ b/src/GraphicObjects/TextBox.cs
@@ -29,14 +29,13 @@ namespace Crow
public class TextBox : Label
{
#region CTOR
+ public TextBox()
+ { }
public TextBox(string _initialValue)
: base(_initialValue)
{
}
-
- public TextBox()
- { }
#endregion
#region GraphicObject overrides