2 * ImageList implementation
4 * Copyright 1998 Eric Kohl
5 * Copyright 2000 Jason Mawdsley
6 * Copyright 2001, 2004 Michael Stefaniuc
7 * Copyright 2001 Charles Loep for CodeWeavers
8 * Copyright 2002 Dimitrie O. Paun
9 * Copyright 2009 Owen Rudge for CodeWeavers
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public
13 * License as published by the Free Software Foundation; either
14 * version 2.1 of the License, or (at your option) any later version.
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with this library; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 * - Add support for ILD_SCALE, ILD_DPISCALE
27 * - Add support for ILS_GLOW, ILS_SHADOW
28 * - Thread-safe locking
45 #include "commoncontrols.h"
46 #include "wine/debug.h"
47 #include "wine/exception.h"
49 WINE_DEFAULT_DEBUG_CHANNEL(imagelist
);
51 #define MAX_OVERLAYIMAGE 15
55 IImageList2 IImageList2_iface
; /* 00: IImageList vtable */
56 INT cCurImage
; /* 04: ImageCount */
57 INT cMaxImage
; /* 08: maximages */
58 INT cGrow
; /* 0C: cGrow */
62 UINT flags
; /* 1C: flags */
63 COLORREF clrFg
; /* 20: foreground color */
64 COLORREF clrBk
; /* 24: background color */
67 HBITMAP hbmImage
; /* 28: images Bitmap */
68 HBITMAP hbmMask
; /* 2C: masks Bitmap */
69 HDC hdcImage
; /* 30: images MemDC */
70 HDC hdcMask
; /* 34: masks MemDC */
71 INT nOvlIdx
[MAX_OVERLAYIMAGE
]; /* 38: overlay images index */
73 /* not yet found out */
81 LONG ref
; /* reference count */
84 #define IMAGELIST_MAGIC 0x53414D58
86 /* Header used by ImageList_Read() and ImageList_Write() */
88 typedef struct _ILHEAD
103 /* internal image list data used for Drag & Drop operations */
108 HIMAGELIST himlNoCursor
;
109 /* position of the drag image relative to the window */
112 /* offset of the hotspot relative to the origin of the image */
115 /* is the drag image visible */
117 /* saved background */
121 static INTERNALDRAG InternalDrag
= { 0, 0, 0, 0, 0, 0, 0, FALSE
, 0 };
123 static inline HIMAGELIST
impl_from_IImageList2(IImageList2
*iface
)
125 return CONTAINING_RECORD(iface
, struct _IMAGELIST
, IImageList2_iface
);
128 static HBITMAP
ImageList_CreateImage(HDC hdc
, HIMAGELIST himl
, UINT count
);
129 static HRESULT
ImageListImpl_CreateInstance(const IUnknown
*pUnkOuter
, REFIID iid
, void** ppv
);
130 static BOOL
is_valid(HIMAGELIST himl
);
133 * An imagelist with N images is tiled like this:
145 BOOL
imagelist_has_alpha( HIMAGELIST himl
, UINT index
)
147 return himl
->item_flags
[index
] & ILIF_ALPHA
;
150 static inline UINT
imagelist_height( UINT count
)
152 return ((count
+ TILE_COUNT
- 1)/TILE_COUNT
);
155 static inline void imagelist_point_from_index( HIMAGELIST himl
, UINT index
, LPPOINT pt
)
157 pt
->x
= (index
%TILE_COUNT
) * himl
->cx
;
158 pt
->y
= (index
/TILE_COUNT
) * himl
->cy
;
161 static inline void imagelist_get_bitmap_size( HIMAGELIST himl
, UINT count
, SIZE
*sz
)
163 sz
->cx
= himl
->cx
* TILE_COUNT
;
164 sz
->cy
= imagelist_height( count
) * himl
->cy
;
167 static inline int get_dib_stride( int width
, int bpp
)
169 return ((width
* bpp
+ 31) >> 3) & ~3;
172 static inline int get_dib_image_size( const BITMAPINFO
*info
)
174 return get_dib_stride( info
->bmiHeader
.biWidth
, info
->bmiHeader
.biBitCount
)
175 * abs( info
->bmiHeader
.biHeight
);
179 * imagelist_copy_images()
181 * Copies a block of count images from offset src in the list to offset dest.
182 * Images are copied a row at at time. Assumes hdcSrc and hdcDest are different.
184 static inline void imagelist_copy_images( HIMAGELIST himl
, HDC hdcSrc
, HDC hdcDest
,
185 UINT src
, UINT count
, UINT dest
)
191 for ( i
=0; i
<TILE_COUNT
; i
++ )
193 imagelist_point_from_index( himl
, src
+i
, &ptSrc
);
194 imagelist_point_from_index( himl
, dest
+i
, &ptDest
);
196 sz
.cy
= himl
->cy
* imagelist_height( count
- i
);
198 BitBlt( hdcDest
, ptDest
.x
, ptDest
.y
, sz
.cx
, sz
.cy
,
199 hdcSrc
, ptSrc
.x
, ptSrc
.y
, SRCCOPY
);
203 static void add_dib_bits( HIMAGELIST himl
, int pos
, int count
, int width
, int height
,
204 BITMAPINFO
*info
, BITMAPINFO
*mask_info
, DWORD
*bits
, BYTE
*mask_bits
)
208 int stride
= info
->bmiHeader
.biWidth
;
209 int mask_stride
= (info
->bmiHeader
.biWidth
+ 31) / 32 * 4;
211 for (n
= 0; n
< count
; n
++)
213 BOOL has_alpha
= FALSE
;
215 imagelist_point_from_index( himl
, pos
+ n
, &pt
);
217 /* check if bitmap has an alpha channel */
218 for (i
= 0; i
< height
&& !has_alpha
; i
++)
219 for (j
= n
* width
; j
< (n
+ 1) * width
; j
++)
220 if ((has_alpha
= ((bits
[i
* stride
+ j
] & 0xff000000) != 0))) break;
224 himl
->item_flags
[pos
+ n
] = ILIF_ALPHA
;
226 if (mask_info
&& himl
->hbmMask
) /* generate the mask from the alpha channel */
228 for (i
= 0; i
< height
; i
++)
229 for (j
= n
* width
; j
< (n
+ 1) * width
; j
++)
230 if ((bits
[i
* stride
+ j
] >> 24) > 25) /* more than 10% alpha */
231 mask_bits
[i
* mask_stride
+ j
/ 8] &= ~(0x80 >> (j
% 8));
233 mask_bits
[i
* mask_stride
+ j
/ 8] |= 0x80 >> (j
% 8);
236 else if (mask_info
) /* mask out the background */
238 for (i
= 0; i
< height
; i
++)
239 for (j
= n
* width
; j
< (n
+ 1) * width
; j
++)
240 if ((mask_bits
[i
* mask_stride
+ j
/ 8] << (j
% 8)) & 0x80)
241 bits
[i
* stride
+ j
] = 0;
243 StretchDIBits( himl
->hdcImage
, pt
.x
, pt
.y
, himl
->cx
, himl
->cy
,
244 n
* width
, 0, width
, height
, bits
, info
, DIB_RGB_COLORS
, SRCCOPY
);
246 StretchDIBits( himl
->hdcMask
, pt
.x
, pt
.y
, himl
->cx
, himl
->cy
,
247 n
* width
, 0, width
, height
, mask_bits
, mask_info
, DIB_RGB_COLORS
, SRCCOPY
);
251 /* add images with an alpha channel when the image list is 32 bpp */
252 static BOOL
add_with_alpha( HIMAGELIST himl
, HDC hdc
, int pos
, int count
,
253 int width
, int height
, HBITMAP hbmImage
, HBITMAP hbmMask
)
257 BITMAPINFO
*info
, *mask_info
= NULL
;
259 BYTE
*mask_bits
= NULL
;
262 if (!GetObjectW( hbmImage
, sizeof(bm
), &bm
)) return FALSE
;
264 /* if either the imagelist or the source bitmap don't have an alpha channel, bail out now */
265 if ((himl
->flags
& 0xfe) != ILC_COLOR32
) return FALSE
;
266 if (bm
.bmBitsPixel
!= 32) return FALSE
;
268 SelectObject( hdc
, hbmImage
);
269 mask_width
= (bm
.bmWidth
+ 31) / 32 * 4;
271 if (!(info
= Alloc( FIELD_OFFSET( BITMAPINFO
, bmiColors
[256] )))) goto done
;
272 info
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
273 info
->bmiHeader
.biWidth
= bm
.bmWidth
;
274 info
->bmiHeader
.biHeight
= -height
;
275 info
->bmiHeader
.biPlanes
= 1;
276 info
->bmiHeader
.biBitCount
= 32;
277 info
->bmiHeader
.biCompression
= BI_RGB
;
278 info
->bmiHeader
.biSizeImage
= bm
.bmWidth
* height
* 4;
279 info
->bmiHeader
.biXPelsPerMeter
= 0;
280 info
->bmiHeader
.biYPelsPerMeter
= 0;
281 info
->bmiHeader
.biClrUsed
= 0;
282 info
->bmiHeader
.biClrImportant
= 0;
283 if (!(bits
= Alloc( info
->bmiHeader
.biSizeImage
))) goto done
;
284 if (!GetDIBits( hdc
, hbmImage
, 0, height
, bits
, info
, DIB_RGB_COLORS
)) goto done
;
288 if (!(mask_info
= Alloc( FIELD_OFFSET( BITMAPINFO
, bmiColors
[2] ))))
290 mask_info
->bmiHeader
= info
->bmiHeader
;
291 mask_info
->bmiHeader
.biBitCount
= 1;
292 mask_info
->bmiHeader
.biSizeImage
= mask_width
* height
;
293 if (!(mask_bits
= Alloc( mask_info
->bmiHeader
.biSizeImage
)))
295 if (!GetDIBits( hdc
, hbmMask
, 0, height
, mask_bits
, mask_info
, DIB_RGB_COLORS
)) goto done
;
298 add_dib_bits( himl
, pos
, count
, width
, height
, info
, mask_info
, bits
, mask_bits
);
310 ImageList_SetColorTable(HIMAGELIST himl
, UINT uStartIndex
, UINT cEntries
, const RGBQUAD
*prgb
);
312 /*************************************************************************
313 * IMAGELIST_InternalExpandBitmaps [Internal]
315 * Expands the bitmaps of an image list by the given number of images.
318 * himl [I] handle to image list
319 * nImageCount [I] number of images to add
325 * This function CANNOT be used to reduce the number of images.
328 IMAGELIST_InternalExpandBitmaps(HIMAGELIST himl
, INT nImageCount
)
331 HBITMAP hbmNewBitmap
, hbmNull
;
335 TRACE("%p has allocated %d, max %d, grow %d images\n", himl
, himl
->cCurImage
, himl
->cMaxImage
, himl
->cGrow
);
337 if (himl
->cCurImage
+ nImageCount
< himl
->cMaxImage
)
340 nNewCount
= himl
->cMaxImage
+ max(nImageCount
, himl
->cGrow
) + 1;
342 imagelist_get_bitmap_size(himl
, nNewCount
, &sz
);
344 TRACE("Create expanded bitmaps : himl=%p x=%ld y=%ld count=%d\n", himl
, sz
.cx
, sz
.cy
, nNewCount
);
345 hdcBitmap
= CreateCompatibleDC (0);
347 hbmNewBitmap
= ImageList_CreateImage(hdcBitmap
, himl
, nNewCount
);
349 if (hbmNewBitmap
== 0)
350 ERR("creating new image bitmap (x=%ld y=%ld)!\n", sz
.cx
, sz
.cy
);
354 hbmNull
= SelectObject (hdcBitmap
, hbmNewBitmap
);
355 BitBlt (hdcBitmap
, 0, 0, sz
.cx
, sz
.cy
,
356 himl
->hdcImage
, 0, 0, SRCCOPY
);
357 SelectObject (hdcBitmap
, hbmNull
);
359 SelectObject (himl
->hdcImage
, hbmNewBitmap
);
360 DeleteObject (himl
->hbmImage
);
361 himl
->hbmImage
= hbmNewBitmap
;
363 if (himl
->flags
& ILC_MASK
)
365 hbmNewBitmap
= CreateBitmap (sz
.cx
, sz
.cy
, 1, 1, NULL
);
367 if (hbmNewBitmap
== 0)
368 ERR("creating new mask bitmap!\n");
372 hbmNull
= SelectObject (hdcBitmap
, hbmNewBitmap
);
373 BitBlt (hdcBitmap
, 0, 0, sz
.cx
, sz
.cy
,
374 himl
->hdcMask
, 0, 0, SRCCOPY
);
375 SelectObject (hdcBitmap
, hbmNull
);
377 SelectObject (himl
->hdcMask
, hbmNewBitmap
);
378 DeleteObject (himl
->hbmMask
);
379 himl
->hbmMask
= hbmNewBitmap
;
382 himl
->item_flags
= HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, himl
->item_flags
,
383 nNewCount
* sizeof(*himl
->item_flags
));
384 himl
->cMaxImage
= nNewCount
;
386 DeleteDC (hdcBitmap
);
390 /*************************************************************************
391 * ImageList_Add [COMCTL32.@]
393 * Add an image or images to an image list.
396 * himl [I] handle to image list
397 * hbmImage [I] handle to image bitmap
398 * hbmMask [I] handle to mask bitmap
401 * Success: Index of the first new image.
406 ImageList_Add (HIMAGELIST himl
, HBITMAP hbmImage
, HBITMAP hbmMask
)
408 HDC hdcBitmap
, hdcTemp
= 0;
409 INT nFirstIndex
, nImageCount
, i
;
413 TRACE("himl=%p hbmimage=%p hbmmask=%p\n", himl
, hbmImage
, hbmMask
);
417 if (!GetObjectW(hbmImage
, sizeof(BITMAP
), &bmp
))
420 TRACE("himl %p, cCurImage %d, cMaxImage %d, cGrow %d, cx %d, cy %d\n",
421 himl
, himl
->cCurImage
, himl
->cMaxImage
, himl
->cGrow
, himl
->cx
, himl
->cy
);
423 nImageCount
= bmp
.bmWidth
/ himl
->cx
;
425 TRACE("%p has %d images (%d x %d) bpp %d\n", hbmImage
, nImageCount
, bmp
.bmWidth
, bmp
.bmHeight
,
428 IMAGELIST_InternalExpandBitmaps(himl
, nImageCount
);
430 hdcBitmap
= CreateCompatibleDC(0);
432 SelectObject(hdcBitmap
, hbmImage
);
434 if (add_with_alpha( himl
, hdcBitmap
, himl
->cCurImage
, nImageCount
,
435 himl
->cx
, min( himl
->cy
, bmp
.bmHeight
), hbmImage
, hbmMask
))
440 hdcTemp
= CreateCompatibleDC(0);
441 SelectObject(hdcTemp
, hbmMask
);
444 if (himl
->uBitsPixel
<= 8 && bmp
.bmBitsPixel
<= 8 &&
445 !himl
->color_table_set
&& himl
->cCurImage
== 0)
448 UINT num
= GetDIBColorTable( hdcBitmap
, 0, 1 << bmp
.bmBitsPixel
, colors
);
449 if (num
) ImageList_SetColorTable( himl
, 0, num
, colors
);
452 for (i
=0; i
<nImageCount
; i
++)
454 imagelist_point_from_index( himl
, himl
->cCurImage
+ i
, &pt
);
456 /* Copy result to the imagelist
458 BitBlt( himl
->hdcImage
, pt
.x
, pt
.y
, himl
->cx
, bmp
.bmHeight
,
459 hdcBitmap
, i
*himl
->cx
, 0, SRCCOPY
);
464 BitBlt( himl
->hdcMask
, pt
.x
, pt
.y
, himl
->cx
, bmp
.bmHeight
,
465 hdcTemp
, i
*himl
->cx
, 0, SRCCOPY
);
467 /* Remove the background from the image
469 BitBlt( himl
->hdcImage
, pt
.x
, pt
.y
, himl
->cx
, bmp
.bmHeight
,
470 himl
->hdcMask
, pt
.x
, pt
.y
, 0x220326 ); /* NOTSRCAND */
472 if (hdcTemp
) DeleteDC(hdcTemp
);
477 nFirstIndex
= himl
->cCurImage
;
478 himl
->cCurImage
+= nImageCount
;
484 /*************************************************************************
485 * ImageList_AddIcon [COMCTL32.@]
487 * Adds an icon to an image list.
490 * himl [I] handle to image list
491 * hIcon [I] handle to icon
494 * Success: index of the new image
497 #undef ImageList_AddIcon
498 INT WINAPI
ImageList_AddIcon (HIMAGELIST himl
, HICON hIcon
)
500 return ImageList_ReplaceIcon (himl
, -1, hIcon
);
504 /*************************************************************************
505 * ImageList_AddMasked [COMCTL32.@]
507 * Adds an image or images to an image list and creates a mask from the
508 * specified bitmap using the mask color.
511 * himl [I] handle to image list.
512 * hBitmap [I] handle to bitmap
513 * clrMask [I] mask color.
516 * Success: Index of the first new image.
521 ImageList_AddMasked (HIMAGELIST himl
, HBITMAP hBitmap
, COLORREF clrMask
)
523 HDC hdcMask
, hdcBitmap
;
529 TRACE("himl %p, hbitmap %p, clrmask %#lx\n", himl
, hBitmap
, clrMask
);
534 if (!GetObjectW(hBitmap
, sizeof(BITMAP
), &bmp
))
537 hdcBitmap
= CreateCompatibleDC(0);
538 SelectObject(hdcBitmap
, hBitmap
);
540 /* Create a temp Mask so we can remove the background of the Image */
541 hdcMask
= CreateCompatibleDC(0);
542 hMaskBitmap
= CreateBitmap(bmp
.bmWidth
, bmp
.bmHeight
, 1, 1, NULL
);
543 SelectObject(hdcMask
, hMaskBitmap
);
545 /* create monochrome image to the mask bitmap */
546 bkColor
= (clrMask
!= CLR_DEFAULT
) ? clrMask
: GetPixel (hdcBitmap
, 0, 0);
547 SetBkColor (hdcBitmap
, bkColor
);
548 BitBlt (hdcMask
, 0, 0, bmp
.bmWidth
, bmp
.bmHeight
, hdcBitmap
, 0, 0, SRCCOPY
);
551 * Remove the background from the image
553 * WINDOWS BUG ALERT!!!!!!
554 * The statement below should not be done in common practice
555 * but this is how ImageList_AddMasked works in Windows.
556 * It overwrites the original bitmap passed, this was discovered
557 * by using the same bitmap to iterate the different styles
558 * on windows where it failed (BUT ImageList_Add is OK)
559 * This is here in case some apps rely on this bug
561 * Blt mode 0x220326 is NOTSRCAND
563 if (bmp
.bmBitsPixel
> 8) /* NOTSRCAND can't work with palettes */
565 SetBkColor(hdcBitmap
, RGB(255,255,255));
566 BitBlt(hdcBitmap
, 0, 0, bmp
.bmWidth
, bmp
.bmHeight
, hdcMask
, 0, 0, 0x220326);
572 ret
= ImageList_Add( himl
, hBitmap
, hMaskBitmap
);
574 DeleteObject(hMaskBitmap
);
579 /*************************************************************************
580 * ImageList_BeginDrag [COMCTL32.@]
582 * Creates a temporary image list that contains one image. It will be used
586 * himlTrack [I] handle to the source image list
587 * iTrack [I] index of the drag image in the source image list
588 * dxHotspot [I] X position of the hot spot of the drag image
589 * dyHotspot [I] Y position of the hot spot of the drag image
597 ImageList_BeginDrag (HIMAGELIST himlTrack
, INT iTrack
,
598 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 (iTrack
>= himlTrack
->cCurImage
)
612 if (InternalDrag
.himl
)
618 InternalDrag
.himlNoCursor
= InternalDrag
.himl
= ImageList_Create (cx
, cy
, himlTrack
->flags
, 1, 1);
619 if (InternalDrag
.himl
== NULL
) {
620 WARN("Error creating drag image list!\n");
624 InternalDrag
.dxHotspot
= dxHotspot
;
625 InternalDrag
.dyHotspot
= dyHotspot
;
628 imagelist_point_from_index(InternalDrag
.himl
, 0, &dst
);
629 imagelist_point_from_index(himlTrack
, iTrack
, &src
);
630 BitBlt(InternalDrag
.himl
->hdcImage
, dst
.x
, dst
.y
, cx
, cy
, himlTrack
->hdcImage
, src
.x
, src
.y
,
632 BitBlt(InternalDrag
.himl
->hdcMask
, dst
.x
, dst
.y
, cx
, cy
, himlTrack
->hdcMask
, src
.x
, src
.y
,
635 InternalDrag
.himl
->cCurImage
= 1;
641 /*************************************************************************
642 * ImageList_Copy [COMCTL32.@]
644 * Copies an image of the source image list to an image of the
645 * destination image list. Images can be copied or swapped.
648 * himlDst [I] handle to the destination image list
649 * iDst [I] destination image index.
650 * himlSrc [I] handle to the source image list
651 * iSrc [I] source image index
652 * uFlags [I] flags for the copy operation
659 * Copying from one image list to another is possible. The original
660 * implementation just copies or swaps within one image list.
661 * Could this feature become a bug??? ;-)
665 ImageList_Copy (HIMAGELIST himlDst
, INT iDst
, HIMAGELIST himlSrc
,
666 INT iSrc
, UINT uFlags
)
670 TRACE("himlDst=%p iDst=%d himlSrc=%p iSrc=%d\n", himlDst
, iDst
, himlSrc
, iSrc
);
672 if (!is_valid(himlSrc
) || !is_valid(himlDst
))
674 if ((iDst
< 0) || (iDst
>= himlDst
->cCurImage
))
676 if ((iSrc
< 0) || (iSrc
>= himlSrc
->cCurImage
))
679 imagelist_point_from_index( himlDst
, iDst
, &ptDst
);
680 imagelist_point_from_index( himlSrc
, iSrc
, &ptSrc
);
682 if (uFlags
& ILCF_SWAP
) {
685 HBITMAP hbmTempImage
, hbmTempMask
;
687 hdcBmp
= CreateCompatibleDC (0);
689 /* create temporary bitmaps */
690 hbmTempImage
= CreateBitmap (himlSrc
->cx
, himlSrc
->cy
, 1,
691 himlSrc
->uBitsPixel
, NULL
);
692 hbmTempMask
= CreateBitmap (himlSrc
->cx
, himlSrc
->cy
, 1,
695 /* copy (and stretch) destination to temporary bitmaps.(save) */
697 SelectObject (hdcBmp
, hbmTempImage
);
698 StretchBlt (hdcBmp
, 0, 0, himlSrc
->cx
, himlSrc
->cy
,
699 himlDst
->hdcImage
, ptDst
.x
, ptDst
.y
, himlDst
->cx
, himlDst
->cy
,
702 SelectObject (hdcBmp
, hbmTempMask
);
703 StretchBlt (hdcBmp
, 0, 0, himlSrc
->cx
, himlSrc
->cy
,
704 himlDst
->hdcMask
, ptDst
.x
, ptDst
.y
, himlDst
->cx
, himlDst
->cy
,
707 /* copy (and stretch) source to destination */
709 StretchBlt (himlDst
->hdcImage
, ptDst
.x
, ptDst
.y
, himlDst
->cx
, himlDst
->cy
,
710 himlSrc
->hdcImage
, ptSrc
.x
, ptSrc
.y
, himlSrc
->cx
, himlSrc
->cy
,
713 StretchBlt (himlDst
->hdcMask
, ptDst
.x
, ptDst
.y
, himlDst
->cx
, himlDst
->cy
,
714 himlSrc
->hdcMask
, ptSrc
.x
, ptSrc
.y
, himlSrc
->cx
, himlSrc
->cy
,
717 /* copy (without stretching) temporary bitmaps to source (restore) */
719 BitBlt (himlSrc
->hdcMask
, ptSrc
.x
, ptSrc
.y
, himlSrc
->cx
, himlSrc
->cy
,
720 hdcBmp
, 0, 0, SRCCOPY
);
723 BitBlt (himlSrc
->hdcImage
, ptSrc
.x
, ptSrc
.y
, himlSrc
->cx
, himlSrc
->cy
,
724 hdcBmp
, 0, 0, SRCCOPY
);
725 /* delete temporary bitmaps */
726 DeleteObject (hbmTempMask
);
727 DeleteObject (hbmTempImage
);
732 StretchBlt (himlDst
->hdcImage
, ptDst
.x
, ptDst
.y
, himlDst
->cx
, himlDst
->cy
,
733 himlSrc
->hdcImage
, ptSrc
.x
, ptSrc
.y
, himlSrc
->cx
, himlSrc
->cy
,
737 StretchBlt (himlDst
->hdcMask
, ptDst
.x
, ptDst
.y
, himlDst
->cx
, himlDst
->cy
,
738 himlSrc
->hdcMask
, ptSrc
.x
, ptSrc
.y
, himlSrc
->cx
, himlSrc
->cy
,
746 /*************************************************************************
747 * ImageList_Create [COMCTL32.@]
749 * Creates a new image list.
752 * cx [I] image height
754 * flags [I] creation flags
755 * cInitial [I] initial number of images in the image list
756 * cGrow [I] number of images by which image list grows
759 * Success: Handle to the created image list
763 ImageList_Create (INT cx
, INT cy
, UINT flags
,
764 INT cInitial
, INT cGrow
)
769 UINT ilc
= (flags
& 0xFE);
770 static const WORD aBitBlend25
[] =
771 {0xAA, 0x00, 0x55, 0x00, 0xAA, 0x00, 0x55, 0x00};
773 static const WORD aBitBlend50
[] =
774 {0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA};
776 TRACE("(%d %d 0x%x %d %d)\n", cx
, cy
, flags
, cInitial
, cGrow
);
778 if (cx
< 0 || cy
< 0) return NULL
;
779 if (!((flags
&ILC_COLORDDB
) == ILC_COLORDDB
) && (cx
== 0 || cy
== 0)) return NULL
;
781 /* Create the IImageList interface for the image list */
782 if (FAILED(ImageListImpl_CreateInstance(NULL
, &IID_IImageList
, (void **)&himl
)))
785 cGrow
= (WORD
)((max( cGrow
, 1 ) + 3) & ~3);
789 /* Windows doesn't limit the size here, but X11 doesn't let us allocate such huge bitmaps */
790 WARN( "grow %d too large, limiting to 256\n", cGrow
);
797 himl
->cMaxImage
= cInitial
+ 1;
798 himl
->cInitial
= cInitial
;
800 himl
->clrFg
= CLR_DEFAULT
;
801 himl
->clrBk
= CLR_NONE
;
802 himl
->color_table_set
= FALSE
;
804 /* initialize overlay mask indices */
805 for (nCount
= 0; nCount
< MAX_OVERLAYIMAGE
; nCount
++)
806 himl
->nOvlIdx
[nCount
] = -1;
808 /* Create Image & Mask DCs */
809 himl
->hdcImage
= CreateCompatibleDC (0);
812 if (himl
->flags
& ILC_MASK
){
813 himl
->hdcMask
= CreateCompatibleDC(0);
818 /* Default to ILC_COLOR4 if none of the ILC_COLOR* flags are specified */
819 if (ilc
== ILC_COLOR
)
822 himl
->flags
|= ILC_COLOR4
;
825 if (ilc
>= ILC_COLOR4
&& ilc
<= ILC_COLOR32
)
826 himl
->uBitsPixel
= ilc
;
828 himl
->uBitsPixel
= (UINT
)GetDeviceCaps (himl
->hdcImage
, BITSPIXEL
);
830 if (himl
->cMaxImage
> 0) {
831 himl
->hbmImage
= ImageList_CreateImage(himl
->hdcImage
, himl
, himl
->cMaxImage
);
832 SelectObject(himl
->hdcImage
, himl
->hbmImage
);
836 if ((himl
->cMaxImage
> 0) && (himl
->flags
& ILC_MASK
)) {
839 imagelist_get_bitmap_size(himl
, himl
->cMaxImage
, &sz
);
840 himl
->hbmMask
= CreateBitmap (sz
.cx
, sz
.cy
, 1, 1, NULL
);
841 if (himl
->hbmMask
== 0) {
842 ERR("Error creating mask bitmap!\n");
845 SelectObject(himl
->hdcMask
, himl
->hbmMask
);
850 himl
->item_flags
= Alloc( himl
->cMaxImage
* sizeof(*himl
->item_flags
) );
852 /* create blending brushes */
853 hbmTemp
= CreateBitmap (8, 8, 1, 1, aBitBlend25
);
854 himl
->hbrBlend25
= CreatePatternBrush (hbmTemp
);
855 DeleteObject (hbmTemp
);
857 hbmTemp
= CreateBitmap (8, 8, 1, 1, aBitBlend50
);
858 himl
->hbrBlend50
= CreatePatternBrush (hbmTemp
);
859 DeleteObject (hbmTemp
);
861 TRACE("created imagelist %p\n", himl
);
865 ImageList_Destroy(himl
);
870 /*************************************************************************
871 * ImageList_Destroy [COMCTL32.@]
873 * Destroys an image list.
876 * himl [I] handle to image list
884 ImageList_Destroy (HIMAGELIST himl
)
889 IImageList_Release((IImageList
*) himl
);
894 /*************************************************************************
895 * ImageList_DragEnter [COMCTL32.@]
897 * Locks window update and displays the drag image at the given position.
900 * hwndLock [I] handle of the window that owns the drag image.
901 * x [I] X position of the drag image.
902 * y [I] Y position of the drag image.
909 * The position of the drag image is relative to the window, not
914 ImageList_DragEnter (HWND hwndLock
, INT x
, INT y
)
916 TRACE("(hwnd=%p x=%d y=%d)\n", hwndLock
, x
, y
);
918 if (!is_valid(InternalDrag
.himl
))
922 InternalDrag
.hwnd
= hwndLock
;
924 InternalDrag
.hwnd
= GetDesktopWindow ();
929 /* draw the drag image and save the background */
930 return 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
, UINT style
, UINT state
,
1245 DWORD frame
, COLORREF blend_col
, BOOL has_alpha
)
1249 HBITMAP bmp
= 0, mask
= 0;
1252 void *bits
, *mask_bits
;
1256 func
.BlendOp
= AC_SRC_OVER
;
1257 func
.BlendFlags
= 0;
1258 func
.SourceConstantAlpha
= 255;
1259 func
.AlphaFormat
= AC_SRC_ALPHA
;
1261 if (!(hdc
= CreateCompatibleDC( 0 ))) return FALSE
;
1262 if (!(info
= Alloc( FIELD_OFFSET( BITMAPINFO
, bmiColors
[256] )))) goto done
;
1263 info
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
1264 info
->bmiHeader
.biWidth
= cx
;
1265 info
->bmiHeader
.biHeight
= cy
;
1266 info
->bmiHeader
.biPlanes
= 1;
1267 info
->bmiHeader
.biBitCount
= 32;
1268 info
->bmiHeader
.biCompression
= BI_RGB
;
1269 info
->bmiHeader
.biSizeImage
= cx
* cy
* 4;
1270 info
->bmiHeader
.biXPelsPerMeter
= 0;
1271 info
->bmiHeader
.biYPelsPerMeter
= 0;
1272 info
->bmiHeader
.biClrUsed
= 0;
1273 info
->bmiHeader
.biClrImportant
= 0;
1274 if (!(bmp
= CreateDIBSection( himl
->hdcImage
, info
, DIB_RGB_COLORS
, &bits
, 0, 0 ))) goto done
;
1275 SelectObject( hdc
, bmp
);
1276 BitBlt( hdc
, 0, 0, cx
, cy
, himl
->hdcImage
, src_x
, src_y
, SRCCOPY
);
1278 if (blend_col
!= CLR_NONE
)
1280 BYTE r
= GetRValue( blend_col
);
1281 BYTE g
= GetGValue( blend_col
);
1282 BYTE b
= GetBValue( blend_col
);
1284 if (style
& ILD_BLEND25
)
1286 for (i
= 0, ptr
= bits
; i
< cx
* cy
; i
++, ptr
++)
1287 *ptr
= ((*ptr
& 0xff000000) |
1288 ((((*ptr
& 0x00ff0000) * 3 + (r
<< 16)) / 4) & 0x00ff0000) |
1289 ((((*ptr
& 0x0000ff00) * 3 + (g
<< 8)) / 4) & 0x0000ff00) |
1290 ((((*ptr
& 0x000000ff) * 3 + (b
<< 0)) / 4) & 0x000000ff));
1292 else if (style
& ILD_BLEND50
)
1294 for (i
= 0, ptr
= bits
; i
< cx
* cy
; i
++, ptr
++)
1295 *ptr
= ((*ptr
& 0xff000000) |
1296 ((((*ptr
& 0x00ff0000) + (r
<< 16)) / 2) & 0x00ff0000) |
1297 ((((*ptr
& 0x0000ff00) + (g
<< 8)) / 2) & 0x0000ff00) |
1298 ((((*ptr
& 0x000000ff) + (b
<< 0)) / 2) & 0x000000ff));
1303 if (state
& ILS_ALPHA
)
1305 func
.SourceConstantAlpha
= (BYTE
)frame
;
1307 else if (state
& ILS_SATURATE
)
1309 for (i
= 0, ptr
= bits
; i
< cx
* cy
; i
++, ptr
++)
1311 DWORD gray
= (((*ptr
& 0x00ff0000) >> 16) * 299 +
1312 ((*ptr
& 0x0000ff00) >> 8) * 587 +
1313 ((*ptr
& 0x000000ff) >> 0) * 114 + 500) / 1000;
1314 if (has_alpha
) gray
= gray
* (*ptr
>> 24) / 255;
1315 *ptr
= (*ptr
& 0xff000000)| (gray
<< 16) | (gray
<< 8) | gray
;
1318 else if (style
& ILD_PRESERVEALPHA
)
1320 HBRUSH old_brush
= SelectObject( dest_dc
, GetStockObject(BLACK_BRUSH
) );
1321 PatBlt( dest_dc
, dest_x
, dest_y
, cx
, cy
, PATCOPY
);
1322 SelectObject( dest_dc
, old_brush
);
1325 if (has_alpha
) /* we already have an alpha channel in this case */
1327 /* pre-multiply by the alpha channel */
1328 for (i
= 0, ptr
= bits
; i
< cx
* cy
; i
++, ptr
++)
1330 DWORD alpha
= *ptr
>> 24;
1331 *ptr
= ((*ptr
& 0xff000000) |
1332 (((*ptr
& 0x00ff0000) * alpha
/ 255) & 0x00ff0000) |
1333 (((*ptr
& 0x0000ff00) * alpha
/ 255) & 0x0000ff00) |
1334 (((*ptr
& 0x000000ff) * alpha
/ 255)));
1337 else if (himl
->hbmMask
)
1339 unsigned int width_bytes
= (cx
+ 31) / 32 * 4;
1340 /* generate alpha channel from the mask */
1341 info
->bmiHeader
.biBitCount
= 1;
1342 info
->bmiHeader
.biSizeImage
= width_bytes
* cy
;
1343 info
->bmiColors
[0].rgbRed
= 0;
1344 info
->bmiColors
[0].rgbGreen
= 0;
1345 info
->bmiColors
[0].rgbBlue
= 0;
1346 info
->bmiColors
[0].rgbReserved
= 0;
1347 info
->bmiColors
[1].rgbRed
= 0xff;
1348 info
->bmiColors
[1].rgbGreen
= 0xff;
1349 info
->bmiColors
[1].rgbBlue
= 0xff;
1350 info
->bmiColors
[1].rgbReserved
= 0;
1351 if (!(mask
= CreateDIBSection( himl
->hdcMask
, info
, DIB_RGB_COLORS
, &mask_bits
, 0, 0 )))
1353 SelectObject( hdc
, mask
);
1354 BitBlt( hdc
, 0, 0, cx
, cy
, himl
->hdcMask
, src_x
, src_y
, SRCCOPY
);
1355 SelectObject( hdc
, bmp
);
1356 for (i
= 0, ptr
= bits
; i
< cy
; i
++)
1357 for (j
= 0; j
< cx
; j
++, ptr
++)
1358 if ((((BYTE
*)mask_bits
)[i
* width_bytes
+ j
/ 8] << (j
% 8)) & 0x80) *ptr
= 0;
1359 else *ptr
|= 0xff000000;
1363 for (i
= 0, ptr
= bits
; i
< cx
* cy
; i
++, ptr
++)
1367 ret
= GdiAlphaBlend( dest_dc
, dest_x
, dest_y
, cx
, cy
, hdc
, 0, 0, cx
, cy
, func
);
1371 if (bmp
) DeleteObject( bmp
);
1372 if (mask
) DeleteObject( mask
);
1377 /*************************************************************************
1378 * ImageList_DrawIndirect [COMCTL32.@]
1380 * Draws an image using various parameters specified in pimldp.
1383 * pimldp [I] pointer to IMAGELISTDRAWPARAMS structure.
1391 ImageList_DrawIndirect (IMAGELISTDRAWPARAMS
*pimldp
)
1393 INT cx
, cy
, nOvlIdx
;
1394 DWORD fState
, dwRop
;
1396 COLORREF oldImageBk
, oldImageFg
;
1397 HDC hImageDC
, hImageListDC
, hMaskListDC
;
1398 HBITMAP hImageBmp
, hOldImageBmp
, hBlendMaskBmp
;
1399 BOOL bIsTransparent
, bBlend
, bResult
= FALSE
, bMask
;
1405 if (!pimldp
|| !(himl
= pimldp
->himl
)) return FALSE
;
1406 if (!is_valid(himl
)) return FALSE
;
1407 if ((pimldp
->i
< 0) || (pimldp
->i
>= himl
->cCurImage
)) return FALSE
;
1409 imagelist_point_from_index( himl
, pimldp
->i
, &pt
);
1410 pt
.x
+= pimldp
->xBitmap
;
1411 pt
.y
+= pimldp
->yBitmap
;
1413 fState
= pimldp
->cbSize
< sizeof(IMAGELISTDRAWPARAMS
) ? ILS_NORMAL
: pimldp
->fState
;
1414 fStyle
= pimldp
->fStyle
& ~ILD_OVERLAYMASK
;
1415 cx
= (pimldp
->cx
== 0) ? himl
->cx
: pimldp
->cx
;
1416 cy
= (pimldp
->cy
== 0) ? himl
->cy
: pimldp
->cy
;
1418 bIsTransparent
= (fStyle
& ILD_TRANSPARENT
);
1419 if( pimldp
->rgbBk
== CLR_NONE
)
1420 bIsTransparent
= TRUE
;
1421 if( ( pimldp
->rgbBk
== CLR_DEFAULT
) && ( himl
->clrBk
== CLR_NONE
) )
1422 bIsTransparent
= TRUE
;
1423 bMask
= (himl
->flags
& ILC_MASK
) && (fStyle
& ILD_MASK
) ;
1424 bBlend
= (fStyle
& (ILD_BLEND25
| ILD_BLEND50
) ) && !bMask
;
1426 TRACE("himl(%p) hbmMask(%p) iImage(%d) x(%d) y(%d) cx(%d) cy(%d)\n",
1427 himl
, himl
->hbmMask
, pimldp
->i
, pimldp
->x
, pimldp
->y
, cx
, cy
);
1429 /* we will use these DCs to access the images and masks in the ImageList */
1430 hImageListDC
= himl
->hdcImage
;
1431 hMaskListDC
= himl
->hdcMask
;
1433 /* these will accumulate the image and mask for the image we're drawing */
1434 hImageDC
= CreateCompatibleDC( pimldp
->hdcDst
);
1435 hImageBmp
= CreateCompatibleBitmap( pimldp
->hdcDst
, cx
, cy
);
1436 hBlendMaskBmp
= bBlend
? CreateBitmap(cx
, cy
, 1, 1, NULL
) : 0;
1438 /* Create a compatible DC. */
1439 if (!hImageListDC
|| !hImageDC
|| !hImageBmp
||
1440 (bBlend
&& !hBlendMaskBmp
) || (himl
->hbmMask
&& !hMaskListDC
))
1443 hOldImageBmp
= SelectObject(hImageDC
, hImageBmp
);
1446 * To obtain a transparent look, background color should be set
1447 * to white and foreground color to black when blitting the
1450 oldImageFg
= SetTextColor( hImageDC
, RGB( 0, 0, 0 ) );
1451 oldImageBk
= SetBkColor( hImageDC
, RGB( 0xff, 0xff, 0xff ) );
1453 has_alpha
= himl
->item_flags
[pimldp
->i
] & ILIF_ALPHA
;
1454 if (!bMask
&& (has_alpha
|| (fState
& ILS_ALPHA
) || (fState
& ILS_SATURATE
)))
1456 COLORREF colour
, blend_col
= CLR_NONE
;
1460 blend_col
= pimldp
->rgbFg
;
1461 if (blend_col
== CLR_DEFAULT
) blend_col
= GetSysColor( COLOR_HIGHLIGHT
);
1462 else if (blend_col
== CLR_NONE
) blend_col
= GetTextColor( pimldp
->hdcDst
);
1467 bResult
= alpha_blend_image( himl
, pimldp
->hdcDst
, pimldp
->x
, pimldp
->y
, pt
.x
, pt
.y
, cx
, cy
,
1468 fStyle
, fState
, pimldp
->Frame
, blend_col
, has_alpha
);
1471 colour
= pimldp
->rgbBk
;
1472 if (colour
== CLR_DEFAULT
) colour
= himl
->clrBk
;
1473 if (colour
== CLR_NONE
) colour
= GetBkColor( pimldp
->hdcDst
);
1475 hOldBrush
= SelectObject (hImageDC
, CreateSolidBrush (colour
));
1476 PatBlt( hImageDC
, 0, 0, cx
, cy
, PATCOPY
);
1477 alpha_blend_image( himl
, hImageDC
, 0, 0, pt
.x
, pt
.y
, cx
, cy
, fStyle
, fState
,
1478 pimldp
->Frame
, blend_col
, has_alpha
);
1479 DeleteObject (SelectObject (hImageDC
, hOldBrush
));
1480 bResult
= BitBlt( pimldp
->hdcDst
, pimldp
->x
, pimldp
->y
, cx
, cy
, hImageDC
, 0, 0, SRCCOPY
);
1485 * Draw the initial image
1488 if (himl
->hbmMask
) {
1489 hOldBrush
= SelectObject (hImageDC
, CreateSolidBrush (GetTextColor(pimldp
->hdcDst
)));
1490 PatBlt( hImageDC
, 0, 0, cx
, cy
, PATCOPY
);
1491 BitBlt(hImageDC
, 0, 0, cx
, cy
, hMaskListDC
, pt
.x
, pt
.y
, SRCPAINT
);
1492 DeleteObject (SelectObject (hImageDC
, hOldBrush
));
1493 if( bIsTransparent
)
1495 BitBlt ( pimldp
->hdcDst
, pimldp
->x
, pimldp
->y
, cx
, cy
, hImageDC
, 0, 0, SRCAND
);
1500 hOldBrush
= SelectObject (hImageDC
, GetStockObject(BLACK_BRUSH
));
1501 PatBlt( hImageDC
, 0, 0, cx
, cy
, PATCOPY
);
1502 SelectObject(hImageDC
, hOldBrush
);
1505 /* blend the image with the needed solid background */
1506 COLORREF colour
= RGB(0,0,0);
1508 if( !bIsTransparent
)
1510 colour
= pimldp
->rgbBk
;
1511 if( colour
== CLR_DEFAULT
)
1512 colour
= himl
->clrBk
;
1513 if( colour
== CLR_NONE
)
1514 colour
= GetBkColor(pimldp
->hdcDst
);
1517 hOldBrush
= SelectObject (hImageDC
, CreateSolidBrush (colour
));
1518 PatBlt( hImageDC
, 0, 0, cx
, cy
, PATCOPY
);
1521 BitBlt( hImageDC
, 0, 0, cx
, cy
, hMaskListDC
, pt
.x
, pt
.y
, SRCAND
);
1522 BitBlt( hImageDC
, 0, 0, cx
, cy
, hImageListDC
, pt
.x
, pt
.y
, SRCPAINT
);
1525 BitBlt( hImageDC
, 0, 0, cx
, cy
, hImageListDC
, pt
.x
, pt
.y
, SRCCOPY
);
1526 DeleteObject (SelectObject (hImageDC
, hOldBrush
));
1529 /* Time for blending, if required */
1532 COLORREF clrBlend
= pimldp
->rgbFg
;
1533 HDC hBlendMaskDC
= hImageListDC
;
1536 /* Create the blend Mask */
1537 hOldBitmap
= SelectObject(hBlendMaskDC
, hBlendMaskBmp
);
1538 hBlendBrush
= fStyle
& ILD_BLEND50
? himl
->hbrBlend50
: himl
->hbrBlend25
;
1539 hOldBrush
= SelectObject(hBlendMaskDC
, hBlendBrush
);
1540 PatBlt(hBlendMaskDC
, 0, 0, cx
, cy
, PATCOPY
);
1541 SelectObject(hBlendMaskDC
, hOldBrush
);
1543 /* Modify the blend mask if an Image Mask exist */
1545 BitBlt(hBlendMaskDC
, 0, 0, cx
, cy
, hMaskListDC
, pt
.x
, pt
.y
, 0x220326); /* NOTSRCAND */
1546 BitBlt(hBlendMaskDC
, 0, 0, cx
, cy
, hBlendMaskDC
, 0, 0, NOTSRCCOPY
);
1549 /* now apply blend to the current image given the BlendMask */
1550 if (clrBlend
== CLR_DEFAULT
) clrBlend
= GetSysColor (COLOR_HIGHLIGHT
);
1551 else if (clrBlend
== CLR_NONE
) clrBlend
= GetTextColor (pimldp
->hdcDst
);
1552 hOldBrush
= SelectObject (hImageDC
, CreateSolidBrush(clrBlend
));
1553 BitBlt (hImageDC
, 0, 0, cx
, cy
, hBlendMaskDC
, 0, 0, 0xB8074A); /* PSDPxax */
1554 DeleteObject(SelectObject(hImageDC
, hOldBrush
));
1555 SelectObject(hBlendMaskDC
, hOldBitmap
);
1558 /* Now do the overlay image, if any */
1559 nOvlIdx
= (pimldp
->fStyle
& ILD_OVERLAYMASK
) >> 8;
1560 if ( (nOvlIdx
>= 1) && (nOvlIdx
<= MAX_OVERLAYIMAGE
)) {
1561 nOvlIdx
= himl
->nOvlIdx
[nOvlIdx
- 1];
1562 if ((nOvlIdx
>= 0) && (nOvlIdx
< himl
->cCurImage
)) {
1564 imagelist_point_from_index( himl
, nOvlIdx
, &ptOvl
);
1565 ptOvl
.x
+= pimldp
->xBitmap
;
1566 if (himl
->hbmMask
&& !(fStyle
& ILD_IMAGE
))
1567 BitBlt (hImageDC
, 0, 0, cx
, cy
, hMaskListDC
, ptOvl
.x
, ptOvl
.y
, SRCAND
);
1568 BitBlt (hImageDC
, 0, 0, cx
, cy
, hImageListDC
, ptOvl
.x
, ptOvl
.y
, SRCPAINT
);
1572 if (fState
& ILS_GLOW
) FIXME("ILS_GLOW: unimplemented!\n");
1573 if (fState
& ILS_SHADOW
) FIXME("ILS_SHADOW: unimplemented!\n");
1575 if (fStyle
& ILD_SCALE
) FIXME("ILD_SCALE: unimplemented!\n");
1576 if (fStyle
& ILD_DPISCALE
) FIXME("ILD_DPISCALE: unimplemented!\n");
1578 /* now copy the image to the screen */
1580 if (himl
->hbmMask
&& bIsTransparent
) {
1581 COLORREF oldDstFg
= SetTextColor(pimldp
->hdcDst
, RGB( 0, 0, 0 ) );
1582 COLORREF oldDstBk
= SetBkColor(pimldp
->hdcDst
, RGB( 0xff, 0xff, 0xff ));
1583 BitBlt (pimldp
->hdcDst
, pimldp
->x
, pimldp
->y
, cx
, cy
, hMaskListDC
, pt
.x
, pt
.y
, SRCAND
);
1584 SetBkColor(pimldp
->hdcDst
, oldDstBk
);
1585 SetTextColor(pimldp
->hdcDst
, oldDstFg
);
1588 if (fStyle
& ILD_ROP
) dwRop
= pimldp
->dwRop
;
1589 BitBlt (pimldp
->hdcDst
, pimldp
->x
, pimldp
->y
, cx
, cy
, hImageDC
, 0, 0, dwRop
);
1593 /* cleanup the mess */
1594 SetBkColor(hImageDC
, oldImageBk
);
1595 SetTextColor(hImageDC
, oldImageFg
);
1596 SelectObject(hImageDC
, hOldImageBmp
);
1598 DeleteObject(hBlendMaskBmp
);
1599 DeleteObject(hImageBmp
);
1606 /*************************************************************************
1607 * ImageList_Duplicate [COMCTL32.@]
1609 * Duplicates an image list.
1612 * himlSrc [I] source image list handle
1615 * Success: Handle of duplicated image list.
1620 ImageList_Duplicate (HIMAGELIST himlSrc
)
1624 if (!is_valid(himlSrc
)) {
1625 ERR("Invalid image list handle!\n");
1629 himlDst
= ImageList_Create (himlSrc
->cx
, himlSrc
->cy
, himlSrc
->flags
,
1630 himlSrc
->cCurImage
, himlSrc
->cGrow
);
1636 imagelist_get_bitmap_size(himlSrc
, himlSrc
->cCurImage
, &sz
);
1637 BitBlt (himlDst
->hdcImage
, 0, 0, sz
.cx
, sz
.cy
,
1638 himlSrc
->hdcImage
, 0, 0, SRCCOPY
);
1640 if (himlDst
->hbmMask
)
1641 BitBlt (himlDst
->hdcMask
, 0, 0, sz
.cx
, sz
.cy
,
1642 himlSrc
->hdcMask
, 0, 0, SRCCOPY
);
1644 himlDst
->cCurImage
= himlSrc
->cCurImage
;
1645 memcpy( himlDst
->item_flags
, himlSrc
->item_flags
, himlDst
->cCurImage
* sizeof(*himlDst
->item_flags
) );
1651 /*************************************************************************
1652 * ImageList_EndDrag [COMCTL32.@]
1654 * Finishes a drag operation.
1665 ImageList_EndDrag (void)
1667 /* cleanup the InternalDrag struct */
1668 InternalDrag
.hwnd
= 0;
1669 if (InternalDrag
.himl
!= InternalDrag
.himlNoCursor
)
1670 ImageList_Destroy (InternalDrag
.himlNoCursor
);
1671 ImageList_Destroy (InternalDrag
.himl
);
1672 InternalDrag
.himlNoCursor
= InternalDrag
.himl
= 0;
1675 InternalDrag
.dxHotspot
= 0;
1676 InternalDrag
.dyHotspot
= 0;
1677 InternalDrag
.bShow
= FALSE
;
1678 DeleteObject(InternalDrag
.hbmBg
);
1679 InternalDrag
.hbmBg
= 0;
1683 /*************************************************************************
1684 * ImageList_GetBkColor [COMCTL32.@]
1686 * Returns the background color of an image list.
1689 * himl [I] Image list handle.
1692 * Success: background color
1697 ImageList_GetBkColor (HIMAGELIST himl
)
1699 return himl
? himl
->clrBk
: CLR_NONE
;
1703 /*************************************************************************
1704 * ImageList_GetDragImage [COMCTL32.@]
1706 * Returns the handle to the internal drag image list.
1709 * ppt [O] Pointer to the drag position. Can be NULL.
1710 * pptHotspot [O] Pointer to the position of the hot spot. Can be NULL.
1713 * Success: Handle of the drag image list.
1718 ImageList_GetDragImage (POINT
*ppt
, POINT
*pptHotspot
)
1720 if (is_valid(InternalDrag
.himl
)) {
1722 ppt
->x
= InternalDrag
.x
;
1723 ppt
->y
= InternalDrag
.y
;
1726 pptHotspot
->x
= InternalDrag
.dxHotspot
;
1727 pptHotspot
->y
= InternalDrag
.dyHotspot
;
1729 return (InternalDrag
.himl
);
1736 /*************************************************************************
1737 * ImageList_GetFlags [COMCTL32.@]
1739 * Gets the flags of the specified image list.
1742 * himl [I] Handle to image list
1752 ImageList_GetFlags(HIMAGELIST himl
)
1754 TRACE("%p\n", himl
);
1756 return is_valid(himl
) ? himl
->flags
: 0;
1760 /*************************************************************************
1761 * ImageList_GetIcon [COMCTL32.@]
1763 * Creates an icon from a masked image of an image list.
1766 * himl [I] handle to image list
1768 * flags [I] drawing style flags
1771 * Success: icon handle
1776 ImageList_GetIcon (HIMAGELIST himl
, INT i
, UINT fStyle
)
1780 HBITMAP hOldDstBitmap
;
1784 TRACE("%p %d %d\n", himl
, i
, fStyle
);
1785 if (!is_valid(himl
) || (i
< 0) || (i
>= himl
->cCurImage
)) return NULL
;
1791 /* create colour bitmap */
1793 ii
.hbmColor
= CreateCompatibleBitmap(hdcDst
, himl
->cx
, himl
->cy
);
1794 ReleaseDC(0, hdcDst
);
1796 hdcDst
= CreateCompatibleDC(0);
1798 imagelist_point_from_index( himl
, i
, &pt
);
1801 ii
.hbmMask
= CreateBitmap (himl
->cx
, himl
->cy
, 1, 1, NULL
);
1802 hOldDstBitmap
= SelectObject (hdcDst
, ii
.hbmMask
);
1803 if (himl
->hbmMask
) {
1804 BitBlt (hdcDst
, 0, 0, himl
->cx
, himl
->cy
,
1805 himl
->hdcMask
, pt
.x
, pt
.y
, SRCCOPY
);
1808 PatBlt (hdcDst
, 0, 0, himl
->cx
, himl
->cy
, BLACKNESS
);
1811 SelectObject (hdcDst
, ii
.hbmColor
);
1812 BitBlt (hdcDst
, 0, 0, himl
->cx
, himl
->cy
,
1813 himl
->hdcImage
, pt
.x
, pt
.y
, SRCCOPY
);
1816 * CreateIconIndirect requires us to deselect the bitmaps from
1817 * the DCs before calling
1819 SelectObject(hdcDst
, hOldDstBitmap
);
1821 hIcon
= CreateIconIndirect (&ii
);
1823 DeleteObject (ii
.hbmMask
);
1824 DeleteObject (ii
.hbmColor
);
1831 /*************************************************************************
1832 * ImageList_GetIconSize [COMCTL32.@]
1834 * Retrieves the size of an image in an image list.
1837 * himl [I] handle to image list
1838 * cx [O] pointer to the image width.
1839 * cy [O] pointer to the image height.
1846 * All images in an image list have the same size.
1850 ImageList_GetIconSize (HIMAGELIST himl
, INT
*cx
, INT
*cy
)
1852 if (!is_valid(himl
) || !cx
|| !cy
)
1862 /*************************************************************************
1863 * ImageList_GetImageCount [COMCTL32.@]
1865 * Returns the number of images in an image list.
1868 * himl [I] handle to image list
1871 * Success: Number of images.
1876 ImageList_GetImageCount (HIMAGELIST himl
)
1878 if (!is_valid(himl
))
1881 return himl
->cCurImage
;
1885 /*************************************************************************
1886 * ImageList_GetImageInfo [COMCTL32.@]
1888 * Returns information about an image in an image list.
1891 * himl [I] handle to image list
1893 * pImageInfo [O] pointer to the image information
1901 ImageList_GetImageInfo (HIMAGELIST himl
, INT i
, IMAGEINFO
*pImageInfo
)
1905 if (!is_valid(himl
) || (pImageInfo
== NULL
))
1907 if ((i
< 0) || (i
>= himl
->cCurImage
))
1910 pImageInfo
->hbmImage
= himl
->hbmImage
;
1911 pImageInfo
->hbmMask
= himl
->hbmMask
;
1913 imagelist_point_from_index( himl
, i
, &pt
);
1914 pImageInfo
->rcImage
.top
= pt
.y
;
1915 pImageInfo
->rcImage
.bottom
= pt
.y
+ himl
->cy
;
1916 pImageInfo
->rcImage
.left
= pt
.x
;
1917 pImageInfo
->rcImage
.right
= pt
.x
+ himl
->cx
;
1923 /*************************************************************************
1924 * ImageList_GetImageRect [COMCTL32.@]
1926 * Retrieves the rectangle of the specified image in an image list.
1929 * himl [I] handle to image list
1931 * lpRect [O] pointer to the image rectangle
1938 * This is an UNDOCUMENTED function!!!
1942 ImageList_GetImageRect (HIMAGELIST himl
, INT i
, LPRECT lpRect
)
1946 if (!is_valid(himl
) || (lpRect
== NULL
))
1948 if ((i
< 0) || (i
>= himl
->cCurImage
))
1951 imagelist_point_from_index( himl
, i
, &pt
);
1952 lpRect
->left
= pt
.x
;
1954 lpRect
->right
= pt
.x
+ himl
->cx
;
1955 lpRect
->bottom
= pt
.y
+ himl
->cy
;
1961 /*************************************************************************
1962 * ImageList_LoadImage [COMCTL32.@]
1963 * ImageList_LoadImageA [COMCTL32.@]
1965 * Creates an image list from a bitmap, icon or cursor.
1967 * See ImageList_LoadImageW.
1971 ImageList_LoadImageA (HINSTANCE hi
, LPCSTR lpbmp
, INT cx
, INT cGrow
,
1972 COLORREF clrMask
, UINT uType
, UINT uFlags
)
1978 if (IS_INTRESOURCE(lpbmp
))
1979 return ImageList_LoadImageW(hi
, (LPCWSTR
)lpbmp
, cx
, cGrow
, clrMask
,
1982 len
= MultiByteToWideChar(CP_ACP
, 0, lpbmp
, -1, NULL
, 0);
1983 lpbmpW
= Alloc(len
* sizeof(WCHAR
));
1984 MultiByteToWideChar(CP_ACP
, 0, lpbmp
, -1, lpbmpW
, len
);
1986 himl
= ImageList_LoadImageW(hi
, lpbmpW
, cx
, cGrow
, clrMask
, uType
, uFlags
);
1992 /*************************************************************************
1993 * ImageList_LoadImageW [COMCTL32.@]
1995 * Creates an image list from a bitmap, icon or cursor.
1998 * hi [I] instance handle
1999 * lpbmp [I] name or id of the image
2000 * cx [I] width of each image
2001 * cGrow [I] number of images to expand
2002 * clrMask [I] mask color
2003 * uType [I] type of image to load
2004 * uFlags [I] loading flags
2007 * Success: handle to the loaded image list
2015 ImageList_LoadImageW (HINSTANCE hi
, LPCWSTR lpbmp
, INT cx
, INT cGrow
,
2016 COLORREF clrMask
, UINT uType
, UINT uFlags
)
2018 HIMAGELIST himl
= NULL
;
2022 handle
= LoadImageW (hi
, lpbmp
, uType
, 0, 0, uFlags
);
2024 WARN("Couldn't load image\n");
2028 if (uType
== IMAGE_BITMAP
) {
2032 if (GetObjectW (handle
, sizeof(dib
), &dib
) == sizeof(BITMAP
)) color
= ILC_COLOR
;
2033 else color
= dib
.dsBm
.bmBitsPixel
;
2035 /* To match windows behavior, if cx is set to zero and
2036 the flag DI_DEFAULTSIZE is specified, cx becomes the
2037 system metric value for icons. If the flag is not specified
2038 the function sets the size to the height of the bitmap */
2041 if (uFlags
& DI_DEFAULTSIZE
)
2042 cx
= GetSystemMetrics (SM_CXICON
);
2044 cx
= dib
.dsBm
.bmHeight
;
2047 nImageCount
= dib
.dsBm
.bmWidth
/ cx
;
2049 if (clrMask
!= CLR_NONE
) color
|= ILC_MASK
;
2050 himl
= ImageList_Create (cx
, dib
.dsBm
.bmHeight
, color
, nImageCount
, cGrow
);
2052 DeleteObject (handle
);
2055 ImageList_AddMasked (himl
, handle
, clrMask
);
2057 else if ((uType
== IMAGE_ICON
) || (uType
== IMAGE_CURSOR
)) {
2061 GetIconInfo (handle
, &ii
);
2062 GetObjectW (ii
.hbmColor
, sizeof(BITMAP
), &bmp
);
2063 himl
= ImageList_Create (bmp
.bmWidth
, bmp
.bmHeight
,
2064 ILC_MASK
| ILC_COLOR
, 1, cGrow
);
2066 DeleteObject (ii
.hbmColor
);
2067 DeleteObject (ii
.hbmMask
);
2068 DeleteObject (handle
);
2071 ImageList_Add (himl
, ii
.hbmColor
, ii
.hbmMask
);
2072 DeleteObject (ii
.hbmColor
);
2073 DeleteObject (ii
.hbmMask
);
2076 DeleteObject (handle
);
2082 /*************************************************************************
2083 * ImageList_Merge [COMCTL32.@]
2085 * Create an image list containing a merged image from two image lists.
2088 * himl1 [I] handle to first image list
2089 * i1 [I] first image index
2090 * himl2 [I] handle to second image list
2091 * i2 [I] second image index
2092 * dx [I] X offset of the second image relative to the first.
2093 * dy [I] Y offset of the second image relative to the first.
2096 * Success: The newly created image list. It contains a single image
2097 * consisting of the second image merged with the first.
2098 * Failure: NULL, if either himl1 or himl2 is invalid.
2101 * - The returned image list should be deleted by the caller using
2102 * ImageList_Destroy() when it is no longer required.
2103 * - If either i1 or i2 is not a valid image index, they will be treated
2107 ImageList_Merge (HIMAGELIST himl1
, INT i1
, HIMAGELIST himl2
, INT i2
,
2110 HIMAGELIST himlDst
= NULL
;
2112 INT xOff1
, yOff1
, xOff2
, yOff2
;
2116 TRACE("(himl1=%p i1=%d himl2=%p i2=%d dx=%d dy=%d)\n", himl1
, i1
, himl2
,
2119 if (!is_valid(himl1
) || !is_valid(himl2
))
2123 cxDst
= max (himl1
->cx
, dx
+ himl2
->cx
);
2128 cxDst
= max (himl2
->cx
, himl1
->cx
- dx
);
2133 cxDst
= max (himl1
->cx
, himl2
->cx
);
2139 cyDst
= max (himl1
->cy
, dy
+ himl2
->cy
);
2144 cyDst
= max (himl2
->cy
, himl1
->cy
- dy
);
2149 cyDst
= max (himl1
->cy
, himl2
->cy
);
2154 newFlags
= (himl1
->flags
> himl2
->flags
? himl1
->flags
: himl2
->flags
) & ILC_COLORDDB
;
2155 if (newFlags
== ILC_COLORDDB
&& (himl1
->flags
& ILC_COLORDDB
) == ILC_COLOR16
)
2156 newFlags
= ILC_COLOR16
; /* this is what native (at least v5) does, don't know why */
2157 himlDst
= ImageList_Create (cxDst
, cyDst
, ILC_MASK
| newFlags
, 1, 1);
2161 imagelist_point_from_index( himl1
, i1
, &pt1
);
2162 imagelist_point_from_index( himl2
, i2
, &pt2
);
2165 BitBlt (himlDst
->hdcImage
, 0, 0, cxDst
, cyDst
, himl1
->hdcImage
, 0, 0, BLACKNESS
);
2166 if (i1
>= 0 && i1
< himl1
->cCurImage
)
2167 BitBlt (himlDst
->hdcImage
, xOff1
, yOff1
, himl1
->cx
, himl1
->cy
, himl1
->hdcImage
, pt1
.x
, pt1
.y
, SRCCOPY
);
2168 if (i2
>= 0 && i2
< himl2
->cCurImage
)
2170 if (himl2
->flags
& ILC_MASK
)
2172 BitBlt (himlDst
->hdcImage
, xOff2
, yOff2
, himl2
->cx
, himl2
->cy
, himl2
->hdcMask
, pt2
.x
, pt2
.y
, SRCAND
);
2173 BitBlt (himlDst
->hdcImage
, xOff2
, yOff2
, himl2
->cx
, himl2
->cy
, himl2
->hdcImage
, pt2
.x
, pt2
.y
, SRCPAINT
);
2176 BitBlt (himlDst
->hdcImage
, xOff2
, yOff2
, himl2
->cx
, himl2
->cy
, himl2
->hdcImage
, pt2
.x
, pt2
.y
, SRCCOPY
);
2180 BitBlt (himlDst
->hdcMask
, 0, 0, cxDst
, cyDst
, himl1
->hdcMask
, 0, 0, WHITENESS
);
2181 if (i1
>= 0 && i1
< himl1
->cCurImage
)
2182 BitBlt (himlDst
->hdcMask
, xOff1
, yOff1
, himl1
->cx
, himl1
->cy
, himl1
->hdcMask
, pt1
.x
, pt1
.y
, SRCCOPY
);
2183 if (i2
>= 0 && i2
< himl2
->cCurImage
)
2184 BitBlt (himlDst
->hdcMask
, xOff2
, yOff2
, himl2
->cx
, himl2
->cy
, himl2
->hdcMask
, pt2
.x
, pt2
.y
, SRCAND
);
2186 himlDst
->cCurImage
= 1;
2193 /* helper for ImageList_Read, see comments below */
2194 static void *read_bitmap(IStream
*pstm
, BITMAPINFO
*bmi
)
2196 BITMAPFILEHEADER bmfh
;
2197 int bitsperpixel
, palspace
;
2200 if (FAILED(IStream_Read ( pstm
, &bmfh
, sizeof(bmfh
), NULL
)))
2203 if (bmfh
.bfType
!= (('M'<<8)|'B'))
2206 if (FAILED(IStream_Read ( pstm
, &bmi
->bmiHeader
, sizeof(bmi
->bmiHeader
), NULL
)))
2209 if ((bmi
->bmiHeader
.biSize
!= sizeof(bmi
->bmiHeader
)))
2212 TRACE("width %lu, height %lu, planes %u, bpp %u\n",
2213 bmi
->bmiHeader
.biWidth
, bmi
->bmiHeader
.biHeight
,
2214 bmi
->bmiHeader
.biPlanes
, bmi
->bmiHeader
.biBitCount
);
2216 bitsperpixel
= bmi
->bmiHeader
.biPlanes
* bmi
->bmiHeader
.biBitCount
;
2217 if (bitsperpixel
<=8)
2218 palspace
= (1<<bitsperpixel
)*sizeof(RGBQUAD
);
2222 bmi
->bmiHeader
.biSizeImage
= get_dib_image_size( bmi
);
2224 /* read the palette right after the end of the bitmapinfoheader */
2225 if (palspace
&& FAILED(IStream_Read(pstm
, bmi
->bmiColors
, palspace
, NULL
)))
2228 bits
= Alloc(bmi
->bmiHeader
.biSizeImage
);
2229 if (!bits
) return NULL
;
2231 if (FAILED(IStream_Read(pstm
, bits
, bmi
->bmiHeader
.biSizeImage
, NULL
)))
2239 /*************************************************************************
2240 * ImageList_Read [COMCTL32.@]
2242 * Reads an image list from a stream.
2245 * pstm [I] pointer to a stream
2248 * Success: handle to image list
2251 * The format is like this:
2252 * ILHEAD ilheadstruct;
2254 * for the color image part:
2255 * BITMAPFILEHEADER bmfh;
2256 * BITMAPINFOHEADER bmih;
2257 * only if it has a palette:
2258 * RGBQUAD rgbs[nr_of_paletted_colors];
2260 * BYTE colorbits[imagesize];
2262 * the following only if the ILC_MASK bit is set in ILHEAD.ilFlags:
2263 * BITMAPFILEHEADER bmfh_mask;
2264 * BITMAPINFOHEADER bmih_mask;
2265 * only if it has a palette (it usually does not):
2266 * RGBQUAD rgbs[nr_of_paletted_colors];
2268 * BYTE maskbits[imagesize];
2270 HIMAGELIST WINAPI
ImageList_Read(IStream
*pstm
)
2272 char image_buf
[sizeof(BITMAPINFOHEADER
) + sizeof(RGBQUAD
) * 256];
2273 char mask_buf
[sizeof(BITMAPINFOHEADER
) + sizeof(RGBQUAD
) * 256];
2274 BITMAPINFO
*image_info
= (BITMAPINFO
*)image_buf
;
2275 BITMAPINFO
*mask_info
= (BITMAPINFO
*)mask_buf
;
2276 void *image_bits
, *mask_bits
= NULL
;
2281 TRACE("%p\n", pstm
);
2283 if (FAILED(IStream_Read (pstm
, &ilHead
, sizeof(ILHEAD
), NULL
)))
2285 if (ilHead
.usMagic
!= (('L' << 8) | 'I'))
2287 if (ilHead
.usVersion
!= 0x101) /* probably version? */
2290 TRACE("cx %u, cy %u, flags 0x%04x, cCurImage %u, cMaxImage %u\n",
2291 ilHead
.cx
, ilHead
.cy
, ilHead
.flags
, ilHead
.cCurImage
, ilHead
.cMaxImage
);
2293 himl
= ImageList_Create(ilHead
.cx
, ilHead
.cy
, ilHead
.flags
, ilHead
.cMaxImage
, ilHead
.cGrow
);
2297 if (!(image_bits
= read_bitmap(pstm
, image_info
)))
2299 WARN("failed to read bitmap from stream\n");
2302 if (ilHead
.flags
& ILC_MASK
)
2304 if (!(mask_bits
= read_bitmap(pstm
, mask_info
)))
2306 WARN("failed to read mask bitmap from stream\n");
2310 else mask_info
= NULL
;
2312 if ((himl
->flags
& 0xfe) == ILC_COLOR32
&& image_info
->bmiHeader
.biBitCount
== 32)
2314 DWORD
*ptr
= image_bits
;
2315 BYTE
*mask_ptr
= mask_bits
;
2316 int stride
= himl
->cy
* image_info
->bmiHeader
.biWidth
;
2318 if (image_info
->bmiHeader
.biHeight
> 0) /* bottom-up */
2320 ptr
+= image_info
->bmiHeader
.biHeight
* image_info
->bmiHeader
.biWidth
- stride
;
2321 mask_ptr
+= (image_info
->bmiHeader
.biHeight
* image_info
->bmiHeader
.biWidth
- stride
) / 8;
2323 image_info
->bmiHeader
.biHeight
= himl
->cy
;
2325 else image_info
->bmiHeader
.biHeight
= -himl
->cy
;
2327 for (i
= 0; i
< ilHead
.cCurImage
; i
+= TILE_COUNT
)
2329 add_dib_bits( himl
, i
, min( ilHead
.cCurImage
- i
, TILE_COUNT
),
2330 himl
->cx
, himl
->cy
, image_info
, mask_info
, ptr
, mask_ptr
);
2332 mask_ptr
+= stride
/ 8;
2337 StretchDIBits( himl
->hdcImage
, 0, 0, image_info
->bmiHeader
.biWidth
, image_info
->bmiHeader
.biHeight
,
2338 0, 0, image_info
->bmiHeader
.biWidth
, image_info
->bmiHeader
.biHeight
,
2339 image_bits
, image_info
, DIB_RGB_COLORS
, SRCCOPY
);
2341 StretchDIBits( himl
->hdcMask
, 0, 0, mask_info
->bmiHeader
.biWidth
, mask_info
->bmiHeader
.biHeight
,
2342 0, 0, mask_info
->bmiHeader
.biWidth
, mask_info
->bmiHeader
.biHeight
,
2343 mask_bits
, mask_info
, DIB_RGB_COLORS
, SRCCOPY
);
2348 himl
->cCurImage
= ilHead
.cCurImage
;
2349 himl
->cMaxImage
= ilHead
.cMaxImage
;
2351 ImageList_SetBkColor(himl
,ilHead
.bkcolor
);
2353 ImageList_SetOverlayImage(himl
,ilHead
.ovls
[i
],i
+1);
2358 /*************************************************************************
2359 * ImageList_Remove [COMCTL32.@]
2361 * Removes an image from an image list
2364 * himl [I] image list handle
2371 * FIXME: as the image list storage test shows, native comctl32 simply shifts
2372 * images without creating a new bitmap.
2375 ImageList_Remove (HIMAGELIST himl
, INT i
)
2377 HBITMAP hbmNewImage
, hbmNewMask
;
2381 TRACE("(himl=%p i=%d)\n", himl
, i
);
2383 if (!is_valid(himl
)) {
2384 ERR("Invalid image list handle!\n");
2388 if ((i
< -1) || (i
>= himl
->cCurImage
)) {
2389 TRACE("index out of range! %d\n", i
);
2397 if (himl
->cCurImage
== 0) {
2398 /* remove all on empty ImageList is allowed */
2399 TRACE("remove all on empty ImageList!\n");
2403 himl
->cMaxImage
= himl
->cGrow
;
2404 himl
->cCurImage
= 0;
2405 for (nCount
= 0; nCount
< MAX_OVERLAYIMAGE
; nCount
++)
2406 himl
->nOvlIdx
[nCount
] = -1;
2408 Free( himl
->item_flags
);
2409 himl
->item_flags
= Alloc( himl
->cMaxImage
* sizeof(*himl
->item_flags
) );
2411 hbmNewImage
= ImageList_CreateImage(himl
->hdcImage
, himl
, himl
->cMaxImage
);
2412 SelectObject (himl
->hdcImage
, hbmNewImage
);
2413 DeleteObject (himl
->hbmImage
);
2414 himl
->hbmImage
= hbmNewImage
;
2416 if (himl
->hbmMask
) {
2418 imagelist_get_bitmap_size(himl
, himl
->cMaxImage
, &sz
);
2419 hbmNewMask
= CreateBitmap (sz
.cx
, sz
.cy
, 1, 1, NULL
);
2420 SelectObject (himl
->hdcMask
, hbmNewMask
);
2421 DeleteObject (himl
->hbmMask
);
2422 himl
->hbmMask
= hbmNewMask
;
2426 /* delete one image */
2427 TRACE("Remove single image! %d\n", i
);
2429 /* create new bitmap(s) */
2430 TRACE(" - Number of images: %d / %d (Old/New)\n",
2431 himl
->cCurImage
, himl
->cCurImage
- 1);
2433 hbmNewImage
= ImageList_CreateImage(himl
->hdcImage
, himl
, himl
->cMaxImage
);
2435 imagelist_get_bitmap_size(himl
, himl
->cMaxImage
, &sz
);
2437 hbmNewMask
= CreateBitmap (sz
.cx
, sz
.cy
, 1, 1, NULL
);
2439 hbmNewMask
= 0; /* Just to keep compiler happy! */
2441 hdcBmp
= CreateCompatibleDC (0);
2443 /* copy all images and masks prior to the "removed" image */
2445 TRACE("Pre image copy: Copy %d images\n", i
);
2447 SelectObject (hdcBmp
, hbmNewImage
);
2448 imagelist_copy_images( himl
, himl
->hdcImage
, hdcBmp
, 0, i
, 0 );
2450 if (himl
->hbmMask
) {
2451 SelectObject (hdcBmp
, hbmNewMask
);
2452 imagelist_copy_images( himl
, himl
->hdcMask
, hdcBmp
, 0, i
, 0 );
2456 /* copy all images and masks behind the removed image */
2457 if (i
< himl
->cCurImage
- 1) {
2458 TRACE("Post image copy!\n");
2460 SelectObject (hdcBmp
, hbmNewImage
);
2461 imagelist_copy_images( himl
, himl
->hdcImage
, hdcBmp
, i
+ 1,
2462 (himl
->cCurImage
- i
), i
);
2464 if (himl
->hbmMask
) {
2465 SelectObject (hdcBmp
, hbmNewMask
);
2466 imagelist_copy_images( himl
, himl
->hdcMask
, hdcBmp
, i
+ 1,
2467 (himl
->cCurImage
- i
), i
);
2473 /* delete old images and insert new ones */
2474 SelectObject (himl
->hdcImage
, hbmNewImage
);
2475 DeleteObject (himl
->hbmImage
);
2476 himl
->hbmImage
= hbmNewImage
;
2477 if (himl
->hbmMask
) {
2478 SelectObject (himl
->hdcMask
, hbmNewMask
);
2479 DeleteObject (himl
->hbmMask
);
2480 himl
->hbmMask
= hbmNewMask
;
2490 /*************************************************************************
2491 * ImageList_Replace [COMCTL32.@]
2493 * Replaces an image in an image list with a new image.
2496 * himl [I] handle to image list
2498 * hbmImage [I] handle to image bitmap
2499 * hbmMask [I] handle to mask bitmap. Can be NULL.
2507 ImageList_Replace (HIMAGELIST himl
, INT i
, HBITMAP hbmImage
,
2514 TRACE("%p %d %p %p\n", himl
, i
, hbmImage
, hbmMask
);
2516 if (!is_valid(himl
)) {
2517 ERR("Invalid image list handle!\n");
2521 if ((i
>= himl
->cMaxImage
) || (i
< 0)) {
2522 ERR("Invalid image index!\n");
2526 if (!GetObjectW(hbmImage
, sizeof(BITMAP
), &bmp
))
2529 hdcImage
= CreateCompatibleDC (0);
2532 SelectObject (hdcImage
, hbmImage
);
2534 if (add_with_alpha( himl
, hdcImage
, i
, 1, bmp
.bmWidth
, bmp
.bmHeight
, hbmImage
, hbmMask
))
2537 imagelist_point_from_index(himl
, i
, &pt
);
2538 StretchBlt (himl
->hdcImage
, pt
.x
, pt
.y
, himl
->cx
, himl
->cy
,
2539 hdcImage
, 0, 0, bmp
.bmWidth
, bmp
.bmHeight
, SRCCOPY
);
2544 HBITMAP hOldBitmapTemp
;
2546 hdcTemp
= CreateCompatibleDC(0);
2547 hOldBitmapTemp
= SelectObject(hdcTemp
, hbmMask
);
2549 StretchBlt (himl
->hdcMask
, pt
.x
, pt
.y
, himl
->cx
, himl
->cy
,
2550 hdcTemp
, 0, 0, bmp
.bmWidth
, bmp
.bmHeight
, SRCCOPY
);
2551 SelectObject(hdcTemp
, hOldBitmapTemp
);
2554 /* Remove the background from the image
2556 BitBlt (himl
->hdcImage
, pt
.x
, pt
.y
, bmp
.bmWidth
, bmp
.bmHeight
,
2557 himl
->hdcMask
, pt
.x
, pt
.y
, 0x220326); /* NOTSRCAND */
2561 DeleteDC (hdcImage
);
2567 /*************************************************************************
2568 * ImageList_ReplaceIcon [COMCTL32.@]
2570 * Replaces an image in an image list using an icon.
2573 * himl [I] handle to image list
2575 * hIcon [I] handle to icon
2578 * Success: index of the replaced image
2583 ImageList_ReplaceIcon (HIMAGELIST himl
, INT nIndex
, HICON hIcon
)
2591 TRACE("(%p %d %p)\n", himl
, nIndex
, hIcon
);
2593 if (!is_valid(himl
)) {
2594 ERR("invalid image list\n");
2597 if ((nIndex
>= himl
->cMaxImage
) || (nIndex
< -1)) {
2598 ERR("invalid image index %d / %d\n", nIndex
, himl
->cMaxImage
);
2602 hBestFitIcon
= CopyImage(
2605 LR_COPYFROMRESOURCE
);
2606 /* the above will fail if the icon wasn't loaded from a resource, so try
2607 * again without LR_COPYFROMRESOURCE flag */
2609 hBestFitIcon
= CopyImage(
2617 if (himl
->cCurImage
+ 1 >= himl
->cMaxImage
)
2618 IMAGELIST_InternalExpandBitmaps(himl
, 1);
2620 nIndex
= himl
->cCurImage
;
2624 if ((himl
->flags
& 0xfe) == ILC_COLOR32
&& GetIconInfo (hBestFitIcon
, &ii
))
2626 HDC hdcImage
= CreateCompatibleDC( 0 );
2627 GetObjectW (ii
.hbmMask
, sizeof(BITMAP
), &bmp
);
2631 UINT height
= bmp
.bmHeight
/ 2;
2632 HDC hdcMask
= CreateCompatibleDC( 0 );
2633 HBITMAP color
= CreateBitmap( bmp
.bmWidth
, height
, 1, 1, NULL
);
2634 SelectObject( hdcImage
, color
);
2635 SelectObject( hdcMask
, ii
.hbmMask
);
2636 BitBlt( hdcImage
, 0, 0, bmp
.bmWidth
, height
, hdcMask
, 0, height
, SRCCOPY
);
2637 ret
= add_with_alpha( himl
, hdcImage
, nIndex
, 1, bmp
.bmWidth
, height
, color
, ii
.hbmMask
);
2638 DeleteDC( hdcMask
);
2639 DeleteObject( color
);
2641 else ret
= add_with_alpha( himl
, hdcImage
, nIndex
, 1, bmp
.bmWidth
, bmp
.bmHeight
,
2642 ii
.hbmColor
, ii
.hbmMask
);
2644 DeleteDC( hdcImage
);
2645 DeleteObject (ii
.hbmMask
);
2646 if (ii
.hbmColor
) DeleteObject (ii
.hbmColor
);
2650 imagelist_point_from_index(himl
, nIndex
, &pt
);
2654 DrawIconEx( himl
->hdcImage
, pt
.x
, pt
.y
, hBestFitIcon
, himl
->cx
, himl
->cy
, 0, 0, DI_IMAGE
);
2655 PatBlt( himl
->hdcMask
, pt
.x
, pt
.y
, himl
->cx
, himl
->cy
, WHITENESS
);
2656 DrawIconEx( himl
->hdcMask
, pt
.x
, pt
.y
, hBestFitIcon
, himl
->cx
, himl
->cy
, 0, 0, DI_MASK
);
2660 COLORREF color
= himl
->clrBk
!= CLR_NONE
? himl
->clrBk
: comctl32_color
.clrWindow
;
2661 HBRUSH brush
= CreateSolidBrush( GetNearestColor( himl
->hdcImage
, color
));
2663 SelectObject( himl
->hdcImage
, brush
);
2664 PatBlt( himl
->hdcImage
, pt
.x
, pt
.y
, himl
->cx
, himl
->cy
, PATCOPY
);
2665 SelectObject( himl
->hdcImage
, GetStockObject(BLACK_BRUSH
) );
2666 DeleteObject( brush
);
2667 DrawIconEx( himl
->hdcImage
, pt
.x
, pt
.y
, hBestFitIcon
, himl
->cx
, himl
->cy
, 0, 0, DI_NORMAL
);
2671 DestroyIcon(hBestFitIcon
);
2673 TRACE("Insert index = %d, himl->cCurImage = %d\n", nIndex
, himl
->cCurImage
);
2678 /*************************************************************************
2679 * ImageList_SetBkColor [COMCTL32.@]
2681 * Sets the background color of an image list.
2684 * himl [I] handle to image list
2685 * clrBk [I] background color
2688 * Success: previous background color
2693 ImageList_SetBkColor (HIMAGELIST himl
, COLORREF clrBk
)
2697 if (!is_valid(himl
))
2700 clrOldBk
= himl
->clrBk
;
2701 himl
->clrBk
= clrBk
;
2706 /*************************************************************************
2707 * ImageList_SetDragCursorImage [COMCTL32.@]
2709 * Combines the specified image with the current drag image
2712 * himlDrag [I] handle to drag image list
2713 * iDrag [I] drag image index
2714 * dxHotspot [I] X position of the hot spot
2715 * dyHotspot [I] Y position of the hot spot
2722 * - The names dxHotspot, dyHotspot are misleading because they have nothing
2723 * to do with a hotspot but are only the offset of the origin of the new
2724 * image relative to the origin of the old image.
2726 * - When this function is called and the drag image is visible, a
2727 * short flickering occurs but this matches the Win9x behavior. It is
2728 * possible to fix the flickering using code like in ImageList_DragMove.
2732 ImageList_SetDragCursorImage (HIMAGELIST himlDrag
, INT iDrag
,
2733 INT dxHotspot
, INT dyHotspot
)
2735 HIMAGELIST himlTemp
;
2738 if (!is_valid(InternalDrag
.himl
) || !is_valid(himlDrag
))
2741 TRACE(" dxH=%d dyH=%d nX=%d nY=%d\n",
2742 dxHotspot
, dyHotspot
, InternalDrag
.dxHotspot
, InternalDrag
.dyHotspot
);
2744 visible
= InternalDrag
.bShow
;
2746 himlTemp
= ImageList_Merge (InternalDrag
.himlNoCursor
, 0, himlDrag
, iDrag
,
2747 dxHotspot
, dyHotspot
);
2750 /* hide the drag image */
2751 ImageList_DragShowNolock(FALSE
);
2753 if ((InternalDrag
.himl
->cx
!= himlTemp
->cx
) ||
2754 (InternalDrag
.himl
->cy
!= himlTemp
->cy
)) {
2755 /* the size of the drag image changed, invalidate the buffer */
2756 DeleteObject(InternalDrag
.hbmBg
);
2757 InternalDrag
.hbmBg
= 0;
2760 if (InternalDrag
.himl
!= InternalDrag
.himlNoCursor
)
2761 ImageList_Destroy (InternalDrag
.himl
);
2762 InternalDrag
.himl
= himlTemp
;
2765 /* show the drag image */
2766 ImageList_DragShowNolock(TRUE
);
2773 /*************************************************************************
2774 * ImageList_SetFilter [COMCTL32.@]
2776 * Sets a filter (or does something completely different)!!???
2777 * It removes 12 Bytes from the stack (3 Parameters).
2780 * himl [I] SHOULD be a handle to image list
2781 * i [I] COULD be an index?
2786 * Failure: FALSE ???
2789 * This is an UNDOCUMENTED function!!!!
2794 ImageList_SetFilter (HIMAGELIST himl
, INT i
, DWORD dwFilter
)
2796 FIXME("%p, %d, %#lx:empty stub!\n", himl
, i
, dwFilter
);
2802 /*************************************************************************
2803 * ImageList_SetFlags [COMCTL32.@]
2805 * Sets the image list flags.
2808 * himl [I] Handle to image list
2809 * flags [I] Flags to set
2819 ImageList_SetFlags(HIMAGELIST himl
, DWORD flags
)
2821 FIXME("(%p %#lx):empty stub\n", himl
, flags
);
2826 /*************************************************************************
2827 * ImageList_SetIconSize [COMCTL32.@]
2829 * Sets the image size of the bitmap and deletes all images.
2832 * himl [I] handle to image list
2833 * cx [I] image width
2834 * cy [I] image height
2842 ImageList_SetIconSize (HIMAGELIST himl
, INT cx
, INT cy
)
2847 if (!is_valid(himl
))
2850 /* remove all images */
2851 himl
->cMaxImage
= himl
->cInitial
+ 1;
2852 himl
->cCurImage
= 0;
2856 /* initialize overlay mask indices */
2857 for (nCount
= 0; nCount
< MAX_OVERLAYIMAGE
; nCount
++)
2858 himl
->nOvlIdx
[nCount
] = -1;
2860 hbmNew
= ImageList_CreateImage(himl
->hdcImage
, himl
, himl
->cMaxImage
);
2861 SelectObject (himl
->hdcImage
, hbmNew
);
2862 DeleteObject (himl
->hbmImage
);
2863 himl
->hbmImage
= hbmNew
;
2865 if (himl
->hbmMask
) {
2867 imagelist_get_bitmap_size(himl
, himl
->cMaxImage
, &sz
);
2868 hbmNew
= CreateBitmap (sz
.cx
, sz
.cy
, 1, 1, NULL
);
2869 SelectObject (himl
->hdcMask
, hbmNew
);
2870 DeleteObject (himl
->hbmMask
);
2871 himl
->hbmMask
= hbmNew
;
2878 /*************************************************************************
2879 * ImageList_SetImageCount [COMCTL32.@]
2881 * Resizes an image list to the specified number of images.
2884 * himl [I] handle to image list
2885 * iImageCount [I] number of images in the image list
2893 ImageList_SetImageCount (HIMAGELIST himl
, UINT iImageCount
)
2896 HBITMAP hbmNewBitmap
, hbmOld
;
2897 INT nNewCount
, nCopyCount
;
2899 TRACE("%p %d\n",himl
,iImageCount
);
2901 if (!is_valid(himl
))
2904 nNewCount
= iImageCount
+ 1;
2905 nCopyCount
= min(himl
->cCurImage
, iImageCount
);
2907 hdcBitmap
= CreateCompatibleDC (0);
2909 hbmNewBitmap
= ImageList_CreateImage(hdcBitmap
, himl
, nNewCount
);
2911 if (hbmNewBitmap
!= 0)
2913 hbmOld
= SelectObject (hdcBitmap
, hbmNewBitmap
);
2914 imagelist_copy_images( himl
, himl
->hdcImage
, hdcBitmap
, 0, nCopyCount
, 0 );
2915 SelectObject (hdcBitmap
, hbmOld
);
2917 /* FIXME: delete 'empty' image space? */
2919 SelectObject (himl
->hdcImage
, hbmNewBitmap
);
2920 DeleteObject (himl
->hbmImage
);
2921 himl
->hbmImage
= hbmNewBitmap
;
2924 ERR("Could not create new image bitmap!\n");
2929 imagelist_get_bitmap_size( himl
, nNewCount
, &sz
);
2930 hbmNewBitmap
= CreateBitmap (sz
.cx
, sz
.cy
, 1, 1, NULL
);
2931 if (hbmNewBitmap
!= 0)
2933 hbmOld
= SelectObject (hdcBitmap
, hbmNewBitmap
);
2934 imagelist_copy_images( himl
, himl
->hdcMask
, hdcBitmap
, 0, nCopyCount
, 0 );
2935 SelectObject (hdcBitmap
, hbmOld
);
2937 /* FIXME: delete 'empty' image space? */
2939 SelectObject (himl
->hdcMask
, hbmNewBitmap
);
2940 DeleteObject (himl
->hbmMask
);
2941 himl
->hbmMask
= hbmNewBitmap
;
2944 ERR("Could not create new mask bitmap!\n");
2947 DeleteDC (hdcBitmap
);
2949 himl
->item_flags
= HeapReAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, himl
->item_flags
,
2950 nNewCount
* sizeof(*himl
->item_flags
));
2952 /* Update max image count and current image count */
2953 himl
->cMaxImage
= nNewCount
;
2954 himl
->cCurImage
= iImageCount
;
2960 /*************************************************************************
2961 * ImageList_SetOverlayImage [COMCTL32.@]
2963 * Assigns an overlay mask index to an existing image in an image list.
2966 * himl [I] handle to image list
2967 * iImage [I] image index
2968 * iOverlay [I] overlay mask index
2976 ImageList_SetOverlayImage (HIMAGELIST himl
, INT iImage
, INT iOverlay
)
2978 if (!is_valid(himl
))
2980 if ((iOverlay
< 1) || (iOverlay
> MAX_OVERLAYIMAGE
))
2982 if ((iImage
!=-1) && ((iImage
< 0) || (iImage
> himl
->cCurImage
)))
2984 himl
->nOvlIdx
[iOverlay
- 1] = iImage
;
2990 /* helper for ImageList_Write - write bitmap to pstm
2991 * currently everything is written as 24 bit RGB, except masks
2993 static BOOL
_write_bitmap(HBITMAP hBitmap
, IStream
*pstm
)
2995 LPBITMAPFILEHEADER bmfh
;
2996 LPBITMAPINFOHEADER bmih
;
2997 LPBYTE data
= NULL
, lpBits
;
2999 INT bitCount
, sizeImage
, offBits
, totalSize
;
3001 BOOL result
= FALSE
;
3003 if (!GetObjectW(hBitmap
, sizeof(BITMAP
), &bm
))
3006 bitCount
= bm
.bmBitsPixel
;
3007 sizeImage
= get_dib_stride(bm
.bmWidth
, bitCount
) * bm
.bmHeight
;
3009 totalSize
= sizeof(BITMAPFILEHEADER
) + sizeof(BITMAPINFOHEADER
);
3011 totalSize
+= (1 << bitCount
) * sizeof(RGBQUAD
);
3012 offBits
= totalSize
;
3013 totalSize
+= sizeImage
;
3015 data
= Alloc(totalSize
);
3016 bmfh
= (LPBITMAPFILEHEADER
)data
;
3017 bmih
= (LPBITMAPINFOHEADER
)(data
+ sizeof(BITMAPFILEHEADER
));
3018 lpBits
= data
+ offBits
;
3020 /* setup BITMAPFILEHEADER */
3021 bmfh
->bfType
= (('M' << 8) | 'B');
3022 bmfh
->bfSize
= offBits
;
3023 bmfh
->bfReserved1
= 0;
3024 bmfh
->bfReserved2
= 0;
3025 bmfh
->bfOffBits
= offBits
;
3027 /* setup BITMAPINFOHEADER */
3028 bmih
->biSize
= sizeof(BITMAPINFOHEADER
);
3029 bmih
->biWidth
= bm
.bmWidth
;
3030 bmih
->biHeight
= bm
.bmHeight
;
3032 bmih
->biBitCount
= bitCount
;
3033 bmih
->biCompression
= BI_RGB
;
3034 bmih
->biSizeImage
= sizeImage
;
3035 bmih
->biXPelsPerMeter
= 0;
3036 bmih
->biYPelsPerMeter
= 0;
3037 bmih
->biClrUsed
= 0;
3038 bmih
->biClrImportant
= 0;
3041 result
= GetDIBits(xdc
, hBitmap
, 0, bm
.bmHeight
, lpBits
, (BITMAPINFO
*)bmih
, DIB_RGB_COLORS
) == bm
.bmHeight
;
3046 TRACE("width %lu, height %lu, planes %u, bpp %u\n",
3047 bmih
->biWidth
, bmih
->biHeight
,
3048 bmih
->biPlanes
, bmih
->biBitCount
);
3050 if(FAILED(IStream_Write(pstm
, data
, totalSize
, NULL
)))
3061 /*************************************************************************
3062 * ImageList_WriteEx [COMCTL32.@]
3064 HRESULT WINAPI
ImageList_WriteEx(HIMAGELIST himl
, DWORD flags
, IStream
*pstm
)
3066 FIXME("%p %#lx %p: semi-stub\n", himl
, flags
, pstm
);
3067 return ImageList_Write(himl
, pstm
) ? S_OK
: E_FAIL
;
3070 /*************************************************************************
3071 * ImageList_Write [COMCTL32.@]
3073 * Writes an image list to a stream.
3076 * himl [I] handle to image list
3077 * pstm [O] Pointer to a stream.
3087 BOOL WINAPI
ImageList_Write(HIMAGELIST himl
, IStream
*pstm
)
3092 TRACE("%p %p\n", himl
, pstm
);
3094 if (!is_valid(himl
))
3097 ilHead
.usMagic
= (('L' << 8) | 'I');
3098 ilHead
.usVersion
= 0x101;
3099 ilHead
.cCurImage
= himl
->cCurImage
;
3100 ilHead
.cMaxImage
= himl
->cMaxImage
;
3101 ilHead
.cGrow
= himl
->cGrow
;
3102 ilHead
.cx
= himl
->cx
;
3103 ilHead
.cy
= himl
->cy
;
3104 ilHead
.bkcolor
= himl
->clrBk
;
3105 ilHead
.flags
= himl
->flags
;
3106 for(i
= 0; i
< 4; i
++) {
3107 ilHead
.ovls
[i
] = himl
->nOvlIdx
[i
];
3110 TRACE("cx %u, cy %u, flags 0x04%x, cCurImage %u, cMaxImage %u\n",
3111 ilHead
.cx
, ilHead
.cy
, ilHead
.flags
, ilHead
.cCurImage
, ilHead
.cMaxImage
);
3113 if(FAILED(IStream_Write(pstm
, &ilHead
, sizeof(ILHEAD
), NULL
)))
3116 /* write the bitmap */
3117 if(!_write_bitmap(himl
->hbmImage
, pstm
))
3120 /* write the mask if we have one */
3121 if(himl
->flags
& ILC_MASK
) {
3122 if(!_write_bitmap(himl
->hbmMask
, pstm
))
3130 static HBITMAP
ImageList_CreateImage(HDC hdc
, HIMAGELIST himl
, UINT count
)
3132 HBITMAP hbmNewBitmap
;
3133 UINT ilc
= (himl
->flags
& 0xFE);
3136 imagelist_get_bitmap_size( himl
, count
, &sz
);
3138 if ((ilc
>= ILC_COLOR4
&& ilc
<= ILC_COLOR32
) || ilc
== ILC_COLOR
)
3140 char buffer
[sizeof(BITMAPINFOHEADER
) + 256 * sizeof(RGBQUAD
)];
3141 BITMAPINFO
*bmi
= (BITMAPINFO
*)buffer
;
3143 TRACE("Creating DIBSection %ld x %ld, %d Bits per Pixel\n",
3144 sz
.cx
, sz
.cy
, himl
->uBitsPixel
);
3146 memset( buffer
, 0, sizeof(buffer
) );
3147 bmi
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
3148 bmi
->bmiHeader
.biWidth
= sz
.cx
;
3149 bmi
->bmiHeader
.biHeight
= sz
.cy
;
3150 bmi
->bmiHeader
.biPlanes
= 1;
3151 bmi
->bmiHeader
.biBitCount
= himl
->uBitsPixel
;
3152 bmi
->bmiHeader
.biCompression
= BI_RGB
;
3154 if (himl
->uBitsPixel
<= ILC_COLOR8
)
3156 if (!himl
->color_table_set
)
3158 /* retrieve the default color map */
3159 HBITMAP tmp
= CreateBitmap( 1, 1, 1, 1, NULL
);
3160 GetDIBits( hdc
, tmp
, 0, 0, NULL
, bmi
, DIB_RGB_COLORS
);
3161 DeleteObject( tmp
);
3162 if (ilc
== ILC_COLOR4
)
3165 tmp
= bmi
->bmiColors
[7];
3166 bmi
->bmiColors
[7] = bmi
->bmiColors
[8];
3167 bmi
->bmiColors
[8] = tmp
;
3172 GetDIBColorTable(himl
->hdcImage
, 0, 1 << himl
->uBitsPixel
, bmi
->bmiColors
);
3175 hbmNewBitmap
= CreateDIBSection(hdc
, bmi
, DIB_RGB_COLORS
, NULL
, 0, 0);
3177 else /*if (ilc == ILC_COLORDDB)*/
3179 TRACE("Creating Bitmap: %d Bits per Pixel\n", himl
->uBitsPixel
);
3181 hbmNewBitmap
= CreateBitmap (sz
.cx
, sz
.cy
, 1, himl
->uBitsPixel
, NULL
);
3183 TRACE("returning %p\n", hbmNewBitmap
);
3184 return hbmNewBitmap
;
3187 /*************************************************************************
3188 * ImageList_SetColorTable [COMCTL32.@]
3190 * Sets the color table of an image list.
3193 * himl [I] Handle to the image list.
3194 * uStartIndex [I] The first index to set.
3195 * cEntries [I] Number of entries to set.
3196 * prgb [I] New color information for color table for the image list.
3199 * Success: Number of entries in the table that were set.
3203 * ImageList_Create(), SetDIBColorTable()
3207 ImageList_SetColorTable(HIMAGELIST himl
, UINT uStartIndex
, UINT cEntries
, const RGBQUAD
*prgb
)
3209 TRACE("(%p, %d, %d, %p)\n", himl
, uStartIndex
, cEntries
, prgb
);
3210 himl
->color_table_set
= TRUE
;
3211 return SetDIBColorTable(himl
->hdcImage
, uStartIndex
, cEntries
, prgb
);
3214 /*************************************************************************
3215 * ImageList_CoCreateInstance [COMCTL32.@]
3217 * Creates a new imagelist instance and returns an interface pointer to it.
3220 * rclsid [I] A reference to the CLSID (CLSID_ImageList).
3221 * punkOuter [I] Pointer to IUnknown interface for aggregation, if desired
3222 * riid [I] Identifier of the requested interface.
3223 * ppv [O] Returns the address of the pointer requested, or NULL.
3227 * Failure: Error value.
3230 ImageList_CoCreateInstance (REFCLSID rclsid
, const IUnknown
*punkOuter
, REFIID riid
, void **ppv
)
3232 TRACE("(%s,%p,%s,%p)\n", debugstr_guid(rclsid
), punkOuter
, debugstr_guid(riid
), ppv
);
3234 if (!IsEqualCLSID(&CLSID_ImageList
, rclsid
))
3235 return E_NOINTERFACE
;
3237 return ImageListImpl_CreateInstance(punkOuter
, riid
, ppv
);
3241 /*************************************************************************
3242 * IImageList implementation
3245 static HRESULT WINAPI
ImageListImpl_QueryInterface(IImageList2
*iface
,
3246 REFIID iid
, void **ppv
)
3248 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3250 TRACE("(%p,%s,%p)\n", iface
, debugstr_guid(iid
), ppv
);
3252 if (!ppv
) return E_INVALIDARG
;
3254 if (IsEqualIID(&IID_IUnknown
, iid
) ||
3255 IsEqualIID(&IID_IImageList
, iid
) ||
3256 IsEqualIID(&IID_IImageList2
, iid
))
3258 *ppv
= &imgl
->IImageList2_iface
;
3263 return E_NOINTERFACE
;
3266 IImageList2_AddRef(iface
);
3270 static ULONG WINAPI
ImageListImpl_AddRef(IImageList2
*iface
)
3272 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3273 ULONG ref
= InterlockedIncrement(&imgl
->ref
);
3275 TRACE("%p, refcount %lu\n", iface
, ref
);
3279 static ULONG WINAPI
ImageListImpl_Release(IImageList2
*iface
)
3281 HIMAGELIST This
= impl_from_IImageList2(iface
);
3282 ULONG ref
= InterlockedDecrement(&This
->ref
);
3284 TRACE("%p, refcount %lu\n", iface
, ref
);
3288 /* delete image bitmaps */
3289 if (This
->hbmImage
) DeleteObject (This
->hbmImage
);
3290 if (This
->hbmMask
) DeleteObject (This
->hbmMask
);
3292 /* delete image & mask DCs */
3293 if (This
->hdcImage
) DeleteDC (This
->hdcImage
);
3294 if (This
->hdcMask
) DeleteDC (This
->hdcMask
);
3296 /* delete blending brushes */
3297 if (This
->hbrBlend25
) DeleteObject (This
->hbrBlend25
);
3298 if (This
->hbrBlend50
) DeleteObject (This
->hbrBlend50
);
3300 This
->IImageList2_iface
.lpVtbl
= NULL
;
3301 Free(This
->item_flags
);
3308 static HRESULT WINAPI
ImageListImpl_Add(IImageList2
*iface
, HBITMAP hbmImage
,
3309 HBITMAP hbmMask
, int *pi
)
3311 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3317 ret
= ImageList_Add(imgl
, hbmImage
, hbmMask
);
3326 static HRESULT WINAPI
ImageListImpl_ReplaceIcon(IImageList2
*iface
, int i
,
3327 HICON hicon
, int *pi
)
3329 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3335 ret
= ImageList_ReplaceIcon(imgl
, i
, hicon
);
3344 static HRESULT WINAPI
ImageListImpl_SetOverlayImage(IImageList2
*iface
,
3345 int iImage
, int iOverlay
)
3347 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3348 return ImageList_SetOverlayImage(imgl
, iImage
, iOverlay
) ? S_OK
: E_FAIL
;
3351 static HRESULT WINAPI
ImageListImpl_Replace(IImageList2
*iface
, int i
,
3352 HBITMAP hbmImage
, HBITMAP hbmMask
)
3354 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3355 return ImageList_Replace(imgl
, i
, hbmImage
, hbmMask
) ? S_OK
: E_FAIL
;
3358 static HRESULT WINAPI
ImageListImpl_AddMasked(IImageList2
*iface
, HBITMAP hbmImage
,
3359 COLORREF crMask
, int *pi
)
3361 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3367 ret
= ImageList_AddMasked(imgl
, hbmImage
, crMask
);
3376 static HRESULT WINAPI
ImageListImpl_Draw(IImageList2
*iface
,
3377 IMAGELISTDRAWPARAMS
*pimldp
)
3379 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3380 HIMAGELIST old_himl
;
3383 /* As far as I can tell, Windows simply ignores the contents of pimldp->himl
3384 so we shall simulate the same */
3385 old_himl
= pimldp
->himl
;
3386 pimldp
->himl
= imgl
;
3388 ret
= ImageList_DrawIndirect(pimldp
);
3390 pimldp
->himl
= old_himl
;
3391 return ret
? S_OK
: E_INVALIDARG
;
3394 static HRESULT WINAPI
ImageListImpl_Remove(IImageList2
*iface
, int i
)
3396 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3397 return (ImageList_Remove(imgl
, i
) == 0) ? E_INVALIDARG
: S_OK
;
3400 static HRESULT WINAPI
ImageListImpl_GetIcon(IImageList2
*iface
, int i
, UINT flags
,
3403 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3409 hIcon
= ImageList_GetIcon(imgl
, i
, flags
);
3418 static HRESULT WINAPI
ImageListImpl_GetImageInfo(IImageList2
*iface
, int i
,
3419 IMAGEINFO
*pImageInfo
)
3421 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3422 return ImageList_GetImageInfo(imgl
, i
, pImageInfo
) ? S_OK
: E_FAIL
;
3425 static HRESULT WINAPI
ImageListImpl_Copy(IImageList2
*iface
, int dst_index
,
3426 IUnknown
*unk_src
, int src_index
, UINT flags
)
3428 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3429 IImageList
*src
= NULL
;
3435 /* TODO: Add test for IID_ImageList2 too */
3436 if (FAILED(IUnknown_QueryInterface(unk_src
, &IID_IImageList
,
3440 if (ImageList_Copy(imgl
, dst_index
, (HIMAGELIST
) src
, src_index
, flags
))
3445 IImageList_Release(src
);
3449 static HRESULT WINAPI
ImageListImpl_Merge(IImageList2
*iface
, int i1
,
3450 IUnknown
*punk2
, int i2
, int dx
, int dy
, REFIID riid
, void **ppv
)
3452 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3453 IImageList
*iml2
= NULL
;
3455 HRESULT ret
= E_FAIL
;
3457 TRACE("(%p)->(%d %p %d %d %d %s %p)\n", iface
, i1
, punk2
, i2
, dx
, dy
, debugstr_guid(riid
), ppv
);
3459 /* TODO: Add test for IID_ImageList2 too */
3460 if (FAILED(IUnknown_QueryInterface(punk2
, &IID_IImageList
,
3464 merged
= ImageList_Merge(imgl
, i1
, (HIMAGELIST
) iml2
, i2
, dx
, dy
);
3466 /* Get the interface for the new image list */
3469 ret
= HIMAGELIST_QueryInterface(merged
, riid
, ppv
);
3470 ImageList_Destroy(merged
);
3473 IImageList_Release(iml2
);
3477 static HRESULT WINAPI
ImageListImpl_Clone(IImageList2
*iface
, REFIID riid
, void **ppv
)
3479 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3481 HRESULT ret
= E_FAIL
;
3483 TRACE("(%p)->(%s %p)\n", iface
, debugstr_guid(riid
), ppv
);
3485 clone
= ImageList_Duplicate(imgl
);
3487 /* Get the interface for the new image list */
3490 ret
= HIMAGELIST_QueryInterface(clone
, riid
, ppv
);
3491 ImageList_Destroy(clone
);
3497 static HRESULT WINAPI
ImageListImpl_GetImageRect(IImageList2
*iface
, int i
,
3500 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3506 if (!ImageList_GetImageInfo(imgl
, i
, &info
))
3509 *prc
= info
.rcImage
;
3514 static HRESULT WINAPI
ImageListImpl_GetIconSize(IImageList2
*iface
, int *cx
,
3517 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3518 return ImageList_GetIconSize(imgl
, cx
, cy
) ? S_OK
: E_INVALIDARG
;
3521 static HRESULT WINAPI
ImageListImpl_SetIconSize(IImageList2
*iface
, int cx
,
3524 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3525 return ImageList_SetIconSize(imgl
, cx
, cy
) ? S_OK
: E_FAIL
;
3528 static HRESULT WINAPI
ImageListImpl_GetImageCount(IImageList2
*iface
, int *pi
)
3530 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3531 *pi
= ImageList_GetImageCount(imgl
);
3535 static HRESULT WINAPI
ImageListImpl_SetImageCount(IImageList2
*iface
, UINT count
)
3537 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3538 return ImageList_SetImageCount(imgl
, count
) ? S_OK
: E_FAIL
;
3541 static HRESULT WINAPI
ImageListImpl_SetBkColor(IImageList2
*iface
, COLORREF clrBk
,
3544 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3545 *pclr
= ImageList_SetBkColor(imgl
, clrBk
);
3549 static HRESULT WINAPI
ImageListImpl_GetBkColor(IImageList2
*iface
, COLORREF
*pclr
)
3551 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3552 *pclr
= ImageList_GetBkColor(imgl
);
3556 static HRESULT WINAPI
ImageListImpl_BeginDrag(IImageList2
*iface
, int iTrack
,
3557 int dxHotspot
, int dyHotspot
)
3559 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3560 return ImageList_BeginDrag(imgl
, iTrack
, dxHotspot
, dyHotspot
) ? S_OK
: E_FAIL
;
3563 static HRESULT WINAPI
ImageListImpl_EndDrag(IImageList2
*iface
)
3565 ImageList_EndDrag();
3569 static HRESULT WINAPI
ImageListImpl_DragEnter(IImageList2
*iface
, HWND hwndLock
,
3572 return ImageList_DragEnter(hwndLock
, x
, y
) ? S_OK
: E_FAIL
;
3575 static HRESULT WINAPI
ImageListImpl_DragLeave(IImageList2
*iface
, HWND hwndLock
)
3577 return ImageList_DragLeave(hwndLock
) ? S_OK
: E_FAIL
;
3580 static HRESULT WINAPI
ImageListImpl_DragMove(IImageList2
*iface
, int x
, int y
)
3582 return ImageList_DragMove(x
, y
) ? S_OK
: E_FAIL
;
3585 static HRESULT WINAPI
ImageListImpl_SetDragCursorImage(IImageList2
*iface
,
3586 IUnknown
*punk
, int iDrag
, int dxHotspot
, int dyHotspot
)
3588 IImageList
*iml2
= NULL
;
3594 /* TODO: Add test for IID_ImageList2 too */
3595 if (FAILED(IUnknown_QueryInterface(punk
, &IID_IImageList
,
3599 ret
= ImageList_SetDragCursorImage((HIMAGELIST
) iml2
, iDrag
, dxHotspot
,
3602 IImageList_Release(iml2
);
3604 return ret
? S_OK
: E_FAIL
;
3607 static HRESULT WINAPI
ImageListImpl_DragShowNolock(IImageList2
*iface
, BOOL fShow
)
3609 return ImageList_DragShowNolock(fShow
) ? S_OK
: E_FAIL
;
3612 static HRESULT WINAPI
ImageListImpl_GetDragImage(IImageList2
*iface
, POINT
*ppt
,
3613 POINT
*pptHotspot
, REFIID riid
, PVOID
*ppv
)
3615 HRESULT ret
= E_FAIL
;
3621 hNew
= ImageList_GetDragImage(ppt
, pptHotspot
);
3623 /* Get the interface for the new image list */
3626 IImageList
*idrag
= (IImageList
*)hNew
;
3628 ret
= HIMAGELIST_QueryInterface(hNew
, riid
, ppv
);
3629 IImageList_Release(idrag
);
3635 static HRESULT WINAPI
ImageListImpl_GetItemFlags(IImageList2
*iface
, int i
, DWORD
*flags
)
3637 HIMAGELIST This
= impl_from_IImageList2(iface
);
3639 if (i
< 0 || i
>= This
->cCurImage
)
3640 return E_INVALIDARG
;
3642 *flags
= This
->item_flags
[i
];
3647 static HRESULT WINAPI
ImageListImpl_GetOverlayImage(IImageList2
*iface
, int iOverlay
,
3650 HIMAGELIST This
= impl_from_IImageList2(iface
);
3653 if ((iOverlay
< 0) || (iOverlay
> This
->cCurImage
))
3656 for (i
= 0; i
< MAX_OVERLAYIMAGE
; i
++)
3658 if (This
->nOvlIdx
[i
] == iOverlay
)
3668 static HRESULT WINAPI
ImageListImpl_Resize(IImageList2
*iface
, INT cx
, INT cy
)
3670 FIXME("(%p)->(%d %d): stub\n", iface
, cx
, cy
);
3674 static HRESULT WINAPI
ImageListImpl_GetOriginalSize(IImageList2
*iface
, INT image
, DWORD flags
, INT
*cx
, INT
*cy
)
3676 FIXME("(%p)->(%d %lx %p %p): stub\n", iface
, image
, flags
, cx
, cy
);
3680 static HRESULT WINAPI
ImageListImpl_SetOriginalSize(IImageList2
*iface
, INT image
, INT cx
, INT cy
)
3682 FIXME("(%p)->(%d %d %d): stub\n", iface
, image
, cx
, cy
);
3686 static HRESULT WINAPI
ImageListImpl_SetCallback(IImageList2
*iface
, IUnknown
*callback
)
3688 FIXME("(%p)->(%p): stub\n", iface
, callback
);
3692 static HRESULT WINAPI
ImageListImpl_GetCallback(IImageList2
*iface
, REFIID riid
, void **ppv
)
3694 FIXME("(%p)->(%s %p): stub\n", iface
, debugstr_guid(riid
), ppv
);
3698 static HRESULT WINAPI
ImageListImpl_ForceImagePresent(IImageList2
*iface
, INT image
, DWORD flags
)
3700 FIXME("(%p)->(%d %lx): stub\n", iface
, image
, flags
);
3704 static HRESULT WINAPI
ImageListImpl_DiscardImages(IImageList2
*iface
, INT first_image
, INT last_image
, DWORD flags
)
3706 FIXME("(%p)->(%d %d %lx): stub\n", iface
, first_image
, last_image
, flags
);
3710 static HRESULT WINAPI
ImageListImpl_PreloadImages(IImageList2
*iface
, IMAGELISTDRAWPARAMS
*params
)
3712 FIXME("(%p)->(%p): stub\n", iface
, params
);
3716 static HRESULT WINAPI
ImageListImpl_GetStatistics(IImageList2
*iface
, IMAGELISTSTATS
*stats
)
3718 FIXME("(%p)->(%p): stub\n", iface
, stats
);
3722 static HRESULT WINAPI
ImageListImpl_Initialize(IImageList2
*iface
, INT cx
, INT cy
, UINT flags
, INT initial
, INT grow
)
3724 FIXME("(%p)->(%d %d %d %d %d): stub\n", iface
, cx
, cy
, flags
, initial
, grow
);
3728 static HRESULT WINAPI
ImageListImpl_Replace2(IImageList2
*iface
, INT i
, HBITMAP image
, HBITMAP mask
, IUnknown
*unk
, DWORD flags
)
3730 FIXME("(%p)->(%d %p %p %p %lx): stub\n", iface
, i
, image
, mask
, unk
, flags
);
3734 static HRESULT WINAPI
ImageListImpl_ReplaceFromImageList(IImageList2
*iface
, INT i
, IImageList
*imagelist
, INT src
,
3735 IUnknown
*unk
, DWORD flags
)
3737 FIXME("(%p)->(%d %p %d %p %lx): stub\n", iface
, i
, imagelist
, src
, unk
, flags
);
3741 static const IImageList2Vtbl ImageListImpl_Vtbl
= {
3742 ImageListImpl_QueryInterface
,
3743 ImageListImpl_AddRef
,
3744 ImageListImpl_Release
,
3746 ImageListImpl_ReplaceIcon
,
3747 ImageListImpl_SetOverlayImage
,
3748 ImageListImpl_Replace
,
3749 ImageListImpl_AddMasked
,
3751 ImageListImpl_Remove
,
3752 ImageListImpl_GetIcon
,
3753 ImageListImpl_GetImageInfo
,
3755 ImageListImpl_Merge
,
3756 ImageListImpl_Clone
,
3757 ImageListImpl_GetImageRect
,
3758 ImageListImpl_GetIconSize
,
3759 ImageListImpl_SetIconSize
,
3760 ImageListImpl_GetImageCount
,
3761 ImageListImpl_SetImageCount
,
3762 ImageListImpl_SetBkColor
,
3763 ImageListImpl_GetBkColor
,
3764 ImageListImpl_BeginDrag
,
3765 ImageListImpl_EndDrag
,
3766 ImageListImpl_DragEnter
,
3767 ImageListImpl_DragLeave
,
3768 ImageListImpl_DragMove
,
3769 ImageListImpl_SetDragCursorImage
,
3770 ImageListImpl_DragShowNolock
,
3771 ImageListImpl_GetDragImage
,
3772 ImageListImpl_GetItemFlags
,
3773 ImageListImpl_GetOverlayImage
,
3774 ImageListImpl_Resize
,
3775 ImageListImpl_GetOriginalSize
,
3776 ImageListImpl_SetOriginalSize
,
3777 ImageListImpl_SetCallback
,
3778 ImageListImpl_GetCallback
,
3779 ImageListImpl_ForceImagePresent
,
3780 ImageListImpl_DiscardImages
,
3781 ImageListImpl_PreloadImages
,
3782 ImageListImpl_GetStatistics
,
3783 ImageListImpl_Initialize
,
3784 ImageListImpl_Replace2
,
3785 ImageListImpl_ReplaceFromImageList
3788 static BOOL
is_valid(HIMAGELIST himl
)
3793 valid
= himl
&& himl
->IImageList2_iface
.lpVtbl
== &ImageListImpl_Vtbl
;
3803 /*************************************************************************
3804 * HIMAGELIST_QueryInterface [COMCTL32.@]
3806 * Returns a pointer to an IImageList or IImageList2 object for the given
3810 * himl [I] Image list handle.
3811 * riid [I] Identifier of the requested interface.
3812 * ppv [O] Returns the address of the pointer requested, or NULL.
3816 * Failure: Error value.
3819 HIMAGELIST_QueryInterface (HIMAGELIST himl
, REFIID riid
, void **ppv
)
3821 TRACE("(%p,%s,%p)\n", himl
, debugstr_guid(riid
), ppv
);
3822 return IImageList2_QueryInterface((IImageList2
*) himl
, riid
, ppv
);
3825 static HRESULT
ImageListImpl_CreateInstance(const IUnknown
*pUnkOuter
, REFIID iid
, void** ppv
)
3830 TRACE("(%p,%s,%p)\n", pUnkOuter
, debugstr_guid(iid
), ppv
);
3834 if (pUnkOuter
) return CLASS_E_NOAGGREGATION
;
3836 This
= Alloc(sizeof(struct _IMAGELIST
));
3837 if (!This
) return E_OUTOFMEMORY
;
3839 This
->IImageList2_iface
.lpVtbl
= &ImageListImpl_Vtbl
;
3842 ret
= IImageList2_QueryInterface(&This
->IImageList2_iface
, iid
, ppv
);
3843 IImageList2_Release(&This
->IImageList2_iface
);