diff --git a/dlls/riched20/editor.c b/dlls/riched20/editor.c index 53d54a3b8e2..f96f52ef56d 100644 --- a/dlls/riched20/editor.c +++ b/dlls/riched20/editor.c @@ -4014,15 +4014,14 @@ LRESULT ME_HandleMessage(ME_TextEditor *editor, UINT msg, WPARAM wParam, int nEnd = rng->chrg.cpMax; int textlength = ME_GetTextLength(editor); - TRACE("EM_GETTEXTRANGE min=%d max=%d unicode=%d textlength=%d\n", - rng->chrg.cpMin, rng->chrg.cpMax, unicode, textlength); + TRACE( "EM_GETTEXTRANGE min = %d max = %d textlength = %d\n", rng->chrg.cpMin, rng->chrg.cpMax, textlength ); if (nStart < 0) return 0; if ((nStart == 0 && nEnd == -1) || nEnd > textlength) nEnd = textlength; if (nStart >= nEnd) return 0; cursor_from_char_ofs( editor, nStart, &start ); - return ME_GetTextRange(editor, rng->lpstrText, &start, nEnd - nStart, unicode); + return ME_GetTextRange( editor, rng->lpstrText, &start, nEnd - nStart, TRUE ); } case EM_GETLINE: { diff --git a/dlls/riched20/tests/editor.c b/dlls/riched20/tests/editor.c index 4c87869c4a3..170c29f186e 100644 --- a/dlls/riched20/tests/editor.c +++ b/dlls/riched20/tests/editor.c @@ -1790,8 +1790,8 @@ static void test_EM_GETTEXTRANGE(void) textRange.chrg.cpMin = 4; textRange.chrg.cpMax = 8; result = SendMessageA(hwndRichEdit, EM_GETTEXTRANGE, 0, (LPARAM)&textRange); - todo_wine ok(result == 5, "EM_GETTEXTRANGE returned %ld\n", result); - todo_wine ok(!strcmp("ef\x8e\xf0g", buffer), "EM_GETTEXTRANGE filled %s\n", buffer); + ok(result == 5, "EM_GETTEXTRANGE returned %ld\n", result); + ok(!strcmp("ef\x8e\xf0g", buffer), "EM_GETTEXTRANGE filled %s\n", buffer); } DestroyWindow(hwndRichEdit); diff --git a/dlls/riched20/txthost.c b/dlls/riched20/txthost.c index ca911453010..3c968ddfecc 100644 --- a/dlls/riched20/txthost.c +++ b/dlls/riched20/txthost.c @@ -753,6 +753,39 @@ static BOOL create_windowed_editor( HWND hwnd, CREATESTRUCTW *create, BOOL emula return TRUE; } +static HRESULT get_text_rangeA( struct host *host, TEXTRANGEA *rangeA, LRESULT *res ) +{ + TEXTRANGEW range; + HRESULT hr; + unsigned int count; + LRESULT len; + + *res = 0; + if (rangeA->chrg.cpMin < 0) return S_OK; + ITextServices_TxSendMessage( host->text_srv, WM_GETTEXTLENGTH, 0, 0, &len ); + range.chrg = rangeA->chrg; + if ((range.chrg.cpMin == 0 && range.chrg.cpMax == -1) || range.chrg.cpMax > len) + range.chrg.cpMax = len; + if (range.chrg.cpMin >= range.chrg.cpMax) return S_OK; + count = range.chrg.cpMax - range.chrg.cpMin + 1; + range.lpstrText = heap_alloc( count * sizeof(WCHAR) ); + if (!range.lpstrText) return E_OUTOFMEMORY; + hr = ITextServices_TxSendMessage( host->text_srv, EM_GETTEXTRANGE, 0, (LPARAM)&range, &len ); + if (hr == S_OK && len) + { + if (!host->emulate_10) count = INT_MAX; + len = WideCharToMultiByte( CP_ACP, 0, range.lpstrText, -1, rangeA->lpstrText, count, NULL, NULL ); + if (!host->emulate_10) *res = len - 1; + else + { + *res = count - 1; + rangeA->lpstrText[*res] = '\0'; + } + } + heap_free( range.lpstrText ); + return hr; +} + static LRESULT RichEditWndProc_common( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam, BOOL unicode ) { @@ -822,6 +855,11 @@ static LRESULT RichEditWndProc_common( HWND hwnd, UINT msg, WPARAM wparam, hr = ITextServices_TxSendMessage( host->text_srv, EM_GETTEXTLENGTHEX, (WPARAM)¶ms, 0, &res ); break; } + case EM_GETTEXTRANGE: + if (unicode) hr = ITextServices_TxSendMessage( host->text_srv, msg, wparam, lparam, &res ); + else hr = get_text_rangeA( host, (TEXTRANGEA *)lparam, &res ); + break; + case WM_PAINT: { HDC hdc; diff --git a/dlls/riched32/tests/editor.c b/dlls/riched32/tests/editor.c index f4f6ebeb709..0f5ca9f738b 100644 --- a/dlls/riched32/tests/editor.c +++ b/dlls/riched32/tests/editor.c @@ -584,7 +584,7 @@ static void test_EM_GETTEXTRANGE(void) textRange.chrg.cpMax = 8; result = SendMessageA(hwndRichEdit, EM_GETTEXTRANGE, 0, (LPARAM)&textRange); ok(result == 4, "EM_GETTEXTRANGE returned %ld\n", result); - todo_wine ok(!strcmp("ef\x8e\xf0", buffer), "EM_GETTEXTRANGE filled %s\n", buffer); + ok(!strcmp("ef\x8e\xf0", buffer), "EM_GETTEXTRANGE filled %s\n", buffer); } DestroyWindow(hwndRichEdit);