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>
This commit is contained in:
Jactry Zeng 2018-04-03 17:57:43 +08:00 committed by Alexandre Julliard
parent ad5da1462f
commit 125fbf7b2f
2 changed files with 170 additions and 4 deletions

View File

@ -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,

View File

@ -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();
}