Commit 2a588697 authored by Huw Davies's avatar Huw Davies Committed by Alexandre Julliard

riched20: Don't resend a partial chunk to the edit stream callback.

It's basically used as a boolean to terminate the writing process if it's set to zero.
parent cb1e8566
......@@ -3404,6 +3404,24 @@ static void test_WM_SETTEXT(void)
#undef TEST_SETTEXTW
}
/* Set *pcb to one to show that the remaining cb-1 bytes are not
resent to the callkack. */
static DWORD CALLBACK test_esCallback_written_1(DWORD_PTR dwCookie,
LPBYTE pbBuff,
LONG cb,
LONG *pcb)
{
char** str = (char**)dwCookie;
ok(cb == *pcb, "cb %d, *pcb %d\n", cb, *pcb);
*pcb = 0;
if (cb > 0) {
memcpy(*str, pbBuff, cb);
*str += cb;
*pcb = 1;
}
return 0;
}
static void test_EM_STREAMOUT(void)
{
HWND hwndRichEdit = new_richedit(NULL);
......@@ -3452,6 +3470,19 @@ static void test_EM_STREAMOUT(void)
ok(strcmp(buf, TestItem3) == 0,
"streamed text different, got %s\n", buf);
/* Use a callback that sets *pcb to one */
p = buf;
es.dwCookie = (DWORD_PTR)&p;
es.dwError = 0;
es.pfnCallback = test_esCallback_written_1;
memset(buf, 0, sizeof(buf));
SendMessageA(hwndRichEdit, EM_STREAMOUT, SF_TEXT, (LPARAM)&es);
r = strlen(buf);
ok(r == 14, "streamed text length is %d, expecting 14\n", r);
ok(strcmp(buf, TestItem3) == 0,
"streamed text different, got %s\n", buf);
DestroyWindow(hwndRichEdit);
}
......
......@@ -49,29 +49,18 @@ ME_StreamOutInit(ME_TextEditor *editor, EDITSTREAM *stream)
static BOOL
ME_StreamOutFlush(ME_OutStream *pStream)
{
LONG nStart = 0;
LONG nWritten = 0;
LONG nRemaining = 0;
EDITSTREAM *stream = pStream->stream;
while (nStart < pStream->pos) {
TRACE("sending %u bytes\n", pStream->pos - nStart);
/* Some apps seem not to set *pcb unless a problem arises, relying
on initial random nWritten value, which is usually >STREAMOUT_BUFFER_SIZE */
nRemaining = pStream->pos - nStart;
nWritten = 0xDEADBEEF;
stream->dwError = stream->pfnCallback(stream->dwCookie, (LPBYTE)pStream->buffer + nStart,
pStream->pos - nStart, &nWritten);
if (pStream->pos) {
TRACE("sending %u bytes\n", pStream->pos);
nWritten = pStream->pos;
stream->dwError = stream->pfnCallback(stream->dwCookie, (LPBYTE)pStream->buffer,
pStream->pos, &nWritten);
TRACE("error=%u written=%u\n", stream->dwError, nWritten);
if (nWritten > (pStream->pos - nStart) || nWritten<0) {
FIXME("Invalid returned written size *pcb: 0x%x (%d) instead of %d\n",
(unsigned)nWritten, nWritten, nRemaining);
nWritten = nRemaining;
}
if (nWritten == 0 || stream->dwError)
return FALSE;
pStream->written += nWritten;
nStart += nWritten;
/* Don't resend partial chunks if nWritten < pStream->pos */
}
pStream->pos = 0;
return TRUE;
......
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