Nikolay Sivov : riched20: Create selection instance first time it' s requested.

Alexandre Julliard julliard at wine.codeweavers.com
Mon Jun 1 07:36:59 CDT 2015


Module: wine
Branch: master
Commit: f0c508661816a5e6f6221e88ddea6e0151a189ac
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=f0c508661816a5e6f6221e88ddea6e0151a189ac

Author: Nikolay Sivov <nsivov at codeweavers.com>
Date:   Sun May 31 19:56:45 2015 +0300

riched20: Create selection instance first time it's requested.

---

 dlls/riched20/richole.c | 35 +++++++++++++++++++++--------------
 1 file changed, 21 insertions(+), 14 deletions(-)

diff --git a/dlls/riched20/richole.c b/dlls/riched20/richole.c
index 7c50304..f3a4a01 100644
--- a/dlls/riched20/richole.c
+++ b/dlls/riched20/richole.c
@@ -310,6 +310,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 void textranges_update_ranges(IRichEditOleImpl *reole, LONG start, LONG end, enum range_update_op op)
 {
@@ -943,10 +944,11 @@ static ULONG WINAPI IRichEditOleImpl_inner_fnRelease(IUnknown *iface)
         IOleClientSiteImpl *clientsite;
         ITextRangeImpl *txtRge;
 
-        TRACE("Destroying %p\n", This);
-        This->txtSel->reOle = NULL;
         This->editor->reOle = NULL;
-        ITextSelection_Release(&This->txtSel->ITextSelection_iface);
+        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;
@@ -3790,15 +3792,25 @@ ITextDocument_fnGetName(ITextDocument* me, BSTR* pName)
 }
 
 static HRESULT WINAPI
-ITextDocument_fnGetSelection(ITextDocument* me, ITextSelection** ppSel)
+ITextDocument_fnGetSelection(ITextDocument *me, ITextSelection **selection)
 {
     IRichEditOleImpl *This = impl_from_ITextDocument(me);
-    TRACE("(%p)\n", me);
 
-    if(!ppSel)
+    TRACE("(%p)->(%p)\n", me, selection);
+
+    if (!selection)
       return E_INVALIDARG;
-    *ppSel = &This->txtSel->ITextSelection_iface;
-    ITextSelection_AddRef(*ppSel);
+
+    if (!This->txtSel) {
+      This->txtSel = CreateTextSelection(This);
+      if (!This->txtSel) {
+        *selection = NULL;
+        return E_OUTOFMEMORY;
+      }
+    }
+
+    *selection = &This->txtSel->ITextSelection_iface;
+    ITextSelection_AddRef(*selection);
     return S_OK;
 }
 
@@ -4977,12 +4989,7 @@ LRESULT CreateIRichEditOle(IUnknown *outer_unk, ME_TextEditor *editor, LPVOID *p
     reo->ITextDocument_iface.lpVtbl = &tdvt;
     reo->ref = 1;
     reo->editor = editor;
-    reo->txtSel = CreateTextSelection(reo);
-    if (!reo->txtSel)
-    {
-        heap_free(reo);
-        return 0;
-    }
+    reo->txtSel = NULL;
 
     TRACE("Created %p\n",reo);
     list_init(&reo->rangelist);




More information about the wine-cvs mailing list