2 * ImageList implementation
4 * Copyright 1998 Eric Kohl
5 * Copyright 2000 Jason Mawdsley
6 * Copyright 2001, 2004 Michael Stefaniuc
7 * Copyright 2001 Charles Loep for CodeWeavers
8 * Copyright 2002 Dimitrie O. Paun
9 * Copyright 2009 Owen Rudge for CodeWeavers
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public
13 * License as published by the Free Software Foundation; either
14 * version 2.1 of the License, or (at your option) any later version.
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with this library; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
27 * This code was audited for completeness against the documented features
28 * of Comctl32.dll version 6.0 on Sep. 12, 2002, by Dimitrie O. Paun.
30 * Unless otherwise noted, we believe this code to be complete, as per
31 * the specification mentioned above.
32 * If you discover missing features, or bugs, please note them below.
35 * - Add support for ILD_PRESERVEALPHA, ILD_SCALE, ILD_DPISCALE
36 * - Add support for ILS_GLOW, ILS_SHADOW, ILS_SATURATE
37 * - Thread-safe locking
54 #include "commoncontrols.h"
55 #include "imagelist.h"
56 #include "wine/debug.h"
58 WINE_DEFAULT_DEBUG_CHANNEL(imagelist);
61 #define MAX_OVERLAYIMAGE 15
63 /* internal image list data used for Drag & Drop operations */
68 /* position of the drag image relative to the window */
71 /* offset of the hotspot relative to the origin of the image */
74 /* is the drag image visible */
76 /* saved background */
80 static INTERNALDRAG InternalDrag = { 0, 0, 0, 0, 0, 0, FALSE, 0 };
82 static HBITMAP ImageList_CreateImage(HDC hdc, HIMAGELIST himl, UINT count);
83 static HRESULT ImageListImpl_CreateInstance(const IUnknown *pUnkOuter, REFIID iid, void** ppv);
84 static inline BOOL is_valid(HIMAGELIST himl);
87 * An imagelist with N images is tiled like this:
99 static inline UINT imagelist_height( UINT count )
101 return ((count + TILE_COUNT - 1)/TILE_COUNT);
104 static inline void imagelist_point_from_index( HIMAGELIST himl, UINT index, LPPOINT pt )
106 pt->x = (index%TILE_COUNT) * himl->cx;
107 pt->y = (index/TILE_COUNT) * himl->cy;
110 static inline void imagelist_get_bitmap_size( HIMAGELIST himl, UINT count, SIZE *sz )
112 sz->cx = himl->cx * TILE_COUNT;
113 sz->cy = imagelist_height( count ) * himl->cy;
117 * imagelist_copy_images()
119 * Copies a block of count images from offset src in the list to offset dest.
120 * Images are copied a row at at time. Assumes hdcSrc and hdcDest are different.
122 static inline void imagelist_copy_images( HIMAGELIST himl, HDC hdcSrc, HDC hdcDest,
123 UINT src, UINT count, UINT dest )
129 for ( i=0; i<TILE_COUNT; i++ )
131 imagelist_point_from_index( himl, src+i, &ptSrc );
132 imagelist_point_from_index( himl, dest+i, &ptDest );
134 sz.cy = himl->cy * imagelist_height( count - i );
136 BitBlt( hdcDest, ptDest.x, ptDest.y, sz.cx, sz.cy,
137 hdcSrc, ptSrc.x, ptSrc.y, SRCCOPY );
141 /* add images with an alpha channel when the image list is 32 bpp */
142 static BOOL add_with_alpha( HIMAGELIST himl, HDC hdc, int pos, int count,
143 int width, int height, HBITMAP hbmImage, HBITMAP hbmMask )
147 BITMAPINFO *info, *mask_info = NULL;
149 BYTE *mask_bits = NULL;
154 if (!GetObjectW( hbmImage, sizeof(bm), &bm )) return FALSE;
156 /* if either the imagelist or the source bitmap don't have an alpha channel, bail out now */
157 if (!himl->has_alpha) return FALSE;
158 if (bm.bmBitsPixel != 32) return FALSE;
160 SelectObject( hdc, hbmImage );
161 mask_width = (bm.bmWidth + 31) / 32 * 4;
163 if (!(info = HeapAlloc( GetProcessHeap(), 0, FIELD_OFFSET( BITMAPINFO, bmiColors[256] )))) goto done;
164 info->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
165 info->bmiHeader.biWidth = bm.bmWidth;
166 info->bmiHeader.biHeight = -height;
167 info->bmiHeader.biPlanes = 1;
168 info->bmiHeader.biBitCount = 32;
169 info->bmiHeader.biCompression = BI_RGB;
170 info->bmiHeader.biSizeImage = bm.bmWidth * height * 4;
171 info->bmiHeader.biXPelsPerMeter = 0;
172 info->bmiHeader.biYPelsPerMeter = 0;
173 info->bmiHeader.biClrUsed = 0;
174 info->bmiHeader.biClrImportant = 0;
175 if (!(bits = HeapAlloc( GetProcessHeap(), 0, info->bmiHeader.biSizeImage ))) goto done;
176 if (!GetDIBits( hdc, hbmImage, 0, height, bits, info, DIB_RGB_COLORS )) goto done;
180 if (!(mask_info = HeapAlloc( GetProcessHeap(), 0, FIELD_OFFSET( BITMAPINFO, bmiColors[2] ))))
182 mask_info->bmiHeader = info->bmiHeader;
183 mask_info->bmiHeader.biBitCount = 1;
184 mask_info->bmiHeader.biSizeImage = mask_width * height;
185 if (!(mask_bits = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, info->bmiHeader.biSizeImage )))
187 if (!GetDIBits( hdc, hbmMask, 0, height, mask_bits, mask_info, DIB_RGB_COLORS )) goto done;
190 for (n = 0; n < count; n++)
194 imagelist_point_from_index( himl, pos + n, &pt );
196 /* check if bitmap has an alpha channel */
197 for (i = 0; i < height && !has_alpha; i++)
198 for (j = n * width; j < (n + 1) * width; j++)
199 if ((has_alpha = ((bits[i * bm.bmWidth + j] & 0xff000000) != 0))) break;
201 if (!has_alpha) /* generate alpha channel from the mask */
203 for (i = 0; i < height; i++)
204 for (j = n * width; j < (n + 1) * width; j++)
205 if (!mask_bits || !((mask_bits[i * mask_width + j / 8] << (j % 8)) & 0x80))
206 bits[i * bm.bmWidth + j] |= 0xff000000;
208 bits[i * bm.bmWidth + j] = 0;
212 himl->has_alpha[pos + n] = 1;
214 if (mask_info && himl->hbmMask) /* generate the mask from the alpha channel */
216 for (i = 0; i < height; i++)
217 for (j = n * width; j < (n + 1) * width; j++)
218 if ((bits[i * bm.bmWidth + j] >> 24) > 25) /* more than 10% alpha */
219 mask_bits[i * mask_width + j / 8] &= ~(0x80 >> (j % 8));
221 mask_bits[i * mask_width + j / 8] |= 0x80 >> (j % 8);
224 StretchDIBits( himl->hdcImage, pt.x, pt.y, himl->cx, himl->cy,
225 n * width, 0, width, height, bits, info, DIB_RGB_COLORS, SRCCOPY );
227 StretchDIBits( himl->hdcMask, pt.x, pt.y, himl->cx, himl->cy,
228 n * width, 0, width, height, mask_bits, mask_info, DIB_RGB_COLORS, SRCCOPY );
233 HeapFree( GetProcessHeap(), 0, info );
234 HeapFree( GetProcessHeap(), 0, mask_info );
235 HeapFree( GetProcessHeap(), 0, bits );
236 HeapFree( GetProcessHeap(), 0, mask_bits );
240 /*************************************************************************
241 * IMAGELIST_InternalExpandBitmaps [Internal]
243 * Expands the bitmaps of an image list by the given number of images.
246 * himl [I] handle to image list
247 * nImageCount [I] number of images to add
253 * This function CANNOT be used to reduce the number of images.
256 IMAGELIST_InternalExpandBitmaps(HIMAGELIST himl, INT nImageCount)
259 HBITMAP hbmNewBitmap, hbmNull;
263 TRACE("%p has allocated %d, max %d, grow %d images\n", himl, himl->cCurImage, himl->cMaxImage, himl->cGrow);
265 if (himl->cCurImage + nImageCount < himl->cMaxImage)
268 nNewCount = himl->cMaxImage + max(nImageCount, himl->cGrow) + 1;
270 imagelist_get_bitmap_size(himl, nNewCount, &sz);
272 TRACE("Create expanded bitmaps : himl=%p x=%d y=%d count=%d\n", himl, sz.cx, sz.cy, nNewCount);
273 hdcBitmap = CreateCompatibleDC (0);
275 hbmNewBitmap = ImageList_CreateImage(hdcBitmap, himl, nNewCount);
277 if (hbmNewBitmap == 0)
278 ERR("creating new image bitmap (x=%d y=%d)!\n", sz.cx, sz.cy);
282 hbmNull = SelectObject (hdcBitmap, hbmNewBitmap);
283 BitBlt (hdcBitmap, 0, 0, sz.cx, sz.cy,
284 himl->hdcImage, 0, 0, SRCCOPY);
285 SelectObject (hdcBitmap, hbmNull);
287 SelectObject (himl->hdcImage, hbmNewBitmap);
288 DeleteObject (himl->hbmImage);
289 himl->hbmImage = hbmNewBitmap;
291 if (himl->flags & ILC_MASK)
293 hbmNewBitmap = CreateBitmap (sz.cx, sz.cy, 1, 1, NULL);
295 if (hbmNewBitmap == 0)
296 ERR("creating new mask bitmap!\n");
300 hbmNull = SelectObject (hdcBitmap, hbmNewBitmap);
301 BitBlt (hdcBitmap, 0, 0, sz.cx, sz.cy,
302 himl->hdcMask, 0, 0, SRCCOPY);
303 SelectObject (hdcBitmap, hbmNull);
305 SelectObject (himl->hdcMask, hbmNewBitmap);
306 DeleteObject (himl->hbmMask);
307 himl->hbmMask = hbmNewBitmap;
312 char *new_alpha = HeapReAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, himl->has_alpha, nNewCount );
313 if (new_alpha) himl->has_alpha = new_alpha;
316 HeapFree( GetProcessHeap(), 0, himl->has_alpha );
317 himl->has_alpha = NULL;
321 himl->cMaxImage = nNewCount;
323 DeleteDC (hdcBitmap);
327 /*************************************************************************
328 * ImageList_Add [COMCTL32.@]
330 * Add an image or images to an image list.
333 * himl [I] handle to image list
334 * hbmImage [I] handle to image bitmap
335 * hbmMask [I] handle to mask bitmap
338 * Success: Index of the first new image.
343 ImageList_Add (HIMAGELIST himl, HBITMAP hbmImage, HBITMAP hbmMask)
345 HDC hdcBitmap, hdcTemp = 0;
346 INT nFirstIndex, nImageCount, i;
350 TRACE("himl=%p hbmimage=%p hbmmask=%p\n", himl, hbmImage, hbmMask);
354 if (!GetObjectW(hbmImage, sizeof(BITMAP), &bmp))
357 TRACE("himl %p, cCurImage %d, cMaxImage %d, cGrow %d, cx %d, cy %d\n",
358 himl, himl->cCurImage, himl->cMaxImage, himl->cGrow, himl->cx, himl->cy);
360 nImageCount = bmp.bmWidth / himl->cx;
362 TRACE("%p has %d images (%d x %d)\n", hbmImage, nImageCount, bmp.bmWidth, bmp.bmHeight);
364 IMAGELIST_InternalExpandBitmaps(himl, nImageCount);
366 hdcBitmap = CreateCompatibleDC(0);
368 SelectObject(hdcBitmap, hbmImage);
370 if (add_with_alpha( himl, hdcBitmap, himl->cCurImage, nImageCount,
371 himl->cx, min( himl->cy, bmp.bmHeight), hbmImage, hbmMask ))
376 hdcTemp = CreateCompatibleDC(0);
377 SelectObject(hdcTemp, hbmMask);
380 for (i=0; i<nImageCount; i++)
382 imagelist_point_from_index( himl, himl->cCurImage + i, &pt );
384 /* Copy result to the imagelist
386 BitBlt( himl->hdcImage, pt.x, pt.y, himl->cx, bmp.bmHeight,
387 hdcBitmap, i*himl->cx, 0, SRCCOPY );
392 BitBlt( himl->hdcMask, pt.x, pt.y, himl->cx, bmp.bmHeight,
393 hdcTemp, i*himl->cx, 0, SRCCOPY );
395 /* Remove the background from the image
397 BitBlt( himl->hdcImage, pt.x, pt.y, himl->cx, bmp.bmHeight,
398 himl->hdcMask, pt.x, pt.y, 0x220326 ); /* NOTSRCAND */
400 if (hdcTemp) DeleteDC(hdcTemp);
405 nFirstIndex = himl->cCurImage;
406 himl->cCurImage += nImageCount;
412 /*************************************************************************
413 * ImageList_AddIcon [COMCTL32.@]
415 * Adds an icon to an image list.
418 * himl [I] handle to image list
419 * hIcon [I] handle to icon
422 * Success: index of the new image
425 #undef ImageList_AddIcon
426 INT WINAPI ImageList_AddIcon (HIMAGELIST himl, HICON hIcon)
428 return ImageList_ReplaceIcon (himl, -1, hIcon);
432 /*************************************************************************
433 * ImageList_AddMasked [COMCTL32.@]
435 * Adds an image or images to an image list and creates a mask from the
436 * specified bitmap using the mask color.
439 * himl [I] handle to image list.
440 * hBitmap [I] handle to bitmap
441 * clrMask [I] mask color.
444 * Success: Index of the first new image.
449 ImageList_AddMasked (HIMAGELIST himl, HBITMAP hBitmap, COLORREF clrMask)
451 HDC hdcMask, hdcBitmap;
457 TRACE("himl=%p hbitmap=%p clrmask=%x\n", himl, hBitmap, clrMask);
461 if (!GetObjectW(hBitmap, sizeof(BITMAP), &bmp))
464 hdcBitmap = CreateCompatibleDC(0);
465 SelectObject(hdcBitmap, hBitmap);
467 /* Create a temp Mask so we can remove the background of the Image */
468 hdcMask = CreateCompatibleDC(0);
469 hMaskBitmap = CreateBitmap(bmp.bmWidth, bmp.bmHeight, 1, 1, NULL);
470 SelectObject(hdcMask, hMaskBitmap);
472 /* create monochrome image to the mask bitmap */
473 bkColor = (clrMask != CLR_DEFAULT) ? clrMask : GetPixel (hdcBitmap, 0, 0);
474 SetBkColor (hdcBitmap, bkColor);
475 BitBlt (hdcMask, 0, 0, bmp.bmWidth, bmp.bmHeight, hdcBitmap, 0, 0, SRCCOPY);
477 SetBkColor(hdcBitmap, RGB(255,255,255));
480 * Remove the background from the image
482 * WINDOWS BUG ALERT!!!!!!
483 * The statement below should not be done in common practice
484 * but this is how ImageList_AddMasked works in Windows.
485 * It overwrites the original bitmap passed, this was discovered
486 * by using the same bitmap to iterate the different styles
487 * on windows where it failed (BUT ImageList_Add is OK)
488 * This is here in case some apps rely on this bug
490 * Blt mode 0x220326 is NOTSRCAND
492 BitBlt(hdcBitmap, 0, 0, bmp.bmWidth, bmp.bmHeight, hdcMask, 0, 0, 0x220326);
497 ret = ImageList_Add( himl, hBitmap, hMaskBitmap );
499 DeleteObject(hMaskBitmap);
504 /*************************************************************************
505 * ImageList_BeginDrag [COMCTL32.@]
507 * Creates a temporary image list that contains one image. It will be used
511 * himlTrack [I] handle to the source image list
512 * iTrack [I] index of the drag image in the source image list
513 * dxHotspot [I] X position of the hot spot of the drag image
514 * dyHotspot [I] Y position of the hot spot of the drag image
522 ImageList_BeginDrag (HIMAGELIST himlTrack, INT iTrack,
523 INT dxHotspot, INT dyHotspot)
527 TRACE("(himlTrack=%p iTrack=%d dx=%d dy=%d)\n", himlTrack, iTrack,
528 dxHotspot, dyHotspot);
530 if (!is_valid(himlTrack))
533 if (InternalDrag.himl)
534 ImageList_EndDrag ();
539 InternalDrag.himl = ImageList_Create (cx, cy, himlTrack->flags, 1, 1);
540 if (InternalDrag.himl == NULL) {
541 WARN("Error creating drag image list!\n");
545 InternalDrag.dxHotspot = dxHotspot;
546 InternalDrag.dyHotspot = dyHotspot;
549 BitBlt (InternalDrag.himl->hdcImage, 0, 0, cx, cy, himlTrack->hdcImage, iTrack * cx, 0, SRCCOPY);
552 BitBlt (InternalDrag.himl->hdcMask, 0, 0, cx, cy, himlTrack->hdcMask, iTrack * cx, 0, SRCCOPY);
554 InternalDrag.himl->cCurImage = 1;
560 /*************************************************************************
561 * ImageList_Copy [COMCTL32.@]
563 * Copies an image of the source image list to an image of the
564 * destination image list. Images can be copied or swapped.
567 * himlDst [I] handle to the destination image list
568 * iDst [I] destination image index.
569 * himlSrc [I] handle to the source image list
570 * iSrc [I] source image index
571 * uFlags [I] flags for the copy operation
578 * Copying from one image list to another is possible. The original
579 * implementation just copies or swaps within one image list.
580 * Could this feature become a bug??? ;-)
584 ImageList_Copy (HIMAGELIST himlDst, INT iDst, HIMAGELIST himlSrc,
585 INT iSrc, UINT uFlags)
589 TRACE("himlDst=%p iDst=%d himlSrc=%p iSrc=%d\n", himlDst, iDst, himlSrc, iSrc);
591 if (!is_valid(himlSrc) || !is_valid(himlDst))
593 if ((iDst < 0) || (iDst >= himlDst->cCurImage))
595 if ((iSrc < 0) || (iSrc >= himlSrc->cCurImage))
598 imagelist_point_from_index( himlDst, iDst, &ptDst );
599 imagelist_point_from_index( himlSrc, iSrc, &ptSrc );
601 if (uFlags & ILCF_SWAP) {
604 HBITMAP hbmTempImage, hbmTempMask;
606 hdcBmp = CreateCompatibleDC (0);
608 /* create temporary bitmaps */
609 hbmTempImage = CreateBitmap (himlSrc->cx, himlSrc->cy, 1,
610 himlSrc->uBitsPixel, NULL);
611 hbmTempMask = CreateBitmap (himlSrc->cx, himlSrc->cy, 1,
614 /* copy (and stretch) destination to temporary bitmaps.(save) */
616 SelectObject (hdcBmp, hbmTempImage);
617 StretchBlt (hdcBmp, 0, 0, himlSrc->cx, himlSrc->cy,
618 himlDst->hdcImage, ptDst.x, ptDst.y, himlDst->cx, himlDst->cy,
621 SelectObject (hdcBmp, hbmTempMask);
622 StretchBlt (hdcBmp, 0, 0, himlSrc->cx, himlSrc->cy,
623 himlDst->hdcMask, ptDst.x, ptDst.y, himlDst->cx, himlDst->cy,
626 /* copy (and stretch) source to destination */
628 StretchBlt (himlDst->hdcImage, ptDst.x, ptDst.y, himlDst->cx, himlDst->cy,
629 himlSrc->hdcImage, ptSrc.x, ptSrc.y, himlSrc->cx, himlSrc->cy,
632 StretchBlt (himlDst->hdcMask, ptDst.x, ptDst.y, himlDst->cx, himlDst->cy,
633 himlSrc->hdcMask, ptSrc.x, ptSrc.y, himlSrc->cx, himlSrc->cy,
636 /* copy (without stretching) temporary bitmaps to source (restore) */
638 BitBlt (himlSrc->hdcMask, ptSrc.x, ptSrc.y, himlSrc->cx, himlSrc->cy,
639 hdcBmp, 0, 0, SRCCOPY);
642 BitBlt (himlSrc->hdcImage, ptSrc.x, ptSrc.y, himlSrc->cx, himlSrc->cy,
643 hdcBmp, 0, 0, SRCCOPY);
644 /* delete temporary bitmaps */
645 DeleteObject (hbmTempMask);
646 DeleteObject (hbmTempImage);
651 StretchBlt (himlDst->hdcImage, ptDst.x, ptDst.y, himlDst->cx, himlDst->cy,
652 himlSrc->hdcImage, ptSrc.x, ptSrc.y, himlSrc->cx, himlSrc->cy,
656 StretchBlt (himlDst->hdcMask, ptDst.x, ptDst.y, himlDst->cx, himlDst->cy,
657 himlSrc->hdcMask, ptSrc.x, ptSrc.y, himlSrc->cx, himlSrc->cy,
665 /*************************************************************************
666 * ImageList_Create [COMCTL32.@]
668 * Creates a new image list.
671 * cx [I] image height
673 * flags [I] creation flags
674 * cInitial [I] initial number of images in the image list
675 * cGrow [I] number of images by which image list grows
678 * Success: Handle to the created image list
682 ImageList_Create (INT cx, INT cy, UINT flags,
683 INT cInitial, INT cGrow)
688 UINT ilc = (flags & 0xFE);
689 static const WORD aBitBlend25[] =
690 {0xAA, 0x00, 0x55, 0x00, 0xAA, 0x00, 0x55, 0x00};
692 static const WORD aBitBlend50[] =
693 {0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA};
695 TRACE("(%d %d 0x%x %d %d)\n", cx, cy, flags, cInitial, cGrow);
697 if (cx <= 0 || cy <= 0) return NULL;
699 /* Create the IImageList interface for the image list */
700 if (FAILED(ImageListImpl_CreateInstance(NULL, &IID_IImageList, (void **)&himl)))
703 cGrow = (cGrow < 4) ? 4 : (cGrow + 3) & ~3;
708 himl->cMaxImage = cInitial + 1;
709 himl->cInitial = cInitial;
711 himl->clrFg = CLR_DEFAULT;
712 himl->clrBk = CLR_NONE;
714 /* initialize overlay mask indices */
715 for (nCount = 0; nCount < MAX_OVERLAYIMAGE; nCount++)
716 himl->nOvlIdx[nCount] = -1;
718 /* Create Image & Mask DCs */
719 himl->hdcImage = CreateCompatibleDC (0);
722 if (himl->flags & ILC_MASK){
723 himl->hdcMask = CreateCompatibleDC(0);
728 /* Default to ILC_COLOR4 if none of the ILC_COLOR* flags are specified */
729 if (ilc == ILC_COLOR)
732 if (ilc >= ILC_COLOR4 && ilc <= ILC_COLOR32)
733 himl->uBitsPixel = ilc;
735 himl->uBitsPixel = (UINT)GetDeviceCaps (himl->hdcImage, BITSPIXEL);
737 if (himl->cMaxImage > 0) {
738 himl->hbmImage = ImageList_CreateImage(himl->hdcImage, himl, himl->cMaxImage);
739 SelectObject(himl->hdcImage, himl->hbmImage);
743 if ((himl->cMaxImage > 0) && (himl->flags & ILC_MASK)) {
746 imagelist_get_bitmap_size(himl, himl->cMaxImage, &sz);
747 himl->hbmMask = CreateBitmap (sz.cx, sz.cy, 1, 1, NULL);
748 if (himl->hbmMask == 0) {
749 ERR("Error creating mask bitmap!\n");
752 SelectObject(himl->hdcMask, himl->hbmMask);
757 if (ilc == ILC_COLOR32)
758 himl->has_alpha = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, himl->cMaxImage );
760 himl->has_alpha = NULL;
762 /* create blending brushes */
763 hbmTemp = CreateBitmap (8, 8, 1, 1, aBitBlend25);
764 himl->hbrBlend25 = CreatePatternBrush (hbmTemp);
765 DeleteObject (hbmTemp);
767 hbmTemp = CreateBitmap (8, 8, 1, 1, aBitBlend50);
768 himl->hbrBlend50 = CreatePatternBrush (hbmTemp);
769 DeleteObject (hbmTemp);
771 TRACE("created imagelist %p\n", himl);
775 ImageList_Destroy(himl);
780 /*************************************************************************
781 * ImageList_Destroy [COMCTL32.@]
783 * Destroys an image list.
786 * himl [I] handle to image list
794 ImageList_Destroy (HIMAGELIST himl)
799 IImageList_Release((IImageList *) himl);
804 /*************************************************************************
805 * ImageList_DragEnter [COMCTL32.@]
807 * Locks window update and displays the drag image at the given position.
810 * hwndLock [I] handle of the window that owns the drag image.
811 * x [I] X position of the drag image.
812 * y [I] Y position of the drag image.
819 * The position of the drag image is relative to the window, not
824 ImageList_DragEnter (HWND hwndLock, INT x, INT y)
826 TRACE("(hwnd=%p x=%d y=%d)\n", hwndLock, x, y);
828 if (!is_valid(InternalDrag.himl))
832 InternalDrag.hwnd = hwndLock;
834 InternalDrag.hwnd = GetDesktopWindow ();
839 /* draw the drag image and save the background */
840 if (!ImageList_DragShowNolock(TRUE)) {
848 /*************************************************************************
849 * ImageList_DragLeave [COMCTL32.@]
851 * Unlocks window update and hides the drag image.
854 * hwndLock [I] handle of the window that owns the drag image.
862 ImageList_DragLeave (HWND hwndLock)
864 /* As we don't save drag info in the window this can lead to problems if
865 an app does not supply the same window as DragEnter */
867 InternalDrag.hwnd = hwndLock;
869 InternalDrag.hwnd = GetDesktopWindow (); */
871 hwndLock = GetDesktopWindow();
872 if(InternalDrag.hwnd != hwndLock)
873 FIXME("DragLeave hWnd != DragEnter hWnd\n");
875 ImageList_DragShowNolock (FALSE);
881 /*************************************************************************
882 * ImageList_InternalDragDraw [Internal]
884 * Draws the drag image.
887 * hdc [I] device context to draw into.
888 * x [I] X position of the drag image.
889 * y [I] Y position of the drag image.
896 * The position of the drag image is relative to the window, not
902 ImageList_InternalDragDraw (HDC hdc, INT x, INT y)
904 IMAGELISTDRAWPARAMS imldp;
906 ZeroMemory (&imldp, sizeof(imldp));
907 imldp.cbSize = sizeof(imldp);
908 imldp.himl = InternalDrag.himl;
913 imldp.rgbBk = CLR_DEFAULT;
914 imldp.rgbFg = CLR_DEFAULT;
915 imldp.fStyle = ILD_NORMAL;
916 imldp.fState = ILS_ALPHA;
918 ImageList_DrawIndirect (&imldp);
921 /*************************************************************************
922 * ImageList_DragMove [COMCTL32.@]
924 * Moves the drag image.
927 * x [I] X position of the drag image.
928 * y [I] Y position of the drag image.
935 * The position of the drag image is relative to the window, not
940 ImageList_DragMove (INT x, INT y)
942 TRACE("(x=%d y=%d)\n", x, y);
944 if (!is_valid(InternalDrag.himl))
947 /* draw/update the drag image */
948 if (InternalDrag.bShow) {
952 HBITMAP hbmOffScreen;
953 INT origNewX, origNewY;
954 INT origOldX, origOldY;
955 INT origRegX, origRegY;
956 INT sizeRegX, sizeRegY;
959 /* calculate the update region */
960 origNewX = x - InternalDrag.dxHotspot;
961 origNewY = y - InternalDrag.dyHotspot;
962 origOldX = InternalDrag.x - InternalDrag.dxHotspot;
963 origOldY = InternalDrag.y - InternalDrag.dyHotspot;
964 origRegX = min(origNewX, origOldX);
965 origRegY = min(origNewY, origOldY);
966 sizeRegX = InternalDrag.himl->cx + abs(x - InternalDrag.x);
967 sizeRegY = InternalDrag.himl->cy + abs(y - InternalDrag.y);
969 hdcDrag = GetDCEx(InternalDrag.hwnd, 0,
970 DCX_WINDOW | DCX_CACHE | DCX_LOCKWINDOWUPDATE);
971 hdcOffScreen = CreateCompatibleDC(hdcDrag);
972 hdcBg = CreateCompatibleDC(hdcDrag);
974 hbmOffScreen = CreateCompatibleBitmap(hdcDrag, sizeRegX, sizeRegY);
975 SelectObject(hdcOffScreen, hbmOffScreen);
976 SelectObject(hdcBg, InternalDrag.hbmBg);
978 /* get the actual background of the update region */
979 BitBlt(hdcOffScreen, 0, 0, sizeRegX, sizeRegY, hdcDrag,
980 origRegX, origRegY, SRCCOPY);
981 /* erase the old image */
982 BitBlt(hdcOffScreen, origOldX - origRegX, origOldY - origRegY,
983 InternalDrag.himl->cx, InternalDrag.himl->cy, hdcBg, 0, 0,
985 /* save the background */
986 BitBlt(hdcBg, 0, 0, InternalDrag.himl->cx, InternalDrag.himl->cy,
987 hdcOffScreen, origNewX - origRegX, origNewY - origRegY, SRCCOPY);
989 ImageList_InternalDragDraw(hdcOffScreen, origNewX - origRegX,
990 origNewY - origRegY);
991 /* draw the update region to the screen */
992 BitBlt(hdcDrag, origRegX, origRegY, sizeRegX, sizeRegY,
993 hdcOffScreen, 0, 0, SRCCOPY);
996 DeleteDC(hdcOffScreen);
997 DeleteObject(hbmOffScreen);
998 ReleaseDC(InternalDrag.hwnd, hdcDrag);
1001 /* update the image position */
1009 /*************************************************************************
1010 * ImageList_DragShowNolock [COMCTL32.@]
1012 * Shows or hides the drag image.
1015 * bShow [I] TRUE shows the drag image, FALSE hides it.
1023 ImageList_DragShowNolock (BOOL bShow)
1029 if (!is_valid(InternalDrag.himl))
1032 TRACE("bShow=0x%X!\n", bShow);
1034 /* DragImage is already visible/hidden */
1035 if ((InternalDrag.bShow && bShow) || (!InternalDrag.bShow && !bShow)) {
1039 /* position of the origin of the DragImage */
1040 x = InternalDrag.x - InternalDrag.dxHotspot;
1041 y = InternalDrag.y - InternalDrag.dyHotspot;
1043 hdcDrag = GetDCEx (InternalDrag.hwnd, 0,
1044 DCX_WINDOW | DCX_CACHE | DCX_LOCKWINDOWUPDATE);
1049 hdcBg = CreateCompatibleDC(hdcDrag);
1050 if (!InternalDrag.hbmBg) {
1051 InternalDrag.hbmBg = CreateCompatibleBitmap(hdcDrag,
1052 InternalDrag.himl->cx, InternalDrag.himl->cy);
1054 SelectObject(hdcBg, InternalDrag.hbmBg);
1057 /* save the background */
1058 BitBlt(hdcBg, 0, 0, InternalDrag.himl->cx, InternalDrag.himl->cy,
1059 hdcDrag, x, y, SRCCOPY);
1060 /* show the image */
1061 ImageList_InternalDragDraw(hdcDrag, x, y);
1063 /* hide the image */
1064 BitBlt(hdcDrag, x, y, InternalDrag.himl->cx, InternalDrag.himl->cy,
1065 hdcBg, 0, 0, SRCCOPY);
1068 InternalDrag.bShow = !InternalDrag.bShow;
1071 ReleaseDC (InternalDrag.hwnd, hdcDrag);
1076 /*************************************************************************
1077 * ImageList_Draw [COMCTL32.@]
1082 * himl [I] handle to image list
1084 * hdc [I] handle to device context
1087 * fStyle [I] drawing flags
1098 ImageList_Draw (HIMAGELIST himl, INT i, HDC hdc, INT x, INT y, UINT fStyle)
1100 return ImageList_DrawEx (himl, i, hdc, x, y, 0, 0,
1101 CLR_DEFAULT, CLR_DEFAULT, fStyle);
1105 /*************************************************************************
1106 * ImageList_DrawEx [COMCTL32.@]
1108 * Draws an image and allows to use extended drawing features.
1111 * himl [I] handle to image list
1113 * hdc [I] handle to device context
1118 * rgbBk [I] background color
1119 * rgbFg [I] foreground color
1120 * fStyle [I] drawing flags
1127 * Calls ImageList_DrawIndirect.
1130 * ImageList_DrawIndirect.
1134 ImageList_DrawEx (HIMAGELIST himl, INT i, HDC hdc, INT x, INT y,
1135 INT dx, INT dy, COLORREF rgbBk, COLORREF rgbFg,
1138 IMAGELISTDRAWPARAMS imldp;
1140 ZeroMemory (&imldp, sizeof(imldp));
1141 imldp.cbSize = sizeof(imldp);
1149 imldp.rgbBk = rgbBk;
1150 imldp.rgbFg = rgbFg;
1151 imldp.fStyle = fStyle;
1153 return ImageList_DrawIndirect (&imldp);
1157 static BOOL alpha_blend_image( HIMAGELIST himl, HDC dest_dc, int dest_x, int dest_y,
1158 int src_x, int src_y, int cx, int cy, BLENDFUNCTION func,
1159 UINT style, COLORREF blend_col )
1163 HBITMAP bmp = 0, mask = 0;
1165 void *bits, *mask_bits;
1169 if (!(hdc = CreateCompatibleDC( 0 ))) return FALSE;
1170 if (!(info = HeapAlloc( GetProcessHeap(), 0, FIELD_OFFSET( BITMAPINFO, bmiColors[256] )))) goto done;
1171 info->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
1172 info->bmiHeader.biWidth = cx;
1173 info->bmiHeader.biHeight = cy;
1174 info->bmiHeader.biPlanes = 1;
1175 info->bmiHeader.biBitCount = 32;
1176 info->bmiHeader.biCompression = BI_RGB;
1177 info->bmiHeader.biSizeImage = cx * cy * 4;
1178 info->bmiHeader.biXPelsPerMeter = 0;
1179 info->bmiHeader.biYPelsPerMeter = 0;
1180 info->bmiHeader.biClrUsed = 0;
1181 info->bmiHeader.biClrImportant = 0;
1182 if (!(bmp = CreateDIBSection( himl->hdcImage, info, DIB_RGB_COLORS, &bits, 0, 0 ))) goto done;
1183 SelectObject( hdc, bmp );
1184 BitBlt( hdc, 0, 0, cx, cy, himl->hdcImage, src_x, src_y, SRCCOPY );
1186 if (blend_col != CLR_NONE)
1188 BYTE r = GetRValue( blend_col );
1189 BYTE g = GetGValue( blend_col );
1190 BYTE b = GetBValue( blend_col );
1192 if (style & ILD_BLEND25)
1194 for (i = 0, ptr = bits; i < cx * cy; i++, ptr++)
1195 *ptr = ((*ptr & 0xff000000) |
1196 ((((*ptr & 0x00ff0000) * 3 + (r << 16)) / 4) & 0x00ff0000) |
1197 ((((*ptr & 0x0000ff00) * 3 + (g << 8)) / 4) & 0x0000ff00) |
1198 ((((*ptr & 0x000000ff) * 3 + (b << 0)) / 4) & 0x000000ff));
1200 else if (style & ILD_BLEND50)
1202 for (i = 0, ptr = bits; i < cx * cy; i++, ptr++)
1203 *ptr = ((*ptr & 0xff000000) |
1204 ((((*ptr & 0x00ff0000) + (r << 16)) / 2) & 0x00ff0000) |
1205 ((((*ptr & 0x0000ff00) + (g << 8)) / 2) & 0x0000ff00) |
1206 ((((*ptr & 0x000000ff) + (b << 0)) / 2) & 0x000000ff));
1210 if (himl->has_alpha) /* we already have an alpha channel in this case */
1212 /* pre-multiply by the alpha channel */
1213 for (i = 0, ptr = bits; i < cx * cy; i++, ptr++)
1215 DWORD alpha = *ptr >> 24;
1216 *ptr = ((*ptr & 0xff000000) |
1217 (((*ptr & 0x00ff0000) * alpha / 255) & 0x00ff0000) |
1218 (((*ptr & 0x0000ff00) * alpha / 255) & 0x0000ff00) |
1219 (((*ptr & 0x000000ff) * alpha / 255)));
1222 else if (himl->hbmMask)
1224 unsigned int width_bytes = (cx + 31) / 32 * 4;
1225 /* generate alpha channel from the mask */
1226 info->bmiHeader.biBitCount = 1;
1227 info->bmiHeader.biSizeImage = width_bytes * cy;
1228 if (!(mask = CreateDIBSection( himl->hdcMask, info, DIB_RGB_COLORS, &mask_bits, 0, 0 )))
1230 SelectObject( hdc, mask );
1231 BitBlt( hdc, 0, 0, cx, cy, himl->hdcMask, src_x, src_y, SRCCOPY );
1232 SelectObject( hdc, bmp );
1233 for (i = 0, ptr = bits; i < cy; i++)
1234 for (j = 0; j < cx; j++, ptr++)
1235 if ((((BYTE *)mask_bits)[i * width_bytes + j / 8] << (j % 8)) & 0x80) *ptr = 0;
1236 else *ptr |= 0xff000000;
1239 ret = GdiAlphaBlend( dest_dc, dest_x, dest_y, cx, cy, hdc, 0, 0, cx, cy, func );
1243 if (bmp) DeleteObject( bmp );
1244 if (mask) DeleteObject( mask );
1245 HeapFree( GetProcessHeap(), 0, info );
1249 /*************************************************************************
1250 * ImageList_DrawIndirect [COMCTL32.@]
1252 * Draws an image using various parameters specified in pimldp.
1255 * pimldp [I] pointer to IMAGELISTDRAWPARAMS structure.
1263 ImageList_DrawIndirect (IMAGELISTDRAWPARAMS *pimldp)
1265 INT cx, cy, nOvlIdx;
1266 DWORD fState, dwRop;
1268 COLORREF oldImageBk, oldImageFg;
1269 HDC hImageDC, hImageListDC, hMaskListDC;
1270 HBITMAP hImageBmp, hOldImageBmp, hBlendMaskBmp;
1271 BOOL bIsTransparent, bBlend, bResult = FALSE, bMask;
1277 if (!pimldp || !(himl = pimldp->himl)) return FALSE;
1278 if (!is_valid(himl)) return FALSE;
1279 if ((pimldp->i < 0) || (pimldp->i >= himl->cCurImage)) return FALSE;
1281 imagelist_point_from_index( himl, pimldp->i, &pt );
1282 pt.x += pimldp->xBitmap;
1283 pt.y += pimldp->yBitmap;
1285 fState = pimldp->cbSize < sizeof(IMAGELISTDRAWPARAMS) ? ILS_NORMAL : pimldp->fState;
1286 fStyle = pimldp->fStyle & ~ILD_OVERLAYMASK;
1287 cx = (pimldp->cx == 0) ? himl->cx : pimldp->cx;
1288 cy = (pimldp->cy == 0) ? himl->cy : pimldp->cy;
1290 bIsTransparent = (fStyle & ILD_TRANSPARENT);
1291 if( pimldp->rgbBk == CLR_NONE )
1292 bIsTransparent = TRUE;
1293 if( ( pimldp->rgbBk == CLR_DEFAULT ) && ( himl->clrBk == CLR_NONE ) )
1294 bIsTransparent = TRUE;
1295 bMask = (himl->flags & ILC_MASK) && (fStyle & ILD_MASK) ;
1296 bBlend = (fStyle & (ILD_BLEND25 | ILD_BLEND50) ) && !bMask;
1298 TRACE("himl(%p) hbmMask(%p) iImage(%d) x(%d) y(%d) cx(%d) cy(%d)\n",
1299 himl, himl->hbmMask, pimldp->i, pimldp->x, pimldp->y, cx, cy);
1301 /* we will use these DCs to access the images and masks in the ImageList */
1302 hImageListDC = himl->hdcImage;
1303 hMaskListDC = himl->hdcMask;
1305 /* these will accumulate the image and mask for the image we're drawing */
1306 hImageDC = CreateCompatibleDC( pimldp->hdcDst );
1307 hImageBmp = CreateCompatibleBitmap( pimldp->hdcDst, cx, cy );
1308 hBlendMaskBmp = bBlend ? CreateBitmap(cx, cy, 1, 1, NULL) : 0;
1310 /* Create a compatible DC. */
1311 if (!hImageListDC || !hImageDC || !hImageBmp ||
1312 (bBlend && !hBlendMaskBmp) || (himl->hbmMask && !hMaskListDC))
1315 hOldImageBmp = SelectObject(hImageDC, hImageBmp);
1318 * To obtain a transparent look, background color should be set
1319 * to white and foreground color to black when blitting the
1322 oldImageFg = SetTextColor( hImageDC, RGB( 0, 0, 0 ) );
1323 oldImageBk = SetBkColor( hImageDC, RGB( 0xff, 0xff, 0xff ) );
1325 has_alpha = (himl->has_alpha && himl->has_alpha[pimldp->i]);
1326 if (!bMask && (has_alpha || (fState & ILS_ALPHA)))
1328 COLORREF colour, blend_col = CLR_NONE;
1333 blend_col = pimldp->rgbFg;
1334 if (blend_col == CLR_DEFAULT) blend_col = GetSysColor( COLOR_HIGHLIGHT );
1335 else if (blend_col == CLR_NONE) blend_col = GetTextColor( pimldp->hdcDst );
1338 func.BlendOp = AC_SRC_OVER;
1339 func.BlendFlags = 0;
1340 func.SourceConstantAlpha = (fState & ILS_ALPHA) ? pimldp->Frame : 255;
1341 func.AlphaFormat = AC_SRC_ALPHA;
1345 bResult = alpha_blend_image( himl, pimldp->hdcDst, pimldp->x, pimldp->y,
1346 pt.x, pt.y, cx, cy, func, fStyle, blend_col );
1349 colour = pimldp->rgbBk;
1350 if (colour == CLR_DEFAULT) colour = himl->clrBk;
1351 if (colour == CLR_NONE) colour = GetBkColor( pimldp->hdcDst );
1353 hOldBrush = SelectObject (hImageDC, CreateSolidBrush (colour));
1354 PatBlt( hImageDC, 0, 0, cx, cy, PATCOPY );
1355 alpha_blend_image( himl, hImageDC, 0, 0, pt.x, pt.y, cx, cy, func, fStyle, blend_col );
1356 DeleteObject (SelectObject (hImageDC, hOldBrush));
1357 bResult = BitBlt( pimldp->hdcDst, pimldp->x, pimldp->y, cx, cy, hImageDC, 0, 0, SRCCOPY );
1362 * Draw the initial image
1365 if (himl->hbmMask) {
1366 hOldBrush = SelectObject (hImageDC, CreateSolidBrush (GetTextColor(pimldp->hdcDst)));
1367 PatBlt( hImageDC, 0, 0, cx, cy, PATCOPY );
1368 BitBlt(hImageDC, 0, 0, cx, cy, hMaskListDC, pt.x, pt.y, SRCPAINT);
1369 DeleteObject (SelectObject (hImageDC, hOldBrush));
1370 if( bIsTransparent )
1372 BitBlt ( pimldp->hdcDst, pimldp->x, pimldp->y, cx, cy, hImageDC, 0, 0, SRCAND);
1377 hOldBrush = SelectObject (hImageDC, GetStockObject(BLACK_BRUSH));
1378 PatBlt( hImageDC, 0, 0, cx, cy, PATCOPY);
1379 SelectObject(hImageDC, hOldBrush);
1382 /* blend the image with the needed solid background */
1383 COLORREF colour = RGB(0,0,0);
1385 if( !bIsTransparent )
1387 colour = pimldp->rgbBk;
1388 if( colour == CLR_DEFAULT )
1389 colour = himl->clrBk;
1390 if( colour == CLR_NONE )
1391 colour = GetBkColor(pimldp->hdcDst);
1394 hOldBrush = SelectObject (hImageDC, CreateSolidBrush (colour));
1395 PatBlt( hImageDC, 0, 0, cx, cy, PATCOPY );
1398 BitBlt( hImageDC, 0, 0, cx, cy, hMaskListDC, pt.x, pt.y, SRCAND );
1399 BitBlt( hImageDC, 0, 0, cx, cy, hImageListDC, pt.x, pt.y, SRCPAINT );
1402 BitBlt( hImageDC, 0, 0, cx, cy, hImageListDC, pt.x, pt.y, SRCCOPY);
1403 DeleteObject (SelectObject (hImageDC, hOldBrush));
1406 /* Time for blending, if required */
1409 COLORREF clrBlend = pimldp->rgbFg;
1410 HDC hBlendMaskDC = hImageListDC;
1413 /* Create the blend Mask */
1414 hOldBitmap = SelectObject(hBlendMaskDC, hBlendMaskBmp);
1415 hBlendBrush = fStyle & ILD_BLEND50 ? himl->hbrBlend50 : himl->hbrBlend25;
1416 hOldBrush = SelectObject(hBlendMaskDC, hBlendBrush);
1417 PatBlt(hBlendMaskDC, 0, 0, cx, cy, PATCOPY);
1418 SelectObject(hBlendMaskDC, hOldBrush);
1420 /* Modify the blend mask if an Image Mask exist */
1422 BitBlt(hBlendMaskDC, 0, 0, cx, cy, hMaskListDC, pt.x, pt.y, 0x220326); /* NOTSRCAND */
1423 BitBlt(hBlendMaskDC, 0, 0, cx, cy, hBlendMaskDC, 0, 0, NOTSRCCOPY);
1426 /* now apply blend to the current image given the BlendMask */
1427 if (clrBlend == CLR_DEFAULT) clrBlend = GetSysColor (COLOR_HIGHLIGHT);
1428 else if (clrBlend == CLR_NONE) clrBlend = GetTextColor (pimldp->hdcDst);
1429 hOldBrush = SelectObject (hImageDC, CreateSolidBrush(clrBlend));
1430 BitBlt (hImageDC, 0, 0, cx, cy, hBlendMaskDC, 0, 0, 0xB8074A); /* PSDPxax */
1431 DeleteObject(SelectObject(hImageDC, hOldBrush));
1432 SelectObject(hBlendMaskDC, hOldBitmap);
1435 /* Now do the overlay image, if any */
1436 nOvlIdx = (pimldp->fStyle & ILD_OVERLAYMASK) >> 8;
1437 if ( (nOvlIdx >= 1) && (nOvlIdx <= MAX_OVERLAYIMAGE)) {
1438 nOvlIdx = himl->nOvlIdx[nOvlIdx - 1];
1439 if ((nOvlIdx >= 0) && (nOvlIdx < himl->cCurImage)) {
1441 imagelist_point_from_index( himl, nOvlIdx, &ptOvl );
1442 ptOvl.x += pimldp->xBitmap;
1443 if (himl->hbmMask && !(fStyle & ILD_IMAGE))
1444 BitBlt (hImageDC, 0, 0, cx, cy, hMaskListDC, ptOvl.x, ptOvl.y, SRCAND);
1445 BitBlt (hImageDC, 0, 0, cx, cy, hImageListDC, ptOvl.x, ptOvl.y, SRCPAINT);
1449 if (fState & ILS_SATURATE) FIXME("ILS_SATURATE: unimplemented!\n");
1450 if (fState & ILS_GLOW) FIXME("ILS_GLOW: unimplemented!\n");
1451 if (fState & ILS_SHADOW) FIXME("ILS_SHADOW: unimplemented!\n");
1453 if (fStyle & ILD_PRESERVEALPHA) FIXME("ILD_PRESERVEALPHA: unimplemented!\n");
1454 if (fStyle & ILD_SCALE) FIXME("ILD_SCALE: unimplemented!\n");
1455 if (fStyle & ILD_DPISCALE) FIXME("ILD_DPISCALE: unimplemented!\n");
1457 /* now copy the image to the screen */
1459 if (himl->hbmMask && bIsTransparent ) {
1460 COLORREF oldDstFg = SetTextColor(pimldp->hdcDst, RGB( 0, 0, 0 ) );
1461 COLORREF oldDstBk = SetBkColor(pimldp->hdcDst, RGB( 0xff, 0xff, 0xff ));
1462 BitBlt (pimldp->hdcDst, pimldp->x, pimldp->y, cx, cy, hMaskListDC, pt.x, pt.y, SRCAND);
1463 SetBkColor(pimldp->hdcDst, oldDstBk);
1464 SetTextColor(pimldp->hdcDst, oldDstFg);
1467 if (fStyle & ILD_ROP) dwRop = pimldp->dwRop;
1468 BitBlt (pimldp->hdcDst, pimldp->x, pimldp->y, cx, cy, hImageDC, 0, 0, dwRop);
1472 /* cleanup the mess */
1473 SetBkColor(hImageDC, oldImageBk);
1474 SetTextColor(hImageDC, oldImageFg);
1475 SelectObject(hImageDC, hOldImageBmp);
1477 DeleteObject(hBlendMaskBmp);
1478 DeleteObject(hImageBmp);
1485 /*************************************************************************
1486 * ImageList_Duplicate [COMCTL32.@]
1488 * Duplicates an image list.
1491 * himlSrc [I] source image list handle
1494 * Success: Handle of duplicated image list.
1499 ImageList_Duplicate (HIMAGELIST himlSrc)
1503 if (!is_valid(himlSrc)) {
1504 ERR("Invalid image list handle!\n");
1508 himlDst = ImageList_Create (himlSrc->cx, himlSrc->cy, himlSrc->flags,
1509 himlSrc->cCurImage, himlSrc->cGrow);
1515 imagelist_get_bitmap_size(himlSrc, himlSrc->cCurImage, &sz);
1516 BitBlt (himlDst->hdcImage, 0, 0, sz.cx, sz.cy,
1517 himlSrc->hdcImage, 0, 0, SRCCOPY);
1519 if (himlDst->hbmMask)
1520 BitBlt (himlDst->hdcMask, 0, 0, sz.cx, sz.cy,
1521 himlSrc->hdcMask, 0, 0, SRCCOPY);
1523 himlDst->cCurImage = himlSrc->cCurImage;
1524 if (himlSrc->has_alpha && himlDst->has_alpha)
1525 memcpy( himlDst->has_alpha, himlSrc->has_alpha, himlDst->cCurImage );
1531 /*************************************************************************
1532 * ImageList_EndDrag [COMCTL32.@]
1534 * Finishes a drag operation.
1545 ImageList_EndDrag (void)
1547 /* cleanup the InternalDrag struct */
1548 InternalDrag.hwnd = 0;
1549 ImageList_Destroy (InternalDrag.himl);
1550 InternalDrag.himl = 0;
1553 InternalDrag.dxHotspot = 0;
1554 InternalDrag.dyHotspot = 0;
1555 InternalDrag.bShow = FALSE;
1556 DeleteObject(InternalDrag.hbmBg);
1557 InternalDrag.hbmBg = 0;
1561 /*************************************************************************
1562 * ImageList_GetBkColor [COMCTL32.@]
1564 * Returns the background color of an image list.
1567 * himl [I] Image list handle.
1570 * Success: background color
1575 ImageList_GetBkColor (HIMAGELIST himl)
1577 return himl ? himl->clrBk : CLR_NONE;
1581 /*************************************************************************
1582 * ImageList_GetDragImage [COMCTL32.@]
1584 * Returns the handle to the internal drag image list.
1587 * ppt [O] Pointer to the drag position. Can be NULL.
1588 * pptHotspot [O] Pointer to the position of the hot spot. Can be NULL.
1591 * Success: Handle of the drag image list.
1596 ImageList_GetDragImage (POINT *ppt, POINT *pptHotspot)
1598 if (is_valid(InternalDrag.himl)) {
1600 ppt->x = InternalDrag.x;
1601 ppt->y = InternalDrag.y;
1604 pptHotspot->x = InternalDrag.dxHotspot;
1605 pptHotspot->y = InternalDrag.dyHotspot;
1607 return (InternalDrag.himl);
1614 /*************************************************************************
1615 * ImageList_GetFlags [COMCTL32.@]
1617 * Gets the flags of the specified image list.
1620 * himl [I] Handle to image list
1630 ImageList_GetFlags(HIMAGELIST himl)
1632 TRACE("%p\n", himl);
1634 return is_valid(himl) ? himl->flags : 0;
1638 /*************************************************************************
1639 * ImageList_GetIcon [COMCTL32.@]
1641 * Creates an icon from a masked image of an image list.
1644 * himl [I] handle to image list
1646 * flags [I] drawing style flags
1649 * Success: icon handle
1654 ImageList_GetIcon (HIMAGELIST himl, INT i, UINT fStyle)
1658 HBITMAP hOldDstBitmap;
1662 TRACE("%p %d %d\n", himl, i, fStyle);
1663 if (!is_valid(himl) || (i < 0) || (i >= himl->cCurImage)) return NULL;
1669 /* create colour bitmap */
1671 ii.hbmColor = CreateCompatibleBitmap(hdcDst, himl->cx, himl->cy);
1672 ReleaseDC(0, hdcDst);
1674 hdcDst = CreateCompatibleDC(0);
1676 imagelist_point_from_index( himl, i, &pt );
1679 ii.hbmMask = CreateBitmap (himl->cx, himl->cy, 1, 1, NULL);
1680 hOldDstBitmap = SelectObject (hdcDst, ii.hbmMask);
1681 if (himl->hbmMask) {
1682 BitBlt (hdcDst, 0, 0, himl->cx, himl->cy,
1683 himl->hdcMask, pt.x, pt.y, SRCCOPY);
1686 PatBlt (hdcDst, 0, 0, himl->cx, himl->cy, BLACKNESS);
1689 SelectObject (hdcDst, ii.hbmColor);
1690 BitBlt (hdcDst, 0, 0, himl->cx, himl->cy,
1691 himl->hdcImage, pt.x, pt.y, SRCCOPY);
1694 * CreateIconIndirect requires us to deselect the bitmaps from
1695 * the DCs before calling
1697 SelectObject(hdcDst, hOldDstBitmap);
1699 hIcon = CreateIconIndirect (&ii);
1701 DeleteObject (ii.hbmMask);
1702 DeleteObject (ii.hbmColor);
1709 /*************************************************************************
1710 * ImageList_GetIconSize [COMCTL32.@]
1712 * Retrieves the size of an image in an image list.
1715 * himl [I] handle to image list
1716 * cx [O] pointer to the image width.
1717 * cy [O] pointer to the image height.
1724 * All images in an image list have the same size.
1728 ImageList_GetIconSize (HIMAGELIST himl, INT *cx, INT *cy)
1730 if (!is_valid(himl) || !cx || !cy)
1732 if ((himl->cx <= 0) || (himl->cy <= 0))
1742 /*************************************************************************
1743 * ImageList_GetImageCount [COMCTL32.@]
1745 * Returns the number of images in an image list.
1748 * himl [I] handle to image list
1751 * Success: Number of images.
1756 ImageList_GetImageCount (HIMAGELIST himl)
1758 if (!is_valid(himl))
1761 return himl->cCurImage;
1765 /*************************************************************************
1766 * ImageList_GetImageInfo [COMCTL32.@]
1768 * Returns information about an image in an image list.
1771 * himl [I] handle to image list
1773 * pImageInfo [O] pointer to the image information
1781 ImageList_GetImageInfo (HIMAGELIST himl, INT i, IMAGEINFO *pImageInfo)
1785 if (!is_valid(himl) || (pImageInfo == NULL))
1787 if ((i < 0) || (i >= himl->cCurImage))
1790 pImageInfo->hbmImage = himl->hbmImage;
1791 pImageInfo->hbmMask = himl->hbmMask;
1793 imagelist_point_from_index( himl, i, &pt );
1794 pImageInfo->rcImage.top = pt.y;
1795 pImageInfo->rcImage.bottom = pt.y + himl->cy;
1796 pImageInfo->rcImage.left = pt.x;
1797 pImageInfo->rcImage.right = pt.x + himl->cx;
1803 /*************************************************************************
1804 * ImageList_GetImageRect [COMCTL32.@]
1806 * Retrieves the rectangle of the specified image in an image list.
1809 * himl [I] handle to image list
1811 * lpRect [O] pointer to the image rectangle
1818 * This is an UNDOCUMENTED function!!!
1822 ImageList_GetImageRect (HIMAGELIST himl, INT i, LPRECT lpRect)
1826 if (!is_valid(himl) || (lpRect == NULL))
1828 if ((i < 0) || (i >= himl->cCurImage))
1831 imagelist_point_from_index( himl, i, &pt );
1832 lpRect->left = pt.x;
1834 lpRect->right = pt.x + himl->cx;
1835 lpRect->bottom = pt.y + himl->cy;
1841 /*************************************************************************
1842 * ImageList_LoadImage [COMCTL32.@]
1843 * ImageList_LoadImageA [COMCTL32.@]
1845 * Creates an image list from a bitmap, icon or cursor.
1847 * See ImageList_LoadImageW.
1851 ImageList_LoadImageA (HINSTANCE hi, LPCSTR lpbmp, INT cx, INT cGrow,
1852 COLORREF clrMask, UINT uType, UINT uFlags)
1858 if (IS_INTRESOURCE(lpbmp))
1859 return ImageList_LoadImageW(hi, (LPCWSTR)lpbmp, cx, cGrow, clrMask,
1862 len = MultiByteToWideChar(CP_ACP, 0, lpbmp, -1, NULL, 0);
1863 lpbmpW = Alloc(len * sizeof(WCHAR));
1864 MultiByteToWideChar(CP_ACP, 0, lpbmp, -1, lpbmpW, len);
1866 himl = ImageList_LoadImageW(hi, lpbmpW, cx, cGrow, clrMask, uType, uFlags);
1872 /*************************************************************************
1873 * ImageList_LoadImageW [COMCTL32.@]
1875 * Creates an image list from a bitmap, icon or cursor.
1878 * hi [I] instance handle
1879 * lpbmp [I] name or id of the image
1880 * cx [I] width of each image
1881 * cGrow [I] number of images to expand
1882 * clrMask [I] mask color
1883 * uType [I] type of image to load
1884 * uFlags [I] loading flags
1887 * Success: handle to the loaded image list
1895 ImageList_LoadImageW (HINSTANCE hi, LPCWSTR lpbmp, INT cx, INT cGrow,
1896 COLORREF clrMask, UINT uType, UINT uFlags)
1898 HIMAGELIST himl = NULL;
1902 handle = LoadImageW (hi, lpbmp, uType, 0, 0, uFlags);
1904 WARN("Couldn't load image\n");
1908 if (uType == IMAGE_BITMAP) {
1912 if (GetObjectW (handle, sizeof(dib), &dib) == sizeof(BITMAP)) color = ILC_COLOR;
1913 else color = dib.dsBm.bmBitsPixel;
1915 /* To match windows behavior, if cx is set to zero and
1916 the flag DI_DEFAULTSIZE is specified, cx becomes the
1917 system metric value for icons. If the flag is not specified
1918 the function sets the size to the height of the bitmap */
1921 if (uFlags & DI_DEFAULTSIZE)
1922 cx = GetSystemMetrics (SM_CXICON);
1924 cx = dib.dsBm.bmHeight;
1927 nImageCount = dib.dsBm.bmWidth / cx;
1929 himl = ImageList_Create (cx, dib.dsBm.bmHeight, ILC_MASK | color, nImageCount, cGrow);
1931 DeleteObject (handle);
1934 ImageList_AddMasked (himl, handle, clrMask);
1936 else if ((uType == IMAGE_ICON) || (uType == IMAGE_CURSOR)) {
1940 GetIconInfo (handle, &ii);
1941 GetObjectW (ii.hbmColor, sizeof(BITMAP), &bmp);
1942 himl = ImageList_Create (bmp.bmWidth, bmp.bmHeight,
1943 ILC_MASK | ILC_COLOR, 1, cGrow);
1945 DeleteObject (ii.hbmColor);
1946 DeleteObject (ii.hbmMask);
1947 DeleteObject (handle);
1950 ImageList_Add (himl, ii.hbmColor, ii.hbmMask);
1951 DeleteObject (ii.hbmColor);
1952 DeleteObject (ii.hbmMask);
1955 DeleteObject (handle);
1961 /*************************************************************************
1962 * ImageList_Merge [COMCTL32.@]
1964 * Create an image list containing a merged image from two image lists.
1967 * himl1 [I] handle to first image list
1968 * i1 [I] first image index
1969 * himl2 [I] handle to second image list
1970 * i2 [I] second image index
1971 * dx [I] X offset of the second image relative to the first.
1972 * dy [I] Y offset of the second image relative to the first.
1975 * Success: The newly created image list. It contains a single image
1976 * consisting of the second image merged with the first.
1977 * Failure: NULL, if either himl1 or himl2 are invalid.
1980 * - The returned image list should be deleted by the caller using
1981 * ImageList_Destroy() when it is no longer required.
1982 * - If either i1 or i2 are not valid image indices they will be treated
1986 ImageList_Merge (HIMAGELIST himl1, INT i1, HIMAGELIST himl2, INT i2,
1989 HIMAGELIST himlDst = NULL;
1991 INT xOff1, yOff1, xOff2, yOff2;
1994 TRACE("(himl1=%p i1=%d himl2=%p i2=%d dx=%d dy=%d)\n", himl1, i1, himl2,
1997 if (!is_valid(himl1) || !is_valid(himl2))
2001 cxDst = max (himl1->cx, dx + himl2->cx);
2006 cxDst = max (himl2->cx, himl1->cx - dx);
2011 cxDst = max (himl1->cx, himl2->cx);
2017 cyDst = max (himl1->cy, dy + himl2->cy);
2022 cyDst = max (himl2->cy, himl1->cy - dy);
2027 cyDst = max (himl1->cy, himl2->cy);
2032 himlDst = ImageList_Create (cxDst, cyDst, ILC_MASK | ILC_COLOR, 1, 1);
2036 imagelist_point_from_index( himl1, i1, &pt1 );
2037 imagelist_point_from_index( himl2, i2, &pt2 );
2040 BitBlt (himlDst->hdcImage, 0, 0, cxDst, cyDst, himl1->hdcImage, 0, 0, BLACKNESS);
2041 if (i1 >= 0 && i1 < himl1->cCurImage)
2042 BitBlt (himlDst->hdcImage, xOff1, yOff1, himl1->cx, himl1->cy, himl1->hdcImage, pt1.x, pt1.y, SRCCOPY);
2043 if (i2 >= 0 && i2 < himl2->cCurImage)
2045 BitBlt (himlDst->hdcImage, xOff2, yOff2, himl2->cx, himl2->cy, himl2->hdcMask , pt2.x, pt2.y, SRCAND);
2046 BitBlt (himlDst->hdcImage, xOff2, yOff2, himl2->cx, himl2->cy, himl2->hdcImage, pt2.x, pt2.y, SRCPAINT);
2050 BitBlt (himlDst->hdcMask, 0, 0, cxDst, cyDst, himl1->hdcMask, 0, 0, WHITENESS);
2051 if (i1 >= 0 && i1 < himl1->cCurImage)
2052 BitBlt (himlDst->hdcMask, xOff1, yOff1, himl1->cx, himl1->cy, himl1->hdcMask, pt1.x, pt1.y, SRCCOPY);
2053 if (i2 >= 0 && i2 < himl2->cCurImage)
2054 BitBlt (himlDst->hdcMask, xOff2, yOff2, himl2->cx, himl2->cy, himl2->hdcMask, pt2.x, pt2.y, SRCAND);
2056 himlDst->cCurImage = 1;
2063 /***********************************************************************
2064 * DIB_GetDIBImageBytes
2066 * Return the number of bytes used to hold the image in a DIB bitmap.
2068 static int DIB_GetDIBImageBytes( int width, int height, int depth )
2070 return (((width * depth + 31) / 8) & ~3) * abs( height );
2074 /* helper for ImageList_Read, see comments below */
2075 static BOOL _read_bitmap(HDC hdcIml, LPSTREAM pstm)
2077 BITMAPFILEHEADER bmfh;
2078 int bitsperpixel, palspace;
2079 char bmi_buf[sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD) * 256];
2080 LPBITMAPINFO bmi = (LPBITMAPINFO)bmi_buf;
2084 if (FAILED(IStream_Read ( pstm, &bmfh, sizeof(bmfh), NULL)))
2087 if (bmfh.bfType != (('M'<<8)|'B'))
2090 if (FAILED(IStream_Read ( pstm, &bmi->bmiHeader, sizeof(bmi->bmiHeader), NULL)))
2093 if ((bmi->bmiHeader.biSize != sizeof(bmi->bmiHeader)))
2096 TRACE("width %u, height %u, planes %u, bpp %u\n",
2097 bmi->bmiHeader.biWidth, bmi->bmiHeader.biHeight,
2098 bmi->bmiHeader.biPlanes, bmi->bmiHeader.biBitCount);
2100 bitsperpixel = bmi->bmiHeader.biPlanes * bmi->bmiHeader.biBitCount;
2101 if (bitsperpixel<=8)
2102 palspace = (1<<bitsperpixel)*sizeof(RGBQUAD);
2106 bmi->bmiHeader.biSizeImage = DIB_GetDIBImageBytes(bmi->bmiHeader.biWidth, bmi->bmiHeader.biHeight, bitsperpixel);
2108 /* read the palette right after the end of the bitmapinfoheader */
2109 if (palspace && FAILED(IStream_Read(pstm, bmi->bmiColors, palspace, NULL)))
2112 bits = Alloc(bmi->bmiHeader.biSizeImage);
2115 if (FAILED(IStream_Read(pstm, bits, bmi->bmiHeader.biSizeImage, NULL)))
2118 if (!StretchDIBits(hdcIml, 0, 0, bmi->bmiHeader.biWidth, bmi->bmiHeader.biHeight,
2119 0, 0, bmi->bmiHeader.biWidth, bmi->bmiHeader.biHeight,
2120 bits, bmi, DIB_RGB_COLORS, SRCCOPY))
2129 /*************************************************************************
2130 * ImageList_Read [COMCTL32.@]
2132 * Reads an image list from a stream.
2135 * pstm [I] pointer to a stream
2138 * Success: handle to image list
2141 * The format is like this:
2142 * ILHEAD ilheadstruct;
2144 * for the color image part:
2145 * BITMAPFILEHEADER bmfh;
2146 * BITMAPINFOHEADER bmih;
2147 * only if it has a palette:
2148 * RGBQUAD rgbs[nr_of_paletted_colors];
2150 * BYTE colorbits[imagesize];
2152 * the following only if the ILC_MASK bit is set in ILHEAD.ilFlags:
2153 * BITMAPFILEHEADER bmfh_mask;
2154 * BITMAPINFOHEADER bmih_mask;
2155 * only if it has a palette (it usually does not):
2156 * RGBQUAD rgbs[nr_of_paletted_colors];
2158 * BYTE maskbits[imagesize];
2160 HIMAGELIST WINAPI ImageList_Read (LPSTREAM pstm)
2166 TRACE("%p\n", pstm);
2168 if (FAILED(IStream_Read (pstm, &ilHead, sizeof(ILHEAD), NULL)))
2170 if (ilHead.usMagic != (('L' << 8) | 'I'))
2172 if (ilHead.usVersion != 0x101) /* probably version? */
2175 TRACE("cx %u, cy %u, flags 0x%04x, cCurImage %u, cMaxImage %u\n",
2176 ilHead.cx, ilHead.cy, ilHead.flags, ilHead.cCurImage, ilHead.cMaxImage);
2178 himl = ImageList_Create(ilHead.cx, ilHead.cy, ilHead.flags, ilHead.cCurImage, ilHead.cMaxImage);
2182 if (!_read_bitmap(himl->hdcImage, pstm))
2184 WARN("failed to read bitmap from stream\n");
2187 if (ilHead.flags & ILC_MASK)
2189 if (!_read_bitmap(himl->hdcMask, pstm))
2191 WARN("failed to read mask bitmap from stream\n");
2196 himl->cCurImage = ilHead.cCurImage;
2197 himl->cMaxImage = ilHead.cMaxImage;
2199 ImageList_SetBkColor(himl,ilHead.bkcolor);
2201 ImageList_SetOverlayImage(himl,ilHead.ovls[i],i+1);
2206 /*************************************************************************
2207 * ImageList_Remove [COMCTL32.@]
2209 * Removes an image from an image list
2212 * himl [I] image list handle
2219 * FIXME: as the image list storage test shows, native comctl32 simply shifts
2220 * images without creating a new bitmap.
2223 ImageList_Remove (HIMAGELIST himl, INT i)
2225 HBITMAP hbmNewImage, hbmNewMask;
2229 TRACE("(himl=%p i=%d)\n", himl, i);
2231 if (!is_valid(himl)) {
2232 ERR("Invalid image list handle!\n");
2236 if ((i < -1) || (i >= himl->cCurImage)) {
2237 TRACE("index out of range! %d\n", i);
2245 if (himl->cCurImage == 0) {
2246 /* remove all on empty ImageList is allowed */
2247 TRACE("remove all on empty ImageList!\n");
2251 himl->cMaxImage = himl->cInitial + himl->cGrow - 1;
2252 himl->cCurImage = 0;
2253 for (nCount = 0; nCount < MAX_OVERLAYIMAGE; nCount++)
2254 himl->nOvlIdx[nCount] = -1;
2256 hbmNewImage = ImageList_CreateImage(himl->hdcImage, himl, himl->cMaxImage);
2257 SelectObject (himl->hdcImage, hbmNewImage);
2258 DeleteObject (himl->hbmImage);
2259 himl->hbmImage = hbmNewImage;
2261 if (himl->hbmMask) {
2263 imagelist_get_bitmap_size(himl, himl->cMaxImage, &sz);
2264 hbmNewMask = CreateBitmap (sz.cx, sz.cy, 1, 1, NULL);
2265 SelectObject (himl->hdcMask, hbmNewMask);
2266 DeleteObject (himl->hbmMask);
2267 himl->hbmMask = hbmNewMask;
2271 /* delete one image */
2272 TRACE("Remove single image! %d\n", i);
2274 /* create new bitmap(s) */
2275 TRACE(" - Number of images: %d / %d (Old/New)\n",
2276 himl->cCurImage, himl->cCurImage - 1);
2278 hbmNewImage = ImageList_CreateImage(himl->hdcImage, himl, himl->cMaxImage);
2280 imagelist_get_bitmap_size(himl, himl->cMaxImage, &sz );
2282 hbmNewMask = CreateBitmap (sz.cx, sz.cy, 1, 1, NULL);
2284 hbmNewMask = 0; /* Just to keep compiler happy! */
2286 hdcBmp = CreateCompatibleDC (0);
2288 /* copy all images and masks prior to the "removed" image */
2290 TRACE("Pre image copy: Copy %d images\n", i);
2292 SelectObject (hdcBmp, hbmNewImage);
2293 imagelist_copy_images( himl, himl->hdcImage, hdcBmp, 0, i, 0 );
2295 if (himl->hbmMask) {
2296 SelectObject (hdcBmp, hbmNewMask);
2297 imagelist_copy_images( himl, himl->hdcMask, hdcBmp, 0, i, 0 );
2301 /* copy all images and masks behind the removed image */
2302 if (i < himl->cCurImage - 1) {
2303 TRACE("Post image copy!\n");
2305 SelectObject (hdcBmp, hbmNewImage);
2306 imagelist_copy_images( himl, himl->hdcImage, hdcBmp, i + 1,
2307 (himl->cCurImage - i), i );
2309 if (himl->hbmMask) {
2310 SelectObject (hdcBmp, hbmNewMask);
2311 imagelist_copy_images( himl, himl->hdcMask, hdcBmp, i + 1,
2312 (himl->cCurImage - i), i );
2318 /* delete old images and insert new ones */
2319 SelectObject (himl->hdcImage, hbmNewImage);
2320 DeleteObject (himl->hbmImage);
2321 himl->hbmImage = hbmNewImage;
2322 if (himl->hbmMask) {
2323 SelectObject (himl->hdcMask, hbmNewMask);
2324 DeleteObject (himl->hbmMask);
2325 himl->hbmMask = hbmNewMask;
2335 /*************************************************************************
2336 * ImageList_Replace [COMCTL32.@]
2338 * Replaces an image in an image list with a new image.
2341 * himl [I] handle to image list
2343 * hbmImage [I] handle to image bitmap
2344 * hbmMask [I] handle to mask bitmap. Can be NULL.
2352 ImageList_Replace (HIMAGELIST himl, INT i, HBITMAP hbmImage,
2359 TRACE("%p %d %p %p\n", himl, i, hbmImage, hbmMask);
2361 if (!is_valid(himl)) {
2362 ERR("Invalid image list handle!\n");
2366 if ((i >= himl->cMaxImage) || (i < 0)) {
2367 ERR("Invalid image index!\n");
2371 if (!GetObjectW(hbmImage, sizeof(BITMAP), &bmp))
2374 hdcImage = CreateCompatibleDC (0);
2377 SelectObject (hdcImage, hbmImage);
2379 if (add_with_alpha( himl, hdcImage, i, 1, bmp.bmWidth, bmp.bmHeight, hbmImage, hbmMask ))
2382 imagelist_point_from_index(himl, i, &pt);
2383 StretchBlt (himl->hdcImage, pt.x, pt.y, himl->cx, himl->cy,
2384 hdcImage, 0, 0, bmp.bmWidth, bmp.bmHeight, SRCCOPY);
2389 HBITMAP hOldBitmapTemp;
2391 hdcTemp = CreateCompatibleDC(0);
2392 hOldBitmapTemp = SelectObject(hdcTemp, hbmMask);
2394 StretchBlt (himl->hdcMask, pt.x, pt.y, himl->cx, himl->cy,
2395 hdcTemp, 0, 0, bmp.bmWidth, bmp.bmHeight, SRCCOPY);
2396 SelectObject(hdcTemp, hOldBitmapTemp);
2399 /* Remove the background from the image
2401 BitBlt (himl->hdcImage, pt.x, pt.y, bmp.bmWidth, bmp.bmHeight,
2402 himl->hdcMask, pt.x, pt.y, 0x220326); /* NOTSRCAND */
2406 DeleteDC (hdcImage);
2412 /*************************************************************************
2413 * ImageList_ReplaceIcon [COMCTL32.@]
2415 * Replaces an image in an image list using an icon.
2418 * himl [I] handle to image list
2420 * hIcon [I] handle to icon
2423 * Success: index of the replaced image
2428 ImageList_ReplaceIcon (HIMAGELIST himl, INT nIndex, HICON hIcon)
2437 TRACE("(%p %d %p)\n", himl, nIndex, hIcon);
2439 if (!is_valid(himl)) {
2440 ERR("invalid image list\n");
2443 if ((nIndex >= himl->cMaxImage) || (nIndex < -1)) {
2444 ERR("invalid image index %d / %d\n", nIndex, himl->cMaxImage);
2448 hBestFitIcon = CopyImage(
2451 LR_COPYFROMRESOURCE);
2452 /* the above will fail if the icon wasn't loaded from a resource, so try
2453 * again without LR_COPYFROMRESOURCE flag */
2455 hBestFitIcon = CopyImage(
2462 ret = GetIconInfo (hBestFitIcon, &ii);
2464 DestroyIcon(hBestFitIcon);
2468 ret = GetObjectW (ii.hbmMask, sizeof(BITMAP), &bmp);
2470 ERR("couldn't get mask bitmap info\n");
2472 DeleteObject (ii.hbmColor);
2474 DeleteObject (ii.hbmMask);
2475 DestroyIcon(hBestFitIcon);
2480 if (himl->cCurImage + 1 > himl->cMaxImage)
2481 IMAGELIST_InternalExpandBitmaps(himl, 1);
2483 nIndex = himl->cCurImage;
2487 hdcImage = CreateCompatibleDC (0);
2488 TRACE("hdcImage=%p\n", hdcImage);
2490 ERR("invalid hdcImage!\n");
2492 if (himl->has_alpha)
2496 UINT height = bmp.bmHeight / 2;
2497 HDC hdcMask = CreateCompatibleDC( 0 );
2498 HBITMAP color = CreateBitmap( bmp.bmWidth, height, 1, 1, NULL );
2499 SelectObject( hdcImage, color );
2500 SelectObject( hdcMask, ii.hbmMask );
2501 BitBlt( hdcImage, 0, 0, bmp.bmWidth, height, hdcMask, 0, height, SRCCOPY );
2502 ret = add_with_alpha( himl, hdcImage, nIndex, 1, bmp.bmWidth, height, color, ii.hbmMask );
2503 DeleteDC( hdcMask );
2504 DeleteObject( color );
2507 else if (add_with_alpha( himl, hdcImage, nIndex, 1, bmp.bmWidth, bmp.bmHeight,
2508 ii.hbmColor, ii.hbmMask )) goto done;
2511 imagelist_point_from_index(himl, nIndex, &pt);
2513 SetTextColor(himl->hdcImage, RGB(0,0,0));
2514 SetBkColor (himl->hdcImage, RGB(255,255,255));
2518 SelectObject (hdcImage, ii.hbmColor);
2519 StretchBlt (himl->hdcImage, pt.x, pt.y, himl->cx, himl->cy,
2520 hdcImage, 0, 0, bmp.bmWidth, bmp.bmHeight, SRCCOPY);
2523 SelectObject (hdcImage, ii.hbmMask);
2524 StretchBlt (himl->hdcMask, pt.x, pt.y, himl->cx, himl->cy,
2525 hdcImage, 0, 0, bmp.bmWidth, bmp.bmHeight, SRCCOPY);
2530 UINT height = bmp.bmHeight / 2;
2531 SelectObject (hdcImage, ii.hbmMask);
2532 StretchBlt (himl->hdcImage, pt.x, pt.y, himl->cx, himl->cy,
2533 hdcImage, 0, height, bmp.bmWidth, height, SRCCOPY);
2535 StretchBlt (himl->hdcMask, pt.x, pt.y, himl->cx, himl->cy,
2536 hdcImage, 0, 0, bmp.bmWidth, height, SRCCOPY);
2540 DestroyIcon(hBestFitIcon);
2542 DeleteDC (hdcImage);
2544 DeleteObject (ii.hbmColor);
2546 DeleteObject (ii.hbmMask);
2548 TRACE("Insert index = %d, himl->cCurImage = %d\n", nIndex, himl->cCurImage);
2553 /*************************************************************************
2554 * ImageList_SetBkColor [COMCTL32.@]
2556 * Sets the background color of an image list.
2559 * himl [I] handle to image list
2560 * clrBk [I] background color
2563 * Success: previous background color
2568 ImageList_SetBkColor (HIMAGELIST himl, COLORREF clrBk)
2572 if (!is_valid(himl))
2575 clrOldBk = himl->clrBk;
2576 himl->clrBk = clrBk;
2581 /*************************************************************************
2582 * ImageList_SetDragCursorImage [COMCTL32.@]
2584 * Combines the specified image with the current drag image
2587 * himlDrag [I] handle to drag image list
2588 * iDrag [I] drag image index
2589 * dxHotspot [I] X position of the hot spot
2590 * dyHotspot [I] Y position of the hot spot
2597 * - The names dxHotspot, dyHotspot are misleading because they have nothing
2598 * to do with a hotspot but are only the offset of the origin of the new
2599 * image relative to the origin of the old image.
2601 * - When this function is called and the drag image is visible, a
2602 * short flickering occurs but this matches the Win9x behavior. It is
2603 * possible to fix the flickering using code like in ImageList_DragMove.
2607 ImageList_SetDragCursorImage (HIMAGELIST himlDrag, INT iDrag,
2608 INT dxHotspot, INT dyHotspot)
2610 HIMAGELIST himlTemp;
2613 if (!is_valid(InternalDrag.himl) || !is_valid(himlDrag))
2616 TRACE(" dxH=%d dyH=%d nX=%d nY=%d\n",
2617 dxHotspot, dyHotspot, InternalDrag.dxHotspot, InternalDrag.dyHotspot);
2619 visible = InternalDrag.bShow;
2621 himlTemp = ImageList_Merge (InternalDrag.himl, 0, himlDrag, iDrag,
2622 dxHotspot, dyHotspot);
2625 /* hide the drag image */
2626 ImageList_DragShowNolock(FALSE);
2628 if ((InternalDrag.himl->cx != himlTemp->cx) ||
2629 (InternalDrag.himl->cy != himlTemp->cy)) {
2630 /* the size of the drag image changed, invalidate the buffer */
2631 DeleteObject(InternalDrag.hbmBg);
2632 InternalDrag.hbmBg = 0;
2635 ImageList_Destroy (InternalDrag.himl);
2636 InternalDrag.himl = himlTemp;
2639 /* show the drag image */
2640 ImageList_DragShowNolock(TRUE);
2647 /*************************************************************************
2648 * ImageList_SetFilter [COMCTL32.@]
2650 * Sets a filter (or does something completely different)!!???
2651 * It removes 12 Bytes from the stack (3 Parameters).
2654 * himl [I] SHOULD be a handle to image list
2655 * i [I] COULD be an index?
2660 * Failure: FALSE ???
2663 * This is an UNDOCUMENTED function!!!!
2668 ImageList_SetFilter (HIMAGELIST himl, INT i, DWORD dwFilter)
2670 FIXME("(%p 0x%x 0x%x):empty stub!\n", himl, i, dwFilter);
2676 /*************************************************************************
2677 * ImageList_SetFlags [COMCTL32.@]
2679 * Sets the image list flags.
2682 * himl [I] Handle to image list
2683 * flags [I] Flags to set
2693 ImageList_SetFlags(HIMAGELIST himl, DWORD flags)
2695 FIXME("(%p %08x):empty stub\n", himl, flags);
2700 /*************************************************************************
2701 * ImageList_SetIconSize [COMCTL32.@]
2703 * Sets the image size of the bitmap and deletes all images.
2706 * himl [I] handle to image list
2707 * cx [I] image width
2708 * cy [I] image height
2716 ImageList_SetIconSize (HIMAGELIST himl, INT cx, INT cy)
2721 if (!is_valid(himl))
2724 /* remove all images */
2725 himl->cMaxImage = himl->cInitial + 1;
2726 himl->cCurImage = 0;
2730 /* initialize overlay mask indices */
2731 for (nCount = 0; nCount < MAX_OVERLAYIMAGE; nCount++)
2732 himl->nOvlIdx[nCount] = -1;
2734 hbmNew = ImageList_CreateImage(himl->hdcImage, himl, himl->cMaxImage);
2735 SelectObject (himl->hdcImage, hbmNew);
2736 DeleteObject (himl->hbmImage);
2737 himl->hbmImage = hbmNew;
2739 if (himl->hbmMask) {
2741 imagelist_get_bitmap_size(himl, himl->cMaxImage, &sz);
2742 hbmNew = CreateBitmap (sz.cx, sz.cy, 1, 1, NULL);
2743 SelectObject (himl->hdcMask, hbmNew);
2744 DeleteObject (himl->hbmMask);
2745 himl->hbmMask = hbmNew;
2752 /*************************************************************************
2753 * ImageList_SetImageCount [COMCTL32.@]
2755 * Resizes an image list to the specified number of images.
2758 * himl [I] handle to image list
2759 * iImageCount [I] number of images in the image list
2767 ImageList_SetImageCount (HIMAGELIST himl, UINT iImageCount)
2770 HBITMAP hbmNewBitmap, hbmOld;
2771 INT nNewCount, nCopyCount;
2773 TRACE("%p %d\n",himl,iImageCount);
2775 if (!is_valid(himl))
2777 if (himl->cMaxImage > iImageCount)
2779 himl->cCurImage = iImageCount;
2780 /* TODO: shrink the bitmap when cMaxImage-cCurImage>cGrow ? */
2784 nNewCount = iImageCount + himl->cGrow;
2785 nCopyCount = min(himl->cCurImage, iImageCount);
2787 hdcBitmap = CreateCompatibleDC (0);
2789 hbmNewBitmap = ImageList_CreateImage(hdcBitmap, himl, nNewCount);
2791 if (hbmNewBitmap != 0)
2793 hbmOld = SelectObject (hdcBitmap, hbmNewBitmap);
2794 imagelist_copy_images( himl, himl->hdcImage, hdcBitmap, 0, nCopyCount, 0 );
2795 SelectObject (hdcBitmap, hbmOld);
2797 /* FIXME: delete 'empty' image space? */
2799 SelectObject (himl->hdcImage, hbmNewBitmap);
2800 DeleteObject (himl->hbmImage);
2801 himl->hbmImage = hbmNewBitmap;
2804 ERR("Could not create new image bitmap !\n");
2809 imagelist_get_bitmap_size( himl, nNewCount, &sz );
2810 hbmNewBitmap = CreateBitmap (sz.cx, sz.cy, 1, 1, NULL);
2811 if (hbmNewBitmap != 0)
2813 hbmOld = SelectObject (hdcBitmap, hbmNewBitmap);
2814 imagelist_copy_images( himl, himl->hdcMask, hdcBitmap, 0, nCopyCount, 0 );
2815 SelectObject (hdcBitmap, hbmOld);
2817 /* FIXME: delete 'empty' image space? */
2819 SelectObject (himl->hdcMask, hbmNewBitmap);
2820 DeleteObject (himl->hbmMask);
2821 himl->hbmMask = hbmNewBitmap;
2824 ERR("Could not create new mask bitmap!\n");
2827 DeleteDC (hdcBitmap);
2829 if (himl->has_alpha)
2831 char *new_alpha = HeapReAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, himl->has_alpha, nNewCount );
2832 if (new_alpha) himl->has_alpha = new_alpha;
2835 HeapFree( GetProcessHeap(), 0, himl->has_alpha );
2836 himl->has_alpha = NULL;
2840 /* Update max image count and current image count */
2841 himl->cMaxImage = nNewCount;
2842 himl->cCurImage = iImageCount;
2848 /*************************************************************************
2849 * ImageList_SetOverlayImage [COMCTL32.@]
2851 * Assigns an overlay mask index to an existing image in an image list.
2854 * himl [I] handle to image list
2855 * iImage [I] image index
2856 * iOverlay [I] overlay mask index
2864 ImageList_SetOverlayImage (HIMAGELIST himl, INT iImage, INT iOverlay)
2866 if (!is_valid(himl))
2868 if ((iOverlay < 1) || (iOverlay > MAX_OVERLAYIMAGE))
2870 if ((iImage!=-1) && ((iImage < 0) || (iImage > himl->cCurImage)))
2872 himl->nOvlIdx[iOverlay - 1] = iImage;
2878 /* helper for ImageList_Write - write bitmap to pstm
2879 * currently everything is written as 24 bit RGB, except masks
2882 _write_bitmap(HBITMAP hBitmap, LPSTREAM pstm)
2884 LPBITMAPFILEHEADER bmfh;
2885 LPBITMAPINFOHEADER bmih;
2886 LPBYTE data = NULL, lpBits;
2888 INT bitCount, sizeImage, offBits, totalSize;
2890 BOOL result = FALSE;
2892 if (!GetObjectW(hBitmap, sizeof(BITMAP), &bm))
2895 bitCount = bm.bmBitsPixel == 1 ? 1 : 24;
2896 sizeImage = DIB_GetDIBImageBytes(bm.bmWidth, bm.bmHeight, bitCount);
2898 totalSize = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);
2900 totalSize += (1 << bitCount) * sizeof(RGBQUAD);
2901 offBits = totalSize;
2902 totalSize += sizeImage;
2904 data = Alloc(totalSize);
2905 bmfh = (LPBITMAPFILEHEADER)data;
2906 bmih = (LPBITMAPINFOHEADER)(data + sizeof(BITMAPFILEHEADER));
2907 lpBits = data + offBits;
2909 /* setup BITMAPFILEHEADER */
2910 bmfh->bfType = (('M' << 8) | 'B');
2911 bmfh->bfSize = offBits;
2912 bmfh->bfReserved1 = 0;
2913 bmfh->bfReserved2 = 0;
2914 bmfh->bfOffBits = offBits;
2916 /* setup BITMAPINFOHEADER */
2917 bmih->biSize = sizeof(BITMAPINFOHEADER);
2918 bmih->biWidth = bm.bmWidth;
2919 bmih->biHeight = bm.bmHeight;
2921 bmih->biBitCount = bitCount;
2922 bmih->biCompression = BI_RGB;
2923 bmih->biSizeImage = sizeImage;
2924 bmih->biXPelsPerMeter = 0;
2925 bmih->biYPelsPerMeter = 0;
2926 bmih->biClrUsed = 0;
2927 bmih->biClrImportant = 0;
2930 result = GetDIBits(xdc, hBitmap, 0, bm.bmHeight, lpBits, (BITMAPINFO *)bmih, DIB_RGB_COLORS) == bm.bmHeight;
2935 TRACE("width %u, height %u, planes %u, bpp %u\n",
2936 bmih->biWidth, bmih->biHeight,
2937 bmih->biPlanes, bmih->biBitCount);
2941 LPBITMAPINFO inf = (LPBITMAPINFO)bmih;
2942 inf->bmiColors[0].rgbRed = inf->bmiColors[0].rgbGreen = inf->bmiColors[0].rgbBlue = 0;
2943 inf->bmiColors[1].rgbRed = inf->bmiColors[1].rgbGreen = inf->bmiColors[1].rgbBlue = 0xff;
2946 if(FAILED(IStream_Write(pstm, data, totalSize, NULL)))
2958 /*************************************************************************
2959 * ImageList_Write [COMCTL32.@]
2961 * Writes an image list to a stream.
2964 * himl [I] handle to image list
2965 * pstm [O] Pointer to a stream.
2976 ImageList_Write (HIMAGELIST himl, LPSTREAM pstm)
2981 TRACE("%p %p\n", himl, pstm);
2983 if (!is_valid(himl))
2986 ilHead.usMagic = (('L' << 8) | 'I');
2987 ilHead.usVersion = 0x101;
2988 ilHead.cCurImage = himl->cCurImage;
2989 ilHead.cMaxImage = himl->cMaxImage;
2990 ilHead.cGrow = himl->cGrow;
2991 ilHead.cx = himl->cx;
2992 ilHead.cy = himl->cy;
2993 ilHead.bkcolor = himl->clrBk;
2994 ilHead.flags = himl->flags;
2995 for(i = 0; i < 4; i++) {
2996 ilHead.ovls[i] = himl->nOvlIdx[i];
2999 TRACE("cx %u, cy %u, flags 0x04%x, cCurImage %u, cMaxImage %u\n",
3000 ilHead.cx, ilHead.cy, ilHead.flags, ilHead.cCurImage, ilHead.cMaxImage);
3002 if(FAILED(IStream_Write(pstm, &ilHead, sizeof(ILHEAD), NULL)))
3005 /* write the bitmap */
3006 if(!_write_bitmap(himl->hbmImage, pstm))
3009 /* write the mask if we have one */
3010 if(himl->flags & ILC_MASK) {
3011 if(!_write_bitmap(himl->hbmMask, pstm))
3019 static HBITMAP ImageList_CreateImage(HDC hdc, HIMAGELIST himl, UINT count)
3021 HBITMAP hbmNewBitmap;
3022 UINT ilc = (himl->flags & 0xFE);
3025 imagelist_get_bitmap_size( himl, count, &sz );
3027 if ((ilc >= ILC_COLOR4 && ilc <= ILC_COLOR32) || ilc == ILC_COLOR)
3032 TRACE("Creating DIBSection %d x %d, %d Bits per Pixel\n",
3033 sz.cx, sz.cy, himl->uBitsPixel);
3035 if (himl->uBitsPixel <= ILC_COLOR8)
3041 colors = 1 << himl->uBitsPixel;
3042 bmi = Alloc(sizeof(BITMAPINFOHEADER) +
3043 sizeof(PALETTEENTRY) * colors);
3045 pal = (LPPALETTEENTRY)bmi->bmiColors;
3046 GetPaletteEntries(GetStockObject(DEFAULT_PALETTE), 0, colors, pal);
3048 /* Swap colors returned by GetPaletteEntries so we can use them for
3049 * CreateDIBSection call. */
3050 for (i = 0; i < colors; i++)
3052 temp = pal[i].peBlue;
3053 bmi->bmiColors[i].rgbRed = pal[i].peRed;
3054 bmi->bmiColors[i].rgbBlue = temp;
3059 bmi = Alloc(sizeof(BITMAPINFOHEADER));
3062 bmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
3063 bmi->bmiHeader.biWidth = sz.cx;
3064 bmi->bmiHeader.biHeight = sz.cy;
3065 bmi->bmiHeader.biPlanes = 1;
3066 bmi->bmiHeader.biBitCount = himl->uBitsPixel;
3067 bmi->bmiHeader.biCompression = BI_RGB;
3068 bmi->bmiHeader.biSizeImage = 0;
3069 bmi->bmiHeader.biXPelsPerMeter = 0;
3070 bmi->bmiHeader.biYPelsPerMeter = 0;
3071 bmi->bmiHeader.biClrUsed = 0;
3072 bmi->bmiHeader.biClrImportant = 0;
3074 hbmNewBitmap = CreateDIBSection(hdc, bmi, DIB_RGB_COLORS, &bits, 0, 0);
3078 else /*if (ilc == ILC_COLORDDB)*/
3080 TRACE("Creating Bitmap: %d Bits per Pixel\n", himl->uBitsPixel);
3082 hbmNewBitmap = CreateBitmap (sz.cx, sz.cy, 1, himl->uBitsPixel, NULL);
3084 TRACE("returning %p\n", hbmNewBitmap);
3085 return hbmNewBitmap;
3088 /*************************************************************************
3089 * ImageList_SetColorTable [COMCTL32.@]
3091 * Sets the color table of an image list.
3094 * himl [I] Handle to the image list.
3095 * uStartIndex [I] The first index to set.
3096 * cEntries [I] Number of entries to set.
3097 * prgb [I] New color information for color table for the image list.
3100 * Success: Number of entries in the table that were set.
3104 * ImageList_Create(), SetDIBColorTable()
3108 ImageList_SetColorTable (HIMAGELIST himl, UINT uStartIndex, UINT cEntries, CONST RGBQUAD * prgb)
3110 return SetDIBColorTable(himl->hdcImage, uStartIndex, cEntries, prgb);
3113 /*************************************************************************
3114 * ImageList_CoCreateInstance [COMCTL32.@]
3116 * Creates a new imagelist instance and returns an interface pointer to it.
3119 * rclsid [I] A reference to the CLSID (CLSID_ImageList).
3120 * punkOuter [I] Pointer to IUnknown interface for aggregation, if desired
3121 * riid [I] Identifier of the requested interface.
3122 * ppv [O] Returns the address of the pointer requested, or NULL.
3126 * Failure: Error value.
3129 ImageList_CoCreateInstance (REFCLSID rclsid, const IUnknown *punkOuter, REFIID riid, void **ppv)
3131 TRACE("(%s,%p,%s,%p)\n", debugstr_guid(rclsid), punkOuter, debugstr_guid(riid), ppv);
3133 if (!IsEqualCLSID(&CLSID_ImageList, rclsid))
3134 return E_NOINTERFACE;
3136 return ImageListImpl_CreateInstance(punkOuter, riid, ppv);
3140 /*************************************************************************
3141 * IImageList implementation
3144 static HRESULT WINAPI ImageListImpl_QueryInterface(IImageList *iface,
3145 REFIID iid, void **ppv)
3147 HIMAGELIST This = (HIMAGELIST) iface;
3148 TRACE("(%p,%s,%p)\n", iface, debugstr_guid(iid), ppv);
3150 if (!ppv) return E_INVALIDARG;
3152 if (IsEqualIID(&IID_IUnknown, iid) || IsEqualIID(&IID_IImageList, iid))
3157 return E_NOINTERFACE;
3160 IUnknown_AddRef((IUnknown*)*ppv);
3164 static ULONG WINAPI ImageListImpl_AddRef(IImageList *iface)
3166 HIMAGELIST This = (HIMAGELIST) iface;
3167 ULONG ref = InterlockedIncrement(&This->ref);
3169 TRACE("(%p) refcount=%u\n", iface, ref);
3173 static ULONG WINAPI ImageListImpl_Release(IImageList *iface)
3175 HIMAGELIST This = (HIMAGELIST) iface;
3176 ULONG ref = InterlockedDecrement(&This->ref);
3178 TRACE("(%p) refcount=%u\n", iface, ref);
3182 /* delete image bitmaps */
3183 if (This->hbmImage) DeleteObject (This->hbmImage);
3184 if (This->hbmMask) DeleteObject (This->hbmMask);
3186 /* delete image & mask DCs */
3187 if (This->hdcImage) DeleteDC (This->hdcImage);
3188 if (This->hdcMask) DeleteDC (This->hdcMask);
3190 /* delete blending brushes */
3191 if (This->hbrBlend25) DeleteObject (This->hbrBlend25);
3192 if (This->hbrBlend50) DeleteObject (This->hbrBlend50);
3194 This->lpVtbl = NULL;
3195 HeapFree(GetProcessHeap(), 0, This->has_alpha);
3196 HeapFree(GetProcessHeap(), 0, This);
3202 static HRESULT WINAPI ImageListImpl_Add(IImageList *iface, HBITMAP hbmImage,
3203 HBITMAP hbmMask, int *pi)
3205 HIMAGELIST This = (HIMAGELIST) iface;
3211 ret = ImageList_Add(This, hbmImage, hbmMask);
3220 static HRESULT WINAPI ImageListImpl_ReplaceIcon(IImageList *iface, int i,
3221 HICON hicon, int *pi)
3223 HIMAGELIST This = (HIMAGELIST) iface;
3229 ret = ImageList_ReplaceIcon(This, i, hicon);
3238 static HRESULT WINAPI ImageListImpl_SetOverlayImage(IImageList *iface,
3239 int iImage, int iOverlay)
3241 return ImageList_SetOverlayImage((HIMAGELIST) iface, iImage, iOverlay)
3245 static HRESULT WINAPI ImageListImpl_Replace(IImageList *iface, int i,
3246 HBITMAP hbmImage, HBITMAP hbmMask)
3248 return ImageList_Replace((HIMAGELIST) iface, i, hbmImage, hbmMask) ? S_OK :
3252 static HRESULT WINAPI ImageListImpl_AddMasked(IImageList *iface, HBITMAP hbmImage,
3253 COLORREF crMask, int *pi)
3255 HIMAGELIST This = (HIMAGELIST) iface;
3261 ret = ImageList_AddMasked(This, hbmImage, crMask);
3270 static HRESULT WINAPI ImageListImpl_Draw(IImageList *iface,
3271 IMAGELISTDRAWPARAMS *pimldp)
3273 HIMAGELIST This = (HIMAGELIST) iface;
3274 HIMAGELIST old_himl;
3277 /* As far as I can tell, Windows simply ignores the contents of pimldp->himl
3278 so we shall simulate the same */
3279 old_himl = pimldp->himl;
3280 pimldp->himl = This;
3282 ret = ImageList_DrawIndirect(pimldp);
3284 pimldp->himl = old_himl;
3285 return ret ? S_OK : E_INVALIDARG;
3288 static HRESULT WINAPI ImageListImpl_Remove(IImageList *iface, int i)
3290 return (ImageList_Remove((HIMAGELIST) iface, i) == 0) ? E_INVALIDARG : S_OK;
3293 static HRESULT WINAPI ImageListImpl_GetIcon(IImageList *iface, int i, UINT flags,
3301 hIcon = ImageList_GetIcon((HIMAGELIST) iface, i, flags);
3310 static HRESULT WINAPI ImageListImpl_GetImageInfo(IImageList *iface, int i,
3311 IMAGEINFO *pImageInfo)
3313 return ImageList_GetImageInfo((HIMAGELIST) iface, i, pImageInfo) ? S_OK : E_FAIL;
3316 static HRESULT WINAPI ImageListImpl_Copy(IImageList *iface, int iDst,
3317 IUnknown *punkSrc, int iSrc, UINT uFlags)
3319 HIMAGELIST This = (HIMAGELIST) iface;
3320 IImageList *src = NULL;
3326 /* TODO: Add test for IID_ImageList2 too */
3327 if (FAILED(IImageList_QueryInterface(punkSrc, &IID_IImageList,
3331 if (ImageList_Copy(This, iDst, (HIMAGELIST) src, iSrc, uFlags))
3336 IImageList_Release(src);
3340 static HRESULT WINAPI ImageListImpl_Merge(IImageList *iface, int i1,
3341 IUnknown *punk2, int i2, int dx, int dy, REFIID riid, void **ppv)
3343 HIMAGELIST This = (HIMAGELIST) iface;
3344 IImageList *iml2 = NULL;
3346 HRESULT ret = E_FAIL;
3348 TRACE("(%p)->(%d %p %d %d %d %s %p)\n", iface, i1, punk2, i2, dx, dy, debugstr_guid(riid), ppv);
3350 /* TODO: Add test for IID_ImageList2 too */
3351 if (FAILED(IImageList_QueryInterface(punk2, &IID_IImageList,
3355 hNew = ImageList_Merge(This, i1, (HIMAGELIST) iml2, i2, dx, dy);
3357 /* Get the interface for the new image list */
3360 IImageList *imerge = (IImageList*)hNew;
3362 ret = HIMAGELIST_QueryInterface(hNew, riid, ppv);
3363 IImageList_Release(imerge);
3366 IImageList_Release(iml2);
3370 static HRESULT WINAPI ImageListImpl_Clone(IImageList *iface, REFIID riid, void **ppv)
3372 HIMAGELIST This = (HIMAGELIST) iface;
3374 HRESULT ret = E_FAIL;
3376 TRACE("(%p)->(%s %p)\n", iface, debugstr_guid(riid), ppv);
3378 clone = ImageList_Duplicate(This);
3380 /* Get the interface for the new image list */
3383 IImageList *iclone = (IImageList*)clone;
3385 ret = HIMAGELIST_QueryInterface(clone, riid, ppv);
3386 IImageList_Release(iclone);
3392 static HRESULT WINAPI ImageListImpl_GetImageRect(IImageList *iface, int i,
3395 HIMAGELIST This = (HIMAGELIST) iface;
3401 if (!ImageList_GetImageInfo(This, i, &info))
3404 return CopyRect(prc, &info.rcImage) ? S_OK : E_FAIL;
3407 static HRESULT WINAPI ImageListImpl_GetIconSize(IImageList *iface, int *cx,
3410 HIMAGELIST This = (HIMAGELIST) iface;
3412 return ImageList_GetIconSize(This, cx, cy) ? S_OK : E_INVALIDARG;
3415 static HRESULT WINAPI ImageListImpl_SetIconSize(IImageList *iface, int cx,
3418 return ImageList_SetIconSize((HIMAGELIST) iface, cx, cy) ? S_OK : E_FAIL;
3421 static HRESULT WINAPI ImageListImpl_GetImageCount(IImageList *iface, int *pi)
3423 *pi = ImageList_GetImageCount((HIMAGELIST) iface);
3427 static HRESULT WINAPI ImageListImpl_SetImageCount(IImageList *iface,
3430 return ImageList_SetImageCount((HIMAGELIST) iface, uNewCount) ? S_OK : E_FAIL;
3433 static HRESULT WINAPI ImageListImpl_SetBkColor(IImageList *iface, COLORREF clrBk,
3436 *pclr = ImageList_SetBkColor((HIMAGELIST) iface, clrBk);
3440 static HRESULT WINAPI ImageListImpl_GetBkColor(IImageList *iface, COLORREF *pclr)
3442 *pclr = ImageList_GetBkColor((HIMAGELIST) iface);
3446 static HRESULT WINAPI ImageListImpl_BeginDrag(IImageList *iface, int iTrack,
3447 int dxHotspot, int dyHotspot)
3449 return ImageList_BeginDrag((HIMAGELIST) iface, iTrack, dxHotspot, dyHotspot) ? S_OK : E_FAIL;
3452 static HRESULT WINAPI ImageListImpl_EndDrag(IImageList *iface)
3454 ImageList_EndDrag();
3458 static HRESULT WINAPI ImageListImpl_DragEnter(IImageList *iface, HWND hwndLock,
3461 return ImageList_DragEnter(hwndLock, x, y) ? S_OK : E_FAIL;
3464 static HRESULT WINAPI ImageListImpl_DragLeave(IImageList *iface, HWND hwndLock)
3466 return ImageList_DragLeave(hwndLock) ? S_OK : E_FAIL;
3469 static HRESULT WINAPI ImageListImpl_DragMove(IImageList *iface, int x, int y)
3471 return ImageList_DragMove(x, y) ? S_OK : E_FAIL;
3474 static HRESULT WINAPI ImageListImpl_SetDragCursorImage(IImageList *iface,
3475 IUnknown *punk, int iDrag, int dxHotspot, int dyHotspot)
3477 IImageList *iml2 = NULL;
3483 /* TODO: Add test for IID_ImageList2 too */
3484 if (FAILED(IImageList_QueryInterface(punk, &IID_IImageList,
3488 ret = ImageList_SetDragCursorImage((HIMAGELIST) iml2, iDrag, dxHotspot,
3491 IImageList_Release(iml2);
3493 return ret ? S_OK : E_FAIL;
3496 static HRESULT WINAPI ImageListImpl_DragShowNolock(IImageList *iface, BOOL fShow)
3498 return ImageList_DragShowNolock(fShow) ? S_OK : E_FAIL;
3501 static HRESULT WINAPI ImageListImpl_GetDragImage(IImageList *iface, POINT *ppt,
3502 POINT *pptHotspot, REFIID riid, PVOID *ppv)
3504 HRESULT ret = E_FAIL;
3510 hNew = ImageList_GetDragImage(ppt, pptHotspot);
3512 /* Get the interface for the new image list */
3515 IImageList *idrag = (IImageList*)hNew;
3517 ret = HIMAGELIST_QueryInterface(hNew, riid, ppv);
3518 IImageList_Release(idrag);
3524 static HRESULT WINAPI ImageListImpl_GetItemFlags(IImageList *iface, int i,
3527 FIXME("STUB: %p %d %p\n", iface, i, dwFlags);
3531 static HRESULT WINAPI ImageListImpl_GetOverlayImage(IImageList *iface, int iOverlay,
3534 HIMAGELIST This = (HIMAGELIST) iface;
3537 if ((iOverlay < 0) || (iOverlay > This->cCurImage))
3540 for (i = 0; i < MAX_OVERLAYIMAGE; i++)
3542 if (This->nOvlIdx[i] == iOverlay)
3553 static const IImageListVtbl ImageListImpl_Vtbl = {
3554 ImageListImpl_QueryInterface,
3555 ImageListImpl_AddRef,
3556 ImageListImpl_Release,
3558 ImageListImpl_ReplaceIcon,
3559 ImageListImpl_SetOverlayImage,
3560 ImageListImpl_Replace,
3561 ImageListImpl_AddMasked,
3563 ImageListImpl_Remove,
3564 ImageListImpl_GetIcon,
3565 ImageListImpl_GetImageInfo,
3567 ImageListImpl_Merge,
3568 ImageListImpl_Clone,
3569 ImageListImpl_GetImageRect,
3570 ImageListImpl_GetIconSize,
3571 ImageListImpl_SetIconSize,
3572 ImageListImpl_GetImageCount,
3573 ImageListImpl_SetImageCount,
3574 ImageListImpl_SetBkColor,
3575 ImageListImpl_GetBkColor,
3576 ImageListImpl_BeginDrag,
3577 ImageListImpl_EndDrag,
3578 ImageListImpl_DragEnter,
3579 ImageListImpl_DragLeave,
3580 ImageListImpl_DragMove,
3581 ImageListImpl_SetDragCursorImage,
3582 ImageListImpl_DragShowNolock,
3583 ImageListImpl_GetDragImage,
3584 ImageListImpl_GetItemFlags,
3585 ImageListImpl_GetOverlayImage
3588 static inline BOOL is_valid(HIMAGELIST himl)
3590 return himl && himl->lpVtbl == &ImageListImpl_Vtbl;
3593 /*************************************************************************
3594 * HIMAGELIST_QueryInterface [COMCTL32.@]
3596 * Returns a pointer to an IImageList or IImageList2 object for the given
3600 * himl [I] Image list handle.
3601 * riid [I] Identifier of the requested interface.
3602 * ppv [O] Returns the address of the pointer requested, or NULL.
3606 * Failure: Error value.
3609 HIMAGELIST_QueryInterface (HIMAGELIST himl, REFIID riid, void **ppv)
3611 TRACE("(%p,%s,%p)\n", himl, debugstr_guid(riid), ppv);
3612 return IImageList_QueryInterface((IImageList *) himl, riid, ppv);
3615 static HRESULT ImageListImpl_CreateInstance(const IUnknown *pUnkOuter, REFIID iid, void** ppv)
3620 TRACE("(%p,%s,%p)\n", pUnkOuter, debugstr_guid(iid), ppv);
3624 if (pUnkOuter) return CLASS_E_NOAGGREGATION;
3626 This = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(struct _IMAGELIST));
3627 if (!This) return E_OUTOFMEMORY;
3629 This->lpVtbl = &ImageListImpl_Vtbl;
3632 ret = IUnknown_QueryInterface((IUnknown*)This, iid, ppv);
3633 IUnknown_Release((IUnknown*)This);