From 2b6f45066b903541205f55a8683691625b6cd07f Mon Sep 17 00:00:00 2001 From: Akihiro Sagawa Date: Thu, 14 Mar 2019 23:55:22 +0900 Subject: [PATCH] user32: Fix minimum control size conditions when using EC_USEFONTINFO. Signed-off-by: Akihiro Sagawa Signed-off-by: Alexandre Julliard --- dlls/user32/edit.c | 45 +++++++++++----------------------------- dlls/user32/tests/edit.c | 13 +----------- 2 files changed, 13 insertions(+), 45 deletions(-) diff --git a/dlls/user32/edit.c b/dlls/user32/edit.c index 6f8f41238e3..d1659b49c54 100644 --- a/dlls/user32/edit.c +++ b/dlls/user32/edit.c @@ -2850,26 +2850,10 @@ static void EDIT_EM_SetLimitText(EDITSTATE *es, UINT limit) * action wParam despite what the docs say. EC_USEFONTINFO calculates the * margin according to the textmetrics of the current font. * - * When EC_USEFONTINFO is used in the non_cjk case the margins only - * change if the edit control is equal to or larger than a certain - * size. Though there is an exception for the empty client rect case - * with small font sizes. + * When EC_USEFONTINFO is used, the margins only change if the edit control is + * equal to or larger than a certain size. The empty client rect is treated as + * 80 pixels width. */ -static BOOL is_cjk(UINT charset) -{ - switch(charset) - { - case SHIFTJIS_CHARSET: - case HANGUL_CHARSET: - case GB2312_CHARSET: - case CHINESEBIG5_CHARSET: - return TRUE; - } - /* HANGUL_CHARSET is strange, though treated as CJK by Win 8, it is - * not by other versions including Win 10. */ - return FALSE; -} - static void EDIT_EM_SetMargins(EDITSTATE *es, INT action, WORD left, WORD right, BOOL repaint) { @@ -2881,25 +2865,20 @@ static void EDIT_EM_SetMargins(EDITSTATE *es, INT action, if (es->font && (left == EC_USEFONTINFO || right == EC_USEFONTINFO)) { HDC dc = GetDC(es->hwndSelf); HFONT old_font = SelectObject(dc, es->font); - LONG width = GdiGetCharDimensions(dc, &tm, NULL); + LONG width = GdiGetCharDimensions(dc, &tm, NULL), rc_width; RECT rc; /* The default margins are only non zero for TrueType or Vector fonts */ if (tm.tmPitchAndFamily & ( TMPF_VECTOR | TMPF_TRUETYPE )) { - if (!is_cjk(tm.tmCharSet)) { - default_left_margin = width / 2; - default_right_margin = width / 2; + /* FIXME: figure out the CJK values. */ + default_left_margin = width / 2; + default_right_margin = width / 2; - GetClientRect(es->hwndSelf, &rc); - if (rc.right - rc.left < (width / 2 + width) * 2 && - (width >= 28 || !IsRectEmpty(&rc)) ) { - default_left_margin = es->left_margin; - default_right_margin = es->right_margin; - } - } else { - /* FIXME: figure out the CJK values. They are not affected by the client rect. */ - default_left_margin = width / 2; - default_right_margin = width / 2; + GetClientRect(es->hwndSelf, &rc); + rc_width = !IsRectEmpty(&rc) ? rc.right - rc.left : 80; + if (rc_width < default_left_margin + default_right_margin + width * 2) { + default_left_margin = es->left_margin; + default_right_margin = es->right_margin; } } SelectObject(dc, old_font); diff --git a/dlls/user32/tests/edit.c b/dlls/user32/tests/edit.c index 72fad2da0ad..41ed07a5b90 100644 --- a/dlls/user32/tests/edit.c +++ b/dlls/user32/tests/edit.c @@ -1451,7 +1451,7 @@ static void test_margins_usefontinfo(UINT charset) HDC hdc; TEXTMETRICW tm; SIZE size; - BOOL cjk = FALSE, cjk_charset; + BOOL cjk_charset; LOGFONTA lf; HFONT hfont; RECT rect; @@ -1486,16 +1486,6 @@ static void test_margins_usefontinfo(UINT charset) return; } expect = MAKELONG(size.cx / 2, size.cx / 2); - - charset = GetTextCharset(hdc); - switch (charset) - { - case SHIFTJIS_CHARSET: - case HANGUL_CHARSET: - case GB2312_CHARSET: - case CHINESEBIG5_CHARSET: - cjk = TRUE; - } cjk_charset = is_cjk_charset(hdc); hfont = SelectObject(hdc, hfont); @@ -1537,7 +1527,6 @@ static void test_margins_usefontinfo(UINT charset) SendMessageA(hwnd, EM_SETMARGINS, EC_LEFTMARGIN | EC_RIGHTMARGIN, small_margins); SendMessageA(hwnd, EM_SETMARGINS, EC_LEFTMARGIN | EC_RIGHTMARGIN, MAKELONG(EC_USEFONTINFO, EC_USEFONTINFO)); margins = SendMessageA(hwnd, EM_GETMARGINS, 0, 0); - todo_wine_if(cjk) ok(margins == small_margins, "%d: got %d, %d\n", charset, HIWORD(margins), LOWORD(margins)); DestroyWindow(hwnd);