[user32]
authorGregor Schneider <grschneider@gmail.com>
Tue, 29 Dec 2009 18:03:16 +0000 (18:03 +0000)
committerGregor Schneider <grschneider@gmail.com>
Tue, 29 Dec 2009 18:03:16 +0000 (18:03 +0000)
- Merge icon and cursor creation into one function, fix height assumptions
- Remove code preventing color cursors to be selected
- Winamp cursor is now shown correctly, bug #4370

svn path=/trunk/; revision=44802

reactos/dll/win32/user32/windows/bitmap.c
reactos/dll/win32/user32/windows/icon.c

index a3c6cf0..41486c5 100644 (file)
@@ -57,7 +57,7 @@ typedef struct
 #include "poppack.h"
 
 /* forward declarations... actually in user32\windows\icon.c but useful here */
 #include "poppack.h"
 
 /* forward declarations... actually in user32\windows\icon.c but useful here */
-HICON ICON_CreateIconFromData(HDC hDC, PVOID ImageData, ICONIMAGE* IconImage, int cxDesired, int cyDesired, int xHotspot, int yHotspot);
+HICON CreateCursorIconFromData(HDC hDC, PVOID ImageData, ICONIMAGE* IconImage, int cxDesired, int cyDesired, int xHotspot, int yHotspot, BOOL fIcon);
 CURSORICONDIRENTRY *CURSORICON_FindBestIcon( CURSORICONDIR *dir, int width, int height, int colors);
 CURSORICONDIRENTRY *CURSORICON_FindBestCursor( CURSORICONDIR *dir, int width, int height, int colors);
 
 CURSORICONDIRENTRY *CURSORICON_FindBestIcon( CURSORICONDIR *dir, int width, int height, int colors);
 CURSORICONDIRENTRY *CURSORICON_FindBestCursor( CURSORICONDIR *dir, int width, int height, int colors);
 
@@ -328,12 +328,6 @@ LoadCursorIconImage(
    else
    {
       ColorBits = GetDeviceCaps(hScreenDc, BITSPIXEL);
    else
    {
       ColorBits = GetDeviceCaps(hScreenDc, BITSPIXEL);
-      /*
-       * FIXME:
-       * Remove this after proper support for alpha icons will be finished.
-       */
-      if (ColorBits > 8)
-         ColorBits = 8;
    }
 
    /* Pick the best size. */
    }
 
    /* Pick the best size. */
@@ -390,7 +384,7 @@ LoadCursorIconImage(
    /* Make data point to the start of the XOR image data. */
    Data = (PBYTE)SafeIconImage + HeaderSize;
 
    /* Make data point to the start of the XOR image data. */
    Data = (PBYTE)SafeIconImage + HeaderSize;
 
-   hIcon = ICON_CreateIconFromData(hScreenDc, Data, SafeIconImage, width, height, width/2, height/2);
+   hIcon = CreateCursorIconFromData(hScreenDc, Data, SafeIconImage, width, height, width/2, height/2, Icon);
    RtlFreeHeap(GetProcessHeap(), 0, SafeIconImage);
    DeleteDC(hScreenDc);
 
    RtlFreeHeap(GetProcessHeap(), 0, SafeIconImage);
    DeleteDC(hScreenDc);
 
index bbf90d7..5840b89 100644 (file)
@@ -37,121 +37,72 @@ WINE_DEFAULT_DEBUG_CHANNEL(user32);
 
 
 HICON
 
 
 HICON
-ICON_CreateIconFromData(HDC hDC, PVOID ImageData, ICONIMAGE* IconImage, int cxDesired, int cyDesired, int xHotspot, int yHotspot)
+CreateCursorIconFromData(HDC hDC, PVOID ImageData, ICONIMAGE* IconImage, int cxDesired, int cyDesired, int xHotspot, int yHotspot, BOOL fIcon)
 {
    BYTE BitmapInfoBuffer[sizeof(BITMAPINFOHEADER) + 2 * sizeof(RGBQUAD)];
    BITMAPINFO *bwBIH = (BITMAPINFO *)BitmapInfoBuffer;
    ICONINFO IconInfo;
 
 {
    BYTE BitmapInfoBuffer[sizeof(BITMAPINFOHEADER) + 2 * sizeof(RGBQUAD)];
    BITMAPINFO *bwBIH = (BITMAPINFO *)BitmapInfoBuffer;
    ICONINFO IconInfo;
 
-   IconInfo.fIcon = TRUE;
+   IconInfo.fIcon = fIcon;
    IconInfo.xHotspot = xHotspot;
    IconInfo.yHotspot = yHotspot;
 
    IconInfo.xHotspot = xHotspot;
    IconInfo.yHotspot = yHotspot;
 
-   /* Load the XOR bitmap */
-   IconInfo.hbmColor = CreateDIBitmap(hDC, &IconImage->icHeader, CBM_INIT,
-                                      ImageData, (BITMAPINFO*)IconImage,
-                                      DIB_RGB_COLORS);
-
-   /* Make ImageData point to the start of the AND image data. */
-   ImageData = ((PBYTE)ImageData) + (((IconImage->icHeader.biWidth *
-                                      IconImage->icHeader.biBitCount + 31) & ~31) >> 3) *
-                                      (IconImage->icHeader.biHeight );
-
-   /* Create a BITMAPINFO header for the monocrome part of the icon. */
-   bwBIH->bmiHeader.biBitCount = 1;
-   bwBIH->bmiHeader.biWidth = IconImage->icHeader.biWidth;
-   bwBIH->bmiHeader.biHeight = IconImage->icHeader.biHeight;
-   bwBIH->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
-   bwBIH->bmiHeader.biPlanes = 1;
-   bwBIH->bmiHeader.biSizeImage = 0;
-   bwBIH->bmiHeader.biCompression = BI_RGB;
-   bwBIH->bmiHeader.biClrImportant = 0;
-   bwBIH->bmiHeader.biClrUsed = 0;
-   bwBIH->bmiHeader.biXPelsPerMeter = 0;
-   bwBIH->bmiHeader.biYPelsPerMeter = 0;
-
-   bwBIH->bmiColors[0].rgbBlue = 0;
-   bwBIH->bmiColors[0].rgbGreen = 0;
-   bwBIH->bmiColors[0].rgbRed = 0;
-   bwBIH->bmiColors[0].rgbReserved = 0;
-
-   bwBIH->bmiColors[1].rgbBlue = 0xff;
-   bwBIH->bmiColors[1].rgbGreen = 0xff;
-   bwBIH->bmiColors[1].rgbRed = 0xff;
-   bwBIH->bmiColors[1].rgbReserved = 0;
-
-   /* Load the AND bitmap. */
-   IconInfo.hbmMask = CreateDIBitmap(hDC, &bwBIH->bmiHeader, 0,
-                                     ImageData, bwBIH, DIB_RGB_COLORS);
-
-   SetDIBits(hDC, IconInfo.hbmMask, 0, IconImage->icHeader.biHeight,
-             ImageData, bwBIH, DIB_RGB_COLORS);
-
-   /* Create the icon based on everything we have so far */
-   return NtUserCreateCursorIconHandle(&IconInfo, FALSE);
-}
-
-HICON
-ICON_CreateCursorFromData(HDC hDC, PVOID ImageData, ICONIMAGE* IconImage, int cxDesired, int cyDesired, int xHotspot, int yHotspot)
-{
-   BYTE BitmapInfoBuffer[sizeof(BITMAPINFOHEADER) + 2 * sizeof(RGBQUAD)];
-   BITMAPINFO *bwBIH = (BITMAPINFO *)BitmapInfoBuffer;
-   BITMAPINFO *orgBIH = (BITMAPINFO *)IconImage;
-   ICONINFO IconInfo;
-
-   IconInfo.fIcon = FALSE;
-   IconInfo.xHotspot = xHotspot;
-   IconInfo.yHotspot = yHotspot;
-
-   /* Handle the color part of the cursor */
    if (IconImage->icHeader.biBitCount == 1)
    {
    if (IconImage->icHeader.biBitCount == 1)
    {
-      IconInfo.hbmColor = (HBITMAP)0;
+       IconInfo.hbmColor = (HBITMAP)0;
+       IconImage->icHeader.biHeight *= 2;
+       IconInfo.hbmMask = CreateDIBitmap(hDC, &IconImage->icHeader, CBM_INIT,
+                                  ImageData, (BITMAPINFO*)IconImage,
+                                  DIB_RGB_COLORS);
    }
    else
    {
    }
    else
    {
+       /* Create the XOR bitmap */
        IconInfo.hbmColor = CreateDIBitmap(hDC, &IconImage->icHeader, CBM_INIT,
                                           ImageData, (BITMAPINFO*)IconImage,
                                           DIB_RGB_COLORS);
        IconInfo.hbmColor = CreateDIBitmap(hDC, &IconImage->icHeader, CBM_INIT,
                                           ImageData, (BITMAPINFO*)IconImage,
                                           DIB_RGB_COLORS);
-   }
 
 
-   /* Create a BITMAPINFO header for the monochrome part of the cursor */
-   bwBIH->bmiHeader.biBitCount = 1;
-   bwBIH->bmiHeader.biWidth = IconImage->icHeader.biWidth;
-   bwBIH->bmiHeader.biHeight = IconImage->icHeader.biHeight;
-   bwBIH->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
-   bwBIH->bmiHeader.biPlanes = 1;
-   bwBIH->bmiHeader.biSizeImage = 0;
-   bwBIH->bmiHeader.biCompression = BI_RGB;
-   bwBIH->bmiHeader.biClrImportant = 0;
-   bwBIH->bmiHeader.biClrUsed = 0;
-   bwBIH->bmiHeader.biXPelsPerMeter = 0;
-   bwBIH->bmiHeader.biYPelsPerMeter = 0;
-
-   bwBIH->bmiColors[0].rgbBlue = 0;
-   bwBIH->bmiColors[0].rgbGreen = 0;
-   bwBIH->bmiColors[0].rgbRed = 0;
-   bwBIH->bmiColors[0].rgbReserved = 0;
-
-   bwBIH->bmiColors[1].rgbBlue = 0xff;
-   bwBIH->bmiColors[1].rgbGreen = 0xff;
-   bwBIH->bmiColors[1].rgbRed = 0xff;
-   bwBIH->bmiColors[1].rgbReserved = 0;
-
-   /* Load the monochrome bitmap */
-   IconInfo.hbmMask = CreateDIBitmap(hDC, &bwBIH->bmiHeader, 0,
-                                     ImageData, bwBIH, DIB_RGB_COLORS);
-   if (IconInfo.hbmMask)
-   {
-      SetDIBits(hDC, IconInfo.hbmMask, 0, IconImage->icHeader.biHeight,
-                ImageData, orgBIH, DIB_RGB_COLORS);
+       /* Make ImageData point to the start of the AND image data. */
+       ImageData = ((PBYTE)ImageData) + (((IconImage->icHeader.biWidth *
+                                          IconImage->icHeader.biBitCount + 31) & ~31) >> 3) *
+                                          (IconImage->icHeader.biHeight );
+
+       /* Create a BITMAPINFO header for the monochrome part of the icon. */
+       bwBIH->bmiHeader.biBitCount = 1;
+       bwBIH->bmiHeader.biWidth = IconImage->icHeader.biWidth;
+       bwBIH->bmiHeader.biHeight = IconImage->icHeader.biHeight;
+       bwBIH->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
+       bwBIH->bmiHeader.biPlanes = 1;
+       bwBIH->bmiHeader.biSizeImage = 0;
+       bwBIH->bmiHeader.biCompression = BI_RGB;
+       bwBIH->bmiHeader.biClrImportant = 0;
+       bwBIH->bmiHeader.biClrUsed = 0;
+       bwBIH->bmiHeader.biXPelsPerMeter = 0;
+       bwBIH->bmiHeader.biYPelsPerMeter = 0;
+
+       bwBIH->bmiColors[0].rgbBlue = 0;
+       bwBIH->bmiColors[0].rgbGreen = 0;
+       bwBIH->bmiColors[0].rgbRed = 0;
+       bwBIH->bmiColors[0].rgbReserved = 0;
+
+       bwBIH->bmiColors[1].rgbBlue = 0xff;
+       bwBIH->bmiColors[1].rgbGreen = 0xff;
+       bwBIH->bmiColors[1].rgbRed = 0xff;
+       bwBIH->bmiColors[1].rgbReserved = 0;
+
+       /* Create the AND bitmap. */
+       IconInfo.hbmMask = CreateDIBitmap(hDC, &bwBIH->bmiHeader, 0,
+                                         ImageData, bwBIH, DIB_RGB_COLORS);
+
+       SetDIBits(hDC, IconInfo.hbmMask, 0, IconImage->icHeader.biHeight,
+                 ImageData, bwBIH, DIB_RGB_COLORS);
    }
 
    }
 
+
    /* Create the icon based on everything we have so far */
    return NtUserCreateCursorIconHandle(&IconInfo, FALSE);
 }
 
    /* Create the icon based on everything we have so far */
    return NtUserCreateCursorIconHandle(&IconInfo, FALSE);
 }
 
-
 /*
  * @implemented
  */
 /*
  * @implemented
  */
@@ -290,8 +241,7 @@ CreateIconFromResourceEx(
     }
   memcpy(SafeIconImage, pbIconBits, cbIconBits);
 
     }
   memcpy(SafeIconImage, pbIconBits, cbIconBits);
 
-  /* take into acount the original height was for both the AND and XOR images */
-  if(fIcon)
+  /* Take into acount the original height was for both the AND and XOR images */
     SafeIconImage->icHeader.biHeight /= 2;
 
   if (SafeIconImage->icHeader.biSize == sizeof(BITMAPCOREHEADER))
     SafeIconImage->icHeader.biHeight /= 2;
 
   if (SafeIconImage->icHeader.biSize == sizeof(BITMAPCOREHEADER))
@@ -320,10 +270,7 @@ CreateIconFromResourceEx(
       return(NULL);
     }
 
       return(NULL);
     }
 
-  if(fIcon)
-    hIcon = ICON_CreateIconFromData(hScreenDc, Data, SafeIconImage, cxDesired, cyDesired, wXHotspot, wYHotspot);
-  else
-    hIcon = ICON_CreateCursorFromData(hScreenDc, Data, SafeIconImage, cxDesired, cyDesired, wXHotspot, wYHotspot);
+  hIcon = CreateCursorIconFromData(hScreenDc, Data, SafeIconImage, cxDesired, cyDesired, wXHotspot, wYHotspot, fIcon);
   RtlFreeHeap(GetProcessHeap(), 0, SafeIconImage);
   DeleteDC(hScreenDc);
 
   RtlFreeHeap(GetProcessHeap(), 0, SafeIconImage);
   DeleteDC(hScreenDc);