[Win32k]
[reactos.git] / reactos / subsystems / win32 / win32k / ntuser / window.c
index 22777b2..4445fff 100644 (file)
@@ -93,9 +93,9 @@ PWINDOW_OBJECT FASTCALL IntGetWindowObject(HWND hWnd)
    Window = UserGetWindowObject(hWnd);
    if (Window)
    {
-      ASSERT(USER_BODY_TO_HEADER(Window)->RefCount >= 0);
+      ASSERT(Window->head.cLockObj >= 0);
 
-      USER_BODY_TO_HEADER(Window)->RefCount++;
+      Window->head.cLockObj++;
    }
    return Window;
 }
@@ -129,7 +129,7 @@ PWINDOW_OBJECT FASTCALL UserGetWindowObject(HWND hWnd)
       return NULL;
    }
 
-   ASSERT(USER_BODY_TO_HEADER(Window)->RefCount >= 0);
+   ASSERT(Window->head.cLockObj >= 0);
    return Window;
 }
 
@@ -478,6 +478,7 @@ static LRESULT co_UserFreeWindow(PWINDOW_OBJECT Window,
       Window->SystemMenu = (HMENU)0;
    }
 
+   DceFreeWindowDCE(Window);    /* Always do this to catch orphaned DCs */
 #if 0 /* FIXME */
 
    WINPROC_FreeProc(Window->winproc, WIN_PROC_WINDOW);
@@ -1806,6 +1807,7 @@ co_IntCreateWindowEx(DWORD dwExStyle,
 
    /* Create the window object. */
    Window = (PWINDOW_OBJECT) UserCreateObject( gHandleTable,
+                                               pti->rpdesk,
                                                (PHANDLE)&hWnd,
                                                otWindow,
                                                sizeof(WINDOW_OBJECT));
@@ -2055,9 +2057,7 @@ AllocErr:
    }
    else if ( Wnd->pcls->style & CS_OWNDC)
    {  /* Allocate a DCE for this window. */
-      PDCE pDce = DceAllocDCE(Window, DCE_WINDOW_DC);
-      if (!Wnd->pcls->pdce)
-         Wnd->pcls->pdce = pDce;
+      DceAllocDCE(Window, DCE_WINDOW_DC);
    }
 
    Pos.x = x;
@@ -4552,7 +4552,7 @@ IntGetWindowRgn(PWINDOW_OBJECT Window, HRGN hRgn)
    Wnd = Window->Wnd;
 
    /* Create a new window region using the window rectangle */
-   VisRgn = UnsafeIntCreateRectRgnIndirect(&Window->Wnd->rcWindow);
+   VisRgn = IntSysCreateRectRgnIndirect(&Window->Wnd->rcWindow);
    NtGdiOffsetRgn(VisRgn, -Window->Wnd->rcWindow.left, -Window->Wnd->rcWindow.top);
    /* if there's a region assigned to the window, combine them both */
    if(Window->hrgnClip && !(Wnd->style & WS_MINIMIZE))
@@ -4568,7 +4568,7 @@ IntGetWindowRgn(PWINDOW_OBJECT Window, HRGN hRgn)
    else
       Ret = ERROR;
 
-   GreDeleteObject(VisRgn);
+   REGION_FreeRgnByHandle(VisRgn);
 
    return Ret;
 }
@@ -4593,7 +4593,7 @@ IntGetWindowRgnBox(PWINDOW_OBJECT Window, RECTL *Rect)
    Wnd = Window->Wnd;
 
    /* Create a new window region using the window rectangle */
-   VisRgn = UnsafeIntCreateRectRgnIndirect(&Window->Wnd->rcWindow);
+   VisRgn = IntSysCreateRectRgnIndirect(&Window->Wnd->rcWindow);
    NtGdiOffsetRgn(VisRgn, -Window->Wnd->rcWindow.left, -Window->Wnd->rcWindow.top);
    /* if there's a region assigned to the window, combine them both */
    if(Window->hrgnClip && !(Wnd->style & WS_MINIMIZE))
@@ -4608,7 +4608,7 @@ IntGetWindowRgnBox(PWINDOW_OBJECT Window, RECTL *Rect)
    else
       Ret = ERROR;
 
-   GreDeleteObject(VisRgn);
+   REGION_FreeRgnByHandle(VisRgn);
 
    return Ret;
 }
@@ -4623,6 +4623,7 @@ NtUserSetWindowRgn(
    HRGN hRgn,
    BOOL bRedraw)
 {
+   HRGN hrgnCopy;
    PWINDOW_OBJECT Window;
    DECLARE_RETURN(INT);
 
@@ -4634,15 +4635,25 @@ NtUserSetWindowRgn(
       RETURN( 0);
    }
 
-   /* FIXME - Verify if hRgn is a valid handle!!!!
-              Propably make this operation thread-safe, but maybe it's not necessary */
+   if (hRgn) // The region will be deleted in user32.
+   {
+      if (GDIOBJ_ValidateHandle(hRgn, GDI_OBJECT_TYPE_REGION))
+      {
+         hrgnCopy = IntSysCreateRectRgn(0, 0, 0, 0);
+         NtGdiCombineRgn(hrgnCopy, hRgn, 0, RGN_COPY);
+      }
+      else
+         RETURN( 0);
+   }
+   else
+      hrgnCopy = (HRGN) 1;
 
-   if(Window->hrgnClip)
+   if (Window->hrgnClip)
    {
       /* Delete no longer needed region handle */
       GreDeleteObject(Window->hrgnClip);
    }
-   Window->hrgnClip = hRgn;
+   Window->hrgnClip = hrgnCopy;
 
    /* FIXME - send WM_WINDOWPOSCHANGING and WM_WINDOWPOSCHANGED messages to the window */