/// <summary> /// <see cref="ITextView.BringLineIntoViewAsync"/> /// </summary> internal override void BringLineIntoViewAsync(ITextPointer position, double suggestedX, int count, object userState) { // Verify that layout information is valid. Cannot continue if not valid. if (!IsValid) { throw new InvalidOperationException(SR.Get(SRID.TextViewInvalidLayout)); } if (_pendingRequest != null) { // Ignore new request if the previous is not completed yet. OnBringLineIntoViewCompleted(new BringLineIntoViewCompletedEventArgs( position, suggestedX, count, position, suggestedX, 0, false, null, false, userState)); } else { _pendingRequest = new BringLineIntoViewRequest(position, suggestedX, count, userState); BringLineIntoViewCore((BringLineIntoViewRequest)_pendingRequest); } }
/// <summary> /// Bring line into view. /// </summary> private void BringLineIntoViewCore(BringLineIntoViewRequest request) { ITextPointer newPosition; double newSuggestedX; int linesMoved; int pageNumber; // Try to use existing TextViews to handle this request. newPosition = GetPositionAtNextLineCore(request.NewPosition, request.NewSuggestedX, request.NewCount, out newSuggestedX, out linesMoved, out pageNumber); Invariant.Assert(Math.Abs(request.NewCount) >= Math.Abs(linesMoved)); request.NewPosition = newPosition; request.NewSuggestedX = newSuggestedX; request.NewCount = request.NewCount - linesMoved; request.NewPageNumber = pageNumber; if (request.NewCount == 0) { OnBringLineIntoViewCompleted(request); } else { if (newPosition is DocumentSequenceTextPointer || newPosition is FixedTextPointer) { //Fixed generally uses a stitched viewing mechanism and the approach used for Flow does not work properly for Fixed //NextPage() call in DocumentViewer results in DocumentGrid.ScrollToNextRow() which scrolls to firstVisibleRow + 1 //E.g. if there are two views on the screen and we need to navigate to the third, this makes it impossible to achieve if (_viewer.CanGoToPage(pageNumber + 1)) { _viewer.GoToPage(pageNumber + 1); } else { OnBringLineIntoViewCompleted(request); } } else { if (request.NewCount > 0) { // If the viewer can navigate to the next page, request navigation and wait for // Updated event for the TextView. // If cannot to the next page, raise BringLineIntoViewCompleted with success = 'False'. if (_viewer.CanGoToNextPage) { _viewer.NextPage(); } else { OnBringLineIntoViewCompleted(request); } } else { // If the viewer can navigate to the previous page, request navigation and wait for // Updated event fo the TextView. // If cannot to the previous page, raise BringLineIntoViewCompleted with success = 'False'. if (_viewer.CanGoToPreviousPage) { _viewer.PreviousPage(); } else { OnBringLineIntoViewCompleted(request); } } } } }
/// <summary> /// Fires BringLineIntoViewCompleted event. /// </summary> private void OnBringLineIntoViewCompleted(BringLineIntoViewRequest request) { _pendingRequest = null; OnBringLineIntoViewCompleted(new BringLineIntoViewCompletedEventArgs( request.Position, request.SuggestedX, request.Count, request.NewPosition, request.NewSuggestedX, request.Count - request.NewCount, request.NewCount == 0, null, false, request.UserState)); }