aboutsummaryrefslogtreecommitdiffstatsci
path: root/src/GraphicObjects/TemplatedControl.cs
diff options
context:
space:
mode:
authorj-p <jp.bruyere@live.be>2016-08-05 18:48:09 +0200
committerGitHub <noreply@github.com>2016-08-05 18:48:09 +0200
commitbeba8120aa8f1529d79ccf0f52f02069b02aaf4d (patch)
tree8de343d8341be621c4b5daa12899155e0bc2f26a /src/GraphicObjects/TemplatedControl.cs
parentda0cd66b6af42a3df1f35014617f1e0882ae9e63 (diff)
parentb9e90a3df66f4bd8228c1246af830d7801ea57ba (diff)
Merge pull request #15 from jpbruyere/TemplateImprovments
Template improvments
Diffstat (limited to 'src/GraphicObjects/TemplatedControl.cs')
-rw-r--r--src/GraphicObjects/TemplatedControl.cs70
1 files changed, 58 insertions, 12 deletions
diff --git a/src/GraphicObjects/TemplatedControl.cs b/src/GraphicObjects/TemplatedControl.cs
index 12c2b81f..f1c719f6 100644
--- a/src/GraphicObjects/TemplatedControl.cs
+++ b/src/GraphicObjects/TemplatedControl.cs
@@ -25,6 +25,8 @@ using System.IO;
using System.Xml;
using System.Diagnostics;
using System.Linq;
+using System.Collections.Generic;
+using System.Text;
namespace Crow
{
@@ -54,13 +56,15 @@ namespace Crow
#region CTOR
public TemplatedControl () : base()
{
- if (Interface.XmlLoaderCount > 0)
+ if (Interface.CurrentInterface.XmlLoading)
return;
loadTemplate ();
}
#endregion
string _template;
+ string _itemTemplate;
+ public Dictionary<string, ItemTemplate> ItemTemplates;
[XmlAttributeAttribute][DefaultValue(null)]
public string Template {
@@ -76,13 +80,36 @@ namespace Crow
loadTemplate (Interface.Load (_template, this));
}
}
+ [XmlAttributeAttribute][DefaultValue("#Crow.Templates.ItemTemplate.goml")]
+ public string ItemTemplate {
+ get { return _itemTemplate; }
+ set {
+ if (value == _itemTemplate)
+ return;
+
+ _itemTemplate = value;
+ //TODO:reload list with new template?
+ NotifyValueChanged("ItemTemplate", _itemTemplate);
+ }
+ }
#region GraphicObject overrides
public override GraphicObject FindByName (string nameToFind)
{
//prevent name searching in template
return nameToFind == this.Name ? this : null;
}
+ protected override void onDraw (Cairo.Context gr)
+ {
+ gr.Save ();
+ //clip to client zone
+ CairoHelpers.CairoRectangle (gr, ClientRectangle, CornerRadius);
+ gr.Clip ();
+
+ if (child != null)
+ child.Paint (ref gr);
+ gr.Restore ();
+ }
#endregion
protected virtual void loadTemplate(GraphicObject template = null)
@@ -115,12 +142,34 @@ namespace Crow
using (XmlReader xr = new XmlTextReader (tmp, XmlNodeType.Element, null)) {
//load template first if inlined
- xr.Read (); //skip current node
+ xr.Read (); //read first child
+ xr.Read (); //skip root node
+
+ while (!xr.EOF) {
+ if (!xr.IsStartElement ()) {
+ xr.Read ();
+ continue;
+ }
+ if (xr.Name == "ItemTemplate") {
+ string dataType = "default", datas = "", itemTmp;
+ while (xr.MoveToNextAttribute ()) {
+ if (xr.Name == "DataType")
+ dataType = xr.Value;
+ else if (xr.Name == "Data")
+ datas = xr.Value;
+ }
+ xr.MoveToElement ();
+ itemTmp = xr.ReadInnerXml ();
+
+ if (ItemTemplates == null)
+ ItemTemplates = new Dictionary<string, ItemTemplate> ();
+ //TODO:check encoding
+ ItemTemplates[dataType] = new ItemTemplate (Encoding.UTF8.GetBytes(itemTmp));
+ if (!string.IsNullOrEmpty (datas))
+ ItemTemplates [dataType].CreateExpandDelegate(this, dataType, datas);
- while (!xr.EOF) {
- xr.Read (); //read first child
- if (!xr.IsStartElement ())
continue;
+ }
if (xr.Name == "Template") {
xr.Read ();
@@ -129,12 +178,9 @@ namespace Crow
(go as IXmlSerializable).ReadXml (xr);
loadTemplate (go);
-
- xr.Read ();//go close tag
- xr.Read ();//Template close tag
- break;
- } else
- xr.ReadInnerXml ();
+ continue;
+ }
+ xr.ReadInnerXml ();
}
}
} else
@@ -143,7 +189,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 ();