Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/xwt.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLluis Sanchez Gual <lluis@xamarin.com>2014-02-19 22:16:23 +0400
committerLluis Sanchez Gual <lluis@xamarin.com>2014-02-19 22:16:23 +0400
commit2fb9b0ad97837a640379e39494b2a12437cd45a5 (patch)
tree83aee064ded7956896fb98a7225ef0bd2bf5b33d /Xwt.Mac
parent659fd666489b32587c5845aec1574cb3146f6f7a (diff)
parentea3ca3beffac204cfe7509af5a5498996a274f96 (diff)
Merge branch 'new-scroll-properties'
Diffstat (limited to 'Xwt.Mac')
-rw-r--r--Xwt.Mac/Xwt.Mac.csproj1
-rw-r--r--Xwt.Mac/Xwt.Mac/ScrollAdjustmentBackend.cs20
-rw-r--r--Xwt.Mac/Xwt.Mac/ScrollControlBackend.cs126
-rw-r--r--Xwt.Mac/Xwt.Mac/ScrollViewBackend.cs44
-rw-r--r--Xwt.Mac/Xwt.Mac/TableViewBackend.cs30
5 files changed, 217 insertions, 4 deletions
diff --git a/Xwt.Mac/Xwt.Mac.csproj b/Xwt.Mac/Xwt.Mac.csproj
index d4bfba05..0345ccc6 100644
--- a/Xwt.Mac/Xwt.Mac.csproj
+++ b/Xwt.Mac/Xwt.Mac.csproj
@@ -124,6 +124,7 @@
<Compile Include="Xwt.Mac\MacKeyboardHandler.cs" />
<Compile Include="Xwt.Mac\PasswordEntryBackend.cs" />
<Compile Include="Xwt.Mac\WebViewBackend.cs" />
+ <Compile Include="Xwt.Mac\ScrollControlBackend.cs" />
</ItemGroup>
<Import Project="..\BuildHelpers.targets" />
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
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
new file mode 100644
index 00000000..6ea939a7
--- /dev/null
+++ b/Xwt.Mac/Xwt.Mac/ScrollControlBackend.cs
@@ -0,0 +1,126 @@
+//
+// ScrollControlBackend.cs
+//
+// Author:
+// Lluis Sanchez <lluis@xamarin.com>
+//
+// Copyright (c) 2012 Xamarin Inc
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+using System;
+using Xwt.Backends;
+using MonoMac.AppKit;
+using MonoMac.Foundation;
+
+
+namespace Xwt.Mac
+{
+ class ScrollControlBackend: IScrollControlBackend
+ {
+ bool vertical;
+ NSScrollView scrollView;
+ IScrollControlEventSink eventSink;
+ ApplicationContext appContext;
+ double lastValue;
+
+ 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
+ public void InitializeBackend (object frontend, ApplicationContext context)
+ {
+ }
+
+ public void EnableEvent (object eventId)
+ {
+ }
+
+ public void DisableEvent (object eventId)
+ {
+ }
+ #endregion
+
+ #region IScrollAdjustmentBackend implementation
+ public void Initialize (IScrollControlEventSink eventSink)
+ {
+ this.eventSink = eventSink;
+ }
+
+ public double Value {
+ get {
+ if (vertical)
+ return scrollView.DocumentVisibleRect.Y;
+ else
+ return scrollView.DocumentVisibleRect.X;
+ }
+ set {
+ if (vertical)
+ scrollView.ContentView.ScrollToPoint (new System.Drawing.PointF (scrollView.DocumentVisibleRect.X, (float)value));
+ else
+ scrollView.ContentView.ScrollToPoint (new System.Drawing.PointF ((float)value, scrollView.DocumentVisibleRect.Y));
+ scrollView.ReflectScrolledClipView (scrollView.ContentView);
+ }
+ }
+
+ public double LowerValue {
+ get {
+ return 0;
+ }
+ }
+
+ public double UpperValue {
+ get { return vertical ? scrollView.ContentSize.Height : scrollView.ContentSize.Width; }
+ }
+
+ public double PageIncrement {
+ get {
+ return vertical ? scrollView.VerticalPageScroll : scrollView.HorizontalPageScroll;
+ }
+ }
+
+ public double PageSize {
+ get {
+ return vertical ? scrollView.DocumentVisibleRect.Height : scrollView.DocumentVisibleRect.Width;
+ }
+ }
+
+ public double StepIncrement {
+ get {
+ return vertical ? scrollView.VerticalLineScroll : scrollView.HorizontalLineScroll;
+ }
+ }
+ #endregion
+ }
+}
+
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 41439dd6..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;
@@ -112,7 +116,31 @@ namespace Xwt.Mac
}
}
}
-
+
+ ScrollControlBackend vertScroll;
+ public IScrollControlBackend CreateVerticalScrollControl ()
+ {
+ if (vertScroll == null)
+ vertScroll = new ScrollControlBackend (ApplicationContext, scroll, true);
+ return vertScroll;
+ }
+
+ ScrollControlBackend horScroll;
+ public IScrollControlBackend CreateHorizontalScrollControl ()
+ {
+ 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 ()
{
return EventSink.GetDefaultNaturalSize ();