Пример #1
0
 public override void ScrollViewportVerticallyByLines(VSTE.ScrollDirection direction, int count)
 {
     if (count < 0)
     {
         throw new ArgumentOutOfRangeException(nameof(count));
     }
     if (direction == VSTE.ScrollDirection.Up)
     {
         double pixels = 0;
         var    line   = hexView.HexViewLines.FirstVisibleLine;
         for (int i = 0; i < count; i++)
         {
             if (i == 0)
             {
                 if (line.VisibilityState == VSTF.VisibilityState.PartiallyVisible)
                 {
                     pixels += hexView.ViewportTop - line.Top;
                 }
                 if (line.BufferStart > hexView.BufferLines.BufferStart)
                 {
                     line    = hexView.GetHexViewLineContainingBufferPosition(line.BufferStart - 1);
                     pixels += line.Height;
                 }
             }
             else
             {
                 if (line.VisibilityState == VSTF.VisibilityState.Unattached)
                 {
                     // Height is only fully initialized once it's been shown on the screen
                     // (its LineTransform property is used to calculate Height)
                     var lineStart = line.BufferStart;
                     hexView.DisplayHexLineContainingBufferPosition(lineStart, 0, VSTE.ViewRelativePosition.Top);
                     line = hexView.GetHexViewLineContainingBufferPosition(lineStart);
                     Debug.Assert(line.VisibilityState != VSTF.VisibilityState.Unattached);
                     pixels = 0;
                 }
                 else
                 {
                     pixels += line.Height;
                 }
             }
             if (line.BufferStart <= hexView.BufferLines.BufferStart)
             {
                 break;
             }
             line = hexView.GetHexViewLineContainingBufferPosition(line.BufferStart - 1);
         }
         if (pixels != 0)
         {
             ScrollViewportVerticallyByPixels(pixels);
         }
     }
     else
     {
         Debug.Assert(direction == VSTE.ScrollDirection.Down);
         double pixels = 0;
         var    line   = hexView.HexViewLines.FirstVisibleLine;
         for (int i = 0; i < count; i++)
         {
             if (line.IsLastDocumentLine())
             {
                 break;
             }
             if (i == 0)
             {
                 if (line.VisibilityState == VSTF.VisibilityState.FullyVisible)
                 {
                     pixels += line.Height;
                 }
                 else
                 {
                     pixels += line.Bottom - hexView.ViewportTop;
                     line    = hexView.GetHexViewLineContainingBufferPosition(line.BufferEnd);
                     pixels += line.Height;
                 }
             }
             else
             {
                 if (line.VisibilityState == VSTF.VisibilityState.Unattached)
                 {
                     // Height is only fully initialized once it's been shown on the screen
                     // (its LineTransform property is used to calculate Height)
                     var lineStart = line.BufferStart;
                     hexView.DisplayHexLineContainingBufferPosition(lineStart, 0, VSTE.ViewRelativePosition.Top);
                     line = hexView.GetHexViewLineContainingBufferPosition(lineStart);
                     Debug.Assert(line.VisibilityState != VSTF.VisibilityState.Unattached);
                     pixels = 0;
                 }
                 else
                 {
                     pixels += line.Height;
                 }
             }
             if (line.IsLastDocumentLine())
             {
                 break;
             }
             line = hexView.GetHexViewLineContainingBufferPosition(line.BufferEnd);
         }
         if (pixels != 0)
         {
             ScrollViewportVerticallyByPixels(-pixels);
         }
     }
 }