[Win32k]
[reactos.git] / reactos / subsystems / win32 / win32k / objects / rect.c
index 28d6925..9fd5cda 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.
  */
-/* $Id$ */
 
-#include <w32k.h>
+#include <win32k.h>
 
 #define NDEBUG
 #include <debug.h>
 
 /* FUNCTIONS *****************************************************************/
 
-VOID FASTCALL
-IntGdiSetEmptyRect(PRECT Rect)
+BOOL
+FASTCALL
+RECTL_bUnionRect(RECTL *prclDst, const RECTL *prcl1, const RECTL *prcl2)
 {
-  Rect->left = Rect->right = Rect->top = Rect->bottom = 0;
-}
-
-BOOL STDCALL
-NtGdiSetEmptyRect(PRECT UnsafeRect)
-{
-  RECT Rect;
-  NTSTATUS Status = STATUS_SUCCESS;
-
-  IntGdiSetEmptyRect(&Rect);
-
-  _SEH_TRY
-  {
-    ProbeForWrite(UnsafeRect,
-                  sizeof(RECT),
-                  1);
-    *UnsafeRect = Rect;
-  }
-  _SEH_HANDLE
-  {
-    Status = _SEH_GetExceptionCode();
-  }
-  _SEH_END;
-
-  if (! NT_SUCCESS(Status))
+    if (RECTL_bIsEmptyRect(prcl1))
     {
-      SetLastNtError(Status);
-      return FALSE;
+        if (RECTL_bIsEmptyRect(prcl2))
+           {
+               RECTL_vSetEmptyRect(prclDst);
+               return FALSE;
+           }
+        else
+           {
+               *prclDst = *prcl2;
+           }
     }
-
-  return TRUE;
-}
-
-BOOL FASTCALL
-IntGdiIsEmptyRect(const RECT* Rect)
-{
-  return(Rect->left >= Rect->right || Rect->top >= Rect->bottom);
-}
-
-BOOL STDCALL
-NtGdiIsEmptyRect(const RECT* UnsafeRect)
-{
-  RECT Rect = {0};
-  NTSTATUS Status = STATUS_SUCCESS;
-
-  _SEH_TRY
-  {
-    ProbeForRead(UnsafeRect,
-                 sizeof(RECT),
-                 1);
-    Rect = *UnsafeRect;
-  }
-  _SEH_HANDLE
-  {
-    Status = _SEH_GetExceptionCode();
-  }
-  _SEH_END;
-  if (! NT_SUCCESS(Status))
+    else
     {
-      SetLastNtError(Status);
-      return FALSE;
+        if (RECTL_bIsEmptyRect(prcl2))
+           {
+               *prclDst = *prcl1;
+           }
+        else
+           {
+               prclDst->left = min(prcl1->left, prcl2->left);
+               prclDst->top = min(prcl1->top, prcl2->top);
+               prclDst->right = max(prcl1->right, prcl2->right);
+               prclDst->bottom = max(prcl1->bottom, prcl2->bottom);
+           }
     }
 
-  return IntGdiIsEmptyRect(&Rect);
+    return TRUE;
 }
 
-VOID FASTCALL
-IntGdiOffsetRect(LPRECT Rect, INT x, INT y)
-{
-  Rect->left += x;
-  Rect->right += x;
-  Rect->top += y;
-  Rect->bottom += y;
-}
-
-BOOL STDCALL
-NtGdiOffsetRect(LPRECT UnsafeRect, INT x, INT y)
-{
-  RECT Rect = {0};
-  NTSTATUS Status = STATUS_SUCCESS;
-
-  _SEH_TRY
-  {
-    ProbeForRead(UnsafeRect,
-                 sizeof(RECT),
-                 1);
-    Rect = *UnsafeRect;
-  }
-  _SEH_HANDLE
-  {
-    Status = _SEH_GetExceptionCode();
-  }
-  _SEH_END;
-  if (! NT_SUCCESS(Status))
-    {
-      SetLastNtError(Status);
-      return FALSE;
-    }
-
-  IntGdiOffsetRect(&Rect, x, y);
-
-  _SEH_TRY
-  {
-    ProbeForWrite(UnsafeRect,
-                  sizeof(RECT),
-                  1);
-    *UnsafeRect = Rect;
-  }
-  _SEH_HANDLE
-  {
-    Status = _SEH_GetExceptionCode();
-  }
-  _SEH_END;
-  if (! NT_SUCCESS(Status))
-    {
-      SetLastNtError(Status);
-      return FALSE;
-    }
-
-  return TRUE;
-}
-
-BOOL FASTCALL
-IntGdiUnionRect(PRECT Dest, const RECT* Src1, const RECT* Src2)
-{
-  if (IntGdiIsEmptyRect(Src1))
-    {
-      if (IntGdiIsEmptyRect(Src2))
-       {
-         IntGdiSetEmptyRect(Dest);
-         return FALSE;
-       }
-      else
-       {
-         *Dest = *Src2;
-       }
-    }
-  else
-    {
-      if (IntGdiIsEmptyRect(Src2))
-       {
-         *Dest = *Src1;
-       }
-      else
-       {
-         Dest->left = min(Src1->left, Src2->left);
-         Dest->top = min(Src1->top, Src2->top);
-         Dest->right = max(Src1->right, Src2->right);
-         Dest->bottom = max(Src1->bottom, Src2->bottom);
-       }
-    }
-
-  return TRUE;
-}
 
-BOOL STDCALL
-NtGdiUnionRect(PRECT UnsafeDest, const RECT* UnsafeSrc1, const RECT* UnsafeSrc2)
+BOOL
+FASTCALL
+RECTL_bIntersectRect(RECTL* prclDst, const RECTL* prcl1, const RECTL* prcl2)
 {
-    RECT Dest, Src1 = {0}, Src2 = {0};
-  NTSTATUS Status = STATUS_SUCCESS;
-  BOOL Ret;
+    prclDst->left  = max(prcl1->left, prcl2->left);
+    prclDst->right = min(prcl1->right, prcl2->right);
 
-  _SEH_TRY
-  {
-    ProbeForRead(UnsafeSrc1,
-                 sizeof(RECT),
-                 1);
-    ProbeForRead(UnsafeSrc2,
-                 sizeof(RECT),
-                 1);
-    Src1 = *UnsafeSrc1;
-    Src2 = *UnsafeSrc2;
-  }
-  _SEH_HANDLE
-  {
-    Status = _SEH_GetExceptionCode();
-  }
-  _SEH_END;
-  if (! NT_SUCCESS(Status))
+    if (prclDst->left < prclDst->right)
     {
-      SetLastNtError(Status);
-      return FALSE;
-    }
-
-  Ret = IntGdiUnionRect(&Dest, &Src1, &Src2);
+        prclDst->top    = max(prcl1->top, prcl2->top);
+        prclDst->bottom = min(prcl1->bottom, prcl2->bottom);
 
-  if (Ret)
-    {
-      _SEH_TRY
-      {
-        ProbeForWrite(UnsafeDest,
-                      sizeof(RECT),
-                      1);
-        *UnsafeDest = Dest;
-      }
-      _SEH_HANDLE
-      {
-        Status = _SEH_GetExceptionCode();
-      }
-      _SEH_END;
-      if (! NT_SUCCESS(Status))
+        if (prclDst->top < prclDst->bottom)
         {
-          SetLastNtError(Status);
-          return FALSE;
+            return TRUE;
         }
     }
 
-  return Ret;
-}
+    RECTL_vSetEmptyRect(prclDst);
 
-VOID FASTCALL
-IntGdiSetRect(PRECT Rect, INT left, INT top, INT right, INT bottom)
-{
-  Rect->left = left;
-  Rect->top = top;
-  Rect->right = right;
-  Rect->bottom = bottom;
+    return FALSE;
 }
 
-BOOL STDCALL
-NtGdiSetRect(PRECT UnsafeRect, INT left, INT top, INT right, INT bottom)
+VOID
+FASTCALL
+RECTL_vMakeWellOrdered(RECTL *prcl)
 {
-  RECT Rect;
-  NTSTATUS Status = STATUS_SUCCESS;
-
-  IntGdiSetRect(&Rect, left, top, right, bottom);
-
-  _SEH_TRY
-  {
-    ProbeForWrite(UnsafeRect,
-                  sizeof(RECT),
-                  1);
-    *UnsafeRect = Rect;
-  }
-  _SEH_HANDLE
-  {
-    Status = _SEH_GetExceptionCode();
-  }
-  _SEH_END;
-  if (! NT_SUCCESS(Status))
+    LONG lTmp;
+    if (prcl->left > prcl->right)
     {
-      SetLastNtError(Status);
-      return FALSE;
+        lTmp = prcl->left;
+        prcl->left = prcl->right;
+        prcl->right = lTmp;       
     }
-
-  return TRUE;
-}
-
-BOOL FASTCALL
-IntGdiIntersectRect(PRECT Dest, const RECT* Src1, const RECT* Src2)
-{
-  if (IntGdiIsEmptyRect(Src1) || IntGdiIsEmptyRect(Src2) ||
-      Src1->left >= Src2->right || Src2->left >= Src1->right ||
-      Src1->top >= Src2->bottom || Src2->top >= Src1->bottom)
+    if (prcl->top > prcl->bottom)
     {
-      IntGdiSetEmptyRect(Dest);
-      return FALSE;
+        lTmp = prcl->top;
+        prcl->top = prcl->bottom;
+        prcl->bottom = lTmp;       
     }
-
-  Dest->left = max(Src1->left, Src2->left);
-  Dest->right = min(Src1->right, Src2->right);
-  Dest->top = max(Src1->top, Src2->top);
-  Dest->bottom = min(Src1->bottom, Src2->bottom);
-
-  return TRUE;
 }
 
-BOOL STDCALL
-NtGdiIntersectRect(PRECT UnsafeDest, const RECT* UnsafeSrc1, const RECT* UnsafeSrc2)
+VOID 
+FASTCALL
+RECTL_vInflateRect(RECTL *rect, INT dx, INT dy)
 {
-  RECT Dest, Src1, Src2 = {0};
-  NTSTATUS Status = STATUS_SUCCESS;
-  BOOL Ret;
-
-  _SEH_TRY
-  {
-    ProbeForRead(UnsafeSrc1,
-                 sizeof(RECT),
-                 1);
-    ProbeForRead(UnsafeSrc2,
-                 sizeof(RECT),
-                 1);
-    Src1 = *UnsafeSrc1;
-    Src2 = *UnsafeSrc2;
-  }
-  _SEH_HANDLE
-  {
-    Status = _SEH_GetExceptionCode();
-  }
-  _SEH_END;
-  if (! NT_SUCCESS(Status))
-    {
-      SetLastNtError(Status);
-      return FALSE;
-    }
-
-  Ret = IntGdiIntersectRect(&Dest, &Src2, &Src2);
-
-  if (Ret)
-    {
-      _SEH_TRY
-      {
-        ProbeForWrite(UnsafeDest,
-                      sizeof(RECT),
-                      1);
-        *UnsafeDest = Dest;
-      }
-      _SEH_HANDLE
-      {
-        Status = _SEH_GetExceptionCode();
-      }
-      _SEH_END;
-      if (! NT_SUCCESS(Status))
-        {
-          SetLastNtError(Status);
-          return FALSE;
-        }
-    }
-
-  return Ret;
+    rect->left -= dx;
+    rect->top -= dy;
+    rect->right += dx;
+    rect->bottom += dy;
 }
 
 /* EOF */