From ba3a6d1f4b9db64c12301d0d83d559dd6f1e83b4 Mon Sep 17 00:00:00 2001 From: Nikolay Sivov Date: Fri, 4 Apr 2014 21:45:28 +0400 Subject: [PATCH] user32: Fix Edit margins calculation for empty client area case. --- dlls/user32/edit.c | 2 +- dlls/user32/tests/edit.c | 42 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/dlls/user32/edit.c b/dlls/user32/edit.c index ac4cec34e08..e9cbc915001 100644 --- a/dlls/user32/edit.c +++ b/dlls/user32/edit.c @@ -2914,7 +2914,7 @@ static void EDIT_EM_SetMargins(EDITSTATE *es, INT action, default_right_margin = tm.tmAveCharWidth / 2; min_size = calc_min_set_margin_size(dc, default_left_margin, default_right_margin); GetClientRect(es->hwndSelf, &rc); - if(rc.right - rc.left < min_size) { + if (!IsRectEmpty(&rc) && (rc.right - rc.left < min_size)) { default_left_margin = es->left_margin; default_right_margin = es->right_margin; } diff --git a/dlls/user32/tests/edit.c b/dlls/user32/tests/edit.c index e95964c25c1..d5fd3b237f8 100644 --- a/dlls/user32/tests/edit.c +++ b/dlls/user32/tests/edit.c @@ -1423,6 +1423,8 @@ static void test_margins(void) RECT old_rect, new_rect; INT old_right_margin; DWORD old_margins, new_margins; + LOGFONTA lf; + HFONT hfont; hwEdit = create_editcontrol(WS_BORDER | ES_AUTOHSCROLL | ES_AUTOVSCROLL, 0); @@ -1470,6 +1472,46 @@ static void test_margins(void) ok(new_rect.bottom == old_rect.bottom, "The bottom border of the rectangle has changed\n"); DestroyWindow (hwEdit); + + memset(&lf, 0, sizeof(lf)); + lf.lfHeight = -11; + lf.lfWeight = FW_NORMAL; + lf.lfCharSet = DEFAULT_CHARSET; + strcpy(lf.lfFaceName, "Tahoma"); + + hfont = CreateFontIndirectA(&lf); + ok(hfont != NULL, "got %p\n", hfont); + + /* Empty window rectangle */ + hwEdit = CreateWindowExA(0, "Edit", "A", WS_POPUP, 0, 0, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, NULL, NULL); + ok(hwEdit != NULL, "got %p\n", hwEdit); + GetClientRect(hwEdit, &old_rect); + ok(IsRectEmpty(&old_rect), "got rect %d,%d-%d,%d\n", old_rect.left, old_rect.top, old_rect.right, old_rect.bottom); + + old_margins = SendMessageA(hwEdit, EM_GETMARGINS, 0, 0); + ok(old_margins == 0, "got %x\n", old_margins); + + SendMessageA(hwEdit, WM_SETFONT, (WPARAM)hfont, MAKELPARAM(TRUE, 0)); + old_margins = SendMessageA(hwEdit, EM_GETMARGINS, 0, 0); + ok(HIWORD(old_margins) > 0 && LOWORD(old_margins) > 0, "got %d, %d\n", HIWORD(old_margins), LOWORD(old_margins)); + + DestroyWindow(hwEdit); + + /* Size is not enough to display a text, but not empty */ + hwEdit = CreateWindowExA(0, "Edit", "A", WS_POPUP, 0, 0, 2, 2, NULL, NULL, NULL, NULL); + ok(hwEdit != NULL, "got %p\n", hwEdit); + GetClientRect(hwEdit, &old_rect); + ok(!IsRectEmpty(&old_rect), "got rect %d,%d-%d,%d\n", old_rect.left, old_rect.top, old_rect.right, old_rect.bottom); + + old_margins = SendMessageA(hwEdit, EM_GETMARGINS, 0, 0); + ok(old_margins == 0, "got %x\n", old_margins); + + SendMessageA(hwEdit, WM_SETFONT, (WPARAM)hfont, MAKELPARAM(TRUE, 0)); + old_margins = SendMessageA(hwEdit, EM_GETMARGINS, 0, 0); + ok(old_margins == 0, "got %d, %d\n", HIWORD(old_margins), LOWORD(old_margins)); + + DeleteObject(hfont); + DestroyWindow(hwEdit); } static INT CALLBACK find_font_proc(const LOGFONTA *elf, const TEXTMETRICA *ntm, DWORD type, LPARAM lParam)