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
37 * - Thread-safe locking
42 #include <commoncontrols.h>
43 #include <wine/exception.h>
45 WINE_DEFAULT_DEBUG_CHANNEL(imagelist
);
47 #define MAX_OVERLAYIMAGE 15
51 IImageList2 IImageList2_iface
; /* 00: IImageList vtable */
52 INT cCurImage
; /* 04: ImageCount */
53 INT cMaxImage
; /* 08: maximages */
54 INT cGrow
; /* 0C: cGrow */
58 UINT flags
; /* 1C: flags */
59 COLORREF clrFg
; /* 20: foreground color */
60 COLORREF clrBk
; /* 24: background color */
63 HBITMAP hbmImage
; /* 28: images Bitmap */
64 HBITMAP hbmMask
; /* 2C: masks Bitmap */
65 HDC hdcImage
; /* 30: images MemDC */
66 HDC hdcMask
; /* 34: masks MemDC */
67 INT nOvlIdx
[MAX_OVERLAYIMAGE
]; /* 38: overlay images index */
69 /* not yet found out */
76 LONG ref
; /* reference count */
79 #define IMAGELIST_MAGIC 0x53414D58
81 /* Header used by ImageList_Read() and ImageList_Write() */
83 typedef struct _ILHEAD
98 /* internal image list data used for Drag & Drop operations */
103 HIMAGELIST himlNoCursor
;
104 /* position of the drag image relative to the window */
107 /* offset of the hotspot relative to the origin of the image */
110 /* is the drag image visible */
112 /* saved background */
116 static INTERNALDRAG InternalDrag
= { 0, 0, 0, 0, 0, 0, 0, FALSE
, 0 };
118 static inline HIMAGELIST
impl_from_IImageList2(IImageList2
*iface
)
120 return CONTAINING_RECORD(iface
, struct _IMAGELIST
, IImageList2_iface
);
123 static HBITMAP
ImageList_CreateImage(HDC hdc
, HIMAGELIST himl
, UINT count
);
124 static HRESULT
ImageListImpl_CreateInstance(const IUnknown
*pUnkOuter
, REFIID iid
, void** ppv
);
125 static BOOL
is_valid(HIMAGELIST himl
);
128 * An imagelist with N images is tiled like this:
140 static inline UINT
imagelist_height( UINT count
)
142 return ((count
+ TILE_COUNT
- 1)/TILE_COUNT
);
145 static inline void imagelist_point_from_index( HIMAGELIST himl
, UINT index
, LPPOINT pt
)
147 pt
->x
= (index
%TILE_COUNT
) * himl
->cx
;
148 pt
->y
= (index
/TILE_COUNT
) * himl
->cy
;
151 static inline void imagelist_get_bitmap_size( HIMAGELIST himl
, UINT count
, SIZE
*sz
)
153 sz
->cx
= himl
->cx
* TILE_COUNT
;
154 sz
->cy
= imagelist_height( count
) * himl
->cy
;
157 static inline int get_dib_stride( int width
, int bpp
)
159 return ((width
* bpp
+ 31) >> 3) & ~3;
162 static inline int get_dib_image_size( const BITMAPINFO
*info
)
164 return get_dib_stride( info
->bmiHeader
.biWidth
, info
->bmiHeader
.biBitCount
)
165 * abs( info
->bmiHeader
.biHeight
);
169 * imagelist_copy_images()
171 * Copies a block of count images from offset src in the list to offset dest.
172 * Images are copied a row at at time. Assumes hdcSrc and hdcDest are different.
174 static inline void imagelist_copy_images( HIMAGELIST himl
, HDC hdcSrc
, HDC hdcDest
,
175 UINT src
, UINT count
, UINT dest
)
181 for ( i
=0; i
<TILE_COUNT
; i
++ )
183 imagelist_point_from_index( himl
, src
+i
, &ptSrc
);
184 imagelist_point_from_index( himl
, dest
+i
, &ptDest
);
186 sz
.cy
= himl
->cy
* imagelist_height( count
- i
);
188 BitBlt( hdcDest
, ptDest
.x
, ptDest
.y
, sz
.cx
, sz
.cy
,
189 hdcSrc
, ptSrc
.x
, ptSrc
.y
, SRCCOPY
);
193 static void add_dib_bits( HIMAGELIST himl
, int pos
, int count
, int width
, int height
,
194 BITMAPINFO
*info
, BITMAPINFO
*mask_info
, DWORD
*bits
, BYTE
*mask_bits
)
198 int stride
= info
->bmiHeader
.biWidth
;
199 int mask_stride
= (info
->bmiHeader
.biWidth
+ 31) / 32 * 4;
201 for (n
= 0; n
< count
; n
++)
203 BOOL has_alpha
= FALSE
;
205 imagelist_point_from_index( himl
, pos
+ n
, &pt
);
207 /* check if bitmap has an alpha channel */
208 for (i
= 0; i
< height
&& !has_alpha
; i
++)
209 for (j
= n
* width
; j
< (n
+ 1) * width
; j
++)
210 if ((has_alpha
= ((bits
[i
* stride
+ j
] & 0xff000000) != 0))) break;
212 if (!has_alpha
) /* generate alpha channel from the mask */
214 for (i
= 0; i
< height
; i
++)
215 for (j
= n
* width
; j
< (n
+ 1) * width
; j
++)
216 if (!mask_info
|| !((mask_bits
[i
* mask_stride
+ j
/ 8] << (j
% 8)) & 0x80))
217 bits
[i
* stride
+ j
] |= 0xff000000;
219 bits
[i
* stride
+ j
] = 0;
223 himl
->has_alpha
[pos
+ n
] = 1;
225 if (mask_info
&& himl
->hbmMask
) /* generate the mask from the alpha channel */
227 for (i
= 0; i
< height
; i
++)
228 for (j
= n
* width
; j
< (n
+ 1) * width
; j
++)
229 if ((bits
[i
* stride
+ j
] >> 24) > 25) /* more than 10% alpha */
230 mask_bits
[i
* mask_stride
+ j
/ 8] &= ~(0x80 >> (j
% 8));
232 mask_bits
[i
* mask_stride
+ j
/ 8] |= 0x80 >> (j
% 8);
235 StretchDIBits( himl
->hdcImage
, pt
.x
, pt
.y
, himl
->cx
, himl
->cy
,
236 n
* width
, 0, width
, height
, bits
, info
, DIB_RGB_COLORS
, SRCCOPY
);
238 StretchDIBits( himl
->hdcMask
, pt
.x
, pt
.y
, himl
->cx
, himl
->cy
,
239 n
* width
, 0, width
, height
, mask_bits
, mask_info
, DIB_RGB_COLORS
, SRCCOPY
);
243 /* add images with an alpha channel when the image list is 32 bpp */
244 static BOOL
add_with_alpha( HIMAGELIST himl
, HDC hdc
, int pos
, int count
,
245 int width
, int height
, HBITMAP hbmImage
, HBITMAP hbmMask
)
249 BITMAPINFO
*info
, *mask_info
= NULL
;
251 BYTE
*mask_bits
= NULL
;
254 if (!GetObjectW( hbmImage
, sizeof(bm
), &bm
)) return FALSE
;
256 /* if either the imagelist or the source bitmap don't have an alpha channel, bail out now */
257 if (!himl
->has_alpha
) return FALSE
;
258 if (bm
.bmBitsPixel
!= 32) return FALSE
;
260 SelectObject( hdc
, hbmImage
);
261 mask_width
= (bm
.bmWidth
+ 31) / 32 * 4;
263 if (!(info
= HeapAlloc( GetProcessHeap(), 0, FIELD_OFFSET( BITMAPINFO
, bmiColors
[256] )))) goto done
;
264 info
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
265 info
->bmiHeader
.biWidth
= bm
.bmWidth
;
266 info
->bmiHeader
.biHeight
= -height
;
267 info
->bmiHeader
.biPlanes
= 1;
268 info
->bmiHeader
.biBitCount
= 32;
269 info
->bmiHeader
.biCompression
= BI_RGB
;
270 info
->bmiHeader
.biSizeImage
= bm
.bmWidth
* height
* 4;
271 info
->bmiHeader
.biXPelsPerMeter
= 0;
272 info
->bmiHeader
.biYPelsPerMeter
= 0;
273 info
->bmiHeader
.biClrUsed
= 0;
274 info
->bmiHeader
.biClrImportant
= 0;
275 if (!(bits
= HeapAlloc( GetProcessHeap(), 0, info
->bmiHeader
.biSizeImage
))) goto done
;
276 if (!GetDIBits( hdc
, hbmImage
, 0, height
, bits
, info
, DIB_RGB_COLORS
)) goto done
;
280 if (!(mask_info
= HeapAlloc( GetProcessHeap(), 0, FIELD_OFFSET( BITMAPINFO
, bmiColors
[2] ))))
282 mask_info
->bmiHeader
= info
->bmiHeader
;
283 mask_info
->bmiHeader
.biBitCount
= 1;
284 mask_info
->bmiHeader
.biSizeImage
= mask_width
* height
;
285 if (!(mask_bits
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, info
->bmiHeader
.biSizeImage
)))
287 if (!GetDIBits( hdc
, hbmMask
, 0, height
, mask_bits
, mask_info
, DIB_RGB_COLORS
)) goto done
;
290 add_dib_bits( himl
, pos
, count
, width
, height
, info
, mask_info
, bits
, mask_bits
);
294 HeapFree( GetProcessHeap(), 0, info
);
295 HeapFree( GetProcessHeap(), 0, mask_info
);
296 HeapFree( GetProcessHeap(), 0, bits
);
297 HeapFree( GetProcessHeap(), 0, mask_bits
);
301 /*************************************************************************
302 * IMAGELIST_InternalExpandBitmaps [Internal]
304 * Expands the bitmaps of an image list by the given number of images.
307 * himl [I] handle to image list
308 * nImageCount [I] number of images to add
314 * This function CANNOT be used to reduce the number of images.
317 IMAGELIST_InternalExpandBitmaps(HIMAGELIST himl
, INT nImageCount
)
320 HBITMAP hbmNewBitmap
, hbmNull
;
324 TRACE("%p has allocated %d, max %d, grow %d images\n", himl
, himl
->cCurImage
, himl
->cMaxImage
, himl
->cGrow
);
326 if (himl
->cCurImage
+ nImageCount
< himl
->cMaxImage
)
329 nNewCount
= himl
->cMaxImage
+ max(nImageCount
, himl
->cGrow
) + 1;
331 imagelist_get_bitmap_size(himl
, nNewCount
, &sz
);
333 TRACE("Create expanded bitmaps : himl=%p x=%d y=%d count=%d\n", himl
, sz
.cx
, sz
.cy
, nNewCount
);
334 hdcBitmap
= CreateCompatibleDC (0);
336 hbmNewBitmap
= ImageList_CreateImage(hdcBitmap
, himl
, nNewCount
);
338 if (hbmNewBitmap
== 0)
339 ERR("creating new image bitmap (x=%d y=%d)!\n", sz
.cx
, sz
.cy
);
343 hbmNull
= SelectObject (hdcBitmap
, hbmNewBitmap
);
344 BitBlt (hdcBitmap
, 0, 0, sz
.cx
, sz
.cy
,
345 himl
->hdcImage
, 0, 0, SRCCOPY
);
346 SelectObject (hdcBitmap
, hbmNull
);
348 SelectObject (himl
->hdcImage
, hbmNewBitmap
);
349 DeleteObject (himl
->hbmImage
);
350 himl
->hbmImage
= hbmNewBitmap
;
352 if (himl
->flags
& ILC_MASK
)
354 hbmNewBitmap
= CreateBitmap (sz
.cx
, sz
.cy
, 1, 1, NULL
);
356 if (hbmNewBitmap
== 0)
357 ERR("creating new mask bitmap!\n");
361 hbmNull
= SelectObject (hdcBitmap
, hbmNewBitmap
);
362 BitBlt (hdcBitmap
, 0, 0, sz
.cx
, sz
.cy
,
363 himl
->hdcMask
, 0, 0, SRCCOPY
);
364 SelectObject (hdcBitmap
, hbmNull
);
366 SelectObject (himl
->hdcMask
, hbmNewBitmap
);
367 DeleteObject (himl
->hbmMask
);
368 himl
->hbmMask
= hbmNewBitmap
;
373 char *new_alpha
= HeapReAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, himl
->has_alpha
, nNewCount
);
374 if (new_alpha
) himl
->has_alpha
= new_alpha
;
377 HeapFree( GetProcessHeap(), 0, himl
->has_alpha
);
378 himl
->has_alpha
= NULL
;
382 himl
->cMaxImage
= nNewCount
;
384 DeleteDC (hdcBitmap
);
388 /*************************************************************************
389 * ImageList_Add [COMCTL32.@]
391 * Add an image or images to an image list.
394 * himl [I] handle to image list
395 * hbmImage [I] handle to image bitmap
396 * hbmMask [I] handle to mask bitmap
399 * Success: Index of the first new image.
404 ImageList_Add (HIMAGELIST himl
, HBITMAP hbmImage
, HBITMAP hbmMask
)
406 HDC hdcBitmap
, hdcTemp
= 0;
407 INT nFirstIndex
, nImageCount
, i
;
411 TRACE("himl=%p hbmimage=%p hbmmask=%p\n", himl
, hbmImage
, hbmMask
);
415 if (!GetObjectW(hbmImage
, sizeof(BITMAP
), &bmp
))
418 TRACE("himl %p, cCurImage %d, cMaxImage %d, cGrow %d, cx %d, cy %d\n",
419 himl
, himl
->cCurImage
, himl
->cMaxImage
, himl
->cGrow
, himl
->cx
, himl
->cy
);
421 nImageCount
= bmp
.bmWidth
/ himl
->cx
;
423 TRACE("%p has %d images (%d x %d)\n", hbmImage
, nImageCount
, bmp
.bmWidth
, bmp
.bmHeight
);
425 IMAGELIST_InternalExpandBitmaps(himl
, nImageCount
);
427 hdcBitmap
= CreateCompatibleDC(0);
429 SelectObject(hdcBitmap
, hbmImage
);
431 if (add_with_alpha( himl
, hdcBitmap
, himl
->cCurImage
, nImageCount
,
432 himl
->cx
, min( himl
->cy
, bmp
.bmHeight
), hbmImage
, hbmMask
))
437 hdcTemp
= CreateCompatibleDC(0);
438 SelectObject(hdcTemp
, hbmMask
);
441 for (i
=0; i
<nImageCount
; i
++)
443 imagelist_point_from_index( himl
, himl
->cCurImage
+ i
, &pt
);
445 /* Copy result to the imagelist
447 BitBlt( himl
->hdcImage
, pt
.x
, pt
.y
, himl
->cx
, bmp
.bmHeight
,
448 hdcBitmap
, i
*himl
->cx
, 0, SRCCOPY
);
453 BitBlt( himl
->hdcMask
, pt
.x
, pt
.y
, himl
->cx
, bmp
.bmHeight
,
454 hdcTemp
, i
*himl
->cx
, 0, SRCCOPY
);
456 /* Remove the background from the image
458 BitBlt( himl
->hdcImage
, pt
.x
, pt
.y
, himl
->cx
, bmp
.bmHeight
,
459 himl
->hdcMask
, pt
.x
, pt
.y
, 0x220326 ); /* NOTSRCAND */
461 if (hdcTemp
) DeleteDC(hdcTemp
);
466 nFirstIndex
= himl
->cCurImage
;
467 himl
->cCurImage
+= nImageCount
;
473 /*************************************************************************
474 * ImageList_AddIcon [COMCTL32.@]
476 * Adds an icon to an image list.
479 * himl [I] handle to image list
480 * hIcon [I] handle to icon
483 * Success: index of the new image
486 #undef ImageList_AddIcon
487 INT WINAPI
ImageList_AddIcon (HIMAGELIST himl
, HICON hIcon
)
489 return ImageList_ReplaceIcon (himl
, -1, hIcon
);
493 /*************************************************************************
494 * ImageList_AddMasked [COMCTL32.@]
496 * Adds an image or images to an image list and creates a mask from the
497 * specified bitmap using the mask color.
500 * himl [I] handle to image list.
501 * hBitmap [I] handle to bitmap
502 * clrMask [I] mask color.
505 * Success: Index of the first new image.
510 ImageList_AddMasked (HIMAGELIST himl
, HBITMAP hBitmap
, COLORREF clrMask
)
512 HDC hdcMask
, hdcBitmap
;
518 TRACE("himl=%p hbitmap=%p clrmask=%x\n", himl
, hBitmap
, clrMask
);
522 if (!GetObjectW(hBitmap
, sizeof(BITMAP
), &bmp
))
525 hdcBitmap
= CreateCompatibleDC(0);
526 SelectObject(hdcBitmap
, hBitmap
);
528 /* Create a temp Mask so we can remove the background of the Image */
529 hdcMask
= CreateCompatibleDC(0);
530 hMaskBitmap
= CreateBitmap(bmp
.bmWidth
, bmp
.bmHeight
, 1, 1, NULL
);
531 SelectObject(hdcMask
, hMaskBitmap
);
533 /* create monochrome image to the mask bitmap */
534 bkColor
= (clrMask
!= CLR_DEFAULT
) ? clrMask
: GetPixel (hdcBitmap
, 0, 0);
535 SetBkColor (hdcBitmap
, bkColor
);
536 BitBlt (hdcMask
, 0, 0, bmp
.bmWidth
, bmp
.bmHeight
, hdcBitmap
, 0, 0, SRCCOPY
);
539 * Remove the background from the image
541 * WINDOWS BUG ALERT!!!!!!
542 * The statement below should not be done in common practice
543 * but this is how ImageList_AddMasked works in Windows.
544 * It overwrites the original bitmap passed, this was discovered
545 * by using the same bitmap to iterate the different styles
546 * on windows where it failed (BUT ImageList_Add is OK)
547 * This is here in case some apps rely on this bug
549 * Blt mode 0x220326 is NOTSRCAND
551 if (bmp
.bmBitsPixel
> 8) /* NOTSRCAND can't work with palettes */
553 SetBkColor(hdcBitmap
, RGB(255,255,255));
554 BitBlt(hdcBitmap
, 0, 0, bmp
.bmWidth
, bmp
.bmHeight
, hdcMask
, 0, 0, 0x220326);
560 ret
= ImageList_Add( himl
, hBitmap
, hMaskBitmap
);
562 DeleteObject(hMaskBitmap
);
567 /*************************************************************************
568 * ImageList_BeginDrag [COMCTL32.@]
570 * Creates a temporary image list that contains one image. It will be used
574 * himlTrack [I] handle to the source image list
575 * iTrack [I] index of the drag image in the source image list
576 * dxHotspot [I] X position of the hot spot of the drag image
577 * dyHotspot [I] Y position of the hot spot of the drag image
585 ImageList_BeginDrag (HIMAGELIST himlTrack
, INT iTrack
,
586 INT dxHotspot
, INT dyHotspot
)
591 TRACE("(himlTrack=%p iTrack=%d dx=%d dy=%d)\n", himlTrack
, iTrack
,
592 dxHotspot
, dyHotspot
);
594 if (!is_valid(himlTrack
))
597 if (iTrack
>= himlTrack
->cCurImage
)
600 if (InternalDrag
.himl
)
606 InternalDrag
.himlNoCursor
= InternalDrag
.himl
= ImageList_Create (cx
, cy
, himlTrack
->flags
, 1, 1);
607 if (InternalDrag
.himl
== NULL
) {
608 WARN("Error creating drag image list!\n");
612 InternalDrag
.dxHotspot
= dxHotspot
;
613 InternalDrag
.dyHotspot
= dyHotspot
;
616 imagelist_point_from_index(InternalDrag
.himl
, 0, &dst
);
617 imagelist_point_from_index(himlTrack
, iTrack
, &src
);
618 BitBlt(InternalDrag
.himl
->hdcImage
, dst
.x
, dst
.y
, cx
, cy
, himlTrack
->hdcImage
, src
.x
, src
.y
,
620 BitBlt(InternalDrag
.himl
->hdcMask
, dst
.x
, dst
.y
, cx
, cy
, himlTrack
->hdcMask
, src
.x
, src
.y
,
623 InternalDrag
.himl
->cCurImage
= 1;
629 /*************************************************************************
630 * ImageList_Copy [COMCTL32.@]
632 * Copies an image of the source image list to an image of the
633 * destination image list. Images can be copied or swapped.
636 * himlDst [I] handle to the destination image list
637 * iDst [I] destination image index.
638 * himlSrc [I] handle to the source image list
639 * iSrc [I] source image index
640 * uFlags [I] flags for the copy operation
647 * Copying from one image list to another is possible. The original
648 * implementation just copies or swaps within one image list.
649 * Could this feature become a bug??? ;-)
653 ImageList_Copy (HIMAGELIST himlDst
, INT iDst
, HIMAGELIST himlSrc
,
654 INT iSrc
, UINT uFlags
)
658 TRACE("himlDst=%p iDst=%d himlSrc=%p iSrc=%d\n", himlDst
, iDst
, himlSrc
, iSrc
);
660 if (!is_valid(himlSrc
) || !is_valid(himlDst
))
662 if ((iDst
< 0) || (iDst
>= himlDst
->cCurImage
))
664 if ((iSrc
< 0) || (iSrc
>= himlSrc
->cCurImage
))
667 imagelist_point_from_index( himlDst
, iDst
, &ptDst
);
668 imagelist_point_from_index( himlSrc
, iSrc
, &ptSrc
);
670 if (uFlags
& ILCF_SWAP
) {
673 HBITMAP hbmTempImage
, hbmTempMask
;
675 hdcBmp
= CreateCompatibleDC (0);
677 /* create temporary bitmaps */
678 hbmTempImage
= CreateBitmap (himlSrc
->cx
, himlSrc
->cy
, 1,
679 himlSrc
->uBitsPixel
, NULL
);
680 hbmTempMask
= CreateBitmap (himlSrc
->cx
, himlSrc
->cy
, 1,
683 /* copy (and stretch) destination to temporary bitmaps.(save) */
685 SelectObject (hdcBmp
, hbmTempImage
);
686 StretchBlt (hdcBmp
, 0, 0, himlSrc
->cx
, himlSrc
->cy
,
687 himlDst
->hdcImage
, ptDst
.x
, ptDst
.y
, himlDst
->cx
, himlDst
->cy
,
690 SelectObject (hdcBmp
, hbmTempMask
);
691 StretchBlt (hdcBmp
, 0, 0, himlSrc
->cx
, himlSrc
->cy
,
692 himlDst
->hdcMask
, ptDst
.x
, ptDst
.y
, himlDst
->cx
, himlDst
->cy
,
695 /* copy (and stretch) source to destination */
697 StretchBlt (himlDst
->hdcImage
, ptDst
.x
, ptDst
.y
, himlDst
->cx
, himlDst
->cy
,
698 himlSrc
->hdcImage
, ptSrc
.x
, ptSrc
.y
, himlSrc
->cx
, himlSrc
->cy
,
701 StretchBlt (himlDst
->hdcMask
, ptDst
.x
, ptDst
.y
, himlDst
->cx
, himlDst
->cy
,
702 himlSrc
->hdcMask
, ptSrc
.x
, ptSrc
.y
, himlSrc
->cx
, himlSrc
->cy
,
705 /* copy (without stretching) temporary bitmaps to source (restore) */
707 BitBlt (himlSrc
->hdcMask
, ptSrc
.x
, ptSrc
.y
, himlSrc
->cx
, himlSrc
->cy
,
708 hdcBmp
, 0, 0, SRCCOPY
);
711 BitBlt (himlSrc
->hdcImage
, ptSrc
.x
, ptSrc
.y
, himlSrc
->cx
, himlSrc
->cy
,
712 hdcBmp
, 0, 0, SRCCOPY
);
713 /* delete temporary bitmaps */
714 DeleteObject (hbmTempMask
);
715 DeleteObject (hbmTempImage
);
720 StretchBlt (himlDst
->hdcImage
, ptDst
.x
, ptDst
.y
, himlDst
->cx
, himlDst
->cy
,
721 himlSrc
->hdcImage
, ptSrc
.x
, ptSrc
.y
, himlSrc
->cx
, himlSrc
->cy
,
725 StretchBlt (himlDst
->hdcMask
, ptDst
.x
, ptDst
.y
, himlDst
->cx
, himlDst
->cy
,
726 himlSrc
->hdcMask
, ptSrc
.x
, ptSrc
.y
, himlSrc
->cx
, himlSrc
->cy
,
734 /*************************************************************************
735 * ImageList_Create [COMCTL32.@]
737 * Creates a new image list.
740 * cx [I] image height
742 * flags [I] creation flags
743 * cInitial [I] initial number of images in the image list
744 * cGrow [I] number of images by which image list grows
747 * Success: Handle to the created image list
751 ImageList_Create (INT cx
, INT cy
, UINT flags
,
752 INT cInitial
, INT cGrow
)
757 UINT ilc
= (flags
& 0xFE);
758 static const WORD aBitBlend25
[] =
759 {0xAA, 0x00, 0x55, 0x00, 0xAA, 0x00, 0x55, 0x00};
761 static const WORD aBitBlend50
[] =
762 {0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA};
764 TRACE("(%d %d 0x%x %d %d)\n", cx
, cy
, flags
, cInitial
, cGrow
);
766 if (cx
<= 0 || cy
<= 0) return NULL
;
768 /* Create the IImageList interface for the image list */
769 if (FAILED(ImageListImpl_CreateInstance(NULL
, &IID_IImageList
, (void **)&himl
)))
772 cGrow
= (WORD
)((max( cGrow
, 1 ) + 3) & ~3);
776 /* Windows doesn't limit the size here, but X11 doesn't let us allocate such huge bitmaps */
777 WARN( "grow %d too large, limiting to 256\n", cGrow
);
784 himl
->cMaxImage
= cInitial
+ 1;
785 himl
->cInitial
= cInitial
;
787 himl
->clrFg
= CLR_DEFAULT
;
788 himl
->clrBk
= CLR_NONE
;
790 /* initialize overlay mask indices */
791 for (nCount
= 0; nCount
< MAX_OVERLAYIMAGE
; nCount
++)
792 himl
->nOvlIdx
[nCount
] = -1;
794 /* Create Image & Mask DCs */
795 himl
->hdcImage
= CreateCompatibleDC (0);
798 if (himl
->flags
& ILC_MASK
){
799 himl
->hdcMask
= CreateCompatibleDC(0);
804 /* Default to ILC_COLOR4 if none of the ILC_COLOR* flags are specified */
805 if (ilc
== ILC_COLOR
)
808 himl
->flags
|= ILC_COLOR4
;
811 if (ilc
>= ILC_COLOR4
&& ilc
<= ILC_COLOR32
)
812 himl
->uBitsPixel
= ilc
;
814 himl
->uBitsPixel
= (UINT
)GetDeviceCaps (himl
->hdcImage
, BITSPIXEL
);
816 if (himl
->cMaxImage
> 0) {
817 himl
->hbmImage
= ImageList_CreateImage(himl
->hdcImage
, himl
, himl
->cMaxImage
);
818 SelectObject(himl
->hdcImage
, himl
->hbmImage
);
822 if ((himl
->cMaxImage
> 0) && (himl
->flags
& ILC_MASK
)) {
825 imagelist_get_bitmap_size(himl
, himl
->cMaxImage
, &sz
);
826 himl
->hbmMask
= CreateBitmap (sz
.cx
, sz
.cy
, 1, 1, NULL
);
827 if (himl
->hbmMask
== 0) {
828 ERR("Error creating mask bitmap!\n");
831 SelectObject(himl
->hdcMask
, himl
->hbmMask
);
836 if (ilc
== ILC_COLOR32
)
837 himl
->has_alpha
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, himl
->cMaxImage
);
839 himl
->has_alpha
= NULL
;
841 /* create blending brushes */
842 hbmTemp
= CreateBitmap (8, 8, 1, 1, aBitBlend25
);
843 himl
->hbrBlend25
= CreatePatternBrush (hbmTemp
);
844 DeleteObject (hbmTemp
);
846 hbmTemp
= CreateBitmap (8, 8, 1, 1, aBitBlend50
);
847 himl
->hbrBlend50
= CreatePatternBrush (hbmTemp
);
848 DeleteObject (hbmTemp
);
850 TRACE("created imagelist %p\n", himl
);
854 ImageList_Destroy(himl
);
859 /*************************************************************************
860 * ImageList_Destroy [COMCTL32.@]
862 * Destroys an image list.
865 * himl [I] handle to image list
873 ImageList_Destroy (HIMAGELIST himl
)
878 IImageList_Release((IImageList
*) himl
);
883 /*************************************************************************
884 * ImageList_DragEnter [COMCTL32.@]
886 * Locks window update and displays the drag image at the given position.
889 * hwndLock [I] handle of the window that owns the drag image.
890 * x [I] X position of the drag image.
891 * y [I] Y position of the drag image.
898 * The position of the drag image is relative to the window, not
903 ImageList_DragEnter (HWND hwndLock
, INT x
, INT y
)
905 TRACE("(hwnd=%p x=%d y=%d)\n", hwndLock
, x
, y
);
907 if (!is_valid(InternalDrag
.himl
))
911 InternalDrag
.hwnd
= hwndLock
;
913 InternalDrag
.hwnd
= GetDesktopWindow ();
918 /* draw the drag image and save the background */
919 if (!ImageList_DragShowNolock(TRUE
)) {
927 /*************************************************************************
928 * ImageList_DragLeave [COMCTL32.@]
930 * Unlocks window update and hides the drag image.
933 * hwndLock [I] handle of the window that owns the drag image.
941 ImageList_DragLeave (HWND hwndLock
)
943 /* As we don't save drag info in the window this can lead to problems if
944 an app does not supply the same window as DragEnter */
946 InternalDrag.hwnd = hwndLock;
948 InternalDrag.hwnd = GetDesktopWindow (); */
950 hwndLock
= GetDesktopWindow();
951 if(InternalDrag
.hwnd
!= hwndLock
)
952 FIXME("DragLeave hWnd != DragEnter hWnd\n");
954 ImageList_DragShowNolock (FALSE
);
960 /*************************************************************************
961 * ImageList_InternalDragDraw [Internal]
963 * Draws the drag image.
966 * hdc [I] device context to draw into.
967 * x [I] X position of the drag image.
968 * y [I] Y position of the drag image.
975 * The position of the drag image is relative to the window, not
981 ImageList_InternalDragDraw (HDC hdc
, INT x
, INT y
)
983 IMAGELISTDRAWPARAMS imldp
;
985 ZeroMemory (&imldp
, sizeof(imldp
));
986 imldp
.cbSize
= sizeof(imldp
);
987 imldp
.himl
= InternalDrag
.himl
;
992 imldp
.rgbBk
= CLR_DEFAULT
;
993 imldp
.rgbFg
= CLR_DEFAULT
;
994 imldp
.fStyle
= ILD_NORMAL
;
995 imldp
.fState
= ILS_ALPHA
;
997 ImageList_DrawIndirect (&imldp
);
1000 /*************************************************************************
1001 * ImageList_DragMove [COMCTL32.@]
1003 * Moves the drag image.
1006 * x [I] X position of the drag image.
1007 * y [I] Y position of the drag image.
1014 * The position of the drag image is relative to the window, not
1019 ImageList_DragMove (INT x
, INT y
)
1021 TRACE("(x=%d y=%d)\n", x
, y
);
1023 if (!is_valid(InternalDrag
.himl
))
1026 /* draw/update the drag image */
1027 if (InternalDrag
.bShow
) {
1031 HBITMAP hbmOffScreen
;
1032 INT origNewX
, origNewY
;
1033 INT origOldX
, origOldY
;
1034 INT origRegX
, origRegY
;
1035 INT sizeRegX
, sizeRegY
;
1038 /* calculate the update region */
1039 origNewX
= x
- InternalDrag
.dxHotspot
;
1040 origNewY
= y
- InternalDrag
.dyHotspot
;
1041 origOldX
= InternalDrag
.x
- InternalDrag
.dxHotspot
;
1042 origOldY
= InternalDrag
.y
- InternalDrag
.dyHotspot
;
1043 origRegX
= min(origNewX
, origOldX
);
1044 origRegY
= min(origNewY
, origOldY
);
1045 sizeRegX
= InternalDrag
.himl
->cx
+ abs(x
- InternalDrag
.x
);
1046 sizeRegY
= InternalDrag
.himl
->cy
+ abs(y
- InternalDrag
.y
);
1048 hdcDrag
= GetDCEx(InternalDrag
.hwnd
, 0,
1049 DCX_WINDOW
| DCX_CACHE
| DCX_LOCKWINDOWUPDATE
);
1050 hdcOffScreen
= CreateCompatibleDC(hdcDrag
);
1051 hdcBg
= CreateCompatibleDC(hdcDrag
);
1053 hbmOffScreen
= CreateCompatibleBitmap(hdcDrag
, sizeRegX
, sizeRegY
);
1054 SelectObject(hdcOffScreen
, hbmOffScreen
);
1055 SelectObject(hdcBg
, InternalDrag
.hbmBg
);
1057 /* get the actual background of the update region */
1058 BitBlt(hdcOffScreen
, 0, 0, sizeRegX
, sizeRegY
, hdcDrag
,
1059 origRegX
, origRegY
, SRCCOPY
);
1060 /* erase the old image */
1061 BitBlt(hdcOffScreen
, origOldX
- origRegX
, origOldY
- origRegY
,
1062 InternalDrag
.himl
->cx
, InternalDrag
.himl
->cy
, hdcBg
, 0, 0,
1064 /* save the background */
1065 BitBlt(hdcBg
, 0, 0, InternalDrag
.himl
->cx
, InternalDrag
.himl
->cy
,
1066 hdcOffScreen
, origNewX
- origRegX
, origNewY
- origRegY
, SRCCOPY
);
1067 /* draw the image */
1068 ImageList_InternalDragDraw(hdcOffScreen
, origNewX
- origRegX
,
1069 origNewY
- origRegY
);
1070 /* draw the update region to the screen */
1071 BitBlt(hdcDrag
, origRegX
, origRegY
, sizeRegX
, sizeRegY
,
1072 hdcOffScreen
, 0, 0, SRCCOPY
);
1075 DeleteDC(hdcOffScreen
);
1076 DeleteObject(hbmOffScreen
);
1077 ReleaseDC(InternalDrag
.hwnd
, hdcDrag
);
1080 /* update the image position */
1088 /*************************************************************************
1089 * ImageList_DragShowNolock [COMCTL32.@]
1091 * Shows or hides the drag image.
1094 * bShow [I] TRUE shows the drag image, FALSE hides it.
1102 ImageList_DragShowNolock (BOOL bShow
)
1108 if (!is_valid(InternalDrag
.himl
))
1111 TRACE("bShow=0x%X!\n", bShow
);
1113 /* DragImage is already visible/hidden */
1114 if ((InternalDrag
.bShow
&& bShow
) || (!InternalDrag
.bShow
&& !bShow
)) {
1118 /* position of the origin of the DragImage */
1119 x
= InternalDrag
.x
- InternalDrag
.dxHotspot
;
1120 y
= InternalDrag
.y
- InternalDrag
.dyHotspot
;
1122 hdcDrag
= GetDCEx (InternalDrag
.hwnd
, 0,
1123 DCX_WINDOW
| DCX_CACHE
| DCX_LOCKWINDOWUPDATE
);
1128 hdcBg
= CreateCompatibleDC(hdcDrag
);
1129 if (!InternalDrag
.hbmBg
) {
1130 InternalDrag
.hbmBg
= CreateCompatibleBitmap(hdcDrag
,
1131 InternalDrag
.himl
->cx
, InternalDrag
.himl
->cy
);
1133 SelectObject(hdcBg
, InternalDrag
.hbmBg
);
1136 /* save the background */
1137 BitBlt(hdcBg
, 0, 0, InternalDrag
.himl
->cx
, InternalDrag
.himl
->cy
,
1138 hdcDrag
, x
, y
, SRCCOPY
);
1139 /* show the image */
1140 ImageList_InternalDragDraw(hdcDrag
, x
, y
);
1142 /* hide the image */
1143 BitBlt(hdcDrag
, x
, y
, InternalDrag
.himl
->cx
, InternalDrag
.himl
->cy
,
1144 hdcBg
, 0, 0, SRCCOPY
);
1147 InternalDrag
.bShow
= !InternalDrag
.bShow
;
1150 ReleaseDC (InternalDrag
.hwnd
, hdcDrag
);
1155 /*************************************************************************
1156 * ImageList_Draw [COMCTL32.@]
1161 * himl [I] handle to image list
1163 * hdc [I] handle to device context
1166 * fStyle [I] drawing flags
1177 ImageList_Draw (HIMAGELIST himl
, INT i
, HDC hdc
, INT x
, INT y
, UINT fStyle
)
1179 return ImageList_DrawEx (himl
, i
, hdc
, x
, y
, 0, 0,
1180 CLR_DEFAULT
, CLR_DEFAULT
, fStyle
);
1184 /*************************************************************************
1185 * ImageList_DrawEx [COMCTL32.@]
1187 * Draws an image and allows using extended drawing features.
1190 * himl [I] handle to image list
1192 * hdc [I] handle to device context
1197 * rgbBk [I] background color
1198 * rgbFg [I] foreground color
1199 * fStyle [I] drawing flags
1206 * Calls ImageList_DrawIndirect.
1209 * ImageList_DrawIndirect.
1213 ImageList_DrawEx (HIMAGELIST himl
, INT i
, HDC hdc
, INT x
, INT y
,
1214 INT dx
, INT dy
, COLORREF rgbBk
, COLORREF rgbFg
,
1217 IMAGELISTDRAWPARAMS imldp
;
1219 ZeroMemory (&imldp
, sizeof(imldp
));
1220 imldp
.cbSize
= sizeof(imldp
);
1228 imldp
.rgbBk
= rgbBk
;
1229 imldp
.rgbFg
= rgbFg
;
1230 imldp
.fStyle
= fStyle
;
1232 return ImageList_DrawIndirect (&imldp
);
1236 static BOOL
alpha_blend_image( HIMAGELIST himl
, HDC srce_dc
, HDC dest_dc
, int dest_x
, int dest_y
,
1237 int src_x
, int src_y
, int cx
, int cy
, BLENDFUNCTION func
,
1238 UINT style
, COLORREF blend_col
)
1242 HBITMAP bmp
= 0, mask
= 0;
1244 void *bits
, *mask_bits
;
1248 if (!(hdc
= CreateCompatibleDC( 0 ))) return FALSE
;
1249 if (!(info
= HeapAlloc( GetProcessHeap(), 0, FIELD_OFFSET( BITMAPINFO
, bmiColors
[256] )))) goto done
;
1250 info
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
1251 info
->bmiHeader
.biWidth
= cx
;
1252 info
->bmiHeader
.biHeight
= cy
;
1253 info
->bmiHeader
.biPlanes
= 1;
1254 info
->bmiHeader
.biBitCount
= 32;
1255 info
->bmiHeader
.biCompression
= BI_RGB
;
1256 info
->bmiHeader
.biSizeImage
= cx
* cy
* 4;
1257 info
->bmiHeader
.biXPelsPerMeter
= 0;
1258 info
->bmiHeader
.biYPelsPerMeter
= 0;
1259 info
->bmiHeader
.biClrUsed
= 0;
1260 info
->bmiHeader
.biClrImportant
= 0;
1261 if (!(bmp
= CreateDIBSection( srce_dc
, info
, DIB_RGB_COLORS
, &bits
, 0, 0 ))) goto done
;
1262 SelectObject( hdc
, bmp
);
1263 BitBlt( hdc
, 0, 0, cx
, cy
, srce_dc
, src_x
, src_y
, SRCCOPY
);
1265 if (blend_col
!= CLR_NONE
)
1267 BYTE r
= GetRValue( blend_col
);
1268 BYTE g
= GetGValue( blend_col
);
1269 BYTE b
= GetBValue( blend_col
);
1271 if (style
& ILD_BLEND25
)
1273 for (i
= 0, ptr
= bits
; i
< cx
* cy
; i
++, ptr
++)
1274 *ptr
= ((*ptr
& 0xff000000) |
1275 ((((*ptr
& 0x00ff0000) * 3 + (r
<< 16)) / 4) & 0x00ff0000) |
1276 ((((*ptr
& 0x0000ff00) * 3 + (g
<< 8)) / 4) & 0x0000ff00) |
1277 ((((*ptr
& 0x000000ff) * 3 + (b
<< 0)) / 4) & 0x000000ff));
1279 else if (style
& ILD_BLEND50
)
1281 for (i
= 0, ptr
= bits
; i
< cx
* cy
; i
++, ptr
++)
1282 *ptr
= ((*ptr
& 0xff000000) |
1283 ((((*ptr
& 0x00ff0000) + (r
<< 16)) / 2) & 0x00ff0000) |
1284 ((((*ptr
& 0x0000ff00) + (g
<< 8)) / 2) & 0x0000ff00) |
1285 ((((*ptr
& 0x000000ff) + (b
<< 0)) / 2) & 0x000000ff));
1289 if (himl
->has_alpha
) /* we already have an alpha channel in this case */
1291 /* pre-multiply by the alpha channel */
1292 for (i
= 0, ptr
= bits
; i
< cx
* cy
; i
++, ptr
++)
1294 DWORD alpha
= *ptr
>> 24;
1295 *ptr
= ((*ptr
& 0xff000000) |
1296 (((*ptr
& 0x00ff0000) * alpha
/ 255) & 0x00ff0000) |
1297 (((*ptr
& 0x0000ff00) * alpha
/ 255) & 0x0000ff00) |
1298 (((*ptr
& 0x000000ff) * alpha
/ 255)));
1301 else if (himl
->hbmMask
)
1303 unsigned int width_bytes
= (cx
+ 31) / 32 * 4;
1304 /* generate alpha channel from the mask */
1305 info
->bmiHeader
.biBitCount
= 1;
1306 info
->bmiHeader
.biSizeImage
= width_bytes
* cy
;
1307 info
->bmiColors
[0].rgbRed
= 0;
1308 info
->bmiColors
[0].rgbGreen
= 0;
1309 info
->bmiColors
[0].rgbBlue
= 0;
1310 info
->bmiColors
[0].rgbReserved
= 0;
1311 info
->bmiColors
[1].rgbRed
= 0xff;
1312 info
->bmiColors
[1].rgbGreen
= 0xff;
1313 info
->bmiColors
[1].rgbBlue
= 0xff;
1314 info
->bmiColors
[1].rgbReserved
= 0;
1315 if (!(mask
= CreateDIBSection( himl
->hdcMask
, info
, DIB_RGB_COLORS
, &mask_bits
, 0, 0 )))
1317 SelectObject( hdc
, mask
);
1318 BitBlt( hdc
, 0, 0, cx
, cy
, himl
->hdcMask
, src_x
, src_y
, SRCCOPY
);
1319 SelectObject( hdc
, bmp
);
1320 for (i
= 0, ptr
= bits
; i
< cy
; i
++)
1321 for (j
= 0; j
< cx
; j
++, ptr
++)
1322 if ((((BYTE
*)mask_bits
)[i
* width_bytes
+ j
/ 8] << (j
% 8)) & 0x80) *ptr
= 0;
1323 else *ptr
|= 0xff000000;
1326 ret
= GdiAlphaBlend( dest_dc
, dest_x
, dest_y
, cx
, cy
, hdc
, 0, 0, cx
, cy
, func
);
1330 if (bmp
) DeleteObject( bmp
);
1331 if (mask
) DeleteObject( mask
);
1332 HeapFree( GetProcessHeap(), 0, info
);
1336 HDC
saturate_image( HIMAGELIST himl
, HDC dest_dc
, int dest_x
, int dest_y
,
1337 int src_x
, int src_y
, int cx
, int cy
, COLORREF rgbFg
)
1347 /* create a dc and its device independent bitmap for doing the work,
1348 shamelessly copied from the alpha-blending function above */
1349 if (!(hdc
= CreateCompatibleDC( 0 ))) return FALSE
;
1350 if (!(info
= HeapAlloc( GetProcessHeap(), 0, FIELD_OFFSET( BITMAPINFO
, bmiColors
[256] )))) goto done
;
1351 info
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
1352 info
->bmiHeader
.biWidth
= cx
;
1353 info
->bmiHeader
.biHeight
= cy
;
1354 info
->bmiHeader
.biPlanes
= 1;
1355 info
->bmiHeader
.biBitCount
= 32;
1356 info
->bmiHeader
.biCompression
= BI_RGB
;
1357 info
->bmiHeader
.biSizeImage
= cx
* cy
* 4;
1358 info
->bmiHeader
.biXPelsPerMeter
= 0;
1359 info
->bmiHeader
.biYPelsPerMeter
= 0;
1360 info
->bmiHeader
.biClrUsed
= 0;
1361 info
->bmiHeader
.biClrImportant
= 0;
1362 if (!(bmp
= CreateDIBSection(himl
->hdcImage
, info
, DIB_RGB_COLORS
, &bits
, 0, 0 ))) goto done
;
1364 /* bind both surfaces */
1365 SelectObject(hdc
, bmp
);
1367 /* copy into our dc the section that covers just the icon we we're asked for */
1368 BitBlt(hdc
, 0, 0, cx
, cy
, himl
->hdcImage
, src_x
, src_y
, SRCCOPY
);
1370 /* loop every pixel of the bitmap */
1371 for (i
= 0, ptr
= bits
; i
< cx
* cy
; i
++, ptr
++)
1373 COLORREF orig_color
= *ptr
;
1375 /* calculate the effective luminance using the constants from here, adapted to the human eye:
1376 <http://bobpowell.net/grayscale.aspx> */
1377 float mixed_color
= (GetRValue(orig_color
) * .30 +
1378 GetGValue(orig_color
) * .59 +
1379 GetBValue(orig_color
) * .11);
1381 *ptr
= RGBA(mixed_color
, mixed_color
, mixed_color
, GetAValue(orig_color
));
1390 HeapFree(GetProcessHeap(), 0, info
);
1392 /* return the handle to our desaturated dc, that will substitute its original counterpart in the next calls */
1396 /*************************************************************************
1397 * ImageList_DrawIndirect [COMCTL32.@]
1399 * Draws an image using various parameters specified in pimldp.
1402 * pimldp [I] pointer to IMAGELISTDRAWPARAMS structure.
1410 ImageList_DrawIndirect (IMAGELISTDRAWPARAMS
*pimldp
)
1412 INT cx
, cy
, nOvlIdx
;
1413 DWORD fState
, dwRop
;
1415 COLORREF oldImageBk
, oldImageFg
;
1416 HDC hImageDC
, hImageListDC
, hMaskListDC
;
1417 HBITMAP hImageBmp
, hOldImageBmp
, hBlendMaskBmp
;
1418 BOOL bIsTransparent
, bBlend
, bResult
= FALSE
, bMask
;
1424 if (!pimldp
|| !(himl
= pimldp
->himl
)) return FALSE
;
1425 if (!is_valid(himl
)) return FALSE
;
1426 if ((pimldp
->i
< 0) || (pimldp
->i
>= himl
->cCurImage
)) return FALSE
;
1428 imagelist_point_from_index( himl
, pimldp
->i
, &pt
);
1429 pt
.x
+= pimldp
->xBitmap
;
1430 pt
.y
+= pimldp
->yBitmap
;
1432 fState
= pimldp
->cbSize
< sizeof(IMAGELISTDRAWPARAMS
) ? ILS_NORMAL
: pimldp
->fState
;
1433 fStyle
= pimldp
->fStyle
& ~ILD_OVERLAYMASK
;
1434 cx
= (pimldp
->cx
== 0) ? himl
->cx
: pimldp
->cx
;
1435 cy
= (pimldp
->cy
== 0) ? himl
->cy
: pimldp
->cy
;
1437 bIsTransparent
= (fStyle
& ILD_TRANSPARENT
);
1438 if( pimldp
->rgbBk
== CLR_NONE
)
1439 bIsTransparent
= TRUE
;
1440 if( ( pimldp
->rgbBk
== CLR_DEFAULT
) && ( himl
->clrBk
== CLR_NONE
) )
1441 bIsTransparent
= TRUE
;
1442 bMask
= (himl
->flags
& ILC_MASK
) && (fStyle
& ILD_MASK
) ;
1443 bBlend
= (fStyle
& (ILD_BLEND25
| ILD_BLEND50
) ) && !bMask
;
1445 TRACE("himl(%p) hbmMask(%p) iImage(%d) x(%d) y(%d) cx(%d) cy(%d)\n",
1446 himl
, himl
->hbmMask
, pimldp
->i
, pimldp
->x
, pimldp
->y
, cx
, cy
);
1448 /* we will use these DCs to access the images and masks in the ImageList */
1449 hImageListDC
= himl
->hdcImage
;
1450 hMaskListDC
= himl
->hdcMask
;
1452 /* these will accumulate the image and mask for the image we're drawing */
1453 hImageDC
= CreateCompatibleDC( pimldp
->hdcDst
);
1454 hImageBmp
= CreateCompatibleBitmap( pimldp
->hdcDst
, cx
, cy
);
1455 hBlendMaskBmp
= bBlend
? CreateBitmap(cx
, cy
, 1, 1, NULL
) : 0;
1457 /* Create a compatible DC. */
1458 if (!hImageListDC
|| !hImageDC
|| !hImageBmp
||
1459 (bBlend
&& !hBlendMaskBmp
) || (himl
->hbmMask
&& !hMaskListDC
))
1462 hOldImageBmp
= SelectObject(hImageDC
, hImageBmp
);
1465 * To obtain a transparent look, background color should be set
1466 * to white and foreground color to black when blitting the
1469 oldImageFg
= SetTextColor( hImageDC
, RGB( 0, 0, 0 ) );
1470 oldImageBk
= SetBkColor( hImageDC
, RGB( 0xff, 0xff, 0xff ) );
1473 * If the ILS_SATURATE bit is enabled we should multiply the
1474 * RGB colors of the original image by the contents of rgbFg.
1476 if (fState
& ILS_SATURATE
)
1478 hImageListDC
= saturate_image(himl
, pimldp
->hdcDst
, pimldp
->x
, pimldp
->y
,
1479 pt
.x
, pt
.y
, cx
, cy
, pimldp
->rgbFg
);
1481 /* shitty way of getting subroutines to blit at the right place (top left corner),
1482 as our modified imagelist only contains a single image for performance reasons */
1487 has_alpha
= (himl
->has_alpha
&& himl
->has_alpha
[pimldp
->i
]);
1488 if (!bMask
&& (has_alpha
|| (fState
& ILS_ALPHA
)))
1490 COLORREF colour
, blend_col
= CLR_NONE
;
1495 blend_col
= pimldp
->rgbFg
;
1496 if (blend_col
== CLR_DEFAULT
) blend_col
= GetSysColor( COLOR_HIGHLIGHT
);
1497 else if (blend_col
== CLR_NONE
) blend_col
= GetTextColor( pimldp
->hdcDst
);
1500 func
.BlendOp
= AC_SRC_OVER
;
1501 func
.BlendFlags
= 0;
1502 func
.SourceConstantAlpha
= (fState
& ILS_ALPHA
) ? pimldp
->Frame
: 255;
1503 func
.AlphaFormat
= AC_SRC_ALPHA
;
1507 bResult
= alpha_blend_image( himl
, hImageListDC
, pimldp
->hdcDst
, pimldp
->x
, pimldp
->y
,
1508 pt
.x
, pt
.y
, cx
, cy
, func
, fStyle
, blend_col
);
1511 colour
= pimldp
->rgbBk
;
1512 if (colour
== CLR_DEFAULT
) colour
= himl
->clrBk
;
1513 if (colour
== CLR_NONE
) colour
= GetBkColor( pimldp
->hdcDst
);
1515 hOldBrush
= SelectObject (hImageDC
, CreateSolidBrush (colour
));
1516 PatBlt( hImageDC
, 0, 0, cx
, cy
, PATCOPY
);
1517 alpha_blend_image( himl
, hImageListDC
, hImageDC
, 0, 0, pt
.x
, pt
.y
, cx
, cy
, func
, fStyle
, blend_col
);
1518 DeleteObject (SelectObject (hImageDC
, hOldBrush
));
1519 bResult
= BitBlt( pimldp
->hdcDst
, pimldp
->x
, pimldp
->y
, cx
, cy
, hImageDC
, 0, 0, SRCCOPY
);
1524 * Draw the initial image
1527 if (himl
->hbmMask
) {
1528 hOldBrush
= SelectObject (hImageDC
, CreateSolidBrush (GetTextColor(pimldp
->hdcDst
)));
1529 PatBlt( hImageDC
, 0, 0, cx
, cy
, PATCOPY
);
1530 BitBlt(hImageDC
, 0, 0, cx
, cy
, hMaskListDC
, pt
.x
, pt
.y
, SRCPAINT
);
1531 DeleteObject (SelectObject (hImageDC
, hOldBrush
));
1532 if( bIsTransparent
)
1534 BitBlt ( pimldp
->hdcDst
, pimldp
->x
, pimldp
->y
, cx
, cy
, hImageDC
, 0, 0, SRCAND
);
1539 hOldBrush
= SelectObject (hImageDC
, GetStockObject(BLACK_BRUSH
));
1540 PatBlt( hImageDC
, 0, 0, cx
, cy
, PATCOPY
);
1541 SelectObject(hImageDC
, hOldBrush
);
1544 /* blend the image with the needed solid background */
1545 COLORREF colour
= RGB(0,0,0);
1547 if( !bIsTransparent
)
1549 colour
= pimldp
->rgbBk
;
1550 if( colour
== CLR_DEFAULT
)
1551 colour
= himl
->clrBk
;
1552 if( colour
== CLR_NONE
)
1553 colour
= GetBkColor(pimldp
->hdcDst
);
1556 hOldBrush
= SelectObject (hImageDC
, CreateSolidBrush (colour
));
1557 PatBlt( hImageDC
, 0, 0, cx
, cy
, PATCOPY
);
1560 BitBlt( hImageDC
, 0, 0, cx
, cy
, hMaskListDC
, pt
.x
, pt
.y
, SRCAND
);
1561 BitBlt( hImageDC
, 0, 0, cx
, cy
, hImageListDC
, pt
.x
, pt
.y
, SRCPAINT
);
1564 BitBlt( hImageDC
, 0, 0, cx
, cy
, hImageListDC
, pt
.x
, pt
.y
, SRCCOPY
);
1565 DeleteObject (SelectObject (hImageDC
, hOldBrush
));
1568 /* Time for blending, if required */
1571 COLORREF clrBlend
= pimldp
->rgbFg
;
1572 HDC hBlendMaskDC
= hImageListDC
;
1575 /* Create the blend Mask */
1576 hOldBitmap
= SelectObject(hBlendMaskDC
, hBlendMaskBmp
);
1577 hBlendBrush
= fStyle
& ILD_BLEND50
? himl
->hbrBlend50
: himl
->hbrBlend25
;
1578 hOldBrush
= SelectObject(hBlendMaskDC
, hBlendBrush
);
1579 PatBlt(hBlendMaskDC
, 0, 0, cx
, cy
, PATCOPY
);
1580 SelectObject(hBlendMaskDC
, hOldBrush
);
1582 /* Modify the blend mask if an Image Mask exist */
1584 BitBlt(hBlendMaskDC
, 0, 0, cx
, cy
, hMaskListDC
, pt
.x
, pt
.y
, 0x220326); /* NOTSRCAND */
1585 BitBlt(hBlendMaskDC
, 0, 0, cx
, cy
, hBlendMaskDC
, 0, 0, NOTSRCCOPY
);
1588 /* now apply blend to the current image given the BlendMask */
1589 if (clrBlend
== CLR_DEFAULT
) clrBlend
= GetSysColor (COLOR_HIGHLIGHT
);
1590 else if (clrBlend
== CLR_NONE
) clrBlend
= GetTextColor (pimldp
->hdcDst
);
1591 hOldBrush
= SelectObject (hImageDC
, CreateSolidBrush(clrBlend
));
1592 BitBlt (hImageDC
, 0, 0, cx
, cy
, hBlendMaskDC
, 0, 0, 0xB8074A); /* PSDPxax */
1593 DeleteObject(SelectObject(hImageDC
, hOldBrush
));
1594 SelectObject(hBlendMaskDC
, hOldBitmap
);
1597 /* Now do the overlay image, if any */
1598 nOvlIdx
= (pimldp
->fStyle
& ILD_OVERLAYMASK
) >> 8;
1599 if ( (nOvlIdx
>= 1) && (nOvlIdx
<= MAX_OVERLAYIMAGE
)) {
1600 nOvlIdx
= himl
->nOvlIdx
[nOvlIdx
- 1];
1601 if ((nOvlIdx
>= 0) && (nOvlIdx
< himl
->cCurImage
)) {
1603 imagelist_point_from_index( himl
, nOvlIdx
, &ptOvl
);
1604 ptOvl
.x
+= pimldp
->xBitmap
;
1605 if (himl
->hbmMask
&& !(fStyle
& ILD_IMAGE
))
1606 BitBlt (hImageDC
, 0, 0, cx
, cy
, hMaskListDC
, ptOvl
.x
, ptOvl
.y
, SRCAND
);
1607 BitBlt (hImageDC
, 0, 0, cx
, cy
, hImageListDC
, ptOvl
.x
, ptOvl
.y
, SRCPAINT
);
1611 if (fState
& ILS_GLOW
) FIXME("ILS_GLOW: unimplemented!\n");
1612 if (fState
& ILS_SHADOW
) FIXME("ILS_SHADOW: unimplemented!\n");
1614 if (fStyle
& ILD_PRESERVEALPHA
) FIXME("ILD_PRESERVEALPHA: unimplemented!\n");
1615 if (fStyle
& ILD_SCALE
) FIXME("ILD_SCALE: unimplemented!\n");
1616 if (fStyle
& ILD_DPISCALE
) FIXME("ILD_DPISCALE: unimplemented!\n");
1618 /* now copy the image to the screen */
1620 if (himl
->hbmMask
&& bIsTransparent
) {
1621 COLORREF oldDstFg
= SetTextColor(pimldp
->hdcDst
, RGB( 0, 0, 0 ) );
1622 COLORREF oldDstBk
= SetBkColor(pimldp
->hdcDst
, RGB( 0xff, 0xff, 0xff ));
1623 BitBlt (pimldp
->hdcDst
, pimldp
->x
, pimldp
->y
, cx
, cy
, hMaskListDC
, pt
.x
, pt
.y
, SRCAND
);
1624 SetBkColor(pimldp
->hdcDst
, oldDstBk
);
1625 SetTextColor(pimldp
->hdcDst
, oldDstFg
);
1628 if (fStyle
& ILD_ROP
) dwRop
= pimldp
->dwRop
;
1629 BitBlt (pimldp
->hdcDst
, pimldp
->x
, pimldp
->y
, cx
, cy
, hImageDC
, 0, 0, dwRop
);
1633 /* cleanup the mess */
1634 SetBkColor(hImageDC
, oldImageBk
);
1635 SetTextColor(hImageDC
, oldImageFg
);
1636 SelectObject(hImageDC
, hOldImageBmp
);
1638 DeleteObject(hBlendMaskBmp
);
1639 DeleteObject(hImageBmp
);
1646 /*************************************************************************
1647 * ImageList_Duplicate [COMCTL32.@]
1649 * Duplicates an image list.
1652 * himlSrc [I] source image list handle
1655 * Success: Handle of duplicated image list.
1660 ImageList_Duplicate (HIMAGELIST himlSrc
)
1664 if (!is_valid(himlSrc
)) {
1665 ERR("Invalid image list handle!\n");
1669 himlDst
= ImageList_Create (himlSrc
->cx
, himlSrc
->cy
, himlSrc
->flags
,
1670 himlSrc
->cCurImage
, himlSrc
->cGrow
);
1676 imagelist_get_bitmap_size(himlSrc
, himlSrc
->cCurImage
, &sz
);
1677 BitBlt (himlDst
->hdcImage
, 0, 0, sz
.cx
, sz
.cy
,
1678 himlSrc
->hdcImage
, 0, 0, SRCCOPY
);
1680 if (himlDst
->hbmMask
)
1681 BitBlt (himlDst
->hdcMask
, 0, 0, sz
.cx
, sz
.cy
,
1682 himlSrc
->hdcMask
, 0, 0, SRCCOPY
);
1684 himlDst
->cCurImage
= himlSrc
->cCurImage
;
1685 if (himlSrc
->has_alpha
&& himlDst
->has_alpha
)
1686 memcpy( himlDst
->has_alpha
, himlSrc
->has_alpha
, himlDst
->cCurImage
);
1692 /*************************************************************************
1693 * ImageList_EndDrag [COMCTL32.@]
1695 * Finishes a drag operation.
1706 ImageList_EndDrag (void)
1708 /* cleanup the InternalDrag struct */
1709 InternalDrag
.hwnd
= 0;
1710 if (InternalDrag
.himl
!= InternalDrag
.himlNoCursor
)
1711 ImageList_Destroy (InternalDrag
.himlNoCursor
);
1712 ImageList_Destroy (InternalDrag
.himl
);
1713 InternalDrag
.himlNoCursor
= InternalDrag
.himl
= 0;
1716 InternalDrag
.dxHotspot
= 0;
1717 InternalDrag
.dyHotspot
= 0;
1718 InternalDrag
.bShow
= FALSE
;
1719 DeleteObject(InternalDrag
.hbmBg
);
1720 InternalDrag
.hbmBg
= 0;
1724 /*************************************************************************
1725 * ImageList_GetBkColor [COMCTL32.@]
1727 * Returns the background color of an image list.
1730 * himl [I] Image list handle.
1733 * Success: background color
1738 ImageList_GetBkColor (HIMAGELIST himl
)
1740 return himl
? himl
->clrBk
: CLR_NONE
;
1744 /*************************************************************************
1745 * ImageList_GetDragImage [COMCTL32.@]
1747 * Returns the handle to the internal drag image list.
1750 * ppt [O] Pointer to the drag position. Can be NULL.
1751 * pptHotspot [O] Pointer to the position of the hot spot. Can be NULL.
1754 * Success: Handle of the drag image list.
1759 ImageList_GetDragImage (POINT
*ppt
, POINT
*pptHotspot
)
1761 if (is_valid(InternalDrag
.himl
)) {
1763 ppt
->x
= InternalDrag
.x
;
1764 ppt
->y
= InternalDrag
.y
;
1767 pptHotspot
->x
= InternalDrag
.dxHotspot
;
1768 pptHotspot
->y
= InternalDrag
.dyHotspot
;
1770 return (InternalDrag
.himl
);
1777 /*************************************************************************
1778 * ImageList_GetFlags [COMCTL32.@]
1780 * Gets the flags of the specified image list.
1783 * himl [I] Handle to image list
1793 ImageList_GetFlags(HIMAGELIST himl
)
1795 TRACE("%p\n", himl
);
1797 return is_valid(himl
) ? himl
->flags
: 0;
1801 /*************************************************************************
1802 * ImageList_GetIcon [COMCTL32.@]
1804 * Creates an icon from a masked image of an image list.
1807 * himl [I] handle to image list
1809 * flags [I] drawing style flags
1812 * Success: icon handle
1817 ImageList_GetIcon (HIMAGELIST himl
, INT i
, UINT fStyle
)
1821 HBITMAP hOldDstBitmap
;
1825 TRACE("%p %d %d\n", himl
, i
, fStyle
);
1826 if (!is_valid(himl
) || (i
< 0) || (i
>= himl
->cCurImage
)) return NULL
;
1832 /* create colour bitmap */
1834 ii
.hbmColor
= CreateCompatibleBitmap(hdcDst
, himl
->cx
, himl
->cy
);
1835 ReleaseDC(0, hdcDst
);
1837 hdcDst
= CreateCompatibleDC(0);
1839 imagelist_point_from_index( himl
, i
, &pt
);
1842 ii
.hbmMask
= CreateBitmap (himl
->cx
, himl
->cy
, 1, 1, NULL
);
1843 hOldDstBitmap
= SelectObject (hdcDst
, ii
.hbmMask
);
1844 if (himl
->hbmMask
) {
1845 BitBlt (hdcDst
, 0, 0, himl
->cx
, himl
->cy
,
1846 himl
->hdcMask
, pt
.x
, pt
.y
, SRCCOPY
);
1849 PatBlt (hdcDst
, 0, 0, himl
->cx
, himl
->cy
, BLACKNESS
);
1852 SelectObject (hdcDst
, ii
.hbmColor
);
1853 BitBlt (hdcDst
, 0, 0, himl
->cx
, himl
->cy
,
1854 himl
->hdcImage
, pt
.x
, pt
.y
, SRCCOPY
);
1857 * CreateIconIndirect requires us to deselect the bitmaps from
1858 * the DCs before calling
1860 SelectObject(hdcDst
, hOldDstBitmap
);
1862 hIcon
= CreateIconIndirect (&ii
);
1864 DeleteObject (ii
.hbmMask
);
1865 DeleteObject (ii
.hbmColor
);
1872 /*************************************************************************
1873 * ImageList_GetIconSize [COMCTL32.@]
1875 * Retrieves the size of an image in an image list.
1878 * himl [I] handle to image list
1879 * cx [O] pointer to the image width.
1880 * cy [O] pointer to the image height.
1887 * All images in an image list have the same size.
1891 ImageList_GetIconSize (HIMAGELIST himl
, INT
*cx
, INT
*cy
)
1893 if (!is_valid(himl
) || !cx
|| !cy
)
1895 if ((himl
->cx
<= 0) || (himl
->cy
<= 0))
1905 /*************************************************************************
1906 * ImageList_GetImageCount [COMCTL32.@]
1908 * Returns the number of images in an image list.
1911 * himl [I] handle to image list
1914 * Success: Number of images.
1919 ImageList_GetImageCount (HIMAGELIST himl
)
1921 if (!is_valid(himl
))
1924 return himl
->cCurImage
;
1928 /*************************************************************************
1929 * ImageList_GetImageInfo [COMCTL32.@]
1931 * Returns information about an image in an image list.
1934 * himl [I] handle to image list
1936 * pImageInfo [O] pointer to the image information
1944 ImageList_GetImageInfo (HIMAGELIST himl
, INT i
, IMAGEINFO
*pImageInfo
)
1948 if (!is_valid(himl
) || (pImageInfo
== NULL
))
1950 if ((i
< 0) || (i
>= himl
->cCurImage
))
1953 pImageInfo
->hbmImage
= himl
->hbmImage
;
1954 pImageInfo
->hbmMask
= himl
->hbmMask
;
1956 imagelist_point_from_index( himl
, i
, &pt
);
1957 pImageInfo
->rcImage
.top
= pt
.y
;
1958 pImageInfo
->rcImage
.bottom
= pt
.y
+ himl
->cy
;
1959 pImageInfo
->rcImage
.left
= pt
.x
;
1960 pImageInfo
->rcImage
.right
= pt
.x
+ himl
->cx
;
1966 /*************************************************************************
1967 * ImageList_GetImageRect [COMCTL32.@]
1969 * Retrieves the rectangle of the specified image in an image list.
1972 * himl [I] handle to image list
1974 * lpRect [O] pointer to the image rectangle
1981 * This is an UNDOCUMENTED function!!!
1985 ImageList_GetImageRect (HIMAGELIST himl
, INT i
, LPRECT lpRect
)
1989 if (!is_valid(himl
) || (lpRect
== NULL
))
1991 if ((i
< 0) || (i
>= himl
->cCurImage
))
1994 imagelist_point_from_index( himl
, i
, &pt
);
1995 lpRect
->left
= pt
.x
;
1997 lpRect
->right
= pt
.x
+ himl
->cx
;
1998 lpRect
->bottom
= pt
.y
+ himl
->cy
;
2004 /*************************************************************************
2005 * ImageList_LoadImage [COMCTL32.@]
2006 * ImageList_LoadImageA [COMCTL32.@]
2008 * Creates an image list from a bitmap, icon or cursor.
2010 * See ImageList_LoadImageW.
2014 ImageList_LoadImageA (HINSTANCE hi
, LPCSTR lpbmp
, INT cx
, INT cGrow
,
2015 COLORREF clrMask
, UINT uType
, UINT uFlags
)
2021 if (IS_INTRESOURCE(lpbmp
))
2022 return ImageList_LoadImageW(hi
, (LPCWSTR
)lpbmp
, cx
, cGrow
, clrMask
,
2025 len
= MultiByteToWideChar(CP_ACP
, 0, lpbmp
, -1, NULL
, 0);
2026 lpbmpW
= Alloc(len
* sizeof(WCHAR
));
2027 MultiByteToWideChar(CP_ACP
, 0, lpbmp
, -1, lpbmpW
, len
);
2029 himl
= ImageList_LoadImageW(hi
, lpbmpW
, cx
, cGrow
, clrMask
, uType
, uFlags
);
2035 /*************************************************************************
2036 * ImageList_LoadImageW [COMCTL32.@]
2038 * Creates an image list from a bitmap, icon or cursor.
2041 * hi [I] instance handle
2042 * lpbmp [I] name or id of the image
2043 * cx [I] width of each image
2044 * cGrow [I] number of images to expand
2045 * clrMask [I] mask color
2046 * uType [I] type of image to load
2047 * uFlags [I] loading flags
2050 * Success: handle to the loaded image list
2058 ImageList_LoadImageW (HINSTANCE hi
, LPCWSTR lpbmp
, INT cx
, INT cGrow
,
2059 COLORREF clrMask
, UINT uType
, UINT uFlags
)
2061 HIMAGELIST himl
= NULL
;
2065 handle
= LoadImageW (hi
, lpbmp
, uType
, 0, 0, uFlags
);
2067 WARN("Couldn't load image\n");
2071 if (uType
== IMAGE_BITMAP
) {
2075 if (GetObjectW (handle
, sizeof(dib
), &dib
) == sizeof(BITMAP
)) color
= ILC_COLOR
;
2076 else color
= dib
.dsBm
.bmBitsPixel
;
2078 /* To match windows behavior, if cx is set to zero and
2079 the flag DI_DEFAULTSIZE is specified, cx becomes the
2080 system metric value for icons. If the flag is not specified
2081 the function sets the size to the height of the bitmap */
2084 if (uFlags
& DI_DEFAULTSIZE
)
2085 cx
= GetSystemMetrics (SM_CXICON
);
2087 cx
= dib
.dsBm
.bmHeight
;
2090 nImageCount
= dib
.dsBm
.bmWidth
/ cx
;
2092 himl
= ImageList_Create (cx
, dib
.dsBm
.bmHeight
, ILC_MASK
| color
, nImageCount
, cGrow
);
2094 DeleteObject (handle
);
2097 ImageList_AddMasked (himl
, handle
, clrMask
);
2099 else if ((uType
== IMAGE_ICON
) || (uType
== IMAGE_CURSOR
)) {
2103 GetIconInfo (handle
, &ii
);
2104 GetObjectW (ii
.hbmColor
, sizeof(BITMAP
), &bmp
);
2105 himl
= ImageList_Create (bmp
.bmWidth
, bmp
.bmHeight
,
2106 ILC_MASK
| ILC_COLOR
, 1, cGrow
);
2108 DeleteObject (ii
.hbmColor
);
2109 DeleteObject (ii
.hbmMask
);
2110 DeleteObject (handle
);
2113 ImageList_Add (himl
, ii
.hbmColor
, ii
.hbmMask
);
2114 DeleteObject (ii
.hbmColor
);
2115 DeleteObject (ii
.hbmMask
);
2118 DeleteObject (handle
);
2124 /*************************************************************************
2125 * ImageList_Merge [COMCTL32.@]
2127 * Create an image list containing a merged image from two image lists.
2130 * himl1 [I] handle to first image list
2131 * i1 [I] first image index
2132 * himl2 [I] handle to second image list
2133 * i2 [I] second image index
2134 * dx [I] X offset of the second image relative to the first.
2135 * dy [I] Y offset of the second image relative to the first.
2138 * Success: The newly created image list. It contains a single image
2139 * consisting of the second image merged with the first.
2140 * Failure: NULL, if either himl1 or himl2 is invalid.
2143 * - The returned image list should be deleted by the caller using
2144 * ImageList_Destroy() when it is no longer required.
2145 * - If either i1 or i2 is not a valid image index, they will be treated
2149 ImageList_Merge (HIMAGELIST himl1
, INT i1
, HIMAGELIST himl2
, INT i2
,
2152 HIMAGELIST himlDst
= NULL
;
2154 INT xOff1
, yOff1
, xOff2
, yOff2
;
2158 TRACE("(himl1=%p i1=%d himl2=%p i2=%d dx=%d dy=%d)\n", himl1
, i1
, himl2
,
2161 if (!is_valid(himl1
) || !is_valid(himl2
))
2165 cxDst
= max (himl1
->cx
, dx
+ himl2
->cx
);
2170 cxDst
= max (himl2
->cx
, himl1
->cx
- dx
);
2175 cxDst
= max (himl1
->cx
, himl2
->cx
);
2181 cyDst
= max (himl1
->cy
, dy
+ himl2
->cy
);
2186 cyDst
= max (himl2
->cy
, himl1
->cy
- dy
);
2191 cyDst
= max (himl1
->cy
, himl2
->cy
);
2196 newFlags
= (himl1
->flags
> himl2
->flags
? himl1
->flags
: himl2
->flags
) & ILC_COLORDDB
;
2197 if (newFlags
== ILC_COLORDDB
&& (himl1
->flags
& ILC_COLORDDB
) == ILC_COLOR16
)
2198 newFlags
= ILC_COLOR16
; /* this is what native (at least v5) does, don't know why */
2199 himlDst
= ImageList_Create (cxDst
, cyDst
, ILC_MASK
| newFlags
, 1, 1);
2203 imagelist_point_from_index( himl1
, i1
, &pt1
);
2204 imagelist_point_from_index( himl2
, i2
, &pt2
);
2207 BitBlt (himlDst
->hdcImage
, 0, 0, cxDst
, cyDst
, himl1
->hdcImage
, 0, 0, BLACKNESS
);
2208 if (i1
>= 0 && i1
< himl1
->cCurImage
)
2209 BitBlt (himlDst
->hdcImage
, xOff1
, yOff1
, himl1
->cx
, himl1
->cy
, himl1
->hdcImage
, pt1
.x
, pt1
.y
, SRCCOPY
);
2210 if (i2
>= 0 && i2
< himl2
->cCurImage
)
2212 if (himl2
->flags
& ILC_MASK
)
2214 BitBlt (himlDst
->hdcImage
, xOff2
, yOff2
, himl2
->cx
, himl2
->cy
, himl2
->hdcMask
, pt2
.x
, pt2
.y
, SRCAND
);
2215 BitBlt (himlDst
->hdcImage
, xOff2
, yOff2
, himl2
->cx
, himl2
->cy
, himl2
->hdcImage
, pt2
.x
, pt2
.y
, SRCPAINT
);
2218 BitBlt (himlDst
->hdcImage
, xOff2
, yOff2
, himl2
->cx
, himl2
->cy
, himl2
->hdcImage
, pt2
.x
, pt2
.y
, SRCCOPY
);
2222 BitBlt (himlDst
->hdcMask
, 0, 0, cxDst
, cyDst
, himl1
->hdcMask
, 0, 0, WHITENESS
);
2223 if (i1
>= 0 && i1
< himl1
->cCurImage
)
2224 BitBlt (himlDst
->hdcMask
, xOff1
, yOff1
, himl1
->cx
, himl1
->cy
, himl1
->hdcMask
, pt1
.x
, pt1
.y
, SRCCOPY
);
2225 if (i2
>= 0 && i2
< himl2
->cCurImage
)
2226 BitBlt (himlDst
->hdcMask
, xOff2
, yOff2
, himl2
->cx
, himl2
->cy
, himl2
->hdcMask
, pt2
.x
, pt2
.y
, SRCAND
);
2228 himlDst
->cCurImage
= 1;
2235 /* helper for ImageList_Read, see comments below */
2236 static void *read_bitmap(LPSTREAM pstm
, BITMAPINFO
*bmi
)
2238 BITMAPFILEHEADER bmfh
;
2239 int bitsperpixel
, palspace
;
2242 if (FAILED(IStream_Read ( pstm
, &bmfh
, sizeof(bmfh
), NULL
)))
2245 if (bmfh
.bfType
!= (('M'<<8)|'B'))
2248 if (FAILED(IStream_Read ( pstm
, &bmi
->bmiHeader
, sizeof(bmi
->bmiHeader
), NULL
)))
2251 if ((bmi
->bmiHeader
.biSize
!= sizeof(bmi
->bmiHeader
)))
2254 TRACE("width %u, height %u, planes %u, bpp %u\n",
2255 bmi
->bmiHeader
.biWidth
, bmi
->bmiHeader
.biHeight
,
2256 bmi
->bmiHeader
.biPlanes
, bmi
->bmiHeader
.biBitCount
);
2258 bitsperpixel
= bmi
->bmiHeader
.biPlanes
* bmi
->bmiHeader
.biBitCount
;
2259 if (bitsperpixel
<=8)
2260 palspace
= (1<<bitsperpixel
)*sizeof(RGBQUAD
);
2264 bmi
->bmiHeader
.biSizeImage
= get_dib_image_size( bmi
);
2266 /* read the palette right after the end of the bitmapinfoheader */
2267 if (palspace
&& FAILED(IStream_Read(pstm
, bmi
->bmiColors
, palspace
, NULL
)))
2270 bits
= Alloc(bmi
->bmiHeader
.biSizeImage
);
2271 if (!bits
) return NULL
;
2273 if (FAILED(IStream_Read(pstm
, bits
, bmi
->bmiHeader
.biSizeImage
, NULL
)))
2281 /*************************************************************************
2282 * ImageList_Read [COMCTL32.@]
2284 * Reads an image list from a stream.
2287 * pstm [I] pointer to a stream
2290 * Success: handle to image list
2293 * The format is like this:
2294 * ILHEAD ilheadstruct;
2296 * for the color image part:
2297 * BITMAPFILEHEADER bmfh;
2298 * BITMAPINFOHEADER bmih;
2299 * only if it has a palette:
2300 * RGBQUAD rgbs[nr_of_paletted_colors];
2302 * BYTE colorbits[imagesize];
2304 * the following only if the ILC_MASK bit is set in ILHEAD.ilFlags:
2305 * BITMAPFILEHEADER bmfh_mask;
2306 * BITMAPINFOHEADER bmih_mask;
2307 * only if it has a palette (it usually does not):
2308 * RGBQUAD rgbs[nr_of_paletted_colors];
2310 * BYTE maskbits[imagesize];
2312 HIMAGELIST WINAPI
ImageList_Read (LPSTREAM pstm
)
2314 char image_buf
[sizeof(BITMAPINFOHEADER
) + sizeof(RGBQUAD
) * 256];
2315 char mask_buf
[sizeof(BITMAPINFOHEADER
) + sizeof(RGBQUAD
) * 256];
2316 BITMAPINFO
*image_info
= (BITMAPINFO
*)image_buf
;
2317 BITMAPINFO
*mask_info
= (BITMAPINFO
*)mask_buf
;
2318 void *image_bits
, *mask_bits
= NULL
;
2323 TRACE("%p\n", pstm
);
2325 if (FAILED(IStream_Read (pstm
, &ilHead
, sizeof(ILHEAD
), NULL
)))
2327 if (ilHead
.usMagic
!= (('L' << 8) | 'I'))
2329 if (ilHead
.usVersion
!= 0x101) /* probably version? */
2332 TRACE("cx %u, cy %u, flags 0x%04x, cCurImage %u, cMaxImage %u\n",
2333 ilHead
.cx
, ilHead
.cy
, ilHead
.flags
, ilHead
.cCurImage
, ilHead
.cMaxImage
);
2335 himl
= ImageList_Create(ilHead
.cx
, ilHead
.cy
, ilHead
.flags
, ilHead
.cCurImage
, ilHead
.cMaxImage
);
2339 if (!(image_bits
= read_bitmap(pstm
, image_info
)))
2341 WARN("failed to read bitmap from stream\n");
2344 if (ilHead
.flags
& ILC_MASK
)
2346 if (!(mask_bits
= read_bitmap(pstm
, mask_info
)))
2348 WARN("failed to read mask bitmap from stream\n");
2352 else mask_info
= NULL
;
2354 if (himl
->has_alpha
&& image_info
->bmiHeader
.biBitCount
== 32)
2356 DWORD
*ptr
= image_bits
;
2357 BYTE
*mask_ptr
= mask_bits
;
2358 int stride
= himl
->cy
* image_info
->bmiHeader
.biWidth
;
2360 if (image_info
->bmiHeader
.biHeight
> 0) /* bottom-up */
2362 ptr
+= image_info
->bmiHeader
.biHeight
* image_info
->bmiHeader
.biWidth
- stride
;
2363 mask_ptr
+= (image_info
->bmiHeader
.biHeight
* image_info
->bmiHeader
.biWidth
- stride
) / 8;
2365 image_info
->bmiHeader
.biHeight
= himl
->cy
;
2367 else image_info
->bmiHeader
.biHeight
= -himl
->cy
;
2369 for (i
= 0; i
< ilHead
.cCurImage
; i
+= TILE_COUNT
)
2371 add_dib_bits( himl
, i
, min( ilHead
.cCurImage
- i
, TILE_COUNT
),
2372 himl
->cx
, himl
->cy
, image_info
, mask_info
, ptr
, mask_ptr
);
2374 mask_ptr
+= stride
/ 8;
2379 StretchDIBits( himl
->hdcImage
, 0, 0, image_info
->bmiHeader
.biWidth
, image_info
->bmiHeader
.biHeight
,
2380 0, 0, image_info
->bmiHeader
.biWidth
, image_info
->bmiHeader
.biHeight
,
2381 image_bits
, image_info
, DIB_RGB_COLORS
, SRCCOPY
);
2383 StretchDIBits( himl
->hdcMask
, 0, 0, mask_info
->bmiHeader
.biWidth
, mask_info
->bmiHeader
.biHeight
,
2384 0, 0, mask_info
->bmiHeader
.biWidth
, mask_info
->bmiHeader
.biHeight
,
2385 mask_bits
, mask_info
, DIB_RGB_COLORS
, SRCCOPY
);
2390 himl
->cCurImage
= ilHead
.cCurImage
;
2391 himl
->cMaxImage
= ilHead
.cMaxImage
;
2393 ImageList_SetBkColor(himl
,ilHead
.bkcolor
);
2395 ImageList_SetOverlayImage(himl
,ilHead
.ovls
[i
],i
+1);
2400 /*************************************************************************
2401 * ImageList_Remove [COMCTL32.@]
2403 * Removes an image from an image list
2406 * himl [I] image list handle
2413 * FIXME: as the image list storage test shows, native comctl32 simply shifts
2414 * images without creating a new bitmap.
2417 ImageList_Remove (HIMAGELIST himl
, INT i
)
2419 HBITMAP hbmNewImage
, hbmNewMask
;
2423 TRACE("(himl=%p i=%d)\n", himl
, i
);
2425 if (!is_valid(himl
)) {
2426 ERR("Invalid image list handle!\n");
2430 if ((i
< -1) || (i
>= himl
->cCurImage
)) {
2431 TRACE("index out of range! %d\n", i
);
2439 if (himl
->cCurImage
== 0) {
2440 /* remove all on empty ImageList is allowed */
2441 TRACE("remove all on empty ImageList!\n");
2445 himl
->cMaxImage
= himl
->cGrow
;
2446 himl
->cCurImage
= 0;
2447 for (nCount
= 0; nCount
< MAX_OVERLAYIMAGE
; nCount
++)
2448 himl
->nOvlIdx
[nCount
] = -1;
2450 if (himl
->has_alpha
)
2452 HeapFree( GetProcessHeap(), 0, himl
->has_alpha
);
2453 himl
->has_alpha
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, himl
->cMaxImage
);
2456 hbmNewImage
= ImageList_CreateImage(himl
->hdcImage
, himl
, himl
->cMaxImage
);
2457 SelectObject (himl
->hdcImage
, hbmNewImage
);
2458 DeleteObject (himl
->hbmImage
);
2459 himl
->hbmImage
= hbmNewImage
;
2461 if (himl
->hbmMask
) {
2463 imagelist_get_bitmap_size(himl
, himl
->cMaxImage
, &sz
);
2464 hbmNewMask
= CreateBitmap (sz
.cx
, sz
.cy
, 1, 1, NULL
);
2465 SelectObject (himl
->hdcMask
, hbmNewMask
);
2466 DeleteObject (himl
->hbmMask
);
2467 himl
->hbmMask
= hbmNewMask
;
2471 /* delete one image */
2472 TRACE("Remove single image! %d\n", i
);
2474 /* create new bitmap(s) */
2475 TRACE(" - Number of images: %d / %d (Old/New)\n",
2476 himl
->cCurImage
, himl
->cCurImage
- 1);
2478 hbmNewImage
= ImageList_CreateImage(himl
->hdcImage
, himl
, himl
->cMaxImage
);
2480 imagelist_get_bitmap_size(himl
, himl
->cMaxImage
, &sz
);
2482 hbmNewMask
= CreateBitmap (sz
.cx
, sz
.cy
, 1, 1, NULL
);
2484 hbmNewMask
= 0; /* Just to keep compiler happy! */
2486 hdcBmp
= CreateCompatibleDC (0);
2488 /* copy all images and masks prior to the "removed" image */
2490 TRACE("Pre image copy: Copy %d images\n", i
);
2492 SelectObject (hdcBmp
, hbmNewImage
);
2493 imagelist_copy_images( himl
, himl
->hdcImage
, hdcBmp
, 0, i
, 0 );
2495 if (himl
->hbmMask
) {
2496 SelectObject (hdcBmp
, hbmNewMask
);
2497 imagelist_copy_images( himl
, himl
->hdcMask
, hdcBmp
, 0, i
, 0 );
2501 /* copy all images and masks behind the removed image */
2502 if (i
< himl
->cCurImage
- 1) {
2503 TRACE("Post image copy!\n");
2505 SelectObject (hdcBmp
, hbmNewImage
);
2506 imagelist_copy_images( himl
, himl
->hdcImage
, hdcBmp
, i
+ 1,
2507 (himl
->cCurImage
- i
), i
);
2509 if (himl
->hbmMask
) {
2510 SelectObject (hdcBmp
, hbmNewMask
);
2511 imagelist_copy_images( himl
, himl
->hdcMask
, hdcBmp
, i
+ 1,
2512 (himl
->cCurImage
- i
), i
);
2518 /* delete old images and insert new ones */
2519 SelectObject (himl
->hdcImage
, hbmNewImage
);
2520 DeleteObject (himl
->hbmImage
);
2521 himl
->hbmImage
= hbmNewImage
;
2522 if (himl
->hbmMask
) {
2523 SelectObject (himl
->hdcMask
, hbmNewMask
);
2524 DeleteObject (himl
->hbmMask
);
2525 himl
->hbmMask
= hbmNewMask
;
2535 /*************************************************************************
2536 * ImageList_Replace [COMCTL32.@]
2538 * Replaces an image in an image list with a new image.
2541 * himl [I] handle to image list
2543 * hbmImage [I] handle to image bitmap
2544 * hbmMask [I] handle to mask bitmap. Can be NULL.
2552 ImageList_Replace (HIMAGELIST himl
, INT i
, HBITMAP hbmImage
,
2559 TRACE("%p %d %p %p\n", himl
, i
, hbmImage
, hbmMask
);
2561 if (!is_valid(himl
)) {
2562 ERR("Invalid image list handle!\n");
2566 if ((i
>= himl
->cMaxImage
) || (i
< 0)) {
2567 ERR("Invalid image index!\n");
2571 if (!GetObjectW(hbmImage
, sizeof(BITMAP
), &bmp
))
2574 hdcImage
= CreateCompatibleDC (0);
2577 SelectObject (hdcImage
, hbmImage
);
2579 if (add_with_alpha( himl
, hdcImage
, i
, 1, bmp
.bmWidth
, bmp
.bmHeight
, hbmImage
, hbmMask
))
2582 imagelist_point_from_index(himl
, i
, &pt
);
2583 StretchBlt (himl
->hdcImage
, pt
.x
, pt
.y
, himl
->cx
, himl
->cy
,
2584 hdcImage
, 0, 0, bmp
.bmWidth
, bmp
.bmHeight
, SRCCOPY
);
2589 HBITMAP hOldBitmapTemp
;
2591 hdcTemp
= CreateCompatibleDC(0);
2592 hOldBitmapTemp
= SelectObject(hdcTemp
, hbmMask
);
2594 StretchBlt (himl
->hdcMask
, pt
.x
, pt
.y
, himl
->cx
, himl
->cy
,
2595 hdcTemp
, 0, 0, bmp
.bmWidth
, bmp
.bmHeight
, SRCCOPY
);
2596 SelectObject(hdcTemp
, hOldBitmapTemp
);
2599 /* Remove the background from the image
2601 BitBlt (himl
->hdcImage
, pt
.x
, pt
.y
, bmp
.bmWidth
, bmp
.bmHeight
,
2602 himl
->hdcMask
, pt
.x
, pt
.y
, 0x220326); /* NOTSRCAND */
2606 DeleteDC (hdcImage
);
2612 /*************************************************************************
2613 * ImageList_ReplaceIcon [COMCTL32.@]
2615 * Replaces an image in an image list using an icon.
2618 * himl [I] handle to image list
2620 * hIcon [I] handle to icon
2623 * Success: index of the replaced image
2628 ImageList_ReplaceIcon (HIMAGELIST himl
, INT nIndex
, HICON hIcon
)
2636 TRACE("(%p %d %p)\n", himl
, nIndex
, hIcon
);
2638 if (!is_valid(himl
)) {
2639 ERR("invalid image list\n");
2642 if ((nIndex
>= himl
->cMaxImage
) || (nIndex
< -1)) {
2643 ERR("invalid image index %d / %d\n", nIndex
, himl
->cMaxImage
);
2647 hBestFitIcon
= CopyImage(
2650 LR_COPYFROMRESOURCE
);
2651 /* the above will fail if the icon wasn't loaded from a resource, so try
2652 * again without LR_COPYFROMRESOURCE flag */
2654 hBestFitIcon
= CopyImage(
2662 if (himl
->cCurImage
+ 1 >= himl
->cMaxImage
)
2663 IMAGELIST_InternalExpandBitmaps(himl
, 1);
2665 nIndex
= himl
->cCurImage
;
2669 if (himl
->has_alpha
&& GetIconInfo (hBestFitIcon
, &ii
))
2671 HDC hdcImage
= CreateCompatibleDC( 0 );
2672 GetObjectW (ii
.hbmMask
, sizeof(BITMAP
), &bmp
);
2676 UINT height
= bmp
.bmHeight
/ 2;
2677 HDC hdcMask
= CreateCompatibleDC( 0 );
2678 HBITMAP color
= CreateBitmap( bmp
.bmWidth
, height
, 1, 1, NULL
);
2679 SelectObject( hdcImage
, color
);
2680 SelectObject( hdcMask
, ii
.hbmMask
);
2681 BitBlt( hdcImage
, 0, 0, bmp
.bmWidth
, height
, hdcMask
, 0, height
, SRCCOPY
);
2682 ret
= add_with_alpha( himl
, hdcImage
, nIndex
, 1, bmp
.bmWidth
, height
, color
, ii
.hbmMask
);
2683 DeleteDC( hdcMask
);
2684 DeleteObject( color
);
2686 else ret
= add_with_alpha( himl
, hdcImage
, nIndex
, 1, bmp
.bmWidth
, bmp
.bmHeight
,
2687 ii
.hbmColor
, ii
.hbmMask
);
2689 DeleteDC( hdcImage
);
2690 DeleteObject (ii
.hbmMask
);
2691 if (ii
.hbmColor
) DeleteObject (ii
.hbmColor
);
2695 imagelist_point_from_index(himl
, nIndex
, &pt
);
2699 DrawIconEx( himl
->hdcImage
, pt
.x
, pt
.y
, hBestFitIcon
, himl
->cx
, himl
->cy
, 0, 0, DI_IMAGE
);
2700 PatBlt( himl
->hdcMask
, pt
.x
, pt
.y
, himl
->cx
, himl
->cy
, WHITENESS
);
2701 DrawIconEx( himl
->hdcMask
, pt
.x
, pt
.y
, hBestFitIcon
, himl
->cx
, himl
->cy
, 0, 0, DI_MASK
);
2705 COLORREF color
= himl
->clrBk
!= CLR_NONE
? himl
->clrBk
: comctl32_color
.clrWindow
;
2706 HBRUSH brush
= CreateSolidBrush( GetNearestColor( himl
->hdcImage
, color
));
2708 SelectObject( himl
->hdcImage
, brush
);
2709 PatBlt( himl
->hdcImage
, pt
.x
, pt
.y
, himl
->cx
, himl
->cy
, PATCOPY
);
2710 SelectObject( himl
->hdcImage
, GetStockObject(BLACK_BRUSH
) );
2711 DeleteObject( brush
);
2712 DrawIconEx( himl
->hdcImage
, pt
.x
, pt
.y
, hBestFitIcon
, himl
->cx
, himl
->cy
, 0, 0, DI_NORMAL
);
2716 DestroyIcon(hBestFitIcon
);
2718 TRACE("Insert index = %d, himl->cCurImage = %d\n", nIndex
, himl
->cCurImage
);
2723 /*************************************************************************
2724 * ImageList_SetBkColor [COMCTL32.@]
2726 * Sets the background color of an image list.
2729 * himl [I] handle to image list
2730 * clrBk [I] background color
2733 * Success: previous background color
2738 ImageList_SetBkColor (HIMAGELIST himl
, COLORREF clrBk
)
2742 if (!is_valid(himl
))
2745 clrOldBk
= himl
->clrBk
;
2746 himl
->clrBk
= clrBk
;
2751 /*************************************************************************
2752 * ImageList_SetDragCursorImage [COMCTL32.@]
2754 * Combines the specified image with the current drag image
2757 * himlDrag [I] handle to drag image list
2758 * iDrag [I] drag image index
2759 * dxHotspot [I] X position of the hot spot
2760 * dyHotspot [I] Y position of the hot spot
2767 * - The names dxHotspot, dyHotspot are misleading because they have nothing
2768 * to do with a hotspot but are only the offset of the origin of the new
2769 * image relative to the origin of the old image.
2771 * - When this function is called and the drag image is visible, a
2772 * short flickering occurs but this matches the Win9x behavior. It is
2773 * possible to fix the flickering using code like in ImageList_DragMove.
2777 ImageList_SetDragCursorImage (HIMAGELIST himlDrag
, INT iDrag
,
2778 INT dxHotspot
, INT dyHotspot
)
2780 HIMAGELIST himlTemp
;
2783 if (!is_valid(InternalDrag
.himl
) || !is_valid(himlDrag
))
2786 TRACE(" dxH=%d dyH=%d nX=%d nY=%d\n",
2787 dxHotspot
, dyHotspot
, InternalDrag
.dxHotspot
, InternalDrag
.dyHotspot
);
2789 visible
= InternalDrag
.bShow
;
2791 himlTemp
= ImageList_Merge (InternalDrag
.himlNoCursor
, 0, himlDrag
, iDrag
,
2792 dxHotspot
, dyHotspot
);
2795 /* hide the drag image */
2796 ImageList_DragShowNolock(FALSE
);
2798 if ((InternalDrag
.himl
->cx
!= himlTemp
->cx
) ||
2799 (InternalDrag
.himl
->cy
!= himlTemp
->cy
)) {
2800 /* the size of the drag image changed, invalidate the buffer */
2801 DeleteObject(InternalDrag
.hbmBg
);
2802 InternalDrag
.hbmBg
= 0;
2805 if (InternalDrag
.himl
!= InternalDrag
.himlNoCursor
)
2806 ImageList_Destroy (InternalDrag
.himl
);
2807 InternalDrag
.himl
= himlTemp
;
2810 /* show the drag image */
2811 ImageList_DragShowNolock(TRUE
);
2818 /*************************************************************************
2819 * ImageList_SetFilter [COMCTL32.@]
2821 * Sets a filter (or does something completely different)!!???
2822 * It removes 12 Bytes from the stack (3 Parameters).
2825 * himl [I] SHOULD be a handle to image list
2826 * i [I] COULD be an index?
2831 * Failure: FALSE ???
2834 * This is an UNDOCUMENTED function!!!!
2839 ImageList_SetFilter (HIMAGELIST himl
, INT i
, DWORD dwFilter
)
2841 FIXME("(%p 0x%x 0x%x):empty stub!\n", himl
, i
, dwFilter
);
2847 /*************************************************************************
2848 * ImageList_SetFlags [COMCTL32.@]
2850 * Sets the image list flags.
2853 * himl [I] Handle to image list
2854 * flags [I] Flags to set
2864 ImageList_SetFlags(HIMAGELIST himl
, DWORD flags
)
2866 FIXME("(%p %08x):empty stub\n", himl
, flags
);
2871 /*************************************************************************
2872 * ImageList_SetIconSize [COMCTL32.@]
2874 * Sets the image size of the bitmap and deletes all images.
2877 * himl [I] handle to image list
2878 * cx [I] image width
2879 * cy [I] image height
2887 ImageList_SetIconSize (HIMAGELIST himl
, INT cx
, INT cy
)
2892 if (!is_valid(himl
))
2895 /* remove all images */
2896 himl
->cMaxImage
= himl
->cInitial
+ 1;
2897 himl
->cCurImage
= 0;
2901 /* initialize overlay mask indices */
2902 for (nCount
= 0; nCount
< MAX_OVERLAYIMAGE
; nCount
++)
2903 himl
->nOvlIdx
[nCount
] = -1;
2905 hbmNew
= ImageList_CreateImage(himl
->hdcImage
, himl
, himl
->cMaxImage
);
2906 SelectObject (himl
->hdcImage
, hbmNew
);
2907 DeleteObject (himl
->hbmImage
);
2908 himl
->hbmImage
= hbmNew
;
2910 if (himl
->hbmMask
) {
2912 imagelist_get_bitmap_size(himl
, himl
->cMaxImage
, &sz
);
2913 hbmNew
= CreateBitmap (sz
.cx
, sz
.cy
, 1, 1, NULL
);
2914 SelectObject (himl
->hdcMask
, hbmNew
);
2915 DeleteObject (himl
->hbmMask
);
2916 himl
->hbmMask
= hbmNew
;
2923 /*************************************************************************
2924 * ImageList_SetImageCount [COMCTL32.@]
2926 * Resizes an image list to the specified number of images.
2929 * himl [I] handle to image list
2930 * iImageCount [I] number of images in the image list
2938 ImageList_SetImageCount (HIMAGELIST himl
, UINT iImageCount
)
2941 HBITMAP hbmNewBitmap
, hbmOld
;
2942 INT nNewCount
, nCopyCount
;
2944 TRACE("%p %d\n",himl
,iImageCount
);
2946 if (!is_valid(himl
))
2949 nNewCount
= iImageCount
+ 1;
2950 nCopyCount
= min(himl
->cCurImage
, iImageCount
);
2952 hdcBitmap
= CreateCompatibleDC (0);
2954 hbmNewBitmap
= ImageList_CreateImage(hdcBitmap
, himl
, nNewCount
);
2956 if (hbmNewBitmap
!= 0)
2958 hbmOld
= SelectObject (hdcBitmap
, hbmNewBitmap
);
2959 imagelist_copy_images( himl
, himl
->hdcImage
, hdcBitmap
, 0, nCopyCount
, 0 );
2960 SelectObject (hdcBitmap
, hbmOld
);
2962 /* FIXME: delete 'empty' image space? */
2964 SelectObject (himl
->hdcImage
, hbmNewBitmap
);
2965 DeleteObject (himl
->hbmImage
);
2966 himl
->hbmImage
= hbmNewBitmap
;
2969 ERR("Could not create new image bitmap!\n");
2974 imagelist_get_bitmap_size( himl
, nNewCount
, &sz
);
2975 hbmNewBitmap
= CreateBitmap (sz
.cx
, sz
.cy
, 1, 1, NULL
);
2976 if (hbmNewBitmap
!= 0)
2978 hbmOld
= SelectObject (hdcBitmap
, hbmNewBitmap
);
2979 imagelist_copy_images( himl
, himl
->hdcMask
, hdcBitmap
, 0, nCopyCount
, 0 );
2980 SelectObject (hdcBitmap
, hbmOld
);
2982 /* FIXME: delete 'empty' image space? */
2984 SelectObject (himl
->hdcMask
, hbmNewBitmap
);
2985 DeleteObject (himl
->hbmMask
);
2986 himl
->hbmMask
= hbmNewBitmap
;
2989 ERR("Could not create new mask bitmap!\n");
2992 DeleteDC (hdcBitmap
);
2994 if (himl
->has_alpha
)
2996 char *new_alpha
= HeapReAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, himl
->has_alpha
, nNewCount
);
2997 if (new_alpha
) himl
->has_alpha
= new_alpha
;
3000 HeapFree( GetProcessHeap(), 0, himl
->has_alpha
);
3001 himl
->has_alpha
= NULL
;
3005 /* Update max image count and current image count */
3006 himl
->cMaxImage
= nNewCount
;
3007 himl
->cCurImage
= iImageCount
;
3013 /*************************************************************************
3014 * ImageList_SetOverlayImage [COMCTL32.@]
3016 * Assigns an overlay mask index to an existing image in an image list.
3019 * himl [I] handle to image list
3020 * iImage [I] image index
3021 * iOverlay [I] overlay mask index
3029 ImageList_SetOverlayImage (HIMAGELIST himl
, INT iImage
, INT iOverlay
)
3031 if (!is_valid(himl
))
3033 if ((iOverlay
< 1) || (iOverlay
> MAX_OVERLAYIMAGE
))
3035 if ((iImage
!=-1) && ((iImage
< 0) || (iImage
> himl
->cCurImage
)))
3037 himl
->nOvlIdx
[iOverlay
- 1] = iImage
;
3043 /* helper for ImageList_Write - write bitmap to pstm
3044 * currently everything is written as 24 bit RGB, except masks
3047 _write_bitmap(HBITMAP hBitmap
, LPSTREAM pstm
)
3049 LPBITMAPFILEHEADER bmfh
;
3050 LPBITMAPINFOHEADER bmih
;
3051 LPBYTE data
= NULL
, lpBits
;
3053 INT bitCount
, sizeImage
, offBits
, totalSize
;
3055 BOOL result
= FALSE
;
3057 if (!GetObjectW(hBitmap
, sizeof(BITMAP
), &bm
))
3060 bitCount
= bm
.bmBitsPixel
;
3061 sizeImage
= get_dib_stride(bm
.bmWidth
, bitCount
) * bm
.bmHeight
;
3063 totalSize
= sizeof(BITMAPFILEHEADER
) + sizeof(BITMAPINFOHEADER
);
3065 totalSize
+= (1 << bitCount
) * sizeof(RGBQUAD
);
3066 offBits
= totalSize
;
3067 totalSize
+= sizeImage
;
3069 data
= Alloc(totalSize
);
3070 bmfh
= (LPBITMAPFILEHEADER
)data
;
3071 bmih
= (LPBITMAPINFOHEADER
)(data
+ sizeof(BITMAPFILEHEADER
));
3072 lpBits
= data
+ offBits
;
3074 /* setup BITMAPFILEHEADER */
3075 bmfh
->bfType
= (('M' << 8) | 'B');
3076 bmfh
->bfSize
= offBits
;
3077 bmfh
->bfReserved1
= 0;
3078 bmfh
->bfReserved2
= 0;
3079 bmfh
->bfOffBits
= offBits
;
3081 /* setup BITMAPINFOHEADER */
3082 bmih
->biSize
= sizeof(BITMAPINFOHEADER
);
3083 bmih
->biWidth
= bm
.bmWidth
;
3084 bmih
->biHeight
= bm
.bmHeight
;
3086 bmih
->biBitCount
= bitCount
;
3087 bmih
->biCompression
= BI_RGB
;
3088 bmih
->biSizeImage
= sizeImage
;
3089 bmih
->biXPelsPerMeter
= 0;
3090 bmih
->biYPelsPerMeter
= 0;
3091 bmih
->biClrUsed
= 0;
3092 bmih
->biClrImportant
= 0;
3095 result
= GetDIBits(xdc
, hBitmap
, 0, bm
.bmHeight
, lpBits
, (BITMAPINFO
*)bmih
, DIB_RGB_COLORS
) == bm
.bmHeight
;
3100 TRACE("width %u, height %u, planes %u, bpp %u\n",
3101 bmih
->biWidth
, bmih
->biHeight
,
3102 bmih
->biPlanes
, bmih
->biBitCount
);
3104 if(FAILED(IStream_Write(pstm
, data
, totalSize
, NULL
)))
3116 /*************************************************************************
3117 * ImageList_Write [COMCTL32.@]
3119 * Writes an image list to a stream.
3122 * himl [I] handle to image list
3123 * pstm [O] Pointer to a stream.
3134 ImageList_Write (HIMAGELIST himl
, LPSTREAM pstm
)
3139 TRACE("%p %p\n", himl
, pstm
);
3141 if (!is_valid(himl
))
3144 ilHead
.usMagic
= (('L' << 8) | 'I');
3145 ilHead
.usVersion
= 0x101;
3146 ilHead
.cCurImage
= himl
->cCurImage
;
3147 ilHead
.cMaxImage
= himl
->cMaxImage
;
3148 ilHead
.cGrow
= himl
->cGrow
;
3149 ilHead
.cx
= himl
->cx
;
3150 ilHead
.cy
= himl
->cy
;
3151 ilHead
.bkcolor
= himl
->clrBk
;
3152 ilHead
.flags
= himl
->flags
;
3153 for(i
= 0; i
< 4; i
++) {
3154 ilHead
.ovls
[i
] = himl
->nOvlIdx
[i
];
3157 TRACE("cx %u, cy %u, flags 0x04%x, cCurImage %u, cMaxImage %u\n",
3158 ilHead
.cx
, ilHead
.cy
, ilHead
.flags
, ilHead
.cCurImage
, ilHead
.cMaxImage
);
3160 if(FAILED(IStream_Write(pstm
, &ilHead
, sizeof(ILHEAD
), NULL
)))
3163 /* write the bitmap */
3164 if(!_write_bitmap(himl
->hbmImage
, pstm
))
3167 /* write the mask if we have one */
3168 if(himl
->flags
& ILC_MASK
) {
3169 if(!_write_bitmap(himl
->hbmMask
, pstm
))
3177 static HBITMAP
ImageList_CreateImage(HDC hdc
, HIMAGELIST himl
, UINT count
)
3179 HBITMAP hbmNewBitmap
;
3180 UINT ilc
= (himl
->flags
& 0xFE);
3183 imagelist_get_bitmap_size( himl
, count
, &sz
);
3185 if ((ilc
>= ILC_COLOR4
&& ilc
<= ILC_COLOR32
) || ilc
== ILC_COLOR
)
3187 char buffer
[sizeof(BITMAPINFOHEADER
) + 256 * sizeof(RGBQUAD
)];
3188 BITMAPINFO
*bmi
= (BITMAPINFO
*)buffer
;
3190 TRACE("Creating DIBSection %d x %d, %d Bits per Pixel\n",
3191 sz
.cx
, sz
.cy
, himl
->uBitsPixel
);
3193 memset( buffer
, 0, sizeof(buffer
) );
3194 bmi
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
3195 bmi
->bmiHeader
.biWidth
= sz
.cx
;
3196 bmi
->bmiHeader
.biHeight
= sz
.cy
;
3197 bmi
->bmiHeader
.biPlanes
= 1;
3198 bmi
->bmiHeader
.biBitCount
= himl
->uBitsPixel
;
3199 bmi
->bmiHeader
.biCompression
= BI_RGB
;
3201 if (himl
->uBitsPixel
<= ILC_COLOR8
)
3203 /* retrieve the default color map */
3204 HBITMAP tmp
= CreateBitmap( 1, 1, 1, 1, NULL
);
3205 GetDIBits( hdc
, tmp
, 0, 0, NULL
, bmi
, DIB_RGB_COLORS
);
3206 DeleteObject( tmp
);
3208 hbmNewBitmap
= CreateDIBSection(hdc
, bmi
, DIB_RGB_COLORS
, NULL
, 0, 0);
3210 else /*if (ilc == ILC_COLORDDB)*/
3212 TRACE("Creating Bitmap: %d Bits per Pixel\n", himl
->uBitsPixel
);
3214 hbmNewBitmap
= CreateBitmap (sz
.cx
, sz
.cy
, 1, himl
->uBitsPixel
, NULL
);
3216 TRACE("returning %p\n", hbmNewBitmap
);
3217 return hbmNewBitmap
;
3220 /*************************************************************************
3221 * ImageList_SetColorTable [COMCTL32.@]
3223 * Sets the color table of an image list.
3226 * himl [I] Handle to the image list.
3227 * uStartIndex [I] The first index to set.
3228 * cEntries [I] Number of entries to set.
3229 * prgb [I] New color information for color table for the image list.
3232 * Success: Number of entries in the table that were set.
3236 * ImageList_Create(), SetDIBColorTable()
3240 ImageList_SetColorTable(HIMAGELIST himl
, UINT uStartIndex
, UINT cEntries
, const RGBQUAD
*prgb
)
3242 return SetDIBColorTable(himl
->hdcImage
, uStartIndex
, cEntries
, prgb
);
3245 /*************************************************************************
3246 * ImageList_CoCreateInstance [COMCTL32.@]
3248 * Creates a new imagelist instance and returns an interface pointer to it.
3251 * rclsid [I] A reference to the CLSID (CLSID_ImageList).
3252 * punkOuter [I] Pointer to IUnknown interface for aggregation, if desired
3253 * riid [I] Identifier of the requested interface.
3254 * ppv [O] Returns the address of the pointer requested, or NULL.
3258 * Failure: Error value.
3261 ImageList_CoCreateInstance (REFCLSID rclsid
, const IUnknown
*punkOuter
, REFIID riid
, void **ppv
)
3263 TRACE("(%s,%p,%s,%p)\n", debugstr_guid(rclsid
), punkOuter
, debugstr_guid(riid
), ppv
);
3265 if (!IsEqualCLSID(&CLSID_ImageList
, rclsid
))
3266 return E_NOINTERFACE
;
3268 return ImageListImpl_CreateInstance(punkOuter
, riid
, ppv
);
3272 /*************************************************************************
3273 * IImageList implementation
3276 static HRESULT WINAPI
ImageListImpl_QueryInterface(IImageList2
*iface
,
3277 REFIID iid
, void **ppv
)
3279 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3281 TRACE("(%p,%s,%p)\n", iface
, debugstr_guid(iid
), ppv
);
3283 if (!ppv
) return E_INVALIDARG
;
3285 if (IsEqualIID(&IID_IUnknown
, iid
) ||
3286 IsEqualIID(&IID_IImageList
, iid
) ||
3287 IsEqualIID(&IID_IImageList2
, iid
))
3289 *ppv
= &imgl
->IImageList2_iface
;
3294 return E_NOINTERFACE
;
3297 IImageList2_AddRef(iface
);
3301 static ULONG WINAPI
ImageListImpl_AddRef(IImageList2
*iface
)
3303 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3304 ULONG ref
= InterlockedIncrement(&imgl
->ref
);
3306 TRACE("(%p) refcount=%u\n", iface
, ref
);
3310 static ULONG WINAPI
ImageListImpl_Release(IImageList2
*iface
)
3312 HIMAGELIST This
= impl_from_IImageList2(iface
);
3313 ULONG ref
= InterlockedDecrement(&This
->ref
);
3315 TRACE("(%p) refcount=%u\n", iface
, ref
);
3319 /* delete image bitmaps */
3320 if (This
->hbmImage
) DeleteObject (This
->hbmImage
);
3321 if (This
->hbmMask
) DeleteObject (This
->hbmMask
);
3323 /* delete image & mask DCs */
3324 if (This
->hdcImage
) DeleteDC (This
->hdcImage
);
3325 if (This
->hdcMask
) DeleteDC (This
->hdcMask
);
3327 /* delete blending brushes */
3328 if (This
->hbrBlend25
) DeleteObject (This
->hbrBlend25
);
3329 if (This
->hbrBlend50
) DeleteObject (This
->hbrBlend50
);
3331 This
->IImageList2_iface
.lpVtbl
= NULL
;
3332 HeapFree(GetProcessHeap(), 0, This
->has_alpha
);
3333 HeapFree(GetProcessHeap(), 0, This
);
3339 static HRESULT WINAPI
ImageListImpl_Add(IImageList2
*iface
, HBITMAP hbmImage
,
3340 HBITMAP hbmMask
, int *pi
)
3342 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3348 ret
= ImageList_Add(imgl
, hbmImage
, hbmMask
);
3357 static HRESULT WINAPI
ImageListImpl_ReplaceIcon(IImageList2
*iface
, int i
,
3358 HICON hicon
, int *pi
)
3360 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3366 ret
= ImageList_ReplaceIcon(imgl
, i
, hicon
);
3375 static HRESULT WINAPI
ImageListImpl_SetOverlayImage(IImageList2
*iface
,
3376 int iImage
, int iOverlay
)
3378 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3379 return ImageList_SetOverlayImage(imgl
, iImage
, iOverlay
) ? S_OK
: E_FAIL
;
3382 static HRESULT WINAPI
ImageListImpl_Replace(IImageList2
*iface
, int i
,
3383 HBITMAP hbmImage
, HBITMAP hbmMask
)
3385 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3386 return ImageList_Replace(imgl
, i
, hbmImage
, hbmMask
) ? S_OK
: E_FAIL
;
3389 static HRESULT WINAPI
ImageListImpl_AddMasked(IImageList2
*iface
, HBITMAP hbmImage
,
3390 COLORREF crMask
, int *pi
)
3392 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3398 ret
= ImageList_AddMasked(imgl
, hbmImage
, crMask
);
3407 static HRESULT WINAPI
ImageListImpl_Draw(IImageList2
*iface
,
3408 IMAGELISTDRAWPARAMS
*pimldp
)
3410 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3411 HIMAGELIST old_himl
;
3414 /* As far as I can tell, Windows simply ignores the contents of pimldp->himl
3415 so we shall simulate the same */
3416 old_himl
= pimldp
->himl
;
3417 pimldp
->himl
= imgl
;
3419 ret
= ImageList_DrawIndirect(pimldp
);
3421 pimldp
->himl
= old_himl
;
3422 return ret
? S_OK
: E_INVALIDARG
;
3425 static HRESULT WINAPI
ImageListImpl_Remove(IImageList2
*iface
, int i
)
3427 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3428 return (ImageList_Remove(imgl
, i
) == 0) ? E_INVALIDARG
: S_OK
;
3431 static HRESULT WINAPI
ImageListImpl_GetIcon(IImageList2
*iface
, int i
, UINT flags
,
3434 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3440 hIcon
= ImageList_GetIcon(imgl
, i
, flags
);
3449 static HRESULT WINAPI
ImageListImpl_GetImageInfo(IImageList2
*iface
, int i
,
3450 IMAGEINFO
*pImageInfo
)
3452 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3453 return ImageList_GetImageInfo(imgl
, i
, pImageInfo
) ? S_OK
: E_FAIL
;
3456 static HRESULT WINAPI
ImageListImpl_Copy(IImageList2
*iface
, int dst_index
,
3457 IUnknown
*unk_src
, int src_index
, UINT flags
)
3459 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3460 IImageList
*src
= NULL
;
3466 /* TODO: Add test for IID_ImageList2 too */
3467 if (FAILED(IUnknown_QueryInterface(unk_src
, &IID_IImageList
,
3471 if (ImageList_Copy(imgl
, dst_index
, (HIMAGELIST
) src
, src_index
, flags
))
3476 IImageList_Release(src
);
3480 static HRESULT WINAPI
ImageListImpl_Merge(IImageList2
*iface
, int i1
,
3481 IUnknown
*punk2
, int i2
, int dx
, int dy
, REFIID riid
, void **ppv
)
3483 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3484 IImageList
*iml2
= NULL
;
3486 HRESULT ret
= E_FAIL
;
3488 TRACE("(%p)->(%d %p %d %d %d %s %p)\n", iface
, i1
, punk2
, i2
, dx
, dy
, debugstr_guid(riid
), ppv
);
3490 /* TODO: Add test for IID_ImageList2 too */
3491 if (FAILED(IUnknown_QueryInterface(punk2
, &IID_IImageList
,
3495 merged
= ImageList_Merge(imgl
, i1
, (HIMAGELIST
) iml2
, i2
, dx
, dy
);
3497 /* Get the interface for the new image list */
3500 ret
= HIMAGELIST_QueryInterface(merged
, riid
, ppv
);
3501 ImageList_Destroy(merged
);
3504 IImageList_Release(iml2
);
3508 static HRESULT WINAPI
ImageListImpl_Clone(IImageList2
*iface
, REFIID riid
, void **ppv
)
3510 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3512 HRESULT ret
= E_FAIL
;
3514 TRACE("(%p)->(%s %p)\n", iface
, debugstr_guid(riid
), ppv
);
3516 clone
= ImageList_Duplicate(imgl
);
3518 /* Get the interface for the new image list */
3521 ret
= HIMAGELIST_QueryInterface(clone
, riid
, ppv
);
3522 ImageList_Destroy(clone
);
3528 static HRESULT WINAPI
ImageListImpl_GetImageRect(IImageList2
*iface
, int i
,
3531 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3537 if (!ImageList_GetImageInfo(imgl
, i
, &info
))
3540 return CopyRect(prc
, &info
.rcImage
) ? S_OK
: E_FAIL
;
3543 static HRESULT WINAPI
ImageListImpl_GetIconSize(IImageList2
*iface
, int *cx
,
3546 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3547 return ImageList_GetIconSize(imgl
, cx
, cy
) ? S_OK
: E_INVALIDARG
;
3550 static HRESULT WINAPI
ImageListImpl_SetIconSize(IImageList2
*iface
, int cx
,
3553 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3554 return ImageList_SetIconSize(imgl
, cx
, cy
) ? S_OK
: E_FAIL
;
3557 static HRESULT WINAPI
ImageListImpl_GetImageCount(IImageList2
*iface
, int *pi
)
3559 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3560 *pi
= ImageList_GetImageCount(imgl
);
3564 static HRESULT WINAPI
ImageListImpl_SetImageCount(IImageList2
*iface
, UINT count
)
3566 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3567 return ImageList_SetImageCount(imgl
, count
) ? S_OK
: E_FAIL
;
3570 static HRESULT WINAPI
ImageListImpl_SetBkColor(IImageList2
*iface
, COLORREF clrBk
,
3573 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3574 *pclr
= ImageList_SetBkColor(imgl
, clrBk
);
3578 static HRESULT WINAPI
ImageListImpl_GetBkColor(IImageList2
*iface
, COLORREF
*pclr
)
3580 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3581 *pclr
= ImageList_GetBkColor(imgl
);
3585 static HRESULT WINAPI
ImageListImpl_BeginDrag(IImageList2
*iface
, int iTrack
,
3586 int dxHotspot
, int dyHotspot
)
3588 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3589 return ImageList_BeginDrag(imgl
, iTrack
, dxHotspot
, dyHotspot
) ? S_OK
: E_FAIL
;
3592 static HRESULT WINAPI
ImageListImpl_EndDrag(IImageList2
*iface
)
3594 ImageList_EndDrag();
3598 static HRESULT WINAPI
ImageListImpl_DragEnter(IImageList2
*iface
, HWND hwndLock
,
3601 return ImageList_DragEnter(hwndLock
, x
, y
) ? S_OK
: E_FAIL
;
3604 static HRESULT WINAPI
ImageListImpl_DragLeave(IImageList2
*iface
, HWND hwndLock
)
3606 return ImageList_DragLeave(hwndLock
) ? S_OK
: E_FAIL
;
3609 static HRESULT WINAPI
ImageListImpl_DragMove(IImageList2
*iface
, int x
, int y
)
3611 return ImageList_DragMove(x
, y
) ? S_OK
: E_FAIL
;
3614 static HRESULT WINAPI
ImageListImpl_SetDragCursorImage(IImageList2
*iface
,
3615 IUnknown
*punk
, int iDrag
, int dxHotspot
, int dyHotspot
)
3617 IImageList
*iml2
= NULL
;
3623 /* TODO: Add test for IID_ImageList2 too */
3624 if (FAILED(IUnknown_QueryInterface(punk
, &IID_IImageList
,
3628 ret
= ImageList_SetDragCursorImage((HIMAGELIST
) iml2
, iDrag
, dxHotspot
,
3631 IImageList_Release(iml2
);
3633 return ret
? S_OK
: E_FAIL
;
3636 static HRESULT WINAPI
ImageListImpl_DragShowNolock(IImageList2
*iface
, BOOL fShow
)
3638 return ImageList_DragShowNolock(fShow
) ? S_OK
: E_FAIL
;
3641 static HRESULT WINAPI
ImageListImpl_GetDragImage(IImageList2
*iface
, POINT
*ppt
,
3642 POINT
*pptHotspot
, REFIID riid
, PVOID
*ppv
)
3644 HRESULT ret
= E_FAIL
;
3650 hNew
= ImageList_GetDragImage(ppt
, pptHotspot
);
3652 /* Get the interface for the new image list */
3655 IImageList
*idrag
= (IImageList
*)hNew
;
3657 ret
= HIMAGELIST_QueryInterface(hNew
, riid
, ppv
);
3658 IImageList_Release(idrag
);
3664 static HRESULT WINAPI
ImageListImpl_GetItemFlags(IImageList2
*iface
, int i
,
3667 FIXME("STUB: %p %d %p\n", iface
, i
, dwFlags
);
3671 static HRESULT WINAPI
ImageListImpl_GetOverlayImage(IImageList2
*iface
, int iOverlay
,
3674 HIMAGELIST This
= impl_from_IImageList2(iface
);
3677 if ((iOverlay
< 0) || (iOverlay
> This
->cCurImage
))
3680 for (i
= 0; i
< MAX_OVERLAYIMAGE
; i
++)
3682 if (This
->nOvlIdx
[i
] == iOverlay
)
3692 static HRESULT WINAPI
ImageListImpl_Resize(IImageList2
*iface
, INT cx
, INT cy
)
3694 FIXME("(%p)->(%d %d): stub\n", iface
, cx
, cy
);
3698 static HRESULT WINAPI
ImageListImpl_GetOriginalSize(IImageList2
*iface
, INT image
, DWORD flags
, INT
*cx
, INT
*cy
)
3700 FIXME("(%p)->(%d %x %p %p): stub\n", iface
, image
, flags
, cx
, cy
);
3704 static HRESULT WINAPI
ImageListImpl_SetOriginalSize(IImageList2
*iface
, INT image
, INT cx
, INT cy
)
3706 FIXME("(%p)->(%d %d %d): stub\n", iface
, image
, cx
, cy
);
3710 static HRESULT WINAPI
ImageListImpl_SetCallback(IImageList2
*iface
, IUnknown
*callback
)
3712 FIXME("(%p)->(%p): stub\n", iface
, callback
);
3716 static HRESULT WINAPI
ImageListImpl_GetCallback(IImageList2
*iface
, REFIID riid
, void **ppv
)
3718 FIXME("(%p)->(%s %p): stub\n", iface
, debugstr_guid(riid
), ppv
);
3722 static HRESULT WINAPI
ImageListImpl_ForceImagePresent(IImageList2
*iface
, INT image
, DWORD flags
)
3724 FIXME("(%p)->(%d %x): stub\n", iface
, image
, flags
);
3728 static HRESULT WINAPI
ImageListImpl_DiscardImages(IImageList2
*iface
, INT first_image
, INT last_image
, DWORD flags
)
3730 FIXME("(%p)->(%d %d %x): stub\n", iface
, first_image
, last_image
, flags
);
3734 static HRESULT WINAPI
ImageListImpl_PreloadImages(IImageList2
*iface
, IMAGELISTDRAWPARAMS
*params
)
3736 FIXME("(%p)->(%p): stub\n", iface
, params
);
3740 static HRESULT WINAPI
ImageListImpl_GetStatistics(IImageList2
*iface
, IMAGELISTSTATS
*stats
)
3742 FIXME("(%p)->(%p): stub\n", iface
, stats
);
3746 static HRESULT WINAPI
ImageListImpl_Initialize(IImageList2
*iface
, INT cx
, INT cy
, UINT flags
, INT initial
, INT grow
)
3748 FIXME("(%p)->(%d %d %d %d %d): stub\n", iface
, cx
, cy
, flags
, initial
, grow
);
3752 static HRESULT WINAPI
ImageListImpl_Replace2(IImageList2
*iface
, INT i
, HBITMAP image
, HBITMAP mask
, IUnknown
*unk
, DWORD flags
)
3754 FIXME("(%p)->(%d %p %p %p %x): stub\n", iface
, i
, image
, mask
, unk
, flags
);
3758 static HRESULT WINAPI
ImageListImpl_ReplaceFromImageList(IImageList2
*iface
, INT i
, IImageList
*imagelist
, INT src
,
3759 IUnknown
*unk
, DWORD flags
)
3761 FIXME("(%p)->(%d %p %d %p %x): stub\n", iface
, i
, imagelist
, src
, unk
, flags
);
3765 static const IImageList2Vtbl ImageListImpl_Vtbl
= {
3766 ImageListImpl_QueryInterface
,
3767 ImageListImpl_AddRef
,
3768 ImageListImpl_Release
,
3770 ImageListImpl_ReplaceIcon
,
3771 ImageListImpl_SetOverlayImage
,
3772 ImageListImpl_Replace
,
3773 ImageListImpl_AddMasked
,
3775 ImageListImpl_Remove
,
3776 ImageListImpl_GetIcon
,
3777 ImageListImpl_GetImageInfo
,
3779 ImageListImpl_Merge
,
3780 ImageListImpl_Clone
,
3781 ImageListImpl_GetImageRect
,
3782 ImageListImpl_GetIconSize
,
3783 ImageListImpl_SetIconSize
,
3784 ImageListImpl_GetImageCount
,
3785 ImageListImpl_SetImageCount
,
3786 ImageListImpl_SetBkColor
,
3787 ImageListImpl_GetBkColor
,
3788 ImageListImpl_BeginDrag
,
3789 ImageListImpl_EndDrag
,
3790 ImageListImpl_DragEnter
,
3791 ImageListImpl_DragLeave
,
3792 ImageListImpl_DragMove
,
3793 ImageListImpl_SetDragCursorImage
,
3794 ImageListImpl_DragShowNolock
,
3795 ImageListImpl_GetDragImage
,
3796 ImageListImpl_GetItemFlags
,
3797 ImageListImpl_GetOverlayImage
,
3798 ImageListImpl_Resize
,
3799 ImageListImpl_GetOriginalSize
,
3800 ImageListImpl_SetOriginalSize
,
3801 ImageListImpl_SetCallback
,
3802 ImageListImpl_GetCallback
,
3803 ImageListImpl_ForceImagePresent
,
3804 ImageListImpl_DiscardImages
,
3805 ImageListImpl_PreloadImages
,
3806 ImageListImpl_GetStatistics
,
3807 ImageListImpl_Initialize
,
3808 ImageListImpl_Replace2
,
3809 ImageListImpl_ReplaceFromImageList
3812 static BOOL
is_valid(HIMAGELIST himl
)
3817 valid
= himl
&& himl
->IImageList2_iface
.lpVtbl
== &ImageListImpl_Vtbl
;
3827 /*************************************************************************
3828 * HIMAGELIST_QueryInterface [COMCTL32.@]
3830 * Returns a pointer to an IImageList or IImageList2 object for the given
3834 * himl [I] Image list handle.
3835 * riid [I] Identifier of the requested interface.
3836 * ppv [O] Returns the address of the pointer requested, or NULL.
3840 * Failure: Error value.
3843 HIMAGELIST_QueryInterface (HIMAGELIST himl
, REFIID riid
, void **ppv
)
3845 TRACE("(%p,%s,%p)\n", himl
, debugstr_guid(riid
), ppv
);
3846 return IImageList2_QueryInterface((IImageList2
*) himl
, riid
, ppv
);
3849 static HRESULT
ImageListImpl_CreateInstance(const IUnknown
*pUnkOuter
, REFIID iid
, void** ppv
)
3854 TRACE("(%p,%s,%p)\n", pUnkOuter
, debugstr_guid(iid
), ppv
);
3858 if (pUnkOuter
) return CLASS_E_NOAGGREGATION
;
3860 This
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(struct _IMAGELIST
));
3861 if (!This
) return E_OUTOFMEMORY
;
3863 This
->IImageList2_iface
.lpVtbl
= &ImageListImpl_Vtbl
;
3866 ret
= IImageList2_QueryInterface(&This
->IImageList2_iface
, iid
, ppv
);
3867 IImageList2_Release(&This
->IImageList2_iface
);