Skip to content

Commit

Permalink
user32: Fix Edit margins calculation for empty client area case.
Browse files Browse the repository at this point in the history
  • Loading branch information
nsivov authored and julliard committed Apr 7, 2014
1 parent f820d97 commit ba3a6d1
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
2 changes: 1 addition & 1 deletion dlls/user32/edit.c
Expand Up @@ -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;
}
Expand Down
42 changes: 42 additions & 0 deletions dlls/user32/tests/edit.c
Expand Up @@ -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);

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit ba3a6d1

Please sign in to comment.