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 /* pre-multiply by the alpha channel */
216 for (i = 0; i < height; i++)
218 for (j = n * width; j < (n + 1) * width; j++)
220 DWORD argb = bits[i * bm.bmWidth + j];
221 DWORD alpha = argb >> 24;
222 bits[i * bm.bmWidth + j] = ((argb & 0xff000000) |
223 (((argb & 0x00ff0000) * alpha / 255) & 0x00ff0000) |
224 (((argb & 0x0000ff00) * alpha / 255) & 0x0000ff00) |
225 (((argb & 0x000000ff) * alpha / 255)));
229 if (mask_info && himl->hbmMask) /* generate the mask from the alpha channel */
231 for (i = 0; i < height; i++)
232 for (j = n * width; j < (n + 1) * width; j++)
233 if ((bits[i * bm.bmWidth + j] >> 24) > 25) /* more than 10% alpha */
234 mask_bits[i * mask_width + j / 8] &= ~(0x80 >> (j % 8));
236 mask_bits[i * mask_width + j / 8] |= 0x80 >> (j % 8);
237 StretchDIBits( himl->hdcMask, pt.x, pt.y, himl->cx, himl->cy,
238 n * width, 0, width, height, mask_bits, mask_info, DIB_RGB_COLORS, SRCCOPY );
241 StretchDIBits( himl->hdcImage, pt.x, pt.y, himl->cx, himl->cy,
242 n * width, 0, width, height, bits, info, DIB_RGB_COLORS, SRCCOPY );
248 if (hdcMask) DeleteDC( hdcMask );
249 HeapFree( GetProcessHeap(), 0, info );
250 HeapFree( GetProcessHeap(), 0, bits );
251 HeapFree( GetProcessHeap(), 0, mask_bits );
255 /*************************************************************************
256 * IMAGELIST_InternalExpandBitmaps [Internal]
258 * Expands the bitmaps of an image list by the given number of images.
261 * himl [I] handle to image list
262 * nImageCount [I] number of images to add
268 * This function CANNOT be used to reduce the number of images.
271 IMAGELIST_InternalExpandBitmaps(HIMAGELIST himl, INT nImageCount)
274 HBITMAP hbmNewBitmap, hbmNull;
278 TRACE("%p has %d allocated %d images\n", himl, himl->cCurImage, himl->cMaxImage);
280 if (himl->cCurImage + nImageCount <= himl->cMaxImage)
283 nNewCount = himl->cCurImage + max(nImageCount, himl->cGrow) + 1;
285 imagelist_get_bitmap_size(himl, nNewCount, &sz);
287 TRACE("Create expanded bitmaps : himl=%p x=%d y=%d count=%d\n", himl, sz.cx, sz.cy, nNewCount);
288 hdcBitmap = CreateCompatibleDC (0);
290 hbmNewBitmap = ImageList_CreateImage(hdcBitmap, himl, nNewCount);
292 if (hbmNewBitmap == 0)
293 ERR("creating new image bitmap (x=%d y=%d)!\n", sz.cx, sz.cy);
297 hbmNull = SelectObject (hdcBitmap, hbmNewBitmap);
298 BitBlt (hdcBitmap, 0, 0, sz.cx, sz.cy,
299 himl->hdcImage, 0, 0, SRCCOPY);
300 SelectObject (hdcBitmap, hbmNull);
302 SelectObject (himl->hdcImage, hbmNewBitmap);
303 DeleteObject (himl->hbmImage);
304 himl->hbmImage = hbmNewBitmap;
306 if (himl->flags & ILC_MASK)
308 hbmNewBitmap = CreateBitmap (sz.cx, sz.cy, 1, 1, NULL);
310 if (hbmNewBitmap == 0)
311 ERR("creating new mask bitmap!\n");
315 hbmNull = SelectObject (hdcBitmap, hbmNewBitmap);
316 BitBlt (hdcBitmap, 0, 0, sz.cx, sz.cy,
317 himl->hdcMask, 0, 0, SRCCOPY);
318 SelectObject (hdcBitmap, hbmNull);
320 SelectObject (himl->hdcMask, hbmNewBitmap);
321 DeleteObject (himl->hbmMask);
322 himl->hbmMask = hbmNewBitmap;
327 char *new_alpha = HeapReAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, himl->has_alpha, nNewCount );
328 if (new_alpha) himl->has_alpha = new_alpha;
331 HeapFree( GetProcessHeap(), 0, himl->has_alpha );
332 himl->has_alpha = NULL;
336 himl->cMaxImage = nNewCount;
338 DeleteDC (hdcBitmap);
342 /*************************************************************************
343 * ImageList_Add [COMCTL32.@]
345 * Add an image or images to an image list.
348 * himl [I] handle to image list
349 * hbmImage [I] handle to image bitmap
350 * hbmMask [I] handle to mask bitmap
353 * Success: Index of the first new image.
358 ImageList_Add (HIMAGELIST himl, HBITMAP hbmImage, HBITMAP hbmMask)
360 HDC hdcBitmap, hdcTemp = 0;
361 INT nFirstIndex, nImageCount, i;
365 TRACE("himl=%p hbmimage=%p hbmmask=%p\n", himl, hbmImage, hbmMask);
369 if (!GetObjectW(hbmImage, sizeof(BITMAP), &bmp))
372 TRACE("himl %p, cCurImage %d, cMaxImage %d, cGrow %d, cx %d, cy %d\n",
373 himl, himl->cCurImage, himl->cMaxImage, himl->cGrow, himl->cx, himl->cy);
375 nImageCount = bmp.bmWidth / himl->cx;
377 TRACE("%p has %d images (%d x %d)\n", hbmImage, nImageCount, bmp.bmWidth, bmp.bmHeight);
379 IMAGELIST_InternalExpandBitmaps(himl, nImageCount);
381 hdcBitmap = CreateCompatibleDC(0);
383 SelectObject(hdcBitmap, hbmImage);
385 if (add_with_alpha( himl, hdcBitmap, himl->cCurImage, nImageCount,
386 himl->cx, min( himl->cy, bmp.bmHeight), hbmImage, hbmMask ))
391 hdcTemp = CreateCompatibleDC(0);
392 SelectObject(hdcTemp, hbmMask);
395 for (i=0; i<nImageCount; i++)
397 imagelist_point_from_index( himl, himl->cCurImage + i, &pt );
399 /* Copy result to the imagelist
401 BitBlt( himl->hdcImage, pt.x, pt.y, himl->cx, bmp.bmHeight,
402 hdcBitmap, i*himl->cx, 0, SRCCOPY );
407 BitBlt( himl->hdcMask, pt.x, pt.y, himl->cx, bmp.bmHeight,
408 hdcTemp, i*himl->cx, 0, SRCCOPY );
410 /* Remove the background from the image
412 BitBlt( himl->hdcImage, pt.x, pt.y, himl->cx, bmp.bmHeight,
413 himl->hdcMask, pt.x, pt.y, 0x220326 ); /* NOTSRCAND */
415 if (hdcTemp) DeleteDC(hdcTemp);
420 nFirstIndex = himl->cCurImage;
421 himl->cCurImage += nImageCount;
427 /*************************************************************************
428 * ImageList_AddIcon [COMCTL32.@]
430 * Adds an icon to an image list.
433 * himl [I] handle to image list
434 * hIcon [I] handle to icon
437 * Success: index of the new image
440 #undef ImageList_AddIcon
441 INT WINAPI ImageList_AddIcon (HIMAGELIST himl, HICON hIcon)
443 return ImageList_ReplaceIcon (himl, -1, hIcon);
447 /*************************************************************************
448 * ImageList_AddMasked [COMCTL32.@]
450 * Adds an image or images to an image list and creates a mask from the
451 * specified bitmap using the mask color.
454 * himl [I] handle to image list.
455 * hBitmap [I] handle to bitmap
456 * clrMask [I] mask color.
459 * Success: Index of the first new image.
464 ImageList_AddMasked (HIMAGELIST himl, HBITMAP hBitmap, COLORREF clrMask)
466 HDC hdcMask, hdcBitmap;
472 TRACE("himl=%p hbitmap=%p clrmask=%x\n", himl, hBitmap, clrMask);
476 if (!GetObjectW(hBitmap, sizeof(BITMAP), &bmp))
479 hdcBitmap = CreateCompatibleDC(0);
480 SelectObject(hdcBitmap, hBitmap);
482 /* Create a temp Mask so we can remove the background of the Image */
483 hdcMask = CreateCompatibleDC(0);
484 hMaskBitmap = CreateBitmap(bmp.bmWidth, bmp.bmHeight, 1, 1, NULL);
485 SelectObject(hdcMask, hMaskBitmap);
487 /* create monochrome image to the mask bitmap */
488 bkColor = (clrMask != CLR_DEFAULT) ? clrMask : GetPixel (hdcBitmap, 0, 0);
489 SetBkColor (hdcBitmap, bkColor);
490 BitBlt (hdcMask, 0, 0, bmp.bmWidth, bmp.bmHeight, hdcBitmap, 0, 0, SRCCOPY);
492 SetBkColor(hdcBitmap, RGB(255,255,255));
495 * Remove the background from the image
497 * WINDOWS BUG ALERT!!!!!!
498 * The statement below should not be done in common practice
499 * but this is how ImageList_AddMasked works in Windows.
500 * It overwrites the original bitmap passed, this was discovered
501 * by using the same bitmap to iterate the different styles
502 * on windows where it failed (BUT ImageList_Add is OK)
503 * This is here in case some apps rely on this bug
505 * Blt mode 0x220326 is NOTSRCAND
507 BitBlt(hdcBitmap, 0, 0, bmp.bmWidth, bmp.bmHeight, hdcMask, 0, 0, 0x220326);
512 ret = ImageList_Add( himl, hBitmap, hMaskBitmap );
514 DeleteObject(hMaskBitmap);
519 /*************************************************************************
520 * ImageList_BeginDrag [COMCTL32.@]
522 * Creates a temporary image list that contains one image. It will be used
526 * himlTrack [I] handle to the source image list
527 * iTrack [I] index of the drag image in the source image list
528 * dxHotspot [I] X position of the hot spot of the drag image
529 * dyHotspot [I] Y position of the hot spot of the drag image
537 ImageList_BeginDrag (HIMAGELIST himlTrack, INT iTrack,
538 INT dxHotspot, INT dyHotspot)
542 TRACE("(himlTrack=%p iTrack=%d dx=%d dy=%d)\n", himlTrack, iTrack,
543 dxHotspot, dyHotspot);
545 if (!is_valid(himlTrack))
548 if (InternalDrag.himl)
549 ImageList_EndDrag ();
554 InternalDrag.himl = ImageList_Create (cx, cy, himlTrack->flags, 1, 1);
555 if (InternalDrag.himl == NULL) {
556 WARN("Error creating drag image list!\n");
560 InternalDrag.dxHotspot = dxHotspot;
561 InternalDrag.dyHotspot = dyHotspot;
564 BitBlt (InternalDrag.himl->hdcImage, 0, 0, cx, cy, himlTrack->hdcImage, iTrack * cx, 0, SRCCOPY);
567 BitBlt (InternalDrag.himl->hdcMask, 0, 0, cx, cy, himlTrack->hdcMask, iTrack * cx, 0, SRCCOPY);
569 InternalDrag.himl->cCurImage = 1;
575 /*************************************************************************
576 * ImageList_Copy [COMCTL32.@]
578 * Copies an image of the source image list to an image of the
579 * destination image list. Images can be copied or swapped.
582 * himlDst [I] handle to the destination image list
583 * iDst [I] destination image index.
584 * himlSrc [I] handle to the source image list
585 * iSrc [I] source image index
586 * uFlags [I] flags for the copy operation
593 * Copying from one image list to another is possible. The original
594 * implementation just copies or swaps within one image list.
595 * Could this feature become a bug??? ;-)
599 ImageList_Copy (HIMAGELIST himlDst, INT iDst, HIMAGELIST himlSrc,
600 INT iSrc, UINT uFlags)
604 TRACE("himlDst=%p iDst=%d himlSrc=%p iSrc=%d\n", himlDst, iDst, himlSrc, iSrc);
606 if (!is_valid(himlSrc) || !is_valid(himlDst))
608 if ((iDst < 0) || (iDst >= himlDst->cCurImage))
610 if ((iSrc < 0) || (iSrc >= himlSrc->cCurImage))
613 imagelist_point_from_index( himlDst, iDst, &ptDst );
614 imagelist_point_from_index( himlSrc, iSrc, &ptSrc );
616 if (uFlags & ILCF_SWAP) {
619 HBITMAP hbmTempImage, hbmTempMask;
621 hdcBmp = CreateCompatibleDC (0);
623 /* create temporary bitmaps */
624 hbmTempImage = CreateBitmap (himlSrc->cx, himlSrc->cy, 1,
625 himlSrc->uBitsPixel, NULL);
626 hbmTempMask = CreateBitmap (himlSrc->cx, himlSrc->cy, 1,
629 /* copy (and stretch) destination to temporary bitmaps.(save) */
631 SelectObject (hdcBmp, hbmTempImage);
632 StretchBlt (hdcBmp, 0, 0, himlSrc->cx, himlSrc->cy,
633 himlDst->hdcImage, ptDst.x, ptDst.y, himlDst->cx, himlDst->cy,
636 SelectObject (hdcBmp, hbmTempMask);
637 StretchBlt (hdcBmp, 0, 0, himlSrc->cx, himlSrc->cy,
638 himlDst->hdcMask, ptDst.x, ptDst.y, himlDst->cx, himlDst->cy,
641 /* copy (and stretch) source to destination */
643 StretchBlt (himlDst->hdcImage, ptDst.x, ptDst.y, himlDst->cx, himlDst->cy,
644 himlSrc->hdcImage, ptSrc.x, ptSrc.y, himlSrc->cx, himlSrc->cy,
647 StretchBlt (himlDst->hdcMask, ptDst.x, ptDst.y, himlDst->cx, himlDst->cy,
648 himlSrc->hdcMask, ptSrc.x, ptSrc.y, himlSrc->cx, himlSrc->cy,
651 /* copy (without stretching) temporary bitmaps to source (restore) */
653 BitBlt (himlSrc->hdcMask, ptSrc.x, ptSrc.y, himlSrc->cx, himlSrc->cy,
654 hdcBmp, 0, 0, SRCCOPY);
657 BitBlt (himlSrc->hdcImage, ptSrc.x, ptSrc.y, himlSrc->cx, himlSrc->cy,
658 hdcBmp, 0, 0, SRCCOPY);
659 /* delete temporary bitmaps */
660 DeleteObject (hbmTempMask);
661 DeleteObject (hbmTempImage);
666 StretchBlt (himlDst->hdcImage, ptDst.x, ptDst.y, himlDst->cx, himlDst->cy,
667 himlSrc->hdcImage, ptSrc.x, ptSrc.y, himlSrc->cx, himlSrc->cy,
671 StretchBlt (himlDst->hdcMask, ptDst.x, ptDst.y, himlDst->cx, himlDst->cy,
672 himlSrc->hdcMask, ptSrc.x, ptSrc.y, himlSrc->cx, himlSrc->cy,
680 /*************************************************************************
681 * ImageList_Create [COMCTL32.@]
683 * Creates a new image list.
686 * cx [I] image height
688 * flags [I] creation flags
689 * cInitial [I] initial number of images in the image list
690 * cGrow [I] number of images by which image list grows
693 * Success: Handle to the created image list
697 ImageList_Create (INT cx, INT cy, UINT flags,
698 INT cInitial, INT cGrow)
703 UINT ilc = (flags & 0xFE);
704 static const WORD aBitBlend25[] =
705 {0xAA, 0x00, 0x55, 0x00, 0xAA, 0x00, 0x55, 0x00};
707 static const WORD aBitBlend50[] =
708 {0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA};
710 TRACE("(%d %d 0x%x %d %d)\n", cx, cy, flags, cInitial, cGrow);
712 /* Create the IImageList interface for the image list */
713 if (FAILED(ImageListImpl_CreateInstance(NULL, &IID_IImageList, (void **)&himl)))
716 cGrow = (cGrow < 4) ? 4 : (cGrow + 3) & ~3;
721 himl->cMaxImage = cInitial + 1;
722 himl->cInitial = cInitial;
724 himl->clrFg = CLR_DEFAULT;
725 himl->clrBk = CLR_NONE;
727 /* initialize overlay mask indices */
728 for (nCount = 0; nCount < MAX_OVERLAYIMAGE; nCount++)
729 himl->nOvlIdx[nCount] = -1;
731 /* Create Image & Mask DCs */
732 himl->hdcImage = CreateCompatibleDC (0);
735 if (himl->flags & ILC_MASK){
736 himl->hdcMask = CreateCompatibleDC(0);
741 /* Default to ILC_COLOR4 if none of the ILC_COLOR* flags are specified */
742 if (ilc == ILC_COLOR)
745 if (ilc >= ILC_COLOR4 && ilc <= ILC_COLOR32)
746 himl->uBitsPixel = ilc;
748 himl->uBitsPixel = (UINT)GetDeviceCaps (himl->hdcImage, BITSPIXEL);
750 if (himl->cMaxImage > 0) {
751 himl->hbmImage = ImageList_CreateImage(himl->hdcImage, himl, himl->cMaxImage);
752 SelectObject(himl->hdcImage, himl->hbmImage);
756 if ((himl->cMaxImage > 0) && (himl->flags & ILC_MASK)) {
759 imagelist_get_bitmap_size(himl, himl->cMaxImage, &sz);
760 himl->hbmMask = CreateBitmap (sz.cx, sz.cy, 1, 1, NULL);
761 if (himl->hbmMask == 0) {
762 ERR("Error creating mask bitmap!\n");
765 SelectObject(himl->hdcMask, himl->hbmMask);
770 if (himl->uBitsPixel == 32)
771 himl->has_alpha = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, himl->cMaxImage );
773 himl->has_alpha = NULL;
775 /* create blending brushes */
776 hbmTemp = CreateBitmap (8, 8, 1, 1, aBitBlend25);
777 himl->hbrBlend25 = CreatePatternBrush (hbmTemp);
778 DeleteObject (hbmTemp);
780 hbmTemp = CreateBitmap (8, 8, 1, 1, aBitBlend50);
781 himl->hbrBlend50 = CreatePatternBrush (hbmTemp);
782 DeleteObject (hbmTemp);
784 TRACE("created imagelist %p\n", himl);
788 ImageList_Destroy(himl);
793 /*************************************************************************
794 * ImageList_Destroy [COMCTL32.@]
796 * Destroys an image list.
799 * himl [I] handle to image list
807 ImageList_Destroy (HIMAGELIST himl)
812 IImageList_Release((IImageList *) himl);
817 /*************************************************************************
818 * ImageList_DragEnter [COMCTL32.@]
820 * Locks window update and displays the drag image at the given position.
823 * hwndLock [I] handle of the window that owns the drag image.
824 * x [I] X position of the drag image.
825 * y [I] Y position of the drag image.
832 * The position of the drag image is relative to the window, not
837 ImageList_DragEnter (HWND hwndLock, INT x, INT y)
839 TRACE("(hwnd=%p x=%d y=%d)\n", hwndLock, x, y);
841 if (!is_valid(InternalDrag.himl))
845 InternalDrag.hwnd = hwndLock;
847 InternalDrag.hwnd = GetDesktopWindow ();
852 /* draw the drag image and save the background */
853 if (!ImageList_DragShowNolock(TRUE)) {
861 /*************************************************************************
862 * ImageList_DragLeave [COMCTL32.@]
864 * Unlocks window update and hides the drag image.
867 * hwndLock [I] handle of the window that owns the drag image.
875 ImageList_DragLeave (HWND hwndLock)
877 /* As we don't save drag info in the window this can lead to problems if
878 an app does not supply the same window as DragEnter */
880 InternalDrag.hwnd = hwndLock;
882 InternalDrag.hwnd = GetDesktopWindow (); */
884 hwndLock = GetDesktopWindow();
885 if(InternalDrag.hwnd != hwndLock)
886 FIXME("DragLeave hWnd != DragEnter hWnd\n");
888 ImageList_DragShowNolock (FALSE);
894 /*************************************************************************
895 * ImageList_InternalDragDraw [Internal]
897 * Draws the drag image.
900 * hdc [I] device context to draw into.
901 * x [I] X position of the drag image.
902 * y [I] Y position of the drag image.
909 * The position of the drag image is relative to the window, not
915 ImageList_InternalDragDraw (HDC hdc, INT x, INT y)
917 IMAGELISTDRAWPARAMS imldp;
919 ZeroMemory (&imldp, sizeof(imldp));
920 imldp.cbSize = sizeof(imldp);
921 imldp.himl = InternalDrag.himl;
926 imldp.rgbBk = CLR_DEFAULT;
927 imldp.rgbFg = CLR_DEFAULT;
928 imldp.fStyle = ILD_NORMAL;
929 imldp.fState = ILS_ALPHA;
931 ImageList_DrawIndirect (&imldp);
934 /*************************************************************************
935 * ImageList_DragMove [COMCTL32.@]
937 * Moves the drag image.
940 * x [I] X position of the drag image.
941 * y [I] Y position of the drag image.
948 * The position of the drag image is relative to the window, not
953 ImageList_DragMove (INT x, INT y)
955 TRACE("(x=%d y=%d)\n", x, y);
957 if (!is_valid(InternalDrag.himl))
960 /* draw/update the drag image */
961 if (InternalDrag.bShow) {
965 HBITMAP hbmOffScreen;
966 INT origNewX, origNewY;
967 INT origOldX, origOldY;
968 INT origRegX, origRegY;
969 INT sizeRegX, sizeRegY;
972 /* calculate the update region */
973 origNewX = x - InternalDrag.dxHotspot;
974 origNewY = y - InternalDrag.dyHotspot;
975 origOldX = InternalDrag.x - InternalDrag.dxHotspot;
976 origOldY = InternalDrag.y - InternalDrag.dyHotspot;
977 origRegX = min(origNewX, origOldX);
978 origRegY = min(origNewY, origOldY);
979 sizeRegX = InternalDrag.himl->cx + abs(x - InternalDrag.x);
980 sizeRegY = InternalDrag.himl->cy + abs(y - InternalDrag.y);
982 hdcDrag = GetDCEx(InternalDrag.hwnd, 0,
983 DCX_WINDOW | DCX_CACHE | DCX_LOCKWINDOWUPDATE);
984 hdcOffScreen = CreateCompatibleDC(hdcDrag);
985 hdcBg = CreateCompatibleDC(hdcDrag);
987 hbmOffScreen = CreateCompatibleBitmap(hdcDrag, sizeRegX, sizeRegY);
988 SelectObject(hdcOffScreen, hbmOffScreen);
989 SelectObject(hdcBg, InternalDrag.hbmBg);
991 /* get the actual background of the update region */
992 BitBlt(hdcOffScreen, 0, 0, sizeRegX, sizeRegY, hdcDrag,
993 origRegX, origRegY, SRCCOPY);
994 /* erase the old image */
995 BitBlt(hdcOffScreen, origOldX - origRegX, origOldY - origRegY,
996 InternalDrag.himl->cx, InternalDrag.himl->cy, hdcBg, 0, 0,
998 /* save the background */
999 BitBlt(hdcBg, 0, 0, InternalDrag.himl->cx, InternalDrag.himl->cy,
1000 hdcOffScreen, origNewX - origRegX, origNewY - origRegY, SRCCOPY);
1001 /* draw the image */
1002 ImageList_InternalDragDraw(hdcOffScreen, origNewX - origRegX,
1003 origNewY - origRegY);
1004 /* draw the update region to the screen */
1005 BitBlt(hdcDrag, origRegX, origRegY, sizeRegX, sizeRegY,
1006 hdcOffScreen, 0, 0, SRCCOPY);
1009 DeleteDC(hdcOffScreen);
1010 DeleteObject(hbmOffScreen);
1011 ReleaseDC(InternalDrag.hwnd, hdcDrag);
1014 /* update the image position */
1022 /*************************************************************************
1023 * ImageList_DragShowNolock [COMCTL32.@]
1025 * Shows or hides the drag image.
1028 * bShow [I] TRUE shows the drag image, FALSE hides it.
1036 ImageList_DragShowNolock (BOOL bShow)
1042 if (!is_valid(InternalDrag.himl))
1045 TRACE("bShow=0x%X!\n", bShow);
1047 /* DragImage is already visible/hidden */
1048 if ((InternalDrag.bShow && bShow) || (!InternalDrag.bShow && !bShow)) {
1052 /* position of the origin of the DragImage */
1053 x = InternalDrag.x - InternalDrag.dxHotspot;
1054 y = InternalDrag.y - InternalDrag.dyHotspot;
1056 hdcDrag = GetDCEx (InternalDrag.hwnd, 0,
1057 DCX_WINDOW | DCX_CACHE | DCX_LOCKWINDOWUPDATE);
1062 hdcBg = CreateCompatibleDC(hdcDrag);
1063 if (!InternalDrag.hbmBg) {
1064 InternalDrag.hbmBg = CreateCompatibleBitmap(hdcDrag,
1065 InternalDrag.himl->cx, InternalDrag.himl->cy);
1067 SelectObject(hdcBg, InternalDrag.hbmBg);
1070 /* save the background */
1071 BitBlt(hdcBg, 0, 0, InternalDrag.himl->cx, InternalDrag.himl->cy,
1072 hdcDrag, x, y, SRCCOPY);
1073 /* show the image */
1074 ImageList_InternalDragDraw(hdcDrag, x, y);
1076 /* hide the image */
1077 BitBlt(hdcDrag, x, y, InternalDrag.himl->cx, InternalDrag.himl->cy,
1078 hdcBg, 0, 0, SRCCOPY);
1081 InternalDrag.bShow = !InternalDrag.bShow;
1084 ReleaseDC (InternalDrag.hwnd, hdcDrag);
1089 /*************************************************************************
1090 * ImageList_Draw [COMCTL32.@]
1095 * himl [I] handle to image list
1097 * hdc [I] handle to device context
1100 * fStyle [I] drawing flags
1111 ImageList_Draw (HIMAGELIST himl, INT i, HDC hdc, INT x, INT y, UINT fStyle)
1113 return ImageList_DrawEx (himl, i, hdc, x, y, 0, 0,
1114 CLR_DEFAULT, CLR_DEFAULT, fStyle);
1118 /*************************************************************************
1119 * ImageList_DrawEx [COMCTL32.@]
1121 * Draws an image and allows to use extended drawing features.
1124 * himl [I] handle to image list
1126 * hdc [I] handle to device context
1131 * rgbBk [I] background color
1132 * rgbFg [I] foreground color
1133 * fStyle [I] drawing flags
1140 * Calls ImageList_DrawIndirect.
1143 * ImageList_DrawIndirect.
1147 ImageList_DrawEx (HIMAGELIST himl, INT i, HDC hdc, INT x, INT y,
1148 INT dx, INT dy, COLORREF rgbBk, COLORREF rgbFg,
1151 IMAGELISTDRAWPARAMS imldp;
1153 ZeroMemory (&imldp, sizeof(imldp));
1154 imldp.cbSize = sizeof(imldp);
1162 imldp.rgbBk = rgbBk;
1163 imldp.rgbFg = rgbFg;
1164 imldp.fStyle = fStyle;
1166 return ImageList_DrawIndirect (&imldp);
1170 static BOOL alpha_blend_image( HIMAGELIST himl, HDC dest_dc, int dest_x, int dest_y,
1171 int src_x, int src_y, int cx, int cy, BLENDFUNCTION func )
1175 HBITMAP bmp = 0, mask = 0;
1177 void *bits, *mask_bits;
1181 if (!(hdc = CreateCompatibleDC( 0 ))) return FALSE;
1182 if (!(info = HeapAlloc( GetProcessHeap(), 0, FIELD_OFFSET( BITMAPINFO, bmiColors[256] )))) goto done;
1183 info->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
1184 info->bmiHeader.biWidth = cx;
1185 info->bmiHeader.biHeight = cy;
1186 info->bmiHeader.biPlanes = 1;
1187 info->bmiHeader.biBitCount = 32;
1188 info->bmiHeader.biCompression = BI_RGB;
1189 info->bmiHeader.biSizeImage = cx * cy * 4;
1190 info->bmiHeader.biXPelsPerMeter = 0;
1191 info->bmiHeader.biYPelsPerMeter = 0;
1192 info->bmiHeader.biClrUsed = 0;
1193 info->bmiHeader.biClrImportant = 0;
1194 if (!(bmp = CreateDIBSection( himl->hdcImage, info, DIB_RGB_COLORS, &bits, 0, 0 ))) goto done;
1195 SelectObject( hdc, bmp );
1196 BitBlt( hdc, 0, 0, cx, cy, himl->hdcImage, src_x, src_y, SRCCOPY );
1200 unsigned int width_bytes = (cx + 31) / 32 * 4;
1201 /* generate alpha channel from the mask */
1202 info->bmiHeader.biBitCount = 1;
1203 info->bmiHeader.biSizeImage = width_bytes * cy;
1204 if (!(mask = CreateDIBSection( himl->hdcMask, info, DIB_RGB_COLORS, &mask_bits, 0, 0 )))
1206 SelectObject( hdc, mask );
1207 BitBlt( hdc, 0, 0, cx, cy, himl->hdcMask, src_x, src_y, SRCCOPY );
1208 SelectObject( hdc, bmp );
1209 for (i = 0, ptr = bits; i < cy; i++)
1210 for (j = 0; j < cx; j++, ptr++)
1211 if ((((BYTE *)mask_bits)[i * width_bytes + j / 8] << (j % 8)) & 0x80) *ptr = 0;
1212 else *ptr |= 0xff000000;
1215 ret = GdiAlphaBlend( dest_dc, dest_x, dest_y, cx, cy, hdc, 0, 0, cx, cy, func );
1219 if (bmp) DeleteObject( bmp );
1220 if (mask) DeleteObject( mask );
1221 HeapFree( GetProcessHeap(), 0, info );
1225 /*************************************************************************
1226 * ImageList_DrawIndirect [COMCTL32.@]
1228 * Draws an image using various parameters specified in pimldp.
1231 * pimldp [I] pointer to IMAGELISTDRAWPARAMS structure.
1239 ImageList_DrawIndirect (IMAGELISTDRAWPARAMS *pimldp)
1241 INT cx, cy, nOvlIdx;
1242 DWORD fState, dwRop;
1244 COLORREF oldImageBk, oldImageFg;
1245 HDC hImageDC, hImageListDC, hMaskListDC;
1246 HBITMAP hImageBmp, hOldImageBmp, hBlendMaskBmp;
1247 BOOL bIsTransparent, bBlend, bResult = FALSE, bMask;
1253 if (!pimldp || !(himl = pimldp->himl)) return FALSE;
1254 if (!is_valid(himl)) return FALSE;
1255 if ((pimldp->i < 0) || (pimldp->i >= himl->cCurImage)) return FALSE;
1257 imagelist_point_from_index( himl, pimldp->i, &pt );
1258 pt.x += pimldp->xBitmap;
1259 pt.y += pimldp->yBitmap;
1261 fState = pimldp->cbSize < sizeof(IMAGELISTDRAWPARAMS) ? ILS_NORMAL : pimldp->fState;
1262 fStyle = pimldp->fStyle & ~ILD_OVERLAYMASK;
1263 cx = (pimldp->cx == 0) ? himl->cx : pimldp->cx;
1264 cy = (pimldp->cy == 0) ? himl->cy : pimldp->cy;
1266 bIsTransparent = (fStyle & ILD_TRANSPARENT);
1267 if( pimldp->rgbBk == CLR_NONE )
1268 bIsTransparent = TRUE;
1269 if( ( pimldp->rgbBk == CLR_DEFAULT ) && ( himl->clrBk == CLR_NONE ) )
1270 bIsTransparent = TRUE;
1271 bMask = (himl->flags & ILC_MASK) && (fStyle & ILD_MASK) ;
1272 bBlend = (fStyle & (ILD_BLEND25 | ILD_BLEND50) ) && !bMask;
1274 TRACE("himl(%p) hbmMask(%p) iImage(%d) x(%d) y(%d) cx(%d) cy(%d)\n",
1275 himl, himl->hbmMask, pimldp->i, pimldp->x, pimldp->y, cx, cy);
1277 /* we will use these DCs to access the images and masks in the ImageList */
1278 hImageListDC = himl->hdcImage;
1279 hMaskListDC = himl->hdcMask;
1281 /* these will accumulate the image and mask for the image we're drawing */
1282 hImageDC = CreateCompatibleDC( pimldp->hdcDst );
1283 hImageBmp = CreateCompatibleBitmap( pimldp->hdcDst, cx, cy );
1284 hBlendMaskBmp = bBlend ? CreateBitmap(cx, cy, 1, 1, NULL) : 0;
1286 /* Create a compatible DC. */
1287 if (!hImageListDC || !hImageDC || !hImageBmp ||
1288 (bBlend && !hBlendMaskBmp) || (himl->hbmMask && !hMaskListDC))
1291 hOldImageBmp = SelectObject(hImageDC, hImageBmp);
1294 * To obtain a transparent look, background color should be set
1295 * to white and foreground color to black when blitting the
1298 oldImageFg = SetTextColor( hImageDC, RGB( 0, 0, 0 ) );
1299 oldImageBk = SetBkColor( hImageDC, RGB( 0xff, 0xff, 0xff ) );
1301 has_alpha = (himl->has_alpha && himl->has_alpha[pimldp->i]);
1302 if (!bMask && (has_alpha || (fState & ILS_ALPHA)))
1307 func.BlendOp = AC_SRC_OVER;
1308 func.BlendFlags = 0;
1309 func.SourceConstantAlpha = (fState & ILS_ALPHA) ? pimldp->Frame : 255;
1310 func.AlphaFormat = AC_SRC_ALPHA;
1314 if (himl->uBitsPixel == 32) /* we already have an alpha channel in this case */
1315 bResult = GdiAlphaBlend( pimldp->hdcDst, pimldp->x, pimldp->y, cx, cy,
1316 himl->hdcImage, pt.x, pt.y, cx, cy, func );
1318 bResult = alpha_blend_image( himl, pimldp->hdcDst, pimldp->x, pimldp->y,
1319 pt.x, pt.y, cx, cy, func );
1322 colour = pimldp->rgbBk;
1323 if (colour == CLR_DEFAULT) colour = himl->clrBk;
1324 if (colour == CLR_NONE) colour = GetBkColor( pimldp->hdcDst );
1326 hOldBrush = SelectObject (hImageDC, CreateSolidBrush (colour));
1327 PatBlt( hImageDC, 0, 0, cx, cy, PATCOPY );
1328 if (himl->uBitsPixel == 32)
1329 GdiAlphaBlend( hImageDC, 0, 0, cx, cy, himl->hdcImage, pt.x, pt.y, cx, cy, func );
1331 alpha_blend_image( himl, hImageDC, 0, 0, pt.x, pt.y, cx, cy, func );
1332 DeleteObject (SelectObject (hImageDC, hOldBrush));
1333 bResult = BitBlt( pimldp->hdcDst, pimldp->x, pimldp->y, cx, cy, hImageDC, 0, 0, SRCCOPY );
1338 * Draw the initial image
1341 if (himl->hbmMask) {
1342 hOldBrush = SelectObject (hImageDC, CreateSolidBrush (GetTextColor(pimldp->hdcDst)));
1343 PatBlt( hImageDC, 0, 0, cx, cy, PATCOPY );
1344 BitBlt(hImageDC, 0, 0, cx, cy, hMaskListDC, pt.x, pt.y, SRCPAINT);
1345 DeleteObject (SelectObject (hImageDC, hOldBrush));
1346 if( bIsTransparent )
1348 BitBlt ( pimldp->hdcDst, pimldp->x, pimldp->y, cx, cy, hImageDC, 0, 0, SRCAND);
1353 hOldBrush = SelectObject (hImageDC, GetStockObject(BLACK_BRUSH));
1354 PatBlt( hImageDC, 0, 0, cx, cy, PATCOPY);
1355 SelectObject(hImageDC, hOldBrush);
1358 /* blend the image with the needed solid background */
1359 COLORREF colour = RGB(0,0,0);
1361 if( !bIsTransparent )
1363 colour = pimldp->rgbBk;
1364 if( colour == CLR_DEFAULT )
1365 colour = himl->clrBk;
1366 if( colour == CLR_NONE )
1367 colour = GetBkColor(pimldp->hdcDst);
1370 hOldBrush = SelectObject (hImageDC, CreateSolidBrush (colour));
1371 PatBlt( hImageDC, 0, 0, cx, cy, PATCOPY );
1374 BitBlt( hImageDC, 0, 0, cx, cy, hMaskListDC, pt.x, pt.y, SRCAND );
1375 BitBlt( hImageDC, 0, 0, cx, cy, hImageListDC, pt.x, pt.y, SRCPAINT );
1378 BitBlt( hImageDC, 0, 0, cx, cy, hImageListDC, pt.x, pt.y, SRCCOPY);
1379 DeleteObject (SelectObject (hImageDC, hOldBrush));
1382 /* Time for blending, if required */
1385 COLORREF clrBlend = pimldp->rgbFg;
1386 HDC hBlendMaskDC = hImageListDC;
1389 /* Create the blend Mask */
1390 hOldBitmap = SelectObject(hBlendMaskDC, hBlendMaskBmp);
1391 hBlendBrush = fStyle & ILD_BLEND50 ? himl->hbrBlend50 : himl->hbrBlend25;
1392 hOldBrush = SelectObject(hBlendMaskDC, hBlendBrush);
1393 PatBlt(hBlendMaskDC, 0, 0, cx, cy, PATCOPY);
1394 SelectObject(hBlendMaskDC, hOldBrush);
1396 /* Modify the blend mask if an Image Mask exist */
1398 BitBlt(hBlendMaskDC, 0, 0, cx, cy, hMaskListDC, pt.x, pt.y, 0x220326); /* NOTSRCAND */
1399 BitBlt(hBlendMaskDC, 0, 0, cx, cy, hBlendMaskDC, 0, 0, NOTSRCCOPY);
1402 /* now apply blend to the current image given the BlendMask */
1403 if (clrBlend == CLR_DEFAULT) clrBlend = GetSysColor (COLOR_HIGHLIGHT);
1404 else if (clrBlend == CLR_NONE) clrBlend = GetTextColor (pimldp->hdcDst);
1405 hOldBrush = SelectObject (hImageDC, CreateSolidBrush(clrBlend));
1406 BitBlt (hImageDC, 0, 0, cx, cy, hBlendMaskDC, 0, 0, 0xB8074A); /* PSDPxax */
1407 DeleteObject(SelectObject(hImageDC, hOldBrush));
1408 SelectObject(hBlendMaskDC, hOldBitmap);
1411 /* Now do the overlay image, if any */
1412 nOvlIdx = (pimldp->fStyle & ILD_OVERLAYMASK) >> 8;
1413 if ( (nOvlIdx >= 1) && (nOvlIdx <= MAX_OVERLAYIMAGE)) {
1414 nOvlIdx = himl->nOvlIdx[nOvlIdx - 1];
1415 if ((nOvlIdx >= 0) && (nOvlIdx < himl->cCurImage)) {
1417 imagelist_point_from_index( himl, nOvlIdx, &ptOvl );
1418 ptOvl.x += pimldp->xBitmap;
1419 if (himl->hbmMask && !(fStyle & ILD_IMAGE))
1420 BitBlt (hImageDC, 0, 0, cx, cy, hMaskListDC, ptOvl.x, ptOvl.y, SRCAND);
1421 BitBlt (hImageDC, 0, 0, cx, cy, hImageListDC, ptOvl.x, ptOvl.y, SRCPAINT);
1425 if (fState & ILS_SATURATE) FIXME("ILS_SATURATE: unimplemented!\n");
1426 if (fState & ILS_GLOW) FIXME("ILS_GLOW: unimplemented!\n");
1427 if (fState & ILS_SHADOW) FIXME("ILS_SHADOW: unimplemented!\n");
1429 if (fStyle & ILD_PRESERVEALPHA) FIXME("ILD_PRESERVEALPHA: unimplemented!\n");
1430 if (fStyle & ILD_SCALE) FIXME("ILD_SCALE: unimplemented!\n");
1431 if (fStyle & ILD_DPISCALE) FIXME("ILD_DPISCALE: unimplemented!\n");
1433 /* now copy the image to the screen */
1435 if (himl->hbmMask && bIsTransparent ) {
1436 COLORREF oldDstFg = SetTextColor(pimldp->hdcDst, RGB( 0, 0, 0 ) );
1437 COLORREF oldDstBk = SetBkColor(pimldp->hdcDst, RGB( 0xff, 0xff, 0xff ));
1438 BitBlt (pimldp->hdcDst, pimldp->x, pimldp->y, cx, cy, hMaskListDC, pt.x, pt.y, SRCAND);
1439 SetBkColor(pimldp->hdcDst, oldDstBk);
1440 SetTextColor(pimldp->hdcDst, oldDstFg);
1443 if (fStyle & ILD_ROP) dwRop = pimldp->dwRop;
1444 BitBlt (pimldp->hdcDst, pimldp->x, pimldp->y, cx, cy, hImageDC, 0, 0, dwRop);
1448 /* cleanup the mess */
1449 SetBkColor(hImageDC, oldImageBk);
1450 SetTextColor(hImageDC, oldImageFg);
1451 SelectObject(hImageDC, hOldImageBmp);
1453 DeleteObject(hBlendMaskBmp);
1454 DeleteObject(hImageBmp);
1461 /*************************************************************************
1462 * ImageList_Duplicate [COMCTL32.@]
1464 * Duplicates an image list.
1467 * himlSrc [I] source image list handle
1470 * Success: Handle of duplicated image list.
1475 ImageList_Duplicate (HIMAGELIST himlSrc)
1479 if (!is_valid(himlSrc)) {
1480 ERR("Invalid image list handle!\n");
1484 himlDst = ImageList_Create (himlSrc->cx, himlSrc->cy, himlSrc->flags,
1485 himlSrc->cCurImage, himlSrc->cGrow);
1491 imagelist_get_bitmap_size(himlSrc, himlSrc->cCurImage, &sz);
1492 BitBlt (himlDst->hdcImage, 0, 0, sz.cx, sz.cy,
1493 himlSrc->hdcImage, 0, 0, SRCCOPY);
1495 if (himlDst->hbmMask)
1496 BitBlt (himlDst->hdcMask, 0, 0, sz.cx, sz.cy,
1497 himlSrc->hdcMask, 0, 0, SRCCOPY);
1499 himlDst->cCurImage = himlSrc->cCurImage;
1500 himlDst->cMaxImage = himlSrc->cMaxImage;
1501 if (himlSrc->has_alpha && himlDst->has_alpha)
1502 memcpy( himlDst->has_alpha, himlSrc->has_alpha, himlDst->cCurImage );
1508 /*************************************************************************
1509 * ImageList_EndDrag [COMCTL32.@]
1511 * Finishes a drag operation.
1522 ImageList_EndDrag (void)
1524 /* cleanup the InternalDrag struct */
1525 InternalDrag.hwnd = 0;
1526 ImageList_Destroy (InternalDrag.himl);
1527 InternalDrag.himl = 0;
1530 InternalDrag.dxHotspot = 0;
1531 InternalDrag.dyHotspot = 0;
1532 InternalDrag.bShow = FALSE;
1533 DeleteObject(InternalDrag.hbmBg);
1534 InternalDrag.hbmBg = 0;
1538 /*************************************************************************
1539 * ImageList_GetBkColor [COMCTL32.@]
1541 * Returns the background color of an image list.
1544 * himl [I] Image list handle.
1547 * Success: background color
1552 ImageList_GetBkColor (HIMAGELIST himl)
1554 return himl ? himl->clrBk : CLR_NONE;
1558 /*************************************************************************
1559 * ImageList_GetDragImage [COMCTL32.@]
1561 * Returns the handle to the internal drag image list.
1564 * ppt [O] Pointer to the drag position. Can be NULL.
1565 * pptHotspot [O] Pointer to the position of the hot spot. Can be NULL.
1568 * Success: Handle of the drag image list.
1573 ImageList_GetDragImage (POINT *ppt, POINT *pptHotspot)
1575 if (is_valid(InternalDrag.himl)) {
1577 ppt->x = InternalDrag.x;
1578 ppt->y = InternalDrag.y;
1581 pptHotspot->x = InternalDrag.dxHotspot;
1582 pptHotspot->y = InternalDrag.dyHotspot;
1584 return (InternalDrag.himl);
1591 /*************************************************************************
1592 * ImageList_GetFlags [COMCTL32.@]
1594 * Gets the flags of the specified image list.
1597 * himl [I] Handle to image list
1607 ImageList_GetFlags(HIMAGELIST himl)
1609 TRACE("%p\n", himl);
1611 return is_valid(himl) ? himl->flags : 0;
1615 /*************************************************************************
1616 * ImageList_GetIcon [COMCTL32.@]
1618 * Creates an icon from a masked image of an image list.
1621 * himl [I] handle to image list
1623 * flags [I] drawing style flags
1626 * Success: icon handle
1631 ImageList_GetIcon (HIMAGELIST himl, INT i, UINT fStyle)
1635 HBITMAP hOldDstBitmap;
1639 TRACE("%p %d %d\n", himl, i, fStyle);
1640 if (!is_valid(himl) || (i < 0) || (i >= himl->cCurImage)) return NULL;
1646 /* create colour bitmap */
1648 ii.hbmColor = CreateCompatibleBitmap(hdcDst, himl->cx, himl->cy);
1649 ReleaseDC(0, hdcDst);
1651 hdcDst = CreateCompatibleDC(0);
1653 imagelist_point_from_index( himl, i, &pt );
1656 ii.hbmMask = CreateBitmap (himl->cx, himl->cy, 1, 1, NULL);
1657 hOldDstBitmap = SelectObject (hdcDst, ii.hbmMask);
1658 if (himl->hbmMask) {
1659 BitBlt (hdcDst, 0, 0, himl->cx, himl->cy,
1660 himl->hdcMask, pt.x, pt.y, SRCCOPY);
1663 PatBlt (hdcDst, 0, 0, himl->cx, himl->cy, BLACKNESS);
1666 SelectObject (hdcDst, ii.hbmColor);
1667 BitBlt (hdcDst, 0, 0, himl->cx, himl->cy,
1668 himl->hdcImage, pt.x, pt.y, SRCCOPY);
1671 * CreateIconIndirect requires us to deselect the bitmaps from
1672 * the DCs before calling
1674 SelectObject(hdcDst, hOldDstBitmap);
1676 hIcon = CreateIconIndirect (&ii);
1678 DeleteObject (ii.hbmMask);
1679 DeleteObject (ii.hbmColor);
1686 /*************************************************************************
1687 * ImageList_GetIconSize [COMCTL32.@]
1689 * Retrieves the size of an image in an image list.
1692 * himl [I] handle to image list
1693 * cx [O] pointer to the image width.
1694 * cy [O] pointer to the image height.
1701 * All images in an image list have the same size.
1705 ImageList_GetIconSize (HIMAGELIST himl, INT *cx, INT *cy)
1707 if (!is_valid(himl))
1709 if ((himl->cx <= 0) || (himl->cy <= 0))
1721 /*************************************************************************
1722 * ImageList_GetImageCount [COMCTL32.@]
1724 * Returns the number of images in an image list.
1727 * himl [I] handle to image list
1730 * Success: Number of images.
1735 ImageList_GetImageCount (HIMAGELIST himl)
1737 if (!is_valid(himl))
1740 return himl->cCurImage;
1744 /*************************************************************************
1745 * ImageList_GetImageInfo [COMCTL32.@]
1747 * Returns information about an image in an image list.
1750 * himl [I] handle to image list
1752 * pImageInfo [O] pointer to the image information
1760 ImageList_GetImageInfo (HIMAGELIST himl, INT i, IMAGEINFO *pImageInfo)
1764 if (!is_valid(himl) || (pImageInfo == NULL))
1766 if ((i < 0) || (i >= himl->cCurImage))
1769 pImageInfo->hbmImage = himl->hbmImage;
1770 pImageInfo->hbmMask = himl->hbmMask;
1772 imagelist_point_from_index( himl, i, &pt );
1773 pImageInfo->rcImage.top = pt.y;
1774 pImageInfo->rcImage.bottom = pt.y + himl->cy;
1775 pImageInfo->rcImage.left = pt.x;
1776 pImageInfo->rcImage.right = pt.x + himl->cx;
1782 /*************************************************************************
1783 * ImageList_GetImageRect [COMCTL32.@]
1785 * Retrieves the rectangle of the specified image in an image list.
1788 * himl [I] handle to image list
1790 * lpRect [O] pointer to the image rectangle
1797 * This is an UNDOCUMENTED function!!!
1801 ImageList_GetImageRect (HIMAGELIST himl, INT i, LPRECT lpRect)
1805 if (!is_valid(himl) || (lpRect == NULL))
1807 if ((i < 0) || (i >= himl->cCurImage))
1810 imagelist_point_from_index( himl, i, &pt );
1811 lpRect->left = pt.x;
1813 lpRect->right = pt.x + himl->cx;
1814 lpRect->bottom = pt.y + himl->cy;
1820 /*************************************************************************
1821 * ImageList_LoadImage [COMCTL32.@]
1822 * ImageList_LoadImageA [COMCTL32.@]
1824 * Creates an image list from a bitmap, icon or cursor.
1826 * See ImageList_LoadImageW.
1830 ImageList_LoadImageA (HINSTANCE hi, LPCSTR lpbmp, INT cx, INT cGrow,
1831 COLORREF clrMask, UINT uType, UINT uFlags)
1837 if (IS_INTRESOURCE(lpbmp))
1838 return ImageList_LoadImageW(hi, (LPCWSTR)lpbmp, cx, cGrow, clrMask,
1841 len = MultiByteToWideChar(CP_ACP, 0, lpbmp, -1, NULL, 0);
1842 lpbmpW = Alloc(len * sizeof(WCHAR));
1843 MultiByteToWideChar(CP_ACP, 0, lpbmp, -1, lpbmpW, len);
1845 himl = ImageList_LoadImageW(hi, lpbmpW, cx, cGrow, clrMask, uType, uFlags);
1851 /*************************************************************************
1852 * ImageList_LoadImageW [COMCTL32.@]
1854 * Creates an image list from a bitmap, icon or cursor.
1857 * hi [I] instance handle
1858 * lpbmp [I] name or id of the image
1859 * cx [I] width of each image
1860 * cGrow [I] number of images to expand
1861 * clrMask [I] mask color
1862 * uType [I] type of image to load
1863 * uFlags [I] loading flags
1866 * Success: handle to the loaded image list
1874 ImageList_LoadImageW (HINSTANCE hi, LPCWSTR lpbmp, INT cx, INT cGrow,
1875 COLORREF clrMask, UINT uType, UINT uFlags)
1877 HIMAGELIST himl = NULL;
1881 handle = LoadImageW (hi, lpbmp, uType, 0, 0, uFlags);
1883 WARN("Couldn't load image\n");
1887 if (uType == IMAGE_BITMAP) {
1889 GetObjectW (handle, sizeof(BITMAP), &bmp);
1891 /* To match windows behavior, if cx is set to zero and
1892 the flag DI_DEFAULTSIZE is specified, cx becomes the
1893 system metric value for icons. If the flag is not specified
1894 the function sets the size to the height of the bitmap */
1897 if (uFlags & DI_DEFAULTSIZE)
1898 cx = GetSystemMetrics (SM_CXICON);
1903 nImageCount = bmp.bmWidth / cx;
1905 himl = ImageList_Create (cx, bmp.bmHeight, ILC_MASK | ILC_COLOR,
1906 nImageCount, cGrow);
1908 DeleteObject (handle);
1911 ImageList_AddMasked (himl, handle, clrMask);
1913 else if ((uType == IMAGE_ICON) || (uType == IMAGE_CURSOR)) {
1917 GetIconInfo (handle, &ii);
1918 GetObjectW (ii.hbmColor, sizeof(BITMAP), &bmp);
1919 himl = ImageList_Create (bmp.bmWidth, bmp.bmHeight,
1920 ILC_MASK | ILC_COLOR, 1, cGrow);
1922 DeleteObject (ii.hbmColor);
1923 DeleteObject (ii.hbmMask);
1924 DeleteObject (handle);
1927 ImageList_Add (himl, ii.hbmColor, ii.hbmMask);
1928 DeleteObject (ii.hbmColor);
1929 DeleteObject (ii.hbmMask);
1932 DeleteObject (handle);
1938 /*************************************************************************
1939 * ImageList_Merge [COMCTL32.@]
1941 * Create an image list containing a merged image from two image lists.
1944 * himl1 [I] handle to first image list
1945 * i1 [I] first image index
1946 * himl2 [I] handle to second image list
1947 * i2 [I] second image index
1948 * dx [I] X offset of the second image relative to the first.
1949 * dy [I] Y offset of the second image relative to the first.
1952 * Success: The newly created image list. It contains a single image
1953 * consisting of the second image merged with the first.
1954 * Failure: NULL, if either himl1 or himl2 are invalid.
1957 * - The returned image list should be deleted by the caller using
1958 * ImageList_Destroy() when it is no longer required.
1959 * - If either i1 or i2 are not valid image indices they will be treated
1963 ImageList_Merge (HIMAGELIST himl1, INT i1, HIMAGELIST himl2, INT i2,
1966 HIMAGELIST himlDst = NULL;
1968 INT xOff1, yOff1, xOff2, yOff2;
1971 TRACE("(himl1=%p i1=%d himl2=%p i2=%d dx=%d dy=%d)\n", himl1, i1, himl2,
1974 if (!is_valid(himl1) || !is_valid(himl2))
1978 cxDst = max (himl1->cx, dx + himl2->cx);
1983 cxDst = max (himl2->cx, himl1->cx - dx);
1988 cxDst = max (himl1->cx, himl2->cx);
1994 cyDst = max (himl1->cy, dy + himl2->cy);
1999 cyDst = max (himl2->cy, himl1->cy - dy);
2004 cyDst = max (himl1->cy, himl2->cy);
2009 himlDst = ImageList_Create (cxDst, cyDst, ILC_MASK | ILC_COLOR, 1, 1);
2013 imagelist_point_from_index( himl1, i1, &pt1 );
2014 imagelist_point_from_index( himl1, i2, &pt2 );
2017 BitBlt (himlDst->hdcImage, 0, 0, cxDst, cyDst, himl1->hdcImage, 0, 0, BLACKNESS);
2018 if (i1 >= 0 && i1 < himl1->cCurImage)
2019 BitBlt (himlDst->hdcImage, xOff1, yOff1, himl1->cx, himl1->cy, himl1->hdcImage, pt1.x, pt1.y, SRCCOPY);
2020 if (i2 >= 0 && i2 < himl2->cCurImage)
2022 BitBlt (himlDst->hdcImage, xOff2, yOff2, himl2->cx, himl2->cy, himl2->hdcMask , pt2.x, pt2.y, SRCAND);
2023 BitBlt (himlDst->hdcImage, xOff2, yOff2, himl2->cx, himl2->cy, himl2->hdcImage, pt2.x, pt2.y, SRCPAINT);
2027 BitBlt (himlDst->hdcMask, 0, 0, cxDst, cyDst, himl1->hdcMask, 0, 0, WHITENESS);
2028 if (i1 >= 0 && i1 < himl1->cCurImage)
2029 BitBlt (himlDst->hdcMask, xOff1, yOff1, himl1->cx, himl1->cy, himl1->hdcMask, pt1.x, pt1.y, SRCCOPY);
2030 if (i2 >= 0 && i2 < himl2->cCurImage)
2031 BitBlt (himlDst->hdcMask, xOff2, yOff2, himl2->cx, himl2->cy, himl2->hdcMask, pt2.x, pt2.y, SRCAND);
2033 himlDst->cCurImage = 1;
2040 /***********************************************************************
2041 * DIB_GetDIBWidthBytes
2043 * Return the width of a DIB bitmap in bytes. DIB bitmap data is 32-bit aligned.
2045 static int DIB_GetDIBWidthBytes( int width, int depth )
2051 case 1: words = (width + 31) / 32; break;
2052 case 4: words = (width + 7) / 8; break;
2053 case 8: words = (width + 3) / 4; break;
2055 case 16: words = (width + 1) / 2; break;
2056 case 24: words = (width * 3 + 3)/4; break;
2059 WARN("(%d): Unsupported depth\n", depth );
2068 /***********************************************************************
2069 * DIB_GetDIBImageBytes
2071 * Return the number of bytes used to hold the image in a DIB bitmap.
2073 static int DIB_GetDIBImageBytes( int width, int height, int depth )
2075 return DIB_GetDIBWidthBytes( width, depth ) * abs( height );
2079 /* helper for ImageList_Read, see comments below */
2080 static BOOL _read_bitmap(HDC hdcIml, LPSTREAM pstm)
2082 BITMAPFILEHEADER bmfh;
2083 int bitsperpixel, palspace;
2084 char bmi_buf[sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD) * 256];
2085 LPBITMAPINFO bmi = (LPBITMAPINFO)bmi_buf;
2089 if (FAILED(IStream_Read ( pstm, &bmfh, sizeof(bmfh), NULL)))
2092 if (bmfh.bfType != (('M'<<8)|'B'))
2095 if (FAILED(IStream_Read ( pstm, &bmi->bmiHeader, sizeof(bmi->bmiHeader), NULL)))
2098 if ((bmi->bmiHeader.biSize != sizeof(bmi->bmiHeader)))
2101 TRACE("width %u, height %u, planes %u, bpp %u\n",
2102 bmi->bmiHeader.biWidth, bmi->bmiHeader.biHeight,
2103 bmi->bmiHeader.biPlanes, bmi->bmiHeader.biBitCount);
2105 bitsperpixel = bmi->bmiHeader.biPlanes * bmi->bmiHeader.biBitCount;
2106 if (bitsperpixel<=8)
2107 palspace = (1<<bitsperpixel)*sizeof(RGBQUAD);
2111 bmi->bmiHeader.biSizeImage = DIB_GetDIBImageBytes(bmi->bmiHeader.biWidth, bmi->bmiHeader.biHeight, bitsperpixel);
2113 /* read the palette right after the end of the bitmapinfoheader */
2114 if (palspace && FAILED(IStream_Read(pstm, bmi->bmiColors, palspace, NULL)))
2117 bits = Alloc(bmi->bmiHeader.biSizeImage);
2120 if (FAILED(IStream_Read(pstm, bits, bmi->bmiHeader.biSizeImage, NULL)))
2123 if (!StretchDIBits(hdcIml, 0, 0, bmi->bmiHeader.biWidth, bmi->bmiHeader.biHeight,
2124 0, 0, bmi->bmiHeader.biWidth, bmi->bmiHeader.biHeight,
2125 bits, bmi, DIB_RGB_COLORS, SRCCOPY))
2134 /*************************************************************************
2135 * ImageList_Read [COMCTL32.@]
2137 * Reads an image list from a stream.
2140 * pstm [I] pointer to a stream
2143 * Success: handle to image list
2146 * The format is like this:
2147 * ILHEAD ilheadstruct;
2149 * for the color image part:
2150 * BITMAPFILEHEADER bmfh;
2151 * BITMAPINFOHEADER bmih;
2152 * only if it has a palette:
2153 * RGBQUAD rgbs[nr_of_paletted_colors];
2155 * BYTE colorbits[imagesize];
2157 * the following only if the ILC_MASK bit is set in ILHEAD.ilFlags:
2158 * BITMAPFILEHEADER bmfh_mask;
2159 * BITMAPINFOHEADER bmih_mask;
2160 * only if it has a palette (it usually does not):
2161 * RGBQUAD rgbs[nr_of_paletted_colors];
2163 * BYTE maskbits[imagesize];
2165 HIMAGELIST WINAPI ImageList_Read (LPSTREAM pstm)
2171 TRACE("%p\n", pstm);
2173 if (FAILED(IStream_Read (pstm, &ilHead, sizeof(ILHEAD), NULL)))
2175 if (ilHead.usMagic != (('L' << 8) | 'I'))
2177 if (ilHead.usVersion != 0x101) /* probably version? */
2180 TRACE("cx %u, cy %u, flags 0x%04x, cCurImage %u, cMaxImage %u\n",
2181 ilHead.cx, ilHead.cy, ilHead.flags, ilHead.cCurImage, ilHead.cMaxImage);
2183 himl = ImageList_Create(ilHead.cx, ilHead.cy, ilHead.flags, ilHead.cCurImage, ilHead.cMaxImage);
2187 if (!_read_bitmap(himl->hdcImage, pstm))
2189 WARN("failed to read bitmap from stream\n");
2192 if (ilHead.flags & ILC_MASK)
2194 if (!_read_bitmap(himl->hdcMask, pstm))
2196 WARN("failed to read mask bitmap from stream\n");
2201 himl->cCurImage = ilHead.cCurImage;
2202 himl->cMaxImage = ilHead.cMaxImage;
2204 ImageList_SetBkColor(himl,ilHead.bkcolor);
2206 ImageList_SetOverlayImage(himl,ilHead.ovls[i],i+1);
2211 /*************************************************************************
2212 * ImageList_Remove [COMCTL32.@]
2214 * Removes an image from an image list
2217 * himl [I] image list handle
2224 * FIXME: as the image list storage test shows, native comctl32 simply shifts
2225 * images without creating a new bitmap.
2228 ImageList_Remove (HIMAGELIST himl, INT i)
2230 HBITMAP hbmNewImage, hbmNewMask;
2234 TRACE("(himl=%p i=%d)\n", himl, i);
2236 if (!is_valid(himl)) {
2237 ERR("Invalid image list handle!\n");
2241 if ((i < -1) || (i >= himl->cCurImage)) {
2242 TRACE("index out of range! %d\n", i);
2250 if (himl->cCurImage == 0) {
2251 /* remove all on empty ImageList is allowed */
2252 TRACE("remove all on empty ImageList!\n");
2256 himl->cMaxImage = himl->cInitial + himl->cGrow - 1;
2257 himl->cCurImage = 0;
2258 for (nCount = 0; nCount < MAX_OVERLAYIMAGE; nCount++)
2259 himl->nOvlIdx[nCount] = -1;
2261 hbmNewImage = ImageList_CreateImage(himl->hdcImage, himl, himl->cMaxImage);
2262 SelectObject (himl->hdcImage, hbmNewImage);
2263 DeleteObject (himl->hbmImage);
2264 himl->hbmImage = hbmNewImage;
2266 if (himl->hbmMask) {
2268 imagelist_get_bitmap_size(himl, himl->cMaxImage, &sz);
2269 hbmNewMask = CreateBitmap (sz.cx, sz.cy, 1, 1, NULL);
2270 SelectObject (himl->hdcMask, hbmNewMask);
2271 DeleteObject (himl->hbmMask);
2272 himl->hbmMask = hbmNewMask;
2276 /* delete one image */
2277 TRACE("Remove single image! %d\n", i);
2279 /* create new bitmap(s) */
2280 TRACE(" - Number of images: %d / %d (Old/New)\n",
2281 himl->cCurImage, himl->cCurImage - 1);
2283 hbmNewImage = ImageList_CreateImage(himl->hdcImage, himl, himl->cMaxImage);
2285 imagelist_get_bitmap_size(himl, himl->cMaxImage, &sz );
2287 hbmNewMask = CreateBitmap (sz.cx, sz.cy, 1, 1, NULL);
2289 hbmNewMask = 0; /* Just to keep compiler happy! */
2291 hdcBmp = CreateCompatibleDC (0);
2293 /* copy all images and masks prior to the "removed" image */
2295 TRACE("Pre image copy: Copy %d images\n", i);
2297 SelectObject (hdcBmp, hbmNewImage);
2298 imagelist_copy_images( himl, himl->hdcImage, hdcBmp, 0, i, 0 );
2300 if (himl->hbmMask) {
2301 SelectObject (hdcBmp, hbmNewMask);
2302 imagelist_copy_images( himl, himl->hdcMask, hdcBmp, 0, i, 0 );
2306 /* copy all images and masks behind the removed image */
2307 if (i < himl->cCurImage - 1) {
2308 TRACE("Post image copy!\n");
2310 SelectObject (hdcBmp, hbmNewImage);
2311 imagelist_copy_images( himl, himl->hdcImage, hdcBmp, i + 1,
2312 (himl->cCurImage - i), i );
2314 if (himl->hbmMask) {
2315 SelectObject (hdcBmp, hbmNewMask);
2316 imagelist_copy_images( himl, himl->hdcMask, hdcBmp, i + 1,
2317 (himl->cCurImage - i), i );
2323 /* delete old images and insert new ones */
2324 SelectObject (himl->hdcImage, hbmNewImage);
2325 DeleteObject (himl->hbmImage);
2326 himl->hbmImage = hbmNewImage;
2327 if (himl->hbmMask) {
2328 SelectObject (himl->hdcMask, hbmNewMask);
2329 DeleteObject (himl->hbmMask);
2330 himl->hbmMask = hbmNewMask;
2340 /*************************************************************************
2341 * ImageList_Replace [COMCTL32.@]
2343 * Replaces an image in an image list with a new image.
2346 * himl [I] handle to image list
2348 * hbmImage [I] handle to image bitmap
2349 * hbmMask [I] handle to mask bitmap. Can be NULL.
2357 ImageList_Replace (HIMAGELIST himl, INT i, HBITMAP hbmImage,
2364 TRACE("%p %d %p %p\n", himl, i, hbmImage, hbmMask);
2366 if (!is_valid(himl)) {
2367 ERR("Invalid image list handle!\n");
2371 if ((i >= himl->cMaxImage) || (i < 0)) {
2372 ERR("Invalid image index!\n");
2376 if (!GetObjectW(hbmImage, sizeof(BITMAP), &bmp))
2379 hdcImage = CreateCompatibleDC (0);
2382 SelectObject (hdcImage, hbmImage);
2384 if (add_with_alpha( himl, hdcImage, i, 1, bmp.bmWidth, bmp.bmHeight, hbmImage, hbmMask ))
2387 imagelist_point_from_index(himl, i, &pt);
2388 StretchBlt (himl->hdcImage, pt.x, pt.y, himl->cx, himl->cy,
2389 hdcImage, 0, 0, bmp.bmWidth, bmp.bmHeight, SRCCOPY);
2394 HBITMAP hOldBitmapTemp;
2396 hdcTemp = CreateCompatibleDC(0);
2397 hOldBitmapTemp = SelectObject(hdcTemp, hbmMask);
2399 StretchBlt (himl->hdcMask, pt.x, pt.y, himl->cx, himl->cy,
2400 hdcTemp, 0, 0, bmp.bmWidth, bmp.bmHeight, SRCCOPY);
2401 SelectObject(hdcTemp, hOldBitmapTemp);
2404 /* Remove the background from the image
2406 BitBlt (himl->hdcImage, pt.x, pt.y, bmp.bmWidth, bmp.bmHeight,
2407 himl->hdcMask, pt.x, pt.y, 0x220326); /* NOTSRCAND */
2411 DeleteDC (hdcImage);
2417 /*************************************************************************
2418 * ImageList_ReplaceIcon [COMCTL32.@]
2420 * Replaces an image in an image list using an icon.
2423 * himl [I] handle to image list
2425 * hIcon [I] handle to icon
2428 * Success: index of the replaced image
2433 ImageList_ReplaceIcon (HIMAGELIST himl, INT nIndex, HICON hIcon)
2442 TRACE("(%p %d %p)\n", himl, nIndex, hIcon);
2444 if (!is_valid(himl)) {
2445 ERR("invalid image list\n");
2448 if ((nIndex >= himl->cMaxImage) || (nIndex < -1)) {
2449 ERR("invalid image index %d / %d\n", nIndex, himl->cMaxImage);
2453 hBestFitIcon = CopyImage(
2456 LR_COPYFROMRESOURCE);
2457 /* the above will fail if the icon wasn't loaded from a resource, so try
2458 * again without LR_COPYFROMRESOURCE flag */
2460 hBestFitIcon = CopyImage(
2467 ret = GetIconInfo (hBestFitIcon, &ii);
2469 DestroyIcon(hBestFitIcon);
2473 ret = GetObjectW (ii.hbmMask, sizeof(BITMAP), &bmp);
2475 ERR("couldn't get mask bitmap info\n");
2477 DeleteObject (ii.hbmColor);
2479 DeleteObject (ii.hbmMask);
2480 DestroyIcon(hBestFitIcon);
2485 if (himl->cCurImage + 1 > himl->cMaxImage)
2486 IMAGELIST_InternalExpandBitmaps(himl, 1);
2488 nIndex = himl->cCurImage;
2492 hdcImage = CreateCompatibleDC (0);
2493 TRACE("hdcImage=%p\n", hdcImage);
2495 ERR("invalid hdcImage!\n");
2497 if (himl->uBitsPixel == 32)
2501 UINT height = bmp.bmHeight / 2;
2502 HDC hdcMask = CreateCompatibleDC( 0 );
2503 HBITMAP color = CreateBitmap( bmp.bmWidth, height, 1, 1, NULL );
2504 SelectObject( hdcImage, color );
2505 SelectObject( hdcMask, ii.hbmMask );
2506 BitBlt( hdcImage, 0, 0, bmp.bmWidth, height, hdcMask, 0, height, SRCCOPY );
2507 add_with_alpha( himl, hdcImage, nIndex, 1, bmp.bmWidth, height, color, ii.hbmMask );
2508 DeleteDC( hdcMask );
2509 DeleteObject( color );
2511 else add_with_alpha( himl, hdcImage, nIndex, 1, bmp.bmWidth, bmp.bmHeight, ii.hbmColor, ii.hbmMask );
2516 imagelist_point_from_index(himl, nIndex, &pt);
2518 SetTextColor(himl->hdcImage, RGB(0,0,0));
2519 SetBkColor (himl->hdcImage, RGB(255,255,255));
2523 SelectObject (hdcImage, ii.hbmColor);
2524 StretchBlt (himl->hdcImage, pt.x, pt.y, himl->cx, himl->cy,
2525 hdcImage, 0, 0, bmp.bmWidth, bmp.bmHeight, SRCCOPY);
2528 SelectObject (hdcImage, ii.hbmMask);
2529 StretchBlt (himl->hdcMask, pt.x, pt.y, himl->cx, himl->cy,
2530 hdcImage, 0, 0, bmp.bmWidth, bmp.bmHeight, SRCCOPY);
2535 UINT height = bmp.bmHeight / 2;
2536 SelectObject (hdcImage, ii.hbmMask);
2537 StretchBlt (himl->hdcImage, pt.x, pt.y, himl->cx, himl->cy,
2538 hdcImage, 0, height, bmp.bmWidth, height, SRCCOPY);
2540 StretchBlt (himl->hdcMask, pt.x, pt.y, himl->cx, himl->cy,
2541 hdcImage, 0, 0, bmp.bmWidth, height, SRCCOPY);
2545 DestroyIcon(hBestFitIcon);
2547 DeleteDC (hdcImage);
2549 DeleteObject (ii.hbmColor);
2551 DeleteObject (ii.hbmMask);
2553 TRACE("Insert index = %d, himl->cCurImage = %d\n", nIndex, himl->cCurImage);
2558 /*************************************************************************
2559 * ImageList_SetBkColor [COMCTL32.@]
2561 * Sets the background color of an image list.
2564 * himl [I] handle to image list
2565 * clrBk [I] background color
2568 * Success: previous background color
2573 ImageList_SetBkColor (HIMAGELIST himl, COLORREF clrBk)
2577 if (!is_valid(himl))
2580 clrOldBk = himl->clrBk;
2581 himl->clrBk = clrBk;
2586 /*************************************************************************
2587 * ImageList_SetDragCursorImage [COMCTL32.@]
2589 * Combines the specified image with the current drag image
2592 * himlDrag [I] handle to drag image list
2593 * iDrag [I] drag image index
2594 * dxHotspot [I] X position of the hot spot
2595 * dyHotspot [I] Y position of the hot spot
2602 * - The names dxHotspot, dyHotspot are misleading because they have nothing
2603 * to do with a hotspot but are only the offset of the origin of the new
2604 * image relative to the origin of the old image.
2606 * - When this function is called and the drag image is visible, a
2607 * short flickering occurs but this matches the Win9x behavior. It is
2608 * possible to fix the flickering using code like in ImageList_DragMove.
2612 ImageList_SetDragCursorImage (HIMAGELIST himlDrag, INT iDrag,
2613 INT dxHotspot, INT dyHotspot)
2615 HIMAGELIST himlTemp;
2618 if (!is_valid(InternalDrag.himl) || !is_valid(himlDrag))
2621 TRACE(" dxH=%d dyH=%d nX=%d nY=%d\n",
2622 dxHotspot, dyHotspot, InternalDrag.dxHotspot, InternalDrag.dyHotspot);
2624 visible = InternalDrag.bShow;
2626 himlTemp = ImageList_Merge (InternalDrag.himl, 0, himlDrag, iDrag,
2627 dxHotspot, dyHotspot);
2630 /* hide the drag image */
2631 ImageList_DragShowNolock(FALSE);
2633 if ((InternalDrag.himl->cx != himlTemp->cx) ||
2634 (InternalDrag.himl->cy != himlTemp->cy)) {
2635 /* the size of the drag image changed, invalidate the buffer */
2636 DeleteObject(InternalDrag.hbmBg);
2637 InternalDrag.hbmBg = 0;
2640 ImageList_Destroy (InternalDrag.himl);
2641 InternalDrag.himl = himlTemp;
2644 /* show the drag image */
2645 ImageList_DragShowNolock(TRUE);
2652 /*************************************************************************
2653 * ImageList_SetFilter [COMCTL32.@]
2655 * Sets a filter (or does something completely different)!!???
2656 * It removes 12 Bytes from the stack (3 Parameters).
2659 * himl [I] SHOULD be a handle to image list
2660 * i [I] COULD be an index?
2665 * Failure: FALSE ???
2668 * This is an UNDOCUMENTED function!!!!
2673 ImageList_SetFilter (HIMAGELIST himl, INT i, DWORD dwFilter)
2675 FIXME("(%p 0x%x 0x%x):empty stub!\n", himl, i, dwFilter);
2681 /*************************************************************************
2682 * ImageList_SetFlags [COMCTL32.@]
2684 * Sets the image list flags.
2687 * himl [I] Handle to image list
2688 * flags [I] Flags to set
2698 ImageList_SetFlags(HIMAGELIST himl, DWORD flags)
2700 FIXME("(%p %08x):empty stub\n", himl, flags);
2705 /*************************************************************************
2706 * ImageList_SetIconSize [COMCTL32.@]
2708 * Sets the image size of the bitmap and deletes all images.
2711 * himl [I] handle to image list
2712 * cx [I] image width
2713 * cy [I] image height
2721 ImageList_SetIconSize (HIMAGELIST himl, INT cx, INT cy)
2726 if (!is_valid(himl))
2729 /* remove all images */
2730 himl->cMaxImage = himl->cInitial + 1;
2731 himl->cCurImage = 0;
2735 /* initialize overlay mask indices */
2736 for (nCount = 0; nCount < MAX_OVERLAYIMAGE; nCount++)
2737 himl->nOvlIdx[nCount] = -1;
2739 hbmNew = ImageList_CreateImage(himl->hdcImage, himl, himl->cMaxImage);
2740 SelectObject (himl->hdcImage, hbmNew);
2741 DeleteObject (himl->hbmImage);
2742 himl->hbmImage = hbmNew;
2744 if (himl->hbmMask) {
2746 imagelist_get_bitmap_size(himl, himl->cMaxImage, &sz);
2747 hbmNew = CreateBitmap (sz.cx, sz.cy, 1, 1, NULL);
2748 SelectObject (himl->hdcMask, hbmNew);
2749 DeleteObject (himl->hbmMask);
2750 himl->hbmMask = hbmNew;
2757 /*************************************************************************
2758 * ImageList_SetImageCount [COMCTL32.@]
2760 * Resizes an image list to the specified number of images.
2763 * himl [I] handle to image list
2764 * iImageCount [I] number of images in the image list
2772 ImageList_SetImageCount (HIMAGELIST himl, UINT iImageCount)
2775 HBITMAP hbmNewBitmap, hbmOld;
2776 INT nNewCount, nCopyCount;
2778 TRACE("%p %d\n",himl,iImageCount);
2780 if (!is_valid(himl))
2782 if (himl->cMaxImage > iImageCount)
2784 himl->cCurImage = iImageCount;
2785 /* TODO: shrink the bitmap when cMaxImage-cCurImage>cGrow ? */
2789 nNewCount = iImageCount + himl->cGrow;
2790 nCopyCount = min(himl->cCurImage, iImageCount);
2792 hdcBitmap = CreateCompatibleDC (0);
2794 hbmNewBitmap = ImageList_CreateImage(hdcBitmap, himl, nNewCount);
2796 if (hbmNewBitmap != 0)
2798 hbmOld = SelectObject (hdcBitmap, hbmNewBitmap);
2799 imagelist_copy_images( himl, himl->hdcImage, hdcBitmap, 0, nCopyCount, 0 );
2800 SelectObject (hdcBitmap, hbmOld);
2802 /* FIXME: delete 'empty' image space? */
2804 SelectObject (himl->hdcImage, hbmNewBitmap);
2805 DeleteObject (himl->hbmImage);
2806 himl->hbmImage = hbmNewBitmap;
2809 ERR("Could not create new image bitmap !\n");
2814 imagelist_get_bitmap_size( himl, nNewCount, &sz );
2815 hbmNewBitmap = CreateBitmap (sz.cx, sz.cy, 1, 1, NULL);
2816 if (hbmNewBitmap != 0)
2818 hbmOld = SelectObject (hdcBitmap, hbmNewBitmap);
2819 imagelist_copy_images( himl, himl->hdcMask, hdcBitmap, 0, nCopyCount, 0 );
2820 SelectObject (hdcBitmap, hbmOld);
2822 /* FIXME: delete 'empty' image space? */
2824 SelectObject (himl->hdcMask, hbmNewBitmap);
2825 DeleteObject (himl->hbmMask);
2826 himl->hbmMask = hbmNewBitmap;
2829 ERR("Could not create new mask bitmap!\n");
2832 DeleteDC (hdcBitmap);
2834 /* Update max image count and current image count */
2835 himl->cMaxImage = nNewCount;
2836 himl->cCurImage = iImageCount;
2842 /*************************************************************************
2843 * ImageList_SetOverlayImage [COMCTL32.@]
2845 * Assigns an overlay mask index to an existing image in an image list.
2848 * himl [I] handle to image list
2849 * iImage [I] image index
2850 * iOverlay [I] overlay mask index
2858 ImageList_SetOverlayImage (HIMAGELIST himl, INT iImage, INT iOverlay)
2860 if (!is_valid(himl))
2862 if ((iOverlay < 1) || (iOverlay > MAX_OVERLAYIMAGE))
2864 if ((iImage!=-1) && ((iImage < 0) || (iImage > himl->cCurImage)))
2866 himl->nOvlIdx[iOverlay - 1] = iImage;
2872 /* helper for ImageList_Write - write bitmap to pstm
2873 * currently everything is written as 24 bit RGB, except masks
2876 _write_bitmap(HBITMAP hBitmap, LPSTREAM pstm)
2878 LPBITMAPFILEHEADER bmfh;
2879 LPBITMAPINFOHEADER bmih;
2880 LPBYTE data = NULL, lpBits;
2882 INT bitCount, sizeImage, offBits, totalSize;
2884 BOOL result = FALSE;
2886 if (!GetObjectW(hBitmap, sizeof(BITMAP), &bm))
2889 bitCount = bm.bmBitsPixel == 1 ? 1 : 24;
2890 sizeImage = DIB_GetDIBImageBytes(bm.bmWidth, bm.bmHeight, bitCount);
2892 totalSize = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);
2894 totalSize += (1 << bitCount) * sizeof(RGBQUAD);
2895 offBits = totalSize;
2896 totalSize += sizeImage;
2898 data = Alloc(totalSize);
2899 bmfh = (LPBITMAPFILEHEADER)data;
2900 bmih = (LPBITMAPINFOHEADER)(data + sizeof(BITMAPFILEHEADER));
2901 lpBits = data + offBits;
2903 /* setup BITMAPFILEHEADER */
2904 bmfh->bfType = (('M' << 8) | 'B');
2905 bmfh->bfSize = offBits;
2906 bmfh->bfReserved1 = 0;
2907 bmfh->bfReserved2 = 0;
2908 bmfh->bfOffBits = offBits;
2910 /* setup BITMAPINFOHEADER */
2911 bmih->biSize = sizeof(BITMAPINFOHEADER);
2912 bmih->biWidth = bm.bmWidth;
2913 bmih->biHeight = bm.bmHeight;
2915 bmih->biBitCount = bitCount;
2916 bmih->biCompression = BI_RGB;
2917 bmih->biSizeImage = sizeImage;
2918 bmih->biXPelsPerMeter = 0;
2919 bmih->biYPelsPerMeter = 0;
2920 bmih->biClrUsed = 0;
2921 bmih->biClrImportant = 0;
2924 result = GetDIBits(xdc, hBitmap, 0, bm.bmHeight, lpBits, (BITMAPINFO *)bmih, DIB_RGB_COLORS) == bm.bmHeight;
2929 TRACE("width %u, height %u, planes %u, bpp %u\n",
2930 bmih->biWidth, bmih->biHeight,
2931 bmih->biPlanes, bmih->biBitCount);
2935 LPBITMAPINFO inf = (LPBITMAPINFO)bmih;
2936 inf->bmiColors[0].rgbRed = inf->bmiColors[0].rgbGreen = inf->bmiColors[0].rgbBlue = 0;
2937 inf->bmiColors[1].rgbRed = inf->bmiColors[1].rgbGreen = inf->bmiColors[1].rgbBlue = 0xff;
2940 if(FAILED(IStream_Write(pstm, data, totalSize, NULL)))
2952 /*************************************************************************
2953 * ImageList_Write [COMCTL32.@]
2955 * Writes an image list to a stream.
2958 * himl [I] handle to image list
2959 * pstm [O] Pointer to a stream.
2970 ImageList_Write (HIMAGELIST himl, LPSTREAM pstm)
2975 TRACE("%p %p\n", himl, pstm);
2977 if (!is_valid(himl))
2980 ilHead.usMagic = (('L' << 8) | 'I');
2981 ilHead.usVersion = 0x101;
2982 ilHead.cCurImage = himl->cCurImage;
2983 ilHead.cMaxImage = himl->cMaxImage;
2984 ilHead.cGrow = himl->cGrow;
2985 ilHead.cx = himl->cx;
2986 ilHead.cy = himl->cy;
2987 ilHead.bkcolor = himl->clrBk;
2988 ilHead.flags = himl->flags;
2989 for(i = 0; i < 4; i++) {
2990 ilHead.ovls[i] = himl->nOvlIdx[i];
2993 TRACE("cx %u, cy %u, flags 0x04%x, cCurImage %u, cMaxImage %u\n",
2994 ilHead.cx, ilHead.cy, ilHead.flags, ilHead.cCurImage, ilHead.cMaxImage);
2996 if(FAILED(IStream_Write(pstm, &ilHead, sizeof(ILHEAD), NULL)))
2999 /* write the bitmap */
3000 if(!_write_bitmap(himl->hbmImage, pstm))
3003 /* write the mask if we have one */
3004 if(himl->flags & ILC_MASK) {
3005 if(!_write_bitmap(himl->hbmMask, pstm))
3013 static HBITMAP ImageList_CreateImage(HDC hdc, HIMAGELIST himl, UINT count)
3015 HBITMAP hbmNewBitmap;
3016 UINT ilc = (himl->flags & 0xFE);
3019 imagelist_get_bitmap_size( himl, count, &sz );
3021 if ((ilc >= ILC_COLOR4 && ilc <= ILC_COLOR32) || ilc == ILC_COLOR)
3026 TRACE("Creating DIBSection %d x %d, %d Bits per Pixel\n",
3027 sz.cx, sz.cy, himl->uBitsPixel);
3029 if (himl->uBitsPixel <= ILC_COLOR8)
3035 colors = 1 << himl->uBitsPixel;
3036 bmi = Alloc(sizeof(BITMAPINFOHEADER) +
3037 sizeof(PALETTEENTRY) * colors);
3039 pal = (LPPALETTEENTRY)bmi->bmiColors;
3040 GetPaletteEntries(GetStockObject(DEFAULT_PALETTE), 0, colors, pal);
3042 /* Swap colors returned by GetPaletteEntries so we can use them for
3043 * CreateDIBSection call. */
3044 for (i = 0; i < colors; i++)
3046 temp = pal[i].peBlue;
3047 bmi->bmiColors[i].rgbRed = pal[i].peRed;
3048 bmi->bmiColors[i].rgbBlue = temp;
3053 bmi = Alloc(sizeof(BITMAPINFOHEADER));
3056 bmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
3057 bmi->bmiHeader.biWidth = sz.cx;
3058 bmi->bmiHeader.biHeight = sz.cy;
3059 bmi->bmiHeader.biPlanes = 1;
3060 bmi->bmiHeader.biBitCount = himl->uBitsPixel;
3061 bmi->bmiHeader.biCompression = BI_RGB;
3062 bmi->bmiHeader.biSizeImage = 0;
3063 bmi->bmiHeader.biXPelsPerMeter = 0;
3064 bmi->bmiHeader.biYPelsPerMeter = 0;
3065 bmi->bmiHeader.biClrUsed = 0;
3066 bmi->bmiHeader.biClrImportant = 0;
3068 hbmNewBitmap = CreateDIBSection(hdc, bmi, DIB_RGB_COLORS, &bits, 0, 0);
3072 else /*if (ilc == ILC_COLORDDB)*/
3074 TRACE("Creating Bitmap: %d Bits per Pixel\n", himl->uBitsPixel);
3076 hbmNewBitmap = CreateBitmap (sz.cx, sz.cy, 1, himl->uBitsPixel, NULL);
3078 TRACE("returning %p\n", hbmNewBitmap);
3079 return hbmNewBitmap;
3082 /*************************************************************************
3083 * ImageList_SetColorTable [COMCTL32.@]
3085 * Sets the color table of an image list.
3088 * himl [I] Handle to the image list.
3089 * uStartIndex [I] The first index to set.
3090 * cEntries [I] Number of entries to set.
3091 * prgb [I] New color information for color table for the image list.
3094 * Success: Number of entries in the table that were set.
3098 * ImageList_Create(), SetDIBColorTable()
3102 ImageList_SetColorTable (HIMAGELIST himl, UINT uStartIndex, UINT cEntries, CONST RGBQUAD * prgb)
3104 return SetDIBColorTable(himl->hdcImage, uStartIndex, cEntries, prgb);
3107 /*************************************************************************
3108 * ImageList_CoCreateInstance [COMCTL32.@]
3110 * Creates a new imagelist instance and returns an interface pointer to it.
3113 * rclsid [I] A reference to the CLSID (CLSID_ImageList).
3114 * punkOuter [I] Pointer to IUnknown interface for aggregation, if desired
3115 * riid [I] Identifier of the requested interface.
3116 * ppv [O] Returns the address of the pointer requested, or NULL.
3120 * Failure: Error value.
3123 ImageList_CoCreateInstance (REFCLSID rclsid, const IUnknown *punkOuter, REFIID riid, void **ppv)
3125 TRACE("(%s,%p,%s,%p)\n", debugstr_guid(rclsid), punkOuter, debugstr_guid(riid), ppv);
3127 if (!IsEqualCLSID(&CLSID_ImageList, rclsid))
3128 return E_NOINTERFACE;
3130 return ImageListImpl_CreateInstance(punkOuter, riid, ppv);
3134 /*************************************************************************
3135 * IImageList implementation
3138 static HRESULT WINAPI ImageListImpl_QueryInterface(IImageList *iface,
3139 REFIID iid, void **ppv)
3141 HIMAGELIST This = (HIMAGELIST) iface;
3142 TRACE("(%p,%s,%p)\n", iface, debugstr_guid(iid), ppv);
3144 if (!ppv) return E_INVALIDARG;
3146 if (IsEqualIID(&IID_IUnknown, iid) || IsEqualIID(&IID_IImageList, iid))
3151 return E_NOINTERFACE;
3154 IUnknown_AddRef((IUnknown*)*ppv);
3158 static ULONG WINAPI ImageListImpl_AddRef(IImageList *iface)
3160 HIMAGELIST This = (HIMAGELIST) iface;
3161 ULONG ref = InterlockedIncrement(&This->ref);
3163 TRACE("(%p) refcount=%u\n", iface, ref);
3167 static ULONG WINAPI ImageListImpl_Release(IImageList *iface)
3169 HIMAGELIST This = (HIMAGELIST) iface;
3170 ULONG ref = InterlockedDecrement(&This->ref);
3172 TRACE("(%p) refcount=%u\n", iface, ref);
3176 /* delete image bitmaps */
3177 if (This->hbmImage) DeleteObject (This->hbmImage);
3178 if (This->hbmMask) DeleteObject (This->hbmMask);
3180 /* delete image & mask DCs */
3181 if (This->hdcImage) DeleteDC (This->hdcImage);
3182 if (This->hdcMask) DeleteDC (This->hdcMask);
3184 /* delete blending brushes */
3185 if (This->hbrBlend25) DeleteObject (This->hbrBlend25);
3186 if (This->hbrBlend50) DeleteObject (This->hbrBlend50);
3188 This->lpVtbl = NULL;
3189 HeapFree(GetProcessHeap(), 0, This->has_alpha);
3190 HeapFree(GetProcessHeap(), 0, This);
3196 static HRESULT WINAPI ImageListImpl_Add(IImageList *iface, HBITMAP hbmImage,
3197 HBITMAP hbmMask, int *pi)
3199 HIMAGELIST This = (HIMAGELIST) iface;
3205 ret = ImageList_Add(This, hbmImage, hbmMask);
3214 static HRESULT WINAPI ImageListImpl_ReplaceIcon(IImageList *iface, int i,
3215 HICON hicon, int *pi)
3217 HIMAGELIST This = (HIMAGELIST) iface;
3223 ret = ImageList_ReplaceIcon(This, i, hicon);
3232 static HRESULT WINAPI ImageListImpl_SetOverlayImage(IImageList *iface,
3233 int iImage, int iOverlay)
3235 return ImageList_SetOverlayImage((HIMAGELIST) iface, iImage, iOverlay)
3239 static HRESULT WINAPI ImageListImpl_Replace(IImageList *iface, int i,
3240 HBITMAP hbmImage, HBITMAP hbmMask)
3242 return ImageList_Replace((HIMAGELIST) iface, i, hbmImage, hbmMask) ? S_OK :
3246 static HRESULT WINAPI ImageListImpl_AddMasked(IImageList *iface, HBITMAP hbmImage,
3247 COLORREF crMask, int *pi)
3249 HIMAGELIST This = (HIMAGELIST) iface;
3255 ret = ImageList_AddMasked(This, hbmImage, crMask);
3264 static HRESULT WINAPI ImageListImpl_Draw(IImageList *iface,
3265 IMAGELISTDRAWPARAMS *pimldp)
3267 HIMAGELIST This = (HIMAGELIST) iface;
3268 HIMAGELIST old_himl = 0;
3274 /* As far as I can tell, Windows simply ignores the contents of pimldp->himl
3275 so we shall simulate the same */
3276 old_himl = pimldp->himl;
3277 pimldp->himl = This;
3279 ret = ImageList_DrawIndirect(pimldp);
3281 pimldp->himl = old_himl;
3282 return ret ? S_OK : E_FAIL;
3285 static HRESULT WINAPI ImageListImpl_Remove(IImageList *iface, int i)
3287 return (ImageList_Remove((HIMAGELIST) iface, i) == 0) ? E_FAIL : S_OK;
3290 static HRESULT WINAPI ImageListImpl_GetIcon(IImageList *iface, int i, UINT flags,
3298 hIcon = ImageList_GetIcon((HIMAGELIST) iface, i, flags);
3307 static HRESULT WINAPI ImageListImpl_GetImageInfo(IImageList *iface, int i,
3308 IMAGEINFO *pImageInfo)
3310 return ImageList_GetImageInfo((HIMAGELIST) iface, i, pImageInfo) ? S_OK : E_FAIL;
3313 static HRESULT WINAPI ImageListImpl_Copy(IImageList *iface, int iDst,
3314 IUnknown *punkSrc, int iSrc, UINT uFlags)
3316 HIMAGELIST This = (HIMAGELIST) iface;
3317 IImageList *src = NULL;
3323 /* TODO: Add test for IID_ImageList2 too */
3324 if (FAILED(IImageList_QueryInterface(punkSrc, &IID_IImageList,
3328 if (ImageList_Copy(This, iDst, (HIMAGELIST) src, iSrc, uFlags))
3333 IImageList_Release(src);
3337 static HRESULT WINAPI ImageListImpl_Merge(IImageList *iface, int i1,
3338 IUnknown *punk2, int i2, int dx, int dy, REFIID riid, PVOID *ppv)
3340 HIMAGELIST This = (HIMAGELIST) iface;
3341 IImageList *iml2 = NULL;
3343 HRESULT ret = E_FAIL;
3348 /* TODO: Add test for IID_ImageList2 too */
3349 if (FAILED(IImageList_QueryInterface(punk2, &IID_IImageList,
3353 hNew = ImageList_Merge(This, i1, (HIMAGELIST) iml2, i2, dx, dy);
3355 /* Get the interface for the new image list */
3357 ret = HIMAGELIST_QueryInterface(hNew, riid, ppv);
3359 IImageList_Release(iml2);
3363 static HRESULT WINAPI ImageListImpl_Clone(IImageList *iface, REFIID riid,
3366 HIMAGELIST This = (HIMAGELIST) iface;
3368 HRESULT ret = E_FAIL;
3373 hNew = ImageList_Duplicate(This);
3375 /* Get the interface for the new image list */
3377 ret = HIMAGELIST_QueryInterface(hNew, riid, ppv);
3382 static HRESULT WINAPI ImageListImpl_GetImageRect(IImageList *iface, int i,
3385 HIMAGELIST This = (HIMAGELIST) iface;
3391 if (!ImageList_GetImageInfo(This, i, &info))
3394 return CopyRect(prc, &info.rcImage) ? S_OK : E_FAIL;
3397 static HRESULT WINAPI ImageListImpl_GetIconSize(IImageList *iface, int *cx,
3400 HIMAGELIST This = (HIMAGELIST) iface;
3402 return ImageList_GetIconSize(This, cx, cy) ? S_OK : E_FAIL;
3405 static HRESULT WINAPI ImageListImpl_SetIconSize(IImageList *iface, int cx,
3408 return ImageList_SetIconSize((HIMAGELIST) iface, cx, cy) ? S_OK : E_FAIL;
3411 static HRESULT WINAPI ImageListImpl_GetImageCount(IImageList *iface, int *pi)
3416 *pi = ImageList_GetImageCount((HIMAGELIST) iface);
3420 static HRESULT WINAPI ImageListImpl_SetImageCount(IImageList *iface,
3423 return ImageList_SetImageCount((HIMAGELIST) iface, uNewCount) ? S_OK : E_FAIL;
3426 static HRESULT WINAPI ImageListImpl_SetBkColor(IImageList *iface, COLORREF clrBk,
3432 *pclr = ImageList_SetBkColor((HIMAGELIST) iface, clrBk);
3433 return *pclr == CLR_NONE ? E_FAIL : S_OK;
3436 static HRESULT WINAPI ImageListImpl_GetBkColor(IImageList *iface, COLORREF *pclr)
3441 *pclr = ImageList_GetBkColor((HIMAGELIST) iface);
3445 static HRESULT WINAPI ImageListImpl_BeginDrag(IImageList *iface, int iTrack,
3446 int dxHotspot, int dyHotspot)
3448 return ImageList_BeginDrag((HIMAGELIST) iface, iTrack, dxHotspot, dyHotspot) ? S_OK : E_FAIL;
3451 static HRESULT WINAPI ImageListImpl_EndDrag(IImageList *iface)
3453 ImageList_EndDrag();
3457 static HRESULT WINAPI ImageListImpl_DragEnter(IImageList *iface, HWND hwndLock,
3460 return ImageList_DragEnter(hwndLock, x, y) ? S_OK : E_FAIL;
3463 static HRESULT WINAPI ImageListImpl_DragLeave(IImageList *iface, HWND hwndLock)
3465 return ImageList_DragLeave(hwndLock) ? S_OK : E_FAIL;
3468 static HRESULT WINAPI ImageListImpl_DragMove(IImageList *iface, int x, int y)
3470 return ImageList_DragMove(x, y) ? S_OK : E_FAIL;
3473 static HRESULT WINAPI ImageListImpl_SetDragCursorImage(IImageList *iface,
3474 IUnknown *punk, int iDrag, int dxHotspot, int dyHotspot)
3476 IImageList *iml2 = NULL;
3482 /* TODO: Add test for IID_ImageList2 too */
3483 if (FAILED(IImageList_QueryInterface(punk, &IID_IImageList,
3487 ret = ImageList_SetDragCursorImage((HIMAGELIST) iml2, iDrag, dxHotspot,
3490 IImageList_Release(iml2);
3492 return ret ? S_OK : E_FAIL;
3495 static HRESULT WINAPI ImageListImpl_DragShowNolock(IImageList *iface, BOOL fShow)
3497 return ImageList_DragShowNolock(fShow) ? S_OK : E_FAIL;
3500 static HRESULT WINAPI ImageListImpl_GetDragImage(IImageList *iface, POINT *ppt,
3501 POINT *pptHotspot, REFIID riid, PVOID *ppv)
3503 HRESULT ret = E_FAIL;
3509 hNew = ImageList_GetDragImage(ppt, pptHotspot);
3511 /* Get the interface for the new image list */
3513 ret = HIMAGELIST_QueryInterface(hNew, riid, ppv);
3518 static HRESULT WINAPI ImageListImpl_GetItemFlags(IImageList *iface, int i,
3521 FIXME("STUB: %p %d %p\n", iface, i, dwFlags);
3525 static HRESULT WINAPI ImageListImpl_GetOverlayImage(IImageList *iface, int iOverlay,
3528 HIMAGELIST This = (HIMAGELIST) iface;
3531 if ((iOverlay < 0) || (iOverlay > This->cCurImage))
3534 for (i = 0; i < MAX_OVERLAYIMAGE; i++)
3536 if (This->nOvlIdx[i] == iOverlay)
3547 static const IImageListVtbl ImageListImpl_Vtbl = {
3548 ImageListImpl_QueryInterface,
3549 ImageListImpl_AddRef,
3550 ImageListImpl_Release,
3552 ImageListImpl_ReplaceIcon,
3553 ImageListImpl_SetOverlayImage,
3554 ImageListImpl_Replace,
3555 ImageListImpl_AddMasked,
3557 ImageListImpl_Remove,
3558 ImageListImpl_GetIcon,
3559 ImageListImpl_GetImageInfo,
3561 ImageListImpl_Merge,
3562 ImageListImpl_Clone,
3563 ImageListImpl_GetImageRect,
3564 ImageListImpl_GetIconSize,
3565 ImageListImpl_SetIconSize,
3566 ImageListImpl_GetImageCount,
3567 ImageListImpl_SetImageCount,
3568 ImageListImpl_SetBkColor,
3569 ImageListImpl_GetBkColor,
3570 ImageListImpl_BeginDrag,
3571 ImageListImpl_EndDrag,
3572 ImageListImpl_DragEnter,
3573 ImageListImpl_DragLeave,
3574 ImageListImpl_DragMove,
3575 ImageListImpl_SetDragCursorImage,
3576 ImageListImpl_DragShowNolock,
3577 ImageListImpl_GetDragImage,
3578 ImageListImpl_GetItemFlags,
3579 ImageListImpl_GetOverlayImage
3582 static inline BOOL is_valid(HIMAGELIST himl)
3584 return himl && himl->lpVtbl == &ImageListImpl_Vtbl;
3587 /*************************************************************************
3588 * HIMAGELIST_QueryInterface [COMCTL32.@]
3590 * Returns a pointer to an IImageList or IImageList2 object for the given
3594 * himl [I] Image list handle.
3595 * riid [I] Identifier of the requested interface.
3596 * ppv [O] Returns the address of the pointer requested, or NULL.
3600 * Failure: Error value.
3603 HIMAGELIST_QueryInterface (HIMAGELIST himl, REFIID riid, void **ppv)
3605 TRACE("(%p,%s,%p)\n", himl, debugstr_guid(riid), ppv);
3606 return IImageList_QueryInterface((IImageList *) himl, riid, ppv);
3609 static HRESULT ImageListImpl_CreateInstance(const IUnknown *pUnkOuter, REFIID iid, void** ppv)
3614 TRACE("(%p,%s,%p)\n", pUnkOuter, debugstr_guid(iid), ppv);
3618 if (pUnkOuter) return CLASS_E_NOAGGREGATION;
3620 This = HeapAlloc(GetProcessHeap(), 0, sizeof(struct _IMAGELIST));
3621 if (!This) return E_OUTOFMEMORY;
3623 ZeroMemory(This, sizeof(struct _IMAGELIST));
3625 This->lpVtbl = &ImageListImpl_Vtbl;
3628 ret = IUnknown_QueryInterface((IUnknown*)This, iid, ppv);
3629 IUnknown_Release((IUnknown*)This);