riched20: Implement GetSize().

This commit is contained in:
Nikolay Sivov 2015-05-20 10:26:21 +03:00 committed by Alexandre Julliard
parent a53371497f
commit c48e0519ac
2 changed files with 98 additions and 17 deletions

View File

@ -208,7 +208,47 @@ static const DWORD textfont_prop_masks[] = {
CFM_WEIGHT
};
static HRESULT get_textfont_prop_for_pos(const IRichEditOleImpl *reole, int pos, enum textfont_prop_id propid, LONG *value)
typedef union {
FLOAT f;
LONG l;
} textfont_prop_val;
static inline BOOL is_equal_textfont_prop_value(enum textfont_prop_id propid, textfont_prop_val *left,
textfont_prop_val *right)
{
switch (propid)
{
case FONT_BOLD:
case FONT_ITALIC:
return left->l == right->l;
case FONT_SIZE:
return left->f == right->f;
default:
FIXME("unhandled font property %d\n", propid);
return FALSE;
}
}
static inline void init_textfont_prop_value(enum textfont_prop_id propid, textfont_prop_val *v)
{
switch (propid)
{
case FONT_BOLD:
case FONT_ITALIC:
v->l = tomUndefined;
return;
case FONT_SIZE:
v->f = tomUndefined;
return;
default:
FIXME("unhandled font property %d\n", propid);
v->l = tomUndefined;
return;
}
}
static HRESULT get_textfont_prop_for_pos(const IRichEditOleImpl *reole, int pos, enum textfont_prop_id propid,
textfont_prop_val *value)
{
ME_Cursor from, to;
CHARFORMAT2W fmt;
@ -225,10 +265,13 @@ static HRESULT get_textfont_prop_for_pos(const IRichEditOleImpl *reole, int pos,
switch (propid)
{
case FONT_BOLD:
*value = fmt.dwEffects & CFE_BOLD ? tomTrue : tomFalse;
value->l = fmt.dwEffects & CFE_BOLD ? tomTrue : tomFalse;
break;
case FONT_ITALIC:
*value = fmt.dwEffects & CFE_ITALIC ? tomTrue : tomFalse;
value->l = fmt.dwEffects & CFE_ITALIC ? tomTrue : tomFalse;
break;
case FONT_SIZE:
value->f = fmt.yHeight;
break;
default:
FIXME("unhandled font property %d\n", propid);
@ -238,34 +281,31 @@ static HRESULT get_textfont_prop_for_pos(const IRichEditOleImpl *reole, int pos,
return S_OK;
}
static HRESULT get_textfont_prop(ITextRange *range, enum textfont_prop_id propid, LONG *value)
static HRESULT get_textfont_prop(ITextRange *range, enum textfont_prop_id propid, textfont_prop_val *value)
{
ITextRangeImpl *rng = impl_from_ITextRange(range);
textfont_prop_val v;
HRESULT hr;
LONG v;
int i;
if (!value)
return E_INVALIDARG;
*value = tomUndefined;
if (!rng->reOle)
return CO_E_RELEASED;
init_textfont_prop_value(propid, value);
/* iterate trough a range to see if property value is consistent */
hr = get_textfont_prop_for_pos(rng->reOle, rng->start, propid, &v);
if (FAILED(hr))
return hr;
for (i = rng->start + 1; i < rng->end; i++) {
LONG cur;
textfont_prop_val cur;
hr = get_textfont_prop_for_pos(rng->reOle, i, propid, &cur);
if (FAILED(hr))
return hr;
if (cur != v)
if (!is_equal_textfont_prop_value(propid, &v, &cur))
return S_OK;
}
@ -273,6 +313,32 @@ static HRESULT get_textfont_prop(ITextRange *range, enum textfont_prop_id propid
return S_OK;
}
static HRESULT get_textfont_propf(ITextRange *range, enum textfont_prop_id propid, FLOAT *value)
{
textfont_prop_val v;
HRESULT hr;
if (!value)
return E_INVALIDARG;
hr = get_textfont_prop(range, propid, &v);
*value = v.f;
return hr;
}
static HRESULT get_textfont_propl(ITextRange *range, enum textfont_prop_id propid, LONG *value)
{
textfont_prop_val v;
HRESULT hr;
if (!value)
return E_INVALIDARG;
hr = get_textfont_prop(range, propid, &v);
*value = v.l;
return hr;
}
static HRESULT WINAPI IRichEditOleImpl_inner_fnQueryInterface(IUnknown *iface, REFIID riid, LPVOID *ppvObj)
{
IRichEditOleImpl *This = impl_from_IUnknown(iface);
@ -1770,7 +1836,7 @@ static HRESULT WINAPI TextFont_GetBold(ITextFont *iface, LONG *value)
{
ITextFontImpl *This = impl_from_ITextFont(iface);
TRACE("(%p)->(%p)\n", This, value);
return get_textfont_prop(This->range, FONT_BOLD, value);
return get_textfont_propl(This->range, FONT_BOLD, value);
}
static HRESULT WINAPI TextFont_SetBold(ITextFont *iface, LONG value)
@ -1840,7 +1906,7 @@ static HRESULT WINAPI TextFont_GetItalic(ITextFont *iface, LONG *value)
{
ITextFontImpl *This = impl_from_ITextFont(iface);
TRACE("(%p)->(%p)\n", This, value);
return get_textfont_prop(This->range, FONT_ITALIC, value);
return get_textfont_propl(This->range, FONT_ITALIC, value);
}
static HRESULT WINAPI TextFont_SetItalic(ITextFont *iface, LONG value)
@ -1951,8 +2017,8 @@ static HRESULT WINAPI TextFont_SetShadow(ITextFont *iface, LONG value)
static HRESULT WINAPI TextFont_GetSize(ITextFont *iface, FLOAT *value)
{
ITextFontImpl *This = impl_from_ITextFont(iface);
FIXME("(%p)->(%p): stub\n", This, value);
return E_NOTIMPL;
TRACE("(%p)->(%p)\n", This, value);
return get_textfont_propf(This->range, FONT_SIZE, value);
}
static HRESULT WINAPI TextFont_SetSize(ITextFont *iface, FLOAT value)

View File

@ -1219,6 +1219,7 @@ static void test_GetFont(void)
ITextFont *font, *font2;
CHARFORMAT2A cf;
LONG value;
float size;
HRESULT hr;
HWND hwnd;
BOOL ret;
@ -1263,6 +1264,14 @@ static void test_GetFont(void)
hr = ITextFont_GetItalic(font, NULL);
ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
hr = ITextFont_GetSize(font, NULL);
ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
size = 0.0;
hr = ITextFont_GetSize(font, &size);
ok(hr == S_OK, "got 0x%08x\n", hr);
ok(size > 0.0, "size %.2f\n", size);
/* range is non-italic */
value = tomTrue;
hr = ITextFont_GetItalic(font, &value);
@ -1270,8 +1279,9 @@ static void test_GetFont(void)
ok(value == tomFalse, "got %d\n", value);
cf.cbSize = sizeof(CHARFORMAT2A);
cf.dwMask = CFM_ITALIC;
cf.dwMask = CFM_ITALIC|CFM_SIZE;
cf.dwEffects = CFE_ITALIC;
cf.yHeight = 24.0;
SendMessageA(hwnd, EM_SETSEL, 2, 3);
ret = SendMessageA(hwnd, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&cf);
@ -1283,6 +1293,11 @@ static void test_GetFont(void)
ok(hr == S_OK, "got 0x%08x\n", hr);
ok(value == tomUndefined, "got %d\n", value);
size = 0.0;
hr = ITextFont_GetSize(font, &size);
ok(hr == S_OK, "got 0x%08x\n", hr);
ok(size == tomUndefined, "size %.2f\n", size);
ITextFont_Release(font);
ITextRange_Release(range);
release_interfaces(&hwnd, &reOle, &doc, NULL);