[PATCH 2/4] riched20: Merge the richole object with the text services object.

Huw Davies huw at codeweavers.com
Wed Mar 31 06:23:04 CDT 2021


Signed-off-by: Huw Davies <huw at codeweavers.com>
---
 dlls/riched20/editor.c  |  31 +-
 dlls/riched20/editor.h  |   4 +-
 dlls/riched20/editstr.h |  26 +-
 dlls/riched20/richole.c | 897 ++++++++++++++++++----------------------
 dlls/riched20/txtsrv.c  |  29 +-
 5 files changed, 444 insertions(+), 543 deletions(-)

diff --git a/dlls/riched20/editor.c b/dlls/riched20/editor.c
index deb0a93c8dc..d4aadc325f9 100644
--- a/dlls/riched20/editor.c
+++ b/dlls/riched20/editor.c
@@ -1121,7 +1121,6 @@ static HRESULT insert_static_object(ME_TextEditor *editor, HENHMETAFILE hemf, HB
   LPOLECLIENTSITE     lpClientSite = NULL;
   LPDATAOBJECT        lpDataObject = NULL;
   LPOLECACHE          lpOleCache = NULL;
-  LPRICHEDITOLE       lpReOle = NULL;
   STGMEDIUM           stgm;
   FORMATETC           fm;
   CLSID               clsid;
@@ -1149,15 +1148,8 @@ static HRESULT insert_static_object(ME_TextEditor *editor, HENHMETAFILE hemf, HB
   fm.lindex = -1;
   fm.tymed = stgm.tymed;
 
-  if (!editor->reOle)
-  {
-    if (!CreateIRichEditOle(NULL, editor, (LPVOID *)&editor->reOle))
-      return hr;
-  }
-
   if (OleCreateDefaultHandler(&CLSID_NULL, NULL, &IID_IOleObject, (void**)&lpObject) == S_OK &&
-      IUnknown_QueryInterface(editor->reOle, &IID_IRichEditOle, (void**)&lpReOle) == S_OK &&
-      IRichEditOle_GetClientSite(lpReOle, &lpClientSite) == S_OK &&
+      IRichEditOle_GetClientSite(editor->richole, &lpClientSite) == S_OK &&
       IOleObject_SetClientSite(lpObject, lpClientSite) == S_OK &&
       IOleObject_GetUserClassID(lpObject, &clsid) == S_OK &&
       IOleObject_QueryInterface(lpObject, &IID_IOleCache, (void**)&lpOleCache) == S_OK &&
@@ -1189,7 +1181,6 @@ static HRESULT insert_static_object(ME_TextEditor *editor, HENHMETAFILE hemf, HB
   if (lpStorage)      IStorage_Release(lpStorage);
   if (lpDataObject)   IDataObject_Release(lpDataObject);
   if (lpOleCache)     IOleCache_Release(lpOleCache);
-  if (lpReOle)        IRichEditOle_Release(lpReOle);
 
   return hr;
 }
@@ -2950,7 +2941,6 @@ ME_TextEditor *ME_MakeEditor(ITextHost *texthost, BOOL bEmulateVersion10)
     ed->have_texthost2 = FALSE;
   }
 
-  ed->reOle = NULL;
   ed->bEmulateVersion10 = bEmulateVersion10;
   ed->in_place_active = FALSE;
   ed->total_rows = 0;
@@ -2993,6 +2983,7 @@ ME_TextEditor *ME_MakeEditor(ITextHost *texthost, BOOL bEmulateVersion10)
   ed->last_sel_start_para = ed->last_sel_end_para = ed->pCursors[0].para;
   ed->bHideSelection = FALSE;
   ed->pfnWordBreak = NULL;
+  ed->richole = NULL;
   ed->lpOleCallback = NULL;
   ed->mode = TM_MULTILEVELUNDO | TM_MULTICODEPAGE;
   ed->mode |= (ed->props & TXTBIT_RICHTEXT) ? TM_RICHTEXT : TM_PLAINTEXT;
@@ -3094,11 +3085,7 @@ void ME_DestroyEditor(ME_TextEditor *editor)
   }
   if(editor->lpOleCallback)
     IRichEditOleCallback_Release(editor->lpOleCallback);
-  if (editor->reOle)
-  {
-    IUnknown_Release(editor->reOle);
-    editor->reOle = NULL;
-  }
+
   OleUninitialize();
 
   heap_free(editor->pBuffer);
@@ -4159,14 +4146,10 @@ LRESULT editor_handle_message( ME_TextEditor *editor, UINT msg, WPARAM wParam,
     return 0;
   }
   case EM_GETOLEINTERFACE:
-  {
-    if (!editor->reOle)
-      if (!CreateIRichEditOle(NULL, editor, (LPVOID *)&editor->reOle))
-        return 0;
-    if (IUnknown_QueryInterface(editor->reOle, &IID_IRichEditOle, (LPVOID *)lParam) == S_OK)
-      return 1;
-    return 0;
-  }
+    IRichEditOle_AddRef( editor->richole );
+    *(IRichEditOle **)lParam = editor->richole;
+    return 1;
+
   case EM_SETOLECALLBACK:
     if(editor->lpOleCallback)
       IRichEditOleCallback_Release(editor->lpOleCallback);
diff --git a/dlls/riched20/editor.h b/dlls/riched20/editor.h
index d0274de409d..141e9034a6a 100644
--- a/dlls/riched20/editor.h
+++ b/dlls/riched20/editor.h
@@ -263,11 +263,13 @@ void ME_UpdateScrollBar(ME_TextEditor *editor) DECLSPEC_HIDDEN;
 int ME_GetParaBorderWidth(const ME_Context *c, int flags) DECLSPEC_HIDDEN;
 
 /* richole.c */
-LRESULT CreateIRichEditOle(IUnknown *outer_unk, ME_TextEditor *editor, LPVOID *ppvObj) DECLSPEC_HIDDEN;
 void draw_ole( ME_Context *c, int x, int y, ME_Run* run, BOOL selected ) DECLSPEC_HIDDEN;
 void ME_GetOLEObjectSize(const ME_Context *c, ME_Run *run, SIZE *pSize) DECLSPEC_HIDDEN;
 void ME_CopyReObject(REOBJECT *dst, const REOBJECT *src, DWORD flags) DECLSPEC_HIDDEN;
 void ME_DeleteReObject(struct re_object *re_object) DECLSPEC_HIDDEN;
+void richole_release_children( struct text_services *services ) DECLSPEC_HIDDEN;
+extern const IRichEditOleVtbl re_ole_vtbl DECLSPEC_HIDDEN;
+extern const ITextDocument2OldVtbl text_doc2old_vtbl DECLSPEC_HIDDEN;
 
 /* editor.c */
 ME_TextEditor *ME_MakeEditor(ITextHost *texthost, BOOL bEmulateVersion10) DECLSPEC_HIDDEN;
diff --git a/dlls/riched20/editstr.h b/dlls/riched20/editstr.h
index 86b3f0196c7..22cfd74722c 100644
--- a/dlls/riched20/editstr.h
+++ b/dlls/riched20/editstr.h
@@ -41,6 +41,7 @@
 #include <richole.h>
 #include "imm.h"
 #include <textserv.h>
+#include <tom.h>
 #include "usp10.h"
 
 #include "wine/asm.h"
@@ -378,7 +379,6 @@ typedef struct tagME_InStream ME_InStream;
 typedef struct tagME_TextEditor
 {
   ITextHost2 *texthost;
-  IUnknown *reOle;
   unsigned int bEmulateVersion10 : 1;
   unsigned int in_place_active : 1;
   unsigned int have_texthost2 : 1;
@@ -409,6 +409,7 @@ typedef struct tagME_TextEditor
   BOOL bWordWrap;
   int nTextLimit;
   EDITWORDBREAKPROCW pfnWordBreak;
+  IRichEditOle *richole;
   LPRICHEDITOLECALLBACK lpOleCallback;
   /*TEXTMODE variable; contains only one of each of the following options:
    *TM_RICHTEXT or TM_PLAINTEXT
@@ -456,4 +457,27 @@ typedef struct tagME_Context
   ME_TextEditor *editor;
 } ME_Context;
 
+struct text_selection
+{
+    ITextSelection ITextSelection_iface;
+    LONG ref;
+
+    struct text_services *services;
+};
+
+struct text_services
+{
+    IUnknown IUnknown_inner;
+    ITextServices ITextServices_iface;
+    IRichEditOle IRichEditOle_iface;
+    ITextDocument2Old ITextDocument2Old_iface;
+    IUnknown *outer_unk;
+    LONG ref;
+    ME_TextEditor *editor;
+    struct text_selection *text_selection;
+    struct list rangelist;
+    struct list clientsites;
+    char spare[256]; /* for bug #12179 */
+};
+
 #endif
diff --git a/dlls/riched20/richole.c b/dlls/riched20/richole.c
index 2bb15bb4504..72840a4cafa 100644
--- a/dlls/riched20/richole.c
+++ b/dlls/riched20/richole.c
@@ -136,7 +136,6 @@ static HRESULT get_typeinfo(enum tid_t tid, ITypeInfo **typeinfo)
 /* private IID used to get back IRichEditOleImpl pointer */
 DEFINE_GUID(IID_Igetrichole, 0xe3ce5c7a, 0x8247, 0x4622, 0x81, 0xad, 0x11, 0x81, 0x02, 0xaa, 0x01, 0x30);
 
-typedef struct ITextSelectionImpl ITextSelectionImpl;
 typedef struct IOleClientSiteImpl IOleClientSiteImpl;
 typedef struct ITextRangeImpl ITextRangeImpl;
 
@@ -206,23 +205,9 @@ enum range_update_op {
     RANGE_UPDATE_DELETE
 };
 
-typedef struct IRichEditOleImpl {
-    IUnknown IUnknown_inner;
-    IRichEditOle IRichEditOle_iface;
-    ITextDocument2Old ITextDocument2Old_iface;
-    IUnknown *outer_unk;
-    LONG ref;
-
-    ME_TextEditor *editor;
-    ITextSelectionImpl *txtSel;
-
-    struct list rangelist;
-    struct list clientsites;
-} IRichEditOleImpl;
-
 struct reole_child {
     struct list entry;
-    IRichEditOleImpl *reole;
+    struct text_services *reole;
 };
 
 struct ITextRangeImpl {
@@ -232,13 +217,6 @@ struct ITextRangeImpl {
     LONG start, end;
 };
 
-struct ITextSelectionImpl {
-    ITextSelection ITextSelection_iface;
-    LONG ref;
-
-    IRichEditOleImpl *reOle;
-};
-
 typedef struct ITextFontImpl {
     ITextFont ITextFont_iface;
     LONG ref;
@@ -263,19 +241,14 @@ struct IOleClientSiteImpl {
     LONG ref;
 };
 
-static inline IRichEditOleImpl *impl_from_IRichEditOle(IRichEditOle *iface)
-{
-    return CONTAINING_RECORD(iface, IRichEditOleImpl, IRichEditOle_iface);
-}
-
-static inline IRichEditOleImpl *impl_from_ITextDocument2Old(ITextDocument2Old *iface)
+static inline struct text_services *impl_from_IRichEditOle( IRichEditOle *iface )
 {
-    return CONTAINING_RECORD(iface, IRichEditOleImpl, ITextDocument2Old_iface);
+    return CONTAINING_RECORD( iface, struct text_services, IRichEditOle_iface );
 }
 
-static inline IRichEditOleImpl *impl_from_IUnknown(IUnknown *iface)
+static inline struct text_services *impl_from_ITextDocument2Old( ITextDocument2Old *iface )
 {
-    return CONTAINING_RECORD(iface, IRichEditOleImpl, IUnknown_inner);
+    return CONTAINING_RECORD( iface, struct text_services, ITextDocument2Old_iface );
 }
 
 static inline IOleClientSiteImpl *impl_from_IOleInPlaceSite(IOleInPlaceSite *iface)
@@ -288,9 +261,9 @@ static inline ITextRangeImpl *impl_from_ITextRange(ITextRange *iface)
     return CONTAINING_RECORD(iface, ITextRangeImpl, ITextRange_iface);
 }
 
-static inline ITextSelectionImpl *impl_from_ITextSelection(ITextSelection *iface)
+static inline struct text_selection *impl_from_ITextSelection(ITextSelection *iface)
 {
-    return CONTAINING_RECORD(iface, ITextSelectionImpl, ITextSelection_iface);
+    return CONTAINING_RECORD(iface, struct text_selection, ITextSelection_iface);
 }
 
 static inline ITextFontImpl *impl_from_ITextFont(ITextFont *iface)
@@ -305,7 +278,7 @@ static inline ITextParaImpl *impl_from_ITextPara(ITextPara *iface)
 
 static HRESULT create_textfont(ITextRange*, const ITextFontImpl*, ITextFont**);
 static HRESULT create_textpara(ITextRange*, ITextPara**);
-static ITextSelectionImpl *CreateTextSelection(IRichEditOleImpl*);
+static struct text_selection *text_selection_create( struct text_services * );
 
 static HRESULT textrange_get_storylength(ME_TextEditor *editor, LONG *length)
 {
@@ -316,11 +289,11 @@ static HRESULT textrange_get_storylength(ME_TextEditor *editor, LONG *length)
     return S_OK;
 }
 
-static void textranges_update_ranges(IRichEditOleImpl *reole, LONG start, LONG end, enum range_update_op op)
+static void textranges_update_ranges(struct text_services *services, LONG start, LONG end, enum range_update_op op)
 {
     ITextRangeImpl *range;
 
-    LIST_FOR_EACH_ENTRY(range, &reole->rangelist, ITextRangeImpl, child.entry) {
+    LIST_FOR_EACH_ENTRY(range, &services->rangelist, ITextRangeImpl, child.entry) {
         switch (op)
         {
         case RANGE_UPDATE_DELETE:
@@ -434,7 +407,7 @@ static inline FLOAT points_to_twips(FLOAT value)
     return value * 1440 / 72.0;
 }
 
-static HRESULT get_textfont_prop_for_pos(const IRichEditOleImpl *reole, int pos, enum textfont_prop_id propid,
+static HRESULT get_textfont_prop_for_pos(const struct text_services *services, int pos, enum textfont_prop_id propid,
     textfont_prop_val *value)
 {
     ME_Cursor from, to;
@@ -444,10 +417,10 @@ static HRESULT get_textfont_prop_for_pos(const IRichEditOleImpl *reole, int pos,
     fmt.cbSize = sizeof(fmt);
     fmt.dwMask = textfont_prop_masks[propid][0];
 
-    cursor_from_char_ofs( reole->editor, pos, &from );
+    cursor_from_char_ofs( services->editor, pos, &from );
     to = from;
-    ME_MoveCursorChars(reole->editor, &to, 1, FALSE);
-    ME_GetCharFormat(reole->editor, &from, &to, &fmt);
+    ME_MoveCursorChars( services->editor, &to, 1, FALSE );
+    ME_GetCharFormat( services->editor, &from, &to, &fmt );
 
     switch (propid)
     {
@@ -508,11 +481,11 @@ static HRESULT get_textfont_prop_for_pos(const IRichEditOleImpl *reole, int pos,
     return S_OK;
 }
 
-static inline const IRichEditOleImpl *get_range_reole(ITextRange *range)
+static inline const struct text_services *get_range_reole(ITextRange *range)
 {
-    IRichEditOleImpl *reole = NULL;
-    ITextRange_QueryInterface(range, &IID_Igetrichole, (void**)&reole);
-    return reole;
+    struct text_services *services = NULL;
+    ITextRange_QueryInterface(range, &IID_Igetrichole, (void**)&services);
+    return services;
 }
 
 static void textrange_set_font(ITextRange *range, ITextFont *font)
@@ -664,22 +637,22 @@ static void textrange_set_font(ITextRange *range, ITextFont *font)
 
     if (fmt.dwMask)
     {
-        const IRichEditOleImpl *reole = get_range_reole(range);
+        const struct text_services *services = get_range_reole(range);
         ME_Cursor from, to;
         LONG start, end;
 
         ITextRange_GetStart(range, &start);
         ITextRange_GetEnd(range, &end);
 
-        cursor_from_char_ofs( reole->editor, start, &from );
-        cursor_from_char_ofs( reole->editor, end, &to );
-        ME_SetCharFormat(reole->editor, &from, &to, &fmt);
+        cursor_from_char_ofs( services->editor, start, &from );
+        cursor_from_char_ofs( services->editor, end, &to );
+        ME_SetCharFormat( services->editor, &from, &to, &fmt );
     }
 }
 
 static HRESULT get_textfont_prop(const ITextFontImpl *font, enum textfont_prop_id propid, textfont_prop_val *value)
 {
-    const IRichEditOleImpl *reole;
+    const struct text_services *services;
     textfont_prop_val v;
     LONG start, end, i;
     HRESULT hr;
@@ -690,7 +663,7 @@ static HRESULT get_textfont_prop(const ITextFontImpl *font, enum textfont_prop_i
         return S_OK;
     }
 
-    if (!(reole = get_range_reole(font->range)))
+    if (!(services = get_range_reole(font->range)))
         return CO_E_RELEASED;
 
     init_textfont_prop_value(propid, value);
@@ -699,14 +672,14 @@ static HRESULT get_textfont_prop(const ITextFontImpl *font, enum textfont_prop_i
     ITextRange_GetEnd(font->range, &end);
 
     /* iterate trough a range to see if property value is consistent */
-    hr = get_textfont_prop_for_pos(reole, start, propid, &v);
+    hr = get_textfont_prop_for_pos( services, start, propid, &v );
     if (FAILED(hr))
         return hr;
 
     for (i = start + 1; i < end; i++) {
         textfont_prop_val cur;
 
-        hr = get_textfont_prop_for_pos(reole, i, propid, &cur);
+        hr = get_textfont_prop_for_pos( services, i, propid, &cur );
         if (FAILED(hr))
             return hr;
 
@@ -747,7 +720,7 @@ static HRESULT get_textfont_propl(const ITextFontImpl *font, enum textfont_prop_
 /* Value should already have a terminal value, for boolean properties it means tomToggle is not handled */
 static HRESULT set_textfont_prop(ITextFontImpl *font, enum textfont_prop_id propid, const textfont_prop_val *value)
 {
-    const IRichEditOleImpl *reole;
+    const struct text_services *services;
     ME_Cursor from, to;
     CHARFORMAT2W fmt;
     LONG start, end;
@@ -763,7 +736,7 @@ static HRESULT set_textfont_prop(ITextFontImpl *font, enum textfont_prop_id prop
         return S_OK;
     }
 
-    if (!(reole = get_range_reole(font->range)))
+    if (!(services = get_range_reole(font->range)))
         return CO_E_RELEASED;
 
     memset(&fmt, 0, sizeof(fmt));
@@ -829,9 +802,9 @@ static HRESULT set_textfont_prop(ITextFontImpl *font, enum textfont_prop_id prop
     ITextRange_GetStart(font->range, &start);
     ITextRange_GetEnd(font->range, &end);
 
-    cursor_from_char_ofs( reole->editor, start, &from );
-    cursor_from_char_ofs( reole->editor, end, &to );
-    ME_SetCharFormat(reole->editor, &from, &to, &fmt);
+    cursor_from_char_ofs( services->editor, start, &from );
+    cursor_from_char_ofs( services->editor, end, &to );
+    ME_SetCharFormat( services->editor, &from, &to, &fmt );
 
     return S_OK;
 }
@@ -880,16 +853,16 @@ static HRESULT set_textfont_propd(ITextFontImpl *font, enum textfont_prop_id pro
 
 static HRESULT textfont_getname_from_range(ITextRange *range, BSTR *ret)
 {
-    const IRichEditOleImpl *reole;
+    const struct text_services *services;
     textfont_prop_val v;
     HRESULT hr;
     LONG start;
 
-    if (!(reole = get_range_reole(range)))
+    if (!(services = get_range_reole( range )))
         return CO_E_RELEASED;
 
     ITextRange_GetStart(range, &start);
-    hr = get_textfont_prop_for_pos(reole, start, FONT_NAME, &v);
+    hr = get_textfont_prop_for_pos( services, start, FONT_NAME, &v );
     *ret = v.str;
     return hr;
 }
@@ -934,118 +907,48 @@ static HRESULT textrange_expand(ITextRange *range, LONG unit, LONG *delta)
     return S_OK;
 }
 
-static HRESULT WINAPI IRichEditOleImpl_inner_fnQueryInterface(IUnknown *iface, REFIID riid, LPVOID *ppvObj)
-{
-    IRichEditOleImpl *This = impl_from_IUnknown(iface);
-
-    TRACE("%p %s\n", This, debugstr_guid(riid));
-
-    *ppvObj = NULL;
-    if (IsEqualGUID(riid, &IID_IUnknown))
-        *ppvObj = &This->IUnknown_inner;
-    else if (IsEqualGUID(riid, &IID_IRichEditOle))
-        *ppvObj = &This->IRichEditOle_iface;
-    else if (IsEqualGUID(riid, &IID_ITextDocument) || IsEqualGUID(riid, &IID_ITextDocument2Old))
-        *ppvObj = &This->ITextDocument2Old_iface;
-    if (*ppvObj)
-    {
-        IUnknown_AddRef((IUnknown *)*ppvObj);
-        return S_OK;
-    }
-    FIXME("%p: unhandled interface %s\n", This, debugstr_guid(riid));
- 
-    return E_NOINTERFACE;   
-}
-
-static ULONG WINAPI IRichEditOleImpl_inner_fnAddRef(IUnknown *iface)
-{
-    IRichEditOleImpl *This = impl_from_IUnknown(iface);
-    ULONG ref = InterlockedIncrement(&This->ref);
-
-    TRACE("%p ref = %u\n", This, ref);
-
-    return ref;
-}
-
-static ULONG WINAPI IRichEditOleImpl_inner_fnRelease(IUnknown *iface)
-{
-    IRichEditOleImpl *This = impl_from_IUnknown(iface);
-    ULONG ref = InterlockedDecrement(&This->ref);
-
-    TRACE ("%p ref=%u\n", This, ref);
-
-    if (!ref)
-    {
-        IOleClientSiteImpl *clientsite;
-        ITextRangeImpl *txtRge;
-
-        This->editor->reOle = NULL;
-        if (This->txtSel) {
-            This->txtSel->reOle = NULL;
-            ITextSelection_Release(&This->txtSel->ITextSelection_iface);
-        }
-
-        LIST_FOR_EACH_ENTRY(txtRge, &This->rangelist, ITextRangeImpl, child.entry)
-            txtRge->child.reole = NULL;
-
-        LIST_FOR_EACH_ENTRY(clientsite, &This->clientsites, IOleClientSiteImpl, child.entry)
-            clientsite->child.reole = NULL;
-
-        heap_free(This);
-    }
-    return ref;
-}
-
-static const IUnknownVtbl reo_unk_vtbl =
-{
-    IRichEditOleImpl_inner_fnQueryInterface,
-    IRichEditOleImpl_inner_fnAddRef,
-    IRichEditOleImpl_inner_fnRelease
-};
-
 static HRESULT WINAPI
-IRichEditOle_fnQueryInterface(IRichEditOle *me, REFIID riid, LPVOID *ppvObj)
+IRichEditOle_fnQueryInterface(IRichEditOle *iface, REFIID riid, LPVOID *ppvObj)
 {
-    IRichEditOleImpl *This = impl_from_IRichEditOle(me);
-    return IUnknown_QueryInterface(This->outer_unk, riid, ppvObj);
+    struct text_services *services = impl_from_IRichEditOle( iface );
+    return IUnknown_QueryInterface( services->outer_unk, riid, ppvObj );
 }
 
 static ULONG WINAPI
-IRichEditOle_fnAddRef(IRichEditOle *me)
+IRichEditOle_fnAddRef(IRichEditOle *iface)
 {
-    IRichEditOleImpl *This = impl_from_IRichEditOle(me);
-    return IUnknown_AddRef(This->outer_unk);
+    struct text_services *services = impl_from_IRichEditOle( iface );
+    return IUnknown_AddRef( services->outer_unk );
 }
 
 static ULONG WINAPI
-IRichEditOle_fnRelease(IRichEditOle *me)
+IRichEditOle_fnRelease(IRichEditOle *iface)
 {
-    IRichEditOleImpl *This = impl_from_IRichEditOle(me);
-    return IUnknown_Release(This->outer_unk);
+    struct text_services *services = impl_from_IRichEditOle( iface );
+    return IUnknown_Release( services->outer_unk );
 }
 
 static HRESULT WINAPI
-IRichEditOle_fnActivateAs(IRichEditOle *me, REFCLSID rclsid, REFCLSID rclsidAs)
+IRichEditOle_fnActivateAs(IRichEditOle *iface, REFCLSID rclsid, REFCLSID rclsidAs)
 {
-    IRichEditOleImpl *This = impl_from_IRichEditOle(me);
-    FIXME("stub %p\n",This);
+    struct text_services *services = impl_from_IRichEditOle( iface );
+    FIXME( "stub %p\n", services );
     return E_NOTIMPL;
 }
 
 static HRESULT WINAPI
-IRichEditOle_fnContextSensitiveHelp(IRichEditOle *me, BOOL fEnterMode)
+IRichEditOle_fnContextSensitiveHelp(IRichEditOle *iface, BOOL fEnterMode)
 {
-    IRichEditOleImpl *This = impl_from_IRichEditOle(me);
-    FIXME("stub %p\n",This);
+    struct text_services *services = impl_from_IRichEditOle( iface );
+    FIXME( "stub %p\n", services );
     return E_NOTIMPL;
 }
 
 static HRESULT WINAPI
-IRichEditOle_fnConvertObject(IRichEditOle *me, LONG iob,
-               REFCLSID rclsidNew, LPCSTR lpstrUserTypeNew)
+IRichEditOle_fnConvertObject( IRichEditOle *iface, LONG iob, REFCLSID class, LPCSTR user_type )
 {
-    IRichEditOleImpl *This = impl_from_IRichEditOle(me);
-    FIXME("stub %p\n",This);
+    struct text_services *services = impl_from_IRichEditOle( iface );
+    FIXME( "stub %p\n", services );
     return E_NOTIMPL;
 }
 
@@ -1308,7 +1211,7 @@ static const IOleInPlaceSiteVtbl olestvt =
     IOleInPlaceSite_fnOnPosRectChange
 };
 
-static HRESULT CreateOleClientSite(IRichEditOleImpl *reOle, IOleClientSite **ret)
+static HRESULT CreateOleClientSite( struct text_services *services, IOleClientSite **ret )
 {
     IOleClientSiteImpl *clientSite = heap_alloc(sizeof *clientSite);
 
@@ -1318,67 +1221,67 @@ static HRESULT CreateOleClientSite(IRichEditOleImpl *reOle, IOleClientSite **ret
     clientSite->IOleClientSite_iface.lpVtbl = &ocst;
     clientSite->IOleInPlaceSite_iface.lpVtbl = &olestvt;
     clientSite->ref = 1;
-    clientSite->child.reole = reOle;
-    list_add_head(&reOle->clientsites, &clientSite->child.entry);
+    clientSite->child.reole = services;
+    list_add_head( &services->clientsites, &clientSite->child.entry );
 
     *ret = &clientSite->IOleClientSite_iface;
     return S_OK;
 }
 
 static HRESULT WINAPI
-IRichEditOle_fnGetClientSite(IRichEditOle *me, IOleClientSite **clientsite)
+IRichEditOle_fnGetClientSite( IRichEditOle *iface, IOleClientSite **clientsite )
 {
-    IRichEditOleImpl *This = impl_from_IRichEditOle(me);
+    struct text_services *services = impl_from_IRichEditOle( iface );
 
-    TRACE("(%p)->(%p)\n", This, clientsite);
+    TRACE("(%p)->(%p)\n", services, clientsite);
 
     if (!clientsite)
         return E_INVALIDARG;
 
-    return CreateOleClientSite(This, clientsite);
+    return CreateOleClientSite( services, clientsite );
 }
 
 static HRESULT WINAPI
-IRichEditOle_fnGetClipboardData(IRichEditOle *me, CHARRANGE *lpchrg,
+IRichEditOle_fnGetClipboardData(IRichEditOle *iface, CHARRANGE *lpchrg,
                DWORD reco, LPDATAOBJECT *lplpdataobj)
 {
-    IRichEditOleImpl *This = impl_from_IRichEditOle(me);
+    struct text_services *services = impl_from_IRichEditOle( iface );
     ME_Cursor start;
     int nChars;
 
-    TRACE("(%p,%p,%d)\n",This, lpchrg, reco);
+    TRACE("(%p,%p,%d)\n", services, lpchrg, reco);
     if(!lplpdataobj)
         return E_INVALIDARG;
     if(!lpchrg)
     {
-        int nFrom, nTo, nStartCur = ME_GetSelectionOfs(This->editor, &nFrom, &nTo);
-        start = This->editor->pCursors[nStartCur];
+        int nFrom, nTo, nStartCur = ME_GetSelectionOfs( services->editor, &nFrom, &nTo );
+        start = services->editor->pCursors[nStartCur];
         nChars = nTo - nFrom;
     }
     else
     {
-        cursor_from_char_ofs( This->editor, lpchrg->cpMin, &start );
+        cursor_from_char_ofs( services->editor, lpchrg->cpMin, &start );
         nChars = lpchrg->cpMax - lpchrg->cpMin;
     }
-    return ME_GetDataObject(This->editor, &start, nChars, lplpdataobj);
+    return ME_GetDataObject( services->editor, &start, nChars, lplpdataobj );
 }
 
-static LONG WINAPI IRichEditOle_fnGetLinkCount(IRichEditOle *me)
+static LONG WINAPI IRichEditOle_fnGetLinkCount(IRichEditOle *iface)
 {
-    IRichEditOleImpl *This = impl_from_IRichEditOle(me);
-    FIXME("stub %p\n",This);
+    struct text_services *services = impl_from_IRichEditOle( iface );
+    FIXME("stub %p\n", services);
     return E_NOTIMPL;
 }
 
 static HRESULT WINAPI
-IRichEditOle_fnGetObject(IRichEditOle *me, LONG iob,
+IRichEditOle_fnGetObject(IRichEditOle *iface, LONG iob,
                REOBJECT *lpreobject, DWORD dwFlags)
 {
-    IRichEditOleImpl *This = impl_from_IRichEditOle(me);
+    struct text_services *services = impl_from_IRichEditOle( iface );
     struct re_object *reobj = NULL;
     LONG count = 0;
 
-    TRACE("(%p)->(%x, %p, %x)\n", This, iob, lpreobject, dwFlags);
+    TRACE("(%p)->(%x, %p, %x)\n", services, iob, lpreobject, dwFlags);
 
     if (!lpreobject || !lpreobject->cbStruct)
         return E_INVALIDARG;
@@ -1388,7 +1291,7 @@ IRichEditOle_fnGetObject(IRichEditOle *me, LONG iob,
         ME_Cursor cursor;
 
         TRACE("character offset: %d\n", lpreobject->cp);
-        cursor_from_char_ofs( This->editor, lpreobject->cp, &cursor );
+        cursor_from_char_ofs( services->editor, lpreobject->cp, &cursor );
         if (!cursor.run->reobj)
             return E_INVALIDARG;
         else
@@ -1398,7 +1301,7 @@ IRichEditOle_fnGetObject(IRichEditOle *me, LONG iob,
     {
         ME_Cursor *from, *to;
 
-        ME_GetSelection(This->editor, &from, &to);
+        ME_GetSelection(services->editor, &from, &to);
         if (!from->run->reobj)
             return E_INVALIDARG;
         else
@@ -1406,9 +1309,9 @@ IRichEditOle_fnGetObject(IRichEditOle *me, LONG iob,
     }
     else
     {
-        if (iob < 0 || iob >= IRichEditOle_GetObjectCount(me))
+        if (iob < 0 || iob >= IRichEditOle_GetObjectCount( iface ))
             return E_INVALIDARG;
-        LIST_FOR_EACH_ENTRY(reobj, &This->editor->reobj_list, struct re_object, entry)
+        LIST_FOR_EACH_ENTRY(reobj, &services->editor->reobj_list, struct re_object, entry)
         {
             if (count == iob)
                 break;
@@ -1420,89 +1323,90 @@ IRichEditOle_fnGetObject(IRichEditOle *me, LONG iob,
 }
 
 static LONG WINAPI
-IRichEditOle_fnGetObjectCount(IRichEditOle *me)
+IRichEditOle_fnGetObjectCount( IRichEditOle *iface )
 {
-    IRichEditOleImpl *This = impl_from_IRichEditOle(me);
-    TRACE("(%p)\n",This);
-    return list_count(&This->editor->reobj_list);
+    struct text_services *services = impl_from_IRichEditOle( iface );
+    TRACE("(%p)\n", services);
+    return list_count( &services->editor->reobj_list );
 }
 
 static HRESULT WINAPI
-IRichEditOle_fnHandsOffStorage(IRichEditOle *me, LONG iob)
+IRichEditOle_fnHandsOffStorage(IRichEditOle *iface, LONG iob)
 {
-    IRichEditOleImpl *This = impl_from_IRichEditOle(me);
-    FIXME("stub %p\n",This);
+    struct text_services *services = impl_from_IRichEditOle( iface );
+    FIXME("stub %p\n", services);
     return E_NOTIMPL;
 }
 
 static HRESULT WINAPI
-IRichEditOle_fnImportDataObject(IRichEditOle *me, LPDATAOBJECT lpdataobj,
+IRichEditOle_fnImportDataObject(IRichEditOle *iface, LPDATAOBJECT lpdataobj,
                CLIPFORMAT cf, HGLOBAL hMetaPict)
 {
-    IRichEditOleImpl *This = impl_from_IRichEditOle(me);
-    FIXME("stub %p\n",This);
+    struct text_services *services = impl_from_IRichEditOle( iface );
+    FIXME("stub %p\n", services);
     return E_NOTIMPL;
 }
 
 static HRESULT WINAPI
-IRichEditOle_fnInPlaceDeactivate(IRichEditOle *me)
+IRichEditOle_fnInPlaceDeactivate(IRichEditOle *iface)
 {
-    IRichEditOleImpl *This = impl_from_IRichEditOle(me);
-    FIXME("stub %p\n",This);
+    struct text_services *services = impl_from_IRichEditOle( iface );
+    FIXME("stub %p\n", services);
     return E_NOTIMPL;
 }
 
 static HRESULT WINAPI
-IRichEditOle_fnInsertObject(IRichEditOle *me, REOBJECT *reo)
+IRichEditOle_fnInsertObject(IRichEditOle *iface, REOBJECT *reo)
 {
-    IRichEditOleImpl *This = impl_from_IRichEditOle(me);
+    struct text_services *services = impl_from_IRichEditOle( iface );
 
-    TRACE("(%p,%p)\n", This, reo);
+    TRACE("(%p,%p)\n", services, reo);
 
     if (!reo)
         return E_INVALIDARG;
 
     if (reo->cbStruct < sizeof(*reo)) return STG_E_INVALIDPARAMETER;
 
-    ME_InsertOLEFromCursor(This->editor, reo, 0);
-    ME_CommitUndo(This->editor);
-    ME_UpdateRepaint(This->editor, FALSE);
+    ME_InsertOLEFromCursor(services->editor, reo, 0);
+    ME_CommitUndo(services->editor);
+    ME_UpdateRepaint(services->editor, FALSE);
     return S_OK;
 }
 
-static HRESULT WINAPI IRichEditOle_fnSaveCompleted(IRichEditOle *me, LONG iob,
+static HRESULT WINAPI IRichEditOle_fnSaveCompleted(IRichEditOle *iface, LONG iob,
                LPSTORAGE lpstg)
 {
-    IRichEditOleImpl *This = impl_from_IRichEditOle(me);
-    FIXME("stub %p\n",This);
+    struct text_services *services = impl_from_IRichEditOle( iface );
+    FIXME("stub %p\n", services);
     return E_NOTIMPL;
 }
 
 static HRESULT WINAPI
-IRichEditOle_fnSetDvaspect(IRichEditOle *me, LONG iob, DWORD dvaspect)
+IRichEditOle_fnSetDvaspect(IRichEditOle *iface, LONG iob, DWORD dvaspect)
 {
-    IRichEditOleImpl *This = impl_from_IRichEditOle(me);
-    FIXME("stub %p\n",This);
+    struct text_services *services = impl_from_IRichEditOle( iface );
+    FIXME("stub %p\n", services);
     return E_NOTIMPL;
 }
 
-static HRESULT WINAPI IRichEditOle_fnSetHostNames(IRichEditOle *me,
+static HRESULT WINAPI IRichEditOle_fnSetHostNames(IRichEditOle *iface,
                LPCSTR lpstrContainerApp, LPCSTR lpstrContainerObj)
 {
-    IRichEditOleImpl *This = impl_from_IRichEditOle(me);
-    FIXME("stub %p %s %s\n",This, lpstrContainerApp, lpstrContainerObj);
+    struct text_services *services = impl_from_IRichEditOle( iface );
+    FIXME("stub %p %s %s\n", services, lpstrContainerApp, lpstrContainerObj);
     return E_NOTIMPL;
 }
 
 static HRESULT WINAPI
-IRichEditOle_fnSetLinkAvailable(IRichEditOle *me, LONG iob, BOOL fAvailable)
+IRichEditOle_fnSetLinkAvailable(IRichEditOle *iface, LONG iob, BOOL fAvailable)
 {
-    IRichEditOleImpl *This = impl_from_IRichEditOle(me);
-    FIXME("stub %p\n",This);
+    struct text_services *services = impl_from_IRichEditOle( iface );
+    FIXME("stub %p\n", services);
     return E_NOTIMPL;
 }
 
-static const IRichEditOleVtbl revt = {
+const IRichEditOleVtbl re_ole_vtbl =
+{
     IRichEditOle_fnQueryInterface,
     IRichEditOle_fnAddRef,
     IRichEditOle_fnRelease,
@@ -1750,7 +1654,7 @@ static HRESULT WINAPI ITextRange_fnSetChar(ITextRange *me, LONG ch)
     return E_NOTIMPL;
 }
 
-static HRESULT CreateITextRange(IRichEditOleImpl *reOle, LONG start, LONG end, ITextRange** ppRange);
+static HRESULT CreateITextRange(struct text_services *services, LONG start, LONG end, ITextRange** ppRange);
 
 static HRESULT WINAPI ITextRange_fnGetDuplicate(ITextRange *me, ITextRange **ppRange)
 {
@@ -1807,7 +1711,7 @@ static HRESULT WINAPI ITextRange_fnGetStart(ITextRange *me, LONG *start)
     return S_OK;
 }
 
-static HRESULT textrange_setstart(const IRichEditOleImpl *reole, LONG value, LONG *start, LONG *end)
+static HRESULT textrange_setstart(const struct text_services *services, LONG value, LONG *start, LONG *end)
 {
     int len;
 
@@ -1822,7 +1726,7 @@ static HRESULT textrange_setstart(const IRichEditOleImpl *reole, LONG value, LON
         return S_OK;
     }
 
-    len = ME_GetTextLength(reole->editor);
+    len = ME_GetTextLength(services->editor);
     *start = *end = value > len ? len : value;
     return S_OK;
 }
@@ -1855,7 +1759,7 @@ static HRESULT WINAPI ITextRange_fnGetEnd(ITextRange *me, LONG *end)
     return S_OK;
 }
 
-static HRESULT textrange_setend(const IRichEditOleImpl *reole, LONG value, LONG *start, LONG *end)
+static HRESULT textrange_setend(const struct text_services *services, LONG value, LONG *start, LONG *end)
 {
     int len;
 
@@ -1867,7 +1771,7 @@ static HRESULT textrange_setend(const IRichEditOleImpl *reole, LONG value, LONG
         return S_OK;
     }
 
-    len = ME_GetTextLength(reole->editor);
+    len = ME_GetTextLength( services->editor );
     *end = value > len ? len + 1 : value;
     return S_OK;
 }
@@ -4126,27 +4030,27 @@ static HRESULT create_textpara(ITextRange *range, ITextPara **ret)
 static HRESULT WINAPI ITextDocument2Old_fnQueryInterface(ITextDocument2Old* iface, REFIID riid,
                                                          void **ppvObject)
 {
-    IRichEditOleImpl *This = impl_from_ITextDocument2Old(iface);
-    return IRichEditOle_QueryInterface(&This->IRichEditOle_iface, riid, ppvObject);
+    struct text_services *services = impl_from_ITextDocument2Old(iface);
+    return IUnknown_QueryInterface( services->outer_unk, riid, ppvObject );
 }
 
 static ULONG WINAPI ITextDocument2Old_fnAddRef(ITextDocument2Old *iface)
 {
-    IRichEditOleImpl *This = impl_from_ITextDocument2Old(iface);
-    return IRichEditOle_AddRef(&This->IRichEditOle_iface);
+    struct text_services *services = impl_from_ITextDocument2Old(iface);
+    return IUnknown_AddRef( services->outer_unk );
 }
 
 static ULONG WINAPI ITextDocument2Old_fnRelease(ITextDocument2Old *iface)
 {
-    IRichEditOleImpl *This = impl_from_ITextDocument2Old(iface);
-    return IRichEditOle_Release(&This->IRichEditOle_iface);
+    struct text_services *services = impl_from_ITextDocument2Old(iface);
+    return IUnknown_Release( services->outer_unk );
 }
 
 static HRESULT WINAPI ITextDocument2Old_fnGetTypeInfoCount(ITextDocument2Old *iface,
                                                            UINT *pctinfo)
 {
-    IRichEditOleImpl *This = impl_from_ITextDocument2Old(iface);
-    TRACE("(%p)->(%p)\n", This, pctinfo);
+    struct text_services *services = impl_from_ITextDocument2Old(iface);
+    TRACE("(%p)->(%p)\n", services, pctinfo);
     *pctinfo = 1;
     return S_OK;
 }
@@ -4154,10 +4058,10 @@ static HRESULT WINAPI ITextDocument2Old_fnGetTypeInfoCount(ITextDocument2Old *if
 static HRESULT WINAPI ITextDocument2Old_fnGetTypeInfo(ITextDocument2Old *iface, UINT iTInfo, LCID lcid,
                                                       ITypeInfo **ppTInfo)
 {
-    IRichEditOleImpl *This = impl_from_ITextDocument2Old(iface);
+    struct text_services *services = impl_from_ITextDocument2Old(iface);
     HRESULT hr;
 
-    TRACE("(%p)->(%u,%d,%p)\n", This, iTInfo, lcid, ppTInfo);
+    TRACE("(%p)->(%u,%d,%p)\n", services, iTInfo, lcid, ppTInfo);
 
     hr = get_typeinfo(ITextDocument_tid, ppTInfo);
     if (SUCCEEDED(hr))
@@ -4169,11 +4073,11 @@ static HRESULT WINAPI ITextDocument2Old_fnGetIDsOfNames(ITextDocument2Old *iface
                                                         LPOLESTR *rgszNames, UINT cNames,
                                                         LCID lcid, DISPID *rgDispId)
 {
-    IRichEditOleImpl *This = impl_from_ITextDocument2Old(iface);
+    struct text_services *services = impl_from_ITextDocument2Old(iface);
     ITypeInfo *ti;
     HRESULT hr;
 
-    TRACE("(%p)->(%s, %p, %u, %d, %p)\n", This, debugstr_guid(riid),
+    TRACE("(%p)->(%s, %p, %u, %d, %p)\n", services, debugstr_guid(riid),
             rgszNames, cNames, lcid, rgDispId);
 
     hr = get_typeinfo(ITextDocument_tid, &ti);
@@ -4187,11 +4091,11 @@ static HRESULT WINAPI ITextDocument2Old_fnInvoke(ITextDocument2Old *iface, DISPI
                                                  DISPPARAMS *pDispParams, VARIANT *pVarResult,
                                                  EXCEPINFO *pExcepInfo, UINT *puArgErr)
 {
-    IRichEditOleImpl *This = impl_from_ITextDocument2Old(iface);
+    struct text_services *services = impl_from_ITextDocument2Old(iface);
     ITypeInfo *ti;
     HRESULT hr;
 
-    TRACE("(%p)->(%d, %s, %d, %u, %p, %p, %p, %p)\n", This, dispIdMember,
+    TRACE("(%p)->(%d, %s, %d, %u, %p, %p, %p, %p)\n", services, dispIdMember,
             debugstr_guid(riid), lcid, wFlags, pDispParams, pVarResult,
             pExcepInfo, puArgErr);
 
@@ -4203,142 +4107,144 @@ static HRESULT WINAPI ITextDocument2Old_fnInvoke(ITextDocument2Old *iface, DISPI
 
 static HRESULT WINAPI ITextDocument2Old_fnGetName(ITextDocument2Old *iface, BSTR *pName)
 {
-    IRichEditOleImpl *This = impl_from_ITextDocument2Old(iface);
-    FIXME("stub %p\n",This);
+    struct text_services *services = impl_from_ITextDocument2Old(iface);
+    FIXME("stub %p\n", services);
     return E_NOTIMPL;
 }
 
 static HRESULT WINAPI ITextDocument2Old_fnGetSelection(ITextDocument2Old *iface, ITextSelection **selection)
 {
-    IRichEditOleImpl *This = impl_from_ITextDocument2Old(iface);
+    struct text_services *services = impl_from_ITextDocument2Old(iface);
 
     TRACE("(%p)->(%p)\n", iface, selection);
 
     if (!selection)
       return E_INVALIDARG;
 
-    if (!This->txtSel) {
-      This->txtSel = CreateTextSelection(This);
-      if (!This->txtSel) {
-        *selection = NULL;
-        return E_OUTOFMEMORY;
-      }
+    if (!services->text_selection)
+    {
+        services->text_selection = text_selection_create( services );
+        if (!services->text_selection)
+        {
+            *selection = NULL;
+            return E_OUTOFMEMORY;
+        }
     }
 
-    *selection = &This->txtSel->ITextSelection_iface;
+    *selection = &services->text_selection->ITextSelection_iface;
     ITextSelection_AddRef(*selection);
     return S_OK;
 }
 
 static HRESULT WINAPI ITextDocument2Old_fnGetStoryCount(ITextDocument2Old *iface, LONG *pCount)
 {
-    IRichEditOleImpl *This = impl_from_ITextDocument2Old(iface);
-    FIXME("stub %p\n",This);
+    struct text_services *services = impl_from_ITextDocument2Old(iface);
+    FIXME("stub %p\n", services);
     return E_NOTIMPL;
 }
 
 static HRESULT WINAPI ITextDocument2Old_fnGetStoryRanges(ITextDocument2Old *iface,
                                                          ITextStoryRanges **ppStories)
 {
-    IRichEditOleImpl *This = impl_from_ITextDocument2Old(iface);
-    FIXME("stub %p\n",This);
+    struct text_services *services = impl_from_ITextDocument2Old(iface);
+    FIXME("stub %p\n", services);
     return E_NOTIMPL;
 }
 
 static HRESULT WINAPI ITextDocument2Old_fnGetSaved(ITextDocument2Old *iface, LONG *pValue)
 {
-    IRichEditOleImpl *This = impl_from_ITextDocument2Old(iface);
-    FIXME("stub %p\n",This);
+    struct text_services *services = impl_from_ITextDocument2Old(iface);
+    FIXME("stub %p\n", services);
     return E_NOTIMPL;
 }
 
 static HRESULT WINAPI ITextDocument2Old_fnSetSaved(ITextDocument2Old *iface, LONG Value)
 {
-    IRichEditOleImpl *This = impl_from_ITextDocument2Old(iface);
-    FIXME("stub %p\n",This);
+    struct text_services *services = impl_from_ITextDocument2Old(iface);
+    FIXME("stub %p\n", services);
     return E_NOTIMPL;
 }
 
 static HRESULT WINAPI ITextDocument2Old_fnGetDefaultTabStop(ITextDocument2Old *iface, float *pValue)
 {
-    IRichEditOleImpl *This = impl_from_ITextDocument2Old(iface);
-    FIXME("stub %p\n",This);
+    struct text_services *services = impl_from_ITextDocument2Old(iface);
+    FIXME("stub %p\n", services);
     return E_NOTIMPL;
 }
 
 static HRESULT WINAPI ITextDocument2Old_fnSetDefaultTabStop(ITextDocument2Old *iface, float Value)
 {
-    IRichEditOleImpl *This = impl_from_ITextDocument2Old(iface);
-    FIXME("stub %p\n",This);
+    struct text_services *services = impl_from_ITextDocument2Old(iface);
+    FIXME("stub %p\n", services);
     return E_NOTIMPL;
 }
 
 static HRESULT WINAPI ITextDocument2Old_fnNew(ITextDocument2Old *iface)
 {
-    IRichEditOleImpl *This = impl_from_ITextDocument2Old(iface);
-    FIXME("stub %p\n",This);
+    struct text_services *services = impl_from_ITextDocument2Old(iface);
+    FIXME("stub %p\n", services);
     return E_NOTIMPL;
 }
 
 static HRESULT WINAPI ITextDocument2Old_fnOpen(ITextDocument2Old *iface, VARIANT *pVar,
                                                LONG Flags, LONG CodePage)
 {
-    IRichEditOleImpl *This = impl_from_ITextDocument2Old(iface);
-    FIXME("stub %p\n",This);
+    struct text_services *services = impl_from_ITextDocument2Old(iface);
+    FIXME("stub %p\n", services);
     return E_NOTIMPL;
 }
 
 static HRESULT WINAPI ITextDocument2Old_fnSave(ITextDocument2Old *iface, VARIANT *pVar,
                                                LONG Flags, LONG CodePage)
 {
-    IRichEditOleImpl *This = impl_from_ITextDocument2Old(iface);
-    FIXME("stub %p\n",This);
+    struct text_services *services = impl_from_ITextDocument2Old(iface);
+    FIXME("stub %p\n", services);
     return E_NOTIMPL;
 }
 
 static HRESULT WINAPI ITextDocument2Old_fnFreeze(ITextDocument2Old *iface, LONG *pCount)
 {
-    IRichEditOleImpl *This = impl_from_ITextDocument2Old(iface);
-    FIXME("stub %p\n",This);
+    struct text_services *services = impl_from_ITextDocument2Old(iface);
+    FIXME("stub %p\n", services);
     return E_NOTIMPL;
 }
 
 static HRESULT WINAPI ITextDocument2Old_fnUnfreeze(ITextDocument2Old *iface, LONG *pCount)
 {
-    IRichEditOleImpl *This = impl_from_ITextDocument2Old(iface);
-    FIXME("stub %p\n",This);
+    struct text_services *services = impl_from_ITextDocument2Old(iface);
+    FIXME("stub %p\n", services);
     return E_NOTIMPL;
 }
 
 static HRESULT WINAPI ITextDocument2Old_fnBeginEditCollection(ITextDocument2Old *iface)
 {
-    IRichEditOleImpl *This = impl_from_ITextDocument2Old(iface);
-    FIXME("stub %p\n",This);
+    struct text_services *services = impl_from_ITextDocument2Old(iface);
+    FIXME("stub %p\n", services);
     return E_NOTIMPL;
 }
 
 static HRESULT WINAPI ITextDocument2Old_fnEndEditCollection(ITextDocument2Old *iface)
 {
-    IRichEditOleImpl *This = impl_from_ITextDocument2Old(iface);
-    FIXME("stub %p\n",This);
+    struct text_services *services = impl_from_ITextDocument2Old(iface);
+    FIXME("stub %p\n", services);
     return E_NOTIMPL;
 }
 
 static HRESULT WINAPI ITextDocument2Old_fnUndo(ITextDocument2Old *iface, LONG Count, LONG *prop)
 {
-    IRichEditOleImpl *This = impl_from_ITextDocument2Old(iface);
-    FIXME("stub %p\n",This);
+    struct text_services *services = impl_from_ITextDocument2Old(iface);
+    FIXME("stub %p\n", services);
     return E_NOTIMPL;
 }
 
 static HRESULT WINAPI ITextDocument2Old_fnRedo(ITextDocument2Old *iface, LONG Count, LONG *prop)
 {
-    IRichEditOleImpl *This = impl_from_ITextDocument2Old(iface);
-    FIXME("stub %p\n",This);
+    struct text_services *services = impl_from_ITextDocument2Old(iface);
+    FIXME("stub %p\n", services);
     return E_NOTIMPL;
 }
 
-static HRESULT CreateITextRange(IRichEditOleImpl *reOle, LONG start, LONG end, ITextRange** ppRange)
+static HRESULT CreateITextRange(struct text_services *services, LONG start, LONG end, ITextRange** ppRange)
 {
     ITextRangeImpl *txtRge = heap_alloc(sizeof(ITextRangeImpl));
 
@@ -4346,10 +4252,10 @@ static HRESULT CreateITextRange(IRichEditOleImpl *reOle, LONG start, LONG end, I
         return E_OUTOFMEMORY;
     txtRge->ITextRange_iface.lpVtbl = &trvt;
     txtRge->ref = 1;
-    txtRge->child.reole = reOle;
+    txtRge->child.reole = services;
     txtRge->start = start;
     txtRge->end = end;
-    list_add_head(&reOle->rangelist, &txtRge->child.entry);
+    list_add_head( &services->rangelist, &txtRge->child.entry );
     *ppRange = &txtRge->ITextRange_iface;
     return S_OK;
 }
@@ -4357,84 +4263,84 @@ static HRESULT CreateITextRange(IRichEditOleImpl *reOle, LONG start, LONG end, I
 static HRESULT WINAPI ITextDocument2Old_fnRange(ITextDocument2Old *iface, LONG cp1, LONG cp2,
                                                 ITextRange **ppRange)
 {
-    IRichEditOleImpl *This = impl_from_ITextDocument2Old(iface);
+    struct text_services *services = impl_from_ITextDocument2Old(iface);
 
-    TRACE("%p %p %d %d\n", This, ppRange, cp1, cp2);
+    TRACE("%p %p %d %d\n", services, ppRange, cp1, cp2);
     if (!ppRange)
         return E_INVALIDARG;
 
-    cp2range(This->editor, &cp1, &cp2);
-    return CreateITextRange(This, cp1, cp2, ppRange);
+    cp2range(services->editor, &cp1, &cp2);
+    return CreateITextRange(services, cp1, cp2, ppRange);
 }
 
 static HRESULT WINAPI ITextDocument2Old_fnRangeFromPoint(ITextDocument2Old *iface, LONG x, LONG y,
                                                          ITextRange **ppRange)
 {
-    IRichEditOleImpl *This = impl_from_ITextDocument2Old(iface);
-    FIXME("stub %p\n",This);
+    struct text_services *services = impl_from_ITextDocument2Old(iface);
+    FIXME("stub %p\n", services);
     return E_NOTIMPL;
 }
 
 /* ITextDocument2Old methods */
 static HRESULT WINAPI ITextDocument2Old_fnAttachMsgFilter(ITextDocument2Old *iface, IUnknown *filter)
 {
-    IRichEditOleImpl *This = impl_from_ITextDocument2Old(iface);
+    struct text_services *services = impl_from_ITextDocument2Old(iface);
 
-    FIXME("(%p)->(%p): stub\n", This, filter);
+    FIXME("(%p)->(%p): stub\n", services, filter);
 
     return E_NOTIMPL;
 }
 
 static HRESULT WINAPI ITextDocument2Old_fnSetEffectColor(ITextDocument2Old *iface, LONG index, COLORREF cr)
 {
-    IRichEditOleImpl *This = impl_from_ITextDocument2Old(iface);
+    struct text_services *services = impl_from_ITextDocument2Old(iface);
 
-    FIXME("(%p)->(%d, 0x%x): stub\n", This, index, cr);
+    FIXME("(%p)->(%d, 0x%x): stub\n", services, index, cr);
 
     return E_NOTIMPL;
 }
 
 static HRESULT WINAPI ITextDocument2Old_fnGetEffectColor(ITextDocument2Old *iface, LONG index, COLORREF *cr)
 {
-    IRichEditOleImpl *This = impl_from_ITextDocument2Old(iface);
+    struct text_services *services = impl_from_ITextDocument2Old(iface);
 
-    FIXME("(%p)->(%d, %p): stub\n", This, index, cr);
+    FIXME("(%p)->(%d, %p): stub\n", services, index, cr);
 
     return E_NOTIMPL;
 }
 
 static HRESULT WINAPI ITextDocument2Old_fnGetCaretType(ITextDocument2Old *iface, LONG *type)
 {
-    IRichEditOleImpl *This = impl_from_ITextDocument2Old(iface);
+    struct text_services *services = impl_from_ITextDocument2Old(iface);
 
-    FIXME("(%p)->(%p): stub\n", This, type);
+    FIXME("(%p)->(%p): stub\n", services, type);
 
     return E_NOTIMPL;
 }
 
 static HRESULT WINAPI ITextDocument2Old_fnSetCaretType(ITextDocument2Old *iface, LONG type)
 {
-    IRichEditOleImpl *This = impl_from_ITextDocument2Old(iface);
+    struct text_services *services = impl_from_ITextDocument2Old(iface);
 
-    FIXME("(%p)->(%d): stub\n", This, type);
+    FIXME("(%p)->(%d): stub\n", services, type);
 
     return E_NOTIMPL;
 }
 
 static HRESULT WINAPI ITextDocument2Old_fnGetImmContext(ITextDocument2Old *iface, LONG *context)
 {
-    IRichEditOleImpl *This = impl_from_ITextDocument2Old(iface);
+    struct text_services *services = impl_from_ITextDocument2Old(iface);
 
-    FIXME("(%p)->(%p): stub\n", This, context);
+    FIXME("(%p)->(%p): stub\n", services, context);
 
     return E_NOTIMPL;
 }
 
 static HRESULT WINAPI ITextDocument2Old_fnReleaseImmContext(ITextDocument2Old *iface, LONG context)
 {
-    IRichEditOleImpl *This = impl_from_ITextDocument2Old(iface);
+    struct text_services *services = impl_from_ITextDocument2Old(iface);
 
-    FIXME("(%p)->(%d): stub\n", This, context);
+    FIXME("(%p)->(%d): stub\n", services, context);
 
     return E_NOTIMPL;
 }
@@ -4443,9 +4349,9 @@ static HRESULT WINAPI ITextDocument2Old_fnGetPreferredFont(ITextDocument2Old *if
                                                            LONG options, LONG current_charrep, LONG current_fontsize,
                                                            BSTR *bstr, LONG *pitch_family, LONG *new_fontsize)
 {
-    IRichEditOleImpl *This = impl_from_ITextDocument2Old(iface);
+    struct text_services *services = impl_from_ITextDocument2Old(iface);
 
-    FIXME("(%p)->(%d, %d, %d, %d, %d, %p, %p, %p): stub\n", This, cp, charrep, options, current_charrep,
+    FIXME("(%p)->(%d, %d, %d, %d, %d, %p, %p, %p): stub\n", services, cp, charrep, options, current_charrep,
           current_fontsize, bstr, pitch_family, new_fontsize);
 
     return E_NOTIMPL;
@@ -4453,18 +4359,18 @@ static HRESULT WINAPI ITextDocument2Old_fnGetPreferredFont(ITextDocument2Old *if
 
 static HRESULT WINAPI ITextDocument2Old_fnGetNotificationMode(ITextDocument2Old *iface, LONG *mode)
 {
-    IRichEditOleImpl *This = impl_from_ITextDocument2Old(iface);
+    struct text_services *services = impl_from_ITextDocument2Old(iface);
 
-    FIXME("(%p)->(%p): stub\n", This, mode);
+    FIXME("(%p)->(%p): stub\n", services, mode);
 
     return E_NOTIMPL;
 }
 
 static HRESULT WINAPI ITextDocument2Old_fnSetNotificationMode(ITextDocument2Old *iface, LONG mode)
 {
-    IRichEditOleImpl *This = impl_from_ITextDocument2Old(iface);
+    struct text_services *services = impl_from_ITextDocument2Old(iface);
 
-    FIXME("(%p)->(0x%x): stub\n", This, mode);
+    FIXME("(%p)->(0x%x): stub\n", services, mode);
 
     return E_NOTIMPL;
 }
@@ -4472,95 +4378,96 @@ static HRESULT WINAPI ITextDocument2Old_fnSetNotificationMode(ITextDocument2Old
 static HRESULT WINAPI ITextDocument2Old_fnGetClientRect(ITextDocument2Old *iface, LONG type, LONG *left, LONG *top,
                                                         LONG *right, LONG *bottom)
 {
-    IRichEditOleImpl *This = impl_from_ITextDocument2Old(iface);
+    struct text_services *services = impl_from_ITextDocument2Old(iface);
 
-    FIXME("(%p)->(%d, %p, %p, %p, %p): stub\n", This, type, left, top, right, bottom);
+    FIXME("(%p)->(%d, %p, %p, %p, %p): stub\n", services, type, left, top, right, bottom);
 
     return E_NOTIMPL;
 }
 
 static HRESULT WINAPI ITextDocument2Old_fnGetSelectionEx(ITextDocument2Old *iface, ITextSelection **selection)
 {
-    IRichEditOleImpl *This = impl_from_ITextDocument2Old(iface);
+    struct text_services *services = impl_from_ITextDocument2Old(iface);
 
-    FIXME("(%p)->(%p): stub\n", This, selection);
+    FIXME("(%p)->(%p): stub\n", services, selection);
 
     return E_NOTIMPL;
 }
 
 static HRESULT WINAPI ITextDocument2Old_fnGetWindow(ITextDocument2Old *iface, LONG *hwnd)
 {
-    IRichEditOleImpl *This = impl_from_ITextDocument2Old(iface);
+    struct text_services *services = impl_from_ITextDocument2Old(iface);
 
-    FIXME("(%p)->(%p): stub\n", This, hwnd);
+    FIXME("(%p)->(%p): stub\n", services, hwnd);
 
     return E_NOTIMPL;
 }
 
 static HRESULT WINAPI ITextDocument2Old_fnGetFEFlags(ITextDocument2Old *iface, LONG *flags)
 {
-    IRichEditOleImpl *This = impl_from_ITextDocument2Old(iface);
+    struct text_services *services = impl_from_ITextDocument2Old(iface);
 
-    FIXME("(%p)->(%p): stub\n", This, flags);
+    FIXME("(%p)->(%p): stub\n", services, flags);
 
     return E_NOTIMPL;
 }
 
 static HRESULT WINAPI ITextDocument2Old_fnUpdateWindow(ITextDocument2Old *iface)
 {
-    IRichEditOleImpl *This = impl_from_ITextDocument2Old(iface);
+    struct text_services *services = impl_from_ITextDocument2Old(iface);
 
-    FIXME("(%p): stub\n", This);
+    FIXME("(%p): stub\n", services);
 
     return E_NOTIMPL;
 }
 
 static HRESULT WINAPI ITextDocument2Old_fnCheckTextLimit(ITextDocument2Old *iface, LONG cch, LONG *exceed)
 {
-    IRichEditOleImpl *This = impl_from_ITextDocument2Old(iface);
+    struct text_services *services = impl_from_ITextDocument2Old(iface);
 
-    FIXME("(%p)->(%d, %p): stub\n", This, cch, exceed);
+    FIXME("(%p)->(%d, %p): stub\n", services, cch, exceed);
 
     return E_NOTIMPL;
 }
 
 static HRESULT WINAPI ITextDocument2Old_fnIMEInProgress(ITextDocument2Old *iface, LONG mode)
 {
-    IRichEditOleImpl *This = impl_from_ITextDocument2Old(iface);
+    struct text_services *services = impl_from_ITextDocument2Old(iface);
 
-    FIXME("(%p)->(0x%x): stub\n", This, mode);
+    FIXME("(%p)->(0x%x): stub\n", services, mode);
 
     return E_NOTIMPL;
 }
 
 static HRESULT WINAPI ITextDocument2Old_fnSysBeep(ITextDocument2Old *iface)
 {
-    IRichEditOleImpl *This = impl_from_ITextDocument2Old(iface);
+    struct text_services *services = impl_from_ITextDocument2Old(iface);
 
-    FIXME("(%p): stub\n", This);
+    FIXME("(%p): stub\n", services);
 
     return E_NOTIMPL;
 }
 
 static HRESULT WINAPI ITextDocument2Old_fnUpdate(ITextDocument2Old *iface, LONG mode)
 {
-    IRichEditOleImpl *This = impl_from_ITextDocument2Old(iface);
+    struct text_services *services = impl_from_ITextDocument2Old(iface);
 
-    FIXME("(%p)->(0x%x): stub\n", This, mode);
+    FIXME("(%p)->(0x%x): stub\n", services, mode);
 
     return E_NOTIMPL;
 }
 
 static HRESULT WINAPI ITextDocument2Old_fnNotify(ITextDocument2Old *iface, LONG notify)
 {
-    IRichEditOleImpl *This = impl_from_ITextDocument2Old(iface);
+    struct text_services *services = impl_from_ITextDocument2Old(iface);
 
-    FIXME("(%p)->(%d): stub\n", This, notify);
+    FIXME("(%p)->(%d): stub\n", services, notify);
 
     return E_NOTIMPL;
 }
 
-static const ITextDocument2OldVtbl tdvt = {
+const ITextDocument2OldVtbl text_doc2old_vtbl =
+{
     ITextDocument2Old_fnQueryInterface,
     ITextDocument2Old_fnAddRef,
     ITextDocument2Old_fnRelease,
@@ -4616,7 +4523,7 @@ static HRESULT WINAPI ITextSelection_fnQueryInterface(
     REFIID riid,
     void **ppvObj)
 {
-    ITextSelectionImpl *This = impl_from_ITextSelection(me);
+    struct text_selection *This = impl_from_ITextSelection(me);
 
     *ppvObj = NULL;
     if (IsEqualGUID(riid, &IID_IUnknown)
@@ -4630,7 +4537,7 @@ static HRESULT WINAPI ITextSelection_fnQueryInterface(
     }
     else if (IsEqualGUID(riid, &IID_Igetrichole))
     {
-        *ppvObj = This->reOle;
+        *ppvObj = This->services;
         return S_OK;
     }
 
@@ -4639,13 +4546,13 @@ static HRESULT WINAPI ITextSelection_fnQueryInterface(
 
 static ULONG WINAPI ITextSelection_fnAddRef(ITextSelection *me)
 {
-    ITextSelectionImpl *This = impl_from_ITextSelection(me);
+    struct text_selection *This = impl_from_ITextSelection(me);
     return InterlockedIncrement(&This->ref);
 }
 
 static ULONG WINAPI ITextSelection_fnRelease(ITextSelection *me)
 {
-    ITextSelectionImpl *This = impl_from_ITextSelection(me);
+    struct text_selection *This = impl_from_ITextSelection(me);
     ULONG ref = InterlockedDecrement(&This->ref);
     if (ref == 0)
         heap_free(This);
@@ -4654,7 +4561,7 @@ static ULONG WINAPI ITextSelection_fnRelease(ITextSelection *me)
 
 static HRESULT WINAPI ITextSelection_fnGetTypeInfoCount(ITextSelection *me, UINT *pctinfo)
 {
-    ITextSelectionImpl *This = impl_from_ITextSelection(me);
+    struct text_selection *This = impl_from_ITextSelection(me);
     TRACE("(%p)->(%p)\n", This, pctinfo);
     *pctinfo = 1;
     return S_OK;
@@ -4663,7 +4570,7 @@ static HRESULT WINAPI ITextSelection_fnGetTypeInfoCount(ITextSelection *me, UINT
 static HRESULT WINAPI ITextSelection_fnGetTypeInfo(ITextSelection *me, UINT iTInfo, LCID lcid,
     ITypeInfo **ppTInfo)
 {
-    ITextSelectionImpl *This = impl_from_ITextSelection(me);
+    struct text_selection *This = impl_from_ITextSelection(me);
     HRESULT hr;
 
     TRACE("(%p)->(%u,%d,%p)\n", This, iTInfo, lcid, ppTInfo);
@@ -4677,7 +4584,7 @@ static HRESULT WINAPI ITextSelection_fnGetTypeInfo(ITextSelection *me, UINT iTIn
 static HRESULT WINAPI ITextSelection_fnGetIDsOfNames(ITextSelection *me, REFIID riid,
     LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
 {
-    ITextSelectionImpl *This = impl_from_ITextSelection(me);
+    struct text_selection *This = impl_from_ITextSelection(me);
     ITypeInfo *ti;
     HRESULT hr;
 
@@ -4701,7 +4608,7 @@ static HRESULT WINAPI ITextSelection_fnInvoke(
     EXCEPINFO *pExcepInfo,
     UINT *puArgErr)
 {
-    ITextSelectionImpl *This = impl_from_ITextSelection(me);
+    struct text_selection *This = impl_from_ITextSelection(me);
     ITypeInfo *ti;
     HRESULT hr;
 
@@ -4717,20 +4624,20 @@ static HRESULT WINAPI ITextSelection_fnInvoke(
 /*** ITextRange methods ***/
 static HRESULT WINAPI ITextSelection_fnGetText(ITextSelection *me, BSTR *pbstr)
 {
-    ITextSelectionImpl *This = impl_from_ITextSelection(me);
+    struct text_selection *This = impl_from_ITextSelection(me);
     ME_Cursor *start = NULL, *end = NULL;
     int nChars, endOfs;
     BOOL bEOP;
 
     TRACE("(%p)->(%p)\n", This, pbstr);
 
-    if (!This->reOle)
+    if (!This->services)
         return CO_E_RELEASED;
 
     if (!pbstr)
         return E_INVALIDARG;
 
-    ME_GetSelection(This->reOle->editor, &start, &end);
+    ME_GetSelection(This->services->editor, &start, &end);
     endOfs = ME_GetCursorOfs(end);
     nChars = endOfs - ME_GetCursorOfs(start);
     if (!nChars)
@@ -4743,8 +4650,8 @@ static HRESULT WINAPI ITextSelection_fnGetText(ITextSelection *me, BSTR *pbstr)
     if (!*pbstr)
         return E_OUTOFMEMORY;
 
-    bEOP = (!para_next( para_next( end->para ) ) && endOfs > ME_GetTextLength(This->reOle->editor));
-    ME_GetTextW(This->reOle->editor, *pbstr, nChars, start, nChars, FALSE, bEOP);
+    bEOP = (!para_next( para_next( end->para ) ) && endOfs > ME_GetTextLength(This->services->editor));
+    ME_GetTextW(This->services->editor, *pbstr, nChars, start, nChars, FALSE, bEOP);
     TRACE("%s\n", wine_dbgstr_w(*pbstr));
 
     return S_OK;
@@ -4752,50 +4659,50 @@ static HRESULT WINAPI ITextSelection_fnGetText(ITextSelection *me, BSTR *pbstr)
 
 static HRESULT WINAPI ITextSelection_fnSetText(ITextSelection *me, BSTR str)
 {
-    ITextSelectionImpl *This = impl_from_ITextSelection(me);
+    struct text_selection *This = impl_from_ITextSelection(me);
     ME_TextEditor *editor;
     int len, to, from;
 
     TRACE("(%p)->(%s)\n", This, debugstr_w(str));
 
-    if (!This->reOle)
+    if (!This->services)
         return CO_E_RELEASED;
 
-    editor = This->reOle->editor;
+    editor = This->services->editor;
     len = lstrlenW(str);
     ME_GetSelectionOfs(editor, &from, &to);
     ME_ReplaceSel(editor, FALSE, str, len);
 
     if (len < to - from)
-        textranges_update_ranges(This->reOle, from, len, RANGE_UPDATE_DELETE);
+        textranges_update_ranges(This->services, from, len, RANGE_UPDATE_DELETE);
 
     return S_OK;
 }
 
 static HRESULT WINAPI ITextSelection_fnGetChar(ITextSelection *me, LONG *pch)
 {
-    ITextSelectionImpl *This = impl_from_ITextSelection(me);
+    struct text_selection *This = impl_from_ITextSelection(me);
     ME_Cursor *start = NULL, *end = NULL;
 
     TRACE("(%p)->(%p)\n", This, pch);
 
-    if (!This->reOle)
+    if (!This->services)
         return CO_E_RELEASED;
 
     if (!pch)
         return E_INVALIDARG;
 
-    ME_GetSelection(This->reOle->editor, &start, &end);
-    return range_GetChar(This->reOle->editor, start, pch);
+    ME_GetSelection(This->services->editor, &start, &end);
+    return range_GetChar(This->services->editor, start, pch);
 }
 
 static HRESULT WINAPI ITextSelection_fnSetChar(ITextSelection *me, LONG ch)
 {
-    ITextSelectionImpl *This = impl_from_ITextSelection(me);
+    struct text_selection *This = impl_from_ITextSelection(me);
 
     FIXME("(%p)->(%x): stub\n", This, ch);
 
-    if (!This->reOle)
+    if (!This->services)
         return CO_E_RELEASED;
 
     return E_NOTIMPL;
@@ -4803,12 +4710,12 @@ static HRESULT WINAPI ITextSelection_fnSetChar(ITextSelection *me, LONG ch)
 
 static HRESULT WINAPI ITextSelection_fnGetDuplicate(ITextSelection *me, ITextRange **range)
 {
-    ITextSelectionImpl *This = impl_from_ITextSelection(me);
+    struct text_selection *This = impl_from_ITextSelection(me);
     LONG start, end;
 
     TRACE("(%p)->(%p)\n", This, range);
 
-    if (!This->reOle)
+    if (!This->services)
         return CO_E_RELEASED;
 
     if (!range)
@@ -4816,16 +4723,16 @@ static HRESULT WINAPI ITextSelection_fnGetDuplicate(ITextSelection *me, ITextRan
 
     ITextSelection_GetStart(me, &start);
     ITextSelection_GetEnd(me, &end);
-    return CreateITextRange(This->reOle, start, end, range);
+    return CreateITextRange(This->services, start, end, range);
 }
 
 static HRESULT WINAPI ITextSelection_fnGetFormattedText(ITextSelection *me, ITextRange **range)
 {
-    ITextSelectionImpl *This = impl_from_ITextSelection(me);
+    struct text_selection *This = impl_from_ITextSelection(me);
 
     FIXME("(%p)->(%p): stub\n", This, range);
 
-    if (!This->reOle)
+    if (!This->services)
         return CO_E_RELEASED;
 
     return E_NOTIMPL;
@@ -4833,11 +4740,11 @@ static HRESULT WINAPI ITextSelection_fnGetFormattedText(ITextSelection *me, ITex
 
 static HRESULT WINAPI ITextSelection_fnSetFormattedText(ITextSelection *me, ITextRange *range)
 {
-    ITextSelectionImpl *This = impl_from_ITextSelection(me);
+    struct text_selection *This = impl_from_ITextSelection(me);
 
     FIXME("(%p)->(%p): stub\n", This, range);
 
-    if (!This->reOle)
+    if (!This->services)
         return CO_E_RELEASED;
 
     FIXME("not implemented\n");
@@ -4846,83 +4753,83 @@ static HRESULT WINAPI ITextSelection_fnSetFormattedText(ITextSelection *me, ITex
 
 static HRESULT WINAPI ITextSelection_fnGetStart(ITextSelection *me, LONG *pcpFirst)
 {
-    ITextSelectionImpl *This = impl_from_ITextSelection(me);
+    struct text_selection *This = impl_from_ITextSelection(me);
     LONG lim;
 
     TRACE("(%p)->(%p)\n", This, pcpFirst);
 
-    if (!This->reOle)
+    if (!This->services)
         return CO_E_RELEASED;
 
     if (!pcpFirst)
         return E_INVALIDARG;
-    ME_GetSelectionOfs(This->reOle->editor, pcpFirst, &lim);
+    ME_GetSelectionOfs(This->services->editor, pcpFirst, &lim);
     return S_OK;
 }
 
 static HRESULT WINAPI ITextSelection_fnSetStart(ITextSelection *me, LONG value)
 {
-    ITextSelectionImpl *This = impl_from_ITextSelection(me);
+    struct text_selection *This = impl_from_ITextSelection(me);
     LONG start, end;
     HRESULT hr;
 
     TRACE("(%p)->(%d)\n", This, value);
 
-    if (!This->reOle)
+    if (!This->services)
         return CO_E_RELEASED;
 
-    ME_GetSelectionOfs(This->reOle->editor, &start, &end);
-    hr = textrange_setstart(This->reOle, value, &start, &end);
+    ME_GetSelectionOfs(This->services->editor, &start, &end);
+    hr = textrange_setstart(This->services, value, &start, &end);
     if (hr == S_OK)
-        set_selection(This->reOle->editor, start, end);
+        set_selection(This->services->editor, start, end);
 
     return hr;
 }
 
 static HRESULT WINAPI ITextSelection_fnGetEnd(ITextSelection *me, LONG *pcpLim)
 {
-    ITextSelectionImpl *This = impl_from_ITextSelection(me);
+    struct text_selection *This = impl_from_ITextSelection(me);
     LONG first;
 
     TRACE("(%p)->(%p)\n", This, pcpLim);
 
-    if (!This->reOle)
+    if (!This->services)
         return CO_E_RELEASED;
 
     if (!pcpLim)
         return E_INVALIDARG;
-    ME_GetSelectionOfs(This->reOle->editor, &first, pcpLim);
+    ME_GetSelectionOfs(This->services->editor, &first, pcpLim);
     return S_OK;
 }
 
 static HRESULT WINAPI ITextSelection_fnSetEnd(ITextSelection *me, LONG value)
 {
-    ITextSelectionImpl *This = impl_from_ITextSelection(me);
+    struct text_selection *This = impl_from_ITextSelection(me);
     LONG start, end;
     HRESULT hr;
 
     TRACE("(%p)->(%d)\n", This, value);
 
-    if (!This->reOle)
+    if (!This->services)
         return CO_E_RELEASED;
 
-    ME_GetSelectionOfs(This->reOle->editor, &start, &end);
-    hr = textrange_setend(This->reOle, value, &start, &end);
+    ME_GetSelectionOfs(This->services->editor, &start, &end);
+    hr = textrange_setend(This->services, value, &start, &end);
     if (hr == S_OK)
-        set_selection(This->reOle->editor, start, end);
+        set_selection(This->services->editor, start, end);
 
     return hr;
 }
 
 static HRESULT WINAPI ITextSelection_fnGetFont(ITextSelection *me, ITextFont **font)
 {
-    ITextSelectionImpl *This = impl_from_ITextSelection(me);
+    struct text_selection *This = impl_from_ITextSelection(me);
     ITextRange *range = NULL;
     HRESULT hr;
 
     TRACE("(%p)->(%p)\n", This, font);
 
-    if (!This->reOle)
+    if (!This->services)
         return CO_E_RELEASED;
 
     if (!font)
@@ -4936,7 +4843,7 @@ static HRESULT WINAPI ITextSelection_fnGetFont(ITextSelection *me, ITextFont **f
 
 static HRESULT WINAPI ITextSelection_fnSetFont(ITextSelection *me, ITextFont *font)
 {
-    ITextSelectionImpl *This = impl_from_ITextSelection(me);
+    struct text_selection *This = impl_from_ITextSelection(me);
     ITextRange *range = NULL;
 
     TRACE("(%p)->(%p)\n", This, font);
@@ -4944,7 +4851,7 @@ static HRESULT WINAPI ITextSelection_fnSetFont(ITextSelection *me, ITextFont *fo
     if (!font)
         return E_INVALIDARG;
 
-    if (!This->reOle)
+    if (!This->services)
         return CO_E_RELEASED;
 
     ITextSelection_QueryInterface(me, &IID_ITextRange, (void**)&range);
@@ -4955,13 +4862,13 @@ static HRESULT WINAPI ITextSelection_fnSetFont(ITextSelection *me, ITextFont *fo
 
 static HRESULT WINAPI ITextSelection_fnGetPara(ITextSelection *me, ITextPara **para)
 {
-    ITextSelectionImpl *This = impl_from_ITextSelection(me);
+    struct text_selection *This = impl_from_ITextSelection(me);
     ITextRange *range = NULL;
     HRESULT hr;
 
     TRACE("(%p)->(%p)\n", This, para);
 
-    if (!This->reOle)
+    if (!This->services)
         return CO_E_RELEASED;
 
     if (!para)
@@ -4975,11 +4882,11 @@ static HRESULT WINAPI ITextSelection_fnGetPara(ITextSelection *me, ITextPara **p
 
 static HRESULT WINAPI ITextSelection_fnSetPara(ITextSelection *me, ITextPara *para)
 {
-    ITextSelectionImpl *This = impl_from_ITextSelection(me);
+    struct text_selection *This = impl_from_ITextSelection(me);
 
     FIXME("(%p)->(%p): stub\n", This, para);
 
-    if (!This->reOle)
+    if (!This->services)
         return CO_E_RELEASED;
 
     FIXME("not implemented\n");
@@ -4988,23 +4895,23 @@ static HRESULT WINAPI ITextSelection_fnSetPara(ITextSelection *me, ITextPara *pa
 
 static HRESULT WINAPI ITextSelection_fnGetStoryLength(ITextSelection *me, LONG *length)
 {
-    ITextSelectionImpl *This = impl_from_ITextSelection(me);
+    struct text_selection *This = impl_from_ITextSelection(me);
 
     TRACE("(%p)->(%p)\n", This, length);
 
-    if (!This->reOle)
+    if (!This->services)
         return CO_E_RELEASED;
 
-    return textrange_get_storylength(This->reOle->editor, length);
+    return textrange_get_storylength(This->services->editor, length);
 }
 
 static HRESULT WINAPI ITextSelection_fnGetStoryType(ITextSelection *me, LONG *value)
 {
-    ITextSelectionImpl *This = impl_from_ITextSelection(me);
+    struct text_selection *This = impl_from_ITextSelection(me);
 
     TRACE("(%p)->(%p)\n", This, value);
 
-    if (!This->reOle)
+    if (!This->services)
         return CO_E_RELEASED;
 
     if (!value)
@@ -5016,31 +4923,31 @@ static HRESULT WINAPI ITextSelection_fnGetStoryType(ITextSelection *me, LONG *va
 
 static HRESULT WINAPI ITextSelection_fnCollapse(ITextSelection *me, LONG bStart)
 {
-    ITextSelectionImpl *This = impl_from_ITextSelection(me);
+    struct text_selection *This = impl_from_ITextSelection(me);
     LONG start, end;
     HRESULT hres;
 
     TRACE("(%p)->(%d)\n", This, bStart);
 
-    if (!This->reOle)
+    if (!This->services)
         return CO_E_RELEASED;
 
-    ME_GetSelectionOfs(This->reOle->editor, &start, &end);
+    ME_GetSelectionOfs(This->services->editor, &start, &end);
     hres = range_Collapse(bStart, &start, &end);
     if (SUCCEEDED(hres))
-        set_selection(This->reOle->editor, start, end);
+        set_selection(This->services->editor, start, end);
     return hres;
 }
 
 static HRESULT WINAPI ITextSelection_fnExpand(ITextSelection *me, LONG unit, LONG *delta)
 {
-    ITextSelectionImpl *This = impl_from_ITextSelection(me);
+    struct text_selection *This = impl_from_ITextSelection(me);
     ITextRange *range = NULL;
     HRESULT hr;
 
     TRACE("(%p)->(%d %p)\n", This, unit, delta);
 
-    if (!This->reOle)
+    if (!This->services)
         return CO_E_RELEASED;
 
     ITextSelection_QueryInterface(me, &IID_ITextRange, (void**)&range);
@@ -5051,11 +4958,11 @@ static HRESULT WINAPI ITextSelection_fnExpand(ITextSelection *me, LONG unit, LON
 
 static HRESULT WINAPI ITextSelection_fnGetIndex(ITextSelection *me, LONG unit, LONG *index)
 {
-    ITextSelectionImpl *This = impl_from_ITextSelection(me);
+    struct text_selection *This = impl_from_ITextSelection(me);
 
     FIXME("(%p)->(%d %p): stub\n", This, unit, index);
 
-    if (!This->reOle)
+    if (!This->services)
         return CO_E_RELEASED;
 
     return E_NOTIMPL;
@@ -5064,11 +4971,11 @@ static HRESULT WINAPI ITextSelection_fnGetIndex(ITextSelection *me, LONG unit, L
 static HRESULT WINAPI ITextSelection_fnSetIndex(ITextSelection *me, LONG unit, LONG index,
     LONG extend)
 {
-    ITextSelectionImpl *This = impl_from_ITextSelection(me);
+    struct text_selection *This = impl_from_ITextSelection(me);
 
     FIXME("(%p)->(%d %d %d): stub\n", This, unit, index, extend);
 
-    if (!This->reOle)
+    if (!This->services)
         return CO_E_RELEASED;
 
     return E_NOTIMPL;
@@ -5076,11 +4983,11 @@ static HRESULT WINAPI ITextSelection_fnSetIndex(ITextSelection *me, LONG unit, L
 
 static HRESULT WINAPI ITextSelection_fnSetRange(ITextSelection *me, LONG anchor, LONG active)
 {
-    ITextSelectionImpl *This = impl_from_ITextSelection(me);
+    struct text_selection *This = impl_from_ITextSelection(me);
 
     FIXME("(%p)->(%d %d): stub\n", This, anchor, active);
 
-    if (!This->reOle)
+    if (!This->services)
         return CO_E_RELEASED;
 
     return E_NOTIMPL;
@@ -5088,7 +4995,7 @@ static HRESULT WINAPI ITextSelection_fnSetRange(ITextSelection *me, LONG anchor,
 
 static HRESULT WINAPI ITextSelection_fnInRange(ITextSelection *me, ITextRange *range, LONG *ret)
 {
-    ITextSelectionImpl *This = impl_from_ITextSelection(me);
+    struct text_selection *This = impl_from_ITextSelection(me);
     ITextSelection *selection = NULL;
     LONG start, end;
 
@@ -5097,7 +5004,7 @@ static HRESULT WINAPI ITextSelection_fnInRange(ITextSelection *me, ITextRange *r
     if (ret)
         *ret = tomFalse;
 
-    if (!This->reOle)
+    if (!This->services)
         return CO_E_RELEASED;
 
     if (!range)
@@ -5115,11 +5022,11 @@ static HRESULT WINAPI ITextSelection_fnInRange(ITextSelection *me, ITextRange *r
 
 static HRESULT WINAPI ITextSelection_fnInStory(ITextSelection *me, ITextRange *range, LONG *ret)
 {
-    ITextSelectionImpl *This = impl_from_ITextSelection(me);
+    struct text_selection *This = impl_from_ITextSelection(me);
 
     FIXME("(%p)->(%p %p): stub\n", This, range, ret);
 
-    if (!This->reOle)
+    if (!This->services)
         return CO_E_RELEASED;
 
     return E_NOTIMPL;
@@ -5127,7 +5034,7 @@ static HRESULT WINAPI ITextSelection_fnInStory(ITextSelection *me, ITextRange *r
 
 static HRESULT WINAPI ITextSelection_fnIsEqual(ITextSelection *me, ITextRange *range, LONG *ret)
 {
-    ITextSelectionImpl *This = impl_from_ITextSelection(me);
+    struct text_selection *This = impl_from_ITextSelection(me);
     ITextSelection *selection = NULL;
     LONG start, end;
 
@@ -5136,7 +5043,7 @@ static HRESULT WINAPI ITextSelection_fnIsEqual(ITextSelection *me, ITextRange *r
     if (ret)
         *ret = tomFalse;
 
-    if (!This->reOle)
+    if (!This->services)
         return CO_E_RELEASED;
 
     if (!range)
@@ -5154,11 +5061,11 @@ static HRESULT WINAPI ITextSelection_fnIsEqual(ITextSelection *me, ITextRange *r
 
 static HRESULT WINAPI ITextSelection_fnSelect(ITextSelection *me)
 {
-    ITextSelectionImpl *This = impl_from_ITextSelection(me);
+    struct text_selection *This = impl_from_ITextSelection(me);
 
     TRACE("(%p)\n", This);
 
-    if (!This->reOle)
+    if (!This->services)
         return CO_E_RELEASED;
 
     /* nothing to do */
@@ -5168,13 +5075,13 @@ static HRESULT WINAPI ITextSelection_fnSelect(ITextSelection *me)
 static HRESULT WINAPI ITextSelection_fnStartOf(ITextSelection *me, LONG unit, LONG extend,
     LONG *delta)
 {
-    ITextSelectionImpl *This = impl_from_ITextSelection(me);
+    struct text_selection *This = impl_from_ITextSelection(me);
     ITextRange *range = NULL;
     HRESULT hr;
 
     TRACE("(%p)->(%d %d %p)\n", This, unit, extend, delta);
 
-    if (!This->reOle)
+    if (!This->services)
         return CO_E_RELEASED;
 
     ITextSelection_QueryInterface(me, &IID_ITextRange, (void**)&range);
@@ -5186,34 +5093,34 @@ static HRESULT WINAPI ITextSelection_fnStartOf(ITextSelection *me, LONG unit, LO
 static HRESULT WINAPI ITextSelection_fnEndOf(ITextSelection *me, LONG unit, LONG extend,
     LONG *delta)
 {
-    ITextSelectionImpl *This = impl_from_ITextSelection(me);
+    struct text_selection *This = impl_from_ITextSelection(me);
     ITextRange *range = NULL;
     HRESULT hr;
 
     TRACE("(%p)->(%d %d %p)\n", This, unit, extend, delta);
 
-    if (!This->reOle)
+    if (!This->services)
         return CO_E_RELEASED;
 
     ITextSelection_QueryInterface(me, &IID_ITextRange, (void**)&range);
-    hr = textrange_endof(range, This->reOle->editor, unit, extend, delta);
+    hr = textrange_endof(range, This->services->editor, unit, extend, delta);
     ITextRange_Release(range);
     return hr;
 }
 
 static HRESULT WINAPI ITextSelection_fnMove(ITextSelection *me, LONG unit, LONG count, LONG *delta)
 {
-    ITextSelectionImpl *This = impl_from_ITextSelection(me);
+    struct text_selection *This = impl_from_ITextSelection(me);
     ITextRange *range = NULL;
     HRESULT hr;
 
     TRACE("(%p)->(%d %d %p)\n", This, unit, count, delta);
 
-    if (!This->reOle)
+    if (!This->services)
         return CO_E_RELEASED;
 
     ITextSelection_QueryInterface(me, &IID_ITextRange, (void**)&range);
-    hr = textrange_movestart(range, This->reOle->editor, unit, count, delta);
+    hr = textrange_movestart(range, This->services->editor, unit, count, delta);
     ITextRange_Release(range);
     return hr;
 }
@@ -5221,17 +5128,17 @@ static HRESULT WINAPI ITextSelection_fnMove(ITextSelection *me, LONG unit, LONG
 static HRESULT WINAPI ITextSelection_fnMoveStart(ITextSelection *me, LONG unit, LONG count,
     LONG *delta)
 {
-    ITextSelectionImpl *This = impl_from_ITextSelection(me);
+    struct text_selection *This = impl_from_ITextSelection(me);
     ITextRange *range = NULL;
     HRESULT hr;
 
     TRACE("(%p)->(%d %d %p)\n", This, unit, count, delta);
 
-    if (!This->reOle)
+    if (!This->services)
         return CO_E_RELEASED;
 
     ITextSelection_QueryInterface(me, &IID_ITextRange, (void**)&range);
-    hr = textrange_movestart(range, This->reOle->editor, unit, count, delta);
+    hr = textrange_movestart(range, This->services->editor, unit, count, delta);
     ITextRange_Release(range);
     return hr;
 }
@@ -5239,17 +5146,17 @@ static HRESULT WINAPI ITextSelection_fnMoveStart(ITextSelection *me, LONG unit,
 static HRESULT WINAPI ITextSelection_fnMoveEnd(ITextSelection *me, LONG unit, LONG count,
     LONG *delta)
 {
-    ITextSelectionImpl *This = impl_from_ITextSelection(me);
+    struct text_selection *This = impl_from_ITextSelection(me);
     ITextRange *range = NULL;
     HRESULT hr;
 
     TRACE("(%p)->(%d %d %p)\n", This, unit, count, delta);
 
-    if (!This->reOle)
+    if (!This->services)
         return CO_E_RELEASED;
 
     ITextSelection_QueryInterface(me, &IID_ITextRange, (void**)&range);
-    hr = textrange_moveend(range, This->reOle->editor, unit, count, delta);
+    hr = textrange_moveend(range, This->services->editor, unit, count, delta);
     ITextRange_Release(range);
     return hr;
 }
@@ -5257,11 +5164,11 @@ static HRESULT WINAPI ITextSelection_fnMoveEnd(ITextSelection *me, LONG unit, LO
 static HRESULT WINAPI ITextSelection_fnMoveWhile(ITextSelection *me, VARIANT *charset, LONG count,
     LONG *delta)
 {
-    ITextSelectionImpl *This = impl_from_ITextSelection(me);
+    struct text_selection *This = impl_from_ITextSelection(me);
 
     FIXME("(%p)->(%s %d %p): stub\n", This, debugstr_variant(charset), count, delta);
 
-    if (!This->reOle)
+    if (!This->services)
         return CO_E_RELEASED;
 
     return E_NOTIMPL;
@@ -5270,11 +5177,11 @@ static HRESULT WINAPI ITextSelection_fnMoveWhile(ITextSelection *me, VARIANT *ch
 static HRESULT WINAPI ITextSelection_fnMoveStartWhile(ITextSelection *me, VARIANT *charset, LONG count,
     LONG *delta)
 {
-    ITextSelectionImpl *This = impl_from_ITextSelection(me);
+    struct text_selection *This = impl_from_ITextSelection(me);
 
     FIXME("(%p)->(%s %d %p): stub\n", This, debugstr_variant(charset), count, delta);
 
-    if (!This->reOle)
+    if (!This->services)
         return CO_E_RELEASED;
 
     return E_NOTIMPL;
@@ -5283,11 +5190,11 @@ static HRESULT WINAPI ITextSelection_fnMoveStartWhile(ITextSelection *me, VARIAN
 static HRESULT WINAPI ITextSelection_fnMoveEndWhile(ITextSelection *me, VARIANT *charset, LONG count,
     LONG *delta)
 {
-    ITextSelectionImpl *This = impl_from_ITextSelection(me);
+    struct text_selection *This = impl_from_ITextSelection(me);
 
     FIXME("(%p)->(%s %d %p): stub\n", This, debugstr_variant(charset), count, delta);
 
-    if (!This->reOle)
+    if (!This->services)
         return CO_E_RELEASED;
 
     return E_NOTIMPL;
@@ -5296,11 +5203,11 @@ static HRESULT WINAPI ITextSelection_fnMoveEndWhile(ITextSelection *me, VARIANT
 static HRESULT WINAPI ITextSelection_fnMoveUntil(ITextSelection *me, VARIANT *charset, LONG count,
     LONG *delta)
 {
-    ITextSelectionImpl *This = impl_from_ITextSelection(me);
+    struct text_selection *This = impl_from_ITextSelection(me);
 
     FIXME("(%p)->(%s %d %p): stub\n", This, debugstr_variant(charset), count, delta);
 
-    if (!This->reOle)
+    if (!This->services)
         return CO_E_RELEASED;
 
     return E_NOTIMPL;
@@ -5309,11 +5216,11 @@ static HRESULT WINAPI ITextSelection_fnMoveUntil(ITextSelection *me, VARIANT *ch
 static HRESULT WINAPI ITextSelection_fnMoveStartUntil(ITextSelection *me, VARIANT *charset, LONG count,
     LONG *delta)
 {
-    ITextSelectionImpl *This = impl_from_ITextSelection(me);
+    struct text_selection *This = impl_from_ITextSelection(me);
 
     FIXME("(%p)->(%s %d %p): stub\n", This, debugstr_variant(charset), count, delta);
 
-    if (!This->reOle)
+    if (!This->services)
         return CO_E_RELEASED;
 
     return E_NOTIMPL;
@@ -5322,11 +5229,11 @@ static HRESULT WINAPI ITextSelection_fnMoveStartUntil(ITextSelection *me, VARIAN
 static HRESULT WINAPI ITextSelection_fnMoveEndUntil(ITextSelection *me, VARIANT *charset, LONG count,
     LONG *delta)
 {
-    ITextSelectionImpl *This = impl_from_ITextSelection(me);
+    struct text_selection *This = impl_from_ITextSelection(me);
 
     FIXME("(%p)->(%s %d %p): stub\n", This, debugstr_variant(charset), count, delta);
 
-    if (!This->reOle)
+    if (!This->services)
         return CO_E_RELEASED;
 
     return E_NOTIMPL;
@@ -5335,11 +5242,11 @@ static HRESULT WINAPI ITextSelection_fnMoveEndUntil(ITextSelection *me, VARIANT
 static HRESULT WINAPI ITextSelection_fnFindText(ITextSelection *me, BSTR text, LONG count, LONG flags,
     LONG *length)
 {
-    ITextSelectionImpl *This = impl_from_ITextSelection(me);
+    struct text_selection *This = impl_from_ITextSelection(me);
 
     FIXME("(%p)->(%s %d %x %p): stub\n", This, debugstr_w(text), count, flags, length);
 
-    if (!This->reOle)
+    if (!This->services)
         return CO_E_RELEASED;
 
     FIXME("not implemented\n");
@@ -5349,11 +5256,11 @@ static HRESULT WINAPI ITextSelection_fnFindText(ITextSelection *me, BSTR text, L
 static HRESULT WINAPI ITextSelection_fnFindTextStart(ITextSelection *me, BSTR text, LONG count,
     LONG flags, LONG *length)
 {
-    ITextSelectionImpl *This = impl_from_ITextSelection(me);
+    struct text_selection *This = impl_from_ITextSelection(me);
 
     FIXME("(%p)->(%s %d %x %p): stub\n", This, debugstr_w(text), count, flags, length);
 
-    if (!This->reOle)
+    if (!This->services)
         return CO_E_RELEASED;
 
     return E_NOTIMPL;
@@ -5362,11 +5269,11 @@ static HRESULT WINAPI ITextSelection_fnFindTextStart(ITextSelection *me, BSTR te
 static HRESULT WINAPI ITextSelection_fnFindTextEnd(ITextSelection *me, BSTR text, LONG count,
     LONG flags, LONG *length)
 {
-    ITextSelectionImpl *This = impl_from_ITextSelection(me);
+    struct text_selection *This = impl_from_ITextSelection(me);
 
     FIXME("(%p)->(%s %d %x %p): stub\n", This, debugstr_w(text), count, flags, length);
 
-    if (!This->reOle)
+    if (!This->services)
         return CO_E_RELEASED;
 
     return E_NOTIMPL;
@@ -5375,11 +5282,11 @@ static HRESULT WINAPI ITextSelection_fnFindTextEnd(ITextSelection *me, BSTR text
 static HRESULT WINAPI ITextSelection_fnDelete(ITextSelection *me, LONG unit, LONG count,
     LONG *delta)
 {
-    ITextSelectionImpl *This = impl_from_ITextSelection(me);
+    struct text_selection *This = impl_from_ITextSelection(me);
 
     FIXME("(%p)->(%d %d %p): stub\n", This, unit, count, delta);
 
-    if (!This->reOle)
+    if (!This->services)
         return CO_E_RELEASED;
 
     return E_NOTIMPL;
@@ -5387,45 +5294,45 @@ static HRESULT WINAPI ITextSelection_fnDelete(ITextSelection *me, LONG unit, LON
 
 static HRESULT WINAPI ITextSelection_fnCut(ITextSelection *me, VARIANT *v)
 {
-    ITextSelectionImpl *This = impl_from_ITextSelection(me);
+    struct text_selection *This = impl_from_ITextSelection(me);
     ITextRange *range = NULL;
     HRESULT hr;
 
     TRACE("(%p)->(%p): stub\n", This, v);
 
-    if (!This->reOle)
+    if (!This->services)
         return CO_E_RELEASED;
 
     ITextSelection_QueryInterface(me, &IID_ITextRange, (void**)&range);
-    hr = textrange_copy_or_cut(range, This->reOle->editor, TRUE, v);
+    hr = textrange_copy_or_cut(range, This->services->editor, TRUE, v);
     ITextRange_Release(range);
     return hr;
 }
 
 static HRESULT WINAPI ITextSelection_fnCopy(ITextSelection *me, VARIANT *v)
 {
-    ITextSelectionImpl *This = impl_from_ITextSelection(me);
+    struct text_selection *This = impl_from_ITextSelection(me);
     ITextRange *range = NULL;
     HRESULT hr;
 
     TRACE("(%p)->(%p)\n", This, v);
 
-    if (!This->reOle)
+    if (!This->services)
         return CO_E_RELEASED;
 
     ITextSelection_QueryInterface(me, &IID_ITextRange, (void**)&range);
-    hr = textrange_copy_or_cut(range, This->reOle->editor, FALSE, v);
+    hr = textrange_copy_or_cut(range, This->services->editor, FALSE, v);
     ITextRange_Release(range);
     return hr;
 }
 
 static HRESULT WINAPI ITextSelection_fnPaste(ITextSelection *me, VARIANT *v, LONG format)
 {
-    ITextSelectionImpl *This = impl_from_ITextSelection(me);
+    struct text_selection *This = impl_from_ITextSelection(me);
 
     FIXME("(%p)->(%s %x): stub\n", This, debugstr_variant(v), format);
 
-    if (!This->reOle)
+    if (!This->services)
         return CO_E_RELEASED;
 
     return E_NOTIMPL;
@@ -5434,11 +5341,11 @@ static HRESULT WINAPI ITextSelection_fnPaste(ITextSelection *me, VARIANT *v, LON
 static HRESULT WINAPI ITextSelection_fnCanPaste(ITextSelection *me, VARIANT *v, LONG format,
     LONG *ret)
 {
-    ITextSelectionImpl *This = impl_from_ITextSelection(me);
+    struct text_selection *This = impl_from_ITextSelection(me);
 
     FIXME("(%p)->(%s %x %p): stub\n", This, debugstr_variant(v), format, ret);
 
-    if (!This->reOle)
+    if (!This->services)
         return CO_E_RELEASED;
 
     return E_NOTIMPL;
@@ -5446,11 +5353,11 @@ static HRESULT WINAPI ITextSelection_fnCanPaste(ITextSelection *me, VARIANT *v,
 
 static HRESULT WINAPI ITextSelection_fnCanEdit(ITextSelection *me, LONG *ret)
 {
-    ITextSelectionImpl *This = impl_from_ITextSelection(me);
+    struct text_selection *This = impl_from_ITextSelection(me);
 
     FIXME("(%p)->(%p): stub\n", This, ret);
 
-    if (!This->reOle)
+    if (!This->services)
         return CO_E_RELEASED;
 
     return E_NOTIMPL;
@@ -5458,11 +5365,11 @@ static HRESULT WINAPI ITextSelection_fnCanEdit(ITextSelection *me, LONG *ret)
 
 static HRESULT WINAPI ITextSelection_fnChangeCase(ITextSelection *me, LONG type)
 {
-    ITextSelectionImpl *This = impl_from_ITextSelection(me);
+    struct text_selection *This = impl_from_ITextSelection(me);
 
     FIXME("(%p)->(%d): stub\n", This, type);
 
-    if (!This->reOle)
+    if (!This->services)
         return CO_E_RELEASED;
 
     return E_NOTIMPL;
@@ -5470,11 +5377,11 @@ 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);
+    struct text_selection *This = impl_from_ITextSelection(me);
 
     FIXME("(%p)->(%d %p %p): stub\n", This, type, cx, cy);
 
-    if (!This->reOle)
+    if (!This->services)
         return CO_E_RELEASED;
 
     return E_NOTIMPL;
@@ -5483,11 +5390,11 @@ static HRESULT WINAPI ITextSelection_fnGetPoint(ITextSelection *me, LONG type, L
 static HRESULT WINAPI ITextSelection_fnSetPoint(ITextSelection *me, LONG x, LONG y, LONG type,
     LONG extend)
 {
-    ITextSelectionImpl *This = impl_from_ITextSelection(me);
+    struct text_selection *This = impl_from_ITextSelection(me);
 
     FIXME("(%p)->(%d %d %d %d): stub\n", This, x, y, type, extend);
 
-    if (!This->reOle)
+    if (!This->services)
         return CO_E_RELEASED;
 
     return E_NOTIMPL;
@@ -5495,11 +5402,11 @@ 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);
+    struct text_selection *This = impl_from_ITextSelection(me);
 
     FIXME("(%p)->(%d): stub\n", This, value);
 
-    if (!This->reOle)
+    if (!This->services)
         return CO_E_RELEASED;
 
     return E_NOTIMPL;
@@ -5507,11 +5414,11 @@ static HRESULT WINAPI ITextSelection_fnScrollIntoView(ITextSelection *me, LONG v
 
 static HRESULT WINAPI ITextSelection_fnGetEmbeddedObject(ITextSelection *me, IUnknown **ppv)
 {
-    ITextSelectionImpl *This = impl_from_ITextSelection(me);
+    struct text_selection *This = impl_from_ITextSelection(me);
 
     FIXME("(%p)->(%p): stub\n", This, ppv);
 
-    if (!This->reOle)
+    if (!This->services)
         return CO_E_RELEASED;
 
     return E_NOTIMPL;
@@ -5520,11 +5427,11 @@ static HRESULT WINAPI ITextSelection_fnGetEmbeddedObject(ITextSelection *me, IUn
 /*** ITextSelection methods ***/
 static HRESULT WINAPI ITextSelection_fnGetFlags(ITextSelection *me, LONG *flags)
 {
-    ITextSelectionImpl *This = impl_from_ITextSelection(me);
+    struct text_selection *This = impl_from_ITextSelection(me);
 
     FIXME("(%p)->(%p): stub\n", This, flags);
 
-    if (!This->reOle)
+    if (!This->services)
         return CO_E_RELEASED;
 
     return E_NOTIMPL;
@@ -5532,11 +5439,11 @@ static HRESULT WINAPI ITextSelection_fnGetFlags(ITextSelection *me, LONG *flags)
 
 static HRESULT WINAPI ITextSelection_fnSetFlags(ITextSelection *me, LONG flags)
 {
-    ITextSelectionImpl *This = impl_from_ITextSelection(me);
+    struct text_selection *This = impl_from_ITextSelection(me);
 
     FIXME("(%p)->(%x): stub\n", This, flags);
 
-    if (!This->reOle)
+    if (!This->services)
         return CO_E_RELEASED;
 
     return E_NOTIMPL;
@@ -5544,11 +5451,11 @@ static HRESULT WINAPI ITextSelection_fnSetFlags(ITextSelection *me, LONG flags)
 
 static HRESULT WINAPI ITextSelection_fnGetType(ITextSelection *me, LONG *type)
 {
-    ITextSelectionImpl *This = impl_from_ITextSelection(me);
+    struct text_selection *This = impl_from_ITextSelection(me);
 
     FIXME("(%p)->(%p): stub\n", This, type);
 
-    if (!This->reOle)
+    if (!This->services)
         return CO_E_RELEASED;
 
     return E_NOTIMPL;
@@ -5557,11 +5464,11 @@ static HRESULT WINAPI ITextSelection_fnGetType(ITextSelection *me, LONG *type)
 static HRESULT WINAPI ITextSelection_fnMoveLeft(ITextSelection *me, LONG unit, LONG count,
     LONG extend, LONG *delta)
 {
-    ITextSelectionImpl *This = impl_from_ITextSelection(me);
+    struct text_selection *This = impl_from_ITextSelection(me);
 
     FIXME("(%p)->(%d %d %d %p): stub\n", This, unit, count, extend, delta);
 
-    if (!This->reOle)
+    if (!This->services)
         return CO_E_RELEASED;
 
     return E_NOTIMPL;
@@ -5570,11 +5477,11 @@ static HRESULT WINAPI ITextSelection_fnMoveLeft(ITextSelection *me, LONG unit, L
 static HRESULT WINAPI ITextSelection_fnMoveRight(ITextSelection *me, LONG unit, LONG count,
     LONG extend, LONG *delta)
 {
-    ITextSelectionImpl *This = impl_from_ITextSelection(me);
+    struct text_selection *This = impl_from_ITextSelection(me);
 
     FIXME("(%p)->(%d %d %d %p): stub\n", This, unit, count, extend, delta);
 
-    if (!This->reOle)
+    if (!This->services)
         return CO_E_RELEASED;
 
     return E_NOTIMPL;
@@ -5583,11 +5490,11 @@ static HRESULT WINAPI ITextSelection_fnMoveRight(ITextSelection *me, LONG unit,
 static HRESULT WINAPI ITextSelection_fnMoveUp(ITextSelection *me, LONG unit, LONG count,
     LONG extend, LONG *delta)
 {
-    ITextSelectionImpl *This = impl_from_ITextSelection(me);
+    struct text_selection *This = impl_from_ITextSelection(me);
 
     FIXME("(%p)->(%d %d %d %p): stub\n", This, unit, count, extend, delta);
 
-    if (!This->reOle)
+    if (!This->services)
         return CO_E_RELEASED;
 
     return E_NOTIMPL;
@@ -5596,11 +5503,11 @@ static HRESULT WINAPI ITextSelection_fnMoveUp(ITextSelection *me, LONG unit, LON
 static HRESULT WINAPI ITextSelection_fnMoveDown(ITextSelection *me, LONG unit, LONG count,
     LONG extend, LONG *delta)
 {
-    ITextSelectionImpl *This = impl_from_ITextSelection(me);
+    struct text_selection *This = impl_from_ITextSelection(me);
 
     FIXME("(%p)->(%d %d %d %p): stub\n", This, unit, count, extend, delta);
 
-    if (!This->reOle)
+    if (!This->services)
         return CO_E_RELEASED;
 
     return E_NOTIMPL;
@@ -5609,11 +5516,11 @@ static HRESULT WINAPI ITextSelection_fnMoveDown(ITextSelection *me, LONG unit, L
 static HRESULT WINAPI ITextSelection_fnHomeKey(ITextSelection *me, LONG unit, LONG extend,
     LONG *delta)
 {
-    ITextSelectionImpl *This = impl_from_ITextSelection(me);
+    struct text_selection *This = impl_from_ITextSelection(me);
 
     FIXME("(%p)->(%d %d %p): stub\n", This, unit, extend, delta);
 
-    if (!This->reOle)
+    if (!This->services)
         return CO_E_RELEASED;
 
     return E_NOTIMPL;
@@ -5622,11 +5529,11 @@ static HRESULT WINAPI ITextSelection_fnHomeKey(ITextSelection *me, LONG unit, LO
 static HRESULT WINAPI ITextSelection_fnEndKey(ITextSelection *me, LONG unit, LONG extend,
     LONG *delta)
 {
-    ITextSelectionImpl *This = impl_from_ITextSelection(me);
+    struct text_selection *This = impl_from_ITextSelection(me);
 
     FIXME("(%p)->(%d %d %p): stub\n", This, unit, extend, delta);
 
-    if (!This->reOle)
+    if (!This->services)
         return CO_E_RELEASED;
 
     return E_NOTIMPL;
@@ -5634,11 +5541,11 @@ static HRESULT WINAPI ITextSelection_fnEndKey(ITextSelection *me, LONG unit, LON
 
 static HRESULT WINAPI ITextSelection_fnTypeText(ITextSelection *me, BSTR text)
 {
-    ITextSelectionImpl *This = impl_from_ITextSelection(me);
+    struct text_selection *This = impl_from_ITextSelection(me);
 
     FIXME("(%p)->(%s): stub\n", This, debugstr_w(text));
 
-    if (!This->reOle)
+    if (!This->services)
         return CO_E_RELEASED;
 
     return E_NOTIMPL;
@@ -5715,46 +5622,18 @@ static const ITextSelectionVtbl tsvt = {
     ITextSelection_fnTypeText
 };
 
-static ITextSelectionImpl *
-CreateTextSelection(IRichEditOleImpl *reOle)
+static struct text_selection *text_selection_create(struct text_services *services)
 {
-    ITextSelectionImpl *txtSel = heap_alloc(sizeof *txtSel);
+    struct text_selection *txtSel = heap_alloc(sizeof *txtSel);
     if (!txtSel)
         return NULL;
 
     txtSel->ITextSelection_iface.lpVtbl = &tsvt;
     txtSel->ref = 1;
-    txtSel->reOle = reOle;
+    txtSel->services = services;
     return txtSel;
 }
 
-LRESULT CreateIRichEditOle(IUnknown *outer_unk, ME_TextEditor *editor, LPVOID *ppvObj)
-{
-    IRichEditOleImpl *reo;
-
-    reo = heap_alloc(sizeof(IRichEditOleImpl));
-    if (!reo)
-        return 0;
-
-    reo->IUnknown_inner.lpVtbl = &reo_unk_vtbl;
-    reo->IRichEditOle_iface.lpVtbl = &revt;
-    reo->ITextDocument2Old_iface.lpVtbl = &tdvt;
-    reo->ref = 1;
-    reo->editor = editor;
-    reo->txtSel = NULL;
-
-    TRACE("Created %p\n",reo);
-    list_init(&reo->rangelist);
-    list_init(&reo->clientsites);
-    if (outer_unk)
-        reo->outer_unk = outer_unk;
-    else
-        reo->outer_unk = &reo->IUnknown_inner;
-    *ppvObj = &reo->IUnknown_inner;
-
-    return 1;
-}
-
 static void convert_sizel(const ME_Context *c, const SIZEL* szl, SIZE* sz)
 {
   /* sizel is in .01 millimeters, sz in pixels */
@@ -5970,3 +5849,21 @@ void ME_CopyReObject(REOBJECT *dst, const REOBJECT *src, DWORD flags)
         IOleClientSite_AddRef(dst->polesite);
     }
 }
+
+void richole_release_children( struct text_services *services )
+{
+    ITextRangeImpl *range;
+    IOleClientSiteImpl *site;
+
+    if (services->text_selection)
+    {
+        services->text_selection->services = NULL;
+        ITextSelection_Release( &services->text_selection->ITextSelection_iface );
+    }
+
+    LIST_FOR_EACH_ENTRY( range, &services->rangelist, ITextRangeImpl, child.entry )
+        range->child.reole = NULL;
+
+    LIST_FOR_EACH_ENTRY( site, &services->clientsites, IOleClientSiteImpl, child.entry )
+        site->child.reole = NULL;
+}
diff --git a/dlls/riched20/txtsrv.c b/dlls/riched20/txtsrv.c
index 80e4682880f..73b8d3ea7e9 100644
--- a/dlls/riched20/txtsrv.c
+++ b/dlls/riched20/txtsrv.c
@@ -32,16 +32,6 @@
 
 WINE_DEFAULT_DEBUG_CHANNEL(richedit);
 
-struct text_services
-{
-    IUnknown IUnknown_inner;
-    ITextServices ITextServices_iface;
-    IUnknown *outer_unk;
-    LONG ref;
-    ME_TextEditor *editor;
-    char spare[256]; /* for bug #12179 */
-};
-
 static inline struct text_services *impl_from_IUnknown( IUnknown *iface )
 {
     return CONTAINING_RECORD( iface, struct text_services, IUnknown_inner );
@@ -55,13 +45,10 @@ static HRESULT WINAPI ITextServicesImpl_QueryInterface( IUnknown *iface, REFIID
 
     if (IsEqualIID( iid, &IID_IUnknown )) *obj = &services->IUnknown_inner;
     else if (IsEqualIID( iid, &IID_ITextServices )) *obj = &services->ITextServices_iface;
-    else if (IsEqualIID( iid, &IID_IRichEditOle ) || IsEqualIID( iid, &IID_ITextDocument ) ||
-             IsEqualIID( iid, &IID_ITextDocument2Old ))
-    {
-        if (!services->editor->reOle && !CreateIRichEditOle( services->outer_unk, services->editor, (void **)&services->editor->reOle ))
-            return E_OUTOFMEMORY;
-        return IUnknown_QueryInterface( services->editor->reOle, iid, obj );
-    }
+    else if (IsEqualIID( iid, &IID_IRichEditOle )) *obj= &services->IRichEditOle_iface;
+    else if (IsEqualIID( iid, &IID_IDispatch ) ||
+             IsEqualIID( iid, &IID_ITextDocument ) ||
+             IsEqualIID( iid, &IID_ITextDocument2Old )) *obj = &services->ITextDocument2Old_iface;
     else
     {
         *obj = NULL;
@@ -92,6 +79,7 @@ static ULONG WINAPI ITextServicesImpl_Release(IUnknown *iface)
 
     if (!ref)
     {
+        richole_release_children( services );
         ME_DestroyEditor( services->editor );
         CoTaskMemFree( services );
     }
@@ -597,11 +585,18 @@ HRESULT create_text_services( IUnknown *outer, ITextHost *text_host, IUnknown **
     services->ref = 1;
     services->IUnknown_inner.lpVtbl = &textservices_inner_vtbl;
     services->ITextServices_iface.lpVtbl = &textservices_vtbl;
+    services->IRichEditOle_iface.lpVtbl = &re_ole_vtbl;
+    services->ITextDocument2Old_iface.lpVtbl = &text_doc2old_vtbl;
     services->editor = ME_MakeEditor( text_host, emulate_10 );
+    services->editor->richole = &services->IRichEditOle_iface;
 
     if (outer) services->outer_unk = outer;
     else services->outer_unk = &services->IUnknown_inner;
 
+    services->text_selection = NULL;
+    list_init( &services->rangelist );
+    list_init( &services->clientsites );
+
     *unk = &services->IUnknown_inner;
     return S_OK;
 }
-- 
2.23.0




More information about the wine-devel mailing list