Dylan Smith : richedit: Use width from EM_SETTARGETDEVICE for wrapping.

Alexandre Julliard julliard at winehq.org
Mon Feb 2 09:01:21 CST 2009


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

Author: Dylan Smith <dylan.ah.smith at gmail.com>
Date:   Mon Feb  2 01:32:20 2009 -0500

richedit: Use width from EM_SETTARGETDEVICE for wrapping.

The width for EM_SETTARGETDEVICE is used by some applications to set the
wrapping width to a certain distance in twips.  This can be used even
though the target device is ignored.

---

 dlls/riched20/context.c      |    6 +++++-
 dlls/riched20/editor.c       |   15 ++++++++++++---
 dlls/riched20/editstr.h      |    6 ++++--
 dlls/riched20/tests/editor.c |    4 ++--
 dlls/riched20/wrap.c         |    2 +-
 dlls/riched32/tests/editor.c |    4 ++--
 6 files changed, 26 insertions(+), 11 deletions(-)

diff --git a/dlls/riched20/context.c b/dlls/riched20/context.c
index 6d4a2a9..93d5caa 100644
--- a/dlls/riched20/context.c
+++ b/dlls/riched20/context.c
@@ -22,7 +22,7 @@
 
 void ME_InitContext(ME_Context *c, ME_TextEditor *editor, HDC hDC)
 {
-  c->nSequence = editor->nSequence++;  
+  c->nSequence = editor->nSequence++;
   c->hDC = hDC;
   c->editor = editor;
   c->pt.x = 0;
@@ -35,6 +35,10 @@ void ME_InitContext(ME_Context *c, ME_TextEditor *editor, HDC hDC)
   } else {
       c->dpi.cx = c->dpi.cy = 96;
   }
+  if (editor->nAvailWidth)
+      c->nAvailWidth = ME_twips2pointsX(c, editor->nAvailWidth);
+  else
+      c->nAvailWidth = c->rcView.right - c->rcView.left;
 }
 
 void ME_DestroyContext(ME_Context *c)
diff --git a/dlls/riched20/editor.c b/dlls/riched20/editor.c
index 574118a..f875385 100644
--- a/dlls/riched20/editor.c
+++ b/dlls/riched20/editor.c
@@ -4332,14 +4332,23 @@ LRESULT ME_HandleMessage(ME_TextEditor *editor, UINT msg, WPARAM wParam,
     if (wParam == 0)
     {
       BOOL new = (lParam == 0);
-      if (editor->bWordWrap != new)
+      if (editor->nAvailWidth || editor->bWordWrap != new)
       {
         editor->bWordWrap = new;
+        editor->nAvailWidth = 0; /* wrap to client area */
         ME_RewrapRepaint(editor);
       }
+    } else {
+      int width = max(0, lParam);
+      if (!editor->bWordWrap || editor->nAvailWidth != width)
+      {
+        editor->nAvailWidth = width;
+        editor->bWordWrap = TRUE;
+        ME_RewrapRepaint(editor);
+      }
+      FIXME("EM_SETTARGETDEVICE doesn't use non-NULL target devices\n");
     }
-    else FIXME("Unsupported yet non NULL device in EM_SETTARGETDEVICE\n");
-    break;
+    return TRUE;
   default:
   do_default:
     *phresult = S_FALSE;
diff --git a/dlls/riched20/editstr.h b/dlls/riched20/editstr.h
index a645075..63ef7f9 100644
--- a/dlls/riched20/editstr.h
+++ b/dlls/riched20/editstr.h
@@ -342,6 +342,7 @@ typedef struct tagME_TextEditor
   SIZE sizeWindow;
   int nTotalLength, nLastTotalLength;
   int nTotalWidth, nLastTotalWidth;
+  int nAvailWidth; /* 0 = wrap to client area, else wrap width in twips */
   int nUDArrowX;
   int nSequence;
   COLORREF rgbBackColor;
@@ -396,6 +397,7 @@ typedef struct tagME_Context
   RECT rcView;
   HBRUSH hbrMargin;
   SIZE dpi;
+  int nAvailWidth;
 
   /* those are valid inside ME_WrapTextParagraph and related */
   POINT ptFirstRun;
@@ -413,9 +415,9 @@ typedef struct tagME_WrapContext
   POINT pt;
   BOOL bOverflown, bWordWrap;
   ME_DisplayItem *pRowStart;
-  
+
   ME_DisplayItem *pLastSplittableRun;
   POINT ptLastSplittableRun;
-} ME_WrapContext;  
+} ME_WrapContext;
 
 #endif
diff --git a/dlls/riched20/tests/editor.c b/dlls/riched20/tests/editor.c
index 29d3124..f8da3fa 100644
--- a/dlls/riched20/tests/editor.c
+++ b/dlls/riched20/tests/editor.c
@@ -5939,12 +5939,12 @@ static void test_word_wrap(void)
 
     /* Test the effect of EM_SETTARGETDEVICE on word wrap. */
     res = SendMessage(hwnd, EM_SETTARGETDEVICE, 0, 1);
-    todo_wine ok(res, "EM_SETTARGETDEVICE failed (returned %d).\n", res);
+    ok(res, "EM_SETTARGETDEVICE failed (returned %d).\n", res);
     pos = SendMessage(hwnd, EM_CHARFROMPOS, 0, (LPARAM) &point);
     ok(!pos, "pos=%d indicating word wrap when none is expected.\n", pos);
 
     res = SendMessage(hwnd, EM_SETTARGETDEVICE, 0, 0);
-    todo_wine ok(res, "EM_SETTARGETDEVICE failed (returned %d).\n", res);
+    ok(res, "EM_SETTARGETDEVICE failed (returned %d).\n", res);
     pos = SendMessage(hwnd, EM_CHARFROMPOS, 0, (LPARAM) &point);
     ok(pos, "pos=%d indicating no word wrap when it is expected.\n", pos);
     DestroyWindow(hwnd);
diff --git a/dlls/riched20/wrap.c b/dlls/riched20/wrap.c
index 4edbbb2..a2da5eb 100644
--- a/dlls/riched20/wrap.c
+++ b/dlls/riched20/wrap.c
@@ -77,7 +77,7 @@ static void ME_BeginRow(ME_WrapContext *wc, ME_DisplayItem *para)
         - (wc->nRow ? wc->nLeftMargin : wc->nFirstMargin) - wc->nRightMargin;
     wc->bWordWrap = TRUE;
   } else {
-    wc->nAvailWidth = wc->context->rcView.right - wc->context->rcView.left
+    wc->nAvailWidth = wc->context->nAvailWidth
         - (wc->nRow ? wc->nLeftMargin : wc->nFirstMargin) - wc->nRightMargin;
   }
   wc->pt.x = wc->context->pt.x;
diff --git a/dlls/riched32/tests/editor.c b/dlls/riched32/tests/editor.c
index ac98d16..e81f033 100644
--- a/dlls/riched32/tests/editor.c
+++ b/dlls/riched32/tests/editor.c
@@ -897,12 +897,12 @@ static void test_word_wrap(void)
 
     /* Test the effect of EM_SETTARGETDEVICE on word wrap. */
     res = SendMessage(hwnd, EM_SETTARGETDEVICE, 0, 1);
-    todo_wine ok(res, "EM_SETTARGETDEVICE failed (returned %d).\n", res);
+    ok(res, "EM_SETTARGETDEVICE failed (returned %d).\n", res);
     pos = SendMessage(hwnd, EM_CHARFROMPOS, 0, (LPARAM) &point);
     ok(!pos, "pos=%d indicating word wrap when none is expected.\n", pos);
 
     res = SendMessage(hwnd, EM_SETTARGETDEVICE, 0, 0);
-    todo_wine ok(res, "EM_SETTARGETDEVICE failed (returned %d).\n", res);
+    ok(res, "EM_SETTARGETDEVICE failed (returned %d).\n", res);
     pos = SendMessage(hwnd, EM_CHARFROMPOS, 0, (LPARAM) &point);
     ok(pos, "pos=%d indicating no word wrap when it is expected.\n", pos);
     DestroyWindow(hwnd);




More information about the wine-cvs mailing list