Nikolay Sivov : riched20: Implement GetFont() for selection range.

Alexandre Julliard julliard at wine.codeweavers.com
Wed May 20 10:04:12 CDT 2015


Module: wine
Branch: master
Commit: fa8c384b3bbcbc3ad7f47d5bbd345baee9042185
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=fa8c384b3bbcbc3ad7f47d5bbd345baee9042185

Author: Nikolay Sivov <nsivov at codeweavers.com>
Date:   Wed May 20 11:41:34 2015 +0300

riched20: Implement GetFont() for selection range.

---

 dlls/riched20/richole.c       | 44 ++++++++++++++++++++++++++++++++++---------
 dlls/riched20/tests/richole.c | 22 ++++++++++++++++++++--
 2 files changed, 55 insertions(+), 11 deletions(-)

diff --git a/dlls/riched20/richole.c b/dlls/riched20/richole.c
index 1fbbc0a..c9c75b8 100644
--- a/dlls/riched20/richole.c
+++ b/dlls/riched20/richole.c
@@ -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_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 IOleClientSiteImpl IOleClientSiteImpl;
 typedef struct ITextRangeImpl ITextRangeImpl;
@@ -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)
 {
-    ITextRangeImpl *rng = impl_from_ITextRange(range);
+    IRichEditOleImpl *reole;
     textfont_prop_val v;
+    LONG start, end, i;
     HRESULT hr;
-    int i;
 
-    if (!rng->reOle)
+    ITextRange_QueryInterface(range, &IID_Igetrichole, (void**)&reole);
+    if (!reole)
         return CO_E_RELEASED;
 
     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 */
-    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))
         return hr;
 
-    for (i = rng->start + 1; i < rng->end; i++) {
+    for (i = start + 1; i < end; i++) {
         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))
             return hr;
 
@@ -937,6 +944,8 @@ static const IRichEditOleVtbl revt = {
 /* ITextRange interface */
 static HRESULT WINAPI ITextRange_fnQueryInterface(ITextRange *me, REFIID riid, void **ppvObj)
 {
+    ITextRangeImpl *This = impl_from_ITextRange(me);
+
     *ppvObj = NULL;
     if (IsEqualGUID(riid, &IID_IUnknown)
         || IsEqualGUID(riid, &IID_IDispatch)
@@ -946,6 +955,11 @@ static HRESULT WINAPI ITextRange_fnQueryInterface(ITextRange *me, REFIID riid, v
         ITextRange_AddRef(me);
         return S_OK;
     }
+    else if (IsEqualGUID(riid, &IID_Igetrichole))
+    {
+        *ppvObj = This->reOle;
+        return S_OK;
+    }
 
     return E_NOINTERFACE;
 }
@@ -3023,6 +3037,8 @@ static HRESULT WINAPI ITextSelection_fnQueryInterface(
     REFIID riid,
     void **ppvObj)
 {
+    ITextSelectionImpl *This = impl_from_ITextSelection(me);
+
     *ppvObj = NULL;
     if (IsEqualGUID(riid, &IID_IUnknown)
         || IsEqualGUID(riid, &IID_IDispatch)
@@ -3033,6 +3049,11 @@ static HRESULT WINAPI ITextSelection_fnQueryInterface(
         ITextSelection_AddRef(me);
         return S_OK;
     }
+    else if (IsEqualGUID(riid, &IID_Igetrichole))
+    {
+        *ppvObj = This->reOle;
+        return S_OK;
+    }
 
     return E_NOINTERFACE;
 }
@@ -3246,14 +3267,19 @@ static HRESULT WINAPI ITextSelection_fnSetEnd(ITextSelection *me, LONG cpLim)
     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);
+
+    TRACE("(%p)->(%p)\n", This, font);
+
     if (!This->reOle)
         return CO_E_RELEASED;
 
-    FIXME("not implemented\n");
-    return E_NOTIMPL;
+    if (!font)
+        return E_INVALIDARG;
+
+    return create_textfont((ITextRange*)me, font);
 }
 
 static HRESULT WINAPI ITextSelection_fnSetFont(ITextSelection *me, ITextFont *pFont)
diff --git a/dlls/riched20/tests/richole.c b/dlls/riched20/tests/richole.c
index 6ff2fe3..a47d31f 100644
--- a/dlls/riched20/tests/richole.c
+++ b/dlls/riched20/tests/richole.c
@@ -114,7 +114,7 @@ static void test_Interfaces(void)
 {
   IRichEditOle *reOle = NULL, *reOle1 = NULL;
   ITextDocument *txtDoc = NULL;
-  ITextSelection *txtSel = NULL;
+  ITextSelection *txtSel = NULL, *txtSel2;
   IUnknown *punk;
   HRESULT hres;
   LRESULT res;
@@ -147,7 +147,13 @@ static void test_Interfaces(void)
   hres = ITextDocument_GetSelection(txtDoc, NULL);
   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;
   hres = ITextSelection_QueryInterface(txtSel, &IID_ITextSelection, (void **) &punk);
@@ -1216,6 +1222,7 @@ static void test_GetFont(void)
   IRichEditOle *reOle = NULL;
   ITextDocument *doc = NULL;
   ITextRange *range = NULL;
+  ITextSelection *selection;
   ITextFont *font, *font2;
   CHARFORMAT2A cf;
   LONG value;
@@ -1227,6 +1234,17 @@ static void test_GetFont(void)
   create_interfaces(&hwnd, &reOle, &doc, NULL);
   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(doc, 3);
 




More information about the wine-cvs mailing list