private void ProcessBringIntoView()
{
// Do we need to process a 'BringIntoView' request?
if (_bringIntoView >= 0)
{
// If there are any lines to actually work against
if (_lineItems > 0)
{
// Find target line for bringing into view
int line = _bringIntoView / _lineItems;
int itemLine = line;
// Limit check to the last line for display purposes
if (line > _endLine)
line = _endLine;
// Cache top line before any changes made to it
int prevTopLine = _topLine;
// Is that line before the current top line?
if (line < _topLine)
{
// How many lines do we need to scroll upwards
int diffLines = _topLine - line;
// Shift topline to target immediately
_topLine = line;
// If we are supposed to scroll to the target position
if (ScrollIntoView)
{
// Modify the offset to reflect change in number of lines
_offset += _itemSize.Height * diffLines;
_scrollTimer.Start();
}
else
{
_offset = 0;
_scrollTimer.Stop();
}
}
else if (itemLine >= (_topLine + _displayLines))
{
// How many lines do we need to scroll upwards
int diffLines = itemLine - (_topLine + (_displayLines - 1));
// Shift topline to target immediately
_topLine = itemLine - (_displayLines - 1);
if (ScrollIntoView)
{
// Modify the offset to reflect change in number of lines
_offset -= _itemSize.Height * diffLines;
_scrollTimer.Start();
}
else
{
_offset = 0;
_scrollTimer.Stop();
}
}
// Update the begin line
if (_offset < 0)
{
// Ensure the old top line can be displayed during scrolling
if ((_beginLine == -1) || (_beginLine > prevTopLine))
_beginLine = prevTopLine;
}
else if (_offset > 0)
{
// Ensure the old top line can be displayed during scrolling
if ((_beginLine == -1) || (_beginLine < prevTopLine))
_beginLine = prevTopLine;
}
}
// Reset the request
_bringIntoView = -1;
}
}