From 8089d980d1b07fbed1d2ba47e888e83b33c47977 Mon Sep 17 00:00:00 2001 From: Dylan Smith Date: Sun, 11 Jan 2009 02:59:31 -0500 Subject: [PATCH] richedit: Set bEmulateVersion10 initially to avoid retroactive changes. 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. --- dlls/riched20/editor.c | 38 ++++++++++++++++++-------------------- dlls/riched20/editor.h | 2 +- dlls/riched20/para.c | 4 ++-- 3 files changed, 21 insertions(+), 23 deletions(-) diff --git a/dlls/riched20/editor.c b/dlls/riched20/editor.c index 9e5f1235bfc..47e50b3a7a1 100644 --- a/dlls/riched20/editor.c +++ b/dlls/riched20/editor.c @@ -2620,11 +2620,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); @@ -2658,7 +2659,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; @@ -2915,8 +2919,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; } @@ -4309,23 +4313,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 df82073af67..4016ba2e60d 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 9cf4d97c0b4..f786d8c3c92 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); }