From 1d1cd63088503c171b4979d624ea03a3120a00e7 Mon Sep 17 00:00:00 2001 From: Jactry Zeng Date: Sat, 7 Sep 2013 16:29:46 +0800 Subject: [PATCH 1/6] riched20: Implement ITextDocument_fnOpen. --- dlls/riched20/richole.c | 47 +++++++++++++++++++++++++++++++++++++++-- dlls/riched20/tests/richole.c | 8 +++---- 2 files changed, 49 insertions(+), 6 deletions(-) diff --git a/dlls/riched20/richole.c b/dlls/riched20/richole.c index 6805873..e7da55f 100644 --- a/dlls/riched20/richole.c +++ b/dlls/riched20/richole.c @@ -582,8 +582,51 @@ ITextDocument_fnOpen(ITextDocument* me, VARIANT* pVar, LONG Flags, LONG CodePage) { IRichEditOleImpl *This = impl_from_ITextDocument(me); - FIXME("stub %p\n",This); - return E_NOTIMPL; + + HANDLE hFile; + DWORD dwReadSize, size; + SETTEXTEX settextex; + LPSTR chBuffer; + + TRACE("(%p %p 0x%x %d)\n", me, pVar, Flags, CodePage); + + if(V_VT(pVar) != VT_BSTR) return E_INVALIDARG; + + hFile = CreateFileW(V_BSTR(pVar), GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ| + FILE_SHARE_WRITE|FILE_SHARE_DELETE, + NULL, OPEN_EXISTING, 0, NULL); + + if(hFile == INVALID_HANDLE_VALUE) + return HRESULT_FROM_WIN32(GetLastError()); + + settextex.codepage = CodePage; + settextex.flags = ST_DEFAULT; + + size = GetFileSize(hFile, NULL); + if(size == INVALID_FILE_SIZE) + { + CloseHandle(hFile); + return HRESULT_FROM_WIN32(GetLastError()); + } + + chBuffer = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size+2); + if(!chBuffer) + { + CloseHandle(hFile); + return HRESULT_FROM_WIN32(GetLastError()); + } + + if(!ReadFile(hFile, chBuffer, size, &dwReadSize, NULL)) + { + CloseHandle(hFile); + HeapFree(GetProcessHeap(), 0, chBuffer); + return HRESULT_FROM_WIN32(GetLastError()); + } + + SendMessageW(This->editor->hWnd, EM_SETTEXTEX, (int)&settextex, (LPARAM)chBuffer); + CloseHandle(hFile); + + return S_OK; } static HRESULT WINAPI diff --git a/dlls/riched20/tests/richole.c b/dlls/riched20/tests/richole.c index 1bd0be9..6f2ed17 100644 --- a/dlls/riched20/tests/richole.c +++ b/dlls/riched20/tests/richole.c @@ -190,7 +190,7 @@ static void test_ITextDocument_Open(void) touch_file(filename); create_interfaces(&w, &reOle, &txtDoc, &txtSel); hres = ITextDocument_Open(txtDoc, &testfile, tomConstantsSingle[i], CP_ACP); - todo_wine ok(hres == S_OK, "ITextDocument_Open: Filename:test.txt Flags:0x%x Codepage:CP_ACP hres:0x%x\n", + ok(hres == S_OK, "ITextDocument_Open: Filename:test.txt Flags:0x%x Codepage:CP_ACP hres:0x%x\n", tomConstantsSingle[i], hres); release_interfaces(&w, &reOle, &txtDoc, &txtSel); DeleteFileW(filename); @@ -198,7 +198,7 @@ static void test_ITextDocument_Open(void) touch_file(filename); create_interfaces(&w, &reOle, &txtDoc, &txtSel); hres = ITextDocument_Open(txtDoc, &testfile, tomConstantsSingle[i], CP_UTF8); - todo_wine ok(hres == S_OK, "ITextDocument_Open: Filename:test.txt Flags:0x%x Codepage:CP_UTF8 hres:0x%x\n", + ok(hres == S_OK, "ITextDocument_Open: Filename:test.txt Flags:0x%x Codepage:CP_UTF8 hres:0x%x\n", tomConstantsSingle[i], hres); release_interfaces(&w, &reOle, &txtDoc, &txtSel); DeleteFileW(filename); @@ -209,7 +209,7 @@ static void test_ITextDocument_Open(void) touch_file(filename); create_interfaces(&w, &reOle, &txtDoc, &txtSel); hres = ITextDocument_Open(txtDoc, &testfile, tomConstantsMulti[i], CP_ACP); - todo_wine ok(hres == S_OK, "ITextDocument_Open: Filename:test.txt Flags:0x%x Codepage:CP_ACP hres:0x%x\n", + ok(hres == S_OK, "ITextDocument_Open: Filename:test.txt Flags:0x%x Codepage:CP_ACP hres:0x%x\n", tomConstantsMulti[i], hres); release_interfaces(&w, &reOle, &txtDoc, &txtSel); DeleteFileW(filename); @@ -217,7 +217,7 @@ static void test_ITextDocument_Open(void) touch_file(filename); create_interfaces(&w, &reOle, &txtDoc, &txtSel); hres = ITextDocument_Open(txtDoc, &testfile, tomConstantsMulti[i], CP_UTF8); - todo_wine ok(hres == S_OK, "ITextDocument_Open: Filename:test.txt Flags:0x%x Codepage:CP_UTF8 hres:0x%x\n", + ok(hres == S_OK, "ITextDocument_Open: Filename:test.txt Flags:0x%x Codepage:CP_UTF8 hres:0x%x\n", tomConstantsMulti[i], hres); release_interfaces(&w, &reOle, &txtDoc, &txtSel); DeleteFileW(filename); -- 1.7.10.4