<Compile Include="src\CompilerServices\Bindings.cs">
<LogicalName></LogicalName>
</Compile>
+ <Compile Include="src\StyleReader.cs" />
</ItemGroup>
<ItemGroup>
<Reference Include="System" />
-Focusable = true
-Fit = true
+Focusable = true;
+Fit = true;
-Focusable = true
-Height=Fit
+Focusable = true;
+Height=Fit;
-Focusable = true
-Height = Fit
+Focusable = true;
+Height = Fit;
-Focusable = true
-Height = Fit
+Focusable = true;
+Height = Fit;
-Fit = true
+Fit = true;
-Width=200
-Height=Fit
-Title=MessageBox
-Focusable=true
-MinimumSize=150;80
+Width=200;
+Height=Fit;
+Title=MessageBox;
+Focusable=true;
+MinimumSize=150;80;
-Focusable = true
-Height = Fit
+Focusable = true;
+Height = Fit;
-Focusable = true
-Height = Fit
+Focusable = true;
+Height = Fit;
-Background = vgradient|0:Black|0,1:Gray|0,9:Gray|1:LightGray
-Foreground = Gray
-Focusable = true
-Fit = true
+Background = vgradient|0:Black|0,1:Gray|0,9:Gray|1:LightGray;
+Foreground = Gray;
+Focusable = true;
+Fit = true;
-Focusable = true
-Height = Fit
+Focusable = true;
+Height = Fit;
-Focusable = true
-Background = DimGray
+Focusable = true;
+Background = DimGray;
-Focusable = true
-CacheEnabled = false
+Focusable = true;
+CacheEnabled = false;
-Fit = true
-Focusable = true
-Background = White
-Foreground = Black
+Fit = true;
+Focusable = true;
+Background = White;
+Foreground = Black;
-Fit = true
-Margin = 2
+Fit = true;
+Margin = 2;
-Focusable=true
-MinimumSize=50;50
-Fit=true
+Focusable=true;
+MinimumSize=50;50;
+Fit=true;
testFiles = new string [] { @"Interfaces/Divers/welcome.crow" };
+ testFiles = testFiles.Concat (Directory.GetFiles (@"Interfaces/Divers", "*.crow")).ToArray ();
testFiles = testFiles.Concat (Directory.GetFiles (@"Interfaces/GraphicObject", "*.crow")).ToArray ();
//testFiles = testFiles.Concat (Directory.GetFiles (@"Interfaces/basicTests", "*.crow")).ToArray ();
testFiles = testFiles.Concat (Directory.GetFiles (@"Interfaces/Container", "*.crow")).ToArray ();
testFiles = testFiles.Concat (Directory.GetFiles (@"Interfaces/Stack", "*.crow")).ToArray ();
testFiles = testFiles.Concat (Directory.GetFiles (@"Interfaces/Splitter", "*.crow")).ToArray ();
testFiles = testFiles.Concat (Directory.GetFiles (@"Interfaces/Expandable", "*.crow")).ToArray ();
- testFiles = testFiles.Concat (Directory.GetFiles (@"Interfaces/Divers", "*.crow")).ToArray ();
this.Title = testFiles [idx] + ". Press key to switch example.";
CrowInterface.LoadInterface(testFiles[idx]).DataSource = this;
<?xml version="1.0"?>
<VerticalStack Fit="true">
+ <TextBox Font="droid, 20" Text="test text box" Width="Stretched"/>
<HorizontalStack Margin="5" Fit="true" MouseEnter="{Background=White}" MouseLeave="{Background=Transparent}">
<Label Text="centered" Width="80" Height="30" Background="DarkBlue" TextAlignment="Center"/>
<Label Text="top left" Width="80" Height="30" Background="DarkBlue" TextAlignment="TopLeft"/>
-MouseEnter = {Background = Gray;Foreground = White}
-Fit = true
-MouseLeave = {Background=Transparent;Foreground=Gray}
-MouseDown = {Background=Red;Foreground=White}
-MouseUp = {Background=Gray;Foreground=White}
-Foreground=Gray
-Margin=5
-CornerRadius=5
+MouseEnter = {Background = Gray;Foreground = White;}
+Fit = true;
+MouseLeave = {Background=Transparent;Foreground=Gray;}
+MouseDown = {Background=Red;Foreground=White;}
+MouseUp = {Background=Gray;Foreground=White;}
+Foreground=Gray;
+Margin=5;
+CornerRadius=5;
-Height = Fit
-Width = Stretched
-MinimumSize=60;10
-Margin=2
-CornerRadius=0
-TextAlignment=Left
-Foreground=Gray
-MouseEnter = {Background=SeaGreen;Foreground=White}
-MouseLeave = {Background=Transparent;Foreground=Gray}
-MouseDown = {Background=White;Foreground=DimGray}
-MouseUp = {Background=SeaGreen;Foreground=White}
+Height = Fit;
+Width = Stretched;
+MinimumSize=60;10;
+Margin=2;
+CornerRadius=0;
+TextAlignment=Left;
+Foreground=Gray;
+MouseEnter = {Background=SeaGreen;Foreground=White;}
+MouseLeave = {Background=Transparent;Foreground=Gray;}
+MouseDown = {Background=White;Foreground=DimGray;}
+MouseUp = {Background=SeaGreen;Foreground=White;}
var ret = Run.DynamicInvoke(data);
return ret;
}
+ public static bool IsWhiteSpaceOrNewLine (this char c)
+ {
+ return c == '\t' || c == '\r' || c == '\n' || char.IsWhiteSpace (c);
+ }
}
}
namespace Crow
{
- [DefaultStyle("#Crow.Styles.Button.style")]
[DefaultTemplate("#Crow.Templates.Button.crow")]
public class Button : TemplatedContainer
{
-using System;
+//
+// CheckBox.cs
+//
+// Author:
+// Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
+//
+// Copyright (c) 2016 jp
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+using System;
using System.ComponentModel;
using System.Xml.Serialization;
namespace Crow
{
- [DefaultStyle("#Crow.Styles.CheckBox.style")]
[DefaultTemplate("#Crow.Templates.CheckBox.goml")]
public class CheckBox : TemplatedControl
{
-using System;
+//
+// ComboBox.cs
+//
+// Author:
+// Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
+//
+// Copyright (c) 2016 jp
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+using System;
using System.Xml.Serialization;
namespace Crow
{
- [DefaultStyle("#Crow.Styles.ComboBox.style")]
[DefaultTemplate("#Crow.Templates.ComboBox.goml")]
public class ComboBox : ListBox
{
-using System;
+//
+// Expandable.cs
+//
+// Author:
+// Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
+//
+// Copyright (c) 2016 jp
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+using System;
using System.ComponentModel;
using System.Xml.Serialization;
namespace Crow
{
- [DefaultStyle("#Crow.Styles.Expandable.style")]
[DefaultTemplate("#Crow.Templates.Expandable.goml")]
public class Expandable : TemplatedContainer
{
#endif
Type thisType = this.GetType ();
- if (Interface.DefaultValuesLoader.ContainsKey(thisType.FullName)) {
- Interface.DefaultValuesLoader[thisType.FullName] (this);
- applyStyle ();
+ if (Interface.DefaultValuesLoader.ContainsKey (thisType.FullName)) {
+ Interface.DefaultValuesLoader [thisType.FullName] (this);
return;
}
+ Dictionary<string, string> styling = null;
+
+ if (Interface.CurrentInterface.Styling.ContainsKey (thisType.Name))
+ styling = Interface.CurrentInterface.Styling[thisType.Name];
+
//Reflexion being very slow compared to dyn method or delegates,
//I compile the initial values coded in the CustomAttribs of the class,
//all other instance of this type would not longer use reflexion to init properly
else
name = xaa.AttributeName;
}
- if (name == "Style"){
- //retrieve default value from class attribute
- DefaultStyle defStyle = thisType.GetCustomAttribute<DefaultStyle>();
- if (defStyle != null)
- defaultValue = defStyle.Path;
- }else{
- DefaultValueAttribute dv = (DefaultValueAttribute)pi.GetCustomAttribute (typeof(DefaultValueAttribute));
- if (dv == null)
- continue;
- defaultValue = dv.Value;
+ if (styling.ContainsKey (name)) {
+
+ } else {
+ if (name == "Style") {
+ //retrieve default value from class attribute
+ //DefaultStyle defStyle = thisType.GetCustomAttribute<DefaultStyle>();
+ //if (defStyle != null)
+ // defaultValue = defStyle.Path;
+ } else {
+ DefaultValueAttribute dv = (DefaultValueAttribute)pi.GetCustomAttribute (typeof (DefaultValueAttribute));
+ if (dv == null)
+ continue;
+ defaultValue = dv.Value;
+ }
}
#endregion
-using System;
+//
+// GroupBox.cs
+//
+// Author:
+// Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
+//
+// Copyright (c) 2016 jp
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+using System;
using System.Xml.Serialization;
using System.ComponentModel;
namespace Crow
{
- [DefaultStyle("#Crow.Styles.GroupBox.style")]
[DefaultTemplate("#Crow.Templates.GroupBox.goml")]
public class GroupBox : TemplatedContainer
{
}
#endregion
- [XmlAttributeAttribute()][DefaultValue("Groupbox")]
+ [XmlAttributeAttribute][DefaultValue("Groupbox")]
public string Caption {
get { return caption; }
set {
-using System;
+//
+// Label.cs
+//
+// Author:
+// Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
+//
+// Copyright (c) 2016 jp
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+using System;
using System.Collections.Generic;
using System.Linq;
-using System.Text;
using System.Diagnostics;
using Cairo;
using System.Text.RegularExpressions;
namespace Crow
{
- [DefaultStyle("#Crow.Styles.Label.style")]
public class Label : GraphicObject
{
#region CTOR
protected TextExtents te;
#endregion
- [XmlAttributeAttribute()][DefaultValue("SteelBlue")]
+ [XmlAttributeAttribute][DefaultValue("SteelBlue")]
public virtual Color SelectionBackground {
get { return selColor; }
set {
RegisterForGraphicUpdate ();
}
}
- [XmlAttributeAttribute()][DefaultValue("White")]
+ [XmlAttributeAttribute][DefaultValue("White")]
public virtual Color SelectionForeground {
get { return selFontColor; }
set {
RegisterForGraphicUpdate ();
}
}
- [XmlAttributeAttribute()][DefaultValue(Alignment.Left)]
+ [XmlAttributeAttribute][DefaultValue(Alignment.Left)]
public Alignment TextAlignment
{
get { return _textAlignment; }
NotifyValueChanged ("TextAlignment", _textAlignment);
}
}
- [XmlAttributeAttribute()][DefaultValue(false)]
+ [XmlAttributeAttribute][DefaultValue(false)]
public virtual bool HorizontalStretch {
get { return horizontalStretch; }
set {
NotifyValueChanged ("HorizontalStretch", horizontalStretch);
}
}
- [XmlAttributeAttribute()][DefaultValue(false)]
+ [XmlAttributeAttribute][DefaultValue(false)]
public virtual bool VerticalStretch {
get { return verticalStretch; }
set {
}
}
- [XmlAttributeAttribute()][DefaultValue("label")]
+ [XmlAttributeAttribute][DefaultValue("label")]
public string Text
{
get {
NotifyValueChanged ("Text", _text);
}
}
- [XmlAttributeAttribute()][DefaultValue(false)]
+ [XmlAttributeAttribute][DefaultValue(false)]
public bool Multiline
{
get { return _multiline; }
RegisterForGraphicUpdate();
}
}
- [XmlAttributeAttribute()][DefaultValue(0)]
+ [XmlAttributeAttribute][DefaultValue(0)]
public int CurrentColumn{
get { return _currentCol; }
set {
NotifyValueChanged ("CurrentColumn", _currentCol);
}
}
- [XmlAttributeAttribute()][DefaultValue(0)]
+ [XmlAttributeAttribute][DefaultValue(0)]
public int CurrentLine{
get { return _currentLine; }
set {
}
}
//TODO:using HasFocus for drawing selection cause SelBegin and Release binding not to work
- [XmlAttributeAttribute()][DefaultValue("-1")]
+ [XmlAttributeAttribute][DefaultValue("-1")]
public Point SelBegin {
get {
return _selBegin;
NotifyValueChanged ("SelectedText", SelectedText);
}
}
- [XmlAttributeAttribute()][DefaultValue("-1")]
+ [XmlAttributeAttribute][DefaultValue("-1")]
public Point SelRelease {
get {
return _selRelease;
namespace Crow
{
- [DefaultStyle("#Crow.Styles.MessageBox.style")]
[DefaultTemplate("#Crow.Templates.MessageBox.goml")]
public class MessageBox : Window
{
-using System;
+//
+// Popper.cs
+//
+// Author:
+// Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
+//
+// Copyright (c) 2016 jp
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+using System;
using System.Xml.Serialization;
using System.ComponentModel;
using OpenTK.Input;
namespace Crow
{
- [DefaultStyle("#Crow.Styles.Popper.style")]
[DefaultTemplate("#Crow.Templates.Popper.goml")]
public class Popper : TemplatedContainer
{
-using System;
+//
+// RadioButton.cs
+//
+// Author:
+// Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
+//
+// Copyright (c) 2016 jp
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+using System;
using System.ComponentModel;
using System.Xml.Serialization;
namespace Crow
{
- [DefaultStyle("#Crow.Styles.RadioButton.style")]
[DefaultTemplate("#Crow.Templates.RadioButton.goml")]
public class RadioButton : TemplatedControl
{
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
+//
+// Slider.cs
+//
+// Author:
+// Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
+//
+// Copyright (c) 2016 jp
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+using System;
using Cairo;
using System.Xml.Serialization;
using System.ComponentModel;
namespace Crow
{
- [DefaultStyle ("#Crow.Styles.Slider.style")]
public class Slider : NumericControl
{
#region CTOR
namespace Crow
{
- [DefaultStyle("#Crow.Styles.Spinner.style")]
[DefaultTemplate("#Crow.Templates.Spinner.goml")]
public class Spinner : NumericControl
{
namespace Crow
{
- [DefaultStyle("#Crow.Styles.Splitter.style")]
public class Splitter : GraphicObject
{
#region CTOR
int thickness;
- [XmlAttributeAttribute()][DefaultValue(1)]
+ [XmlAttributeAttribute][DefaultValue(1)]
public virtual int Thickness {
get { return thickness; }
set {
namespace Crow
{
- [DefaultStyle ("#Crow.Styles.TabItem.style")]
[DefaultTemplate("#Crow.Templates.TabItem.crow")]
public class TabItem : TemplatedContainer
{
internal GraphicObject TabTitle { get { return _tabTitle; }}
#endregion
- [XmlAttributeAttribute()][DefaultValue(0)]
+ [XmlAttributeAttribute][DefaultValue(0)]
public virtual int TabOffset {
get { return tabOffset; }
set {
RegisterForGraphicUpdate ();
}
}
- [XmlAttributeAttribute()][DefaultValue("TabItem")]
+ [XmlAttributeAttribute][DefaultValue("TabItem")]
public string Caption {
get { return caption; }
set {
}
}
bool isSelected;
- [XmlAttributeAttribute()][DefaultValue(false)]
+ [XmlAttributeAttribute][DefaultValue(false)]
public virtual bool IsSelected {
get { return isSelected; }
set {
Path = path;
}
}
- [AttributeUsage(AttributeTargets.Class)]
- public class DefaultStyle : TemplateAttribute
- {
- public DefaultStyle(string path) : base(path){}
- }
+
[AttributeUsage(AttributeTargets.Class)]
public class DefaultTemplate : TemplateAttribute
{
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
+//
+// TextBox.cs
+//
+// Author:
+// Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
+//
+// Copyright (c) 2016 jp
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+using System;
using Cairo;
using System.Diagnostics;
using System.Xml.Serialization;
-using System.Globalization;
-using System.ComponentModel;
-using System.Runtime.InteropServices;
namespace Crow
{
- [DefaultStyle("#Crow.Styles.TextBox.style")]
public class TextBox : Label
{
#region CTOR
namespace Crow
{
- [Serializable]
- [DefaultStyle("#Crow.Styles.TextRun.style")]
public class TextRun : GraphicObject
{
#region CTOR
-using System;
+//
+// Window.cs
+//
+// Author:
+// Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
+//
+// Copyright (c) 2016 jp
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+using System;
using System.Xml.Serialization;
using System.ComponentModel;
using System.Diagnostics;
namespace Crow
{
- [DefaultStyle("#Crow.Styles.Window.style")]
[DefaultTemplate("#Crow.Templates.Window.goml")]
public class Window : TemplatedContainer
{
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
+using System.Linq;
using System.Reflection;
using System.Threading;
using System.Xml;
public Interface(){
LayoutingQueue = new Queue<LayoutingQueueItem>();
Interface.CurrentInterface = this;
+ LoadStyling ();
}
#endregion
return tmp;
}
}
+ public Dictionary<string, Dictionary<string, string>> Styling;
+ public void LoadStyling() {
+ Styling = new Dictionary<string, Dictionary<string, string>> ();
+
+ //fetch styling info in this order, if member styling is alreadey referenced in previous
+ //assembly, it's ignored
+ loadStylingFromAssembly (Assembly.GetEntryAssembly ());
+ loadStylingFromAssembly (Assembly.GetExecutingAssembly ());
+ }
+
+ void loadStylingFromAssembly (Assembly assembly) {
+ foreach (string s in assembly
+ .GetManifestResourceNames ()
+ .Where (r => r.EndsWith (".style", StringComparison.OrdinalIgnoreCase))) {
+
+ StyleReader sr = new StyleReader (assembly, s);
+
+ }
+ }
+
+ //public static bool TryGetStyle (Type crowType, out Stream stream) {
+ // string styleId = crowType.Name + ".style";
+
+ // if (tryGetStyle (Assembly.GetEntryAssembly (), styleId, out stream))
+ // return true;
+ // if (tryGetStyle (Assembly.GetExecutingAssembly (), styleId, out stream))
+ // return true;
+ // return false;
+ //}
+
+ //static bool tryGetStyle (Assembly assembly, string styleId, out Stream stream) {
+ // try {
+ // stream = assembly.GetManifestResourceStream (
+ // assembly.GetManifestResourceNames ().FirstOrDefault (r => r.EndsWith
+ // (styleId, StringComparison.OrdinalIgnoreCase)));
+ // } catch {
+ // stream = null;
+ // return false;
+ // }
+ // return true;
+ //}
#endregion
#if MEASURE_TIME
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Reflection;
+
namespace Crow
{
- public class StyleReader
+ public class StyleReader : StreamReader
{
- public StyleReader ()
+ enum readerState { classNames, propertyName, expression }
+ readerState state = readerState.classNames;
+
+
+ public StyleReader (Assembly assembly, string resId)
+ : base(assembly.GetManifestResourceStream (resId))
{
+ Interface iface = Interface.CurrentInterface;
+ string classNameFromResId = resId.Substring (0, resId.Length - 6);
+ string token = "";
+ List<string> targetsClasses = new List<string> ();
+ string currentProperty = "";
+
+ while (!EndOfStream) {
+ char c = (Char)Read ();
+
+ switch (state) {
+ case readerState.classNames:
+ if (c.IsWhiteSpaceOrNewLine () || c == ',' || c == '{') {
+ if (!string.IsNullOrEmpty (token))
+ targetsClasses.Add (token);
+ if (c == '{')
+ state = readerState.propertyName;
+ token = "";
+ }else if (c=='='){
+ //this file contains only properties,
+ //resource Id (minus .style extention) will determine the single target class
+ if (targetsClasses.Count > 1)
+ throw new Exception ("Unexpected token '='");
+ else if (targetsClasses.Count == 1) {
+ if (!string.IsNullOrEmpty (token))
+ throw new Exception ("Unexpected token '='");
+ currentProperty = targetsClasses [0];
+ targetsClasses [0] = classNameFromResId;
+ }else{
+ if (string.IsNullOrEmpty (token))
+ throw new Exception ("Unexpected token '='");
+ targetsClasses.Add (classNameFromResId);
+ currentProperty = token;
+ token = "";
+ }
+ state = readerState.expression;
+ }else
+ token += c;
+ break;
+ case readerState.propertyName:
+ if (c.IsWhiteSpaceOrNewLine () || c == '=') {
+ if (!string.IsNullOrEmpty (token))
+ currentProperty = token;
+ if (c == '=')
+ state = readerState.expression;
+
+ token = "";
+ }else if (c == '}'){
+ if (!string.IsNullOrEmpty (token))
+ throw new Exception ("Unexpected token '" + c + "'");
+ targetsClasses = new List<string> ();
+ currentProperty = "";
+ state = readerState.classNames;
+ } else
+ token += c;
+ break;
+ case readerState.expression:
+ if (c == ';') {
+ if (!string.IsNullOrEmpty (token)) {
+ string expression = token.Trim ();
+
+ foreach (string tc in targetsClasses) {
+ if (!iface.Styling.ContainsKey (tc))
+ iface.Styling [tc] = new Dictionary<string, string> ();
+ else if (iface.Styling [tc].ContainsKey (currentProperty))
+ continue;
+ iface.Styling [tc] [currentProperty] = expression;
+ }
+ token = "";
+ }
+ state = readerState.propertyName;
+ } else
+ token += c;
+ break;
+ }
+ }
}
}
}