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;
208 if (hdcMask) StretchBlt( himl->hdcMask, pt.x, pt.y, himl->cx, himl->cy,
209 hdcMask, n * width, 0, width, height, SRCCOPY );
213 if (himl->has_alpha) himl->has_alpha[pos + n] = 1;
215 if (mask_info && himl->hbmMask) /* generate the mask from the alpha channel */
217 for (i = 0; i < height; i++)
218 for (j = n * width; j < (n + 1) * width; j++)
219 if ((bits[i * bm.bmWidth + j] >> 24) > 25) /* more than 10% alpha */
220 mask_bits[i * mask_width + j / 8] &= ~(0x80 >> (j % 8));
222 mask_bits[i * mask_width + j / 8] |= 0x80 >> (j % 8);
223 StretchDIBits( himl->hdcMask, pt.x, pt.y, himl->cx, himl->cy,
224 n * width, 0, width, height, mask_bits, mask_info, DIB_RGB_COLORS, SRCCOPY );
227 StretchDIBits( himl->hdcImage, pt.x, pt.y, himl->cx, himl->cy,
228 n * width, 0, width, height, bits, info, DIB_RGB_COLORS, SRCCOPY );
234 if (hdcMask) DeleteDC( hdcMask );
235 HeapFree( GetProcessHeap(), 0, info );
236 HeapFree( GetProcessHeap(), 0, mask_info );
237 HeapFree( GetProcessHeap(), 0, bits );
238 HeapFree( GetProcessHeap(), 0, mask_bits );
242 /*************************************************************************
243 * IMAGELIST_InternalExpandBitmaps [Internal]
245 * Expands the bitmaps of an image list by the given number of images.
248 * himl [I] handle to image list
249 * nImageCount [I] number of images to add
255 * This function CANNOT be used to reduce the number of images.
258 IMAGELIST_InternalExpandBitmaps(HIMAGELIST himl, INT nImageCount)
261 HBITMAP hbmNewBitmap, hbmNull;
265 TRACE("%p has %d allocated %d images\n", himl, himl->cCurImage, himl->cMaxImage);
267 if (himl->cCurImage + nImageCount <= himl->cMaxImage)
270 nNewCount = himl->cCurImage + max(nImageCount, himl->cGrow) + 1;
272 imagelist_get_bitmap_size(himl, nNewCount, &sz);
274 TRACE("Create expanded bitmaps : himl=%p x=%d y=%d count=%d\n", himl, sz.cx, sz.cy, nNewCount);
275 hdcBitmap = CreateCompatibleDC (0);
277 hbmNewBitmap = ImageList_CreateImage(hdcBitmap, himl, nNewCount);
279 if (hbmNewBitmap == 0)
280 ERR("creating new image bitmap (x=%d y=%d)!\n", sz.cx, sz.cy);
284 hbmNull = SelectObject (hdcBitmap, hbmNewBitmap);
285 BitBlt (hdcBitmap, 0, 0, sz.cx, sz.cy,
286 himl->hdcImage, 0, 0, SRCCOPY);
287 SelectObject (hdcBitmap, hbmNull);
289 SelectObject (himl->hdcImage, hbmNewBitmap);
290 DeleteObject (himl->hbmImage);
291 himl->hbmImage = hbmNewBitmap;
293 if (himl->flags & ILC_MASK)
295 hbmNewBitmap = CreateBitmap (sz.cx, sz.cy, 1, 1, NULL);
297 if (hbmNewBitmap == 0)
298 ERR("creating new mask bitmap!\n");
302 hbmNull = SelectObject (hdcBitmap, hbmNewBitmap);
303 BitBlt (hdcBitmap, 0, 0, sz.cx, sz.cy,
304 himl->hdcMask, 0, 0, SRCCOPY);
305 SelectObject (hdcBitmap, hbmNull);
307 SelectObject (himl->hdcMask, hbmNewBitmap);
308 DeleteObject (himl->hbmMask);
309 himl->hbmMask = hbmNewBitmap;
314 char *new_alpha = HeapReAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, himl->has_alpha, nNewCount );
315 if (new_alpha) himl->has_alpha = new_alpha;
318 HeapFree( GetProcessHeap(), 0, himl->has_alpha );
319 himl->has_alpha = NULL;
323 himl->cMaxImage = nNewCount;
325 DeleteDC (hdcBitmap);
329 /*************************************************************************
330 * ImageList_Add [COMCTL32.@]
332 * Add an image or images to an image list.
335 * himl [I] handle to image list
336 * hbmImage [I] handle to image bitmap
337 * hbmMask [I] handle to mask bitmap
340 * Success: Index of the first new image.
345 ImageList_Add (HIMAGELIST himl, HBITMAP hbmImage, HBITMAP hbmMask)
347 HDC hdcBitmap, hdcTemp = 0;
348 INT nFirstIndex, nImageCount, i;
352 TRACE("himl=%p hbmimage=%p hbmmask=%p\n", himl, hbmImage, hbmMask);
356 if (!GetObjectW(hbmImage, sizeof(BITMAP), &bmp))
359 TRACE("himl %p, cCurImage %d, cMaxImage %d, cGrow %d, cx %d, cy %d\n",
360 himl, himl->cCurImage, himl->cMaxImage, himl->cGrow, himl->cx, himl->cy);
362 nImageCount = bmp.bmWidth / himl->cx;
364 TRACE("%p has %d images (%d x %d)\n", hbmImage, nImageCount, bmp.bmWidth, bmp.bmHeight);
366 IMAGELIST_InternalExpandBitmaps(himl, nImageCount);
368 hdcBitmap = CreateCompatibleDC(0);
370 SelectObject(hdcBitmap, hbmImage);
372 if (add_with_alpha( himl, hdcBitmap, himl->cCurImage, nImageCount,
373 himl->cx, min( himl->cy, bmp.bmHeight), hbmImage, hbmMask ))
378 hdcTemp = CreateCompatibleDC(0);
379 SelectObject(hdcTemp, hbmMask);
382 for (i=0; i<nImageCount; i++)
384 imagelist_point_from_index( himl, himl->cCurImage + i, &pt );
386 /* Copy result to the imagelist
388 BitBlt( himl->hdcImage, pt.x, pt.y, himl->cx, bmp.bmHeight,
389 hdcBitmap, i*himl->cx, 0, SRCCOPY );
394 BitBlt( himl->hdcMask, pt.x, pt.y, himl->cx, bmp.bmHeight,
395 hdcTemp, i*himl->cx, 0, SRCCOPY );
397 /* Remove the background from the image
399 BitBlt( himl->hdcImage, pt.x, pt.y, himl->cx, bmp.bmHeight,
400 himl->hdcMask, pt.x, pt.y, 0x220326 ); /* NOTSRCAND */
402 if (hdcTemp) DeleteDC(hdcTemp);
407 nFirstIndex = himl->cCurImage;
408 himl->cCurImage += nImageCount;
414 /*************************************************************************
415 * ImageList_AddIcon [COMCTL32.@]
417 * Adds an icon to an image list.
420 * himl [I] handle to image list
421 * hIcon [I] handle to icon
424 * Success: index of the new image
427 #undef ImageList_AddIcon
428 INT WINAPI ImageList_AddIcon (HIMAGELIST himl, HICON hIcon)
430 return ImageList_ReplaceIcon (himl, -1, hIcon);
434 /*************************************************************************
435 * ImageList_AddMasked [COMCTL32.@]
437 * Adds an image or images to an image list and creates a mask from the
438 * specified bitmap using the mask color.
441 * himl [I] handle to image list.
442 * hBitmap [I] handle to bitmap
443 * clrMask [I] mask color.
446 * Success: Index of the first new image.
451 ImageList_AddMasked (HIMAGELIST himl, HBITMAP hBitmap, COLORREF clrMask)
453 HDC hdcMask, hdcBitmap;
459 TRACE("himl=%p hbitmap=%p clrmask=%x\n", himl, hBitmap, clrMask);
463 if (!GetObjectW(hBitmap, sizeof(BITMAP), &bmp))
466 hdcBitmap = CreateCompatibleDC(0);
467 SelectObject(hdcBitmap, hBitmap);
469 /* Create a temp Mask so we can remove the background of the Image */
470 hdcMask = CreateCompatibleDC(0);
471 hMaskBitmap = CreateBitmap(bmp.bmWidth, bmp.bmHeight, 1, 1, NULL);
472 SelectObject(hdcMask, hMaskBitmap);
474 /* create monochrome image to the mask bitmap */
475 bkColor = (clrMask != CLR_DEFAULT) ? clrMask : GetPixel (hdcBitmap, 0, 0);
476 SetBkColor (hdcBitmap, bkColor);
477 BitBlt (hdcMask, 0, 0, bmp.bmWidth, bmp.bmHeight, hdcBitmap, 0, 0, SRCCOPY);
479 SetBkColor(hdcBitmap, RGB(255,255,255));
482 * Remove the background from the image
484 * WINDOWS BUG ALERT!!!!!!
485 * The statement below should not be done in common practice
486 * but this is how ImageList_AddMasked works in Windows.
487 * It overwrites the original bitmap passed, this was discovered
488 * by using the same bitmap to iterate the different styles
489 * on windows where it failed (BUT ImageList_Add is OK)
490 * This is here in case some apps rely on this bug
492 * Blt mode 0x220326 is NOTSRCAND
494 BitBlt(hdcBitmap, 0, 0, bmp.bmWidth, bmp.bmHeight, hdcMask, 0, 0, 0x220326);
499 ret = ImageList_Add( himl, hBitmap, hMaskBitmap );
501 DeleteObject(hMaskBitmap);
506 /*************************************************************************
507 * ImageList_BeginDrag [COMCTL32.@]
509 * Creates a temporary image list that contains one image. It will be used
513 * himlTrack [I] handle to the source image list
514 * iTrack [I] index of the drag image in the source image list
515 * dxHotspot [I] X position of the hot spot of the drag image
516 * dyHotspot [I] Y position of the hot spot of the drag image
524 ImageList_BeginDrag (HIMAGELIST himlTrack, INT iTrack,
525 INT dxHotspot, INT dyHotspot)
529 TRACE("(himlTrack=%p iTrack=%d dx=%d dy=%d)\n", himlTrack, iTrack,
530 dxHotspot, dyHotspot);
532 if (!is_valid(himlTrack))
535 if (InternalDrag.himl)
536 ImageList_EndDrag ();
541 InternalDrag.himl = ImageList_Create (cx, cy, himlTrack->flags, 1, 1);
542 if (InternalDrag.himl == NULL) {
543 WARN("Error creating drag image list!\n");
547 InternalDrag.dxHotspot = dxHotspot;
548 InternalDrag.dyHotspot = dyHotspot;
551 BitBlt (InternalDrag.himl->hdcImage, 0, 0, cx, cy, himlTrack->hdcImage, iTrack * cx, 0, SRCCOPY);
554 BitBlt (InternalDrag.himl->hdcMask, 0, 0, cx, cy, himlTrack->hdcMask, iTrack * cx, 0, SRCCOPY);
556 InternalDrag.himl->cCurImage = 1;
562 /*************************************************************************
563 * ImageList_Copy [COMCTL32.@]
565 * Copies an image of the source image list to an image of the
566 * destination image list. Images can be copied or swapped.
569 * himlDst [I] handle to the destination image list
570 * iDst [I] destination image index.
571 * himlSrc [I] handle to the source image list
572 * iSrc [I] source image index
573 * uFlags [I] flags for the copy operation
580 * Copying from one image list to another is possible. The original
581 * implementation just copies or swaps within one image list.
582 * Could this feature become a bug??? ;-)
586 ImageList_Copy (HIMAGELIST himlDst, INT iDst, HIMAGELIST himlSrc,
587 INT iSrc, UINT uFlags)
591 TRACE("himlDst=%p iDst=%d himlSrc=%p iSrc=%d\n", himlDst, iDst, himlSrc, iSrc);
593 if (!is_valid(himlSrc) || !is_valid(himlDst))
595 if ((iDst < 0) || (iDst >= himlDst->cCurImage))
597 if ((iSrc < 0) || (iSrc >= himlSrc->cCurImage))
600 imagelist_point_from_index( himlDst, iDst, &ptDst );
601 imagelist_point_from_index( himlSrc, iSrc, &ptSrc );
603 if (uFlags & ILCF_SWAP) {
606 HBITMAP hbmTempImage, hbmTempMask;
608 hdcBmp = CreateCompatibleDC (0);
610 /* create temporary bitmaps */
611 hbmTempImage = CreateBitmap (himlSrc->cx, himlSrc->cy, 1,
612 himlSrc->uBitsPixel, NULL);
613 hbmTempMask = CreateBitmap (himlSrc->cx, himlSrc->cy, 1,
616 /* copy (and stretch) destination to temporary bitmaps.(save) */
618 SelectObject (hdcBmp, hbmTempImage);
619 StretchBlt (hdcBmp, 0, 0, himlSrc->cx, himlSrc->cy,
620 himlDst->hdcImage, ptDst.x, ptDst.y, himlDst->cx, himlDst->cy,
623 SelectObject (hdcBmp, hbmTempMask);
624 StretchBlt (hdcBmp, 0, 0, himlSrc->cx, himlSrc->cy,
625 himlDst->hdcMask, ptDst.x, ptDst.y, himlDst->cx, himlDst->cy,
628 /* copy (and stretch) source to destination */
630 StretchBlt (himlDst->hdcImage, ptDst.x, ptDst.y, himlDst->cx, himlDst->cy,
631 himlSrc->hdcImage, ptSrc.x, ptSrc.y, himlSrc->cx, himlSrc->cy,
634 StretchBlt (himlDst->hdcMask, ptDst.x, ptDst.y, himlDst->cx, himlDst->cy,
635 himlSrc->hdcMask, ptSrc.x, ptSrc.y, himlSrc->cx, himlSrc->cy,
638 /* copy (without stretching) temporary bitmaps to source (restore) */
640 BitBlt (himlSrc->hdcMask, ptSrc.x, ptSrc.y, himlSrc->cx, himlSrc->cy,
641 hdcBmp, 0, 0, SRCCOPY);
644 BitBlt (himlSrc->hdcImage, ptSrc.x, ptSrc.y, himlSrc->cx, himlSrc->cy,
645 hdcBmp, 0, 0, SRCCOPY);
646 /* delete temporary bitmaps */
647 DeleteObject (hbmTempMask);
648 DeleteObject (hbmTempImage);
653 StretchBlt (himlDst->hdcImage, ptDst.x, ptDst.y, himlDst->cx, himlDst->cy,
654 himlSrc->hdcImage, ptSrc.x, ptSrc.y, himlSrc->cx, himlSrc->cy,
658 StretchBlt (himlDst->hdcMask, ptDst.x, ptDst.y, himlDst->cx, himlDst->cy,
659 himlSrc->hdcMask, ptSrc.x, ptSrc.y, himlSrc->cx, himlSrc->cy,
667 /*************************************************************************
668 * ImageList_Create [COMCTL32.@]
670 * Creates a new image list.
673 * cx [I] image height
675 * flags [I] creation flags
676 * cInitial [I] initial number of images in the image list
677 * cGrow [I] number of images by which image list grows
680 * Success: Handle to the created image list
684 ImageList_Create (INT cx, INT cy, UINT flags,
685 INT cInitial, INT cGrow)
690 UINT ilc = (flags & 0xFE);
691 static const WORD aBitBlend25[] =
692 {0xAA, 0x00, 0x55, 0x00, 0xAA, 0x00, 0x55, 0x00};
694 static const WORD aBitBlend50[] =
695 {0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA};
697 TRACE("(%d %d 0x%x %d %d)\n", cx, cy, flags, cInitial, cGrow);
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 (himl->uBitsPixel == 32)
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 )
1162 HBITMAP bmp = 0, mask = 0;
1164 void *bits, *mask_bits;
1168 if (!(hdc = CreateCompatibleDC( 0 ))) return FALSE;
1169 if (!(info = HeapAlloc( GetProcessHeap(), 0, FIELD_OFFSET( BITMAPINFO, bmiColors[256] )))) goto done;
1170 info->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
1171 info->bmiHeader.biWidth = cx;
1172 info->bmiHeader.biHeight = cy;
1173 info->bmiHeader.biPlanes = 1;
1174 info->bmiHeader.biBitCount = 32;
1175 info->bmiHeader.biCompression = BI_RGB;
1176 info->bmiHeader.biSizeImage = cx * cy * 4;
1177 info->bmiHeader.biXPelsPerMeter = 0;
1178 info->bmiHeader.biYPelsPerMeter = 0;
1179 info->bmiHeader.biClrUsed = 0;
1180 info->bmiHeader.biClrImportant = 0;
1181 if (!(bmp = CreateDIBSection( himl->hdcImage, info, DIB_RGB_COLORS, &bits, 0, 0 ))) goto done;
1182 SelectObject( hdc, bmp );
1183 BitBlt( hdc, 0, 0, cx, cy, himl->hdcImage, src_x, src_y, SRCCOPY );
1185 if (himl->uBitsPixel == 32) /* we already have an alpha channel in this case */
1187 /* pre-multiply by the alpha channel */
1188 for (i = 0, ptr = bits; i < cx * cy; i++, ptr++)
1190 DWORD alpha = *ptr >> 24;
1191 *ptr = ((*ptr & 0xff000000) |
1192 (((*ptr & 0x00ff0000) * alpha / 255) & 0x00ff0000) |
1193 (((*ptr & 0x0000ff00) * alpha / 255) & 0x0000ff00) |
1194 (((*ptr & 0x000000ff) * alpha / 255)));
1197 else if (himl->hbmMask)
1199 unsigned int width_bytes = (cx + 31) / 32 * 4;
1200 /* generate alpha channel from the mask */
1201 info->bmiHeader.biBitCount = 1;
1202 info->bmiHeader.biSizeImage = width_bytes * cy;
1203 if (!(mask = CreateDIBSection( himl->hdcMask, info, DIB_RGB_COLORS, &mask_bits, 0, 0 )))
1205 SelectObject( hdc, mask );
1206 BitBlt( hdc, 0, 0, cx, cy, himl->hdcMask, src_x, src_y, SRCCOPY );
1207 SelectObject( hdc, bmp );
1208 for (i = 0, ptr = bits; i < cy; i++)
1209 for (j = 0; j < cx; j++, ptr++)
1210 if ((((BYTE *)mask_bits)[i * width_bytes + j / 8] << (j % 8)) & 0x80) *ptr = 0;
1211 else *ptr |= 0xff000000;
1214 ret = GdiAlphaBlend( dest_dc, dest_x, dest_y, cx, cy, hdc, 0, 0, cx, cy, func );
1218 if (bmp) DeleteObject( bmp );
1219 if (mask) DeleteObject( mask );
1220 HeapFree( GetProcessHeap(), 0, info );
1224 /*************************************************************************
1225 * ImageList_DrawIndirect [COMCTL32.@]
1227 * Draws an image using various parameters specified in pimldp.
1230 * pimldp [I] pointer to IMAGELISTDRAWPARAMS structure.
1238 ImageList_DrawIndirect (IMAGELISTDRAWPARAMS *pimldp)
1240 INT cx, cy, nOvlIdx;
1241 DWORD fState, dwRop;
1243 COLORREF oldImageBk, oldImageFg;
1244 HDC hImageDC, hImageListDC, hMaskListDC;
1245 HBITMAP hImageBmp, hOldImageBmp, hBlendMaskBmp;
1246 BOOL bIsTransparent, bBlend, bResult = FALSE, bMask;
1252 if (!pimldp || !(himl = pimldp->himl)) return FALSE;
1253 if (!is_valid(himl)) return FALSE;
1254 if ((pimldp->i < 0) || (pimldp->i >= himl->cCurImage)) return FALSE;
1256 imagelist_point_from_index( himl, pimldp->i, &pt );
1257 pt.x += pimldp->xBitmap;
1258 pt.y += pimldp->yBitmap;
1260 fState = pimldp->cbSize < sizeof(IMAGELISTDRAWPARAMS) ? ILS_NORMAL : pimldp->fState;
1261 fStyle = pimldp->fStyle & ~ILD_OVERLAYMASK;
1262 cx = (pimldp->cx == 0) ? himl->cx : pimldp->cx;
1263 cy = (pimldp->cy == 0) ? himl->cy : pimldp->cy;
1265 bIsTransparent = (fStyle & ILD_TRANSPARENT);
1266 if( pimldp->rgbBk == CLR_NONE )
1267 bIsTransparent = TRUE;
1268 if( ( pimldp->rgbBk == CLR_DEFAULT ) && ( himl->clrBk == CLR_NONE ) )
1269 bIsTransparent = TRUE;
1270 bMask = (himl->flags & ILC_MASK) && (fStyle & ILD_MASK) ;
1271 bBlend = (fStyle & (ILD_BLEND25 | ILD_BLEND50) ) && !bMask;
1273 TRACE("himl(%p) hbmMask(%p) iImage(%d) x(%d) y(%d) cx(%d) cy(%d)\n",
1274 himl, himl->hbmMask, pimldp->i, pimldp->x, pimldp->y, cx, cy);
1276 /* we will use these DCs to access the images and masks in the ImageList */
1277 hImageListDC = himl->hdcImage;
1278 hMaskListDC = himl->hdcMask;
1280 /* these will accumulate the image and mask for the image we're drawing */
1281 hImageDC = CreateCompatibleDC( pimldp->hdcDst );
1282 hImageBmp = CreateCompatibleBitmap( pimldp->hdcDst, cx, cy );
1283 hBlendMaskBmp = bBlend ? CreateBitmap(cx, cy, 1, 1, NULL) : 0;
1285 /* Create a compatible DC. */
1286 if (!hImageListDC || !hImageDC || !hImageBmp ||
1287 (bBlend && !hBlendMaskBmp) || (himl->hbmMask && !hMaskListDC))
1290 hOldImageBmp = SelectObject(hImageDC, hImageBmp);
1293 * To obtain a transparent look, background color should be set
1294 * to white and foreground color to black when blitting the
1297 oldImageFg = SetTextColor( hImageDC, RGB( 0, 0, 0 ) );
1298 oldImageBk = SetBkColor( hImageDC, RGB( 0xff, 0xff, 0xff ) );
1300 has_alpha = (himl->has_alpha && himl->has_alpha[pimldp->i]);
1301 if (!bMask && (has_alpha || (fState & ILS_ALPHA)))
1306 func.BlendOp = AC_SRC_OVER;
1307 func.BlendFlags = 0;
1308 func.SourceConstantAlpha = (fState & ILS_ALPHA) ? pimldp->Frame : 255;
1309 func.AlphaFormat = AC_SRC_ALPHA;
1313 bResult = alpha_blend_image( himl, pimldp->hdcDst, pimldp->x, pimldp->y,
1314 pt.x, pt.y, cx, cy, func );
1317 colour = pimldp->rgbBk;
1318 if (colour == CLR_DEFAULT) colour = himl->clrBk;
1319 if (colour == CLR_NONE) colour = GetBkColor( pimldp->hdcDst );
1321 hOldBrush = SelectObject (hImageDC, CreateSolidBrush (colour));
1322 PatBlt( hImageDC, 0, 0, cx, cy, PATCOPY );
1323 alpha_blend_image( himl, hImageDC, 0, 0, pt.x, pt.y, cx, cy, func );
1324 DeleteObject (SelectObject (hImageDC, hOldBrush));
1325 bResult = BitBlt( pimldp->hdcDst, pimldp->x, pimldp->y, cx, cy, hImageDC, 0, 0, SRCCOPY );
1330 * Draw the initial image
1333 if (himl->hbmMask) {
1334 hOldBrush = SelectObject (hImageDC, CreateSolidBrush (GetTextColor(pimldp->hdcDst)));
1335 PatBlt( hImageDC, 0, 0, cx, cy, PATCOPY );
1336 BitBlt(hImageDC, 0, 0, cx, cy, hMaskListDC, pt.x, pt.y, SRCPAINT);
1337 DeleteObject (SelectObject (hImageDC, hOldBrush));
1338 if( bIsTransparent )
1340 BitBlt ( pimldp->hdcDst, pimldp->x, pimldp->y, cx, cy, hImageDC, 0, 0, SRCAND);
1345 hOldBrush = SelectObject (hImageDC, GetStockObject(BLACK_BRUSH));
1346 PatBlt( hImageDC, 0, 0, cx, cy, PATCOPY);
1347 SelectObject(hImageDC, hOldBrush);
1350 /* blend the image with the needed solid background */
1351 COLORREF colour = RGB(0,0,0);
1353 if( !bIsTransparent )
1355 colour = pimldp->rgbBk;
1356 if( colour == CLR_DEFAULT )
1357 colour = himl->clrBk;
1358 if( colour == CLR_NONE )
1359 colour = GetBkColor(pimldp->hdcDst);
1362 hOldBrush = SelectObject (hImageDC, CreateSolidBrush (colour));
1363 PatBlt( hImageDC, 0, 0, cx, cy, PATCOPY );
1366 BitBlt( hImageDC, 0, 0, cx, cy, hMaskListDC, pt.x, pt.y, SRCAND );
1367 BitBlt( hImageDC, 0, 0, cx, cy, hImageListDC, pt.x, pt.y, SRCPAINT );
1370 BitBlt( hImageDC, 0, 0, cx, cy, hImageListDC, pt.x, pt.y, SRCCOPY);
1371 DeleteObject (SelectObject (hImageDC, hOldBrush));
1374 /* Time for blending, if required */
1377 COLORREF clrBlend = pimldp->rgbFg;
1378 HDC hBlendMaskDC = hImageListDC;
1381 /* Create the blend Mask */
1382 hOldBitmap = SelectObject(hBlendMaskDC, hBlendMaskBmp);
1383 hBlendBrush = fStyle & ILD_BLEND50 ? himl->hbrBlend50 : himl->hbrBlend25;
1384 hOldBrush = SelectObject(hBlendMaskDC, hBlendBrush);
1385 PatBlt(hBlendMaskDC, 0, 0, cx, cy, PATCOPY);
1386 SelectObject(hBlendMaskDC, hOldBrush);
1388 /* Modify the blend mask if an Image Mask exist */
1390 BitBlt(hBlendMaskDC, 0, 0, cx, cy, hMaskListDC, pt.x, pt.y, 0x220326); /* NOTSRCAND */
1391 BitBlt(hBlendMaskDC, 0, 0, cx, cy, hBlendMaskDC, 0, 0, NOTSRCCOPY);
1394 /* now apply blend to the current image given the BlendMask */
1395 if (clrBlend == CLR_DEFAULT) clrBlend = GetSysColor (COLOR_HIGHLIGHT);
1396 else if (clrBlend == CLR_NONE) clrBlend = GetTextColor (pimldp->hdcDst);
1397 hOldBrush = SelectObject (hImageDC, CreateSolidBrush(clrBlend));
1398 BitBlt (hImageDC, 0, 0, cx, cy, hBlendMaskDC, 0, 0, 0xB8074A); /* PSDPxax */
1399 DeleteObject(SelectObject(hImageDC, hOldBrush));
1400 SelectObject(hBlendMaskDC, hOldBitmap);
1403 /* Now do the overlay image, if any */
1404 nOvlIdx = (pimldp->fStyle & ILD_OVERLAYMASK) >> 8;
1405 if ( (nOvlIdx >= 1) && (nOvlIdx <= MAX_OVERLAYIMAGE)) {
1406 nOvlIdx = himl->nOvlIdx[nOvlIdx - 1];
1407 if ((nOvlIdx >= 0) && (nOvlIdx < himl->cCurImage)) {
1409 imagelist_point_from_index( himl, nOvlIdx, &ptOvl );
1410 ptOvl.x += pimldp->xBitmap;
1411 if (himl->hbmMask && !(fStyle & ILD_IMAGE))
1412 BitBlt (hImageDC, 0, 0, cx, cy, hMaskListDC, ptOvl.x, ptOvl.y, SRCAND);
1413 BitBlt (hImageDC, 0, 0, cx, cy, hImageListDC, ptOvl.x, ptOvl.y, SRCPAINT);
1417 if (fState & ILS_SATURATE) FIXME("ILS_SATURATE: unimplemented!\n");
1418 if (fState & ILS_GLOW) FIXME("ILS_GLOW: unimplemented!\n");
1419 if (fState & ILS_SHADOW) FIXME("ILS_SHADOW: unimplemented!\n");
1421 if (fStyle & ILD_PRESERVEALPHA) FIXME("ILD_PRESERVEALPHA: unimplemented!\n");
1422 if (fStyle & ILD_SCALE) FIXME("ILD_SCALE: unimplemented!\n");
1423 if (fStyle & ILD_DPISCALE) FIXME("ILD_DPISCALE: unimplemented!\n");
1425 /* now copy the image to the screen */
1427 if (himl->hbmMask && bIsTransparent ) {
1428 COLORREF oldDstFg = SetTextColor(pimldp->hdcDst, RGB( 0, 0, 0 ) );
1429 COLORREF oldDstBk = SetBkColor(pimldp->hdcDst, RGB( 0xff, 0xff, 0xff ));
1430 BitBlt (pimldp->hdcDst, pimldp->x, pimldp->y, cx, cy, hMaskListDC, pt.x, pt.y, SRCAND);
1431 SetBkColor(pimldp->hdcDst, oldDstBk);
1432 SetTextColor(pimldp->hdcDst, oldDstFg);
1435 if (fStyle & ILD_ROP) dwRop = pimldp->dwRop;
1436 BitBlt (pimldp->hdcDst, pimldp->x, pimldp->y, cx, cy, hImageDC, 0, 0, dwRop);
1440 /* cleanup the mess */
1441 SetBkColor(hImageDC, oldImageBk);
1442 SetTextColor(hImageDC, oldImageFg);
1443 SelectObject(hImageDC, hOldImageBmp);
1445 DeleteObject(hBlendMaskBmp);
1446 DeleteObject(hImageBmp);
1453 /*************************************************************************
1454 * ImageList_Duplicate [COMCTL32.@]
1456 * Duplicates an image list.
1459 * himlSrc [I] source image list handle
1462 * Success: Handle of duplicated image list.
1467 ImageList_Duplicate (HIMAGELIST himlSrc)
1471 if (!is_valid(himlSrc)) {
1472 ERR("Invalid image list handle!\n");
1476 himlDst = ImageList_Create (himlSrc->cx, himlSrc->cy, himlSrc->flags,
1477 himlSrc->cCurImage, himlSrc->cGrow);
1483 imagelist_get_bitmap_size(himlSrc, himlSrc->cCurImage, &sz);
1484 BitBlt (himlDst->hdcImage, 0, 0, sz.cx, sz.cy,
1485 himlSrc->hdcImage, 0, 0, SRCCOPY);
1487 if (himlDst->hbmMask)
1488 BitBlt (himlDst->hdcMask, 0, 0, sz.cx, sz.cy,
1489 himlSrc->hdcMask, 0, 0, SRCCOPY);
1491 himlDst->cCurImage = himlSrc->cCurImage;
1492 himlDst->cMaxImage = himlSrc->cMaxImage;
1493 if (himlSrc->has_alpha && himlDst->has_alpha)
1494 memcpy( himlDst->has_alpha, himlSrc->has_alpha, himlDst->cCurImage );
1500 /*************************************************************************
1501 * ImageList_EndDrag [COMCTL32.@]
1503 * Finishes a drag operation.
1514 ImageList_EndDrag (void)
1516 /* cleanup the InternalDrag struct */
1517 InternalDrag.hwnd = 0;
1518 ImageList_Destroy (InternalDrag.himl);
1519 InternalDrag.himl = 0;
1522 InternalDrag.dxHotspot = 0;
1523 InternalDrag.dyHotspot = 0;
1524 InternalDrag.bShow = FALSE;
1525 DeleteObject(InternalDrag.hbmBg);
1526 InternalDrag.hbmBg = 0;
1530 /*************************************************************************
1531 * ImageList_GetBkColor [COMCTL32.@]
1533 * Returns the background color of an image list.
1536 * himl [I] Image list handle.
1539 * Success: background color
1544 ImageList_GetBkColor (HIMAGELIST himl)
1546 return himl ? himl->clrBk : CLR_NONE;
1550 /*************************************************************************
1551 * ImageList_GetDragImage [COMCTL32.@]
1553 * Returns the handle to the internal drag image list.
1556 * ppt [O] Pointer to the drag position. Can be NULL.
1557 * pptHotspot [O] Pointer to the position of the hot spot. Can be NULL.
1560 * Success: Handle of the drag image list.
1565 ImageList_GetDragImage (POINT *ppt, POINT *pptHotspot)
1567 if (is_valid(InternalDrag.himl)) {
1569 ppt->x = InternalDrag.x;
1570 ppt->y = InternalDrag.y;
1573 pptHotspot->x = InternalDrag.dxHotspot;
1574 pptHotspot->y = InternalDrag.dyHotspot;
1576 return (InternalDrag.himl);
1583 /*************************************************************************
1584 * ImageList_GetFlags [COMCTL32.@]
1586 * Gets the flags of the specified image list.
1589 * himl [I] Handle to image list
1599 ImageList_GetFlags(HIMAGELIST himl)
1601 TRACE("%p\n", himl);
1603 return is_valid(himl) ? himl->flags : 0;
1607 /*************************************************************************
1608 * ImageList_GetIcon [COMCTL32.@]
1610 * Creates an icon from a masked image of an image list.
1613 * himl [I] handle to image list
1615 * flags [I] drawing style flags
1618 * Success: icon handle
1623 ImageList_GetIcon (HIMAGELIST himl, INT i, UINT fStyle)
1627 HBITMAP hOldDstBitmap;
1631 TRACE("%p %d %d\n", himl, i, fStyle);
1632 if (!is_valid(himl) || (i < 0) || (i >= himl->cCurImage)) return NULL;
1638 /* create colour bitmap */
1640 ii.hbmColor = CreateCompatibleBitmap(hdcDst, himl->cx, himl->cy);
1641 ReleaseDC(0, hdcDst);
1643 hdcDst = CreateCompatibleDC(0);
1645 imagelist_point_from_index( himl, i, &pt );
1648 ii.hbmMask = CreateBitmap (himl->cx, himl->cy, 1, 1, NULL);
1649 hOldDstBitmap = SelectObject (hdcDst, ii.hbmMask);
1650 if (himl->hbmMask) {
1651 BitBlt (hdcDst, 0, 0, himl->cx, himl->cy,
1652 himl->hdcMask, pt.x, pt.y, SRCCOPY);
1655 PatBlt (hdcDst, 0, 0, himl->cx, himl->cy, BLACKNESS);
1658 SelectObject (hdcDst, ii.hbmColor);
1659 BitBlt (hdcDst, 0, 0, himl->cx, himl->cy,
1660 himl->hdcImage, pt.x, pt.y, SRCCOPY);
1663 * CreateIconIndirect requires us to deselect the bitmaps from
1664 * the DCs before calling
1666 SelectObject(hdcDst, hOldDstBitmap);
1668 hIcon = CreateIconIndirect (&ii);
1670 DeleteObject (ii.hbmMask);
1671 DeleteObject (ii.hbmColor);
1678 /*************************************************************************
1679 * ImageList_GetIconSize [COMCTL32.@]
1681 * Retrieves the size of an image in an image list.
1684 * himl [I] handle to image list
1685 * cx [O] pointer to the image width.
1686 * cy [O] pointer to the image height.
1693 * All images in an image list have the same size.
1697 ImageList_GetIconSize (HIMAGELIST himl, INT *cx, INT *cy)
1699 if (!is_valid(himl))
1701 if ((himl->cx <= 0) || (himl->cy <= 0))
1713 /*************************************************************************
1714 * ImageList_GetImageCount [COMCTL32.@]
1716 * Returns the number of images in an image list.
1719 * himl [I] handle to image list
1722 * Success: Number of images.
1727 ImageList_GetImageCount (HIMAGELIST himl)
1729 if (!is_valid(himl))
1732 return himl->cCurImage;
1736 /*************************************************************************
1737 * ImageList_GetImageInfo [COMCTL32.@]
1739 * Returns information about an image in an image list.
1742 * himl [I] handle to image list
1744 * pImageInfo [O] pointer to the image information
1752 ImageList_GetImageInfo (HIMAGELIST himl, INT i, IMAGEINFO *pImageInfo)
1756 if (!is_valid(himl) || (pImageInfo == NULL))
1758 if ((i < 0) || (i >= himl->cCurImage))
1761 pImageInfo->hbmImage = himl->hbmImage;
1762 pImageInfo->hbmMask = himl->hbmMask;
1764 imagelist_point_from_index( himl, i, &pt );
1765 pImageInfo->rcImage.top = pt.y;
1766 pImageInfo->rcImage.bottom = pt.y + himl->cy;
1767 pImageInfo->rcImage.left = pt.x;
1768 pImageInfo->rcImage.right = pt.x + himl->cx;
1774 /*************************************************************************
1775 * ImageList_GetImageRect [COMCTL32.@]
1777 * Retrieves the rectangle of the specified image in an image list.
1780 * himl [I] handle to image list
1782 * lpRect [O] pointer to the image rectangle
1789 * This is an UNDOCUMENTED function!!!
1793 ImageList_GetImageRect (HIMAGELIST himl, INT i, LPRECT lpRect)
1797 if (!is_valid(himl) || (lpRect == NULL))
1799 if ((i < 0) || (i >= himl->cCurImage))
1802 imagelist_point_from_index( himl, i, &pt );
1803 lpRect->left = pt.x;
1805 lpRect->right = pt.x + himl->cx;
1806 lpRect->bottom = pt.y + himl->cy;
1812 /*************************************************************************
1813 * ImageList_LoadImage [COMCTL32.@]
1814 * ImageList_LoadImageA [COMCTL32.@]
1816 * Creates an image list from a bitmap, icon or cursor.
1818 * See ImageList_LoadImageW.
1822 ImageList_LoadImageA (HINSTANCE hi, LPCSTR lpbmp, INT cx, INT cGrow,
1823 COLORREF clrMask, UINT uType, UINT uFlags)
1829 if (IS_INTRESOURCE(lpbmp))
1830 return ImageList_LoadImageW(hi, (LPCWSTR)lpbmp, cx, cGrow, clrMask,
1833 len = MultiByteToWideChar(CP_ACP, 0, lpbmp, -1, NULL, 0);
1834 lpbmpW = Alloc(len * sizeof(WCHAR));
1835 MultiByteToWideChar(CP_ACP, 0, lpbmp, -1, lpbmpW, len);
1837 himl = ImageList_LoadImageW(hi, lpbmpW, cx, cGrow, clrMask, uType, uFlags);
1843 /*************************************************************************
1844 * ImageList_LoadImageW [COMCTL32.@]
1846 * Creates an image list from a bitmap, icon or cursor.
1849 * hi [I] instance handle
1850 * lpbmp [I] name or id of the image
1851 * cx [I] width of each image
1852 * cGrow [I] number of images to expand
1853 * clrMask [I] mask color
1854 * uType [I] type of image to load
1855 * uFlags [I] loading flags
1858 * Success: handle to the loaded image list
1866 ImageList_LoadImageW (HINSTANCE hi, LPCWSTR lpbmp, INT cx, INT cGrow,
1867 COLORREF clrMask, UINT uType, UINT uFlags)
1869 HIMAGELIST himl = NULL;
1873 handle = LoadImageW (hi, lpbmp, uType, 0, 0, uFlags);
1875 WARN("Couldn't load image\n");
1879 if (uType == IMAGE_BITMAP) {
1881 GetObjectW (handle, sizeof(BITMAP), &bmp);
1883 /* To match windows behavior, if cx is set to zero and
1884 the flag DI_DEFAULTSIZE is specified, cx becomes the
1885 system metric value for icons. If the flag is not specified
1886 the function sets the size to the height of the bitmap */
1889 if (uFlags & DI_DEFAULTSIZE)
1890 cx = GetSystemMetrics (SM_CXICON);
1895 nImageCount = bmp.bmWidth / cx;
1897 himl = ImageList_Create (cx, bmp.bmHeight, ILC_MASK | ILC_COLOR,
1898 nImageCount, cGrow);
1900 DeleteObject (handle);
1903 ImageList_AddMasked (himl, handle, clrMask);
1905 else if ((uType == IMAGE_ICON) || (uType == IMAGE_CURSOR)) {
1909 GetIconInfo (handle, &ii);
1910 GetObjectW (ii.hbmColor, sizeof(BITMAP), &bmp);
1911 himl = ImageList_Create (bmp.bmWidth, bmp.bmHeight,
1912 ILC_MASK | ILC_COLOR, 1, cGrow);
1914 DeleteObject (ii.hbmColor);
1915 DeleteObject (ii.hbmMask);
1916 DeleteObject (handle);
1919 ImageList_Add (himl, ii.hbmColor, ii.hbmMask);
1920 DeleteObject (ii.hbmColor);
1921 DeleteObject (ii.hbmMask);
1924 DeleteObject (handle);
1930 /*************************************************************************
1931 * ImageList_Merge [COMCTL32.@]
1933 * Create an image list containing a merged image from two image lists.
1936 * himl1 [I] handle to first image list
1937 * i1 [I] first image index
1938 * himl2 [I] handle to second image list
1939 * i2 [I] second image index
1940 * dx [I] X offset of the second image relative to the first.
1941 * dy [I] Y offset of the second image relative to the first.
1944 * Success: The newly created image list. It contains a single image
1945 * consisting of the second image merged with the first.
1946 * Failure: NULL, if either himl1 or himl2 are invalid.
1949 * - The returned image list should be deleted by the caller using
1950 * ImageList_Destroy() when it is no longer required.
1951 * - If either i1 or i2 are not valid image indices they will be treated
1955 ImageList_Merge (HIMAGELIST himl1, INT i1, HIMAGELIST himl2, INT i2,
1958 HIMAGELIST himlDst = NULL;
1960 INT xOff1, yOff1, xOff2, yOff2;
1963 TRACE("(himl1=%p i1=%d himl2=%p i2=%d dx=%d dy=%d)\n", himl1, i1, himl2,
1966 if (!is_valid(himl1) || !is_valid(himl2))
1970 cxDst = max (himl1->cx, dx + himl2->cx);
1975 cxDst = max (himl2->cx, himl1->cx - dx);
1980 cxDst = max (himl1->cx, himl2->cx);
1986 cyDst = max (himl1->cy, dy + himl2->cy);
1991 cyDst = max (himl2->cy, himl1->cy - dy);
1996 cyDst = max (himl1->cy, himl2->cy);
2001 himlDst = ImageList_Create (cxDst, cyDst, ILC_MASK | ILC_COLOR, 1, 1);
2005 imagelist_point_from_index( himl1, i1, &pt1 );
2006 imagelist_point_from_index( himl1, i2, &pt2 );
2009 BitBlt (himlDst->hdcImage, 0, 0, cxDst, cyDst, himl1->hdcImage, 0, 0, BLACKNESS);
2010 if (i1 >= 0 && i1 < himl1->cCurImage)
2011 BitBlt (himlDst->hdcImage, xOff1, yOff1, himl1->cx, himl1->cy, himl1->hdcImage, pt1.x, pt1.y, SRCCOPY);
2012 if (i2 >= 0 && i2 < himl2->cCurImage)
2014 BitBlt (himlDst->hdcImage, xOff2, yOff2, himl2->cx, himl2->cy, himl2->hdcMask , pt2.x, pt2.y, SRCAND);
2015 BitBlt (himlDst->hdcImage, xOff2, yOff2, himl2->cx, himl2->cy, himl2->hdcImage, pt2.x, pt2.y, SRCPAINT);
2019 BitBlt (himlDst->hdcMask, 0, 0, cxDst, cyDst, himl1->hdcMask, 0, 0, WHITENESS);
2020 if (i1 >= 0 && i1 < himl1->cCurImage)
2021 BitBlt (himlDst->hdcMask, xOff1, yOff1, himl1->cx, himl1->cy, himl1->hdcMask, pt1.x, pt1.y, SRCCOPY);
2022 if (i2 >= 0 && i2 < himl2->cCurImage)
2023 BitBlt (himlDst->hdcMask, xOff2, yOff2, himl2->cx, himl2->cy, himl2->hdcMask, pt2.x, pt2.y, SRCAND);
2025 himlDst->cCurImage = 1;
2032 /***********************************************************************
2033 * DIB_GetDIBWidthBytes
2035 * Return the width of a DIB bitmap in bytes. DIB bitmap data is 32-bit aligned.
2037 static int DIB_GetDIBWidthBytes( int width, int depth )
2043 case 1: words = (width + 31) / 32; break;
2044 case 4: words = (width + 7) / 8; break;
2045 case 8: words = (width + 3) / 4; break;
2047 case 16: words = (width + 1) / 2; break;
2048 case 24: words = (width * 3 + 3)/4; break;
2051 WARN("(%d): Unsupported depth\n", depth );
2060 /***********************************************************************
2061 * DIB_GetDIBImageBytes
2063 * Return the number of bytes used to hold the image in a DIB bitmap.
2065 static int DIB_GetDIBImageBytes( int width, int height, int depth )
2067 return DIB_GetDIBWidthBytes( width, depth ) * abs( height );
2071 /* helper for ImageList_Read, see comments below */
2072 static BOOL _read_bitmap(HDC hdcIml, LPSTREAM pstm)
2074 BITMAPFILEHEADER bmfh;
2075 int bitsperpixel, palspace;
2076 char bmi_buf[sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD) * 256];
2077 LPBITMAPINFO bmi = (LPBITMAPINFO)bmi_buf;
2081 if (FAILED(IStream_Read ( pstm, &bmfh, sizeof(bmfh), NULL)))
2084 if (bmfh.bfType != (('M'<<8)|'B'))
2087 if (FAILED(IStream_Read ( pstm, &bmi->bmiHeader, sizeof(bmi->bmiHeader), NULL)))
2090 if ((bmi->bmiHeader.biSize != sizeof(bmi->bmiHeader)))
2093 TRACE("width %u, height %u, planes %u, bpp %u\n",
2094 bmi->bmiHeader.biWidth, bmi->bmiHeader.biHeight,
2095 bmi->bmiHeader.biPlanes, bmi->bmiHeader.biBitCount);
2097 bitsperpixel = bmi->bmiHeader.biPlanes * bmi->bmiHeader.biBitCount;
2098 if (bitsperpixel<=8)
2099 palspace = (1<<bitsperpixel)*sizeof(RGBQUAD);
2103 bmi->bmiHeader.biSizeImage = DIB_GetDIBImageBytes(bmi->bmiHeader.biWidth, bmi->bmiHeader.biHeight, bitsperpixel);
2105 /* read the palette right after the end of the bitmapinfoheader */
2106 if (palspace && FAILED(IStream_Read(pstm, bmi->bmiColors, palspace, NULL)))
2109 bits = Alloc(bmi->bmiHeader.biSizeImage);
2112 if (FAILED(IStream_Read(pstm, bits, bmi->bmiHeader.biSizeImage, NULL)))
2115 if (!StretchDIBits(hdcIml, 0, 0, bmi->bmiHeader.biWidth, bmi->bmiHeader.biHeight,
2116 0, 0, bmi->bmiHeader.biWidth, bmi->bmiHeader.biHeight,
2117 bits, bmi, DIB_RGB_COLORS, SRCCOPY))
2126 /*************************************************************************
2127 * ImageList_Read [COMCTL32.@]
2129 * Reads an image list from a stream.
2132 * pstm [I] pointer to a stream
2135 * Success: handle to image list
2138 * The format is like this:
2139 * ILHEAD ilheadstruct;
2141 * for the color image part:
2142 * BITMAPFILEHEADER bmfh;
2143 * BITMAPINFOHEADER bmih;
2144 * only if it has a palette:
2145 * RGBQUAD rgbs[nr_of_paletted_colors];
2147 * BYTE colorbits[imagesize];
2149 * the following only if the ILC_MASK bit is set in ILHEAD.ilFlags:
2150 * BITMAPFILEHEADER bmfh_mask;
2151 * BITMAPINFOHEADER bmih_mask;
2152 * only if it has a palette (it usually does not):
2153 * RGBQUAD rgbs[nr_of_paletted_colors];
2155 * BYTE maskbits[imagesize];
2157 HIMAGELIST WINAPI ImageList_Read (LPSTREAM pstm)
2163 TRACE("%p\n", pstm);
2165 if (FAILED(IStream_Read (pstm, &ilHead, sizeof(ILHEAD), NULL)))
2167 if (ilHead.usMagic != (('L' << 8) | 'I'))
2169 if (ilHead.usVersion != 0x101) /* probably version? */
2172 TRACE("cx %u, cy %u, flags 0x%04x, cCurImage %u, cMaxImage %u\n",
2173 ilHead.cx, ilHead.cy, ilHead.flags, ilHead.cCurImage, ilHead.cMaxImage);
2175 himl = ImageList_Create(ilHead.cx, ilHead.cy, ilHead.flags, ilHead.cCurImage, ilHead.cMaxImage);
2179 if (!_read_bitmap(himl->hdcImage, pstm))
2181 WARN("failed to read bitmap from stream\n");
2184 if (ilHead.flags & ILC_MASK)
2186 if (!_read_bitmap(himl->hdcMask, pstm))
2188 WARN("failed to read mask bitmap from stream\n");
2193 himl->cCurImage = ilHead.cCurImage;
2194 himl->cMaxImage = ilHead.cMaxImage;
2196 ImageList_SetBkColor(himl,ilHead.bkcolor);
2198 ImageList_SetOverlayImage(himl,ilHead.ovls[i],i+1);
2203 /*************************************************************************
2204 * ImageList_Remove [COMCTL32.@]
2206 * Removes an image from an image list
2209 * himl [I] image list handle
2216 * FIXME: as the image list storage test shows, native comctl32 simply shifts
2217 * images without creating a new bitmap.
2220 ImageList_Remove (HIMAGELIST himl, INT i)
2222 HBITMAP hbmNewImage, hbmNewMask;
2226 TRACE("(himl=%p i=%d)\n", himl, i);
2228 if (!is_valid(himl)) {
2229 ERR("Invalid image list handle!\n");
2233 if ((i < -1) || (i >= himl->cCurImage)) {
2234 TRACE("index out of range! %d\n", i);
2242 if (himl->cCurImage == 0) {
2243 /* remove all on empty ImageList is allowed */
2244 TRACE("remove all on empty ImageList!\n");
2248 himl->cMaxImage = himl->cInitial + himl->cGrow - 1;
2249 himl->cCurImage = 0;
2250 for (nCount = 0; nCount < MAX_OVERLAYIMAGE; nCount++)
2251 himl->nOvlIdx[nCount] = -1;
2253 hbmNewImage = ImageList_CreateImage(himl->hdcImage, himl, himl->cMaxImage);
2254 SelectObject (himl->hdcImage, hbmNewImage);
2255 DeleteObject (himl->hbmImage);
2256 himl->hbmImage = hbmNewImage;
2258 if (himl->hbmMask) {
2260 imagelist_get_bitmap_size(himl, himl->cMaxImage, &sz);
2261 hbmNewMask = CreateBitmap (sz.cx, sz.cy, 1, 1, NULL);
2262 SelectObject (himl->hdcMask, hbmNewMask);
2263 DeleteObject (himl->hbmMask);
2264 himl->hbmMask = hbmNewMask;
2268 /* delete one image */
2269 TRACE("Remove single image! %d\n", i);
2271 /* create new bitmap(s) */
2272 TRACE(" - Number of images: %d / %d (Old/New)\n",
2273 himl->cCurImage, himl->cCurImage - 1);
2275 hbmNewImage = ImageList_CreateImage(himl->hdcImage, himl, himl->cMaxImage);
2277 imagelist_get_bitmap_size(himl, himl->cMaxImage, &sz );
2279 hbmNewMask = CreateBitmap (sz.cx, sz.cy, 1, 1, NULL);
2281 hbmNewMask = 0; /* Just to keep compiler happy! */
2283 hdcBmp = CreateCompatibleDC (0);
2285 /* copy all images and masks prior to the "removed" image */
2287 TRACE("Pre image copy: Copy %d images\n", i);
2289 SelectObject (hdcBmp, hbmNewImage);
2290 imagelist_copy_images( himl, himl->hdcImage, hdcBmp, 0, i, 0 );
2292 if (himl->hbmMask) {
2293 SelectObject (hdcBmp, hbmNewMask);
2294 imagelist_copy_images( himl, himl->hdcMask, hdcBmp, 0, i, 0 );
2298 /* copy all images and masks behind the removed image */
2299 if (i < himl->cCurImage - 1) {
2300 TRACE("Post image copy!\n");
2302 SelectObject (hdcBmp, hbmNewImage);
2303 imagelist_copy_images( himl, himl->hdcImage, hdcBmp, i + 1,
2304 (himl->cCurImage - i), i );
2306 if (himl->hbmMask) {
2307 SelectObject (hdcBmp, hbmNewMask);
2308 imagelist_copy_images( himl, himl->hdcMask, hdcBmp, i + 1,
2309 (himl->cCurImage - i), i );
2315 /* delete old images and insert new ones */
2316 SelectObject (himl->hdcImage, hbmNewImage);
2317 DeleteObject (himl->hbmImage);
2318 himl->hbmImage = hbmNewImage;
2319 if (himl->hbmMask) {
2320 SelectObject (himl->hdcMask, hbmNewMask);
2321 DeleteObject (himl->hbmMask);
2322 himl->hbmMask = hbmNewMask;
2332 /*************************************************************************
2333 * ImageList_Replace [COMCTL32.@]
2335 * Replaces an image in an image list with a new image.
2338 * himl [I] handle to image list
2340 * hbmImage [I] handle to image bitmap
2341 * hbmMask [I] handle to mask bitmap. Can be NULL.
2349 ImageList_Replace (HIMAGELIST himl, INT i, HBITMAP hbmImage,
2356 TRACE("%p %d %p %p\n", himl, i, hbmImage, hbmMask);
2358 if (!is_valid(himl)) {
2359 ERR("Invalid image list handle!\n");
2363 if ((i >= himl->cMaxImage) || (i < 0)) {
2364 ERR("Invalid image index!\n");
2368 if (!GetObjectW(hbmImage, sizeof(BITMAP), &bmp))
2371 hdcImage = CreateCompatibleDC (0);
2374 SelectObject (hdcImage, hbmImage);
2376 if (add_with_alpha( himl, hdcImage, i, 1, bmp.bmWidth, bmp.bmHeight, hbmImage, hbmMask ))
2379 imagelist_point_from_index(himl, i, &pt);
2380 StretchBlt (himl->hdcImage, pt.x, pt.y, himl->cx, himl->cy,
2381 hdcImage, 0, 0, bmp.bmWidth, bmp.bmHeight, SRCCOPY);
2386 HBITMAP hOldBitmapTemp;
2388 hdcTemp = CreateCompatibleDC(0);
2389 hOldBitmapTemp = SelectObject(hdcTemp, hbmMask);
2391 StretchBlt (himl->hdcMask, pt.x, pt.y, himl->cx, himl->cy,
2392 hdcTemp, 0, 0, bmp.bmWidth, bmp.bmHeight, SRCCOPY);
2393 SelectObject(hdcTemp, hOldBitmapTemp);
2396 /* Remove the background from the image
2398 BitBlt (himl->hdcImage, pt.x, pt.y, bmp.bmWidth, bmp.bmHeight,
2399 himl->hdcMask, pt.x, pt.y, 0x220326); /* NOTSRCAND */
2403 DeleteDC (hdcImage);
2409 /*************************************************************************
2410 * ImageList_ReplaceIcon [COMCTL32.@]
2412 * Replaces an image in an image list using an icon.
2415 * himl [I] handle to image list
2417 * hIcon [I] handle to icon
2420 * Success: index of the replaced image
2425 ImageList_ReplaceIcon (HIMAGELIST himl, INT nIndex, HICON hIcon)
2434 TRACE("(%p %d %p)\n", himl, nIndex, hIcon);
2436 if (!is_valid(himl)) {
2437 ERR("invalid image list\n");
2440 if ((nIndex >= himl->cMaxImage) || (nIndex < -1)) {
2441 ERR("invalid image index %d / %d\n", nIndex, himl->cMaxImage);
2445 hBestFitIcon = CopyImage(
2448 LR_COPYFROMRESOURCE);
2449 /* the above will fail if the icon wasn't loaded from a resource, so try
2450 * again without LR_COPYFROMRESOURCE flag */
2452 hBestFitIcon = CopyImage(
2459 ret = GetIconInfo (hBestFitIcon, &ii);
2461 DestroyIcon(hBestFitIcon);
2465 ret = GetObjectW (ii.hbmMask, sizeof(BITMAP), &bmp);
2467 ERR("couldn't get mask bitmap info\n");
2469 DeleteObject (ii.hbmColor);
2471 DeleteObject (ii.hbmMask);
2472 DestroyIcon(hBestFitIcon);
2477 if (himl->cCurImage + 1 > himl->cMaxImage)
2478 IMAGELIST_InternalExpandBitmaps(himl, 1);
2480 nIndex = himl->cCurImage;
2484 hdcImage = CreateCompatibleDC (0);
2485 TRACE("hdcImage=%p\n", hdcImage);
2487 ERR("invalid hdcImage!\n");
2489 if (himl->uBitsPixel == 32)
2493 UINT height = bmp.bmHeight / 2;
2494 HDC hdcMask = CreateCompatibleDC( 0 );
2495 HBITMAP color = CreateBitmap( bmp.bmWidth, height, 1, 1, NULL );
2496 SelectObject( hdcImage, color );
2497 SelectObject( hdcMask, ii.hbmMask );
2498 BitBlt( hdcImage, 0, 0, bmp.bmWidth, height, hdcMask, 0, height, SRCCOPY );
2499 add_with_alpha( himl, hdcImage, nIndex, 1, bmp.bmWidth, height, color, ii.hbmMask );
2500 DeleteDC( hdcMask );
2501 DeleteObject( color );
2503 else add_with_alpha( himl, hdcImage, nIndex, 1, bmp.bmWidth, bmp.bmHeight, ii.hbmColor, ii.hbmMask );
2508 imagelist_point_from_index(himl, nIndex, &pt);
2510 SetTextColor(himl->hdcImage, RGB(0,0,0));
2511 SetBkColor (himl->hdcImage, RGB(255,255,255));
2515 SelectObject (hdcImage, ii.hbmColor);
2516 StretchBlt (himl->hdcImage, pt.x, pt.y, himl->cx, himl->cy,
2517 hdcImage, 0, 0, bmp.bmWidth, bmp.bmHeight, SRCCOPY);
2520 SelectObject (hdcImage, ii.hbmMask);
2521 StretchBlt (himl->hdcMask, pt.x, pt.y, himl->cx, himl->cy,
2522 hdcImage, 0, 0, bmp.bmWidth, bmp.bmHeight, SRCCOPY);
2527 UINT height = bmp.bmHeight / 2;
2528 SelectObject (hdcImage, ii.hbmMask);
2529 StretchBlt (himl->hdcImage, pt.x, pt.y, himl->cx, himl->cy,
2530 hdcImage, 0, height, bmp.bmWidth, height, SRCCOPY);
2532 StretchBlt (himl->hdcMask, pt.x, pt.y, himl->cx, himl->cy,
2533 hdcImage, 0, 0, bmp.bmWidth, height, SRCCOPY);
2537 DestroyIcon(hBestFitIcon);
2539 DeleteDC (hdcImage);
2541 DeleteObject (ii.hbmColor);
2543 DeleteObject (ii.hbmMask);
2545 TRACE("Insert index = %d, himl->cCurImage = %d\n", nIndex, himl->cCurImage);
2550 /*************************************************************************
2551 * ImageList_SetBkColor [COMCTL32.@]
2553 * Sets the background color of an image list.
2556 * himl [I] handle to image list
2557 * clrBk [I] background color
2560 * Success: previous background color
2565 ImageList_SetBkColor (HIMAGELIST himl, COLORREF clrBk)
2569 if (!is_valid(himl))
2572 clrOldBk = himl->clrBk;
2573 himl->clrBk = clrBk;
2578 /*************************************************************************
2579 * ImageList_SetDragCursorImage [COMCTL32.@]
2581 * Combines the specified image with the current drag image
2584 * himlDrag [I] handle to drag image list
2585 * iDrag [I] drag image index
2586 * dxHotspot [I] X position of the hot spot
2587 * dyHotspot [I] Y position of the hot spot
2594 * - The names dxHotspot, dyHotspot are misleading because they have nothing
2595 * to do with a hotspot but are only the offset of the origin of the new
2596 * image relative to the origin of the old image.
2598 * - When this function is called and the drag image is visible, a
2599 * short flickering occurs but this matches the Win9x behavior. It is
2600 * possible to fix the flickering using code like in ImageList_DragMove.
2604 ImageList_SetDragCursorImage (HIMAGELIST himlDrag, INT iDrag,
2605 INT dxHotspot, INT dyHotspot)
2607 HIMAGELIST himlTemp;
2610 if (!is_valid(InternalDrag.himl) || !is_valid(himlDrag))
2613 TRACE(" dxH=%d dyH=%d nX=%d nY=%d\n",
2614 dxHotspot, dyHotspot, InternalDrag.dxHotspot, InternalDrag.dyHotspot);
2616 visible = InternalDrag.bShow;
2618 himlTemp = ImageList_Merge (InternalDrag.himl, 0, himlDrag, iDrag,
2619 dxHotspot, dyHotspot);
2622 /* hide the drag image */
2623 ImageList_DragShowNolock(FALSE);
2625 if ((InternalDrag.himl->cx != himlTemp->cx) ||
2626 (InternalDrag.himl->cy != himlTemp->cy)) {
2627 /* the size of the drag image changed, invalidate the buffer */
2628 DeleteObject(InternalDrag.hbmBg);
2629 InternalDrag.hbmBg = 0;
2632 ImageList_Destroy (InternalDrag.himl);
2633 InternalDrag.himl = himlTemp;
2636 /* show the drag image */
2637 ImageList_DragShowNolock(TRUE);
2644 /*************************************************************************
2645 * ImageList_SetFilter [COMCTL32.@]
2647 * Sets a filter (or does something completely different)!!???
2648 * It removes 12 Bytes from the stack (3 Parameters).
2651 * himl [I] SHOULD be a handle to image list
2652 * i [I] COULD be an index?
2657 * Failure: FALSE ???
2660 * This is an UNDOCUMENTED function!!!!
2665 ImageList_SetFilter (HIMAGELIST himl, INT i, DWORD dwFilter)
2667 FIXME("(%p 0x%x 0x%x):empty stub!\n", himl, i, dwFilter);
2673 /*************************************************************************
2674 * ImageList_SetFlags [COMCTL32.@]
2676 * Sets the image list flags.
2679 * himl [I] Handle to image list
2680 * flags [I] Flags to set
2690 ImageList_SetFlags(HIMAGELIST himl, DWORD flags)
2692 FIXME("(%p %08x):empty stub\n", himl, flags);
2697 /*************************************************************************
2698 * ImageList_SetIconSize [COMCTL32.@]
2700 * Sets the image size of the bitmap and deletes all images.
2703 * himl [I] handle to image list
2704 * cx [I] image width
2705 * cy [I] image height
2713 ImageList_SetIconSize (HIMAGELIST himl, INT cx, INT cy)
2718 if (!is_valid(himl))
2721 /* remove all images */
2722 himl->cMaxImage = himl->cInitial + 1;
2723 himl->cCurImage = 0;
2727 /* initialize overlay mask indices */
2728 for (nCount = 0; nCount < MAX_OVERLAYIMAGE; nCount++)
2729 himl->nOvlIdx[nCount] = -1;
2731 hbmNew = ImageList_CreateImage(himl->hdcImage, himl, himl->cMaxImage);
2732 SelectObject (himl->hdcImage, hbmNew);
2733 DeleteObject (himl->hbmImage);
2734 himl->hbmImage = hbmNew;
2736 if (himl->hbmMask) {
2738 imagelist_get_bitmap_size(himl, himl->cMaxImage, &sz);
2739 hbmNew = CreateBitmap (sz.cx, sz.cy, 1, 1, NULL);
2740 SelectObject (himl->hdcMask, hbmNew);
2741 DeleteObject (himl->hbmMask);
2742 himl->hbmMask = hbmNew;
2749 /*************************************************************************
2750 * ImageList_SetImageCount [COMCTL32.@]
2752 * Resizes an image list to the specified number of images.
2755 * himl [I] handle to image list
2756 * iImageCount [I] number of images in the image list
2764 ImageList_SetImageCount (HIMAGELIST himl, UINT iImageCount)
2767 HBITMAP hbmNewBitmap, hbmOld;
2768 INT nNewCount, nCopyCount;
2770 TRACE("%p %d\n",himl,iImageCount);
2772 if (!is_valid(himl))
2774 if (himl->cMaxImage > iImageCount)
2776 himl->cCurImage = iImageCount;
2777 /* TODO: shrink the bitmap when cMaxImage-cCurImage>cGrow ? */
2781 nNewCount = iImageCount + himl->cGrow;
2782 nCopyCount = min(himl->cCurImage, iImageCount);
2784 hdcBitmap = CreateCompatibleDC (0);
2786 hbmNewBitmap = ImageList_CreateImage(hdcBitmap, himl, nNewCount);
2788 if (hbmNewBitmap != 0)
2790 hbmOld = SelectObject (hdcBitmap, hbmNewBitmap);
2791 imagelist_copy_images( himl, himl->hdcImage, hdcBitmap, 0, nCopyCount, 0 );
2792 SelectObject (hdcBitmap, hbmOld);
2794 /* FIXME: delete 'empty' image space? */
2796 SelectObject (himl->hdcImage, hbmNewBitmap);
2797 DeleteObject (himl->hbmImage);
2798 himl->hbmImage = hbmNewBitmap;
2801 ERR("Could not create new image bitmap !\n");
2806 imagelist_get_bitmap_size( himl, nNewCount, &sz );
2807 hbmNewBitmap = CreateBitmap (sz.cx, sz.cy, 1, 1, NULL);
2808 if (hbmNewBitmap != 0)
2810 hbmOld = SelectObject (hdcBitmap, hbmNewBitmap);
2811 imagelist_copy_images( himl, himl->hdcMask, hdcBitmap, 0, nCopyCount, 0 );
2812 SelectObject (hdcBitmap, hbmOld);
2814 /* FIXME: delete 'empty' image space? */
2816 SelectObject (himl->hdcMask, hbmNewBitmap);
2817 DeleteObject (himl->hbmMask);
2818 himl->hbmMask = hbmNewBitmap;
2821 ERR("Could not create new mask bitmap!\n");
2824 DeleteDC (hdcBitmap);
2826 /* Update max image count and current image count */
2827 himl->cMaxImage = nNewCount;
2828 himl->cCurImage = iImageCount;
2834 /*************************************************************************
2835 * ImageList_SetOverlayImage [COMCTL32.@]
2837 * Assigns an overlay mask index to an existing image in an image list.
2840 * himl [I] handle to image list
2841 * iImage [I] image index
2842 * iOverlay [I] overlay mask index
2850 ImageList_SetOverlayImage (HIMAGELIST himl, INT iImage, INT iOverlay)
2852 if (!is_valid(himl))
2854 if ((iOverlay < 1) || (iOverlay > MAX_OVERLAYIMAGE))
2856 if ((iImage!=-1) && ((iImage < 0) || (iImage > himl->cCurImage)))
2858 himl->nOvlIdx[iOverlay - 1] = iImage;
2864 /* helper for ImageList_Write - write bitmap to pstm
2865 * currently everything is written as 24 bit RGB, except masks
2868 _write_bitmap(HBITMAP hBitmap, LPSTREAM pstm)
2870 LPBITMAPFILEHEADER bmfh;
2871 LPBITMAPINFOHEADER bmih;
2872 LPBYTE data = NULL, lpBits;
2874 INT bitCount, sizeImage, offBits, totalSize;
2876 BOOL result = FALSE;
2878 if (!GetObjectW(hBitmap, sizeof(BITMAP), &bm))
2881 bitCount = bm.bmBitsPixel == 1 ? 1 : 24;
2882 sizeImage = DIB_GetDIBImageBytes(bm.bmWidth, bm.bmHeight, bitCount);
2884 totalSize = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);
2886 totalSize += (1 << bitCount) * sizeof(RGBQUAD);
2887 offBits = totalSize;
2888 totalSize += sizeImage;
2890 data = Alloc(totalSize);
2891 bmfh = (LPBITMAPFILEHEADER)data;
2892 bmih = (LPBITMAPINFOHEADER)(data + sizeof(BITMAPFILEHEADER));
2893 lpBits = data + offBits;
2895 /* setup BITMAPFILEHEADER */
2896 bmfh->bfType = (('M' << 8) | 'B');
2897 bmfh->bfSize = offBits;
2898 bmfh->bfReserved1 = 0;
2899 bmfh->bfReserved2 = 0;
2900 bmfh->bfOffBits = offBits;
2902 /* setup BITMAPINFOHEADER */
2903 bmih->biSize = sizeof(BITMAPINFOHEADER);
2904 bmih->biWidth = bm.bmWidth;
2905 bmih->biHeight = bm.bmHeight;
2907 bmih->biBitCount = bitCount;
2908 bmih->biCompression = BI_RGB;
2909 bmih->biSizeImage = sizeImage;
2910 bmih->biXPelsPerMeter = 0;
2911 bmih->biYPelsPerMeter = 0;
2912 bmih->biClrUsed = 0;
2913 bmih->biClrImportant = 0;
2916 result = GetDIBits(xdc, hBitmap, 0, bm.bmHeight, lpBits, (BITMAPINFO *)bmih, DIB_RGB_COLORS) == bm.bmHeight;
2921 TRACE("width %u, height %u, planes %u, bpp %u\n",
2922 bmih->biWidth, bmih->biHeight,
2923 bmih->biPlanes, bmih->biBitCount);
2927 LPBITMAPINFO inf = (LPBITMAPINFO)bmih;
2928 inf->bmiColors[0].rgbRed = inf->bmiColors[0].rgbGreen = inf->bmiColors[0].rgbBlue = 0;
2929 inf->bmiColors[1].rgbRed = inf->bmiColors[1].rgbGreen = inf->bmiColors[1].rgbBlue = 0xff;
2932 if(FAILED(IStream_Write(pstm, data, totalSize, NULL)))
2944 /*************************************************************************
2945 * ImageList_Write [COMCTL32.@]
2947 * Writes an image list to a stream.
2950 * himl [I] handle to image list
2951 * pstm [O] Pointer to a stream.
2962 ImageList_Write (HIMAGELIST himl, LPSTREAM pstm)
2967 TRACE("%p %p\n", himl, pstm);
2969 if (!is_valid(himl))
2972 ilHead.usMagic = (('L' << 8) | 'I');
2973 ilHead.usVersion = 0x101;
2974 ilHead.cCurImage = himl->cCurImage;
2975 ilHead.cMaxImage = himl->cMaxImage;
2976 ilHead.cGrow = himl->cGrow;
2977 ilHead.cx = himl->cx;
2978 ilHead.cy = himl->cy;
2979 ilHead.bkcolor = himl->clrBk;
2980 ilHead.flags = himl->flags;
2981 for(i = 0; i < 4; i++) {
2982 ilHead.ovls[i] = himl->nOvlIdx[i];
2985 TRACE("cx %u, cy %u, flags 0x04%x, cCurImage %u, cMaxImage %u\n",
2986 ilHead.cx, ilHead.cy, ilHead.flags, ilHead.cCurImage, ilHead.cMaxImage);
2988 if(FAILED(IStream_Write(pstm, &ilHead, sizeof(ILHEAD), NULL)))
2991 /* write the bitmap */
2992 if(!_write_bitmap(himl->hbmImage, pstm))
2995 /* write the mask if we have one */
2996 if(himl->flags & ILC_MASK) {
2997 if(!_write_bitmap(himl->hbmMask, pstm))
3005 static HBITMAP ImageList_CreateImage(HDC hdc, HIMAGELIST himl, UINT count)
3007 HBITMAP hbmNewBitmap;
3008 UINT ilc = (himl->flags & 0xFE);
3011 imagelist_get_bitmap_size( himl, count, &sz );
3013 if ((ilc >= ILC_COLOR4 && ilc <= ILC_COLOR32) || ilc == ILC_COLOR)
3018 TRACE("Creating DIBSection %d x %d, %d Bits per Pixel\n",
3019 sz.cx, sz.cy, himl->uBitsPixel);
3021 if (himl->uBitsPixel <= ILC_COLOR8)
3027 colors = 1 << himl->uBitsPixel;
3028 bmi = Alloc(sizeof(BITMAPINFOHEADER) +
3029 sizeof(PALETTEENTRY) * colors);
3031 pal = (LPPALETTEENTRY)bmi->bmiColors;
3032 GetPaletteEntries(GetStockObject(DEFAULT_PALETTE), 0, colors, pal);
3034 /* Swap colors returned by GetPaletteEntries so we can use them for
3035 * CreateDIBSection call. */
3036 for (i = 0; i < colors; i++)
3038 temp = pal[i].peBlue;
3039 bmi->bmiColors[i].rgbRed = pal[i].peRed;
3040 bmi->bmiColors[i].rgbBlue = temp;
3045 bmi = Alloc(sizeof(BITMAPINFOHEADER));
3048 bmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
3049 bmi->bmiHeader.biWidth = sz.cx;
3050 bmi->bmiHeader.biHeight = sz.cy;
3051 bmi->bmiHeader.biPlanes = 1;
3052 bmi->bmiHeader.biBitCount = himl->uBitsPixel;
3053 bmi->bmiHeader.biCompression = BI_RGB;
3054 bmi->bmiHeader.biSizeImage = 0;
3055 bmi->bmiHeader.biXPelsPerMeter = 0;
3056 bmi->bmiHeader.biYPelsPerMeter = 0;
3057 bmi->bmiHeader.biClrUsed = 0;
3058 bmi->bmiHeader.biClrImportant = 0;
3060 hbmNewBitmap = CreateDIBSection(hdc, bmi, DIB_RGB_COLORS, &bits, 0, 0);
3064 else /*if (ilc == ILC_COLORDDB)*/
3066 TRACE("Creating Bitmap: %d Bits per Pixel\n", himl->uBitsPixel);
3068 hbmNewBitmap = CreateBitmap (sz.cx, sz.cy, 1, himl->uBitsPixel, NULL);
3070 TRACE("returning %p\n", hbmNewBitmap);
3071 return hbmNewBitmap;
3074 /*************************************************************************
3075 * ImageList_SetColorTable [COMCTL32.@]
3077 * Sets the color table of an image list.
3080 * himl [I] Handle to the image list.
3081 * uStartIndex [I] The first index to set.
3082 * cEntries [I] Number of entries to set.
3083 * prgb [I] New color information for color table for the image list.
3086 * Success: Number of entries in the table that were set.
3090 * ImageList_Create(), SetDIBColorTable()
3094 ImageList_SetColorTable (HIMAGELIST himl, UINT uStartIndex, UINT cEntries, CONST RGBQUAD * prgb)
3096 return SetDIBColorTable(himl->hdcImage, uStartIndex, cEntries, prgb);
3099 /*************************************************************************
3100 * ImageList_CoCreateInstance [COMCTL32.@]
3102 * Creates a new imagelist instance and returns an interface pointer to it.
3105 * rclsid [I] A reference to the CLSID (CLSID_ImageList).
3106 * punkOuter [I] Pointer to IUnknown interface for aggregation, if desired
3107 * riid [I] Identifier of the requested interface.
3108 * ppv [O] Returns the address of the pointer requested, or NULL.
3112 * Failure: Error value.
3115 ImageList_CoCreateInstance (REFCLSID rclsid, const IUnknown *punkOuter, REFIID riid, void **ppv)
3117 TRACE("(%s,%p,%s,%p)\n", debugstr_guid(rclsid), punkOuter, debugstr_guid(riid), ppv);
3119 if (!IsEqualCLSID(&CLSID_ImageList, rclsid))
3120 return E_NOINTERFACE;
3122 return ImageListImpl_CreateInstance(punkOuter, riid, ppv);
3126 /*************************************************************************
3127 * IImageList implementation
3130 static HRESULT WINAPI ImageListImpl_QueryInterface(IImageList *iface,
3131 REFIID iid, void **ppv)
3133 HIMAGELIST This = (HIMAGELIST) iface;
3134 TRACE("(%p,%s,%p)\n", iface, debugstr_guid(iid), ppv);
3136 if (!ppv) return E_INVALIDARG;
3138 if (IsEqualIID(&IID_IUnknown, iid) || IsEqualIID(&IID_IImageList, iid))
3143 return E_NOINTERFACE;
3146 IUnknown_AddRef((IUnknown*)*ppv);
3150 static ULONG WINAPI ImageListImpl_AddRef(IImageList *iface)
3152 HIMAGELIST This = (HIMAGELIST) iface;
3153 ULONG ref = InterlockedIncrement(&This->ref);
3155 TRACE("(%p) refcount=%u\n", iface, ref);
3159 static ULONG WINAPI ImageListImpl_Release(IImageList *iface)
3161 HIMAGELIST This = (HIMAGELIST) iface;
3162 ULONG ref = InterlockedDecrement(&This->ref);
3164 TRACE("(%p) refcount=%u\n", iface, ref);
3168 /* delete image bitmaps */
3169 if (This->hbmImage) DeleteObject (This->hbmImage);
3170 if (This->hbmMask) DeleteObject (This->hbmMask);
3172 /* delete image & mask DCs */
3173 if (This->hdcImage) DeleteDC (This->hdcImage);
3174 if (This->hdcMask) DeleteDC (This->hdcMask);
3176 /* delete blending brushes */
3177 if (This->hbrBlend25) DeleteObject (This->hbrBlend25);
3178 if (This->hbrBlend50) DeleteObject (This->hbrBlend50);
3180 This->lpVtbl = NULL;
3181 HeapFree(GetProcessHeap(), 0, This->has_alpha);
3182 HeapFree(GetProcessHeap(), 0, This);
3188 static HRESULT WINAPI ImageListImpl_Add(IImageList *iface, HBITMAP hbmImage,
3189 HBITMAP hbmMask, int *pi)
3191 HIMAGELIST This = (HIMAGELIST) iface;
3197 ret = ImageList_Add(This, hbmImage, hbmMask);
3206 static HRESULT WINAPI ImageListImpl_ReplaceIcon(IImageList *iface, int i,
3207 HICON hicon, int *pi)
3209 HIMAGELIST This = (HIMAGELIST) iface;
3215 ret = ImageList_ReplaceIcon(This, i, hicon);
3224 static HRESULT WINAPI ImageListImpl_SetOverlayImage(IImageList *iface,
3225 int iImage, int iOverlay)
3227 return ImageList_SetOverlayImage((HIMAGELIST) iface, iImage, iOverlay)
3231 static HRESULT WINAPI ImageListImpl_Replace(IImageList *iface, int i,
3232 HBITMAP hbmImage, HBITMAP hbmMask)
3234 return ImageList_Replace((HIMAGELIST) iface, i, hbmImage, hbmMask) ? S_OK :
3238 static HRESULT WINAPI ImageListImpl_AddMasked(IImageList *iface, HBITMAP hbmImage,
3239 COLORREF crMask, int *pi)
3241 HIMAGELIST This = (HIMAGELIST) iface;
3247 ret = ImageList_AddMasked(This, hbmImage, crMask);
3256 static HRESULT WINAPI ImageListImpl_Draw(IImageList *iface,
3257 IMAGELISTDRAWPARAMS *pimldp)
3259 HIMAGELIST This = (HIMAGELIST) iface;
3260 HIMAGELIST old_himl = 0;
3266 /* As far as I can tell, Windows simply ignores the contents of pimldp->himl
3267 so we shall simulate the same */
3268 old_himl = pimldp->himl;
3269 pimldp->himl = This;
3271 ret = ImageList_DrawIndirect(pimldp);
3273 pimldp->himl = old_himl;
3274 return ret ? S_OK : E_FAIL;
3277 static HRESULT WINAPI ImageListImpl_Remove(IImageList *iface, int i)
3279 return (ImageList_Remove((HIMAGELIST) iface, i) == 0) ? E_FAIL : S_OK;
3282 static HRESULT WINAPI ImageListImpl_GetIcon(IImageList *iface, int i, UINT flags,
3290 hIcon = ImageList_GetIcon((HIMAGELIST) iface, i, flags);
3299 static HRESULT WINAPI ImageListImpl_GetImageInfo(IImageList *iface, int i,
3300 IMAGEINFO *pImageInfo)
3302 return ImageList_GetImageInfo((HIMAGELIST) iface, i, pImageInfo) ? S_OK : E_FAIL;
3305 static HRESULT WINAPI ImageListImpl_Copy(IImageList *iface, int iDst,
3306 IUnknown *punkSrc, int iSrc, UINT uFlags)
3308 HIMAGELIST This = (HIMAGELIST) iface;
3309 IImageList *src = NULL;
3315 /* TODO: Add test for IID_ImageList2 too */
3316 if (FAILED(IImageList_QueryInterface(punkSrc, &IID_IImageList,
3320 if (ImageList_Copy(This, iDst, (HIMAGELIST) src, iSrc, uFlags))
3325 IImageList_Release(src);
3329 static HRESULT WINAPI ImageListImpl_Merge(IImageList *iface, int i1,
3330 IUnknown *punk2, int i2, int dx, int dy, REFIID riid, PVOID *ppv)
3332 HIMAGELIST This = (HIMAGELIST) iface;
3333 IImageList *iml2 = NULL;
3335 HRESULT ret = E_FAIL;
3340 /* TODO: Add test for IID_ImageList2 too */
3341 if (FAILED(IImageList_QueryInterface(punk2, &IID_IImageList,
3345 hNew = ImageList_Merge(This, i1, (HIMAGELIST) iml2, i2, dx, dy);
3347 /* Get the interface for the new image list */
3349 ret = HIMAGELIST_QueryInterface(hNew, riid, ppv);
3351 IImageList_Release(iml2);
3355 static HRESULT WINAPI ImageListImpl_Clone(IImageList *iface, REFIID riid,
3358 HIMAGELIST This = (HIMAGELIST) iface;
3360 HRESULT ret = E_FAIL;
3365 hNew = ImageList_Duplicate(This);
3367 /* Get the interface for the new image list */
3369 ret = HIMAGELIST_QueryInterface(hNew, riid, ppv);
3374 static HRESULT WINAPI ImageListImpl_GetImageRect(IImageList *iface, int i,
3377 HIMAGELIST This = (HIMAGELIST) iface;
3383 if (!ImageList_GetImageInfo(This, i, &info))
3386 return CopyRect(prc, &info.rcImage) ? S_OK : E_FAIL;
3389 static HRESULT WINAPI ImageListImpl_GetIconSize(IImageList *iface, int *cx,
3392 HIMAGELIST This = (HIMAGELIST) iface;
3394 return ImageList_GetIconSize(This, cx, cy) ? S_OK : E_FAIL;
3397 static HRESULT WINAPI ImageListImpl_SetIconSize(IImageList *iface, int cx,
3400 return ImageList_SetIconSize((HIMAGELIST) iface, cx, cy) ? S_OK : E_FAIL;
3403 static HRESULT WINAPI ImageListImpl_GetImageCount(IImageList *iface, int *pi)
3408 *pi = ImageList_GetImageCount((HIMAGELIST) iface);
3412 static HRESULT WINAPI ImageListImpl_SetImageCount(IImageList *iface,
3415 return ImageList_SetImageCount((HIMAGELIST) iface, uNewCount) ? S_OK : E_FAIL;
3418 static HRESULT WINAPI ImageListImpl_SetBkColor(IImageList *iface, COLORREF clrBk,
3424 *pclr = ImageList_SetBkColor((HIMAGELIST) iface, clrBk);
3425 return *pclr == CLR_NONE ? E_FAIL : S_OK;
3428 static HRESULT WINAPI ImageListImpl_GetBkColor(IImageList *iface, COLORREF *pclr)
3433 *pclr = ImageList_GetBkColor((HIMAGELIST) iface);
3437 static HRESULT WINAPI ImageListImpl_BeginDrag(IImageList *iface, int iTrack,
3438 int dxHotspot, int dyHotspot)
3440 return ImageList_BeginDrag((HIMAGELIST) iface, iTrack, dxHotspot, dyHotspot) ? S_OK : E_FAIL;
3443 static HRESULT WINAPI ImageListImpl_EndDrag(IImageList *iface)
3445 ImageList_EndDrag();
3449 static HRESULT WINAPI ImageListImpl_DragEnter(IImageList *iface, HWND hwndLock,
3452 return ImageList_DragEnter(hwndLock, x, y) ? S_OK : E_FAIL;
3455 static HRESULT WINAPI ImageListImpl_DragLeave(IImageList *iface, HWND hwndLock)
3457 return ImageList_DragLeave(hwndLock) ? S_OK : E_FAIL;
3460 static HRESULT WINAPI ImageListImpl_DragMove(IImageList *iface, int x, int y)
3462 return ImageList_DragMove(x, y) ? S_OK : E_FAIL;
3465 static HRESULT WINAPI ImageListImpl_SetDragCursorImage(IImageList *iface,
3466 IUnknown *punk, int iDrag, int dxHotspot, int dyHotspot)
3468 IImageList *iml2 = NULL;
3474 /* TODO: Add test for IID_ImageList2 too */
3475 if (FAILED(IImageList_QueryInterface(punk, &IID_IImageList,
3479 ret = ImageList_SetDragCursorImage((HIMAGELIST) iml2, iDrag, dxHotspot,
3482 IImageList_Release(iml2);
3484 return ret ? S_OK : E_FAIL;
3487 static HRESULT WINAPI ImageListImpl_DragShowNolock(IImageList *iface, BOOL fShow)
3489 return ImageList_DragShowNolock(fShow) ? S_OK : E_FAIL;
3492 static HRESULT WINAPI ImageListImpl_GetDragImage(IImageList *iface, POINT *ppt,
3493 POINT *pptHotspot, REFIID riid, PVOID *ppv)
3495 HRESULT ret = E_FAIL;
3501 hNew = ImageList_GetDragImage(ppt, pptHotspot);
3503 /* Get the interface for the new image list */
3505 ret = HIMAGELIST_QueryInterface(hNew, riid, ppv);
3510 static HRESULT WINAPI ImageListImpl_GetItemFlags(IImageList *iface, int i,
3513 FIXME("STUB: %p %d %p\n", iface, i, dwFlags);
3517 static HRESULT WINAPI ImageListImpl_GetOverlayImage(IImageList *iface, int iOverlay,
3520 HIMAGELIST This = (HIMAGELIST) iface;
3523 if ((iOverlay < 0) || (iOverlay > This->cCurImage))
3526 for (i = 0; i < MAX_OVERLAYIMAGE; i++)
3528 if (This->nOvlIdx[i] == iOverlay)
3539 static const IImageListVtbl ImageListImpl_Vtbl = {
3540 ImageListImpl_QueryInterface,
3541 ImageListImpl_AddRef,
3542 ImageListImpl_Release,
3544 ImageListImpl_ReplaceIcon,
3545 ImageListImpl_SetOverlayImage,
3546 ImageListImpl_Replace,
3547 ImageListImpl_AddMasked,
3549 ImageListImpl_Remove,
3550 ImageListImpl_GetIcon,
3551 ImageListImpl_GetImageInfo,
3553 ImageListImpl_Merge,
3554 ImageListImpl_Clone,
3555 ImageListImpl_GetImageRect,
3556 ImageListImpl_GetIconSize,
3557 ImageListImpl_SetIconSize,
3558 ImageListImpl_GetImageCount,
3559 ImageListImpl_SetImageCount,
3560 ImageListImpl_SetBkColor,
3561 ImageListImpl_GetBkColor,
3562 ImageListImpl_BeginDrag,
3563 ImageListImpl_EndDrag,
3564 ImageListImpl_DragEnter,
3565 ImageListImpl_DragLeave,
3566 ImageListImpl_DragMove,
3567 ImageListImpl_SetDragCursorImage,
3568 ImageListImpl_DragShowNolock,
3569 ImageListImpl_GetDragImage,
3570 ImageListImpl_GetItemFlags,
3571 ImageListImpl_GetOverlayImage
3574 static inline BOOL is_valid(HIMAGELIST himl)
3576 return himl && himl->lpVtbl == &ImageListImpl_Vtbl;
3579 /*************************************************************************
3580 * HIMAGELIST_QueryInterface [COMCTL32.@]
3582 * Returns a pointer to an IImageList or IImageList2 object for the given
3586 * himl [I] Image list handle.
3587 * riid [I] Identifier of the requested interface.
3588 * ppv [O] Returns the address of the pointer requested, or NULL.
3592 * Failure: Error value.
3595 HIMAGELIST_QueryInterface (HIMAGELIST himl, REFIID riid, void **ppv)
3597 TRACE("(%p,%s,%p)\n", himl, debugstr_guid(riid), ppv);
3598 return IImageList_QueryInterface((IImageList *) himl, riid, ppv);
3601 static HRESULT ImageListImpl_CreateInstance(const IUnknown *pUnkOuter, REFIID iid, void** ppv)
3606 TRACE("(%p,%s,%p)\n", pUnkOuter, debugstr_guid(iid), ppv);
3610 if (pUnkOuter) return CLASS_E_NOAGGREGATION;
3612 This = HeapAlloc(GetProcessHeap(), 0, sizeof(struct _IMAGELIST));
3613 if (!This) return E_OUTOFMEMORY;
3615 ZeroMemory(This, sizeof(struct _IMAGELIST));
3617 This->lpVtbl = &ImageListImpl_Vtbl;
3620 ret = IUnknown_QueryInterface((IUnknown*)This, iid, ppv);
3621 IUnknown_Release((IUnknown*)This);