[WIN32K]
[reactos.git] / reactos / subsystems / win32 / win32k / objects / cliprgn.c
index 3d9d98c..7bfcf80 100644 (file)
  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  *  GNU General Public License for more details.
  *
- *  You should have received a copy of the GNU General Public License
- *  along with this program; if not, write to the Free Software
- *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *  You should have received a copy of the GNU General Public License along
+ *  with this program; if not, write to the Free Software Foundation, Inc.,
+ *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
-#include <w32k.h>
+#include <win32k.h>
 
 #define NDEBUG
 #include <debug.h>
@@ -26,36 +26,66 @@ int FASTCALL
 CLIPPING_UpdateGCRegion(DC* Dc)
 {
    PROSRGNDATA CombinedRegion;
+   HRGN hRgnVis = Dc->prgnVis->BaseObject.hHmgr;
 
-   if (Dc->w.hGCClipRgn == NULL)
-      Dc->w.hGCClipRgn = NtGdiCreateRectRgn(0, 0, 0, 0);
-
-   if (Dc->w.hClipRgn == NULL)
-      NtGdiCombineRgn(Dc->w.hGCClipRgn, Dc->w.hVisRgn, 0, RGN_COPY);
-   else
-      NtGdiCombineRgn(Dc->w.hGCClipRgn, Dc->w.hClipRgn, Dc->w.hVisRgn, RGN_AND);
-   NtGdiOffsetRgn(Dc->w.hGCClipRgn, Dc->ptlDCOrig.x, Dc->ptlDCOrig.y);
-
-   if((CombinedRegion = REGION_LockRgn(Dc->w.hGCClipRgn)))
+   /* Experiment with API region based on wine.. */
+   if (Dc->rosdc.hClipRgn && Dc->dclevel.prgnMeta)
    {
-     if (Dc->CombinedClip != NULL)
-        IntEngDeleteClipRegion(Dc->CombinedClip);
+      PROSRGNDATA pClipRgn;
 
-     Dc->CombinedClip = IntEngCreateClipRegion(
-        CombinedRegion->rdh.nCount,
-        (PRECTL)CombinedRegion->Buffer,
-        (PRECTL)&CombinedRegion->rdh.rcBound);
+      if ((pClipRgn = RGNOBJAPI_Lock(Dc->rosdc.hClipRgn, NULL)))
+      {
+         if (!Dc->prgnAPI) Dc->prgnAPI = IntSysCreateRectpRgn( 0, 0, 0, 0 );
 
-     REGION_UnlockRgn(CombinedRegion);
+         IntGdiCombineRgn( Dc->prgnAPI,
+                           pClipRgn,
+                           Dc->dclevel.prgnMeta,
+                           RGN_AND );
+         RGNOBJAPI_Unlock(pClipRgn);
+      }
    }
-
-   if ( NULL == Dc->CombinedClip )
+   else
    {
-       DPRINT1("IntEngCreateClipRegion() failed\n");
-       return ERROR;
+      if (Dc->prgnAPI)
+         GreDeleteObject(((PROSRGNDATA)Dc->prgnAPI)->BaseObject.hHmgr);
+      Dc->prgnAPI = NULL;
    }
 
-   return NtGdiOffsetRgn(Dc->w.hGCClipRgn, -Dc->ptlDCOrig.x, -Dc->ptlDCOrig.y);
+
+   if (Dc->rosdc.hGCClipRgn == NULL)
+      Dc->rosdc.hGCClipRgn = IntSysCreateRectRgn(0, 0, 0, 0);
+
+   if (Dc->rosdc.hClipRgn == NULL)
+      NtGdiCombineRgn(Dc->rosdc.hGCClipRgn, hRgnVis, 0, RGN_COPY);
+   else
+      NtGdiCombineRgn(Dc->rosdc.hGCClipRgn, Dc->rosdc.hClipRgn, hRgnVis, RGN_AND);
+
+   NtGdiOffsetRgn(Dc->rosdc.hGCClipRgn, Dc->ptlDCOrig.x, Dc->ptlDCOrig.y);
+
+    if((CombinedRegion = RGNOBJAPI_Lock(Dc->rosdc.hGCClipRgn, NULL)))
+    {
+        CLIPOBJ *CombinedClip;
+      
+        CombinedClip = IntEngCreateClipRegion(CombinedRegion->rdh.nCount,
+                                              CombinedRegion->Buffer,
+                                              &CombinedRegion->rdh.rcBound);
+
+        RGNOBJAPI_Unlock(CombinedRegion);
+
+        if (!CombinedClip)
+        {
+            DPRINT1("IntEngCreateClipRegion() failed\n");
+            return ERROR;
+        }
+
+        if (Dc->rosdc.CombinedClip != NULL)
+            IntEngDeleteClipRegion(Dc->rosdc.CombinedClip);
+
+        Dc->rosdc.CombinedClip = CombinedClip;
+    }
+
+
+   return NtGdiOffsetRgn(Dc->rosdc.hGCClipRgn, -Dc->ptlDCOrig.x, -Dc->ptlDCOrig.y);
 }
 
 INT FASTCALL
@@ -75,20 +105,21 @@ GdiSelectVisRgn(HDC hdc, HRGN hrgn)
        return ERROR;
   }
 
-  dc->DC_Flags &= ~DC_FLAG_DIRTY_RAO;
-  
-  if (dc->w.hVisRgn == NULL)
+  dc->fs &= ~DC_FLAG_DIRTY_RAO;
+
+  if (dc->prgnVis == NULL)
   {
-    dc->w.hVisRgn = NtGdiCreateRectRgn(0, 0, 0, 0);
-    GDIOBJ_CopyOwnership(hdc, dc->w.hVisRgn);
+    dc->prgnVis = IntSysCreateRectpRgn(0, 0, 0, 0);
+    GDIOBJ_CopyOwnership(hdc, ((PROSRGNDATA)dc->prgnVis)->BaseObject.hHmgr);
   }
 
-  retval = NtGdiCombineRgn(dc->w.hVisRgn, hrgn, 0, RGN_COPY);
+  retval = NtGdiCombineRgn(((PROSRGNDATA)dc->prgnVis)->BaseObject.hHmgr, hrgn, 0, RGN_COPY);
   if ( retval != ERROR )
   {
-    NtGdiOffsetRgn(dc->w.hVisRgn, -dc->ptlDCOrig.x, -dc->ptlDCOrig.y);
+    NtGdiOffsetRgn(((PROSRGNDATA)dc->prgnVis)->BaseObject.hHmgr, -dc->ptlDCOrig.x, -dc->ptlDCOrig.y);
     CLIPPING_UpdateGCRegion(dc);
   }
+
   DC_UnlockDc(dc);
 
   return retval;
@@ -96,21 +127,19 @@ GdiSelectVisRgn(HDC hdc, HRGN hrgn)
 
 
 int FASTCALL GdiExtSelectClipRgn(PDC dc,
-                              HRGN hrgn,
-                             int fnMode)
+                                 HRGN hrgn,
+                                 int fnMode)
 {
-  int retval;
-  //  dc->DC_Flags &= ~DC_FLAG_DIRTY_RAO;
+  //  dc->fs &= ~DC_FLAG_DIRTY_RAO;
 
   if (!hrgn)
   {
     if (fnMode == RGN_COPY)
     {
-      if (dc->w.hClipRgn != NULL)
+      if (dc->rosdc.hClipRgn != NULL)
       {
-        NtGdiDeleteObject(dc->w.hClipRgn);
-        dc->w.hClipRgn = NULL;
-        retval = NULLREGION;
+        REGION_FreeRgnByHandle(dc->rosdc.hClipRgn);
+        dc->rosdc.hClipRgn = NULL;
       }
     }
     else
@@ -121,35 +150,31 @@ int FASTCALL GdiExtSelectClipRgn(PDC dc,
   }
   else
   {
-    if (!dc->w.hClipRgn)
+    if (!dc->rosdc.hClipRgn)
     {
-      PROSRGNDATA Rgn;
-      RECT rect;
-      if((Rgn = REGION_LockRgn(dc->w.hVisRgn)))
+      RECTL rect;
+      if(dc->prgnVis)
       {
-        REGION_GetRgnBox(Rgn, &rect);
-        REGION_UnlockRgn(Rgn);
-        dc->w.hClipRgn = UnsafeIntCreateRectRgnIndirect(&rect);
+               REGION_GetRgnBox(dc->prgnVis, &rect);
+        dc->rosdc.hClipRgn = IntSysCreateRectRgnIndirect(&rect);
       }
       else
       {
-        dc->w.hClipRgn = NtGdiCreateRectRgn(0, 0, 0, 0);
+        dc->rosdc.hClipRgn = IntSysCreateRectRgn(0, 0, 0, 0);
       }
     }
     if(fnMode == RGN_COPY)
     {
-      NtGdiCombineRgn(dc->w.hClipRgn, hrgn, 0, fnMode);
+      NtGdiCombineRgn(dc->rosdc.hClipRgn, hrgn, 0, fnMode);
     }
     else
-      NtGdiCombineRgn(dc->w.hClipRgn, dc->w.hClipRgn, hrgn, fnMode);
+      NtGdiCombineRgn(dc->rosdc.hClipRgn, dc->rosdc.hClipRgn, hrgn, fnMode);
   }
-
-  retval = CLIPPING_UpdateGCRegion(dc);
-  return retval;
+  return CLIPPING_UpdateGCRegion(dc);
 }
 
 
-int STDCALL NtGdiExtSelectClipRgn(HDC  hDC,
+int APIENTRY NtGdiExtSelectClipRgn(HDC  hDC,
                                 HRGN  hrgn,
                                int  fnMode)
 {
@@ -169,51 +194,82 @@ int STDCALL NtGdiExtSelectClipRgn(HDC  hDC,
 }
 
 INT FASTCALL
-GdiGetClipBox(HDC hDC, LPRECT rc)
+GdiGetClipBox(HDC hDC, PRECTL rc)
 {
-   PROSRGNDATA Rgn;
    INT retval;
    PDC dc;
+   PROSRGNDATA pRgnNew, pRgn = NULL;
+   BOOL Unlock = FALSE; //Small hack
 
    if (!(dc = DC_LockDc(hDC)))
    {
       return ERROR;
    }
 
-   if (!(Rgn = REGION_LockRgn(dc->w.hGCClipRgn)))
+   /* FIXME! Rao and Vis only! */
+   if (dc->prgnAPI) // APIRGN
    {
+      pRgn = dc->prgnAPI;
+   }
+   else if (dc->dclevel.prgnMeta) // METARGN
+   {
+      pRgn = dc->dclevel.prgnMeta;
+   }
+   else
+   {
+          Unlock = TRUE ;
+       pRgn = REGION_LockRgn(dc->rosdc.hClipRgn); // CLIPRGN
+   }
+
+   if (pRgn)
+   {
+      pRgnNew = IntSysCreateRectpRgn( 0, 0, 0, 0 );
+
+         if (!pRgnNew)
+      {
+         DC_UnlockDc(dc);
+                if(Unlock) REGION_UnlockRgn(pRgn);
+         return ERROR;
+      }
+
+      IntGdiCombineRgn(pRgnNew, dc->prgnVis, pRgn, RGN_AND);
+
+      retval = REGION_GetRgnBox(pRgnNew, rc);
+
+         REGION_FreeRgnByHandle(pRgnNew->BaseObject.hHmgr);
       DC_UnlockDc(dc);
-      return ERROR;
+         if(Unlock) REGION_UnlockRgn(pRgn);
+      return retval;
    }
-   retval = REGION_GetRgnBox(Rgn, rc);
-   REGION_UnlockRgn(Rgn);
+
+   retval = REGION_GetRgnBox(dc->prgnVis, rc);
    IntDPtoLP(dc, (LPPOINT)rc, 2);
    DC_UnlockDc(dc);
 
    return retval;
 }
 
-INT STDCALL
-NtGdiGetAppClipBox(HDC hDC, LPRECT rc)
+INT APIENTRY
+NtGdiGetAppClipBox(HDC hDC, PRECTL rc)
 {
   INT Ret;
   NTSTATUS Status = STATUS_SUCCESS;
-  RECT Saferect;
+  RECTL Saferect;
 
   Ret = GdiGetClipBox(hDC, &Saferect);
 
-  _SEH_TRY
+  _SEH2_TRY
   {
     ProbeForWrite(rc,
                   sizeof(RECT),
                   1);
     *rc = Saferect;
   }
-  _SEH_HANDLE
+  _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
   {
-    Status = _SEH_GetExceptionCode();
+    Status = _SEH2_GetExceptionCode();
   }
-  _SEH_END;
+  _SEH2_END;
 
   if(!NT_SUCCESS(Status))
   {
@@ -224,14 +280,14 @@ NtGdiGetAppClipBox(HDC hDC, LPRECT rc)
   return Ret;
 }
 
-int STDCALL NtGdiExcludeClipRect(HDC  hDC,
+int APIENTRY NtGdiExcludeClipRect(HDC  hDC,
                          int  LeftRect,
                          int  TopRect,
                          int  RightRect,
                          int  BottomRect)
 {
    INT Result;
-   RECT Rect;
+   RECTL Rect;
    HRGN NewRgn;
    PDC dc = DC_LockDc(hDC);
 
@@ -248,24 +304,24 @@ int STDCALL NtGdiExcludeClipRect(HDC  hDC,
 
    IntLPtoDP(dc, (LPPOINT)&Rect, 2);
 
-   NewRgn = UnsafeIntCreateRectRgnIndirect(&Rect);
+   NewRgn = IntSysCreateRectRgnIndirect(&Rect);
    if (!NewRgn)
    {
       Result = ERROR;
    }
    else
    {
-      if (!dc->w.hClipRgn)
+      if (!dc->rosdc.hClipRgn)
       {
-         dc->w.hClipRgn = NtGdiCreateRectRgn(0, 0, 0, 0);
-         NtGdiCombineRgn(dc->w.hClipRgn, dc->w.hVisRgn, NewRgn, RGN_DIFF);
+         dc->rosdc.hClipRgn = IntSysCreateRectRgn(0, 0, 0, 0);
+         NtGdiCombineRgn(dc->rosdc.hClipRgn, ((PROSRGNDATA)dc->prgnVis)->BaseObject.hHmgr, NewRgn, RGN_DIFF);
          Result = SIMPLEREGION;
       }
       else
       {
-         Result = NtGdiCombineRgn(dc->w.hClipRgn, dc->w.hClipRgn, NewRgn, RGN_DIFF);
+         Result = NtGdiCombineRgn(dc->rosdc.hClipRgn, dc->rosdc.hClipRgn, NewRgn, RGN_DIFF);
       }
-      NtGdiDeleteObject(NewRgn);
+      REGION_FreeRgnByHandle(NewRgn);
    }
    if (Result != ERROR)
       CLIPPING_UpdateGCRegion(dc);
@@ -275,14 +331,14 @@ int STDCALL NtGdiExcludeClipRect(HDC  hDC,
    return Result;
 }
 
-int STDCALL NtGdiIntersectClipRect(HDC  hDC,
+int APIENTRY NtGdiIntersectClipRect(HDC  hDC,
                            int  LeftRect,
                            int  TopRect,
                            int  RightRect,
                            int  BottomRect)
 {
    INT Result;
-   RECT Rect;
+   RECTL Rect;
    HRGN NewRgn;
    PDC dc = DC_LockDc(hDC);
 
@@ -302,20 +358,20 @@ int STDCALL NtGdiIntersectClipRect(HDC  hDC,
 
    IntLPtoDP(dc, (LPPOINT)&Rect, 2);
 
-   NewRgn = UnsafeIntCreateRectRgnIndirect(&Rect);
+   NewRgn = IntSysCreateRectRgnIndirect(&Rect);
    if (!NewRgn)
    {
       Result = ERROR;
    }
-   else if (!dc->w.hClipRgn)
+   else if (!dc->rosdc.hClipRgn)
    {
-      dc->w.hClipRgn = NewRgn;
+      dc->rosdc.hClipRgn = NewRgn;
       Result = SIMPLEREGION;
    }
    else
    {
-      Result = NtGdiCombineRgn(dc->w.hClipRgn, dc->w.hClipRgn, NewRgn, RGN_AND);
-      NtGdiDeleteObject(NewRgn);
+      Result = NtGdiCombineRgn(dc->rosdc.hClipRgn, dc->rosdc.hClipRgn, NewRgn, RGN_AND);
+      REGION_FreeRgnByHandle(NewRgn);
    }
    if (Result != ERROR)
       CLIPPING_UpdateGCRegion(dc);
@@ -325,7 +381,7 @@ int STDCALL NtGdiIntersectClipRect(HDC  hDC,
    return Result;
 }
 
-int STDCALL NtGdiOffsetClipRgn(HDC  hDC,
+int APIENTRY NtGdiOffsetClipRgn(HDC  hDC,
                        int  XOffset,
                        int  YOffset)
 {
@@ -338,9 +394,9 @@ int STDCALL NtGdiOffsetClipRgn(HDC  hDC,
     return ERROR;
   }
 
-  if(dc->w.hClipRgn != NULL)
+  if(dc->rosdc.hClipRgn != NULL)
   {
-    Result = NtGdiOffsetRgn(dc->w.hClipRgn,
+    Result = NtGdiOffsetRgn(dc->rosdc.hClipRgn,
                             XOffset,
                             YOffset);
     CLIPPING_UpdateGCRegion(dc);
@@ -354,7 +410,7 @@ int STDCALL NtGdiOffsetClipRgn(HDC  hDC,
   return Result;
 }
 
-BOOL STDCALL NtGdiPtVisible(HDC  hDC,
+BOOL APIENTRY NtGdiPtVisible(HDC  hDC,
                     int  X,
                     int  Y)
 {
@@ -367,20 +423,20 @@ BOOL STDCALL NtGdiPtVisible(HDC  hDC,
     return FALSE;
   }
 
-  rgn = dc->w.hGCClipRgn;
+  rgn = dc->rosdc.hGCClipRgn;
   DC_UnlockDc(dc);
 
   return (rgn ? NtGdiPtInRegion(rgn, X, Y) : FALSE);
 }
 
-BOOL STDCALL NtGdiRectVisible(HDC  hDC,
-                      CONST PRECT  UnsafeRect)
+BOOL APIENTRY NtGdiRectVisible(HDC  hDC,
+                      LPRECT UnsafeRect)
 {
    NTSTATUS Status = STATUS_SUCCESS;
    PROSRGNDATA Rgn;
    PDC dc = DC_LockDc(hDC);
    BOOL Result = FALSE;
-   RECT Rect;
+   RECTL Rect;
 
    if (!dc)
    {
@@ -388,18 +444,18 @@ BOOL STDCALL NtGdiRectVisible(HDC  hDC,
       return FALSE;
    }
 
-   _SEH_TRY
+   _SEH2_TRY
    {
       ProbeForRead(UnsafeRect,
                    sizeof(RECT),
                    1);
       Rect = *UnsafeRect;
    }
-   _SEH_HANDLE
+   _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
    {
-      Status = _SEH_GetExceptionCode();
+      Status = _SEH2_GetExceptionCode();
    }
-   _SEH_END;
+   _SEH2_END;
 
    if(!NT_SUCCESS(Status))
    {
@@ -408,13 +464,13 @@ BOOL STDCALL NtGdiRectVisible(HDC  hDC,
       return FALSE;
    }
 
-   if (dc->w.hGCClipRgn)
+   if (dc->rosdc.hGCClipRgn)
    {
-      if((Rgn = (PROSRGNDATA)REGION_LockRgn(dc->w.hGCClipRgn)))
+      if((Rgn = (PROSRGNDATA)RGNOBJAPI_Lock(dc->rosdc.hGCClipRgn, NULL)))
       {
          IntLPtoDP(dc, (LPPOINT)&Rect, 2);
          Result = REGION_RectInRegion(Rgn, &Rect);
-         REGION_UnlockRgn(Rgn);
+         RGNOBJAPI_Unlock(Rgn);
       }
    }
    DC_UnlockDc(dc);
@@ -423,36 +479,36 @@ BOOL STDCALL NtGdiRectVisible(HDC  hDC,
 }
 
 int
-FASTCALL 
+FASTCALL
 IntGdiSetMetaRgn(PDC pDC)
 {
   INT Ret = ERROR;
   PROSRGNDATA TempRgn;
 
-  if ( pDC->DcLevel.prgnMeta )
+  if ( pDC->dclevel.prgnMeta )
   {
-     if ( pDC->DcLevel.prgnClip )
+     if ( pDC->dclevel.prgnClip )
      {
-        TempRgn = IntGdiCreateRectRgn(0,0,0,0);
+        TempRgn = IntSysCreateRectpRgn(0,0,0,0);
         if (TempRgn)
-        {        
+        {
            Ret = IntGdiCombineRgn( TempRgn,
-                     pDC->DcLevel.prgnMeta,
-                     pDC->DcLevel.prgnClip,
+                     pDC->dclevel.prgnMeta,
+                     pDC->dclevel.prgnClip,
                                    RGN_AND);
            if ( Ret )
            {
-              GDIOBJ_ShareUnlockObjByPtr(pDC->DcLevel.prgnMeta);
-              if (!((PROSRGNDATA)pDC->DcLevel.prgnMeta)->BaseObject.ulShareCount)
-                 REGION_Delete(pDC->DcLevel.prgnMeta);
+              GDIOBJ_ShareUnlockObjByPtr(pDC->dclevel.prgnMeta);
+              if (!((PROSRGNDATA)pDC->dclevel.prgnMeta)->BaseObject.ulShareCount)
+                 REGION_Delete(pDC->dclevel.prgnMeta);
 
-              pDC->DcLevel.prgnMeta = TempRgn;
+              pDC->dclevel.prgnMeta = TempRgn;
 
-              GDIOBJ_ShareUnlockObjByPtr(pDC->DcLevel.prgnClip);
-              if (!((PROSRGNDATA)pDC->DcLevel.prgnClip)->BaseObject.ulShareCount)
-                 REGION_Delete(pDC->DcLevel.prgnClip);
+              GDIOBJ_ShareUnlockObjByPtr(pDC->dclevel.prgnClip);
+              if (!((PROSRGNDATA)pDC->dclevel.prgnClip)->BaseObject.ulShareCount)
+                 REGION_Delete(pDC->dclevel.prgnClip);
 
-              pDC->DcLevel.prgnClip = NULL;
+              pDC->dclevel.prgnClip = NULL;
 
               IntGdiReleaseRaoRgn(pDC);
            }
@@ -461,24 +517,23 @@ IntGdiSetMetaRgn(PDC pDC)
         }
      }
      else
-        Ret = REGION_Complexity(pDC->DcLevel.prgnMeta);
+        Ret = REGION_Complexity(pDC->dclevel.prgnMeta);
   }
   else
   {
-     if ( pDC->DcLevel.prgnClip )
+     if ( pDC->dclevel.prgnClip )
      {
-        Ret = REGION_Complexity(pDC->DcLevel.prgnClip);
-        pDC->DcLevel.prgnMeta = pDC->DcLevel.prgnClip;
-        pDC->DcLevel.prgnClip = NULL;
+        Ret = REGION_Complexity(pDC->dclevel.prgnClip);
+        pDC->dclevel.prgnMeta = pDC->dclevel.prgnClip;
+        pDC->dclevel.prgnClip = NULL;
      }
-     else 
+     else
        Ret = SIMPLEREGION;
   }
   return Ret;
 }
 
-
-int STDCALL NtGdiSetMetaRgn(HDC  hDC)
+int APIENTRY NtGdiSetMetaRgn(HDC  hDC)
 {
   INT Ret;
   PDC pDC = DC_LockDc(hDC);
@@ -499,56 +554,77 @@ NEW_CLIPPING_UpdateGCRegion(PDC pDC)
 {
   CLIPOBJ * co;
 
-  if (!pDC->prgnVis) return 0;
+  /* Must have VisRgn set to a valid state! */
+  if (!pDC->prgnVis) return ERROR;
 
   if (pDC->prgnAPI)
   {
      REGION_Delete(pDC->prgnAPI);
-     pDC->prgnAPI = IntGdiCreateRectRgn(0,0,0,0);
+     pDC->prgnAPI = IntSysCreateRectpRgn(0,0,0,0);
   }
 
   if (pDC->prgnRao)
   {
      REGION_Delete(pDC->prgnRao);
-     pDC->prgnRao = IntGdiCreateRectRgn(0,0,0,0);
+     pDC->prgnRao = IntSysCreateRectpRgn(0,0,0,0);
   }
-  
-  if (pDC->DcLevel.prgnMeta && pDC->DcLevel.prgnClip)
+
+  if (pDC->dclevel.prgnMeta && pDC->dclevel.prgnClip)
   {
      IntGdiCombineRgn( pDC->prgnAPI,
-              pDC->DcLevel.prgnClip,
-              pDC->DcLevel.prgnMeta,
-                            RGN_AND);
+                       pDC->dclevel.prgnClip,
+                       pDC->dclevel.prgnMeta,
+                       RGN_AND );
   }
   else
   {
-     if (pDC->DcLevel.prgnClip)
+     if (pDC->dclevel.prgnClip)
+     {
         IntGdiCombineRgn( pDC->prgnAPI,
-                 pDC->DcLevel.prgnClip,
-                                  NULL,
-                              RGN_COPY);
-     else if (pDC->DcLevel.prgnMeta)
+                          pDC->dclevel.prgnClip,
+                          NULL,
+                          RGN_COPY );
+     }
+     else if (pDC->dclevel.prgnMeta)
+     {
         IntGdiCombineRgn( pDC->prgnAPI,
-                 pDC->DcLevel.prgnMeta,
-                                  NULL,
-                              RGN_COPY);
+                          pDC->dclevel.prgnMeta,
+                          NULL,
+                          RGN_COPY );
+     }
   }
 
   IntGdiCombineRgn( pDC->prgnRao,
                     pDC->prgnVis,
                     pDC->prgnAPI,
-                         RGN_AND);
+                    RGN_AND );
+
+  RtlCopyMemory( &pDC->erclClip,
+                 &((PROSRGNDATA)pDC->prgnRao)->rdh.rcBound,
+                 sizeof(RECTL));
 
-  RtlCopyMemory(&pDC->erclClip, &((PROSRGNDATA)pDC->prgnRao)->rdh.rcBound , sizeof(RECTL));
-  pDC->DC_Flags &= ~DC_FLAG_DIRTY_RAO;
+  pDC->fs &= ~DC_FLAG_DIRTY_RAO;
+
+  IntGdiOffsetRgn(pDC->prgnRao, pDC->ptlDCOrig.x, pDC->ptlDCOrig.y);
+
+  // pDC->co should be used. Example, CLIPOBJ_cEnumStart uses XCLIPOBJ to build
+  // the rects from region objects rects in pClipRgn->Buffer. 
+  // With pDC->co.pClipRgn->Buffer,
+  // pDC->co.pClipRgn = pDC->prgnRao ? pDC->prgnRao : pDC->prgnVis;
 
-//  if (Dc->CombinedClip != NULL) IntEngDeleteClipRegion(Dc->CombinedClip);
-  
   co = IntEngCreateClipRegion( ((PROSRGNDATA)pDC->prgnRao)->rdh.nCount,
-                           (PRECTL)((PROSRGNDATA)pDC->prgnRao)->Buffer,
-                                 (PRECTL)&pDC->erclClip);
+                               ((PROSRGNDATA)pDC->prgnRao)->Buffer,
+                               &pDC->erclClip);
+
+  if (co)
+  {
+    if (pDC->rosdc.CombinedClip != NULL)
+     IntEngDeleteClipRegion(pDC->rosdc.CombinedClip);
+
+    pDC->rosdc.CombinedClip = co;
+  }
 
-  return REGION_Complexity(pDC->prgnRao);
+  return IntGdiOffsetRgn(pDC->prgnRao, -pDC->ptlDCOrig.x, -pDC->ptlDCOrig.y);
 }
 
 /* EOF */