Module: wine Branch: master Commit: 9215aabd2ef84821ff3fb81c379c0986e3d9371a URL: http://source.winehq.org/git/wine.git/?a=commit;h=9215aabd2ef84821ff3fb81c37...
Author: Alexandre Julliard julliard@winehq.org Date: Tue Nov 7 21:20:24 2017 +0100
user32: Pass the text length explicitly to EDIT_EM_ReplaceSel.
Signed-off-by: Alexandre Julliard julliard@winehq.org
---
dlls/user32/edit.c | 63 ++++++++++++++++++++++-------------------------------- 1 file changed, 25 insertions(+), 38 deletions(-)
diff --git a/dlls/user32/edit.c b/dlls/user32/edit.c index ee9b45e..c93d3c3 100644 --- a/dlls/user32/edit.c +++ b/dlls/user32/edit.c @@ -176,7 +176,6 @@ typedef struct (LPARAM)(es->hwndSelf)); \ } while(0)
-static const WCHAR empty_stringW[] = {0}; static LRESULT EDIT_EM_PosFromChar(EDITSTATE *es, INT index, BOOL after_wrap);
/********************************************************************* @@ -2560,9 +2559,9 @@ static LRESULT EDIT_EM_GetSel(const EDITSTATE *es, PUINT start, PUINT end) * FIXME: handle ES_NUMBER and ES_OEMCONVERT here * */ -static void EDIT_EM_ReplaceSel(EDITSTATE *es, BOOL can_undo, LPCWSTR lpsz_replace, BOOL send_update, BOOL honor_limit) +static void EDIT_EM_ReplaceSel(EDITSTATE *es, BOOL can_undo, const WCHAR *lpsz_replace, UINT strl, + BOOL send_update, BOOL honor_limit) { - UINT strl = strlenW(lpsz_replace); UINT tl = get_text_length(es); UINT utl; UINT s; @@ -3043,7 +3042,7 @@ static BOOL EDIT_EM_Undo(EDITSTATE *es)
EDIT_EM_SetSel(es, es->undo_position, es->undo_position + es->undo_insert_count, FALSE); EDIT_EM_EmptyUndoBuffer(es); - EDIT_EM_ReplaceSel(es, TRUE, utext, TRUE, TRUE); + EDIT_EM_ReplaceSel(es, TRUE, utext, ulength, TRUE, TRUE); EDIT_EM_SetSel(es, es->undo_position, es->undo_position + es->undo_insert_count, FALSE); /* send the notification after the selection start and end are set */ EDIT_NOTIFY_PARENT(es, EN_CHANGE); @@ -3077,7 +3076,7 @@ static inline BOOL EDIT_IsInsideDialog(EDITSTATE *es) static void EDIT_WM_Paste(EDITSTATE *es) { HGLOBAL hsrc; - LPWSTR src, new_src, ptr; + LPWSTR src, ptr; int len;
/* Protect read-only edit control from modification */ @@ -3087,25 +3086,19 @@ static void EDIT_WM_Paste(EDITSTATE *es) OpenClipboard(es->hwndSelf); if ((hsrc = GetClipboardData(CF_UNICODETEXT))) { src = GlobalLock(hsrc); - + len = strlenW(src); /* Protect single-line edit against pasting new line character */ if (!(es->style & ES_MULTILINE) && ((ptr = strchrW(src, '\n')))) { len = ptr - src; if (len && src[len - 1] == '\r') --len; - new_src = HeapAlloc(GetProcessHeap(), 0, (len+1) * sizeof(WCHAR)); - if (new_src != NULL) { - lstrcpynW(new_src, src, len+1); - EDIT_EM_ReplaceSel(es, TRUE, new_src, TRUE, TRUE); - HeapFree(GetProcessHeap(), 0, new_src); - } - } else - EDIT_EM_ReplaceSel(es, TRUE, src, TRUE, TRUE); + } + EDIT_EM_ReplaceSel(es, TRUE, src, len, TRUE, TRUE); GlobalUnlock(hsrc); } else if (es->style & ES_PASSWORD) { /* clear selected text in password edit box even with empty clipboard */ - EDIT_EM_ReplaceSel(es, TRUE, empty_stringW, TRUE, TRUE); + EDIT_EM_ReplaceSel(es, TRUE, NULL, 0, TRUE, TRUE); } CloseClipboard(); } @@ -3151,7 +3144,7 @@ static inline void EDIT_WM_Clear(EDITSTATE *es) if(es->style & ES_READONLY) return;
- EDIT_EM_ReplaceSel(es, TRUE, empty_stringW, TRUE, TRUE); + EDIT_EM_ReplaceSel(es, TRUE, NULL, 0, TRUE, TRUE); }
@@ -3193,18 +3186,18 @@ static LRESULT EDIT_WM_Char(EDITSTATE *es, WCHAR c) EDIT_MoveHome(es, FALSE, FALSE); EDIT_MoveDown_ML(es, FALSE); } else { - static const WCHAR cr_lfW[] = {'\r','\n',0}; - EDIT_EM_ReplaceSel(es, TRUE, cr_lfW, TRUE, TRUE); + static const WCHAR cr_lfW[] = {'\r','\n'}; + EDIT_EM_ReplaceSel(es, TRUE, cr_lfW, 2, TRUE, TRUE); } } break; case '\t': if ((es->style & ES_MULTILINE) && !(es->style & ES_READONLY)) { - static const WCHAR tabW[] = {'\t',0}; + static const WCHAR tabW[] = {'\t'}; if (EDIT_IsInsideDialog(es)) break; - EDIT_EM_ReplaceSel(es, TRUE, tabW, TRUE, TRUE); + EDIT_EM_ReplaceSel(es, TRUE, tabW, 1, TRUE, TRUE); } break; case VK_BACK: @@ -3241,12 +3234,8 @@ static LRESULT EDIT_WM_Char(EDITSTATE *es, WCHAR c) if( (es->style & ES_NUMBER) && !( c >= '0' && c <= '9') ) break; - if (!(es->style & ES_READONLY) && (c >= ' ') && (c != 127)) { - WCHAR str[2]; - str[0] = c; - str[1] = '\0'; - EDIT_EM_ReplaceSel(es, TRUE, str, TRUE, TRUE); - } + if (!(es->style & ES_READONLY) && (c >= ' ') && (c != 127)) + EDIT_EM_ReplaceSel(es, TRUE, &c, 1, TRUE, TRUE); break; } return 1; @@ -3904,14 +3893,14 @@ static void EDIT_WM_SetText(EDITSTATE *es, LPCWSTR text, BOOL unicode) if (text) { TRACE("%s\n", debugstr_w(text)); - EDIT_EM_ReplaceSel(es, FALSE, text, FALSE, FALSE); + EDIT_EM_ReplaceSel(es, FALSE, text, strlenW(text), FALSE, FALSE); if(!unicode) HeapFree(GetProcessHeap(), 0, textW); } else { TRACE("<NULL>\n"); - EDIT_EM_ReplaceSel(es, FALSE, empty_stringW, FALSE, FALSE); + EDIT_EM_ReplaceSel(es, FALSE, NULL, 0, FALSE, FALSE); } es->x_offset = 0; es->flags &= ~EF_MODIFIED; @@ -4325,7 +4314,7 @@ static void EDIT_GetCompositionStr(HIMC hIMC, LPARAM CompFlag, EDITSTATE *es) return; }
- lpCompStr = HeapAlloc(GetProcessHeap(),0,buflen + sizeof(WCHAR)); + lpCompStr = HeapAlloc(GetProcessHeap(),0,buflen); if (!lpCompStr) { ERR("Unable to allocate IME CompositionString\n"); @@ -4334,7 +4323,6 @@ static void EDIT_GetCompositionStr(HIMC hIMC, LPARAM CompFlag, EDITSTATE *es)
if (buflen) ImmGetCompositionStringW(hIMC, GCS_COMPSTR, lpCompStr, buflen); - lpCompStr[buflen/sizeof(WCHAR)] = 0;
if (CompFlag & GCS_COMPATTR) { @@ -4371,7 +4359,7 @@ static void EDIT_GetCompositionStr(HIMC hIMC, LPARAM CompFlag, EDITSTATE *es) else es->selection_end = es->selection_start;
- EDIT_EM_ReplaceSel(es, FALSE, lpCompStr, TRUE, TRUE); + EDIT_EM_ReplaceSel(es, FALSE, lpCompStr, buflen / sizeof(WCHAR), TRUE, TRUE); es->composition_len = abs(es->composition_start - es->selection_end);
es->selection_start = es->composition_start; @@ -4392,7 +4380,7 @@ static void EDIT_GetResultStr(HIMC hIMC, EDITSTATE *es) return; }
- lpResultStr = HeapAlloc(GetProcessHeap(),0, buflen+sizeof(WCHAR)); + lpResultStr = HeapAlloc(GetProcessHeap(),0, buflen); if (!lpResultStr) { ERR("Unable to alloc buffer for IME string\n"); @@ -4400,7 +4388,6 @@ static void EDIT_GetResultStr(HIMC hIMC, EDITSTATE *es) }
ImmGetCompositionStringW(hIMC, GCS_RESULTSTR, lpResultStr, buflen); - lpResultStr[buflen/sizeof(WCHAR)] = 0;
/* check for change in composition start */ if (es->selection_end < es->composition_start) @@ -4408,7 +4395,7 @@ static void EDIT_GetResultStr(HIMC hIMC, EDITSTATE *es)
es->selection_start = es->composition_start; es->selection_end = es->composition_start + es->composition_len; - EDIT_EM_ReplaceSel(es, TRUE, lpResultStr, TRUE, TRUE); + EDIT_EM_ReplaceSel(es, TRUE, lpResultStr, buflen / sizeof(WCHAR), TRUE, TRUE); es->composition_start = es->selection_end; es->composition_len = 0;
@@ -4422,7 +4409,7 @@ static void EDIT_ImeComposition(HWND hwnd, LPARAM CompFlag, EDITSTATE *es)
if (es->composition_len == 0 && es->selection_start != es->selection_end) { - EDIT_EM_ReplaceSel(es, TRUE, empty_stringW, TRUE, TRUE); + EDIT_EM_ReplaceSel(es, TRUE, NULL, 0, TRUE, TRUE); es->composition_start = es->selection_end; }
@@ -4587,7 +4574,7 @@ static LRESULT EDIT_WM_Create(EDITSTATE *es, LPCWSTR name) EDIT_SetRectNP(es, &clientRect);
if (name && *name) { - EDIT_EM_ReplaceSel(es, FALSE, name, FALSE, FALSE); + EDIT_EM_ReplaceSel(es, FALSE, name, strlenW(name), FALSE, FALSE); /* if we insert text to the editline, the text scrolls out * of the window, as the caret is placed after the insert * pos normally; thus we reset es->selection... to 0 and @@ -4771,7 +4758,7 @@ LRESULT EditWndProc_common( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam, B MultiByteToWideChar(CP_ACP, 0, textA, -1, textW, countW); }
- EDIT_EM_ReplaceSel(es, (BOOL)wParam, textW, TRUE, TRUE); + EDIT_EM_ReplaceSel(es, (BOOL)wParam, textW, strlenW(textW), TRUE, TRUE); result = 1;
if(!unicode) @@ -5175,7 +5162,7 @@ LRESULT EditWndProc_common( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam, B case WM_IME_ENDCOMPOSITION: if (es->composition_len > 0) { - EDIT_EM_ReplaceSel(es, TRUE, empty_stringW, TRUE, TRUE); + EDIT_EM_ReplaceSel(es, TRUE, NULL, 0, TRUE, TRUE); es->selection_end = es->selection_start; es->composition_len= 0; }