aboutsummaryrefslogtreecommitdiffstatsci
path: root/src/GraphicObjects/ListBox.cs
diff options
context:
space:
mode:
authorjpbruyere <jp.bruyere@hotmail.com>2015-09-17 18:30:01 +0200
committerjpbruyere <jp.bruyere@hotmail.com>2015-09-17 18:30:01 +0200
commit41b76ea576cdece6c5a2f1feb936dfb4a2a9854a (patch)
tree42c16725f61d0cfb1fef4c1016f3c0a15f130d3f /src/GraphicObjects/ListBox.cs
parent3aba832ca7c6f9da0e9be8f5060013a2bbc6d345 (diff)
Combobox
Diffstat (limited to 'src/GraphicObjects/ListBox.cs')
-rw-r--r--src/GraphicObjects/ListBox.cs94
1 files changed, 80 insertions, 14 deletions
diff --git a/src/GraphicObjects/ListBox.cs b/src/GraphicObjects/ListBox.cs
index a73791c8..4222bc50 100644
--- a/src/GraphicObjects/ListBox.cs
+++ b/src/GraphicObjects/ListBox.cs
@@ -25,19 +25,25 @@ using System.ComponentModel;
//TODO: implement ItemTemplate node in xml
using System.IO;
using System.Diagnostics;
+using System.Xml;
namespace go
{
[DefaultTemplate("#go.Templates.Listbox.goml")]
//[DefaultTemplate("#go.Templates.ItemTemplate.goml")]
- public class ListBox : TemplatedControl
+ public class ListBox : TemplatedControl, IXmlSerializable
{
+ #region CTOR
+ public ListBox () : base() {}
+ #endregion
+
Group _list;
+ IList data;
+ int _selectedIndex;
+ string _itemTemplate;
- public ListBox () : base()
- {
- }
+ public event EventHandler<SelectionChangeEventArgs> SelectedItemChanged;
#region implemented abstract members of TemplatedControl
protected override void loadTemplate (GraphicObject template = null)
@@ -47,21 +53,21 @@ namespace go
}
#endregion
- IList data;
- int _selectedIndex;
- string _itemTemplate;
-
[XmlAttributeAttribute][DefaultValue("#go.Templates.ItemTemplate.goml")]
public string ItemTemplate {
get { return _itemTemplate; }
- set { _itemTemplate = value; }
+ set {
+ //TODO:reload list with new template?
+ _itemTemplate = value;
+ }
}
+ [XmlAttributeAttribute][DefaultValue(-1)]
public int SelectedIndex{
get { return _selectedIndex; }
set { _selectedIndex = value; }
}
public object SelectedItem{
- get { return data[_selectedIndex]; }
+ get { return data == null ? null : data[_selectedIndex]; }
}
[XmlAttributeAttribute][DefaultValue(null)]
public IList Data {
@@ -85,10 +91,8 @@ namespace go
#endif
MemoryStream ms = new MemoryStream ();
- using (Stream stream = Interface.GetStreamFromPath (ItemTemplate)) {
-
+ using (Stream stream = Interface.GetStreamFromPath (ItemTemplate))
stream.CopyTo (ms);
- }
Type t = Interface.GetTopContainerOfGOMLStream (ms);
@@ -97,8 +101,8 @@ namespace go
GraphicObject g = Interface.Load (ms, t, item);
g.MouseClick += itemClick;
_list.addChild(g);
-
}
+
ms.Dispose ();
#if DEBUG
@@ -109,10 +113,72 @@ namespace go
#endif
}
}
+
void itemClick(object sender, OpenTK.Input.MouseButtonEventArgs e){
+ SelectedItemChanged.Raise (sender, new SelectionChangeEventArgs((sender as GraphicObject).DataSource));
NotifyValueChanged ("SelectedItem", (sender as GraphicObject).DataSource);
//Debug.WriteLine ((sender as GraphicObject).DataSource);
}
+
+ #region IXmlSerializable
+ public override System.Xml.Schema.XmlSchema GetSchema(){ return null; }
+ public override void ReadXml(System.Xml.XmlReader reader)
+ {
+ //Template could be either an attribute containing path or expressed inlined
+ //as a Template Element
+ using (System.Xml.XmlReader subTree = reader.ReadSubtree())
+ {
+ subTree.Read ();
+
+ string template = reader.GetAttribute ("Template");
+ string tmp = subTree.ReadOuterXml ();
+
+ //Load template from path set as attribute in templated control
+ if (string.IsNullOrEmpty (template)) {
+ //seek for template tag first
+ using (XmlReader xr = new XmlTextReader (tmp, XmlNodeType.Element, null)) {
+ //load template first if inlined
+
+ xr.Read (); //skip current node
+
+ while (!xr.EOF) {
+ xr.Read (); //read first child
+ if (!xr.IsStartElement ())
+ continue;
+ if (xr.Name == "Template") {
+ xr.Read ();
+
+ Type t = Type.GetType ("go." + xr.Name);
+ GraphicObject go = (GraphicObject)Activator.CreateInstance (t);
+ (go as IXmlSerializable).ReadXml (xr);
+
+ loadTemplate (go);
+
+ xr.Read ();//go close tag
+ xr.Read ();//Template close tag
+ break;
+ } else {
+ xr.ReadInnerXml ();
+ }
+ }
+ }
+ } else
+ loadTemplate (Interface.Load (template, this, !Interface.DontResoveGOML));
+
+
+ //normal xml read
+ using (XmlReader xr = new XmlTextReader (tmp, XmlNodeType.Element, null)) {
+ xr.Read ();
+ base.ReadXml(xr);
+ }
+ }
+ }
+ public override void WriteXml(System.Xml.XmlWriter writer)
+ {
+ //TODO:
+ throw new NotImplementedException();
+ }
+ #endregion
}
}