riched20: Implement ITextSelection::Collapse.

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

View File

@ -1754,11 +1754,16 @@ static HRESULT WINAPI ITextSelection_fnGetStoryType(ITextSelection *me, LONG *pV
static HRESULT WINAPI ITextSelection_fnCollapse(ITextSelection *me, LONG bStart)
{
ITextSelectionImpl *This = impl_from_ITextSelection(me);
LONG start, end;
HRESULT hres;
if (!This->reOle)
return CO_E_RELEASED;
FIXME("not implemented\n");
return E_NOTIMPL;
ME_GetSelectionOfs(This->reOle->editor, &start, &end);
hres = range_Collapse(bStart, &start, &end);
if (SUCCEEDED(hres))
ME_SetSelection(This->reOle->editor, start, end);
return hres;
}
static HRESULT WINAPI ITextSelection_fnExpand(ITextSelection *me, LONG Unit, LONG *pDelta)

View File

@ -872,6 +872,75 @@ static void test_ITextRange_Collapse(void)
release_interfaces(&w, &reOle, &txtDoc, NULL);
}
static void test_ITextSelection_Collapse(void)
{
HWND w;
IRichEditOle *reOle = NULL;
ITextDocument *txtDoc = NULL;
ITextSelection *txtSel = NULL;
HRESULT hres;
LONG first, lim, start, end;
static const CHAR test_text1[] = "TestSomeText";
create_interfaces(&w, &reOle, &txtDoc, &txtSel);
SendMessageA(w, WM_SETTEXT, 0, (LPARAM)test_text1);
first = 4, lim = 8;
SendMessageA(w, EM_SETSEL, first, lim);
hres = ITextSelection_Collapse(txtSel, tomTrue);
ok(hres == S_OK, "ITextSelection_Collapse\n");
SendMessageA(w, EM_GETSEL, (LPARAM)&start, (WPARAM)&end);
ok(start == 4, "got wrong start value: %d\n", start);
ok(end == 4, "got wrong end value: %d\n", end);
SendMessageA(w, EM_SETSEL, first, lim);
hres = ITextSelection_Collapse(txtSel, tomStart);
ok(hres == S_OK, "ITextSelection_Collapse\n");
SendMessageA(w, EM_GETSEL, (LPARAM)&start, (WPARAM)&end);
ok(start == 4, "got wrong start value: %d\n", start);
ok(end == 4, "got wrong end value: %d\n", end);
SendMessageA(w, EM_SETSEL, first, lim);
hres = ITextSelection_Collapse(txtSel, tomFalse);
ok(hres == S_OK, "ITextSelection_Collapse\n");
SendMessageA(w, EM_GETSEL, (LPARAM)&start, (WPARAM)&end);
ok(start == 8, "got wrong start value: %d\n", start);
ok(end == 8, "got wrong end value: %d\n", end);
SendMessageA(w, EM_SETSEL, first, lim);
hres = ITextSelection_Collapse(txtSel, tomEnd);
ok(hres == S_OK, "ITextSelection_Collapse\n");
SendMessageA(w, EM_GETSEL, (LPARAM)&start, (WPARAM)&end);
ok(start == 8, "got wrong start value: %d\n", start);
ok(end == 8, "got wrong end value: %d\n", end);
/* tomStart is the default */
SendMessageA(w, EM_SETSEL, first, lim);
hres = ITextSelection_Collapse(txtSel, 256);
ok(hres == S_OK, "ITextSelection_Collapse\n");
SendMessageA(w, EM_GETSEL, (LPARAM)&start, (WPARAM)&end);
ok(start == 4, "got wrong start value: %d\n", start);
ok(end == 4, "got wrong end value: %d\n", end);
first = 6, lim = 6;
SendMessageA(w, EM_SETSEL, first, lim);
hres = ITextSelection_Collapse(txtSel, tomEnd);
ok(hres == S_FALSE, "ITextSelection_Collapse\n");
SendMessageA(w, EM_GETSEL, (LPARAM)&start, (WPARAM)&end);
ok(start == 6, "got wrong start value: %d\n", start);
ok(end == 6, "got wrong end value: %d\n", end);
first = 8, lim = 8;
SendMessageA(w, EM_SETSEL, first, lim);
hres = ITextSelection_Collapse(txtSel, tomStart);
ok(hres == S_FALSE, "ITextSelection_Collapse\n");
SendMessageA(w, EM_GETSEL, (LPARAM)&start, (WPARAM)&end);
ok(start == 8, "got wrong start value: %d\n", start);
ok(end == 8, "got wrong end value: %d\n", end);
release_interfaces(&w, &reOle, &txtDoc, &txtSel);
}
START_TEST(richole)
{
/* Must explicitly LoadLibrary(). The test has no references to functions in
@ -884,6 +953,7 @@ START_TEST(richole)
test_ITextSelection_GetText();
test_ITextSelection_GetChar();
test_ITextSelection_GetStart_GetEnd();
test_ITextSelection_Collapse();
test_ITextDocument_Range();
test_ITextRange_GetChar();
test_ITextRange_GetStart_GetEnd();