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

Jactry Zeng jzeng at codeweavers.com
Wed Jun 6 04:24:37 CDT 2018


Superseded patch 146573.

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

diff --git a/dlls/riched20/tests/txtsrv.c b/dlls/riched20/tests/txtsrv.c
index ac06aa868e..f9c545938a 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;
 }
 
@@ -739,6 +740,13 @@ 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 long_text[] = {'T','e','s','t','W','i','t','h','A','L','o','n','g',
+                                      'L','i','n','e','S','t','r','i','n','g',0};
+    static const WCHAR long_text1[] = {'T','e','s','t','W','i','t','h','Y','e','t','A','n',
+                                       'o','t','h','o','r','L', 'o','n','g','L','i','n','e',
+                                       'S','t','r','i','n','g','W','h','i','c','h','H','a',
+                                       's','M','o','r','e','T','h','a','n','T','w','o','L',
+                                       'i','n','e','s',0};
     LONG width, height;
     HDC hdcDraw;
     HWND hwnd;
@@ -782,7 +790,49 @@ static void test_TxGetNaturalSize(void)
     height = 0;
     result = ITextServices_TxGetNaturalSize(txtserv, DVASPECT_CONTENT, hdcDraw, NULL, NULL,
                                             TXTNS_FITTOCONTENT, &psizelExtent, &width, &height);
-    todo_wine CHECK_TXGETNATURALSIZE(result, width, height, hdcDraw, test_text);
+    CHECK_TXGETNATURALSIZE(result, width, height, hdcDraw, test_text);
+
+    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, hdcDraw, test_text);
+
+    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);
+    ok(result == S_OK, "ITextServices_TxGetNaturalSize failed: 0x%08x.\n", result);
+    ok(!width && !height, "got wrong width and height: (%d, %d) expected (0, 0).\n", width, height);
+
+    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: 0x%08x.\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, hdcDraw, long_text);
+
+    /* Test with string which has more than two lines */
+    result = ITextServices_TxSetText(txtserv, long_text1);
+    ok(result == S_OK, "ITextServices_TxSetText failed result: 0x%08x.\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, hdcDraw, long_text1);
 
     ReleaseDC(hwnd, hdcDraw);
     DestroyWindow(hwnd);
diff --git a/dlls/riched20/txtsrv.c b/dlls/riched20/txtsrv.c
index eb61e4eff6..f417f46ad1 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.17.1




More information about the wine-devel mailing list