2 * ImageList implementation
4 * Copyright 1998 Eric Kohl
5 * Copyright 2000 Jason Mawdsley
6 * Copyright 2001, 2004 Michael Stefaniuc
7 * Copyright 2001 Charles Loep for CodeWeavers
8 * Copyright 2002 Dimitrie O. Paun
9 * Copyright 2009 Owen Rudge for CodeWeavers
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public
13 * License as published by the Free Software Foundation; either
14 * version 2.1 of the License, or (at your option) any later version.
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with this library; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
27 * This code was audited for completeness against the documented features
28 * of Comctl32.dll version 6.0 on Sep. 12, 2002, by Dimitrie O. Paun.
30 * Unless otherwise noted, we believe this code to be complete, as per
31 * the specification mentioned above.
32 * If you discover missing features, or bugs, please note them below.
35 * - Add support for ILD_PRESERVEALPHA, ILD_SCALE, ILD_DPISCALE
36 * - Add support for ILS_GLOW, ILS_SHADOW, ILS_SATURATE
37 * - Thread-safe locking
42 #include <commoncontrols.h>
43 #include <wine/exception.h>
45 WINE_DEFAULT_DEBUG_CHANNEL(imagelist
);
47 #define MAX_OVERLAYIMAGE 15
51 IImageList2 IImageList2_iface
; /* 00: IImageList vtable */
52 INT cCurImage
; /* 04: ImageCount */
53 INT cMaxImage
; /* 08: maximages */
54 INT cGrow
; /* 0C: cGrow */
58 UINT flags
; /* 1C: flags */
59 COLORREF clrFg
; /* 20: foreground color */
60 COLORREF clrBk
; /* 24: background color */
63 HBITMAP hbmImage
; /* 28: images Bitmap */
64 HBITMAP hbmMask
; /* 2C: masks Bitmap */
65 HDC hdcImage
; /* 30: images MemDC */
66 HDC hdcMask
; /* 34: masks MemDC */
67 INT nOvlIdx
[MAX_OVERLAYIMAGE
]; /* 38: overlay images index */
69 /* not yet found out */
76 LONG ref
; /* reference count */
79 #define IMAGELIST_MAGIC 0x53414D58
81 /* Header used by ImageList_Read() and ImageList_Write() */
83 typedef struct _ILHEAD
98 /* internal image list data used for Drag & Drop operations */
103 HIMAGELIST himlNoCursor
;
104 /* position of the drag image relative to the window */
107 /* offset of the hotspot relative to the origin of the image */
110 /* is the drag image visible */
112 /* saved background */
116 static INTERNALDRAG InternalDrag
= { 0, 0, 0, 0, 0, 0, 0, FALSE
, 0 };
118 static inline HIMAGELIST
impl_from_IImageList2(IImageList2
*iface
)
120 return CONTAINING_RECORD(iface
, struct _IMAGELIST
, IImageList2_iface
);
123 static HBITMAP
ImageList_CreateImage(HDC hdc
, HIMAGELIST himl
, UINT count
);
124 static HRESULT
ImageListImpl_CreateInstance(const IUnknown
*pUnkOuter
, REFIID iid
, void** ppv
);
125 static BOOL
is_valid(HIMAGELIST himl
);
128 * An imagelist with N images is tiled like this:
140 static inline UINT
imagelist_height( UINT count
)
142 return ((count
+ TILE_COUNT
- 1)/TILE_COUNT
);
145 static inline void imagelist_point_from_index( HIMAGELIST himl
, UINT index
, LPPOINT pt
)
147 pt
->x
= (index
%TILE_COUNT
) * himl
->cx
;
148 pt
->y
= (index
/TILE_COUNT
) * himl
->cy
;
151 static inline void imagelist_get_bitmap_size( HIMAGELIST himl
, UINT count
, SIZE
*sz
)
153 sz
->cx
= himl
->cx
* TILE_COUNT
;
154 sz
->cy
= imagelist_height( count
) * himl
->cy
;
157 static inline int get_dib_stride( int width
, int bpp
)
159 return ((width
* bpp
+ 31) >> 3) & ~3;
162 static inline int get_dib_image_size( const BITMAPINFO
*info
)
164 return get_dib_stride( info
->bmiHeader
.biWidth
, info
->bmiHeader
.biBitCount
)
165 * abs( info
->bmiHeader
.biHeight
);
169 * imagelist_copy_images()
171 * Copies a block of count images from offset src in the list to offset dest.
172 * Images are copied a row at at time. Assumes hdcSrc and hdcDest are different.
174 static inline void imagelist_copy_images( HIMAGELIST himl
, HDC hdcSrc
, HDC hdcDest
,
175 UINT src
, UINT count
, UINT dest
)
181 for ( i
=0; i
<TILE_COUNT
; i
++ )
183 imagelist_point_from_index( himl
, src
+i
, &ptSrc
);
184 imagelist_point_from_index( himl
, dest
+i
, &ptDest
);
186 sz
.cy
= himl
->cy
* imagelist_height( count
- i
);
188 BitBlt( hdcDest
, ptDest
.x
, ptDest
.y
, sz
.cx
, sz
.cy
,
189 hdcSrc
, ptSrc
.x
, ptSrc
.y
, SRCCOPY
);
193 static void add_dib_bits( HIMAGELIST himl
, int pos
, int count
, int width
, int height
,
194 BITMAPINFO
*info
, BITMAPINFO
*mask_info
, DWORD
*bits
, BYTE
*mask_bits
)
198 int stride
= info
->bmiHeader
.biWidth
;
199 int mask_stride
= (info
->bmiHeader
.biWidth
+ 31) / 32 * 4;
201 for (n
= 0; n
< count
; n
++)
203 BOOL has_alpha
= FALSE
;
205 imagelist_point_from_index( himl
, pos
+ n
, &pt
);
207 /* check if bitmap has an alpha channel */
208 for (i
= 0; i
< height
&& !has_alpha
; i
++)
209 for (j
= n
* width
; j
< (n
+ 1) * width
; j
++)
210 if ((has_alpha
= ((bits
[i
* stride
+ j
] & 0xff000000) != 0))) break;
212 if (!has_alpha
) /* generate alpha channel from the mask */
214 for (i
= 0; i
< height
; i
++)
215 for (j
= n
* width
; j
< (n
+ 1) * width
; j
++)
216 if (!mask_info
|| !((mask_bits
[i
* mask_stride
+ j
/ 8] << (j
% 8)) & 0x80))
217 bits
[i
* stride
+ j
] |= 0xff000000;
219 bits
[i
* stride
+ j
] = 0;
223 himl
->has_alpha
[pos
+ n
] = 1;
225 if (mask_info
&& himl
->hbmMask
) /* generate the mask from the alpha channel */
227 for (i
= 0; i
< height
; i
++)
228 for (j
= n
* width
; j
< (n
+ 1) * width
; j
++)
229 if ((bits
[i
* stride
+ j
] >> 24) > 25) /* more than 10% alpha */
230 mask_bits
[i
* mask_stride
+ j
/ 8] &= ~(0x80 >> (j
% 8));
232 mask_bits
[i
* mask_stride
+ j
/ 8] |= 0x80 >> (j
% 8);
235 StretchDIBits( himl
->hdcImage
, pt
.x
, pt
.y
, himl
->cx
, himl
->cy
,
236 n
* width
, 0, width
, height
, bits
, info
, DIB_RGB_COLORS
, SRCCOPY
);
238 StretchDIBits( himl
->hdcMask
, pt
.x
, pt
.y
, himl
->cx
, himl
->cy
,
239 n
* width
, 0, width
, height
, mask_bits
, mask_info
, DIB_RGB_COLORS
, SRCCOPY
);
243 /* add images with an alpha channel when the image list is 32 bpp */
244 static BOOL
add_with_alpha( HIMAGELIST himl
, HDC hdc
, int pos
, int count
,
245 int width
, int height
, HBITMAP hbmImage
, HBITMAP hbmMask
)
249 BITMAPINFO
*info
, *mask_info
= NULL
;
251 BYTE
*mask_bits
= NULL
;
254 if (!GetObjectW( hbmImage
, sizeof(bm
), &bm
)) return FALSE
;
256 /* if either the imagelist or the source bitmap don't have an alpha channel, bail out now */
257 if (!himl
->has_alpha
) return FALSE
;
258 if (bm
.bmBitsPixel
!= 32) return FALSE
;
260 SelectObject( hdc
, hbmImage
);
261 mask_width
= (bm
.bmWidth
+ 31) / 32 * 4;
263 if (!(info
= HeapAlloc( GetProcessHeap(), 0, FIELD_OFFSET( BITMAPINFO
, bmiColors
[256] )))) goto done
;
264 info
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
265 info
->bmiHeader
.biWidth
= bm
.bmWidth
;
266 info
->bmiHeader
.biHeight
= -height
;
267 info
->bmiHeader
.biPlanes
= 1;
268 info
->bmiHeader
.biBitCount
= 32;
269 info
->bmiHeader
.biCompression
= BI_RGB
;
270 info
->bmiHeader
.biSizeImage
= bm
.bmWidth
* height
* 4;
271 info
->bmiHeader
.biXPelsPerMeter
= 0;
272 info
->bmiHeader
.biYPelsPerMeter
= 0;
273 info
->bmiHeader
.biClrUsed
= 0;
274 info
->bmiHeader
.biClrImportant
= 0;
275 if (!(bits
= HeapAlloc( GetProcessHeap(), 0, info
->bmiHeader
.biSizeImage
))) goto done
;
276 if (!GetDIBits( hdc
, hbmImage
, 0, height
, bits
, info
, DIB_RGB_COLORS
)) goto done
;
280 if (!(mask_info
= HeapAlloc( GetProcessHeap(), 0, FIELD_OFFSET( BITMAPINFO
, bmiColors
[2] ))))
282 mask_info
->bmiHeader
= info
->bmiHeader
;
283 mask_info
->bmiHeader
.biBitCount
= 1;
284 mask_info
->bmiHeader
.biSizeImage
= mask_width
* height
;
285 if (!(mask_bits
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, info
->bmiHeader
.biSizeImage
)))
287 if (!GetDIBits( hdc
, hbmMask
, 0, height
, mask_bits
, mask_info
, DIB_RGB_COLORS
)) goto done
;
290 add_dib_bits( himl
, pos
, count
, width
, height
, info
, mask_info
, bits
, mask_bits
);
294 HeapFree( GetProcessHeap(), 0, info
);
295 HeapFree( GetProcessHeap(), 0, mask_info
);
296 HeapFree( GetProcessHeap(), 0, bits
);
297 HeapFree( GetProcessHeap(), 0, mask_bits
);
301 /*************************************************************************
302 * IMAGELIST_InternalExpandBitmaps [Internal]
304 * Expands the bitmaps of an image list by the given number of images.
307 * himl [I] handle to image list
308 * nImageCount [I] number of images to add
314 * This function CANNOT be used to reduce the number of images.
317 IMAGELIST_InternalExpandBitmaps(HIMAGELIST himl
, INT nImageCount
)
320 HBITMAP hbmNewBitmap
, hbmNull
;
324 TRACE("%p has allocated %d, max %d, grow %d images\n", himl
, himl
->cCurImage
, himl
->cMaxImage
, himl
->cGrow
);
326 if (himl
->cCurImage
+ nImageCount
< himl
->cMaxImage
)
329 nNewCount
= himl
->cMaxImage
+ max(nImageCount
, himl
->cGrow
) + 1;
331 imagelist_get_bitmap_size(himl
, nNewCount
, &sz
);
333 TRACE("Create expanded bitmaps : himl=%p x=%d y=%d count=%d\n", himl
, sz
.cx
, sz
.cy
, nNewCount
);
334 hdcBitmap
= CreateCompatibleDC (0);
336 hbmNewBitmap
= ImageList_CreateImage(hdcBitmap
, himl
, nNewCount
);
338 if (hbmNewBitmap
== 0)
339 ERR("creating new image bitmap (x=%d y=%d)!\n", sz
.cx
, sz
.cy
);
343 hbmNull
= SelectObject (hdcBitmap
, hbmNewBitmap
);
344 BitBlt (hdcBitmap
, 0, 0, sz
.cx
, sz
.cy
,
345 himl
->hdcImage
, 0, 0, SRCCOPY
);
346 SelectObject (hdcBitmap
, hbmNull
);
348 SelectObject (himl
->hdcImage
, hbmNewBitmap
);
349 DeleteObject (himl
->hbmImage
);
350 himl
->hbmImage
= hbmNewBitmap
;
352 if (himl
->flags
& ILC_MASK
)
354 hbmNewBitmap
= CreateBitmap (sz
.cx
, sz
.cy
, 1, 1, NULL
);
356 if (hbmNewBitmap
== 0)
357 ERR("creating new mask bitmap!\n");
361 hbmNull
= SelectObject (hdcBitmap
, hbmNewBitmap
);
362 BitBlt (hdcBitmap
, 0, 0, sz
.cx
, sz
.cy
,
363 himl
->hdcMask
, 0, 0, SRCCOPY
);
364 SelectObject (hdcBitmap
, hbmNull
);
366 SelectObject (himl
->hdcMask
, hbmNewBitmap
);
367 DeleteObject (himl
->hbmMask
);
368 himl
->hbmMask
= hbmNewBitmap
;
373 char *new_alpha
= HeapReAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, himl
->has_alpha
, nNewCount
);
374 if (new_alpha
) himl
->has_alpha
= new_alpha
;
377 HeapFree( GetProcessHeap(), 0, himl
->has_alpha
);
378 himl
->has_alpha
= NULL
;
382 himl
->cMaxImage
= nNewCount
;
384 DeleteDC (hdcBitmap
);
388 /*************************************************************************
389 * ImageList_Add [COMCTL32.@]
391 * Add an image or images to an image list.
394 * himl [I] handle to image list
395 * hbmImage [I] handle to image bitmap
396 * hbmMask [I] handle to mask bitmap
399 * Success: Index of the first new image.
404 ImageList_Add (HIMAGELIST himl
, HBITMAP hbmImage
, HBITMAP hbmMask
)
406 HDC hdcBitmap
, hdcTemp
= 0;
407 INT nFirstIndex
, nImageCount
, i
;
411 TRACE("himl=%p hbmimage=%p hbmmask=%p\n", himl
, hbmImage
, hbmMask
);
415 if (!GetObjectW(hbmImage
, sizeof(BITMAP
), &bmp
))
418 TRACE("himl %p, cCurImage %d, cMaxImage %d, cGrow %d, cx %d, cy %d\n",
419 himl
, himl
->cCurImage
, himl
->cMaxImage
, himl
->cGrow
, himl
->cx
, himl
->cy
);
421 nImageCount
= bmp
.bmWidth
/ himl
->cx
;
423 TRACE("%p has %d images (%d x %d)\n", hbmImage
, nImageCount
, bmp
.bmWidth
, bmp
.bmHeight
);
425 IMAGELIST_InternalExpandBitmaps(himl
, nImageCount
);
427 hdcBitmap
= CreateCompatibleDC(0);
429 SelectObject(hdcBitmap
, hbmImage
);
431 if (add_with_alpha( himl
, hdcBitmap
, himl
->cCurImage
, nImageCount
,
432 himl
->cx
, min( himl
->cy
, bmp
.bmHeight
), hbmImage
, hbmMask
))
437 hdcTemp
= CreateCompatibleDC(0);
438 SelectObject(hdcTemp
, hbmMask
);
441 for (i
=0; i
<nImageCount
; i
++)
443 imagelist_point_from_index( himl
, himl
->cCurImage
+ i
, &pt
);
445 /* Copy result to the imagelist
447 BitBlt( himl
->hdcImage
, pt
.x
, pt
.y
, himl
->cx
, bmp
.bmHeight
,
448 hdcBitmap
, i
*himl
->cx
, 0, SRCCOPY
);
453 BitBlt( himl
->hdcMask
, pt
.x
, pt
.y
, himl
->cx
, bmp
.bmHeight
,
454 hdcTemp
, i
*himl
->cx
, 0, SRCCOPY
);
456 /* Remove the background from the image
458 BitBlt( himl
->hdcImage
, pt
.x
, pt
.y
, himl
->cx
, bmp
.bmHeight
,
459 himl
->hdcMask
, pt
.x
, pt
.y
, 0x220326 ); /* NOTSRCAND */
461 if (hdcTemp
) DeleteDC(hdcTemp
);
466 nFirstIndex
= himl
->cCurImage
;
467 himl
->cCurImage
+= nImageCount
;
473 /*************************************************************************
474 * ImageList_AddIcon [COMCTL32.@]
476 * Adds an icon to an image list.
479 * himl [I] handle to image list
480 * hIcon [I] handle to icon
483 * Success: index of the new image
486 #undef ImageList_AddIcon
487 INT WINAPI
ImageList_AddIcon (HIMAGELIST himl
, HICON hIcon
)
489 return ImageList_ReplaceIcon (himl
, -1, hIcon
);
493 /*************************************************************************
494 * ImageList_AddMasked [COMCTL32.@]
496 * Adds an image or images to an image list and creates a mask from the
497 * specified bitmap using the mask color.
500 * himl [I] handle to image list.
501 * hBitmap [I] handle to bitmap
502 * clrMask [I] mask color.
505 * Success: Index of the first new image.
510 ImageList_AddMasked (HIMAGELIST himl
, HBITMAP hBitmap
, COLORREF clrMask
)
512 HDC hdcMask
, hdcBitmap
;
518 TRACE("himl=%p hbitmap=%p clrmask=%x\n", himl
, hBitmap
, clrMask
);
522 if (!GetObjectW(hBitmap
, sizeof(BITMAP
), &bmp
))
525 hdcBitmap
= CreateCompatibleDC(0);
526 SelectObject(hdcBitmap
, hBitmap
);
528 /* Create a temp Mask so we can remove the background of the Image */
529 hdcMask
= CreateCompatibleDC(0);
530 hMaskBitmap
= CreateBitmap(bmp
.bmWidth
, bmp
.bmHeight
, 1, 1, NULL
);
531 SelectObject(hdcMask
, hMaskBitmap
);
533 /* create monochrome image to the mask bitmap */
534 bkColor
= (clrMask
!= CLR_DEFAULT
) ? clrMask
: GetPixel (hdcBitmap
, 0, 0);
535 SetBkColor (hdcBitmap
, bkColor
);
536 BitBlt (hdcMask
, 0, 0, bmp
.bmWidth
, bmp
.bmHeight
, hdcBitmap
, 0, 0, SRCCOPY
);
539 * Remove the background from the image
541 * WINDOWS BUG ALERT!!!!!!
542 * The statement below should not be done in common practice
543 * but this is how ImageList_AddMasked works in Windows.
544 * It overwrites the original bitmap passed, this was discovered
545 * by using the same bitmap to iterate the different styles
546 * on windows where it failed (BUT ImageList_Add is OK)
547 * This is here in case some apps rely on this bug
549 * Blt mode 0x220326 is NOTSRCAND
551 if (bmp
.bmBitsPixel
> 8) /* NOTSRCAND can't work with palettes */
553 SetBkColor(hdcBitmap
, RGB(255,255,255));
554 BitBlt(hdcBitmap
, 0, 0, bmp
.bmWidth
, bmp
.bmHeight
, hdcMask
, 0, 0, 0x220326);
560 ret
= ImageList_Add( himl
, hBitmap
, hMaskBitmap
);
562 DeleteObject(hMaskBitmap
);
567 /*************************************************************************
568 * ImageList_BeginDrag [COMCTL32.@]
570 * Creates a temporary image list that contains one image. It will be used
574 * himlTrack [I] handle to the source image list
575 * iTrack [I] index of the drag image in the source image list
576 * dxHotspot [I] X position of the hot spot of the drag image
577 * dyHotspot [I] Y position of the hot spot of the drag image
585 ImageList_BeginDrag (HIMAGELIST himlTrack
, INT iTrack
,
586 INT dxHotspot
, INT dyHotspot
)
590 TRACE("(himlTrack=%p iTrack=%d dx=%d dy=%d)\n", himlTrack
, iTrack
,
591 dxHotspot
, dyHotspot
);
593 if (!is_valid(himlTrack
))
596 if (InternalDrag
.himl
)
597 ImageList_EndDrag ();
602 InternalDrag
.himlNoCursor
= InternalDrag
.himl
= ImageList_Create (cx
, cy
, himlTrack
->flags
, 1, 1);
603 if (InternalDrag
.himl
== NULL
) {
604 WARN("Error creating drag image list!\n");
608 InternalDrag
.dxHotspot
= dxHotspot
;
609 InternalDrag
.dyHotspot
= dyHotspot
;
612 BitBlt (InternalDrag
.himl
->hdcImage
, 0, 0, cx
, cy
, himlTrack
->hdcImage
, iTrack
* cx
, 0, SRCCOPY
);
615 BitBlt (InternalDrag
.himl
->hdcMask
, 0, 0, cx
, cy
, himlTrack
->hdcMask
, iTrack
* cx
, 0, SRCCOPY
);
617 InternalDrag
.himl
->cCurImage
= 1;
623 /*************************************************************************
624 * ImageList_Copy [COMCTL32.@]
626 * Copies an image of the source image list to an image of the
627 * destination image list. Images can be copied or swapped.
630 * himlDst [I] handle to the destination image list
631 * iDst [I] destination image index.
632 * himlSrc [I] handle to the source image list
633 * iSrc [I] source image index
634 * uFlags [I] flags for the copy operation
641 * Copying from one image list to another is possible. The original
642 * implementation just copies or swaps within one image list.
643 * Could this feature become a bug??? ;-)
647 ImageList_Copy (HIMAGELIST himlDst
, INT iDst
, HIMAGELIST himlSrc
,
648 INT iSrc
, UINT uFlags
)
652 TRACE("himlDst=%p iDst=%d himlSrc=%p iSrc=%d\n", himlDst
, iDst
, himlSrc
, iSrc
);
654 if (!is_valid(himlSrc
) || !is_valid(himlDst
))
656 if ((iDst
< 0) || (iDst
>= himlDst
->cCurImage
))
658 if ((iSrc
< 0) || (iSrc
>= himlSrc
->cCurImage
))
661 imagelist_point_from_index( himlDst
, iDst
, &ptDst
);
662 imagelist_point_from_index( himlSrc
, iSrc
, &ptSrc
);
664 if (uFlags
& ILCF_SWAP
) {
667 HBITMAP hbmTempImage
, hbmTempMask
;
669 hdcBmp
= CreateCompatibleDC (0);
671 /* create temporary bitmaps */
672 hbmTempImage
= CreateBitmap (himlSrc
->cx
, himlSrc
->cy
, 1,
673 himlSrc
->uBitsPixel
, NULL
);
674 hbmTempMask
= CreateBitmap (himlSrc
->cx
, himlSrc
->cy
, 1,
677 /* copy (and stretch) destination to temporary bitmaps.(save) */
679 SelectObject (hdcBmp
, hbmTempImage
);
680 StretchBlt (hdcBmp
, 0, 0, himlSrc
->cx
, himlSrc
->cy
,
681 himlDst
->hdcImage
, ptDst
.x
, ptDst
.y
, himlDst
->cx
, himlDst
->cy
,
684 SelectObject (hdcBmp
, hbmTempMask
);
685 StretchBlt (hdcBmp
, 0, 0, himlSrc
->cx
, himlSrc
->cy
,
686 himlDst
->hdcMask
, ptDst
.x
, ptDst
.y
, himlDst
->cx
, himlDst
->cy
,
689 /* copy (and stretch) source to destination */
691 StretchBlt (himlDst
->hdcImage
, ptDst
.x
, ptDst
.y
, himlDst
->cx
, himlDst
->cy
,
692 himlSrc
->hdcImage
, ptSrc
.x
, ptSrc
.y
, himlSrc
->cx
, himlSrc
->cy
,
695 StretchBlt (himlDst
->hdcMask
, ptDst
.x
, ptDst
.y
, himlDst
->cx
, himlDst
->cy
,
696 himlSrc
->hdcMask
, ptSrc
.x
, ptSrc
.y
, himlSrc
->cx
, himlSrc
->cy
,
699 /* copy (without stretching) temporary bitmaps to source (restore) */
701 BitBlt (himlSrc
->hdcMask
, ptSrc
.x
, ptSrc
.y
, himlSrc
->cx
, himlSrc
->cy
,
702 hdcBmp
, 0, 0, SRCCOPY
);
705 BitBlt (himlSrc
->hdcImage
, ptSrc
.x
, ptSrc
.y
, himlSrc
->cx
, himlSrc
->cy
,
706 hdcBmp
, 0, 0, SRCCOPY
);
707 /* delete temporary bitmaps */
708 DeleteObject (hbmTempMask
);
709 DeleteObject (hbmTempImage
);
714 StretchBlt (himlDst
->hdcImage
, ptDst
.x
, ptDst
.y
, himlDst
->cx
, himlDst
->cy
,
715 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
,
728 /*************************************************************************
729 * ImageList_Create [COMCTL32.@]
731 * Creates a new image list.
734 * cx [I] image height
736 * flags [I] creation flags
737 * cInitial [I] initial number of images in the image list
738 * cGrow [I] number of images by which image list grows
741 * Success: Handle to the created image list
745 ImageList_Create (INT cx
, INT cy
, UINT flags
,
746 INT cInitial
, INT cGrow
)
751 UINT ilc
= (flags
& 0xFE);
752 static const WORD aBitBlend25
[] =
753 {0xAA, 0x00, 0x55, 0x00, 0xAA, 0x00, 0x55, 0x00};
755 static const WORD aBitBlend50
[] =
756 {0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA};
758 TRACE("(%d %d 0x%x %d %d)\n", cx
, cy
, flags
, cInitial
, cGrow
);
760 if (cx
<= 0 || cy
<= 0) return NULL
;
762 /* Create the IImageList interface for the image list */
763 if (FAILED(ImageListImpl_CreateInstance(NULL
, &IID_IImageList
, (void **)&himl
)))
766 cGrow
= (WORD
)((max( cGrow
, 1 ) + 3) & ~3);
770 /* Windows doesn't limit the size here, but X11 doesn't let us allocate such huge bitmaps */
771 WARN( "grow %d too large, limiting to 256\n", cGrow
);
778 himl
->cMaxImage
= cInitial
+ 1;
779 himl
->cInitial
= cInitial
;
781 himl
->clrFg
= CLR_DEFAULT
;
782 himl
->clrBk
= CLR_NONE
;
784 /* initialize overlay mask indices */
785 for (nCount
= 0; nCount
< MAX_OVERLAYIMAGE
; nCount
++)
786 himl
->nOvlIdx
[nCount
] = -1;
788 /* Create Image & Mask DCs */
789 himl
->hdcImage
= CreateCompatibleDC (0);
792 if (himl
->flags
& ILC_MASK
){
793 himl
->hdcMask
= CreateCompatibleDC(0);
798 /* Default to ILC_COLOR4 if none of the ILC_COLOR* flags are specified */
799 if (ilc
== ILC_COLOR
)
802 himl
->flags
|= ILC_COLOR4
;
805 if (ilc
>= ILC_COLOR4
&& ilc
<= ILC_COLOR32
)
806 himl
->uBitsPixel
= ilc
;
808 himl
->uBitsPixel
= (UINT
)GetDeviceCaps (himl
->hdcImage
, BITSPIXEL
);
810 if (himl
->cMaxImage
> 0) {
811 himl
->hbmImage
= ImageList_CreateImage(himl
->hdcImage
, himl
, himl
->cMaxImage
);
812 SelectObject(himl
->hdcImage
, himl
->hbmImage
);
816 if ((himl
->cMaxImage
> 0) && (himl
->flags
& ILC_MASK
)) {
819 imagelist_get_bitmap_size(himl
, himl
->cMaxImage
, &sz
);
820 himl
->hbmMask
= CreateBitmap (sz
.cx
, sz
.cy
, 1, 1, NULL
);
821 if (himl
->hbmMask
== 0) {
822 ERR("Error creating mask bitmap!\n");
825 SelectObject(himl
->hdcMask
, himl
->hbmMask
);
830 if (ilc
== ILC_COLOR32
)
831 himl
->has_alpha
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, himl
->cMaxImage
);
833 himl
->has_alpha
= NULL
;
835 /* create blending brushes */
836 hbmTemp
= CreateBitmap (8, 8, 1, 1, aBitBlend25
);
837 himl
->hbrBlend25
= CreatePatternBrush (hbmTemp
);
838 DeleteObject (hbmTemp
);
840 hbmTemp
= CreateBitmap (8, 8, 1, 1, aBitBlend50
);
841 himl
->hbrBlend50
= CreatePatternBrush (hbmTemp
);
842 DeleteObject (hbmTemp
);
844 TRACE("created imagelist %p\n", himl
);
848 ImageList_Destroy(himl
);
853 /*************************************************************************
854 * ImageList_Destroy [COMCTL32.@]
856 * Destroys an image list.
859 * himl [I] handle to image list
867 ImageList_Destroy (HIMAGELIST himl
)
872 IImageList_Release((IImageList
*) himl
);
877 /*************************************************************************
878 * ImageList_DragEnter [COMCTL32.@]
880 * Locks window update and displays the drag image at the given position.
883 * hwndLock [I] handle of the window that owns the drag image.
884 * x [I] X position of the drag image.
885 * y [I] Y position of the drag image.
892 * The position of the drag image is relative to the window, not
897 ImageList_DragEnter (HWND hwndLock
, INT x
, INT y
)
899 TRACE("(hwnd=%p x=%d y=%d)\n", hwndLock
, x
, y
);
901 if (!is_valid(InternalDrag
.himl
))
905 InternalDrag
.hwnd
= hwndLock
;
907 InternalDrag
.hwnd
= GetDesktopWindow ();
912 /* draw the drag image and save the background */
913 if (!ImageList_DragShowNolock(TRUE
)) {
921 /*************************************************************************
922 * ImageList_DragLeave [COMCTL32.@]
924 * Unlocks window update and hides the drag image.
927 * hwndLock [I] handle of the window that owns the drag image.
935 ImageList_DragLeave (HWND hwndLock
)
937 /* As we don't save drag info in the window this can lead to problems if
938 an app does not supply the same window as DragEnter */
940 InternalDrag.hwnd = hwndLock;
942 InternalDrag.hwnd = GetDesktopWindow (); */
944 hwndLock
= GetDesktopWindow();
945 if(InternalDrag
.hwnd
!= hwndLock
)
946 FIXME("DragLeave hWnd != DragEnter hWnd\n");
948 ImageList_DragShowNolock (FALSE
);
954 /*************************************************************************
955 * ImageList_InternalDragDraw [Internal]
957 * Draws the drag image.
960 * hdc [I] device context to draw into.
961 * x [I] X position of the drag image.
962 * y [I] Y position of the drag image.
969 * The position of the drag image is relative to the window, not
975 ImageList_InternalDragDraw (HDC hdc
, INT x
, INT y
)
977 IMAGELISTDRAWPARAMS imldp
;
979 ZeroMemory (&imldp
, sizeof(imldp
));
980 imldp
.cbSize
= sizeof(imldp
);
981 imldp
.himl
= InternalDrag
.himl
;
986 imldp
.rgbBk
= CLR_DEFAULT
;
987 imldp
.rgbFg
= CLR_DEFAULT
;
988 imldp
.fStyle
= ILD_NORMAL
;
989 imldp
.fState
= ILS_ALPHA
;
991 ImageList_DrawIndirect (&imldp
);
994 /*************************************************************************
995 * ImageList_DragMove [COMCTL32.@]
997 * Moves the drag image.
1000 * x [I] X position of the drag image.
1001 * y [I] Y position of the drag image.
1008 * The position of the drag image is relative to the window, not
1013 ImageList_DragMove (INT x
, INT y
)
1015 TRACE("(x=%d y=%d)\n", x
, y
);
1017 if (!is_valid(InternalDrag
.himl
))
1020 /* draw/update the drag image */
1021 if (InternalDrag
.bShow
) {
1025 HBITMAP hbmOffScreen
;
1026 INT origNewX
, origNewY
;
1027 INT origOldX
, origOldY
;
1028 INT origRegX
, origRegY
;
1029 INT sizeRegX
, sizeRegY
;
1032 /* calculate the update region */
1033 origNewX
= x
- InternalDrag
.dxHotspot
;
1034 origNewY
= y
- InternalDrag
.dyHotspot
;
1035 origOldX
= InternalDrag
.x
- InternalDrag
.dxHotspot
;
1036 origOldY
= InternalDrag
.y
- InternalDrag
.dyHotspot
;
1037 origRegX
= min(origNewX
, origOldX
);
1038 origRegY
= min(origNewY
, origOldY
);
1039 sizeRegX
= InternalDrag
.himl
->cx
+ abs(x
- InternalDrag
.x
);
1040 sizeRegY
= InternalDrag
.himl
->cy
+ abs(y
- InternalDrag
.y
);
1042 hdcDrag
= GetDCEx(InternalDrag
.hwnd
, 0,
1043 DCX_WINDOW
| DCX_CACHE
| DCX_LOCKWINDOWUPDATE
);
1044 hdcOffScreen
= CreateCompatibleDC(hdcDrag
);
1045 hdcBg
= CreateCompatibleDC(hdcDrag
);
1047 hbmOffScreen
= CreateCompatibleBitmap(hdcDrag
, sizeRegX
, sizeRegY
);
1048 SelectObject(hdcOffScreen
, hbmOffScreen
);
1049 SelectObject(hdcBg
, InternalDrag
.hbmBg
);
1051 /* get the actual background of the update region */
1052 BitBlt(hdcOffScreen
, 0, 0, sizeRegX
, sizeRegY
, hdcDrag
,
1053 origRegX
, origRegY
, SRCCOPY
);
1054 /* erase the old image */
1055 BitBlt(hdcOffScreen
, origOldX
- origRegX
, origOldY
- origRegY
,
1056 InternalDrag
.himl
->cx
, InternalDrag
.himl
->cy
, hdcBg
, 0, 0,
1058 /* save the background */
1059 BitBlt(hdcBg
, 0, 0, InternalDrag
.himl
->cx
, InternalDrag
.himl
->cy
,
1060 hdcOffScreen
, origNewX
- origRegX
, origNewY
- origRegY
, SRCCOPY
);
1061 /* draw the image */
1062 ImageList_InternalDragDraw(hdcOffScreen
, origNewX
- origRegX
,
1063 origNewY
- origRegY
);
1064 /* draw the update region to the screen */
1065 BitBlt(hdcDrag
, origRegX
, origRegY
, sizeRegX
, sizeRegY
,
1066 hdcOffScreen
, 0, 0, SRCCOPY
);
1069 DeleteDC(hdcOffScreen
);
1070 DeleteObject(hbmOffScreen
);
1071 ReleaseDC(InternalDrag
.hwnd
, hdcDrag
);
1074 /* update the image position */
1082 /*************************************************************************
1083 * ImageList_DragShowNolock [COMCTL32.@]
1085 * Shows or hides the drag image.
1088 * bShow [I] TRUE shows the drag image, FALSE hides it.
1096 ImageList_DragShowNolock (BOOL bShow
)
1102 if (!is_valid(InternalDrag
.himl
))
1105 TRACE("bShow=0x%X!\n", bShow
);
1107 /* DragImage is already visible/hidden */
1108 if ((InternalDrag
.bShow
&& bShow
) || (!InternalDrag
.bShow
&& !bShow
)) {
1112 /* position of the origin of the DragImage */
1113 x
= InternalDrag
.x
- InternalDrag
.dxHotspot
;
1114 y
= InternalDrag
.y
- InternalDrag
.dyHotspot
;
1116 hdcDrag
= GetDCEx (InternalDrag
.hwnd
, 0,
1117 DCX_WINDOW
| DCX_CACHE
| DCX_LOCKWINDOWUPDATE
);
1122 hdcBg
= CreateCompatibleDC(hdcDrag
);
1123 if (!InternalDrag
.hbmBg
) {
1124 InternalDrag
.hbmBg
= CreateCompatibleBitmap(hdcDrag
,
1125 InternalDrag
.himl
->cx
, InternalDrag
.himl
->cy
);
1127 SelectObject(hdcBg
, InternalDrag
.hbmBg
);
1130 /* save the background */
1131 BitBlt(hdcBg
, 0, 0, InternalDrag
.himl
->cx
, InternalDrag
.himl
->cy
,
1132 hdcDrag
, x
, y
, SRCCOPY
);
1133 /* show the image */
1134 ImageList_InternalDragDraw(hdcDrag
, x
, y
);
1136 /* hide the image */
1137 BitBlt(hdcDrag
, x
, y
, InternalDrag
.himl
->cx
, InternalDrag
.himl
->cy
,
1138 hdcBg
, 0, 0, SRCCOPY
);
1141 InternalDrag
.bShow
= !InternalDrag
.bShow
;
1144 ReleaseDC (InternalDrag
.hwnd
, hdcDrag
);
1149 /*************************************************************************
1150 * ImageList_Draw [COMCTL32.@]
1155 * himl [I] handle to image list
1157 * hdc [I] handle to device context
1160 * fStyle [I] drawing flags
1171 ImageList_Draw (HIMAGELIST himl
, INT i
, HDC hdc
, INT x
, INT y
, UINT fStyle
)
1173 return ImageList_DrawEx (himl
, i
, hdc
, x
, y
, 0, 0,
1174 CLR_DEFAULT
, CLR_DEFAULT
, fStyle
);
1178 /*************************************************************************
1179 * ImageList_DrawEx [COMCTL32.@]
1181 * Draws an image and allows using extended drawing features.
1184 * himl [I] handle to image list
1186 * hdc [I] handle to device context
1191 * rgbBk [I] background color
1192 * rgbFg [I] foreground color
1193 * fStyle [I] drawing flags
1200 * Calls ImageList_DrawIndirect.
1203 * ImageList_DrawIndirect.
1207 ImageList_DrawEx (HIMAGELIST himl
, INT i
, HDC hdc
, INT x
, INT y
,
1208 INT dx
, INT dy
, COLORREF rgbBk
, COLORREF rgbFg
,
1211 IMAGELISTDRAWPARAMS imldp
;
1213 ZeroMemory (&imldp
, sizeof(imldp
));
1214 imldp
.cbSize
= sizeof(imldp
);
1222 imldp
.rgbBk
= rgbBk
;
1223 imldp
.rgbFg
= rgbFg
;
1224 imldp
.fStyle
= fStyle
;
1226 return ImageList_DrawIndirect (&imldp
);
1230 static BOOL
alpha_blend_image( HIMAGELIST himl
, HDC dest_dc
, int dest_x
, int dest_y
,
1231 int src_x
, int src_y
, int cx
, int cy
, BLENDFUNCTION func
,
1232 UINT style
, COLORREF blend_col
)
1236 HBITMAP bmp
= 0, mask
= 0;
1238 void *bits
, *mask_bits
;
1242 if (!(hdc
= CreateCompatibleDC( 0 ))) return FALSE
;
1243 if (!(info
= HeapAlloc( GetProcessHeap(), 0, FIELD_OFFSET( BITMAPINFO
, bmiColors
[256] )))) goto done
;
1244 info
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
1245 info
->bmiHeader
.biWidth
= cx
;
1246 info
->bmiHeader
.biHeight
= cy
;
1247 info
->bmiHeader
.biPlanes
= 1;
1248 info
->bmiHeader
.biBitCount
= 32;
1249 info
->bmiHeader
.biCompression
= BI_RGB
;
1250 info
->bmiHeader
.biSizeImage
= cx
* cy
* 4;
1251 info
->bmiHeader
.biXPelsPerMeter
= 0;
1252 info
->bmiHeader
.biYPelsPerMeter
= 0;
1253 info
->bmiHeader
.biClrUsed
= 0;
1254 info
->bmiHeader
.biClrImportant
= 0;
1255 if (!(bmp
= CreateDIBSection( himl
->hdcImage
, info
, DIB_RGB_COLORS
, &bits
, 0, 0 ))) goto done
;
1256 SelectObject( hdc
, bmp
);
1257 BitBlt( hdc
, 0, 0, cx
, cy
, himl
->hdcImage
, src_x
, src_y
, SRCCOPY
);
1259 if (blend_col
!= CLR_NONE
)
1261 BYTE r
= GetRValue( blend_col
);
1262 BYTE g
= GetGValue( blend_col
);
1263 BYTE b
= GetBValue( blend_col
);
1265 if (style
& ILD_BLEND25
)
1267 for (i
= 0, ptr
= bits
; i
< cx
* cy
; i
++, ptr
++)
1268 *ptr
= ((*ptr
& 0xff000000) |
1269 ((((*ptr
& 0x00ff0000) * 3 + (r
<< 16)) / 4) & 0x00ff0000) |
1270 ((((*ptr
& 0x0000ff00) * 3 + (g
<< 8)) / 4) & 0x0000ff00) |
1271 ((((*ptr
& 0x000000ff) * 3 + (b
<< 0)) / 4) & 0x000000ff));
1273 else if (style
& ILD_BLEND50
)
1275 for (i
= 0, ptr
= bits
; i
< cx
* cy
; i
++, ptr
++)
1276 *ptr
= ((*ptr
& 0xff000000) |
1277 ((((*ptr
& 0x00ff0000) + (r
<< 16)) / 2) & 0x00ff0000) |
1278 ((((*ptr
& 0x0000ff00) + (g
<< 8)) / 2) & 0x0000ff00) |
1279 ((((*ptr
& 0x000000ff) + (b
<< 0)) / 2) & 0x000000ff));
1283 if (himl
->has_alpha
) /* we already have an alpha channel in this case */
1285 /* pre-multiply by the alpha channel */
1286 for (i
= 0, ptr
= bits
; i
< cx
* cy
; i
++, ptr
++)
1288 DWORD alpha
= *ptr
>> 24;
1289 *ptr
= ((*ptr
& 0xff000000) |
1290 (((*ptr
& 0x00ff0000) * alpha
/ 255) & 0x00ff0000) |
1291 (((*ptr
& 0x0000ff00) * alpha
/ 255) & 0x0000ff00) |
1292 (((*ptr
& 0x000000ff) * alpha
/ 255)));
1295 else if (himl
->hbmMask
)
1297 unsigned int width_bytes
= (cx
+ 31) / 32 * 4;
1298 /* generate alpha channel from the mask */
1299 info
->bmiHeader
.biBitCount
= 1;
1300 info
->bmiHeader
.biSizeImage
= width_bytes
* cy
;
1301 info
->bmiColors
[0].rgbRed
= 0;
1302 info
->bmiColors
[0].rgbGreen
= 0;
1303 info
->bmiColors
[0].rgbBlue
= 0;
1304 info
->bmiColors
[0].rgbReserved
= 0;
1305 info
->bmiColors
[1].rgbRed
= 0xff;
1306 info
->bmiColors
[1].rgbGreen
= 0xff;
1307 info
->bmiColors
[1].rgbBlue
= 0xff;
1308 info
->bmiColors
[1].rgbReserved
= 0;
1309 if (!(mask
= CreateDIBSection( himl
->hdcMask
, info
, DIB_RGB_COLORS
, &mask_bits
, 0, 0 )))
1311 SelectObject( hdc
, mask
);
1312 BitBlt( hdc
, 0, 0, cx
, cy
, himl
->hdcMask
, src_x
, src_y
, SRCCOPY
);
1313 SelectObject( hdc
, bmp
);
1314 for (i
= 0, ptr
= bits
; i
< cy
; i
++)
1315 for (j
= 0; j
< cx
; j
++, ptr
++)
1316 if ((((BYTE
*)mask_bits
)[i
* width_bytes
+ j
/ 8] << (j
% 8)) & 0x80) *ptr
= 0;
1317 else *ptr
|= 0xff000000;
1320 ret
= GdiAlphaBlend( dest_dc
, dest_x
, dest_y
, cx
, cy
, hdc
, 0, 0, cx
, cy
, func
);
1324 if (bmp
) DeleteObject( bmp
);
1325 if (mask
) DeleteObject( mask
);
1326 HeapFree( GetProcessHeap(), 0, info
);
1330 /*************************************************************************
1331 * ImageList_DrawIndirect [COMCTL32.@]
1333 * Draws an image using various parameters specified in pimldp.
1336 * pimldp [I] pointer to IMAGELISTDRAWPARAMS structure.
1344 ImageList_DrawIndirect (IMAGELISTDRAWPARAMS
*pimldp
)
1346 INT cx
, cy
, nOvlIdx
;
1347 DWORD fState
, dwRop
;
1349 COLORREF oldImageBk
, oldImageFg
;
1350 HDC hImageDC
, hImageListDC
, hMaskListDC
;
1351 HBITMAP hImageBmp
, hOldImageBmp
, hBlendMaskBmp
;
1352 BOOL bIsTransparent
, bBlend
, bResult
= FALSE
, bMask
;
1358 if (!pimldp
|| !(himl
= pimldp
->himl
)) return FALSE
;
1359 if (!is_valid(himl
)) return FALSE
;
1360 if ((pimldp
->i
< 0) || (pimldp
->i
>= himl
->cCurImage
)) return FALSE
;
1362 imagelist_point_from_index( himl
, pimldp
->i
, &pt
);
1363 pt
.x
+= pimldp
->xBitmap
;
1364 pt
.y
+= pimldp
->yBitmap
;
1366 fState
= pimldp
->cbSize
< sizeof(IMAGELISTDRAWPARAMS
) ? ILS_NORMAL
: pimldp
->fState
;
1367 fStyle
= pimldp
->fStyle
& ~ILD_OVERLAYMASK
;
1368 cx
= (pimldp
->cx
== 0) ? himl
->cx
: pimldp
->cx
;
1369 cy
= (pimldp
->cy
== 0) ? himl
->cy
: pimldp
->cy
;
1371 bIsTransparent
= (fStyle
& ILD_TRANSPARENT
);
1372 if( pimldp
->rgbBk
== CLR_NONE
)
1373 bIsTransparent
= TRUE
;
1374 if( ( pimldp
->rgbBk
== CLR_DEFAULT
) && ( himl
->clrBk
== CLR_NONE
) )
1375 bIsTransparent
= TRUE
;
1376 bMask
= (himl
->flags
& ILC_MASK
) && (fStyle
& ILD_MASK
) ;
1377 bBlend
= (fStyle
& (ILD_BLEND25
| ILD_BLEND50
) ) && !bMask
;
1379 TRACE("himl(%p) hbmMask(%p) iImage(%d) x(%d) y(%d) cx(%d) cy(%d)\n",
1380 himl
, himl
->hbmMask
, pimldp
->i
, pimldp
->x
, pimldp
->y
, cx
, cy
);
1382 /* we will use these DCs to access the images and masks in the ImageList */
1383 hImageListDC
= himl
->hdcImage
;
1384 hMaskListDC
= himl
->hdcMask
;
1386 /* these will accumulate the image and mask for the image we're drawing */
1387 hImageDC
= CreateCompatibleDC( pimldp
->hdcDst
);
1388 hImageBmp
= CreateCompatibleBitmap( pimldp
->hdcDst
, cx
, cy
);
1389 hBlendMaskBmp
= bBlend
? CreateBitmap(cx
, cy
, 1, 1, NULL
) : 0;
1391 /* Create a compatible DC. */
1392 if (!hImageListDC
|| !hImageDC
|| !hImageBmp
||
1393 (bBlend
&& !hBlendMaskBmp
) || (himl
->hbmMask
&& !hMaskListDC
))
1396 hOldImageBmp
= SelectObject(hImageDC
, hImageBmp
);
1399 * To obtain a transparent look, background color should be set
1400 * to white and foreground color to black when blitting the
1403 oldImageFg
= SetTextColor( hImageDC
, RGB( 0, 0, 0 ) );
1404 oldImageBk
= SetBkColor( hImageDC
, RGB( 0xff, 0xff, 0xff ) );
1406 has_alpha
= (himl
->has_alpha
&& himl
->has_alpha
[pimldp
->i
]);
1407 if (!bMask
&& (has_alpha
|| (fState
& ILS_ALPHA
)))
1409 COLORREF colour
, blend_col
= CLR_NONE
;
1414 blend_col
= pimldp
->rgbFg
;
1415 if (blend_col
== CLR_DEFAULT
) blend_col
= GetSysColor( COLOR_HIGHLIGHT
);
1416 else if (blend_col
== CLR_NONE
) blend_col
= GetTextColor( pimldp
->hdcDst
);
1419 func
.BlendOp
= AC_SRC_OVER
;
1420 func
.BlendFlags
= 0;
1421 func
.SourceConstantAlpha
= (fState
& ILS_ALPHA
) ? pimldp
->Frame
: 255;
1422 func
.AlphaFormat
= AC_SRC_ALPHA
;
1426 bResult
= alpha_blend_image( himl
, pimldp
->hdcDst
, pimldp
->x
, pimldp
->y
,
1427 pt
.x
, pt
.y
, cx
, cy
, func
, fStyle
, blend_col
);
1430 colour
= pimldp
->rgbBk
;
1431 if (colour
== CLR_DEFAULT
) colour
= himl
->clrBk
;
1432 if (colour
== CLR_NONE
) colour
= GetBkColor( pimldp
->hdcDst
);
1434 hOldBrush
= SelectObject (hImageDC
, CreateSolidBrush (colour
));
1435 PatBlt( hImageDC
, 0, 0, cx
, cy
, PATCOPY
);
1436 alpha_blend_image( himl
, hImageDC
, 0, 0, pt
.x
, pt
.y
, cx
, cy
, func
, fStyle
, blend_col
);
1437 DeleteObject (SelectObject (hImageDC
, hOldBrush
));
1438 bResult
= BitBlt( pimldp
->hdcDst
, pimldp
->x
, pimldp
->y
, cx
, cy
, hImageDC
, 0, 0, SRCCOPY
);
1443 * Draw the initial image
1446 if (himl
->hbmMask
) {
1447 hOldBrush
= SelectObject (hImageDC
, CreateSolidBrush (GetTextColor(pimldp
->hdcDst
)));
1448 PatBlt( hImageDC
, 0, 0, cx
, cy
, PATCOPY
);
1449 BitBlt(hImageDC
, 0, 0, cx
, cy
, hMaskListDC
, pt
.x
, pt
.y
, SRCPAINT
);
1450 DeleteObject (SelectObject (hImageDC
, hOldBrush
));
1451 if( bIsTransparent
)
1453 BitBlt ( pimldp
->hdcDst
, pimldp
->x
, pimldp
->y
, cx
, cy
, hImageDC
, 0, 0, SRCAND
);
1458 hOldBrush
= SelectObject (hImageDC
, GetStockObject(BLACK_BRUSH
));
1459 PatBlt( hImageDC
, 0, 0, cx
, cy
, PATCOPY
);
1460 SelectObject(hImageDC
, hOldBrush
);
1463 /* blend the image with the needed solid background */
1464 COLORREF colour
= RGB(0,0,0);
1466 if( !bIsTransparent
)
1468 colour
= pimldp
->rgbBk
;
1469 if( colour
== CLR_DEFAULT
)
1470 colour
= himl
->clrBk
;
1471 if( colour
== CLR_NONE
)
1472 colour
= GetBkColor(pimldp
->hdcDst
);
1475 hOldBrush
= SelectObject (hImageDC
, CreateSolidBrush (colour
));
1476 PatBlt( hImageDC
, 0, 0, cx
, cy
, PATCOPY
);
1479 BitBlt( hImageDC
, 0, 0, cx
, cy
, hMaskListDC
, pt
.x
, pt
.y
, SRCAND
);
1480 BitBlt( hImageDC
, 0, 0, cx
, cy
, hImageListDC
, pt
.x
, pt
.y
, SRCPAINT
);
1483 BitBlt( hImageDC
, 0, 0, cx
, cy
, hImageListDC
, pt
.x
, pt
.y
, SRCCOPY
);
1484 DeleteObject (SelectObject (hImageDC
, hOldBrush
));
1487 /* Time for blending, if required */
1490 COLORREF clrBlend
= pimldp
->rgbFg
;
1491 HDC hBlendMaskDC
= hImageListDC
;
1494 /* Create the blend Mask */
1495 hOldBitmap
= SelectObject(hBlendMaskDC
, hBlendMaskBmp
);
1496 hBlendBrush
= fStyle
& ILD_BLEND50
? himl
->hbrBlend50
: himl
->hbrBlend25
;
1497 hOldBrush
= SelectObject(hBlendMaskDC
, hBlendBrush
);
1498 PatBlt(hBlendMaskDC
, 0, 0, cx
, cy
, PATCOPY
);
1499 SelectObject(hBlendMaskDC
, hOldBrush
);
1501 /* Modify the blend mask if an Image Mask exist */
1503 BitBlt(hBlendMaskDC
, 0, 0, cx
, cy
, hMaskListDC
, pt
.x
, pt
.y
, 0x220326); /* NOTSRCAND */
1504 BitBlt(hBlendMaskDC
, 0, 0, cx
, cy
, hBlendMaskDC
, 0, 0, NOTSRCCOPY
);
1507 /* now apply blend to the current image given the BlendMask */
1508 if (clrBlend
== CLR_DEFAULT
) clrBlend
= GetSysColor (COLOR_HIGHLIGHT
);
1509 else if (clrBlend
== CLR_NONE
) clrBlend
= GetTextColor (pimldp
->hdcDst
);
1510 hOldBrush
= SelectObject (hImageDC
, CreateSolidBrush(clrBlend
));
1511 BitBlt (hImageDC
, 0, 0, cx
, cy
, hBlendMaskDC
, 0, 0, 0xB8074A); /* PSDPxax */
1512 DeleteObject(SelectObject(hImageDC
, hOldBrush
));
1513 SelectObject(hBlendMaskDC
, hOldBitmap
);
1516 /* Now do the overlay image, if any */
1517 nOvlIdx
= (pimldp
->fStyle
& ILD_OVERLAYMASK
) >> 8;
1518 if ( (nOvlIdx
>= 1) && (nOvlIdx
<= MAX_OVERLAYIMAGE
)) {
1519 nOvlIdx
= himl
->nOvlIdx
[nOvlIdx
- 1];
1520 if ((nOvlIdx
>= 0) && (nOvlIdx
< himl
->cCurImage
)) {
1522 imagelist_point_from_index( himl
, nOvlIdx
, &ptOvl
);
1523 ptOvl
.x
+= pimldp
->xBitmap
;
1524 if (himl
->hbmMask
&& !(fStyle
& ILD_IMAGE
))
1525 BitBlt (hImageDC
, 0, 0, cx
, cy
, hMaskListDC
, ptOvl
.x
, ptOvl
.y
, SRCAND
);
1526 BitBlt (hImageDC
, 0, 0, cx
, cy
, hImageListDC
, ptOvl
.x
, ptOvl
.y
, SRCPAINT
);
1530 if (fState
& ILS_SATURATE
) FIXME("ILS_SATURATE: unimplemented!\n");
1531 if (fState
& ILS_GLOW
) FIXME("ILS_GLOW: unimplemented!\n");
1532 if (fState
& ILS_SHADOW
) FIXME("ILS_SHADOW: unimplemented!\n");
1534 if (fStyle
& ILD_PRESERVEALPHA
) FIXME("ILD_PRESERVEALPHA: unimplemented!\n");
1535 if (fStyle
& ILD_SCALE
) FIXME("ILD_SCALE: unimplemented!\n");
1536 if (fStyle
& ILD_DPISCALE
) FIXME("ILD_DPISCALE: unimplemented!\n");
1538 /* now copy the image to the screen */
1540 if (himl
->hbmMask
&& bIsTransparent
) {
1541 COLORREF oldDstFg
= SetTextColor(pimldp
->hdcDst
, RGB( 0, 0, 0 ) );
1542 COLORREF oldDstBk
= SetBkColor(pimldp
->hdcDst
, RGB( 0xff, 0xff, 0xff ));
1543 BitBlt (pimldp
->hdcDst
, pimldp
->x
, pimldp
->y
, cx
, cy
, hMaskListDC
, pt
.x
, pt
.y
, SRCAND
);
1544 SetBkColor(pimldp
->hdcDst
, oldDstBk
);
1545 SetTextColor(pimldp
->hdcDst
, oldDstFg
);
1548 if (fStyle
& ILD_ROP
) dwRop
= pimldp
->dwRop
;
1549 BitBlt (pimldp
->hdcDst
, pimldp
->x
, pimldp
->y
, cx
, cy
, hImageDC
, 0, 0, dwRop
);
1553 /* cleanup the mess */
1554 SetBkColor(hImageDC
, oldImageBk
);
1555 SetTextColor(hImageDC
, oldImageFg
);
1556 SelectObject(hImageDC
, hOldImageBmp
);
1558 DeleteObject(hBlendMaskBmp
);
1559 DeleteObject(hImageBmp
);
1566 /*************************************************************************
1567 * ImageList_Duplicate [COMCTL32.@]
1569 * Duplicates an image list.
1572 * himlSrc [I] source image list handle
1575 * Success: Handle of duplicated image list.
1580 ImageList_Duplicate (HIMAGELIST himlSrc
)
1584 if (!is_valid(himlSrc
)) {
1585 ERR("Invalid image list handle!\n");
1589 himlDst
= ImageList_Create (himlSrc
->cx
, himlSrc
->cy
, himlSrc
->flags
,
1590 himlSrc
->cCurImage
, himlSrc
->cGrow
);
1596 imagelist_get_bitmap_size(himlSrc
, himlSrc
->cCurImage
, &sz
);
1597 BitBlt (himlDst
->hdcImage
, 0, 0, sz
.cx
, sz
.cy
,
1598 himlSrc
->hdcImage
, 0, 0, SRCCOPY
);
1600 if (himlDst
->hbmMask
)
1601 BitBlt (himlDst
->hdcMask
, 0, 0, sz
.cx
, sz
.cy
,
1602 himlSrc
->hdcMask
, 0, 0, SRCCOPY
);
1604 himlDst
->cCurImage
= himlSrc
->cCurImage
;
1605 if (himlSrc
->has_alpha
&& himlDst
->has_alpha
)
1606 memcpy( himlDst
->has_alpha
, himlSrc
->has_alpha
, himlDst
->cCurImage
);
1612 /*************************************************************************
1613 * ImageList_EndDrag [COMCTL32.@]
1615 * Finishes a drag operation.
1626 ImageList_EndDrag (void)
1628 /* cleanup the InternalDrag struct */
1629 InternalDrag
.hwnd
= 0;
1630 if (InternalDrag
.himl
!= InternalDrag
.himlNoCursor
)
1631 ImageList_Destroy (InternalDrag
.himlNoCursor
);
1632 ImageList_Destroy (InternalDrag
.himl
);
1633 InternalDrag
.himlNoCursor
= InternalDrag
.himl
= 0;
1636 InternalDrag
.dxHotspot
= 0;
1637 InternalDrag
.dyHotspot
= 0;
1638 InternalDrag
.bShow
= FALSE
;
1639 DeleteObject(InternalDrag
.hbmBg
);
1640 InternalDrag
.hbmBg
= 0;
1644 /*************************************************************************
1645 * ImageList_GetBkColor [COMCTL32.@]
1647 * Returns the background color of an image list.
1650 * himl [I] Image list handle.
1653 * Success: background color
1658 ImageList_GetBkColor (HIMAGELIST himl
)
1660 return himl
? himl
->clrBk
: CLR_NONE
;
1664 /*************************************************************************
1665 * ImageList_GetDragImage [COMCTL32.@]
1667 * Returns the handle to the internal drag image list.
1670 * ppt [O] Pointer to the drag position. Can be NULL.
1671 * pptHotspot [O] Pointer to the position of the hot spot. Can be NULL.
1674 * Success: Handle of the drag image list.
1679 ImageList_GetDragImage (POINT
*ppt
, POINT
*pptHotspot
)
1681 if (is_valid(InternalDrag
.himl
)) {
1683 ppt
->x
= InternalDrag
.x
;
1684 ppt
->y
= InternalDrag
.y
;
1687 pptHotspot
->x
= InternalDrag
.dxHotspot
;
1688 pptHotspot
->y
= InternalDrag
.dyHotspot
;
1690 return (InternalDrag
.himl
);
1697 /*************************************************************************
1698 * ImageList_GetFlags [COMCTL32.@]
1700 * Gets the flags of the specified image list.
1703 * himl [I] Handle to image list
1713 ImageList_GetFlags(HIMAGELIST himl
)
1715 TRACE("%p\n", himl
);
1717 return is_valid(himl
) ? himl
->flags
: 0;
1721 /*************************************************************************
1722 * ImageList_GetIcon [COMCTL32.@]
1724 * Creates an icon from a masked image of an image list.
1727 * himl [I] handle to image list
1729 * flags [I] drawing style flags
1732 * Success: icon handle
1737 ImageList_GetIcon (HIMAGELIST himl
, INT i
, UINT fStyle
)
1741 HBITMAP hOldDstBitmap
;
1745 TRACE("%p %d %d\n", himl
, i
, fStyle
);
1746 if (!is_valid(himl
) || (i
< 0) || (i
>= himl
->cCurImage
)) return NULL
;
1752 /* create colour bitmap */
1754 ii
.hbmColor
= CreateCompatibleBitmap(hdcDst
, himl
->cx
, himl
->cy
);
1755 ReleaseDC(0, hdcDst
);
1757 hdcDst
= CreateCompatibleDC(0);
1759 imagelist_point_from_index( himl
, i
, &pt
);
1762 ii
.hbmMask
= CreateBitmap (himl
->cx
, himl
->cy
, 1, 1, NULL
);
1763 hOldDstBitmap
= SelectObject (hdcDst
, ii
.hbmMask
);
1764 if (himl
->hbmMask
) {
1765 BitBlt (hdcDst
, 0, 0, himl
->cx
, himl
->cy
,
1766 himl
->hdcMask
, pt
.x
, pt
.y
, SRCCOPY
);
1769 PatBlt (hdcDst
, 0, 0, himl
->cx
, himl
->cy
, BLACKNESS
);
1772 SelectObject (hdcDst
, ii
.hbmColor
);
1773 BitBlt (hdcDst
, 0, 0, himl
->cx
, himl
->cy
,
1774 himl
->hdcImage
, pt
.x
, pt
.y
, SRCCOPY
);
1777 * CreateIconIndirect requires us to deselect the bitmaps from
1778 * the DCs before calling
1780 SelectObject(hdcDst
, hOldDstBitmap
);
1782 hIcon
= CreateIconIndirect (&ii
);
1784 DeleteObject (ii
.hbmMask
);
1785 DeleteObject (ii
.hbmColor
);
1792 /*************************************************************************
1793 * ImageList_GetIconSize [COMCTL32.@]
1795 * Retrieves the size of an image in an image list.
1798 * himl [I] handle to image list
1799 * cx [O] pointer to the image width.
1800 * cy [O] pointer to the image height.
1807 * All images in an image list have the same size.
1811 ImageList_GetIconSize (HIMAGELIST himl
, INT
*cx
, INT
*cy
)
1813 if (!is_valid(himl
) || !cx
|| !cy
)
1815 if ((himl
->cx
<= 0) || (himl
->cy
<= 0))
1825 /*************************************************************************
1826 * ImageList_GetImageCount [COMCTL32.@]
1828 * Returns the number of images in an image list.
1831 * himl [I] handle to image list
1834 * Success: Number of images.
1839 ImageList_GetImageCount (HIMAGELIST himl
)
1841 if (!is_valid(himl
))
1844 return himl
->cCurImage
;
1848 /*************************************************************************
1849 * ImageList_GetImageInfo [COMCTL32.@]
1851 * Returns information about an image in an image list.
1854 * himl [I] handle to image list
1856 * pImageInfo [O] pointer to the image information
1864 ImageList_GetImageInfo (HIMAGELIST himl
, INT i
, IMAGEINFO
*pImageInfo
)
1868 if (!is_valid(himl
) || (pImageInfo
== NULL
))
1870 if ((i
< 0) || (i
>= himl
->cCurImage
))
1873 pImageInfo
->hbmImage
= himl
->hbmImage
;
1874 pImageInfo
->hbmMask
= himl
->hbmMask
;
1876 imagelist_point_from_index( himl
, i
, &pt
);
1877 pImageInfo
->rcImage
.top
= pt
.y
;
1878 pImageInfo
->rcImage
.bottom
= pt
.y
+ himl
->cy
;
1879 pImageInfo
->rcImage
.left
= pt
.x
;
1880 pImageInfo
->rcImage
.right
= pt
.x
+ himl
->cx
;
1886 /*************************************************************************
1887 * ImageList_GetImageRect [COMCTL32.@]
1889 * Retrieves the rectangle of the specified image in an image list.
1892 * himl [I] handle to image list
1894 * lpRect [O] pointer to the image rectangle
1901 * This is an UNDOCUMENTED function!!!
1905 ImageList_GetImageRect (HIMAGELIST himl
, INT i
, LPRECT lpRect
)
1909 if (!is_valid(himl
) || (lpRect
== NULL
))
1911 if ((i
< 0) || (i
>= himl
->cCurImage
))
1914 imagelist_point_from_index( himl
, i
, &pt
);
1915 lpRect
->left
= pt
.x
;
1917 lpRect
->right
= pt
.x
+ himl
->cx
;
1918 lpRect
->bottom
= pt
.y
+ himl
->cy
;
1924 /*************************************************************************
1925 * ImageList_LoadImage [COMCTL32.@]
1926 * ImageList_LoadImageA [COMCTL32.@]
1928 * Creates an image list from a bitmap, icon or cursor.
1930 * See ImageList_LoadImageW.
1934 ImageList_LoadImageA (HINSTANCE hi
, LPCSTR lpbmp
, INT cx
, INT cGrow
,
1935 COLORREF clrMask
, UINT uType
, UINT uFlags
)
1941 if (IS_INTRESOURCE(lpbmp
))
1942 return ImageList_LoadImageW(hi
, (LPCWSTR
)lpbmp
, cx
, cGrow
, clrMask
,
1945 len
= MultiByteToWideChar(CP_ACP
, 0, lpbmp
, -1, NULL
, 0);
1946 lpbmpW
= Alloc(len
* sizeof(WCHAR
));
1947 MultiByteToWideChar(CP_ACP
, 0, lpbmp
, -1, lpbmpW
, len
);
1949 himl
= ImageList_LoadImageW(hi
, lpbmpW
, cx
, cGrow
, clrMask
, uType
, uFlags
);
1955 /*************************************************************************
1956 * ImageList_LoadImageW [COMCTL32.@]
1958 * Creates an image list from a bitmap, icon or cursor.
1961 * hi [I] instance handle
1962 * lpbmp [I] name or id of the image
1963 * cx [I] width of each image
1964 * cGrow [I] number of images to expand
1965 * clrMask [I] mask color
1966 * uType [I] type of image to load
1967 * uFlags [I] loading flags
1970 * Success: handle to the loaded image list
1978 ImageList_LoadImageW (HINSTANCE hi
, LPCWSTR lpbmp
, INT cx
, INT cGrow
,
1979 COLORREF clrMask
, UINT uType
, UINT uFlags
)
1981 HIMAGELIST himl
= NULL
;
1985 handle
= LoadImageW (hi
, lpbmp
, uType
, 0, 0, uFlags
);
1987 WARN("Couldn't load image\n");
1991 if (uType
== IMAGE_BITMAP
) {
1995 if (GetObjectW (handle
, sizeof(dib
), &dib
) == sizeof(BITMAP
)) color
= ILC_COLOR
;
1996 else color
= dib
.dsBm
.bmBitsPixel
;
1998 /* To match windows behavior, if cx is set to zero and
1999 the flag DI_DEFAULTSIZE is specified, cx becomes the
2000 system metric value for icons. If the flag is not specified
2001 the function sets the size to the height of the bitmap */
2004 if (uFlags
& DI_DEFAULTSIZE
)
2005 cx
= GetSystemMetrics (SM_CXICON
);
2007 cx
= dib
.dsBm
.bmHeight
;
2010 nImageCount
= dib
.dsBm
.bmWidth
/ cx
;
2012 himl
= ImageList_Create (cx
, dib
.dsBm
.bmHeight
, ILC_MASK
| color
, nImageCount
, cGrow
);
2014 DeleteObject (handle
);
2017 ImageList_AddMasked (himl
, handle
, clrMask
);
2019 else if ((uType
== IMAGE_ICON
) || (uType
== IMAGE_CURSOR
)) {
2023 GetIconInfo (handle
, &ii
);
2024 GetObjectW (ii
.hbmColor
, sizeof(BITMAP
), &bmp
);
2025 himl
= ImageList_Create (bmp
.bmWidth
, bmp
.bmHeight
,
2026 ILC_MASK
| ILC_COLOR
, 1, cGrow
);
2028 DeleteObject (ii
.hbmColor
);
2029 DeleteObject (ii
.hbmMask
);
2030 DeleteObject (handle
);
2033 ImageList_Add (himl
, ii
.hbmColor
, ii
.hbmMask
);
2034 DeleteObject (ii
.hbmColor
);
2035 DeleteObject (ii
.hbmMask
);
2038 DeleteObject (handle
);
2044 /*************************************************************************
2045 * ImageList_Merge [COMCTL32.@]
2047 * Create an image list containing a merged image from two image lists.
2050 * himl1 [I] handle to first image list
2051 * i1 [I] first image index
2052 * himl2 [I] handle to second image list
2053 * i2 [I] second image index
2054 * dx [I] X offset of the second image relative to the first.
2055 * dy [I] Y offset of the second image relative to the first.
2058 * Success: The newly created image list. It contains a single image
2059 * consisting of the second image merged with the first.
2060 * Failure: NULL, if either himl1 or himl2 is invalid.
2063 * - The returned image list should be deleted by the caller using
2064 * ImageList_Destroy() when it is no longer required.
2065 * - If either i1 or i2 is not a valid image index, they will be treated
2069 ImageList_Merge (HIMAGELIST himl1
, INT i1
, HIMAGELIST himl2
, INT i2
,
2072 HIMAGELIST himlDst
= NULL
;
2074 INT xOff1
, yOff1
, xOff2
, yOff2
;
2078 TRACE("(himl1=%p i1=%d himl2=%p i2=%d dx=%d dy=%d)\n", himl1
, i1
, himl2
,
2081 if (!is_valid(himl1
) || !is_valid(himl2
))
2085 cxDst
= max (himl1
->cx
, dx
+ himl2
->cx
);
2090 cxDst
= max (himl2
->cx
, himl1
->cx
- dx
);
2095 cxDst
= max (himl1
->cx
, himl2
->cx
);
2101 cyDst
= max (himl1
->cy
, dy
+ himl2
->cy
);
2106 cyDst
= max (himl2
->cy
, himl1
->cy
- dy
);
2111 cyDst
= max (himl1
->cy
, himl2
->cy
);
2116 newFlags
= (himl1
->flags
> himl2
->flags
? himl1
->flags
: himl2
->flags
) & ILC_COLORDDB
;
2117 if (newFlags
== ILC_COLORDDB
&& (himl1
->flags
& ILC_COLORDDB
) == ILC_COLOR16
)
2118 newFlags
= ILC_COLOR16
; /* this is what native (at least v5) does, don't know why */
2119 himlDst
= ImageList_Create (cxDst
, cyDst
, ILC_MASK
| newFlags
, 1, 1);
2123 imagelist_point_from_index( himl1
, i1
, &pt1
);
2124 imagelist_point_from_index( himl2
, i2
, &pt2
);
2127 BitBlt (himlDst
->hdcImage
, 0, 0, cxDst
, cyDst
, himl1
->hdcImage
, 0, 0, BLACKNESS
);
2128 if (i1
>= 0 && i1
< himl1
->cCurImage
)
2129 BitBlt (himlDst
->hdcImage
, xOff1
, yOff1
, himl1
->cx
, himl1
->cy
, himl1
->hdcImage
, pt1
.x
, pt1
.y
, SRCCOPY
);
2130 if (i2
>= 0 && i2
< himl2
->cCurImage
)
2132 if (himl2
->flags
& ILC_MASK
)
2134 BitBlt (himlDst
->hdcImage
, xOff2
, yOff2
, himl2
->cx
, himl2
->cy
, himl2
->hdcMask
, pt2
.x
, pt2
.y
, SRCAND
);
2135 BitBlt (himlDst
->hdcImage
, xOff2
, yOff2
, himl2
->cx
, himl2
->cy
, himl2
->hdcImage
, pt2
.x
, pt2
.y
, SRCPAINT
);
2138 BitBlt (himlDst
->hdcImage
, xOff2
, yOff2
, himl2
->cx
, himl2
->cy
, himl2
->hdcImage
, pt2
.x
, pt2
.y
, SRCCOPY
);
2142 BitBlt (himlDst
->hdcMask
, 0, 0, cxDst
, cyDst
, himl1
->hdcMask
, 0, 0, WHITENESS
);
2143 if (i1
>= 0 && i1
< himl1
->cCurImage
)
2144 BitBlt (himlDst
->hdcMask
, xOff1
, yOff1
, himl1
->cx
, himl1
->cy
, himl1
->hdcMask
, pt1
.x
, pt1
.y
, SRCCOPY
);
2145 if (i2
>= 0 && i2
< himl2
->cCurImage
)
2146 BitBlt (himlDst
->hdcMask
, xOff2
, yOff2
, himl2
->cx
, himl2
->cy
, himl2
->hdcMask
, pt2
.x
, pt2
.y
, SRCAND
);
2148 himlDst
->cCurImage
= 1;
2155 /* helper for ImageList_Read, see comments below */
2156 static void *read_bitmap(LPSTREAM pstm
, BITMAPINFO
*bmi
)
2158 BITMAPFILEHEADER bmfh
;
2159 int bitsperpixel
, palspace
;
2162 if (FAILED(IStream_Read ( pstm
, &bmfh
, sizeof(bmfh
), NULL
)))
2165 if (bmfh
.bfType
!= (('M'<<8)|'B'))
2168 if (FAILED(IStream_Read ( pstm
, &bmi
->bmiHeader
, sizeof(bmi
->bmiHeader
), NULL
)))
2171 if ((bmi
->bmiHeader
.biSize
!= sizeof(bmi
->bmiHeader
)))
2174 TRACE("width %u, height %u, planes %u, bpp %u\n",
2175 bmi
->bmiHeader
.biWidth
, bmi
->bmiHeader
.biHeight
,
2176 bmi
->bmiHeader
.biPlanes
, bmi
->bmiHeader
.biBitCount
);
2178 bitsperpixel
= bmi
->bmiHeader
.biPlanes
* bmi
->bmiHeader
.biBitCount
;
2179 if (bitsperpixel
<=8)
2180 palspace
= (1<<bitsperpixel
)*sizeof(RGBQUAD
);
2184 bmi
->bmiHeader
.biSizeImage
= get_dib_image_size( bmi
);
2186 /* read the palette right after the end of the bitmapinfoheader */
2187 if (palspace
&& FAILED(IStream_Read(pstm
, bmi
->bmiColors
, palspace
, NULL
)))
2190 bits
= Alloc(bmi
->bmiHeader
.biSizeImage
);
2191 if (!bits
) return NULL
;
2193 if (FAILED(IStream_Read(pstm
, bits
, bmi
->bmiHeader
.biSizeImage
, NULL
)))
2201 /*************************************************************************
2202 * ImageList_Read [COMCTL32.@]
2204 * Reads an image list from a stream.
2207 * pstm [I] pointer to a stream
2210 * Success: handle to image list
2213 * The format is like this:
2214 * ILHEAD ilheadstruct;
2216 * for the color image part:
2217 * BITMAPFILEHEADER bmfh;
2218 * BITMAPINFOHEADER bmih;
2219 * only if it has a palette:
2220 * RGBQUAD rgbs[nr_of_paletted_colors];
2222 * BYTE colorbits[imagesize];
2224 * the following only if the ILC_MASK bit is set in ILHEAD.ilFlags:
2225 * BITMAPFILEHEADER bmfh_mask;
2226 * BITMAPINFOHEADER bmih_mask;
2227 * only if it has a palette (it usually does not):
2228 * RGBQUAD rgbs[nr_of_paletted_colors];
2230 * BYTE maskbits[imagesize];
2232 HIMAGELIST WINAPI
ImageList_Read (LPSTREAM pstm
)
2234 char image_buf
[sizeof(BITMAPINFOHEADER
) + sizeof(RGBQUAD
) * 256];
2235 char mask_buf
[sizeof(BITMAPINFOHEADER
) + sizeof(RGBQUAD
) * 256];
2236 BITMAPINFO
*image_info
= (BITMAPINFO
*)image_buf
;
2237 BITMAPINFO
*mask_info
= (BITMAPINFO
*)mask_buf
;
2238 void *image_bits
, *mask_bits
= NULL
;
2243 TRACE("%p\n", pstm
);
2245 if (FAILED(IStream_Read (pstm
, &ilHead
, sizeof(ILHEAD
), NULL
)))
2247 if (ilHead
.usMagic
!= (('L' << 8) | 'I'))
2249 if (ilHead
.usVersion
!= 0x101) /* probably version? */
2252 TRACE("cx %u, cy %u, flags 0x%04x, cCurImage %u, cMaxImage %u\n",
2253 ilHead
.cx
, ilHead
.cy
, ilHead
.flags
, ilHead
.cCurImage
, ilHead
.cMaxImage
);
2255 himl
= ImageList_Create(ilHead
.cx
, ilHead
.cy
, ilHead
.flags
, ilHead
.cCurImage
, ilHead
.cMaxImage
);
2259 if (!(image_bits
= read_bitmap(pstm
, image_info
)))
2261 WARN("failed to read bitmap from stream\n");
2264 if (ilHead
.flags
& ILC_MASK
)
2266 if (!(mask_bits
= read_bitmap(pstm
, mask_info
)))
2268 WARN("failed to read mask bitmap from stream\n");
2272 else mask_info
= NULL
;
2274 if (himl
->has_alpha
&& image_info
->bmiHeader
.biBitCount
== 32)
2276 DWORD
*ptr
= image_bits
;
2277 BYTE
*mask_ptr
= mask_bits
;
2278 int stride
= himl
->cy
* image_info
->bmiHeader
.biWidth
;
2280 if (image_info
->bmiHeader
.biHeight
> 0) /* bottom-up */
2282 ptr
+= image_info
->bmiHeader
.biHeight
* image_info
->bmiHeader
.biWidth
- stride
;
2283 mask_ptr
+= (image_info
->bmiHeader
.biHeight
* image_info
->bmiHeader
.biWidth
- stride
) / 8;
2285 image_info
->bmiHeader
.biHeight
= himl
->cy
;
2287 else image_info
->bmiHeader
.biHeight
= -himl
->cy
;
2289 for (i
= 0; i
< ilHead
.cCurImage
; i
+= TILE_COUNT
)
2291 add_dib_bits( himl
, i
, min( ilHead
.cCurImage
- i
, TILE_COUNT
),
2292 himl
->cx
, himl
->cy
, image_info
, mask_info
, ptr
, mask_ptr
);
2294 mask_ptr
+= stride
/ 8;
2299 StretchDIBits( himl
->hdcImage
, 0, 0, image_info
->bmiHeader
.biWidth
, image_info
->bmiHeader
.biHeight
,
2300 0, 0, image_info
->bmiHeader
.biWidth
, image_info
->bmiHeader
.biHeight
,
2301 image_bits
, image_info
, DIB_RGB_COLORS
, SRCCOPY
);
2303 StretchDIBits( himl
->hdcMask
, 0, 0, mask_info
->bmiHeader
.biWidth
, mask_info
->bmiHeader
.biHeight
,
2304 0, 0, mask_info
->bmiHeader
.biWidth
, mask_info
->bmiHeader
.biHeight
,
2305 mask_bits
, mask_info
, DIB_RGB_COLORS
, SRCCOPY
);
2310 himl
->cCurImage
= ilHead
.cCurImage
;
2311 himl
->cMaxImage
= ilHead
.cMaxImage
;
2313 ImageList_SetBkColor(himl
,ilHead
.bkcolor
);
2315 ImageList_SetOverlayImage(himl
,ilHead
.ovls
[i
],i
+1);
2320 /*************************************************************************
2321 * ImageList_Remove [COMCTL32.@]
2323 * Removes an image from an image list
2326 * himl [I] image list handle
2333 * FIXME: as the image list storage test shows, native comctl32 simply shifts
2334 * images without creating a new bitmap.
2337 ImageList_Remove (HIMAGELIST himl
, INT i
)
2339 HBITMAP hbmNewImage
, hbmNewMask
;
2343 TRACE("(himl=%p i=%d)\n", himl
, i
);
2345 if (!is_valid(himl
)) {
2346 ERR("Invalid image list handle!\n");
2350 if ((i
< -1) || (i
>= himl
->cCurImage
)) {
2351 TRACE("index out of range! %d\n", i
);
2359 if (himl
->cCurImage
== 0) {
2360 /* remove all on empty ImageList is allowed */
2361 TRACE("remove all on empty ImageList!\n");
2365 himl
->cMaxImage
= himl
->cGrow
;
2366 himl
->cCurImage
= 0;
2367 for (nCount
= 0; nCount
< MAX_OVERLAYIMAGE
; nCount
++)
2368 himl
->nOvlIdx
[nCount
] = -1;
2370 if (himl
->has_alpha
)
2372 HeapFree( GetProcessHeap(), 0, himl
->has_alpha
);
2373 himl
->has_alpha
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, himl
->cMaxImage
);
2376 hbmNewImage
= ImageList_CreateImage(himl
->hdcImage
, himl
, himl
->cMaxImage
);
2377 SelectObject (himl
->hdcImage
, hbmNewImage
);
2378 DeleteObject (himl
->hbmImage
);
2379 himl
->hbmImage
= hbmNewImage
;
2381 if (himl
->hbmMask
) {
2383 imagelist_get_bitmap_size(himl
, himl
->cMaxImage
, &sz
);
2384 hbmNewMask
= CreateBitmap (sz
.cx
, sz
.cy
, 1, 1, NULL
);
2385 SelectObject (himl
->hdcMask
, hbmNewMask
);
2386 DeleteObject (himl
->hbmMask
);
2387 himl
->hbmMask
= hbmNewMask
;
2391 /* delete one image */
2392 TRACE("Remove single image! %d\n", i
);
2394 /* create new bitmap(s) */
2395 TRACE(" - Number of images: %d / %d (Old/New)\n",
2396 himl
->cCurImage
, himl
->cCurImage
- 1);
2398 hbmNewImage
= ImageList_CreateImage(himl
->hdcImage
, himl
, himl
->cMaxImage
);
2400 imagelist_get_bitmap_size(himl
, himl
->cMaxImage
, &sz
);
2402 hbmNewMask
= CreateBitmap (sz
.cx
, sz
.cy
, 1, 1, NULL
);
2404 hbmNewMask
= 0; /* Just to keep compiler happy! */
2406 hdcBmp
= CreateCompatibleDC (0);
2408 /* copy all images and masks prior to the "removed" image */
2410 TRACE("Pre image copy: Copy %d images\n", i
);
2412 SelectObject (hdcBmp
, hbmNewImage
);
2413 imagelist_copy_images( himl
, himl
->hdcImage
, hdcBmp
, 0, i
, 0 );
2415 if (himl
->hbmMask
) {
2416 SelectObject (hdcBmp
, hbmNewMask
);
2417 imagelist_copy_images( himl
, himl
->hdcMask
, hdcBmp
, 0, i
, 0 );
2421 /* copy all images and masks behind the removed image */
2422 if (i
< himl
->cCurImage
- 1) {
2423 TRACE("Post image copy!\n");
2425 SelectObject (hdcBmp
, hbmNewImage
);
2426 imagelist_copy_images( himl
, himl
->hdcImage
, hdcBmp
, i
+ 1,
2427 (himl
->cCurImage
- i
), i
);
2429 if (himl
->hbmMask
) {
2430 SelectObject (hdcBmp
, hbmNewMask
);
2431 imagelist_copy_images( himl
, himl
->hdcMask
, hdcBmp
, i
+ 1,
2432 (himl
->cCurImage
- i
), i
);
2438 /* delete old images and insert new ones */
2439 SelectObject (himl
->hdcImage
, hbmNewImage
);
2440 DeleteObject (himl
->hbmImage
);
2441 himl
->hbmImage
= hbmNewImage
;
2442 if (himl
->hbmMask
) {
2443 SelectObject (himl
->hdcMask
, hbmNewMask
);
2444 DeleteObject (himl
->hbmMask
);
2445 himl
->hbmMask
= hbmNewMask
;
2455 /*************************************************************************
2456 * ImageList_Replace [COMCTL32.@]
2458 * Replaces an image in an image list with a new image.
2461 * himl [I] handle to image list
2463 * hbmImage [I] handle to image bitmap
2464 * hbmMask [I] handle to mask bitmap. Can be NULL.
2472 ImageList_Replace (HIMAGELIST himl
, INT i
, HBITMAP hbmImage
,
2479 TRACE("%p %d %p %p\n", himl
, i
, hbmImage
, hbmMask
);
2481 if (!is_valid(himl
)) {
2482 ERR("Invalid image list handle!\n");
2486 if ((i
>= himl
->cMaxImage
) || (i
< 0)) {
2487 ERR("Invalid image index!\n");
2491 if (!GetObjectW(hbmImage
, sizeof(BITMAP
), &bmp
))
2494 hdcImage
= CreateCompatibleDC (0);
2497 SelectObject (hdcImage
, hbmImage
);
2499 if (add_with_alpha( himl
, hdcImage
, i
, 1, bmp
.bmWidth
, bmp
.bmHeight
, hbmImage
, hbmMask
))
2502 imagelist_point_from_index(himl
, i
, &pt
);
2503 StretchBlt (himl
->hdcImage
, pt
.x
, pt
.y
, himl
->cx
, himl
->cy
,
2504 hdcImage
, 0, 0, bmp
.bmWidth
, bmp
.bmHeight
, SRCCOPY
);
2509 HBITMAP hOldBitmapTemp
;
2511 hdcTemp
= CreateCompatibleDC(0);
2512 hOldBitmapTemp
= SelectObject(hdcTemp
, hbmMask
);
2514 StretchBlt (himl
->hdcMask
, pt
.x
, pt
.y
, himl
->cx
, himl
->cy
,
2515 hdcTemp
, 0, 0, bmp
.bmWidth
, bmp
.bmHeight
, SRCCOPY
);
2516 SelectObject(hdcTemp
, hOldBitmapTemp
);
2519 /* Remove the background from the image
2521 BitBlt (himl
->hdcImage
, pt
.x
, pt
.y
, bmp
.bmWidth
, bmp
.bmHeight
,
2522 himl
->hdcMask
, pt
.x
, pt
.y
, 0x220326); /* NOTSRCAND */
2526 DeleteDC (hdcImage
);
2532 /*************************************************************************
2533 * ImageList_ReplaceIcon [COMCTL32.@]
2535 * Replaces an image in an image list using an icon.
2538 * himl [I] handle to image list
2540 * hIcon [I] handle to icon
2543 * Success: index of the replaced image
2548 ImageList_ReplaceIcon (HIMAGELIST himl
, INT nIndex
, HICON hIcon
)
2556 TRACE("(%p %d %p)\n", himl
, nIndex
, hIcon
);
2558 if (!is_valid(himl
)) {
2559 ERR("invalid image list\n");
2562 if ((nIndex
>= himl
->cMaxImage
) || (nIndex
< -1)) {
2563 ERR("invalid image index %d / %d\n", nIndex
, himl
->cMaxImage
);
2567 hBestFitIcon
= CopyImage(
2570 LR_COPYFROMRESOURCE
);
2571 /* the above will fail if the icon wasn't loaded from a resource, so try
2572 * again without LR_COPYFROMRESOURCE flag */
2574 hBestFitIcon
= CopyImage(
2582 if (himl
->cCurImage
+ 1 >= himl
->cMaxImage
)
2583 IMAGELIST_InternalExpandBitmaps(himl
, 1);
2585 nIndex
= himl
->cCurImage
;
2589 if (himl
->has_alpha
&& GetIconInfo (hBestFitIcon
, &ii
))
2591 HDC hdcImage
= CreateCompatibleDC( 0 );
2592 GetObjectW (ii
.hbmMask
, sizeof(BITMAP
), &bmp
);
2596 UINT height
= bmp
.bmHeight
/ 2;
2597 HDC hdcMask
= CreateCompatibleDC( 0 );
2598 HBITMAP color
= CreateBitmap( bmp
.bmWidth
, height
, 1, 1, NULL
);
2599 SelectObject( hdcImage
, color
);
2600 SelectObject( hdcMask
, ii
.hbmMask
);
2601 BitBlt( hdcImage
, 0, 0, bmp
.bmWidth
, height
, hdcMask
, 0, height
, SRCCOPY
);
2602 ret
= add_with_alpha( himl
, hdcImage
, nIndex
, 1, bmp
.bmWidth
, height
, color
, ii
.hbmMask
);
2603 DeleteDC( hdcMask
);
2604 DeleteObject( color
);
2606 else ret
= add_with_alpha( himl
, hdcImage
, nIndex
, 1, bmp
.bmWidth
, bmp
.bmHeight
,
2607 ii
.hbmColor
, ii
.hbmMask
);
2609 DeleteDC( hdcImage
);
2610 DeleteObject (ii
.hbmMask
);
2611 if (ii
.hbmColor
) DeleteObject (ii
.hbmColor
);
2615 imagelist_point_from_index(himl
, nIndex
, &pt
);
2619 DrawIconEx( himl
->hdcImage
, pt
.x
, pt
.y
, hBestFitIcon
, himl
->cx
, himl
->cy
, 0, 0, DI_IMAGE
);
2620 PatBlt( himl
->hdcMask
, pt
.x
, pt
.y
, himl
->cx
, himl
->cy
, WHITENESS
);
2621 DrawIconEx( himl
->hdcMask
, pt
.x
, pt
.y
, hBestFitIcon
, himl
->cx
, himl
->cy
, 0, 0, DI_MASK
);
2625 COLORREF color
= himl
->clrBk
!= CLR_NONE
? himl
->clrBk
: comctl32_color
.clrWindow
;
2626 HBRUSH brush
= CreateSolidBrush( GetNearestColor( himl
->hdcImage
, color
));
2628 SelectObject( himl
->hdcImage
, brush
);
2629 PatBlt( himl
->hdcImage
, pt
.x
, pt
.y
, himl
->cx
, himl
->cy
, PATCOPY
);
2630 SelectObject( himl
->hdcImage
, GetStockObject(BLACK_BRUSH
) );
2631 DeleteObject( brush
);
2632 DrawIconEx( himl
->hdcImage
, pt
.x
, pt
.y
, hBestFitIcon
, himl
->cx
, himl
->cy
, 0, 0, DI_NORMAL
);
2636 DestroyIcon(hBestFitIcon
);
2638 TRACE("Insert index = %d, himl->cCurImage = %d\n", nIndex
, himl
->cCurImage
);
2643 /*************************************************************************
2644 * ImageList_SetBkColor [COMCTL32.@]
2646 * Sets the background color of an image list.
2649 * himl [I] handle to image list
2650 * clrBk [I] background color
2653 * Success: previous background color
2658 ImageList_SetBkColor (HIMAGELIST himl
, COLORREF clrBk
)
2662 if (!is_valid(himl
))
2665 clrOldBk
= himl
->clrBk
;
2666 himl
->clrBk
= clrBk
;
2671 /*************************************************************************
2672 * ImageList_SetDragCursorImage [COMCTL32.@]
2674 * Combines the specified image with the current drag image
2677 * himlDrag [I] handle to drag image list
2678 * iDrag [I] drag image index
2679 * dxHotspot [I] X position of the hot spot
2680 * dyHotspot [I] Y position of the hot spot
2687 * - The names dxHotspot, dyHotspot are misleading because they have nothing
2688 * to do with a hotspot but are only the offset of the origin of the new
2689 * image relative to the origin of the old image.
2691 * - When this function is called and the drag image is visible, a
2692 * short flickering occurs but this matches the Win9x behavior. It is
2693 * possible to fix the flickering using code like in ImageList_DragMove.
2697 ImageList_SetDragCursorImage (HIMAGELIST himlDrag
, INT iDrag
,
2698 INT dxHotspot
, INT dyHotspot
)
2700 HIMAGELIST himlTemp
;
2703 if (!is_valid(InternalDrag
.himl
) || !is_valid(himlDrag
))
2706 TRACE(" dxH=%d dyH=%d nX=%d nY=%d\n",
2707 dxHotspot
, dyHotspot
, InternalDrag
.dxHotspot
, InternalDrag
.dyHotspot
);
2709 visible
= InternalDrag
.bShow
;
2711 himlTemp
= ImageList_Merge (InternalDrag
.himlNoCursor
, 0, himlDrag
, iDrag
,
2712 dxHotspot
, dyHotspot
);
2715 /* hide the drag image */
2716 ImageList_DragShowNolock(FALSE
);
2718 if ((InternalDrag
.himl
->cx
!= himlTemp
->cx
) ||
2719 (InternalDrag
.himl
->cy
!= himlTemp
->cy
)) {
2720 /* the size of the drag image changed, invalidate the buffer */
2721 DeleteObject(InternalDrag
.hbmBg
);
2722 InternalDrag
.hbmBg
= 0;
2725 if (InternalDrag
.himl
!= InternalDrag
.himlNoCursor
)
2726 ImageList_Destroy (InternalDrag
.himl
);
2727 InternalDrag
.himl
= himlTemp
;
2730 /* show the drag image */
2731 ImageList_DragShowNolock(TRUE
);
2738 /*************************************************************************
2739 * ImageList_SetFilter [COMCTL32.@]
2741 * Sets a filter (or does something completely different)!!???
2742 * It removes 12 Bytes from the stack (3 Parameters).
2745 * himl [I] SHOULD be a handle to image list
2746 * i [I] COULD be an index?
2751 * Failure: FALSE ???
2754 * This is an UNDOCUMENTED function!!!!
2759 ImageList_SetFilter (HIMAGELIST himl
, INT i
, DWORD dwFilter
)
2761 FIXME("(%p 0x%x 0x%x):empty stub!\n", himl
, i
, dwFilter
);
2767 /*************************************************************************
2768 * ImageList_SetFlags [COMCTL32.@]
2770 * Sets the image list flags.
2773 * himl [I] Handle to image list
2774 * flags [I] Flags to set
2784 ImageList_SetFlags(HIMAGELIST himl
, DWORD flags
)
2786 FIXME("(%p %08x):empty stub\n", himl
, flags
);
2791 /*************************************************************************
2792 * ImageList_SetIconSize [COMCTL32.@]
2794 * Sets the image size of the bitmap and deletes all images.
2797 * himl [I] handle to image list
2798 * cx [I] image width
2799 * cy [I] image height
2807 ImageList_SetIconSize (HIMAGELIST himl
, INT cx
, INT cy
)
2812 if (!is_valid(himl
))
2815 /* remove all images */
2816 himl
->cMaxImage
= himl
->cInitial
+ 1;
2817 himl
->cCurImage
= 0;
2821 /* initialize overlay mask indices */
2822 for (nCount
= 0; nCount
< MAX_OVERLAYIMAGE
; nCount
++)
2823 himl
->nOvlIdx
[nCount
] = -1;
2825 hbmNew
= ImageList_CreateImage(himl
->hdcImage
, himl
, himl
->cMaxImage
);
2826 SelectObject (himl
->hdcImage
, hbmNew
);
2827 DeleteObject (himl
->hbmImage
);
2828 himl
->hbmImage
= hbmNew
;
2830 if (himl
->hbmMask
) {
2832 imagelist_get_bitmap_size(himl
, himl
->cMaxImage
, &sz
);
2833 hbmNew
= CreateBitmap (sz
.cx
, sz
.cy
, 1, 1, NULL
);
2834 SelectObject (himl
->hdcMask
, hbmNew
);
2835 DeleteObject (himl
->hbmMask
);
2836 himl
->hbmMask
= hbmNew
;
2843 /*************************************************************************
2844 * ImageList_SetImageCount [COMCTL32.@]
2846 * Resizes an image list to the specified number of images.
2849 * himl [I] handle to image list
2850 * iImageCount [I] number of images in the image list
2858 ImageList_SetImageCount (HIMAGELIST himl
, UINT iImageCount
)
2861 HBITMAP hbmNewBitmap
, hbmOld
;
2862 INT nNewCount
, nCopyCount
;
2864 TRACE("%p %d\n",himl
,iImageCount
);
2866 if (!is_valid(himl
))
2869 nNewCount
= iImageCount
+ 1;
2870 nCopyCount
= min(himl
->cCurImage
, iImageCount
);
2872 hdcBitmap
= CreateCompatibleDC (0);
2874 hbmNewBitmap
= ImageList_CreateImage(hdcBitmap
, himl
, nNewCount
);
2876 if (hbmNewBitmap
!= 0)
2878 hbmOld
= SelectObject (hdcBitmap
, hbmNewBitmap
);
2879 imagelist_copy_images( himl
, himl
->hdcImage
, hdcBitmap
, 0, nCopyCount
, 0 );
2880 SelectObject (hdcBitmap
, hbmOld
);
2882 /* FIXME: delete 'empty' image space? */
2884 SelectObject (himl
->hdcImage
, hbmNewBitmap
);
2885 DeleteObject (himl
->hbmImage
);
2886 himl
->hbmImage
= hbmNewBitmap
;
2889 ERR("Could not create new image bitmap!\n");
2894 imagelist_get_bitmap_size( himl
, nNewCount
, &sz
);
2895 hbmNewBitmap
= CreateBitmap (sz
.cx
, sz
.cy
, 1, 1, NULL
);
2896 if (hbmNewBitmap
!= 0)
2898 hbmOld
= SelectObject (hdcBitmap
, hbmNewBitmap
);
2899 imagelist_copy_images( himl
, himl
->hdcMask
, hdcBitmap
, 0, nCopyCount
, 0 );
2900 SelectObject (hdcBitmap
, hbmOld
);
2902 /* FIXME: delete 'empty' image space? */
2904 SelectObject (himl
->hdcMask
, hbmNewBitmap
);
2905 DeleteObject (himl
->hbmMask
);
2906 himl
->hbmMask
= hbmNewBitmap
;
2909 ERR("Could not create new mask bitmap!\n");
2912 DeleteDC (hdcBitmap
);
2914 if (himl
->has_alpha
)
2916 char *new_alpha
= HeapReAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, himl
->has_alpha
, nNewCount
);
2917 if (new_alpha
) himl
->has_alpha
= new_alpha
;
2920 HeapFree( GetProcessHeap(), 0, himl
->has_alpha
);
2921 himl
->has_alpha
= NULL
;
2925 /* Update max image count and current image count */
2926 himl
->cMaxImage
= nNewCount
;
2927 himl
->cCurImage
= iImageCount
;
2933 /*************************************************************************
2934 * ImageList_SetOverlayImage [COMCTL32.@]
2936 * Assigns an overlay mask index to an existing image in an image list.
2939 * himl [I] handle to image list
2940 * iImage [I] image index
2941 * iOverlay [I] overlay mask index
2949 ImageList_SetOverlayImage (HIMAGELIST himl
, INT iImage
, INT iOverlay
)
2951 if (!is_valid(himl
))
2953 if ((iOverlay
< 1) || (iOverlay
> MAX_OVERLAYIMAGE
))
2955 if ((iImage
!=-1) && ((iImage
< 0) || (iImage
> himl
->cCurImage
)))
2957 himl
->nOvlIdx
[iOverlay
- 1] = iImage
;
2963 /* helper for ImageList_Write - write bitmap to pstm
2964 * currently everything is written as 24 bit RGB, except masks
2967 _write_bitmap(HBITMAP hBitmap
, LPSTREAM pstm
)
2969 LPBITMAPFILEHEADER bmfh
;
2970 LPBITMAPINFOHEADER bmih
;
2971 LPBYTE data
= NULL
, lpBits
;
2973 INT bitCount
, sizeImage
, offBits
, totalSize
;
2975 BOOL result
= FALSE
;
2977 if (!GetObjectW(hBitmap
, sizeof(BITMAP
), &bm
))
2980 bitCount
= bm
.bmBitsPixel
;
2981 sizeImage
= get_dib_stride(bm
.bmWidth
, bitCount
) * bm
.bmHeight
;
2983 totalSize
= sizeof(BITMAPFILEHEADER
) + sizeof(BITMAPINFOHEADER
);
2985 totalSize
+= (1 << bitCount
) * sizeof(RGBQUAD
);
2986 offBits
= totalSize
;
2987 totalSize
+= sizeImage
;
2989 data
= Alloc(totalSize
);
2990 bmfh
= (LPBITMAPFILEHEADER
)data
;
2991 bmih
= (LPBITMAPINFOHEADER
)(data
+ sizeof(BITMAPFILEHEADER
));
2992 lpBits
= data
+ offBits
;
2994 /* setup BITMAPFILEHEADER */
2995 bmfh
->bfType
= (('M' << 8) | 'B');
2996 bmfh
->bfSize
= offBits
;
2997 bmfh
->bfReserved1
= 0;
2998 bmfh
->bfReserved2
= 0;
2999 bmfh
->bfOffBits
= offBits
;
3001 /* setup BITMAPINFOHEADER */
3002 bmih
->biSize
= sizeof(BITMAPINFOHEADER
);
3003 bmih
->biWidth
= bm
.bmWidth
;
3004 bmih
->biHeight
= bm
.bmHeight
;
3006 bmih
->biBitCount
= bitCount
;
3007 bmih
->biCompression
= BI_RGB
;
3008 bmih
->biSizeImage
= sizeImage
;
3009 bmih
->biXPelsPerMeter
= 0;
3010 bmih
->biYPelsPerMeter
= 0;
3011 bmih
->biClrUsed
= 0;
3012 bmih
->biClrImportant
= 0;
3015 result
= GetDIBits(xdc
, hBitmap
, 0, bm
.bmHeight
, lpBits
, (BITMAPINFO
*)bmih
, DIB_RGB_COLORS
) == bm
.bmHeight
;
3020 TRACE("width %u, height %u, planes %u, bpp %u\n",
3021 bmih
->biWidth
, bmih
->biHeight
,
3022 bmih
->biPlanes
, bmih
->biBitCount
);
3024 if(FAILED(IStream_Write(pstm
, data
, totalSize
, NULL
)))
3036 /*************************************************************************
3037 * ImageList_Write [COMCTL32.@]
3039 * Writes an image list to a stream.
3042 * himl [I] handle to image list
3043 * pstm [O] Pointer to a stream.
3054 ImageList_Write (HIMAGELIST himl
, LPSTREAM pstm
)
3059 TRACE("%p %p\n", himl
, pstm
);
3061 if (!is_valid(himl
))
3064 ilHead
.usMagic
= (('L' << 8) | 'I');
3065 ilHead
.usVersion
= 0x101;
3066 ilHead
.cCurImage
= himl
->cCurImage
;
3067 ilHead
.cMaxImage
= himl
->cMaxImage
;
3068 ilHead
.cGrow
= himl
->cGrow
;
3069 ilHead
.cx
= himl
->cx
;
3070 ilHead
.cy
= himl
->cy
;
3071 ilHead
.bkcolor
= himl
->clrBk
;
3072 ilHead
.flags
= himl
->flags
;
3073 for(i
= 0; i
< 4; i
++) {
3074 ilHead
.ovls
[i
] = himl
->nOvlIdx
[i
];
3077 TRACE("cx %u, cy %u, flags 0x04%x, cCurImage %u, cMaxImage %u\n",
3078 ilHead
.cx
, ilHead
.cy
, ilHead
.flags
, ilHead
.cCurImage
, ilHead
.cMaxImage
);
3080 if(FAILED(IStream_Write(pstm
, &ilHead
, sizeof(ILHEAD
), NULL
)))
3083 /* write the bitmap */
3084 if(!_write_bitmap(himl
->hbmImage
, pstm
))
3087 /* write the mask if we have one */
3088 if(himl
->flags
& ILC_MASK
) {
3089 if(!_write_bitmap(himl
->hbmMask
, pstm
))
3097 static HBITMAP
ImageList_CreateImage(HDC hdc
, HIMAGELIST himl
, UINT count
)
3099 HBITMAP hbmNewBitmap
;
3100 UINT ilc
= (himl
->flags
& 0xFE);
3103 imagelist_get_bitmap_size( himl
, count
, &sz
);
3105 if ((ilc
>= ILC_COLOR4
&& ilc
<= ILC_COLOR32
) || ilc
== ILC_COLOR
)
3107 char buffer
[sizeof(BITMAPINFOHEADER
) + 256 * sizeof(RGBQUAD
)];
3108 BITMAPINFO
*bmi
= (BITMAPINFO
*)buffer
;
3110 TRACE("Creating DIBSection %d x %d, %d Bits per Pixel\n",
3111 sz
.cx
, sz
.cy
, himl
->uBitsPixel
);
3113 memset( buffer
, 0, sizeof(buffer
) );
3114 bmi
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
3115 bmi
->bmiHeader
.biWidth
= sz
.cx
;
3116 bmi
->bmiHeader
.biHeight
= sz
.cy
;
3117 bmi
->bmiHeader
.biPlanes
= 1;
3118 bmi
->bmiHeader
.biBitCount
= himl
->uBitsPixel
;
3119 bmi
->bmiHeader
.biCompression
= BI_RGB
;
3121 if (himl
->uBitsPixel
<= ILC_COLOR8
)
3123 /* retrieve the default color map */
3124 HBITMAP tmp
= CreateBitmap( 1, 1, 1, 1, NULL
);
3125 GetDIBits( hdc
, tmp
, 0, 0, NULL
, bmi
, DIB_RGB_COLORS
);
3126 DeleteObject( tmp
);
3128 hbmNewBitmap
= CreateDIBSection(hdc
, bmi
, DIB_RGB_COLORS
, NULL
, 0, 0);
3130 else /*if (ilc == ILC_COLORDDB)*/
3132 TRACE("Creating Bitmap: %d Bits per Pixel\n", himl
->uBitsPixel
);
3134 hbmNewBitmap
= CreateBitmap (sz
.cx
, sz
.cy
, 1, himl
->uBitsPixel
, NULL
);
3136 TRACE("returning %p\n", hbmNewBitmap
);
3137 return hbmNewBitmap
;
3140 /*************************************************************************
3141 * ImageList_SetColorTable [COMCTL32.@]
3143 * Sets the color table of an image list.
3146 * himl [I] Handle to the image list.
3147 * uStartIndex [I] The first index to set.
3148 * cEntries [I] Number of entries to set.
3149 * prgb [I] New color information for color table for the image list.
3152 * Success: Number of entries in the table that were set.
3156 * ImageList_Create(), SetDIBColorTable()
3160 ImageList_SetColorTable(HIMAGELIST himl
, UINT uStartIndex
, UINT cEntries
, const RGBQUAD
*prgb
)
3162 return SetDIBColorTable(himl
->hdcImage
, uStartIndex
, cEntries
, prgb
);
3165 /*************************************************************************
3166 * ImageList_CoCreateInstance [COMCTL32.@]
3168 * Creates a new imagelist instance and returns an interface pointer to it.
3171 * rclsid [I] A reference to the CLSID (CLSID_ImageList).
3172 * punkOuter [I] Pointer to IUnknown interface for aggregation, if desired
3173 * riid [I] Identifier of the requested interface.
3174 * ppv [O] Returns the address of the pointer requested, or NULL.
3178 * Failure: Error value.
3181 ImageList_CoCreateInstance (REFCLSID rclsid
, const IUnknown
*punkOuter
, REFIID riid
, void **ppv
)
3183 TRACE("(%s,%p,%s,%p)\n", debugstr_guid(rclsid
), punkOuter
, debugstr_guid(riid
), ppv
);
3185 if (!IsEqualCLSID(&CLSID_ImageList
, rclsid
))
3186 return E_NOINTERFACE
;
3188 return ImageListImpl_CreateInstance(punkOuter
, riid
, ppv
);
3192 /*************************************************************************
3193 * IImageList implementation
3196 static HRESULT WINAPI
ImageListImpl_QueryInterface(IImageList2
*iface
,
3197 REFIID iid
, void **ppv
)
3199 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3201 TRACE("(%p,%s,%p)\n", iface
, debugstr_guid(iid
), ppv
);
3203 if (!ppv
) return E_INVALIDARG
;
3205 if (IsEqualIID(&IID_IUnknown
, iid
) ||
3206 IsEqualIID(&IID_IImageList
, iid
) ||
3207 IsEqualIID(&IID_IImageList2
, iid
))
3209 *ppv
= &imgl
->IImageList2_iface
;
3214 return E_NOINTERFACE
;
3217 IImageList2_AddRef(iface
);
3221 static ULONG WINAPI
ImageListImpl_AddRef(IImageList2
*iface
)
3223 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3224 ULONG ref
= InterlockedIncrement(&imgl
->ref
);
3226 TRACE("(%p) refcount=%u\n", iface
, ref
);
3230 static ULONG WINAPI
ImageListImpl_Release(IImageList2
*iface
)
3232 HIMAGELIST This
= impl_from_IImageList2(iface
);
3233 ULONG ref
= InterlockedDecrement(&This
->ref
);
3235 TRACE("(%p) refcount=%u\n", iface
, ref
);
3239 /* delete image bitmaps */
3240 if (This
->hbmImage
) DeleteObject (This
->hbmImage
);
3241 if (This
->hbmMask
) DeleteObject (This
->hbmMask
);
3243 /* delete image & mask DCs */
3244 if (This
->hdcImage
) DeleteDC (This
->hdcImage
);
3245 if (This
->hdcMask
) DeleteDC (This
->hdcMask
);
3247 /* delete blending brushes */
3248 if (This
->hbrBlend25
) DeleteObject (This
->hbrBlend25
);
3249 if (This
->hbrBlend50
) DeleteObject (This
->hbrBlend50
);
3251 This
->IImageList2_iface
.lpVtbl
= NULL
;
3252 HeapFree(GetProcessHeap(), 0, This
->has_alpha
);
3253 HeapFree(GetProcessHeap(), 0, This
);
3259 static HRESULT WINAPI
ImageListImpl_Add(IImageList2
*iface
, HBITMAP hbmImage
,
3260 HBITMAP hbmMask
, int *pi
)
3262 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3268 ret
= ImageList_Add(imgl
, hbmImage
, hbmMask
);
3277 static HRESULT WINAPI
ImageListImpl_ReplaceIcon(IImageList2
*iface
, int i
,
3278 HICON hicon
, int *pi
)
3280 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3286 ret
= ImageList_ReplaceIcon(imgl
, i
, hicon
);
3295 static HRESULT WINAPI
ImageListImpl_SetOverlayImage(IImageList2
*iface
,
3296 int iImage
, int iOverlay
)
3298 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3299 return ImageList_SetOverlayImage(imgl
, iImage
, iOverlay
) ? S_OK
: E_FAIL
;
3302 static HRESULT WINAPI
ImageListImpl_Replace(IImageList2
*iface
, int i
,
3303 HBITMAP hbmImage
, HBITMAP hbmMask
)
3305 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3306 return ImageList_Replace(imgl
, i
, hbmImage
, hbmMask
) ? S_OK
: E_FAIL
;
3309 static HRESULT WINAPI
ImageListImpl_AddMasked(IImageList2
*iface
, HBITMAP hbmImage
,
3310 COLORREF crMask
, int *pi
)
3312 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3318 ret
= ImageList_AddMasked(imgl
, hbmImage
, crMask
);
3327 static HRESULT WINAPI
ImageListImpl_Draw(IImageList2
*iface
,
3328 IMAGELISTDRAWPARAMS
*pimldp
)
3330 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3331 HIMAGELIST old_himl
;
3334 /* As far as I can tell, Windows simply ignores the contents of pimldp->himl
3335 so we shall simulate the same */
3336 old_himl
= pimldp
->himl
;
3337 pimldp
->himl
= imgl
;
3339 ret
= ImageList_DrawIndirect(pimldp
);
3341 pimldp
->himl
= old_himl
;
3342 return ret
? S_OK
: E_INVALIDARG
;
3345 static HRESULT WINAPI
ImageListImpl_Remove(IImageList2
*iface
, int i
)
3347 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3348 return (ImageList_Remove(imgl
, i
) == 0) ? E_INVALIDARG
: S_OK
;
3351 static HRESULT WINAPI
ImageListImpl_GetIcon(IImageList2
*iface
, int i
, UINT flags
,
3354 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3360 hIcon
= ImageList_GetIcon(imgl
, i
, flags
);
3369 static HRESULT WINAPI
ImageListImpl_GetImageInfo(IImageList2
*iface
, int i
,
3370 IMAGEINFO
*pImageInfo
)
3372 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3373 return ImageList_GetImageInfo(imgl
, i
, pImageInfo
) ? S_OK
: E_FAIL
;
3376 static HRESULT WINAPI
ImageListImpl_Copy(IImageList2
*iface
, int dst_index
,
3377 IUnknown
*unk_src
, int src_index
, UINT flags
)
3379 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3380 IImageList
*src
= NULL
;
3386 /* TODO: Add test for IID_ImageList2 too */
3387 if (FAILED(IUnknown_QueryInterface(unk_src
, &IID_IImageList
,
3391 if (ImageList_Copy(imgl
, dst_index
, (HIMAGELIST
) src
, src_index
, flags
))
3396 IImageList_Release(src
);
3400 static HRESULT WINAPI
ImageListImpl_Merge(IImageList2
*iface
, int i1
,
3401 IUnknown
*punk2
, int i2
, int dx
, int dy
, REFIID riid
, void **ppv
)
3403 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3404 IImageList
*iml2
= NULL
;
3406 HRESULT ret
= E_FAIL
;
3408 TRACE("(%p)->(%d %p %d %d %d %s %p)\n", iface
, i1
, punk2
, i2
, dx
, dy
, debugstr_guid(riid
), ppv
);
3410 /* TODO: Add test for IID_ImageList2 too */
3411 if (FAILED(IUnknown_QueryInterface(punk2
, &IID_IImageList
,
3415 merged
= ImageList_Merge(imgl
, i1
, (HIMAGELIST
) iml2
, i2
, dx
, dy
);
3417 /* Get the interface for the new image list */
3420 ret
= HIMAGELIST_QueryInterface(merged
, riid
, ppv
);
3421 ImageList_Destroy(merged
);
3424 IImageList_Release(iml2
);
3428 static HRESULT WINAPI
ImageListImpl_Clone(IImageList2
*iface
, REFIID riid
, void **ppv
)
3430 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3432 HRESULT ret
= E_FAIL
;
3434 TRACE("(%p)->(%s %p)\n", iface
, debugstr_guid(riid
), ppv
);
3436 clone
= ImageList_Duplicate(imgl
);
3438 /* Get the interface for the new image list */
3441 ret
= HIMAGELIST_QueryInterface(clone
, riid
, ppv
);
3442 ImageList_Destroy(clone
);
3448 static HRESULT WINAPI
ImageListImpl_GetImageRect(IImageList2
*iface
, int i
,
3451 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3457 if (!ImageList_GetImageInfo(imgl
, i
, &info
))
3460 return CopyRect(prc
, &info
.rcImage
) ? S_OK
: E_FAIL
;
3463 static HRESULT WINAPI
ImageListImpl_GetIconSize(IImageList2
*iface
, int *cx
,
3466 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3467 return ImageList_GetIconSize(imgl
, cx
, cy
) ? S_OK
: E_INVALIDARG
;
3470 static HRESULT WINAPI
ImageListImpl_SetIconSize(IImageList2
*iface
, int cx
,
3473 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3474 return ImageList_SetIconSize(imgl
, cx
, cy
) ? S_OK
: E_FAIL
;
3477 static HRESULT WINAPI
ImageListImpl_GetImageCount(IImageList2
*iface
, int *pi
)
3479 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3480 *pi
= ImageList_GetImageCount(imgl
);
3484 static HRESULT WINAPI
ImageListImpl_SetImageCount(IImageList2
*iface
, UINT count
)
3486 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3487 return ImageList_SetImageCount(imgl
, count
) ? S_OK
: E_FAIL
;
3490 static HRESULT WINAPI
ImageListImpl_SetBkColor(IImageList2
*iface
, COLORREF clrBk
,
3493 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3494 *pclr
= ImageList_SetBkColor(imgl
, clrBk
);
3498 static HRESULT WINAPI
ImageListImpl_GetBkColor(IImageList2
*iface
, COLORREF
*pclr
)
3500 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3501 *pclr
= ImageList_GetBkColor(imgl
);
3505 static HRESULT WINAPI
ImageListImpl_BeginDrag(IImageList2
*iface
, int iTrack
,
3506 int dxHotspot
, int dyHotspot
)
3508 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3509 return ImageList_BeginDrag(imgl
, iTrack
, dxHotspot
, dyHotspot
) ? S_OK
: E_FAIL
;
3512 static HRESULT WINAPI
ImageListImpl_EndDrag(IImageList2
*iface
)
3514 ImageList_EndDrag();
3518 static HRESULT WINAPI
ImageListImpl_DragEnter(IImageList2
*iface
, HWND hwndLock
,
3521 return ImageList_DragEnter(hwndLock
, x
, y
) ? S_OK
: E_FAIL
;
3524 static HRESULT WINAPI
ImageListImpl_DragLeave(IImageList2
*iface
, HWND hwndLock
)
3526 return ImageList_DragLeave(hwndLock
) ? S_OK
: E_FAIL
;
3529 static HRESULT WINAPI
ImageListImpl_DragMove(IImageList2
*iface
, int x
, int y
)
3531 return ImageList_DragMove(x
, y
) ? S_OK
: E_FAIL
;
3534 static HRESULT WINAPI
ImageListImpl_SetDragCursorImage(IImageList2
*iface
,
3535 IUnknown
*punk
, int iDrag
, int dxHotspot
, int dyHotspot
)
3537 IImageList
*iml2
= NULL
;
3543 /* TODO: Add test for IID_ImageList2 too */
3544 if (FAILED(IUnknown_QueryInterface(punk
, &IID_IImageList
,
3548 ret
= ImageList_SetDragCursorImage((HIMAGELIST
) iml2
, iDrag
, dxHotspot
,
3551 IImageList_Release(iml2
);
3553 return ret
? S_OK
: E_FAIL
;
3556 static HRESULT WINAPI
ImageListImpl_DragShowNolock(IImageList2
*iface
, BOOL fShow
)
3558 return ImageList_DragShowNolock(fShow
) ? S_OK
: E_FAIL
;
3561 static HRESULT WINAPI
ImageListImpl_GetDragImage(IImageList2
*iface
, POINT
*ppt
,
3562 POINT
*pptHotspot
, REFIID riid
, PVOID
*ppv
)
3564 HRESULT ret
= E_FAIL
;
3570 hNew
= ImageList_GetDragImage(ppt
, pptHotspot
);
3572 /* Get the interface for the new image list */
3575 IImageList
*idrag
= (IImageList
*)hNew
;
3577 ret
= HIMAGELIST_QueryInterface(hNew
, riid
, ppv
);
3578 IImageList_Release(idrag
);
3584 static HRESULT WINAPI
ImageListImpl_GetItemFlags(IImageList2
*iface
, int i
,
3587 FIXME("STUB: %p %d %p\n", iface
, i
, dwFlags
);
3591 static HRESULT WINAPI
ImageListImpl_GetOverlayImage(IImageList2
*iface
, int iOverlay
,
3594 HIMAGELIST This
= impl_from_IImageList2(iface
);
3597 if ((iOverlay
< 0) || (iOverlay
> This
->cCurImage
))
3600 for (i
= 0; i
< MAX_OVERLAYIMAGE
; i
++)
3602 if (This
->nOvlIdx
[i
] == iOverlay
)
3612 static HRESULT WINAPI
ImageListImpl_Resize(IImageList2
*iface
, INT cx
, INT cy
)
3614 FIXME("(%p)->(%d %d): stub\n", iface
, cx
, cy
);
3618 static HRESULT WINAPI
ImageListImpl_GetOriginalSize(IImageList2
*iface
, INT image
, DWORD flags
, INT
*cx
, INT
*cy
)
3620 FIXME("(%p)->(%d %x %p %p): stub\n", iface
, image
, flags
, cx
, cy
);
3624 static HRESULT WINAPI
ImageListImpl_SetOriginalSize(IImageList2
*iface
, INT image
, INT cx
, INT cy
)
3626 FIXME("(%p)->(%d %d %d): stub\n", iface
, image
, cx
, cy
);
3630 static HRESULT WINAPI
ImageListImpl_SetCallback(IImageList2
*iface
, IUnknown
*callback
)
3632 FIXME("(%p)->(%p): stub\n", iface
, callback
);
3636 static HRESULT WINAPI
ImageListImpl_GetCallback(IImageList2
*iface
, REFIID riid
, void **ppv
)
3638 FIXME("(%p)->(%s %p): stub\n", iface
, debugstr_guid(riid
), ppv
);
3642 static HRESULT WINAPI
ImageListImpl_ForceImagePresent(IImageList2
*iface
, INT image
, DWORD flags
)
3644 FIXME("(%p)->(%d %x): stub\n", iface
, image
, flags
);
3648 static HRESULT WINAPI
ImageListImpl_DiscardImages(IImageList2
*iface
, INT first_image
, INT last_image
, DWORD flags
)
3650 FIXME("(%p)->(%d %d %x): stub\n", iface
, first_image
, last_image
, flags
);
3654 static HRESULT WINAPI
ImageListImpl_PreloadImages(IImageList2
*iface
, IMAGELISTDRAWPARAMS
*params
)
3656 FIXME("(%p)->(%p): stub\n", iface
, params
);
3660 static HRESULT WINAPI
ImageListImpl_GetStatistics(IImageList2
*iface
, IMAGELISTSTATS
*stats
)
3662 FIXME("(%p)->(%p): stub\n", iface
, stats
);
3666 static HRESULT WINAPI
ImageListImpl_Initialize(IImageList2
*iface
, INT cx
, INT cy
, UINT flags
, INT initial
, INT grow
)
3668 FIXME("(%p)->(%d %d %d %d %d): stub\n", iface
, cx
, cy
, flags
, initial
, grow
);
3672 static HRESULT WINAPI
ImageListImpl_Replace2(IImageList2
*iface
, INT i
, HBITMAP image
, HBITMAP mask
, IUnknown
*unk
, DWORD flags
)
3674 FIXME("(%p)->(%d %p %p %p %x): stub\n", iface
, i
, image
, mask
, unk
, flags
);
3678 static HRESULT WINAPI
ImageListImpl_ReplaceFromImageList(IImageList2
*iface
, INT i
, IImageList
*imagelist
, INT src
,
3679 IUnknown
*unk
, DWORD flags
)
3681 FIXME("(%p)->(%d %p %d %p %x): stub\n", iface
, i
, imagelist
, src
, unk
, flags
);
3685 static const IImageList2Vtbl ImageListImpl_Vtbl
= {
3686 ImageListImpl_QueryInterface
,
3687 ImageListImpl_AddRef
,
3688 ImageListImpl_Release
,
3690 ImageListImpl_ReplaceIcon
,
3691 ImageListImpl_SetOverlayImage
,
3692 ImageListImpl_Replace
,
3693 ImageListImpl_AddMasked
,
3695 ImageListImpl_Remove
,
3696 ImageListImpl_GetIcon
,
3697 ImageListImpl_GetImageInfo
,
3699 ImageListImpl_Merge
,
3700 ImageListImpl_Clone
,
3701 ImageListImpl_GetImageRect
,
3702 ImageListImpl_GetIconSize
,
3703 ImageListImpl_SetIconSize
,
3704 ImageListImpl_GetImageCount
,
3705 ImageListImpl_SetImageCount
,
3706 ImageListImpl_SetBkColor
,
3707 ImageListImpl_GetBkColor
,
3708 ImageListImpl_BeginDrag
,
3709 ImageListImpl_EndDrag
,
3710 ImageListImpl_DragEnter
,
3711 ImageListImpl_DragLeave
,
3712 ImageListImpl_DragMove
,
3713 ImageListImpl_SetDragCursorImage
,
3714 ImageListImpl_DragShowNolock
,
3715 ImageListImpl_GetDragImage
,
3716 ImageListImpl_GetItemFlags
,
3717 ImageListImpl_GetOverlayImage
,
3718 ImageListImpl_Resize
,
3719 ImageListImpl_GetOriginalSize
,
3720 ImageListImpl_SetOriginalSize
,
3721 ImageListImpl_SetCallback
,
3722 ImageListImpl_GetCallback
,
3723 ImageListImpl_ForceImagePresent
,
3724 ImageListImpl_DiscardImages
,
3725 ImageListImpl_PreloadImages
,
3726 ImageListImpl_GetStatistics
,
3727 ImageListImpl_Initialize
,
3728 ImageListImpl_Replace2
,
3729 ImageListImpl_ReplaceFromImageList
3732 static BOOL
is_valid(HIMAGELIST himl
)
3737 valid
= himl
&& himl
->IImageList2_iface
.lpVtbl
== &ImageListImpl_Vtbl
;
3747 /*************************************************************************
3748 * HIMAGELIST_QueryInterface [COMCTL32.@]
3750 * Returns a pointer to an IImageList or IImageList2 object for the given
3754 * himl [I] Image list handle.
3755 * riid [I] Identifier of the requested interface.
3756 * ppv [O] Returns the address of the pointer requested, or NULL.
3760 * Failure: Error value.
3763 HIMAGELIST_QueryInterface (HIMAGELIST himl
, REFIID riid
, void **ppv
)
3765 TRACE("(%p,%s,%p)\n", himl
, debugstr_guid(riid
), ppv
);
3766 return IImageList2_QueryInterface((IImageList2
*) himl
, riid
, ppv
);
3769 static HRESULT
ImageListImpl_CreateInstance(const IUnknown
*pUnkOuter
, REFIID iid
, void** ppv
)
3774 TRACE("(%p,%s,%p)\n", pUnkOuter
, debugstr_guid(iid
), ppv
);
3778 if (pUnkOuter
) return CLASS_E_NOAGGREGATION
;
3780 This
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(struct _IMAGELIST
));
3781 if (!This
) return E_OUTOFMEMORY
;
3783 This
->IImageList2_iface
.lpVtbl
= &ImageListImpl_Vtbl
;
3786 ret
= IImageList2_QueryInterface(&This
->IImageList2_iface
, iid
, ppv
);
3787 IImageList2_Release(&This
->IImageList2_iface
);