Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / wpf / src / Framework / MS / Internal / documents / TextViewBase.cs / 1305600 / TextViewBase.cs
//---------------------------------------------------------------------------- // // Copyright (C) Microsoft Corporation. All rights reserved. // // File: TextViewBase.cs // // Description: TextViewBase is a minimal base class, providing only // the functionality common across TextViews. // //--------------------------------------------------------------------------- using System; // InvalidOperationException, ... using System.Collections.Generic; // Listusing System.Collections.ObjectModel; // ReadOnlyCollection using System.Windows; // Point, Rect, ... using System.Windows.Controls.Primitives; // DocumentPageView using System.Windows.Documents; // ITextView, ITextContainer using System.Windows.Media; // VisualTreeHelper namespace MS.Internal.Documents { /// /// TextViewBase is a minimal base class, providing only the functionality /// common across TextViews. /// internal abstract class TextViewBase : ITextView { //------------------------------------------------------------------- // // Internal Methods // //------------------------------------------------------------------- #region Internal Methods ////// internal abstract ITextPointer GetTextPositionFromPoint(Point point, bool snapToText); ////// /// ////// /// Calls GetRawRectangleFromTextPosition to get a rect and a transform, and applies the transform to the /// rect. /// internal virtual Rect GetRectangleFromTextPosition(ITextPointer position) { Transform transform; Rect rect = GetRawRectangleFromTextPosition(position, out transform); // Transform must not be null. TextViews returning no transform should return identity Invariant.Assert(transform != null); if (rect != Rect.Empty) { rect = transform.TransformBounds(rect); } return rect; } ////// internal abstract Rect GetRawRectangleFromTextPosition(ITextPointer position, out Transform transform); ////// /// internal abstract Geometry GetTightBoundingGeometryFromTextPositions(ITextPointer startPosition, ITextPointer endPosition); ////// /// internal abstract ITextPointer GetPositionAtNextLine(ITextPointer position, double suggestedX, int count, out double newSuggestedX, out int linesMoved); ////// /// internal virtual ITextPointer GetPositionAtNextPage(ITextPointer position, Point suggestedOffset, int count, out Point newSuggestedOffset, out int pagesMoved) { newSuggestedOffset = suggestedOffset; pagesMoved = 0; return position; } ////// /// internal abstract bool IsAtCaretUnitBoundary(ITextPointer position); ////// /// internal abstract ITextPointer GetNextCaretUnitPosition(ITextPointer position, LogicalDirection direction); ////// /// internal abstract ITextPointer GetBackspaceCaretUnitPosition(ITextPointer position); ////// /// internal abstract TextSegment GetLineRange(ITextPointer position); ////// /// internal virtual ReadOnlyCollection/// GetGlyphRuns(ITextPointer start, ITextPointer end) { // Verify that layout information is valid. Cannot continue if not valid. if (!IsValid) { throw new InvalidOperationException(SR.Get(SRID.TextViewInvalidLayout)); } return new ReadOnlyCollection (new List ()); } /// /// internal abstract bool Contains(ITextPointer position); ////// /// Scroll the given rectangle the minimum amount required to bring it entirely into view. /// /// TextView doing the scrolling /// Rect to scroll ////// # RECT POSITION RECT SIZE SCROLL REMEDY /// 1 Above viewport lte viewport Down Align top edge of rect and viewport /// 2 Above viewport gt viewport Down Align bottom edge of rect and viewport /// 3 Below viewport lte viewport Up Align bottom edge of rect and viewport /// 4 Below viewport gt viewport Up Align top edge of rect and viewport /// 5 Entirely within viewport NA No scroll. /// 6 Spanning viewport NA No scroll. /// internal static void BringRectIntoViewMinimally(ITextView textView, Rect rect) { IScrollInfo isi = textView.RenderScope as IScrollInfo; if (isi != null) { // Initialize the viewport Rect viewport = new Rect(isi.HorizontalOffset, isi.VerticalOffset, isi.ViewportWidth, isi.ViewportHeight); rect.X += viewport.X; rect.Y += viewport.Y; // Compute the offsets required to minimally scroll the child maximally into view. double minX = System.Windows.Controls.ScrollContentPresenter.ComputeScrollOffsetWithMinimalScroll(viewport.Left, viewport.Right, rect.Left, rect.Right); double minY = System.Windows.Controls.ScrollContentPresenter.ComputeScrollOffsetWithMinimalScroll(viewport.Top, viewport.Bottom, rect.Top, rect.Bottom); // We have computed the scrolling offsets; scroll to them. isi.SetHorizontalOffset(minX); isi.SetVerticalOffset(minY); // Adjust rect to reflect changes and allow outer IScrollInfos to react FrameworkElement frameworkParent = FrameworkElement.GetFrameworkParent(textView.RenderScope) as FrameworkElement; if (frameworkParent != null) { if (isi.ViewportWidth > 0) { rect.X -= minX; } if (isi.ViewportHeight > 0) { rect.Y -= minY; } frameworkParent.BringIntoView(rect); } } else { ((FrameworkElement)textView.RenderScope).BringIntoView(rect); } } ////// internal virtual void BringPositionIntoViewAsync(ITextPointer position, object userState) { // Verify that layout information is valid. Cannot continue if not valid. if (!IsValid) { throw new InvalidOperationException(SR.Get(SRID.TextViewInvalidLayout)); } OnBringPositionIntoViewCompleted(new BringPositionIntoViewCompletedEventArgs(position, Contains(position), null, false, userState)); } ////// /// internal virtual void BringPointIntoViewAsync(Point point, object userState) { ITextPointer position; // Verify that layout information is valid. Cannot continue if not valid. if (!IsValid) { throw new InvalidOperationException(SR.Get(SRID.TextViewInvalidLayout)); } position = GetTextPositionFromPoint(point, true); OnBringPointIntoViewCompleted(new BringPointIntoViewCompletedEventArgs(point, position, position != null, null, false, userState)); } ////// /// internal virtual void BringLineIntoViewAsync(ITextPointer position, double suggestedX, int count, object userState) { ITextPointer newPosition; double newSuggestedX; int linesMoved; // Verify that layout information is valid. Cannot continue if not valid. if (!IsValid) { throw new InvalidOperationException(SR.Get(SRID.TextViewInvalidLayout)); } newPosition = GetPositionAtNextLine(position, suggestedX, count, out newSuggestedX, out linesMoved); OnBringLineIntoViewCompleted(new BringLineIntoViewCompletedEventArgs(position, suggestedX, count, newPosition, newSuggestedX, linesMoved, linesMoved == count, null, false, userState)); } ////// /// internal virtual void BringPageIntoViewAsync(ITextPointer position, Point suggestedOffset, int count, object userState) { ITextPointer newPosition; Point newSuggestedOffset; int pagesMoved; // Verify that layout information is valid. Cannot continue if not valid. if (!IsValid) { throw new InvalidOperationException(SR.Get(SRID.TextViewInvalidLayout)); } newPosition = GetPositionAtNextPage(position, suggestedOffset, count, out newSuggestedOffset, out pagesMoved); OnBringPageIntoViewCompleted(new BringPageIntoViewCompletedEventArgs(position, suggestedOffset, count, newPosition, newSuggestedOffset, pagesMoved, pagesMoved == count, null, false, userState)); } ////// /// internal virtual void CancelAsync(object userState) { } ////// /// internal virtual bool Validate() { return this.IsValid; } ////// /// internal virtual bool Validate(Point point) { return Validate(); } ////// /// internal virtual bool Validate(ITextPointer position) { Validate(); return (this.IsValid && this.Contains(position)); } ////// /// internal virtual void ThrottleBackgroundTasksForUserInput() { } #endregion Internal Methods //-------------------------------------------------------------------- // // Internal Properties // //------------------------------------------------------------------- #region Internal Properties ////// /// internal abstract UIElement RenderScope { get; } ////// /// internal abstract ITextContainer TextContainer { get; } ////// /// internal abstract bool IsValid { get; } ////// /// internal virtual bool RendersOwnSelection { get { return false; } } ////// /// internal abstract ReadOnlyCollection/// TextSegments { get; } #endregion Internal Properties //-------------------------------------------------------------------- // // Public Events // //-------------------------------------------------------------------- #region Public Events /// /// public event BringPositionIntoViewCompletedEventHandler BringPositionIntoViewCompleted; ////// /// public event BringPointIntoViewCompletedEventHandler BringPointIntoViewCompleted; ////// /// public event BringLineIntoViewCompletedEventHandler BringLineIntoViewCompleted; ////// /// public event BringPageIntoViewCompletedEventHandler BringPageIntoViewCompleted; ////// /// public event EventHandler Updated; #endregion Public Events //------------------------------------------------------------------- // // Protected Methods // //-------------------------------------------------------------------- #region Protected Methods ////// /// Fires BringPositionIntoViewCompleted event. /// /// Event arguments for the BringPositionIntoViewCompleted event. protected virtual void OnBringPositionIntoViewCompleted(BringPositionIntoViewCompletedEventArgs e) { if (this.BringPositionIntoViewCompleted != null) { this.BringPositionIntoViewCompleted(this, e); } } ////// Fires BringPointIntoViewCompleted event. /// /// Event arguments for the BringPointIntoViewCompleted event. protected virtual void OnBringPointIntoViewCompleted(BringPointIntoViewCompletedEventArgs e) { if (this.BringPointIntoViewCompleted != null) { this.BringPointIntoViewCompleted(this, e); } } ////// Fires BringLineIntoViewCompleted event. /// /// Event arguments for the BringLineIntoViewCompleted event. protected virtual void OnBringLineIntoViewCompleted(BringLineIntoViewCompletedEventArgs e) { if (this.BringLineIntoViewCompleted != null) { this.BringLineIntoViewCompleted(this, e); } } ////// Fires BringPageIntoViewCompleted event. /// /// Event arguments for the BringPageIntoViewCompleted event. protected virtual void OnBringPageIntoViewCompleted(BringPageIntoViewCompletedEventArgs e) { if (this.BringPageIntoViewCompleted != null) { this.BringPageIntoViewCompleted(this, e); } } ////// Fires Updated event. /// /// Event arguments for the Updated event. protected virtual void OnUpdated(EventArgs e) { if (this.Updated != null) { this.Updated(this, e); } } ////// Returns aggregate of two transforms /// ////// If either transform is identity, aggregation is not needed and the other transform is returned. /// Otherwise returns a matrix transform whose value is the product of first and second transform values. /// protected virtual Transform GetAggregateTransform(Transform firstTransform, Transform secondTransform) { Invariant.Assert(firstTransform != null); Invariant.Assert(secondTransform != null); if (firstTransform.IsIdentity) { // First transform is Identity. No aggregation needed. Return second transform. return secondTransform; } else if (secondTransform.IsIdentity) { // Second transform is Identity. No aggregation needed. Return first transform. return firstTransform; } // Both transforms are non-identity. Return matrix transform that is the product of firstTransform * secondTransform Transform transform = new MatrixTransform(firstTransform.Value * secondTransform.Value); return transform; } #endregion Protected Methods //------------------------------------------------------------------- // // ITextView // //------------------------------------------------------------------- #region ITextView ////// ITextPointer ITextView.GetTextPositionFromPoint(Point point, bool snapToText) { return GetTextPositionFromPoint(point, snapToText); } ////// /// Rect ITextView.GetRectangleFromTextPosition(ITextPointer position) { return GetRectangleFromTextPosition(position); } ////// /// Rect ITextView.GetRawRectangleFromTextPosition(ITextPointer position, out Transform transform) { return GetRawRectangleFromTextPosition(position, out transform); } ////// /// Geometry ITextView.GetTightBoundingGeometryFromTextPositions(ITextPointer startPosition, ITextPointer endPosition) { return GetTightBoundingGeometryFromTextPositions(startPosition, endPosition); } ////// /// ITextPointer ITextView.GetPositionAtNextLine(ITextPointer position, double suggestedX, int count, out double newSuggestedX, out int linesMoved) { return GetPositionAtNextLine(position, suggestedX, count, out newSuggestedX, out linesMoved); } ////// /// ITextPointer ITextView.GetPositionAtNextPage(ITextPointer position, Point suggestedOffset, int count, out Point newSuggestedOffset, out int pagesMoved) { return GetPositionAtNextPage(position, suggestedOffset, count, out newSuggestedOffset, out pagesMoved); } ////// /// bool ITextView.IsAtCaretUnitBoundary(ITextPointer position) { return IsAtCaretUnitBoundary(position); } ////// /// ITextPointer ITextView.GetNextCaretUnitPosition(ITextPointer position, LogicalDirection direction) { return GetNextCaretUnitPosition(position, direction); } ////// /// ITextPointer ITextView.GetBackspaceCaretUnitPosition(ITextPointer position) { return GetBackspaceCaretUnitPosition(position); } ////// /// TextSegment ITextView.GetLineRange(ITextPointer position) { return GetLineRange(position); } ////// /// ReadOnlyCollection/// ITextView.GetGlyphRuns(ITextPointer start, ITextPointer end) { return GetGlyphRuns(start, end); } /// /// bool ITextView.Contains(ITextPointer position) { return Contains(position); } ////// /// void ITextView.BringPositionIntoViewAsync(ITextPointer position, object userState) { BringPositionIntoViewAsync(position, userState); } ////// /// void ITextView.BringPointIntoViewAsync(Point point, object userState) { BringPointIntoViewAsync(point, userState); } ////// /// void ITextView.BringLineIntoViewAsync(ITextPointer position, double suggestedX, int count, object userState) { BringLineIntoViewAsync(position, suggestedX, count, userState); } ////// /// void ITextView.BringPageIntoViewAsync(ITextPointer position, Point suggestedOffset, int count, object userState) { BringPageIntoViewAsync(position, suggestedOffset, count, userState); } ////// /// void ITextView.CancelAsync(object userState) { CancelAsync(userState); } ////// /// bool ITextView.Validate() { return Validate(); } ////// /// bool ITextView.Validate(Point point) { return Validate(point); } ////// /// bool ITextView.Validate(ITextPointer position) { return Validate(position); } ////// /// void ITextView.ThrottleBackgroundTasksForUserInput() { ThrottleBackgroundTasksForUserInput(); } ////// /// UIElement ITextView.RenderScope { get { return RenderScope; } } ////// /// ITextContainer ITextView.TextContainer { get { return TextContainer; } } ////// /// bool ITextView.IsValid { get { return IsValid; } } ////// /// bool ITextView.RendersOwnSelection { get { return RendersOwnSelection; } } ////// /// ReadOnlyCollection/// ITextView.TextSegments { get { return TextSegments; } } #endregion ITextView } } // 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
- Soap.cs
- DesignerLoader.cs
- HelpInfo.cs
- CommonObjectSecurity.cs
- GridViewRowPresenter.cs
- XmlValueConverter.cs
- Rfc4050KeyFormatter.cs
- EntityParameter.cs
- GenericTypeParameterConverter.cs
- ToolstripProfessionalRenderer.cs
- FilteredAttributeCollection.cs
- InternalConfigConfigurationFactory.cs
- FileLogRecordHeader.cs
- ControlEvent.cs
- listviewsubitemcollectioneditor.cs
- DynamicPropertyHolder.cs
- TemplatedMailWebEventProvider.cs
- XmlTextEncoder.cs
- XPathExpr.cs
- NetworkInformationPermission.cs
- TextEffectResolver.cs
- SvcMapFileLoader.cs
- PageStatePersister.cs
- OdbcConnection.cs
- ConfigDefinitionUpdates.cs
- ProfilePropertySettingsCollection.cs
- SchemaImporter.cs
- DataGridBoolColumn.cs
- PathSegmentCollection.cs
- X509ChainPolicy.cs
- DetailsViewUpdateEventArgs.cs
- Constraint.cs
- HttpServerVarsCollection.cs
- ComponentChangingEvent.cs
- CacheEntry.cs
- EditorZoneBase.cs
- SHA256.cs
- SQLDecimal.cs
- ChannelServices.cs
- DnsPermission.cs
- OutputCacheSettings.cs
- SurrogateSelector.cs
- SectionUpdates.cs
- IdentifierService.cs
- IndexedString.cs
- SequenceFullException.cs
- File.cs
- WebResourceUtil.cs
- infer.cs
- HtmlTableRow.cs
- ToolStripPanelRow.cs
- ProfileEventArgs.cs
- SpAudioStreamWrapper.cs
- RoleService.cs
- CompositeCollection.cs
- XmlSchemaGroupRef.cs
- RecordManager.cs
- GeometryHitTestResult.cs
- Currency.cs
- DelegateBodyWriter.cs
- HandlerWithFactory.cs
- PageParserFilter.cs
- Mapping.cs
- _Rfc2616CacheValidators.cs
- DesignerSerializationManager.cs
- XamlStyleSerializer.cs
- ColorDialog.cs
- EmbeddedMailObject.cs
- WmpBitmapEncoder.cs
- TimeoutValidationAttribute.cs
- SmtpAuthenticationManager.cs
- TypeToStringValueConverter.cs
- Highlights.cs
- ReadOnlyCollection.cs
- ConsoleKeyInfo.cs
- Parser.cs
- ADMembershipUser.cs
- ServiceNameElementCollection.cs
- _NTAuthentication.cs
- Pkcs9Attribute.cs
- complextypematerializer.cs
- EventLogPermission.cs
- ProcessThreadCollection.cs
- AnnotationService.cs
- AddInServer.cs
- AuditLog.cs
- MetafileEditor.cs
- XmlSchemaDocumentation.cs
- Matrix.cs
- BoolExpression.cs
- SamlSecurityTokenAuthenticator.cs
- RubberbandSelector.cs
- WindowsGraphicsWrapper.cs
- GridViewSortEventArgs.cs
- WriterOutput.cs
- WebSysDescriptionAttribute.cs
- TextViewBase.cs
- JsonWriter.cs
- AsymmetricSignatureFormatter.cs
- TypeNameParser.cs