]> O.S.I.I.S - jp/crow.git/commitdiff
remove style attributes, add ';' to style files line ending, new style parser
authorjpbruyere <jp.bruyere@hotmail.com>
Sat, 30 Jul 2016 08:00:02 +0000 (10:00 +0200)
committerjpbruyere <jp.bruyere@hotmail.com>
Sat, 30 Jul 2016 08:00:02 +0000 (10:00 +0200)
41 files changed:
Crow.csproj
Styles/Button.style
Styles/CheckBox.style
Styles/ComboBox.style
Styles/Expandable.style
Styles/Label.style
Styles/MessageBox.style
Styles/Popper.style
Styles/RadioButton.style
Styles/Slider.style
Styles/Spinner.style
Styles/Splitter.style
Styles/TabItem.style
Styles/TextBox.style
Styles/TextRun.style
Styles/Window.style
Tests/BasicTests.cs
Tests/Interfaces/Divers/2.crow
Tests/ui/LabelButton.style
Tests/ui/MenuItem.style
src/ExtensionsMethods.cs
src/GraphicObjects/Button.cs
src/GraphicObjects/CheckBox.cs
src/GraphicObjects/ComboBox.cs
src/GraphicObjects/Expandable.cs
src/GraphicObjects/GraphicObject.cs
src/GraphicObjects/GroupBox.cs
src/GraphicObjects/Label.cs
src/GraphicObjects/MessageBox.cs
src/GraphicObjects/Popper.cs
src/GraphicObjects/RadioButton.cs
src/GraphicObjects/Slider.cs
src/GraphicObjects/Spinner.cs
src/GraphicObjects/Splitter.cs
src/GraphicObjects/TabItem.cs
src/GraphicObjects/TemplatedControl.cs
src/GraphicObjects/TextBox.cs
src/GraphicObjects/TextRun.cs
src/GraphicObjects/Window.cs
src/Interface.cs
src/StyleReader.cs

index 68f67ca6b67a4e7af814eb14c49c4959788627c4..0467b31490d2146d517afd373743a9bca1dd661f 100644 (file)
     <Compile Include="src\CompilerServices\Bindings.cs">
       <LogicalName></LogicalName>
     </Compile>
+    <Compile Include="src\StyleReader.cs" />
   </ItemGroup>
   <ItemGroup>
     <Reference Include="System" />
index 2038c524654678f0d509917fc4b10813cd7de2d0..55920f27ae4a349c319f637248a797e767eea9c7 100644 (file)
@@ -1,2 +1,2 @@
-Focusable = true
-Fit = true
+Focusable = true;
+Fit = true;
index 13d2224a93a3bfbbce0c92d957d3a6824c2363a8..934248ab5b31d9ca0cccf1946832b1e6e44d15f9 100644 (file)
@@ -1,2 +1,2 @@
-Focusable = true
-Height=Fit
+Focusable = true;
+Height=Fit;
index 9fa3b2678895e8360c6ff964ae0b5a74887e04bd..8b54a40a91819d53af36fae84a0f789b08656b06 100644 (file)
@@ -1,2 +1,2 @@
-Focusable = true
-Height = Fit
+Focusable = true;
+Height = Fit;
index 9fa3b2678895e8360c6ff964ae0b5a74887e04bd..8b54a40a91819d53af36fae84a0f789b08656b06 100644 (file)
@@ -1,2 +1,2 @@
-Focusable = true
-Height = Fit
+Focusable = true;
+Height = Fit;
index d5b41383e8020931d8786826e7b70f4f0bb4b551..8a165c2aa18e73f50d113c9d36a4fab1a3fc06ad 100644 (file)
@@ -1 +1 @@
-Fit = true
+Fit = true;
index ed5cb20f9966f5fcfb572bfdf06c6219e275f17d..1f562c11de0eb63e2a5be853221657d6e2e423f3 100644 (file)
@@ -1,5 +1,5 @@
-Width=200
-Height=Fit
-Title=MessageBox
-Focusable=true
-MinimumSize=150;80
+Width=200;
+Height=Fit;
+Title=MessageBox;
+Focusable=true;
+MinimumSize=150;80;
index 9fa3b2678895e8360c6ff964ae0b5a74887e04bd..8b54a40a91819d53af36fae84a0f789b08656b06 100644 (file)
@@ -1,2 +1,2 @@
-Focusable = true
-Height = Fit
+Focusable = true;
+Height = Fit;
index 9fa3b2678895e8360c6ff964ae0b5a74887e04bd..8b54a40a91819d53af36fae84a0f789b08656b06 100644 (file)
@@ -1,2 +1,2 @@
-Focusable = true
-Height = Fit
+Focusable = true;
+Height = Fit;
index e767555c2e6b53068a574c50134d37876529289c..7e4f60684e152fe87cf646f3eec7ebd81f526ee9 100644 (file)
@@ -1,4 +1,4 @@
-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;
index 9fa3b2678895e8360c6ff964ae0b5a74887e04bd..8b54a40a91819d53af36fae84a0f789b08656b06 100644 (file)
@@ -1,2 +1,2 @@
-Focusable = true
-Height = Fit
+Focusable = true;
+Height = Fit;
index 536e13dd0dd8bbecd4c14d3c698d03231a20ac09..b02cd71488485b274cff01948bb83e9b246b3a86 100644 (file)
@@ -1,2 +1,2 @@
-Focusable = true
-Background = DimGray
+Focusable = true;
+Background = DimGray;
index 9562848dffc9c9a36fddbef34f9ab497103e673f..dc3820e0fe337bd2eb44399fe205faf49318bd5b 100644 (file)
@@ -1,2 +1,2 @@
-Focusable = true
-CacheEnabled = false
+Focusable = true;
+CacheEnabled = false;
index 2ad617a51c6681497bb73ba3f7a06d582952c17a..764cfcdd5b26a91562f4a1e614a5dff2d5c1d62d 100644 (file)
@@ -1,5 +1,5 @@
-Fit = true
-Focusable = true
-Background = White
-Foreground = Black
+Fit = true;
+Focusable = true;
+Background = White;
+Foreground = Black;
 
index c2eb97fe295d3ae3d9bced67f38f982a6291af67..1f000247094561dfc40d226123bfdc0f421fb527 100644 (file)
@@ -1,2 +1,2 @@
-Fit = true
-Margin = 2
+Fit = true;
+Margin = 2;
index f0032e46885e5eba7159f0afc6850a0e2de1ec4f..22ee20e298e6717da39a2ae65688a037c9f07307 100644 (file)
@@ -1,3 +1,3 @@
-Focusable=true
-MinimumSize=50;50
-Fit=true
+Focusable=true;
+MinimumSize=50;50;
+Fit=true;
index e194bc80da7cadf92f5e23d6f18afe7b47ba433f..0cc2c555d2d72dc44d841e00e5e3d3dff2a38a76 100644 (file)
@@ -80,6 +80,7 @@ namespace Tests
 
 
                        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 ();
@@ -87,7 +88,6 @@ namespace Tests
                        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;
index 959cadb1fad01bff91aebdac1882ef54f07bbbdc..5b4d9c757222ee9ad3899ac25019de7490f5b2d0 100755 (executable)
@@ -1,5 +1,6 @@
 <?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"/>
index d376121f628913b781471d7aacc35f22d990294d..617cfb8e877f9d2d77d5cc1e221bcb83f752e0ed 100644 (file)
@@ -1,8 +1,8 @@
-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;
index 8011ebcca3e6605ae21cb92c208e3af62f4b3063..bce8e730104778121cf21e906a077d5f5011bd3f 100644 (file)
@@ -1,11 +1,11 @@
-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;}
index 10aaf20a403d8ac0ea0c5e6e59bbcda8404ddd5c..8985c92973d2b97f668ac57dac7f661b95f6d816 100644 (file)
@@ -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);
+               }
        }
 }
 
index 3dd10606e260bb5a1141216f6fd270d2d7ad32c3..92238e69237b8ae6e84c1c6cf91618066fc8e92b 100644 (file)
@@ -12,7 +12,6 @@ using System.ComponentModel;
 
 namespace Crow
 {
-       [DefaultStyle("#Crow.Styles.Button.style")]
        [DefaultTemplate("#Crow.Templates.Button.crow")]
     public class Button : TemplatedContainer
     {
index 71e686f911adc56cd2c95611c4c29ea171f0c209..f8193e242c77ed78e3c508f0ffc05e4c23587d2c 100644 (file)
@@ -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
        {
index 8888696db78ffb7309576bf51db081f84c666f02..e45d20df2590b3f5f91cf124c5d721c5d544c10c 100644 (file)
@@ -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
     {          
index af8b5640ee91a5143fe43282822c0317992dcba5..d21936e81bb55eae7204eea77ea062ad893873c6 100644 (file)
@@ -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
     {
index 2838f6cd118b29865998e5d586149155e5522581..433599c1bfecb1e377294b6f5fe27482988a13f8 100644 (file)
@@ -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
 
index 86c659d0d9911b28c1b9dc7a05d722d6bc1c646f..886e79649ecff80e1b714375715d30b6d70a5185 100644 (file)
@@ -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 {
index 22a60aa0e6e83e1476f8e69e33b54df9d3439b81..e1bf02a7d7828e86ca7e3384618e6b00b9b89ad5 100644 (file)
@@ -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;
index 2114262e8cd0d3e400466655a4825d4812b8bb2c..550f5b7271ba76a77350cefcde77e3a8ca96bb56 100644 (file)
@@ -23,7 +23,6 @@ using System.ComponentModel;
 
 namespace Crow
 {
-       [DefaultStyle("#Crow.Styles.MessageBox.style")]
        [DefaultTemplate("#Crow.Templates.MessageBox.goml")]
        public class MessageBox : Window
        {
index 5e5541fefde0ed81677d830633b3d4fd09593a6c..14e7ec7ad1d7d6b774326468bb2b1870e388e0ec 100644 (file)
@@ -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
     {          
index a62487069c05a8b0e667a4a6771c3cf1d50a6a39..ffd5ba27d125830dc9bb5e4880e7e4f41234d915 100644 (file)
@@ -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
     {                  
index 3b2cebf43423f14e6f94a75235cc6638320fc642..bce7497154e3f7b69c7577ef46469b6e6de3f9f7 100644 (file)
@@ -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
index 9447f205d2a6355e8fa5a68074b408d075e98d4b..1a8674d076511c0ba0d0cfa9cc5a5b803c46b4a3 100644 (file)
@@ -22,7 +22,6 @@ using System;
 
 namespace Crow
 {
-       [DefaultStyle("#Crow.Styles.Spinner.style")]
        [DefaultTemplate("#Crow.Templates.Spinner.goml")]
        public class Spinner : NumericControl
        {
index 248863b56736b6d2f83528b3558fa2f967622b98..f33210654f1f97d13ae3f1f4ad8b555a7f56e491 100644 (file)
@@ -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 {
index 38d56c5d640ee7253598e6a245735e5a1e4b298f..2d2ba4534f626a55fb706f1150cec8e3f63851b1 100644 (file)
@@ -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 {
index c8ec2d9e87b05ca4485285b6bb5dffe33caff317..12c2b81f144d43d11bf0f8b443b1713936292139 100644 (file)
@@ -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
        {
index 7d61d5ab2115f40a89025499a39b800ba9352b31..fc02f0d63135dbba96bd26c28b224a65490a75dd 100644 (file)
@@ -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
index 103f2fcf73a044403fa500052753b854e7860e91..c644767c84d34373ef4715e7074965ecfd27da12 100644 (file)
@@ -10,8 +10,6 @@ using System.ComponentModel;
 
 namespace Crow
 {
-    [Serializable]
-       [DefaultStyle("#Crow.Styles.TextRun.style")]
     public class TextRun : GraphicObject
     {
                #region CTOR
index afb4f4f2e5ea3c8710934eba661398bab28c83bd..cbdbbb2c2faebfb00d9871d20d4d00e908a469d4 100644 (file)
@@ -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
        {
index b8426e6f8a1231d4dad7f78b0851e2474cec5ad4..d8f66443fa83262f250ecf65b9514612a3762773 100644 (file)
@@ -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
index d99a13772411b5546f4c5e18a8e95536a348cd8f..c1cc28bf964adba928e78d312d90d0a82672bd45 100644 (file)
 //  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;
+                               }
+                       }                                       
                }
        }
 }