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
26 * - Add support for ILD_PRESERVEALPHA, ILD_SCALE, ILD_DPISCALE
27 * - Add support for ILS_GLOW, ILS_SHADOW
28 * - Thread-safe locking
45 #include "commoncontrols.h"
46 #include "wine/debug.h"
47 #include "wine/exception.h"
48 #include "wine/heap.h"
50 WINE_DEFAULT_DEBUG_CHANNEL(imagelist
);
52 #define MAX_OVERLAYIMAGE 15
56 IImageList2 IImageList2_iface
; /* 00: IImageList vtable */
57 INT cCurImage
; /* 04: ImageCount */
58 INT cMaxImage
; /* 08: maximages */
59 INT cGrow
; /* 0C: cGrow */
63 UINT flags
; /* 1C: flags */
64 COLORREF clrFg
; /* 20: foreground color */
65 COLORREF clrBk
; /* 24: background color */
68 HBITMAP hbmImage
; /* 28: images Bitmap */
69 HBITMAP hbmMask
; /* 2C: masks Bitmap */
70 HDC hdcImage
; /* 30: images MemDC */
71 HDC hdcMask
; /* 34: masks MemDC */
72 INT nOvlIdx
[MAX_OVERLAYIMAGE
]; /* 38: overlay images index */
74 /* not yet found out */
82 LONG ref
; /* reference count */
85 #define IMAGELIST_MAGIC 0x53414D58
87 /* Header used by ImageList_Read() and ImageList_Write() */
89 typedef struct _ILHEAD
104 /* internal image list data used for Drag & Drop operations */
109 HIMAGELIST himlNoCursor
;
110 /* position of the drag image relative to the window */
113 /* offset of the hotspot relative to the origin of the image */
116 /* is the drag image visible */
118 /* saved background */
122 static INTERNALDRAG InternalDrag
= { 0, 0, 0, 0, 0, 0, 0, FALSE
, 0 };
124 static inline HIMAGELIST
impl_from_IImageList2(IImageList2
*iface
)
126 return CONTAINING_RECORD(iface
, struct _IMAGELIST
, IImageList2_iface
);
129 static HBITMAP
ImageList_CreateImage(HDC hdc
, HIMAGELIST himl
, UINT count
);
130 static HRESULT
ImageListImpl_CreateInstance(const IUnknown
*pUnkOuter
, REFIID iid
, void** ppv
);
131 static BOOL
is_valid(HIMAGELIST himl
);
134 * An imagelist with N images is tiled like this:
146 static inline UINT
imagelist_height( UINT count
)
148 return ((count
+ TILE_COUNT
- 1)/TILE_COUNT
);
151 static inline void imagelist_point_from_index( HIMAGELIST himl
, UINT index
, LPPOINT pt
)
153 pt
->x
= (index
%TILE_COUNT
) * himl
->cx
;
154 pt
->y
= (index
/TILE_COUNT
) * himl
->cy
;
157 static inline void imagelist_get_bitmap_size( HIMAGELIST himl
, UINT count
, SIZE
*sz
)
159 sz
->cx
= himl
->cx
* TILE_COUNT
;
160 sz
->cy
= imagelist_height( count
) * himl
->cy
;
163 static inline int get_dib_stride( int width
, int bpp
)
165 return ((width
* bpp
+ 31) >> 3) & ~3;
168 static inline int get_dib_image_size( const BITMAPINFO
*info
)
170 return get_dib_stride( info
->bmiHeader
.biWidth
, info
->bmiHeader
.biBitCount
)
171 * abs( info
->bmiHeader
.biHeight
);
175 * imagelist_copy_images()
177 * Copies a block of count images from offset src in the list to offset dest.
178 * Images are copied a row at at time. Assumes hdcSrc and hdcDest are different.
180 static inline void imagelist_copy_images( HIMAGELIST himl
, HDC hdcSrc
, HDC hdcDest
,
181 UINT src
, UINT count
, UINT dest
)
187 for ( i
=0; i
<TILE_COUNT
; i
++ )
189 imagelist_point_from_index( himl
, src
+i
, &ptSrc
);
190 imagelist_point_from_index( himl
, dest
+i
, &ptDest
);
192 sz
.cy
= himl
->cy
* imagelist_height( count
- i
);
194 BitBlt( hdcDest
, ptDest
.x
, ptDest
.y
, sz
.cx
, sz
.cy
,
195 hdcSrc
, ptSrc
.x
, ptSrc
.y
, SRCCOPY
);
199 static void add_dib_bits( HIMAGELIST himl
, int pos
, int count
, int width
, int height
,
200 BITMAPINFO
*info
, BITMAPINFO
*mask_info
, DWORD
*bits
, BYTE
*mask_bits
)
204 int stride
= info
->bmiHeader
.biWidth
;
205 int mask_stride
= (info
->bmiHeader
.biWidth
+ 31) / 32 * 4;
207 for (n
= 0; n
< count
; n
++)
209 BOOL has_alpha
= FALSE
;
211 imagelist_point_from_index( himl
, pos
+ n
, &pt
);
213 /* check if bitmap has an alpha channel */
214 for (i
= 0; i
< height
&& !has_alpha
; i
++)
215 for (j
= n
* width
; j
< (n
+ 1) * width
; j
++)
216 if ((has_alpha
= ((bits
[i
* stride
+ j
] & 0xff000000) != 0))) break;
220 himl
->item_flags
[pos
+ n
] = ILIF_ALPHA
;
222 if (mask_info
&& himl
->hbmMask
) /* generate the mask from the alpha channel */
224 for (i
= 0; i
< height
; i
++)
225 for (j
= n
* width
; j
< (n
+ 1) * width
; j
++)
226 if ((bits
[i
* stride
+ j
] >> 24) > 25) /* more than 10% alpha */
227 mask_bits
[i
* mask_stride
+ j
/ 8] &= ~(0x80 >> (j
% 8));
229 mask_bits
[i
* mask_stride
+ j
/ 8] |= 0x80 >> (j
% 8);
232 StretchDIBits( himl
->hdcImage
, pt
.x
, pt
.y
, himl
->cx
, himl
->cy
,
233 n
* width
, 0, width
, height
, bits
, info
, DIB_RGB_COLORS
, SRCCOPY
);
235 StretchDIBits( himl
->hdcMask
, pt
.x
, pt
.y
, himl
->cx
, himl
->cy
,
236 n
* width
, 0, width
, height
, mask_bits
, mask_info
, DIB_RGB_COLORS
, SRCCOPY
);
240 /* add images with an alpha channel when the image list is 32 bpp */
241 static BOOL
add_with_alpha( HIMAGELIST himl
, HDC hdc
, int pos
, int count
,
242 int width
, int height
, HBITMAP hbmImage
, HBITMAP hbmMask
)
246 BITMAPINFO
*info
, *mask_info
= NULL
;
248 BYTE
*mask_bits
= NULL
;
251 if (!GetObjectW( hbmImage
, sizeof(bm
), &bm
)) return FALSE
;
253 /* if either the imagelist or the source bitmap don't have an alpha channel, bail out now */
254 if ((himl
->flags
& 0xfe) != ILC_COLOR32
) return FALSE
;
255 if (bm
.bmBitsPixel
!= 32) return FALSE
;
257 SelectObject( hdc
, hbmImage
);
258 mask_width
= (bm
.bmWidth
+ 31) / 32 * 4;
260 if (!(info
= heap_alloc( FIELD_OFFSET( BITMAPINFO
, bmiColors
[256] )))) goto done
;
261 info
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
262 info
->bmiHeader
.biWidth
= bm
.bmWidth
;
263 info
->bmiHeader
.biHeight
= -height
;
264 info
->bmiHeader
.biPlanes
= 1;
265 info
->bmiHeader
.biBitCount
= 32;
266 info
->bmiHeader
.biCompression
= BI_RGB
;
267 info
->bmiHeader
.biSizeImage
= bm
.bmWidth
* height
* 4;
268 info
->bmiHeader
.biXPelsPerMeter
= 0;
269 info
->bmiHeader
.biYPelsPerMeter
= 0;
270 info
->bmiHeader
.biClrUsed
= 0;
271 info
->bmiHeader
.biClrImportant
= 0;
272 if (!(bits
= heap_alloc( info
->bmiHeader
.biSizeImage
))) goto done
;
273 if (!GetDIBits( hdc
, hbmImage
, 0, height
, bits
, info
, DIB_RGB_COLORS
)) goto done
;
277 if (!(mask_info
= heap_alloc( FIELD_OFFSET( BITMAPINFO
, bmiColors
[2] ))))
279 mask_info
->bmiHeader
= info
->bmiHeader
;
280 mask_info
->bmiHeader
.biBitCount
= 1;
281 mask_info
->bmiHeader
.biSizeImage
= mask_width
* height
;
282 if (!(mask_bits
= heap_alloc_zero( mask_info
->bmiHeader
.biSizeImage
)))
284 if (!GetDIBits( hdc
, hbmMask
, 0, height
, mask_bits
, mask_info
, DIB_RGB_COLORS
)) goto done
;
287 add_dib_bits( himl
, pos
, count
, width
, height
, info
, mask_info
, bits
, mask_bits
);
292 heap_free( mask_info
);
294 heap_free( mask_bits
);
299 ImageList_SetColorTable(HIMAGELIST himl
, UINT uStartIndex
, UINT cEntries
, const RGBQUAD
*prgb
);
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
;
371 himl
->item_flags
= HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, himl
->item_flags
,
372 nNewCount
* sizeof(*himl
->item_flags
));
373 himl
->cMaxImage
= nNewCount
;
375 DeleteDC (hdcBitmap
);
379 /*************************************************************************
380 * ImageList_Add [COMCTL32.@]
382 * Add an image or images to an image list.
385 * himl [I] handle to image list
386 * hbmImage [I] handle to image bitmap
387 * hbmMask [I] handle to mask bitmap
390 * Success: Index of the first new image.
395 ImageList_Add (HIMAGELIST himl
, HBITMAP hbmImage
, HBITMAP hbmMask
)
397 HDC hdcBitmap
, hdcTemp
= 0;
398 INT nFirstIndex
, nImageCount
, i
;
402 TRACE("himl=%p hbmimage=%p hbmmask=%p\n", himl
, hbmImage
, hbmMask
);
406 if (!GetObjectW(hbmImage
, sizeof(BITMAP
), &bmp
))
409 TRACE("himl %p, cCurImage %d, cMaxImage %d, cGrow %d, cx %d, cy %d\n",
410 himl
, himl
->cCurImage
, himl
->cMaxImage
, himl
->cGrow
, himl
->cx
, himl
->cy
);
412 nImageCount
= bmp
.bmWidth
/ himl
->cx
;
414 TRACE("%p has %d images (%d x %d) bpp %d\n", hbmImage
, nImageCount
, bmp
.bmWidth
, bmp
.bmHeight
,
417 IMAGELIST_InternalExpandBitmaps(himl
, nImageCount
);
419 hdcBitmap
= CreateCompatibleDC(0);
421 SelectObject(hdcBitmap
, hbmImage
);
423 if (add_with_alpha( himl
, hdcBitmap
, himl
->cCurImage
, nImageCount
,
424 himl
->cx
, min( himl
->cy
, bmp
.bmHeight
), hbmImage
, hbmMask
))
429 hdcTemp
= CreateCompatibleDC(0);
430 SelectObject(hdcTemp
, hbmMask
);
433 if (himl
->uBitsPixel
<= 8 && bmp
.bmBitsPixel
<= 8 &&
434 !himl
->color_table_set
&& himl
->cCurImage
== 0)
437 UINT num
= GetDIBColorTable( hdcBitmap
, 0, 1 << bmp
.bmBitsPixel
, colors
);
438 if (num
) ImageList_SetColorTable( himl
, 0, num
, colors
);
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
;
767 if (!((flags
&ILC_COLORDDB
) == ILC_COLORDDB
) && (cx
== 0 || cy
== 0)) return NULL
;
769 /* Create the IImageList interface for the image list */
770 if (FAILED(ImageListImpl_CreateInstance(NULL
, &IID_IImageList
, (void **)&himl
)))
773 cGrow
= (WORD
)((max( cGrow
, 1 ) + 3) & ~3);
777 /* Windows doesn't limit the size here, but X11 doesn't let us allocate such huge bitmaps */
778 WARN( "grow %d too large, limiting to 256\n", cGrow
);
785 himl
->cMaxImage
= cInitial
+ 1;
786 himl
->cInitial
= cInitial
;
788 himl
->clrFg
= CLR_DEFAULT
;
789 himl
->clrBk
= CLR_NONE
;
790 himl
->color_table_set
= FALSE
;
792 /* initialize overlay mask indices */
793 for (nCount
= 0; nCount
< MAX_OVERLAYIMAGE
; nCount
++)
794 himl
->nOvlIdx
[nCount
] = -1;
796 /* Create Image & Mask DCs */
797 himl
->hdcImage
= CreateCompatibleDC (0);
800 if (himl
->flags
& ILC_MASK
){
801 himl
->hdcMask
= CreateCompatibleDC(0);
806 /* Default to ILC_COLOR4 if none of the ILC_COLOR* flags are specified */
807 if (ilc
== ILC_COLOR
)
810 himl
->flags
|= ILC_COLOR4
;
813 if (ilc
>= ILC_COLOR4
&& ilc
<= ILC_COLOR32
)
814 himl
->uBitsPixel
= ilc
;
816 himl
->uBitsPixel
= (UINT
)GetDeviceCaps (himl
->hdcImage
, BITSPIXEL
);
818 if (himl
->cMaxImage
> 0) {
819 himl
->hbmImage
= ImageList_CreateImage(himl
->hdcImage
, himl
, himl
->cMaxImage
);
820 SelectObject(himl
->hdcImage
, himl
->hbmImage
);
824 if ((himl
->cMaxImage
> 0) && (himl
->flags
& ILC_MASK
)) {
827 imagelist_get_bitmap_size(himl
, himl
->cMaxImage
, &sz
);
828 himl
->hbmMask
= CreateBitmap (sz
.cx
, sz
.cy
, 1, 1, NULL
);
829 if (himl
->hbmMask
== 0) {
830 ERR("Error creating mask bitmap!\n");
833 SelectObject(himl
->hdcMask
, himl
->hbmMask
);
838 himl
->item_flags
= heap_alloc_zero( himl
->cMaxImage
* sizeof(*himl
->item_flags
) );
840 /* create blending brushes */
841 hbmTemp
= CreateBitmap (8, 8, 1, 1, aBitBlend25
);
842 himl
->hbrBlend25
= CreatePatternBrush (hbmTemp
);
843 DeleteObject (hbmTemp
);
845 hbmTemp
= CreateBitmap (8, 8, 1, 1, aBitBlend50
);
846 himl
->hbrBlend50
= CreatePatternBrush (hbmTemp
);
847 DeleteObject (hbmTemp
);
849 TRACE("created imagelist %p\n", himl
);
853 ImageList_Destroy(himl
);
858 /*************************************************************************
859 * ImageList_Destroy [COMCTL32.@]
861 * Destroys an image list.
864 * himl [I] handle to image list
872 ImageList_Destroy (HIMAGELIST himl
)
877 IImageList_Release((IImageList
*) himl
);
882 /*************************************************************************
883 * ImageList_DragEnter [COMCTL32.@]
885 * Locks window update and displays the drag image at the given position.
888 * hwndLock [I] handle of the window that owns the drag image.
889 * x [I] X position of the drag image.
890 * y [I] Y position of the drag image.
897 * The position of the drag image is relative to the window, not
902 ImageList_DragEnter (HWND hwndLock
, INT x
, INT y
)
904 TRACE("(hwnd=%p x=%d y=%d)\n", hwndLock
, x
, y
);
906 if (!is_valid(InternalDrag
.himl
))
910 InternalDrag
.hwnd
= hwndLock
;
912 InternalDrag
.hwnd
= GetDesktopWindow ();
917 /* draw the drag image and save the background */
918 return ImageList_DragShowNolock(TRUE
);
922 /*************************************************************************
923 * ImageList_DragLeave [COMCTL32.@]
925 * Unlocks window update and hides the drag image.
928 * hwndLock [I] handle of the window that owns the drag image.
936 ImageList_DragLeave (HWND hwndLock
)
938 /* As we don't save drag info in the window this can lead to problems if
939 an app does not supply the same window as DragEnter */
941 InternalDrag.hwnd = hwndLock;
943 InternalDrag.hwnd = GetDesktopWindow (); */
945 hwndLock
= GetDesktopWindow();
946 if(InternalDrag
.hwnd
!= hwndLock
)
947 FIXME("DragLeave hWnd != DragEnter hWnd\n");
949 ImageList_DragShowNolock (FALSE
);
955 /*************************************************************************
956 * ImageList_InternalDragDraw [Internal]
958 * Draws the drag image.
961 * hdc [I] device context to draw into.
962 * x [I] X position of the drag image.
963 * y [I] Y position of the drag image.
970 * The position of the drag image is relative to the window, not
976 ImageList_InternalDragDraw (HDC hdc
, INT x
, INT y
)
978 IMAGELISTDRAWPARAMS imldp
;
980 ZeroMemory (&imldp
, sizeof(imldp
));
981 imldp
.cbSize
= sizeof(imldp
);
982 imldp
.himl
= InternalDrag
.himl
;
987 imldp
.rgbBk
= CLR_DEFAULT
;
988 imldp
.rgbFg
= CLR_DEFAULT
;
989 imldp
.fStyle
= ILD_NORMAL
;
990 imldp
.fState
= ILS_ALPHA
;
992 ImageList_DrawIndirect (&imldp
);
995 /*************************************************************************
996 * ImageList_DragMove [COMCTL32.@]
998 * Moves the drag image.
1001 * x [I] X position of the drag image.
1002 * y [I] Y position of the drag image.
1009 * The position of the drag image is relative to the window, not
1014 ImageList_DragMove (INT x
, INT y
)
1016 TRACE("(x=%d y=%d)\n", x
, y
);
1018 if (!is_valid(InternalDrag
.himl
))
1021 /* draw/update the drag image */
1022 if (InternalDrag
.bShow
) {
1026 HBITMAP hbmOffScreen
;
1027 INT origNewX
, origNewY
;
1028 INT origOldX
, origOldY
;
1029 INT origRegX
, origRegY
;
1030 INT sizeRegX
, sizeRegY
;
1033 /* calculate the update region */
1034 origNewX
= x
- InternalDrag
.dxHotspot
;
1035 origNewY
= y
- InternalDrag
.dyHotspot
;
1036 origOldX
= InternalDrag
.x
- InternalDrag
.dxHotspot
;
1037 origOldY
= InternalDrag
.y
- InternalDrag
.dyHotspot
;
1038 origRegX
= min(origNewX
, origOldX
);
1039 origRegY
= min(origNewY
, origOldY
);
1040 sizeRegX
= InternalDrag
.himl
->cx
+ abs(x
- InternalDrag
.x
);
1041 sizeRegY
= InternalDrag
.himl
->cy
+ abs(y
- InternalDrag
.y
);
1043 hdcDrag
= GetDCEx(InternalDrag
.hwnd
, 0,
1044 DCX_WINDOW
| DCX_CACHE
| DCX_LOCKWINDOWUPDATE
);
1045 hdcOffScreen
= CreateCompatibleDC(hdcDrag
);
1046 hdcBg
= CreateCompatibleDC(hdcDrag
);
1048 hbmOffScreen
= CreateCompatibleBitmap(hdcDrag
, sizeRegX
, sizeRegY
);
1049 SelectObject(hdcOffScreen
, hbmOffScreen
);
1050 SelectObject(hdcBg
, InternalDrag
.hbmBg
);
1052 /* get the actual background of the update region */
1053 BitBlt(hdcOffScreen
, 0, 0, sizeRegX
, sizeRegY
, hdcDrag
,
1054 origRegX
, origRegY
, SRCCOPY
);
1055 /* erase the old image */
1056 BitBlt(hdcOffScreen
, origOldX
- origRegX
, origOldY
- origRegY
,
1057 InternalDrag
.himl
->cx
, InternalDrag
.himl
->cy
, hdcBg
, 0, 0,
1059 /* save the background */
1060 BitBlt(hdcBg
, 0, 0, InternalDrag
.himl
->cx
, InternalDrag
.himl
->cy
,
1061 hdcOffScreen
, origNewX
- origRegX
, origNewY
- origRegY
, SRCCOPY
);
1062 /* draw the image */
1063 ImageList_InternalDragDraw(hdcOffScreen
, origNewX
- origRegX
,
1064 origNewY
- origRegY
);
1065 /* draw the update region to the screen */
1066 BitBlt(hdcDrag
, origRegX
, origRegY
, sizeRegX
, sizeRegY
,
1067 hdcOffScreen
, 0, 0, SRCCOPY
);
1070 DeleteDC(hdcOffScreen
);
1071 DeleteObject(hbmOffScreen
);
1072 ReleaseDC(InternalDrag
.hwnd
, hdcDrag
);
1075 /* update the image position */
1083 /*************************************************************************
1084 * ImageList_DragShowNolock [COMCTL32.@]
1086 * Shows or hides the drag image.
1089 * bShow [I] TRUE shows the drag image, FALSE hides it.
1097 ImageList_DragShowNolock (BOOL bShow
)
1103 if (!is_valid(InternalDrag
.himl
))
1106 TRACE("bShow=0x%X!\n", bShow
);
1108 /* DragImage is already visible/hidden */
1109 if ((InternalDrag
.bShow
&& bShow
) || (!InternalDrag
.bShow
&& !bShow
)) {
1113 /* position of the origin of the DragImage */
1114 x
= InternalDrag
.x
- InternalDrag
.dxHotspot
;
1115 y
= InternalDrag
.y
- InternalDrag
.dyHotspot
;
1117 hdcDrag
= GetDCEx (InternalDrag
.hwnd
, 0,
1118 DCX_WINDOW
| DCX_CACHE
| DCX_LOCKWINDOWUPDATE
);
1123 hdcBg
= CreateCompatibleDC(hdcDrag
);
1124 if (!InternalDrag
.hbmBg
) {
1125 InternalDrag
.hbmBg
= CreateCompatibleBitmap(hdcDrag
,
1126 InternalDrag
.himl
->cx
, InternalDrag
.himl
->cy
);
1128 SelectObject(hdcBg
, InternalDrag
.hbmBg
);
1131 /* save the background */
1132 BitBlt(hdcBg
, 0, 0, InternalDrag
.himl
->cx
, InternalDrag
.himl
->cy
,
1133 hdcDrag
, x
, y
, SRCCOPY
);
1134 /* show the image */
1135 ImageList_InternalDragDraw(hdcDrag
, x
, y
);
1137 /* hide the image */
1138 BitBlt(hdcDrag
, x
, y
, InternalDrag
.himl
->cx
, InternalDrag
.himl
->cy
,
1139 hdcBg
, 0, 0, SRCCOPY
);
1142 InternalDrag
.bShow
= !InternalDrag
.bShow
;
1145 ReleaseDC (InternalDrag
.hwnd
, hdcDrag
);
1150 /*************************************************************************
1151 * ImageList_Draw [COMCTL32.@]
1156 * himl [I] handle to image list
1158 * hdc [I] handle to device context
1161 * fStyle [I] drawing flags
1172 ImageList_Draw (HIMAGELIST himl
, INT i
, HDC hdc
, INT x
, INT y
, UINT fStyle
)
1174 return ImageList_DrawEx (himl
, i
, hdc
, x
, y
, 0, 0,
1175 CLR_DEFAULT
, CLR_DEFAULT
, fStyle
);
1179 /*************************************************************************
1180 * ImageList_DrawEx [COMCTL32.@]
1182 * Draws an image and allows using extended drawing features.
1185 * himl [I] handle to image list
1187 * hdc [I] handle to device context
1192 * rgbBk [I] background color
1193 * rgbFg [I] foreground color
1194 * fStyle [I] drawing flags
1201 * Calls ImageList_DrawIndirect.
1204 * ImageList_DrawIndirect.
1208 ImageList_DrawEx (HIMAGELIST himl
, INT i
, HDC hdc
, INT x
, INT y
,
1209 INT dx
, INT dy
, COLORREF rgbBk
, COLORREF rgbFg
,
1212 IMAGELISTDRAWPARAMS imldp
;
1214 ZeroMemory (&imldp
, sizeof(imldp
));
1215 imldp
.cbSize
= sizeof(imldp
);
1223 imldp
.rgbBk
= rgbBk
;
1224 imldp
.rgbFg
= rgbFg
;
1225 imldp
.fStyle
= fStyle
;
1227 return ImageList_DrawIndirect (&imldp
);
1231 static BOOL
alpha_blend_image( HIMAGELIST himl
, HDC dest_dc
, int dest_x
, int dest_y
,
1232 int src_x
, int src_y
, int cx
, int cy
, BLENDFUNCTION func
,
1233 UINT style
, COLORREF blend_col
, BOOL has_alpha
, BOOL grayscale
)
1237 HBITMAP bmp
= 0, mask
= 0;
1239 void *bits
, *mask_bits
;
1243 if (!(hdc
= CreateCompatibleDC( 0 ))) return FALSE
;
1244 if (!(info
= heap_alloc( FIELD_OFFSET( BITMAPINFO
, bmiColors
[256] )))) goto done
;
1245 info
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
1246 info
->bmiHeader
.biWidth
= cx
;
1247 info
->bmiHeader
.biHeight
= cy
;
1248 info
->bmiHeader
.biPlanes
= 1;
1249 info
->bmiHeader
.biBitCount
= 32;
1250 info
->bmiHeader
.biCompression
= BI_RGB
;
1251 info
->bmiHeader
.biSizeImage
= cx
* cy
* 4;
1252 info
->bmiHeader
.biXPelsPerMeter
= 0;
1253 info
->bmiHeader
.biYPelsPerMeter
= 0;
1254 info
->bmiHeader
.biClrUsed
= 0;
1255 info
->bmiHeader
.biClrImportant
= 0;
1256 if (!(bmp
= CreateDIBSection( himl
->hdcImage
, info
, DIB_RGB_COLORS
, &bits
, 0, 0 ))) goto done
;
1257 SelectObject( hdc
, bmp
);
1258 BitBlt( hdc
, 0, 0, cx
, cy
, himl
->hdcImage
, src_x
, src_y
, SRCCOPY
);
1260 if (blend_col
!= CLR_NONE
)
1262 BYTE r
= GetRValue( blend_col
);
1263 BYTE g
= GetGValue( blend_col
);
1264 BYTE b
= GetBValue( blend_col
);
1266 if (style
& ILD_BLEND25
)
1268 for (i
= 0, ptr
= bits
; i
< cx
* cy
; i
++, ptr
++)
1269 *ptr
= ((*ptr
& 0xff000000) |
1270 ((((*ptr
& 0x00ff0000) * 3 + (r
<< 16)) / 4) & 0x00ff0000) |
1271 ((((*ptr
& 0x0000ff00) * 3 + (g
<< 8)) / 4) & 0x0000ff00) |
1272 ((((*ptr
& 0x000000ff) * 3 + (b
<< 0)) / 4) & 0x000000ff));
1274 else if (style
& ILD_BLEND50
)
1276 for (i
= 0, ptr
= bits
; i
< cx
* cy
; i
++, ptr
++)
1277 *ptr
= ((*ptr
& 0xff000000) |
1278 ((((*ptr
& 0x00ff0000) + (r
<< 16)) / 2) & 0x00ff0000) |
1279 ((((*ptr
& 0x0000ff00) + (g
<< 8)) / 2) & 0x0000ff00) |
1280 ((((*ptr
& 0x000000ff) + (b
<< 0)) / 2) & 0x000000ff));
1286 for (i
= 0, ptr
= bits
; i
< cx
* cy
; i
++, ptr
++)
1288 DWORD gray
= (((*ptr
& 0x00ff0000) >> 16) * 299 +
1289 ((*ptr
& 0x0000ff00) >> 8) * 587 +
1290 ((*ptr
& 0x000000ff) >> 0) * 114 + 500) / 1000;
1291 if (has_alpha
) gray
= gray
* (*ptr
>> 24) / 255;
1292 *ptr
= (*ptr
& 0xff000000)| (gray
<< 16) | (gray
<< 8) | gray
;
1296 if (has_alpha
) /* we already have an alpha channel in this case */
1298 /* pre-multiply by the alpha channel */
1299 for (i
= 0, ptr
= bits
; i
< cx
* cy
; i
++, ptr
++)
1301 DWORD alpha
= *ptr
>> 24;
1302 *ptr
= ((*ptr
& 0xff000000) |
1303 (((*ptr
& 0x00ff0000) * alpha
/ 255) & 0x00ff0000) |
1304 (((*ptr
& 0x0000ff00) * alpha
/ 255) & 0x0000ff00) |
1305 (((*ptr
& 0x000000ff) * alpha
/ 255)));
1308 else if (himl
->hbmMask
)
1310 unsigned int width_bytes
= (cx
+ 31) / 32 * 4;
1311 /* generate alpha channel from the mask */
1312 info
->bmiHeader
.biBitCount
= 1;
1313 info
->bmiHeader
.biSizeImage
= width_bytes
* cy
;
1314 info
->bmiColors
[0].rgbRed
= 0;
1315 info
->bmiColors
[0].rgbGreen
= 0;
1316 info
->bmiColors
[0].rgbBlue
= 0;
1317 info
->bmiColors
[0].rgbReserved
= 0;
1318 info
->bmiColors
[1].rgbRed
= 0xff;
1319 info
->bmiColors
[1].rgbGreen
= 0xff;
1320 info
->bmiColors
[1].rgbBlue
= 0xff;
1321 info
->bmiColors
[1].rgbReserved
= 0;
1322 if (!(mask
= CreateDIBSection( himl
->hdcMask
, info
, DIB_RGB_COLORS
, &mask_bits
, 0, 0 )))
1324 SelectObject( hdc
, mask
);
1325 BitBlt( hdc
, 0, 0, cx
, cy
, himl
->hdcMask
, src_x
, src_y
, SRCCOPY
);
1326 SelectObject( hdc
, bmp
);
1327 for (i
= 0, ptr
= bits
; i
< cy
; i
++)
1328 for (j
= 0; j
< cx
; j
++, ptr
++)
1329 if ((((BYTE
*)mask_bits
)[i
* width_bytes
+ j
/ 8] << (j
% 8)) & 0x80) *ptr
= 0;
1330 else *ptr
|= 0xff000000;
1334 for (i
= 0, ptr
= bits
; i
< cx
* cy
; i
++, ptr
++)
1338 ret
= GdiAlphaBlend( dest_dc
, dest_x
, dest_y
, cx
, cy
, hdc
, 0, 0, cx
, cy
, func
);
1342 if (bmp
) DeleteObject( bmp
);
1343 if (mask
) DeleteObject( mask
);
1348 /*************************************************************************
1349 * ImageList_DrawIndirect [COMCTL32.@]
1351 * Draws an image using various parameters specified in pimldp.
1354 * pimldp [I] pointer to IMAGELISTDRAWPARAMS structure.
1362 ImageList_DrawIndirect (IMAGELISTDRAWPARAMS
*pimldp
)
1364 INT cx
, cy
, nOvlIdx
;
1365 DWORD fState
, dwRop
;
1367 COLORREF oldImageBk
, oldImageFg
;
1368 HDC hImageDC
, hImageListDC
, hMaskListDC
;
1369 HBITMAP hImageBmp
, hOldImageBmp
, hBlendMaskBmp
;
1370 BOOL bIsTransparent
, bBlend
, bResult
= FALSE
, bMask
;
1376 if (!pimldp
|| !(himl
= pimldp
->himl
)) return FALSE
;
1377 if (!is_valid(himl
)) return FALSE
;
1378 if ((pimldp
->i
< 0) || (pimldp
->i
>= himl
->cCurImage
)) return FALSE
;
1380 imagelist_point_from_index( himl
, pimldp
->i
, &pt
);
1381 pt
.x
+= pimldp
->xBitmap
;
1382 pt
.y
+= pimldp
->yBitmap
;
1384 fState
= pimldp
->cbSize
< sizeof(IMAGELISTDRAWPARAMS
) ? ILS_NORMAL
: pimldp
->fState
;
1385 fStyle
= pimldp
->fStyle
& ~ILD_OVERLAYMASK
;
1386 cx
= (pimldp
->cx
== 0) ? himl
->cx
: pimldp
->cx
;
1387 cy
= (pimldp
->cy
== 0) ? himl
->cy
: pimldp
->cy
;
1389 bIsTransparent
= (fStyle
& ILD_TRANSPARENT
);
1390 if( pimldp
->rgbBk
== CLR_NONE
)
1391 bIsTransparent
= TRUE
;
1392 if( ( pimldp
->rgbBk
== CLR_DEFAULT
) && ( himl
->clrBk
== CLR_NONE
) )
1393 bIsTransparent
= TRUE
;
1394 bMask
= (himl
->flags
& ILC_MASK
) && (fStyle
& ILD_MASK
) ;
1395 bBlend
= (fStyle
& (ILD_BLEND25
| ILD_BLEND50
) ) && !bMask
;
1397 TRACE("himl(%p) hbmMask(%p) iImage(%d) x(%d) y(%d) cx(%d) cy(%d)\n",
1398 himl
, himl
->hbmMask
, pimldp
->i
, pimldp
->x
, pimldp
->y
, cx
, cy
);
1400 /* we will use these DCs to access the images and masks in the ImageList */
1401 hImageListDC
= himl
->hdcImage
;
1402 hMaskListDC
= himl
->hdcMask
;
1404 /* these will accumulate the image and mask for the image we're drawing */
1405 hImageDC
= CreateCompatibleDC( pimldp
->hdcDst
);
1406 hImageBmp
= CreateCompatibleBitmap( pimldp
->hdcDst
, cx
, cy
);
1407 hBlendMaskBmp
= bBlend
? CreateBitmap(cx
, cy
, 1, 1, NULL
) : 0;
1409 /* Create a compatible DC. */
1410 if (!hImageListDC
|| !hImageDC
|| !hImageBmp
||
1411 (bBlend
&& !hBlendMaskBmp
) || (himl
->hbmMask
&& !hMaskListDC
))
1414 hOldImageBmp
= SelectObject(hImageDC
, hImageBmp
);
1417 * To obtain a transparent look, background color should be set
1418 * to white and foreground color to black when blitting the
1421 oldImageFg
= SetTextColor( hImageDC
, RGB( 0, 0, 0 ) );
1422 oldImageBk
= SetBkColor( hImageDC
, RGB( 0xff, 0xff, 0xff ) );
1424 has_alpha
= himl
->item_flags
[pimldp
->i
] & ILIF_ALPHA
;
1425 if (!bMask
&& (has_alpha
|| (fState
& ILS_ALPHA
) || (fState
& ILS_SATURATE
)))
1427 COLORREF colour
, blend_col
= CLR_NONE
;
1432 blend_col
= pimldp
->rgbFg
;
1433 if (blend_col
== CLR_DEFAULT
) blend_col
= GetSysColor( COLOR_HIGHLIGHT
);
1434 else if (blend_col
== CLR_NONE
) blend_col
= GetTextColor( pimldp
->hdcDst
);
1437 func
.BlendOp
= AC_SRC_OVER
;
1438 func
.BlendFlags
= 0;
1439 func
.SourceConstantAlpha
= (fState
& ILS_ALPHA
) ? pimldp
->Frame
: 255;
1440 func
.AlphaFormat
= AC_SRC_ALPHA
;
1444 bResult
= alpha_blend_image( himl
, pimldp
->hdcDst
, pimldp
->x
, pimldp
->y
, pt
.x
, pt
.y
, cx
, cy
,
1445 func
, fStyle
, blend_col
, has_alpha
, fState
& ILS_SATURATE
);
1448 colour
= pimldp
->rgbBk
;
1449 if (colour
== CLR_DEFAULT
) colour
= himl
->clrBk
;
1450 if (colour
== CLR_NONE
) colour
= GetBkColor( pimldp
->hdcDst
);
1452 hOldBrush
= SelectObject (hImageDC
, CreateSolidBrush (colour
));
1453 PatBlt( hImageDC
, 0, 0, cx
, cy
, PATCOPY
);
1454 alpha_blend_image( himl
, hImageDC
, 0, 0, pt
.x
, pt
.y
, cx
, cy
, func
,
1455 fStyle
, blend_col
, has_alpha
, fState
& ILS_SATURATE
);
1456 DeleteObject (SelectObject (hImageDC
, hOldBrush
));
1457 bResult
= BitBlt( pimldp
->hdcDst
, pimldp
->x
, pimldp
->y
, cx
, cy
, hImageDC
, 0, 0, SRCCOPY
);
1462 * Draw the initial image
1465 if (himl
->hbmMask
) {
1466 hOldBrush
= SelectObject (hImageDC
, CreateSolidBrush (GetTextColor(pimldp
->hdcDst
)));
1467 PatBlt( hImageDC
, 0, 0, cx
, cy
, PATCOPY
);
1468 BitBlt(hImageDC
, 0, 0, cx
, cy
, hMaskListDC
, pt
.x
, pt
.y
, SRCPAINT
);
1469 DeleteObject (SelectObject (hImageDC
, hOldBrush
));
1470 if( bIsTransparent
)
1472 BitBlt ( pimldp
->hdcDst
, pimldp
->x
, pimldp
->y
, cx
, cy
, hImageDC
, 0, 0, SRCAND
);
1477 hOldBrush
= SelectObject (hImageDC
, GetStockObject(BLACK_BRUSH
));
1478 PatBlt( hImageDC
, 0, 0, cx
, cy
, PATCOPY
);
1479 SelectObject(hImageDC
, hOldBrush
);
1482 /* blend the image with the needed solid background */
1483 COLORREF colour
= RGB(0,0,0);
1485 if( !bIsTransparent
)
1487 colour
= pimldp
->rgbBk
;
1488 if( colour
== CLR_DEFAULT
)
1489 colour
= himl
->clrBk
;
1490 if( colour
== CLR_NONE
)
1491 colour
= GetBkColor(pimldp
->hdcDst
);
1494 hOldBrush
= SelectObject (hImageDC
, CreateSolidBrush (colour
));
1495 PatBlt( hImageDC
, 0, 0, cx
, cy
, PATCOPY
);
1498 BitBlt( hImageDC
, 0, 0, cx
, cy
, hMaskListDC
, pt
.x
, pt
.y
, SRCAND
);
1499 BitBlt( hImageDC
, 0, 0, cx
, cy
, hImageListDC
, pt
.x
, pt
.y
, SRCPAINT
);
1502 BitBlt( hImageDC
, 0, 0, cx
, cy
, hImageListDC
, pt
.x
, pt
.y
, SRCCOPY
);
1503 DeleteObject (SelectObject (hImageDC
, hOldBrush
));
1506 /* Time for blending, if required */
1509 COLORREF clrBlend
= pimldp
->rgbFg
;
1510 HDC hBlendMaskDC
= hImageListDC
;
1513 /* Create the blend Mask */
1514 hOldBitmap
= SelectObject(hBlendMaskDC
, hBlendMaskBmp
);
1515 hBlendBrush
= fStyle
& ILD_BLEND50
? himl
->hbrBlend50
: himl
->hbrBlend25
;
1516 hOldBrush
= SelectObject(hBlendMaskDC
, hBlendBrush
);
1517 PatBlt(hBlendMaskDC
, 0, 0, cx
, cy
, PATCOPY
);
1518 SelectObject(hBlendMaskDC
, hOldBrush
);
1520 /* Modify the blend mask if an Image Mask exist */
1522 BitBlt(hBlendMaskDC
, 0, 0, cx
, cy
, hMaskListDC
, pt
.x
, pt
.y
, 0x220326); /* NOTSRCAND */
1523 BitBlt(hBlendMaskDC
, 0, 0, cx
, cy
, hBlendMaskDC
, 0, 0, NOTSRCCOPY
);
1526 /* now apply blend to the current image given the BlendMask */
1527 if (clrBlend
== CLR_DEFAULT
) clrBlend
= GetSysColor (COLOR_HIGHLIGHT
);
1528 else if (clrBlend
== CLR_NONE
) clrBlend
= GetTextColor (pimldp
->hdcDst
);
1529 hOldBrush
= SelectObject (hImageDC
, CreateSolidBrush(clrBlend
));
1530 BitBlt (hImageDC
, 0, 0, cx
, cy
, hBlendMaskDC
, 0, 0, 0xB8074A); /* PSDPxax */
1531 DeleteObject(SelectObject(hImageDC
, hOldBrush
));
1532 SelectObject(hBlendMaskDC
, hOldBitmap
);
1535 /* Now do the overlay image, if any */
1536 nOvlIdx
= (pimldp
->fStyle
& ILD_OVERLAYMASK
) >> 8;
1537 if ( (nOvlIdx
>= 1) && (nOvlIdx
<= MAX_OVERLAYIMAGE
)) {
1538 nOvlIdx
= himl
->nOvlIdx
[nOvlIdx
- 1];
1539 if ((nOvlIdx
>= 0) && (nOvlIdx
< himl
->cCurImage
)) {
1541 imagelist_point_from_index( himl
, nOvlIdx
, &ptOvl
);
1542 ptOvl
.x
+= pimldp
->xBitmap
;
1543 if (himl
->hbmMask
&& !(fStyle
& ILD_IMAGE
))
1544 BitBlt (hImageDC
, 0, 0, cx
, cy
, hMaskListDC
, ptOvl
.x
, ptOvl
.y
, SRCAND
);
1545 BitBlt (hImageDC
, 0, 0, cx
, cy
, hImageListDC
, ptOvl
.x
, ptOvl
.y
, SRCPAINT
);
1549 if (fState
& ILS_GLOW
) FIXME("ILS_GLOW: unimplemented!\n");
1550 if (fState
& ILS_SHADOW
) FIXME("ILS_SHADOW: unimplemented!\n");
1552 if (fStyle
& ILD_PRESERVEALPHA
) FIXME("ILD_PRESERVEALPHA: unimplemented!\n");
1553 if (fStyle
& ILD_SCALE
) FIXME("ILD_SCALE: unimplemented!\n");
1554 if (fStyle
& ILD_DPISCALE
) FIXME("ILD_DPISCALE: unimplemented!\n");
1556 /* now copy the image to the screen */
1558 if (himl
->hbmMask
&& bIsTransparent
) {
1559 COLORREF oldDstFg
= SetTextColor(pimldp
->hdcDst
, RGB( 0, 0, 0 ) );
1560 COLORREF oldDstBk
= SetBkColor(pimldp
->hdcDst
, RGB( 0xff, 0xff, 0xff ));
1561 BitBlt (pimldp
->hdcDst
, pimldp
->x
, pimldp
->y
, cx
, cy
, hMaskListDC
, pt
.x
, pt
.y
, SRCAND
);
1562 SetBkColor(pimldp
->hdcDst
, oldDstBk
);
1563 SetTextColor(pimldp
->hdcDst
, oldDstFg
);
1566 if (fStyle
& ILD_ROP
) dwRop
= pimldp
->dwRop
;
1567 BitBlt (pimldp
->hdcDst
, pimldp
->x
, pimldp
->y
, cx
, cy
, hImageDC
, 0, 0, dwRop
);
1571 /* cleanup the mess */
1572 SetBkColor(hImageDC
, oldImageBk
);
1573 SetTextColor(hImageDC
, oldImageFg
);
1574 SelectObject(hImageDC
, hOldImageBmp
);
1576 DeleteObject(hBlendMaskBmp
);
1577 DeleteObject(hImageBmp
);
1584 /*************************************************************************
1585 * ImageList_Duplicate [COMCTL32.@]
1587 * Duplicates an image list.
1590 * himlSrc [I] source image list handle
1593 * Success: Handle of duplicated image list.
1598 ImageList_Duplicate (HIMAGELIST himlSrc
)
1602 if (!is_valid(himlSrc
)) {
1603 ERR("Invalid image list handle!\n");
1607 himlDst
= ImageList_Create (himlSrc
->cx
, himlSrc
->cy
, himlSrc
->flags
,
1608 himlSrc
->cCurImage
, himlSrc
->cGrow
);
1614 imagelist_get_bitmap_size(himlSrc
, himlSrc
->cCurImage
, &sz
);
1615 BitBlt (himlDst
->hdcImage
, 0, 0, sz
.cx
, sz
.cy
,
1616 himlSrc
->hdcImage
, 0, 0, SRCCOPY
);
1618 if (himlDst
->hbmMask
)
1619 BitBlt (himlDst
->hdcMask
, 0, 0, sz
.cx
, sz
.cy
,
1620 himlSrc
->hdcMask
, 0, 0, SRCCOPY
);
1622 himlDst
->cCurImage
= himlSrc
->cCurImage
;
1623 memcpy( himlDst
->item_flags
, himlSrc
->item_flags
, himlDst
->cCurImage
* sizeof(*himlDst
->item_flags
) );
1629 /*************************************************************************
1630 * ImageList_EndDrag [COMCTL32.@]
1632 * Finishes a drag operation.
1643 ImageList_EndDrag (void)
1645 /* cleanup the InternalDrag struct */
1646 InternalDrag
.hwnd
= 0;
1647 if (InternalDrag
.himl
!= InternalDrag
.himlNoCursor
)
1648 ImageList_Destroy (InternalDrag
.himlNoCursor
);
1649 ImageList_Destroy (InternalDrag
.himl
);
1650 InternalDrag
.himlNoCursor
= InternalDrag
.himl
= 0;
1653 InternalDrag
.dxHotspot
= 0;
1654 InternalDrag
.dyHotspot
= 0;
1655 InternalDrag
.bShow
= FALSE
;
1656 DeleteObject(InternalDrag
.hbmBg
);
1657 InternalDrag
.hbmBg
= 0;
1661 /*************************************************************************
1662 * ImageList_GetBkColor [COMCTL32.@]
1664 * Returns the background color of an image list.
1667 * himl [I] Image list handle.
1670 * Success: background color
1675 ImageList_GetBkColor (HIMAGELIST himl
)
1677 return himl
? himl
->clrBk
: CLR_NONE
;
1681 /*************************************************************************
1682 * ImageList_GetDragImage [COMCTL32.@]
1684 * Returns the handle to the internal drag image list.
1687 * ppt [O] Pointer to the drag position. Can be NULL.
1688 * pptHotspot [O] Pointer to the position of the hot spot. Can be NULL.
1691 * Success: Handle of the drag image list.
1696 ImageList_GetDragImage (POINT
*ppt
, POINT
*pptHotspot
)
1698 if (is_valid(InternalDrag
.himl
)) {
1700 ppt
->x
= InternalDrag
.x
;
1701 ppt
->y
= InternalDrag
.y
;
1704 pptHotspot
->x
= InternalDrag
.dxHotspot
;
1705 pptHotspot
->y
= InternalDrag
.dyHotspot
;
1707 return (InternalDrag
.himl
);
1714 /*************************************************************************
1715 * ImageList_GetFlags [COMCTL32.@]
1717 * Gets the flags of the specified image list.
1720 * himl [I] Handle to image list
1730 ImageList_GetFlags(HIMAGELIST himl
)
1732 TRACE("%p\n", himl
);
1734 return is_valid(himl
) ? himl
->flags
: 0;
1738 /*************************************************************************
1739 * ImageList_GetIcon [COMCTL32.@]
1741 * Creates an icon from a masked image of an image list.
1744 * himl [I] handle to image list
1746 * flags [I] drawing style flags
1749 * Success: icon handle
1754 ImageList_GetIcon (HIMAGELIST himl
, INT i
, UINT fStyle
)
1758 HBITMAP hOldDstBitmap
;
1762 TRACE("%p %d %d\n", himl
, i
, fStyle
);
1763 if (!is_valid(himl
) || (i
< 0) || (i
>= himl
->cCurImage
)) return NULL
;
1769 /* create colour bitmap */
1771 ii
.hbmColor
= CreateCompatibleBitmap(hdcDst
, himl
->cx
, himl
->cy
);
1772 ReleaseDC(0, hdcDst
);
1774 hdcDst
= CreateCompatibleDC(0);
1776 imagelist_point_from_index( himl
, i
, &pt
);
1779 ii
.hbmMask
= CreateBitmap (himl
->cx
, himl
->cy
, 1, 1, NULL
);
1780 hOldDstBitmap
= SelectObject (hdcDst
, ii
.hbmMask
);
1781 if (himl
->hbmMask
) {
1782 BitBlt (hdcDst
, 0, 0, himl
->cx
, himl
->cy
,
1783 himl
->hdcMask
, pt
.x
, pt
.y
, SRCCOPY
);
1786 PatBlt (hdcDst
, 0, 0, himl
->cx
, himl
->cy
, BLACKNESS
);
1789 SelectObject (hdcDst
, ii
.hbmColor
);
1790 BitBlt (hdcDst
, 0, 0, himl
->cx
, himl
->cy
,
1791 himl
->hdcImage
, pt
.x
, pt
.y
, SRCCOPY
);
1794 * CreateIconIndirect requires us to deselect the bitmaps from
1795 * the DCs before calling
1797 SelectObject(hdcDst
, hOldDstBitmap
);
1799 hIcon
= CreateIconIndirect (&ii
);
1801 DeleteObject (ii
.hbmMask
);
1802 DeleteObject (ii
.hbmColor
);
1809 /*************************************************************************
1810 * ImageList_GetIconSize [COMCTL32.@]
1812 * Retrieves the size of an image in an image list.
1815 * himl [I] handle to image list
1816 * cx [O] pointer to the image width.
1817 * cy [O] pointer to the image height.
1824 * All images in an image list have the same size.
1828 ImageList_GetIconSize (HIMAGELIST himl
, INT
*cx
, INT
*cy
)
1830 if (!is_valid(himl
) || !cx
|| !cy
)
1840 /*************************************************************************
1841 * ImageList_GetImageCount [COMCTL32.@]
1843 * Returns the number of images in an image list.
1846 * himl [I] handle to image list
1849 * Success: Number of images.
1854 ImageList_GetImageCount (HIMAGELIST himl
)
1856 if (!is_valid(himl
))
1859 return himl
->cCurImage
;
1863 /*************************************************************************
1864 * ImageList_GetImageInfo [COMCTL32.@]
1866 * Returns information about an image in an image list.
1869 * himl [I] handle to image list
1871 * pImageInfo [O] pointer to the image information
1879 ImageList_GetImageInfo (HIMAGELIST himl
, INT i
, IMAGEINFO
*pImageInfo
)
1883 if (!is_valid(himl
) || (pImageInfo
== NULL
))
1885 if ((i
< 0) || (i
>= himl
->cCurImage
))
1888 pImageInfo
->hbmImage
= himl
->hbmImage
;
1889 pImageInfo
->hbmMask
= himl
->hbmMask
;
1891 imagelist_point_from_index( himl
, i
, &pt
);
1892 pImageInfo
->rcImage
.top
= pt
.y
;
1893 pImageInfo
->rcImage
.bottom
= pt
.y
+ himl
->cy
;
1894 pImageInfo
->rcImage
.left
= pt
.x
;
1895 pImageInfo
->rcImage
.right
= pt
.x
+ himl
->cx
;
1901 /*************************************************************************
1902 * ImageList_GetImageRect [COMCTL32.@]
1904 * Retrieves the rectangle of the specified image in an image list.
1907 * himl [I] handle to image list
1909 * lpRect [O] pointer to the image rectangle
1916 * This is an UNDOCUMENTED function!!!
1920 ImageList_GetImageRect (HIMAGELIST himl
, INT i
, LPRECT lpRect
)
1924 if (!is_valid(himl
) || (lpRect
== NULL
))
1926 if ((i
< 0) || (i
>= himl
->cCurImage
))
1929 imagelist_point_from_index( himl
, i
, &pt
);
1930 lpRect
->left
= pt
.x
;
1932 lpRect
->right
= pt
.x
+ himl
->cx
;
1933 lpRect
->bottom
= pt
.y
+ himl
->cy
;
1939 /*************************************************************************
1940 * ImageList_LoadImage [COMCTL32.@]
1941 * ImageList_LoadImageA [COMCTL32.@]
1943 * Creates an image list from a bitmap, icon or cursor.
1945 * See ImageList_LoadImageW.
1949 ImageList_LoadImageA (HINSTANCE hi
, LPCSTR lpbmp
, INT cx
, INT cGrow
,
1950 COLORREF clrMask
, UINT uType
, UINT uFlags
)
1956 if (IS_INTRESOURCE(lpbmp
))
1957 return ImageList_LoadImageW(hi
, (LPCWSTR
)lpbmp
, cx
, cGrow
, clrMask
,
1960 len
= MultiByteToWideChar(CP_ACP
, 0, lpbmp
, -1, NULL
, 0);
1961 lpbmpW
= heap_alloc(len
* sizeof(WCHAR
));
1962 MultiByteToWideChar(CP_ACP
, 0, lpbmp
, -1, lpbmpW
, len
);
1964 himl
= ImageList_LoadImageW(hi
, lpbmpW
, cx
, cGrow
, clrMask
, uType
, uFlags
);
1970 /*************************************************************************
1971 * ImageList_LoadImageW [COMCTL32.@]
1973 * Creates an image list from a bitmap, icon or cursor.
1976 * hi [I] instance handle
1977 * lpbmp [I] name or id of the image
1978 * cx [I] width of each image
1979 * cGrow [I] number of images to expand
1980 * clrMask [I] mask color
1981 * uType [I] type of image to load
1982 * uFlags [I] loading flags
1985 * Success: handle to the loaded image list
1993 ImageList_LoadImageW (HINSTANCE hi
, LPCWSTR lpbmp
, INT cx
, INT cGrow
,
1994 COLORREF clrMask
, UINT uType
, UINT uFlags
)
1996 HIMAGELIST himl
= NULL
;
2000 handle
= LoadImageW (hi
, lpbmp
, uType
, 0, 0, uFlags
);
2002 WARN("Couldn't load image\n");
2006 if (uType
== IMAGE_BITMAP
) {
2010 if (GetObjectW (handle
, sizeof(dib
), &dib
) == sizeof(BITMAP
)) color
= ILC_COLOR
;
2011 else color
= dib
.dsBm
.bmBitsPixel
;
2013 /* To match windows behavior, if cx is set to zero and
2014 the flag DI_DEFAULTSIZE is specified, cx becomes the
2015 system metric value for icons. If the flag is not specified
2016 the function sets the size to the height of the bitmap */
2019 if (uFlags
& DI_DEFAULTSIZE
)
2020 cx
= GetSystemMetrics (SM_CXICON
);
2022 cx
= dib
.dsBm
.bmHeight
;
2025 nImageCount
= dib
.dsBm
.bmWidth
/ cx
;
2027 if (clrMask
!= CLR_NONE
) color
|= ILC_MASK
;
2028 himl
= ImageList_Create (cx
, dib
.dsBm
.bmHeight
, color
, nImageCount
, cGrow
);
2030 DeleteObject (handle
);
2033 ImageList_AddMasked (himl
, handle
, clrMask
);
2035 else if ((uType
== IMAGE_ICON
) || (uType
== IMAGE_CURSOR
)) {
2039 GetIconInfo (handle
, &ii
);
2040 GetObjectW (ii
.hbmColor
, sizeof(BITMAP
), &bmp
);
2041 himl
= ImageList_Create (bmp
.bmWidth
, bmp
.bmHeight
,
2042 ILC_MASK
| ILC_COLOR
, 1, cGrow
);
2044 DeleteObject (ii
.hbmColor
);
2045 DeleteObject (ii
.hbmMask
);
2046 DeleteObject (handle
);
2049 ImageList_Add (himl
, ii
.hbmColor
, ii
.hbmMask
);
2050 DeleteObject (ii
.hbmColor
);
2051 DeleteObject (ii
.hbmMask
);
2054 DeleteObject (handle
);
2060 /*************************************************************************
2061 * ImageList_Merge [COMCTL32.@]
2063 * Create an image list containing a merged image from two image lists.
2066 * himl1 [I] handle to first image list
2067 * i1 [I] first image index
2068 * himl2 [I] handle to second image list
2069 * i2 [I] second image index
2070 * dx [I] X offset of the second image relative to the first.
2071 * dy [I] Y offset of the second image relative to the first.
2074 * Success: The newly created image list. It contains a single image
2075 * consisting of the second image merged with the first.
2076 * Failure: NULL, if either himl1 or himl2 is invalid.
2079 * - The returned image list should be deleted by the caller using
2080 * ImageList_Destroy() when it is no longer required.
2081 * - If either i1 or i2 is not a valid image index, they will be treated
2085 ImageList_Merge (HIMAGELIST himl1
, INT i1
, HIMAGELIST himl2
, INT i2
,
2088 HIMAGELIST himlDst
= NULL
;
2090 INT xOff1
, yOff1
, xOff2
, yOff2
;
2094 TRACE("(himl1=%p i1=%d himl2=%p i2=%d dx=%d dy=%d)\n", himl1
, i1
, himl2
,
2097 if (!is_valid(himl1
) || !is_valid(himl2
))
2101 cxDst
= max (himl1
->cx
, dx
+ himl2
->cx
);
2106 cxDst
= max (himl2
->cx
, himl1
->cx
- dx
);
2111 cxDst
= max (himl1
->cx
, himl2
->cx
);
2117 cyDst
= max (himl1
->cy
, dy
+ himl2
->cy
);
2122 cyDst
= max (himl2
->cy
, himl1
->cy
- dy
);
2127 cyDst
= max (himl1
->cy
, himl2
->cy
);
2132 newFlags
= (himl1
->flags
> himl2
->flags
? himl1
->flags
: himl2
->flags
) & ILC_COLORDDB
;
2133 if (newFlags
== ILC_COLORDDB
&& (himl1
->flags
& ILC_COLORDDB
) == ILC_COLOR16
)
2134 newFlags
= ILC_COLOR16
; /* this is what native (at least v5) does, don't know why */
2135 himlDst
= ImageList_Create (cxDst
, cyDst
, ILC_MASK
| newFlags
, 1, 1);
2139 imagelist_point_from_index( himl1
, i1
, &pt1
);
2140 imagelist_point_from_index( himl2
, i2
, &pt2
);
2143 BitBlt (himlDst
->hdcImage
, 0, 0, cxDst
, cyDst
, himl1
->hdcImage
, 0, 0, BLACKNESS
);
2144 if (i1
>= 0 && i1
< himl1
->cCurImage
)
2145 BitBlt (himlDst
->hdcImage
, xOff1
, yOff1
, himl1
->cx
, himl1
->cy
, himl1
->hdcImage
, pt1
.x
, pt1
.y
, SRCCOPY
);
2146 if (i2
>= 0 && i2
< himl2
->cCurImage
)
2148 if (himl2
->flags
& ILC_MASK
)
2150 BitBlt (himlDst
->hdcImage
, xOff2
, yOff2
, himl2
->cx
, himl2
->cy
, himl2
->hdcMask
, pt2
.x
, pt2
.y
, SRCAND
);
2151 BitBlt (himlDst
->hdcImage
, xOff2
, yOff2
, himl2
->cx
, himl2
->cy
, himl2
->hdcImage
, pt2
.x
, pt2
.y
, SRCPAINT
);
2154 BitBlt (himlDst
->hdcImage
, xOff2
, yOff2
, himl2
->cx
, himl2
->cy
, himl2
->hdcImage
, pt2
.x
, pt2
.y
, SRCCOPY
);
2158 BitBlt (himlDst
->hdcMask
, 0, 0, cxDst
, cyDst
, himl1
->hdcMask
, 0, 0, WHITENESS
);
2159 if (i1
>= 0 && i1
< himl1
->cCurImage
)
2160 BitBlt (himlDst
->hdcMask
, xOff1
, yOff1
, himl1
->cx
, himl1
->cy
, himl1
->hdcMask
, pt1
.x
, pt1
.y
, SRCCOPY
);
2161 if (i2
>= 0 && i2
< himl2
->cCurImage
)
2162 BitBlt (himlDst
->hdcMask
, xOff2
, yOff2
, himl2
->cx
, himl2
->cy
, himl2
->hdcMask
, pt2
.x
, pt2
.y
, SRCAND
);
2164 himlDst
->cCurImage
= 1;
2171 /* helper for ImageList_Read, see comments below */
2172 static void *read_bitmap(IStream
*pstm
, BITMAPINFO
*bmi
)
2174 BITMAPFILEHEADER bmfh
;
2175 int bitsperpixel
, palspace
;
2178 if (FAILED(IStream_Read ( pstm
, &bmfh
, sizeof(bmfh
), NULL
)))
2181 if (bmfh
.bfType
!= (('M'<<8)|'B'))
2184 if (FAILED(IStream_Read ( pstm
, &bmi
->bmiHeader
, sizeof(bmi
->bmiHeader
), NULL
)))
2187 if ((bmi
->bmiHeader
.biSize
!= sizeof(bmi
->bmiHeader
)))
2190 TRACE("width %u, height %u, planes %u, bpp %u\n",
2191 bmi
->bmiHeader
.biWidth
, bmi
->bmiHeader
.biHeight
,
2192 bmi
->bmiHeader
.biPlanes
, bmi
->bmiHeader
.biBitCount
);
2194 bitsperpixel
= bmi
->bmiHeader
.biPlanes
* bmi
->bmiHeader
.biBitCount
;
2195 if (bitsperpixel
<=8)
2196 palspace
= (1<<bitsperpixel
)*sizeof(RGBQUAD
);
2200 bmi
->bmiHeader
.biSizeImage
= get_dib_image_size( bmi
);
2202 /* read the palette right after the end of the bitmapinfoheader */
2203 if (palspace
&& FAILED(IStream_Read(pstm
, bmi
->bmiColors
, palspace
, NULL
)))
2206 bits
= heap_alloc_zero(bmi
->bmiHeader
.biSizeImage
);
2207 if (!bits
) return NULL
;
2209 if (FAILED(IStream_Read(pstm
, bits
, bmi
->bmiHeader
.biSizeImage
, NULL
)))
2217 /*************************************************************************
2218 * ImageList_Read [COMCTL32.@]
2220 * Reads an image list from a stream.
2223 * pstm [I] pointer to a stream
2226 * Success: handle to image list
2229 * The format is like this:
2230 * ILHEAD ilheadstruct;
2232 * for the color image part:
2233 * BITMAPFILEHEADER bmfh;
2234 * BITMAPINFOHEADER bmih;
2235 * only if it has a palette:
2236 * RGBQUAD rgbs[nr_of_paletted_colors];
2238 * BYTE colorbits[imagesize];
2240 * the following only if the ILC_MASK bit is set in ILHEAD.ilFlags:
2241 * BITMAPFILEHEADER bmfh_mask;
2242 * BITMAPINFOHEADER bmih_mask;
2243 * only if it has a palette (it usually does not):
2244 * RGBQUAD rgbs[nr_of_paletted_colors];
2246 * BYTE maskbits[imagesize];
2248 HIMAGELIST WINAPI
ImageList_Read(IStream
*pstm
)
2250 char image_buf
[sizeof(BITMAPINFOHEADER
) + sizeof(RGBQUAD
) * 256];
2251 char mask_buf
[sizeof(BITMAPINFOHEADER
) + sizeof(RGBQUAD
) * 256];
2252 BITMAPINFO
*image_info
= (BITMAPINFO
*)image_buf
;
2253 BITMAPINFO
*mask_info
= (BITMAPINFO
*)mask_buf
;
2254 void *image_bits
, *mask_bits
= NULL
;
2259 TRACE("%p\n", pstm
);
2261 if (FAILED(IStream_Read (pstm
, &ilHead
, sizeof(ILHEAD
), NULL
)))
2263 if (ilHead
.usMagic
!= (('L' << 8) | 'I'))
2265 if (ilHead
.usVersion
!= 0x101) /* probably version? */
2268 TRACE("cx %u, cy %u, flags 0x%04x, cCurImage %u, cMaxImage %u\n",
2269 ilHead
.cx
, ilHead
.cy
, ilHead
.flags
, ilHead
.cCurImage
, ilHead
.cMaxImage
);
2271 himl
= ImageList_Create(ilHead
.cx
, ilHead
.cy
, ilHead
.flags
, ilHead
.cMaxImage
, ilHead
.cGrow
);
2275 if (!(image_bits
= read_bitmap(pstm
, image_info
)))
2277 WARN("failed to read bitmap from stream\n");
2280 if (ilHead
.flags
& ILC_MASK
)
2282 if (!(mask_bits
= read_bitmap(pstm
, mask_info
)))
2284 WARN("failed to read mask bitmap from stream\n");
2288 else mask_info
= NULL
;
2290 if ((himl
->flags
& 0xfe) == ILC_COLOR32
&& image_info
->bmiHeader
.biBitCount
== 32)
2292 DWORD
*ptr
= image_bits
;
2293 BYTE
*mask_ptr
= mask_bits
;
2294 int stride
= himl
->cy
* image_info
->bmiHeader
.biWidth
;
2296 if (image_info
->bmiHeader
.biHeight
> 0) /* bottom-up */
2298 ptr
+= image_info
->bmiHeader
.biHeight
* image_info
->bmiHeader
.biWidth
- stride
;
2299 mask_ptr
+= (image_info
->bmiHeader
.biHeight
* image_info
->bmiHeader
.biWidth
- stride
) / 8;
2301 image_info
->bmiHeader
.biHeight
= himl
->cy
;
2303 else image_info
->bmiHeader
.biHeight
= -himl
->cy
;
2305 for (i
= 0; i
< ilHead
.cCurImage
; i
+= TILE_COUNT
)
2307 add_dib_bits( himl
, i
, min( ilHead
.cCurImage
- i
, TILE_COUNT
),
2308 himl
->cx
, himl
->cy
, image_info
, mask_info
, ptr
, mask_ptr
);
2310 mask_ptr
+= stride
/ 8;
2315 StretchDIBits( himl
->hdcImage
, 0, 0, image_info
->bmiHeader
.biWidth
, image_info
->bmiHeader
.biHeight
,
2316 0, 0, image_info
->bmiHeader
.biWidth
, image_info
->bmiHeader
.biHeight
,
2317 image_bits
, image_info
, DIB_RGB_COLORS
, SRCCOPY
);
2319 StretchDIBits( himl
->hdcMask
, 0, 0, mask_info
->bmiHeader
.biWidth
, mask_info
->bmiHeader
.biHeight
,
2320 0, 0, mask_info
->bmiHeader
.biWidth
, mask_info
->bmiHeader
.biHeight
,
2321 mask_bits
, mask_info
, DIB_RGB_COLORS
, SRCCOPY
);
2323 heap_free( image_bits
);
2324 heap_free( mask_bits
);
2326 himl
->cCurImage
= ilHead
.cCurImage
;
2327 himl
->cMaxImage
= ilHead
.cMaxImage
;
2329 ImageList_SetBkColor(himl
,ilHead
.bkcolor
);
2331 ImageList_SetOverlayImage(himl
,ilHead
.ovls
[i
],i
+1);
2336 /*************************************************************************
2337 * ImageList_Remove [COMCTL32.@]
2339 * Removes an image from an image list
2342 * himl [I] image list handle
2349 * FIXME: as the image list storage test shows, native comctl32 simply shifts
2350 * images without creating a new bitmap.
2353 ImageList_Remove (HIMAGELIST himl
, INT i
)
2355 HBITMAP hbmNewImage
, hbmNewMask
;
2359 TRACE("(himl=%p i=%d)\n", himl
, i
);
2361 if (!is_valid(himl
)) {
2362 ERR("Invalid image list handle!\n");
2366 if ((i
< -1) || (i
>= himl
->cCurImage
)) {
2367 TRACE("index out of range! %d\n", i
);
2375 if (himl
->cCurImage
== 0) {
2376 /* remove all on empty ImageList is allowed */
2377 TRACE("remove all on empty ImageList!\n");
2381 himl
->cMaxImage
= himl
->cGrow
;
2382 himl
->cCurImage
= 0;
2383 for (nCount
= 0; nCount
< MAX_OVERLAYIMAGE
; nCount
++)
2384 himl
->nOvlIdx
[nCount
] = -1;
2386 heap_free( himl
->item_flags
);
2387 himl
->item_flags
= heap_alloc_zero( himl
->cMaxImage
* sizeof(*himl
->item_flags
) );
2389 hbmNewImage
= ImageList_CreateImage(himl
->hdcImage
, himl
, himl
->cMaxImage
);
2390 SelectObject (himl
->hdcImage
, hbmNewImage
);
2391 DeleteObject (himl
->hbmImage
);
2392 himl
->hbmImage
= hbmNewImage
;
2394 if (himl
->hbmMask
) {
2396 imagelist_get_bitmap_size(himl
, himl
->cMaxImage
, &sz
);
2397 hbmNewMask
= CreateBitmap (sz
.cx
, sz
.cy
, 1, 1, NULL
);
2398 SelectObject (himl
->hdcMask
, hbmNewMask
);
2399 DeleteObject (himl
->hbmMask
);
2400 himl
->hbmMask
= hbmNewMask
;
2404 /* delete one image */
2405 TRACE("Remove single image! %d\n", i
);
2407 /* create new bitmap(s) */
2408 TRACE(" - Number of images: %d / %d (Old/New)\n",
2409 himl
->cCurImage
, himl
->cCurImage
- 1);
2411 hbmNewImage
= ImageList_CreateImage(himl
->hdcImage
, himl
, himl
->cMaxImage
);
2413 imagelist_get_bitmap_size(himl
, himl
->cMaxImage
, &sz
);
2415 hbmNewMask
= CreateBitmap (sz
.cx
, sz
.cy
, 1, 1, NULL
);
2417 hbmNewMask
= 0; /* Just to keep compiler happy! */
2419 hdcBmp
= CreateCompatibleDC (0);
2421 /* copy all images and masks prior to the "removed" image */
2423 TRACE("Pre image copy: Copy %d images\n", i
);
2425 SelectObject (hdcBmp
, hbmNewImage
);
2426 imagelist_copy_images( himl
, himl
->hdcImage
, hdcBmp
, 0, i
, 0 );
2428 if (himl
->hbmMask
) {
2429 SelectObject (hdcBmp
, hbmNewMask
);
2430 imagelist_copy_images( himl
, himl
->hdcMask
, hdcBmp
, 0, i
, 0 );
2434 /* copy all images and masks behind the removed image */
2435 if (i
< himl
->cCurImage
- 1) {
2436 TRACE("Post image copy!\n");
2438 SelectObject (hdcBmp
, hbmNewImage
);
2439 imagelist_copy_images( himl
, himl
->hdcImage
, hdcBmp
, i
+ 1,
2440 (himl
->cCurImage
- i
), i
);
2442 if (himl
->hbmMask
) {
2443 SelectObject (hdcBmp
, hbmNewMask
);
2444 imagelist_copy_images( himl
, himl
->hdcMask
, hdcBmp
, i
+ 1,
2445 (himl
->cCurImage
- i
), i
);
2451 /* delete old images and insert new ones */
2452 SelectObject (himl
->hdcImage
, hbmNewImage
);
2453 DeleteObject (himl
->hbmImage
);
2454 himl
->hbmImage
= hbmNewImage
;
2455 if (himl
->hbmMask
) {
2456 SelectObject (himl
->hdcMask
, hbmNewMask
);
2457 DeleteObject (himl
->hbmMask
);
2458 himl
->hbmMask
= hbmNewMask
;
2468 /*************************************************************************
2469 * ImageList_Replace [COMCTL32.@]
2471 * Replaces an image in an image list with a new image.
2474 * himl [I] handle to image list
2476 * hbmImage [I] handle to image bitmap
2477 * hbmMask [I] handle to mask bitmap. Can be NULL.
2485 ImageList_Replace (HIMAGELIST himl
, INT i
, HBITMAP hbmImage
,
2492 TRACE("%p %d %p %p\n", himl
, i
, hbmImage
, hbmMask
);
2494 if (!is_valid(himl
)) {
2495 ERR("Invalid image list handle!\n");
2499 if ((i
>= himl
->cMaxImage
) || (i
< 0)) {
2500 ERR("Invalid image index!\n");
2504 if (!GetObjectW(hbmImage
, sizeof(BITMAP
), &bmp
))
2507 hdcImage
= CreateCompatibleDC (0);
2510 SelectObject (hdcImage
, hbmImage
);
2512 if (add_with_alpha( himl
, hdcImage
, i
, 1, bmp
.bmWidth
, bmp
.bmHeight
, hbmImage
, hbmMask
))
2515 imagelist_point_from_index(himl
, i
, &pt
);
2516 StretchBlt (himl
->hdcImage
, pt
.x
, pt
.y
, himl
->cx
, himl
->cy
,
2517 hdcImage
, 0, 0, bmp
.bmWidth
, bmp
.bmHeight
, SRCCOPY
);
2522 HBITMAP hOldBitmapTemp
;
2524 hdcTemp
= CreateCompatibleDC(0);
2525 hOldBitmapTemp
= SelectObject(hdcTemp
, hbmMask
);
2527 StretchBlt (himl
->hdcMask
, pt
.x
, pt
.y
, himl
->cx
, himl
->cy
,
2528 hdcTemp
, 0, 0, bmp
.bmWidth
, bmp
.bmHeight
, SRCCOPY
);
2529 SelectObject(hdcTemp
, hOldBitmapTemp
);
2532 /* Remove the background from the image
2534 BitBlt (himl
->hdcImage
, pt
.x
, pt
.y
, bmp
.bmWidth
, bmp
.bmHeight
,
2535 himl
->hdcMask
, pt
.x
, pt
.y
, 0x220326); /* NOTSRCAND */
2539 DeleteDC (hdcImage
);
2545 /*************************************************************************
2546 * ImageList_ReplaceIcon [COMCTL32.@]
2548 * Replaces an image in an image list using an icon.
2551 * himl [I] handle to image list
2553 * hIcon [I] handle to icon
2556 * Success: index of the replaced image
2561 ImageList_ReplaceIcon (HIMAGELIST himl
, INT nIndex
, HICON hIcon
)
2569 TRACE("(%p %d %p)\n", himl
, nIndex
, hIcon
);
2571 if (!is_valid(himl
)) {
2572 ERR("invalid image list\n");
2575 if ((nIndex
>= himl
->cMaxImage
) || (nIndex
< -1)) {
2576 ERR("invalid image index %d / %d\n", nIndex
, himl
->cMaxImage
);
2580 hBestFitIcon
= CopyImage(
2583 LR_COPYFROMRESOURCE
);
2584 /* the above will fail if the icon wasn't loaded from a resource, so try
2585 * again without LR_COPYFROMRESOURCE flag */
2587 hBestFitIcon
= CopyImage(
2595 if (himl
->cCurImage
+ 1 >= himl
->cMaxImage
)
2596 IMAGELIST_InternalExpandBitmaps(himl
, 1);
2598 nIndex
= himl
->cCurImage
;
2602 if ((himl
->flags
& 0xfe) == ILC_COLOR32
&& GetIconInfo (hBestFitIcon
, &ii
))
2604 HDC hdcImage
= CreateCompatibleDC( 0 );
2605 GetObjectW (ii
.hbmMask
, sizeof(BITMAP
), &bmp
);
2609 UINT height
= bmp
.bmHeight
/ 2;
2610 HDC hdcMask
= CreateCompatibleDC( 0 );
2611 HBITMAP color
= CreateBitmap( bmp
.bmWidth
, height
, 1, 1, NULL
);
2612 SelectObject( hdcImage
, color
);
2613 SelectObject( hdcMask
, ii
.hbmMask
);
2614 BitBlt( hdcImage
, 0, 0, bmp
.bmWidth
, height
, hdcMask
, 0, height
, SRCCOPY
);
2615 ret
= add_with_alpha( himl
, hdcImage
, nIndex
, 1, bmp
.bmWidth
, height
, color
, ii
.hbmMask
);
2616 DeleteDC( hdcMask
);
2617 DeleteObject( color
);
2619 else ret
= add_with_alpha( himl
, hdcImage
, nIndex
, 1, bmp
.bmWidth
, bmp
.bmHeight
,
2620 ii
.hbmColor
, ii
.hbmMask
);
2622 DeleteDC( hdcImage
);
2623 DeleteObject (ii
.hbmMask
);
2624 if (ii
.hbmColor
) DeleteObject (ii
.hbmColor
);
2628 imagelist_point_from_index(himl
, nIndex
, &pt
);
2632 DrawIconEx( himl
->hdcImage
, pt
.x
, pt
.y
, hBestFitIcon
, himl
->cx
, himl
->cy
, 0, 0, DI_IMAGE
);
2633 PatBlt( himl
->hdcMask
, pt
.x
, pt
.y
, himl
->cx
, himl
->cy
, WHITENESS
);
2634 DrawIconEx( himl
->hdcMask
, pt
.x
, pt
.y
, hBestFitIcon
, himl
->cx
, himl
->cy
, 0, 0, DI_MASK
);
2638 COLORREF color
= himl
->clrBk
!= CLR_NONE
? himl
->clrBk
: comctl32_color
.clrWindow
;
2639 HBRUSH brush
= CreateSolidBrush( GetNearestColor( himl
->hdcImage
, color
));
2641 SelectObject( himl
->hdcImage
, brush
);
2642 PatBlt( himl
->hdcImage
, pt
.x
, pt
.y
, himl
->cx
, himl
->cy
, PATCOPY
);
2643 SelectObject( himl
->hdcImage
, GetStockObject(BLACK_BRUSH
) );
2644 DeleteObject( brush
);
2645 DrawIconEx( himl
->hdcImage
, pt
.x
, pt
.y
, hBestFitIcon
, himl
->cx
, himl
->cy
, 0, 0, DI_NORMAL
);
2649 DestroyIcon(hBestFitIcon
);
2651 TRACE("Insert index = %d, himl->cCurImage = %d\n", nIndex
, himl
->cCurImage
);
2656 /*************************************************************************
2657 * ImageList_SetBkColor [COMCTL32.@]
2659 * Sets the background color of an image list.
2662 * himl [I] handle to image list
2663 * clrBk [I] background color
2666 * Success: previous background color
2671 ImageList_SetBkColor (HIMAGELIST himl
, COLORREF clrBk
)
2675 if (!is_valid(himl
))
2678 clrOldBk
= himl
->clrBk
;
2679 himl
->clrBk
= clrBk
;
2684 /*************************************************************************
2685 * ImageList_SetDragCursorImage [COMCTL32.@]
2687 * Combines the specified image with the current drag image
2690 * himlDrag [I] handle to drag image list
2691 * iDrag [I] drag image index
2692 * dxHotspot [I] X position of the hot spot
2693 * dyHotspot [I] Y position of the hot spot
2700 * - The names dxHotspot, dyHotspot are misleading because they have nothing
2701 * to do with a hotspot but are only the offset of the origin of the new
2702 * image relative to the origin of the old image.
2704 * - When this function is called and the drag image is visible, a
2705 * short flickering occurs but this matches the Win9x behavior. It is
2706 * possible to fix the flickering using code like in ImageList_DragMove.
2710 ImageList_SetDragCursorImage (HIMAGELIST himlDrag
, INT iDrag
,
2711 INT dxHotspot
, INT dyHotspot
)
2713 HIMAGELIST himlTemp
;
2716 if (!is_valid(InternalDrag
.himl
) || !is_valid(himlDrag
))
2719 TRACE(" dxH=%d dyH=%d nX=%d nY=%d\n",
2720 dxHotspot
, dyHotspot
, InternalDrag
.dxHotspot
, InternalDrag
.dyHotspot
);
2722 visible
= InternalDrag
.bShow
;
2724 himlTemp
= ImageList_Merge (InternalDrag
.himlNoCursor
, 0, himlDrag
, iDrag
,
2725 dxHotspot
, dyHotspot
);
2728 /* hide the drag image */
2729 ImageList_DragShowNolock(FALSE
);
2731 if ((InternalDrag
.himl
->cx
!= himlTemp
->cx
) ||
2732 (InternalDrag
.himl
->cy
!= himlTemp
->cy
)) {
2733 /* the size of the drag image changed, invalidate the buffer */
2734 DeleteObject(InternalDrag
.hbmBg
);
2735 InternalDrag
.hbmBg
= 0;
2738 if (InternalDrag
.himl
!= InternalDrag
.himlNoCursor
)
2739 ImageList_Destroy (InternalDrag
.himl
);
2740 InternalDrag
.himl
= himlTemp
;
2743 /* show the drag image */
2744 ImageList_DragShowNolock(TRUE
);
2751 /*************************************************************************
2752 * ImageList_SetFilter [COMCTL32.@]
2754 * Sets a filter (or does something completely different)!!???
2755 * It removes 12 Bytes from the stack (3 Parameters).
2758 * himl [I] SHOULD be a handle to image list
2759 * i [I] COULD be an index?
2764 * Failure: FALSE ???
2767 * This is an UNDOCUMENTED function!!!!
2772 ImageList_SetFilter (HIMAGELIST himl
, INT i
, DWORD dwFilter
)
2774 FIXME("(%p 0x%x 0x%x):empty stub!\n", himl
, i
, dwFilter
);
2780 /*************************************************************************
2781 * ImageList_SetFlags [COMCTL32.@]
2783 * Sets the image list flags.
2786 * himl [I] Handle to image list
2787 * flags [I] Flags to set
2797 ImageList_SetFlags(HIMAGELIST himl
, DWORD flags
)
2799 FIXME("(%p %08x):empty stub\n", himl
, flags
);
2804 /*************************************************************************
2805 * ImageList_SetIconSize [COMCTL32.@]
2807 * Sets the image size of the bitmap and deletes all images.
2810 * himl [I] handle to image list
2811 * cx [I] image width
2812 * cy [I] image height
2820 ImageList_SetIconSize (HIMAGELIST himl
, INT cx
, INT cy
)
2825 if (!is_valid(himl
))
2828 /* remove all images */
2829 himl
->cMaxImage
= himl
->cInitial
+ 1;
2830 himl
->cCurImage
= 0;
2834 /* initialize overlay mask indices */
2835 for (nCount
= 0; nCount
< MAX_OVERLAYIMAGE
; nCount
++)
2836 himl
->nOvlIdx
[nCount
] = -1;
2838 hbmNew
= ImageList_CreateImage(himl
->hdcImage
, himl
, himl
->cMaxImage
);
2839 SelectObject (himl
->hdcImage
, hbmNew
);
2840 DeleteObject (himl
->hbmImage
);
2841 himl
->hbmImage
= hbmNew
;
2843 if (himl
->hbmMask
) {
2845 imagelist_get_bitmap_size(himl
, himl
->cMaxImage
, &sz
);
2846 hbmNew
= CreateBitmap (sz
.cx
, sz
.cy
, 1, 1, NULL
);
2847 SelectObject (himl
->hdcMask
, hbmNew
);
2848 DeleteObject (himl
->hbmMask
);
2849 himl
->hbmMask
= hbmNew
;
2856 /*************************************************************************
2857 * ImageList_SetImageCount [COMCTL32.@]
2859 * Resizes an image list to the specified number of images.
2862 * himl [I] handle to image list
2863 * iImageCount [I] number of images in the image list
2871 ImageList_SetImageCount (HIMAGELIST himl
, UINT iImageCount
)
2874 HBITMAP hbmNewBitmap
, hbmOld
;
2875 INT nNewCount
, nCopyCount
;
2877 TRACE("%p %d\n",himl
,iImageCount
);
2879 if (!is_valid(himl
))
2882 nNewCount
= iImageCount
+ 1;
2883 nCopyCount
= min(himl
->cCurImage
, iImageCount
);
2885 hdcBitmap
= CreateCompatibleDC (0);
2887 hbmNewBitmap
= ImageList_CreateImage(hdcBitmap
, himl
, nNewCount
);
2889 if (hbmNewBitmap
!= 0)
2891 hbmOld
= SelectObject (hdcBitmap
, hbmNewBitmap
);
2892 imagelist_copy_images( himl
, himl
->hdcImage
, hdcBitmap
, 0, nCopyCount
, 0 );
2893 SelectObject (hdcBitmap
, hbmOld
);
2895 /* FIXME: delete 'empty' image space? */
2897 SelectObject (himl
->hdcImage
, hbmNewBitmap
);
2898 DeleteObject (himl
->hbmImage
);
2899 himl
->hbmImage
= hbmNewBitmap
;
2902 ERR("Could not create new image bitmap!\n");
2907 imagelist_get_bitmap_size( himl
, nNewCount
, &sz
);
2908 hbmNewBitmap
= CreateBitmap (sz
.cx
, sz
.cy
, 1, 1, NULL
);
2909 if (hbmNewBitmap
!= 0)
2911 hbmOld
= SelectObject (hdcBitmap
, hbmNewBitmap
);
2912 imagelist_copy_images( himl
, himl
->hdcMask
, hdcBitmap
, 0, nCopyCount
, 0 );
2913 SelectObject (hdcBitmap
, hbmOld
);
2915 /* FIXME: delete 'empty' image space? */
2917 SelectObject (himl
->hdcMask
, hbmNewBitmap
);
2918 DeleteObject (himl
->hbmMask
);
2919 himl
->hbmMask
= hbmNewBitmap
;
2922 ERR("Could not create new mask bitmap!\n");
2925 DeleteDC (hdcBitmap
);
2927 himl
->item_flags
= HeapReAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, himl
->item_flags
,
2928 nNewCount
* sizeof(*himl
->item_flags
));
2930 /* Update max image count and current image count */
2931 himl
->cMaxImage
= nNewCount
;
2932 himl
->cCurImage
= iImageCount
;
2938 /*************************************************************************
2939 * ImageList_SetOverlayImage [COMCTL32.@]
2941 * Assigns an overlay mask index to an existing image in an image list.
2944 * himl [I] handle to image list
2945 * iImage [I] image index
2946 * iOverlay [I] overlay mask index
2954 ImageList_SetOverlayImage (HIMAGELIST himl
, INT iImage
, INT iOverlay
)
2956 if (!is_valid(himl
))
2958 if ((iOverlay
< 1) || (iOverlay
> MAX_OVERLAYIMAGE
))
2960 if ((iImage
!=-1) && ((iImage
< 0) || (iImage
> himl
->cCurImage
)))
2962 himl
->nOvlIdx
[iOverlay
- 1] = iImage
;
2968 /* helper for ImageList_Write - write bitmap to pstm
2969 * currently everything is written as 24 bit RGB, except masks
2971 static BOOL
_write_bitmap(HBITMAP hBitmap
, IStream
*pstm
)
2973 LPBITMAPFILEHEADER bmfh
;
2974 LPBITMAPINFOHEADER bmih
;
2975 LPBYTE data
= NULL
, lpBits
;
2977 INT bitCount
, sizeImage
, offBits
, totalSize
;
2979 BOOL result
= FALSE
;
2981 if (!GetObjectW(hBitmap
, sizeof(BITMAP
), &bm
))
2984 bitCount
= bm
.bmBitsPixel
;
2985 sizeImage
= get_dib_stride(bm
.bmWidth
, bitCount
) * bm
.bmHeight
;
2987 totalSize
= sizeof(BITMAPFILEHEADER
) + sizeof(BITMAPINFOHEADER
);
2989 totalSize
+= (1 << bitCount
) * sizeof(RGBQUAD
);
2990 offBits
= totalSize
;
2991 totalSize
+= sizeImage
;
2993 data
= heap_alloc_zero(totalSize
);
2994 bmfh
= (LPBITMAPFILEHEADER
)data
;
2995 bmih
= (LPBITMAPINFOHEADER
)(data
+ sizeof(BITMAPFILEHEADER
));
2996 lpBits
= data
+ offBits
;
2998 /* setup BITMAPFILEHEADER */
2999 bmfh
->bfType
= (('M' << 8) | 'B');
3000 bmfh
->bfSize
= offBits
;
3001 bmfh
->bfReserved1
= 0;
3002 bmfh
->bfReserved2
= 0;
3003 bmfh
->bfOffBits
= offBits
;
3005 /* setup BITMAPINFOHEADER */
3006 bmih
->biSize
= sizeof(BITMAPINFOHEADER
);
3007 bmih
->biWidth
= bm
.bmWidth
;
3008 bmih
->biHeight
= bm
.bmHeight
;
3010 bmih
->biBitCount
= bitCount
;
3011 bmih
->biCompression
= BI_RGB
;
3012 bmih
->biSizeImage
= sizeImage
;
3013 bmih
->biXPelsPerMeter
= 0;
3014 bmih
->biYPelsPerMeter
= 0;
3015 bmih
->biClrUsed
= 0;
3016 bmih
->biClrImportant
= 0;
3019 result
= GetDIBits(xdc
, hBitmap
, 0, bm
.bmHeight
, lpBits
, (BITMAPINFO
*)bmih
, DIB_RGB_COLORS
) == bm
.bmHeight
;
3024 TRACE("width %u, height %u, planes %u, bpp %u\n",
3025 bmih
->biWidth
, bmih
->biHeight
,
3026 bmih
->biPlanes
, bmih
->biBitCount
);
3028 if(FAILED(IStream_Write(pstm
, data
, totalSize
, NULL
)))
3040 /*************************************************************************
3041 * ImageList_Write [COMCTL32.@]
3043 * Writes an image list to a stream.
3046 * himl [I] handle to image list
3047 * pstm [O] Pointer to a stream.
3057 BOOL WINAPI
ImageList_Write(HIMAGELIST himl
, IStream
*pstm
)
3062 TRACE("%p %p\n", himl
, pstm
);
3064 if (!is_valid(himl
))
3067 ilHead
.usMagic
= (('L' << 8) | 'I');
3068 ilHead
.usVersion
= 0x101;
3069 ilHead
.cCurImage
= himl
->cCurImage
;
3070 ilHead
.cMaxImage
= himl
->cMaxImage
;
3071 ilHead
.cGrow
= himl
->cGrow
;
3072 ilHead
.cx
= himl
->cx
;
3073 ilHead
.cy
= himl
->cy
;
3074 ilHead
.bkcolor
= himl
->clrBk
;
3075 ilHead
.flags
= himl
->flags
;
3076 for(i
= 0; i
< 4; i
++) {
3077 ilHead
.ovls
[i
] = himl
->nOvlIdx
[i
];
3080 TRACE("cx %u, cy %u, flags 0x04%x, cCurImage %u, cMaxImage %u\n",
3081 ilHead
.cx
, ilHead
.cy
, ilHead
.flags
, ilHead
.cCurImage
, ilHead
.cMaxImage
);
3083 if(FAILED(IStream_Write(pstm
, &ilHead
, sizeof(ILHEAD
), NULL
)))
3086 /* write the bitmap */
3087 if(!_write_bitmap(himl
->hbmImage
, pstm
))
3090 /* write the mask if we have one */
3091 if(himl
->flags
& ILC_MASK
) {
3092 if(!_write_bitmap(himl
->hbmMask
, pstm
))
3100 static HBITMAP
ImageList_CreateImage(HDC hdc
, HIMAGELIST himl
, UINT count
)
3102 HBITMAP hbmNewBitmap
;
3103 UINT ilc
= (himl
->flags
& 0xFE);
3106 imagelist_get_bitmap_size( himl
, count
, &sz
);
3108 if ((ilc
>= ILC_COLOR4
&& ilc
<= ILC_COLOR32
) || ilc
== ILC_COLOR
)
3110 char buffer
[sizeof(BITMAPINFOHEADER
) + 256 * sizeof(RGBQUAD
)];
3111 BITMAPINFO
*bmi
= (BITMAPINFO
*)buffer
;
3113 TRACE("Creating DIBSection %d x %d, %d Bits per Pixel\n",
3114 sz
.cx
, sz
.cy
, himl
->uBitsPixel
);
3116 memset( buffer
, 0, sizeof(buffer
) );
3117 bmi
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
3118 bmi
->bmiHeader
.biWidth
= sz
.cx
;
3119 bmi
->bmiHeader
.biHeight
= sz
.cy
;
3120 bmi
->bmiHeader
.biPlanes
= 1;
3121 bmi
->bmiHeader
.biBitCount
= himl
->uBitsPixel
;
3122 bmi
->bmiHeader
.biCompression
= BI_RGB
;
3124 if (himl
->uBitsPixel
<= ILC_COLOR8
)
3126 if (!himl
->color_table_set
)
3128 /* retrieve the default color map */
3129 HBITMAP tmp
= CreateBitmap( 1, 1, 1, 1, NULL
);
3130 GetDIBits( hdc
, tmp
, 0, 0, NULL
, bmi
, DIB_RGB_COLORS
);
3131 DeleteObject( tmp
);
3132 if (ilc
== ILC_COLOR4
)
3135 tmp
= bmi
->bmiColors
[7];
3136 bmi
->bmiColors
[7] = bmi
->bmiColors
[8];
3137 bmi
->bmiColors
[8] = tmp
;
3142 GetDIBColorTable(himl
->hdcImage
, 0, 1 << himl
->uBitsPixel
, bmi
->bmiColors
);
3145 hbmNewBitmap
= CreateDIBSection(hdc
, bmi
, DIB_RGB_COLORS
, NULL
, 0, 0);
3147 else /*if (ilc == ILC_COLORDDB)*/
3149 TRACE("Creating Bitmap: %d Bits per Pixel\n", himl
->uBitsPixel
);
3151 hbmNewBitmap
= CreateBitmap (sz
.cx
, sz
.cy
, 1, himl
->uBitsPixel
, NULL
);
3153 TRACE("returning %p\n", hbmNewBitmap
);
3154 return hbmNewBitmap
;
3157 /*************************************************************************
3158 * ImageList_SetColorTable [COMCTL32.@]
3160 * Sets the color table of an image list.
3163 * himl [I] Handle to the image list.
3164 * uStartIndex [I] The first index to set.
3165 * cEntries [I] Number of entries to set.
3166 * prgb [I] New color information for color table for the image list.
3169 * Success: Number of entries in the table that were set.
3173 * ImageList_Create(), SetDIBColorTable()
3177 ImageList_SetColorTable(HIMAGELIST himl
, UINT uStartIndex
, UINT cEntries
, const RGBQUAD
*prgb
)
3179 TRACE("(%p, %d, %d, %p)\n", himl
, uStartIndex
, cEntries
, prgb
);
3180 himl
->color_table_set
= TRUE
;
3181 return SetDIBColorTable(himl
->hdcImage
, uStartIndex
, cEntries
, prgb
);
3184 /*************************************************************************
3185 * ImageList_CoCreateInstance [COMCTL32.@]
3187 * Creates a new imagelist instance and returns an interface pointer to it.
3190 * rclsid [I] A reference to the CLSID (CLSID_ImageList).
3191 * punkOuter [I] Pointer to IUnknown interface for aggregation, if desired
3192 * riid [I] Identifier of the requested interface.
3193 * ppv [O] Returns the address of the pointer requested, or NULL.
3197 * Failure: Error value.
3200 ImageList_CoCreateInstance (REFCLSID rclsid
, const IUnknown
*punkOuter
, REFIID riid
, void **ppv
)
3202 TRACE("(%s,%p,%s,%p)\n", debugstr_guid(rclsid
), punkOuter
, debugstr_guid(riid
), ppv
);
3204 if (!IsEqualCLSID(&CLSID_ImageList
, rclsid
))
3205 return E_NOINTERFACE
;
3207 return ImageListImpl_CreateInstance(punkOuter
, riid
, ppv
);
3211 /*************************************************************************
3212 * IImageList implementation
3215 static HRESULT WINAPI
ImageListImpl_QueryInterface(IImageList2
*iface
,
3216 REFIID iid
, void **ppv
)
3218 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3220 TRACE("(%p,%s,%p)\n", iface
, debugstr_guid(iid
), ppv
);
3222 if (!ppv
) return E_INVALIDARG
;
3224 if (IsEqualIID(&IID_IUnknown
, iid
) ||
3225 IsEqualIID(&IID_IImageList
, iid
) ||
3226 IsEqualIID(&IID_IImageList2
, iid
))
3228 *ppv
= &imgl
->IImageList2_iface
;
3233 return E_NOINTERFACE
;
3236 IImageList2_AddRef(iface
);
3240 static ULONG WINAPI
ImageListImpl_AddRef(IImageList2
*iface
)
3242 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3243 ULONG ref
= InterlockedIncrement(&imgl
->ref
);
3245 TRACE("(%p) refcount=%u\n", iface
, ref
);
3249 static ULONG WINAPI
ImageListImpl_Release(IImageList2
*iface
)
3251 HIMAGELIST This
= impl_from_IImageList2(iface
);
3252 ULONG ref
= InterlockedDecrement(&This
->ref
);
3254 TRACE("(%p) refcount=%u\n", iface
, ref
);
3258 /* delete image bitmaps */
3259 if (This
->hbmImage
) DeleteObject (This
->hbmImage
);
3260 if (This
->hbmMask
) DeleteObject (This
->hbmMask
);
3262 /* delete image & mask DCs */
3263 if (This
->hdcImage
) DeleteDC (This
->hdcImage
);
3264 if (This
->hdcMask
) DeleteDC (This
->hdcMask
);
3266 /* delete blending brushes */
3267 if (This
->hbrBlend25
) DeleteObject (This
->hbrBlend25
);
3268 if (This
->hbrBlend50
) DeleteObject (This
->hbrBlend50
);
3270 This
->IImageList2_iface
.lpVtbl
= NULL
;
3271 heap_free(This
->item_flags
);
3278 static HRESULT WINAPI
ImageListImpl_Add(IImageList2
*iface
, HBITMAP hbmImage
,
3279 HBITMAP hbmMask
, int *pi
)
3281 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3287 ret
= ImageList_Add(imgl
, hbmImage
, hbmMask
);
3296 static HRESULT WINAPI
ImageListImpl_ReplaceIcon(IImageList2
*iface
, int i
,
3297 HICON hicon
, int *pi
)
3299 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3305 ret
= ImageList_ReplaceIcon(imgl
, i
, hicon
);
3314 static HRESULT WINAPI
ImageListImpl_SetOverlayImage(IImageList2
*iface
,
3315 int iImage
, int iOverlay
)
3317 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3318 return ImageList_SetOverlayImage(imgl
, iImage
, iOverlay
) ? S_OK
: E_FAIL
;
3321 static HRESULT WINAPI
ImageListImpl_Replace(IImageList2
*iface
, int i
,
3322 HBITMAP hbmImage
, HBITMAP hbmMask
)
3324 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3325 return ImageList_Replace(imgl
, i
, hbmImage
, hbmMask
) ? S_OK
: E_FAIL
;
3328 static HRESULT WINAPI
ImageListImpl_AddMasked(IImageList2
*iface
, HBITMAP hbmImage
,
3329 COLORREF crMask
, int *pi
)
3331 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3337 ret
= ImageList_AddMasked(imgl
, hbmImage
, crMask
);
3346 static HRESULT WINAPI
ImageListImpl_Draw(IImageList2
*iface
,
3347 IMAGELISTDRAWPARAMS
*pimldp
)
3349 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3350 HIMAGELIST old_himl
;
3353 /* As far as I can tell, Windows simply ignores the contents of pimldp->himl
3354 so we shall simulate the same */
3355 old_himl
= pimldp
->himl
;
3356 pimldp
->himl
= imgl
;
3358 ret
= ImageList_DrawIndirect(pimldp
);
3360 pimldp
->himl
= old_himl
;
3361 return ret
? S_OK
: E_INVALIDARG
;
3364 static HRESULT WINAPI
ImageListImpl_Remove(IImageList2
*iface
, int i
)
3366 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3367 return (ImageList_Remove(imgl
, i
) == 0) ? E_INVALIDARG
: S_OK
;
3370 static HRESULT WINAPI
ImageListImpl_GetIcon(IImageList2
*iface
, int i
, UINT flags
,
3373 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3379 hIcon
= ImageList_GetIcon(imgl
, i
, flags
);
3388 static HRESULT WINAPI
ImageListImpl_GetImageInfo(IImageList2
*iface
, int i
,
3389 IMAGEINFO
*pImageInfo
)
3391 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3392 return ImageList_GetImageInfo(imgl
, i
, pImageInfo
) ? S_OK
: E_FAIL
;
3395 static HRESULT WINAPI
ImageListImpl_Copy(IImageList2
*iface
, int dst_index
,
3396 IUnknown
*unk_src
, int src_index
, UINT flags
)
3398 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3399 IImageList
*src
= NULL
;
3405 /* TODO: Add test for IID_ImageList2 too */
3406 if (FAILED(IUnknown_QueryInterface(unk_src
, &IID_IImageList
,
3410 if (ImageList_Copy(imgl
, dst_index
, (HIMAGELIST
) src
, src_index
, flags
))
3415 IImageList_Release(src
);
3419 static HRESULT WINAPI
ImageListImpl_Merge(IImageList2
*iface
, int i1
,
3420 IUnknown
*punk2
, int i2
, int dx
, int dy
, REFIID riid
, void **ppv
)
3422 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3423 IImageList
*iml2
= NULL
;
3425 HRESULT ret
= E_FAIL
;
3427 TRACE("(%p)->(%d %p %d %d %d %s %p)\n", iface
, i1
, punk2
, i2
, dx
, dy
, debugstr_guid(riid
), ppv
);
3429 /* TODO: Add test for IID_ImageList2 too */
3430 if (FAILED(IUnknown_QueryInterface(punk2
, &IID_IImageList
,
3434 merged
= ImageList_Merge(imgl
, i1
, (HIMAGELIST
) iml2
, i2
, dx
, dy
);
3436 /* Get the interface for the new image list */
3439 ret
= HIMAGELIST_QueryInterface(merged
, riid
, ppv
);
3440 ImageList_Destroy(merged
);
3443 IImageList_Release(iml2
);
3447 static HRESULT WINAPI
ImageListImpl_Clone(IImageList2
*iface
, REFIID riid
, void **ppv
)
3449 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3451 HRESULT ret
= E_FAIL
;
3453 TRACE("(%p)->(%s %p)\n", iface
, debugstr_guid(riid
), ppv
);
3455 clone
= ImageList_Duplicate(imgl
);
3457 /* Get the interface for the new image list */
3460 ret
= HIMAGELIST_QueryInterface(clone
, riid
, ppv
);
3461 ImageList_Destroy(clone
);
3467 static HRESULT WINAPI
ImageListImpl_GetImageRect(IImageList2
*iface
, int i
,
3470 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3476 if (!ImageList_GetImageInfo(imgl
, i
, &info
))
3479 *prc
= info
.rcImage
;
3484 static HRESULT WINAPI
ImageListImpl_GetIconSize(IImageList2
*iface
, int *cx
,
3487 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3488 return ImageList_GetIconSize(imgl
, cx
, cy
) ? S_OK
: E_INVALIDARG
;
3491 static HRESULT WINAPI
ImageListImpl_SetIconSize(IImageList2
*iface
, int cx
,
3494 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3495 return ImageList_SetIconSize(imgl
, cx
, cy
) ? S_OK
: E_FAIL
;
3498 static HRESULT WINAPI
ImageListImpl_GetImageCount(IImageList2
*iface
, int *pi
)
3500 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3501 *pi
= ImageList_GetImageCount(imgl
);
3505 static HRESULT WINAPI
ImageListImpl_SetImageCount(IImageList2
*iface
, UINT count
)
3507 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3508 return ImageList_SetImageCount(imgl
, count
) ? S_OK
: E_FAIL
;
3511 static HRESULT WINAPI
ImageListImpl_SetBkColor(IImageList2
*iface
, COLORREF clrBk
,
3514 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3515 *pclr
= ImageList_SetBkColor(imgl
, clrBk
);
3519 static HRESULT WINAPI
ImageListImpl_GetBkColor(IImageList2
*iface
, COLORREF
*pclr
)
3521 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3522 *pclr
= ImageList_GetBkColor(imgl
);
3526 static HRESULT WINAPI
ImageListImpl_BeginDrag(IImageList2
*iface
, int iTrack
,
3527 int dxHotspot
, int dyHotspot
)
3529 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3530 return ImageList_BeginDrag(imgl
, iTrack
, dxHotspot
, dyHotspot
) ? S_OK
: E_FAIL
;
3533 static HRESULT WINAPI
ImageListImpl_EndDrag(IImageList2
*iface
)
3535 ImageList_EndDrag();
3539 static HRESULT WINAPI
ImageListImpl_DragEnter(IImageList2
*iface
, HWND hwndLock
,
3542 return ImageList_DragEnter(hwndLock
, x
, y
) ? S_OK
: E_FAIL
;
3545 static HRESULT WINAPI
ImageListImpl_DragLeave(IImageList2
*iface
, HWND hwndLock
)
3547 return ImageList_DragLeave(hwndLock
) ? S_OK
: E_FAIL
;
3550 static HRESULT WINAPI
ImageListImpl_DragMove(IImageList2
*iface
, int x
, int y
)
3552 return ImageList_DragMove(x
, y
) ? S_OK
: E_FAIL
;
3555 static HRESULT WINAPI
ImageListImpl_SetDragCursorImage(IImageList2
*iface
,
3556 IUnknown
*punk
, int iDrag
, int dxHotspot
, int dyHotspot
)
3558 IImageList
*iml2
= NULL
;
3564 /* TODO: Add test for IID_ImageList2 too */
3565 if (FAILED(IUnknown_QueryInterface(punk
, &IID_IImageList
,
3569 ret
= ImageList_SetDragCursorImage((HIMAGELIST
) iml2
, iDrag
, dxHotspot
,
3572 IImageList_Release(iml2
);
3574 return ret
? S_OK
: E_FAIL
;
3577 static HRESULT WINAPI
ImageListImpl_DragShowNolock(IImageList2
*iface
, BOOL fShow
)
3579 return ImageList_DragShowNolock(fShow
) ? S_OK
: E_FAIL
;
3582 static HRESULT WINAPI
ImageListImpl_GetDragImage(IImageList2
*iface
, POINT
*ppt
,
3583 POINT
*pptHotspot
, REFIID riid
, PVOID
*ppv
)
3585 HRESULT ret
= E_FAIL
;
3591 hNew
= ImageList_GetDragImage(ppt
, pptHotspot
);
3593 /* Get the interface for the new image list */
3596 IImageList
*idrag
= (IImageList
*)hNew
;
3598 ret
= HIMAGELIST_QueryInterface(hNew
, riid
, ppv
);
3599 IImageList_Release(idrag
);
3605 static HRESULT WINAPI
ImageListImpl_GetItemFlags(IImageList2
*iface
, int i
, DWORD
*flags
)
3607 HIMAGELIST This
= impl_from_IImageList2(iface
);
3609 if (i
< 0 || i
>= This
->cCurImage
)
3610 return E_INVALIDARG
;
3612 *flags
= This
->item_flags
[i
];
3617 static HRESULT WINAPI
ImageListImpl_GetOverlayImage(IImageList2
*iface
, int iOverlay
,
3620 HIMAGELIST This
= impl_from_IImageList2(iface
);
3623 if ((iOverlay
< 0) || (iOverlay
> This
->cCurImage
))
3626 for (i
= 0; i
< MAX_OVERLAYIMAGE
; i
++)
3628 if (This
->nOvlIdx
[i
] == iOverlay
)
3638 static HRESULT WINAPI
ImageListImpl_Resize(IImageList2
*iface
, INT cx
, INT cy
)
3640 FIXME("(%p)->(%d %d): stub\n", iface
, cx
, cy
);
3644 static HRESULT WINAPI
ImageListImpl_GetOriginalSize(IImageList2
*iface
, INT image
, DWORD flags
, INT
*cx
, INT
*cy
)
3646 FIXME("(%p)->(%d %x %p %p): stub\n", iface
, image
, flags
, cx
, cy
);
3650 static HRESULT WINAPI
ImageListImpl_SetOriginalSize(IImageList2
*iface
, INT image
, INT cx
, INT cy
)
3652 FIXME("(%p)->(%d %d %d): stub\n", iface
, image
, cx
, cy
);
3656 static HRESULT WINAPI
ImageListImpl_SetCallback(IImageList2
*iface
, IUnknown
*callback
)
3658 FIXME("(%p)->(%p): stub\n", iface
, callback
);
3662 static HRESULT WINAPI
ImageListImpl_GetCallback(IImageList2
*iface
, REFIID riid
, void **ppv
)
3664 FIXME("(%p)->(%s %p): stub\n", iface
, debugstr_guid(riid
), ppv
);
3668 static HRESULT WINAPI
ImageListImpl_ForceImagePresent(IImageList2
*iface
, INT image
, DWORD flags
)
3670 FIXME("(%p)->(%d %x): stub\n", iface
, image
, flags
);
3674 static HRESULT WINAPI
ImageListImpl_DiscardImages(IImageList2
*iface
, INT first_image
, INT last_image
, DWORD flags
)
3676 FIXME("(%p)->(%d %d %x): stub\n", iface
, first_image
, last_image
, flags
);
3680 static HRESULT WINAPI
ImageListImpl_PreloadImages(IImageList2
*iface
, IMAGELISTDRAWPARAMS
*params
)
3682 FIXME("(%p)->(%p): stub\n", iface
, params
);
3686 static HRESULT WINAPI
ImageListImpl_GetStatistics(IImageList2
*iface
, IMAGELISTSTATS
*stats
)
3688 FIXME("(%p)->(%p): stub\n", iface
, stats
);
3692 static HRESULT WINAPI
ImageListImpl_Initialize(IImageList2
*iface
, INT cx
, INT cy
, UINT flags
, INT initial
, INT grow
)
3694 FIXME("(%p)->(%d %d %d %d %d): stub\n", iface
, cx
, cy
, flags
, initial
, grow
);
3698 static HRESULT WINAPI
ImageListImpl_Replace2(IImageList2
*iface
, INT i
, HBITMAP image
, HBITMAP mask
, IUnknown
*unk
, DWORD flags
)
3700 FIXME("(%p)->(%d %p %p %p %x): stub\n", iface
, i
, image
, mask
, unk
, flags
);
3704 static HRESULT WINAPI
ImageListImpl_ReplaceFromImageList(IImageList2
*iface
, INT i
, IImageList
*imagelist
, INT src
,
3705 IUnknown
*unk
, DWORD flags
)
3707 FIXME("(%p)->(%d %p %d %p %x): stub\n", iface
, i
, imagelist
, src
, unk
, flags
);
3711 static const IImageList2Vtbl ImageListImpl_Vtbl
= {
3712 ImageListImpl_QueryInterface
,
3713 ImageListImpl_AddRef
,
3714 ImageListImpl_Release
,
3716 ImageListImpl_ReplaceIcon
,
3717 ImageListImpl_SetOverlayImage
,
3718 ImageListImpl_Replace
,
3719 ImageListImpl_AddMasked
,
3721 ImageListImpl_Remove
,
3722 ImageListImpl_GetIcon
,
3723 ImageListImpl_GetImageInfo
,
3725 ImageListImpl_Merge
,
3726 ImageListImpl_Clone
,
3727 ImageListImpl_GetImageRect
,
3728 ImageListImpl_GetIconSize
,
3729 ImageListImpl_SetIconSize
,
3730 ImageListImpl_GetImageCount
,
3731 ImageListImpl_SetImageCount
,
3732 ImageListImpl_SetBkColor
,
3733 ImageListImpl_GetBkColor
,
3734 ImageListImpl_BeginDrag
,
3735 ImageListImpl_EndDrag
,
3736 ImageListImpl_DragEnter
,
3737 ImageListImpl_DragLeave
,
3738 ImageListImpl_DragMove
,
3739 ImageListImpl_SetDragCursorImage
,
3740 ImageListImpl_DragShowNolock
,
3741 ImageListImpl_GetDragImage
,
3742 ImageListImpl_GetItemFlags
,
3743 ImageListImpl_GetOverlayImage
,
3744 ImageListImpl_Resize
,
3745 ImageListImpl_GetOriginalSize
,
3746 ImageListImpl_SetOriginalSize
,
3747 ImageListImpl_SetCallback
,
3748 ImageListImpl_GetCallback
,
3749 ImageListImpl_ForceImagePresent
,
3750 ImageListImpl_DiscardImages
,
3751 ImageListImpl_PreloadImages
,
3752 ImageListImpl_GetStatistics
,
3753 ImageListImpl_Initialize
,
3754 ImageListImpl_Replace2
,
3755 ImageListImpl_ReplaceFromImageList
3758 static BOOL
is_valid(HIMAGELIST himl
)
3763 valid
= himl
&& himl
->IImageList2_iface
.lpVtbl
== &ImageListImpl_Vtbl
;
3773 /*************************************************************************
3774 * HIMAGELIST_QueryInterface [COMCTL32.@]
3776 * Returns a pointer to an IImageList or IImageList2 object for the given
3780 * himl [I] Image list handle.
3781 * riid [I] Identifier of the requested interface.
3782 * ppv [O] Returns the address of the pointer requested, or NULL.
3786 * Failure: Error value.
3789 HIMAGELIST_QueryInterface (HIMAGELIST himl
, REFIID riid
, void **ppv
)
3791 TRACE("(%p,%s,%p)\n", himl
, debugstr_guid(riid
), ppv
);
3792 return IImageList2_QueryInterface((IImageList2
*) himl
, riid
, ppv
);
3795 static HRESULT
ImageListImpl_CreateInstance(const IUnknown
*pUnkOuter
, REFIID iid
, void** ppv
)
3800 TRACE("(%p,%s,%p)\n", pUnkOuter
, debugstr_guid(iid
), ppv
);
3804 if (pUnkOuter
) return CLASS_E_NOAGGREGATION
;
3806 This
= heap_alloc_zero(sizeof(struct _IMAGELIST
));
3807 if (!This
) return E_OUTOFMEMORY
;
3809 This
->IImageList2_iface
.lpVtbl
= &ImageListImpl_Vtbl
;
3812 ret
= IImageList2_QueryInterface(&This
->IImageList2_iface
, iid
, ppv
);
3813 IImageList2_Release(&This
->IImageList2_iface
);