riched20: Always treat the nCount variable in the EM_GETTEXTEX handler as a character count.
Convert ex->cb into a character count before assigning it to nCount. Remove some dubious minus ones that would result in different character counts for the Unicode and ANSI paths.
This commit is contained in:
parent
374f6ec616
commit
4bff248783
|
@ -2101,7 +2101,7 @@ static LRESULT RichEditWndProc_common(HWND hWnd, UINT msg, WPARAM wParam,
|
||||||
case EM_GETTEXTEX:
|
case EM_GETTEXTEX:
|
||||||
{
|
{
|
||||||
GETTEXTEX *ex = (GETTEXTEX*)wParam;
|
GETTEXTEX *ex = (GETTEXTEX*)wParam;
|
||||||
int nStart, nCount;
|
int nStart, nCount; /* in chars */
|
||||||
|
|
||||||
if (ex->flags & ~(GT_SELECTION | GT_USECRLF))
|
if (ex->flags & ~(GT_SELECTION | GT_USECRLF))
|
||||||
FIXME("GETTEXTEX flags 0x%08x not supported\n", ex->flags & ~(GT_SELECTION | GT_USECRLF));
|
FIXME("GETTEXTEX flags 0x%08x not supported\n", ex->flags & ~(GT_SELECTION | GT_USECRLF));
|
||||||
|
@ -2110,12 +2110,11 @@ static LRESULT RichEditWndProc_common(HWND hWnd, UINT msg, WPARAM wParam,
|
||||||
{
|
{
|
||||||
ME_GetSelection(editor, &nStart, &nCount);
|
ME_GetSelection(editor, &nStart, &nCount);
|
||||||
nCount -= nStart;
|
nCount -= nStart;
|
||||||
nCount = min(nCount, ex->cb - 1);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
nStart = 0;
|
nStart = 0;
|
||||||
nCount = ex->cb - 1;
|
nCount = 0x7fffffff;
|
||||||
}
|
}
|
||||||
if (ex->codepage == 1200)
|
if (ex->codepage == 1200)
|
||||||
{
|
{
|
||||||
|
@ -2127,11 +2126,14 @@ static LRESULT RichEditWndProc_common(HWND hWnd, UINT msg, WPARAM wParam,
|
||||||
/* potentially each char may be a CR, why calculate the exact value with O(N) when
|
/* potentially each char may be a CR, why calculate the exact value with O(N) when
|
||||||
we can just take a bigger buffer? :) */
|
we can just take a bigger buffer? :) */
|
||||||
int crlfmul = (ex->flags & GT_USECRLF) ? 2 : 1;
|
int crlfmul = (ex->flags & GT_USECRLF) ? 2 : 1;
|
||||||
LPWSTR buffer = heap_alloc((crlfmul*nCount + 1) * sizeof(WCHAR));
|
LPWSTR buffer;
|
||||||
DWORD buflen = ex->cb;
|
DWORD buflen = ex->cb;
|
||||||
LRESULT rc;
|
LRESULT rc;
|
||||||
DWORD flags = 0;
|
DWORD flags = 0;
|
||||||
|
|
||||||
|
nCount = min(nCount, ex->cb - 1);
|
||||||
|
buffer = heap_alloc((crlfmul*nCount + 1) * sizeof(WCHAR));
|
||||||
|
|
||||||
buflen = ME_GetTextW(editor, buffer, nStart, nCount, ex->flags & GT_USECRLF);
|
buflen = ME_GetTextW(editor, buffer, nStart, nCount, ex->flags & GT_USECRLF);
|
||||||
rc = WideCharToMultiByte(ex->codepage, flags, buffer, -1, (LPSTR)lParam, ex->cb, ex->lpDefaultChar, ex->lpUsedDefaultChar);
|
rc = WideCharToMultiByte(ex->codepage, flags, buffer, -1, (LPSTR)lParam, ex->cb, ex->lpDefaultChar, ex->lpUsedDefaultChar);
|
||||||
if (rc) rc--; /* do not count 0 terminator */
|
if (rc) rc--; /* do not count 0 terminator */
|
||||||
|
|
Loading…
Reference in New Issue