private void EnsureCursorVisible()
{
if (_readOnly == true)
{
_cursorPosition = -1;
}
else if (_maxChars == 1)
{
_cursorPosition = 0;
}
if (this.DeviceContext == null)
{
return;
}
SetFont();
if (_wrap == false)
{
int cursorX = 0;
if (_password == true)
{
cursorX = _cursorPosition * this.DeviceContext.GetCharacterWidth('*', this.TextScale);
}
else
{
int i = 0;
int length = this.Text.Length;
while ((i < length) && (i < _cursorPosition))
{
if (idHelper.IsColor(this.Text, i) == true)
{
i += 2;
}
else
{
cursorX += this.DeviceContext.GetCharacterWidth(this.Text[i], this.TextScale);
i++;
}
}
}
int maxWidth = (int)this.MaximumCharacterWidth;
int left = cursorX - maxWidth;
int right = (int)(cursorX - this.TextRectangle.Width) + maxWidth;
if (_paintOffset > left)
{
// when we go past the left side, we want the text to jump 6 characters
_paintOffset = left - maxWidth * 6;
}
if (_paintOffset < right)
{
_paintOffset = right;
}
if (_paintOffset < 0)
{
_paintOffset = 0;
}
_scroller.SetRange(0, 0, 1);
}
else
{
// word wrap
_breaks.Clear();
idRectangle rect = this.TextRectangle;
rect.Width -= _sizeBias;
this.DeviceContext.DrawText(this.Text, this.TextScale, this.TextAlign, idColor.White, rect, true, ((this.Flags & WindowFlags.Focus) == WindowFlags.Focus) ? _cursorPosition : -1, true, _breaks);
int fit = (int)(this.TextRectangle.Height / (this.MaximumCharacterHeight + 5));
if (fit < (_breaks.Count + 1))
{
_scroller.SetRange(0, _breaks.Count + 1 - fit, 1);
}
else
{
// the text fits completely in the box
_scroller.SetRange(0, 0, 1);
}
if (_forceScroll == true)
{
_scroller.Value = _breaks.Count - fit;
}
else if (_readOnly == true)
{
}
else
{
_cursorLine = 0;
int count = _breaks.Count;
for (int i = 1; i < count; i++)
{
if (_cursorPosition >= _breaks[i])
{
_cursorLine = i;
}
else
{
break;
}
}
int topLine = (int)_scroller.Value;
if (_cursorLine < topLine)
{
_scroller.Value = _cursorLine;
}
else if (_cursorLine >= (topLine + fit))
{
_scroller.Value = (_cursorLine - fit) + 1;
}
}
}
}