2 * ImageList implementation
4 * Copyright 1998 Eric Kohl
5 * Copyright 2000 Jason Mawdsley
6 * Copyright 2001, 2004 Michael Stefaniuc
7 * Copyright 2001 Charles Loep for CodeWeavers
8 * Copyright 2002 Dimitrie O. Paun
9 * Copyright 2009 Owen Rudge for CodeWeavers
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public
13 * License as published by the Free Software Foundation; either
14 * version 2.1 of the License, or (at your option) any later version.
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with this library; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
27 * This code was audited for completeness against the documented features
28 * of Comctl32.dll version 6.0 on Sep. 12, 2002, by Dimitrie O. Paun.
30 * Unless otherwise noted, we believe this code to be complete, as per
31 * the specification mentioned above.
32 * If you discover missing features, or bugs, please note them below.
35 * - Add support for ILD_PRESERVEALPHA, ILD_SCALE, ILD_DPISCALE
36 * - Add support for ILS_GLOW, ILS_SHADOW, ILS_SATURATE
37 * - Thread-safe locking
54 #include "commoncontrols.h"
55 #include "wine/debug.h"
56 #include "wine/exception.h"
58 WINE_DEFAULT_DEBUG_CHANNEL(imagelist
);
60 #define MAX_OVERLAYIMAGE 15
64 IImageList2 IImageList2_iface
; /* 00: IImageList vtable */
65 INT cCurImage
; /* 04: ImageCount */
66 INT cMaxImage
; /* 08: maximages */
67 INT cGrow
; /* 0C: cGrow */
71 UINT flags
; /* 1C: flags */
72 COLORREF clrFg
; /* 20: foreground color */
73 COLORREF clrBk
; /* 24: background color */
76 HBITMAP hbmImage
; /* 28: images Bitmap */
77 HBITMAP hbmMask
; /* 2C: masks Bitmap */
78 HDC hdcImage
; /* 30: images MemDC */
79 HDC hdcMask
; /* 34: masks MemDC */
80 INT nOvlIdx
[MAX_OVERLAYIMAGE
]; /* 38: overlay images index */
82 /* not yet found out */
89 LONG ref
; /* reference count */
92 #define IMAGELIST_MAGIC 0x53414D58
94 /* Header used by ImageList_Read() and ImageList_Write() */
96 typedef struct _ILHEAD
111 /* internal image list data used for Drag & Drop operations */
116 HIMAGELIST himlNoCursor
;
117 /* position of the drag image relative to the window */
120 /* offset of the hotspot relative to the origin of the image */
123 /* is the drag image visible */
125 /* saved background */
129 static INTERNALDRAG InternalDrag
= { 0, 0, 0, 0, 0, 0, 0, FALSE
, 0 };
131 static inline HIMAGELIST
impl_from_IImageList2(IImageList2
*iface
)
133 return CONTAINING_RECORD(iface
, struct _IMAGELIST
, IImageList2_iface
);
136 static HBITMAP
ImageList_CreateImage(HDC hdc
, HIMAGELIST himl
, UINT count
);
137 static HRESULT
ImageListImpl_CreateInstance(const IUnknown
*pUnkOuter
, REFIID iid
, void** ppv
);
138 static inline BOOL
is_valid(HIMAGELIST himl
);
141 * An imagelist with N images is tiled like this:
153 static inline UINT
imagelist_height( UINT count
)
155 return ((count
+ TILE_COUNT
- 1)/TILE_COUNT
);
158 static inline void imagelist_point_from_index( HIMAGELIST himl
, UINT index
, LPPOINT pt
)
160 pt
->x
= (index
%TILE_COUNT
) * himl
->cx
;
161 pt
->y
= (index
/TILE_COUNT
) * himl
->cy
;
164 static inline void imagelist_get_bitmap_size( HIMAGELIST himl
, UINT count
, SIZE
*sz
)
166 sz
->cx
= himl
->cx
* TILE_COUNT
;
167 sz
->cy
= imagelist_height( count
) * himl
->cy
;
170 static inline int get_dib_stride( int width
, int bpp
)
172 return ((width
* bpp
+ 31) >> 3) & ~3;
175 static inline int get_dib_image_size( const BITMAPINFO
*info
)
177 return get_dib_stride( info
->bmiHeader
.biWidth
, info
->bmiHeader
.biBitCount
)
178 * abs( info
->bmiHeader
.biHeight
);
182 * imagelist_copy_images()
184 * Copies a block of count images from offset src in the list to offset dest.
185 * Images are copied a row at at time. Assumes hdcSrc and hdcDest are different.
187 static inline void imagelist_copy_images( HIMAGELIST himl
, HDC hdcSrc
, HDC hdcDest
,
188 UINT src
, UINT count
, UINT dest
)
194 for ( i
=0; i
<TILE_COUNT
; i
++ )
196 imagelist_point_from_index( himl
, src
+i
, &ptSrc
);
197 imagelist_point_from_index( himl
, dest
+i
, &ptDest
);
199 sz
.cy
= himl
->cy
* imagelist_height( count
- i
);
201 BitBlt( hdcDest
, ptDest
.x
, ptDest
.y
, sz
.cx
, sz
.cy
,
202 hdcSrc
, ptSrc
.x
, ptSrc
.y
, SRCCOPY
);
206 static void add_dib_bits( HIMAGELIST himl
, int pos
, int count
, int width
, int height
,
207 BITMAPINFO
*info
, BITMAPINFO
*mask_info
, DWORD
*bits
, BYTE
*mask_bits
)
211 int stride
= info
->bmiHeader
.biWidth
;
212 int mask_stride
= (info
->bmiHeader
.biWidth
+ 31) / 32 * 4;
214 for (n
= 0; n
< count
; n
++)
216 BOOL has_alpha
= FALSE
;
218 imagelist_point_from_index( himl
, pos
+ n
, &pt
);
220 /* check if bitmap has an alpha channel */
221 for (i
= 0; i
< height
&& !has_alpha
; i
++)
222 for (j
= n
* width
; j
< (n
+ 1) * width
; j
++)
223 if ((has_alpha
= ((bits
[i
* stride
+ j
] & 0xff000000) != 0))) break;
225 if (!has_alpha
) /* generate alpha channel from the mask */
227 for (i
= 0; i
< height
; i
++)
228 for (j
= n
* width
; j
< (n
+ 1) * width
; j
++)
229 if (!mask_info
|| !((mask_bits
[i
* mask_stride
+ j
/ 8] << (j
% 8)) & 0x80))
230 bits
[i
* stride
+ j
] |= 0xff000000;
232 bits
[i
* stride
+ j
] = 0;
236 himl
->has_alpha
[pos
+ n
] = 1;
238 if (mask_info
&& himl
->hbmMask
) /* generate the mask from the alpha channel */
240 for (i
= 0; i
< height
; i
++)
241 for (j
= n
* width
; j
< (n
+ 1) * width
; j
++)
242 if ((bits
[i
* stride
+ j
] >> 24) > 25) /* more than 10% alpha */
243 mask_bits
[i
* mask_stride
+ j
/ 8] &= ~(0x80 >> (j
% 8));
245 mask_bits
[i
* mask_stride
+ j
/ 8] |= 0x80 >> (j
% 8);
248 StretchDIBits( himl
->hdcImage
, pt
.x
, pt
.y
, himl
->cx
, himl
->cy
,
249 n
* width
, 0, width
, height
, bits
, info
, DIB_RGB_COLORS
, SRCCOPY
);
251 StretchDIBits( himl
->hdcMask
, pt
.x
, pt
.y
, himl
->cx
, himl
->cy
,
252 n
* width
, 0, width
, height
, mask_bits
, mask_info
, DIB_RGB_COLORS
, SRCCOPY
);
256 /* add images with an alpha channel when the image list is 32 bpp */
257 static BOOL
add_with_alpha( HIMAGELIST himl
, HDC hdc
, int pos
, int count
,
258 int width
, int height
, HBITMAP hbmImage
, HBITMAP hbmMask
)
262 BITMAPINFO
*info
, *mask_info
= NULL
;
264 BYTE
*mask_bits
= NULL
;
267 if (!GetObjectW( hbmImage
, sizeof(bm
), &bm
)) return FALSE
;
269 /* if either the imagelist or the source bitmap don't have an alpha channel, bail out now */
270 if (!himl
->has_alpha
) return FALSE
;
271 if (bm
.bmBitsPixel
!= 32) return FALSE
;
273 SelectObject( hdc
, hbmImage
);
274 mask_width
= (bm
.bmWidth
+ 31) / 32 * 4;
276 if (!(info
= HeapAlloc( GetProcessHeap(), 0, FIELD_OFFSET( BITMAPINFO
, bmiColors
[256] )))) goto done
;
277 info
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
278 info
->bmiHeader
.biWidth
= bm
.bmWidth
;
279 info
->bmiHeader
.biHeight
= -height
;
280 info
->bmiHeader
.biPlanes
= 1;
281 info
->bmiHeader
.biBitCount
= 32;
282 info
->bmiHeader
.biCompression
= BI_RGB
;
283 info
->bmiHeader
.biSizeImage
= bm
.bmWidth
* height
* 4;
284 info
->bmiHeader
.biXPelsPerMeter
= 0;
285 info
->bmiHeader
.biYPelsPerMeter
= 0;
286 info
->bmiHeader
.biClrUsed
= 0;
287 info
->bmiHeader
.biClrImportant
= 0;
288 if (!(bits
= HeapAlloc( GetProcessHeap(), 0, info
->bmiHeader
.biSizeImage
))) goto done
;
289 if (!GetDIBits( hdc
, hbmImage
, 0, height
, bits
, info
, DIB_RGB_COLORS
)) goto done
;
293 if (!(mask_info
= HeapAlloc( GetProcessHeap(), 0, FIELD_OFFSET( BITMAPINFO
, bmiColors
[2] ))))
295 mask_info
->bmiHeader
= info
->bmiHeader
;
296 mask_info
->bmiHeader
.biBitCount
= 1;
297 mask_info
->bmiHeader
.biSizeImage
= mask_width
* height
;
298 if (!(mask_bits
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, info
->bmiHeader
.biSizeImage
)))
300 if (!GetDIBits( hdc
, hbmMask
, 0, height
, mask_bits
, mask_info
, DIB_RGB_COLORS
)) goto done
;
303 add_dib_bits( himl
, pos
, count
, width
, height
, info
, mask_info
, bits
, mask_bits
);
307 HeapFree( GetProcessHeap(), 0, info
);
308 HeapFree( GetProcessHeap(), 0, mask_info
);
309 HeapFree( GetProcessHeap(), 0, bits
);
310 HeapFree( GetProcessHeap(), 0, mask_bits
);
314 /*************************************************************************
315 * IMAGELIST_InternalExpandBitmaps [Internal]
317 * Expands the bitmaps of an image list by the given number of images.
320 * himl [I] handle to image list
321 * nImageCount [I] number of images to add
327 * This function CANNOT be used to reduce the number of images.
330 IMAGELIST_InternalExpandBitmaps(HIMAGELIST himl
, INT nImageCount
)
333 HBITMAP hbmNewBitmap
, hbmNull
;
337 TRACE("%p has allocated %d, max %d, grow %d images\n", himl
, himl
->cCurImage
, himl
->cMaxImage
, himl
->cGrow
);
339 if (himl
->cCurImage
+ nImageCount
< himl
->cMaxImage
)
342 nNewCount
= himl
->cMaxImage
+ max(nImageCount
, himl
->cGrow
) + 1;
344 imagelist_get_bitmap_size(himl
, nNewCount
, &sz
);
346 TRACE("Create expanded bitmaps : himl=%p x=%d y=%d count=%d\n", himl
, sz
.cx
, sz
.cy
, nNewCount
);
347 hdcBitmap
= CreateCompatibleDC (0);
349 hbmNewBitmap
= ImageList_CreateImage(hdcBitmap
, himl
, nNewCount
);
351 if (hbmNewBitmap
== 0)
352 ERR("creating new image bitmap (x=%d y=%d)!\n", sz
.cx
, sz
.cy
);
356 hbmNull
= SelectObject (hdcBitmap
, hbmNewBitmap
);
357 BitBlt (hdcBitmap
, 0, 0, sz
.cx
, sz
.cy
,
358 himl
->hdcImage
, 0, 0, SRCCOPY
);
359 SelectObject (hdcBitmap
, hbmNull
);
361 SelectObject (himl
->hdcImage
, hbmNewBitmap
);
362 DeleteObject (himl
->hbmImage
);
363 himl
->hbmImage
= hbmNewBitmap
;
365 if (himl
->flags
& ILC_MASK
)
367 hbmNewBitmap
= CreateBitmap (sz
.cx
, sz
.cy
, 1, 1, NULL
);
369 if (hbmNewBitmap
== 0)
370 ERR("creating new mask bitmap!\n");
374 hbmNull
= SelectObject (hdcBitmap
, hbmNewBitmap
);
375 BitBlt (hdcBitmap
, 0, 0, sz
.cx
, sz
.cy
,
376 himl
->hdcMask
, 0, 0, SRCCOPY
);
377 SelectObject (hdcBitmap
, hbmNull
);
379 SelectObject (himl
->hdcMask
, hbmNewBitmap
);
380 DeleteObject (himl
->hbmMask
);
381 himl
->hbmMask
= hbmNewBitmap
;
386 char *new_alpha
= HeapReAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, himl
->has_alpha
, nNewCount
);
387 if (new_alpha
) himl
->has_alpha
= new_alpha
;
390 HeapFree( GetProcessHeap(), 0, himl
->has_alpha
);
391 himl
->has_alpha
= NULL
;
395 himl
->cMaxImage
= nNewCount
;
397 DeleteDC (hdcBitmap
);
401 /*************************************************************************
402 * ImageList_Add [COMCTL32.@]
404 * Add an image or images to an image list.
407 * himl [I] handle to image list
408 * hbmImage [I] handle to image bitmap
409 * hbmMask [I] handle to mask bitmap
412 * Success: Index of the first new image.
417 ImageList_Add (HIMAGELIST himl
, HBITMAP hbmImage
, HBITMAP hbmMask
)
419 HDC hdcBitmap
, hdcTemp
= 0;
420 INT nFirstIndex
, nImageCount
, i
;
424 TRACE("himl=%p hbmimage=%p hbmmask=%p\n", himl
, hbmImage
, hbmMask
);
428 if (!GetObjectW(hbmImage
, sizeof(BITMAP
), &bmp
))
431 TRACE("himl %p, cCurImage %d, cMaxImage %d, cGrow %d, cx %d, cy %d\n",
432 himl
, himl
->cCurImage
, himl
->cMaxImage
, himl
->cGrow
, himl
->cx
, himl
->cy
);
434 nImageCount
= bmp
.bmWidth
/ himl
->cx
;
436 TRACE("%p has %d images (%d x %d)\n", hbmImage
, nImageCount
, bmp
.bmWidth
, bmp
.bmHeight
);
438 IMAGELIST_InternalExpandBitmaps(himl
, nImageCount
);
440 hdcBitmap
= CreateCompatibleDC(0);
442 SelectObject(hdcBitmap
, hbmImage
);
444 if (add_with_alpha( himl
, hdcBitmap
, himl
->cCurImage
, nImageCount
,
445 himl
->cx
, min( himl
->cy
, bmp
.bmHeight
), hbmImage
, hbmMask
))
450 hdcTemp
= CreateCompatibleDC(0);
451 SelectObject(hdcTemp
, hbmMask
);
454 for (i
=0; i
<nImageCount
; i
++)
456 imagelist_point_from_index( himl
, himl
->cCurImage
+ i
, &pt
);
458 /* Copy result to the imagelist
460 BitBlt( himl
->hdcImage
, pt
.x
, pt
.y
, himl
->cx
, bmp
.bmHeight
,
461 hdcBitmap
, i
*himl
->cx
, 0, SRCCOPY
);
466 BitBlt( himl
->hdcMask
, pt
.x
, pt
.y
, himl
->cx
, bmp
.bmHeight
,
467 hdcTemp
, i
*himl
->cx
, 0, SRCCOPY
);
469 /* Remove the background from the image
471 BitBlt( himl
->hdcImage
, pt
.x
, pt
.y
, himl
->cx
, bmp
.bmHeight
,
472 himl
->hdcMask
, pt
.x
, pt
.y
, 0x220326 ); /* NOTSRCAND */
474 if (hdcTemp
) DeleteDC(hdcTemp
);
479 nFirstIndex
= himl
->cCurImage
;
480 himl
->cCurImage
+= nImageCount
;
486 /*************************************************************************
487 * ImageList_AddIcon [COMCTL32.@]
489 * Adds an icon to an image list.
492 * himl [I] handle to image list
493 * hIcon [I] handle to icon
496 * Success: index of the new image
499 #undef ImageList_AddIcon
500 INT WINAPI
ImageList_AddIcon (HIMAGELIST himl
, HICON hIcon
)
502 return ImageList_ReplaceIcon (himl
, -1, hIcon
);
506 /*************************************************************************
507 * ImageList_AddMasked [COMCTL32.@]
509 * Adds an image or images to an image list and creates a mask from the
510 * specified bitmap using the mask color.
513 * himl [I] handle to image list.
514 * hBitmap [I] handle to bitmap
515 * clrMask [I] mask color.
518 * Success: Index of the first new image.
523 ImageList_AddMasked (HIMAGELIST himl
, HBITMAP hBitmap
, COLORREF clrMask
)
525 HDC hdcMask
, hdcBitmap
;
531 TRACE("himl=%p hbitmap=%p clrmask=%x\n", himl
, hBitmap
, clrMask
);
535 if (!GetObjectW(hBitmap
, sizeof(BITMAP
), &bmp
))
538 hdcBitmap
= CreateCompatibleDC(0);
539 SelectObject(hdcBitmap
, hBitmap
);
541 /* Create a temp Mask so we can remove the background of the Image */
542 hdcMask
= CreateCompatibleDC(0);
543 hMaskBitmap
= CreateBitmap(bmp
.bmWidth
, bmp
.bmHeight
, 1, 1, NULL
);
544 SelectObject(hdcMask
, hMaskBitmap
);
546 /* create monochrome image to the mask bitmap */
547 bkColor
= (clrMask
!= CLR_DEFAULT
) ? clrMask
: GetPixel (hdcBitmap
, 0, 0);
548 SetBkColor (hdcBitmap
, bkColor
);
549 BitBlt (hdcMask
, 0, 0, bmp
.bmWidth
, bmp
.bmHeight
, hdcBitmap
, 0, 0, SRCCOPY
);
552 * Remove the background from the image
554 * WINDOWS BUG ALERT!!!!!!
555 * The statement below should not be done in common practice
556 * but this is how ImageList_AddMasked works in Windows.
557 * It overwrites the original bitmap passed, this was discovered
558 * by using the same bitmap to iterate the different styles
559 * on windows where it failed (BUT ImageList_Add is OK)
560 * This is here in case some apps rely on this bug
562 * Blt mode 0x220326 is NOTSRCAND
564 if (bmp
.bmBitsPixel
> 8) /* NOTSRCAND can't work with palettes */
566 SetBkColor(hdcBitmap
, RGB(255,255,255));
567 BitBlt(hdcBitmap
, 0, 0, bmp
.bmWidth
, bmp
.bmHeight
, hdcMask
, 0, 0, 0x220326);
573 ret
= ImageList_Add( himl
, hBitmap
, hMaskBitmap
);
575 DeleteObject(hMaskBitmap
);
580 /*************************************************************************
581 * ImageList_BeginDrag [COMCTL32.@]
583 * Creates a temporary image list that contains one image. It will be used
587 * himlTrack [I] handle to the source image list
588 * iTrack [I] index of the drag image in the source image list
589 * dxHotspot [I] X position of the hot spot of the drag image
590 * dyHotspot [I] Y position of the hot spot of the drag image
598 ImageList_BeginDrag (HIMAGELIST himlTrack
, INT iTrack
,
599 INT dxHotspot
, INT dyHotspot
)
603 TRACE("(himlTrack=%p iTrack=%d dx=%d dy=%d)\n", himlTrack
, iTrack
,
604 dxHotspot
, dyHotspot
);
606 if (!is_valid(himlTrack
))
609 if (InternalDrag
.himl
)
610 ImageList_EndDrag ();
615 InternalDrag
.himlNoCursor
= InternalDrag
.himl
= ImageList_Create (cx
, cy
, himlTrack
->flags
, 1, 1);
616 if (InternalDrag
.himl
== NULL
) {
617 WARN("Error creating drag image list!\n");
621 InternalDrag
.dxHotspot
= dxHotspot
;
622 InternalDrag
.dyHotspot
= dyHotspot
;
625 BitBlt (InternalDrag
.himl
->hdcImage
, 0, 0, cx
, cy
, himlTrack
->hdcImage
, iTrack
* cx
, 0, SRCCOPY
);
628 BitBlt (InternalDrag
.himl
->hdcMask
, 0, 0, cx
, cy
, himlTrack
->hdcMask
, iTrack
* cx
, 0, SRCCOPY
);
630 InternalDrag
.himl
->cCurImage
= 1;
636 /*************************************************************************
637 * ImageList_Copy [COMCTL32.@]
639 * Copies an image of the source image list to an image of the
640 * destination image list. Images can be copied or swapped.
643 * himlDst [I] handle to the destination image list
644 * iDst [I] destination image index.
645 * himlSrc [I] handle to the source image list
646 * iSrc [I] source image index
647 * uFlags [I] flags for the copy operation
654 * Copying from one image list to another is possible. The original
655 * implementation just copies or swaps within one image list.
656 * Could this feature become a bug??? ;-)
660 ImageList_Copy (HIMAGELIST himlDst
, INT iDst
, HIMAGELIST himlSrc
,
661 INT iSrc
, UINT uFlags
)
665 TRACE("himlDst=%p iDst=%d himlSrc=%p iSrc=%d\n", himlDst
, iDst
, himlSrc
, iSrc
);
667 if (!is_valid(himlSrc
) || !is_valid(himlDst
))
669 if ((iDst
< 0) || (iDst
>= himlDst
->cCurImage
))
671 if ((iSrc
< 0) || (iSrc
>= himlSrc
->cCurImage
))
674 imagelist_point_from_index( himlDst
, iDst
, &ptDst
);
675 imagelist_point_from_index( himlSrc
, iSrc
, &ptSrc
);
677 if (uFlags
& ILCF_SWAP
) {
680 HBITMAP hbmTempImage
, hbmTempMask
;
682 hdcBmp
= CreateCompatibleDC (0);
684 /* create temporary bitmaps */
685 hbmTempImage
= CreateBitmap (himlSrc
->cx
, himlSrc
->cy
, 1,
686 himlSrc
->uBitsPixel
, NULL
);
687 hbmTempMask
= CreateBitmap (himlSrc
->cx
, himlSrc
->cy
, 1,
690 /* copy (and stretch) destination to temporary bitmaps.(save) */
692 SelectObject (hdcBmp
, hbmTempImage
);
693 StretchBlt (hdcBmp
, 0, 0, himlSrc
->cx
, himlSrc
->cy
,
694 himlDst
->hdcImage
, ptDst
.x
, ptDst
.y
, himlDst
->cx
, himlDst
->cy
,
697 SelectObject (hdcBmp
, hbmTempMask
);
698 StretchBlt (hdcBmp
, 0, 0, himlSrc
->cx
, himlSrc
->cy
,
699 himlDst
->hdcMask
, ptDst
.x
, ptDst
.y
, himlDst
->cx
, himlDst
->cy
,
702 /* copy (and stretch) source to destination */
704 StretchBlt (himlDst
->hdcImage
, ptDst
.x
, ptDst
.y
, himlDst
->cx
, himlDst
->cy
,
705 himlSrc
->hdcImage
, ptSrc
.x
, ptSrc
.y
, himlSrc
->cx
, himlSrc
->cy
,
708 StretchBlt (himlDst
->hdcMask
, ptDst
.x
, ptDst
.y
, himlDst
->cx
, himlDst
->cy
,
709 himlSrc
->hdcMask
, ptSrc
.x
, ptSrc
.y
, himlSrc
->cx
, himlSrc
->cy
,
712 /* copy (without stretching) temporary bitmaps to source (restore) */
714 BitBlt (himlSrc
->hdcMask
, ptSrc
.x
, ptSrc
.y
, himlSrc
->cx
, himlSrc
->cy
,
715 hdcBmp
, 0, 0, SRCCOPY
);
718 BitBlt (himlSrc
->hdcImage
, ptSrc
.x
, ptSrc
.y
, himlSrc
->cx
, himlSrc
->cy
,
719 hdcBmp
, 0, 0, SRCCOPY
);
720 /* delete temporary bitmaps */
721 DeleteObject (hbmTempMask
);
722 DeleteObject (hbmTempImage
);
727 StretchBlt (himlDst
->hdcImage
, ptDst
.x
, ptDst
.y
, himlDst
->cx
, himlDst
->cy
,
728 himlSrc
->hdcImage
, ptSrc
.x
, ptSrc
.y
, himlSrc
->cx
, himlSrc
->cy
,
732 StretchBlt (himlDst
->hdcMask
, ptDst
.x
, ptDst
.y
, himlDst
->cx
, himlDst
->cy
,
733 himlSrc
->hdcMask
, ptSrc
.x
, ptSrc
.y
, himlSrc
->cx
, himlSrc
->cy
,
741 /*************************************************************************
742 * ImageList_Create [COMCTL32.@]
744 * Creates a new image list.
747 * cx [I] image height
749 * flags [I] creation flags
750 * cInitial [I] initial number of images in the image list
751 * cGrow [I] number of images by which image list grows
754 * Success: Handle to the created image list
758 ImageList_Create (INT cx
, INT cy
, UINT flags
,
759 INT cInitial
, INT cGrow
)
764 UINT ilc
= (flags
& 0xFE);
765 static const WORD aBitBlend25
[] =
766 {0xAA, 0x00, 0x55, 0x00, 0xAA, 0x00, 0x55, 0x00};
768 static const WORD aBitBlend50
[] =
769 {0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA};
771 TRACE("(%d %d 0x%x %d %d)\n", cx
, cy
, flags
, cInitial
, cGrow
);
773 if (cx
<= 0 || cy
<= 0) return NULL
;
775 /* Create the IImageList interface for the image list */
776 if (FAILED(ImageListImpl_CreateInstance(NULL
, &IID_IImageList
, (void **)&himl
)))
779 cGrow
= (WORD
)((max( cGrow
, 1 ) + 3) & ~3);
783 /* Windows doesn't limit the size here, but X11 doesn't let us allocate such huge bitmaps */
784 WARN( "grow %d too large, limiting to 256\n", cGrow
);
791 himl
->cMaxImage
= cInitial
+ 1;
792 himl
->cInitial
= cInitial
;
794 himl
->clrFg
= CLR_DEFAULT
;
795 himl
->clrBk
= CLR_NONE
;
797 /* initialize overlay mask indices */
798 for (nCount
= 0; nCount
< MAX_OVERLAYIMAGE
; nCount
++)
799 himl
->nOvlIdx
[nCount
] = -1;
801 /* Create Image & Mask DCs */
802 himl
->hdcImage
= CreateCompatibleDC (0);
805 if (himl
->flags
& ILC_MASK
){
806 himl
->hdcMask
= CreateCompatibleDC(0);
811 /* Default to ILC_COLOR4 if none of the ILC_COLOR* flags are specified */
812 if (ilc
== ILC_COLOR
)
815 himl
->flags
|= ILC_COLOR4
;
818 if (ilc
>= ILC_COLOR4
&& ilc
<= ILC_COLOR32
)
819 himl
->uBitsPixel
= ilc
;
821 himl
->uBitsPixel
= (UINT
)GetDeviceCaps (himl
->hdcImage
, BITSPIXEL
);
823 if (himl
->cMaxImage
> 0) {
824 himl
->hbmImage
= ImageList_CreateImage(himl
->hdcImage
, himl
, himl
->cMaxImage
);
825 SelectObject(himl
->hdcImage
, himl
->hbmImage
);
829 if ((himl
->cMaxImage
> 0) && (himl
->flags
& ILC_MASK
)) {
832 imagelist_get_bitmap_size(himl
, himl
->cMaxImage
, &sz
);
833 himl
->hbmMask
= CreateBitmap (sz
.cx
, sz
.cy
, 1, 1, NULL
);
834 if (himl
->hbmMask
== 0) {
835 ERR("Error creating mask bitmap!\n");
838 SelectObject(himl
->hdcMask
, himl
->hbmMask
);
843 if (ilc
== ILC_COLOR32
)
844 himl
->has_alpha
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, himl
->cMaxImage
);
846 himl
->has_alpha
= NULL
;
848 /* create blending brushes */
849 hbmTemp
= CreateBitmap (8, 8, 1, 1, aBitBlend25
);
850 himl
->hbrBlend25
= CreatePatternBrush (hbmTemp
);
851 DeleteObject (hbmTemp
);
853 hbmTemp
= CreateBitmap (8, 8, 1, 1, aBitBlend50
);
854 himl
->hbrBlend50
= CreatePatternBrush (hbmTemp
);
855 DeleteObject (hbmTemp
);
857 TRACE("created imagelist %p\n", himl
);
861 ImageList_Destroy(himl
);
866 /*************************************************************************
867 * ImageList_Destroy [COMCTL32.@]
869 * Destroys an image list.
872 * himl [I] handle to image list
880 ImageList_Destroy (HIMAGELIST himl
)
885 IImageList_Release((IImageList
*) himl
);
890 /*************************************************************************
891 * ImageList_DragEnter [COMCTL32.@]
893 * Locks window update and displays the drag image at the given position.
896 * hwndLock [I] handle of the window that owns the drag image.
897 * x [I] X position of the drag image.
898 * y [I] Y position of the drag image.
905 * The position of the drag image is relative to the window, not
910 ImageList_DragEnter (HWND hwndLock
, INT x
, INT y
)
912 TRACE("(hwnd=%p x=%d y=%d)\n", hwndLock
, x
, y
);
914 if (!is_valid(InternalDrag
.himl
))
918 InternalDrag
.hwnd
= hwndLock
;
920 InternalDrag
.hwnd
= GetDesktopWindow ();
925 /* draw the drag image and save the background */
926 if (!ImageList_DragShowNolock(TRUE
)) {
934 /*************************************************************************
935 * ImageList_DragLeave [COMCTL32.@]
937 * Unlocks window update and hides the drag image.
940 * hwndLock [I] handle of the window that owns the drag image.
948 ImageList_DragLeave (HWND hwndLock
)
950 /* As we don't save drag info in the window this can lead to problems if
951 an app does not supply the same window as DragEnter */
953 InternalDrag.hwnd = hwndLock;
955 InternalDrag.hwnd = GetDesktopWindow (); */
957 hwndLock
= GetDesktopWindow();
958 if(InternalDrag
.hwnd
!= hwndLock
)
959 FIXME("DragLeave hWnd != DragEnter hWnd\n");
961 ImageList_DragShowNolock (FALSE
);
967 /*************************************************************************
968 * ImageList_InternalDragDraw [Internal]
970 * Draws the drag image.
973 * hdc [I] device context to draw into.
974 * x [I] X position of the drag image.
975 * y [I] Y position of the drag image.
982 * The position of the drag image is relative to the window, not
988 ImageList_InternalDragDraw (HDC hdc
, INT x
, INT y
)
990 IMAGELISTDRAWPARAMS imldp
;
992 ZeroMemory (&imldp
, sizeof(imldp
));
993 imldp
.cbSize
= sizeof(imldp
);
994 imldp
.himl
= InternalDrag
.himl
;
999 imldp
.rgbBk
= CLR_DEFAULT
;
1000 imldp
.rgbFg
= CLR_DEFAULT
;
1001 imldp
.fStyle
= ILD_NORMAL
;
1002 imldp
.fState
= ILS_ALPHA
;
1004 ImageList_DrawIndirect (&imldp
);
1007 /*************************************************************************
1008 * ImageList_DragMove [COMCTL32.@]
1010 * Moves the drag image.
1013 * x [I] X position of the drag image.
1014 * y [I] Y position of the drag image.
1021 * The position of the drag image is relative to the window, not
1026 ImageList_DragMove (INT x
, INT y
)
1028 TRACE("(x=%d y=%d)\n", x
, y
);
1030 if (!is_valid(InternalDrag
.himl
))
1033 /* draw/update the drag image */
1034 if (InternalDrag
.bShow
) {
1038 HBITMAP hbmOffScreen
;
1039 INT origNewX
, origNewY
;
1040 INT origOldX
, origOldY
;
1041 INT origRegX
, origRegY
;
1042 INT sizeRegX
, sizeRegY
;
1045 /* calculate the update region */
1046 origNewX
= x
- InternalDrag
.dxHotspot
;
1047 origNewY
= y
- InternalDrag
.dyHotspot
;
1048 origOldX
= InternalDrag
.x
- InternalDrag
.dxHotspot
;
1049 origOldY
= InternalDrag
.y
- InternalDrag
.dyHotspot
;
1050 origRegX
= min(origNewX
, origOldX
);
1051 origRegY
= min(origNewY
, origOldY
);
1052 sizeRegX
= InternalDrag
.himl
->cx
+ abs(x
- InternalDrag
.x
);
1053 sizeRegY
= InternalDrag
.himl
->cy
+ abs(y
- InternalDrag
.y
);
1055 hdcDrag
= GetDCEx(InternalDrag
.hwnd
, 0,
1056 DCX_WINDOW
| DCX_CACHE
| DCX_LOCKWINDOWUPDATE
);
1057 hdcOffScreen
= CreateCompatibleDC(hdcDrag
);
1058 hdcBg
= CreateCompatibleDC(hdcDrag
);
1060 hbmOffScreen
= CreateCompatibleBitmap(hdcDrag
, sizeRegX
, sizeRegY
);
1061 SelectObject(hdcOffScreen
, hbmOffScreen
);
1062 SelectObject(hdcBg
, InternalDrag
.hbmBg
);
1064 /* get the actual background of the update region */
1065 BitBlt(hdcOffScreen
, 0, 0, sizeRegX
, sizeRegY
, hdcDrag
,
1066 origRegX
, origRegY
, SRCCOPY
);
1067 /* erase the old image */
1068 BitBlt(hdcOffScreen
, origOldX
- origRegX
, origOldY
- origRegY
,
1069 InternalDrag
.himl
->cx
, InternalDrag
.himl
->cy
, hdcBg
, 0, 0,
1071 /* save the background */
1072 BitBlt(hdcBg
, 0, 0, InternalDrag
.himl
->cx
, InternalDrag
.himl
->cy
,
1073 hdcOffScreen
, origNewX
- origRegX
, origNewY
- origRegY
, SRCCOPY
);
1074 /* draw the image */
1075 ImageList_InternalDragDraw(hdcOffScreen
, origNewX
- origRegX
,
1076 origNewY
- origRegY
);
1077 /* draw the update region to the screen */
1078 BitBlt(hdcDrag
, origRegX
, origRegY
, sizeRegX
, sizeRegY
,
1079 hdcOffScreen
, 0, 0, SRCCOPY
);
1082 DeleteDC(hdcOffScreen
);
1083 DeleteObject(hbmOffScreen
);
1084 ReleaseDC(InternalDrag
.hwnd
, hdcDrag
);
1087 /* update the image position */
1095 /*************************************************************************
1096 * ImageList_DragShowNolock [COMCTL32.@]
1098 * Shows or hides the drag image.
1101 * bShow [I] TRUE shows the drag image, FALSE hides it.
1109 ImageList_DragShowNolock (BOOL bShow
)
1115 if (!is_valid(InternalDrag
.himl
))
1118 TRACE("bShow=0x%X!\n", bShow
);
1120 /* DragImage is already visible/hidden */
1121 if ((InternalDrag
.bShow
&& bShow
) || (!InternalDrag
.bShow
&& !bShow
)) {
1125 /* position of the origin of the DragImage */
1126 x
= InternalDrag
.x
- InternalDrag
.dxHotspot
;
1127 y
= InternalDrag
.y
- InternalDrag
.dyHotspot
;
1129 hdcDrag
= GetDCEx (InternalDrag
.hwnd
, 0,
1130 DCX_WINDOW
| DCX_CACHE
| DCX_LOCKWINDOWUPDATE
);
1135 hdcBg
= CreateCompatibleDC(hdcDrag
);
1136 if (!InternalDrag
.hbmBg
) {
1137 InternalDrag
.hbmBg
= CreateCompatibleBitmap(hdcDrag
,
1138 InternalDrag
.himl
->cx
, InternalDrag
.himl
->cy
);
1140 SelectObject(hdcBg
, InternalDrag
.hbmBg
);
1143 /* save the background */
1144 BitBlt(hdcBg
, 0, 0, InternalDrag
.himl
->cx
, InternalDrag
.himl
->cy
,
1145 hdcDrag
, x
, y
, SRCCOPY
);
1146 /* show the image */
1147 ImageList_InternalDragDraw(hdcDrag
, x
, y
);
1149 /* hide the image */
1150 BitBlt(hdcDrag
, x
, y
, InternalDrag
.himl
->cx
, InternalDrag
.himl
->cy
,
1151 hdcBg
, 0, 0, SRCCOPY
);
1154 InternalDrag
.bShow
= !InternalDrag
.bShow
;
1157 ReleaseDC (InternalDrag
.hwnd
, hdcDrag
);
1162 /*************************************************************************
1163 * ImageList_Draw [COMCTL32.@]
1168 * himl [I] handle to image list
1170 * hdc [I] handle to device context
1173 * fStyle [I] drawing flags
1184 ImageList_Draw (HIMAGELIST himl
, INT i
, HDC hdc
, INT x
, INT y
, UINT fStyle
)
1186 return ImageList_DrawEx (himl
, i
, hdc
, x
, y
, 0, 0,
1187 CLR_DEFAULT
, CLR_DEFAULT
, fStyle
);
1191 /*************************************************************************
1192 * ImageList_DrawEx [COMCTL32.@]
1194 * Draws an image and allows using extended drawing features.
1197 * himl [I] handle to image list
1199 * hdc [I] handle to device context
1204 * rgbBk [I] background color
1205 * rgbFg [I] foreground color
1206 * fStyle [I] drawing flags
1213 * Calls ImageList_DrawIndirect.
1216 * ImageList_DrawIndirect.
1220 ImageList_DrawEx (HIMAGELIST himl
, INT i
, HDC hdc
, INT x
, INT y
,
1221 INT dx
, INT dy
, COLORREF rgbBk
, COLORREF rgbFg
,
1224 IMAGELISTDRAWPARAMS imldp
;
1226 ZeroMemory (&imldp
, sizeof(imldp
));
1227 imldp
.cbSize
= sizeof(imldp
);
1235 imldp
.rgbBk
= rgbBk
;
1236 imldp
.rgbFg
= rgbFg
;
1237 imldp
.fStyle
= fStyle
;
1239 return ImageList_DrawIndirect (&imldp
);
1243 static BOOL
alpha_blend_image( HIMAGELIST himl
, HDC dest_dc
, int dest_x
, int dest_y
,
1244 int src_x
, int src_y
, int cx
, int cy
, BLENDFUNCTION func
,
1245 UINT style
, COLORREF blend_col
)
1249 HBITMAP bmp
= 0, mask
= 0;
1251 void *bits
, *mask_bits
;
1255 if (!(hdc
= CreateCompatibleDC( 0 ))) return FALSE
;
1256 if (!(info
= HeapAlloc( GetProcessHeap(), 0, FIELD_OFFSET( BITMAPINFO
, bmiColors
[256] )))) goto done
;
1257 info
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
1258 info
->bmiHeader
.biWidth
= cx
;
1259 info
->bmiHeader
.biHeight
= cy
;
1260 info
->bmiHeader
.biPlanes
= 1;
1261 info
->bmiHeader
.biBitCount
= 32;
1262 info
->bmiHeader
.biCompression
= BI_RGB
;
1263 info
->bmiHeader
.biSizeImage
= cx
* cy
* 4;
1264 info
->bmiHeader
.biXPelsPerMeter
= 0;
1265 info
->bmiHeader
.biYPelsPerMeter
= 0;
1266 info
->bmiHeader
.biClrUsed
= 0;
1267 info
->bmiHeader
.biClrImportant
= 0;
1268 if (!(bmp
= CreateDIBSection( himl
->hdcImage
, info
, DIB_RGB_COLORS
, &bits
, 0, 0 ))) goto done
;
1269 SelectObject( hdc
, bmp
);
1270 BitBlt( hdc
, 0, 0, cx
, cy
, himl
->hdcImage
, src_x
, src_y
, SRCCOPY
);
1272 if (blend_col
!= CLR_NONE
)
1274 BYTE r
= GetRValue( blend_col
);
1275 BYTE g
= GetGValue( blend_col
);
1276 BYTE b
= GetBValue( blend_col
);
1278 if (style
& ILD_BLEND25
)
1280 for (i
= 0, ptr
= bits
; i
< cx
* cy
; i
++, ptr
++)
1281 *ptr
= ((*ptr
& 0xff000000) |
1282 ((((*ptr
& 0x00ff0000) * 3 + (r
<< 16)) / 4) & 0x00ff0000) |
1283 ((((*ptr
& 0x0000ff00) * 3 + (g
<< 8)) / 4) & 0x0000ff00) |
1284 ((((*ptr
& 0x000000ff) * 3 + (b
<< 0)) / 4) & 0x000000ff));
1286 else if (style
& ILD_BLEND50
)
1288 for (i
= 0, ptr
= bits
; i
< cx
* cy
; i
++, ptr
++)
1289 *ptr
= ((*ptr
& 0xff000000) |
1290 ((((*ptr
& 0x00ff0000) + (r
<< 16)) / 2) & 0x00ff0000) |
1291 ((((*ptr
& 0x0000ff00) + (g
<< 8)) / 2) & 0x0000ff00) |
1292 ((((*ptr
& 0x000000ff) + (b
<< 0)) / 2) & 0x000000ff));
1296 if (himl
->has_alpha
) /* we already have an alpha channel in this case */
1298 /* pre-multiply by the alpha channel */
1299 for (i
= 0, ptr
= bits
; i
< cx
* cy
; i
++, ptr
++)
1301 DWORD alpha
= *ptr
>> 24;
1302 *ptr
= ((*ptr
& 0xff000000) |
1303 (((*ptr
& 0x00ff0000) * alpha
/ 255) & 0x00ff0000) |
1304 (((*ptr
& 0x0000ff00) * alpha
/ 255) & 0x0000ff00) |
1305 (((*ptr
& 0x000000ff) * alpha
/ 255)));
1308 else if (himl
->hbmMask
)
1310 unsigned int width_bytes
= (cx
+ 31) / 32 * 4;
1311 /* generate alpha channel from the mask */
1312 info
->bmiHeader
.biBitCount
= 1;
1313 info
->bmiHeader
.biSizeImage
= width_bytes
* cy
;
1314 info
->bmiColors
[0].rgbRed
= 0;
1315 info
->bmiColors
[0].rgbGreen
= 0;
1316 info
->bmiColors
[0].rgbBlue
= 0;
1317 info
->bmiColors
[0].rgbReserved
= 0;
1318 info
->bmiColors
[1].rgbRed
= 0xff;
1319 info
->bmiColors
[1].rgbGreen
= 0xff;
1320 info
->bmiColors
[1].rgbBlue
= 0xff;
1321 info
->bmiColors
[1].rgbReserved
= 0;
1322 if (!(mask
= CreateDIBSection( himl
->hdcMask
, info
, DIB_RGB_COLORS
, &mask_bits
, 0, 0 )))
1324 SelectObject( hdc
, mask
);
1325 BitBlt( hdc
, 0, 0, cx
, cy
, himl
->hdcMask
, src_x
, src_y
, SRCCOPY
);
1326 SelectObject( hdc
, bmp
);
1327 for (i
= 0, ptr
= bits
; i
< cy
; i
++)
1328 for (j
= 0; j
< cx
; j
++, ptr
++)
1329 if ((((BYTE
*)mask_bits
)[i
* width_bytes
+ j
/ 8] << (j
% 8)) & 0x80) *ptr
= 0;
1330 else *ptr
|= 0xff000000;
1333 ret
= GdiAlphaBlend( dest_dc
, dest_x
, dest_y
, cx
, cy
, hdc
, 0, 0, cx
, cy
, func
);
1337 if (bmp
) DeleteObject( bmp
);
1338 if (mask
) DeleteObject( mask
);
1339 HeapFree( GetProcessHeap(), 0, info
);
1343 /*************************************************************************
1344 * ImageList_DrawIndirect [COMCTL32.@]
1346 * Draws an image using various parameters specified in pimldp.
1349 * pimldp [I] pointer to IMAGELISTDRAWPARAMS structure.
1357 ImageList_DrawIndirect (IMAGELISTDRAWPARAMS
*pimldp
)
1359 INT cx
, cy
, nOvlIdx
;
1360 DWORD fState
, dwRop
;
1362 COLORREF oldImageBk
, oldImageFg
;
1363 HDC hImageDC
, hImageListDC
, hMaskListDC
;
1364 HBITMAP hImageBmp
, hOldImageBmp
, hBlendMaskBmp
;
1365 BOOL bIsTransparent
, bBlend
, bResult
= FALSE
, bMask
;
1371 if (!pimldp
|| !(himl
= pimldp
->himl
)) return FALSE
;
1372 if (!is_valid(himl
)) return FALSE
;
1373 if ((pimldp
->i
< 0) || (pimldp
->i
>= himl
->cCurImage
)) return FALSE
;
1375 imagelist_point_from_index( himl
, pimldp
->i
, &pt
);
1376 pt
.x
+= pimldp
->xBitmap
;
1377 pt
.y
+= pimldp
->yBitmap
;
1379 fState
= pimldp
->cbSize
< sizeof(IMAGELISTDRAWPARAMS
) ? ILS_NORMAL
: pimldp
->fState
;
1380 fStyle
= pimldp
->fStyle
& ~ILD_OVERLAYMASK
;
1381 cx
= (pimldp
->cx
== 0) ? himl
->cx
: pimldp
->cx
;
1382 cy
= (pimldp
->cy
== 0) ? himl
->cy
: pimldp
->cy
;
1384 bIsTransparent
= (fStyle
& ILD_TRANSPARENT
);
1385 if( pimldp
->rgbBk
== CLR_NONE
)
1386 bIsTransparent
= TRUE
;
1387 if( ( pimldp
->rgbBk
== CLR_DEFAULT
) && ( himl
->clrBk
== CLR_NONE
) )
1388 bIsTransparent
= TRUE
;
1389 bMask
= (himl
->flags
& ILC_MASK
) && (fStyle
& ILD_MASK
) ;
1390 bBlend
= (fStyle
& (ILD_BLEND25
| ILD_BLEND50
) ) && !bMask
;
1392 TRACE("himl(%p) hbmMask(%p) iImage(%d) x(%d) y(%d) cx(%d) cy(%d)\n",
1393 himl
, himl
->hbmMask
, pimldp
->i
, pimldp
->x
, pimldp
->y
, cx
, cy
);
1395 /* we will use these DCs to access the images and masks in the ImageList */
1396 hImageListDC
= himl
->hdcImage
;
1397 hMaskListDC
= himl
->hdcMask
;
1399 /* these will accumulate the image and mask for the image we're drawing */
1400 hImageDC
= CreateCompatibleDC( pimldp
->hdcDst
);
1401 hImageBmp
= CreateCompatibleBitmap( pimldp
->hdcDst
, cx
, cy
);
1402 hBlendMaskBmp
= bBlend
? CreateBitmap(cx
, cy
, 1, 1, NULL
) : 0;
1404 /* Create a compatible DC. */
1405 if (!hImageListDC
|| !hImageDC
|| !hImageBmp
||
1406 (bBlend
&& !hBlendMaskBmp
) || (himl
->hbmMask
&& !hMaskListDC
))
1409 hOldImageBmp
= SelectObject(hImageDC
, hImageBmp
);
1412 * To obtain a transparent look, background color should be set
1413 * to white and foreground color to black when blitting the
1416 oldImageFg
= SetTextColor( hImageDC
, RGB( 0, 0, 0 ) );
1417 oldImageBk
= SetBkColor( hImageDC
, RGB( 0xff, 0xff, 0xff ) );
1419 has_alpha
= (himl
->has_alpha
&& himl
->has_alpha
[pimldp
->i
]);
1420 if (!bMask
&& (has_alpha
|| (fState
& ILS_ALPHA
)))
1422 COLORREF colour
, blend_col
= CLR_NONE
;
1427 blend_col
= pimldp
->rgbFg
;
1428 if (blend_col
== CLR_DEFAULT
) blend_col
= GetSysColor( COLOR_HIGHLIGHT
);
1429 else if (blend_col
== CLR_NONE
) blend_col
= GetTextColor( pimldp
->hdcDst
);
1432 func
.BlendOp
= AC_SRC_OVER
;
1433 func
.BlendFlags
= 0;
1434 func
.SourceConstantAlpha
= (fState
& ILS_ALPHA
) ? pimldp
->Frame
: 255;
1435 func
.AlphaFormat
= AC_SRC_ALPHA
;
1439 bResult
= alpha_blend_image( himl
, pimldp
->hdcDst
, pimldp
->x
, pimldp
->y
,
1440 pt
.x
, pt
.y
, cx
, cy
, func
, fStyle
, blend_col
);
1443 colour
= pimldp
->rgbBk
;
1444 if (colour
== CLR_DEFAULT
) colour
= himl
->clrBk
;
1445 if (colour
== CLR_NONE
) colour
= GetBkColor( pimldp
->hdcDst
);
1447 hOldBrush
= SelectObject (hImageDC
, CreateSolidBrush (colour
));
1448 PatBlt( hImageDC
, 0, 0, cx
, cy
, PATCOPY
);
1449 alpha_blend_image( himl
, hImageDC
, 0, 0, pt
.x
, pt
.y
, cx
, cy
, func
, fStyle
, blend_col
);
1450 DeleteObject (SelectObject (hImageDC
, hOldBrush
));
1451 bResult
= BitBlt( pimldp
->hdcDst
, pimldp
->x
, pimldp
->y
, cx
, cy
, hImageDC
, 0, 0, SRCCOPY
);
1456 * Draw the initial image
1459 if (himl
->hbmMask
) {
1460 hOldBrush
= SelectObject (hImageDC
, CreateSolidBrush (GetTextColor(pimldp
->hdcDst
)));
1461 PatBlt( hImageDC
, 0, 0, cx
, cy
, PATCOPY
);
1462 BitBlt(hImageDC
, 0, 0, cx
, cy
, hMaskListDC
, pt
.x
, pt
.y
, SRCPAINT
);
1463 DeleteObject (SelectObject (hImageDC
, hOldBrush
));
1464 if( bIsTransparent
)
1466 BitBlt ( pimldp
->hdcDst
, pimldp
->x
, pimldp
->y
, cx
, cy
, hImageDC
, 0, 0, SRCAND
);
1471 hOldBrush
= SelectObject (hImageDC
, GetStockObject(BLACK_BRUSH
));
1472 PatBlt( hImageDC
, 0, 0, cx
, cy
, PATCOPY
);
1473 SelectObject(hImageDC
, hOldBrush
);
1476 /* blend the image with the needed solid background */
1477 COLORREF colour
= RGB(0,0,0);
1479 if( !bIsTransparent
)
1481 colour
= pimldp
->rgbBk
;
1482 if( colour
== CLR_DEFAULT
)
1483 colour
= himl
->clrBk
;
1484 if( colour
== CLR_NONE
)
1485 colour
= GetBkColor(pimldp
->hdcDst
);
1488 hOldBrush
= SelectObject (hImageDC
, CreateSolidBrush (colour
));
1489 PatBlt( hImageDC
, 0, 0, cx
, cy
, PATCOPY
);
1492 BitBlt( hImageDC
, 0, 0, cx
, cy
, hMaskListDC
, pt
.x
, pt
.y
, SRCAND
);
1493 BitBlt( hImageDC
, 0, 0, cx
, cy
, hImageListDC
, pt
.x
, pt
.y
, SRCPAINT
);
1496 BitBlt( hImageDC
, 0, 0, cx
, cy
, hImageListDC
, pt
.x
, pt
.y
, SRCCOPY
);
1497 DeleteObject (SelectObject (hImageDC
, hOldBrush
));
1500 /* Time for blending, if required */
1503 COLORREF clrBlend
= pimldp
->rgbFg
;
1504 HDC hBlendMaskDC
= hImageListDC
;
1507 /* Create the blend Mask */
1508 hOldBitmap
= SelectObject(hBlendMaskDC
, hBlendMaskBmp
);
1509 hBlendBrush
= fStyle
& ILD_BLEND50
? himl
->hbrBlend50
: himl
->hbrBlend25
;
1510 hOldBrush
= SelectObject(hBlendMaskDC
, hBlendBrush
);
1511 PatBlt(hBlendMaskDC
, 0, 0, cx
, cy
, PATCOPY
);
1512 SelectObject(hBlendMaskDC
, hOldBrush
);
1514 /* Modify the blend mask if an Image Mask exist */
1516 BitBlt(hBlendMaskDC
, 0, 0, cx
, cy
, hMaskListDC
, pt
.x
, pt
.y
, 0x220326); /* NOTSRCAND */
1517 BitBlt(hBlendMaskDC
, 0, 0, cx
, cy
, hBlendMaskDC
, 0, 0, NOTSRCCOPY
);
1520 /* now apply blend to the current image given the BlendMask */
1521 if (clrBlend
== CLR_DEFAULT
) clrBlend
= GetSysColor (COLOR_HIGHLIGHT
);
1522 else if (clrBlend
== CLR_NONE
) clrBlend
= GetTextColor (pimldp
->hdcDst
);
1523 hOldBrush
= SelectObject (hImageDC
, CreateSolidBrush(clrBlend
));
1524 BitBlt (hImageDC
, 0, 0, cx
, cy
, hBlendMaskDC
, 0, 0, 0xB8074A); /* PSDPxax */
1525 DeleteObject(SelectObject(hImageDC
, hOldBrush
));
1526 SelectObject(hBlendMaskDC
, hOldBitmap
);
1529 /* Now do the overlay image, if any */
1530 nOvlIdx
= (pimldp
->fStyle
& ILD_OVERLAYMASK
) >> 8;
1531 if ( (nOvlIdx
>= 1) && (nOvlIdx
<= MAX_OVERLAYIMAGE
)) {
1532 nOvlIdx
= himl
->nOvlIdx
[nOvlIdx
- 1];
1533 if ((nOvlIdx
>= 0) && (nOvlIdx
< himl
->cCurImage
)) {
1535 imagelist_point_from_index( himl
, nOvlIdx
, &ptOvl
);
1536 ptOvl
.x
+= pimldp
->xBitmap
;
1537 if (himl
->hbmMask
&& !(fStyle
& ILD_IMAGE
))
1538 BitBlt (hImageDC
, 0, 0, cx
, cy
, hMaskListDC
, ptOvl
.x
, ptOvl
.y
, SRCAND
);
1539 BitBlt (hImageDC
, 0, 0, cx
, cy
, hImageListDC
, ptOvl
.x
, ptOvl
.y
, SRCPAINT
);
1543 if (fState
& ILS_SATURATE
) FIXME("ILS_SATURATE: unimplemented!\n");
1544 if (fState
& ILS_GLOW
) FIXME("ILS_GLOW: unimplemented!\n");
1545 if (fState
& ILS_SHADOW
) FIXME("ILS_SHADOW: unimplemented!\n");
1547 if (fStyle
& ILD_PRESERVEALPHA
) FIXME("ILD_PRESERVEALPHA: unimplemented!\n");
1548 if (fStyle
& ILD_SCALE
) FIXME("ILD_SCALE: unimplemented!\n");
1549 if (fStyle
& ILD_DPISCALE
) FIXME("ILD_DPISCALE: unimplemented!\n");
1551 /* now copy the image to the screen */
1553 if (himl
->hbmMask
&& bIsTransparent
) {
1554 COLORREF oldDstFg
= SetTextColor(pimldp
->hdcDst
, RGB( 0, 0, 0 ) );
1555 COLORREF oldDstBk
= SetBkColor(pimldp
->hdcDst
, RGB( 0xff, 0xff, 0xff ));
1556 BitBlt (pimldp
->hdcDst
, pimldp
->x
, pimldp
->y
, cx
, cy
, hMaskListDC
, pt
.x
, pt
.y
, SRCAND
);
1557 SetBkColor(pimldp
->hdcDst
, oldDstBk
);
1558 SetTextColor(pimldp
->hdcDst
, oldDstFg
);
1561 if (fStyle
& ILD_ROP
) dwRop
= pimldp
->dwRop
;
1562 BitBlt (pimldp
->hdcDst
, pimldp
->x
, pimldp
->y
, cx
, cy
, hImageDC
, 0, 0, dwRop
);
1566 /* cleanup the mess */
1567 SetBkColor(hImageDC
, oldImageBk
);
1568 SetTextColor(hImageDC
, oldImageFg
);
1569 SelectObject(hImageDC
, hOldImageBmp
);
1571 DeleteObject(hBlendMaskBmp
);
1572 DeleteObject(hImageBmp
);
1579 /*************************************************************************
1580 * ImageList_Duplicate [COMCTL32.@]
1582 * Duplicates an image list.
1585 * himlSrc [I] source image list handle
1588 * Success: Handle of duplicated image list.
1593 ImageList_Duplicate (HIMAGELIST himlSrc
)
1597 if (!is_valid(himlSrc
)) {
1598 ERR("Invalid image list handle!\n");
1602 himlDst
= ImageList_Create (himlSrc
->cx
, himlSrc
->cy
, himlSrc
->flags
,
1603 himlSrc
->cCurImage
, himlSrc
->cGrow
);
1609 imagelist_get_bitmap_size(himlSrc
, himlSrc
->cCurImage
, &sz
);
1610 BitBlt (himlDst
->hdcImage
, 0, 0, sz
.cx
, sz
.cy
,
1611 himlSrc
->hdcImage
, 0, 0, SRCCOPY
);
1613 if (himlDst
->hbmMask
)
1614 BitBlt (himlDst
->hdcMask
, 0, 0, sz
.cx
, sz
.cy
,
1615 himlSrc
->hdcMask
, 0, 0, SRCCOPY
);
1617 himlDst
->cCurImage
= himlSrc
->cCurImage
;
1618 if (himlSrc
->has_alpha
&& himlDst
->has_alpha
)
1619 memcpy( himlDst
->has_alpha
, himlSrc
->has_alpha
, himlDst
->cCurImage
);
1625 /*************************************************************************
1626 * ImageList_EndDrag [COMCTL32.@]
1628 * Finishes a drag operation.
1639 ImageList_EndDrag (void)
1641 /* cleanup the InternalDrag struct */
1642 InternalDrag
.hwnd
= 0;
1643 if (InternalDrag
.himl
!= InternalDrag
.himlNoCursor
)
1644 ImageList_Destroy (InternalDrag
.himlNoCursor
);
1645 ImageList_Destroy (InternalDrag
.himl
);
1646 InternalDrag
.himlNoCursor
= InternalDrag
.himl
= 0;
1649 InternalDrag
.dxHotspot
= 0;
1650 InternalDrag
.dyHotspot
= 0;
1651 InternalDrag
.bShow
= FALSE
;
1652 DeleteObject(InternalDrag
.hbmBg
);
1653 InternalDrag
.hbmBg
= 0;
1657 /*************************************************************************
1658 * ImageList_GetBkColor [COMCTL32.@]
1660 * Returns the background color of an image list.
1663 * himl [I] Image list handle.
1666 * Success: background color
1671 ImageList_GetBkColor (HIMAGELIST himl
)
1673 return himl
? himl
->clrBk
: CLR_NONE
;
1677 /*************************************************************************
1678 * ImageList_GetDragImage [COMCTL32.@]
1680 * Returns the handle to the internal drag image list.
1683 * ppt [O] Pointer to the drag position. Can be NULL.
1684 * pptHotspot [O] Pointer to the position of the hot spot. Can be NULL.
1687 * Success: Handle of the drag image list.
1692 ImageList_GetDragImage (POINT
*ppt
, POINT
*pptHotspot
)
1694 if (is_valid(InternalDrag
.himl
)) {
1696 ppt
->x
= InternalDrag
.x
;
1697 ppt
->y
= InternalDrag
.y
;
1700 pptHotspot
->x
= InternalDrag
.dxHotspot
;
1701 pptHotspot
->y
= InternalDrag
.dyHotspot
;
1703 return (InternalDrag
.himl
);
1710 /*************************************************************************
1711 * ImageList_GetFlags [COMCTL32.@]
1713 * Gets the flags of the specified image list.
1716 * himl [I] Handle to image list
1726 ImageList_GetFlags(HIMAGELIST himl
)
1728 TRACE("%p\n", himl
);
1730 return is_valid(himl
) ? himl
->flags
: 0;
1734 /*************************************************************************
1735 * ImageList_GetIcon [COMCTL32.@]
1737 * Creates an icon from a masked image of an image list.
1740 * himl [I] handle to image list
1742 * flags [I] drawing style flags
1745 * Success: icon handle
1750 ImageList_GetIcon (HIMAGELIST himl
, INT i
, UINT fStyle
)
1754 HBITMAP hOldDstBitmap
;
1758 TRACE("%p %d %d\n", himl
, i
, fStyle
);
1759 if (!is_valid(himl
) || (i
< 0) || (i
>= himl
->cCurImage
)) return NULL
;
1765 /* create colour bitmap */
1767 ii
.hbmColor
= CreateCompatibleBitmap(hdcDst
, himl
->cx
, himl
->cy
);
1768 ReleaseDC(0, hdcDst
);
1770 hdcDst
= CreateCompatibleDC(0);
1772 imagelist_point_from_index( himl
, i
, &pt
);
1775 ii
.hbmMask
= CreateBitmap (himl
->cx
, himl
->cy
, 1, 1, NULL
);
1776 hOldDstBitmap
= SelectObject (hdcDst
, ii
.hbmMask
);
1777 if (himl
->hbmMask
) {
1778 BitBlt (hdcDst
, 0, 0, himl
->cx
, himl
->cy
,
1779 himl
->hdcMask
, pt
.x
, pt
.y
, SRCCOPY
);
1782 PatBlt (hdcDst
, 0, 0, himl
->cx
, himl
->cy
, BLACKNESS
);
1785 SelectObject (hdcDst
, ii
.hbmColor
);
1786 BitBlt (hdcDst
, 0, 0, himl
->cx
, himl
->cy
,
1787 himl
->hdcImage
, pt
.x
, pt
.y
, SRCCOPY
);
1790 * CreateIconIndirect requires us to deselect the bitmaps from
1791 * the DCs before calling
1793 SelectObject(hdcDst
, hOldDstBitmap
);
1795 hIcon
= CreateIconIndirect (&ii
);
1797 DeleteObject (ii
.hbmMask
);
1798 DeleteObject (ii
.hbmColor
);
1805 /*************************************************************************
1806 * ImageList_GetIconSize [COMCTL32.@]
1808 * Retrieves the size of an image in an image list.
1811 * himl [I] handle to image list
1812 * cx [O] pointer to the image width.
1813 * cy [O] pointer to the image height.
1820 * All images in an image list have the same size.
1824 ImageList_GetIconSize (HIMAGELIST himl
, INT
*cx
, INT
*cy
)
1826 if (!is_valid(himl
) || !cx
|| !cy
)
1828 if ((himl
->cx
<= 0) || (himl
->cy
<= 0))
1838 /*************************************************************************
1839 * ImageList_GetImageCount [COMCTL32.@]
1841 * Returns the number of images in an image list.
1844 * himl [I] handle to image list
1847 * Success: Number of images.
1852 ImageList_GetImageCount (HIMAGELIST himl
)
1854 if (!is_valid(himl
))
1857 return himl
->cCurImage
;
1861 /*************************************************************************
1862 * ImageList_GetImageInfo [COMCTL32.@]
1864 * Returns information about an image in an image list.
1867 * himl [I] handle to image list
1869 * pImageInfo [O] pointer to the image information
1877 ImageList_GetImageInfo (HIMAGELIST himl
, INT i
, IMAGEINFO
*pImageInfo
)
1881 if (!is_valid(himl
) || (pImageInfo
== NULL
))
1883 if ((i
< 0) || (i
>= himl
->cCurImage
))
1886 pImageInfo
->hbmImage
= himl
->hbmImage
;
1887 pImageInfo
->hbmMask
= himl
->hbmMask
;
1889 imagelist_point_from_index( himl
, i
, &pt
);
1890 pImageInfo
->rcImage
.top
= pt
.y
;
1891 pImageInfo
->rcImage
.bottom
= pt
.y
+ himl
->cy
;
1892 pImageInfo
->rcImage
.left
= pt
.x
;
1893 pImageInfo
->rcImage
.right
= pt
.x
+ himl
->cx
;
1899 /*************************************************************************
1900 * ImageList_GetImageRect [COMCTL32.@]
1902 * Retrieves the rectangle of the specified image in an image list.
1905 * himl [I] handle to image list
1907 * lpRect [O] pointer to the image rectangle
1914 * This is an UNDOCUMENTED function!!!
1918 ImageList_GetImageRect (HIMAGELIST himl
, INT i
, LPRECT lpRect
)
1922 if (!is_valid(himl
) || (lpRect
== NULL
))
1924 if ((i
< 0) || (i
>= himl
->cCurImage
))
1927 imagelist_point_from_index( himl
, i
, &pt
);
1928 lpRect
->left
= pt
.x
;
1930 lpRect
->right
= pt
.x
+ himl
->cx
;
1931 lpRect
->bottom
= pt
.y
+ himl
->cy
;
1937 /*************************************************************************
1938 * ImageList_LoadImage [COMCTL32.@]
1939 * ImageList_LoadImageA [COMCTL32.@]
1941 * Creates an image list from a bitmap, icon or cursor.
1943 * See ImageList_LoadImageW.
1947 ImageList_LoadImageA (HINSTANCE hi
, LPCSTR lpbmp
, INT cx
, INT cGrow
,
1948 COLORREF clrMask
, UINT uType
, UINT uFlags
)
1954 if (IS_INTRESOURCE(lpbmp
))
1955 return ImageList_LoadImageW(hi
, (LPCWSTR
)lpbmp
, cx
, cGrow
, clrMask
,
1958 len
= MultiByteToWideChar(CP_ACP
, 0, lpbmp
, -1, NULL
, 0);
1959 lpbmpW
= Alloc(len
* sizeof(WCHAR
));
1960 MultiByteToWideChar(CP_ACP
, 0, lpbmp
, -1, lpbmpW
, len
);
1962 himl
= ImageList_LoadImageW(hi
, lpbmpW
, cx
, cGrow
, clrMask
, uType
, uFlags
);
1968 /*************************************************************************
1969 * ImageList_LoadImageW [COMCTL32.@]
1971 * Creates an image list from a bitmap, icon or cursor.
1974 * hi [I] instance handle
1975 * lpbmp [I] name or id of the image
1976 * cx [I] width of each image
1977 * cGrow [I] number of images to expand
1978 * clrMask [I] mask color
1979 * uType [I] type of image to load
1980 * uFlags [I] loading flags
1983 * Success: handle to the loaded image list
1991 ImageList_LoadImageW (HINSTANCE hi
, LPCWSTR lpbmp
, INT cx
, INT cGrow
,
1992 COLORREF clrMask
, UINT uType
, UINT uFlags
)
1994 HIMAGELIST himl
= NULL
;
1998 handle
= LoadImageW (hi
, lpbmp
, uType
, 0, 0, uFlags
);
2000 WARN("Couldn't load image\n");
2004 if (uType
== IMAGE_BITMAP
) {
2008 if (GetObjectW (handle
, sizeof(dib
), &dib
) == sizeof(BITMAP
)) color
= ILC_COLOR
;
2009 else color
= dib
.dsBm
.bmBitsPixel
;
2011 /* To match windows behavior, if cx is set to zero and
2012 the flag DI_DEFAULTSIZE is specified, cx becomes the
2013 system metric value for icons. If the flag is not specified
2014 the function sets the size to the height of the bitmap */
2017 if (uFlags
& DI_DEFAULTSIZE
)
2018 cx
= GetSystemMetrics (SM_CXICON
);
2020 cx
= dib
.dsBm
.bmHeight
;
2023 nImageCount
= dib
.dsBm
.bmWidth
/ cx
;
2025 himl
= ImageList_Create (cx
, dib
.dsBm
.bmHeight
, ILC_MASK
| color
, nImageCount
, cGrow
);
2027 DeleteObject (handle
);
2030 ImageList_AddMasked (himl
, handle
, clrMask
);
2032 else if ((uType
== IMAGE_ICON
) || (uType
== IMAGE_CURSOR
)) {
2036 GetIconInfo (handle
, &ii
);
2037 GetObjectW (ii
.hbmColor
, sizeof(BITMAP
), &bmp
);
2038 himl
= ImageList_Create (bmp
.bmWidth
, bmp
.bmHeight
,
2039 ILC_MASK
| ILC_COLOR
, 1, cGrow
);
2041 DeleteObject (ii
.hbmColor
);
2042 DeleteObject (ii
.hbmMask
);
2043 DeleteObject (handle
);
2046 ImageList_Add (himl
, ii
.hbmColor
, ii
.hbmMask
);
2047 DeleteObject (ii
.hbmColor
);
2048 DeleteObject (ii
.hbmMask
);
2051 DeleteObject (handle
);
2057 /*************************************************************************
2058 * ImageList_Merge [COMCTL32.@]
2060 * Create an image list containing a merged image from two image lists.
2063 * himl1 [I] handle to first image list
2064 * i1 [I] first image index
2065 * himl2 [I] handle to second image list
2066 * i2 [I] second image index
2067 * dx [I] X offset of the second image relative to the first.
2068 * dy [I] Y offset of the second image relative to the first.
2071 * Success: The newly created image list. It contains a single image
2072 * consisting of the second image merged with the first.
2073 * Failure: NULL, if either himl1 or himl2 is invalid.
2076 * - The returned image list should be deleted by the caller using
2077 * ImageList_Destroy() when it is no longer required.
2078 * - If either i1 or i2 is not a valid image index, they will be treated
2082 ImageList_Merge (HIMAGELIST himl1
, INT i1
, HIMAGELIST himl2
, INT i2
,
2085 HIMAGELIST himlDst
= NULL
;
2087 INT xOff1
, yOff1
, xOff2
, yOff2
;
2091 TRACE("(himl1=%p i1=%d himl2=%p i2=%d dx=%d dy=%d)\n", himl1
, i1
, himl2
,
2094 if (!is_valid(himl1
) || !is_valid(himl2
))
2098 cxDst
= max (himl1
->cx
, dx
+ himl2
->cx
);
2103 cxDst
= max (himl2
->cx
, himl1
->cx
- dx
);
2108 cxDst
= max (himl1
->cx
, himl2
->cx
);
2114 cyDst
= max (himl1
->cy
, dy
+ himl2
->cy
);
2119 cyDst
= max (himl2
->cy
, himl1
->cy
- dy
);
2124 cyDst
= max (himl1
->cy
, himl2
->cy
);
2129 newFlags
= (himl1
->flags
> himl2
->flags
? himl1
->flags
: himl2
->flags
) & ILC_COLORDDB
;
2130 if (newFlags
== ILC_COLORDDB
&& (himl1
->flags
& ILC_COLORDDB
) == ILC_COLOR16
)
2131 newFlags
= ILC_COLOR16
; /* this is what native (at least v5) does, don't know why */
2132 himlDst
= ImageList_Create (cxDst
, cyDst
, ILC_MASK
| newFlags
, 1, 1);
2136 imagelist_point_from_index( himl1
, i1
, &pt1
);
2137 imagelist_point_from_index( himl2
, i2
, &pt2
);
2140 BitBlt (himlDst
->hdcImage
, 0, 0, cxDst
, cyDst
, himl1
->hdcImage
, 0, 0, BLACKNESS
);
2141 if (i1
>= 0 && i1
< himl1
->cCurImage
)
2142 BitBlt (himlDst
->hdcImage
, xOff1
, yOff1
, himl1
->cx
, himl1
->cy
, himl1
->hdcImage
, pt1
.x
, pt1
.y
, SRCCOPY
);
2143 if (i2
>= 0 && i2
< himl2
->cCurImage
)
2145 if (himl2
->flags
& ILC_MASK
)
2147 BitBlt (himlDst
->hdcImage
, xOff2
, yOff2
, himl2
->cx
, himl2
->cy
, himl2
->hdcMask
, pt2
.x
, pt2
.y
, SRCAND
);
2148 BitBlt (himlDst
->hdcImage
, xOff2
, yOff2
, himl2
->cx
, himl2
->cy
, himl2
->hdcImage
, pt2
.x
, pt2
.y
, SRCPAINT
);
2151 BitBlt (himlDst
->hdcImage
, xOff2
, yOff2
, himl2
->cx
, himl2
->cy
, himl2
->hdcImage
, pt2
.x
, pt2
.y
, SRCCOPY
);
2155 BitBlt (himlDst
->hdcMask
, 0, 0, cxDst
, cyDst
, himl1
->hdcMask
, 0, 0, WHITENESS
);
2156 if (i1
>= 0 && i1
< himl1
->cCurImage
)
2157 BitBlt (himlDst
->hdcMask
, xOff1
, yOff1
, himl1
->cx
, himl1
->cy
, himl1
->hdcMask
, pt1
.x
, pt1
.y
, SRCCOPY
);
2158 if (i2
>= 0 && i2
< himl2
->cCurImage
)
2159 BitBlt (himlDst
->hdcMask
, xOff2
, yOff2
, himl2
->cx
, himl2
->cy
, himl2
->hdcMask
, pt2
.x
, pt2
.y
, SRCAND
);
2161 himlDst
->cCurImage
= 1;
2168 /* helper for ImageList_Read, see comments below */
2169 static void *read_bitmap(LPSTREAM pstm
, BITMAPINFO
*bmi
)
2171 BITMAPFILEHEADER bmfh
;
2172 int bitsperpixel
, palspace
;
2175 if (FAILED(IStream_Read ( pstm
, &bmfh
, sizeof(bmfh
), NULL
)))
2178 if (bmfh
.bfType
!= (('M'<<8)|'B'))
2181 if (FAILED(IStream_Read ( pstm
, &bmi
->bmiHeader
, sizeof(bmi
->bmiHeader
), NULL
)))
2184 if ((bmi
->bmiHeader
.biSize
!= sizeof(bmi
->bmiHeader
)))
2187 TRACE("width %u, height %u, planes %u, bpp %u\n",
2188 bmi
->bmiHeader
.biWidth
, bmi
->bmiHeader
.biHeight
,
2189 bmi
->bmiHeader
.biPlanes
, bmi
->bmiHeader
.biBitCount
);
2191 bitsperpixel
= bmi
->bmiHeader
.biPlanes
* bmi
->bmiHeader
.biBitCount
;
2192 if (bitsperpixel
<=8)
2193 palspace
= (1<<bitsperpixel
)*sizeof(RGBQUAD
);
2197 bmi
->bmiHeader
.biSizeImage
= get_dib_image_size( bmi
);
2199 /* read the palette right after the end of the bitmapinfoheader */
2200 if (palspace
&& FAILED(IStream_Read(pstm
, bmi
->bmiColors
, palspace
, NULL
)))
2203 bits
= Alloc(bmi
->bmiHeader
.biSizeImage
);
2204 if (!bits
) return NULL
;
2206 if (FAILED(IStream_Read(pstm
, bits
, bmi
->bmiHeader
.biSizeImage
, NULL
)))
2214 /*************************************************************************
2215 * ImageList_Read [COMCTL32.@]
2217 * Reads an image list from a stream.
2220 * pstm [I] pointer to a stream
2223 * Success: handle to image list
2226 * The format is like this:
2227 * ILHEAD ilheadstruct;
2229 * for the color image part:
2230 * BITMAPFILEHEADER bmfh;
2231 * BITMAPINFOHEADER bmih;
2232 * only if it has a palette:
2233 * RGBQUAD rgbs[nr_of_paletted_colors];
2235 * BYTE colorbits[imagesize];
2237 * the following only if the ILC_MASK bit is set in ILHEAD.ilFlags:
2238 * BITMAPFILEHEADER bmfh_mask;
2239 * BITMAPINFOHEADER bmih_mask;
2240 * only if it has a palette (it usually does not):
2241 * RGBQUAD rgbs[nr_of_paletted_colors];
2243 * BYTE maskbits[imagesize];
2245 HIMAGELIST WINAPI
ImageList_Read (LPSTREAM pstm
)
2247 char image_buf
[sizeof(BITMAPINFOHEADER
) + sizeof(RGBQUAD
) * 256];
2248 char mask_buf
[sizeof(BITMAPINFOHEADER
) + sizeof(RGBQUAD
) * 256];
2249 BITMAPINFO
*image_info
= (BITMAPINFO
*)image_buf
;
2250 BITMAPINFO
*mask_info
= (BITMAPINFO
*)mask_buf
;
2251 void *image_bits
, *mask_bits
= NULL
;
2256 TRACE("%p\n", pstm
);
2258 if (FAILED(IStream_Read (pstm
, &ilHead
, sizeof(ILHEAD
), NULL
)))
2260 if (ilHead
.usMagic
!= (('L' << 8) | 'I'))
2262 if (ilHead
.usVersion
!= 0x101) /* probably version? */
2265 TRACE("cx %u, cy %u, flags 0x%04x, cCurImage %u, cMaxImage %u\n",
2266 ilHead
.cx
, ilHead
.cy
, ilHead
.flags
, ilHead
.cCurImage
, ilHead
.cMaxImage
);
2268 himl
= ImageList_Create(ilHead
.cx
, ilHead
.cy
, ilHead
.flags
, ilHead
.cCurImage
, ilHead
.cMaxImage
);
2272 if (!(image_bits
= read_bitmap(pstm
, image_info
)))
2274 WARN("failed to read bitmap from stream\n");
2277 if (ilHead
.flags
& ILC_MASK
)
2279 if (!(mask_bits
= read_bitmap(pstm
, mask_info
)))
2281 WARN("failed to read mask bitmap from stream\n");
2285 else mask_info
= NULL
;
2287 if (himl
->has_alpha
&& image_info
->bmiHeader
.biBitCount
== 32)
2289 DWORD
*ptr
= image_bits
;
2290 BYTE
*mask_ptr
= mask_bits
;
2291 int stride
= himl
->cy
* image_info
->bmiHeader
.biWidth
;
2293 if (image_info
->bmiHeader
.biHeight
> 0) /* bottom-up */
2295 ptr
+= image_info
->bmiHeader
.biHeight
* image_info
->bmiHeader
.biWidth
- stride
;
2296 mask_ptr
+= (image_info
->bmiHeader
.biHeight
* image_info
->bmiHeader
.biWidth
- stride
) / 8;
2298 image_info
->bmiHeader
.biHeight
= himl
->cy
;
2300 else image_info
->bmiHeader
.biHeight
= -himl
->cy
;
2302 for (i
= 0; i
< ilHead
.cCurImage
; i
+= TILE_COUNT
)
2304 add_dib_bits( himl
, i
, min( ilHead
.cCurImage
- i
, TILE_COUNT
),
2305 himl
->cx
, himl
->cy
, image_info
, mask_info
, ptr
, mask_ptr
);
2307 mask_ptr
+= stride
/ 8;
2312 StretchDIBits( himl
->hdcImage
, 0, 0, image_info
->bmiHeader
.biWidth
, image_info
->bmiHeader
.biHeight
,
2313 0, 0, image_info
->bmiHeader
.biWidth
, image_info
->bmiHeader
.biHeight
,
2314 image_bits
, image_info
, DIB_RGB_COLORS
, SRCCOPY
);
2316 StretchDIBits( himl
->hdcMask
, 0, 0, mask_info
->bmiHeader
.biWidth
, mask_info
->bmiHeader
.biHeight
,
2317 0, 0, mask_info
->bmiHeader
.biWidth
, mask_info
->bmiHeader
.biHeight
,
2318 mask_bits
, mask_info
, DIB_RGB_COLORS
, SRCCOPY
);
2323 himl
->cCurImage
= ilHead
.cCurImage
;
2324 himl
->cMaxImage
= ilHead
.cMaxImage
;
2326 ImageList_SetBkColor(himl
,ilHead
.bkcolor
);
2328 ImageList_SetOverlayImage(himl
,ilHead
.ovls
[i
],i
+1);
2333 /*************************************************************************
2334 * ImageList_Remove [COMCTL32.@]
2336 * Removes an image from an image list
2339 * himl [I] image list handle
2346 * FIXME: as the image list storage test shows, native comctl32 simply shifts
2347 * images without creating a new bitmap.
2350 ImageList_Remove (HIMAGELIST himl
, INT i
)
2352 HBITMAP hbmNewImage
, hbmNewMask
;
2356 TRACE("(himl=%p i=%d)\n", himl
, i
);
2358 if (!is_valid(himl
)) {
2359 ERR("Invalid image list handle!\n");
2363 if ((i
< -1) || (i
>= himl
->cCurImage
)) {
2364 TRACE("index out of range! %d\n", i
);
2372 if (himl
->cCurImage
== 0) {
2373 /* remove all on empty ImageList is allowed */
2374 TRACE("remove all on empty ImageList!\n");
2378 himl
->cMaxImage
= himl
->cGrow
;
2379 himl
->cCurImage
= 0;
2380 for (nCount
= 0; nCount
< MAX_OVERLAYIMAGE
; nCount
++)
2381 himl
->nOvlIdx
[nCount
] = -1;
2383 if (himl
->has_alpha
)
2385 HeapFree( GetProcessHeap(), 0, himl
->has_alpha
);
2386 himl
->has_alpha
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, himl
->cMaxImage
);
2389 hbmNewImage
= ImageList_CreateImage(himl
->hdcImage
, himl
, himl
->cMaxImage
);
2390 SelectObject (himl
->hdcImage
, hbmNewImage
);
2391 DeleteObject (himl
->hbmImage
);
2392 himl
->hbmImage
= hbmNewImage
;
2394 if (himl
->hbmMask
) {
2396 imagelist_get_bitmap_size(himl
, himl
->cMaxImage
, &sz
);
2397 hbmNewMask
= CreateBitmap (sz
.cx
, sz
.cy
, 1, 1, NULL
);
2398 SelectObject (himl
->hdcMask
, hbmNewMask
);
2399 DeleteObject (himl
->hbmMask
);
2400 himl
->hbmMask
= hbmNewMask
;
2404 /* delete one image */
2405 TRACE("Remove single image! %d\n", i
);
2407 /* create new bitmap(s) */
2408 TRACE(" - Number of images: %d / %d (Old/New)\n",
2409 himl
->cCurImage
, himl
->cCurImage
- 1);
2411 hbmNewImage
= ImageList_CreateImage(himl
->hdcImage
, himl
, himl
->cMaxImage
);
2413 imagelist_get_bitmap_size(himl
, himl
->cMaxImage
, &sz
);
2415 hbmNewMask
= CreateBitmap (sz
.cx
, sz
.cy
, 1, 1, NULL
);
2417 hbmNewMask
= 0; /* Just to keep compiler happy! */
2419 hdcBmp
= CreateCompatibleDC (0);
2421 /* copy all images and masks prior to the "removed" image */
2423 TRACE("Pre image copy: Copy %d images\n", i
);
2425 SelectObject (hdcBmp
, hbmNewImage
);
2426 imagelist_copy_images( himl
, himl
->hdcImage
, hdcBmp
, 0, i
, 0 );
2428 if (himl
->hbmMask
) {
2429 SelectObject (hdcBmp
, hbmNewMask
);
2430 imagelist_copy_images( himl
, himl
->hdcMask
, hdcBmp
, 0, i
, 0 );
2434 /* copy all images and masks behind the removed image */
2435 if (i
< himl
->cCurImage
- 1) {
2436 TRACE("Post image copy!\n");
2438 SelectObject (hdcBmp
, hbmNewImage
);
2439 imagelist_copy_images( himl
, himl
->hdcImage
, hdcBmp
, i
+ 1,
2440 (himl
->cCurImage
- i
), i
);
2442 if (himl
->hbmMask
) {
2443 SelectObject (hdcBmp
, hbmNewMask
);
2444 imagelist_copy_images( himl
, himl
->hdcMask
, hdcBmp
, i
+ 1,
2445 (himl
->cCurImage
- i
), i
);
2451 /* delete old images and insert new ones */
2452 SelectObject (himl
->hdcImage
, hbmNewImage
);
2453 DeleteObject (himl
->hbmImage
);
2454 himl
->hbmImage
= hbmNewImage
;
2455 if (himl
->hbmMask
) {
2456 SelectObject (himl
->hdcMask
, hbmNewMask
);
2457 DeleteObject (himl
->hbmMask
);
2458 himl
->hbmMask
= hbmNewMask
;
2468 /*************************************************************************
2469 * ImageList_Replace [COMCTL32.@]
2471 * Replaces an image in an image list with a new image.
2474 * himl [I] handle to image list
2476 * hbmImage [I] handle to image bitmap
2477 * hbmMask [I] handle to mask bitmap. Can be NULL.
2485 ImageList_Replace (HIMAGELIST himl
, INT i
, HBITMAP hbmImage
,
2492 TRACE("%p %d %p %p\n", himl
, i
, hbmImage
, hbmMask
);
2494 if (!is_valid(himl
)) {
2495 ERR("Invalid image list handle!\n");
2499 if ((i
>= himl
->cMaxImage
) || (i
< 0)) {
2500 ERR("Invalid image index!\n");
2504 if (!GetObjectW(hbmImage
, sizeof(BITMAP
), &bmp
))
2507 hdcImage
= CreateCompatibleDC (0);
2510 SelectObject (hdcImage
, hbmImage
);
2512 if (add_with_alpha( himl
, hdcImage
, i
, 1, bmp
.bmWidth
, bmp
.bmHeight
, hbmImage
, hbmMask
))
2515 imagelist_point_from_index(himl
, i
, &pt
);
2516 StretchBlt (himl
->hdcImage
, pt
.x
, pt
.y
, himl
->cx
, himl
->cy
,
2517 hdcImage
, 0, 0, bmp
.bmWidth
, bmp
.bmHeight
, SRCCOPY
);
2522 HBITMAP hOldBitmapTemp
;
2524 hdcTemp
= CreateCompatibleDC(0);
2525 hOldBitmapTemp
= SelectObject(hdcTemp
, hbmMask
);
2527 StretchBlt (himl
->hdcMask
, pt
.x
, pt
.y
, himl
->cx
, himl
->cy
,
2528 hdcTemp
, 0, 0, bmp
.bmWidth
, bmp
.bmHeight
, SRCCOPY
);
2529 SelectObject(hdcTemp
, hOldBitmapTemp
);
2532 /* Remove the background from the image
2534 BitBlt (himl
->hdcImage
, pt
.x
, pt
.y
, bmp
.bmWidth
, bmp
.bmHeight
,
2535 himl
->hdcMask
, pt
.x
, pt
.y
, 0x220326); /* NOTSRCAND */
2539 DeleteDC (hdcImage
);
2545 /*************************************************************************
2546 * ImageList_ReplaceIcon [COMCTL32.@]
2548 * Replaces an image in an image list using an icon.
2551 * himl [I] handle to image list
2553 * hIcon [I] handle to icon
2556 * Success: index of the replaced image
2561 ImageList_ReplaceIcon (HIMAGELIST himl
, INT nIndex
, HICON hIcon
)
2569 TRACE("(%p %d %p)\n", himl
, nIndex
, hIcon
);
2571 if (!is_valid(himl
)) {
2572 ERR("invalid image list\n");
2575 if ((nIndex
>= himl
->cMaxImage
) || (nIndex
< -1)) {
2576 ERR("invalid image index %d / %d\n", nIndex
, himl
->cMaxImage
);
2580 hBestFitIcon
= CopyImage(
2583 LR_COPYFROMRESOURCE
);
2584 /* the above will fail if the icon wasn't loaded from a resource, so try
2585 * again without LR_COPYFROMRESOURCE flag */
2587 hBestFitIcon
= CopyImage(
2595 if (himl
->cCurImage
+ 1 >= himl
->cMaxImage
)
2596 IMAGELIST_InternalExpandBitmaps(himl
, 1);
2598 nIndex
= himl
->cCurImage
;
2602 if (himl
->has_alpha
&& GetIconInfo (hBestFitIcon
, &ii
))
2604 HDC hdcImage
= CreateCompatibleDC( 0 );
2605 GetObjectW (ii
.hbmMask
, sizeof(BITMAP
), &bmp
);
2609 UINT height
= bmp
.bmHeight
/ 2;
2610 HDC hdcMask
= CreateCompatibleDC( 0 );
2611 HBITMAP color
= CreateBitmap( bmp
.bmWidth
, height
, 1, 1, NULL
);
2612 SelectObject( hdcImage
, color
);
2613 SelectObject( hdcMask
, ii
.hbmMask
);
2614 BitBlt( hdcImage
, 0, 0, bmp
.bmWidth
, height
, hdcMask
, 0, height
, SRCCOPY
);
2615 ret
= add_with_alpha( himl
, hdcImage
, nIndex
, 1, bmp
.bmWidth
, height
, color
, ii
.hbmMask
);
2616 DeleteDC( hdcMask
);
2617 DeleteObject( color
);
2619 else ret
= add_with_alpha( himl
, hdcImage
, nIndex
, 1, bmp
.bmWidth
, bmp
.bmHeight
,
2620 ii
.hbmColor
, ii
.hbmMask
);
2622 DeleteDC( hdcImage
);
2623 DeleteObject (ii
.hbmMask
);
2624 if (ii
.hbmColor
) DeleteObject (ii
.hbmColor
);
2628 imagelist_point_from_index(himl
, nIndex
, &pt
);
2632 DrawIconEx( himl
->hdcImage
, pt
.x
, pt
.y
, hBestFitIcon
, himl
->cx
, himl
->cy
, 0, 0, DI_IMAGE
);
2633 PatBlt( himl
->hdcMask
, pt
.x
, pt
.y
, himl
->cx
, himl
->cy
, WHITENESS
);
2634 DrawIconEx( himl
->hdcMask
, pt
.x
, pt
.y
, hBestFitIcon
, himl
->cx
, himl
->cy
, 0, 0, DI_MASK
);
2638 COLORREF color
= himl
->clrBk
!= CLR_NONE
? himl
->clrBk
: comctl32_color
.clrWindow
;
2639 HBRUSH brush
= CreateSolidBrush( GetNearestColor( himl
->hdcImage
, color
));
2641 SelectObject( himl
->hdcImage
, brush
);
2642 PatBlt( himl
->hdcImage
, pt
.x
, pt
.y
, himl
->cx
, himl
->cy
, PATCOPY
);
2643 SelectObject( himl
->hdcImage
, GetStockObject(BLACK_BRUSH
) );
2644 DeleteObject( brush
);
2645 DrawIconEx( himl
->hdcImage
, pt
.x
, pt
.y
, hBestFitIcon
, himl
->cx
, himl
->cy
, 0, 0, DI_NORMAL
);
2649 DestroyIcon(hBestFitIcon
);
2651 TRACE("Insert index = %d, himl->cCurImage = %d\n", nIndex
, himl
->cCurImage
);
2656 /*************************************************************************
2657 * ImageList_SetBkColor [COMCTL32.@]
2659 * Sets the background color of an image list.
2662 * himl [I] handle to image list
2663 * clrBk [I] background color
2666 * Success: previous background color
2671 ImageList_SetBkColor (HIMAGELIST himl
, COLORREF clrBk
)
2675 if (!is_valid(himl
))
2678 clrOldBk
= himl
->clrBk
;
2679 himl
->clrBk
= clrBk
;
2684 /*************************************************************************
2685 * ImageList_SetDragCursorImage [COMCTL32.@]
2687 * Combines the specified image with the current drag image
2690 * himlDrag [I] handle to drag image list
2691 * iDrag [I] drag image index
2692 * dxHotspot [I] X position of the hot spot
2693 * dyHotspot [I] Y position of the hot spot
2700 * - The names dxHotspot, dyHotspot are misleading because they have nothing
2701 * to do with a hotspot but are only the offset of the origin of the new
2702 * image relative to the origin of the old image.
2704 * - When this function is called and the drag image is visible, a
2705 * short flickering occurs but this matches the Win9x behavior. It is
2706 * possible to fix the flickering using code like in ImageList_DragMove.
2710 ImageList_SetDragCursorImage (HIMAGELIST himlDrag
, INT iDrag
,
2711 INT dxHotspot
, INT dyHotspot
)
2713 HIMAGELIST himlTemp
;
2716 if (!is_valid(InternalDrag
.himl
) || !is_valid(himlDrag
))
2719 TRACE(" dxH=%d dyH=%d nX=%d nY=%d\n",
2720 dxHotspot
, dyHotspot
, InternalDrag
.dxHotspot
, InternalDrag
.dyHotspot
);
2722 visible
= InternalDrag
.bShow
;
2724 himlTemp
= ImageList_Merge (InternalDrag
.himlNoCursor
, 0, himlDrag
, iDrag
,
2725 dxHotspot
, dyHotspot
);
2728 /* hide the drag image */
2729 ImageList_DragShowNolock(FALSE
);
2731 if ((InternalDrag
.himl
->cx
!= himlTemp
->cx
) ||
2732 (InternalDrag
.himl
->cy
!= himlTemp
->cy
)) {
2733 /* the size of the drag image changed, invalidate the buffer */
2734 DeleteObject(InternalDrag
.hbmBg
);
2735 InternalDrag
.hbmBg
= 0;
2738 if (InternalDrag
.himl
!= InternalDrag
.himlNoCursor
)
2739 ImageList_Destroy (InternalDrag
.himl
);
2740 InternalDrag
.himl
= himlTemp
;
2743 /* show the drag image */
2744 ImageList_DragShowNolock(TRUE
);
2751 /*************************************************************************
2752 * ImageList_SetFilter [COMCTL32.@]
2754 * Sets a filter (or does something completely different)!!???
2755 * It removes 12 Bytes from the stack (3 Parameters).
2758 * himl [I] SHOULD be a handle to image list
2759 * i [I] COULD be an index?
2764 * Failure: FALSE ???
2767 * This is an UNDOCUMENTED function!!!!
2772 ImageList_SetFilter (HIMAGELIST himl
, INT i
, DWORD dwFilter
)
2774 FIXME("(%p 0x%x 0x%x):empty stub!\n", himl
, i
, dwFilter
);
2780 /*************************************************************************
2781 * ImageList_SetFlags [COMCTL32.@]
2783 * Sets the image list flags.
2786 * himl [I] Handle to image list
2787 * flags [I] Flags to set
2797 ImageList_SetFlags(HIMAGELIST himl
, DWORD flags
)
2799 FIXME("(%p %08x):empty stub\n", himl
, flags
);
2804 /*************************************************************************
2805 * ImageList_SetIconSize [COMCTL32.@]
2807 * Sets the image size of the bitmap and deletes all images.
2810 * himl [I] handle to image list
2811 * cx [I] image width
2812 * cy [I] image height
2820 ImageList_SetIconSize (HIMAGELIST himl
, INT cx
, INT cy
)
2825 if (!is_valid(himl
))
2828 /* remove all images */
2829 himl
->cMaxImage
= himl
->cInitial
+ 1;
2830 himl
->cCurImage
= 0;
2834 /* initialize overlay mask indices */
2835 for (nCount
= 0; nCount
< MAX_OVERLAYIMAGE
; nCount
++)
2836 himl
->nOvlIdx
[nCount
] = -1;
2838 hbmNew
= ImageList_CreateImage(himl
->hdcImage
, himl
, himl
->cMaxImage
);
2839 SelectObject (himl
->hdcImage
, hbmNew
);
2840 DeleteObject (himl
->hbmImage
);
2841 himl
->hbmImage
= hbmNew
;
2843 if (himl
->hbmMask
) {
2845 imagelist_get_bitmap_size(himl
, himl
->cMaxImage
, &sz
);
2846 hbmNew
= CreateBitmap (sz
.cx
, sz
.cy
, 1, 1, NULL
);
2847 SelectObject (himl
->hdcMask
, hbmNew
);
2848 DeleteObject (himl
->hbmMask
);
2849 himl
->hbmMask
= hbmNew
;
2856 /*************************************************************************
2857 * ImageList_SetImageCount [COMCTL32.@]
2859 * Resizes an image list to the specified number of images.
2862 * himl [I] handle to image list
2863 * iImageCount [I] number of images in the image list
2871 ImageList_SetImageCount (HIMAGELIST himl
, UINT iImageCount
)
2874 HBITMAP hbmNewBitmap
, hbmOld
;
2875 INT nNewCount
, nCopyCount
;
2877 TRACE("%p %d\n",himl
,iImageCount
);
2879 if (!is_valid(himl
))
2882 nNewCount
= iImageCount
+ 1;
2883 nCopyCount
= min(himl
->cCurImage
, iImageCount
);
2885 hdcBitmap
= CreateCompatibleDC (0);
2887 hbmNewBitmap
= ImageList_CreateImage(hdcBitmap
, himl
, nNewCount
);
2889 if (hbmNewBitmap
!= 0)
2891 hbmOld
= SelectObject (hdcBitmap
, hbmNewBitmap
);
2892 imagelist_copy_images( himl
, himl
->hdcImage
, hdcBitmap
, 0, nCopyCount
, 0 );
2893 SelectObject (hdcBitmap
, hbmOld
);
2895 /* FIXME: delete 'empty' image space? */
2897 SelectObject (himl
->hdcImage
, hbmNewBitmap
);
2898 DeleteObject (himl
->hbmImage
);
2899 himl
->hbmImage
= hbmNewBitmap
;
2902 ERR("Could not create new image bitmap!\n");
2907 imagelist_get_bitmap_size( himl
, nNewCount
, &sz
);
2908 hbmNewBitmap
= CreateBitmap (sz
.cx
, sz
.cy
, 1, 1, NULL
);
2909 if (hbmNewBitmap
!= 0)
2911 hbmOld
= SelectObject (hdcBitmap
, hbmNewBitmap
);
2912 imagelist_copy_images( himl
, himl
->hdcMask
, hdcBitmap
, 0, nCopyCount
, 0 );
2913 SelectObject (hdcBitmap
, hbmOld
);
2915 /* FIXME: delete 'empty' image space? */
2917 SelectObject (himl
->hdcMask
, hbmNewBitmap
);
2918 DeleteObject (himl
->hbmMask
);
2919 himl
->hbmMask
= hbmNewBitmap
;
2922 ERR("Could not create new mask bitmap!\n");
2925 DeleteDC (hdcBitmap
);
2927 if (himl
->has_alpha
)
2929 char *new_alpha
= HeapReAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, himl
->has_alpha
, nNewCount
);
2930 if (new_alpha
) himl
->has_alpha
= new_alpha
;
2933 HeapFree( GetProcessHeap(), 0, himl
->has_alpha
);
2934 himl
->has_alpha
= NULL
;
2938 /* Update max image count and current image count */
2939 himl
->cMaxImage
= nNewCount
;
2940 himl
->cCurImage
= iImageCount
;
2946 /*************************************************************************
2947 * ImageList_SetOverlayImage [COMCTL32.@]
2949 * Assigns an overlay mask index to an existing image in an image list.
2952 * himl [I] handle to image list
2953 * iImage [I] image index
2954 * iOverlay [I] overlay mask index
2962 ImageList_SetOverlayImage (HIMAGELIST himl
, INT iImage
, INT iOverlay
)
2964 if (!is_valid(himl
))
2966 if ((iOverlay
< 1) || (iOverlay
> MAX_OVERLAYIMAGE
))
2968 if ((iImage
!=-1) && ((iImage
< 0) || (iImage
> himl
->cCurImage
)))
2970 himl
->nOvlIdx
[iOverlay
- 1] = iImage
;
2976 /* helper for ImageList_Write - write bitmap to pstm
2977 * currently everything is written as 24 bit RGB, except masks
2980 _write_bitmap(HBITMAP hBitmap
, LPSTREAM pstm
)
2982 LPBITMAPFILEHEADER bmfh
;
2983 LPBITMAPINFOHEADER bmih
;
2984 LPBYTE data
= NULL
, lpBits
;
2986 INT bitCount
, sizeImage
, offBits
, totalSize
;
2988 BOOL result
= FALSE
;
2990 if (!GetObjectW(hBitmap
, sizeof(BITMAP
), &bm
))
2993 bitCount
= bm
.bmBitsPixel
;
2994 sizeImage
= get_dib_stride(bm
.bmWidth
, bitCount
) * bm
.bmHeight
;
2996 totalSize
= sizeof(BITMAPFILEHEADER
) + sizeof(BITMAPINFOHEADER
);
2998 totalSize
+= (1 << bitCount
) * sizeof(RGBQUAD
);
2999 offBits
= totalSize
;
3000 totalSize
+= sizeImage
;
3002 data
= Alloc(totalSize
);
3003 bmfh
= (LPBITMAPFILEHEADER
)data
;
3004 bmih
= (LPBITMAPINFOHEADER
)(data
+ sizeof(BITMAPFILEHEADER
));
3005 lpBits
= data
+ offBits
;
3007 /* setup BITMAPFILEHEADER */
3008 bmfh
->bfType
= (('M' << 8) | 'B');
3009 bmfh
->bfSize
= offBits
;
3010 bmfh
->bfReserved1
= 0;
3011 bmfh
->bfReserved2
= 0;
3012 bmfh
->bfOffBits
= offBits
;
3014 /* setup BITMAPINFOHEADER */
3015 bmih
->biSize
= sizeof(BITMAPINFOHEADER
);
3016 bmih
->biWidth
= bm
.bmWidth
;
3017 bmih
->biHeight
= bm
.bmHeight
;
3019 bmih
->biBitCount
= bitCount
;
3020 bmih
->biCompression
= BI_RGB
;
3021 bmih
->biSizeImage
= sizeImage
;
3022 bmih
->biXPelsPerMeter
= 0;
3023 bmih
->biYPelsPerMeter
= 0;
3024 bmih
->biClrUsed
= 0;
3025 bmih
->biClrImportant
= 0;
3028 result
= GetDIBits(xdc
, hBitmap
, 0, bm
.bmHeight
, lpBits
, (BITMAPINFO
*)bmih
, DIB_RGB_COLORS
) == bm
.bmHeight
;
3033 TRACE("width %u, height %u, planes %u, bpp %u\n",
3034 bmih
->biWidth
, bmih
->biHeight
,
3035 bmih
->biPlanes
, bmih
->biBitCount
);
3037 if(FAILED(IStream_Write(pstm
, data
, totalSize
, NULL
)))
3049 /*************************************************************************
3050 * ImageList_Write [COMCTL32.@]
3052 * Writes an image list to a stream.
3055 * himl [I] handle to image list
3056 * pstm [O] Pointer to a stream.
3067 ImageList_Write (HIMAGELIST himl
, LPSTREAM pstm
)
3072 TRACE("%p %p\n", himl
, pstm
);
3074 if (!is_valid(himl
))
3077 ilHead
.usMagic
= (('L' << 8) | 'I');
3078 ilHead
.usVersion
= 0x101;
3079 ilHead
.cCurImage
= himl
->cCurImage
;
3080 ilHead
.cMaxImage
= himl
->cMaxImage
;
3081 ilHead
.cGrow
= himl
->cGrow
;
3082 ilHead
.cx
= himl
->cx
;
3083 ilHead
.cy
= himl
->cy
;
3084 ilHead
.bkcolor
= himl
->clrBk
;
3085 ilHead
.flags
= himl
->flags
;
3086 for(i
= 0; i
< 4; i
++) {
3087 ilHead
.ovls
[i
] = himl
->nOvlIdx
[i
];
3090 TRACE("cx %u, cy %u, flags 0x04%x, cCurImage %u, cMaxImage %u\n",
3091 ilHead
.cx
, ilHead
.cy
, ilHead
.flags
, ilHead
.cCurImage
, ilHead
.cMaxImage
);
3093 if(FAILED(IStream_Write(pstm
, &ilHead
, sizeof(ILHEAD
), NULL
)))
3096 /* write the bitmap */
3097 if(!_write_bitmap(himl
->hbmImage
, pstm
))
3100 /* write the mask if we have one */
3101 if(himl
->flags
& ILC_MASK
) {
3102 if(!_write_bitmap(himl
->hbmMask
, pstm
))
3110 static HBITMAP
ImageList_CreateImage(HDC hdc
, HIMAGELIST himl
, UINT count
)
3112 HBITMAP hbmNewBitmap
;
3113 UINT ilc
= (himl
->flags
& 0xFE);
3116 imagelist_get_bitmap_size( himl
, count
, &sz
);
3118 if ((ilc
>= ILC_COLOR4
&& ilc
<= ILC_COLOR32
) || ilc
== ILC_COLOR
)
3120 char buffer
[sizeof(BITMAPINFOHEADER
) + 256 * sizeof(RGBQUAD
)];
3121 BITMAPINFO
*bmi
= (BITMAPINFO
*)buffer
;
3123 TRACE("Creating DIBSection %d x %d, %d Bits per Pixel\n",
3124 sz
.cx
, sz
.cy
, himl
->uBitsPixel
);
3126 memset( buffer
, 0, sizeof(buffer
) );
3127 bmi
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
3128 bmi
->bmiHeader
.biWidth
= sz
.cx
;
3129 bmi
->bmiHeader
.biHeight
= sz
.cy
;
3130 bmi
->bmiHeader
.biPlanes
= 1;
3131 bmi
->bmiHeader
.biBitCount
= himl
->uBitsPixel
;
3132 bmi
->bmiHeader
.biCompression
= BI_RGB
;
3134 if (himl
->uBitsPixel
<= ILC_COLOR8
)
3136 /* retrieve the default color map */
3137 HBITMAP tmp
= CreateBitmap( 1, 1, 1, 1, NULL
);
3138 GetDIBits( hdc
, tmp
, 0, 0, NULL
, bmi
, DIB_RGB_COLORS
);
3139 DeleteObject( tmp
);
3141 hbmNewBitmap
= CreateDIBSection(hdc
, bmi
, DIB_RGB_COLORS
, NULL
, 0, 0);
3143 else /*if (ilc == ILC_COLORDDB)*/
3145 TRACE("Creating Bitmap: %d Bits per Pixel\n", himl
->uBitsPixel
);
3147 hbmNewBitmap
= CreateBitmap (sz
.cx
, sz
.cy
, 1, himl
->uBitsPixel
, NULL
);
3149 TRACE("returning %p\n", hbmNewBitmap
);
3150 return hbmNewBitmap
;
3153 /*************************************************************************
3154 * ImageList_SetColorTable [COMCTL32.@]
3156 * Sets the color table of an image list.
3159 * himl [I] Handle to the image list.
3160 * uStartIndex [I] The first index to set.
3161 * cEntries [I] Number of entries to set.
3162 * prgb [I] New color information for color table for the image list.
3165 * Success: Number of entries in the table that were set.
3169 * ImageList_Create(), SetDIBColorTable()
3173 ImageList_SetColorTable(HIMAGELIST himl
, UINT uStartIndex
, UINT cEntries
, const RGBQUAD
*prgb
)
3175 return SetDIBColorTable(himl
->hdcImage
, uStartIndex
, cEntries
, prgb
);
3178 /*************************************************************************
3179 * ImageList_CoCreateInstance [COMCTL32.@]
3181 * Creates a new imagelist instance and returns an interface pointer to it.
3184 * rclsid [I] A reference to the CLSID (CLSID_ImageList).
3185 * punkOuter [I] Pointer to IUnknown interface for aggregation, if desired
3186 * riid [I] Identifier of the requested interface.
3187 * ppv [O] Returns the address of the pointer requested, or NULL.
3191 * Failure: Error value.
3194 ImageList_CoCreateInstance (REFCLSID rclsid
, const IUnknown
*punkOuter
, REFIID riid
, void **ppv
)
3196 TRACE("(%s,%p,%s,%p)\n", debugstr_guid(rclsid
), punkOuter
, debugstr_guid(riid
), ppv
);
3198 if (!IsEqualCLSID(&CLSID_ImageList
, rclsid
))
3199 return E_NOINTERFACE
;
3201 return ImageListImpl_CreateInstance(punkOuter
, riid
, ppv
);
3205 /*************************************************************************
3206 * IImageList implementation
3209 static HRESULT WINAPI
ImageListImpl_QueryInterface(IImageList2
*iface
,
3210 REFIID iid
, void **ppv
)
3212 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3214 TRACE("(%p,%s,%p)\n", iface
, debugstr_guid(iid
), ppv
);
3216 if (!ppv
) return E_INVALIDARG
;
3218 if (IsEqualIID(&IID_IUnknown
, iid
) ||
3219 IsEqualIID(&IID_IImageList
, iid
) ||
3220 IsEqualIID(&IID_IImageList2
, iid
))
3222 *ppv
= &imgl
->IImageList2_iface
;
3227 return E_NOINTERFACE
;
3230 IImageList2_AddRef(iface
);
3234 static ULONG WINAPI
ImageListImpl_AddRef(IImageList2
*iface
)
3236 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3237 ULONG ref
= InterlockedIncrement(&imgl
->ref
);
3239 TRACE("(%p) refcount=%u\n", iface
, ref
);
3243 static ULONG WINAPI
ImageListImpl_Release(IImageList2
*iface
)
3245 HIMAGELIST This
= impl_from_IImageList2(iface
);
3246 ULONG ref
= InterlockedDecrement(&This
->ref
);
3248 TRACE("(%p) refcount=%u\n", iface
, ref
);
3252 /* delete image bitmaps */
3253 if (This
->hbmImage
) DeleteObject (This
->hbmImage
);
3254 if (This
->hbmMask
) DeleteObject (This
->hbmMask
);
3256 /* delete image & mask DCs */
3257 if (This
->hdcImage
) DeleteDC (This
->hdcImage
);
3258 if (This
->hdcMask
) DeleteDC (This
->hdcMask
);
3260 /* delete blending brushes */
3261 if (This
->hbrBlend25
) DeleteObject (This
->hbrBlend25
);
3262 if (This
->hbrBlend50
) DeleteObject (This
->hbrBlend50
);
3264 This
->IImageList2_iface
.lpVtbl
= NULL
;
3265 HeapFree(GetProcessHeap(), 0, This
->has_alpha
);
3266 HeapFree(GetProcessHeap(), 0, This
);
3272 static HRESULT WINAPI
ImageListImpl_Add(IImageList2
*iface
, HBITMAP hbmImage
,
3273 HBITMAP hbmMask
, int *pi
)
3275 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3281 ret
= ImageList_Add(imgl
, hbmImage
, hbmMask
);
3290 static HRESULT WINAPI
ImageListImpl_ReplaceIcon(IImageList2
*iface
, int i
,
3291 HICON hicon
, int *pi
)
3293 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3299 ret
= ImageList_ReplaceIcon(imgl
, i
, hicon
);
3308 static HRESULT WINAPI
ImageListImpl_SetOverlayImage(IImageList2
*iface
,
3309 int iImage
, int iOverlay
)
3311 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3312 return ImageList_SetOverlayImage(imgl
, iImage
, iOverlay
) ? S_OK
: E_FAIL
;
3315 static HRESULT WINAPI
ImageListImpl_Replace(IImageList2
*iface
, int i
,
3316 HBITMAP hbmImage
, HBITMAP hbmMask
)
3318 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3319 return ImageList_Replace(imgl
, i
, hbmImage
, hbmMask
) ? S_OK
: E_FAIL
;
3322 static HRESULT WINAPI
ImageListImpl_AddMasked(IImageList2
*iface
, HBITMAP hbmImage
,
3323 COLORREF crMask
, int *pi
)
3325 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3331 ret
= ImageList_AddMasked(imgl
, hbmImage
, crMask
);
3340 static HRESULT WINAPI
ImageListImpl_Draw(IImageList2
*iface
,
3341 IMAGELISTDRAWPARAMS
*pimldp
)
3343 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3344 HIMAGELIST old_himl
;
3347 /* As far as I can tell, Windows simply ignores the contents of pimldp->himl
3348 so we shall simulate the same */
3349 old_himl
= pimldp
->himl
;
3350 pimldp
->himl
= imgl
;
3352 ret
= ImageList_DrawIndirect(pimldp
);
3354 pimldp
->himl
= old_himl
;
3355 return ret
? S_OK
: E_INVALIDARG
;
3358 static HRESULT WINAPI
ImageListImpl_Remove(IImageList2
*iface
, int i
)
3360 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3361 return (ImageList_Remove(imgl
, i
) == 0) ? E_INVALIDARG
: S_OK
;
3364 static HRESULT WINAPI
ImageListImpl_GetIcon(IImageList2
*iface
, int i
, UINT flags
,
3367 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3373 hIcon
= ImageList_GetIcon(imgl
, i
, flags
);
3382 static HRESULT WINAPI
ImageListImpl_GetImageInfo(IImageList2
*iface
, int i
,
3383 IMAGEINFO
*pImageInfo
)
3385 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3386 return ImageList_GetImageInfo(imgl
, i
, pImageInfo
) ? S_OK
: E_FAIL
;
3389 static HRESULT WINAPI
ImageListImpl_Copy(IImageList2
*iface
, int dst_index
,
3390 IUnknown
*unk_src
, int src_index
, UINT flags
)
3392 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3393 IImageList
*src
= NULL
;
3399 /* TODO: Add test for IID_ImageList2 too */
3400 if (FAILED(IUnknown_QueryInterface(unk_src
, &IID_IImageList
,
3404 if (ImageList_Copy(imgl
, dst_index
, (HIMAGELIST
) src
, src_index
, flags
))
3409 IImageList_Release(src
);
3413 static HRESULT WINAPI
ImageListImpl_Merge(IImageList2
*iface
, int i1
,
3414 IUnknown
*punk2
, int i2
, int dx
, int dy
, REFIID riid
, void **ppv
)
3416 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3417 IImageList
*iml2
= NULL
;
3419 HRESULT ret
= E_FAIL
;
3421 TRACE("(%p)->(%d %p %d %d %d %s %p)\n", iface
, i1
, punk2
, i2
, dx
, dy
, debugstr_guid(riid
), ppv
);
3423 /* TODO: Add test for IID_ImageList2 too */
3424 if (FAILED(IUnknown_QueryInterface(punk2
, &IID_IImageList
,
3428 merged
= ImageList_Merge(imgl
, i1
, (HIMAGELIST
) iml2
, i2
, dx
, dy
);
3430 /* Get the interface for the new image list */
3433 ret
= HIMAGELIST_QueryInterface(merged
, riid
, ppv
);
3434 ImageList_Destroy(merged
);
3437 IImageList_Release(iml2
);
3441 static HRESULT WINAPI
ImageListImpl_Clone(IImageList2
*iface
, REFIID riid
, void **ppv
)
3443 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3445 HRESULT ret
= E_FAIL
;
3447 TRACE("(%p)->(%s %p)\n", iface
, debugstr_guid(riid
), ppv
);
3449 clone
= ImageList_Duplicate(imgl
);
3451 /* Get the interface for the new image list */
3454 ret
= HIMAGELIST_QueryInterface(clone
, riid
, ppv
);
3455 ImageList_Destroy(clone
);
3461 static HRESULT WINAPI
ImageListImpl_GetImageRect(IImageList2
*iface
, int i
,
3464 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3470 if (!ImageList_GetImageInfo(imgl
, i
, &info
))
3473 return CopyRect(prc
, &info
.rcImage
) ? S_OK
: E_FAIL
;
3476 static HRESULT WINAPI
ImageListImpl_GetIconSize(IImageList2
*iface
, int *cx
,
3479 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3480 return ImageList_GetIconSize(imgl
, cx
, cy
) ? S_OK
: E_INVALIDARG
;
3483 static HRESULT WINAPI
ImageListImpl_SetIconSize(IImageList2
*iface
, int cx
,
3486 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3487 return ImageList_SetIconSize(imgl
, cx
, cy
) ? S_OK
: E_FAIL
;
3490 static HRESULT WINAPI
ImageListImpl_GetImageCount(IImageList2
*iface
, int *pi
)
3492 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3493 *pi
= ImageList_GetImageCount(imgl
);
3497 static HRESULT WINAPI
ImageListImpl_SetImageCount(IImageList2
*iface
, UINT count
)
3499 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3500 return ImageList_SetImageCount(imgl
, count
) ? S_OK
: E_FAIL
;
3503 static HRESULT WINAPI
ImageListImpl_SetBkColor(IImageList2
*iface
, COLORREF clrBk
,
3506 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3507 *pclr
= ImageList_SetBkColor(imgl
, clrBk
);
3511 static HRESULT WINAPI
ImageListImpl_GetBkColor(IImageList2
*iface
, COLORREF
*pclr
)
3513 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3514 *pclr
= ImageList_GetBkColor(imgl
);
3518 static HRESULT WINAPI
ImageListImpl_BeginDrag(IImageList2
*iface
, int iTrack
,
3519 int dxHotspot
, int dyHotspot
)
3521 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3522 return ImageList_BeginDrag(imgl
, iTrack
, dxHotspot
, dyHotspot
) ? S_OK
: E_FAIL
;
3525 static HRESULT WINAPI
ImageListImpl_EndDrag(IImageList2
*iface
)
3527 ImageList_EndDrag();
3531 static HRESULT WINAPI
ImageListImpl_DragEnter(IImageList2
*iface
, HWND hwndLock
,
3534 return ImageList_DragEnter(hwndLock
, x
, y
) ? S_OK
: E_FAIL
;
3537 static HRESULT WINAPI
ImageListImpl_DragLeave(IImageList2
*iface
, HWND hwndLock
)
3539 return ImageList_DragLeave(hwndLock
) ? S_OK
: E_FAIL
;
3542 static HRESULT WINAPI
ImageListImpl_DragMove(IImageList2
*iface
, int x
, int y
)
3544 return ImageList_DragMove(x
, y
) ? S_OK
: E_FAIL
;
3547 static HRESULT WINAPI
ImageListImpl_SetDragCursorImage(IImageList2
*iface
,
3548 IUnknown
*punk
, int iDrag
, int dxHotspot
, int dyHotspot
)
3550 IImageList
*iml2
= NULL
;
3556 /* TODO: Add test for IID_ImageList2 too */
3557 if (FAILED(IUnknown_QueryInterface(punk
, &IID_IImageList
,
3561 ret
= ImageList_SetDragCursorImage((HIMAGELIST
) iml2
, iDrag
, dxHotspot
,
3564 IImageList_Release(iml2
);
3566 return ret
? S_OK
: E_FAIL
;
3569 static HRESULT WINAPI
ImageListImpl_DragShowNolock(IImageList2
*iface
, BOOL fShow
)
3571 return ImageList_DragShowNolock(fShow
) ? S_OK
: E_FAIL
;
3574 static HRESULT WINAPI
ImageListImpl_GetDragImage(IImageList2
*iface
, POINT
*ppt
,
3575 POINT
*pptHotspot
, REFIID riid
, PVOID
*ppv
)
3577 HRESULT ret
= E_FAIL
;
3583 hNew
= ImageList_GetDragImage(ppt
, pptHotspot
);
3585 /* Get the interface for the new image list */
3588 IImageList
*idrag
= (IImageList
*)hNew
;
3590 ret
= HIMAGELIST_QueryInterface(hNew
, riid
, ppv
);
3591 IImageList_Release(idrag
);
3597 static HRESULT WINAPI
ImageListImpl_GetItemFlags(IImageList2
*iface
, int i
,
3600 FIXME("STUB: %p %d %p\n", iface
, i
, dwFlags
);
3604 static HRESULT WINAPI
ImageListImpl_GetOverlayImage(IImageList2
*iface
, int iOverlay
,
3607 HIMAGELIST This
= impl_from_IImageList2(iface
);
3610 if ((iOverlay
< 0) || (iOverlay
> This
->cCurImage
))
3613 for (i
= 0; i
< MAX_OVERLAYIMAGE
; i
++)
3615 if (This
->nOvlIdx
[i
] == iOverlay
)
3625 static HRESULT WINAPI
ImageListImpl_Resize(IImageList2
*iface
, INT cx
, INT cy
)
3627 FIXME("(%p)->(%d %d): stub\n", iface
, cx
, cy
);
3631 static HRESULT WINAPI
ImageListImpl_GetOriginalSize(IImageList2
*iface
, INT image
, DWORD flags
, INT
*cx
, INT
*cy
)
3633 FIXME("(%p)->(%d %x %p %p): stub\n", iface
, image
, flags
, cx
, cy
);
3637 static HRESULT WINAPI
ImageListImpl_SetOriginalSize(IImageList2
*iface
, INT image
, INT cx
, INT cy
)
3639 FIXME("(%p)->(%d %d %d): stub\n", iface
, image
, cx
, cy
);
3643 static HRESULT WINAPI
ImageListImpl_SetCallback(IImageList2
*iface
, IUnknown
*callback
)
3645 FIXME("(%p)->(%p): stub\n", iface
, callback
);
3649 static HRESULT WINAPI
ImageListImpl_GetCallback(IImageList2
*iface
, REFIID riid
, void **ppv
)
3651 FIXME("(%p)->(%s %p): stub\n", iface
, debugstr_guid(riid
), ppv
);
3655 static HRESULT WINAPI
ImageListImpl_ForceImagePresent(IImageList2
*iface
, INT image
, DWORD flags
)
3657 FIXME("(%p)->(%d %x): stub\n", iface
, image
, flags
);
3661 static HRESULT WINAPI
ImageListImpl_DiscardImages(IImageList2
*iface
, INT first_image
, INT last_image
, DWORD flags
)
3663 FIXME("(%p)->(%d %d %x): stub\n", iface
, first_image
, last_image
, flags
);
3667 static HRESULT WINAPI
ImageListImpl_PreloadImages(IImageList2
*iface
, IMAGELISTDRAWPARAMS
*params
)
3669 FIXME("(%p)->(%p): stub\n", iface
, params
);
3673 static HRESULT WINAPI
ImageListImpl_GetStatistics(IImageList2
*iface
, IMAGELISTSTATS
*stats
)
3675 FIXME("(%p)->(%p): stub\n", iface
, stats
);
3679 static HRESULT WINAPI
ImageListImpl_Initialize(IImageList2
*iface
, INT cx
, INT cy
, UINT flags
, INT initial
, INT grow
)
3681 FIXME("(%p)->(%d %d %d %d %d): stub\n", iface
, cx
, cy
, flags
, initial
, grow
);
3685 static HRESULT WINAPI
ImageListImpl_Replace2(IImageList2
*iface
, INT i
, HBITMAP image
, HBITMAP mask
, IUnknown
*unk
, DWORD flags
)
3687 FIXME("(%p)->(%d %p %p %p %x): stub\n", iface
, i
, image
, mask
, unk
, flags
);
3691 static HRESULT WINAPI
ImageListImpl_ReplaceFromImageList(IImageList2
*iface
, INT i
, IImageList
*imagelist
, INT src
,
3692 IUnknown
*unk
, DWORD flags
)
3694 FIXME("(%p)->(%d %p %d %p %x): stub\n", iface
, i
, imagelist
, src
, unk
, flags
);
3698 static const IImageList2Vtbl ImageListImpl_Vtbl
= {
3699 ImageListImpl_QueryInterface
,
3700 ImageListImpl_AddRef
,
3701 ImageListImpl_Release
,
3703 ImageListImpl_ReplaceIcon
,
3704 ImageListImpl_SetOverlayImage
,
3705 ImageListImpl_Replace
,
3706 ImageListImpl_AddMasked
,
3708 ImageListImpl_Remove
,
3709 ImageListImpl_GetIcon
,
3710 ImageListImpl_GetImageInfo
,
3712 ImageListImpl_Merge
,
3713 ImageListImpl_Clone
,
3714 ImageListImpl_GetImageRect
,
3715 ImageListImpl_GetIconSize
,
3716 ImageListImpl_SetIconSize
,
3717 ImageListImpl_GetImageCount
,
3718 ImageListImpl_SetImageCount
,
3719 ImageListImpl_SetBkColor
,
3720 ImageListImpl_GetBkColor
,
3721 ImageListImpl_BeginDrag
,
3722 ImageListImpl_EndDrag
,
3723 ImageListImpl_DragEnter
,
3724 ImageListImpl_DragLeave
,
3725 ImageListImpl_DragMove
,
3726 ImageListImpl_SetDragCursorImage
,
3727 ImageListImpl_DragShowNolock
,
3728 ImageListImpl_GetDragImage
,
3729 ImageListImpl_GetItemFlags
,
3730 ImageListImpl_GetOverlayImage
,
3731 ImageListImpl_Resize
,
3732 ImageListImpl_GetOriginalSize
,
3733 ImageListImpl_SetOriginalSize
,
3734 ImageListImpl_SetCallback
,
3735 ImageListImpl_GetCallback
,
3736 ImageListImpl_ForceImagePresent
,
3737 ImageListImpl_DiscardImages
,
3738 ImageListImpl_PreloadImages
,
3739 ImageListImpl_GetStatistics
,
3740 ImageListImpl_Initialize
,
3741 ImageListImpl_Replace2
,
3742 ImageListImpl_ReplaceFromImageList
3745 static BOOL
is_valid(HIMAGELIST himl
)
3750 valid
= himl
&& himl
->IImageList2_iface
.lpVtbl
== &ImageListImpl_Vtbl
;
3760 /*************************************************************************
3761 * HIMAGELIST_QueryInterface [COMCTL32.@]
3763 * Returns a pointer to an IImageList or IImageList2 object for the given
3767 * himl [I] Image list handle.
3768 * riid [I] Identifier of the requested interface.
3769 * ppv [O] Returns the address of the pointer requested, or NULL.
3773 * Failure: Error value.
3776 HIMAGELIST_QueryInterface (HIMAGELIST himl
, REFIID riid
, void **ppv
)
3778 TRACE("(%p,%s,%p)\n", himl
, debugstr_guid(riid
), ppv
);
3779 return IImageList2_QueryInterface((IImageList2
*) himl
, riid
, ppv
);
3782 static HRESULT
ImageListImpl_CreateInstance(const IUnknown
*pUnkOuter
, REFIID iid
, void** ppv
)
3787 TRACE("(%p,%s,%p)\n", pUnkOuter
, debugstr_guid(iid
), ppv
);
3791 if (pUnkOuter
) return CLASS_E_NOAGGREGATION
;
3793 This
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(struct _IMAGELIST
));
3794 if (!This
) return E_OUTOFMEMORY
;
3796 This
->IImageList2_iface
.lpVtbl
= &ImageListImpl_Vtbl
;
3799 ret
= IImageList2_QueryInterface(&This
->IImageList2_iface
, iid
, ppv
);
3800 IImageList2_Release(&This
->IImageList2_iface
);