[PATCH 5/5] riched20: Partially implement ITextServices_TxGetNaturalSize().

Jactry Zeng jzeng at codeweavers.com
Tue May 22 02:31:04 CDT 2018


Signed-off-by: Jactry Zeng <jzeng at codeweavers.com>
---
 dlls/riched20/tests/txtsrv.c | 59 ++++++++++++++++++++++++++++++++++++++++++--
 dlls/riched20/txtsrv.c       | 33 +++++++++++++++++++++++--
 2 files changed, 88 insertions(+), 4 deletions(-)

diff --git a/dlls/riched20/tests/txtsrv.c b/dlls/riched20/tests/txtsrv.c
index d6c888629a..20c15072bf 100644
--- a/dlls/riched20/tests/txtsrv.c
+++ b/dlls/riched20/tests/txtsrv.c
@@ -423,9 +423,10 @@ static HRESULT WINAPI ITextHostImpl_TxGetPropertyBits(ITextHost *iface,
                                                       DWORD *pdwBits)
 {
     ITextHostTestImpl *This = impl_from_ITextHost(iface);
+    DWORD bits = TXTBIT_MULTILINE | TXTBIT_WORDWRAP;
     TRACECALL("Call to TxGetPropertyBits(%p, dwMask=0x%08x, pdwBits=%p)\n",
               This, dwMask, pdwBits);
-    *pdwBits = 0;
+    *pdwBits = bits & dwMask;
     return S_OK;
 }
 
@@ -728,6 +729,9 @@ static void test_TxGetNaturalSize(void)
     HRESULT result;
     SIZEL psizelExtent = {-1,-1};
     static const WCHAR test_text[] = {'T','e','s','t','S','o','m','e','T','e','x','t',0};
+    static const WCHAR test_text1[] = {'T','e','x','t',0};
+    static const WCHAR long_text[] = {'T','e','s','t',' ','a',' ','l','o','n','g',' ','l',
+                                      'i','n','e',' ','s','t','r','i','n','g',0};
     LONG width, height;
     HDC hdcDraw;
     HWND hwnd;
@@ -762,7 +766,58 @@ static void test_TxGetNaturalSize(void)
         win_skip("ITextServices_TxGetNaturalSize isn't available on this platform.\n");
         goto cleanup;
     }
-    todo_wine CHECK_TXGETNATURALSIZE(result, width, height, 83, 70, 13);
+    CHECK_TXGETNATURALSIZE(result, width, height, 83, 70, 13);
+
+    psizelExtent.cx = 1; psizelExtent.cy = 1;
+    width = rect.right - rect.left;
+    height = 0;
+    result = ITextServices_TxGetNaturalSize(txtserv, DVASPECT_CONTENT,
+                                            hdcDraw, NULL, NULL,
+                                            TXTNS_FITTOCONTENT, &psizelExtent,
+                                            &width, &height);
+    CHECK_TXGETNATURALSIZE(result, width, height, 83, 70, 13);
+
+    psizelExtent.cx = 0; psizelExtent.cy = 0;
+    width = rect.right - rect.left;
+    height = 0;
+    result = ITextServices_TxGetNaturalSize(txtserv, DVASPECT_CONTENT,
+                                            hdcDraw, NULL, NULL,
+                                            TXTNS_FITTOCONTENT, &psizelExtent,
+                                            &width, &height);
+    CHECK_TXGETNATURALSIZE(result, width, height, 0, 0, 0);
+
+    psizelExtent.cx = -1; psizelExtent.cy = -1;
+    result = ITextServices_TxGetNaturalSize(txtserv, DVASPECT_CONTENT,
+                                            hdcDraw, NULL, NULL,
+                                            TXTNS_FITTOCONTENT, &psizelExtent,
+                                            NULL, NULL);
+    ok(result == E_INVALIDARG, "ITextServices_TxGetNaturalSize should fail: 0x%08x.\n", result);
+
+    /* Test with a long line string */
+    result = ITextServices_TxSetText(txtserv, long_text);
+    ok(result == S_OK, "ITextServices_TxSetText failed (result = %x)\n", result);
+
+    psizelExtent.cx = -1; psizelExtent.cy = -1;
+    width = rect.right - rect.left;
+    height = 0;
+    result = ITextServices_TxGetNaturalSize(txtserv, DVASPECT_CONTENT,
+                                            hdcDraw, NULL, NULL,
+                                            TXTNS_FITTOCONTENT, &psizelExtent,
+                                            &width, &height);
+    CHECK_TXGETNATURALSIZE(result, width, height, 89, 73, 26);
+
+    /* Test with another string */
+    result = ITextServices_TxSetText(txtserv, test_text1);
+    ok(result == S_OK, "ITextServices_TxSetText failed (result = %x)\n", result);
+
+    psizelExtent.cx = -1; psizelExtent.cy = -1;
+    width = rect.right - rect.left;
+    height = 0;
+    result = ITextServices_TxGetNaturalSize(txtserv, DVASPECT_CONTENT,
+                                            hdcDraw, NULL, NULL,
+                                            TXTNS_FITTOCONTENT, &psizelExtent,
+                                            &width, &height);
+    CHECK_TXGETNATURALSIZE(result, width, height, 26, 22, 13);
 
 cleanup:
     ReleaseDC(NULL,hdcDraw);
diff --git a/dlls/riched20/txtsrv.c b/dlls/riched20/txtsrv.c
index eb61e4eff6..461a2723fb 100644
--- a/dlls/riched20/txtsrv.c
+++ b/dlls/riched20/txtsrv.c
@@ -320,8 +320,37 @@ DECLSPEC_HIDDEN HRESULT WINAPI fnTextSrv_TxGetNaturalSize(ITextServices *iface,
 {
    ITextServicesImpl *This = impl_from_ITextServices(iface);
 
-   FIXME("%p: STUB\n", This);
-   return E_NOTIMPL;
+   if (!pwidth || !pheight)
+      return E_INVALIDARG;
+
+   TRACE("(%p)->(%p, %x, %p, %p, %p, %x, %p, %p, %p\n)", This, iface, dwAspect, hdcDraw,
+         hicTargetDev, ptd, dwMode, psizelExtent, pwidth, pheight);
+
+   if (dwAspect != DVASPECT_CONTENT)
+      FIXME("Unsupported aspect: %x\n", dwAspect);
+   if (hicTargetDev)
+      FIXME("Unsupported hicTargetDev: %p\n", hicTargetDev);
+   if (ptd)
+      FIXME("Unsupported ptd: %p\n", ptd);
+   if (dwMode != TXTNS_FITTOCONTENT)
+      FIXME("Unsupported mode: %x\n", dwMode);
+
+   if (!psizelExtent->cy)
+   {
+      *pwidth = 0;
+      *pheight = 0;
+      return S_OK;
+   }
+
+   SetRectEmpty(&This->editor->rcFormat);
+   This->editor->rcFormat.right = *pwidth;
+   This->editor->rcFormat.bottom = *pheight;
+   ME_MarkAllForWrapping(This->editor);
+   ME_WrapMarkedParagraphs(This->editor, hdcDraw);
+   *pwidth = This->editor->nTotalWidth;
+   *pheight = This->editor->nTotalLength;
+
+   return S_OK;
 }
 
 DECLSPEC_HIDDEN HRESULT WINAPI fnTextSrv_TxGetDropTarget(ITextServices *iface, IDropTarget **ppDropTarget)
-- 
2.15.1 (Apple Git-101)




More information about the wine-devel mailing list