From 0a07e329c816b9be02666f2a775e1eec748a7624 Mon Sep 17 00:00:00 2001 From: Jactry Zeng Date: Sun, 8 Sep 2013 12:45:22 +0800 Subject: [PATCH 4/6] riched20: Add RTF support for ITextDocument_fnOpen. --- dlls/riched20/richole.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/dlls/riched20/richole.c b/dlls/riched20/richole.c index c75aefb..3da8653 100644 --- a/dlls/riched20/richole.c +++ b/dlls/riched20/richole.c @@ -613,6 +613,17 @@ static DWORD get_open_access_mode(LONG Flags) } } +static DWORD CALLBACK stream_in(DWORD_PTR hFile, LPBYTE buffer, LONG cb, LONG *pcb) +{ + DWORD read; + + if(!ReadFile((HANDLE)hFile, buffer, cb, &read, 0)) + return 1; + + *pcb = read; + return 0; +} + static HRESULT WINAPI ITextDocument_fnOpen(ITextDocument* me, VARIANT* pVar, LONG Flags, LONG CodePage) @@ -621,6 +632,9 @@ ITextDocument_fnOpen(ITextDocument* me, VARIANT* pVar, LONG Flags, HANDLE hFile; DWORD dwReadSize, size, creationMode, accessMode; + static const char header[] = "{\\rtf"; + char beginHex[5]; + DWORD readOut; SETTEXTEX settextex; LPSTR chBuffer; @@ -638,6 +652,26 @@ ITextDocument_fnOpen(ITextDocument* me, VARIANT* pVar, LONG Flags, if(hFile == INVALID_HANDLE_VALUE) return HRESULT_FROM_WIN32(GetLastError()); + ReadFile(hFile, beginHex, 5, &readOut, NULL); + SetFilePointer(hFile, 0, NULL, FILE_BEGIN); + + /* Open a rtf with tomText. */ + if(readOut >= 5 && !memcmp(header, beginHex, 5) && ((Flags & 0xf) == tomText)) + { + EDITSTREAM editstream; + + editstream.dwCookie = (DWORD_PTR)hFile; + editstream.pfnCallback = stream_in; + + if((Flags & 0xf000) == tomPasteFile) + SendMessageW(This->editor->hWnd, EM_STREAMIN, SF_TEXT|SFF_SELECTION, (LPARAM)&editstream); + else + SendMessageW(This->editor->hWnd, EM_STREAMIN, SF_TEXT, (LPARAM)&editstream); + + CloseHandle(hFile); + return S_OK; + } + settextex.codepage = CodePage; settextex.flags = ST_DEFAULT; -- 1.7.10.4