riched20: Implement InRange().

This commit is contained in:
Nikolay Sivov 2015-05-27 02:16:26 +03:00 committed by Alexandre Julliard
parent c1ce95dc96
commit cebee9bd71
2 changed files with 156 additions and 6 deletions

View File

@ -1748,14 +1748,36 @@ static HRESULT WINAPI ITextRange_fnSetRange(ITextRange *me, LONG cpActive, LONG
return E_NOTIMPL;
}
static HRESULT WINAPI ITextRange_fnInRange(ITextRange *me, ITextRange *pRange, LONG *pb)
static HRESULT textrange_inrange(LONG start, LONG end, ITextRange *range, LONG *ret)
{
LONG from, to, v;
if (!ret)
ret = &v;
ITextRange_GetStart(range, &from);
ITextRange_GetEnd(range, &to);
*ret = (start >= from && end <= to) ? tomTrue : tomFalse;
return *ret == tomTrue ? S_OK : S_FALSE;
}
static HRESULT WINAPI ITextRange_fnInRange(ITextRange *me, ITextRange *range, LONG *ret)
{
ITextRangeImpl *This = impl_from_ITextRange(me);
TRACE("(%p)->(%p %p)\n", This, range, ret);
if (ret)
*ret = tomFalse;
if (!This->reOle)
return CO_E_RELEASED;
FIXME("not implemented %p\n", This);
return E_NOTIMPL;
if (!range)
return S_FALSE;
return textrange_inrange(This->start, This->end, range, ret);
}
static HRESULT WINAPI ITextRange_fnInStory(ITextRange *me, ITextRange *pRange, LONG *pb)
@ -4129,14 +4151,31 @@ static HRESULT WINAPI ITextSelection_fnSetRange(ITextSelection *me, LONG cpActiv
return E_NOTIMPL;
}
static HRESULT WINAPI ITextSelection_fnInRange(ITextSelection *me, ITextRange *pRange, LONG *pb)
static HRESULT WINAPI ITextSelection_fnInRange(ITextSelection *me, ITextRange *range, LONG *ret)
{
ITextSelectionImpl *This = impl_from_ITextSelection(me);
ITextSelection *selection = NULL;
LONG start, end;
TRACE("(%p)->(%p %p)\n", This, range, ret);
if (ret)
*ret = tomFalse;
if (!This->reOle)
return CO_E_RELEASED;
FIXME("not implemented\n");
return E_NOTIMPL;
if (!range)
return S_FALSE;
ITextRange_QueryInterface(range, &IID_ITextSelection, (void**)&selection);
if (!selection)
return S_FALSE;
ITextSelection_Release(selection);
ITextSelection_GetStart(me, &start);
ITextSelection_GetEnd(me, &end);
return textrange_inrange(start, end, range, ret);
}
static HRESULT WINAPI ITextSelection_fnInStory(ITextSelection *me, ITextRange *pRange, LONG *pb)

View File

@ -2521,6 +2521,116 @@ static void test_SetText(void)
ITextRange_Release(range);
}
static void test_InRange(void)
{
static const CHAR test_text1[] = "TestSomeText";
ITextRange *range, *range2, *range3;
IRichEditOle *reOle = NULL;
ITextDocument *doc = NULL;
ITextSelection *selection;
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 = ITextDocument_Range(doc, 0, 4, &range2);
ok(hr == S_OK, "got 0x%08x\n", hr);
/* matches selection */
hr = ITextDocument_Range(doc, 1, 2, &range3);
ok(hr == S_OK, "got 0x%08x\n", hr);
hr = ITextRange_InRange(range, NULL, NULL);
ok(hr == S_FALSE, "got 0x%08x\n", hr);
value = tomTrue;
hr = ITextRange_InRange(range, NULL, &value);
ok(hr == S_FALSE, "got 0x%08x\n", hr);
ok(value == tomFalse, "got %d\n", value);
hr = ITextRange_InRange(range, range2, NULL);
ok(hr == S_OK, "got 0x%08x\n", hr);
value = tomFalse;
hr = ITextRange_InRange(range, range2, &value);
ok(hr == S_OK, "got 0x%08x\n", hr);
ok(value == tomTrue, "got %d\n", value);
/* selection */
hr = ITextSelection_InRange(selection, NULL, NULL);
ok(hr == S_FALSE, "got 0x%08x\n", hr);
value = tomTrue;
hr = ITextSelection_InRange(selection, NULL, &value);
ok(hr == S_FALSE, "got 0x%08x\n", hr);
ok(value == tomFalse, "got %d\n", value);
hr = ITextSelection_InRange(selection, range2, NULL);
ok(hr == S_FALSE, "got 0x%08x\n", hr);
value = tomTrue;
hr = ITextSelection_InRange(selection, range2, &value);
ok(hr == S_FALSE, "got 0x%08x\n", hr);
ok(value == tomFalse, "got %d\n", value);
value = tomTrue;
hr = ITextSelection_InRange(selection, range3, &value);
ok(hr == S_FALSE, "got 0x%08x\n", hr);
ok(value == tomFalse, "got %d\n", value);
/* seems to work on ITextSelection ranges only */
value = tomFalse;
hr = ITextSelection_InRange(selection, (ITextRange*)selection, &value);
ok(hr == S_OK, "got 0x%08x\n", hr);
ok(value == tomTrue, "got %d\n", value);
release_interfaces(&hwnd, &reOle, &doc, NULL);
hr = ITextRange_InRange(range, NULL, NULL);
ok(hr == CO_E_RELEASED, "got 0x%08x\n", hr);
value = tomTrue;
hr = ITextRange_InRange(range, NULL, &value);
ok(hr == CO_E_RELEASED, "got 0x%08x\n", hr);
ok(value == tomFalse, "got %d\n", value);
hr = ITextRange_InRange(range, range2, NULL);
ok(hr == CO_E_RELEASED, "got 0x%08x\n", hr);
value = tomTrue;
hr = ITextRange_InRange(range, range2, &value);
ok(hr == CO_E_RELEASED, "got 0x%08x\n", hr);
ok(value == tomFalse, "got %d\n", value);
/* selection */
hr = ITextSelection_InRange(selection, NULL, NULL);
ok(hr == CO_E_RELEASED, "got 0x%08x\n", hr);
value = tomTrue;
hr = ITextSelection_InRange(selection, NULL, &value);
ok(hr == CO_E_RELEASED, "got 0x%08x\n", hr);
ok(value == tomFalse, "got %d\n", value);
hr = ITextSelection_InRange(selection, range2, NULL);
ok(hr == CO_E_RELEASED, "got 0x%08x\n", hr);
value = tomTrue;
hr = ITextSelection_InRange(selection, range2, &value);
ok(hr == CO_E_RELEASED, "got 0x%08x\n", hr);
ok(value == tomFalse, "got %d\n", value);
ITextRange_Release(range);
ITextRange_Release(range2);
ITextRange_Release(range3);
ITextSelection_Release(selection);
}
START_TEST(richole)
{
/* Must explicitly LoadLibrary(). The test has no references to functions in
@ -2548,4 +2658,5 @@ START_TEST(richole)
test_ITextFont();
test_Delete();
test_SetText();
test_InRange();
}