Nikolay Sivov : riched20: Implement Expand for tomStory case.

Alexandre Julliard julliard at wine.codeweavers.com
Wed Jun 17 10:18:10 CDT 2015


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

Author: Nikolay Sivov <nsivov at codeweavers.com>
Date:   Tue Jun 16 16:15:09 2015 +0300

riched20: Implement Expand for tomStory case.

---

 dlls/riched20/richole.c       | 41 +++++++++++++++++---
 dlls/riched20/tests/richole.c | 87 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 123 insertions(+), 5 deletions(-)

diff --git a/dlls/riched20/richole.c b/dlls/riched20/richole.c
index 66faa6d..257ce7f 100644
--- a/dlls/riched20/richole.c
+++ b/dlls/riched20/richole.c
@@ -909,6 +909,35 @@ static void textfont_cache_range_props(ITextFontImpl *font)
     }
 }
 
+static HRESULT textrange_expand(ITextRange *range, LONG unit, LONG *delta)
+{
+    LONG expand_start, expand_end;
+
+    switch (unit)
+    {
+    case tomStory:
+        expand_start = 0;
+        ITextRange_GetStoryLength(range, &expand_end);
+        break;
+    default:
+        FIXME("unit %d is not supported\n", unit);
+        return E_NOTIMPL;
+    }
+
+    if (delta) {
+        LONG start, end;
+
+        ITextRange_GetStart(range, &start);
+        ITextRange_GetEnd(range, &end);
+        *delta = expand_end - expand_start - (end - start);
+    }
+
+    ITextRange_SetStart(range, expand_start);
+    ITextRange_SetEnd(range, expand_end);
+
+    return S_OK;
+}
+
 static HRESULT WINAPI IRichEditOleImpl_inner_fnQueryInterface(IUnknown *iface, REFIID riid, LPVOID *ppvObj)
 {
     IRichEditOleImpl *This = impl_from_IUnknown(iface);
@@ -1970,12 +1999,12 @@ static HRESULT WINAPI ITextRange_fnExpand(ITextRange *me, LONG unit, LONG *delta
 {
     ITextRangeImpl *This = impl_from_ITextRange(me);
 
-    FIXME("(%p)->(%d %p): stub\n", This, unit, delta);
+    TRACE("(%p)->(%d %p)\n", This, unit, delta);
 
     if (!This->child.reole)
         return CO_E_RELEASED;
 
-    return E_NOTIMPL;
+    return textrange_expand(me, unit, delta);
 }
 
 static HRESULT WINAPI ITextRange_fnGetIndex(ITextRange *me, LONG unit, LONG *index)
@@ -4494,14 +4523,16 @@ static HRESULT WINAPI ITextSelection_fnCollapse(ITextSelection *me, LONG bStart)
     return hres;
 }
 
-static HRESULT WINAPI ITextSelection_fnExpand(ITextSelection *me, LONG Unit, LONG *pDelta)
+static HRESULT WINAPI ITextSelection_fnExpand(ITextSelection *me, LONG unit, LONG *delta)
 {
     ITextSelectionImpl *This = impl_from_ITextSelection(me);
+
+    TRACE("(%p)->(%d %p)\n", This, unit, delta);
+
     if (!This->reOle)
         return CO_E_RELEASED;
 
-    FIXME("not implemented\n");
-    return E_NOTIMPL;
+    return textrange_expand((ITextRange*)me, unit, delta);
 }
 
 static HRESULT WINAPI ITextSelection_fnGetIndex(ITextSelection *me, LONG Unit, LONG *pIndex)
diff --git a/dlls/riched20/tests/richole.c b/dlls/riched20/tests/richole.c
index fd4d9e8..dd1e8a5 100644
--- a/dlls/riched20/tests/richole.c
+++ b/dlls/riched20/tests/richole.c
@@ -3251,6 +3251,92 @@ static void test_ITextSelection_GetDuplicate(void)
   ITextRange_Release(range);
 }
 
+static void test_Expand(void)
+{
+  static const char test_text1[] = "TestSomeText";
+  IRichEditOle *reole = NULL;
+  ITextDocument *doc = NULL;
+  ITextSelection *selection;
+  ITextRange *range;
+  LONG value;
+  HRESULT hr;
+  HWND hwnd;
+
+  create_interfaces(&hwnd, &reole, &doc, &selection);
+  SendMessageA(hwnd, WM_SETTEXT, 0, (LPARAM)test_text1);
+  SendMessageA(hwnd, EM_SETSEL, 1, 2);
+
+  hr = ITextDocument_Range(doc, 0, 4, &range);
+  ok(hr == S_OK, "got 0x%08x\n", hr);
+
+  hr = ITextRange_Expand(range, tomStory, NULL);
+  ok(hr == S_OK, "got 0x%08x\n", hr);
+  hr = ITextRange_GetStart(range, &value);
+  ok(hr == S_OK, "got 0x%08x\n", hr);
+  ok(value == 0, "got %d\n", value);
+  hr = ITextRange_GetEnd(range, &value);
+  ok(hr == S_OK, "got 0x%08x\n", hr);
+  ok(value == 13, "got %d\n", value);
+
+  hr = ITextSelection_Expand(selection, tomStory, NULL);
+  ok(hr == S_OK, "got 0x%08x\n", hr);
+  hr = ITextSelection_GetStart(selection, &value);
+  ok(hr == S_OK, "got 0x%08x\n", hr);
+  ok(value == 0, "got %d\n", value);
+  hr = ITextSelection_GetEnd(selection, &value);
+  ok(hr == S_OK, "got 0x%08x\n", hr);
+  ok(value == 13, "got %d\n", value);
+
+  hr = ITextRange_SetStart(range, 1);
+  ok(hr == S_OK, "got 0x%08x\n", hr);
+  hr = ITextRange_SetEnd(range, 2);
+  ok(hr == S_OK, "got 0x%08x\n", hr);
+
+  hr = ITextSelection_SetStart(selection, 1);
+  ok(hr == S_OK, "got 0x%08x\n", hr);
+  hr = ITextSelection_SetEnd(selection, 2);
+  ok(hr == S_OK, "got 0x%08x\n", hr);
+
+  value = 0;
+  hr = ITextRange_Expand(range, tomStory, &value);
+  ok(hr == S_OK, "got 0x%08x\n", hr);
+  ok(value == 12, "got %d\n", value);
+  hr = ITextRange_GetStart(range, &value);
+  ok(hr == S_OK, "got 0x%08x\n", hr);
+  ok(value == 0, "got %d\n", value);
+  hr = ITextRange_GetEnd(range, &value);
+  ok(hr == S_OK, "got 0x%08x\n", hr);
+  ok(value == 13, "got %d\n", value);
+
+  value = 0;
+  hr = ITextSelection_Expand(selection, tomStory, &value);
+  ok(hr == S_OK, "got 0x%08x\n", hr);
+  ok(value == 12, "got %d\n", value);
+  hr = ITextSelection_GetStart(selection, &value);
+  ok(hr == S_OK, "got 0x%08x\n", hr);
+  ok(value == 0, "got %d\n", value);
+  hr = ITextSelection_GetEnd(selection, &value);
+  ok(hr == S_OK, "got 0x%08x\n", hr);
+  ok(value == 13, "got %d\n", value);
+
+  release_interfaces(&hwnd, &reole, &doc, NULL);
+
+  hr = ITextRange_Expand(range, tomStory, NULL);
+  ok(hr == CO_E_RELEASED, "got 0x%08x\n", hr);
+
+  hr = ITextRange_Expand(range, tomStory, &value);
+  ok(hr == CO_E_RELEASED, "got 0x%08x\n", hr);
+
+  hr = ITextSelection_Expand(selection, tomStory, NULL);
+  ok(hr == CO_E_RELEASED, "got 0x%08x\n", hr);
+
+  hr = ITextSelection_Expand(selection, tomStory, &value);
+  ok(hr == CO_E_RELEASED, "got 0x%08x\n", hr);
+
+  ITextSelection_Release(selection);
+  ITextRange_Release(range);
+}
+
 START_TEST(richole)
 {
   /* Must explicitly LoadLibrary(). The test has no references to functions in
@@ -3286,4 +3372,5 @@ START_TEST(richole)
   test_InsertObject();
   test_GetStoryLength();
   test_ITextSelection_GetDuplicate();
+  test_Expand();
 }




More information about the wine-cvs mailing list