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 himl
= ImageList_Create (cx
, dib
.dsBm
.bmHeight
, ILC_MASK
| color
, nImageCount
, cGrow
);
2042 DeleteObject (handle
);
2045 ImageList_AddMasked (himl
, handle
, clrMask
);
2047 else if ((uType
== IMAGE_ICON
) || (uType
== IMAGE_CURSOR
)) {
2051 GetIconInfo (handle
, &ii
);
2052 GetObjectW (ii
.hbmColor
, sizeof(BITMAP
), &bmp
);
2053 himl
= ImageList_Create (bmp
.bmWidth
, bmp
.bmHeight
,
2054 ILC_MASK
| ILC_COLOR
, 1, cGrow
);
2056 DeleteObject (ii
.hbmColor
);
2057 DeleteObject (ii
.hbmMask
);
2058 DeleteObject (handle
);
2061 ImageList_Add (himl
, ii
.hbmColor
, ii
.hbmMask
);
2062 DeleteObject (ii
.hbmColor
);
2063 DeleteObject (ii
.hbmMask
);
2066 DeleteObject (handle
);
2072 /*************************************************************************
2073 * ImageList_Merge [COMCTL32.@]
2075 * Create an image list containing a merged image from two image lists.
2078 * himl1 [I] handle to first image list
2079 * i1 [I] first image index
2080 * himl2 [I] handle to second image list
2081 * i2 [I] second image index
2082 * dx [I] X offset of the second image relative to the first.
2083 * dy [I] Y offset of the second image relative to the first.
2086 * Success: The newly created image list. It contains a single image
2087 * consisting of the second image merged with the first.
2088 * Failure: NULL, if either himl1 or himl2 is invalid.
2091 * - The returned image list should be deleted by the caller using
2092 * ImageList_Destroy() when it is no longer required.
2093 * - If either i1 or i2 is not a valid image index, they will be treated
2097 ImageList_Merge (HIMAGELIST himl1
, INT i1
, HIMAGELIST himl2
, INT i2
,
2100 HIMAGELIST himlDst
= NULL
;
2102 INT xOff1
, yOff1
, xOff2
, yOff2
;
2106 TRACE("(himl1=%p i1=%d himl2=%p i2=%d dx=%d dy=%d)\n", himl1
, i1
, himl2
,
2109 if (!is_valid(himl1
) || !is_valid(himl2
))
2113 cxDst
= max (himl1
->cx
, dx
+ himl2
->cx
);
2118 cxDst
= max (himl2
->cx
, himl1
->cx
- dx
);
2123 cxDst
= max (himl1
->cx
, himl2
->cx
);
2129 cyDst
= max (himl1
->cy
, dy
+ himl2
->cy
);
2134 cyDst
= max (himl2
->cy
, himl1
->cy
- dy
);
2139 cyDst
= max (himl1
->cy
, himl2
->cy
);
2144 newFlags
= (himl1
->flags
> himl2
->flags
? himl1
->flags
: himl2
->flags
) & ILC_COLORDDB
;
2145 if (newFlags
== ILC_COLORDDB
&& (himl1
->flags
& ILC_COLORDDB
) == ILC_COLOR16
)
2146 newFlags
= ILC_COLOR16
; /* this is what native (at least v5) does, don't know why */
2147 himlDst
= ImageList_Create (cxDst
, cyDst
, ILC_MASK
| newFlags
, 1, 1);
2151 imagelist_point_from_index( himl1
, i1
, &pt1
);
2152 imagelist_point_from_index( himl2
, i2
, &pt2
);
2155 BitBlt (himlDst
->hdcImage
, 0, 0, cxDst
, cyDst
, himl1
->hdcImage
, 0, 0, BLACKNESS
);
2156 if (i1
>= 0 && i1
< himl1
->cCurImage
)
2157 BitBlt (himlDst
->hdcImage
, xOff1
, yOff1
, himl1
->cx
, himl1
->cy
, himl1
->hdcImage
, pt1
.x
, pt1
.y
, SRCCOPY
);
2158 if (i2
>= 0 && i2
< himl2
->cCurImage
)
2160 if (himl2
->flags
& ILC_MASK
)
2162 BitBlt (himlDst
->hdcImage
, xOff2
, yOff2
, himl2
->cx
, himl2
->cy
, himl2
->hdcMask
, pt2
.x
, pt2
.y
, SRCAND
);
2163 BitBlt (himlDst
->hdcImage
, xOff2
, yOff2
, himl2
->cx
, himl2
->cy
, himl2
->hdcImage
, pt2
.x
, pt2
.y
, SRCPAINT
);
2166 BitBlt (himlDst
->hdcImage
, xOff2
, yOff2
, himl2
->cx
, himl2
->cy
, himl2
->hdcImage
, pt2
.x
, pt2
.y
, SRCCOPY
);
2170 BitBlt (himlDst
->hdcMask
, 0, 0, cxDst
, cyDst
, himl1
->hdcMask
, 0, 0, WHITENESS
);
2171 if (i1
>= 0 && i1
< himl1
->cCurImage
)
2172 BitBlt (himlDst
->hdcMask
, xOff1
, yOff1
, himl1
->cx
, himl1
->cy
, himl1
->hdcMask
, pt1
.x
, pt1
.y
, SRCCOPY
);
2173 if (i2
>= 0 && i2
< himl2
->cCurImage
)
2174 BitBlt (himlDst
->hdcMask
, xOff2
, yOff2
, himl2
->cx
, himl2
->cy
, himl2
->hdcMask
, pt2
.x
, pt2
.y
, SRCAND
);
2176 himlDst
->cCurImage
= 1;
2183 /* helper for ImageList_Read, see comments below */
2184 static void *read_bitmap(IStream
*pstm
, BITMAPINFO
*bmi
)
2186 BITMAPFILEHEADER bmfh
;
2187 int bitsperpixel
, palspace
;
2190 if (FAILED(IStream_Read ( pstm
, &bmfh
, sizeof(bmfh
), NULL
)))
2193 if (bmfh
.bfType
!= (('M'<<8)|'B'))
2196 if (FAILED(IStream_Read ( pstm
, &bmi
->bmiHeader
, sizeof(bmi
->bmiHeader
), NULL
)))
2199 if ((bmi
->bmiHeader
.biSize
!= sizeof(bmi
->bmiHeader
)))
2202 TRACE("width %u, height %u, planes %u, bpp %u\n",
2203 bmi
->bmiHeader
.biWidth
, bmi
->bmiHeader
.biHeight
,
2204 bmi
->bmiHeader
.biPlanes
, bmi
->bmiHeader
.biBitCount
);
2206 bitsperpixel
= bmi
->bmiHeader
.biPlanes
* bmi
->bmiHeader
.biBitCount
;
2207 if (bitsperpixel
<=8)
2208 palspace
= (1<<bitsperpixel
)*sizeof(RGBQUAD
);
2212 bmi
->bmiHeader
.biSizeImage
= get_dib_image_size( bmi
);
2214 /* read the palette right after the end of the bitmapinfoheader */
2215 if (palspace
&& FAILED(IStream_Read(pstm
, bmi
->bmiColors
, palspace
, NULL
)))
2218 bits
= Alloc(bmi
->bmiHeader
.biSizeImage
);
2219 if (!bits
) return NULL
;
2221 if (FAILED(IStream_Read(pstm
, bits
, bmi
->bmiHeader
.biSizeImage
, NULL
)))
2229 /*************************************************************************
2230 * ImageList_Read [COMCTL32.@]
2232 * Reads an image list from a stream.
2235 * pstm [I] pointer to a stream
2238 * Success: handle to image list
2241 * The format is like this:
2242 * ILHEAD ilheadstruct;
2244 * for the color image part:
2245 * BITMAPFILEHEADER bmfh;
2246 * BITMAPINFOHEADER bmih;
2247 * only if it has a palette:
2248 * RGBQUAD rgbs[nr_of_paletted_colors];
2250 * BYTE colorbits[imagesize];
2252 * the following only if the ILC_MASK bit is set in ILHEAD.ilFlags:
2253 * BITMAPFILEHEADER bmfh_mask;
2254 * BITMAPINFOHEADER bmih_mask;
2255 * only if it has a palette (it usually does not):
2256 * RGBQUAD rgbs[nr_of_paletted_colors];
2258 * BYTE maskbits[imagesize];
2260 HIMAGELIST WINAPI
ImageList_Read(IStream
*pstm
)
2262 char image_buf
[sizeof(BITMAPINFOHEADER
) + sizeof(RGBQUAD
) * 256];
2263 char mask_buf
[sizeof(BITMAPINFOHEADER
) + sizeof(RGBQUAD
) * 256];
2264 BITMAPINFO
*image_info
= (BITMAPINFO
*)image_buf
;
2265 BITMAPINFO
*mask_info
= (BITMAPINFO
*)mask_buf
;
2266 void *image_bits
, *mask_bits
= NULL
;
2271 TRACE("%p\n", pstm
);
2273 if (FAILED(IStream_Read (pstm
, &ilHead
, sizeof(ILHEAD
), NULL
)))
2275 if (ilHead
.usMagic
!= (('L' << 8) | 'I'))
2277 if (ilHead
.usVersion
!= 0x101) /* probably version? */
2280 TRACE("cx %u, cy %u, flags 0x%04x, cCurImage %u, cMaxImage %u\n",
2281 ilHead
.cx
, ilHead
.cy
, ilHead
.flags
, ilHead
.cCurImage
, ilHead
.cMaxImage
);
2283 himl
= ImageList_Create(ilHead
.cx
, ilHead
.cy
, ilHead
.flags
, ilHead
.cCurImage
, ilHead
.cMaxImage
);
2287 if (!(image_bits
= read_bitmap(pstm
, image_info
)))
2289 WARN("failed to read bitmap from stream\n");
2292 if (ilHead
.flags
& ILC_MASK
)
2294 if (!(mask_bits
= read_bitmap(pstm
, mask_info
)))
2296 WARN("failed to read mask bitmap from stream\n");
2300 else mask_info
= NULL
;
2302 if (himl
->has_alpha
&& image_info
->bmiHeader
.biBitCount
== 32)
2304 DWORD
*ptr
= image_bits
;
2305 BYTE
*mask_ptr
= mask_bits
;
2306 int stride
= himl
->cy
* image_info
->bmiHeader
.biWidth
;
2308 if (image_info
->bmiHeader
.biHeight
> 0) /* bottom-up */
2310 ptr
+= image_info
->bmiHeader
.biHeight
* image_info
->bmiHeader
.biWidth
- stride
;
2311 mask_ptr
+= (image_info
->bmiHeader
.biHeight
* image_info
->bmiHeader
.biWidth
- stride
) / 8;
2313 image_info
->bmiHeader
.biHeight
= himl
->cy
;
2315 else image_info
->bmiHeader
.biHeight
= -himl
->cy
;
2317 for (i
= 0; i
< ilHead
.cCurImage
; i
+= TILE_COUNT
)
2319 add_dib_bits( himl
, i
, min( ilHead
.cCurImage
- i
, TILE_COUNT
),
2320 himl
->cx
, himl
->cy
, image_info
, mask_info
, ptr
, mask_ptr
);
2322 mask_ptr
+= stride
/ 8;
2327 StretchDIBits( himl
->hdcImage
, 0, 0, image_info
->bmiHeader
.biWidth
, image_info
->bmiHeader
.biHeight
,
2328 0, 0, image_info
->bmiHeader
.biWidth
, image_info
->bmiHeader
.biHeight
,
2329 image_bits
, image_info
, DIB_RGB_COLORS
, SRCCOPY
);
2331 StretchDIBits( himl
->hdcMask
, 0, 0, mask_info
->bmiHeader
.biWidth
, mask_info
->bmiHeader
.biHeight
,
2332 0, 0, mask_info
->bmiHeader
.biWidth
, mask_info
->bmiHeader
.biHeight
,
2333 mask_bits
, mask_info
, DIB_RGB_COLORS
, SRCCOPY
);
2338 himl
->cCurImage
= ilHead
.cCurImage
;
2339 himl
->cMaxImage
= ilHead
.cMaxImage
;
2341 ImageList_SetBkColor(himl
,ilHead
.bkcolor
);
2343 ImageList_SetOverlayImage(himl
,ilHead
.ovls
[i
],i
+1);
2348 /*************************************************************************
2349 * ImageList_Remove [COMCTL32.@]
2351 * Removes an image from an image list
2354 * himl [I] image list handle
2361 * FIXME: as the image list storage test shows, native comctl32 simply shifts
2362 * images without creating a new bitmap.
2365 ImageList_Remove (HIMAGELIST himl
, INT i
)
2367 HBITMAP hbmNewImage
, hbmNewMask
;
2371 TRACE("(himl=%p i=%d)\n", himl
, i
);
2373 if (!is_valid(himl
)) {
2374 ERR("Invalid image list handle!\n");
2378 if ((i
< -1) || (i
>= himl
->cCurImage
)) {
2379 TRACE("index out of range! %d\n", i
);
2387 if (himl
->cCurImage
== 0) {
2388 /* remove all on empty ImageList is allowed */
2389 TRACE("remove all on empty ImageList!\n");
2393 himl
->cMaxImage
= himl
->cGrow
;
2394 himl
->cCurImage
= 0;
2395 for (nCount
= 0; nCount
< MAX_OVERLAYIMAGE
; nCount
++)
2396 himl
->nOvlIdx
[nCount
] = -1;
2398 if (himl
->has_alpha
)
2400 HeapFree( GetProcessHeap(), 0, himl
->has_alpha
);
2401 himl
->has_alpha
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, himl
->cMaxImage
);
2404 hbmNewImage
= ImageList_CreateImage(himl
->hdcImage
, himl
, himl
->cMaxImage
);
2405 SelectObject (himl
->hdcImage
, hbmNewImage
);
2406 DeleteObject (himl
->hbmImage
);
2407 himl
->hbmImage
= hbmNewImage
;
2409 if (himl
->hbmMask
) {
2411 imagelist_get_bitmap_size(himl
, himl
->cMaxImage
, &sz
);
2412 hbmNewMask
= CreateBitmap (sz
.cx
, sz
.cy
, 1, 1, NULL
);
2413 SelectObject (himl
->hdcMask
, hbmNewMask
);
2414 DeleteObject (himl
->hbmMask
);
2415 himl
->hbmMask
= hbmNewMask
;
2419 /* delete one image */
2420 TRACE("Remove single image! %d\n", i
);
2422 /* create new bitmap(s) */
2423 TRACE(" - Number of images: %d / %d (Old/New)\n",
2424 himl
->cCurImage
, himl
->cCurImage
- 1);
2426 hbmNewImage
= ImageList_CreateImage(himl
->hdcImage
, himl
, himl
->cMaxImage
);
2428 imagelist_get_bitmap_size(himl
, himl
->cMaxImage
, &sz
);
2430 hbmNewMask
= CreateBitmap (sz
.cx
, sz
.cy
, 1, 1, NULL
);
2432 hbmNewMask
= 0; /* Just to keep compiler happy! */
2434 hdcBmp
= CreateCompatibleDC (0);
2436 /* copy all images and masks prior to the "removed" image */
2438 TRACE("Pre image copy: Copy %d images\n", i
);
2440 SelectObject (hdcBmp
, hbmNewImage
);
2441 imagelist_copy_images( himl
, himl
->hdcImage
, hdcBmp
, 0, i
, 0 );
2443 if (himl
->hbmMask
) {
2444 SelectObject (hdcBmp
, hbmNewMask
);
2445 imagelist_copy_images( himl
, himl
->hdcMask
, hdcBmp
, 0, i
, 0 );
2449 /* copy all images and masks behind the removed image */
2450 if (i
< himl
->cCurImage
- 1) {
2451 TRACE("Post image copy!\n");
2453 SelectObject (hdcBmp
, hbmNewImage
);
2454 imagelist_copy_images( himl
, himl
->hdcImage
, hdcBmp
, i
+ 1,
2455 (himl
->cCurImage
- i
), i
);
2457 if (himl
->hbmMask
) {
2458 SelectObject (hdcBmp
, hbmNewMask
);
2459 imagelist_copy_images( himl
, himl
->hdcMask
, hdcBmp
, i
+ 1,
2460 (himl
->cCurImage
- i
), i
);
2466 /* delete old images and insert new ones */
2467 SelectObject (himl
->hdcImage
, hbmNewImage
);
2468 DeleteObject (himl
->hbmImage
);
2469 himl
->hbmImage
= hbmNewImage
;
2470 if (himl
->hbmMask
) {
2471 SelectObject (himl
->hdcMask
, hbmNewMask
);
2472 DeleteObject (himl
->hbmMask
);
2473 himl
->hbmMask
= hbmNewMask
;
2483 /*************************************************************************
2484 * ImageList_Replace [COMCTL32.@]
2486 * Replaces an image in an image list with a new image.
2489 * himl [I] handle to image list
2491 * hbmImage [I] handle to image bitmap
2492 * hbmMask [I] handle to mask bitmap. Can be NULL.
2500 ImageList_Replace (HIMAGELIST himl
, INT i
, HBITMAP hbmImage
,
2507 TRACE("%p %d %p %p\n", himl
, i
, hbmImage
, hbmMask
);
2509 if (!is_valid(himl
)) {
2510 ERR("Invalid image list handle!\n");
2514 if ((i
>= himl
->cMaxImage
) || (i
< 0)) {
2515 ERR("Invalid image index!\n");
2519 if (!GetObjectW(hbmImage
, sizeof(BITMAP
), &bmp
))
2522 hdcImage
= CreateCompatibleDC (0);
2525 SelectObject (hdcImage
, hbmImage
);
2527 if (add_with_alpha( himl
, hdcImage
, i
, 1, bmp
.bmWidth
, bmp
.bmHeight
, hbmImage
, hbmMask
))
2530 imagelist_point_from_index(himl
, i
, &pt
);
2531 StretchBlt (himl
->hdcImage
, pt
.x
, pt
.y
, himl
->cx
, himl
->cy
,
2532 hdcImage
, 0, 0, bmp
.bmWidth
, bmp
.bmHeight
, SRCCOPY
);
2537 HBITMAP hOldBitmapTemp
;
2539 hdcTemp
= CreateCompatibleDC(0);
2540 hOldBitmapTemp
= SelectObject(hdcTemp
, hbmMask
);
2542 StretchBlt (himl
->hdcMask
, pt
.x
, pt
.y
, himl
->cx
, himl
->cy
,
2543 hdcTemp
, 0, 0, bmp
.bmWidth
, bmp
.bmHeight
, SRCCOPY
);
2544 SelectObject(hdcTemp
, hOldBitmapTemp
);
2547 /* Remove the background from the image
2549 BitBlt (himl
->hdcImage
, pt
.x
, pt
.y
, bmp
.bmWidth
, bmp
.bmHeight
,
2550 himl
->hdcMask
, pt
.x
, pt
.y
, 0x220326); /* NOTSRCAND */
2554 DeleteDC (hdcImage
);
2560 /*************************************************************************
2561 * ImageList_ReplaceIcon [COMCTL32.@]
2563 * Replaces an image in an image list using an icon.
2566 * himl [I] handle to image list
2568 * hIcon [I] handle to icon
2571 * Success: index of the replaced image
2576 ImageList_ReplaceIcon (HIMAGELIST himl
, INT nIndex
, HICON hIcon
)
2584 TRACE("(%p %d %p)\n", himl
, nIndex
, hIcon
);
2586 if (!is_valid(himl
)) {
2587 ERR("invalid image list\n");
2590 if ((nIndex
>= himl
->cMaxImage
) || (nIndex
< -1)) {
2591 ERR("invalid image index %d / %d\n", nIndex
, himl
->cMaxImage
);
2595 hBestFitIcon
= CopyImage(
2598 LR_COPYFROMRESOURCE
);
2599 /* the above will fail if the icon wasn't loaded from a resource, so try
2600 * again without LR_COPYFROMRESOURCE flag */
2602 hBestFitIcon
= CopyImage(
2610 if (himl
->cCurImage
+ 1 >= himl
->cMaxImage
)
2611 IMAGELIST_InternalExpandBitmaps(himl
, 1);
2613 nIndex
= himl
->cCurImage
;
2617 if (himl
->has_alpha
&& GetIconInfo (hBestFitIcon
, &ii
))
2619 HDC hdcImage
= CreateCompatibleDC( 0 );
2620 GetObjectW (ii
.hbmMask
, sizeof(BITMAP
), &bmp
);
2624 UINT height
= bmp
.bmHeight
/ 2;
2625 HDC hdcMask
= CreateCompatibleDC( 0 );
2626 HBITMAP color
= CreateBitmap( bmp
.bmWidth
, height
, 1, 1, NULL
);
2627 SelectObject( hdcImage
, color
);
2628 SelectObject( hdcMask
, ii
.hbmMask
);
2629 BitBlt( hdcImage
, 0, 0, bmp
.bmWidth
, height
, hdcMask
, 0, height
, SRCCOPY
);
2630 ret
= add_with_alpha( himl
, hdcImage
, nIndex
, 1, bmp
.bmWidth
, height
, color
, ii
.hbmMask
);
2631 DeleteDC( hdcMask
);
2632 DeleteObject( color
);
2634 else ret
= add_with_alpha( himl
, hdcImage
, nIndex
, 1, bmp
.bmWidth
, bmp
.bmHeight
,
2635 ii
.hbmColor
, ii
.hbmMask
);
2637 DeleteDC( hdcImage
);
2638 DeleteObject (ii
.hbmMask
);
2639 if (ii
.hbmColor
) DeleteObject (ii
.hbmColor
);
2643 imagelist_point_from_index(himl
, nIndex
, &pt
);
2647 DrawIconEx( himl
->hdcImage
, pt
.x
, pt
.y
, hBestFitIcon
, himl
->cx
, himl
->cy
, 0, 0, DI_IMAGE
);
2648 PatBlt( himl
->hdcMask
, pt
.x
, pt
.y
, himl
->cx
, himl
->cy
, WHITENESS
);
2649 DrawIconEx( himl
->hdcMask
, pt
.x
, pt
.y
, hBestFitIcon
, himl
->cx
, himl
->cy
, 0, 0, DI_MASK
);
2653 COLORREF color
= himl
->clrBk
!= CLR_NONE
? himl
->clrBk
: comctl32_color
.clrWindow
;
2654 HBRUSH brush
= CreateSolidBrush( GetNearestColor( himl
->hdcImage
, color
));
2656 SelectObject( himl
->hdcImage
, brush
);
2657 PatBlt( himl
->hdcImage
, pt
.x
, pt
.y
, himl
->cx
, himl
->cy
, PATCOPY
);
2658 SelectObject( himl
->hdcImage
, GetStockObject(BLACK_BRUSH
) );
2659 DeleteObject( brush
);
2660 DrawIconEx( himl
->hdcImage
, pt
.x
, pt
.y
, hBestFitIcon
, himl
->cx
, himl
->cy
, 0, 0, DI_NORMAL
);
2664 DestroyIcon(hBestFitIcon
);
2666 TRACE("Insert index = %d, himl->cCurImage = %d\n", nIndex
, himl
->cCurImage
);
2671 /*************************************************************************
2672 * ImageList_SetBkColor [COMCTL32.@]
2674 * Sets the background color of an image list.
2677 * himl [I] handle to image list
2678 * clrBk [I] background color
2681 * Success: previous background color
2686 ImageList_SetBkColor (HIMAGELIST himl
, COLORREF clrBk
)
2690 if (!is_valid(himl
))
2693 clrOldBk
= himl
->clrBk
;
2694 himl
->clrBk
= clrBk
;
2699 /*************************************************************************
2700 * ImageList_SetDragCursorImage [COMCTL32.@]
2702 * Combines the specified image with the current drag image
2705 * himlDrag [I] handle to drag image list
2706 * iDrag [I] drag image index
2707 * dxHotspot [I] X position of the hot spot
2708 * dyHotspot [I] Y position of the hot spot
2715 * - The names dxHotspot, dyHotspot are misleading because they have nothing
2716 * to do with a hotspot but are only the offset of the origin of the new
2717 * image relative to the origin of the old image.
2719 * - When this function is called and the drag image is visible, a
2720 * short flickering occurs but this matches the Win9x behavior. It is
2721 * possible to fix the flickering using code like in ImageList_DragMove.
2725 ImageList_SetDragCursorImage (HIMAGELIST himlDrag
, INT iDrag
,
2726 INT dxHotspot
, INT dyHotspot
)
2728 HIMAGELIST himlTemp
;
2731 if (!is_valid(InternalDrag
.himl
) || !is_valid(himlDrag
))
2734 TRACE(" dxH=%d dyH=%d nX=%d nY=%d\n",
2735 dxHotspot
, dyHotspot
, InternalDrag
.dxHotspot
, InternalDrag
.dyHotspot
);
2737 visible
= InternalDrag
.bShow
;
2739 himlTemp
= ImageList_Merge (InternalDrag
.himlNoCursor
, 0, himlDrag
, iDrag
,
2740 dxHotspot
, dyHotspot
);
2743 /* hide the drag image */
2744 ImageList_DragShowNolock(FALSE
);
2746 if ((InternalDrag
.himl
->cx
!= himlTemp
->cx
) ||
2747 (InternalDrag
.himl
->cy
!= himlTemp
->cy
)) {
2748 /* the size of the drag image changed, invalidate the buffer */
2749 DeleteObject(InternalDrag
.hbmBg
);
2750 InternalDrag
.hbmBg
= 0;
2753 if (InternalDrag
.himl
!= InternalDrag
.himlNoCursor
)
2754 ImageList_Destroy (InternalDrag
.himl
);
2755 InternalDrag
.himl
= himlTemp
;
2758 /* show the drag image */
2759 ImageList_DragShowNolock(TRUE
);
2766 /*************************************************************************
2767 * ImageList_SetFilter [COMCTL32.@]
2769 * Sets a filter (or does something completely different)!!???
2770 * It removes 12 Bytes from the stack (3 Parameters).
2773 * himl [I] SHOULD be a handle to image list
2774 * i [I] COULD be an index?
2779 * Failure: FALSE ???
2782 * This is an UNDOCUMENTED function!!!!
2787 ImageList_SetFilter (HIMAGELIST himl
, INT i
, DWORD dwFilter
)
2789 FIXME("(%p 0x%x 0x%x):empty stub!\n", himl
, i
, dwFilter
);
2795 /*************************************************************************
2796 * ImageList_SetFlags [COMCTL32.@]
2798 * Sets the image list flags.
2801 * himl [I] Handle to image list
2802 * flags [I] Flags to set
2812 ImageList_SetFlags(HIMAGELIST himl
, DWORD flags
)
2814 FIXME("(%p %08x):empty stub\n", himl
, flags
);
2819 /*************************************************************************
2820 * ImageList_SetIconSize [COMCTL32.@]
2822 * Sets the image size of the bitmap and deletes all images.
2825 * himl [I] handle to image list
2826 * cx [I] image width
2827 * cy [I] image height
2835 ImageList_SetIconSize (HIMAGELIST himl
, INT cx
, INT cy
)
2840 if (!is_valid(himl
))
2843 /* remove all images */
2844 himl
->cMaxImage
= himl
->cInitial
+ 1;
2845 himl
->cCurImage
= 0;
2849 /* initialize overlay mask indices */
2850 for (nCount
= 0; nCount
< MAX_OVERLAYIMAGE
; nCount
++)
2851 himl
->nOvlIdx
[nCount
] = -1;
2853 hbmNew
= ImageList_CreateImage(himl
->hdcImage
, himl
, himl
->cMaxImage
);
2854 SelectObject (himl
->hdcImage
, hbmNew
);
2855 DeleteObject (himl
->hbmImage
);
2856 himl
->hbmImage
= hbmNew
;
2858 if (himl
->hbmMask
) {
2860 imagelist_get_bitmap_size(himl
, himl
->cMaxImage
, &sz
);
2861 hbmNew
= CreateBitmap (sz
.cx
, sz
.cy
, 1, 1, NULL
);
2862 SelectObject (himl
->hdcMask
, hbmNew
);
2863 DeleteObject (himl
->hbmMask
);
2864 himl
->hbmMask
= hbmNew
;
2871 /*************************************************************************
2872 * ImageList_SetImageCount [COMCTL32.@]
2874 * Resizes an image list to the specified number of images.
2877 * himl [I] handle to image list
2878 * iImageCount [I] number of images in the image list
2886 ImageList_SetImageCount (HIMAGELIST himl
, UINT iImageCount
)
2889 HBITMAP hbmNewBitmap
, hbmOld
;
2890 INT nNewCount
, nCopyCount
;
2892 TRACE("%p %d\n",himl
,iImageCount
);
2894 if (!is_valid(himl
))
2897 nNewCount
= iImageCount
+ 1;
2898 nCopyCount
= min(himl
->cCurImage
, iImageCount
);
2900 hdcBitmap
= CreateCompatibleDC (0);
2902 hbmNewBitmap
= ImageList_CreateImage(hdcBitmap
, himl
, nNewCount
);
2904 if (hbmNewBitmap
!= 0)
2906 hbmOld
= SelectObject (hdcBitmap
, hbmNewBitmap
);
2907 imagelist_copy_images( himl
, himl
->hdcImage
, hdcBitmap
, 0, nCopyCount
, 0 );
2908 SelectObject (hdcBitmap
, hbmOld
);
2910 /* FIXME: delete 'empty' image space? */
2912 SelectObject (himl
->hdcImage
, hbmNewBitmap
);
2913 DeleteObject (himl
->hbmImage
);
2914 himl
->hbmImage
= hbmNewBitmap
;
2917 ERR("Could not create new image bitmap!\n");
2922 imagelist_get_bitmap_size( himl
, nNewCount
, &sz
);
2923 hbmNewBitmap
= CreateBitmap (sz
.cx
, sz
.cy
, 1, 1, NULL
);
2924 if (hbmNewBitmap
!= 0)
2926 hbmOld
= SelectObject (hdcBitmap
, hbmNewBitmap
);
2927 imagelist_copy_images( himl
, himl
->hdcMask
, hdcBitmap
, 0, nCopyCount
, 0 );
2928 SelectObject (hdcBitmap
, hbmOld
);
2930 /* FIXME: delete 'empty' image space? */
2932 SelectObject (himl
->hdcMask
, hbmNewBitmap
);
2933 DeleteObject (himl
->hbmMask
);
2934 himl
->hbmMask
= hbmNewBitmap
;
2937 ERR("Could not create new mask bitmap!\n");
2940 DeleteDC (hdcBitmap
);
2942 if (himl
->has_alpha
)
2944 char *new_alpha
= HeapReAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, himl
->has_alpha
, nNewCount
);
2945 if (new_alpha
) himl
->has_alpha
= new_alpha
;
2948 HeapFree( GetProcessHeap(), 0, himl
->has_alpha
);
2949 himl
->has_alpha
= NULL
;
2953 /* Update max image count and current image count */
2954 himl
->cMaxImage
= nNewCount
;
2955 himl
->cCurImage
= iImageCount
;
2961 /*************************************************************************
2962 * ImageList_SetOverlayImage [COMCTL32.@]
2964 * Assigns an overlay mask index to an existing image in an image list.
2967 * himl [I] handle to image list
2968 * iImage [I] image index
2969 * iOverlay [I] overlay mask index
2977 ImageList_SetOverlayImage (HIMAGELIST himl
, INT iImage
, INT iOverlay
)
2979 if (!is_valid(himl
))
2981 if ((iOverlay
< 1) || (iOverlay
> MAX_OVERLAYIMAGE
))
2983 if ((iImage
!=-1) && ((iImage
< 0) || (iImage
> himl
->cCurImage
)))
2985 himl
->nOvlIdx
[iOverlay
- 1] = iImage
;
2991 /* helper for ImageList_Write - write bitmap to pstm
2992 * currently everything is written as 24 bit RGB, except masks
2994 static BOOL
_write_bitmap(HBITMAP hBitmap
, IStream
*pstm
)
2996 LPBITMAPFILEHEADER bmfh
;
2997 LPBITMAPINFOHEADER bmih
;
2998 LPBYTE data
= NULL
, lpBits
;
3000 INT bitCount
, sizeImage
, offBits
, totalSize
;
3002 BOOL result
= FALSE
;
3004 if (!GetObjectW(hBitmap
, sizeof(BITMAP
), &bm
))
3007 bitCount
= bm
.bmBitsPixel
;
3008 sizeImage
= get_dib_stride(bm
.bmWidth
, bitCount
) * bm
.bmHeight
;
3010 totalSize
= sizeof(BITMAPFILEHEADER
) + sizeof(BITMAPINFOHEADER
);
3012 totalSize
+= (1 << bitCount
) * sizeof(RGBQUAD
);
3013 offBits
= totalSize
;
3014 totalSize
+= sizeImage
;
3016 data
= Alloc(totalSize
);
3017 bmfh
= (LPBITMAPFILEHEADER
)data
;
3018 bmih
= (LPBITMAPINFOHEADER
)(data
+ sizeof(BITMAPFILEHEADER
));
3019 lpBits
= data
+ offBits
;
3021 /* setup BITMAPFILEHEADER */
3022 bmfh
->bfType
= (('M' << 8) | 'B');
3023 bmfh
->bfSize
= offBits
;
3024 bmfh
->bfReserved1
= 0;
3025 bmfh
->bfReserved2
= 0;
3026 bmfh
->bfOffBits
= offBits
;
3028 /* setup BITMAPINFOHEADER */
3029 bmih
->biSize
= sizeof(BITMAPINFOHEADER
);
3030 bmih
->biWidth
= bm
.bmWidth
;
3031 bmih
->biHeight
= bm
.bmHeight
;
3033 bmih
->biBitCount
= bitCount
;
3034 bmih
->biCompression
= BI_RGB
;
3035 bmih
->biSizeImage
= sizeImage
;
3036 bmih
->biXPelsPerMeter
= 0;
3037 bmih
->biYPelsPerMeter
= 0;
3038 bmih
->biClrUsed
= 0;
3039 bmih
->biClrImportant
= 0;
3042 result
= GetDIBits(xdc
, hBitmap
, 0, bm
.bmHeight
, lpBits
, (BITMAPINFO
*)bmih
, DIB_RGB_COLORS
) == bm
.bmHeight
;
3047 TRACE("width %u, height %u, planes %u, bpp %u\n",
3048 bmih
->biWidth
, bmih
->biHeight
,
3049 bmih
->biPlanes
, bmih
->biBitCount
);
3051 if(FAILED(IStream_Write(pstm
, data
, totalSize
, NULL
)))
3063 /*************************************************************************
3064 * ImageList_Write [COMCTL32.@]
3066 * Writes an image list to a stream.
3069 * himl [I] handle to image list
3070 * pstm [O] Pointer to a stream.
3080 BOOL WINAPI
ImageList_Write(HIMAGELIST himl
, IStream
*pstm
)
3085 TRACE("%p %p\n", himl
, pstm
);
3087 if (!is_valid(himl
))
3090 ilHead
.usMagic
= (('L' << 8) | 'I');
3091 ilHead
.usVersion
= 0x101;
3092 ilHead
.cCurImage
= himl
->cCurImage
;
3093 ilHead
.cMaxImage
= himl
->cMaxImage
;
3094 ilHead
.cGrow
= himl
->cGrow
;
3095 ilHead
.cx
= himl
->cx
;
3096 ilHead
.cy
= himl
->cy
;
3097 ilHead
.bkcolor
= himl
->clrBk
;
3098 ilHead
.flags
= himl
->flags
;
3099 for(i
= 0; i
< 4; i
++) {
3100 ilHead
.ovls
[i
] = himl
->nOvlIdx
[i
];
3103 TRACE("cx %u, cy %u, flags 0x04%x, cCurImage %u, cMaxImage %u\n",
3104 ilHead
.cx
, ilHead
.cy
, ilHead
.flags
, ilHead
.cCurImage
, ilHead
.cMaxImage
);
3106 if(FAILED(IStream_Write(pstm
, &ilHead
, sizeof(ILHEAD
), NULL
)))
3109 /* write the bitmap */
3110 if(!_write_bitmap(himl
->hbmImage
, pstm
))
3113 /* write the mask if we have one */
3114 if(himl
->flags
& ILC_MASK
) {
3115 if(!_write_bitmap(himl
->hbmMask
, pstm
))
3123 static HBITMAP
ImageList_CreateImage(HDC hdc
, HIMAGELIST himl
, UINT count
)
3125 HBITMAP hbmNewBitmap
;
3126 UINT ilc
= (himl
->flags
& 0xFE);
3129 imagelist_get_bitmap_size( himl
, count
, &sz
);
3131 if ((ilc
>= ILC_COLOR4
&& ilc
<= ILC_COLOR32
) || ilc
== ILC_COLOR
)
3133 char buffer
[sizeof(BITMAPINFOHEADER
) + 256 * sizeof(RGBQUAD
)];
3134 BITMAPINFO
*bmi
= (BITMAPINFO
*)buffer
;
3136 TRACE("Creating DIBSection %d x %d, %d Bits per Pixel\n",
3137 sz
.cx
, sz
.cy
, himl
->uBitsPixel
);
3139 memset( buffer
, 0, sizeof(buffer
) );
3140 bmi
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
3141 bmi
->bmiHeader
.biWidth
= sz
.cx
;
3142 bmi
->bmiHeader
.biHeight
= sz
.cy
;
3143 bmi
->bmiHeader
.biPlanes
= 1;
3144 bmi
->bmiHeader
.biBitCount
= himl
->uBitsPixel
;
3145 bmi
->bmiHeader
.biCompression
= BI_RGB
;
3147 if (himl
->uBitsPixel
<= ILC_COLOR8
)
3149 if (!himl
->color_table_set
)
3151 /* retrieve the default color map */
3152 HBITMAP tmp
= CreateBitmap( 1, 1, 1, 1, NULL
);
3153 GetDIBits( hdc
, tmp
, 0, 0, NULL
, bmi
, DIB_RGB_COLORS
);
3154 DeleteObject( tmp
);
3155 if (ilc
== ILC_COLOR4
)
3158 tmp
= bmi
->bmiColors
[7];
3159 bmi
->bmiColors
[7] = bmi
->bmiColors
[8];
3160 bmi
->bmiColors
[8] = tmp
;
3165 GetDIBColorTable(himl
->hdcImage
, 0, 1 << himl
->uBitsPixel
, bmi
->bmiColors
);
3168 hbmNewBitmap
= CreateDIBSection(hdc
, bmi
, DIB_RGB_COLORS
, NULL
, 0, 0);
3170 else /*if (ilc == ILC_COLORDDB)*/
3172 TRACE("Creating Bitmap: %d Bits per Pixel\n", himl
->uBitsPixel
);
3174 hbmNewBitmap
= CreateBitmap (sz
.cx
, sz
.cy
, 1, himl
->uBitsPixel
, NULL
);
3176 TRACE("returning %p\n", hbmNewBitmap
);
3177 return hbmNewBitmap
;
3180 /*************************************************************************
3181 * ImageList_SetColorTable [COMCTL32.@]
3183 * Sets the color table of an image list.
3186 * himl [I] Handle to the image list.
3187 * uStartIndex [I] The first index to set.
3188 * cEntries [I] Number of entries to set.
3189 * prgb [I] New color information for color table for the image list.
3192 * Success: Number of entries in the table that were set.
3196 * ImageList_Create(), SetDIBColorTable()
3200 ImageList_SetColorTable(HIMAGELIST himl
, UINT uStartIndex
, UINT cEntries
, const RGBQUAD
*prgb
)
3202 TRACE("(%p, %d, %d, %p)\n", himl
, uStartIndex
, cEntries
, prgb
);
3203 himl
->color_table_set
= TRUE
;
3204 return SetDIBColorTable(himl
->hdcImage
, uStartIndex
, cEntries
, prgb
);
3207 /*************************************************************************
3208 * ImageList_CoCreateInstance [COMCTL32.@]
3210 * Creates a new imagelist instance and returns an interface pointer to it.
3213 * rclsid [I] A reference to the CLSID (CLSID_ImageList).
3214 * punkOuter [I] Pointer to IUnknown interface for aggregation, if desired
3215 * riid [I] Identifier of the requested interface.
3216 * ppv [O] Returns the address of the pointer requested, or NULL.
3220 * Failure: Error value.
3223 ImageList_CoCreateInstance (REFCLSID rclsid
, const IUnknown
*punkOuter
, REFIID riid
, void **ppv
)
3225 TRACE("(%s,%p,%s,%p)\n", debugstr_guid(rclsid
), punkOuter
, debugstr_guid(riid
), ppv
);
3227 if (!IsEqualCLSID(&CLSID_ImageList
, rclsid
))
3228 return E_NOINTERFACE
;
3230 return ImageListImpl_CreateInstance(punkOuter
, riid
, ppv
);
3234 /*************************************************************************
3235 * IImageList implementation
3238 static HRESULT WINAPI
ImageListImpl_QueryInterface(IImageList2
*iface
,
3239 REFIID iid
, void **ppv
)
3241 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3243 TRACE("(%p,%s,%p)\n", iface
, debugstr_guid(iid
), ppv
);
3245 if (!ppv
) return E_INVALIDARG
;
3247 if (IsEqualIID(&IID_IUnknown
, iid
) ||
3248 IsEqualIID(&IID_IImageList
, iid
) ||
3249 IsEqualIID(&IID_IImageList2
, iid
))
3251 *ppv
= &imgl
->IImageList2_iface
;
3256 return E_NOINTERFACE
;
3259 IImageList2_AddRef(iface
);
3263 static ULONG WINAPI
ImageListImpl_AddRef(IImageList2
*iface
)
3265 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3266 ULONG ref
= InterlockedIncrement(&imgl
->ref
);
3268 TRACE("(%p) refcount=%u\n", iface
, ref
);
3272 static ULONG WINAPI
ImageListImpl_Release(IImageList2
*iface
)
3274 HIMAGELIST This
= impl_from_IImageList2(iface
);
3275 ULONG ref
= InterlockedDecrement(&This
->ref
);
3277 TRACE("(%p) refcount=%u\n", iface
, ref
);
3281 /* delete image bitmaps */
3282 if (This
->hbmImage
) DeleteObject (This
->hbmImage
);
3283 if (This
->hbmMask
) DeleteObject (This
->hbmMask
);
3285 /* delete image & mask DCs */
3286 if (This
->hdcImage
) DeleteDC (This
->hdcImage
);
3287 if (This
->hdcMask
) DeleteDC (This
->hdcMask
);
3289 /* delete blending brushes */
3290 if (This
->hbrBlend25
) DeleteObject (This
->hbrBlend25
);
3291 if (This
->hbrBlend50
) DeleteObject (This
->hbrBlend50
);
3293 This
->IImageList2_iface
.lpVtbl
= NULL
;
3294 HeapFree(GetProcessHeap(), 0, This
->has_alpha
);
3295 HeapFree(GetProcessHeap(), 0, This
);
3301 static HRESULT WINAPI
ImageListImpl_Add(IImageList2
*iface
, HBITMAP hbmImage
,
3302 HBITMAP hbmMask
, int *pi
)
3304 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3310 ret
= ImageList_Add(imgl
, hbmImage
, hbmMask
);
3319 static HRESULT WINAPI
ImageListImpl_ReplaceIcon(IImageList2
*iface
, int i
,
3320 HICON hicon
, int *pi
)
3322 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3328 ret
= ImageList_ReplaceIcon(imgl
, i
, hicon
);
3337 static HRESULT WINAPI
ImageListImpl_SetOverlayImage(IImageList2
*iface
,
3338 int iImage
, int iOverlay
)
3340 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3341 return ImageList_SetOverlayImage(imgl
, iImage
, iOverlay
) ? S_OK
: E_FAIL
;
3344 static HRESULT WINAPI
ImageListImpl_Replace(IImageList2
*iface
, int i
,
3345 HBITMAP hbmImage
, HBITMAP hbmMask
)
3347 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3348 return ImageList_Replace(imgl
, i
, hbmImage
, hbmMask
) ? S_OK
: E_FAIL
;
3351 static HRESULT WINAPI
ImageListImpl_AddMasked(IImageList2
*iface
, HBITMAP hbmImage
,
3352 COLORREF crMask
, int *pi
)
3354 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3360 ret
= ImageList_AddMasked(imgl
, hbmImage
, crMask
);
3369 static HRESULT WINAPI
ImageListImpl_Draw(IImageList2
*iface
,
3370 IMAGELISTDRAWPARAMS
*pimldp
)
3372 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3373 HIMAGELIST old_himl
;
3376 /* As far as I can tell, Windows simply ignores the contents of pimldp->himl
3377 so we shall simulate the same */
3378 old_himl
= pimldp
->himl
;
3379 pimldp
->himl
= imgl
;
3381 ret
= ImageList_DrawIndirect(pimldp
);
3383 pimldp
->himl
= old_himl
;
3384 return ret
? S_OK
: E_INVALIDARG
;
3387 static HRESULT WINAPI
ImageListImpl_Remove(IImageList2
*iface
, int i
)
3389 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3390 return (ImageList_Remove(imgl
, i
) == 0) ? E_INVALIDARG
: S_OK
;
3393 static HRESULT WINAPI
ImageListImpl_GetIcon(IImageList2
*iface
, int i
, UINT flags
,
3396 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3402 hIcon
= ImageList_GetIcon(imgl
, i
, flags
);
3411 static HRESULT WINAPI
ImageListImpl_GetImageInfo(IImageList2
*iface
, int i
,
3412 IMAGEINFO
*pImageInfo
)
3414 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3415 return ImageList_GetImageInfo(imgl
, i
, pImageInfo
) ? S_OK
: E_FAIL
;
3418 static HRESULT WINAPI
ImageListImpl_Copy(IImageList2
*iface
, int dst_index
,
3419 IUnknown
*unk_src
, int src_index
, UINT flags
)
3421 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3422 IImageList
*src
= NULL
;
3428 /* TODO: Add test for IID_ImageList2 too */
3429 if (FAILED(IUnknown_QueryInterface(unk_src
, &IID_IImageList
,
3433 if (ImageList_Copy(imgl
, dst_index
, (HIMAGELIST
) src
, src_index
, flags
))
3438 IImageList_Release(src
);
3442 static HRESULT WINAPI
ImageListImpl_Merge(IImageList2
*iface
, int i1
,
3443 IUnknown
*punk2
, int i2
, int dx
, int dy
, REFIID riid
, void **ppv
)
3445 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3446 IImageList
*iml2
= NULL
;
3448 HRESULT ret
= E_FAIL
;
3450 TRACE("(%p)->(%d %p %d %d %d %s %p)\n", iface
, i1
, punk2
, i2
, dx
, dy
, debugstr_guid(riid
), ppv
);
3452 /* TODO: Add test for IID_ImageList2 too */
3453 if (FAILED(IUnknown_QueryInterface(punk2
, &IID_IImageList
,
3457 merged
= ImageList_Merge(imgl
, i1
, (HIMAGELIST
) iml2
, i2
, dx
, dy
);
3459 /* Get the interface for the new image list */
3462 ret
= HIMAGELIST_QueryInterface(merged
, riid
, ppv
);
3463 ImageList_Destroy(merged
);
3466 IImageList_Release(iml2
);
3470 static HRESULT WINAPI
ImageListImpl_Clone(IImageList2
*iface
, REFIID riid
, void **ppv
)
3472 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3474 HRESULT ret
= E_FAIL
;
3476 TRACE("(%p)->(%s %p)\n", iface
, debugstr_guid(riid
), ppv
);
3478 clone
= ImageList_Duplicate(imgl
);
3480 /* Get the interface for the new image list */
3483 ret
= HIMAGELIST_QueryInterface(clone
, riid
, ppv
);
3484 ImageList_Destroy(clone
);
3490 static HRESULT WINAPI
ImageListImpl_GetImageRect(IImageList2
*iface
, int i
,
3493 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3499 if (!ImageList_GetImageInfo(imgl
, i
, &info
))
3502 *prc
= info
.rcImage
;
3507 static HRESULT WINAPI
ImageListImpl_GetIconSize(IImageList2
*iface
, int *cx
,
3510 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3511 return ImageList_GetIconSize(imgl
, cx
, cy
) ? S_OK
: E_INVALIDARG
;
3514 static HRESULT WINAPI
ImageListImpl_SetIconSize(IImageList2
*iface
, int cx
,
3517 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3518 return ImageList_SetIconSize(imgl
, cx
, cy
) ? S_OK
: E_FAIL
;
3521 static HRESULT WINAPI
ImageListImpl_GetImageCount(IImageList2
*iface
, int *pi
)
3523 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3524 *pi
= ImageList_GetImageCount(imgl
);
3528 static HRESULT WINAPI
ImageListImpl_SetImageCount(IImageList2
*iface
, UINT count
)
3530 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3531 return ImageList_SetImageCount(imgl
, count
) ? S_OK
: E_FAIL
;
3534 static HRESULT WINAPI
ImageListImpl_SetBkColor(IImageList2
*iface
, COLORREF clrBk
,
3537 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3538 *pclr
= ImageList_SetBkColor(imgl
, clrBk
);
3542 static HRESULT WINAPI
ImageListImpl_GetBkColor(IImageList2
*iface
, COLORREF
*pclr
)
3544 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3545 *pclr
= ImageList_GetBkColor(imgl
);
3549 static HRESULT WINAPI
ImageListImpl_BeginDrag(IImageList2
*iface
, int iTrack
,
3550 int dxHotspot
, int dyHotspot
)
3552 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3553 return ImageList_BeginDrag(imgl
, iTrack
, dxHotspot
, dyHotspot
) ? S_OK
: E_FAIL
;
3556 static HRESULT WINAPI
ImageListImpl_EndDrag(IImageList2
*iface
)
3558 ImageList_EndDrag();
3562 static HRESULT WINAPI
ImageListImpl_DragEnter(IImageList2
*iface
, HWND hwndLock
,
3565 return ImageList_DragEnter(hwndLock
, x
, y
) ? S_OK
: E_FAIL
;
3568 static HRESULT WINAPI
ImageListImpl_DragLeave(IImageList2
*iface
, HWND hwndLock
)
3570 return ImageList_DragLeave(hwndLock
) ? S_OK
: E_FAIL
;
3573 static HRESULT WINAPI
ImageListImpl_DragMove(IImageList2
*iface
, int x
, int y
)
3575 return ImageList_DragMove(x
, y
) ? S_OK
: E_FAIL
;
3578 static HRESULT WINAPI
ImageListImpl_SetDragCursorImage(IImageList2
*iface
,
3579 IUnknown
*punk
, int iDrag
, int dxHotspot
, int dyHotspot
)
3581 IImageList
*iml2
= NULL
;
3587 /* TODO: Add test for IID_ImageList2 too */
3588 if (FAILED(IUnknown_QueryInterface(punk
, &IID_IImageList
,
3592 ret
= ImageList_SetDragCursorImage((HIMAGELIST
) iml2
, iDrag
, dxHotspot
,
3595 IImageList_Release(iml2
);
3597 return ret
? S_OK
: E_FAIL
;
3600 static HRESULT WINAPI
ImageListImpl_DragShowNolock(IImageList2
*iface
, BOOL fShow
)
3602 return ImageList_DragShowNolock(fShow
) ? S_OK
: E_FAIL
;
3605 static HRESULT WINAPI
ImageListImpl_GetDragImage(IImageList2
*iface
, POINT
*ppt
,
3606 POINT
*pptHotspot
, REFIID riid
, PVOID
*ppv
)
3608 HRESULT ret
= E_FAIL
;
3614 hNew
= ImageList_GetDragImage(ppt
, pptHotspot
);
3616 /* Get the interface for the new image list */
3619 IImageList
*idrag
= (IImageList
*)hNew
;
3621 ret
= HIMAGELIST_QueryInterface(hNew
, riid
, ppv
);
3622 IImageList_Release(idrag
);
3628 static HRESULT WINAPI
ImageListImpl_GetItemFlags(IImageList2
*iface
, int i
,
3631 FIXME("STUB: %p %d %p\n", iface
, i
, dwFlags
);
3635 static HRESULT WINAPI
ImageListImpl_GetOverlayImage(IImageList2
*iface
, int iOverlay
,
3638 HIMAGELIST This
= impl_from_IImageList2(iface
);
3641 if ((iOverlay
< 0) || (iOverlay
> This
->cCurImage
))
3644 for (i
= 0; i
< MAX_OVERLAYIMAGE
; i
++)
3646 if (This
->nOvlIdx
[i
] == iOverlay
)
3656 static HRESULT WINAPI
ImageListImpl_Resize(IImageList2
*iface
, INT cx
, INT cy
)
3658 FIXME("(%p)->(%d %d): stub\n", iface
, cx
, cy
);
3662 static HRESULT WINAPI
ImageListImpl_GetOriginalSize(IImageList2
*iface
, INT image
, DWORD flags
, INT
*cx
, INT
*cy
)
3664 FIXME("(%p)->(%d %x %p %p): stub\n", iface
, image
, flags
, cx
, cy
);
3668 static HRESULT WINAPI
ImageListImpl_SetOriginalSize(IImageList2
*iface
, INT image
, INT cx
, INT cy
)
3670 FIXME("(%p)->(%d %d %d): stub\n", iface
, image
, cx
, cy
);
3674 static HRESULT WINAPI
ImageListImpl_SetCallback(IImageList2
*iface
, IUnknown
*callback
)
3676 FIXME("(%p)->(%p): stub\n", iface
, callback
);
3680 static HRESULT WINAPI
ImageListImpl_GetCallback(IImageList2
*iface
, REFIID riid
, void **ppv
)
3682 FIXME("(%p)->(%s %p): stub\n", iface
, debugstr_guid(riid
), ppv
);
3686 static HRESULT WINAPI
ImageListImpl_ForceImagePresent(IImageList2
*iface
, INT image
, DWORD flags
)
3688 FIXME("(%p)->(%d %x): stub\n", iface
, image
, flags
);
3692 static HRESULT WINAPI
ImageListImpl_DiscardImages(IImageList2
*iface
, INT first_image
, INT last_image
, DWORD flags
)
3694 FIXME("(%p)->(%d %d %x): stub\n", iface
, first_image
, last_image
, flags
);
3698 static HRESULT WINAPI
ImageListImpl_PreloadImages(IImageList2
*iface
, IMAGELISTDRAWPARAMS
*params
)
3700 FIXME("(%p)->(%p): stub\n", iface
, params
);
3704 static HRESULT WINAPI
ImageListImpl_GetStatistics(IImageList2
*iface
, IMAGELISTSTATS
*stats
)
3706 FIXME("(%p)->(%p): stub\n", iface
, stats
);
3710 static HRESULT WINAPI
ImageListImpl_Initialize(IImageList2
*iface
, INT cx
, INT cy
, UINT flags
, INT initial
, INT grow
)
3712 FIXME("(%p)->(%d %d %d %d %d): stub\n", iface
, cx
, cy
, flags
, initial
, grow
);
3716 static HRESULT WINAPI
ImageListImpl_Replace2(IImageList2
*iface
, INT i
, HBITMAP image
, HBITMAP mask
, IUnknown
*unk
, DWORD flags
)
3718 FIXME("(%p)->(%d %p %p %p %x): stub\n", iface
, i
, image
, mask
, unk
, flags
);
3722 static HRESULT WINAPI
ImageListImpl_ReplaceFromImageList(IImageList2
*iface
, INT i
, IImageList
*imagelist
, INT src
,
3723 IUnknown
*unk
, DWORD flags
)
3725 FIXME("(%p)->(%d %p %d %p %x): stub\n", iface
, i
, imagelist
, src
, unk
, flags
);
3729 static const IImageList2Vtbl ImageListImpl_Vtbl
= {
3730 ImageListImpl_QueryInterface
,
3731 ImageListImpl_AddRef
,
3732 ImageListImpl_Release
,
3734 ImageListImpl_ReplaceIcon
,
3735 ImageListImpl_SetOverlayImage
,
3736 ImageListImpl_Replace
,
3737 ImageListImpl_AddMasked
,
3739 ImageListImpl_Remove
,
3740 ImageListImpl_GetIcon
,
3741 ImageListImpl_GetImageInfo
,
3743 ImageListImpl_Merge
,
3744 ImageListImpl_Clone
,
3745 ImageListImpl_GetImageRect
,
3746 ImageListImpl_GetIconSize
,
3747 ImageListImpl_SetIconSize
,
3748 ImageListImpl_GetImageCount
,
3749 ImageListImpl_SetImageCount
,
3750 ImageListImpl_SetBkColor
,
3751 ImageListImpl_GetBkColor
,
3752 ImageListImpl_BeginDrag
,
3753 ImageListImpl_EndDrag
,
3754 ImageListImpl_DragEnter
,
3755 ImageListImpl_DragLeave
,
3756 ImageListImpl_DragMove
,
3757 ImageListImpl_SetDragCursorImage
,
3758 ImageListImpl_DragShowNolock
,
3759 ImageListImpl_GetDragImage
,
3760 ImageListImpl_GetItemFlags
,
3761 ImageListImpl_GetOverlayImage
,
3762 ImageListImpl_Resize
,
3763 ImageListImpl_GetOriginalSize
,
3764 ImageListImpl_SetOriginalSize
,
3765 ImageListImpl_SetCallback
,
3766 ImageListImpl_GetCallback
,
3767 ImageListImpl_ForceImagePresent
,
3768 ImageListImpl_DiscardImages
,
3769 ImageListImpl_PreloadImages
,
3770 ImageListImpl_GetStatistics
,
3771 ImageListImpl_Initialize
,
3772 ImageListImpl_Replace2
,
3773 ImageListImpl_ReplaceFromImageList
3776 static BOOL
is_valid(HIMAGELIST himl
)
3781 valid
= himl
&& himl
->IImageList2_iface
.lpVtbl
== &ImageListImpl_Vtbl
;
3791 /*************************************************************************
3792 * HIMAGELIST_QueryInterface [COMCTL32.@]
3794 * Returns a pointer to an IImageList or IImageList2 object for the given
3798 * himl [I] Image list handle.
3799 * riid [I] Identifier of the requested interface.
3800 * ppv [O] Returns the address of the pointer requested, or NULL.
3804 * Failure: Error value.
3807 HIMAGELIST_QueryInterface (HIMAGELIST himl
, REFIID riid
, void **ppv
)
3809 TRACE("(%p,%s,%p)\n", himl
, debugstr_guid(riid
), ppv
);
3810 return IImageList2_QueryInterface((IImageList2
*) himl
, riid
, ppv
);
3813 static HRESULT
ImageListImpl_CreateInstance(const IUnknown
*pUnkOuter
, REFIID iid
, void** ppv
)
3818 TRACE("(%p,%s,%p)\n", pUnkOuter
, debugstr_guid(iid
), ppv
);
3822 if (pUnkOuter
) return CLASS_E_NOAGGREGATION
;
3824 This
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(struct _IMAGELIST
));
3825 if (!This
) return E_OUTOFMEMORY
;
3827 This
->IImageList2_iface
.lpVtbl
= &ImageListImpl_Vtbl
;
3830 ret
= IImageList2_QueryInterface(&This
->IImageList2_iface
, iid
, ppv
);
3831 IImageList2_Release(&This
->IImageList2_iface
);