This is basically a no-op to make the following fix simpler
Signed-off-by: Fabian Maurer dark.shadow4@web.de --- dlls/riched20/editor.c | 322 +++++++++++++++++++++-------------------- 1 file changed, 168 insertions(+), 154 deletions(-)
diff --git a/dlls/riched20/editor.c b/dlls/riched20/editor.c index 99c87bf61d..9142fd917d 100644 --- a/dlls/riched20/editor.c +++ b/dlls/riched20/editor.c @@ -2427,6 +2427,171 @@ static void ME_UpdateSelectionLinkAttribute(ME_TextEditor *editor) ME_UpdateLinkAttribute(editor, &start, nChars); }
+static INT handle_enter(ME_TextEditor *editor) +{ + BOOL ctrl_is_down = GetKeyState(VK_CONTROL) & 0x8000; + BOOL shift_is_down = GetKeyState(VK_SHIFT) & 0x8000; + + if (editor->bDialogMode) + { + if (ctrl_is_down) + return TRUE; + + if (!(editor->styleFlags & ES_WANTRETURN)) + { + if (editor->hwndParent) + { + DWORD dw; + dw = SendMessageW(editor->hwndParent, DM_GETDEFID, 0, 0); + if (HIWORD(dw) == DC_HASDEFID) + { + HWND hwDefCtrl = GetDlgItem(editor->hwndParent, LOWORD(dw)); + if (hwDefCtrl) + { + SendMessageW(editor->hwndParent, WM_NEXTDLGCTL, (WPARAM)hwDefCtrl, TRUE); + PostMessageW(hwDefCtrl, WM_KEYDOWN, VK_RETURN, 0); + } + } + } + return TRUE; + } + } + + if (editor->styleFlags & ES_MULTILINE) + { + static const WCHAR endl = '\r'; + static const WCHAR endlv10[] = {'\r','\n'}; + ME_Cursor cursor = editor->pCursors[0]; + ME_DisplayItem *para = cursor.pPara; + int from, to; + ME_Style *style, *eop_style; + + if (editor->styleFlags & ES_READONLY) + { + MessageBeep(MB_ICONERROR); + return TRUE; + } + + ME_GetSelectionOfs(editor, &from, &to); + if (editor->nTextLimit > ME_GetTextLength(editor) - (to-from)) + { + if (!editor->bEmulateVersion10) { /* v4.1 */ + if (para->member.para.nFlags & MEPF_ROWEND) { + /* Add a new table row after this row. */ + para = ME_AppendTableRow(editor, para); + para = para->member.para.next_para; + editor->pCursors[0].pPara = para; + editor->pCursors[0].pRun = ME_FindItemFwd(para, diRun); + editor->pCursors[0].nOffset = 0; + editor->pCursors[1] = editor->pCursors[0]; + ME_CommitUndo(editor); + ME_CheckTablesForCorruption(editor); + ME_UpdateRepaint(editor, FALSE); + return TRUE; + } + else if (para == editor->pCursors[1].pPara && + cursor.nOffset + cursor.pRun->member.run.nCharOfs == 0 && + para->member.para.prev_para->member.para.nFlags & MEPF_ROWSTART && + !para->member.para.prev_para->member.para.nCharOfs) + { + /* Insert a newline before the table. */ + para = para->member.para.prev_para; + para->member.para.nFlags &= ~MEPF_ROWSTART; + editor->pCursors[0].pPara = para; + editor->pCursors[0].pRun = ME_FindItemFwd(para, diRun); + editor->pCursors[1] = editor->pCursors[0]; + ME_InsertTextFromCursor(editor, 0, &endl, 1, + editor->pCursors[0].pRun->member.run.style); + para = editor->pBuffer->pFirst->member.para.next_para; + ME_SetDefaultParaFormat(editor, ¶->member.para.fmt); + para->member.para.nFlags = 0; + mark_para_rewrap(editor, para); + editor->pCursors[0].pPara = para; + editor->pCursors[0].pRun = ME_FindItemFwd(para, diRun); + editor->pCursors[1] = editor->pCursors[0]; + para->member.para.next_para->member.para.nFlags |= MEPF_ROWSTART; + ME_CommitCoalescingUndo(editor); + ME_CheckTablesForCorruption(editor); + ME_UpdateRepaint(editor, FALSE); + return TRUE; + } + } else { /* v1.0 - 3.0 */ + ME_DisplayItem *para = cursor.pPara; + if (ME_IsInTable(para)) + { + if (cursor.pRun->member.run.nFlags & MERF_ENDPARA) + { + if (from == to) { + ME_ContinueCoalescingTransaction(editor); + para = ME_AppendTableRow(editor, para); + editor->pCursors[0].pPara = para; + editor->pCursors[0].pRun = ME_FindItemFwd(para, diRun); + editor->pCursors[0].nOffset = 0; + editor->pCursors[1] = editor->pCursors[0]; + ME_CommitCoalescingUndo(editor); + ME_UpdateRepaint(editor, FALSE); + return TRUE; + } + } else { + ME_ContinueCoalescingTransaction(editor); + if (cursor.pRun->member.run.nCharOfs + cursor.nOffset == 0 && + !ME_IsInTable(para->member.para.prev_para)) + { + /* Insert newline before table */ + cursor.pRun = ME_FindItemBack(para, diRun); + if (cursor.pRun) { + editor->pCursors[0].pRun = cursor.pRun; + editor->pCursors[0].pPara = para->member.para.prev_para; + } + editor->pCursors[0].nOffset = 0; + editor->pCursors[1] = editor->pCursors[0]; + ME_InsertTextFromCursor(editor, 0, &endl, 1, + editor->pCursors[0].pRun->member.run.style); + } else { + editor->pCursors[1] = editor->pCursors[0]; + para = ME_AppendTableRow(editor, para); + editor->pCursors[0].pPara = para; + editor->pCursors[0].pRun = ME_FindItemFwd(para, diRun); + editor->pCursors[0].nOffset = 0; + editor->pCursors[1] = editor->pCursors[0]; + } + ME_CommitCoalescingUndo(editor); + ME_UpdateRepaint(editor, FALSE); + return TRUE; + } + } + } + + style = ME_GetInsertStyle(editor, 0); + + /* Normally the new eop style is the insert style, however in a list it is copied from the existing + eop style (this prevents the list label style changing when the new eop is inserted). + No extra ref is taken here on eop_style. */ + if (para->member.para.fmt.wNumbering) + eop_style = para->member.para.eop_run->style; + else + eop_style = style; + ME_ContinueCoalescingTransaction(editor); + if (shift_is_down) + ME_InsertEndRowFromCursor(editor, 0); + else + if (!editor->bEmulateVersion10) + ME_InsertTextFromCursor(editor, 0, &endl, 1, eop_style); + else + ME_InsertTextFromCursor(editor, 0, endlv10, 2, eop_style); + ME_CommitCoalescingUndo(editor); + SetCursor(NULL); + + ME_UpdateSelectionLinkAttribute(editor); + ME_UpdateRepaint(editor, FALSE); + ME_SaveTempStyle(editor, style); /* set the temp insert style for the new para */ + ME_ReleaseStyle(style); + } + return TRUE; + } + return -1; +} + static BOOL ME_KeyDown(ME_TextEditor *editor, WORD nKey) { @@ -2493,161 +2658,10 @@ ME_KeyDown(ME_TextEditor *editor, WORD nKey) ME_SendRequestResize(editor, FALSE); return TRUE; case VK_RETURN: - if (editor->bDialogMode) { - if (ctrl_is_down) - return TRUE; - - if (!(editor->styleFlags & ES_WANTRETURN)) - { - if (editor->hwndParent) - { - DWORD dw; - dw = SendMessageW(editor->hwndParent, DM_GETDEFID, 0, 0); - if (HIWORD(dw) == DC_HASDEFID) - { - HWND hwDefCtrl = GetDlgItem(editor->hwndParent, LOWORD(dw)); - if (hwDefCtrl) - { - SendMessageW(editor->hwndParent, WM_NEXTDLGCTL, (WPARAM)hwDefCtrl, TRUE); - PostMessageW(hwDefCtrl, WM_KEYDOWN, VK_RETURN, 0); - } - } - } - return TRUE; - } - } - - if (editor->styleFlags & ES_MULTILINE) - { - static const WCHAR endl = '\r'; - static const WCHAR endlv10[] = {'\r','\n'}; - ME_Cursor cursor = editor->pCursors[0]; - ME_DisplayItem *para = cursor.pPara; - int from, to; - ME_Style *style, *eop_style; - - if (editor->styleFlags & ES_READONLY) { - MessageBeep(MB_ICONERROR); - return TRUE; - } - - ME_GetSelectionOfs(editor, &from, &to); - if (editor->nTextLimit > ME_GetTextLength(editor) - (to-from)) - { - if (!editor->bEmulateVersion10) { /* v4.1 */ - if (para->member.para.nFlags & MEPF_ROWEND) { - /* Add a new table row after this row. */ - para = ME_AppendTableRow(editor, para); - para = para->member.para.next_para; - editor->pCursors[0].pPara = para; - editor->pCursors[0].pRun = ME_FindItemFwd(para, diRun); - editor->pCursors[0].nOffset = 0; - editor->pCursors[1] = editor->pCursors[0]; - ME_CommitUndo(editor); - ME_CheckTablesForCorruption(editor); - ME_UpdateRepaint(editor, FALSE); - return TRUE; - } - else if (para == editor->pCursors[1].pPara && - cursor.nOffset + cursor.pRun->member.run.nCharOfs == 0 && - para->member.para.prev_para->member.para.nFlags & MEPF_ROWSTART && - !para->member.para.prev_para->member.para.nCharOfs) - { - /* Insert a newline before the table. */ - para = para->member.para.prev_para; - para->member.para.nFlags &= ~MEPF_ROWSTART; - editor->pCursors[0].pPara = para; - editor->pCursors[0].pRun = ME_FindItemFwd(para, diRun); - editor->pCursors[1] = editor->pCursors[0]; - ME_InsertTextFromCursor(editor, 0, &endl, 1, - editor->pCursors[0].pRun->member.run.style); - para = editor->pBuffer->pFirst->member.para.next_para; - ME_SetDefaultParaFormat(editor, ¶->member.para.fmt); - para->member.para.nFlags = 0; - mark_para_rewrap(editor, para); - editor->pCursors[0].pPara = para; - editor->pCursors[0].pRun = ME_FindItemFwd(para, diRun); - editor->pCursors[1] = editor->pCursors[0]; - para->member.para.next_para->member.para.nFlags |= MEPF_ROWSTART; - ME_CommitCoalescingUndo(editor); - ME_CheckTablesForCorruption(editor); - ME_UpdateRepaint(editor, FALSE); - return TRUE; - } - } else { /* v1.0 - 3.0 */ - ME_DisplayItem *para = cursor.pPara; - if (ME_IsInTable(para)) - { - if (cursor.pRun->member.run.nFlags & MERF_ENDPARA) - { - if (from == to) { - ME_ContinueCoalescingTransaction(editor); - para = ME_AppendTableRow(editor, para); - editor->pCursors[0].pPara = para; - editor->pCursors[0].pRun = ME_FindItemFwd(para, diRun); - editor->pCursors[0].nOffset = 0; - editor->pCursors[1] = editor->pCursors[0]; - ME_CommitCoalescingUndo(editor); - ME_UpdateRepaint(editor, FALSE); - return TRUE; - } - } else { - ME_ContinueCoalescingTransaction(editor); - if (cursor.pRun->member.run.nCharOfs + cursor.nOffset == 0 && - !ME_IsInTable(para->member.para.prev_para)) - { - /* Insert newline before table */ - cursor.pRun = ME_FindItemBack(para, diRun); - if (cursor.pRun) { - editor->pCursors[0].pRun = cursor.pRun; - editor->pCursors[0].pPara = para->member.para.prev_para; - } - editor->pCursors[0].nOffset = 0; - editor->pCursors[1] = editor->pCursors[0]; - ME_InsertTextFromCursor(editor, 0, &endl, 1, - editor->pCursors[0].pRun->member.run.style); - } else { - editor->pCursors[1] = editor->pCursors[0]; - para = ME_AppendTableRow(editor, para); - editor->pCursors[0].pPara = para; - editor->pCursors[0].pRun = ME_FindItemFwd(para, diRun); - editor->pCursors[0].nOffset = 0; - editor->pCursors[1] = editor->pCursors[0]; - } - ME_CommitCoalescingUndo(editor); - ME_UpdateRepaint(editor, FALSE); - return TRUE; - } - } - } - - style = ME_GetInsertStyle(editor, 0); - - /* Normally the new eop style is the insert style, however in a list it is copied from the existing - eop style (this prevents the list label style changing when the new eop is inserted). - No extra ref is taken here on eop_style. */ - if (para->member.para.fmt.wNumbering) - eop_style = para->member.para.eop_run->style; - else - eop_style = style; - ME_ContinueCoalescingTransaction(editor); - if (shift_is_down) - ME_InsertEndRowFromCursor(editor, 0); - else - if (!editor->bEmulateVersion10) - ME_InsertTextFromCursor(editor, 0, &endl, 1, eop_style); - else - ME_InsertTextFromCursor(editor, 0, endlv10, 2, eop_style); - ME_CommitCoalescingUndo(editor); - SetCursor(NULL); - - ME_UpdateSelectionLinkAttribute(editor); - ME_UpdateRepaint(editor, FALSE); - ME_SaveTempStyle(editor, style); /* set the temp insert style for the new para */ - ME_ReleaseStyle(style); - } - return TRUE; + INT result = handle_enter(editor); + if (result != -1) + return result; } break; case VK_ESCAPE:
This is basically a no-op to make the tests and the following additions simpler
Signed-off-by: Fabian Maurer dark.shadow4@web.de --- dlls/riched20/tests/editor.c | 51 ++++++++++++++---------------------- dlls/riched32/tests/editor.c | 51 ++++++++++++++---------------------- 2 files changed, 40 insertions(+), 62 deletions(-)
diff --git a/dlls/riched20/tests/editor.c b/dlls/riched20/tests/editor.c index 035869e134..5c2df7f86c 100644 --- a/dlls/riched20/tests/editor.c +++ b/dlls/riched20/tests/editor.c @@ -8259,6 +8259,14 @@ static void test_EM_FINDWORDBREAK_A(void) DestroyWindow(hwndRichEdit); }
+static void format_test_result(char *target, const char *src) +{ + int i; + for (i = 0; i < strlen(src); i++) + sprintf(target + 2*i, "%02x", src[i] & 0xFF); + target[2*i] = 0; +} + /* * This test attempts to show the effect of enter on a richedit * control v1.0 inserts CRLF whereas for higher versions it only @@ -8285,13 +8293,12 @@ static void test_enter(void) char expectedbuf[1024]; char resultbuf[1024]; HWND hwndRichEdit = new_richedit(NULL); - UINT i,j; + UINT i; + char buf[1024] = {0}; + GETTEXTEX getText = {sizeof(buf)}; + LRESULT result;
for (i = 0; i < ARRAY_SIZE(testenteritems); i++) { - - char buf[1024] = {0}; - LRESULT result; - GETTEXTEX getText; const char *expected;
/* Set the text to the initial text */ @@ -8307,12 +8314,8 @@ static void test_enter(void) result = SendMessageA(hwndRichEdit, WM_GETTEXT, 1024, (LPARAM)buf); expected = testenteritems[i].expectedwmtext;
- resultbuf[0]=0x00; - for (j = 0; j < (UINT)result; j++) - sprintf(resultbuf+strlen(resultbuf), "%02x", buf[j] & 0xFF); - expectedbuf[0] = '\0'; - for (j = 0; j < strlen(expected); j++) - sprintf(expectedbuf+strlen(expectedbuf), "%02x", expected[j] & 0xFF); + format_test_result(resultbuf, buf); + format_test_result(expectedbuf, expected);
result = strcmp(expected, buf); ok (result == 0, @@ -8320,21 +8323,14 @@ static void test_enter(void) i, resultbuf, expectedbuf);
/* 2. Retrieve with EM_GETTEXTEX, GT_DEFAULT */ - getText.cb = sizeof(buf); getText.flags = GT_DEFAULT; - getText.codepage = CP_ACP; - getText.lpDefaultChar = NULL; - getText.lpUsedDefChar = NULL; + getText.codepage = CP_ACP; buf[0] = 0x00; result = SendMessageA(hwndRichEdit, EM_GETTEXTEX, (WPARAM)&getText, (LPARAM)buf); expected = testenteritems[i].expectedemtext;
- resultbuf[0]=0x00; - for (j = 0; j < (UINT)result; j++) - sprintf(resultbuf+strlen(resultbuf), "%02x", buf[j] & 0xFF); - expectedbuf[0] = '\0'; - for (j = 0; j < strlen(expected); j++) - sprintf(expectedbuf+strlen(expectedbuf), "%02x", expected[j] & 0xFF); + format_test_result(resultbuf, buf); + format_test_result(expectedbuf, expected);
result = strcmp(expected, buf); ok (result == 0, @@ -8342,21 +8338,14 @@ static void test_enter(void) i, resultbuf, expectedbuf);
/* 3. Retrieve with EM_GETTEXTEX, GT_USECRLF */ - getText.cb = sizeof(buf); getText.flags = GT_USECRLF; - getText.codepage = CP_ACP; - getText.lpDefaultChar = NULL; - getText.lpUsedDefChar = NULL; + getText.codepage = CP_ACP; buf[0] = 0x00; result = SendMessageA(hwndRichEdit, EM_GETTEXTEX, (WPARAM)&getText, (LPARAM)buf); expected = testenteritems[i].expectedemtextcrlf;
- resultbuf[0]=0x00; - for (j = 0; j < (UINT)result; j++) - sprintf(resultbuf+strlen(resultbuf), "%02x", buf[j] & 0xFF); - expectedbuf[0] = '\0'; - for (j = 0; j < strlen(expected); j++) - sprintf(expectedbuf+strlen(expectedbuf), "%02x", expected[j] & 0xFF); + format_test_result(resultbuf, buf); + format_test_result(expectedbuf, expected);
result = strcmp(expected, buf); ok (result == 0, diff --git a/dlls/riched32/tests/editor.c b/dlls/riched32/tests/editor.c index 7751d2b402..64ad0f3029 100644 --- a/dlls/riched32/tests/editor.c +++ b/dlls/riched32/tests/editor.c @@ -1149,6 +1149,14 @@ static void simulate_typing_characters(HWND hwnd, const char* szChars) } }
+static void format_test_result(char *target, const char *src) +{ + int i; + for (i = 0; i < strlen(src); i++) + sprintf(target + 2*i, "%02x", src[i] & 0xFF); + target[2*i] = 0; +} + /* * This test attempts to show the effect of enter on a richedit * control v1.0 inserts CRLF whereas for higher versions it only @@ -1173,13 +1181,12 @@ static void test_enter(void) char expectedbuf[1024]; char resultbuf[1024]; HWND hwndRichEdit = new_richedit(NULL); - UINT i,j; + UINT i; + char buf[1024] = {0}; + GETTEXTEX getText = {sizeof(buf)}; + LRESULT result;
for (i = 0; i < ARRAY_SIZE(testenteritems); i++) { - - char buf[1024] = {0}; - LRESULT result; - GETTEXTEX getText; const char *expected;
/* Set the text to the initial text */ @@ -1195,12 +1202,8 @@ static void test_enter(void) result = SendMessageA(hwndRichEdit, WM_GETTEXT, 1024, (LPARAM)buf); expected = testenteritems[i].expectedtext;
- resultbuf[0]=0x00; - for (j = 0; j < (UINT)result; j++) - sprintf(resultbuf+strlen(resultbuf), "%02x", buf[j] & 0xFF); - expectedbuf[0] = '\0'; - for (j = 0; j < strlen(expected); j++) - sprintf(expectedbuf+strlen(expectedbuf), "%02x", expected[j] & 0xFF); + format_test_result(resultbuf, buf); + format_test_result(expectedbuf, expected);
result = strcmp(expected, buf); ok (result == 0, @@ -1208,21 +1211,14 @@ static void test_enter(void) i, resultbuf, expectedbuf);
/* 2. Retrieve with EM_GETTEXTEX, GT_DEFAULT */ - getText.cb = sizeof(buf); getText.flags = GT_DEFAULT; - getText.codepage = CP_ACP; - getText.lpDefaultChar = NULL; - getText.lpUsedDefChar = NULL; + getText.codepage = CP_ACP; buf[0] = 0x00; result = SendMessageA(hwndRichEdit, EM_GETTEXTEX, (WPARAM)&getText, (LPARAM)buf); expected = testenteritems[i].expectedtext;
- resultbuf[0]=0x00; - for (j = 0; j < (UINT)result; j++) - sprintf(resultbuf+strlen(resultbuf), "%02x", buf[j] & 0xFF); - expectedbuf[0] = '\0'; - for (j = 0; j < strlen(expected); j++) - sprintf(expectedbuf+strlen(expectedbuf), "%02x", expected[j] & 0xFF); + format_test_result(resultbuf, buf); + format_test_result(expectedbuf, expected);
result = strcmp(expected, buf); ok (result == 0 || broken(buf[0]==0x00 /* WinNT4 */), @@ -1230,21 +1226,14 @@ static void test_enter(void) i, resultbuf, expectedbuf);
/* 3. Retrieve with EM_GETTEXTEX, GT_USECRLF */ - getText.cb = sizeof(buf); getText.flags = GT_USECRLF; - getText.codepage = CP_ACP; - getText.lpDefaultChar = NULL; - getText.lpUsedDefChar = NULL; + getText.codepage = CP_ACP; buf[0] = 0x00; result = SendMessageA(hwndRichEdit, EM_GETTEXTEX, (WPARAM)&getText, (LPARAM)buf); expected = testenteritems[i].expectedtext;
- resultbuf[0]=0x00; - for (j = 0; j < (UINT)result; j++) - sprintf(resultbuf+strlen(resultbuf), "%02x", buf[j] & 0xFF); - expectedbuf[0] = '\0'; - for (j = 0; j < strlen(expected); j++) - sprintf(expectedbuf+strlen(expectedbuf), "%02x", expected[j] & 0xFF); + format_test_result(resultbuf, buf); + format_test_result(expectedbuf, expected);
result = strcmp(expected, buf); ok (result == 0 || broken(buf[0]==0x00 /* WinNT4 */),
The test error here isn't new. Dunno why the testbot didn't send a mail for that though.
Fabian Maurer
On Sun, Dec 09, 2018 at 11:51:56PM +0100, Fabian Maurer wrote:
This is basically a no-op to make the tests and the following additions simpler
Signed-off-by: Fabian Maurer dark.shadow4@web.de
dlls/riched20/tests/editor.c | 51 ++++++++++++++---------------------- dlls/riched32/tests/editor.c | 51 ++++++++++++++---------------------- 2 files changed, 40 insertions(+), 62 deletions(-)
diff --git a/dlls/riched20/tests/editor.c b/dlls/riched20/tests/editor.c index 035869e134..5c2df7f86c 100644 --- a/dlls/riched20/tests/editor.c +++ b/dlls/riched20/tests/editor.c @@ -8259,6 +8259,14 @@ static void test_EM_FINDWORDBREAK_A(void) DestroyWindow(hwndRichEdit); }
+static void format_test_result(char *target, const char *src) +{
- int i;
- for (i = 0; i < strlen(src); i++)
sprintf(target + 2*i, "%02x", src[i] & 0xFF);- target[2*i] = 0;
+}
/*
- This test attempts to show the effect of enter on a richedit
- control v1.0 inserts CRLF whereas for higher versions it only
@@ -8285,13 +8293,12 @@ static void test_enter(void) char expectedbuf[1024]; char resultbuf[1024]; HWND hwndRichEdit = new_richedit(NULL);
- UINT i,j;
UINT i;
char buf[1024] = {0};
GETTEXTEX getText = {sizeof(buf)};
LRESULT result;
for (i = 0; i < ARRAY_SIZE(testenteritems); i++) {
- char buf[1024] = {0};
- LRESULT result;
- GETTEXTEX getText; const char *expected;
Might as well move expected to the outer block too.
This fixes an old regression when VK_RETURN handling was implemented
Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=23282 Signed-off-by: Fabian Maurer dark.shadow4@web.de --- dlls/riched20/editor.c | 4 ++++ dlls/riched20/tests/editor.c | 31 +++++++++++++++++++++++++++++++ dlls/riched32/tests/editor.c | 31 +++++++++++++++++++++++++++++++ 3 files changed, 66 insertions(+)
diff --git a/dlls/riched20/editor.c b/dlls/riched20/editor.c index 9142fd917d..8dc1a01f70 100644 --- a/dlls/riched20/editor.c +++ b/dlls/riched20/editor.c @@ -2658,6 +2658,7 @@ ME_KeyDown(ME_TextEditor *editor, WORD nKey) ME_SendRequestResize(editor, FALSE); return TRUE; case VK_RETURN: + if (!editor->bEmulateVersion10) { INT result = handle_enter(editor); if (result != -1) @@ -2732,6 +2733,9 @@ static LRESULT ME_Char(ME_TextEditor *editor, WPARAM charCode, { WCHAR wstr;
+ if (editor->bEmulateVersion10 && charCode == '\r') + handle_enter(editor); + if (editor->bMouseCaptured) return 0;
diff --git a/dlls/riched20/tests/editor.c b/dlls/riched20/tests/editor.c index 5c2df7f86c..690c9b6e67 100644 --- a/dlls/riched20/tests/editor.c +++ b/dlls/riched20/tests/editor.c @@ -8273,6 +8273,7 @@ static void format_test_result(char *target, const char *src) * inserts CR. If shows that EM_GETTEXTEX with GT_USECRLF == WM_GETTEXT * and also shows that GT_USECRLF has no effect in richedit 1.0, but * does for higher. The same test is cloned in riched32 and riched20. + * Also shows the difference between WM_CHAR/WM_KEYDOWN in v1.0 and higher versions */ static void test_enter(void) { @@ -8353,6 +8354,36 @@ static void test_enter(void) i, resultbuf, expectedbuf); }
+ /* Show that WM_CHAR is handled differently from WM_KEYDOWN */ + getText.flags = GT_DEFAULT; + getText.codepage = CP_ACP; + + result = SendMessageA(hwndRichEdit, WM_SETTEXT, 0, (LPARAM)""); + ok (result == 1, "[%d] WM_SETTEXT returned %ld instead of 1\n", i, result); + SendMessageW(hwndRichEdit, WM_CHAR, 'T', 0); + SendMessageW(hwndRichEdit, WM_KEYDOWN, VK_RETURN, 0); + + SendMessageA(hwndRichEdit, EM_GETTEXTEX, (WPARAM)&getText, (LPARAM)buf); + format_test_result(resultbuf, buf); + format_test_result(expectedbuf, "T\r"); + result = strcmp(resultbuf, expectedbuf); + ok (result == 0 || broken(buf[0]==0x00 /* WinNT4 */), + "[%d] EM_GETTEXTEX, GT_DEFAULT unexpected '%s', expected '%s'\n", + i, resultbuf, expectedbuf); + + result = SendMessageA(hwndRichEdit, WM_SETTEXT, 0, (LPARAM)""); + ok (result == 1, "[%d] WM_SETTEXT returned %ld instead of 1\n", i, result); + SendMessageW(hwndRichEdit, WM_CHAR, 'T', 0); + SendMessageW(hwndRichEdit, WM_CHAR, '\r', 0); + + result = SendMessageA(hwndRichEdit, EM_GETTEXTEX, (WPARAM)&getText, (LPARAM)buf); + format_test_result(resultbuf, buf); + format_test_result(expectedbuf, "T"); + result = strcmp(resultbuf, expectedbuf); + ok (result == 0 || broken(buf[0]==0x00 /* WinNT4 */), + "[%d] EM_GETTEXTEX, GT_DEFAULT unexpected '%s', expected '%s'\n", + i, resultbuf, expectedbuf); + DestroyWindow(hwndRichEdit); }
diff --git a/dlls/riched32/tests/editor.c b/dlls/riched32/tests/editor.c index 64ad0f3029..b3835fa346 100644 --- a/dlls/riched32/tests/editor.c +++ b/dlls/riched32/tests/editor.c @@ -1163,6 +1163,7 @@ static void format_test_result(char *target, const char *src) * inserts CR. If shows that EM_GETTEXTEX with GT_USECRLF == WM_GETTEXT * and also shows that GT_USECRLF has no effect in richedit 1.0, but * does for higher. The same test is cloned in riched32 and riched20. + * Also shows the difference between WM_CHAR/WM_KEYDOWN in v1.0 and higher versions */ static void test_enter(void) { @@ -1241,6 +1242,36 @@ static void test_enter(void) i, resultbuf, expectedbuf); }
+ /* Show that WM_CHAR is handled differently from WM_KEYDOWN */ + getText.flags = GT_DEFAULT; + getText.codepage = CP_ACP; + + result = SendMessageA(hwndRichEdit, WM_SETTEXT, 0, (LPARAM)""); + ok (result == 1, "[%d] WM_SETTEXT returned %ld instead of 1\n", i, result); + SendMessageW(hwndRichEdit, WM_CHAR, 'T', 0); + SendMessageW(hwndRichEdit, WM_KEYDOWN, VK_RETURN, 0); + + SendMessageA(hwndRichEdit, EM_GETTEXTEX, (WPARAM)&getText, (LPARAM)buf); + format_test_result(resultbuf, buf); + format_test_result(expectedbuf, "T"); + result = strcmp(resultbuf, expectedbuf); + ok (result == 0 || broken(buf[0]==0x00 /* WinNT4 */), + "[%d] EM_GETTEXTEX, GT_DEFAULT unexpected '%s', expected '%s'\n", + i, resultbuf, expectedbuf); + + result = SendMessageA(hwndRichEdit, WM_SETTEXT, 0, (LPARAM)""); + ok (result == 1, "[%d] WM_SETTEXT returned %ld instead of 1\n", i, result); + SendMessageW(hwndRichEdit, WM_CHAR, 'T', 0); + SendMessageW(hwndRichEdit, WM_CHAR, '\r', 0); + + SendMessageA(hwndRichEdit, EM_GETTEXTEX, (WPARAM)&getText, (LPARAM)buf); + format_test_result(resultbuf, buf); + format_test_result(expectedbuf, "T\r\n"); + result = strcmp(resultbuf, expectedbuf); + ok (result == 0 || broken(buf[0]==0x00 /* WinNT4 */), + "[%d] EM_GETTEXTEX, GT_DEFAULT unexpected '%s', expected '%s'\n", + i, resultbuf, expectedbuf); + DestroyWindow(hwndRichEdit); }
On Sun, Dec 09, 2018 at 11:51:57PM +0100, Fabian Maurer wrote:
This fixes an old regression when VK_RETURN handling was implemented
Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=23282 Signed-off-by: Fabian Maurer dark.shadow4@web.de
dlls/riched20/editor.c | 4 ++++ dlls/riched20/tests/editor.c | 31 +++++++++++++++++++++++++++++++ dlls/riched32/tests/editor.c | 31 +++++++++++++++++++++++++++++++ 3 files changed, 66 insertions(+)
diff --git a/dlls/riched20/editor.c b/dlls/riched20/editor.c index 9142fd917d..8dc1a01f70 100644 --- a/dlls/riched20/editor.c +++ b/dlls/riched20/editor.c @@ -2658,6 +2658,7 @@ ME_KeyDown(ME_TextEditor *editor, WORD nKey) ME_SendRequestResize(editor, FALSE); return TRUE; case VK_RETURN:
if (!editor->bEmulateVersion10) { INT result = handle_enter(editor); if (result != -1)@@ -2732,6 +2733,9 @@ static LRESULT ME_Char(ME_TextEditor *editor, WPARAM charCode, { WCHAR wstr;
- if (editor->bEmulateVersion10 && charCode == '\r')
handle_enter(editor);- if (editor->bMouseCaptured) return 0;
diff --git a/dlls/riched20/tests/editor.c b/dlls/riched20/tests/editor.c index 5c2df7f86c..690c9b6e67 100644 --- a/dlls/riched20/tests/editor.c +++ b/dlls/riched20/tests/editor.c @@ -8273,6 +8273,7 @@ static void format_test_result(char *target, const char *src)
- inserts CR. If shows that EM_GETTEXTEX with GT_USECRLF == WM_GETTEXT
- and also shows that GT_USECRLF has no effect in richedit 1.0, but
- does for higher. The same test is cloned in riched32 and riched20.
*/
- Also shows the difference between WM_CHAR/WM_KEYDOWN in v1.0 and higher versions
static void test_enter(void) { @@ -8353,6 +8354,36 @@ static void test_enter(void) i, resultbuf, expectedbuf); }
- /* Show that WM_CHAR is handled differently from WM_KEYDOWN */
- getText.flags = GT_DEFAULT;
- getText.codepage = CP_ACP;
- result = SendMessageA(hwndRichEdit, WM_SETTEXT, 0, (LPARAM)"");
- ok (result == 1, "[%d] WM_SETTEXT returned %ld instead of 1\n", i, result);
- SendMessageW(hwndRichEdit, WM_CHAR, 'T', 0);
- SendMessageW(hwndRichEdit, WM_KEYDOWN, VK_RETURN, 0);
- SendMessageA(hwndRichEdit, EM_GETTEXTEX, (WPARAM)&getText, (LPARAM)buf);
Testing the return value would be good.
- format_test_result(resultbuf, buf);
- format_test_result(expectedbuf, "T\r");
- result = strcmp(resultbuf, expectedbuf);
- ok (result == 0 || broken(buf[0]==0x00 /* WinNT4 */),
You can drop the broken nt4 tests.
- result = SendMessageA(hwndRichEdit, EM_GETTEXTEX, (WPARAM)&getText, (LPARAM)buf);
Would be good to test result here too.
- format_test_result(resultbuf, buf);
- format_test_result(expectedbuf, "T");
- result = strcmp(resultbuf, expectedbuf);
- ok (result == 0 || broken(buf[0]==0x00 /* WinNT4 */),
"[%d] EM_GETTEXTEX, GT_DEFAULT unexpected '%s', expected '%s'\n",i, resultbuf, expectedbuf);- DestroyWindow(hwndRichEdit);
}
Huw.
On Sun, Dec 09, 2018 at 11:51:55PM +0100, Fabian Maurer wrote:
This is basically a no-op to make the following fix simpler
Signed-off-by: Fabian Maurer dark.shadow4@web.de
dlls/riched20/editor.c | 322 +++++++++++++++++++++-------------------- 1 file changed, 168 insertions(+), 154 deletions(-)
diff --git a/dlls/riched20/editor.c b/dlls/riched20/editor.c index 99c87bf61d..9142fd917d 100644 --- a/dlls/riched20/editor.c +++ b/dlls/riched20/editor.c @@ -2427,6 +2427,171 @@ static void ME_UpdateSelectionLinkAttribute(ME_TextEditor *editor) ME_UpdateLinkAttribute(editor, &start, nChars); }
+static INT handle_enter(ME_TextEditor *editor)
This can return BOOL.
+{
- BOOL ctrl_is_down = GetKeyState(VK_CONTROL) & 0x8000;
- BOOL shift_is_down = GetKeyState(VK_SHIFT) & 0x8000;
- if (editor->bDialogMode)
- {
if (ctrl_is_down)return TRUE;if (!(editor->styleFlags & ES_WANTRETURN)){if (editor->hwndParent){DWORD dw;dw = SendMessageW(editor->hwndParent, DM_GETDEFID, 0, 0);if (HIWORD(dw) == DC_HASDEFID){HWND hwDefCtrl = GetDlgItem(editor->hwndParent, LOWORD(dw));if (hwDefCtrl){SendMessageW(editor->hwndParent, WM_NEXTDLGCTL, (WPARAM)hwDefCtrl, TRUE);PostMessageW(hwDefCtrl, WM_KEYDOWN, VK_RETURN, 0);}}}return TRUE;}- }
- if (editor->styleFlags & ES_MULTILINE)
- {
static const WCHAR endl = '\r';static const WCHAR endlv10[] = {'\r','\n'};ME_Cursor cursor = editor->pCursors[0];ME_DisplayItem *para = cursor.pPara;int from, to;ME_Style *style, *eop_style;if (editor->styleFlags & ES_READONLY){MessageBeep(MB_ICONERROR);return TRUE;}ME_GetSelectionOfs(editor, &from, &to);if (editor->nTextLimit > ME_GetTextLength(editor) - (to-from)){if (!editor->bEmulateVersion10) { /* v4.1 */if (para->member.para.nFlags & MEPF_ROWEND) {
Let's move opening braces to a new line.
/* Add a new table row after this row. */para = ME_AppendTableRow(editor, para);para = para->member.para.next_para;editor->pCursors[0].pPara = para;editor->pCursors[0].pRun = ME_FindItemFwd(para, diRun);editor->pCursors[0].nOffset = 0;editor->pCursors[1] = editor->pCursors[0];ME_CommitUndo(editor);ME_CheckTablesForCorruption(editor);ME_UpdateRepaint(editor, FALSE);return TRUE;}else if (para == editor->pCursors[1].pPara &&cursor.nOffset + cursor.pRun->member.run.nCharOfs == 0 &¶->member.para.prev_para->member.para.nFlags & MEPF_ROWSTART &&!para->member.para.prev_para->member.para.nCharOfs){/* Insert a newline before the table. */para = para->member.para.prev_para;para->member.para.nFlags &= ~MEPF_ROWSTART;editor->pCursors[0].pPara = para;editor->pCursors[0].pRun = ME_FindItemFwd(para, diRun);editor->pCursors[1] = editor->pCursors[0];ME_InsertTextFromCursor(editor, 0, &endl, 1,editor->pCursors[0].pRun->member.run.style);para = editor->pBuffer->pFirst->member.para.next_para;ME_SetDefaultParaFormat(editor, ¶->member.para.fmt);para->member.para.nFlags = 0;mark_para_rewrap(editor, para);editor->pCursors[0].pPara = para;editor->pCursors[0].pRun = ME_FindItemFwd(para, diRun);editor->pCursors[1] = editor->pCursors[0];para->member.para.next_para->member.para.nFlags |= MEPF_ROWSTART;ME_CommitCoalescingUndo(editor);ME_CheckTablesForCorruption(editor);ME_UpdateRepaint(editor, FALSE);return TRUE;}} else { /* v1.0 - 3.0 */
And likewise } else { become three lines.
ME_DisplayItem *para = cursor.pPara;if (ME_IsInTable(para)){if (cursor.pRun->member.run.nFlags & MERF_ENDPARA){if (from == to) {ME_ContinueCoalescingTransaction(editor);para = ME_AppendTableRow(editor, para);editor->pCursors[0].pPara = para;editor->pCursors[0].pRun = ME_FindItemFwd(para, diRun);editor->pCursors[0].nOffset = 0;editor->pCursors[1] = editor->pCursors[0];ME_CommitCoalescingUndo(editor);ME_UpdateRepaint(editor, FALSE);return TRUE;}} else {ME_ContinueCoalescingTransaction(editor);if (cursor.pRun->member.run.nCharOfs + cursor.nOffset == 0 &&!ME_IsInTable(para->member.para.prev_para)){/* Insert newline before table */cursor.pRun = ME_FindItemBack(para, diRun);if (cursor.pRun) {editor->pCursors[0].pRun = cursor.pRun;editor->pCursors[0].pPara = para->member.para.prev_para;}editor->pCursors[0].nOffset = 0;editor->pCursors[1] = editor->pCursors[0];ME_InsertTextFromCursor(editor, 0, &endl, 1,editor->pCursors[0].pRun->member.run.style);} else {editor->pCursors[1] = editor->pCursors[0];para = ME_AppendTableRow(editor, para);editor->pCursors[0].pPara = para;editor->pCursors[0].pRun = ME_FindItemFwd(para, diRun);editor->pCursors[0].nOffset = 0;editor->pCursors[1] = editor->pCursors[0];}ME_CommitCoalescingUndo(editor);ME_UpdateRepaint(editor, FALSE);return TRUE;}}}style = ME_GetInsertStyle(editor, 0);/* Normally the new eop style is the insert style, however in a list it is copied from the existingeop style (this prevents the list label style changing when the new eop is inserted).No extra ref is taken here on eop_style. */if (para->member.para.fmt.wNumbering)eop_style = para->member.para.eop_run->style;elseeop_style = style;ME_ContinueCoalescingTransaction(editor);if (shift_is_down)ME_InsertEndRowFromCursor(editor, 0);elseif (!editor->bEmulateVersion10)ME_InsertTextFromCursor(editor, 0, &endl, 1, eop_style);elseME_InsertTextFromCursor(editor, 0, endlv10, 2, eop_style);ME_CommitCoalescingUndo(editor);SetCursor(NULL);ME_UpdateSelectionLinkAttribute(editor);ME_UpdateRepaint(editor, FALSE);ME_SaveTempStyle(editor, style); /* set the temp insert style for the new para */ME_ReleaseStyle(style);}return TRUE;- }
- return -1;
So return FALSE here.
+}
static BOOL ME_KeyDown(ME_TextEditor *editor, WORD nKey) { @@ -2493,161 +2658,10 @@ ME_KeyDown(ME_TextEditor *editor, WORD nKey) ME_SendRequestResize(editor, FALSE); return TRUE; case VK_RETURN:
if (editor->bDialogMode) {if (ctrl_is_down)
...
return TRUE;
INT result = handle_enter(editor);if (result != -1)return result;
Just return the result of handle_enter here, breaking out just ends up returning FALSE anyway.
Hello Huw,
thanks for the quick feedback! I submitted a new patchseries.
Regards, Fabian Maurer