From: Akihiro Sagawa Subject: [PATCH 3/3] comctl32/edit: Fix minimum control size conditions when using EC_USEFONTINFO. Message-Id: <20190423205622.62D3.375B48EC@gmail.com> Date: Tue, 23 Apr 2019 20:59:37 +0900 Signed-off-by: Akihiro Sagawa --- dlls/comctl32/edit.c | 47 +++++++++++++--------------------------------- dlls/comctl32/tests/edit.c | 16 +--------------- 2 files changed, 14 insertions(+), 49 deletions(-) diff --git a/dlls/comctl32/edit.c b/dlls/comctl32/edit.c index 1f17276..38a0d97 100644 --- a/dlls/comctl32/edit.c +++ b/dlls/comctl32/edit.c @@ -2694,26 +2694,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) { @@ -2725,25 +2709,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; - - 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; + /* FIXME: figure out the CJK values. */ + 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/comctl32/tests/edit.c b/dlls/comctl32/tests/edit.c index 0860048..44d77bb 100644 --- a/dlls/comctl32/tests/edit.c +++ b/dlls/comctl32/tests/edit.c @@ -1501,7 +1501,7 @@ static void test_margins_usefontinfo(UINT charset) HDC hdc; TEXTMETRICW tm; SIZE size; - BOOL cjk, cjk_charset; + BOOL cjk_charset; LOGFONTA lf; HFONT hfont; RECT rect; @@ -1536,19 +1536,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; - break; - default: - cjk = FALSE; - } cjk_charset = is_cjk_charset(hdc); hfont = SelectObject(hdc, hfont); @@ -1590,7 +1577,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);