diff options
| author | jpbruyere <jp.bruyere@hotmail.com> | 2016-08-12 03:37:29 +0200 |
|---|---|---|
| committer | jpbruyere <jp.bruyere@hotmail.com> | 2016-08-12 03:37:29 +0200 |
| commit | 80ceca9f199f37928f8c3068d07732b77d45156f (patch) | |
| tree | 23cc31124f141dfc7919581d8cfab381a4ebc977 /src | |
| parent | 2b62c4b6eefdeaf3ddb4247b6241e87ee2345a6a (diff) | |
* Crow.csproj, Default.style, button.svg, buttest.svg, buttest2.svg, buttest4.svg, 0.crow:
test and divers
* DirectoryView.cs:
SelectedItem property
* GraphicObject.cs:
Style class, EventInfo in styles
* Group.cs:
lock children
* Popper.cs:
alignment = top left, simple unpop on mouse leave, no additional tests
* Spinner.cs:
ctor order
* TabView.cs:
code clean
* Window.cs:
movable
* Style.cs, Interface.cs:
Style class
* StyleReader.cs:
parser exception, debug expression parsing
* Button.crow, Popper.goml, TabItem.crow, CheckBox.goml, Expandable.goml, MessageBox.goml, RadioButton.goml, ScrollingListBox.goml:
templating
* TreeView.crow:
scrollbar
* 1.crow:
showcase
* test.style, Tests.csproj, CheckBox2.imlt:
tests
Diffstat (limited to 'src')
| -rw-r--r-- | src/GraphicObjects/DirectoryView.cs | 13 | ||||
| -rw-r--r-- | src/GraphicObjects/GraphicObject.cs | 26 | ||||
| -rw-r--r-- | src/GraphicObjects/Group.cs | 13 | ||||
| -rw-r--r-- | src/GraphicObjects/Popper.cs | 10 | ||||
| -rw-r--r-- | src/GraphicObjects/Spinner.cs | 8 | ||||
| -rw-r--r-- | src/GraphicObjects/TabView.cs | 13 | ||||
| -rw-r--r-- | src/GraphicObjects/Window.cs | 14 | ||||
| -rw-r--r-- | src/Interface.cs | 4 | ||||
| -rw-r--r-- | src/StyleReader.cs | 84 |
9 files changed, 130 insertions, 55 deletions
diff --git a/src/GraphicObjects/DirectoryView.cs b/src/GraphicObjects/DirectoryView.cs index e9a9ef9b..ac53ee8b 100644 --- a/src/GraphicObjects/DirectoryView.cs +++ b/src/GraphicObjects/DirectoryView.cs @@ -41,6 +41,18 @@ namespace Crow string _root = "/"; bool _showFiles; + object _selectedItem; + [XmlIgnore]public object SelectedItem { + get { + return _selectedItem; + } + set { + if (value == _selectedItem) + return; + _selectedItem = value; + NotifyValueChanged ("SelectedItem", _selectedItem); + } + } [XmlAttributeAttribute()][DefaultValue(true)] public virtual bool ShowFiles { get { return _showFiles; } @@ -66,6 +78,7 @@ namespace Crow get { return new DirectoryInfo (Root).GetFileSystemInfos (); } } public void onSelectedItemChanged (object sender, SelectionChangeEventArgs e){ + SelectedItem = e.NewValue; SelectedItemChanged.Raise (this, e); } } diff --git a/src/GraphicObjects/GraphicObject.cs b/src/GraphicObjects/GraphicObject.cs index 88166fe6..925f69df 100644 --- a/src/GraphicObjects/GraphicObject.cs +++ b/src/GraphicObjects/GraphicObject.cs @@ -538,7 +538,7 @@ namespace Crow } } - List<Dictionary<string, object>> styling = new List<Dictionary<string, object>>(); + List<Style> styling = new List<Style>(); //Search for a style mathing : //1: Full class name, with full namespace @@ -587,7 +587,14 @@ namespace Crow il.Emit (OpCodes.Ldarg_0); il.Emit (OpCodes.Stloc_0); - foreach (PropertyInfo pi in thisType.GetProperties(BindingFlags.Public | BindingFlags.Instance)) { + foreach (EventInfo ei in thisType.GetEvents(BindingFlags.Public | BindingFlags.Instance)) { + string expression; + if (!getDefaultEvent(ei, styling, out expression)) + continue; + CompilerServices.emitBindingCreation (il, ei.Name, expression); + } + + foreach (PropertyInfo pi in thisType.GetProperties(BindingFlags.Public | BindingFlags.Instance)) { if (pi.GetSetMethod () == null) continue; object defaultValue; @@ -606,7 +613,20 @@ namespace Crow throw new Exception ("Error applying style <" + styleKey + ">:", ex); } } - bool getDefaultValue(PropertyInfo pi, List<Dictionary<string, object>> styling, + bool getDefaultEvent(EventInfo ei, List<Style> styling, + out string expression){ + expression = ""; + if (styling.Count > 0){ + for (int i = 0; i < styling.Count; i++) { + if (styling[i].ContainsKey (ei.Name)){ + expression = (string)styling[i] [ei.Name]; + return true; + } + } + } + return false; + } + bool getDefaultValue(PropertyInfo pi, List<Style> styling, out object defaultValue){ defaultValue = null; string name = ""; diff --git a/src/GraphicObjects/Group.cs b/src/GraphicObjects/Group.cs index 4c8d0537..e87ca41c 100644 --- a/src/GraphicObjects/Group.cs +++ b/src/GraphicObjects/Group.cs @@ -39,7 +39,8 @@ namespace Crow set { _multiSelect = value; } } public virtual void AddChild(GraphicObject g){ - Children.Add(g); + lock (children) + Children.Add(g); g.Parent = this; g.ResolveBindings (); g.RegisteredLayoutings = LayoutingType.None; @@ -51,7 +52,8 @@ namespace Crow child.LayoutChanged -= OnChildLayoutChanges; child.ClearBinding (); //child.Parent = null; - Children.Remove(child); + lock (children) + Children.Remove(child); if (child == largestChild && Width == Measure.Fit) searchLargestChild (); @@ -241,9 +243,10 @@ namespace Crow //clip to client zone CairoHelpers.CairoRectangle (gr, ClientRectangle, CornerRadius); gr.Clip (); - - foreach (GraphicObject g in Children) { - g.Paint (ref gr); + lock (children) { + foreach (GraphicObject g in Children) { + g.Paint (ref gr); + } } gr.Restore (); } diff --git a/src/GraphicObjects/Popper.cs b/src/GraphicObjects/Popper.cs index 0a013ae1..ea11435a 100644 --- a/src/GraphicObjects/Popper.cs +++ b/src/GraphicObjects/Popper.cs @@ -100,6 +100,8 @@ namespace Crow return; _content.LogicalParent = this; + _content.HorizontalAlignment = HorizontalAlignment.Left; + _content.VerticalAlignment = VerticalAlignment.Top; _content.LayoutChanged += _content_LayoutChanged; _content.MouseLeave += onMouseLeave; } @@ -187,14 +189,6 @@ namespace Crow public override void onMouseLeave (object sender, MouseMoveEventArgs e) { base.onMouseLeave (sender, e); - if (MouseIsIn (e.Position)) - return; - if (_content == null) - return; - try { - if (_content.MouseIsIn (e.Position)) - return; - } catch {} IsPopped = false; } #endregion diff --git a/src/GraphicObjects/Spinner.cs b/src/GraphicObjects/Spinner.cs index 1a8674d0..0806d4d3 100644 --- a/src/GraphicObjects/Spinner.cs +++ b/src/GraphicObjects/Spinner.cs @@ -25,14 +25,16 @@ namespace Crow [DefaultTemplate("#Crow.Templates.Spinner.goml")] public class Spinner : NumericControl { + #region CTOR + public Spinner () : base() + { + } public Spinner (double minimum, double maximum, double step) : base (minimum, maximum, step) { } - public Spinner () : base() - { - } + #endregion void onUp (object sender, MouseButtonEventArgs e) { diff --git a/src/GraphicObjects/TabView.cs b/src/GraphicObjects/TabView.cs index 015f5f4f..e140191b 100644 --- a/src/GraphicObjects/TabView.cs +++ b/src/GraphicObjects/TabView.cs @@ -39,6 +39,7 @@ namespace Crow { } + #region public properties [XmlAttributeAttribute()][DefaultValue(Orientation.Horizontal)] public virtual Orientation Orientation { @@ -54,7 +55,7 @@ namespace Crow NotifyValueChanged ("TabOrientation", Orientation.Horizontal); } } - [XmlAttributeAttribute()][DefaultValue(2)] + [XmlAttributeAttribute()][DefaultValue(20)] public int Spacing { get { return _spacing; } @@ -81,7 +82,7 @@ namespace Crow RegisterForRedraw (); } } - [XmlAttributeAttribute()][DefaultValue(22)] + [XmlAttributeAttribute()][DefaultValue("15")] public virtual Measure TabThickness { get { return tabThickness; } set { @@ -92,13 +93,7 @@ namespace Crow RegisterForGraphicUpdate (); } } - - //prevent caching, because drawing order is different depending on selected tab - [XmlAttributeAttribute()][DefaultValue(false)] - public override bool CacheEnabled { - get {return false;} - set { } - } + #endregion public override void AddChild (GraphicObject child) { diff --git a/src/GraphicObjects/Window.cs b/src/GraphicObjects/Window.cs index cbdbbb2c..be482e43 100644 --- a/src/GraphicObjects/Window.cs +++ b/src/GraphicObjects/Window.cs @@ -45,6 +45,7 @@ namespace Crow string _title; string _icon; bool _resizable; + bool _movable; bool hoverBorder = false; Container _contentContainer; @@ -100,7 +101,16 @@ namespace Crow NotifyValueChanged ("Resizable", _resizable); } } - + [XmlAttributeAttribute()][DefaultValue(true)] + public bool Movable { + get { + return _movable; + } + set { + _movable = value; + NotifyValueChanged ("Movable", _movable); + } + } #region GraphicObject Overrides public override void ResolveBindings () { @@ -120,7 +130,7 @@ namespace Crow return; } - if (this.HasFocus) { + if (this.HasFocus && _movable) { if (e.Mouse.IsButtonDown (MouseButton.Left)) { int currentLeft = this.Left; int currentTop = this.Top; diff --git a/src/Interface.cs b/src/Interface.cs index ba9769b1..6997f6ba 100644 --- a/src/Interface.cs +++ b/src/Interface.cs @@ -119,13 +119,13 @@ namespace Crow /// The compilation is done on the first object instancing, and is also done for custom widgets public delegate void LoaderInvoker(object instance); public static Dictionary<String, LoaderInvoker> DefaultValuesLoader = new Dictionary<string, LoaderInvoker>(); - public static Dictionary<string, Dictionary<string, object>> Styling; + public static Dictionary<string, Style> Styling; /// <summary> parse all styling data's and build global Styling Dictionary </summary> static void LoadStyling() { System.Globalization.CultureInfo savedCulture = Thread.CurrentThread.CurrentCulture; Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture; - Styling = new Dictionary<string, Dictionary<string, object>> (); + Styling = new Dictionary<string, Style> (); //fetch styling info in this order, if member styling is alreadey referenced in previous //assembly, it's ignored. diff --git a/src/StyleReader.cs b/src/StyleReader.cs index 92b24e2d..27b3f4b5 100644 --- a/src/StyleReader.cs +++ b/src/StyleReader.cs @@ -29,11 +29,14 @@ namespace Crow { enum readerState { classNames, propertyName, expression } readerState state = readerState.classNames; - + string resourceId; + int column = 1; + int line = 1; public StyleReader (Assembly assembly, string resId) : base(assembly.GetManifestResourceStream (resId)) { + resourceId = resId; string styleKey = resId.Substring (0, resId.Length - 6); string token = ""; List<string> targetsClasses = new List<string> (); @@ -56,15 +59,15 @@ namespace Crow //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 '='"); + throwParserException ("Unexpected token '='"); else if (targetsClasses.Count == 1) { if (!string.IsNullOrEmpty (token)) - throw new Exception ("Unexpected token '='"); + throwParserException ("Unexpected token '='"); currentProperty = targetsClasses [0]; targetsClasses [0] = styleKey; }else{ if (string.IsNullOrEmpty (token)) - throw new Exception ("Unexpected token '='"); + throwParserException ("Unexpected token '='"); targetsClasses.Add (styleKey); currentProperty = token; token = ""; @@ -83,7 +86,7 @@ namespace Crow token = ""; }else if (c == '}'){ if (!string.IsNullOrEmpty (token)) - throw new Exception ("Unexpected token '" + c + "'"); + throwParserException ("Unexpected token '" + c + "'"); targetsClasses = new List<string> (); currentProperty = ""; state = readerState.classNames; @@ -91,43 +94,78 @@ namespace Crow token += c; break; case readerState.expression: + bool expressionIsFinished = false; if (curlyBracketCount == 0) { if (c == '{'){ - if (string.IsNullOrEmpty(token)) - throw new Exception ("Unexpected token '{'"); + if (!string.IsNullOrEmpty(token.Trim())) + throwParserException ("Unexpected token '{'"); curlyBracketCount++; token = "{"; }else if (c == '}') - throw new Exception ("Unexpected token '{'"); + throwParserException ("Unexpected token '{'"); else if (c == ';') { - if (!string.IsNullOrEmpty (token)) { - string expression = token.Trim (); - - foreach (string tc in targetsClasses) { - if (!Interface.Styling.ContainsKey (tc)) - Interface.Styling [tc] = new Dictionary<string, object> (); - else if (Interface.Styling [tc].ContainsKey (currentProperty)) - continue; - Interface.Styling [tc] [currentProperty] = expression; - } - token = ""; - } - state = readerState.propertyName; + expressionIsFinished = true; } else token += c; } else { if (c == '{') curlyBracketCount++; - else if (c == '}') + else if (c == '}') { curlyBracketCount--; + if (curlyBracketCount == 0) + expressionIsFinished = true; + } token += c; } + if (expressionIsFinished) { + if (!string.IsNullOrEmpty (token)) { + string expression = token.Trim (); + + foreach (string tc in targetsClasses) { + if (!Interface.Styling.ContainsKey (tc)) + Interface.Styling [tc] = new Style (); + else if (Interface.Styling [tc].ContainsKey (currentProperty)) + continue; + Interface.Styling [tc] [currentProperty] = expression; + } + token = ""; + } + //allow omiting ';' if curly bracket close expression + while (!EndOfStream) { + if (Char.IsWhiteSpace((char)Peek())) + Read(); + else + break; + } + if (this.Peek () == ';') + this.Read (); + state = readerState.propertyName; + } break; } } if (curlyBracketCount > 0) - throw new Exception ("Unexpected end of file"); + throwParserException ("Unexpected end of file"); + } + + public override int Read () + { + int tmp = base.Read (); + char c = (char)tmp; + if (c == '\n') { + line++; + column = 1; + } else if (c == '\t') + column += Interface.TabSize; + else if (c != '\r') + column++; + return tmp; + } + + void throwParserException(string message){ + throw new Exception (string.Format ("Style Reader Exception ({0},{1}): {2} in {3}.", + line, column, message, resourceId)); } } } |