From 13230ae0fdc208b672cd275909df1df11f502962 Mon Sep 17 00:00:00 2001 From: Lei Zhang Date: Fri, 30 May 2008 11:30:21 -0700 Subject: [PATCH] user32: use the original limit even if it changes in response to EN_MAXTEXT. --- dlls/user32/edit.c | 5 ++- dlls/user32/tests/edit.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+), 2 deletions(-) diff --git a/dlls/user32/edit.c b/dlls/user32/edit.c index b37b5dc..68436aa 100644 --- a/dlls/user32/edit.c +++ b/dlls/user32/edit.c @@ -3198,12 +3198,13 @@ static void EDIT_EM_ReplaceSel(EDITSTATE *es, BOOL can_undo, LPCWSTR lpsz_replac /* Issue the EN_MAXTEXT notification and continue with replacing text * such that buffer limit is honored. */ if ((honor_limit) && (size > es->buffer_limit)) { + UINT old_limit = es->buffer_limit; EDIT_NOTIFY_PARENT(es, EN_MAXTEXT); /* Buffer limit can be smaller than the actual length of text in combobox */ - if (es->buffer_limit < (tl - (e-s))) + if (old_limit < (tl - (e-s))) strl = 0; else - strl = es->buffer_limit - (tl - (e-s)); + strl = old_limit - (tl - (e-s)); } if (!EDIT_MakeFit(es, tl - (e - s) + strl)) diff --git a/dlls/user32/tests/edit.c b/dlls/user32/tests/edit.c index 0c5a678..84b9020 100644 --- a/dlls/user32/tests/edit.c +++ b/dlls/user32/tests/edit.c @@ -37,6 +37,12 @@ struct edit_notify { static struct edit_notify notifications; +struct subclass_info +{ + WNDPROC oldproc; + HWND hwEdit; +}; + static INT_PTR CALLBACK multi_edit_dialog_proc(HWND hdlg, UINT msg, WPARAM wparam, LPARAM lparam) { static int num_ok_commands = 0; @@ -1235,6 +1241,69 @@ static void test_edit_control_limittext(void) DestroyWindow(hwEdit); } +static LRESULT CALLBACK setlimit_parent_proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) +{ + static int firstRun = TRUE; + struct subclass_info *info = (struct subclass_info *)GetWindowLongPtrA(hwnd, GWLP_USERDATA); + + switch (msg) { + case WM_COMMAND: + switch (HIWORD(wParam)) { + case EN_MAXTEXT: + if (firstRun) + { + SendMessage(info->hwEdit, EM_SETLIMITTEXT, 10, 0); + firstRun = FALSE; + } + else + SendMessage(info->hwEdit, EM_SETLIMITTEXT, 4, 0); + break; + } + break; + } + return CallWindowProcA(info->oldproc, hwnd, msg, wParam, lParam); +} + +static void test_edit_control_limittext_setlimit(void) +{ + HWND hwEdit, hwParent; + int r; + struct subclass_info *info; + + hwEdit = create_child_editcontrol(ES_MULTILINE, 0); + info = HeapAlloc(GetProcessHeap(), 0, sizeof(struct subclass_info)); + if (!hwEdit || !info) + return; + hwParent = GetParent(hwEdit); + + info->oldproc = (WNDPROC)SetWindowLongPtr(hwParent, GWLP_WNDPROC, (LONG_PTR)setlimit_parent_proc); + info->hwEdit = hwEdit; + SetWindowLongPtr(hwParent, GWLP_USERDATA, (LONG_PTR)info); + r = SendMessage(hwEdit, EM_SETLIMITTEXT, 6, 0); + + r = SendMessage(hwEdit, WM_SETTEXT, 0, (LPARAM) ""); + r = SendMessage(hwEdit, EM_REPLACESEL, 0, (LPARAM) "asdfghjk12345678"); + r = SendMessage(hwEdit, WM_GETTEXTLENGTH, 0, 0); + ok(r == 6, "WM_GETTEXTLENGTH expected %d, got %d\n", 6, r); + + r = SendMessage(hwEdit, WM_SETTEXT, 0, (LPARAM) ""); + r = SendMessage(hwEdit, EM_REPLACESEL, 0, (LPARAM) "asdf"); + r = SendMessage(hwEdit, WM_GETTEXTLENGTH, 0, 0); + ok(r == 4, "WM_GETTEXTLENGTH expected %d, got %d\n", 4, r); + + r = SendMessage(hwEdit, WM_SETTEXT, 0, (LPARAM) ""); + r = SendMessage(hwEdit, EM_REPLACESEL, 0, (LPARAM) "asdfghjk12345678"); + r = SendMessage(hwEdit, WM_GETTEXTLENGTH, 0, 0); + ok(r == 10, "WM_GETTEXTLENGTH expected %d, got %d\n", 10, r); + + r = SendMessage(hwEdit, WM_SETTEXT, 0, (LPARAM) ""); + r = SendMessage(hwEdit, EM_REPLACESEL, 0, (LPARAM) "asdfghjk12345678"); + r = SendMessage(hwEdit, WM_GETTEXTLENGTH, 0, 0); + ok(r == 4, "WM_GETTEXTLENGTH expected %d, got %d\n", 4, r); + + destroy_child_editcontrol(hwEdit); +} + static void test_margins(void) { HWND hwEdit; @@ -2000,6 +2069,7 @@ START_TEST(edit) test_edit_control_4(); test_edit_control_5(); test_edit_control_limittext(); + test_edit_control_limittext_setlimit(); test_margins(); test_margins_font_change(); test_text_position(); -- 1.5.3.6