2 * ImageList implementation
4 * Copyright 1998 Eric Kohl
5 * Copyright 2000 Jason Mawdsley
6 * Copyright 2001, 2004 Michael Stefaniuc
7 * Copyright 2001 Charles Loep for CodeWeavers
8 * Copyright 2002 Dimitrie O. Paun
9 * Copyright 2009 Owen Rudge for CodeWeavers
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public
13 * License as published by the Free Software Foundation; either
14 * version 2.1 of the License, or (at your option) any later version.
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with this library; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
27 * This code was audited for completeness against the documented features
28 * of Comctl32.dll version 6.0 on Sep. 12, 2002, by Dimitrie O. Paun.
30 * Unless otherwise noted, we believe this code to be complete, as per
31 * the specification mentioned above.
32 * If you discover missing features, or bugs, please note them below.
35 * - Add support for ILD_PRESERVEALPHA, ILD_SCALE, ILD_DPISCALE
36 * - Add support for ILS_GLOW, ILS_SHADOW
37 * - Thread-safe locking
42 #include <commoncontrols.h>
43 #include <wine/exception.h>
45 WINE_DEFAULT_DEBUG_CHANNEL(imagelist
);
47 #define MAX_OVERLAYIMAGE 15
51 IImageList2 IImageList2_iface
; /* 00: IImageList vtable */
52 INT cCurImage
; /* 04: ImageCount */
53 INT cMaxImage
; /* 08: maximages */
54 INT cGrow
; /* 0C: cGrow */
58 UINT flags
; /* 1C: flags */
59 COLORREF clrFg
; /* 20: foreground color */
60 COLORREF clrBk
; /* 24: background color */
63 HBITMAP hbmImage
; /* 28: images Bitmap */
64 HBITMAP hbmMask
; /* 2C: masks Bitmap */
65 HDC hdcImage
; /* 30: images MemDC */
66 HDC hdcMask
; /* 34: masks MemDC */
67 INT nOvlIdx
[MAX_OVERLAYIMAGE
]; /* 38: overlay images index */
69 /* not yet found out */
76 LONG ref
; /* reference count */
79 #define IMAGELIST_MAGIC 0x53414D58
81 /* Header used by ImageList_Read() and ImageList_Write() */
83 typedef struct _ILHEAD
98 /* internal image list data used for Drag & Drop operations */
103 HIMAGELIST himlNoCursor
;
104 /* position of the drag image relative to the window */
107 /* offset of the hotspot relative to the origin of the image */
110 /* is the drag image visible */
112 /* saved background */
116 static INTERNALDRAG InternalDrag
= { 0, 0, 0, 0, 0, 0, 0, FALSE
, 0 };
118 static inline HIMAGELIST
impl_from_IImageList2(IImageList2
*iface
)
120 return CONTAINING_RECORD(iface
, struct _IMAGELIST
, IImageList2_iface
);
123 static HBITMAP
ImageList_CreateImage(HDC hdc
, HIMAGELIST himl
, UINT count
);
124 static HRESULT
ImageListImpl_CreateInstance(const IUnknown
*pUnkOuter
, REFIID iid
, void** ppv
);
125 static BOOL
is_valid(HIMAGELIST himl
);
128 * An imagelist with N images is tiled like this:
140 static inline UINT
imagelist_height( UINT count
)
142 return ((count
+ TILE_COUNT
- 1)/TILE_COUNT
);
145 static inline void imagelist_point_from_index( HIMAGELIST himl
, UINT index
, LPPOINT pt
)
147 pt
->x
= (index
%TILE_COUNT
) * himl
->cx
;
148 pt
->y
= (index
/TILE_COUNT
) * himl
->cy
;
151 static inline void imagelist_get_bitmap_size( HIMAGELIST himl
, UINT count
, SIZE
*sz
)
153 sz
->cx
= himl
->cx
* TILE_COUNT
;
154 sz
->cy
= imagelist_height( count
) * himl
->cy
;
157 static inline int get_dib_stride( int width
, int bpp
)
159 return ((width
* bpp
+ 31) >> 3) & ~3;
162 static inline int get_dib_image_size( const BITMAPINFO
*info
)
164 return get_dib_stride( info
->bmiHeader
.biWidth
, info
->bmiHeader
.biBitCount
)
165 * abs( info
->bmiHeader
.biHeight
);
169 * imagelist_copy_images()
171 * Copies a block of count images from offset src in the list to offset dest.
172 * Images are copied a row at at time. Assumes hdcSrc and hdcDest are different.
174 static inline void imagelist_copy_images( HIMAGELIST himl
, HDC hdcSrc
, HDC hdcDest
,
175 UINT src
, UINT count
, UINT dest
)
181 for ( i
=0; i
<TILE_COUNT
; i
++ )
183 imagelist_point_from_index( himl
, src
+i
, &ptSrc
);
184 imagelist_point_from_index( himl
, dest
+i
, &ptDest
);
186 sz
.cy
= himl
->cy
* imagelist_height( count
- i
);
188 BitBlt( hdcDest
, ptDest
.x
, ptDest
.y
, sz
.cx
, sz
.cy
,
189 hdcSrc
, ptSrc
.x
, ptSrc
.y
, SRCCOPY
);
193 static void add_dib_bits( HIMAGELIST himl
, int pos
, int count
, int width
, int height
,
194 BITMAPINFO
*info
, BITMAPINFO
*mask_info
, DWORD
*bits
, BYTE
*mask_bits
)
198 int stride
= info
->bmiHeader
.biWidth
;
199 int mask_stride
= (info
->bmiHeader
.biWidth
+ 31) / 32 * 4;
201 for (n
= 0; n
< count
; n
++)
203 BOOL has_alpha
= FALSE
;
205 imagelist_point_from_index( himl
, pos
+ n
, &pt
);
207 /* check if bitmap has an alpha channel */
208 for (i
= 0; i
< height
&& !has_alpha
; i
++)
209 for (j
= n
* width
; j
< (n
+ 1) * width
; j
++)
210 if ((has_alpha
= ((bits
[i
* stride
+ j
] & 0xff000000) != 0))) break;
212 if (!has_alpha
) /* generate alpha channel from the mask */
214 for (i
= 0; i
< height
; i
++)
215 for (j
= n
* width
; j
< (n
+ 1) * width
; j
++)
216 if (!mask_info
|| !((mask_bits
[i
* mask_stride
+ j
/ 8] << (j
% 8)) & 0x80))
217 bits
[i
* stride
+ j
] |= 0xff000000;
219 bits
[i
* stride
+ j
] = 0;
223 himl
->has_alpha
[pos
+ n
] = 1;
225 if (mask_info
&& himl
->hbmMask
) /* generate the mask from the alpha channel */
227 for (i
= 0; i
< height
; i
++)
228 for (j
= n
* width
; j
< (n
+ 1) * width
; j
++)
229 if ((bits
[i
* stride
+ j
] >> 24) > 25) /* more than 10% alpha */
230 mask_bits
[i
* mask_stride
+ j
/ 8] &= ~(0x80 >> (j
% 8));
232 mask_bits
[i
* mask_stride
+ j
/ 8] |= 0x80 >> (j
% 8);
235 StretchDIBits( himl
->hdcImage
, pt
.x
, pt
.y
, himl
->cx
, himl
->cy
,
236 n
* width
, 0, width
, height
, bits
, info
, DIB_RGB_COLORS
, SRCCOPY
);
238 StretchDIBits( himl
->hdcMask
, pt
.x
, pt
.y
, himl
->cx
, himl
->cy
,
239 n
* width
, 0, width
, height
, mask_bits
, mask_info
, DIB_RGB_COLORS
, SRCCOPY
);
243 /* add images with an alpha channel when the image list is 32 bpp */
244 static BOOL
add_with_alpha( HIMAGELIST himl
, HDC hdc
, int pos
, int count
,
245 int width
, int height
, HBITMAP hbmImage
, HBITMAP hbmMask
)
249 BITMAPINFO
*info
, *mask_info
= NULL
;
251 BYTE
*mask_bits
= NULL
;
254 if (!GetObjectW( hbmImage
, sizeof(bm
), &bm
)) return FALSE
;
256 /* if either the imagelist or the source bitmap don't have an alpha channel, bail out now */
257 if (!himl
->has_alpha
) return FALSE
;
258 if (bm
.bmBitsPixel
!= 32) return FALSE
;
260 SelectObject( hdc
, hbmImage
);
261 mask_width
= (bm
.bmWidth
+ 31) / 32 * 4;
263 if (!(info
= HeapAlloc( GetProcessHeap(), 0, FIELD_OFFSET( BITMAPINFO
, bmiColors
[256] )))) goto done
;
264 info
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
265 info
->bmiHeader
.biWidth
= bm
.bmWidth
;
266 info
->bmiHeader
.biHeight
= -height
;
267 info
->bmiHeader
.biPlanes
= 1;
268 info
->bmiHeader
.biBitCount
= 32;
269 info
->bmiHeader
.biCompression
= BI_RGB
;
270 info
->bmiHeader
.biSizeImage
= bm
.bmWidth
* height
* 4;
271 info
->bmiHeader
.biXPelsPerMeter
= 0;
272 info
->bmiHeader
.biYPelsPerMeter
= 0;
273 info
->bmiHeader
.biClrUsed
= 0;
274 info
->bmiHeader
.biClrImportant
= 0;
275 if (!(bits
= HeapAlloc( GetProcessHeap(), 0, info
->bmiHeader
.biSizeImage
))) goto done
;
276 if (!GetDIBits( hdc
, hbmImage
, 0, height
, bits
, info
, DIB_RGB_COLORS
)) goto done
;
280 if (!(mask_info
= HeapAlloc( GetProcessHeap(), 0, FIELD_OFFSET( BITMAPINFO
, bmiColors
[2] ))))
282 mask_info
->bmiHeader
= info
->bmiHeader
;
283 mask_info
->bmiHeader
.biBitCount
= 1;
284 mask_info
->bmiHeader
.biSizeImage
= mask_width
* height
;
285 if (!(mask_bits
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, info
->bmiHeader
.biSizeImage
)))
287 if (!GetDIBits( hdc
, hbmMask
, 0, height
, mask_bits
, mask_info
, DIB_RGB_COLORS
)) goto done
;
290 add_dib_bits( himl
, pos
, count
, width
, height
, info
, mask_info
, bits
, mask_bits
);
294 HeapFree( GetProcessHeap(), 0, info
);
295 HeapFree( GetProcessHeap(), 0, mask_info
);
296 HeapFree( GetProcessHeap(), 0, bits
);
297 HeapFree( GetProcessHeap(), 0, mask_bits
);
301 /*************************************************************************
302 * IMAGELIST_InternalExpandBitmaps [Internal]
304 * Expands the bitmaps of an image list by the given number of images.
307 * himl [I] handle to image list
308 * nImageCount [I] number of images to add
314 * This function CANNOT be used to reduce the number of images.
317 IMAGELIST_InternalExpandBitmaps(HIMAGELIST himl
, INT nImageCount
)
320 HBITMAP hbmNewBitmap
, hbmNull
;
324 TRACE("%p has allocated %d, max %d, grow %d images\n", himl
, himl
->cCurImage
, himl
->cMaxImage
, himl
->cGrow
);
326 if (himl
->cCurImage
+ nImageCount
< himl
->cMaxImage
)
329 nNewCount
= himl
->cMaxImage
+ max(nImageCount
, himl
->cGrow
) + 1;
331 imagelist_get_bitmap_size(himl
, nNewCount
, &sz
);
333 TRACE("Create expanded bitmaps : himl=%p x=%d y=%d count=%d\n", himl
, sz
.cx
, sz
.cy
, nNewCount
);
334 hdcBitmap
= CreateCompatibleDC (0);
336 hbmNewBitmap
= ImageList_CreateImage(hdcBitmap
, himl
, nNewCount
);
338 if (hbmNewBitmap
== 0)
339 ERR("creating new image bitmap (x=%d y=%d)!\n", sz
.cx
, sz
.cy
);
343 hbmNull
= SelectObject (hdcBitmap
, hbmNewBitmap
);
344 BitBlt (hdcBitmap
, 0, 0, sz
.cx
, sz
.cy
,
345 himl
->hdcImage
, 0, 0, SRCCOPY
);
346 SelectObject (hdcBitmap
, hbmNull
);
348 SelectObject (himl
->hdcImage
, hbmNewBitmap
);
349 DeleteObject (himl
->hbmImage
);
350 himl
->hbmImage
= hbmNewBitmap
;
352 if (himl
->flags
& ILC_MASK
)
354 hbmNewBitmap
= CreateBitmap (sz
.cx
, sz
.cy
, 1, 1, NULL
);
356 if (hbmNewBitmap
== 0)
357 ERR("creating new mask bitmap!\n");
361 hbmNull
= SelectObject (hdcBitmap
, hbmNewBitmap
);
362 BitBlt (hdcBitmap
, 0, 0, sz
.cx
, sz
.cy
,
363 himl
->hdcMask
, 0, 0, SRCCOPY
);
364 SelectObject (hdcBitmap
, hbmNull
);
366 SelectObject (himl
->hdcMask
, hbmNewBitmap
);
367 DeleteObject (himl
->hbmMask
);
368 himl
->hbmMask
= hbmNewBitmap
;
373 char *new_alpha
= HeapReAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, himl
->has_alpha
, nNewCount
);
374 if (new_alpha
) himl
->has_alpha
= new_alpha
;
377 HeapFree( GetProcessHeap(), 0, himl
->has_alpha
);
378 himl
->has_alpha
= NULL
;
382 himl
->cMaxImage
= nNewCount
;
384 DeleteDC (hdcBitmap
);
388 /*************************************************************************
389 * ImageList_Add [COMCTL32.@]
391 * Add an image or images to an image list.
394 * himl [I] handle to image list
395 * hbmImage [I] handle to image bitmap
396 * hbmMask [I] handle to mask bitmap
399 * Success: Index of the first new image.
404 ImageList_Add (HIMAGELIST himl
, HBITMAP hbmImage
, HBITMAP hbmMask
)
406 HDC hdcBitmap
, hdcTemp
= 0;
407 INT nFirstIndex
, nImageCount
, i
;
411 TRACE("himl=%p hbmimage=%p hbmmask=%p\n", himl
, hbmImage
, hbmMask
);
415 if (!GetObjectW(hbmImage
, sizeof(BITMAP
), &bmp
))
418 TRACE("himl %p, cCurImage %d, cMaxImage %d, cGrow %d, cx %d, cy %d\n",
419 himl
, himl
->cCurImage
, himl
->cMaxImage
, himl
->cGrow
, himl
->cx
, himl
->cy
);
421 nImageCount
= bmp
.bmWidth
/ himl
->cx
;
423 TRACE("%p has %d images (%d x %d)\n", hbmImage
, nImageCount
, bmp
.bmWidth
, bmp
.bmHeight
);
425 IMAGELIST_InternalExpandBitmaps(himl
, nImageCount
);
427 hdcBitmap
= CreateCompatibleDC(0);
429 SelectObject(hdcBitmap
, hbmImage
);
431 if (add_with_alpha( himl
, hdcBitmap
, himl
->cCurImage
, nImageCount
,
432 himl
->cx
, min( himl
->cy
, bmp
.bmHeight
), hbmImage
, hbmMask
))
437 hdcTemp
= CreateCompatibleDC(0);
438 SelectObject(hdcTemp
, hbmMask
);
441 for (i
=0; i
<nImageCount
; i
++)
443 imagelist_point_from_index( himl
, himl
->cCurImage
+ i
, &pt
);
445 /* Copy result to the imagelist
447 BitBlt( himl
->hdcImage
, pt
.x
, pt
.y
, himl
->cx
, bmp
.bmHeight
,
448 hdcBitmap
, i
*himl
->cx
, 0, SRCCOPY
);
453 BitBlt( himl
->hdcMask
, pt
.x
, pt
.y
, himl
->cx
, bmp
.bmHeight
,
454 hdcTemp
, i
*himl
->cx
, 0, SRCCOPY
);
456 /* Remove the background from the image
458 BitBlt( himl
->hdcImage
, pt
.x
, pt
.y
, himl
->cx
, bmp
.bmHeight
,
459 himl
->hdcMask
, pt
.x
, pt
.y
, 0x220326 ); /* NOTSRCAND */
461 if (hdcTemp
) DeleteDC(hdcTemp
);
466 nFirstIndex
= himl
->cCurImage
;
467 himl
->cCurImage
+= nImageCount
;
473 /*************************************************************************
474 * ImageList_AddIcon [COMCTL32.@]
476 * Adds an icon to an image list.
479 * himl [I] handle to image list
480 * hIcon [I] handle to icon
483 * Success: index of the new image
486 #undef ImageList_AddIcon
487 INT WINAPI
ImageList_AddIcon (HIMAGELIST himl
, HICON hIcon
)
489 return ImageList_ReplaceIcon (himl
, -1, hIcon
);
493 /*************************************************************************
494 * ImageList_AddMasked [COMCTL32.@]
496 * Adds an image or images to an image list and creates a mask from the
497 * specified bitmap using the mask color.
500 * himl [I] handle to image list.
501 * hBitmap [I] handle to bitmap
502 * clrMask [I] mask color.
505 * Success: Index of the first new image.
510 ImageList_AddMasked (HIMAGELIST himl
, HBITMAP hBitmap
, COLORREF clrMask
)
512 HDC hdcMask
, hdcBitmap
;
518 TRACE("himl=%p hbitmap=%p clrmask=%x\n", himl
, hBitmap
, clrMask
);
522 if (!GetObjectW(hBitmap
, sizeof(BITMAP
), &bmp
))
525 hdcBitmap
= CreateCompatibleDC(0);
526 SelectObject(hdcBitmap
, hBitmap
);
528 /* Create a temp Mask so we can remove the background of the Image */
529 hdcMask
= CreateCompatibleDC(0);
530 hMaskBitmap
= CreateBitmap(bmp
.bmWidth
, bmp
.bmHeight
, 1, 1, NULL
);
531 SelectObject(hdcMask
, hMaskBitmap
);
533 /* create monochrome image to the mask bitmap */
534 bkColor
= (clrMask
!= CLR_DEFAULT
) ? clrMask
: GetPixel (hdcBitmap
, 0, 0);
535 SetBkColor (hdcBitmap
, bkColor
);
536 BitBlt (hdcMask
, 0, 0, bmp
.bmWidth
, bmp
.bmHeight
, hdcBitmap
, 0, 0, SRCCOPY
);
539 * Remove the background from the image
541 * WINDOWS BUG ALERT!!!!!!
542 * The statement below should not be done in common practice
543 * but this is how ImageList_AddMasked works in Windows.
544 * It overwrites the original bitmap passed, this was discovered
545 * by using the same bitmap to iterate the different styles
546 * on windows where it failed (BUT ImageList_Add is OK)
547 * This is here in case some apps rely on this bug
549 * Blt mode 0x220326 is NOTSRCAND
551 if (bmp
.bmBitsPixel
> 8) /* NOTSRCAND can't work with palettes */
553 SetBkColor(hdcBitmap
, RGB(255,255,255));
554 BitBlt(hdcBitmap
, 0, 0, bmp
.bmWidth
, bmp
.bmHeight
, hdcMask
, 0, 0, 0x220326);
560 ret
= ImageList_Add( himl
, hBitmap
, hMaskBitmap
);
562 DeleteObject(hMaskBitmap
);
567 /*************************************************************************
568 * ImageList_BeginDrag [COMCTL32.@]
570 * Creates a temporary image list that contains one image. It will be used
574 * himlTrack [I] handle to the source image list
575 * iTrack [I] index of the drag image in the source image list
576 * dxHotspot [I] X position of the hot spot of the drag image
577 * dyHotspot [I] Y position of the hot spot of the drag image
585 ImageList_BeginDrag (HIMAGELIST himlTrack
, INT iTrack
,
586 INT dxHotspot
, INT dyHotspot
)
590 TRACE("(himlTrack=%p iTrack=%d dx=%d dy=%d)\n", himlTrack
, iTrack
,
591 dxHotspot
, dyHotspot
);
593 if (!is_valid(himlTrack
))
596 if (InternalDrag
.himl
)
597 ImageList_EndDrag ();
602 InternalDrag
.himlNoCursor
= InternalDrag
.himl
= ImageList_Create (cx
, cy
, himlTrack
->flags
, 1, 1);
603 if (InternalDrag
.himl
== NULL
) {
604 WARN("Error creating drag image list!\n");
608 InternalDrag
.dxHotspot
= dxHotspot
;
609 InternalDrag
.dyHotspot
= dyHotspot
;
612 BitBlt (InternalDrag
.himl
->hdcImage
, 0, 0, cx
, cy
, himlTrack
->hdcImage
, iTrack
* cx
, 0, SRCCOPY
);
615 BitBlt (InternalDrag
.himl
->hdcMask
, 0, 0, cx
, cy
, himlTrack
->hdcMask
, iTrack
* cx
, 0, SRCCOPY
);
617 InternalDrag
.himl
->cCurImage
= 1;
623 /*************************************************************************
624 * ImageList_Copy [COMCTL32.@]
626 * Copies an image of the source image list to an image of the
627 * destination image list. Images can be copied or swapped.
630 * himlDst [I] handle to the destination image list
631 * iDst [I] destination image index.
632 * himlSrc [I] handle to the source image list
633 * iSrc [I] source image index
634 * uFlags [I] flags for the copy operation
641 * Copying from one image list to another is possible. The original
642 * implementation just copies or swaps within one image list.
643 * Could this feature become a bug??? ;-)
647 ImageList_Copy (HIMAGELIST himlDst
, INT iDst
, HIMAGELIST himlSrc
,
648 INT iSrc
, UINT uFlags
)
652 TRACE("himlDst=%p iDst=%d himlSrc=%p iSrc=%d\n", himlDst
, iDst
, himlSrc
, iSrc
);
654 if (!is_valid(himlSrc
) || !is_valid(himlDst
))
656 if ((iDst
< 0) || (iDst
>= himlDst
->cCurImage
))
658 if ((iSrc
< 0) || (iSrc
>= himlSrc
->cCurImage
))
661 imagelist_point_from_index( himlDst
, iDst
, &ptDst
);
662 imagelist_point_from_index( himlSrc
, iSrc
, &ptSrc
);
664 if (uFlags
& ILCF_SWAP
) {
667 HBITMAP hbmTempImage
, hbmTempMask
;
669 hdcBmp
= CreateCompatibleDC (0);
671 /* create temporary bitmaps */
672 hbmTempImage
= CreateBitmap (himlSrc
->cx
, himlSrc
->cy
, 1,
673 himlSrc
->uBitsPixel
, NULL
);
674 hbmTempMask
= CreateBitmap (himlSrc
->cx
, himlSrc
->cy
, 1,
677 /* copy (and stretch) destination to temporary bitmaps.(save) */
679 SelectObject (hdcBmp
, hbmTempImage
);
680 StretchBlt (hdcBmp
, 0, 0, himlSrc
->cx
, himlSrc
->cy
,
681 himlDst
->hdcImage
, ptDst
.x
, ptDst
.y
, himlDst
->cx
, himlDst
->cy
,
684 SelectObject (hdcBmp
, hbmTempMask
);
685 StretchBlt (hdcBmp
, 0, 0, himlSrc
->cx
, himlSrc
->cy
,
686 himlDst
->hdcMask
, ptDst
.x
, ptDst
.y
, himlDst
->cx
, himlDst
->cy
,
689 /* copy (and stretch) source to destination */
691 StretchBlt (himlDst
->hdcImage
, ptDst
.x
, ptDst
.y
, himlDst
->cx
, himlDst
->cy
,
692 himlSrc
->hdcImage
, ptSrc
.x
, ptSrc
.y
, himlSrc
->cx
, himlSrc
->cy
,
695 StretchBlt (himlDst
->hdcMask
, ptDst
.x
, ptDst
.y
, himlDst
->cx
, himlDst
->cy
,
696 himlSrc
->hdcMask
, ptSrc
.x
, ptSrc
.y
, himlSrc
->cx
, himlSrc
->cy
,
699 /* copy (without stretching) temporary bitmaps to source (restore) */
701 BitBlt (himlSrc
->hdcMask
, ptSrc
.x
, ptSrc
.y
, himlSrc
->cx
, himlSrc
->cy
,
702 hdcBmp
, 0, 0, SRCCOPY
);
705 BitBlt (himlSrc
->hdcImage
, ptSrc
.x
, ptSrc
.y
, himlSrc
->cx
, himlSrc
->cy
,
706 hdcBmp
, 0, 0, SRCCOPY
);
707 /* delete temporary bitmaps */
708 DeleteObject (hbmTempMask
);
709 DeleteObject (hbmTempImage
);
714 StretchBlt (himlDst
->hdcImage
, ptDst
.x
, ptDst
.y
, himlDst
->cx
, himlDst
->cy
,
715 himlSrc
->hdcImage
, ptSrc
.x
, ptSrc
.y
, himlSrc
->cx
, himlSrc
->cy
,
719 StretchBlt (himlDst
->hdcMask
, ptDst
.x
, ptDst
.y
, himlDst
->cx
, himlDst
->cy
,
720 himlSrc
->hdcMask
, ptSrc
.x
, ptSrc
.y
, himlSrc
->cx
, himlSrc
->cy
,
728 /*************************************************************************
729 * ImageList_Create [COMCTL32.@]
731 * Creates a new image list.
734 * cx [I] image height
736 * flags [I] creation flags
737 * cInitial [I] initial number of images in the image list
738 * cGrow [I] number of images by which image list grows
741 * Success: Handle to the created image list
745 ImageList_Create (INT cx
, INT cy
, UINT flags
,
746 INT cInitial
, INT cGrow
)
751 UINT ilc
= (flags
& 0xFE);
752 static const WORD aBitBlend25
[] =
753 {0xAA, 0x00, 0x55, 0x00, 0xAA, 0x00, 0x55, 0x00};
755 static const WORD aBitBlend50
[] =
756 {0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA};
758 TRACE("(%d %d 0x%x %d %d)\n", cx
, cy
, flags
, cInitial
, cGrow
);
760 if (cx
<= 0 || cy
<= 0) return NULL
;
762 /* Create the IImageList interface for the image list */
763 if (FAILED(ImageListImpl_CreateInstance(NULL
, &IID_IImageList
, (void **)&himl
)))
766 cGrow
= (WORD
)((max( cGrow
, 1 ) + 3) & ~3);
770 /* Windows doesn't limit the size here, but X11 doesn't let us allocate such huge bitmaps */
771 WARN( "grow %d too large, limiting to 256\n", cGrow
);
778 himl
->cMaxImage
= cInitial
+ 1;
779 himl
->cInitial
= cInitial
;
781 himl
->clrFg
= CLR_DEFAULT
;
782 himl
->clrBk
= CLR_NONE
;
784 /* initialize overlay mask indices */
785 for (nCount
= 0; nCount
< MAX_OVERLAYIMAGE
; nCount
++)
786 himl
->nOvlIdx
[nCount
] = -1;
788 /* Create Image & Mask DCs */
789 himl
->hdcImage
= CreateCompatibleDC (0);
792 if (himl
->flags
& ILC_MASK
){
793 himl
->hdcMask
= CreateCompatibleDC(0);
798 /* Default to ILC_COLOR4 if none of the ILC_COLOR* flags are specified */
799 if (ilc
== ILC_COLOR
)
802 himl
->flags
|= ILC_COLOR4
;
805 if (ilc
>= ILC_COLOR4
&& ilc
<= ILC_COLOR32
)
806 himl
->uBitsPixel
= ilc
;
808 himl
->uBitsPixel
= (UINT
)GetDeviceCaps (himl
->hdcImage
, BITSPIXEL
);
810 if (himl
->cMaxImage
> 0) {
811 himl
->hbmImage
= ImageList_CreateImage(himl
->hdcImage
, himl
, himl
->cMaxImage
);
812 SelectObject(himl
->hdcImage
, himl
->hbmImage
);
816 if ((himl
->cMaxImage
> 0) && (himl
->flags
& ILC_MASK
)) {
819 imagelist_get_bitmap_size(himl
, himl
->cMaxImage
, &sz
);
820 himl
->hbmMask
= CreateBitmap (sz
.cx
, sz
.cy
, 1, 1, NULL
);
821 if (himl
->hbmMask
== 0) {
822 ERR("Error creating mask bitmap!\n");
825 SelectObject(himl
->hdcMask
, himl
->hbmMask
);
830 if (ilc
== ILC_COLOR32
)
831 himl
->has_alpha
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, himl
->cMaxImage
);
833 himl
->has_alpha
= NULL
;
835 /* create blending brushes */
836 hbmTemp
= CreateBitmap (8, 8, 1, 1, aBitBlend25
);
837 himl
->hbrBlend25
= CreatePatternBrush (hbmTemp
);
838 DeleteObject (hbmTemp
);
840 hbmTemp
= CreateBitmap (8, 8, 1, 1, aBitBlend50
);
841 himl
->hbrBlend50
= CreatePatternBrush (hbmTemp
);
842 DeleteObject (hbmTemp
);
844 TRACE("created imagelist %p\n", himl
);
848 ImageList_Destroy(himl
);
853 /*************************************************************************
854 * ImageList_Destroy [COMCTL32.@]
856 * Destroys an image list.
859 * himl [I] handle to image list
867 ImageList_Destroy (HIMAGELIST himl
)
872 IImageList_Release((IImageList
*) himl
);
877 /*************************************************************************
878 * ImageList_DragEnter [COMCTL32.@]
880 * Locks window update and displays the drag image at the given position.
883 * hwndLock [I] handle of the window that owns the drag image.
884 * x [I] X position of the drag image.
885 * y [I] Y position of the drag image.
892 * The position of the drag image is relative to the window, not
897 ImageList_DragEnter (HWND hwndLock
, INT x
, INT y
)
899 TRACE("(hwnd=%p x=%d y=%d)\n", hwndLock
, x
, y
);
901 if (!is_valid(InternalDrag
.himl
))
905 InternalDrag
.hwnd
= hwndLock
;
907 InternalDrag
.hwnd
= GetDesktopWindow ();
912 /* draw the drag image and save the background */
913 if (!ImageList_DragShowNolock(TRUE
)) {
921 /*************************************************************************
922 * ImageList_DragLeave [COMCTL32.@]
924 * Unlocks window update and hides the drag image.
927 * hwndLock [I] handle of the window that owns the drag image.
935 ImageList_DragLeave (HWND hwndLock
)
937 /* As we don't save drag info in the window this can lead to problems if
938 an app does not supply the same window as DragEnter */
940 InternalDrag.hwnd = hwndLock;
942 InternalDrag.hwnd = GetDesktopWindow (); */
944 hwndLock
= GetDesktopWindow();
945 if(InternalDrag
.hwnd
!= hwndLock
)
946 FIXME("DragLeave hWnd != DragEnter hWnd\n");
948 ImageList_DragShowNolock (FALSE
);
954 /*************************************************************************
955 * ImageList_InternalDragDraw [Internal]
957 * Draws the drag image.
960 * hdc [I] device context to draw into.
961 * x [I] X position of the drag image.
962 * y [I] Y position of the drag image.
969 * The position of the drag image is relative to the window, not
975 ImageList_InternalDragDraw (HDC hdc
, INT x
, INT y
)
977 IMAGELISTDRAWPARAMS imldp
;
979 ZeroMemory (&imldp
, sizeof(imldp
));
980 imldp
.cbSize
= sizeof(imldp
);
981 imldp
.himl
= InternalDrag
.himl
;
986 imldp
.rgbBk
= CLR_DEFAULT
;
987 imldp
.rgbFg
= CLR_DEFAULT
;
988 imldp
.fStyle
= ILD_NORMAL
;
989 imldp
.fState
= ILS_ALPHA
;
991 ImageList_DrawIndirect (&imldp
);
994 /*************************************************************************
995 * ImageList_DragMove [COMCTL32.@]
997 * Moves the drag image.
1000 * x [I] X position of the drag image.
1001 * y [I] Y position of the drag image.
1008 * The position of the drag image is relative to the window, not
1013 ImageList_DragMove (INT x
, INT y
)
1015 TRACE("(x=%d y=%d)\n", x
, y
);
1017 if (!is_valid(InternalDrag
.himl
))
1020 /* draw/update the drag image */
1021 if (InternalDrag
.bShow
) {
1025 HBITMAP hbmOffScreen
;
1026 INT origNewX
, origNewY
;
1027 INT origOldX
, origOldY
;
1028 INT origRegX
, origRegY
;
1029 INT sizeRegX
, sizeRegY
;
1032 /* calculate the update region */
1033 origNewX
= x
- InternalDrag
.dxHotspot
;
1034 origNewY
= y
- InternalDrag
.dyHotspot
;
1035 origOldX
= InternalDrag
.x
- InternalDrag
.dxHotspot
;
1036 origOldY
= InternalDrag
.y
- InternalDrag
.dyHotspot
;
1037 origRegX
= min(origNewX
, origOldX
);
1038 origRegY
= min(origNewY
, origOldY
);
1039 sizeRegX
= InternalDrag
.himl
->cx
+ abs(x
- InternalDrag
.x
);
1040 sizeRegY
= InternalDrag
.himl
->cy
+ abs(y
- InternalDrag
.y
);
1042 hdcDrag
= GetDCEx(InternalDrag
.hwnd
, 0,
1043 DCX_WINDOW
| DCX_CACHE
| DCX_LOCKWINDOWUPDATE
);
1044 hdcOffScreen
= CreateCompatibleDC(hdcDrag
);
1045 hdcBg
= CreateCompatibleDC(hdcDrag
);
1047 hbmOffScreen
= CreateCompatibleBitmap(hdcDrag
, sizeRegX
, sizeRegY
);
1048 SelectObject(hdcOffScreen
, hbmOffScreen
);
1049 SelectObject(hdcBg
, InternalDrag
.hbmBg
);
1051 /* get the actual background of the update region */
1052 BitBlt(hdcOffScreen
, 0, 0, sizeRegX
, sizeRegY
, hdcDrag
,
1053 origRegX
, origRegY
, SRCCOPY
);
1054 /* erase the old image */
1055 BitBlt(hdcOffScreen
, origOldX
- origRegX
, origOldY
- origRegY
,
1056 InternalDrag
.himl
->cx
, InternalDrag
.himl
->cy
, hdcBg
, 0, 0,
1058 /* save the background */
1059 BitBlt(hdcBg
, 0, 0, InternalDrag
.himl
->cx
, InternalDrag
.himl
->cy
,
1060 hdcOffScreen
, origNewX
- origRegX
, origNewY
- origRegY
, SRCCOPY
);
1061 /* draw the image */
1062 ImageList_InternalDragDraw(hdcOffScreen
, origNewX
- origRegX
,
1063 origNewY
- origRegY
);
1064 /* draw the update region to the screen */
1065 BitBlt(hdcDrag
, origRegX
, origRegY
, sizeRegX
, sizeRegY
,
1066 hdcOffScreen
, 0, 0, SRCCOPY
);
1069 DeleteDC(hdcOffScreen
);
1070 DeleteObject(hbmOffScreen
);
1071 ReleaseDC(InternalDrag
.hwnd
, hdcDrag
);
1074 /* update the image position */
1082 /*************************************************************************
1083 * ImageList_DragShowNolock [COMCTL32.@]
1085 * Shows or hides the drag image.
1088 * bShow [I] TRUE shows the drag image, FALSE hides it.
1096 ImageList_DragShowNolock (BOOL bShow
)
1102 if (!is_valid(InternalDrag
.himl
))
1105 TRACE("bShow=0x%X!\n", bShow
);
1107 /* DragImage is already visible/hidden */
1108 if ((InternalDrag
.bShow
&& bShow
) || (!InternalDrag
.bShow
&& !bShow
)) {
1112 /* position of the origin of the DragImage */
1113 x
= InternalDrag
.x
- InternalDrag
.dxHotspot
;
1114 y
= InternalDrag
.y
- InternalDrag
.dyHotspot
;
1116 hdcDrag
= GetDCEx (InternalDrag
.hwnd
, 0,
1117 DCX_WINDOW
| DCX_CACHE
| DCX_LOCKWINDOWUPDATE
);
1122 hdcBg
= CreateCompatibleDC(hdcDrag
);
1123 if (!InternalDrag
.hbmBg
) {
1124 InternalDrag
.hbmBg
= CreateCompatibleBitmap(hdcDrag
,
1125 InternalDrag
.himl
->cx
, InternalDrag
.himl
->cy
);
1127 SelectObject(hdcBg
, InternalDrag
.hbmBg
);
1130 /* save the background */
1131 BitBlt(hdcBg
, 0, 0, InternalDrag
.himl
->cx
, InternalDrag
.himl
->cy
,
1132 hdcDrag
, x
, y
, SRCCOPY
);
1133 /* show the image */
1134 ImageList_InternalDragDraw(hdcDrag
, x
, y
);
1136 /* hide the image */
1137 BitBlt(hdcDrag
, x
, y
, InternalDrag
.himl
->cx
, InternalDrag
.himl
->cy
,
1138 hdcBg
, 0, 0, SRCCOPY
);
1141 InternalDrag
.bShow
= !InternalDrag
.bShow
;
1144 ReleaseDC (InternalDrag
.hwnd
, hdcDrag
);
1149 /*************************************************************************
1150 * ImageList_Draw [COMCTL32.@]
1155 * himl [I] handle to image list
1157 * hdc [I] handle to device context
1160 * fStyle [I] drawing flags
1171 ImageList_Draw (HIMAGELIST himl
, INT i
, HDC hdc
, INT x
, INT y
, UINT fStyle
)
1173 return ImageList_DrawEx (himl
, i
, hdc
, x
, y
, 0, 0,
1174 CLR_DEFAULT
, CLR_DEFAULT
, fStyle
);
1178 /*************************************************************************
1179 * ImageList_DrawEx [COMCTL32.@]
1181 * Draws an image and allows using extended drawing features.
1184 * himl [I] handle to image list
1186 * hdc [I] handle to device context
1191 * rgbBk [I] background color
1192 * rgbFg [I] foreground color
1193 * fStyle [I] drawing flags
1200 * Calls ImageList_DrawIndirect.
1203 * ImageList_DrawIndirect.
1207 ImageList_DrawEx (HIMAGELIST himl
, INT i
, HDC hdc
, INT x
, INT y
,
1208 INT dx
, INT dy
, COLORREF rgbBk
, COLORREF rgbFg
,
1211 IMAGELISTDRAWPARAMS imldp
;
1213 ZeroMemory (&imldp
, sizeof(imldp
));
1214 imldp
.cbSize
= sizeof(imldp
);
1222 imldp
.rgbBk
= rgbBk
;
1223 imldp
.rgbFg
= rgbFg
;
1224 imldp
.fStyle
= fStyle
;
1226 return ImageList_DrawIndirect (&imldp
);
1230 static BOOL
alpha_blend_image( HIMAGELIST himl
, HDC srce_dc
, HDC dest_dc
, int dest_x
, int dest_y
,
1231 int src_x
, int src_y
, int cx
, int cy
, BLENDFUNCTION func
,
1232 UINT style
, COLORREF blend_col
)
1236 HBITMAP bmp
= 0, mask
= 0;
1238 void *bits
, *mask_bits
;
1242 if (!(hdc
= CreateCompatibleDC( 0 ))) return FALSE
;
1243 if (!(info
= HeapAlloc( GetProcessHeap(), 0, FIELD_OFFSET( BITMAPINFO
, bmiColors
[256] )))) goto done
;
1244 info
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
1245 info
->bmiHeader
.biWidth
= cx
;
1246 info
->bmiHeader
.biHeight
= cy
;
1247 info
->bmiHeader
.biPlanes
= 1;
1248 info
->bmiHeader
.biBitCount
= 32;
1249 info
->bmiHeader
.biCompression
= BI_RGB
;
1250 info
->bmiHeader
.biSizeImage
= cx
* cy
* 4;
1251 info
->bmiHeader
.biXPelsPerMeter
= 0;
1252 info
->bmiHeader
.biYPelsPerMeter
= 0;
1253 info
->bmiHeader
.biClrUsed
= 0;
1254 info
->bmiHeader
.biClrImportant
= 0;
1255 if (!(bmp
= CreateDIBSection( srce_dc
, info
, DIB_RGB_COLORS
, &bits
, 0, 0 ))) goto done
;
1256 SelectObject( hdc
, bmp
);
1257 BitBlt( hdc
, 0, 0, cx
, cy
, srce_dc
, src_x
, src_y
, SRCCOPY
);
1259 if (blend_col
!= CLR_NONE
)
1261 BYTE r
= GetRValue( blend_col
);
1262 BYTE g
= GetGValue( blend_col
);
1263 BYTE b
= GetBValue( blend_col
);
1265 if (style
& ILD_BLEND25
)
1267 for (i
= 0, ptr
= bits
; i
< cx
* cy
; i
++, ptr
++)
1268 *ptr
= ((*ptr
& 0xff000000) |
1269 ((((*ptr
& 0x00ff0000) * 3 + (r
<< 16)) / 4) & 0x00ff0000) |
1270 ((((*ptr
& 0x0000ff00) * 3 + (g
<< 8)) / 4) & 0x0000ff00) |
1271 ((((*ptr
& 0x000000ff) * 3 + (b
<< 0)) / 4) & 0x000000ff));
1273 else if (style
& ILD_BLEND50
)
1275 for (i
= 0, ptr
= bits
; i
< cx
* cy
; i
++, ptr
++)
1276 *ptr
= ((*ptr
& 0xff000000) |
1277 ((((*ptr
& 0x00ff0000) + (r
<< 16)) / 2) & 0x00ff0000) |
1278 ((((*ptr
& 0x0000ff00) + (g
<< 8)) / 2) & 0x0000ff00) |
1279 ((((*ptr
& 0x000000ff) + (b
<< 0)) / 2) & 0x000000ff));
1283 if (himl
->has_alpha
) /* we already have an alpha channel in this case */
1285 /* pre-multiply by the alpha channel */
1286 for (i
= 0, ptr
= bits
; i
< cx
* cy
; i
++, ptr
++)
1288 DWORD alpha
= *ptr
>> 24;
1289 *ptr
= ((*ptr
& 0xff000000) |
1290 (((*ptr
& 0x00ff0000) * alpha
/ 255) & 0x00ff0000) |
1291 (((*ptr
& 0x0000ff00) * alpha
/ 255) & 0x0000ff00) |
1292 (((*ptr
& 0x000000ff) * alpha
/ 255)));
1295 else if (himl
->hbmMask
)
1297 unsigned int width_bytes
= (cx
+ 31) / 32 * 4;
1298 /* generate alpha channel from the mask */
1299 info
->bmiHeader
.biBitCount
= 1;
1300 info
->bmiHeader
.biSizeImage
= width_bytes
* cy
;
1301 info
->bmiColors
[0].rgbRed
= 0;
1302 info
->bmiColors
[0].rgbGreen
= 0;
1303 info
->bmiColors
[0].rgbBlue
= 0;
1304 info
->bmiColors
[0].rgbReserved
= 0;
1305 info
->bmiColors
[1].rgbRed
= 0xff;
1306 info
->bmiColors
[1].rgbGreen
= 0xff;
1307 info
->bmiColors
[1].rgbBlue
= 0xff;
1308 info
->bmiColors
[1].rgbReserved
= 0;
1309 if (!(mask
= CreateDIBSection( himl
->hdcMask
, info
, DIB_RGB_COLORS
, &mask_bits
, 0, 0 )))
1311 SelectObject( hdc
, mask
);
1312 BitBlt( hdc
, 0, 0, cx
, cy
, himl
->hdcMask
, src_x
, src_y
, SRCCOPY
);
1313 SelectObject( hdc
, bmp
);
1314 for (i
= 0, ptr
= bits
; i
< cy
; i
++)
1315 for (j
= 0; j
< cx
; j
++, ptr
++)
1316 if ((((BYTE
*)mask_bits
)[i
* width_bytes
+ j
/ 8] << (j
% 8)) & 0x80) *ptr
= 0;
1317 else *ptr
|= 0xff000000;
1320 ret
= GdiAlphaBlend( dest_dc
, dest_x
, dest_y
, cx
, cy
, hdc
, 0, 0, cx
, cy
, func
);
1324 if (bmp
) DeleteObject( bmp
);
1325 if (mask
) DeleteObject( mask
);
1326 HeapFree( GetProcessHeap(), 0, info
);
1330 HDC
saturate_image( HIMAGELIST himl
, HDC dest_dc
, int dest_x
, int dest_y
,
1331 int src_x
, int src_y
, int cx
, int cy
, COLORREF rgbFg
)
1341 /* create a dc and its device independent bitmap for doing the work,
1342 shamelessly copied from the alpha-blending function above */
1343 if (!(hdc
= CreateCompatibleDC( 0 ))) return FALSE
;
1344 if (!(info
= HeapAlloc( GetProcessHeap(), 0, FIELD_OFFSET( BITMAPINFO
, bmiColors
[256] )))) goto done
;
1345 info
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
1346 info
->bmiHeader
.biWidth
= cx
;
1347 info
->bmiHeader
.biHeight
= cy
;
1348 info
->bmiHeader
.biPlanes
= 1;
1349 info
->bmiHeader
.biBitCount
= 32;
1350 info
->bmiHeader
.biCompression
= BI_RGB
;
1351 info
->bmiHeader
.biSizeImage
= cx
* cy
* 4;
1352 info
->bmiHeader
.biXPelsPerMeter
= 0;
1353 info
->bmiHeader
.biYPelsPerMeter
= 0;
1354 info
->bmiHeader
.biClrUsed
= 0;
1355 info
->bmiHeader
.biClrImportant
= 0;
1356 if (!(bmp
= CreateDIBSection(himl
->hdcImage
, info
, DIB_RGB_COLORS
, &bits
, 0, 0 ))) goto done
;
1358 /* bind both surfaces */
1359 SelectObject(hdc
, bmp
);
1361 /* copy into our dc the section that covers just the icon we we're asked for */
1362 BitBlt(hdc
, 0, 0, cx
, cy
, himl
->hdcImage
, src_x
, src_y
, SRCCOPY
);
1364 /* loop every pixel of the bitmap */
1365 for (i
= 0, ptr
= bits
; i
< cx
* cy
; i
++, ptr
++)
1367 COLORREF orig_color
= *ptr
;
1369 /* calculate the effective luminance using the constants from here, adapted to the human eye:
1370 <http://bobpowell.net/grayscale.aspx> */
1371 float mixed_color
= (GetRValue(orig_color
) * .30 +
1372 GetGValue(orig_color
) * .59 +
1373 GetBValue(orig_color
) * .11);
1375 *ptr
= RGBA(mixed_color
, mixed_color
, mixed_color
, GetAValue(orig_color
));
1384 HeapFree(GetProcessHeap(), 0, info
);
1386 /* return the handle to our desaturated dc, that will substitute its original counterpart in the next calls */
1390 /*************************************************************************
1391 * ImageList_DrawIndirect [COMCTL32.@]
1393 * Draws an image using various parameters specified in pimldp.
1396 * pimldp [I] pointer to IMAGELISTDRAWPARAMS structure.
1404 ImageList_DrawIndirect (IMAGELISTDRAWPARAMS
*pimldp
)
1406 INT cx
, cy
, nOvlIdx
;
1407 DWORD fState
, dwRop
;
1409 COLORREF oldImageBk
, oldImageFg
;
1410 HDC hImageDC
, hImageListDC
, hMaskListDC
;
1411 HBITMAP hImageBmp
, hOldImageBmp
, hBlendMaskBmp
;
1412 BOOL bIsTransparent
, bBlend
, bResult
= FALSE
, bMask
;
1418 if (!pimldp
|| !(himl
= pimldp
->himl
)) return FALSE
;
1419 if (!is_valid(himl
)) return FALSE
;
1420 if ((pimldp
->i
< 0) || (pimldp
->i
>= himl
->cCurImage
)) return FALSE
;
1422 imagelist_point_from_index( himl
, pimldp
->i
, &pt
);
1423 pt
.x
+= pimldp
->xBitmap
;
1424 pt
.y
+= pimldp
->yBitmap
;
1426 fState
= pimldp
->cbSize
< sizeof(IMAGELISTDRAWPARAMS
) ? ILS_NORMAL
: pimldp
->fState
;
1427 fStyle
= pimldp
->fStyle
& ~ILD_OVERLAYMASK
;
1428 cx
= (pimldp
->cx
== 0) ? himl
->cx
: pimldp
->cx
;
1429 cy
= (pimldp
->cy
== 0) ? himl
->cy
: pimldp
->cy
;
1431 bIsTransparent
= (fStyle
& ILD_TRANSPARENT
);
1432 if( pimldp
->rgbBk
== CLR_NONE
)
1433 bIsTransparent
= TRUE
;
1434 if( ( pimldp
->rgbBk
== CLR_DEFAULT
) && ( himl
->clrBk
== CLR_NONE
) )
1435 bIsTransparent
= TRUE
;
1436 bMask
= (himl
->flags
& ILC_MASK
) && (fStyle
& ILD_MASK
) ;
1437 bBlend
= (fStyle
& (ILD_BLEND25
| ILD_BLEND50
) ) && !bMask
;
1439 TRACE("himl(%p) hbmMask(%p) iImage(%d) x(%d) y(%d) cx(%d) cy(%d)\n",
1440 himl
, himl
->hbmMask
, pimldp
->i
, pimldp
->x
, pimldp
->y
, cx
, cy
);
1442 /* we will use these DCs to access the images and masks in the ImageList */
1443 hImageListDC
= himl
->hdcImage
;
1444 hMaskListDC
= himl
->hdcMask
;
1446 /* these will accumulate the image and mask for the image we're drawing */
1447 hImageDC
= CreateCompatibleDC( pimldp
->hdcDst
);
1448 hImageBmp
= CreateCompatibleBitmap( pimldp
->hdcDst
, cx
, cy
);
1449 hBlendMaskBmp
= bBlend
? CreateBitmap(cx
, cy
, 1, 1, NULL
) : 0;
1451 /* Create a compatible DC. */
1452 if (!hImageListDC
|| !hImageDC
|| !hImageBmp
||
1453 (bBlend
&& !hBlendMaskBmp
) || (himl
->hbmMask
&& !hMaskListDC
))
1456 hOldImageBmp
= SelectObject(hImageDC
, hImageBmp
);
1459 * To obtain a transparent look, background color should be set
1460 * to white and foreground color to black when blitting the
1463 oldImageFg
= SetTextColor( hImageDC
, RGB( 0, 0, 0 ) );
1464 oldImageBk
= SetBkColor( hImageDC
, RGB( 0xff, 0xff, 0xff ) );
1467 * If the ILS_SATURATE bit is enabled we should multiply the
1468 * RGB colors of the original image by the contents of rgbFg.
1470 if (fState
& ILS_SATURATE
)
1472 hImageListDC
= saturate_image(himl
, pimldp
->hdcDst
, pimldp
->x
, pimldp
->y
,
1473 pt
.x
, pt
.y
, cx
, cy
, pimldp
->rgbFg
);
1475 /* shitty way of getting subroutines to blit at the right place (top left corner),
1476 as our modified imagelist only contains a single image for performance reasons */
1481 has_alpha
= (himl
->has_alpha
&& himl
->has_alpha
[pimldp
->i
]);
1482 if (!bMask
&& (has_alpha
|| (fState
& ILS_ALPHA
)))
1484 COLORREF colour
, blend_col
= CLR_NONE
;
1489 blend_col
= pimldp
->rgbFg
;
1490 if (blend_col
== CLR_DEFAULT
) blend_col
= GetSysColor( COLOR_HIGHLIGHT
);
1491 else if (blend_col
== CLR_NONE
) blend_col
= GetTextColor( pimldp
->hdcDst
);
1494 func
.BlendOp
= AC_SRC_OVER
;
1495 func
.BlendFlags
= 0;
1496 func
.SourceConstantAlpha
= (fState
& ILS_ALPHA
) ? pimldp
->Frame
: 255;
1497 func
.AlphaFormat
= AC_SRC_ALPHA
;
1501 bResult
= alpha_blend_image( himl
, hImageListDC
, pimldp
->hdcDst
, pimldp
->x
, pimldp
->y
,
1502 pt
.x
, pt
.y
, cx
, cy
, func
, fStyle
, blend_col
);
1505 colour
= pimldp
->rgbBk
;
1506 if (colour
== CLR_DEFAULT
) colour
= himl
->clrBk
;
1507 if (colour
== CLR_NONE
) colour
= GetBkColor( pimldp
->hdcDst
);
1509 hOldBrush
= SelectObject (hImageDC
, CreateSolidBrush (colour
));
1510 PatBlt( hImageDC
, 0, 0, cx
, cy
, PATCOPY
);
1511 alpha_blend_image( himl
, hImageListDC
, hImageDC
, 0, 0, pt
.x
, pt
.y
, cx
, cy
, func
, fStyle
, blend_col
);
1512 DeleteObject (SelectObject (hImageDC
, hOldBrush
));
1513 bResult
= BitBlt( pimldp
->hdcDst
, pimldp
->x
, pimldp
->y
, cx
, cy
, hImageDC
, 0, 0, SRCCOPY
);
1518 * Draw the initial image
1521 if (himl
->hbmMask
) {
1522 hOldBrush
= SelectObject (hImageDC
, CreateSolidBrush (GetTextColor(pimldp
->hdcDst
)));
1523 PatBlt( hImageDC
, 0, 0, cx
, cy
, PATCOPY
);
1524 BitBlt(hImageDC
, 0, 0, cx
, cy
, hMaskListDC
, pt
.x
, pt
.y
, SRCPAINT
);
1525 DeleteObject (SelectObject (hImageDC
, hOldBrush
));
1526 if( bIsTransparent
)
1528 BitBlt ( pimldp
->hdcDst
, pimldp
->x
, pimldp
->y
, cx
, cy
, hImageDC
, 0, 0, SRCAND
);
1533 hOldBrush
= SelectObject (hImageDC
, GetStockObject(BLACK_BRUSH
));
1534 PatBlt( hImageDC
, 0, 0, cx
, cy
, PATCOPY
);
1535 SelectObject(hImageDC
, hOldBrush
);
1538 /* blend the image with the needed solid background */
1539 COLORREF colour
= RGB(0,0,0);
1541 if( !bIsTransparent
)
1543 colour
= pimldp
->rgbBk
;
1544 if( colour
== CLR_DEFAULT
)
1545 colour
= himl
->clrBk
;
1546 if( colour
== CLR_NONE
)
1547 colour
= GetBkColor(pimldp
->hdcDst
);
1550 hOldBrush
= SelectObject (hImageDC
, CreateSolidBrush (colour
));
1551 PatBlt( hImageDC
, 0, 0, cx
, cy
, PATCOPY
);
1554 BitBlt( hImageDC
, 0, 0, cx
, cy
, hMaskListDC
, pt
.x
, pt
.y
, SRCAND
);
1555 BitBlt( hImageDC
, 0, 0, cx
, cy
, hImageListDC
, pt
.x
, pt
.y
, SRCPAINT
);
1558 BitBlt( hImageDC
, 0, 0, cx
, cy
, hImageListDC
, pt
.x
, pt
.y
, SRCCOPY
);
1559 DeleteObject (SelectObject (hImageDC
, hOldBrush
));
1562 /* Time for blending, if required */
1565 COLORREF clrBlend
= pimldp
->rgbFg
;
1566 HDC hBlendMaskDC
= hImageListDC
;
1569 /* Create the blend Mask */
1570 hOldBitmap
= SelectObject(hBlendMaskDC
, hBlendMaskBmp
);
1571 hBlendBrush
= fStyle
& ILD_BLEND50
? himl
->hbrBlend50
: himl
->hbrBlend25
;
1572 hOldBrush
= SelectObject(hBlendMaskDC
, hBlendBrush
);
1573 PatBlt(hBlendMaskDC
, 0, 0, cx
, cy
, PATCOPY
);
1574 SelectObject(hBlendMaskDC
, hOldBrush
);
1576 /* Modify the blend mask if an Image Mask exist */
1578 BitBlt(hBlendMaskDC
, 0, 0, cx
, cy
, hMaskListDC
, pt
.x
, pt
.y
, 0x220326); /* NOTSRCAND */
1579 BitBlt(hBlendMaskDC
, 0, 0, cx
, cy
, hBlendMaskDC
, 0, 0, NOTSRCCOPY
);
1582 /* now apply blend to the current image given the BlendMask */
1583 if (clrBlend
== CLR_DEFAULT
) clrBlend
= GetSysColor (COLOR_HIGHLIGHT
);
1584 else if (clrBlend
== CLR_NONE
) clrBlend
= GetTextColor (pimldp
->hdcDst
);
1585 hOldBrush
= SelectObject (hImageDC
, CreateSolidBrush(clrBlend
));
1586 BitBlt (hImageDC
, 0, 0, cx
, cy
, hBlendMaskDC
, 0, 0, 0xB8074A); /* PSDPxax */
1587 DeleteObject(SelectObject(hImageDC
, hOldBrush
));
1588 SelectObject(hBlendMaskDC
, hOldBitmap
);
1591 /* Now do the overlay image, if any */
1592 nOvlIdx
= (pimldp
->fStyle
& ILD_OVERLAYMASK
) >> 8;
1593 if ( (nOvlIdx
>= 1) && (nOvlIdx
<= MAX_OVERLAYIMAGE
)) {
1594 nOvlIdx
= himl
->nOvlIdx
[nOvlIdx
- 1];
1595 if ((nOvlIdx
>= 0) && (nOvlIdx
< himl
->cCurImage
)) {
1597 imagelist_point_from_index( himl
, nOvlIdx
, &ptOvl
);
1598 ptOvl
.x
+= pimldp
->xBitmap
;
1599 if (himl
->hbmMask
&& !(fStyle
& ILD_IMAGE
))
1600 BitBlt (hImageDC
, 0, 0, cx
, cy
, hMaskListDC
, ptOvl
.x
, ptOvl
.y
, SRCAND
);
1601 BitBlt (hImageDC
, 0, 0, cx
, cy
, hImageListDC
, ptOvl
.x
, ptOvl
.y
, SRCPAINT
);
1605 if (fState
& ILS_GLOW
) FIXME("ILS_GLOW: unimplemented!\n");
1606 if (fState
& ILS_SHADOW
) FIXME("ILS_SHADOW: unimplemented!\n");
1608 if (fStyle
& ILD_PRESERVEALPHA
) FIXME("ILD_PRESERVEALPHA: unimplemented!\n");
1609 if (fStyle
& ILD_SCALE
) FIXME("ILD_SCALE: unimplemented!\n");
1610 if (fStyle
& ILD_DPISCALE
) FIXME("ILD_DPISCALE: unimplemented!\n");
1612 /* now copy the image to the screen */
1614 if (himl
->hbmMask
&& bIsTransparent
) {
1615 COLORREF oldDstFg
= SetTextColor(pimldp
->hdcDst
, RGB( 0, 0, 0 ) );
1616 COLORREF oldDstBk
= SetBkColor(pimldp
->hdcDst
, RGB( 0xff, 0xff, 0xff ));
1617 BitBlt (pimldp
->hdcDst
, pimldp
->x
, pimldp
->y
, cx
, cy
, hMaskListDC
, pt
.x
, pt
.y
, SRCAND
);
1618 SetBkColor(pimldp
->hdcDst
, oldDstBk
);
1619 SetTextColor(pimldp
->hdcDst
, oldDstFg
);
1622 if (fStyle
& ILD_ROP
) dwRop
= pimldp
->dwRop
;
1623 BitBlt (pimldp
->hdcDst
, pimldp
->x
, pimldp
->y
, cx
, cy
, hImageDC
, 0, 0, dwRop
);
1627 /* cleanup the mess */
1628 SetBkColor(hImageDC
, oldImageBk
);
1629 SetTextColor(hImageDC
, oldImageFg
);
1630 SelectObject(hImageDC
, hOldImageBmp
);
1632 DeleteObject(hBlendMaskBmp
);
1633 DeleteObject(hImageBmp
);
1640 /*************************************************************************
1641 * ImageList_Duplicate [COMCTL32.@]
1643 * Duplicates an image list.
1646 * himlSrc [I] source image list handle
1649 * Success: Handle of duplicated image list.
1654 ImageList_Duplicate (HIMAGELIST himlSrc
)
1658 if (!is_valid(himlSrc
)) {
1659 ERR("Invalid image list handle!\n");
1663 himlDst
= ImageList_Create (himlSrc
->cx
, himlSrc
->cy
, himlSrc
->flags
,
1664 himlSrc
->cCurImage
, himlSrc
->cGrow
);
1670 imagelist_get_bitmap_size(himlSrc
, himlSrc
->cCurImage
, &sz
);
1671 BitBlt (himlDst
->hdcImage
, 0, 0, sz
.cx
, sz
.cy
,
1672 himlSrc
->hdcImage
, 0, 0, SRCCOPY
);
1674 if (himlDst
->hbmMask
)
1675 BitBlt (himlDst
->hdcMask
, 0, 0, sz
.cx
, sz
.cy
,
1676 himlSrc
->hdcMask
, 0, 0, SRCCOPY
);
1678 himlDst
->cCurImage
= himlSrc
->cCurImage
;
1679 if (himlSrc
->has_alpha
&& himlDst
->has_alpha
)
1680 memcpy( himlDst
->has_alpha
, himlSrc
->has_alpha
, himlDst
->cCurImage
);
1686 /*************************************************************************
1687 * ImageList_EndDrag [COMCTL32.@]
1689 * Finishes a drag operation.
1700 ImageList_EndDrag (void)
1702 /* cleanup the InternalDrag struct */
1703 InternalDrag
.hwnd
= 0;
1704 if (InternalDrag
.himl
!= InternalDrag
.himlNoCursor
)
1705 ImageList_Destroy (InternalDrag
.himlNoCursor
);
1706 ImageList_Destroy (InternalDrag
.himl
);
1707 InternalDrag
.himlNoCursor
= InternalDrag
.himl
= 0;
1710 InternalDrag
.dxHotspot
= 0;
1711 InternalDrag
.dyHotspot
= 0;
1712 InternalDrag
.bShow
= FALSE
;
1713 DeleteObject(InternalDrag
.hbmBg
);
1714 InternalDrag
.hbmBg
= 0;
1718 /*************************************************************************
1719 * ImageList_GetBkColor [COMCTL32.@]
1721 * Returns the background color of an image list.
1724 * himl [I] Image list handle.
1727 * Success: background color
1732 ImageList_GetBkColor (HIMAGELIST himl
)
1734 return himl
? himl
->clrBk
: CLR_NONE
;
1738 /*************************************************************************
1739 * ImageList_GetDragImage [COMCTL32.@]
1741 * Returns the handle to the internal drag image list.
1744 * ppt [O] Pointer to the drag position. Can be NULL.
1745 * pptHotspot [O] Pointer to the position of the hot spot. Can be NULL.
1748 * Success: Handle of the drag image list.
1753 ImageList_GetDragImage (POINT
*ppt
, POINT
*pptHotspot
)
1755 if (is_valid(InternalDrag
.himl
)) {
1757 ppt
->x
= InternalDrag
.x
;
1758 ppt
->y
= InternalDrag
.y
;
1761 pptHotspot
->x
= InternalDrag
.dxHotspot
;
1762 pptHotspot
->y
= InternalDrag
.dyHotspot
;
1764 return (InternalDrag
.himl
);
1771 /*************************************************************************
1772 * ImageList_GetFlags [COMCTL32.@]
1774 * Gets the flags of the specified image list.
1777 * himl [I] Handle to image list
1787 ImageList_GetFlags(HIMAGELIST himl
)
1789 TRACE("%p\n", himl
);
1791 return is_valid(himl
) ? himl
->flags
: 0;
1795 /*************************************************************************
1796 * ImageList_GetIcon [COMCTL32.@]
1798 * Creates an icon from a masked image of an image list.
1801 * himl [I] handle to image list
1803 * flags [I] drawing style flags
1806 * Success: icon handle
1811 ImageList_GetIcon (HIMAGELIST himl
, INT i
, UINT fStyle
)
1815 HBITMAP hOldDstBitmap
;
1819 TRACE("%p %d %d\n", himl
, i
, fStyle
);
1820 if (!is_valid(himl
) || (i
< 0) || (i
>= himl
->cCurImage
)) return NULL
;
1826 /* create colour bitmap */
1828 ii
.hbmColor
= CreateCompatibleBitmap(hdcDst
, himl
->cx
, himl
->cy
);
1829 ReleaseDC(0, hdcDst
);
1831 hdcDst
= CreateCompatibleDC(0);
1833 imagelist_point_from_index( himl
, i
, &pt
);
1836 ii
.hbmMask
= CreateBitmap (himl
->cx
, himl
->cy
, 1, 1, NULL
);
1837 hOldDstBitmap
= SelectObject (hdcDst
, ii
.hbmMask
);
1838 if (himl
->hbmMask
) {
1839 BitBlt (hdcDst
, 0, 0, himl
->cx
, himl
->cy
,
1840 himl
->hdcMask
, pt
.x
, pt
.y
, SRCCOPY
);
1843 PatBlt (hdcDst
, 0, 0, himl
->cx
, himl
->cy
, BLACKNESS
);
1846 SelectObject (hdcDst
, ii
.hbmColor
);
1847 BitBlt (hdcDst
, 0, 0, himl
->cx
, himl
->cy
,
1848 himl
->hdcImage
, pt
.x
, pt
.y
, SRCCOPY
);
1851 * CreateIconIndirect requires us to deselect the bitmaps from
1852 * the DCs before calling
1854 SelectObject(hdcDst
, hOldDstBitmap
);
1856 hIcon
= CreateIconIndirect (&ii
);
1858 DeleteObject (ii
.hbmMask
);
1859 DeleteObject (ii
.hbmColor
);
1866 /*************************************************************************
1867 * ImageList_GetIconSize [COMCTL32.@]
1869 * Retrieves the size of an image in an image list.
1872 * himl [I] handle to image list
1873 * cx [O] pointer to the image width.
1874 * cy [O] pointer to the image height.
1881 * All images in an image list have the same size.
1885 ImageList_GetIconSize (HIMAGELIST himl
, INT
*cx
, INT
*cy
)
1887 if (!is_valid(himl
) || !cx
|| !cy
)
1889 if ((himl
->cx
<= 0) || (himl
->cy
<= 0))
1899 /*************************************************************************
1900 * ImageList_GetImageCount [COMCTL32.@]
1902 * Returns the number of images in an image list.
1905 * himl [I] handle to image list
1908 * Success: Number of images.
1913 ImageList_GetImageCount (HIMAGELIST himl
)
1915 if (!is_valid(himl
))
1918 return himl
->cCurImage
;
1922 /*************************************************************************
1923 * ImageList_GetImageInfo [COMCTL32.@]
1925 * Returns information about an image in an image list.
1928 * himl [I] handle to image list
1930 * pImageInfo [O] pointer to the image information
1938 ImageList_GetImageInfo (HIMAGELIST himl
, INT i
, IMAGEINFO
*pImageInfo
)
1942 if (!is_valid(himl
) || (pImageInfo
== NULL
))
1944 if ((i
< 0) || (i
>= himl
->cCurImage
))
1947 pImageInfo
->hbmImage
= himl
->hbmImage
;
1948 pImageInfo
->hbmMask
= himl
->hbmMask
;
1950 imagelist_point_from_index( himl
, i
, &pt
);
1951 pImageInfo
->rcImage
.top
= pt
.y
;
1952 pImageInfo
->rcImage
.bottom
= pt
.y
+ himl
->cy
;
1953 pImageInfo
->rcImage
.left
= pt
.x
;
1954 pImageInfo
->rcImage
.right
= pt
.x
+ himl
->cx
;
1960 /*************************************************************************
1961 * ImageList_GetImageRect [COMCTL32.@]
1963 * Retrieves the rectangle of the specified image in an image list.
1966 * himl [I] handle to image list
1968 * lpRect [O] pointer to the image rectangle
1975 * This is an UNDOCUMENTED function!!!
1979 ImageList_GetImageRect (HIMAGELIST himl
, INT i
, LPRECT lpRect
)
1983 if (!is_valid(himl
) || (lpRect
== NULL
))
1985 if ((i
< 0) || (i
>= himl
->cCurImage
))
1988 imagelist_point_from_index( himl
, i
, &pt
);
1989 lpRect
->left
= pt
.x
;
1991 lpRect
->right
= pt
.x
+ himl
->cx
;
1992 lpRect
->bottom
= pt
.y
+ himl
->cy
;
1998 /*************************************************************************
1999 * ImageList_LoadImage [COMCTL32.@]
2000 * ImageList_LoadImageA [COMCTL32.@]
2002 * Creates an image list from a bitmap, icon or cursor.
2004 * See ImageList_LoadImageW.
2008 ImageList_LoadImageA (HINSTANCE hi
, LPCSTR lpbmp
, INT cx
, INT cGrow
,
2009 COLORREF clrMask
, UINT uType
, UINT uFlags
)
2015 if (IS_INTRESOURCE(lpbmp
))
2016 return ImageList_LoadImageW(hi
, (LPCWSTR
)lpbmp
, cx
, cGrow
, clrMask
,
2019 len
= MultiByteToWideChar(CP_ACP
, 0, lpbmp
, -1, NULL
, 0);
2020 lpbmpW
= Alloc(len
* sizeof(WCHAR
));
2021 MultiByteToWideChar(CP_ACP
, 0, lpbmp
, -1, lpbmpW
, len
);
2023 himl
= ImageList_LoadImageW(hi
, lpbmpW
, cx
, cGrow
, clrMask
, uType
, uFlags
);
2029 /*************************************************************************
2030 * ImageList_LoadImageW [COMCTL32.@]
2032 * Creates an image list from a bitmap, icon or cursor.
2035 * hi [I] instance handle
2036 * lpbmp [I] name or id of the image
2037 * cx [I] width of each image
2038 * cGrow [I] number of images to expand
2039 * clrMask [I] mask color
2040 * uType [I] type of image to load
2041 * uFlags [I] loading flags
2044 * Success: handle to the loaded image list
2052 ImageList_LoadImageW (HINSTANCE hi
, LPCWSTR lpbmp
, INT cx
, INT cGrow
,
2053 COLORREF clrMask
, UINT uType
, UINT uFlags
)
2055 HIMAGELIST himl
= NULL
;
2059 handle
= LoadImageW (hi
, lpbmp
, uType
, 0, 0, uFlags
);
2061 WARN("Couldn't load image\n");
2065 if (uType
== IMAGE_BITMAP
) {
2069 if (GetObjectW (handle
, sizeof(dib
), &dib
) == sizeof(BITMAP
)) color
= ILC_COLOR
;
2070 else color
= dib
.dsBm
.bmBitsPixel
;
2072 /* To match windows behavior, if cx is set to zero and
2073 the flag DI_DEFAULTSIZE is specified, cx becomes the
2074 system metric value for icons. If the flag is not specified
2075 the function sets the size to the height of the bitmap */
2078 if (uFlags
& DI_DEFAULTSIZE
)
2079 cx
= GetSystemMetrics (SM_CXICON
);
2081 cx
= dib
.dsBm
.bmHeight
;
2084 nImageCount
= dib
.dsBm
.bmWidth
/ cx
;
2086 himl
= ImageList_Create (cx
, dib
.dsBm
.bmHeight
, ILC_MASK
| color
, nImageCount
, cGrow
);
2088 DeleteObject (handle
);
2091 ImageList_AddMasked (himl
, handle
, clrMask
);
2093 else if ((uType
== IMAGE_ICON
) || (uType
== IMAGE_CURSOR
)) {
2097 GetIconInfo (handle
, &ii
);
2098 GetObjectW (ii
.hbmColor
, sizeof(BITMAP
), &bmp
);
2099 himl
= ImageList_Create (bmp
.bmWidth
, bmp
.bmHeight
,
2100 ILC_MASK
| ILC_COLOR
, 1, cGrow
);
2102 DeleteObject (ii
.hbmColor
);
2103 DeleteObject (ii
.hbmMask
);
2104 DeleteObject (handle
);
2107 ImageList_Add (himl
, ii
.hbmColor
, ii
.hbmMask
);
2108 DeleteObject (ii
.hbmColor
);
2109 DeleteObject (ii
.hbmMask
);
2112 DeleteObject (handle
);
2118 /*************************************************************************
2119 * ImageList_Merge [COMCTL32.@]
2121 * Create an image list containing a merged image from two image lists.
2124 * himl1 [I] handle to first image list
2125 * i1 [I] first image index
2126 * himl2 [I] handle to second image list
2127 * i2 [I] second image index
2128 * dx [I] X offset of the second image relative to the first.
2129 * dy [I] Y offset of the second image relative to the first.
2132 * Success: The newly created image list. It contains a single image
2133 * consisting of the second image merged with the first.
2134 * Failure: NULL, if either himl1 or himl2 is invalid.
2137 * - The returned image list should be deleted by the caller using
2138 * ImageList_Destroy() when it is no longer required.
2139 * - If either i1 or i2 is not a valid image index, they will be treated
2143 ImageList_Merge (HIMAGELIST himl1
, INT i1
, HIMAGELIST himl2
, INT i2
,
2146 HIMAGELIST himlDst
= NULL
;
2148 INT xOff1
, yOff1
, xOff2
, yOff2
;
2152 TRACE("(himl1=%p i1=%d himl2=%p i2=%d dx=%d dy=%d)\n", himl1
, i1
, himl2
,
2155 if (!is_valid(himl1
) || !is_valid(himl2
))
2159 cxDst
= max (himl1
->cx
, dx
+ himl2
->cx
);
2164 cxDst
= max (himl2
->cx
, himl1
->cx
- dx
);
2169 cxDst
= max (himl1
->cx
, himl2
->cx
);
2175 cyDst
= max (himl1
->cy
, dy
+ himl2
->cy
);
2180 cyDst
= max (himl2
->cy
, himl1
->cy
- dy
);
2185 cyDst
= max (himl1
->cy
, himl2
->cy
);
2190 newFlags
= (himl1
->flags
> himl2
->flags
? himl1
->flags
: himl2
->flags
) & ILC_COLORDDB
;
2191 if (newFlags
== ILC_COLORDDB
&& (himl1
->flags
& ILC_COLORDDB
) == ILC_COLOR16
)
2192 newFlags
= ILC_COLOR16
; /* this is what native (at least v5) does, don't know why */
2193 himlDst
= ImageList_Create (cxDst
, cyDst
, ILC_MASK
| newFlags
, 1, 1);
2197 imagelist_point_from_index( himl1
, i1
, &pt1
);
2198 imagelist_point_from_index( himl2
, i2
, &pt2
);
2201 BitBlt (himlDst
->hdcImage
, 0, 0, cxDst
, cyDst
, himl1
->hdcImage
, 0, 0, BLACKNESS
);
2202 if (i1
>= 0 && i1
< himl1
->cCurImage
)
2203 BitBlt (himlDst
->hdcImage
, xOff1
, yOff1
, himl1
->cx
, himl1
->cy
, himl1
->hdcImage
, pt1
.x
, pt1
.y
, SRCCOPY
);
2204 if (i2
>= 0 && i2
< himl2
->cCurImage
)
2206 if (himl2
->flags
& ILC_MASK
)
2208 BitBlt (himlDst
->hdcImage
, xOff2
, yOff2
, himl2
->cx
, himl2
->cy
, himl2
->hdcMask
, pt2
.x
, pt2
.y
, SRCAND
);
2209 BitBlt (himlDst
->hdcImage
, xOff2
, yOff2
, himl2
->cx
, himl2
->cy
, himl2
->hdcImage
, pt2
.x
, pt2
.y
, SRCPAINT
);
2212 BitBlt (himlDst
->hdcImage
, xOff2
, yOff2
, himl2
->cx
, himl2
->cy
, himl2
->hdcImage
, pt2
.x
, pt2
.y
, SRCCOPY
);
2216 BitBlt (himlDst
->hdcMask
, 0, 0, cxDst
, cyDst
, himl1
->hdcMask
, 0, 0, WHITENESS
);
2217 if (i1
>= 0 && i1
< himl1
->cCurImage
)
2218 BitBlt (himlDst
->hdcMask
, xOff1
, yOff1
, himl1
->cx
, himl1
->cy
, himl1
->hdcMask
, pt1
.x
, pt1
.y
, SRCCOPY
);
2219 if (i2
>= 0 && i2
< himl2
->cCurImage
)
2220 BitBlt (himlDst
->hdcMask
, xOff2
, yOff2
, himl2
->cx
, himl2
->cy
, himl2
->hdcMask
, pt2
.x
, pt2
.y
, SRCAND
);
2222 himlDst
->cCurImage
= 1;
2229 /* helper for ImageList_Read, see comments below */
2230 static void *read_bitmap(LPSTREAM pstm
, BITMAPINFO
*bmi
)
2232 BITMAPFILEHEADER bmfh
;
2233 int bitsperpixel
, palspace
;
2236 if (FAILED(IStream_Read ( pstm
, &bmfh
, sizeof(bmfh
), NULL
)))
2239 if (bmfh
.bfType
!= (('M'<<8)|'B'))
2242 if (FAILED(IStream_Read ( pstm
, &bmi
->bmiHeader
, sizeof(bmi
->bmiHeader
), NULL
)))
2245 if ((bmi
->bmiHeader
.biSize
!= sizeof(bmi
->bmiHeader
)))
2248 TRACE("width %u, height %u, planes %u, bpp %u\n",
2249 bmi
->bmiHeader
.biWidth
, bmi
->bmiHeader
.biHeight
,
2250 bmi
->bmiHeader
.biPlanes
, bmi
->bmiHeader
.biBitCount
);
2252 bitsperpixel
= bmi
->bmiHeader
.biPlanes
* bmi
->bmiHeader
.biBitCount
;
2253 if (bitsperpixel
<=8)
2254 palspace
= (1<<bitsperpixel
)*sizeof(RGBQUAD
);
2258 bmi
->bmiHeader
.biSizeImage
= get_dib_image_size( bmi
);
2260 /* read the palette right after the end of the bitmapinfoheader */
2261 if (palspace
&& FAILED(IStream_Read(pstm
, bmi
->bmiColors
, palspace
, NULL
)))
2264 bits
= Alloc(bmi
->bmiHeader
.biSizeImage
);
2265 if (!bits
) return NULL
;
2267 if (FAILED(IStream_Read(pstm
, bits
, bmi
->bmiHeader
.biSizeImage
, NULL
)))
2275 /*************************************************************************
2276 * ImageList_Read [COMCTL32.@]
2278 * Reads an image list from a stream.
2281 * pstm [I] pointer to a stream
2284 * Success: handle to image list
2287 * The format is like this:
2288 * ILHEAD ilheadstruct;
2290 * for the color image part:
2291 * BITMAPFILEHEADER bmfh;
2292 * BITMAPINFOHEADER bmih;
2293 * only if it has a palette:
2294 * RGBQUAD rgbs[nr_of_paletted_colors];
2296 * BYTE colorbits[imagesize];
2298 * the following only if the ILC_MASK bit is set in ILHEAD.ilFlags:
2299 * BITMAPFILEHEADER bmfh_mask;
2300 * BITMAPINFOHEADER bmih_mask;
2301 * only if it has a palette (it usually does not):
2302 * RGBQUAD rgbs[nr_of_paletted_colors];
2304 * BYTE maskbits[imagesize];
2306 HIMAGELIST WINAPI
ImageList_Read (LPSTREAM pstm
)
2308 char image_buf
[sizeof(BITMAPINFOHEADER
) + sizeof(RGBQUAD
) * 256];
2309 char mask_buf
[sizeof(BITMAPINFOHEADER
) + sizeof(RGBQUAD
) * 256];
2310 BITMAPINFO
*image_info
= (BITMAPINFO
*)image_buf
;
2311 BITMAPINFO
*mask_info
= (BITMAPINFO
*)mask_buf
;
2312 void *image_bits
, *mask_bits
= NULL
;
2317 TRACE("%p\n", pstm
);
2319 if (FAILED(IStream_Read (pstm
, &ilHead
, sizeof(ILHEAD
), NULL
)))
2321 if (ilHead
.usMagic
!= (('L' << 8) | 'I'))
2323 if (ilHead
.usVersion
!= 0x101) /* probably version? */
2326 TRACE("cx %u, cy %u, flags 0x%04x, cCurImage %u, cMaxImage %u\n",
2327 ilHead
.cx
, ilHead
.cy
, ilHead
.flags
, ilHead
.cCurImage
, ilHead
.cMaxImage
);
2329 himl
= ImageList_Create(ilHead
.cx
, ilHead
.cy
, ilHead
.flags
, ilHead
.cCurImage
, ilHead
.cMaxImage
);
2333 if (!(image_bits
= read_bitmap(pstm
, image_info
)))
2335 WARN("failed to read bitmap from stream\n");
2338 if (ilHead
.flags
& ILC_MASK
)
2340 if (!(mask_bits
= read_bitmap(pstm
, mask_info
)))
2342 WARN("failed to read mask bitmap from stream\n");
2346 else mask_info
= NULL
;
2348 if (himl
->has_alpha
&& image_info
->bmiHeader
.biBitCount
== 32)
2350 DWORD
*ptr
= image_bits
;
2351 BYTE
*mask_ptr
= mask_bits
;
2352 int stride
= himl
->cy
* image_info
->bmiHeader
.biWidth
;
2354 if (image_info
->bmiHeader
.biHeight
> 0) /* bottom-up */
2356 ptr
+= image_info
->bmiHeader
.biHeight
* image_info
->bmiHeader
.biWidth
- stride
;
2357 mask_ptr
+= (image_info
->bmiHeader
.biHeight
* image_info
->bmiHeader
.biWidth
- stride
) / 8;
2359 image_info
->bmiHeader
.biHeight
= himl
->cy
;
2361 else image_info
->bmiHeader
.biHeight
= -himl
->cy
;
2363 for (i
= 0; i
< ilHead
.cCurImage
; i
+= TILE_COUNT
)
2365 add_dib_bits( himl
, i
, min( ilHead
.cCurImage
- i
, TILE_COUNT
),
2366 himl
->cx
, himl
->cy
, image_info
, mask_info
, ptr
, mask_ptr
);
2368 mask_ptr
+= stride
/ 8;
2373 StretchDIBits( himl
->hdcImage
, 0, 0, image_info
->bmiHeader
.biWidth
, image_info
->bmiHeader
.biHeight
,
2374 0, 0, image_info
->bmiHeader
.biWidth
, image_info
->bmiHeader
.biHeight
,
2375 image_bits
, image_info
, DIB_RGB_COLORS
, SRCCOPY
);
2377 StretchDIBits( himl
->hdcMask
, 0, 0, mask_info
->bmiHeader
.biWidth
, mask_info
->bmiHeader
.biHeight
,
2378 0, 0, mask_info
->bmiHeader
.biWidth
, mask_info
->bmiHeader
.biHeight
,
2379 mask_bits
, mask_info
, DIB_RGB_COLORS
, SRCCOPY
);
2384 himl
->cCurImage
= ilHead
.cCurImage
;
2385 himl
->cMaxImage
= ilHead
.cMaxImage
;
2387 ImageList_SetBkColor(himl
,ilHead
.bkcolor
);
2389 ImageList_SetOverlayImage(himl
,ilHead
.ovls
[i
],i
+1);
2394 /*************************************************************************
2395 * ImageList_Remove [COMCTL32.@]
2397 * Removes an image from an image list
2400 * himl [I] image list handle
2407 * FIXME: as the image list storage test shows, native comctl32 simply shifts
2408 * images without creating a new bitmap.
2411 ImageList_Remove (HIMAGELIST himl
, INT i
)
2413 HBITMAP hbmNewImage
, hbmNewMask
;
2417 TRACE("(himl=%p i=%d)\n", himl
, i
);
2419 if (!is_valid(himl
)) {
2420 ERR("Invalid image list handle!\n");
2424 if ((i
< -1) || (i
>= himl
->cCurImage
)) {
2425 TRACE("index out of range! %d\n", i
);
2433 if (himl
->cCurImage
== 0) {
2434 /* remove all on empty ImageList is allowed */
2435 TRACE("remove all on empty ImageList!\n");
2439 himl
->cMaxImage
= himl
->cGrow
;
2440 himl
->cCurImage
= 0;
2441 for (nCount
= 0; nCount
< MAX_OVERLAYIMAGE
; nCount
++)
2442 himl
->nOvlIdx
[nCount
] = -1;
2444 if (himl
->has_alpha
)
2446 HeapFree( GetProcessHeap(), 0, himl
->has_alpha
);
2447 himl
->has_alpha
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, himl
->cMaxImage
);
2450 hbmNewImage
= ImageList_CreateImage(himl
->hdcImage
, himl
, himl
->cMaxImage
);
2451 SelectObject (himl
->hdcImage
, hbmNewImage
);
2452 DeleteObject (himl
->hbmImage
);
2453 himl
->hbmImage
= hbmNewImage
;
2455 if (himl
->hbmMask
) {
2457 imagelist_get_bitmap_size(himl
, himl
->cMaxImage
, &sz
);
2458 hbmNewMask
= CreateBitmap (sz
.cx
, sz
.cy
, 1, 1, NULL
);
2459 SelectObject (himl
->hdcMask
, hbmNewMask
);
2460 DeleteObject (himl
->hbmMask
);
2461 himl
->hbmMask
= hbmNewMask
;
2465 /* delete one image */
2466 TRACE("Remove single image! %d\n", i
);
2468 /* create new bitmap(s) */
2469 TRACE(" - Number of images: %d / %d (Old/New)\n",
2470 himl
->cCurImage
, himl
->cCurImage
- 1);
2472 hbmNewImage
= ImageList_CreateImage(himl
->hdcImage
, himl
, himl
->cMaxImage
);
2474 imagelist_get_bitmap_size(himl
, himl
->cMaxImage
, &sz
);
2476 hbmNewMask
= CreateBitmap (sz
.cx
, sz
.cy
, 1, 1, NULL
);
2478 hbmNewMask
= 0; /* Just to keep compiler happy! */
2480 hdcBmp
= CreateCompatibleDC (0);
2482 /* copy all images and masks prior to the "removed" image */
2484 TRACE("Pre image copy: Copy %d images\n", i
);
2486 SelectObject (hdcBmp
, hbmNewImage
);
2487 imagelist_copy_images( himl
, himl
->hdcImage
, hdcBmp
, 0, i
, 0 );
2489 if (himl
->hbmMask
) {
2490 SelectObject (hdcBmp
, hbmNewMask
);
2491 imagelist_copy_images( himl
, himl
->hdcMask
, hdcBmp
, 0, i
, 0 );
2495 /* copy all images and masks behind the removed image */
2496 if (i
< himl
->cCurImage
- 1) {
2497 TRACE("Post image copy!\n");
2499 SelectObject (hdcBmp
, hbmNewImage
);
2500 imagelist_copy_images( himl
, himl
->hdcImage
, hdcBmp
, i
+ 1,
2501 (himl
->cCurImage
- i
), i
);
2503 if (himl
->hbmMask
) {
2504 SelectObject (hdcBmp
, hbmNewMask
);
2505 imagelist_copy_images( himl
, himl
->hdcMask
, hdcBmp
, i
+ 1,
2506 (himl
->cCurImage
- i
), i
);
2512 /* delete old images and insert new ones */
2513 SelectObject (himl
->hdcImage
, hbmNewImage
);
2514 DeleteObject (himl
->hbmImage
);
2515 himl
->hbmImage
= hbmNewImage
;
2516 if (himl
->hbmMask
) {
2517 SelectObject (himl
->hdcMask
, hbmNewMask
);
2518 DeleteObject (himl
->hbmMask
);
2519 himl
->hbmMask
= hbmNewMask
;
2529 /*************************************************************************
2530 * ImageList_Replace [COMCTL32.@]
2532 * Replaces an image in an image list with a new image.
2535 * himl [I] handle to image list
2537 * hbmImage [I] handle to image bitmap
2538 * hbmMask [I] handle to mask bitmap. Can be NULL.
2546 ImageList_Replace (HIMAGELIST himl
, INT i
, HBITMAP hbmImage
,
2553 TRACE("%p %d %p %p\n", himl
, i
, hbmImage
, hbmMask
);
2555 if (!is_valid(himl
)) {
2556 ERR("Invalid image list handle!\n");
2560 if ((i
>= himl
->cMaxImage
) || (i
< 0)) {
2561 ERR("Invalid image index!\n");
2565 if (!GetObjectW(hbmImage
, sizeof(BITMAP
), &bmp
))
2568 hdcImage
= CreateCompatibleDC (0);
2571 SelectObject (hdcImage
, hbmImage
);
2573 if (add_with_alpha( himl
, hdcImage
, i
, 1, bmp
.bmWidth
, bmp
.bmHeight
, hbmImage
, hbmMask
))
2576 imagelist_point_from_index(himl
, i
, &pt
);
2577 StretchBlt (himl
->hdcImage
, pt
.x
, pt
.y
, himl
->cx
, himl
->cy
,
2578 hdcImage
, 0, 0, bmp
.bmWidth
, bmp
.bmHeight
, SRCCOPY
);
2583 HBITMAP hOldBitmapTemp
;
2585 hdcTemp
= CreateCompatibleDC(0);
2586 hOldBitmapTemp
= SelectObject(hdcTemp
, hbmMask
);
2588 StretchBlt (himl
->hdcMask
, pt
.x
, pt
.y
, himl
->cx
, himl
->cy
,
2589 hdcTemp
, 0, 0, bmp
.bmWidth
, bmp
.bmHeight
, SRCCOPY
);
2590 SelectObject(hdcTemp
, hOldBitmapTemp
);
2593 /* Remove the background from the image
2595 BitBlt (himl
->hdcImage
, pt
.x
, pt
.y
, bmp
.bmWidth
, bmp
.bmHeight
,
2596 himl
->hdcMask
, pt
.x
, pt
.y
, 0x220326); /* NOTSRCAND */
2600 DeleteDC (hdcImage
);
2606 /*************************************************************************
2607 * ImageList_ReplaceIcon [COMCTL32.@]
2609 * Replaces an image in an image list using an icon.
2612 * himl [I] handle to image list
2614 * hIcon [I] handle to icon
2617 * Success: index of the replaced image
2622 ImageList_ReplaceIcon (HIMAGELIST himl
, INT nIndex
, HICON hIcon
)
2630 TRACE("(%p %d %p)\n", himl
, nIndex
, hIcon
);
2632 if (!is_valid(himl
)) {
2633 ERR("invalid image list\n");
2636 if ((nIndex
>= himl
->cMaxImage
) || (nIndex
< -1)) {
2637 ERR("invalid image index %d / %d\n", nIndex
, himl
->cMaxImage
);
2641 hBestFitIcon
= CopyImage(
2644 LR_COPYFROMRESOURCE
);
2645 /* the above will fail if the icon wasn't loaded from a resource, so try
2646 * again without LR_COPYFROMRESOURCE flag */
2648 hBestFitIcon
= CopyImage(
2656 if (himl
->cCurImage
+ 1 >= himl
->cMaxImage
)
2657 IMAGELIST_InternalExpandBitmaps(himl
, 1);
2659 nIndex
= himl
->cCurImage
;
2663 if (himl
->has_alpha
&& GetIconInfo (hBestFitIcon
, &ii
))
2665 HDC hdcImage
= CreateCompatibleDC( 0 );
2666 GetObjectW (ii
.hbmMask
, sizeof(BITMAP
), &bmp
);
2670 UINT height
= bmp
.bmHeight
/ 2;
2671 HDC hdcMask
= CreateCompatibleDC( 0 );
2672 HBITMAP color
= CreateBitmap( bmp
.bmWidth
, height
, 1, 1, NULL
);
2673 SelectObject( hdcImage
, color
);
2674 SelectObject( hdcMask
, ii
.hbmMask
);
2675 BitBlt( hdcImage
, 0, 0, bmp
.bmWidth
, height
, hdcMask
, 0, height
, SRCCOPY
);
2676 ret
= add_with_alpha( himl
, hdcImage
, nIndex
, 1, bmp
.bmWidth
, height
, color
, ii
.hbmMask
);
2677 DeleteDC( hdcMask
);
2678 DeleteObject( color
);
2680 else ret
= add_with_alpha( himl
, hdcImage
, nIndex
, 1, bmp
.bmWidth
, bmp
.bmHeight
,
2681 ii
.hbmColor
, ii
.hbmMask
);
2683 DeleteDC( hdcImage
);
2684 DeleteObject (ii
.hbmMask
);
2685 if (ii
.hbmColor
) DeleteObject (ii
.hbmColor
);
2689 imagelist_point_from_index(himl
, nIndex
, &pt
);
2693 DrawIconEx( himl
->hdcImage
, pt
.x
, pt
.y
, hBestFitIcon
, himl
->cx
, himl
->cy
, 0, 0, DI_IMAGE
);
2694 PatBlt( himl
->hdcMask
, pt
.x
, pt
.y
, himl
->cx
, himl
->cy
, WHITENESS
);
2695 DrawIconEx( himl
->hdcMask
, pt
.x
, pt
.y
, hBestFitIcon
, himl
->cx
, himl
->cy
, 0, 0, DI_MASK
);
2699 COLORREF color
= himl
->clrBk
!= CLR_NONE
? himl
->clrBk
: comctl32_color
.clrWindow
;
2700 HBRUSH brush
= CreateSolidBrush( GetNearestColor( himl
->hdcImage
, color
));
2702 SelectObject( himl
->hdcImage
, brush
);
2703 PatBlt( himl
->hdcImage
, pt
.x
, pt
.y
, himl
->cx
, himl
->cy
, PATCOPY
);
2704 SelectObject( himl
->hdcImage
, GetStockObject(BLACK_BRUSH
) );
2705 DeleteObject( brush
);
2706 DrawIconEx( himl
->hdcImage
, pt
.x
, pt
.y
, hBestFitIcon
, himl
->cx
, himl
->cy
, 0, 0, DI_NORMAL
);
2710 DestroyIcon(hBestFitIcon
);
2712 TRACE("Insert index = %d, himl->cCurImage = %d\n", nIndex
, himl
->cCurImage
);
2717 /*************************************************************************
2718 * ImageList_SetBkColor [COMCTL32.@]
2720 * Sets the background color of an image list.
2723 * himl [I] handle to image list
2724 * clrBk [I] background color
2727 * Success: previous background color
2732 ImageList_SetBkColor (HIMAGELIST himl
, COLORREF clrBk
)
2736 if (!is_valid(himl
))
2739 clrOldBk
= himl
->clrBk
;
2740 himl
->clrBk
= clrBk
;
2745 /*************************************************************************
2746 * ImageList_SetDragCursorImage [COMCTL32.@]
2748 * Combines the specified image with the current drag image
2751 * himlDrag [I] handle to drag image list
2752 * iDrag [I] drag image index
2753 * dxHotspot [I] X position of the hot spot
2754 * dyHotspot [I] Y position of the hot spot
2761 * - The names dxHotspot, dyHotspot are misleading because they have nothing
2762 * to do with a hotspot but are only the offset of the origin of the new
2763 * image relative to the origin of the old image.
2765 * - When this function is called and the drag image is visible, a
2766 * short flickering occurs but this matches the Win9x behavior. It is
2767 * possible to fix the flickering using code like in ImageList_DragMove.
2771 ImageList_SetDragCursorImage (HIMAGELIST himlDrag
, INT iDrag
,
2772 INT dxHotspot
, INT dyHotspot
)
2774 HIMAGELIST himlTemp
;
2777 if (!is_valid(InternalDrag
.himl
) || !is_valid(himlDrag
))
2780 TRACE(" dxH=%d dyH=%d nX=%d nY=%d\n",
2781 dxHotspot
, dyHotspot
, InternalDrag
.dxHotspot
, InternalDrag
.dyHotspot
);
2783 visible
= InternalDrag
.bShow
;
2785 himlTemp
= ImageList_Merge (InternalDrag
.himlNoCursor
, 0, himlDrag
, iDrag
,
2786 dxHotspot
, dyHotspot
);
2789 /* hide the drag image */
2790 ImageList_DragShowNolock(FALSE
);
2792 if ((InternalDrag
.himl
->cx
!= himlTemp
->cx
) ||
2793 (InternalDrag
.himl
->cy
!= himlTemp
->cy
)) {
2794 /* the size of the drag image changed, invalidate the buffer */
2795 DeleteObject(InternalDrag
.hbmBg
);
2796 InternalDrag
.hbmBg
= 0;
2799 if (InternalDrag
.himl
!= InternalDrag
.himlNoCursor
)
2800 ImageList_Destroy (InternalDrag
.himl
);
2801 InternalDrag
.himl
= himlTemp
;
2804 /* show the drag image */
2805 ImageList_DragShowNolock(TRUE
);
2812 /*************************************************************************
2813 * ImageList_SetFilter [COMCTL32.@]
2815 * Sets a filter (or does something completely different)!!???
2816 * It removes 12 Bytes from the stack (3 Parameters).
2819 * himl [I] SHOULD be a handle to image list
2820 * i [I] COULD be an index?
2825 * Failure: FALSE ???
2828 * This is an UNDOCUMENTED function!!!!
2833 ImageList_SetFilter (HIMAGELIST himl
, INT i
, DWORD dwFilter
)
2835 FIXME("(%p 0x%x 0x%x):empty stub!\n", himl
, i
, dwFilter
);
2841 /*************************************************************************
2842 * ImageList_SetFlags [COMCTL32.@]
2844 * Sets the image list flags.
2847 * himl [I] Handle to image list
2848 * flags [I] Flags to set
2858 ImageList_SetFlags(HIMAGELIST himl
, DWORD flags
)
2860 FIXME("(%p %08x):empty stub\n", himl
, flags
);
2865 /*************************************************************************
2866 * ImageList_SetIconSize [COMCTL32.@]
2868 * Sets the image size of the bitmap and deletes all images.
2871 * himl [I] handle to image list
2872 * cx [I] image width
2873 * cy [I] image height
2881 ImageList_SetIconSize (HIMAGELIST himl
, INT cx
, INT cy
)
2886 if (!is_valid(himl
))
2889 /* remove all images */
2890 himl
->cMaxImage
= himl
->cInitial
+ 1;
2891 himl
->cCurImage
= 0;
2895 /* initialize overlay mask indices */
2896 for (nCount
= 0; nCount
< MAX_OVERLAYIMAGE
; nCount
++)
2897 himl
->nOvlIdx
[nCount
] = -1;
2899 hbmNew
= ImageList_CreateImage(himl
->hdcImage
, himl
, himl
->cMaxImage
);
2900 SelectObject (himl
->hdcImage
, hbmNew
);
2901 DeleteObject (himl
->hbmImage
);
2902 himl
->hbmImage
= hbmNew
;
2904 if (himl
->hbmMask
) {
2906 imagelist_get_bitmap_size(himl
, himl
->cMaxImage
, &sz
);
2907 hbmNew
= CreateBitmap (sz
.cx
, sz
.cy
, 1, 1, NULL
);
2908 SelectObject (himl
->hdcMask
, hbmNew
);
2909 DeleteObject (himl
->hbmMask
);
2910 himl
->hbmMask
= hbmNew
;
2917 /*************************************************************************
2918 * ImageList_SetImageCount [COMCTL32.@]
2920 * Resizes an image list to the specified number of images.
2923 * himl [I] handle to image list
2924 * iImageCount [I] number of images in the image list
2932 ImageList_SetImageCount (HIMAGELIST himl
, UINT iImageCount
)
2935 HBITMAP hbmNewBitmap
, hbmOld
;
2936 INT nNewCount
, nCopyCount
;
2938 TRACE("%p %d\n",himl
,iImageCount
);
2940 if (!is_valid(himl
))
2943 nNewCount
= iImageCount
+ 1;
2944 nCopyCount
= min(himl
->cCurImage
, iImageCount
);
2946 hdcBitmap
= CreateCompatibleDC (0);
2948 hbmNewBitmap
= ImageList_CreateImage(hdcBitmap
, himl
, nNewCount
);
2950 if (hbmNewBitmap
!= 0)
2952 hbmOld
= SelectObject (hdcBitmap
, hbmNewBitmap
);
2953 imagelist_copy_images( himl
, himl
->hdcImage
, hdcBitmap
, 0, nCopyCount
, 0 );
2954 SelectObject (hdcBitmap
, hbmOld
);
2956 /* FIXME: delete 'empty' image space? */
2958 SelectObject (himl
->hdcImage
, hbmNewBitmap
);
2959 DeleteObject (himl
->hbmImage
);
2960 himl
->hbmImage
= hbmNewBitmap
;
2963 ERR("Could not create new image bitmap!\n");
2968 imagelist_get_bitmap_size( himl
, nNewCount
, &sz
);
2969 hbmNewBitmap
= CreateBitmap (sz
.cx
, sz
.cy
, 1, 1, NULL
);
2970 if (hbmNewBitmap
!= 0)
2972 hbmOld
= SelectObject (hdcBitmap
, hbmNewBitmap
);
2973 imagelist_copy_images( himl
, himl
->hdcMask
, hdcBitmap
, 0, nCopyCount
, 0 );
2974 SelectObject (hdcBitmap
, hbmOld
);
2976 /* FIXME: delete 'empty' image space? */
2978 SelectObject (himl
->hdcMask
, hbmNewBitmap
);
2979 DeleteObject (himl
->hbmMask
);
2980 himl
->hbmMask
= hbmNewBitmap
;
2983 ERR("Could not create new mask bitmap!\n");
2986 DeleteDC (hdcBitmap
);
2988 if (himl
->has_alpha
)
2990 char *new_alpha
= HeapReAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, himl
->has_alpha
, nNewCount
);
2991 if (new_alpha
) himl
->has_alpha
= new_alpha
;
2994 HeapFree( GetProcessHeap(), 0, himl
->has_alpha
);
2995 himl
->has_alpha
= NULL
;
2999 /* Update max image count and current image count */
3000 himl
->cMaxImage
= nNewCount
;
3001 himl
->cCurImage
= iImageCount
;
3007 /*************************************************************************
3008 * ImageList_SetOverlayImage [COMCTL32.@]
3010 * Assigns an overlay mask index to an existing image in an image list.
3013 * himl [I] handle to image list
3014 * iImage [I] image index
3015 * iOverlay [I] overlay mask index
3023 ImageList_SetOverlayImage (HIMAGELIST himl
, INT iImage
, INT iOverlay
)
3025 if (!is_valid(himl
))
3027 if ((iOverlay
< 1) || (iOverlay
> MAX_OVERLAYIMAGE
))
3029 if ((iImage
!=-1) && ((iImage
< 0) || (iImage
> himl
->cCurImage
)))
3031 himl
->nOvlIdx
[iOverlay
- 1] = iImage
;
3037 /* helper for ImageList_Write - write bitmap to pstm
3038 * currently everything is written as 24 bit RGB, except masks
3041 _write_bitmap(HBITMAP hBitmap
, LPSTREAM pstm
)
3043 LPBITMAPFILEHEADER bmfh
;
3044 LPBITMAPINFOHEADER bmih
;
3045 LPBYTE data
= NULL
, lpBits
;
3047 INT bitCount
, sizeImage
, offBits
, totalSize
;
3049 BOOL result
= FALSE
;
3051 if (!GetObjectW(hBitmap
, sizeof(BITMAP
), &bm
))
3054 bitCount
= bm
.bmBitsPixel
;
3055 sizeImage
= get_dib_stride(bm
.bmWidth
, bitCount
) * bm
.bmHeight
;
3057 totalSize
= sizeof(BITMAPFILEHEADER
) + sizeof(BITMAPINFOHEADER
);
3059 totalSize
+= (1 << bitCount
) * sizeof(RGBQUAD
);
3060 offBits
= totalSize
;
3061 totalSize
+= sizeImage
;
3063 data
= Alloc(totalSize
);
3064 bmfh
= (LPBITMAPFILEHEADER
)data
;
3065 bmih
= (LPBITMAPINFOHEADER
)(data
+ sizeof(BITMAPFILEHEADER
));
3066 lpBits
= data
+ offBits
;
3068 /* setup BITMAPFILEHEADER */
3069 bmfh
->bfType
= (('M' << 8) | 'B');
3070 bmfh
->bfSize
= offBits
;
3071 bmfh
->bfReserved1
= 0;
3072 bmfh
->bfReserved2
= 0;
3073 bmfh
->bfOffBits
= offBits
;
3075 /* setup BITMAPINFOHEADER */
3076 bmih
->biSize
= sizeof(BITMAPINFOHEADER
);
3077 bmih
->biWidth
= bm
.bmWidth
;
3078 bmih
->biHeight
= bm
.bmHeight
;
3080 bmih
->biBitCount
= bitCount
;
3081 bmih
->biCompression
= BI_RGB
;
3082 bmih
->biSizeImage
= sizeImage
;
3083 bmih
->biXPelsPerMeter
= 0;
3084 bmih
->biYPelsPerMeter
= 0;
3085 bmih
->biClrUsed
= 0;
3086 bmih
->biClrImportant
= 0;
3089 result
= GetDIBits(xdc
, hBitmap
, 0, bm
.bmHeight
, lpBits
, (BITMAPINFO
*)bmih
, DIB_RGB_COLORS
) == bm
.bmHeight
;
3094 TRACE("width %u, height %u, planes %u, bpp %u\n",
3095 bmih
->biWidth
, bmih
->biHeight
,
3096 bmih
->biPlanes
, bmih
->biBitCount
);
3098 if(FAILED(IStream_Write(pstm
, data
, totalSize
, NULL
)))
3110 /*************************************************************************
3111 * ImageList_Write [COMCTL32.@]
3113 * Writes an image list to a stream.
3116 * himl [I] handle to image list
3117 * pstm [O] Pointer to a stream.
3128 ImageList_Write (HIMAGELIST himl
, LPSTREAM pstm
)
3133 TRACE("%p %p\n", himl
, pstm
);
3135 if (!is_valid(himl
))
3138 ilHead
.usMagic
= (('L' << 8) | 'I');
3139 ilHead
.usVersion
= 0x101;
3140 ilHead
.cCurImage
= himl
->cCurImage
;
3141 ilHead
.cMaxImage
= himl
->cMaxImage
;
3142 ilHead
.cGrow
= himl
->cGrow
;
3143 ilHead
.cx
= himl
->cx
;
3144 ilHead
.cy
= himl
->cy
;
3145 ilHead
.bkcolor
= himl
->clrBk
;
3146 ilHead
.flags
= himl
->flags
;
3147 for(i
= 0; i
< 4; i
++) {
3148 ilHead
.ovls
[i
] = himl
->nOvlIdx
[i
];
3151 TRACE("cx %u, cy %u, flags 0x04%x, cCurImage %u, cMaxImage %u\n",
3152 ilHead
.cx
, ilHead
.cy
, ilHead
.flags
, ilHead
.cCurImage
, ilHead
.cMaxImage
);
3154 if(FAILED(IStream_Write(pstm
, &ilHead
, sizeof(ILHEAD
), NULL
)))
3157 /* write the bitmap */
3158 if(!_write_bitmap(himl
->hbmImage
, pstm
))
3161 /* write the mask if we have one */
3162 if(himl
->flags
& ILC_MASK
) {
3163 if(!_write_bitmap(himl
->hbmMask
, pstm
))
3171 static HBITMAP
ImageList_CreateImage(HDC hdc
, HIMAGELIST himl
, UINT count
)
3173 HBITMAP hbmNewBitmap
;
3174 UINT ilc
= (himl
->flags
& 0xFE);
3177 imagelist_get_bitmap_size( himl
, count
, &sz
);
3179 if ((ilc
>= ILC_COLOR4
&& ilc
<= ILC_COLOR32
) || ilc
== ILC_COLOR
)
3181 char buffer
[sizeof(BITMAPINFOHEADER
) + 256 * sizeof(RGBQUAD
)];
3182 BITMAPINFO
*bmi
= (BITMAPINFO
*)buffer
;
3184 TRACE("Creating DIBSection %d x %d, %d Bits per Pixel\n",
3185 sz
.cx
, sz
.cy
, himl
->uBitsPixel
);
3187 memset( buffer
, 0, sizeof(buffer
) );
3188 bmi
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
3189 bmi
->bmiHeader
.biWidth
= sz
.cx
;
3190 bmi
->bmiHeader
.biHeight
= sz
.cy
;
3191 bmi
->bmiHeader
.biPlanes
= 1;
3192 bmi
->bmiHeader
.biBitCount
= himl
->uBitsPixel
;
3193 bmi
->bmiHeader
.biCompression
= BI_RGB
;
3195 if (himl
->uBitsPixel
<= ILC_COLOR8
)
3197 /* retrieve the default color map */
3198 HBITMAP tmp
= CreateBitmap( 1, 1, 1, 1, NULL
);
3199 GetDIBits( hdc
, tmp
, 0, 0, NULL
, bmi
, DIB_RGB_COLORS
);
3200 DeleteObject( tmp
);
3202 hbmNewBitmap
= CreateDIBSection(hdc
, bmi
, DIB_RGB_COLORS
, NULL
, 0, 0);
3204 else /*if (ilc == ILC_COLORDDB)*/
3206 TRACE("Creating Bitmap: %d Bits per Pixel\n", himl
->uBitsPixel
);
3208 hbmNewBitmap
= CreateBitmap (sz
.cx
, sz
.cy
, 1, himl
->uBitsPixel
, NULL
);
3210 TRACE("returning %p\n", hbmNewBitmap
);
3211 return hbmNewBitmap
;
3214 /*************************************************************************
3215 * ImageList_SetColorTable [COMCTL32.@]
3217 * Sets the color table of an image list.
3220 * himl [I] Handle to the image list.
3221 * uStartIndex [I] The first index to set.
3222 * cEntries [I] Number of entries to set.
3223 * prgb [I] New color information for color table for the image list.
3226 * Success: Number of entries in the table that were set.
3230 * ImageList_Create(), SetDIBColorTable()
3234 ImageList_SetColorTable(HIMAGELIST himl
, UINT uStartIndex
, UINT cEntries
, const RGBQUAD
*prgb
)
3236 return SetDIBColorTable(himl
->hdcImage
, uStartIndex
, cEntries
, prgb
);
3239 /*************************************************************************
3240 * ImageList_CoCreateInstance [COMCTL32.@]
3242 * Creates a new imagelist instance and returns an interface pointer to it.
3245 * rclsid [I] A reference to the CLSID (CLSID_ImageList).
3246 * punkOuter [I] Pointer to IUnknown interface for aggregation, if desired
3247 * riid [I] Identifier of the requested interface.
3248 * ppv [O] Returns the address of the pointer requested, or NULL.
3252 * Failure: Error value.
3255 ImageList_CoCreateInstance (REFCLSID rclsid
, const IUnknown
*punkOuter
, REFIID riid
, void **ppv
)
3257 TRACE("(%s,%p,%s,%p)\n", debugstr_guid(rclsid
), punkOuter
, debugstr_guid(riid
), ppv
);
3259 if (!IsEqualCLSID(&CLSID_ImageList
, rclsid
))
3260 return E_NOINTERFACE
;
3262 return ImageListImpl_CreateInstance(punkOuter
, riid
, ppv
);
3266 /*************************************************************************
3267 * IImageList implementation
3270 static HRESULT WINAPI
ImageListImpl_QueryInterface(IImageList2
*iface
,
3271 REFIID iid
, void **ppv
)
3273 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3275 TRACE("(%p,%s,%p)\n", iface
, debugstr_guid(iid
), ppv
);
3277 if (!ppv
) return E_INVALIDARG
;
3279 if (IsEqualIID(&IID_IUnknown
, iid
) ||
3280 IsEqualIID(&IID_IImageList
, iid
) ||
3281 IsEqualIID(&IID_IImageList2
, iid
))
3283 *ppv
= &imgl
->IImageList2_iface
;
3288 return E_NOINTERFACE
;
3291 IImageList2_AddRef(iface
);
3295 static ULONG WINAPI
ImageListImpl_AddRef(IImageList2
*iface
)
3297 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3298 ULONG ref
= InterlockedIncrement(&imgl
->ref
);
3300 TRACE("(%p) refcount=%u\n", iface
, ref
);
3304 static ULONG WINAPI
ImageListImpl_Release(IImageList2
*iface
)
3306 HIMAGELIST This
= impl_from_IImageList2(iface
);
3307 ULONG ref
= InterlockedDecrement(&This
->ref
);
3309 TRACE("(%p) refcount=%u\n", iface
, ref
);
3313 /* delete image bitmaps */
3314 if (This
->hbmImage
) DeleteObject (This
->hbmImage
);
3315 if (This
->hbmMask
) DeleteObject (This
->hbmMask
);
3317 /* delete image & mask DCs */
3318 if (This
->hdcImage
) DeleteDC (This
->hdcImage
);
3319 if (This
->hdcMask
) DeleteDC (This
->hdcMask
);
3321 /* delete blending brushes */
3322 if (This
->hbrBlend25
) DeleteObject (This
->hbrBlend25
);
3323 if (This
->hbrBlend50
) DeleteObject (This
->hbrBlend50
);
3325 This
->IImageList2_iface
.lpVtbl
= NULL
;
3326 HeapFree(GetProcessHeap(), 0, This
->has_alpha
);
3327 HeapFree(GetProcessHeap(), 0, This
);
3333 static HRESULT WINAPI
ImageListImpl_Add(IImageList2
*iface
, HBITMAP hbmImage
,
3334 HBITMAP hbmMask
, int *pi
)
3336 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3342 ret
= ImageList_Add(imgl
, hbmImage
, hbmMask
);
3351 static HRESULT WINAPI
ImageListImpl_ReplaceIcon(IImageList2
*iface
, int i
,
3352 HICON hicon
, int *pi
)
3354 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3360 ret
= ImageList_ReplaceIcon(imgl
, i
, hicon
);
3369 static HRESULT WINAPI
ImageListImpl_SetOverlayImage(IImageList2
*iface
,
3370 int iImage
, int iOverlay
)
3372 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3373 return ImageList_SetOverlayImage(imgl
, iImage
, iOverlay
) ? S_OK
: E_FAIL
;
3376 static HRESULT WINAPI
ImageListImpl_Replace(IImageList2
*iface
, int i
,
3377 HBITMAP hbmImage
, HBITMAP hbmMask
)
3379 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3380 return ImageList_Replace(imgl
, i
, hbmImage
, hbmMask
) ? S_OK
: E_FAIL
;
3383 static HRESULT WINAPI
ImageListImpl_AddMasked(IImageList2
*iface
, HBITMAP hbmImage
,
3384 COLORREF crMask
, int *pi
)
3386 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3392 ret
= ImageList_AddMasked(imgl
, hbmImage
, crMask
);
3401 static HRESULT WINAPI
ImageListImpl_Draw(IImageList2
*iface
,
3402 IMAGELISTDRAWPARAMS
*pimldp
)
3404 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3405 HIMAGELIST old_himl
;
3408 /* As far as I can tell, Windows simply ignores the contents of pimldp->himl
3409 so we shall simulate the same */
3410 old_himl
= pimldp
->himl
;
3411 pimldp
->himl
= imgl
;
3413 ret
= ImageList_DrawIndirect(pimldp
);
3415 pimldp
->himl
= old_himl
;
3416 return ret
? S_OK
: E_INVALIDARG
;
3419 static HRESULT WINAPI
ImageListImpl_Remove(IImageList2
*iface
, int i
)
3421 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3422 return (ImageList_Remove(imgl
, i
) == 0) ? E_INVALIDARG
: S_OK
;
3425 static HRESULT WINAPI
ImageListImpl_GetIcon(IImageList2
*iface
, int i
, UINT flags
,
3428 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3434 hIcon
= ImageList_GetIcon(imgl
, i
, flags
);
3443 static HRESULT WINAPI
ImageListImpl_GetImageInfo(IImageList2
*iface
, int i
,
3444 IMAGEINFO
*pImageInfo
)
3446 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3447 return ImageList_GetImageInfo(imgl
, i
, pImageInfo
) ? S_OK
: E_FAIL
;
3450 static HRESULT WINAPI
ImageListImpl_Copy(IImageList2
*iface
, int dst_index
,
3451 IUnknown
*unk_src
, int src_index
, UINT flags
)
3453 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3454 IImageList
*src
= NULL
;
3460 /* TODO: Add test for IID_ImageList2 too */
3461 if (FAILED(IUnknown_QueryInterface(unk_src
, &IID_IImageList
,
3465 if (ImageList_Copy(imgl
, dst_index
, (HIMAGELIST
) src
, src_index
, flags
))
3470 IImageList_Release(src
);
3474 static HRESULT WINAPI
ImageListImpl_Merge(IImageList2
*iface
, int i1
,
3475 IUnknown
*punk2
, int i2
, int dx
, int dy
, REFIID riid
, void **ppv
)
3477 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3478 IImageList
*iml2
= NULL
;
3480 HRESULT ret
= E_FAIL
;
3482 TRACE("(%p)->(%d %p %d %d %d %s %p)\n", iface
, i1
, punk2
, i2
, dx
, dy
, debugstr_guid(riid
), ppv
);
3484 /* TODO: Add test for IID_ImageList2 too */
3485 if (FAILED(IUnknown_QueryInterface(punk2
, &IID_IImageList
,
3489 merged
= ImageList_Merge(imgl
, i1
, (HIMAGELIST
) iml2
, i2
, dx
, dy
);
3491 /* Get the interface for the new image list */
3494 ret
= HIMAGELIST_QueryInterface(merged
, riid
, ppv
);
3495 ImageList_Destroy(merged
);
3498 IImageList_Release(iml2
);
3502 static HRESULT WINAPI
ImageListImpl_Clone(IImageList2
*iface
, REFIID riid
, void **ppv
)
3504 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3506 HRESULT ret
= E_FAIL
;
3508 TRACE("(%p)->(%s %p)\n", iface
, debugstr_guid(riid
), ppv
);
3510 clone
= ImageList_Duplicate(imgl
);
3512 /* Get the interface for the new image list */
3515 ret
= HIMAGELIST_QueryInterface(clone
, riid
, ppv
);
3516 ImageList_Destroy(clone
);
3522 static HRESULT WINAPI
ImageListImpl_GetImageRect(IImageList2
*iface
, int i
,
3525 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3531 if (!ImageList_GetImageInfo(imgl
, i
, &info
))
3534 return CopyRect(prc
, &info
.rcImage
) ? S_OK
: E_FAIL
;
3537 static HRESULT WINAPI
ImageListImpl_GetIconSize(IImageList2
*iface
, int *cx
,
3540 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3541 return ImageList_GetIconSize(imgl
, cx
, cy
) ? S_OK
: E_INVALIDARG
;
3544 static HRESULT WINAPI
ImageListImpl_SetIconSize(IImageList2
*iface
, int cx
,
3547 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3548 return ImageList_SetIconSize(imgl
, cx
, cy
) ? S_OK
: E_FAIL
;
3551 static HRESULT WINAPI
ImageListImpl_GetImageCount(IImageList2
*iface
, int *pi
)
3553 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3554 *pi
= ImageList_GetImageCount(imgl
);
3558 static HRESULT WINAPI
ImageListImpl_SetImageCount(IImageList2
*iface
, UINT count
)
3560 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3561 return ImageList_SetImageCount(imgl
, count
) ? S_OK
: E_FAIL
;
3564 static HRESULT WINAPI
ImageListImpl_SetBkColor(IImageList2
*iface
, COLORREF clrBk
,
3567 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3568 *pclr
= ImageList_SetBkColor(imgl
, clrBk
);
3572 static HRESULT WINAPI
ImageListImpl_GetBkColor(IImageList2
*iface
, COLORREF
*pclr
)
3574 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3575 *pclr
= ImageList_GetBkColor(imgl
);
3579 static HRESULT WINAPI
ImageListImpl_BeginDrag(IImageList2
*iface
, int iTrack
,
3580 int dxHotspot
, int dyHotspot
)
3582 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3583 return ImageList_BeginDrag(imgl
, iTrack
, dxHotspot
, dyHotspot
) ? S_OK
: E_FAIL
;
3586 static HRESULT WINAPI
ImageListImpl_EndDrag(IImageList2
*iface
)
3588 ImageList_EndDrag();
3592 static HRESULT WINAPI
ImageListImpl_DragEnter(IImageList2
*iface
, HWND hwndLock
,
3595 return ImageList_DragEnter(hwndLock
, x
, y
) ? S_OK
: E_FAIL
;
3598 static HRESULT WINAPI
ImageListImpl_DragLeave(IImageList2
*iface
, HWND hwndLock
)
3600 return ImageList_DragLeave(hwndLock
) ? S_OK
: E_FAIL
;
3603 static HRESULT WINAPI
ImageListImpl_DragMove(IImageList2
*iface
, int x
, int y
)
3605 return ImageList_DragMove(x
, y
) ? S_OK
: E_FAIL
;
3608 static HRESULT WINAPI
ImageListImpl_SetDragCursorImage(IImageList2
*iface
,
3609 IUnknown
*punk
, int iDrag
, int dxHotspot
, int dyHotspot
)
3611 IImageList
*iml2
= NULL
;
3617 /* TODO: Add test for IID_ImageList2 too */
3618 if (FAILED(IUnknown_QueryInterface(punk
, &IID_IImageList
,
3622 ret
= ImageList_SetDragCursorImage((HIMAGELIST
) iml2
, iDrag
, dxHotspot
,
3625 IImageList_Release(iml2
);
3627 return ret
? S_OK
: E_FAIL
;
3630 static HRESULT WINAPI
ImageListImpl_DragShowNolock(IImageList2
*iface
, BOOL fShow
)
3632 return ImageList_DragShowNolock(fShow
) ? S_OK
: E_FAIL
;
3635 static HRESULT WINAPI
ImageListImpl_GetDragImage(IImageList2
*iface
, POINT
*ppt
,
3636 POINT
*pptHotspot
, REFIID riid
, PVOID
*ppv
)
3638 HRESULT ret
= E_FAIL
;
3644 hNew
= ImageList_GetDragImage(ppt
, pptHotspot
);
3646 /* Get the interface for the new image list */
3649 IImageList
*idrag
= (IImageList
*)hNew
;
3651 ret
= HIMAGELIST_QueryInterface(hNew
, riid
, ppv
);
3652 IImageList_Release(idrag
);
3658 static HRESULT WINAPI
ImageListImpl_GetItemFlags(IImageList2
*iface
, int i
,
3661 FIXME("STUB: %p %d %p\n", iface
, i
, dwFlags
);
3665 static HRESULT WINAPI
ImageListImpl_GetOverlayImage(IImageList2
*iface
, int iOverlay
,
3668 HIMAGELIST This
= impl_from_IImageList2(iface
);
3671 if ((iOverlay
< 0) || (iOverlay
> This
->cCurImage
))
3674 for (i
= 0; i
< MAX_OVERLAYIMAGE
; i
++)
3676 if (This
->nOvlIdx
[i
] == iOverlay
)
3686 static HRESULT WINAPI
ImageListImpl_Resize(IImageList2
*iface
, INT cx
, INT cy
)
3688 FIXME("(%p)->(%d %d): stub\n", iface
, cx
, cy
);
3692 static HRESULT WINAPI
ImageListImpl_GetOriginalSize(IImageList2
*iface
, INT image
, DWORD flags
, INT
*cx
, INT
*cy
)
3694 FIXME("(%p)->(%d %x %p %p): stub\n", iface
, image
, flags
, cx
, cy
);
3698 static HRESULT WINAPI
ImageListImpl_SetOriginalSize(IImageList2
*iface
, INT image
, INT cx
, INT cy
)
3700 FIXME("(%p)->(%d %d %d): stub\n", iface
, image
, cx
, cy
);
3704 static HRESULT WINAPI
ImageListImpl_SetCallback(IImageList2
*iface
, IUnknown
*callback
)
3706 FIXME("(%p)->(%p): stub\n", iface
, callback
);
3710 static HRESULT WINAPI
ImageListImpl_GetCallback(IImageList2
*iface
, REFIID riid
, void **ppv
)
3712 FIXME("(%p)->(%s %p): stub\n", iface
, debugstr_guid(riid
), ppv
);
3716 static HRESULT WINAPI
ImageListImpl_ForceImagePresent(IImageList2
*iface
, INT image
, DWORD flags
)
3718 FIXME("(%p)->(%d %x): stub\n", iface
, image
, flags
);
3722 static HRESULT WINAPI
ImageListImpl_DiscardImages(IImageList2
*iface
, INT first_image
, INT last_image
, DWORD flags
)
3724 FIXME("(%p)->(%d %d %x): stub\n", iface
, first_image
, last_image
, flags
);
3728 static HRESULT WINAPI
ImageListImpl_PreloadImages(IImageList2
*iface
, IMAGELISTDRAWPARAMS
*params
)
3730 FIXME("(%p)->(%p): stub\n", iface
, params
);
3734 static HRESULT WINAPI
ImageListImpl_GetStatistics(IImageList2
*iface
, IMAGELISTSTATS
*stats
)
3736 FIXME("(%p)->(%p): stub\n", iface
, stats
);
3740 static HRESULT WINAPI
ImageListImpl_Initialize(IImageList2
*iface
, INT cx
, INT cy
, UINT flags
, INT initial
, INT grow
)
3742 FIXME("(%p)->(%d %d %d %d %d): stub\n", iface
, cx
, cy
, flags
, initial
, grow
);
3746 static HRESULT WINAPI
ImageListImpl_Replace2(IImageList2
*iface
, INT i
, HBITMAP image
, HBITMAP mask
, IUnknown
*unk
, DWORD flags
)
3748 FIXME("(%p)->(%d %p %p %p %x): stub\n", iface
, i
, image
, mask
, unk
, flags
);
3752 static HRESULT WINAPI
ImageListImpl_ReplaceFromImageList(IImageList2
*iface
, INT i
, IImageList
*imagelist
, INT src
,
3753 IUnknown
*unk
, DWORD flags
)
3755 FIXME("(%p)->(%d %p %d %p %x): stub\n", iface
, i
, imagelist
, src
, unk
, flags
);
3759 static const IImageList2Vtbl ImageListImpl_Vtbl
= {
3760 ImageListImpl_QueryInterface
,
3761 ImageListImpl_AddRef
,
3762 ImageListImpl_Release
,
3764 ImageListImpl_ReplaceIcon
,
3765 ImageListImpl_SetOverlayImage
,
3766 ImageListImpl_Replace
,
3767 ImageListImpl_AddMasked
,
3769 ImageListImpl_Remove
,
3770 ImageListImpl_GetIcon
,
3771 ImageListImpl_GetImageInfo
,
3773 ImageListImpl_Merge
,
3774 ImageListImpl_Clone
,
3775 ImageListImpl_GetImageRect
,
3776 ImageListImpl_GetIconSize
,
3777 ImageListImpl_SetIconSize
,
3778 ImageListImpl_GetImageCount
,
3779 ImageListImpl_SetImageCount
,
3780 ImageListImpl_SetBkColor
,
3781 ImageListImpl_GetBkColor
,
3782 ImageListImpl_BeginDrag
,
3783 ImageListImpl_EndDrag
,
3784 ImageListImpl_DragEnter
,
3785 ImageListImpl_DragLeave
,
3786 ImageListImpl_DragMove
,
3787 ImageListImpl_SetDragCursorImage
,
3788 ImageListImpl_DragShowNolock
,
3789 ImageListImpl_GetDragImage
,
3790 ImageListImpl_GetItemFlags
,
3791 ImageListImpl_GetOverlayImage
,
3792 ImageListImpl_Resize
,
3793 ImageListImpl_GetOriginalSize
,
3794 ImageListImpl_SetOriginalSize
,
3795 ImageListImpl_SetCallback
,
3796 ImageListImpl_GetCallback
,
3797 ImageListImpl_ForceImagePresent
,
3798 ImageListImpl_DiscardImages
,
3799 ImageListImpl_PreloadImages
,
3800 ImageListImpl_GetStatistics
,
3801 ImageListImpl_Initialize
,
3802 ImageListImpl_Replace2
,
3803 ImageListImpl_ReplaceFromImageList
3806 static BOOL
is_valid(HIMAGELIST himl
)
3811 valid
= himl
&& himl
->IImageList2_iface
.lpVtbl
== &ImageListImpl_Vtbl
;
3821 /*************************************************************************
3822 * HIMAGELIST_QueryInterface [COMCTL32.@]
3824 * Returns a pointer to an IImageList or IImageList2 object for the given
3828 * himl [I] Image list handle.
3829 * riid [I] Identifier of the requested interface.
3830 * ppv [O] Returns the address of the pointer requested, or NULL.
3834 * Failure: Error value.
3837 HIMAGELIST_QueryInterface (HIMAGELIST himl
, REFIID riid
, void **ppv
)
3839 TRACE("(%p,%s,%p)\n", himl
, debugstr_guid(riid
), ppv
);
3840 return IImageList2_QueryInterface((IImageList2
*) himl
, riid
, ppv
);
3843 static HRESULT
ImageListImpl_CreateInstance(const IUnknown
*pUnkOuter
, REFIID iid
, void** ppv
)
3848 TRACE("(%p,%s,%p)\n", pUnkOuter
, debugstr_guid(iid
), ppv
);
3852 if (pUnkOuter
) return CLASS_E_NOAGGREGATION
;
3854 This
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(struct _IMAGELIST
));
3855 if (!This
) return E_OUTOFMEMORY
;
3857 This
->IImageList2_iface
.lpVtbl
= &ImageListImpl_Vtbl
;
3860 ret
= IImageList2_QueryInterface(&This
->IImageList2_iface
, iid
, ppv
);
3861 IImageList2_Release(&This
->IImageList2_iface
);