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 StretchDIBits( himl
->hdcImage
, pt
.x
, pt
.y
, himl
->cx
, himl
->cy
,
238 n
* width
, 0, width
, height
, bits
, info
, DIB_RGB_COLORS
, SRCCOPY
);
240 StretchDIBits( himl
->hdcMask
, pt
.x
, pt
.y
, himl
->cx
, himl
->cy
,
241 n
* width
, 0, width
, height
, mask_bits
, mask_info
, DIB_RGB_COLORS
, SRCCOPY
);
245 /* add images with an alpha channel when the image list is 32 bpp */
246 static BOOL
add_with_alpha( HIMAGELIST himl
, HDC hdc
, int pos
, int count
,
247 int width
, int height
, HBITMAP hbmImage
, HBITMAP hbmMask
)
251 BITMAPINFO
*info
, *mask_info
= NULL
;
253 BYTE
*mask_bits
= NULL
;
256 if (!GetObjectW( hbmImage
, sizeof(bm
), &bm
)) return FALSE
;
258 /* if either the imagelist or the source bitmap don't have an alpha channel, bail out now */
259 if ((himl
->flags
& 0xfe) != ILC_COLOR32
) return FALSE
;
260 if (bm
.bmBitsPixel
!= 32) return FALSE
;
262 SelectObject( hdc
, hbmImage
);
263 mask_width
= (bm
.bmWidth
+ 31) / 32 * 4;
265 if (!(info
= heap_alloc( FIELD_OFFSET( BITMAPINFO
, bmiColors
[256] )))) goto done
;
266 info
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
267 info
->bmiHeader
.biWidth
= bm
.bmWidth
;
268 info
->bmiHeader
.biHeight
= -height
;
269 info
->bmiHeader
.biPlanes
= 1;
270 info
->bmiHeader
.biBitCount
= 32;
271 info
->bmiHeader
.biCompression
= BI_RGB
;
272 info
->bmiHeader
.biSizeImage
= bm
.bmWidth
* height
* 4;
273 info
->bmiHeader
.biXPelsPerMeter
= 0;
274 info
->bmiHeader
.biYPelsPerMeter
= 0;
275 info
->bmiHeader
.biClrUsed
= 0;
276 info
->bmiHeader
.biClrImportant
= 0;
277 if (!(bits
= heap_alloc( info
->bmiHeader
.biSizeImage
))) goto done
;
278 if (!GetDIBits( hdc
, hbmImage
, 0, height
, bits
, info
, DIB_RGB_COLORS
)) goto done
;
282 if (!(mask_info
= heap_alloc( FIELD_OFFSET( BITMAPINFO
, bmiColors
[2] ))))
284 mask_info
->bmiHeader
= info
->bmiHeader
;
285 mask_info
->bmiHeader
.biBitCount
= 1;
286 mask_info
->bmiHeader
.biSizeImage
= mask_width
* height
;
287 if (!(mask_bits
= heap_alloc_zero( mask_info
->bmiHeader
.biSizeImage
)))
289 if (!GetDIBits( hdc
, hbmMask
, 0, height
, mask_bits
, mask_info
, DIB_RGB_COLORS
)) goto done
;
292 add_dib_bits( himl
, pos
, count
, width
, height
, info
, mask_info
, bits
, mask_bits
);
297 heap_free( mask_info
);
299 heap_free( mask_bits
);
304 ImageList_SetColorTable(HIMAGELIST himl
, UINT uStartIndex
, UINT cEntries
, const RGBQUAD
*prgb
);
306 /*************************************************************************
307 * IMAGELIST_InternalExpandBitmaps [Internal]
309 * Expands the bitmaps of an image list by the given number of images.
312 * himl [I] handle to image list
313 * nImageCount [I] number of images to add
319 * This function CANNOT be used to reduce the number of images.
322 IMAGELIST_InternalExpandBitmaps(HIMAGELIST himl
, INT nImageCount
)
325 HBITMAP hbmNewBitmap
, hbmNull
;
329 TRACE("%p has allocated %d, max %d, grow %d images\n", himl
, himl
->cCurImage
, himl
->cMaxImage
, himl
->cGrow
);
331 if (himl
->cCurImage
+ nImageCount
< himl
->cMaxImage
)
334 nNewCount
= himl
->cMaxImage
+ max(nImageCount
, himl
->cGrow
) + 1;
336 imagelist_get_bitmap_size(himl
, nNewCount
, &sz
);
338 TRACE("Create expanded bitmaps : himl=%p x=%d y=%d count=%d\n", himl
, sz
.cx
, sz
.cy
, nNewCount
);
339 hdcBitmap
= CreateCompatibleDC (0);
341 hbmNewBitmap
= ImageList_CreateImage(hdcBitmap
, himl
, nNewCount
);
343 if (hbmNewBitmap
== 0)
344 ERR("creating new image bitmap (x=%d y=%d)!\n", sz
.cx
, sz
.cy
);
348 hbmNull
= SelectObject (hdcBitmap
, hbmNewBitmap
);
349 BitBlt (hdcBitmap
, 0, 0, sz
.cx
, sz
.cy
,
350 himl
->hdcImage
, 0, 0, SRCCOPY
);
351 SelectObject (hdcBitmap
, hbmNull
);
353 SelectObject (himl
->hdcImage
, hbmNewBitmap
);
354 DeleteObject (himl
->hbmImage
);
355 himl
->hbmImage
= hbmNewBitmap
;
357 if (himl
->flags
& ILC_MASK
)
359 hbmNewBitmap
= CreateBitmap (sz
.cx
, sz
.cy
, 1, 1, NULL
);
361 if (hbmNewBitmap
== 0)
362 ERR("creating new mask bitmap!\n");
366 hbmNull
= SelectObject (hdcBitmap
, hbmNewBitmap
);
367 BitBlt (hdcBitmap
, 0, 0, sz
.cx
, sz
.cy
,
368 himl
->hdcMask
, 0, 0, SRCCOPY
);
369 SelectObject (hdcBitmap
, hbmNull
);
371 SelectObject (himl
->hdcMask
, hbmNewBitmap
);
372 DeleteObject (himl
->hbmMask
);
373 himl
->hbmMask
= hbmNewBitmap
;
376 himl
->item_flags
= HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, himl
->item_flags
,
377 nNewCount
* sizeof(*himl
->item_flags
));
378 himl
->cMaxImage
= nNewCount
;
380 DeleteDC (hdcBitmap
);
384 /*************************************************************************
385 * ImageList_Add [COMCTL32.@]
387 * Add an image or images to an image list.
390 * himl [I] handle to image list
391 * hbmImage [I] handle to image bitmap
392 * hbmMask [I] handle to mask bitmap
395 * Success: Index of the first new image.
400 ImageList_Add (HIMAGELIST himl
, HBITMAP hbmImage
, HBITMAP hbmMask
)
402 HDC hdcBitmap
, hdcTemp
= 0;
403 INT nFirstIndex
, nImageCount
, i
;
407 TRACE("himl=%p hbmimage=%p hbmmask=%p\n", himl
, hbmImage
, hbmMask
);
411 if (!GetObjectW(hbmImage
, sizeof(BITMAP
), &bmp
))
414 TRACE("himl %p, cCurImage %d, cMaxImage %d, cGrow %d, cx %d, cy %d\n",
415 himl
, himl
->cCurImage
, himl
->cMaxImage
, himl
->cGrow
, himl
->cx
, himl
->cy
);
417 nImageCount
= bmp
.bmWidth
/ himl
->cx
;
419 TRACE("%p has %d images (%d x %d) bpp %d\n", hbmImage
, nImageCount
, bmp
.bmWidth
, bmp
.bmHeight
,
422 IMAGELIST_InternalExpandBitmaps(himl
, nImageCount
);
424 hdcBitmap
= CreateCompatibleDC(0);
426 SelectObject(hdcBitmap
, hbmImage
);
428 if (add_with_alpha( himl
, hdcBitmap
, himl
->cCurImage
, nImageCount
,
429 himl
->cx
, min( himl
->cy
, bmp
.bmHeight
), hbmImage
, hbmMask
))
434 hdcTemp
= CreateCompatibleDC(0);
435 SelectObject(hdcTemp
, hbmMask
);
438 if (himl
->uBitsPixel
<= 8 && bmp
.bmBitsPixel
<= 8 &&
439 !himl
->color_table_set
&& himl
->cCurImage
== 0)
442 UINT num
= GetDIBColorTable( hdcBitmap
, 0, 1 << bmp
.bmBitsPixel
, colors
);
443 if (num
) ImageList_SetColorTable( himl
, 0, num
, colors
);
446 for (i
=0; i
<nImageCount
; i
++)
448 imagelist_point_from_index( himl
, himl
->cCurImage
+ i
, &pt
);
450 /* Copy result to the imagelist
452 BitBlt( himl
->hdcImage
, pt
.x
, pt
.y
, himl
->cx
, bmp
.bmHeight
,
453 hdcBitmap
, i
*himl
->cx
, 0, SRCCOPY
);
458 BitBlt( himl
->hdcMask
, pt
.x
, pt
.y
, himl
->cx
, bmp
.bmHeight
,
459 hdcTemp
, i
*himl
->cx
, 0, SRCCOPY
);
461 /* Remove the background from the image
463 BitBlt( himl
->hdcImage
, pt
.x
, pt
.y
, himl
->cx
, bmp
.bmHeight
,
464 himl
->hdcMask
, pt
.x
, pt
.y
, 0x220326 ); /* NOTSRCAND */
466 if (hdcTemp
) DeleteDC(hdcTemp
);
471 nFirstIndex
= himl
->cCurImage
;
472 himl
->cCurImage
+= nImageCount
;
478 /*************************************************************************
479 * ImageList_AddIcon [COMCTL32.@]
481 * Adds an icon to an image list.
484 * himl [I] handle to image list
485 * hIcon [I] handle to icon
488 * Success: index of the new image
491 #undef ImageList_AddIcon
492 INT WINAPI
ImageList_AddIcon (HIMAGELIST himl
, HICON hIcon
)
494 return ImageList_ReplaceIcon (himl
, -1, hIcon
);
498 /*************************************************************************
499 * ImageList_AddMasked [COMCTL32.@]
501 * Adds an image or images to an image list and creates a mask from the
502 * specified bitmap using the mask color.
505 * himl [I] handle to image list.
506 * hBitmap [I] handle to bitmap
507 * clrMask [I] mask color.
510 * Success: Index of the first new image.
515 ImageList_AddMasked (HIMAGELIST himl
, HBITMAP hBitmap
, COLORREF clrMask
)
517 HDC hdcMask
, hdcBitmap
;
523 TRACE("himl=%p hbitmap=%p clrmask=%x\n", himl
, hBitmap
, clrMask
);
527 if (!GetObjectW(hBitmap
, sizeof(BITMAP
), &bmp
))
530 hdcBitmap
= CreateCompatibleDC(0);
531 SelectObject(hdcBitmap
, hBitmap
);
533 /* Create a temp Mask so we can remove the background of the Image */
534 hdcMask
= CreateCompatibleDC(0);
535 hMaskBitmap
= CreateBitmap(bmp
.bmWidth
, bmp
.bmHeight
, 1, 1, NULL
);
536 SelectObject(hdcMask
, hMaskBitmap
);
538 /* create monochrome image to the mask bitmap */
539 bkColor
= (clrMask
!= CLR_DEFAULT
) ? clrMask
: GetPixel (hdcBitmap
, 0, 0);
540 SetBkColor (hdcBitmap
, bkColor
);
541 BitBlt (hdcMask
, 0, 0, bmp
.bmWidth
, bmp
.bmHeight
, hdcBitmap
, 0, 0, SRCCOPY
);
544 * Remove the background from the image
546 * WINDOWS BUG ALERT!!!!!!
547 * The statement below should not be done in common practice
548 * but this is how ImageList_AddMasked works in Windows.
549 * It overwrites the original bitmap passed, this was discovered
550 * by using the same bitmap to iterate the different styles
551 * on windows where it failed (BUT ImageList_Add is OK)
552 * This is here in case some apps rely on this bug
554 * Blt mode 0x220326 is NOTSRCAND
556 if (bmp
.bmBitsPixel
> 8) /* NOTSRCAND can't work with palettes */
558 SetBkColor(hdcBitmap
, RGB(255,255,255));
559 BitBlt(hdcBitmap
, 0, 0, bmp
.bmWidth
, bmp
.bmHeight
, hdcMask
, 0, 0, 0x220326);
565 ret
= ImageList_Add( himl
, hBitmap
, hMaskBitmap
);
567 DeleteObject(hMaskBitmap
);
572 /*************************************************************************
573 * ImageList_BeginDrag [COMCTL32.@]
575 * Creates a temporary image list that contains one image. It will be used
579 * himlTrack [I] handle to the source image list
580 * iTrack [I] index of the drag image in the source image list
581 * dxHotspot [I] X position of the hot spot of the drag image
582 * dyHotspot [I] Y position of the hot spot of the drag image
590 ImageList_BeginDrag (HIMAGELIST himlTrack
, INT iTrack
,
591 INT dxHotspot
, INT dyHotspot
)
596 TRACE("(himlTrack=%p iTrack=%d dx=%d dy=%d)\n", himlTrack
, iTrack
,
597 dxHotspot
, dyHotspot
);
599 if (!is_valid(himlTrack
))
602 if (iTrack
>= himlTrack
->cCurImage
)
605 if (InternalDrag
.himl
)
611 InternalDrag
.himlNoCursor
= InternalDrag
.himl
= ImageList_Create (cx
, cy
, himlTrack
->flags
, 1, 1);
612 if (InternalDrag
.himl
== NULL
) {
613 WARN("Error creating drag image list!\n");
617 InternalDrag
.dxHotspot
= dxHotspot
;
618 InternalDrag
.dyHotspot
= dyHotspot
;
621 imagelist_point_from_index(InternalDrag
.himl
, 0, &dst
);
622 imagelist_point_from_index(himlTrack
, iTrack
, &src
);
623 BitBlt(InternalDrag
.himl
->hdcImage
, dst
.x
, dst
.y
, cx
, cy
, himlTrack
->hdcImage
, src
.x
, src
.y
,
625 BitBlt(InternalDrag
.himl
->hdcMask
, dst
.x
, dst
.y
, cx
, cy
, himlTrack
->hdcMask
, src
.x
, src
.y
,
628 InternalDrag
.himl
->cCurImage
= 1;
634 /*************************************************************************
635 * ImageList_Copy [COMCTL32.@]
637 * Copies an image of the source image list to an image of the
638 * destination image list. Images can be copied or swapped.
641 * himlDst [I] handle to the destination image list
642 * iDst [I] destination image index.
643 * himlSrc [I] handle to the source image list
644 * iSrc [I] source image index
645 * uFlags [I] flags for the copy operation
652 * Copying from one image list to another is possible. The original
653 * implementation just copies or swaps within one image list.
654 * Could this feature become a bug??? ;-)
658 ImageList_Copy (HIMAGELIST himlDst
, INT iDst
, HIMAGELIST himlSrc
,
659 INT iSrc
, UINT uFlags
)
663 TRACE("himlDst=%p iDst=%d himlSrc=%p iSrc=%d\n", himlDst
, iDst
, himlSrc
, iSrc
);
665 if (!is_valid(himlSrc
) || !is_valid(himlDst
))
667 if ((iDst
< 0) || (iDst
>= himlDst
->cCurImage
))
669 if ((iSrc
< 0) || (iSrc
>= himlSrc
->cCurImage
))
672 imagelist_point_from_index( himlDst
, iDst
, &ptDst
);
673 imagelist_point_from_index( himlSrc
, iSrc
, &ptSrc
);
675 if (uFlags
& ILCF_SWAP
) {
678 HBITMAP hbmTempImage
, hbmTempMask
;
680 hdcBmp
= CreateCompatibleDC (0);
682 /* create temporary bitmaps */
683 hbmTempImage
= CreateBitmap (himlSrc
->cx
, himlSrc
->cy
, 1,
684 himlSrc
->uBitsPixel
, NULL
);
685 hbmTempMask
= CreateBitmap (himlSrc
->cx
, himlSrc
->cy
, 1,
688 /* copy (and stretch) destination to temporary bitmaps.(save) */
690 SelectObject (hdcBmp
, hbmTempImage
);
691 StretchBlt (hdcBmp
, 0, 0, himlSrc
->cx
, himlSrc
->cy
,
692 himlDst
->hdcImage
, ptDst
.x
, ptDst
.y
, himlDst
->cx
, himlDst
->cy
,
695 SelectObject (hdcBmp
, hbmTempMask
);
696 StretchBlt (hdcBmp
, 0, 0, himlSrc
->cx
, himlSrc
->cy
,
697 himlDst
->hdcMask
, ptDst
.x
, ptDst
.y
, himlDst
->cx
, himlDst
->cy
,
700 /* copy (and stretch) source to destination */
702 StretchBlt (himlDst
->hdcImage
, ptDst
.x
, ptDst
.y
, himlDst
->cx
, himlDst
->cy
,
703 himlSrc
->hdcImage
, ptSrc
.x
, ptSrc
.y
, himlSrc
->cx
, himlSrc
->cy
,
706 StretchBlt (himlDst
->hdcMask
, ptDst
.x
, ptDst
.y
, himlDst
->cx
, himlDst
->cy
,
707 himlSrc
->hdcMask
, ptSrc
.x
, ptSrc
.y
, himlSrc
->cx
, himlSrc
->cy
,
710 /* copy (without stretching) temporary bitmaps to source (restore) */
712 BitBlt (himlSrc
->hdcMask
, ptSrc
.x
, ptSrc
.y
, himlSrc
->cx
, himlSrc
->cy
,
713 hdcBmp
, 0, 0, SRCCOPY
);
716 BitBlt (himlSrc
->hdcImage
, ptSrc
.x
, ptSrc
.y
, himlSrc
->cx
, himlSrc
->cy
,
717 hdcBmp
, 0, 0, SRCCOPY
);
718 /* delete temporary bitmaps */
719 DeleteObject (hbmTempMask
);
720 DeleteObject (hbmTempImage
);
725 StretchBlt (himlDst
->hdcImage
, ptDst
.x
, ptDst
.y
, himlDst
->cx
, himlDst
->cy
,
726 himlSrc
->hdcImage
, ptSrc
.x
, ptSrc
.y
, himlSrc
->cx
, himlSrc
->cy
,
730 StretchBlt (himlDst
->hdcMask
, ptDst
.x
, ptDst
.y
, himlDst
->cx
, himlDst
->cy
,
731 himlSrc
->hdcMask
, ptSrc
.x
, ptSrc
.y
, himlSrc
->cx
, himlSrc
->cy
,
739 /*************************************************************************
740 * ImageList_Create [COMCTL32.@]
742 * Creates a new image list.
745 * cx [I] image height
747 * flags [I] creation flags
748 * cInitial [I] initial number of images in the image list
749 * cGrow [I] number of images by which image list grows
752 * Success: Handle to the created image list
756 ImageList_Create (INT cx
, INT cy
, UINT flags
,
757 INT cInitial
, INT cGrow
)
762 UINT ilc
= (flags
& 0xFE);
763 static const WORD aBitBlend25
[] =
764 {0xAA, 0x00, 0x55, 0x00, 0xAA, 0x00, 0x55, 0x00};
766 static const WORD aBitBlend50
[] =
767 {0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA};
769 TRACE("(%d %d 0x%x %d %d)\n", cx
, cy
, flags
, cInitial
, cGrow
);
771 if (cx
< 0 || cy
< 0) return NULL
;
772 if (!((flags
&ILC_COLORDDB
) == ILC_COLORDDB
) && (cx
== 0 || cy
== 0)) return NULL
;
774 /* Create the IImageList interface for the image list */
775 if (FAILED(ImageListImpl_CreateInstance(NULL
, &IID_IImageList
, (void **)&himl
)))
778 cGrow
= (WORD
)((max( cGrow
, 1 ) + 3) & ~3);
782 /* Windows doesn't limit the size here, but X11 doesn't let us allocate such huge bitmaps */
783 WARN( "grow %d too large, limiting to 256\n", cGrow
);
790 himl
->cMaxImage
= cInitial
+ 1;
791 himl
->cInitial
= cInitial
;
793 himl
->clrFg
= CLR_DEFAULT
;
794 himl
->clrBk
= CLR_NONE
;
795 himl
->color_table_set
= FALSE
;
797 /* initialize overlay mask indices */
798 for (nCount
= 0; nCount
< MAX_OVERLAYIMAGE
; nCount
++)
799 himl
->nOvlIdx
[nCount
] = -1;
801 /* Create Image & Mask DCs */
802 himl
->hdcImage
= CreateCompatibleDC (0);
805 if (himl
->flags
& ILC_MASK
){
806 himl
->hdcMask
= CreateCompatibleDC(0);
811 /* Default to ILC_COLOR4 if none of the ILC_COLOR* flags are specified */
812 if (ilc
== ILC_COLOR
)
815 himl
->flags
|= ILC_COLOR4
;
818 if (ilc
>= ILC_COLOR4
&& ilc
<= ILC_COLOR32
)
819 himl
->uBitsPixel
= ilc
;
821 himl
->uBitsPixel
= (UINT
)GetDeviceCaps (himl
->hdcImage
, BITSPIXEL
);
823 if (himl
->cMaxImage
> 0) {
824 himl
->hbmImage
= ImageList_CreateImage(himl
->hdcImage
, himl
, himl
->cMaxImage
);
825 SelectObject(himl
->hdcImage
, himl
->hbmImage
);
829 if ((himl
->cMaxImage
> 0) && (himl
->flags
& ILC_MASK
)) {
832 imagelist_get_bitmap_size(himl
, himl
->cMaxImage
, &sz
);
833 himl
->hbmMask
= CreateBitmap (sz
.cx
, sz
.cy
, 1, 1, NULL
);
834 if (himl
->hbmMask
== 0) {
835 ERR("Error creating mask bitmap!\n");
838 SelectObject(himl
->hdcMask
, himl
->hbmMask
);
843 himl
->item_flags
= heap_alloc_zero( himl
->cMaxImage
* sizeof(*himl
->item_flags
) );
845 /* create blending brushes */
846 hbmTemp
= CreateBitmap (8, 8, 1, 1, aBitBlend25
);
847 himl
->hbrBlend25
= CreatePatternBrush (hbmTemp
);
848 DeleteObject (hbmTemp
);
850 hbmTemp
= CreateBitmap (8, 8, 1, 1, aBitBlend50
);
851 himl
->hbrBlend50
= CreatePatternBrush (hbmTemp
);
852 DeleteObject (hbmTemp
);
854 TRACE("created imagelist %p\n", himl
);
858 ImageList_Destroy(himl
);
863 /*************************************************************************
864 * ImageList_Destroy [COMCTL32.@]
866 * Destroys an image list.
869 * himl [I] handle to image list
877 ImageList_Destroy (HIMAGELIST himl
)
882 IImageList_Release((IImageList
*) himl
);
887 /*************************************************************************
888 * ImageList_DragEnter [COMCTL32.@]
890 * Locks window update and displays the drag image at the given position.
893 * hwndLock [I] handle of the window that owns the drag image.
894 * x [I] X position of the drag image.
895 * y [I] Y position of the drag image.
902 * The position of the drag image is relative to the window, not
907 ImageList_DragEnter (HWND hwndLock
, INT x
, INT y
)
909 TRACE("(hwnd=%p x=%d y=%d)\n", hwndLock
, x
, y
);
911 if (!is_valid(InternalDrag
.himl
))
915 InternalDrag
.hwnd
= hwndLock
;
917 InternalDrag
.hwnd
= GetDesktopWindow ();
922 /* draw the drag image and save the background */
923 return ImageList_DragShowNolock(TRUE
);
927 /*************************************************************************
928 * ImageList_DragLeave [COMCTL32.@]
930 * Unlocks window update and hides the drag image.
933 * hwndLock [I] handle of the window that owns the drag image.
941 ImageList_DragLeave (HWND hwndLock
)
943 /* As we don't save drag info in the window this can lead to problems if
944 an app does not supply the same window as DragEnter */
946 InternalDrag.hwnd = hwndLock;
948 InternalDrag.hwnd = GetDesktopWindow (); */
950 hwndLock
= GetDesktopWindow();
951 if(InternalDrag
.hwnd
!= hwndLock
)
952 FIXME("DragLeave hWnd != DragEnter hWnd\n");
954 ImageList_DragShowNolock (FALSE
);
960 /*************************************************************************
961 * ImageList_InternalDragDraw [Internal]
963 * Draws the drag image.
966 * hdc [I] device context to draw into.
967 * x [I] X position of the drag image.
968 * y [I] Y position of the drag image.
975 * The position of the drag image is relative to the window, not
981 ImageList_InternalDragDraw (HDC hdc
, INT x
, INT y
)
983 IMAGELISTDRAWPARAMS imldp
;
985 ZeroMemory (&imldp
, sizeof(imldp
));
986 imldp
.cbSize
= sizeof(imldp
);
987 imldp
.himl
= InternalDrag
.himl
;
992 imldp
.rgbBk
= CLR_DEFAULT
;
993 imldp
.rgbFg
= CLR_DEFAULT
;
994 imldp
.fStyle
= ILD_NORMAL
;
995 imldp
.fState
= ILS_ALPHA
;
997 ImageList_DrawIndirect (&imldp
);
1000 /*************************************************************************
1001 * ImageList_DragMove [COMCTL32.@]
1003 * Moves the drag image.
1006 * x [I] X position of the drag image.
1007 * y [I] Y position of the drag image.
1014 * The position of the drag image is relative to the window, not
1019 ImageList_DragMove (INT x
, INT y
)
1021 TRACE("(x=%d y=%d)\n", x
, y
);
1023 if (!is_valid(InternalDrag
.himl
))
1026 /* draw/update the drag image */
1027 if (InternalDrag
.bShow
) {
1031 HBITMAP hbmOffScreen
;
1032 INT origNewX
, origNewY
;
1033 INT origOldX
, origOldY
;
1034 INT origRegX
, origRegY
;
1035 INT sizeRegX
, sizeRegY
;
1038 /* calculate the update region */
1039 origNewX
= x
- InternalDrag
.dxHotspot
;
1040 origNewY
= y
- InternalDrag
.dyHotspot
;
1041 origOldX
= InternalDrag
.x
- InternalDrag
.dxHotspot
;
1042 origOldY
= InternalDrag
.y
- InternalDrag
.dyHotspot
;
1043 origRegX
= min(origNewX
, origOldX
);
1044 origRegY
= min(origNewY
, origOldY
);
1045 sizeRegX
= InternalDrag
.himl
->cx
+ abs(x
- InternalDrag
.x
);
1046 sizeRegY
= InternalDrag
.himl
->cy
+ abs(y
- InternalDrag
.y
);
1048 hdcDrag
= GetDCEx(InternalDrag
.hwnd
, 0,
1049 DCX_WINDOW
| DCX_CACHE
| DCX_LOCKWINDOWUPDATE
);
1050 hdcOffScreen
= CreateCompatibleDC(hdcDrag
);
1051 hdcBg
= CreateCompatibleDC(hdcDrag
);
1053 hbmOffScreen
= CreateCompatibleBitmap(hdcDrag
, sizeRegX
, sizeRegY
);
1054 SelectObject(hdcOffScreen
, hbmOffScreen
);
1055 SelectObject(hdcBg
, InternalDrag
.hbmBg
);
1057 /* get the actual background of the update region */
1058 BitBlt(hdcOffScreen
, 0, 0, sizeRegX
, sizeRegY
, hdcDrag
,
1059 origRegX
, origRegY
, SRCCOPY
);
1060 /* erase the old image */
1061 BitBlt(hdcOffScreen
, origOldX
- origRegX
, origOldY
- origRegY
,
1062 InternalDrag
.himl
->cx
, InternalDrag
.himl
->cy
, hdcBg
, 0, 0,
1064 /* save the background */
1065 BitBlt(hdcBg
, 0, 0, InternalDrag
.himl
->cx
, InternalDrag
.himl
->cy
,
1066 hdcOffScreen
, origNewX
- origRegX
, origNewY
- origRegY
, SRCCOPY
);
1067 /* draw the image */
1068 ImageList_InternalDragDraw(hdcOffScreen
, origNewX
- origRegX
,
1069 origNewY
- origRegY
);
1070 /* draw the update region to the screen */
1071 BitBlt(hdcDrag
, origRegX
, origRegY
, sizeRegX
, sizeRegY
,
1072 hdcOffScreen
, 0, 0, SRCCOPY
);
1075 DeleteDC(hdcOffScreen
);
1076 DeleteObject(hbmOffScreen
);
1077 ReleaseDC(InternalDrag
.hwnd
, hdcDrag
);
1080 /* update the image position */
1088 /*************************************************************************
1089 * ImageList_DragShowNolock [COMCTL32.@]
1091 * Shows or hides the drag image.
1094 * bShow [I] TRUE shows the drag image, FALSE hides it.
1102 ImageList_DragShowNolock (BOOL bShow
)
1108 if (!is_valid(InternalDrag
.himl
))
1111 TRACE("bShow=0x%X!\n", bShow
);
1113 /* DragImage is already visible/hidden */
1114 if ((InternalDrag
.bShow
&& bShow
) || (!InternalDrag
.bShow
&& !bShow
)) {
1118 /* position of the origin of the DragImage */
1119 x
= InternalDrag
.x
- InternalDrag
.dxHotspot
;
1120 y
= InternalDrag
.y
- InternalDrag
.dyHotspot
;
1122 hdcDrag
= GetDCEx (InternalDrag
.hwnd
, 0,
1123 DCX_WINDOW
| DCX_CACHE
| DCX_LOCKWINDOWUPDATE
);
1128 hdcBg
= CreateCompatibleDC(hdcDrag
);
1129 if (!InternalDrag
.hbmBg
) {
1130 InternalDrag
.hbmBg
= CreateCompatibleBitmap(hdcDrag
,
1131 InternalDrag
.himl
->cx
, InternalDrag
.himl
->cy
);
1133 SelectObject(hdcBg
, InternalDrag
.hbmBg
);
1136 /* save the background */
1137 BitBlt(hdcBg
, 0, 0, InternalDrag
.himl
->cx
, InternalDrag
.himl
->cy
,
1138 hdcDrag
, x
, y
, SRCCOPY
);
1139 /* show the image */
1140 ImageList_InternalDragDraw(hdcDrag
, x
, y
);
1142 /* hide the image */
1143 BitBlt(hdcDrag
, x
, y
, InternalDrag
.himl
->cx
, InternalDrag
.himl
->cy
,
1144 hdcBg
, 0, 0, SRCCOPY
);
1147 InternalDrag
.bShow
= !InternalDrag
.bShow
;
1150 ReleaseDC (InternalDrag
.hwnd
, hdcDrag
);
1155 /*************************************************************************
1156 * ImageList_Draw [COMCTL32.@]
1161 * himl [I] handle to image list
1163 * hdc [I] handle to device context
1166 * fStyle [I] drawing flags
1177 ImageList_Draw (HIMAGELIST himl
, INT i
, HDC hdc
, INT x
, INT y
, UINT fStyle
)
1179 return ImageList_DrawEx (himl
, i
, hdc
, x
, y
, 0, 0,
1180 CLR_DEFAULT
, CLR_DEFAULT
, fStyle
);
1184 /*************************************************************************
1185 * ImageList_DrawEx [COMCTL32.@]
1187 * Draws an image and allows using extended drawing features.
1190 * himl [I] handle to image list
1192 * hdc [I] handle to device context
1197 * rgbBk [I] background color
1198 * rgbFg [I] foreground color
1199 * fStyle [I] drawing flags
1206 * Calls ImageList_DrawIndirect.
1209 * ImageList_DrawIndirect.
1213 ImageList_DrawEx (HIMAGELIST himl
, INT i
, HDC hdc
, INT x
, INT y
,
1214 INT dx
, INT dy
, COLORREF rgbBk
, COLORREF rgbFg
,
1217 IMAGELISTDRAWPARAMS imldp
;
1219 ZeroMemory (&imldp
, sizeof(imldp
));
1220 imldp
.cbSize
= sizeof(imldp
);
1228 imldp
.rgbBk
= rgbBk
;
1229 imldp
.rgbFg
= rgbFg
;
1230 imldp
.fStyle
= fStyle
;
1232 return ImageList_DrawIndirect (&imldp
);
1236 static BOOL
alpha_blend_image( HIMAGELIST himl
, HDC dest_dc
, int dest_x
, int dest_y
,
1237 int src_x
, int src_y
, int cx
, int cy
, UINT style
, UINT state
,
1238 DWORD frame
, COLORREF blend_col
, BOOL has_alpha
)
1242 HBITMAP bmp
= 0, mask
= 0;
1245 void *bits
, *mask_bits
;
1249 func
.BlendOp
= AC_SRC_OVER
;
1250 func
.BlendFlags
= 0;
1251 func
.SourceConstantAlpha
= 255;
1252 func
.AlphaFormat
= AC_SRC_ALPHA
;
1254 if (!(hdc
= CreateCompatibleDC( 0 ))) return FALSE
;
1255 if (!(info
= heap_alloc( FIELD_OFFSET( BITMAPINFO
, bmiColors
[256] )))) goto done
;
1256 info
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
1257 info
->bmiHeader
.biWidth
= cx
;
1258 info
->bmiHeader
.biHeight
= cy
;
1259 info
->bmiHeader
.biPlanes
= 1;
1260 info
->bmiHeader
.biBitCount
= 32;
1261 info
->bmiHeader
.biCompression
= BI_RGB
;
1262 info
->bmiHeader
.biSizeImage
= cx
* cy
* 4;
1263 info
->bmiHeader
.biXPelsPerMeter
= 0;
1264 info
->bmiHeader
.biYPelsPerMeter
= 0;
1265 info
->bmiHeader
.biClrUsed
= 0;
1266 info
->bmiHeader
.biClrImportant
= 0;
1267 if (!(bmp
= CreateDIBSection( himl
->hdcImage
, info
, DIB_RGB_COLORS
, &bits
, 0, 0 ))) goto done
;
1268 SelectObject( hdc
, bmp
);
1269 BitBlt( hdc
, 0, 0, cx
, cy
, himl
->hdcImage
, src_x
, src_y
, SRCCOPY
);
1271 if (blend_col
!= CLR_NONE
)
1273 BYTE r
= GetRValue( blend_col
);
1274 BYTE g
= GetGValue( blend_col
);
1275 BYTE b
= GetBValue( blend_col
);
1277 if (style
& ILD_BLEND25
)
1279 for (i
= 0, ptr
= bits
; i
< cx
* cy
; i
++, ptr
++)
1280 *ptr
= ((*ptr
& 0xff000000) |
1281 ((((*ptr
& 0x00ff0000) * 3 + (r
<< 16)) / 4) & 0x00ff0000) |
1282 ((((*ptr
& 0x0000ff00) * 3 + (g
<< 8)) / 4) & 0x0000ff00) |
1283 ((((*ptr
& 0x000000ff) * 3 + (b
<< 0)) / 4) & 0x000000ff));
1285 else if (style
& ILD_BLEND50
)
1287 for (i
= 0, ptr
= bits
; i
< cx
* cy
; i
++, ptr
++)
1288 *ptr
= ((*ptr
& 0xff000000) |
1289 ((((*ptr
& 0x00ff0000) + (r
<< 16)) / 2) & 0x00ff0000) |
1290 ((((*ptr
& 0x0000ff00) + (g
<< 8)) / 2) & 0x0000ff00) |
1291 ((((*ptr
& 0x000000ff) + (b
<< 0)) / 2) & 0x000000ff));
1296 if (state
& ILS_ALPHA
)
1298 func
.SourceConstantAlpha
= (BYTE
)frame
;
1300 else if (state
& ILS_SATURATE
)
1302 for (i
= 0, ptr
= bits
; i
< cx
* cy
; i
++, ptr
++)
1304 DWORD gray
= (((*ptr
& 0x00ff0000) >> 16) * 299 +
1305 ((*ptr
& 0x0000ff00) >> 8) * 587 +
1306 ((*ptr
& 0x000000ff) >> 0) * 114 + 500) / 1000;
1307 if (has_alpha
) gray
= gray
* (*ptr
>> 24) / 255;
1308 *ptr
= (*ptr
& 0xff000000)| (gray
<< 16) | (gray
<< 8) | gray
;
1311 else if (style
& ILD_PRESERVEALPHA
)
1313 HBRUSH old_brush
= SelectObject( dest_dc
, GetStockObject(BLACK_BRUSH
) );
1314 PatBlt( dest_dc
, dest_x
, dest_y
, cx
, cy
, PATCOPY
);
1315 SelectObject( dest_dc
, old_brush
);
1318 if (has_alpha
) /* we already have an alpha channel in this case */
1320 /* pre-multiply by the alpha channel */
1321 for (i
= 0, ptr
= bits
; i
< cx
* cy
; i
++, ptr
++)
1323 DWORD alpha
= *ptr
>> 24;
1324 *ptr
= ((*ptr
& 0xff000000) |
1325 (((*ptr
& 0x00ff0000) * alpha
/ 255) & 0x00ff0000) |
1326 (((*ptr
& 0x0000ff00) * alpha
/ 255) & 0x0000ff00) |
1327 (((*ptr
& 0x000000ff) * alpha
/ 255)));
1330 else if (himl
->hbmMask
)
1332 unsigned int width_bytes
= (cx
+ 31) / 32 * 4;
1333 /* generate alpha channel from the mask */
1334 info
->bmiHeader
.biBitCount
= 1;
1335 info
->bmiHeader
.biSizeImage
= width_bytes
* cy
;
1336 info
->bmiColors
[0].rgbRed
= 0;
1337 info
->bmiColors
[0].rgbGreen
= 0;
1338 info
->bmiColors
[0].rgbBlue
= 0;
1339 info
->bmiColors
[0].rgbReserved
= 0;
1340 info
->bmiColors
[1].rgbRed
= 0xff;
1341 info
->bmiColors
[1].rgbGreen
= 0xff;
1342 info
->bmiColors
[1].rgbBlue
= 0xff;
1343 info
->bmiColors
[1].rgbReserved
= 0;
1344 if (!(mask
= CreateDIBSection( himl
->hdcMask
, info
, DIB_RGB_COLORS
, &mask_bits
, 0, 0 )))
1346 SelectObject( hdc
, mask
);
1347 BitBlt( hdc
, 0, 0, cx
, cy
, himl
->hdcMask
, src_x
, src_y
, SRCCOPY
);
1348 SelectObject( hdc
, bmp
);
1349 for (i
= 0, ptr
= bits
; i
< cy
; i
++)
1350 for (j
= 0; j
< cx
; j
++, ptr
++)
1351 if ((((BYTE
*)mask_bits
)[i
* width_bytes
+ j
/ 8] << (j
% 8)) & 0x80) *ptr
= 0;
1352 else *ptr
|= 0xff000000;
1356 for (i
= 0, ptr
= bits
; i
< cx
* cy
; i
++, ptr
++)
1360 ret
= GdiAlphaBlend( dest_dc
, dest_x
, dest_y
, cx
, cy
, hdc
, 0, 0, cx
, cy
, func
);
1364 if (bmp
) DeleteObject( bmp
);
1365 if (mask
) DeleteObject( mask
);
1370 /*************************************************************************
1371 * ImageList_DrawIndirect [COMCTL32.@]
1373 * Draws an image using various parameters specified in pimldp.
1376 * pimldp [I] pointer to IMAGELISTDRAWPARAMS structure.
1384 ImageList_DrawIndirect (IMAGELISTDRAWPARAMS
*pimldp
)
1386 INT cx
, cy
, nOvlIdx
;
1387 DWORD fState
, dwRop
;
1389 COLORREF oldImageBk
, oldImageFg
;
1390 HDC hImageDC
, hImageListDC
, hMaskListDC
;
1391 HBITMAP hImageBmp
, hOldImageBmp
, hBlendMaskBmp
;
1392 BOOL bIsTransparent
, bBlend
, bResult
= FALSE
, bMask
;
1398 if (!pimldp
|| !(himl
= pimldp
->himl
)) return FALSE
;
1399 if (!is_valid(himl
)) return FALSE
;
1400 if ((pimldp
->i
< 0) || (pimldp
->i
>= himl
->cCurImage
)) return FALSE
;
1402 imagelist_point_from_index( himl
, pimldp
->i
, &pt
);
1403 pt
.x
+= pimldp
->xBitmap
;
1404 pt
.y
+= pimldp
->yBitmap
;
1406 fState
= pimldp
->cbSize
< sizeof(IMAGELISTDRAWPARAMS
) ? ILS_NORMAL
: pimldp
->fState
;
1407 fStyle
= pimldp
->fStyle
& ~ILD_OVERLAYMASK
;
1408 cx
= (pimldp
->cx
== 0) ? himl
->cx
: pimldp
->cx
;
1409 cy
= (pimldp
->cy
== 0) ? himl
->cy
: pimldp
->cy
;
1411 bIsTransparent
= (fStyle
& ILD_TRANSPARENT
);
1412 if( pimldp
->rgbBk
== CLR_NONE
)
1413 bIsTransparent
= TRUE
;
1414 if( ( pimldp
->rgbBk
== CLR_DEFAULT
) && ( himl
->clrBk
== CLR_NONE
) )
1415 bIsTransparent
= TRUE
;
1416 bMask
= (himl
->flags
& ILC_MASK
) && (fStyle
& ILD_MASK
) ;
1417 bBlend
= (fStyle
& (ILD_BLEND25
| ILD_BLEND50
) ) && !bMask
;
1419 TRACE("himl(%p) hbmMask(%p) iImage(%d) x(%d) y(%d) cx(%d) cy(%d)\n",
1420 himl
, himl
->hbmMask
, pimldp
->i
, pimldp
->x
, pimldp
->y
, cx
, cy
);
1422 /* we will use these DCs to access the images and masks in the ImageList */
1423 hImageListDC
= himl
->hdcImage
;
1424 hMaskListDC
= himl
->hdcMask
;
1426 /* these will accumulate the image and mask for the image we're drawing */
1427 hImageDC
= CreateCompatibleDC( pimldp
->hdcDst
);
1428 hImageBmp
= CreateCompatibleBitmap( pimldp
->hdcDst
, cx
, cy
);
1429 hBlendMaskBmp
= bBlend
? CreateBitmap(cx
, cy
, 1, 1, NULL
) : 0;
1431 /* Create a compatible DC. */
1432 if (!hImageListDC
|| !hImageDC
|| !hImageBmp
||
1433 (bBlend
&& !hBlendMaskBmp
) || (himl
->hbmMask
&& !hMaskListDC
))
1436 hOldImageBmp
= SelectObject(hImageDC
, hImageBmp
);
1439 * To obtain a transparent look, background color should be set
1440 * to white and foreground color to black when blitting the
1443 oldImageFg
= SetTextColor( hImageDC
, RGB( 0, 0, 0 ) );
1444 oldImageBk
= SetBkColor( hImageDC
, RGB( 0xff, 0xff, 0xff ) );
1446 has_alpha
= himl
->item_flags
[pimldp
->i
] & ILIF_ALPHA
;
1447 if (!bMask
&& (has_alpha
|| (fState
& ILS_ALPHA
) || (fState
& ILS_SATURATE
)))
1449 COLORREF colour
, blend_col
= CLR_NONE
;
1453 blend_col
= pimldp
->rgbFg
;
1454 if (blend_col
== CLR_DEFAULT
) blend_col
= GetSysColor( COLOR_HIGHLIGHT
);
1455 else if (blend_col
== CLR_NONE
) blend_col
= GetTextColor( pimldp
->hdcDst
);
1460 bResult
= alpha_blend_image( himl
, pimldp
->hdcDst
, pimldp
->x
, pimldp
->y
, pt
.x
, pt
.y
, cx
, cy
,
1461 fStyle
, fState
, pimldp
->Frame
, blend_col
, has_alpha
);
1464 colour
= pimldp
->rgbBk
;
1465 if (colour
== CLR_DEFAULT
) colour
= himl
->clrBk
;
1466 if (colour
== CLR_NONE
) colour
= GetBkColor( pimldp
->hdcDst
);
1468 hOldBrush
= SelectObject (hImageDC
, CreateSolidBrush (colour
));
1469 PatBlt( hImageDC
, 0, 0, cx
, cy
, PATCOPY
);
1470 alpha_blend_image( himl
, hImageDC
, 0, 0, pt
.x
, pt
.y
, cx
, cy
, fStyle
, fState
,
1471 pimldp
->Frame
, blend_col
, has_alpha
);
1472 DeleteObject (SelectObject (hImageDC
, hOldBrush
));
1473 bResult
= BitBlt( pimldp
->hdcDst
, pimldp
->x
, pimldp
->y
, cx
, cy
, hImageDC
, 0, 0, SRCCOPY
);
1478 * Draw the initial image
1481 if (himl
->hbmMask
) {
1482 hOldBrush
= SelectObject (hImageDC
, CreateSolidBrush (GetTextColor(pimldp
->hdcDst
)));
1483 PatBlt( hImageDC
, 0, 0, cx
, cy
, PATCOPY
);
1484 BitBlt(hImageDC
, 0, 0, cx
, cy
, hMaskListDC
, pt
.x
, pt
.y
, SRCPAINT
);
1485 DeleteObject (SelectObject (hImageDC
, hOldBrush
));
1486 if( bIsTransparent
)
1488 BitBlt ( pimldp
->hdcDst
, pimldp
->x
, pimldp
->y
, cx
, cy
, hImageDC
, 0, 0, SRCAND
);
1493 hOldBrush
= SelectObject (hImageDC
, GetStockObject(BLACK_BRUSH
));
1494 PatBlt( hImageDC
, 0, 0, cx
, cy
, PATCOPY
);
1495 SelectObject(hImageDC
, hOldBrush
);
1498 /* blend the image with the needed solid background */
1499 COLORREF colour
= RGB(0,0,0);
1501 if( !bIsTransparent
)
1503 colour
= pimldp
->rgbBk
;
1504 if( colour
== CLR_DEFAULT
)
1505 colour
= himl
->clrBk
;
1506 if( colour
== CLR_NONE
)
1507 colour
= GetBkColor(pimldp
->hdcDst
);
1510 hOldBrush
= SelectObject (hImageDC
, CreateSolidBrush (colour
));
1511 PatBlt( hImageDC
, 0, 0, cx
, cy
, PATCOPY
);
1514 BitBlt( hImageDC
, 0, 0, cx
, cy
, hMaskListDC
, pt
.x
, pt
.y
, SRCAND
);
1515 BitBlt( hImageDC
, 0, 0, cx
, cy
, hImageListDC
, pt
.x
, pt
.y
, SRCPAINT
);
1518 BitBlt( hImageDC
, 0, 0, cx
, cy
, hImageListDC
, pt
.x
, pt
.y
, SRCCOPY
);
1519 DeleteObject (SelectObject (hImageDC
, hOldBrush
));
1522 /* Time for blending, if required */
1525 COLORREF clrBlend
= pimldp
->rgbFg
;
1526 HDC hBlendMaskDC
= hImageListDC
;
1529 /* Create the blend Mask */
1530 hOldBitmap
= SelectObject(hBlendMaskDC
, hBlendMaskBmp
);
1531 hBlendBrush
= fStyle
& ILD_BLEND50
? himl
->hbrBlend50
: himl
->hbrBlend25
;
1532 hOldBrush
= SelectObject(hBlendMaskDC
, hBlendBrush
);
1533 PatBlt(hBlendMaskDC
, 0, 0, cx
, cy
, PATCOPY
);
1534 SelectObject(hBlendMaskDC
, hOldBrush
);
1536 /* Modify the blend mask if an Image Mask exist */
1538 BitBlt(hBlendMaskDC
, 0, 0, cx
, cy
, hMaskListDC
, pt
.x
, pt
.y
, 0x220326); /* NOTSRCAND */
1539 BitBlt(hBlendMaskDC
, 0, 0, cx
, cy
, hBlendMaskDC
, 0, 0, NOTSRCCOPY
);
1542 /* now apply blend to the current image given the BlendMask */
1543 if (clrBlend
== CLR_DEFAULT
) clrBlend
= GetSysColor (COLOR_HIGHLIGHT
);
1544 else if (clrBlend
== CLR_NONE
) clrBlend
= GetTextColor (pimldp
->hdcDst
);
1545 hOldBrush
= SelectObject (hImageDC
, CreateSolidBrush(clrBlend
));
1546 BitBlt (hImageDC
, 0, 0, cx
, cy
, hBlendMaskDC
, 0, 0, 0xB8074A); /* PSDPxax */
1547 DeleteObject(SelectObject(hImageDC
, hOldBrush
));
1548 SelectObject(hBlendMaskDC
, hOldBitmap
);
1551 /* Now do the overlay image, if any */
1552 nOvlIdx
= (pimldp
->fStyle
& ILD_OVERLAYMASK
) >> 8;
1553 if ( (nOvlIdx
>= 1) && (nOvlIdx
<= MAX_OVERLAYIMAGE
)) {
1554 nOvlIdx
= himl
->nOvlIdx
[nOvlIdx
- 1];
1555 if ((nOvlIdx
>= 0) && (nOvlIdx
< himl
->cCurImage
)) {
1557 imagelist_point_from_index( himl
, nOvlIdx
, &ptOvl
);
1558 ptOvl
.x
+= pimldp
->xBitmap
;
1559 if (himl
->hbmMask
&& !(fStyle
& ILD_IMAGE
))
1560 BitBlt (hImageDC
, 0, 0, cx
, cy
, hMaskListDC
, ptOvl
.x
, ptOvl
.y
, SRCAND
);
1561 BitBlt (hImageDC
, 0, 0, cx
, cy
, hImageListDC
, ptOvl
.x
, ptOvl
.y
, SRCPAINT
);
1565 if (fState
& ILS_GLOW
) FIXME("ILS_GLOW: unimplemented!\n");
1566 if (fState
& ILS_SHADOW
) FIXME("ILS_SHADOW: unimplemented!\n");
1568 if (fStyle
& ILD_SCALE
) FIXME("ILD_SCALE: unimplemented!\n");
1569 if (fStyle
& ILD_DPISCALE
) FIXME("ILD_DPISCALE: unimplemented!\n");
1571 /* now copy the image to the screen */
1573 if (himl
->hbmMask
&& bIsTransparent
) {
1574 COLORREF oldDstFg
= SetTextColor(pimldp
->hdcDst
, RGB( 0, 0, 0 ) );
1575 COLORREF oldDstBk
= SetBkColor(pimldp
->hdcDst
, RGB( 0xff, 0xff, 0xff ));
1576 BitBlt (pimldp
->hdcDst
, pimldp
->x
, pimldp
->y
, cx
, cy
, hMaskListDC
, pt
.x
, pt
.y
, SRCAND
);
1577 SetBkColor(pimldp
->hdcDst
, oldDstBk
);
1578 SetTextColor(pimldp
->hdcDst
, oldDstFg
);
1581 if (fStyle
& ILD_ROP
) dwRop
= pimldp
->dwRop
;
1582 BitBlt (pimldp
->hdcDst
, pimldp
->x
, pimldp
->y
, cx
, cy
, hImageDC
, 0, 0, dwRop
);
1586 /* cleanup the mess */
1587 SetBkColor(hImageDC
, oldImageBk
);
1588 SetTextColor(hImageDC
, oldImageFg
);
1589 SelectObject(hImageDC
, hOldImageBmp
);
1591 DeleteObject(hBlendMaskBmp
);
1592 DeleteObject(hImageBmp
);
1599 /*************************************************************************
1600 * ImageList_Duplicate [COMCTL32.@]
1602 * Duplicates an image list.
1605 * himlSrc [I] source image list handle
1608 * Success: Handle of duplicated image list.
1613 ImageList_Duplicate (HIMAGELIST himlSrc
)
1617 if (!is_valid(himlSrc
)) {
1618 ERR("Invalid image list handle!\n");
1622 himlDst
= ImageList_Create (himlSrc
->cx
, himlSrc
->cy
, himlSrc
->flags
,
1623 himlSrc
->cCurImage
, himlSrc
->cGrow
);
1629 imagelist_get_bitmap_size(himlSrc
, himlSrc
->cCurImage
, &sz
);
1630 BitBlt (himlDst
->hdcImage
, 0, 0, sz
.cx
, sz
.cy
,
1631 himlSrc
->hdcImage
, 0, 0, SRCCOPY
);
1633 if (himlDst
->hbmMask
)
1634 BitBlt (himlDst
->hdcMask
, 0, 0, sz
.cx
, sz
.cy
,
1635 himlSrc
->hdcMask
, 0, 0, SRCCOPY
);
1637 himlDst
->cCurImage
= himlSrc
->cCurImage
;
1638 memcpy( himlDst
->item_flags
, himlSrc
->item_flags
, himlDst
->cCurImage
* sizeof(*himlDst
->item_flags
) );
1644 /*************************************************************************
1645 * ImageList_EndDrag [COMCTL32.@]
1647 * Finishes a drag operation.
1658 ImageList_EndDrag (void)
1660 /* cleanup the InternalDrag struct */
1661 InternalDrag
.hwnd
= 0;
1662 if (InternalDrag
.himl
!= InternalDrag
.himlNoCursor
)
1663 ImageList_Destroy (InternalDrag
.himlNoCursor
);
1664 ImageList_Destroy (InternalDrag
.himl
);
1665 InternalDrag
.himlNoCursor
= InternalDrag
.himl
= 0;
1668 InternalDrag
.dxHotspot
= 0;
1669 InternalDrag
.dyHotspot
= 0;
1670 InternalDrag
.bShow
= FALSE
;
1671 DeleteObject(InternalDrag
.hbmBg
);
1672 InternalDrag
.hbmBg
= 0;
1676 /*************************************************************************
1677 * ImageList_GetBkColor [COMCTL32.@]
1679 * Returns the background color of an image list.
1682 * himl [I] Image list handle.
1685 * Success: background color
1690 ImageList_GetBkColor (HIMAGELIST himl
)
1692 return himl
? himl
->clrBk
: CLR_NONE
;
1696 /*************************************************************************
1697 * ImageList_GetDragImage [COMCTL32.@]
1699 * Returns the handle to the internal drag image list.
1702 * ppt [O] Pointer to the drag position. Can be NULL.
1703 * pptHotspot [O] Pointer to the position of the hot spot. Can be NULL.
1706 * Success: Handle of the drag image list.
1711 ImageList_GetDragImage (POINT
*ppt
, POINT
*pptHotspot
)
1713 if (is_valid(InternalDrag
.himl
)) {
1715 ppt
->x
= InternalDrag
.x
;
1716 ppt
->y
= InternalDrag
.y
;
1719 pptHotspot
->x
= InternalDrag
.dxHotspot
;
1720 pptHotspot
->y
= InternalDrag
.dyHotspot
;
1722 return (InternalDrag
.himl
);
1729 /*************************************************************************
1730 * ImageList_GetFlags [COMCTL32.@]
1732 * Gets the flags of the specified image list.
1735 * himl [I] Handle to image list
1745 ImageList_GetFlags(HIMAGELIST himl
)
1747 TRACE("%p\n", himl
);
1749 return is_valid(himl
) ? himl
->flags
: 0;
1753 /*************************************************************************
1754 * ImageList_GetIcon [COMCTL32.@]
1756 * Creates an icon from a masked image of an image list.
1759 * himl [I] handle to image list
1761 * flags [I] drawing style flags
1764 * Success: icon handle
1769 ImageList_GetIcon (HIMAGELIST himl
, INT i
, UINT fStyle
)
1773 HBITMAP hOldDstBitmap
;
1777 TRACE("%p %d %d\n", himl
, i
, fStyle
);
1778 if (!is_valid(himl
) || (i
< 0) || (i
>= himl
->cCurImage
)) return NULL
;
1784 /* create colour bitmap */
1786 ii
.hbmColor
= CreateCompatibleBitmap(hdcDst
, himl
->cx
, himl
->cy
);
1787 ReleaseDC(0, hdcDst
);
1789 hdcDst
= CreateCompatibleDC(0);
1791 imagelist_point_from_index( himl
, i
, &pt
);
1794 ii
.hbmMask
= CreateBitmap (himl
->cx
, himl
->cy
, 1, 1, NULL
);
1795 hOldDstBitmap
= SelectObject (hdcDst
, ii
.hbmMask
);
1796 if (himl
->hbmMask
) {
1797 BitBlt (hdcDst
, 0, 0, himl
->cx
, himl
->cy
,
1798 himl
->hdcMask
, pt
.x
, pt
.y
, SRCCOPY
);
1801 PatBlt (hdcDst
, 0, 0, himl
->cx
, himl
->cy
, BLACKNESS
);
1804 SelectObject (hdcDst
, ii
.hbmColor
);
1805 BitBlt (hdcDst
, 0, 0, himl
->cx
, himl
->cy
,
1806 himl
->hdcImage
, pt
.x
, pt
.y
, SRCCOPY
);
1809 * CreateIconIndirect requires us to deselect the bitmaps from
1810 * the DCs before calling
1812 SelectObject(hdcDst
, hOldDstBitmap
);
1814 hIcon
= CreateIconIndirect (&ii
);
1816 DeleteObject (ii
.hbmMask
);
1817 DeleteObject (ii
.hbmColor
);
1824 /*************************************************************************
1825 * ImageList_GetIconSize [COMCTL32.@]
1827 * Retrieves the size of an image in an image list.
1830 * himl [I] handle to image list
1831 * cx [O] pointer to the image width.
1832 * cy [O] pointer to the image height.
1839 * All images in an image list have the same size.
1843 ImageList_GetIconSize (HIMAGELIST himl
, INT
*cx
, INT
*cy
)
1845 if (!is_valid(himl
) || !cx
|| !cy
)
1855 /*************************************************************************
1856 * ImageList_GetImageCount [COMCTL32.@]
1858 * Returns the number of images in an image list.
1861 * himl [I] handle to image list
1864 * Success: Number of images.
1869 ImageList_GetImageCount (HIMAGELIST himl
)
1871 if (!is_valid(himl
))
1874 return himl
->cCurImage
;
1878 /*************************************************************************
1879 * ImageList_GetImageInfo [COMCTL32.@]
1881 * Returns information about an image in an image list.
1884 * himl [I] handle to image list
1886 * pImageInfo [O] pointer to the image information
1894 ImageList_GetImageInfo (HIMAGELIST himl
, INT i
, IMAGEINFO
*pImageInfo
)
1898 if (!is_valid(himl
) || (pImageInfo
== NULL
))
1900 if ((i
< 0) || (i
>= himl
->cCurImage
))
1903 pImageInfo
->hbmImage
= himl
->hbmImage
;
1904 pImageInfo
->hbmMask
= himl
->hbmMask
;
1906 imagelist_point_from_index( himl
, i
, &pt
);
1907 pImageInfo
->rcImage
.top
= pt
.y
;
1908 pImageInfo
->rcImage
.bottom
= pt
.y
+ himl
->cy
;
1909 pImageInfo
->rcImage
.left
= pt
.x
;
1910 pImageInfo
->rcImage
.right
= pt
.x
+ himl
->cx
;
1916 /*************************************************************************
1917 * ImageList_GetImageRect [COMCTL32.@]
1919 * Retrieves the rectangle of the specified image in an image list.
1922 * himl [I] handle to image list
1924 * lpRect [O] pointer to the image rectangle
1931 * This is an UNDOCUMENTED function!!!
1935 ImageList_GetImageRect (HIMAGELIST himl
, INT i
, LPRECT lpRect
)
1939 if (!is_valid(himl
) || (lpRect
== NULL
))
1941 if ((i
< 0) || (i
>= himl
->cCurImage
))
1944 imagelist_point_from_index( himl
, i
, &pt
);
1945 lpRect
->left
= pt
.x
;
1947 lpRect
->right
= pt
.x
+ himl
->cx
;
1948 lpRect
->bottom
= pt
.y
+ himl
->cy
;
1954 /*************************************************************************
1955 * ImageList_LoadImage [COMCTL32.@]
1956 * ImageList_LoadImageA [COMCTL32.@]
1958 * Creates an image list from a bitmap, icon or cursor.
1960 * See ImageList_LoadImageW.
1964 ImageList_LoadImageA (HINSTANCE hi
, LPCSTR lpbmp
, INT cx
, INT cGrow
,
1965 COLORREF clrMask
, UINT uType
, UINT uFlags
)
1971 if (IS_INTRESOURCE(lpbmp
))
1972 return ImageList_LoadImageW(hi
, (LPCWSTR
)lpbmp
, cx
, cGrow
, clrMask
,
1975 len
= MultiByteToWideChar(CP_ACP
, 0, lpbmp
, -1, NULL
, 0);
1976 lpbmpW
= heap_alloc(len
* sizeof(WCHAR
));
1977 MultiByteToWideChar(CP_ACP
, 0, lpbmp
, -1, lpbmpW
, len
);
1979 himl
= ImageList_LoadImageW(hi
, lpbmpW
, cx
, cGrow
, clrMask
, uType
, uFlags
);
1985 /*************************************************************************
1986 * ImageList_LoadImageW [COMCTL32.@]
1988 * Creates an image list from a bitmap, icon or cursor.
1991 * hi [I] instance handle
1992 * lpbmp [I] name or id of the image
1993 * cx [I] width of each image
1994 * cGrow [I] number of images to expand
1995 * clrMask [I] mask color
1996 * uType [I] type of image to load
1997 * uFlags [I] loading flags
2000 * Success: handle to the loaded image list
2008 ImageList_LoadImageW (HINSTANCE hi
, LPCWSTR lpbmp
, INT cx
, INT cGrow
,
2009 COLORREF clrMask
, UINT uType
, UINT uFlags
)
2011 HIMAGELIST himl
= NULL
;
2015 handle
= LoadImageW (hi
, lpbmp
, uType
, 0, 0, uFlags
);
2017 WARN("Couldn't load image\n");
2021 if (uType
== IMAGE_BITMAP
) {
2025 if (GetObjectW (handle
, sizeof(dib
), &dib
) == sizeof(BITMAP
)) color
= ILC_COLOR
;
2026 else color
= dib
.dsBm
.bmBitsPixel
;
2028 /* To match windows behavior, if cx is set to zero and
2029 the flag DI_DEFAULTSIZE is specified, cx becomes the
2030 system metric value for icons. If the flag is not specified
2031 the function sets the size to the height of the bitmap */
2034 if (uFlags
& DI_DEFAULTSIZE
)
2035 cx
= GetSystemMetrics (SM_CXICON
);
2037 cx
= dib
.dsBm
.bmHeight
;
2040 nImageCount
= dib
.dsBm
.bmWidth
/ cx
;
2042 if (clrMask
!= CLR_NONE
) color
|= ILC_MASK
;
2043 himl
= ImageList_Create (cx
, dib
.dsBm
.bmHeight
, color
, nImageCount
, cGrow
);
2045 DeleteObject (handle
);
2048 ImageList_AddMasked (himl
, handle
, clrMask
);
2050 else if ((uType
== IMAGE_ICON
) || (uType
== IMAGE_CURSOR
)) {
2054 GetIconInfo (handle
, &ii
);
2055 GetObjectW (ii
.hbmColor
, sizeof(BITMAP
), &bmp
);
2056 himl
= ImageList_Create (bmp
.bmWidth
, bmp
.bmHeight
,
2057 ILC_MASK
| ILC_COLOR
, 1, cGrow
);
2059 DeleteObject (ii
.hbmColor
);
2060 DeleteObject (ii
.hbmMask
);
2061 DeleteObject (handle
);
2064 ImageList_Add (himl
, ii
.hbmColor
, ii
.hbmMask
);
2065 DeleteObject (ii
.hbmColor
);
2066 DeleteObject (ii
.hbmMask
);
2069 DeleteObject (handle
);
2075 /*************************************************************************
2076 * ImageList_Merge [COMCTL32.@]
2078 * Create an image list containing a merged image from two image lists.
2081 * himl1 [I] handle to first image list
2082 * i1 [I] first image index
2083 * himl2 [I] handle to second image list
2084 * i2 [I] second image index
2085 * dx [I] X offset of the second image relative to the first.
2086 * dy [I] Y offset of the second image relative to the first.
2089 * Success: The newly created image list. It contains a single image
2090 * consisting of the second image merged with the first.
2091 * Failure: NULL, if either himl1 or himl2 is invalid.
2094 * - The returned image list should be deleted by the caller using
2095 * ImageList_Destroy() when it is no longer required.
2096 * - If either i1 or i2 is not a valid image index, they will be treated
2100 ImageList_Merge (HIMAGELIST himl1
, INT i1
, HIMAGELIST himl2
, INT i2
,
2103 HIMAGELIST himlDst
= NULL
;
2105 INT xOff1
, yOff1
, xOff2
, yOff2
;
2109 TRACE("(himl1=%p i1=%d himl2=%p i2=%d dx=%d dy=%d)\n", himl1
, i1
, himl2
,
2112 if (!is_valid(himl1
) || !is_valid(himl2
))
2116 cxDst
= max (himl1
->cx
, dx
+ himl2
->cx
);
2121 cxDst
= max (himl2
->cx
, himl1
->cx
- dx
);
2126 cxDst
= max (himl1
->cx
, himl2
->cx
);
2132 cyDst
= max (himl1
->cy
, dy
+ himl2
->cy
);
2137 cyDst
= max (himl2
->cy
, himl1
->cy
- dy
);
2142 cyDst
= max (himl1
->cy
, himl2
->cy
);
2147 newFlags
= (himl1
->flags
> himl2
->flags
? himl1
->flags
: himl2
->flags
) & ILC_COLORDDB
;
2148 if (newFlags
== ILC_COLORDDB
&& (himl1
->flags
& ILC_COLORDDB
) == ILC_COLOR16
)
2149 newFlags
= ILC_COLOR16
; /* this is what native (at least v5) does, don't know why */
2150 himlDst
= ImageList_Create (cxDst
, cyDst
, ILC_MASK
| newFlags
, 1, 1);
2154 imagelist_point_from_index( himl1
, i1
, &pt1
);
2155 imagelist_point_from_index( himl2
, i2
, &pt2
);
2158 BitBlt (himlDst
->hdcImage
, 0, 0, cxDst
, cyDst
, himl1
->hdcImage
, 0, 0, BLACKNESS
);
2159 if (i1
>= 0 && i1
< himl1
->cCurImage
)
2160 BitBlt (himlDst
->hdcImage
, xOff1
, yOff1
, himl1
->cx
, himl1
->cy
, himl1
->hdcImage
, pt1
.x
, pt1
.y
, SRCCOPY
);
2161 if (i2
>= 0 && i2
< himl2
->cCurImage
)
2163 if (himl2
->flags
& ILC_MASK
)
2165 BitBlt (himlDst
->hdcImage
, xOff2
, yOff2
, himl2
->cx
, himl2
->cy
, himl2
->hdcMask
, pt2
.x
, pt2
.y
, SRCAND
);
2166 BitBlt (himlDst
->hdcImage
, xOff2
, yOff2
, himl2
->cx
, himl2
->cy
, himl2
->hdcImage
, pt2
.x
, pt2
.y
, SRCPAINT
);
2169 BitBlt (himlDst
->hdcImage
, xOff2
, yOff2
, himl2
->cx
, himl2
->cy
, himl2
->hdcImage
, pt2
.x
, pt2
.y
, SRCCOPY
);
2173 BitBlt (himlDst
->hdcMask
, 0, 0, cxDst
, cyDst
, himl1
->hdcMask
, 0, 0, WHITENESS
);
2174 if (i1
>= 0 && i1
< himl1
->cCurImage
)
2175 BitBlt (himlDst
->hdcMask
, xOff1
, yOff1
, himl1
->cx
, himl1
->cy
, himl1
->hdcMask
, pt1
.x
, pt1
.y
, SRCCOPY
);
2176 if (i2
>= 0 && i2
< himl2
->cCurImage
)
2177 BitBlt (himlDst
->hdcMask
, xOff2
, yOff2
, himl2
->cx
, himl2
->cy
, himl2
->hdcMask
, pt2
.x
, pt2
.y
, SRCAND
);
2179 himlDst
->cCurImage
= 1;
2186 /* helper for ImageList_Read, see comments below */
2187 static void *read_bitmap(IStream
*pstm
, BITMAPINFO
*bmi
)
2189 BITMAPFILEHEADER bmfh
;
2190 int bitsperpixel
, palspace
;
2193 if (FAILED(IStream_Read ( pstm
, &bmfh
, sizeof(bmfh
), NULL
)))
2196 if (bmfh
.bfType
!= (('M'<<8)|'B'))
2199 if (FAILED(IStream_Read ( pstm
, &bmi
->bmiHeader
, sizeof(bmi
->bmiHeader
), NULL
)))
2202 if ((bmi
->bmiHeader
.biSize
!= sizeof(bmi
->bmiHeader
)))
2205 TRACE("width %u, height %u, planes %u, bpp %u\n",
2206 bmi
->bmiHeader
.biWidth
, bmi
->bmiHeader
.biHeight
,
2207 bmi
->bmiHeader
.biPlanes
, bmi
->bmiHeader
.biBitCount
);
2209 bitsperpixel
= bmi
->bmiHeader
.biPlanes
* bmi
->bmiHeader
.biBitCount
;
2210 if (bitsperpixel
<=8)
2211 palspace
= (1<<bitsperpixel
)*sizeof(RGBQUAD
);
2215 bmi
->bmiHeader
.biSizeImage
= get_dib_image_size( bmi
);
2217 /* read the palette right after the end of the bitmapinfoheader */
2218 if (palspace
&& FAILED(IStream_Read(pstm
, bmi
->bmiColors
, palspace
, NULL
)))
2221 bits
= heap_alloc_zero(bmi
->bmiHeader
.biSizeImage
);
2222 if (!bits
) return NULL
;
2224 if (FAILED(IStream_Read(pstm
, bits
, bmi
->bmiHeader
.biSizeImage
, NULL
)))
2232 /*************************************************************************
2233 * ImageList_Read [COMCTL32.@]
2235 * Reads an image list from a stream.
2238 * pstm [I] pointer to a stream
2241 * Success: handle to image list
2244 * The format is like this:
2245 * ILHEAD ilheadstruct;
2247 * for the color image part:
2248 * BITMAPFILEHEADER bmfh;
2249 * BITMAPINFOHEADER bmih;
2250 * only if it has a palette:
2251 * RGBQUAD rgbs[nr_of_paletted_colors];
2253 * BYTE colorbits[imagesize];
2255 * the following only if the ILC_MASK bit is set in ILHEAD.ilFlags:
2256 * BITMAPFILEHEADER bmfh_mask;
2257 * BITMAPINFOHEADER bmih_mask;
2258 * only if it has a palette (it usually does not):
2259 * RGBQUAD rgbs[nr_of_paletted_colors];
2261 * BYTE maskbits[imagesize];
2263 HIMAGELIST WINAPI
ImageList_Read(IStream
*pstm
)
2265 char image_buf
[sizeof(BITMAPINFOHEADER
) + sizeof(RGBQUAD
) * 256];
2266 char mask_buf
[sizeof(BITMAPINFOHEADER
) + sizeof(RGBQUAD
) * 256];
2267 BITMAPINFO
*image_info
= (BITMAPINFO
*)image_buf
;
2268 BITMAPINFO
*mask_info
= (BITMAPINFO
*)mask_buf
;
2269 void *image_bits
, *mask_bits
= NULL
;
2274 TRACE("%p\n", pstm
);
2276 if (FAILED(IStream_Read (pstm
, &ilHead
, sizeof(ILHEAD
), NULL
)))
2278 if (ilHead
.usMagic
!= (('L' << 8) | 'I'))
2280 if (ilHead
.usVersion
!= 0x101) /* probably version? */
2283 TRACE("cx %u, cy %u, flags 0x%04x, cCurImage %u, cMaxImage %u\n",
2284 ilHead
.cx
, ilHead
.cy
, ilHead
.flags
, ilHead
.cCurImage
, ilHead
.cMaxImage
);
2286 himl
= ImageList_Create(ilHead
.cx
, ilHead
.cy
, ilHead
.flags
, ilHead
.cMaxImage
, ilHead
.cGrow
);
2290 if (!(image_bits
= read_bitmap(pstm
, image_info
)))
2292 WARN("failed to read bitmap from stream\n");
2295 if (ilHead
.flags
& ILC_MASK
)
2297 if (!(mask_bits
= read_bitmap(pstm
, mask_info
)))
2299 WARN("failed to read mask bitmap from stream\n");
2303 else mask_info
= NULL
;
2305 if ((himl
->flags
& 0xfe) == ILC_COLOR32
&& image_info
->bmiHeader
.biBitCount
== 32)
2307 DWORD
*ptr
= image_bits
;
2308 BYTE
*mask_ptr
= mask_bits
;
2309 int stride
= himl
->cy
* image_info
->bmiHeader
.biWidth
;
2311 if (image_info
->bmiHeader
.biHeight
> 0) /* bottom-up */
2313 ptr
+= image_info
->bmiHeader
.biHeight
* image_info
->bmiHeader
.biWidth
- stride
;
2314 mask_ptr
+= (image_info
->bmiHeader
.biHeight
* image_info
->bmiHeader
.biWidth
- stride
) / 8;
2316 image_info
->bmiHeader
.biHeight
= himl
->cy
;
2318 else image_info
->bmiHeader
.biHeight
= -himl
->cy
;
2320 for (i
= 0; i
< ilHead
.cCurImage
; i
+= TILE_COUNT
)
2322 add_dib_bits( himl
, i
, min( ilHead
.cCurImage
- i
, TILE_COUNT
),
2323 himl
->cx
, himl
->cy
, image_info
, mask_info
, ptr
, mask_ptr
);
2325 mask_ptr
+= stride
/ 8;
2330 StretchDIBits( himl
->hdcImage
, 0, 0, image_info
->bmiHeader
.biWidth
, image_info
->bmiHeader
.biHeight
,
2331 0, 0, image_info
->bmiHeader
.biWidth
, image_info
->bmiHeader
.biHeight
,
2332 image_bits
, image_info
, DIB_RGB_COLORS
, SRCCOPY
);
2334 StretchDIBits( himl
->hdcMask
, 0, 0, mask_info
->bmiHeader
.biWidth
, mask_info
->bmiHeader
.biHeight
,
2335 0, 0, mask_info
->bmiHeader
.biWidth
, mask_info
->bmiHeader
.biHeight
,
2336 mask_bits
, mask_info
, DIB_RGB_COLORS
, SRCCOPY
);
2338 heap_free( image_bits
);
2339 heap_free( mask_bits
);
2341 himl
->cCurImage
= ilHead
.cCurImage
;
2342 himl
->cMaxImage
= ilHead
.cMaxImage
;
2344 ImageList_SetBkColor(himl
,ilHead
.bkcolor
);
2346 ImageList_SetOverlayImage(himl
,ilHead
.ovls
[i
],i
+1);
2351 /*************************************************************************
2352 * ImageList_Remove [COMCTL32.@]
2354 * Removes an image from an image list
2357 * himl [I] image list handle
2364 * FIXME: as the image list storage test shows, native comctl32 simply shifts
2365 * images without creating a new bitmap.
2368 ImageList_Remove (HIMAGELIST himl
, INT i
)
2370 HBITMAP hbmNewImage
, hbmNewMask
;
2374 TRACE("(himl=%p i=%d)\n", himl
, i
);
2376 if (!is_valid(himl
)) {
2377 ERR("Invalid image list handle!\n");
2381 if ((i
< -1) || (i
>= himl
->cCurImage
)) {
2382 TRACE("index out of range! %d\n", i
);
2390 if (himl
->cCurImage
== 0) {
2391 /* remove all on empty ImageList is allowed */
2392 TRACE("remove all on empty ImageList!\n");
2396 himl
->cMaxImage
= himl
->cGrow
;
2397 himl
->cCurImage
= 0;
2398 for (nCount
= 0; nCount
< MAX_OVERLAYIMAGE
; nCount
++)
2399 himl
->nOvlIdx
[nCount
] = -1;
2401 heap_free( himl
->item_flags
);
2402 himl
->item_flags
= heap_alloc_zero( himl
->cMaxImage
* sizeof(*himl
->item_flags
) );
2404 hbmNewImage
= ImageList_CreateImage(himl
->hdcImage
, himl
, himl
->cMaxImage
);
2405 SelectObject (himl
->hdcImage
, hbmNewImage
);
2406 DeleteObject (himl
->hbmImage
);
2407 himl
->hbmImage
= hbmNewImage
;
2409 if (himl
->hbmMask
) {
2411 imagelist_get_bitmap_size(himl
, himl
->cMaxImage
, &sz
);
2412 hbmNewMask
= CreateBitmap (sz
.cx
, sz
.cy
, 1, 1, NULL
);
2413 SelectObject (himl
->hdcMask
, hbmNewMask
);
2414 DeleteObject (himl
->hbmMask
);
2415 himl
->hbmMask
= hbmNewMask
;
2419 /* delete one image */
2420 TRACE("Remove single image! %d\n", i
);
2422 /* create new bitmap(s) */
2423 TRACE(" - Number of images: %d / %d (Old/New)\n",
2424 himl
->cCurImage
, himl
->cCurImage
- 1);
2426 hbmNewImage
= ImageList_CreateImage(himl
->hdcImage
, himl
, himl
->cMaxImage
);
2428 imagelist_get_bitmap_size(himl
, himl
->cMaxImage
, &sz
);
2430 hbmNewMask
= CreateBitmap (sz
.cx
, sz
.cy
, 1, 1, NULL
);
2432 hbmNewMask
= 0; /* Just to keep compiler happy! */
2434 hdcBmp
= CreateCompatibleDC (0);
2436 /* copy all images and masks prior to the "removed" image */
2438 TRACE("Pre image copy: Copy %d images\n", i
);
2440 SelectObject (hdcBmp
, hbmNewImage
);
2441 imagelist_copy_images( himl
, himl
->hdcImage
, hdcBmp
, 0, i
, 0 );
2443 if (himl
->hbmMask
) {
2444 SelectObject (hdcBmp
, hbmNewMask
);
2445 imagelist_copy_images( himl
, himl
->hdcMask
, hdcBmp
, 0, i
, 0 );
2449 /* copy all images and masks behind the removed image */
2450 if (i
< himl
->cCurImage
- 1) {
2451 TRACE("Post image copy!\n");
2453 SelectObject (hdcBmp
, hbmNewImage
);
2454 imagelist_copy_images( himl
, himl
->hdcImage
, hdcBmp
, i
+ 1,
2455 (himl
->cCurImage
- i
), i
);
2457 if (himl
->hbmMask
) {
2458 SelectObject (hdcBmp
, hbmNewMask
);
2459 imagelist_copy_images( himl
, himl
->hdcMask
, hdcBmp
, i
+ 1,
2460 (himl
->cCurImage
- i
), i
);
2466 /* delete old images and insert new ones */
2467 SelectObject (himl
->hdcImage
, hbmNewImage
);
2468 DeleteObject (himl
->hbmImage
);
2469 himl
->hbmImage
= hbmNewImage
;
2470 if (himl
->hbmMask
) {
2471 SelectObject (himl
->hdcMask
, hbmNewMask
);
2472 DeleteObject (himl
->hbmMask
);
2473 himl
->hbmMask
= hbmNewMask
;
2483 /*************************************************************************
2484 * ImageList_Replace [COMCTL32.@]
2486 * Replaces an image in an image list with a new image.
2489 * himl [I] handle to image list
2491 * hbmImage [I] handle to image bitmap
2492 * hbmMask [I] handle to mask bitmap. Can be NULL.
2500 ImageList_Replace (HIMAGELIST himl
, INT i
, HBITMAP hbmImage
,
2507 TRACE("%p %d %p %p\n", himl
, i
, hbmImage
, hbmMask
);
2509 if (!is_valid(himl
)) {
2510 ERR("Invalid image list handle!\n");
2514 if ((i
>= himl
->cMaxImage
) || (i
< 0)) {
2515 ERR("Invalid image index!\n");
2519 if (!GetObjectW(hbmImage
, sizeof(BITMAP
), &bmp
))
2522 hdcImage
= CreateCompatibleDC (0);
2525 SelectObject (hdcImage
, hbmImage
);
2527 if (add_with_alpha( himl
, hdcImage
, i
, 1, bmp
.bmWidth
, bmp
.bmHeight
, hbmImage
, hbmMask
))
2530 imagelist_point_from_index(himl
, i
, &pt
);
2531 StretchBlt (himl
->hdcImage
, pt
.x
, pt
.y
, himl
->cx
, himl
->cy
,
2532 hdcImage
, 0, 0, bmp
.bmWidth
, bmp
.bmHeight
, SRCCOPY
);
2537 HBITMAP hOldBitmapTemp
;
2539 hdcTemp
= CreateCompatibleDC(0);
2540 hOldBitmapTemp
= SelectObject(hdcTemp
, hbmMask
);
2542 StretchBlt (himl
->hdcMask
, pt
.x
, pt
.y
, himl
->cx
, himl
->cy
,
2543 hdcTemp
, 0, 0, bmp
.bmWidth
, bmp
.bmHeight
, SRCCOPY
);
2544 SelectObject(hdcTemp
, hOldBitmapTemp
);
2547 /* Remove the background from the image
2549 BitBlt (himl
->hdcImage
, pt
.x
, pt
.y
, bmp
.bmWidth
, bmp
.bmHeight
,
2550 himl
->hdcMask
, pt
.x
, pt
.y
, 0x220326); /* NOTSRCAND */
2554 DeleteDC (hdcImage
);
2560 /*************************************************************************
2561 * ImageList_ReplaceIcon [COMCTL32.@]
2563 * Replaces an image in an image list using an icon.
2566 * himl [I] handle to image list
2568 * hIcon [I] handle to icon
2571 * Success: index of the replaced image
2576 ImageList_ReplaceIcon (HIMAGELIST himl
, INT nIndex
, HICON hIcon
)
2584 TRACE("(%p %d %p)\n", himl
, nIndex
, hIcon
);
2586 if (!is_valid(himl
)) {
2587 ERR("invalid image list\n");
2590 if ((nIndex
>= himl
->cMaxImage
) || (nIndex
< -1)) {
2591 ERR("invalid image index %d / %d\n", nIndex
, himl
->cMaxImage
);
2595 hBestFitIcon
= CopyImage(
2598 LR_COPYFROMRESOURCE
);
2599 /* the above will fail if the icon wasn't loaded from a resource, so try
2600 * again without LR_COPYFROMRESOURCE flag */
2602 hBestFitIcon
= CopyImage(
2610 if (himl
->cCurImage
+ 1 >= himl
->cMaxImage
)
2611 IMAGELIST_InternalExpandBitmaps(himl
, 1);
2613 nIndex
= himl
->cCurImage
;
2617 if ((himl
->flags
& 0xfe) == ILC_COLOR32
&& GetIconInfo (hBestFitIcon
, &ii
))
2619 HDC hdcImage
= CreateCompatibleDC( 0 );
2620 GetObjectW (ii
.hbmMask
, sizeof(BITMAP
), &bmp
);
2624 UINT height
= bmp
.bmHeight
/ 2;
2625 HDC hdcMask
= CreateCompatibleDC( 0 );
2626 HBITMAP color
= CreateBitmap( bmp
.bmWidth
, height
, 1, 1, NULL
);
2627 SelectObject( hdcImage
, color
);
2628 SelectObject( hdcMask
, ii
.hbmMask
);
2629 BitBlt( hdcImage
, 0, 0, bmp
.bmWidth
, height
, hdcMask
, 0, height
, SRCCOPY
);
2630 ret
= add_with_alpha( himl
, hdcImage
, nIndex
, 1, bmp
.bmWidth
, height
, color
, ii
.hbmMask
);
2631 DeleteDC( hdcMask
);
2632 DeleteObject( color
);
2634 else ret
= add_with_alpha( himl
, hdcImage
, nIndex
, 1, bmp
.bmWidth
, bmp
.bmHeight
,
2635 ii
.hbmColor
, ii
.hbmMask
);
2637 DeleteDC( hdcImage
);
2638 DeleteObject (ii
.hbmMask
);
2639 if (ii
.hbmColor
) DeleteObject (ii
.hbmColor
);
2643 imagelist_point_from_index(himl
, nIndex
, &pt
);
2647 DrawIconEx( himl
->hdcImage
, pt
.x
, pt
.y
, hBestFitIcon
, himl
->cx
, himl
->cy
, 0, 0, DI_IMAGE
);
2648 PatBlt( himl
->hdcMask
, pt
.x
, pt
.y
, himl
->cx
, himl
->cy
, WHITENESS
);
2649 DrawIconEx( himl
->hdcMask
, pt
.x
, pt
.y
, hBestFitIcon
, himl
->cx
, himl
->cy
, 0, 0, DI_MASK
);
2653 COLORREF color
= himl
->clrBk
!= CLR_NONE
? himl
->clrBk
: comctl32_color
.clrWindow
;
2654 HBRUSH brush
= CreateSolidBrush( GetNearestColor( himl
->hdcImage
, color
));
2656 SelectObject( himl
->hdcImage
, brush
);
2657 PatBlt( himl
->hdcImage
, pt
.x
, pt
.y
, himl
->cx
, himl
->cy
, PATCOPY
);
2658 SelectObject( himl
->hdcImage
, GetStockObject(BLACK_BRUSH
) );
2659 DeleteObject( brush
);
2660 DrawIconEx( himl
->hdcImage
, pt
.x
, pt
.y
, hBestFitIcon
, himl
->cx
, himl
->cy
, 0, 0, DI_NORMAL
);
2664 DestroyIcon(hBestFitIcon
);
2666 TRACE("Insert index = %d, himl->cCurImage = %d\n", nIndex
, himl
->cCurImage
);
2671 /*************************************************************************
2672 * ImageList_SetBkColor [COMCTL32.@]
2674 * Sets the background color of an image list.
2677 * himl [I] handle to image list
2678 * clrBk [I] background color
2681 * Success: previous background color
2686 ImageList_SetBkColor (HIMAGELIST himl
, COLORREF clrBk
)
2690 if (!is_valid(himl
))
2693 clrOldBk
= himl
->clrBk
;
2694 himl
->clrBk
= clrBk
;
2699 /*************************************************************************
2700 * ImageList_SetDragCursorImage [COMCTL32.@]
2702 * Combines the specified image with the current drag image
2705 * himlDrag [I] handle to drag image list
2706 * iDrag [I] drag image index
2707 * dxHotspot [I] X position of the hot spot
2708 * dyHotspot [I] Y position of the hot spot
2715 * - The names dxHotspot, dyHotspot are misleading because they have nothing
2716 * to do with a hotspot but are only the offset of the origin of the new
2717 * image relative to the origin of the old image.
2719 * - When this function is called and the drag image is visible, a
2720 * short flickering occurs but this matches the Win9x behavior. It is
2721 * possible to fix the flickering using code like in ImageList_DragMove.
2725 ImageList_SetDragCursorImage (HIMAGELIST himlDrag
, INT iDrag
,
2726 INT dxHotspot
, INT dyHotspot
)
2728 HIMAGELIST himlTemp
;
2731 if (!is_valid(InternalDrag
.himl
) || !is_valid(himlDrag
))
2734 TRACE(" dxH=%d dyH=%d nX=%d nY=%d\n",
2735 dxHotspot
, dyHotspot
, InternalDrag
.dxHotspot
, InternalDrag
.dyHotspot
);
2737 visible
= InternalDrag
.bShow
;
2739 himlTemp
= ImageList_Merge (InternalDrag
.himlNoCursor
, 0, himlDrag
, iDrag
,
2740 dxHotspot
, dyHotspot
);
2743 /* hide the drag image */
2744 ImageList_DragShowNolock(FALSE
);
2746 if ((InternalDrag
.himl
->cx
!= himlTemp
->cx
) ||
2747 (InternalDrag
.himl
->cy
!= himlTemp
->cy
)) {
2748 /* the size of the drag image changed, invalidate the buffer */
2749 DeleteObject(InternalDrag
.hbmBg
);
2750 InternalDrag
.hbmBg
= 0;
2753 if (InternalDrag
.himl
!= InternalDrag
.himlNoCursor
)
2754 ImageList_Destroy (InternalDrag
.himl
);
2755 InternalDrag
.himl
= himlTemp
;
2758 /* show the drag image */
2759 ImageList_DragShowNolock(TRUE
);
2766 /*************************************************************************
2767 * ImageList_SetFilter [COMCTL32.@]
2769 * Sets a filter (or does something completely different)!!???
2770 * It removes 12 Bytes from the stack (3 Parameters).
2773 * himl [I] SHOULD be a handle to image list
2774 * i [I] COULD be an index?
2779 * Failure: FALSE ???
2782 * This is an UNDOCUMENTED function!!!!
2787 ImageList_SetFilter (HIMAGELIST himl
, INT i
, DWORD dwFilter
)
2789 FIXME("(%p 0x%x 0x%x):empty stub!\n", himl
, i
, dwFilter
);
2795 /*************************************************************************
2796 * ImageList_SetFlags [COMCTL32.@]
2798 * Sets the image list flags.
2801 * himl [I] Handle to image list
2802 * flags [I] Flags to set
2812 ImageList_SetFlags(HIMAGELIST himl
, DWORD flags
)
2814 FIXME("(%p %08x):empty stub\n", himl
, flags
);
2819 /*************************************************************************
2820 * ImageList_SetIconSize [COMCTL32.@]
2822 * Sets the image size of the bitmap and deletes all images.
2825 * himl [I] handle to image list
2826 * cx [I] image width
2827 * cy [I] image height
2835 ImageList_SetIconSize (HIMAGELIST himl
, INT cx
, INT cy
)
2840 if (!is_valid(himl
))
2843 /* remove all images */
2844 himl
->cMaxImage
= himl
->cInitial
+ 1;
2845 himl
->cCurImage
= 0;
2849 /* initialize overlay mask indices */
2850 for (nCount
= 0; nCount
< MAX_OVERLAYIMAGE
; nCount
++)
2851 himl
->nOvlIdx
[nCount
] = -1;
2853 hbmNew
= ImageList_CreateImage(himl
->hdcImage
, himl
, himl
->cMaxImage
);
2854 SelectObject (himl
->hdcImage
, hbmNew
);
2855 DeleteObject (himl
->hbmImage
);
2856 himl
->hbmImage
= hbmNew
;
2858 if (himl
->hbmMask
) {
2860 imagelist_get_bitmap_size(himl
, himl
->cMaxImage
, &sz
);
2861 hbmNew
= CreateBitmap (sz
.cx
, sz
.cy
, 1, 1, NULL
);
2862 SelectObject (himl
->hdcMask
, hbmNew
);
2863 DeleteObject (himl
->hbmMask
);
2864 himl
->hbmMask
= hbmNew
;
2871 /*************************************************************************
2872 * ImageList_SetImageCount [COMCTL32.@]
2874 * Resizes an image list to the specified number of images.
2877 * himl [I] handle to image list
2878 * iImageCount [I] number of images in the image list
2886 ImageList_SetImageCount (HIMAGELIST himl
, UINT iImageCount
)
2889 HBITMAP hbmNewBitmap
, hbmOld
;
2890 INT nNewCount
, nCopyCount
;
2892 TRACE("%p %d\n",himl
,iImageCount
);
2894 if (!is_valid(himl
))
2897 nNewCount
= iImageCount
+ 1;
2898 nCopyCount
= min(himl
->cCurImage
, iImageCount
);
2900 hdcBitmap
= CreateCompatibleDC (0);
2902 hbmNewBitmap
= ImageList_CreateImage(hdcBitmap
, himl
, nNewCount
);
2904 if (hbmNewBitmap
!= 0)
2906 hbmOld
= SelectObject (hdcBitmap
, hbmNewBitmap
);
2907 imagelist_copy_images( himl
, himl
->hdcImage
, hdcBitmap
, 0, nCopyCount
, 0 );
2908 SelectObject (hdcBitmap
, hbmOld
);
2910 /* FIXME: delete 'empty' image space? */
2912 SelectObject (himl
->hdcImage
, hbmNewBitmap
);
2913 DeleteObject (himl
->hbmImage
);
2914 himl
->hbmImage
= hbmNewBitmap
;
2917 ERR("Could not create new image bitmap!\n");
2922 imagelist_get_bitmap_size( himl
, nNewCount
, &sz
);
2923 hbmNewBitmap
= CreateBitmap (sz
.cx
, sz
.cy
, 1, 1, NULL
);
2924 if (hbmNewBitmap
!= 0)
2926 hbmOld
= SelectObject (hdcBitmap
, hbmNewBitmap
);
2927 imagelist_copy_images( himl
, himl
->hdcMask
, hdcBitmap
, 0, nCopyCount
, 0 );
2928 SelectObject (hdcBitmap
, hbmOld
);
2930 /* FIXME: delete 'empty' image space? */
2932 SelectObject (himl
->hdcMask
, hbmNewBitmap
);
2933 DeleteObject (himl
->hbmMask
);
2934 himl
->hbmMask
= hbmNewBitmap
;
2937 ERR("Could not create new mask bitmap!\n");
2940 DeleteDC (hdcBitmap
);
2942 himl
->item_flags
= HeapReAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, himl
->item_flags
,
2943 nNewCount
* sizeof(*himl
->item_flags
));
2945 /* Update max image count and current image count */
2946 himl
->cMaxImage
= nNewCount
;
2947 himl
->cCurImage
= iImageCount
;
2953 /*************************************************************************
2954 * ImageList_SetOverlayImage [COMCTL32.@]
2956 * Assigns an overlay mask index to an existing image in an image list.
2959 * himl [I] handle to image list
2960 * iImage [I] image index
2961 * iOverlay [I] overlay mask index
2969 ImageList_SetOverlayImage (HIMAGELIST himl
, INT iImage
, INT iOverlay
)
2971 if (!is_valid(himl
))
2973 if ((iOverlay
< 1) || (iOverlay
> MAX_OVERLAYIMAGE
))
2975 if ((iImage
!=-1) && ((iImage
< 0) || (iImage
> himl
->cCurImage
)))
2977 himl
->nOvlIdx
[iOverlay
- 1] = iImage
;
2983 /* helper for ImageList_Write - write bitmap to pstm
2984 * currently everything is written as 24 bit RGB, except masks
2986 static BOOL
_write_bitmap(HBITMAP hBitmap
, IStream
*pstm
)
2988 LPBITMAPFILEHEADER bmfh
;
2989 LPBITMAPINFOHEADER bmih
;
2990 LPBYTE data
= NULL
, lpBits
;
2992 INT bitCount
, sizeImage
, offBits
, totalSize
;
2994 BOOL result
= FALSE
;
2996 if (!GetObjectW(hBitmap
, sizeof(BITMAP
), &bm
))
2999 bitCount
= bm
.bmBitsPixel
;
3000 sizeImage
= get_dib_stride(bm
.bmWidth
, bitCount
) * bm
.bmHeight
;
3002 totalSize
= sizeof(BITMAPFILEHEADER
) + sizeof(BITMAPINFOHEADER
);
3004 totalSize
+= (1 << bitCount
) * sizeof(RGBQUAD
);
3005 offBits
= totalSize
;
3006 totalSize
+= sizeImage
;
3008 data
= heap_alloc_zero(totalSize
);
3009 bmfh
= (LPBITMAPFILEHEADER
)data
;
3010 bmih
= (LPBITMAPINFOHEADER
)(data
+ sizeof(BITMAPFILEHEADER
));
3011 lpBits
= data
+ offBits
;
3013 /* setup BITMAPFILEHEADER */
3014 bmfh
->bfType
= (('M' << 8) | 'B');
3015 bmfh
->bfSize
= offBits
;
3016 bmfh
->bfReserved1
= 0;
3017 bmfh
->bfReserved2
= 0;
3018 bmfh
->bfOffBits
= offBits
;
3020 /* setup BITMAPINFOHEADER */
3021 bmih
->biSize
= sizeof(BITMAPINFOHEADER
);
3022 bmih
->biWidth
= bm
.bmWidth
;
3023 bmih
->biHeight
= bm
.bmHeight
;
3025 bmih
->biBitCount
= bitCount
;
3026 bmih
->biCompression
= BI_RGB
;
3027 bmih
->biSizeImage
= sizeImage
;
3028 bmih
->biXPelsPerMeter
= 0;
3029 bmih
->biYPelsPerMeter
= 0;
3030 bmih
->biClrUsed
= 0;
3031 bmih
->biClrImportant
= 0;
3034 result
= GetDIBits(xdc
, hBitmap
, 0, bm
.bmHeight
, lpBits
, (BITMAPINFO
*)bmih
, DIB_RGB_COLORS
) == bm
.bmHeight
;
3039 TRACE("width %u, height %u, planes %u, bpp %u\n",
3040 bmih
->biWidth
, bmih
->biHeight
,
3041 bmih
->biPlanes
, bmih
->biBitCount
);
3043 if(FAILED(IStream_Write(pstm
, data
, totalSize
, NULL
)))
3055 /*************************************************************************
3056 * ImageList_Write [COMCTL32.@]
3058 * Writes an image list to a stream.
3061 * himl [I] handle to image list
3062 * pstm [O] Pointer to a stream.
3072 BOOL WINAPI
ImageList_Write(HIMAGELIST himl
, IStream
*pstm
)
3077 TRACE("%p %p\n", himl
, pstm
);
3079 if (!is_valid(himl
))
3082 ilHead
.usMagic
= (('L' << 8) | 'I');
3083 ilHead
.usVersion
= 0x101;
3084 ilHead
.cCurImage
= himl
->cCurImage
;
3085 ilHead
.cMaxImage
= himl
->cMaxImage
;
3086 ilHead
.cGrow
= himl
->cGrow
;
3087 ilHead
.cx
= himl
->cx
;
3088 ilHead
.cy
= himl
->cy
;
3089 ilHead
.bkcolor
= himl
->clrBk
;
3090 ilHead
.flags
= himl
->flags
;
3091 for(i
= 0; i
< 4; i
++) {
3092 ilHead
.ovls
[i
] = himl
->nOvlIdx
[i
];
3095 TRACE("cx %u, cy %u, flags 0x04%x, cCurImage %u, cMaxImage %u\n",
3096 ilHead
.cx
, ilHead
.cy
, ilHead
.flags
, ilHead
.cCurImage
, ilHead
.cMaxImage
);
3098 if(FAILED(IStream_Write(pstm
, &ilHead
, sizeof(ILHEAD
), NULL
)))
3101 /* write the bitmap */
3102 if(!_write_bitmap(himl
->hbmImage
, pstm
))
3105 /* write the mask if we have one */
3106 if(himl
->flags
& ILC_MASK
) {
3107 if(!_write_bitmap(himl
->hbmMask
, pstm
))
3115 static HBITMAP
ImageList_CreateImage(HDC hdc
, HIMAGELIST himl
, UINT count
)
3117 HBITMAP hbmNewBitmap
;
3118 UINT ilc
= (himl
->flags
& 0xFE);
3121 imagelist_get_bitmap_size( himl
, count
, &sz
);
3123 if ((ilc
>= ILC_COLOR4
&& ilc
<= ILC_COLOR32
) || ilc
== ILC_COLOR
)
3125 char buffer
[sizeof(BITMAPINFOHEADER
) + 256 * sizeof(RGBQUAD
)];
3126 BITMAPINFO
*bmi
= (BITMAPINFO
*)buffer
;
3128 TRACE("Creating DIBSection %d x %d, %d Bits per Pixel\n",
3129 sz
.cx
, sz
.cy
, himl
->uBitsPixel
);
3131 memset( buffer
, 0, sizeof(buffer
) );
3132 bmi
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
3133 bmi
->bmiHeader
.biWidth
= sz
.cx
;
3134 bmi
->bmiHeader
.biHeight
= sz
.cy
;
3135 bmi
->bmiHeader
.biPlanes
= 1;
3136 bmi
->bmiHeader
.biBitCount
= himl
->uBitsPixel
;
3137 bmi
->bmiHeader
.biCompression
= BI_RGB
;
3139 if (himl
->uBitsPixel
<= ILC_COLOR8
)
3141 if (!himl
->color_table_set
)
3143 /* retrieve the default color map */
3144 HBITMAP tmp
= CreateBitmap( 1, 1, 1, 1, NULL
);
3145 GetDIBits( hdc
, tmp
, 0, 0, NULL
, bmi
, DIB_RGB_COLORS
);
3146 DeleteObject( tmp
);
3147 if (ilc
== ILC_COLOR4
)
3150 tmp
= bmi
->bmiColors
[7];
3151 bmi
->bmiColors
[7] = bmi
->bmiColors
[8];
3152 bmi
->bmiColors
[8] = tmp
;
3157 GetDIBColorTable(himl
->hdcImage
, 0, 1 << himl
->uBitsPixel
, bmi
->bmiColors
);
3160 hbmNewBitmap
= CreateDIBSection(hdc
, bmi
, DIB_RGB_COLORS
, NULL
, 0, 0);
3162 else /*if (ilc == ILC_COLORDDB)*/
3164 TRACE("Creating Bitmap: %d Bits per Pixel\n", himl
->uBitsPixel
);
3166 hbmNewBitmap
= CreateBitmap (sz
.cx
, sz
.cy
, 1, himl
->uBitsPixel
, NULL
);
3168 TRACE("returning %p\n", hbmNewBitmap
);
3169 return hbmNewBitmap
;
3172 /*************************************************************************
3173 * ImageList_SetColorTable [COMCTL32.@]
3175 * Sets the color table of an image list.
3178 * himl [I] Handle to the image list.
3179 * uStartIndex [I] The first index to set.
3180 * cEntries [I] Number of entries to set.
3181 * prgb [I] New color information for color table for the image list.
3184 * Success: Number of entries in the table that were set.
3188 * ImageList_Create(), SetDIBColorTable()
3192 ImageList_SetColorTable(HIMAGELIST himl
, UINT uStartIndex
, UINT cEntries
, const RGBQUAD
*prgb
)
3194 TRACE("(%p, %d, %d, %p)\n", himl
, uStartIndex
, cEntries
, prgb
);
3195 himl
->color_table_set
= TRUE
;
3196 return SetDIBColorTable(himl
->hdcImage
, uStartIndex
, cEntries
, prgb
);
3199 /*************************************************************************
3200 * ImageList_CoCreateInstance [COMCTL32.@]
3202 * Creates a new imagelist instance and returns an interface pointer to it.
3205 * rclsid [I] A reference to the CLSID (CLSID_ImageList).
3206 * punkOuter [I] Pointer to IUnknown interface for aggregation, if desired
3207 * riid [I] Identifier of the requested interface.
3208 * ppv [O] Returns the address of the pointer requested, or NULL.
3212 * Failure: Error value.
3215 ImageList_CoCreateInstance (REFCLSID rclsid
, const IUnknown
*punkOuter
, REFIID riid
, void **ppv
)
3217 TRACE("(%s,%p,%s,%p)\n", debugstr_guid(rclsid
), punkOuter
, debugstr_guid(riid
), ppv
);
3219 if (!IsEqualCLSID(&CLSID_ImageList
, rclsid
))
3220 return E_NOINTERFACE
;
3222 return ImageListImpl_CreateInstance(punkOuter
, riid
, ppv
);
3226 /*************************************************************************
3227 * IImageList implementation
3230 static HRESULT WINAPI
ImageListImpl_QueryInterface(IImageList2
*iface
,
3231 REFIID iid
, void **ppv
)
3233 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3235 TRACE("(%p,%s,%p)\n", iface
, debugstr_guid(iid
), ppv
);
3237 if (!ppv
) return E_INVALIDARG
;
3239 if (IsEqualIID(&IID_IUnknown
, iid
) ||
3240 IsEqualIID(&IID_IImageList
, iid
) ||
3241 IsEqualIID(&IID_IImageList2
, iid
))
3243 *ppv
= &imgl
->IImageList2_iface
;
3248 return E_NOINTERFACE
;
3251 IImageList2_AddRef(iface
);
3255 static ULONG WINAPI
ImageListImpl_AddRef(IImageList2
*iface
)
3257 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3258 ULONG ref
= InterlockedIncrement(&imgl
->ref
);
3260 TRACE("(%p) refcount=%u\n", iface
, ref
);
3264 static ULONG WINAPI
ImageListImpl_Release(IImageList2
*iface
)
3266 HIMAGELIST This
= impl_from_IImageList2(iface
);
3267 ULONG ref
= InterlockedDecrement(&This
->ref
);
3269 TRACE("(%p) refcount=%u\n", iface
, ref
);
3273 /* delete image bitmaps */
3274 if (This
->hbmImage
) DeleteObject (This
->hbmImage
);
3275 if (This
->hbmMask
) DeleteObject (This
->hbmMask
);
3277 /* delete image & mask DCs */
3278 if (This
->hdcImage
) DeleteDC (This
->hdcImage
);
3279 if (This
->hdcMask
) DeleteDC (This
->hdcMask
);
3281 /* delete blending brushes */
3282 if (This
->hbrBlend25
) DeleteObject (This
->hbrBlend25
);
3283 if (This
->hbrBlend50
) DeleteObject (This
->hbrBlend50
);
3285 This
->IImageList2_iface
.lpVtbl
= NULL
;
3286 heap_free(This
->item_flags
);
3293 static HRESULT WINAPI
ImageListImpl_Add(IImageList2
*iface
, HBITMAP hbmImage
,
3294 HBITMAP hbmMask
, int *pi
)
3296 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3302 ret
= ImageList_Add(imgl
, hbmImage
, hbmMask
);
3311 static HRESULT WINAPI
ImageListImpl_ReplaceIcon(IImageList2
*iface
, int i
,
3312 HICON hicon
, int *pi
)
3314 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3320 ret
= ImageList_ReplaceIcon(imgl
, i
, hicon
);
3329 static HRESULT WINAPI
ImageListImpl_SetOverlayImage(IImageList2
*iface
,
3330 int iImage
, int iOverlay
)
3332 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3333 return ImageList_SetOverlayImage(imgl
, iImage
, iOverlay
) ? S_OK
: E_FAIL
;
3336 static HRESULT WINAPI
ImageListImpl_Replace(IImageList2
*iface
, int i
,
3337 HBITMAP hbmImage
, HBITMAP hbmMask
)
3339 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3340 return ImageList_Replace(imgl
, i
, hbmImage
, hbmMask
) ? S_OK
: E_FAIL
;
3343 static HRESULT WINAPI
ImageListImpl_AddMasked(IImageList2
*iface
, HBITMAP hbmImage
,
3344 COLORREF crMask
, int *pi
)
3346 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3352 ret
= ImageList_AddMasked(imgl
, hbmImage
, crMask
);
3361 static HRESULT WINAPI
ImageListImpl_Draw(IImageList2
*iface
,
3362 IMAGELISTDRAWPARAMS
*pimldp
)
3364 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3365 HIMAGELIST old_himl
;
3368 /* As far as I can tell, Windows simply ignores the contents of pimldp->himl
3369 so we shall simulate the same */
3370 old_himl
= pimldp
->himl
;
3371 pimldp
->himl
= imgl
;
3373 ret
= ImageList_DrawIndirect(pimldp
);
3375 pimldp
->himl
= old_himl
;
3376 return ret
? S_OK
: E_INVALIDARG
;
3379 static HRESULT WINAPI
ImageListImpl_Remove(IImageList2
*iface
, int i
)
3381 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3382 return (ImageList_Remove(imgl
, i
) == 0) ? E_INVALIDARG
: S_OK
;
3385 static HRESULT WINAPI
ImageListImpl_GetIcon(IImageList2
*iface
, int i
, UINT flags
,
3388 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3394 hIcon
= ImageList_GetIcon(imgl
, i
, flags
);
3403 static HRESULT WINAPI
ImageListImpl_GetImageInfo(IImageList2
*iface
, int i
,
3404 IMAGEINFO
*pImageInfo
)
3406 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3407 return ImageList_GetImageInfo(imgl
, i
, pImageInfo
) ? S_OK
: E_FAIL
;
3410 static HRESULT WINAPI
ImageListImpl_Copy(IImageList2
*iface
, int dst_index
,
3411 IUnknown
*unk_src
, int src_index
, UINT flags
)
3413 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3414 IImageList
*src
= NULL
;
3420 /* TODO: Add test for IID_ImageList2 too */
3421 if (FAILED(IUnknown_QueryInterface(unk_src
, &IID_IImageList
,
3425 if (ImageList_Copy(imgl
, dst_index
, (HIMAGELIST
) src
, src_index
, flags
))
3430 IImageList_Release(src
);
3434 static HRESULT WINAPI
ImageListImpl_Merge(IImageList2
*iface
, int i1
,
3435 IUnknown
*punk2
, int i2
, int dx
, int dy
, REFIID riid
, void **ppv
)
3437 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3438 IImageList
*iml2
= NULL
;
3440 HRESULT ret
= E_FAIL
;
3442 TRACE("(%p)->(%d %p %d %d %d %s %p)\n", iface
, i1
, punk2
, i2
, dx
, dy
, debugstr_guid(riid
), ppv
);
3444 /* TODO: Add test for IID_ImageList2 too */
3445 if (FAILED(IUnknown_QueryInterface(punk2
, &IID_IImageList
,
3449 merged
= ImageList_Merge(imgl
, i1
, (HIMAGELIST
) iml2
, i2
, dx
, dy
);
3451 /* Get the interface for the new image list */
3454 ret
= HIMAGELIST_QueryInterface(merged
, riid
, ppv
);
3455 ImageList_Destroy(merged
);
3458 IImageList_Release(iml2
);
3462 static HRESULT WINAPI
ImageListImpl_Clone(IImageList2
*iface
, REFIID riid
, void **ppv
)
3464 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3466 HRESULT ret
= E_FAIL
;
3468 TRACE("(%p)->(%s %p)\n", iface
, debugstr_guid(riid
), ppv
);
3470 clone
= ImageList_Duplicate(imgl
);
3472 /* Get the interface for the new image list */
3475 ret
= HIMAGELIST_QueryInterface(clone
, riid
, ppv
);
3476 ImageList_Destroy(clone
);
3482 static HRESULT WINAPI
ImageListImpl_GetImageRect(IImageList2
*iface
, int i
,
3485 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3491 if (!ImageList_GetImageInfo(imgl
, i
, &info
))
3494 *prc
= info
.rcImage
;
3499 static HRESULT WINAPI
ImageListImpl_GetIconSize(IImageList2
*iface
, int *cx
,
3502 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3503 return ImageList_GetIconSize(imgl
, cx
, cy
) ? S_OK
: E_INVALIDARG
;
3506 static HRESULT WINAPI
ImageListImpl_SetIconSize(IImageList2
*iface
, int cx
,
3509 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3510 return ImageList_SetIconSize(imgl
, cx
, cy
) ? S_OK
: E_FAIL
;
3513 static HRESULT WINAPI
ImageListImpl_GetImageCount(IImageList2
*iface
, int *pi
)
3515 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3516 *pi
= ImageList_GetImageCount(imgl
);
3520 static HRESULT WINAPI
ImageListImpl_SetImageCount(IImageList2
*iface
, UINT count
)
3522 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3523 return ImageList_SetImageCount(imgl
, count
) ? S_OK
: E_FAIL
;
3526 static HRESULT WINAPI
ImageListImpl_SetBkColor(IImageList2
*iface
, COLORREF clrBk
,
3529 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3530 *pclr
= ImageList_SetBkColor(imgl
, clrBk
);
3534 static HRESULT WINAPI
ImageListImpl_GetBkColor(IImageList2
*iface
, COLORREF
*pclr
)
3536 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3537 *pclr
= ImageList_GetBkColor(imgl
);
3541 static HRESULT WINAPI
ImageListImpl_BeginDrag(IImageList2
*iface
, int iTrack
,
3542 int dxHotspot
, int dyHotspot
)
3544 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3545 return ImageList_BeginDrag(imgl
, iTrack
, dxHotspot
, dyHotspot
) ? S_OK
: E_FAIL
;
3548 static HRESULT WINAPI
ImageListImpl_EndDrag(IImageList2
*iface
)
3550 ImageList_EndDrag();
3554 static HRESULT WINAPI
ImageListImpl_DragEnter(IImageList2
*iface
, HWND hwndLock
,
3557 return ImageList_DragEnter(hwndLock
, x
, y
) ? S_OK
: E_FAIL
;
3560 static HRESULT WINAPI
ImageListImpl_DragLeave(IImageList2
*iface
, HWND hwndLock
)
3562 return ImageList_DragLeave(hwndLock
) ? S_OK
: E_FAIL
;
3565 static HRESULT WINAPI
ImageListImpl_DragMove(IImageList2
*iface
, int x
, int y
)
3567 return ImageList_DragMove(x
, y
) ? S_OK
: E_FAIL
;
3570 static HRESULT WINAPI
ImageListImpl_SetDragCursorImage(IImageList2
*iface
,
3571 IUnknown
*punk
, int iDrag
, int dxHotspot
, int dyHotspot
)
3573 IImageList
*iml2
= NULL
;
3579 /* TODO: Add test for IID_ImageList2 too */
3580 if (FAILED(IUnknown_QueryInterface(punk
, &IID_IImageList
,
3584 ret
= ImageList_SetDragCursorImage((HIMAGELIST
) iml2
, iDrag
, dxHotspot
,
3587 IImageList_Release(iml2
);
3589 return ret
? S_OK
: E_FAIL
;
3592 static HRESULT WINAPI
ImageListImpl_DragShowNolock(IImageList2
*iface
, BOOL fShow
)
3594 return ImageList_DragShowNolock(fShow
) ? S_OK
: E_FAIL
;
3597 static HRESULT WINAPI
ImageListImpl_GetDragImage(IImageList2
*iface
, POINT
*ppt
,
3598 POINT
*pptHotspot
, REFIID riid
, PVOID
*ppv
)
3600 HRESULT ret
= E_FAIL
;
3606 hNew
= ImageList_GetDragImage(ppt
, pptHotspot
);
3608 /* Get the interface for the new image list */
3611 IImageList
*idrag
= (IImageList
*)hNew
;
3613 ret
= HIMAGELIST_QueryInterface(hNew
, riid
, ppv
);
3614 IImageList_Release(idrag
);
3620 static HRESULT WINAPI
ImageListImpl_GetItemFlags(IImageList2
*iface
, int i
, DWORD
*flags
)
3622 HIMAGELIST This
= impl_from_IImageList2(iface
);
3624 if (i
< 0 || i
>= This
->cCurImage
)
3625 return E_INVALIDARG
;
3627 *flags
= This
->item_flags
[i
];
3632 static HRESULT WINAPI
ImageListImpl_GetOverlayImage(IImageList2
*iface
, int iOverlay
,
3635 HIMAGELIST This
= impl_from_IImageList2(iface
);
3638 if ((iOverlay
< 0) || (iOverlay
> This
->cCurImage
))
3641 for (i
= 0; i
< MAX_OVERLAYIMAGE
; i
++)
3643 if (This
->nOvlIdx
[i
] == iOverlay
)
3653 static HRESULT WINAPI
ImageListImpl_Resize(IImageList2
*iface
, INT cx
, INT cy
)
3655 FIXME("(%p)->(%d %d): stub\n", iface
, cx
, cy
);
3659 static HRESULT WINAPI
ImageListImpl_GetOriginalSize(IImageList2
*iface
, INT image
, DWORD flags
, INT
*cx
, INT
*cy
)
3661 FIXME("(%p)->(%d %x %p %p): stub\n", iface
, image
, flags
, cx
, cy
);
3665 static HRESULT WINAPI
ImageListImpl_SetOriginalSize(IImageList2
*iface
, INT image
, INT cx
, INT cy
)
3667 FIXME("(%p)->(%d %d %d): stub\n", iface
, image
, cx
, cy
);
3671 static HRESULT WINAPI
ImageListImpl_SetCallback(IImageList2
*iface
, IUnknown
*callback
)
3673 FIXME("(%p)->(%p): stub\n", iface
, callback
);
3677 static HRESULT WINAPI
ImageListImpl_GetCallback(IImageList2
*iface
, REFIID riid
, void **ppv
)
3679 FIXME("(%p)->(%s %p): stub\n", iface
, debugstr_guid(riid
), ppv
);
3683 static HRESULT WINAPI
ImageListImpl_ForceImagePresent(IImageList2
*iface
, INT image
, DWORD flags
)
3685 FIXME("(%p)->(%d %x): stub\n", iface
, image
, flags
);
3689 static HRESULT WINAPI
ImageListImpl_DiscardImages(IImageList2
*iface
, INT first_image
, INT last_image
, DWORD flags
)
3691 FIXME("(%p)->(%d %d %x): stub\n", iface
, first_image
, last_image
, flags
);
3695 static HRESULT WINAPI
ImageListImpl_PreloadImages(IImageList2
*iface
, IMAGELISTDRAWPARAMS
*params
)
3697 FIXME("(%p)->(%p): stub\n", iface
, params
);
3701 static HRESULT WINAPI
ImageListImpl_GetStatistics(IImageList2
*iface
, IMAGELISTSTATS
*stats
)
3703 FIXME("(%p)->(%p): stub\n", iface
, stats
);
3707 static HRESULT WINAPI
ImageListImpl_Initialize(IImageList2
*iface
, INT cx
, INT cy
, UINT flags
, INT initial
, INT grow
)
3709 FIXME("(%p)->(%d %d %d %d %d): stub\n", iface
, cx
, cy
, flags
, initial
, grow
);
3713 static HRESULT WINAPI
ImageListImpl_Replace2(IImageList2
*iface
, INT i
, HBITMAP image
, HBITMAP mask
, IUnknown
*unk
, DWORD flags
)
3715 FIXME("(%p)->(%d %p %p %p %x): stub\n", iface
, i
, image
, mask
, unk
, flags
);
3719 static HRESULT WINAPI
ImageListImpl_ReplaceFromImageList(IImageList2
*iface
, INT i
, IImageList
*imagelist
, INT src
,
3720 IUnknown
*unk
, DWORD flags
)
3722 FIXME("(%p)->(%d %p %d %p %x): stub\n", iface
, i
, imagelist
, src
, unk
, flags
);
3726 static const IImageList2Vtbl ImageListImpl_Vtbl
= {
3727 ImageListImpl_QueryInterface
,
3728 ImageListImpl_AddRef
,
3729 ImageListImpl_Release
,
3731 ImageListImpl_ReplaceIcon
,
3732 ImageListImpl_SetOverlayImage
,
3733 ImageListImpl_Replace
,
3734 ImageListImpl_AddMasked
,
3736 ImageListImpl_Remove
,
3737 ImageListImpl_GetIcon
,
3738 ImageListImpl_GetImageInfo
,
3740 ImageListImpl_Merge
,
3741 ImageListImpl_Clone
,
3742 ImageListImpl_GetImageRect
,
3743 ImageListImpl_GetIconSize
,
3744 ImageListImpl_SetIconSize
,
3745 ImageListImpl_GetImageCount
,
3746 ImageListImpl_SetImageCount
,
3747 ImageListImpl_SetBkColor
,
3748 ImageListImpl_GetBkColor
,
3749 ImageListImpl_BeginDrag
,
3750 ImageListImpl_EndDrag
,
3751 ImageListImpl_DragEnter
,
3752 ImageListImpl_DragLeave
,
3753 ImageListImpl_DragMove
,
3754 ImageListImpl_SetDragCursorImage
,
3755 ImageListImpl_DragShowNolock
,
3756 ImageListImpl_GetDragImage
,
3757 ImageListImpl_GetItemFlags
,
3758 ImageListImpl_GetOverlayImage
,
3759 ImageListImpl_Resize
,
3760 ImageListImpl_GetOriginalSize
,
3761 ImageListImpl_SetOriginalSize
,
3762 ImageListImpl_SetCallback
,
3763 ImageListImpl_GetCallback
,
3764 ImageListImpl_ForceImagePresent
,
3765 ImageListImpl_DiscardImages
,
3766 ImageListImpl_PreloadImages
,
3767 ImageListImpl_GetStatistics
,
3768 ImageListImpl_Initialize
,
3769 ImageListImpl_Replace2
,
3770 ImageListImpl_ReplaceFromImageList
3773 static BOOL
is_valid(HIMAGELIST himl
)
3778 valid
= himl
&& himl
->IImageList2_iface
.lpVtbl
== &ImageListImpl_Vtbl
;
3788 /*************************************************************************
3789 * HIMAGELIST_QueryInterface [COMCTL32.@]
3791 * Returns a pointer to an IImageList or IImageList2 object for the given
3795 * himl [I] Image list handle.
3796 * riid [I] Identifier of the requested interface.
3797 * ppv [O] Returns the address of the pointer requested, or NULL.
3801 * Failure: Error value.
3804 HIMAGELIST_QueryInterface (HIMAGELIST himl
, REFIID riid
, void **ppv
)
3806 TRACE("(%p,%s,%p)\n", himl
, debugstr_guid(riid
), ppv
);
3807 return IImageList2_QueryInterface((IImageList2
*) himl
, riid
, ppv
);
3810 static HRESULT
ImageListImpl_CreateInstance(const IUnknown
*pUnkOuter
, REFIID iid
, void** ppv
)
3815 TRACE("(%p,%s,%p)\n", pUnkOuter
, debugstr_guid(iid
), ppv
);
3819 if (pUnkOuter
) return CLASS_E_NOAGGREGATION
;
3821 This
= heap_alloc_zero(sizeof(struct _IMAGELIST
));
3822 if (!This
) return E_OUTOFMEMORY
;
3824 This
->IImageList2_iface
.lpVtbl
= &ImageListImpl_Vtbl
;
3827 ret
= IImageList2_QueryInterface(&This
->IImageList2_iface
, iid
, ppv
);
3828 IImageList2_Release(&This
->IImageList2_iface
);