aboutsummaryrefslogtreecommitdiffstatsci
path: root/src
diff options
context:
space:
mode:
authorjpbruyere <jp.bruyere@hotmail.com>2016-08-06 17:48:03 +0200
committerjpbruyere <jp.bruyere@hotmail.com>2016-08-06 17:48:03 +0200
commitc45ce80e0e4298afcbeee9215ee2d1d30c4c3be8 (patch)
treeec659a28153b9df8406736d9f8df6ee255b8cb7e /src
parentf42cabddc008529eddc0a43cad3be2b39b6790ee (diff)
* Crow.csproj:
* Label.cs: update * GraphicObject.cs: key up * ListBox.cs: IMLStream instanciing * PrivateContainer.cs: Clear child Changes * Scroller.cs: scroller have VerticalSrcrolling by default * TemplatedControl.cs: remove unused hostClass attribute * IMLStream.cs: IMLStream instance and source properties * Interface.cs: removed unused hostClass Only putOnTop Window widget when focused KeyboardState key up and down * TreeView.crow: no border in default template * BasicTests.cs: IMLEditor PropLessBinding test * Tests.csproj: * 2.crow: * 0.crow: * test5.crow: * 2.crow: * testTreeView.crow: update tests * Bindings.cs: * MemberReference.cs: * CompilerServices.cs: property less bindings debug
Diffstat (limited to 'src')
-rw-r--r--src/CompilerServices/Bindings.cs63
-rw-r--r--src/CompilerServices/CompilerServices.cs4
-rw-r--r--src/CompilerServices/MemberReference.cs4
-rw-r--r--src/GraphicObjects/GraphicObject.cs3
-rw-r--r--src/GraphicObjects/Label.cs2
-rw-r--r--src/GraphicObjects/ListBox.cs2
-rw-r--r--src/GraphicObjects/PrivateContainer.cs3
-rw-r--r--src/GraphicObjects/Scroller.cs2
-rw-r--r--src/GraphicObjects/TemplatedControl.cs6
-rw-r--r--src/IMLStream.cs19
-rw-r--r--src/Interface.cs23
11 files changed, 79 insertions, 52 deletions
diff --git a/src/CompilerServices/Bindings.cs b/src/CompilerServices/Bindings.cs
index 40ade60d..8ece856c 100644
--- a/src/CompilerServices/Bindings.cs
+++ b/src/CompilerServices/Bindings.cs
@@ -93,12 +93,12 @@ namespace Crow
/// resolve target expression
/// </summary>
/// <returns><c>true</c>, if target was found, <c>false</c> otherwise.</returns>
- public bool FindTarget ()
+ public bool TryFindTarget ()
{
if (Target != null)
return true;
- string member = null;
+ string memberName = null;
//if binding exp = '{}' => binding is done on datasource
if (string.IsNullOrEmpty (Expression)) {
@@ -118,85 +118,86 @@ namespace Crow
string [] bindingExp = expression.Split ('/');
+
if (bindingExp.Length == 1) {
//datasource binding
- Target = new MemberReference ((Source.Instance as GraphicObject).DataSource);
- member = bindingExp [0];
+ object dataSource = (Source.Instance as GraphicObject).DataSource;
+ if (dataSource == null) {
+ Debug.WriteLine ("\tDataSource is null => " + this.ToString());
+ return false;
+ }
+
+ Target = new MemberReference (dataSource);
+ memberName = bindingExp [0];
} else {
int ptr = 0;
- ILayoutable tmp = Source.Instance as ILayoutable;
+ ILayoutable tmpTarget = Source.Instance as ILayoutable;
//if exp start with '/' => Graphic tree parsing start at source
if (string.IsNullOrEmpty (bindingExp [0]))
ptr++;
else if (bindingExp[0] == "."){ //search template root
do {
- tmp = tmp.Parent;
- if (tmp == null)
+ tmpTarget = tmpTarget.Parent;
+ if (tmpTarget == null)
return false;
- if (tmp is Interface)
+ if (tmpTarget is Interface)
throw new Exception ("Not in Templated Control");
- } while (!(tmp is TemplatedControl));
+ } while (!(tmpTarget is TemplatedControl));
ptr++;
}
while (ptr < bindingExp.Length - 1) {
- if (tmp == null) {
+ if (tmpTarget == null) {
#if DEBUG_BINDING
Debug.WriteLine ("\tERROR: target not found => " + this.ToString());
#endif
return false;
}
if (bindingExp [ptr] == "..")
- tmp = tmp.LogicalParent;
+ tmpTarget = tmpTarget.LogicalParent;
else if (bindingExp [ptr] == ".") {
if (ptr > 0)
throw new Exception ("Syntax error in binding, './' may only appear in first position");
- tmp = Source.Instance as ILayoutable;
+ tmpTarget = Source.Instance as ILayoutable;
} else
- tmp = (tmp as GraphicObject).FindByName (bindingExp [ptr]);
+ tmpTarget = (tmpTarget as GraphicObject).FindByName (bindingExp [ptr]);
ptr++;
}
- if (tmp == null) {
+ if (tmpTarget == null) {
#if DEBUG_BINDING
- Debug.WriteLine ("\tERROR: target not found => " + this.ToString());
+ Debug.WriteLine ("\tERROR: Binding Target not found => " + this.ToString());
#endif
return false;
}
+ Target = new MemberReference (tmpTarget);
+
string [] bindTrg = bindingExp [ptr].Split ('.');
if (bindTrg.Length == 1)
- member = bindTrg [0];
+ memberName = bindTrg [0];
else if (bindTrg.Length == 2) {
- tmp = (tmp as GraphicObject).FindByName (bindTrg [0]);
- member = bindTrg [1];
+ tmpTarget = (tmpTarget as GraphicObject).FindByName (bindTrg [0]);
+ memberName = bindTrg [1];
} else
throw new Exception ("Syntax error in binding, expected 'go dot member'");
- Target = new MemberReference (tmp);
- }
- if (Target == null) {
- #if DEBUG_BINDING
- Debug.WriteLine ("Binding Source is null: " + Expression);
- #endif
- return false;
}
- if (Target.TryFindMember (member)) {
+ if (Target.TryFindMember (memberName)) {
if (TwoWayBinding) {
IBindable source = Target.Instance as IBindable;
if (source == null)
throw new Exception (Source.Instance + " does not implement IBindable for 2 way bindings");
source.Bindings.Add (new Binding (Target, Source));
}
- return true;
}
-
#if DEBUG_BINDING
- Debug.WriteLine ("Binding member not found: " + member);
+ else
+ Debug.WriteLine ("Property less binding: " + Target + expression);
#endif
- Target = null;
- return false;
+
+ return true;
}
public void Reset ()
{
diff --git a/src/CompilerServices/CompilerServices.cs b/src/CompilerServices/CompilerServices.cs
index 4a85c442..0b69f970 100644
--- a/src/CompilerServices/CompilerServices.cs
+++ b/src/CompilerServices/CompilerServices.cs
@@ -31,7 +31,7 @@ namespace Crow
CompilerServices.CompileEventSource (b);
continue;
}
- if (!b.FindTarget ())
+ if (!b.TryFindTarget ())
continue;
//register handler for event
if (b.Target.Method == null) {
@@ -53,7 +53,7 @@ namespace Crow
continue;
}
- if (!b.FindTarget ())
+ if (!b.TryFindTarget ())
continue;
//group Bindings by target instanceq
diff --git a/src/CompilerServices/MemberReference.cs b/src/CompilerServices/MemberReference.cs
index 1dc3a3e4..97f470fc 100644
--- a/src/CompilerServices/MemberReference.cs
+++ b/src/CompilerServices/MemberReference.cs
@@ -68,6 +68,10 @@ namespace Crow
return Member != null;
}
+ public override string ToString ()
+ {
+ return string.Format ("{0}.{1}", Instance, Member);
+ }
}
}
diff --git a/src/GraphicObjects/GraphicObject.cs b/src/GraphicObjects/GraphicObject.cs
index 39556976..36be650d 100644
--- a/src/GraphicObjects/GraphicObject.cs
+++ b/src/GraphicObjects/GraphicObject.cs
@@ -1072,6 +1072,9 @@ namespace Crow
public virtual void onKeyDown(object sender, KeyboardKeyEventArgs e){
KeyDown.Raise (sender, e);
}
+ public virtual void onKeyUp(object sender, KeyboardKeyEventArgs e){
+ KeyUp.Raise (sender, e);
+ }
public virtual void onKeyPress(object sender, KeyPressEventArgs e){
KeyPress.Raise (sender, e);
}
diff --git a/src/GraphicObjects/Label.cs b/src/GraphicObjects/Label.cs
index d09542b5..95892314 100644
--- a/src/GraphicObjects/Label.cs
+++ b/src/GraphicObjects/Label.cs
@@ -72,7 +72,7 @@ namespace Crow
protected TextExtents te;
#endregion
- [XmlAttributeAttribute][DefaultValue("SteelBlue")]
+ [XmlAttributeAttribute][DefaultValue("BlueGray")]
public virtual Color SelectionBackground {
get { return selBackground; }
set {
diff --git a/src/GraphicObjects/ListBox.cs b/src/GraphicObjects/ListBox.cs
index 6cef4fd9..b92fe39f 100644
--- a/src/GraphicObjects/ListBox.cs
+++ b/src/GraphicObjects/ListBox.cs
@@ -172,7 +172,7 @@ namespace Crow
itemStream = ItemTemplates ["default"];
lock (Interface.CurrentInterface.LayoutMutex) {
- g = Interface.Load (itemStream);
+ g = itemStream.Instance;
page.AddChild (g);
g.DataSource = data [i];
}
diff --git a/src/GraphicObjects/PrivateContainer.cs b/src/GraphicObjects/PrivateContainer.cs
index 93bae7fa..8793ba45 100644
--- a/src/GraphicObjects/PrivateContainer.cs
+++ b/src/GraphicObjects/PrivateContainer.cs
@@ -51,10 +51,11 @@ namespace Crow
{
if (child != null) {
+ child.ClearBinding ();
contentSize = new Size (0, 0);
child.LayoutChanged -= OnChildLayoutChanges;
- this.RegisterForLayouting (LayoutingType.Sizing);
child.Parent = null;
+ this.RegisterForGraphicUpdate ();
}
child = _child as GraphicObject;
diff --git a/src/GraphicObjects/Scroller.cs b/src/GraphicObjects/Scroller.cs
index 0d57cdb3..3eaff5f4 100644
--- a/src/GraphicObjects/Scroller.cs
+++ b/src/GraphicObjects/Scroller.cs
@@ -39,7 +39,7 @@ namespace Crow
public event EventHandler<ScrollingEventArgs> Scrolled;
#region public properties
- [XmlAttributeAttribute][DefaultValue(false)]
+ [XmlAttributeAttribute][DefaultValue(true)]
public bool VerticalScrolling {
get { return _verticalScrolling; }
set { _verticalScrolling = value; }
diff --git a/src/GraphicObjects/TemplatedControl.cs b/src/GraphicObjects/TemplatedControl.cs
index f1c719f6..9040ddeb 100644
--- a/src/GraphicObjects/TemplatedControl.cs
+++ b/src/GraphicObjects/TemplatedControl.cs
@@ -77,7 +77,7 @@ namespace Crow
if (string.IsNullOrEmpty(_template))
loadTemplate ();
else
- loadTemplate (Interface.Load (_template, this));
+ loadTemplate (Interface.Load (_template));
}
}
[XmlAttributeAttribute][DefaultValue("#Crow.Templates.ItemTemplate.goml")]
@@ -116,7 +116,7 @@ namespace Crow
{
if (template == null) {
DefaultTemplate dt = (DefaultTemplate)this.GetType ().GetCustomAttributes (typeof(DefaultTemplate), true).FirstOrDefault();
- this.SetChild (Interface.Load (dt.Path, this));
+ this.SetChild (Interface.Load (dt.Path));
}else
this.SetChild (template);
@@ -184,7 +184,7 @@ namespace Crow
}
}
} else
- loadTemplate (Interface.Load (template, this));
+ loadTemplate (Interface.Load (template));
//if no template found, load default one
if (this.child == null)
diff --git a/src/IMLStream.cs b/src/IMLStream.cs
index ccc09f45..d4dc6496 100644
--- a/src/IMLStream.cs
+++ b/src/IMLStream.cs
@@ -37,6 +37,25 @@ namespace Crow
public IMLStream(Byte[] b) : base (b){
RootType = Interface.GetTopContainerOfXMLStream (this);
}
+ /// <summary>
+ /// Create a graphicObject instance from the this XML stream.
+ /// </summary>
+ public GraphicObject Instance {
+ get {
+ Seek (0, SeekOrigin.Begin);
+ return Interface.Load (this, this.RootType);
+ }
+ }
+ /// <summary>
+ /// Gets the xml source code as a string
+ /// </summary>
+ public string Source {
+ get {
+ Seek (0, SeekOrigin.Begin);
+ using (StreamReader sr = new StreamReader(this))
+ return sr.ReadToEnd();
+ }
+ }
}
public class ItemTemplate : IMLStream {
public EventHandler Expand;
diff --git a/src/Interface.cs b/src/Interface.cs
index 99ea974b..df595275 100644
--- a/src/Interface.cs
+++ b/src/Interface.cs
@@ -218,7 +218,7 @@ namespace Crow
xs.Serialize (s, graphicObject, xn);
}
}
- public static GraphicObject Load (string path, object hostClass = null)
+ public static GraphicObject Load (string path)
{
System.Globalization.CultureInfo savedCulture = Thread.CurrentThread.CurrentCulture;
Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture;
@@ -226,7 +226,7 @@ namespace Crow
GraphicObject tmp = null;
try {
using (Stream stream = GetStreamFromPath (path)) {
- tmp = Load(stream, GetTopContainerOfXMLStream(stream), hostClass);
+ tmp = Load(stream, GetTopContainerOfXMLStream(stream));
}
} catch (Exception ex) {
throw new Exception ("Error loading <" + path + ">:", ex);
@@ -236,11 +236,7 @@ namespace Crow
return tmp;
}
- internal static GraphicObject Load (IMLStream stream, object hostClass = null){
- stream.Seek (0, SeekOrigin.Begin);
- return Load(stream, stream.RootType, hostClass);
- }
- internal static GraphicObject Load (Stream stream, Type type, object hostClass = null)
+ internal static GraphicObject Load (Stream stream, Type type)
{
#if DEBUG_LOAD
Stopwatch loadingTime = new Stopwatch ();
@@ -257,7 +253,6 @@ namespace Crow
XmlSerializer xs = new XmlSerializer (type);
result = (GraphicObject)xs.Deserialize (stream);
- //result.DataSource = hostClass;
CurrentInterface.XmlLoading = false;
#if DEBUG_LOAD
@@ -277,7 +272,7 @@ namespace Crow
public GraphicObject LoadInterface (string path)
{
lock (UpdateMutex) {
- GraphicObject tmp = Interface.Load (path, this);
+ GraphicObject tmp = Interface.Load (path);
AddWidget (tmp);
return tmp;
@@ -644,7 +639,8 @@ namespace Crow
GraphicObject g = GraphicTree[i];
if (g.MouseIsIn (e.Position)) {
g.checkHoverWidget (e);
- PutOnTop (g);
+ if (g is Window)
+ PutOnTop (g);
return true;
}
}
@@ -716,6 +712,7 @@ namespace Crow
#region Keyboard
public bool ProcessKeyDown(int Key){
+ Keyboard.SetKeyState((Crow.Key)Key,true);
if (_focusedWidget == null)
return false;
KeyboardKeyEventArgs e = new KeyboardKeyEventArgs((Crow.Key)Key, false, Keyboard);
@@ -723,9 +720,11 @@ namespace Crow
return true;
}
public bool ProcessKeyUp(int Key){
- if (_activeWidget == null)
+ Keyboard.SetKeyState((Crow.Key)Key,false);
+ if (_focusedWidget == null)
return false;
- //KeyboardKeyEventArgs e = new KeyboardKeyEventArgs((Crow.Key)Key, false, Keyboard);
+ KeyboardKeyEventArgs e = new KeyboardKeyEventArgs((Crow.Key)Key, false, Keyboard);
+ _focusedWidget.onKeyUp (this, e);
return true;
}
public bool ProcessKeyPress(char Key){