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 )
150 BYTE *mask_bits = NULL;
155 if (himl->uBitsPixel != 32) return FALSE;
156 if (!GetObjectW( hbmImage, sizeof(bm), &bm )) return FALSE;
157 SelectObject( hdc, hbmImage );
158 mask_width = (bm.bmWidth + 31) / 32 * 4;
160 if (!(info = HeapAlloc( GetProcessHeap(), 0, FIELD_OFFSET( BITMAPINFO, bmiColors[256] )))) goto done;
161 info->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
162 info->bmiHeader.biWidth = bm.bmWidth;
163 info->bmiHeader.biHeight = -height;
164 info->bmiHeader.biPlanes = 1;
165 info->bmiHeader.biBitCount = 32;
166 info->bmiHeader.biCompression = BI_RGB;
167 info->bmiHeader.biSizeImage = bm.bmWidth * height * 4;
168 info->bmiHeader.biXPelsPerMeter = 0;
169 info->bmiHeader.biYPelsPerMeter = 0;
170 info->bmiHeader.biClrUsed = 0;
171 info->bmiHeader.biClrImportant = 0;
172 if (!(bits = HeapAlloc( GetProcessHeap(), 0, info->bmiHeader.biSizeImage ))) goto done;
173 if (!GetDIBits( hdc, hbmImage, 0, height, bits, info, DIB_RGB_COLORS )) goto done;
177 info->bmiHeader.biBitCount = 1;
178 info->bmiHeader.biSizeImage = mask_width * height;
179 if (!(mask_bits = HeapAlloc( GetProcessHeap(), 0, info->bmiHeader.biSizeImage ))) goto done;
180 if (!GetDIBits( hdc, hbmMask, 0, height, mask_bits, info, DIB_RGB_COLORS )) goto done;
181 /* restore values for color info */
182 info->bmiHeader.biBitCount = 32;
183 info->bmiHeader.biSizeImage = bm.bmWidth * height * 4;
184 hdcMask = CreateCompatibleDC( 0 );
185 SelectObject( hdcMask, hbmMask );
188 for (n = 0; n < count; n++)
192 imagelist_point_from_index( himl, pos + n, &pt );
194 /* check if bitmap has an alpha channel */
195 for (i = 0; i < height && !has_alpha; i++)
196 for (j = n * width; j < (n + 1) * width; j++)
197 if ((has_alpha = ((bits[i * bm.bmWidth + j] & 0xff000000) != 0))) break;
199 if (!has_alpha) /* generate alpha channel from the mask */
201 for (i = 0; i < height; i++)
202 for (j = n * width; j < (n + 1) * width; j++)
203 if (!mask_bits || !((mask_bits[i * mask_width + j / 8] << (j % 8)) & 0x80))
204 bits[i * bm.bmWidth + j] |= 0xff000000;
205 StretchDIBits( himl->hdcImage, pt.x, pt.y, himl->cx, himl->cy,
206 n * width, 0, width, height, bits, info, DIB_RGB_COLORS, SRCCOPY );
210 StretchBlt( himl->hdcImage, pt.x, pt.y, himl->cx, himl->cy,
211 hdc, n * width, 0, width, height, SRCCOPY );
214 if (hdcMask) StretchBlt( himl->hdcMask, pt.x, pt.y, himl->cx, himl->cy,
215 hdcMask, n * width, 0, width, height, SRCCOPY );
220 if (hdcMask) DeleteDC( hdcMask );
221 HeapFree( GetProcessHeap(), 0, info );
222 HeapFree( GetProcessHeap(), 0, bits );
223 HeapFree( GetProcessHeap(), 0, mask_bits );
227 /*************************************************************************
228 * IMAGELIST_InternalExpandBitmaps [Internal]
230 * Expands the bitmaps of an image list by the given number of images.
233 * himl [I] handle to image list
234 * nImageCount [I] number of images to add
240 * This function CANNOT be used to reduce the number of images.
243 IMAGELIST_InternalExpandBitmaps(HIMAGELIST himl, INT nImageCount)
246 HBITMAP hbmNewBitmap, hbmNull;
250 TRACE("%p has %d allocated %d images\n", himl, himl->cCurImage, himl->cMaxImage);
252 if (himl->cCurImage + nImageCount <= himl->cMaxImage)
255 nNewCount = himl->cCurImage + max(nImageCount, himl->cGrow) + 1;
257 imagelist_get_bitmap_size(himl, nNewCount, &sz);
259 TRACE("Create expanded bitmaps : himl=%p x=%d y=%d count=%d\n", himl, sz.cx, sz.cy, nNewCount);
260 hdcBitmap = CreateCompatibleDC (0);
262 hbmNewBitmap = ImageList_CreateImage(hdcBitmap, himl, nNewCount);
264 if (hbmNewBitmap == 0)
265 ERR("creating new image bitmap (x=%d y=%d)!\n", sz.cx, sz.cy);
269 hbmNull = SelectObject (hdcBitmap, hbmNewBitmap);
270 BitBlt (hdcBitmap, 0, 0, sz.cx, sz.cy,
271 himl->hdcImage, 0, 0, SRCCOPY);
272 SelectObject (hdcBitmap, hbmNull);
274 SelectObject (himl->hdcImage, hbmNewBitmap);
275 DeleteObject (himl->hbmImage);
276 himl->hbmImage = hbmNewBitmap;
278 if (himl->flags & ILC_MASK)
280 hbmNewBitmap = CreateBitmap (sz.cx, sz.cy, 1, 1, NULL);
282 if (hbmNewBitmap == 0)
283 ERR("creating new mask bitmap!\n");
287 hbmNull = SelectObject (hdcBitmap, hbmNewBitmap);
288 BitBlt (hdcBitmap, 0, 0, sz.cx, sz.cy,
289 himl->hdcMask, 0, 0, SRCCOPY);
290 SelectObject (hdcBitmap, hbmNull);
292 SelectObject (himl->hdcMask, hbmNewBitmap);
293 DeleteObject (himl->hbmMask);
294 himl->hbmMask = hbmNewBitmap;
297 himl->cMaxImage = nNewCount;
299 DeleteDC (hdcBitmap);
303 /*************************************************************************
304 * ImageList_Add [COMCTL32.@]
306 * Add an image or images to an image list.
309 * himl [I] handle to image list
310 * hbmImage [I] handle to image bitmap
311 * hbmMask [I] handle to mask bitmap
314 * Success: Index of the first new image.
319 ImageList_Add (HIMAGELIST himl, HBITMAP hbmImage, HBITMAP hbmMask)
321 HDC hdcBitmap, hdcTemp = 0;
322 INT nFirstIndex, nImageCount, i;
326 TRACE("himl=%p hbmimage=%p hbmmask=%p\n", himl, hbmImage, hbmMask);
330 if (!GetObjectW(hbmImage, sizeof(BITMAP), &bmp))
333 TRACE("himl %p, cCurImage %d, cMaxImage %d, cGrow %d, cx %d, cy %d\n",
334 himl, himl->cCurImage, himl->cMaxImage, himl->cGrow, himl->cx, himl->cy);
336 nImageCount = bmp.bmWidth / himl->cx;
338 TRACE("%p has %d images (%d x %d)\n", hbmImage, nImageCount, bmp.bmWidth, bmp.bmHeight);
340 IMAGELIST_InternalExpandBitmaps(himl, nImageCount);
342 hdcBitmap = CreateCompatibleDC(0);
344 SelectObject(hdcBitmap, hbmImage);
346 if (add_with_alpha( himl, hdcBitmap, himl->cCurImage, nImageCount,
347 himl->cx, min( himl->cy, bmp.bmHeight), hbmImage, hbmMask ))
352 hdcTemp = CreateCompatibleDC(0);
353 SelectObject(hdcTemp, hbmMask);
356 for (i=0; i<nImageCount; i++)
358 imagelist_point_from_index( himl, himl->cCurImage + i, &pt );
360 /* Copy result to the imagelist
362 BitBlt( himl->hdcImage, pt.x, pt.y, himl->cx, bmp.bmHeight,
363 hdcBitmap, i*himl->cx, 0, SRCCOPY );
368 BitBlt( himl->hdcMask, pt.x, pt.y, himl->cx, bmp.bmHeight,
369 hdcTemp, i*himl->cx, 0, SRCCOPY );
371 /* Remove the background from the image
373 BitBlt( himl->hdcImage, pt.x, pt.y, himl->cx, bmp.bmHeight,
374 himl->hdcMask, pt.x, pt.y, 0x220326 ); /* NOTSRCAND */
376 if (hdcTemp) DeleteDC(hdcTemp);
381 nFirstIndex = himl->cCurImage;
382 himl->cCurImage += nImageCount;
388 /*************************************************************************
389 * ImageList_AddIcon [COMCTL32.@]
391 * Adds an icon to an image list.
394 * himl [I] handle to image list
395 * hIcon [I] handle to icon
398 * Success: index of the new image
401 #undef ImageList_AddIcon
402 INT WINAPI ImageList_AddIcon (HIMAGELIST himl, HICON hIcon)
404 return ImageList_ReplaceIcon (himl, -1, hIcon);
408 /*************************************************************************
409 * ImageList_AddMasked [COMCTL32.@]
411 * Adds an image or images to an image list and creates a mask from the
412 * specified bitmap using the mask color.
415 * himl [I] handle to image list.
416 * hBitmap [I] handle to bitmap
417 * clrMask [I] mask color.
420 * Success: Index of the first new image.
425 ImageList_AddMasked (HIMAGELIST himl, HBITMAP hBitmap, COLORREF clrMask)
427 HDC hdcMask, hdcBitmap;
433 TRACE("himl=%p hbitmap=%p clrmask=%x\n", himl, hBitmap, clrMask);
437 if (!GetObjectW(hBitmap, sizeof(BITMAP), &bmp))
440 hdcBitmap = CreateCompatibleDC(0);
441 SelectObject(hdcBitmap, hBitmap);
443 /* Create a temp Mask so we can remove the background of the Image */
444 hdcMask = CreateCompatibleDC(0);
445 hMaskBitmap = CreateBitmap(bmp.bmWidth, bmp.bmHeight, 1, 1, NULL);
446 SelectObject(hdcMask, hMaskBitmap);
448 /* create monochrome image to the mask bitmap */
449 bkColor = (clrMask != CLR_DEFAULT) ? clrMask : GetPixel (hdcBitmap, 0, 0);
450 SetBkColor (hdcBitmap, bkColor);
451 BitBlt (hdcMask, 0, 0, bmp.bmWidth, bmp.bmHeight, hdcBitmap, 0, 0, SRCCOPY);
453 SetBkColor(hdcBitmap, RGB(255,255,255));
456 * Remove the background from the image
458 * WINDOWS BUG ALERT!!!!!!
459 * The statement below should not be done in common practice
460 * but this is how ImageList_AddMasked works in Windows.
461 * It overwrites the original bitmap passed, this was discovered
462 * by using the same bitmap to iterate the different styles
463 * on windows where it failed (BUT ImageList_Add is OK)
464 * This is here in case some apps rely on this bug
466 * Blt mode 0x220326 is NOTSRCAND
468 BitBlt(hdcBitmap, 0, 0, bmp.bmWidth, bmp.bmHeight, hdcMask, 0, 0, 0x220326);
473 ret = ImageList_Add( himl, hBitmap, hMaskBitmap );
475 DeleteObject(hMaskBitmap);
480 /*************************************************************************
481 * ImageList_BeginDrag [COMCTL32.@]
483 * Creates a temporary image list that contains one image. It will be used
487 * himlTrack [I] handle to the source image list
488 * iTrack [I] index of the drag image in the source image list
489 * dxHotspot [I] X position of the hot spot of the drag image
490 * dyHotspot [I] Y position of the hot spot of the drag image
498 ImageList_BeginDrag (HIMAGELIST himlTrack, INT iTrack,
499 INT dxHotspot, INT dyHotspot)
503 TRACE("(himlTrack=%p iTrack=%d dx=%d dy=%d)\n", himlTrack, iTrack,
504 dxHotspot, dyHotspot);
506 if (!is_valid(himlTrack))
509 if (InternalDrag.himl)
510 ImageList_EndDrag ();
515 InternalDrag.himl = ImageList_Create (cx, cy, himlTrack->flags, 1, 1);
516 if (InternalDrag.himl == NULL) {
517 WARN("Error creating drag image list!\n");
521 InternalDrag.dxHotspot = dxHotspot;
522 InternalDrag.dyHotspot = dyHotspot;
525 BitBlt (InternalDrag.himl->hdcImage, 0, 0, cx, cy, himlTrack->hdcImage, iTrack * cx, 0, SRCCOPY);
528 BitBlt (InternalDrag.himl->hdcMask, 0, 0, cx, cy, himlTrack->hdcMask, iTrack * cx, 0, SRCCOPY);
530 InternalDrag.himl->cCurImage = 1;
536 /*************************************************************************
537 * ImageList_Copy [COMCTL32.@]
539 * Copies an image of the source image list to an image of the
540 * destination image list. Images can be copied or swapped.
543 * himlDst [I] handle to the destination image list
544 * iDst [I] destination image index.
545 * himlSrc [I] handle to the source image list
546 * iSrc [I] source image index
547 * uFlags [I] flags for the copy operation
554 * Copying from one image list to another is possible. The original
555 * implementation just copies or swaps within one image list.
556 * Could this feature become a bug??? ;-)
560 ImageList_Copy (HIMAGELIST himlDst, INT iDst, HIMAGELIST himlSrc,
561 INT iSrc, UINT uFlags)
565 TRACE("himlDst=%p iDst=%d himlSrc=%p iSrc=%d\n", himlDst, iDst, himlSrc, iSrc);
567 if (!is_valid(himlSrc) || !is_valid(himlDst))
569 if ((iDst < 0) || (iDst >= himlDst->cCurImage))
571 if ((iSrc < 0) || (iSrc >= himlSrc->cCurImage))
574 imagelist_point_from_index( himlDst, iDst, &ptDst );
575 imagelist_point_from_index( himlSrc, iSrc, &ptSrc );
577 if (uFlags & ILCF_SWAP) {
580 HBITMAP hbmTempImage, hbmTempMask;
582 hdcBmp = CreateCompatibleDC (0);
584 /* create temporary bitmaps */
585 hbmTempImage = CreateBitmap (himlSrc->cx, himlSrc->cy, 1,
586 himlSrc->uBitsPixel, NULL);
587 hbmTempMask = CreateBitmap (himlSrc->cx, himlSrc->cy, 1,
590 /* copy (and stretch) destination to temporary bitmaps.(save) */
592 SelectObject (hdcBmp, hbmTempImage);
593 StretchBlt (hdcBmp, 0, 0, himlSrc->cx, himlSrc->cy,
594 himlDst->hdcImage, ptDst.x, ptDst.y, himlDst->cx, himlDst->cy,
597 SelectObject (hdcBmp, hbmTempMask);
598 StretchBlt (hdcBmp, 0, 0, himlSrc->cx, himlSrc->cy,
599 himlDst->hdcMask, ptDst.x, ptDst.y, himlDst->cx, himlDst->cy,
602 /* copy (and stretch) source to destination */
604 StretchBlt (himlDst->hdcImage, ptDst.x, ptDst.y, himlDst->cx, himlDst->cy,
605 himlSrc->hdcImage, ptSrc.x, ptSrc.y, himlSrc->cx, himlSrc->cy,
608 StretchBlt (himlDst->hdcMask, ptDst.x, ptDst.y, himlDst->cx, himlDst->cy,
609 himlSrc->hdcMask, ptSrc.x, ptSrc.y, himlSrc->cx, himlSrc->cy,
612 /* copy (without stretching) temporary bitmaps to source (restore) */
614 BitBlt (himlSrc->hdcMask, ptSrc.x, ptSrc.y, himlSrc->cx, himlSrc->cy,
615 hdcBmp, 0, 0, SRCCOPY);
618 BitBlt (himlSrc->hdcImage, ptSrc.x, ptSrc.y, himlSrc->cx, himlSrc->cy,
619 hdcBmp, 0, 0, SRCCOPY);
620 /* delete temporary bitmaps */
621 DeleteObject (hbmTempMask);
622 DeleteObject (hbmTempImage);
627 StretchBlt (himlDst->hdcImage, ptDst.x, ptDst.y, himlDst->cx, himlDst->cy,
628 himlSrc->hdcImage, ptSrc.x, ptSrc.y, himlSrc->cx, himlSrc->cy,
632 StretchBlt (himlDst->hdcMask, ptDst.x, ptDst.y, himlDst->cx, himlDst->cy,
633 himlSrc->hdcMask, ptSrc.x, ptSrc.y, himlSrc->cx, himlSrc->cy,
641 /*************************************************************************
642 * ImageList_Create [COMCTL32.@]
644 * Creates a new image list.
647 * cx [I] image height
649 * flags [I] creation flags
650 * cInitial [I] initial number of images in the image list
651 * cGrow [I] number of images by which image list grows
654 * Success: Handle to the created image list
658 ImageList_Create (INT cx, INT cy, UINT flags,
659 INT cInitial, INT cGrow)
664 UINT ilc = (flags & 0xFE);
665 static const WORD aBitBlend25[] =
666 {0xAA, 0x00, 0x55, 0x00, 0xAA, 0x00, 0x55, 0x00};
668 static const WORD aBitBlend50[] =
669 {0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA};
671 TRACE("(%d %d 0x%x %d %d)\n", cx, cy, flags, cInitial, cGrow);
673 /* Create the IImageList interface for the image list */
674 if (FAILED(ImageListImpl_CreateInstance(NULL, &IID_IImageList, (void **)&himl)))
677 cGrow = (cGrow < 4) ? 4 : (cGrow + 3) & ~3;
682 himl->cMaxImage = cInitial + 1;
683 himl->cInitial = cInitial;
685 himl->clrFg = CLR_DEFAULT;
686 himl->clrBk = CLR_NONE;
688 /* initialize overlay mask indices */
689 for (nCount = 0; nCount < MAX_OVERLAYIMAGE; nCount++)
690 himl->nOvlIdx[nCount] = -1;
692 /* Create Image & Mask DCs */
693 himl->hdcImage = CreateCompatibleDC (0);
696 if (himl->flags & ILC_MASK){
697 himl->hdcMask = CreateCompatibleDC(0);
702 /* Default to ILC_COLOR4 if none of the ILC_COLOR* flags are specified */
703 if (ilc == ILC_COLOR)
706 if (ilc >= ILC_COLOR4 && ilc <= ILC_COLOR32)
707 himl->uBitsPixel = ilc;
709 himl->uBitsPixel = (UINT)GetDeviceCaps (himl->hdcImage, BITSPIXEL);
711 if (himl->cMaxImage > 0) {
712 himl->hbmImage = ImageList_CreateImage(himl->hdcImage, himl, himl->cMaxImage);
713 SelectObject(himl->hdcImage, himl->hbmImage);
717 if ((himl->cMaxImage > 0) && (himl->flags & ILC_MASK)) {
720 imagelist_get_bitmap_size(himl, himl->cMaxImage, &sz);
721 himl->hbmMask = CreateBitmap (sz.cx, sz.cy, 1, 1, NULL);
722 if (himl->hbmMask == 0) {
723 ERR("Error creating mask bitmap!\n");
726 SelectObject(himl->hdcMask, himl->hbmMask);
731 /* create blending brushes */
732 hbmTemp = CreateBitmap (8, 8, 1, 1, aBitBlend25);
733 himl->hbrBlend25 = CreatePatternBrush (hbmTemp);
734 DeleteObject (hbmTemp);
736 hbmTemp = CreateBitmap (8, 8, 1, 1, aBitBlend50);
737 himl->hbrBlend50 = CreatePatternBrush (hbmTemp);
738 DeleteObject (hbmTemp);
740 TRACE("created imagelist %p\n", himl);
744 ImageList_Destroy(himl);
749 /*************************************************************************
750 * ImageList_Destroy [COMCTL32.@]
752 * Destroys an image list.
755 * himl [I] handle to image list
763 ImageList_Destroy (HIMAGELIST himl)
768 IImageList_Release((IImageList *) himl);
773 /*************************************************************************
774 * ImageList_DragEnter [COMCTL32.@]
776 * Locks window update and displays the drag image at the given position.
779 * hwndLock [I] handle of the window that owns the drag image.
780 * x [I] X position of the drag image.
781 * y [I] Y position of the drag image.
788 * The position of the drag image is relative to the window, not
793 ImageList_DragEnter (HWND hwndLock, INT x, INT y)
795 TRACE("(hwnd=%p x=%d y=%d)\n", hwndLock, x, y);
797 if (!is_valid(InternalDrag.himl))
801 InternalDrag.hwnd = hwndLock;
803 InternalDrag.hwnd = GetDesktopWindow ();
808 /* draw the drag image and save the background */
809 if (!ImageList_DragShowNolock(TRUE)) {
817 /*************************************************************************
818 * ImageList_DragLeave [COMCTL32.@]
820 * Unlocks window update and hides the drag image.
823 * hwndLock [I] handle of the window that owns the drag image.
831 ImageList_DragLeave (HWND hwndLock)
833 /* As we don't save drag info in the window this can lead to problems if
834 an app does not supply the same window as DragEnter */
836 InternalDrag.hwnd = hwndLock;
838 InternalDrag.hwnd = GetDesktopWindow (); */
840 hwndLock = GetDesktopWindow();
841 if(InternalDrag.hwnd != hwndLock)
842 FIXME("DragLeave hWnd != DragEnter hWnd\n");
844 ImageList_DragShowNolock (FALSE);
850 /*************************************************************************
851 * ImageList_InternalDragDraw [Internal]
853 * Draws the drag image.
856 * hdc [I] device context to draw into.
857 * x [I] X position of the drag image.
858 * y [I] Y position of the drag image.
865 * The position of the drag image is relative to the window, not
871 ImageList_InternalDragDraw (HDC hdc, INT x, INT y)
873 IMAGELISTDRAWPARAMS imldp;
875 ZeroMemory (&imldp, sizeof(imldp));
876 imldp.cbSize = sizeof(imldp);
877 imldp.himl = InternalDrag.himl;
882 imldp.rgbBk = CLR_DEFAULT;
883 imldp.rgbFg = CLR_DEFAULT;
884 imldp.fStyle = ILD_NORMAL;
885 imldp.fState = ILS_ALPHA;
887 ImageList_DrawIndirect (&imldp);
890 /*************************************************************************
891 * ImageList_DragMove [COMCTL32.@]
893 * Moves the drag image.
896 * x [I] X position of the drag image.
897 * y [I] Y position of the drag image.
904 * The position of the drag image is relative to the window, not
909 ImageList_DragMove (INT x, INT y)
911 TRACE("(x=%d y=%d)\n", x, y);
913 if (!is_valid(InternalDrag.himl))
916 /* draw/update the drag image */
917 if (InternalDrag.bShow) {
921 HBITMAP hbmOffScreen;
922 INT origNewX, origNewY;
923 INT origOldX, origOldY;
924 INT origRegX, origRegY;
925 INT sizeRegX, sizeRegY;
928 /* calculate the update region */
929 origNewX = x - InternalDrag.dxHotspot;
930 origNewY = y - InternalDrag.dyHotspot;
931 origOldX = InternalDrag.x - InternalDrag.dxHotspot;
932 origOldY = InternalDrag.y - InternalDrag.dyHotspot;
933 origRegX = min(origNewX, origOldX);
934 origRegY = min(origNewY, origOldY);
935 sizeRegX = InternalDrag.himl->cx + abs(x - InternalDrag.x);
936 sizeRegY = InternalDrag.himl->cy + abs(y - InternalDrag.y);
938 hdcDrag = GetDCEx(InternalDrag.hwnd, 0,
939 DCX_WINDOW | DCX_CACHE | DCX_LOCKWINDOWUPDATE);
940 hdcOffScreen = CreateCompatibleDC(hdcDrag);
941 hdcBg = CreateCompatibleDC(hdcDrag);
943 hbmOffScreen = CreateCompatibleBitmap(hdcDrag, sizeRegX, sizeRegY);
944 SelectObject(hdcOffScreen, hbmOffScreen);
945 SelectObject(hdcBg, InternalDrag.hbmBg);
947 /* get the actual background of the update region */
948 BitBlt(hdcOffScreen, 0, 0, sizeRegX, sizeRegY, hdcDrag,
949 origRegX, origRegY, SRCCOPY);
950 /* erase the old image */
951 BitBlt(hdcOffScreen, origOldX - origRegX, origOldY - origRegY,
952 InternalDrag.himl->cx, InternalDrag.himl->cy, hdcBg, 0, 0,
954 /* save the background */
955 BitBlt(hdcBg, 0, 0, InternalDrag.himl->cx, InternalDrag.himl->cy,
956 hdcOffScreen, origNewX - origRegX, origNewY - origRegY, SRCCOPY);
958 ImageList_InternalDragDraw(hdcOffScreen, origNewX - origRegX,
959 origNewY - origRegY);
960 /* draw the update region to the screen */
961 BitBlt(hdcDrag, origRegX, origRegY, sizeRegX, sizeRegY,
962 hdcOffScreen, 0, 0, SRCCOPY);
965 DeleteDC(hdcOffScreen);
966 DeleteObject(hbmOffScreen);
967 ReleaseDC(InternalDrag.hwnd, hdcDrag);
970 /* update the image position */
978 /*************************************************************************
979 * ImageList_DragShowNolock [COMCTL32.@]
981 * Shows or hides the drag image.
984 * bShow [I] TRUE shows the drag image, FALSE hides it.
992 ImageList_DragShowNolock (BOOL bShow)
998 if (!is_valid(InternalDrag.himl))
1001 TRACE("bShow=0x%X!\n", bShow);
1003 /* DragImage is already visible/hidden */
1004 if ((InternalDrag.bShow && bShow) || (!InternalDrag.bShow && !bShow)) {
1008 /* position of the origin of the DragImage */
1009 x = InternalDrag.x - InternalDrag.dxHotspot;
1010 y = InternalDrag.y - InternalDrag.dyHotspot;
1012 hdcDrag = GetDCEx (InternalDrag.hwnd, 0,
1013 DCX_WINDOW | DCX_CACHE | DCX_LOCKWINDOWUPDATE);
1018 hdcBg = CreateCompatibleDC(hdcDrag);
1019 if (!InternalDrag.hbmBg) {
1020 InternalDrag.hbmBg = CreateCompatibleBitmap(hdcDrag,
1021 InternalDrag.himl->cx, InternalDrag.himl->cy);
1023 SelectObject(hdcBg, InternalDrag.hbmBg);
1026 /* save the background */
1027 BitBlt(hdcBg, 0, 0, InternalDrag.himl->cx, InternalDrag.himl->cy,
1028 hdcDrag, x, y, SRCCOPY);
1029 /* show the image */
1030 ImageList_InternalDragDraw(hdcDrag, x, y);
1032 /* hide the image */
1033 BitBlt(hdcDrag, x, y, InternalDrag.himl->cx, InternalDrag.himl->cy,
1034 hdcBg, 0, 0, SRCCOPY);
1037 InternalDrag.bShow = !InternalDrag.bShow;
1040 ReleaseDC (InternalDrag.hwnd, hdcDrag);
1045 /*************************************************************************
1046 * ImageList_Draw [COMCTL32.@]
1051 * himl [I] handle to image list
1053 * hdc [I] handle to device context
1056 * fStyle [I] drawing flags
1067 ImageList_Draw (HIMAGELIST himl, INT i, HDC hdc, INT x, INT y, UINT fStyle)
1069 return ImageList_DrawEx (himl, i, hdc, x, y, 0, 0,
1070 CLR_DEFAULT, CLR_DEFAULT, fStyle);
1074 /*************************************************************************
1075 * ImageList_DrawEx [COMCTL32.@]
1077 * Draws an image and allows to use extended drawing features.
1080 * himl [I] handle to image list
1082 * hdc [I] handle to device context
1087 * rgbBk [I] background color
1088 * rgbFg [I] foreground color
1089 * fStyle [I] drawing flags
1096 * Calls ImageList_DrawIndirect.
1099 * ImageList_DrawIndirect.
1103 ImageList_DrawEx (HIMAGELIST himl, INT i, HDC hdc, INT x, INT y,
1104 INT dx, INT dy, COLORREF rgbBk, COLORREF rgbFg,
1107 IMAGELISTDRAWPARAMS imldp;
1109 ZeroMemory (&imldp, sizeof(imldp));
1110 imldp.cbSize = sizeof(imldp);
1118 imldp.rgbBk = rgbBk;
1119 imldp.rgbFg = rgbFg;
1120 imldp.fStyle = fStyle;
1122 return ImageList_DrawIndirect (&imldp);
1126 static BOOL alpha_blend_image( HIMAGELIST himl, HDC dest_dc, int dest_x, int dest_y,
1127 int src_x, int src_y, int cx, int cy, int alpha )
1132 HBITMAP bmp = 0, mask = 0;
1134 void *bits, *mask_bits;
1136 int i, j, has_alpha = 0;
1138 if (!(hdc = CreateCompatibleDC( 0 ))) return FALSE;
1139 if (!(info = HeapAlloc( GetProcessHeap(), 0, FIELD_OFFSET( BITMAPINFO, bmiColors[256] )))) goto done;
1140 info->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
1141 info->bmiHeader.biWidth = cx;
1142 info->bmiHeader.biHeight = cy;
1143 info->bmiHeader.biPlanes = 1;
1144 info->bmiHeader.biBitCount = 32;
1145 info->bmiHeader.biCompression = BI_RGB;
1146 info->bmiHeader.biSizeImage = cx * cy * 4;
1147 info->bmiHeader.biXPelsPerMeter = 0;
1148 info->bmiHeader.biYPelsPerMeter = 0;
1149 info->bmiHeader.biClrUsed = 0;
1150 info->bmiHeader.biClrImportant = 0;
1151 if (!(bmp = CreateDIBSection( himl->hdcImage, info, DIB_RGB_COLORS, &bits, 0, 0 ))) goto done;
1152 SelectObject( hdc, bmp );
1153 BitBlt( hdc, 0, 0, cx, cy, himl->hdcImage, src_x, src_y, SRCCOPY );
1155 for (i = 0, ptr = bits; i < cx * cy; i++) if ((has_alpha = (ptr[i] & 0xff000000) != 0)) break;
1159 unsigned int width_bytes = (cx + 31) / 32 * 4;
1160 /* generate alpha channel from the mask */
1161 info->bmiHeader.biBitCount = 1;
1162 info->bmiHeader.biSizeImage = width_bytes * cy;
1163 if (!(mask = CreateDIBSection( himl->hdcMask, info, DIB_RGB_COLORS, &mask_bits, 0, 0 )))
1165 SelectObject( hdc, mask );
1166 BitBlt( hdc, 0, 0, cx, cy, himl->hdcMask, src_x, src_y, SRCCOPY );
1167 SelectObject( hdc, bmp );
1168 for (i = 0, ptr = bits; i < cy; i++)
1169 for (j = 0; j < cx; j++, ptr++)
1170 if ((((BYTE *)mask_bits)[i * width_bytes + j / 8] << (j % 8)) & 0x80) *ptr = 0;
1171 else if (!has_alpha) *ptr |= 0xff000000;
1174 func.BlendOp = AC_SRC_OVER;
1175 func.BlendFlags = 0;
1176 func.SourceConstantAlpha = alpha;
1177 func.AlphaFormat = AC_SRC_ALPHA;
1178 ret = GdiAlphaBlend( dest_dc, dest_x, dest_y, cx, cy, hdc, 0, 0, cx, cy, func );
1182 if (bmp) DeleteObject( bmp );
1183 if (mask) DeleteObject( mask );
1184 HeapFree( GetProcessHeap(), 0, info );
1188 /*************************************************************************
1189 * ImageList_DrawIndirect [COMCTL32.@]
1191 * Draws an image using various parameters specified in pimldp.
1194 * pimldp [I] pointer to IMAGELISTDRAWPARAMS structure.
1202 ImageList_DrawIndirect (IMAGELISTDRAWPARAMS *pimldp)
1204 INT cx, cy, nOvlIdx;
1205 DWORD fState, dwRop;
1207 COLORREF oldImageBk, oldImageFg;
1208 HDC hImageDC, hImageListDC, hMaskListDC;
1209 HBITMAP hImageBmp, hOldImageBmp, hBlendMaskBmp;
1210 BOOL bIsTransparent, bBlend, bResult = FALSE, bMask;
1215 if (!pimldp || !(himl = pimldp->himl)) return FALSE;
1216 if (!is_valid(himl)) return FALSE;
1217 if ((pimldp->i < 0) || (pimldp->i >= himl->cCurImage)) return FALSE;
1219 imagelist_point_from_index( himl, pimldp->i, &pt );
1220 pt.x += pimldp->xBitmap;
1221 pt.y += pimldp->yBitmap;
1223 fState = pimldp->cbSize < sizeof(IMAGELISTDRAWPARAMS) ? ILS_NORMAL : pimldp->fState;
1224 fStyle = pimldp->fStyle & ~ILD_OVERLAYMASK;
1225 cx = (pimldp->cx == 0) ? himl->cx : pimldp->cx;
1226 cy = (pimldp->cy == 0) ? himl->cy : pimldp->cy;
1228 bIsTransparent = (fStyle & ILD_TRANSPARENT);
1229 if( pimldp->rgbBk == CLR_NONE )
1230 bIsTransparent = TRUE;
1231 if( ( pimldp->rgbBk == CLR_DEFAULT ) && ( himl->clrBk == CLR_NONE ) )
1232 bIsTransparent = TRUE;
1233 bMask = (himl->flags & ILC_MASK) && (fStyle & ILD_MASK) ;
1234 bBlend = (fStyle & (ILD_BLEND25 | ILD_BLEND50) ) && !bMask;
1236 TRACE("himl(%p) hbmMask(%p) iImage(%d) x(%d) y(%d) cx(%d) cy(%d)\n",
1237 himl, himl->hbmMask, pimldp->i, pimldp->x, pimldp->y, cx, cy);
1239 /* we will use these DCs to access the images and masks in the ImageList */
1240 hImageListDC = himl->hdcImage;
1241 hMaskListDC = himl->hdcMask;
1243 /* these will accumulate the image and mask for the image we're drawing */
1244 hImageDC = CreateCompatibleDC( pimldp->hdcDst );
1245 hImageBmp = CreateCompatibleBitmap( pimldp->hdcDst, cx, cy );
1246 hBlendMaskBmp = bBlend ? CreateBitmap(cx, cy, 1, 1, NULL) : 0;
1248 /* Create a compatible DC. */
1249 if (!hImageListDC || !hImageDC || !hImageBmp ||
1250 (bBlend && !hBlendMaskBmp) || (himl->hbmMask && !hMaskListDC))
1253 hOldImageBmp = SelectObject(hImageDC, hImageBmp);
1256 * To obtain a transparent look, background color should be set
1257 * to white and foreground color to black when blitting the
1260 oldImageFg = SetTextColor( hImageDC, RGB( 0, 0, 0 ) );
1261 oldImageBk = SetBkColor( hImageDC, RGB( 0xff, 0xff, 0xff ) );
1263 if (fState & ILS_ALPHA)
1269 bResult = alpha_blend_image( himl, pimldp->hdcDst, pimldp->x, pimldp->y,
1270 pt.x, pt.y, cx, cy, pimldp->Frame );
1273 colour = pimldp->rgbBk;
1274 if (colour == CLR_DEFAULT) colour = himl->clrBk;
1275 if (colour == CLR_NONE) colour = GetBkColor( pimldp->hdcDst );
1277 hOldBrush = SelectObject (hImageDC, CreateSolidBrush (colour));
1278 PatBlt( hImageDC, 0, 0, cx, cy, PATCOPY );
1279 alpha_blend_image( himl, hImageDC, 0, 0, pt.x, pt.y, cx, cy, pimldp->Frame );
1280 DeleteObject (SelectObject (hImageDC, hOldBrush));
1281 bResult = BitBlt( pimldp->hdcDst, pimldp->x, pimldp->y, cx, cy, hImageDC, 0, 0, SRCCOPY );
1286 * Draw the initial image
1289 if (himl->hbmMask) {
1290 hOldBrush = SelectObject (hImageDC, CreateSolidBrush (GetTextColor(pimldp->hdcDst)));
1291 PatBlt( hImageDC, 0, 0, cx, cy, PATCOPY );
1292 BitBlt(hImageDC, 0, 0, cx, cy, hMaskListDC, pt.x, pt.y, SRCPAINT);
1293 DeleteObject (SelectObject (hImageDC, hOldBrush));
1294 if( bIsTransparent )
1296 BitBlt ( pimldp->hdcDst, pimldp->x, pimldp->y, cx, cy, hImageDC, 0, 0, SRCAND);
1301 hOldBrush = SelectObject (hImageDC, GetStockObject(BLACK_BRUSH));
1302 PatBlt( hImageDC, 0, 0, cx, cy, PATCOPY);
1303 SelectObject(hImageDC, hOldBrush);
1306 /* blend the image with the needed solid background */
1307 COLORREF colour = RGB(0,0,0);
1309 if( !bIsTransparent )
1311 colour = pimldp->rgbBk;
1312 if( colour == CLR_DEFAULT )
1313 colour = himl->clrBk;
1314 if( colour == CLR_NONE )
1315 colour = GetBkColor(pimldp->hdcDst);
1318 hOldBrush = SelectObject (hImageDC, CreateSolidBrush (colour));
1319 PatBlt( hImageDC, 0, 0, cx, cy, PATCOPY );
1322 BitBlt( hImageDC, 0, 0, cx, cy, hMaskListDC, pt.x, pt.y, SRCAND );
1323 BitBlt( hImageDC, 0, 0, cx, cy, hImageListDC, pt.x, pt.y, SRCPAINT );
1326 BitBlt( hImageDC, 0, 0, cx, cy, hImageListDC, pt.x, pt.y, SRCCOPY);
1327 DeleteObject (SelectObject (hImageDC, hOldBrush));
1330 /* Time for blending, if required */
1333 COLORREF clrBlend = pimldp->rgbFg;
1334 HDC hBlendMaskDC = hImageListDC;
1337 /* Create the blend Mask */
1338 hOldBitmap = SelectObject(hBlendMaskDC, hBlendMaskBmp);
1339 hBlendBrush = fStyle & ILD_BLEND50 ? himl->hbrBlend50 : himl->hbrBlend25;
1340 hOldBrush = SelectObject(hBlendMaskDC, hBlendBrush);
1341 PatBlt(hBlendMaskDC, 0, 0, cx, cy, PATCOPY);
1342 SelectObject(hBlendMaskDC, hOldBrush);
1344 /* Modify the blend mask if an Image Mask exist */
1346 BitBlt(hBlendMaskDC, 0, 0, cx, cy, hMaskListDC, pt.x, pt.y, 0x220326); /* NOTSRCAND */
1347 BitBlt(hBlendMaskDC, 0, 0, cx, cy, hBlendMaskDC, 0, 0, NOTSRCCOPY);
1350 /* now apply blend to the current image given the BlendMask */
1351 if (clrBlend == CLR_DEFAULT) clrBlend = GetSysColor (COLOR_HIGHLIGHT);
1352 else if (clrBlend == CLR_NONE) clrBlend = GetTextColor (pimldp->hdcDst);
1353 hOldBrush = SelectObject (hImageDC, CreateSolidBrush(clrBlend));
1354 BitBlt (hImageDC, 0, 0, cx, cy, hBlendMaskDC, 0, 0, 0xB8074A); /* PSDPxax */
1355 DeleteObject(SelectObject(hImageDC, hOldBrush));
1356 SelectObject(hBlendMaskDC, hOldBitmap);
1359 /* Now do the overlay image, if any */
1360 nOvlIdx = (pimldp->fStyle & ILD_OVERLAYMASK) >> 8;
1361 if ( (nOvlIdx >= 1) && (nOvlIdx <= MAX_OVERLAYIMAGE)) {
1362 nOvlIdx = himl->nOvlIdx[nOvlIdx - 1];
1363 if ((nOvlIdx >= 0) && (nOvlIdx < himl->cCurImage)) {
1365 imagelist_point_from_index( himl, nOvlIdx, &ptOvl );
1366 ptOvl.x += pimldp->xBitmap;
1367 if (himl->hbmMask && !(fStyle & ILD_IMAGE))
1368 BitBlt (hImageDC, 0, 0, cx, cy, hMaskListDC, ptOvl.x, ptOvl.y, SRCAND);
1369 BitBlt (hImageDC, 0, 0, cx, cy, hImageListDC, ptOvl.x, ptOvl.y, SRCPAINT);
1373 if (fState & ILS_SATURATE) FIXME("ILS_SATURATE: unimplemented!\n");
1374 if (fState & ILS_GLOW) FIXME("ILS_GLOW: unimplemented!\n");
1375 if (fState & ILS_SHADOW) FIXME("ILS_SHADOW: unimplemented!\n");
1377 if (fStyle & ILD_PRESERVEALPHA) FIXME("ILD_PRESERVEALPHA: unimplemented!\n");
1378 if (fStyle & ILD_SCALE) FIXME("ILD_SCALE: unimplemented!\n");
1379 if (fStyle & ILD_DPISCALE) FIXME("ILD_DPISCALE: unimplemented!\n");
1381 /* now copy the image to the screen */
1383 if (himl->hbmMask && bIsTransparent ) {
1384 COLORREF oldDstFg = SetTextColor(pimldp->hdcDst, RGB( 0, 0, 0 ) );
1385 COLORREF oldDstBk = SetBkColor(pimldp->hdcDst, RGB( 0xff, 0xff, 0xff ));
1386 BitBlt (pimldp->hdcDst, pimldp->x, pimldp->y, cx, cy, hMaskListDC, pt.x, pt.y, SRCAND);
1387 SetBkColor(pimldp->hdcDst, oldDstBk);
1388 SetTextColor(pimldp->hdcDst, oldDstFg);
1391 if (fStyle & ILD_ROP) dwRop = pimldp->dwRop;
1392 BitBlt (pimldp->hdcDst, pimldp->x, pimldp->y, cx, cy, hImageDC, 0, 0, dwRop);
1396 /* cleanup the mess */
1397 SetBkColor(hImageDC, oldImageBk);
1398 SetTextColor(hImageDC, oldImageFg);
1399 SelectObject(hImageDC, hOldImageBmp);
1401 DeleteObject(hBlendMaskBmp);
1402 DeleteObject(hImageBmp);
1409 /*************************************************************************
1410 * ImageList_Duplicate [COMCTL32.@]
1412 * Duplicates an image list.
1415 * himlSrc [I] source image list handle
1418 * Success: Handle of duplicated image list.
1423 ImageList_Duplicate (HIMAGELIST himlSrc)
1427 if (!is_valid(himlSrc)) {
1428 ERR("Invalid image list handle!\n");
1432 himlDst = ImageList_Create (himlSrc->cx, himlSrc->cy, himlSrc->flags,
1433 himlSrc->cInitial, himlSrc->cGrow);
1439 imagelist_get_bitmap_size(himlSrc, himlSrc->cCurImage, &sz);
1440 BitBlt (himlDst->hdcImage, 0, 0, sz.cx, sz.cy,
1441 himlSrc->hdcImage, 0, 0, SRCCOPY);
1443 if (himlDst->hbmMask)
1444 BitBlt (himlDst->hdcMask, 0, 0, sz.cx, sz.cy,
1445 himlSrc->hdcMask, 0, 0, SRCCOPY);
1447 himlDst->cCurImage = himlSrc->cCurImage;
1448 himlDst->cMaxImage = himlSrc->cMaxImage;
1454 /*************************************************************************
1455 * ImageList_EndDrag [COMCTL32.@]
1457 * Finishes a drag operation.
1468 ImageList_EndDrag (void)
1470 /* cleanup the InternalDrag struct */
1471 InternalDrag.hwnd = 0;
1472 ImageList_Destroy (InternalDrag.himl);
1473 InternalDrag.himl = 0;
1476 InternalDrag.dxHotspot = 0;
1477 InternalDrag.dyHotspot = 0;
1478 InternalDrag.bShow = FALSE;
1479 DeleteObject(InternalDrag.hbmBg);
1480 InternalDrag.hbmBg = 0;
1484 /*************************************************************************
1485 * ImageList_GetBkColor [COMCTL32.@]
1487 * Returns the background color of an image list.
1490 * himl [I] Image list handle.
1493 * Success: background color
1498 ImageList_GetBkColor (HIMAGELIST himl)
1500 return himl ? himl->clrBk : CLR_NONE;
1504 /*************************************************************************
1505 * ImageList_GetDragImage [COMCTL32.@]
1507 * Returns the handle to the internal drag image list.
1510 * ppt [O] Pointer to the drag position. Can be NULL.
1511 * pptHotspot [O] Pointer to the position of the hot spot. Can be NULL.
1514 * Success: Handle of the drag image list.
1519 ImageList_GetDragImage (POINT *ppt, POINT *pptHotspot)
1521 if (is_valid(InternalDrag.himl)) {
1523 ppt->x = InternalDrag.x;
1524 ppt->y = InternalDrag.y;
1527 pptHotspot->x = InternalDrag.dxHotspot;
1528 pptHotspot->y = InternalDrag.dyHotspot;
1530 return (InternalDrag.himl);
1537 /*************************************************************************
1538 * ImageList_GetFlags [COMCTL32.@]
1540 * Gets the flags of the specified image list.
1543 * himl [I] Handle to image list
1553 ImageList_GetFlags(HIMAGELIST himl)
1555 TRACE("%p\n", himl);
1557 return is_valid(himl) ? himl->flags : 0;
1561 /*************************************************************************
1562 * ImageList_GetIcon [COMCTL32.@]
1564 * Creates an icon from a masked image of an image list.
1567 * himl [I] handle to image list
1569 * flags [I] drawing style flags
1572 * Success: icon handle
1577 ImageList_GetIcon (HIMAGELIST himl, INT i, UINT fStyle)
1581 HBITMAP hOldDstBitmap;
1585 TRACE("%p %d %d\n", himl, i, fStyle);
1586 if (!is_valid(himl) || (i < 0) || (i >= himl->cCurImage)) return NULL;
1592 /* create colour bitmap */
1594 ii.hbmColor = CreateCompatibleBitmap(hdcDst, himl->cx, himl->cy);
1595 ReleaseDC(0, hdcDst);
1597 hdcDst = CreateCompatibleDC(0);
1599 imagelist_point_from_index( himl, i, &pt );
1602 ii.hbmMask = CreateBitmap (himl->cx, himl->cy, 1, 1, NULL);
1603 hOldDstBitmap = SelectObject (hdcDst, ii.hbmMask);
1604 if (himl->hbmMask) {
1605 BitBlt (hdcDst, 0, 0, himl->cx, himl->cy,
1606 himl->hdcMask, pt.x, pt.y, SRCCOPY);
1609 PatBlt (hdcDst, 0, 0, himl->cx, himl->cy, BLACKNESS);
1612 SelectObject (hdcDst, ii.hbmColor);
1613 BitBlt (hdcDst, 0, 0, himl->cx, himl->cy,
1614 himl->hdcImage, pt.x, pt.y, SRCCOPY);
1617 * CreateIconIndirect requires us to deselect the bitmaps from
1618 * the DCs before calling
1620 SelectObject(hdcDst, hOldDstBitmap);
1622 hIcon = CreateIconIndirect (&ii);
1624 DeleteObject (ii.hbmMask);
1625 DeleteObject (ii.hbmColor);
1632 /*************************************************************************
1633 * ImageList_GetIconSize [COMCTL32.@]
1635 * Retrieves the size of an image in an image list.
1638 * himl [I] handle to image list
1639 * cx [O] pointer to the image width.
1640 * cy [O] pointer to the image height.
1647 * All images in an image list have the same size.
1651 ImageList_GetIconSize (HIMAGELIST himl, INT *cx, INT *cy)
1653 if (!is_valid(himl))
1655 if ((himl->cx <= 0) || (himl->cy <= 0))
1667 /*************************************************************************
1668 * ImageList_GetImageCount [COMCTL32.@]
1670 * Returns the number of images in an image list.
1673 * himl [I] handle to image list
1676 * Success: Number of images.
1681 ImageList_GetImageCount (HIMAGELIST himl)
1683 if (!is_valid(himl))
1686 return himl->cCurImage;
1690 /*************************************************************************
1691 * ImageList_GetImageInfo [COMCTL32.@]
1693 * Returns information about an image in an image list.
1696 * himl [I] handle to image list
1698 * pImageInfo [O] pointer to the image information
1706 ImageList_GetImageInfo (HIMAGELIST himl, INT i, IMAGEINFO *pImageInfo)
1710 if (!is_valid(himl) || (pImageInfo == NULL))
1712 if ((i < 0) || (i >= himl->cCurImage))
1715 pImageInfo->hbmImage = himl->hbmImage;
1716 pImageInfo->hbmMask = himl->hbmMask;
1718 imagelist_point_from_index( himl, i, &pt );
1719 pImageInfo->rcImage.top = pt.y;
1720 pImageInfo->rcImage.bottom = pt.y + himl->cy;
1721 pImageInfo->rcImage.left = pt.x;
1722 pImageInfo->rcImage.right = pt.x + himl->cx;
1728 /*************************************************************************
1729 * ImageList_GetImageRect [COMCTL32.@]
1731 * Retrieves the rectangle of the specified image in an image list.
1734 * himl [I] handle to image list
1736 * lpRect [O] pointer to the image rectangle
1743 * This is an UNDOCUMENTED function!!!
1747 ImageList_GetImageRect (HIMAGELIST himl, INT i, LPRECT lpRect)
1751 if (!is_valid(himl) || (lpRect == NULL))
1753 if ((i < 0) || (i >= himl->cCurImage))
1756 imagelist_point_from_index( himl, i, &pt );
1757 lpRect->left = pt.x;
1759 lpRect->right = pt.x + himl->cx;
1760 lpRect->bottom = pt.y + himl->cy;
1766 /*************************************************************************
1767 * ImageList_LoadImage [COMCTL32.@]
1768 * ImageList_LoadImageA [COMCTL32.@]
1770 * Creates an image list from a bitmap, icon or cursor.
1772 * See ImageList_LoadImageW.
1776 ImageList_LoadImageA (HINSTANCE hi, LPCSTR lpbmp, INT cx, INT cGrow,
1777 COLORREF clrMask, UINT uType, UINT uFlags)
1783 if (IS_INTRESOURCE(lpbmp))
1784 return ImageList_LoadImageW(hi, (LPCWSTR)lpbmp, cx, cGrow, clrMask,
1787 len = MultiByteToWideChar(CP_ACP, 0, lpbmp, -1, NULL, 0);
1788 lpbmpW = Alloc(len * sizeof(WCHAR));
1789 MultiByteToWideChar(CP_ACP, 0, lpbmp, -1, lpbmpW, len);
1791 himl = ImageList_LoadImageW(hi, lpbmpW, cx, cGrow, clrMask, uType, uFlags);
1797 /*************************************************************************
1798 * ImageList_LoadImageW [COMCTL32.@]
1800 * Creates an image list from a bitmap, icon or cursor.
1803 * hi [I] instance handle
1804 * lpbmp [I] name or id of the image
1805 * cx [I] width of each image
1806 * cGrow [I] number of images to expand
1807 * clrMask [I] mask color
1808 * uType [I] type of image to load
1809 * uFlags [I] loading flags
1812 * Success: handle to the loaded image list
1820 ImageList_LoadImageW (HINSTANCE hi, LPCWSTR lpbmp, INT cx, INT cGrow,
1821 COLORREF clrMask, UINT uType, UINT uFlags)
1823 HIMAGELIST himl = NULL;
1827 handle = LoadImageW (hi, lpbmp, uType, 0, 0, uFlags);
1829 WARN("Couldn't load image\n");
1833 if (uType == IMAGE_BITMAP) {
1835 GetObjectW (handle, sizeof(BITMAP), &bmp);
1837 /* To match windows behavior, if cx is set to zero and
1838 the flag DI_DEFAULTSIZE is specified, cx becomes the
1839 system metric value for icons. If the flag is not specified
1840 the function sets the size to the height of the bitmap */
1843 if (uFlags & DI_DEFAULTSIZE)
1844 cx = GetSystemMetrics (SM_CXICON);
1849 nImageCount = bmp.bmWidth / cx;
1851 himl = ImageList_Create (cx, bmp.bmHeight, ILC_MASK | ILC_COLOR,
1852 nImageCount, cGrow);
1854 DeleteObject (handle);
1857 ImageList_AddMasked (himl, handle, clrMask);
1859 else if ((uType == IMAGE_ICON) || (uType == IMAGE_CURSOR)) {
1863 GetIconInfo (handle, &ii);
1864 GetObjectW (ii.hbmColor, sizeof(BITMAP), &bmp);
1865 himl = ImageList_Create (bmp.bmWidth, bmp.bmHeight,
1866 ILC_MASK | ILC_COLOR, 1, cGrow);
1868 DeleteObject (ii.hbmColor);
1869 DeleteObject (ii.hbmMask);
1870 DeleteObject (handle);
1873 ImageList_Add (himl, ii.hbmColor, ii.hbmMask);
1874 DeleteObject (ii.hbmColor);
1875 DeleteObject (ii.hbmMask);
1878 DeleteObject (handle);
1884 /*************************************************************************
1885 * ImageList_Merge [COMCTL32.@]
1887 * Create an image list containing a merged image from two image lists.
1890 * himl1 [I] handle to first image list
1891 * i1 [I] first image index
1892 * himl2 [I] handle to second image list
1893 * i2 [I] second image index
1894 * dx [I] X offset of the second image relative to the first.
1895 * dy [I] Y offset of the second image relative to the first.
1898 * Success: The newly created image list. It contains a single image
1899 * consisting of the second image merged with the first.
1900 * Failure: NULL, if either himl1 or himl2 are invalid.
1903 * - The returned image list should be deleted by the caller using
1904 * ImageList_Destroy() when it is no longer required.
1905 * - If either i1 or i2 are not valid image indices they will be treated
1909 ImageList_Merge (HIMAGELIST himl1, INT i1, HIMAGELIST himl2, INT i2,
1912 HIMAGELIST himlDst = NULL;
1914 INT xOff1, yOff1, xOff2, yOff2;
1917 TRACE("(himl1=%p i1=%d himl2=%p i2=%d dx=%d dy=%d)\n", himl1, i1, himl2,
1920 if (!is_valid(himl1) || !is_valid(himl2))
1924 cxDst = max (himl1->cx, dx + himl2->cx);
1929 cxDst = max (himl2->cx, himl1->cx - dx);
1934 cxDst = max (himl1->cx, himl2->cx);
1940 cyDst = max (himl1->cy, dy + himl2->cy);
1945 cyDst = max (himl2->cy, himl1->cy - dy);
1950 cyDst = max (himl1->cy, himl2->cy);
1955 himlDst = ImageList_Create (cxDst, cyDst, ILC_MASK | ILC_COLOR, 1, 1);
1959 imagelist_point_from_index( himl1, i1, &pt1 );
1960 imagelist_point_from_index( himl1, i2, &pt2 );
1963 BitBlt (himlDst->hdcImage, 0, 0, cxDst, cyDst, himl1->hdcImage, 0, 0, BLACKNESS);
1964 if (i1 >= 0 && i1 < himl1->cCurImage)
1965 BitBlt (himlDst->hdcImage, xOff1, yOff1, himl1->cx, himl1->cy, himl1->hdcImage, pt1.x, pt1.y, SRCCOPY);
1966 if (i2 >= 0 && i2 < himl2->cCurImage)
1968 BitBlt (himlDst->hdcImage, xOff2, yOff2, himl2->cx, himl2->cy, himl2->hdcMask , pt2.x, pt2.y, SRCAND);
1969 BitBlt (himlDst->hdcImage, xOff2, yOff2, himl2->cx, himl2->cy, himl2->hdcImage, pt2.x, pt2.y, SRCPAINT);
1973 BitBlt (himlDst->hdcMask, 0, 0, cxDst, cyDst, himl1->hdcMask, 0, 0, WHITENESS);
1974 if (i1 >= 0 && i1 < himl1->cCurImage)
1975 BitBlt (himlDst->hdcMask, xOff1, yOff1, himl1->cx, himl1->cy, himl1->hdcMask, pt1.x, pt1.y, SRCCOPY);
1976 if (i2 >= 0 && i2 < himl2->cCurImage)
1977 BitBlt (himlDst->hdcMask, xOff2, yOff2, himl2->cx, himl2->cy, himl2->hdcMask, pt2.x, pt2.y, SRCAND);
1979 himlDst->cCurImage = 1;
1986 /***********************************************************************
1987 * DIB_GetDIBWidthBytes
1989 * Return the width of a DIB bitmap in bytes. DIB bitmap data is 32-bit aligned.
1991 static int DIB_GetDIBWidthBytes( int width, int depth )
1997 case 1: words = (width + 31) / 32; break;
1998 case 4: words = (width + 7) / 8; break;
1999 case 8: words = (width + 3) / 4; break;
2001 case 16: words = (width + 1) / 2; break;
2002 case 24: words = (width * 3 + 3)/4; break;
2005 WARN("(%d): Unsupported depth\n", depth );
2014 /***********************************************************************
2015 * DIB_GetDIBImageBytes
2017 * Return the number of bytes used to hold the image in a DIB bitmap.
2019 static int DIB_GetDIBImageBytes( int width, int height, int depth )
2021 return DIB_GetDIBWidthBytes( width, depth ) * abs( height );
2025 /* helper for ImageList_Read, see comments below */
2026 static BOOL _read_bitmap(HDC hdcIml, LPSTREAM pstm)
2028 BITMAPFILEHEADER bmfh;
2029 int bitsperpixel, palspace;
2030 char bmi_buf[sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD) * 256];
2031 LPBITMAPINFO bmi = (LPBITMAPINFO)bmi_buf;
2035 if (FAILED(IStream_Read ( pstm, &bmfh, sizeof(bmfh), NULL)))
2038 if (bmfh.bfType != (('M'<<8)|'B'))
2041 if (FAILED(IStream_Read ( pstm, &bmi->bmiHeader, sizeof(bmi->bmiHeader), NULL)))
2044 if ((bmi->bmiHeader.biSize != sizeof(bmi->bmiHeader)))
2047 TRACE("width %u, height %u, planes %u, bpp %u\n",
2048 bmi->bmiHeader.biWidth, bmi->bmiHeader.biHeight,
2049 bmi->bmiHeader.biPlanes, bmi->bmiHeader.biBitCount);
2051 bitsperpixel = bmi->bmiHeader.biPlanes * bmi->bmiHeader.biBitCount;
2052 if (bitsperpixel<=8)
2053 palspace = (1<<bitsperpixel)*sizeof(RGBQUAD);
2057 bmi->bmiHeader.biSizeImage = DIB_GetDIBImageBytes(bmi->bmiHeader.biWidth, bmi->bmiHeader.biHeight, bitsperpixel);
2059 /* read the palette right after the end of the bitmapinfoheader */
2060 if (palspace && FAILED(IStream_Read(pstm, bmi->bmiColors, palspace, NULL)))
2063 bits = Alloc(bmi->bmiHeader.biSizeImage);
2066 if (FAILED(IStream_Read(pstm, bits, bmi->bmiHeader.biSizeImage, NULL)))
2069 if (!StretchDIBits(hdcIml, 0, 0, bmi->bmiHeader.biWidth, bmi->bmiHeader.biHeight,
2070 0, 0, bmi->bmiHeader.biWidth, bmi->bmiHeader.biHeight,
2071 bits, bmi, DIB_RGB_COLORS, SRCCOPY))
2080 /*************************************************************************
2081 * ImageList_Read [COMCTL32.@]
2083 * Reads an image list from a stream.
2086 * pstm [I] pointer to a stream
2089 * Success: handle to image list
2092 * The format is like this:
2093 * ILHEAD ilheadstruct;
2095 * for the color image part:
2096 * BITMAPFILEHEADER bmfh;
2097 * BITMAPINFOHEADER bmih;
2098 * only if it has a palette:
2099 * RGBQUAD rgbs[nr_of_paletted_colors];
2101 * BYTE colorbits[imagesize];
2103 * the following only if the ILC_MASK bit is set in ILHEAD.ilFlags:
2104 * BITMAPFILEHEADER bmfh_mask;
2105 * BITMAPINFOHEADER bmih_mask;
2106 * only if it has a palette (it usually does not):
2107 * RGBQUAD rgbs[nr_of_paletted_colors];
2109 * BYTE maskbits[imagesize];
2111 HIMAGELIST WINAPI ImageList_Read (LPSTREAM pstm)
2117 TRACE("%p\n", pstm);
2119 if (FAILED(IStream_Read (pstm, &ilHead, sizeof(ILHEAD), NULL)))
2121 if (ilHead.usMagic != (('L' << 8) | 'I'))
2123 if (ilHead.usVersion != 0x101) /* probably version? */
2126 TRACE("cx %u, cy %u, flags 0x%04x, cCurImage %u, cMaxImage %u\n",
2127 ilHead.cx, ilHead.cy, ilHead.flags, ilHead.cCurImage, ilHead.cMaxImage);
2129 himl = ImageList_Create(ilHead.cx, ilHead.cy, ilHead.flags, ilHead.cCurImage, ilHead.cMaxImage);
2133 if (!_read_bitmap(himl->hdcImage, pstm))
2135 WARN("failed to read bitmap from stream\n");
2138 if (ilHead.flags & ILC_MASK)
2140 if (!_read_bitmap(himl->hdcMask, pstm))
2142 WARN("failed to read mask bitmap from stream\n");
2147 himl->cCurImage = ilHead.cCurImage;
2148 himl->cMaxImage = ilHead.cMaxImage;
2150 ImageList_SetBkColor(himl,ilHead.bkcolor);
2152 ImageList_SetOverlayImage(himl,ilHead.ovls[i],i+1);
2157 /*************************************************************************
2158 * ImageList_Remove [COMCTL32.@]
2160 * Removes an image from an image list
2163 * himl [I] image list handle
2170 * FIXME: as the image list storage test shows, native comctl32 simply shifts
2171 * images without creating a new bitmap.
2174 ImageList_Remove (HIMAGELIST himl, INT i)
2176 HBITMAP hbmNewImage, hbmNewMask;
2180 TRACE("(himl=%p i=%d)\n", himl, i);
2182 if (!is_valid(himl)) {
2183 ERR("Invalid image list handle!\n");
2187 if ((i < -1) || (i >= himl->cCurImage)) {
2188 TRACE("index out of range! %d\n", i);
2196 if (himl->cCurImage == 0) {
2197 /* remove all on empty ImageList is allowed */
2198 TRACE("remove all on empty ImageList!\n");
2202 himl->cMaxImage = himl->cInitial + himl->cGrow - 1;
2203 himl->cCurImage = 0;
2204 for (nCount = 0; nCount < MAX_OVERLAYIMAGE; nCount++)
2205 himl->nOvlIdx[nCount] = -1;
2207 hbmNewImage = ImageList_CreateImage(himl->hdcImage, himl, himl->cMaxImage);
2208 SelectObject (himl->hdcImage, hbmNewImage);
2209 DeleteObject (himl->hbmImage);
2210 himl->hbmImage = hbmNewImage;
2212 if (himl->hbmMask) {
2214 imagelist_get_bitmap_size(himl, himl->cMaxImage, &sz);
2215 hbmNewMask = CreateBitmap (sz.cx, sz.cy, 1, 1, NULL);
2216 SelectObject (himl->hdcMask, hbmNewMask);
2217 DeleteObject (himl->hbmMask);
2218 himl->hbmMask = hbmNewMask;
2222 /* delete one image */
2223 TRACE("Remove single image! %d\n", i);
2225 /* create new bitmap(s) */
2226 TRACE(" - Number of images: %d / %d (Old/New)\n",
2227 himl->cCurImage, himl->cCurImage - 1);
2229 hbmNewImage = ImageList_CreateImage(himl->hdcImage, himl, himl->cMaxImage);
2231 imagelist_get_bitmap_size(himl, himl->cMaxImage, &sz );
2233 hbmNewMask = CreateBitmap (sz.cx, sz.cy, 1, 1, NULL);
2235 hbmNewMask = 0; /* Just to keep compiler happy! */
2237 hdcBmp = CreateCompatibleDC (0);
2239 /* copy all images and masks prior to the "removed" image */
2241 TRACE("Pre image copy: Copy %d images\n", i);
2243 SelectObject (hdcBmp, hbmNewImage);
2244 imagelist_copy_images( himl, himl->hdcImage, hdcBmp, 0, i, 0 );
2246 if (himl->hbmMask) {
2247 SelectObject (hdcBmp, hbmNewMask);
2248 imagelist_copy_images( himl, himl->hdcMask, hdcBmp, 0, i, 0 );
2252 /* copy all images and masks behind the removed image */
2253 if (i < himl->cCurImage - 1) {
2254 TRACE("Post image copy!\n");
2256 SelectObject (hdcBmp, hbmNewImage);
2257 imagelist_copy_images( himl, himl->hdcImage, hdcBmp, i + 1,
2258 (himl->cCurImage - i), i );
2260 if (himl->hbmMask) {
2261 SelectObject (hdcBmp, hbmNewMask);
2262 imagelist_copy_images( himl, himl->hdcMask, hdcBmp, i + 1,
2263 (himl->cCurImage - i), i );
2269 /* delete old images and insert new ones */
2270 SelectObject (himl->hdcImage, hbmNewImage);
2271 DeleteObject (himl->hbmImage);
2272 himl->hbmImage = hbmNewImage;
2273 if (himl->hbmMask) {
2274 SelectObject (himl->hdcMask, hbmNewMask);
2275 DeleteObject (himl->hbmMask);
2276 himl->hbmMask = hbmNewMask;
2286 /*************************************************************************
2287 * ImageList_Replace [COMCTL32.@]
2289 * Replaces an image in an image list with a new image.
2292 * himl [I] handle to image list
2294 * hbmImage [I] handle to image bitmap
2295 * hbmMask [I] handle to mask bitmap. Can be NULL.
2303 ImageList_Replace (HIMAGELIST himl, INT i, HBITMAP hbmImage,
2310 TRACE("%p %d %p %p\n", himl, i, hbmImage, hbmMask);
2312 if (!is_valid(himl)) {
2313 ERR("Invalid image list handle!\n");
2317 if ((i >= himl->cMaxImage) || (i < 0)) {
2318 ERR("Invalid image index!\n");
2322 if (!GetObjectW(hbmImage, sizeof(BITMAP), &bmp))
2325 hdcImage = CreateCompatibleDC (0);
2328 SelectObject (hdcImage, hbmImage);
2330 if (add_with_alpha( himl, hdcImage, i, 1, bmp.bmWidth, bmp.bmHeight, hbmImage, hbmMask ))
2333 imagelist_point_from_index(himl, i, &pt);
2334 StretchBlt (himl->hdcImage, pt.x, pt.y, himl->cx, himl->cy,
2335 hdcImage, 0, 0, bmp.bmWidth, bmp.bmHeight, SRCCOPY);
2340 HBITMAP hOldBitmapTemp;
2342 hdcTemp = CreateCompatibleDC(0);
2343 hOldBitmapTemp = SelectObject(hdcTemp, hbmMask);
2345 StretchBlt (himl->hdcMask, pt.x, pt.y, himl->cx, himl->cy,
2346 hdcTemp, 0, 0, bmp.bmWidth, bmp.bmHeight, SRCCOPY);
2347 SelectObject(hdcTemp, hOldBitmapTemp);
2350 /* Remove the background from the image
2352 BitBlt (himl->hdcImage, pt.x, pt.y, bmp.bmWidth, bmp.bmHeight,
2353 himl->hdcMask, pt.x, pt.y, 0x220326); /* NOTSRCAND */
2357 DeleteDC (hdcImage);
2363 /*************************************************************************
2364 * ImageList_ReplaceIcon [COMCTL32.@]
2366 * Replaces an image in an image list using an icon.
2369 * himl [I] handle to image list
2371 * hIcon [I] handle to icon
2374 * Success: index of the replaced image
2379 ImageList_ReplaceIcon (HIMAGELIST himl, INT nIndex, HICON hIcon)
2388 TRACE("(%p %d %p)\n", himl, nIndex, hIcon);
2390 if (!is_valid(himl)) {
2391 ERR("invalid image list\n");
2394 if ((nIndex >= himl->cMaxImage) || (nIndex < -1)) {
2395 ERR("invalid image index %d / %d\n", nIndex, himl->cMaxImage);
2399 hBestFitIcon = CopyImage(
2402 LR_COPYFROMRESOURCE);
2403 /* the above will fail if the icon wasn't loaded from a resource, so try
2404 * again without LR_COPYFROMRESOURCE flag */
2406 hBestFitIcon = CopyImage(
2413 ret = GetIconInfo (hBestFitIcon, &ii);
2415 DestroyIcon(hBestFitIcon);
2419 ret = GetObjectW (ii.hbmMask, sizeof(BITMAP), &bmp);
2421 ERR("couldn't get mask bitmap info\n");
2423 DeleteObject (ii.hbmColor);
2425 DeleteObject (ii.hbmMask);
2426 DestroyIcon(hBestFitIcon);
2431 if (himl->cCurImage + 1 > himl->cMaxImage)
2432 IMAGELIST_InternalExpandBitmaps(himl, 1);
2434 nIndex = himl->cCurImage;
2438 hdcImage = CreateCompatibleDC (0);
2439 TRACE("hdcImage=%p\n", hdcImage);
2441 ERR("invalid hdcImage!\n");
2443 if (himl->uBitsPixel == 32)
2447 UINT height = bmp.bmHeight / 2;
2448 HDC hdcMask = CreateCompatibleDC( 0 );
2449 HBITMAP color = CreateBitmap( bmp.bmWidth, height, 1, 1, NULL );
2450 SelectObject( hdcImage, color );
2451 SelectObject( hdcMask, ii.hbmMask );
2452 BitBlt( hdcImage, 0, 0, bmp.bmWidth, height, hdcMask, 0, height, SRCCOPY );
2453 add_with_alpha( himl, hdcImage, nIndex, 1, bmp.bmWidth, height, color, ii.hbmMask );
2454 DeleteDC( hdcMask );
2455 DeleteObject( color );
2457 else add_with_alpha( himl, hdcImage, nIndex, 1, bmp.bmWidth, bmp.bmHeight, ii.hbmColor, ii.hbmMask );
2462 imagelist_point_from_index(himl, nIndex, &pt);
2464 SetTextColor(himl->hdcImage, RGB(0,0,0));
2465 SetBkColor (himl->hdcImage, RGB(255,255,255));
2469 SelectObject (hdcImage, ii.hbmColor);
2470 StretchBlt (himl->hdcImage, pt.x, pt.y, himl->cx, himl->cy,
2471 hdcImage, 0, 0, bmp.bmWidth, bmp.bmHeight, SRCCOPY);
2474 SelectObject (hdcImage, ii.hbmMask);
2475 StretchBlt (himl->hdcMask, pt.x, pt.y, himl->cx, himl->cy,
2476 hdcImage, 0, 0, bmp.bmWidth, bmp.bmHeight, SRCCOPY);
2481 UINT height = bmp.bmHeight / 2;
2482 SelectObject (hdcImage, ii.hbmMask);
2483 StretchBlt (himl->hdcImage, pt.x, pt.y, himl->cx, himl->cy,
2484 hdcImage, 0, height, bmp.bmWidth, height, SRCCOPY);
2486 StretchBlt (himl->hdcMask, pt.x, pt.y, himl->cx, himl->cy,
2487 hdcImage, 0, 0, bmp.bmWidth, height, SRCCOPY);
2491 DestroyIcon(hBestFitIcon);
2493 DeleteDC (hdcImage);
2495 DeleteObject (ii.hbmColor);
2497 DeleteObject (ii.hbmMask);
2499 TRACE("Insert index = %d, himl->cCurImage = %d\n", nIndex, himl->cCurImage);
2504 /*************************************************************************
2505 * ImageList_SetBkColor [COMCTL32.@]
2507 * Sets the background color of an image list.
2510 * himl [I] handle to image list
2511 * clrBk [I] background color
2514 * Success: previous background color
2519 ImageList_SetBkColor (HIMAGELIST himl, COLORREF clrBk)
2523 if (!is_valid(himl))
2526 clrOldBk = himl->clrBk;
2527 himl->clrBk = clrBk;
2532 /*************************************************************************
2533 * ImageList_SetDragCursorImage [COMCTL32.@]
2535 * Combines the specified image with the current drag image
2538 * himlDrag [I] handle to drag image list
2539 * iDrag [I] drag image index
2540 * dxHotspot [I] X position of the hot spot
2541 * dyHotspot [I] Y position of the hot spot
2548 * - The names dxHotspot, dyHotspot are misleading because they have nothing
2549 * to do with a hotspot but are only the offset of the origin of the new
2550 * image relative to the origin of the old image.
2552 * - When this function is called and the drag image is visible, a
2553 * short flickering occurs but this matches the Win9x behavior. It is
2554 * possible to fix the flickering using code like in ImageList_DragMove.
2558 ImageList_SetDragCursorImage (HIMAGELIST himlDrag, INT iDrag,
2559 INT dxHotspot, INT dyHotspot)
2561 HIMAGELIST himlTemp;
2564 if (!is_valid(InternalDrag.himl) || !is_valid(himlDrag))
2567 TRACE(" dxH=%d dyH=%d nX=%d nY=%d\n",
2568 dxHotspot, dyHotspot, InternalDrag.dxHotspot, InternalDrag.dyHotspot);
2570 visible = InternalDrag.bShow;
2572 himlTemp = ImageList_Merge (InternalDrag.himl, 0, himlDrag, iDrag,
2573 dxHotspot, dyHotspot);
2576 /* hide the drag image */
2577 ImageList_DragShowNolock(FALSE);
2579 if ((InternalDrag.himl->cx != himlTemp->cx) ||
2580 (InternalDrag.himl->cy != himlTemp->cy)) {
2581 /* the size of the drag image changed, invalidate the buffer */
2582 DeleteObject(InternalDrag.hbmBg);
2583 InternalDrag.hbmBg = 0;
2586 ImageList_Destroy (InternalDrag.himl);
2587 InternalDrag.himl = himlTemp;
2590 /* show the drag image */
2591 ImageList_DragShowNolock(TRUE);
2598 /*************************************************************************
2599 * ImageList_SetFilter [COMCTL32.@]
2601 * Sets a filter (or does something completely different)!!???
2602 * It removes 12 Bytes from the stack (3 Parameters).
2605 * himl [I] SHOULD be a handle to image list
2606 * i [I] COULD be an index?
2611 * Failure: FALSE ???
2614 * This is an UNDOCUMENTED function!!!!
2619 ImageList_SetFilter (HIMAGELIST himl, INT i, DWORD dwFilter)
2621 FIXME("(%p 0x%x 0x%x):empty stub!\n", himl, i, dwFilter);
2627 /*************************************************************************
2628 * ImageList_SetFlags [COMCTL32.@]
2630 * Sets the image list flags.
2633 * himl [I] Handle to image list
2634 * flags [I] Flags to set
2644 ImageList_SetFlags(HIMAGELIST himl, DWORD flags)
2646 FIXME("(%p %08x):empty stub\n", himl, flags);
2651 /*************************************************************************
2652 * ImageList_SetIconSize [COMCTL32.@]
2654 * Sets the image size of the bitmap and deletes all images.
2657 * himl [I] handle to image list
2658 * cx [I] image width
2659 * cy [I] image height
2667 ImageList_SetIconSize (HIMAGELIST himl, INT cx, INT cy)
2672 if (!is_valid(himl))
2675 /* remove all images */
2676 himl->cMaxImage = himl->cInitial + 1;
2677 himl->cCurImage = 0;
2681 /* initialize overlay mask indices */
2682 for (nCount = 0; nCount < MAX_OVERLAYIMAGE; nCount++)
2683 himl->nOvlIdx[nCount] = -1;
2685 hbmNew = ImageList_CreateImage(himl->hdcImage, himl, himl->cMaxImage);
2686 SelectObject (himl->hdcImage, hbmNew);
2687 DeleteObject (himl->hbmImage);
2688 himl->hbmImage = hbmNew;
2690 if (himl->hbmMask) {
2692 imagelist_get_bitmap_size(himl, himl->cMaxImage, &sz);
2693 hbmNew = CreateBitmap (sz.cx, sz.cy, 1, 1, NULL);
2694 SelectObject (himl->hdcMask, hbmNew);
2695 DeleteObject (himl->hbmMask);
2696 himl->hbmMask = hbmNew;
2703 /*************************************************************************
2704 * ImageList_SetImageCount [COMCTL32.@]
2706 * Resizes an image list to the specified number of images.
2709 * himl [I] handle to image list
2710 * iImageCount [I] number of images in the image list
2718 ImageList_SetImageCount (HIMAGELIST himl, UINT iImageCount)
2721 HBITMAP hbmNewBitmap, hbmOld;
2722 INT nNewCount, nCopyCount;
2724 TRACE("%p %d\n",himl,iImageCount);
2726 if (!is_valid(himl))
2728 if (himl->cMaxImage > iImageCount)
2730 himl->cCurImage = iImageCount;
2731 /* TODO: shrink the bitmap when cMaxImage-cCurImage>cGrow ? */
2735 nNewCount = iImageCount + himl->cGrow;
2736 nCopyCount = min(himl->cCurImage, iImageCount);
2738 hdcBitmap = CreateCompatibleDC (0);
2740 hbmNewBitmap = ImageList_CreateImage(hdcBitmap, himl, nNewCount);
2742 if (hbmNewBitmap != 0)
2744 hbmOld = SelectObject (hdcBitmap, hbmNewBitmap);
2745 imagelist_copy_images( himl, himl->hdcImage, hdcBitmap, 0, nCopyCount, 0 );
2746 SelectObject (hdcBitmap, hbmOld);
2748 /* FIXME: delete 'empty' image space? */
2750 SelectObject (himl->hdcImage, hbmNewBitmap);
2751 DeleteObject (himl->hbmImage);
2752 himl->hbmImage = hbmNewBitmap;
2755 ERR("Could not create new image bitmap !\n");
2760 imagelist_get_bitmap_size( himl, nNewCount, &sz );
2761 hbmNewBitmap = CreateBitmap (sz.cx, sz.cy, 1, 1, NULL);
2762 if (hbmNewBitmap != 0)
2764 hbmOld = SelectObject (hdcBitmap, hbmNewBitmap);
2765 imagelist_copy_images( himl, himl->hdcMask, hdcBitmap, 0, nCopyCount, 0 );
2766 SelectObject (hdcBitmap, hbmOld);
2768 /* FIXME: delete 'empty' image space? */
2770 SelectObject (himl->hdcMask, hbmNewBitmap);
2771 DeleteObject (himl->hbmMask);
2772 himl->hbmMask = hbmNewBitmap;
2775 ERR("Could not create new mask bitmap!\n");
2778 DeleteDC (hdcBitmap);
2780 /* Update max image count and current image count */
2781 himl->cMaxImage = nNewCount;
2782 himl->cCurImage = iImageCount;
2788 /*************************************************************************
2789 * ImageList_SetOverlayImage [COMCTL32.@]
2791 * Assigns an overlay mask index to an existing image in an image list.
2794 * himl [I] handle to image list
2795 * iImage [I] image index
2796 * iOverlay [I] overlay mask index
2804 ImageList_SetOverlayImage (HIMAGELIST himl, INT iImage, INT iOverlay)
2806 if (!is_valid(himl))
2808 if ((iOverlay < 1) || (iOverlay > MAX_OVERLAYIMAGE))
2810 if ((iImage!=-1) && ((iImage < 0) || (iImage > himl->cCurImage)))
2812 himl->nOvlIdx[iOverlay - 1] = iImage;
2818 /* helper for ImageList_Write - write bitmap to pstm
2819 * currently everything is written as 24 bit RGB, except masks
2822 _write_bitmap(HBITMAP hBitmap, LPSTREAM pstm)
2824 LPBITMAPFILEHEADER bmfh;
2825 LPBITMAPINFOHEADER bmih;
2826 LPBYTE data = NULL, lpBits;
2828 INT bitCount, sizeImage, offBits, totalSize;
2830 BOOL result = FALSE;
2832 if (!GetObjectW(hBitmap, sizeof(BITMAP), &bm))
2835 bitCount = bm.bmBitsPixel == 1 ? 1 : 24;
2836 sizeImage = DIB_GetDIBImageBytes(bm.bmWidth, bm.bmHeight, bitCount);
2838 totalSize = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);
2840 totalSize += (1 << bitCount) * sizeof(RGBQUAD);
2841 offBits = totalSize;
2842 totalSize += sizeImage;
2844 data = Alloc(totalSize);
2845 bmfh = (LPBITMAPFILEHEADER)data;
2846 bmih = (LPBITMAPINFOHEADER)(data + sizeof(BITMAPFILEHEADER));
2847 lpBits = data + offBits;
2849 /* setup BITMAPFILEHEADER */
2850 bmfh->bfType = (('M' << 8) | 'B');
2851 bmfh->bfSize = offBits;
2852 bmfh->bfReserved1 = 0;
2853 bmfh->bfReserved2 = 0;
2854 bmfh->bfOffBits = offBits;
2856 /* setup BITMAPINFOHEADER */
2857 bmih->biSize = sizeof(BITMAPINFOHEADER);
2858 bmih->biWidth = bm.bmWidth;
2859 bmih->biHeight = bm.bmHeight;
2861 bmih->biBitCount = bitCount;
2862 bmih->biCompression = BI_RGB;
2863 bmih->biSizeImage = sizeImage;
2864 bmih->biXPelsPerMeter = 0;
2865 bmih->biYPelsPerMeter = 0;
2866 bmih->biClrUsed = 0;
2867 bmih->biClrImportant = 0;
2870 result = GetDIBits(xdc, hBitmap, 0, bm.bmHeight, lpBits, (BITMAPINFO *)bmih, DIB_RGB_COLORS) == bm.bmHeight;
2875 TRACE("width %u, height %u, planes %u, bpp %u\n",
2876 bmih->biWidth, bmih->biHeight,
2877 bmih->biPlanes, bmih->biBitCount);
2881 LPBITMAPINFO inf = (LPBITMAPINFO)bmih;
2882 inf->bmiColors[0].rgbRed = inf->bmiColors[0].rgbGreen = inf->bmiColors[0].rgbBlue = 0;
2883 inf->bmiColors[1].rgbRed = inf->bmiColors[1].rgbGreen = inf->bmiColors[1].rgbBlue = 0xff;
2886 if(FAILED(IStream_Write(pstm, data, totalSize, NULL)))
2898 /*************************************************************************
2899 * ImageList_Write [COMCTL32.@]
2901 * Writes an image list to a stream.
2904 * himl [I] handle to image list
2905 * pstm [O] Pointer to a stream.
2916 ImageList_Write (HIMAGELIST himl, LPSTREAM pstm)
2921 TRACE("%p %p\n", himl, pstm);
2923 if (!is_valid(himl))
2926 ilHead.usMagic = (('L' << 8) | 'I');
2927 ilHead.usVersion = 0x101;
2928 ilHead.cCurImage = himl->cCurImage;
2929 ilHead.cMaxImage = himl->cMaxImage;
2930 ilHead.cGrow = himl->cGrow;
2931 ilHead.cx = himl->cx;
2932 ilHead.cy = himl->cy;
2933 ilHead.bkcolor = himl->clrBk;
2934 ilHead.flags = himl->flags;
2935 for(i = 0; i < 4; i++) {
2936 ilHead.ovls[i] = himl->nOvlIdx[i];
2939 TRACE("cx %u, cy %u, flags 0x04%x, cCurImage %u, cMaxImage %u\n",
2940 ilHead.cx, ilHead.cy, ilHead.flags, ilHead.cCurImage, ilHead.cMaxImage);
2942 if(FAILED(IStream_Write(pstm, &ilHead, sizeof(ILHEAD), NULL)))
2945 /* write the bitmap */
2946 if(!_write_bitmap(himl->hbmImage, pstm))
2949 /* write the mask if we have one */
2950 if(himl->flags & ILC_MASK) {
2951 if(!_write_bitmap(himl->hbmMask, pstm))
2959 static HBITMAP ImageList_CreateImage(HDC hdc, HIMAGELIST himl, UINT count)
2961 HBITMAP hbmNewBitmap;
2962 UINT ilc = (himl->flags & 0xFE);
2965 imagelist_get_bitmap_size( himl, count, &sz );
2967 if ((ilc >= ILC_COLOR4 && ilc <= ILC_COLOR32) || ilc == ILC_COLOR)
2972 TRACE("Creating DIBSection %d x %d, %d Bits per Pixel\n",
2973 sz.cx, sz.cy, himl->uBitsPixel);
2975 if (himl->uBitsPixel <= ILC_COLOR8)
2981 colors = 1 << himl->uBitsPixel;
2982 bmi = Alloc(sizeof(BITMAPINFOHEADER) +
2983 sizeof(PALETTEENTRY) * colors);
2985 pal = (LPPALETTEENTRY)bmi->bmiColors;
2986 GetPaletteEntries(GetStockObject(DEFAULT_PALETTE), 0, colors, pal);
2988 /* Swap colors returned by GetPaletteEntries so we can use them for
2989 * CreateDIBSection call. */
2990 for (i = 0; i < colors; i++)
2992 temp = pal[i].peBlue;
2993 bmi->bmiColors[i].rgbRed = pal[i].peRed;
2994 bmi->bmiColors[i].rgbBlue = temp;
2999 bmi = Alloc(sizeof(BITMAPINFOHEADER));
3002 bmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
3003 bmi->bmiHeader.biWidth = sz.cx;
3004 bmi->bmiHeader.biHeight = sz.cy;
3005 bmi->bmiHeader.biPlanes = 1;
3006 bmi->bmiHeader.biBitCount = himl->uBitsPixel;
3007 bmi->bmiHeader.biCompression = BI_RGB;
3008 bmi->bmiHeader.biSizeImage = 0;
3009 bmi->bmiHeader.biXPelsPerMeter = 0;
3010 bmi->bmiHeader.biYPelsPerMeter = 0;
3011 bmi->bmiHeader.biClrUsed = 0;
3012 bmi->bmiHeader.biClrImportant = 0;
3014 hbmNewBitmap = CreateDIBSection(hdc, bmi, DIB_RGB_COLORS, &bits, 0, 0);
3018 else /*if (ilc == ILC_COLORDDB)*/
3020 TRACE("Creating Bitmap: %d Bits per Pixel\n", himl->uBitsPixel);
3022 hbmNewBitmap = CreateBitmap (sz.cx, sz.cy, 1, himl->uBitsPixel, NULL);
3024 TRACE("returning %p\n", hbmNewBitmap);
3025 return hbmNewBitmap;
3028 /*************************************************************************
3029 * ImageList_SetColorTable [COMCTL32.@]
3031 * Sets the color table of an image list.
3034 * himl [I] Handle to the image list.
3035 * uStartIndex [I] The first index to set.
3036 * cEntries [I] Number of entries to set.
3037 * prgb [I] New color information for color table for the image list.
3040 * Success: Number of entries in the table that were set.
3044 * ImageList_Create(), SetDIBColorTable()
3048 ImageList_SetColorTable (HIMAGELIST himl, UINT uStartIndex, UINT cEntries, CONST RGBQUAD * prgb)
3050 return SetDIBColorTable(himl->hdcImage, uStartIndex, cEntries, prgb);
3053 /*************************************************************************
3054 * ImageList_CoCreateInstance [COMCTL32.@]
3056 * Creates a new imagelist instance and returns an interface pointer to it.
3059 * rclsid [I] A reference to the CLSID (CLSID_ImageList).
3060 * punkOuter [I] Pointer to IUnknown interface for aggregation, if desired
3061 * riid [I] Identifier of the requested interface.
3062 * ppv [O] Returns the address of the pointer requested, or NULL.
3066 * Failure: Error value.
3069 ImageList_CoCreateInstance (REFCLSID rclsid, const IUnknown *punkOuter, REFIID riid, void **ppv)
3071 TRACE("(%s,%p,%s,%p)\n", debugstr_guid(rclsid), punkOuter, debugstr_guid(riid), ppv);
3073 if (!IsEqualCLSID(&CLSID_ImageList, rclsid))
3074 return E_NOINTERFACE;
3076 return ImageListImpl_CreateInstance(punkOuter, riid, ppv);
3080 /*************************************************************************
3081 * IImageList implementation
3084 static HRESULT WINAPI ImageListImpl_QueryInterface(IImageList *iface,
3085 REFIID iid, void **ppv)
3087 HIMAGELIST This = (HIMAGELIST) iface;
3088 TRACE("(%p,%s,%p)\n", iface, debugstr_guid(iid), ppv);
3090 if (!ppv) return E_INVALIDARG;
3092 if (IsEqualIID(&IID_IUnknown, iid) || IsEqualIID(&IID_IImageList, iid))
3097 return E_NOINTERFACE;
3100 IUnknown_AddRef((IUnknown*)*ppv);
3104 static ULONG WINAPI ImageListImpl_AddRef(IImageList *iface)
3106 HIMAGELIST This = (HIMAGELIST) iface;
3107 ULONG ref = InterlockedIncrement(&This->ref);
3109 TRACE("(%p) refcount=%u\n", iface, ref);
3113 static ULONG WINAPI ImageListImpl_Release(IImageList *iface)
3115 HIMAGELIST This = (HIMAGELIST) iface;
3116 ULONG ref = InterlockedDecrement(&This->ref);
3118 TRACE("(%p) refcount=%u\n", iface, ref);
3122 /* delete image bitmaps */
3123 if (This->hbmImage) DeleteObject (This->hbmImage);
3124 if (This->hbmMask) DeleteObject (This->hbmMask);
3126 /* delete image & mask DCs */
3127 if (This->hdcImage) DeleteDC (This->hdcImage);
3128 if (This->hdcMask) DeleteDC (This->hdcMask);
3130 /* delete blending brushes */
3131 if (This->hbrBlend25) DeleteObject (This->hbrBlend25);
3132 if (This->hbrBlend50) DeleteObject (This->hbrBlend50);
3134 This->lpVtbl = NULL;
3135 HeapFree(GetProcessHeap(), 0, This);
3141 static HRESULT WINAPI ImageListImpl_Add(IImageList *iface, HBITMAP hbmImage,
3142 HBITMAP hbmMask, int *pi)
3144 HIMAGELIST This = (HIMAGELIST) iface;
3150 ret = ImageList_Add(This, hbmImage, hbmMask);
3159 static HRESULT WINAPI ImageListImpl_ReplaceIcon(IImageList *iface, int i,
3160 HICON hicon, int *pi)
3162 HIMAGELIST This = (HIMAGELIST) iface;
3168 ret = ImageList_ReplaceIcon(This, i, hicon);
3177 static HRESULT WINAPI ImageListImpl_SetOverlayImage(IImageList *iface,
3178 int iImage, int iOverlay)
3180 return ImageList_SetOverlayImage((HIMAGELIST) iface, iImage, iOverlay)
3184 static HRESULT WINAPI ImageListImpl_Replace(IImageList *iface, int i,
3185 HBITMAP hbmImage, HBITMAP hbmMask)
3187 return ImageList_Replace((HIMAGELIST) iface, i, hbmImage, hbmMask) ? S_OK :
3191 static HRESULT WINAPI ImageListImpl_AddMasked(IImageList *iface, HBITMAP hbmImage,
3192 COLORREF crMask, int *pi)
3194 HIMAGELIST This = (HIMAGELIST) iface;
3200 ret = ImageList_AddMasked(This, hbmImage, crMask);
3209 static HRESULT WINAPI ImageListImpl_Draw(IImageList *iface,
3210 IMAGELISTDRAWPARAMS *pimldp)
3212 HIMAGELIST This = (HIMAGELIST) iface;
3213 HIMAGELIST old_himl = 0;
3219 /* As far as I can tell, Windows simply ignores the contents of pimldp->himl
3220 so we shall simulate the same */
3221 old_himl = pimldp->himl;
3222 pimldp->himl = This;
3224 ret = ImageList_DrawIndirect(pimldp);
3226 pimldp->himl = old_himl;
3227 return ret ? S_OK : E_FAIL;
3230 static HRESULT WINAPI ImageListImpl_Remove(IImageList *iface, int i)
3232 return (ImageList_Remove((HIMAGELIST) iface, i) == 0) ? E_FAIL : S_OK;
3235 static HRESULT WINAPI ImageListImpl_GetIcon(IImageList *iface, int i, UINT flags,
3243 hIcon = ImageList_GetIcon((HIMAGELIST) iface, i, flags);
3252 static HRESULT WINAPI ImageListImpl_GetImageInfo(IImageList *iface, int i,
3253 IMAGEINFO *pImageInfo)
3255 return ImageList_GetImageInfo((HIMAGELIST) iface, i, pImageInfo) ? S_OK : E_FAIL;
3258 static HRESULT WINAPI ImageListImpl_Copy(IImageList *iface, int iDst,
3259 IUnknown *punkSrc, int iSrc, UINT uFlags)
3261 HIMAGELIST This = (HIMAGELIST) iface;
3262 IImageList *src = NULL;
3268 /* TODO: Add test for IID_ImageList2 too */
3269 if (FAILED(IImageList_QueryInterface(punkSrc, &IID_IImageList,
3273 if (ImageList_Copy(This, iDst, (HIMAGELIST) src, iSrc, uFlags))
3278 IImageList_Release(src);
3282 static HRESULT WINAPI ImageListImpl_Merge(IImageList *iface, int i1,
3283 IUnknown *punk2, int i2, int dx, int dy, REFIID riid, PVOID *ppv)
3285 HIMAGELIST This = (HIMAGELIST) iface;
3286 IImageList *iml2 = NULL;
3288 HRESULT ret = E_FAIL;
3293 /* TODO: Add test for IID_ImageList2 too */
3294 if (FAILED(IImageList_QueryInterface(punk2, &IID_IImageList,
3298 hNew = ImageList_Merge(This, i1, (HIMAGELIST) iml2, i2, dx, dy);
3300 /* Get the interface for the new image list */
3302 ret = HIMAGELIST_QueryInterface(hNew, riid, ppv);
3304 IImageList_Release(iml2);
3308 static HRESULT WINAPI ImageListImpl_Clone(IImageList *iface, REFIID riid,
3311 HIMAGELIST This = (HIMAGELIST) iface;
3313 HRESULT ret = E_FAIL;
3318 hNew = ImageList_Duplicate(This);
3320 /* Get the interface for the new image list */
3322 ret = HIMAGELIST_QueryInterface(hNew, riid, ppv);
3327 static HRESULT WINAPI ImageListImpl_GetImageRect(IImageList *iface, int i,
3330 HIMAGELIST This = (HIMAGELIST) iface;
3336 if (!ImageList_GetImageInfo(This, i, &info))
3339 return CopyRect(prc, &info.rcImage) ? S_OK : E_FAIL;
3342 static HRESULT WINAPI ImageListImpl_GetIconSize(IImageList *iface, int *cx,
3345 HIMAGELIST This = (HIMAGELIST) iface;
3347 return ImageList_GetIconSize(This, cx, cy) ? S_OK : E_FAIL;
3350 static HRESULT WINAPI ImageListImpl_SetIconSize(IImageList *iface, int cx,
3353 return ImageList_SetIconSize((HIMAGELIST) iface, cx, cy) ? S_OK : E_FAIL;
3356 static HRESULT WINAPI ImageListImpl_GetImageCount(IImageList *iface, int *pi)
3361 *pi = ImageList_GetImageCount((HIMAGELIST) iface);
3365 static HRESULT WINAPI ImageListImpl_SetImageCount(IImageList *iface,
3368 return ImageList_SetImageCount((HIMAGELIST) iface, uNewCount) ? S_OK : E_FAIL;
3371 static HRESULT WINAPI ImageListImpl_SetBkColor(IImageList *iface, COLORREF clrBk,
3377 *pclr = ImageList_SetBkColor((HIMAGELIST) iface, clrBk);
3378 return *pclr == CLR_NONE ? E_FAIL : S_OK;
3381 static HRESULT WINAPI ImageListImpl_GetBkColor(IImageList *iface, COLORREF *pclr)
3386 *pclr = ImageList_GetBkColor((HIMAGELIST) iface);
3390 static HRESULT WINAPI ImageListImpl_BeginDrag(IImageList *iface, int iTrack,
3391 int dxHotspot, int dyHotspot)
3393 return ImageList_BeginDrag((HIMAGELIST) iface, iTrack, dxHotspot, dyHotspot) ? S_OK : E_FAIL;
3396 static HRESULT WINAPI ImageListImpl_EndDrag(IImageList *iface)
3398 ImageList_EndDrag();
3402 static HRESULT WINAPI ImageListImpl_DragEnter(IImageList *iface, HWND hwndLock,
3405 return ImageList_DragEnter(hwndLock, x, y) ? S_OK : E_FAIL;
3408 static HRESULT WINAPI ImageListImpl_DragLeave(IImageList *iface, HWND hwndLock)
3410 return ImageList_DragLeave(hwndLock) ? S_OK : E_FAIL;
3413 static HRESULT WINAPI ImageListImpl_DragMove(IImageList *iface, int x, int y)
3415 return ImageList_DragMove(x, y) ? S_OK : E_FAIL;
3418 static HRESULT WINAPI ImageListImpl_SetDragCursorImage(IImageList *iface,
3419 IUnknown *punk, int iDrag, int dxHotspot, int dyHotspot)
3421 IImageList *iml2 = NULL;
3427 /* TODO: Add test for IID_ImageList2 too */
3428 if (FAILED(IImageList_QueryInterface(punk, &IID_IImageList,
3432 ret = ImageList_SetDragCursorImage((HIMAGELIST) iml2, iDrag, dxHotspot,
3435 IImageList_Release(iml2);
3437 return ret ? S_OK : E_FAIL;
3440 static HRESULT WINAPI ImageListImpl_DragShowNolock(IImageList *iface, BOOL fShow)
3442 return ImageList_DragShowNolock(fShow) ? S_OK : E_FAIL;
3445 static HRESULT WINAPI ImageListImpl_GetDragImage(IImageList *iface, POINT *ppt,
3446 POINT *pptHotspot, REFIID riid, PVOID *ppv)
3448 HRESULT ret = E_FAIL;
3454 hNew = ImageList_GetDragImage(ppt, pptHotspot);
3456 /* Get the interface for the new image list */
3458 ret = HIMAGELIST_QueryInterface(hNew, riid, ppv);
3463 static HRESULT WINAPI ImageListImpl_GetItemFlags(IImageList *iface, int i,
3466 FIXME("STUB: %p %d %p\n", iface, i, dwFlags);
3470 static HRESULT WINAPI ImageListImpl_GetOverlayImage(IImageList *iface, int iOverlay,
3473 HIMAGELIST This = (HIMAGELIST) iface;
3476 if ((iOverlay < 0) || (iOverlay > This->cCurImage))
3479 for (i = 0; i < MAX_OVERLAYIMAGE; i++)
3481 if (This->nOvlIdx[i] == iOverlay)
3492 static const IImageListVtbl ImageListImpl_Vtbl = {
3493 ImageListImpl_QueryInterface,
3494 ImageListImpl_AddRef,
3495 ImageListImpl_Release,
3497 ImageListImpl_ReplaceIcon,
3498 ImageListImpl_SetOverlayImage,
3499 ImageListImpl_Replace,
3500 ImageListImpl_AddMasked,
3502 ImageListImpl_Remove,
3503 ImageListImpl_GetIcon,
3504 ImageListImpl_GetImageInfo,
3506 ImageListImpl_Merge,
3507 ImageListImpl_Clone,
3508 ImageListImpl_GetImageRect,
3509 ImageListImpl_GetIconSize,
3510 ImageListImpl_SetIconSize,
3511 ImageListImpl_GetImageCount,
3512 ImageListImpl_SetImageCount,
3513 ImageListImpl_SetBkColor,
3514 ImageListImpl_GetBkColor,
3515 ImageListImpl_BeginDrag,
3516 ImageListImpl_EndDrag,
3517 ImageListImpl_DragEnter,
3518 ImageListImpl_DragLeave,
3519 ImageListImpl_DragMove,
3520 ImageListImpl_SetDragCursorImage,
3521 ImageListImpl_DragShowNolock,
3522 ImageListImpl_GetDragImage,
3523 ImageListImpl_GetItemFlags,
3524 ImageListImpl_GetOverlayImage
3527 static inline BOOL is_valid(HIMAGELIST himl)
3529 return himl && himl->lpVtbl == &ImageListImpl_Vtbl;
3532 /*************************************************************************
3533 * HIMAGELIST_QueryInterface [COMCTL32.@]
3535 * Returns a pointer to an IImageList or IImageList2 object for the given
3539 * himl [I] Image list handle.
3540 * riid [I] Identifier of the requested interface.
3541 * ppv [O] Returns the address of the pointer requested, or NULL.
3545 * Failure: Error value.
3548 HIMAGELIST_QueryInterface (HIMAGELIST himl, REFIID riid, void **ppv)
3550 TRACE("(%p,%s,%p)\n", himl, debugstr_guid(riid), ppv);
3551 return IImageList_QueryInterface((IImageList *) himl, riid, ppv);
3554 static HRESULT ImageListImpl_CreateInstance(const IUnknown *pUnkOuter, REFIID iid, void** ppv)
3559 TRACE("(%p,%s,%p)\n", pUnkOuter, debugstr_guid(iid), ppv);
3563 if (pUnkOuter) return CLASS_E_NOAGGREGATION;
3565 This = HeapAlloc(GetProcessHeap(), 0, sizeof(struct _IMAGELIST));
3566 if (!This) return E_OUTOFMEMORY;
3568 ZeroMemory(This, sizeof(struct _IMAGELIST));
3570 This->lpVtbl = &ImageListImpl_Vtbl;
3573 ret = IUnknown_QueryInterface((IUnknown*)This, iid, ppv);
3574 IUnknown_Release((IUnknown*)This);