Commit 9215aabd authored by Alexandre Julliard's avatar Alexandre Julliard

user32: Pass the text length explicitly to EDIT_EM_ReplaceSel.

parent 6653d430
...@@ -176,7 +176,6 @@ typedef struct ...@@ -176,7 +176,6 @@ typedef struct
(LPARAM)(es->hwndSelf)); \ (LPARAM)(es->hwndSelf)); \
} while(0) } while(0)
static const WCHAR empty_stringW[] = {0};
static LRESULT EDIT_EM_PosFromChar(EDITSTATE *es, INT index, BOOL after_wrap); 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) ...@@ -2560,9 +2559,9 @@ static LRESULT EDIT_EM_GetSel(const EDITSTATE *es, PUINT start, PUINT end)
* FIXME: handle ES_NUMBER and ES_OEMCONVERT here * 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 tl = get_text_length(es);
UINT utl; UINT utl;
UINT s; UINT s;
...@@ -3043,7 +3042,7 @@ static BOOL EDIT_EM_Undo(EDITSTATE *es) ...@@ -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_SetSel(es, es->undo_position, es->undo_position + es->undo_insert_count, FALSE);
EDIT_EM_EmptyUndoBuffer(es); 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); 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 */ /* send the notification after the selection start and end are set */
EDIT_NOTIFY_PARENT(es, EN_CHANGE); EDIT_NOTIFY_PARENT(es, EN_CHANGE);
...@@ -3077,7 +3076,7 @@ static inline BOOL EDIT_IsInsideDialog(EDITSTATE *es) ...@@ -3077,7 +3076,7 @@ static inline BOOL EDIT_IsInsideDialog(EDITSTATE *es)
static void EDIT_WM_Paste(EDITSTATE *es) static void EDIT_WM_Paste(EDITSTATE *es)
{ {
HGLOBAL hsrc; HGLOBAL hsrc;
LPWSTR src, new_src, ptr; LPWSTR src, ptr;
int len; int len;
/* Protect read-only edit control from modification */ /* Protect read-only edit control from modification */
...@@ -3087,25 +3086,19 @@ static void EDIT_WM_Paste(EDITSTATE *es) ...@@ -3087,25 +3086,19 @@ static void EDIT_WM_Paste(EDITSTATE *es)
OpenClipboard(es->hwndSelf); OpenClipboard(es->hwndSelf);
if ((hsrc = GetClipboardData(CF_UNICODETEXT))) { if ((hsrc = GetClipboardData(CF_UNICODETEXT))) {
src = GlobalLock(hsrc); src = GlobalLock(hsrc);
len = strlenW(src);
/* Protect single-line edit against pasting new line character */ /* Protect single-line edit against pasting new line character */
if (!(es->style & ES_MULTILINE) && ((ptr = strchrW(src, '\n')))) { if (!(es->style & ES_MULTILINE) && ((ptr = strchrW(src, '\n')))) {
len = ptr - src; len = ptr - src;
if (len && src[len - 1] == '\r') if (len && src[len - 1] == '\r')
--len; --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, len, TRUE, TRUE);
EDIT_EM_ReplaceSel(es, TRUE, src, TRUE, TRUE);
GlobalUnlock(hsrc); GlobalUnlock(hsrc);
} }
else if (es->style & ES_PASSWORD) { else if (es->style & ES_PASSWORD) {
/* clear selected text in password edit box even with empty clipboard */ /* 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(); CloseClipboard();
} }
...@@ -3151,7 +3144,7 @@ static inline void EDIT_WM_Clear(EDITSTATE *es) ...@@ -3151,7 +3144,7 @@ static inline void EDIT_WM_Clear(EDITSTATE *es)
if(es->style & ES_READONLY) if(es->style & ES_READONLY)
return; 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) ...@@ -3193,18 +3186,18 @@ static LRESULT EDIT_WM_Char(EDITSTATE *es, WCHAR c)
EDIT_MoveHome(es, FALSE, FALSE); EDIT_MoveHome(es, FALSE, FALSE);
EDIT_MoveDown_ML(es, FALSE); EDIT_MoveDown_ML(es, FALSE);
} else { } else {
static const WCHAR cr_lfW[] = {'\r','\n',0}; static const WCHAR cr_lfW[] = {'\r','\n'};
EDIT_EM_ReplaceSel(es, TRUE, cr_lfW, TRUE, TRUE); EDIT_EM_ReplaceSel(es, TRUE, cr_lfW, 2, TRUE, TRUE);
} }
} }
break; break;
case '\t': case '\t':
if ((es->style & ES_MULTILINE) && !(es->style & ES_READONLY)) if ((es->style & ES_MULTILINE) && !(es->style & ES_READONLY))
{ {
static const WCHAR tabW[] = {'\t',0}; static const WCHAR tabW[] = {'\t'};
if (EDIT_IsInsideDialog(es)) if (EDIT_IsInsideDialog(es))
break; break;
EDIT_EM_ReplaceSel(es, TRUE, tabW, TRUE, TRUE); EDIT_EM_ReplaceSel(es, TRUE, tabW, 1, TRUE, TRUE);
} }
break; break;
case VK_BACK: case VK_BACK:
...@@ -3241,12 +3234,8 @@ static LRESULT EDIT_WM_Char(EDITSTATE *es, WCHAR c) ...@@ -3241,12 +3234,8 @@ static LRESULT EDIT_WM_Char(EDITSTATE *es, WCHAR c)
if( (es->style & ES_NUMBER) && !( c >= '0' && c <= '9') ) if( (es->style & ES_NUMBER) && !( c >= '0' && c <= '9') )
break; break;
if (!(es->style & ES_READONLY) && (c >= ' ') && (c != 127)) { if (!(es->style & ES_READONLY) && (c >= ' ') && (c != 127))
WCHAR str[2]; EDIT_EM_ReplaceSel(es, TRUE, &c, 1, TRUE, TRUE);
str[0] = c;
str[1] = '\0';
EDIT_EM_ReplaceSel(es, TRUE, str, TRUE, TRUE);
}
break; break;
} }
return 1; return 1;
...@@ -3904,14 +3893,14 @@ static void EDIT_WM_SetText(EDITSTATE *es, LPCWSTR text, BOOL unicode) ...@@ -3904,14 +3893,14 @@ static void EDIT_WM_SetText(EDITSTATE *es, LPCWSTR text, BOOL unicode)
if (text) if (text)
{ {
TRACE("%s\n", debugstr_w(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) if(!unicode)
HeapFree(GetProcessHeap(), 0, textW); HeapFree(GetProcessHeap(), 0, textW);
} }
else else
{ {
TRACE("<NULL>\n"); 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->x_offset = 0;
es->flags &= ~EF_MODIFIED; es->flags &= ~EF_MODIFIED;
...@@ -4325,7 +4314,7 @@ static void EDIT_GetCompositionStr(HIMC hIMC, LPARAM CompFlag, EDITSTATE *es) ...@@ -4325,7 +4314,7 @@ static void EDIT_GetCompositionStr(HIMC hIMC, LPARAM CompFlag, EDITSTATE *es)
return; return;
} }
lpCompStr = HeapAlloc(GetProcessHeap(),0,buflen + sizeof(WCHAR)); lpCompStr = HeapAlloc(GetProcessHeap(),0,buflen);
if (!lpCompStr) if (!lpCompStr)
{ {
ERR("Unable to allocate IME CompositionString\n"); ERR("Unable to allocate IME CompositionString\n");
...@@ -4334,7 +4323,6 @@ static void EDIT_GetCompositionStr(HIMC hIMC, LPARAM CompFlag, EDITSTATE *es) ...@@ -4334,7 +4323,6 @@ static void EDIT_GetCompositionStr(HIMC hIMC, LPARAM CompFlag, EDITSTATE *es)
if (buflen) if (buflen)
ImmGetCompositionStringW(hIMC, GCS_COMPSTR, lpCompStr, buflen); ImmGetCompositionStringW(hIMC, GCS_COMPSTR, lpCompStr, buflen);
lpCompStr[buflen/sizeof(WCHAR)] = 0;
if (CompFlag & GCS_COMPATTR) if (CompFlag & GCS_COMPATTR)
{ {
...@@ -4371,7 +4359,7 @@ static void EDIT_GetCompositionStr(HIMC hIMC, LPARAM CompFlag, EDITSTATE *es) ...@@ -4371,7 +4359,7 @@ static void EDIT_GetCompositionStr(HIMC hIMC, LPARAM CompFlag, EDITSTATE *es)
else else
es->selection_end = es->selection_start; 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->composition_len = abs(es->composition_start - es->selection_end);
es->selection_start = es->composition_start; es->selection_start = es->composition_start;
...@@ -4392,7 +4380,7 @@ static void EDIT_GetResultStr(HIMC hIMC, EDITSTATE *es) ...@@ -4392,7 +4380,7 @@ static void EDIT_GetResultStr(HIMC hIMC, EDITSTATE *es)
return; return;
} }
lpResultStr = HeapAlloc(GetProcessHeap(),0, buflen+sizeof(WCHAR)); lpResultStr = HeapAlloc(GetProcessHeap(),0, buflen);
if (!lpResultStr) if (!lpResultStr)
{ {
ERR("Unable to alloc buffer for IME string\n"); ERR("Unable to alloc buffer for IME string\n");
...@@ -4400,7 +4388,6 @@ static void EDIT_GetResultStr(HIMC hIMC, EDITSTATE *es) ...@@ -4400,7 +4388,6 @@ static void EDIT_GetResultStr(HIMC hIMC, EDITSTATE *es)
} }
ImmGetCompositionStringW(hIMC, GCS_RESULTSTR, lpResultStr, buflen); ImmGetCompositionStringW(hIMC, GCS_RESULTSTR, lpResultStr, buflen);
lpResultStr[buflen/sizeof(WCHAR)] = 0;
/* check for change in composition start */ /* check for change in composition start */
if (es->selection_end < es->composition_start) if (es->selection_end < es->composition_start)
...@@ -4408,7 +4395,7 @@ static void EDIT_GetResultStr(HIMC hIMC, EDITSTATE *es) ...@@ -4408,7 +4395,7 @@ static void EDIT_GetResultStr(HIMC hIMC, EDITSTATE *es)
es->selection_start = es->composition_start; es->selection_start = es->composition_start;
es->selection_end = es->composition_start + es->composition_len; 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_start = es->selection_end;
es->composition_len = 0; es->composition_len = 0;
...@@ -4422,7 +4409,7 @@ static void EDIT_ImeComposition(HWND hwnd, LPARAM CompFlag, EDITSTATE *es) ...@@ -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) 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; es->composition_start = es->selection_end;
} }
...@@ -4587,7 +4574,7 @@ static LRESULT EDIT_WM_Create(EDITSTATE *es, LPCWSTR name) ...@@ -4587,7 +4574,7 @@ static LRESULT EDIT_WM_Create(EDITSTATE *es, LPCWSTR name)
EDIT_SetRectNP(es, &clientRect); EDIT_SetRectNP(es, &clientRect);
if (name && *name) { 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 /* if we insert text to the editline, the text scrolls out
* of the window, as the caret is placed after the insert * of the window, as the caret is placed after the insert
* pos normally; thus we reset es->selection... to 0 and * 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 ...@@ -4771,7 +4758,7 @@ LRESULT EditWndProc_common( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam, B
MultiByteToWideChar(CP_ACP, 0, textA, -1, textW, countW); 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; result = 1;
if(!unicode) if(!unicode)
...@@ -5175,7 +5162,7 @@ LRESULT EditWndProc_common( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam, B ...@@ -5175,7 +5162,7 @@ LRESULT EditWndProc_common( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam, B
case WM_IME_ENDCOMPOSITION: case WM_IME_ENDCOMPOSITION:
if (es->composition_len > 0) 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->selection_end = es->selection_start;
es->composition_len= 0; es->composition_len= 0;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment