Module: wine Branch: master Commit: 125fbf7b2fe3c4ec99673cf2088d835353f60951 URL: https://source.winehq.org/git/wine.git/?a=commit;h=125fbf7b2fe3c4ec99673cf20...
Author: Jactry Zeng jzeng@codeweavers.com Date: Tue Apr 3 17:57:43 2018 +0800
riched20: Implement {ITextRange,ITextSelection}::MoveEnd.
Signed-off-by: Jactry Zeng jzeng@codeweavers.com Signed-off-by: Huw Davies huw@codeweavers.com Signed-off-by: Alexandre Julliard julliard@winehq.org
---
dlls/riched20/richole.c | 59 ++++++++++++++++++++-- dlls/riched20/tests/richole.c | 115 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 170 insertions(+), 4 deletions(-)
diff --git a/dlls/riched20/richole.c b/dlls/riched20/richole.c index 3033157..a52cd52 100644 --- a/dlls/riched20/richole.c +++ b/dlls/riched20/richole.c @@ -2139,17 +2139,63 @@ static HRESULT WINAPI ITextRange_fnMoveStart(ITextRange *me, LONG unit, LONG cou return E_NOTIMPL; }
+static HRESULT textrange_moveend(ITextRange *range, LONG unit, LONG count, LONG *delta) +{ + LONG old_start, old_end, new_start, new_end; + HRESULT hr = S_OK; + + if (!count) + { + if (delta) + *delta = 0; + return S_FALSE; + } + + ITextRange_GetStart(range, &old_start); + ITextRange_GetEnd(range, &old_end); + switch (unit) + { + case tomStory: + if (count < 0) + new_start = new_end = 0; + else + { + new_start = old_start; + ITextRange_GetStoryLength(range, &new_end); + } + if (delta) + { + if (new_end < old_end) + *delta = -1; + else if (new_end == old_end) + *delta = 0; + else + *delta = 1; + } + break; + default: + FIXME("unit %d is not supported\n", unit); + return E_NOTIMPL; + } + if (new_end == old_end) + hr = S_FALSE; + ITextRange_SetStart(range, new_start); + ITextRange_SetEnd(range, new_end); + + return hr; +} + static HRESULT WINAPI ITextRange_fnMoveEnd(ITextRange *me, LONG unit, LONG count, LONG *delta) { ITextRangeImpl *This = impl_from_ITextRange(me);
- FIXME("(%p)->(%d %d %p): stub\n", This, unit, count, delta); + TRACE("(%p)->(%d %d %p)\n", This, unit, count, delta);
if (!This->child.reole) return CO_E_RELEASED;
- return E_NOTIMPL; + return textrange_moveend(me, unit, count, delta); }
static HRESULT WINAPI ITextRange_fnMoveWhile(ITextRange *me, VARIANT *charset, LONG count, @@ -4694,13 +4740,18 @@ static HRESULT WINAPI ITextSelection_fnMoveEnd(ITextSelection *me, LONG unit, LO LONG *delta) { ITextSelectionImpl *This = impl_from_ITextSelection(me); + ITextRange *range = NULL; + HRESULT hr;
- FIXME("(%p)->(%d %d %p): stub\n", This, unit, count, delta); + TRACE("(%p)->(%d %d %p)\n", This, unit, count, delta);
if (!This->reOle) return CO_E_RELEASED;
- return E_NOTIMPL; + ITextSelection_QueryInterface(me, &IID_ITextRange, (void**)&range); + hr = textrange_moveend(range, unit, count, delta); + ITextRange_Release(range); + return hr; }
static HRESULT WINAPI ITextSelection_fnMoveWhile(ITextSelection *me, VARIANT *charset, LONG count, diff --git a/dlls/riched20/tests/richole.c b/dlls/riched20/tests/richole.c index 5ba1794..97f8e46 100644 --- a/dlls/riched20/tests/richole.c +++ b/dlls/riched20/tests/richole.c @@ -3427,6 +3427,120 @@ static void test_Expand(void) ITextRange_Release(range); }
+static void test_MoveEnd(void) +{ + static const char test_text1[] = "Word1 Word2"; + IRichEditOle *reole = NULL; + ITextDocument *doc = NULL; + ITextSelection *selection; + ITextRange *range; + LONG delta; + 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, 1, 2, &range); + ok(hr == S_OK, "got 0x%08x\n", hr); + + hr = ITextRange_MoveEnd(range, tomStory, 0, &delta); + ok(hr == S_FALSE, "got 0x%08x\n", hr); + ok(delta == 0, "got %d\n", delta); + CHECK_RANGE(range, 1, 2); + + hr = ITextRange_MoveEnd(range, tomStory, -1, &delta); + ok(hr == S_OK, "got 0x%08x\n", hr); + ok(delta == -1, "got %d\n", delta); + CHECK_RANGE(range, 0, 0); + + hr = ITextRange_MoveEnd(range, tomStory, 1, &delta); + ok(hr == S_OK, "got 0x%08x\n", hr); + ok(delta == 1, "got %d\n", delta); + CHECK_RANGE(range, 0, 12); + + hr = ITextRange_MoveEnd(range, tomStory, 1, &delta); + ok(hr == S_FALSE, "got 0x%08x\n", hr); + ok(delta == 0, "got %d\n", delta); + CHECK_RANGE(range, 0, 12); + + RESET_RANGE(range, 1, 2); + + hr = ITextRange_MoveEnd(range, tomStory, 3, &delta); + ok(hr == S_OK, "got 0x%08x\n", hr); + ok(delta == 1, "got %d\n", delta); + CHECK_RANGE(range, 1, 12); + + RESET_RANGE(range, 2, 3); + + hr = ITextRange_MoveEnd(range, tomStory, -3, &delta); + ok(hr == S_OK, "got 0x%08x\n", hr); + ok(delta == -1, "got %d\n", delta); + CHECK_RANGE(range, 0, 0); + + hr = ITextRange_MoveEnd(range, tomStory, -1, &delta); + ok(hr == S_FALSE, "got 0x%08x\n", hr); + ok(delta == 0, "got %d\n", delta); + CHECK_RANGE(range, 0, 0); + + hr = ITextSelection_MoveEnd(selection, tomStory, 0, &delta); + ok(hr == S_FALSE, "got 0x%08x\n", hr); + ok(delta == 0, "got %d\n", delta); + CHECK_SELECTION(selection, 1, 2); + + hr = ITextSelection_MoveEnd(selection, tomStory, -1, &delta); + ok(hr == S_OK, "got 0x%08x\n", hr); + ok(delta == -1, "got %d\n", delta); + CHECK_SELECTION(selection, 0, 0); + + hr = ITextSelection_MoveEnd(selection, tomStory, 1, &delta); + ok(hr == S_OK, "got 0x%08x\n", hr); + ok(delta == 1, "got %d\n", delta); + CHECK_SELECTION(selection, 0, 12); + + hr = ITextSelection_MoveEnd(selection, tomStory, 1, &delta); + ok(hr == S_FALSE, "got 0x%08x\n", hr); + ok(delta == 0, "got %d\n", delta); + CHECK_SELECTION(selection, 0, 12); + + RESET_SELECTION(selection, 1, 2); + + hr = ITextSelection_MoveEnd(selection, tomStory, 3, &delta); + ok(hr == S_OK, "got 0x%08x\n", hr); + ok(delta == 1, "got %d\n", delta); + CHECK_SELECTION(selection, 1, 12); + + RESET_SELECTION(selection, 2, 3); + + hr = ITextSelection_MoveEnd(selection, tomStory, -3, &delta); + ok(hr == S_OK, "got 0x%08x\n", hr); + ok(delta == -1, "got %d\n", delta); + CHECK_SELECTION(selection, 0, 0); + + hr = ITextSelection_MoveEnd(selection, tomStory, -1, &delta); + ok(hr == S_FALSE, "got 0x%08x\n", hr); + ok(delta == 0, "got %d\n", delta); + CHECK_SELECTION(selection, 0, 0); + + release_interfaces(&hwnd, &reole, &doc, NULL); + + hr = ITextRange_MoveEnd(range, tomStory, 1, NULL); + ok(hr == CO_E_RELEASED, "got 0x%08x\n", hr); + + hr = ITextRange_MoveEnd(range, tomStory, 1, &delta); + ok(hr == CO_E_RELEASED, "got 0x%08x\n", hr); + + hr = ITextSelection_MoveEnd(selection, tomStory, 1, NULL); + ok(hr == CO_E_RELEASED, "got 0x%08x\n", hr); + + hr = ITextSelection_MoveEnd(selection, tomStory, 1, &delta); + 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 @@ -3464,4 +3578,5 @@ START_TEST(richole) test_GetStoryLength(); test_ITextSelection_GetDuplicate(); test_Expand(); + test_MoveEnd(); }