2 * ImageList implementation
4 * Copyright 1998 Eric Kohl
5 * Copyright 2000 Jason Mawdsley
6 * Copyright 2001, 2004 Michael Stefaniuc
7 * Copyright 2001 Charles Loep for CodeWeavers
8 * Copyright 2002 Dimitrie O. Paun
9 * Copyright 2009 Owen Rudge for CodeWeavers
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public
13 * License as published by the Free Software Foundation; either
14 * version 2.1 of the License, or (at your option) any later version.
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with this library; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
27 * This code was audited for completeness against the documented features
28 * of Comctl32.dll version 6.0 on Sep. 12, 2002, by Dimitrie O. Paun.
30 * Unless otherwise noted, we believe this code to be complete, as per
31 * the specification mentioned above.
32 * If you discover missing features, or bugs, please note them below.
35 * - Add support for ILD_PRESERVEALPHA, ILD_SCALE, ILD_DPISCALE
36 * - Add support for ILS_GLOW, ILS_SHADOW, ILS_SATURATE
37 * - Thread-safe locking
54 #include "commoncontrols.h"
55 #include "wine/debug.h"
56 #include "wine/exception.h"
58 WINE_DEFAULT_DEBUG_CHANNEL(imagelist
);
60 #define MAX_OVERLAYIMAGE 15
64 IImageList2 IImageList2_iface
; /* 00: IImageList vtable */
65 INT cCurImage
; /* 04: ImageCount */
66 INT cMaxImage
; /* 08: maximages */
67 INT cGrow
; /* 0C: cGrow */
71 UINT flags
; /* 1C: flags */
72 COLORREF clrFg
; /* 20: foreground color */
73 COLORREF clrBk
; /* 24: background color */
76 HBITMAP hbmImage
; /* 28: images Bitmap */
77 HBITMAP hbmMask
; /* 2C: masks Bitmap */
78 HDC hdcImage
; /* 30: images MemDC */
79 HDC hdcMask
; /* 34: masks MemDC */
80 INT nOvlIdx
[MAX_OVERLAYIMAGE
]; /* 38: overlay images index */
82 /* not yet found out */
90 LONG ref
; /* reference count */
93 #define IMAGELIST_MAGIC 0x53414D58
95 /* Header used by ImageList_Read() and ImageList_Write() */
97 typedef struct _ILHEAD
112 /* internal image list data used for Drag & Drop operations */
117 HIMAGELIST himlNoCursor
;
118 /* position of the drag image relative to the window */
121 /* offset of the hotspot relative to the origin of the image */
124 /* is the drag image visible */
126 /* saved background */
130 static INTERNALDRAG InternalDrag
= { 0, 0, 0, 0, 0, 0, 0, FALSE
, 0 };
132 static inline HIMAGELIST
impl_from_IImageList2(IImageList2
*iface
)
134 return CONTAINING_RECORD(iface
, struct _IMAGELIST
, IImageList2_iface
);
137 static HBITMAP
ImageList_CreateImage(HDC hdc
, HIMAGELIST himl
, UINT count
);
138 static HRESULT
ImageListImpl_CreateInstance(const IUnknown
*pUnkOuter
, REFIID iid
, void** ppv
);
139 static BOOL
is_valid(HIMAGELIST himl
);
142 * An imagelist with N images is tiled like this:
154 static inline UINT
imagelist_height( UINT count
)
156 return ((count
+ TILE_COUNT
- 1)/TILE_COUNT
);
159 static inline void imagelist_point_from_index( HIMAGELIST himl
, UINT index
, LPPOINT pt
)
161 pt
->x
= (index
%TILE_COUNT
) * himl
->cx
;
162 pt
->y
= (index
/TILE_COUNT
) * himl
->cy
;
165 static inline void imagelist_get_bitmap_size( HIMAGELIST himl
, UINT count
, SIZE
*sz
)
167 sz
->cx
= himl
->cx
* TILE_COUNT
;
168 sz
->cy
= imagelist_height( count
) * himl
->cy
;
171 static inline int get_dib_stride( int width
, int bpp
)
173 return ((width
* bpp
+ 31) >> 3) & ~3;
176 static inline int get_dib_image_size( const BITMAPINFO
*info
)
178 return get_dib_stride( info
->bmiHeader
.biWidth
, info
->bmiHeader
.biBitCount
)
179 * abs( info
->bmiHeader
.biHeight
);
183 * imagelist_copy_images()
185 * Copies a block of count images from offset src in the list to offset dest.
186 * Images are copied a row at at time. Assumes hdcSrc and hdcDest are different.
188 static inline void imagelist_copy_images( HIMAGELIST himl
, HDC hdcSrc
, HDC hdcDest
,
189 UINT src
, UINT count
, UINT dest
)
195 for ( i
=0; i
<TILE_COUNT
; i
++ )
197 imagelist_point_from_index( himl
, src
+i
, &ptSrc
);
198 imagelist_point_from_index( himl
, dest
+i
, &ptDest
);
200 sz
.cy
= himl
->cy
* imagelist_height( count
- i
);
202 BitBlt( hdcDest
, ptDest
.x
, ptDest
.y
, sz
.cx
, sz
.cy
,
203 hdcSrc
, ptSrc
.x
, ptSrc
.y
, SRCCOPY
);
207 static void add_dib_bits( HIMAGELIST himl
, int pos
, int count
, int width
, int height
,
208 BITMAPINFO
*info
, BITMAPINFO
*mask_info
, DWORD
*bits
, BYTE
*mask_bits
)
212 int stride
= info
->bmiHeader
.biWidth
;
213 int mask_stride
= (info
->bmiHeader
.biWidth
+ 31) / 32 * 4;
215 for (n
= 0; n
< count
; n
++)
217 BOOL has_alpha
= FALSE
;
219 imagelist_point_from_index( himl
, pos
+ n
, &pt
);
221 /* check if bitmap has an alpha channel */
222 for (i
= 0; i
< height
&& !has_alpha
; i
++)
223 for (j
= n
* width
; j
< (n
+ 1) * width
; j
++)
224 if ((has_alpha
= ((bits
[i
* stride
+ j
] & 0xff000000) != 0))) break;
226 if (!has_alpha
) /* generate alpha channel from the mask */
228 for (i
= 0; i
< height
; i
++)
229 for (j
= n
* width
; j
< (n
+ 1) * width
; j
++)
230 if (!mask_info
|| !((mask_bits
[i
* mask_stride
+ j
/ 8] << (j
% 8)) & 0x80))
231 bits
[i
* stride
+ j
] |= 0xff000000;
233 bits
[i
* stride
+ j
] = 0;
237 himl
->has_alpha
[pos
+ n
] = 1;
239 if (mask_info
&& himl
->hbmMask
) /* generate the mask from the alpha channel */
241 for (i
= 0; i
< height
; i
++)
242 for (j
= n
* width
; j
< (n
+ 1) * width
; j
++)
243 if ((bits
[i
* stride
+ j
] >> 24) > 25) /* more than 10% alpha */
244 mask_bits
[i
* mask_stride
+ j
/ 8] &= ~(0x80 >> (j
% 8));
246 mask_bits
[i
* mask_stride
+ j
/ 8] |= 0x80 >> (j
% 8);
249 StretchDIBits( himl
->hdcImage
, pt
.x
, pt
.y
, himl
->cx
, himl
->cy
,
250 n
* width
, 0, width
, height
, bits
, info
, DIB_RGB_COLORS
, SRCCOPY
);
252 StretchDIBits( himl
->hdcMask
, pt
.x
, pt
.y
, himl
->cx
, himl
->cy
,
253 n
* width
, 0, width
, height
, mask_bits
, mask_info
, DIB_RGB_COLORS
, SRCCOPY
);
257 /* add images with an alpha channel when the image list is 32 bpp */
258 static BOOL
add_with_alpha( HIMAGELIST himl
, HDC hdc
, int pos
, int count
,
259 int width
, int height
, HBITMAP hbmImage
, HBITMAP hbmMask
)
263 BITMAPINFO
*info
, *mask_info
= NULL
;
265 BYTE
*mask_bits
= NULL
;
268 if (!GetObjectW( hbmImage
, sizeof(bm
), &bm
)) return FALSE
;
270 /* if either the imagelist or the source bitmap don't have an alpha channel, bail out now */
271 if (!himl
->has_alpha
) return FALSE
;
272 if (bm
.bmBitsPixel
!= 32) return FALSE
;
274 SelectObject( hdc
, hbmImage
);
275 mask_width
= (bm
.bmWidth
+ 31) / 32 * 4;
277 if (!(info
= HeapAlloc( GetProcessHeap(), 0, FIELD_OFFSET( BITMAPINFO
, bmiColors
[256] )))) goto done
;
278 info
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
279 info
->bmiHeader
.biWidth
= bm
.bmWidth
;
280 info
->bmiHeader
.biHeight
= -height
;
281 info
->bmiHeader
.biPlanes
= 1;
282 info
->bmiHeader
.biBitCount
= 32;
283 info
->bmiHeader
.biCompression
= BI_RGB
;
284 info
->bmiHeader
.biSizeImage
= bm
.bmWidth
* height
* 4;
285 info
->bmiHeader
.biXPelsPerMeter
= 0;
286 info
->bmiHeader
.biYPelsPerMeter
= 0;
287 info
->bmiHeader
.biClrUsed
= 0;
288 info
->bmiHeader
.biClrImportant
= 0;
289 if (!(bits
= HeapAlloc( GetProcessHeap(), 0, info
->bmiHeader
.biSizeImage
))) goto done
;
290 if (!GetDIBits( hdc
, hbmImage
, 0, height
, bits
, info
, DIB_RGB_COLORS
)) goto done
;
294 if (!(mask_info
= HeapAlloc( GetProcessHeap(), 0, FIELD_OFFSET( BITMAPINFO
, bmiColors
[2] ))))
296 mask_info
->bmiHeader
= info
->bmiHeader
;
297 mask_info
->bmiHeader
.biBitCount
= 1;
298 mask_info
->bmiHeader
.biSizeImage
= mask_width
* height
;
299 if (!(mask_bits
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, info
->bmiHeader
.biSizeImage
)))
301 if (!GetDIBits( hdc
, hbmMask
, 0, height
, mask_bits
, mask_info
, DIB_RGB_COLORS
)) goto done
;
304 add_dib_bits( himl
, pos
, count
, width
, height
, info
, mask_info
, bits
, mask_bits
);
308 HeapFree( GetProcessHeap(), 0, info
);
309 HeapFree( GetProcessHeap(), 0, mask_info
);
310 HeapFree( GetProcessHeap(), 0, bits
);
311 HeapFree( GetProcessHeap(), 0, mask_bits
);
316 ImageList_SetColorTable(HIMAGELIST himl
, UINT uStartIndex
, UINT cEntries
, const RGBQUAD
*prgb
);
318 /*************************************************************************
319 * IMAGELIST_InternalExpandBitmaps [Internal]
321 * Expands the bitmaps of an image list by the given number of images.
324 * himl [I] handle to image list
325 * nImageCount [I] number of images to add
331 * This function CANNOT be used to reduce the number of images.
334 IMAGELIST_InternalExpandBitmaps(HIMAGELIST himl
, INT nImageCount
)
337 HBITMAP hbmNewBitmap
, hbmNull
;
341 TRACE("%p has allocated %d, max %d, grow %d images\n", himl
, himl
->cCurImage
, himl
->cMaxImage
, himl
->cGrow
);
343 if (himl
->cCurImage
+ nImageCount
< himl
->cMaxImage
)
346 nNewCount
= himl
->cMaxImage
+ max(nImageCount
, himl
->cGrow
) + 1;
348 imagelist_get_bitmap_size(himl
, nNewCount
, &sz
);
350 TRACE("Create expanded bitmaps : himl=%p x=%d y=%d count=%d\n", himl
, sz
.cx
, sz
.cy
, nNewCount
);
351 hdcBitmap
= CreateCompatibleDC (0);
353 hbmNewBitmap
= ImageList_CreateImage(hdcBitmap
, himl
, nNewCount
);
355 if (hbmNewBitmap
== 0)
356 ERR("creating new image bitmap (x=%d y=%d)!\n", sz
.cx
, sz
.cy
);
360 hbmNull
= SelectObject (hdcBitmap
, hbmNewBitmap
);
361 BitBlt (hdcBitmap
, 0, 0, sz
.cx
, sz
.cy
,
362 himl
->hdcImage
, 0, 0, SRCCOPY
);
363 SelectObject (hdcBitmap
, hbmNull
);
365 SelectObject (himl
->hdcImage
, hbmNewBitmap
);
366 DeleteObject (himl
->hbmImage
);
367 himl
->hbmImage
= hbmNewBitmap
;
369 if (himl
->flags
& ILC_MASK
)
371 hbmNewBitmap
= CreateBitmap (sz
.cx
, sz
.cy
, 1, 1, NULL
);
373 if (hbmNewBitmap
== 0)
374 ERR("creating new mask bitmap!\n");
378 hbmNull
= SelectObject (hdcBitmap
, hbmNewBitmap
);
379 BitBlt (hdcBitmap
, 0, 0, sz
.cx
, sz
.cy
,
380 himl
->hdcMask
, 0, 0, SRCCOPY
);
381 SelectObject (hdcBitmap
, hbmNull
);
383 SelectObject (himl
->hdcMask
, hbmNewBitmap
);
384 DeleteObject (himl
->hbmMask
);
385 himl
->hbmMask
= hbmNewBitmap
;
390 char *new_alpha
= HeapReAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, himl
->has_alpha
, nNewCount
);
391 if (new_alpha
) himl
->has_alpha
= new_alpha
;
394 HeapFree( GetProcessHeap(), 0, himl
->has_alpha
);
395 himl
->has_alpha
= NULL
;
399 himl
->cMaxImage
= nNewCount
;
401 DeleteDC (hdcBitmap
);
405 /*************************************************************************
406 * ImageList_Add [COMCTL32.@]
408 * Add an image or images to an image list.
411 * himl [I] handle to image list
412 * hbmImage [I] handle to image bitmap
413 * hbmMask [I] handle to mask bitmap
416 * Success: Index of the first new image.
421 ImageList_Add (HIMAGELIST himl
, HBITMAP hbmImage
, HBITMAP hbmMask
)
423 HDC hdcBitmap
, hdcTemp
= 0;
424 INT nFirstIndex
, nImageCount
, i
;
428 TRACE("himl=%p hbmimage=%p hbmmask=%p\n", himl
, hbmImage
, hbmMask
);
432 if (!GetObjectW(hbmImage
, sizeof(BITMAP
), &bmp
))
435 TRACE("himl %p, cCurImage %d, cMaxImage %d, cGrow %d, cx %d, cy %d\n",
436 himl
, himl
->cCurImage
, himl
->cMaxImage
, himl
->cGrow
, himl
->cx
, himl
->cy
);
438 nImageCount
= bmp
.bmWidth
/ himl
->cx
;
440 TRACE("%p has %d images (%d x %d) bpp %d\n", hbmImage
, nImageCount
, bmp
.bmWidth
, bmp
.bmHeight
,
443 IMAGELIST_InternalExpandBitmaps(himl
, nImageCount
);
445 hdcBitmap
= CreateCompatibleDC(0);
447 SelectObject(hdcBitmap
, hbmImage
);
449 if (add_with_alpha( himl
, hdcBitmap
, himl
->cCurImage
, nImageCount
,
450 himl
->cx
, min( himl
->cy
, bmp
.bmHeight
), hbmImage
, hbmMask
))
455 hdcTemp
= CreateCompatibleDC(0);
456 SelectObject(hdcTemp
, hbmMask
);
459 if (himl
->uBitsPixel
<= 8 && bmp
.bmBitsPixel
<= 8 &&
460 !himl
->color_table_set
&& himl
->cCurImage
== 0)
463 UINT num
= GetDIBColorTable( hdcBitmap
, 0, 1 << bmp
.bmBitsPixel
, colors
);
464 if (num
) ImageList_SetColorTable( himl
, 0, num
, colors
);
467 for (i
=0; i
<nImageCount
; i
++)
469 imagelist_point_from_index( himl
, himl
->cCurImage
+ i
, &pt
);
471 /* Copy result to the imagelist
473 BitBlt( himl
->hdcImage
, pt
.x
, pt
.y
, himl
->cx
, bmp
.bmHeight
,
474 hdcBitmap
, i
*himl
->cx
, 0, SRCCOPY
);
479 BitBlt( himl
->hdcMask
, pt
.x
, pt
.y
, himl
->cx
, bmp
.bmHeight
,
480 hdcTemp
, i
*himl
->cx
, 0, SRCCOPY
);
482 /* Remove the background from the image
484 BitBlt( himl
->hdcImage
, pt
.x
, pt
.y
, himl
->cx
, bmp
.bmHeight
,
485 himl
->hdcMask
, pt
.x
, pt
.y
, 0x220326 ); /* NOTSRCAND */
487 if (hdcTemp
) DeleteDC(hdcTemp
);
492 nFirstIndex
= himl
->cCurImage
;
493 himl
->cCurImage
+= nImageCount
;
499 /*************************************************************************
500 * ImageList_AddIcon [COMCTL32.@]
502 * Adds an icon to an image list.
505 * himl [I] handle to image list
506 * hIcon [I] handle to icon
509 * Success: index of the new image
512 #undef ImageList_AddIcon
513 INT WINAPI
ImageList_AddIcon (HIMAGELIST himl
, HICON hIcon
)
515 return ImageList_ReplaceIcon (himl
, -1, hIcon
);
519 /*************************************************************************
520 * ImageList_AddMasked [COMCTL32.@]
522 * Adds an image or images to an image list and creates a mask from the
523 * specified bitmap using the mask color.
526 * himl [I] handle to image list.
527 * hBitmap [I] handle to bitmap
528 * clrMask [I] mask color.
531 * Success: Index of the first new image.
536 ImageList_AddMasked (HIMAGELIST himl
, HBITMAP hBitmap
, COLORREF clrMask
)
538 HDC hdcMask
, hdcBitmap
;
544 TRACE("himl=%p hbitmap=%p clrmask=%x\n", himl
, hBitmap
, clrMask
);
548 if (!GetObjectW(hBitmap
, sizeof(BITMAP
), &bmp
))
551 hdcBitmap
= CreateCompatibleDC(0);
552 SelectObject(hdcBitmap
, hBitmap
);
554 /* Create a temp Mask so we can remove the background of the Image */
555 hdcMask
= CreateCompatibleDC(0);
556 hMaskBitmap
= CreateBitmap(bmp
.bmWidth
, bmp
.bmHeight
, 1, 1, NULL
);
557 SelectObject(hdcMask
, hMaskBitmap
);
559 /* create monochrome image to the mask bitmap */
560 bkColor
= (clrMask
!= CLR_DEFAULT
) ? clrMask
: GetPixel (hdcBitmap
, 0, 0);
561 SetBkColor (hdcBitmap
, bkColor
);
562 BitBlt (hdcMask
, 0, 0, bmp
.bmWidth
, bmp
.bmHeight
, hdcBitmap
, 0, 0, SRCCOPY
);
565 * Remove the background from the image
567 * WINDOWS BUG ALERT!!!!!!
568 * The statement below should not be done in common practice
569 * but this is how ImageList_AddMasked works in Windows.
570 * It overwrites the original bitmap passed, this was discovered
571 * by using the same bitmap to iterate the different styles
572 * on windows where it failed (BUT ImageList_Add is OK)
573 * This is here in case some apps rely on this bug
575 * Blt mode 0x220326 is NOTSRCAND
577 if (bmp
.bmBitsPixel
> 8) /* NOTSRCAND can't work with palettes */
579 SetBkColor(hdcBitmap
, RGB(255,255,255));
580 BitBlt(hdcBitmap
, 0, 0, bmp
.bmWidth
, bmp
.bmHeight
, hdcMask
, 0, 0, 0x220326);
586 ret
= ImageList_Add( himl
, hBitmap
, hMaskBitmap
);
588 DeleteObject(hMaskBitmap
);
593 /*************************************************************************
594 * ImageList_BeginDrag [COMCTL32.@]
596 * Creates a temporary image list that contains one image. It will be used
600 * himlTrack [I] handle to the source image list
601 * iTrack [I] index of the drag image in the source image list
602 * dxHotspot [I] X position of the hot spot of the drag image
603 * dyHotspot [I] Y position of the hot spot of the drag image
611 ImageList_BeginDrag (HIMAGELIST himlTrack
, INT iTrack
,
612 INT dxHotspot
, INT dyHotspot
)
617 TRACE("(himlTrack=%p iTrack=%d dx=%d dy=%d)\n", himlTrack
, iTrack
,
618 dxHotspot
, dyHotspot
);
620 if (!is_valid(himlTrack
))
623 if (iTrack
>= himlTrack
->cCurImage
)
626 if (InternalDrag
.himl
)
632 InternalDrag
.himlNoCursor
= InternalDrag
.himl
= ImageList_Create (cx
, cy
, himlTrack
->flags
, 1, 1);
633 if (InternalDrag
.himl
== NULL
) {
634 WARN("Error creating drag image list!\n");
638 InternalDrag
.dxHotspot
= dxHotspot
;
639 InternalDrag
.dyHotspot
= dyHotspot
;
642 imagelist_point_from_index(InternalDrag
.himl
, 0, &dst
);
643 imagelist_point_from_index(himlTrack
, iTrack
, &src
);
644 BitBlt(InternalDrag
.himl
->hdcImage
, dst
.x
, dst
.y
, cx
, cy
, himlTrack
->hdcImage
, src
.x
, src
.y
,
646 BitBlt(InternalDrag
.himl
->hdcMask
, dst
.x
, dst
.y
, cx
, cy
, himlTrack
->hdcMask
, src
.x
, src
.y
,
649 InternalDrag
.himl
->cCurImage
= 1;
655 /*************************************************************************
656 * ImageList_Copy [COMCTL32.@]
658 * Copies an image of the source image list to an image of the
659 * destination image list. Images can be copied or swapped.
662 * himlDst [I] handle to the destination image list
663 * iDst [I] destination image index.
664 * himlSrc [I] handle to the source image list
665 * iSrc [I] source image index
666 * uFlags [I] flags for the copy operation
673 * Copying from one image list to another is possible. The original
674 * implementation just copies or swaps within one image list.
675 * Could this feature become a bug??? ;-)
679 ImageList_Copy (HIMAGELIST himlDst
, INT iDst
, HIMAGELIST himlSrc
,
680 INT iSrc
, UINT uFlags
)
684 TRACE("himlDst=%p iDst=%d himlSrc=%p iSrc=%d\n", himlDst
, iDst
, himlSrc
, iSrc
);
686 if (!is_valid(himlSrc
) || !is_valid(himlDst
))
688 if ((iDst
< 0) || (iDst
>= himlDst
->cCurImage
))
690 if ((iSrc
< 0) || (iSrc
>= himlSrc
->cCurImage
))
693 imagelist_point_from_index( himlDst
, iDst
, &ptDst
);
694 imagelist_point_from_index( himlSrc
, iSrc
, &ptSrc
);
696 if (uFlags
& ILCF_SWAP
) {
699 HBITMAP hbmTempImage
, hbmTempMask
;
701 hdcBmp
= CreateCompatibleDC (0);
703 /* create temporary bitmaps */
704 hbmTempImage
= CreateBitmap (himlSrc
->cx
, himlSrc
->cy
, 1,
705 himlSrc
->uBitsPixel
, NULL
);
706 hbmTempMask
= CreateBitmap (himlSrc
->cx
, himlSrc
->cy
, 1,
709 /* copy (and stretch) destination to temporary bitmaps.(save) */
711 SelectObject (hdcBmp
, hbmTempImage
);
712 StretchBlt (hdcBmp
, 0, 0, himlSrc
->cx
, himlSrc
->cy
,
713 himlDst
->hdcImage
, ptDst
.x
, ptDst
.y
, himlDst
->cx
, himlDst
->cy
,
716 SelectObject (hdcBmp
, hbmTempMask
);
717 StretchBlt (hdcBmp
, 0, 0, himlSrc
->cx
, himlSrc
->cy
,
718 himlDst
->hdcMask
, ptDst
.x
, ptDst
.y
, himlDst
->cx
, himlDst
->cy
,
721 /* copy (and stretch) source to destination */
723 StretchBlt (himlDst
->hdcImage
, ptDst
.x
, ptDst
.y
, himlDst
->cx
, himlDst
->cy
,
724 himlSrc
->hdcImage
, ptSrc
.x
, ptSrc
.y
, himlSrc
->cx
, himlSrc
->cy
,
727 StretchBlt (himlDst
->hdcMask
, ptDst
.x
, ptDst
.y
, himlDst
->cx
, himlDst
->cy
,
728 himlSrc
->hdcMask
, ptSrc
.x
, ptSrc
.y
, himlSrc
->cx
, himlSrc
->cy
,
731 /* copy (without stretching) temporary bitmaps to source (restore) */
733 BitBlt (himlSrc
->hdcMask
, ptSrc
.x
, ptSrc
.y
, himlSrc
->cx
, himlSrc
->cy
,
734 hdcBmp
, 0, 0, SRCCOPY
);
737 BitBlt (himlSrc
->hdcImage
, ptSrc
.x
, ptSrc
.y
, himlSrc
->cx
, himlSrc
->cy
,
738 hdcBmp
, 0, 0, SRCCOPY
);
739 /* delete temporary bitmaps */
740 DeleteObject (hbmTempMask
);
741 DeleteObject (hbmTempImage
);
746 StretchBlt (himlDst
->hdcImage
, ptDst
.x
, ptDst
.y
, himlDst
->cx
, himlDst
->cy
,
747 himlSrc
->hdcImage
, ptSrc
.x
, ptSrc
.y
, himlSrc
->cx
, himlSrc
->cy
,
751 StretchBlt (himlDst
->hdcMask
, ptDst
.x
, ptDst
.y
, himlDst
->cx
, himlDst
->cy
,
752 himlSrc
->hdcMask
, ptSrc
.x
, ptSrc
.y
, himlSrc
->cx
, himlSrc
->cy
,
760 /*************************************************************************
761 * ImageList_Create [COMCTL32.@]
763 * Creates a new image list.
766 * cx [I] image height
768 * flags [I] creation flags
769 * cInitial [I] initial number of images in the image list
770 * cGrow [I] number of images by which image list grows
773 * Success: Handle to the created image list
777 ImageList_Create (INT cx
, INT cy
, UINT flags
,
778 INT cInitial
, INT cGrow
)
783 UINT ilc
= (flags
& 0xFE);
784 static const WORD aBitBlend25
[] =
785 {0xAA, 0x00, 0x55, 0x00, 0xAA, 0x00, 0x55, 0x00};
787 static const WORD aBitBlend50
[] =
788 {0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA};
790 TRACE("(%d %d 0x%x %d %d)\n", cx
, cy
, flags
, cInitial
, cGrow
);
792 if (cx
< 0 || cy
< 0) return NULL
;
793 if (!((flags
&ILC_COLORDDB
) == ILC_COLORDDB
) && (cx
== 0 || cy
== 0)) return NULL
;
795 /* Create the IImageList interface for the image list */
796 if (FAILED(ImageListImpl_CreateInstance(NULL
, &IID_IImageList
, (void **)&himl
)))
799 cGrow
= (WORD
)((max( cGrow
, 1 ) + 3) & ~3);
803 /* Windows doesn't limit the size here, but X11 doesn't let us allocate such huge bitmaps */
804 WARN( "grow %d too large, limiting to 256\n", cGrow
);
811 himl
->cMaxImage
= cInitial
+ 1;
812 himl
->cInitial
= cInitial
;
814 himl
->clrFg
= CLR_DEFAULT
;
815 himl
->clrBk
= CLR_NONE
;
816 himl
->color_table_set
= FALSE
;
818 /* initialize overlay mask indices */
819 for (nCount
= 0; nCount
< MAX_OVERLAYIMAGE
; nCount
++)
820 himl
->nOvlIdx
[nCount
] = -1;
822 /* Create Image & Mask DCs */
823 himl
->hdcImage
= CreateCompatibleDC (0);
826 if (himl
->flags
& ILC_MASK
){
827 himl
->hdcMask
= CreateCompatibleDC(0);
832 /* Default to ILC_COLOR4 if none of the ILC_COLOR* flags are specified */
833 if (ilc
== ILC_COLOR
)
836 himl
->flags
|= ILC_COLOR4
;
839 if (ilc
>= ILC_COLOR4
&& ilc
<= ILC_COLOR32
)
840 himl
->uBitsPixel
= ilc
;
842 himl
->uBitsPixel
= (UINT
)GetDeviceCaps (himl
->hdcImage
, BITSPIXEL
);
844 if (himl
->cMaxImage
> 0) {
845 himl
->hbmImage
= ImageList_CreateImage(himl
->hdcImage
, himl
, himl
->cMaxImage
);
846 SelectObject(himl
->hdcImage
, himl
->hbmImage
);
850 if ((himl
->cMaxImage
> 0) && (himl
->flags
& ILC_MASK
)) {
853 imagelist_get_bitmap_size(himl
, himl
->cMaxImage
, &sz
);
854 himl
->hbmMask
= CreateBitmap (sz
.cx
, sz
.cy
, 1, 1, NULL
);
855 if (himl
->hbmMask
== 0) {
856 ERR("Error creating mask bitmap!\n");
859 SelectObject(himl
->hdcMask
, himl
->hbmMask
);
864 if (ilc
== ILC_COLOR32
)
865 himl
->has_alpha
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, himl
->cMaxImage
);
867 himl
->has_alpha
= NULL
;
869 /* create blending brushes */
870 hbmTemp
= CreateBitmap (8, 8, 1, 1, aBitBlend25
);
871 himl
->hbrBlend25
= CreatePatternBrush (hbmTemp
);
872 DeleteObject (hbmTemp
);
874 hbmTemp
= CreateBitmap (8, 8, 1, 1, aBitBlend50
);
875 himl
->hbrBlend50
= CreatePatternBrush (hbmTemp
);
876 DeleteObject (hbmTemp
);
878 TRACE("created imagelist %p\n", himl
);
882 ImageList_Destroy(himl
);
887 /*************************************************************************
888 * ImageList_Destroy [COMCTL32.@]
890 * Destroys an image list.
893 * himl [I] handle to image list
901 ImageList_Destroy (HIMAGELIST himl
)
906 IImageList_Release((IImageList
*) himl
);
911 /*************************************************************************
912 * ImageList_DragEnter [COMCTL32.@]
914 * Locks window update and displays the drag image at the given position.
917 * hwndLock [I] handle of the window that owns the drag image.
918 * x [I] X position of the drag image.
919 * y [I] Y position of the drag image.
926 * The position of the drag image is relative to the window, not
931 ImageList_DragEnter (HWND hwndLock
, INT x
, INT y
)
933 TRACE("(hwnd=%p x=%d y=%d)\n", hwndLock
, x
, y
);
935 if (!is_valid(InternalDrag
.himl
))
939 InternalDrag
.hwnd
= hwndLock
;
941 InternalDrag
.hwnd
= GetDesktopWindow ();
946 /* draw the drag image and save the background */
947 return ImageList_DragShowNolock(TRUE
);
951 /*************************************************************************
952 * ImageList_DragLeave [COMCTL32.@]
954 * Unlocks window update and hides the drag image.
957 * hwndLock [I] handle of the window that owns the drag image.
965 ImageList_DragLeave (HWND hwndLock
)
967 /* As we don't save drag info in the window this can lead to problems if
968 an app does not supply the same window as DragEnter */
970 InternalDrag.hwnd = hwndLock;
972 InternalDrag.hwnd = GetDesktopWindow (); */
974 hwndLock
= GetDesktopWindow();
975 if(InternalDrag
.hwnd
!= hwndLock
)
976 FIXME("DragLeave hWnd != DragEnter hWnd\n");
978 ImageList_DragShowNolock (FALSE
);
984 /*************************************************************************
985 * ImageList_InternalDragDraw [Internal]
987 * Draws the drag image.
990 * hdc [I] device context to draw into.
991 * x [I] X position of the drag image.
992 * y [I] Y position of the drag image.
999 * The position of the drag image is relative to the window, not
1005 ImageList_InternalDragDraw (HDC hdc
, INT x
, INT y
)
1007 IMAGELISTDRAWPARAMS imldp
;
1009 ZeroMemory (&imldp
, sizeof(imldp
));
1010 imldp
.cbSize
= sizeof(imldp
);
1011 imldp
.himl
= InternalDrag
.himl
;
1016 imldp
.rgbBk
= CLR_DEFAULT
;
1017 imldp
.rgbFg
= CLR_DEFAULT
;
1018 imldp
.fStyle
= ILD_NORMAL
;
1019 imldp
.fState
= ILS_ALPHA
;
1021 ImageList_DrawIndirect (&imldp
);
1024 /*************************************************************************
1025 * ImageList_DragMove [COMCTL32.@]
1027 * Moves the drag image.
1030 * x [I] X position of the drag image.
1031 * y [I] Y position of the drag image.
1038 * The position of the drag image is relative to the window, not
1043 ImageList_DragMove (INT x
, INT y
)
1045 TRACE("(x=%d y=%d)\n", x
, y
);
1047 if (!is_valid(InternalDrag
.himl
))
1050 /* draw/update the drag image */
1051 if (InternalDrag
.bShow
) {
1055 HBITMAP hbmOffScreen
;
1056 INT origNewX
, origNewY
;
1057 INT origOldX
, origOldY
;
1058 INT origRegX
, origRegY
;
1059 INT sizeRegX
, sizeRegY
;
1062 /* calculate the update region */
1063 origNewX
= x
- InternalDrag
.dxHotspot
;
1064 origNewY
= y
- InternalDrag
.dyHotspot
;
1065 origOldX
= InternalDrag
.x
- InternalDrag
.dxHotspot
;
1066 origOldY
= InternalDrag
.y
- InternalDrag
.dyHotspot
;
1067 origRegX
= min(origNewX
, origOldX
);
1068 origRegY
= min(origNewY
, origOldY
);
1069 sizeRegX
= InternalDrag
.himl
->cx
+ abs(x
- InternalDrag
.x
);
1070 sizeRegY
= InternalDrag
.himl
->cy
+ abs(y
- InternalDrag
.y
);
1072 hdcDrag
= GetDCEx(InternalDrag
.hwnd
, 0,
1073 DCX_WINDOW
| DCX_CACHE
| DCX_LOCKWINDOWUPDATE
);
1074 hdcOffScreen
= CreateCompatibleDC(hdcDrag
);
1075 hdcBg
= CreateCompatibleDC(hdcDrag
);
1077 hbmOffScreen
= CreateCompatibleBitmap(hdcDrag
, sizeRegX
, sizeRegY
);
1078 SelectObject(hdcOffScreen
, hbmOffScreen
);
1079 SelectObject(hdcBg
, InternalDrag
.hbmBg
);
1081 /* get the actual background of the update region */
1082 BitBlt(hdcOffScreen
, 0, 0, sizeRegX
, sizeRegY
, hdcDrag
,
1083 origRegX
, origRegY
, SRCCOPY
);
1084 /* erase the old image */
1085 BitBlt(hdcOffScreen
, origOldX
- origRegX
, origOldY
- origRegY
,
1086 InternalDrag
.himl
->cx
, InternalDrag
.himl
->cy
, hdcBg
, 0, 0,
1088 /* save the background */
1089 BitBlt(hdcBg
, 0, 0, InternalDrag
.himl
->cx
, InternalDrag
.himl
->cy
,
1090 hdcOffScreen
, origNewX
- origRegX
, origNewY
- origRegY
, SRCCOPY
);
1091 /* draw the image */
1092 ImageList_InternalDragDraw(hdcOffScreen
, origNewX
- origRegX
,
1093 origNewY
- origRegY
);
1094 /* draw the update region to the screen */
1095 BitBlt(hdcDrag
, origRegX
, origRegY
, sizeRegX
, sizeRegY
,
1096 hdcOffScreen
, 0, 0, SRCCOPY
);
1099 DeleteDC(hdcOffScreen
);
1100 DeleteObject(hbmOffScreen
);
1101 ReleaseDC(InternalDrag
.hwnd
, hdcDrag
);
1104 /* update the image position */
1112 /*************************************************************************
1113 * ImageList_DragShowNolock [COMCTL32.@]
1115 * Shows or hides the drag image.
1118 * bShow [I] TRUE shows the drag image, FALSE hides it.
1126 ImageList_DragShowNolock (BOOL bShow
)
1132 if (!is_valid(InternalDrag
.himl
))
1135 TRACE("bShow=0x%X!\n", bShow
);
1137 /* DragImage is already visible/hidden */
1138 if ((InternalDrag
.bShow
&& bShow
) || (!InternalDrag
.bShow
&& !bShow
)) {
1142 /* position of the origin of the DragImage */
1143 x
= InternalDrag
.x
- InternalDrag
.dxHotspot
;
1144 y
= InternalDrag
.y
- InternalDrag
.dyHotspot
;
1146 hdcDrag
= GetDCEx (InternalDrag
.hwnd
, 0,
1147 DCX_WINDOW
| DCX_CACHE
| DCX_LOCKWINDOWUPDATE
);
1152 hdcBg
= CreateCompatibleDC(hdcDrag
);
1153 if (!InternalDrag
.hbmBg
) {
1154 InternalDrag
.hbmBg
= CreateCompatibleBitmap(hdcDrag
,
1155 InternalDrag
.himl
->cx
, InternalDrag
.himl
->cy
);
1157 SelectObject(hdcBg
, InternalDrag
.hbmBg
);
1160 /* save the background */
1161 BitBlt(hdcBg
, 0, 0, InternalDrag
.himl
->cx
, InternalDrag
.himl
->cy
,
1162 hdcDrag
, x
, y
, SRCCOPY
);
1163 /* show the image */
1164 ImageList_InternalDragDraw(hdcDrag
, x
, y
);
1166 /* hide the image */
1167 BitBlt(hdcDrag
, x
, y
, InternalDrag
.himl
->cx
, InternalDrag
.himl
->cy
,
1168 hdcBg
, 0, 0, SRCCOPY
);
1171 InternalDrag
.bShow
= !InternalDrag
.bShow
;
1174 ReleaseDC (InternalDrag
.hwnd
, hdcDrag
);
1179 /*************************************************************************
1180 * ImageList_Draw [COMCTL32.@]
1185 * himl [I] handle to image list
1187 * hdc [I] handle to device context
1190 * fStyle [I] drawing flags
1201 ImageList_Draw (HIMAGELIST himl
, INT i
, HDC hdc
, INT x
, INT y
, UINT fStyle
)
1203 return ImageList_DrawEx (himl
, i
, hdc
, x
, y
, 0, 0,
1204 CLR_DEFAULT
, CLR_DEFAULT
, fStyle
);
1208 /*************************************************************************
1209 * ImageList_DrawEx [COMCTL32.@]
1211 * Draws an image and allows using extended drawing features.
1214 * himl [I] handle to image list
1216 * hdc [I] handle to device context
1221 * rgbBk [I] background color
1222 * rgbFg [I] foreground color
1223 * fStyle [I] drawing flags
1230 * Calls ImageList_DrawIndirect.
1233 * ImageList_DrawIndirect.
1237 ImageList_DrawEx (HIMAGELIST himl
, INT i
, HDC hdc
, INT x
, INT y
,
1238 INT dx
, INT dy
, COLORREF rgbBk
, COLORREF rgbFg
,
1241 IMAGELISTDRAWPARAMS imldp
;
1243 ZeroMemory (&imldp
, sizeof(imldp
));
1244 imldp
.cbSize
= sizeof(imldp
);
1252 imldp
.rgbBk
= rgbBk
;
1253 imldp
.rgbFg
= rgbFg
;
1254 imldp
.fStyle
= fStyle
;
1256 return ImageList_DrawIndirect (&imldp
);
1260 static BOOL
alpha_blend_image( HIMAGELIST himl
, HDC dest_dc
, int dest_x
, int dest_y
,
1261 int src_x
, int src_y
, int cx
, int cy
, BLENDFUNCTION func
,
1262 UINT style
, COLORREF blend_col
)
1266 HBITMAP bmp
= 0, mask
= 0;
1268 void *bits
, *mask_bits
;
1272 if (!(hdc
= CreateCompatibleDC( 0 ))) return FALSE
;
1273 if (!(info
= HeapAlloc( GetProcessHeap(), 0, FIELD_OFFSET( BITMAPINFO
, bmiColors
[256] )))) goto done
;
1274 info
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
1275 info
->bmiHeader
.biWidth
= cx
;
1276 info
->bmiHeader
.biHeight
= cy
;
1277 info
->bmiHeader
.biPlanes
= 1;
1278 info
->bmiHeader
.biBitCount
= 32;
1279 info
->bmiHeader
.biCompression
= BI_RGB
;
1280 info
->bmiHeader
.biSizeImage
= cx
* cy
* 4;
1281 info
->bmiHeader
.biXPelsPerMeter
= 0;
1282 info
->bmiHeader
.biYPelsPerMeter
= 0;
1283 info
->bmiHeader
.biClrUsed
= 0;
1284 info
->bmiHeader
.biClrImportant
= 0;
1285 if (!(bmp
= CreateDIBSection( himl
->hdcImage
, info
, DIB_RGB_COLORS
, &bits
, 0, 0 ))) goto done
;
1286 SelectObject( hdc
, bmp
);
1287 BitBlt( hdc
, 0, 0, cx
, cy
, himl
->hdcImage
, src_x
, src_y
, SRCCOPY
);
1289 if (blend_col
!= CLR_NONE
)
1291 BYTE r
= GetRValue( blend_col
);
1292 BYTE g
= GetGValue( blend_col
);
1293 BYTE b
= GetBValue( blend_col
);
1295 if (style
& ILD_BLEND25
)
1297 for (i
= 0, ptr
= bits
; i
< cx
* cy
; i
++, ptr
++)
1298 *ptr
= ((*ptr
& 0xff000000) |
1299 ((((*ptr
& 0x00ff0000) * 3 + (r
<< 16)) / 4) & 0x00ff0000) |
1300 ((((*ptr
& 0x0000ff00) * 3 + (g
<< 8)) / 4) & 0x0000ff00) |
1301 ((((*ptr
& 0x000000ff) * 3 + (b
<< 0)) / 4) & 0x000000ff));
1303 else if (style
& ILD_BLEND50
)
1305 for (i
= 0, ptr
= bits
; i
< cx
* cy
; i
++, ptr
++)
1306 *ptr
= ((*ptr
& 0xff000000) |
1307 ((((*ptr
& 0x00ff0000) + (r
<< 16)) / 2) & 0x00ff0000) |
1308 ((((*ptr
& 0x0000ff00) + (g
<< 8)) / 2) & 0x0000ff00) |
1309 ((((*ptr
& 0x000000ff) + (b
<< 0)) / 2) & 0x000000ff));
1313 if (himl
->has_alpha
) /* we already have an alpha channel in this case */
1315 /* pre-multiply by the alpha channel */
1316 for (i
= 0, ptr
= bits
; i
< cx
* cy
; i
++, ptr
++)
1318 DWORD alpha
= *ptr
>> 24;
1319 *ptr
= ((*ptr
& 0xff000000) |
1320 (((*ptr
& 0x00ff0000) * alpha
/ 255) & 0x00ff0000) |
1321 (((*ptr
& 0x0000ff00) * alpha
/ 255) & 0x0000ff00) |
1322 (((*ptr
& 0x000000ff) * alpha
/ 255)));
1325 else if (himl
->hbmMask
)
1327 unsigned int width_bytes
= (cx
+ 31) / 32 * 4;
1328 /* generate alpha channel from the mask */
1329 info
->bmiHeader
.biBitCount
= 1;
1330 info
->bmiHeader
.biSizeImage
= width_bytes
* cy
;
1331 info
->bmiColors
[0].rgbRed
= 0;
1332 info
->bmiColors
[0].rgbGreen
= 0;
1333 info
->bmiColors
[0].rgbBlue
= 0;
1334 info
->bmiColors
[0].rgbReserved
= 0;
1335 info
->bmiColors
[1].rgbRed
= 0xff;
1336 info
->bmiColors
[1].rgbGreen
= 0xff;
1337 info
->bmiColors
[1].rgbBlue
= 0xff;
1338 info
->bmiColors
[1].rgbReserved
= 0;
1339 if (!(mask
= CreateDIBSection( himl
->hdcMask
, info
, DIB_RGB_COLORS
, &mask_bits
, 0, 0 )))
1341 SelectObject( hdc
, mask
);
1342 BitBlt( hdc
, 0, 0, cx
, cy
, himl
->hdcMask
, src_x
, src_y
, SRCCOPY
);
1343 SelectObject( hdc
, bmp
);
1344 for (i
= 0, ptr
= bits
; i
< cy
; i
++)
1345 for (j
= 0; j
< cx
; j
++, ptr
++)
1346 if ((((BYTE
*)mask_bits
)[i
* width_bytes
+ j
/ 8] << (j
% 8)) & 0x80) *ptr
= 0;
1347 else *ptr
|= 0xff000000;
1350 ret
= GdiAlphaBlend( dest_dc
, dest_x
, dest_y
, cx
, cy
, hdc
, 0, 0, cx
, cy
, func
);
1354 if (bmp
) DeleteObject( bmp
);
1355 if (mask
) DeleteObject( mask
);
1356 HeapFree( GetProcessHeap(), 0, info
);
1360 /*************************************************************************
1361 * ImageList_DrawIndirect [COMCTL32.@]
1363 * Draws an image using various parameters specified in pimldp.
1366 * pimldp [I] pointer to IMAGELISTDRAWPARAMS structure.
1374 ImageList_DrawIndirect (IMAGELISTDRAWPARAMS
*pimldp
)
1376 INT cx
, cy
, nOvlIdx
;
1377 DWORD fState
, dwRop
;
1379 COLORREF oldImageBk
, oldImageFg
;
1380 HDC hImageDC
, hImageListDC
, hMaskListDC
;
1381 HBITMAP hImageBmp
, hOldImageBmp
, hBlendMaskBmp
;
1382 BOOL bIsTransparent
, bBlend
, bResult
= FALSE
, bMask
;
1388 if (!pimldp
|| !(himl
= pimldp
->himl
)) return FALSE
;
1389 if (!is_valid(himl
)) return FALSE
;
1390 if ((pimldp
->i
< 0) || (pimldp
->i
>= himl
->cCurImage
)) return FALSE
;
1392 imagelist_point_from_index( himl
, pimldp
->i
, &pt
);
1393 pt
.x
+= pimldp
->xBitmap
;
1394 pt
.y
+= pimldp
->yBitmap
;
1396 fState
= pimldp
->cbSize
< sizeof(IMAGELISTDRAWPARAMS
) ? ILS_NORMAL
: pimldp
->fState
;
1397 fStyle
= pimldp
->fStyle
& ~ILD_OVERLAYMASK
;
1398 cx
= (pimldp
->cx
== 0) ? himl
->cx
: pimldp
->cx
;
1399 cy
= (pimldp
->cy
== 0) ? himl
->cy
: pimldp
->cy
;
1401 bIsTransparent
= (fStyle
& ILD_TRANSPARENT
);
1402 if( pimldp
->rgbBk
== CLR_NONE
)
1403 bIsTransparent
= TRUE
;
1404 if( ( pimldp
->rgbBk
== CLR_DEFAULT
) && ( himl
->clrBk
== CLR_NONE
) )
1405 bIsTransparent
= TRUE
;
1406 bMask
= (himl
->flags
& ILC_MASK
) && (fStyle
& ILD_MASK
) ;
1407 bBlend
= (fStyle
& (ILD_BLEND25
| ILD_BLEND50
) ) && !bMask
;
1409 TRACE("himl(%p) hbmMask(%p) iImage(%d) x(%d) y(%d) cx(%d) cy(%d)\n",
1410 himl
, himl
->hbmMask
, pimldp
->i
, pimldp
->x
, pimldp
->y
, cx
, cy
);
1412 /* we will use these DCs to access the images and masks in the ImageList */
1413 hImageListDC
= himl
->hdcImage
;
1414 hMaskListDC
= himl
->hdcMask
;
1416 /* these will accumulate the image and mask for the image we're drawing */
1417 hImageDC
= CreateCompatibleDC( pimldp
->hdcDst
);
1418 hImageBmp
= CreateCompatibleBitmap( pimldp
->hdcDst
, cx
, cy
);
1419 hBlendMaskBmp
= bBlend
? CreateBitmap(cx
, cy
, 1, 1, NULL
) : 0;
1421 /* Create a compatible DC. */
1422 if (!hImageListDC
|| !hImageDC
|| !hImageBmp
||
1423 (bBlend
&& !hBlendMaskBmp
) || (himl
->hbmMask
&& !hMaskListDC
))
1426 hOldImageBmp
= SelectObject(hImageDC
, hImageBmp
);
1429 * To obtain a transparent look, background color should be set
1430 * to white and foreground color to black when blitting the
1433 oldImageFg
= SetTextColor( hImageDC
, RGB( 0, 0, 0 ) );
1434 oldImageBk
= SetBkColor( hImageDC
, RGB( 0xff, 0xff, 0xff ) );
1436 has_alpha
= (himl
->has_alpha
&& himl
->has_alpha
[pimldp
->i
]);
1437 if (!bMask
&& (has_alpha
|| (fState
& ILS_ALPHA
)))
1439 COLORREF colour
, blend_col
= CLR_NONE
;
1444 blend_col
= pimldp
->rgbFg
;
1445 if (blend_col
== CLR_DEFAULT
) blend_col
= GetSysColor( COLOR_HIGHLIGHT
);
1446 else if (blend_col
== CLR_NONE
) blend_col
= GetTextColor( pimldp
->hdcDst
);
1449 func
.BlendOp
= AC_SRC_OVER
;
1450 func
.BlendFlags
= 0;
1451 func
.SourceConstantAlpha
= (fState
& ILS_ALPHA
) ? pimldp
->Frame
: 255;
1452 func
.AlphaFormat
= AC_SRC_ALPHA
;
1456 bResult
= alpha_blend_image( himl
, pimldp
->hdcDst
, pimldp
->x
, pimldp
->y
,
1457 pt
.x
, pt
.y
, cx
, cy
, func
, fStyle
, blend_col
);
1460 colour
= pimldp
->rgbBk
;
1461 if (colour
== CLR_DEFAULT
) colour
= himl
->clrBk
;
1462 if (colour
== CLR_NONE
) colour
= GetBkColor( pimldp
->hdcDst
);
1464 hOldBrush
= SelectObject (hImageDC
, CreateSolidBrush (colour
));
1465 PatBlt( hImageDC
, 0, 0, cx
, cy
, PATCOPY
);
1466 alpha_blend_image( himl
, hImageDC
, 0, 0, pt
.x
, pt
.y
, cx
, cy
, func
, fStyle
, blend_col
);
1467 DeleteObject (SelectObject (hImageDC
, hOldBrush
));
1468 bResult
= BitBlt( pimldp
->hdcDst
, pimldp
->x
, pimldp
->y
, cx
, cy
, hImageDC
, 0, 0, SRCCOPY
);
1473 * Draw the initial image
1476 if (himl
->hbmMask
) {
1477 hOldBrush
= SelectObject (hImageDC
, CreateSolidBrush (GetTextColor(pimldp
->hdcDst
)));
1478 PatBlt( hImageDC
, 0, 0, cx
, cy
, PATCOPY
);
1479 BitBlt(hImageDC
, 0, 0, cx
, cy
, hMaskListDC
, pt
.x
, pt
.y
, SRCPAINT
);
1480 DeleteObject (SelectObject (hImageDC
, hOldBrush
));
1481 if( bIsTransparent
)
1483 BitBlt ( pimldp
->hdcDst
, pimldp
->x
, pimldp
->y
, cx
, cy
, hImageDC
, 0, 0, SRCAND
);
1488 hOldBrush
= SelectObject (hImageDC
, GetStockObject(BLACK_BRUSH
));
1489 PatBlt( hImageDC
, 0, 0, cx
, cy
, PATCOPY
);
1490 SelectObject(hImageDC
, hOldBrush
);
1493 /* blend the image with the needed solid background */
1494 COLORREF colour
= RGB(0,0,0);
1496 if( !bIsTransparent
)
1498 colour
= pimldp
->rgbBk
;
1499 if( colour
== CLR_DEFAULT
)
1500 colour
= himl
->clrBk
;
1501 if( colour
== CLR_NONE
)
1502 colour
= GetBkColor(pimldp
->hdcDst
);
1505 hOldBrush
= SelectObject (hImageDC
, CreateSolidBrush (colour
));
1506 PatBlt( hImageDC
, 0, 0, cx
, cy
, PATCOPY
);
1509 BitBlt( hImageDC
, 0, 0, cx
, cy
, hMaskListDC
, pt
.x
, pt
.y
, SRCAND
);
1510 BitBlt( hImageDC
, 0, 0, cx
, cy
, hImageListDC
, pt
.x
, pt
.y
, SRCPAINT
);
1513 BitBlt( hImageDC
, 0, 0, cx
, cy
, hImageListDC
, pt
.x
, pt
.y
, SRCCOPY
);
1514 DeleteObject (SelectObject (hImageDC
, hOldBrush
));
1517 /* Time for blending, if required */
1520 COLORREF clrBlend
= pimldp
->rgbFg
;
1521 HDC hBlendMaskDC
= hImageListDC
;
1524 /* Create the blend Mask */
1525 hOldBitmap
= SelectObject(hBlendMaskDC
, hBlendMaskBmp
);
1526 hBlendBrush
= fStyle
& ILD_BLEND50
? himl
->hbrBlend50
: himl
->hbrBlend25
;
1527 hOldBrush
= SelectObject(hBlendMaskDC
, hBlendBrush
);
1528 PatBlt(hBlendMaskDC
, 0, 0, cx
, cy
, PATCOPY
);
1529 SelectObject(hBlendMaskDC
, hOldBrush
);
1531 /* Modify the blend mask if an Image Mask exist */
1533 BitBlt(hBlendMaskDC
, 0, 0, cx
, cy
, hMaskListDC
, pt
.x
, pt
.y
, 0x220326); /* NOTSRCAND */
1534 BitBlt(hBlendMaskDC
, 0, 0, cx
, cy
, hBlendMaskDC
, 0, 0, NOTSRCCOPY
);
1537 /* now apply blend to the current image given the BlendMask */
1538 if (clrBlend
== CLR_DEFAULT
) clrBlend
= GetSysColor (COLOR_HIGHLIGHT
);
1539 else if (clrBlend
== CLR_NONE
) clrBlend
= GetTextColor (pimldp
->hdcDst
);
1540 hOldBrush
= SelectObject (hImageDC
, CreateSolidBrush(clrBlend
));
1541 BitBlt (hImageDC
, 0, 0, cx
, cy
, hBlendMaskDC
, 0, 0, 0xB8074A); /* PSDPxax */
1542 DeleteObject(SelectObject(hImageDC
, hOldBrush
));
1543 SelectObject(hBlendMaskDC
, hOldBitmap
);
1546 /* Now do the overlay image, if any */
1547 nOvlIdx
= (pimldp
->fStyle
& ILD_OVERLAYMASK
) >> 8;
1548 if ( (nOvlIdx
>= 1) && (nOvlIdx
<= MAX_OVERLAYIMAGE
)) {
1549 nOvlIdx
= himl
->nOvlIdx
[nOvlIdx
- 1];
1550 if ((nOvlIdx
>= 0) && (nOvlIdx
< himl
->cCurImage
)) {
1552 imagelist_point_from_index( himl
, nOvlIdx
, &ptOvl
);
1553 ptOvl
.x
+= pimldp
->xBitmap
;
1554 if (himl
->hbmMask
&& !(fStyle
& ILD_IMAGE
))
1555 BitBlt (hImageDC
, 0, 0, cx
, cy
, hMaskListDC
, ptOvl
.x
, ptOvl
.y
, SRCAND
);
1556 BitBlt (hImageDC
, 0, 0, cx
, cy
, hImageListDC
, ptOvl
.x
, ptOvl
.y
, SRCPAINT
);
1560 if (fState
& ILS_SATURATE
) FIXME("ILS_SATURATE: unimplemented!\n");
1561 if (fState
& ILS_GLOW
) FIXME("ILS_GLOW: unimplemented!\n");
1562 if (fState
& ILS_SHADOW
) FIXME("ILS_SHADOW: unimplemented!\n");
1564 if (fStyle
& ILD_PRESERVEALPHA
) FIXME("ILD_PRESERVEALPHA: unimplemented!\n");
1565 if (fStyle
& ILD_SCALE
) FIXME("ILD_SCALE: unimplemented!\n");
1566 if (fStyle
& ILD_DPISCALE
) FIXME("ILD_DPISCALE: unimplemented!\n");
1568 /* now copy the image to the screen */
1570 if (himl
->hbmMask
&& bIsTransparent
) {
1571 COLORREF oldDstFg
= SetTextColor(pimldp
->hdcDst
, RGB( 0, 0, 0 ) );
1572 COLORREF oldDstBk
= SetBkColor(pimldp
->hdcDst
, RGB( 0xff, 0xff, 0xff ));
1573 BitBlt (pimldp
->hdcDst
, pimldp
->x
, pimldp
->y
, cx
, cy
, hMaskListDC
, pt
.x
, pt
.y
, SRCAND
);
1574 SetBkColor(pimldp
->hdcDst
, oldDstBk
);
1575 SetTextColor(pimldp
->hdcDst
, oldDstFg
);
1578 if (fStyle
& ILD_ROP
) dwRop
= pimldp
->dwRop
;
1579 BitBlt (pimldp
->hdcDst
, pimldp
->x
, pimldp
->y
, cx
, cy
, hImageDC
, 0, 0, dwRop
);
1583 /* cleanup the mess */
1584 SetBkColor(hImageDC
, oldImageBk
);
1585 SetTextColor(hImageDC
, oldImageFg
);
1586 SelectObject(hImageDC
, hOldImageBmp
);
1588 DeleteObject(hBlendMaskBmp
);
1589 DeleteObject(hImageBmp
);
1596 /*************************************************************************
1597 * ImageList_Duplicate [COMCTL32.@]
1599 * Duplicates an image list.
1602 * himlSrc [I] source image list handle
1605 * Success: Handle of duplicated image list.
1610 ImageList_Duplicate (HIMAGELIST himlSrc
)
1614 if (!is_valid(himlSrc
)) {
1615 ERR("Invalid image list handle!\n");
1619 himlDst
= ImageList_Create (himlSrc
->cx
, himlSrc
->cy
, himlSrc
->flags
,
1620 himlSrc
->cCurImage
, himlSrc
->cGrow
);
1626 imagelist_get_bitmap_size(himlSrc
, himlSrc
->cCurImage
, &sz
);
1627 BitBlt (himlDst
->hdcImage
, 0, 0, sz
.cx
, sz
.cy
,
1628 himlSrc
->hdcImage
, 0, 0, SRCCOPY
);
1630 if (himlDst
->hbmMask
)
1631 BitBlt (himlDst
->hdcMask
, 0, 0, sz
.cx
, sz
.cy
,
1632 himlSrc
->hdcMask
, 0, 0, SRCCOPY
);
1634 himlDst
->cCurImage
= himlSrc
->cCurImage
;
1635 if (himlSrc
->has_alpha
&& himlDst
->has_alpha
)
1636 memcpy( himlDst
->has_alpha
, himlSrc
->has_alpha
, himlDst
->cCurImage
);
1642 /*************************************************************************
1643 * ImageList_EndDrag [COMCTL32.@]
1645 * Finishes a drag operation.
1656 ImageList_EndDrag (void)
1658 /* cleanup the InternalDrag struct */
1659 InternalDrag
.hwnd
= 0;
1660 if (InternalDrag
.himl
!= InternalDrag
.himlNoCursor
)
1661 ImageList_Destroy (InternalDrag
.himlNoCursor
);
1662 ImageList_Destroy (InternalDrag
.himl
);
1663 InternalDrag
.himlNoCursor
= InternalDrag
.himl
= 0;
1666 InternalDrag
.dxHotspot
= 0;
1667 InternalDrag
.dyHotspot
= 0;
1668 InternalDrag
.bShow
= FALSE
;
1669 DeleteObject(InternalDrag
.hbmBg
);
1670 InternalDrag
.hbmBg
= 0;
1674 /*************************************************************************
1675 * ImageList_GetBkColor [COMCTL32.@]
1677 * Returns the background color of an image list.
1680 * himl [I] Image list handle.
1683 * Success: background color
1688 ImageList_GetBkColor (HIMAGELIST himl
)
1690 return himl
? himl
->clrBk
: CLR_NONE
;
1694 /*************************************************************************
1695 * ImageList_GetDragImage [COMCTL32.@]
1697 * Returns the handle to the internal drag image list.
1700 * ppt [O] Pointer to the drag position. Can be NULL.
1701 * pptHotspot [O] Pointer to the position of the hot spot. Can be NULL.
1704 * Success: Handle of the drag image list.
1709 ImageList_GetDragImage (POINT
*ppt
, POINT
*pptHotspot
)
1711 if (is_valid(InternalDrag
.himl
)) {
1713 ppt
->x
= InternalDrag
.x
;
1714 ppt
->y
= InternalDrag
.y
;
1717 pptHotspot
->x
= InternalDrag
.dxHotspot
;
1718 pptHotspot
->y
= InternalDrag
.dyHotspot
;
1720 return (InternalDrag
.himl
);
1727 /*************************************************************************
1728 * ImageList_GetFlags [COMCTL32.@]
1730 * Gets the flags of the specified image list.
1733 * himl [I] Handle to image list
1743 ImageList_GetFlags(HIMAGELIST himl
)
1745 TRACE("%p\n", himl
);
1747 return is_valid(himl
) ? himl
->flags
: 0;
1751 /*************************************************************************
1752 * ImageList_GetIcon [COMCTL32.@]
1754 * Creates an icon from a masked image of an image list.
1757 * himl [I] handle to image list
1759 * flags [I] drawing style flags
1762 * Success: icon handle
1767 ImageList_GetIcon (HIMAGELIST himl
, INT i
, UINT fStyle
)
1771 HBITMAP hOldDstBitmap
;
1775 TRACE("%p %d %d\n", himl
, i
, fStyle
);
1776 if (!is_valid(himl
) || (i
< 0) || (i
>= himl
->cCurImage
)) return NULL
;
1782 /* create colour bitmap */
1784 ii
.hbmColor
= CreateCompatibleBitmap(hdcDst
, himl
->cx
, himl
->cy
);
1785 ReleaseDC(0, hdcDst
);
1787 hdcDst
= CreateCompatibleDC(0);
1789 imagelist_point_from_index( himl
, i
, &pt
);
1792 ii
.hbmMask
= CreateBitmap (himl
->cx
, himl
->cy
, 1, 1, NULL
);
1793 hOldDstBitmap
= SelectObject (hdcDst
, ii
.hbmMask
);
1794 if (himl
->hbmMask
) {
1795 BitBlt (hdcDst
, 0, 0, himl
->cx
, himl
->cy
,
1796 himl
->hdcMask
, pt
.x
, pt
.y
, SRCCOPY
);
1799 PatBlt (hdcDst
, 0, 0, himl
->cx
, himl
->cy
, BLACKNESS
);
1802 SelectObject (hdcDst
, ii
.hbmColor
);
1803 BitBlt (hdcDst
, 0, 0, himl
->cx
, himl
->cy
,
1804 himl
->hdcImage
, pt
.x
, pt
.y
, SRCCOPY
);
1807 * CreateIconIndirect requires us to deselect the bitmaps from
1808 * the DCs before calling
1810 SelectObject(hdcDst
, hOldDstBitmap
);
1812 hIcon
= CreateIconIndirect (&ii
);
1814 DeleteObject (ii
.hbmMask
);
1815 DeleteObject (ii
.hbmColor
);
1822 /*************************************************************************
1823 * ImageList_GetIconSize [COMCTL32.@]
1825 * Retrieves the size of an image in an image list.
1828 * himl [I] handle to image list
1829 * cx [O] pointer to the image width.
1830 * cy [O] pointer to the image height.
1837 * All images in an image list have the same size.
1841 ImageList_GetIconSize (HIMAGELIST himl
, INT
*cx
, INT
*cy
)
1843 if (!is_valid(himl
) || !cx
|| !cy
)
1853 /*************************************************************************
1854 * ImageList_GetImageCount [COMCTL32.@]
1856 * Returns the number of images in an image list.
1859 * himl [I] handle to image list
1862 * Success: Number of images.
1867 ImageList_GetImageCount (HIMAGELIST himl
)
1869 if (!is_valid(himl
))
1872 return himl
->cCurImage
;
1876 /*************************************************************************
1877 * ImageList_GetImageInfo [COMCTL32.@]
1879 * Returns information about an image in an image list.
1882 * himl [I] handle to image list
1884 * pImageInfo [O] pointer to the image information
1892 ImageList_GetImageInfo (HIMAGELIST himl
, INT i
, IMAGEINFO
*pImageInfo
)
1896 if (!is_valid(himl
) || (pImageInfo
== NULL
))
1898 if ((i
< 0) || (i
>= himl
->cCurImage
))
1901 pImageInfo
->hbmImage
= himl
->hbmImage
;
1902 pImageInfo
->hbmMask
= himl
->hbmMask
;
1904 imagelist_point_from_index( himl
, i
, &pt
);
1905 pImageInfo
->rcImage
.top
= pt
.y
;
1906 pImageInfo
->rcImage
.bottom
= pt
.y
+ himl
->cy
;
1907 pImageInfo
->rcImage
.left
= pt
.x
;
1908 pImageInfo
->rcImage
.right
= pt
.x
+ himl
->cx
;
1914 /*************************************************************************
1915 * ImageList_GetImageRect [COMCTL32.@]
1917 * Retrieves the rectangle of the specified image in an image list.
1920 * himl [I] handle to image list
1922 * lpRect [O] pointer to the image rectangle
1929 * This is an UNDOCUMENTED function!!!
1933 ImageList_GetImageRect (HIMAGELIST himl
, INT i
, LPRECT lpRect
)
1937 if (!is_valid(himl
) || (lpRect
== NULL
))
1939 if ((i
< 0) || (i
>= himl
->cCurImage
))
1942 imagelist_point_from_index( himl
, i
, &pt
);
1943 lpRect
->left
= pt
.x
;
1945 lpRect
->right
= pt
.x
+ himl
->cx
;
1946 lpRect
->bottom
= pt
.y
+ himl
->cy
;
1952 /*************************************************************************
1953 * ImageList_LoadImage [COMCTL32.@]
1954 * ImageList_LoadImageA [COMCTL32.@]
1956 * Creates an image list from a bitmap, icon or cursor.
1958 * See ImageList_LoadImageW.
1962 ImageList_LoadImageA (HINSTANCE hi
, LPCSTR lpbmp
, INT cx
, INT cGrow
,
1963 COLORREF clrMask
, UINT uType
, UINT uFlags
)
1969 if (IS_INTRESOURCE(lpbmp
))
1970 return ImageList_LoadImageW(hi
, (LPCWSTR
)lpbmp
, cx
, cGrow
, clrMask
,
1973 len
= MultiByteToWideChar(CP_ACP
, 0, lpbmp
, -1, NULL
, 0);
1974 lpbmpW
= Alloc(len
* sizeof(WCHAR
));
1975 MultiByteToWideChar(CP_ACP
, 0, lpbmp
, -1, lpbmpW
, len
);
1977 himl
= ImageList_LoadImageW(hi
, lpbmpW
, cx
, cGrow
, clrMask
, uType
, uFlags
);
1983 /*************************************************************************
1984 * ImageList_LoadImageW [COMCTL32.@]
1986 * Creates an image list from a bitmap, icon or cursor.
1989 * hi [I] instance handle
1990 * lpbmp [I] name or id of the image
1991 * cx [I] width of each image
1992 * cGrow [I] number of images to expand
1993 * clrMask [I] mask color
1994 * uType [I] type of image to load
1995 * uFlags [I] loading flags
1998 * Success: handle to the loaded image list
2006 ImageList_LoadImageW (HINSTANCE hi
, LPCWSTR lpbmp
, INT cx
, INT cGrow
,
2007 COLORREF clrMask
, UINT uType
, UINT uFlags
)
2009 HIMAGELIST himl
= NULL
;
2013 handle
= LoadImageW (hi
, lpbmp
, uType
, 0, 0, uFlags
);
2015 WARN("Couldn't load image\n");
2019 if (uType
== IMAGE_BITMAP
) {
2023 if (GetObjectW (handle
, sizeof(dib
), &dib
) == sizeof(BITMAP
)) color
= ILC_COLOR
;
2024 else color
= dib
.dsBm
.bmBitsPixel
;
2026 /* To match windows behavior, if cx is set to zero and
2027 the flag DI_DEFAULTSIZE is specified, cx becomes the
2028 system metric value for icons. If the flag is not specified
2029 the function sets the size to the height of the bitmap */
2032 if (uFlags
& DI_DEFAULTSIZE
)
2033 cx
= GetSystemMetrics (SM_CXICON
);
2035 cx
= dib
.dsBm
.bmHeight
;
2038 nImageCount
= dib
.dsBm
.bmWidth
/ cx
;
2040 if (clrMask
!= CLR_NONE
) color
|= ILC_MASK
;
2041 himl
= ImageList_Create (cx
, dib
.dsBm
.bmHeight
, color
, nImageCount
, cGrow
);
2043 DeleteObject (handle
);
2046 ImageList_AddMasked (himl
, handle
, clrMask
);
2048 else if ((uType
== IMAGE_ICON
) || (uType
== IMAGE_CURSOR
)) {
2052 GetIconInfo (handle
, &ii
);
2053 GetObjectW (ii
.hbmColor
, sizeof(BITMAP
), &bmp
);
2054 himl
= ImageList_Create (bmp
.bmWidth
, bmp
.bmHeight
,
2055 ILC_MASK
| ILC_COLOR
, 1, cGrow
);
2057 DeleteObject (ii
.hbmColor
);
2058 DeleteObject (ii
.hbmMask
);
2059 DeleteObject (handle
);
2062 ImageList_Add (himl
, ii
.hbmColor
, ii
.hbmMask
);
2063 DeleteObject (ii
.hbmColor
);
2064 DeleteObject (ii
.hbmMask
);
2067 DeleteObject (handle
);
2073 /*************************************************************************
2074 * ImageList_Merge [COMCTL32.@]
2076 * Create an image list containing a merged image from two image lists.
2079 * himl1 [I] handle to first image list
2080 * i1 [I] first image index
2081 * himl2 [I] handle to second image list
2082 * i2 [I] second image index
2083 * dx [I] X offset of the second image relative to the first.
2084 * dy [I] Y offset of the second image relative to the first.
2087 * Success: The newly created image list. It contains a single image
2088 * consisting of the second image merged with the first.
2089 * Failure: NULL, if either himl1 or himl2 is invalid.
2092 * - The returned image list should be deleted by the caller using
2093 * ImageList_Destroy() when it is no longer required.
2094 * - If either i1 or i2 is not a valid image index, they will be treated
2098 ImageList_Merge (HIMAGELIST himl1
, INT i1
, HIMAGELIST himl2
, INT i2
,
2101 HIMAGELIST himlDst
= NULL
;
2103 INT xOff1
, yOff1
, xOff2
, yOff2
;
2107 TRACE("(himl1=%p i1=%d himl2=%p i2=%d dx=%d dy=%d)\n", himl1
, i1
, himl2
,
2110 if (!is_valid(himl1
) || !is_valid(himl2
))
2114 cxDst
= max (himl1
->cx
, dx
+ himl2
->cx
);
2119 cxDst
= max (himl2
->cx
, himl1
->cx
- dx
);
2124 cxDst
= max (himl1
->cx
, himl2
->cx
);
2130 cyDst
= max (himl1
->cy
, dy
+ himl2
->cy
);
2135 cyDst
= max (himl2
->cy
, himl1
->cy
- dy
);
2140 cyDst
= max (himl1
->cy
, himl2
->cy
);
2145 newFlags
= (himl1
->flags
> himl2
->flags
? himl1
->flags
: himl2
->flags
) & ILC_COLORDDB
;
2146 if (newFlags
== ILC_COLORDDB
&& (himl1
->flags
& ILC_COLORDDB
) == ILC_COLOR16
)
2147 newFlags
= ILC_COLOR16
; /* this is what native (at least v5) does, don't know why */
2148 himlDst
= ImageList_Create (cxDst
, cyDst
, ILC_MASK
| newFlags
, 1, 1);
2152 imagelist_point_from_index( himl1
, i1
, &pt1
);
2153 imagelist_point_from_index( himl2
, i2
, &pt2
);
2156 BitBlt (himlDst
->hdcImage
, 0, 0, cxDst
, cyDst
, himl1
->hdcImage
, 0, 0, BLACKNESS
);
2157 if (i1
>= 0 && i1
< himl1
->cCurImage
)
2158 BitBlt (himlDst
->hdcImage
, xOff1
, yOff1
, himl1
->cx
, himl1
->cy
, himl1
->hdcImage
, pt1
.x
, pt1
.y
, SRCCOPY
);
2159 if (i2
>= 0 && i2
< himl2
->cCurImage
)
2161 if (himl2
->flags
& ILC_MASK
)
2163 BitBlt (himlDst
->hdcImage
, xOff2
, yOff2
, himl2
->cx
, himl2
->cy
, himl2
->hdcMask
, pt2
.x
, pt2
.y
, SRCAND
);
2164 BitBlt (himlDst
->hdcImage
, xOff2
, yOff2
, himl2
->cx
, himl2
->cy
, himl2
->hdcImage
, pt2
.x
, pt2
.y
, SRCPAINT
);
2167 BitBlt (himlDst
->hdcImage
, xOff2
, yOff2
, himl2
->cx
, himl2
->cy
, himl2
->hdcImage
, pt2
.x
, pt2
.y
, SRCCOPY
);
2171 BitBlt (himlDst
->hdcMask
, 0, 0, cxDst
, cyDst
, himl1
->hdcMask
, 0, 0, WHITENESS
);
2172 if (i1
>= 0 && i1
< himl1
->cCurImage
)
2173 BitBlt (himlDst
->hdcMask
, xOff1
, yOff1
, himl1
->cx
, himl1
->cy
, himl1
->hdcMask
, pt1
.x
, pt1
.y
, SRCCOPY
);
2174 if (i2
>= 0 && i2
< himl2
->cCurImage
)
2175 BitBlt (himlDst
->hdcMask
, xOff2
, yOff2
, himl2
->cx
, himl2
->cy
, himl2
->hdcMask
, pt2
.x
, pt2
.y
, SRCAND
);
2177 himlDst
->cCurImage
= 1;
2184 /* helper for ImageList_Read, see comments below */
2185 static void *read_bitmap(IStream
*pstm
, BITMAPINFO
*bmi
)
2187 BITMAPFILEHEADER bmfh
;
2188 int bitsperpixel
, palspace
;
2191 if (FAILED(IStream_Read ( pstm
, &bmfh
, sizeof(bmfh
), NULL
)))
2194 if (bmfh
.bfType
!= (('M'<<8)|'B'))
2197 if (FAILED(IStream_Read ( pstm
, &bmi
->bmiHeader
, sizeof(bmi
->bmiHeader
), NULL
)))
2200 if ((bmi
->bmiHeader
.biSize
!= sizeof(bmi
->bmiHeader
)))
2203 TRACE("width %u, height %u, planes %u, bpp %u\n",
2204 bmi
->bmiHeader
.biWidth
, bmi
->bmiHeader
.biHeight
,
2205 bmi
->bmiHeader
.biPlanes
, bmi
->bmiHeader
.biBitCount
);
2207 bitsperpixel
= bmi
->bmiHeader
.biPlanes
* bmi
->bmiHeader
.biBitCount
;
2208 if (bitsperpixel
<=8)
2209 palspace
= (1<<bitsperpixel
)*sizeof(RGBQUAD
);
2213 bmi
->bmiHeader
.biSizeImage
= get_dib_image_size( bmi
);
2215 /* read the palette right after the end of the bitmapinfoheader */
2216 if (palspace
&& FAILED(IStream_Read(pstm
, bmi
->bmiColors
, palspace
, NULL
)))
2219 bits
= Alloc(bmi
->bmiHeader
.biSizeImage
);
2220 if (!bits
) return NULL
;
2222 if (FAILED(IStream_Read(pstm
, bits
, bmi
->bmiHeader
.biSizeImage
, NULL
)))
2230 /*************************************************************************
2231 * ImageList_Read [COMCTL32.@]
2233 * Reads an image list from a stream.
2236 * pstm [I] pointer to a stream
2239 * Success: handle to image list
2242 * The format is like this:
2243 * ILHEAD ilheadstruct;
2245 * for the color image part:
2246 * BITMAPFILEHEADER bmfh;
2247 * BITMAPINFOHEADER bmih;
2248 * only if it has a palette:
2249 * RGBQUAD rgbs[nr_of_paletted_colors];
2251 * BYTE colorbits[imagesize];
2253 * the following only if the ILC_MASK bit is set in ILHEAD.ilFlags:
2254 * BITMAPFILEHEADER bmfh_mask;
2255 * BITMAPINFOHEADER bmih_mask;
2256 * only if it has a palette (it usually does not):
2257 * RGBQUAD rgbs[nr_of_paletted_colors];
2259 * BYTE maskbits[imagesize];
2261 HIMAGELIST WINAPI
ImageList_Read(IStream
*pstm
)
2263 char image_buf
[sizeof(BITMAPINFOHEADER
) + sizeof(RGBQUAD
) * 256];
2264 char mask_buf
[sizeof(BITMAPINFOHEADER
) + sizeof(RGBQUAD
) * 256];
2265 BITMAPINFO
*image_info
= (BITMAPINFO
*)image_buf
;
2266 BITMAPINFO
*mask_info
= (BITMAPINFO
*)mask_buf
;
2267 void *image_bits
, *mask_bits
= NULL
;
2272 TRACE("%p\n", pstm
);
2274 if (FAILED(IStream_Read (pstm
, &ilHead
, sizeof(ILHEAD
), NULL
)))
2276 if (ilHead
.usMagic
!= (('L' << 8) | 'I'))
2278 if (ilHead
.usVersion
!= 0x101) /* probably version? */
2281 TRACE("cx %u, cy %u, flags 0x%04x, cCurImage %u, cMaxImage %u\n",
2282 ilHead
.cx
, ilHead
.cy
, ilHead
.flags
, ilHead
.cCurImage
, ilHead
.cMaxImage
);
2284 himl
= ImageList_Create(ilHead
.cx
, ilHead
.cy
, ilHead
.flags
, ilHead
.cCurImage
, ilHead
.cMaxImage
);
2288 if (!(image_bits
= read_bitmap(pstm
, image_info
)))
2290 WARN("failed to read bitmap from stream\n");
2293 if (ilHead
.flags
& ILC_MASK
)
2295 if (!(mask_bits
= read_bitmap(pstm
, mask_info
)))
2297 WARN("failed to read mask bitmap from stream\n");
2301 else mask_info
= NULL
;
2303 if (himl
->has_alpha
&& image_info
->bmiHeader
.biBitCount
== 32)
2305 DWORD
*ptr
= image_bits
;
2306 BYTE
*mask_ptr
= mask_bits
;
2307 int stride
= himl
->cy
* image_info
->bmiHeader
.biWidth
;
2309 if (image_info
->bmiHeader
.biHeight
> 0) /* bottom-up */
2311 ptr
+= image_info
->bmiHeader
.biHeight
* image_info
->bmiHeader
.biWidth
- stride
;
2312 mask_ptr
+= (image_info
->bmiHeader
.biHeight
* image_info
->bmiHeader
.biWidth
- stride
) / 8;
2314 image_info
->bmiHeader
.biHeight
= himl
->cy
;
2316 else image_info
->bmiHeader
.biHeight
= -himl
->cy
;
2318 for (i
= 0; i
< ilHead
.cCurImage
; i
+= TILE_COUNT
)
2320 add_dib_bits( himl
, i
, min( ilHead
.cCurImage
- i
, TILE_COUNT
),
2321 himl
->cx
, himl
->cy
, image_info
, mask_info
, ptr
, mask_ptr
);
2323 mask_ptr
+= stride
/ 8;
2328 StretchDIBits( himl
->hdcImage
, 0, 0, image_info
->bmiHeader
.biWidth
, image_info
->bmiHeader
.biHeight
,
2329 0, 0, image_info
->bmiHeader
.biWidth
, image_info
->bmiHeader
.biHeight
,
2330 image_bits
, image_info
, DIB_RGB_COLORS
, SRCCOPY
);
2332 StretchDIBits( himl
->hdcMask
, 0, 0, mask_info
->bmiHeader
.biWidth
, mask_info
->bmiHeader
.biHeight
,
2333 0, 0, mask_info
->bmiHeader
.biWidth
, mask_info
->bmiHeader
.biHeight
,
2334 mask_bits
, mask_info
, DIB_RGB_COLORS
, SRCCOPY
);
2339 himl
->cCurImage
= ilHead
.cCurImage
;
2340 himl
->cMaxImage
= ilHead
.cMaxImage
;
2342 ImageList_SetBkColor(himl
,ilHead
.bkcolor
);
2344 ImageList_SetOverlayImage(himl
,ilHead
.ovls
[i
],i
+1);
2349 /*************************************************************************
2350 * ImageList_Remove [COMCTL32.@]
2352 * Removes an image from an image list
2355 * himl [I] image list handle
2362 * FIXME: as the image list storage test shows, native comctl32 simply shifts
2363 * images without creating a new bitmap.
2366 ImageList_Remove (HIMAGELIST himl
, INT i
)
2368 HBITMAP hbmNewImage
, hbmNewMask
;
2372 TRACE("(himl=%p i=%d)\n", himl
, i
);
2374 if (!is_valid(himl
)) {
2375 ERR("Invalid image list handle!\n");
2379 if ((i
< -1) || (i
>= himl
->cCurImage
)) {
2380 TRACE("index out of range! %d\n", i
);
2388 if (himl
->cCurImage
== 0) {
2389 /* remove all on empty ImageList is allowed */
2390 TRACE("remove all on empty ImageList!\n");
2394 himl
->cMaxImage
= himl
->cGrow
;
2395 himl
->cCurImage
= 0;
2396 for (nCount
= 0; nCount
< MAX_OVERLAYIMAGE
; nCount
++)
2397 himl
->nOvlIdx
[nCount
] = -1;
2399 if (himl
->has_alpha
)
2401 HeapFree( GetProcessHeap(), 0, himl
->has_alpha
);
2402 himl
->has_alpha
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, himl
->cMaxImage
);
2405 hbmNewImage
= ImageList_CreateImage(himl
->hdcImage
, himl
, himl
->cMaxImage
);
2406 SelectObject (himl
->hdcImage
, hbmNewImage
);
2407 DeleteObject (himl
->hbmImage
);
2408 himl
->hbmImage
= hbmNewImage
;
2410 if (himl
->hbmMask
) {
2412 imagelist_get_bitmap_size(himl
, himl
->cMaxImage
, &sz
);
2413 hbmNewMask
= CreateBitmap (sz
.cx
, sz
.cy
, 1, 1, NULL
);
2414 SelectObject (himl
->hdcMask
, hbmNewMask
);
2415 DeleteObject (himl
->hbmMask
);
2416 himl
->hbmMask
= hbmNewMask
;
2420 /* delete one image */
2421 TRACE("Remove single image! %d\n", i
);
2423 /* create new bitmap(s) */
2424 TRACE(" - Number of images: %d / %d (Old/New)\n",
2425 himl
->cCurImage
, himl
->cCurImage
- 1);
2427 hbmNewImage
= ImageList_CreateImage(himl
->hdcImage
, himl
, himl
->cMaxImage
);
2429 imagelist_get_bitmap_size(himl
, himl
->cMaxImage
, &sz
);
2431 hbmNewMask
= CreateBitmap (sz
.cx
, sz
.cy
, 1, 1, NULL
);
2433 hbmNewMask
= 0; /* Just to keep compiler happy! */
2435 hdcBmp
= CreateCompatibleDC (0);
2437 /* copy all images and masks prior to the "removed" image */
2439 TRACE("Pre image copy: Copy %d images\n", i
);
2441 SelectObject (hdcBmp
, hbmNewImage
);
2442 imagelist_copy_images( himl
, himl
->hdcImage
, hdcBmp
, 0, i
, 0 );
2444 if (himl
->hbmMask
) {
2445 SelectObject (hdcBmp
, hbmNewMask
);
2446 imagelist_copy_images( himl
, himl
->hdcMask
, hdcBmp
, 0, i
, 0 );
2450 /* copy all images and masks behind the removed image */
2451 if (i
< himl
->cCurImage
- 1) {
2452 TRACE("Post image copy!\n");
2454 SelectObject (hdcBmp
, hbmNewImage
);
2455 imagelist_copy_images( himl
, himl
->hdcImage
, hdcBmp
, i
+ 1,
2456 (himl
->cCurImage
- i
), i
);
2458 if (himl
->hbmMask
) {
2459 SelectObject (hdcBmp
, hbmNewMask
);
2460 imagelist_copy_images( himl
, himl
->hdcMask
, hdcBmp
, i
+ 1,
2461 (himl
->cCurImage
- i
), i
);
2467 /* delete old images and insert new ones */
2468 SelectObject (himl
->hdcImage
, hbmNewImage
);
2469 DeleteObject (himl
->hbmImage
);
2470 himl
->hbmImage
= hbmNewImage
;
2471 if (himl
->hbmMask
) {
2472 SelectObject (himl
->hdcMask
, hbmNewMask
);
2473 DeleteObject (himl
->hbmMask
);
2474 himl
->hbmMask
= hbmNewMask
;
2484 /*************************************************************************
2485 * ImageList_Replace [COMCTL32.@]
2487 * Replaces an image in an image list with a new image.
2490 * himl [I] handle to image list
2492 * hbmImage [I] handle to image bitmap
2493 * hbmMask [I] handle to mask bitmap. Can be NULL.
2501 ImageList_Replace (HIMAGELIST himl
, INT i
, HBITMAP hbmImage
,
2508 TRACE("%p %d %p %p\n", himl
, i
, hbmImage
, hbmMask
);
2510 if (!is_valid(himl
)) {
2511 ERR("Invalid image list handle!\n");
2515 if ((i
>= himl
->cMaxImage
) || (i
< 0)) {
2516 ERR("Invalid image index!\n");
2520 if (!GetObjectW(hbmImage
, sizeof(BITMAP
), &bmp
))
2523 hdcImage
= CreateCompatibleDC (0);
2526 SelectObject (hdcImage
, hbmImage
);
2528 if (add_with_alpha( himl
, hdcImage
, i
, 1, bmp
.bmWidth
, bmp
.bmHeight
, hbmImage
, hbmMask
))
2531 imagelist_point_from_index(himl
, i
, &pt
);
2532 StretchBlt (himl
->hdcImage
, pt
.x
, pt
.y
, himl
->cx
, himl
->cy
,
2533 hdcImage
, 0, 0, bmp
.bmWidth
, bmp
.bmHeight
, SRCCOPY
);
2538 HBITMAP hOldBitmapTemp
;
2540 hdcTemp
= CreateCompatibleDC(0);
2541 hOldBitmapTemp
= SelectObject(hdcTemp
, hbmMask
);
2543 StretchBlt (himl
->hdcMask
, pt
.x
, pt
.y
, himl
->cx
, himl
->cy
,
2544 hdcTemp
, 0, 0, bmp
.bmWidth
, bmp
.bmHeight
, SRCCOPY
);
2545 SelectObject(hdcTemp
, hOldBitmapTemp
);
2548 /* Remove the background from the image
2550 BitBlt (himl
->hdcImage
, pt
.x
, pt
.y
, bmp
.bmWidth
, bmp
.bmHeight
,
2551 himl
->hdcMask
, pt
.x
, pt
.y
, 0x220326); /* NOTSRCAND */
2555 DeleteDC (hdcImage
);
2561 /*************************************************************************
2562 * ImageList_ReplaceIcon [COMCTL32.@]
2564 * Replaces an image in an image list using an icon.
2567 * himl [I] handle to image list
2569 * hIcon [I] handle to icon
2572 * Success: index of the replaced image
2577 ImageList_ReplaceIcon (HIMAGELIST himl
, INT nIndex
, HICON hIcon
)
2585 TRACE("(%p %d %p)\n", himl
, nIndex
, hIcon
);
2587 if (!is_valid(himl
)) {
2588 ERR("invalid image list\n");
2591 if ((nIndex
>= himl
->cMaxImage
) || (nIndex
< -1)) {
2592 ERR("invalid image index %d / %d\n", nIndex
, himl
->cMaxImage
);
2596 hBestFitIcon
= CopyImage(
2599 LR_COPYFROMRESOURCE
);
2600 /* the above will fail if the icon wasn't loaded from a resource, so try
2601 * again without LR_COPYFROMRESOURCE flag */
2603 hBestFitIcon
= CopyImage(
2611 if (himl
->cCurImage
+ 1 >= himl
->cMaxImage
)
2612 IMAGELIST_InternalExpandBitmaps(himl
, 1);
2614 nIndex
= himl
->cCurImage
;
2618 if (himl
->has_alpha
&& GetIconInfo (hBestFitIcon
, &ii
))
2620 HDC hdcImage
= CreateCompatibleDC( 0 );
2621 GetObjectW (ii
.hbmMask
, sizeof(BITMAP
), &bmp
);
2625 UINT height
= bmp
.bmHeight
/ 2;
2626 HDC hdcMask
= CreateCompatibleDC( 0 );
2627 HBITMAP color
= CreateBitmap( bmp
.bmWidth
, height
, 1, 1, NULL
);
2628 SelectObject( hdcImage
, color
);
2629 SelectObject( hdcMask
, ii
.hbmMask
);
2630 BitBlt( hdcImage
, 0, 0, bmp
.bmWidth
, height
, hdcMask
, 0, height
, SRCCOPY
);
2631 ret
= add_with_alpha( himl
, hdcImage
, nIndex
, 1, bmp
.bmWidth
, height
, color
, ii
.hbmMask
);
2632 DeleteDC( hdcMask
);
2633 DeleteObject( color
);
2635 else ret
= add_with_alpha( himl
, hdcImage
, nIndex
, 1, bmp
.bmWidth
, bmp
.bmHeight
,
2636 ii
.hbmColor
, ii
.hbmMask
);
2638 DeleteDC( hdcImage
);
2639 DeleteObject (ii
.hbmMask
);
2640 if (ii
.hbmColor
) DeleteObject (ii
.hbmColor
);
2644 imagelist_point_from_index(himl
, nIndex
, &pt
);
2648 DrawIconEx( himl
->hdcImage
, pt
.x
, pt
.y
, hBestFitIcon
, himl
->cx
, himl
->cy
, 0, 0, DI_IMAGE
);
2649 PatBlt( himl
->hdcMask
, pt
.x
, pt
.y
, himl
->cx
, himl
->cy
, WHITENESS
);
2650 DrawIconEx( himl
->hdcMask
, pt
.x
, pt
.y
, hBestFitIcon
, himl
->cx
, himl
->cy
, 0, 0, DI_MASK
);
2654 COLORREF color
= himl
->clrBk
!= CLR_NONE
? himl
->clrBk
: comctl32_color
.clrWindow
;
2655 HBRUSH brush
= CreateSolidBrush( GetNearestColor( himl
->hdcImage
, color
));
2657 SelectObject( himl
->hdcImage
, brush
);
2658 PatBlt( himl
->hdcImage
, pt
.x
, pt
.y
, himl
->cx
, himl
->cy
, PATCOPY
);
2659 SelectObject( himl
->hdcImage
, GetStockObject(BLACK_BRUSH
) );
2660 DeleteObject( brush
);
2661 DrawIconEx( himl
->hdcImage
, pt
.x
, pt
.y
, hBestFitIcon
, himl
->cx
, himl
->cy
, 0, 0, DI_NORMAL
);
2665 DestroyIcon(hBestFitIcon
);
2667 TRACE("Insert index = %d, himl->cCurImage = %d\n", nIndex
, himl
->cCurImage
);
2672 /*************************************************************************
2673 * ImageList_SetBkColor [COMCTL32.@]
2675 * Sets the background color of an image list.
2678 * himl [I] handle to image list
2679 * clrBk [I] background color
2682 * Success: previous background color
2687 ImageList_SetBkColor (HIMAGELIST himl
, COLORREF clrBk
)
2691 if (!is_valid(himl
))
2694 clrOldBk
= himl
->clrBk
;
2695 himl
->clrBk
= clrBk
;
2700 /*************************************************************************
2701 * ImageList_SetDragCursorImage [COMCTL32.@]
2703 * Combines the specified image with the current drag image
2706 * himlDrag [I] handle to drag image list
2707 * iDrag [I] drag image index
2708 * dxHotspot [I] X position of the hot spot
2709 * dyHotspot [I] Y position of the hot spot
2716 * - The names dxHotspot, dyHotspot are misleading because they have nothing
2717 * to do with a hotspot but are only the offset of the origin of the new
2718 * image relative to the origin of the old image.
2720 * - When this function is called and the drag image is visible, a
2721 * short flickering occurs but this matches the Win9x behavior. It is
2722 * possible to fix the flickering using code like in ImageList_DragMove.
2726 ImageList_SetDragCursorImage (HIMAGELIST himlDrag
, INT iDrag
,
2727 INT dxHotspot
, INT dyHotspot
)
2729 HIMAGELIST himlTemp
;
2732 if (!is_valid(InternalDrag
.himl
) || !is_valid(himlDrag
))
2735 TRACE(" dxH=%d dyH=%d nX=%d nY=%d\n",
2736 dxHotspot
, dyHotspot
, InternalDrag
.dxHotspot
, InternalDrag
.dyHotspot
);
2738 visible
= InternalDrag
.bShow
;
2740 himlTemp
= ImageList_Merge (InternalDrag
.himlNoCursor
, 0, himlDrag
, iDrag
,
2741 dxHotspot
, dyHotspot
);
2744 /* hide the drag image */
2745 ImageList_DragShowNolock(FALSE
);
2747 if ((InternalDrag
.himl
->cx
!= himlTemp
->cx
) ||
2748 (InternalDrag
.himl
->cy
!= himlTemp
->cy
)) {
2749 /* the size of the drag image changed, invalidate the buffer */
2750 DeleteObject(InternalDrag
.hbmBg
);
2751 InternalDrag
.hbmBg
= 0;
2754 if (InternalDrag
.himl
!= InternalDrag
.himlNoCursor
)
2755 ImageList_Destroy (InternalDrag
.himl
);
2756 InternalDrag
.himl
= himlTemp
;
2759 /* show the drag image */
2760 ImageList_DragShowNolock(TRUE
);
2767 /*************************************************************************
2768 * ImageList_SetFilter [COMCTL32.@]
2770 * Sets a filter (or does something completely different)!!???
2771 * It removes 12 Bytes from the stack (3 Parameters).
2774 * himl [I] SHOULD be a handle to image list
2775 * i [I] COULD be an index?
2780 * Failure: FALSE ???
2783 * This is an UNDOCUMENTED function!!!!
2788 ImageList_SetFilter (HIMAGELIST himl
, INT i
, DWORD dwFilter
)
2790 FIXME("(%p 0x%x 0x%x):empty stub!\n", himl
, i
, dwFilter
);
2796 /*************************************************************************
2797 * ImageList_SetFlags [COMCTL32.@]
2799 * Sets the image list flags.
2802 * himl [I] Handle to image list
2803 * flags [I] Flags to set
2813 ImageList_SetFlags(HIMAGELIST himl
, DWORD flags
)
2815 FIXME("(%p %08x):empty stub\n", himl
, flags
);
2820 /*************************************************************************
2821 * ImageList_SetIconSize [COMCTL32.@]
2823 * Sets the image size of the bitmap and deletes all images.
2826 * himl [I] handle to image list
2827 * cx [I] image width
2828 * cy [I] image height
2836 ImageList_SetIconSize (HIMAGELIST himl
, INT cx
, INT cy
)
2841 if (!is_valid(himl
))
2844 /* remove all images */
2845 himl
->cMaxImage
= himl
->cInitial
+ 1;
2846 himl
->cCurImage
= 0;
2850 /* initialize overlay mask indices */
2851 for (nCount
= 0; nCount
< MAX_OVERLAYIMAGE
; nCount
++)
2852 himl
->nOvlIdx
[nCount
] = -1;
2854 hbmNew
= ImageList_CreateImage(himl
->hdcImage
, himl
, himl
->cMaxImage
);
2855 SelectObject (himl
->hdcImage
, hbmNew
);
2856 DeleteObject (himl
->hbmImage
);
2857 himl
->hbmImage
= hbmNew
;
2859 if (himl
->hbmMask
) {
2861 imagelist_get_bitmap_size(himl
, himl
->cMaxImage
, &sz
);
2862 hbmNew
= CreateBitmap (sz
.cx
, sz
.cy
, 1, 1, NULL
);
2863 SelectObject (himl
->hdcMask
, hbmNew
);
2864 DeleteObject (himl
->hbmMask
);
2865 himl
->hbmMask
= hbmNew
;
2872 /*************************************************************************
2873 * ImageList_SetImageCount [COMCTL32.@]
2875 * Resizes an image list to the specified number of images.
2878 * himl [I] handle to image list
2879 * iImageCount [I] number of images in the image list
2887 ImageList_SetImageCount (HIMAGELIST himl
, UINT iImageCount
)
2890 HBITMAP hbmNewBitmap
, hbmOld
;
2891 INT nNewCount
, nCopyCount
;
2893 TRACE("%p %d\n",himl
,iImageCount
);
2895 if (!is_valid(himl
))
2898 nNewCount
= iImageCount
+ 1;
2899 nCopyCount
= min(himl
->cCurImage
, iImageCount
);
2901 hdcBitmap
= CreateCompatibleDC (0);
2903 hbmNewBitmap
= ImageList_CreateImage(hdcBitmap
, himl
, nNewCount
);
2905 if (hbmNewBitmap
!= 0)
2907 hbmOld
= SelectObject (hdcBitmap
, hbmNewBitmap
);
2908 imagelist_copy_images( himl
, himl
->hdcImage
, hdcBitmap
, 0, nCopyCount
, 0 );
2909 SelectObject (hdcBitmap
, hbmOld
);
2911 /* FIXME: delete 'empty' image space? */
2913 SelectObject (himl
->hdcImage
, hbmNewBitmap
);
2914 DeleteObject (himl
->hbmImage
);
2915 himl
->hbmImage
= hbmNewBitmap
;
2918 ERR("Could not create new image bitmap!\n");
2923 imagelist_get_bitmap_size( himl
, nNewCount
, &sz
);
2924 hbmNewBitmap
= CreateBitmap (sz
.cx
, sz
.cy
, 1, 1, NULL
);
2925 if (hbmNewBitmap
!= 0)
2927 hbmOld
= SelectObject (hdcBitmap
, hbmNewBitmap
);
2928 imagelist_copy_images( himl
, himl
->hdcMask
, hdcBitmap
, 0, nCopyCount
, 0 );
2929 SelectObject (hdcBitmap
, hbmOld
);
2931 /* FIXME: delete 'empty' image space? */
2933 SelectObject (himl
->hdcMask
, hbmNewBitmap
);
2934 DeleteObject (himl
->hbmMask
);
2935 himl
->hbmMask
= hbmNewBitmap
;
2938 ERR("Could not create new mask bitmap!\n");
2941 DeleteDC (hdcBitmap
);
2943 if (himl
->has_alpha
)
2945 char *new_alpha
= HeapReAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, himl
->has_alpha
, nNewCount
);
2946 if (new_alpha
) himl
->has_alpha
= new_alpha
;
2949 HeapFree( GetProcessHeap(), 0, himl
->has_alpha
);
2950 himl
->has_alpha
= NULL
;
2954 /* Update max image count and current image count */
2955 himl
->cMaxImage
= nNewCount
;
2956 himl
->cCurImage
= iImageCount
;
2962 /*************************************************************************
2963 * ImageList_SetOverlayImage [COMCTL32.@]
2965 * Assigns an overlay mask index to an existing image in an image list.
2968 * himl [I] handle to image list
2969 * iImage [I] image index
2970 * iOverlay [I] overlay mask index
2978 ImageList_SetOverlayImage (HIMAGELIST himl
, INT iImage
, INT iOverlay
)
2980 if (!is_valid(himl
))
2982 if ((iOverlay
< 1) || (iOverlay
> MAX_OVERLAYIMAGE
))
2984 if ((iImage
!=-1) && ((iImage
< 0) || (iImage
> himl
->cCurImage
)))
2986 himl
->nOvlIdx
[iOverlay
- 1] = iImage
;
2992 /* helper for ImageList_Write - write bitmap to pstm
2993 * currently everything is written as 24 bit RGB, except masks
2995 static BOOL
_write_bitmap(HBITMAP hBitmap
, IStream
*pstm
)
2997 LPBITMAPFILEHEADER bmfh
;
2998 LPBITMAPINFOHEADER bmih
;
2999 LPBYTE data
= NULL
, lpBits
;
3001 INT bitCount
, sizeImage
, offBits
, totalSize
;
3003 BOOL result
= FALSE
;
3005 if (!GetObjectW(hBitmap
, sizeof(BITMAP
), &bm
))
3008 bitCount
= bm
.bmBitsPixel
;
3009 sizeImage
= get_dib_stride(bm
.bmWidth
, bitCount
) * bm
.bmHeight
;
3011 totalSize
= sizeof(BITMAPFILEHEADER
) + sizeof(BITMAPINFOHEADER
);
3013 totalSize
+= (1 << bitCount
) * sizeof(RGBQUAD
);
3014 offBits
= totalSize
;
3015 totalSize
+= sizeImage
;
3017 data
= Alloc(totalSize
);
3018 bmfh
= (LPBITMAPFILEHEADER
)data
;
3019 bmih
= (LPBITMAPINFOHEADER
)(data
+ sizeof(BITMAPFILEHEADER
));
3020 lpBits
= data
+ offBits
;
3022 /* setup BITMAPFILEHEADER */
3023 bmfh
->bfType
= (('M' << 8) | 'B');
3024 bmfh
->bfSize
= offBits
;
3025 bmfh
->bfReserved1
= 0;
3026 bmfh
->bfReserved2
= 0;
3027 bmfh
->bfOffBits
= offBits
;
3029 /* setup BITMAPINFOHEADER */
3030 bmih
->biSize
= sizeof(BITMAPINFOHEADER
);
3031 bmih
->biWidth
= bm
.bmWidth
;
3032 bmih
->biHeight
= bm
.bmHeight
;
3034 bmih
->biBitCount
= bitCount
;
3035 bmih
->biCompression
= BI_RGB
;
3036 bmih
->biSizeImage
= sizeImage
;
3037 bmih
->biXPelsPerMeter
= 0;
3038 bmih
->biYPelsPerMeter
= 0;
3039 bmih
->biClrUsed
= 0;
3040 bmih
->biClrImportant
= 0;
3043 result
= GetDIBits(xdc
, hBitmap
, 0, bm
.bmHeight
, lpBits
, (BITMAPINFO
*)bmih
, DIB_RGB_COLORS
) == bm
.bmHeight
;
3048 TRACE("width %u, height %u, planes %u, bpp %u\n",
3049 bmih
->biWidth
, bmih
->biHeight
,
3050 bmih
->biPlanes
, bmih
->biBitCount
);
3052 if(FAILED(IStream_Write(pstm
, data
, totalSize
, NULL
)))
3064 /*************************************************************************
3065 * ImageList_Write [COMCTL32.@]
3067 * Writes an image list to a stream.
3070 * himl [I] handle to image list
3071 * pstm [O] Pointer to a stream.
3081 BOOL WINAPI
ImageList_Write(HIMAGELIST himl
, IStream
*pstm
)
3086 TRACE("%p %p\n", himl
, pstm
);
3088 if (!is_valid(himl
))
3091 ilHead
.usMagic
= (('L' << 8) | 'I');
3092 ilHead
.usVersion
= 0x101;
3093 ilHead
.cCurImage
= himl
->cCurImage
;
3094 ilHead
.cMaxImage
= himl
->cMaxImage
;
3095 ilHead
.cGrow
= himl
->cGrow
;
3096 ilHead
.cx
= himl
->cx
;
3097 ilHead
.cy
= himl
->cy
;
3098 ilHead
.bkcolor
= himl
->clrBk
;
3099 ilHead
.flags
= himl
->flags
;
3100 for(i
= 0; i
< 4; i
++) {
3101 ilHead
.ovls
[i
] = himl
->nOvlIdx
[i
];
3104 TRACE("cx %u, cy %u, flags 0x04%x, cCurImage %u, cMaxImage %u\n",
3105 ilHead
.cx
, ilHead
.cy
, ilHead
.flags
, ilHead
.cCurImage
, ilHead
.cMaxImage
);
3107 if(FAILED(IStream_Write(pstm
, &ilHead
, sizeof(ILHEAD
), NULL
)))
3110 /* write the bitmap */
3111 if(!_write_bitmap(himl
->hbmImage
, pstm
))
3114 /* write the mask if we have one */
3115 if(himl
->flags
& ILC_MASK
) {
3116 if(!_write_bitmap(himl
->hbmMask
, pstm
))
3124 static HBITMAP
ImageList_CreateImage(HDC hdc
, HIMAGELIST himl
, UINT count
)
3126 HBITMAP hbmNewBitmap
;
3127 UINT ilc
= (himl
->flags
& 0xFE);
3130 imagelist_get_bitmap_size( himl
, count
, &sz
);
3132 if ((ilc
>= ILC_COLOR4
&& ilc
<= ILC_COLOR32
) || ilc
== ILC_COLOR
)
3134 char buffer
[sizeof(BITMAPINFOHEADER
) + 256 * sizeof(RGBQUAD
)];
3135 BITMAPINFO
*bmi
= (BITMAPINFO
*)buffer
;
3137 TRACE("Creating DIBSection %d x %d, %d Bits per Pixel\n",
3138 sz
.cx
, sz
.cy
, himl
->uBitsPixel
);
3140 memset( buffer
, 0, sizeof(buffer
) );
3141 bmi
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
3142 bmi
->bmiHeader
.biWidth
= sz
.cx
;
3143 bmi
->bmiHeader
.biHeight
= sz
.cy
;
3144 bmi
->bmiHeader
.biPlanes
= 1;
3145 bmi
->bmiHeader
.biBitCount
= himl
->uBitsPixel
;
3146 bmi
->bmiHeader
.biCompression
= BI_RGB
;
3148 if (himl
->uBitsPixel
<= ILC_COLOR8
)
3150 if (!himl
->color_table_set
)
3152 /* retrieve the default color map */
3153 HBITMAP tmp
= CreateBitmap( 1, 1, 1, 1, NULL
);
3154 GetDIBits( hdc
, tmp
, 0, 0, NULL
, bmi
, DIB_RGB_COLORS
);
3155 DeleteObject( tmp
);
3156 if (ilc
== ILC_COLOR4
)
3159 tmp
= bmi
->bmiColors
[7];
3160 bmi
->bmiColors
[7] = bmi
->bmiColors
[8];
3161 bmi
->bmiColors
[8] = tmp
;
3166 GetDIBColorTable(himl
->hdcImage
, 0, 1 << himl
->uBitsPixel
, bmi
->bmiColors
);
3169 hbmNewBitmap
= CreateDIBSection(hdc
, bmi
, DIB_RGB_COLORS
, NULL
, 0, 0);
3171 else /*if (ilc == ILC_COLORDDB)*/
3173 TRACE("Creating Bitmap: %d Bits per Pixel\n", himl
->uBitsPixel
);
3175 hbmNewBitmap
= CreateBitmap (sz
.cx
, sz
.cy
, 1, himl
->uBitsPixel
, NULL
);
3177 TRACE("returning %p\n", hbmNewBitmap
);
3178 return hbmNewBitmap
;
3181 /*************************************************************************
3182 * ImageList_SetColorTable [COMCTL32.@]
3184 * Sets the color table of an image list.
3187 * himl [I] Handle to the image list.
3188 * uStartIndex [I] The first index to set.
3189 * cEntries [I] Number of entries to set.
3190 * prgb [I] New color information for color table for the image list.
3193 * Success: Number of entries in the table that were set.
3197 * ImageList_Create(), SetDIBColorTable()
3201 ImageList_SetColorTable(HIMAGELIST himl
, UINT uStartIndex
, UINT cEntries
, const RGBQUAD
*prgb
)
3203 TRACE("(%p, %d, %d, %p)\n", himl
, uStartIndex
, cEntries
, prgb
);
3204 himl
->color_table_set
= TRUE
;
3205 return SetDIBColorTable(himl
->hdcImage
, uStartIndex
, cEntries
, prgb
);
3208 /*************************************************************************
3209 * ImageList_CoCreateInstance [COMCTL32.@]
3211 * Creates a new imagelist instance and returns an interface pointer to it.
3214 * rclsid [I] A reference to the CLSID (CLSID_ImageList).
3215 * punkOuter [I] Pointer to IUnknown interface for aggregation, if desired
3216 * riid [I] Identifier of the requested interface.
3217 * ppv [O] Returns the address of the pointer requested, or NULL.
3221 * Failure: Error value.
3224 ImageList_CoCreateInstance (REFCLSID rclsid
, const IUnknown
*punkOuter
, REFIID riid
, void **ppv
)
3226 TRACE("(%s,%p,%s,%p)\n", debugstr_guid(rclsid
), punkOuter
, debugstr_guid(riid
), ppv
);
3228 if (!IsEqualCLSID(&CLSID_ImageList
, rclsid
))
3229 return E_NOINTERFACE
;
3231 return ImageListImpl_CreateInstance(punkOuter
, riid
, ppv
);
3235 /*************************************************************************
3236 * IImageList implementation
3239 static HRESULT WINAPI
ImageListImpl_QueryInterface(IImageList2
*iface
,
3240 REFIID iid
, void **ppv
)
3242 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3244 TRACE("(%p,%s,%p)\n", iface
, debugstr_guid(iid
), ppv
);
3246 if (!ppv
) return E_INVALIDARG
;
3248 if (IsEqualIID(&IID_IUnknown
, iid
) ||
3249 IsEqualIID(&IID_IImageList
, iid
) ||
3250 IsEqualIID(&IID_IImageList2
, iid
))
3252 *ppv
= &imgl
->IImageList2_iface
;
3257 return E_NOINTERFACE
;
3260 IImageList2_AddRef(iface
);
3264 static ULONG WINAPI
ImageListImpl_AddRef(IImageList2
*iface
)
3266 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3267 ULONG ref
= InterlockedIncrement(&imgl
->ref
);
3269 TRACE("(%p) refcount=%u\n", iface
, ref
);
3273 static ULONG WINAPI
ImageListImpl_Release(IImageList2
*iface
)
3275 HIMAGELIST This
= impl_from_IImageList2(iface
);
3276 ULONG ref
= InterlockedDecrement(&This
->ref
);
3278 TRACE("(%p) refcount=%u\n", iface
, ref
);
3282 /* delete image bitmaps */
3283 if (This
->hbmImage
) DeleteObject (This
->hbmImage
);
3284 if (This
->hbmMask
) DeleteObject (This
->hbmMask
);
3286 /* delete image & mask DCs */
3287 if (This
->hdcImage
) DeleteDC (This
->hdcImage
);
3288 if (This
->hdcMask
) DeleteDC (This
->hdcMask
);
3290 /* delete blending brushes */
3291 if (This
->hbrBlend25
) DeleteObject (This
->hbrBlend25
);
3292 if (This
->hbrBlend50
) DeleteObject (This
->hbrBlend50
);
3294 This
->IImageList2_iface
.lpVtbl
= NULL
;
3295 HeapFree(GetProcessHeap(), 0, This
->has_alpha
);
3296 HeapFree(GetProcessHeap(), 0, This
);
3302 static HRESULT WINAPI
ImageListImpl_Add(IImageList2
*iface
, HBITMAP hbmImage
,
3303 HBITMAP hbmMask
, int *pi
)
3305 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3311 ret
= ImageList_Add(imgl
, hbmImage
, hbmMask
);
3320 static HRESULT WINAPI
ImageListImpl_ReplaceIcon(IImageList2
*iface
, int i
,
3321 HICON hicon
, int *pi
)
3323 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3329 ret
= ImageList_ReplaceIcon(imgl
, i
, hicon
);
3338 static HRESULT WINAPI
ImageListImpl_SetOverlayImage(IImageList2
*iface
,
3339 int iImage
, int iOverlay
)
3341 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3342 return ImageList_SetOverlayImage(imgl
, iImage
, iOverlay
) ? S_OK
: E_FAIL
;
3345 static HRESULT WINAPI
ImageListImpl_Replace(IImageList2
*iface
, int i
,
3346 HBITMAP hbmImage
, HBITMAP hbmMask
)
3348 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3349 return ImageList_Replace(imgl
, i
, hbmImage
, hbmMask
) ? S_OK
: E_FAIL
;
3352 static HRESULT WINAPI
ImageListImpl_AddMasked(IImageList2
*iface
, HBITMAP hbmImage
,
3353 COLORREF crMask
, int *pi
)
3355 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3361 ret
= ImageList_AddMasked(imgl
, hbmImage
, crMask
);
3370 static HRESULT WINAPI
ImageListImpl_Draw(IImageList2
*iface
,
3371 IMAGELISTDRAWPARAMS
*pimldp
)
3373 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3374 HIMAGELIST old_himl
;
3377 /* As far as I can tell, Windows simply ignores the contents of pimldp->himl
3378 so we shall simulate the same */
3379 old_himl
= pimldp
->himl
;
3380 pimldp
->himl
= imgl
;
3382 ret
= ImageList_DrawIndirect(pimldp
);
3384 pimldp
->himl
= old_himl
;
3385 return ret
? S_OK
: E_INVALIDARG
;
3388 static HRESULT WINAPI
ImageListImpl_Remove(IImageList2
*iface
, int i
)
3390 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3391 return (ImageList_Remove(imgl
, i
) == 0) ? E_INVALIDARG
: S_OK
;
3394 static HRESULT WINAPI
ImageListImpl_GetIcon(IImageList2
*iface
, int i
, UINT flags
,
3397 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3403 hIcon
= ImageList_GetIcon(imgl
, i
, flags
);
3412 static HRESULT WINAPI
ImageListImpl_GetImageInfo(IImageList2
*iface
, int i
,
3413 IMAGEINFO
*pImageInfo
)
3415 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3416 return ImageList_GetImageInfo(imgl
, i
, pImageInfo
) ? S_OK
: E_FAIL
;
3419 static HRESULT WINAPI
ImageListImpl_Copy(IImageList2
*iface
, int dst_index
,
3420 IUnknown
*unk_src
, int src_index
, UINT flags
)
3422 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3423 IImageList
*src
= NULL
;
3429 /* TODO: Add test for IID_ImageList2 too */
3430 if (FAILED(IUnknown_QueryInterface(unk_src
, &IID_IImageList
,
3434 if (ImageList_Copy(imgl
, dst_index
, (HIMAGELIST
) src
, src_index
, flags
))
3439 IImageList_Release(src
);
3443 static HRESULT WINAPI
ImageListImpl_Merge(IImageList2
*iface
, int i1
,
3444 IUnknown
*punk2
, int i2
, int dx
, int dy
, REFIID riid
, void **ppv
)
3446 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3447 IImageList
*iml2
= NULL
;
3449 HRESULT ret
= E_FAIL
;
3451 TRACE("(%p)->(%d %p %d %d %d %s %p)\n", iface
, i1
, punk2
, i2
, dx
, dy
, debugstr_guid(riid
), ppv
);
3453 /* TODO: Add test for IID_ImageList2 too */
3454 if (FAILED(IUnknown_QueryInterface(punk2
, &IID_IImageList
,
3458 merged
= ImageList_Merge(imgl
, i1
, (HIMAGELIST
) iml2
, i2
, dx
, dy
);
3460 /* Get the interface for the new image list */
3463 ret
= HIMAGELIST_QueryInterface(merged
, riid
, ppv
);
3464 ImageList_Destroy(merged
);
3467 IImageList_Release(iml2
);
3471 static HRESULT WINAPI
ImageListImpl_Clone(IImageList2
*iface
, REFIID riid
, void **ppv
)
3473 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3475 HRESULT ret
= E_FAIL
;
3477 TRACE("(%p)->(%s %p)\n", iface
, debugstr_guid(riid
), ppv
);
3479 clone
= ImageList_Duplicate(imgl
);
3481 /* Get the interface for the new image list */
3484 ret
= HIMAGELIST_QueryInterface(clone
, riid
, ppv
);
3485 ImageList_Destroy(clone
);
3491 static HRESULT WINAPI
ImageListImpl_GetImageRect(IImageList2
*iface
, int i
,
3494 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3500 if (!ImageList_GetImageInfo(imgl
, i
, &info
))
3503 *prc
= info
.rcImage
;
3508 static HRESULT WINAPI
ImageListImpl_GetIconSize(IImageList2
*iface
, int *cx
,
3511 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3512 return ImageList_GetIconSize(imgl
, cx
, cy
) ? S_OK
: E_INVALIDARG
;
3515 static HRESULT WINAPI
ImageListImpl_SetIconSize(IImageList2
*iface
, int cx
,
3518 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3519 return ImageList_SetIconSize(imgl
, cx
, cy
) ? S_OK
: E_FAIL
;
3522 static HRESULT WINAPI
ImageListImpl_GetImageCount(IImageList2
*iface
, int *pi
)
3524 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3525 *pi
= ImageList_GetImageCount(imgl
);
3529 static HRESULT WINAPI
ImageListImpl_SetImageCount(IImageList2
*iface
, UINT count
)
3531 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3532 return ImageList_SetImageCount(imgl
, count
) ? S_OK
: E_FAIL
;
3535 static HRESULT WINAPI
ImageListImpl_SetBkColor(IImageList2
*iface
, COLORREF clrBk
,
3538 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3539 *pclr
= ImageList_SetBkColor(imgl
, clrBk
);
3543 static HRESULT WINAPI
ImageListImpl_GetBkColor(IImageList2
*iface
, COLORREF
*pclr
)
3545 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3546 *pclr
= ImageList_GetBkColor(imgl
);
3550 static HRESULT WINAPI
ImageListImpl_BeginDrag(IImageList2
*iface
, int iTrack
,
3551 int dxHotspot
, int dyHotspot
)
3553 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3554 return ImageList_BeginDrag(imgl
, iTrack
, dxHotspot
, dyHotspot
) ? S_OK
: E_FAIL
;
3557 static HRESULT WINAPI
ImageListImpl_EndDrag(IImageList2
*iface
)
3559 ImageList_EndDrag();
3563 static HRESULT WINAPI
ImageListImpl_DragEnter(IImageList2
*iface
, HWND hwndLock
,
3566 return ImageList_DragEnter(hwndLock
, x
, y
) ? S_OK
: E_FAIL
;
3569 static HRESULT WINAPI
ImageListImpl_DragLeave(IImageList2
*iface
, HWND hwndLock
)
3571 return ImageList_DragLeave(hwndLock
) ? S_OK
: E_FAIL
;
3574 static HRESULT WINAPI
ImageListImpl_DragMove(IImageList2
*iface
, int x
, int y
)
3576 return ImageList_DragMove(x
, y
) ? S_OK
: E_FAIL
;
3579 static HRESULT WINAPI
ImageListImpl_SetDragCursorImage(IImageList2
*iface
,
3580 IUnknown
*punk
, int iDrag
, int dxHotspot
, int dyHotspot
)
3582 IImageList
*iml2
= NULL
;
3588 /* TODO: Add test for IID_ImageList2 too */
3589 if (FAILED(IUnknown_QueryInterface(punk
, &IID_IImageList
,
3593 ret
= ImageList_SetDragCursorImage((HIMAGELIST
) iml2
, iDrag
, dxHotspot
,
3596 IImageList_Release(iml2
);
3598 return ret
? S_OK
: E_FAIL
;
3601 static HRESULT WINAPI
ImageListImpl_DragShowNolock(IImageList2
*iface
, BOOL fShow
)
3603 return ImageList_DragShowNolock(fShow
) ? S_OK
: E_FAIL
;
3606 static HRESULT WINAPI
ImageListImpl_GetDragImage(IImageList2
*iface
, POINT
*ppt
,
3607 POINT
*pptHotspot
, REFIID riid
, PVOID
*ppv
)
3609 HRESULT ret
= E_FAIL
;
3615 hNew
= ImageList_GetDragImage(ppt
, pptHotspot
);
3617 /* Get the interface for the new image list */
3620 IImageList
*idrag
= (IImageList
*)hNew
;
3622 ret
= HIMAGELIST_QueryInterface(hNew
, riid
, ppv
);
3623 IImageList_Release(idrag
);
3629 static HRESULT WINAPI
ImageListImpl_GetItemFlags(IImageList2
*iface
, int i
,
3632 FIXME("STUB: %p %d %p\n", iface
, i
, dwFlags
);
3636 static HRESULT WINAPI
ImageListImpl_GetOverlayImage(IImageList2
*iface
, int iOverlay
,
3639 HIMAGELIST This
= impl_from_IImageList2(iface
);
3642 if ((iOverlay
< 0) || (iOverlay
> This
->cCurImage
))
3645 for (i
= 0; i
< MAX_OVERLAYIMAGE
; i
++)
3647 if (This
->nOvlIdx
[i
] == iOverlay
)
3657 static HRESULT WINAPI
ImageListImpl_Resize(IImageList2
*iface
, INT cx
, INT cy
)
3659 FIXME("(%p)->(%d %d): stub\n", iface
, cx
, cy
);
3663 static HRESULT WINAPI
ImageListImpl_GetOriginalSize(IImageList2
*iface
, INT image
, DWORD flags
, INT
*cx
, INT
*cy
)
3665 FIXME("(%p)->(%d %x %p %p): stub\n", iface
, image
, flags
, cx
, cy
);
3669 static HRESULT WINAPI
ImageListImpl_SetOriginalSize(IImageList2
*iface
, INT image
, INT cx
, INT cy
)
3671 FIXME("(%p)->(%d %d %d): stub\n", iface
, image
, cx
, cy
);
3675 static HRESULT WINAPI
ImageListImpl_SetCallback(IImageList2
*iface
, IUnknown
*callback
)
3677 FIXME("(%p)->(%p): stub\n", iface
, callback
);
3681 static HRESULT WINAPI
ImageListImpl_GetCallback(IImageList2
*iface
, REFIID riid
, void **ppv
)
3683 FIXME("(%p)->(%s %p): stub\n", iface
, debugstr_guid(riid
), ppv
);
3687 static HRESULT WINAPI
ImageListImpl_ForceImagePresent(IImageList2
*iface
, INT image
, DWORD flags
)
3689 FIXME("(%p)->(%d %x): stub\n", iface
, image
, flags
);
3693 static HRESULT WINAPI
ImageListImpl_DiscardImages(IImageList2
*iface
, INT first_image
, INT last_image
, DWORD flags
)
3695 FIXME("(%p)->(%d %d %x): stub\n", iface
, first_image
, last_image
, flags
);
3699 static HRESULT WINAPI
ImageListImpl_PreloadImages(IImageList2
*iface
, IMAGELISTDRAWPARAMS
*params
)
3701 FIXME("(%p)->(%p): stub\n", iface
, params
);
3705 static HRESULT WINAPI
ImageListImpl_GetStatistics(IImageList2
*iface
, IMAGELISTSTATS
*stats
)
3707 FIXME("(%p)->(%p): stub\n", iface
, stats
);
3711 static HRESULT WINAPI
ImageListImpl_Initialize(IImageList2
*iface
, INT cx
, INT cy
, UINT flags
, INT initial
, INT grow
)
3713 FIXME("(%p)->(%d %d %d %d %d): stub\n", iface
, cx
, cy
, flags
, initial
, grow
);
3717 static HRESULT WINAPI
ImageListImpl_Replace2(IImageList2
*iface
, INT i
, HBITMAP image
, HBITMAP mask
, IUnknown
*unk
, DWORD flags
)
3719 FIXME("(%p)->(%d %p %p %p %x): stub\n", iface
, i
, image
, mask
, unk
, flags
);
3723 static HRESULT WINAPI
ImageListImpl_ReplaceFromImageList(IImageList2
*iface
, INT i
, IImageList
*imagelist
, INT src
,
3724 IUnknown
*unk
, DWORD flags
)
3726 FIXME("(%p)->(%d %p %d %p %x): stub\n", iface
, i
, imagelist
, src
, unk
, flags
);
3730 static const IImageList2Vtbl ImageListImpl_Vtbl
= {
3731 ImageListImpl_QueryInterface
,
3732 ImageListImpl_AddRef
,
3733 ImageListImpl_Release
,
3735 ImageListImpl_ReplaceIcon
,
3736 ImageListImpl_SetOverlayImage
,
3737 ImageListImpl_Replace
,
3738 ImageListImpl_AddMasked
,
3740 ImageListImpl_Remove
,
3741 ImageListImpl_GetIcon
,
3742 ImageListImpl_GetImageInfo
,
3744 ImageListImpl_Merge
,
3745 ImageListImpl_Clone
,
3746 ImageListImpl_GetImageRect
,
3747 ImageListImpl_GetIconSize
,
3748 ImageListImpl_SetIconSize
,
3749 ImageListImpl_GetImageCount
,
3750 ImageListImpl_SetImageCount
,
3751 ImageListImpl_SetBkColor
,
3752 ImageListImpl_GetBkColor
,
3753 ImageListImpl_BeginDrag
,
3754 ImageListImpl_EndDrag
,
3755 ImageListImpl_DragEnter
,
3756 ImageListImpl_DragLeave
,
3757 ImageListImpl_DragMove
,
3758 ImageListImpl_SetDragCursorImage
,
3759 ImageListImpl_DragShowNolock
,
3760 ImageListImpl_GetDragImage
,
3761 ImageListImpl_GetItemFlags
,
3762 ImageListImpl_GetOverlayImage
,
3763 ImageListImpl_Resize
,
3764 ImageListImpl_GetOriginalSize
,
3765 ImageListImpl_SetOriginalSize
,
3766 ImageListImpl_SetCallback
,
3767 ImageListImpl_GetCallback
,
3768 ImageListImpl_ForceImagePresent
,
3769 ImageListImpl_DiscardImages
,
3770 ImageListImpl_PreloadImages
,
3771 ImageListImpl_GetStatistics
,
3772 ImageListImpl_Initialize
,
3773 ImageListImpl_Replace2
,
3774 ImageListImpl_ReplaceFromImageList
3777 static BOOL
is_valid(HIMAGELIST himl
)
3782 valid
= himl
&& himl
->IImageList2_iface
.lpVtbl
== &ImageListImpl_Vtbl
;
3792 /*************************************************************************
3793 * HIMAGELIST_QueryInterface [COMCTL32.@]
3795 * Returns a pointer to an IImageList or IImageList2 object for the given
3799 * himl [I] Image list handle.
3800 * riid [I] Identifier of the requested interface.
3801 * ppv [O] Returns the address of the pointer requested, or NULL.
3805 * Failure: Error value.
3808 HIMAGELIST_QueryInterface (HIMAGELIST himl
, REFIID riid
, void **ppv
)
3810 TRACE("(%p,%s,%p)\n", himl
, debugstr_guid(riid
), ppv
);
3811 return IImageList2_QueryInterface((IImageList2
*) himl
, riid
, ppv
);
3814 static HRESULT
ImageListImpl_CreateInstance(const IUnknown
*pUnkOuter
, REFIID iid
, void** ppv
)
3819 TRACE("(%p,%s,%p)\n", pUnkOuter
, debugstr_guid(iid
), ppv
);
3823 if (pUnkOuter
) return CLASS_E_NOAGGREGATION
;
3825 This
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(struct _IMAGELIST
));
3826 if (!This
) return E_OUTOFMEMORY
;
3828 This
->IImageList2_iface
.lpVtbl
= &ImageListImpl_Vtbl
;
3831 ret
= IImageList2_QueryInterface(&This
->IImageList2_iface
, iid
, ppv
);
3832 IImageList2_Release(&This
->IImageList2_iface
);