Changeset 1749 for trunk/src/user32/winicon.cpp
- Timestamp:
- Nov 15, 1999, 12:29:25 AM (26 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/user32/winicon.cpp
r1739 r1749 1 /* $Id: winicon.cpp,v 1. 3 1999-11-14 16:35:58sandervl Exp $ */1 /* $Id: winicon.cpp,v 1.4 1999-11-14 23:29:25 sandervl Exp $ */ 2 2 /* 3 3 * Win32 Icon Code for OS/2 … … 6 6 * Copyright 1998 Sander van Leeuwen (sandervl@xs4all.nl) 7 7 * 8 * LookupIconIdFromDirectory(Ex) (+help functions) ported from Wine (991031) 9 * 10 * Copyright 1995 Alexandre Julliard 8 * Parts based on Wine code (objects\bitmap.c, loader\resource.c, objects\cursoricon.c): 9 * 10 * Copyright 1993 Alexandre Julliard 11 * 1993 Robert J. Amstadt 11 12 * 1996 Martin Von Loewis 12 13 * 1997 Alex Korobka 13 14 * 1998 Turchanov Sergey 15 * 1998 Huw D M Davies 14 16 * 15 17 * Project Odin Software License can be found in LICENSE.TXT … … 88 90 SelectObject (hdcSrc, pIcon->hbmMask); 89 91 BitBlt (hdcDst, 0, 0, bmpsize.cx, bmpsize.cy, 90 hdcSrc, bmpsize.cx, 0, SRCCOPY);92 hdcSrc, 0, 0, SRCCOPY); 91 93 PatBlt (hdcDst, bmpsize.cx, bmpsize.cy, bmpsize.cx, bmpsize.cy, BLACKNESS); 92 94 … … 107 109 //****************************************************************************** 108 110 //****************************************************************************** 109 BOOL WIN32API DestroyIcon( HICON arg1) 110 { 111 #ifdef DEBUG 112 WriteLog("USER32: DestroyIcon\n"); 111 HICON CreateIconIndirect(LPICONINFO pIcon, BOOL bIsIcon, int desiredX, int desiredY, DWORD flags) 112 { 113 HICON hIcon; 114 HDC hdcSrc, hdcDst; 115 BITMAP bmp; 116 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 //Open32 calls WinCreatePointerIndirect which expects AND & XOR bits 127 //To solve this we create a bitmap that's 2x height of the mask, copy 128 //the AND bits and set the XOR bits to 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 bmp.bmWidth, bmp.bmHeight, SRCCOPY); 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 bmp.bmWidth, bmp.bmHeight, SRCCOPY); 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 } 166 hIcon = O32_CreateIconIndirect(pIcon); 167 if(hIcon == 0) { 168 dprintf(("CreateIconIndirect %d (%d,%d) %x %x failed with %x", pIcon->fIcon, pIcon->xHotspot, pIcon->yHotspot, pIcon->hbmMask, pIcon->hbmColor, GetLastError())); 169 } 170 return hIcon; 171 } 172 //****************************************************************************** 173 //****************************************************************************** 174 BOOL WIN32API DestroyIcon( HICON hIcon) 175 { 176 dprintf(("USER32: DestroyIcon %x", hIcon)); 177 return O32_DestroyIcon(hIcon); 178 } 179 //****************************************************************************** 180 //****************************************************************************** 181 HICON WIN32API CopyIcon( HICON hIcon) 182 { 183 dprintf(("USER32: CopyIcon %x", hIcon)); 184 return O32_CopyIcon(hIcon); 185 } 186 //****************************************************************************** 187 //WARNING: MEMORY LEAK & DIRTY HACK TO WORK AROUND OPEN32 BUG 188 //OS/2 icon masks must be twice the height of the color bitmap 189 //In Windows, the mask only contains the AND data if there's a color bitmap 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 BUG 192 //****************************************************************************** 193 BOOL WIN32API GetIconInfo( HICON hIcon, LPICONINFO pIconInfo) 194 { 195 BOOL rc; 196 HBITMAP hbmMask, hbmOldSrc, hbmOldDst; 197 BITMAP bmp; 198 199 dprintf(("USER32: GetIconInfo %x", hIcon)); 200 rc = O32_GetIconInfo(hIcon, pIconInfo); 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->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; 221 } 113 222 #endif 114 return O32_DestroyIcon(arg1); 115 } 116 //****************************************************************************** 117 //****************************************************************************** 118 HICON WIN32API CopyIcon( HICON arg1) 119 { 120 #ifdef DEBUG 121 WriteLog("USER32: CopyIcon\n"); 122 #endif 123 return O32_CopyIcon(arg1); 124 } 125 //****************************************************************************** 126 //****************************************************************************** 127 BOOL WIN32API GetIconInfo( HICON arg1, LPICONINFO arg2) 128 { 129 #ifdef DEBUG 130 WriteLog("USER32: GetIconInfo\n"); 131 #endif 132 return O32_GetIconInfo(arg1, arg2); 223 return rc; 133 224 } 134 225 /********************************************************************** … … 284 375 bIcon ? GetSystemMetrics(SM_CYICON) : GetSystemMetrics(SM_CYCURSOR), bIcon ? 0 : LR_MONOCHROME ); 285 376 } 286 //****************************************************************************** 287 //****************************************************************************** 377 /************************************************************************* 378 * CURSORICON_ExtCopy 379 * 380 * Copies an Image from the Cache if LR_COPYFROMRESOURCE is specified 381 * 382 * PARAMS 383 * Handle [I] handle to an Image 384 * nType [I] Type of Handle (IMAGE_CURSOR | IMAGE_ICON) 385 * iDesiredCX [I] The Desired width of the Image 386 * iDesiredCY [I] The desired height of the Image 387 * nFlags [I] The flags from CopyImage 388 * 389 * RETURNS 390 * Success: The new handle of the Image 391 * 392 * NOTES 393 * LR_COPYDELETEORG and LR_MONOCHROME are currently not implemented. 394 * LR_MONOCHROME should be implemented by CURSORICON_CreateFromResource. 395 * LR_COPYFROMRESOURCE will only work if the Image is in the Cache. 396 * 397 * 398 * TODO: LR_COPYFROMRESOURCE doesn't work. Uses supplied icon instead 399 * 400 */ 401 HGLOBAL CopyCursorIcon(HGLOBAL Handle, UINT nType, 402 INT iDesiredCX, INT iDesiredCY, 403 UINT nFlags) 404 { 405 HGLOBAL hNew=0; 406 BOOL bIsIcon = (nType == IMAGE_ICON); 407 408 if(Handle == 0) 409 { 410 return 0; 411 } 412 413 /* Best Fit or Monochrome */ 414 if(!bIsIcon || (nFlags & LR_COPYFROMRESOURCE 415 && (iDesiredCX > 0 || iDesiredCY > 0)) 416 || nFlags & LR_MONOCHROME) 417 { 418 LPBYTE pBits; 419 HANDLE hMem; 420 HRSRC hRsrc; 421 DWORD dwBytesInRes; 422 WORD wResId; 423 CURSORICONDIR *pDir; 424 CURSORICONDIRENTRY *pDirEntry; 425 426 /* Completing iDesiredCX CY for Monochrome Bitmaps if needed 427 */ 428 if(((nFlags & LR_MONOCHROME) && !(nFlags & LR_COPYFROMRESOURCE)) 429 || (iDesiredCX == 0 && iDesiredCY == 0)) 430 { 431 iDesiredCY = GetSystemMetrics(bIsIcon ? 432 SM_CYICON : SM_CYCURSOR); 433 iDesiredCX = GetSystemMetrics(bIsIcon ? 434 SM_CXICON : SM_CXCURSOR); 435 } 436 437 /* Create a New Icon with the proper dimension 438 */ 439 ICONINFO iconinfo; 440 441 GetIconInfo(Handle, &iconinfo); 442 hNew = CreateIconIndirect(&iconinfo, bIsIcon, iDesiredCX, iDesiredCY, nFlags); 443 } 444 else 445 { 446 if(bIsIcon) { 447 return CopyIcon(Handle); 448 } 449 else return CopyCursor(Handle); 450 } 451 return hNew; 452 } 453 //****************************************************************************** 454 //******************************************************************************
Note:
See TracChangeset
for help on using the changeset viewer.