riched20: Make ITextDocument stub reusable for ITextServices (try 4)

Caibin Chen tigersoldi at gmail.com
Thu Aug 1 02:09:37 CDT 2013


suppress patches: 97643, 97644, 97645, 97649, 97650

This time I reuse the ITextDocument stub in richole.c, and introduce a
new struct ITextDocumentImpl so that it can be used by ITestServices.

---
 dlls/riched20/richole.c      | 255 ++++++++++++++++++++++++-------------------
 dlls/riched20/tests/txtsrv.c |  10 ++
 dlls/riched20/tomimpl.h      |  59 ++++++++++
 dlls/riched20/txtsrv.c       |   6 +
 4 files changed, 216 insertions(+), 114 deletions(-)
 create mode 100644 dlls/riched20/tomimpl.h
-------------- next part --------------
From fd01879404a854719c2025b97a599e7faf1f8a92 Mon Sep 17 00:00:00 2001
From: Caibin Chen <tigersoldi at gmail.com>
Date: Sun, 30 Jun 2013 17:14:41 -0700
Subject: riched20: Make ITextDocument stub reusable for ITextServices

---
 dlls/riched20/richole.c      | 255 ++++++++++++++++++++++++-------------------
 dlls/riched20/tests/txtsrv.c |  10 ++
 dlls/riched20/tomimpl.h      |  59 ++++++++++
 dlls/riched20/txtsrv.c       |   6 +
 4 files changed, 216 insertions(+), 114 deletions(-)
 create mode 100644 dlls/riched20/tomimpl.h

diff --git a/dlls/riched20/richole.c b/dlls/riched20/richole.c
index 6805873..f428873 100644
--- a/dlls/riched20/richole.c
+++ b/dlls/riched20/richole.c
@@ -33,6 +33,7 @@
 #include "richole.h"
 #include "editor.h"
 #include "tom.h"
+#include "tomimpl.h"
 #include "wine/debug.h"
 
 WINE_DEFAULT_DEBUG_CHANNEL(richedit);
@@ -47,16 +48,14 @@ DEFINE_GUID(IID_ITextDocument, 0x8cc497c0, 0xa1df, 0x11ce, 0x80, 0x98, 0x00, 0xa
 DEFINE_GUID(IID_ITextRange, 0x8cc497c2, 0xa1df, 0x11ce, 0x80, 0x98, 0x00, 0xaa, 0x00, 0x47, 0xbe, 0x5d);
 DEFINE_GUID(IID_ITextSelection, 0x8cc497c1, 0xa1df, 0x11ce, 0x80, 0x98, 0x00, 0xaa, 0x00, 0x47, 0xbe, 0x5d);
 
-typedef struct ITextSelectionImpl ITextSelectionImpl;
 typedef struct IOleClientSiteImpl IOleClientSiteImpl;
 
 typedef struct IRichEditOleImpl {
     IRichEditOle IRichEditOle_iface;
-    ITextDocument ITextDocument_iface;
+    ITextDocumentImpl *txtDoc;
     LONG ref;
 
     ME_TextEditor *editor;
-    ITextSelectionImpl *txtSel;
     IOleClientSiteImpl *clientSite;
 } IRichEditOleImpl;
 
@@ -64,7 +63,7 @@ struct ITextSelectionImpl {
     ITextSelection ITextSelection_iface;
     LONG ref;
 
-    IRichEditOleImpl *reOle;
+    ITextDocumentImpl *txtDoc;
 };
 
 struct IOleClientSiteImpl {
@@ -74,14 +73,17 @@ struct IOleClientSiteImpl {
     IRichEditOleImpl *reOle;
 };
 
+/* Forward declarations */
+static ITextSelectionImpl *CreateTextSelection(ITextDocumentImpl *txtDoc);
+
 static inline IRichEditOleImpl *impl_from_IRichEditOle(IRichEditOle *iface)
 {
     return CONTAINING_RECORD(iface, IRichEditOleImpl, IRichEditOle_iface);
 }
 
-static inline IRichEditOleImpl *impl_from_ITextDocument(ITextDocument *iface)
+static inline ITextDocumentImpl *impl_from_ITextDocument(ITextDocument *iface)
 {
-    return CONTAINING_RECORD(iface, IRichEditOleImpl, ITextDocument_iface);
+    return CONTAINING_RECORD(iface, ITextDocumentImpl, ITextDocument_iface);
 }
 
 static HRESULT WINAPI
@@ -96,15 +98,15 @@ IRichEditOle_fnQueryInterface(IRichEditOle *me, REFIID riid, LPVOID *ppvObj)
         IsEqualGUID(riid, &IID_IRichEditOle))
         *ppvObj = &This->IRichEditOle_iface;
     else if (IsEqualGUID(riid, &IID_ITextDocument))
-        *ppvObj = &This->ITextDocument_iface;
+        *ppvObj = &This->txtDoc->ITextDocument_iface;
     if (*ppvObj)
     {
         IRichEditOle_AddRef(me);
         return S_OK;
     }
     FIXME("%p: unhandled interface %s\n", This, debugstr_guid(riid) );
- 
-    return E_NOINTERFACE;   
+
+    return E_NOINTERFACE;
 }
 
 static ULONG WINAPI
@@ -129,8 +131,7 @@ IRichEditOle_fnRelease(IRichEditOle *me)
     if (!ref)
     {
         TRACE ("Destroying %p\n", This);
-        This->txtSel->reOle = NULL;
-        ITextSelection_Release(&This->txtSel->ITextSelection_iface);
+        ITextDocumentImpl_destroy(This->txtDoc);
         IOleClientSite_Release(&This->clientSite->IOleClientSite_iface);
         heap_free(This);
     }
@@ -447,29 +448,29 @@ static HRESULT WINAPI
 ITextDocument_fnQueryInterface(ITextDocument* me, REFIID riid,
     void** ppvObject)
 {
-    IRichEditOleImpl *This = impl_from_ITextDocument(me);
-    return IRichEditOle_QueryInterface(&This->IRichEditOle_iface, riid, ppvObject);
+    ITextDocumentImpl *This = impl_from_ITextDocument(me);
+    return IUnknown_QueryInterface(This->outer_unk, riid, ppvObject);
 }
 
 static ULONG WINAPI
 ITextDocument_fnAddRef(ITextDocument* me)
 {
-    IRichEditOleImpl *This = impl_from_ITextDocument(me);
-    return IRichEditOle_AddRef(&This->IRichEditOle_iface);
+    ITextDocumentImpl *This = impl_from_ITextDocument(me);
+    return IUnknown_AddRef(This->outer_unk);
 }
 
 static ULONG WINAPI
 ITextDocument_fnRelease(ITextDocument* me)
 {
-    IRichEditOleImpl *This = impl_from_ITextDocument(me);
-    return IRichEditOle_Release(&This->IRichEditOle_iface);
+    ITextDocumentImpl *This = impl_from_ITextDocument(me);
+    return IUnknown_Release(This->outer_unk);
 }
 
 static HRESULT WINAPI
 ITextDocument_fnGetTypeInfoCount(ITextDocument* me,
     UINT* pctinfo)
 {
-    IRichEditOleImpl *This = impl_from_ITextDocument(me);
+    ITextDocumentImpl *This = impl_from_ITextDocument(me);
     FIXME("stub %p\n",This);
     return E_NOTIMPL;
 }
@@ -478,7 +479,7 @@ static HRESULT WINAPI
 ITextDocument_fnGetTypeInfo(ITextDocument* me, UINT iTInfo, LCID lcid,
     ITypeInfo** ppTInfo)
 {
-    IRichEditOleImpl *This = impl_from_ITextDocument(me);
+    ITextDocumentImpl *This = impl_from_ITextDocument(me);
     FIXME("stub %p\n",This);
     return E_NOTIMPL;
 }
@@ -487,7 +488,7 @@ static HRESULT WINAPI
 ITextDocument_fnGetIDsOfNames(ITextDocument* me, REFIID riid,
     LPOLESTR* rgszNames, UINT cNames, LCID lcid, DISPID* rgDispId)
 {
-    IRichEditOleImpl *This = impl_from_ITextDocument(me);
+    ITextDocumentImpl *This = impl_from_ITextDocument(me);
     FIXME("stub %p\n",This);
     return E_NOTIMPL;
 }
@@ -497,7 +498,7 @@ ITextDocument_fnInvoke(ITextDocument* me, DISPID dispIdMember,
     REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS* pDispParams,
     VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr)
 {
-    IRichEditOleImpl *This = impl_from_ITextDocument(me);
+    ITextDocumentImpl *This = impl_from_ITextDocument(me);
     FIXME("stub %p\n",This);
     return E_NOTIMPL;
 }
@@ -505,7 +506,7 @@ ITextDocument_fnInvoke(ITextDocument* me, DISPID dispIdMember,
 static HRESULT WINAPI
 ITextDocument_fnGetName(ITextDocument* me, BSTR* pName)
 {
-    IRichEditOleImpl *This = impl_from_ITextDocument(me);
+    ITextDocumentImpl *This = impl_from_ITextDocument(me);
     FIXME("stub %p\n",This);
     return E_NOTIMPL;
 }
@@ -513,7 +514,7 @@ ITextDocument_fnGetName(ITextDocument* me, BSTR* pName)
 static HRESULT WINAPI
 ITextDocument_fnGetSelection(ITextDocument* me, ITextSelection** ppSel)
 {
-    IRichEditOleImpl *This = impl_from_ITextDocument(me);
+    ITextDocumentImpl *This = impl_from_ITextDocument(me);
     TRACE("(%p)\n", me);
     *ppSel = &This->txtSel->ITextSelection_iface;
     ITextSelection_AddRef(*ppSel);
@@ -523,7 +524,7 @@ ITextDocument_fnGetSelection(ITextDocument* me, ITextSelection** ppSel)
 static HRESULT WINAPI
 ITextDocument_fnGetStoryCount(ITextDocument* me, LONG* pCount)
 {
-    IRichEditOleImpl *This = impl_from_ITextDocument(me);
+    ITextDocumentImpl *This = impl_from_ITextDocument(me);
     FIXME("stub %p\n",This);
     return E_NOTIMPL;
 }
@@ -532,7 +533,7 @@ static HRESULT WINAPI
 ITextDocument_fnGetStoryRanges(ITextDocument* me,
     ITextStoryRanges** ppStories)
 {
-    IRichEditOleImpl *This = impl_from_ITextDocument(me);
+    ITextDocumentImpl *This = impl_from_ITextDocument(me);
     FIXME("stub %p\n",This);
     return E_NOTIMPL;
 }
@@ -540,7 +541,7 @@ ITextDocument_fnGetStoryRanges(ITextDocument* me,
 static HRESULT WINAPI
 ITextDocument_fnGetSaved(ITextDocument* me, LONG* pValue)
 {
-    IRichEditOleImpl *This = impl_from_ITextDocument(me);
+    ITextDocumentImpl *This = impl_from_ITextDocument(me);
     FIXME("stub %p\n",This);
     return E_NOTIMPL;
 }
@@ -548,7 +549,7 @@ ITextDocument_fnGetSaved(ITextDocument* me, LONG* pValue)
 static HRESULT WINAPI
 ITextDocument_fnSetSaved(ITextDocument* me, LONG Value)
 {
-    IRichEditOleImpl *This = impl_from_ITextDocument(me);
+    ITextDocumentImpl *This = impl_from_ITextDocument(me);
     FIXME("stub %p\n",This);
     return E_NOTIMPL;
 }
@@ -556,7 +557,7 @@ ITextDocument_fnSetSaved(ITextDocument* me, LONG Value)
 static HRESULT WINAPI
 ITextDocument_fnGetDefaultTabStop(ITextDocument* me, float* pValue)
 {
-    IRichEditOleImpl *This = impl_from_ITextDocument(me);
+    ITextDocumentImpl *This = impl_from_ITextDocument(me);
     FIXME("stub %p\n",This);
     return E_NOTIMPL;
 }
@@ -564,7 +565,7 @@ ITextDocument_fnGetDefaultTabStop(ITextDocument* me, float* pValue)
 static HRESULT WINAPI
 ITextDocument_fnSetDefaultTabStop(ITextDocument* me, float Value)
 {
-    IRichEditOleImpl *This = impl_from_ITextDocument(me);
+    ITextDocumentImpl *This = impl_from_ITextDocument(me);
     FIXME("stub %p\n",This);
     return E_NOTIMPL;
 }
@@ -572,7 +573,7 @@ ITextDocument_fnSetDefaultTabStop(ITextDocument* me, float Value)
 static HRESULT WINAPI
 ITextDocument_fnNew(ITextDocument* me)
 {
-    IRichEditOleImpl *This = impl_from_ITextDocument(me);
+    ITextDocumentImpl *This = impl_from_ITextDocument(me);
     FIXME("stub %p\n",This);
     return E_NOTIMPL;
 }
@@ -581,7 +582,7 @@ static HRESULT WINAPI
 ITextDocument_fnOpen(ITextDocument* me, VARIANT* pVar, LONG Flags,
     LONG CodePage)
 {
-    IRichEditOleImpl *This = impl_from_ITextDocument(me);
+    ITextDocumentImpl *This = impl_from_ITextDocument(me);
     FIXME("stub %p\n",This);
     return E_NOTIMPL;
 }
@@ -590,7 +591,7 @@ static HRESULT WINAPI
 ITextDocument_fnSave(ITextDocument* me, VARIANT* pVar, LONG Flags,
     LONG CodePage)
 {
-    IRichEditOleImpl *This = impl_from_ITextDocument(me);
+    ITextDocumentImpl *This = impl_from_ITextDocument(me);
     FIXME("stub %p\n",This);
     return E_NOTIMPL;
 }
@@ -598,7 +599,7 @@ ITextDocument_fnSave(ITextDocument* me, VARIANT* pVar, LONG Flags,
 static HRESULT WINAPI
 ITextDocument_fnFreeze(ITextDocument* me, LONG* pCount)
 {
-    IRichEditOleImpl *This = impl_from_ITextDocument(me);
+    ITextDocumentImpl *This = impl_from_ITextDocument(me);
     FIXME("stub %p\n",This);
     return E_NOTIMPL;
 }
@@ -606,7 +607,7 @@ ITextDocument_fnFreeze(ITextDocument* me, LONG* pCount)
 static HRESULT WINAPI
 ITextDocument_fnUnfreeze(ITextDocument* me, LONG* pCount)
 {
-    IRichEditOleImpl *This = impl_from_ITextDocument(me);
+    ITextDocumentImpl *This = impl_from_ITextDocument(me);
     FIXME("stub %p\n",This);
     return E_NOTIMPL;
 }
@@ -614,7 +615,7 @@ ITextDocument_fnUnfreeze(ITextDocument* me, LONG* pCount)
 static HRESULT WINAPI
 ITextDocument_fnBeginEditCollection(ITextDocument* me)
 {
-    IRichEditOleImpl *This = impl_from_ITextDocument(me);
+    ITextDocumentImpl *This = impl_from_ITextDocument(me);
     FIXME("stub %p\n",This);
     return E_NOTIMPL;
 }
@@ -622,7 +623,7 @@ ITextDocument_fnBeginEditCollection(ITextDocument* me)
 static HRESULT WINAPI
 ITextDocument_fnEndEditCollection(ITextDocument* me)
 {
-    IRichEditOleImpl *This = impl_from_ITextDocument(me);
+    ITextDocumentImpl *This = impl_from_ITextDocument(me);
     FIXME("stub %p\n",This);
     return E_NOTIMPL;
 }
@@ -630,7 +631,7 @@ ITextDocument_fnEndEditCollection(ITextDocument* me)
 static HRESULT WINAPI
 ITextDocument_fnUndo(ITextDocument* me, LONG Count, LONG* prop)
 {
-    IRichEditOleImpl *This = impl_from_ITextDocument(me);
+    ITextDocumentImpl *This = impl_from_ITextDocument(me);
     FIXME("stub %p\n",This);
     return E_NOTIMPL;
 }
@@ -638,7 +639,7 @@ ITextDocument_fnUndo(ITextDocument* me, LONG Count, LONG* prop)
 static HRESULT WINAPI
 ITextDocument_fnRedo(ITextDocument* me, LONG Count, LONG* prop)
 {
-    IRichEditOleImpl *This = impl_from_ITextDocument(me);
+    ITextDocumentImpl *This = impl_from_ITextDocument(me);
     FIXME("stub %p\n",This);
     return E_NOTIMPL;
 }
@@ -647,7 +648,7 @@ static HRESULT WINAPI
 ITextDocument_fnRange(ITextDocument* me, LONG cp1, LONG cp2,
     ITextRange** ppRange)
 {
-    IRichEditOleImpl *This = impl_from_ITextDocument(me);
+    ITextDocumentImpl *This = impl_from_ITextDocument(me);
     FIXME("stub %p\n",This);
     return E_NOTIMPL;
 }
@@ -656,7 +657,7 @@ static HRESULT WINAPI
 ITextDocument_fnRangeFromPoint(ITextDocument* me, LONG x, LONG y,
     ITextRange** ppRange)
 {
-    IRichEditOleImpl *This = impl_from_ITextDocument(me);
+    ITextDocumentImpl *This = impl_from_ITextDocument(me);
     FIXME("stub %p\n",This);
     return E_NOTIMPL;
 }
@@ -690,6 +691,34 @@ static const ITextDocumentVtbl tdvt = {
     ITextDocument_fnRangeFromPoint
 };
 
+ITextDocumentImpl *ITextDocumentImpl_create(IUnknown *outer_unk, ME_TextEditor *editor)
+{
+    ITextDocumentImpl *This = heap_alloc(sizeof *This);
+    TRACE("(%p,%p)\n", outer_unk, editor);
+    if (!This)
+        return NULL;
+
+    This->outer_unk = outer_unk;
+    This->editor = editor;
+    This->ITextDocument_iface.lpVtbl = &tdvt;
+    This->txtSel = CreateTextSelection(This);
+    if (!This->txtSel) {
+        heap_free(This);
+        This = NULL;
+    }
+    return This;
+}
+
+void ITextDocumentImpl_destroy(ITextDocumentImpl *This)
+{
+    TRACE("(%p)\n", This);
+    This->outer_unk = NULL;
+    This->editor = NULL;
+    This->txtSel->txtDoc = NULL;
+    ITextSelection_Release(&This->txtSel->ITextSelection_iface);
+    heap_free(This);
+}
+
 static inline ITextSelectionImpl *impl_from_ITextSelection(ITextSelection *iface)
 {
     return CONTAINING_RECORD(iface, ITextSelectionImpl, ITextSelection_iface);
@@ -732,7 +761,7 @@ static ULONG WINAPI ITextSelection_fnRelease(ITextSelection *me)
 static HRESULT WINAPI ITextSelection_fnGetTypeInfoCount(ITextSelection *me, UINT *pctinfo)
 {
     ITextSelectionImpl *This = impl_from_ITextSelection(me);
-    if (!This->reOle)
+    if (!This->txtDoc)
         return CO_E_RELEASED;
 
     FIXME("not implemented\n");
@@ -743,7 +772,7 @@ static HRESULT WINAPI ITextSelection_fnGetTypeInfo(ITextSelection *me, UINT iTIn
     ITypeInfo **ppTInfo)
 {
     ITextSelectionImpl *This = impl_from_ITextSelection(me);
-    if (!This->reOle)
+    if (!This->txtDoc)
         return CO_E_RELEASED;
 
     FIXME("not implemented\n");
@@ -754,7 +783,7 @@ static HRESULT WINAPI ITextSelection_fnGetIDsOfNames(ITextSelection *me, REFIID
     LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
 {
     ITextSelectionImpl *This = impl_from_ITextSelection(me);
-    if (!This->reOle)
+    if (!This->txtDoc)
         return CO_E_RELEASED;
 
     FIXME("not implemented\n");
@@ -780,7 +809,7 @@ static HRESULT WINAPI ITextSelection_fnInvoke(
 static HRESULT WINAPI ITextSelection_fnGetText(ITextSelection *me, BSTR *pbstr)
 {
     ITextSelectionImpl *This = impl_from_ITextSelection(me);
-    if (!This->reOle)
+    if (!This->txtDoc)
         return CO_E_RELEASED;
 
     FIXME("not implemented\n");
@@ -790,7 +819,7 @@ static HRESULT WINAPI ITextSelection_fnGetText(ITextSelection *me, BSTR *pbstr)
 static HRESULT WINAPI ITextSelection_fnSetText(ITextSelection *me, BSTR bstr)
 {
     ITextSelectionImpl *This = impl_from_ITextSelection(me);
-    if (!This->reOle)
+    if (!This->txtDoc)
         return CO_E_RELEASED;
 
     FIXME("not implemented\n");
@@ -800,7 +829,7 @@ static HRESULT WINAPI ITextSelection_fnSetText(ITextSelection *me, BSTR bstr)
 static HRESULT WINAPI ITextSelection_fnGetChar(ITextSelection *me, LONG *pch)
 {
     ITextSelectionImpl *This = impl_from_ITextSelection(me);
-    if (!This->reOle)
+    if (!This->txtDoc)
         return CO_E_RELEASED;
 
     FIXME("not implemented\n");
@@ -810,7 +839,7 @@ static HRESULT WINAPI ITextSelection_fnGetChar(ITextSelection *me, LONG *pch)
 static HRESULT WINAPI ITextSelection_fnSetChar(ITextSelection *me, LONG ch)
 {
     ITextSelectionImpl *This = impl_from_ITextSelection(me);
-    if (!This->reOle)
+    if (!This->txtDoc)
         return CO_E_RELEASED;
 
     FIXME("not implemented\n");
@@ -820,7 +849,7 @@ static HRESULT WINAPI ITextSelection_fnSetChar(ITextSelection *me, LONG ch)
 static HRESULT WINAPI ITextSelection_fnGetDuplicate(ITextSelection *me, ITextRange **ppRange)
 {
     ITextSelectionImpl *This = impl_from_ITextSelection(me);
-    if (!This->reOle)
+    if (!This->txtDoc)
         return CO_E_RELEASED;
 
     FIXME("not implemented\n");
@@ -830,7 +859,7 @@ static HRESULT WINAPI ITextSelection_fnGetDuplicate(ITextSelection *me, ITextRan
 static HRESULT WINAPI ITextSelection_fnGetFormattedText(ITextSelection *me, ITextRange **ppRange)
 {
     ITextSelectionImpl *This = impl_from_ITextSelection(me);
-    if (!This->reOle)
+    if (!This->txtDoc)
         return CO_E_RELEASED;
 
     FIXME("not implemented\n");
@@ -840,7 +869,7 @@ static HRESULT WINAPI ITextSelection_fnGetFormattedText(ITextSelection *me, ITex
 static HRESULT WINAPI ITextSelection_fnSetFormattedText(ITextSelection *me, ITextRange *pRange)
 {
     ITextSelectionImpl *This = impl_from_ITextSelection(me);
-    if (!This->reOle)
+    if (!This->txtDoc)
         return CO_E_RELEASED;
 
     FIXME("not implemented\n");
@@ -850,7 +879,7 @@ static HRESULT WINAPI ITextSelection_fnSetFormattedText(ITextSelection *me, ITex
 static HRESULT WINAPI ITextSelection_fnGetStart(ITextSelection *me, LONG *pcpFirst)
 {
     ITextSelectionImpl *This = impl_from_ITextSelection(me);
-    if (!This->reOle)
+    if (!This->txtDoc)
         return CO_E_RELEASED;
 
     FIXME("not implemented\n");
@@ -860,7 +889,7 @@ static HRESULT WINAPI ITextSelection_fnGetStart(ITextSelection *me, LONG *pcpFir
 static HRESULT WINAPI ITextSelection_fnSetStart(ITextSelection *me, LONG cpFirst)
 {
     ITextSelectionImpl *This = impl_from_ITextSelection(me);
-    if (!This->reOle)
+    if (!This->txtDoc)
         return CO_E_RELEASED;
 
     FIXME("not implemented\n");
@@ -870,7 +899,7 @@ static HRESULT WINAPI ITextSelection_fnSetStart(ITextSelection *me, LONG cpFirst
 static HRESULT WINAPI ITextSelection_fnGetEnd(ITextSelection *me, LONG *pcpLim)
 {
     ITextSelectionImpl *This = impl_from_ITextSelection(me);
-    if (!This->reOle)
+    if (!This->txtDoc)
         return CO_E_RELEASED;
 
     FIXME("not implemented\n");
@@ -880,7 +909,7 @@ static HRESULT WINAPI ITextSelection_fnGetEnd(ITextSelection *me, LONG *pcpLim)
 static HRESULT WINAPI ITextSelection_fnSetEnd(ITextSelection *me, LONG cpLim)
 {
     ITextSelectionImpl *This = impl_from_ITextSelection(me);
-    if (!This->reOle)
+    if (!This->txtDoc)
         return CO_E_RELEASED;
 
     FIXME("not implemented\n");
@@ -890,7 +919,7 @@ static HRESULT WINAPI ITextSelection_fnSetEnd(ITextSelection *me, LONG cpLim)
 static HRESULT WINAPI ITextSelection_fnGetFont(ITextSelection *me, ITextFont **pFont)
 {
     ITextSelectionImpl *This = impl_from_ITextSelection(me);
-    if (!This->reOle)
+    if (!This->txtDoc)
         return CO_E_RELEASED;
 
     FIXME("not implemented\n");
@@ -900,7 +929,7 @@ static HRESULT WINAPI ITextSelection_fnGetFont(ITextSelection *me, ITextFont **p
 static HRESULT WINAPI ITextSelection_fnSetFont(ITextSelection *me, ITextFont *pFont)
 {
     ITextSelectionImpl *This = impl_from_ITextSelection(me);
-    if (!This->reOle)
+    if (!This->txtDoc)
         return CO_E_RELEASED;
 
     FIXME("not implemented\n");
@@ -910,7 +939,7 @@ static HRESULT WINAPI ITextSelection_fnSetFont(ITextSelection *me, ITextFont *pF
 static HRESULT WINAPI ITextSelection_fnGetPara(ITextSelection *me, ITextPara **ppPara)
 {
     ITextSelectionImpl *This = impl_from_ITextSelection(me);
-    if (!This->reOle)
+    if (!This->txtDoc)
         return CO_E_RELEASED;
 
     FIXME("not implemented\n");
@@ -920,7 +949,7 @@ static HRESULT WINAPI ITextSelection_fnGetPara(ITextSelection *me, ITextPara **p
 static HRESULT WINAPI ITextSelection_fnSetPara(ITextSelection *me, ITextPara *pPara)
 {
     ITextSelectionImpl *This = impl_from_ITextSelection(me);
-    if (!This->reOle)
+    if (!This->txtDoc)
         return CO_E_RELEASED;
 
     FIXME("not implemented\n");
@@ -930,7 +959,7 @@ static HRESULT WINAPI ITextSelection_fnSetPara(ITextSelection *me, ITextPara *pP
 static HRESULT WINAPI ITextSelection_fnGetStoryLength(ITextSelection *me, LONG *pcch)
 {
     ITextSelectionImpl *This = impl_from_ITextSelection(me);
-    if (!This->reOle)
+    if (!This->txtDoc)
         return CO_E_RELEASED;
 
     FIXME("not implemented\n");
@@ -940,7 +969,7 @@ static HRESULT WINAPI ITextSelection_fnGetStoryLength(ITextSelection *me, LONG *
 static HRESULT WINAPI ITextSelection_fnGetStoryType(ITextSelection *me, LONG *pValue)
 {
     ITextSelectionImpl *This = impl_from_ITextSelection(me);
-    if (!This->reOle)
+    if (!This->txtDoc)
         return CO_E_RELEASED;
 
     FIXME("not implemented\n");
@@ -950,7 +979,7 @@ static HRESULT WINAPI ITextSelection_fnGetStoryType(ITextSelection *me, LONG *pV
 static HRESULT WINAPI ITextSelection_fnCollapse(ITextSelection *me, LONG bStart)
 {
     ITextSelectionImpl *This = impl_from_ITextSelection(me);
-    if (!This->reOle)
+    if (!This->txtDoc)
         return CO_E_RELEASED;
 
     FIXME("not implemented\n");
@@ -960,7 +989,7 @@ static HRESULT WINAPI ITextSelection_fnCollapse(ITextSelection *me, LONG bStart)
 static HRESULT WINAPI ITextSelection_fnExpand(ITextSelection *me, LONG Unit, LONG *pDelta)
 {
     ITextSelectionImpl *This = impl_from_ITextSelection(me);
-    if (!This->reOle)
+    if (!This->txtDoc)
         return CO_E_RELEASED;
 
     FIXME("not implemented\n");
@@ -970,7 +999,7 @@ static HRESULT WINAPI ITextSelection_fnExpand(ITextSelection *me, LONG Unit, LON
 static HRESULT WINAPI ITextSelection_fnGetIndex(ITextSelection *me, LONG Unit, LONG *pIndex)
 {
     ITextSelectionImpl *This = impl_from_ITextSelection(me);
-    if (!This->reOle)
+    if (!This->txtDoc)
         return CO_E_RELEASED;
 
     FIXME("not implemented\n");
@@ -981,7 +1010,7 @@ static HRESULT WINAPI ITextSelection_fnSetIndex(ITextSelection *me, LONG Unit, L
     LONG Extend)
 {
     ITextSelectionImpl *This = impl_from_ITextSelection(me);
-    if (!This->reOle)
+    if (!This->txtDoc)
         return CO_E_RELEASED;
 
     FIXME("not implemented\n");
@@ -991,7 +1020,7 @@ static HRESULT WINAPI ITextSelection_fnSetIndex(ITextSelection *me, LONG Unit, L
 static HRESULT WINAPI ITextSelection_fnSetRange(ITextSelection *me, LONG cpActive, LONG cpOther)
 {
     ITextSelectionImpl *This = impl_from_ITextSelection(me);
-    if (!This->reOle)
+    if (!This->txtDoc)
         return CO_E_RELEASED;
 
     FIXME("not implemented\n");
@@ -1001,7 +1030,7 @@ static HRESULT WINAPI ITextSelection_fnSetRange(ITextSelection *me, LONG cpActiv
 static HRESULT WINAPI ITextSelection_fnInRange(ITextSelection *me, ITextRange *pRange, LONG *pb)
 {
     ITextSelectionImpl *This = impl_from_ITextSelection(me);
-    if (!This->reOle)
+    if (!This->txtDoc)
         return CO_E_RELEASED;
 
     FIXME("not implemented\n");
@@ -1011,7 +1040,7 @@ static HRESULT WINAPI ITextSelection_fnInRange(ITextSelection *me, ITextRange *p
 static HRESULT WINAPI ITextSelection_fnInStory(ITextSelection *me, ITextRange *pRange, LONG *pb)
 {
     ITextSelectionImpl *This = impl_from_ITextSelection(me);
-    if (!This->reOle)
+    if (!This->txtDoc)
         return CO_E_RELEASED;
 
     FIXME("not implemented\n");
@@ -1021,7 +1050,7 @@ static HRESULT WINAPI ITextSelection_fnInStory(ITextSelection *me, ITextRange *p
 static HRESULT WINAPI ITextSelection_fnIsEqual(ITextSelection *me, ITextRange *pRange, LONG *pb)
 {
     ITextSelectionImpl *This = impl_from_ITextSelection(me);
-    if (!This->reOle)
+    if (!This->txtDoc)
         return CO_E_RELEASED;
 
     FIXME("not implemented\n");
@@ -1031,7 +1060,7 @@ static HRESULT WINAPI ITextSelection_fnIsEqual(ITextSelection *me, ITextRange *p
 static HRESULT WINAPI ITextSelection_fnSelect(ITextSelection *me)
 {
     ITextSelectionImpl *This = impl_from_ITextSelection(me);
-    if (!This->reOle)
+    if (!This->txtDoc)
         return CO_E_RELEASED;
 
     FIXME("not implemented\n");
@@ -1042,7 +1071,7 @@ static HRESULT WINAPI ITextSelection_fnStartOf(ITextSelection *me, LONG Unit, LO
     LONG *pDelta)
 {
     ITextSelectionImpl *This = impl_from_ITextSelection(me);
-    if (!This->reOle)
+    if (!This->txtDoc)
         return CO_E_RELEASED;
 
     FIXME("not implemented\n");
@@ -1053,7 +1082,7 @@ static HRESULT WINAPI ITextSelection_fnEndOf(ITextSelection *me, LONG Unit, LONG
     LONG *pDelta)
 {
     ITextSelectionImpl *This = impl_from_ITextSelection(me);
-    if (!This->reOle)
+    if (!This->txtDoc)
         return CO_E_RELEASED;
 
     FIXME("not implemented\n");
@@ -1063,7 +1092,7 @@ static HRESULT WINAPI ITextSelection_fnEndOf(ITextSelection *me, LONG Unit, LONG
 static HRESULT WINAPI ITextSelection_fnMove(ITextSelection *me, LONG Unit, LONG Count, LONG *pDelta)
 {
     ITextSelectionImpl *This = impl_from_ITextSelection(me);
-    if (!This->reOle)
+    if (!This->txtDoc)
         return CO_E_RELEASED;
 
     FIXME("not implemented\n");
@@ -1074,7 +1103,7 @@ static HRESULT WINAPI ITextSelection_fnMoveStart(ITextSelection *me, LONG Unit,
     LONG *pDelta)
 {
     ITextSelectionImpl *This = impl_from_ITextSelection(me);
-    if (!This->reOle)
+    if (!This->txtDoc)
         return CO_E_RELEASED;
 
     FIXME("not implemented\n");
@@ -1085,7 +1114,7 @@ static HRESULT WINAPI ITextSelection_fnMoveEnd(ITextSelection *me, LONG Unit, LO
     LONG *pDelta)
 {
     ITextSelectionImpl *This = impl_from_ITextSelection(me);
-    if (!This->reOle)
+    if (!This->txtDoc)
         return CO_E_RELEASED;
 
     FIXME("not implemented\n");
@@ -1096,7 +1125,7 @@ static HRESULT WINAPI ITextSelection_fnMoveWhile(ITextSelection *me, VARIANT *Cs
     LONG *pDelta)
 {
     ITextSelectionImpl *This = impl_from_ITextSelection(me);
-    if (!This->reOle)
+    if (!This->txtDoc)
         return CO_E_RELEASED;
 
     FIXME("not implemented\n");
@@ -1107,7 +1136,7 @@ static HRESULT WINAPI ITextSelection_fnMoveStartWhile(ITextSelection *me, VARIAN
     LONG *pDelta)
 {
     ITextSelectionImpl *This = impl_from_ITextSelection(me);
-    if (!This->reOle)
+    if (!This->txtDoc)
         return CO_E_RELEASED;
 
     FIXME("not implemented\n");
@@ -1118,7 +1147,7 @@ static HRESULT WINAPI ITextSelection_fnMoveEndWhile(ITextSelection *me, VARIANT
     LONG *pDelta)
 {
     ITextSelectionImpl *This = impl_from_ITextSelection(me);
-    if (!This->reOle)
+    if (!This->txtDoc)
         return CO_E_RELEASED;
 
     FIXME("not implemented\n");
@@ -1129,7 +1158,7 @@ static HRESULT WINAPI ITextSelection_fnMoveUntil(ITextSelection *me, VARIANT *Cs
     LONG *pDelta)
 {
     ITextSelectionImpl *This = impl_from_ITextSelection(me);
-    if (!This->reOle)
+    if (!This->txtDoc)
         return CO_E_RELEASED;
 
     FIXME("not implemented\n");
@@ -1140,7 +1169,7 @@ static HRESULT WINAPI ITextSelection_fnMoveStartUntil(ITextSelection *me, VARIAN
     LONG *pDelta)
 {
     ITextSelectionImpl *This = impl_from_ITextSelection(me);
-    if (!This->reOle)
+    if (!This->txtDoc)
         return CO_E_RELEASED;
 
     FIXME("not implemented\n");
@@ -1151,7 +1180,7 @@ static HRESULT WINAPI ITextSelection_fnMoveEndUntil(ITextSelection *me, VARIANT
     LONG *pDelta)
 {
     ITextSelectionImpl *This = impl_from_ITextSelection(me);
-    if (!This->reOle)
+    if (!This->txtDoc)
         return CO_E_RELEASED;
 
     FIXME("not implemented\n");
@@ -1162,7 +1191,7 @@ static HRESULT WINAPI ITextSelection_fnFindText(ITextSelection *me, BSTR bstr, L
     LONG *pLength)
 {
     ITextSelectionImpl *This = impl_from_ITextSelection(me);
-    if (!This->reOle)
+    if (!This->txtDoc)
         return CO_E_RELEASED;
 
     FIXME("not implemented\n");
@@ -1173,7 +1202,7 @@ static HRESULT WINAPI ITextSelection_fnFindTextStart(ITextSelection *me, BSTR bs
     LONG Flags, LONG *pLength)
 {
     ITextSelectionImpl *This = impl_from_ITextSelection(me);
-    if (!This->reOle)
+    if (!This->txtDoc)
         return CO_E_RELEASED;
 
     FIXME("not implemented\n");
@@ -1184,7 +1213,7 @@ static HRESULT WINAPI ITextSelection_fnFindTextEnd(ITextSelection *me, BSTR bstr
     LONG Flags, LONG *pLength)
 {
     ITextSelectionImpl *This = impl_from_ITextSelection(me);
-    if (!This->reOle)
+    if (!This->txtDoc)
         return CO_E_RELEASED;
 
     FIXME("not implemented\n");
@@ -1195,7 +1224,7 @@ static HRESULT WINAPI ITextSelection_fnDelete(ITextSelection *me, LONG Unit, LON
     LONG *pDelta)
 {
     ITextSelectionImpl *This = impl_from_ITextSelection(me);
-    if (!This->reOle)
+    if (!This->txtDoc)
         return CO_E_RELEASED;
 
     FIXME("not implemented\n");
@@ -1205,7 +1234,7 @@ static HRESULT WINAPI ITextSelection_fnDelete(ITextSelection *me, LONG Unit, LON
 static HRESULT WINAPI ITextSelection_fnCut(ITextSelection *me, VARIANT *pVar)
 {
     ITextSelectionImpl *This = impl_from_ITextSelection(me);
-    if (!This->reOle)
+    if (!This->txtDoc)
         return CO_E_RELEASED;
 
     FIXME("not implemented\n");
@@ -1215,7 +1244,7 @@ static HRESULT WINAPI ITextSelection_fnCut(ITextSelection *me, VARIANT *pVar)
 static HRESULT WINAPI ITextSelection_fnCopy(ITextSelection *me, VARIANT *pVar)
 {
     ITextSelectionImpl *This = impl_from_ITextSelection(me);
-    if (!This->reOle)
+    if (!This->txtDoc)
         return CO_E_RELEASED;
 
     FIXME("not implemented\n");
@@ -1225,7 +1254,7 @@ static HRESULT WINAPI ITextSelection_fnCopy(ITextSelection *me, VARIANT *pVar)
 static HRESULT WINAPI ITextSelection_fnPaste(ITextSelection *me, VARIANT *pVar, LONG Format)
 {
     ITextSelectionImpl *This = impl_from_ITextSelection(me);
-    if (!This->reOle)
+    if (!This->txtDoc)
         return CO_E_RELEASED;
 
     FIXME("not implemented\n");
@@ -1236,7 +1265,7 @@ static HRESULT WINAPI ITextSelection_fnCanPaste(ITextSelection *me, VARIANT *pVa
     LONG *pb)
 {
     ITextSelectionImpl *This = impl_from_ITextSelection(me);
-    if (!This->reOle)
+    if (!This->txtDoc)
         return CO_E_RELEASED;
 
     FIXME("not implemented\n");
@@ -1246,7 +1275,7 @@ static HRESULT WINAPI ITextSelection_fnCanPaste(ITextSelection *me, VARIANT *pVa
 static HRESULT WINAPI ITextSelection_fnCanEdit(ITextSelection *me, LONG *pb)
 {
     ITextSelectionImpl *This = impl_from_ITextSelection(me);
-    if (!This->reOle)
+    if (!This->txtDoc)
         return CO_E_RELEASED;
 
     FIXME("not implemented\n");
@@ -1256,7 +1285,7 @@ static HRESULT WINAPI ITextSelection_fnCanEdit(ITextSelection *me, LONG *pb)
 static HRESULT WINAPI ITextSelection_fnChangeCase(ITextSelection *me, LONG Type)
 {
     ITextSelectionImpl *This = impl_from_ITextSelection(me);
-    if (!This->reOle)
+    if (!This->txtDoc)
         return CO_E_RELEASED;
 
     FIXME("not implemented\n");
@@ -1266,7 +1295,7 @@ static HRESULT WINAPI ITextSelection_fnChangeCase(ITextSelection *me, LONG Type)
 static HRESULT WINAPI ITextSelection_fnGetPoint(ITextSelection *me, LONG Type, LONG *cx, LONG *cy)
 {
     ITextSelectionImpl *This = impl_from_ITextSelection(me);
-    if (!This->reOle)
+    if (!This->txtDoc)
         return CO_E_RELEASED;
 
     FIXME("not implemented\n");
@@ -1277,7 +1306,7 @@ static HRESULT WINAPI ITextSelection_fnSetPoint(ITextSelection *me, LONG x, LONG
     LONG Extend)
 {
     ITextSelectionImpl *This = impl_from_ITextSelection(me);
-    if (!This->reOle)
+    if (!This->txtDoc)
         return CO_E_RELEASED;
 
     FIXME("not implemented\n");
@@ -1287,7 +1316,7 @@ static HRESULT WINAPI ITextSelection_fnSetPoint(ITextSelection *me, LONG x, LONG
 static HRESULT WINAPI ITextSelection_fnScrollIntoView(ITextSelection *me, LONG Value)
 {
     ITextSelectionImpl *This = impl_from_ITextSelection(me);
-    if (!This->reOle)
+    if (!This->txtDoc)
         return CO_E_RELEASED;
 
     FIXME("not implemented\n");
@@ -1297,7 +1326,7 @@ static HRESULT WINAPI ITextSelection_fnScrollIntoView(ITextSelection *me, LONG V
 static HRESULT WINAPI ITextSelection_fnGetEmbeddedObject(ITextSelection *me, IUnknown **ppv)
 {
     ITextSelectionImpl *This = impl_from_ITextSelection(me);
-    if (!This->reOle)
+    if (!This->txtDoc)
         return CO_E_RELEASED;
 
     FIXME("not implemented\n");
@@ -1308,7 +1337,7 @@ static HRESULT WINAPI ITextSelection_fnGetEmbeddedObject(ITextSelection *me, IUn
 static HRESULT WINAPI ITextSelection_fnGetFlags(ITextSelection *me, LONG *pFlags)
 {
     ITextSelectionImpl *This = impl_from_ITextSelection(me);
-    if (!This->reOle)
+    if (!This->txtDoc)
         return CO_E_RELEASED;
 
     FIXME("not implemented\n");
@@ -1318,7 +1347,7 @@ static HRESULT WINAPI ITextSelection_fnGetFlags(ITextSelection *me, LONG *pFlags
 static HRESULT WINAPI ITextSelection_fnSetFlags(ITextSelection *me, LONG Flags)
 {
     ITextSelectionImpl *This = impl_from_ITextSelection(me);
-    if (!This->reOle)
+    if (!This->txtDoc)
         return CO_E_RELEASED;
 
     FIXME("not implemented\n");
@@ -1328,7 +1357,7 @@ static HRESULT WINAPI ITextSelection_fnSetFlags(ITextSelection *me, LONG Flags)
 static HRESULT WINAPI ITextSelection_fnGetType(ITextSelection *me, LONG *pType)
 {
     ITextSelectionImpl *This = impl_from_ITextSelection(me);
-    if (!This->reOle)
+    if (!This->txtDoc)
         return CO_E_RELEASED;
 
     FIXME("not implemented\n");
@@ -1339,7 +1368,7 @@ static HRESULT WINAPI ITextSelection_fnMoveLeft(ITextSelection *me, LONG Unit, L
     LONG Extend, LONG *pDelta)
 {
     ITextSelectionImpl *This = impl_from_ITextSelection(me);
-    if (!This->reOle)
+    if (!This->txtDoc)
         return CO_E_RELEASED;
 
     FIXME("not implemented\n");
@@ -1350,7 +1379,7 @@ static HRESULT WINAPI ITextSelection_fnMoveRight(ITextSelection *me, LONG Unit,
     LONG Extend, LONG *pDelta)
 {
     ITextSelectionImpl *This = impl_from_ITextSelection(me);
-    if (!This->reOle)
+    if (!This->txtDoc)
         return CO_E_RELEASED;
 
     FIXME("not implemented\n");
@@ -1361,7 +1390,7 @@ static HRESULT WINAPI ITextSelection_fnMoveUp(ITextSelection *me, LONG Unit, LON
     LONG Extend, LONG *pDelta)
 {
     ITextSelectionImpl *This = impl_from_ITextSelection(me);
-    if (!This->reOle)
+    if (!This->txtDoc)
         return CO_E_RELEASED;
 
     FIXME("not implemented\n");
@@ -1372,7 +1401,7 @@ static HRESULT WINAPI ITextSelection_fnMoveDown(ITextSelection *me, LONG Unit, L
     LONG Extend, LONG *pDelta)
 {
     ITextSelectionImpl *This = impl_from_ITextSelection(me);
-    if (!This->reOle)
+    if (!This->txtDoc)
         return CO_E_RELEASED;
 
     FIXME("not implemented\n");
@@ -1383,7 +1412,7 @@ static HRESULT WINAPI ITextSelection_fnHomeKey(ITextSelection *me, LONG Unit, LO
     LONG *pDelta)
 {
     ITextSelectionImpl *This = impl_from_ITextSelection(me);
-    if (!This->reOle)
+    if (!This->txtDoc)
         return CO_E_RELEASED;
 
     FIXME("not implemented\n");
@@ -1394,7 +1423,7 @@ static HRESULT WINAPI ITextSelection_fnEndKey(ITextSelection *me, LONG Unit, LON
     LONG *pDelta)
 {
     ITextSelectionImpl *This = impl_from_ITextSelection(me);
-    if (!This->reOle)
+    if (!This->txtDoc)
         return CO_E_RELEASED;
 
     FIXME("not implemented\n");
@@ -1404,7 +1433,7 @@ static HRESULT WINAPI ITextSelection_fnEndKey(ITextSelection *me, LONG Unit, LON
 static HRESULT WINAPI ITextSelection_fnTypeText(ITextSelection *me, BSTR bstr)
 {
     ITextSelectionImpl *This = impl_from_ITextSelection(me);
-    if (!This->reOle)
+    if (!This->txtDoc)
         return CO_E_RELEASED;
 
     FIXME("not implemented\n");
@@ -1482,8 +1511,7 @@ static const ITextSelectionVtbl tsvt = {
     ITextSelection_fnTypeText
 };
 
-static ITextSelectionImpl *
-CreateTextSelection(IRichEditOleImpl *reOle)
+static ITextSelectionImpl *CreateTextSelection(ITextDocumentImpl *txtDoc)
 {
     ITextSelectionImpl *txtSel = heap_alloc(sizeof *txtSel);
     if (!txtSel)
@@ -1491,7 +1519,7 @@ CreateTextSelection(IRichEditOleImpl *reOle)
 
     txtSel->ITextSelection_iface.lpVtbl = &tsvt;
     txtSel->ref = 1;
-    txtSel->reOle = reOle;
+    txtSel->txtDoc = txtDoc;
     return txtSel;
 }
 
@@ -1504,19 +1532,18 @@ LRESULT CreateIRichEditOle(ME_TextEditor *editor, LPVOID *ppObj)
         return 0;
 
     reo->IRichEditOle_iface.lpVtbl = &revt;
-    reo->ITextDocument_iface.lpVtbl = &tdvt;
-    reo->ref = 1;
-    reo->editor = editor;
-    reo->txtSel = CreateTextSelection(reo);
-    if (!reo->txtSel)
+    reo->txtDoc = ITextDocumentImpl_create((IUnknown*) &reo->IRichEditOle_iface, editor);
+    if (!reo->txtDoc)
     {
         heap_free(reo);
         return 0;
     }
+    reo->ref = 1;
+    reo->editor = editor;
     reo->clientSite = CreateOleClientSite(reo);
-    if (!reo->txtSel)
+    if (!reo->clientSite)
     {
-        ITextSelection_Release(&reo->txtSel->ITextSelection_iface);
+        ITextDocumentImpl_destroy(reo->txtDoc);
         heap_free(reo);
         return 0;
     }
diff --git a/dlls/riched20/tests/txtsrv.c b/dlls/riched20/tests/txtsrv.c
index e517e03..5f7d7de 100644
--- a/dlls/riched20/tests/txtsrv.c
+++ b/dlls/riched20/tests/txtsrv.c
@@ -29,6 +29,8 @@
 #include <winbase.h>
 #include <objbase.h>
 #include <richedit.h>
+/* should be included before initguid.h to avoid multiple difenition with richole.c */
+#include <tom.h>
 #include <initguid.h>
 #include <textserv.h>
 #include <wine/test.h>
@@ -857,6 +859,7 @@ static void test_COM(void)
     struct unk_impl unk_obj = {{&unk_vtbl}, 19, NULL};
     struct ITextHostTestImpl texthost = {{&itextHostVtbl}, 1};
     ITextServices *textsrv;
+    ITextDocument *textdoc;
     ULONG refcount;
     HRESULT hr;
 
@@ -864,6 +867,7 @@ static void test_COM(void)
     hr = pCreateTextServices(&unk_obj.IUnknown_iface, &texthost.ITextHost_iface,
                              &unk_obj.inner_unk);
     ok(hr == S_OK, "CreateTextServices failed: %08x\n", hr);
+
     hr = IUnknown_QueryInterface(unk_obj.inner_unk, pIID_ITextServices, (void**)&textsrv);
     ok(hr == S_OK, "QueryInterface for IID_ITextServices failed: %08x\n", hr);
     refcount = ITextServices_AddRef(textsrv);
@@ -871,6 +875,12 @@ static void test_COM(void)
     refcount = ITextServices_Release(textsrv);
     ok(refcount == unk_obj.ref, "CreateTextServices just pretends to support COM aggregation\n");
     refcount = ITextServices_Release(textsrv);
+
+    /* Test that ITextDocument is supported */
+    hr = IUnknown_QueryInterface(unk_obj.inner_unk, &IID_ITextDocument, (void**)&textdoc);
+    ok(hr == S_OK, "QueryInterface for IID_ITextDocument failed: %08x\n", hr);
+    refcount = ITextDocument_Release(textdoc);
+
     ok(refcount == 19, "Refcount should be back at 19 but is %u\n", refcount);
 
     IUnknown_Release(unk_obj.inner_unk);
diff --git a/dlls/riched20/tomimpl.h b/dlls/riched20/tomimpl.h
new file mode 100644
index 0000000..886c3a8
--- /dev/null
+++ b/dlls/riched20/tomimpl.h
@@ -0,0 +1,59 @@
+/*
+ * RichEdit - TOM interfaces implementations
+ *
+ * Copyright 2013 by Caibin Chen
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef __RICHOLE_H
+#define __RICHOLE_H
+
+#include <tom.h>
+
+#include "editstr.h"
+
+typedef struct ITextDocumentImpl ITextDocumentImpl;
+typedef struct ITextSelectionImpl ITextSelectionImpl;
+
+/* ITextDocument */
+
+struct ITextDocumentImpl {
+  ITextDocument ITextDocument_iface;
+  IUnknown *outer_unk;
+  ME_TextEditor *editor;
+  ITextSelectionImpl *txtSel;
+};
+
+/**
+ * Create an ITextDocumentImpl object, which acts as an inner object of COM aggression.
+ *
+ * The ITextDocumentImpl object will delegate all of its IUnknown calls to the specified
+ * {@code outer_unk}.
+ *
+ * @param outer_unk The outer objects that creates and delegates ITextDocument
+ *        method calls to the created ITextDocumentImpl.
+ * @param editor The editor implementation.
+ *
+ * @return An ITextDocumentImpl object that should be destroyed with
+ * {@code ITextDocumentImpl_destroy}
+ */
+ITextDocumentImpl *ITextDocumentImpl_create(IUnknown *outer_unk, ME_TextEditor *editor);
+
+void ITextDocumentImpl_destroy(ITextDocumentImpl *document);
+
+/* ITextSelection */
+
+#endif /* __RICHOLE_H */
diff --git a/dlls/riched20/txtsrv.c b/dlls/riched20/txtsrv.c
index 0e78c53..e437a38 100644
--- a/dlls/riched20/txtsrv.c
+++ b/dlls/riched20/txtsrv.c
@@ -31,6 +31,7 @@
 #include "richole.h"
 #include "imm.h"
 #include "textserv.h"
+#include "tomimpl.h"
 #include "wine/debug.h"
 #include "editstr.h"
 
@@ -61,6 +62,7 @@ typedef struct ITextServicesImpl {
    ITextHost *pMyHost;
    CRITICAL_SECTION csTxtSrv;
    ME_TextEditor *editor;
+   ITextDocumentImpl *txtDoc;
    char spare[256];
 } ITextServicesImpl;
 
@@ -79,6 +81,8 @@ static HRESULT WINAPI ITextServicesImpl_QueryInterface(IUnknown *iface, REFIID r
       *ppv = &This->IUnknown_inner;
    else if (IsEqualIID(riid, &IID_ITextServices))
       *ppv = &This->ITextServices_iface;
+   else if (IsEqualIID(riid, &IID_ITextDocument))
+      *ppv = &This->txtDoc->ITextDocument_iface;
    else {
       *ppv = NULL;
       FIXME("Unknown interface: %s\n", debugstr_guid(riid));
@@ -111,6 +115,7 @@ static ULONG WINAPI ITextServicesImpl_Release(IUnknown *iface)
       ITextHost_Release(This->pMyHost);
       This->csTxtSrv.DebugInfo->Spare[0] = 0;
       DeleteCriticalSection(&This->csTxtSrv);
+      ITextDocumentImpl_destroy(This->txtDoc);
       CoTaskMemFree(This);
    }
    return ref;
@@ -420,6 +425,7 @@ HRESULT WINAPI CreateTextServices(IUnknown  *pUnkOuter, ITextHost *pITextHost, I
       ITextImpl->outer_unk = pUnkOuter;
    else
       ITextImpl->outer_unk = &ITextImpl->IUnknown_inner;
+   ITextImpl->txtDoc = ITextDocumentImpl_create(ITextImpl->outer_unk, ITextImpl->editor);
 
    *ppUnk = &ITextImpl->IUnknown_inner;
    return S_OK;
-- 
1.8.3.4


More information about the wine-patches mailing list