Changeset 4612 for trunk/src


Ignore:
Timestamp:
Nov 18, 2000, 3:08:54 PM (25 years ago)
Author:
sandervl
Message:

CopyImage fix for icons

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/user32/winicon.cpp

    r4584 r4612  
    1 /* $Id: winicon.cpp,v 1.13 2000-11-10 10:14:50 sandervl Exp $ */
     1/* $Id: winicon.cpp,v 1.14 2000-11-18 14:08:54 sandervl Exp $ */
    22/*
    33 * Win32 Icon Code for OS/2
     
    3333static WORD ICON_HOTSPOT = 0x4242;
    3434
    35 static HGLOBAL CURSORICON_CreateFromResource( HINSTANCE hInstance, HGLOBAL hObj, LPBYTE bits,
    36                         UINT cbSize, BOOL bIcon, DWORD dwVersion,
    37                         INT width, INT height, UINT loadflags );
    38 static HGLOBAL CURSORICON_Copy( HINSTANCE hInstance, HGLOBAL handle );
     35static HGLOBAL CURSORICON_CreateFromResource( HINSTANCE hInstance, DWORD dwResGroupId, HGLOBAL hObj, LPBYTE bits,
     36                                              UINT cbSize, BOOL bIcon, DWORD dwVersion, INT width, INT height, UINT loadflags );
     37static HGLOBAL CURSORICON_Copy( HGLOBAL handle );
    3938static CURSORICONDIRENTRY *CURSORICON_FindBestIcon( CURSORICONDIR *dir, int width,
    4039                                                    int height, int colors );
     
    6261    info.bPlanes = bPlanes;
    6362    info.bBitsPerPixel = bBitsPixel;
    64 
     63    info.hInstance = hInstance;
     64    info.dwResGroupId = -1;
    6565    return CreateCursorIconIndirect(0, &info, lpANDbits, lpXORbits);
    6666}
     
    8181{
    8282    dprintf(("USER32:  CreateIconFromResourceEx %X %d %d %X %d %d %X,", bits, cbSize, bIcon, dwVersion, width, height, cFlag));
    83     return CURSORICON_CreateFromResource(0, 0, bits, cbSize, bIcon, dwVersion, width, height, cFlag );
     83    return CURSORICON_CreateFromResource(0, -1, 0, bits, cbSize, bIcon, dwVersion, width, height, cFlag );
    8484}
    8585/**********************************************************************
     
    124124        info->bPlanes       = bmpXor.bmPlanes;
    125125        info->bBitsPerPixel = bmpXor.bmBitsPixel;
    126 
     126        info->hInstance     = -1;
     127        info->dwResGroupId  = -1;
    127128        /* Transfer the bitmap bits to the CURSORICONINFO structure */
    128129        GetBitmapBits( iconinfo->hbmMask ,sizeAnd,(char*)(info + 1) );
     
    147148{
    148149    dprintf(("USER32:  CopyIcon %x", hIcon));
    149     return CURSORICON_Copy( 0, hIcon );
     150    return CURSORICON_Copy( hIcon );
    150151}
    151152/**********************************************************************
     
    285286            dirEntry = (CURSORICONDIRENTRY *)CURSORICON_FindBestIcon(dir, width, height, colors);
    286287        bits = ptr[dirEntry->wResId-1];
    287         h = CURSORICON_CreateFromResource( 0, 0, bits, dirEntry->dwBytesInRes,
     288        h = CURSORICON_CreateFromResource( 0, -1, 0, bits, dirEntry->dwBytesInRes,
    288289                                           !fCursor, 0x00030000, width, height, loadflags);
    289290        HeapFree( GetProcessHeap(), 0, dir );
     
    340341        if (!(handle = LoadResource( hInstance, hRsrc ))) return 0;
    341342        bits = (LPBYTE)LockResource( handle );
    342         h = CURSORICON_CreateFromResource( 0, 0, bits, dwBytesInRes,
     343        h = CURSORICON_CreateFromResource( hInstance, (DWORD)name, 0, bits, dwBytesInRes,
    343344                                           !fCursor, 0x00030000, width, height, loadflags);
    344345        FreeResource( handle );
     
    459460 *        with cbSize parameter as well.
    460461 */
    461 static HGLOBAL CURSORICON_CreateFromResource( HINSTANCE hInstance, HGLOBAL hObj, LPBYTE bits,
     462static HGLOBAL CURSORICON_CreateFromResource( HINSTANCE hInstance, DWORD dwResGroupId, HGLOBAL hObj, LPBYTE bits,
    462463                        UINT cbSize, BOOL bIcon, DWORD dwVersion,
    463464                        INT width, INT height, UINT loadflags )
     
    474475    hotspot.x = ICON_HOTSPOT;
    475476    hotspot.y = ICON_HOTSPOT;
     477
     478//testestest
     479    dprintf(("CURSORICON_CreateFromResource %x %x %x %x %d", hInstance, dwResGroupId, hObj, bits, cbSize));
    476480
    477481    if (dwVersion == 0x00020000)
     
    696700        info->bBitsPerPixel = bmpXor.bmBitsPixel;
    697701        info->hColorBmp     = hXorBits;
     702        info->hInstance     = hInstance;
     703        info->dwResGroupId  = dwResGroupId;
    698704
    699705        /* Transfer the bitmap bits to the CURSORICONINFO structure */
     
    774780 * Make a copy of a cursor or icon.
    775781 */
    776 static HGLOBAL CURSORICON_Copy( HINSTANCE hInstance, HGLOBAL handle )
     782static HGLOBAL CURSORICON_Copy(HGLOBAL handle)
    777783{
    778784    char *ptrOld, *ptrNew;
     
    813819 *
    814820 */
    815 
    816821HGLOBAL CURSORICON_ExtCopy(HGLOBAL Handle, UINT nType,
    817                INT iDesiredCX, INT iDesiredCY,
    818                UINT nFlags)
     822                                   INT iDesiredCX, INT iDesiredCY,
     823                                       UINT nFlags)
    819824{
    820825    HGLOBAL hNew=0;
     
    822827    if(Handle == 0)
    823828    {
    824         return 0;
    825     }
    826 
    827     hNew = CURSORICON_Copy(0, Handle);
     829            return 0;
     830    }
     831    /* Best Fit or Monochrome */
     832    if( (nFlags & LR_COPYFROMRESOURCE
     833        && (iDesiredCX > 0 || iDesiredCY > 0))
     834        || nFlags & LR_MONOCHROME)
     835    {
     836            int iTargetCY = iDesiredCY, iTargetCX = iDesiredCX;
     837            LPBYTE pBits;
     838            HANDLE hMem;
     839            HRSRC hRsrc;
     840            DWORD dwBytesInRes;
     841            WORD wResId;
     842            DWORD dwResGroupId;
     843            HINSTANCE hInstance;
     844            CURSORICONINFO *iconinfo;
     845            CURSORICONDIR *pDir;
     846            CURSORICONDIRENTRY *pDirEntry;
     847            BOOL bIsIcon = (nType == IMAGE_ICON);
     848
     849            iconinfo = (CURSORICONINFO *)GlobalLock( Handle );
     850            if(iconinfo == NULL) {
     851                dprintf(("ERROR: CURSORICON_ExtCopy invalid icon!"));
     852            }
     853            hInstance    = iconinfo->hInstance;
     854            dwResGroupId = iconinfo->dwResGroupId;
     855            GlobalUnlock( Handle );
     856            if(dwResGroupId == -1) {
     857                dprintf(("WARNING: no resource associated with icon/cursor -> copy without scaling!"));
     858                hNew = CURSORICON_Copy(Handle);
     859            }
     860
     861            /* Completing iDesiredCX CY for Monochrome Bitmaps if needed
     862            */
     863            if(((nFlags & LR_MONOCHROME) && !(nFlags & LR_COPYFROMRESOURCE))
     864                || (iDesiredCX == 0 && iDesiredCY == 0))
     865            {
     866                iDesiredCY = GetSystemMetrics(bIsIcon ? SM_CYICON : SM_CYCURSOR);
     867                iDesiredCX = GetSystemMetrics(bIsIcon ? SM_CXICON : SM_CXCURSOR);
     868            }
     869
     870            /* Retreive the CURSORICONDIRENTRY
     871            */
     872            hRsrc = FindResourceW(hInstance, (LPWSTR)dwResGroupId, bIsIcon ? RT_GROUP_ICONW : RT_GROUP_CURSORW);
     873            if(!hRsrc)  return 0;
     874
     875            if (!(hMem = LoadResource( hInstance, hRsrc)))
     876            {
     877                return 0;
     878            }
     879            if (!(pDir = (CURSORICONDIR*)LockResource( hMem )))
     880            {
     881                return 0;
     882            }
     883
     884            /* Find Best Fit
     885            */
     886            if(bIsIcon)
     887            {
     888                pDirEntry = (CURSORICONDIRENTRY *)CURSORICON_FindBestIcon(
     889                                pDir, iDesiredCX, iDesiredCY, 256);
     890            }
     891            else
     892            {
     893                pDirEntry = (CURSORICONDIRENTRY *)CURSORICON_FindBestCursor(
     894                                pDir, iDesiredCX, iDesiredCY, 1);
     895            }
     896
     897            wResId = pDirEntry->wResId;
     898            dwBytesInRes = pDirEntry->dwBytesInRes;
     899            FreeResource(hMem);
     900
     901            /* Get the Best Fit
     902            */
     903            if (!(hRsrc = FindResourceW(hInstance ,
     904                MAKEINTRESOURCEW(wResId), bIsIcon ? RT_ICONW : RT_CURSORW)))
     905            {
     906                return 0;
     907            }
     908            if (!(hMem = LoadResource( hInstance, hRsrc )))
     909            {
     910                return 0;
     911            }
     912
     913            pBits = (LPBYTE)LockResource( hMem );
     914
     915                if(nFlags & LR_DEFAULTSIZE)
     916                {
     917                    iTargetCY = GetSystemMetrics(SM_CYICON);
     918                iTargetCX = GetSystemMetrics(SM_CXICON);
     919                }
     920
     921            /* Create a New Icon with the proper dimension
     922            */
     923            hNew = CURSORICON_CreateFromResource( hInstance, dwResGroupId, 0, pBits, dwBytesInRes,
     924                                                  bIsIcon, 0x00030000, iTargetCX, iTargetCY, nFlags);
     925            FreeResource(hMem);
     926    }
     927    else
     928    {
     929            hNew = CURSORICON_Copy(Handle);
     930    }
    828931    return hNew;
    829932}
     
    879982        }
    880983    }
    881 
     984////testestest
     985    dprintf(("CURSORICON_FindBestIcon (%d,%d) %d -> %d", width, height, colors, (bestEntry) ? bestEntry->wResId : 0));
    882986    return bestEntry;
    883987}
Note: See TracChangeset for help on using the changeset viewer.