Skip to content

Commit 3e15c24

Browse files
committed
[USER32] - Sync with Wine Staging 1.9.18.
svn path=/trunk/; revision=72651
1 parent cf98f01 commit 3e15c24

File tree

1 file changed

+38
-32
lines changed
  • reactos/win32ss/user/user32/controls

1 file changed

+38
-32
lines changed

reactos/win32ss/user/user32/controls/edit.c

Lines changed: 38 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
/*
2-
* Edit control
2+
* Edit control
33
*
4-
* Copyright David W. Metcalfe, 1994
5-
* Copyright William Magro, 1995, 1996
6-
* Copyright Frans van Dorsselaer, 1996, 1997
4+
* Copyright David W. Metcalfe, 1994
5+
* Copyright William Magro, 1995, 1996
6+
* Copyright Frans van Dorsselaer, 1996, 1997
77
*
88
*
99
* This library is free software; you can redistribute it and/or
@@ -2904,30 +2904,30 @@ static void EDIT_EM_SetLimitText(EDITSTATE *es, UINT limit)
29042904

29052905
/*********************************************************************
29062906
*
2907-
* EM_SETMARGINS
2907+
* EM_SETMARGINS
29082908
*
29092909
* EC_USEFONTINFO is used as a left or right value i.e. lParam and not as an
29102910
* action wParam despite what the docs say. EC_USEFONTINFO calculates the
29112911
* margin according to the textmetrics of the current font.
29122912
*
2913-
* FIXME - With TrueType or vector fonts EC_USEFONTINFO currently sets one third
2914-
* of the char's width as the margin, but this is not how Windows handles this.
2915-
* For all other fonts Windows sets the margins to zero.
2916-
*
2917-
* FIXME - When EC_USEFONTINFO is used the margins only change if the
2918-
* edit control is equal to or larger than a certain size.
2919-
* Interestingly if one subtracts both the left and right margins from
2920-
* this size one always seems to get an even number. The extents of
2921-
* the (four character) string "'**'" match this quite closely, so
2922-
* we'll use this until we come up with a better idea.
2913+
* When EC_USEFONTINFO is used in the non_cjk case the margins only
2914+
* change if the edit control is equal to or larger than a certain
2915+
* size. Though there is an exception for the empty client rect case
2916+
* with small font sizes.
29232917
*/
2924-
static int calc_min_set_margin_size(HDC dc, INT left, INT right)
2918+
static BOOL is_cjk(UINT charset)
29252919
{
2926-
static const WCHAR magic_string[] = {'\'','*','*','\'', 0};
2927-
SIZE sz;
2928-
2929-
GetTextExtentPointW(dc, magic_string, sizeof(magic_string)/sizeof(WCHAR) - 1, &sz);
2930-
return sz.cx + left + right;
2920+
switch(charset)
2921+
{
2922+
case SHIFTJIS_CHARSET:
2923+
case HANGUL_CHARSET:
2924+
case GB2312_CHARSET:
2925+
case CHINESEBIG5_CHARSET:
2926+
return TRUE;
2927+
}
2928+
/* HANGUL_CHARSET is strange, though treated as CJK by Win 8, it is
2929+
* not by other versions including Win 10. */
2930+
return FALSE;
29312931
}
29322932

29332933
static void EDIT_EM_SetMargins(EDITSTATE *es, INT action,
@@ -2941,19 +2941,25 @@ static void EDIT_EM_SetMargins(EDITSTATE *es, INT action,
29412941
if (es->font && (left == EC_USEFONTINFO || right == EC_USEFONTINFO)) {
29422942
HDC dc = GetDC(es->hwndSelf);
29432943
HFONT old_font = SelectObject(dc, es->font);
2944-
GetTextMetricsW(dc, &tm);
2944+
LONG width = GdiGetCharDimensions(dc, &tm, NULL);
2945+
RECT rc;
2946+
29452947
/* The default margins are only non zero for TrueType or Vector fonts */
29462948
if (tm.tmPitchAndFamily & ( TMPF_VECTOR | TMPF_TRUETYPE )) {
2947-
int min_size;
2948-
RECT rc;
2949-
/* This must be calculated more exactly! But how? */
2950-
default_left_margin = tm.tmAveCharWidth / 2;
2951-
default_right_margin = tm.tmAveCharWidth / 2;
2952-
min_size = calc_min_set_margin_size(dc, default_left_margin, default_right_margin);
2953-
GetClientRect(es->hwndSelf, &rc);
2954-
if (!IsRectEmpty(&rc) && (rc.right - rc.left < min_size)) {
2955-
default_left_margin = es->left_margin;
2956-
default_right_margin = es->right_margin;
2949+
if (!is_cjk(tm.tmCharSet)) {
2950+
default_left_margin = width / 2;
2951+
default_right_margin = width / 2;
2952+
2953+
GetClientRect(es->hwndSelf, &rc);
2954+
if (rc.right - rc.left < (width / 2 + width) * 2 &&
2955+
(width >= 28 || !IsRectEmpty(&rc)) ) {
2956+
default_left_margin = es->left_margin;
2957+
default_right_margin = es->right_margin;
2958+
}
2959+
} else {
2960+
/* FIXME: figure out the CJK values. They are not affected by the client rect. */
2961+
default_left_margin = width / 2;
2962+
default_right_margin = width / 2;
29572963
}
29582964
}
29592965
SelectObject(dc, old_font);

0 commit comments

Comments
 (0)