[PATCH] richedit: fix modify step setting in EM_SETCHARFORMAT. Fixes crash #2 with Perfect! TextEdit. EM_SETCHARFORMAT with wParam==0 sets default char format and does NOT set modify step flag. EM_SETCHARFORMAT with wParam==SCF_SELECTION only sets modify step flag when selection is nonempty. EM_GETMODIFY returns -1, not 1, when modify flag is set. Tests for the above behavior.

Alex Villacís Lasso alex at karlalex.palosanto.com
Sun Apr 27 13:17:28 CDT 2008


---
 dlls/riched20/editor.c       |   10 ++++---
 dlls/riched20/tests/editor.c |   58 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 64 insertions(+), 4 deletions(-)

diff --git a/dlls/riched20/editor.c b/dlls/riched20/editor.c
index 9f357bb..56596d5 100644
--- a/dlls/riched20/editor.c
+++ b/dlls/riched20/editor.c
@@ -2206,7 +2206,7 @@ static LRESULT RichEditWndProc_common(HWND hWnd, UINT msg, WPARAM wParam,
     return lColor;
   }
   case EM_GETMODIFY:
-    return editor->nModifyStep == 0 ? 0 : 1;
+    return editor->nModifyStep == 0 ? 0 : -1;
   case EM_SETMODIFY:
   {
     if (wParam)
@@ -2249,8 +2249,10 @@ static LRESULT RichEditWndProc_common(HWND hWnd, UINT msg, WPARAM wParam,
     } else if (wParam == SCF_ALL) {
       if (editor->mode & TM_PLAINTEXT)
         ME_SetDefaultCharFormat(editor, p);
-      else
+      else {
         ME_SetCharFormat(editor, 0, ME_GetTextLength(editor), p);
+        editor->nModifyStep = 1;
+      }
     } else if (editor->mode & TM_PLAINTEXT) {
       return 0;
     } else {
@@ -2258,8 +2260,8 @@ static LRESULT RichEditWndProc_common(HWND hWnd, UINT msg, WPARAM wParam,
       ME_GetSelection(editor, &from, &to);
       bRepaint = (from != to);
       ME_SetSelectionCharFormat(editor, p);
-    }
-    editor->nModifyStep = 1;
+      if (from != to) editor->nModifyStep = 1;
+    }    
     ME_CommitUndo(editor);
     if (bRepaint)
       ME_RewrapRepaint(editor);
diff --git a/dlls/riched20/tests/editor.c b/dlls/riched20/tests/editor.c
index 56a23f6..211103c 100644
--- a/dlls/riched20/tests/editor.c
+++ b/dlls/riched20/tests/editor.c
@@ -438,6 +438,57 @@ static void test_EM_SETCHARFORMAT(void)
              (LPARAM) &cf2);
   ok(rc == 1, "EM_SETCHARFORMAT returned %d instead of 1\n", rc);
 
+  cf2.cbSize = sizeof(CHARFORMAT2);
+  SendMessage(hwndRichEdit, EM_GETCHARFORMAT, (WPARAM) SCF_DEFAULT,
+             (LPARAM) &cf2);
+
+  /* Test state of modify flag before and after valid EM_SETCHARFORMAT */
+  cf2.cbSize = sizeof(CHARFORMAT2);
+  SendMessage(hwndRichEdit, EM_GETCHARFORMAT, (WPARAM) SCF_DEFAULT,
+             (LPARAM) &cf2);
+  cf2.dwMask = CFM_ITALIC | cf2.dwMask;
+  cf2.dwEffects = CFE_ITALIC ^ cf2.dwEffects;
+
+  /* wParam==0 is default char format, does not set modify */
+  SendMessage(hwndRichEdit, WM_SETTEXT, 0, (LPARAM)NULL);
+  rc = SendMessage(hwndRichEdit, EM_GETMODIFY, 0, 0);
+  ok(rc == 0, "Text marked as modified, expected not modified!\n");
+  rc = SendMessage(hwndRichEdit, EM_SETCHARFORMAT, 0, (LPARAM) &cf2);
+  ok(rc == 1, "EM_SETCHARFORMAT returned %d instead of 1\n", rc);
+  rc = SendMessage(hwndRichEdit, EM_GETMODIFY, 0, 0);
+  ok(rc == 0, "Text marked as modified, expected not modified!\n");
+
+  /* wParam==SCF_SELECTION sets modify if nonempty selection */
+  SendMessage(hwndRichEdit, WM_SETTEXT, 0, (LPARAM)NULL);
+  rc = SendMessage(hwndRichEdit, EM_GETMODIFY, 0, 0);
+  ok(rc == 0, "Text marked as modified, expected not modified!\n");
+  rc = SendMessage(hwndRichEdit, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM) &cf2);
+  ok(rc == 1, "EM_SETCHARFORMAT returned %d instead of 1\n", rc);
+  rc = SendMessage(hwndRichEdit, EM_GETMODIFY, 0, 0);
+  ok(rc == 0, "Text marked as modified, expected not modified!\n");
+
+  SendMessage(hwndRichEdit, WM_SETTEXT, 0, (LPARAM)"wine");
+  rc = SendMessage(hwndRichEdit, EM_GETMODIFY, 0, 0);
+  ok(rc == 0, "Text marked as modified, expected not modified!\n");
+  rc = SendMessage(hwndRichEdit, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM) &cf2);
+  ok(rc == 1, "EM_SETCHARFORMAT returned %d instead of 1\n", rc);
+  rc = SendMessage(hwndRichEdit, EM_GETMODIFY, 0, 0);
+  ok(rc == 0, "Text marked as modified, expected not modified!\n");
+  SendMessage(hwndRichEdit, EM_SETSEL, 0, 2);
+  rc = SendMessage(hwndRichEdit, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM) &cf2);
+  ok(rc == 1, "EM_SETCHARFORMAT returned %d instead of 1\n", rc);
+  rc = SendMessage(hwndRichEdit, EM_GETMODIFY, 0, 0);
+  ok(rc == -1, "Text not marked as modified, expected modified! (%d)\n", rc);
+
+  /* wParam==SCF_ALL sets modify regardless of whether text is present */
+  SendMessage(hwndRichEdit, WM_SETTEXT, 0, (LPARAM)NULL);
+  rc = SendMessage(hwndRichEdit, EM_GETMODIFY, 0, 0);
+  ok(rc == 0, "Text marked as modified, expected not modified!\n");
+  rc = SendMessage(hwndRichEdit, EM_SETCHARFORMAT, (WPARAM) SCF_ALL, (LPARAM) &cf2);
+  ok(rc == 1, "EM_SETCHARFORMAT returned %d instead of 1\n", rc);
+  rc = SendMessage(hwndRichEdit, EM_GETMODIFY, 0, 0);
+  ok(rc == -1, "Text not marked as modified, expected modified! (%d)\n", rc);
+
   DestroyWindow(hwndRichEdit);
 }
 
@@ -472,10 +523,17 @@ static void test_EM_SETTEXTMODE(void)
   cf2.dwMask = CFM_ITALIC | cf2.dwMask;
   cf2.dwEffects = CFE_ITALIC ^ cf2.dwEffects;
 
+  rc = SendMessage(hwndRichEdit, EM_GETMODIFY, 0, 0);
+  ok(rc == 0, "Text marked as modified, expected not modified!\n");
+
   /*EM_SETCHARFORMAT is not yet fully implemented for all WPARAMs in wine;
   however, SCF_ALL has been implemented*/
   rc = SendMessage(hwndRichEdit, EM_SETCHARFORMAT, (WPARAM) SCF_ALL, (LPARAM) &cf2);
   ok(rc == 1, "EM_SETCHARFORMAT returned %d instead of 1\n", rc);
+
+  rc = SendMessage(hwndRichEdit, EM_GETMODIFY, 0, 0);
+  ok(rc == -1, "Text not marked as modified, expected modified! (%d)\n", rc);
+
   SendMessage(hwndRichEdit, WM_SETTEXT, 0, (LPARAM) "wine");
 
   /*Select the string "wine"*/
-- 
1.5.4.1


--------------000203000903060809020307--



More information about the wine-patches mailing list