Commit fa8c384b authored by Nikolay Sivov's avatar Nikolay Sivov Committed by Alexandre Julliard

riched20: Implement GetFont() for selection range.

parent 72ef3679
...@@ -49,6 +49,9 @@ DEFINE_GUID(IID_ITextSelection, 0x8cc497c1, 0xa1df, 0x11ce, 0x80, 0x98, 0x00, 0x ...@@ -49,6 +49,9 @@ DEFINE_GUID(IID_ITextSelection, 0x8cc497c1, 0xa1df, 0x11ce, 0x80, 0x98, 0x00, 0x
DEFINE_GUID(IID_ITextFont, 0x8cc497c3, 0xa1df, 0x11ce, 0x80, 0x98, 0x00, 0xaa, 0x00, 0x47, 0xbe, 0x5d); DEFINE_GUID(IID_ITextFont, 0x8cc497c3, 0xa1df, 0x11ce, 0x80, 0x98, 0x00, 0xaa, 0x00, 0x47, 0xbe, 0x5d);
DEFINE_GUID(IID_ITextPara, 0x8cc497c4, 0xa1df, 0x11ce, 0x80, 0x98, 0x00, 0xaa, 0x00, 0x47, 0xbe, 0x5d); DEFINE_GUID(IID_ITextPara, 0x8cc497c4, 0xa1df, 0x11ce, 0x80, 0x98, 0x00, 0xaa, 0x00, 0x47, 0xbe, 0x5d);
/* private IID used to get back IRichEditOleImpl pointer */
DEFINE_GUID(IID_Igetrichole, 0xe3ce5c7a, 0x8247, 0x4622, 0x81, 0xad, 0x11, 0x81, 0x02, 0xaa, 0x01, 0x30);
typedef struct ITextSelectionImpl ITextSelectionImpl; typedef struct ITextSelectionImpl ITextSelectionImpl;
typedef struct IOleClientSiteImpl IOleClientSiteImpl; typedef struct IOleClientSiteImpl IOleClientSiteImpl;
typedef struct ITextRangeImpl ITextRangeImpl; typedef struct ITextRangeImpl ITextRangeImpl;
...@@ -313,25 +316,29 @@ static HRESULT get_textfont_prop_for_pos(const IRichEditOleImpl *reole, int pos, ...@@ -313,25 +316,29 @@ static HRESULT get_textfont_prop_for_pos(const IRichEditOleImpl *reole, int pos,
static HRESULT get_textfont_prop(ITextRange *range, enum textfont_prop_id propid, textfont_prop_val *value) static HRESULT get_textfont_prop(ITextRange *range, enum textfont_prop_id propid, textfont_prop_val *value)
{ {
ITextRangeImpl *rng = impl_from_ITextRange(range); IRichEditOleImpl *reole;
textfont_prop_val v; textfont_prop_val v;
LONG start, end, i;
HRESULT hr; HRESULT hr;
int i;
if (!rng->reOle) ITextRange_QueryInterface(range, &IID_Igetrichole, (void**)&reole);
if (!reole)
return CO_E_RELEASED; return CO_E_RELEASED;
init_textfont_prop_value(propid, value); init_textfont_prop_value(propid, value);
ITextRange_GetStart(range, &start);
ITextRange_GetEnd(range, &end);
/* iterate trough a range to see if property value is consistent */ /* iterate trough a range to see if property value is consistent */
hr = get_textfont_prop_for_pos(rng->reOle, rng->start, propid, &v); hr = get_textfont_prop_for_pos(reole, start, propid, &v);
if (FAILED(hr)) if (FAILED(hr))
return hr; return hr;
for (i = rng->start + 1; i < rng->end; i++) { for (i = start + 1; i < end; i++) {
textfont_prop_val cur; textfont_prop_val cur;
hr = get_textfont_prop_for_pos(rng->reOle, i, propid, &cur); hr = get_textfont_prop_for_pos(reole, i, propid, &cur);
if (FAILED(hr)) if (FAILED(hr))
return hr; return hr;
...@@ -937,6 +944,8 @@ static const IRichEditOleVtbl revt = { ...@@ -937,6 +944,8 @@ static const IRichEditOleVtbl revt = {
/* ITextRange interface */ /* ITextRange interface */
static HRESULT WINAPI ITextRange_fnQueryInterface(ITextRange *me, REFIID riid, void **ppvObj) static HRESULT WINAPI ITextRange_fnQueryInterface(ITextRange *me, REFIID riid, void **ppvObj)
{ {
ITextRangeImpl *This = impl_from_ITextRange(me);
*ppvObj = NULL; *ppvObj = NULL;
if (IsEqualGUID(riid, &IID_IUnknown) if (IsEqualGUID(riid, &IID_IUnknown)
|| IsEqualGUID(riid, &IID_IDispatch) || IsEqualGUID(riid, &IID_IDispatch)
...@@ -946,6 +955,11 @@ static HRESULT WINAPI ITextRange_fnQueryInterface(ITextRange *me, REFIID riid, v ...@@ -946,6 +955,11 @@ static HRESULT WINAPI ITextRange_fnQueryInterface(ITextRange *me, REFIID riid, v
ITextRange_AddRef(me); ITextRange_AddRef(me);
return S_OK; return S_OK;
} }
else if (IsEqualGUID(riid, &IID_Igetrichole))
{
*ppvObj = This->reOle;
return S_OK;
}
return E_NOINTERFACE; return E_NOINTERFACE;
} }
...@@ -3023,6 +3037,8 @@ static HRESULT WINAPI ITextSelection_fnQueryInterface( ...@@ -3023,6 +3037,8 @@ static HRESULT WINAPI ITextSelection_fnQueryInterface(
REFIID riid, REFIID riid,
void **ppvObj) void **ppvObj)
{ {
ITextSelectionImpl *This = impl_from_ITextSelection(me);
*ppvObj = NULL; *ppvObj = NULL;
if (IsEqualGUID(riid, &IID_IUnknown) if (IsEqualGUID(riid, &IID_IUnknown)
|| IsEqualGUID(riid, &IID_IDispatch) || IsEqualGUID(riid, &IID_IDispatch)
...@@ -3033,6 +3049,11 @@ static HRESULT WINAPI ITextSelection_fnQueryInterface( ...@@ -3033,6 +3049,11 @@ static HRESULT WINAPI ITextSelection_fnQueryInterface(
ITextSelection_AddRef(me); ITextSelection_AddRef(me);
return S_OK; return S_OK;
} }
else if (IsEqualGUID(riid, &IID_Igetrichole))
{
*ppvObj = This->reOle;
return S_OK;
}
return E_NOINTERFACE; return E_NOINTERFACE;
} }
...@@ -3246,14 +3267,19 @@ static HRESULT WINAPI ITextSelection_fnSetEnd(ITextSelection *me, LONG cpLim) ...@@ -3246,14 +3267,19 @@ static HRESULT WINAPI ITextSelection_fnSetEnd(ITextSelection *me, LONG cpLim)
return E_NOTIMPL; return E_NOTIMPL;
} }
static HRESULT WINAPI ITextSelection_fnGetFont(ITextSelection *me, ITextFont **pFont) static HRESULT WINAPI ITextSelection_fnGetFont(ITextSelection *me, ITextFont **font)
{ {
ITextSelectionImpl *This = impl_from_ITextSelection(me); ITextSelectionImpl *This = impl_from_ITextSelection(me);
TRACE("(%p)->(%p)\n", This, font);
if (!This->reOle) if (!This->reOle)
return CO_E_RELEASED; return CO_E_RELEASED;
FIXME("not implemented\n"); if (!font)
return E_NOTIMPL; return E_INVALIDARG;
return create_textfont((ITextRange*)me, font);
} }
static HRESULT WINAPI ITextSelection_fnSetFont(ITextSelection *me, ITextFont *pFont) static HRESULT WINAPI ITextSelection_fnSetFont(ITextSelection *me, ITextFont *pFont)
......
...@@ -114,7 +114,7 @@ static void test_Interfaces(void) ...@@ -114,7 +114,7 @@ static void test_Interfaces(void)
{ {
IRichEditOle *reOle = NULL, *reOle1 = NULL; IRichEditOle *reOle = NULL, *reOle1 = NULL;
ITextDocument *txtDoc = NULL; ITextDocument *txtDoc = NULL;
ITextSelection *txtSel = NULL; ITextSelection *txtSel = NULL, *txtSel2;
IUnknown *punk; IUnknown *punk;
HRESULT hres; HRESULT hres;
LRESULT res; LRESULT res;
...@@ -147,7 +147,13 @@ static void test_Interfaces(void) ...@@ -147,7 +147,13 @@ static void test_Interfaces(void)
hres = ITextDocument_GetSelection(txtDoc, NULL); hres = ITextDocument_GetSelection(txtDoc, NULL);
ok(hres == E_INVALIDARG, "ITextDocument_GetSelection: 0x%x\n", hres); ok(hres == E_INVALIDARG, "ITextDocument_GetSelection: 0x%x\n", hres);
ITextDocument_GetSelection(txtDoc, &txtSel); hres = ITextDocument_GetSelection(txtDoc, &txtSel);
ok(hres == S_OK, "got 0x%08x\n", hres);
hres = ITextDocument_GetSelection(txtDoc, &txtSel2);
ok(hres == S_OK, "got 0x%08x\n", hres);
ok(txtSel2 == txtSel, "got %p, %p\n", txtSel, txtSel2);
ITextSelection_Release(txtSel2);
punk = NULL; punk = NULL;
hres = ITextSelection_QueryInterface(txtSel, &IID_ITextSelection, (void **) &punk); hres = ITextSelection_QueryInterface(txtSel, &IID_ITextSelection, (void **) &punk);
...@@ -1216,6 +1222,7 @@ static void test_GetFont(void) ...@@ -1216,6 +1222,7 @@ static void test_GetFont(void)
IRichEditOle *reOle = NULL; IRichEditOle *reOle = NULL;
ITextDocument *doc = NULL; ITextDocument *doc = NULL;
ITextRange *range = NULL; ITextRange *range = NULL;
ITextSelection *selection;
ITextFont *font, *font2; ITextFont *font, *font2;
CHARFORMAT2A cf; CHARFORMAT2A cf;
LONG value; LONG value;
...@@ -1227,6 +1234,17 @@ static void test_GetFont(void) ...@@ -1227,6 +1234,17 @@ static void test_GetFont(void)
create_interfaces(&hwnd, &reOle, &doc, NULL); create_interfaces(&hwnd, &reOle, &doc, NULL);
SendMessageA(hwnd, WM_SETTEXT, 0, (LPARAM)test_text1); SendMessageA(hwnd, WM_SETTEXT, 0, (LPARAM)test_text1);
hr = ITextDocument_GetSelection(doc, &selection);
ok(hr == S_OK, "got 0x%08x\n", hr);
hr = ITextSelection_GetFont(selection, &font);
ok(hr == S_OK, "got 0x%08x\n", hr);
hr = ITextSelection_GetFont(selection, &font2);
ok(hr == S_OK, "got 0x%08x\n", hr);
ok(font != font2, "got %p, %p\n", font, font2);
ITextFont_Release(font2);
ITextFont_Release(font);
ITextSelection_Release(selection);
EXPECT_REF(reOle, 3); EXPECT_REF(reOle, 3);
EXPECT_REF(doc, 3); EXPECT_REF(doc, 3);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment