richedit: Set bEmulateVersion10 initially to avoid retroactive changes.

Dylan Smith dylan.ah.smith at gmail.com
Sun Jan 11 01:59:31 CST 2009


Previously the WM_NCCREATE was handled by the as if it was always for
later versions, then the window proc for version 1.0 would make
appropriate changes afterwards.  Instead both versions should call the
same function (e.g. ME_MakeEditor) and provide the value for
bEmulateVersion10 to make the code clearer.

For instance, in ME_MakeFirstParagraph the bEmulateVersion10 variable is
used, but it is always FALSE for this call.  It isn't until execution
returns to RichEdit10ANSIWndProc where this change is made to emulate
version 1.0.
---
 dlls/riched20/editor.c |   38 ++++++++++++++++++--------------------
 dlls/riched20/editor.h |    2 +-
 dlls/riched20/para.c   |    4 ++--
 3 files changed, 21 insertions(+), 23 deletions(-)
-------------- next part --------------
diff --git a/dlls/riched20/editor.c b/dlls/riched20/editor.c
index 563e12e..13b58f1 100644
--- a/dlls/riched20/editor.c
+++ b/dlls/riched20/editor.c
@@ -2583,11 +2583,12 @@ static BOOL ME_ShowContextMenu(ME_TextEditor *editor, int x, int y)
   return TRUE;
 }
 
-ME_TextEditor *ME_MakeEditor(HWND hWnd) {
+ME_TextEditor *ME_MakeEditor(HWND hWnd, BOOL bEmulateVersion10)
+{
   ME_TextEditor *ed = ALLOC_OBJ(ME_TextEditor);
   int i;
   ed->hWnd = hWnd;
-  ed->bEmulateVersion10 = FALSE;
+  ed->bEmulateVersion10 = bEmulateVersion10;
   ed->pBuffer = ME_MakeText();
   ed->nZoomNumerator = ed->nZoomDenominator = 0;
   ME_MakeFirstParagraph(ed);
@@ -2621,7 +2622,10 @@ ME_TextEditor *ME_MakeEditor(HWND hWnd) {
   ed->nParagraphs = 1;
   ed->nLastSelStart = ed->nLastSelEnd = 0;
   ed->pLastSelStartPara = ed->pLastSelEndPara = ME_FindItemFwd(ed->pBuffer->pFirst, diParagraph);
-  ed->bWordWrap = (GetWindowLongW(hWnd, GWL_STYLE) & (WS_HSCROLL|ES_AUTOHSCROLL)) ? FALSE : TRUE;
+  if (ed->bEmulateVersion10)
+    ed->bWordWrap = (GetWindowLongW(hWnd, GWL_STYLE) & ES_AUTOHSCROLL) ? FALSE : TRUE;
+  else
+    ed->bWordWrap = (GetWindowLongW(hWnd, GWL_STYLE) & (WS_HSCROLL|ES_AUTOHSCROLL)) ? FALSE : TRUE;
   ed->bHideSelection = FALSE;
   ed->nInvalidOfs = -1;
   ed->pfnWordBreak = NULL;
@@ -2878,8 +2882,8 @@ static LRESULT RichEditWndProc_common(HWND hWnd, UINT msg, WPARAM wParam,
     if (msg == WM_NCCREATE)
     {
       CREATESTRUCTW *pcs = (CREATESTRUCTW *)lParam;
-      TRACE("WM_NCCREATE: style 0x%08x\n", pcs->style);
-      editor = ME_MakeEditor(hWnd);
+      TRACE("WM_NCCREATE: hWnd %p style 0x%08x\n", hWnd, pcs->style);
+      editor = ME_MakeEditor(hWnd, FALSE);
       SetWindowLongPtrW(hWnd, 0, (LONG_PTR)editor);
       return TRUE;
     }
@@ -4272,23 +4276,17 @@ LRESULT WINAPI RichEditANSIWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lP
  */
 LRESULT WINAPI RichEdit10ANSIWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
 {
-  LRESULT result;
-  
-  /* FIXME: this is NOT the same as 2.0 version */
-  result = RichEditANSIWndProc(hWnd, msg, wParam, lParam);
-  if (msg == WM_NCCREATE)
+  if (msg == WM_NCCREATE && !GetWindowLongPtrW(hWnd, 0))
   {
-    ME_TextEditor *editor = (ME_TextEditor *)GetWindowLongPtrW(hWnd, 0);
-    
-    TRACE("Emulating version 1.0 (hWnd=%p)\n", hWnd);
-    editor->bEmulateVersion10 = TRUE;
-    editor->bWordWrap = (GetWindowLongW(hWnd, GWL_STYLE) & ES_AUTOHSCROLL) ? FALSE : TRUE;
-    editor->pBuffer->pLast->member.para.nCharOfs = 2;
-    assert(editor->pBuffer->pLast->prev->type == diRun);
-    assert(editor->pBuffer->pLast->prev->member.run.nFlags & MERF_ENDPARA);
-    editor->pBuffer->pLast->prev->member.run.nLF = 1;
+    ME_TextEditor *editor;
+    CREATESTRUCTW *pcs = (CREATESTRUCTW *)lParam;
+
+    TRACE("WM_NCCREATE: hWnd %p style 0x%08x\n", hWnd, pcs->style);
+    editor = ME_MakeEditor(hWnd, TRUE);
+    SetWindowLongPtrW(hWnd, 0, (LONG_PTR)editor);
+    return TRUE;
   }
-  return result;
+  return RichEditANSIWndProc(hWnd, msg, wParam, lParam);
 }
 
 void ME_SendOldNotify(ME_TextEditor *editor, int nCode)
diff --git a/dlls/riched20/editor.h b/dlls/riched20/editor.h
index df82073..4016ba2 100644
--- a/dlls/riched20/editor.h
+++ b/dlls/riched20/editor.h
@@ -269,7 +269,7 @@ void ME_CopyReObject(REOBJECT* dst, const REOBJECT* src);
 void ME_DeleteReObject(REOBJECT* reo);
 
 /* editor.c */
-ME_TextEditor *ME_MakeEditor(HWND hWnd);
+ME_TextEditor *ME_MakeEditor(HWND hWnd, BOOL bEmulateVersion10);
 void ME_DestroyEditor(ME_TextEditor *editor);
 LRESULT ME_HandleMessage(ME_TextEditor *editor, UINT msg, WPARAM wParam,
                          LPARAM lParam, BOOL unicode, HRESULT* phresult);
diff --git a/dlls/riched20/para.c b/dlls/riched20/para.c
index 9cf4d97..f786d8c 100644
--- a/dlls/riched20/para.c
+++ b/dlls/riched20/para.c
@@ -67,7 +67,7 @@ void ME_MakeFirstParagraph(ME_TextEditor *editor)
   run = ME_MakeRun(style, ME_MakeString(wszParagraphSign), MERF_ENDPARA);
   run->member.run.nCharOfs = 0;
   run->member.run.nCR = 1;
-  run->member.run.nLF = (editor->bEmulateVersion10) ? 1 : 0;
+  run->member.run.nLF = editor->bEmulateVersion10 ? 1 : 0;
 
   ME_InsertBefore(text->pLast, para);
   ME_InsertBefore(text->pLast, run);
@@ -76,7 +76,7 @@ void ME_MakeFirstParagraph(ME_TextEditor *editor)
   text->pFirst->member.para.next_para = para;
   text->pLast->member.para.prev_para = para;
 
-  text->pLast->member.para.nCharOfs = 1;
+  text->pLast->member.para.nCharOfs = editor->bEmulateVersion10 ? 2 : 1;
 
   ME_DestroyContext(&c, editor->hWnd);
 }


More information about the wine-patches mailing list