Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / wpf / src / Framework / MS / Internal / documents / ScrollData.cs / 1305600 / ScrollData.cs
//----------------------------------------------------------------------------
//
// Copyright (C) Microsoft Corporation. All rights reserved.
//
// File: ScrollData.cs
//
// Description: IScrollInfo implementation helper for FlowDocumentView, TextBoxView.
//
//---------------------------------------------------------------------------
namespace MS.Internal.Documents
{
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using MS.Internal;
// IScrollInfo implementation helper for FlowDocumentView, TextBoxView.
internal class ScrollData
{
//-------------------------------------------------------------------
//
// Internal Methods
//
//-------------------------------------------------------------------
#region Internal Methods
///
///
///
internal void LineUp(UIElement owner)
{
SetVerticalOffset(owner, _offset.Y - ScrollViewer._scrollLineDelta);
}
///
///
///
internal void LineDown(UIElement owner)
{
SetVerticalOffset(owner, _offset.Y + ScrollViewer._scrollLineDelta);
}
///
///
///
internal void LineLeft(UIElement owner)
{
SetHorizontalOffset(owner, _offset.X - ScrollViewer._scrollLineDelta);
}
///
///
///
internal void LineRight(UIElement owner)
{
SetHorizontalOffset(owner, _offset.X + ScrollViewer._scrollLineDelta);
}
///
///
///
internal void PageUp(UIElement owner)
{
SetVerticalOffset(owner, _offset.Y - _viewport.Height);
}
///
///
///
internal void PageDown(UIElement owner)
{
SetVerticalOffset(owner, _offset.Y + _viewport.Height);
}
///
///
///
internal void PageLeft(UIElement owner)
{
SetHorizontalOffset(owner, _offset.X - _viewport.Width);
}
///
///
///
internal void PageRight(UIElement owner)
{
SetHorizontalOffset(owner, _offset.X + _viewport.Width);
}
///
///
///
internal void MouseWheelUp(UIElement owner)
{
SetVerticalOffset(owner, _offset.Y - ScrollViewer._mouseWheelDelta);
}
///
///
///
internal void MouseWheelDown(UIElement owner)
{
SetVerticalOffset(owner, _offset.Y + ScrollViewer._mouseWheelDelta);
}
///
///
///
internal void MouseWheelLeft(UIElement owner)
{
SetHorizontalOffset(owner, _offset.X - ScrollViewer._mouseWheelDelta);
}
///
///
///
internal void MouseWheelRight(UIElement owner)
{
SetHorizontalOffset(owner, _offset.X + ScrollViewer._mouseWheelDelta);
}
///
///
///
internal void SetHorizontalOffset(UIElement owner, double offset)
{
if (!this.CanHorizontallyScroll)
{
return;
}
offset = Math.Max(0, Math.Min(_extent.Width - _viewport.Width, offset));
if (!DoubleUtil.AreClose(offset, _offset.X))
{
_offset.X = offset;
owner.InvalidateArrange();
if (_scrollOwner != null)
{
_scrollOwner.InvalidateScrollInfo();
}
}
}
///
///
///
internal void SetVerticalOffset(UIElement owner, double offset)
{
if (!this.CanVerticallyScroll)
{
return;
}
offset = Math.Max(0, Math.Min(_extent.Height - _viewport.Height, offset));
if (!DoubleUtil.AreClose(offset, _offset.Y))
{
_offset.Y = offset;
owner.InvalidateArrange();
if (_scrollOwner != null)
{
_scrollOwner.InvalidateScrollInfo();
}
}
}
///
///
///
internal Rect MakeVisible(UIElement owner, Visual visual, Rect rectangle)
{
// We can only work on visuals that are us or children.
// An empty rect has no size or position. We can't meaningfully use it.
if (rectangle.IsEmpty ||
visual == null ||
(visual != owner && !owner.IsAncestorOf(visual)))
{
return Rect.Empty;
}
// Compute the child's rect relative to (0,0) in our coordinate space.
GeneralTransform childTransform = visual.TransformToAncestor(owner);
rectangle = childTransform.TransformBounds(rectangle);
// Initialize the viewport
Rect viewport = new Rect(_offset.X, _offset.Y, _viewport.Width, _viewport.Height);
rectangle.X += viewport.X;
rectangle.Y += viewport.Y;
// Compute the offsets required to minimally scroll the child maximally into view.
double minX = ComputeScrollOffset(viewport.Left, viewport.Right, rectangle.Left, rectangle.Right);
double minY = ComputeScrollOffset(viewport.Top, viewport.Bottom, rectangle.Top, rectangle.Bottom);
// We have computed the scrolling offsets; scroll to them.
SetHorizontalOffset(owner, minX);
SetVerticalOffset(owner, minY);
// Compute the visible rectangle of the child relative to the viewport.
if (this.CanHorizontallyScroll)
{
viewport.X = minX;
}
else
{
// munge the intersection
rectangle.X = viewport.X;
}
if (this.CanVerticallyScroll)
{
viewport.Y = minY;
}
else
{
// munge the intersection
rectangle.Y = viewport.Y;
}
rectangle.Intersect(viewport);
if (!rectangle.IsEmpty)
{
rectangle.X -= viewport.X;
rectangle.Y -= viewport.Y;
}
// Return the rectangle
return rectangle;
}
///
///
///
internal void SetScrollOwner(UIElement owner, ScrollViewer value)
{
if (value != _scrollOwner)
{
// Reset cached scroll info.
_disableHorizonalScroll = false;
_disableVerticalScroll = false;
_offset = new Vector();
_viewport = new Size();
_extent = new Size();
_scrollOwner = value;
owner.InvalidateArrange();
}
}
#endregion Internal Methods
//--------------------------------------------------------------------
//
// Internal Properties
//
//-------------------------------------------------------------------
#region Internal Properties
///
///
///
internal bool CanVerticallyScroll
{
get
{
return !_disableVerticalScroll;
}
set
{
_disableVerticalScroll = !value;
}
}
///
///
///
internal bool CanHorizontallyScroll
{
get
{
return !_disableHorizonalScroll;
}
set
{
_disableHorizonalScroll = !value;
}
}
///
///
///
internal double ExtentWidth
{
get
{
return _extent.Width;
}
set
{
_extent.Width = value;
}
}
///
///
///
internal double ExtentHeight
{
get
{
return _extent.Height;
}
set
{
_extent.Height = value;
}
}
///
///
///
internal double ViewportWidth
{
get
{
return _viewport.Width;
}
}
///
///
///
internal double ViewportHeight
{
get
{
return _viewport.Height;
}
}
///
///
///
internal double HorizontalOffset
{
get
{
return _offset.X;
}
}
///
///
///
internal double VerticalOffset
{
get
{
return _offset.Y;
}
}
///
///
///
internal ScrollViewer ScrollOwner
{
get
{
return _scrollOwner;
}
}
// HorizontalOffset/VerticalOffset as a Vector.
internal Vector Offset
{
get
{
return _offset;
}
set
{
_offset = value;
}
}
// ExtenttWidth/ExtentHeight as a Size.
internal Size Extent
{
get
{
return _extent;
}
set
{
_extent = value;
}
}
// ViewportWidth/ViewportHeight as a Size.
internal Size Viewport
{
get
{
return _viewport;
}
set
{
_viewport = value;
}
}
#endregion Internal Properties
//--------------------------------------------------------------------
//
// Private Methods
//
//--------------------------------------------------------------------
#region Private Methods
///
/// Compute scroll offset for child rectangle.
///
private double ComputeScrollOffset(double topView, double bottomView, double topChild, double bottomChild)
{
// # CHILD POSITION REMEDY
// 1 Above viewport Align top edge of child & viewport
// 2 Below viewport Align top edge of child & viewport
// 3 Entirely within viewport No scroll
// 4 Spanning viewport Align top edge of child & viewport
//
// Note: "Above viewport" = childTop above viewportTop, childBottom above viewportBottom
// "Below viewport" = childTop below viewportTop, childBottom below viewportBottom
// These child thus may overlap with the viewport, but will scroll the same direction/
bool topInView = DoubleUtil.GreaterThanOrClose(topChild, topView) && DoubleUtil.LessThan(topChild, bottomView);
bool bottomInView = DoubleUtil.LessThanOrClose(bottomChild, bottomView) && DoubleUtil.GreaterThan(bottomChild, topView);
double position;
if (topInView && bottomInView)
{
position = topView;
}
else
{
position = topChild;
}
return position;
}
#endregion Private Methods
//-------------------------------------------------------------------
//
// Private Fields
//
//--------------------------------------------------------------------
#region Private Fields
private bool _disableHorizonalScroll;
private bool _disableVerticalScroll;
private Vector _offset;
private Size _viewport;
private Size _extent;
private ScrollViewer _scrollOwner;
#endregion Private Fields
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- PageContentAsyncResult.cs
- XmlWrappingReader.cs
- XamlGridLengthSerializer.cs
- _LazyAsyncResult.cs
- DataControlField.cs
- SoapTypeAttribute.cs
- PersianCalendar.cs
- _ConnectionGroup.cs
- Expander.cs
- TreeNodeMouseHoverEvent.cs
- Stopwatch.cs
- OperationFormatter.cs
- AttachedPropertyBrowsableAttribute.cs
- XamlVector3DCollectionSerializer.cs
- XmlSchemaSimpleTypeList.cs
- DbSourceCommand.cs
- XmlNullResolver.cs
- File.cs
- FormatStringEditor.cs
- TrailingSpaceComparer.cs
- DoubleLinkList.cs
- FormViewPageEventArgs.cs
- DSASignatureDeformatter.cs
- RemotingException.cs
- UnsafeNativeMethods.cs
- SupportsPreviewControlAttribute.cs
- ProfileModule.cs
- WebPartHelpVerb.cs
- XmlCharType.cs
- RSACryptoServiceProvider.cs
- DocumentGridContextMenu.cs
- ProfilePropertySettingsCollection.cs
- ValidationError.cs
- EntityDesignerBuildProvider.cs
- CollectionContainer.cs
- BamlTreeUpdater.cs
- cryptoapiTransform.cs
- KeyedHashAlgorithm.cs
- TableLayoutStyleCollection.cs
- ObjectPersistData.cs
- GlyphRunDrawing.cs
- TemplateAction.cs
- DataAccessor.cs
- GacUtil.cs
- backend.cs
- EventLogPermission.cs
- indexingfiltermarshaler.cs
- SqlProviderServices.cs
- XmlElement.cs
- BaseTypeViewSchema.cs
- LinqDataSourceStatusEventArgs.cs
- AmbientLight.cs
- UrlMappingsSection.cs
- ValidationError.cs
- LoginCancelEventArgs.cs
- WebConfigurationHostFileChange.cs
- DrawingState.cs
- GridProviderWrapper.cs
- DataGridViewCellStyle.cs
- TickBar.cs
- TemplateBuilder.cs
- CancellationHandlerDesigner.cs
- Mappings.cs
- FreezableDefaultValueFactory.cs
- RegionInfo.cs
- TargetInvocationException.cs
- ServiceOperation.cs
- IgnoreSectionHandler.cs
- CryptoSession.cs
- SchemaNotation.cs
- MaterialCollection.cs
- BinaryObjectWriter.cs
- ListItemCollection.cs
- IgnoreSectionHandler.cs
- ApplicationManager.cs
- ConnectorDragDropGlyph.cs
- ProcessThreadCollection.cs
- StaticSiteMapProvider.cs
- FileLogRecordEnumerator.cs
- EncryptedData.cs
- Util.cs
- PropertyInfoSet.cs
- ObjectFactoryCodeDomTreeGenerator.cs
- CheckBoxPopupAdapter.cs
- XmlCompatibilityReader.cs
- SecurityTokenException.cs
- WebProxyScriptElement.cs
- CatalogPart.cs
- EUCJPEncoding.cs
- SegmentInfo.cs
- PageClientProxyGenerator.cs
- DynamicExpression.cs
- ConfigsHelper.cs
- SecurityState.cs
- FileEnumerator.cs
- PopupEventArgs.cs
- TextElement.cs
- CoTaskMemUnicodeSafeHandle.cs
- PersonalizationAdministration.cs
- Vector3D.cs