From 4cb7578d0b32dd8f8aec58077156076c9d1810ee Mon Sep 17 00:00:00 2001 From: Huw Davies Date: Mon, 21 Aug 2017 12:31:44 +0100 Subject: [PATCH] riched20: Move the editor initialization out of CreateTextHost(). Signed-off-by: Huw Davies Signed-off-by: Alexandre Julliard --- dlls/riched20/editor.c | 32 ++++++++++++++++++++++++++------ dlls/riched20/txthost.c | 21 ++++++--------------- 2 files changed, 32 insertions(+), 21 deletions(-) diff --git a/dlls/riched20/editor.c b/dlls/riched20/editor.c index 1ce444e6047..f5b9e4c0d07 100644 --- a/dlls/riched20/editor.c +++ b/dlls/riched20/editor.c @@ -4792,6 +4792,30 @@ LRESULT ME_HandleMessage(ME_TextEditor *editor, UINT msg, WPARAM wParam, return 0L; } +static BOOL create_windowed_editor(HWND hwnd, CREATESTRUCTW *create, BOOL emulate_10) +{ + ITextHost *host = ME_CreateTextHost( hwnd, create, emulate_10 ); + ME_TextEditor *editor; + + if (!host) return FALSE; + + editor = ME_MakeEditor( host, emulate_10, create->style ); + if (!editor) + { + ITextHost_Release( host ); + return FALSE; + } + + editor->exStyleFlags = GetWindowLongW( hwnd, GWL_EXSTYLE ); + editor->styleFlags |= GetWindowLongW( hwnd, GWL_STYLE ) & ES_WANTRETURN; + editor->hWnd = hwnd; /* FIXME: Remove editor's dependence on hWnd */ + editor->hwndParent = create->hwndParent; + + SetWindowLongPtrW( hwnd, 0, (LONG_PTR)editor ); + + return TRUE; +} + static LRESULT RichEditWndProc_common(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, BOOL unicode) { @@ -4808,11 +4832,9 @@ static LRESULT RichEditWndProc_common(HWND hWnd, UINT msg, WPARAM wParam, if (msg == WM_NCCREATE) { CREATESTRUCTW *pcs = (CREATESTRUCTW *)lParam; - ITextHost *texthost; TRACE("WM_NCCREATE: hWnd %p style 0x%08x\n", hWnd, pcs->style); - texthost = ME_CreateTextHost(hWnd, pcs, FALSE); - return texthost != NULL; + return create_windowed_editor( hWnd, pcs, FALSE ); } else { @@ -4938,12 +4960,10 @@ LRESULT WINAPI RichEdit10ANSIWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM { if (msg == WM_NCCREATE && !GetWindowLongPtrW(hWnd, 0)) { - ITextHost *texthost; CREATESTRUCTW *pcs = (CREATESTRUCTW *)lParam; TRACE("WM_NCCREATE: hWnd %p style 0x%08x\n", hWnd, pcs->style); - texthost = ME_CreateTextHost(hWnd, pcs, TRUE); - return texthost != NULL; + return create_windowed_editor( hWnd, pcs, TRUE ); } return RichEditANSIWndProc(hWnd, msg, wParam, lParam); } diff --git a/dlls/riched20/txthost.c b/dlls/riched20/txthost.c index 0e51ecf850b..ccd554d6e0b 100644 --- a/dlls/riched20/txthost.c +++ b/dlls/riched20/txthost.c @@ -45,23 +45,14 @@ static const ITextHostVtbl textHostVtbl; ITextHost *ME_CreateTextHost(HWND hwnd, CREATESTRUCTW *cs, BOOL bEmulateVersion10) { ITextHostImpl *texthost; + texthost = CoTaskMemAlloc(sizeof(*texthost)); - if (texthost) - { - ME_TextEditor *editor; + if (!texthost) return NULL; - texthost->ITextHost_iface.lpVtbl = &textHostVtbl; - texthost->ref = 1; - texthost->hWnd = hwnd; - texthost->bEmulateVersion10 = bEmulateVersion10; - - editor = ME_MakeEditor(&texthost->ITextHost_iface, bEmulateVersion10, cs->style); - editor->exStyleFlags = GetWindowLongW(hwnd, GWL_EXSTYLE); - editor->styleFlags |= GetWindowLongW(hwnd, GWL_STYLE) & ES_WANTRETURN; - editor->hWnd = hwnd; /* FIXME: Remove editor's dependence on hWnd */ - editor->hwndParent = cs->hwndParent; - SetWindowLongPtrW(hwnd, 0, (LONG_PTR)editor); - } + texthost->ITextHost_iface.lpVtbl = &textHostVtbl; + texthost->ref = 1; + texthost->hWnd = hwnd; + texthost->bEmulateVersion10 = bEmulateVersion10; return &texthost->ITextHost_iface; }