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