/// <summary> /// <see cref="ITextView.BringLineIntoViewAsync"/> /// </summary> internal override void BringPageIntoViewAsync(ITextPointer position, Point suggestedOffset, 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. OnBringPageIntoViewCompleted(new BringPageIntoViewCompletedEventArgs( position, suggestedOffset, count, position, suggestedOffset, 0, false, null, false, userState)); } else { _pendingRequest = new BringPageIntoViewRequest(position, suggestedOffset, count, userState); BringPageIntoViewCore((BringPageIntoViewRequest)_pendingRequest); } }
/// <summary> /// Bring page into view. /// </summary> private void BringPageIntoViewCore(BringPageIntoViewRequest request) { ITextPointer newPosition; Point newSuggestedOffset; int pagesMoved; int newPageNumber; // Try to use existing TextViews to handle this request. newPosition = GetPositionAtNextPageCore(request.NewPosition, request.NewSuggestedOffset, request.NewCount, out newSuggestedOffset, out pagesMoved, out newPageNumber); Invariant.Assert(Math.Abs(request.NewCount) >= Math.Abs(pagesMoved)); request.NewPosition = newPosition; request.NewSuggestedOffset = newSuggestedOffset; request.NewCount = request.NewCount - pagesMoved; if (request.NewCount == 0 || newPageNumber == -1) { OnBringPageIntoViewCompleted(request); } else { // 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'. newPageNumber += (request.NewCount > 0) ? 1 : -1; if (_viewer.CanGoToPage(newPageNumber + 1)) { request.NewPageNumber = newPageNumber; _viewer.GoToPage(newPageNumber + 1); } else { OnBringPageIntoViewCompleted(request); } } }
/// <summary> /// Fires BringPageIntoViewCompleted event. /// </summary> private void OnBringPageIntoViewCompleted(BringPageIntoViewRequest request) { _pendingRequest = null; OnBringPageIntoViewCompleted(new BringPageIntoViewCompletedEventArgs( request.Position, request.SuggestedOffset, request.Count, request.NewPosition, request.NewSuggestedOffset, request.Count - request.NewCount, request.NewCount == 0, null, false, request.UserState)); }