user32: Fix case where EM_SCROLL with page down results in trying to scroll up past...
authorDavid Hedberg <david.hedberg@gmail.com>
Wed, 3 Mar 2010 12:19:47 +0000 (13:19 +0100)
committerAlexandre Julliard <julliard@winehq.org>
Wed, 3 Mar 2010 13:01:58 +0000 (14:01 +0100)
dlls/user32/edit.c
dlls/user32/tests/edit.c

index 35f828539398802183810046260a72e7a69e72b4..9898bc4ae831b313e23c4a6cbb9b1776c5e3f15e 100644 (file)
@@ -1632,7 +1632,7 @@ static LRESULT EDIT_EM_Scroll(EDITSTATE *es, INT action)
            INT vlc = get_vertical_line_count(es);
            /* check if we are going to move too far */
            if(es->y_offset + dy > es->line_count - vlc)
-               dy = es->line_count - vlc - es->y_offset;
+               dy = max(es->line_count - vlc, 0) - es->y_offset;
 
            /* Notification is done in EDIT_EM_LineScroll */
            if(dy) {
index 6d3afb8ee89213c01126249b0e3057e9ac863198..ee181f21f6a3312e718ff487b77b7d07fc6cc3bf 100644 (file)
@@ -1320,6 +1320,7 @@ static void test_edit_control_limittext(void)
 static void test_edit_control_scroll(void)
 {
     static const char *single_line_str = "a";
+    static const char *multiline_str = "Test\r\nText";
     HWND hwEdit;
     LONG ret;
 
@@ -1348,6 +1349,22 @@ static void test_edit_control_scroll(void)
     ok(!ret, "Returned %x, expected 0.\n", ret);
 
     DestroyWindow (hwEdit);
+
+    /* SB_PAGEDOWN while at the beginning of a buffer with few lines
+       should not cause EM_SCROLL to return a negative value of
+       scrolled lines that would put us "before" the beginning. */
+    hwEdit = CreateWindow(
+                "EDIT",
+                multiline_str,
+                WS_VSCROLL | ES_MULTILINE,
+                0, 0, 100, 100,
+                NULL, NULL, hinst, NULL);
+    assert(hwEdit);
+
+    ret = SendMessage(hwEdit, EM_SCROLL, SB_PAGEDOWN, 0);
+    ok(!ret, "Returned %x, expected 0.\n", ret);
+
+    DestroyWindow (hwEdit);
 }
 
 static void test_margins(void)