- Fix region deleting and ownership for DCEs.
- Fix uninitialized hDC variable in painting code :)
Modified: trunk/reactos/subsys/win32k/include/userfuncs.h
Modified: trunk/reactos/subsys/win32k/ntuser/painting.c
Modified: trunk/reactos/subsys/win32k/ntuser/windc.c
Modified: trunk/reactos/subsys/win32k/ntuser/winpos.c
Modified: trunk/reactos/subsys/win32k/objects/color.c

Modified: trunk/reactos/subsys/win32k/include/userfuncs.h
--- trunk/reactos/subsys/win32k/include/userfuncs.h	2005-09-19 10:39:26 UTC (rev 17931)
+++ trunk/reactos/subsys/win32k/include/userfuncs.h	2005-09-19 12:21:52 UTC (rev 17932)
@@ -112,7 +112,7 @@
 /*************** WINDC.C ***************/
 
 INT FASTCALL
-UserReleaseDC(PWINDOW_OBJECT Window, HDC hDc);
+UserReleaseDC(PWINDOW_OBJECT Window, HDC hDc, BOOL EndPaint);
 
 HDC FASTCALL
 UserGetDCEx(PWINDOW_OBJECT Window OPTIONAL, HANDLE ClipRegion, ULONG Flags);

Modified: trunk/reactos/subsys/win32k/ntuser/painting.c
--- trunk/reactos/subsys/win32k/ntuser/painting.c	2005-09-19 10:39:26 UTC (rev 17931)
+++ trunk/reactos/subsys/win32k/ntuser/painting.c	2005-09-19 12:21:52 UTC (rev 17932)
@@ -259,11 +259,14 @@
          {
             if (Window->UpdateRegion)
             {
+               hDC = UserGetDCEx(Window, Window->UpdateRegion,
+                                 DCX_CACHE | DCX_USESTYLE |
+                                 DCX_INTERSECTRGN | DCX_KEEPCLIPRGN);
                if (co_IntSendMessage(hWnd, WM_ERASEBKGND, (WPARAM)hDC, 0))
                {
                   Window->Flags &= ~WINDOWOBJECT_NEED_ERASEBKGND;
                }
-               UserReleaseDC(Window, hDC);
+               UserReleaseDC(Window, hDC, FALSE);
             }
          }
       }
@@ -829,7 +832,7 @@
       RETURN(FALSE);
    }
 
-   UserReleaseDC(Window, lPs->hdc);
+   UserReleaseDC(Window, lPs->hdc, TRUE);
 
    UserRefObjectCo(Window);
    co_UserShowCaret(Window);
@@ -1295,7 +1298,7 @@
    if (hDC)
    {
       UserScrollDC(hDC, dx, dy, &rc, &cliprc, hrgnUpdate, rcUpdate);
-      UserReleaseDC(Window, hDC);
+      UserReleaseDC(Window, hDC, FALSE);
    }
 
    /*

Modified: trunk/reactos/subsys/win32k/ntuser/windc.c
--- trunk/reactos/subsys/win32k/ntuser/windc.c	2005-09-19 10:39:26 UTC (rev 17931)
+++ trunk/reactos/subsys/win32k/ntuser/windc.c	2005-09-19 12:21:52 UTC (rev 17932)
@@ -118,7 +118,7 @@
    if (NULL == defaultDCstate)
    {
       defaultDCstate = NtGdiGetDCState(Dce->hDC);
-      GDIOBJ_SetOwnership(defaultDCstate, NULL);
+      DC_SetOwnership(defaultDCstate, NULL);
    }
    GDIOBJ_SetOwnership(Dce->Self, NULL);
    DC_SetOwnership(Dce->hDC, NULL);
@@ -193,7 +193,6 @@
    }
    else if (Dce->hClipRgn != NULL)
    {
-      GDIOBJ_SetOwnership(Dce->hClipRgn, PsGetCurrentProcess());
       NtGdiDeleteObject(Dce->hClipRgn);
    }
 
@@ -204,7 +203,7 @@
 }
 
 STATIC INT FASTCALL
-DceReleaseDC(DCE* dce)
+DceReleaseDC(DCE* dce, BOOL EndPaint)
 {
    if (DCX_DCEBUSY != (dce->DCXFlags & (DCX_DCEEMPTY | DCX_DCEBUSY)))
    {
@@ -214,7 +213,7 @@
    /* restore previous visible region */
 
    if ((dce->DCXFlags & (DCX_INTERSECTRGN | DCX_EXCLUDERGN)) &&
-         (dce->DCXFlags & DCX_CACHE) )
+         ((dce->DCXFlags & DCX_CACHE) || EndPaint))
    {
       DceDeleteClipRgn(dce);
    }
@@ -463,23 +462,27 @@
    }
 
    Dce->hwndCurrent = (Window ? Window->hSelf : NULL);
-   Dce->DCXFlags = DcxFlags | DCX_DCEBUSY;
+   Dce->DCXFlags = Flags | DCX_DCEBUSY;
 
    if (0 == (Flags & (DCX_EXCLUDERGN | DCX_INTERSECTRGN)) && NULL != ClipRegion)
    {
-      NtGdiDeleteObject(ClipRegion);
+      if (Flags & DCX_KEEPCLIPRGN)
+         NtGdiDeleteObject(ClipRegion);
       ClipRegion = NULL;
    }
 
+#if 0
    if (NULL != Dce->hClipRgn)
    {
       DceDeleteClipRgn(Dce);
       Dce->hClipRgn = NULL;
    }
+#endif
 
    if (0 != (Flags & DCX_INTERSECTUPDATE) && NULL == ClipRegion)
    {
       Flags |= DCX_INTERSECTRGN | DCX_KEEPCLIPRGN;
+      Dce->DCXFlags |= DCX_INTERSECTRGN | DCX_KEEPCLIPRGN;
       ClipRegion = Window->UpdateRegion;
    }
 
@@ -488,18 +491,15 @@
       if (!(Flags & DCX_WINDOW))
       {
          Dce->hClipRgn = UnsafeIntCreateRectRgnIndirect(&Window->ClientRect);
-         GDIOBJ_SetOwnership(Dce->hClipRgn, NULL);
       }
       else
       {
          Dce->hClipRgn = UnsafeIntCreateRectRgnIndirect(&Window->WindowRect);
-         GDIOBJ_SetOwnership(Dce->hClipRgn, NULL);
       }
    }
    else if (ClipRegion != NULL)
    {
       Dce->hClipRgn = ClipRegion;
-      GDIOBJ_SetOwnership(Dce->hClipRgn, NULL);
    }
 
    DceSetDrawable(Window, Dce->hDC, Flags, UpdateClipOrigin);
@@ -583,7 +583,7 @@
 
 
 INT FASTCALL
-UserReleaseDC(PWINDOW_OBJECT Window, HDC hDc)
+UserReleaseDC(PWINDOW_OBJECT Window, HDC hDc, BOOL EndPaint)
 {
    DCE *dce;
    INT nRet = 0;
@@ -599,7 +599,7 @@
 
    if (dce && (dce->DCXFlags & DCX_DCEBUSY))
    {
-      nRet = DceReleaseDC(dce);
+      nRet = DceReleaseDC(dce, EndPaint);
    }
 
    return nRet;
@@ -615,7 +615,7 @@
    DPRINT("Enter NtUserReleaseDC\n");
    UserEnterExclusive();
 
-   RETURN(UserReleaseDC(NULL, hDc));
+   RETURN(UserReleaseDC(NULL, hDc, FALSE));
 
 CLEANUP:
    DPRINT("Leave NtUserReleaseDC, ret=%i\n",_ret_);
@@ -650,7 +650,6 @@
    }
 
    NtGdiDeleteDC(dce->hDC);
-   GDIOBJ_SetOwnership(dce->hClipRgn, PsGetCurrentProcess());
    if (dce->hClipRgn && ! (dce->DCXFlags & DCX_KEEPCLIPRGN))
    {
       NtGdiDeleteObject(dce->hClipRgn);
@@ -703,7 +702,7 @@
                 * (for 1.0?).
                 */
                DPRINT1("[%p] GetDC() without ReleaseDC()!\n", Window->hSelf);
-               DceReleaseDC(pDCE);
+               DceReleaseDC(pDCE, FALSE);
             }
 
             pDCE->DCXFlags &= DCX_CACHE;
@@ -715,12 +714,12 @@
    }
 }
 
-void FASTCALL
+VOID FASTCALL
 DceEmptyCache()
 {
    while (FirstDce != NULL)
    {
-      DceFreeDCE(FirstDce, TRUE);
+      FirstDce = DceFreeDCE(FirstDce, TRUE);
    }
 }
 

Modified: trunk/reactos/subsys/win32k/ntuser/winpos.c
--- trunk/reactos/subsys/win32k/ntuser/winpos.c	2005-09-19 10:39:26 UTC (rev 17931)
+++ trunk/reactos/subsys/win32k/ntuser/winpos.c	2005-09-19 12:21:52 UTC (rev 17932)
@@ -1189,7 +1189,7 @@
                         CopyRect.bottom - CopyRect.top, Dc,
                         CopyRect.left + (OldWindowRect.left - NewWindowRect.left),
                         CopyRect.top + (OldWindowRect.top - NewWindowRect.top), SRCCOPY);
-            UserReleaseDC(Window, Dc);
+            UserReleaseDC(Window, Dc, FALSE);
             IntValidateParent(Window, CopyRgn);
             NtGdiOffsetRgn(CopyRgn, -NewWindowRect.left, -NewWindowRect.top);
          }

Modified: trunk/reactos/subsys/win32k/objects/color.c
--- trunk/reactos/subsys/win32k/objects/color.c	2005-09-19 10:39:26 UTC (rev 17931)
+++ trunk/reactos/subsys/win32k/objects/color.c	2005-09-19 12:21:52 UTC (rev 17932)
@@ -122,7 +122,7 @@
           else
             DC_UnlockDc(dc);
         }		
-      UserReleaseDC(Wnd,hDC);   
+      UserReleaseDC(Wnd,hDC, FALSE);
     }
     return TRUE;
 }