user32: factorize graphics driver's CreateWindow [2/2]

Pierre d'Herbemont pdherbemont at free.fr
Thu Dec 7 12:45:24 CST 2006


I am not sure you will like this 2/2 patch because it makes extensive 
use of USER_driver->pSetWindowPos. I am not sure that this is really 
sane. (that's why I broked this into two pieces)

I was thinking having a separate function in user32 to call wineserver's 
set_window_pos.

Pierre.
---
  dlls/user32/win.c         |  123 
+++++++++++++++++++++++++++++++++++++++++++
  dlls/winex11.drv/window.c |  128 
+--------------------------------------------
  2 files changed, 125 insertions(+), 126 deletions(-)
-------------- next part --------------
diff --git a/dlls/user32/win.c b/dlls/user32/win.c
index 9ee1c00..ecc270e 100644
--- a/dlls/user32/win.c
+++ b/dlls/user32/win.c
@@ -865,6 +865,11 @@ static HWND WIN_CreateWindowEx( CREATEST
     HWND hwnd, parent, owner, top_child = 0;
     BOOL unicode = (flags & WIN_ISUNICODE) != 0;
     MDICREATESTRUCTA mdi_cs;
+    HWND insert_after;
+    RECT rect;
+    CBT_CREATEWNDA cbtc;
+    CREATESTRUCTA cbcs;
+    BOOL ret = FALSE;
 
     TRACE("%s %s ex=%08x style=%08x %d,%d %dx%d parent=%p menu=%p inst=%p params=%p\n",
           unicode ? debugstr_w((LPCWSTR)cs->lpszName) : debugstr_a(cs->lpszName),
@@ -1077,6 +1082,124 @@ static HWND WIN_CreateWindowEx( CREATEST
     else SetWindowLongPtrW( hwnd, GWLP_ID, (ULONG_PTR)cs->hMenu );
     WIN_ReleasePtr( wndPtr );
 
+    if (cs->cx > 65535)
+    {
+        ERR( "invalid window width %d\n", cs->cx );
+        cs->cx = 65535;
+    }
+    if (cs->cy > 65535)
+    {
+        ERR( "invalid window height %d\n", cs->cy );
+        cs->cy = 65535;
+    }
+    if (cs->cx < 0)
+    {
+        ERR( "invalid window width %d\n", cs->cx );
+        cs->cx = 0;
+    }
+    if (cs->cy < 0)
+    {
+        ERR( "invalid window height %d\n", cs->cy );
+        cs->cy = 0;
+    }
+
+    /* initialize the dimensions before sending WM_GETMINMAXINFO */
+    SetRect( &rect, cs->x, cs->y, cs->x + cs->cx, cs->y + cs->cy );
+    USER_Driver->pSetWindowPos( hwnd, 0, &rect, &rect, SWP_NOZORDER, NULL );
+
+    /* Call the WH_CBT hook */
+
+    /* the window style passed to the hook must be the real window style,
+     * rather than just the window style that the caller to CreateWindowEx
+     * passed in, so we have to copy the original CREATESTRUCT and get the
+     * the real style. */
+    cbcs = *cs;
+    cbcs.style = GetWindowLongW(hwnd, GWL_STYLE);
+
+    cbtc.lpcs = &cbcs;
+    cbtc.hwndInsertAfter = HWND_TOP;
+    if (HOOK_CallHooks( WH_CBT, HCBT_CREATEWND, (WPARAM)hwnd, (LPARAM)&cbtc, unicode ))
+    {
+        TRACE("CBT-hook returned !0\n");
+        return 0;
+    }
+
+    /* Send the WM_GETMINMAXINFO message and fix the size if needed */
+    if ((cs->style & WS_THICKFRAME) || !(cs->style & (WS_POPUP | WS_CHILD)))
+    {
+        POINT maxSize, maxPos, minTrack, maxTrack;
+
+        WINPOS_GetMinMaxInfo( hwnd, &maxSize, &maxPos, &minTrack, &maxTrack);
+        if (maxSize.x < cs->cx) cs->cx = maxSize.x;
+        if (maxSize.y < cs->cy) cs->cy = maxSize.y;
+        if (cs->cx < 0) cs->cx = 0;
+        if (cs->cy < 0) cs->cy = 0;
+
+        SetRect( &rect, cs->x, cs->y, cs->x + cs->cx, cs->y + cs->cy );
+        if (!USER_Driver->pSetWindowPos( hwnd, 0, &rect, &rect, SWP_NOZORDER, NULL )) return FALSE;
+    }
+
+    /* send WM_NCCREATE */
+    TRACE( "hwnd %p cs %d,%d %dx%d\n", hwnd, cs->x, cs->y, cs->cx, cs->cy );
+    if (unicode)
+        ret = SendMessageW( hwnd, WM_NCCREATE, 0, (LPARAM)cs );
+    else
+        ret = SendMessageA( hwnd, WM_NCCREATE, 0, (LPARAM)cs );
+    if (!ret)
+    {
+        WARN("aborted by WM_xxCREATE!\n");
+        return FALSE;
+    }
+
+    if (!(wndPtr = WIN_GetPtr(hwnd))) return 0;
+
+    /* send WM_NCCALCSIZE */
+    rect = wndPtr->rectWindow;
+    WIN_ReleasePtr( wndPtr );
+
+    SendMessageW( hwnd, WM_NCCALCSIZE, FALSE, (LPARAM)&rect );
+
+    /* yes, even if the CBT hook was called with HWND_TOP */
+    if (!(wndPtr = WIN_GetPtr(hwnd))) return 0;
+
+    insert_after = ((wndPtr->dwStyle & (WS_CHILD|WS_MAXIMIZE)) == WS_CHILD) ? HWND_BOTTOM : HWND_TOP;
+
+    USER_Driver->pSetWindowPos( hwnd, insert_after, &wndPtr->rectWindow, &rect, 0, NULL );
+
+    TRACE( "win %p window %d,%d,%d,%d client %d,%d,%d,%d\n",
+           hwnd, wndPtr->rectWindow.left, wndPtr->rectWindow.top,
+           wndPtr->rectWindow.right, wndPtr->rectWindow.bottom,
+           wndPtr->rectClient.left, wndPtr->rectClient.top,
+           wndPtr->rectClient.right, wndPtr->rectClient.bottom);
+
+    WIN_ReleasePtr( wndPtr );
+
+    if (unicode)
+        ret = (SendMessageW( hwnd, WM_CREATE, 0, (LPARAM)cs ) != -1);
+    else
+        ret = (SendMessageA( hwnd, WM_CREATE, 0, (LPARAM)cs ) != -1);
+
+    if (!ret) return FALSE;
+
+    NotifyWinEvent(EVENT_OBJECT_CREATE, hwnd, OBJID_WINDOW, 0);
+
+    /* Send the size messages */
+
+    if (!(wndPtr = WIN_GetPtr(hwnd)) || wndPtr == WND_OTHER_PROCESS) return FALSE;
+    if (!(wndPtr->flags & WIN_NEED_SIZE))
+    {
+        RECT rect = wndPtr->rectClient;
+        WIN_ReleasePtr( wndPtr );
+        /* send it anyway */
+        if (((rect.right-rect.left) <0) ||((rect.bottom-rect.top)<0))
+            WARN("sending bogus WM_SIZE message 0x%08x\n",
+                 MAKELONG(rect.right-rect.left, rect.bottom-rect.top));
+        SendMessageW( hwnd, WM_SIZE, SIZE_RESTORED,
+                      MAKELONG(rect.right-rect.left, rect.bottom-rect.top));
+        SendMessageW( hwnd, WM_MOVE, 0, MAKELONG( rect.left, rect.top ) );
+    }
+    else WIN_ReleasePtr( wndPtr );
+
     if (!USER_Driver->pCreateWindow( hwnd, cs, unicode))
     {
         WIN_DestroyWindow( hwnd );
diff --git a/dlls/winex11.drv/window.c b/dlls/winex11.drv/window.c
index 5ff01e0..4f1a74c 100644
--- a/dlls/winex11.drv/window.c
+++ b/dlls/winex11.drv/window.c
@@ -1006,134 +1006,10 @@ BOOL X11DRV_CreateWindow( HWND hwnd, CRE
 {
     Display *display = thread_display();
     WND *wndPtr;
-    struct x11drv_win_data *data = NULL;
-    HWND insert_after;
-    RECT rect;
+    struct x11drv_win_data *data;
     RECT window, client;
     LPWSTR text;
     DWORD style;
-    CBT_CREATEWNDA cbtc;
-    CREATESTRUCTA cbcs;
-    BOOL ret = FALSE;
-
-    if (cs->cx > 65535)
-    {
-        ERR( "invalid window width %d\n", cs->cx );
-        cs->cx = 65535;
-    }
-    if (cs->cy > 65535)
-    {
-        ERR( "invalid window height %d\n", cs->cy );
-        cs->cy = 65535;
-    }
-    if (cs->cx < 0)
-    {
-        ERR( "invalid window width %d\n", cs->cx );
-        cs->cx = 0;
-    }
-    if (cs->cy < 0)
-    {
-        ERR( "invalid window height %d\n", cs->cy );
-        cs->cy = 0;
-    }
-
-    /* initialize the dimensions before sending WM_GETMINMAXINFO */
-    SetRect( &rect, cs->x, cs->y, cs->x + cs->cx, cs->y + cs->cy );
-    X11DRV_SetWindowPos( hwnd, 0, &rect, &rect, SWP_NOZORDER, NULL );
-
-    /* Call the WH_CBT hook */
-
-    /* the window style passed to the hook must be the real window style,
-     * rather than just the window style that the caller to CreateWindowEx
-     * passed in, so we have to copy the original CREATESTRUCT and get the
-     * the real style. */
-    cbcs = *cs;
-    cbcs.style = GetWindowLongW(hwnd, GWL_STYLE);
-
-    cbtc.lpcs = &cbcs;
-    cbtc.hwndInsertAfter = HWND_TOP;
-    if (HOOK_CallHooks( WH_CBT, HCBT_CREATEWND, (WPARAM)hwnd, (LPARAM)&cbtc, unicode ))
-    {
-        TRACE("CBT-hook returned !0\n");
-        goto failed;
-    }
-
-    /* Send the WM_GETMINMAXINFO message and fix the size if needed */
-    if ((cs->style & WS_THICKFRAME) || !(cs->style & (WS_POPUP | WS_CHILD)))
-    {
-        POINT maxSize, maxPos, minTrack, maxTrack;
-
-        WINPOS_GetMinMaxInfo( hwnd, &maxSize, &maxPos, &minTrack, &maxTrack);
-        if (maxSize.x < cs->cx) cs->cx = maxSize.x;
-        if (maxSize.y < cs->cy) cs->cy = maxSize.y;
-        if (cs->cx < 0) cs->cx = 0;
-        if (cs->cy < 0) cs->cy = 0;
-
-        SetRect( &rect, cs->x, cs->y, cs->x + cs->cx, cs->y + cs->cy );
-        if (!X11DRV_SetWindowPos( hwnd, 0, &rect, &rect, SWP_NOZORDER, NULL )) return FALSE;
-    }
-
-    /* send WM_NCCREATE */
-    TRACE( "hwnd %p cs %d,%d %dx%d\n", hwnd, cs->x, cs->y, cs->cx, cs->cy );
-    if (unicode)
-        ret = SendMessageW( hwnd, WM_NCCREATE, 0, (LPARAM)cs );
-    else
-        ret = SendMessageA( hwnd, WM_NCCREATE, 0, (LPARAM)cs );
-    if (!ret)
-    {
-        WARN("aborted by WM_xxCREATE!\n");
-        return FALSE;
-    }
-
-    if (!(wndPtr = WIN_GetPtr(hwnd))) return FALSE;
-
-    /* send WM_NCCALCSIZE */
-    rect = wndPtr->rectWindow;
-    WIN_ReleasePtr( wndPtr );
-
-    SendMessageW( hwnd, WM_NCCALCSIZE, FALSE, (LPARAM)&rect );
-
-    /* yes, even if the CBT hook was called with HWND_TOP */
-    if (!(wndPtr = WIN_GetPtr(hwnd))) return FALSE;
-
-    insert_after = ((wndPtr->dwStyle & (WS_CHILD|WS_MAXIMIZE)) == WS_CHILD) ? HWND_BOTTOM : HWND_TOP;
-
-    X11DRV_SetWindowPos( hwnd, insert_after, &wndPtr->rectWindow, &rect, 0, NULL );
-
-    TRACE( "win %p window %d,%d,%d,%d client %d,%d,%d,%d\n",
-           hwnd, wndPtr->rectWindow.left, wndPtr->rectWindow.top,
-           wndPtr->rectWindow.right, wndPtr->rectWindow.bottom,
-           wndPtr->rectClient.left, wndPtr->rectClient.top,
-           wndPtr->rectClient.right, wndPtr->rectClient.bottom);
-
-    WIN_ReleasePtr( wndPtr );
-
-    if (unicode)
-        ret = (SendMessageW( hwnd, WM_CREATE, 0, (LPARAM)cs ) != -1);
-    else
-        ret = (SendMessageA( hwnd, WM_CREATE, 0, (LPARAM)cs ) != -1);
-
-    if (!ret) return FALSE;
-
-    NotifyWinEvent(EVENT_OBJECT_CREATE, hwnd, OBJID_WINDOW, 0);
-
-    /* Send the size messages */
-
-    if (!(wndPtr = WIN_GetPtr(hwnd)) || wndPtr == WND_OTHER_PROCESS) return FALSE;
-    if (!(wndPtr->flags & WIN_NEED_SIZE))
-    {
-        RECT rect = wndPtr->rectClient;
-        WIN_ReleasePtr( wndPtr );
-        /* send it anyway */
-        if (((rect.right-rect.left) <0) ||((rect.bottom-rect.top)<0))
-            WARN("sending bogus WM_SIZE message 0x%08x\n",
-                 MAKELONG(rect.right-rect.left, rect.bottom-rect.top));
-        SendMessageW( hwnd, WM_SIZE, SIZE_RESTORED,
-                      MAKELONG(rect.right-rect.left, rect.bottom-rect.top));
-        SendMessageW( hwnd, WM_MOVE, 0, MAKELONG( rect.left, rect.top ) );
-    }
-    else WIN_ReleasePtr( wndPtr );
-
     
     if (!(data = alloc_win_data( display, hwnd ))) return FALSE;
     
@@ -1143,7 +1019,7 @@ BOOL X11DRV_CreateWindow( HWND hwnd, CRE
     client = wndPtr->rectClient;
     WIN_ReleasePtr( wndPtr );
 
-    X11DRV_SetWindowPos(hwnd, insert_after, &window, &client, SWP_NOZORDER, NULL);
+    X11DRV_SetWindowPos(hwnd, 0, &window, &client, SWP_NOZORDER, NULL);
 
     /* create an X window if it's a top level window */
     if (GetAncestor( hwnd, GA_PARENT ) == GetDesktopWindow())


More information about the wine-patches mailing list