Commit 6650abcd authored by Krzysztof Foltman's avatar Krzysztof Foltman Committed by Alexandre Julliard

- Bugfix in EM_GETTEXTEX

- Additional traces helpful in diagnosing similar (text retrieval-related) bugs.
parent 658a5420
...@@ -1565,16 +1565,19 @@ LRESULT WINAPI RichEditANSIWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lP ...@@ -1565,16 +1565,19 @@ LRESULT WINAPI RichEditANSIWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lP
} }
else else
{ {
LPWSTR buffer = HeapAlloc(GetProcessHeap(), 0, (nCount + 1) * sizeof(WCHAR)); /* potentially each char may be a CR, why calculate the exact value with O(N) when
DWORD buflen = ex->cb; we can just take a bigger buffer? :) */
LRESULT rc; int crlfmul = (ex->flags & GT_USECRLF) ? 2 : 1;
DWORD flags = 0; LPWSTR buffer = HeapAlloc(GetProcessHeap(), 0, (crlfmul*nCount + 1) * sizeof(WCHAR));
DWORD buflen = ex->cb;
buflen = ME_GetTextW(editor, buffer, nStart, nCount, ex->flags & GT_USECRLF); LRESULT rc;
rc = WideCharToMultiByte(ex->codepage, flags, buffer, buflen, (LPSTR)lParam, ex->cb, ex->lpDefaultChar, ex->lpUsedDefaultChar); DWORD flags = 0;
HeapFree(GetProcessHeap(),0,buffer); buflen = ME_GetTextW(editor, buffer, nStart, nCount, ex->flags & GT_USECRLF);
return rc; rc = WideCharToMultiByte(ex->codepage, flags, buffer, buflen, (LPSTR)lParam, ex->cb, ex->lpDefaultChar, ex->lpUsedDefaultChar);
HeapFree(GetProcessHeap(),0,buffer);
return rc;
} }
} }
case EM_GETSELTEXT: case EM_GETSELTEXT:
...@@ -1590,6 +1593,9 @@ LRESULT WINAPI RichEditANSIWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lP ...@@ -1590,6 +1593,9 @@ LRESULT WINAPI RichEditANSIWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lP
case EM_GETTEXTRANGE: case EM_GETTEXTRANGE:
{ {
TEXTRANGEW *rng = (TEXTRANGEW *)lParam; TEXTRANGEW *rng = (TEXTRANGEW *)lParam;
TRACE("EM_GETTEXTRANGE min=%ld max=%ld unicode=%d emul1.0=%d length=%d\n",
rng->chrg.cpMin, rng->chrg.cpMax, IsWindowUnicode(hWnd),
editor->bEmulateVersion10, ME_GetTextLength(editor));
if (IsWindowUnicode(hWnd)) if (IsWindowUnicode(hWnd))
return ME_GetTextW(editor, rng->lpstrText, rng->chrg.cpMin, rng->chrg.cpMax-rng->chrg.cpMin, editor->bEmulateVersion10); return ME_GetTextW(editor, rng->lpstrText, rng->chrg.cpMin, rng->chrg.cpMax-rng->chrg.cpMin, editor->bEmulateVersion10);
else else
...@@ -2037,12 +2043,12 @@ int ME_GetTextW(ME_TextEditor *editor, WCHAR *buffer, int nStart, int nChars, in ...@@ -2037,12 +2043,12 @@ int ME_GetTextW(ME_TextEditor *editor, WCHAR *buffer, int nStart, int nChars, in
{ {
ME_DisplayItem *item = ME_FindItemAtOffset(editor, diRun, nStart, &nStart); ME_DisplayItem *item = ME_FindItemAtOffset(editor, diRun, nStart, &nStart);
int nWritten = 0; int nWritten = 0;
WCHAR *pStart = buffer;
if (!item) { if (!item) {
*buffer = L'\0'; *buffer = L'\0';
return 0; return 0;
} }
assert(item);
if (nStart) if (nStart)
{ {
...@@ -2086,12 +2092,14 @@ int ME_GetTextW(ME_TextEditor *editor, WCHAR *buffer, int nStart, int nChars, in ...@@ -2086,12 +2092,14 @@ int ME_GetTextW(ME_TextEditor *editor, WCHAR *buffer, int nStart, int nChars, in
if (!nChars) if (!nChars)
{ {
TRACE("nWritten=%d, actual=%d\n", nWritten, buffer-pStart);
*buffer = L'\0'; *buffer = L'\0';
return nWritten; return nWritten;
} }
item = ME_FindItemFwd(item, diRun); item = ME_FindItemFwd(item, diRun);
} }
*buffer = L'\0'; *buffer = L'\0';
TRACE("nWritten=%d, actual=%d\n", nWritten, buffer-pStart);
return nWritten; return nWritten;
} }
......
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