Changeset 2160 for trunk/src/user32/winicon.cpp
- Timestamp:
- Dec 20, 1999, 5:45:18 PM (26 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/user32/winicon.cpp
r1810 r2160 1 /* $Id: winicon.cpp,v 1. 5 1999-11-22 20:33:25 sandervlExp $ */1 /* $Id: winicon.cpp,v 1.6 1999-12-20 16:45:18 cbratschi Exp $ */ 2 2 /* 3 3 * Win32 Icon Code for OS/2 … … 70 70 71 71 dprintf(("USER32: CreateIconIndirect\n")); 72 if(pIcon->hbmMask && pIcon->hbmColor) 73 { 74 75 76 77 78 79 80 81 72 if(pIcon->hbmMask && pIcon->hbmColor) 73 { 74 ICONINFO iconinfo; 75 SIZE bmpsize; 76 77 iconinfo = *pIcon; 78 if(GetBitmapDimensionEx(pIcon->hbmColor, &bmpsize) == FALSE) { 79 return 0; 80 } 81 //if there's a color bitmap, the mask bitmap contains only the AND bits 82 82 //Open32 calls WinCreatePointerIndirect which expects AND & XOR bits 83 83 //To solve this we create a bitmap that's 2x height of the mask, copy 84 84 //the AND bits and set the XOR bits to 0 85 86 87 88 89 90 91 85 hdcSrc = CreateCompatibleDC(0); 86 hdcDst = CreateCompatibleDC(0); 87 88 iconinfo.hbmMask = CreateCompatibleBitmap (hdcDst, bmpsize.cx, bmpsize.cy*2); 89 SelectObject (hdcDst, iconinfo.hbmMask); 90 SelectObject (hdcSrc, pIcon->hbmMask); 91 BitBlt (hdcDst, 0, 0, bmpsize.cx, bmpsize.cy, 92 92 hdcSrc, 0, 0, SRCCOPY); 93 94 95 96 97 98 99 100 101 93 PatBlt (hdcDst, bmpsize.cx, bmpsize.cy, bmpsize.cx, bmpsize.cy, BLACKNESS); 94 95 hIcon = O32_CreateIconIndirect(&iconinfo); 96 97 DeleteObject(iconinfo.hbmMask); 98 DeleteDC(hdcSrc); 99 DeleteDC(hdcDst); 100 101 return hIcon; 102 102 } 103 103 hIcon = O32_CreateIconIndirect(pIcon); 104 104 if(hIcon == 0) { 105 105 dprintf(("CreateIconIndirect %d (%d,%d) %x %x failed with %x", pIcon->fIcon, pIcon->xHotspot, pIcon->yHotspot, pIcon->hbmMask, pIcon->hbmColor, GetLastError())); 106 106 } 107 107 return hIcon; … … 115 115 BITMAP bmp; 116 116 117 if(pIcon->hbmMask && pIcon->hbmColor) 118 { 119 120 121 122 123 124 125 117 if(pIcon->hbmMask && pIcon->hbmColor) 118 { 119 ICONINFO iconinfo; 120 HBITMAP hbmOldSrc, hbmOldDst; 121 122 iconinfo = *pIcon; 123 GetObjectA(pIcon->hbmColor, sizeof(BITMAP), (LPVOID)&bmp); 124 125 //if there's a color bitmap, the mask bitmap contains only the AND bits 126 126 //Open32 calls WinCreatePointerIndirect which expects AND & XOR bits 127 127 //To solve this we create a bitmap that's 2x height of the mask, copy 128 128 //the AND bits and set the XOR bits to 0 129 130 131 132 133 134 135 136 StretchBlt(hdcDst, 0, 0, desiredX, desiredY, hdcSrc, 0, 0, 129 hdcSrc = CreateCompatibleDC(0); 130 hdcDst = CreateCompatibleDC(0); 131 132 iconinfo.hbmMask = CreateCompatibleBitmap (hdcDst, desiredX, desiredY*2); 133 hbmOldDst = SelectObject (hdcDst, iconinfo.hbmMask); 134 hbmOldSrc = SelectObject (hdcSrc, pIcon->hbmMask); 135 if(desiredX != bmp.bmWidth || desiredY != bmp.bmHeight) { 136 StretchBlt(hdcDst, 0, 0, desiredX, desiredY, hdcSrc, 0, 0, 137 137 bmp.bmWidth, bmp.bmHeight, SRCCOPY); 138 139 140 141 142 143 144 145 146 147 148 149 StretchBlt(hdcDst, 0, 0, desiredX, desiredY, hdcSrc, 0, 0, 138 } 139 else { 140 BitBlt (hdcDst, 0, 0, bmp.bmWidth, bmp.bmHeight, 141 hdcSrc, 0, 0, SRCCOPY); 142 } 143 PatBlt (hdcDst, desiredX, desiredY, desiredX, desiredY, BLACKNESS); 144 145 if(desiredX != bmp.bmWidth || desiredY != bmp.bmHeight) { 146 iconinfo.hbmColor = CreateCompatibleBitmap (hdcDst, desiredX, desiredY); 147 SelectObject (hdcDst, iconinfo.hbmColor); 148 SelectObject (hdcSrc, pIcon->hbmColor); 149 StretchBlt(hdcDst, 0, 0, desiredX, desiredY, hdcSrc, 0, 0, 150 150 bmp.bmWidth, bmp.bmHeight, SRCCOPY); 151 152 153 154 155 156 157 158 159 160 161 162 163 164 151 } 152 153 hIcon = O32_CreateIconIndirect(&iconinfo); 154 155 DeleteObject(iconinfo.hbmMask); 156 if(desiredX != bmp.bmWidth || desiredY != bmp.bmHeight) { 157 DeleteObject(iconinfo.hbmColor); 158 } 159 SelectObject (hdcDst, hbmOldDst); 160 SelectObject (hdcSrc, hbmOldSrc); 161 DeleteDC(hdcSrc); 162 DeleteDC(hdcDst); 163 164 return hIcon; 165 165 } 166 166 hIcon = O32_CreateIconIndirect(pIcon); 167 167 if(hIcon == 0) { 168 168 dprintf(("CreateIconIndirect %d (%d,%d) %x %x failed with %x", pIcon->fIcon, pIcon->xHotspot, pIcon->yHotspot, pIcon->hbmMask, pIcon->hbmColor, GetLastError())); 169 169 } 170 170 return hIcon; … … 189 189 //In Windows, the mask only contains the AND data if there's a color bitmap 190 190 //--->> We're allocating a bitmap to replace the mask bitmap, but DON'T DELETE it! 191 //WARNING: MEMORY LEAK &DIRTY HACK TO WORK AROUND OPEN32 BUG191 //WARNING: DIRTY HACK TO WORK AROUND OPEN32 BUG 192 192 //****************************************************************************** 193 193 BOOL WIN32API GetIconInfo( HICON hIcon, LPICONINFO pIconInfo) … … 199 199 dprintf(("USER32: GetIconInfo %x", hIcon)); 200 200 rc = O32_GetIconInfo(hIcon, pIconInfo); 201 #if 0 202 if(rc && pIconInfo->hbmColor) 203 { 204 HDC hdcSrc, hdcDst; 205 hdcSrc = CreateCompatibleDC(0); 206 hdcDst = CreateCompatibleDC(0); 207 208 GetObjectA(pIconInfo->hbmMask, sizeof(BITMAP), (LPVOID)&bmp); 209 210 hbmMask = CreateCompatibleBitmap (hdcDst, bmp.bmWidth, bmp.bmHeight/2); 211 hbmOldDst = SelectObject (hdcDst, hbmMask); 212 hbmOldSrc = SelectObject (hdcSrc, pIconInfo->hbmMask); 213 BitBlt (hdcDst, 0, 0, bmp.bmWidth, bmp.bmHeight/2, 214 hdcSrc, 0, bmp.bmHeight/2, SRCCOPY); 215 216 SelectObject(hdcDst, hbmOldDst); 217 SelectObject(hdcSrc, hbmOldSrc); 218 DeleteDC(hdcDst); 219 DeleteDC(hdcSrc); 220 pIconInfo->hbmMask = hbmMask; 201 #if 1 202 if(rc && pIconInfo->hbmColor) 203 { 204 HDC hdcSrc, hdcDst; 205 hdcSrc = CreateCompatibleDC(0); 206 hdcDst = CreateCompatibleDC(0); 207 208 GetObjectA(pIconInfo->hbmColor, sizeof(BITMAP), (LPVOID)&bmp); 209 210 hbmMask = CreateCompatibleBitmap (hdcDst, bmp.bmWidth, bmp.bmHeight); 211 hbmOldDst = SelectObject (hdcDst, hbmMask); 212 hbmOldSrc = SelectObject (hdcSrc, pIconInfo->hbmMask); 213 BitBlt (hdcDst, 0, 0, bmp.bmWidth, bmp.bmHeight, 214 hdcSrc, 0, 0, SRCCOPY); 215 216 SelectObject(hdcDst, hbmOldDst); 217 SelectObject(hdcSrc, hbmOldSrc); 218 DeleteDC(hdcDst); 219 DeleteDC(hdcSrc); 220 DeleteObject(pIconInfo->hbmMask); 221 pIconInfo->hbmMask = hbmMask; 221 222 } 222 223 #endif … … 224 225 } 225 226 /********************************************************************** 226 * 227 * CURSORICON_FindBestIcon 227 228 * 228 229 * Find the icon closest to the requested size and number of colors. … … 231 232 int height, int colors ) 232 233 { 233 int i; 234 int i; 234 235 CURSORICONDIRENTRY *entry, *bestEntry = NULL; 235 236 UINT iTotalDiff, iXDiff=0, iYDiff=0, iColorDiff; … … 248 249 for (i = 0, entry = &dir->idEntries[0]; i < dir->idCount; i++,entry++) 249 250 { 250 251 251 iTempXDiff = abs(width - entry->ResInfo.icon.bWidth); 252 iTempYDiff = abs(height - entry->ResInfo.icon.bHeight); 252 253 253 254 if(iTotalDiff > (iTempXDiff + iTempYDiff)) … … 255 256 iXDiff = iTempXDiff; 256 257 iYDiff = iTempYDiff; 257 258 iTotalDiff = iXDiff + iYDiff; 258 259 } 259 260 } … … 279 280 280 281 /********************************************************************** 281 * 282 * CURSORICON_FindBestCursor 282 283 * 283 284 * Find the cursor closest to the requested size. … … 308 309 if ((entry->ResInfo.cursor.wWidth <= width) && (entry->ResInfo.cursor.wHeight <= height) && 309 310 (entry->ResInfo.cursor.wWidth > maxwidth) && (entry->ResInfo.cursor.wHeight > maxheight) && 310 311 (entry->wBitCount == 1)) 311 312 { 312 313 bestEntry = entry; … … 321 322 for(i = 0,entry = &dir->idEntries[0]; i < dir->idCount; i++,entry++) 322 323 if ((entry->ResInfo.cursor.wWidth < maxwidth) && (entry->ResInfo.cursor.wHeight < maxheight) && 323 324 (entry->wBitCount == 1)) 324 325 { 325 326 bestEntry = entry; … … 331 332 } 332 333 /********************************************************************** 333 * LookupIconIdFromDirectoryEx16 334 * LookupIconIdFromDirectoryEx16 (USER.364) 334 335 * 335 336 * FIXME: exact parameter sizes 336 337 */ 337 338 INT WIN32API LookupIconIdFromDirectoryEx(LPBYTE xdir, BOOL bIcon, 338 339 { 340 CURSORICONDIR 339 INT width, INT height, UINT cFlag ) 340 { 341 CURSORICONDIR *dir = (CURSORICONDIR*)xdir; 341 342 UINT retVal = 0; 342 343 … … 344 345 if( dir && !dir->idReserved && (dir->idType & 3) ) 345 346 { 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 347 CURSORICONDIRENTRY* entry; 348 HDC hdc; 349 UINT palEnts; 350 int colors; 351 hdc = GetDC(0); 352 palEnts = GetSystemPaletteEntries(hdc, 0, 0, NULL); 353 if (palEnts == 0) 354 palEnts = 256; 355 colors = (cFlag & LR_MONOCHROME) ? 2 : palEnts; 356 357 ReleaseDC(0, hdc); 358 359 if( bIcon ) 360 entry = CURSORICON_FindBestIcon( dir, width, height, colors ); 361 else 362 entry = CURSORICON_FindBestCursor( dir, width, height, 1); 363 364 if( entry ) retVal = entry->wResId; 364 365 } 365 366 else dprintf(("invalid resource directory\n")); … … 367 368 } 368 369 /********************************************************************** 369 * LookupIconIdFromDirectory 370 * LookupIconIdFromDirectory (USER32.379) 370 371 */ 371 372 INT WIN32API LookupIconIdFromDirectory( LPBYTE dir, BOOL bIcon ) 372 373 { 373 return LookupIconIdFromDirectoryEx( dir, bIcon, 374 375 374 return LookupIconIdFromDirectoryEx( dir, bIcon, 375 bIcon ? GetSystemMetrics(SM_CXICON) : GetSystemMetrics(SM_CXCURSOR), 376 bIcon ? GetSystemMetrics(SM_CYICON) : GetSystemMetrics(SM_CYCURSOR), bIcon ? 0 : LR_MONOCHROME ); 376 377 } 377 378 /************************************************************************* 378 * CURSORICON_ExtCopy 379 * CURSORICON_ExtCopy 379 380 * 380 381 * Copies an Image from the Cache if LR_COPYFROMRESOURCE is specified 381 382 * 382 383 * PARAMS 383 * Handle [I] handle to an Image 384 * Handle [I] handle to an Image 384 385 * nType [I] Type of Handle (IMAGE_CURSOR | IMAGE_ICON) 385 386 * iDesiredCX [I] The Desired width of the Image … … 395 396 * LR_COPYFROMRESOURCE will only work if the Image is in the Cache. 396 397 * 397 * 398 * 398 399 * TODO: LR_COPYFROMRESOURCE doesn't work. Uses supplied icon instead 399 400 * 400 401 */ 401 HGLOBAL CopyCursorIcon(HGLOBAL Handle, UINT nType, 402 INT iDesiredCX, INT iDesiredCY,403 402 HGLOBAL CopyCursorIcon(HGLOBAL Handle, UINT nType, 403 INT iDesiredCX, INT iDesiredCY, 404 UINT nFlags) 404 405 { 405 406 HGLOBAL hNew=0; … … 408 409 if(Handle == 0) 409 410 { 410 411 return 0; 411 412 } 412 413 … … 414 415 if(!bIsIcon || (nFlags & LR_COPYFROMRESOURCE 415 416 && (iDesiredCX > 0 || iDesiredCY > 0)) 416 || nFlags & LR_MONOCHROME) 417 || nFlags & LR_MONOCHROME) 417 418 { 418 419 LPBYTE pBits; … … 429 430 || (iDesiredCX == 0 && iDesiredCY == 0)) 430 431 { 431 iDesiredCY = GetSystemMetrics(bIsIcon ? 432 iDesiredCY = GetSystemMetrics(bIsIcon ? 432 433 SM_CYICON : SM_CYCURSOR); 433 iDesiredCX = GetSystemMetrics(bIsIcon ? 434 iDesiredCX = GetSystemMetrics(bIsIcon ? 434 435 SM_CXICON : SM_CXCURSOR); 435 436 } 436 437 437 438 /* Create a New Icon with the proper dimension 438 439 */ 439 440 441 440 ICONINFO iconinfo; 441 442 GetIconInfo(Handle, &iconinfo); 442 443 hNew = CreateIconIndirect(&iconinfo, bIsIcon, iDesiredCX, iDesiredCY, nFlags); 443 444 } 444 445 else 445 446 { 446 447 448 449 elsereturn CopyCursor(Handle);447 if(bIsIcon) { 448 return CopyIcon(Handle); 449 } 450 else return CopyCursor(Handle); 450 451 } 451 452 return hNew;
Note:
See TracChangeset
for help on using the changeset viewer.