diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/ExtensionsMethods.cs | 4 | ||||
| -rw-r--r-- | src/GraphicObjects/Button.cs | 1 | ||||
| -rw-r--r-- | src/GraphicObjects/CheckBox.cs | 24 | ||||
| -rw-r--r-- | src/GraphicObjects/ComboBox.cs | 24 | ||||
| -rw-r--r-- | src/GraphicObjects/Expandable.cs | 24 | ||||
| -rw-r--r-- | src/GraphicObjects/GraphicObject.cs | 34 | ||||
| -rw-r--r-- | src/GraphicObjects/GroupBox.cs | 26 | ||||
| -rw-r--r-- | src/GraphicObjects/Label.cs | 47 | ||||
| -rw-r--r-- | src/GraphicObjects/MessageBox.cs | 1 | ||||
| -rw-r--r-- | src/GraphicObjects/Popper.cs | 24 | ||||
| -rw-r--r-- | src/GraphicObjects/RadioButton.cs | 24 | ||||
| -rw-r--r-- | src/GraphicObjects/Slider.cs | 27 | ||||
| -rw-r--r-- | src/GraphicObjects/Spinner.cs | 1 | ||||
| -rw-r--r-- | src/GraphicObjects/Splitter.cs | 3 | ||||
| -rw-r--r-- | src/GraphicObjects/TabItem.cs | 7 | ||||
| -rw-r--r-- | src/GraphicObjects/TemplatedControl.cs | 6 | ||||
| -rw-r--r-- | src/GraphicObjects/TextBox.cs | 30 | ||||
| -rw-r--r-- | src/GraphicObjects/TextRun.cs | 2 | ||||
| -rw-r--r-- | src/GraphicObjects/Window.cs | 24 | ||||
| -rw-r--r-- | src/Interface.cs | 43 | ||||
| -rw-r--r-- | src/StyleReader.cs | 88 |
21 files changed, 391 insertions, 73 deletions
diff --git a/src/ExtensionsMethods.cs b/src/ExtensionsMethods.cs index 10aaf20a..8985c929 100644 --- a/src/ExtensionsMethods.cs +++ b/src/ExtensionsMethods.cs @@ -65,6 +65,10 @@ namespace Crow var ret = Run.DynamicInvoke(data); return ret; } + public static bool IsWhiteSpaceOrNewLine (this char c) + { + return c == '\t' || c == '\r' || c == '\n' || char.IsWhiteSpace (c); + } } } diff --git a/src/GraphicObjects/Button.cs b/src/GraphicObjects/Button.cs index 3dd10606..92238e69 100644 --- a/src/GraphicObjects/Button.cs +++ b/src/GraphicObjects/Button.cs @@ -12,7 +12,6 @@ using System.ComponentModel; namespace Crow { - [DefaultStyle("#Crow.Styles.Button.style")] [DefaultTemplate("#Crow.Templates.Button.crow")] public class Button : TemplatedContainer { diff --git a/src/GraphicObjects/CheckBox.cs b/src/GraphicObjects/CheckBox.cs index 71e686f9..f8193e24 100644 --- a/src/GraphicObjects/CheckBox.cs +++ b/src/GraphicObjects/CheckBox.cs @@ -1,10 +1,30 @@ -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 { diff --git a/src/GraphicObjects/ComboBox.cs b/src/GraphicObjects/ComboBox.cs index 8888696d..e45d20df 100644 --- a/src/GraphicObjects/ComboBox.cs +++ b/src/GraphicObjects/ComboBox.cs @@ -1,9 +1,29 @@ -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 { diff --git a/src/GraphicObjects/Expandable.cs b/src/GraphicObjects/Expandable.cs index af8b5640..d21936e8 100644 --- a/src/GraphicObjects/Expandable.cs +++ b/src/GraphicObjects/Expandable.cs @@ -1,10 +1,30 @@ -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 { diff --git a/src/GraphicObjects/GraphicObject.cs b/src/GraphicObjects/GraphicObject.cs index 2838f6cd..433599c1 100644 --- a/src/GraphicObjects/GraphicObject.cs +++ b/src/GraphicObjects/GraphicObject.cs @@ -493,12 +493,16 @@ namespace Crow #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 @@ -535,16 +539,20 @@ namespace Crow 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 diff --git a/src/GraphicObjects/GroupBox.cs b/src/GraphicObjects/GroupBox.cs index 86c659d0..886e7964 100644 --- a/src/GraphicObjects/GroupBox.cs +++ b/src/GraphicObjects/GroupBox.cs @@ -1,10 +1,30 @@ -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 { @@ -32,7 +52,7 @@ namespace Crow } #endregion - [XmlAttributeAttribute()][DefaultValue("Groupbox")] + [XmlAttributeAttribute][DefaultValue("Groupbox")] public string Caption { get { return caption; } set { diff --git a/src/GraphicObjects/Label.cs b/src/GraphicObjects/Label.cs index 22a60aa0..e1bf02a7 100644 --- a/src/GraphicObjects/Label.cs +++ b/src/GraphicObjects/Label.cs @@ -1,7 +1,27 @@ -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; @@ -10,7 +30,6 @@ using System.ComponentModel; namespace Crow { - [DefaultStyle("#Crow.Styles.Label.style")] public class Label : GraphicObject { #region CTOR @@ -52,7 +71,7 @@ namespace Crow protected TextExtents te; #endregion - [XmlAttributeAttribute()][DefaultValue("SteelBlue")] + [XmlAttributeAttribute][DefaultValue("SteelBlue")] public virtual Color SelectionBackground { get { return selColor; } set { @@ -63,7 +82,7 @@ namespace Crow RegisterForGraphicUpdate (); } } - [XmlAttributeAttribute()][DefaultValue("White")] + [XmlAttributeAttribute][DefaultValue("White")] public virtual Color SelectionForeground { get { return selFontColor; } set { @@ -74,7 +93,7 @@ namespace Crow RegisterForGraphicUpdate (); } } - [XmlAttributeAttribute()][DefaultValue(Alignment.Left)] + [XmlAttributeAttribute][DefaultValue(Alignment.Left)] public Alignment TextAlignment { get { return _textAlignment; } @@ -87,7 +106,7 @@ namespace Crow NotifyValueChanged ("TextAlignment", _textAlignment); } } - [XmlAttributeAttribute()][DefaultValue(false)] + [XmlAttributeAttribute][DefaultValue(false)] public virtual bool HorizontalStretch { get { return horizontalStretch; } set { @@ -98,7 +117,7 @@ namespace Crow NotifyValueChanged ("HorizontalStretch", horizontalStretch); } } - [XmlAttributeAttribute()][DefaultValue(false)] + [XmlAttributeAttribute][DefaultValue(false)] public virtual bool VerticalStretch { get { return verticalStretch; } set { @@ -109,7 +128,7 @@ namespace Crow } } - [XmlAttributeAttribute()][DefaultValue("label")] + [XmlAttributeAttribute][DefaultValue("label")] public string Text { get { @@ -133,7 +152,7 @@ namespace Crow NotifyValueChanged ("Text", _text); } } - [XmlAttributeAttribute()][DefaultValue(false)] + [XmlAttributeAttribute][DefaultValue(false)] public bool Multiline { get { return _multiline; } @@ -146,7 +165,7 @@ namespace Crow RegisterForGraphicUpdate(); } } - [XmlAttributeAttribute()][DefaultValue(0)] + [XmlAttributeAttribute][DefaultValue(0)] public int CurrentColumn{ get { return _currentCol; } set { @@ -161,7 +180,7 @@ namespace Crow NotifyValueChanged ("CurrentColumn", _currentCol); } } - [XmlAttributeAttribute()][DefaultValue(0)] + [XmlAttributeAttribute][DefaultValue(0)] public int CurrentLine{ get { return _currentLine; } set { @@ -181,7 +200,7 @@ namespace Crow } } //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; @@ -194,7 +213,7 @@ namespace Crow NotifyValueChanged ("SelectedText", SelectedText); } } - [XmlAttributeAttribute()][DefaultValue("-1")] + [XmlAttributeAttribute][DefaultValue("-1")] public Point SelRelease { get { return _selRelease; diff --git a/src/GraphicObjects/MessageBox.cs b/src/GraphicObjects/MessageBox.cs index 2114262e..550f5b72 100644 --- a/src/GraphicObjects/MessageBox.cs +++ b/src/GraphicObjects/MessageBox.cs @@ -23,7 +23,6 @@ using System.ComponentModel; namespace Crow { - [DefaultStyle("#Crow.Styles.MessageBox.style")] [DefaultTemplate("#Crow.Templates.MessageBox.goml")] public class MessageBox : Window { diff --git a/src/GraphicObjects/Popper.cs b/src/GraphicObjects/Popper.cs index 5e5541fe..14e7ec7a 100644 --- a/src/GraphicObjects/Popper.cs +++ b/src/GraphicObjects/Popper.cs @@ -1,11 +1,31 @@ -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 { diff --git a/src/GraphicObjects/RadioButton.cs b/src/GraphicObjects/RadioButton.cs index a6248706..ffd5ba27 100644 --- a/src/GraphicObjects/RadioButton.cs +++ b/src/GraphicObjects/RadioButton.cs @@ -1,10 +1,30 @@ -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 { diff --git a/src/GraphicObjects/Slider.cs b/src/GraphicObjects/Slider.cs index 3b2cebf4..bce74971 100644 --- a/src/GraphicObjects/Slider.cs +++ b/src/GraphicObjects/Slider.cs @@ -1,7 +1,25 @@ -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; @@ -9,7 +27,6 @@ using System.Diagnostics; namespace Crow { - [DefaultStyle ("#Crow.Styles.Slider.style")] public class Slider : NumericControl { #region CTOR diff --git a/src/GraphicObjects/Spinner.cs b/src/GraphicObjects/Spinner.cs index 9447f205..1a8674d0 100644 --- a/src/GraphicObjects/Spinner.cs +++ b/src/GraphicObjects/Spinner.cs @@ -22,7 +22,6 @@ using System; namespace Crow { - [DefaultStyle("#Crow.Styles.Spinner.style")] [DefaultTemplate("#Crow.Templates.Spinner.goml")] public class Spinner : NumericControl { diff --git a/src/GraphicObjects/Splitter.cs b/src/GraphicObjects/Splitter.cs index 248863b5..f3321065 100644 --- a/src/GraphicObjects/Splitter.cs +++ b/src/GraphicObjects/Splitter.cs @@ -24,7 +24,6 @@ using System.ComponentModel; namespace Crow { - [DefaultStyle("#Crow.Styles.Splitter.style")] public class Splitter : GraphicObject { #region CTOR @@ -33,7 +32,7 @@ namespace Crow int thickness; - [XmlAttributeAttribute()][DefaultValue(1)] + [XmlAttributeAttribute][DefaultValue(1)] public virtual int Thickness { get { return thickness; } set { diff --git a/src/GraphicObjects/TabItem.cs b/src/GraphicObjects/TabItem.cs index 38d56c5d..2d2ba453 100644 --- a/src/GraphicObjects/TabItem.cs +++ b/src/GraphicObjects/TabItem.cs @@ -25,7 +25,6 @@ using System.Diagnostics; namespace Crow { - [DefaultStyle ("#Crow.Styles.TabItem.style")] [DefaultTemplate("#Crow.Templates.TabItem.crow")] public class TabItem : TemplatedContainer { @@ -67,7 +66,7 @@ namespace Crow internal GraphicObject TabTitle { get { return _tabTitle; }} #endregion - [XmlAttributeAttribute()][DefaultValue(0)] + [XmlAttributeAttribute][DefaultValue(0)] public virtual int TabOffset { get { return tabOffset; } set { @@ -80,7 +79,7 @@ namespace Crow RegisterForGraphicUpdate (); } } - [XmlAttributeAttribute()][DefaultValue("TabItem")] + [XmlAttributeAttribute][DefaultValue("TabItem")] public string Caption { get { return caption; } set { @@ -91,7 +90,7 @@ namespace Crow } } bool isSelected; - [XmlAttributeAttribute()][DefaultValue(false)] + [XmlAttributeAttribute][DefaultValue(false)] public virtual bool IsSelected { get { return isSelected; } set { diff --git a/src/GraphicObjects/TemplatedControl.cs b/src/GraphicObjects/TemplatedControl.cs index c8ec2d9e..12c2b81f 100644 --- a/src/GraphicObjects/TemplatedControl.cs +++ b/src/GraphicObjects/TemplatedControl.cs @@ -37,11 +37,7 @@ namespace Crow Path = path; } } - [AttributeUsage(AttributeTargets.Class)] - public class DefaultStyle : TemplateAttribute - { - public DefaultStyle(string path) : base(path){} - } + [AttributeUsage(AttributeTargets.Class)] public class DefaultTemplate : TemplateAttribute { diff --git a/src/GraphicObjects/TextBox.cs b/src/GraphicObjects/TextBox.cs index 7d61d5ab..fc02f0d6 100644 --- a/src/GraphicObjects/TextBox.cs +++ b/src/GraphicObjects/TextBox.cs @@ -1,17 +1,31 @@ -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 diff --git a/src/GraphicObjects/TextRun.cs b/src/GraphicObjects/TextRun.cs index 103f2fcf..c644767c 100644 --- a/src/GraphicObjects/TextRun.cs +++ b/src/GraphicObjects/TextRun.cs @@ -10,8 +10,6 @@ using System.ComponentModel; namespace Crow { - [Serializable] - [DefaultStyle("#Crow.Styles.TextRun.style")] public class TextRun : GraphicObject { #region CTOR diff --git a/src/GraphicObjects/Window.cs b/src/GraphicObjects/Window.cs index afb4f4f2..cbdbbb2c 100644 --- a/src/GraphicObjects/Window.cs +++ b/src/GraphicObjects/Window.cs @@ -1,11 +1,31 @@ -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 { diff --git a/src/Interface.cs b/src/Interface.cs index b8426e6f..d8f66443 100644 --- a/src/Interface.cs +++ b/src/Interface.cs @@ -22,6 +22,7 @@ using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; +using System.Linq; using System.Reflection; using System.Threading; using System.Xml; @@ -54,6 +55,7 @@ namespace Crow public Interface(){ LayoutingQueue = new Queue<LayoutingQueueItem>(); Interface.CurrentInterface = this; + LoadStyling (); } #endregion @@ -259,7 +261,48 @@ namespace Crow 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 diff --git a/src/StyleReader.cs b/src/StyleReader.cs index d99a1377..c1cc28bf 100644 --- a/src/StyleReader.cs +++ b/src/StyleReader.cs @@ -19,12 +19,96 @@ // 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; + } + } } } } |