[PATCH 2/2] riched20: Draw OLE objects with IViewObject implementation.

Jinoh Kang wine at gitlab.winehq.org
Fri Jun 10 14:56:56 CDT 2022


From: Jinoh Kang <jinoh.kang.kr at gmail.com>

Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=52752
Signed-off-by: Jinoh Kang <jinoh.kang.kr at gmail.com>
---
 dlls/riched20/richole.c       | 64 +++++++++++++++++++++++++++++++++++
 dlls/riched20/tests/richole.c |  2 --
 2 files changed, 64 insertions(+), 2 deletions(-)

diff --git a/dlls/riched20/richole.c b/dlls/riched20/richole.c
index 936f1c928b3..9d414af8ee2 100644
--- a/dlls/riched20/richole.c
+++ b/dlls/riched20/richole.c
@@ -5656,6 +5656,7 @@ static void convert_sizel(const ME_Context *c, const SIZEL* szl, SIZE* sz)
 void ME_GetOLEObjectSize(const ME_Context *c, ME_Run *run, SIZE *pSize)
 {
   IDataObject*  ido;
+  IViewObject*  ivo;
   FORMATETC     fmt;
   STGMEDIUM     stgm;
   DIBSECTION    dibsect;
@@ -5681,6 +5682,29 @@ void ME_GetOLEObjectSize(const ME_Context *c, ME_Run *run, SIZE *pSize)
     return;
   }
 
+  if (SUCCEEDED(IOleObject_QueryInterface(run->reobj->obj.poleobj, &IID_IViewObject, (void**)&ivo)))
+  {
+    HRESULT hr;
+    SIZEL sizel;
+
+    hr = IOleObject_GetExtent(run->reobj->obj.poleobj, DVASPECT_CONTENT, &sizel);
+    if (FAILED(hr))
+    {
+      WARN("failed to get extent: %#08lx\n", hr);
+      sizel.cx = sizel.cy = 0;
+    }
+
+    convert_sizel(c, &sizel, pSize);
+    if (c->editor->nZoomNumerator != 0)
+    {
+      pSize->cx = MulDiv(pSize->cx, c->editor->nZoomNumerator, c->editor->nZoomDenominator);
+      pSize->cy = MulDiv(pSize->cy, c->editor->nZoomNumerator, c->editor->nZoomDenominator);
+    }
+
+    IViewObject_Release(ivo);
+    return;
+  }
+
   if (IOleObject_QueryInterface(run->reobj->obj.poleobj, &IID_IDataObject, (void**)&ido) != S_OK)
   {
       FIXME("Query Interface IID_IDataObject failed!\n");
@@ -5733,6 +5757,7 @@ void ME_GetOLEObjectSize(const ME_Context *c, ME_Run *run, SIZE *pSize)
 void draw_ole( ME_Context *c, int x, int y, ME_Run *run, BOOL selected )
 {
   IDataObject*  ido;
+  IViewObject*  ivo;
   FORMATETC     fmt;
   STGMEDIUM     stgm;
   DIBSECTION    dibsect;
@@ -5745,6 +5770,45 @@ void draw_ole( ME_Context *c, int x, int y, ME_Run *run, BOOL selected )
 
   assert(run->nFlags & MERF_GRAPHICS);
   assert(run->reobj);
+
+  if (SUCCEEDED(IOleObject_QueryInterface(run->reobj->obj.poleobj, &IID_IViewObject, (void**)&ivo)))
+  {
+    HRESULT hr;
+    SIZEL sizel = run->reobj->obj.sizel;
+
+    if (sizel.cx == 0 && sizel.cy == 0)
+    {
+      hr = IOleObject_GetExtent(run->reobj->obj.poleobj, DVASPECT_CONTENT, &sizel);
+      if (FAILED(hr))
+      {
+        WARN("failed to get extent: %#08lx\n", hr);
+        IViewObject_Release(ivo);
+        return;
+      }
+    }
+
+    convert_sizel(c, &sizel, &sz);
+    if (c->editor->nZoomNumerator != 0)
+    {
+      sz.cx = MulDiv(sz.cx, c->editor->nZoomNumerator, c->editor->nZoomDenominator);
+      sz.cy = MulDiv(sz.cy, c->editor->nZoomNumerator, c->editor->nZoomDenominator);
+    }
+
+    rc.left = x;
+    rc.top = y - sz.cy;
+    rc.right = x + sz.cx;
+    rc.bottom = y;
+
+    hr = IViewObject_Draw(ivo, DVASPECT_CONTENT, -1, 0, 0, 0, c->hDC, (RECTL*)&rc, NULL, NULL, 0);
+    if (FAILED(hr))
+    {
+      WARN("failed to draw object: %#08lx\n", hr);
+    }
+
+    IViewObject_Release(ivo);
+    return;
+  }
+
   if (IOleObject_QueryInterface(run->reobj->obj.poleobj, &IID_IDataObject, (void**)&ido) != S_OK)
   {
     FIXME("Couldn't get interface\n");
diff --git a/dlls/riched20/tests/richole.c b/dlls/riched20/tests/richole.c
index d0ccb8713d6..900c814bce1 100644
--- a/dlls/riched20/tests/richole.c
+++ b/dlls/riched20/tests/richole.c
@@ -4205,7 +4205,6 @@ static void subtest_InsertObject(struct reolecb_obj *callback)
 
   testobj->line = __LINE__;
   UpdateWindow(hwnd);
-  todo_wine
   ok(testobj->draw_count, "expected draw_count to be nonzero, got %d\n", testobj->draw_count);
 
   SendMessageA(hwnd, WM_SETTEXT, 0, (LPARAM)"");
@@ -4222,7 +4221,6 @@ static void subtest_InsertObject(struct reolecb_obj *callback)
 
   testobj->line = __LINE__;
   UpdateWindow(hwnd);
-  todo_wine
   ok(testobj->draw_count, "expected draw_count to be nonzero, got %d\n", testobj->draw_count);
 
   IOleObject_Release(&testobj->IOleObject_iface);
-- 
GitLab

https://gitlab.winehq.org/wine/wine/-/merge_requests/227



More information about the wine-devel mailing list