riched20: Implement ITextRange::Collapse.

This commit is contained in:
Jactry Zeng 2014-09-17 17:38:31 +08:00 committed by Alexandre Julliard
parent da40589e71
commit 07154f7fee
2 changed files with 97 additions and 2 deletions

View File

@ -743,14 +743,25 @@ static HRESULT WINAPI ITextRange_fnGetStoryType(ITextRange *me, LONG *pValue)
return E_NOTIMPL;
}
static HRESULT range_Collapse(LONG bStart, LONG *start, LONG *end)
{
if (*end == *start)
return S_FALSE;
if (bStart == tomEnd || bStart == tomFalse)
*start = *end;
else
*end = *start;
return S_OK;
}
static HRESULT WINAPI ITextRange_fnCollapse(ITextRange *me, LONG bStart)
{
ITextRangeImpl *This = impl_from_ITextRange(me);
if (!This->reOle)
return CO_E_RELEASED;
FIXME("not implemented %p\n", This);
return E_NOTIMPL;
return range_Collapse(bStart, &This->start, &This->end);
}
static HRESULT WINAPI ITextRange_fnExpand(ITextRange *me, LONG Unit, LONG *pDelta)

View File

@ -789,6 +789,89 @@ static void test_ITextRange_GetDuplicate(void)
release_interfaces(&w, &reOle, &txtDoc, NULL);
}
static void test_ITextRange_Collapse(void)
{
HWND w;
IRichEditOle *reOle = NULL;
ITextDocument *txtDoc = NULL;
ITextRange *txtRge = NULL;
HRESULT hres;
LONG first, lim, start, end;
static const CHAR test_text1[] = "TestSomeText";
create_interfaces(&w, &reOle, &txtDoc, NULL);
SendMessageA(w, WM_SETTEXT, 0, (LPARAM)test_text1);
first = 4, lim = 8;
ITextDocument_Range(txtDoc, first, lim, &txtRge);
hres = ITextRange_Collapse(txtRge, tomTrue);
ok(hres == S_OK, "ITextRange_Collapse\n");
ITextRange_GetStart(txtRge, &start);
ok(start == 4, "got wrong start value: %d\n", start);
ITextRange_GetEnd(txtRge, &end);
ok(end == 4, "got wrong end value: %d\n", end);
ITextRange_Release(txtRge);
ITextDocument_Range(txtDoc, first, lim, &txtRge);
hres = ITextRange_Collapse(txtRge, tomStart);
ok(hres == S_OK, "ITextRange_Collapse\n");
ITextRange_GetStart(txtRge, &start);
ok(start == 4, "got wrong start value: %d\n", start);
ITextRange_GetEnd(txtRge, &end);
ok(end == 4, "got wrong end value: %d\n", end);
ITextRange_Release(txtRge);
ITextDocument_Range(txtDoc, first, lim, &txtRge);
hres = ITextRange_Collapse(txtRge, tomFalse);
ok(hres == S_OK, "ITextRange_Collapse\n");
ITextRange_GetStart(txtRge, &start);
ok(start == 8, "got wrong start value: %d\n", start);
ITextRange_GetEnd(txtRge, &end);
ok(end == 8, "got wrong end value: %d\n", end);
ITextRange_Release(txtRge);
ITextDocument_Range(txtDoc, first, lim, &txtRge);
hres = ITextRange_Collapse(txtRge, tomEnd);
ok(hres == S_OK, "ITextRange_Collapse\n");
ITextRange_GetStart(txtRge, &start);
ok(start == 8, "got wrong start value: %d\n", start);
ITextRange_GetEnd(txtRge, &end);
ok(end == 8, "got wrong end value: %d\n", end);
ITextRange_Release(txtRge);
/* tomStart is the default */
ITextDocument_Range(txtDoc, first, lim, &txtRge);
hres = ITextRange_Collapse(txtRge, 256);
ok(hres == S_OK, "ITextRange_Collapse\n");
ITextRange_GetStart(txtRge, &start);
ok(start == 4, "got wrong start value: %d\n", start);
ITextRange_GetEnd(txtRge, &end);
ok(end == 4, "got wrong end value: %d\n", end);
ITextRange_Release(txtRge);
first = 6, lim = 6;
ITextDocument_Range(txtDoc, first, lim, &txtRge);
hres = ITextRange_Collapse(txtRge, tomEnd);
ok(hres == S_FALSE, "ITextRange_Collapse\n");
ITextRange_GetStart(txtRge, &start);
ok(start == 6, "got wrong start value: %d\n", start);
ITextRange_GetEnd(txtRge, &end);
ok(end == 6, "got wrong end value: %d\n", end);
ITextRange_Release(txtRge);
first = 8, lim = 8;
ITextDocument_Range(txtDoc, first, lim, &txtRge);
hres = ITextRange_Collapse(txtRge, tomStart);
ok(hres == S_FALSE, "ITextRange_Collapse\n");
ITextRange_GetStart(txtRge, &start);
ok(start == 8, "got wrong start value: %d\n", start);
ITextRange_GetEnd(txtRge, &end);
ok(end == 8, "got wrong end value: %d\n", end);
ITextRange_Release(txtRge);
release_interfaces(&w, &reOle, &txtDoc, NULL);
}
START_TEST(richole)
{
/* Must explicitly LoadLibrary(). The test has no references to functions in
@ -805,4 +888,5 @@ START_TEST(richole)
test_ITextRange_GetChar();
test_ITextRange_GetStart_GetEnd();
test_ITextRange_GetDuplicate();
test_ITextRange_Collapse();
}