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"
48 #include "wine/heap.h"
50 WINE_DEFAULT_DEBUG_CHANNEL(imagelist
);
52 #define MAX_OVERLAYIMAGE 15
56 IImageList2 IImageList2_iface
; /* 00: IImageList vtable */
57 INT cCurImage
; /* 04: ImageCount */
58 INT cMaxImage
; /* 08: maximages */
59 INT cGrow
; /* 0C: cGrow */
63 UINT flags
; /* 1C: flags */
64 COLORREF clrFg
; /* 20: foreground color */
65 COLORREF clrBk
; /* 24: background color */
68 HBITMAP hbmImage
; /* 28: images Bitmap */
69 HBITMAP hbmMask
; /* 2C: masks Bitmap */
70 HDC hdcImage
; /* 30: images MemDC */
71 HDC hdcMask
; /* 34: masks MemDC */
72 INT nOvlIdx
[MAX_OVERLAYIMAGE
]; /* 38: overlay images index */
74 /* not yet found out */
82 LONG ref
; /* reference count */
85 #define IMAGELIST_MAGIC 0x53414D58
87 /* Header used by ImageList_Read() and ImageList_Write() */
89 typedef struct _ILHEAD
104 /* internal image list data used for Drag & Drop operations */
109 HIMAGELIST himlNoCursor
;
110 /* position of the drag image relative to the window */
113 /* offset of the hotspot relative to the origin of the image */
116 /* is the drag image visible */
118 /* saved background */
122 static INTERNALDRAG InternalDrag
= { 0, 0, 0, 0, 0, 0, 0, FALSE
, 0 };
124 static inline HIMAGELIST
impl_from_IImageList2(IImageList2
*iface
)
126 return CONTAINING_RECORD(iface
, struct _IMAGELIST
, IImageList2_iface
);
129 static HBITMAP
ImageList_CreateImage(HDC hdc
, HIMAGELIST himl
, UINT count
);
130 static HRESULT
ImageListImpl_CreateInstance(const IUnknown
*pUnkOuter
, REFIID iid
, void** ppv
);
131 static BOOL
is_valid(HIMAGELIST himl
);
134 * An imagelist with N images is tiled like this:
146 BOOL
imagelist_has_alpha( HIMAGELIST himl
, UINT index
)
148 return himl
->item_flags
[index
] & ILIF_ALPHA
;
151 static inline UINT
imagelist_height( UINT count
)
153 return ((count
+ TILE_COUNT
- 1)/TILE_COUNT
);
156 static inline void imagelist_point_from_index( HIMAGELIST himl
, UINT index
, LPPOINT pt
)
158 pt
->x
= (index
%TILE_COUNT
) * himl
->cx
;
159 pt
->y
= (index
/TILE_COUNT
) * himl
->cy
;
162 static inline void imagelist_get_bitmap_size( HIMAGELIST himl
, UINT count
, SIZE
*sz
)
164 sz
->cx
= himl
->cx
* TILE_COUNT
;
165 sz
->cy
= imagelist_height( count
) * himl
->cy
;
168 static inline int get_dib_stride( int width
, int bpp
)
170 return ((width
* bpp
+ 31) >> 3) & ~3;
173 static inline int get_dib_image_size( const BITMAPINFO
*info
)
175 return get_dib_stride( info
->bmiHeader
.biWidth
, info
->bmiHeader
.biBitCount
)
176 * abs( info
->bmiHeader
.biHeight
);
180 * imagelist_copy_images()
182 * Copies a block of count images from offset src in the list to offset dest.
183 * Images are copied a row at at time. Assumes hdcSrc and hdcDest are different.
185 static inline void imagelist_copy_images( HIMAGELIST himl
, HDC hdcSrc
, HDC hdcDest
,
186 UINT src
, UINT count
, UINT dest
)
192 for ( i
=0; i
<TILE_COUNT
; i
++ )
194 imagelist_point_from_index( himl
, src
+i
, &ptSrc
);
195 imagelist_point_from_index( himl
, dest
+i
, &ptDest
);
197 sz
.cy
= himl
->cy
* imagelist_height( count
- i
);
199 BitBlt( hdcDest
, ptDest
.x
, ptDest
.y
, sz
.cx
, sz
.cy
,
200 hdcSrc
, ptSrc
.x
, ptSrc
.y
, SRCCOPY
);
204 static void add_dib_bits( HIMAGELIST himl
, int pos
, int count
, int width
, int height
,
205 BITMAPINFO
*info
, BITMAPINFO
*mask_info
, DWORD
*bits
, BYTE
*mask_bits
)
209 int stride
= info
->bmiHeader
.biWidth
;
210 int mask_stride
= (info
->bmiHeader
.biWidth
+ 31) / 32 * 4;
212 for (n
= 0; n
< count
; n
++)
214 BOOL has_alpha
= FALSE
;
216 imagelist_point_from_index( himl
, pos
+ n
, &pt
);
218 /* check if bitmap has an alpha channel */
219 for (i
= 0; i
< height
&& !has_alpha
; i
++)
220 for (j
= n
* width
; j
< (n
+ 1) * width
; j
++)
221 if ((has_alpha
= ((bits
[i
* stride
+ j
] & 0xff000000) != 0))) break;
225 himl
->item_flags
[pos
+ n
] = ILIF_ALPHA
;
227 if (mask_info
&& himl
->hbmMask
) /* generate the mask from the alpha channel */
229 for (i
= 0; i
< height
; i
++)
230 for (j
= n
* width
; j
< (n
+ 1) * width
; j
++)
231 if ((bits
[i
* stride
+ j
] >> 24) > 25) /* more than 10% alpha */
232 mask_bits
[i
* mask_stride
+ j
/ 8] &= ~(0x80 >> (j
% 8));
234 mask_bits
[i
* mask_stride
+ j
/ 8] |= 0x80 >> (j
% 8);
237 else if (mask_info
) /* mask out the background */
239 for (i
= 0; i
< height
; i
++)
240 for (j
= n
* width
; j
< (n
+ 1) * width
; j
++)
241 if ((mask_bits
[i
* mask_stride
+ j
/ 8] << (j
% 8)) & 0x80)
242 bits
[i
* stride
+ j
] = 0;
244 StretchDIBits( himl
->hdcImage
, pt
.x
, pt
.y
, himl
->cx
, himl
->cy
,
245 n
* width
, 0, width
, height
, bits
, info
, DIB_RGB_COLORS
, SRCCOPY
);
247 StretchDIBits( himl
->hdcMask
, pt
.x
, pt
.y
, himl
->cx
, himl
->cy
,
248 n
* width
, 0, width
, height
, mask_bits
, mask_info
, DIB_RGB_COLORS
, SRCCOPY
);
252 /* add images with an alpha channel when the image list is 32 bpp */
253 static BOOL
add_with_alpha( HIMAGELIST himl
, HDC hdc
, int pos
, int count
,
254 int width
, int height
, HBITMAP hbmImage
, HBITMAP hbmMask
)
258 BITMAPINFO
*info
, *mask_info
= NULL
;
260 BYTE
*mask_bits
= NULL
;
263 if (!GetObjectW( hbmImage
, sizeof(bm
), &bm
)) return FALSE
;
265 /* if either the imagelist or the source bitmap don't have an alpha channel, bail out now */
266 if ((himl
->flags
& 0xfe) != ILC_COLOR32
) return FALSE
;
267 if (bm
.bmBitsPixel
!= 32) return FALSE
;
269 SelectObject( hdc
, hbmImage
);
270 mask_width
= (bm
.bmWidth
+ 31) / 32 * 4;
272 if (!(info
= heap_alloc( FIELD_OFFSET( BITMAPINFO
, bmiColors
[256] )))) goto done
;
273 info
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
274 info
->bmiHeader
.biWidth
= bm
.bmWidth
;
275 info
->bmiHeader
.biHeight
= -height
;
276 info
->bmiHeader
.biPlanes
= 1;
277 info
->bmiHeader
.biBitCount
= 32;
278 info
->bmiHeader
.biCompression
= BI_RGB
;
279 info
->bmiHeader
.biSizeImage
= bm
.bmWidth
* height
* 4;
280 info
->bmiHeader
.biXPelsPerMeter
= 0;
281 info
->bmiHeader
.biYPelsPerMeter
= 0;
282 info
->bmiHeader
.biClrUsed
= 0;
283 info
->bmiHeader
.biClrImportant
= 0;
284 if (!(bits
= heap_alloc( info
->bmiHeader
.biSizeImage
))) goto done
;
285 if (!GetDIBits( hdc
, hbmImage
, 0, height
, bits
, info
, DIB_RGB_COLORS
)) goto done
;
289 if (!(mask_info
= heap_alloc( FIELD_OFFSET( BITMAPINFO
, bmiColors
[2] ))))
291 mask_info
->bmiHeader
= info
->bmiHeader
;
292 mask_info
->bmiHeader
.biBitCount
= 1;
293 mask_info
->bmiHeader
.biSizeImage
= mask_width
* height
;
294 if (!(mask_bits
= heap_alloc_zero( mask_info
->bmiHeader
.biSizeImage
)))
296 if (!GetDIBits( hdc
, hbmMask
, 0, height
, mask_bits
, mask_info
, DIB_RGB_COLORS
)) goto done
;
299 add_dib_bits( himl
, pos
, count
, width
, height
, info
, mask_info
, bits
, mask_bits
);
304 heap_free( mask_info
);
306 heap_free( mask_bits
);
311 ImageList_SetColorTable(HIMAGELIST himl
, UINT uStartIndex
, UINT cEntries
, const RGBQUAD
*prgb
);
313 /*************************************************************************
314 * IMAGELIST_InternalExpandBitmaps [Internal]
316 * Expands the bitmaps of an image list by the given number of images.
319 * himl [I] handle to image list
320 * nImageCount [I] number of images to add
326 * This function CANNOT be used to reduce the number of images.
329 IMAGELIST_InternalExpandBitmaps(HIMAGELIST himl
, INT nImageCount
)
332 HBITMAP hbmNewBitmap
, hbmNull
;
336 TRACE("%p has allocated %d, max %d, grow %d images\n", himl
, himl
->cCurImage
, himl
->cMaxImage
, himl
->cGrow
);
338 if (himl
->cCurImage
+ nImageCount
< himl
->cMaxImage
)
341 nNewCount
= himl
->cMaxImage
+ max(nImageCount
, himl
->cGrow
) + 1;
343 imagelist_get_bitmap_size(himl
, nNewCount
, &sz
);
345 TRACE("Create expanded bitmaps : himl=%p x=%d y=%d count=%d\n", himl
, sz
.cx
, sz
.cy
, nNewCount
);
346 hdcBitmap
= CreateCompatibleDC (0);
348 hbmNewBitmap
= ImageList_CreateImage(hdcBitmap
, himl
, nNewCount
);
350 if (hbmNewBitmap
== 0)
351 ERR("creating new image bitmap (x=%d y=%d)!\n", sz
.cx
, sz
.cy
);
355 hbmNull
= SelectObject (hdcBitmap
, hbmNewBitmap
);
356 BitBlt (hdcBitmap
, 0, 0, sz
.cx
, sz
.cy
,
357 himl
->hdcImage
, 0, 0, SRCCOPY
);
358 SelectObject (hdcBitmap
, hbmNull
);
360 SelectObject (himl
->hdcImage
, hbmNewBitmap
);
361 DeleteObject (himl
->hbmImage
);
362 himl
->hbmImage
= hbmNewBitmap
;
364 if (himl
->flags
& ILC_MASK
)
366 hbmNewBitmap
= CreateBitmap (sz
.cx
, sz
.cy
, 1, 1, NULL
);
368 if (hbmNewBitmap
== 0)
369 ERR("creating new mask bitmap!\n");
373 hbmNull
= SelectObject (hdcBitmap
, hbmNewBitmap
);
374 BitBlt (hdcBitmap
, 0, 0, sz
.cx
, sz
.cy
,
375 himl
->hdcMask
, 0, 0, SRCCOPY
);
376 SelectObject (hdcBitmap
, hbmNull
);
378 SelectObject (himl
->hdcMask
, hbmNewBitmap
);
379 DeleteObject (himl
->hbmMask
);
380 himl
->hbmMask
= hbmNewBitmap
;
383 himl
->item_flags
= HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, himl
->item_flags
,
384 nNewCount
* sizeof(*himl
->item_flags
));
385 himl
->cMaxImage
= nNewCount
;
387 DeleteDC (hdcBitmap
);
391 /*************************************************************************
392 * ImageList_Add [COMCTL32.@]
394 * Add an image or images to an image list.
397 * himl [I] handle to image list
398 * hbmImage [I] handle to image bitmap
399 * hbmMask [I] handle to mask bitmap
402 * Success: Index of the first new image.
407 ImageList_Add (HIMAGELIST himl
, HBITMAP hbmImage
, HBITMAP hbmMask
)
409 HDC hdcBitmap
, hdcTemp
= 0;
410 INT nFirstIndex
, nImageCount
, i
;
414 TRACE("himl=%p hbmimage=%p hbmmask=%p\n", himl
, hbmImage
, hbmMask
);
418 if (!GetObjectW(hbmImage
, sizeof(BITMAP
), &bmp
))
421 TRACE("himl %p, cCurImage %d, cMaxImage %d, cGrow %d, cx %d, cy %d\n",
422 himl
, himl
->cCurImage
, himl
->cMaxImage
, himl
->cGrow
, himl
->cx
, himl
->cy
);
424 nImageCount
= bmp
.bmWidth
/ himl
->cx
;
426 TRACE("%p has %d images (%d x %d) bpp %d\n", hbmImage
, nImageCount
, bmp
.bmWidth
, bmp
.bmHeight
,
429 IMAGELIST_InternalExpandBitmaps(himl
, nImageCount
);
431 hdcBitmap
= CreateCompatibleDC(0);
433 SelectObject(hdcBitmap
, hbmImage
);
435 if (add_with_alpha( himl
, hdcBitmap
, himl
->cCurImage
, nImageCount
,
436 himl
->cx
, min( himl
->cy
, bmp
.bmHeight
), hbmImage
, hbmMask
))
441 hdcTemp
= CreateCompatibleDC(0);
442 SelectObject(hdcTemp
, hbmMask
);
445 if (himl
->uBitsPixel
<= 8 && bmp
.bmBitsPixel
<= 8 &&
446 !himl
->color_table_set
&& himl
->cCurImage
== 0)
449 UINT num
= GetDIBColorTable( hdcBitmap
, 0, 1 << bmp
.bmBitsPixel
, colors
);
450 if (num
) ImageList_SetColorTable( himl
, 0, num
, colors
);
453 for (i
=0; i
<nImageCount
; i
++)
455 imagelist_point_from_index( himl
, himl
->cCurImage
+ i
, &pt
);
457 /* Copy result to the imagelist
459 BitBlt( himl
->hdcImage
, pt
.x
, pt
.y
, himl
->cx
, bmp
.bmHeight
,
460 hdcBitmap
, i
*himl
->cx
, 0, SRCCOPY
);
465 BitBlt( himl
->hdcMask
, pt
.x
, pt
.y
, himl
->cx
, bmp
.bmHeight
,
466 hdcTemp
, i
*himl
->cx
, 0, SRCCOPY
);
468 /* Remove the background from the image
470 BitBlt( himl
->hdcImage
, pt
.x
, pt
.y
, himl
->cx
, bmp
.bmHeight
,
471 himl
->hdcMask
, pt
.x
, pt
.y
, 0x220326 ); /* NOTSRCAND */
473 if (hdcTemp
) DeleteDC(hdcTemp
);
478 nFirstIndex
= himl
->cCurImage
;
479 himl
->cCurImage
+= nImageCount
;
485 /*************************************************************************
486 * ImageList_AddIcon [COMCTL32.@]
488 * Adds an icon to an image list.
491 * himl [I] handle to image list
492 * hIcon [I] handle to icon
495 * Success: index of the new image
498 #undef ImageList_AddIcon
499 INT WINAPI
ImageList_AddIcon (HIMAGELIST himl
, HICON hIcon
)
501 return ImageList_ReplaceIcon (himl
, -1, hIcon
);
505 /*************************************************************************
506 * ImageList_AddMasked [COMCTL32.@]
508 * Adds an image or images to an image list and creates a mask from the
509 * specified bitmap using the mask color.
512 * himl [I] handle to image list.
513 * hBitmap [I] handle to bitmap
514 * clrMask [I] mask color.
517 * Success: Index of the first new image.
522 ImageList_AddMasked (HIMAGELIST himl
, HBITMAP hBitmap
, COLORREF clrMask
)
524 HDC hdcMask
, hdcBitmap
;
530 TRACE("himl=%p hbitmap=%p clrmask=%x\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
= heap_alloc_zero( 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
= heap_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
= heap_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 %u, height %u, 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
= heap_alloc_zero(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
);
2345 heap_free( image_bits
);
2346 heap_free( mask_bits
);
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 heap_free( himl
->item_flags
);
2409 himl
->item_flags
= heap_alloc_zero( 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 0x%x 0x%x):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 %08x):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
= heap_alloc_zero(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 %u, height %u, planes %u, bpp %u\n",
3047 bmih
->biWidth
, bmih
->biHeight
,
3048 bmih
->biPlanes
, bmih
->biBitCount
);
3050 if(FAILED(IStream_Write(pstm
, data
, totalSize
, NULL
)))
3062 /*************************************************************************
3063 * ImageList_Write [COMCTL32.@]
3065 * Writes an image list to a stream.
3068 * himl [I] handle to image list
3069 * pstm [O] Pointer to a stream.
3079 BOOL WINAPI
ImageList_Write(HIMAGELIST himl
, IStream
*pstm
)
3084 TRACE("%p %p\n", himl
, pstm
);
3086 if (!is_valid(himl
))
3089 ilHead
.usMagic
= (('L' << 8) | 'I');
3090 ilHead
.usVersion
= 0x101;
3091 ilHead
.cCurImage
= himl
->cCurImage
;
3092 ilHead
.cMaxImage
= himl
->cMaxImage
;
3093 ilHead
.cGrow
= himl
->cGrow
;
3094 ilHead
.cx
= himl
->cx
;
3095 ilHead
.cy
= himl
->cy
;
3096 ilHead
.bkcolor
= himl
->clrBk
;
3097 ilHead
.flags
= himl
->flags
;
3098 for(i
= 0; i
< 4; i
++) {
3099 ilHead
.ovls
[i
] = himl
->nOvlIdx
[i
];
3102 TRACE("cx %u, cy %u, flags 0x04%x, cCurImage %u, cMaxImage %u\n",
3103 ilHead
.cx
, ilHead
.cy
, ilHead
.flags
, ilHead
.cCurImage
, ilHead
.cMaxImage
);
3105 if(FAILED(IStream_Write(pstm
, &ilHead
, sizeof(ILHEAD
), NULL
)))
3108 /* write the bitmap */
3109 if(!_write_bitmap(himl
->hbmImage
, pstm
))
3112 /* write the mask if we have one */
3113 if(himl
->flags
& ILC_MASK
) {
3114 if(!_write_bitmap(himl
->hbmMask
, pstm
))
3122 static HBITMAP
ImageList_CreateImage(HDC hdc
, HIMAGELIST himl
, UINT count
)
3124 HBITMAP hbmNewBitmap
;
3125 UINT ilc
= (himl
->flags
& 0xFE);
3128 imagelist_get_bitmap_size( himl
, count
, &sz
);
3130 if ((ilc
>= ILC_COLOR4
&& ilc
<= ILC_COLOR32
) || ilc
== ILC_COLOR
)
3132 char buffer
[sizeof(BITMAPINFOHEADER
) + 256 * sizeof(RGBQUAD
)];
3133 BITMAPINFO
*bmi
= (BITMAPINFO
*)buffer
;
3135 TRACE("Creating DIBSection %d x %d, %d Bits per Pixel\n",
3136 sz
.cx
, sz
.cy
, himl
->uBitsPixel
);
3138 memset( buffer
, 0, sizeof(buffer
) );
3139 bmi
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
3140 bmi
->bmiHeader
.biWidth
= sz
.cx
;
3141 bmi
->bmiHeader
.biHeight
= sz
.cy
;
3142 bmi
->bmiHeader
.biPlanes
= 1;
3143 bmi
->bmiHeader
.biBitCount
= himl
->uBitsPixel
;
3144 bmi
->bmiHeader
.biCompression
= BI_RGB
;
3146 if (himl
->uBitsPixel
<= ILC_COLOR8
)
3148 if (!himl
->color_table_set
)
3150 /* retrieve the default color map */
3151 HBITMAP tmp
= CreateBitmap( 1, 1, 1, 1, NULL
);
3152 GetDIBits( hdc
, tmp
, 0, 0, NULL
, bmi
, DIB_RGB_COLORS
);
3153 DeleteObject( tmp
);
3154 if (ilc
== ILC_COLOR4
)
3157 tmp
= bmi
->bmiColors
[7];
3158 bmi
->bmiColors
[7] = bmi
->bmiColors
[8];
3159 bmi
->bmiColors
[8] = tmp
;
3164 GetDIBColorTable(himl
->hdcImage
, 0, 1 << himl
->uBitsPixel
, bmi
->bmiColors
);
3167 hbmNewBitmap
= CreateDIBSection(hdc
, bmi
, DIB_RGB_COLORS
, NULL
, 0, 0);
3169 else /*if (ilc == ILC_COLORDDB)*/
3171 TRACE("Creating Bitmap: %d Bits per Pixel\n", himl
->uBitsPixel
);
3173 hbmNewBitmap
= CreateBitmap (sz
.cx
, sz
.cy
, 1, himl
->uBitsPixel
, NULL
);
3175 TRACE("returning %p\n", hbmNewBitmap
);
3176 return hbmNewBitmap
;
3179 /*************************************************************************
3180 * ImageList_SetColorTable [COMCTL32.@]
3182 * Sets the color table of an image list.
3185 * himl [I] Handle to the image list.
3186 * uStartIndex [I] The first index to set.
3187 * cEntries [I] Number of entries to set.
3188 * prgb [I] New color information for color table for the image list.
3191 * Success: Number of entries in the table that were set.
3195 * ImageList_Create(), SetDIBColorTable()
3199 ImageList_SetColorTable(HIMAGELIST himl
, UINT uStartIndex
, UINT cEntries
, const RGBQUAD
*prgb
)
3201 TRACE("(%p, %d, %d, %p)\n", himl
, uStartIndex
, cEntries
, prgb
);
3202 himl
->color_table_set
= TRUE
;
3203 return SetDIBColorTable(himl
->hdcImage
, uStartIndex
, cEntries
, prgb
);
3206 /*************************************************************************
3207 * ImageList_CoCreateInstance [COMCTL32.@]
3209 * Creates a new imagelist instance and returns an interface pointer to it.
3212 * rclsid [I] A reference to the CLSID (CLSID_ImageList).
3213 * punkOuter [I] Pointer to IUnknown interface for aggregation, if desired
3214 * riid [I] Identifier of the requested interface.
3215 * ppv [O] Returns the address of the pointer requested, or NULL.
3219 * Failure: Error value.
3222 ImageList_CoCreateInstance (REFCLSID rclsid
, const IUnknown
*punkOuter
, REFIID riid
, void **ppv
)
3224 TRACE("(%s,%p,%s,%p)\n", debugstr_guid(rclsid
), punkOuter
, debugstr_guid(riid
), ppv
);
3226 if (!IsEqualCLSID(&CLSID_ImageList
, rclsid
))
3227 return E_NOINTERFACE
;
3229 return ImageListImpl_CreateInstance(punkOuter
, riid
, ppv
);
3233 /*************************************************************************
3234 * IImageList implementation
3237 static HRESULT WINAPI
ImageListImpl_QueryInterface(IImageList2
*iface
,
3238 REFIID iid
, void **ppv
)
3240 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3242 TRACE("(%p,%s,%p)\n", iface
, debugstr_guid(iid
), ppv
);
3244 if (!ppv
) return E_INVALIDARG
;
3246 if (IsEqualIID(&IID_IUnknown
, iid
) ||
3247 IsEqualIID(&IID_IImageList
, iid
) ||
3248 IsEqualIID(&IID_IImageList2
, iid
))
3250 *ppv
= &imgl
->IImageList2_iface
;
3255 return E_NOINTERFACE
;
3258 IImageList2_AddRef(iface
);
3262 static ULONG WINAPI
ImageListImpl_AddRef(IImageList2
*iface
)
3264 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3265 ULONG ref
= InterlockedIncrement(&imgl
->ref
);
3267 TRACE("(%p) refcount=%u\n", iface
, ref
);
3271 static ULONG WINAPI
ImageListImpl_Release(IImageList2
*iface
)
3273 HIMAGELIST This
= impl_from_IImageList2(iface
);
3274 ULONG ref
= InterlockedDecrement(&This
->ref
);
3276 TRACE("(%p) refcount=%u\n", iface
, ref
);
3280 /* delete image bitmaps */
3281 if (This
->hbmImage
) DeleteObject (This
->hbmImage
);
3282 if (This
->hbmMask
) DeleteObject (This
->hbmMask
);
3284 /* delete image & mask DCs */
3285 if (This
->hdcImage
) DeleteDC (This
->hdcImage
);
3286 if (This
->hdcMask
) DeleteDC (This
->hdcMask
);
3288 /* delete blending brushes */
3289 if (This
->hbrBlend25
) DeleteObject (This
->hbrBlend25
);
3290 if (This
->hbrBlend50
) DeleteObject (This
->hbrBlend50
);
3292 This
->IImageList2_iface
.lpVtbl
= NULL
;
3293 heap_free(This
->item_flags
);
3300 static HRESULT WINAPI
ImageListImpl_Add(IImageList2
*iface
, HBITMAP hbmImage
,
3301 HBITMAP hbmMask
, int *pi
)
3303 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3309 ret
= ImageList_Add(imgl
, hbmImage
, hbmMask
);
3318 static HRESULT WINAPI
ImageListImpl_ReplaceIcon(IImageList2
*iface
, int i
,
3319 HICON hicon
, int *pi
)
3321 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3327 ret
= ImageList_ReplaceIcon(imgl
, i
, hicon
);
3336 static HRESULT WINAPI
ImageListImpl_SetOverlayImage(IImageList2
*iface
,
3337 int iImage
, int iOverlay
)
3339 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3340 return ImageList_SetOverlayImage(imgl
, iImage
, iOverlay
) ? S_OK
: E_FAIL
;
3343 static HRESULT WINAPI
ImageListImpl_Replace(IImageList2
*iface
, int i
,
3344 HBITMAP hbmImage
, HBITMAP hbmMask
)
3346 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3347 return ImageList_Replace(imgl
, i
, hbmImage
, hbmMask
) ? S_OK
: E_FAIL
;
3350 static HRESULT WINAPI
ImageListImpl_AddMasked(IImageList2
*iface
, HBITMAP hbmImage
,
3351 COLORREF crMask
, int *pi
)
3353 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3359 ret
= ImageList_AddMasked(imgl
, hbmImage
, crMask
);
3368 static HRESULT WINAPI
ImageListImpl_Draw(IImageList2
*iface
,
3369 IMAGELISTDRAWPARAMS
*pimldp
)
3371 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3372 HIMAGELIST old_himl
;
3375 /* As far as I can tell, Windows simply ignores the contents of pimldp->himl
3376 so we shall simulate the same */
3377 old_himl
= pimldp
->himl
;
3378 pimldp
->himl
= imgl
;
3380 ret
= ImageList_DrawIndirect(pimldp
);
3382 pimldp
->himl
= old_himl
;
3383 return ret
? S_OK
: E_INVALIDARG
;
3386 static HRESULT WINAPI
ImageListImpl_Remove(IImageList2
*iface
, int i
)
3388 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3389 return (ImageList_Remove(imgl
, i
) == 0) ? E_INVALIDARG
: S_OK
;
3392 static HRESULT WINAPI
ImageListImpl_GetIcon(IImageList2
*iface
, int i
, UINT flags
,
3395 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3401 hIcon
= ImageList_GetIcon(imgl
, i
, flags
);
3410 static HRESULT WINAPI
ImageListImpl_GetImageInfo(IImageList2
*iface
, int i
,
3411 IMAGEINFO
*pImageInfo
)
3413 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3414 return ImageList_GetImageInfo(imgl
, i
, pImageInfo
) ? S_OK
: E_FAIL
;
3417 static HRESULT WINAPI
ImageListImpl_Copy(IImageList2
*iface
, int dst_index
,
3418 IUnknown
*unk_src
, int src_index
, UINT flags
)
3420 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3421 IImageList
*src
= NULL
;
3427 /* TODO: Add test for IID_ImageList2 too */
3428 if (FAILED(IUnknown_QueryInterface(unk_src
, &IID_IImageList
,
3432 if (ImageList_Copy(imgl
, dst_index
, (HIMAGELIST
) src
, src_index
, flags
))
3437 IImageList_Release(src
);
3441 static HRESULT WINAPI
ImageListImpl_Merge(IImageList2
*iface
, int i1
,
3442 IUnknown
*punk2
, int i2
, int dx
, int dy
, REFIID riid
, void **ppv
)
3444 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3445 IImageList
*iml2
= NULL
;
3447 HRESULT ret
= E_FAIL
;
3449 TRACE("(%p)->(%d %p %d %d %d %s %p)\n", iface
, i1
, punk2
, i2
, dx
, dy
, debugstr_guid(riid
), ppv
);
3451 /* TODO: Add test for IID_ImageList2 too */
3452 if (FAILED(IUnknown_QueryInterface(punk2
, &IID_IImageList
,
3456 merged
= ImageList_Merge(imgl
, i1
, (HIMAGELIST
) iml2
, i2
, dx
, dy
);
3458 /* Get the interface for the new image list */
3461 ret
= HIMAGELIST_QueryInterface(merged
, riid
, ppv
);
3462 ImageList_Destroy(merged
);
3465 IImageList_Release(iml2
);
3469 static HRESULT WINAPI
ImageListImpl_Clone(IImageList2
*iface
, REFIID riid
, void **ppv
)
3471 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3473 HRESULT ret
= E_FAIL
;
3475 TRACE("(%p)->(%s %p)\n", iface
, debugstr_guid(riid
), ppv
);
3477 clone
= ImageList_Duplicate(imgl
);
3479 /* Get the interface for the new image list */
3482 ret
= HIMAGELIST_QueryInterface(clone
, riid
, ppv
);
3483 ImageList_Destroy(clone
);
3489 static HRESULT WINAPI
ImageListImpl_GetImageRect(IImageList2
*iface
, int i
,
3492 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3498 if (!ImageList_GetImageInfo(imgl
, i
, &info
))
3501 *prc
= info
.rcImage
;
3506 static HRESULT WINAPI
ImageListImpl_GetIconSize(IImageList2
*iface
, int *cx
,
3509 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3510 return ImageList_GetIconSize(imgl
, cx
, cy
) ? S_OK
: E_INVALIDARG
;
3513 static HRESULT WINAPI
ImageListImpl_SetIconSize(IImageList2
*iface
, int cx
,
3516 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3517 return ImageList_SetIconSize(imgl
, cx
, cy
) ? S_OK
: E_FAIL
;
3520 static HRESULT WINAPI
ImageListImpl_GetImageCount(IImageList2
*iface
, int *pi
)
3522 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3523 *pi
= ImageList_GetImageCount(imgl
);
3527 static HRESULT WINAPI
ImageListImpl_SetImageCount(IImageList2
*iface
, UINT count
)
3529 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3530 return ImageList_SetImageCount(imgl
, count
) ? S_OK
: E_FAIL
;
3533 static HRESULT WINAPI
ImageListImpl_SetBkColor(IImageList2
*iface
, COLORREF clrBk
,
3536 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3537 *pclr
= ImageList_SetBkColor(imgl
, clrBk
);
3541 static HRESULT WINAPI
ImageListImpl_GetBkColor(IImageList2
*iface
, COLORREF
*pclr
)
3543 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3544 *pclr
= ImageList_GetBkColor(imgl
);
3548 static HRESULT WINAPI
ImageListImpl_BeginDrag(IImageList2
*iface
, int iTrack
,
3549 int dxHotspot
, int dyHotspot
)
3551 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3552 return ImageList_BeginDrag(imgl
, iTrack
, dxHotspot
, dyHotspot
) ? S_OK
: E_FAIL
;
3555 static HRESULT WINAPI
ImageListImpl_EndDrag(IImageList2
*iface
)
3557 ImageList_EndDrag();
3561 static HRESULT WINAPI
ImageListImpl_DragEnter(IImageList2
*iface
, HWND hwndLock
,
3564 return ImageList_DragEnter(hwndLock
, x
, y
) ? S_OK
: E_FAIL
;
3567 static HRESULT WINAPI
ImageListImpl_DragLeave(IImageList2
*iface
, HWND hwndLock
)
3569 return ImageList_DragLeave(hwndLock
) ? S_OK
: E_FAIL
;
3572 static HRESULT WINAPI
ImageListImpl_DragMove(IImageList2
*iface
, int x
, int y
)
3574 return ImageList_DragMove(x
, y
) ? S_OK
: E_FAIL
;
3577 static HRESULT WINAPI
ImageListImpl_SetDragCursorImage(IImageList2
*iface
,
3578 IUnknown
*punk
, int iDrag
, int dxHotspot
, int dyHotspot
)
3580 IImageList
*iml2
= NULL
;
3586 /* TODO: Add test for IID_ImageList2 too */
3587 if (FAILED(IUnknown_QueryInterface(punk
, &IID_IImageList
,
3591 ret
= ImageList_SetDragCursorImage((HIMAGELIST
) iml2
, iDrag
, dxHotspot
,
3594 IImageList_Release(iml2
);
3596 return ret
? S_OK
: E_FAIL
;
3599 static HRESULT WINAPI
ImageListImpl_DragShowNolock(IImageList2
*iface
, BOOL fShow
)
3601 return ImageList_DragShowNolock(fShow
) ? S_OK
: E_FAIL
;
3604 static HRESULT WINAPI
ImageListImpl_GetDragImage(IImageList2
*iface
, POINT
*ppt
,
3605 POINT
*pptHotspot
, REFIID riid
, PVOID
*ppv
)
3607 HRESULT ret
= E_FAIL
;
3613 hNew
= ImageList_GetDragImage(ppt
, pptHotspot
);
3615 /* Get the interface for the new image list */
3618 IImageList
*idrag
= (IImageList
*)hNew
;
3620 ret
= HIMAGELIST_QueryInterface(hNew
, riid
, ppv
);
3621 IImageList_Release(idrag
);
3627 static HRESULT WINAPI
ImageListImpl_GetItemFlags(IImageList2
*iface
, int i
, DWORD
*flags
)
3629 HIMAGELIST This
= impl_from_IImageList2(iface
);
3631 if (i
< 0 || i
>= This
->cCurImage
)
3632 return E_INVALIDARG
;
3634 *flags
= This
->item_flags
[i
];
3639 static HRESULT WINAPI
ImageListImpl_GetOverlayImage(IImageList2
*iface
, int iOverlay
,
3642 HIMAGELIST This
= impl_from_IImageList2(iface
);
3645 if ((iOverlay
< 0) || (iOverlay
> This
->cCurImage
))
3648 for (i
= 0; i
< MAX_OVERLAYIMAGE
; i
++)
3650 if (This
->nOvlIdx
[i
] == iOverlay
)
3660 static HRESULT WINAPI
ImageListImpl_Resize(IImageList2
*iface
, INT cx
, INT cy
)
3662 FIXME("(%p)->(%d %d): stub\n", iface
, cx
, cy
);
3666 static HRESULT WINAPI
ImageListImpl_GetOriginalSize(IImageList2
*iface
, INT image
, DWORD flags
, INT
*cx
, INT
*cy
)
3668 FIXME("(%p)->(%d %x %p %p): stub\n", iface
, image
, flags
, cx
, cy
);
3672 static HRESULT WINAPI
ImageListImpl_SetOriginalSize(IImageList2
*iface
, INT image
, INT cx
, INT cy
)
3674 FIXME("(%p)->(%d %d %d): stub\n", iface
, image
, cx
, cy
);
3678 static HRESULT WINAPI
ImageListImpl_SetCallback(IImageList2
*iface
, IUnknown
*callback
)
3680 FIXME("(%p)->(%p): stub\n", iface
, callback
);
3684 static HRESULT WINAPI
ImageListImpl_GetCallback(IImageList2
*iface
, REFIID riid
, void **ppv
)
3686 FIXME("(%p)->(%s %p): stub\n", iface
, debugstr_guid(riid
), ppv
);
3690 static HRESULT WINAPI
ImageListImpl_ForceImagePresent(IImageList2
*iface
, INT image
, DWORD flags
)
3692 FIXME("(%p)->(%d %x): stub\n", iface
, image
, flags
);
3696 static HRESULT WINAPI
ImageListImpl_DiscardImages(IImageList2
*iface
, INT first_image
, INT last_image
, DWORD flags
)
3698 FIXME("(%p)->(%d %d %x): stub\n", iface
, first_image
, last_image
, flags
);
3702 static HRESULT WINAPI
ImageListImpl_PreloadImages(IImageList2
*iface
, IMAGELISTDRAWPARAMS
*params
)
3704 FIXME("(%p)->(%p): stub\n", iface
, params
);
3708 static HRESULT WINAPI
ImageListImpl_GetStatistics(IImageList2
*iface
, IMAGELISTSTATS
*stats
)
3710 FIXME("(%p)->(%p): stub\n", iface
, stats
);
3714 static HRESULT WINAPI
ImageListImpl_Initialize(IImageList2
*iface
, INT cx
, INT cy
, UINT flags
, INT initial
, INT grow
)
3716 FIXME("(%p)->(%d %d %d %d %d): stub\n", iface
, cx
, cy
, flags
, initial
, grow
);
3720 static HRESULT WINAPI
ImageListImpl_Replace2(IImageList2
*iface
, INT i
, HBITMAP image
, HBITMAP mask
, IUnknown
*unk
, DWORD flags
)
3722 FIXME("(%p)->(%d %p %p %p %x): stub\n", iface
, i
, image
, mask
, unk
, flags
);
3726 static HRESULT WINAPI
ImageListImpl_ReplaceFromImageList(IImageList2
*iface
, INT i
, IImageList
*imagelist
, INT src
,
3727 IUnknown
*unk
, DWORD flags
)
3729 FIXME("(%p)->(%d %p %d %p %x): stub\n", iface
, i
, imagelist
, src
, unk
, flags
);
3733 static const IImageList2Vtbl ImageListImpl_Vtbl
= {
3734 ImageListImpl_QueryInterface
,
3735 ImageListImpl_AddRef
,
3736 ImageListImpl_Release
,
3738 ImageListImpl_ReplaceIcon
,
3739 ImageListImpl_SetOverlayImage
,
3740 ImageListImpl_Replace
,
3741 ImageListImpl_AddMasked
,
3743 ImageListImpl_Remove
,
3744 ImageListImpl_GetIcon
,
3745 ImageListImpl_GetImageInfo
,
3747 ImageListImpl_Merge
,
3748 ImageListImpl_Clone
,
3749 ImageListImpl_GetImageRect
,
3750 ImageListImpl_GetIconSize
,
3751 ImageListImpl_SetIconSize
,
3752 ImageListImpl_GetImageCount
,
3753 ImageListImpl_SetImageCount
,
3754 ImageListImpl_SetBkColor
,
3755 ImageListImpl_GetBkColor
,
3756 ImageListImpl_BeginDrag
,
3757 ImageListImpl_EndDrag
,
3758 ImageListImpl_DragEnter
,
3759 ImageListImpl_DragLeave
,
3760 ImageListImpl_DragMove
,
3761 ImageListImpl_SetDragCursorImage
,
3762 ImageListImpl_DragShowNolock
,
3763 ImageListImpl_GetDragImage
,
3764 ImageListImpl_GetItemFlags
,
3765 ImageListImpl_GetOverlayImage
,
3766 ImageListImpl_Resize
,
3767 ImageListImpl_GetOriginalSize
,
3768 ImageListImpl_SetOriginalSize
,
3769 ImageListImpl_SetCallback
,
3770 ImageListImpl_GetCallback
,
3771 ImageListImpl_ForceImagePresent
,
3772 ImageListImpl_DiscardImages
,
3773 ImageListImpl_PreloadImages
,
3774 ImageListImpl_GetStatistics
,
3775 ImageListImpl_Initialize
,
3776 ImageListImpl_Replace2
,
3777 ImageListImpl_ReplaceFromImageList
3780 static BOOL
is_valid(HIMAGELIST himl
)
3785 valid
= himl
&& himl
->IImageList2_iface
.lpVtbl
== &ImageListImpl_Vtbl
;
3795 /*************************************************************************
3796 * HIMAGELIST_QueryInterface [COMCTL32.@]
3798 * Returns a pointer to an IImageList or IImageList2 object for the given
3802 * himl [I] Image list handle.
3803 * riid [I] Identifier of the requested interface.
3804 * ppv [O] Returns the address of the pointer requested, or NULL.
3808 * Failure: Error value.
3811 HIMAGELIST_QueryInterface (HIMAGELIST himl
, REFIID riid
, void **ppv
)
3813 TRACE("(%p,%s,%p)\n", himl
, debugstr_guid(riid
), ppv
);
3814 return IImageList2_QueryInterface((IImageList2
*) himl
, riid
, ppv
);
3817 static HRESULT
ImageListImpl_CreateInstance(const IUnknown
*pUnkOuter
, REFIID iid
, void** ppv
)
3822 TRACE("(%p,%s,%p)\n", pUnkOuter
, debugstr_guid(iid
), ppv
);
3826 if (pUnkOuter
) return CLASS_E_NOAGGREGATION
;
3828 This
= heap_alloc_zero(sizeof(struct _IMAGELIST
));
3829 if (!This
) return E_OUTOFMEMORY
;
3831 This
->IImageList2_iface
.lpVtbl
= &ImageListImpl_Vtbl
;
3834 ret
= IImageList2_QueryInterface(&This
->IImageList2_iface
, iid
, ppv
);
3835 IImageList2_Release(&This
->IImageList2_iface
);