riched20: Implement ITextRange::SetRange.

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 2019-05-27 11:07:45 +08:00 committed by Alexandre Julliard
parent 4f201cfcc9
commit fec6920638
2 changed files with 72 additions and 16 deletions

View File

@ -2026,6 +2026,24 @@ static HRESULT WINAPI ITextRange_fnSetIndex(ITextRange *me, LONG unit, LONG inde
return E_NOTIMPL; return E_NOTIMPL;
} }
static void cp2range(ME_TextEditor *editor, LONG *cp1, LONG *cp2)
{
int len = ME_GetTextLength(editor) + 1;
*cp1 = max(*cp1, 0);
*cp2 = max(*cp2, 0);
*cp1 = min(*cp1, len);
*cp2 = min(*cp2, len);
if (*cp1 > *cp2)
{
int tmp = *cp1;
*cp1 = *cp2;
*cp2 = tmp;
}
if (*cp1 == len)
*cp1 = *cp2 = len - 1;
}
static HRESULT WINAPI ITextRange_fnSetRange(ITextRange *me, LONG anchor, LONG active) static HRESULT WINAPI ITextRange_fnSetRange(ITextRange *me, LONG anchor, LONG active)
{ {
ITextRangeImpl *This = impl_from_ITextRange(me); ITextRangeImpl *This = impl_from_ITextRange(me);
@ -2035,7 +2053,13 @@ static HRESULT WINAPI ITextRange_fnSetRange(ITextRange *me, LONG anchor, LONG ac
if (!This->child.reole) if (!This->child.reole)
return CO_E_RELEASED; return CO_E_RELEASED;
return E_NOTIMPL; cp2range(This->child.reole->editor, &anchor, &active);
if (anchor == This->start && active == This->end)
return S_FALSE;
This->start = anchor;
This->end = active;
return S_OK;
} }
static HRESULT textrange_inrange(LONG start, LONG end, ITextRange *range, LONG *ret) static HRESULT textrange_inrange(LONG start, LONG end, ITextRange *range, LONG *ret)
@ -4109,26 +4133,12 @@ static HRESULT WINAPI ITextDocument2Old_fnRange(ITextDocument2Old *iface, LONG c
ITextRange **ppRange) ITextRange **ppRange)
{ {
IRichEditOleImpl *This = impl_from_ITextDocument2Old(iface); IRichEditOleImpl *This = impl_from_ITextDocument2Old(iface);
const int len = ME_GetTextLength(This->editor) + 1;
TRACE("%p %p %d %d\n", This, ppRange, cp1, cp2); TRACE("%p %p %d %d\n", This, ppRange, cp1, cp2);
if (!ppRange) if (!ppRange)
return E_INVALIDARG; return E_INVALIDARG;
cp1 = max(cp1, 0); cp2range(This->editor, &cp1, &cp2);
cp2 = max(cp2, 0);
cp1 = min(cp1, len);
cp2 = min(cp2, len);
if (cp1 > cp2)
{
LONG tmp;
tmp = cp1;
cp1 = cp2;
cp2 = tmp;
}
if (cp1 == len)
cp1 = cp2 = len - 1;
return CreateITextRange(This, cp1, cp2, ppRange); return CreateITextRange(This, cp1, cp2, ppRange);
} }

View File

@ -3590,6 +3590,51 @@ static void _check_selection(ITextSelection *selection, LONG expected_start, LON
expected_end, value); expected_end, value);
} }
static void test_ITextRange_SetRange(void)
{
static const CHAR test_text1[] = "TestSomeText";
ITextDocument *txtDoc = NULL;
IRichEditOle *reOle = NULL;
ITextRange *txtRge = NULL;
HRESULT hr;
HWND w;
create_interfaces(&w, &reOle, &txtDoc, NULL);
SendMessageA(w, WM_SETTEXT, 0, (LPARAM)test_text1);
ITextDocument_Range(txtDoc, 0, 0, &txtRge);
hr = ITextRange_SetRange(txtRge, 2, 4);
ok(hr == S_OK, "got 0x%08x.\n", hr);
CHECK_RANGE(txtRge, 2, 4);
hr = ITextRange_SetRange(txtRge, 2, 4);
ok(hr == S_FALSE, "got 0x%08x.\n", hr);
CHECK_RANGE(txtRge, 2, 4);
hr = ITextRange_SetRange(txtRge, 4, 2);
ok(hr == S_FALSE, "got 0x%08x.\n", hr);
CHECK_RANGE(txtRge, 2, 4);
hr = ITextRange_SetRange(txtRge, 14, 14);
ok(hr == S_OK, "got 0x%08x.\n", hr);
CHECK_RANGE(txtRge, 12, 12);
hr = ITextRange_SetRange(txtRge, 15, 15);
ok(hr == S_FALSE, "got 0x%08x.\n", hr);
CHECK_RANGE(txtRge, 12, 12);
hr = ITextRange_SetRange(txtRge, 14, 1);
ok(hr == S_OK, "got 0x%08x.\n", hr);
CHECK_RANGE(txtRge, 1, 13);
hr = ITextRange_SetRange(txtRge, -1, 4);
ok(hr == S_OK, "got 0x%08x.\n", hr);
CHECK_RANGE(txtRge, 0, 4);
ITextRange_Release(txtRge);
release_interfaces(&w, &reOle, &txtDoc, NULL);
}
static void test_Expand(void) static void test_Expand(void)
{ {
static const char test_text1[] = "TestSomeText"; static const char test_text1[] = "TestSomeText";
@ -3780,6 +3825,7 @@ START_TEST(richole)
test_ITextRange_GetChar(); test_ITextRange_GetChar();
test_ITextRange_ScrollIntoView(); test_ITextRange_ScrollIntoView();
test_ITextRange_GetStart_GetEnd(); test_ITextRange_GetStart_GetEnd();
test_ITextRange_SetRange();
test_ITextRange_GetDuplicate(); test_ITextRange_GetDuplicate();
test_ITextRange_Collapse(); test_ITextRange_Collapse();
test_GetClientSite(); test_GetClientSite();