deferwindowpos commit
authorMaarten Lankhorst <m.b.lankhorst@gmail.com>
Sat, 13 Dec 2008 23:47:20 +0000 (14 00:47 +0100)
committerMaarten Lankhorst <m.b.lankhorst@gmail.com>
Sat, 27 Dec 2008 20:18:37 +0000 (27 21:18 +0100)
dlls/user32/tests/win.c
dlls/user32/winpos.c

index 0d9d426..8e833f8 100644 (file)
@@ -5349,6 +5349,66 @@ static void test_handles( HWND full_hwnd )
 #endif
 }
 
+static void test_DeferWindowPos( HWND hwnd )
+{
+    HDWP hdwp;
+    BOOL ret;
+
+    SetLastError( 0xdeadbeef );
+    hdwp = BeginDeferWindowPos( -1 );
+    ok(!hdwp, "BeginDeferWindowPos(-1) succeeded\n");
+    ok(GetLastError() == ERROR_INVALID_PARAMETER, "LastError is %u\n", GetLastError());
+
+    if (hdwp) EndDeferWindowPos( hdwp );
+
+    SetLastError( 0xdeadbeef );
+    hdwp = BeginDeferWindowPos( 0 );
+    ok(!hdwp, "BeginDeferWindowPos(0) failed\n");
+    ok(GetLastError() == 0xdeadbeef, "LastError is %u\n", GetLastError());
+    ok(HeapValidate( GetProcessHeap(), 0, hdwp ), "Cannot read from hdwp structure\n");
+    trace("hdwp: %p\n", hdwp);
+
+    if (hdwp)
+    {
+        BOOL visible;
+
+        SetLastError( 0xdeadbeef );
+        hdwp = DeferWindowPos( hdwp, GetDesktopWindow(), NULL, 0, 0, 0, 0, SWP_SHOWWINDOW );
+        ok(!hdwp, "DeferWindowPos(GetDesktopWindow()) succeeded\n");
+        ok(GetLastError() == 0xdeadbeef, "LastError is %u\n", GetLastError());
+        if (hdwp) EndDeferWindowPos( hdwp );
+
+        SetLastError( 0xdeadbeef );
+        hdwp = BeginDeferWindowPos( 1 );
+        ok(!hdwp, "BeginDeferWindowPos(1) failed\n");
+        ok(GetLastError() == 0xdeadbeef, "LastError is %u\n", GetLastError());
+
+        visible = IsWindowVisible( hwnd );
+
+        SetLastError( 0xdeadbeef );
+        hdwp = DeferWindowPos( hdwp, hwnd, NULL, 0, 0, 0, 0, visible ? SWP_HIDEWINDOW : SWP_SHOWWINDOW );
+        ok(!!hdwp, "DeferWindowPos(hwnd) failed\n");
+        ok(GetLastError() == 0xdeadbeef, "LastError is %u\n", GetLastError());
+        if (hdwp)
+        {
+            BOOL nowvisible;
+
+            SetLastError( 0xdeadbeef );
+            ret = EndDeferWindowPos( hdwp );
+            ok(ret, "EndDeferWindowPos failed\n");
+            ok(GetLastError() == 0xdeadbeef, "LastError is %u\n", GetLastError());
+            nowvisible = IsWindowVisible( hwnd );
+            ok(nowvisible != visible, "Window visibility didn't change!\n");
+            ShowWindow( hwnd, visible ? SWP_SHOWWINDOW : SWP_HIDEWINDOW );
+        }
+    }
+
+    SetLastError( 0xdeadbeef );
+    ret = EndDeferWindowPos( NULL );
+    ok(!ret, "EndDeferWindowPos(NULL) succeeded\n");
+    ok(GetLastError() == 0xdeadbeef, "LastError is %u\n", GetLastError());
+}
+
 START_TEST(win)
 {
     HMODULE user32 = GetModuleHandleA( "user32.dll" );
@@ -5398,6 +5458,7 @@ START_TEST(win)
     test_mdi();
     test_icons();
     test_SetWindowPos(hwndMain);
+    test_DeferWindowPos(hwndMain);
     test_SetMenu(hwndMain);
     test_SetFocus(hwndMain);
     test_SetActiveWindow(hwndMain);
index d680cc1..11e5f92 100644 (file)
@@ -2079,9 +2079,13 @@ HDWP WINAPI BeginDeferWindowPos( INT count )
     /* Windows allows zero count, in which case it allocates context for 8 moves */
     if (count == 0) count = 8;
 
-    handle = USER_HEAP_ALLOC( sizeof(DWP) + (count-1)*sizeof(WINDOWPOS) );
-    if (!handle) return 0;
-    pDWP = (DWP *) USER_HEAP_LIN_ADDR( handle );
+    handle = HeapAlloc( GetProcessHeap(), 0, sizeof(DWP) + (count-1)*sizeof(WINDOWPOS) );
+    if (!handle)
+    {
+        SetLastError(ERROR_OUTOFMEMORY);
+        return 0;
+    }
+    pDWP = handle;
     pDWP->actualCount    = 0;
     pDWP->suggestedCount = count;
     pDWP->valid          = TRUE;
@@ -2102,15 +2106,24 @@ HDWP WINAPI DeferWindowPos( HDWP hdwp, HWND hwnd, HWND hwndAfter,
 {
     DWP *pDWP;
     int i;
-    HDWP newhdwp = hdwp,retvalue;
+    HDWP newhdwp = hdwp, retvalue;
 
     TRACE("hdwp %p, hwnd %p, after %p, %d,%d (%dx%d), flags %08x\n",
           hdwp, hwnd, hwndAfter, x, y, cx, cy, flags);
 
-    hwnd = WIN_GetFullHandle( hwnd );
-    if (is_desktop_window( hwnd )) return 0;
+    if (!hdwp)
+    {
+        SetLastError(ERROR_INVALID_PARAMETER);
+        return NULL;
+    }
+    pDWP = hdwp;
 
-    if (!(pDWP = USER_HEAP_LIN_ADDR( hdwp ))) return 0;
+    hwnd = WIN_GetFullHandle( hwnd );
+    if (is_desktop_window( hwnd ))
+    {
+        HeapFree( GetProcessHeap(), 0, hdwp );
+        return NULL;
+    }
 
     USER_Lock();
 
@@ -2145,14 +2158,14 @@ HDWP WINAPI DeferWindowPos( HDWP hdwp, HWND hwnd, HWND hwndAfter,
     }
     if (pDWP->actualCount >= pDWP->suggestedCount)
     {
-        newhdwp = USER_HEAP_REALLOC( hdwp,
+        newhdwp = HeapReAlloc( GetProcessHeap(), 0, hdwp,
                       sizeof(DWP) + pDWP->suggestedCount*sizeof(WINDOWPOS) );
         if (!newhdwp)
         {
             retvalue = 0;
             goto END;
         }
-        pDWP = (DWP *) USER_HEAP_LIN_ADDR( newhdwp );
+        pDWP = newhdwp;
         pDWP->suggestedCount++;
     }
     pDWP->winPos[pDWP->actualCount].hwnd = hwnd;
@@ -2182,8 +2195,13 @@ BOOL WINAPI EndDeferWindowPos( HDWP hdwp )
 
     TRACE("%p\n", hdwp);
 
-    pDWP = (DWP *) USER_HEAP_LIN_ADDR( hdwp );
-    if (!pDWP) return FALSE;
+    pDWP = hdwp;
+    if (!pDWP)
+    {
+        SetLastError(ERROR_INVALID_PARAMETER);
+        return FALSE;
+    }
+
     for (i = 0, winpos = pDWP->winPos; res && i < pDWP->actualCount; i++, winpos++)
     {
         TRACE("hwnd %p, after %p, %d,%d (%dx%d), flags %08x\n",
@@ -2195,7 +2213,7 @@ BOOL WINAPI EndDeferWindowPos( HDWP hdwp )
         else
             res = SendMessageW( winpos->hwnd, WM_WINE_SETWINDOWPOS, 0, (LPARAM)winpos );
     }
-    USER_HEAP_FREE( hdwp );
+    HeapFree( GetProcessHeap(), 0, hdwp );
     return res;
 }