[PATCH 4/6] riched20: Add RTF support for ITextDocument_fnOpen.
Jactry
jactry92 at gmail.com
Thu Sep 26 08:52:27 CDT 2013
-------------- next part --------------
From 08e7f1ce06b04f86fbab9527aa51698bcb95e63d Mon Sep 17 00:00:00 2001
From: Jactry Zeng <jactry92 at gmail.com>
Date: Thu, 26 Sep 2013 21:20:29 +0800
Subject: [PATCH 4/6] riched20: Add RTF support for ITextDocument_fnOpen.
To: wine-patches <wine-patches at winehq.org>
Reply-To: wine-devel <wine-devel at winehq.org>
---
dlls/riched20/richole.c | 34 ++++++++++++++++++++++++++++++++++
1 file changed, 34 insertions(+)
diff --git a/dlls/riched20/richole.c b/dlls/riched20/richole.c
index 1250bf7..4832597 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)
@@ -623,6 +634,9 @@ ITextDocument_fnOpen(ITextDocument* me, VARIANT* pVar, LONG Flags,
DWORD dwReadSize, size, creationMode, accessMode;
SETTEXTEX settextex;
LPSTR chBuffer;
+ static const char header[] = "{\\rtf";
+ char beginHex[5];
+ DWORD readOut;
TRACE("(%p %p 0x%x %d)\n", me, pVar, Flags, CodePage);
@@ -641,6 +655,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.8.3.4 (Apple Git-47)
More information about the wine-patches
mailing list