comctl32/edit: Fix minimum control size conditions when using EC_USEFONTINFO.

Signed-off-by: Akihiro Sagawa <sagawa.aki@gmail.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Akihiro Sagawa 2019-04-23 22:01:37 +09:00 committed by Alexandre Julliard
parent 81c30446d9
commit 05864617bb
2 changed files with 13 additions and 48 deletions

View File

@ -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;
/* 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);

View File

@ -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);