Jactry Zeng : riched20: Some cleanup for CHARFORMAT convertor functions.

Alexandre Julliard julliard at winehq.org
Mon Jul 16 14:40:00 CDT 2018


Module: wine
Branch: master
Commit: 8d506cb216023996ea84fc2c336fe74c325ade56
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=8d506cb216023996ea84fc2c336fe74c325ade56

Author: Jactry Zeng <jzeng at codeweavers.com>
Date:   Fri Jul 13 17:11:35 2018 +0800

riched20: Some cleanup for CHARFORMAT convertor functions.

Signed-off-by: Jactry Zeng <jzeng at codeweavers.com>
Signed-off-by: Huw Davies <huw at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/riched20/editor.c | 18 +++++++++---------
 dlls/riched20/editor.h |  4 ++--
 dlls/riched20/style.c  | 37 ++++++++++++++++++++-----------------
 3 files changed, 31 insertions(+), 28 deletions(-)

diff --git a/dlls/riched20/editor.c b/dlls/riched20/editor.c
index 820b038..8020117 100644
--- a/dlls/riched20/editor.c
+++ b/dlls/riched20/editor.c
@@ -3901,17 +3901,17 @@ LRESULT ME_HandleMessage(ME_TextEditor *editor, UINT msg, WPARAM wParam,
     return editor->nEventMask;
   case EM_SETCHARFORMAT:
   {
-    CHARFORMAT2W buf, *p;
+    CHARFORMAT2W p;
     BOOL bRepaint = TRUE;
-    p = ME_ToCF2W(&buf, (CHARFORMAT2W *)lParam);
-    if (p == NULL) return 0;
+    if (!cfany_to_cf2w(&p, (CHARFORMAT2W *)lParam))
+      return 0;
     if (wParam & SCF_ALL) {
       if (editor->mode & TM_PLAINTEXT) {
-        ME_SetDefaultCharFormat(editor, p);
+        ME_SetDefaultCharFormat(editor, &p);
       } else {
         ME_Cursor start;
         ME_SetCursorToStart(editor, &start);
-        ME_SetCharFormat(editor, &start, NULL, p);
+        ME_SetCharFormat(editor, &start, NULL, &p);
         editor->nModifyStep = 1;
       }
     } else if (wParam & SCF_SELECTION) {
@@ -3923,13 +3923,13 @@ LRESULT ME_HandleMessage(ME_TextEditor *editor, UINT msg, WPARAM wParam,
         ME_MoveCursorWords(editor, &end, +1);
         start = end;
         ME_MoveCursorWords(editor, &start, -1);
-        ME_SetCharFormat(editor, &start, &end, p);
+        ME_SetCharFormat(editor, &start, &end, &p);
       }
       bRepaint = ME_IsSelection(editor);
-      ME_SetSelectionCharFormat(editor, p);
+      ME_SetSelectionCharFormat(editor, &p);
       if (bRepaint) editor->nModifyStep = 1;
     } else { /* SCF_DEFAULT */
-      ME_SetDefaultCharFormat(editor, p);
+      ME_SetDefaultCharFormat(editor, &p);
     }
     ME_CommitUndo(editor);
     if (bRepaint)
@@ -3953,7 +3953,7 @@ LRESULT ME_HandleMessage(ME_TextEditor *editor, UINT msg, WPARAM wParam,
       ME_GetDefaultCharFormat(editor, &tmp);
     else
       ME_GetSelectionCharFormat(editor, &tmp);
-    ME_CopyToCFAny(dst, &tmp);
+    cf2w_to_cfany(dst, &tmp);
     return tmp.dwMask;
   }
   case EM_SETPARAFORMAT:
diff --git a/dlls/riched20/editor.h b/dlls/riched20/editor.h
index 0f0e56e..141c63a 100644
--- a/dlls/riched20/editor.h
+++ b/dlls/riched20/editor.h
@@ -61,8 +61,8 @@ void ME_SaveTempStyle(ME_TextEditor *editor, ME_Style *style) DECLSPEC_HIDDEN;
 void ME_ClearTempStyle(ME_TextEditor *editor) DECLSPEC_HIDDEN;
 void ME_DumpStyleToBuf(CHARFORMAT2W *pFmt, char buf[2048]) DECLSPEC_HIDDEN;
 void ME_DumpStyle(ME_Style *s) DECLSPEC_HIDDEN;
-CHARFORMAT2W *ME_ToCF2W(CHARFORMAT2W *to, CHARFORMAT2W *from) DECLSPEC_HIDDEN;
-void ME_CopyToCFAny(CHARFORMAT2W *to, CHARFORMAT2W *from) DECLSPEC_HIDDEN;
+BOOL cfany_to_cf2w(CHARFORMAT2W *to, const CHARFORMAT2W *from) DECLSPEC_HIDDEN;
+BOOL cf2w_to_cfany(CHARFORMAT2W *to, const CHARFORMAT2W *from) DECLSPEC_HIDDEN;
 void ME_CopyCharFormat(CHARFORMAT2W *pDest, const CHARFORMAT2W *pSrc) DECLSPEC_HIDDEN; /* only works with 2W structs */
 void ME_CharFormatFromLogFont(HDC hDC, const LOGFONTW *lf, CHARFORMAT2W *fmt) DECLSPEC_HIDDEN; /* ditto */
 
diff --git a/dlls/riched20/style.c b/dlls/riched20/style.c
index 0b85d69..97e98a7 100644
--- a/dlls/riched20/style.c
+++ b/dlls/riched20/style.c
@@ -33,7 +33,7 @@ static int all_refs = 0;
  *   sizeof(char[AW])
  */
 
-CHARFORMAT2W *ME_ToCF2W(CHARFORMAT2W *to, CHARFORMAT2W *from)
+BOOL cfany_to_cf2w(CHARFORMAT2W *to, const CHARFORMAT2W *from)
 {
   if (from->cbSize == sizeof(CHARFORMATA))
   {
@@ -43,7 +43,7 @@ CHARFORMAT2W *ME_ToCF2W(CHARFORMAT2W *to, CHARFORMAT2W *from)
     if (f->dwMask & CFM_FACE) {
       MultiByteToWideChar(CP_ACP, 0, f->szFaceName, -1, to->szFaceName, sizeof(to->szFaceName)/sizeof(WCHAR));
     }
-    return to;
+    return TRUE;
   }
   if (from->cbSize == sizeof(CHARFORMATW))
   {
@@ -52,7 +52,7 @@ CHARFORMAT2W *ME_ToCF2W(CHARFORMAT2W *to, CHARFORMAT2W *from)
     /* theoretically, we don't need to zero the remaining memory */
     ZeroMemory(&to->wWeight, sizeof(CHARFORMAT2W)-FIELD_OFFSET(CHARFORMAT2W, wWeight));
     to->cbSize = sizeof(CHARFORMAT2W);
-    return to;
+    return TRUE;
   }
   if (from->cbSize == sizeof(CHARFORMAT2A))
   {
@@ -65,13 +65,18 @@ CHARFORMAT2W *ME_ToCF2W(CHARFORMAT2W *to, CHARFORMAT2W *from)
     /* copy the rest of the 2A structure to 2W */
     CopyMemory(&to->wWeight, &f->wWeight, sizeof(CHARFORMAT2A)-FIELD_OFFSET(CHARFORMAT2A, wWeight));
     to->cbSize = sizeof(CHARFORMAT2W);
-    return to;
+    return TRUE;
+  }
+  if (from->cbSize == sizeof(CHARFORMAT2W))
+  {
+    CopyMemory(to, from, sizeof(CHARFORMAT2W));
+    return TRUE;
   }
 
-  return (from->cbSize >= sizeof(CHARFORMAT2W)) ? from : NULL;
+  return FALSE;
 }
 
-static CHARFORMAT2W *ME_ToCFAny(CHARFORMAT2W *to, CHARFORMAT2W *from)
+BOOL cf2w_to_cfany(CHARFORMAT2W *to, const CHARFORMAT2W *from)
 {
   assert(from->cbSize == sizeof(CHARFORMAT2W));
   if (to->cbSize == sizeof(CHARFORMATA))
@@ -80,14 +85,14 @@ static CHARFORMAT2W *ME_ToCFAny(CHARFORMAT2W *to, CHARFORMAT2W *from)
     CopyMemory(t, from, FIELD_OFFSET(CHARFORMATA, szFaceName));
     WideCharToMultiByte(CP_ACP, 0, from->szFaceName, -1, t->szFaceName, sizeof(t->szFaceName), NULL, NULL);
     t->cbSize = sizeof(*t); /* it was overwritten by CopyMemory */
-    return to;
+    return TRUE;
   }
   if (to->cbSize == sizeof(CHARFORMATW))
   {
     CHARFORMATW *t = (CHARFORMATW *)to;
     CopyMemory(t, from, sizeof(*t));
     t->cbSize = sizeof(*t); /* it was overwritten by CopyMemory */
-    return to;
+    return TRUE;
   }
   if (to->cbSize == sizeof(CHARFORMAT2A))
   {
@@ -99,16 +104,14 @@ static CHARFORMAT2W *ME_ToCFAny(CHARFORMAT2W *to, CHARFORMAT2W *from)
     /* copy the rest of the 2A structure to 2W */
     CopyMemory(&t->wWeight, &from->wWeight, sizeof(CHARFORMAT2W)-FIELD_OFFSET(CHARFORMAT2W,wWeight));
     t->cbSize = sizeof(*t); /* it was overwritten by CopyMemory */
-    return to;
+    return TRUE;
   }
-  assert(to->cbSize >= sizeof(CHARFORMAT2W));
-  return from;
-}
-
-void ME_CopyToCFAny(CHARFORMAT2W *to, CHARFORMAT2W *from)
-{
-  if (ME_ToCFAny(to, from) == from)
-    CopyMemory(to, from, to->cbSize);
+  if (to->cbSize == sizeof(CHARFORMAT2W))
+  {
+    CopyMemory(to, from, sizeof(CHARFORMAT2W));
+    return TRUE;
+  }
+  return FALSE;
 }
 
 ME_Style *ME_MakeStyle(CHARFORMAT2W *style)




More information about the wine-cvs mailing list