diff options
author | Lluis Sanchez Gual <lluis@xamarin.com> | 2014-02-19 21:43:14 +0400 |
---|---|---|
committer | Lluis Sanchez Gual <lluis@xamarin.com> | 2014-02-19 21:43:14 +0400 |
commit | c9aa62d137988b2cb605478099cd727c76faf914 (patch) | |
tree | 6771ee6a7e96c313cad45116f64d82492b75adb4 /Xwt.Mac | |
parent | 79a18e9797b85713512228930afa9cfd548778bd (diff) |
Added scroll controls to ScrollView
Also added scrolling unit tests
Diffstat (limited to 'Xwt.Mac')
-rw-r--r-- | Xwt.Mac/Xwt.Mac/ScrollAdjustmentBackend.cs | 20 | ||||
-rw-r--r-- | Xwt.Mac/Xwt.Mac/ScrollControlBackend.cs | 26 | ||||
-rw-r--r-- | Xwt.Mac/Xwt.Mac/ScrollViewBackend.cs | 44 | ||||
-rw-r--r-- | Xwt.Mac/Xwt.Mac/TableViewBackend.cs | 22 |
4 files changed, 99 insertions, 13 deletions
diff --git a/Xwt.Mac/Xwt.Mac/ScrollAdjustmentBackend.cs b/Xwt.Mac/Xwt.Mac/ScrollAdjustmentBackend.cs index 8fb0a963..9fa6dffc 100644 --- a/Xwt.Mac/Xwt.Mac/ScrollAdjustmentBackend.cs +++ b/Xwt.Mac/Xwt.Mac/ScrollAdjustmentBackend.cs @@ -30,11 +30,13 @@ using MonoMac.AppKit; namespace Xwt.Mac { - class ScrollAdjustmentBackend: IScrollAdjustmentBackend + class ScrollAdjustmentBackend: IScrollAdjustmentBackend, IScrollControlBackend { bool vertical; NSScrollView scrollView; IScrollAdjustmentEventSink eventSink; + IScrollControlEventSink controlEventSink; + ApplicationContext context; public ScrollAdjustmentBackend (NSScrollView scrollView, bool vertical) { @@ -45,6 +47,7 @@ namespace Xwt.Mac #region IBackend implementation public void InitializeBackend (object frontend, ApplicationContext context) { + this.context = context; } public void EnableEvent (object eventId) @@ -58,7 +61,12 @@ namespace Xwt.Mac public void NotifyValueChanged () { - eventSink.OnValueChanged (); + context.InvokeUserCode (delegate { + if (eventSink != null) + eventSink.OnValueChanged (); + if (controlEventSink != null) + controlEventSink.OnValueChanged (); + }); } #region IScrollAdjustmentBackend implementation @@ -67,6 +75,11 @@ namespace Xwt.Mac this.eventSink = eventSink; } + public void Initialize (IScrollControlEventSink eventSink) + { + this.controlEventSink = eventSink; + } + CustomClipView ClipView { get { return ((CustomClipView)scrollView.ContentView); } } @@ -92,6 +105,7 @@ namespace Xwt.Mac UpperValue = upperValue; PageSize = pageSize; PageIncrement = pageIncrement; + StepIncrement = stepIncrement; if (vertical) scrollView.VerticalLineScroll = (float)stepIncrement; @@ -111,6 +125,8 @@ namespace Xwt.Mac public double PageSize { get; private set; } + public double StepIncrement { get; private set; } + #endregion } } diff --git a/Xwt.Mac/Xwt.Mac/ScrollControlBackend.cs b/Xwt.Mac/Xwt.Mac/ScrollControlBackend.cs index 27c0361e..6ea939a7 100644 --- a/Xwt.Mac/Xwt.Mac/ScrollControlBackend.cs +++ b/Xwt.Mac/Xwt.Mac/ScrollControlBackend.cs @@ -26,6 +26,7 @@ using System; using Xwt.Backends; using MonoMac.AppKit; +using MonoMac.Foundation; namespace Xwt.Mac @@ -35,11 +36,25 @@ namespace Xwt.Mac bool vertical; NSScrollView scrollView; IScrollControlEventSink eventSink; + ApplicationContext appContext; + double lastValue; - public ScrollControlBackend (NSScrollView scrollView, bool vertical) + public ScrollControlBackend (ApplicationContext appContext, NSScrollView scrollView, bool vertical) { this.vertical = vertical; this.scrollView = scrollView; + this.appContext = appContext; + lastValue = Value; + } + + public void NotifyValueChanged () + { + if (lastValue != Value) { + lastValue = Value; + appContext.InvokeUserCode (delegate { + eventSink.OnValueChanged (); + }); + } } #region IBackend implementation @@ -56,11 +71,6 @@ namespace Xwt.Mac } #endregion - public void NotifyValueChanged () - { - eventSink.OnValueChanged (); - } - #region IScrollAdjustmentBackend implementation public void Initialize (IScrollControlEventSink eventSink) { @@ -76,9 +86,9 @@ namespace Xwt.Mac } set { if (vertical) - scrollView.ScrollPoint (new System.Drawing.PointF (scrollView.DocumentVisibleRect.X, (float)value)); + scrollView.ContentView.ScrollToPoint (new System.Drawing.PointF (scrollView.DocumentVisibleRect.X, (float)value)); else - scrollView.ScrollPoint (new System.Drawing.PointF ((float)value, scrollView.DocumentVisibleRect.Y)); + scrollView.ContentView.ScrollToPoint (new System.Drawing.PointF ((float)value, scrollView.DocumentVisibleRect.Y)); scrollView.ReflectScrolledClipView (scrollView.ContentView); } } diff --git a/Xwt.Mac/Xwt.Mac/ScrollViewBackend.cs b/Xwt.Mac/Xwt.Mac/ScrollViewBackend.cs index 541094e5..0a85196c 100644 --- a/Xwt.Mac/Xwt.Mac/ScrollViewBackend.cs +++ b/Xwt.Mac/Xwt.Mac/ScrollViewBackend.cs @@ -34,6 +34,7 @@ namespace Xwt.Mac IWidgetBackend child; ScrollPolicy verticalScrollPolicy; ScrollPolicy horizontalScrollPolicy; + NormalClipView clipView; public override void Initialize () { @@ -62,8 +63,13 @@ namespace Xwt.Mac backend.Widget.Frame = new System.Drawing.RectangleF (0, 0, clipView.Frame.Width, clipView.Frame.Height); clipView.DocumentView = dummy; backend.EventSink.SetScrollAdjustments (hs, vs); + vertScroll = vs; + horScroll = hs; } else { + clipView = new NormalClipView (); + clipView.Scrolled += OnScrolled; + Widget.ContentView = clipView; Widget.DocumentView = backend.Widget; UpdateChildSize (); } @@ -88,7 +94,31 @@ namespace Xwt.Mac Widget.HasHorizontalScroller = horizontalScrollPolicy != ScrollPolicy.Never; } } - + + IScrollControlBackend vertScroll; + public IScrollControlBackend CreateVerticalScrollControl () + { + if (vertScroll == null) + vertScroll = new ScrollControlBackend (ApplicationContext, Widget, true); + return vertScroll; + } + + IScrollControlBackend horScroll; + public IScrollControlBackend CreateHorizontalScrollControl () + { + if (horScroll == null) + horScroll = new ScrollControlBackend (ApplicationContext, Widget, false); + return horScroll; + } + + void OnScrolled (object o, EventArgs e) + { + if (vertScroll is ScrollControlBackend) + ((ScrollControlBackend)vertScroll).NotifyValueChanged (); + if (horScroll is ScrollControlBackend) + ((ScrollControlBackend)horScroll).NotifyValueChanged (); + } + public Rectangle VisibleRect { get { return Rectangle.Zero; @@ -232,5 +262,17 @@ namespace Xwt.Mac DocumentView.Frame = new System.Drawing.RectangleF (0, 0, (float)(hScroll.UpperValue - hScroll.LowerValue) * ratioX, (float)(vScroll.UpperValue - vScroll.LowerValue) * ratioY); } } + + class NormalClipView: NSClipView + { + public event EventHandler Scrolled; + + public override void ScrollToPoint (System.Drawing.PointF newOrigin) + { + base.ScrollToPoint (newOrigin); + if (Scrolled != null) + Scrolled (this, EventArgs.Empty); + } + } } diff --git a/Xwt.Mac/Xwt.Mac/TableViewBackend.cs b/Xwt.Mac/Xwt.Mac/TableViewBackend.cs index e50d2ae3..0a183b1e 100644 --- a/Xwt.Mac/Xwt.Mac/TableViewBackend.cs +++ b/Xwt.Mac/Xwt.Mac/TableViewBackend.cs @@ -39,6 +39,7 @@ namespace Xwt.Mac protected NSTableView Table; ScrollView scroll; NSObject selChangeObserver; + NormalClipView clipView; public TableViewBackend () { @@ -48,6 +49,9 @@ namespace Xwt.Mac { Table = CreateView (); scroll = new ScrollView (); + clipView = new NormalClipView (); + clipView.Scrolled += OnScrolled; + scroll.ContentView = clipView; scroll.DocumentView = Table; scroll.BorderType = NSBorderType.BezelBorder; ViewObject = scroll; @@ -113,14 +117,28 @@ namespace Xwt.Mac } } + ScrollControlBackend vertScroll; public IScrollControlBackend CreateVerticalScrollControl () { - return new ScrollControlBackend (scroll, true); + if (vertScroll == null) + vertScroll = new ScrollControlBackend (ApplicationContext, scroll, true); + return vertScroll; } + ScrollControlBackend horScroll; public IScrollControlBackend CreateHorizontalScrollControl () { - return new ScrollControlBackend (scroll, false); + if (horScroll == null) + horScroll = new ScrollControlBackend (ApplicationContext, scroll, false); + return horScroll; + } + + void OnScrolled (object o, EventArgs e) + { + if (vertScroll != null) + vertScroll.NotifyValueChanged (); + if (horScroll != null) + horScroll.NotifyValueChanged (); } protected override Size GetNaturalSize () |