Dylan Smith : richedit: Handle to parent window is cached.

Alexandre Julliard julliard at winehq.org
Wed Sep 30 10:56:12 CDT 2009


Module: wine
Branch: master
Commit: 3fe20bdc7ea59b3e5711bed26d86c433109b21e7
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=3fe20bdc7ea59b3e5711bed26d86c433109b21e7

Author: Dylan Smith <dylan.ah.smith at gmail.com>
Date:   Wed Sep 30 10:46:37 2009 -0400

richedit: Handle to parent window is cached.

The parent window for the richedit control on creation is the one that
receives notify messages, even after the parent has been changed using
SetParent.

---

 dlls/riched20/editor.c       |   11 ++++++-----
 dlls/riched20/editor.h       |    2 +-
 dlls/riched20/editstr.h      |    2 +-
 dlls/riched20/tests/editor.c |    2 +-
 dlls/riched20/txthost.c      |   17 +++++++++++------
 5 files changed, 20 insertions(+), 14 deletions(-)

diff --git a/dlls/riched20/editor.c b/dlls/riched20/editor.c
index 97e55ba..11d4925 100644
--- a/dlls/riched20/editor.c
+++ b/dlls/riched20/editor.c
@@ -2035,14 +2035,14 @@ ME_FilterEvent(ME_TextEditor *editor, UINT msg, WPARAM* wParam, LPARAM* lParam)
 {
     MSGFILTER msgf;
 
-    if (!editor->hWnd) return FALSE;
+    if (!editor->hWnd || !editor->hwndParent) return FALSE;
     msgf.nmhdr.hwndFrom = editor->hWnd;
     msgf.nmhdr.idFrom = GetWindowLongW(editor->hWnd, GWLP_ID);
     msgf.nmhdr.code = EN_MSGFILTER;
     msgf.msg = msg;
     msgf.wParam = *wParam;
     msgf.lParam = *lParam;
-    if (SendMessageW(GetParent(editor->hWnd), WM_NOTIFY, msgf.nmhdr.idFrom, (LPARAM)&msgf))
+    if (SendMessageW(editor->hwndParent, WM_NOTIFY, msgf.nmhdr.idFrom, (LPARAM)&msgf))
         return FALSE;
     *wParam = msgf.wParam;
     *lParam = msgf.lParam;
@@ -2598,7 +2598,7 @@ static BOOL ME_ShowContextMenu(ME_TextEditor *editor, int x, int y)
   }
   if(SUCCEEDED(IRichEditOleCallback_GetContextMenu(editor->lpOleCallback, seltype, NULL, &selrange, &menu)))
   {
-    TrackPopupMenu(menu, TPM_LEFTALIGN | TPM_RIGHTBUTTON, x, y, 0, GetParent(editor->hWnd), NULL);
+    TrackPopupMenu(menu, TPM_LEFTALIGN | TPM_RIGHTBUTTON, x, y, 0, editor->hwndParent, NULL);
     DestroyMenu(menu);
   }
   return TRUE;
@@ -2612,6 +2612,7 @@ ME_TextEditor *ME_MakeEditor(ITextHost *texthost, BOOL bEmulateVersion10)
   LONG selbarwidth;
 
   ed->hWnd = NULL;
+  ed->hwndParent = NULL;
   ed->texthost = texthost;
   ed->bEmulateVersion10 = bEmulateVersion10;
   ITextHost_TxGetPropertyBits(texthost,
@@ -4369,7 +4370,7 @@ static LRESULT RichEditWndProc_common(HWND hWnd, UINT msg, WPARAM wParam,
       ITextHost *texthost;
 
       TRACE("WM_NCCREATE: hWnd %p style 0x%08x\n", hWnd, pcs->style);
-      texthost = ME_CreateTextHost(hWnd, FALSE);
+      texthost = ME_CreateTextHost(hWnd, pcs, FALSE);
       return texthost != NULL;
     }
     else if (msg != WM_NCDESTROY)
@@ -4499,7 +4500,7 @@ LRESULT WINAPI RichEdit10ANSIWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM
     CREATESTRUCTW *pcs = (CREATESTRUCTW *)lParam;
 
     TRACE("WM_NCCREATE: hWnd %p style 0x%08x\n", hWnd, pcs->style);
-    texthost = ME_CreateTextHost(hWnd, TRUE);
+    texthost = ME_CreateTextHost(hWnd, pcs, TRUE);
     return texthost != NULL;
   }
   return RichEditANSIWndProc(hWnd, msg, wParam, lParam);
diff --git a/dlls/riched20/editor.h b/dlls/riched20/editor.h
index 7edd86f..8a5304b 100644
--- a/dlls/riched20/editor.h
+++ b/dlls/riched20/editor.h
@@ -271,7 +271,7 @@ struct RTFTable *ME_MakeTableDef(ME_TextEditor *editor);
 void ME_InitTableDef(ME_TextEditor *editor, struct RTFTable *tableDef);
 
 /* txthost.c */
-ITextHost *ME_CreateTextHost(HWND hwnd, BOOL bEmulateVersion10);
+ITextHost *ME_CreateTextHost(HWND hwnd, CREATESTRUCTW *cs, BOOL bEmulateVersion10);
 #ifdef __i386__ /* Use wrappers to perform thiscall on i386 */
 #define TXTHOST_VTABLE(This) (&itextHostStdcallVtbl)
 #else /* __i386__ */
diff --git a/dlls/riched20/editstr.h b/dlls/riched20/editstr.h
index 6258a63..115662c 100644
--- a/dlls/riched20/editstr.h
+++ b/dlls/riched20/editstr.h
@@ -326,7 +326,7 @@ typedef struct tagME_FontCacheItem
 
 typedef struct tagME_TextEditor
 {
-  HWND hWnd;
+  HWND hWnd, hwndParent;
   ITextHost *texthost;
   BOOL bEmulateVersion10;
   ME_TextBuffer *pBuffer;
diff --git a/dlls/riched20/tests/editor.c b/dlls/riched20/tests/editor.c
index e5f6310..15ac461 100644
--- a/dlls/riched20/tests/editor.c
+++ b/dlls/riched20/tests/editor.c
@@ -5741,7 +5741,7 @@ static void test_WM_NOTIFY(void)
     SetWindowLongPtr(hwndRichedit_WM_NOTIFY, GWLP_HWNDPARENT, 0);
     SendMessage(hwndRichedit_WM_NOTIFY, WM_KEYDOWN, VK_RIGHT, 0);
     SendMessage(hwndRichedit_WM_NOTIFY, EM_GETSEL, (WPARAM)&sel_start, (LPARAM)&sel_end);
-    todo_wine ok(sel_start == 1 && sel_end == 1,
+    ok(sel_start == 1 && sel_end == 1,
        "selections is incorrectly at (%d,%d)\n", sel_start, sel_end);
 
     DestroyWindow(hwndRichedit_WM_NOTIFY);
diff --git a/dlls/riched20/txthost.c b/dlls/riched20/txthost.c
index 0ccb177..950d200 100644
--- a/dlls/riched20/txthost.c
+++ b/dlls/riched20/txthost.c
@@ -44,7 +44,7 @@ typedef struct ITextHostImpl {
 
 static const ITextHostVtbl textHostVtbl;
 
-ITextHost *ME_CreateTextHost(HWND hwnd, BOOL bEmulateVersion10)
+ITextHost *ME_CreateTextHost(HWND hwnd, CREATESTRUCTW *cs, BOOL bEmulateVersion10)
 {
     ITextHostImpl *texthost;
     texthost = CoTaskMemAlloc(sizeof(*texthost));
@@ -60,6 +60,7 @@ ITextHost *ME_CreateTextHost(HWND hwnd, BOOL bEmulateVersion10)
         editor = ME_MakeEditor((ITextHost*)texthost, bEmulateVersion10);
         editor->exStyleFlags = GetWindowLongW(hwnd, GWL_EXSTYLE);
         editor->hWnd = hwnd; /* FIXME: Remove editor's dependence on hWnd */
+        editor->hwndParent = cs->hwndParent;
         SetWindowLongPtrW(hwnd, 0, (LONG_PTR)editor);
     }
 
@@ -448,9 +449,13 @@ HRESULT WINAPI ITextHostImpl_TxNotify(ITextHost *iface,
                                       void *pv)
 {
     ITextHostImpl *This = (ITextHostImpl *)iface;
+    ME_TextEditor *editor = (ME_TextEditor*)GetWindowLongPtrW(This->hWnd, 0);
     HWND hwnd = This->hWnd;
-    HWND parent = GetParent(hwnd);
-    UINT id = GetWindowLongW(hwnd, GWLP_ID);
+    UINT id;
+
+    if (!editor || !editor->hwndParent) return S_OK;
+
+    id = GetWindowLongW(hwnd, GWLP_ID);
 
     switch (iNotify)
     {
@@ -471,13 +476,13 @@ HRESULT WINAPI ITextHostImpl_TxNotify(ITextHost *iface,
             info->hwndFrom = hwnd;
             info->idFrom = id;
             info->code = iNotify;
-            SendMessageW(parent, WM_NOTIFY, id, (LPARAM)info);
+            SendMessageW(editor->hwndParent, WM_NOTIFY, id, (LPARAM)info);
             break;
         }
 
         case EN_UPDATE:
             /* Only sent when the window is visible. */
-            if (!IsWindowVisible(This->hWnd))
+            if (!IsWindowVisible(hwnd))
                 break;
             /* Fall through */
         case EN_CHANGE:
@@ -487,7 +492,7 @@ HRESULT WINAPI ITextHostImpl_TxNotify(ITextHost *iface,
         case EN_MAXTEXT:
         case EN_SETFOCUS:
         case EN_VSCROLL:
-            SendMessageW(parent, WM_COMMAND, MAKEWPARAM(id, iNotify), (LPARAM)hwnd);
+            SendMessageW(editor->hwndParent, WM_COMMAND, MAKEWPARAM(id, iNotify), (LPARAM)hwnd);
             break;
 
         case EN_MSGFILTER:




More information about the wine-cvs mailing list