2 * ImageList implementation
4 * Copyright 1998 Eric Kohl
5 * Copyright 2000 Jason Mawdsley
6 * Copyright 2001, 2004 Michael Stefaniuc
7 * Copyright 2001 Charles Loep for CodeWeavers
8 * Copyright 2002 Dimitrie O. Paun
9 * Copyright 2009 Owen Rudge for CodeWeavers
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public
13 * License as published by the Free Software Foundation; either
14 * version 2.1 of the License, or (at your option) any later version.
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with this library; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 * - Add support for ILD_PRESERVEALPHA, ILD_SCALE, ILD_DPISCALE
27 * - Add support for ILS_GLOW, ILS_SHADOW
28 * - Thread-safe locking
45 #include "commoncontrols.h"
46 #include "wine/debug.h"
47 #include "wine/exception.h"
48 #include "wine/heap.h"
50 WINE_DEFAULT_DEBUG_CHANNEL(imagelist
);
52 #define MAX_OVERLAYIMAGE 15
56 IImageList2 IImageList2_iface
; /* 00: IImageList vtable */
57 INT cCurImage
; /* 04: ImageCount */
58 INT cMaxImage
; /* 08: maximages */
59 INT cGrow
; /* 0C: cGrow */
63 UINT flags
; /* 1C: flags */
64 COLORREF clrFg
; /* 20: foreground color */
65 COLORREF clrBk
; /* 24: background color */
68 HBITMAP hbmImage
; /* 28: images Bitmap */
69 HBITMAP hbmMask
; /* 2C: masks Bitmap */
70 HDC hdcImage
; /* 30: images MemDC */
71 HDC hdcMask
; /* 34: masks MemDC */
72 INT nOvlIdx
[MAX_OVERLAYIMAGE
]; /* 38: overlay images index */
74 /* not yet found out */
82 LONG ref
; /* reference count */
85 #define IMAGELIST_MAGIC 0x53414D58
87 /* Header used by ImageList_Read() and ImageList_Write() */
89 typedef struct _ILHEAD
104 /* internal image list data used for Drag & Drop operations */
109 HIMAGELIST himlNoCursor
;
110 /* position of the drag image relative to the window */
113 /* offset of the hotspot relative to the origin of the image */
116 /* is the drag image visible */
118 /* saved background */
122 static INTERNALDRAG InternalDrag
= { 0, 0, 0, 0, 0, 0, 0, FALSE
, 0 };
124 static inline HIMAGELIST
impl_from_IImageList2(IImageList2
*iface
)
126 return CONTAINING_RECORD(iface
, struct _IMAGELIST
, IImageList2_iface
);
129 static HBITMAP
ImageList_CreateImage(HDC hdc
, HIMAGELIST himl
, UINT count
);
130 static HRESULT
ImageListImpl_CreateInstance(const IUnknown
*pUnkOuter
, REFIID iid
, void** ppv
);
131 static BOOL
is_valid(HIMAGELIST himl
);
134 * An imagelist with N images is tiled like this:
146 static inline UINT
imagelist_height( UINT count
)
148 return ((count
+ TILE_COUNT
- 1)/TILE_COUNT
);
151 static inline void imagelist_point_from_index( HIMAGELIST himl
, UINT index
, LPPOINT pt
)
153 pt
->x
= (index
%TILE_COUNT
) * himl
->cx
;
154 pt
->y
= (index
/TILE_COUNT
) * himl
->cy
;
157 static inline void imagelist_get_bitmap_size( HIMAGELIST himl
, UINT count
, SIZE
*sz
)
159 sz
->cx
= himl
->cx
* TILE_COUNT
;
160 sz
->cy
= imagelist_height( count
) * himl
->cy
;
163 static inline int get_dib_stride( int width
, int bpp
)
165 return ((width
* bpp
+ 31) >> 3) & ~3;
168 static inline int get_dib_image_size( const BITMAPINFO
*info
)
170 return get_dib_stride( info
->bmiHeader
.biWidth
, info
->bmiHeader
.biBitCount
)
171 * abs( info
->bmiHeader
.biHeight
);
175 * imagelist_copy_images()
177 * Copies a block of count images from offset src in the list to offset dest.
178 * Images are copied a row at at time. Assumes hdcSrc and hdcDest are different.
180 static inline void imagelist_copy_images( HIMAGELIST himl
, HDC hdcSrc
, HDC hdcDest
,
181 UINT src
, UINT count
, UINT dest
)
187 for ( i
=0; i
<TILE_COUNT
; i
++ )
189 imagelist_point_from_index( himl
, src
+i
, &ptSrc
);
190 imagelist_point_from_index( himl
, dest
+i
, &ptDest
);
192 sz
.cy
= himl
->cy
* imagelist_height( count
- i
);
194 BitBlt( hdcDest
, ptDest
.x
, ptDest
.y
, sz
.cx
, sz
.cy
,
195 hdcSrc
, ptSrc
.x
, ptSrc
.y
, SRCCOPY
);
199 static void add_dib_bits( HIMAGELIST himl
, int pos
, int count
, int width
, int height
,
200 BITMAPINFO
*info
, BITMAPINFO
*mask_info
, DWORD
*bits
, BYTE
*mask_bits
)
204 int stride
= info
->bmiHeader
.biWidth
;
205 int mask_stride
= (info
->bmiHeader
.biWidth
+ 31) / 32 * 4;
207 for (n
= 0; n
< count
; n
++)
209 BOOL has_alpha
= FALSE
;
211 imagelist_point_from_index( himl
, pos
+ n
, &pt
);
213 /* check if bitmap has an alpha channel */
214 for (i
= 0; i
< height
&& !has_alpha
; i
++)
215 for (j
= n
* width
; j
< (n
+ 1) * width
; j
++)
216 if ((has_alpha
= ((bits
[i
* stride
+ j
] & 0xff000000) != 0))) break;
218 if (!has_alpha
) /* generate alpha channel from the mask */
220 for (i
= 0; i
< height
; i
++)
221 for (j
= n
* width
; j
< (n
+ 1) * width
; j
++)
222 if (!mask_info
|| !((mask_bits
[i
* mask_stride
+ j
/ 8] << (j
% 8)) & 0x80))
223 bits
[i
* stride
+ j
] |= 0xff000000;
225 bits
[i
* stride
+ j
] = 0;
229 himl
->has_alpha
[pos
+ n
] = 1;
231 if (mask_info
&& himl
->hbmMask
) /* generate the mask from the alpha channel */
233 for (i
= 0; i
< height
; i
++)
234 for (j
= n
* width
; j
< (n
+ 1) * width
; j
++)
235 if ((bits
[i
* stride
+ j
] >> 24) > 25) /* more than 10% alpha */
236 mask_bits
[i
* mask_stride
+ j
/ 8] &= ~(0x80 >> (j
% 8));
238 mask_bits
[i
* mask_stride
+ j
/ 8] |= 0x80 >> (j
% 8);
241 StretchDIBits( himl
->hdcImage
, pt
.x
, pt
.y
, himl
->cx
, himl
->cy
,
242 n
* width
, 0, width
, height
, bits
, info
, DIB_RGB_COLORS
, SRCCOPY
);
244 StretchDIBits( himl
->hdcMask
, pt
.x
, pt
.y
, himl
->cx
, himl
->cy
,
245 n
* width
, 0, width
, height
, mask_bits
, mask_info
, DIB_RGB_COLORS
, SRCCOPY
);
249 /* add images with an alpha channel when the image list is 32 bpp */
250 static BOOL
add_with_alpha( HIMAGELIST himl
, HDC hdc
, int pos
, int count
,
251 int width
, int height
, HBITMAP hbmImage
, HBITMAP hbmMask
)
255 BITMAPINFO
*info
, *mask_info
= NULL
;
257 BYTE
*mask_bits
= NULL
;
260 if (!GetObjectW( hbmImage
, sizeof(bm
), &bm
)) return FALSE
;
262 /* if either the imagelist or the source bitmap don't have an alpha channel, bail out now */
263 if (!himl
->has_alpha
) return FALSE
;
264 if (bm
.bmBitsPixel
!= 32) return FALSE
;
266 SelectObject( hdc
, hbmImage
);
267 mask_width
= (bm
.bmWidth
+ 31) / 32 * 4;
269 if (!(info
= heap_alloc( FIELD_OFFSET( BITMAPINFO
, bmiColors
[256] )))) goto done
;
270 info
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
271 info
->bmiHeader
.biWidth
= bm
.bmWidth
;
272 info
->bmiHeader
.biHeight
= -height
;
273 info
->bmiHeader
.biPlanes
= 1;
274 info
->bmiHeader
.biBitCount
= 32;
275 info
->bmiHeader
.biCompression
= BI_RGB
;
276 info
->bmiHeader
.biSizeImage
= bm
.bmWidth
* height
* 4;
277 info
->bmiHeader
.biXPelsPerMeter
= 0;
278 info
->bmiHeader
.biYPelsPerMeter
= 0;
279 info
->bmiHeader
.biClrUsed
= 0;
280 info
->bmiHeader
.biClrImportant
= 0;
281 if (!(bits
= heap_alloc( info
->bmiHeader
.biSizeImage
))) goto done
;
282 if (!GetDIBits( hdc
, hbmImage
, 0, height
, bits
, info
, DIB_RGB_COLORS
)) goto done
;
286 if (!(mask_info
= heap_alloc( FIELD_OFFSET( BITMAPINFO
, bmiColors
[2] ))))
288 mask_info
->bmiHeader
= info
->bmiHeader
;
289 mask_info
->bmiHeader
.biBitCount
= 1;
290 mask_info
->bmiHeader
.biSizeImage
= mask_width
* height
;
291 if (!(mask_bits
= heap_alloc_zero( mask_info
->bmiHeader
.biSizeImage
)))
293 if (!GetDIBits( hdc
, hbmMask
, 0, height
, mask_bits
, mask_info
, DIB_RGB_COLORS
)) goto done
;
296 add_dib_bits( himl
, pos
, count
, width
, height
, info
, mask_info
, bits
, mask_bits
);
301 heap_free( mask_info
);
303 heap_free( mask_bits
);
308 ImageList_SetColorTable(HIMAGELIST himl
, UINT uStartIndex
, UINT cEntries
, const RGBQUAD
*prgb
);
310 /*************************************************************************
311 * IMAGELIST_InternalExpandBitmaps [Internal]
313 * Expands the bitmaps of an image list by the given number of images.
316 * himl [I] handle to image list
317 * nImageCount [I] number of images to add
323 * This function CANNOT be used to reduce the number of images.
326 IMAGELIST_InternalExpandBitmaps(HIMAGELIST himl
, INT nImageCount
)
329 HBITMAP hbmNewBitmap
, hbmNull
;
333 TRACE("%p has allocated %d, max %d, grow %d images\n", himl
, himl
->cCurImage
, himl
->cMaxImage
, himl
->cGrow
);
335 if (himl
->cCurImage
+ nImageCount
< himl
->cMaxImage
)
338 nNewCount
= himl
->cMaxImage
+ max(nImageCount
, himl
->cGrow
) + 1;
340 imagelist_get_bitmap_size(himl
, nNewCount
, &sz
);
342 TRACE("Create expanded bitmaps : himl=%p x=%d y=%d count=%d\n", himl
, sz
.cx
, sz
.cy
, nNewCount
);
343 hdcBitmap
= CreateCompatibleDC (0);
345 hbmNewBitmap
= ImageList_CreateImage(hdcBitmap
, himl
, nNewCount
);
347 if (hbmNewBitmap
== 0)
348 ERR("creating new image bitmap (x=%d y=%d)!\n", sz
.cx
, sz
.cy
);
352 hbmNull
= SelectObject (hdcBitmap
, hbmNewBitmap
);
353 BitBlt (hdcBitmap
, 0, 0, sz
.cx
, sz
.cy
,
354 himl
->hdcImage
, 0, 0, SRCCOPY
);
355 SelectObject (hdcBitmap
, hbmNull
);
357 SelectObject (himl
->hdcImage
, hbmNewBitmap
);
358 DeleteObject (himl
->hbmImage
);
359 himl
->hbmImage
= hbmNewBitmap
;
361 if (himl
->flags
& ILC_MASK
)
363 hbmNewBitmap
= CreateBitmap (sz
.cx
, sz
.cy
, 1, 1, NULL
);
365 if (hbmNewBitmap
== 0)
366 ERR("creating new mask bitmap!\n");
370 hbmNull
= SelectObject (hdcBitmap
, hbmNewBitmap
);
371 BitBlt (hdcBitmap
, 0, 0, sz
.cx
, sz
.cy
,
372 himl
->hdcMask
, 0, 0, SRCCOPY
);
373 SelectObject (hdcBitmap
, hbmNull
);
375 SelectObject (himl
->hdcMask
, hbmNewBitmap
);
376 DeleteObject (himl
->hbmMask
);
377 himl
->hbmMask
= hbmNewBitmap
;
382 char *new_alpha
= HeapReAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, himl
->has_alpha
, nNewCount
);
383 if (new_alpha
) himl
->has_alpha
= new_alpha
;
386 heap_free( himl
->has_alpha
);
387 himl
->has_alpha
= NULL
;
391 himl
->cMaxImage
= nNewCount
;
393 DeleteDC (hdcBitmap
);
397 /*************************************************************************
398 * ImageList_Add [COMCTL32.@]
400 * Add an image or images to an image list.
403 * himl [I] handle to image list
404 * hbmImage [I] handle to image bitmap
405 * hbmMask [I] handle to mask bitmap
408 * Success: Index of the first new image.
413 ImageList_Add (HIMAGELIST himl
, HBITMAP hbmImage
, HBITMAP hbmMask
)
415 HDC hdcBitmap
, hdcTemp
= 0;
416 INT nFirstIndex
, nImageCount
, i
;
420 TRACE("himl=%p hbmimage=%p hbmmask=%p\n", himl
, hbmImage
, hbmMask
);
424 if (!GetObjectW(hbmImage
, sizeof(BITMAP
), &bmp
))
427 TRACE("himl %p, cCurImage %d, cMaxImage %d, cGrow %d, cx %d, cy %d\n",
428 himl
, himl
->cCurImage
, himl
->cMaxImage
, himl
->cGrow
, himl
->cx
, himl
->cy
);
430 nImageCount
= bmp
.bmWidth
/ himl
->cx
;
432 TRACE("%p has %d images (%d x %d) bpp %d\n", hbmImage
, nImageCount
, bmp
.bmWidth
, bmp
.bmHeight
,
435 IMAGELIST_InternalExpandBitmaps(himl
, nImageCount
);
437 hdcBitmap
= CreateCompatibleDC(0);
439 SelectObject(hdcBitmap
, hbmImage
);
441 if (add_with_alpha( himl
, hdcBitmap
, himl
->cCurImage
, nImageCount
,
442 himl
->cx
, min( himl
->cy
, bmp
.bmHeight
), hbmImage
, hbmMask
))
447 hdcTemp
= CreateCompatibleDC(0);
448 SelectObject(hdcTemp
, hbmMask
);
451 if (himl
->uBitsPixel
<= 8 && bmp
.bmBitsPixel
<= 8 &&
452 !himl
->color_table_set
&& himl
->cCurImage
== 0)
455 UINT num
= GetDIBColorTable( hdcBitmap
, 0, 1 << bmp
.bmBitsPixel
, colors
);
456 if (num
) ImageList_SetColorTable( himl
, 0, num
, colors
);
459 for (i
=0; i
<nImageCount
; i
++)
461 imagelist_point_from_index( himl
, himl
->cCurImage
+ i
, &pt
);
463 /* Copy result to the imagelist
465 BitBlt( himl
->hdcImage
, pt
.x
, pt
.y
, himl
->cx
, bmp
.bmHeight
,
466 hdcBitmap
, i
*himl
->cx
, 0, SRCCOPY
);
471 BitBlt( himl
->hdcMask
, pt
.x
, pt
.y
, himl
->cx
, bmp
.bmHeight
,
472 hdcTemp
, i
*himl
->cx
, 0, SRCCOPY
);
474 /* Remove the background from the image
476 BitBlt( himl
->hdcImage
, pt
.x
, pt
.y
, himl
->cx
, bmp
.bmHeight
,
477 himl
->hdcMask
, pt
.x
, pt
.y
, 0x220326 ); /* NOTSRCAND */
479 if (hdcTemp
) DeleteDC(hdcTemp
);
484 nFirstIndex
= himl
->cCurImage
;
485 himl
->cCurImage
+= nImageCount
;
491 /*************************************************************************
492 * ImageList_AddIcon [COMCTL32.@]
494 * Adds an icon to an image list.
497 * himl [I] handle to image list
498 * hIcon [I] handle to icon
501 * Success: index of the new image
504 #undef ImageList_AddIcon
505 INT WINAPI
ImageList_AddIcon (HIMAGELIST himl
, HICON hIcon
)
507 return ImageList_ReplaceIcon (himl
, -1, hIcon
);
511 /*************************************************************************
512 * ImageList_AddMasked [COMCTL32.@]
514 * Adds an image or images to an image list and creates a mask from the
515 * specified bitmap using the mask color.
518 * himl [I] handle to image list.
519 * hBitmap [I] handle to bitmap
520 * clrMask [I] mask color.
523 * Success: Index of the first new image.
528 ImageList_AddMasked (HIMAGELIST himl
, HBITMAP hBitmap
, COLORREF clrMask
)
530 HDC hdcMask
, hdcBitmap
;
536 TRACE("himl=%p hbitmap=%p clrmask=%x\n", himl
, hBitmap
, clrMask
);
540 if (!GetObjectW(hBitmap
, sizeof(BITMAP
), &bmp
))
543 hdcBitmap
= CreateCompatibleDC(0);
544 SelectObject(hdcBitmap
, hBitmap
);
546 /* Create a temp Mask so we can remove the background of the Image */
547 hdcMask
= CreateCompatibleDC(0);
548 hMaskBitmap
= CreateBitmap(bmp
.bmWidth
, bmp
.bmHeight
, 1, 1, NULL
);
549 SelectObject(hdcMask
, hMaskBitmap
);
551 /* create monochrome image to the mask bitmap */
552 bkColor
= (clrMask
!= CLR_DEFAULT
) ? clrMask
: GetPixel (hdcBitmap
, 0, 0);
553 SetBkColor (hdcBitmap
, bkColor
);
554 BitBlt (hdcMask
, 0, 0, bmp
.bmWidth
, bmp
.bmHeight
, hdcBitmap
, 0, 0, SRCCOPY
);
557 * Remove the background from the image
559 * WINDOWS BUG ALERT!!!!!!
560 * The statement below should not be done in common practice
561 * but this is how ImageList_AddMasked works in Windows.
562 * It overwrites the original bitmap passed, this was discovered
563 * by using the same bitmap to iterate the different styles
564 * on windows where it failed (BUT ImageList_Add is OK)
565 * This is here in case some apps rely on this bug
567 * Blt mode 0x220326 is NOTSRCAND
569 if (bmp
.bmBitsPixel
> 8) /* NOTSRCAND can't work with palettes */
571 SetBkColor(hdcBitmap
, RGB(255,255,255));
572 BitBlt(hdcBitmap
, 0, 0, bmp
.bmWidth
, bmp
.bmHeight
, hdcMask
, 0, 0, 0x220326);
578 ret
= ImageList_Add( himl
, hBitmap
, hMaskBitmap
);
580 DeleteObject(hMaskBitmap
);
585 /*************************************************************************
586 * ImageList_BeginDrag [COMCTL32.@]
588 * Creates a temporary image list that contains one image. It will be used
592 * himlTrack [I] handle to the source image list
593 * iTrack [I] index of the drag image in the source image list
594 * dxHotspot [I] X position of the hot spot of the drag image
595 * dyHotspot [I] Y position of the hot spot of the drag image
603 ImageList_BeginDrag (HIMAGELIST himlTrack
, INT iTrack
,
604 INT dxHotspot
, INT dyHotspot
)
609 TRACE("(himlTrack=%p iTrack=%d dx=%d dy=%d)\n", himlTrack
, iTrack
,
610 dxHotspot
, dyHotspot
);
612 if (!is_valid(himlTrack
))
615 if (iTrack
>= himlTrack
->cCurImage
)
618 if (InternalDrag
.himl
)
624 InternalDrag
.himlNoCursor
= InternalDrag
.himl
= ImageList_Create (cx
, cy
, himlTrack
->flags
, 1, 1);
625 if (InternalDrag
.himl
== NULL
) {
626 WARN("Error creating drag image list!\n");
630 InternalDrag
.dxHotspot
= dxHotspot
;
631 InternalDrag
.dyHotspot
= dyHotspot
;
634 imagelist_point_from_index(InternalDrag
.himl
, 0, &dst
);
635 imagelist_point_from_index(himlTrack
, iTrack
, &src
);
636 BitBlt(InternalDrag
.himl
->hdcImage
, dst
.x
, dst
.y
, cx
, cy
, himlTrack
->hdcImage
, src
.x
, src
.y
,
638 BitBlt(InternalDrag
.himl
->hdcMask
, dst
.x
, dst
.y
, cx
, cy
, himlTrack
->hdcMask
, src
.x
, src
.y
,
641 InternalDrag
.himl
->cCurImage
= 1;
647 /*************************************************************************
648 * ImageList_Copy [COMCTL32.@]
650 * Copies an image of the source image list to an image of the
651 * destination image list. Images can be copied or swapped.
654 * himlDst [I] handle to the destination image list
655 * iDst [I] destination image index.
656 * himlSrc [I] handle to the source image list
657 * iSrc [I] source image index
658 * uFlags [I] flags for the copy operation
665 * Copying from one image list to another is possible. The original
666 * implementation just copies or swaps within one image list.
667 * Could this feature become a bug??? ;-)
671 ImageList_Copy (HIMAGELIST himlDst
, INT iDst
, HIMAGELIST himlSrc
,
672 INT iSrc
, UINT uFlags
)
676 TRACE("himlDst=%p iDst=%d himlSrc=%p iSrc=%d\n", himlDst
, iDst
, himlSrc
, iSrc
);
678 if (!is_valid(himlSrc
) || !is_valid(himlDst
))
680 if ((iDst
< 0) || (iDst
>= himlDst
->cCurImage
))
682 if ((iSrc
< 0) || (iSrc
>= himlSrc
->cCurImage
))
685 imagelist_point_from_index( himlDst
, iDst
, &ptDst
);
686 imagelist_point_from_index( himlSrc
, iSrc
, &ptSrc
);
688 if (uFlags
& ILCF_SWAP
) {
691 HBITMAP hbmTempImage
, hbmTempMask
;
693 hdcBmp
= CreateCompatibleDC (0);
695 /* create temporary bitmaps */
696 hbmTempImage
= CreateBitmap (himlSrc
->cx
, himlSrc
->cy
, 1,
697 himlSrc
->uBitsPixel
, NULL
);
698 hbmTempMask
= CreateBitmap (himlSrc
->cx
, himlSrc
->cy
, 1,
701 /* copy (and stretch) destination to temporary bitmaps.(save) */
703 SelectObject (hdcBmp
, hbmTempImage
);
704 StretchBlt (hdcBmp
, 0, 0, himlSrc
->cx
, himlSrc
->cy
,
705 himlDst
->hdcImage
, ptDst
.x
, ptDst
.y
, himlDst
->cx
, himlDst
->cy
,
708 SelectObject (hdcBmp
, hbmTempMask
);
709 StretchBlt (hdcBmp
, 0, 0, himlSrc
->cx
, himlSrc
->cy
,
710 himlDst
->hdcMask
, ptDst
.x
, ptDst
.y
, himlDst
->cx
, himlDst
->cy
,
713 /* copy (and stretch) source to destination */
715 StretchBlt (himlDst
->hdcImage
, ptDst
.x
, ptDst
.y
, himlDst
->cx
, himlDst
->cy
,
716 himlSrc
->hdcImage
, ptSrc
.x
, ptSrc
.y
, himlSrc
->cx
, himlSrc
->cy
,
719 StretchBlt (himlDst
->hdcMask
, ptDst
.x
, ptDst
.y
, himlDst
->cx
, himlDst
->cy
,
720 himlSrc
->hdcMask
, ptSrc
.x
, ptSrc
.y
, himlSrc
->cx
, himlSrc
->cy
,
723 /* copy (without stretching) temporary bitmaps to source (restore) */
725 BitBlt (himlSrc
->hdcMask
, ptSrc
.x
, ptSrc
.y
, himlSrc
->cx
, himlSrc
->cy
,
726 hdcBmp
, 0, 0, SRCCOPY
);
729 BitBlt (himlSrc
->hdcImage
, ptSrc
.x
, ptSrc
.y
, himlSrc
->cx
, himlSrc
->cy
,
730 hdcBmp
, 0, 0, SRCCOPY
);
731 /* delete temporary bitmaps */
732 DeleteObject (hbmTempMask
);
733 DeleteObject (hbmTempImage
);
738 StretchBlt (himlDst
->hdcImage
, ptDst
.x
, ptDst
.y
, himlDst
->cx
, himlDst
->cy
,
739 himlSrc
->hdcImage
, ptSrc
.x
, ptSrc
.y
, himlSrc
->cx
, himlSrc
->cy
,
743 StretchBlt (himlDst
->hdcMask
, ptDst
.x
, ptDst
.y
, himlDst
->cx
, himlDst
->cy
,
744 himlSrc
->hdcMask
, ptSrc
.x
, ptSrc
.y
, himlSrc
->cx
, himlSrc
->cy
,
752 /*************************************************************************
753 * ImageList_Create [COMCTL32.@]
755 * Creates a new image list.
758 * cx [I] image height
760 * flags [I] creation flags
761 * cInitial [I] initial number of images in the image list
762 * cGrow [I] number of images by which image list grows
765 * Success: Handle to the created image list
769 ImageList_Create (INT cx
, INT cy
, UINT flags
,
770 INT cInitial
, INT cGrow
)
775 UINT ilc
= (flags
& 0xFE);
776 static const WORD aBitBlend25
[] =
777 {0xAA, 0x00, 0x55, 0x00, 0xAA, 0x00, 0x55, 0x00};
779 static const WORD aBitBlend50
[] =
780 {0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA};
782 TRACE("(%d %d 0x%x %d %d)\n", cx
, cy
, flags
, cInitial
, cGrow
);
784 if (cx
< 0 || cy
< 0) return NULL
;
785 if (!((flags
&ILC_COLORDDB
) == ILC_COLORDDB
) && (cx
== 0 || cy
== 0)) return NULL
;
787 /* Create the IImageList interface for the image list */
788 if (FAILED(ImageListImpl_CreateInstance(NULL
, &IID_IImageList
, (void **)&himl
)))
791 cGrow
= (WORD
)((max( cGrow
, 1 ) + 3) & ~3);
795 /* Windows doesn't limit the size here, but X11 doesn't let us allocate such huge bitmaps */
796 WARN( "grow %d too large, limiting to 256\n", cGrow
);
803 himl
->cMaxImage
= cInitial
+ 1;
804 himl
->cInitial
= cInitial
;
806 himl
->clrFg
= CLR_DEFAULT
;
807 himl
->clrBk
= CLR_NONE
;
808 himl
->color_table_set
= FALSE
;
810 /* initialize overlay mask indices */
811 for (nCount
= 0; nCount
< MAX_OVERLAYIMAGE
; nCount
++)
812 himl
->nOvlIdx
[nCount
] = -1;
814 /* Create Image & Mask DCs */
815 himl
->hdcImage
= CreateCompatibleDC (0);
818 if (himl
->flags
& ILC_MASK
){
819 himl
->hdcMask
= CreateCompatibleDC(0);
824 /* Default to ILC_COLOR4 if none of the ILC_COLOR* flags are specified */
825 if (ilc
== ILC_COLOR
)
828 himl
->flags
|= ILC_COLOR4
;
831 if (ilc
>= ILC_COLOR4
&& ilc
<= ILC_COLOR32
)
832 himl
->uBitsPixel
= ilc
;
834 himl
->uBitsPixel
= (UINT
)GetDeviceCaps (himl
->hdcImage
, BITSPIXEL
);
836 if (himl
->cMaxImage
> 0) {
837 himl
->hbmImage
= ImageList_CreateImage(himl
->hdcImage
, himl
, himl
->cMaxImage
);
838 SelectObject(himl
->hdcImage
, himl
->hbmImage
);
842 if ((himl
->cMaxImage
> 0) && (himl
->flags
& ILC_MASK
)) {
845 imagelist_get_bitmap_size(himl
, himl
->cMaxImage
, &sz
);
846 himl
->hbmMask
= CreateBitmap (sz
.cx
, sz
.cy
, 1, 1, NULL
);
847 if (himl
->hbmMask
== 0) {
848 ERR("Error creating mask bitmap!\n");
851 SelectObject(himl
->hdcMask
, himl
->hbmMask
);
856 if (ilc
== ILC_COLOR32
)
857 himl
->has_alpha
= heap_alloc_zero( himl
->cMaxImage
);
859 himl
->has_alpha
= NULL
;
861 /* create blending brushes */
862 hbmTemp
= CreateBitmap (8, 8, 1, 1, aBitBlend25
);
863 himl
->hbrBlend25
= CreatePatternBrush (hbmTemp
);
864 DeleteObject (hbmTemp
);
866 hbmTemp
= CreateBitmap (8, 8, 1, 1, aBitBlend50
);
867 himl
->hbrBlend50
= CreatePatternBrush (hbmTemp
);
868 DeleteObject (hbmTemp
);
870 TRACE("created imagelist %p\n", himl
);
874 ImageList_Destroy(himl
);
879 /*************************************************************************
880 * ImageList_Destroy [COMCTL32.@]
882 * Destroys an image list.
885 * himl [I] handle to image list
893 ImageList_Destroy (HIMAGELIST himl
)
898 IImageList_Release((IImageList
*) himl
);
903 /*************************************************************************
904 * ImageList_DragEnter [COMCTL32.@]
906 * Locks window update and displays the drag image at the given position.
909 * hwndLock [I] handle of the window that owns the drag image.
910 * x [I] X position of the drag image.
911 * y [I] Y position of the drag image.
918 * The position of the drag image is relative to the window, not
923 ImageList_DragEnter (HWND hwndLock
, INT x
, INT y
)
925 TRACE("(hwnd=%p x=%d y=%d)\n", hwndLock
, x
, y
);
927 if (!is_valid(InternalDrag
.himl
))
931 InternalDrag
.hwnd
= hwndLock
;
933 InternalDrag
.hwnd
= GetDesktopWindow ();
938 /* draw the drag image and save the background */
939 return ImageList_DragShowNolock(TRUE
);
943 /*************************************************************************
944 * ImageList_DragLeave [COMCTL32.@]
946 * Unlocks window update and hides the drag image.
949 * hwndLock [I] handle of the window that owns the drag image.
957 ImageList_DragLeave (HWND hwndLock
)
959 /* As we don't save drag info in the window this can lead to problems if
960 an app does not supply the same window as DragEnter */
962 InternalDrag.hwnd = hwndLock;
964 InternalDrag.hwnd = GetDesktopWindow (); */
966 hwndLock
= GetDesktopWindow();
967 if(InternalDrag
.hwnd
!= hwndLock
)
968 FIXME("DragLeave hWnd != DragEnter hWnd\n");
970 ImageList_DragShowNolock (FALSE
);
976 /*************************************************************************
977 * ImageList_InternalDragDraw [Internal]
979 * Draws the drag image.
982 * hdc [I] device context to draw into.
983 * x [I] X position of the drag image.
984 * y [I] Y position of the drag image.
991 * The position of the drag image is relative to the window, not
997 ImageList_InternalDragDraw (HDC hdc
, INT x
, INT y
)
999 IMAGELISTDRAWPARAMS imldp
;
1001 ZeroMemory (&imldp
, sizeof(imldp
));
1002 imldp
.cbSize
= sizeof(imldp
);
1003 imldp
.himl
= InternalDrag
.himl
;
1008 imldp
.rgbBk
= CLR_DEFAULT
;
1009 imldp
.rgbFg
= CLR_DEFAULT
;
1010 imldp
.fStyle
= ILD_NORMAL
;
1011 imldp
.fState
= ILS_ALPHA
;
1013 ImageList_DrawIndirect (&imldp
);
1016 /*************************************************************************
1017 * ImageList_DragMove [COMCTL32.@]
1019 * Moves the drag image.
1022 * x [I] X position of the drag image.
1023 * y [I] Y position of the drag image.
1030 * The position of the drag image is relative to the window, not
1035 ImageList_DragMove (INT x
, INT y
)
1037 TRACE("(x=%d y=%d)\n", x
, y
);
1039 if (!is_valid(InternalDrag
.himl
))
1042 /* draw/update the drag image */
1043 if (InternalDrag
.bShow
) {
1047 HBITMAP hbmOffScreen
;
1048 INT origNewX
, origNewY
;
1049 INT origOldX
, origOldY
;
1050 INT origRegX
, origRegY
;
1051 INT sizeRegX
, sizeRegY
;
1054 /* calculate the update region */
1055 origNewX
= x
- InternalDrag
.dxHotspot
;
1056 origNewY
= y
- InternalDrag
.dyHotspot
;
1057 origOldX
= InternalDrag
.x
- InternalDrag
.dxHotspot
;
1058 origOldY
= InternalDrag
.y
- InternalDrag
.dyHotspot
;
1059 origRegX
= min(origNewX
, origOldX
);
1060 origRegY
= min(origNewY
, origOldY
);
1061 sizeRegX
= InternalDrag
.himl
->cx
+ abs(x
- InternalDrag
.x
);
1062 sizeRegY
= InternalDrag
.himl
->cy
+ abs(y
- InternalDrag
.y
);
1064 hdcDrag
= GetDCEx(InternalDrag
.hwnd
, 0,
1065 DCX_WINDOW
| DCX_CACHE
| DCX_LOCKWINDOWUPDATE
);
1066 hdcOffScreen
= CreateCompatibleDC(hdcDrag
);
1067 hdcBg
= CreateCompatibleDC(hdcDrag
);
1069 hbmOffScreen
= CreateCompatibleBitmap(hdcDrag
, sizeRegX
, sizeRegY
);
1070 SelectObject(hdcOffScreen
, hbmOffScreen
);
1071 SelectObject(hdcBg
, InternalDrag
.hbmBg
);
1073 /* get the actual background of the update region */
1074 BitBlt(hdcOffScreen
, 0, 0, sizeRegX
, sizeRegY
, hdcDrag
,
1075 origRegX
, origRegY
, SRCCOPY
);
1076 /* erase the old image */
1077 BitBlt(hdcOffScreen
, origOldX
- origRegX
, origOldY
- origRegY
,
1078 InternalDrag
.himl
->cx
, InternalDrag
.himl
->cy
, hdcBg
, 0, 0,
1080 /* save the background */
1081 BitBlt(hdcBg
, 0, 0, InternalDrag
.himl
->cx
, InternalDrag
.himl
->cy
,
1082 hdcOffScreen
, origNewX
- origRegX
, origNewY
- origRegY
, SRCCOPY
);
1083 /* draw the image */
1084 ImageList_InternalDragDraw(hdcOffScreen
, origNewX
- origRegX
,
1085 origNewY
- origRegY
);
1086 /* draw the update region to the screen */
1087 BitBlt(hdcDrag
, origRegX
, origRegY
, sizeRegX
, sizeRegY
,
1088 hdcOffScreen
, 0, 0, SRCCOPY
);
1091 DeleteDC(hdcOffScreen
);
1092 DeleteObject(hbmOffScreen
);
1093 ReleaseDC(InternalDrag
.hwnd
, hdcDrag
);
1096 /* update the image position */
1104 /*************************************************************************
1105 * ImageList_DragShowNolock [COMCTL32.@]
1107 * Shows or hides the drag image.
1110 * bShow [I] TRUE shows the drag image, FALSE hides it.
1118 ImageList_DragShowNolock (BOOL bShow
)
1124 if (!is_valid(InternalDrag
.himl
))
1127 TRACE("bShow=0x%X!\n", bShow
);
1129 /* DragImage is already visible/hidden */
1130 if ((InternalDrag
.bShow
&& bShow
) || (!InternalDrag
.bShow
&& !bShow
)) {
1134 /* position of the origin of the DragImage */
1135 x
= InternalDrag
.x
- InternalDrag
.dxHotspot
;
1136 y
= InternalDrag
.y
- InternalDrag
.dyHotspot
;
1138 hdcDrag
= GetDCEx (InternalDrag
.hwnd
, 0,
1139 DCX_WINDOW
| DCX_CACHE
| DCX_LOCKWINDOWUPDATE
);
1144 hdcBg
= CreateCompatibleDC(hdcDrag
);
1145 if (!InternalDrag
.hbmBg
) {
1146 InternalDrag
.hbmBg
= CreateCompatibleBitmap(hdcDrag
,
1147 InternalDrag
.himl
->cx
, InternalDrag
.himl
->cy
);
1149 SelectObject(hdcBg
, InternalDrag
.hbmBg
);
1152 /* save the background */
1153 BitBlt(hdcBg
, 0, 0, InternalDrag
.himl
->cx
, InternalDrag
.himl
->cy
,
1154 hdcDrag
, x
, y
, SRCCOPY
);
1155 /* show the image */
1156 ImageList_InternalDragDraw(hdcDrag
, x
, y
);
1158 /* hide the image */
1159 BitBlt(hdcDrag
, x
, y
, InternalDrag
.himl
->cx
, InternalDrag
.himl
->cy
,
1160 hdcBg
, 0, 0, SRCCOPY
);
1163 InternalDrag
.bShow
= !InternalDrag
.bShow
;
1166 ReleaseDC (InternalDrag
.hwnd
, hdcDrag
);
1171 /*************************************************************************
1172 * ImageList_Draw [COMCTL32.@]
1177 * himl [I] handle to image list
1179 * hdc [I] handle to device context
1182 * fStyle [I] drawing flags
1193 ImageList_Draw (HIMAGELIST himl
, INT i
, HDC hdc
, INT x
, INT y
, UINT fStyle
)
1195 return ImageList_DrawEx (himl
, i
, hdc
, x
, y
, 0, 0,
1196 CLR_DEFAULT
, CLR_DEFAULT
, fStyle
);
1200 /*************************************************************************
1201 * ImageList_DrawEx [COMCTL32.@]
1203 * Draws an image and allows using extended drawing features.
1206 * himl [I] handle to image list
1208 * hdc [I] handle to device context
1213 * rgbBk [I] background color
1214 * rgbFg [I] foreground color
1215 * fStyle [I] drawing flags
1222 * Calls ImageList_DrawIndirect.
1225 * ImageList_DrawIndirect.
1229 ImageList_DrawEx (HIMAGELIST himl
, INT i
, HDC hdc
, INT x
, INT y
,
1230 INT dx
, INT dy
, COLORREF rgbBk
, COLORREF rgbFg
,
1233 IMAGELISTDRAWPARAMS imldp
;
1235 ZeroMemory (&imldp
, sizeof(imldp
));
1236 imldp
.cbSize
= sizeof(imldp
);
1244 imldp
.rgbBk
= rgbBk
;
1245 imldp
.rgbFg
= rgbFg
;
1246 imldp
.fStyle
= fStyle
;
1248 return ImageList_DrawIndirect (&imldp
);
1252 static BOOL
alpha_blend_image( HIMAGELIST himl
, HDC srce_dc
, HDC dest_dc
, int dest_x
, int dest_y
,
1254 static BOOL
alpha_blend_image( HIMAGELIST himl
, HDC dest_dc
, int dest_x
, int dest_y
,
1256 int src_x
, int src_y
, int cx
, int cy
, BLENDFUNCTION func
,
1257 UINT style
, COLORREF blend_col
)
1261 HBITMAP bmp
= 0, mask
= 0;
1263 void *bits
, *mask_bits
;
1267 if (!(hdc
= CreateCompatibleDC( 0 ))) return FALSE
;
1268 if (!(info
= heap_alloc( FIELD_OFFSET( BITMAPINFO
, bmiColors
[256] )))) goto done
;
1269 info
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
1270 info
->bmiHeader
.biWidth
= cx
;
1271 info
->bmiHeader
.biHeight
= cy
;
1272 info
->bmiHeader
.biPlanes
= 1;
1273 info
->bmiHeader
.biBitCount
= 32;
1274 info
->bmiHeader
.biCompression
= BI_RGB
;
1275 info
->bmiHeader
.biSizeImage
= cx
* cy
* 4;
1276 info
->bmiHeader
.biXPelsPerMeter
= 0;
1277 info
->bmiHeader
.biYPelsPerMeter
= 0;
1278 info
->bmiHeader
.biClrUsed
= 0;
1279 info
->bmiHeader
.biClrImportant
= 0;
1281 if (!(bmp
= CreateDIBSection( srce_dc
, info
, DIB_RGB_COLORS
, &bits
, 0, 0 ))) goto done
;
1283 if (!(bmp
= CreateDIBSection( himl
->hdcImage
, info
, DIB_RGB_COLORS
, &bits
, 0, 0 ))) goto done
;
1285 SelectObject( hdc
, bmp
);
1287 BitBlt( hdc
, 0, 0, cx
, cy
, srce_dc
, src_x
, src_y
, SRCCOPY
);
1289 BitBlt( hdc
, 0, 0, cx
, cy
, himl
->hdcImage
, src_x
, src_y
, SRCCOPY
);
1292 if (blend_col
!= CLR_NONE
)
1294 BYTE r
= GetRValue( blend_col
);
1295 BYTE g
= GetGValue( blend_col
);
1296 BYTE b
= GetBValue( blend_col
);
1298 if (style
& ILD_BLEND25
)
1300 for (i
= 0, ptr
= bits
; i
< cx
* cy
; i
++, ptr
++)
1301 *ptr
= ((*ptr
& 0xff000000) |
1302 ((((*ptr
& 0x00ff0000) * 3 + (r
<< 16)) / 4) & 0x00ff0000) |
1303 ((((*ptr
& 0x0000ff00) * 3 + (g
<< 8)) / 4) & 0x0000ff00) |
1304 ((((*ptr
& 0x000000ff) * 3 + (b
<< 0)) / 4) & 0x000000ff));
1306 else if (style
& ILD_BLEND50
)
1308 for (i
= 0, ptr
= bits
; i
< cx
* cy
; i
++, ptr
++)
1309 *ptr
= ((*ptr
& 0xff000000) |
1310 ((((*ptr
& 0x00ff0000) + (r
<< 16)) / 2) & 0x00ff0000) |
1311 ((((*ptr
& 0x0000ff00) + (g
<< 8)) / 2) & 0x0000ff00) |
1312 ((((*ptr
& 0x000000ff) + (b
<< 0)) / 2) & 0x000000ff));
1316 if (himl
->has_alpha
) /* we already have an alpha channel in this case */
1318 /* pre-multiply by the alpha channel */
1319 for (i
= 0, ptr
= bits
; i
< cx
* cy
; i
++, ptr
++)
1321 DWORD alpha
= *ptr
>> 24;
1322 *ptr
= ((*ptr
& 0xff000000) |
1323 (((*ptr
& 0x00ff0000) * alpha
/ 255) & 0x00ff0000) |
1324 (((*ptr
& 0x0000ff00) * alpha
/ 255) & 0x0000ff00) |
1325 (((*ptr
& 0x000000ff) * alpha
/ 255)));
1328 else if (himl
->hbmMask
)
1330 unsigned int width_bytes
= (cx
+ 31) / 32 * 4;
1331 /* generate alpha channel from the mask */
1332 info
->bmiHeader
.biBitCount
= 1;
1333 info
->bmiHeader
.biSizeImage
= width_bytes
* cy
;
1334 info
->bmiColors
[0].rgbRed
= 0;
1335 info
->bmiColors
[0].rgbGreen
= 0;
1336 info
->bmiColors
[0].rgbBlue
= 0;
1337 info
->bmiColors
[0].rgbReserved
= 0;
1338 info
->bmiColors
[1].rgbRed
= 0xff;
1339 info
->bmiColors
[1].rgbGreen
= 0xff;
1340 info
->bmiColors
[1].rgbBlue
= 0xff;
1341 info
->bmiColors
[1].rgbReserved
= 0;
1342 if (!(mask
= CreateDIBSection( himl
->hdcMask
, info
, DIB_RGB_COLORS
, &mask_bits
, 0, 0 )))
1344 SelectObject( hdc
, mask
);
1345 BitBlt( hdc
, 0, 0, cx
, cy
, himl
->hdcMask
, src_x
, src_y
, SRCCOPY
);
1346 SelectObject( hdc
, bmp
);
1347 for (i
= 0, ptr
= bits
; i
< cy
; i
++)
1348 for (j
= 0; j
< cx
; j
++, ptr
++)
1349 if ((((BYTE
*)mask_bits
)[i
* width_bytes
+ j
/ 8] << (j
% 8)) & 0x80) *ptr
= 0;
1350 else *ptr
|= 0xff000000;
1353 ret
= GdiAlphaBlend( dest_dc
, dest_x
, dest_y
, cx
, cy
, hdc
, 0, 0, cx
, cy
, func
);
1357 if (bmp
) DeleteObject( bmp
);
1358 if (mask
) DeleteObject( mask
);
1364 HDC
saturate_image( HIMAGELIST himl
, HDC dest_dc
, int dest_x
, int dest_y
,
1365 int src_x
, int src_y
, int cx
, int cy
, COLORREF rgbFg
)
1375 /* create a dc and its device independent bitmap for doing the work,
1376 shamelessly copied from the alpha-blending function above */
1377 if (!(hdc
= CreateCompatibleDC( 0 ))) return FALSE
;
1378 if (!(info
= HeapAlloc( GetProcessHeap(), 0, FIELD_OFFSET( BITMAPINFO
, bmiColors
[256] )))) goto done
;
1379 info
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
1380 info
->bmiHeader
.biWidth
= cx
;
1381 info
->bmiHeader
.biHeight
= cy
;
1382 info
->bmiHeader
.biPlanes
= 1;
1383 info
->bmiHeader
.biBitCount
= 32;
1384 info
->bmiHeader
.biCompression
= BI_RGB
;
1385 info
->bmiHeader
.biSizeImage
= cx
* cy
* 4;
1386 info
->bmiHeader
.biXPelsPerMeter
= 0;
1387 info
->bmiHeader
.biYPelsPerMeter
= 0;
1388 info
->bmiHeader
.biClrUsed
= 0;
1389 info
->bmiHeader
.biClrImportant
= 0;
1390 if (!(bmp
= CreateDIBSection(himl
->hdcImage
, info
, DIB_RGB_COLORS
, &bits
, 0, 0 ))) goto done
;
1392 /* bind both surfaces */
1393 SelectObject(hdc
, bmp
);
1395 /* copy into our dc the section that covers just the icon we we're asked for */
1396 BitBlt(hdc
, 0, 0, cx
, cy
, himl
->hdcImage
, src_x
, src_y
, SRCCOPY
);
1398 /* loop every pixel of the bitmap */
1399 for (i
= 0, ptr
= bits
; i
< cx
* cy
; i
++, ptr
++)
1401 COLORREF orig_color
= *ptr
;
1403 /* calculate the effective luminance using the constants from here, adapted to the human eye:
1404 <http://bobpowell.net/grayscale.aspx> */
1405 float mixed_color
= (GetRValue(orig_color
) * .30 +
1406 GetGValue(orig_color
) * .59 +
1407 GetBValue(orig_color
) * .11);
1409 *ptr
= RGBA(mixed_color
, mixed_color
, mixed_color
, GetAValue(orig_color
));
1418 HeapFree(GetProcessHeap(), 0, info
);
1420 /* return the handle to our desaturated dc, that will substitute its original counterpart in the next calls */
1423 #endif /* __REACTOS__ */
1425 /*************************************************************************
1426 * ImageList_DrawIndirect [COMCTL32.@]
1428 * Draws an image using various parameters specified in pimldp.
1431 * pimldp [I] pointer to IMAGELISTDRAWPARAMS structure.
1439 ImageList_DrawIndirect (IMAGELISTDRAWPARAMS
*pimldp
)
1441 INT cx
, cy
, nOvlIdx
;
1442 DWORD fState
, dwRop
;
1444 COLORREF oldImageBk
, oldImageFg
;
1445 HDC hImageDC
, hImageListDC
, hMaskListDC
;
1446 HBITMAP hImageBmp
, hOldImageBmp
, hBlendMaskBmp
;
1447 BOOL bIsTransparent
, bBlend
, bResult
= FALSE
, bMask
;
1453 HDC hdcSaturated
= NULL
;
1456 if (!pimldp
|| !(himl
= pimldp
->himl
)) return FALSE
;
1457 if (!is_valid(himl
)) return FALSE
;
1458 if ((pimldp
->i
< 0) || (pimldp
->i
>= himl
->cCurImage
)) return FALSE
;
1460 imagelist_point_from_index( himl
, pimldp
->i
, &pt
);
1461 pt
.x
+= pimldp
->xBitmap
;
1462 pt
.y
+= pimldp
->yBitmap
;
1464 fState
= pimldp
->cbSize
< sizeof(IMAGELISTDRAWPARAMS
) ? ILS_NORMAL
: pimldp
->fState
;
1465 fStyle
= pimldp
->fStyle
& ~ILD_OVERLAYMASK
;
1466 cx
= (pimldp
->cx
== 0) ? himl
->cx
: pimldp
->cx
;
1467 cy
= (pimldp
->cy
== 0) ? himl
->cy
: pimldp
->cy
;
1469 bIsTransparent
= (fStyle
& ILD_TRANSPARENT
);
1470 if( pimldp
->rgbBk
== CLR_NONE
)
1471 bIsTransparent
= TRUE
;
1472 if( ( pimldp
->rgbBk
== CLR_DEFAULT
) && ( himl
->clrBk
== CLR_NONE
) )
1473 bIsTransparent
= TRUE
;
1474 bMask
= (himl
->flags
& ILC_MASK
) && (fStyle
& ILD_MASK
) ;
1475 bBlend
= (fStyle
& (ILD_BLEND25
| ILD_BLEND50
) ) && !bMask
;
1477 TRACE("himl(%p) hbmMask(%p) iImage(%d) x(%d) y(%d) cx(%d) cy(%d)\n",
1478 himl
, himl
->hbmMask
, pimldp
->i
, pimldp
->x
, pimldp
->y
, cx
, cy
);
1480 /* we will use these DCs to access the images and masks in the ImageList */
1481 hImageListDC
= himl
->hdcImage
;
1482 hMaskListDC
= himl
->hdcMask
;
1484 /* these will accumulate the image and mask for the image we're drawing */
1485 hImageDC
= CreateCompatibleDC( pimldp
->hdcDst
);
1486 hImageBmp
= CreateCompatibleBitmap( pimldp
->hdcDst
, cx
, cy
);
1487 hBlendMaskBmp
= bBlend
? CreateBitmap(cx
, cy
, 1, 1, NULL
) : 0;
1489 /* Create a compatible DC. */
1490 if (!hImageListDC
|| !hImageDC
|| !hImageBmp
||
1491 (bBlend
&& !hBlendMaskBmp
) || (himl
->hbmMask
&& !hMaskListDC
))
1494 hOldImageBmp
= SelectObject(hImageDC
, hImageBmp
);
1497 * To obtain a transparent look, background color should be set
1498 * to white and foreground color to black when blitting the
1501 oldImageFg
= SetTextColor( hImageDC
, RGB( 0, 0, 0 ) );
1502 oldImageBk
= SetBkColor( hImageDC
, RGB( 0xff, 0xff, 0xff ) );
1506 * If the ILS_SATURATE bit is enabled we should multiply the
1507 * RGB colors of the original image by the contents of rgbFg.
1509 if (fState
& ILS_SATURATE
)
1511 hdcSaturated
= saturate_image(himl
, pimldp
->hdcDst
, pimldp
->x
, pimldp
->y
,
1512 pt
.x
, pt
.y
, cx
, cy
, pimldp
->rgbFg
);
1514 hImageListDC
= hdcSaturated
;
1515 /* shitty way of getting subroutines to blit at the right place (top left corner),
1516 as our modified imagelist only contains a single image for performance reasons */
1522 has_alpha
= (himl
->has_alpha
&& himl
->has_alpha
[pimldp
->i
]);
1523 if (!bMask
&& (has_alpha
|| (fState
& ILS_ALPHA
)))
1525 COLORREF colour
, blend_col
= CLR_NONE
;
1530 blend_col
= pimldp
->rgbFg
;
1531 if (blend_col
== CLR_DEFAULT
) blend_col
= GetSysColor( COLOR_HIGHLIGHT
);
1532 else if (blend_col
== CLR_NONE
) blend_col
= GetTextColor( pimldp
->hdcDst
);
1535 func
.BlendOp
= AC_SRC_OVER
;
1536 func
.BlendFlags
= 0;
1537 func
.SourceConstantAlpha
= (fState
& ILS_ALPHA
) ? pimldp
->Frame
: 255;
1538 func
.AlphaFormat
= AC_SRC_ALPHA
;
1543 bResult
= alpha_blend_image( himl
, hImageListDC
, pimldp
->hdcDst
, pimldp
->x
, pimldp
->y
,
1545 bResult
= alpha_blend_image( himl
, pimldp
->hdcDst
, pimldp
->x
, pimldp
->y
,
1547 pt
.x
, pt
.y
, cx
, cy
, func
, fStyle
, blend_col
);
1550 colour
= pimldp
->rgbBk
;
1551 if (colour
== CLR_DEFAULT
) colour
= himl
->clrBk
;
1552 if (colour
== CLR_NONE
) colour
= GetBkColor( pimldp
->hdcDst
);
1554 hOldBrush
= SelectObject (hImageDC
, CreateSolidBrush (colour
));
1555 PatBlt( hImageDC
, 0, 0, cx
, cy
, PATCOPY
);
1557 alpha_blend_image( himl
, hImageListDC
, hImageDC
, 0, 0, pt
.x
, pt
.y
, cx
, cy
, func
, fStyle
, blend_col
);
1559 alpha_blend_image( himl
, hImageDC
, 0, 0, pt
.x
, pt
.y
, cx
, cy
, func
, fStyle
, blend_col
);
1561 DeleteObject (SelectObject (hImageDC
, hOldBrush
));
1562 bResult
= BitBlt( pimldp
->hdcDst
, pimldp
->x
, pimldp
->y
, cx
, cy
, hImageDC
, 0, 0, SRCCOPY
);
1567 * Draw the initial image
1570 if (himl
->hbmMask
) {
1571 hOldBrush
= SelectObject (hImageDC
, CreateSolidBrush (GetTextColor(pimldp
->hdcDst
)));
1572 PatBlt( hImageDC
, 0, 0, cx
, cy
, PATCOPY
);
1573 BitBlt(hImageDC
, 0, 0, cx
, cy
, hMaskListDC
, pt
.x
, pt
.y
, SRCPAINT
);
1574 DeleteObject (SelectObject (hImageDC
, hOldBrush
));
1575 if( bIsTransparent
)
1577 BitBlt ( pimldp
->hdcDst
, pimldp
->x
, pimldp
->y
, cx
, cy
, hImageDC
, 0, 0, SRCAND
);
1582 hOldBrush
= SelectObject (hImageDC
, GetStockObject(BLACK_BRUSH
));
1583 PatBlt( hImageDC
, 0, 0, cx
, cy
, PATCOPY
);
1584 SelectObject(hImageDC
, hOldBrush
);
1587 /* blend the image with the needed solid background */
1588 COLORREF colour
= RGB(0,0,0);
1590 if( !bIsTransparent
)
1592 colour
= pimldp
->rgbBk
;
1593 if( colour
== CLR_DEFAULT
)
1594 colour
= himl
->clrBk
;
1595 if( colour
== CLR_NONE
)
1596 colour
= GetBkColor(pimldp
->hdcDst
);
1599 hOldBrush
= SelectObject (hImageDC
, CreateSolidBrush (colour
));
1600 PatBlt( hImageDC
, 0, 0, cx
, cy
, PATCOPY
);
1603 BitBlt( hImageDC
, 0, 0, cx
, cy
, hMaskListDC
, pt
.x
, pt
.y
, SRCAND
);
1604 BitBlt( hImageDC
, 0, 0, cx
, cy
, hImageListDC
, pt
.x
, pt
.y
, SRCPAINT
);
1607 BitBlt( hImageDC
, 0, 0, cx
, cy
, hImageListDC
, pt
.x
, pt
.y
, SRCCOPY
);
1608 DeleteObject (SelectObject (hImageDC
, hOldBrush
));
1611 /* Time for blending, if required */
1614 COLORREF clrBlend
= pimldp
->rgbFg
;
1615 HDC hBlendMaskDC
= hImageListDC
;
1618 /* Create the blend Mask */
1619 hOldBitmap
= SelectObject(hBlendMaskDC
, hBlendMaskBmp
);
1620 hBlendBrush
= fStyle
& ILD_BLEND50
? himl
->hbrBlend50
: himl
->hbrBlend25
;
1621 hOldBrush
= SelectObject(hBlendMaskDC
, hBlendBrush
);
1622 PatBlt(hBlendMaskDC
, 0, 0, cx
, cy
, PATCOPY
);
1623 SelectObject(hBlendMaskDC
, hOldBrush
);
1625 /* Modify the blend mask if an Image Mask exist */
1627 BitBlt(hBlendMaskDC
, 0, 0, cx
, cy
, hMaskListDC
, pt
.x
, pt
.y
, 0x220326); /* NOTSRCAND */
1628 BitBlt(hBlendMaskDC
, 0, 0, cx
, cy
, hBlendMaskDC
, 0, 0, NOTSRCCOPY
);
1631 /* now apply blend to the current image given the BlendMask */
1632 if (clrBlend
== CLR_DEFAULT
) clrBlend
= GetSysColor (COLOR_HIGHLIGHT
);
1633 else if (clrBlend
== CLR_NONE
) clrBlend
= GetTextColor (pimldp
->hdcDst
);
1634 hOldBrush
= SelectObject (hImageDC
, CreateSolidBrush(clrBlend
));
1635 BitBlt (hImageDC
, 0, 0, cx
, cy
, hBlendMaskDC
, 0, 0, 0xB8074A); /* PSDPxax */
1636 DeleteObject(SelectObject(hImageDC
, hOldBrush
));
1637 SelectObject(hBlendMaskDC
, hOldBitmap
);
1640 /* Now do the overlay image, if any */
1641 nOvlIdx
= (pimldp
->fStyle
& ILD_OVERLAYMASK
) >> 8;
1642 if ( (nOvlIdx
>= 1) && (nOvlIdx
<= MAX_OVERLAYIMAGE
)) {
1643 nOvlIdx
= himl
->nOvlIdx
[nOvlIdx
- 1];
1644 if ((nOvlIdx
>= 0) && (nOvlIdx
< himl
->cCurImage
)) {
1646 imagelist_point_from_index( himl
, nOvlIdx
, &ptOvl
);
1647 ptOvl
.x
+= pimldp
->xBitmap
;
1648 if (himl
->hbmMask
&& !(fStyle
& ILD_IMAGE
))
1649 BitBlt (hImageDC
, 0, 0, cx
, cy
, hMaskListDC
, ptOvl
.x
, ptOvl
.y
, SRCAND
);
1650 BitBlt (hImageDC
, 0, 0, cx
, cy
, hImageListDC
, ptOvl
.x
, ptOvl
.y
, SRCPAINT
);
1655 if (fState
& ILS_SATURATE
) FIXME("ILS_SATURATE: unimplemented!\n");
1657 if (fState
& ILS_GLOW
) FIXME("ILS_GLOW: unimplemented!\n");
1658 if (fState
& ILS_SHADOW
) FIXME("ILS_SHADOW: unimplemented!\n");
1660 if (fStyle
& ILD_PRESERVEALPHA
) FIXME("ILD_PRESERVEALPHA: unimplemented!\n");
1661 if (fStyle
& ILD_SCALE
) FIXME("ILD_SCALE: unimplemented!\n");
1662 if (fStyle
& ILD_DPISCALE
) FIXME("ILD_DPISCALE: unimplemented!\n");
1664 /* now copy the image to the screen */
1666 if (himl
->hbmMask
&& bIsTransparent
) {
1667 COLORREF oldDstFg
= SetTextColor(pimldp
->hdcDst
, RGB( 0, 0, 0 ) );
1668 COLORREF oldDstBk
= SetBkColor(pimldp
->hdcDst
, RGB( 0xff, 0xff, 0xff ));
1669 BitBlt (pimldp
->hdcDst
, pimldp
->x
, pimldp
->y
, cx
, cy
, hMaskListDC
, pt
.x
, pt
.y
, SRCAND
);
1670 SetBkColor(pimldp
->hdcDst
, oldDstBk
);
1671 SetTextColor(pimldp
->hdcDst
, oldDstFg
);
1674 if (fStyle
& ILD_ROP
) dwRop
= pimldp
->dwRop
;
1675 BitBlt (pimldp
->hdcDst
, pimldp
->x
, pimldp
->y
, cx
, cy
, hImageDC
, 0, 0, dwRop
);
1679 /* cleanup the mess */
1680 SetBkColor(hImageDC
, oldImageBk
);
1681 SetTextColor(hImageDC
, oldImageFg
);
1682 SelectObject(hImageDC
, hOldImageBmp
);
1686 DeleteDC(hdcSaturated
);
1688 DeleteObject(hBlendMaskBmp
);
1689 DeleteObject(hImageBmp
);
1696 /*************************************************************************
1697 * ImageList_Duplicate [COMCTL32.@]
1699 * Duplicates an image list.
1702 * himlSrc [I] source image list handle
1705 * Success: Handle of duplicated image list.
1710 ImageList_Duplicate (HIMAGELIST himlSrc
)
1714 if (!is_valid(himlSrc
)) {
1715 ERR("Invalid image list handle!\n");
1719 himlDst
= ImageList_Create (himlSrc
->cx
, himlSrc
->cy
, himlSrc
->flags
,
1720 himlSrc
->cCurImage
, himlSrc
->cGrow
);
1726 imagelist_get_bitmap_size(himlSrc
, himlSrc
->cCurImage
, &sz
);
1727 BitBlt (himlDst
->hdcImage
, 0, 0, sz
.cx
, sz
.cy
,
1728 himlSrc
->hdcImage
, 0, 0, SRCCOPY
);
1730 if (himlDst
->hbmMask
)
1731 BitBlt (himlDst
->hdcMask
, 0, 0, sz
.cx
, sz
.cy
,
1732 himlSrc
->hdcMask
, 0, 0, SRCCOPY
);
1734 himlDst
->cCurImage
= himlSrc
->cCurImage
;
1735 if (himlSrc
->has_alpha
&& himlDst
->has_alpha
)
1736 memcpy( himlDst
->has_alpha
, himlSrc
->has_alpha
, himlDst
->cCurImage
);
1742 /*************************************************************************
1743 * ImageList_EndDrag [COMCTL32.@]
1745 * Finishes a drag operation.
1756 ImageList_EndDrag (void)
1758 /* cleanup the InternalDrag struct */
1759 InternalDrag
.hwnd
= 0;
1760 if (InternalDrag
.himl
!= InternalDrag
.himlNoCursor
)
1761 ImageList_Destroy (InternalDrag
.himlNoCursor
);
1762 ImageList_Destroy (InternalDrag
.himl
);
1763 InternalDrag
.himlNoCursor
= InternalDrag
.himl
= 0;
1766 InternalDrag
.dxHotspot
= 0;
1767 InternalDrag
.dyHotspot
= 0;
1768 InternalDrag
.bShow
= FALSE
;
1769 DeleteObject(InternalDrag
.hbmBg
);
1770 InternalDrag
.hbmBg
= 0;
1774 /*************************************************************************
1775 * ImageList_GetBkColor [COMCTL32.@]
1777 * Returns the background color of an image list.
1780 * himl [I] Image list handle.
1783 * Success: background color
1788 ImageList_GetBkColor (HIMAGELIST himl
)
1790 return himl
? himl
->clrBk
: CLR_NONE
;
1794 /*************************************************************************
1795 * ImageList_GetDragImage [COMCTL32.@]
1797 * Returns the handle to the internal drag image list.
1800 * ppt [O] Pointer to the drag position. Can be NULL.
1801 * pptHotspot [O] Pointer to the position of the hot spot. Can be NULL.
1804 * Success: Handle of the drag image list.
1809 ImageList_GetDragImage (POINT
*ppt
, POINT
*pptHotspot
)
1811 if (is_valid(InternalDrag
.himl
)) {
1813 ppt
->x
= InternalDrag
.x
;
1814 ppt
->y
= InternalDrag
.y
;
1817 pptHotspot
->x
= InternalDrag
.dxHotspot
;
1818 pptHotspot
->y
= InternalDrag
.dyHotspot
;
1820 return (InternalDrag
.himl
);
1827 /*************************************************************************
1828 * ImageList_GetFlags [COMCTL32.@]
1830 * Gets the flags of the specified image list.
1833 * himl [I] Handle to image list
1843 ImageList_GetFlags(HIMAGELIST himl
)
1845 TRACE("%p\n", himl
);
1847 return is_valid(himl
) ? himl
->flags
: 0;
1851 /*************************************************************************
1852 * ImageList_GetIcon [COMCTL32.@]
1854 * Creates an icon from a masked image of an image list.
1857 * himl [I] handle to image list
1859 * flags [I] drawing style flags
1862 * Success: icon handle
1867 ImageList_GetIcon (HIMAGELIST himl
, INT i
, UINT fStyle
)
1871 HBITMAP hOldDstBitmap
;
1875 TRACE("%p %d %d\n", himl
, i
, fStyle
);
1876 if (!is_valid(himl
) || (i
< 0) || (i
>= himl
->cCurImage
)) return NULL
;
1882 /* create colour bitmap */
1884 ii
.hbmColor
= CreateCompatibleBitmap(hdcDst
, himl
->cx
, himl
->cy
);
1885 ReleaseDC(0, hdcDst
);
1887 hdcDst
= CreateCompatibleDC(0);
1889 imagelist_point_from_index( himl
, i
, &pt
);
1892 ii
.hbmMask
= CreateBitmap (himl
->cx
, himl
->cy
, 1, 1, NULL
);
1893 hOldDstBitmap
= SelectObject (hdcDst
, ii
.hbmMask
);
1894 if (himl
->hbmMask
) {
1895 BitBlt (hdcDst
, 0, 0, himl
->cx
, himl
->cy
,
1896 himl
->hdcMask
, pt
.x
, pt
.y
, SRCCOPY
);
1899 PatBlt (hdcDst
, 0, 0, himl
->cx
, himl
->cy
, BLACKNESS
);
1902 SelectObject (hdcDst
, ii
.hbmColor
);
1903 BitBlt (hdcDst
, 0, 0, himl
->cx
, himl
->cy
,
1904 himl
->hdcImage
, pt
.x
, pt
.y
, SRCCOPY
);
1907 * CreateIconIndirect requires us to deselect the bitmaps from
1908 * the DCs before calling
1910 SelectObject(hdcDst
, hOldDstBitmap
);
1912 hIcon
= CreateIconIndirect (&ii
);
1914 DeleteObject (ii
.hbmMask
);
1915 DeleteObject (ii
.hbmColor
);
1922 /*************************************************************************
1923 * ImageList_GetIconSize [COMCTL32.@]
1925 * Retrieves the size of an image in an image list.
1928 * himl [I] handle to image list
1929 * cx [O] pointer to the image width.
1930 * cy [O] pointer to the image height.
1937 * All images in an image list have the same size.
1941 ImageList_GetIconSize (HIMAGELIST himl
, INT
*cx
, INT
*cy
)
1943 if (!is_valid(himl
) || !cx
|| !cy
)
1953 /*************************************************************************
1954 * ImageList_GetImageCount [COMCTL32.@]
1956 * Returns the number of images in an image list.
1959 * himl [I] handle to image list
1962 * Success: Number of images.
1967 ImageList_GetImageCount (HIMAGELIST himl
)
1969 if (!is_valid(himl
))
1972 return himl
->cCurImage
;
1976 /*************************************************************************
1977 * ImageList_GetImageInfo [COMCTL32.@]
1979 * Returns information about an image in an image list.
1982 * himl [I] handle to image list
1984 * pImageInfo [O] pointer to the image information
1992 ImageList_GetImageInfo (HIMAGELIST himl
, INT i
, IMAGEINFO
*pImageInfo
)
1996 if (!is_valid(himl
) || (pImageInfo
== NULL
))
1998 if ((i
< 0) || (i
>= himl
->cCurImage
))
2001 pImageInfo
->hbmImage
= himl
->hbmImage
;
2002 pImageInfo
->hbmMask
= himl
->hbmMask
;
2004 imagelist_point_from_index( himl
, i
, &pt
);
2005 pImageInfo
->rcImage
.top
= pt
.y
;
2006 pImageInfo
->rcImage
.bottom
= pt
.y
+ himl
->cy
;
2007 pImageInfo
->rcImage
.left
= pt
.x
;
2008 pImageInfo
->rcImage
.right
= pt
.x
+ himl
->cx
;
2014 /*************************************************************************
2015 * ImageList_GetImageRect [COMCTL32.@]
2017 * Retrieves the rectangle of the specified image in an image list.
2020 * himl [I] handle to image list
2022 * lpRect [O] pointer to the image rectangle
2029 * This is an UNDOCUMENTED function!!!
2033 ImageList_GetImageRect (HIMAGELIST himl
, INT i
, LPRECT lpRect
)
2037 if (!is_valid(himl
) || (lpRect
== NULL
))
2039 if ((i
< 0) || (i
>= himl
->cCurImage
))
2042 imagelist_point_from_index( himl
, i
, &pt
);
2043 lpRect
->left
= pt
.x
;
2045 lpRect
->right
= pt
.x
+ himl
->cx
;
2046 lpRect
->bottom
= pt
.y
+ himl
->cy
;
2052 /*************************************************************************
2053 * ImageList_LoadImage [COMCTL32.@]
2054 * ImageList_LoadImageA [COMCTL32.@]
2056 * Creates an image list from a bitmap, icon or cursor.
2058 * See ImageList_LoadImageW.
2062 ImageList_LoadImageA (HINSTANCE hi
, LPCSTR lpbmp
, INT cx
, INT cGrow
,
2063 COLORREF clrMask
, UINT uType
, UINT uFlags
)
2069 if (IS_INTRESOURCE(lpbmp
))
2070 return ImageList_LoadImageW(hi
, (LPCWSTR
)lpbmp
, cx
, cGrow
, clrMask
,
2073 len
= MultiByteToWideChar(CP_ACP
, 0, lpbmp
, -1, NULL
, 0);
2074 lpbmpW
= heap_alloc(len
* sizeof(WCHAR
));
2075 MultiByteToWideChar(CP_ACP
, 0, lpbmp
, -1, lpbmpW
, len
);
2077 himl
= ImageList_LoadImageW(hi
, lpbmpW
, cx
, cGrow
, clrMask
, uType
, uFlags
);
2083 /*************************************************************************
2084 * ImageList_LoadImageW [COMCTL32.@]
2086 * Creates an image list from a bitmap, icon or cursor.
2089 * hi [I] instance handle
2090 * lpbmp [I] name or id of the image
2091 * cx [I] width of each image
2092 * cGrow [I] number of images to expand
2093 * clrMask [I] mask color
2094 * uType [I] type of image to load
2095 * uFlags [I] loading flags
2098 * Success: handle to the loaded image list
2106 ImageList_LoadImageW (HINSTANCE hi
, LPCWSTR lpbmp
, INT cx
, INT cGrow
,
2107 COLORREF clrMask
, UINT uType
, UINT uFlags
)
2109 HIMAGELIST himl
= NULL
;
2113 handle
= LoadImageW (hi
, lpbmp
, uType
, 0, 0, uFlags
);
2115 WARN("Couldn't load image\n");
2119 if (uType
== IMAGE_BITMAP
) {
2123 if (GetObjectW (handle
, sizeof(dib
), &dib
) == sizeof(BITMAP
)) color
= ILC_COLOR
;
2124 else color
= dib
.dsBm
.bmBitsPixel
;
2126 /* To match windows behavior, if cx is set to zero and
2127 the flag DI_DEFAULTSIZE is specified, cx becomes the
2128 system metric value for icons. If the flag is not specified
2129 the function sets the size to the height of the bitmap */
2132 if (uFlags
& DI_DEFAULTSIZE
)
2133 cx
= GetSystemMetrics (SM_CXICON
);
2135 cx
= dib
.dsBm
.bmHeight
;
2138 nImageCount
= dib
.dsBm
.bmWidth
/ cx
;
2140 if (clrMask
!= CLR_NONE
) color
|= ILC_MASK
;
2141 himl
= ImageList_Create (cx
, dib
.dsBm
.bmHeight
, color
, nImageCount
, cGrow
);
2143 DeleteObject (handle
);
2146 ImageList_AddMasked (himl
, handle
, clrMask
);
2148 else if ((uType
== IMAGE_ICON
) || (uType
== IMAGE_CURSOR
)) {
2152 GetIconInfo (handle
, &ii
);
2153 GetObjectW (ii
.hbmColor
, sizeof(BITMAP
), &bmp
);
2154 himl
= ImageList_Create (bmp
.bmWidth
, bmp
.bmHeight
,
2155 ILC_MASK
| ILC_COLOR
, 1, cGrow
);
2157 DeleteObject (ii
.hbmColor
);
2158 DeleteObject (ii
.hbmMask
);
2159 DeleteObject (handle
);
2162 ImageList_Add (himl
, ii
.hbmColor
, ii
.hbmMask
);
2163 DeleteObject (ii
.hbmColor
);
2164 DeleteObject (ii
.hbmMask
);
2167 DeleteObject (handle
);
2173 /*************************************************************************
2174 * ImageList_Merge [COMCTL32.@]
2176 * Create an image list containing a merged image from two image lists.
2179 * himl1 [I] handle to first image list
2180 * i1 [I] first image index
2181 * himl2 [I] handle to second image list
2182 * i2 [I] second image index
2183 * dx [I] X offset of the second image relative to the first.
2184 * dy [I] Y offset of the second image relative to the first.
2187 * Success: The newly created image list. It contains a single image
2188 * consisting of the second image merged with the first.
2189 * Failure: NULL, if either himl1 or himl2 is invalid.
2192 * - The returned image list should be deleted by the caller using
2193 * ImageList_Destroy() when it is no longer required.
2194 * - If either i1 or i2 is not a valid image index, they will be treated
2198 ImageList_Merge (HIMAGELIST himl1
, INT i1
, HIMAGELIST himl2
, INT i2
,
2201 HIMAGELIST himlDst
= NULL
;
2203 INT xOff1
, yOff1
, xOff2
, yOff2
;
2207 TRACE("(himl1=%p i1=%d himl2=%p i2=%d dx=%d dy=%d)\n", himl1
, i1
, himl2
,
2210 if (!is_valid(himl1
) || !is_valid(himl2
))
2214 cxDst
= max (himl1
->cx
, dx
+ himl2
->cx
);
2219 cxDst
= max (himl2
->cx
, himl1
->cx
- dx
);
2224 cxDst
= max (himl1
->cx
, himl2
->cx
);
2230 cyDst
= max (himl1
->cy
, dy
+ himl2
->cy
);
2235 cyDst
= max (himl2
->cy
, himl1
->cy
- dy
);
2240 cyDst
= max (himl1
->cy
, himl2
->cy
);
2245 newFlags
= (himl1
->flags
> himl2
->flags
? himl1
->flags
: himl2
->flags
) & ILC_COLORDDB
;
2246 if (newFlags
== ILC_COLORDDB
&& (himl1
->flags
& ILC_COLORDDB
) == ILC_COLOR16
)
2247 newFlags
= ILC_COLOR16
; /* this is what native (at least v5) does, don't know why */
2248 himlDst
= ImageList_Create (cxDst
, cyDst
, ILC_MASK
| newFlags
, 1, 1);
2252 imagelist_point_from_index( himl1
, i1
, &pt1
);
2253 imagelist_point_from_index( himl2
, i2
, &pt2
);
2256 BitBlt (himlDst
->hdcImage
, 0, 0, cxDst
, cyDst
, himl1
->hdcImage
, 0, 0, BLACKNESS
);
2257 if (i1
>= 0 && i1
< himl1
->cCurImage
)
2258 BitBlt (himlDst
->hdcImage
, xOff1
, yOff1
, himl1
->cx
, himl1
->cy
, himl1
->hdcImage
, pt1
.x
, pt1
.y
, SRCCOPY
);
2259 if (i2
>= 0 && i2
< himl2
->cCurImage
)
2261 if (himl2
->flags
& ILC_MASK
)
2263 BitBlt (himlDst
->hdcImage
, xOff2
, yOff2
, himl2
->cx
, himl2
->cy
, himl2
->hdcMask
, pt2
.x
, pt2
.y
, SRCAND
);
2264 BitBlt (himlDst
->hdcImage
, xOff2
, yOff2
, himl2
->cx
, himl2
->cy
, himl2
->hdcImage
, pt2
.x
, pt2
.y
, SRCPAINT
);
2267 BitBlt (himlDst
->hdcImage
, xOff2
, yOff2
, himl2
->cx
, himl2
->cy
, himl2
->hdcImage
, pt2
.x
, pt2
.y
, SRCCOPY
);
2271 BitBlt (himlDst
->hdcMask
, 0, 0, cxDst
, cyDst
, himl1
->hdcMask
, 0, 0, WHITENESS
);
2272 if (i1
>= 0 && i1
< himl1
->cCurImage
)
2273 BitBlt (himlDst
->hdcMask
, xOff1
, yOff1
, himl1
->cx
, himl1
->cy
, himl1
->hdcMask
, pt1
.x
, pt1
.y
, SRCCOPY
);
2274 if (i2
>= 0 && i2
< himl2
->cCurImage
)
2275 BitBlt (himlDst
->hdcMask
, xOff2
, yOff2
, himl2
->cx
, himl2
->cy
, himl2
->hdcMask
, pt2
.x
, pt2
.y
, SRCAND
);
2277 himlDst
->cCurImage
= 1;
2284 /* helper for ImageList_Read, see comments below */
2285 static void *read_bitmap(IStream
*pstm
, BITMAPINFO
*bmi
)
2287 BITMAPFILEHEADER bmfh
;
2288 int bitsperpixel
, palspace
;
2291 if (FAILED(IStream_Read ( pstm
, &bmfh
, sizeof(bmfh
), NULL
)))
2294 if (bmfh
.bfType
!= (('M'<<8)|'B'))
2297 if (FAILED(IStream_Read ( pstm
, &bmi
->bmiHeader
, sizeof(bmi
->bmiHeader
), NULL
)))
2300 if ((bmi
->bmiHeader
.biSize
!= sizeof(bmi
->bmiHeader
)))
2303 TRACE("width %u, height %u, planes %u, bpp %u\n",
2304 bmi
->bmiHeader
.biWidth
, bmi
->bmiHeader
.biHeight
,
2305 bmi
->bmiHeader
.biPlanes
, bmi
->bmiHeader
.biBitCount
);
2307 bitsperpixel
= bmi
->bmiHeader
.biPlanes
* bmi
->bmiHeader
.biBitCount
;
2308 if (bitsperpixel
<=8)
2309 palspace
= (1<<bitsperpixel
)*sizeof(RGBQUAD
);
2313 bmi
->bmiHeader
.biSizeImage
= get_dib_image_size( bmi
);
2315 /* read the palette right after the end of the bitmapinfoheader */
2316 if (palspace
&& FAILED(IStream_Read(pstm
, bmi
->bmiColors
, palspace
, NULL
)))
2319 bits
= heap_alloc_zero(bmi
->bmiHeader
.biSizeImage
);
2320 if (!bits
) return NULL
;
2322 if (FAILED(IStream_Read(pstm
, bits
, bmi
->bmiHeader
.biSizeImage
, NULL
)))
2330 /*************************************************************************
2331 * ImageList_Read [COMCTL32.@]
2333 * Reads an image list from a stream.
2336 * pstm [I] pointer to a stream
2339 * Success: handle to image list
2342 * The format is like this:
2343 * ILHEAD ilheadstruct;
2345 * for the color image part:
2346 * BITMAPFILEHEADER bmfh;
2347 * BITMAPINFOHEADER bmih;
2348 * only if it has a palette:
2349 * RGBQUAD rgbs[nr_of_paletted_colors];
2351 * BYTE colorbits[imagesize];
2353 * the following only if the ILC_MASK bit is set in ILHEAD.ilFlags:
2354 * BITMAPFILEHEADER bmfh_mask;
2355 * BITMAPINFOHEADER bmih_mask;
2356 * only if it has a palette (it usually does not):
2357 * RGBQUAD rgbs[nr_of_paletted_colors];
2359 * BYTE maskbits[imagesize];
2361 HIMAGELIST WINAPI
ImageList_Read(IStream
*pstm
)
2363 char image_buf
[sizeof(BITMAPINFOHEADER
) + sizeof(RGBQUAD
) * 256];
2364 char mask_buf
[sizeof(BITMAPINFOHEADER
) + sizeof(RGBQUAD
) * 256];
2365 BITMAPINFO
*image_info
= (BITMAPINFO
*)image_buf
;
2366 BITMAPINFO
*mask_info
= (BITMAPINFO
*)mask_buf
;
2367 void *image_bits
, *mask_bits
= NULL
;
2372 TRACE("%p\n", pstm
);
2374 if (FAILED(IStream_Read (pstm
, &ilHead
, sizeof(ILHEAD
), NULL
)))
2376 if (ilHead
.usMagic
!= (('L' << 8) | 'I'))
2378 if (ilHead
.usVersion
!= 0x101) /* probably version? */
2381 TRACE("cx %u, cy %u, flags 0x%04x, cCurImage %u, cMaxImage %u\n",
2382 ilHead
.cx
, ilHead
.cy
, ilHead
.flags
, ilHead
.cCurImage
, ilHead
.cMaxImage
);
2384 himl
= ImageList_Create(ilHead
.cx
, ilHead
.cy
, ilHead
.flags
, ilHead
.cCurImage
, ilHead
.cMaxImage
);
2388 if (!(image_bits
= read_bitmap(pstm
, image_info
)))
2390 WARN("failed to read bitmap from stream\n");
2393 if (ilHead
.flags
& ILC_MASK
)
2395 if (!(mask_bits
= read_bitmap(pstm
, mask_info
)))
2397 WARN("failed to read mask bitmap from stream\n");
2401 else mask_info
= NULL
;
2403 if (himl
->has_alpha
&& image_info
->bmiHeader
.biBitCount
== 32)
2405 DWORD
*ptr
= image_bits
;
2406 BYTE
*mask_ptr
= mask_bits
;
2407 int stride
= himl
->cy
* image_info
->bmiHeader
.biWidth
;
2409 if (image_info
->bmiHeader
.biHeight
> 0) /* bottom-up */
2411 ptr
+= image_info
->bmiHeader
.biHeight
* image_info
->bmiHeader
.biWidth
- stride
;
2412 mask_ptr
+= (image_info
->bmiHeader
.biHeight
* image_info
->bmiHeader
.biWidth
- stride
) / 8;
2414 image_info
->bmiHeader
.biHeight
= himl
->cy
;
2416 else image_info
->bmiHeader
.biHeight
= -himl
->cy
;
2418 for (i
= 0; i
< ilHead
.cCurImage
; i
+= TILE_COUNT
)
2420 add_dib_bits( himl
, i
, min( ilHead
.cCurImage
- i
, TILE_COUNT
),
2421 himl
->cx
, himl
->cy
, image_info
, mask_info
, ptr
, mask_ptr
);
2423 mask_ptr
+= stride
/ 8;
2428 StretchDIBits( himl
->hdcImage
, 0, 0, image_info
->bmiHeader
.biWidth
, image_info
->bmiHeader
.biHeight
,
2429 0, 0, image_info
->bmiHeader
.biWidth
, image_info
->bmiHeader
.biHeight
,
2430 image_bits
, image_info
, DIB_RGB_COLORS
, SRCCOPY
);
2432 StretchDIBits( himl
->hdcMask
, 0, 0, mask_info
->bmiHeader
.biWidth
, mask_info
->bmiHeader
.biHeight
,
2433 0, 0, mask_info
->bmiHeader
.biWidth
, mask_info
->bmiHeader
.biHeight
,
2434 mask_bits
, mask_info
, DIB_RGB_COLORS
, SRCCOPY
);
2436 heap_free( image_bits
);
2437 heap_free( mask_bits
);
2439 himl
->cCurImage
= ilHead
.cCurImage
;
2440 himl
->cMaxImage
= ilHead
.cMaxImage
;
2442 ImageList_SetBkColor(himl
,ilHead
.bkcolor
);
2444 ImageList_SetOverlayImage(himl
,ilHead
.ovls
[i
],i
+1);
2449 /*************************************************************************
2450 * ImageList_Remove [COMCTL32.@]
2452 * Removes an image from an image list
2455 * himl [I] image list handle
2462 * FIXME: as the image list storage test shows, native comctl32 simply shifts
2463 * images without creating a new bitmap.
2466 ImageList_Remove (HIMAGELIST himl
, INT i
)
2468 HBITMAP hbmNewImage
, hbmNewMask
;
2472 TRACE("(himl=%p i=%d)\n", himl
, i
);
2474 if (!is_valid(himl
)) {
2475 ERR("Invalid image list handle!\n");
2479 if ((i
< -1) || (i
>= himl
->cCurImage
)) {
2480 TRACE("index out of range! %d\n", i
);
2488 if (himl
->cCurImage
== 0) {
2489 /* remove all on empty ImageList is allowed */
2490 TRACE("remove all on empty ImageList!\n");
2494 himl
->cMaxImage
= himl
->cGrow
;
2495 himl
->cCurImage
= 0;
2496 for (nCount
= 0; nCount
< MAX_OVERLAYIMAGE
; nCount
++)
2497 himl
->nOvlIdx
[nCount
] = -1;
2499 if (himl
->has_alpha
)
2501 heap_free( himl
->has_alpha
);
2502 himl
->has_alpha
= heap_alloc_zero( himl
->cMaxImage
);
2505 hbmNewImage
= ImageList_CreateImage(himl
->hdcImage
, himl
, himl
->cMaxImage
);
2506 SelectObject (himl
->hdcImage
, hbmNewImage
);
2507 DeleteObject (himl
->hbmImage
);
2508 himl
->hbmImage
= hbmNewImage
;
2510 if (himl
->hbmMask
) {
2512 imagelist_get_bitmap_size(himl
, himl
->cMaxImage
, &sz
);
2513 hbmNewMask
= CreateBitmap (sz
.cx
, sz
.cy
, 1, 1, NULL
);
2514 SelectObject (himl
->hdcMask
, hbmNewMask
);
2515 DeleteObject (himl
->hbmMask
);
2516 himl
->hbmMask
= hbmNewMask
;
2520 /* delete one image */
2521 TRACE("Remove single image! %d\n", i
);
2523 /* create new bitmap(s) */
2524 TRACE(" - Number of images: %d / %d (Old/New)\n",
2525 himl
->cCurImage
, himl
->cCurImage
- 1);
2527 hbmNewImage
= ImageList_CreateImage(himl
->hdcImage
, himl
, himl
->cMaxImage
);
2529 imagelist_get_bitmap_size(himl
, himl
->cMaxImage
, &sz
);
2531 hbmNewMask
= CreateBitmap (sz
.cx
, sz
.cy
, 1, 1, NULL
);
2533 hbmNewMask
= 0; /* Just to keep compiler happy! */
2535 hdcBmp
= CreateCompatibleDC (0);
2537 /* copy all images and masks prior to the "removed" image */
2539 TRACE("Pre image copy: Copy %d images\n", i
);
2541 SelectObject (hdcBmp
, hbmNewImage
);
2542 imagelist_copy_images( himl
, himl
->hdcImage
, hdcBmp
, 0, i
, 0 );
2544 if (himl
->hbmMask
) {
2545 SelectObject (hdcBmp
, hbmNewMask
);
2546 imagelist_copy_images( himl
, himl
->hdcMask
, hdcBmp
, 0, i
, 0 );
2550 /* copy all images and masks behind the removed image */
2551 if (i
< himl
->cCurImage
- 1) {
2552 TRACE("Post image copy!\n");
2554 SelectObject (hdcBmp
, hbmNewImage
);
2555 imagelist_copy_images( himl
, himl
->hdcImage
, hdcBmp
, i
+ 1,
2556 (himl
->cCurImage
- i
), i
);
2558 if (himl
->hbmMask
) {
2559 SelectObject (hdcBmp
, hbmNewMask
);
2560 imagelist_copy_images( himl
, himl
->hdcMask
, hdcBmp
, i
+ 1,
2561 (himl
->cCurImage
- i
), i
);
2567 /* delete old images and insert new ones */
2568 SelectObject (himl
->hdcImage
, hbmNewImage
);
2569 DeleteObject (himl
->hbmImage
);
2570 himl
->hbmImage
= hbmNewImage
;
2571 if (himl
->hbmMask
) {
2572 SelectObject (himl
->hdcMask
, hbmNewMask
);
2573 DeleteObject (himl
->hbmMask
);
2574 himl
->hbmMask
= hbmNewMask
;
2584 /*************************************************************************
2585 * ImageList_Replace [COMCTL32.@]
2587 * Replaces an image in an image list with a new image.
2590 * himl [I] handle to image list
2592 * hbmImage [I] handle to image bitmap
2593 * hbmMask [I] handle to mask bitmap. Can be NULL.
2601 ImageList_Replace (HIMAGELIST himl
, INT i
, HBITMAP hbmImage
,
2608 TRACE("%p %d %p %p\n", himl
, i
, hbmImage
, hbmMask
);
2610 if (!is_valid(himl
)) {
2611 ERR("Invalid image list handle!\n");
2615 if ((i
>= himl
->cMaxImage
) || (i
< 0)) {
2616 ERR("Invalid image index!\n");
2620 if (!GetObjectW(hbmImage
, sizeof(BITMAP
), &bmp
))
2623 hdcImage
= CreateCompatibleDC (0);
2626 SelectObject (hdcImage
, hbmImage
);
2628 if (add_with_alpha( himl
, hdcImage
, i
, 1, bmp
.bmWidth
, bmp
.bmHeight
, hbmImage
, hbmMask
))
2631 imagelist_point_from_index(himl
, i
, &pt
);
2632 StretchBlt (himl
->hdcImage
, pt
.x
, pt
.y
, himl
->cx
, himl
->cy
,
2633 hdcImage
, 0, 0, bmp
.bmWidth
, bmp
.bmHeight
, SRCCOPY
);
2638 HBITMAP hOldBitmapTemp
;
2640 hdcTemp
= CreateCompatibleDC(0);
2641 hOldBitmapTemp
= SelectObject(hdcTemp
, hbmMask
);
2643 StretchBlt (himl
->hdcMask
, pt
.x
, pt
.y
, himl
->cx
, himl
->cy
,
2644 hdcTemp
, 0, 0, bmp
.bmWidth
, bmp
.bmHeight
, SRCCOPY
);
2645 SelectObject(hdcTemp
, hOldBitmapTemp
);
2648 /* Remove the background from the image
2650 BitBlt (himl
->hdcImage
, pt
.x
, pt
.y
, bmp
.bmWidth
, bmp
.bmHeight
,
2651 himl
->hdcMask
, pt
.x
, pt
.y
, 0x220326); /* NOTSRCAND */
2655 DeleteDC (hdcImage
);
2661 /*************************************************************************
2662 * ImageList_ReplaceIcon [COMCTL32.@]
2664 * Replaces an image in an image list using an icon.
2667 * himl [I] handle to image list
2669 * hIcon [I] handle to icon
2672 * Success: index of the replaced image
2677 ImageList_ReplaceIcon (HIMAGELIST himl
, INT nIndex
, HICON hIcon
)
2685 TRACE("(%p %d %p)\n", himl
, nIndex
, hIcon
);
2687 if (!is_valid(himl
)) {
2688 ERR("invalid image list\n");
2691 if ((nIndex
>= himl
->cMaxImage
) || (nIndex
< -1)) {
2692 ERR("invalid image index %d / %d\n", nIndex
, himl
->cMaxImage
);
2696 hBestFitIcon
= CopyImage(
2699 LR_COPYFROMRESOURCE
);
2700 /* the above will fail if the icon wasn't loaded from a resource, so try
2701 * again without LR_COPYFROMRESOURCE flag */
2703 hBestFitIcon
= CopyImage(
2711 if (himl
->cCurImage
+ 1 >= himl
->cMaxImage
)
2712 IMAGELIST_InternalExpandBitmaps(himl
, 1);
2714 nIndex
= himl
->cCurImage
;
2718 if (himl
->has_alpha
&& GetIconInfo (hBestFitIcon
, &ii
))
2720 HDC hdcImage
= CreateCompatibleDC( 0 );
2721 GetObjectW (ii
.hbmMask
, sizeof(BITMAP
), &bmp
);
2725 UINT height
= bmp
.bmHeight
/ 2;
2726 HDC hdcMask
= CreateCompatibleDC( 0 );
2727 HBITMAP color
= CreateBitmap( bmp
.bmWidth
, height
, 1, 1, NULL
);
2728 SelectObject( hdcImage
, color
);
2729 SelectObject( hdcMask
, ii
.hbmMask
);
2730 BitBlt( hdcImage
, 0, 0, bmp
.bmWidth
, height
, hdcMask
, 0, height
, SRCCOPY
);
2731 ret
= add_with_alpha( himl
, hdcImage
, nIndex
, 1, bmp
.bmWidth
, height
, color
, ii
.hbmMask
);
2732 DeleteDC( hdcMask
);
2733 DeleteObject( color
);
2735 else ret
= add_with_alpha( himl
, hdcImage
, nIndex
, 1, bmp
.bmWidth
, bmp
.bmHeight
,
2736 ii
.hbmColor
, ii
.hbmMask
);
2738 DeleteDC( hdcImage
);
2739 DeleteObject (ii
.hbmMask
);
2740 if (ii
.hbmColor
) DeleteObject (ii
.hbmColor
);
2744 imagelist_point_from_index(himl
, nIndex
, &pt
);
2748 DrawIconEx( himl
->hdcImage
, pt
.x
, pt
.y
, hBestFitIcon
, himl
->cx
, himl
->cy
, 0, 0, DI_IMAGE
);
2749 PatBlt( himl
->hdcMask
, pt
.x
, pt
.y
, himl
->cx
, himl
->cy
, WHITENESS
);
2750 DrawIconEx( himl
->hdcMask
, pt
.x
, pt
.y
, hBestFitIcon
, himl
->cx
, himl
->cy
, 0, 0, DI_MASK
);
2754 COLORREF color
= himl
->clrBk
!= CLR_NONE
? himl
->clrBk
: comctl32_color
.clrWindow
;
2755 HBRUSH brush
= CreateSolidBrush( GetNearestColor( himl
->hdcImage
, color
));
2757 SelectObject( himl
->hdcImage
, brush
);
2758 PatBlt( himl
->hdcImage
, pt
.x
, pt
.y
, himl
->cx
, himl
->cy
, PATCOPY
);
2759 SelectObject( himl
->hdcImage
, GetStockObject(BLACK_BRUSH
) );
2760 DeleteObject( brush
);
2761 DrawIconEx( himl
->hdcImage
, pt
.x
, pt
.y
, hBestFitIcon
, himl
->cx
, himl
->cy
, 0, 0, DI_NORMAL
);
2765 DestroyIcon(hBestFitIcon
);
2767 TRACE("Insert index = %d, himl->cCurImage = %d\n", nIndex
, himl
->cCurImage
);
2772 /*************************************************************************
2773 * ImageList_SetBkColor [COMCTL32.@]
2775 * Sets the background color of an image list.
2778 * himl [I] handle to image list
2779 * clrBk [I] background color
2782 * Success: previous background color
2787 ImageList_SetBkColor (HIMAGELIST himl
, COLORREF clrBk
)
2791 if (!is_valid(himl
))
2794 clrOldBk
= himl
->clrBk
;
2795 himl
->clrBk
= clrBk
;
2800 /*************************************************************************
2801 * ImageList_SetDragCursorImage [COMCTL32.@]
2803 * Combines the specified image with the current drag image
2806 * himlDrag [I] handle to drag image list
2807 * iDrag [I] drag image index
2808 * dxHotspot [I] X position of the hot spot
2809 * dyHotspot [I] Y position of the hot spot
2816 * - The names dxHotspot, dyHotspot are misleading because they have nothing
2817 * to do with a hotspot but are only the offset of the origin of the new
2818 * image relative to the origin of the old image.
2820 * - When this function is called and the drag image is visible, a
2821 * short flickering occurs but this matches the Win9x behavior. It is
2822 * possible to fix the flickering using code like in ImageList_DragMove.
2826 ImageList_SetDragCursorImage (HIMAGELIST himlDrag
, INT iDrag
,
2827 INT dxHotspot
, INT dyHotspot
)
2829 HIMAGELIST himlTemp
;
2832 if (!is_valid(InternalDrag
.himl
) || !is_valid(himlDrag
))
2835 TRACE(" dxH=%d dyH=%d nX=%d nY=%d\n",
2836 dxHotspot
, dyHotspot
, InternalDrag
.dxHotspot
, InternalDrag
.dyHotspot
);
2838 visible
= InternalDrag
.bShow
;
2840 himlTemp
= ImageList_Merge (InternalDrag
.himlNoCursor
, 0, himlDrag
, iDrag
,
2841 dxHotspot
, dyHotspot
);
2844 /* hide the drag image */
2845 ImageList_DragShowNolock(FALSE
);
2847 if ((InternalDrag
.himl
->cx
!= himlTemp
->cx
) ||
2848 (InternalDrag
.himl
->cy
!= himlTemp
->cy
)) {
2849 /* the size of the drag image changed, invalidate the buffer */
2850 DeleteObject(InternalDrag
.hbmBg
);
2851 InternalDrag
.hbmBg
= 0;
2854 if (InternalDrag
.himl
!= InternalDrag
.himlNoCursor
)
2855 ImageList_Destroy (InternalDrag
.himl
);
2856 InternalDrag
.himl
= himlTemp
;
2859 /* show the drag image */
2860 ImageList_DragShowNolock(TRUE
);
2867 /*************************************************************************
2868 * ImageList_SetFilter [COMCTL32.@]
2870 * Sets a filter (or does something completely different)!!???
2871 * It removes 12 Bytes from the stack (3 Parameters).
2874 * himl [I] SHOULD be a handle to image list
2875 * i [I] COULD be an index?
2880 * Failure: FALSE ???
2883 * This is an UNDOCUMENTED function!!!!
2888 ImageList_SetFilter (HIMAGELIST himl
, INT i
, DWORD dwFilter
)
2890 FIXME("(%p 0x%x 0x%x):empty stub!\n", himl
, i
, dwFilter
);
2896 /*************************************************************************
2897 * ImageList_SetFlags [COMCTL32.@]
2899 * Sets the image list flags.
2902 * himl [I] Handle to image list
2903 * flags [I] Flags to set
2913 ImageList_SetFlags(HIMAGELIST himl
, DWORD flags
)
2915 FIXME("(%p %08x):empty stub\n", himl
, flags
);
2920 /*************************************************************************
2921 * ImageList_SetIconSize [COMCTL32.@]
2923 * Sets the image size of the bitmap and deletes all images.
2926 * himl [I] handle to image list
2927 * cx [I] image width
2928 * cy [I] image height
2936 ImageList_SetIconSize (HIMAGELIST himl
, INT cx
, INT cy
)
2941 if (!is_valid(himl
))
2944 /* remove all images */
2945 himl
->cMaxImage
= himl
->cInitial
+ 1;
2946 himl
->cCurImage
= 0;
2950 /* initialize overlay mask indices */
2951 for (nCount
= 0; nCount
< MAX_OVERLAYIMAGE
; nCount
++)
2952 himl
->nOvlIdx
[nCount
] = -1;
2954 hbmNew
= ImageList_CreateImage(himl
->hdcImage
, himl
, himl
->cMaxImage
);
2955 SelectObject (himl
->hdcImage
, hbmNew
);
2956 DeleteObject (himl
->hbmImage
);
2957 himl
->hbmImage
= hbmNew
;
2959 if (himl
->hbmMask
) {
2961 imagelist_get_bitmap_size(himl
, himl
->cMaxImage
, &sz
);
2962 hbmNew
= CreateBitmap (sz
.cx
, sz
.cy
, 1, 1, NULL
);
2963 SelectObject (himl
->hdcMask
, hbmNew
);
2964 DeleteObject (himl
->hbmMask
);
2965 himl
->hbmMask
= hbmNew
;
2972 /*************************************************************************
2973 * ImageList_SetImageCount [COMCTL32.@]
2975 * Resizes an image list to the specified number of images.
2978 * himl [I] handle to image list
2979 * iImageCount [I] number of images in the image list
2987 ImageList_SetImageCount (HIMAGELIST himl
, UINT iImageCount
)
2990 HBITMAP hbmNewBitmap
, hbmOld
;
2991 INT nNewCount
, nCopyCount
;
2993 TRACE("%p %d\n",himl
,iImageCount
);
2995 if (!is_valid(himl
))
2998 nNewCount
= iImageCount
+ 1;
2999 nCopyCount
= min(himl
->cCurImage
, iImageCount
);
3001 hdcBitmap
= CreateCompatibleDC (0);
3003 hbmNewBitmap
= ImageList_CreateImage(hdcBitmap
, himl
, nNewCount
);
3005 if (hbmNewBitmap
!= 0)
3007 hbmOld
= SelectObject (hdcBitmap
, hbmNewBitmap
);
3008 imagelist_copy_images( himl
, himl
->hdcImage
, hdcBitmap
, 0, nCopyCount
, 0 );
3009 SelectObject (hdcBitmap
, hbmOld
);
3011 /* FIXME: delete 'empty' image space? */
3013 SelectObject (himl
->hdcImage
, hbmNewBitmap
);
3014 DeleteObject (himl
->hbmImage
);
3015 himl
->hbmImage
= hbmNewBitmap
;
3018 ERR("Could not create new image bitmap!\n");
3023 imagelist_get_bitmap_size( himl
, nNewCount
, &sz
);
3024 hbmNewBitmap
= CreateBitmap (sz
.cx
, sz
.cy
, 1, 1, NULL
);
3025 if (hbmNewBitmap
!= 0)
3027 hbmOld
= SelectObject (hdcBitmap
, hbmNewBitmap
);
3028 imagelist_copy_images( himl
, himl
->hdcMask
, hdcBitmap
, 0, nCopyCount
, 0 );
3029 SelectObject (hdcBitmap
, hbmOld
);
3031 /* FIXME: delete 'empty' image space? */
3033 SelectObject (himl
->hdcMask
, hbmNewBitmap
);
3034 DeleteObject (himl
->hbmMask
);
3035 himl
->hbmMask
= hbmNewBitmap
;
3038 ERR("Could not create new mask bitmap!\n");
3041 DeleteDC (hdcBitmap
);
3043 if (himl
->has_alpha
)
3045 char *new_alpha
= HeapReAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, himl
->has_alpha
, nNewCount
);
3046 if (new_alpha
) himl
->has_alpha
= new_alpha
;
3049 heap_free( himl
->has_alpha
);
3050 himl
->has_alpha
= NULL
;
3054 /* Update max image count and current image count */
3055 himl
->cMaxImage
= nNewCount
;
3056 himl
->cCurImage
= iImageCount
;
3062 /*************************************************************************
3063 * ImageList_SetOverlayImage [COMCTL32.@]
3065 * Assigns an overlay mask index to an existing image in an image list.
3068 * himl [I] handle to image list
3069 * iImage [I] image index
3070 * iOverlay [I] overlay mask index
3078 ImageList_SetOverlayImage (HIMAGELIST himl
, INT iImage
, INT iOverlay
)
3080 if (!is_valid(himl
))
3082 if ((iOverlay
< 1) || (iOverlay
> MAX_OVERLAYIMAGE
))
3084 if ((iImage
!=-1) && ((iImage
< 0) || (iImage
> himl
->cCurImage
)))
3086 himl
->nOvlIdx
[iOverlay
- 1] = iImage
;
3092 /* helper for ImageList_Write - write bitmap to pstm
3093 * currently everything is written as 24 bit RGB, except masks
3095 static BOOL
_write_bitmap(HBITMAP hBitmap
, IStream
*pstm
)
3097 LPBITMAPFILEHEADER bmfh
;
3098 LPBITMAPINFOHEADER bmih
;
3099 LPBYTE data
= NULL
, lpBits
;
3101 INT bitCount
, sizeImage
, offBits
, totalSize
;
3103 BOOL result
= FALSE
;
3105 if (!GetObjectW(hBitmap
, sizeof(BITMAP
), &bm
))
3108 bitCount
= bm
.bmBitsPixel
;
3109 sizeImage
= get_dib_stride(bm
.bmWidth
, bitCount
) * bm
.bmHeight
;
3111 totalSize
= sizeof(BITMAPFILEHEADER
) + sizeof(BITMAPINFOHEADER
);
3113 totalSize
+= (1 << bitCount
) * sizeof(RGBQUAD
);
3114 offBits
= totalSize
;
3115 totalSize
+= sizeImage
;
3117 data
= heap_alloc_zero(totalSize
);
3118 bmfh
= (LPBITMAPFILEHEADER
)data
;
3119 bmih
= (LPBITMAPINFOHEADER
)(data
+ sizeof(BITMAPFILEHEADER
));
3120 lpBits
= data
+ offBits
;
3122 /* setup BITMAPFILEHEADER */
3123 bmfh
->bfType
= (('M' << 8) | 'B');
3124 bmfh
->bfSize
= offBits
;
3125 bmfh
->bfReserved1
= 0;
3126 bmfh
->bfReserved2
= 0;
3127 bmfh
->bfOffBits
= offBits
;
3129 /* setup BITMAPINFOHEADER */
3130 bmih
->biSize
= sizeof(BITMAPINFOHEADER
);
3131 bmih
->biWidth
= bm
.bmWidth
;
3132 bmih
->biHeight
= bm
.bmHeight
;
3134 bmih
->biBitCount
= bitCount
;
3135 bmih
->biCompression
= BI_RGB
;
3136 bmih
->biSizeImage
= sizeImage
;
3137 bmih
->biXPelsPerMeter
= 0;
3138 bmih
->biYPelsPerMeter
= 0;
3139 bmih
->biClrUsed
= 0;
3140 bmih
->biClrImportant
= 0;
3143 result
= GetDIBits(xdc
, hBitmap
, 0, bm
.bmHeight
, lpBits
, (BITMAPINFO
*)bmih
, DIB_RGB_COLORS
) == bm
.bmHeight
;
3148 TRACE("width %u, height %u, planes %u, bpp %u\n",
3149 bmih
->biWidth
, bmih
->biHeight
,
3150 bmih
->biPlanes
, bmih
->biBitCount
);
3152 if(FAILED(IStream_Write(pstm
, data
, totalSize
, NULL
)))
3164 /*************************************************************************
3165 * ImageList_Write [COMCTL32.@]
3167 * Writes an image list to a stream.
3170 * himl [I] handle to image list
3171 * pstm [O] Pointer to a stream.
3181 BOOL WINAPI
ImageList_Write(HIMAGELIST himl
, IStream
*pstm
)
3186 TRACE("%p %p\n", himl
, pstm
);
3188 if (!is_valid(himl
))
3191 ilHead
.usMagic
= (('L' << 8) | 'I');
3192 ilHead
.usVersion
= 0x101;
3193 ilHead
.cCurImage
= himl
->cCurImage
;
3194 ilHead
.cMaxImage
= himl
->cMaxImage
;
3195 ilHead
.cGrow
= himl
->cGrow
;
3196 ilHead
.cx
= himl
->cx
;
3197 ilHead
.cy
= himl
->cy
;
3198 ilHead
.bkcolor
= himl
->clrBk
;
3199 ilHead
.flags
= himl
->flags
;
3200 for(i
= 0; i
< 4; i
++) {
3201 ilHead
.ovls
[i
] = himl
->nOvlIdx
[i
];
3204 TRACE("cx %u, cy %u, flags 0x04%x, cCurImage %u, cMaxImage %u\n",
3205 ilHead
.cx
, ilHead
.cy
, ilHead
.flags
, ilHead
.cCurImage
, ilHead
.cMaxImage
);
3207 if(FAILED(IStream_Write(pstm
, &ilHead
, sizeof(ILHEAD
), NULL
)))
3210 /* write the bitmap */
3211 if(!_write_bitmap(himl
->hbmImage
, pstm
))
3214 /* write the mask if we have one */
3215 if(himl
->flags
& ILC_MASK
) {
3216 if(!_write_bitmap(himl
->hbmMask
, pstm
))
3224 static HBITMAP
ImageList_CreateImage(HDC hdc
, HIMAGELIST himl
, UINT count
)
3226 HBITMAP hbmNewBitmap
;
3227 UINT ilc
= (himl
->flags
& 0xFE);
3230 imagelist_get_bitmap_size( himl
, count
, &sz
);
3232 if ((ilc
>= ILC_COLOR4
&& ilc
<= ILC_COLOR32
) || ilc
== ILC_COLOR
)
3234 char buffer
[sizeof(BITMAPINFOHEADER
) + 256 * sizeof(RGBQUAD
)];
3235 BITMAPINFO
*bmi
= (BITMAPINFO
*)buffer
;
3237 TRACE("Creating DIBSection %d x %d, %d Bits per Pixel\n",
3238 sz
.cx
, sz
.cy
, himl
->uBitsPixel
);
3240 memset( buffer
, 0, sizeof(buffer
) );
3241 bmi
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
3242 bmi
->bmiHeader
.biWidth
= sz
.cx
;
3243 bmi
->bmiHeader
.biHeight
= sz
.cy
;
3244 bmi
->bmiHeader
.biPlanes
= 1;
3245 bmi
->bmiHeader
.biBitCount
= himl
->uBitsPixel
;
3246 bmi
->bmiHeader
.biCompression
= BI_RGB
;
3248 if (himl
->uBitsPixel
<= ILC_COLOR8
)
3250 if (!himl
->color_table_set
)
3252 /* retrieve the default color map */
3253 HBITMAP tmp
= CreateBitmap( 1, 1, 1, 1, NULL
);
3254 GetDIBits( hdc
, tmp
, 0, 0, NULL
, bmi
, DIB_RGB_COLORS
);
3255 DeleteObject( tmp
);
3256 if (ilc
== ILC_COLOR4
)
3259 tmp
= bmi
->bmiColors
[7];
3260 bmi
->bmiColors
[7] = bmi
->bmiColors
[8];
3261 bmi
->bmiColors
[8] = tmp
;
3266 GetDIBColorTable(himl
->hdcImage
, 0, 1 << himl
->uBitsPixel
, bmi
->bmiColors
);
3269 hbmNewBitmap
= CreateDIBSection(hdc
, bmi
, DIB_RGB_COLORS
, NULL
, 0, 0);
3271 else /*if (ilc == ILC_COLORDDB)*/
3273 TRACE("Creating Bitmap: %d Bits per Pixel\n", himl
->uBitsPixel
);
3275 hbmNewBitmap
= CreateBitmap (sz
.cx
, sz
.cy
, 1, himl
->uBitsPixel
, NULL
);
3277 TRACE("returning %p\n", hbmNewBitmap
);
3278 return hbmNewBitmap
;
3281 /*************************************************************************
3282 * ImageList_SetColorTable [COMCTL32.@]
3284 * Sets the color table of an image list.
3287 * himl [I] Handle to the image list.
3288 * uStartIndex [I] The first index to set.
3289 * cEntries [I] Number of entries to set.
3290 * prgb [I] New color information for color table for the image list.
3293 * Success: Number of entries in the table that were set.
3297 * ImageList_Create(), SetDIBColorTable()
3301 ImageList_SetColorTable(HIMAGELIST himl
, UINT uStartIndex
, UINT cEntries
, const RGBQUAD
*prgb
)
3303 TRACE("(%p, %d, %d, %p)\n", himl
, uStartIndex
, cEntries
, prgb
);
3304 himl
->color_table_set
= TRUE
;
3305 return SetDIBColorTable(himl
->hdcImage
, uStartIndex
, cEntries
, prgb
);
3308 /*************************************************************************
3309 * ImageList_CoCreateInstance [COMCTL32.@]
3311 * Creates a new imagelist instance and returns an interface pointer to it.
3314 * rclsid [I] A reference to the CLSID (CLSID_ImageList).
3315 * punkOuter [I] Pointer to IUnknown interface for aggregation, if desired
3316 * riid [I] Identifier of the requested interface.
3317 * ppv [O] Returns the address of the pointer requested, or NULL.
3321 * Failure: Error value.
3324 ImageList_CoCreateInstance (REFCLSID rclsid
, const IUnknown
*punkOuter
, REFIID riid
, void **ppv
)
3326 TRACE("(%s,%p,%s,%p)\n", debugstr_guid(rclsid
), punkOuter
, debugstr_guid(riid
), ppv
);
3328 if (!IsEqualCLSID(&CLSID_ImageList
, rclsid
))
3329 return E_NOINTERFACE
;
3331 return ImageListImpl_CreateInstance(punkOuter
, riid
, ppv
);
3335 /*************************************************************************
3336 * IImageList implementation
3339 static HRESULT WINAPI
ImageListImpl_QueryInterface(IImageList2
*iface
,
3340 REFIID iid
, void **ppv
)
3342 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3344 TRACE("(%p,%s,%p)\n", iface
, debugstr_guid(iid
), ppv
);
3346 if (!ppv
) return E_INVALIDARG
;
3348 if (IsEqualIID(&IID_IUnknown
, iid
) ||
3349 IsEqualIID(&IID_IImageList
, iid
) ||
3350 IsEqualIID(&IID_IImageList2
, iid
))
3352 *ppv
= &imgl
->IImageList2_iface
;
3357 return E_NOINTERFACE
;
3360 IImageList2_AddRef(iface
);
3364 static ULONG WINAPI
ImageListImpl_AddRef(IImageList2
*iface
)
3366 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3367 ULONG ref
= InterlockedIncrement(&imgl
->ref
);
3369 TRACE("(%p) refcount=%u\n", iface
, ref
);
3373 static ULONG WINAPI
ImageListImpl_Release(IImageList2
*iface
)
3375 HIMAGELIST This
= impl_from_IImageList2(iface
);
3376 ULONG ref
= InterlockedDecrement(&This
->ref
);
3378 TRACE("(%p) refcount=%u\n", iface
, ref
);
3382 /* delete image bitmaps */
3383 if (This
->hbmImage
) DeleteObject (This
->hbmImage
);
3384 if (This
->hbmMask
) DeleteObject (This
->hbmMask
);
3386 /* delete image & mask DCs */
3387 if (This
->hdcImage
) DeleteDC (This
->hdcImage
);
3388 if (This
->hdcMask
) DeleteDC (This
->hdcMask
);
3390 /* delete blending brushes */
3391 if (This
->hbrBlend25
) DeleteObject (This
->hbrBlend25
);
3392 if (This
->hbrBlend50
) DeleteObject (This
->hbrBlend50
);
3394 This
->IImageList2_iface
.lpVtbl
= NULL
;
3395 heap_free(This
->has_alpha
);
3402 static HRESULT WINAPI
ImageListImpl_Add(IImageList2
*iface
, HBITMAP hbmImage
,
3403 HBITMAP hbmMask
, int *pi
)
3405 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3411 ret
= ImageList_Add(imgl
, hbmImage
, hbmMask
);
3420 static HRESULT WINAPI
ImageListImpl_ReplaceIcon(IImageList2
*iface
, int i
,
3421 HICON hicon
, int *pi
)
3423 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3429 ret
= ImageList_ReplaceIcon(imgl
, i
, hicon
);
3438 static HRESULT WINAPI
ImageListImpl_SetOverlayImage(IImageList2
*iface
,
3439 int iImage
, int iOverlay
)
3441 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3442 return ImageList_SetOverlayImage(imgl
, iImage
, iOverlay
) ? S_OK
: E_FAIL
;
3445 static HRESULT WINAPI
ImageListImpl_Replace(IImageList2
*iface
, int i
,
3446 HBITMAP hbmImage
, HBITMAP hbmMask
)
3448 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3449 return ImageList_Replace(imgl
, i
, hbmImage
, hbmMask
) ? S_OK
: E_FAIL
;
3452 static HRESULT WINAPI
ImageListImpl_AddMasked(IImageList2
*iface
, HBITMAP hbmImage
,
3453 COLORREF crMask
, int *pi
)
3455 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3461 ret
= ImageList_AddMasked(imgl
, hbmImage
, crMask
);
3470 static HRESULT WINAPI
ImageListImpl_Draw(IImageList2
*iface
,
3471 IMAGELISTDRAWPARAMS
*pimldp
)
3473 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3474 HIMAGELIST old_himl
;
3477 /* As far as I can tell, Windows simply ignores the contents of pimldp->himl
3478 so we shall simulate the same */
3479 old_himl
= pimldp
->himl
;
3480 pimldp
->himl
= imgl
;
3482 ret
= ImageList_DrawIndirect(pimldp
);
3484 pimldp
->himl
= old_himl
;
3485 return ret
? S_OK
: E_INVALIDARG
;
3488 static HRESULT WINAPI
ImageListImpl_Remove(IImageList2
*iface
, int i
)
3490 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3491 return (ImageList_Remove(imgl
, i
) == 0) ? E_INVALIDARG
: S_OK
;
3494 static HRESULT WINAPI
ImageListImpl_GetIcon(IImageList2
*iface
, int i
, UINT flags
,
3497 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3503 hIcon
= ImageList_GetIcon(imgl
, i
, flags
);
3512 static HRESULT WINAPI
ImageListImpl_GetImageInfo(IImageList2
*iface
, int i
,
3513 IMAGEINFO
*pImageInfo
)
3515 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3516 return ImageList_GetImageInfo(imgl
, i
, pImageInfo
) ? S_OK
: E_FAIL
;
3519 static HRESULT WINAPI
ImageListImpl_Copy(IImageList2
*iface
, int dst_index
,
3520 IUnknown
*unk_src
, int src_index
, UINT flags
)
3522 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3523 IImageList
*src
= NULL
;
3529 /* TODO: Add test for IID_ImageList2 too */
3530 if (FAILED(IUnknown_QueryInterface(unk_src
, &IID_IImageList
,
3534 if (ImageList_Copy(imgl
, dst_index
, (HIMAGELIST
) src
, src_index
, flags
))
3539 IImageList_Release(src
);
3543 static HRESULT WINAPI
ImageListImpl_Merge(IImageList2
*iface
, int i1
,
3544 IUnknown
*punk2
, int i2
, int dx
, int dy
, REFIID riid
, void **ppv
)
3546 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3547 IImageList
*iml2
= NULL
;
3549 HRESULT ret
= E_FAIL
;
3551 TRACE("(%p)->(%d %p %d %d %d %s %p)\n", iface
, i1
, punk2
, i2
, dx
, dy
, debugstr_guid(riid
), ppv
);
3553 /* TODO: Add test for IID_ImageList2 too */
3554 if (FAILED(IUnknown_QueryInterface(punk2
, &IID_IImageList
,
3558 merged
= ImageList_Merge(imgl
, i1
, (HIMAGELIST
) iml2
, i2
, dx
, dy
);
3560 /* Get the interface for the new image list */
3563 ret
= HIMAGELIST_QueryInterface(merged
, riid
, ppv
);
3564 ImageList_Destroy(merged
);
3567 IImageList_Release(iml2
);
3571 static HRESULT WINAPI
ImageListImpl_Clone(IImageList2
*iface
, REFIID riid
, void **ppv
)
3573 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3575 HRESULT ret
= E_FAIL
;
3577 TRACE("(%p)->(%s %p)\n", iface
, debugstr_guid(riid
), ppv
);
3579 clone
= ImageList_Duplicate(imgl
);
3581 /* Get the interface for the new image list */
3584 ret
= HIMAGELIST_QueryInterface(clone
, riid
, ppv
);
3585 ImageList_Destroy(clone
);
3591 static HRESULT WINAPI
ImageListImpl_GetImageRect(IImageList2
*iface
, int i
,
3594 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3600 if (!ImageList_GetImageInfo(imgl
, i
, &info
))
3603 *prc
= info
.rcImage
;
3608 static HRESULT WINAPI
ImageListImpl_GetIconSize(IImageList2
*iface
, int *cx
,
3611 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3612 return ImageList_GetIconSize(imgl
, cx
, cy
) ? S_OK
: E_INVALIDARG
;
3615 static HRESULT WINAPI
ImageListImpl_SetIconSize(IImageList2
*iface
, int cx
,
3618 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3619 return ImageList_SetIconSize(imgl
, cx
, cy
) ? S_OK
: E_FAIL
;
3622 static HRESULT WINAPI
ImageListImpl_GetImageCount(IImageList2
*iface
, int *pi
)
3624 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3625 *pi
= ImageList_GetImageCount(imgl
);
3629 static HRESULT WINAPI
ImageListImpl_SetImageCount(IImageList2
*iface
, UINT count
)
3631 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3632 return ImageList_SetImageCount(imgl
, count
) ? S_OK
: E_FAIL
;
3635 static HRESULT WINAPI
ImageListImpl_SetBkColor(IImageList2
*iface
, COLORREF clrBk
,
3638 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3639 *pclr
= ImageList_SetBkColor(imgl
, clrBk
);
3643 static HRESULT WINAPI
ImageListImpl_GetBkColor(IImageList2
*iface
, COLORREF
*pclr
)
3645 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3646 *pclr
= ImageList_GetBkColor(imgl
);
3650 static HRESULT WINAPI
ImageListImpl_BeginDrag(IImageList2
*iface
, int iTrack
,
3651 int dxHotspot
, int dyHotspot
)
3653 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3654 return ImageList_BeginDrag(imgl
, iTrack
, dxHotspot
, dyHotspot
) ? S_OK
: E_FAIL
;
3657 static HRESULT WINAPI
ImageListImpl_EndDrag(IImageList2
*iface
)
3659 ImageList_EndDrag();
3663 static HRESULT WINAPI
ImageListImpl_DragEnter(IImageList2
*iface
, HWND hwndLock
,
3666 return ImageList_DragEnter(hwndLock
, x
, y
) ? S_OK
: E_FAIL
;
3669 static HRESULT WINAPI
ImageListImpl_DragLeave(IImageList2
*iface
, HWND hwndLock
)
3671 return ImageList_DragLeave(hwndLock
) ? S_OK
: E_FAIL
;
3674 static HRESULT WINAPI
ImageListImpl_DragMove(IImageList2
*iface
, int x
, int y
)
3676 return ImageList_DragMove(x
, y
) ? S_OK
: E_FAIL
;
3679 static HRESULT WINAPI
ImageListImpl_SetDragCursorImage(IImageList2
*iface
,
3680 IUnknown
*punk
, int iDrag
, int dxHotspot
, int dyHotspot
)
3682 IImageList
*iml2
= NULL
;
3688 /* TODO: Add test for IID_ImageList2 too */
3689 if (FAILED(IUnknown_QueryInterface(punk
, &IID_IImageList
,
3693 ret
= ImageList_SetDragCursorImage((HIMAGELIST
) iml2
, iDrag
, dxHotspot
,
3696 IImageList_Release(iml2
);
3698 return ret
? S_OK
: E_FAIL
;
3701 static HRESULT WINAPI
ImageListImpl_DragShowNolock(IImageList2
*iface
, BOOL fShow
)
3703 return ImageList_DragShowNolock(fShow
) ? S_OK
: E_FAIL
;
3706 static HRESULT WINAPI
ImageListImpl_GetDragImage(IImageList2
*iface
, POINT
*ppt
,
3707 POINT
*pptHotspot
, REFIID riid
, PVOID
*ppv
)
3709 HRESULT ret
= E_FAIL
;
3715 hNew
= ImageList_GetDragImage(ppt
, pptHotspot
);
3717 /* Get the interface for the new image list */
3720 IImageList
*idrag
= (IImageList
*)hNew
;
3722 ret
= HIMAGELIST_QueryInterface(hNew
, riid
, ppv
);
3723 IImageList_Release(idrag
);
3729 static HRESULT WINAPI
ImageListImpl_GetItemFlags(IImageList2
*iface
, int i
,
3732 FIXME("STUB: %p %d %p\n", iface
, i
, dwFlags
);
3736 static HRESULT WINAPI
ImageListImpl_GetOverlayImage(IImageList2
*iface
, int iOverlay
,
3739 HIMAGELIST This
= impl_from_IImageList2(iface
);
3742 if ((iOverlay
< 0) || (iOverlay
> This
->cCurImage
))
3745 for (i
= 0; i
< MAX_OVERLAYIMAGE
; i
++)
3747 if (This
->nOvlIdx
[i
] == iOverlay
)
3757 static HRESULT WINAPI
ImageListImpl_Resize(IImageList2
*iface
, INT cx
, INT cy
)
3759 FIXME("(%p)->(%d %d): stub\n", iface
, cx
, cy
);
3763 static HRESULT WINAPI
ImageListImpl_GetOriginalSize(IImageList2
*iface
, INT image
, DWORD flags
, INT
*cx
, INT
*cy
)
3765 FIXME("(%p)->(%d %x %p %p): stub\n", iface
, image
, flags
, cx
, cy
);
3769 static HRESULT WINAPI
ImageListImpl_SetOriginalSize(IImageList2
*iface
, INT image
, INT cx
, INT cy
)
3771 FIXME("(%p)->(%d %d %d): stub\n", iface
, image
, cx
, cy
);
3775 static HRESULT WINAPI
ImageListImpl_SetCallback(IImageList2
*iface
, IUnknown
*callback
)
3777 FIXME("(%p)->(%p): stub\n", iface
, callback
);
3781 static HRESULT WINAPI
ImageListImpl_GetCallback(IImageList2
*iface
, REFIID riid
, void **ppv
)
3783 FIXME("(%p)->(%s %p): stub\n", iface
, debugstr_guid(riid
), ppv
);
3787 static HRESULT WINAPI
ImageListImpl_ForceImagePresent(IImageList2
*iface
, INT image
, DWORD flags
)
3789 FIXME("(%p)->(%d %x): stub\n", iface
, image
, flags
);
3793 static HRESULT WINAPI
ImageListImpl_DiscardImages(IImageList2
*iface
, INT first_image
, INT last_image
, DWORD flags
)
3795 FIXME("(%p)->(%d %d %x): stub\n", iface
, first_image
, last_image
, flags
);
3799 static HRESULT WINAPI
ImageListImpl_PreloadImages(IImageList2
*iface
, IMAGELISTDRAWPARAMS
*params
)
3801 FIXME("(%p)->(%p): stub\n", iface
, params
);
3805 static HRESULT WINAPI
ImageListImpl_GetStatistics(IImageList2
*iface
, IMAGELISTSTATS
*stats
)
3807 FIXME("(%p)->(%p): stub\n", iface
, stats
);
3811 static HRESULT WINAPI
ImageListImpl_Initialize(IImageList2
*iface
, INT cx
, INT cy
, UINT flags
, INT initial
, INT grow
)
3813 FIXME("(%p)->(%d %d %d %d %d): stub\n", iface
, cx
, cy
, flags
, initial
, grow
);
3817 static HRESULT WINAPI
ImageListImpl_Replace2(IImageList2
*iface
, INT i
, HBITMAP image
, HBITMAP mask
, IUnknown
*unk
, DWORD flags
)
3819 FIXME("(%p)->(%d %p %p %p %x): stub\n", iface
, i
, image
, mask
, unk
, flags
);
3823 static HRESULT WINAPI
ImageListImpl_ReplaceFromImageList(IImageList2
*iface
, INT i
, IImageList
*imagelist
, INT src
,
3824 IUnknown
*unk
, DWORD flags
)
3826 FIXME("(%p)->(%d %p %d %p %x): stub\n", iface
, i
, imagelist
, src
, unk
, flags
);
3830 static const IImageList2Vtbl ImageListImpl_Vtbl
= {
3831 ImageListImpl_QueryInterface
,
3832 ImageListImpl_AddRef
,
3833 ImageListImpl_Release
,
3835 ImageListImpl_ReplaceIcon
,
3836 ImageListImpl_SetOverlayImage
,
3837 ImageListImpl_Replace
,
3838 ImageListImpl_AddMasked
,
3840 ImageListImpl_Remove
,
3841 ImageListImpl_GetIcon
,
3842 ImageListImpl_GetImageInfo
,
3844 ImageListImpl_Merge
,
3845 ImageListImpl_Clone
,
3846 ImageListImpl_GetImageRect
,
3847 ImageListImpl_GetIconSize
,
3848 ImageListImpl_SetIconSize
,
3849 ImageListImpl_GetImageCount
,
3850 ImageListImpl_SetImageCount
,
3851 ImageListImpl_SetBkColor
,
3852 ImageListImpl_GetBkColor
,
3853 ImageListImpl_BeginDrag
,
3854 ImageListImpl_EndDrag
,
3855 ImageListImpl_DragEnter
,
3856 ImageListImpl_DragLeave
,
3857 ImageListImpl_DragMove
,
3858 ImageListImpl_SetDragCursorImage
,
3859 ImageListImpl_DragShowNolock
,
3860 ImageListImpl_GetDragImage
,
3861 ImageListImpl_GetItemFlags
,
3862 ImageListImpl_GetOverlayImage
,
3863 ImageListImpl_Resize
,
3864 ImageListImpl_GetOriginalSize
,
3865 ImageListImpl_SetOriginalSize
,
3866 ImageListImpl_SetCallback
,
3867 ImageListImpl_GetCallback
,
3868 ImageListImpl_ForceImagePresent
,
3869 ImageListImpl_DiscardImages
,
3870 ImageListImpl_PreloadImages
,
3871 ImageListImpl_GetStatistics
,
3872 ImageListImpl_Initialize
,
3873 ImageListImpl_Replace2
,
3874 ImageListImpl_ReplaceFromImageList
3877 static BOOL
is_valid(HIMAGELIST himl
)
3882 valid
= himl
&& himl
->IImageList2_iface
.lpVtbl
== &ImageListImpl_Vtbl
;
3892 /*************************************************************************
3893 * HIMAGELIST_QueryInterface [COMCTL32.@]
3895 * Returns a pointer to an IImageList or IImageList2 object for the given
3899 * himl [I] Image list handle.
3900 * riid [I] Identifier of the requested interface.
3901 * ppv [O] Returns the address of the pointer requested, or NULL.
3905 * Failure: Error value.
3908 HIMAGELIST_QueryInterface (HIMAGELIST himl
, REFIID riid
, void **ppv
)
3910 TRACE("(%p,%s,%p)\n", himl
, debugstr_guid(riid
), ppv
);
3911 return IImageList2_QueryInterface((IImageList2
*) himl
, riid
, ppv
);
3914 static HRESULT
ImageListImpl_CreateInstance(const IUnknown
*pUnkOuter
, REFIID iid
, void** ppv
)
3919 TRACE("(%p,%s,%p)\n", pUnkOuter
, debugstr_guid(iid
), ppv
);
3923 if (pUnkOuter
) return CLASS_E_NOAGGREGATION
;
3925 This
= heap_alloc_zero(sizeof(struct _IMAGELIST
));
3926 if (!This
) return E_OUTOFMEMORY
;
3928 This
->IImageList2_iface
.lpVtbl
= &ImageListImpl_Vtbl
;
3931 ret
= IImageList2_QueryInterface(&This
->IImageList2_iface
, iid
, ppv
);
3932 IImageList2_Release(&This
->IImageList2_iface
);