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_PRESERVEALPHA, ILD_SCALE, ILD_DPISCALE
27 * - Add support for ILS_GLOW, ILS_SHADOW, ILS_SATURATE
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 static inline UINT
imagelist_height( UINT count
)
148 return ((count
+ TILE_COUNT
- 1)/TILE_COUNT
);
151 static inline void imagelist_point_from_index( HIMAGELIST himl
, UINT index
, LPPOINT pt
)
153 pt
->x
= (index
%TILE_COUNT
) * himl
->cx
;
154 pt
->y
= (index
/TILE_COUNT
) * himl
->cy
;
157 static inline void imagelist_get_bitmap_size( HIMAGELIST himl
, UINT count
, SIZE
*sz
)
159 sz
->cx
= himl
->cx
* TILE_COUNT
;
160 sz
->cy
= imagelist_height( count
) * himl
->cy
;
163 static inline int get_dib_stride( int width
, int bpp
)
165 return ((width
* bpp
+ 31) >> 3) & ~3;
168 static inline int get_dib_image_size( const BITMAPINFO
*info
)
170 return get_dib_stride( info
->bmiHeader
.biWidth
, info
->bmiHeader
.biBitCount
)
171 * abs( info
->bmiHeader
.biHeight
);
175 * imagelist_copy_images()
177 * Copies a block of count images from offset src in the list to offset dest.
178 * Images are copied a row at at time. Assumes hdcSrc and hdcDest are different.
180 static inline void imagelist_copy_images( HIMAGELIST himl
, HDC hdcSrc
, HDC hdcDest
,
181 UINT src
, UINT count
, UINT dest
)
187 for ( i
=0; i
<TILE_COUNT
; i
++ )
189 imagelist_point_from_index( himl
, src
+i
, &ptSrc
);
190 imagelist_point_from_index( himl
, dest
+i
, &ptDest
);
192 sz
.cy
= himl
->cy
* imagelist_height( count
- i
);
194 BitBlt( hdcDest
, ptDest
.x
, ptDest
.y
, sz
.cx
, sz
.cy
,
195 hdcSrc
, ptSrc
.x
, ptSrc
.y
, SRCCOPY
);
199 static void add_dib_bits( HIMAGELIST himl
, int pos
, int count
, int width
, int height
,
200 BITMAPINFO
*info
, BITMAPINFO
*mask_info
, DWORD
*bits
, BYTE
*mask_bits
)
204 int stride
= info
->bmiHeader
.biWidth
;
205 int mask_stride
= (info
->bmiHeader
.biWidth
+ 31) / 32 * 4;
207 for (n
= 0; n
< count
; n
++)
209 BOOL has_alpha
= FALSE
;
211 imagelist_point_from_index( himl
, pos
+ n
, &pt
);
213 /* check if bitmap has an alpha channel */
214 for (i
= 0; i
< height
&& !has_alpha
; i
++)
215 for (j
= n
* width
; j
< (n
+ 1) * width
; j
++)
216 if ((has_alpha
= ((bits
[i
* stride
+ j
] & 0xff000000) != 0))) break;
218 if (!has_alpha
) /* generate alpha channel from the mask */
220 for (i
= 0; i
< height
; i
++)
221 for (j
= n
* width
; j
< (n
+ 1) * width
; j
++)
222 if (!mask_info
|| !((mask_bits
[i
* mask_stride
+ j
/ 8] << (j
% 8)) & 0x80))
223 bits
[i
* stride
+ j
] |= 0xff000000;
225 bits
[i
* stride
+ j
] = 0;
229 himl
->has_alpha
[pos
+ n
] = 1;
231 if (mask_info
&& himl
->hbmMask
) /* generate the mask from the alpha channel */
233 for (i
= 0; i
< height
; i
++)
234 for (j
= n
* width
; j
< (n
+ 1) * width
; j
++)
235 if ((bits
[i
* stride
+ j
] >> 24) > 25) /* more than 10% alpha */
236 mask_bits
[i
* mask_stride
+ j
/ 8] &= ~(0x80 >> (j
% 8));
238 mask_bits
[i
* mask_stride
+ j
/ 8] |= 0x80 >> (j
% 8);
241 StretchDIBits( himl
->hdcImage
, pt
.x
, pt
.y
, himl
->cx
, himl
->cy
,
242 n
* width
, 0, width
, height
, bits
, info
, DIB_RGB_COLORS
, SRCCOPY
);
244 StretchDIBits( himl
->hdcMask
, pt
.x
, pt
.y
, himl
->cx
, himl
->cy
,
245 n
* width
, 0, width
, height
, mask_bits
, mask_info
, DIB_RGB_COLORS
, SRCCOPY
);
249 /* add images with an alpha channel when the image list is 32 bpp */
250 static BOOL
add_with_alpha( HIMAGELIST himl
, HDC hdc
, int pos
, int count
,
251 int width
, int height
, HBITMAP hbmImage
, HBITMAP hbmMask
)
255 BITMAPINFO
*info
, *mask_info
= NULL
;
257 BYTE
*mask_bits
= NULL
;
260 if (!GetObjectW( hbmImage
, sizeof(bm
), &bm
)) return FALSE
;
262 /* if either the imagelist or the source bitmap don't have an alpha channel, bail out now */
263 if (!himl
->has_alpha
) return FALSE
;
264 if (bm
.bmBitsPixel
!= 32) return FALSE
;
266 SelectObject( hdc
, hbmImage
);
267 mask_width
= (bm
.bmWidth
+ 31) / 32 * 4;
269 if (!(info
= heap_alloc( FIELD_OFFSET( BITMAPINFO
, bmiColors
[256] )))) goto done
;
270 info
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
271 info
->bmiHeader
.biWidth
= bm
.bmWidth
;
272 info
->bmiHeader
.biHeight
= -height
;
273 info
->bmiHeader
.biPlanes
= 1;
274 info
->bmiHeader
.biBitCount
= 32;
275 info
->bmiHeader
.biCompression
= BI_RGB
;
276 info
->bmiHeader
.biSizeImage
= bm
.bmWidth
* height
* 4;
277 info
->bmiHeader
.biXPelsPerMeter
= 0;
278 info
->bmiHeader
.biYPelsPerMeter
= 0;
279 info
->bmiHeader
.biClrUsed
= 0;
280 info
->bmiHeader
.biClrImportant
= 0;
281 if (!(bits
= heap_alloc( info
->bmiHeader
.biSizeImage
))) goto done
;
282 if (!GetDIBits( hdc
, hbmImage
, 0, height
, bits
, info
, DIB_RGB_COLORS
)) goto done
;
286 if (!(mask_info
= heap_alloc( FIELD_OFFSET( BITMAPINFO
, bmiColors
[2] ))))
288 mask_info
->bmiHeader
= info
->bmiHeader
;
289 mask_info
->bmiHeader
.biBitCount
= 1;
290 mask_info
->bmiHeader
.biSizeImage
= mask_width
* height
;
291 if (!(mask_bits
= heap_alloc_zero( mask_info
->bmiHeader
.biSizeImage
)))
293 if (!GetDIBits( hdc
, hbmMask
, 0, height
, mask_bits
, mask_info
, DIB_RGB_COLORS
)) goto done
;
296 add_dib_bits( himl
, pos
, count
, width
, height
, info
, mask_info
, bits
, mask_bits
);
301 heap_free( mask_info
);
303 heap_free( mask_bits
);
308 ImageList_SetColorTable(HIMAGELIST himl
, UINT uStartIndex
, UINT cEntries
, const RGBQUAD
*prgb
);
310 /*************************************************************************
311 * IMAGELIST_InternalExpandBitmaps [Internal]
313 * Expands the bitmaps of an image list by the given number of images.
316 * himl [I] handle to image list
317 * nImageCount [I] number of images to add
323 * This function CANNOT be used to reduce the number of images.
326 IMAGELIST_InternalExpandBitmaps(HIMAGELIST himl
, INT nImageCount
)
329 HBITMAP hbmNewBitmap
, hbmNull
;
333 TRACE("%p has allocated %d, max %d, grow %d images\n", himl
, himl
->cCurImage
, himl
->cMaxImage
, himl
->cGrow
);
335 if (himl
->cCurImage
+ nImageCount
< himl
->cMaxImage
)
338 nNewCount
= himl
->cMaxImage
+ max(nImageCount
, himl
->cGrow
) + 1;
340 imagelist_get_bitmap_size(himl
, nNewCount
, &sz
);
342 TRACE("Create expanded bitmaps : himl=%p x=%d y=%d count=%d\n", himl
, sz
.cx
, sz
.cy
, nNewCount
);
343 hdcBitmap
= CreateCompatibleDC (0);
345 hbmNewBitmap
= ImageList_CreateImage(hdcBitmap
, himl
, nNewCount
);
347 if (hbmNewBitmap
== 0)
348 ERR("creating new image bitmap (x=%d y=%d)!\n", sz
.cx
, sz
.cy
);
352 hbmNull
= SelectObject (hdcBitmap
, hbmNewBitmap
);
353 BitBlt (hdcBitmap
, 0, 0, sz
.cx
, sz
.cy
,
354 himl
->hdcImage
, 0, 0, SRCCOPY
);
355 SelectObject (hdcBitmap
, hbmNull
);
357 SelectObject (himl
->hdcImage
, hbmNewBitmap
);
358 DeleteObject (himl
->hbmImage
);
359 himl
->hbmImage
= hbmNewBitmap
;
361 if (himl
->flags
& ILC_MASK
)
363 hbmNewBitmap
= CreateBitmap (sz
.cx
, sz
.cy
, 1, 1, NULL
);
365 if (hbmNewBitmap
== 0)
366 ERR("creating new mask bitmap!\n");
370 hbmNull
= SelectObject (hdcBitmap
, hbmNewBitmap
);
371 BitBlt (hdcBitmap
, 0, 0, sz
.cx
, sz
.cy
,
372 himl
->hdcMask
, 0, 0, SRCCOPY
);
373 SelectObject (hdcBitmap
, hbmNull
);
375 SelectObject (himl
->hdcMask
, hbmNewBitmap
);
376 DeleteObject (himl
->hbmMask
);
377 himl
->hbmMask
= hbmNewBitmap
;
382 char *new_alpha
= HeapReAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, himl
->has_alpha
, nNewCount
);
383 if (new_alpha
) himl
->has_alpha
= new_alpha
;
386 heap_free( himl
->has_alpha
);
387 himl
->has_alpha
= NULL
;
391 himl
->cMaxImage
= nNewCount
;
393 DeleteDC (hdcBitmap
);
397 /*************************************************************************
398 * ImageList_Add [COMCTL32.@]
400 * Add an image or images to an image list.
403 * himl [I] handle to image list
404 * hbmImage [I] handle to image bitmap
405 * hbmMask [I] handle to mask bitmap
408 * Success: Index of the first new image.
413 ImageList_Add (HIMAGELIST himl
, HBITMAP hbmImage
, HBITMAP hbmMask
)
415 HDC hdcBitmap
, hdcTemp
= 0;
416 INT nFirstIndex
, nImageCount
, i
;
420 TRACE("himl=%p hbmimage=%p hbmmask=%p\n", himl
, hbmImage
, hbmMask
);
424 if (!GetObjectW(hbmImage
, sizeof(BITMAP
), &bmp
))
427 TRACE("himl %p, cCurImage %d, cMaxImage %d, cGrow %d, cx %d, cy %d\n",
428 himl
, himl
->cCurImage
, himl
->cMaxImage
, himl
->cGrow
, himl
->cx
, himl
->cy
);
430 nImageCount
= bmp
.bmWidth
/ himl
->cx
;
432 TRACE("%p has %d images (%d x %d) bpp %d\n", hbmImage
, nImageCount
, bmp
.bmWidth
, bmp
.bmHeight
,
435 IMAGELIST_InternalExpandBitmaps(himl
, nImageCount
);
437 hdcBitmap
= CreateCompatibleDC(0);
439 SelectObject(hdcBitmap
, hbmImage
);
441 if (add_with_alpha( himl
, hdcBitmap
, himl
->cCurImage
, nImageCount
,
442 himl
->cx
, min( himl
->cy
, bmp
.bmHeight
), hbmImage
, hbmMask
))
447 hdcTemp
= CreateCompatibleDC(0);
448 SelectObject(hdcTemp
, hbmMask
);
451 if (himl
->uBitsPixel
<= 8 && bmp
.bmBitsPixel
<= 8 &&
452 !himl
->color_table_set
&& himl
->cCurImage
== 0)
455 UINT num
= GetDIBColorTable( hdcBitmap
, 0, 1 << bmp
.bmBitsPixel
, colors
);
456 if (num
) ImageList_SetColorTable( himl
, 0, num
, colors
);
459 for (i
=0; i
<nImageCount
; i
++)
461 imagelist_point_from_index( himl
, himl
->cCurImage
+ i
, &pt
);
463 /* Copy result to the imagelist
465 BitBlt( himl
->hdcImage
, pt
.x
, pt
.y
, himl
->cx
, bmp
.bmHeight
,
466 hdcBitmap
, i
*himl
->cx
, 0, SRCCOPY
);
471 BitBlt( himl
->hdcMask
, pt
.x
, pt
.y
, himl
->cx
, bmp
.bmHeight
,
472 hdcTemp
, i
*himl
->cx
, 0, SRCCOPY
);
474 /* Remove the background from the image
476 BitBlt( himl
->hdcImage
, pt
.x
, pt
.y
, himl
->cx
, bmp
.bmHeight
,
477 himl
->hdcMask
, pt
.x
, pt
.y
, 0x220326 ); /* NOTSRCAND */
479 if (hdcTemp
) DeleteDC(hdcTemp
);
484 nFirstIndex
= himl
->cCurImage
;
485 himl
->cCurImage
+= nImageCount
;
491 /*************************************************************************
492 * ImageList_AddIcon [COMCTL32.@]
494 * Adds an icon to an image list.
497 * himl [I] handle to image list
498 * hIcon [I] handle to icon
501 * Success: index of the new image
504 #undef ImageList_AddIcon
505 INT WINAPI
ImageList_AddIcon (HIMAGELIST himl
, HICON hIcon
)
507 return ImageList_ReplaceIcon (himl
, -1, hIcon
);
511 /*************************************************************************
512 * ImageList_AddMasked [COMCTL32.@]
514 * Adds an image or images to an image list and creates a mask from the
515 * specified bitmap using the mask color.
518 * himl [I] handle to image list.
519 * hBitmap [I] handle to bitmap
520 * clrMask [I] mask color.
523 * Success: Index of the first new image.
528 ImageList_AddMasked (HIMAGELIST himl
, HBITMAP hBitmap
, COLORREF clrMask
)
530 HDC hdcMask
, hdcBitmap
;
536 TRACE("himl=%p hbitmap=%p clrmask=%x\n", himl
, hBitmap
, clrMask
);
540 if (!GetObjectW(hBitmap
, sizeof(BITMAP
), &bmp
))
543 hdcBitmap
= CreateCompatibleDC(0);
544 SelectObject(hdcBitmap
, hBitmap
);
546 /* Create a temp Mask so we can remove the background of the Image */
547 hdcMask
= CreateCompatibleDC(0);
548 hMaskBitmap
= CreateBitmap(bmp
.bmWidth
, bmp
.bmHeight
, 1, 1, NULL
);
549 SelectObject(hdcMask
, hMaskBitmap
);
551 /* create monochrome image to the mask bitmap */
552 bkColor
= (clrMask
!= CLR_DEFAULT
) ? clrMask
: GetPixel (hdcBitmap
, 0, 0);
553 SetBkColor (hdcBitmap
, bkColor
);
554 BitBlt (hdcMask
, 0, 0, bmp
.bmWidth
, bmp
.bmHeight
, hdcBitmap
, 0, 0, SRCCOPY
);
557 * Remove the background from the image
559 * WINDOWS BUG ALERT!!!!!!
560 * The statement below should not be done in common practice
561 * but this is how ImageList_AddMasked works in Windows.
562 * It overwrites the original bitmap passed, this was discovered
563 * by using the same bitmap to iterate the different styles
564 * on windows where it failed (BUT ImageList_Add is OK)
565 * This is here in case some apps rely on this bug
567 * Blt mode 0x220326 is NOTSRCAND
569 if (bmp
.bmBitsPixel
> 8) /* NOTSRCAND can't work with palettes */
571 SetBkColor(hdcBitmap
, RGB(255,255,255));
572 BitBlt(hdcBitmap
, 0, 0, bmp
.bmWidth
, bmp
.bmHeight
, hdcMask
, 0, 0, 0x220326);
578 ret
= ImageList_Add( himl
, hBitmap
, hMaskBitmap
);
580 DeleteObject(hMaskBitmap
);
585 /*************************************************************************
586 * ImageList_BeginDrag [COMCTL32.@]
588 * Creates a temporary image list that contains one image. It will be used
592 * himlTrack [I] handle to the source image list
593 * iTrack [I] index of the drag image in the source image list
594 * dxHotspot [I] X position of the hot spot of the drag image
595 * dyHotspot [I] Y position of the hot spot of the drag image
603 ImageList_BeginDrag (HIMAGELIST himlTrack
, INT iTrack
,
604 INT dxHotspot
, INT dyHotspot
)
609 TRACE("(himlTrack=%p iTrack=%d dx=%d dy=%d)\n", himlTrack
, iTrack
,
610 dxHotspot
, dyHotspot
);
612 if (!is_valid(himlTrack
))
615 if (iTrack
>= himlTrack
->cCurImage
)
618 if (InternalDrag
.himl
)
624 InternalDrag
.himlNoCursor
= InternalDrag
.himl
= ImageList_Create (cx
, cy
, himlTrack
->flags
, 1, 1);
625 if (InternalDrag
.himl
== NULL
) {
626 WARN("Error creating drag image list!\n");
630 InternalDrag
.dxHotspot
= dxHotspot
;
631 InternalDrag
.dyHotspot
= dyHotspot
;
634 imagelist_point_from_index(InternalDrag
.himl
, 0, &dst
);
635 imagelist_point_from_index(himlTrack
, iTrack
, &src
);
636 BitBlt(InternalDrag
.himl
->hdcImage
, dst
.x
, dst
.y
, cx
, cy
, himlTrack
->hdcImage
, src
.x
, src
.y
,
638 BitBlt(InternalDrag
.himl
->hdcMask
, dst
.x
, dst
.y
, cx
, cy
, himlTrack
->hdcMask
, src
.x
, src
.y
,
641 InternalDrag
.himl
->cCurImage
= 1;
647 /*************************************************************************
648 * ImageList_Copy [COMCTL32.@]
650 * Copies an image of the source image list to an image of the
651 * destination image list. Images can be copied or swapped.
654 * himlDst [I] handle to the destination image list
655 * iDst [I] destination image index.
656 * himlSrc [I] handle to the source image list
657 * iSrc [I] source image index
658 * uFlags [I] flags for the copy operation
665 * Copying from one image list to another is possible. The original
666 * implementation just copies or swaps within one image list.
667 * Could this feature become a bug??? ;-)
671 ImageList_Copy (HIMAGELIST himlDst
, INT iDst
, HIMAGELIST himlSrc
,
672 INT iSrc
, UINT uFlags
)
676 TRACE("himlDst=%p iDst=%d himlSrc=%p iSrc=%d\n", himlDst
, iDst
, himlSrc
, iSrc
);
678 if (!is_valid(himlSrc
) || !is_valid(himlDst
))
680 if ((iDst
< 0) || (iDst
>= himlDst
->cCurImage
))
682 if ((iSrc
< 0) || (iSrc
>= himlSrc
->cCurImage
))
685 imagelist_point_from_index( himlDst
, iDst
, &ptDst
);
686 imagelist_point_from_index( himlSrc
, iSrc
, &ptSrc
);
688 if (uFlags
& ILCF_SWAP
) {
691 HBITMAP hbmTempImage
, hbmTempMask
;
693 hdcBmp
= CreateCompatibleDC (0);
695 /* create temporary bitmaps */
696 hbmTempImage
= CreateBitmap (himlSrc
->cx
, himlSrc
->cy
, 1,
697 himlSrc
->uBitsPixel
, NULL
);
698 hbmTempMask
= CreateBitmap (himlSrc
->cx
, himlSrc
->cy
, 1,
701 /* copy (and stretch) destination to temporary bitmaps.(save) */
703 SelectObject (hdcBmp
, hbmTempImage
);
704 StretchBlt (hdcBmp
, 0, 0, himlSrc
->cx
, himlSrc
->cy
,
705 himlDst
->hdcImage
, ptDst
.x
, ptDst
.y
, himlDst
->cx
, himlDst
->cy
,
708 SelectObject (hdcBmp
, hbmTempMask
);
709 StretchBlt (hdcBmp
, 0, 0, himlSrc
->cx
, himlSrc
->cy
,
710 himlDst
->hdcMask
, ptDst
.x
, ptDst
.y
, himlDst
->cx
, himlDst
->cy
,
713 /* copy (and stretch) source to destination */
715 StretchBlt (himlDst
->hdcImage
, ptDst
.x
, ptDst
.y
, himlDst
->cx
, himlDst
->cy
,
716 himlSrc
->hdcImage
, ptSrc
.x
, ptSrc
.y
, himlSrc
->cx
, himlSrc
->cy
,
719 StretchBlt (himlDst
->hdcMask
, ptDst
.x
, ptDst
.y
, himlDst
->cx
, himlDst
->cy
,
720 himlSrc
->hdcMask
, ptSrc
.x
, ptSrc
.y
, himlSrc
->cx
, himlSrc
->cy
,
723 /* copy (without stretching) temporary bitmaps to source (restore) */
725 BitBlt (himlSrc
->hdcMask
, ptSrc
.x
, ptSrc
.y
, himlSrc
->cx
, himlSrc
->cy
,
726 hdcBmp
, 0, 0, SRCCOPY
);
729 BitBlt (himlSrc
->hdcImage
, ptSrc
.x
, ptSrc
.y
, himlSrc
->cx
, himlSrc
->cy
,
730 hdcBmp
, 0, 0, SRCCOPY
);
731 /* delete temporary bitmaps */
732 DeleteObject (hbmTempMask
);
733 DeleteObject (hbmTempImage
);
738 StretchBlt (himlDst
->hdcImage
, ptDst
.x
, ptDst
.y
, himlDst
->cx
, himlDst
->cy
,
739 himlSrc
->hdcImage
, ptSrc
.x
, ptSrc
.y
, himlSrc
->cx
, himlSrc
->cy
,
743 StretchBlt (himlDst
->hdcMask
, ptDst
.x
, ptDst
.y
, himlDst
->cx
, himlDst
->cy
,
744 himlSrc
->hdcMask
, ptSrc
.x
, ptSrc
.y
, himlSrc
->cx
, himlSrc
->cy
,
752 /*************************************************************************
753 * ImageList_Create [COMCTL32.@]
755 * Creates a new image list.
758 * cx [I] image height
760 * flags [I] creation flags
761 * cInitial [I] initial number of images in the image list
762 * cGrow [I] number of images by which image list grows
765 * Success: Handle to the created image list
769 ImageList_Create (INT cx
, INT cy
, UINT flags
,
770 INT cInitial
, INT cGrow
)
775 UINT ilc
= (flags
& 0xFE);
776 static const WORD aBitBlend25
[] =
777 {0xAA, 0x00, 0x55, 0x00, 0xAA, 0x00, 0x55, 0x00};
779 static const WORD aBitBlend50
[] =
780 {0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA};
782 TRACE("(%d %d 0x%x %d %d)\n", cx
, cy
, flags
, cInitial
, cGrow
);
784 if (cx
< 0 || cy
< 0) return NULL
;
785 if (!((flags
&ILC_COLORDDB
) == ILC_COLORDDB
) && (cx
== 0 || cy
== 0)) return NULL
;
787 /* Create the IImageList interface for the image list */
788 if (FAILED(ImageListImpl_CreateInstance(NULL
, &IID_IImageList
, (void **)&himl
)))
791 cGrow
= (WORD
)((max( cGrow
, 1 ) + 3) & ~3);
795 /* Windows doesn't limit the size here, but X11 doesn't let us allocate such huge bitmaps */
796 WARN( "grow %d too large, limiting to 256\n", cGrow
);
803 himl
->cMaxImage
= cInitial
+ 1;
804 himl
->cInitial
= cInitial
;
806 himl
->clrFg
= CLR_DEFAULT
;
807 himl
->clrBk
= CLR_NONE
;
808 himl
->color_table_set
= FALSE
;
810 /* initialize overlay mask indices */
811 for (nCount
= 0; nCount
< MAX_OVERLAYIMAGE
; nCount
++)
812 himl
->nOvlIdx
[nCount
] = -1;
814 /* Create Image & Mask DCs */
815 himl
->hdcImage
= CreateCompatibleDC (0);
818 if (himl
->flags
& ILC_MASK
){
819 himl
->hdcMask
= CreateCompatibleDC(0);
824 /* Default to ILC_COLOR4 if none of the ILC_COLOR* flags are specified */
825 if (ilc
== ILC_COLOR
)
828 himl
->flags
|= ILC_COLOR4
;
831 if (ilc
>= ILC_COLOR4
&& ilc
<= ILC_COLOR32
)
832 himl
->uBitsPixel
= ilc
;
834 himl
->uBitsPixel
= (UINT
)GetDeviceCaps (himl
->hdcImage
, BITSPIXEL
);
836 if (himl
->cMaxImage
> 0) {
837 himl
->hbmImage
= ImageList_CreateImage(himl
->hdcImage
, himl
, himl
->cMaxImage
);
838 SelectObject(himl
->hdcImage
, himl
->hbmImage
);
842 if ((himl
->cMaxImage
> 0) && (himl
->flags
& ILC_MASK
)) {
845 imagelist_get_bitmap_size(himl
, himl
->cMaxImage
, &sz
);
846 himl
->hbmMask
= CreateBitmap (sz
.cx
, sz
.cy
, 1, 1, NULL
);
847 if (himl
->hbmMask
== 0) {
848 ERR("Error creating mask bitmap!\n");
851 SelectObject(himl
->hdcMask
, himl
->hbmMask
);
856 if (ilc
== ILC_COLOR32
)
857 himl
->has_alpha
= heap_alloc_zero( himl
->cMaxImage
);
859 himl
->has_alpha
= NULL
;
861 /* create blending brushes */
862 hbmTemp
= CreateBitmap (8, 8, 1, 1, aBitBlend25
);
863 himl
->hbrBlend25
= CreatePatternBrush (hbmTemp
);
864 DeleteObject (hbmTemp
);
866 hbmTemp
= CreateBitmap (8, 8, 1, 1, aBitBlend50
);
867 himl
->hbrBlend50
= CreatePatternBrush (hbmTemp
);
868 DeleteObject (hbmTemp
);
870 TRACE("created imagelist %p\n", himl
);
874 ImageList_Destroy(himl
);
879 /*************************************************************************
880 * ImageList_Destroy [COMCTL32.@]
882 * Destroys an image list.
885 * himl [I] handle to image list
893 ImageList_Destroy (HIMAGELIST himl
)
898 IImageList_Release((IImageList
*) himl
);
903 /*************************************************************************
904 * ImageList_DragEnter [COMCTL32.@]
906 * Locks window update and displays the drag image at the given position.
909 * hwndLock [I] handle of the window that owns the drag image.
910 * x [I] X position of the drag image.
911 * y [I] Y position of the drag image.
918 * The position of the drag image is relative to the window, not
923 ImageList_DragEnter (HWND hwndLock
, INT x
, INT y
)
925 TRACE("(hwnd=%p x=%d y=%d)\n", hwndLock
, x
, y
);
927 if (!is_valid(InternalDrag
.himl
))
931 InternalDrag
.hwnd
= hwndLock
;
933 InternalDrag
.hwnd
= GetDesktopWindow ();
938 /* draw the drag image and save the background */
939 return ImageList_DragShowNolock(TRUE
);
943 /*************************************************************************
944 * ImageList_DragLeave [COMCTL32.@]
946 * Unlocks window update and hides the drag image.
949 * hwndLock [I] handle of the window that owns the drag image.
957 ImageList_DragLeave (HWND hwndLock
)
959 /* As we don't save drag info in the window this can lead to problems if
960 an app does not supply the same window as DragEnter */
962 InternalDrag.hwnd = hwndLock;
964 InternalDrag.hwnd = GetDesktopWindow (); */
966 hwndLock
= GetDesktopWindow();
967 if(InternalDrag
.hwnd
!= hwndLock
)
968 FIXME("DragLeave hWnd != DragEnter hWnd\n");
970 ImageList_DragShowNolock (FALSE
);
976 /*************************************************************************
977 * ImageList_InternalDragDraw [Internal]
979 * Draws the drag image.
982 * hdc [I] device context to draw into.
983 * x [I] X position of the drag image.
984 * y [I] Y position of the drag image.
991 * The position of the drag image is relative to the window, not
997 ImageList_InternalDragDraw (HDC hdc
, INT x
, INT y
)
999 IMAGELISTDRAWPARAMS imldp
;
1001 ZeroMemory (&imldp
, sizeof(imldp
));
1002 imldp
.cbSize
= sizeof(imldp
);
1003 imldp
.himl
= InternalDrag
.himl
;
1008 imldp
.rgbBk
= CLR_DEFAULT
;
1009 imldp
.rgbFg
= CLR_DEFAULT
;
1010 imldp
.fStyle
= ILD_NORMAL
;
1011 imldp
.fState
= ILS_ALPHA
;
1013 ImageList_DrawIndirect (&imldp
);
1016 /*************************************************************************
1017 * ImageList_DragMove [COMCTL32.@]
1019 * Moves the drag image.
1022 * x [I] X position of the drag image.
1023 * y [I] Y position of the drag image.
1030 * The position of the drag image is relative to the window, not
1035 ImageList_DragMove (INT x
, INT y
)
1037 TRACE("(x=%d y=%d)\n", x
, y
);
1039 if (!is_valid(InternalDrag
.himl
))
1042 /* draw/update the drag image */
1043 if (InternalDrag
.bShow
) {
1047 HBITMAP hbmOffScreen
;
1048 INT origNewX
, origNewY
;
1049 INT origOldX
, origOldY
;
1050 INT origRegX
, origRegY
;
1051 INT sizeRegX
, sizeRegY
;
1054 /* calculate the update region */
1055 origNewX
= x
- InternalDrag
.dxHotspot
;
1056 origNewY
= y
- InternalDrag
.dyHotspot
;
1057 origOldX
= InternalDrag
.x
- InternalDrag
.dxHotspot
;
1058 origOldY
= InternalDrag
.y
- InternalDrag
.dyHotspot
;
1059 origRegX
= min(origNewX
, origOldX
);
1060 origRegY
= min(origNewY
, origOldY
);
1061 sizeRegX
= InternalDrag
.himl
->cx
+ abs(x
- InternalDrag
.x
);
1062 sizeRegY
= InternalDrag
.himl
->cy
+ abs(y
- InternalDrag
.y
);
1064 hdcDrag
= GetDCEx(InternalDrag
.hwnd
, 0,
1065 DCX_WINDOW
| DCX_CACHE
| DCX_LOCKWINDOWUPDATE
);
1066 hdcOffScreen
= CreateCompatibleDC(hdcDrag
);
1067 hdcBg
= CreateCompatibleDC(hdcDrag
);
1069 hbmOffScreen
= CreateCompatibleBitmap(hdcDrag
, sizeRegX
, sizeRegY
);
1070 SelectObject(hdcOffScreen
, hbmOffScreen
);
1071 SelectObject(hdcBg
, InternalDrag
.hbmBg
);
1073 /* get the actual background of the update region */
1074 BitBlt(hdcOffScreen
, 0, 0, sizeRegX
, sizeRegY
, hdcDrag
,
1075 origRegX
, origRegY
, SRCCOPY
);
1076 /* erase the old image */
1077 BitBlt(hdcOffScreen
, origOldX
- origRegX
, origOldY
- origRegY
,
1078 InternalDrag
.himl
->cx
, InternalDrag
.himl
->cy
, hdcBg
, 0, 0,
1080 /* save the background */
1081 BitBlt(hdcBg
, 0, 0, InternalDrag
.himl
->cx
, InternalDrag
.himl
->cy
,
1082 hdcOffScreen
, origNewX
- origRegX
, origNewY
- origRegY
, SRCCOPY
);
1083 /* draw the image */
1084 ImageList_InternalDragDraw(hdcOffScreen
, origNewX
- origRegX
,
1085 origNewY
- origRegY
);
1086 /* draw the update region to the screen */
1087 BitBlt(hdcDrag
, origRegX
, origRegY
, sizeRegX
, sizeRegY
,
1088 hdcOffScreen
, 0, 0, SRCCOPY
);
1091 DeleteDC(hdcOffScreen
);
1092 DeleteObject(hbmOffScreen
);
1093 ReleaseDC(InternalDrag
.hwnd
, hdcDrag
);
1096 /* update the image position */
1104 /*************************************************************************
1105 * ImageList_DragShowNolock [COMCTL32.@]
1107 * Shows or hides the drag image.
1110 * bShow [I] TRUE shows the drag image, FALSE hides it.
1118 ImageList_DragShowNolock (BOOL bShow
)
1124 if (!is_valid(InternalDrag
.himl
))
1127 TRACE("bShow=0x%X!\n", bShow
);
1129 /* DragImage is already visible/hidden */
1130 if ((InternalDrag
.bShow
&& bShow
) || (!InternalDrag
.bShow
&& !bShow
)) {
1134 /* position of the origin of the DragImage */
1135 x
= InternalDrag
.x
- InternalDrag
.dxHotspot
;
1136 y
= InternalDrag
.y
- InternalDrag
.dyHotspot
;
1138 hdcDrag
= GetDCEx (InternalDrag
.hwnd
, 0,
1139 DCX_WINDOW
| DCX_CACHE
| DCX_LOCKWINDOWUPDATE
);
1144 hdcBg
= CreateCompatibleDC(hdcDrag
);
1145 if (!InternalDrag
.hbmBg
) {
1146 InternalDrag
.hbmBg
= CreateCompatibleBitmap(hdcDrag
,
1147 InternalDrag
.himl
->cx
, InternalDrag
.himl
->cy
);
1149 SelectObject(hdcBg
, InternalDrag
.hbmBg
);
1152 /* save the background */
1153 BitBlt(hdcBg
, 0, 0, InternalDrag
.himl
->cx
, InternalDrag
.himl
->cy
,
1154 hdcDrag
, x
, y
, SRCCOPY
);
1155 /* show the image */
1156 ImageList_InternalDragDraw(hdcDrag
, x
, y
);
1158 /* hide the image */
1159 BitBlt(hdcDrag
, x
, y
, InternalDrag
.himl
->cx
, InternalDrag
.himl
->cy
,
1160 hdcBg
, 0, 0, SRCCOPY
);
1163 InternalDrag
.bShow
= !InternalDrag
.bShow
;
1166 ReleaseDC (InternalDrag
.hwnd
, hdcDrag
);
1171 /*************************************************************************
1172 * ImageList_Draw [COMCTL32.@]
1177 * himl [I] handle to image list
1179 * hdc [I] handle to device context
1182 * fStyle [I] drawing flags
1193 ImageList_Draw (HIMAGELIST himl
, INT i
, HDC hdc
, INT x
, INT y
, UINT fStyle
)
1195 return ImageList_DrawEx (himl
, i
, hdc
, x
, y
, 0, 0,
1196 CLR_DEFAULT
, CLR_DEFAULT
, fStyle
);
1200 /*************************************************************************
1201 * ImageList_DrawEx [COMCTL32.@]
1203 * Draws an image and allows using extended drawing features.
1206 * himl [I] handle to image list
1208 * hdc [I] handle to device context
1213 * rgbBk [I] background color
1214 * rgbFg [I] foreground color
1215 * fStyle [I] drawing flags
1222 * Calls ImageList_DrawIndirect.
1225 * ImageList_DrawIndirect.
1229 ImageList_DrawEx (HIMAGELIST himl
, INT i
, HDC hdc
, INT x
, INT y
,
1230 INT dx
, INT dy
, COLORREF rgbBk
, COLORREF rgbFg
,
1233 IMAGELISTDRAWPARAMS imldp
;
1235 ZeroMemory (&imldp
, sizeof(imldp
));
1236 imldp
.cbSize
= sizeof(imldp
);
1244 imldp
.rgbBk
= rgbBk
;
1245 imldp
.rgbFg
= rgbFg
;
1246 imldp
.fStyle
= fStyle
;
1248 return ImageList_DrawIndirect (&imldp
);
1252 static BOOL
alpha_blend_image( HIMAGELIST himl
, HDC dest_dc
, int dest_x
, int dest_y
,
1253 int src_x
, int src_y
, int cx
, int cy
, BLENDFUNCTION func
,
1254 UINT style
, COLORREF blend_col
)
1258 HBITMAP bmp
= 0, mask
= 0;
1260 void *bits
, *mask_bits
;
1264 if (!(hdc
= CreateCompatibleDC( 0 ))) return FALSE
;
1265 if (!(info
= heap_alloc( FIELD_OFFSET( BITMAPINFO
, bmiColors
[256] )))) goto done
;
1266 info
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
1267 info
->bmiHeader
.biWidth
= cx
;
1268 info
->bmiHeader
.biHeight
= cy
;
1269 info
->bmiHeader
.biPlanes
= 1;
1270 info
->bmiHeader
.biBitCount
= 32;
1271 info
->bmiHeader
.biCompression
= BI_RGB
;
1272 info
->bmiHeader
.biSizeImage
= cx
* cy
* 4;
1273 info
->bmiHeader
.biXPelsPerMeter
= 0;
1274 info
->bmiHeader
.biYPelsPerMeter
= 0;
1275 info
->bmiHeader
.biClrUsed
= 0;
1276 info
->bmiHeader
.biClrImportant
= 0;
1277 if (!(bmp
= CreateDIBSection( himl
->hdcImage
, info
, DIB_RGB_COLORS
, &bits
, 0, 0 ))) goto done
;
1278 SelectObject( hdc
, bmp
);
1279 BitBlt( hdc
, 0, 0, cx
, cy
, himl
->hdcImage
, src_x
, src_y
, SRCCOPY
);
1281 if (blend_col
!= CLR_NONE
)
1283 BYTE r
= GetRValue( blend_col
);
1284 BYTE g
= GetGValue( blend_col
);
1285 BYTE b
= GetBValue( blend_col
);
1287 if (style
& ILD_BLEND25
)
1289 for (i
= 0, ptr
= bits
; i
< cx
* cy
; i
++, ptr
++)
1290 *ptr
= ((*ptr
& 0xff000000) |
1291 ((((*ptr
& 0x00ff0000) * 3 + (r
<< 16)) / 4) & 0x00ff0000) |
1292 ((((*ptr
& 0x0000ff00) * 3 + (g
<< 8)) / 4) & 0x0000ff00) |
1293 ((((*ptr
& 0x000000ff) * 3 + (b
<< 0)) / 4) & 0x000000ff));
1295 else if (style
& ILD_BLEND50
)
1297 for (i
= 0, ptr
= bits
; i
< cx
* cy
; i
++, ptr
++)
1298 *ptr
= ((*ptr
& 0xff000000) |
1299 ((((*ptr
& 0x00ff0000) + (r
<< 16)) / 2) & 0x00ff0000) |
1300 ((((*ptr
& 0x0000ff00) + (g
<< 8)) / 2) & 0x0000ff00) |
1301 ((((*ptr
& 0x000000ff) + (b
<< 0)) / 2) & 0x000000ff));
1305 if (himl
->has_alpha
) /* we already have an alpha channel in this case */
1307 /* pre-multiply by the alpha channel */
1308 for (i
= 0, ptr
= bits
; i
< cx
* cy
; i
++, ptr
++)
1310 DWORD alpha
= *ptr
>> 24;
1311 *ptr
= ((*ptr
& 0xff000000) |
1312 (((*ptr
& 0x00ff0000) * alpha
/ 255) & 0x00ff0000) |
1313 (((*ptr
& 0x0000ff00) * alpha
/ 255) & 0x0000ff00) |
1314 (((*ptr
& 0x000000ff) * alpha
/ 255)));
1317 else if (himl
->hbmMask
)
1319 unsigned int width_bytes
= (cx
+ 31) / 32 * 4;
1320 /* generate alpha channel from the mask */
1321 info
->bmiHeader
.biBitCount
= 1;
1322 info
->bmiHeader
.biSizeImage
= width_bytes
* cy
;
1323 info
->bmiColors
[0].rgbRed
= 0;
1324 info
->bmiColors
[0].rgbGreen
= 0;
1325 info
->bmiColors
[0].rgbBlue
= 0;
1326 info
->bmiColors
[0].rgbReserved
= 0;
1327 info
->bmiColors
[1].rgbRed
= 0xff;
1328 info
->bmiColors
[1].rgbGreen
= 0xff;
1329 info
->bmiColors
[1].rgbBlue
= 0xff;
1330 info
->bmiColors
[1].rgbReserved
= 0;
1331 if (!(mask
= CreateDIBSection( himl
->hdcMask
, info
, DIB_RGB_COLORS
, &mask_bits
, 0, 0 )))
1333 SelectObject( hdc
, mask
);
1334 BitBlt( hdc
, 0, 0, cx
, cy
, himl
->hdcMask
, src_x
, src_y
, SRCCOPY
);
1335 SelectObject( hdc
, bmp
);
1336 for (i
= 0, ptr
= bits
; i
< cy
; i
++)
1337 for (j
= 0; j
< cx
; j
++, ptr
++)
1338 if ((((BYTE
*)mask_bits
)[i
* width_bytes
+ j
/ 8] << (j
% 8)) & 0x80) *ptr
= 0;
1339 else *ptr
|= 0xff000000;
1342 ret
= GdiAlphaBlend( dest_dc
, dest_x
, dest_y
, cx
, cy
, hdc
, 0, 0, cx
, cy
, func
);
1346 if (bmp
) DeleteObject( bmp
);
1347 if (mask
) DeleteObject( mask
);
1352 /*************************************************************************
1353 * ImageList_DrawIndirect [COMCTL32.@]
1355 * Draws an image using various parameters specified in pimldp.
1358 * pimldp [I] pointer to IMAGELISTDRAWPARAMS structure.
1366 ImageList_DrawIndirect (IMAGELISTDRAWPARAMS
*pimldp
)
1368 INT cx
, cy
, nOvlIdx
;
1369 DWORD fState
, dwRop
;
1371 COLORREF oldImageBk
, oldImageFg
;
1372 HDC hImageDC
, hImageListDC
, hMaskListDC
;
1373 HBITMAP hImageBmp
, hOldImageBmp
, hBlendMaskBmp
;
1374 BOOL bIsTransparent
, bBlend
, bResult
= FALSE
, bMask
;
1380 if (!pimldp
|| !(himl
= pimldp
->himl
)) return FALSE
;
1381 if (!is_valid(himl
)) return FALSE
;
1382 if ((pimldp
->i
< 0) || (pimldp
->i
>= himl
->cCurImage
)) return FALSE
;
1384 imagelist_point_from_index( himl
, pimldp
->i
, &pt
);
1385 pt
.x
+= pimldp
->xBitmap
;
1386 pt
.y
+= pimldp
->yBitmap
;
1388 fState
= pimldp
->cbSize
< sizeof(IMAGELISTDRAWPARAMS
) ? ILS_NORMAL
: pimldp
->fState
;
1389 fStyle
= pimldp
->fStyle
& ~ILD_OVERLAYMASK
;
1390 cx
= (pimldp
->cx
== 0) ? himl
->cx
: pimldp
->cx
;
1391 cy
= (pimldp
->cy
== 0) ? himl
->cy
: pimldp
->cy
;
1393 bIsTransparent
= (fStyle
& ILD_TRANSPARENT
);
1394 if( pimldp
->rgbBk
== CLR_NONE
)
1395 bIsTransparent
= TRUE
;
1396 if( ( pimldp
->rgbBk
== CLR_DEFAULT
) && ( himl
->clrBk
== CLR_NONE
) )
1397 bIsTransparent
= TRUE
;
1398 bMask
= (himl
->flags
& ILC_MASK
) && (fStyle
& ILD_MASK
) ;
1399 bBlend
= (fStyle
& (ILD_BLEND25
| ILD_BLEND50
) ) && !bMask
;
1401 TRACE("himl(%p) hbmMask(%p) iImage(%d) x(%d) y(%d) cx(%d) cy(%d)\n",
1402 himl
, himl
->hbmMask
, pimldp
->i
, pimldp
->x
, pimldp
->y
, cx
, cy
);
1404 /* we will use these DCs to access the images and masks in the ImageList */
1405 hImageListDC
= himl
->hdcImage
;
1406 hMaskListDC
= himl
->hdcMask
;
1408 /* these will accumulate the image and mask for the image we're drawing */
1409 hImageDC
= CreateCompatibleDC( pimldp
->hdcDst
);
1410 hImageBmp
= CreateCompatibleBitmap( pimldp
->hdcDst
, cx
, cy
);
1411 hBlendMaskBmp
= bBlend
? CreateBitmap(cx
, cy
, 1, 1, NULL
) : 0;
1413 /* Create a compatible DC. */
1414 if (!hImageListDC
|| !hImageDC
|| !hImageBmp
||
1415 (bBlend
&& !hBlendMaskBmp
) || (himl
->hbmMask
&& !hMaskListDC
))
1418 hOldImageBmp
= SelectObject(hImageDC
, hImageBmp
);
1421 * To obtain a transparent look, background color should be set
1422 * to white and foreground color to black when blitting the
1425 oldImageFg
= SetTextColor( hImageDC
, RGB( 0, 0, 0 ) );
1426 oldImageBk
= SetBkColor( hImageDC
, RGB( 0xff, 0xff, 0xff ) );
1428 has_alpha
= (himl
->has_alpha
&& himl
->has_alpha
[pimldp
->i
]);
1429 if (!bMask
&& (has_alpha
|| (fState
& ILS_ALPHA
)))
1431 COLORREF colour
, blend_col
= CLR_NONE
;
1436 blend_col
= pimldp
->rgbFg
;
1437 if (blend_col
== CLR_DEFAULT
) blend_col
= GetSysColor( COLOR_HIGHLIGHT
);
1438 else if (blend_col
== CLR_NONE
) blend_col
= GetTextColor( pimldp
->hdcDst
);
1441 func
.BlendOp
= AC_SRC_OVER
;
1442 func
.BlendFlags
= 0;
1443 func
.SourceConstantAlpha
= (fState
& ILS_ALPHA
) ? pimldp
->Frame
: 255;
1444 func
.AlphaFormat
= AC_SRC_ALPHA
;
1448 bResult
= alpha_blend_image( himl
, pimldp
->hdcDst
, pimldp
->x
, pimldp
->y
,
1449 pt
.x
, pt
.y
, cx
, cy
, func
, fStyle
, blend_col
);
1452 colour
= pimldp
->rgbBk
;
1453 if (colour
== CLR_DEFAULT
) colour
= himl
->clrBk
;
1454 if (colour
== CLR_NONE
) colour
= GetBkColor( pimldp
->hdcDst
);
1456 hOldBrush
= SelectObject (hImageDC
, CreateSolidBrush (colour
));
1457 PatBlt( hImageDC
, 0, 0, cx
, cy
, PATCOPY
);
1458 alpha_blend_image( himl
, hImageDC
, 0, 0, pt
.x
, pt
.y
, cx
, cy
, func
, fStyle
, blend_col
);
1459 DeleteObject (SelectObject (hImageDC
, hOldBrush
));
1460 bResult
= BitBlt( pimldp
->hdcDst
, pimldp
->x
, pimldp
->y
, cx
, cy
, hImageDC
, 0, 0, SRCCOPY
);
1465 * Draw the initial image
1468 if (himl
->hbmMask
) {
1469 hOldBrush
= SelectObject (hImageDC
, CreateSolidBrush (GetTextColor(pimldp
->hdcDst
)));
1470 PatBlt( hImageDC
, 0, 0, cx
, cy
, PATCOPY
);
1471 BitBlt(hImageDC
, 0, 0, cx
, cy
, hMaskListDC
, pt
.x
, pt
.y
, SRCPAINT
);
1472 DeleteObject (SelectObject (hImageDC
, hOldBrush
));
1473 if( bIsTransparent
)
1475 BitBlt ( pimldp
->hdcDst
, pimldp
->x
, pimldp
->y
, cx
, cy
, hImageDC
, 0, 0, SRCAND
);
1480 hOldBrush
= SelectObject (hImageDC
, GetStockObject(BLACK_BRUSH
));
1481 PatBlt( hImageDC
, 0, 0, cx
, cy
, PATCOPY
);
1482 SelectObject(hImageDC
, hOldBrush
);
1485 /* blend the image with the needed solid background */
1486 COLORREF colour
= RGB(0,0,0);
1488 if( !bIsTransparent
)
1490 colour
= pimldp
->rgbBk
;
1491 if( colour
== CLR_DEFAULT
)
1492 colour
= himl
->clrBk
;
1493 if( colour
== CLR_NONE
)
1494 colour
= GetBkColor(pimldp
->hdcDst
);
1497 hOldBrush
= SelectObject (hImageDC
, CreateSolidBrush (colour
));
1498 PatBlt( hImageDC
, 0, 0, cx
, cy
, PATCOPY
);
1501 BitBlt( hImageDC
, 0, 0, cx
, cy
, hMaskListDC
, pt
.x
, pt
.y
, SRCAND
);
1502 BitBlt( hImageDC
, 0, 0, cx
, cy
, hImageListDC
, pt
.x
, pt
.y
, SRCPAINT
);
1505 BitBlt( hImageDC
, 0, 0, cx
, cy
, hImageListDC
, pt
.x
, pt
.y
, SRCCOPY
);
1506 DeleteObject (SelectObject (hImageDC
, hOldBrush
));
1509 /* Time for blending, if required */
1512 COLORREF clrBlend
= pimldp
->rgbFg
;
1513 HDC hBlendMaskDC
= hImageListDC
;
1516 /* Create the blend Mask */
1517 hOldBitmap
= SelectObject(hBlendMaskDC
, hBlendMaskBmp
);
1518 hBlendBrush
= fStyle
& ILD_BLEND50
? himl
->hbrBlend50
: himl
->hbrBlend25
;
1519 hOldBrush
= SelectObject(hBlendMaskDC
, hBlendBrush
);
1520 PatBlt(hBlendMaskDC
, 0, 0, cx
, cy
, PATCOPY
);
1521 SelectObject(hBlendMaskDC
, hOldBrush
);
1523 /* Modify the blend mask if an Image Mask exist */
1525 BitBlt(hBlendMaskDC
, 0, 0, cx
, cy
, hMaskListDC
, pt
.x
, pt
.y
, 0x220326); /* NOTSRCAND */
1526 BitBlt(hBlendMaskDC
, 0, 0, cx
, cy
, hBlendMaskDC
, 0, 0, NOTSRCCOPY
);
1529 /* now apply blend to the current image given the BlendMask */
1530 if (clrBlend
== CLR_DEFAULT
) clrBlend
= GetSysColor (COLOR_HIGHLIGHT
);
1531 else if (clrBlend
== CLR_NONE
) clrBlend
= GetTextColor (pimldp
->hdcDst
);
1532 hOldBrush
= SelectObject (hImageDC
, CreateSolidBrush(clrBlend
));
1533 BitBlt (hImageDC
, 0, 0, cx
, cy
, hBlendMaskDC
, 0, 0, 0xB8074A); /* PSDPxax */
1534 DeleteObject(SelectObject(hImageDC
, hOldBrush
));
1535 SelectObject(hBlendMaskDC
, hOldBitmap
);
1538 /* Now do the overlay image, if any */
1539 nOvlIdx
= (pimldp
->fStyle
& ILD_OVERLAYMASK
) >> 8;
1540 if ( (nOvlIdx
>= 1) && (nOvlIdx
<= MAX_OVERLAYIMAGE
)) {
1541 nOvlIdx
= himl
->nOvlIdx
[nOvlIdx
- 1];
1542 if ((nOvlIdx
>= 0) && (nOvlIdx
< himl
->cCurImage
)) {
1544 imagelist_point_from_index( himl
, nOvlIdx
, &ptOvl
);
1545 ptOvl
.x
+= pimldp
->xBitmap
;
1546 if (himl
->hbmMask
&& !(fStyle
& ILD_IMAGE
))
1547 BitBlt (hImageDC
, 0, 0, cx
, cy
, hMaskListDC
, ptOvl
.x
, ptOvl
.y
, SRCAND
);
1548 BitBlt (hImageDC
, 0, 0, cx
, cy
, hImageListDC
, ptOvl
.x
, ptOvl
.y
, SRCPAINT
);
1552 if (fState
& ILS_SATURATE
) FIXME("ILS_SATURATE: unimplemented!\n");
1553 if (fState
& ILS_GLOW
) FIXME("ILS_GLOW: unimplemented!\n");
1554 if (fState
& ILS_SHADOW
) FIXME("ILS_SHADOW: unimplemented!\n");
1556 if (fStyle
& ILD_PRESERVEALPHA
) FIXME("ILD_PRESERVEALPHA: unimplemented!\n");
1557 if (fStyle
& ILD_SCALE
) FIXME("ILD_SCALE: unimplemented!\n");
1558 if (fStyle
& ILD_DPISCALE
) FIXME("ILD_DPISCALE: unimplemented!\n");
1560 /* now copy the image to the screen */
1562 if (himl
->hbmMask
&& bIsTransparent
) {
1563 COLORREF oldDstFg
= SetTextColor(pimldp
->hdcDst
, RGB( 0, 0, 0 ) );
1564 COLORREF oldDstBk
= SetBkColor(pimldp
->hdcDst
, RGB( 0xff, 0xff, 0xff ));
1565 BitBlt (pimldp
->hdcDst
, pimldp
->x
, pimldp
->y
, cx
, cy
, hMaskListDC
, pt
.x
, pt
.y
, SRCAND
);
1566 SetBkColor(pimldp
->hdcDst
, oldDstBk
);
1567 SetTextColor(pimldp
->hdcDst
, oldDstFg
);
1570 if (fStyle
& ILD_ROP
) dwRop
= pimldp
->dwRop
;
1571 BitBlt (pimldp
->hdcDst
, pimldp
->x
, pimldp
->y
, cx
, cy
, hImageDC
, 0, 0, dwRop
);
1575 /* cleanup the mess */
1576 SetBkColor(hImageDC
, oldImageBk
);
1577 SetTextColor(hImageDC
, oldImageFg
);
1578 SelectObject(hImageDC
, hOldImageBmp
);
1580 DeleteObject(hBlendMaskBmp
);
1581 DeleteObject(hImageBmp
);
1588 /*************************************************************************
1589 * ImageList_Duplicate [COMCTL32.@]
1591 * Duplicates an image list.
1594 * himlSrc [I] source image list handle
1597 * Success: Handle of duplicated image list.
1602 ImageList_Duplicate (HIMAGELIST himlSrc
)
1606 if (!is_valid(himlSrc
)) {
1607 ERR("Invalid image list handle!\n");
1611 himlDst
= ImageList_Create (himlSrc
->cx
, himlSrc
->cy
, himlSrc
->flags
,
1612 himlSrc
->cCurImage
, himlSrc
->cGrow
);
1618 imagelist_get_bitmap_size(himlSrc
, himlSrc
->cCurImage
, &sz
);
1619 BitBlt (himlDst
->hdcImage
, 0, 0, sz
.cx
, sz
.cy
,
1620 himlSrc
->hdcImage
, 0, 0, SRCCOPY
);
1622 if (himlDst
->hbmMask
)
1623 BitBlt (himlDst
->hdcMask
, 0, 0, sz
.cx
, sz
.cy
,
1624 himlSrc
->hdcMask
, 0, 0, SRCCOPY
);
1626 himlDst
->cCurImage
= himlSrc
->cCurImage
;
1627 if (himlSrc
->has_alpha
&& himlDst
->has_alpha
)
1628 memcpy( himlDst
->has_alpha
, himlSrc
->has_alpha
, himlDst
->cCurImage
);
1634 /*************************************************************************
1635 * ImageList_EndDrag [COMCTL32.@]
1637 * Finishes a drag operation.
1648 ImageList_EndDrag (void)
1650 /* cleanup the InternalDrag struct */
1651 InternalDrag
.hwnd
= 0;
1652 if (InternalDrag
.himl
!= InternalDrag
.himlNoCursor
)
1653 ImageList_Destroy (InternalDrag
.himlNoCursor
);
1654 ImageList_Destroy (InternalDrag
.himl
);
1655 InternalDrag
.himlNoCursor
= InternalDrag
.himl
= 0;
1658 InternalDrag
.dxHotspot
= 0;
1659 InternalDrag
.dyHotspot
= 0;
1660 InternalDrag
.bShow
= FALSE
;
1661 DeleteObject(InternalDrag
.hbmBg
);
1662 InternalDrag
.hbmBg
= 0;
1666 /*************************************************************************
1667 * ImageList_GetBkColor [COMCTL32.@]
1669 * Returns the background color of an image list.
1672 * himl [I] Image list handle.
1675 * Success: background color
1680 ImageList_GetBkColor (HIMAGELIST himl
)
1682 return himl
? himl
->clrBk
: CLR_NONE
;
1686 /*************************************************************************
1687 * ImageList_GetDragImage [COMCTL32.@]
1689 * Returns the handle to the internal drag image list.
1692 * ppt [O] Pointer to the drag position. Can be NULL.
1693 * pptHotspot [O] Pointer to the position of the hot spot. Can be NULL.
1696 * Success: Handle of the drag image list.
1701 ImageList_GetDragImage (POINT
*ppt
, POINT
*pptHotspot
)
1703 if (is_valid(InternalDrag
.himl
)) {
1705 ppt
->x
= InternalDrag
.x
;
1706 ppt
->y
= InternalDrag
.y
;
1709 pptHotspot
->x
= InternalDrag
.dxHotspot
;
1710 pptHotspot
->y
= InternalDrag
.dyHotspot
;
1712 return (InternalDrag
.himl
);
1719 /*************************************************************************
1720 * ImageList_GetFlags [COMCTL32.@]
1722 * Gets the flags of the specified image list.
1725 * himl [I] Handle to image list
1735 ImageList_GetFlags(HIMAGELIST himl
)
1737 TRACE("%p\n", himl
);
1739 return is_valid(himl
) ? himl
->flags
: 0;
1743 /*************************************************************************
1744 * ImageList_GetIcon [COMCTL32.@]
1746 * Creates an icon from a masked image of an image list.
1749 * himl [I] handle to image list
1751 * flags [I] drawing style flags
1754 * Success: icon handle
1759 ImageList_GetIcon (HIMAGELIST himl
, INT i
, UINT fStyle
)
1763 HBITMAP hOldDstBitmap
;
1767 TRACE("%p %d %d\n", himl
, i
, fStyle
);
1768 if (!is_valid(himl
) || (i
< 0) || (i
>= himl
->cCurImage
)) return NULL
;
1774 /* create colour bitmap */
1776 ii
.hbmColor
= CreateCompatibleBitmap(hdcDst
, himl
->cx
, himl
->cy
);
1777 ReleaseDC(0, hdcDst
);
1779 hdcDst
= CreateCompatibleDC(0);
1781 imagelist_point_from_index( himl
, i
, &pt
);
1784 ii
.hbmMask
= CreateBitmap (himl
->cx
, himl
->cy
, 1, 1, NULL
);
1785 hOldDstBitmap
= SelectObject (hdcDst
, ii
.hbmMask
);
1786 if (himl
->hbmMask
) {
1787 BitBlt (hdcDst
, 0, 0, himl
->cx
, himl
->cy
,
1788 himl
->hdcMask
, pt
.x
, pt
.y
, SRCCOPY
);
1791 PatBlt (hdcDst
, 0, 0, himl
->cx
, himl
->cy
, BLACKNESS
);
1794 SelectObject (hdcDst
, ii
.hbmColor
);
1795 BitBlt (hdcDst
, 0, 0, himl
->cx
, himl
->cy
,
1796 himl
->hdcImage
, pt
.x
, pt
.y
, SRCCOPY
);
1799 * CreateIconIndirect requires us to deselect the bitmaps from
1800 * the DCs before calling
1802 SelectObject(hdcDst
, hOldDstBitmap
);
1804 hIcon
= CreateIconIndirect (&ii
);
1806 DeleteObject (ii
.hbmMask
);
1807 DeleteObject (ii
.hbmColor
);
1814 /*************************************************************************
1815 * ImageList_GetIconSize [COMCTL32.@]
1817 * Retrieves the size of an image in an image list.
1820 * himl [I] handle to image list
1821 * cx [O] pointer to the image width.
1822 * cy [O] pointer to the image height.
1829 * All images in an image list have the same size.
1833 ImageList_GetIconSize (HIMAGELIST himl
, INT
*cx
, INT
*cy
)
1835 if (!is_valid(himl
) || !cx
|| !cy
)
1845 /*************************************************************************
1846 * ImageList_GetImageCount [COMCTL32.@]
1848 * Returns the number of images in an image list.
1851 * himl [I] handle to image list
1854 * Success: Number of images.
1859 ImageList_GetImageCount (HIMAGELIST himl
)
1861 if (!is_valid(himl
))
1864 return himl
->cCurImage
;
1868 /*************************************************************************
1869 * ImageList_GetImageInfo [COMCTL32.@]
1871 * Returns information about an image in an image list.
1874 * himl [I] handle to image list
1876 * pImageInfo [O] pointer to the image information
1884 ImageList_GetImageInfo (HIMAGELIST himl
, INT i
, IMAGEINFO
*pImageInfo
)
1888 if (!is_valid(himl
) || (pImageInfo
== NULL
))
1890 if ((i
< 0) || (i
>= himl
->cCurImage
))
1893 pImageInfo
->hbmImage
= himl
->hbmImage
;
1894 pImageInfo
->hbmMask
= himl
->hbmMask
;
1896 imagelist_point_from_index( himl
, i
, &pt
);
1897 pImageInfo
->rcImage
.top
= pt
.y
;
1898 pImageInfo
->rcImage
.bottom
= pt
.y
+ himl
->cy
;
1899 pImageInfo
->rcImage
.left
= pt
.x
;
1900 pImageInfo
->rcImage
.right
= pt
.x
+ himl
->cx
;
1906 /*************************************************************************
1907 * ImageList_GetImageRect [COMCTL32.@]
1909 * Retrieves the rectangle of the specified image in an image list.
1912 * himl [I] handle to image list
1914 * lpRect [O] pointer to the image rectangle
1921 * This is an UNDOCUMENTED function!!!
1925 ImageList_GetImageRect (HIMAGELIST himl
, INT i
, LPRECT lpRect
)
1929 if (!is_valid(himl
) || (lpRect
== NULL
))
1931 if ((i
< 0) || (i
>= himl
->cCurImage
))
1934 imagelist_point_from_index( himl
, i
, &pt
);
1935 lpRect
->left
= pt
.x
;
1937 lpRect
->right
= pt
.x
+ himl
->cx
;
1938 lpRect
->bottom
= pt
.y
+ himl
->cy
;
1944 /*************************************************************************
1945 * ImageList_LoadImage [COMCTL32.@]
1946 * ImageList_LoadImageA [COMCTL32.@]
1948 * Creates an image list from a bitmap, icon or cursor.
1950 * See ImageList_LoadImageW.
1954 ImageList_LoadImageA (HINSTANCE hi
, LPCSTR lpbmp
, INT cx
, INT cGrow
,
1955 COLORREF clrMask
, UINT uType
, UINT uFlags
)
1961 if (IS_INTRESOURCE(lpbmp
))
1962 return ImageList_LoadImageW(hi
, (LPCWSTR
)lpbmp
, cx
, cGrow
, clrMask
,
1965 len
= MultiByteToWideChar(CP_ACP
, 0, lpbmp
, -1, NULL
, 0);
1966 lpbmpW
= heap_alloc(len
* sizeof(WCHAR
));
1967 MultiByteToWideChar(CP_ACP
, 0, lpbmp
, -1, lpbmpW
, len
);
1969 himl
= ImageList_LoadImageW(hi
, lpbmpW
, cx
, cGrow
, clrMask
, uType
, uFlags
);
1975 /*************************************************************************
1976 * ImageList_LoadImageW [COMCTL32.@]
1978 * Creates an image list from a bitmap, icon or cursor.
1981 * hi [I] instance handle
1982 * lpbmp [I] name or id of the image
1983 * cx [I] width of each image
1984 * cGrow [I] number of images to expand
1985 * clrMask [I] mask color
1986 * uType [I] type of image to load
1987 * uFlags [I] loading flags
1990 * Success: handle to the loaded image list
1998 ImageList_LoadImageW (HINSTANCE hi
, LPCWSTR lpbmp
, INT cx
, INT cGrow
,
1999 COLORREF clrMask
, UINT uType
, UINT uFlags
)
2001 HIMAGELIST himl
= NULL
;
2005 handle
= LoadImageW (hi
, lpbmp
, uType
, 0, 0, uFlags
);
2007 WARN("Couldn't load image\n");
2011 if (uType
== IMAGE_BITMAP
) {
2015 if (GetObjectW (handle
, sizeof(dib
), &dib
) == sizeof(BITMAP
)) color
= ILC_COLOR
;
2016 else color
= dib
.dsBm
.bmBitsPixel
;
2018 /* To match windows behavior, if cx is set to zero and
2019 the flag DI_DEFAULTSIZE is specified, cx becomes the
2020 system metric value for icons. If the flag is not specified
2021 the function sets the size to the height of the bitmap */
2024 if (uFlags
& DI_DEFAULTSIZE
)
2025 cx
= GetSystemMetrics (SM_CXICON
);
2027 cx
= dib
.dsBm
.bmHeight
;
2030 nImageCount
= dib
.dsBm
.bmWidth
/ cx
;
2032 if (clrMask
!= CLR_NONE
) color
|= ILC_MASK
;
2033 himl
= ImageList_Create (cx
, dib
.dsBm
.bmHeight
, color
, nImageCount
, cGrow
);
2035 DeleteObject (handle
);
2038 ImageList_AddMasked (himl
, handle
, clrMask
);
2040 else if ((uType
== IMAGE_ICON
) || (uType
== IMAGE_CURSOR
)) {
2044 GetIconInfo (handle
, &ii
);
2045 GetObjectW (ii
.hbmColor
, sizeof(BITMAP
), &bmp
);
2046 himl
= ImageList_Create (bmp
.bmWidth
, bmp
.bmHeight
,
2047 ILC_MASK
| ILC_COLOR
, 1, cGrow
);
2049 DeleteObject (ii
.hbmColor
);
2050 DeleteObject (ii
.hbmMask
);
2051 DeleteObject (handle
);
2054 ImageList_Add (himl
, ii
.hbmColor
, ii
.hbmMask
);
2055 DeleteObject (ii
.hbmColor
);
2056 DeleteObject (ii
.hbmMask
);
2059 DeleteObject (handle
);
2065 /*************************************************************************
2066 * ImageList_Merge [COMCTL32.@]
2068 * Create an image list containing a merged image from two image lists.
2071 * himl1 [I] handle to first image list
2072 * i1 [I] first image index
2073 * himl2 [I] handle to second image list
2074 * i2 [I] second image index
2075 * dx [I] X offset of the second image relative to the first.
2076 * dy [I] Y offset of the second image relative to the first.
2079 * Success: The newly created image list. It contains a single image
2080 * consisting of the second image merged with the first.
2081 * Failure: NULL, if either himl1 or himl2 is invalid.
2084 * - The returned image list should be deleted by the caller using
2085 * ImageList_Destroy() when it is no longer required.
2086 * - If either i1 or i2 is not a valid image index, they will be treated
2090 ImageList_Merge (HIMAGELIST himl1
, INT i1
, HIMAGELIST himl2
, INT i2
,
2093 HIMAGELIST himlDst
= NULL
;
2095 INT xOff1
, yOff1
, xOff2
, yOff2
;
2099 TRACE("(himl1=%p i1=%d himl2=%p i2=%d dx=%d dy=%d)\n", himl1
, i1
, himl2
,
2102 if (!is_valid(himl1
) || !is_valid(himl2
))
2106 cxDst
= max (himl1
->cx
, dx
+ himl2
->cx
);
2111 cxDst
= max (himl2
->cx
, himl1
->cx
- dx
);
2116 cxDst
= max (himl1
->cx
, himl2
->cx
);
2122 cyDst
= max (himl1
->cy
, dy
+ himl2
->cy
);
2127 cyDst
= max (himl2
->cy
, himl1
->cy
- dy
);
2132 cyDst
= max (himl1
->cy
, himl2
->cy
);
2137 newFlags
= (himl1
->flags
> himl2
->flags
? himl1
->flags
: himl2
->flags
) & ILC_COLORDDB
;
2138 if (newFlags
== ILC_COLORDDB
&& (himl1
->flags
& ILC_COLORDDB
) == ILC_COLOR16
)
2139 newFlags
= ILC_COLOR16
; /* this is what native (at least v5) does, don't know why */
2140 himlDst
= ImageList_Create (cxDst
, cyDst
, ILC_MASK
| newFlags
, 1, 1);
2144 imagelist_point_from_index( himl1
, i1
, &pt1
);
2145 imagelist_point_from_index( himl2
, i2
, &pt2
);
2148 BitBlt (himlDst
->hdcImage
, 0, 0, cxDst
, cyDst
, himl1
->hdcImage
, 0, 0, BLACKNESS
);
2149 if (i1
>= 0 && i1
< himl1
->cCurImage
)
2150 BitBlt (himlDst
->hdcImage
, xOff1
, yOff1
, himl1
->cx
, himl1
->cy
, himl1
->hdcImage
, pt1
.x
, pt1
.y
, SRCCOPY
);
2151 if (i2
>= 0 && i2
< himl2
->cCurImage
)
2153 if (himl2
->flags
& ILC_MASK
)
2155 BitBlt (himlDst
->hdcImage
, xOff2
, yOff2
, himl2
->cx
, himl2
->cy
, himl2
->hdcMask
, pt2
.x
, pt2
.y
, SRCAND
);
2156 BitBlt (himlDst
->hdcImage
, xOff2
, yOff2
, himl2
->cx
, himl2
->cy
, himl2
->hdcImage
, pt2
.x
, pt2
.y
, SRCPAINT
);
2159 BitBlt (himlDst
->hdcImage
, xOff2
, yOff2
, himl2
->cx
, himl2
->cy
, himl2
->hdcImage
, pt2
.x
, pt2
.y
, SRCCOPY
);
2163 BitBlt (himlDst
->hdcMask
, 0, 0, cxDst
, cyDst
, himl1
->hdcMask
, 0, 0, WHITENESS
);
2164 if (i1
>= 0 && i1
< himl1
->cCurImage
)
2165 BitBlt (himlDst
->hdcMask
, xOff1
, yOff1
, himl1
->cx
, himl1
->cy
, himl1
->hdcMask
, pt1
.x
, pt1
.y
, SRCCOPY
);
2166 if (i2
>= 0 && i2
< himl2
->cCurImage
)
2167 BitBlt (himlDst
->hdcMask
, xOff2
, yOff2
, himl2
->cx
, himl2
->cy
, himl2
->hdcMask
, pt2
.x
, pt2
.y
, SRCAND
);
2169 himlDst
->cCurImage
= 1;
2176 /* helper for ImageList_Read, see comments below */
2177 static void *read_bitmap(IStream
*pstm
, BITMAPINFO
*bmi
)
2179 BITMAPFILEHEADER bmfh
;
2180 int bitsperpixel
, palspace
;
2183 if (FAILED(IStream_Read ( pstm
, &bmfh
, sizeof(bmfh
), NULL
)))
2186 if (bmfh
.bfType
!= (('M'<<8)|'B'))
2189 if (FAILED(IStream_Read ( pstm
, &bmi
->bmiHeader
, sizeof(bmi
->bmiHeader
), NULL
)))
2192 if ((bmi
->bmiHeader
.biSize
!= sizeof(bmi
->bmiHeader
)))
2195 TRACE("width %u, height %u, planes %u, bpp %u\n",
2196 bmi
->bmiHeader
.biWidth
, bmi
->bmiHeader
.biHeight
,
2197 bmi
->bmiHeader
.biPlanes
, bmi
->bmiHeader
.biBitCount
);
2199 bitsperpixel
= bmi
->bmiHeader
.biPlanes
* bmi
->bmiHeader
.biBitCount
;
2200 if (bitsperpixel
<=8)
2201 palspace
= (1<<bitsperpixel
)*sizeof(RGBQUAD
);
2205 bmi
->bmiHeader
.biSizeImage
= get_dib_image_size( bmi
);
2207 /* read the palette right after the end of the bitmapinfoheader */
2208 if (palspace
&& FAILED(IStream_Read(pstm
, bmi
->bmiColors
, palspace
, NULL
)))
2211 bits
= heap_alloc_zero(bmi
->bmiHeader
.biSizeImage
);
2212 if (!bits
) return NULL
;
2214 if (FAILED(IStream_Read(pstm
, bits
, bmi
->bmiHeader
.biSizeImage
, NULL
)))
2222 /*************************************************************************
2223 * ImageList_Read [COMCTL32.@]
2225 * Reads an image list from a stream.
2228 * pstm [I] pointer to a stream
2231 * Success: handle to image list
2234 * The format is like this:
2235 * ILHEAD ilheadstruct;
2237 * for the color image part:
2238 * BITMAPFILEHEADER bmfh;
2239 * BITMAPINFOHEADER bmih;
2240 * only if it has a palette:
2241 * RGBQUAD rgbs[nr_of_paletted_colors];
2243 * BYTE colorbits[imagesize];
2245 * the following only if the ILC_MASK bit is set in ILHEAD.ilFlags:
2246 * BITMAPFILEHEADER bmfh_mask;
2247 * BITMAPINFOHEADER bmih_mask;
2248 * only if it has a palette (it usually does not):
2249 * RGBQUAD rgbs[nr_of_paletted_colors];
2251 * BYTE maskbits[imagesize];
2253 HIMAGELIST WINAPI
ImageList_Read(IStream
*pstm
)
2255 char image_buf
[sizeof(BITMAPINFOHEADER
) + sizeof(RGBQUAD
) * 256];
2256 char mask_buf
[sizeof(BITMAPINFOHEADER
) + sizeof(RGBQUAD
) * 256];
2257 BITMAPINFO
*image_info
= (BITMAPINFO
*)image_buf
;
2258 BITMAPINFO
*mask_info
= (BITMAPINFO
*)mask_buf
;
2259 void *image_bits
, *mask_bits
= NULL
;
2264 TRACE("%p\n", pstm
);
2266 if (FAILED(IStream_Read (pstm
, &ilHead
, sizeof(ILHEAD
), NULL
)))
2268 if (ilHead
.usMagic
!= (('L' << 8) | 'I'))
2270 if (ilHead
.usVersion
!= 0x101) /* probably version? */
2273 TRACE("cx %u, cy %u, flags 0x%04x, cCurImage %u, cMaxImage %u\n",
2274 ilHead
.cx
, ilHead
.cy
, ilHead
.flags
, ilHead
.cCurImage
, ilHead
.cMaxImage
);
2276 himl
= ImageList_Create(ilHead
.cx
, ilHead
.cy
, ilHead
.flags
, ilHead
.cCurImage
, ilHead
.cMaxImage
);
2280 if (!(image_bits
= read_bitmap(pstm
, image_info
)))
2282 WARN("failed to read bitmap from stream\n");
2285 if (ilHead
.flags
& ILC_MASK
)
2287 if (!(mask_bits
= read_bitmap(pstm
, mask_info
)))
2289 WARN("failed to read mask bitmap from stream\n");
2293 else mask_info
= NULL
;
2295 if (himl
->has_alpha
&& image_info
->bmiHeader
.biBitCount
== 32)
2297 DWORD
*ptr
= image_bits
;
2298 BYTE
*mask_ptr
= mask_bits
;
2299 int stride
= himl
->cy
* image_info
->bmiHeader
.biWidth
;
2301 if (image_info
->bmiHeader
.biHeight
> 0) /* bottom-up */
2303 ptr
+= image_info
->bmiHeader
.biHeight
* image_info
->bmiHeader
.biWidth
- stride
;
2304 mask_ptr
+= (image_info
->bmiHeader
.biHeight
* image_info
->bmiHeader
.biWidth
- stride
) / 8;
2306 image_info
->bmiHeader
.biHeight
= himl
->cy
;
2308 else image_info
->bmiHeader
.biHeight
= -himl
->cy
;
2310 for (i
= 0; i
< ilHead
.cCurImage
; i
+= TILE_COUNT
)
2312 add_dib_bits( himl
, i
, min( ilHead
.cCurImage
- i
, TILE_COUNT
),
2313 himl
->cx
, himl
->cy
, image_info
, mask_info
, ptr
, mask_ptr
);
2315 mask_ptr
+= stride
/ 8;
2320 StretchDIBits( himl
->hdcImage
, 0, 0, image_info
->bmiHeader
.biWidth
, image_info
->bmiHeader
.biHeight
,
2321 0, 0, image_info
->bmiHeader
.biWidth
, image_info
->bmiHeader
.biHeight
,
2322 image_bits
, image_info
, DIB_RGB_COLORS
, SRCCOPY
);
2324 StretchDIBits( himl
->hdcMask
, 0, 0, mask_info
->bmiHeader
.biWidth
, mask_info
->bmiHeader
.biHeight
,
2325 0, 0, mask_info
->bmiHeader
.biWidth
, mask_info
->bmiHeader
.biHeight
,
2326 mask_bits
, mask_info
, DIB_RGB_COLORS
, SRCCOPY
);
2328 heap_free( image_bits
);
2329 heap_free( mask_bits
);
2331 himl
->cCurImage
= ilHead
.cCurImage
;
2332 himl
->cMaxImage
= ilHead
.cMaxImage
;
2334 ImageList_SetBkColor(himl
,ilHead
.bkcolor
);
2336 ImageList_SetOverlayImage(himl
,ilHead
.ovls
[i
],i
+1);
2341 /*************************************************************************
2342 * ImageList_Remove [COMCTL32.@]
2344 * Removes an image from an image list
2347 * himl [I] image list handle
2354 * FIXME: as the image list storage test shows, native comctl32 simply shifts
2355 * images without creating a new bitmap.
2358 ImageList_Remove (HIMAGELIST himl
, INT i
)
2360 HBITMAP hbmNewImage
, hbmNewMask
;
2364 TRACE("(himl=%p i=%d)\n", himl
, i
);
2366 if (!is_valid(himl
)) {
2367 ERR("Invalid image list handle!\n");
2371 if ((i
< -1) || (i
>= himl
->cCurImage
)) {
2372 TRACE("index out of range! %d\n", i
);
2380 if (himl
->cCurImage
== 0) {
2381 /* remove all on empty ImageList is allowed */
2382 TRACE("remove all on empty ImageList!\n");
2386 himl
->cMaxImage
= himl
->cGrow
;
2387 himl
->cCurImage
= 0;
2388 for (nCount
= 0; nCount
< MAX_OVERLAYIMAGE
; nCount
++)
2389 himl
->nOvlIdx
[nCount
] = -1;
2391 if (himl
->has_alpha
)
2393 heap_free( himl
->has_alpha
);
2394 himl
->has_alpha
= heap_alloc_zero( himl
->cMaxImage
);
2397 hbmNewImage
= ImageList_CreateImage(himl
->hdcImage
, himl
, himl
->cMaxImage
);
2398 SelectObject (himl
->hdcImage
, hbmNewImage
);
2399 DeleteObject (himl
->hbmImage
);
2400 himl
->hbmImage
= hbmNewImage
;
2402 if (himl
->hbmMask
) {
2404 imagelist_get_bitmap_size(himl
, himl
->cMaxImage
, &sz
);
2405 hbmNewMask
= CreateBitmap (sz
.cx
, sz
.cy
, 1, 1, NULL
);
2406 SelectObject (himl
->hdcMask
, hbmNewMask
);
2407 DeleteObject (himl
->hbmMask
);
2408 himl
->hbmMask
= hbmNewMask
;
2412 /* delete one image */
2413 TRACE("Remove single image! %d\n", i
);
2415 /* create new bitmap(s) */
2416 TRACE(" - Number of images: %d / %d (Old/New)\n",
2417 himl
->cCurImage
, himl
->cCurImage
- 1);
2419 hbmNewImage
= ImageList_CreateImage(himl
->hdcImage
, himl
, himl
->cMaxImage
);
2421 imagelist_get_bitmap_size(himl
, himl
->cMaxImage
, &sz
);
2423 hbmNewMask
= CreateBitmap (sz
.cx
, sz
.cy
, 1, 1, NULL
);
2425 hbmNewMask
= 0; /* Just to keep compiler happy! */
2427 hdcBmp
= CreateCompatibleDC (0);
2429 /* copy all images and masks prior to the "removed" image */
2431 TRACE("Pre image copy: Copy %d images\n", i
);
2433 SelectObject (hdcBmp
, hbmNewImage
);
2434 imagelist_copy_images( himl
, himl
->hdcImage
, hdcBmp
, 0, i
, 0 );
2436 if (himl
->hbmMask
) {
2437 SelectObject (hdcBmp
, hbmNewMask
);
2438 imagelist_copy_images( himl
, himl
->hdcMask
, hdcBmp
, 0, i
, 0 );
2442 /* copy all images and masks behind the removed image */
2443 if (i
< himl
->cCurImage
- 1) {
2444 TRACE("Post image copy!\n");
2446 SelectObject (hdcBmp
, hbmNewImage
);
2447 imagelist_copy_images( himl
, himl
->hdcImage
, hdcBmp
, i
+ 1,
2448 (himl
->cCurImage
- i
), i
);
2450 if (himl
->hbmMask
) {
2451 SelectObject (hdcBmp
, hbmNewMask
);
2452 imagelist_copy_images( himl
, himl
->hdcMask
, hdcBmp
, i
+ 1,
2453 (himl
->cCurImage
- i
), i
);
2459 /* delete old images and insert new ones */
2460 SelectObject (himl
->hdcImage
, hbmNewImage
);
2461 DeleteObject (himl
->hbmImage
);
2462 himl
->hbmImage
= hbmNewImage
;
2463 if (himl
->hbmMask
) {
2464 SelectObject (himl
->hdcMask
, hbmNewMask
);
2465 DeleteObject (himl
->hbmMask
);
2466 himl
->hbmMask
= hbmNewMask
;
2476 /*************************************************************************
2477 * ImageList_Replace [COMCTL32.@]
2479 * Replaces an image in an image list with a new image.
2482 * himl [I] handle to image list
2484 * hbmImage [I] handle to image bitmap
2485 * hbmMask [I] handle to mask bitmap. Can be NULL.
2493 ImageList_Replace (HIMAGELIST himl
, INT i
, HBITMAP hbmImage
,
2500 TRACE("%p %d %p %p\n", himl
, i
, hbmImage
, hbmMask
);
2502 if (!is_valid(himl
)) {
2503 ERR("Invalid image list handle!\n");
2507 if ((i
>= himl
->cMaxImage
) || (i
< 0)) {
2508 ERR("Invalid image index!\n");
2512 if (!GetObjectW(hbmImage
, sizeof(BITMAP
), &bmp
))
2515 hdcImage
= CreateCompatibleDC (0);
2518 SelectObject (hdcImage
, hbmImage
);
2520 if (add_with_alpha( himl
, hdcImage
, i
, 1, bmp
.bmWidth
, bmp
.bmHeight
, hbmImage
, hbmMask
))
2523 imagelist_point_from_index(himl
, i
, &pt
);
2524 StretchBlt (himl
->hdcImage
, pt
.x
, pt
.y
, himl
->cx
, himl
->cy
,
2525 hdcImage
, 0, 0, bmp
.bmWidth
, bmp
.bmHeight
, SRCCOPY
);
2530 HBITMAP hOldBitmapTemp
;
2532 hdcTemp
= CreateCompatibleDC(0);
2533 hOldBitmapTemp
= SelectObject(hdcTemp
, hbmMask
);
2535 StretchBlt (himl
->hdcMask
, pt
.x
, pt
.y
, himl
->cx
, himl
->cy
,
2536 hdcTemp
, 0, 0, bmp
.bmWidth
, bmp
.bmHeight
, SRCCOPY
);
2537 SelectObject(hdcTemp
, hOldBitmapTemp
);
2540 /* Remove the background from the image
2542 BitBlt (himl
->hdcImage
, pt
.x
, pt
.y
, bmp
.bmWidth
, bmp
.bmHeight
,
2543 himl
->hdcMask
, pt
.x
, pt
.y
, 0x220326); /* NOTSRCAND */
2547 DeleteDC (hdcImage
);
2553 /*************************************************************************
2554 * ImageList_ReplaceIcon [COMCTL32.@]
2556 * Replaces an image in an image list using an icon.
2559 * himl [I] handle to image list
2561 * hIcon [I] handle to icon
2564 * Success: index of the replaced image
2569 ImageList_ReplaceIcon (HIMAGELIST himl
, INT nIndex
, HICON hIcon
)
2577 TRACE("(%p %d %p)\n", himl
, nIndex
, hIcon
);
2579 if (!is_valid(himl
)) {
2580 ERR("invalid image list\n");
2583 if ((nIndex
>= himl
->cMaxImage
) || (nIndex
< -1)) {
2584 ERR("invalid image index %d / %d\n", nIndex
, himl
->cMaxImage
);
2588 hBestFitIcon
= CopyImage(
2591 LR_COPYFROMRESOURCE
);
2592 /* the above will fail if the icon wasn't loaded from a resource, so try
2593 * again without LR_COPYFROMRESOURCE flag */
2595 hBestFitIcon
= CopyImage(
2603 if (himl
->cCurImage
+ 1 >= himl
->cMaxImage
)
2604 IMAGELIST_InternalExpandBitmaps(himl
, 1);
2606 nIndex
= himl
->cCurImage
;
2610 if (himl
->has_alpha
&& GetIconInfo (hBestFitIcon
, &ii
))
2612 HDC hdcImage
= CreateCompatibleDC( 0 );
2613 GetObjectW (ii
.hbmMask
, sizeof(BITMAP
), &bmp
);
2617 UINT height
= bmp
.bmHeight
/ 2;
2618 HDC hdcMask
= CreateCompatibleDC( 0 );
2619 HBITMAP color
= CreateBitmap( bmp
.bmWidth
, height
, 1, 1, NULL
);
2620 SelectObject( hdcImage
, color
);
2621 SelectObject( hdcMask
, ii
.hbmMask
);
2622 BitBlt( hdcImage
, 0, 0, bmp
.bmWidth
, height
, hdcMask
, 0, height
, SRCCOPY
);
2623 ret
= add_with_alpha( himl
, hdcImage
, nIndex
, 1, bmp
.bmWidth
, height
, color
, ii
.hbmMask
);
2624 DeleteDC( hdcMask
);
2625 DeleteObject( color
);
2627 else ret
= add_with_alpha( himl
, hdcImage
, nIndex
, 1, bmp
.bmWidth
, bmp
.bmHeight
,
2628 ii
.hbmColor
, ii
.hbmMask
);
2630 DeleteDC( hdcImage
);
2631 DeleteObject (ii
.hbmMask
);
2632 if (ii
.hbmColor
) DeleteObject (ii
.hbmColor
);
2636 imagelist_point_from_index(himl
, nIndex
, &pt
);
2640 DrawIconEx( himl
->hdcImage
, pt
.x
, pt
.y
, hBestFitIcon
, himl
->cx
, himl
->cy
, 0, 0, DI_IMAGE
);
2641 PatBlt( himl
->hdcMask
, pt
.x
, pt
.y
, himl
->cx
, himl
->cy
, WHITENESS
);
2642 DrawIconEx( himl
->hdcMask
, pt
.x
, pt
.y
, hBestFitIcon
, himl
->cx
, himl
->cy
, 0, 0, DI_MASK
);
2646 COLORREF color
= himl
->clrBk
!= CLR_NONE
? himl
->clrBk
: comctl32_color
.clrWindow
;
2647 HBRUSH brush
= CreateSolidBrush( GetNearestColor( himl
->hdcImage
, color
));
2649 SelectObject( himl
->hdcImage
, brush
);
2650 PatBlt( himl
->hdcImage
, pt
.x
, pt
.y
, himl
->cx
, himl
->cy
, PATCOPY
);
2651 SelectObject( himl
->hdcImage
, GetStockObject(BLACK_BRUSH
) );
2652 DeleteObject( brush
);
2653 DrawIconEx( himl
->hdcImage
, pt
.x
, pt
.y
, hBestFitIcon
, himl
->cx
, himl
->cy
, 0, 0, DI_NORMAL
);
2657 DestroyIcon(hBestFitIcon
);
2659 TRACE("Insert index = %d, himl->cCurImage = %d\n", nIndex
, himl
->cCurImage
);
2664 /*************************************************************************
2665 * ImageList_SetBkColor [COMCTL32.@]
2667 * Sets the background color of an image list.
2670 * himl [I] handle to image list
2671 * clrBk [I] background color
2674 * Success: previous background color
2679 ImageList_SetBkColor (HIMAGELIST himl
, COLORREF clrBk
)
2683 if (!is_valid(himl
))
2686 clrOldBk
= himl
->clrBk
;
2687 himl
->clrBk
= clrBk
;
2692 /*************************************************************************
2693 * ImageList_SetDragCursorImage [COMCTL32.@]
2695 * Combines the specified image with the current drag image
2698 * himlDrag [I] handle to drag image list
2699 * iDrag [I] drag image index
2700 * dxHotspot [I] X position of the hot spot
2701 * dyHotspot [I] Y position of the hot spot
2708 * - The names dxHotspot, dyHotspot are misleading because they have nothing
2709 * to do with a hotspot but are only the offset of the origin of the new
2710 * image relative to the origin of the old image.
2712 * - When this function is called and the drag image is visible, a
2713 * short flickering occurs but this matches the Win9x behavior. It is
2714 * possible to fix the flickering using code like in ImageList_DragMove.
2718 ImageList_SetDragCursorImage (HIMAGELIST himlDrag
, INT iDrag
,
2719 INT dxHotspot
, INT dyHotspot
)
2721 HIMAGELIST himlTemp
;
2724 if (!is_valid(InternalDrag
.himl
) || !is_valid(himlDrag
))
2727 TRACE(" dxH=%d dyH=%d nX=%d nY=%d\n",
2728 dxHotspot
, dyHotspot
, InternalDrag
.dxHotspot
, InternalDrag
.dyHotspot
);
2730 visible
= InternalDrag
.bShow
;
2732 himlTemp
= ImageList_Merge (InternalDrag
.himlNoCursor
, 0, himlDrag
, iDrag
,
2733 dxHotspot
, dyHotspot
);
2736 /* hide the drag image */
2737 ImageList_DragShowNolock(FALSE
);
2739 if ((InternalDrag
.himl
->cx
!= himlTemp
->cx
) ||
2740 (InternalDrag
.himl
->cy
!= himlTemp
->cy
)) {
2741 /* the size of the drag image changed, invalidate the buffer */
2742 DeleteObject(InternalDrag
.hbmBg
);
2743 InternalDrag
.hbmBg
= 0;
2746 if (InternalDrag
.himl
!= InternalDrag
.himlNoCursor
)
2747 ImageList_Destroy (InternalDrag
.himl
);
2748 InternalDrag
.himl
= himlTemp
;
2751 /* show the drag image */
2752 ImageList_DragShowNolock(TRUE
);
2759 /*************************************************************************
2760 * ImageList_SetFilter [COMCTL32.@]
2762 * Sets a filter (or does something completely different)!!???
2763 * It removes 12 Bytes from the stack (3 Parameters).
2766 * himl [I] SHOULD be a handle to image list
2767 * i [I] COULD be an index?
2772 * Failure: FALSE ???
2775 * This is an UNDOCUMENTED function!!!!
2780 ImageList_SetFilter (HIMAGELIST himl
, INT i
, DWORD dwFilter
)
2782 FIXME("(%p 0x%x 0x%x):empty stub!\n", himl
, i
, dwFilter
);
2788 /*************************************************************************
2789 * ImageList_SetFlags [COMCTL32.@]
2791 * Sets the image list flags.
2794 * himl [I] Handle to image list
2795 * flags [I] Flags to set
2805 ImageList_SetFlags(HIMAGELIST himl
, DWORD flags
)
2807 FIXME("(%p %08x):empty stub\n", himl
, flags
);
2812 /*************************************************************************
2813 * ImageList_SetIconSize [COMCTL32.@]
2815 * Sets the image size of the bitmap and deletes all images.
2818 * himl [I] handle to image list
2819 * cx [I] image width
2820 * cy [I] image height
2828 ImageList_SetIconSize (HIMAGELIST himl
, INT cx
, INT cy
)
2833 if (!is_valid(himl
))
2836 /* remove all images */
2837 himl
->cMaxImage
= himl
->cInitial
+ 1;
2838 himl
->cCurImage
= 0;
2842 /* initialize overlay mask indices */
2843 for (nCount
= 0; nCount
< MAX_OVERLAYIMAGE
; nCount
++)
2844 himl
->nOvlIdx
[nCount
] = -1;
2846 hbmNew
= ImageList_CreateImage(himl
->hdcImage
, himl
, himl
->cMaxImage
);
2847 SelectObject (himl
->hdcImage
, hbmNew
);
2848 DeleteObject (himl
->hbmImage
);
2849 himl
->hbmImage
= hbmNew
;
2851 if (himl
->hbmMask
) {
2853 imagelist_get_bitmap_size(himl
, himl
->cMaxImage
, &sz
);
2854 hbmNew
= CreateBitmap (sz
.cx
, sz
.cy
, 1, 1, NULL
);
2855 SelectObject (himl
->hdcMask
, hbmNew
);
2856 DeleteObject (himl
->hbmMask
);
2857 himl
->hbmMask
= hbmNew
;
2864 /*************************************************************************
2865 * ImageList_SetImageCount [COMCTL32.@]
2867 * Resizes an image list to the specified number of images.
2870 * himl [I] handle to image list
2871 * iImageCount [I] number of images in the image list
2879 ImageList_SetImageCount (HIMAGELIST himl
, UINT iImageCount
)
2882 HBITMAP hbmNewBitmap
, hbmOld
;
2883 INT nNewCount
, nCopyCount
;
2885 TRACE("%p %d\n",himl
,iImageCount
);
2887 if (!is_valid(himl
))
2890 nNewCount
= iImageCount
+ 1;
2891 nCopyCount
= min(himl
->cCurImage
, iImageCount
);
2893 hdcBitmap
= CreateCompatibleDC (0);
2895 hbmNewBitmap
= ImageList_CreateImage(hdcBitmap
, himl
, nNewCount
);
2897 if (hbmNewBitmap
!= 0)
2899 hbmOld
= SelectObject (hdcBitmap
, hbmNewBitmap
);
2900 imagelist_copy_images( himl
, himl
->hdcImage
, hdcBitmap
, 0, nCopyCount
, 0 );
2901 SelectObject (hdcBitmap
, hbmOld
);
2903 /* FIXME: delete 'empty' image space? */
2905 SelectObject (himl
->hdcImage
, hbmNewBitmap
);
2906 DeleteObject (himl
->hbmImage
);
2907 himl
->hbmImage
= hbmNewBitmap
;
2910 ERR("Could not create new image bitmap!\n");
2915 imagelist_get_bitmap_size( himl
, nNewCount
, &sz
);
2916 hbmNewBitmap
= CreateBitmap (sz
.cx
, sz
.cy
, 1, 1, NULL
);
2917 if (hbmNewBitmap
!= 0)
2919 hbmOld
= SelectObject (hdcBitmap
, hbmNewBitmap
);
2920 imagelist_copy_images( himl
, himl
->hdcMask
, hdcBitmap
, 0, nCopyCount
, 0 );
2921 SelectObject (hdcBitmap
, hbmOld
);
2923 /* FIXME: delete 'empty' image space? */
2925 SelectObject (himl
->hdcMask
, hbmNewBitmap
);
2926 DeleteObject (himl
->hbmMask
);
2927 himl
->hbmMask
= hbmNewBitmap
;
2930 ERR("Could not create new mask bitmap!\n");
2933 DeleteDC (hdcBitmap
);
2935 if (himl
->has_alpha
)
2937 char *new_alpha
= HeapReAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, himl
->has_alpha
, nNewCount
);
2938 if (new_alpha
) himl
->has_alpha
= new_alpha
;
2941 heap_free( himl
->has_alpha
);
2942 himl
->has_alpha
= NULL
;
2946 /* Update max image count and current image count */
2947 himl
->cMaxImage
= nNewCount
;
2948 himl
->cCurImage
= iImageCount
;
2954 /*************************************************************************
2955 * ImageList_SetOverlayImage [COMCTL32.@]
2957 * Assigns an overlay mask index to an existing image in an image list.
2960 * himl [I] handle to image list
2961 * iImage [I] image index
2962 * iOverlay [I] overlay mask index
2970 ImageList_SetOverlayImage (HIMAGELIST himl
, INT iImage
, INT iOverlay
)
2972 if (!is_valid(himl
))
2974 if ((iOverlay
< 1) || (iOverlay
> MAX_OVERLAYIMAGE
))
2976 if ((iImage
!=-1) && ((iImage
< 0) || (iImage
> himl
->cCurImage
)))
2978 himl
->nOvlIdx
[iOverlay
- 1] = iImage
;
2984 /* helper for ImageList_Write - write bitmap to pstm
2985 * currently everything is written as 24 bit RGB, except masks
2987 static BOOL
_write_bitmap(HBITMAP hBitmap
, IStream
*pstm
)
2989 LPBITMAPFILEHEADER bmfh
;
2990 LPBITMAPINFOHEADER bmih
;
2991 LPBYTE data
= NULL
, lpBits
;
2993 INT bitCount
, sizeImage
, offBits
, totalSize
;
2995 BOOL result
= FALSE
;
2997 if (!GetObjectW(hBitmap
, sizeof(BITMAP
), &bm
))
3000 bitCount
= bm
.bmBitsPixel
;
3001 sizeImage
= get_dib_stride(bm
.bmWidth
, bitCount
) * bm
.bmHeight
;
3003 totalSize
= sizeof(BITMAPFILEHEADER
) + sizeof(BITMAPINFOHEADER
);
3005 totalSize
+= (1 << bitCount
) * sizeof(RGBQUAD
);
3006 offBits
= totalSize
;
3007 totalSize
+= sizeImage
;
3009 data
= heap_alloc_zero(totalSize
);
3010 bmfh
= (LPBITMAPFILEHEADER
)data
;
3011 bmih
= (LPBITMAPINFOHEADER
)(data
+ sizeof(BITMAPFILEHEADER
));
3012 lpBits
= data
+ offBits
;
3014 /* setup BITMAPFILEHEADER */
3015 bmfh
->bfType
= (('M' << 8) | 'B');
3016 bmfh
->bfSize
= offBits
;
3017 bmfh
->bfReserved1
= 0;
3018 bmfh
->bfReserved2
= 0;
3019 bmfh
->bfOffBits
= offBits
;
3021 /* setup BITMAPINFOHEADER */
3022 bmih
->biSize
= sizeof(BITMAPINFOHEADER
);
3023 bmih
->biWidth
= bm
.bmWidth
;
3024 bmih
->biHeight
= bm
.bmHeight
;
3026 bmih
->biBitCount
= bitCount
;
3027 bmih
->biCompression
= BI_RGB
;
3028 bmih
->biSizeImage
= sizeImage
;
3029 bmih
->biXPelsPerMeter
= 0;
3030 bmih
->biYPelsPerMeter
= 0;
3031 bmih
->biClrUsed
= 0;
3032 bmih
->biClrImportant
= 0;
3035 result
= GetDIBits(xdc
, hBitmap
, 0, bm
.bmHeight
, lpBits
, (BITMAPINFO
*)bmih
, DIB_RGB_COLORS
) == bm
.bmHeight
;
3040 TRACE("width %u, height %u, planes %u, bpp %u\n",
3041 bmih
->biWidth
, bmih
->biHeight
,
3042 bmih
->biPlanes
, bmih
->biBitCount
);
3044 if(FAILED(IStream_Write(pstm
, data
, totalSize
, NULL
)))
3056 /*************************************************************************
3057 * ImageList_Write [COMCTL32.@]
3059 * Writes an image list to a stream.
3062 * himl [I] handle to image list
3063 * pstm [O] Pointer to a stream.
3073 BOOL WINAPI
ImageList_Write(HIMAGELIST himl
, IStream
*pstm
)
3078 TRACE("%p %p\n", himl
, pstm
);
3080 if (!is_valid(himl
))
3083 ilHead
.usMagic
= (('L' << 8) | 'I');
3084 ilHead
.usVersion
= 0x101;
3085 ilHead
.cCurImage
= himl
->cCurImage
;
3086 ilHead
.cMaxImage
= himl
->cMaxImage
;
3087 ilHead
.cGrow
= himl
->cGrow
;
3088 ilHead
.cx
= himl
->cx
;
3089 ilHead
.cy
= himl
->cy
;
3090 ilHead
.bkcolor
= himl
->clrBk
;
3091 ilHead
.flags
= himl
->flags
;
3092 for(i
= 0; i
< 4; i
++) {
3093 ilHead
.ovls
[i
] = himl
->nOvlIdx
[i
];
3096 TRACE("cx %u, cy %u, flags 0x04%x, cCurImage %u, cMaxImage %u\n",
3097 ilHead
.cx
, ilHead
.cy
, ilHead
.flags
, ilHead
.cCurImage
, ilHead
.cMaxImage
);
3099 if(FAILED(IStream_Write(pstm
, &ilHead
, sizeof(ILHEAD
), NULL
)))
3102 /* write the bitmap */
3103 if(!_write_bitmap(himl
->hbmImage
, pstm
))
3106 /* write the mask if we have one */
3107 if(himl
->flags
& ILC_MASK
) {
3108 if(!_write_bitmap(himl
->hbmMask
, pstm
))
3116 static HBITMAP
ImageList_CreateImage(HDC hdc
, HIMAGELIST himl
, UINT count
)
3118 HBITMAP hbmNewBitmap
;
3119 UINT ilc
= (himl
->flags
& 0xFE);
3122 imagelist_get_bitmap_size( himl
, count
, &sz
);
3124 if ((ilc
>= ILC_COLOR4
&& ilc
<= ILC_COLOR32
) || ilc
== ILC_COLOR
)
3126 char buffer
[sizeof(BITMAPINFOHEADER
) + 256 * sizeof(RGBQUAD
)];
3127 BITMAPINFO
*bmi
= (BITMAPINFO
*)buffer
;
3129 TRACE("Creating DIBSection %d x %d, %d Bits per Pixel\n",
3130 sz
.cx
, sz
.cy
, himl
->uBitsPixel
);
3132 memset( buffer
, 0, sizeof(buffer
) );
3133 bmi
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
3134 bmi
->bmiHeader
.biWidth
= sz
.cx
;
3135 bmi
->bmiHeader
.biHeight
= sz
.cy
;
3136 bmi
->bmiHeader
.biPlanes
= 1;
3137 bmi
->bmiHeader
.biBitCount
= himl
->uBitsPixel
;
3138 bmi
->bmiHeader
.biCompression
= BI_RGB
;
3140 if (himl
->uBitsPixel
<= ILC_COLOR8
)
3142 if (!himl
->color_table_set
)
3144 /* retrieve the default color map */
3145 HBITMAP tmp
= CreateBitmap( 1, 1, 1, 1, NULL
);
3146 GetDIBits( hdc
, tmp
, 0, 0, NULL
, bmi
, DIB_RGB_COLORS
);
3147 DeleteObject( tmp
);
3148 if (ilc
== ILC_COLOR4
)
3151 tmp
= bmi
->bmiColors
[7];
3152 bmi
->bmiColors
[7] = bmi
->bmiColors
[8];
3153 bmi
->bmiColors
[8] = tmp
;
3158 GetDIBColorTable(himl
->hdcImage
, 0, 1 << himl
->uBitsPixel
, bmi
->bmiColors
);
3161 hbmNewBitmap
= CreateDIBSection(hdc
, bmi
, DIB_RGB_COLORS
, NULL
, 0, 0);
3163 else /*if (ilc == ILC_COLORDDB)*/
3165 TRACE("Creating Bitmap: %d Bits per Pixel\n", himl
->uBitsPixel
);
3167 hbmNewBitmap
= CreateBitmap (sz
.cx
, sz
.cy
, 1, himl
->uBitsPixel
, NULL
);
3169 TRACE("returning %p\n", hbmNewBitmap
);
3170 return hbmNewBitmap
;
3173 /*************************************************************************
3174 * ImageList_SetColorTable [COMCTL32.@]
3176 * Sets the color table of an image list.
3179 * himl [I] Handle to the image list.
3180 * uStartIndex [I] The first index to set.
3181 * cEntries [I] Number of entries to set.
3182 * prgb [I] New color information for color table for the image list.
3185 * Success: Number of entries in the table that were set.
3189 * ImageList_Create(), SetDIBColorTable()
3193 ImageList_SetColorTable(HIMAGELIST himl
, UINT uStartIndex
, UINT cEntries
, const RGBQUAD
*prgb
)
3195 TRACE("(%p, %d, %d, %p)\n", himl
, uStartIndex
, cEntries
, prgb
);
3196 himl
->color_table_set
= TRUE
;
3197 return SetDIBColorTable(himl
->hdcImage
, uStartIndex
, cEntries
, prgb
);
3200 /*************************************************************************
3201 * ImageList_CoCreateInstance [COMCTL32.@]
3203 * Creates a new imagelist instance and returns an interface pointer to it.
3206 * rclsid [I] A reference to the CLSID (CLSID_ImageList).
3207 * punkOuter [I] Pointer to IUnknown interface for aggregation, if desired
3208 * riid [I] Identifier of the requested interface.
3209 * ppv [O] Returns the address of the pointer requested, or NULL.
3213 * Failure: Error value.
3216 ImageList_CoCreateInstance (REFCLSID rclsid
, const IUnknown
*punkOuter
, REFIID riid
, void **ppv
)
3218 TRACE("(%s,%p,%s,%p)\n", debugstr_guid(rclsid
), punkOuter
, debugstr_guid(riid
), ppv
);
3220 if (!IsEqualCLSID(&CLSID_ImageList
, rclsid
))
3221 return E_NOINTERFACE
;
3223 return ImageListImpl_CreateInstance(punkOuter
, riid
, ppv
);
3227 /*************************************************************************
3228 * IImageList implementation
3231 static HRESULT WINAPI
ImageListImpl_QueryInterface(IImageList2
*iface
,
3232 REFIID iid
, void **ppv
)
3234 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3236 TRACE("(%p,%s,%p)\n", iface
, debugstr_guid(iid
), ppv
);
3238 if (!ppv
) return E_INVALIDARG
;
3240 if (IsEqualIID(&IID_IUnknown
, iid
) ||
3241 IsEqualIID(&IID_IImageList
, iid
) ||
3242 IsEqualIID(&IID_IImageList2
, iid
))
3244 *ppv
= &imgl
->IImageList2_iface
;
3249 return E_NOINTERFACE
;
3252 IImageList2_AddRef(iface
);
3256 static ULONG WINAPI
ImageListImpl_AddRef(IImageList2
*iface
)
3258 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3259 ULONG ref
= InterlockedIncrement(&imgl
->ref
);
3261 TRACE("(%p) refcount=%u\n", iface
, ref
);
3265 static ULONG WINAPI
ImageListImpl_Release(IImageList2
*iface
)
3267 HIMAGELIST This
= impl_from_IImageList2(iface
);
3268 ULONG ref
= InterlockedDecrement(&This
->ref
);
3270 TRACE("(%p) refcount=%u\n", iface
, ref
);
3274 /* delete image bitmaps */
3275 if (This
->hbmImage
) DeleteObject (This
->hbmImage
);
3276 if (This
->hbmMask
) DeleteObject (This
->hbmMask
);
3278 /* delete image & mask DCs */
3279 if (This
->hdcImage
) DeleteDC (This
->hdcImage
);
3280 if (This
->hdcMask
) DeleteDC (This
->hdcMask
);
3282 /* delete blending brushes */
3283 if (This
->hbrBlend25
) DeleteObject (This
->hbrBlend25
);
3284 if (This
->hbrBlend50
) DeleteObject (This
->hbrBlend50
);
3286 This
->IImageList2_iface
.lpVtbl
= NULL
;
3287 heap_free(This
->has_alpha
);
3294 static HRESULT WINAPI
ImageListImpl_Add(IImageList2
*iface
, HBITMAP hbmImage
,
3295 HBITMAP hbmMask
, int *pi
)
3297 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3303 ret
= ImageList_Add(imgl
, hbmImage
, hbmMask
);
3312 static HRESULT WINAPI
ImageListImpl_ReplaceIcon(IImageList2
*iface
, int i
,
3313 HICON hicon
, int *pi
)
3315 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3321 ret
= ImageList_ReplaceIcon(imgl
, i
, hicon
);
3330 static HRESULT WINAPI
ImageListImpl_SetOverlayImage(IImageList2
*iface
,
3331 int iImage
, int iOverlay
)
3333 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3334 return ImageList_SetOverlayImage(imgl
, iImage
, iOverlay
) ? S_OK
: E_FAIL
;
3337 static HRESULT WINAPI
ImageListImpl_Replace(IImageList2
*iface
, int i
,
3338 HBITMAP hbmImage
, HBITMAP hbmMask
)
3340 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3341 return ImageList_Replace(imgl
, i
, hbmImage
, hbmMask
) ? S_OK
: E_FAIL
;
3344 static HRESULT WINAPI
ImageListImpl_AddMasked(IImageList2
*iface
, HBITMAP hbmImage
,
3345 COLORREF crMask
, int *pi
)
3347 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3353 ret
= ImageList_AddMasked(imgl
, hbmImage
, crMask
);
3362 static HRESULT WINAPI
ImageListImpl_Draw(IImageList2
*iface
,
3363 IMAGELISTDRAWPARAMS
*pimldp
)
3365 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3366 HIMAGELIST old_himl
;
3369 /* As far as I can tell, Windows simply ignores the contents of pimldp->himl
3370 so we shall simulate the same */
3371 old_himl
= pimldp
->himl
;
3372 pimldp
->himl
= imgl
;
3374 ret
= ImageList_DrawIndirect(pimldp
);
3376 pimldp
->himl
= old_himl
;
3377 return ret
? S_OK
: E_INVALIDARG
;
3380 static HRESULT WINAPI
ImageListImpl_Remove(IImageList2
*iface
, int i
)
3382 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3383 return (ImageList_Remove(imgl
, i
) == 0) ? E_INVALIDARG
: S_OK
;
3386 static HRESULT WINAPI
ImageListImpl_GetIcon(IImageList2
*iface
, int i
, UINT flags
,
3389 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3395 hIcon
= ImageList_GetIcon(imgl
, i
, flags
);
3404 static HRESULT WINAPI
ImageListImpl_GetImageInfo(IImageList2
*iface
, int i
,
3405 IMAGEINFO
*pImageInfo
)
3407 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3408 return ImageList_GetImageInfo(imgl
, i
, pImageInfo
) ? S_OK
: E_FAIL
;
3411 static HRESULT WINAPI
ImageListImpl_Copy(IImageList2
*iface
, int dst_index
,
3412 IUnknown
*unk_src
, int src_index
, UINT flags
)
3414 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3415 IImageList
*src
= NULL
;
3421 /* TODO: Add test for IID_ImageList2 too */
3422 if (FAILED(IUnknown_QueryInterface(unk_src
, &IID_IImageList
,
3426 if (ImageList_Copy(imgl
, dst_index
, (HIMAGELIST
) src
, src_index
, flags
))
3431 IImageList_Release(src
);
3435 static HRESULT WINAPI
ImageListImpl_Merge(IImageList2
*iface
, int i1
,
3436 IUnknown
*punk2
, int i2
, int dx
, int dy
, REFIID riid
, void **ppv
)
3438 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3439 IImageList
*iml2
= NULL
;
3441 HRESULT ret
= E_FAIL
;
3443 TRACE("(%p)->(%d %p %d %d %d %s %p)\n", iface
, i1
, punk2
, i2
, dx
, dy
, debugstr_guid(riid
), ppv
);
3445 /* TODO: Add test for IID_ImageList2 too */
3446 if (FAILED(IUnknown_QueryInterface(punk2
, &IID_IImageList
,
3450 merged
= ImageList_Merge(imgl
, i1
, (HIMAGELIST
) iml2
, i2
, dx
, dy
);
3452 /* Get the interface for the new image list */
3455 ret
= HIMAGELIST_QueryInterface(merged
, riid
, ppv
);
3456 ImageList_Destroy(merged
);
3459 IImageList_Release(iml2
);
3463 static HRESULT WINAPI
ImageListImpl_Clone(IImageList2
*iface
, REFIID riid
, void **ppv
)
3465 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3467 HRESULT ret
= E_FAIL
;
3469 TRACE("(%p)->(%s %p)\n", iface
, debugstr_guid(riid
), ppv
);
3471 clone
= ImageList_Duplicate(imgl
);
3473 /* Get the interface for the new image list */
3476 ret
= HIMAGELIST_QueryInterface(clone
, riid
, ppv
);
3477 ImageList_Destroy(clone
);
3483 static HRESULT WINAPI
ImageListImpl_GetImageRect(IImageList2
*iface
, int i
,
3486 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3492 if (!ImageList_GetImageInfo(imgl
, i
, &info
))
3495 *prc
= info
.rcImage
;
3500 static HRESULT WINAPI
ImageListImpl_GetIconSize(IImageList2
*iface
, int *cx
,
3503 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3504 return ImageList_GetIconSize(imgl
, cx
, cy
) ? S_OK
: E_INVALIDARG
;
3507 static HRESULT WINAPI
ImageListImpl_SetIconSize(IImageList2
*iface
, int cx
,
3510 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3511 return ImageList_SetIconSize(imgl
, cx
, cy
) ? S_OK
: E_FAIL
;
3514 static HRESULT WINAPI
ImageListImpl_GetImageCount(IImageList2
*iface
, int *pi
)
3516 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3517 *pi
= ImageList_GetImageCount(imgl
);
3521 static HRESULT WINAPI
ImageListImpl_SetImageCount(IImageList2
*iface
, UINT count
)
3523 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3524 return ImageList_SetImageCount(imgl
, count
) ? S_OK
: E_FAIL
;
3527 static HRESULT WINAPI
ImageListImpl_SetBkColor(IImageList2
*iface
, COLORREF clrBk
,
3530 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3531 *pclr
= ImageList_SetBkColor(imgl
, clrBk
);
3535 static HRESULT WINAPI
ImageListImpl_GetBkColor(IImageList2
*iface
, COLORREF
*pclr
)
3537 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3538 *pclr
= ImageList_GetBkColor(imgl
);
3542 static HRESULT WINAPI
ImageListImpl_BeginDrag(IImageList2
*iface
, int iTrack
,
3543 int dxHotspot
, int dyHotspot
)
3545 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3546 return ImageList_BeginDrag(imgl
, iTrack
, dxHotspot
, dyHotspot
) ? S_OK
: E_FAIL
;
3549 static HRESULT WINAPI
ImageListImpl_EndDrag(IImageList2
*iface
)
3551 ImageList_EndDrag();
3555 static HRESULT WINAPI
ImageListImpl_DragEnter(IImageList2
*iface
, HWND hwndLock
,
3558 return ImageList_DragEnter(hwndLock
, x
, y
) ? S_OK
: E_FAIL
;
3561 static HRESULT WINAPI
ImageListImpl_DragLeave(IImageList2
*iface
, HWND hwndLock
)
3563 return ImageList_DragLeave(hwndLock
) ? S_OK
: E_FAIL
;
3566 static HRESULT WINAPI
ImageListImpl_DragMove(IImageList2
*iface
, int x
, int y
)
3568 return ImageList_DragMove(x
, y
) ? S_OK
: E_FAIL
;
3571 static HRESULT WINAPI
ImageListImpl_SetDragCursorImage(IImageList2
*iface
,
3572 IUnknown
*punk
, int iDrag
, int dxHotspot
, int dyHotspot
)
3574 IImageList
*iml2
= NULL
;
3580 /* TODO: Add test for IID_ImageList2 too */
3581 if (FAILED(IUnknown_QueryInterface(punk
, &IID_IImageList
,
3585 ret
= ImageList_SetDragCursorImage((HIMAGELIST
) iml2
, iDrag
, dxHotspot
,
3588 IImageList_Release(iml2
);
3590 return ret
? S_OK
: E_FAIL
;
3593 static HRESULT WINAPI
ImageListImpl_DragShowNolock(IImageList2
*iface
, BOOL fShow
)
3595 return ImageList_DragShowNolock(fShow
) ? S_OK
: E_FAIL
;
3598 static HRESULT WINAPI
ImageListImpl_GetDragImage(IImageList2
*iface
, POINT
*ppt
,
3599 POINT
*pptHotspot
, REFIID riid
, PVOID
*ppv
)
3601 HRESULT ret
= E_FAIL
;
3607 hNew
= ImageList_GetDragImage(ppt
, pptHotspot
);
3609 /* Get the interface for the new image list */
3612 IImageList
*idrag
= (IImageList
*)hNew
;
3614 ret
= HIMAGELIST_QueryInterface(hNew
, riid
, ppv
);
3615 IImageList_Release(idrag
);
3621 static HRESULT WINAPI
ImageListImpl_GetItemFlags(IImageList2
*iface
, int i
,
3624 FIXME("STUB: %p %d %p\n", iface
, i
, dwFlags
);
3628 static HRESULT WINAPI
ImageListImpl_GetOverlayImage(IImageList2
*iface
, int iOverlay
,
3631 HIMAGELIST This
= impl_from_IImageList2(iface
);
3634 if ((iOverlay
< 0) || (iOverlay
> This
->cCurImage
))
3637 for (i
= 0; i
< MAX_OVERLAYIMAGE
; i
++)
3639 if (This
->nOvlIdx
[i
] == iOverlay
)
3649 static HRESULT WINAPI
ImageListImpl_Resize(IImageList2
*iface
, INT cx
, INT cy
)
3651 FIXME("(%p)->(%d %d): stub\n", iface
, cx
, cy
);
3655 static HRESULT WINAPI
ImageListImpl_GetOriginalSize(IImageList2
*iface
, INT image
, DWORD flags
, INT
*cx
, INT
*cy
)
3657 FIXME("(%p)->(%d %x %p %p): stub\n", iface
, image
, flags
, cx
, cy
);
3661 static HRESULT WINAPI
ImageListImpl_SetOriginalSize(IImageList2
*iface
, INT image
, INT cx
, INT cy
)
3663 FIXME("(%p)->(%d %d %d): stub\n", iface
, image
, cx
, cy
);
3667 static HRESULT WINAPI
ImageListImpl_SetCallback(IImageList2
*iface
, IUnknown
*callback
)
3669 FIXME("(%p)->(%p): stub\n", iface
, callback
);
3673 static HRESULT WINAPI
ImageListImpl_GetCallback(IImageList2
*iface
, REFIID riid
, void **ppv
)
3675 FIXME("(%p)->(%s %p): stub\n", iface
, debugstr_guid(riid
), ppv
);
3679 static HRESULT WINAPI
ImageListImpl_ForceImagePresent(IImageList2
*iface
, INT image
, DWORD flags
)
3681 FIXME("(%p)->(%d %x): stub\n", iface
, image
, flags
);
3685 static HRESULT WINAPI
ImageListImpl_DiscardImages(IImageList2
*iface
, INT first_image
, INT last_image
, DWORD flags
)
3687 FIXME("(%p)->(%d %d %x): stub\n", iface
, first_image
, last_image
, flags
);
3691 static HRESULT WINAPI
ImageListImpl_PreloadImages(IImageList2
*iface
, IMAGELISTDRAWPARAMS
*params
)
3693 FIXME("(%p)->(%p): stub\n", iface
, params
);
3697 static HRESULT WINAPI
ImageListImpl_GetStatistics(IImageList2
*iface
, IMAGELISTSTATS
*stats
)
3699 FIXME("(%p)->(%p): stub\n", iface
, stats
);
3703 static HRESULT WINAPI
ImageListImpl_Initialize(IImageList2
*iface
, INT cx
, INT cy
, UINT flags
, INT initial
, INT grow
)
3705 FIXME("(%p)->(%d %d %d %d %d): stub\n", iface
, cx
, cy
, flags
, initial
, grow
);
3709 static HRESULT WINAPI
ImageListImpl_Replace2(IImageList2
*iface
, INT i
, HBITMAP image
, HBITMAP mask
, IUnknown
*unk
, DWORD flags
)
3711 FIXME("(%p)->(%d %p %p %p %x): stub\n", iface
, i
, image
, mask
, unk
, flags
);
3715 static HRESULT WINAPI
ImageListImpl_ReplaceFromImageList(IImageList2
*iface
, INT i
, IImageList
*imagelist
, INT src
,
3716 IUnknown
*unk
, DWORD flags
)
3718 FIXME("(%p)->(%d %p %d %p %x): stub\n", iface
, i
, imagelist
, src
, unk
, flags
);
3722 static const IImageList2Vtbl ImageListImpl_Vtbl
= {
3723 ImageListImpl_QueryInterface
,
3724 ImageListImpl_AddRef
,
3725 ImageListImpl_Release
,
3727 ImageListImpl_ReplaceIcon
,
3728 ImageListImpl_SetOverlayImage
,
3729 ImageListImpl_Replace
,
3730 ImageListImpl_AddMasked
,
3732 ImageListImpl_Remove
,
3733 ImageListImpl_GetIcon
,
3734 ImageListImpl_GetImageInfo
,
3736 ImageListImpl_Merge
,
3737 ImageListImpl_Clone
,
3738 ImageListImpl_GetImageRect
,
3739 ImageListImpl_GetIconSize
,
3740 ImageListImpl_SetIconSize
,
3741 ImageListImpl_GetImageCount
,
3742 ImageListImpl_SetImageCount
,
3743 ImageListImpl_SetBkColor
,
3744 ImageListImpl_GetBkColor
,
3745 ImageListImpl_BeginDrag
,
3746 ImageListImpl_EndDrag
,
3747 ImageListImpl_DragEnter
,
3748 ImageListImpl_DragLeave
,
3749 ImageListImpl_DragMove
,
3750 ImageListImpl_SetDragCursorImage
,
3751 ImageListImpl_DragShowNolock
,
3752 ImageListImpl_GetDragImage
,
3753 ImageListImpl_GetItemFlags
,
3754 ImageListImpl_GetOverlayImage
,
3755 ImageListImpl_Resize
,
3756 ImageListImpl_GetOriginalSize
,
3757 ImageListImpl_SetOriginalSize
,
3758 ImageListImpl_SetCallback
,
3759 ImageListImpl_GetCallback
,
3760 ImageListImpl_ForceImagePresent
,
3761 ImageListImpl_DiscardImages
,
3762 ImageListImpl_PreloadImages
,
3763 ImageListImpl_GetStatistics
,
3764 ImageListImpl_Initialize
,
3765 ImageListImpl_Replace2
,
3766 ImageListImpl_ReplaceFromImageList
3769 static BOOL
is_valid(HIMAGELIST himl
)
3774 valid
= himl
&& himl
->IImageList2_iface
.lpVtbl
== &ImageListImpl_Vtbl
;
3784 /*************************************************************************
3785 * HIMAGELIST_QueryInterface [COMCTL32.@]
3787 * Returns a pointer to an IImageList or IImageList2 object for the given
3791 * himl [I] Image list handle.
3792 * riid [I] Identifier of the requested interface.
3793 * ppv [O] Returns the address of the pointer requested, or NULL.
3797 * Failure: Error value.
3800 HIMAGELIST_QueryInterface (HIMAGELIST himl
, REFIID riid
, void **ppv
)
3802 TRACE("(%p,%s,%p)\n", himl
, debugstr_guid(riid
), ppv
);
3803 return IImageList2_QueryInterface((IImageList2
*) himl
, riid
, ppv
);
3806 static HRESULT
ImageListImpl_CreateInstance(const IUnknown
*pUnkOuter
, REFIID iid
, void** ppv
)
3811 TRACE("(%p,%s,%p)\n", pUnkOuter
, debugstr_guid(iid
), ppv
);
3815 if (pUnkOuter
) return CLASS_E_NOAGGREGATION
;
3817 This
= heap_alloc_zero(sizeof(struct _IMAGELIST
));
3818 if (!This
) return E_OUTOFMEMORY
;
3820 This
->IImageList2_iface
.lpVtbl
= &ImageListImpl_Vtbl
;
3823 ret
= IImageList2_QueryInterface(&This
->IImageList2_iface
, iid
, ppv
);
3824 IImageList2_Release(&This
->IImageList2_iface
);