From 645a3280f5d67b84f636bdd229aefc1e0fe3c192 Mon Sep 17 00:00:00 2001 From: Aleksey Bragin Date: Mon, 10 Jul 2006 08:56:02 +0000 Subject: [PATCH] Sync with Wine: Update EDIT_EM_SetMargins in EDIT control. svn path=/trunk/; revision=22991 --- reactos/dll/win32/user32/controls/edit.c | 35 ++++++++++++++++++++---- reactos/media/doc/README.WINE | 2 +- 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/reactos/dll/win32/user32/controls/edit.c b/reactos/dll/win32/user32/controls/edit.c index e3eca53de09..d864e0c0f8c 100644 --- a/reactos/dll/win32/user32/controls/edit.c +++ b/reactos/dll/win32/user32/controls/edit.c @@ -18,7 +18,7 @@ * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA * * NOTES * @@ -239,7 +239,7 @@ static void EDIT_EM_SetHandle(EDITSTATE *es, HLOCAL hloc); static void EDIT_EM_SetHandle16(EDITSTATE *es, HLOCAL16 hloc); #endif static void EDIT_EM_SetLimitText(EDITSTATE *es, INT limit); -static void EDIT_EM_SetMargins(EDITSTATE *es, INT action, INT left, INT right, BOOL repaint); +static void EDIT_EM_SetMargins(EDITSTATE *es, INT action, WORD left, WORD right, BOOL repaint); static void EDIT_EM_SetPasswordChar(EDITSTATE *es, WCHAR c); static void EDIT_EM_SetSel(EDITSTATE *es, UINT start, UINT end, BOOL after_wrap); static BOOL EDIT_EM_SetTabStops(EDITSTATE *es, INT count, LPINT tabs); @@ -802,7 +802,7 @@ static LRESULT WINAPI EditWndProc_common( HWND hwnd, UINT msg, /* The following EM_xxx are new to win95 and don't exist for 16 bit */ case EM_SETMARGINS: - EDIT_EM_SetMargins(es, (INT)wParam, (short)LOWORD(lParam), (short)HIWORD(lParam), TRUE); + EDIT_EM_SetMargins(es, (INT)wParam, LOWORD(lParam), HIWORD(lParam), TRUE); break; case EM_GETMARGINS: @@ -3715,9 +3715,24 @@ static void EDIT_EM_SetLimitText(EDITSTATE *es, INT limit) * of the char's width as the margin, but this is not how Windows handles this. * For all other fonts Windows sets the margins to zero. * + * FIXME - When EC_USEFONTINFO is used the margins only change if the + * edit control is equal to or larger than a certain size. + * Interestingly if one subtracts both the left and right margins from + * this size one always seems to get an even number. The extents of + * the (four character) string "'**'" match this quite closely, so + * we'll use this until we come up with a better idea. */ +static int calc_min_set_margin_size(HDC dc, INT left, INT right) +{ + WCHAR magic_string[] = {'\'','*','*','\'', 0}; + SIZE sz; + + GetTextExtentPointW(dc, magic_string, sizeof(magic_string)/sizeof(WCHAR) - 1, &sz); + return sz.cx + left + right; +} + static void EDIT_EM_SetMargins(EDITSTATE *es, INT action, - INT left, INT right, BOOL repaint) + WORD left, WORD right, BOOL repaint) { TEXTMETRICW tm; INT default_left_margin = 0; /* in pixels */ @@ -3730,9 +3745,17 @@ static void EDIT_EM_SetMargins(EDITSTATE *es, INT action, GetTextMetricsW(dc, &tm); /* The default margins are only non zero for TrueType or Vector fonts */ if (tm.tmPitchAndFamily & ( TMPF_VECTOR | TMPF_TRUETYPE )) { + int min_size; + RECT rc; /* This must be calculated more exactly! But how? */ - default_left_margin = tm.tmAveCharWidth / 3; - default_right_margin = tm.tmAveCharWidth / 3; + default_left_margin = tm.tmAveCharWidth / 2; + 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) { + default_left_margin = es->left_margin; + default_right_margin = es->right_margin; + } } SelectObject(dc, old_font); ReleaseDC(es->hwndSelf, dc); diff --git a/reactos/media/doc/README.WINE b/reactos/media/doc/README.WINE index 6ecfc91c12b..cd994d581c6 100644 --- a/reactos/media/doc/README.WINE +++ b/reactos/media/doc/README.WINE @@ -117,7 +117,7 @@ msvcrt - User32 - reactos/dll/win32/user32/controls/button.c # Synced at 20060621 reactos/dll/win32/user32/controls/combo.c # Synced at 20060617 - reactos/dll/win32/user32/controls/edit.c # Synced at 20060623 + reactos/dll/win32/user32/controls/edit.c # Synced at 20060710 reactos/dll/win32/user32/controls/icontitle.c # Synced at 20060617 reactos/dll/win32/user32/controls/listbox.c # Synced at 20060616 reactos/dll/win32/user32/controls/scrollbar.c # Forked