From: Jactry Zeng Subject: [PATCH 2/8] riched20: Implement ITextSelection::GetChar and ITextRange::GetChar. (resend try2) Message-Id: <54116CF6.80100@jactry.com> Date: Thu, 11 Sep 2014 17:35:50 +0800 --- dlls/riched20/richole.c | 28 ++++++++++++++--- dlls/riched20/tests/richole.c | 70 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 94 insertions(+), 4 deletions(-) diff --git a/dlls/riched20/richole.c b/dlls/riched20/richole.c index ad0e727..b3ffdcd 100644 --- a/dlls/riched20/richole.c +++ b/dlls/riched20/richole.c @@ -564,14 +564,29 @@ static HRESULT WINAPI ITextRange_fnSetText(ITextRange *me, BSTR bstr) return E_NOTIMPL; } +static HRESULT range_GetChar(ME_TextEditor *editor, ME_Cursor *cursor, LONG *pch) +{ + WCHAR wch[2]; + + ME_GetTextW(editor, wch, 1, cursor, 1, FALSE, cursor->pRun->next->type == diTextEnd); + *pch = wch[0]; + + return S_OK; +} + static HRESULT WINAPI ITextRange_fnGetChar(ITextRange *me, LONG *pch) { ITextRangeImpl *This = impl_from_ITextRange(me); + ME_Cursor cursor; + if (!This->reOle) return CO_E_RELEASED; + TRACE("%p\n", pch); + if (!pch) + return E_INVALIDARG; - FIXME("not implemented %p\n", This); - return E_NOTIMPL; + ME_CursorFromCharOfs(This->reOle->editor, This->start, &cursor); + return range_GetChar(This->reOle->editor, &cursor, pch); } static HRESULT WINAPI ITextRange_fnSetChar(ITextRange *me, LONG ch) @@ -1551,11 +1566,16 @@ static HRESULT WINAPI ITextSelection_fnSetText(ITextSelection *me, BSTR bstr) static HRESULT WINAPI ITextSelection_fnGetChar(ITextSelection *me, LONG *pch) { ITextSelectionImpl *This = impl_from_ITextSelection(me); + ME_Cursor *start = NULL, *end = NULL; + if (!This->reOle) return CO_E_RELEASED; + TRACE("%p\n", pch); + if (!pch) + return E_INVALIDARG; - FIXME("not implemented\n"); - return E_NOTIMPL; + ME_GetSelection(This->reOle->editor, &start, &end); + return range_GetChar(This->reOle->editor, start, pch); } static HRESULT WINAPI ITextSelection_fnSetChar(ITextSelection *me, LONG ch) diff --git a/dlls/riched20/tests/richole.c b/dlls/riched20/tests/richole.c index f56a14a..152d144 100644 --- a/dlls/riched20/tests/richole.c +++ b/dlls/riched20/tests/richole.c @@ -518,6 +518,74 @@ static void test_ITextDocument_Range(void) ITextRange_Release(txtRge); } +static void test_ITextSelection_GetChar(void) +{ + HWND w; + IRichEditOle *reOle = NULL; + ITextDocument *txtDoc = NULL; + ITextSelection *txtSel = NULL; + HRESULT hres; + LONG pch = 0xdeadbeef; + static const CHAR test_text1[] = "TestSomeText"; + + create_interfaces(&w, &reOle, &txtDoc, &txtSel); + SendMessageA(w, WM_SETTEXT, 0, (LPARAM)test_text1); + +#define TEST_TXTSEL_GETCHAR(first, lim, expected_char) \ + SendMessageA(w, EM_SETSEL, first, lim); \ + pch = 0xdeadbeef; \ + hres = ITextSelection_GetChar(txtSel, &pch); \ + ok(hres == S_OK, "ITextSelection_GetChar\n"); \ + ok(pch == expected_char, "got wrong char: %c\n", pch); + + TEST_TXTSEL_GETCHAR(0, 4, 'T') + TEST_TXTSEL_GETCHAR(0, 0, 'T') + TEST_TXTSEL_GETCHAR(12, 12, '\r') + TEST_TXTSEL_GETCHAR(13, 13, '\r') + + hres = ITextSelection_GetChar(txtSel, NULL); + ok(hres == E_INVALIDARG, "ITextSelection_GetChar\n"); + + release_interfaces(&w, &reOle, &txtDoc, &txtSel); +} + +static void test_ITextRange_GetChar(void) +{ + HWND w; + IRichEditOle *reOle = NULL; + ITextDocument *txtDoc = NULL; + ITextRange *txtRge = NULL; + HRESULT hres; + LONG pch = 0xdeadbeef; + int first, lim; + static const CHAR test_text1[] = "TestSomeText"; + +#define TEST_TXTRGE_GETCHAR(first, lim, expected_char) \ + create_interfaces(&w, &reOle, &txtDoc, NULL); \ + SendMessageA(w, WM_SETTEXT, 0, (LPARAM)test_text1); \ + ITextDocument_Range(txtDoc, first, lim, &txtRge); \ + pch = 0xdeadbeef; \ + hres = ITextRange_GetChar(txtRge, &pch); \ + ok(hres == S_OK, "ITextRange_GetChar\n"); \ + ok(pch == expected_char, "got wrong char: %c\n", pch); \ + ITextRange_Release(txtRge); \ + release_interfaces(&w, &reOle, &txtDoc, NULL); + + TEST_TXTRGE_GETCHAR(0, 4, 'T') + TEST_TXTRGE_GETCHAR(0, 0, 'T') + TEST_TXTRGE_GETCHAR(12, 12, '\r') + TEST_TXTRGE_GETCHAR(13, 13, '\r') + + create_interfaces(&w, &reOle, &txtDoc, NULL); + SendMessageA(w, WM_SETTEXT, 0, (LPARAM)test_text1); + first = 12, lim = 12; + ITextDocument_Range(txtDoc, first, lim, &txtRge); + hres = ITextRange_GetChar(txtRge, NULL); + ok(hres == E_INVALIDARG, "ITextRange_GetChar\n"); + ITextRange_Release(txtRge); + release_interfaces(&w, &reOle, &txtDoc, NULL); +} + START_TEST(richole) { /* Must explicitly LoadLibrary(). The test has no references to functions in @@ -528,5 +596,7 @@ START_TEST(richole) test_Interfaces(); test_ITextDocument_Open(); test_ITextSelection_GetText(); + test_ITextSelection_GetChar(); test_ITextDocument_Range(); + test_ITextRange_GetChar(); }