richedit: Handle EM_GETTEXTRANGE's unicode conversion in the host.

Signed-off-by: Huw Davies <huw@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Huw Davies 2021-03-12 09:01:36 +00:00 committed by Alexandre Julliard
parent 6a173becd4
commit 93fec636d5
4 changed files with 43 additions and 6 deletions

View File

@ -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:
{

View File

@ -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);

View File

@ -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)&params, 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;

View File

@ -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);