From: Jactry Zeng Subject: [PATCH 2/2] riched20: Implement ITextSelection::GetFont. (rebase) Message-Id: <541C289C.9030307@codeweavers.com> Date: Fri, 19 Sep 2014 20:59:08 +0800 Superseded patch 106606. --- dlls/riched20/richole.c | 16 +++++++++++++-- dlls/riched20/tests/richole.c | 46 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 2 deletions(-) diff --git a/dlls/riched20/richole.c b/dlls/riched20/richole.c index 992f6e0..026b291 100644 --- a/dlls/riched20/richole.c +++ b/dlls/riched20/richole.c @@ -2476,11 +2476,23 @@ static HRESULT WINAPI ITextSelection_fnSetEnd(ITextSelection *me, LONG cpLim) static HRESULT WINAPI ITextSelection_fnGetFont(ITextSelection *me, ITextFont **pFont) { ITextSelectionImpl *This = impl_from_ITextSelection(me); + ITextFontImpl *txtFont = NULL; + HRESULT hres; + if (!This->reOle) return CO_E_RELEASED; - FIXME("not implemented\n"); - return E_NOTIMPL; + TRACE("%p\n", This); + if (!pFont) + return E_INVALIDARG; + hres = CreateITextFont(&txtFont); + if (SUCCEEDED(hres)) + { + txtFont->txtSel = This; + ITextSelection_AddRef(me); + *pFont = &txtFont->ITextFont_iface; + } + return hres; } static HRESULT WINAPI ITextSelection_fnSetFont(ITextSelection *me, ITextFont *pFont) diff --git a/dlls/riched20/tests/richole.c b/dlls/riched20/tests/richole.c index b25ec02..623b2a3 100644 --- a/dlls/riched20/tests/richole.c +++ b/dlls/riched20/tests/richole.c @@ -987,6 +987,51 @@ static void test_ITextRange_GetFont(void) ITextFont_Release(txtFont); } +static void test_ITextSelection_GetFont(void) +{ + HWND w; + IRichEditOle *reOle = NULL; + ITextDocument *txtDoc = NULL; + ITextSelection *txtSel = NULL; + ITextFont *txtFont = NULL, *txtFont1 = NULL; + HRESULT hres; + int first, lim; + int refcount; + static const CHAR test_text1[] = "TestSomeText"; + LONG value; + + create_interfaces(&w, &reOle, &txtDoc, &txtSel); + SendMessageA(w, WM_SETTEXT, 0, (LPARAM)test_text1); + + first = 4, lim = 4; + SendMessageA(w, EM_SETSEL, first, lim); + refcount = get_refcount((IUnknown *)txtSel); + ok(refcount == 2, "got wrong ref count: %d\n", refcount); + + hres = ITextSelection_GetFont(txtSel, &txtFont); + ok(hres == S_OK, "ITextSelection_GetFont\n"); + refcount = get_refcount((IUnknown *)txtFont); + ok(refcount == 1, "got wrong ref count: %d\n", refcount); + refcount = get_refcount((IUnknown *)txtSel); + ok(refcount == 3, "got wrong ref count: %d\n", refcount); + + hres = ITextSelection_GetFont(txtSel, &txtFont1); + ok(hres == S_OK, "ITextSelection_GetFont\n"); + ok(txtFont1 != txtFont, "A new pointer should be return\n"); + refcount = get_refcount((IUnknown *)txtFont1); + ok(refcount == 1, "got wrong ref count: %d\n", refcount); + ITextFont_Release(txtFont1); + refcount = get_refcount((IUnknown *)txtSel); + ok(refcount == 3, "got wrong ref count: %d\n", refcount); + + release_interfaces(&w, &reOle, &txtDoc, &txtSel); + + hres = ITextFont_GetOutline(txtFont, &value); + ok(hres == CO_E_RELEASED, "ITextFont after ITextDocument destroyed\n"); + + ITextFont_Release(txtFont); +} + START_TEST(richole) { /* Must explicitly LoadLibrary(). The test has no references to functions in @@ -1000,6 +1045,7 @@ START_TEST(richole) test_ITextSelection_GetChar(); test_ITextSelection_GetStart_GetEnd(); test_ITextSelection_Collapse(); + test_ITextSelection_GetFont(); test_ITextDocument_Range(); test_ITextRange_GetChar(); test_ITextRange_GetStart_GetEnd();