update for HEAD-2003091401
[reactos.git] / subsys / win32k / objects / cliprgn.c
index 0b00d4e..cd0ab34 100644 (file)
@@ -1,4 +1,22 @@
-
+/*
+ *  ReactOS W32 Subsystem
+ *  Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 ReactOS Team
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  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.
+ */
+/* $Id$ */
 
 #undef WIN32_LEAN_AND_MEAN
 #include <windows.h>
 #include <win32k/region.h>
 #include <win32k/cliprgn.h>
 #include <win32k/coord.h>
+#include <include/error.h>
+#include "../eng/clip.h"
 
 #define NDEBUG
 #include <win32k/debug1.h>
 
-VOID
+VOID FASTCALL
 CLIPPING_UpdateGCRegion(DC* Dc)
 {
+  HRGN Combined;
+  PROSRGNDATA CombinedRegion;
+
+#ifndef TODO
+  if (Dc->w.hGCClipRgn == NULL)
+    {
+      Dc->w.hGCClipRgn = NtGdiCreateRectRgn(0, 0, 0, 0);
+    }
+
   if (Dc->w.hGCClipRgn == NULL)
+    return;
+
+  if (Dc->w.hClipRgn == NULL)
+    {
+      NtGdiCombineRgn(Dc->w.hGCClipRgn, Dc->w.hVisRgn, 0, RGN_COPY);
+    }
+  else
     {
-      Dc->w.hGCClipRgn = W32kCreateRectRgn(0, 0, 0, 0);
+      NtGdiCombineRgn(Dc->w.hGCClipRgn, Dc->w.hClipRgn, Dc->w.hVisRgn,
+                    RGN_AND);
     }
+#endif
+
+  Combined = NtGdiCreateRectRgn(0, 0, 0, 0);
+  ASSERT(NULL != Combined);
 
   if (Dc->w.hClipRgn == NULL)
     {
-      W32kCombineRgn(Dc->w.hGCClipRgn, Dc->w.hVisRgn, 0, RGN_COPY);
+      NtGdiCombineRgn(Combined, Dc->w.hVisRgn, 0, RGN_COPY);
     }
   else
     {
-      W32kCombineRgn(Dc->w.hGCClipRgn, Dc->w.hClipRgn, Dc->w.hVisRgn,
+      NtGdiCombineRgn(Combined, Dc->w.hClipRgn, Dc->w.hVisRgn,
                     RGN_AND);
     }
+  NtGdiOffsetRgn(Combined, Dc->w.DCOrgX, Dc->w.DCOrgY);
+
+  CombinedRegion = RGNDATA_LockRgn(Combined);
+  ASSERT(NULL != CombinedRegion);
+
+  if (NULL != Dc->CombinedClip)
+    {
+      IntEngDeleteClipRegion(Dc->CombinedClip);
+    }
+
+  Dc->CombinedClip = IntEngCreateClipRegion(CombinedRegion->rdh.nCount,
+                                            (PRECTL)CombinedRegion->Buffer,
+                                            CombinedRegion->rdh.rcBound);
+  ASSERT(NULL != Dc->CombinedClip);
+
+  RGNDATA_UnlockRgn(Combined);
+  NtGdiDeleteObject(Combined);
 }
 
 HRGN WINAPI SaveVisRgn(HDC hdc)
 {
   HRGN copy;
   PROSRGNDATA obj, copyObj;
-  PDC dc = DC_HandleToPtr(hdc);
+  PDC dc = DC_LockDc(hdc);
 
   if (!dc) return 0;
 
   obj = RGNDATA_LockRgn(dc->w.hVisRgn);
 
-  if(!(copy = W32kCreateRectRgn(0, 0, 0, 0)))
+  if(!(copy = NtGdiCreateRectRgn(0, 0, 0, 0)))
   {
     RGNDATA_UnlockRgn(dc->w.hVisRgn);
-    DC_ReleasePtr(hdc);
+    DC_UnlockDc(hdc);
     return 0;
   }
-  W32kCombineRgn(copy, dc->w.hVisRgn, 0, RGN_COPY);
+  NtGdiCombineRgn(copy, dc->w.hVisRgn, 0, RGN_COPY);
   copyObj = RGNDATA_LockRgn(copy);
 /*  copyObj->header.hNext = obj->header.hNext;
   header.hNext = copy; */
@@ -55,26 +113,31 @@ HRGN WINAPI SaveVisRgn(HDC hdc)
 }
 
 INT STDCALL
-W32kSelectVisRgn(HDC hdc, HRGN hrgn)
+NtGdiSelectVisRgn(HDC hdc, HRGN hrgn)
 {
   int retval;
   DC *dc;
 
   if (!hrgn)
        return ERROR;
-  if (!(dc = DC_HandleToPtr(hdc)))
+  if (!(dc = DC_LockDc(hdc)))
        return ERROR;
 
   dc->w.flags &= ~DC_DIRTY;
 
-  retval = W32kCombineRgn(dc->w.hVisRgn, hrgn, 0, RGN_COPY);
+  if (dc->w.hVisRgn == NULL)
+    {
+      dc->w.hVisRgn = NtGdiCreateRectRgn(0, 0, 0, 0);
+    }
+
+  retval = NtGdiCombineRgn(dc->w.hVisRgn, hrgn, 0, RGN_COPY);
   CLIPPING_UpdateGCRegion(dc);
-  DC_ReleasePtr( hdc );
+  DC_UnlockDc( hdc );
 
   return retval;
 }
 
-int STDCALL W32kExcludeClipRect(HDC  hDC,
+int STDCALL NtGdiExcludeClipRect(HDC  hDC,
                          int  LeftRect,
                          int  TopRect,
                          int  RightRect,
@@ -83,39 +146,35 @@ int STDCALL W32kExcludeClipRect(HDC  hDC,
   UNIMPLEMENTED;
 }
 
-int STDCALL W32kExtSelectClipRgn(HDC  hDC,
+int STDCALL NtGdiExtSelectClipRgn(HDC  hDC,
                           HRGN  hrgn,
                           int  fnMode)
 {
   UNIMPLEMENTED;
 }
 
-int STDCALL W32kGetClipBox(HDC  hDC,
+int STDCALL NtGdiGetClipBox(HDC  hDC,
                           LPRECT  rc)
 {
   int retval;
   DC *dc;
 
-  if (!(dc = DC_HandleToPtr(hDC)))
+  if (!(dc = DC_LockDc(hDC)))
        return ERROR;
-  retval = UnsafeW32kGetRgnBox(dc->w.hGCClipRgn, rc);
-  rc->left -= dc->w.DCOrgX;
-  rc->right -= dc->w.DCOrgX;
-  rc->top -= dc->w.DCOrgY;
-  rc->bottom -= dc->w.DCOrgY;
-
-  DC_ReleasePtr( hDC );
-  W32kDPtoLP(hDC, (LPPOINT)rc, 2);
+  retval = UnsafeIntGetRgnBox(dc->w.hGCClipRgn, rc);
+
+  DC_UnlockDc( hDC );
+  NtGdiDPtoLP(hDC, (LPPOINT)rc, 2);
   return(retval);
 }
 
-int STDCALL W32kGetMetaRgn(HDC  hDC,
+int STDCALL NtGdiGetMetaRgn(HDC  hDC,
                     HRGN  hrgn)
 {
   UNIMPLEMENTED;
 }
 
-int STDCALL W32kIntersectClipRect(HDC  hDC,
+int STDCALL NtGdiIntersectClipRect(HDC  hDC,
                            int  LeftRect,
                            int  TopRect,
                            int  RightRect,
@@ -124,42 +183,82 @@ int STDCALL W32kIntersectClipRect(HDC  hDC,
   UNIMPLEMENTED;
 }
 
-int STDCALL W32kOffsetClipRgn(HDC  hDC,
+int STDCALL NtGdiOffsetClipRgn(HDC  hDC,
                        int  XOffset,
                        int  YOffset)
 {
   UNIMPLEMENTED;
 }
 
-BOOL STDCALL W32kPtVisible(HDC  hDC,
+BOOL STDCALL NtGdiPtVisible(HDC  hDC,
                     int  X,
                     int  Y)
 {
   UNIMPLEMENTED;
 }
 
-BOOL STDCALL W32kRectVisible(HDC  hDC,
+BOOL STDCALL NtGdiRectVisible(HDC  hDC,
                       CONST PRECT  rc)
 {
   UNIMPLEMENTED;
 }
 
-BOOL STDCALL W32kSelectClipPath(HDC  hDC,
+BOOL STDCALL NtGdiSelectClipPath(HDC  hDC,
                          int  Mode)
 {
   UNIMPLEMENTED;
 }
 
-int STDCALL W32kSelectClipRgn(HDC  hDC,
-                       HRGN  hrgn)
+int STDCALL NtGdiSelectClipRgn(HDC  hDC,
+                              HRGN hRgn)
 {
-  UNIMPLEMENTED;
+  int Type;
+  PDC dc;
+  HRGN Copy;
+
+  dc = DC_LockDc(hDC);
+  if (NULL == dc)
+    {
+    SetLastWin32Error(ERROR_INVALID_HANDLE);
+    return ERROR;
+    }
+
+  if (NULL != hRgn)
+    {
+      Copy = NtGdiCreateRectRgn(0, 0, 0, 0);
+      if (NULL == Copy)
+       {
+         DC_UnlockDc(hDC);
+         return ERROR;
+       }
+      Type = NtGdiCombineRgn(Copy, hRgn, 0, RGN_COPY);
+      if (ERROR == Type)
+       {
+         NtGdiDeleteObject(Copy);
+         DC_UnlockDc(hDC);
+         return ERROR;
+       }
+    }
+  else
+    {
+      Copy = NULL;
+    }
+
+  if (NULL != dc->w.hClipRgn)
+    {
+      NtGdiDeleteObject(dc->w.hClipRgn);
+    }
+  dc->w.hClipRgn = Copy;
+  CLIPPING_UpdateGCRegion(dc);
+  DC_UnlockDc(hDC);
+
+  return ERROR;
 }
 
-int STDCALL W32kSetMetaRgn(HDC  hDC)
+int STDCALL NtGdiSetMetaRgn(HDC  hDC)
 {
   UNIMPLEMENTED;
 }
 
 
-
+/* EOF */