From: Jactry Zeng Subject: [PATCH 2/2] riched20: Implement ITextSelection::GetChar. Message-Id: <541660A8.1000205@jactry.com> Date: Mon, 15 Sep 2014 11:44:40 +0800 --- dlls/riched20/richole.c | 9 +++++++-- dlls/riched20/tests/richole.c | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/dlls/riched20/richole.c b/dlls/riched20/richole.c index 4f462a6..1ff35cf 100644 --- a/dlls/riched20/richole.c +++ b/dlls/riched20/richole.c @@ -1566,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 65c452b..c4ba549 100644 --- a/dlls/riched20/tests/richole.c +++ b/dlls/riched20/tests/richole.c @@ -555,6 +555,37 @@ static void test_ITextRange_GetChar(void) release_interfaces(&w, &reOle, &txtDoc, NULL); } +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); +} + START_TEST(richole) { /* Must explicitly LoadLibrary(). The test has no references to functions in @@ -565,6 +596,7 @@ START_TEST(richole) test_Interfaces(); test_ITextDocument_Open(); test_ITextSelection_GetText(); + test_ITextSelection_GetChar(); test_ITextDocument_Range(); test_ITextRange_GetChar(); }