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 )
148 BITMAPINFO *info, *mask_info = NULL;
150 BYTE *mask_bits = NULL;
155 if (!GetObjectW( hbmImage, sizeof(bm), &bm )) return FALSE;
157 /* if neither the imagelist nor the source bitmap can have an alpha channel, bail out now */
158 if (himl->uBitsPixel != 32 && 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(), 0, info->bmiHeader.biSizeImage ))) goto done;
186 if (!GetDIBits( hdc, hbmMask, 0, height, mask_bits, mask_info, DIB_RGB_COLORS )) goto done;
187 hdcMask = CreateCompatibleDC( 0 );
188 SelectObject( hdcMask, hbmMask );
191 for (n = 0; n < count; n++)
195 imagelist_point_from_index( himl, pos + n, &pt );
197 /* check if bitmap has an alpha channel */
198 for (i = 0; i < height && !has_alpha; i++)
199 for (j = n * width; j < (n + 1) * width; j++)
200 if ((has_alpha = ((bits[i * bm.bmWidth + j] & 0xff000000) != 0))) break;
202 if (!has_alpha) /* generate alpha channel from the mask */
204 for (i = 0; i < height; i++)
205 for (j = n * width; j < (n + 1) * width; j++)
206 if (!mask_bits || !((mask_bits[i * mask_width + j / 8] << (j % 8)) & 0x80))
207 bits[i * bm.bmWidth + j] |= 0xff000000;
209 bits[i * bm.bmWidth + j] = 0;
210 if (hdcMask) StretchBlt( himl->hdcMask, pt.x, pt.y, himl->cx, himl->cy,
211 hdcMask, n * width, 0, width, height, SRCCOPY );
215 if (himl->has_alpha) himl->has_alpha[pos + n] = 1;
217 if (mask_info && himl->hbmMask) /* generate the mask from the alpha channel */
219 for (i = 0; i < height; i++)
220 for (j = n * width; j < (n + 1) * width; j++)
221 if ((bits[i * bm.bmWidth + j] >> 24) > 25) /* more than 10% alpha */
222 mask_bits[i * mask_width + j / 8] &= ~(0x80 >> (j % 8));
224 mask_bits[i * mask_width + j / 8] |= 0x80 >> (j % 8);
225 StretchDIBits( himl->hdcMask, pt.x, pt.y, himl->cx, himl->cy,
226 n * width, 0, width, height, mask_bits, mask_info, DIB_RGB_COLORS, SRCCOPY );
229 StretchDIBits( himl->hdcImage, pt.x, pt.y, himl->cx, himl->cy,
230 n * width, 0, width, height, bits, info, DIB_RGB_COLORS, SRCCOPY );
236 if (hdcMask) DeleteDC( hdcMask );
237 HeapFree( GetProcessHeap(), 0, info );
238 HeapFree( GetProcessHeap(), 0, mask_info );
239 HeapFree( GetProcessHeap(), 0, bits );
240 HeapFree( GetProcessHeap(), 0, mask_bits );
244 /*************************************************************************
245 * IMAGELIST_InternalExpandBitmaps [Internal]
247 * Expands the bitmaps of an image list by the given number of images.
250 * himl [I] handle to image list
251 * nImageCount [I] number of images to add
257 * This function CANNOT be used to reduce the number of images.
260 IMAGELIST_InternalExpandBitmaps(HIMAGELIST himl, INT nImageCount)
263 HBITMAP hbmNewBitmap, hbmNull;
267 TRACE("%p has %d allocated %d images\n", himl, himl->cCurImage, himl->cMaxImage);
269 if (himl->cCurImage + nImageCount <= himl->cMaxImage)
272 nNewCount = himl->cCurImage + max(nImageCount, himl->cGrow) + 1;
274 imagelist_get_bitmap_size(himl, nNewCount, &sz);
276 TRACE("Create expanded bitmaps : himl=%p x=%d y=%d count=%d\n", himl, sz.cx, sz.cy, nNewCount);
277 hdcBitmap = CreateCompatibleDC (0);
279 hbmNewBitmap = ImageList_CreateImage(hdcBitmap, himl, nNewCount);
281 if (hbmNewBitmap == 0)
282 ERR("creating new image bitmap (x=%d y=%d)!\n", sz.cx, sz.cy);
286 hbmNull = SelectObject (hdcBitmap, hbmNewBitmap);
287 BitBlt (hdcBitmap, 0, 0, sz.cx, sz.cy,
288 himl->hdcImage, 0, 0, SRCCOPY);
289 SelectObject (hdcBitmap, hbmNull);
291 SelectObject (himl->hdcImage, hbmNewBitmap);
292 DeleteObject (himl->hbmImage);
293 himl->hbmImage = hbmNewBitmap;
295 if (himl->flags & ILC_MASK)
297 hbmNewBitmap = CreateBitmap (sz.cx, sz.cy, 1, 1, NULL);
299 if (hbmNewBitmap == 0)
300 ERR("creating new mask bitmap!\n");
304 hbmNull = SelectObject (hdcBitmap, hbmNewBitmap);
305 BitBlt (hdcBitmap, 0, 0, sz.cx, sz.cy,
306 himl->hdcMask, 0, 0, SRCCOPY);
307 SelectObject (hdcBitmap, hbmNull);
309 SelectObject (himl->hdcMask, hbmNewBitmap);
310 DeleteObject (himl->hbmMask);
311 himl->hbmMask = hbmNewBitmap;
316 char *new_alpha = HeapReAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, himl->has_alpha, nNewCount );
317 if (new_alpha) himl->has_alpha = new_alpha;
320 HeapFree( GetProcessHeap(), 0, himl->has_alpha );
321 himl->has_alpha = NULL;
325 himl->cMaxImage = nNewCount;
327 DeleteDC (hdcBitmap);
331 /*************************************************************************
332 * ImageList_Add [COMCTL32.@]
334 * Add an image or images to an image list.
337 * himl [I] handle to image list
338 * hbmImage [I] handle to image bitmap
339 * hbmMask [I] handle to mask bitmap
342 * Success: Index of the first new image.
347 ImageList_Add (HIMAGELIST himl, HBITMAP hbmImage, HBITMAP hbmMask)
349 HDC hdcBitmap, hdcTemp = 0;
350 INT nFirstIndex, nImageCount, i;
354 TRACE("himl=%p hbmimage=%p hbmmask=%p\n", himl, hbmImage, hbmMask);
358 if (!GetObjectW(hbmImage, sizeof(BITMAP), &bmp))
361 TRACE("himl %p, cCurImage %d, cMaxImage %d, cGrow %d, cx %d, cy %d\n",
362 himl, himl->cCurImage, himl->cMaxImage, himl->cGrow, himl->cx, himl->cy);
364 nImageCount = bmp.bmWidth / himl->cx;
366 TRACE("%p has %d images (%d x %d)\n", hbmImage, nImageCount, bmp.bmWidth, bmp.bmHeight);
368 IMAGELIST_InternalExpandBitmaps(himl, nImageCount);
370 hdcBitmap = CreateCompatibleDC(0);
372 SelectObject(hdcBitmap, hbmImage);
374 if (add_with_alpha( himl, hdcBitmap, himl->cCurImage, nImageCount,
375 himl->cx, min( himl->cy, bmp.bmHeight), hbmImage, hbmMask ))
380 hdcTemp = CreateCompatibleDC(0);
381 SelectObject(hdcTemp, hbmMask);
384 for (i=0; i<nImageCount; i++)
386 imagelist_point_from_index( himl, himl->cCurImage + i, &pt );
388 /* Copy result to the imagelist
390 BitBlt( himl->hdcImage, pt.x, pt.y, himl->cx, bmp.bmHeight,
391 hdcBitmap, i*himl->cx, 0, SRCCOPY );
396 BitBlt( himl->hdcMask, pt.x, pt.y, himl->cx, bmp.bmHeight,
397 hdcTemp, i*himl->cx, 0, SRCCOPY );
399 /* Remove the background from the image
401 BitBlt( himl->hdcImage, pt.x, pt.y, himl->cx, bmp.bmHeight,
402 himl->hdcMask, pt.x, pt.y, 0x220326 ); /* NOTSRCAND */
404 if (hdcTemp) DeleteDC(hdcTemp);
409 nFirstIndex = himl->cCurImage;
410 himl->cCurImage += nImageCount;
416 /*************************************************************************
417 * ImageList_AddIcon [COMCTL32.@]
419 * Adds an icon to an image list.
422 * himl [I] handle to image list
423 * hIcon [I] handle to icon
426 * Success: index of the new image
429 #undef ImageList_AddIcon
430 INT WINAPI ImageList_AddIcon (HIMAGELIST himl, HICON hIcon)
432 return ImageList_ReplaceIcon (himl, -1, hIcon);
436 /*************************************************************************
437 * ImageList_AddMasked [COMCTL32.@]
439 * Adds an image or images to an image list and creates a mask from the
440 * specified bitmap using the mask color.
443 * himl [I] handle to image list.
444 * hBitmap [I] handle to bitmap
445 * clrMask [I] mask color.
448 * Success: Index of the first new image.
453 ImageList_AddMasked (HIMAGELIST himl, HBITMAP hBitmap, COLORREF clrMask)
455 HDC hdcMask, hdcBitmap;
461 TRACE("himl=%p hbitmap=%p clrmask=%x\n", himl, hBitmap, clrMask);
465 if (!GetObjectW(hBitmap, sizeof(BITMAP), &bmp))
468 hdcBitmap = CreateCompatibleDC(0);
469 SelectObject(hdcBitmap, hBitmap);
471 /* Create a temp Mask so we can remove the background of the Image */
472 hdcMask = CreateCompatibleDC(0);
473 hMaskBitmap = CreateBitmap(bmp.bmWidth, bmp.bmHeight, 1, 1, NULL);
474 SelectObject(hdcMask, hMaskBitmap);
476 /* create monochrome image to the mask bitmap */
477 bkColor = (clrMask != CLR_DEFAULT) ? clrMask : GetPixel (hdcBitmap, 0, 0);
478 SetBkColor (hdcBitmap, bkColor);
479 BitBlt (hdcMask, 0, 0, bmp.bmWidth, bmp.bmHeight, hdcBitmap, 0, 0, SRCCOPY);
481 SetBkColor(hdcBitmap, RGB(255,255,255));
484 * Remove the background from the image
486 * WINDOWS BUG ALERT!!!!!!
487 * The statement below should not be done in common practice
488 * but this is how ImageList_AddMasked works in Windows.
489 * It overwrites the original bitmap passed, this was discovered
490 * by using the same bitmap to iterate the different styles
491 * on windows where it failed (BUT ImageList_Add is OK)
492 * This is here in case some apps rely on this bug
494 * Blt mode 0x220326 is NOTSRCAND
496 BitBlt(hdcBitmap, 0, 0, bmp.bmWidth, bmp.bmHeight, hdcMask, 0, 0, 0x220326);
501 ret = ImageList_Add( himl, hBitmap, hMaskBitmap );
503 DeleteObject(hMaskBitmap);
508 /*************************************************************************
509 * ImageList_BeginDrag [COMCTL32.@]
511 * Creates a temporary image list that contains one image. It will be used
515 * himlTrack [I] handle to the source image list
516 * iTrack [I] index of the drag image in the source image list
517 * dxHotspot [I] X position of the hot spot of the drag image
518 * dyHotspot [I] Y position of the hot spot of the drag image
526 ImageList_BeginDrag (HIMAGELIST himlTrack, INT iTrack,
527 INT dxHotspot, INT dyHotspot)
531 TRACE("(himlTrack=%p iTrack=%d dx=%d dy=%d)\n", himlTrack, iTrack,
532 dxHotspot, dyHotspot);
534 if (!is_valid(himlTrack))
537 if (InternalDrag.himl)
538 ImageList_EndDrag ();
543 InternalDrag.himl = ImageList_Create (cx, cy, himlTrack->flags, 1, 1);
544 if (InternalDrag.himl == NULL) {
545 WARN("Error creating drag image list!\n");
549 InternalDrag.dxHotspot = dxHotspot;
550 InternalDrag.dyHotspot = dyHotspot;
553 BitBlt (InternalDrag.himl->hdcImage, 0, 0, cx, cy, himlTrack->hdcImage, iTrack * cx, 0, SRCCOPY);
556 BitBlt (InternalDrag.himl->hdcMask, 0, 0, cx, cy, himlTrack->hdcMask, iTrack * cx, 0, SRCCOPY);
558 InternalDrag.himl->cCurImage = 1;
564 /*************************************************************************
565 * ImageList_Copy [COMCTL32.@]
567 * Copies an image of the source image list to an image of the
568 * destination image list. Images can be copied or swapped.
571 * himlDst [I] handle to the destination image list
572 * iDst [I] destination image index.
573 * himlSrc [I] handle to the source image list
574 * iSrc [I] source image index
575 * uFlags [I] flags for the copy operation
582 * Copying from one image list to another is possible. The original
583 * implementation just copies or swaps within one image list.
584 * Could this feature become a bug??? ;-)
588 ImageList_Copy (HIMAGELIST himlDst, INT iDst, HIMAGELIST himlSrc,
589 INT iSrc, UINT uFlags)
593 TRACE("himlDst=%p iDst=%d himlSrc=%p iSrc=%d\n", himlDst, iDst, himlSrc, iSrc);
595 if (!is_valid(himlSrc) || !is_valid(himlDst))
597 if ((iDst < 0) || (iDst >= himlDst->cCurImage))
599 if ((iSrc < 0) || (iSrc >= himlSrc->cCurImage))
602 imagelist_point_from_index( himlDst, iDst, &ptDst );
603 imagelist_point_from_index( himlSrc, iSrc, &ptSrc );
605 if (uFlags & ILCF_SWAP) {
608 HBITMAP hbmTempImage, hbmTempMask;
610 hdcBmp = CreateCompatibleDC (0);
612 /* create temporary bitmaps */
613 hbmTempImage = CreateBitmap (himlSrc->cx, himlSrc->cy, 1,
614 himlSrc->uBitsPixel, NULL);
615 hbmTempMask = CreateBitmap (himlSrc->cx, himlSrc->cy, 1,
618 /* copy (and stretch) destination to temporary bitmaps.(save) */
620 SelectObject (hdcBmp, hbmTempImage);
621 StretchBlt (hdcBmp, 0, 0, himlSrc->cx, himlSrc->cy,
622 himlDst->hdcImage, ptDst.x, ptDst.y, himlDst->cx, himlDst->cy,
625 SelectObject (hdcBmp, hbmTempMask);
626 StretchBlt (hdcBmp, 0, 0, himlSrc->cx, himlSrc->cy,
627 himlDst->hdcMask, ptDst.x, ptDst.y, himlDst->cx, himlDst->cy,
630 /* copy (and stretch) source to destination */
632 StretchBlt (himlDst->hdcImage, ptDst.x, ptDst.y, himlDst->cx, himlDst->cy,
633 himlSrc->hdcImage, ptSrc.x, ptSrc.y, himlSrc->cx, himlSrc->cy,
636 StretchBlt (himlDst->hdcMask, ptDst.x, ptDst.y, himlDst->cx, himlDst->cy,
637 himlSrc->hdcMask, ptSrc.x, ptSrc.y, himlSrc->cx, himlSrc->cy,
640 /* copy (without stretching) temporary bitmaps to source (restore) */
642 BitBlt (himlSrc->hdcMask, ptSrc.x, ptSrc.y, himlSrc->cx, himlSrc->cy,
643 hdcBmp, 0, 0, SRCCOPY);
646 BitBlt (himlSrc->hdcImage, ptSrc.x, ptSrc.y, himlSrc->cx, himlSrc->cy,
647 hdcBmp, 0, 0, SRCCOPY);
648 /* delete temporary bitmaps */
649 DeleteObject (hbmTempMask);
650 DeleteObject (hbmTempImage);
655 StretchBlt (himlDst->hdcImage, ptDst.x, ptDst.y, himlDst->cx, himlDst->cy,
656 himlSrc->hdcImage, ptSrc.x, ptSrc.y, himlSrc->cx, himlSrc->cy,
660 StretchBlt (himlDst->hdcMask, ptDst.x, ptDst.y, himlDst->cx, himlDst->cy,
661 himlSrc->hdcMask, ptSrc.x, ptSrc.y, himlSrc->cx, himlSrc->cy,
669 /*************************************************************************
670 * ImageList_Create [COMCTL32.@]
672 * Creates a new image list.
675 * cx [I] image height
677 * flags [I] creation flags
678 * cInitial [I] initial number of images in the image list
679 * cGrow [I] number of images by which image list grows
682 * Success: Handle to the created image list
686 ImageList_Create (INT cx, INT cy, UINT flags,
687 INT cInitial, INT cGrow)
692 UINT ilc = (flags & 0xFE);
693 static const WORD aBitBlend25[] =
694 {0xAA, 0x00, 0x55, 0x00, 0xAA, 0x00, 0x55, 0x00};
696 static const WORD aBitBlend50[] =
697 {0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA};
699 TRACE("(%d %d 0x%x %d %d)\n", cx, cy, flags, cInitial, cGrow);
701 /* Create the IImageList interface for the image list */
702 if (FAILED(ImageListImpl_CreateInstance(NULL, &IID_IImageList, (void **)&himl)))
705 cGrow = (cGrow < 4) ? 4 : (cGrow + 3) & ~3;
710 himl->cMaxImage = cInitial + 1;
711 himl->cInitial = cInitial;
713 himl->clrFg = CLR_DEFAULT;
714 himl->clrBk = CLR_NONE;
716 /* initialize overlay mask indices */
717 for (nCount = 0; nCount < MAX_OVERLAYIMAGE; nCount++)
718 himl->nOvlIdx[nCount] = -1;
720 /* Create Image & Mask DCs */
721 himl->hdcImage = CreateCompatibleDC (0);
724 if (himl->flags & ILC_MASK){
725 himl->hdcMask = CreateCompatibleDC(0);
730 /* Default to ILC_COLOR4 if none of the ILC_COLOR* flags are specified */
731 if (ilc == ILC_COLOR)
734 if (ilc >= ILC_COLOR4 && ilc <= ILC_COLOR32)
735 himl->uBitsPixel = ilc;
737 himl->uBitsPixel = (UINT)GetDeviceCaps (himl->hdcImage, BITSPIXEL);
739 if (himl->cMaxImage > 0) {
740 himl->hbmImage = ImageList_CreateImage(himl->hdcImage, himl, himl->cMaxImage);
741 SelectObject(himl->hdcImage, himl->hbmImage);
745 if ((himl->cMaxImage > 0) && (himl->flags & ILC_MASK)) {
748 imagelist_get_bitmap_size(himl, himl->cMaxImage, &sz);
749 himl->hbmMask = CreateBitmap (sz.cx, sz.cy, 1, 1, NULL);
750 if (himl->hbmMask == 0) {
751 ERR("Error creating mask bitmap!\n");
754 SelectObject(himl->hdcMask, himl->hbmMask);
759 if (himl->uBitsPixel == 32)
760 himl->has_alpha = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, himl->cMaxImage );
762 himl->has_alpha = NULL;
764 /* create blending brushes */
765 hbmTemp = CreateBitmap (8, 8, 1, 1, aBitBlend25);
766 himl->hbrBlend25 = CreatePatternBrush (hbmTemp);
767 DeleteObject (hbmTemp);
769 hbmTemp = CreateBitmap (8, 8, 1, 1, aBitBlend50);
770 himl->hbrBlend50 = CreatePatternBrush (hbmTemp);
771 DeleteObject (hbmTemp);
773 TRACE("created imagelist %p\n", himl);
777 ImageList_Destroy(himl);
782 /*************************************************************************
783 * ImageList_Destroy [COMCTL32.@]
785 * Destroys an image list.
788 * himl [I] handle to image list
796 ImageList_Destroy (HIMAGELIST himl)
801 IImageList_Release((IImageList *) himl);
806 /*************************************************************************
807 * ImageList_DragEnter [COMCTL32.@]
809 * Locks window update and displays the drag image at the given position.
812 * hwndLock [I] handle of the window that owns the drag image.
813 * x [I] X position of the drag image.
814 * y [I] Y position of the drag image.
821 * The position of the drag image is relative to the window, not
826 ImageList_DragEnter (HWND hwndLock, INT x, INT y)
828 TRACE("(hwnd=%p x=%d y=%d)\n", hwndLock, x, y);
830 if (!is_valid(InternalDrag.himl))
834 InternalDrag.hwnd = hwndLock;
836 InternalDrag.hwnd = GetDesktopWindow ();
841 /* draw the drag image and save the background */
842 if (!ImageList_DragShowNolock(TRUE)) {
850 /*************************************************************************
851 * ImageList_DragLeave [COMCTL32.@]
853 * Unlocks window update and hides the drag image.
856 * hwndLock [I] handle of the window that owns the drag image.
864 ImageList_DragLeave (HWND hwndLock)
866 /* As we don't save drag info in the window this can lead to problems if
867 an app does not supply the same window as DragEnter */
869 InternalDrag.hwnd = hwndLock;
871 InternalDrag.hwnd = GetDesktopWindow (); */
873 hwndLock = GetDesktopWindow();
874 if(InternalDrag.hwnd != hwndLock)
875 FIXME("DragLeave hWnd != DragEnter hWnd\n");
877 ImageList_DragShowNolock (FALSE);
883 /*************************************************************************
884 * ImageList_InternalDragDraw [Internal]
886 * Draws the drag image.
889 * hdc [I] device context to draw into.
890 * x [I] X position of the drag image.
891 * y [I] Y position of the drag image.
898 * The position of the drag image is relative to the window, not
904 ImageList_InternalDragDraw (HDC hdc, INT x, INT y)
906 IMAGELISTDRAWPARAMS imldp;
908 ZeroMemory (&imldp, sizeof(imldp));
909 imldp.cbSize = sizeof(imldp);
910 imldp.himl = InternalDrag.himl;
915 imldp.rgbBk = CLR_DEFAULT;
916 imldp.rgbFg = CLR_DEFAULT;
917 imldp.fStyle = ILD_NORMAL;
918 imldp.fState = ILS_ALPHA;
920 ImageList_DrawIndirect (&imldp);
923 /*************************************************************************
924 * ImageList_DragMove [COMCTL32.@]
926 * Moves the drag image.
929 * x [I] X position of the drag image.
930 * y [I] Y position of the drag image.
937 * The position of the drag image is relative to the window, not
942 ImageList_DragMove (INT x, INT y)
944 TRACE("(x=%d y=%d)\n", x, y);
946 if (!is_valid(InternalDrag.himl))
949 /* draw/update the drag image */
950 if (InternalDrag.bShow) {
954 HBITMAP hbmOffScreen;
955 INT origNewX, origNewY;
956 INT origOldX, origOldY;
957 INT origRegX, origRegY;
958 INT sizeRegX, sizeRegY;
961 /* calculate the update region */
962 origNewX = x - InternalDrag.dxHotspot;
963 origNewY = y - InternalDrag.dyHotspot;
964 origOldX = InternalDrag.x - InternalDrag.dxHotspot;
965 origOldY = InternalDrag.y - InternalDrag.dyHotspot;
966 origRegX = min(origNewX, origOldX);
967 origRegY = min(origNewY, origOldY);
968 sizeRegX = InternalDrag.himl->cx + abs(x - InternalDrag.x);
969 sizeRegY = InternalDrag.himl->cy + abs(y - InternalDrag.y);
971 hdcDrag = GetDCEx(InternalDrag.hwnd, 0,
972 DCX_WINDOW | DCX_CACHE | DCX_LOCKWINDOWUPDATE);
973 hdcOffScreen = CreateCompatibleDC(hdcDrag);
974 hdcBg = CreateCompatibleDC(hdcDrag);
976 hbmOffScreen = CreateCompatibleBitmap(hdcDrag, sizeRegX, sizeRegY);
977 SelectObject(hdcOffScreen, hbmOffScreen);
978 SelectObject(hdcBg, InternalDrag.hbmBg);
980 /* get the actual background of the update region */
981 BitBlt(hdcOffScreen, 0, 0, sizeRegX, sizeRegY, hdcDrag,
982 origRegX, origRegY, SRCCOPY);
983 /* erase the old image */
984 BitBlt(hdcOffScreen, origOldX - origRegX, origOldY - origRegY,
985 InternalDrag.himl->cx, InternalDrag.himl->cy, hdcBg, 0, 0,
987 /* save the background */
988 BitBlt(hdcBg, 0, 0, InternalDrag.himl->cx, InternalDrag.himl->cy,
989 hdcOffScreen, origNewX - origRegX, origNewY - origRegY, SRCCOPY);
991 ImageList_InternalDragDraw(hdcOffScreen, origNewX - origRegX,
992 origNewY - origRegY);
993 /* draw the update region to the screen */
994 BitBlt(hdcDrag, origRegX, origRegY, sizeRegX, sizeRegY,
995 hdcOffScreen, 0, 0, SRCCOPY);
998 DeleteDC(hdcOffScreen);
999 DeleteObject(hbmOffScreen);
1000 ReleaseDC(InternalDrag.hwnd, hdcDrag);
1003 /* update the image position */
1011 /*************************************************************************
1012 * ImageList_DragShowNolock [COMCTL32.@]
1014 * Shows or hides the drag image.
1017 * bShow [I] TRUE shows the drag image, FALSE hides it.
1025 ImageList_DragShowNolock (BOOL bShow)
1031 if (!is_valid(InternalDrag.himl))
1034 TRACE("bShow=0x%X!\n", bShow);
1036 /* DragImage is already visible/hidden */
1037 if ((InternalDrag.bShow && bShow) || (!InternalDrag.bShow && !bShow)) {
1041 /* position of the origin of the DragImage */
1042 x = InternalDrag.x - InternalDrag.dxHotspot;
1043 y = InternalDrag.y - InternalDrag.dyHotspot;
1045 hdcDrag = GetDCEx (InternalDrag.hwnd, 0,
1046 DCX_WINDOW | DCX_CACHE | DCX_LOCKWINDOWUPDATE);
1051 hdcBg = CreateCompatibleDC(hdcDrag);
1052 if (!InternalDrag.hbmBg) {
1053 InternalDrag.hbmBg = CreateCompatibleBitmap(hdcDrag,
1054 InternalDrag.himl->cx, InternalDrag.himl->cy);
1056 SelectObject(hdcBg, InternalDrag.hbmBg);
1059 /* save the background */
1060 BitBlt(hdcBg, 0, 0, InternalDrag.himl->cx, InternalDrag.himl->cy,
1061 hdcDrag, x, y, SRCCOPY);
1062 /* show the image */
1063 ImageList_InternalDragDraw(hdcDrag, x, y);
1065 /* hide the image */
1066 BitBlt(hdcDrag, x, y, InternalDrag.himl->cx, InternalDrag.himl->cy,
1067 hdcBg, 0, 0, SRCCOPY);
1070 InternalDrag.bShow = !InternalDrag.bShow;
1073 ReleaseDC (InternalDrag.hwnd, hdcDrag);
1078 /*************************************************************************
1079 * ImageList_Draw [COMCTL32.@]
1084 * himl [I] handle to image list
1086 * hdc [I] handle to device context
1089 * fStyle [I] drawing flags
1100 ImageList_Draw (HIMAGELIST himl, INT i, HDC hdc, INT x, INT y, UINT fStyle)
1102 return ImageList_DrawEx (himl, i, hdc, x, y, 0, 0,
1103 CLR_DEFAULT, CLR_DEFAULT, fStyle);
1107 /*************************************************************************
1108 * ImageList_DrawEx [COMCTL32.@]
1110 * Draws an image and allows to use extended drawing features.
1113 * himl [I] handle to image list
1115 * hdc [I] handle to device context
1120 * rgbBk [I] background color
1121 * rgbFg [I] foreground color
1122 * fStyle [I] drawing flags
1129 * Calls ImageList_DrawIndirect.
1132 * ImageList_DrawIndirect.
1136 ImageList_DrawEx (HIMAGELIST himl, INT i, HDC hdc, INT x, INT y,
1137 INT dx, INT dy, COLORREF rgbBk, COLORREF rgbFg,
1140 IMAGELISTDRAWPARAMS imldp;
1142 ZeroMemory (&imldp, sizeof(imldp));
1143 imldp.cbSize = sizeof(imldp);
1151 imldp.rgbBk = rgbBk;
1152 imldp.rgbFg = rgbFg;
1153 imldp.fStyle = fStyle;
1155 return ImageList_DrawIndirect (&imldp);
1159 static BOOL alpha_blend_image( HIMAGELIST himl, HDC dest_dc, int dest_x, int dest_y,
1160 int src_x, int src_y, int cx, int cy, BLENDFUNCTION func,
1161 UINT style, COLORREF blend_col )
1165 HBITMAP bmp = 0, mask = 0;
1167 void *bits, *mask_bits;
1171 if (!(hdc = CreateCompatibleDC( 0 ))) return FALSE;
1172 if (!(info = HeapAlloc( GetProcessHeap(), 0, FIELD_OFFSET( BITMAPINFO, bmiColors[256] )))) goto done;
1173 info->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
1174 info->bmiHeader.biWidth = cx;
1175 info->bmiHeader.biHeight = cy;
1176 info->bmiHeader.biPlanes = 1;
1177 info->bmiHeader.biBitCount = 32;
1178 info->bmiHeader.biCompression = BI_RGB;
1179 info->bmiHeader.biSizeImage = cx * cy * 4;
1180 info->bmiHeader.biXPelsPerMeter = 0;
1181 info->bmiHeader.biYPelsPerMeter = 0;
1182 info->bmiHeader.biClrUsed = 0;
1183 info->bmiHeader.biClrImportant = 0;
1184 if (!(bmp = CreateDIBSection( himl->hdcImage, info, DIB_RGB_COLORS, &bits, 0, 0 ))) goto done;
1185 SelectObject( hdc, bmp );
1186 BitBlt( hdc, 0, 0, cx, cy, himl->hdcImage, src_x, src_y, SRCCOPY );
1188 if (blend_col != CLR_NONE)
1190 BYTE r = GetRValue( blend_col );
1191 BYTE g = GetGValue( blend_col );
1192 BYTE b = GetBValue( blend_col );
1194 if (style & ILD_BLEND25)
1196 for (i = 0, ptr = bits; i < cx * cy; i++, ptr++)
1197 *ptr = ((*ptr & 0xff000000) |
1198 ((((*ptr & 0x00ff0000) * 3 + (r << 16)) / 4) & 0x00ff0000) |
1199 ((((*ptr & 0x0000ff00) * 3 + (g << 8)) / 4) & 0x0000ff00) |
1200 ((((*ptr & 0x000000ff) * 3 + (b << 0)) / 4) & 0x000000ff));
1202 else if (style & ILD_BLEND50)
1204 for (i = 0, ptr = bits; i < cx * cy; i++, ptr++)
1205 *ptr = ((*ptr & 0xff000000) |
1206 ((((*ptr & 0x00ff0000) + (r << 16)) / 2) & 0x00ff0000) |
1207 ((((*ptr & 0x0000ff00) + (g << 8)) / 2) & 0x0000ff00) |
1208 ((((*ptr & 0x000000ff) + (b << 0)) / 2) & 0x000000ff));
1212 if (himl->uBitsPixel == 32) /* we already have an alpha channel in this case */
1214 /* pre-multiply by the alpha channel */
1215 for (i = 0, ptr = bits; i < cx * cy; i++, ptr++)
1217 DWORD alpha = *ptr >> 24;
1218 *ptr = ((*ptr & 0xff000000) |
1219 (((*ptr & 0x00ff0000) * alpha / 255) & 0x00ff0000) |
1220 (((*ptr & 0x0000ff00) * alpha / 255) & 0x0000ff00) |
1221 (((*ptr & 0x000000ff) * alpha / 255)));
1224 else if (himl->hbmMask)
1226 unsigned int width_bytes = (cx + 31) / 32 * 4;
1227 /* generate alpha channel from the mask */
1228 info->bmiHeader.biBitCount = 1;
1229 info->bmiHeader.biSizeImage = width_bytes * cy;
1230 if (!(mask = CreateDIBSection( himl->hdcMask, info, DIB_RGB_COLORS, &mask_bits, 0, 0 )))
1232 SelectObject( hdc, mask );
1233 BitBlt( hdc, 0, 0, cx, cy, himl->hdcMask, src_x, src_y, SRCCOPY );
1234 SelectObject( hdc, bmp );
1235 for (i = 0, ptr = bits; i < cy; i++)
1236 for (j = 0; j < cx; j++, ptr++)
1237 if ((((BYTE *)mask_bits)[i * width_bytes + j / 8] << (j % 8)) & 0x80) *ptr = 0;
1238 else *ptr |= 0xff000000;
1241 ret = GdiAlphaBlend( dest_dc, dest_x, dest_y, cx, cy, hdc, 0, 0, cx, cy, func );
1245 if (bmp) DeleteObject( bmp );
1246 if (mask) DeleteObject( mask );
1247 HeapFree( GetProcessHeap(), 0, info );
1251 /*************************************************************************
1252 * ImageList_DrawIndirect [COMCTL32.@]
1254 * Draws an image using various parameters specified in pimldp.
1257 * pimldp [I] pointer to IMAGELISTDRAWPARAMS structure.
1265 ImageList_DrawIndirect (IMAGELISTDRAWPARAMS *pimldp)
1267 INT cx, cy, nOvlIdx;
1268 DWORD fState, dwRop;
1270 COLORREF oldImageBk, oldImageFg;
1271 HDC hImageDC, hImageListDC, hMaskListDC;
1272 HBITMAP hImageBmp, hOldImageBmp, hBlendMaskBmp;
1273 BOOL bIsTransparent, bBlend, bResult = FALSE, bMask;
1279 if (!pimldp || !(himl = pimldp->himl)) return FALSE;
1280 if (!is_valid(himl)) return FALSE;
1281 if ((pimldp->i < 0) || (pimldp->i >= himl->cCurImage)) return FALSE;
1283 imagelist_point_from_index( himl, pimldp->i, &pt );
1284 pt.x += pimldp->xBitmap;
1285 pt.y += pimldp->yBitmap;
1287 fState = pimldp->cbSize < sizeof(IMAGELISTDRAWPARAMS) ? ILS_NORMAL : pimldp->fState;
1288 fStyle = pimldp->fStyle & ~ILD_OVERLAYMASK;
1289 cx = (pimldp->cx == 0) ? himl->cx : pimldp->cx;
1290 cy = (pimldp->cy == 0) ? himl->cy : pimldp->cy;
1292 bIsTransparent = (fStyle & ILD_TRANSPARENT);
1293 if( pimldp->rgbBk == CLR_NONE )
1294 bIsTransparent = TRUE;
1295 if( ( pimldp->rgbBk == CLR_DEFAULT ) && ( himl->clrBk == CLR_NONE ) )
1296 bIsTransparent = TRUE;
1297 bMask = (himl->flags & ILC_MASK) && (fStyle & ILD_MASK) ;
1298 bBlend = (fStyle & (ILD_BLEND25 | ILD_BLEND50) ) && !bMask;
1300 TRACE("himl(%p) hbmMask(%p) iImage(%d) x(%d) y(%d) cx(%d) cy(%d)\n",
1301 himl, himl->hbmMask, pimldp->i, pimldp->x, pimldp->y, cx, cy);
1303 /* we will use these DCs to access the images and masks in the ImageList */
1304 hImageListDC = himl->hdcImage;
1305 hMaskListDC = himl->hdcMask;
1307 /* these will accumulate the image and mask for the image we're drawing */
1308 hImageDC = CreateCompatibleDC( pimldp->hdcDst );
1309 hImageBmp = CreateCompatibleBitmap( pimldp->hdcDst, cx, cy );
1310 hBlendMaskBmp = bBlend ? CreateBitmap(cx, cy, 1, 1, NULL) : 0;
1312 /* Create a compatible DC. */
1313 if (!hImageListDC || !hImageDC || !hImageBmp ||
1314 (bBlend && !hBlendMaskBmp) || (himl->hbmMask && !hMaskListDC))
1317 hOldImageBmp = SelectObject(hImageDC, hImageBmp);
1320 * To obtain a transparent look, background color should be set
1321 * to white and foreground color to black when blitting the
1324 oldImageFg = SetTextColor( hImageDC, RGB( 0, 0, 0 ) );
1325 oldImageBk = SetBkColor( hImageDC, RGB( 0xff, 0xff, 0xff ) );
1327 has_alpha = (himl->has_alpha && himl->has_alpha[pimldp->i]);
1328 if (!bMask && (has_alpha || (fState & ILS_ALPHA)))
1330 COLORREF colour, blend_col = CLR_NONE;
1335 blend_col = pimldp->rgbFg;
1336 if (blend_col == CLR_DEFAULT) blend_col = GetSysColor( COLOR_HIGHLIGHT );
1337 else if (blend_col == CLR_NONE) blend_col = GetTextColor( pimldp->hdcDst );
1340 func.BlendOp = AC_SRC_OVER;
1341 func.BlendFlags = 0;
1342 func.SourceConstantAlpha = (fState & ILS_ALPHA) ? pimldp->Frame : 255;
1343 func.AlphaFormat = AC_SRC_ALPHA;
1347 bResult = alpha_blend_image( himl, pimldp->hdcDst, pimldp->x, pimldp->y,
1348 pt.x, pt.y, cx, cy, func, fStyle, blend_col );
1351 colour = pimldp->rgbBk;
1352 if (colour == CLR_DEFAULT) colour = himl->clrBk;
1353 if (colour == CLR_NONE) colour = GetBkColor( pimldp->hdcDst );
1355 hOldBrush = SelectObject (hImageDC, CreateSolidBrush (colour));
1356 PatBlt( hImageDC, 0, 0, cx, cy, PATCOPY );
1357 alpha_blend_image( himl, hImageDC, 0, 0, pt.x, pt.y, cx, cy, func, fStyle, blend_col );
1358 DeleteObject (SelectObject (hImageDC, hOldBrush));
1359 bResult = BitBlt( pimldp->hdcDst, pimldp->x, pimldp->y, cx, cy, hImageDC, 0, 0, SRCCOPY );
1364 * Draw the initial image
1367 if (himl->hbmMask) {
1368 hOldBrush = SelectObject (hImageDC, CreateSolidBrush (GetTextColor(pimldp->hdcDst)));
1369 PatBlt( hImageDC, 0, 0, cx, cy, PATCOPY );
1370 BitBlt(hImageDC, 0, 0, cx, cy, hMaskListDC, pt.x, pt.y, SRCPAINT);
1371 DeleteObject (SelectObject (hImageDC, hOldBrush));
1372 if( bIsTransparent )
1374 BitBlt ( pimldp->hdcDst, pimldp->x, pimldp->y, cx, cy, hImageDC, 0, 0, SRCAND);
1379 hOldBrush = SelectObject (hImageDC, GetStockObject(BLACK_BRUSH));
1380 PatBlt( hImageDC, 0, 0, cx, cy, PATCOPY);
1381 SelectObject(hImageDC, hOldBrush);
1384 /* blend the image with the needed solid background */
1385 COLORREF colour = RGB(0,0,0);
1387 if( !bIsTransparent )
1389 colour = pimldp->rgbBk;
1390 if( colour == CLR_DEFAULT )
1391 colour = himl->clrBk;
1392 if( colour == CLR_NONE )
1393 colour = GetBkColor(pimldp->hdcDst);
1396 hOldBrush = SelectObject (hImageDC, CreateSolidBrush (colour));
1397 PatBlt( hImageDC, 0, 0, cx, cy, PATCOPY );
1400 BitBlt( hImageDC, 0, 0, cx, cy, hMaskListDC, pt.x, pt.y, SRCAND );
1401 BitBlt( hImageDC, 0, 0, cx, cy, hImageListDC, pt.x, pt.y, SRCPAINT );
1404 BitBlt( hImageDC, 0, 0, cx, cy, hImageListDC, pt.x, pt.y, SRCCOPY);
1405 DeleteObject (SelectObject (hImageDC, hOldBrush));
1408 /* Time for blending, if required */
1411 COLORREF clrBlend = pimldp->rgbFg;
1412 HDC hBlendMaskDC = hImageListDC;
1415 /* Create the blend Mask */
1416 hOldBitmap = SelectObject(hBlendMaskDC, hBlendMaskBmp);
1417 hBlendBrush = fStyle & ILD_BLEND50 ? himl->hbrBlend50 : himl->hbrBlend25;
1418 hOldBrush = SelectObject(hBlendMaskDC, hBlendBrush);
1419 PatBlt(hBlendMaskDC, 0, 0, cx, cy, PATCOPY);
1420 SelectObject(hBlendMaskDC, hOldBrush);
1422 /* Modify the blend mask if an Image Mask exist */
1424 BitBlt(hBlendMaskDC, 0, 0, cx, cy, hMaskListDC, pt.x, pt.y, 0x220326); /* NOTSRCAND */
1425 BitBlt(hBlendMaskDC, 0, 0, cx, cy, hBlendMaskDC, 0, 0, NOTSRCCOPY);
1428 /* now apply blend to the current image given the BlendMask */
1429 if (clrBlend == CLR_DEFAULT) clrBlend = GetSysColor (COLOR_HIGHLIGHT);
1430 else if (clrBlend == CLR_NONE) clrBlend = GetTextColor (pimldp->hdcDst);
1431 hOldBrush = SelectObject (hImageDC, CreateSolidBrush(clrBlend));
1432 BitBlt (hImageDC, 0, 0, cx, cy, hBlendMaskDC, 0, 0, 0xB8074A); /* PSDPxax */
1433 DeleteObject(SelectObject(hImageDC, hOldBrush));
1434 SelectObject(hBlendMaskDC, hOldBitmap);
1437 /* Now do the overlay image, if any */
1438 nOvlIdx = (pimldp->fStyle & ILD_OVERLAYMASK) >> 8;
1439 if ( (nOvlIdx >= 1) && (nOvlIdx <= MAX_OVERLAYIMAGE)) {
1440 nOvlIdx = himl->nOvlIdx[nOvlIdx - 1];
1441 if ((nOvlIdx >= 0) && (nOvlIdx < himl->cCurImage)) {
1443 imagelist_point_from_index( himl, nOvlIdx, &ptOvl );
1444 ptOvl.x += pimldp->xBitmap;
1445 if (himl->hbmMask && !(fStyle & ILD_IMAGE))
1446 BitBlt (hImageDC, 0, 0, cx, cy, hMaskListDC, ptOvl.x, ptOvl.y, SRCAND);
1447 BitBlt (hImageDC, 0, 0, cx, cy, hImageListDC, ptOvl.x, ptOvl.y, SRCPAINT);
1451 if (fState & ILS_SATURATE) FIXME("ILS_SATURATE: unimplemented!\n");
1452 if (fState & ILS_GLOW) FIXME("ILS_GLOW: unimplemented!\n");
1453 if (fState & ILS_SHADOW) FIXME("ILS_SHADOW: unimplemented!\n");
1455 if (fStyle & ILD_PRESERVEALPHA) FIXME("ILD_PRESERVEALPHA: unimplemented!\n");
1456 if (fStyle & ILD_SCALE) FIXME("ILD_SCALE: unimplemented!\n");
1457 if (fStyle & ILD_DPISCALE) FIXME("ILD_DPISCALE: unimplemented!\n");
1459 /* now copy the image to the screen */
1461 if (himl->hbmMask && bIsTransparent ) {
1462 COLORREF oldDstFg = SetTextColor(pimldp->hdcDst, RGB( 0, 0, 0 ) );
1463 COLORREF oldDstBk = SetBkColor(pimldp->hdcDst, RGB( 0xff, 0xff, 0xff ));
1464 BitBlt (pimldp->hdcDst, pimldp->x, pimldp->y, cx, cy, hMaskListDC, pt.x, pt.y, SRCAND);
1465 SetBkColor(pimldp->hdcDst, oldDstBk);
1466 SetTextColor(pimldp->hdcDst, oldDstFg);
1469 if (fStyle & ILD_ROP) dwRop = pimldp->dwRop;
1470 BitBlt (pimldp->hdcDst, pimldp->x, pimldp->y, cx, cy, hImageDC, 0, 0, dwRop);
1474 /* cleanup the mess */
1475 SetBkColor(hImageDC, oldImageBk);
1476 SetTextColor(hImageDC, oldImageFg);
1477 SelectObject(hImageDC, hOldImageBmp);
1479 DeleteObject(hBlendMaskBmp);
1480 DeleteObject(hImageBmp);
1487 /*************************************************************************
1488 * ImageList_Duplicate [COMCTL32.@]
1490 * Duplicates an image list.
1493 * himlSrc [I] source image list handle
1496 * Success: Handle of duplicated image list.
1501 ImageList_Duplicate (HIMAGELIST himlSrc)
1505 if (!is_valid(himlSrc)) {
1506 ERR("Invalid image list handle!\n");
1510 himlDst = ImageList_Create (himlSrc->cx, himlSrc->cy, himlSrc->flags,
1511 himlSrc->cCurImage, himlSrc->cGrow);
1517 imagelist_get_bitmap_size(himlSrc, himlSrc->cCurImage, &sz);
1518 BitBlt (himlDst->hdcImage, 0, 0, sz.cx, sz.cy,
1519 himlSrc->hdcImage, 0, 0, SRCCOPY);
1521 if (himlDst->hbmMask)
1522 BitBlt (himlDst->hdcMask, 0, 0, sz.cx, sz.cy,
1523 himlSrc->hdcMask, 0, 0, SRCCOPY);
1525 himlDst->cCurImage = himlSrc->cCurImage;
1526 himlDst->cMaxImage = himlSrc->cMaxImage;
1527 if (himlSrc->has_alpha && himlDst->has_alpha)
1528 memcpy( himlDst->has_alpha, himlSrc->has_alpha, himlDst->cCurImage );
1534 /*************************************************************************
1535 * ImageList_EndDrag [COMCTL32.@]
1537 * Finishes a drag operation.
1548 ImageList_EndDrag (void)
1550 /* cleanup the InternalDrag struct */
1551 InternalDrag.hwnd = 0;
1552 ImageList_Destroy (InternalDrag.himl);
1553 InternalDrag.himl = 0;
1556 InternalDrag.dxHotspot = 0;
1557 InternalDrag.dyHotspot = 0;
1558 InternalDrag.bShow = FALSE;
1559 DeleteObject(InternalDrag.hbmBg);
1560 InternalDrag.hbmBg = 0;
1564 /*************************************************************************
1565 * ImageList_GetBkColor [COMCTL32.@]
1567 * Returns the background color of an image list.
1570 * himl [I] Image list handle.
1573 * Success: background color
1578 ImageList_GetBkColor (HIMAGELIST himl)
1580 return himl ? himl->clrBk : CLR_NONE;
1584 /*************************************************************************
1585 * ImageList_GetDragImage [COMCTL32.@]
1587 * Returns the handle to the internal drag image list.
1590 * ppt [O] Pointer to the drag position. Can be NULL.
1591 * pptHotspot [O] Pointer to the position of the hot spot. Can be NULL.
1594 * Success: Handle of the drag image list.
1599 ImageList_GetDragImage (POINT *ppt, POINT *pptHotspot)
1601 if (is_valid(InternalDrag.himl)) {
1603 ppt->x = InternalDrag.x;
1604 ppt->y = InternalDrag.y;
1607 pptHotspot->x = InternalDrag.dxHotspot;
1608 pptHotspot->y = InternalDrag.dyHotspot;
1610 return (InternalDrag.himl);
1617 /*************************************************************************
1618 * ImageList_GetFlags [COMCTL32.@]
1620 * Gets the flags of the specified image list.
1623 * himl [I] Handle to image list
1633 ImageList_GetFlags(HIMAGELIST himl)
1635 TRACE("%p\n", himl);
1637 return is_valid(himl) ? himl->flags : 0;
1641 /*************************************************************************
1642 * ImageList_GetIcon [COMCTL32.@]
1644 * Creates an icon from a masked image of an image list.
1647 * himl [I] handle to image list
1649 * flags [I] drawing style flags
1652 * Success: icon handle
1657 ImageList_GetIcon (HIMAGELIST himl, INT i, UINT fStyle)
1661 HBITMAP hOldDstBitmap;
1665 TRACE("%p %d %d\n", himl, i, fStyle);
1666 if (!is_valid(himl) || (i < 0) || (i >= himl->cCurImage)) return NULL;
1672 /* create colour bitmap */
1674 ii.hbmColor = CreateCompatibleBitmap(hdcDst, himl->cx, himl->cy);
1675 ReleaseDC(0, hdcDst);
1677 hdcDst = CreateCompatibleDC(0);
1679 imagelist_point_from_index( himl, i, &pt );
1682 ii.hbmMask = CreateBitmap (himl->cx, himl->cy, 1, 1, NULL);
1683 hOldDstBitmap = SelectObject (hdcDst, ii.hbmMask);
1684 if (himl->hbmMask) {
1685 BitBlt (hdcDst, 0, 0, himl->cx, himl->cy,
1686 himl->hdcMask, pt.x, pt.y, SRCCOPY);
1689 PatBlt (hdcDst, 0, 0, himl->cx, himl->cy, BLACKNESS);
1692 SelectObject (hdcDst, ii.hbmColor);
1693 BitBlt (hdcDst, 0, 0, himl->cx, himl->cy,
1694 himl->hdcImage, pt.x, pt.y, SRCCOPY);
1697 * CreateIconIndirect requires us to deselect the bitmaps from
1698 * the DCs before calling
1700 SelectObject(hdcDst, hOldDstBitmap);
1702 hIcon = CreateIconIndirect (&ii);
1704 DeleteObject (ii.hbmMask);
1705 DeleteObject (ii.hbmColor);
1712 /*************************************************************************
1713 * ImageList_GetIconSize [COMCTL32.@]
1715 * Retrieves the size of an image in an image list.
1718 * himl [I] handle to image list
1719 * cx [O] pointer to the image width.
1720 * cy [O] pointer to the image height.
1727 * All images in an image list have the same size.
1731 ImageList_GetIconSize (HIMAGELIST himl, INT *cx, INT *cy)
1733 if (!is_valid(himl))
1735 if ((himl->cx <= 0) || (himl->cy <= 0))
1747 /*************************************************************************
1748 * ImageList_GetImageCount [COMCTL32.@]
1750 * Returns the number of images in an image list.
1753 * himl [I] handle to image list
1756 * Success: Number of images.
1761 ImageList_GetImageCount (HIMAGELIST himl)
1763 if (!is_valid(himl))
1766 return himl->cCurImage;
1770 /*************************************************************************
1771 * ImageList_GetImageInfo [COMCTL32.@]
1773 * Returns information about an image in an image list.
1776 * himl [I] handle to image list
1778 * pImageInfo [O] pointer to the image information
1786 ImageList_GetImageInfo (HIMAGELIST himl, INT i, IMAGEINFO *pImageInfo)
1790 if (!is_valid(himl) || (pImageInfo == NULL))
1792 if ((i < 0) || (i >= himl->cCurImage))
1795 pImageInfo->hbmImage = himl->hbmImage;
1796 pImageInfo->hbmMask = himl->hbmMask;
1798 imagelist_point_from_index( himl, i, &pt );
1799 pImageInfo->rcImage.top = pt.y;
1800 pImageInfo->rcImage.bottom = pt.y + himl->cy;
1801 pImageInfo->rcImage.left = pt.x;
1802 pImageInfo->rcImage.right = pt.x + himl->cx;
1808 /*************************************************************************
1809 * ImageList_GetImageRect [COMCTL32.@]
1811 * Retrieves the rectangle of the specified image in an image list.
1814 * himl [I] handle to image list
1816 * lpRect [O] pointer to the image rectangle
1823 * This is an UNDOCUMENTED function!!!
1827 ImageList_GetImageRect (HIMAGELIST himl, INT i, LPRECT lpRect)
1831 if (!is_valid(himl) || (lpRect == NULL))
1833 if ((i < 0) || (i >= himl->cCurImage))
1836 imagelist_point_from_index( himl, i, &pt );
1837 lpRect->left = pt.x;
1839 lpRect->right = pt.x + himl->cx;
1840 lpRect->bottom = pt.y + himl->cy;
1846 /*************************************************************************
1847 * ImageList_LoadImage [COMCTL32.@]
1848 * ImageList_LoadImageA [COMCTL32.@]
1850 * Creates an image list from a bitmap, icon or cursor.
1852 * See ImageList_LoadImageW.
1856 ImageList_LoadImageA (HINSTANCE hi, LPCSTR lpbmp, INT cx, INT cGrow,
1857 COLORREF clrMask, UINT uType, UINT uFlags)
1863 if (IS_INTRESOURCE(lpbmp))
1864 return ImageList_LoadImageW(hi, (LPCWSTR)lpbmp, cx, cGrow, clrMask,
1867 len = MultiByteToWideChar(CP_ACP, 0, lpbmp, -1, NULL, 0);
1868 lpbmpW = Alloc(len * sizeof(WCHAR));
1869 MultiByteToWideChar(CP_ACP, 0, lpbmp, -1, lpbmpW, len);
1871 himl = ImageList_LoadImageW(hi, lpbmpW, cx, cGrow, clrMask, uType, uFlags);
1877 /*************************************************************************
1878 * ImageList_LoadImageW [COMCTL32.@]
1880 * Creates an image list from a bitmap, icon or cursor.
1883 * hi [I] instance handle
1884 * lpbmp [I] name or id of the image
1885 * cx [I] width of each image
1886 * cGrow [I] number of images to expand
1887 * clrMask [I] mask color
1888 * uType [I] type of image to load
1889 * uFlags [I] loading flags
1892 * Success: handle to the loaded image list
1900 ImageList_LoadImageW (HINSTANCE hi, LPCWSTR lpbmp, INT cx, INT cGrow,
1901 COLORREF clrMask, UINT uType, UINT uFlags)
1903 HIMAGELIST himl = NULL;
1907 handle = LoadImageW (hi, lpbmp, uType, 0, 0, uFlags);
1909 WARN("Couldn't load image\n");
1913 if (uType == IMAGE_BITMAP) {
1915 GetObjectW (handle, sizeof(BITMAP), &bmp);
1917 /* To match windows behavior, if cx is set to zero and
1918 the flag DI_DEFAULTSIZE is specified, cx becomes the
1919 system metric value for icons. If the flag is not specified
1920 the function sets the size to the height of the bitmap */
1923 if (uFlags & DI_DEFAULTSIZE)
1924 cx = GetSystemMetrics (SM_CXICON);
1929 nImageCount = bmp.bmWidth / cx;
1931 himl = ImageList_Create (cx, bmp.bmHeight, ILC_MASK | ILC_COLOR,
1932 nImageCount, cGrow);
1934 DeleteObject (handle);
1937 ImageList_AddMasked (himl, handle, clrMask);
1939 else if ((uType == IMAGE_ICON) || (uType == IMAGE_CURSOR)) {
1943 GetIconInfo (handle, &ii);
1944 GetObjectW (ii.hbmColor, sizeof(BITMAP), &bmp);
1945 himl = ImageList_Create (bmp.bmWidth, bmp.bmHeight,
1946 ILC_MASK | ILC_COLOR, 1, cGrow);
1948 DeleteObject (ii.hbmColor);
1949 DeleteObject (ii.hbmMask);
1950 DeleteObject (handle);
1953 ImageList_Add (himl, ii.hbmColor, ii.hbmMask);
1954 DeleteObject (ii.hbmColor);
1955 DeleteObject (ii.hbmMask);
1958 DeleteObject (handle);
1964 /*************************************************************************
1965 * ImageList_Merge [COMCTL32.@]
1967 * Create an image list containing a merged image from two image lists.
1970 * himl1 [I] handle to first image list
1971 * i1 [I] first image index
1972 * himl2 [I] handle to second image list
1973 * i2 [I] second image index
1974 * dx [I] X offset of the second image relative to the first.
1975 * dy [I] Y offset of the second image relative to the first.
1978 * Success: The newly created image list. It contains a single image
1979 * consisting of the second image merged with the first.
1980 * Failure: NULL, if either himl1 or himl2 are invalid.
1983 * - The returned image list should be deleted by the caller using
1984 * ImageList_Destroy() when it is no longer required.
1985 * - If either i1 or i2 are not valid image indices they will be treated
1989 ImageList_Merge (HIMAGELIST himl1, INT i1, HIMAGELIST himl2, INT i2,
1992 HIMAGELIST himlDst = NULL;
1994 INT xOff1, yOff1, xOff2, yOff2;
1997 TRACE("(himl1=%p i1=%d himl2=%p i2=%d dx=%d dy=%d)\n", himl1, i1, himl2,
2000 if (!is_valid(himl1) || !is_valid(himl2))
2004 cxDst = max (himl1->cx, dx + himl2->cx);
2009 cxDst = max (himl2->cx, himl1->cx - dx);
2014 cxDst = max (himl1->cx, himl2->cx);
2020 cyDst = max (himl1->cy, dy + himl2->cy);
2025 cyDst = max (himl2->cy, himl1->cy - dy);
2030 cyDst = max (himl1->cy, himl2->cy);
2035 himlDst = ImageList_Create (cxDst, cyDst, ILC_MASK | ILC_COLOR, 1, 1);
2039 imagelist_point_from_index( himl1, i1, &pt1 );
2040 imagelist_point_from_index( himl2, i2, &pt2 );
2043 BitBlt (himlDst->hdcImage, 0, 0, cxDst, cyDst, himl1->hdcImage, 0, 0, BLACKNESS);
2044 if (i1 >= 0 && i1 < himl1->cCurImage)
2045 BitBlt (himlDst->hdcImage, xOff1, yOff1, himl1->cx, himl1->cy, himl1->hdcImage, pt1.x, pt1.y, SRCCOPY);
2046 if (i2 >= 0 && i2 < himl2->cCurImage)
2048 BitBlt (himlDst->hdcImage, xOff2, yOff2, himl2->cx, himl2->cy, himl2->hdcMask , pt2.x, pt2.y, SRCAND);
2049 BitBlt (himlDst->hdcImage, xOff2, yOff2, himl2->cx, himl2->cy, himl2->hdcImage, pt2.x, pt2.y, SRCPAINT);
2053 BitBlt (himlDst->hdcMask, 0, 0, cxDst, cyDst, himl1->hdcMask, 0, 0, WHITENESS);
2054 if (i1 >= 0 && i1 < himl1->cCurImage)
2055 BitBlt (himlDst->hdcMask, xOff1, yOff1, himl1->cx, himl1->cy, himl1->hdcMask, pt1.x, pt1.y, SRCCOPY);
2056 if (i2 >= 0 && i2 < himl2->cCurImage)
2057 BitBlt (himlDst->hdcMask, xOff2, yOff2, himl2->cx, himl2->cy, himl2->hdcMask, pt2.x, pt2.y, SRCAND);
2059 himlDst->cCurImage = 1;
2066 /***********************************************************************
2067 * DIB_GetDIBWidthBytes
2069 * Return the width of a DIB bitmap in bytes. DIB bitmap data is 32-bit aligned.
2071 static int DIB_GetDIBWidthBytes( int width, int depth )
2077 case 1: words = (width + 31) / 32; break;
2078 case 4: words = (width + 7) / 8; break;
2079 case 8: words = (width + 3) / 4; break;
2081 case 16: words = (width + 1) / 2; break;
2082 case 24: words = (width * 3 + 3)/4; break;
2085 WARN("(%d): Unsupported depth\n", depth );
2094 /***********************************************************************
2095 * DIB_GetDIBImageBytes
2097 * Return the number of bytes used to hold the image in a DIB bitmap.
2099 static int DIB_GetDIBImageBytes( int width, int height, int depth )
2101 return DIB_GetDIBWidthBytes( width, depth ) * abs( height );
2105 /* helper for ImageList_Read, see comments below */
2106 static BOOL _read_bitmap(HDC hdcIml, LPSTREAM pstm)
2108 BITMAPFILEHEADER bmfh;
2109 int bitsperpixel, palspace;
2110 char bmi_buf[sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD) * 256];
2111 LPBITMAPINFO bmi = (LPBITMAPINFO)bmi_buf;
2115 if (FAILED(IStream_Read ( pstm, &bmfh, sizeof(bmfh), NULL)))
2118 if (bmfh.bfType != (('M'<<8)|'B'))
2121 if (FAILED(IStream_Read ( pstm, &bmi->bmiHeader, sizeof(bmi->bmiHeader), NULL)))
2124 if ((bmi->bmiHeader.biSize != sizeof(bmi->bmiHeader)))
2127 TRACE("width %u, height %u, planes %u, bpp %u\n",
2128 bmi->bmiHeader.biWidth, bmi->bmiHeader.biHeight,
2129 bmi->bmiHeader.biPlanes, bmi->bmiHeader.biBitCount);
2131 bitsperpixel = bmi->bmiHeader.biPlanes * bmi->bmiHeader.biBitCount;
2132 if (bitsperpixel<=8)
2133 palspace = (1<<bitsperpixel)*sizeof(RGBQUAD);
2137 bmi->bmiHeader.biSizeImage = DIB_GetDIBImageBytes(bmi->bmiHeader.biWidth, bmi->bmiHeader.biHeight, bitsperpixel);
2139 /* read the palette right after the end of the bitmapinfoheader */
2140 if (palspace && FAILED(IStream_Read(pstm, bmi->bmiColors, palspace, NULL)))
2143 bits = Alloc(bmi->bmiHeader.biSizeImage);
2146 if (FAILED(IStream_Read(pstm, bits, bmi->bmiHeader.biSizeImage, NULL)))
2149 if (!StretchDIBits(hdcIml, 0, 0, bmi->bmiHeader.biWidth, bmi->bmiHeader.biHeight,
2150 0, 0, bmi->bmiHeader.biWidth, bmi->bmiHeader.biHeight,
2151 bits, bmi, DIB_RGB_COLORS, SRCCOPY))
2160 /*************************************************************************
2161 * ImageList_Read [COMCTL32.@]
2163 * Reads an image list from a stream.
2166 * pstm [I] pointer to a stream
2169 * Success: handle to image list
2172 * The format is like this:
2173 * ILHEAD ilheadstruct;
2175 * for the color image part:
2176 * BITMAPFILEHEADER bmfh;
2177 * BITMAPINFOHEADER bmih;
2178 * only if it has a palette:
2179 * RGBQUAD rgbs[nr_of_paletted_colors];
2181 * BYTE colorbits[imagesize];
2183 * the following only if the ILC_MASK bit is set in ILHEAD.ilFlags:
2184 * BITMAPFILEHEADER bmfh_mask;
2185 * BITMAPINFOHEADER bmih_mask;
2186 * only if it has a palette (it usually does not):
2187 * RGBQUAD rgbs[nr_of_paletted_colors];
2189 * BYTE maskbits[imagesize];
2191 HIMAGELIST WINAPI ImageList_Read (LPSTREAM pstm)
2197 TRACE("%p\n", pstm);
2199 if (FAILED(IStream_Read (pstm, &ilHead, sizeof(ILHEAD), NULL)))
2201 if (ilHead.usMagic != (('L' << 8) | 'I'))
2203 if (ilHead.usVersion != 0x101) /* probably version? */
2206 TRACE("cx %u, cy %u, flags 0x%04x, cCurImage %u, cMaxImage %u\n",
2207 ilHead.cx, ilHead.cy, ilHead.flags, ilHead.cCurImage, ilHead.cMaxImage);
2209 himl = ImageList_Create(ilHead.cx, ilHead.cy, ilHead.flags, ilHead.cCurImage, ilHead.cMaxImage);
2213 if (!_read_bitmap(himl->hdcImage, pstm))
2215 WARN("failed to read bitmap from stream\n");
2218 if (ilHead.flags & ILC_MASK)
2220 if (!_read_bitmap(himl->hdcMask, pstm))
2222 WARN("failed to read mask bitmap from stream\n");
2227 himl->cCurImage = ilHead.cCurImage;
2228 himl->cMaxImage = ilHead.cMaxImage;
2230 ImageList_SetBkColor(himl,ilHead.bkcolor);
2232 ImageList_SetOverlayImage(himl,ilHead.ovls[i],i+1);
2237 /*************************************************************************
2238 * ImageList_Remove [COMCTL32.@]
2240 * Removes an image from an image list
2243 * himl [I] image list handle
2250 * FIXME: as the image list storage test shows, native comctl32 simply shifts
2251 * images without creating a new bitmap.
2254 ImageList_Remove (HIMAGELIST himl, INT i)
2256 HBITMAP hbmNewImage, hbmNewMask;
2260 TRACE("(himl=%p i=%d)\n", himl, i);
2262 if (!is_valid(himl)) {
2263 ERR("Invalid image list handle!\n");
2267 if ((i < -1) || (i >= himl->cCurImage)) {
2268 TRACE("index out of range! %d\n", i);
2276 if (himl->cCurImage == 0) {
2277 /* remove all on empty ImageList is allowed */
2278 TRACE("remove all on empty ImageList!\n");
2282 himl->cMaxImage = himl->cInitial + himl->cGrow - 1;
2283 himl->cCurImage = 0;
2284 for (nCount = 0; nCount < MAX_OVERLAYIMAGE; nCount++)
2285 himl->nOvlIdx[nCount] = -1;
2287 hbmNewImage = ImageList_CreateImage(himl->hdcImage, himl, himl->cMaxImage);
2288 SelectObject (himl->hdcImage, hbmNewImage);
2289 DeleteObject (himl->hbmImage);
2290 himl->hbmImage = hbmNewImage;
2292 if (himl->hbmMask) {
2294 imagelist_get_bitmap_size(himl, himl->cMaxImage, &sz);
2295 hbmNewMask = CreateBitmap (sz.cx, sz.cy, 1, 1, NULL);
2296 SelectObject (himl->hdcMask, hbmNewMask);
2297 DeleteObject (himl->hbmMask);
2298 himl->hbmMask = hbmNewMask;
2302 /* delete one image */
2303 TRACE("Remove single image! %d\n", i);
2305 /* create new bitmap(s) */
2306 TRACE(" - Number of images: %d / %d (Old/New)\n",
2307 himl->cCurImage, himl->cCurImage - 1);
2309 hbmNewImage = ImageList_CreateImage(himl->hdcImage, himl, himl->cMaxImage);
2311 imagelist_get_bitmap_size(himl, himl->cMaxImage, &sz );
2313 hbmNewMask = CreateBitmap (sz.cx, sz.cy, 1, 1, NULL);
2315 hbmNewMask = 0; /* Just to keep compiler happy! */
2317 hdcBmp = CreateCompatibleDC (0);
2319 /* copy all images and masks prior to the "removed" image */
2321 TRACE("Pre image copy: Copy %d images\n", i);
2323 SelectObject (hdcBmp, hbmNewImage);
2324 imagelist_copy_images( himl, himl->hdcImage, hdcBmp, 0, i, 0 );
2326 if (himl->hbmMask) {
2327 SelectObject (hdcBmp, hbmNewMask);
2328 imagelist_copy_images( himl, himl->hdcMask, hdcBmp, 0, i, 0 );
2332 /* copy all images and masks behind the removed image */
2333 if (i < himl->cCurImage - 1) {
2334 TRACE("Post image copy!\n");
2336 SelectObject (hdcBmp, hbmNewImage);
2337 imagelist_copy_images( himl, himl->hdcImage, hdcBmp, i + 1,
2338 (himl->cCurImage - i), i );
2340 if (himl->hbmMask) {
2341 SelectObject (hdcBmp, hbmNewMask);
2342 imagelist_copy_images( himl, himl->hdcMask, hdcBmp, i + 1,
2343 (himl->cCurImage - i), i );
2349 /* delete old images and insert new ones */
2350 SelectObject (himl->hdcImage, hbmNewImage);
2351 DeleteObject (himl->hbmImage);
2352 himl->hbmImage = hbmNewImage;
2353 if (himl->hbmMask) {
2354 SelectObject (himl->hdcMask, hbmNewMask);
2355 DeleteObject (himl->hbmMask);
2356 himl->hbmMask = hbmNewMask;
2366 /*************************************************************************
2367 * ImageList_Replace [COMCTL32.@]
2369 * Replaces an image in an image list with a new image.
2372 * himl [I] handle to image list
2374 * hbmImage [I] handle to image bitmap
2375 * hbmMask [I] handle to mask bitmap. Can be NULL.
2383 ImageList_Replace (HIMAGELIST himl, INT i, HBITMAP hbmImage,
2390 TRACE("%p %d %p %p\n", himl, i, hbmImage, hbmMask);
2392 if (!is_valid(himl)) {
2393 ERR("Invalid image list handle!\n");
2397 if ((i >= himl->cMaxImage) || (i < 0)) {
2398 ERR("Invalid image index!\n");
2402 if (!GetObjectW(hbmImage, sizeof(BITMAP), &bmp))
2405 hdcImage = CreateCompatibleDC (0);
2408 SelectObject (hdcImage, hbmImage);
2410 if (add_with_alpha( himl, hdcImage, i, 1, bmp.bmWidth, bmp.bmHeight, hbmImage, hbmMask ))
2413 imagelist_point_from_index(himl, i, &pt);
2414 StretchBlt (himl->hdcImage, pt.x, pt.y, himl->cx, himl->cy,
2415 hdcImage, 0, 0, bmp.bmWidth, bmp.bmHeight, SRCCOPY);
2420 HBITMAP hOldBitmapTemp;
2422 hdcTemp = CreateCompatibleDC(0);
2423 hOldBitmapTemp = SelectObject(hdcTemp, hbmMask);
2425 StretchBlt (himl->hdcMask, pt.x, pt.y, himl->cx, himl->cy,
2426 hdcTemp, 0, 0, bmp.bmWidth, bmp.bmHeight, SRCCOPY);
2427 SelectObject(hdcTemp, hOldBitmapTemp);
2430 /* Remove the background from the image
2432 BitBlt (himl->hdcImage, pt.x, pt.y, bmp.bmWidth, bmp.bmHeight,
2433 himl->hdcMask, pt.x, pt.y, 0x220326); /* NOTSRCAND */
2437 DeleteDC (hdcImage);
2443 /*************************************************************************
2444 * ImageList_ReplaceIcon [COMCTL32.@]
2446 * Replaces an image in an image list using an icon.
2449 * himl [I] handle to image list
2451 * hIcon [I] handle to icon
2454 * Success: index of the replaced image
2459 ImageList_ReplaceIcon (HIMAGELIST himl, INT nIndex, HICON hIcon)
2468 TRACE("(%p %d %p)\n", himl, nIndex, hIcon);
2470 if (!is_valid(himl)) {
2471 ERR("invalid image list\n");
2474 if ((nIndex >= himl->cMaxImage) || (nIndex < -1)) {
2475 ERR("invalid image index %d / %d\n", nIndex, himl->cMaxImage);
2479 hBestFitIcon = CopyImage(
2482 LR_COPYFROMRESOURCE);
2483 /* the above will fail if the icon wasn't loaded from a resource, so try
2484 * again without LR_COPYFROMRESOURCE flag */
2486 hBestFitIcon = CopyImage(
2493 ret = GetIconInfo (hBestFitIcon, &ii);
2495 DestroyIcon(hBestFitIcon);
2499 ret = GetObjectW (ii.hbmMask, sizeof(BITMAP), &bmp);
2501 ERR("couldn't get mask bitmap info\n");
2503 DeleteObject (ii.hbmColor);
2505 DeleteObject (ii.hbmMask);
2506 DestroyIcon(hBestFitIcon);
2511 if (himl->cCurImage + 1 > himl->cMaxImage)
2512 IMAGELIST_InternalExpandBitmaps(himl, 1);
2514 nIndex = himl->cCurImage;
2518 hdcImage = CreateCompatibleDC (0);
2519 TRACE("hdcImage=%p\n", hdcImage);
2521 ERR("invalid hdcImage!\n");
2523 if (himl->uBitsPixel == 32)
2527 UINT height = bmp.bmHeight / 2;
2528 HDC hdcMask = CreateCompatibleDC( 0 );
2529 HBITMAP color = CreateBitmap( bmp.bmWidth, height, 1, 1, NULL );
2530 SelectObject( hdcImage, color );
2531 SelectObject( hdcMask, ii.hbmMask );
2532 BitBlt( hdcImage, 0, 0, bmp.bmWidth, height, hdcMask, 0, height, SRCCOPY );
2533 add_with_alpha( himl, hdcImage, nIndex, 1, bmp.bmWidth, height, color, ii.hbmMask );
2534 DeleteDC( hdcMask );
2535 DeleteObject( color );
2537 else add_with_alpha( himl, hdcImage, nIndex, 1, bmp.bmWidth, bmp.bmHeight, ii.hbmColor, ii.hbmMask );
2542 imagelist_point_from_index(himl, nIndex, &pt);
2544 SetTextColor(himl->hdcImage, RGB(0,0,0));
2545 SetBkColor (himl->hdcImage, RGB(255,255,255));
2549 SelectObject (hdcImage, ii.hbmColor);
2550 StretchBlt (himl->hdcImage, pt.x, pt.y, himl->cx, himl->cy,
2551 hdcImage, 0, 0, bmp.bmWidth, bmp.bmHeight, SRCCOPY);
2554 SelectObject (hdcImage, ii.hbmMask);
2555 StretchBlt (himl->hdcMask, pt.x, pt.y, himl->cx, himl->cy,
2556 hdcImage, 0, 0, bmp.bmWidth, bmp.bmHeight, SRCCOPY);
2561 UINT height = bmp.bmHeight / 2;
2562 SelectObject (hdcImage, ii.hbmMask);
2563 StretchBlt (himl->hdcImage, pt.x, pt.y, himl->cx, himl->cy,
2564 hdcImage, 0, height, bmp.bmWidth, height, SRCCOPY);
2566 StretchBlt (himl->hdcMask, pt.x, pt.y, himl->cx, himl->cy,
2567 hdcImage, 0, 0, bmp.bmWidth, height, SRCCOPY);
2571 DestroyIcon(hBestFitIcon);
2573 DeleteDC (hdcImage);
2575 DeleteObject (ii.hbmColor);
2577 DeleteObject (ii.hbmMask);
2579 TRACE("Insert index = %d, himl->cCurImage = %d\n", nIndex, himl->cCurImage);
2584 /*************************************************************************
2585 * ImageList_SetBkColor [COMCTL32.@]
2587 * Sets the background color of an image list.
2590 * himl [I] handle to image list
2591 * clrBk [I] background color
2594 * Success: previous background color
2599 ImageList_SetBkColor (HIMAGELIST himl, COLORREF clrBk)
2603 if (!is_valid(himl))
2606 clrOldBk = himl->clrBk;
2607 himl->clrBk = clrBk;
2612 /*************************************************************************
2613 * ImageList_SetDragCursorImage [COMCTL32.@]
2615 * Combines the specified image with the current drag image
2618 * himlDrag [I] handle to drag image list
2619 * iDrag [I] drag image index
2620 * dxHotspot [I] X position of the hot spot
2621 * dyHotspot [I] Y position of the hot spot
2628 * - The names dxHotspot, dyHotspot are misleading because they have nothing
2629 * to do with a hotspot but are only the offset of the origin of the new
2630 * image relative to the origin of the old image.
2632 * - When this function is called and the drag image is visible, a
2633 * short flickering occurs but this matches the Win9x behavior. It is
2634 * possible to fix the flickering using code like in ImageList_DragMove.
2638 ImageList_SetDragCursorImage (HIMAGELIST himlDrag, INT iDrag,
2639 INT dxHotspot, INT dyHotspot)
2641 HIMAGELIST himlTemp;
2644 if (!is_valid(InternalDrag.himl) || !is_valid(himlDrag))
2647 TRACE(" dxH=%d dyH=%d nX=%d nY=%d\n",
2648 dxHotspot, dyHotspot, InternalDrag.dxHotspot, InternalDrag.dyHotspot);
2650 visible = InternalDrag.bShow;
2652 himlTemp = ImageList_Merge (InternalDrag.himl, 0, himlDrag, iDrag,
2653 dxHotspot, dyHotspot);
2656 /* hide the drag image */
2657 ImageList_DragShowNolock(FALSE);
2659 if ((InternalDrag.himl->cx != himlTemp->cx) ||
2660 (InternalDrag.himl->cy != himlTemp->cy)) {
2661 /* the size of the drag image changed, invalidate the buffer */
2662 DeleteObject(InternalDrag.hbmBg);
2663 InternalDrag.hbmBg = 0;
2666 ImageList_Destroy (InternalDrag.himl);
2667 InternalDrag.himl = himlTemp;
2670 /* show the drag image */
2671 ImageList_DragShowNolock(TRUE);
2678 /*************************************************************************
2679 * ImageList_SetFilter [COMCTL32.@]
2681 * Sets a filter (or does something completely different)!!???
2682 * It removes 12 Bytes from the stack (3 Parameters).
2685 * himl [I] SHOULD be a handle to image list
2686 * i [I] COULD be an index?
2691 * Failure: FALSE ???
2694 * This is an UNDOCUMENTED function!!!!
2699 ImageList_SetFilter (HIMAGELIST himl, INT i, DWORD dwFilter)
2701 FIXME("(%p 0x%x 0x%x):empty stub!\n", himl, i, dwFilter);
2707 /*************************************************************************
2708 * ImageList_SetFlags [COMCTL32.@]
2710 * Sets the image list flags.
2713 * himl [I] Handle to image list
2714 * flags [I] Flags to set
2724 ImageList_SetFlags(HIMAGELIST himl, DWORD flags)
2726 FIXME("(%p %08x):empty stub\n", himl, flags);
2731 /*************************************************************************
2732 * ImageList_SetIconSize [COMCTL32.@]
2734 * Sets the image size of the bitmap and deletes all images.
2737 * himl [I] handle to image list
2738 * cx [I] image width
2739 * cy [I] image height
2747 ImageList_SetIconSize (HIMAGELIST himl, INT cx, INT cy)
2752 if (!is_valid(himl))
2755 /* remove all images */
2756 himl->cMaxImage = himl->cInitial + 1;
2757 himl->cCurImage = 0;
2761 /* initialize overlay mask indices */
2762 for (nCount = 0; nCount < MAX_OVERLAYIMAGE; nCount++)
2763 himl->nOvlIdx[nCount] = -1;
2765 hbmNew = ImageList_CreateImage(himl->hdcImage, himl, himl->cMaxImage);
2766 SelectObject (himl->hdcImage, hbmNew);
2767 DeleteObject (himl->hbmImage);
2768 himl->hbmImage = hbmNew;
2770 if (himl->hbmMask) {
2772 imagelist_get_bitmap_size(himl, himl->cMaxImage, &sz);
2773 hbmNew = CreateBitmap (sz.cx, sz.cy, 1, 1, NULL);
2774 SelectObject (himl->hdcMask, hbmNew);
2775 DeleteObject (himl->hbmMask);
2776 himl->hbmMask = hbmNew;
2783 /*************************************************************************
2784 * ImageList_SetImageCount [COMCTL32.@]
2786 * Resizes an image list to the specified number of images.
2789 * himl [I] handle to image list
2790 * iImageCount [I] number of images in the image list
2798 ImageList_SetImageCount (HIMAGELIST himl, UINT iImageCount)
2801 HBITMAP hbmNewBitmap, hbmOld;
2802 INT nNewCount, nCopyCount;
2804 TRACE("%p %d\n",himl,iImageCount);
2806 if (!is_valid(himl))
2808 if (himl->cMaxImage > iImageCount)
2810 himl->cCurImage = iImageCount;
2811 /* TODO: shrink the bitmap when cMaxImage-cCurImage>cGrow ? */
2815 nNewCount = iImageCount + himl->cGrow;
2816 nCopyCount = min(himl->cCurImage, iImageCount);
2818 hdcBitmap = CreateCompatibleDC (0);
2820 hbmNewBitmap = ImageList_CreateImage(hdcBitmap, himl, nNewCount);
2822 if (hbmNewBitmap != 0)
2824 hbmOld = SelectObject (hdcBitmap, hbmNewBitmap);
2825 imagelist_copy_images( himl, himl->hdcImage, hdcBitmap, 0, nCopyCount, 0 );
2826 SelectObject (hdcBitmap, hbmOld);
2828 /* FIXME: delete 'empty' image space? */
2830 SelectObject (himl->hdcImage, hbmNewBitmap);
2831 DeleteObject (himl->hbmImage);
2832 himl->hbmImage = hbmNewBitmap;
2835 ERR("Could not create new image bitmap !\n");
2840 imagelist_get_bitmap_size( himl, nNewCount, &sz );
2841 hbmNewBitmap = CreateBitmap (sz.cx, sz.cy, 1, 1, NULL);
2842 if (hbmNewBitmap != 0)
2844 hbmOld = SelectObject (hdcBitmap, hbmNewBitmap);
2845 imagelist_copy_images( himl, himl->hdcMask, hdcBitmap, 0, nCopyCount, 0 );
2846 SelectObject (hdcBitmap, hbmOld);
2848 /* FIXME: delete 'empty' image space? */
2850 SelectObject (himl->hdcMask, hbmNewBitmap);
2851 DeleteObject (himl->hbmMask);
2852 himl->hbmMask = hbmNewBitmap;
2855 ERR("Could not create new mask bitmap!\n");
2858 DeleteDC (hdcBitmap);
2860 /* Update max image count and current image count */
2861 himl->cMaxImage = nNewCount;
2862 himl->cCurImage = iImageCount;
2868 /*************************************************************************
2869 * ImageList_SetOverlayImage [COMCTL32.@]
2871 * Assigns an overlay mask index to an existing image in an image list.
2874 * himl [I] handle to image list
2875 * iImage [I] image index
2876 * iOverlay [I] overlay mask index
2884 ImageList_SetOverlayImage (HIMAGELIST himl, INT iImage, INT iOverlay)
2886 if (!is_valid(himl))
2888 if ((iOverlay < 1) || (iOverlay > MAX_OVERLAYIMAGE))
2890 if ((iImage!=-1) && ((iImage < 0) || (iImage > himl->cCurImage)))
2892 himl->nOvlIdx[iOverlay - 1] = iImage;
2898 /* helper for ImageList_Write - write bitmap to pstm
2899 * currently everything is written as 24 bit RGB, except masks
2902 _write_bitmap(HBITMAP hBitmap, LPSTREAM pstm)
2904 LPBITMAPFILEHEADER bmfh;
2905 LPBITMAPINFOHEADER bmih;
2906 LPBYTE data = NULL, lpBits;
2908 INT bitCount, sizeImage, offBits, totalSize;
2910 BOOL result = FALSE;
2912 if (!GetObjectW(hBitmap, sizeof(BITMAP), &bm))
2915 bitCount = bm.bmBitsPixel == 1 ? 1 : 24;
2916 sizeImage = DIB_GetDIBImageBytes(bm.bmWidth, bm.bmHeight, bitCount);
2918 totalSize = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);
2920 totalSize += (1 << bitCount) * sizeof(RGBQUAD);
2921 offBits = totalSize;
2922 totalSize += sizeImage;
2924 data = Alloc(totalSize);
2925 bmfh = (LPBITMAPFILEHEADER)data;
2926 bmih = (LPBITMAPINFOHEADER)(data + sizeof(BITMAPFILEHEADER));
2927 lpBits = data + offBits;
2929 /* setup BITMAPFILEHEADER */
2930 bmfh->bfType = (('M' << 8) | 'B');
2931 bmfh->bfSize = offBits;
2932 bmfh->bfReserved1 = 0;
2933 bmfh->bfReserved2 = 0;
2934 bmfh->bfOffBits = offBits;
2936 /* setup BITMAPINFOHEADER */
2937 bmih->biSize = sizeof(BITMAPINFOHEADER);
2938 bmih->biWidth = bm.bmWidth;
2939 bmih->biHeight = bm.bmHeight;
2941 bmih->biBitCount = bitCount;
2942 bmih->biCompression = BI_RGB;
2943 bmih->biSizeImage = sizeImage;
2944 bmih->biXPelsPerMeter = 0;
2945 bmih->biYPelsPerMeter = 0;
2946 bmih->biClrUsed = 0;
2947 bmih->biClrImportant = 0;
2950 result = GetDIBits(xdc, hBitmap, 0, bm.bmHeight, lpBits, (BITMAPINFO *)bmih, DIB_RGB_COLORS) == bm.bmHeight;
2955 TRACE("width %u, height %u, planes %u, bpp %u\n",
2956 bmih->biWidth, bmih->biHeight,
2957 bmih->biPlanes, bmih->biBitCount);
2961 LPBITMAPINFO inf = (LPBITMAPINFO)bmih;
2962 inf->bmiColors[0].rgbRed = inf->bmiColors[0].rgbGreen = inf->bmiColors[0].rgbBlue = 0;
2963 inf->bmiColors[1].rgbRed = inf->bmiColors[1].rgbGreen = inf->bmiColors[1].rgbBlue = 0xff;
2966 if(FAILED(IStream_Write(pstm, data, totalSize, NULL)))
2978 /*************************************************************************
2979 * ImageList_Write [COMCTL32.@]
2981 * Writes an image list to a stream.
2984 * himl [I] handle to image list
2985 * pstm [O] Pointer to a stream.
2996 ImageList_Write (HIMAGELIST himl, LPSTREAM pstm)
3001 TRACE("%p %p\n", himl, pstm);
3003 if (!is_valid(himl))
3006 ilHead.usMagic = (('L' << 8) | 'I');
3007 ilHead.usVersion = 0x101;
3008 ilHead.cCurImage = himl->cCurImage;
3009 ilHead.cMaxImage = himl->cMaxImage;
3010 ilHead.cGrow = himl->cGrow;
3011 ilHead.cx = himl->cx;
3012 ilHead.cy = himl->cy;
3013 ilHead.bkcolor = himl->clrBk;
3014 ilHead.flags = himl->flags;
3015 for(i = 0; i < 4; i++) {
3016 ilHead.ovls[i] = himl->nOvlIdx[i];
3019 TRACE("cx %u, cy %u, flags 0x04%x, cCurImage %u, cMaxImage %u\n",
3020 ilHead.cx, ilHead.cy, ilHead.flags, ilHead.cCurImage, ilHead.cMaxImage);
3022 if(FAILED(IStream_Write(pstm, &ilHead, sizeof(ILHEAD), NULL)))
3025 /* write the bitmap */
3026 if(!_write_bitmap(himl->hbmImage, pstm))
3029 /* write the mask if we have one */
3030 if(himl->flags & ILC_MASK) {
3031 if(!_write_bitmap(himl->hbmMask, pstm))
3039 static HBITMAP ImageList_CreateImage(HDC hdc, HIMAGELIST himl, UINT count)
3041 HBITMAP hbmNewBitmap;
3042 UINT ilc = (himl->flags & 0xFE);
3045 imagelist_get_bitmap_size( himl, count, &sz );
3047 if ((ilc >= ILC_COLOR4 && ilc <= ILC_COLOR32) || ilc == ILC_COLOR)
3052 TRACE("Creating DIBSection %d x %d, %d Bits per Pixel\n",
3053 sz.cx, sz.cy, himl->uBitsPixel);
3055 if (himl->uBitsPixel <= ILC_COLOR8)
3061 colors = 1 << himl->uBitsPixel;
3062 bmi = Alloc(sizeof(BITMAPINFOHEADER) +
3063 sizeof(PALETTEENTRY) * colors);
3065 pal = (LPPALETTEENTRY)bmi->bmiColors;
3066 GetPaletteEntries(GetStockObject(DEFAULT_PALETTE), 0, colors, pal);
3068 /* Swap colors returned by GetPaletteEntries so we can use them for
3069 * CreateDIBSection call. */
3070 for (i = 0; i < colors; i++)
3072 temp = pal[i].peBlue;
3073 bmi->bmiColors[i].rgbRed = pal[i].peRed;
3074 bmi->bmiColors[i].rgbBlue = temp;
3079 bmi = Alloc(sizeof(BITMAPINFOHEADER));
3082 bmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
3083 bmi->bmiHeader.biWidth = sz.cx;
3084 bmi->bmiHeader.biHeight = sz.cy;
3085 bmi->bmiHeader.biPlanes = 1;
3086 bmi->bmiHeader.biBitCount = himl->uBitsPixel;
3087 bmi->bmiHeader.biCompression = BI_RGB;
3088 bmi->bmiHeader.biSizeImage = 0;
3089 bmi->bmiHeader.biXPelsPerMeter = 0;
3090 bmi->bmiHeader.biYPelsPerMeter = 0;
3091 bmi->bmiHeader.biClrUsed = 0;
3092 bmi->bmiHeader.biClrImportant = 0;
3094 hbmNewBitmap = CreateDIBSection(hdc, bmi, DIB_RGB_COLORS, &bits, 0, 0);
3098 else /*if (ilc == ILC_COLORDDB)*/
3100 TRACE("Creating Bitmap: %d Bits per Pixel\n", himl->uBitsPixel);
3102 hbmNewBitmap = CreateBitmap (sz.cx, sz.cy, 1, himl->uBitsPixel, NULL);
3104 TRACE("returning %p\n", hbmNewBitmap);
3105 return hbmNewBitmap;
3108 /*************************************************************************
3109 * ImageList_SetColorTable [COMCTL32.@]
3111 * Sets the color table of an image list.
3114 * himl [I] Handle to the image list.
3115 * uStartIndex [I] The first index to set.
3116 * cEntries [I] Number of entries to set.
3117 * prgb [I] New color information for color table for the image list.
3120 * Success: Number of entries in the table that were set.
3124 * ImageList_Create(), SetDIBColorTable()
3128 ImageList_SetColorTable (HIMAGELIST himl, UINT uStartIndex, UINT cEntries, CONST RGBQUAD * prgb)
3130 return SetDIBColorTable(himl->hdcImage, uStartIndex, cEntries, prgb);
3133 /*************************************************************************
3134 * ImageList_CoCreateInstance [COMCTL32.@]
3136 * Creates a new imagelist instance and returns an interface pointer to it.
3139 * rclsid [I] A reference to the CLSID (CLSID_ImageList).
3140 * punkOuter [I] Pointer to IUnknown interface for aggregation, if desired
3141 * riid [I] Identifier of the requested interface.
3142 * ppv [O] Returns the address of the pointer requested, or NULL.
3146 * Failure: Error value.
3149 ImageList_CoCreateInstance (REFCLSID rclsid, const IUnknown *punkOuter, REFIID riid, void **ppv)
3151 TRACE("(%s,%p,%s,%p)\n", debugstr_guid(rclsid), punkOuter, debugstr_guid(riid), ppv);
3153 if (!IsEqualCLSID(&CLSID_ImageList, rclsid))
3154 return E_NOINTERFACE;
3156 return ImageListImpl_CreateInstance(punkOuter, riid, ppv);
3160 /*************************************************************************
3161 * IImageList implementation
3164 static HRESULT WINAPI ImageListImpl_QueryInterface(IImageList *iface,
3165 REFIID iid, void **ppv)
3167 HIMAGELIST This = (HIMAGELIST) iface;
3168 TRACE("(%p,%s,%p)\n", iface, debugstr_guid(iid), ppv);
3170 if (!ppv) return E_INVALIDARG;
3172 if (IsEqualIID(&IID_IUnknown, iid) || IsEqualIID(&IID_IImageList, iid))
3177 return E_NOINTERFACE;
3180 IUnknown_AddRef((IUnknown*)*ppv);
3184 static ULONG WINAPI ImageListImpl_AddRef(IImageList *iface)
3186 HIMAGELIST This = (HIMAGELIST) iface;
3187 ULONG ref = InterlockedIncrement(&This->ref);
3189 TRACE("(%p) refcount=%u\n", iface, ref);
3193 static ULONG WINAPI ImageListImpl_Release(IImageList *iface)
3195 HIMAGELIST This = (HIMAGELIST) iface;
3196 ULONG ref = InterlockedDecrement(&This->ref);
3198 TRACE("(%p) refcount=%u\n", iface, ref);
3202 /* delete image bitmaps */
3203 if (This->hbmImage) DeleteObject (This->hbmImage);
3204 if (This->hbmMask) DeleteObject (This->hbmMask);
3206 /* delete image & mask DCs */
3207 if (This->hdcImage) DeleteDC (This->hdcImage);
3208 if (This->hdcMask) DeleteDC (This->hdcMask);
3210 /* delete blending brushes */
3211 if (This->hbrBlend25) DeleteObject (This->hbrBlend25);
3212 if (This->hbrBlend50) DeleteObject (This->hbrBlend50);
3214 This->lpVtbl = NULL;
3215 HeapFree(GetProcessHeap(), 0, This->has_alpha);
3216 HeapFree(GetProcessHeap(), 0, This);
3222 static HRESULT WINAPI ImageListImpl_Add(IImageList *iface, HBITMAP hbmImage,
3223 HBITMAP hbmMask, int *pi)
3225 HIMAGELIST This = (HIMAGELIST) iface;
3231 ret = ImageList_Add(This, hbmImage, hbmMask);
3240 static HRESULT WINAPI ImageListImpl_ReplaceIcon(IImageList *iface, int i,
3241 HICON hicon, int *pi)
3243 HIMAGELIST This = (HIMAGELIST) iface;
3249 ret = ImageList_ReplaceIcon(This, i, hicon);
3258 static HRESULT WINAPI ImageListImpl_SetOverlayImage(IImageList *iface,
3259 int iImage, int iOverlay)
3261 return ImageList_SetOverlayImage((HIMAGELIST) iface, iImage, iOverlay)
3265 static HRESULT WINAPI ImageListImpl_Replace(IImageList *iface, int i,
3266 HBITMAP hbmImage, HBITMAP hbmMask)
3268 return ImageList_Replace((HIMAGELIST) iface, i, hbmImage, hbmMask) ? S_OK :
3272 static HRESULT WINAPI ImageListImpl_AddMasked(IImageList *iface, HBITMAP hbmImage,
3273 COLORREF crMask, int *pi)
3275 HIMAGELIST This = (HIMAGELIST) iface;
3281 ret = ImageList_AddMasked(This, hbmImage, crMask);
3290 static HRESULT WINAPI ImageListImpl_Draw(IImageList *iface,
3291 IMAGELISTDRAWPARAMS *pimldp)
3293 HIMAGELIST This = (HIMAGELIST) iface;
3294 HIMAGELIST old_himl = 0;
3300 /* As far as I can tell, Windows simply ignores the contents of pimldp->himl
3301 so we shall simulate the same */
3302 old_himl = pimldp->himl;
3303 pimldp->himl = This;
3305 ret = ImageList_DrawIndirect(pimldp);
3307 pimldp->himl = old_himl;
3308 return ret ? S_OK : E_FAIL;
3311 static HRESULT WINAPI ImageListImpl_Remove(IImageList *iface, int i)
3313 return (ImageList_Remove((HIMAGELIST) iface, i) == 0) ? E_FAIL : S_OK;
3316 static HRESULT WINAPI ImageListImpl_GetIcon(IImageList *iface, int i, UINT flags,
3324 hIcon = ImageList_GetIcon((HIMAGELIST) iface, i, flags);
3333 static HRESULT WINAPI ImageListImpl_GetImageInfo(IImageList *iface, int i,
3334 IMAGEINFO *pImageInfo)
3336 return ImageList_GetImageInfo((HIMAGELIST) iface, i, pImageInfo) ? S_OK : E_FAIL;
3339 static HRESULT WINAPI ImageListImpl_Copy(IImageList *iface, int iDst,
3340 IUnknown *punkSrc, int iSrc, UINT uFlags)
3342 HIMAGELIST This = (HIMAGELIST) iface;
3343 IImageList *src = NULL;
3349 /* TODO: Add test for IID_ImageList2 too */
3350 if (FAILED(IImageList_QueryInterface(punkSrc, &IID_IImageList,
3354 if (ImageList_Copy(This, iDst, (HIMAGELIST) src, iSrc, uFlags))
3359 IImageList_Release(src);
3363 static HRESULT WINAPI ImageListImpl_Merge(IImageList *iface, int i1,
3364 IUnknown *punk2, int i2, int dx, int dy, REFIID riid, PVOID *ppv)
3366 HIMAGELIST This = (HIMAGELIST) iface;
3367 IImageList *iml2 = NULL;
3369 HRESULT ret = E_FAIL;
3374 /* TODO: Add test for IID_ImageList2 too */
3375 if (FAILED(IImageList_QueryInterface(punk2, &IID_IImageList,
3379 hNew = ImageList_Merge(This, i1, (HIMAGELIST) iml2, i2, dx, dy);
3381 /* Get the interface for the new image list */
3383 ret = HIMAGELIST_QueryInterface(hNew, riid, ppv);
3385 IImageList_Release(iml2);
3389 static HRESULT WINAPI ImageListImpl_Clone(IImageList *iface, REFIID riid,
3392 HIMAGELIST This = (HIMAGELIST) iface;
3394 HRESULT ret = E_FAIL;
3399 hNew = ImageList_Duplicate(This);
3401 /* Get the interface for the new image list */
3403 ret = HIMAGELIST_QueryInterface(hNew, riid, ppv);
3408 static HRESULT WINAPI ImageListImpl_GetImageRect(IImageList *iface, int i,
3411 HIMAGELIST This = (HIMAGELIST) iface;
3417 if (!ImageList_GetImageInfo(This, i, &info))
3420 return CopyRect(prc, &info.rcImage) ? S_OK : E_FAIL;
3423 static HRESULT WINAPI ImageListImpl_GetIconSize(IImageList *iface, int *cx,
3426 HIMAGELIST This = (HIMAGELIST) iface;
3428 return ImageList_GetIconSize(This, cx, cy) ? S_OK : E_FAIL;
3431 static HRESULT WINAPI ImageListImpl_SetIconSize(IImageList *iface, int cx,
3434 return ImageList_SetIconSize((HIMAGELIST) iface, cx, cy) ? S_OK : E_FAIL;
3437 static HRESULT WINAPI ImageListImpl_GetImageCount(IImageList *iface, int *pi)
3442 *pi = ImageList_GetImageCount((HIMAGELIST) iface);
3446 static HRESULT WINAPI ImageListImpl_SetImageCount(IImageList *iface,
3449 return ImageList_SetImageCount((HIMAGELIST) iface, uNewCount) ? S_OK : E_FAIL;
3452 static HRESULT WINAPI ImageListImpl_SetBkColor(IImageList *iface, COLORREF clrBk,
3458 *pclr = ImageList_SetBkColor((HIMAGELIST) iface, clrBk);
3459 return *pclr == CLR_NONE ? E_FAIL : S_OK;
3462 static HRESULT WINAPI ImageListImpl_GetBkColor(IImageList *iface, COLORREF *pclr)
3467 *pclr = ImageList_GetBkColor((HIMAGELIST) iface);
3471 static HRESULT WINAPI ImageListImpl_BeginDrag(IImageList *iface, int iTrack,
3472 int dxHotspot, int dyHotspot)
3474 return ImageList_BeginDrag((HIMAGELIST) iface, iTrack, dxHotspot, dyHotspot) ? S_OK : E_FAIL;
3477 static HRESULT WINAPI ImageListImpl_EndDrag(IImageList *iface)
3479 ImageList_EndDrag();
3483 static HRESULT WINAPI ImageListImpl_DragEnter(IImageList *iface, HWND hwndLock,
3486 return ImageList_DragEnter(hwndLock, x, y) ? S_OK : E_FAIL;
3489 static HRESULT WINAPI ImageListImpl_DragLeave(IImageList *iface, HWND hwndLock)
3491 return ImageList_DragLeave(hwndLock) ? S_OK : E_FAIL;
3494 static HRESULT WINAPI ImageListImpl_DragMove(IImageList *iface, int x, int y)
3496 return ImageList_DragMove(x, y) ? S_OK : E_FAIL;
3499 static HRESULT WINAPI ImageListImpl_SetDragCursorImage(IImageList *iface,
3500 IUnknown *punk, int iDrag, int dxHotspot, int dyHotspot)
3502 IImageList *iml2 = NULL;
3508 /* TODO: Add test for IID_ImageList2 too */
3509 if (FAILED(IImageList_QueryInterface(punk, &IID_IImageList,
3513 ret = ImageList_SetDragCursorImage((HIMAGELIST) iml2, iDrag, dxHotspot,
3516 IImageList_Release(iml2);
3518 return ret ? S_OK : E_FAIL;
3521 static HRESULT WINAPI ImageListImpl_DragShowNolock(IImageList *iface, BOOL fShow)
3523 return ImageList_DragShowNolock(fShow) ? S_OK : E_FAIL;
3526 static HRESULT WINAPI ImageListImpl_GetDragImage(IImageList *iface, POINT *ppt,
3527 POINT *pptHotspot, REFIID riid, PVOID *ppv)
3529 HRESULT ret = E_FAIL;
3535 hNew = ImageList_GetDragImage(ppt, pptHotspot);
3537 /* Get the interface for the new image list */
3539 ret = HIMAGELIST_QueryInterface(hNew, riid, ppv);
3544 static HRESULT WINAPI ImageListImpl_GetItemFlags(IImageList *iface, int i,
3547 FIXME("STUB: %p %d %p\n", iface, i, dwFlags);
3551 static HRESULT WINAPI ImageListImpl_GetOverlayImage(IImageList *iface, int iOverlay,
3554 HIMAGELIST This = (HIMAGELIST) iface;
3557 if ((iOverlay < 0) || (iOverlay > This->cCurImage))
3560 for (i = 0; i < MAX_OVERLAYIMAGE; i++)
3562 if (This->nOvlIdx[i] == iOverlay)
3573 static const IImageListVtbl ImageListImpl_Vtbl = {
3574 ImageListImpl_QueryInterface,
3575 ImageListImpl_AddRef,
3576 ImageListImpl_Release,
3578 ImageListImpl_ReplaceIcon,
3579 ImageListImpl_SetOverlayImage,
3580 ImageListImpl_Replace,
3581 ImageListImpl_AddMasked,
3583 ImageListImpl_Remove,
3584 ImageListImpl_GetIcon,
3585 ImageListImpl_GetImageInfo,
3587 ImageListImpl_Merge,
3588 ImageListImpl_Clone,
3589 ImageListImpl_GetImageRect,
3590 ImageListImpl_GetIconSize,
3591 ImageListImpl_SetIconSize,
3592 ImageListImpl_GetImageCount,
3593 ImageListImpl_SetImageCount,
3594 ImageListImpl_SetBkColor,
3595 ImageListImpl_GetBkColor,
3596 ImageListImpl_BeginDrag,
3597 ImageListImpl_EndDrag,
3598 ImageListImpl_DragEnter,
3599 ImageListImpl_DragLeave,
3600 ImageListImpl_DragMove,
3601 ImageListImpl_SetDragCursorImage,
3602 ImageListImpl_DragShowNolock,
3603 ImageListImpl_GetDragImage,
3604 ImageListImpl_GetItemFlags,
3605 ImageListImpl_GetOverlayImage
3608 static inline BOOL is_valid(HIMAGELIST himl)
3610 return himl && himl->lpVtbl == &ImageListImpl_Vtbl;
3613 /*************************************************************************
3614 * HIMAGELIST_QueryInterface [COMCTL32.@]
3616 * Returns a pointer to an IImageList or IImageList2 object for the given
3620 * himl [I] Image list handle.
3621 * riid [I] Identifier of the requested interface.
3622 * ppv [O] Returns the address of the pointer requested, or NULL.
3626 * Failure: Error value.
3629 HIMAGELIST_QueryInterface (HIMAGELIST himl, REFIID riid, void **ppv)
3631 TRACE("(%p,%s,%p)\n", himl, debugstr_guid(riid), ppv);
3632 return IImageList_QueryInterface((IImageList *) himl, riid, ppv);
3635 static HRESULT ImageListImpl_CreateInstance(const IUnknown *pUnkOuter, REFIID iid, void** ppv)
3640 TRACE("(%p,%s,%p)\n", pUnkOuter, debugstr_guid(iid), ppv);
3644 if (pUnkOuter) return CLASS_E_NOAGGREGATION;
3646 This = HeapAlloc(GetProcessHeap(), 0, sizeof(struct _IMAGELIST));
3647 if (!This) return E_OUTOFMEMORY;
3649 ZeroMemory(This, sizeof(struct _IMAGELIST));
3651 This->lpVtbl = &ImageListImpl_Vtbl;
3654 ret = IUnknown_QueryInterface((IUnknown*)This, iid, ppv);
3655 IUnknown_Release((IUnknown*)This);