Nikolay Sivov : riched20: Implement GetName() for ITextFont.
Alexandre Julliard
julliard at wine.codeweavers.com
Thu May 21 07:24:24 CDT 2015
Module: wine
Branch: master
Commit: e6e16eb6323fe7d4c52012df74221d2fcb18ab43
URL: http://source.winehq.org/git/wine.git/?a=commit;h=e6e16eb6323fe7d4c52012df74221d2fcb18ab43
Author: Nikolay Sivov <nsivov at codeweavers.com>
Date: Thu May 21 11:25:24 2015 +0300
riched20: Implement GetName() for ITextFont.
---
dlls/riched20/richole.c | 41 +++++++++++++++++--
dlls/riched20/tests/richole.c | 93 +++++++++++++++++++++++++++++++++++++++++--
2 files changed, 127 insertions(+), 7 deletions(-)
diff --git a/dlls/riched20/richole.c b/dlls/riched20/richole.c
index c9c75b8..215d326 100644
--- a/dlls/riched20/richole.c
+++ b/dlls/riched20/richole.c
@@ -213,7 +213,8 @@ static const DWORD textfont_prop_masks[] = {
typedef union {
FLOAT f;
- LONG l;
+ LONG l;
+ BSTR str;
} textfont_prop_val;
static inline BOOL is_equal_textfont_prop_value(enum textfont_prop_id propid, textfont_prop_val *left,
@@ -230,6 +231,8 @@ static inline BOOL is_equal_textfont_prop_value(enum textfont_prop_id propid, te
case FONT_SUPERSCRIPT:
case FONT_UNDERLINE:
return left->l == right->l;
+ case FONT_NAME:
+ return !strcmpW(left->str, right->str);
case FONT_SIZE:
return left->f == right->f;
default:
@@ -252,6 +255,9 @@ static inline void init_textfont_prop_value(enum textfont_prop_id propid, textfo
case FONT_UNDERLINE:
v->l = tomUndefined;
return;
+ case FONT_NAME:
+ v->str = NULL;
+ return;
case FONT_SIZE:
v->f = tomUndefined;
return;
@@ -291,6 +297,12 @@ static HRESULT get_textfont_prop_for_pos(const IRichEditOleImpl *reole, int pos,
case FONT_LANGID:
value->l = fmt.lcid;
break;
+ case FONT_NAME:
+ /* this case is used exclusively by GetName() */
+ value->str = SysAllocString(fmt.szFaceName);
+ if (!value->str)
+ return E_OUTOFMEMORY;
+ break;
case FONT_SIZE:
value->f = fmt.yHeight;
break;
@@ -1991,8 +2003,31 @@ static HRESULT WINAPI TextFont_SetLanguageID(ITextFont *iface, LONG value)
static HRESULT WINAPI TextFont_GetName(ITextFont *iface, BSTR *value)
{
ITextFontImpl *This = impl_from_ITextFont(iface);
- FIXME("(%p)->(%p): stub\n", This, value);
- return E_NOTIMPL;
+ const IRichEditOleImpl *reole;
+ textfont_prop_val v;
+ LONG start;
+ HRESULT hr;
+
+ TRACE("(%p)->(%p)\n", This, value);
+
+ if (!value)
+ return E_INVALIDARG;
+
+ *value = NULL;
+
+ ITextRange_QueryInterface(This->range, &IID_Igetrichole, (void**)&reole);
+ if (!reole)
+ return CO_E_RELEASED;
+
+ init_textfont_prop_value(FONT_NAME, &v);
+
+ ITextRange_GetStart(This->range, &start);
+ hr = get_textfont_prop_for_pos(reole, start, FONT_NAME, &v);
+ if (FAILED(hr))
+ return hr;
+
+ *value = v.str;
+ return S_OK;
}
static HRESULT WINAPI TextFont_SetName(ITextFont *iface, BSTR value)
diff --git a/dlls/riched20/tests/richole.c b/dlls/riched20/tests/richole.c
index a47d31f..042bef4 100644
--- a/dlls/riched20/tests/richole.c
+++ b/dlls/riched20/tests/richole.c
@@ -130,14 +130,12 @@ static void test_Interfaces(void)
res = SendMessageA(w, EM_GETOLEINTERFACE, 0, (LPARAM)&reOle);
ok(res, "SendMessage\n");
ok(reOle != NULL, "EM_GETOLEINTERFACE\n");
- refcount = get_refcount((IUnknown *)reOle);
- ok(refcount == 2, "got wrong ref count: %d\n", refcount);
+ EXPECT_REF(reOle, 2);
res = SendMessageA(w, EM_GETOLEINTERFACE, 0, (LPARAM)&reOle1);
ok(res == 1, "SendMessage\n");
ok(reOle1 == reOle, "Should not return a new IRichEditOle interface\n");
- refcount = get_refcount((IUnknown *)reOle);
- ok(refcount == 3, "got wrong ref count: %d\n", refcount);
+ EXPECT_REF(reOle, 3);
hres = IRichEditOle_QueryInterface(reOle, &IID_ITextDocument,
(void **) &txtDoc);
@@ -147,12 +145,21 @@ static void test_Interfaces(void)
hres = ITextDocument_GetSelection(txtDoc, NULL);
ok(hres == E_INVALIDARG, "ITextDocument_GetSelection: 0x%x\n", hres);
+ EXPECT_REF(txtDoc, 4);
+
hres = ITextDocument_GetSelection(txtDoc, &txtSel);
ok(hres == S_OK, "got 0x%08x\n", hres);
+ EXPECT_REF(txtDoc, 4);
+ EXPECT_REF(txtSel, 2);
+
hres = ITextDocument_GetSelection(txtDoc, &txtSel2);
ok(hres == S_OK, "got 0x%08x\n", hres);
ok(txtSel2 == txtSel, "got %p, %p\n", txtSel, txtSel2);
+
+ EXPECT_REF(txtDoc, 4);
+ EXPECT_REF(txtSel, 3);
+
ITextSelection_Release(txtSel2);
punk = NULL;
@@ -1415,6 +1422,83 @@ todo_wine {
release_interfaces(&hwnd, &reOle, &doc, NULL);
}
+static void test_ITextFont(void)
+{
+ static const WCHAR sysW[] = {'S','y','s','t','e','m',0};
+ static const WCHAR arialW[] = {'A','r','i','a','l',0};
+ static const CHAR test_text1[] = "TestSomeText";
+ IRichEditOle *reOle = NULL;
+ ITextDocument *doc = NULL;
+ ITextRange *range = NULL;
+ ITextFont *font;
+ CHARFORMAT2A cf;
+ HRESULT hr;
+ HWND hwnd;
+ BOOL ret;
+ BSTR str;
+
+ create_interfaces(&hwnd, &reOle, &doc, NULL);
+ SendMessageA(hwnd, WM_SETTEXT, 0, (LPARAM)test_text1);
+
+ hr = ITextDocument_Range(doc, 0, 10, &range);
+ ok(hr == S_OK, "got 0x%08x\n", hr);
+
+ hr = ITextRange_GetFont(range, &font);
+ ok(hr == S_OK, "got 0x%08x\n", hr);
+
+ hr = ITextFont_GetName(font, NULL);
+ ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
+
+ /* default font name */
+ str = NULL;
+ hr = ITextFont_GetName(font, &str);
+ ok(hr == S_OK, "got 0x%08x\n", hr);
+ ok(!lstrcmpW(str, sysW), "got %s\n", wine_dbgstr_w(str));
+ SysFreeString(str);
+
+ /* change font name for an inner subrange */
+ memset(&cf, 0, sizeof(cf));
+ cf.cbSize = sizeof(cf);
+ cf.dwMask = CFM_FACE;
+ strcpy(cf.szFaceName, "Arial");
+
+ SendMessageA(hwnd, EM_SETSEL, 3, 4);
+ ret = SendMessageA(hwnd, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&cf);
+ ok(ret, "got %d\n", ret);
+
+ /* still original name */
+ str = NULL;
+ hr = ITextFont_GetName(font, &str);
+ ok(hr == S_OK, "got 0x%08x\n", hr);
+ ok(!lstrcmpW(str, sysW), "got %s\n", wine_dbgstr_w(str));
+ SysFreeString(str);
+
+ SendMessageA(hwnd, EM_SETSEL, 1, 2);
+ ret = SendMessageA(hwnd, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&cf);
+ ok(ret, "got %d\n", ret);
+
+ str = NULL;
+ hr = ITextFont_GetName(font, &str);
+ ok(hr == S_OK, "got 0x%08x\n", hr);
+ ok(!lstrcmpW(str, sysW), "got %s\n", wine_dbgstr_w(str));
+ SysFreeString(str);
+
+ /* name is returned for first position within a range */
+ SendMessageA(hwnd, EM_SETSEL, 0, 1);
+ ret = SendMessageA(hwnd, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&cf);
+ ok(ret, "got %d\n", ret);
+
+ str = NULL;
+ hr = ITextFont_GetName(font, &str);
+ ok(hr == S_OK, "got 0x%08x\n", hr);
+ ok(!lstrcmpW(str, arialW), "got %s\n", wine_dbgstr_w(str));
+ SysFreeString(str);
+
+ ITextFont_Release(font);
+ ITextRange_Release(range);
+ release_interfaces(&hwnd, &reOle, &doc, NULL);
+}
+
START_TEST(richole)
{
/* Must explicitly LoadLibrary(). The test has no references to functions in
@@ -1439,4 +1523,5 @@ START_TEST(richole)
test_GetFont();
test_GetPara();
test_dispatch();
+ test_ITextFont();
}
More information about the wine-cvs
mailing list