[4/6] USER: .ANI cursor loading preparation

H. Verbeet hverbeet at gmail.com
Tue Apr 18 16:50:22 CDT 2006


This patch just adds a couple of braces around the main block of code
in CreateIconFromResourceEx. It shouldn't alter any other code. The
main purpose of this patch is to keep the next few patches readable.

Changelog:
  - .ANI cursor loading preparation
-------------- next part --------------
diff --git a/dlls/user/cursoricon.c b/dlls/user/cursoricon.c
index 64aa3cb..b85f4ae 100644
--- a/dlls/user/cursoricon.c
+++ b/dlls/user/cursoricon.c
@@ -705,184 +705,185 @@ HICON WINAPI CreateIconFromResourceEx( L
         return 0;
     }
 
-    if (bIcon)
-        bmi = (BITMAPINFO *)bits;
-    else /* get the hotspot */
     {
-        POINT16 *pt = (POINT16 *)bits;
-        hotspot = *pt;
-        bmi = (BITMAPINFO *)(pt + 1);
-    }
-    size = bitmap_info_size( bmi, DIB_RGB_COLORS );
-
-    if (!width) width = bmi->bmiHeader.biWidth;
-    if (!height) height = bmi->bmiHeader.biHeight/2;
-    DoStretch = (bmi->bmiHeader.biHeight/2 != height) ||
-      (bmi->bmiHeader.biWidth != width);
-
-    /* Check bitmap header */
-
-    if ( (bmi->bmiHeader.biSize != sizeof(BITMAPCOREHEADER)) &&
-         (bmi->bmiHeader.biSize != sizeof(BITMAPINFOHEADER)  ||
-          bmi->bmiHeader.biCompression != BI_RGB) )
-    {
-          WARN_(cursor)("\tinvalid resource bitmap header.\n");
-          return 0;
-    }
-
-    if (!screen_dc) screen_dc = CreateDCW( DISPLAYW, NULL, NULL, NULL );
-    if (screen_dc)
-    {
-        BITMAPINFO* pInfo;
-
-        /* Make sure we have room for the monochrome bitmap later on.
-         * Note that BITMAPINFOINFO and BITMAPCOREHEADER are the same
-         * up to and including the biBitCount. In-memory icon resource
-         * format is as follows:
-         *
-         *   BITMAPINFOHEADER   icHeader  // DIB header
-         *   RGBQUAD         icColors[]   // Color table
-         *   BYTE            icXOR[]      // DIB bits for XOR mask
-         *   BYTE            icAND[]      // DIB bits for AND mask
-         */
-
-        if ((pInfo = HeapAlloc( GetProcessHeap(), 0,
-                                max(size, sizeof(BITMAPINFOHEADER) + 2*sizeof(RGBQUAD)))))
+        if (bIcon)
+            bmi = (BITMAPINFO *)bits;
+        else /* get the hotspot */
         {
-            memcpy( pInfo, bmi, size );
-            pInfo->bmiHeader.biHeight /= 2;
+            POINT16 *pt = (POINT16 *)bits;
+            hotspot = *pt;
+            bmi = (BITMAPINFO *)(pt + 1);
+        }
+        size = bitmap_info_size( bmi, DIB_RGB_COLORS );
 
-            /* Create the XOR bitmap */
+        if (!width) width = bmi->bmiHeader.biWidth;
+        if (!height) height = bmi->bmiHeader.biHeight/2;
+        DoStretch = (bmi->bmiHeader.biHeight/2 != height) ||
+          (bmi->bmiHeader.biWidth != width);
+
+        /* Check bitmap header */
+
+        if ( (bmi->bmiHeader.biSize != sizeof(BITMAPCOREHEADER)) &&
+             (bmi->bmiHeader.biSize != sizeof(BITMAPINFOHEADER)  ||
+              bmi->bmiHeader.biCompression != BI_RGB) )
+        {
+              WARN_(cursor)("\tinvalid resource bitmap header.\n");
+              return 0;
+        }
 
-            if (DoStretch) {
-                if(bIcon)
-                {
-                    hXorBits = CreateCompatibleBitmap(screen_dc, width, height);
-                }
-                else
-                {
-                    hXorBits = CreateBitmap(width, height, 1, 1, NULL);
-                }
-                if(hXorBits)
-                {
-                HBITMAP hOld;
-                BOOL res = FALSE;
+        if (!screen_dc) screen_dc = CreateDCW( DISPLAYW, NULL, NULL, NULL );
+        if (screen_dc)
+        {
+            BITMAPINFO* pInfo;
 
-                if (!hdcMem) hdcMem = CreateCompatibleDC(screen_dc);
-                if (hdcMem) {
-                    hOld = SelectObject(hdcMem, hXorBits);
-                    res = StretchDIBits(hdcMem, 0, 0, width, height, 0, 0,
-                                        bmi->bmiHeader.biWidth, bmi->bmiHeader.biHeight/2,
-                                        (char*)bmi + size, pInfo, DIB_RGB_COLORS, SRCCOPY);
-                    SelectObject(hdcMem, hOld);
-                }
-                if (!res) { DeleteObject(hXorBits); hXorBits = 0; }
-              }
-            } else {
-              if (is_dib_monochrome(bmi)) {
-                  hXorBits = CreateBitmap(width, height, 1, 1, NULL);
-                  SetDIBits(screen_dc, hXorBits, 0, height,
-                     (char*)bmi + size, pInfo, DIB_RGB_COLORS);
-              }
-              else
-                  hXorBits = CreateDIBitmap(screen_dc, &pInfo->bmiHeader,
-                     CBM_INIT, (char*)bmi + size, pInfo, DIB_RGB_COLORS); 
-            }
+            /* Make sure we have room for the monochrome bitmap later on.
+             * Note that BITMAPINFOINFO and BITMAPCOREHEADER are the same
+             * up to and including the biBitCount. In-memory icon resource
+             * format is as follows:
+             *
+             *   BITMAPINFOHEADER   icHeader  // DIB header
+             *   RGBQUAD         icColors[]   // Color table
+             *   BYTE            icXOR[]      // DIB bits for XOR mask
+             *   BYTE            icAND[]      // DIB bits for AND mask
+             */
 
-            if( hXorBits )
+            if ((pInfo = HeapAlloc( GetProcessHeap(), 0,
+                                    max(size, sizeof(BITMAPINFOHEADER) + 2*sizeof(RGBQUAD)))))
             {
-                char* xbits = (char *)bmi + size +
-                    get_dib_width_bytes( bmi->bmiHeader.biWidth,
-                                         bmi->bmiHeader.biBitCount ) * abs( bmi->bmiHeader.biHeight ) / 2;
+                memcpy( pInfo, bmi, size );
+                pInfo->bmiHeader.biHeight /= 2;
 
-                pInfo->bmiHeader.biBitCount = 1;
-                if (pInfo->bmiHeader.biSize != sizeof(BITMAPCOREHEADER))
-                {
-                    RGBQUAD *rgb = pInfo->bmiColors;
+                /* Create the XOR bitmap */
 
-                    pInfo->bmiHeader.biClrUsed = pInfo->bmiHeader.biClrImportant = 2;
-                    rgb[0].rgbBlue = rgb[0].rgbGreen = rgb[0].rgbRed = 0x00;
-                    rgb[1].rgbBlue = rgb[1].rgbGreen = rgb[1].rgbRed = 0xff;
-                    rgb[0].rgbReserved = rgb[1].rgbReserved = 0;
+                if (DoStretch) {
+                    if(bIcon)
+                    {
+                        hXorBits = CreateCompatibleBitmap(screen_dc, width, height);
+                    }
+                    else
+                    {
+                        hXorBits = CreateBitmap(width, height, 1, 1, NULL);
+                    }
+                    if(hXorBits)
+                    {
+                        HBITMAP hOld;
+                        BOOL res = FALSE;
+
+                        if (!hdcMem) hdcMem = CreateCompatibleDC(screen_dc);
+                        if (hdcMem) {
+                            hOld = SelectObject(hdcMem, hXorBits);
+                            res = StretchDIBits(hdcMem, 0, 0, width, height, 0, 0,
+                                                bmi->bmiHeader.biWidth, bmi->bmiHeader.biHeight/2,
+                                                (char*)bmi + size, pInfo, DIB_RGB_COLORS, SRCCOPY);
+                            SelectObject(hdcMem, hOld);
+                        }
+                        if (!res) { DeleteObject(hXorBits); hXorBits = 0; }
+                    }
+                } else {
+                    if (is_dib_monochrome(bmi)) {
+                        hXorBits = CreateBitmap(width, height, 1, 1, NULL);
+                        SetDIBits(screen_dc, hXorBits, 0, height,
+                            (char*)bmi + size, pInfo, DIB_RGB_COLORS);
+                    }
+                    else
+                        hXorBits = CreateDIBitmap(screen_dc, &pInfo->bmiHeader,
+                            CBM_INIT, (char*)bmi + size, pInfo, DIB_RGB_COLORS);
                 }
-                else
-                {
-                    RGBTRIPLE *rgb = (RGBTRIPLE *)(((BITMAPCOREHEADER *)pInfo) + 1);
 
-                    rgb[0].rgbtBlue = rgb[0].rgbtGreen = rgb[0].rgbtRed = 0x00;
-                    rgb[1].rgbtBlue = rgb[1].rgbtGreen = rgb[1].rgbtRed = 0xff;
-                }
+                if( hXorBits )
+                {
+                    char* xbits = (char *)bmi + size +
+                        get_dib_width_bytes( bmi->bmiHeader.biWidth,
+                                             bmi->bmiHeader.biBitCount ) * abs( bmi->bmiHeader.biHeight ) / 2;
+
+                    pInfo->bmiHeader.biBitCount = 1;
+                    if (pInfo->bmiHeader.biSize != sizeof(BITMAPCOREHEADER))
+                    {
+                        RGBQUAD *rgb = pInfo->bmiColors;
+
+                        pInfo->bmiHeader.biClrUsed = pInfo->bmiHeader.biClrImportant = 2;
+                        rgb[0].rgbBlue = rgb[0].rgbGreen = rgb[0].rgbRed = 0x00;
+                        rgb[1].rgbBlue = rgb[1].rgbGreen = rgb[1].rgbRed = 0xff;
+                        rgb[0].rgbReserved = rgb[1].rgbReserved = 0;
+                    }
+                    else
+                    {
+                        RGBTRIPLE *rgb = (RGBTRIPLE *)(((BITMAPCOREHEADER *)pInfo) + 1);
+
+                        rgb[0].rgbtBlue = rgb[0].rgbtGreen = rgb[0].rgbtRed = 0x00;
+                        rgb[1].rgbtBlue = rgb[1].rgbtGreen = rgb[1].rgbtRed = 0xff;
+                    }
+
+                    /* Create the AND bitmap */
+
+                    if (DoStretch) {
+                        if ((hAndBits = CreateBitmap(width, height, 1, 1, NULL))) {
+                            HBITMAP hOld;
+                            BOOL res = FALSE;
+
+                            if (!hdcMem) hdcMem = CreateCompatibleDC(screen_dc);
+                            if (hdcMem) {
+                                hOld = SelectObject(hdcMem, hAndBits);
+                                res = StretchDIBits(hdcMem, 0, 0, width, height, 0, 0,
+                                            pInfo->bmiHeader.biWidth, pInfo->bmiHeader.biHeight,
+                                            xbits, pInfo, DIB_RGB_COLORS, SRCCOPY);
+                                SelectObject(hdcMem, hOld);
+                            }
+                            if (!res) { DeleteObject(hAndBits); hAndBits = 0; }
+                        }
+                    } else {
+                        hAndBits = CreateBitmap(width, height, 1, 1, NULL);
 
-                /* Create the AND bitmap */
+                        if (hAndBits) SetDIBits(screen_dc, hAndBits, 0, height,
+                                 xbits, pInfo, DIB_RGB_COLORS);
 
-            if (DoStretch) {
-              if ((hAndBits = CreateBitmap(width, height, 1, 1, NULL))) {
-                HBITMAP hOld;
-                BOOL res = FALSE;
-
-                if (!hdcMem) hdcMem = CreateCompatibleDC(screen_dc);
-                if (hdcMem) {
-                    hOld = SelectObject(hdcMem, hAndBits);
-                    res = StretchDIBits(hdcMem, 0, 0, width, height, 0, 0,
-                                        pInfo->bmiHeader.biWidth, pInfo->bmiHeader.biHeight,
-                                        xbits, pInfo, DIB_RGB_COLORS, SRCCOPY);
-                    SelectObject(hdcMem, hOld);
+                    }
+                    if( !hAndBits ) DeleteObject( hXorBits );
                 }
-                if (!res) { DeleteObject(hAndBits); hAndBits = 0; }
-              }
-            } else {
-              hAndBits = CreateBitmap(width, height, 1, 1, NULL);
-
-              if (hAndBits) SetDIBits(screen_dc, hAndBits, 0, height,
-                             xbits, pInfo, DIB_RGB_COLORS);
-
+                HeapFree( GetProcessHeap(), 0, pInfo );
             }
-                if( !hAndBits ) DeleteObject( hXorBits );
-            }
-            HeapFree( GetProcessHeap(), 0, pInfo );
         }
-    }
-
-    if( !hXorBits || !hAndBits )
-    {
-        WARN_(cursor)("\tunable to create an icon bitmap.\n");
-        return 0;
-    }
 
-    /* Now create the CURSORICONINFO structure */
-    GetObjectA( hXorBits, sizeof(bmpXor), &bmpXor );
-    GetObjectA( hAndBits, sizeof(bmpAnd), &bmpAnd );
-    sizeXor = bmpXor.bmHeight * bmpXor.bmWidthBytes;
-    sizeAnd = bmpAnd.bmHeight * bmpAnd.bmWidthBytes;
+        if( !hXorBits || !hAndBits )
+        {
+            WARN_(cursor)("\tunable to create an icon bitmap.\n");
+            return 0;
+        }
 
-    hObj = GlobalAlloc16( GMEM_MOVEABLE,
-                     sizeof(CURSORANIINFO) + sizeof(CURSORICONINFO) + sizeXor + sizeAnd );
-    if (hObj)
-    {
-        CURSORANIINFO *ani_info;
-        CURSORICONINFO *info;
+        /* Now create the CURSORICONINFO structure */
+        GetObjectA( hXorBits, sizeof(bmpXor), &bmpXor );
+        GetObjectA( hAndBits, sizeof(bmpAnd), &bmpAnd );
+        sizeXor = bmpXor.bmHeight * bmpXor.bmWidthBytes;
+        sizeAnd = bmpAnd.bmHeight * bmpAnd.bmWidthBytes;
+
+        hObj = GlobalAlloc16( GMEM_MOVEABLE,
+                         sizeof(CURSORANIINFO) + sizeof(CURSORICONINFO) + sizeXor + sizeAnd );
+        if (hObj)
+        {
+            CURSORANIINFO *ani_info;
+            CURSORICONINFO *info;
 
-        ani_info = (CURSORANIINFO *)GlobalLock16( hObj );
-        ani_info->num_frames = 1;
-        ani_info->delay = 0;
-        info = (CURSORICONINFO *)(ani_info + 1);
-        info->ptHotSpot.x   = hotspot.x;
-        info->ptHotSpot.y   = hotspot.y;
-        info->nWidth        = bmpXor.bmWidth;
-        info->nHeight       = bmpXor.bmHeight;
-        info->nWidthBytes   = bmpXor.bmWidthBytes;
-        info->bPlanes       = bmpXor.bmPlanes;
-        info->bBitsPerPixel = bmpXor.bmBitsPixel;
+            ani_info = (CURSORANIINFO *)GlobalLock16( hObj );
+            ani_info->num_frames = 1;
+            ani_info->delay = 0;
+            info = (CURSORICONINFO *)(ani_info + 1);
+            info->ptHotSpot.x   = hotspot.x;
+            info->ptHotSpot.y   = hotspot.y;
+            info->nWidth        = bmpXor.bmWidth;
+            info->nHeight       = bmpXor.bmHeight;
+            info->nWidthBytes   = bmpXor.bmWidthBytes;
+            info->bPlanes       = bmpXor.bmPlanes;
+            info->bBitsPerPixel = bmpXor.bmBitsPixel;
 
-        /* Transfer the bitmap bits to the CURSORICONINFO structure */
+            /* Transfer the bitmap bits to the CURSORICONINFO structure */
+            GetBitmapBits( hAndBits, sizeAnd, (char *)(info + 1) );
+            GetBitmapBits( hXorBits, sizeXor, (char *)(info + 1) + sizeAnd );
+            GlobalUnlock16( hObj );
+        }
 
-        GetBitmapBits( hAndBits, sizeAnd, (char *)(info + 1) );
-        GetBitmapBits( hXorBits, sizeXor, (char *)(info + 1) + sizeAnd );
-        GlobalUnlock16( hObj );
+        DeleteObject( hAndBits );
+        DeleteObject( hXorBits );
     }
-
-    DeleteObject( hAndBits );
-    DeleteObject( hXorBits );
     return HICON_32((HICON16)hObj);
 }
 





More information about the wine-patches mailing list