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
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 */
77 LONG ref
; /* reference count */
80 #define IMAGELIST_MAGIC 0x53414D58
82 /* Header used by ImageList_Read() and ImageList_Write() */
84 typedef struct _ILHEAD
99 /* internal image list data used for Drag & Drop operations */
104 HIMAGELIST himlNoCursor
;
105 /* position of the drag image relative to the window */
108 /* offset of the hotspot relative to the origin of the image */
111 /* is the drag image visible */
113 /* saved background */
117 static INTERNALDRAG InternalDrag
= { 0, 0, 0, 0, 0, 0, 0, FALSE
, 0 };
119 static inline HIMAGELIST
impl_from_IImageList2(IImageList2
*iface
)
121 return CONTAINING_RECORD(iface
, struct _IMAGELIST
, IImageList2_iface
);
124 static HBITMAP
ImageList_CreateImage(HDC hdc
, HIMAGELIST himl
, UINT count
);
125 static HRESULT
ImageListImpl_CreateInstance(const IUnknown
*pUnkOuter
, REFIID iid
, void** ppv
);
126 static BOOL
is_valid(HIMAGELIST himl
);
129 * An imagelist with N images is tiled like this:
141 static inline UINT
imagelist_height( UINT count
)
143 return ((count
+ TILE_COUNT
- 1)/TILE_COUNT
);
146 static inline void imagelist_point_from_index( HIMAGELIST himl
, UINT index
, LPPOINT pt
)
148 pt
->x
= (index
%TILE_COUNT
) * himl
->cx
;
149 pt
->y
= (index
/TILE_COUNT
) * himl
->cy
;
152 static inline void imagelist_get_bitmap_size( HIMAGELIST himl
, UINT count
, SIZE
*sz
)
154 sz
->cx
= himl
->cx
* TILE_COUNT
;
155 sz
->cy
= imagelist_height( count
) * himl
->cy
;
158 static inline int get_dib_stride( int width
, int bpp
)
160 return ((width
* bpp
+ 31) >> 3) & ~3;
163 static inline int get_dib_image_size( const BITMAPINFO
*info
)
165 return get_dib_stride( info
->bmiHeader
.biWidth
, info
->bmiHeader
.biBitCount
)
166 * abs( info
->bmiHeader
.biHeight
);
170 * imagelist_copy_images()
172 * Copies a block of count images from offset src in the list to offset dest.
173 * Images are copied a row at at time. Assumes hdcSrc and hdcDest are different.
175 static inline void imagelist_copy_images( HIMAGELIST himl
, HDC hdcSrc
, HDC hdcDest
,
176 UINT src
, UINT count
, UINT dest
)
182 for ( i
=0; i
<TILE_COUNT
; i
++ )
184 imagelist_point_from_index( himl
, src
+i
, &ptSrc
);
185 imagelist_point_from_index( himl
, dest
+i
, &ptDest
);
187 sz
.cy
= himl
->cy
* imagelist_height( count
- i
);
189 BitBlt( hdcDest
, ptDest
.x
, ptDest
.y
, sz
.cx
, sz
.cy
,
190 hdcSrc
, ptSrc
.x
, ptSrc
.y
, SRCCOPY
);
194 static void add_dib_bits( HIMAGELIST himl
, int pos
, int count
, int width
, int height
,
195 BITMAPINFO
*info
, BITMAPINFO
*mask_info
, DWORD
*bits
, BYTE
*mask_bits
)
199 int stride
= info
->bmiHeader
.biWidth
;
200 int mask_stride
= (info
->bmiHeader
.biWidth
+ 31) / 32 * 4;
202 for (n
= 0; n
< count
; n
++)
204 BOOL has_alpha
= FALSE
;
206 imagelist_point_from_index( himl
, pos
+ n
, &pt
);
208 /* check if bitmap has an alpha channel */
209 for (i
= 0; i
< height
&& !has_alpha
; i
++)
210 for (j
= n
* width
; j
< (n
+ 1) * width
; j
++)
211 if ((has_alpha
= ((bits
[i
* stride
+ j
] & 0xff000000) != 0))) break;
213 if (!has_alpha
) /* generate alpha channel from the mask */
215 for (i
= 0; i
< height
; i
++)
216 for (j
= n
* width
; j
< (n
+ 1) * width
; j
++)
217 if (!mask_info
|| !((mask_bits
[i
* mask_stride
+ j
/ 8] << (j
% 8)) & 0x80))
218 bits
[i
* stride
+ j
] |= 0xff000000;
220 bits
[i
* stride
+ j
] = 0;
224 himl
->has_alpha
[pos
+ n
] = 1;
226 if (mask_info
&& himl
->hbmMask
) /* generate the mask from the alpha channel */
228 for (i
= 0; i
< height
; i
++)
229 for (j
= n
* width
; j
< (n
+ 1) * width
; j
++)
230 if ((bits
[i
* stride
+ j
] >> 24) > 25) /* more than 10% alpha */
231 mask_bits
[i
* mask_stride
+ j
/ 8] &= ~(0x80 >> (j
% 8));
233 mask_bits
[i
* mask_stride
+ j
/ 8] |= 0x80 >> (j
% 8);
236 StretchDIBits( himl
->hdcImage
, pt
.x
, pt
.y
, himl
->cx
, himl
->cy
,
237 n
* width
, 0, width
, height
, bits
, info
, DIB_RGB_COLORS
, SRCCOPY
);
239 StretchDIBits( himl
->hdcMask
, pt
.x
, pt
.y
, himl
->cx
, himl
->cy
,
240 n
* width
, 0, width
, height
, mask_bits
, mask_info
, DIB_RGB_COLORS
, SRCCOPY
);
244 /* add images with an alpha channel when the image list is 32 bpp */
245 static BOOL
add_with_alpha( HIMAGELIST himl
, HDC hdc
, int pos
, int count
,
246 int width
, int height
, HBITMAP hbmImage
, HBITMAP hbmMask
)
250 BITMAPINFO
*info
, *mask_info
= NULL
;
252 BYTE
*mask_bits
= NULL
;
255 if (!GetObjectW( hbmImage
, sizeof(bm
), &bm
)) return FALSE
;
257 /* if either the imagelist or the source bitmap don't have an alpha channel, bail out now */
258 if (!himl
->has_alpha
) return FALSE
;
259 if (bm
.bmBitsPixel
!= 32) return FALSE
;
261 SelectObject( hdc
, hbmImage
);
262 mask_width
= (bm
.bmWidth
+ 31) / 32 * 4;
264 if (!(info
= HeapAlloc( GetProcessHeap(), 0, FIELD_OFFSET( BITMAPINFO
, bmiColors
[256] )))) goto done
;
265 info
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
266 info
->bmiHeader
.biWidth
= bm
.bmWidth
;
267 info
->bmiHeader
.biHeight
= -height
;
268 info
->bmiHeader
.biPlanes
= 1;
269 info
->bmiHeader
.biBitCount
= 32;
270 info
->bmiHeader
.biCompression
= BI_RGB
;
271 info
->bmiHeader
.biSizeImage
= bm
.bmWidth
* height
* 4;
272 info
->bmiHeader
.biXPelsPerMeter
= 0;
273 info
->bmiHeader
.biYPelsPerMeter
= 0;
274 info
->bmiHeader
.biClrUsed
= 0;
275 info
->bmiHeader
.biClrImportant
= 0;
276 if (!(bits
= HeapAlloc( GetProcessHeap(), 0, info
->bmiHeader
.biSizeImage
))) goto done
;
277 if (!GetDIBits( hdc
, hbmImage
, 0, height
, bits
, info
, DIB_RGB_COLORS
)) goto done
;
281 if (!(mask_info
= HeapAlloc( GetProcessHeap(), 0, FIELD_OFFSET( BITMAPINFO
, bmiColors
[2] ))))
283 mask_info
->bmiHeader
= info
->bmiHeader
;
284 mask_info
->bmiHeader
.biBitCount
= 1;
285 mask_info
->bmiHeader
.biSizeImage
= mask_width
* height
;
286 if (!(mask_bits
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, info
->bmiHeader
.biSizeImage
)))
288 if (!GetDIBits( hdc
, hbmMask
, 0, height
, mask_bits
, mask_info
, DIB_RGB_COLORS
)) goto done
;
291 add_dib_bits( himl
, pos
, count
, width
, height
, info
, mask_info
, bits
, mask_bits
);
295 HeapFree( GetProcessHeap(), 0, info
);
296 HeapFree( GetProcessHeap(), 0, mask_info
);
297 HeapFree( GetProcessHeap(), 0, bits
);
298 HeapFree( GetProcessHeap(), 0, mask_bits
);
303 ImageList_SetColorTable(HIMAGELIST himl
, UINT uStartIndex
, UINT cEntries
, const RGBQUAD
*prgb
);
305 /*************************************************************************
306 * IMAGELIST_InternalExpandBitmaps [Internal]
308 * Expands the bitmaps of an image list by the given number of images.
311 * himl [I] handle to image list
312 * nImageCount [I] number of images to add
318 * This function CANNOT be used to reduce the number of images.
321 IMAGELIST_InternalExpandBitmaps(HIMAGELIST himl
, INT nImageCount
)
324 HBITMAP hbmNewBitmap
, hbmNull
;
328 TRACE("%p has allocated %d, max %d, grow %d images\n", himl
, himl
->cCurImage
, himl
->cMaxImage
, himl
->cGrow
);
330 if (himl
->cCurImage
+ nImageCount
< himl
->cMaxImage
)
333 nNewCount
= himl
->cMaxImage
+ max(nImageCount
, himl
->cGrow
) + 1;
335 imagelist_get_bitmap_size(himl
, nNewCount
, &sz
);
337 TRACE("Create expanded bitmaps : himl=%p x=%d y=%d count=%d\n", himl
, sz
.cx
, sz
.cy
, nNewCount
);
338 hdcBitmap
= CreateCompatibleDC (0);
340 hbmNewBitmap
= ImageList_CreateImage(hdcBitmap
, himl
, nNewCount
);
342 if (hbmNewBitmap
== 0)
343 ERR("creating new image bitmap (x=%d y=%d)!\n", sz
.cx
, sz
.cy
);
347 hbmNull
= SelectObject (hdcBitmap
, hbmNewBitmap
);
348 BitBlt (hdcBitmap
, 0, 0, sz
.cx
, sz
.cy
,
349 himl
->hdcImage
, 0, 0, SRCCOPY
);
350 SelectObject (hdcBitmap
, hbmNull
);
352 SelectObject (himl
->hdcImage
, hbmNewBitmap
);
353 DeleteObject (himl
->hbmImage
);
354 himl
->hbmImage
= hbmNewBitmap
;
356 if (himl
->flags
& ILC_MASK
)
358 hbmNewBitmap
= CreateBitmap (sz
.cx
, sz
.cy
, 1, 1, NULL
);
360 if (hbmNewBitmap
== 0)
361 ERR("creating new mask bitmap!\n");
365 hbmNull
= SelectObject (hdcBitmap
, hbmNewBitmap
);
366 BitBlt (hdcBitmap
, 0, 0, sz
.cx
, sz
.cy
,
367 himl
->hdcMask
, 0, 0, SRCCOPY
);
368 SelectObject (hdcBitmap
, hbmNull
);
370 SelectObject (himl
->hdcMask
, hbmNewBitmap
);
371 DeleteObject (himl
->hbmMask
);
372 himl
->hbmMask
= hbmNewBitmap
;
377 char *new_alpha
= HeapReAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, himl
->has_alpha
, nNewCount
);
378 if (new_alpha
) himl
->has_alpha
= new_alpha
;
381 HeapFree( GetProcessHeap(), 0, himl
->has_alpha
);
382 himl
->has_alpha
= NULL
;
386 himl
->cMaxImage
= nNewCount
;
388 DeleteDC (hdcBitmap
);
392 /*************************************************************************
393 * ImageList_Add [COMCTL32.@]
395 * Add an image or images to an image list.
398 * himl [I] handle to image list
399 * hbmImage [I] handle to image bitmap
400 * hbmMask [I] handle to mask bitmap
403 * Success: Index of the first new image.
408 ImageList_Add (HIMAGELIST himl
, HBITMAP hbmImage
, HBITMAP hbmMask
)
410 HDC hdcBitmap
, hdcTemp
= 0;
411 INT nFirstIndex
, nImageCount
, i
;
415 TRACE("himl=%p hbmimage=%p hbmmask=%p\n", himl
, hbmImage
, hbmMask
);
419 if (!GetObjectW(hbmImage
, sizeof(BITMAP
), &bmp
))
422 TRACE("himl %p, cCurImage %d, cMaxImage %d, cGrow %d, cx %d, cy %d\n",
423 himl
, himl
->cCurImage
, himl
->cMaxImage
, himl
->cGrow
, himl
->cx
, himl
->cy
);
425 nImageCount
= bmp
.bmWidth
/ himl
->cx
;
427 TRACE("%p has %d images (%d x %d) bpp %d\n", hbmImage
, nImageCount
, bmp
.bmWidth
, bmp
.bmHeight
,
430 IMAGELIST_InternalExpandBitmaps(himl
, nImageCount
);
432 hdcBitmap
= CreateCompatibleDC(0);
434 SelectObject(hdcBitmap
, hbmImage
);
436 if (add_with_alpha( himl
, hdcBitmap
, himl
->cCurImage
, nImageCount
,
437 himl
->cx
, min( himl
->cy
, bmp
.bmHeight
), hbmImage
, hbmMask
))
442 hdcTemp
= CreateCompatibleDC(0);
443 SelectObject(hdcTemp
, hbmMask
);
446 if (himl
->uBitsPixel
<= 8 && bmp
.bmBitsPixel
<= 8 &&
447 !himl
->color_table_set
&& himl
->cCurImage
== 0)
450 UINT num
= GetDIBColorTable( hdcBitmap
, 0, 1 << bmp
.bmBitsPixel
, colors
);
451 if (num
) ImageList_SetColorTable( himl
, 0, num
, colors
);
454 for (i
=0; i
<nImageCount
; i
++)
456 imagelist_point_from_index( himl
, himl
->cCurImage
+ i
, &pt
);
458 /* Copy result to the imagelist
460 BitBlt( himl
->hdcImage
, pt
.x
, pt
.y
, himl
->cx
, bmp
.bmHeight
,
461 hdcBitmap
, i
*himl
->cx
, 0, SRCCOPY
);
466 BitBlt( himl
->hdcMask
, pt
.x
, pt
.y
, himl
->cx
, bmp
.bmHeight
,
467 hdcTemp
, i
*himl
->cx
, 0, SRCCOPY
);
469 /* Remove the background from the image
471 BitBlt( himl
->hdcImage
, pt
.x
, pt
.y
, himl
->cx
, bmp
.bmHeight
,
472 himl
->hdcMask
, pt
.x
, pt
.y
, 0x220326 ); /* NOTSRCAND */
474 if (hdcTemp
) DeleteDC(hdcTemp
);
479 nFirstIndex
= himl
->cCurImage
;
480 himl
->cCurImage
+= nImageCount
;
486 /*************************************************************************
487 * ImageList_AddIcon [COMCTL32.@]
489 * Adds an icon to an image list.
492 * himl [I] handle to image list
493 * hIcon [I] handle to icon
496 * Success: index of the new image
499 #undef ImageList_AddIcon
500 INT WINAPI
ImageList_AddIcon (HIMAGELIST himl
, HICON hIcon
)
502 return ImageList_ReplaceIcon (himl
, -1, hIcon
);
506 /*************************************************************************
507 * ImageList_AddMasked [COMCTL32.@]
509 * Adds an image or images to an image list and creates a mask from the
510 * specified bitmap using the mask color.
513 * himl [I] handle to image list.
514 * hBitmap [I] handle to bitmap
515 * clrMask [I] mask color.
518 * Success: Index of the first new image.
523 ImageList_AddMasked (HIMAGELIST himl
, HBITMAP hBitmap
, COLORREF clrMask
)
525 HDC hdcMask
, hdcBitmap
;
531 TRACE("himl=%p hbitmap=%p clrmask=%x\n", himl
, hBitmap
, clrMask
);
535 if (!GetObjectW(hBitmap
, sizeof(BITMAP
), &bmp
))
538 hdcBitmap
= CreateCompatibleDC(0);
539 SelectObject(hdcBitmap
, hBitmap
);
541 /* Create a temp Mask so we can remove the background of the Image */
542 hdcMask
= CreateCompatibleDC(0);
543 hMaskBitmap
= CreateBitmap(bmp
.bmWidth
, bmp
.bmHeight
, 1, 1, NULL
);
544 SelectObject(hdcMask
, hMaskBitmap
);
546 /* create monochrome image to the mask bitmap */
547 bkColor
= (clrMask
!= CLR_DEFAULT
) ? clrMask
: GetPixel (hdcBitmap
, 0, 0);
548 SetBkColor (hdcBitmap
, bkColor
);
549 BitBlt (hdcMask
, 0, 0, bmp
.bmWidth
, bmp
.bmHeight
, hdcBitmap
, 0, 0, SRCCOPY
);
552 * Remove the background from the image
554 * WINDOWS BUG ALERT!!!!!!
555 * The statement below should not be done in common practice
556 * but this is how ImageList_AddMasked works in Windows.
557 * It overwrites the original bitmap passed, this was discovered
558 * by using the same bitmap to iterate the different styles
559 * on windows where it failed (BUT ImageList_Add is OK)
560 * This is here in case some apps rely on this bug
562 * Blt mode 0x220326 is NOTSRCAND
564 if (bmp
.bmBitsPixel
> 8) /* NOTSRCAND can't work with palettes */
566 SetBkColor(hdcBitmap
, RGB(255,255,255));
567 BitBlt(hdcBitmap
, 0, 0, bmp
.bmWidth
, bmp
.bmHeight
, hdcMask
, 0, 0, 0x220326);
573 ret
= ImageList_Add( himl
, hBitmap
, hMaskBitmap
);
575 DeleteObject(hMaskBitmap
);
580 /*************************************************************************
581 * ImageList_BeginDrag [COMCTL32.@]
583 * Creates a temporary image list that contains one image. It will be used
587 * himlTrack [I] handle to the source image list
588 * iTrack [I] index of the drag image in the source image list
589 * dxHotspot [I] X position of the hot spot of the drag image
590 * dyHotspot [I] Y position of the hot spot of the drag image
598 ImageList_BeginDrag (HIMAGELIST himlTrack
, INT iTrack
,
599 INT dxHotspot
, INT dyHotspot
)
604 TRACE("(himlTrack=%p iTrack=%d dx=%d dy=%d)\n", himlTrack
, iTrack
,
605 dxHotspot
, dyHotspot
);
607 if (!is_valid(himlTrack
))
610 if (iTrack
>= himlTrack
->cCurImage
)
613 if (InternalDrag
.himl
)
619 InternalDrag
.himlNoCursor
= InternalDrag
.himl
= ImageList_Create (cx
, cy
, himlTrack
->flags
, 1, 1);
620 if (InternalDrag
.himl
== NULL
) {
621 WARN("Error creating drag image list!\n");
625 InternalDrag
.dxHotspot
= dxHotspot
;
626 InternalDrag
.dyHotspot
= dyHotspot
;
629 imagelist_point_from_index(InternalDrag
.himl
, 0, &dst
);
630 imagelist_point_from_index(himlTrack
, iTrack
, &src
);
631 BitBlt(InternalDrag
.himl
->hdcImage
, dst
.x
, dst
.y
, cx
, cy
, himlTrack
->hdcImage
, src
.x
, src
.y
,
633 BitBlt(InternalDrag
.himl
->hdcMask
, dst
.x
, dst
.y
, cx
, cy
, himlTrack
->hdcMask
, src
.x
, src
.y
,
636 InternalDrag
.himl
->cCurImage
= 1;
642 /*************************************************************************
643 * ImageList_Copy [COMCTL32.@]
645 * Copies an image of the source image list to an image of the
646 * destination image list. Images can be copied or swapped.
649 * himlDst [I] handle to the destination image list
650 * iDst [I] destination image index.
651 * himlSrc [I] handle to the source image list
652 * iSrc [I] source image index
653 * uFlags [I] flags for the copy operation
660 * Copying from one image list to another is possible. The original
661 * implementation just copies or swaps within one image list.
662 * Could this feature become a bug??? ;-)
666 ImageList_Copy (HIMAGELIST himlDst
, INT iDst
, HIMAGELIST himlSrc
,
667 INT iSrc
, UINT uFlags
)
671 TRACE("himlDst=%p iDst=%d himlSrc=%p iSrc=%d\n", himlDst
, iDst
, himlSrc
, iSrc
);
673 if (!is_valid(himlSrc
) || !is_valid(himlDst
))
675 if ((iDst
< 0) || (iDst
>= himlDst
->cCurImage
))
677 if ((iSrc
< 0) || (iSrc
>= himlSrc
->cCurImage
))
680 imagelist_point_from_index( himlDst
, iDst
, &ptDst
);
681 imagelist_point_from_index( himlSrc
, iSrc
, &ptSrc
);
683 if (uFlags
& ILCF_SWAP
) {
686 HBITMAP hbmTempImage
, hbmTempMask
;
688 hdcBmp
= CreateCompatibleDC (0);
690 /* create temporary bitmaps */
691 hbmTempImage
= CreateBitmap (himlSrc
->cx
, himlSrc
->cy
, 1,
692 himlSrc
->uBitsPixel
, NULL
);
693 hbmTempMask
= CreateBitmap (himlSrc
->cx
, himlSrc
->cy
, 1,
696 /* copy (and stretch) destination to temporary bitmaps.(save) */
698 SelectObject (hdcBmp
, hbmTempImage
);
699 StretchBlt (hdcBmp
, 0, 0, himlSrc
->cx
, himlSrc
->cy
,
700 himlDst
->hdcImage
, ptDst
.x
, ptDst
.y
, himlDst
->cx
, himlDst
->cy
,
703 SelectObject (hdcBmp
, hbmTempMask
);
704 StretchBlt (hdcBmp
, 0, 0, himlSrc
->cx
, himlSrc
->cy
,
705 himlDst
->hdcMask
, ptDst
.x
, ptDst
.y
, himlDst
->cx
, himlDst
->cy
,
708 /* copy (and stretch) source to destination */
710 StretchBlt (himlDst
->hdcImage
, ptDst
.x
, ptDst
.y
, himlDst
->cx
, himlDst
->cy
,
711 himlSrc
->hdcImage
, ptSrc
.x
, ptSrc
.y
, himlSrc
->cx
, himlSrc
->cy
,
714 StretchBlt (himlDst
->hdcMask
, ptDst
.x
, ptDst
.y
, himlDst
->cx
, himlDst
->cy
,
715 himlSrc
->hdcMask
, ptSrc
.x
, ptSrc
.y
, himlSrc
->cx
, himlSrc
->cy
,
718 /* copy (without stretching) temporary bitmaps to source (restore) */
720 BitBlt (himlSrc
->hdcMask
, ptSrc
.x
, ptSrc
.y
, himlSrc
->cx
, himlSrc
->cy
,
721 hdcBmp
, 0, 0, SRCCOPY
);
724 BitBlt (himlSrc
->hdcImage
, ptSrc
.x
, ptSrc
.y
, himlSrc
->cx
, himlSrc
->cy
,
725 hdcBmp
, 0, 0, SRCCOPY
);
726 /* delete temporary bitmaps */
727 DeleteObject (hbmTempMask
);
728 DeleteObject (hbmTempImage
);
733 StretchBlt (himlDst
->hdcImage
, ptDst
.x
, ptDst
.y
, himlDst
->cx
, himlDst
->cy
,
734 himlSrc
->hdcImage
, ptSrc
.x
, ptSrc
.y
, himlSrc
->cx
, himlSrc
->cy
,
738 StretchBlt (himlDst
->hdcMask
, ptDst
.x
, ptDst
.y
, himlDst
->cx
, himlDst
->cy
,
739 himlSrc
->hdcMask
, ptSrc
.x
, ptSrc
.y
, himlSrc
->cx
, himlSrc
->cy
,
747 /*************************************************************************
748 * ImageList_Create [COMCTL32.@]
750 * Creates a new image list.
753 * cx [I] image height
755 * flags [I] creation flags
756 * cInitial [I] initial number of images in the image list
757 * cGrow [I] number of images by which image list grows
760 * Success: Handle to the created image list
764 ImageList_Create (INT cx
, INT cy
, UINT flags
,
765 INT cInitial
, INT cGrow
)
770 UINT ilc
= (flags
& 0xFE);
771 static const WORD aBitBlend25
[] =
772 {0xAA, 0x00, 0x55, 0x00, 0xAA, 0x00, 0x55, 0x00};
774 static const WORD aBitBlend50
[] =
775 {0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA};
777 TRACE("(%d %d 0x%x %d %d)\n", cx
, cy
, flags
, cInitial
, cGrow
);
779 if (cx
< 0 || cy
< 0) return NULL
;
780 if (!((flags
&ILC_COLORDDB
) == ILC_COLORDDB
) && (cx
== 0 || cy
== 0)) return NULL
;
782 /* Create the IImageList interface for the image list */
783 if (FAILED(ImageListImpl_CreateInstance(NULL
, &IID_IImageList
, (void **)&himl
)))
786 cGrow
= (WORD
)((max( cGrow
, 1 ) + 3) & ~3);
790 /* Windows doesn't limit the size here, but X11 doesn't let us allocate such huge bitmaps */
791 WARN( "grow %d too large, limiting to 256\n", cGrow
);
798 himl
->cMaxImage
= cInitial
+ 1;
799 himl
->cInitial
= cInitial
;
801 himl
->clrFg
= CLR_DEFAULT
;
802 himl
->clrBk
= CLR_NONE
;
803 himl
->color_table_set
= FALSE
;
805 /* initialize overlay mask indices */
806 for (nCount
= 0; nCount
< MAX_OVERLAYIMAGE
; nCount
++)
807 himl
->nOvlIdx
[nCount
] = -1;
809 /* Create Image & Mask DCs */
810 himl
->hdcImage
= CreateCompatibleDC (0);
813 if (himl
->flags
& ILC_MASK
){
814 himl
->hdcMask
= CreateCompatibleDC(0);
819 /* Default to ILC_COLOR4 if none of the ILC_COLOR* flags are specified */
820 if (ilc
== ILC_COLOR
)
823 himl
->flags
|= ILC_COLOR4
;
826 if (ilc
>= ILC_COLOR4
&& ilc
<= ILC_COLOR32
)
827 himl
->uBitsPixel
= ilc
;
829 himl
->uBitsPixel
= (UINT
)GetDeviceCaps (himl
->hdcImage
, BITSPIXEL
);
831 if (himl
->cMaxImage
> 0) {
832 himl
->hbmImage
= ImageList_CreateImage(himl
->hdcImage
, himl
, himl
->cMaxImage
);
833 SelectObject(himl
->hdcImage
, himl
->hbmImage
);
837 if ((himl
->cMaxImage
> 0) && (himl
->flags
& ILC_MASK
)) {
840 imagelist_get_bitmap_size(himl
, himl
->cMaxImage
, &sz
);
841 himl
->hbmMask
= CreateBitmap (sz
.cx
, sz
.cy
, 1, 1, NULL
);
842 if (himl
->hbmMask
== 0) {
843 ERR("Error creating mask bitmap!\n");
846 SelectObject(himl
->hdcMask
, himl
->hbmMask
);
851 if (ilc
== ILC_COLOR32
)
852 himl
->has_alpha
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, himl
->cMaxImage
);
854 himl
->has_alpha
= NULL
;
856 /* create blending brushes */
857 hbmTemp
= CreateBitmap (8, 8, 1, 1, aBitBlend25
);
858 himl
->hbrBlend25
= CreatePatternBrush (hbmTemp
);
859 DeleteObject (hbmTemp
);
861 hbmTemp
= CreateBitmap (8, 8, 1, 1, aBitBlend50
);
862 himl
->hbrBlend50
= CreatePatternBrush (hbmTemp
);
863 DeleteObject (hbmTemp
);
865 TRACE("created imagelist %p\n", himl
);
869 ImageList_Destroy(himl
);
874 /*************************************************************************
875 * ImageList_Destroy [COMCTL32.@]
877 * Destroys an image list.
880 * himl [I] handle to image list
888 ImageList_Destroy (HIMAGELIST himl
)
893 IImageList_Release((IImageList
*) himl
);
898 /*************************************************************************
899 * ImageList_DragEnter [COMCTL32.@]
901 * Locks window update and displays the drag image at the given position.
904 * hwndLock [I] handle of the window that owns the drag image.
905 * x [I] X position of the drag image.
906 * y [I] Y position of the drag image.
913 * The position of the drag image is relative to the window, not
918 ImageList_DragEnter (HWND hwndLock
, INT x
, INT y
)
920 TRACE("(hwnd=%p x=%d y=%d)\n", hwndLock
, x
, y
);
922 if (!is_valid(InternalDrag
.himl
))
926 InternalDrag
.hwnd
= hwndLock
;
928 InternalDrag
.hwnd
= GetDesktopWindow ();
933 /* draw the drag image and save the background */
934 return ImageList_DragShowNolock(TRUE
);
938 /*************************************************************************
939 * ImageList_DragLeave [COMCTL32.@]
941 * Unlocks window update and hides the drag image.
944 * hwndLock [I] handle of the window that owns the drag image.
952 ImageList_DragLeave (HWND hwndLock
)
954 /* As we don't save drag info in the window this can lead to problems if
955 an app does not supply the same window as DragEnter */
957 InternalDrag.hwnd = hwndLock;
959 InternalDrag.hwnd = GetDesktopWindow (); */
961 hwndLock
= GetDesktopWindow();
962 if(InternalDrag
.hwnd
!= hwndLock
)
963 FIXME("DragLeave hWnd != DragEnter hWnd\n");
965 ImageList_DragShowNolock (FALSE
);
971 /*************************************************************************
972 * ImageList_InternalDragDraw [Internal]
974 * Draws the drag image.
977 * hdc [I] device context to draw into.
978 * x [I] X position of the drag image.
979 * y [I] Y position of the drag image.
986 * The position of the drag image is relative to the window, not
992 ImageList_InternalDragDraw (HDC hdc
, INT x
, INT y
)
994 IMAGELISTDRAWPARAMS imldp
;
996 ZeroMemory (&imldp
, sizeof(imldp
));
997 imldp
.cbSize
= sizeof(imldp
);
998 imldp
.himl
= InternalDrag
.himl
;
1003 imldp
.rgbBk
= CLR_DEFAULT
;
1004 imldp
.rgbFg
= CLR_DEFAULT
;
1005 imldp
.fStyle
= ILD_NORMAL
;
1006 imldp
.fState
= ILS_ALPHA
;
1008 ImageList_DrawIndirect (&imldp
);
1011 /*************************************************************************
1012 * ImageList_DragMove [COMCTL32.@]
1014 * Moves the drag image.
1017 * x [I] X position of the drag image.
1018 * y [I] Y position of the drag image.
1025 * The position of the drag image is relative to the window, not
1030 ImageList_DragMove (INT x
, INT y
)
1032 TRACE("(x=%d y=%d)\n", x
, y
);
1034 if (!is_valid(InternalDrag
.himl
))
1037 /* draw/update the drag image */
1038 if (InternalDrag
.bShow
) {
1042 HBITMAP hbmOffScreen
;
1043 INT origNewX
, origNewY
;
1044 INT origOldX
, origOldY
;
1045 INT origRegX
, origRegY
;
1046 INT sizeRegX
, sizeRegY
;
1049 /* calculate the update region */
1050 origNewX
= x
- InternalDrag
.dxHotspot
;
1051 origNewY
= y
- InternalDrag
.dyHotspot
;
1052 origOldX
= InternalDrag
.x
- InternalDrag
.dxHotspot
;
1053 origOldY
= InternalDrag
.y
- InternalDrag
.dyHotspot
;
1054 origRegX
= min(origNewX
, origOldX
);
1055 origRegY
= min(origNewY
, origOldY
);
1056 sizeRegX
= InternalDrag
.himl
->cx
+ abs(x
- InternalDrag
.x
);
1057 sizeRegY
= InternalDrag
.himl
->cy
+ abs(y
- InternalDrag
.y
);
1059 hdcDrag
= GetDCEx(InternalDrag
.hwnd
, 0,
1060 DCX_WINDOW
| DCX_CACHE
| DCX_LOCKWINDOWUPDATE
);
1061 hdcOffScreen
= CreateCompatibleDC(hdcDrag
);
1062 hdcBg
= CreateCompatibleDC(hdcDrag
);
1064 hbmOffScreen
= CreateCompatibleBitmap(hdcDrag
, sizeRegX
, sizeRegY
);
1065 SelectObject(hdcOffScreen
, hbmOffScreen
);
1066 SelectObject(hdcBg
, InternalDrag
.hbmBg
);
1068 /* get the actual background of the update region */
1069 BitBlt(hdcOffScreen
, 0, 0, sizeRegX
, sizeRegY
, hdcDrag
,
1070 origRegX
, origRegY
, SRCCOPY
);
1071 /* erase the old image */
1072 BitBlt(hdcOffScreen
, origOldX
- origRegX
, origOldY
- origRegY
,
1073 InternalDrag
.himl
->cx
, InternalDrag
.himl
->cy
, hdcBg
, 0, 0,
1075 /* save the background */
1076 BitBlt(hdcBg
, 0, 0, InternalDrag
.himl
->cx
, InternalDrag
.himl
->cy
,
1077 hdcOffScreen
, origNewX
- origRegX
, origNewY
- origRegY
, SRCCOPY
);
1078 /* draw the image */
1079 ImageList_InternalDragDraw(hdcOffScreen
, origNewX
- origRegX
,
1080 origNewY
- origRegY
);
1081 /* draw the update region to the screen */
1082 BitBlt(hdcDrag
, origRegX
, origRegY
, sizeRegX
, sizeRegY
,
1083 hdcOffScreen
, 0, 0, SRCCOPY
);
1086 DeleteDC(hdcOffScreen
);
1087 DeleteObject(hbmOffScreen
);
1088 ReleaseDC(InternalDrag
.hwnd
, hdcDrag
);
1091 /* update the image position */
1099 /*************************************************************************
1100 * ImageList_DragShowNolock [COMCTL32.@]
1102 * Shows or hides the drag image.
1105 * bShow [I] TRUE shows the drag image, FALSE hides it.
1113 ImageList_DragShowNolock (BOOL bShow
)
1119 if (!is_valid(InternalDrag
.himl
))
1122 TRACE("bShow=0x%X!\n", bShow
);
1124 /* DragImage is already visible/hidden */
1125 if ((InternalDrag
.bShow
&& bShow
) || (!InternalDrag
.bShow
&& !bShow
)) {
1129 /* position of the origin of the DragImage */
1130 x
= InternalDrag
.x
- InternalDrag
.dxHotspot
;
1131 y
= InternalDrag
.y
- InternalDrag
.dyHotspot
;
1133 hdcDrag
= GetDCEx (InternalDrag
.hwnd
, 0,
1134 DCX_WINDOW
| DCX_CACHE
| DCX_LOCKWINDOWUPDATE
);
1139 hdcBg
= CreateCompatibleDC(hdcDrag
);
1140 if (!InternalDrag
.hbmBg
) {
1141 InternalDrag
.hbmBg
= CreateCompatibleBitmap(hdcDrag
,
1142 InternalDrag
.himl
->cx
, InternalDrag
.himl
->cy
);
1144 SelectObject(hdcBg
, InternalDrag
.hbmBg
);
1147 /* save the background */
1148 BitBlt(hdcBg
, 0, 0, InternalDrag
.himl
->cx
, InternalDrag
.himl
->cy
,
1149 hdcDrag
, x
, y
, SRCCOPY
);
1150 /* show the image */
1151 ImageList_InternalDragDraw(hdcDrag
, x
, y
);
1153 /* hide the image */
1154 BitBlt(hdcDrag
, x
, y
, InternalDrag
.himl
->cx
, InternalDrag
.himl
->cy
,
1155 hdcBg
, 0, 0, SRCCOPY
);
1158 InternalDrag
.bShow
= !InternalDrag
.bShow
;
1161 ReleaseDC (InternalDrag
.hwnd
, hdcDrag
);
1166 /*************************************************************************
1167 * ImageList_Draw [COMCTL32.@]
1172 * himl [I] handle to image list
1174 * hdc [I] handle to device context
1177 * fStyle [I] drawing flags
1188 ImageList_Draw (HIMAGELIST himl
, INT i
, HDC hdc
, INT x
, INT y
, UINT fStyle
)
1190 return ImageList_DrawEx (himl
, i
, hdc
, x
, y
, 0, 0,
1191 CLR_DEFAULT
, CLR_DEFAULT
, fStyle
);
1195 /*************************************************************************
1196 * ImageList_DrawEx [COMCTL32.@]
1198 * Draws an image and allows using extended drawing features.
1201 * himl [I] handle to image list
1203 * hdc [I] handle to device context
1208 * rgbBk [I] background color
1209 * rgbFg [I] foreground color
1210 * fStyle [I] drawing flags
1217 * Calls ImageList_DrawIndirect.
1220 * ImageList_DrawIndirect.
1224 ImageList_DrawEx (HIMAGELIST himl
, INT i
, HDC hdc
, INT x
, INT y
,
1225 INT dx
, INT dy
, COLORREF rgbBk
, COLORREF rgbFg
,
1228 IMAGELISTDRAWPARAMS imldp
;
1230 ZeroMemory (&imldp
, sizeof(imldp
));
1231 imldp
.cbSize
= sizeof(imldp
);
1239 imldp
.rgbBk
= rgbBk
;
1240 imldp
.rgbFg
= rgbFg
;
1241 imldp
.fStyle
= fStyle
;
1243 return ImageList_DrawIndirect (&imldp
);
1247 static BOOL
alpha_blend_image( HIMAGELIST himl
, HDC srce_dc
, HDC dest_dc
, int dest_x
, int dest_y
,
1249 static BOOL
alpha_blend_image( HIMAGELIST himl
, HDC dest_dc
, int dest_x
, int dest_y
,
1251 int src_x
, int src_y
, int cx
, int cy
, BLENDFUNCTION func
,
1252 UINT style
, COLORREF blend_col
)
1256 HBITMAP bmp
= 0, mask
= 0;
1258 void *bits
, *mask_bits
;
1262 if (!(hdc
= CreateCompatibleDC( 0 ))) return FALSE
;
1263 if (!(info
= HeapAlloc( GetProcessHeap(), 0, FIELD_OFFSET( BITMAPINFO
, bmiColors
[256] )))) goto done
;
1264 info
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
1265 info
->bmiHeader
.biWidth
= cx
;
1266 info
->bmiHeader
.biHeight
= cy
;
1267 info
->bmiHeader
.biPlanes
= 1;
1268 info
->bmiHeader
.biBitCount
= 32;
1269 info
->bmiHeader
.biCompression
= BI_RGB
;
1270 info
->bmiHeader
.biSizeImage
= cx
* cy
* 4;
1271 info
->bmiHeader
.biXPelsPerMeter
= 0;
1272 info
->bmiHeader
.biYPelsPerMeter
= 0;
1273 info
->bmiHeader
.biClrUsed
= 0;
1274 info
->bmiHeader
.biClrImportant
= 0;
1276 if (!(bmp
= CreateDIBSection( srce_dc
, info
, DIB_RGB_COLORS
, &bits
, 0, 0 ))) goto done
;
1278 if (!(bmp
= CreateDIBSection( himl
->hdcImage
, info
, DIB_RGB_COLORS
, &bits
, 0, 0 ))) goto done
;
1280 SelectObject( hdc
, bmp
);
1282 BitBlt( hdc
, 0, 0, cx
, cy
, srce_dc
, src_x
, src_y
, SRCCOPY
);
1284 BitBlt( hdc
, 0, 0, cx
, cy
, himl
->hdcImage
, src_x
, src_y
, SRCCOPY
);
1287 if (blend_col
!= CLR_NONE
)
1289 BYTE r
= GetRValue( blend_col
);
1290 BYTE g
= GetGValue( blend_col
);
1291 BYTE b
= GetBValue( blend_col
);
1293 if (style
& ILD_BLEND25
)
1295 for (i
= 0, ptr
= bits
; i
< cx
* cy
; i
++, ptr
++)
1296 *ptr
= ((*ptr
& 0xff000000) |
1297 ((((*ptr
& 0x00ff0000) * 3 + (r
<< 16)) / 4) & 0x00ff0000) |
1298 ((((*ptr
& 0x0000ff00) * 3 + (g
<< 8)) / 4) & 0x0000ff00) |
1299 ((((*ptr
& 0x000000ff) * 3 + (b
<< 0)) / 4) & 0x000000ff));
1301 else if (style
& ILD_BLEND50
)
1303 for (i
= 0, ptr
= bits
; i
< cx
* cy
; i
++, ptr
++)
1304 *ptr
= ((*ptr
& 0xff000000) |
1305 ((((*ptr
& 0x00ff0000) + (r
<< 16)) / 2) & 0x00ff0000) |
1306 ((((*ptr
& 0x0000ff00) + (g
<< 8)) / 2) & 0x0000ff00) |
1307 ((((*ptr
& 0x000000ff) + (b
<< 0)) / 2) & 0x000000ff));
1311 if (himl
->has_alpha
) /* we already have an alpha channel in this case */
1313 /* pre-multiply by the alpha channel */
1314 for (i
= 0, ptr
= bits
; i
< cx
* cy
; i
++, ptr
++)
1316 DWORD alpha
= *ptr
>> 24;
1317 *ptr
= ((*ptr
& 0xff000000) |
1318 (((*ptr
& 0x00ff0000) * alpha
/ 255) & 0x00ff0000) |
1319 (((*ptr
& 0x0000ff00) * alpha
/ 255) & 0x0000ff00) |
1320 (((*ptr
& 0x000000ff) * alpha
/ 255)));
1323 else if (himl
->hbmMask
)
1325 unsigned int width_bytes
= (cx
+ 31) / 32 * 4;
1326 /* generate alpha channel from the mask */
1327 info
->bmiHeader
.biBitCount
= 1;
1328 info
->bmiHeader
.biSizeImage
= width_bytes
* cy
;
1329 info
->bmiColors
[0].rgbRed
= 0;
1330 info
->bmiColors
[0].rgbGreen
= 0;
1331 info
->bmiColors
[0].rgbBlue
= 0;
1332 info
->bmiColors
[0].rgbReserved
= 0;
1333 info
->bmiColors
[1].rgbRed
= 0xff;
1334 info
->bmiColors
[1].rgbGreen
= 0xff;
1335 info
->bmiColors
[1].rgbBlue
= 0xff;
1336 info
->bmiColors
[1].rgbReserved
= 0;
1337 if (!(mask
= CreateDIBSection( himl
->hdcMask
, info
, DIB_RGB_COLORS
, &mask_bits
, 0, 0 )))
1339 SelectObject( hdc
, mask
);
1340 BitBlt( hdc
, 0, 0, cx
, cy
, himl
->hdcMask
, src_x
, src_y
, SRCCOPY
);
1341 SelectObject( hdc
, bmp
);
1342 for (i
= 0, ptr
= bits
; i
< cy
; i
++)
1343 for (j
= 0; j
< cx
; j
++, ptr
++)
1344 if ((((BYTE
*)mask_bits
)[i
* width_bytes
+ j
/ 8] << (j
% 8)) & 0x80) *ptr
= 0;
1345 else *ptr
|= 0xff000000;
1348 ret
= GdiAlphaBlend( dest_dc
, dest_x
, dest_y
, cx
, cy
, hdc
, 0, 0, cx
, cy
, func
);
1352 if (bmp
) DeleteObject( bmp
);
1353 if (mask
) DeleteObject( mask
);
1354 HeapFree( GetProcessHeap(), 0, info
);
1359 HDC
saturate_image( HIMAGELIST himl
, HDC dest_dc
, int dest_x
, int dest_y
,
1360 int src_x
, int src_y
, int cx
, int cy
, COLORREF rgbFg
)
1370 /* create a dc and its device independent bitmap for doing the work,
1371 shamelessly copied from the alpha-blending function above */
1372 if (!(hdc
= CreateCompatibleDC( 0 ))) return FALSE
;
1373 if (!(info
= HeapAlloc( GetProcessHeap(), 0, FIELD_OFFSET( BITMAPINFO
, bmiColors
[256] )))) goto done
;
1374 info
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
1375 info
->bmiHeader
.biWidth
= cx
;
1376 info
->bmiHeader
.biHeight
= cy
;
1377 info
->bmiHeader
.biPlanes
= 1;
1378 info
->bmiHeader
.biBitCount
= 32;
1379 info
->bmiHeader
.biCompression
= BI_RGB
;
1380 info
->bmiHeader
.biSizeImage
= cx
* cy
* 4;
1381 info
->bmiHeader
.biXPelsPerMeter
= 0;
1382 info
->bmiHeader
.biYPelsPerMeter
= 0;
1383 info
->bmiHeader
.biClrUsed
= 0;
1384 info
->bmiHeader
.biClrImportant
= 0;
1385 if (!(bmp
= CreateDIBSection(himl
->hdcImage
, info
, DIB_RGB_COLORS
, &bits
, 0, 0 ))) goto done
;
1387 /* bind both surfaces */
1388 SelectObject(hdc
, bmp
);
1390 /* copy into our dc the section that covers just the icon we we're asked for */
1391 BitBlt(hdc
, 0, 0, cx
, cy
, himl
->hdcImage
, src_x
, src_y
, SRCCOPY
);
1393 /* loop every pixel of the bitmap */
1394 for (i
= 0, ptr
= bits
; i
< cx
* cy
; i
++, ptr
++)
1396 COLORREF orig_color
= *ptr
;
1398 /* calculate the effective luminance using the constants from here, adapted to the human eye:
1399 <http://bobpowell.net/grayscale.aspx> */
1400 float mixed_color
= (GetRValue(orig_color
) * .30 +
1401 GetGValue(orig_color
) * .59 +
1402 GetBValue(orig_color
) * .11);
1404 *ptr
= RGBA(mixed_color
, mixed_color
, mixed_color
, GetAValue(orig_color
));
1413 HeapFree(GetProcessHeap(), 0, info
);
1415 /* return the handle to our desaturated dc, that will substitute its original counterpart in the next calls */
1418 #endif /* __REACTOS__ */
1420 /*************************************************************************
1421 * ImageList_DrawIndirect [COMCTL32.@]
1423 * Draws an image using various parameters specified in pimldp.
1426 * pimldp [I] pointer to IMAGELISTDRAWPARAMS structure.
1434 ImageList_DrawIndirect (IMAGELISTDRAWPARAMS
*pimldp
)
1436 INT cx
, cy
, nOvlIdx
;
1437 DWORD fState
, dwRop
;
1439 COLORREF oldImageBk
, oldImageFg
;
1440 HDC hImageDC
, hImageListDC
, hMaskListDC
;
1441 HBITMAP hImageBmp
, hOldImageBmp
, hBlendMaskBmp
;
1442 BOOL bIsTransparent
, bBlend
, bResult
= FALSE
, bMask
;
1451 if (!pimldp
|| !(himl
= pimldp
->himl
)) return FALSE
;
1452 if (!is_valid(himl
)) return FALSE
;
1453 if ((pimldp
->i
< 0) || (pimldp
->i
>= himl
->cCurImage
)) return FALSE
;
1455 imagelist_point_from_index( himl
, pimldp
->i
, &pt
);
1456 pt
.x
+= pimldp
->xBitmap
;
1457 pt
.y
+= pimldp
->yBitmap
;
1459 fState
= pimldp
->cbSize
< sizeof(IMAGELISTDRAWPARAMS
) ? ILS_NORMAL
: pimldp
->fState
;
1460 fStyle
= pimldp
->fStyle
& ~ILD_OVERLAYMASK
;
1461 cx
= (pimldp
->cx
== 0) ? himl
->cx
: pimldp
->cx
;
1462 cy
= (pimldp
->cy
== 0) ? himl
->cy
: pimldp
->cy
;
1464 bIsTransparent
= (fStyle
& ILD_TRANSPARENT
);
1465 if( pimldp
->rgbBk
== CLR_NONE
)
1466 bIsTransparent
= TRUE
;
1467 if( ( pimldp
->rgbBk
== CLR_DEFAULT
) && ( himl
->clrBk
== CLR_NONE
) )
1468 bIsTransparent
= TRUE
;
1469 bMask
= (himl
->flags
& ILC_MASK
) && (fStyle
& ILD_MASK
) ;
1470 bBlend
= (fStyle
& (ILD_BLEND25
| ILD_BLEND50
) ) && !bMask
;
1472 TRACE("himl(%p) hbmMask(%p) iImage(%d) x(%d) y(%d) cx(%d) cy(%d)\n",
1473 himl
, himl
->hbmMask
, pimldp
->i
, pimldp
->x
, pimldp
->y
, cx
, cy
);
1475 /* we will use these DCs to access the images and masks in the ImageList */
1476 hImageListDC
= himl
->hdcImage
;
1477 hMaskListDC
= himl
->hdcMask
;
1479 /* these will accumulate the image and mask for the image we're drawing */
1480 hImageDC
= CreateCompatibleDC( pimldp
->hdcDst
);
1481 hImageBmp
= CreateCompatibleBitmap( pimldp
->hdcDst
, cx
, cy
);
1482 hBlendMaskBmp
= bBlend
? CreateBitmap(cx
, cy
, 1, 1, NULL
) : 0;
1484 /* Create a compatible DC. */
1485 if (!hImageListDC
|| !hImageDC
|| !hImageBmp
||
1486 (bBlend
&& !hBlendMaskBmp
) || (himl
->hbmMask
&& !hMaskListDC
))
1489 hOldImageBmp
= SelectObject(hImageDC
, hImageBmp
);
1492 * To obtain a transparent look, background color should be set
1493 * to white and foreground color to black when blitting the
1496 oldImageFg
= SetTextColor( hImageDC
, RGB( 0, 0, 0 ) );
1497 oldImageBk
= SetBkColor( hImageDC
, RGB( 0xff, 0xff, 0xff ) );
1501 * If the ILS_SATURATE bit is enabled we should multiply the
1502 * RGB colors of the original image by the contents of rgbFg.
1504 if (fState
& ILS_SATURATE
)
1506 hdcSaturated
= saturate_image(himl
, pimldp
->hdcDst
, pimldp
->x
, pimldp
->y
,
1507 pt
.x
, pt
.y
, cx
, cy
, pimldp
->rgbFg
);
1509 hImageListDC
= hdcSaturated
;
1510 /* shitty way of getting subroutines to blit at the right place (top left corner),
1511 as our modified imagelist only contains a single image for performance reasons */
1517 has_alpha
= (himl
->has_alpha
&& himl
->has_alpha
[pimldp
->i
]);
1518 if (!bMask
&& (has_alpha
|| (fState
& ILS_ALPHA
)))
1520 COLORREF colour
, blend_col
= CLR_NONE
;
1525 blend_col
= pimldp
->rgbFg
;
1526 if (blend_col
== CLR_DEFAULT
) blend_col
= GetSysColor( COLOR_HIGHLIGHT
);
1527 else if (blend_col
== CLR_NONE
) blend_col
= GetTextColor( pimldp
->hdcDst
);
1530 func
.BlendOp
= AC_SRC_OVER
;
1531 func
.BlendFlags
= 0;
1532 func
.SourceConstantAlpha
= (fState
& ILS_ALPHA
) ? pimldp
->Frame
: 255;
1533 func
.AlphaFormat
= AC_SRC_ALPHA
;
1538 bResult
= alpha_blend_image( himl
, hImageListDC
, pimldp
->hdcDst
, pimldp
->x
, pimldp
->y
,
1540 bResult
= alpha_blend_image( himl
, pimldp
->hdcDst
, pimldp
->x
, pimldp
->y
,
1542 pt
.x
, pt
.y
, cx
, cy
, func
, fStyle
, blend_col
);
1545 colour
= pimldp
->rgbBk
;
1546 if (colour
== CLR_DEFAULT
) colour
= himl
->clrBk
;
1547 if (colour
== CLR_NONE
) colour
= GetBkColor( pimldp
->hdcDst
);
1549 hOldBrush
= SelectObject (hImageDC
, CreateSolidBrush (colour
));
1550 PatBlt( hImageDC
, 0, 0, cx
, cy
, PATCOPY
);
1552 alpha_blend_image( himl
, hImageListDC
, hImageDC
, 0, 0, pt
.x
, pt
.y
, cx
, cy
, func
, fStyle
, blend_col
);
1554 alpha_blend_image( himl
, hImageDC
, 0, 0, pt
.x
, pt
.y
, cx
, cy
, func
, fStyle
, blend_col
);
1556 DeleteObject (SelectObject (hImageDC
, hOldBrush
));
1557 bResult
= BitBlt( pimldp
->hdcDst
, pimldp
->x
, pimldp
->y
, cx
, cy
, hImageDC
, 0, 0, SRCCOPY
);
1562 * Draw the initial image
1565 if (himl
->hbmMask
) {
1566 hOldBrush
= SelectObject (hImageDC
, CreateSolidBrush (GetTextColor(pimldp
->hdcDst
)));
1567 PatBlt( hImageDC
, 0, 0, cx
, cy
, PATCOPY
);
1568 BitBlt(hImageDC
, 0, 0, cx
, cy
, hMaskListDC
, pt
.x
, pt
.y
, SRCPAINT
);
1569 DeleteObject (SelectObject (hImageDC
, hOldBrush
));
1570 if( bIsTransparent
)
1572 BitBlt ( pimldp
->hdcDst
, pimldp
->x
, pimldp
->y
, cx
, cy
, hImageDC
, 0, 0, SRCAND
);
1577 hOldBrush
= SelectObject (hImageDC
, GetStockObject(BLACK_BRUSH
));
1578 PatBlt( hImageDC
, 0, 0, cx
, cy
, PATCOPY
);
1579 SelectObject(hImageDC
, hOldBrush
);
1582 /* blend the image with the needed solid background */
1583 COLORREF colour
= RGB(0,0,0);
1585 if( !bIsTransparent
)
1587 colour
= pimldp
->rgbBk
;
1588 if( colour
== CLR_DEFAULT
)
1589 colour
= himl
->clrBk
;
1590 if( colour
== CLR_NONE
)
1591 colour
= GetBkColor(pimldp
->hdcDst
);
1594 hOldBrush
= SelectObject (hImageDC
, CreateSolidBrush (colour
));
1595 PatBlt( hImageDC
, 0, 0, cx
, cy
, PATCOPY
);
1598 BitBlt( hImageDC
, 0, 0, cx
, cy
, hMaskListDC
, pt
.x
, pt
.y
, SRCAND
);
1599 BitBlt( hImageDC
, 0, 0, cx
, cy
, hImageListDC
, pt
.x
, pt
.y
, SRCPAINT
);
1602 BitBlt( hImageDC
, 0, 0, cx
, cy
, hImageListDC
, pt
.x
, pt
.y
, SRCCOPY
);
1603 DeleteObject (SelectObject (hImageDC
, hOldBrush
));
1606 /* Time for blending, if required */
1609 COLORREF clrBlend
= pimldp
->rgbFg
;
1610 HDC hBlendMaskDC
= hImageListDC
;
1613 /* Create the blend Mask */
1614 hOldBitmap
= SelectObject(hBlendMaskDC
, hBlendMaskBmp
);
1615 hBlendBrush
= fStyle
& ILD_BLEND50
? himl
->hbrBlend50
: himl
->hbrBlend25
;
1616 hOldBrush
= SelectObject(hBlendMaskDC
, hBlendBrush
);
1617 PatBlt(hBlendMaskDC
, 0, 0, cx
, cy
, PATCOPY
);
1618 SelectObject(hBlendMaskDC
, hOldBrush
);
1620 /* Modify the blend mask if an Image Mask exist */
1622 BitBlt(hBlendMaskDC
, 0, 0, cx
, cy
, hMaskListDC
, pt
.x
, pt
.y
, 0x220326); /* NOTSRCAND */
1623 BitBlt(hBlendMaskDC
, 0, 0, cx
, cy
, hBlendMaskDC
, 0, 0, NOTSRCCOPY
);
1626 /* now apply blend to the current image given the BlendMask */
1627 if (clrBlend
== CLR_DEFAULT
) clrBlend
= GetSysColor (COLOR_HIGHLIGHT
);
1628 else if (clrBlend
== CLR_NONE
) clrBlend
= GetTextColor (pimldp
->hdcDst
);
1629 hOldBrush
= SelectObject (hImageDC
, CreateSolidBrush(clrBlend
));
1630 BitBlt (hImageDC
, 0, 0, cx
, cy
, hBlendMaskDC
, 0, 0, 0xB8074A); /* PSDPxax */
1631 DeleteObject(SelectObject(hImageDC
, hOldBrush
));
1632 SelectObject(hBlendMaskDC
, hOldBitmap
);
1635 /* Now do the overlay image, if any */
1636 nOvlIdx
= (pimldp
->fStyle
& ILD_OVERLAYMASK
) >> 8;
1637 if ( (nOvlIdx
>= 1) && (nOvlIdx
<= MAX_OVERLAYIMAGE
)) {
1638 nOvlIdx
= himl
->nOvlIdx
[nOvlIdx
- 1];
1639 if ((nOvlIdx
>= 0) && (nOvlIdx
< himl
->cCurImage
)) {
1641 imagelist_point_from_index( himl
, nOvlIdx
, &ptOvl
);
1642 ptOvl
.x
+= pimldp
->xBitmap
;
1643 if (himl
->hbmMask
&& !(fStyle
& ILD_IMAGE
))
1644 BitBlt (hImageDC
, 0, 0, cx
, cy
, hMaskListDC
, ptOvl
.x
, ptOvl
.y
, SRCAND
);
1645 BitBlt (hImageDC
, 0, 0, cx
, cy
, hImageListDC
, ptOvl
.x
, ptOvl
.y
, SRCPAINT
);
1650 if (fState
& ILS_SATURATE
) FIXME("ILS_SATURATE: unimplemented!\n");
1652 if (fState
& ILS_GLOW
) FIXME("ILS_GLOW: unimplemented!\n");
1653 if (fState
& ILS_SHADOW
) FIXME("ILS_SHADOW: unimplemented!\n");
1655 if (fStyle
& ILD_PRESERVEALPHA
) FIXME("ILD_PRESERVEALPHA: unimplemented!\n");
1656 if (fStyle
& ILD_SCALE
) FIXME("ILD_SCALE: unimplemented!\n");
1657 if (fStyle
& ILD_DPISCALE
) FIXME("ILD_DPISCALE: unimplemented!\n");
1659 /* now copy the image to the screen */
1661 if (himl
->hbmMask
&& bIsTransparent
) {
1662 COLORREF oldDstFg
= SetTextColor(pimldp
->hdcDst
, RGB( 0, 0, 0 ) );
1663 COLORREF oldDstBk
= SetBkColor(pimldp
->hdcDst
, RGB( 0xff, 0xff, 0xff ));
1664 BitBlt (pimldp
->hdcDst
, pimldp
->x
, pimldp
->y
, cx
, cy
, hMaskListDC
, pt
.x
, pt
.y
, SRCAND
);
1665 SetBkColor(pimldp
->hdcDst
, oldDstBk
);
1666 SetTextColor(pimldp
->hdcDst
, oldDstFg
);
1669 if (fStyle
& ILD_ROP
) dwRop
= pimldp
->dwRop
;
1670 BitBlt (pimldp
->hdcDst
, pimldp
->x
, pimldp
->y
, cx
, cy
, hImageDC
, 0, 0, dwRop
);
1674 /* cleanup the mess */
1675 SetBkColor(hImageDC
, oldImageBk
);
1676 SetTextColor(hImageDC
, oldImageFg
);
1677 SelectObject(hImageDC
, hOldImageBmp
);
1681 DeleteDC(hdcSaturated
);
1683 DeleteObject(hBlendMaskBmp
);
1684 DeleteObject(hImageBmp
);
1691 /*************************************************************************
1692 * ImageList_Duplicate [COMCTL32.@]
1694 * Duplicates an image list.
1697 * himlSrc [I] source image list handle
1700 * Success: Handle of duplicated image list.
1705 ImageList_Duplicate (HIMAGELIST himlSrc
)
1709 if (!is_valid(himlSrc
)) {
1710 ERR("Invalid image list handle!\n");
1714 himlDst
= ImageList_Create (himlSrc
->cx
, himlSrc
->cy
, himlSrc
->flags
,
1715 himlSrc
->cCurImage
, himlSrc
->cGrow
);
1721 imagelist_get_bitmap_size(himlSrc
, himlSrc
->cCurImage
, &sz
);
1722 BitBlt (himlDst
->hdcImage
, 0, 0, sz
.cx
, sz
.cy
,
1723 himlSrc
->hdcImage
, 0, 0, SRCCOPY
);
1725 if (himlDst
->hbmMask
)
1726 BitBlt (himlDst
->hdcMask
, 0, 0, sz
.cx
, sz
.cy
,
1727 himlSrc
->hdcMask
, 0, 0, SRCCOPY
);
1729 himlDst
->cCurImage
= himlSrc
->cCurImage
;
1730 if (himlSrc
->has_alpha
&& himlDst
->has_alpha
)
1731 memcpy( himlDst
->has_alpha
, himlSrc
->has_alpha
, himlDst
->cCurImage
);
1737 /*************************************************************************
1738 * ImageList_EndDrag [COMCTL32.@]
1740 * Finishes a drag operation.
1751 ImageList_EndDrag (void)
1753 /* cleanup the InternalDrag struct */
1754 InternalDrag
.hwnd
= 0;
1755 if (InternalDrag
.himl
!= InternalDrag
.himlNoCursor
)
1756 ImageList_Destroy (InternalDrag
.himlNoCursor
);
1757 ImageList_Destroy (InternalDrag
.himl
);
1758 InternalDrag
.himlNoCursor
= InternalDrag
.himl
= 0;
1761 InternalDrag
.dxHotspot
= 0;
1762 InternalDrag
.dyHotspot
= 0;
1763 InternalDrag
.bShow
= FALSE
;
1764 DeleteObject(InternalDrag
.hbmBg
);
1765 InternalDrag
.hbmBg
= 0;
1769 /*************************************************************************
1770 * ImageList_GetBkColor [COMCTL32.@]
1772 * Returns the background color of an image list.
1775 * himl [I] Image list handle.
1778 * Success: background color
1783 ImageList_GetBkColor (HIMAGELIST himl
)
1785 return himl
? himl
->clrBk
: CLR_NONE
;
1789 /*************************************************************************
1790 * ImageList_GetDragImage [COMCTL32.@]
1792 * Returns the handle to the internal drag image list.
1795 * ppt [O] Pointer to the drag position. Can be NULL.
1796 * pptHotspot [O] Pointer to the position of the hot spot. Can be NULL.
1799 * Success: Handle of the drag image list.
1804 ImageList_GetDragImage (POINT
*ppt
, POINT
*pptHotspot
)
1806 if (is_valid(InternalDrag
.himl
)) {
1808 ppt
->x
= InternalDrag
.x
;
1809 ppt
->y
= InternalDrag
.y
;
1812 pptHotspot
->x
= InternalDrag
.dxHotspot
;
1813 pptHotspot
->y
= InternalDrag
.dyHotspot
;
1815 return (InternalDrag
.himl
);
1822 /*************************************************************************
1823 * ImageList_GetFlags [COMCTL32.@]
1825 * Gets the flags of the specified image list.
1828 * himl [I] Handle to image list
1838 ImageList_GetFlags(HIMAGELIST himl
)
1840 TRACE("%p\n", himl
);
1842 return is_valid(himl
) ? himl
->flags
: 0;
1846 /*************************************************************************
1847 * ImageList_GetIcon [COMCTL32.@]
1849 * Creates an icon from a masked image of an image list.
1852 * himl [I] handle to image list
1854 * flags [I] drawing style flags
1857 * Success: icon handle
1862 ImageList_GetIcon (HIMAGELIST himl
, INT i
, UINT fStyle
)
1866 HBITMAP hOldDstBitmap
;
1870 TRACE("%p %d %d\n", himl
, i
, fStyle
);
1871 if (!is_valid(himl
) || (i
< 0) || (i
>= himl
->cCurImage
)) return NULL
;
1877 /* create colour bitmap */
1879 ii
.hbmColor
= CreateCompatibleBitmap(hdcDst
, himl
->cx
, himl
->cy
);
1880 ReleaseDC(0, hdcDst
);
1882 hdcDst
= CreateCompatibleDC(0);
1884 imagelist_point_from_index( himl
, i
, &pt
);
1887 ii
.hbmMask
= CreateBitmap (himl
->cx
, himl
->cy
, 1, 1, NULL
);
1888 hOldDstBitmap
= SelectObject (hdcDst
, ii
.hbmMask
);
1889 if (himl
->hbmMask
) {
1890 BitBlt (hdcDst
, 0, 0, himl
->cx
, himl
->cy
,
1891 himl
->hdcMask
, pt
.x
, pt
.y
, SRCCOPY
);
1894 PatBlt (hdcDst
, 0, 0, himl
->cx
, himl
->cy
, BLACKNESS
);
1897 SelectObject (hdcDst
, ii
.hbmColor
);
1898 BitBlt (hdcDst
, 0, 0, himl
->cx
, himl
->cy
,
1899 himl
->hdcImage
, pt
.x
, pt
.y
, SRCCOPY
);
1902 * CreateIconIndirect requires us to deselect the bitmaps from
1903 * the DCs before calling
1905 SelectObject(hdcDst
, hOldDstBitmap
);
1907 hIcon
= CreateIconIndirect (&ii
);
1909 DeleteObject (ii
.hbmMask
);
1910 DeleteObject (ii
.hbmColor
);
1917 /*************************************************************************
1918 * ImageList_GetIconSize [COMCTL32.@]
1920 * Retrieves the size of an image in an image list.
1923 * himl [I] handle to image list
1924 * cx [O] pointer to the image width.
1925 * cy [O] pointer to the image height.
1932 * All images in an image list have the same size.
1936 ImageList_GetIconSize (HIMAGELIST himl
, INT
*cx
, INT
*cy
)
1938 if (!is_valid(himl
) || !cx
|| !cy
)
1948 /*************************************************************************
1949 * ImageList_GetImageCount [COMCTL32.@]
1951 * Returns the number of images in an image list.
1954 * himl [I] handle to image list
1957 * Success: Number of images.
1962 ImageList_GetImageCount (HIMAGELIST himl
)
1964 if (!is_valid(himl
))
1967 return himl
->cCurImage
;
1971 /*************************************************************************
1972 * ImageList_GetImageInfo [COMCTL32.@]
1974 * Returns information about an image in an image list.
1977 * himl [I] handle to image list
1979 * pImageInfo [O] pointer to the image information
1987 ImageList_GetImageInfo (HIMAGELIST himl
, INT i
, IMAGEINFO
*pImageInfo
)
1991 if (!is_valid(himl
) || (pImageInfo
== NULL
))
1993 if ((i
< 0) || (i
>= himl
->cCurImage
))
1996 pImageInfo
->hbmImage
= himl
->hbmImage
;
1997 pImageInfo
->hbmMask
= himl
->hbmMask
;
1999 imagelist_point_from_index( himl
, i
, &pt
);
2000 pImageInfo
->rcImage
.top
= pt
.y
;
2001 pImageInfo
->rcImage
.bottom
= pt
.y
+ himl
->cy
;
2002 pImageInfo
->rcImage
.left
= pt
.x
;
2003 pImageInfo
->rcImage
.right
= pt
.x
+ himl
->cx
;
2009 /*************************************************************************
2010 * ImageList_GetImageRect [COMCTL32.@]
2012 * Retrieves the rectangle of the specified image in an image list.
2015 * himl [I] handle to image list
2017 * lpRect [O] pointer to the image rectangle
2024 * This is an UNDOCUMENTED function!!!
2028 ImageList_GetImageRect (HIMAGELIST himl
, INT i
, LPRECT lpRect
)
2032 if (!is_valid(himl
) || (lpRect
== NULL
))
2034 if ((i
< 0) || (i
>= himl
->cCurImage
))
2037 imagelist_point_from_index( himl
, i
, &pt
);
2038 lpRect
->left
= pt
.x
;
2040 lpRect
->right
= pt
.x
+ himl
->cx
;
2041 lpRect
->bottom
= pt
.y
+ himl
->cy
;
2047 /*************************************************************************
2048 * ImageList_LoadImage [COMCTL32.@]
2049 * ImageList_LoadImageA [COMCTL32.@]
2051 * Creates an image list from a bitmap, icon or cursor.
2053 * See ImageList_LoadImageW.
2057 ImageList_LoadImageA (HINSTANCE hi
, LPCSTR lpbmp
, INT cx
, INT cGrow
,
2058 COLORREF clrMask
, UINT uType
, UINT uFlags
)
2064 if (IS_INTRESOURCE(lpbmp
))
2065 return ImageList_LoadImageW(hi
, (LPCWSTR
)lpbmp
, cx
, cGrow
, clrMask
,
2068 len
= MultiByteToWideChar(CP_ACP
, 0, lpbmp
, -1, NULL
, 0);
2069 lpbmpW
= Alloc(len
* sizeof(WCHAR
));
2070 MultiByteToWideChar(CP_ACP
, 0, lpbmp
, -1, lpbmpW
, len
);
2072 himl
= ImageList_LoadImageW(hi
, lpbmpW
, cx
, cGrow
, clrMask
, uType
, uFlags
);
2078 /*************************************************************************
2079 * ImageList_LoadImageW [COMCTL32.@]
2081 * Creates an image list from a bitmap, icon or cursor.
2084 * hi [I] instance handle
2085 * lpbmp [I] name or id of the image
2086 * cx [I] width of each image
2087 * cGrow [I] number of images to expand
2088 * clrMask [I] mask color
2089 * uType [I] type of image to load
2090 * uFlags [I] loading flags
2093 * Success: handle to the loaded image list
2101 ImageList_LoadImageW (HINSTANCE hi
, LPCWSTR lpbmp
, INT cx
, INT cGrow
,
2102 COLORREF clrMask
, UINT uType
, UINT uFlags
)
2104 HIMAGELIST himl
= NULL
;
2108 handle
= LoadImageW (hi
, lpbmp
, uType
, 0, 0, uFlags
);
2110 WARN("Couldn't load image\n");
2114 if (uType
== IMAGE_BITMAP
) {
2118 if (GetObjectW (handle
, sizeof(dib
), &dib
) == sizeof(BITMAP
)) color
= ILC_COLOR
;
2119 else color
= dib
.dsBm
.bmBitsPixel
;
2121 /* To match windows behavior, if cx is set to zero and
2122 the flag DI_DEFAULTSIZE is specified, cx becomes the
2123 system metric value for icons. If the flag is not specified
2124 the function sets the size to the height of the bitmap */
2127 if (uFlags
& DI_DEFAULTSIZE
)
2128 cx
= GetSystemMetrics (SM_CXICON
);
2130 cx
= dib
.dsBm
.bmHeight
;
2133 nImageCount
= dib
.dsBm
.bmWidth
/ cx
;
2135 himl
= ImageList_Create (cx
, dib
.dsBm
.bmHeight
, ILC_MASK
| color
, nImageCount
, cGrow
);
2137 DeleteObject (handle
);
2140 ImageList_AddMasked (himl
, handle
, clrMask
);
2142 else if ((uType
== IMAGE_ICON
) || (uType
== IMAGE_CURSOR
)) {
2146 GetIconInfo (handle
, &ii
);
2147 GetObjectW (ii
.hbmColor
, sizeof(BITMAP
), &bmp
);
2148 himl
= ImageList_Create (bmp
.bmWidth
, bmp
.bmHeight
,
2149 ILC_MASK
| ILC_COLOR
, 1, cGrow
);
2151 DeleteObject (ii
.hbmColor
);
2152 DeleteObject (ii
.hbmMask
);
2153 DeleteObject (handle
);
2156 ImageList_Add (himl
, ii
.hbmColor
, ii
.hbmMask
);
2157 DeleteObject (ii
.hbmColor
);
2158 DeleteObject (ii
.hbmMask
);
2161 DeleteObject (handle
);
2167 /*************************************************************************
2168 * ImageList_Merge [COMCTL32.@]
2170 * Create an image list containing a merged image from two image lists.
2173 * himl1 [I] handle to first image list
2174 * i1 [I] first image index
2175 * himl2 [I] handle to second image list
2176 * i2 [I] second image index
2177 * dx [I] X offset of the second image relative to the first.
2178 * dy [I] Y offset of the second image relative to the first.
2181 * Success: The newly created image list. It contains a single image
2182 * consisting of the second image merged with the first.
2183 * Failure: NULL, if either himl1 or himl2 is invalid.
2186 * - The returned image list should be deleted by the caller using
2187 * ImageList_Destroy() when it is no longer required.
2188 * - If either i1 or i2 is not a valid image index, they will be treated
2192 ImageList_Merge (HIMAGELIST himl1
, INT i1
, HIMAGELIST himl2
, INT i2
,
2195 HIMAGELIST himlDst
= NULL
;
2197 INT xOff1
, yOff1
, xOff2
, yOff2
;
2201 TRACE("(himl1=%p i1=%d himl2=%p i2=%d dx=%d dy=%d)\n", himl1
, i1
, himl2
,
2204 if (!is_valid(himl1
) || !is_valid(himl2
))
2208 cxDst
= max (himl1
->cx
, dx
+ himl2
->cx
);
2213 cxDst
= max (himl2
->cx
, himl1
->cx
- dx
);
2218 cxDst
= max (himl1
->cx
, himl2
->cx
);
2224 cyDst
= max (himl1
->cy
, dy
+ himl2
->cy
);
2229 cyDst
= max (himl2
->cy
, himl1
->cy
- dy
);
2234 cyDst
= max (himl1
->cy
, himl2
->cy
);
2239 newFlags
= (himl1
->flags
> himl2
->flags
? himl1
->flags
: himl2
->flags
) & ILC_COLORDDB
;
2240 if (newFlags
== ILC_COLORDDB
&& (himl1
->flags
& ILC_COLORDDB
) == ILC_COLOR16
)
2241 newFlags
= ILC_COLOR16
; /* this is what native (at least v5) does, don't know why */
2242 himlDst
= ImageList_Create (cxDst
, cyDst
, ILC_MASK
| newFlags
, 1, 1);
2246 imagelist_point_from_index( himl1
, i1
, &pt1
);
2247 imagelist_point_from_index( himl2
, i2
, &pt2
);
2250 BitBlt (himlDst
->hdcImage
, 0, 0, cxDst
, cyDst
, himl1
->hdcImage
, 0, 0, BLACKNESS
);
2251 if (i1
>= 0 && i1
< himl1
->cCurImage
)
2252 BitBlt (himlDst
->hdcImage
, xOff1
, yOff1
, himl1
->cx
, himl1
->cy
, himl1
->hdcImage
, pt1
.x
, pt1
.y
, SRCCOPY
);
2253 if (i2
>= 0 && i2
< himl2
->cCurImage
)
2255 if (himl2
->flags
& ILC_MASK
)
2257 BitBlt (himlDst
->hdcImage
, xOff2
, yOff2
, himl2
->cx
, himl2
->cy
, himl2
->hdcMask
, pt2
.x
, pt2
.y
, SRCAND
);
2258 BitBlt (himlDst
->hdcImage
, xOff2
, yOff2
, himl2
->cx
, himl2
->cy
, himl2
->hdcImage
, pt2
.x
, pt2
.y
, SRCPAINT
);
2261 BitBlt (himlDst
->hdcImage
, xOff2
, yOff2
, himl2
->cx
, himl2
->cy
, himl2
->hdcImage
, pt2
.x
, pt2
.y
, SRCCOPY
);
2265 BitBlt (himlDst
->hdcMask
, 0, 0, cxDst
, cyDst
, himl1
->hdcMask
, 0, 0, WHITENESS
);
2266 if (i1
>= 0 && i1
< himl1
->cCurImage
)
2267 BitBlt (himlDst
->hdcMask
, xOff1
, yOff1
, himl1
->cx
, himl1
->cy
, himl1
->hdcMask
, pt1
.x
, pt1
.y
, SRCCOPY
);
2268 if (i2
>= 0 && i2
< himl2
->cCurImage
)
2269 BitBlt (himlDst
->hdcMask
, xOff2
, yOff2
, himl2
->cx
, himl2
->cy
, himl2
->hdcMask
, pt2
.x
, pt2
.y
, SRCAND
);
2271 himlDst
->cCurImage
= 1;
2278 /* helper for ImageList_Read, see comments below */
2279 static void *read_bitmap(IStream
*pstm
, BITMAPINFO
*bmi
)
2281 BITMAPFILEHEADER bmfh
;
2282 int bitsperpixel
, palspace
;
2285 if (FAILED(IStream_Read ( pstm
, &bmfh
, sizeof(bmfh
), NULL
)))
2288 if (bmfh
.bfType
!= (('M'<<8)|'B'))
2291 if (FAILED(IStream_Read ( pstm
, &bmi
->bmiHeader
, sizeof(bmi
->bmiHeader
), NULL
)))
2294 if ((bmi
->bmiHeader
.biSize
!= sizeof(bmi
->bmiHeader
)))
2297 TRACE("width %u, height %u, planes %u, bpp %u\n",
2298 bmi
->bmiHeader
.biWidth
, bmi
->bmiHeader
.biHeight
,
2299 bmi
->bmiHeader
.biPlanes
, bmi
->bmiHeader
.biBitCount
);
2301 bitsperpixel
= bmi
->bmiHeader
.biPlanes
* bmi
->bmiHeader
.biBitCount
;
2302 if (bitsperpixel
<=8)
2303 palspace
= (1<<bitsperpixel
)*sizeof(RGBQUAD
);
2307 bmi
->bmiHeader
.biSizeImage
= get_dib_image_size( bmi
);
2309 /* read the palette right after the end of the bitmapinfoheader */
2310 if (palspace
&& FAILED(IStream_Read(pstm
, bmi
->bmiColors
, palspace
, NULL
)))
2313 bits
= Alloc(bmi
->bmiHeader
.biSizeImage
);
2314 if (!bits
) return NULL
;
2316 if (FAILED(IStream_Read(pstm
, bits
, bmi
->bmiHeader
.biSizeImage
, NULL
)))
2324 /*************************************************************************
2325 * ImageList_Read [COMCTL32.@]
2327 * Reads an image list from a stream.
2330 * pstm [I] pointer to a stream
2333 * Success: handle to image list
2336 * The format is like this:
2337 * ILHEAD ilheadstruct;
2339 * for the color image part:
2340 * BITMAPFILEHEADER bmfh;
2341 * BITMAPINFOHEADER bmih;
2342 * only if it has a palette:
2343 * RGBQUAD rgbs[nr_of_paletted_colors];
2345 * BYTE colorbits[imagesize];
2347 * the following only if the ILC_MASK bit is set in ILHEAD.ilFlags:
2348 * BITMAPFILEHEADER bmfh_mask;
2349 * BITMAPINFOHEADER bmih_mask;
2350 * only if it has a palette (it usually does not):
2351 * RGBQUAD rgbs[nr_of_paletted_colors];
2353 * BYTE maskbits[imagesize];
2355 HIMAGELIST WINAPI
ImageList_Read(IStream
*pstm
)
2357 char image_buf
[sizeof(BITMAPINFOHEADER
) + sizeof(RGBQUAD
) * 256];
2358 char mask_buf
[sizeof(BITMAPINFOHEADER
) + sizeof(RGBQUAD
) * 256];
2359 BITMAPINFO
*image_info
= (BITMAPINFO
*)image_buf
;
2360 BITMAPINFO
*mask_info
= (BITMAPINFO
*)mask_buf
;
2361 void *image_bits
, *mask_bits
= NULL
;
2366 TRACE("%p\n", pstm
);
2368 if (FAILED(IStream_Read (pstm
, &ilHead
, sizeof(ILHEAD
), NULL
)))
2370 if (ilHead
.usMagic
!= (('L' << 8) | 'I'))
2372 if (ilHead
.usVersion
!= 0x101) /* probably version? */
2375 TRACE("cx %u, cy %u, flags 0x%04x, cCurImage %u, cMaxImage %u\n",
2376 ilHead
.cx
, ilHead
.cy
, ilHead
.flags
, ilHead
.cCurImage
, ilHead
.cMaxImage
);
2378 himl
= ImageList_Create(ilHead
.cx
, ilHead
.cy
, ilHead
.flags
, ilHead
.cCurImage
, ilHead
.cMaxImage
);
2382 if (!(image_bits
= read_bitmap(pstm
, image_info
)))
2384 WARN("failed to read bitmap from stream\n");
2387 if (ilHead
.flags
& ILC_MASK
)
2389 if (!(mask_bits
= read_bitmap(pstm
, mask_info
)))
2391 WARN("failed to read mask bitmap from stream\n");
2395 else mask_info
= NULL
;
2397 if (himl
->has_alpha
&& image_info
->bmiHeader
.biBitCount
== 32)
2399 DWORD
*ptr
= image_bits
;
2400 BYTE
*mask_ptr
= mask_bits
;
2401 int stride
= himl
->cy
* image_info
->bmiHeader
.biWidth
;
2403 if (image_info
->bmiHeader
.biHeight
> 0) /* bottom-up */
2405 ptr
+= image_info
->bmiHeader
.biHeight
* image_info
->bmiHeader
.biWidth
- stride
;
2406 mask_ptr
+= (image_info
->bmiHeader
.biHeight
* image_info
->bmiHeader
.biWidth
- stride
) / 8;
2408 image_info
->bmiHeader
.biHeight
= himl
->cy
;
2410 else image_info
->bmiHeader
.biHeight
= -himl
->cy
;
2412 for (i
= 0; i
< ilHead
.cCurImage
; i
+= TILE_COUNT
)
2414 add_dib_bits( himl
, i
, min( ilHead
.cCurImage
- i
, TILE_COUNT
),
2415 himl
->cx
, himl
->cy
, image_info
, mask_info
, ptr
, mask_ptr
);
2417 mask_ptr
+= stride
/ 8;
2422 StretchDIBits( himl
->hdcImage
, 0, 0, image_info
->bmiHeader
.biWidth
, image_info
->bmiHeader
.biHeight
,
2423 0, 0, image_info
->bmiHeader
.biWidth
, image_info
->bmiHeader
.biHeight
,
2424 image_bits
, image_info
, DIB_RGB_COLORS
, SRCCOPY
);
2426 StretchDIBits( himl
->hdcMask
, 0, 0, mask_info
->bmiHeader
.biWidth
, mask_info
->bmiHeader
.biHeight
,
2427 0, 0, mask_info
->bmiHeader
.biWidth
, mask_info
->bmiHeader
.biHeight
,
2428 mask_bits
, mask_info
, DIB_RGB_COLORS
, SRCCOPY
);
2433 himl
->cCurImage
= ilHead
.cCurImage
;
2434 himl
->cMaxImage
= ilHead
.cMaxImage
;
2436 ImageList_SetBkColor(himl
,ilHead
.bkcolor
);
2438 ImageList_SetOverlayImage(himl
,ilHead
.ovls
[i
],i
+1);
2443 /*************************************************************************
2444 * ImageList_Remove [COMCTL32.@]
2446 * Removes an image from an image list
2449 * himl [I] image list handle
2456 * FIXME: as the image list storage test shows, native comctl32 simply shifts
2457 * images without creating a new bitmap.
2460 ImageList_Remove (HIMAGELIST himl
, INT i
)
2462 HBITMAP hbmNewImage
, hbmNewMask
;
2466 TRACE("(himl=%p i=%d)\n", himl
, i
);
2468 if (!is_valid(himl
)) {
2469 ERR("Invalid image list handle!\n");
2473 if ((i
< -1) || (i
>= himl
->cCurImage
)) {
2474 TRACE("index out of range! %d\n", i
);
2482 if (himl
->cCurImage
== 0) {
2483 /* remove all on empty ImageList is allowed */
2484 TRACE("remove all on empty ImageList!\n");
2488 himl
->cMaxImage
= himl
->cGrow
;
2489 himl
->cCurImage
= 0;
2490 for (nCount
= 0; nCount
< MAX_OVERLAYIMAGE
; nCount
++)
2491 himl
->nOvlIdx
[nCount
] = -1;
2493 if (himl
->has_alpha
)
2495 HeapFree( GetProcessHeap(), 0, himl
->has_alpha
);
2496 himl
->has_alpha
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, himl
->cMaxImage
);
2499 hbmNewImage
= ImageList_CreateImage(himl
->hdcImage
, himl
, himl
->cMaxImage
);
2500 SelectObject (himl
->hdcImage
, hbmNewImage
);
2501 DeleteObject (himl
->hbmImage
);
2502 himl
->hbmImage
= hbmNewImage
;
2504 if (himl
->hbmMask
) {
2506 imagelist_get_bitmap_size(himl
, himl
->cMaxImage
, &sz
);
2507 hbmNewMask
= CreateBitmap (sz
.cx
, sz
.cy
, 1, 1, NULL
);
2508 SelectObject (himl
->hdcMask
, hbmNewMask
);
2509 DeleteObject (himl
->hbmMask
);
2510 himl
->hbmMask
= hbmNewMask
;
2514 /* delete one image */
2515 TRACE("Remove single image! %d\n", i
);
2517 /* create new bitmap(s) */
2518 TRACE(" - Number of images: %d / %d (Old/New)\n",
2519 himl
->cCurImage
, himl
->cCurImage
- 1);
2521 hbmNewImage
= ImageList_CreateImage(himl
->hdcImage
, himl
, himl
->cMaxImage
);
2523 imagelist_get_bitmap_size(himl
, himl
->cMaxImage
, &sz
);
2525 hbmNewMask
= CreateBitmap (sz
.cx
, sz
.cy
, 1, 1, NULL
);
2527 hbmNewMask
= 0; /* Just to keep compiler happy! */
2529 hdcBmp
= CreateCompatibleDC (0);
2531 /* copy all images and masks prior to the "removed" image */
2533 TRACE("Pre image copy: Copy %d images\n", i
);
2535 SelectObject (hdcBmp
, hbmNewImage
);
2536 imagelist_copy_images( himl
, himl
->hdcImage
, hdcBmp
, 0, i
, 0 );
2538 if (himl
->hbmMask
) {
2539 SelectObject (hdcBmp
, hbmNewMask
);
2540 imagelist_copy_images( himl
, himl
->hdcMask
, hdcBmp
, 0, i
, 0 );
2544 /* copy all images and masks behind the removed image */
2545 if (i
< himl
->cCurImage
- 1) {
2546 TRACE("Post image copy!\n");
2548 SelectObject (hdcBmp
, hbmNewImage
);
2549 imagelist_copy_images( himl
, himl
->hdcImage
, hdcBmp
, i
+ 1,
2550 (himl
->cCurImage
- i
), i
);
2552 if (himl
->hbmMask
) {
2553 SelectObject (hdcBmp
, hbmNewMask
);
2554 imagelist_copy_images( himl
, himl
->hdcMask
, hdcBmp
, i
+ 1,
2555 (himl
->cCurImage
- i
), i
);
2561 /* delete old images and insert new ones */
2562 SelectObject (himl
->hdcImage
, hbmNewImage
);
2563 DeleteObject (himl
->hbmImage
);
2564 himl
->hbmImage
= hbmNewImage
;
2565 if (himl
->hbmMask
) {
2566 SelectObject (himl
->hdcMask
, hbmNewMask
);
2567 DeleteObject (himl
->hbmMask
);
2568 himl
->hbmMask
= hbmNewMask
;
2578 /*************************************************************************
2579 * ImageList_Replace [COMCTL32.@]
2581 * Replaces an image in an image list with a new image.
2584 * himl [I] handle to image list
2586 * hbmImage [I] handle to image bitmap
2587 * hbmMask [I] handle to mask bitmap. Can be NULL.
2595 ImageList_Replace (HIMAGELIST himl
, INT i
, HBITMAP hbmImage
,
2602 TRACE("%p %d %p %p\n", himl
, i
, hbmImage
, hbmMask
);
2604 if (!is_valid(himl
)) {
2605 ERR("Invalid image list handle!\n");
2609 if ((i
>= himl
->cMaxImage
) || (i
< 0)) {
2610 ERR("Invalid image index!\n");
2614 if (!GetObjectW(hbmImage
, sizeof(BITMAP
), &bmp
))
2617 hdcImage
= CreateCompatibleDC (0);
2620 SelectObject (hdcImage
, hbmImage
);
2622 if (add_with_alpha( himl
, hdcImage
, i
, 1, bmp
.bmWidth
, bmp
.bmHeight
, hbmImage
, hbmMask
))
2625 imagelist_point_from_index(himl
, i
, &pt
);
2626 StretchBlt (himl
->hdcImage
, pt
.x
, pt
.y
, himl
->cx
, himl
->cy
,
2627 hdcImage
, 0, 0, bmp
.bmWidth
, bmp
.bmHeight
, SRCCOPY
);
2632 HBITMAP hOldBitmapTemp
;
2634 hdcTemp
= CreateCompatibleDC(0);
2635 hOldBitmapTemp
= SelectObject(hdcTemp
, hbmMask
);
2637 StretchBlt (himl
->hdcMask
, pt
.x
, pt
.y
, himl
->cx
, himl
->cy
,
2638 hdcTemp
, 0, 0, bmp
.bmWidth
, bmp
.bmHeight
, SRCCOPY
);
2639 SelectObject(hdcTemp
, hOldBitmapTemp
);
2642 /* Remove the background from the image
2644 BitBlt (himl
->hdcImage
, pt
.x
, pt
.y
, bmp
.bmWidth
, bmp
.bmHeight
,
2645 himl
->hdcMask
, pt
.x
, pt
.y
, 0x220326); /* NOTSRCAND */
2649 DeleteDC (hdcImage
);
2655 /*************************************************************************
2656 * ImageList_ReplaceIcon [COMCTL32.@]
2658 * Replaces an image in an image list using an icon.
2661 * himl [I] handle to image list
2663 * hIcon [I] handle to icon
2666 * Success: index of the replaced image
2671 ImageList_ReplaceIcon (HIMAGELIST himl
, INT nIndex
, HICON hIcon
)
2679 TRACE("(%p %d %p)\n", himl
, nIndex
, hIcon
);
2681 if (!is_valid(himl
)) {
2682 ERR("invalid image list\n");
2685 if ((nIndex
>= himl
->cMaxImage
) || (nIndex
< -1)) {
2686 ERR("invalid image index %d / %d\n", nIndex
, himl
->cMaxImage
);
2690 hBestFitIcon
= CopyImage(
2693 LR_COPYFROMRESOURCE
);
2694 /* the above will fail if the icon wasn't loaded from a resource, so try
2695 * again without LR_COPYFROMRESOURCE flag */
2697 hBestFitIcon
= CopyImage(
2705 if (himl
->cCurImage
+ 1 >= himl
->cMaxImage
)
2706 IMAGELIST_InternalExpandBitmaps(himl
, 1);
2708 nIndex
= himl
->cCurImage
;
2712 if (himl
->has_alpha
&& GetIconInfo (hBestFitIcon
, &ii
))
2714 HDC hdcImage
= CreateCompatibleDC( 0 );
2715 GetObjectW (ii
.hbmMask
, sizeof(BITMAP
), &bmp
);
2719 UINT height
= bmp
.bmHeight
/ 2;
2720 HDC hdcMask
= CreateCompatibleDC( 0 );
2721 HBITMAP color
= CreateBitmap( bmp
.bmWidth
, height
, 1, 1, NULL
);
2722 SelectObject( hdcImage
, color
);
2723 SelectObject( hdcMask
, ii
.hbmMask
);
2724 BitBlt( hdcImage
, 0, 0, bmp
.bmWidth
, height
, hdcMask
, 0, height
, SRCCOPY
);
2725 ret
= add_with_alpha( himl
, hdcImage
, nIndex
, 1, bmp
.bmWidth
, height
, color
, ii
.hbmMask
);
2726 DeleteDC( hdcMask
);
2727 DeleteObject( color
);
2729 else ret
= add_with_alpha( himl
, hdcImage
, nIndex
, 1, bmp
.bmWidth
, bmp
.bmHeight
,
2730 ii
.hbmColor
, ii
.hbmMask
);
2732 DeleteDC( hdcImage
);
2733 DeleteObject (ii
.hbmMask
);
2734 if (ii
.hbmColor
) DeleteObject (ii
.hbmColor
);
2738 imagelist_point_from_index(himl
, nIndex
, &pt
);
2742 DrawIconEx( himl
->hdcImage
, pt
.x
, pt
.y
, hBestFitIcon
, himl
->cx
, himl
->cy
, 0, 0, DI_IMAGE
);
2743 PatBlt( himl
->hdcMask
, pt
.x
, pt
.y
, himl
->cx
, himl
->cy
, WHITENESS
);
2744 DrawIconEx( himl
->hdcMask
, pt
.x
, pt
.y
, hBestFitIcon
, himl
->cx
, himl
->cy
, 0, 0, DI_MASK
);
2748 COLORREF color
= himl
->clrBk
!= CLR_NONE
? himl
->clrBk
: comctl32_color
.clrWindow
;
2749 HBRUSH brush
= CreateSolidBrush( GetNearestColor( himl
->hdcImage
, color
));
2751 SelectObject( himl
->hdcImage
, brush
);
2752 PatBlt( himl
->hdcImage
, pt
.x
, pt
.y
, himl
->cx
, himl
->cy
, PATCOPY
);
2753 SelectObject( himl
->hdcImage
, GetStockObject(BLACK_BRUSH
) );
2754 DeleteObject( brush
);
2755 DrawIconEx( himl
->hdcImage
, pt
.x
, pt
.y
, hBestFitIcon
, himl
->cx
, himl
->cy
, 0, 0, DI_NORMAL
);
2759 DestroyIcon(hBestFitIcon
);
2761 TRACE("Insert index = %d, himl->cCurImage = %d\n", nIndex
, himl
->cCurImage
);
2766 /*************************************************************************
2767 * ImageList_SetBkColor [COMCTL32.@]
2769 * Sets the background color of an image list.
2772 * himl [I] handle to image list
2773 * clrBk [I] background color
2776 * Success: previous background color
2781 ImageList_SetBkColor (HIMAGELIST himl
, COLORREF clrBk
)
2785 if (!is_valid(himl
))
2788 clrOldBk
= himl
->clrBk
;
2789 himl
->clrBk
= clrBk
;
2794 /*************************************************************************
2795 * ImageList_SetDragCursorImage [COMCTL32.@]
2797 * Combines the specified image with the current drag image
2800 * himlDrag [I] handle to drag image list
2801 * iDrag [I] drag image index
2802 * dxHotspot [I] X position of the hot spot
2803 * dyHotspot [I] Y position of the hot spot
2810 * - The names dxHotspot, dyHotspot are misleading because they have nothing
2811 * to do with a hotspot but are only the offset of the origin of the new
2812 * image relative to the origin of the old image.
2814 * - When this function is called and the drag image is visible, a
2815 * short flickering occurs but this matches the Win9x behavior. It is
2816 * possible to fix the flickering using code like in ImageList_DragMove.
2820 ImageList_SetDragCursorImage (HIMAGELIST himlDrag
, INT iDrag
,
2821 INT dxHotspot
, INT dyHotspot
)
2823 HIMAGELIST himlTemp
;
2826 if (!is_valid(InternalDrag
.himl
) || !is_valid(himlDrag
))
2829 TRACE(" dxH=%d dyH=%d nX=%d nY=%d\n",
2830 dxHotspot
, dyHotspot
, InternalDrag
.dxHotspot
, InternalDrag
.dyHotspot
);
2832 visible
= InternalDrag
.bShow
;
2834 himlTemp
= ImageList_Merge (InternalDrag
.himlNoCursor
, 0, himlDrag
, iDrag
,
2835 dxHotspot
, dyHotspot
);
2838 /* hide the drag image */
2839 ImageList_DragShowNolock(FALSE
);
2841 if ((InternalDrag
.himl
->cx
!= himlTemp
->cx
) ||
2842 (InternalDrag
.himl
->cy
!= himlTemp
->cy
)) {
2843 /* the size of the drag image changed, invalidate the buffer */
2844 DeleteObject(InternalDrag
.hbmBg
);
2845 InternalDrag
.hbmBg
= 0;
2848 if (InternalDrag
.himl
!= InternalDrag
.himlNoCursor
)
2849 ImageList_Destroy (InternalDrag
.himl
);
2850 InternalDrag
.himl
= himlTemp
;
2853 /* show the drag image */
2854 ImageList_DragShowNolock(TRUE
);
2861 /*************************************************************************
2862 * ImageList_SetFilter [COMCTL32.@]
2864 * Sets a filter (or does something completely different)!!???
2865 * It removes 12 Bytes from the stack (3 Parameters).
2868 * himl [I] SHOULD be a handle to image list
2869 * i [I] COULD be an index?
2874 * Failure: FALSE ???
2877 * This is an UNDOCUMENTED function!!!!
2882 ImageList_SetFilter (HIMAGELIST himl
, INT i
, DWORD dwFilter
)
2884 FIXME("(%p 0x%x 0x%x):empty stub!\n", himl
, i
, dwFilter
);
2890 /*************************************************************************
2891 * ImageList_SetFlags [COMCTL32.@]
2893 * Sets the image list flags.
2896 * himl [I] Handle to image list
2897 * flags [I] Flags to set
2907 ImageList_SetFlags(HIMAGELIST himl
, DWORD flags
)
2909 FIXME("(%p %08x):empty stub\n", himl
, flags
);
2914 /*************************************************************************
2915 * ImageList_SetIconSize [COMCTL32.@]
2917 * Sets the image size of the bitmap and deletes all images.
2920 * himl [I] handle to image list
2921 * cx [I] image width
2922 * cy [I] image height
2930 ImageList_SetIconSize (HIMAGELIST himl
, INT cx
, INT cy
)
2935 if (!is_valid(himl
))
2938 /* remove all images */
2939 himl
->cMaxImage
= himl
->cInitial
+ 1;
2940 himl
->cCurImage
= 0;
2944 /* initialize overlay mask indices */
2945 for (nCount
= 0; nCount
< MAX_OVERLAYIMAGE
; nCount
++)
2946 himl
->nOvlIdx
[nCount
] = -1;
2948 hbmNew
= ImageList_CreateImage(himl
->hdcImage
, himl
, himl
->cMaxImage
);
2949 SelectObject (himl
->hdcImage
, hbmNew
);
2950 DeleteObject (himl
->hbmImage
);
2951 himl
->hbmImage
= hbmNew
;
2953 if (himl
->hbmMask
) {
2955 imagelist_get_bitmap_size(himl
, himl
->cMaxImage
, &sz
);
2956 hbmNew
= CreateBitmap (sz
.cx
, sz
.cy
, 1, 1, NULL
);
2957 SelectObject (himl
->hdcMask
, hbmNew
);
2958 DeleteObject (himl
->hbmMask
);
2959 himl
->hbmMask
= hbmNew
;
2966 /*************************************************************************
2967 * ImageList_SetImageCount [COMCTL32.@]
2969 * Resizes an image list to the specified number of images.
2972 * himl [I] handle to image list
2973 * iImageCount [I] number of images in the image list
2981 ImageList_SetImageCount (HIMAGELIST himl
, UINT iImageCount
)
2984 HBITMAP hbmNewBitmap
, hbmOld
;
2985 INT nNewCount
, nCopyCount
;
2987 TRACE("%p %d\n",himl
,iImageCount
);
2989 if (!is_valid(himl
))
2992 nNewCount
= iImageCount
+ 1;
2993 nCopyCount
= min(himl
->cCurImage
, iImageCount
);
2995 hdcBitmap
= CreateCompatibleDC (0);
2997 hbmNewBitmap
= ImageList_CreateImage(hdcBitmap
, himl
, nNewCount
);
2999 if (hbmNewBitmap
!= 0)
3001 hbmOld
= SelectObject (hdcBitmap
, hbmNewBitmap
);
3002 imagelist_copy_images( himl
, himl
->hdcImage
, hdcBitmap
, 0, nCopyCount
, 0 );
3003 SelectObject (hdcBitmap
, hbmOld
);
3005 /* FIXME: delete 'empty' image space? */
3007 SelectObject (himl
->hdcImage
, hbmNewBitmap
);
3008 DeleteObject (himl
->hbmImage
);
3009 himl
->hbmImage
= hbmNewBitmap
;
3012 ERR("Could not create new image bitmap!\n");
3017 imagelist_get_bitmap_size( himl
, nNewCount
, &sz
);
3018 hbmNewBitmap
= CreateBitmap (sz
.cx
, sz
.cy
, 1, 1, NULL
);
3019 if (hbmNewBitmap
!= 0)
3021 hbmOld
= SelectObject (hdcBitmap
, hbmNewBitmap
);
3022 imagelist_copy_images( himl
, himl
->hdcMask
, hdcBitmap
, 0, nCopyCount
, 0 );
3023 SelectObject (hdcBitmap
, hbmOld
);
3025 /* FIXME: delete 'empty' image space? */
3027 SelectObject (himl
->hdcMask
, hbmNewBitmap
);
3028 DeleteObject (himl
->hbmMask
);
3029 himl
->hbmMask
= hbmNewBitmap
;
3032 ERR("Could not create new mask bitmap!\n");
3035 DeleteDC (hdcBitmap
);
3037 if (himl
->has_alpha
)
3039 char *new_alpha
= HeapReAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, himl
->has_alpha
, nNewCount
);
3040 if (new_alpha
) himl
->has_alpha
= new_alpha
;
3043 HeapFree( GetProcessHeap(), 0, himl
->has_alpha
);
3044 himl
->has_alpha
= NULL
;
3048 /* Update max image count and current image count */
3049 himl
->cMaxImage
= nNewCount
;
3050 himl
->cCurImage
= iImageCount
;
3056 /*************************************************************************
3057 * ImageList_SetOverlayImage [COMCTL32.@]
3059 * Assigns an overlay mask index to an existing image in an image list.
3062 * himl [I] handle to image list
3063 * iImage [I] image index
3064 * iOverlay [I] overlay mask index
3072 ImageList_SetOverlayImage (HIMAGELIST himl
, INT iImage
, INT iOverlay
)
3074 if (!is_valid(himl
))
3076 if ((iOverlay
< 1) || (iOverlay
> MAX_OVERLAYIMAGE
))
3078 if ((iImage
!=-1) && ((iImage
< 0) || (iImage
> himl
->cCurImage
)))
3080 himl
->nOvlIdx
[iOverlay
- 1] = iImage
;
3086 /* helper for ImageList_Write - write bitmap to pstm
3087 * currently everything is written as 24 bit RGB, except masks
3089 static BOOL
_write_bitmap(HBITMAP hBitmap
, IStream
*pstm
)
3091 LPBITMAPFILEHEADER bmfh
;
3092 LPBITMAPINFOHEADER bmih
;
3093 LPBYTE data
= NULL
, lpBits
;
3095 INT bitCount
, sizeImage
, offBits
, totalSize
;
3097 BOOL result
= FALSE
;
3099 if (!GetObjectW(hBitmap
, sizeof(BITMAP
), &bm
))
3102 bitCount
= bm
.bmBitsPixel
;
3103 sizeImage
= get_dib_stride(bm
.bmWidth
, bitCount
) * bm
.bmHeight
;
3105 totalSize
= sizeof(BITMAPFILEHEADER
) + sizeof(BITMAPINFOHEADER
);
3107 totalSize
+= (1 << bitCount
) * sizeof(RGBQUAD
);
3108 offBits
= totalSize
;
3109 totalSize
+= sizeImage
;
3111 data
= Alloc(totalSize
);
3112 bmfh
= (LPBITMAPFILEHEADER
)data
;
3113 bmih
= (LPBITMAPINFOHEADER
)(data
+ sizeof(BITMAPFILEHEADER
));
3114 lpBits
= data
+ offBits
;
3116 /* setup BITMAPFILEHEADER */
3117 bmfh
->bfType
= (('M' << 8) | 'B');
3118 bmfh
->bfSize
= offBits
;
3119 bmfh
->bfReserved1
= 0;
3120 bmfh
->bfReserved2
= 0;
3121 bmfh
->bfOffBits
= offBits
;
3123 /* setup BITMAPINFOHEADER */
3124 bmih
->biSize
= sizeof(BITMAPINFOHEADER
);
3125 bmih
->biWidth
= bm
.bmWidth
;
3126 bmih
->biHeight
= bm
.bmHeight
;
3128 bmih
->biBitCount
= bitCount
;
3129 bmih
->biCompression
= BI_RGB
;
3130 bmih
->biSizeImage
= sizeImage
;
3131 bmih
->biXPelsPerMeter
= 0;
3132 bmih
->biYPelsPerMeter
= 0;
3133 bmih
->biClrUsed
= 0;
3134 bmih
->biClrImportant
= 0;
3137 result
= GetDIBits(xdc
, hBitmap
, 0, bm
.bmHeight
, lpBits
, (BITMAPINFO
*)bmih
, DIB_RGB_COLORS
) == bm
.bmHeight
;
3142 TRACE("width %u, height %u, planes %u, bpp %u\n",
3143 bmih
->biWidth
, bmih
->biHeight
,
3144 bmih
->biPlanes
, bmih
->biBitCount
);
3146 if(FAILED(IStream_Write(pstm
, data
, totalSize
, NULL
)))
3158 /*************************************************************************
3159 * ImageList_Write [COMCTL32.@]
3161 * Writes an image list to a stream.
3164 * himl [I] handle to image list
3165 * pstm [O] Pointer to a stream.
3175 BOOL WINAPI
ImageList_Write(HIMAGELIST himl
, IStream
*pstm
)
3180 TRACE("%p %p\n", himl
, pstm
);
3182 if (!is_valid(himl
))
3185 ilHead
.usMagic
= (('L' << 8) | 'I');
3186 ilHead
.usVersion
= 0x101;
3187 ilHead
.cCurImage
= himl
->cCurImage
;
3188 ilHead
.cMaxImage
= himl
->cMaxImage
;
3189 ilHead
.cGrow
= himl
->cGrow
;
3190 ilHead
.cx
= himl
->cx
;
3191 ilHead
.cy
= himl
->cy
;
3192 ilHead
.bkcolor
= himl
->clrBk
;
3193 ilHead
.flags
= himl
->flags
;
3194 for(i
= 0; i
< 4; i
++) {
3195 ilHead
.ovls
[i
] = himl
->nOvlIdx
[i
];
3198 TRACE("cx %u, cy %u, flags 0x04%x, cCurImage %u, cMaxImage %u\n",
3199 ilHead
.cx
, ilHead
.cy
, ilHead
.flags
, ilHead
.cCurImage
, ilHead
.cMaxImage
);
3201 if(FAILED(IStream_Write(pstm
, &ilHead
, sizeof(ILHEAD
), NULL
)))
3204 /* write the bitmap */
3205 if(!_write_bitmap(himl
->hbmImage
, pstm
))
3208 /* write the mask if we have one */
3209 if(himl
->flags
& ILC_MASK
) {
3210 if(!_write_bitmap(himl
->hbmMask
, pstm
))
3218 static HBITMAP
ImageList_CreateImage(HDC hdc
, HIMAGELIST himl
, UINT count
)
3220 HBITMAP hbmNewBitmap
;
3221 UINT ilc
= (himl
->flags
& 0xFE);
3224 imagelist_get_bitmap_size( himl
, count
, &sz
);
3226 if ((ilc
>= ILC_COLOR4
&& ilc
<= ILC_COLOR32
) || ilc
== ILC_COLOR
)
3228 char buffer
[sizeof(BITMAPINFOHEADER
) + 256 * sizeof(RGBQUAD
)];
3229 BITMAPINFO
*bmi
= (BITMAPINFO
*)buffer
;
3231 TRACE("Creating DIBSection %d x %d, %d Bits per Pixel\n",
3232 sz
.cx
, sz
.cy
, himl
->uBitsPixel
);
3234 memset( buffer
, 0, sizeof(buffer
) );
3235 bmi
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
3236 bmi
->bmiHeader
.biWidth
= sz
.cx
;
3237 bmi
->bmiHeader
.biHeight
= sz
.cy
;
3238 bmi
->bmiHeader
.biPlanes
= 1;
3239 bmi
->bmiHeader
.biBitCount
= himl
->uBitsPixel
;
3240 bmi
->bmiHeader
.biCompression
= BI_RGB
;
3242 if (himl
->uBitsPixel
<= ILC_COLOR8
)
3244 if (!himl
->color_table_set
)
3246 /* retrieve the default color map */
3247 HBITMAP tmp
= CreateBitmap( 1, 1, 1, 1, NULL
);
3248 GetDIBits( hdc
, tmp
, 0, 0, NULL
, bmi
, DIB_RGB_COLORS
);
3249 DeleteObject( tmp
);
3250 if (ilc
== ILC_COLOR4
)
3253 tmp
= bmi
->bmiColors
[7];
3254 bmi
->bmiColors
[7] = bmi
->bmiColors
[8];
3255 bmi
->bmiColors
[8] = tmp
;
3260 GetDIBColorTable(himl
->hdcImage
, 0, 1 << himl
->uBitsPixel
, bmi
->bmiColors
);
3263 hbmNewBitmap
= CreateDIBSection(hdc
, bmi
, DIB_RGB_COLORS
, NULL
, 0, 0);
3265 else /*if (ilc == ILC_COLORDDB)*/
3267 TRACE("Creating Bitmap: %d Bits per Pixel\n", himl
->uBitsPixel
);
3269 hbmNewBitmap
= CreateBitmap (sz
.cx
, sz
.cy
, 1, himl
->uBitsPixel
, NULL
);
3271 TRACE("returning %p\n", hbmNewBitmap
);
3272 return hbmNewBitmap
;
3275 /*************************************************************************
3276 * ImageList_SetColorTable [COMCTL32.@]
3278 * Sets the color table of an image list.
3281 * himl [I] Handle to the image list.
3282 * uStartIndex [I] The first index to set.
3283 * cEntries [I] Number of entries to set.
3284 * prgb [I] New color information for color table for the image list.
3287 * Success: Number of entries in the table that were set.
3291 * ImageList_Create(), SetDIBColorTable()
3295 ImageList_SetColorTable(HIMAGELIST himl
, UINT uStartIndex
, UINT cEntries
, const RGBQUAD
*prgb
)
3297 TRACE("(%p, %d, %d, %p)\n", himl
, uStartIndex
, cEntries
, prgb
);
3298 himl
->color_table_set
= TRUE
;
3299 return SetDIBColorTable(himl
->hdcImage
, uStartIndex
, cEntries
, prgb
);
3302 /*************************************************************************
3303 * ImageList_CoCreateInstance [COMCTL32.@]
3305 * Creates a new imagelist instance and returns an interface pointer to it.
3308 * rclsid [I] A reference to the CLSID (CLSID_ImageList).
3309 * punkOuter [I] Pointer to IUnknown interface for aggregation, if desired
3310 * riid [I] Identifier of the requested interface.
3311 * ppv [O] Returns the address of the pointer requested, or NULL.
3315 * Failure: Error value.
3318 ImageList_CoCreateInstance (REFCLSID rclsid
, const IUnknown
*punkOuter
, REFIID riid
, void **ppv
)
3320 TRACE("(%s,%p,%s,%p)\n", debugstr_guid(rclsid
), punkOuter
, debugstr_guid(riid
), ppv
);
3322 if (!IsEqualCLSID(&CLSID_ImageList
, rclsid
))
3323 return E_NOINTERFACE
;
3325 return ImageListImpl_CreateInstance(punkOuter
, riid
, ppv
);
3329 /*************************************************************************
3330 * IImageList implementation
3333 static HRESULT WINAPI
ImageListImpl_QueryInterface(IImageList2
*iface
,
3334 REFIID iid
, void **ppv
)
3336 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3338 TRACE("(%p,%s,%p)\n", iface
, debugstr_guid(iid
), ppv
);
3340 if (!ppv
) return E_INVALIDARG
;
3342 if (IsEqualIID(&IID_IUnknown
, iid
) ||
3343 IsEqualIID(&IID_IImageList
, iid
) ||
3344 IsEqualIID(&IID_IImageList2
, iid
))
3346 *ppv
= &imgl
->IImageList2_iface
;
3351 return E_NOINTERFACE
;
3354 IImageList2_AddRef(iface
);
3358 static ULONG WINAPI
ImageListImpl_AddRef(IImageList2
*iface
)
3360 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3361 ULONG ref
= InterlockedIncrement(&imgl
->ref
);
3363 TRACE("(%p) refcount=%u\n", iface
, ref
);
3367 static ULONG WINAPI
ImageListImpl_Release(IImageList2
*iface
)
3369 HIMAGELIST This
= impl_from_IImageList2(iface
);
3370 ULONG ref
= InterlockedDecrement(&This
->ref
);
3372 TRACE("(%p) refcount=%u\n", iface
, ref
);
3376 /* delete image bitmaps */
3377 if (This
->hbmImage
) DeleteObject (This
->hbmImage
);
3378 if (This
->hbmMask
) DeleteObject (This
->hbmMask
);
3380 /* delete image & mask DCs */
3381 if (This
->hdcImage
) DeleteDC (This
->hdcImage
);
3382 if (This
->hdcMask
) DeleteDC (This
->hdcMask
);
3384 /* delete blending brushes */
3385 if (This
->hbrBlend25
) DeleteObject (This
->hbrBlend25
);
3386 if (This
->hbrBlend50
) DeleteObject (This
->hbrBlend50
);
3388 This
->IImageList2_iface
.lpVtbl
= NULL
;
3389 HeapFree(GetProcessHeap(), 0, This
->has_alpha
);
3390 HeapFree(GetProcessHeap(), 0, This
);
3396 static HRESULT WINAPI
ImageListImpl_Add(IImageList2
*iface
, HBITMAP hbmImage
,
3397 HBITMAP hbmMask
, int *pi
)
3399 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3405 ret
= ImageList_Add(imgl
, hbmImage
, hbmMask
);
3414 static HRESULT WINAPI
ImageListImpl_ReplaceIcon(IImageList2
*iface
, int i
,
3415 HICON hicon
, int *pi
)
3417 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3423 ret
= ImageList_ReplaceIcon(imgl
, i
, hicon
);
3432 static HRESULT WINAPI
ImageListImpl_SetOverlayImage(IImageList2
*iface
,
3433 int iImage
, int iOverlay
)
3435 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3436 return ImageList_SetOverlayImage(imgl
, iImage
, iOverlay
) ? S_OK
: E_FAIL
;
3439 static HRESULT WINAPI
ImageListImpl_Replace(IImageList2
*iface
, int i
,
3440 HBITMAP hbmImage
, HBITMAP hbmMask
)
3442 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3443 return ImageList_Replace(imgl
, i
, hbmImage
, hbmMask
) ? S_OK
: E_FAIL
;
3446 static HRESULT WINAPI
ImageListImpl_AddMasked(IImageList2
*iface
, HBITMAP hbmImage
,
3447 COLORREF crMask
, int *pi
)
3449 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3455 ret
= ImageList_AddMasked(imgl
, hbmImage
, crMask
);
3464 static HRESULT WINAPI
ImageListImpl_Draw(IImageList2
*iface
,
3465 IMAGELISTDRAWPARAMS
*pimldp
)
3467 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3468 HIMAGELIST old_himl
;
3471 /* As far as I can tell, Windows simply ignores the contents of pimldp->himl
3472 so we shall simulate the same */
3473 old_himl
= pimldp
->himl
;
3474 pimldp
->himl
= imgl
;
3476 ret
= ImageList_DrawIndirect(pimldp
);
3478 pimldp
->himl
= old_himl
;
3479 return ret
? S_OK
: E_INVALIDARG
;
3482 static HRESULT WINAPI
ImageListImpl_Remove(IImageList2
*iface
, int i
)
3484 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3485 return (ImageList_Remove(imgl
, i
) == 0) ? E_INVALIDARG
: S_OK
;
3488 static HRESULT WINAPI
ImageListImpl_GetIcon(IImageList2
*iface
, int i
, UINT flags
,
3491 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3497 hIcon
= ImageList_GetIcon(imgl
, i
, flags
);
3506 static HRESULT WINAPI
ImageListImpl_GetImageInfo(IImageList2
*iface
, int i
,
3507 IMAGEINFO
*pImageInfo
)
3509 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3510 return ImageList_GetImageInfo(imgl
, i
, pImageInfo
) ? S_OK
: E_FAIL
;
3513 static HRESULT WINAPI
ImageListImpl_Copy(IImageList2
*iface
, int dst_index
,
3514 IUnknown
*unk_src
, int src_index
, UINT flags
)
3516 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3517 IImageList
*src
= NULL
;
3523 /* TODO: Add test for IID_ImageList2 too */
3524 if (FAILED(IUnknown_QueryInterface(unk_src
, &IID_IImageList
,
3528 if (ImageList_Copy(imgl
, dst_index
, (HIMAGELIST
) src
, src_index
, flags
))
3533 IImageList_Release(src
);
3537 static HRESULT WINAPI
ImageListImpl_Merge(IImageList2
*iface
, int i1
,
3538 IUnknown
*punk2
, int i2
, int dx
, int dy
, REFIID riid
, void **ppv
)
3540 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3541 IImageList
*iml2
= NULL
;
3543 HRESULT ret
= E_FAIL
;
3545 TRACE("(%p)->(%d %p %d %d %d %s %p)\n", iface
, i1
, punk2
, i2
, dx
, dy
, debugstr_guid(riid
), ppv
);
3547 /* TODO: Add test for IID_ImageList2 too */
3548 if (FAILED(IUnknown_QueryInterface(punk2
, &IID_IImageList
,
3552 merged
= ImageList_Merge(imgl
, i1
, (HIMAGELIST
) iml2
, i2
, dx
, dy
);
3554 /* Get the interface for the new image list */
3557 ret
= HIMAGELIST_QueryInterface(merged
, riid
, ppv
);
3558 ImageList_Destroy(merged
);
3561 IImageList_Release(iml2
);
3565 static HRESULT WINAPI
ImageListImpl_Clone(IImageList2
*iface
, REFIID riid
, void **ppv
)
3567 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3569 HRESULT ret
= E_FAIL
;
3571 TRACE("(%p)->(%s %p)\n", iface
, debugstr_guid(riid
), ppv
);
3573 clone
= ImageList_Duplicate(imgl
);
3575 /* Get the interface for the new image list */
3578 ret
= HIMAGELIST_QueryInterface(clone
, riid
, ppv
);
3579 ImageList_Destroy(clone
);
3585 static HRESULT WINAPI
ImageListImpl_GetImageRect(IImageList2
*iface
, int i
,
3588 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3594 if (!ImageList_GetImageInfo(imgl
, i
, &info
))
3597 *prc
= info
.rcImage
;
3602 static HRESULT WINAPI
ImageListImpl_GetIconSize(IImageList2
*iface
, int *cx
,
3605 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3606 return ImageList_GetIconSize(imgl
, cx
, cy
) ? S_OK
: E_INVALIDARG
;
3609 static HRESULT WINAPI
ImageListImpl_SetIconSize(IImageList2
*iface
, int cx
,
3612 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3613 return ImageList_SetIconSize(imgl
, cx
, cy
) ? S_OK
: E_FAIL
;
3616 static HRESULT WINAPI
ImageListImpl_GetImageCount(IImageList2
*iface
, int *pi
)
3618 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3619 *pi
= ImageList_GetImageCount(imgl
);
3623 static HRESULT WINAPI
ImageListImpl_SetImageCount(IImageList2
*iface
, UINT count
)
3625 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3626 return ImageList_SetImageCount(imgl
, count
) ? S_OK
: E_FAIL
;
3629 static HRESULT WINAPI
ImageListImpl_SetBkColor(IImageList2
*iface
, COLORREF clrBk
,
3632 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3633 *pclr
= ImageList_SetBkColor(imgl
, clrBk
);
3637 static HRESULT WINAPI
ImageListImpl_GetBkColor(IImageList2
*iface
, COLORREF
*pclr
)
3639 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3640 *pclr
= ImageList_GetBkColor(imgl
);
3644 static HRESULT WINAPI
ImageListImpl_BeginDrag(IImageList2
*iface
, int iTrack
,
3645 int dxHotspot
, int dyHotspot
)
3647 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3648 return ImageList_BeginDrag(imgl
, iTrack
, dxHotspot
, dyHotspot
) ? S_OK
: E_FAIL
;
3651 static HRESULT WINAPI
ImageListImpl_EndDrag(IImageList2
*iface
)
3653 ImageList_EndDrag();
3657 static HRESULT WINAPI
ImageListImpl_DragEnter(IImageList2
*iface
, HWND hwndLock
,
3660 return ImageList_DragEnter(hwndLock
, x
, y
) ? S_OK
: E_FAIL
;
3663 static HRESULT WINAPI
ImageListImpl_DragLeave(IImageList2
*iface
, HWND hwndLock
)
3665 return ImageList_DragLeave(hwndLock
) ? S_OK
: E_FAIL
;
3668 static HRESULT WINAPI
ImageListImpl_DragMove(IImageList2
*iface
, int x
, int y
)
3670 return ImageList_DragMove(x
, y
) ? S_OK
: E_FAIL
;
3673 static HRESULT WINAPI
ImageListImpl_SetDragCursorImage(IImageList2
*iface
,
3674 IUnknown
*punk
, int iDrag
, int dxHotspot
, int dyHotspot
)
3676 IImageList
*iml2
= NULL
;
3682 /* TODO: Add test for IID_ImageList2 too */
3683 if (FAILED(IUnknown_QueryInterface(punk
, &IID_IImageList
,
3687 ret
= ImageList_SetDragCursorImage((HIMAGELIST
) iml2
, iDrag
, dxHotspot
,
3690 IImageList_Release(iml2
);
3692 return ret
? S_OK
: E_FAIL
;
3695 static HRESULT WINAPI
ImageListImpl_DragShowNolock(IImageList2
*iface
, BOOL fShow
)
3697 return ImageList_DragShowNolock(fShow
) ? S_OK
: E_FAIL
;
3700 static HRESULT WINAPI
ImageListImpl_GetDragImage(IImageList2
*iface
, POINT
*ppt
,
3701 POINT
*pptHotspot
, REFIID riid
, PVOID
*ppv
)
3703 HRESULT ret
= E_FAIL
;
3709 hNew
= ImageList_GetDragImage(ppt
, pptHotspot
);
3711 /* Get the interface for the new image list */
3714 IImageList
*idrag
= (IImageList
*)hNew
;
3716 ret
= HIMAGELIST_QueryInterface(hNew
, riid
, ppv
);
3717 IImageList_Release(idrag
);
3723 static HRESULT WINAPI
ImageListImpl_GetItemFlags(IImageList2
*iface
, int i
,
3726 FIXME("STUB: %p %d %p\n", iface
, i
, dwFlags
);
3730 static HRESULT WINAPI
ImageListImpl_GetOverlayImage(IImageList2
*iface
, int iOverlay
,
3733 HIMAGELIST This
= impl_from_IImageList2(iface
);
3736 if ((iOverlay
< 0) || (iOverlay
> This
->cCurImage
))
3739 for (i
= 0; i
< MAX_OVERLAYIMAGE
; i
++)
3741 if (This
->nOvlIdx
[i
] == iOverlay
)
3751 static HRESULT WINAPI
ImageListImpl_Resize(IImageList2
*iface
, INT cx
, INT cy
)
3753 FIXME("(%p)->(%d %d): stub\n", iface
, cx
, cy
);
3757 static HRESULT WINAPI
ImageListImpl_GetOriginalSize(IImageList2
*iface
, INT image
, DWORD flags
, INT
*cx
, INT
*cy
)
3759 FIXME("(%p)->(%d %x %p %p): stub\n", iface
, image
, flags
, cx
, cy
);
3763 static HRESULT WINAPI
ImageListImpl_SetOriginalSize(IImageList2
*iface
, INT image
, INT cx
, INT cy
)
3765 FIXME("(%p)->(%d %d %d): stub\n", iface
, image
, cx
, cy
);
3769 static HRESULT WINAPI
ImageListImpl_SetCallback(IImageList2
*iface
, IUnknown
*callback
)
3771 FIXME("(%p)->(%p): stub\n", iface
, callback
);
3775 static HRESULT WINAPI
ImageListImpl_GetCallback(IImageList2
*iface
, REFIID riid
, void **ppv
)
3777 FIXME("(%p)->(%s %p): stub\n", iface
, debugstr_guid(riid
), ppv
);
3781 static HRESULT WINAPI
ImageListImpl_ForceImagePresent(IImageList2
*iface
, INT image
, DWORD flags
)
3783 FIXME("(%p)->(%d %x): stub\n", iface
, image
, flags
);
3787 static HRESULT WINAPI
ImageListImpl_DiscardImages(IImageList2
*iface
, INT first_image
, INT last_image
, DWORD flags
)
3789 FIXME("(%p)->(%d %d %x): stub\n", iface
, first_image
, last_image
, flags
);
3793 static HRESULT WINAPI
ImageListImpl_PreloadImages(IImageList2
*iface
, IMAGELISTDRAWPARAMS
*params
)
3795 FIXME("(%p)->(%p): stub\n", iface
, params
);
3799 static HRESULT WINAPI
ImageListImpl_GetStatistics(IImageList2
*iface
, IMAGELISTSTATS
*stats
)
3801 FIXME("(%p)->(%p): stub\n", iface
, stats
);
3805 static HRESULT WINAPI
ImageListImpl_Initialize(IImageList2
*iface
, INT cx
, INT cy
, UINT flags
, INT initial
, INT grow
)
3807 FIXME("(%p)->(%d %d %d %d %d): stub\n", iface
, cx
, cy
, flags
, initial
, grow
);
3811 static HRESULT WINAPI
ImageListImpl_Replace2(IImageList2
*iface
, INT i
, HBITMAP image
, HBITMAP mask
, IUnknown
*unk
, DWORD flags
)
3813 FIXME("(%p)->(%d %p %p %p %x): stub\n", iface
, i
, image
, mask
, unk
, flags
);
3817 static HRESULT WINAPI
ImageListImpl_ReplaceFromImageList(IImageList2
*iface
, INT i
, IImageList
*imagelist
, INT src
,
3818 IUnknown
*unk
, DWORD flags
)
3820 FIXME("(%p)->(%d %p %d %p %x): stub\n", iface
, i
, imagelist
, src
, unk
, flags
);
3824 static const IImageList2Vtbl ImageListImpl_Vtbl
= {
3825 ImageListImpl_QueryInterface
,
3826 ImageListImpl_AddRef
,
3827 ImageListImpl_Release
,
3829 ImageListImpl_ReplaceIcon
,
3830 ImageListImpl_SetOverlayImage
,
3831 ImageListImpl_Replace
,
3832 ImageListImpl_AddMasked
,
3834 ImageListImpl_Remove
,
3835 ImageListImpl_GetIcon
,
3836 ImageListImpl_GetImageInfo
,
3838 ImageListImpl_Merge
,
3839 ImageListImpl_Clone
,
3840 ImageListImpl_GetImageRect
,
3841 ImageListImpl_GetIconSize
,
3842 ImageListImpl_SetIconSize
,
3843 ImageListImpl_GetImageCount
,
3844 ImageListImpl_SetImageCount
,
3845 ImageListImpl_SetBkColor
,
3846 ImageListImpl_GetBkColor
,
3847 ImageListImpl_BeginDrag
,
3848 ImageListImpl_EndDrag
,
3849 ImageListImpl_DragEnter
,
3850 ImageListImpl_DragLeave
,
3851 ImageListImpl_DragMove
,
3852 ImageListImpl_SetDragCursorImage
,
3853 ImageListImpl_DragShowNolock
,
3854 ImageListImpl_GetDragImage
,
3855 ImageListImpl_GetItemFlags
,
3856 ImageListImpl_GetOverlayImage
,
3857 ImageListImpl_Resize
,
3858 ImageListImpl_GetOriginalSize
,
3859 ImageListImpl_SetOriginalSize
,
3860 ImageListImpl_SetCallback
,
3861 ImageListImpl_GetCallback
,
3862 ImageListImpl_ForceImagePresent
,
3863 ImageListImpl_DiscardImages
,
3864 ImageListImpl_PreloadImages
,
3865 ImageListImpl_GetStatistics
,
3866 ImageListImpl_Initialize
,
3867 ImageListImpl_Replace2
,
3868 ImageListImpl_ReplaceFromImageList
3871 static BOOL
is_valid(HIMAGELIST himl
)
3876 valid
= himl
&& himl
->IImageList2_iface
.lpVtbl
== &ImageListImpl_Vtbl
;
3886 /*************************************************************************
3887 * HIMAGELIST_QueryInterface [COMCTL32.@]
3889 * Returns a pointer to an IImageList or IImageList2 object for the given
3893 * himl [I] Image list handle.
3894 * riid [I] Identifier of the requested interface.
3895 * ppv [O] Returns the address of the pointer requested, or NULL.
3899 * Failure: Error value.
3902 HIMAGELIST_QueryInterface (HIMAGELIST himl
, REFIID riid
, void **ppv
)
3904 TRACE("(%p,%s,%p)\n", himl
, debugstr_guid(riid
), ppv
);
3905 return IImageList2_QueryInterface((IImageList2
*) himl
, riid
, ppv
);
3908 static HRESULT
ImageListImpl_CreateInstance(const IUnknown
*pUnkOuter
, REFIID iid
, void** ppv
)
3913 TRACE("(%p,%s,%p)\n", pUnkOuter
, debugstr_guid(iid
), ppv
);
3917 if (pUnkOuter
) return CLASS_E_NOAGGREGATION
;
3919 This
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(struct _IMAGELIST
));
3920 if (!This
) return E_OUTOFMEMORY
;
3922 This
->IImageList2_iface
.lpVtbl
= &ImageListImpl_Vtbl
;
3925 ret
= IImageList2_QueryInterface(&This
->IImageList2_iface
, iid
, ppv
);
3926 IImageList2_Release(&This
->IImageList2_iface
);