From 4b0c2d5e95858e88e5462a0632d23c95cd547113 Mon Sep 17 00:00:00 2001 From: Austin English Date: Mon, 4 Aug 2008 14:39:13 -0500 Subject: [PATCH] user32: Check for bad scroll value and fix return values in EDIT_EM_Scroll. --- dlls/user32/edit.c | 17 ++++++++++- dlls/user32/tests/edit.c | 69 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 84 insertions(+), 2 deletions(-) diff --git a/dlls/user32/edit.c b/dlls/user32/edit.c index dcf9550..8085962 100644 --- a/dlls/user32/edit.c +++ b/dlls/user32/edit.c @@ -3421,15 +3421,28 @@ static LRESULT EDIT_EM_Scroll(EDITSTATE *es, INT action) } if (dy) { INT vlc = (es->format_rect.bottom - es->format_rect.top) / es->line_height; + /* 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 = es->line_count - vlc - es->y_offset; + + /* Make sure we're not trying to scroll backwards here */ + if(es->y_offset + dy < 0) + dy = 0; + + } + /* Notification is done in EDIT_EM_LineScroll */ if(dy) EDIT_EM_LineScroll(es, 0, dy); } - return MAKELONG((INT16)dy, (BOOL16)TRUE); + + if(dy) + return MAKELONG((INT16)dy, (BOOL16)TRUE); + else + return (LRESULT)FALSE; } diff --git a/dlls/user32/tests/edit.c b/dlls/user32/tests/edit.c index 0c5a678..628a84b 100644 --- a/dlls/user32/tests/edit.c +++ b/dlls/user32/tests/edit.c @@ -1205,6 +1205,74 @@ static void test_edit_control_5(void) DestroyWindow(hWnd); } +static void test_edit_control_6(void) +{ + HWND hwEdit; + LONG r; + + static const char *single_line_str = "a"; + static const char *multiline_str = "Test\nText"; + + /* Check the return value when EM_SCROLL doesn't actually scroll anything. */ + + hwEdit = CreateWindow( + "EDIT", + single_line_str, + WS_VSCROLL | ES_MULTILINE, + 1, 1, 35, 35, + NULL, NULL, hinst, NULL); + + assert(hwEdit); + + trace("EDIT: Scrolling down one page \n"); + r = SendMessage(hwEdit, EM_SCROLL, SB_PAGEDOWN, 0); + if(LOWORD(r)) + skip("Scrolled lines not 0.\n"); + else + ok(!r, "Returned %x\n", r); + + trace("EDIT: Scrolling up one page \n"); + r = SendMessage(hwEdit, EM_SCROLL, SB_PAGEUP, 0); + if(LOWORD(r)) + skip("Scrolled lines not 0.\n"); + else + ok(!r, "Returned %x\n", r); + + trace("EDIT: Scrolling up one line\n"); + r = SendMessage(hwEdit, EM_SCROLL, SB_LINEUP, 0); + if(LOWORD(r)) + skip("Scrolled lines not 0.\n"); + else + ok(!r, "Returned %x\n", r); + + trace("EDIT: Scrolling down one line\n"); + r = SendMessage(hwEdit, EM_SCROLL, SB_LINEDOWN, 0); + if(LOWORD(r)) + skip("Scrolled lines not 0.\n"); + else + ok(!r, "Returned %x\n", r); + + DestroyWindow (hwEdit); + + + /* Check for bug in wine where sending SB_PAGEDOWN causes + EDIT_EM_Scroll to return a negative amount of scrolled lines. */ + + hwEdit = CreateWindow( //Ex(NULL, + "EDIT", + multiline_str, + ES_MULTILINE, + 0, 0, 50, 1000, + NULL, NULL, hinst, NULL); + + assert(hwEdit); + + r = SendMessage(hwEdit, EM_SCROLL, SB_PAGEDOWN, 0); + ok(!r, "Returned %x\n", r); + + DestroyWindow (hwEdit); +} + static void test_edit_control_limittext(void) { HWND hwEdit; @@ -1999,6 +2067,7 @@ START_TEST(edit) test_edit_control_3(); test_edit_control_4(); test_edit_control_5(); + test_edit_control_6(); test_edit_control_limittext(); test_margins(); test_margins_font_change(); -- 1.5.2.5