diff options
author | Lluis Sanchez Gual <lluis@xamarin.com> | 2014-02-19 17:47:56 +0400 |
---|---|---|
committer | Lluis Sanchez Gual <lluis@xamarin.com> | 2014-02-19 17:47:56 +0400 |
commit | 79a18e9797b85713512228930afa9cfd548778bd (patch) | |
tree | 9ebfb21fcb887d125243df4f52ea45b544ad04de /Xwt.Mac | |
parent | 2eb0e1eda6125a5fd450f7b5875141edecb184fd (diff) |
New ScrollControl class
This class is used instead of ScrollAdjustment for getting information about
scroll position and extents of a widget.
Diffstat (limited to 'Xwt.Mac')
-rw-r--r-- | Xwt.Mac/Xwt.Mac.csproj | 1 | ||||
-rw-r--r-- | Xwt.Mac/Xwt.Mac/ScrollControlBackend.cs | 116 | ||||
-rw-r--r-- | Xwt.Mac/Xwt.Mac/TableViewBackend.cs | 8 |
3 files changed, 121 insertions, 4 deletions
diff --git a/Xwt.Mac/Xwt.Mac.csproj b/Xwt.Mac/Xwt.Mac.csproj index 9921e770..ecafc808 100644 --- a/Xwt.Mac/Xwt.Mac.csproj +++ b/Xwt.Mac/Xwt.Mac.csproj @@ -126,6 +126,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/ScrollControlBackend.cs b/Xwt.Mac/Xwt.Mac/ScrollControlBackend.cs new file mode 100644 index 00000000..27c0361e --- /dev/null +++ b/Xwt.Mac/Xwt.Mac/ScrollControlBackend.cs @@ -0,0 +1,116 @@ +// +// 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; + + +namespace Xwt.Mac +{ + class ScrollControlBackend: IScrollControlBackend + { + bool vertical; + NSScrollView scrollView; + IScrollControlEventSink eventSink; + + public ScrollControlBackend (NSScrollView scrollView, bool vertical) + { + this.vertical = vertical; + this.scrollView = scrollView; + } + + #region IBackend implementation + public void InitializeBackend (object frontend, ApplicationContext context) + { + } + + public void EnableEvent (object eventId) + { + } + + public void DisableEvent (object eventId) + { + } + #endregion + + public void NotifyValueChanged () + { + eventSink.OnValueChanged (); + } + + #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.ScrollPoint (new System.Drawing.PointF (scrollView.DocumentVisibleRect.X, (float)value)); + else + scrollView.ScrollPoint (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/TableViewBackend.cs b/Xwt.Mac/Xwt.Mac/TableViewBackend.cs index 331248b4..e50d2ae3 100644 --- a/Xwt.Mac/Xwt.Mac/TableViewBackend.cs +++ b/Xwt.Mac/Xwt.Mac/TableViewBackend.cs @@ -113,14 +113,14 @@ namespace Xwt.Mac } } - public IScrollAdjustmentBackend CreateVerticalScrollAdjustment () + public IScrollControlBackend CreateVerticalScrollControl () { - return new ScrollAdjustmentBackend (scroll, true); + return new ScrollControlBackend (scroll, true); } - public IScrollAdjustmentBackend CreateHorizontalScrollAdjustment () + public IScrollControlBackend CreateHorizontalScrollControl () { - return new ScrollAdjustmentBackend (scroll, false); + return new ScrollControlBackend (scroll, false); } protected override Size GetNaturalSize () |