From: jpbruyere Date: Tue, 23 Jun 2015 15:18:19 +0000 (+0200) Subject: advanced bindings with directory like syntax, need double direction X-Git-Tag: 0.2~74 X-Git-Url: https://git.osiis.dedyn.io/?a=commitdiff_plain;h=89f3b961d95eea59364719c26ed65f2df26d0b55;p=jp%2Fcrow.git advanced bindings with directory like syntax, need double direction binding --- diff --git a/Templates/Scrollbar.goml b/Templates/Scrollbar.goml index 1e3fa514..bc47eb9e 100755 --- a/Templates/Scrollbar.goml +++ b/Templates/Scrollbar.goml @@ -4,7 +4,7 @@ - + diff --git a/Tests/Interfaces/test4.goml b/Tests/Interfaces/test4.goml index d0e644e9..3ceb7198 100755 --- a/Tests/Interfaces/test4.goml +++ b/Tests/Interfaces/test4.goml @@ -133,15 +133,17 @@ TextAlignment="Center" Background="AoEnglish"/> - - - - - - - + + + + + + + + Exe Tests Tests - test2.GOLIBTest_Scrollbar + test.GOLIBTest_4 v4.5 ..\bin\$(configuration) obj\$(configuration) diff --git a/src/CompilerServices/CompilerServices.cs b/src/CompilerServices/CompilerServices.cs index 7bd91805..a4f4110c 100644 --- a/src/CompilerServices/CompilerServices.cs +++ b/src/CompilerServices/CompilerServices.cs @@ -156,21 +156,42 @@ namespace go public static void ResolveBinding(DynAttribute binding, object _source) { + object srcGO = _source; + Type srcType = _source.GetType (); Type dstType = binding.Source.GetType (); MemberInfo miDst = dstType.GetMember (binding.MemberName).FirstOrDefault (); - MemberInfo miSrc = srcType.GetMember (binding.Value).FirstOrDefault(); + string[] bindingExp = binding.Value.Split ('/'); + MemberInfo miSrc; + if (bindingExp.Length > 1){ + int i = 0; + srcGO = binding.Source; //starts parsing from current GO + while (bindingExp [i] == "..") { + srcGO = (srcGO as ILayoutable).Parent as GraphicObject; + i++; + } + string[] bindTrg = bindingExp [i].Split ('.'); + if (bindTrg.Length == 1) + srcType = srcGO.GetType (); + else { + srcGO = (srcGO as GraphicObject).FindByName (bindTrg [0]); + srcType = srcGO.GetType (); + } + miSrc = srcType.GetMember (bindTrg.LastOrDefault()).FirstOrDefault (); + }else + miSrc = srcType.GetMember (binding.Value).FirstOrDefault (); + #region initialize target with actual value object srcVal = null; if (miSrc == null) - srcVal = _source;//if no member is provided for binding, source raw value is taken + srcVal = srcGO;//if no member is provided for binding, source raw value is taken else { if (miSrc.MemberType == MemberTypes.Property) - srcVal = (miSrc as PropertyInfo).GetGetMethod ().Invoke (_source, null); + srcVal = (miSrc as PropertyInfo).GetGetMethod ().Invoke (srcGO, null); else if (miSrc.MemberType == MemberTypes.Field) - srcVal = (miSrc as FieldInfo).GetValue (_source); + srcVal = (miSrc as FieldInfo).GetValue (srcGO); else throw new Exception ("unandled source member type for binding"); } @@ -288,7 +309,7 @@ namespace go Delegate del = dm.CreateDelegate(ei.EventHandlerType); MethodInfo addHandler = ei.GetAddMethod (); //Delegate del = dm.CreateDelegate(typeof(System.EventHandler)); - addHandler.Invoke(_source, new object[] {del}); + addHandler.Invoke(srcGO, new object[] {del}); } #region conversions @@ -307,6 +328,8 @@ namespace go name = "ToInt32"; else if( targetType == typeof( long ) ) name = "ToInt64"; + else if( targetType == typeof( double ) ) + name = "ToDouble"; else if (targetType == typeof (string ) ) return typeof(object).GetMethod("ToString", Type.EmptyTypes); else diff --git a/src/GraphicObjects/NumericControl.cs b/src/GraphicObjects/NumericControl.cs index c6d76bcd..61af27d4 100644 --- a/src/GraphicObjects/NumericControl.cs +++ b/src/GraphicObjects/NumericControl.cs @@ -4,7 +4,7 @@ using System.ComponentModel; namespace go { - public abstract class NumericControl : TemplatedControl + public abstract class NumericControl : TemplatedControl, IValueChange { #region CTOR public NumericControl () : base() diff --git a/src/GraphicObjects/Scrollbar.cs b/src/GraphicObjects/Scrollbar.cs index ca17393e..f66ce83f 100644 --- a/src/GraphicObjects/Scrollbar.cs +++ b/src/GraphicObjects/Scrollbar.cs @@ -25,6 +25,8 @@ namespace go Orientation _orientation; Slider _slider; + double _maximumScroll; + double _scroll; public Scrollbar() : base() { @@ -36,6 +38,29 @@ namespace go _slider = this.child.FindByName ("Slider") as Slider; } + [XmlAttributeAttribute()][DefaultValue(0.0)] + public virtual double MaximumScroll + { + get { return _maximumScroll; } + set { + if (_maximumScroll == value) + return; + _maximumScroll = value; + ValueChanged.Raise(this, new ValueChangeEventArgs ("MaximumScroll", _maximumScroll)); + } + } + [XmlAttributeAttribute()][DefaultValue(0.0)] + public virtual double Scroll + { + get { return _scroll; } + set { + if (_scroll == value) + return; + _scroll = value; + registerForGraphicUpdate (); + ValueChanged.Raise(this, new ValueChangeEventArgs ("Scroll", _scroll)); + } + } [XmlAttributeAttribute()][DefaultValue(Orientation.Vertical)] public virtual Orientation Orientation { @@ -49,11 +74,11 @@ namespace go } public void onScrollBack (object sender, MouseButtonEventArgs e) { - _slider.Value -= _slider.LargeIncrement; + Scroll -= _slider.LargeIncrement; } public void onScrollForth (object sender, MouseButtonEventArgs e) { - _slider.Value += _slider.LargeIncrement; + Scroll += _slider.LargeIncrement; } } } diff --git a/src/GraphicObjects/Scroller.cs b/src/GraphicObjects/Scroller.cs index bd8384a2..089c7111 100644 --- a/src/GraphicObjects/Scroller.cs +++ b/src/GraphicObjects/Scroller.cs @@ -11,8 +11,12 @@ using System.ComponentModel; namespace go { - public class Scroller : Container + public class Scroller : Container, IValueChange { + #region IValueChange implementation + public event EventHandler ValueChanged; + #endregion + bool _verticalScrolling; bool _horizontalScrolling; bool _scrollbarVisible; @@ -47,6 +51,7 @@ namespace go } set { _scrollX = value; + ValueChanged.Raise(this, new ValueChangeEventArgs("ScrollX", _scrollX)); } } @@ -58,6 +63,16 @@ namespace go } set { _scrollY = value; + ValueChanged.Raise(this, new ValueChangeEventArgs("ScrollY", _scrollY)); + } + } + + [XmlIgnore] + public int MaximumScroll { + get { + return VerticalScrolling ? + Child.Slot.Height - ClientRectangle.Height : + Child.Slot.Width - ClientRectangle.Width; } } @@ -72,7 +87,16 @@ namespace go } #region GraphicObject Overrides + protected override void OnLayoutChanges (LayoutingType layoutType) + { + base.OnLayoutChanges (layoutType); + if (_verticalScrolling) { + if (layoutType == LayoutingType.Height) + ValueChanged.Raise(this, new ValueChangeEventArgs("MaximumScroll", MaximumScroll)); + }else if (layoutType == LayoutingType.Width) + ValueChanged.Raise(this, new ValueChangeEventArgs("MaximumScroll", MaximumScroll)); + } #endregion #region Mouse handling diff --git a/src/GraphicObjects/Slider.cs b/src/GraphicObjects/Slider.cs index 4bf41d52..488617de 100644 --- a/src/GraphicObjects/Slider.cs +++ b/src/GraphicObjects/Slider.cs @@ -78,14 +78,16 @@ namespace go } protected override void UpdateGraphic () { - computeCursorPosition(); + if (Maximum > 0) + computeCursorPosition(); base.UpdateGraphic (); } protected override void onDraw (Context gr) { base.onDraw (gr); - + if (Maximum <= 0) + return; Rectangle r = ClientRectangle; PointD pStart; PointD pEnd; diff --git a/src/Rectangles.cs b/src/Rectangles.cs index de7b8438..aa54605c 100644 --- a/src/Rectangles.cs +++ b/src/Rectangles.cs @@ -100,9 +100,9 @@ namespace go Rectangle r = rInList; if (sw.VerticalScrolling) - r.Top -= sw.scrollY; + r.Top -= sw.ScrollY; if (sw.HorizontalScrolling) - r.Left -= sw.scrollX; + r.Left -= sw.ScrollX; newList.Add(r); } @@ -122,11 +122,11 @@ namespace go if (sw != null) { if (sw.VerticalScrolling) { - rebasedR.Top -= sw.scrollY; + rebasedR.Top -= sw.ScrollY; // if (sw.scrollY < 0) // Debug.WriteLine (".."); }if (sw.HorizontalScrolling) - rebasedR.Left -= sw.scrollX; + rebasedR.Left -= sw.ScrollX; } newList.Add(rebasedR);