[9638] | 1 | /* $Id: winicon.cpp,v 1.40 2003-01-07 10:26:01 sandervl Exp $ */
|
---|
[2469] | 2 | /*
|
---|
| 3 | * Win32 Icon Code for OS/2
|
---|
| 4 | *
|
---|
| 5 | *
|
---|
[4573] | 6 | * Copyright 1998 Sander van Leeuwen (sandervl@xs4all.nl) (OS/2 Port)
|
---|
[2469] | 7 | *
|
---|
[4573] | 8 | * Based on Wine code (objects\bitmap.c, loader\resource.c, objects\cursoricon.c):
|
---|
[2469] | 9 | *
|
---|
| 10 | * Copyright 1993 Alexandre Julliard
|
---|
| 11 | * 1993 Robert J. Amstadt
|
---|
| 12 | * 1996 Martin Von Loewis
|
---|
| 13 | * 1997 Alex Korobka
|
---|
| 14 | * 1998 Turchanov Sergey
|
---|
| 15 | * 1998 Huw D M Davies
|
---|
[5385] | 16 | * Theory:
|
---|
[2469] | 17 | *
|
---|
[5385] | 18 | * http://www.microsoft.com/win32dev/ui/icons.htm
|
---|
| 19 | *
|
---|
| 20 | * Cursors and icons are stored in a global heap block, with the
|
---|
| 21 | * following layout:
|
---|
| 22 | *
|
---|
| 23 | * CURSORICONINFO info;
|
---|
| 24 | * BYTE[] ANDbits;
|
---|
| 25 | * BYTE[] XORbits;
|
---|
| 26 | *
|
---|
| 27 | * The bits structures are in the format of a device-dependent bitmap.
|
---|
| 28 | *
|
---|
| 29 | * This layout is very sub-optimal, as the bitmap bits are stored in
|
---|
| 30 | * the X client instead of in the server like other bitmaps; however,
|
---|
| 31 | * some programs (notably Paint Brush) expect to be able to manipulate
|
---|
| 32 | * the bits directly :-(
|
---|
| 33 | *
|
---|
| 34 | * FIXME: what are we going to do with animation and color (bpp > 1) cursors ?!
|
---|
| 35 | *
|
---|
| 36 | **************************************************************************************************
|
---|
| 37 | *
|
---|
| 38 | * TODO: Scaling of system cursors (store them as resources in user32 instead of using PM pointers)
|
---|
| 39 | * TODO: We use the hColorBmp member of the CURSORICONINFO structure to store the PM cursor handle
|
---|
| 40 | * Might mess up PaintBrush (see above)
|
---|
| 41 | *
|
---|
[2469] | 42 | * Project Odin Software License can be found in LICENSE.TXT
|
---|
| 43 | *
|
---|
| 44 | */
|
---|
| 45 | #include <os2win.h>
|
---|
[4573] | 46 | #include <stdio.h>
|
---|
| 47 | #include <string.h>
|
---|
[2469] | 48 | #include <winicon.h>
|
---|
[21916] | 49 | #include <win/cursoricon.h>
|
---|
[6183] | 50 | #include <objhandle.h>
|
---|
[4573] | 51 | #include "dib.h"
|
---|
| 52 | #include <heapstring.h>
|
---|
[21916] | 53 | #include <win/virtual.h>
|
---|
[4573] | 54 | #include "initterm.h"
|
---|
[5385] | 55 | #include "oslibres.h"
|
---|
| 56 | #include "oslibwin.h"
|
---|
[5482] | 57 | #include "dc.h"
|
---|
[2469] | 58 |
|
---|
[4573] | 59 | #define DBG_LOCALLOG DBG_winicon
|
---|
[2803] | 60 | #include "dbglocal.h"
|
---|
| 61 |
|
---|
[4573] | 62 |
|
---|
[5385] | 63 | /**********************************************************************
|
---|
| 64 | * ICONCACHE for cursors/icons loaded with LR_SHARED.
|
---|
| 65 | *
|
---|
| 66 | * FIXME: This should not be allocated on the system heap, but on a
|
---|
| 67 | * subsystem-global heap (i.e. one for all Win16 processes,
|
---|
| 68 | * and one for each Win32 process).
|
---|
| 69 | */
|
---|
| 70 | typedef struct tagICONCACHE
|
---|
| 71 | {
|
---|
| 72 | struct tagICONCACHE *next;
|
---|
| 73 |
|
---|
| 74 | HMODULE hModule;
|
---|
| 75 | HRSRC hRsrc;
|
---|
| 76 | HRSRC hGroupRsrc;
|
---|
| 77 | HANDLE handle;
|
---|
| 78 | INT count;
|
---|
| 79 | } ICONCACHE;
|
---|
| 80 |
|
---|
| 81 | static ICONCACHE *IconAnchor = NULL;
|
---|
[9409] | 82 | static CRITICAL_SECTION IconCrst = CRITICAL_SECTION_INIT("User32WinIcon");
|
---|
[5385] | 83 | static WORD ICON_HOTSPOT = 0x4242;
|
---|
| 84 | static HCURSOR hActiveCursor = 0;
|
---|
[5728] | 85 | static HCURSOR hActiveCursorPM = 0;
|
---|
[5385] | 86 |
|
---|
| 87 |
|
---|
[4612] | 88 | static HGLOBAL CURSORICON_CreateFromResource( HINSTANCE hInstance, DWORD dwResGroupId, HGLOBAL hObj, LPBYTE bits,
|
---|
| 89 | UINT cbSize, BOOL bIcon, DWORD dwVersion, INT width, INT height, UINT loadflags );
|
---|
| 90 | static HGLOBAL CURSORICON_Copy( HGLOBAL handle );
|
---|
[4573] | 91 | static CURSORICONDIRENTRY *CURSORICON_FindBestIcon( CURSORICONDIR *dir, int width,
|
---|
| 92 | int height, int colors );
|
---|
| 93 | static CURSORICONDIRENTRY *CURSORICON_FindBestCursor( CURSORICONDIR *dir,
|
---|
| 94 | int width, int height, int color);
|
---|
| 95 | BOOL CURSORICON_SimulateLoadingFromResourceW( LPWSTR filename, BOOL fCursor,
|
---|
| 96 | CURSORICONDIR **res, LPBYTE **ptr);
|
---|
| 97 |
|
---|
[5385] | 98 | static INT CURSORICON_DelSharedIcon( HANDLE handle );
|
---|
| 99 | static void CURSORICON_AddSharedIcon( HMODULE hModule, HRSRC hRsrc, HRSRC hGroupRsrc, HANDLE handle );
|
---|
| 100 | static HANDLE CURSORICON_FindSharedIcon( HMODULE hModule, HRSRC hRsrc );
|
---|
| 101 | static ICONCACHE* CURSORICON_FindCache(HANDLE handle);
|
---|
| 102 |
|
---|
[6595] | 103 | static HGLOBAL CreateCursorIconIndirect( HINSTANCE hInstance,
|
---|
| 104 | CURSORICONINFO *info,
|
---|
| 105 | LPCVOID lpANDbits,
|
---|
| 106 | LPCVOID lpXORbits, BOOL fIcon);
|
---|
| 107 |
|
---|
[4573] | 108 | /***********************************************************************
|
---|
| 109 | * CreateIcon (USER32.75)
|
---|
| 110 | */
|
---|
| 111 | HICON WIN32API CreateIcon(HINSTANCE hInstance, INT nWidth,
|
---|
| 112 | INT nHeight, BYTE bPlanes, BYTE bBitsPixel,
|
---|
| 113 | LPCVOID lpANDbits, LPCVOID lpXORbits )
|
---|
[2469] | 114 | {
|
---|
[4573] | 115 | CURSORICONINFO info;
|
---|
| 116 |
|
---|
| 117 | dprintf(("USER32: CreateIcon (%d,%d), %d, %x, %x", nWidth, nHeight, bPlanes * bBitsPixel, lpXORbits, lpANDbits));
|
---|
| 118 |
|
---|
| 119 | info.ptHotSpot.x = ICON_HOTSPOT;
|
---|
| 120 | info.ptHotSpot.y = ICON_HOTSPOT;
|
---|
| 121 | info.nWidth = nWidth;
|
---|
| 122 | info.nHeight = nHeight;
|
---|
| 123 | info.nWidthBytes = 0;
|
---|
| 124 | info.bPlanes = bPlanes;
|
---|
| 125 | info.bBitsPerPixel = bBitsPixel;
|
---|
[4612] | 126 | info.hInstance = hInstance;
|
---|
| 127 | info.dwResGroupId = -1;
|
---|
[5385] | 128 | info.hColorBmp = 0;
|
---|
[6595] | 129 | return CreateCursorIconIndirect(0, &info, lpANDbits, lpXORbits, TRUE);
|
---|
[2469] | 130 | }
|
---|
[4573] | 131 | /**********************************************************************
|
---|
| 132 | * CreateIconFromResource (USER32.76)
|
---|
| 133 | */
|
---|
| 134 | HICON WIN32API CreateIconFromResource(LPBYTE bits, UINT cbSize,
|
---|
| 135 | BOOL bIcon, DWORD dwVersion)
|
---|
| 136 | {
|
---|
| 137 | return CreateIconFromResourceEx( bits, cbSize, bIcon, dwVersion, 0,0,0);
|
---|
| 138 | }
|
---|
[2469] | 139 | //******************************************************************************
|
---|
| 140 | //******************************************************************************
|
---|
[4573] | 141 | HICON WIN32API CreateIconFromResourceEx(LPBYTE bits, UINT cbSize,
|
---|
| 142 | BOOL bIcon, DWORD dwVersion,
|
---|
| 143 | INT width, INT height,
|
---|
| 144 | UINT cFlag )
|
---|
[2469] | 145 | {
|
---|
[4573] | 146 | dprintf(("USER32: CreateIconFromResourceEx %X %d %d %X %d %d %X,", bits, cbSize, bIcon, dwVersion, width, height, cFlag));
|
---|
[4612] | 147 | return CURSORICON_CreateFromResource(0, -1, 0, bits, cbSize, bIcon, dwVersion, width, height, cFlag );
|
---|
[4573] | 148 | }
|
---|
| 149 | /**********************************************************************
|
---|
| 150 | * CreateIconIndirect (USER32.78)
|
---|
| 151 | */
|
---|
| 152 | HICON WINAPI CreateIconIndirect(ICONINFO *iconinfo)
|
---|
| 153 | {
|
---|
| 154 | BITMAP bmpXor,bmpAnd;
|
---|
| 155 | HICON hObj;
|
---|
[6595] | 156 | int sizeXor,sizeAnd,colortablesize;
|
---|
[2469] | 157 |
|
---|
[7045] | 158 | dprintf(("USER32: CreateIconIndirect %x %x %x %s", iconinfo, iconinfo->hbmMask, iconinfo->hbmColor, (iconinfo->fIcon) ? "icon" : "cursor"));
|
---|
[2469] | 159 |
|
---|
[4573] | 160 | GetObjectA( iconinfo->hbmColor, sizeof(bmpXor), &bmpXor );
|
---|
| 161 | GetObjectA( iconinfo->hbmMask, sizeof(bmpAnd), &bmpAnd );
|
---|
| 162 |
|
---|
[6595] | 163 | colortablesize = 0;
|
---|
| 164 |
|
---|
[21964] | 165 | // GetDIBits expectes DWORD-aligned scan lines
|
---|
[21951] | 166 | bmpXor.bmWidthBytes = (bmpXor.bmWidthBytes + 3) / 4 * 4;
|
---|
| 167 |
|
---|
[6595] | 168 | if(bmpXor.bmBitsPixel <= 8) {
|
---|
| 169 | colortablesize = sizeof(RGBQUAD)*(1<<bmpXor.bmBitsPixel);
|
---|
| 170 | sizeXor = bmpXor.bmHeight * bmpXor.bmWidthBytes + colortablesize;
|
---|
| 171 | }
|
---|
| 172 | else sizeXor = bmpXor.bmHeight * bmpXor.bmWidthBytes;
|
---|
| 173 |
|
---|
[4573] | 174 | sizeAnd = bmpAnd.bmHeight * bmpAnd.bmWidthBytes;
|
---|
| 175 |
|
---|
| 176 | hObj = GlobalAlloc( GMEM_MOVEABLE, sizeof(CURSORICONINFO) + sizeXor + sizeAnd );
|
---|
| 177 | if (hObj)
|
---|
| 178 | {
|
---|
| 179 | CURSORICONINFO *info;
|
---|
| 180 |
|
---|
| 181 | info = (CURSORICONINFO *)GlobalLock( hObj );
|
---|
| 182 |
|
---|
| 183 | /* If we are creating an icon, the hotspot is unused */
|
---|
| 184 | if (iconinfo->fIcon)
|
---|
| 185 | {
|
---|
| 186 | info->ptHotSpot.x = ICON_HOTSPOT;
|
---|
| 187 | info->ptHotSpot.y = ICON_HOTSPOT;
|
---|
| 188 | }
|
---|
| 189 | else
|
---|
| 190 | {
|
---|
| 191 | info->ptHotSpot.x = iconinfo->xHotspot;
|
---|
| 192 | info->ptHotSpot.y = iconinfo->yHotspot;
|
---|
| 193 | }
|
---|
| 194 |
|
---|
| 195 | info->nWidth = bmpXor.bmWidth;
|
---|
| 196 | info->nHeight = bmpXor.bmHeight;
|
---|
| 197 | info->nWidthBytes = bmpXor.bmWidthBytes;
|
---|
| 198 | info->bPlanes = bmpXor.bmPlanes;
|
---|
| 199 | info->bBitsPerPixel = bmpXor.bmBitsPixel;
|
---|
[4612] | 200 | info->hInstance = -1;
|
---|
| 201 | info->dwResGroupId = -1;
|
---|
[5385] | 202 | info->hColorBmp = 0;
|
---|
| 203 |
|
---|
[4573] | 204 | /* Transfer the bitmap bits to the CURSORICONINFO structure */
|
---|
[21916] | 205 | if(bmpAnd.bmBitsPixel > 1)
|
---|
[9638] | 206 | {//Our code expects b&w masks, so convert it first
|
---|
| 207 | //We could also use GetDIBits to do the conversion for us, but it returns
|
---|
| 208 | //scanlines aligned differently from what we want.
|
---|
| 209 | HBITMAP oldbmpSrc, oldbmpDest, hbmMask;
|
---|
| 210 | HDC hdcSrc, hdcDest;
|
---|
| 211 |
|
---|
| 212 | hdcSrc = CreateCompatibleDC(0);
|
---|
| 213 | oldbmpSrc = SelectObject(hdcSrc, iconinfo->hbmMask);
|
---|
| 214 |
|
---|
| 215 | hdcDest = CreateCompatibleDC(0);
|
---|
| 216 | hbmMask = CreateBitmap(bmpAnd.bmWidth, bmpAnd.bmHeight, 1,
|
---|
| 217 | 1, NULL);
|
---|
| 218 | oldbmpDest = SelectObject(hdcDest, hbmMask);
|
---|
| 219 |
|
---|
| 220 | //blit to the destination HDC & convert to 1bpp
|
---|
[21916] | 221 | BitBlt(hdcDest, 0, 0, bmpAnd.bmWidth, bmpAnd.bmHeight,
|
---|
[9638] | 222 | hdcSrc, 0, 0, SRCCOPY);
|
---|
| 223 |
|
---|
| 224 | //recalculate the mask bitmap size
|
---|
| 225 | GetObjectA( hbmMask, sizeof(bmpAnd), &bmpAnd );
|
---|
[21964] | 226 | sizeAnd = bmpAnd.bmHeight * bmpAnd.bmWidthBytes;
|
---|
[9638] | 227 |
|
---|
| 228 | //query the 1bpp bitmap data
|
---|
| 229 | GetBitmapBits( hbmMask ,sizeAnd,(char*)(info + 1) );
|
---|
| 230 |
|
---|
| 231 | SelectObject(hdcSrc, oldbmpSrc);
|
---|
| 232 | SelectObject(hdcDest, oldbmpDest);
|
---|
| 233 | DeleteObject(hbmMask);
|
---|
| 234 | DeleteDC(hdcSrc);
|
---|
| 235 | DeleteDC(hdcDest);
|
---|
| 236 | }
|
---|
| 237 | else {
|
---|
| 238 | GetBitmapBits( iconinfo->hbmMask ,sizeAnd,(char*)(info + 1) );
|
---|
| 239 | }
|
---|
[6595] | 240 | if(bmpXor.bmBitsPixel > 1)
|
---|
| 241 | {
|
---|
| 242 | BITMAPINFO* pInfo = (BITMAPINFO *)malloc(sizeof(BITMAPINFO)+colortablesize+3*sizeof(DWORD)); //+ extra space for > 8bpp images
|
---|
| 243 | HBITMAP oldbmp;
|
---|
| 244 | HDC hdc;
|
---|
| 245 |
|
---|
| 246 | hdc = CreateCompatibleDC(0);
|
---|
| 247 |
|
---|
| 248 | memset(pInfo, 0, sizeof(BITMAPINFO)+colortablesize+3*sizeof(DWORD));
|
---|
| 249 | pInfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
|
---|
| 250 | pInfo->bmiHeader.biPlanes = info->bPlanes;
|
---|
| 251 | pInfo->bmiHeader.biBitCount = info->bBitsPerPixel;
|
---|
| 252 |
|
---|
| 253 | GetDIBits(hdc, iconinfo->hbmColor, 0, bmpXor.bmHeight, (char *)(info + 1) + sizeAnd + colortablesize, pInfo, DIB_RGB_COLORS);
|
---|
| 254 | if(colortablesize) {
|
---|
| 255 | memcpy((char *)(info + 1) + sizeAnd, (char *)&pInfo->bmiHeader + pInfo->bmiHeader.biSize, colortablesize);
|
---|
| 256 | }
|
---|
| 257 |
|
---|
| 258 | DeleteDC(hdc);
|
---|
| 259 | free(pInfo);
|
---|
| 260 | }
|
---|
| 261 | else {
|
---|
| 262 | GetBitmapBits( iconinfo->hbmColor,sizeXor,(char*)(info + 1) +sizeAnd);
|
---|
| 263 | }
|
---|
| 264 |
|
---|
| 265 | #ifdef __WIN32OS2__
|
---|
[7237] | 266 | info->hColorBmp = OSLibWinCreatePointer(info, (char*)(info + 1), (LPBITMAP_W)&bmpAnd, (char*)(info + 1) + sizeAnd, (LPBITMAP_W)&bmpXor, iconinfo->fIcon == FALSE);
|
---|
[6595] | 267 | #endif
|
---|
[4573] | 268 | GlobalUnlock(hObj);
|
---|
[6183] | 269 |
|
---|
| 270 | #ifdef __WIN32OS2__
|
---|
| 271 | HICON hIcon;
|
---|
[8872] | 272 | if(ObjAllocateHandle(&hIcon, (DWORD)hObj, HNDL_CURSORICON) == FALSE) {
|
---|
[6183] | 273 | GlobalFree(hObj);
|
---|
| 274 | dprintf(("ERROR: CreateIconIndirect ObjAllocateHandle failed!!"));
|
---|
| 275 | return 0;
|
---|
| 276 | }
|
---|
| 277 | #endif
|
---|
[6595] | 278 | dprintf(("USER32: CreateIconIndirect %x returned %x", iconinfo, hIcon));
|
---|
[6183] | 279 | return hIcon;
|
---|
[4573] | 280 | }
|
---|
| 281 | else {
|
---|
| 282 | dprintf(("ERROR: CreateIconIndirect GlobalAlloc failed!!"));
|
---|
[6183] | 283 | return 0;
|
---|
[4573] | 284 | }
|
---|
[2469] | 285 | }
|
---|
| 286 | //******************************************************************************
|
---|
| 287 | //******************************************************************************
|
---|
[4573] | 288 | BOOL WIN32API DestroyIcon( HICON hIcon)
|
---|
[2469] | 289 | {
|
---|
[4573] | 290 | dprintf(("USER32: DestroyIcon %x", hIcon));
|
---|
| 291 | return CURSORICON_Destroy( hIcon, 0 );
|
---|
[2469] | 292 | }
|
---|
| 293 | //******************************************************************************
|
---|
| 294 | //******************************************************************************
|
---|
[4573] | 295 | HICON WIN32API CopyIcon( HICON hIcon)
|
---|
[2469] | 296 | {
|
---|
[4573] | 297 | dprintf(("USER32: CopyIcon %x", hIcon));
|
---|
[4612] | 298 | return CURSORICON_Copy( hIcon );
|
---|
[4573] | 299 | }
|
---|
[6168] | 300 | //******************************************************************************
|
---|
| 301 | //******************************************************************************
|
---|
| 302 | HICON WIN32API GetOS2Icon(HICON hIcon)
|
---|
| 303 | {
|
---|
| 304 | CURSORICONINFO *ciconinfo;
|
---|
| 305 |
|
---|
[8872] | 306 | hIcon = ObjQueryHandleData(hIcon, HNDL_CURSORICON);
|
---|
[6183] | 307 | if(hIcon == -1) {
|
---|
| 308 | dprintf(("ERROR: Invalid cursor/icon!"));
|
---|
| 309 | return 0;
|
---|
| 310 | }
|
---|
[6168] | 311 | ciconinfo = (CURSORICONINFO *)GlobalLock((HGLOBAL)hIcon);
|
---|
| 312 | if (!ciconinfo)
|
---|
| 313 | return 0;
|
---|
| 314 | HICON hOS2Icon = ciconinfo->hColorBmp;
|
---|
| 315 | GlobalUnlock(hIcon);
|
---|
| 316 | return hOS2Icon;
|
---|
| 317 | }
|
---|
[4573] | 318 | /**********************************************************************
|
---|
| 319 | * GetIconInfo (USER32.242)
|
---|
| 320 | */
|
---|
| 321 | BOOL WINAPI GetIconInfo(HICON hIcon, ICONINFO *iconinfo)
|
---|
| 322 | {
|
---|
| 323 | CURSORICONINFO *ciconinfo;
|
---|
[2469] | 324 |
|
---|
[4573] | 325 | dprintf(("GetIconInfo %x %x", hIcon, iconinfo));
|
---|
| 326 |
|
---|
[6183] | 327 | #ifdef __WIN32OS2__
|
---|
[8872] | 328 | hIcon = ObjQueryHandleData(hIcon, HNDL_CURSORICON);
|
---|
[6183] | 329 | if(hIcon == -1) {
|
---|
| 330 | dprintf(("ERROR: Invalid cursor/icon!"));
|
---|
| 331 | return 0;
|
---|
| 332 | }
|
---|
| 333 | #endif
|
---|
[4573] | 334 | ciconinfo = (CURSORICONINFO *)GlobalLock((HGLOBAL)hIcon);
|
---|
| 335 | if (!ciconinfo)
|
---|
| 336 | return FALSE;
|
---|
| 337 |
|
---|
| 338 | if((ciconinfo->ptHotSpot.x == ICON_HOTSPOT) &&
|
---|
| 339 | (ciconinfo->ptHotSpot.y == ICON_HOTSPOT))
|
---|
[2469] | 340 | {
|
---|
[4573] | 341 | iconinfo->fIcon = TRUE;
|
---|
| 342 | iconinfo->xHotspot = ciconinfo->nWidth / 2;
|
---|
| 343 | iconinfo->yHotspot = ciconinfo->nHeight / 2;
|
---|
| 344 | }
|
---|
| 345 | else
|
---|
| 346 | {
|
---|
| 347 | iconinfo->fIcon = FALSE;
|
---|
| 348 | iconinfo->xHotspot = ciconinfo->ptHotSpot.x;
|
---|
| 349 | iconinfo->yHotspot = ciconinfo->ptHotSpot.y;
|
---|
| 350 | }
|
---|
[2469] | 351 |
|
---|
[4573] | 352 | //Create new bitmaps for the color and mask data; application is responsible
|
---|
| 353 | //for deleteing them (according to docs & verified in NT4)
|
---|
| 354 | if(ciconinfo->bBitsPerPixel > 1)
|
---|
| 355 | {
|
---|
| 356 | BITMAPINFO* pInfo;
|
---|
| 357 | int colorsize = 0;
|
---|
| 358 | int coloroff;
|
---|
| 359 |
|
---|
| 360 | HDC hdc = CreateCompatibleDC(0);
|
---|
| 361 |
|
---|
| 362 | if(ciconinfo->bBitsPerPixel <= 8) {
|
---|
| 363 | colorsize = (1<<ciconinfo->bBitsPerPixel)*sizeof(RGBQUAD);
|
---|
[2469] | 364 | }
|
---|
[4573] | 365 | else {
|
---|
| 366 | colorsize = 3*sizeof(DWORD); //color masks
|
---|
| 367 | }
|
---|
| 368 | pInfo = (BITMAPINFO *)malloc(ciconinfo->nHeight * ciconinfo->nWidthBytes + colorsize + sizeof(BITMAPINFO));
|
---|
| 369 | memset(pInfo, 0, sizeof(BITMAPINFO)+colorsize);
|
---|
[2469] | 370 |
|
---|
[4573] | 371 | pInfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
|
---|
| 372 | pInfo->bmiHeader.biWidth = ciconinfo->nWidth;
|
---|
| 373 | pInfo->bmiHeader.biHeight = ciconinfo->nHeight,
|
---|
| 374 | pInfo->bmiHeader.biPlanes = ciconinfo->bPlanes;
|
---|
| 375 | pInfo->bmiHeader.biBitCount = ciconinfo->bBitsPerPixel;
|
---|
| 376 | pInfo->bmiHeader.biSizeImage= ciconinfo->nHeight * ciconinfo->nWidthBytes;
|
---|
[2469] | 377 |
|
---|
[4573] | 378 | //offset in cursorinfo memory
|
---|
| 379 | coloroff = ciconinfo->nHeight * BITMAP_GetWidthBytes (ciconinfo->nWidth, 1);
|
---|
[2469] | 380 |
|
---|
[4573] | 381 | char *src = (char *)(ciconinfo + 1) + coloroff;
|
---|
| 382 | if(ciconinfo->bBitsPerPixel <= 8) {
|
---|
| 383 | src += colorsize; //no color masks in cursorinfo data for bpp > 8
|
---|
| 384 | }
|
---|
| 385 | if(ciconinfo->bBitsPerPixel <= 8) {
|
---|
| 386 | memcpy(&pInfo->bmiColors[0], (char *)(ciconinfo + 1) + coloroff, colorsize);
|
---|
| 387 | }
|
---|
[5385] | 388 | //else TODO: color masks (currently unused in CreateDIBitmap)
|
---|
[2469] | 389 |
|
---|
[4573] | 390 | iconinfo->hbmColor = CreateDIBitmap(hdc, &pInfo->bmiHeader, CBM_INIT, src, pInfo, DIB_RGB_COLORS);
|
---|
| 391 |
|
---|
| 392 | free(pInfo);
|
---|
| 393 | DeleteDC(hdc);
|
---|
[2469] | 394 | }
|
---|
[4573] | 395 | else {
|
---|
| 396 | iconinfo->hbmColor = CreateBitmap ( ciconinfo->nWidth, ciconinfo->nHeight,
|
---|
| 397 | ciconinfo->bPlanes, ciconinfo->bBitsPerPixel,
|
---|
| 398 | (char *)(ciconinfo + 1)
|
---|
| 399 | + ciconinfo->nHeight *
|
---|
| 400 | BITMAP_GetWidthBytes (ciconinfo->nWidth, 1) );
|
---|
[2469] | 401 | }
|
---|
[4573] | 402 |
|
---|
| 403 | iconinfo->hbmMask = CreateBitmap ( ciconinfo->nWidth, ciconinfo->nHeight,
|
---|
| 404 | 1, 1, (char *)(ciconinfo + 1));
|
---|
| 405 |
|
---|
| 406 | GlobalUnlock(hIcon);
|
---|
| 407 |
|
---|
| 408 | return TRUE;
|
---|
[2469] | 409 | }
|
---|
[5385] | 410 | //******************************************************************************
|
---|
| 411 | //******************************************************************************
|
---|
| 412 | HCURSOR WIN32API CreateCursor(HINSTANCE hInst, int xHotSpot, int yHotSpot, int nWidth, int nHeight,
|
---|
| 413 | const VOID *lpANDbits, const VOID *lpXORbits)
|
---|
| 414 | {
|
---|
| 415 | CURSORICONINFO info;
|
---|
| 416 |
|
---|
| 417 | dprintf(("CreateCursor %dx%d spot=%d,%d xor=%p and=%p\n",
|
---|
| 418 | nWidth, nHeight, xHotSpot, yHotSpot, lpXORbits, lpANDbits));
|
---|
| 419 |
|
---|
| 420 | info.ptHotSpot.x = xHotSpot;
|
---|
| 421 | info.ptHotSpot.y = yHotSpot;
|
---|
| 422 | info.nWidth = nWidth;
|
---|
| 423 | info.nHeight = nHeight;
|
---|
| 424 | info.nWidthBytes = 0;
|
---|
| 425 | info.bPlanes = 1;
|
---|
| 426 | info.bBitsPerPixel = 1;
|
---|
| 427 | info.hInstance = hInst;
|
---|
| 428 | info.dwResGroupId = -1;
|
---|
| 429 | info.hColorBmp = 0;
|
---|
| 430 |
|
---|
[6595] | 431 | return CreateCursorIconIndirect( 0, &info, lpANDbits, lpXORbits, FALSE);
|
---|
[5385] | 432 | }
|
---|
| 433 | //******************************************************************************
|
---|
| 434 | //******************************************************************************
|
---|
| 435 | BOOL WIN32API DestroyCursor( HCURSOR hCursor)
|
---|
| 436 | {
|
---|
| 437 | dprintf(("USER32: DestroyCursor %x", hCursor));
|
---|
| 438 | return CURSORICON_Destroy( hCursor, CID_WIN32 );
|
---|
| 439 | }
|
---|
| 440 | //******************************************************************************
|
---|
| 441 | //******************************************************************************
|
---|
| 442 | HCURSOR WIN32API GetCursor(void)
|
---|
| 443 | {
|
---|
| 444 | dprintf2(("USER32: GetCursor"));
|
---|
[5728] | 445 | if(hActiveCursorPM && hActiveCursorPM != OSLibWinQueryPointer()) {
|
---|
| 446 | dprintf(("Another app changed mouse cursor"));
|
---|
[21916] | 447 | hActiveCursorPM = hActiveCursor = 0;
|
---|
[5728] | 448 | }
|
---|
[5385] | 449 | return hActiveCursor;
|
---|
| 450 | }
|
---|
| 451 | //******************************************************************************
|
---|
| 452 | //******************************************************************************
|
---|
| 453 | HCURSOR WIN32API SetCursor( HCURSOR hCursor)
|
---|
| 454 | {
|
---|
| 455 | HCURSOR hOldCursor;
|
---|
| 456 |
|
---|
| 457 | dprintf(("USER32: SetCursor %x (prev %x)", hCursor, hActiveCursor));
|
---|
[5728] | 458 | GetCursor();
|
---|
[5385] | 459 | if (hCursor == hActiveCursor) return hActiveCursor; /* No change */
|
---|
| 460 |
|
---|
| 461 | hOldCursor = hActiveCursor;
|
---|
| 462 | hActiveCursor = hCursor;
|
---|
| 463 |
|
---|
[6183] | 464 | #ifdef __WIN32OS2__
|
---|
[8872] | 465 | hCursor = ObjQueryHandleData(hCursor, HNDL_CURSORICON);
|
---|
[6183] | 466 | if(hCursor == -1) {
|
---|
| 467 | dprintf(("ERROR: Invalid cursor/icon!"));
|
---|
| 468 | return 0;
|
---|
| 469 | }
|
---|
| 470 | #endif
|
---|
| 471 |
|
---|
[5385] | 472 | CURSORICONINFO *iconinfo = (CURSORICONINFO *)GlobalLock((HGLOBAL)hCursor);
|
---|
| 473 | if (!iconinfo) {
|
---|
| 474 | dprintf(("ERROR: Invalid cursor!"));
|
---|
| 475 | return 0;
|
---|
| 476 | }
|
---|
| 477 | if(!iconinfo->hColorBmp) {
|
---|
| 478 | dprintf(("SetCursor: invalid os/2 pointer handle!!"));
|
---|
| 479 | }
|
---|
| 480 |
|
---|
[7063] | 481 | dprintf2(("OSLibWinSetPointer %x", iconinfo->hColorBmp));
|
---|
[5385] | 482 | if(OSLibWinSetPointer(iconinfo->hColorBmp) == FALSE) {
|
---|
| 483 | dprintf(("OSLibWinSetPointer %x returned FALSE!!", iconinfo->hColorBmp));
|
---|
| 484 | }
|
---|
[5728] | 485 | hActiveCursorPM = iconinfo->hColorBmp;
|
---|
[5385] | 486 | GlobalUnlock(hCursor);
|
---|
| 487 |
|
---|
| 488 | return hOldCursor;
|
---|
| 489 | }
|
---|
| 490 | /*****************************************************************************
|
---|
| 491 | * Name : BOOL WIN32API SetSystemCursor
|
---|
| 492 | * Purpose : The SetSystemCursor function replaces the contents of the system
|
---|
| 493 | * cursor specified by dwCursorId with the contents of the cursor
|
---|
| 494 | * specified by hCursor, and then destroys hCursor. This function
|
---|
| 495 | * lets an application customize the system cursors.
|
---|
| 496 | * Parameters: HCURSOR hCursor set specified system cursor to this cursor's
|
---|
| 497 | * contents, then destroy this
|
---|
| 498 | * DWORD dwCursorID system cursor specified by its identifier
|
---|
| 499 | * Variables :
|
---|
| 500 | * Result : If the function succeeds, the return value is TRUE.
|
---|
| 501 | * If the function fails, the return value is FALSE. To get extended
|
---|
| 502 | * error information, call GetLastError.
|
---|
| 503 | * Remark :
|
---|
| 504 | * Status : UNTESTED STUB
|
---|
| 505 | *
|
---|
| 506 | * Author : Patrick Haller [Thu, 1998/02/26 11:55]
|
---|
| 507 | *****************************************************************************/
|
---|
| 508 | BOOL WIN32API SetSystemCursor(HCURSOR hCursor, DWORD dwCursorId)
|
---|
| 509 | {
|
---|
| 510 | dprintf(("USER32:SetSystemCursor (%08xh,%08x) not supported.\n",
|
---|
| 511 | hCursor,
|
---|
| 512 | dwCursorId));
|
---|
| 513 |
|
---|
| 514 | return DestroyCursor(hCursor);
|
---|
| 515 | }
|
---|
| 516 | //******************************************************************************
|
---|
| 517 | //******************************************************************************
|
---|
[5482] | 518 | INT OPEN32API __ShowCursor(BOOL bShow);
|
---|
| 519 |
|
---|
| 520 | inline INT _ShowCursor (BOOL bShow)
|
---|
[5385] | 521 | {
|
---|
[5482] | 522 | INT yyrc;
|
---|
| 523 | USHORT sel = RestoreOS2FS();
|
---|
| 524 |
|
---|
| 525 | yyrc = __ShowCursor(bShow);
|
---|
| 526 | SetFS(sel);
|
---|
| 527 |
|
---|
| 528 | return yyrc;
|
---|
[5385] | 529 | }
|
---|
| 530 | //******************************************************************************
|
---|
[5482] | 531 | static int cursorshowcnt = 0;
|
---|
[5385] | 532 | //******************************************************************************
|
---|
[5482] | 533 | void RestoreCursor()
|
---|
| 534 | {
|
---|
| 535 | dprintf2(("USER32: RestoreCursor %d", cursorshowcnt));
|
---|
| 536 | while(cursorshowcnt != 0)
|
---|
| 537 | {
|
---|
| 538 | if(cursorshowcnt > 0 )
|
---|
| 539 | {
|
---|
| 540 | ShowCursor(FALSE);
|
---|
| 541 | }
|
---|
| 542 | else
|
---|
| 543 | {
|
---|
| 544 | ShowCursor(TRUE);
|
---|
| 545 | }
|
---|
| 546 | }
|
---|
| 547 | }
|
---|
| 548 | //******************************************************************************
|
---|
| 549 | //******************************************************************************
|
---|
| 550 | int WIN32API ShowCursor(BOOL bShow)
|
---|
| 551 | {
|
---|
| 552 | dprintf2(("USER32: ShowCursor %d", bShow));
|
---|
| 553 | cursorshowcnt = cursorshowcnt + ((bShow) ? 1 : -1);
|
---|
| 554 | return _ShowCursor(bShow);
|
---|
| 555 | }
|
---|
[4573] | 556 | /***********************************************************************
|
---|
[5385] | 557 | * CreateCursorIconIndirect
|
---|
[4573] | 558 | */
|
---|
[6595] | 559 | static HGLOBAL CreateCursorIconIndirect( HINSTANCE hInstance,
|
---|
| 560 | CURSORICONINFO *info,
|
---|
| 561 | LPCVOID lpANDbits,
|
---|
| 562 | LPCVOID lpXORbits, BOOL fIcon)
|
---|
[2469] | 563 | {
|
---|
[4573] | 564 | HGLOBAL handle;
|
---|
| 565 | char *ptr;
|
---|
| 566 | int sizeAnd, sizeXor;
|
---|
[6595] | 567 | #ifdef __WIN32OS2__
|
---|
| 568 | BITMAP bmpXor, bmpAnd;
|
---|
| 569 | #endif
|
---|
[2469] | 570 |
|
---|
[4573] | 571 | if (!lpXORbits || !lpANDbits || info->bPlanes != 1) return 0;
|
---|
| 572 | info->nWidthBytes = BITMAP_GetWidthBytes(info->nWidth,info->bBitsPerPixel);
|
---|
| 573 | sizeXor = info->nHeight * info->nWidthBytes;
|
---|
| 574 | sizeAnd = info->nHeight * BITMAP_GetWidthBytes( info->nWidth, 1 );
|
---|
| 575 | if (!(handle = GlobalAlloc( GMEM_MOVEABLE,
|
---|
| 576 | sizeof(CURSORICONINFO) + sizeXor + sizeAnd)))
|
---|
| 577 | return 0;
|
---|
| 578 | ptr = (char *)GlobalLock( handle );
|
---|
| 579 | memcpy( ptr, info, sizeof(*info) );
|
---|
| 580 | memcpy( ptr + sizeof(CURSORICONINFO), lpANDbits, sizeAnd );
|
---|
| 581 | memcpy( ptr + sizeof(CURSORICONINFO) + sizeAnd, lpXORbits, sizeXor );
|
---|
[6595] | 582 | #ifdef __WIN32OS2__
|
---|
| 583 | bmpAnd.bmType = 0;
|
---|
| 584 | bmpAnd.bmWidth = info->nWidth;
|
---|
| 585 | bmpAnd.bmHeight = info->nHeight;
|
---|
| 586 | bmpAnd.bmWidthBytes = BITMAP_GetWidthBytes(info->nWidth, 1);
|
---|
| 587 | bmpAnd.bmPlanes = info->bPlanes;
|
---|
| 588 | bmpAnd.bmBitsPixel = 1;
|
---|
| 589 | bmpAnd.bmBits = NULL;
|
---|
| 590 |
|
---|
| 591 | bmpXor.bmType = 0;
|
---|
| 592 | bmpXor.bmWidth = info->nWidth;
|
---|
| 593 | bmpXor.bmHeight = info->nHeight;
|
---|
| 594 | bmpXor.bmWidthBytes = info->nWidthBytes;
|
---|
| 595 | bmpXor.bmPlanes = info->bPlanes;
|
---|
| 596 | bmpXor.bmBitsPixel = info->bBitsPerPixel;
|
---|
| 597 | bmpXor.bmBits = NULL;
|
---|
[21916] | 598 | ((CURSORICONINFO *)ptr)->hColorBmp =
|
---|
[6595] | 599 | OSLibWinCreatePointer(info, (char *)lpANDbits, (LPBITMAP_W)&bmpAnd, (char *)lpXORbits, (LPBITMAP_W)&bmpXor, fIcon == FALSE);
|
---|
| 600 | #endif
|
---|
[4573] | 601 | GlobalUnlock( handle );
|
---|
[6183] | 602 |
|
---|
| 603 | #ifdef __WIN32OS2__
|
---|
| 604 | HICON hIcon;
|
---|
[8872] | 605 | if(ObjAllocateHandle(&hIcon, (DWORD)handle, HNDL_CURSORICON) == FALSE) {
|
---|
[6183] | 606 | GlobalFree(handle);
|
---|
| 607 | dprintf(("ERROR: CreateCursorIconIndirect ObjAllocateHandle failed!!"));
|
---|
| 608 | return 0;
|
---|
| 609 | }
|
---|
[6595] | 610 | dprintf(("USER32: CreateCursorIconIndirect returned %x", hIcon));
|
---|
[6183] | 611 | return hIcon;
|
---|
| 612 | #else
|
---|
[4573] | 613 | return handle;
|
---|
[6183] | 614 | #endif
|
---|
[4573] | 615 | }
|
---|
| 616 | /**********************************************************************
|
---|
| 617 | * CURSORICON_Load
|
---|
| 618 | *
|
---|
| 619 | * Load a cursor or icon from resource or file.
|
---|
| 620 | */
|
---|
| 621 | HGLOBAL CURSORICON_Load( HINSTANCE hInstance, LPCWSTR name,
|
---|
| 622 | INT width, INT height, INT colors,
|
---|
| 623 | BOOL fCursor, UINT loadflags )
|
---|
| 624 | {
|
---|
| 625 | HANDLE handle = 0, h = 0;
|
---|
| 626 | HANDLE hRsrc;
|
---|
| 627 | CURSORICONDIR *dir;
|
---|
| 628 | CURSORICONDIRENTRY *dirEntry;
|
---|
| 629 | LPBYTE bits;
|
---|
| 630 |
|
---|
[5385] | 631 | #ifdef __WIN32OS2__
|
---|
| 632 | //TODO: Can system cursors be loaded by name??? (#xxx)
|
---|
| 633 | if (fCursor && hInstance == NULL && !HIWORD(name))
|
---|
| 634 | {
|
---|
| 635 | HCURSOR hCursor = OSLibWinQuerySysPointer((ULONG)name, width, height);
|
---|
| 636 | if(hCursor)
|
---|
| 637 | {
|
---|
| 638 | /* If shared icon, check whether it was already loaded */
|
---|
| 639 | if ((loadflags & LR_SHARED)
|
---|
| 640 | && (h = CURSORICON_FindSharedIcon( -1, hCursor ) ) != 0 )
|
---|
| 641 | {
|
---|
| 642 | dprintf(("Found icon/cursor in cache; returned old handle %x", h));
|
---|
| 643 | return h;
|
---|
| 644 | }
|
---|
| 645 |
|
---|
| 646 | HANDLE hObj = GlobalAlloc( GMEM_MOVEABLE, sizeof(CURSORICONINFO));
|
---|
| 647 | if (!hObj)
|
---|
| 648 | {
|
---|
| 649 | DebugInt3();
|
---|
| 650 | return 0;
|
---|
| 651 | }
|
---|
| 652 | CURSORICONINFO *info;
|
---|
| 653 |
|
---|
| 654 | info = (CURSORICONINFO *)GlobalLock( hObj );
|
---|
| 655 | info->ptHotSpot.x = 0;
|
---|
| 656 | info->ptHotSpot.y = 0;
|
---|
| 657 | info->nWidth = width;
|
---|
| 658 | info->nHeight = height;
|
---|
| 659 | info->nWidthBytes = width*height/8;
|
---|
| 660 | info->bPlanes = 1;
|
---|
| 661 | info->bBitsPerPixel = 1;
|
---|
| 662 | info->hColorBmp = hCursor;
|
---|
| 663 | info->hInstance = -1;
|
---|
| 664 | info->dwResGroupId = -1;
|
---|
| 665 |
|
---|
[6183] | 666 | HICON hIcon;
|
---|
[8872] | 667 | if(ObjAllocateHandle(&hIcon, (DWORD)hObj, HNDL_CURSORICON) == FALSE) {
|
---|
[6183] | 668 | GlobalUnlock( hObj );
|
---|
| 669 | GlobalFree(hObj);
|
---|
| 670 | dprintf(("ERROR: CURSORICON_Load ObjAllocateHandle failed!!"));
|
---|
| 671 | return 0;
|
---|
| 672 | }
|
---|
| 673 |
|
---|
[5385] | 674 | if (loadflags & LR_SHARED )
|
---|
[6241] | 675 | CURSORICON_AddSharedIcon( -1, hCursor, -1, hIcon );
|
---|
[5385] | 676 |
|
---|
| 677 | GlobalUnlock( hObj );
|
---|
| 678 |
|
---|
[6183] | 679 | return hIcon;
|
---|
[5385] | 680 | }
|
---|
| 681 | }
|
---|
| 682 | #endif
|
---|
[4573] | 683 | if ( loadflags & LR_LOADFROMFILE ) /* Load from file */
|
---|
[2469] | 684 | {
|
---|
[4573] | 685 | LPBYTE *ptr;
|
---|
[5385] | 686 |
|
---|
[4573] | 687 | if (!CURSORICON_SimulateLoadingFromResourceW((LPWSTR)name, fCursor, &dir, &ptr))
|
---|
| 688 | return 0;
|
---|
| 689 | if (fCursor)
|
---|
| 690 | dirEntry = (CURSORICONDIRENTRY *)CURSORICON_FindBestCursor(dir, width, height, 1);
|
---|
| 691 | else
|
---|
| 692 | dirEntry = (CURSORICONDIRENTRY *)CURSORICON_FindBestIcon(dir, width, height, colors);
|
---|
| 693 | bits = ptr[dirEntry->wResId-1];
|
---|
[4612] | 694 | h = CURSORICON_CreateFromResource( 0, -1, 0, bits, dirEntry->dwBytesInRes,
|
---|
[4573] | 695 | !fCursor, 0x00030000, width, height, loadflags);
|
---|
[5385] | 696 |
|
---|
[4573] | 697 | HeapFree( GetProcessHeap(), 0, dir );
|
---|
| 698 | HeapFree( GetProcessHeap(), 0, ptr );
|
---|
| 699 | }
|
---|
| 700 | else /* Load from resource */
|
---|
| 701 | {
|
---|
| 702 | HANDLE hGroupRsrc;
|
---|
| 703 | WORD wResId;
|
---|
| 704 | DWORD dwBytesInRes;
|
---|
| 705 | BOOL bIsGroup = TRUE;
|
---|
[2469] | 706 |
|
---|
[4573] | 707 | /* Get directory resource ID */
|
---|
| 708 | if (!hInstance)
|
---|
| 709 | {
|
---|
| 710 | hRsrc = FindResourceW(hInstanceUser32, name, fCursor ? RT_CURSORW : RT_ICONW);
|
---|
| 711 | if(!hRsrc) {
|
---|
| 712 | hRsrc = FindResourceW(hInstanceUser32, name, fCursor ? RT_GROUP_CURSORW : RT_GROUP_ICONW);
|
---|
| 713 | }
|
---|
| 714 | else bIsGroup = FALSE;
|
---|
[2469] | 715 |
|
---|
[4573] | 716 | if(!hRsrc) return 0;
|
---|
[2469] | 717 |
|
---|
[4573] | 718 | hInstance = hInstanceUser32;
|
---|
[2469] | 719 | }
|
---|
| 720 | else {
|
---|
[4573] | 721 | hRsrc = FindResourceW(hInstance, name, fCursor ? RT_GROUP_CURSORW : RT_GROUP_ICONW);
|
---|
| 722 | if(!hRsrc) return 0;
|
---|
[2469] | 723 | }
|
---|
[4573] | 724 | hGroupRsrc = hRsrc;
|
---|
[2469] | 725 |
|
---|
[4573] | 726 | if(bIsGroup) {
|
---|
| 727 | /* Find the best entry in the directory */
|
---|
[2469] | 728 |
|
---|
[4573] | 729 | if (!(handle = LoadResource( hInstance, hRsrc ))) return 0;
|
---|
| 730 | if (!(dir = (CURSORICONDIR*)LockResource( handle ))) return 0;
|
---|
[2469] | 731 |
|
---|
[4573] | 732 | if (fCursor)
|
---|
| 733 | dirEntry = (CURSORICONDIRENTRY *)CURSORICON_FindBestCursor( dir,
|
---|
| 734 | width, height, 1);
|
---|
| 735 | else
|
---|
| 736 | dirEntry = (CURSORICONDIRENTRY *)CURSORICON_FindBestIcon( dir,
|
---|
| 737 | width, height, colors );
|
---|
| 738 | if (!dirEntry) return 0;
|
---|
| 739 | wResId = dirEntry->wResId;
|
---|
| 740 | dwBytesInRes = dirEntry->dwBytesInRes;
|
---|
| 741 | FreeResource( handle );
|
---|
| 742 |
|
---|
| 743 | /* Load the resource */
|
---|
| 744 | if (!(hRsrc = FindResourceW(hInstance,MAKEINTRESOURCEW(wResId),
|
---|
| 745 | fCursor ? RT_CURSORW : RT_ICONW ))) return 0;
|
---|
[2469] | 746 | }
|
---|
| 747 |
|
---|
[5385] | 748 | /* If shared icon, check whether it was already loaded */
|
---|
| 749 | if ((loadflags & LR_SHARED)
|
---|
| 750 | && (h = CURSORICON_FindSharedIcon( hInstance, hRsrc ) ) != 0 )
|
---|
| 751 | {
|
---|
| 752 | dprintf(("Found icon/cursor in cache; returned old handle %x", h));
|
---|
| 753 | return h;
|
---|
| 754 | }
|
---|
| 755 |
|
---|
[4573] | 756 | if (!(handle = LoadResource( hInstance, hRsrc ))) return 0;
|
---|
| 757 | bits = (LPBYTE)LockResource( handle );
|
---|
[4612] | 758 | h = CURSORICON_CreateFromResource( hInstance, (DWORD)name, 0, bits, dwBytesInRes,
|
---|
[4573] | 759 | !fCursor, 0x00030000, width, height, loadflags);
|
---|
| 760 | FreeResource( handle );
|
---|
| 761 |
|
---|
[5385] | 762 | /* If shared icon, add to icon cache */
|
---|
| 763 |
|
---|
| 764 | if ( h && (loadflags & LR_SHARED) )
|
---|
| 765 | CURSORICON_AddSharedIcon( hInstance, hRsrc, hGroupRsrc, h );
|
---|
| 766 |
|
---|
[2469] | 767 | }
|
---|
[4573] | 768 |
|
---|
| 769 | return h;
|
---|
[2469] | 770 | }
|
---|
[4573] | 771 |
|
---|
| 772 | /*********************************************************************
|
---|
| 773 | * The main purpose of this function is to create fake resource directory
|
---|
| 774 | * and fake resource entries. There are several reasons for this:
|
---|
| 775 | * - CURSORICONDIR and CURSORICONFILEDIR differ in sizes and their
|
---|
| 776 | * fields
|
---|
| 777 | * There are some "bad" cursor files which do not have
|
---|
| 778 | * bColorCount initialized but instead one must read this info
|
---|
| 779 | * directly from corresponding DIB sections
|
---|
| 780 | * Note: wResId is index to array of pointer returned in ptrs (origin is 1)
|
---|
| 781 | */
|
---|
| 782 | BOOL CURSORICON_SimulateLoadingFromResourceW( LPWSTR filename, BOOL fCursor,
|
---|
| 783 | CURSORICONDIR **res, LPBYTE **ptr)
|
---|
[2469] | 784 | {
|
---|
[4573] | 785 | LPBYTE _free;
|
---|
| 786 | CURSORICONFILEDIR *bits;
|
---|
| 787 | int entries, size, i;
|
---|
| 788 | HANDLE hMapping = 0;
|
---|
| 789 |
|
---|
| 790 | *res = NULL;
|
---|
| 791 | *ptr = NULL;
|
---|
| 792 |
|
---|
| 793 | hMapping = VIRTUAL_MapFileW( filename, (LPVOID *)&bits, TRUE);
|
---|
| 794 | if(hMapping == INVALID_HANDLE_VALUE)
|
---|
| 795 | return FALSE;
|
---|
| 796 |
|
---|
| 797 | /* FIXME: test for inimated icons
|
---|
| 798 | * hack to load the first icon from the *.ani file
|
---|
| 799 | */
|
---|
| 800 | if ( *(LPDWORD)bits==0x46464952 ) /* "RIFF" */
|
---|
| 801 | {
|
---|
| 802 | LPBYTE pos = (LPBYTE) bits;
|
---|
| 803 | dprintf(("Animated icons not correctly implemented! %p \n", bits));
|
---|
| 804 |
|
---|
| 805 | for (;;)
|
---|
| 806 | {
|
---|
| 807 | if (*(LPDWORD)pos==0x6e6f6369) /* "icon" */
|
---|
| 808 | {
|
---|
| 809 | dprintf(("icon entry found! %p\n", bits));
|
---|
| 810 | pos+=4;
|
---|
| 811 | if ( !*(LPWORD) pos==0x2fe) /* iconsize */
|
---|
| 812 | {
|
---|
| 813 | goto fail;
|
---|
| 814 | }
|
---|
| 815 | bits=(CURSORICONFILEDIR*)(pos+4);
|
---|
| 816 | dprintf(("icon size ok. offset=%p \n", bits));
|
---|
| 817 | break;
|
---|
| 818 | }
|
---|
| 819 | pos+=2;
|
---|
| 820 | if (pos>=(LPBYTE)bits+766) goto fail;
|
---|
| 821 | }
|
---|
| 822 | }
|
---|
| 823 | if (!(entries = bits->idCount)) goto fail;
|
---|
| 824 | size = sizeof(CURSORICONDIR) + sizeof(CURSORICONDIRENTRY) * (entries - 1);
|
---|
| 825 | _free = (LPBYTE) size;
|
---|
| 826 |
|
---|
| 827 | for (i=0; i < entries; i++)
|
---|
| 828 | size += bits->idEntries[i].dwDIBSize + (fCursor ? sizeof(POINT16): 0);
|
---|
| 829 |
|
---|
| 830 | if (!(*ptr = (LPBYTE *)HeapAlloc( GetProcessHeap(), 0,
|
---|
| 831 | entries * sizeof (CURSORICONDIRENTRY*)))) goto fail;
|
---|
| 832 | if (!(*res = (CURSORICONDIR *)HeapAlloc( GetProcessHeap(), 0, size))) goto fail;
|
---|
| 833 |
|
---|
| 834 | _free = (LPBYTE)(*res) + (int)_free;
|
---|
| 835 | memcpy((*res), bits, 6);
|
---|
| 836 | for (i=0; i<entries; i++)
|
---|
| 837 | {
|
---|
| 838 | ((LPBYTE*)(*ptr))[i] = _free;
|
---|
| 839 | if (fCursor) {
|
---|
| 840 | (*res)->idEntries[i].ResInfo.cursor.wWidth=bits->idEntries[i].bWidth;
|
---|
| 841 | (*res)->idEntries[i].ResInfo.cursor.wHeight=bits->idEntries[i].bHeight;
|
---|
| 842 | ((LPPOINT16)_free)->x=bits->idEntries[i].xHotspot;
|
---|
| 843 | ((LPPOINT16)_free)->y=bits->idEntries[i].yHotspot;
|
---|
| 844 | _free+=sizeof(POINT16);
|
---|
| 845 | }
|
---|
| 846 | else {
|
---|
| 847 | (*res)->idEntries[i].ResInfo.icon.bWidth=bits->idEntries[i].bWidth;
|
---|
| 848 | (*res)->idEntries[i].ResInfo.icon.bHeight=bits->idEntries[i].bHeight;
|
---|
| 849 | (*res)->idEntries[i].ResInfo.icon.bColorCount = bits->idEntries[i].bColorCount;
|
---|
| 850 | }
|
---|
| 851 | (*res)->idEntries[i].wPlanes=1;
|
---|
| 852 | (*res)->idEntries[i].wBitCount = ((LPBITMAPINFOHEADER)((LPBYTE)bits +
|
---|
| 853 | bits->idEntries[i].dwDIBOffset))->biBitCount;
|
---|
| 854 | (*res)->idEntries[i].dwBytesInRes = bits->idEntries[i].dwDIBSize;
|
---|
| 855 | (*res)->idEntries[i].wResId=i+1;
|
---|
| 856 |
|
---|
| 857 | memcpy(_free,(LPBYTE)bits +bits->idEntries[i].dwDIBOffset,
|
---|
| 858 | (*res)->idEntries[i].dwBytesInRes);
|
---|
| 859 | _free += (*res)->idEntries[i].dwBytesInRes;
|
---|
| 860 | }
|
---|
| 861 | UnmapViewOfFile( bits );
|
---|
| 862 | CloseHandle(hMapping);
|
---|
| 863 | return TRUE;
|
---|
| 864 |
|
---|
| 865 | fail:
|
---|
| 866 | if (*res) HeapFree( GetProcessHeap(), 0, *res );
|
---|
| 867 | if (*ptr) HeapFree( GetProcessHeap(), 0, *ptr );
|
---|
| 868 |
|
---|
| 869 | UnmapViewOfFile( bits );
|
---|
| 870 | CloseHandle(hMapping);
|
---|
| 871 | return FALSE;
|
---|
[2469] | 872 | }
|
---|
[4573] | 873 |
|
---|
| 874 | /**********************************************************************
|
---|
| 875 | * CURSORICON_CreateFromResource
|
---|
| 876 | *
|
---|
| 877 | * Create a cursor or icon from in-memory resource template.
|
---|
| 878 | *
|
---|
| 879 | * FIXME: Convert to mono when cFlag is LR_MONOCHROME. Do something
|
---|
| 880 | * with cbSize parameter as well.
|
---|
| 881 | */
|
---|
[4612] | 882 | static HGLOBAL CURSORICON_CreateFromResource( HINSTANCE hInstance, DWORD dwResGroupId, HGLOBAL hObj, LPBYTE bits,
|
---|
[4573] | 883 | UINT cbSize, BOOL bIcon, DWORD dwVersion,
|
---|
| 884 | INT width, INT height, UINT loadflags )
|
---|
[2469] | 885 | {
|
---|
[4573] | 886 | int sizeAnd, sizeXor;
|
---|
| 887 | HBITMAP hAndBits = 0, hXorBits = 0; /* error condition for later */
|
---|
| 888 | BITMAP bmpXor, bmpAnd;
|
---|
| 889 | POINT16 hotspot;
|
---|
| 890 | BITMAPINFO *bmi;
|
---|
| 891 | HDC hdc = 0;
|
---|
| 892 | BOOL DoStretch;
|
---|
[4579] | 893 | INT size, colortablesize, bwsize, colorsize;
|
---|
[4573] | 894 |
|
---|
| 895 | hotspot.x = ICON_HOTSPOT;
|
---|
| 896 | hotspot.y = ICON_HOTSPOT;
|
---|
| 897 |
|
---|
[6487] | 898 | dprintf2(("CURSORICON_CreateFromResource %x %x %x %x %d", hInstance, dwResGroupId, hObj, bits, cbSize));
|
---|
[4612] | 899 |
|
---|
[4573] | 900 | if (dwVersion == 0x00020000)
|
---|
| 901 | {
|
---|
| 902 | dprintf(("CURSORICON_CreateFromResource 2.xx resources are not supported"));
|
---|
| 903 | return 0;
|
---|
| 904 | }
|
---|
| 905 |
|
---|
| 906 | if (bIcon) {
|
---|
| 907 | bmi = (BITMAPINFO *)bits;
|
---|
| 908 | }
|
---|
| 909 | else /* get the hotspot */
|
---|
| 910 | {
|
---|
| 911 | POINT16 *pt = (POINT16 *)bits;
|
---|
| 912 | hotspot = *pt;
|
---|
| 913 | bmi = (BITMAPINFO *)(pt + 1);
|
---|
| 914 | }
|
---|
| 915 | size = DIB_BitmapInfoSize(bmi, DIB_RGB_COLORS);
|
---|
| 916 |
|
---|
| 917 | if (!width) width = bmi->bmiHeader.biWidth;
|
---|
| 918 | if (!height) height = bmi->bmiHeader.biHeight/2;
|
---|
| 919 |
|
---|
| 920 | DoStretch = (bmi->bmiHeader.biHeight/2 != height) || (bmi->bmiHeader.biWidth != width);
|
---|
| 921 |
|
---|
[4579] | 922 | colorsize = DIB_GetDIBImageBytes(bmi->bmiHeader.biWidth, bmi->bmiHeader.biHeight/2, bmi->bmiHeader.biBitCount);
|
---|
[9393] | 923 | bwsize = BITMAP_GetWidthBytes(bmi->bmiHeader.biWidth, 1) * bmi->bmiHeader.biHeight/2;
|
---|
[4579] | 924 |
|
---|
[4573] | 925 | /* Check bitmap header */
|
---|
[4579] | 926 | if((bmi->bmiHeader.biSize != sizeof(BITMAPCOREHEADER)) &&
|
---|
| 927 | (bmi->bmiHeader.biSize != sizeof(BITMAPINFOHEADER) ||
|
---|
| 928 | bmi->bmiHeader.biCompression != BI_RGB) )
|
---|
[4573] | 929 | {
|
---|
| 930 | return 0;
|
---|
| 931 | }
|
---|
| 932 |
|
---|
[5968] | 933 | #ifdef __WIN32OS2__
|
---|
[21356] | 934 | if( (hdc = CreateCompatibleDC( 0 )) != 0 )
|
---|
[5968] | 935 | #else
|
---|
[4573] | 936 | if( (hdc = GetDC( 0 )) )
|
---|
[5968] | 937 | #endif
|
---|
[4573] | 938 | {
|
---|
| 939 | BITMAPINFO* pInfo;
|
---|
| 940 |
|
---|
| 941 | /* Make sure we have room for the monochrome bitmap later on.
|
---|
| 942 | * Note that BITMAPINFOINFO and BITMAPCOREHEADER are the same
|
---|
| 943 | * up to and including the biBitCount. In-memory icon resource
|
---|
| 944 | * format is as follows:
|
---|
| 945 | *
|
---|
| 946 | * BITMAPINFOHEADER icHeader // DIB header
|
---|
| 947 | * RGBQUAD icColors[] // Color table
|
---|
| 948 | * BYTE icXOR[] // DIB bits for XOR mask
|
---|
| 949 | * BYTE icAND[] // DIB bits for AND mask
|
---|
| 950 | */
|
---|
| 951 |
|
---|
| 952 | if ((pInfo = (BITMAPINFO *)HeapAlloc( GetProcessHeap(), 0,
|
---|
[21356] | 953 | max(size, sizeof(BITMAPINFOHEADER) + 2*sizeof(RGBQUAD)))) != NULL)
|
---|
[4573] | 954 | {
|
---|
| 955 | memcpy( pInfo, bmi, size );
|
---|
| 956 | pInfo->bmiHeader.biHeight /= 2;
|
---|
| 957 |
|
---|
| 958 | /* Create the XOR bitmap */
|
---|
| 959 | if (DoStretch)
|
---|
| 960 | {
|
---|
| 961 | if(bIcon)
|
---|
| 962 | {
|
---|
| 963 | hXorBits = CreateCompatibleBitmap(hdc, width, height);
|
---|
| 964 | }
|
---|
| 965 | else
|
---|
| 966 | {
|
---|
| 967 | hXorBits = CreateBitmap(width, height, 1, 1, NULL);
|
---|
| 968 | }
|
---|
| 969 | if(hXorBits)
|
---|
| 970 | {
|
---|
| 971 | HBITMAP hOld;
|
---|
| 972 | HDC hMem = CreateCompatibleDC(hdc);
|
---|
| 973 | BOOL res;
|
---|
| 974 |
|
---|
| 975 | if (hMem) {
|
---|
| 976 | hOld = SelectObject(hMem, hXorBits);
|
---|
| 977 | res = StretchDIBits(hMem, 0, 0, width, height, 0, 0,
|
---|
| 978 | bmi->bmiHeader.biWidth, bmi->bmiHeader.biHeight/2,
|
---|
| 979 | (char*)bmi + size, pInfo, DIB_RGB_COLORS, SRCCOPY);
|
---|
| 980 | SelectObject(hMem, hOld);
|
---|
| 981 | DeleteDC(hMem);
|
---|
| 982 | }
|
---|
| 983 | else res = FALSE;
|
---|
| 984 | if (!res) {
|
---|
| 985 | DeleteObject(hXorBits);
|
---|
| 986 | hXorBits = 0;
|
---|
| 987 | }
|
---|
| 988 | }
|
---|
| 989 | }
|
---|
| 990 | else
|
---|
| 991 | {
|
---|
| 992 | hXorBits = CreateDIBitmap(hdc, &pInfo->bmiHeader,
|
---|
| 993 | CBM_INIT, (char*)bmi + size, pInfo, DIB_RGB_COLORS );
|
---|
| 994 | }
|
---|
| 995 | if( hXorBits )
|
---|
| 996 | {
|
---|
| 997 | char* xbits = (char *)bmi + size + DIB_GetDIBImageBytes(bmi->bmiHeader.biWidth,
|
---|
| 998 | bmi->bmiHeader.biHeight,
|
---|
| 999 | bmi->bmiHeader.biBitCount) / 2;
|
---|
| 1000 |
|
---|
| 1001 | pInfo->bmiHeader.biBitCount = 1;
|
---|
| 1002 | if (pInfo->bmiHeader.biSize == sizeof(BITMAPINFOHEADER))
|
---|
| 1003 | {
|
---|
| 1004 | RGBQUAD *rgb = pInfo->bmiColors;
|
---|
| 1005 |
|
---|
| 1006 | pInfo->bmiHeader.biClrUsed = pInfo->bmiHeader.biClrImportant = 2;
|
---|
| 1007 | rgb[0].rgbBlue = rgb[0].rgbGreen = rgb[0].rgbRed = 0x00;
|
---|
| 1008 | rgb[1].rgbBlue = rgb[1].rgbGreen = rgb[1].rgbRed = 0xff;
|
---|
| 1009 | rgb[0].rgbReserved = rgb[1].rgbReserved = 0;
|
---|
| 1010 | }
|
---|
| 1011 | else
|
---|
| 1012 | {
|
---|
| 1013 | RGBTRIPLE *rgb = (RGBTRIPLE *)(((BITMAPCOREHEADER *)pInfo) + 1);
|
---|
| 1014 |
|
---|
| 1015 | rgb[0].rgbtBlue = rgb[0].rgbtGreen = rgb[0].rgbtRed = 0x00;
|
---|
| 1016 | rgb[1].rgbtBlue = rgb[1].rgbtGreen = rgb[1].rgbtRed = 0xff;
|
---|
| 1017 | }
|
---|
| 1018 |
|
---|
| 1019 | /* Create the AND bitmap */
|
---|
| 1020 | if (DoStretch)
|
---|
| 1021 | {
|
---|
[21356] | 1022 | if ((hAndBits = CreateBitmap(width, height, 1, 1, NULL)) != 0)
|
---|
[4573] | 1023 | {
|
---|
| 1024 | HBITMAP hOld;
|
---|
| 1025 | HDC hMem = CreateCompatibleDC(hdc);
|
---|
| 1026 | BOOL res;
|
---|
| 1027 |
|
---|
| 1028 | if (hMem) {
|
---|
| 1029 | hOld = SelectObject(hMem, hAndBits);
|
---|
[4677] | 1030 | //SvL: This also doesn't work as StretchDIBits doesn't handle 1bpp bitmaps correctly
|
---|
| 1031 | //--------->>> hack alert!
|
---|
| 1032 | #if 1
|
---|
| 1033 | HBITMAP hBmp, hOld1;
|
---|
| 1034 | HDC hMem1;
|
---|
| 1035 |
|
---|
| 1036 | hMem1 = CreateCompatibleDC(hdc);
|
---|
| 1037 |
|
---|
| 1038 | int linewidth = BITMAP_GetWidthBytes(pInfo->bmiHeader.biWidth, 1);
|
---|
| 1039 |
|
---|
| 1040 | char *newpix = (char *)malloc(linewidth*pInfo->bmiHeader.biHeight);
|
---|
| 1041 |
|
---|
| 1042 | newpix += ((pInfo->bmiHeader.biHeight-1)*linewidth);
|
---|
| 1043 |
|
---|
| 1044 | if(cbSize - size - colorsize - bwsize == bwsize)
|
---|
| 1045 | {//this means an AND and XOR mask is present (interleaved; and/xor)
|
---|
| 1046 | for(int i=0;i<pInfo->bmiHeader.biHeight;i++) {
|
---|
| 1047 | memcpy(newpix, xbits, linewidth);
|
---|
| 1048 | newpix -= linewidth;
|
---|
| 1049 | xbits += linewidth*2;
|
---|
| 1050 | }
|
---|
| 1051 | }
|
---|
| 1052 | else {
|
---|
| 1053 | for(int i=0;i<pInfo->bmiHeader.biHeight;i++) {
|
---|
| 1054 | memcpy(newpix, xbits, linewidth);
|
---|
| 1055 | newpix -= linewidth;
|
---|
| 1056 | xbits += linewidth;
|
---|
| 1057 | }
|
---|
| 1058 | }
|
---|
| 1059 | newpix += linewidth;
|
---|
| 1060 | hBmp = CreateBitmap(pInfo->bmiHeader.biWidth, pInfo->bmiHeader.biHeight, 1, 1, newpix);
|
---|
| 1061 | free(newpix);
|
---|
| 1062 |
|
---|
| 1063 | hOld1 = SelectObject(hMem1, hBmp);
|
---|
| 1064 |
|
---|
| 1065 | res = StretchBlt(hMem, 0, 0, width, height, hMem1, 0, 0, pInfo->bmiHeader.biWidth, pInfo->bmiHeader.biHeight, SRCCOPY);
|
---|
| 1066 |
|
---|
| 1067 | SelectObject(hMem1, hOld1);
|
---|
| 1068 | DeleteObject(hBmp);
|
---|
| 1069 | DeleteDC(hMem1);
|
---|
| 1070 |
|
---|
| 1071 |
|
---|
| 1072 | #else
|
---|
[4573] | 1073 | res = StretchDIBits(hMem, 0, 0, width, height, 0, 0,
|
---|
| 1074 | pInfo->bmiHeader.biWidth, pInfo->bmiHeader.biHeight,
|
---|
| 1075 | xbits, pInfo, DIB_RGB_COLORS, SRCCOPY);
|
---|
[4677] | 1076 | #endif
|
---|
[4573] | 1077 | SelectObject(hMem, hOld);
|
---|
| 1078 | DeleteDC(hMem);
|
---|
| 1079 | }
|
---|
| 1080 | else res = FALSE;
|
---|
| 1081 | if (!res) {
|
---|
[4677] | 1082 | DeleteObject(hAndBits);
|
---|
| 1083 | hAndBits = 0;
|
---|
[4573] | 1084 | }
|
---|
| 1085 | }
|
---|
| 1086 | }
|
---|
| 1087 | else {
|
---|
| 1088 | //SvL: Must use CreateBitmap here as CreateDIBitmap converts data to 8bpp (GetObjectA info -> 8 bpp)
|
---|
| 1089 | #if 1
|
---|
[21916] | 1090 | int linewidth;
|
---|
[9432] | 1091 | int orglinewidth;
|
---|
[4573] | 1092 |
|
---|
[9432] | 1093 | linewidth = BITMAP_GetWidthBytes(width, 1);
|
---|
| 1094 |
|
---|
| 1095 | //the lines in the image might be aligned differently
|
---|
| 1096 | //CreateBitmap expects them to be optimally aligned
|
---|
| 1097 | //(as calculated by BITMAP_GetWidthBytes)
|
---|
| 1098 | //(For now only applies when both masks (and/xor) aren't present)
|
---|
| 1099 | if(pInfo->bmiHeader.biSizeImage > colorsize + bwsize) {
|
---|
| 1100 | orglinewidth = (pInfo->bmiHeader.biSizeImage - colorsize)/height;
|
---|
| 1101 | }
|
---|
| 1102 | else orglinewidth = linewidth;
|
---|
| 1103 |
|
---|
[4573] | 1104 | char *newpix = (char *)malloc(linewidth*height);
|
---|
| 1105 |
|
---|
| 1106 | newpix += ((height-1)*linewidth);
|
---|
| 1107 |
|
---|
[4579] | 1108 | if(cbSize - size - colorsize - bwsize == bwsize)
|
---|
| 1109 | {//this means an AND and XOR mask is present (interleaved; and/xor)
|
---|
| 1110 | for(int i=0;i<height;i++) {
|
---|
| 1111 | memcpy(newpix, xbits, linewidth);
|
---|
| 1112 | newpix -= linewidth;
|
---|
| 1113 | xbits += linewidth*2;
|
---|
| 1114 | }
|
---|
[4573] | 1115 | }
|
---|
[4579] | 1116 | else {
|
---|
| 1117 | for(int i=0;i<height;i++) {
|
---|
| 1118 | memcpy(newpix, xbits, linewidth);
|
---|
| 1119 | newpix -= linewidth;
|
---|
[9432] | 1120 | xbits += orglinewidth;
|
---|
[4579] | 1121 | }
|
---|
| 1122 | }
|
---|
[4573] | 1123 | newpix += linewidth;
|
---|
| 1124 | hAndBits = CreateBitmap(width, height, 1, 1, newpix);
|
---|
| 1125 |
|
---|
| 1126 | free(newpix);
|
---|
| 1127 |
|
---|
| 1128 | #else
|
---|
| 1129 | hAndBits = CreateDIBitmap(hdc, &pInfo->bmiHeader,
|
---|
| 1130 | CBM_INIT, xbits, pInfo, DIB_RGB_COLORS );
|
---|
| 1131 | #endif
|
---|
| 1132 | }
|
---|
| 1133 | if( !hAndBits )
|
---|
| 1134 | DeleteObject( hXorBits );
|
---|
| 1135 | }
|
---|
| 1136 | HeapFree( GetProcessHeap(), 0, pInfo );
|
---|
| 1137 | }
|
---|
[5968] | 1138 | #ifdef __WIN32OS2__
|
---|
| 1139 | DeleteDC(hdc );
|
---|
| 1140 | #else
|
---|
[4573] | 1141 | ReleaseDC( 0, hdc );
|
---|
[5968] | 1142 | #endif
|
---|
[4573] | 1143 | }
|
---|
| 1144 |
|
---|
| 1145 | if( !hXorBits || !hAndBits )
|
---|
| 1146 | {
|
---|
[5385] | 1147 | dprintf(("\tunable to create an icon bitmap."));
|
---|
[4573] | 1148 | return 0;
|
---|
| 1149 | }
|
---|
| 1150 | /* Now create the CURSORICONINFO structure */
|
---|
| 1151 | GetObjectA( hXorBits, sizeof(bmpXor), &bmpXor );
|
---|
| 1152 | GetObjectA( hAndBits, sizeof(bmpAnd), &bmpAnd );
|
---|
| 1153 | colortablesize = 0;
|
---|
| 1154 |
|
---|
[9624] | 1155 | //SvL: Workaround for problem with B&W cursor XOR bitmaps
|
---|
| 1156 | // End result = inverted PM cursor; not sure what's actually causing
|
---|
| 1157 | // this...
|
---|
| 1158 | // So we let GetDIBits convert the mono cursor to 8bpp
|
---|
| 1159 | if(bmpXor.bmBitsPixel == 1)
|
---|
| 1160 | {
|
---|
| 1161 | bmpXor.bmBitsPixel = 8;
|
---|
| 1162 | bmpXor.bmWidthBytes *= 8;
|
---|
| 1163 | }
|
---|
| 1164 |
|
---|
[21964] | 1165 | // GetDIBits expectes DWORD-aligned scan lines
|
---|
[21951] | 1166 | bmpXor.bmWidthBytes = (bmpXor.bmWidthBytes + 3) / 4 * 4;
|
---|
| 1167 |
|
---|
[4573] | 1168 | if(bmpXor.bmBitsPixel <= 8) {
|
---|
| 1169 | colortablesize = sizeof(RGBQUAD)*(1<<bmpXor.bmBitsPixel);
|
---|
| 1170 | sizeXor = bmpXor.bmHeight * bmpXor.bmWidthBytes + colortablesize;
|
---|
| 1171 | }
|
---|
| 1172 | else sizeXor = bmpXor.bmHeight * bmpXor.bmWidthBytes;
|
---|
| 1173 |
|
---|
| 1174 | sizeAnd = bmpAnd.bmHeight * bmpAnd.bmWidthBytes;
|
---|
| 1175 |
|
---|
| 1176 | if (hObj) hObj = GlobalReAlloc( hObj,
|
---|
| 1177 | sizeof(CURSORICONINFO) + sizeXor + sizeAnd, GMEM_MOVEABLE );
|
---|
| 1178 | if (!hObj) hObj = GlobalAlloc( GMEM_MOVEABLE,
|
---|
| 1179 | sizeof(CURSORICONINFO) + sizeXor + sizeAnd );
|
---|
| 1180 | if (hObj)
|
---|
| 1181 | {
|
---|
| 1182 | CURSORICONINFO *info;
|
---|
| 1183 |
|
---|
| 1184 | info = (CURSORICONINFO *)GlobalLock( hObj );
|
---|
| 1185 | info->ptHotSpot.x = hotspot.x;
|
---|
| 1186 | info->ptHotSpot.y = hotspot.y;
|
---|
| 1187 | info->nWidth = bmpXor.bmWidth;
|
---|
| 1188 | info->nHeight = bmpXor.bmHeight;
|
---|
| 1189 | info->nWidthBytes = bmpXor.bmWidthBytes;
|
---|
| 1190 | info->bPlanes = bmpXor.bmPlanes;
|
---|
| 1191 | info->bBitsPerPixel = bmpXor.bmBitsPixel;
|
---|
[4612] | 1192 | info->hInstance = hInstance;
|
---|
| 1193 | info->dwResGroupId = dwResGroupId;
|
---|
[5385] | 1194 | info->hColorBmp = 0;
|
---|
[4573] | 1195 |
|
---|
| 1196 | /* Transfer the bitmap bits to the CURSORICONINFO structure */
|
---|
| 1197 | GetBitmapBits( hAndBits, sizeAnd, (char *)(info + 1));
|
---|
| 1198 |
|
---|
| 1199 | if(bmpXor.bmBitsPixel > 1)
|
---|
| 1200 | {
|
---|
| 1201 | BITMAPINFO* pInfo = (BITMAPINFO *)malloc(sizeof(BITMAPINFO)+colortablesize+3*sizeof(DWORD)); //+ extra space for > 8bpp images
|
---|
| 1202 | HBITMAP oldbmp;
|
---|
| 1203 |
|
---|
| 1204 | hdc = CreateCompatibleDC(0);
|
---|
| 1205 |
|
---|
[4584] | 1206 | memset(pInfo, 0, sizeof(BITMAPINFO)+colortablesize+3*sizeof(DWORD));
|
---|
[4573] | 1207 | pInfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
|
---|
| 1208 | pInfo->bmiHeader.biPlanes = info->bPlanes;
|
---|
| 1209 | pInfo->bmiHeader.biBitCount = info->bBitsPerPixel;
|
---|
| 1210 |
|
---|
| 1211 | GetDIBits(hdc, hXorBits, 0, bmpXor.bmHeight, (char *)(info + 1) + sizeAnd + colortablesize, pInfo, DIB_RGB_COLORS);
|
---|
| 1212 | if(colortablesize) {
|
---|
| 1213 | memcpy((char *)(info + 1) + sizeAnd, (char *)&pInfo->bmiHeader + pInfo->bmiHeader.biSize, colortablesize);
|
---|
| 1214 | }
|
---|
| 1215 |
|
---|
| 1216 | DeleteDC(hdc);
|
---|
| 1217 | free(pInfo);
|
---|
| 1218 | }
|
---|
| 1219 | else {
|
---|
| 1220 | GetBitmapBits( hXorBits, sizeXor, (char *)(info + 1) + sizeAnd);
|
---|
| 1221 | }
|
---|
[7043] | 1222 | info->hColorBmp = OSLibWinCreatePointer(info, (char*)(info + 1), (LPBITMAP_W)&bmpAnd, (char*)(info + 1) + sizeAnd, (LPBITMAP_W)&bmpXor, bIcon == FALSE);
|
---|
| 1223 |
|
---|
[6168] | 1224 | dprintf(("Create cursor/icon %x with OS/2 pointer handle %x", hObj, info->hColorBmp));
|
---|
[4573] | 1225 | GlobalUnlock( hObj );
|
---|
| 1226 | }
|
---|
| 1227 |
|
---|
| 1228 | DeleteObject( hAndBits );
|
---|
| 1229 | DeleteObject( hXorBits );
|
---|
[6183] | 1230 |
|
---|
| 1231 | #ifdef __WIN32OS2__
|
---|
| 1232 | if(hObj) {
|
---|
| 1233 | HICON hIcon;
|
---|
[8872] | 1234 | if(ObjAllocateHandle(&hIcon, (DWORD)hObj, HNDL_CURSORICON) == FALSE) {
|
---|
[6183] | 1235 | GlobalFree(hObj);
|
---|
| 1236 | dprintf(("ERROR: CURSORICON_Load ObjAllocateHandle failed!!"));
|
---|
| 1237 | return 0;
|
---|
| 1238 | }
|
---|
| 1239 | return hIcon;
|
---|
| 1240 | }
|
---|
| 1241 | #endif
|
---|
[4573] | 1242 | return hObj;
|
---|
[2469] | 1243 | }
|
---|
[4573] | 1244 |
|
---|
| 1245 | /**********************************************************************
|
---|
| 1246 | * CURSORICON_Destroy (USER.610)
|
---|
| 1247 | *
|
---|
| 1248 | * This routine is actually exported from Win95 USER under the name
|
---|
| 1249 | * DestroyIcon32 ... The behaviour implemented here should mimic
|
---|
| 1250 | * the Win95 one exactly, especially the return values, which
|
---|
| 1251 | * depend on the setting of various flags.
|
---|
| 1252 | */
|
---|
| 1253 | WORD WIN32API CURSORICON_Destroy( HGLOBAL handle, UINT flags )
|
---|
[2469] | 1254 | {
|
---|
[4573] | 1255 | WORD retv;
|
---|
[2469] | 1256 |
|
---|
[4573] | 1257 | /* Check whether destroying active cursor */
|
---|
| 1258 |
|
---|
| 1259 | if ( hActiveCursor == handle )
|
---|
[2469] | 1260 | {
|
---|
[5385] | 1261 | dprintf(("WARNING: Destroying active cursor!" ));
|
---|
[4573] | 1262 | SetCursor( 0 );
|
---|
| 1263 | }
|
---|
[5385] | 1264 |
|
---|
[6183] | 1265 | #ifdef __WIN32OS2__
|
---|
[8872] | 1266 | HICON hIcon = ObjQueryHandleData(handle, HNDL_CURSORICON);
|
---|
[6183] | 1267 | if(hIcon == -1) {
|
---|
| 1268 | dprintf(("ERROR: Invalid cursor/icon!"));
|
---|
| 1269 | return 0;
|
---|
| 1270 | }
|
---|
| 1271 | #endif
|
---|
| 1272 |
|
---|
[4573] | 1273 | /* Try shared cursor/icon first */
|
---|
| 1274 | if ( !(flags & CID_NONSHARED) )
|
---|
| 1275 | {
|
---|
| 1276 | INT count = CURSORICON_DelSharedIcon( handle );
|
---|
[2469] | 1277 |
|
---|
[4573] | 1278 | if ( count != -1 )
|
---|
| 1279 | return (flags & CID_WIN32)? TRUE : (count == 0);
|
---|
[2469] | 1280 |
|
---|
[4573] | 1281 | /* FIXME: OEM cursors/icons should be recognized */
|
---|
[2469] | 1282 | }
|
---|
[4573] | 1283 | /* Now assume non-shared cursor/icon */
|
---|
| 1284 |
|
---|
[5385] | 1285 | #ifdef __WIN32OS2__
|
---|
[6183] | 1286 | CURSORICONINFO *iconinfo = (CURSORICONINFO *)GlobalLock((HGLOBAL)hIcon);
|
---|
[5385] | 1287 | if (!iconinfo) {
|
---|
| 1288 | dprintf(("ERROR: Invalid cursor!"));
|
---|
| 1289 | return 0;
|
---|
| 1290 | }
|
---|
| 1291 |
|
---|
| 1292 | if(iconinfo->hColorBmp) {
|
---|
| 1293 | OSLibWinDestroyPointer(iconinfo->hColorBmp);
|
---|
| 1294 | }
|
---|
[6183] | 1295 | GlobalUnlock(hIcon);
|
---|
| 1296 | retv = GlobalFree( hIcon );
|
---|
[8872] | 1297 | ObjDeleteHandle(handle, HNDL_CURSORICON);
|
---|
[5385] | 1298 |
|
---|
[6183] | 1299 | return (flags & CID_RESOURCE)? retv : TRUE;
|
---|
| 1300 | #else
|
---|
[4573] | 1301 | retv = GlobalFree( handle );
|
---|
| 1302 | return (flags & CID_RESOURCE)? retv : TRUE;
|
---|
[6183] | 1303 | #endif
|
---|
[2469] | 1304 | }
|
---|
[4573] | 1305 |
|
---|
| 1306 | /***********************************************************************
|
---|
| 1307 | * CURSORICON_Copy
|
---|
| 1308 | *
|
---|
| 1309 | * Make a copy of a cursor or icon.
|
---|
| 1310 | */
|
---|
[4612] | 1311 | static HGLOBAL CURSORICON_Copy(HGLOBAL handle)
|
---|
[4573] | 1312 | {
|
---|
| 1313 | char *ptrOld, *ptrNew;
|
---|
| 1314 | int size;
|
---|
| 1315 | HGLOBAL hNew;
|
---|
| 1316 |
|
---|
[8872] | 1317 | handle = ObjQueryHandleData(handle, HNDL_CURSORICON);
|
---|
[6183] | 1318 | if(handle == -1) {
|
---|
| 1319 | dprintf(("ERROR: Invalid cursor/icon!"));
|
---|
| 1320 | return 0;
|
---|
| 1321 | }
|
---|
| 1322 |
|
---|
[4573] | 1323 | if (!(ptrOld = (char *)GlobalLock( handle ))) return 0;
|
---|
| 1324 |
|
---|
| 1325 | size = GlobalSize( handle );
|
---|
| 1326 | hNew = GlobalAlloc( GMEM_MOVEABLE, size );
|
---|
[6183] | 1327 | #ifdef __WIN32OS2__
|
---|
| 1328 | if(hNew == NULL) {
|
---|
| 1329 | dprintf(("ERROR: CURSORICON_Copy GlobalAlloc failed!!"));
|
---|
| 1330 | return NULL;
|
---|
| 1331 | }
|
---|
| 1332 | #endif
|
---|
[4573] | 1333 | ptrNew = (char *)GlobalLock( hNew );
|
---|
| 1334 | memcpy( ptrNew, ptrOld, size );
|
---|
| 1335 | GlobalUnlock( handle );
|
---|
| 1336 | GlobalUnlock( hNew );
|
---|
[6183] | 1337 |
|
---|
| 1338 | #ifdef __WIN32OS2__
|
---|
| 1339 | HICON hIcon;
|
---|
[8872] | 1340 | if(ObjAllocateHandle(&hIcon, (DWORD)hNew, HNDL_CURSORICON) == FALSE) {
|
---|
[6183] | 1341 | GlobalFree(hNew);
|
---|
| 1342 | dprintf(("ERROR: CURSORICON_Copy ObjAllocateHandle failed!!"));
|
---|
| 1343 | return 0;
|
---|
| 1344 | }
|
---|
| 1345 | return hIcon;
|
---|
| 1346 | #else
|
---|
[4573] | 1347 | return hNew;
|
---|
[6183] | 1348 | #endif
|
---|
[4573] | 1349 | }
|
---|
| 1350 |
|
---|
| 1351 | /*************************************************************************
|
---|
| 1352 | * CURSORICON_ExtCopy
|
---|
| 1353 | *
|
---|
| 1354 | * Copies an Image from the Cache if LR_COPYFROMRESOURCE is specified
|
---|
| 1355 | *
|
---|
| 1356 | * PARAMS
|
---|
| 1357 | * Handle [I] handle to an Image
|
---|
| 1358 | * nType [I] Type of Handle (IMAGE_CURSOR | IMAGE_ICON)
|
---|
| 1359 | * iDesiredCX [I] The Desired width of the Image
|
---|
| 1360 | * iDesiredCY [I] The desired height of the Image
|
---|
| 1361 | * nFlags [I] The flags from CopyImage
|
---|
| 1362 | *
|
---|
| 1363 | * RETURNS
|
---|
| 1364 | * Success: The new handle of the Image
|
---|
| 1365 | *
|
---|
| 1366 | * NOTES
|
---|
| 1367 | * LR_COPYDELETEORG and LR_MONOCHROME are currently not implemented.
|
---|
| 1368 | * LR_MONOCHROME should be implemented by CURSORICON_CreateFromResource.
|
---|
| 1369 | * LR_COPYFROMRESOURCE will only work if the Image is in the Cache.
|
---|
| 1370 | *
|
---|
| 1371 | *
|
---|
| 1372 | */
|
---|
| 1373 | HGLOBAL CURSORICON_ExtCopy(HGLOBAL Handle, UINT nType,
|
---|
[4649] | 1374 | INT iDesiredCX, INT iDesiredCY,
|
---|
| 1375 | UINT nFlags)
|
---|
[4573] | 1376 | {
|
---|
| 1377 | HGLOBAL hNew=0;
|
---|
| 1378 |
|
---|
[6183] | 1379 | #ifdef __WIN32OS2__
|
---|
[8872] | 1380 | HICON hIcon = ObjQueryHandleData(Handle, HNDL_CURSORICON);
|
---|
[6183] | 1381 | if(hIcon == -1) {
|
---|
| 1382 | dprintf(("ERROR: Invalid cursor/icon!"));
|
---|
| 1383 | return 0;
|
---|
| 1384 | }
|
---|
| 1385 |
|
---|
| 1386 | #else
|
---|
[4573] | 1387 | if(Handle == 0)
|
---|
| 1388 | {
|
---|
[4649] | 1389 | return 0;
|
---|
[4573] | 1390 | }
|
---|
[6183] | 1391 | #endif
|
---|
[4612] | 1392 | /* Best Fit or Monochrome */
|
---|
| 1393 | if( (nFlags & LR_COPYFROMRESOURCE
|
---|
| 1394 | && (iDesiredCX > 0 || iDesiredCY > 0))
|
---|
| 1395 | || nFlags & LR_MONOCHROME)
|
---|
| 1396 | {
|
---|
[6183] | 1397 | #ifdef __WIN32OS2__
|
---|
| 1398 | ICONCACHE* pIconCache = CURSORICON_FindCache(hIcon);
|
---|
| 1399 | #else
|
---|
[5385] | 1400 | ICONCACHE* pIconCache = CURSORICON_FindCache(Handle);
|
---|
[6183] | 1401 | #endif
|
---|
[5385] | 1402 |
|
---|
| 1403 | /* Not Found in Cache, then do a straight copy
|
---|
| 1404 | */
|
---|
| 1405 | if(pIconCache == NULL)
|
---|
| 1406 | {
|
---|
| 1407 | #ifdef __WIN32OS2__
|
---|
| 1408 | hNew = CURSORICON_Copy(Handle);
|
---|
| 1409 | #else
|
---|
| 1410 | hNew = CURSORICON_Copy(0, Handle);
|
---|
| 1411 | #endif
|
---|
| 1412 | if(nFlags & LR_COPYFROMRESOURCE)
|
---|
| 1413 | {
|
---|
| 1414 | dprintf(("WARNING: LR_COPYFROMRESOURCE: Failed to load from cache\n"));
|
---|
| 1415 | }
|
---|
| 1416 | }
|
---|
| 1417 | else
|
---|
| 1418 | {
|
---|
[4612] | 1419 | int iTargetCY = iDesiredCY, iTargetCX = iDesiredCX;
|
---|
| 1420 | LPBYTE pBits;
|
---|
| 1421 | HANDLE hMem;
|
---|
| 1422 | HRSRC hRsrc;
|
---|
| 1423 | DWORD dwBytesInRes;
|
---|
| 1424 | WORD wResId;
|
---|
| 1425 | DWORD dwResGroupId;
|
---|
| 1426 | HINSTANCE hInstance;
|
---|
| 1427 | CURSORICONINFO *iconinfo;
|
---|
| 1428 | CURSORICONDIR *pDir;
|
---|
| 1429 | CURSORICONDIRENTRY *pDirEntry;
|
---|
| 1430 | BOOL bIsIcon = (nType == IMAGE_ICON);
|
---|
[4573] | 1431 |
|
---|
[6183] | 1432 | #ifdef __WIN32OS2__
|
---|
| 1433 | iconinfo = (CURSORICONINFO *)GlobalLock( hIcon );
|
---|
| 1434 | #else
|
---|
[4612] | 1435 | iconinfo = (CURSORICONINFO *)GlobalLock( Handle );
|
---|
[6183] | 1436 | #endif
|
---|
[4612] | 1437 | if(iconinfo == NULL) {
|
---|
| 1438 | dprintf(("ERROR: CURSORICON_ExtCopy invalid icon!"));
|
---|
| 1439 | }
|
---|
| 1440 | hInstance = iconinfo->hInstance;
|
---|
| 1441 | dwResGroupId = iconinfo->dwResGroupId;
|
---|
| 1442 | GlobalUnlock( Handle );
|
---|
| 1443 | if(dwResGroupId == -1) {
|
---|
[4689] | 1444 | //todo: if scaling is necessary..
|
---|
[4612] | 1445 | dprintf(("WARNING: no resource associated with icon/cursor -> copy without scaling!"));
|
---|
| 1446 | hNew = CURSORICON_Copy(Handle);
|
---|
[4665] | 1447 | return hNew;
|
---|
[4612] | 1448 | }
|
---|
| 1449 |
|
---|
| 1450 | /* Completing iDesiredCX CY for Monochrome Bitmaps if needed
|
---|
| 1451 | */
|
---|
| 1452 | if(((nFlags & LR_MONOCHROME) && !(nFlags & LR_COPYFROMRESOURCE))
|
---|
| 1453 | || (iDesiredCX == 0 && iDesiredCY == 0))
|
---|
| 1454 | {
|
---|
| 1455 | iDesiredCY = GetSystemMetrics(bIsIcon ? SM_CYICON : SM_CYCURSOR);
|
---|
| 1456 | iDesiredCX = GetSystemMetrics(bIsIcon ? SM_CXICON : SM_CXCURSOR);
|
---|
| 1457 | }
|
---|
| 1458 |
|
---|
| 1459 | /* Retreive the CURSORICONDIRENTRY
|
---|
| 1460 | */
|
---|
| 1461 | hRsrc = FindResourceW(hInstance, (LPWSTR)dwResGroupId, bIsIcon ? RT_GROUP_ICONW : RT_GROUP_CURSORW);
|
---|
[4689] | 1462 | if(!hRsrc) {
|
---|
| 1463 | goto notfound;
|
---|
| 1464 | }
|
---|
[4612] | 1465 |
|
---|
| 1466 | if (!(hMem = LoadResource( hInstance, hRsrc)))
|
---|
| 1467 | {
|
---|
[4689] | 1468 | goto notfound;
|
---|
[4612] | 1469 | }
|
---|
| 1470 | if (!(pDir = (CURSORICONDIR*)LockResource( hMem )))
|
---|
| 1471 | {
|
---|
[4689] | 1472 | goto notfound;
|
---|
[4612] | 1473 | }
|
---|
| 1474 |
|
---|
| 1475 | /* Find Best Fit
|
---|
| 1476 | */
|
---|
| 1477 | if(bIsIcon)
|
---|
| 1478 | {
|
---|
| 1479 | pDirEntry = (CURSORICONDIRENTRY *)CURSORICON_FindBestIcon(
|
---|
| 1480 | pDir, iDesiredCX, iDesiredCY, 256);
|
---|
| 1481 | }
|
---|
| 1482 | else
|
---|
| 1483 | {
|
---|
| 1484 | pDirEntry = (CURSORICONDIRENTRY *)CURSORICON_FindBestCursor(
|
---|
| 1485 | pDir, iDesiredCX, iDesiredCY, 1);
|
---|
| 1486 | }
|
---|
| 1487 |
|
---|
| 1488 | wResId = pDirEntry->wResId;
|
---|
| 1489 | dwBytesInRes = pDirEntry->dwBytesInRes;
|
---|
| 1490 | FreeResource(hMem);
|
---|
| 1491 |
|
---|
| 1492 | /* Get the Best Fit
|
---|
| 1493 | */
|
---|
| 1494 | if (!(hRsrc = FindResourceW(hInstance ,
|
---|
| 1495 | MAKEINTRESOURCEW(wResId), bIsIcon ? RT_ICONW : RT_CURSORW)))
|
---|
| 1496 | {
|
---|
[4689] | 1497 | goto notfound;
|
---|
[4612] | 1498 | }
|
---|
| 1499 | if (!(hMem = LoadResource( hInstance, hRsrc )))
|
---|
| 1500 | {
|
---|
[4689] | 1501 | goto notfound;
|
---|
[4612] | 1502 | }
|
---|
| 1503 |
|
---|
| 1504 | pBits = (LPBYTE)LockResource( hMem );
|
---|
| 1505 |
|
---|
[4649] | 1506 | if(nFlags & LR_DEFAULTSIZE)
|
---|
| 1507 | {
|
---|
| 1508 | iTargetCY = GetSystemMetrics(SM_CYICON);
|
---|
[4612] | 1509 | iTargetCX = GetSystemMetrics(SM_CXICON);
|
---|
[4649] | 1510 | }
|
---|
[4612] | 1511 |
|
---|
| 1512 | /* Create a New Icon with the proper dimension
|
---|
| 1513 | */
|
---|
| 1514 | hNew = CURSORICON_CreateFromResource( hInstance, dwResGroupId, 0, pBits, dwBytesInRes,
|
---|
| 1515 | bIsIcon, 0x00030000, iTargetCX, iTargetCY, nFlags);
|
---|
| 1516 | FreeResource(hMem);
|
---|
[5385] | 1517 | }
|
---|
[4612] | 1518 | }
|
---|
| 1519 | else
|
---|
| 1520 | {
|
---|
| 1521 | hNew = CURSORICON_Copy(Handle);
|
---|
| 1522 | }
|
---|
[4573] | 1523 | return hNew;
|
---|
[4689] | 1524 |
|
---|
| 1525 | notfound:
|
---|
| 1526 | dprintf(("WARNING: unable to find resource associated with icon/cursor -> copy without scaling!"));
|
---|
| 1527 | hNew = CURSORICON_Copy(Handle);
|
---|
| 1528 | return hNew;
|
---|
[4573] | 1529 | }
|
---|
| 1530 |
|
---|
[2469] | 1531 | /**********************************************************************
|
---|
| 1532 | * CURSORICON_FindBestIcon
|
---|
| 1533 | *
|
---|
| 1534 | * Find the icon closest to the requested size and number of colors.
|
---|
| 1535 | */
|
---|
| 1536 | static CURSORICONDIRENTRY *CURSORICON_FindBestIcon( CURSORICONDIR *dir, int width,
|
---|
| 1537 | int height, int colors )
|
---|
| 1538 | {
|
---|
| 1539 | int i;
|
---|
| 1540 | CURSORICONDIRENTRY *entry, *bestEntry = NULL;
|
---|
| 1541 | UINT iTotalDiff, iXDiff=0, iYDiff=0, iColorDiff;
|
---|
| 1542 | UINT iTempXDiff, iTempYDiff, iTempColorDiff;
|
---|
| 1543 |
|
---|
| 1544 | if (dir->idCount < 1)
|
---|
| 1545 | {
|
---|
| 1546 | dprintf(("Empty directory!\n" ));
|
---|
| 1547 | return NULL;
|
---|
| 1548 | }
|
---|
| 1549 | if (dir->idCount == 1) return &dir->idEntries[0]; /* No choice... */
|
---|
| 1550 |
|
---|
| 1551 | /* Find Best Fit */
|
---|
| 1552 | iTotalDiff = 0xFFFFFFFF;
|
---|
| 1553 | iColorDiff = 0xFFFFFFFF;
|
---|
| 1554 | for (i = 0, entry = &dir->idEntries[0]; i < dir->idCount; i++,entry++)
|
---|
[5385] | 1555 | {
|
---|
[2469] | 1556 | iTempXDiff = abs(width - entry->ResInfo.icon.bWidth);
|
---|
| 1557 | iTempYDiff = abs(height - entry->ResInfo.icon.bHeight);
|
---|
| 1558 |
|
---|
| 1559 | if(iTotalDiff > (iTempXDiff + iTempYDiff))
|
---|
| 1560 | {
|
---|
| 1561 | iXDiff = iTempXDiff;
|
---|
| 1562 | iYDiff = iTempYDiff;
|
---|
| 1563 | iTotalDiff = iXDiff + iYDiff;
|
---|
| 1564 | }
|
---|
[5385] | 1565 | }
|
---|
[2469] | 1566 |
|
---|
| 1567 | /* Find Best Colors for Best Fit */
|
---|
| 1568 | for (i = 0, entry = &dir->idEntries[0]; i < dir->idCount; i++,entry++)
|
---|
[5385] | 1569 | {
|
---|
[2469] | 1570 | if(abs(width - entry->ResInfo.icon.bWidth) == iXDiff &&
|
---|
| 1571 | abs(height - entry->ResInfo.icon.bHeight) == iYDiff)
|
---|
| 1572 | {
|
---|
[4649] | 1573 | #ifdef __WIN32OS2__
|
---|
| 1574 | iTempColorDiff = abs(colors - (1 << entry->wBitCount));
|
---|
| 1575 | #else
|
---|
[2469] | 1576 | iTempColorDiff = abs(colors - entry->ResInfo.icon.bColorCount);
|
---|
[4649] | 1577 | #endif
|
---|
[2469] | 1578 | if(iColorDiff > iTempColorDiff)
|
---|
[5385] | 1579 | {
|
---|
| 1580 | bestEntry = entry;
|
---|
[2469] | 1581 | iColorDiff = iTempColorDiff;
|
---|
[5385] | 1582 | }
|
---|
[2469] | 1583 | }
|
---|
| 1584 | }
|
---|
[4612] | 1585 | ////testestest
|
---|
| 1586 | dprintf(("CURSORICON_FindBestIcon (%d,%d) %d -> %d", width, height, colors, (bestEntry) ? bestEntry->wResId : 0));
|
---|
[2469] | 1587 | return bestEntry;
|
---|
| 1588 | }
|
---|
| 1589 |
|
---|
| 1590 |
|
---|
| 1591 | /**********************************************************************
|
---|
| 1592 | * CURSORICON_FindBestCursor
|
---|
| 1593 | *
|
---|
| 1594 | * Find the cursor closest to the requested size.
|
---|
| 1595 | * FIXME: parameter 'color' ignored and entries with more than 1 bpp
|
---|
| 1596 | * ignored too
|
---|
| 1597 | */
|
---|
| 1598 | static CURSORICONDIRENTRY *CURSORICON_FindBestCursor( CURSORICONDIR *dir,
|
---|
[5385] | 1599 | int width, int height, int color)
|
---|
[2469] | 1600 | {
|
---|
| 1601 | int i, maxwidth, maxheight;
|
---|
| 1602 | CURSORICONDIRENTRY *entry, *bestEntry = NULL;
|
---|
| 1603 |
|
---|
| 1604 | if (dir->idCount < 1)
|
---|
| 1605 | {
|
---|
| 1606 | dprintf(("Empty directory!\n" ));
|
---|
| 1607 | return NULL;
|
---|
| 1608 | }
|
---|
| 1609 | if (dir->idCount == 1) return &dir->idEntries[0]; /* No choice... */
|
---|
| 1610 |
|
---|
| 1611 | /* Double height to account for AND and XOR masks */
|
---|
| 1612 |
|
---|
| 1613 | height *= 2;
|
---|
| 1614 |
|
---|
| 1615 | /* First find the largest one smaller than or equal to the requested size*/
|
---|
| 1616 |
|
---|
| 1617 | maxwidth = maxheight = 0;
|
---|
| 1618 | for(i = 0,entry = &dir->idEntries[0]; i < dir->idCount; i++,entry++)
|
---|
| 1619 | if ((entry->ResInfo.cursor.wWidth <= width) && (entry->ResInfo.cursor.wHeight <= height) &&
|
---|
| 1620 | (entry->ResInfo.cursor.wWidth > maxwidth) && (entry->ResInfo.cursor.wHeight > maxheight) &&
|
---|
| 1621 | (entry->wBitCount == 1))
|
---|
| 1622 | {
|
---|
| 1623 | bestEntry = entry;
|
---|
| 1624 | maxwidth = entry->ResInfo.cursor.wWidth;
|
---|
| 1625 | maxheight = entry->ResInfo.cursor.wHeight;
|
---|
| 1626 | }
|
---|
| 1627 | if (bestEntry) return bestEntry;
|
---|
| 1628 |
|
---|
| 1629 | /* Now find the smallest one larger than the requested size */
|
---|
| 1630 |
|
---|
| 1631 | maxwidth = maxheight = 255;
|
---|
| 1632 | for(i = 0,entry = &dir->idEntries[0]; i < dir->idCount; i++,entry++)
|
---|
| 1633 | if ((entry->ResInfo.cursor.wWidth < maxwidth) && (entry->ResInfo.cursor.wHeight < maxheight) &&
|
---|
| 1634 | (entry->wBitCount == 1))
|
---|
| 1635 | {
|
---|
| 1636 | bestEntry = entry;
|
---|
| 1637 | maxwidth = entry->ResInfo.cursor.wWidth;
|
---|
| 1638 | maxheight = entry->ResInfo.cursor.wHeight;
|
---|
| 1639 | }
|
---|
| 1640 |
|
---|
| 1641 | return bestEntry;
|
---|
| 1642 | }
|
---|
| 1643 | /**********************************************************************
|
---|
[4573] | 1644 | * LookupIconIdFromDirectoryEx (USER.364)
|
---|
[2469] | 1645 | *
|
---|
| 1646 | * FIXME: exact parameter sizes
|
---|
| 1647 | */
|
---|
| 1648 | INT WIN32API LookupIconIdFromDirectoryEx(LPBYTE xdir, BOOL bIcon,
|
---|
| 1649 | INT width, INT height, UINT cFlag )
|
---|
| 1650 | {
|
---|
| 1651 | CURSORICONDIR *dir = (CURSORICONDIR*)xdir;
|
---|
| 1652 | UINT retVal = 0;
|
---|
| 1653 |
|
---|
| 1654 | dprintf(("LookupIconIdFromDirectoryEx %x %d (%d,%d)", xdir, bIcon, width, height));
|
---|
| 1655 | if( dir && !dir->idReserved && (dir->idType & 3) )
|
---|
| 1656 | {
|
---|
| 1657 | CURSORICONDIRENTRY* entry;
|
---|
| 1658 | HDC hdc;
|
---|
| 1659 | UINT palEnts;
|
---|
| 1660 | int colors;
|
---|
| 1661 | hdc = GetDC(0);
|
---|
| 1662 | palEnts = GetSystemPaletteEntries(hdc, 0, 0, NULL);
|
---|
| 1663 | if (palEnts == 0)
|
---|
| 1664 | palEnts = 256;
|
---|
| 1665 | colors = (cFlag & LR_MONOCHROME) ? 2 : palEnts;
|
---|
| 1666 |
|
---|
| 1667 | ReleaseDC(0, hdc);
|
---|
| 1668 |
|
---|
| 1669 | if( bIcon )
|
---|
| 1670 | entry = CURSORICON_FindBestIcon( dir, width, height, colors );
|
---|
| 1671 | else
|
---|
| 1672 | entry = CURSORICON_FindBestCursor( dir, width, height, 1);
|
---|
| 1673 |
|
---|
| 1674 | if( entry ) retVal = entry->wResId;
|
---|
| 1675 | }
|
---|
| 1676 | else dprintf(("invalid resource directory\n"));
|
---|
| 1677 | return retVal;
|
---|
| 1678 | }
|
---|
| 1679 | /**********************************************************************
|
---|
| 1680 | * LookupIconIdFromDirectory (USER32.379)
|
---|
| 1681 | */
|
---|
| 1682 | INT WIN32API LookupIconIdFromDirectory( LPBYTE dir, BOOL bIcon )
|
---|
| 1683 | {
|
---|
| 1684 | return LookupIconIdFromDirectoryEx( dir, bIcon,
|
---|
| 1685 | bIcon ? GetSystemMetrics(SM_CXICON) : GetSystemMetrics(SM_CXCURSOR),
|
---|
| 1686 | bIcon ? GetSystemMetrics(SM_CYICON) : GetSystemMetrics(SM_CYCURSOR), bIcon ? 0 : LR_MONOCHROME );
|
---|
| 1687 | }
|
---|
| 1688 | //******************************************************************************
|
---|
| 1689 | //******************************************************************************
|
---|
[5385] | 1690 |
|
---|
| 1691 | //ICON cache implementation (Wine code)
|
---|
| 1692 |
|
---|
| 1693 | /**********************************************************************
|
---|
| 1694 | * CURSORICON_FindSharedIcon
|
---|
| 1695 | */
|
---|
| 1696 | static HANDLE CURSORICON_FindSharedIcon( HMODULE hModule, HRSRC hRsrc )
|
---|
| 1697 | {
|
---|
| 1698 | HANDLE handle = 0;
|
---|
| 1699 | ICONCACHE *ptr;
|
---|
| 1700 |
|
---|
| 1701 | EnterCriticalSection( &IconCrst );
|
---|
| 1702 |
|
---|
| 1703 | for ( ptr = IconAnchor; ptr; ptr = ptr->next )
|
---|
| 1704 | if ( ptr->hModule == hModule && ptr->hRsrc == hRsrc )
|
---|
| 1705 | {
|
---|
| 1706 | ptr->count++;
|
---|
| 1707 | handle = ptr->handle;
|
---|
| 1708 | break;
|
---|
| 1709 | }
|
---|
| 1710 |
|
---|
| 1711 | LeaveCriticalSection( &IconCrst );
|
---|
| 1712 |
|
---|
| 1713 | return handle;
|
---|
| 1714 | }
|
---|
| 1715 |
|
---|
| 1716 | /*************************************************************************
|
---|
| 1717 | * CURSORICON_FindCache
|
---|
| 1718 | *
|
---|
| 1719 | * Given a handle, find the corresponding cache element
|
---|
| 1720 | *
|
---|
| 1721 | * PARAMS
|
---|
| 1722 | * Handle [I] handle to an Image
|
---|
| 1723 | *
|
---|
| 1724 | * RETURNS
|
---|
| 1725 | * Success: The cache entry
|
---|
| 1726 | * Failure: NULL
|
---|
| 1727 | *
|
---|
| 1728 | */
|
---|
| 1729 | static ICONCACHE* CURSORICON_FindCache(HANDLE handle)
|
---|
| 1730 | {
|
---|
| 1731 | ICONCACHE *ptr;
|
---|
| 1732 | ICONCACHE *pRet=NULL;
|
---|
| 1733 | BOOL IsFound = FALSE;
|
---|
| 1734 | int count;
|
---|
| 1735 |
|
---|
| 1736 | EnterCriticalSection( &IconCrst );
|
---|
| 1737 |
|
---|
| 1738 | for (count = 0, ptr = IconAnchor; ptr != NULL && !IsFound; ptr = ptr->next, count++ )
|
---|
| 1739 | {
|
---|
| 1740 | if ( handle == ptr->handle )
|
---|
| 1741 | {
|
---|
| 1742 | IsFound = TRUE;
|
---|
| 1743 | pRet = ptr;
|
---|
| 1744 | }
|
---|
| 1745 | }
|
---|
| 1746 |
|
---|
| 1747 | LeaveCriticalSection( &IconCrst );
|
---|
| 1748 |
|
---|
| 1749 | return pRet;
|
---|
| 1750 | }
|
---|
| 1751 |
|
---|
| 1752 | /**********************************************************************
|
---|
| 1753 | * CURSORICON_AddSharedIcon
|
---|
| 1754 | */
|
---|
| 1755 | static void CURSORICON_AddSharedIcon( HMODULE hModule, HRSRC hRsrc, HRSRC hGroupRsrc, HANDLE handle )
|
---|
| 1756 | {
|
---|
| 1757 | ICONCACHE *ptr = (ICONCACHE *)HeapAlloc( GetProcessHeap(), 0, sizeof(ICONCACHE) );
|
---|
| 1758 | if ( !ptr ) return;
|
---|
| 1759 |
|
---|
| 1760 | ptr->hModule = hModule;
|
---|
| 1761 | ptr->hRsrc = hRsrc;
|
---|
| 1762 | ptr->handle = handle;
|
---|
| 1763 | ptr->hGroupRsrc = hGroupRsrc;
|
---|
| 1764 | ptr->count = 1;
|
---|
| 1765 |
|
---|
| 1766 | EnterCriticalSection( &IconCrst );
|
---|
| 1767 | ptr->next = IconAnchor;
|
---|
| 1768 | IconAnchor = ptr;
|
---|
| 1769 | LeaveCriticalSection( &IconCrst );
|
---|
| 1770 | }
|
---|
| 1771 |
|
---|
| 1772 | /**********************************************************************
|
---|
| 1773 | * CURSORICON_DelSharedIcon
|
---|
| 1774 | */
|
---|
| 1775 | static INT CURSORICON_DelSharedIcon( HANDLE handle )
|
---|
| 1776 | {
|
---|
| 1777 | INT count = -1;
|
---|
| 1778 | ICONCACHE *ptr;
|
---|
| 1779 |
|
---|
| 1780 | EnterCriticalSection( &IconCrst );
|
---|
| 1781 |
|
---|
| 1782 | for ( ptr = IconAnchor; ptr; ptr = ptr->next )
|
---|
| 1783 | if ( ptr->handle == handle )
|
---|
| 1784 | {
|
---|
| 1785 | if ( ptr->count > 0 ) ptr->count--;
|
---|
| 1786 | count = ptr->count;
|
---|
| 1787 | break;
|
---|
| 1788 | }
|
---|
| 1789 |
|
---|
| 1790 | LeaveCriticalSection( &IconCrst );
|
---|
| 1791 |
|
---|
| 1792 | return count;
|
---|
| 1793 | }
|
---|
| 1794 |
|
---|
| 1795 | /**********************************************************************
|
---|
| 1796 | * CURSORICON_FreeModuleIcons
|
---|
| 1797 | */
|
---|
| 1798 | void CURSORICON_FreeModuleIcons( HMODULE hModule )
|
---|
| 1799 | {
|
---|
| 1800 | ICONCACHE **ptr = &IconAnchor;
|
---|
| 1801 |
|
---|
| 1802 | EnterCriticalSection( &IconCrst );
|
---|
| 1803 |
|
---|
| 1804 | while ( *ptr )
|
---|
| 1805 | {
|
---|
| 1806 | if ( (*ptr)->hModule == hModule )
|
---|
| 1807 | {
|
---|
| 1808 | ICONCACHE *freePtr = *ptr;
|
---|
| 1809 | *ptr = freePtr->next;
|
---|
| 1810 |
|
---|
| 1811 | #ifdef __WIN32OS2__
|
---|
| 1812 | CURSORICON_Destroy(freePtr->handle, CID_NONSHARED);
|
---|
| 1813 | #else
|
---|
| 1814 | GlobalFree( freePtr->handle );
|
---|
| 1815 | #endif
|
---|
| 1816 | HeapFree( GetProcessHeap(), 0, freePtr );
|
---|
| 1817 | continue;
|
---|
| 1818 | }
|
---|
| 1819 | ptr = &(*ptr)->next;
|
---|
| 1820 | }
|
---|
| 1821 |
|
---|
| 1822 | LeaveCriticalSection( &IconCrst );
|
---|
| 1823 | }
|
---|
| 1824 |
|
---|