Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / wpf / src / Framework / System / Windows / Automation / Peers / ScrollViewerAutomationPeer.cs / 1305600 / ScrollViewerAutomationPeer.cs
using System; using System.Globalization; using System.Runtime.InteropServices; using System.Security; using System.Text; using System.Windows; using System.Windows.Automation.Provider; using System.Windows.Controls; using System.Windows.Interop; using System.Windows.Media; using MS.Internal; using MS.Win32; namespace System.Windows.Automation.Peers { /// public class ScrollViewerAutomationPeer : FrameworkElementAutomationPeer, IScrollProvider { /// public ScrollViewerAutomationPeer(ScrollViewer owner): base(owner) {} /// override protected string GetClassNameCore() { return "ScrollViewer"; } /// override protected AutomationControlType GetAutomationControlTypeCore() { return AutomationControlType.Pane; } /// override protected bool IsControlElementCore() { // Return true if ScrollViewer is not part of the style return ((ScrollViewer)Owner).TemplatedParent == null; } /// override public object GetPattern(PatternInterface patternInterface) { if (patternInterface == PatternInterface.Scroll) { return this; } else { return base.GetPattern(patternInterface); } } //-------------------------------------------------------------------- // // IScrollProvider // //------------------------------------------------------------------- ////// Request to scroll horizontally and vertically by the specified amount. /// The ability to call this method and simultaneously scroll horizontally /// and vertically provides simple panning support. /// ///void IScrollProvider.Scroll(ScrollAmount horizontalAmount, ScrollAmount verticalAmount) { if(!IsEnabled()) throw new ElementNotEnabledException(); bool scrollHorizontally = (horizontalAmount != ScrollAmount.NoAmount); bool scrollVertically = (verticalAmount != ScrollAmount.NoAmount); ScrollViewer owner = (ScrollViewer)Owner; if (scrollHorizontally && !HorizontallyScrollable || scrollVertically && !VerticallyScrollable) { throw new InvalidOperationException(SR.Get(SRID.UIA_OperationCannotBePerformed)); } switch (horizontalAmount) { case ScrollAmount.LargeDecrement: owner.PageLeft(); break; case ScrollAmount.SmallDecrement: owner.LineLeft(); break; case ScrollAmount.SmallIncrement: owner.LineRight(); break; case ScrollAmount.LargeIncrement: owner.PageRight(); break; case ScrollAmount.NoAmount: break; default: throw new InvalidOperationException(SR.Get(SRID.UIA_OperationCannotBePerformed)); } switch (verticalAmount) { case ScrollAmount.LargeDecrement: owner.PageUp(); break; case ScrollAmount.SmallDecrement: owner.LineUp(); break; case ScrollAmount.SmallIncrement: owner.LineDown(); break; case ScrollAmount.LargeIncrement: owner.PageDown(); break; case ScrollAmount.NoAmount: break; default: throw new InvalidOperationException(SR.Get(SRID.UIA_OperationCannotBePerformed)); } } /// /// Request to set the current horizontal and Vertical scroll position by percent (0-100). /// Passing in the value of "-1", represented by the constant "NoScroll", will indicate that scrolling /// in that direction should be ignored. /// The ability to call this method and simultaneously scroll horizontally and vertically provides simple panning support. /// ///void IScrollProvider.SetScrollPercent(double horizontalPercent, double verticalPercent) { if(!IsEnabled()) throw new ElementNotEnabledException(); bool scrollHorizontally = (horizontalPercent != (double)ScrollPatternIdentifiers.NoScroll); bool scrollVertically = (verticalPercent != (double)ScrollPatternIdentifiers.NoScroll); ScrollViewer owner = (ScrollViewer)Owner; if (scrollHorizontally && !HorizontallyScrollable || scrollVertically && !VerticallyScrollable) { throw new InvalidOperationException(SR.Get(SRID.UIA_OperationCannotBePerformed)); } if (scrollHorizontally && (horizontalPercent < 0.0) || (horizontalPercent > 100.0)) { throw new ArgumentOutOfRangeException("horizontalPercent", SR.Get(SRID.ScrollViewer_OutOfRange, "horizontalPercent", horizontalPercent.ToString(CultureInfo.InvariantCulture), "0", "100")); } if (scrollVertically && (verticalPercent < 0.0) || (verticalPercent > 100.0)) { throw new ArgumentOutOfRangeException("verticalPercent", SR.Get(SRID.ScrollViewer_OutOfRange, "verticalPercent", verticalPercent.ToString(CultureInfo.InvariantCulture), "0", "100")); } if (scrollHorizontally) { owner.ScrollToHorizontalOffset((owner.ExtentWidth - owner.ViewportWidth) * (double)horizontalPercent * 0.01); } if (scrollVertically) { owner.ScrollToVerticalOffset((owner.ExtentHeight - owner.ViewportHeight) * (double)verticalPercent * 0.01); } } /// /// Get the current horizontal scroll position /// ///double IScrollProvider.HorizontalScrollPercent { get { if (!HorizontallyScrollable) { return ScrollPatternIdentifiers.NoScroll; } ScrollViewer owner = (ScrollViewer)Owner; return (double)(owner.HorizontalOffset * 100.0 / (owner.ExtentWidth - owner.ViewportWidth)); } } /// /// Get the current vertical scroll position /// ///double IScrollProvider.VerticalScrollPercent { get { if (!VerticallyScrollable) { return ScrollPatternIdentifiers.NoScroll; } ScrollViewer owner = (ScrollViewer)Owner; return (double)(owner.VerticalOffset * 100.0 / (owner.ExtentHeight - owner.ViewportHeight)); } } /// /// Equal to the horizontal percentage of the entire control that is currently viewable. /// ///double IScrollProvider.HorizontalViewSize { get { ScrollViewer owner = (ScrollViewer)Owner; if (owner.ScrollInfo == null || DoubleUtil.IsZero(owner.ExtentWidth)) { return 100.0; } return Math.Min(100.0, (double)(owner.ViewportWidth * 100.0 / owner.ExtentWidth)); } } /// /// Equal to the vertical percentage of the entire control that is currently viewable. /// ///double IScrollProvider.VerticalViewSize { get { ScrollViewer owner = (ScrollViewer)Owner; if (owner.ScrollInfo == null || DoubleUtil.IsZero(owner.ExtentHeight)) { return 100f; } return Math.Min(100.0, (double)(owner.ViewportHeight * 100.0 / owner.ExtentHeight)); } } /// /// True if control can scroll horizontally /// ///bool IScrollProvider.HorizontallyScrollable { get { return HorizontallyScrollable; } } /// /// True if control can scroll vertically /// ///bool IScrollProvider.VerticallyScrollable { get { return VerticallyScrollable; } } private static bool AutomationIsScrollable(double extent, double viewport) { return DoubleUtil.GreaterThan(extent, viewport); } private static double AutomationGetScrollPercent(double extent, double viewport, double actualOffset) { if (!AutomationIsScrollable(extent, viewport)) { return ScrollPatternIdentifiers.NoScroll; } return (double)(actualOffset * 100.0 / (extent - viewport)); } private static double AutomationGetViewSize(double extent, double viewport) { if (DoubleUtil.IsZero(extent)) { return 100.0; } return Math.Min(100.0, (double)(viewport * 100.0 / extent)); } // Private *Scrollable properties used to determine scrollability for IScrollProvider implemenation. private bool HorizontallyScrollable { get { ScrollViewer owner = (ScrollViewer)Owner; return owner.ScrollInfo != null && DoubleUtil.GreaterThan(owner.ExtentWidth, owner.ViewportWidth); } } private bool VerticallyScrollable { get { ScrollViewer owner = (ScrollViewer)Owner; return owner.ScrollInfo != null && DoubleUtil.GreaterThan(owner.ExtentHeight, owner.ViewportHeight); } } // This helper synchronously fires automation PropertyChange events for every IScrollProvider property that has changed. // [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] internal void RaiseAutomationEvents(double extentX, double extentY, double viewportX, double viewportY, double offsetX, double offsetY) { IScrollProvider isp = (IScrollProvider)this; if (AutomationIsScrollable(extentX, viewportX) != isp.HorizontallyScrollable) { RaisePropertyChangedEvent( ScrollPatternIdentifiers.HorizontallyScrollableProperty, AutomationIsScrollable(extentX, viewportX), isp.HorizontallyScrollable); } if (AutomationIsScrollable(extentY, viewportY) != isp.VerticallyScrollable) { RaisePropertyChangedEvent( ScrollPatternIdentifiers.VerticallyScrollableProperty, AutomationIsScrollable(extentY, viewportY), isp.VerticallyScrollable); } if (AutomationGetViewSize(extentX, viewportX) != isp.HorizontalViewSize) { RaisePropertyChangedEvent( ScrollPatternIdentifiers.HorizontalViewSizeProperty, AutomationGetViewSize(extentX, viewportX), isp.HorizontalViewSize); } if (AutomationGetViewSize(extentY, viewportY) != isp.VerticalViewSize) { RaisePropertyChangedEvent( ScrollPatternIdentifiers.VerticalViewSizeProperty, AutomationGetViewSize(extentY, viewportY), isp.VerticalViewSize); } if (AutomationGetScrollPercent(extentX, viewportX, offsetX) != isp.HorizontalScrollPercent) { RaisePropertyChangedEvent( ScrollPatternIdentifiers.HorizontalScrollPercentProperty, AutomationGetScrollPercent(extentX, viewportX, offsetX), isp.HorizontalScrollPercent); } if (AutomationGetScrollPercent(extentY, viewportY, offsetY) != isp.VerticalScrollPercent) { RaisePropertyChangedEvent( ScrollPatternIdentifiers.VerticalScrollPercentProperty, AutomationGetScrollPercent(extentY, viewportY, offsetY), isp.VerticalScrollPercent); } } } } // 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
- ConfigXmlWhitespace.cs
- ResourceDisplayNameAttribute.cs
- Message.cs
- TextTreeObjectNode.cs
- WebHttpSecurity.cs
- RuntimeHandles.cs
- Matrix3D.cs
- ColumnResizeAdorner.cs
- IOException.cs
- PaintValueEventArgs.cs
- PackWebRequest.cs
- TextParagraph.cs
- FactoryGenerator.cs
- ConstructorExpr.cs
- ServicePointManagerElement.cs
- FrameworkContextData.cs
- SortDescriptionCollection.cs
- SourceFileBuildProvider.cs
- PrintDocument.cs
- IgnorePropertiesAttribute.cs
- DecimalFormatter.cs
- DefaultBinder.cs
- PrintPreviewGraphics.cs
- AssemblyHash.cs
- CultureMapper.cs
- RuntimeArgumentHandle.cs
- OpCopier.cs
- SamlAttributeStatement.cs
- SqlServices.cs
- DataSourceXmlAttributeAttribute.cs
- DbReferenceCollection.cs
- Pair.cs
- TabControlEvent.cs
- SerTrace.cs
- SqlErrorCollection.cs
- BrowserCapabilitiesCodeGenerator.cs
- CopyOnWriteList.cs
- XmlHierarchyData.cs
- RijndaelManagedTransform.cs
- Configuration.cs
- ReverseInheritProperty.cs
- MemberInfoSerializationHolder.cs
- ShapingWorkspace.cs
- BinaryUtilClasses.cs
- SystemMulticastIPAddressInformation.cs
- MatrixIndependentAnimationStorage.cs
- MouseEventArgs.cs
- ExpressionBindings.cs
- Clock.cs
- __Filters.cs
- DiscardableAttribute.cs
- LinkDescriptor.cs
- SqlInfoMessageEvent.cs
- ISAPIRuntime.cs
- ViewGenerator.cs
- PersonalizationStateInfo.cs
- documentsequencetextview.cs
- XmlTextReaderImplHelpers.cs
- DocumentViewerHelper.cs
- SHA256Cng.cs
- PointLight.cs
- EventToken.cs
- SafePEFileHandle.cs
- TokenBasedSet.cs
- XhtmlConformanceSection.cs
- NullableDecimalMinMaxAggregationOperator.cs
- AmbiguousMatchException.cs
- SettingsAttributeDictionary.cs
- XmlUrlResolver.cs
- DispatcherEventArgs.cs
- TableStyle.cs
- Button.cs
- Speller.cs
- ScrollItemProviderWrapper.cs
- IOThreadTimer.cs
- TableCell.cs
- SoapFormatter.cs
- FixedBufferAttribute.cs
- OdbcDataReader.cs
- ArcSegment.cs
- MouseWheelEventArgs.cs
- ButtonFlatAdapter.cs
- IdentityHolder.cs
- FullTextBreakpoint.cs
- DataGridViewCellStyle.cs
- Binding.cs
- DbConnectionPoolGroup.cs
- infer.cs
- ArrayWithOffset.cs
- ScriptResourceAttribute.cs
- XmlUrlResolver.cs
- SystemIPGlobalStatistics.cs
- TimeSpanStorage.cs
- ConvertEvent.cs
- ProxyGenerator.cs
- HtmlTernaryTree.cs
- XmlDataProvider.cs
- WebControlAdapter.cs
- TextRenderer.cs
- ScopeElement.cs