Nikolay Sivov : riched20: Implement GetText() for regular range.

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


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

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

riched20: Implement GetText() for regular range.

---

 dlls/riched20/richole.c       | 28 +++++++++++++++++++++++-----
 dlls/riched20/tests/richole.c | 20 ++++++--------------
 2 files changed, 29 insertions(+), 19 deletions(-)

diff --git a/dlls/riched20/richole.c b/dlls/riched20/richole.c
index 5b8cad5..5b921fe 100644
--- a/dlls/riched20/richole.c
+++ b/dlls/riched20/richole.c
@@ -1563,20 +1563,38 @@ static HRESULT WINAPI ITextRange_fnInvoke(ITextRange *me, DISPID dispIdMember, R
     return hr;
 }
 
-static HRESULT WINAPI ITextRange_fnGetText(ITextRange *me, BSTR *pbstr)
+static HRESULT WINAPI ITextRange_fnGetText(ITextRange *me, BSTR *str)
 {
     ITextRangeImpl *This = impl_from_ITextRange(me);
+    ME_Cursor start, end;
+    int length;
+    BOOL bEOP;
 
-    FIXME("(%p)->(%p): stub\n", This, pbstr);
+    TRACE("(%p)->(%p)\n", This, str);
 
     if (!This->reOle)
         return CO_E_RELEASED;
 
-    if (!pbstr)
+    if (!str)
         return E_INVALIDARG;
 
-    *pbstr = NULL;
-    return E_NOTIMPL;
+    /* return early for degenerate range */
+    if (This->start == This->end) {
+        *str = NULL;
+        return S_OK;
+    }
+
+    ME_CursorFromCharOfs(This->reOle->editor, This->start, &start);
+    ME_CursorFromCharOfs(This->reOle->editor, This->end, &end);
+
+    length = This->end - This->start;
+    *str = SysAllocStringLen(NULL, length);
+    if (!*str)
+        return E_OUTOFMEMORY;
+
+    bEOP = (end.pRun->next->type == diTextEnd && This->end > ME_GetTextLength(This->reOle->editor));
+    ME_GetTextW(This->reOle->editor, *str, length, &start, length, FALSE, bEOP);
+    return S_OK;
 }
 
 static HRESULT WINAPI ITextRange_fnSetText(ITextRange *me, BSTR str)
diff --git a/dlls/riched20/tests/richole.c b/dlls/riched20/tests/richole.c
index 02aaefb..79c3c3d 100644
--- a/dlls/riched20/tests/richole.c
+++ b/dlls/riched20/tests/richole.c
@@ -544,27 +544,24 @@ static void test_GetText(void)
   hres = ITextDocument_Range(txtDoc, 0, 4, &range);
   ok(hres == S_OK, "got 0x%08x\n", hres);
   hres = ITextRange_GetText(range, &bstr);
-todo_wine {
   ok(hres == S_OK, "got 0x%08x\n", hres);
   ok(!lstrcmpW(bstr, bufW1), "got wrong text: %s\n", wine_dbgstr_w(bstr));
-}
+
   SysFreeString(bstr);
   ITextRange_Release(range);
 
   hres = ITextDocument_Range(txtDoc, 4, 0, &range);
   ok(hres == S_OK, "got 0x%08x\n", hres);
   hres = ITextRange_GetText(range, &bstr);
-todo_wine {
   ok(hres == S_OK, "got 0x%08x\n", hres);
   ok(!lstrcmpW(bstr, bufW1), "got wrong text: %s\n", wine_dbgstr_w(bstr));
-}
+
   SysFreeString(bstr);
   ITextRange_Release(range);
 
   hres = ITextDocument_Range(txtDoc, 1, 1, &range);
   ok(hres == S_OK, "got 0x%08x\n", hres);
   hres = ITextRange_GetText(range, &bstr);
-todo_wine
   ok(hres == S_OK, "got 0x%08x\n", hres);
   ok(!bstr, "got wrong text: %s\n", wine_dbgstr_w(bstr));
   if (!is64bit)
@@ -577,37 +574,33 @@ todo_wine
   hres = ITextDocument_Range(txtDoc, 8, 12, &range);
   ok(hres == S_OK, "got 0x%08x\n", hres);
   hres = ITextRange_GetText(range, &bstr);
-todo_wine {
   ok(hres == S_OK, "got 0x%08x\n", hres);
   ok(!lstrcmpW(bstr, bufW3), "got wrong text: %s\n", wine_dbgstr_w(bstr));
-}
+
   SysFreeString(bstr);
   ITextRange_Release(range);
 
   hres = ITextDocument_Range(txtDoc, 8, 13, &range);
   ok(hres == S_OK, "got 0x%08x\n", hres);
   hres = ITextRange_GetText(range, &bstr);
-todo_wine {
   ok(hres == S_OK, "got 0x%08x\n", hres);
   ok(!lstrcmpW(bstr, bufW2), "got wrong text: %s\n", wine_dbgstr_w(bstr));
-}
+
   SysFreeString(bstr);
   ITextRange_Release(range);
 
   hres = ITextDocument_Range(txtDoc, 12, 13, &range);
   ok(hres == S_OK, "got 0x%08x\n", hres);
   hres = ITextRange_GetText(range, &bstr);
-todo_wine {
   ok(hres == S_OK, "got 0x%08x\n", hres);
   ok(!lstrcmpW(bstr, bufW5), "got wrong text: %s\n", wine_dbgstr_w(bstr));
-}
+
   SysFreeString(bstr);
   ITextRange_Release(range);
 
   hres = ITextDocument_Range(txtDoc, 0, -1, &range);
   ok(hres == S_OK, "got 0x%08x\n", hres);
   hres = ITextRange_GetText(range, &bstr);
-todo_wine
   ok(hres == S_OK, "got 0x%08x\n", hres);
   ok(!bstr, "got wrong text: %s\n", wine_dbgstr_w(bstr));
   ITextRange_Release(range);
@@ -615,10 +608,9 @@ todo_wine
   hres = ITextDocument_Range(txtDoc, -1, 9, &range);
   ok(hres == S_OK, "got 0x%08x\n", hres);
   hres = ITextRange_GetText(range, &bstr);
-todo_wine {
   ok(hres == S_OK, "got 0x%08x\n", hres);
   ok(!lstrcmpW(bstr, bufW6), "got wrong text: %s\n", wine_dbgstr_w(bstr));
-}
+
   SysFreeString(bstr);
 
   release_interfaces(&w, &reOle, &txtDoc, NULL);




More information about the wine-cvs mailing list