From d6915136bf0d89b56b65d8f29099c5b7a2a0c6bc Mon Sep 17 00:00:00 2001 From: Jackson Harper Date: Tue, 14 Nov 2006 19:07:59 +0000 Subject: [PATCH] * TextControl.cs: Make PageUp and PageDown more like the MS versions. svn path=/trunk/mcs/; revision=67867 --- .../System.Windows.Forms/ChangeLog | 5 + .../System.Windows.Forms/TextControl.cs | 106 +++++++-------------- 2 files changed, 42 insertions(+), 69 deletions(-) diff --git a/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog b/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog index 6f965b6fbee..37e70deaa99 100644 --- a/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog +++ b/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog @@ -1,3 +1,8 @@ +2006-11-14 Jackson Harper + + * TextControl.cs: Make PageUp and PageDown more like the MS + versions. + 2006-11-14 Rolf Bjarne Kvinge * Form.cs: if a mdi child's WindowState has changed diff --git a/mcs/class/Managed.Windows.Forms/System.Windows.Forms/TextControl.cs b/mcs/class/Managed.Windows.Forms/System.Windows.Forms/TextControl.cs index 5b65ef09112..64c0b8e1111 100644 --- a/mcs/class/Managed.Windows.Forms/System.Windows.Forms/TextControl.cs +++ b/mcs/class/Managed.Windows.Forms/System.Windows.Forms/TextControl.cs @@ -1682,90 +1682,58 @@ namespace System.Windows.Forms { } case CaretDirection.PgUp: { - int index; - int new_y; - Line line; - if ((viewport_y - viewport_height) < 0) { - // We're just placing the caret at the end of the document, no scrolling needed - owner.vscroll.Value = 0; - line = GetLine(1); - PositionCaret(line, 0); - DisplayCaret (); - owner.Invalidate(); - return; - } - - new_y = caret.line.Y - viewport_height; - if (new_y < 0) { - line = GetLine(1); - PositionCaret(line, 0); - } else { - line = FindTag((int)caret.line.widths[caret.pos], caret.line.Y - viewport_height, out index, false).line; - if (caret.pos > 0) { - PositionCaret(line, index); - } else { - PositionCaret(line, 0); + int new_y, y_offset; + + if (viewport_y == 0) { + + // This should probably be handled elsewhere + if (!(owner is RichTextBox)) { + // Page down doesn't do anything in a regular TextBox + // if the bottom of the document + // is already visible, the page and the caret stay still + return; } - } - // Line up to fill line starts - new_y = viewport_y - viewport_height; - line = FindTag(0, new_y, out index, false).line; - if (line != null) { - owner.vscroll.Value = line.Y; - } else { - owner.vscroll.Value = new_y; + // We're just placing the caret at the end of the document, no scrolling needed + owner.vscroll.Value = 0; + Line line = GetLine (1); + PositionCaret (line, 0); } - DisplayCaret (); + y_offset = caret.line.Y - viewport_y; + new_y = caret.line.Y - viewport_height; - owner.Invalidate(); + owner.vscroll.Value = Math.Max (new_y, 0); + PositionCaret ((int)caret.line.widths[caret.pos], y_offset + viewport_y); return; } case CaretDirection.PgDn: { - int index; - int new_y; - Line line; + int new_y, y_offset; if ((viewport_y + viewport_height) > document_y) { - // We're just placing the caret at the end of the document, no scrolling needed - owner.vscroll.Value = owner.vscroll.Maximum; - line = GetLine(lines); - PositionCaret(line, line.Text.Length); - DisplayCaret (); - owner.Invalidate(); - return; - } - - new_y = caret.line.Y + viewport_height; - if (new_y > document_y) { - line = GetLine(lines); - PositionCaret(line, line.text.Length); - } else { - line = FindTag((int)caret.line.widths[caret.pos], caret.line.Y + viewport_height, out index, false).line; - if (caret.pos > 0) { - PositionCaret(line, index); - } else { - PositionCaret(line, 0); - } - } - // Line up to fill line starts - new_y = viewport_y + viewport_height; - line = FindTag(0, new_y, out index, false).line; - if (line != null) { - if (line.Y > owner.vscroll.Maximum) { - owner.vscroll.Value = owner.vscroll.Maximum; - } else { - owner.vscroll.Value = line.Y; + // This should probably be handled elsewhere + if (!(owner is RichTextBox)) { + // Page up doesn't do anything in a regular TextBox + // if the bottom of the document + // is already visible, the page and the caret stay still + return; } - } else { - owner.vscroll.Value = new_y; + + // We're just placing the caret at the end of the document, no scrolling needed + owner.vscroll.Value = owner.vscroll.Maximum - viewport_height + 1; + Line line = GetLine (lines); + PositionCaret (line, line.Text.Length); } - DisplayCaret (); - owner.Invalidate(); + + y_offset = caret.line.Y - viewport_y; + new_y = caret.line.Y + viewport_height; + + owner.vscroll.Value = Math.Min (new_y, owner.vscroll.Maximum - viewport_height + 1); + PositionCaret ((int)caret.line.widths[caret.pos], y_offset + viewport_y); + return; } -- 2.11.4.GIT