[YAROTOWS] Reintegrate the branch. For a brighter future.
[reactos.git] / reactos / subsystems / win32 / win32k / ntuser / cursoricon.c
index 427632e..2d8ff95 100644 (file)
@@ -109,7 +109,7 @@ UserSetCursor(
     PCURICON_OBJECT OldCursor;
     HCURSOR hOldCursor = (HCURSOR)0;
     HDC hdcScreen;
-       
+
        CurInfo = IntGetSysCursorInfo();
 
     OldCursor = CurInfo->CurrentCursorObject;
@@ -483,6 +483,7 @@ IntCleanupCurIcons(struct _EPROCESS *Process, PPROCESSINFO Win32Process)
 
 }
 
+
 /*
  * @implemented
  */
@@ -692,52 +693,73 @@ CLEANUP:
     END_CLEANUP;
 }
 
-
-/*
- * @implemented
- */
 BOOL
 APIENTRY
-NtUserClipCursor(
-    RECTL *UnsafeRect)
+UserClipCursor(
+    RECTL *prcl)
 {
     /* FIXME - check if process has WINSTA_WRITEATTRIBUTES */
     PSYSTEM_CURSORINFO CurInfo;
-    RECTL Rect;
     PWND DesktopWindow = NULL;
-    DECLARE_RETURN(BOOL);
-
-    DPRINT("Enter NtUserClipCursor\n");
-    UserEnterExclusive();
-
-    if (NULL != UnsafeRect && ! NT_SUCCESS(MmCopyFromCaller(&Rect, UnsafeRect, sizeof(RECT))))
-    {
-        SetLastWin32Error(ERROR_INVALID_PARAMETER);
-        RETURN(FALSE);
-    }
 
     CurInfo = IntGetSysCursorInfo();
 
     DesktopWindow = UserGetDesktopWindow();
 
-    if ((Rect.right > Rect.left) && (Rect.bottom > Rect.top)
-            && DesktopWindow && UnsafeRect != NULL)
+    if (prcl != NULL &&
+       (prcl->right > prcl->left) &&
+       (prcl->bottom > prcl->top) &&
+        DesktopWindow != NULL)
     {
-
         CurInfo->bClipped = TRUE;
-        RECTL_bIntersectRect(&CurInfo->rcClip, &Rect, &DesktopWindow->rcWindow);
+        RECTL_bIntersectRect(&CurInfo->rcClip, prcl, &DesktopWindow->rcWindow);
         UserSetCursorPos(gpsi->ptCursor.x, gpsi->ptCursor.y, FALSE);
+    }
+    else
+    {
+        CurInfo->bClipped = FALSE;
+    }
+
+    return TRUE;
+}
+
+/*
+ * @implemented
+ */
+BOOL
+APIENTRY
+NtUserClipCursor(
+    RECTL *prcl)
+{
+    RECTL rclLocal;
+    BOOL bResult;
+
+    if (prcl)
+    {
+        _SEH2_TRY
+        {
+            /* Probe and copy rect */
+            ProbeForRead(prcl, sizeof(RECTL), 1);
+            rclLocal = *prcl;
+        }
+        _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
+        {
+            SetLastWin32Error(ERROR_INVALID_PARAMETER);
+            _SEH2_YIELD(return FALSE;)
+        }
+        _SEH2_END
 
-        RETURN(TRUE);
+        prcl = &rclLocal;
     }
+       
+       UserEnterExclusive();
 
-    CurInfo->bClipped = FALSE;
-    RETURN(TRUE);
+    /* Call the internal function */
+    bResult = UserClipCursor(prcl);
 
-CLEANUP:
-    DPRINT("Leave NtUserClipCursor, ret=%i\n",_ret_);
     UserLeave();
-    END_CLEANUP;
+
+    return bResult;
 }
 
 
@@ -937,12 +959,12 @@ NtUserSetCursorContents(
 
     /* Delete old bitmaps */
     if ((CurIcon->IconInfo.hbmColor)
-               && (CurIcon->IconInfo.hbmColor != IconInfo.hbmColor))
+                       && (CurIcon->IconInfo.hbmColor != IconInfo.hbmColor))
     {
         GreDeleteObject(CurIcon->IconInfo.hbmColor);
     }
     if ((CurIcon->IconInfo.hbmMask)
-               && (CurIcon->IconInfo.hbmMask != IconInfo.hbmMask))
+                       && CurIcon->IconInfo.hbmMask != IconInfo.hbmMask)
     {
         GreDeleteObject(CurIcon->IconInfo.hbmMask);
     }
@@ -968,8 +990,8 @@ NtUserSetCursorContents(
         CurIcon->Size.cy = psurfBmp->SurfObj.sizlBitmap.cy / 2;
 
         SURFACE_UnlockSurface(psurfBmp);
-        GDIOBJ_SetOwnership(CurIcon->IconInfo.hbmMask, NULL);
     }
+       GDIOBJ_SetOwnership(CurIcon->IconInfo.hbmMask, NULL);
 
     Ret = TRUE;
 
@@ -1287,23 +1309,12 @@ UserDrawIconEx(
        if(bAlpha && (diFlags & DI_IMAGE))
        {
                BLENDFUNCTION pixelblend = { AC_SRC_OVER, 0, 255, AC_SRC_ALPHA };
-        DWORD Pixel;
-        BYTE Red, Green, Blue, Alpha;
-        DWORD Count = 0;
+        BYTE Alpha;
         INT i, j;
         PSURFACE psurf;
-        PBYTE pBits ;
+        PBYTE ptr ;
         HBITMAP hMemBmp = NULL;
 
-        pBits = ExAllocatePoolWithTag(PagedPool,
-                                      bmpColor.bmWidthBytes * abs(bmpColor.bmHeight),
-                                      TAG_BITMAP);
-        if (pBits == NULL)
-        {
-            Ret = FALSE;
-            goto CleanupAlpha;
-        }
-
         hMemBmp = BITMAP_CopyBitmap(hbmColor);
         if(!hMemBmp)
         {
@@ -1317,35 +1328,22 @@ UserDrawIconEx(
             DPRINT1("SURFACE_LockSurface failed!\n");
             goto CleanupAlpha;
         }
-        /* get color bits */
-        IntGetBitmapBits(psurf,
-                         bmpColor.bmWidthBytes * abs(bmpColor.bmHeight),
-                         pBits);
 
         /* premultiply with the alpha channel value */
-        for (i = 0; i < abs(bmpColor.bmHeight); i++)
+        for (i = 0; i < psurf->SurfObj.sizlBitmap.cy; i++)
         {
-                       Count = i*bmpColor.bmWidthBytes;
-            for (j = 0; j < bmpColor.bmWidth; j++)
+                       ptr = (PBYTE)psurf->SurfObj.pvScan0 + i*psurf->SurfObj.lDelta;
+            for (j = 0; j < psurf->SurfObj.sizlBitmap.cx; j++)
             {
-                Pixel = *(DWORD *)(pBits + Count);
-
-                Alpha = ((BYTE)(Pixel >> 24) & 0xff);
+                Alpha = ptr[3];
+                ptr[0] = (ptr[0] * Alpha) / 0xff;
+                ptr[1] = (ptr[1] * Alpha) / 0xff;
+                ptr[2] = (ptr[2] * Alpha) / 0xff;
 
-                Red   = (((BYTE)(Pixel >>  0)) * Alpha) / 0xff;
-                Green = (((BYTE)(Pixel >>  8)) * Alpha) / 0xff;
-                Blue  = (((BYTE)(Pixel >> 16)) * Alpha) / 0xff;
-
-                *(DWORD *)(pBits + Count) = (DWORD)(Red | (Green << 8) | (Blue << 16) | (Alpha << 24));
-
-                Count += sizeof(DWORD);
+                               ptr += 4;
             }
         }
 
-        /* set mem bits */
-        IntSetBitmapBits(psurf,
-                         bmpColor.bmWidthBytes * abs(bmpColor.bmHeight),
-                         pBits);
         SURFACE_UnlockSurface(psurf);
 
         hTmpBmp = NtGdiSelectBitmap(hMemDC, hMemBmp);
@@ -1364,12 +1362,10 @@ UserDrawIconEx(
                               NULL);
         NtGdiSelectBitmap(hMemDC, hTmpBmp);
     CleanupAlpha:
-        if(pBits) ExFreePoolWithTag(pBits, TAG_BITMAP);
         if(hMemBmp) NtGdiDeleteObjectApp(hMemBmp);
                if(Ret) goto done;
     }
 
-
     if (diFlags & DI_MASK)
     {
         hTmpBmp = NtGdiSelectBitmap(hMemDC, hbmMask);