Author: fireball
Date: Sun Jun  6 23:40:11 2010
New Revision: 47640
URL: 
http://svn.reactos.org/svn/reactos?rev=47640&view=rev
Log:
- Remove my implementation of SWM cursor icons which turned out to be similar to creating
an elephant from a fly. Instead use a much simpler, updated and fail-proof implementation
by Giannis Adamopoulos. Arwinss is back on track.
Modified:
    branches/arwinss/reactos/dll/win32/winent.drv/mouse.c
    branches/arwinss/reactos/dll/win32/winent.drv/userdrv.c
    branches/arwinss/reactos/dll/win32/winent.drv/winent.h
    branches/arwinss/reactos/include/reactos/win32k/rosuser.h
    branches/arwinss/reactos/subsystems/win32/win32k/gre/cursoricon.c
    branches/arwinss/reactos/subsystems/win32/win32k/include/cursor.h
    branches/arwinss/reactos/subsystems/win32/win32k/include/gre.h
    branches/arwinss/reactos/subsystems/win32/win32k/include/swm.h
    branches/arwinss/reactos/subsystems/win32/win32k/main/cursor.c
    branches/arwinss/reactos/subsystems/win32/win32k/main/init.c
    branches/arwinss/reactos/subsystems/win32/win32k/swm/winman.c
    branches/arwinss/reactos/subsystems/win32/win32k/w32ksvc.db
Modified: branches/arwinss/reactos/dll/win32/winent.drv/mouse.c
URL:
http://svn.reactos.org/svn/reactos/branches/arwinss/reactos/dll/win32/winen…
==============================================================================
--- branches/arwinss/reactos/dll/win32/winent.drv/mouse.c [iso-8859-1] (original)
+++ branches/arwinss/reactos/dll/win32/winent.drv/mouse.c [iso-8859-1] Sun Jun  6 23:40:11
2010
@@ -1,5 +1,5 @@
 /*
- * X11 mouse driver
+ * NTDRV mouse driver
  *
  * Copyright 1998 Ulrich Weigand
  * Copyright 2007 Henri Verbeet
@@ -69,41 +69,8 @@
     MOUSEEVENTF_XUP
 };
-static HWND cursor_window;
 static BYTE TrackSysKey = 0; /* determine whether ALT key up will cause a WM_SYSKEYUP
                                 or a WM_KEYUP message */
-
-VOID create_cursor( HANDLE handle );
-
-/***********************************************************************
- *             set_window_cursor
- */
-void set_window_cursor( HWND hwnd, HCURSOR handle )
-{
-    struct ntdrv_win_data *data;
-
-    if (!(data = NTDRV_get_win_data( hwnd ))) return;
-
-    if (!handle)
-    {
-        // FIXME: Special case for removing the cursor
-        FIXME("TODO: Cursor should be removed!\n");
-        data->cursor = handle;
-        return;
-    }
-
-    /* Try to set the cursor */
-    if (!SwmDefineCursor(hwnd, handle))
-    {
-        /* This cursor doesn't exist yet, create it */
-        create_cursor(handle);
-
-        /* Set it for this window */
-        SwmDefineCursor(hwnd, handle);
-    }
-
-    data->cursor = handle;
-}
 /***********************************************************************
  *           get_key_state
@@ -165,12 +132,6 @@
         cursor = (reply->count >= 0) ? wine_server_ptr_handle(reply->cursor) :
0;
     }
     SERVER_END_REQ;
-
-    if (hwnd)
-    {
-        struct ntdrv_win_data *data = NTDRV_get_win_data( hwnd );
-        if (data && cursor != data->cursor) set_window_cursor( hwnd, cursor );
-    }
 }
 /***********************************************************************
@@ -233,7 +194,6 @@
     /* get the window handle from cursor position */
     hwnd = SwmGetWindowFromPoint(pt.x, pt.y);
-    cursor_window = hwnd;
     if (flags & MOUSEEVENTF_MOVE)
     {
@@ -424,208 +384,24 @@
 }
 /***********************************************************************
- *           get_bitmap_width_bytes
- *
- * Return number of bytes taken by a scanline of 16-bit aligned Windows DDB
- * data.
- * from user32/cursoricon.c:168
- */
-static int get_bitmap_width_bytes( int width, int bpp )
-{
-    switch(bpp)
-    {
-    case 1:
-        return 2 * ((width+15) / 16);
-    case 4:
-        return 2 * ((width+3) / 4);
-    case 24:
-        width *= 3;
-        /* fall through */
-    case 8:
-        return width + (width & 1);
-    case 16:
-    case 15:
-        return width * 2;
-    case 32:
-        return width * 4;
-    default:
-        WARN("Unknown depth %d, please report.\n", bpp );
-    }
-    return -1;
-}
-
-VOID CDECL RosDrv_GetIconInfo(CURSORICONINFO *ciconinfo, PICONINFO iconinfo)
-{
-    INT height;
-    BITMAP bitmap;
-    PVOID pbits;
-    static const WORD ICON_HOTSPOT = 0x4242; /* From user32/cursoricon.c:128 */
-
-    //TRACE("%p => %dx%d, %d bpp\n", ciconinfo,
-    //      ciconinfo->nWidth, ciconinfo->nHeight, ciconinfo->bBitsPerPixel);
-
-    if ( (ciconinfo->ptHotSpot.x == ICON_HOTSPOT) &&
-         (ciconinfo->ptHotSpot.y == ICON_HOTSPOT) )
-    {
-      iconinfo->fIcon    = TRUE;
-      iconinfo->xHotspot = ciconinfo->nWidth / 2;
-      iconinfo->yHotspot = ciconinfo->nHeight / 2;
+ *             DestroyCursorIcon (NTDRV.@)
+ */
+void CDECL RosDrv_DestroyCursorIcon( HCURSOR handle )
+{
+}
+
+void CDECL RosDrv_SetCursor( HCURSOR handle )
+{
+    ICONINFO iconinfo;
+
+    if(handle == NULL)
+    {
+        RosUserSetCursor(NULL);
     }
     else
     {
-      iconinfo->fIcon    = FALSE;
-      iconinfo->xHotspot = ciconinfo->ptHotSpot.x;
-      iconinfo->yHotspot = ciconinfo->ptHotSpot.y;
-    }
-
-    height = ciconinfo->nHeight;
-
-    if (ciconinfo->bBitsPerPixel > 1)
-    {
-        pbits = (char *)(ciconinfo + 1) + ciconinfo->nHeight * get_bitmap_width_bytes
(ciconinfo->nWidth,1);
-
-        iconinfo->hbmColor = CreateBitmap( ciconinfo->nWidth,
ciconinfo->nHeight,
-                                           ciconinfo->bPlanes,
ciconinfo->bBitsPerPixel,
-                                           pbits);
-        if(GetObjectW(iconinfo->hbmColor, sizeof(bitmap), &bitmap))
-            RosGdiCreateBitmap(NULL, iconinfo->hbmColor, &bitmap, pbits);
-    }
-    else
-    {
-        iconinfo->hbmColor = 0;
-        height *= 2;
-    }
-
-    pbits = (char *)(ciconinfo + 1);
-
-    /* Create the mask bitmap */
-    iconinfo->hbmMask = CreateBitmap ( ciconinfo->nWidth, height,
-                                       1, 1, pbits);
-    if( GetObjectW(iconinfo->hbmMask, sizeof(bitmap), &bitmap))
-    {
-        RosGdiCreateBitmap(NULL, iconinfo->hbmMask, &bitmap, pbits);
-    }
-}
-
-/***********************************************************************
- *             create_cursor
- *
- * Create a client cursor from a Windows one.
- */
-VOID create_cursor( HANDLE handle )
-{
-    HDC hdc;
-    ICONINFO icon;
-    BITMAP bm;
-
-    //if (!handle) return get_empty_cursor();
-
-    if (!(hdc = CreateCompatibleDC( 0 ))) return;
-    if (!GetIconInfo( handle, &icon ))
-    {
-        DeleteDC( hdc );
-        return;
-    }
-
-    GetObjectW( icon.hbmMask, sizeof(bm), &bm );
-    if (!icon.hbmColor) bm.bmHeight /= 2;
-
-    /* make sure hotspot is valid */
-    if (icon.xHotspot >= bm.bmWidth || icon.yHotspot >= bm.bmHeight)
-    {
-        icon.xHotspot = bm.bmWidth / 2;
-        icon.yHotspot = bm.bmHeight / 2;
-    }
-
-    // help for debugging
-#if 0
-    {
-        BITMAPINFO *info;
-        unsigned int *color_bits = NULL;
-        unsigned char *mask_bits = NULL;
-        int width = bm.bmWidth;
-        int height = bm.bmHeight;
-        unsigned int width_bytes = (width + 31) / 32 * 4;
-        BITMAP bitmap;
-
-
-        if (!(info = HeapAlloc( GetProcessHeap(), 0, FIELD_OFFSET( BITMAPINFO,
bmiColors[256] ))))
-            return;
-
-        info->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
-        info->bmiHeader.biWidth = width;
-        info->bmiHeader.biHeight = -height;
-        info->bmiHeader.biPlanes = 1;
-        info->bmiHeader.biBitCount = 1;
-        info->bmiHeader.biCompression = BI_RGB;
-        info->bmiHeader.biSizeImage = width_bytes * height;
-        info->bmiHeader.biXPelsPerMeter = 0;
-        info->bmiHeader.biYPelsPerMeter = 0;
-        info->bmiHeader.biClrUsed = 0;
-        info->bmiHeader.biClrImportant = 0;
-
-        if (!(mask_bits = HeapAlloc( GetProcessHeap(), 0, info->bmiHeader.biSizeImage
))) goto done;
-        if (!GetDIBits( hdc, icon.hbmMask, 0, height, mask_bits, info, DIB_RGB_COLORS ))
goto done;
-
-        /* HACK: Create the mask bitmap */
-        DeleteObject( icon.hbmMask );
-        icon.hbmMask = CreateBitmap ( width, height,
-                                           1, 1, NULL);
-        if( GetObjectW(icon.hbmMask, sizeof(bitmap), &bitmap))
-        {
-            RosGdiCreateBitmap(NULL, icon.hbmMask, &bitmap, NULL);
-            mask_bits[0] = 0xFF; mask_bits[1] = 0xFF; mask_bits[2] = 0xFF;
-            SetDIBits( hdc, icon.hbmMask, 0, height, mask_bits, info, DIB_RGB_COLORS );
-        }
-
-        info->bmiHeader.biBitCount = 32;
-        info->bmiHeader.biSizeImage = width * height * 4;
-        if (!(color_bits = HeapAlloc( GetProcessHeap(), 0, info->bmiHeader.biSizeImage
))) goto done;
-        GetDIBits( hdc, icon.hbmColor, 0, height, color_bits, info, DIB_RGB_COLORS );
-
-done:
-        HeapFree( GetProcessHeap(), 0, info );
-        HeapFree( GetProcessHeap(), 0, color_bits );
-        HeapFree( GetProcessHeap(), 0, mask_bits );
-    }
-#endif
-
-    /* Create the cursor icon */
-    RosUserCreateCursorIcon( &icon, handle );
-
-    //DeleteObject( icon.hbmMask );
-    DeleteDC( hdc );
-}
-
-/***********************************************************************
- *             DestroyCursorIcon (NTDRV.@)
- */
-void CDECL RosDrv_DestroyCursorIcon( HCURSOR handle )
-{
-    ICONINFO IconInfo = {0};
-
-    FIXME( "Destroying cursor %p\n", handle );
-
-    /* Destroy kernel mode part of the cursor icon */
-    RosUserDestroyCursorIcon( &IconInfo, handle );
-
-    /* Destroy usermode-created bitmaps */
-    // FIXME: Will it delete kernelmode bitmaps?!
-    // HACK
-    //if (IconInfo.hbmColor) DeleteObject( IconInfo.hbmColor );
-    //if (IconInfo.hbmMask) DeleteObject( IconInfo.hbmMask );
-}
-
-void CDECL RosDrv_SetCursor( HCURSOR handle )
-{
-
-    // HACK
-    if (!cursor_window)
-    {
-        cursor_window = SwmGetWindowFromPoint(200, 200);
-    }
-
-    if (cursor_window) SendNotifyMessageW( cursor_window, WM_NTDRV_SET_CURSOR, 0,
(LPARAM)handle );
-    FIXME("handle %x, cursor_window %x\n", handle, cursor_window);
-}
-
+        GetIconInfo(handle, &iconinfo);
+        RosUserSetCursor(&iconinfo);
+    }
+}
+
Modified: branches/arwinss/reactos/dll/win32/winent.drv/userdrv.c
URL:
http://svn.reactos.org/svn/reactos/branches/arwinss/reactos/dll/win32/winen…
==============================================================================
--- branches/arwinss/reactos/dll/win32/winent.drv/userdrv.c [iso-8859-1] (original)
+++ branches/arwinss/reactos/dll/win32/winent.drv/userdrv.c [iso-8859-1] Sun Jun  6
23:40:11 2010
@@ -763,9 +763,6 @@
 {
     switch(msg)
     {
-    case WM_NTDRV_SET_CURSOR:
-        set_window_cursor( hwnd, (HCURSOR)lparam );
-        return 0;
     default:
         FIXME( "got window msg %x hwnd %p wp %lx lp %lx\n", msg, hwnd, wparam,
lparam );
         return 0;
Modified: branches/arwinss/reactos/dll/win32/winent.drv/winent.h
URL:
http://svn.reactos.org/svn/reactos/branches/arwinss/reactos/dll/win32/winen…
==============================================================================
--- branches/arwinss/reactos/dll/win32/winent.drv/winent.h [iso-8859-1] (original)
+++ branches/arwinss/reactos/dll/win32/winent.drv/winent.h [iso-8859-1] Sun Jun  6
23:40:11 2010
@@ -14,12 +14,6 @@
     NTDRV_GET_GLX_DRAWABLE, /* get current glx drawable for a DC */
     NTDRV_SYNC_PIXMAP,      /* sync the dibsection to its pixmap */
     NTDRV_FLUSH_GL_DRAWABLE /* flush changes made to the gl drawable */
-};
-
-/* NT driver private messages, must be in the range 0x80001000..0x80001fff */
-enum ntdrv_window_messages
-{
-    WM_NTDRV_SET_CURSOR = 0x80001000
 };
 struct ntdrv_escape_set_drawable
Modified: branches/arwinss/reactos/include/reactos/win32k/rosuser.h
URL:
http://svn.reactos.org/svn/reactos/branches/arwinss/reactos/include/reactos…
==============================================================================
--- branches/arwinss/reactos/include/reactos/win32k/rosuser.h [iso-8859-1] (original)
+++ branches/arwinss/reactos/include/reactos/win32k/rosuser.h [iso-8859-1] Sun Jun  6
23:40:11 2010
@@ -46,6 +46,7 @@
 BOOL NTAPI
 RosUserClipCursor( LPCRECT clip );
+#if 0
 void NTAPI
 RosUserSetCursor( ICONINFO* IconInfo );
@@ -56,6 +57,11 @@
 VOID APIENTRY
 RosUserDestroyCursorIcon(ICONINFO* IconInfoUnsafe,
                          HCURSOR Handle);
+#endif
+
+VOID
+APIENTRY
+RosUserSetCursor( ICONINFO* IconInfoUnsafe );
 LONG
 APIENTRY
@@ -167,9 +173,6 @@
 VOID NTAPI
 SwmAddDesktopWindow(HWND hWnd, UINT Width, UINT Height);
-BOOL NTAPI
-SwmDefineCursor(HWND hWnd, HCURSOR hCursor);
-
 VOID NTAPI
 SwmRemoveWindow(HWND hWnd);
Modified: branches/arwinss/reactos/subsystems/win32/win32k/gre/cursoricon.c
URL:
http://svn.reactos.org/svn/reactos/branches/arwinss/reactos/subsystems/win3…
==============================================================================
--- branches/arwinss/reactos/subsystems/win32/win32k/gre/cursoricon.c [iso-8859-1]
(original)
+++ branches/arwinss/reactos/subsystems/win32/win32k/gre/cursoricon.c [iso-8859-1] Sun Jun
6 23:40:11 2010
@@ -13,7 +13,7 @@
 extern PDEVOBJ PrimarySurface;
 VOID NTAPI
-GreMovePointer(
+IntEngMovePointer(
     IN SURFOBJ *pso,
     IN LONG x,
     IN LONG y,
@@ -27,8 +27,30 @@
     SURFACE_UnlockBitmapBits(pSurf);
 }
+VOID
+NTAPI
+GreMovePointer(
+    HDC hdc,
+    LONG x,
+    LONG y)
+{
+    PRECTL prcl;
+    SURFOBJ *pso;
+
+    pso = EngLockSurface(PrimarySurface.pSurface);
+
+    /* Store the cursor exclude position in the PDEV */
+    prcl = &(GDIDEV(pso)->Pointer.Exclude);
+
+    /* Call Eng/Drv function */
+    IntEngMovePointer(pso, x, y, prcl);
+
+    EngUnlockSurface(pso);
+}
+
+
 ULONG NTAPI
-GreSetPointerShape(
+IntSetPointerShape(
    IN SURFOBJ *pso,
    IN SURFOBJ *psoMask,
    IN SURFOBJ *psoColor,
@@ -90,37 +112,23 @@
     return ulResult;
 }
-
-
-BOOL
+ULONG
 NTAPI
-GreSetCursor(ICONINFO* NewCursor, PSYSTEM_CURSORINFO CursorInfo)
+GreSetPointerShape(
+    HDC hdc,
+    HBITMAP hbmMask,
+    HBITMAP hbmColor,
+    LONG xHot,
+    LONG yHot,
+    LONG x,
+    LONG y)
 {
     SURFOBJ *pso;
-    HBITMAP hbmMask, hbmColor;
     PSURFACE psurfMask, psurfColor;
     XLATEOBJ *XlateObj = NULL;
     ULONG Status;
     pso = EngLockSurface(PrimarySurface.pSurface);
-
-    if (!NewCursor)
-    {
-        if (CursorInfo->ShowingCursor)
-        {
-            DPRINT("Removing pointer!\n");
-            /* Remove the cursor if it was displayed */
-            GreMovePointer(pso, -1, -1, NULL);
-        }
-        CursorInfo->ShowingCursor = 0;
-        EngUnlockSurface(pso);
-        return TRUE;
-    }
-
-    CursorInfo->ShowingCursor = TRUE;
-
-    hbmMask = NewCursor->hbmMask;
-    hbmColor = NewCursor->hbmColor;
     /* Lock the mask bitmap */
     if (hbmMask)
@@ -133,7 +141,7 @@
     {
         /* We have one, lock it */
         psurfColor = SURFACE_ShareLock(hbmColor);
-
+
         if (psurfColor)
         {
             /* Create an XLATEOBJ, no mono support */
@@ -144,14 +152,14 @@
     else
         psurfColor = NULL;
-   Status  = GreSetPointerShape(pso,
+   Status  = IntSetPointerShape(pso,
                                 psurfMask ? &psurfMask->SurfObj : NULL,
                                 psurfColor ? &psurfColor->SurfObj : NULL,
                                 XlateObj,
-                                NewCursor->xHotspot,
-                                NewCursor->yHotspot,
-                                CursorInfo->CursorPos.x,
-                                CursorInfo->CursorPos.y,
+                                xHot,
+                                yHot,
+                                x,
+                                y,
                                 &(GDIDEV(pso)->Pointer.Exclude),
                                 SPS_CHANGE);
Modified: branches/arwinss/reactos/subsystems/win32/win32k/include/cursor.h
URL:
http://svn.reactos.org/svn/reactos/branches/arwinss/reactos/subsystems/win3…
==============================================================================
--- branches/arwinss/reactos/subsystems/win32/win32k/include/cursor.h [iso-8859-1]
(original)
+++ branches/arwinss/reactos/subsystems/win32/win32k/include/cursor.h [iso-8859-1] Sun Jun
6 23:40:11 2010
@@ -31,8 +31,5 @@
 extern SYSTEM_CURSORINFO CursorInfo;
-VOID NTAPI USER_InitCursorIcons();
-VOID USER_LockCursorIcons();
-VOID USER_UnlockCursorIcons();
 PCURSORICONENTRY NTAPI USER_GetCursorIcon(HCURSOR Handle);
Modified: branches/arwinss/reactos/subsystems/win32/win32k/include/gre.h
URL:
http://svn.reactos.org/svn/reactos/branches/arwinss/reactos/subsystems/win3…
==============================================================================
--- branches/arwinss/reactos/subsystems/win32/win32k/include/gre.h [iso-8859-1] (original)
+++ branches/arwinss/reactos/subsystems/win32/win32k/include/gre.h [iso-8859-1] Sun Jun  6
23:40:11 2010
@@ -366,15 +366,23 @@
 /* Mouse pointer */
-BOOL NTAPI
-GreSetCursor(ICONINFO* NewCursor, PSYSTEM_CURSORINFO CursorInfo);
-
-VOID NTAPI
+ULONG
+NTAPI
+GreSetPointerShape(
+    HDC hdc,
+    HBITMAP hbmMask,
+    HBITMAP hbmColor,
+    LONG xHot,
+    LONG yHot,
+    LONG x,
+    LONG y);
+
+VOID
+NTAPI
 GreMovePointer(
-    SURFOBJ *pso,
+    HDC hdc,
     LONG x,
-    LONG y,
-    RECTL *prcl);
+    LONG y);
 INT FASTCALL
 MouseSafetyOnDrawStart(SURFOBJ *pso,
Modified: branches/arwinss/reactos/subsystems/win32/win32k/include/swm.h
URL:
http://svn.reactos.org/svn/reactos/branches/arwinss/reactos/subsystems/win3…
==============================================================================
--- branches/arwinss/reactos/subsystems/win32/win32k/include/swm.h [iso-8859-1] (original)
+++ branches/arwinss/reactos/subsystems/win32/win32k/include/swm.h [iso-8859-1] Sun Jun  6
23:40:11 2010
@@ -17,6 +17,6 @@
 PSWM_WINDOW NTAPI SwmFindByHwnd(HWND hWnd);
 VOID NTAPI SwmAcquire(VOID);
 VOID NTAPI SwmRelease(VOID);
-
+HDC SwmGetScreenDC();
 #endif
Modified: branches/arwinss/reactos/subsystems/win32/win32k/main/cursor.c
URL:
http://svn.reactos.org/svn/reactos/branches/arwinss/reactos/subsystems/win3…
==============================================================================
--- branches/arwinss/reactos/subsystems/win32/win32k/main/cursor.c [iso-8859-1] (original)
+++ branches/arwinss/reactos/subsystems/win32/win32k/main/cursor.c [iso-8859-1] Sun Jun  6
23:40:11 2010
@@ -10,10 +10,6 @@
 #define NDEBUG
 #include <debug.h>
-/* Cursor icons list */
-LIST_ENTRY CursorIcons;
-ERESOURCE CursorIconsLock;
-
 SYSTEM_CURSORINFO CursorInfo;
 extern PDEVOBJ PrimarySurface;
@@ -22,8 +18,6 @@
 APIENTRY
 RosUserGetCursorPos(LPPOINT pt)
 {
-    NTSTATUS Status = STATUS_SUCCESS;
-
     _SEH2_TRY
     {
         ProbeForWrite(pt, sizeof(POINT), 1);
@@ -31,11 +25,11 @@
     }
     _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
     {
-        Status = _SEH2_GetExceptionCode();
+        _SEH2_YIELD(return FALSE);
     }
     _SEH2_END;
-    return NT_SUCCESS(Status);
+    return TRUE;
 }
 static void NTAPI clip_point_to_rect(LPCRECT rect, LPPOINT pt)
@@ -51,7 +45,6 @@
 RosUserSetCursorPos(INT x, INT y)
 {
     POINT pos;
-    SURFOBJ *pso;
     pos.x = x;
     pos.y = y;
@@ -63,9 +56,10 @@
     if (CursorInfo.ShowingCursor)
     {
-        pso = EngLockSurface(PrimarySurface.pSurface);
-        GreMovePointer(pso, pos.x, pos.y, &(GDIDEV(pso)->Pointer.Exclude));
-        EngUnlockSurface(pso);
+        HDC hDCscreen = SwmGetScreenDC();
+        if (!hDCscreen) return FALSE;
+
+        GreMovePointer(hDCscreen, pos.x, pos.y);
     }
     CursorInfo.CursorPos = pos;
@@ -77,7 +71,6 @@
 APIENTRY
 RosUserClipCursor( LPCRECT UnsafeRect )
 {
-    NTSTATUS Status = STATUS_SUCCESS;
     RECT Rect;
     if (!UnsafeRect)
@@ -93,15 +86,10 @@
     }
     _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
     {
-        Status = _SEH2_GetExceptionCode();
+        SetLastWin32Error(ERROR_INVALID_PARAMETER);
+        _SEH2_YIELD(return FALSE);
     }
     _SEH2_END;
-
-    if (!NT_SUCCESS(Status))
-    {
-        SetLastWin32Error(ERROR_INVALID_PARAMETER);
-        return FALSE;
-    }
     CursorInfo.IsClipped = TRUE;
     CursorInfo.ClipRect = Rect;
@@ -111,166 +99,66 @@
     return TRUE;
 }
+VOID UserSetCursor(  ICONINFO* IconInfo )
+{
+    HDC hDCscreen;
+
+    hDCscreen = SwmGetScreenDC();
+    if (!hDCscreen) return;
+
+    if (!IconInfo)
+    {
+        if (CursorInfo.ShowingCursor == FALSE)
+            return;
+
+        DPRINT("Removing pointer!\n");
+        /* Remove the cursor if it was displayed */
+        GreMovePointer(hDCscreen, -1, -1);
+
+        CursorInfo.ShowingCursor = FALSE;
+        return;
+    }
+
+    IconInfo->hbmMask = GDI_MapUserHandle(IconInfo->hbmMask);
+    IconInfo->hbmColor = GDI_MapUserHandle(IconInfo->hbmColor);
+
+    DPRINT("hbmMask = 0x%x, hbmColor = 0x%x\n", IconInfo->hbmMask,
IconInfo->hbmColor);
+
+    GreSetPointerShape( hDCscreen,
+                        IconInfo->hbmMask,
+                        IconInfo->hbmColor,
+                        IconInfo->xHotspot,
+                        IconInfo->yHotspot,
+                        CursorInfo.CursorPos.x,
+                        CursorInfo.CursorPos.y);
+
+    CursorInfo.ShowingCursor = TRUE;
+}
+
 VOID
 APIENTRY
 RosUserSetCursor( ICONINFO* IconInfoUnsafe )
 {
     ICONINFO IconInfo;
-    NTSTATUS Status = STATUS_SUCCESS;
-    /* Special case for removing a pointer */
-    if (!IconInfoUnsafe)
+    if(IconInfoUnsafe == NULL)
     {
-        GreSetCursor(NULL, &CursorInfo);
-        return;
+        UserSetCursor(NULL);
     }
+    else
+    {
+        _SEH2_TRY
+        {
+            ProbeForRead(IconInfoUnsafe, sizeof(ICONINFO), 1);
+            RtlCopyMemory(&IconInfo, IconInfoUnsafe , sizeof(ICONINFO));
+        }
+        _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
+        {
+            _SEH2_YIELD(return;)
+        }
+        _SEH2_END;
-    _SEH2_TRY
-    {
-        ProbeForRead(IconInfoUnsafe, sizeof(ICONINFO), 1);
-        RtlCopyMemory(&IconInfo, IconInfoUnsafe , sizeof(ICONINFO));
-    }
-    _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
-    {
-        Status = _SEH2_GetExceptionCode();
-    }
-    _SEH2_END;
-
-    if (NT_SUCCESS(Status))
-    {
-        IconInfo.hbmMask = GDI_MapUserHandle(IconInfo.hbmMask);
-        IconInfo.hbmColor = GDI_MapUserHandle(IconInfo.hbmColor);
-        GreSetCursor(&IconInfo, &CursorInfo);
+        UserSetCursor(&IconInfo);
     }
 }
-VOID
-APIENTRY
-RosUserCreateCursorIcon(ICONINFO* IconInfoUnsafe,
-                        HCURSOR Handle)
-{
-    PCURSORICONENTRY pCursorIcon;
-
-    // FIXME: SEH!
-
-    /* Allocate an entry in the cursor icons list */
-    pCursorIcon = ExAllocatePool(PagedPool, sizeof(CURSORICONENTRY));
-    RtlZeroMemory(pCursorIcon, sizeof(CURSORICONENTRY));
-
-    /* Save the usermode handle and other fields */
-    pCursorIcon->Self = Handle;
-    pCursorIcon->IconInfo = *IconInfoUnsafe;
-    pCursorIcon->hbmMaskUser = IconInfoUnsafe->hbmMask;
-    pCursorIcon->hbmColorUser = IconInfoUnsafe->hbmColor;
-
-    /* Map handles */
-    pCursorIcon->IconInfo.hbmMask =
GDI_MapUserHandle(pCursorIcon->IconInfo.hbmMask);
-    if (pCursorIcon->IconInfo.hbmColor)
-        pCursorIcon->IconInfo.hbmColor =
GDI_MapUserHandle(pCursorIcon->IconInfo.hbmColor);
-
-    /* Make those bitmaps "system" objects */
-    GDIOBJ_SetOwnership(pCursorIcon->IconInfo.hbmMask, NULL);
-    if (pCursorIcon->IconInfo.hbmColor)
-        GDIOBJ_SetOwnership(pCursorIcon->IconInfo.hbmColor, NULL);
-
-    /* Acquire lock */
-    USER_LockCursorIcons();
-
-    /* Add it to the list */
-    InsertTailList(&CursorIcons, &pCursorIcon->Entry);
-
-    /* Release lock */
-    USER_UnlockCursorIcons();
-}
-
-VOID
-APIENTRY
-RosUserDestroyCursorIcon(ICONINFO* IconInfoUnsafe,
-                         HCURSOR Handle)
-{
-    PLIST_ENTRY Current;
-    PCURSORICONENTRY pCursorIcon;
-
-    /* Acquire lock */
-    USER_LockCursorIcons();
-
-    /* Traverse the list to find our mapping */
-    Current = CursorIcons.Flink;
-    while(Current != &CursorIcons)
-    {
-        pCursorIcon = CONTAINING_RECORD(Current, CURSORICONENTRY, Entry);
-
-        /* Check if it's our entry */
-        if (pCursorIcon->Self == Handle)
-        {
-            /* Remove it from the list */
-            RemoveEntryList(Current);
-
-            /* Get handles back to the user for proper disposal */
-            IconInfoUnsafe->hbmColor = pCursorIcon->hbmColorUser;
-            IconInfoUnsafe->hbmMask = pCursorIcon->hbmMaskUser;
-
-            // TODO: Go through all windows and remove this cursor from them!
-            DPRINT1("Hitting a TODO!\n");
-
-            /* Free memory */
-            ExFreePool(pCursorIcon);
-            break;
-        }
-
-        /* Advance to the next pair */
-        Current = Current->Flink;
-    }
-
-    /* Release lock */
-    USER_UnlockCursorIcons();
-}
-
-PCURSORICONENTRY
-NTAPI
-USER_GetCursorIcon(HCURSOR Handle)
-{
-    PLIST_ENTRY Current;
-    PCURSORICONENTRY pCursorIcon;
-
-    /* Traverse the list to find our mapping */
-    Current = CursorIcons.Flink;
-    while(Current != &CursorIcons)
-    {
-        pCursorIcon = CONTAINING_RECORD(Current, CURSORICONENTRY, Entry);
-
-        /* Check if it's our entry */
-        if (pCursorIcon->Self == Handle) return pCursorIcon;
-
-        /* Advance to the next pair */
-        Current = Current->Flink;
-    }
-
-    return NULL;
-}
-
-VOID NTAPI
-USER_InitCursorIcons()
-{
-    NTSTATUS Status;
-
-    /* Initialize cursor icons list and a spinlock */
-    InitializeListHead(&CursorIcons);
-    Status = ExInitializeResourceLite(&CursorIconsLock);
-    if (!NT_SUCCESS(Status))
-        DPRINT1("Initializing cursor icons lock failed with Status 0x%08X\n",
Status);
-}
-
-VOID USER_LockCursorIcons()
-{
-    /* Acquire lock */
-    KeEnterCriticalRegion();
-    ExAcquireResourceExclusiveLite(&CursorIconsLock, TRUE);
-}
-
-VOID USER_UnlockCursorIcons()
-{
-    /* Release lock */
-    ExReleaseResourceLite(&CursorIconsLock);
-    KeLeaveCriticalRegion();
-}
Modified: branches/arwinss/reactos/subsystems/win32/win32k/main/init.c
URL:
http://svn.reactos.org/svn/reactos/branches/arwinss/reactos/subsystems/win3…
==============================================================================
--- branches/arwinss/reactos/subsystems/win32/win32k/main/init.c [iso-8859-1] (original)
+++ branches/arwinss/reactos/subsystems/win32/win32k/main/init.c [iso-8859-1] Sun Jun  6
23:40:11 2010
@@ -357,9 +357,6 @@
     /* Initialize handle-mapping */
     GDI_InitHandleMapping();
-    /* Initialize cursor icons */
-    USER_InitCursorIcons();
-
     /* Create stock objects */
     CreateStockBitmap();
     PALETTE_Init();
Modified: branches/arwinss/reactos/subsystems/win32/win32k/swm/winman.c
URL:
http://svn.reactos.org/svn/reactos/branches/arwinss/reactos/subsystems/win3…
==============================================================================
--- branches/arwinss/reactos/subsystems/win32/win32k/swm/winman.c [iso-8859-1] (original)
+++ branches/arwinss/reactos/subsystems/win32/win32k/swm/winman.c [iso-8859-1] Sun Jun  6
23:40:11 2010
@@ -35,7 +35,6 @@
 LIST_ENTRY SwmWindows;
 ERESOURCE SwmLock;
 HDC SwmDc; /* Screen DC for copying operations */
-PCURSORICONENTRY SwmLastCursor;
 /* FUNCTIONS *****************************************************************/
@@ -87,6 +86,14 @@
     GDIOBJ_SetOwnership(SwmDc, NULL);
 }
+HDC SwmGetScreenDC()
+{
+    /* Lazily create a global screen DC */
+    if (!SwmDc) SwmCreateScreenDc();
+
+    return SwmDc;
+}
+
 VOID
 NTAPI
 SwmInvalidateRegion(PSWM_WINDOW Window, struct region *Region, rectangle_t *Rect)
@@ -785,37 +792,11 @@
         if (point_in_region(Window->Visible, x, y))
         {
-            /* Acquire CI lock */
-            USER_LockCursorIcons();
-
-            /* Check if cursor needs to be changed */
-            if (Window->Cursor != SwmLastCursor)
-            {
-                if (Window->Cursor)
-                {
-                    /* Set the new cursor */
-                    DPRINT1("Setting cursor bitmap %p for hwnd %p\n",
Window->Cursor->IconInfo.hbmMask, Window->hwnd);
-                    GreSetCursor(&Window->Cursor->IconInfo, &CursorInfo);
-                }
-                else
-                {
-                    /* This window should have no cursor */
-                    GreSetCursor(NULL, &CursorInfo);
-                }
-
-                /* Update the last cursor */
-                SwmLastCursor = Window->Cursor;
-            }
-
-            /* Release CI lock */
-            USER_UnlockCursorIcons();
-
             /* Release the lock */
             SwmRelease();
             return Window->hwnd;
         }
-
         /* Advance to the next window */
         Current = Current->Flink;
     }
@@ -826,63 +807,6 @@
     return 0;
 }
-BOOL
-NTAPI
-SwmDefineCursor(HWND hWnd, HCURSOR hCursor)
-{
-    PCURSORICONENTRY pCursorIcon;
-    PSWM_WINDOW pSwmWindow;
-
-    /* Acquire CI lock */
-    USER_LockCursorIcons();
-
-    /* Try to find this cursor */
-    pCursorIcon = USER_GetCursorIcon(hCursor);
-
-    /* Release CI lock */
-    USER_UnlockCursorIcons();
-
-    if (!pCursorIcon) return FALSE;
-
-    /* Acquire the SWM lock */
-    SwmAcquire();
-
-    if (!hWnd)
-    {
-        /* Special case for setting default cursor */
-        DPRINT1("Setting cursor bitmap uh%p\n", pCursorIcon->hbmMaskUser);
-        GreSetCursor(&pCursorIcon->IconInfo, &CursorInfo);
-
-        /* Update current cursor */
-        SwmLastCursor = hCursor;
-
-        /* Release the SWM lock */
-        SwmRelease();
-
-        return TRUE;
-    }
-
-    /* Now find the window */
-    pSwmWindow = SwmFindByHwnd(hWnd);
-
-    /* Success is returned in this case */
-    if (!pSwmWindow)
-    {
-        /* Release the SWM lock */
-        SwmRelease();
-
-        return TRUE;
-    }
-
-    /* Set a cursor for this window */
-    pSwmWindow->Cursor = pCursorIcon;
-
-    /* Release the SWM lock */
-    SwmRelease();
-
-    return TRUE;
-}
-
 VOID
 NTAPI
 SwmInitialize()
@@ -900,10 +824,7 @@
         DPRINT1("Failure initializing SWM resource!\n");
     }
-    /* Cursor is hidden by default */
-    SwmLastCursor = NULL;
-
-    SwmTest();
+    //SwmTest();
 }
 VOID
Modified: branches/arwinss/reactos/subsystems/win32/win32k/w32ksvc.db
URL:
http://svn.reactos.org/svn/reactos/branches/arwinss/reactos/subsystems/win3…
==============================================================================
--- branches/arwinss/reactos/subsystems/win32/win32k/w32ksvc.db [iso-8859-1] (original)
+++ branches/arwinss/reactos/subsystems/win32/win32k/w32ksvc.db [iso-8859-1] Sun Jun  6
23:40:11 2010
@@ -64,12 +64,10 @@
 RosGdiSwapBuffers                  1
 RosGdiUnrealizePalette             1
 RosUserConnectCsrss                0
-RosUserCreateCursorIcon            2
-RosUserDestroyCursorIcon           2
+RosUserSetCursor                   1
 RosUserGetCursorPos                1
 RosUserSetCursorPos                2
 RosUserClipCursor                  1
-RosUserSetCursor                   1
 RosUserChangeDisplaySettings       5
 RosUserEnumDisplayMonitors         3
 RosUserEnumDisplaySettings         4
@@ -88,7 +86,6 @@
 RosUserGetAsyncKeyState            1
 SwmAddWindow                       2
 SwmAddDesktopWindow                3
-SwmDefineCursor                    2
 SwmRemoveWindow                    1
 SwmSetForeground                   1
 SwmPosChanging                     2