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_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"
49 WINE_DEFAULT_DEBUG_CHANNEL(imagelist
);
51 #define MAX_OVERLAYIMAGE 15
55 IImageList2 IImageList2_iface
; /* 00: IImageList vtable */
56 INT cCurImage
; /* 04: ImageCount */
57 INT cMaxImage
; /* 08: maximages */
58 INT cGrow
; /* 0C: cGrow */
62 UINT flags
; /* 1C: flags */
63 COLORREF clrFg
; /* 20: foreground color */
64 COLORREF clrBk
; /* 24: background color */
67 HBITMAP hbmImage
; /* 28: images Bitmap */
68 HBITMAP hbmMask
; /* 2C: masks Bitmap */
69 HDC hdcImage
; /* 30: images MemDC */
70 HDC hdcMask
; /* 34: masks MemDC */
71 INT nOvlIdx
[MAX_OVERLAYIMAGE
]; /* 38: overlay images index */
73 /* not yet found out */
81 LONG ref
; /* reference count */
84 #define IMAGELIST_MAGIC 0x53414D58
86 /* Header used by ImageList_Read() and ImageList_Write() */
88 typedef struct _ILHEAD
103 /* internal image list data used for Drag & Drop operations */
108 HIMAGELIST himlNoCursor
;
109 /* position of the drag image relative to the window */
112 /* offset of the hotspot relative to the origin of the image */
115 /* is the drag image visible */
117 /* saved background */
121 static INTERNALDRAG InternalDrag
= { 0, 0, 0, 0, 0, 0, 0, FALSE
, 0 };
123 static inline HIMAGELIST
impl_from_IImageList2(IImageList2
*iface
)
125 return CONTAINING_RECORD(iface
, struct _IMAGELIST
, IImageList2_iface
);
128 static HBITMAP
ImageList_CreateImage(HDC hdc
, HIMAGELIST himl
, UINT count
);
129 static HRESULT
ImageListImpl_CreateInstance(const IUnknown
*pUnkOuter
, REFIID iid
, void** ppv
);
130 static BOOL
is_valid(HIMAGELIST himl
);
133 * An imagelist with N images is tiled like this:
145 BOOL
imagelist_has_alpha( HIMAGELIST himl
, UINT index
)
147 return himl
->item_flags
[index
] & ILIF_ALPHA
;
150 static inline UINT
imagelist_height( UINT count
)
152 return ((count
+ TILE_COUNT
- 1)/TILE_COUNT
);
155 static inline void imagelist_point_from_index( HIMAGELIST himl
, UINT index
, LPPOINT pt
)
157 pt
->x
= (index
%TILE_COUNT
) * himl
->cx
;
158 pt
->y
= (index
/TILE_COUNT
) * himl
->cy
;
161 static inline void imagelist_get_bitmap_size( HIMAGELIST himl
, UINT count
, SIZE
*sz
)
163 sz
->cx
= himl
->cx
* TILE_COUNT
;
164 sz
->cy
= imagelist_height( count
) * himl
->cy
;
167 static inline int get_dib_stride( int width
, int bpp
)
169 return ((width
* bpp
+ 31) >> 3) & ~3;
172 static inline int get_dib_image_size( const BITMAPINFO
*info
)
174 return get_dib_stride( info
->bmiHeader
.biWidth
, info
->bmiHeader
.biBitCount
)
175 * abs( info
->bmiHeader
.biHeight
);
179 * imagelist_copy_images()
181 * Copies a block of count images from offset src in the list to offset dest.
182 * Images are copied a row at at time. Assumes hdcSrc and hdcDest are different.
184 static inline void imagelist_copy_images( HIMAGELIST himl
, HDC hdcSrc
, HDC hdcDest
,
185 UINT src
, UINT count
, UINT dest
)
191 for ( i
=0; i
<TILE_COUNT
; i
++ )
193 imagelist_point_from_index( himl
, src
+i
, &ptSrc
);
194 imagelist_point_from_index( himl
, dest
+i
, &ptDest
);
196 sz
.cy
= himl
->cy
* imagelist_height( count
- i
);
198 BitBlt( hdcDest
, ptDest
.x
, ptDest
.y
, sz
.cx
, sz
.cy
,
199 hdcSrc
, ptSrc
.x
, ptSrc
.y
, SRCCOPY
);
203 static void add_dib_bits( HIMAGELIST himl
, int pos
, int count
, int width
, int height
,
204 BITMAPINFO
*info
, BITMAPINFO
*mask_info
, DWORD
*bits
, BYTE
*mask_bits
)
208 int stride
= info
->bmiHeader
.biWidth
;
209 int mask_stride
= (info
->bmiHeader
.biWidth
+ 31) / 32 * 4;
211 for (n
= 0; n
< count
; n
++)
213 BOOL has_alpha
= FALSE
;
215 imagelist_point_from_index( himl
, pos
+ n
, &pt
);
217 /* check if bitmap has an alpha channel */
218 for (i
= 0; i
< height
&& !has_alpha
; i
++)
219 for (j
= n
* width
; j
< (n
+ 1) * width
; j
++)
220 if ((has_alpha
= ((bits
[i
* stride
+ j
] & 0xff000000) != 0))) break;
224 himl
->item_flags
[pos
+ n
] = ILIF_ALPHA
;
226 if (mask_info
&& himl
->hbmMask
) /* generate the mask from the alpha channel */
228 for (i
= 0; i
< height
; i
++)
229 for (j
= n
* width
; j
< (n
+ 1) * width
; j
++)
230 if ((bits
[i
* stride
+ j
] >> 24) > 25) /* more than 10% alpha */
231 mask_bits
[i
* mask_stride
+ j
/ 8] &= ~(0x80 >> (j
% 8));
233 mask_bits
[i
* mask_stride
+ j
/ 8] |= 0x80 >> (j
% 8);
236 else if (mask_info
) /* mask out the background */
238 for (i
= 0; i
< height
; i
++)
239 for (j
= n
* width
; j
< (n
+ 1) * width
; j
++)
240 if ((mask_bits
[i
* mask_stride
+ j
/ 8] << (j
% 8)) & 0x80)
241 bits
[i
* stride
+ j
] = 0;
243 StretchDIBits( himl
->hdcImage
, pt
.x
, pt
.y
, himl
->cx
, himl
->cy
,
244 n
* width
, 0, width
, height
, bits
, info
, DIB_RGB_COLORS
, SRCCOPY
);
246 StretchDIBits( himl
->hdcMask
, pt
.x
, pt
.y
, himl
->cx
, himl
->cy
,
247 n
* width
, 0, width
, height
, mask_bits
, mask_info
, DIB_RGB_COLORS
, SRCCOPY
);
251 /* add images with an alpha channel when the image list is 32 bpp */
252 static BOOL
add_with_alpha( HIMAGELIST himl
, HDC hdc
, int pos
, int count
,
253 int width
, int height
, HBITMAP hbmImage
, HBITMAP hbmMask
)
257 BITMAPINFO
*info
, *mask_info
= NULL
;
259 BYTE
*mask_bits
= NULL
;
262 if (!GetObjectW( hbmImage
, sizeof(bm
), &bm
)) return FALSE
;
264 /* if either the imagelist or the source bitmap don't have an alpha channel, bail out now */
265 if ((himl
->flags
& 0xfe) != ILC_COLOR32
) return FALSE
;
266 if (bm
.bmBitsPixel
!= 32) return FALSE
;
268 SelectObject( hdc
, hbmImage
);
269 mask_width
= (bm
.bmWidth
+ 31) / 32 * 4;
271 if (!(info
= Alloc( FIELD_OFFSET( BITMAPINFO
, bmiColors
[256] )))) goto done
;
272 info
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
273 info
->bmiHeader
.biWidth
= bm
.bmWidth
;
274 info
->bmiHeader
.biHeight
= -height
;
275 info
->bmiHeader
.biPlanes
= 1;
276 info
->bmiHeader
.biBitCount
= 32;
277 info
->bmiHeader
.biCompression
= BI_RGB
;
278 info
->bmiHeader
.biSizeImage
= bm
.bmWidth
* height
* 4;
279 info
->bmiHeader
.biXPelsPerMeter
= 0;
280 info
->bmiHeader
.biYPelsPerMeter
= 0;
281 info
->bmiHeader
.biClrUsed
= 0;
282 info
->bmiHeader
.biClrImportant
= 0;
283 if (!(bits
= Alloc( info
->bmiHeader
.biSizeImage
))) goto done
;
284 if (!GetDIBits( hdc
, hbmImage
, 0, height
, bits
, info
, DIB_RGB_COLORS
)) goto done
;
288 if (!(mask_info
= Alloc( FIELD_OFFSET( BITMAPINFO
, bmiColors
[2] ))))
290 mask_info
->bmiHeader
= info
->bmiHeader
;
291 mask_info
->bmiHeader
.biBitCount
= 1;
292 mask_info
->bmiHeader
.biSizeImage
= mask_width
* height
;
293 if (!(mask_bits
= Alloc( mask_info
->bmiHeader
.biSizeImage
)))
295 if (!GetDIBits( hdc
, hbmMask
, 0, height
, mask_bits
, mask_info
, DIB_RGB_COLORS
)) goto done
;
298 add_dib_bits( himl
, pos
, count
, width
, height
, info
, mask_info
, bits
, mask_bits
);
310 ImageList_SetColorTable(HIMAGELIST himl
, UINT uStartIndex
, UINT cEntries
, const RGBQUAD
*prgb
);
312 /*************************************************************************
313 * IMAGELIST_InternalExpandBitmaps [Internal]
315 * Expands the bitmaps of an image list by the given number of images.
318 * himl [I] handle to image list
319 * nImageCount [I] number of images to add
325 * This function CANNOT be used to reduce the number of images.
328 IMAGELIST_InternalExpandBitmaps(HIMAGELIST himl
, INT nImageCount
)
331 HBITMAP hbmNewBitmap
, hbmNull
;
335 TRACE("%p has allocated %d, max %d, grow %d images\n", himl
, himl
->cCurImage
, himl
->cMaxImage
, himl
->cGrow
);
337 if (himl
->cCurImage
+ nImageCount
< himl
->cMaxImage
)
340 nNewCount
= himl
->cMaxImage
+ max(nImageCount
, himl
->cGrow
) + 1;
342 imagelist_get_bitmap_size(himl
, nNewCount
, &sz
);
344 TRACE("Create expanded bitmaps : himl=%p x=%ld y=%ld count=%d\n", himl
, sz
.cx
, sz
.cy
, nNewCount
);
345 hdcBitmap
= CreateCompatibleDC (0);
347 hbmNewBitmap
= ImageList_CreateImage(hdcBitmap
, himl
, nNewCount
);
349 if (hbmNewBitmap
== 0)
350 ERR("creating new image bitmap (x=%ld y=%ld)!\n", sz
.cx
, sz
.cy
);
354 hbmNull
= SelectObject (hdcBitmap
, hbmNewBitmap
);
355 BitBlt (hdcBitmap
, 0, 0, sz
.cx
, sz
.cy
,
356 himl
->hdcImage
, 0, 0, SRCCOPY
);
357 SelectObject (hdcBitmap
, hbmNull
);
359 SelectObject (himl
->hdcImage
, hbmNewBitmap
);
360 DeleteObject (himl
->hbmImage
);
361 himl
->hbmImage
= hbmNewBitmap
;
363 if (himl
->flags
& ILC_MASK
)
365 hbmNewBitmap
= CreateBitmap (sz
.cx
, sz
.cy
, 1, 1, NULL
);
367 if (hbmNewBitmap
== 0)
368 ERR("creating new mask bitmap!\n");
372 hbmNull
= SelectObject (hdcBitmap
, hbmNewBitmap
);
373 BitBlt (hdcBitmap
, 0, 0, sz
.cx
, sz
.cy
,
374 himl
->hdcMask
, 0, 0, SRCCOPY
);
375 SelectObject (hdcBitmap
, hbmNull
);
377 SelectObject (himl
->hdcMask
, hbmNewBitmap
);
378 DeleteObject (himl
->hbmMask
);
379 himl
->hbmMask
= hbmNewBitmap
;
382 himl
->item_flags
= HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, himl
->item_flags
,
383 nNewCount
* sizeof(*himl
->item_flags
));
384 himl
->cMaxImage
= nNewCount
;
386 DeleteDC (hdcBitmap
);
390 /*************************************************************************
391 * ImageList_Add [COMCTL32.@]
393 * Add an image or images to an image list.
396 * himl [I] handle to image list
397 * hbmImage [I] handle to image bitmap
398 * hbmMask [I] handle to mask bitmap
401 * Success: Index of the first new image.
406 ImageList_Add (HIMAGELIST himl
, HBITMAP hbmImage
, HBITMAP hbmMask
)
408 HDC hdcBitmap
, hdcTemp
= 0;
409 INT nFirstIndex
, nImageCount
, i
;
413 TRACE("himl=%p hbmimage=%p hbmmask=%p\n", himl
, hbmImage
, hbmMask
);
417 if (!GetObjectW(hbmImage
, sizeof(BITMAP
), &bmp
))
420 TRACE("himl %p, cCurImage %d, cMaxImage %d, cGrow %d, cx %d, cy %d\n",
421 himl
, himl
->cCurImage
, himl
->cMaxImage
, himl
->cGrow
, himl
->cx
, himl
->cy
);
423 nImageCount
= bmp
.bmWidth
/ himl
->cx
;
425 TRACE("%p has %d images (%d x %d) bpp %d\n", hbmImage
, nImageCount
, bmp
.bmWidth
, bmp
.bmHeight
,
428 IMAGELIST_InternalExpandBitmaps(himl
, nImageCount
);
430 hdcBitmap
= CreateCompatibleDC(0);
432 SelectObject(hdcBitmap
, hbmImage
);
434 if (add_with_alpha( himl
, hdcBitmap
, himl
->cCurImage
, nImageCount
,
435 himl
->cx
, min( himl
->cy
, bmp
.bmHeight
), hbmImage
, hbmMask
))
440 hdcTemp
= CreateCompatibleDC(0);
441 SelectObject(hdcTemp
, hbmMask
);
444 if (himl
->uBitsPixel
<= 8 && bmp
.bmBitsPixel
<= 8 &&
445 !himl
->color_table_set
&& himl
->cCurImage
== 0)
448 UINT num
= GetDIBColorTable( hdcBitmap
, 0, 1 << bmp
.bmBitsPixel
, colors
);
449 if (num
) ImageList_SetColorTable( himl
, 0, num
, colors
);
452 for (i
=0; i
<nImageCount
; i
++)
454 imagelist_point_from_index( himl
, himl
->cCurImage
+ i
, &pt
);
456 /* Copy result to the imagelist
458 BitBlt( himl
->hdcImage
, pt
.x
, pt
.y
, himl
->cx
, bmp
.bmHeight
,
459 hdcBitmap
, i
*himl
->cx
, 0, SRCCOPY
);
464 BitBlt( himl
->hdcMask
, pt
.x
, pt
.y
, himl
->cx
, bmp
.bmHeight
,
465 hdcTemp
, i
*himl
->cx
, 0, SRCCOPY
);
467 /* Remove the background from the image
469 BitBlt( himl
->hdcImage
, pt
.x
, pt
.y
, himl
->cx
, bmp
.bmHeight
,
470 himl
->hdcMask
, pt
.x
, pt
.y
, 0x220326 ); /* NOTSRCAND */
472 if (hdcTemp
) DeleteDC(hdcTemp
);
477 nFirstIndex
= himl
->cCurImage
;
478 himl
->cCurImage
+= nImageCount
;
484 /*************************************************************************
485 * ImageList_AddIcon [COMCTL32.@]
487 * Adds an icon to an image list.
490 * himl [I] handle to image list
491 * hIcon [I] handle to icon
494 * Success: index of the new image
497 #undef ImageList_AddIcon
498 INT WINAPI
ImageList_AddIcon (HIMAGELIST himl
, HICON hIcon
)
500 return ImageList_ReplaceIcon (himl
, -1, hIcon
);
504 /*************************************************************************
505 * ImageList_AddMasked [COMCTL32.@]
507 * Adds an image or images to an image list and creates a mask from the
508 * specified bitmap using the mask color.
511 * himl [I] handle to image list.
512 * hBitmap [I] handle to bitmap
513 * clrMask [I] mask color.
516 * Success: Index of the first new image.
521 ImageList_AddMasked (HIMAGELIST himl
, HBITMAP hBitmap
, COLORREF clrMask
)
523 HDC hdcMask
, hdcBitmap
;
529 TRACE("himl %p, hbitmap %p, clrmask %#lx\n", himl
, hBitmap
, clrMask
);
534 if (!GetObjectW(hBitmap
, sizeof(BITMAP
), &bmp
))
537 hdcBitmap
= CreateCompatibleDC(0);
538 SelectObject(hdcBitmap
, hBitmap
);
540 /* Create a temp Mask so we can remove the background of the Image */
541 hdcMask
= CreateCompatibleDC(0);
542 hMaskBitmap
= CreateBitmap(bmp
.bmWidth
, bmp
.bmHeight
, 1, 1, NULL
);
543 SelectObject(hdcMask
, hMaskBitmap
);
545 /* create monochrome image to the mask bitmap */
546 bkColor
= (clrMask
!= CLR_DEFAULT
) ? clrMask
: GetPixel (hdcBitmap
, 0, 0);
547 SetBkColor (hdcBitmap
, bkColor
);
548 BitBlt (hdcMask
, 0, 0, bmp
.bmWidth
, bmp
.bmHeight
, hdcBitmap
, 0, 0, SRCCOPY
);
551 * Remove the background from the image
553 * WINDOWS BUG ALERT!!!!!!
554 * The statement below should not be done in common practice
555 * but this is how ImageList_AddMasked works in Windows.
556 * It overwrites the original bitmap passed, this was discovered
557 * by using the same bitmap to iterate the different styles
558 * on windows where it failed (BUT ImageList_Add is OK)
559 * This is here in case some apps rely on this bug
561 * Blt mode 0x220326 is NOTSRCAND
563 if (bmp
.bmBitsPixel
> 8) /* NOTSRCAND can't work with palettes */
565 SetBkColor(hdcBitmap
, RGB(255,255,255));
566 BitBlt(hdcBitmap
, 0, 0, bmp
.bmWidth
, bmp
.bmHeight
, hdcMask
, 0, 0, 0x220326);
572 ret
= ImageList_Add( himl
, hBitmap
, hMaskBitmap
);
574 DeleteObject(hMaskBitmap
);
579 /*************************************************************************
580 * ImageList_BeginDrag [COMCTL32.@]
582 * Creates a temporary image list that contains one image. It will be used
586 * himlTrack [I] handle to the source image list
587 * iTrack [I] index of the drag image in the source image list
588 * dxHotspot [I] X position of the hot spot of the drag image
589 * dyHotspot [I] Y position of the hot spot of the drag image
597 ImageList_BeginDrag (HIMAGELIST himlTrack
, INT iTrack
,
598 INT dxHotspot
, INT dyHotspot
)
603 TRACE("(himlTrack=%p iTrack=%d dx=%d dy=%d)\n", himlTrack
, iTrack
,
604 dxHotspot
, dyHotspot
);
606 if (!is_valid(himlTrack
))
609 if (iTrack
>= himlTrack
->cCurImage
)
612 if (InternalDrag
.himl
)
618 InternalDrag
.himlNoCursor
= InternalDrag
.himl
= ImageList_Create (cx
, cy
, himlTrack
->flags
, 1, 1);
619 if (InternalDrag
.himl
== NULL
) {
620 WARN("Error creating drag image list!\n");
624 InternalDrag
.dxHotspot
= dxHotspot
;
625 InternalDrag
.dyHotspot
= dyHotspot
;
628 imagelist_point_from_index(InternalDrag
.himl
, 0, &dst
);
629 imagelist_point_from_index(himlTrack
, iTrack
, &src
);
630 BitBlt(InternalDrag
.himl
->hdcImage
, dst
.x
, dst
.y
, cx
, cy
, himlTrack
->hdcImage
, src
.x
, src
.y
,
632 BitBlt(InternalDrag
.himl
->hdcMask
, dst
.x
, dst
.y
, cx
, cy
, himlTrack
->hdcMask
, src
.x
, src
.y
,
635 InternalDrag
.himl
->cCurImage
= 1;
641 /*************************************************************************
642 * ImageList_Copy [COMCTL32.@]
644 * Copies an image of the source image list to an image of the
645 * destination image list. Images can be copied or swapped.
648 * himlDst [I] handle to the destination image list
649 * iDst [I] destination image index.
650 * himlSrc [I] handle to the source image list
651 * iSrc [I] source image index
652 * uFlags [I] flags for the copy operation
659 * Copying from one image list to another is possible. The original
660 * implementation just copies or swaps within one image list.
661 * Could this feature become a bug??? ;-)
665 ImageList_Copy (HIMAGELIST himlDst
, INT iDst
, HIMAGELIST himlSrc
,
666 INT iSrc
, UINT uFlags
)
670 TRACE("himlDst=%p iDst=%d himlSrc=%p iSrc=%d\n", himlDst
, iDst
, himlSrc
, iSrc
);
672 if (!is_valid(himlSrc
) || !is_valid(himlDst
))
674 if ((iDst
< 0) || (iDst
>= himlDst
->cCurImage
))
676 if ((iSrc
< 0) || (iSrc
>= himlSrc
->cCurImage
))
679 imagelist_point_from_index( himlDst
, iDst
, &ptDst
);
680 imagelist_point_from_index( himlSrc
, iSrc
, &ptSrc
);
682 if (uFlags
& ILCF_SWAP
) {
685 HBITMAP hbmTempImage
, hbmTempMask
;
687 hdcBmp
= CreateCompatibleDC (0);
689 /* create temporary bitmaps */
690 hbmTempImage
= CreateBitmap (himlSrc
->cx
, himlSrc
->cy
, 1,
691 himlSrc
->uBitsPixel
, NULL
);
692 hbmTempMask
= CreateBitmap (himlSrc
->cx
, himlSrc
->cy
, 1,
695 /* copy (and stretch) destination to temporary bitmaps.(save) */
697 SelectObject (hdcBmp
, hbmTempImage
);
698 StretchBlt (hdcBmp
, 0, 0, himlSrc
->cx
, himlSrc
->cy
,
699 himlDst
->hdcImage
, ptDst
.x
, ptDst
.y
, himlDst
->cx
, himlDst
->cy
,
702 SelectObject (hdcBmp
, hbmTempMask
);
703 StretchBlt (hdcBmp
, 0, 0, himlSrc
->cx
, himlSrc
->cy
,
704 himlDst
->hdcMask
, ptDst
.x
, ptDst
.y
, himlDst
->cx
, himlDst
->cy
,
707 /* copy (and stretch) source to destination */
709 StretchBlt (himlDst
->hdcImage
, ptDst
.x
, ptDst
.y
, himlDst
->cx
, himlDst
->cy
,
710 himlSrc
->hdcImage
, ptSrc
.x
, ptSrc
.y
, himlSrc
->cx
, himlSrc
->cy
,
713 StretchBlt (himlDst
->hdcMask
, ptDst
.x
, ptDst
.y
, himlDst
->cx
, himlDst
->cy
,
714 himlSrc
->hdcMask
, ptSrc
.x
, ptSrc
.y
, himlSrc
->cx
, himlSrc
->cy
,
717 /* copy (without stretching) temporary bitmaps to source (restore) */
719 BitBlt (himlSrc
->hdcMask
, ptSrc
.x
, ptSrc
.y
, himlSrc
->cx
, himlSrc
->cy
,
720 hdcBmp
, 0, 0, SRCCOPY
);
723 BitBlt (himlSrc
->hdcImage
, ptSrc
.x
, ptSrc
.y
, himlSrc
->cx
, himlSrc
->cy
,
724 hdcBmp
, 0, 0, SRCCOPY
);
725 /* delete temporary bitmaps */
726 DeleteObject (hbmTempMask
);
727 DeleteObject (hbmTempImage
);
732 StretchBlt (himlDst
->hdcImage
, ptDst
.x
, ptDst
.y
, himlDst
->cx
, himlDst
->cy
,
733 himlSrc
->hdcImage
, ptSrc
.x
, ptSrc
.y
, himlSrc
->cx
, himlSrc
->cy
,
737 StretchBlt (himlDst
->hdcMask
, ptDst
.x
, ptDst
.y
, himlDst
->cx
, himlDst
->cy
,
738 himlSrc
->hdcMask
, ptSrc
.x
, ptSrc
.y
, himlSrc
->cx
, himlSrc
->cy
,
746 /*************************************************************************
747 * ImageList_Create [COMCTL32.@]
749 * Creates a new image list.
752 * cx [I] image height
754 * flags [I] creation flags
755 * cInitial [I] initial number of images in the image list
756 * cGrow [I] number of images by which image list grows
759 * Success: Handle to the created image list
763 ImageList_Create (INT cx
, INT cy
, UINT flags
,
764 INT cInitial
, INT cGrow
)
768 TRACE("(%d %d 0x%x %d %d)\n", cx
, cy
, flags
, cInitial
, cGrow
);
770 /* Create the IImageList interface for the image list */
771 if (FAILED(ImageListImpl_CreateInstance(NULL
, &IID_IImageList2
, (void **)&himl
)))
774 if (IImageList2_Initialize(himl
, cx
, cy
, flags
, cInitial
, cGrow
) == S_OK
)
775 return (HIMAGELIST
)himl
;
777 IImageList2_Release(himl
);
782 /*************************************************************************
783 * ImageList_Destroy [COMCTL32.@]
785 * Destroys an image list.
788 * himl [I] handle to image list
796 ImageList_Destroy (HIMAGELIST himl
)
801 IImageList_Release((IImageList
*) himl
);
806 /*************************************************************************
807 * ImageList_DragEnter [COMCTL32.@]
809 * Locks window update and displays the drag image at the given position.
812 * hwndLock [I] handle of the window that owns the drag image.
813 * x [I] X position of the drag image.
814 * y [I] Y position of the drag image.
821 * The position of the drag image is relative to the window, not
826 ImageList_DragEnter (HWND hwndLock
, INT x
, INT y
)
828 TRACE("(hwnd=%p x=%d y=%d)\n", hwndLock
, x
, y
);
830 if (!is_valid(InternalDrag
.himl
))
834 InternalDrag
.hwnd
= hwndLock
;
836 InternalDrag
.hwnd
= GetDesktopWindow ();
841 /* draw the drag image and save the background */
842 return ImageList_DragShowNolock(TRUE
);
846 /*************************************************************************
847 * ImageList_DragLeave [COMCTL32.@]
849 * Unlocks window update and hides the drag image.
852 * hwndLock [I] handle of the window that owns the drag image.
860 ImageList_DragLeave (HWND hwndLock
)
862 /* As we don't save drag info in the window this can lead to problems if
863 an app does not supply the same window as DragEnter */
865 InternalDrag.hwnd = hwndLock;
867 InternalDrag.hwnd = GetDesktopWindow (); */
869 hwndLock
= GetDesktopWindow();
870 if(InternalDrag
.hwnd
!= hwndLock
)
871 FIXME("DragLeave hWnd != DragEnter hWnd\n");
873 ImageList_DragShowNolock (FALSE
);
879 /*************************************************************************
880 * ImageList_InternalDragDraw [Internal]
882 * Draws the drag image.
885 * hdc [I] device context to draw into.
886 * x [I] X position of the drag image.
887 * y [I] Y position of the drag image.
894 * The position of the drag image is relative to the window, not
900 ImageList_InternalDragDraw (HDC hdc
, INT x
, INT y
)
902 IMAGELISTDRAWPARAMS imldp
;
904 ZeroMemory (&imldp
, sizeof(imldp
));
905 imldp
.cbSize
= sizeof(imldp
);
906 imldp
.himl
= InternalDrag
.himl
;
911 imldp
.rgbBk
= CLR_DEFAULT
;
912 imldp
.rgbFg
= CLR_DEFAULT
;
913 imldp
.fStyle
= ILD_NORMAL
;
914 imldp
.fState
= ILS_ALPHA
;
916 ImageList_DrawIndirect (&imldp
);
919 /*************************************************************************
920 * ImageList_DragMove [COMCTL32.@]
922 * Moves the drag image.
925 * x [I] X position of the drag image.
926 * y [I] Y position of the drag image.
933 * The position of the drag image is relative to the window, not
938 ImageList_DragMove (INT x
, INT y
)
940 TRACE("(x=%d y=%d)\n", x
, y
);
942 if (!is_valid(InternalDrag
.himl
))
945 /* draw/update the drag image */
946 if (InternalDrag
.bShow
) {
950 HBITMAP hbmOffScreen
;
951 INT origNewX
, origNewY
;
952 INT origOldX
, origOldY
;
953 INT origRegX
, origRegY
;
954 INT sizeRegX
, sizeRegY
;
957 /* calculate the update region */
958 origNewX
= x
- InternalDrag
.dxHotspot
;
959 origNewY
= y
- InternalDrag
.dyHotspot
;
960 origOldX
= InternalDrag
.x
- InternalDrag
.dxHotspot
;
961 origOldY
= InternalDrag
.y
- InternalDrag
.dyHotspot
;
962 origRegX
= min(origNewX
, origOldX
);
963 origRegY
= min(origNewY
, origOldY
);
964 sizeRegX
= InternalDrag
.himl
->cx
+ abs(x
- InternalDrag
.x
);
965 sizeRegY
= InternalDrag
.himl
->cy
+ abs(y
- InternalDrag
.y
);
967 hdcDrag
= GetDCEx(InternalDrag
.hwnd
, 0,
968 DCX_WINDOW
| DCX_CACHE
| DCX_LOCKWINDOWUPDATE
);
969 hdcOffScreen
= CreateCompatibleDC(hdcDrag
);
970 hdcBg
= CreateCompatibleDC(hdcDrag
);
972 hbmOffScreen
= CreateCompatibleBitmap(hdcDrag
, sizeRegX
, sizeRegY
);
973 SelectObject(hdcOffScreen
, hbmOffScreen
);
974 SelectObject(hdcBg
, InternalDrag
.hbmBg
);
976 /* get the actual background of the update region */
977 BitBlt(hdcOffScreen
, 0, 0, sizeRegX
, sizeRegY
, hdcDrag
,
978 origRegX
, origRegY
, SRCCOPY
);
979 /* erase the old image */
980 BitBlt(hdcOffScreen
, origOldX
- origRegX
, origOldY
- origRegY
,
981 InternalDrag
.himl
->cx
, InternalDrag
.himl
->cy
, hdcBg
, 0, 0,
983 /* save the background */
984 BitBlt(hdcBg
, 0, 0, InternalDrag
.himl
->cx
, InternalDrag
.himl
->cy
,
985 hdcOffScreen
, origNewX
- origRegX
, origNewY
- origRegY
, SRCCOPY
);
987 ImageList_InternalDragDraw(hdcOffScreen
, origNewX
- origRegX
,
988 origNewY
- origRegY
);
989 /* draw the update region to the screen */
990 BitBlt(hdcDrag
, origRegX
, origRegY
, sizeRegX
, sizeRegY
,
991 hdcOffScreen
, 0, 0, SRCCOPY
);
994 DeleteDC(hdcOffScreen
);
995 DeleteObject(hbmOffScreen
);
996 ReleaseDC(InternalDrag
.hwnd
, hdcDrag
);
999 /* update the image position */
1007 /*************************************************************************
1008 * ImageList_DragShowNolock [COMCTL32.@]
1010 * Shows or hides the drag image.
1013 * bShow [I] TRUE shows the drag image, FALSE hides it.
1021 ImageList_DragShowNolock (BOOL bShow
)
1027 if (!is_valid(InternalDrag
.himl
))
1030 TRACE("bShow=0x%X!\n", bShow
);
1032 /* DragImage is already visible/hidden */
1033 if ((InternalDrag
.bShow
&& bShow
) || (!InternalDrag
.bShow
&& !bShow
)) {
1037 /* position of the origin of the DragImage */
1038 x
= InternalDrag
.x
- InternalDrag
.dxHotspot
;
1039 y
= InternalDrag
.y
- InternalDrag
.dyHotspot
;
1041 hdcDrag
= GetDCEx (InternalDrag
.hwnd
, 0,
1042 DCX_WINDOW
| DCX_CACHE
| DCX_LOCKWINDOWUPDATE
);
1047 hdcBg
= CreateCompatibleDC(hdcDrag
);
1048 if (!InternalDrag
.hbmBg
) {
1049 InternalDrag
.hbmBg
= CreateCompatibleBitmap(hdcDrag
,
1050 InternalDrag
.himl
->cx
, InternalDrag
.himl
->cy
);
1052 SelectObject(hdcBg
, InternalDrag
.hbmBg
);
1055 /* save the background */
1056 BitBlt(hdcBg
, 0, 0, InternalDrag
.himl
->cx
, InternalDrag
.himl
->cy
,
1057 hdcDrag
, x
, y
, SRCCOPY
);
1058 /* show the image */
1059 ImageList_InternalDragDraw(hdcDrag
, x
, y
);
1061 /* hide the image */
1062 BitBlt(hdcDrag
, x
, y
, InternalDrag
.himl
->cx
, InternalDrag
.himl
->cy
,
1063 hdcBg
, 0, 0, SRCCOPY
);
1066 InternalDrag
.bShow
= !InternalDrag
.bShow
;
1069 ReleaseDC (InternalDrag
.hwnd
, hdcDrag
);
1074 /*************************************************************************
1075 * ImageList_Draw [COMCTL32.@]
1080 * himl [I] handle to image list
1082 * hdc [I] handle to device context
1085 * fStyle [I] drawing flags
1096 ImageList_Draw (HIMAGELIST himl
, INT i
, HDC hdc
, INT x
, INT y
, UINT fStyle
)
1098 return ImageList_DrawEx (himl
, i
, hdc
, x
, y
, 0, 0,
1099 CLR_DEFAULT
, CLR_DEFAULT
, fStyle
);
1103 /*************************************************************************
1104 * ImageList_DrawEx [COMCTL32.@]
1106 * Draws an image and allows using extended drawing features.
1109 * himl [I] handle to image list
1111 * hdc [I] handle to device context
1116 * rgbBk [I] background color
1117 * rgbFg [I] foreground color
1118 * fStyle [I] drawing flags
1125 * Calls ImageList_DrawIndirect.
1128 * ImageList_DrawIndirect.
1132 ImageList_DrawEx (HIMAGELIST himl
, INT i
, HDC hdc
, INT x
, INT y
,
1133 INT dx
, INT dy
, COLORREF rgbBk
, COLORREF rgbFg
,
1136 IMAGELISTDRAWPARAMS imldp
;
1138 ZeroMemory (&imldp
, sizeof(imldp
));
1139 imldp
.cbSize
= sizeof(imldp
);
1147 imldp
.rgbBk
= rgbBk
;
1148 imldp
.rgbFg
= rgbFg
;
1149 imldp
.fStyle
= fStyle
;
1151 return ImageList_DrawIndirect (&imldp
);
1155 static BOOL
alpha_blend_image( HIMAGELIST himl
, HDC dest_dc
, int dest_x
, int dest_y
,
1156 int src_x
, int src_y
, int cx
, int cy
, UINT style
, UINT state
,
1157 DWORD frame
, COLORREF blend_col
, BOOL has_alpha
)
1161 HBITMAP bmp
= 0, mask
= 0;
1164 void *bits
, *mask_bits
;
1168 func
.BlendOp
= AC_SRC_OVER
;
1169 func
.BlendFlags
= 0;
1170 func
.SourceConstantAlpha
= 255;
1171 func
.AlphaFormat
= AC_SRC_ALPHA
;
1173 if (!(hdc
= CreateCompatibleDC( 0 ))) return FALSE
;
1174 if (!(info
= Alloc( FIELD_OFFSET( BITMAPINFO
, bmiColors
[256] )))) goto done
;
1175 info
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
1176 info
->bmiHeader
.biWidth
= cx
;
1177 info
->bmiHeader
.biHeight
= cy
;
1178 info
->bmiHeader
.biPlanes
= 1;
1179 info
->bmiHeader
.biBitCount
= 32;
1180 info
->bmiHeader
.biCompression
= BI_RGB
;
1181 info
->bmiHeader
.biSizeImage
= cx
* cy
* 4;
1182 info
->bmiHeader
.biXPelsPerMeter
= 0;
1183 info
->bmiHeader
.biYPelsPerMeter
= 0;
1184 info
->bmiHeader
.biClrUsed
= 0;
1185 info
->bmiHeader
.biClrImportant
= 0;
1186 if (!(bmp
= CreateDIBSection( himl
->hdcImage
, info
, DIB_RGB_COLORS
, &bits
, 0, 0 ))) goto done
;
1187 SelectObject( hdc
, bmp
);
1188 BitBlt( hdc
, 0, 0, cx
, cy
, himl
->hdcImage
, src_x
, src_y
, SRCCOPY
);
1190 if (blend_col
!= CLR_NONE
)
1192 BYTE r
= GetRValue( blend_col
);
1193 BYTE g
= GetGValue( blend_col
);
1194 BYTE b
= GetBValue( blend_col
);
1196 if (style
& ILD_BLEND25
)
1198 for (i
= 0, ptr
= bits
; i
< cx
* cy
; i
++, ptr
++)
1199 *ptr
= ((*ptr
& 0xff000000) |
1200 ((((*ptr
& 0x00ff0000) * 3 + (r
<< 16)) / 4) & 0x00ff0000) |
1201 ((((*ptr
& 0x0000ff00) * 3 + (g
<< 8)) / 4) & 0x0000ff00) |
1202 ((((*ptr
& 0x000000ff) * 3 + (b
<< 0)) / 4) & 0x000000ff));
1204 else if (style
& ILD_BLEND50
)
1206 for (i
= 0, ptr
= bits
; i
< cx
* cy
; i
++, ptr
++)
1207 *ptr
= ((*ptr
& 0xff000000) |
1208 ((((*ptr
& 0x00ff0000) + (r
<< 16)) / 2) & 0x00ff0000) |
1209 ((((*ptr
& 0x0000ff00) + (g
<< 8)) / 2) & 0x0000ff00) |
1210 ((((*ptr
& 0x000000ff) + (b
<< 0)) / 2) & 0x000000ff));
1215 if (state
& ILS_ALPHA
)
1217 func
.SourceConstantAlpha
= (BYTE
)frame
;
1219 else if (state
& ILS_SATURATE
)
1221 for (i
= 0, ptr
= bits
; i
< cx
* cy
; i
++, ptr
++)
1223 DWORD gray
= (((*ptr
& 0x00ff0000) >> 16) * 299 +
1224 ((*ptr
& 0x0000ff00) >> 8) * 587 +
1225 ((*ptr
& 0x000000ff) >> 0) * 114 + 500) / 1000;
1226 if (has_alpha
) gray
= gray
* (*ptr
>> 24) / 255;
1227 *ptr
= (*ptr
& 0xff000000)| (gray
<< 16) | (gray
<< 8) | gray
;
1230 else if (style
& ILD_PRESERVEALPHA
)
1232 HBRUSH old_brush
= SelectObject( dest_dc
, GetStockObject(BLACK_BRUSH
) );
1233 PatBlt( dest_dc
, dest_x
, dest_y
, cx
, cy
, PATCOPY
);
1234 SelectObject( dest_dc
, old_brush
);
1237 if (has_alpha
) /* we already have an alpha channel in this case */
1239 /* pre-multiply by the alpha channel */
1240 for (i
= 0, ptr
= bits
; i
< cx
* cy
; i
++, ptr
++)
1242 DWORD alpha
= *ptr
>> 24;
1243 *ptr
= ((*ptr
& 0xff000000) |
1244 (((*ptr
& 0x00ff0000) * alpha
/ 255) & 0x00ff0000) |
1245 (((*ptr
& 0x0000ff00) * alpha
/ 255) & 0x0000ff00) |
1246 (((*ptr
& 0x000000ff) * alpha
/ 255)));
1249 else if (himl
->hbmMask
)
1251 unsigned int width_bytes
= (cx
+ 31) / 32 * 4;
1252 /* generate alpha channel from the mask */
1253 info
->bmiHeader
.biBitCount
= 1;
1254 info
->bmiHeader
.biSizeImage
= width_bytes
* cy
;
1255 info
->bmiColors
[0].rgbRed
= 0;
1256 info
->bmiColors
[0].rgbGreen
= 0;
1257 info
->bmiColors
[0].rgbBlue
= 0;
1258 info
->bmiColors
[0].rgbReserved
= 0;
1259 info
->bmiColors
[1].rgbRed
= 0xff;
1260 info
->bmiColors
[1].rgbGreen
= 0xff;
1261 info
->bmiColors
[1].rgbBlue
= 0xff;
1262 info
->bmiColors
[1].rgbReserved
= 0;
1263 if (!(mask
= CreateDIBSection( himl
->hdcMask
, info
, DIB_RGB_COLORS
, &mask_bits
, 0, 0 )))
1265 SelectObject( hdc
, mask
);
1266 BitBlt( hdc
, 0, 0, cx
, cy
, himl
->hdcMask
, src_x
, src_y
, SRCCOPY
);
1267 SelectObject( hdc
, bmp
);
1268 for (i
= 0, ptr
= bits
; i
< cy
; i
++)
1269 for (j
= 0; j
< cx
; j
++, ptr
++)
1270 if ((((BYTE
*)mask_bits
)[i
* width_bytes
+ j
/ 8] << (j
% 8)) & 0x80) *ptr
= 0;
1271 else *ptr
|= 0xff000000;
1275 for (i
= 0, ptr
= bits
; i
< cx
* cy
; i
++, ptr
++)
1279 ret
= GdiAlphaBlend( dest_dc
, dest_x
, dest_y
, cx
, cy
, hdc
, 0, 0, cx
, cy
, func
);
1283 if (bmp
) DeleteObject( bmp
);
1284 if (mask
) DeleteObject( mask
);
1289 /*************************************************************************
1290 * ImageList_DrawIndirect [COMCTL32.@]
1292 * Draws an image using various parameters specified in pimldp.
1295 * pimldp [I] pointer to IMAGELISTDRAWPARAMS structure.
1303 ImageList_DrawIndirect (IMAGELISTDRAWPARAMS
*pimldp
)
1305 INT cx
, cy
, nOvlIdx
;
1306 DWORD fState
, dwRop
;
1308 COLORREF oldImageBk
, oldImageFg
;
1309 HDC hImageDC
, hImageListDC
, hMaskListDC
;
1310 HBITMAP hImageBmp
, hOldImageBmp
, hBlendMaskBmp
;
1311 BOOL bIsTransparent
, bBlend
, bResult
= FALSE
, bMask
;
1317 if (!pimldp
|| !(himl
= pimldp
->himl
)) return FALSE
;
1318 if (!is_valid(himl
)) return FALSE
;
1319 if ((pimldp
->i
< 0) || (pimldp
->i
>= himl
->cCurImage
)) return FALSE
;
1321 imagelist_point_from_index( himl
, pimldp
->i
, &pt
);
1322 pt
.x
+= pimldp
->xBitmap
;
1323 pt
.y
+= pimldp
->yBitmap
;
1325 fState
= pimldp
->cbSize
< sizeof(IMAGELISTDRAWPARAMS
) ? ILS_NORMAL
: pimldp
->fState
;
1326 fStyle
= pimldp
->fStyle
& ~ILD_OVERLAYMASK
;
1327 cx
= (pimldp
->cx
== 0) ? himl
->cx
: pimldp
->cx
;
1328 cy
= (pimldp
->cy
== 0) ? himl
->cy
: pimldp
->cy
;
1330 bIsTransparent
= (fStyle
& ILD_TRANSPARENT
);
1331 if( pimldp
->rgbBk
== CLR_NONE
)
1332 bIsTransparent
= TRUE
;
1333 if( ( pimldp
->rgbBk
== CLR_DEFAULT
) && ( himl
->clrBk
== CLR_NONE
) )
1334 bIsTransparent
= TRUE
;
1335 bMask
= (himl
->flags
& ILC_MASK
) && (fStyle
& ILD_MASK
) ;
1336 bBlend
= (fStyle
& (ILD_BLEND25
| ILD_BLEND50
) ) && !bMask
;
1338 TRACE("himl(%p) hbmMask(%p) iImage(%d) x(%d) y(%d) cx(%d) cy(%d)\n",
1339 himl
, himl
->hbmMask
, pimldp
->i
, pimldp
->x
, pimldp
->y
, cx
, cy
);
1341 /* we will use these DCs to access the images and masks in the ImageList */
1342 hImageListDC
= himl
->hdcImage
;
1343 hMaskListDC
= himl
->hdcMask
;
1345 /* these will accumulate the image and mask for the image we're drawing */
1346 hImageDC
= CreateCompatibleDC( pimldp
->hdcDst
);
1347 hImageBmp
= CreateCompatibleBitmap( pimldp
->hdcDst
, cx
, cy
);
1348 hBlendMaskBmp
= bBlend
? CreateBitmap(cx
, cy
, 1, 1, NULL
) : 0;
1350 /* Create a compatible DC. */
1351 if (!hImageListDC
|| !hImageDC
|| !hImageBmp
||
1352 (bBlend
&& !hBlendMaskBmp
) || (himl
->hbmMask
&& !hMaskListDC
))
1355 hOldImageBmp
= SelectObject(hImageDC
, hImageBmp
);
1358 * To obtain a transparent look, background color should be set
1359 * to white and foreground color to black when blitting the
1362 oldImageFg
= SetTextColor( hImageDC
, RGB( 0, 0, 0 ) );
1363 oldImageBk
= SetBkColor( hImageDC
, RGB( 0xff, 0xff, 0xff ) );
1365 has_alpha
= himl
->item_flags
[pimldp
->i
] & ILIF_ALPHA
;
1366 if (!bMask
&& (has_alpha
|| (fState
& ILS_ALPHA
) || (fState
& ILS_SATURATE
)))
1368 COLORREF colour
, blend_col
= CLR_NONE
;
1372 blend_col
= pimldp
->rgbFg
;
1373 if (blend_col
== CLR_DEFAULT
) blend_col
= GetSysColor( COLOR_HIGHLIGHT
);
1374 else if (blend_col
== CLR_NONE
) blend_col
= GetTextColor( pimldp
->hdcDst
);
1379 bResult
= alpha_blend_image( himl
, pimldp
->hdcDst
, pimldp
->x
, pimldp
->y
, pt
.x
, pt
.y
, cx
, cy
,
1380 fStyle
, fState
, pimldp
->Frame
, blend_col
, has_alpha
);
1383 colour
= pimldp
->rgbBk
;
1384 if (colour
== CLR_DEFAULT
) colour
= himl
->clrBk
;
1385 if (colour
== CLR_NONE
) colour
= GetBkColor( pimldp
->hdcDst
);
1387 hOldBrush
= SelectObject (hImageDC
, CreateSolidBrush (colour
));
1388 PatBlt( hImageDC
, 0, 0, cx
, cy
, PATCOPY
);
1389 alpha_blend_image( himl
, hImageDC
, 0, 0, pt
.x
, pt
.y
, cx
, cy
, fStyle
, fState
,
1390 pimldp
->Frame
, blend_col
, has_alpha
);
1391 DeleteObject (SelectObject (hImageDC
, hOldBrush
));
1392 bResult
= BitBlt( pimldp
->hdcDst
, pimldp
->x
, pimldp
->y
, cx
, cy
, hImageDC
, 0, 0, SRCCOPY
);
1397 * Draw the initial image
1400 if (himl
->hbmMask
) {
1401 hOldBrush
= SelectObject (hImageDC
, CreateSolidBrush (GetTextColor(pimldp
->hdcDst
)));
1402 PatBlt( hImageDC
, 0, 0, cx
, cy
, PATCOPY
);
1403 BitBlt(hImageDC
, 0, 0, cx
, cy
, hMaskListDC
, pt
.x
, pt
.y
, SRCPAINT
);
1404 DeleteObject (SelectObject (hImageDC
, hOldBrush
));
1405 if( bIsTransparent
)
1407 BitBlt ( pimldp
->hdcDst
, pimldp
->x
, pimldp
->y
, cx
, cy
, hImageDC
, 0, 0, SRCAND
);
1412 hOldBrush
= SelectObject (hImageDC
, GetStockObject(BLACK_BRUSH
));
1413 PatBlt( hImageDC
, 0, 0, cx
, cy
, PATCOPY
);
1414 SelectObject(hImageDC
, hOldBrush
);
1417 /* blend the image with the needed solid background */
1418 COLORREF colour
= RGB(0,0,0);
1420 if( !bIsTransparent
)
1422 colour
= pimldp
->rgbBk
;
1423 if( colour
== CLR_DEFAULT
)
1424 colour
= himl
->clrBk
;
1425 if( colour
== CLR_NONE
)
1426 colour
= GetBkColor(pimldp
->hdcDst
);
1429 hOldBrush
= SelectObject (hImageDC
, CreateSolidBrush (colour
));
1430 PatBlt( hImageDC
, 0, 0, cx
, cy
, PATCOPY
);
1433 BitBlt( hImageDC
, 0, 0, cx
, cy
, hMaskListDC
, pt
.x
, pt
.y
, SRCAND
);
1434 BitBlt( hImageDC
, 0, 0, cx
, cy
, hImageListDC
, pt
.x
, pt
.y
, SRCPAINT
);
1437 BitBlt( hImageDC
, 0, 0, cx
, cy
, hImageListDC
, pt
.x
, pt
.y
, SRCCOPY
);
1438 DeleteObject (SelectObject (hImageDC
, hOldBrush
));
1441 /* Time for blending, if required */
1444 COLORREF clrBlend
= pimldp
->rgbFg
;
1445 HDC hBlendMaskDC
= hImageListDC
;
1448 /* Create the blend Mask */
1449 hOldBitmap
= SelectObject(hBlendMaskDC
, hBlendMaskBmp
);
1450 hBlendBrush
= fStyle
& ILD_BLEND50
? himl
->hbrBlend50
: himl
->hbrBlend25
;
1451 hOldBrush
= SelectObject(hBlendMaskDC
, hBlendBrush
);
1452 PatBlt(hBlendMaskDC
, 0, 0, cx
, cy
, PATCOPY
);
1453 SelectObject(hBlendMaskDC
, hOldBrush
);
1455 /* Modify the blend mask if an Image Mask exist */
1457 BitBlt(hBlendMaskDC
, 0, 0, cx
, cy
, hMaskListDC
, pt
.x
, pt
.y
, 0x220326); /* NOTSRCAND */
1458 BitBlt(hBlendMaskDC
, 0, 0, cx
, cy
, hBlendMaskDC
, 0, 0, NOTSRCCOPY
);
1461 /* now apply blend to the current image given the BlendMask */
1462 if (clrBlend
== CLR_DEFAULT
) clrBlend
= GetSysColor (COLOR_HIGHLIGHT
);
1463 else if (clrBlend
== CLR_NONE
) clrBlend
= GetTextColor (pimldp
->hdcDst
);
1464 hOldBrush
= SelectObject (hImageDC
, CreateSolidBrush(clrBlend
));
1465 BitBlt (hImageDC
, 0, 0, cx
, cy
, hBlendMaskDC
, 0, 0, 0xB8074A); /* PSDPxax */
1466 DeleteObject(SelectObject(hImageDC
, hOldBrush
));
1467 SelectObject(hBlendMaskDC
, hOldBitmap
);
1470 /* Now do the overlay image, if any */
1471 nOvlIdx
= (pimldp
->fStyle
& ILD_OVERLAYMASK
) >> 8;
1472 if ( (nOvlIdx
>= 1) && (nOvlIdx
<= MAX_OVERLAYIMAGE
)) {
1473 nOvlIdx
= himl
->nOvlIdx
[nOvlIdx
- 1];
1474 if ((nOvlIdx
>= 0) && (nOvlIdx
< himl
->cCurImage
)) {
1476 imagelist_point_from_index( himl
, nOvlIdx
, &ptOvl
);
1477 ptOvl
.x
+= pimldp
->xBitmap
;
1478 if (himl
->hbmMask
&& !(fStyle
& ILD_IMAGE
))
1479 BitBlt (hImageDC
, 0, 0, cx
, cy
, hMaskListDC
, ptOvl
.x
, ptOvl
.y
, SRCAND
);
1480 BitBlt (hImageDC
, 0, 0, cx
, cy
, hImageListDC
, ptOvl
.x
, ptOvl
.y
, SRCPAINT
);
1484 if (fState
& ILS_GLOW
) FIXME("ILS_GLOW: unimplemented!\n");
1485 if (fState
& ILS_SHADOW
) FIXME("ILS_SHADOW: unimplemented!\n");
1487 if (fStyle
& ILD_SCALE
) FIXME("ILD_SCALE: unimplemented!\n");
1488 if (fStyle
& ILD_DPISCALE
) FIXME("ILD_DPISCALE: unimplemented!\n");
1490 /* now copy the image to the screen */
1492 if (himl
->hbmMask
&& bIsTransparent
) {
1493 COLORREF oldDstFg
= SetTextColor(pimldp
->hdcDst
, RGB( 0, 0, 0 ) );
1494 COLORREF oldDstBk
= SetBkColor(pimldp
->hdcDst
, RGB( 0xff, 0xff, 0xff ));
1495 BitBlt (pimldp
->hdcDst
, pimldp
->x
, pimldp
->y
, cx
, cy
, hMaskListDC
, pt
.x
, pt
.y
, SRCAND
);
1496 SetBkColor(pimldp
->hdcDst
, oldDstBk
);
1497 SetTextColor(pimldp
->hdcDst
, oldDstFg
);
1500 if (fStyle
& ILD_ROP
) dwRop
= pimldp
->dwRop
;
1501 BitBlt (pimldp
->hdcDst
, pimldp
->x
, pimldp
->y
, cx
, cy
, hImageDC
, 0, 0, dwRop
);
1505 /* cleanup the mess */
1506 SetBkColor(hImageDC
, oldImageBk
);
1507 SetTextColor(hImageDC
, oldImageFg
);
1508 SelectObject(hImageDC
, hOldImageBmp
);
1510 DeleteObject(hBlendMaskBmp
);
1511 DeleteObject(hImageBmp
);
1518 /*************************************************************************
1519 * ImageList_Duplicate [COMCTL32.@]
1521 * Duplicates an image list.
1524 * himlSrc [I] source image list handle
1527 * Success: Handle of duplicated image list.
1532 ImageList_Duplicate (HIMAGELIST himlSrc
)
1536 if (!is_valid(himlSrc
)) {
1537 ERR("Invalid image list handle!\n");
1541 himlDst
= ImageList_Create (himlSrc
->cx
, himlSrc
->cy
, himlSrc
->flags
,
1542 himlSrc
->cCurImage
, himlSrc
->cGrow
);
1548 imagelist_get_bitmap_size(himlSrc
, himlSrc
->cCurImage
, &sz
);
1549 BitBlt (himlDst
->hdcImage
, 0, 0, sz
.cx
, sz
.cy
,
1550 himlSrc
->hdcImage
, 0, 0, SRCCOPY
);
1552 if (himlDst
->hbmMask
)
1553 BitBlt (himlDst
->hdcMask
, 0, 0, sz
.cx
, sz
.cy
,
1554 himlSrc
->hdcMask
, 0, 0, SRCCOPY
);
1556 himlDst
->cCurImage
= himlSrc
->cCurImage
;
1557 memcpy( himlDst
->item_flags
, himlSrc
->item_flags
, himlDst
->cCurImage
* sizeof(*himlDst
->item_flags
) );
1563 /*************************************************************************
1564 * ImageList_EndDrag [COMCTL32.@]
1566 * Finishes a drag operation.
1577 ImageList_EndDrag (void)
1579 /* cleanup the InternalDrag struct */
1580 InternalDrag
.hwnd
= 0;
1581 if (InternalDrag
.himl
!= InternalDrag
.himlNoCursor
)
1582 ImageList_Destroy (InternalDrag
.himlNoCursor
);
1583 ImageList_Destroy (InternalDrag
.himl
);
1584 InternalDrag
.himlNoCursor
= InternalDrag
.himl
= 0;
1587 InternalDrag
.dxHotspot
= 0;
1588 InternalDrag
.dyHotspot
= 0;
1589 InternalDrag
.bShow
= FALSE
;
1590 DeleteObject(InternalDrag
.hbmBg
);
1591 InternalDrag
.hbmBg
= 0;
1595 /*************************************************************************
1596 * ImageList_GetBkColor [COMCTL32.@]
1598 * Returns the background color of an image list.
1601 * himl [I] Image list handle.
1604 * Success: background color
1609 ImageList_GetBkColor (HIMAGELIST himl
)
1611 return himl
? himl
->clrBk
: CLR_NONE
;
1615 /*************************************************************************
1616 * ImageList_GetDragImage [COMCTL32.@]
1618 * Returns the handle to the internal drag image list.
1621 * ppt [O] Pointer to the drag position. Can be NULL.
1622 * pptHotspot [O] Pointer to the position of the hot spot. Can be NULL.
1625 * Success: Handle of the drag image list.
1630 ImageList_GetDragImage (POINT
*ppt
, POINT
*pptHotspot
)
1632 if (is_valid(InternalDrag
.himl
)) {
1634 ppt
->x
= InternalDrag
.x
;
1635 ppt
->y
= InternalDrag
.y
;
1638 pptHotspot
->x
= InternalDrag
.dxHotspot
;
1639 pptHotspot
->y
= InternalDrag
.dyHotspot
;
1641 return (InternalDrag
.himl
);
1648 /*************************************************************************
1649 * ImageList_GetFlags [COMCTL32.@]
1651 * Gets the flags of the specified image list.
1654 * himl [I] Handle to image list
1664 ImageList_GetFlags(HIMAGELIST himl
)
1666 TRACE("%p\n", himl
);
1668 return is_valid(himl
) ? himl
->flags
: 0;
1672 /*************************************************************************
1673 * ImageList_GetIcon [COMCTL32.@]
1675 * Creates an icon from a masked image of an image list.
1678 * himl [I] handle to image list
1680 * flags [I] drawing style flags
1683 * Success: icon handle
1688 ImageList_GetIcon (HIMAGELIST himl
, INT i
, UINT fStyle
)
1692 HBITMAP hOldDstBitmap
;
1696 TRACE("%p %d %d\n", himl
, i
, fStyle
);
1697 if (!is_valid(himl
) || (i
< 0) || (i
>= himl
->cCurImage
)) return NULL
;
1703 /* create colour bitmap */
1705 ii
.hbmColor
= CreateCompatibleBitmap(hdcDst
, himl
->cx
, himl
->cy
);
1706 ReleaseDC(0, hdcDst
);
1708 hdcDst
= CreateCompatibleDC(0);
1710 imagelist_point_from_index( himl
, i
, &pt
);
1713 ii
.hbmMask
= CreateBitmap (himl
->cx
, himl
->cy
, 1, 1, NULL
);
1714 hOldDstBitmap
= SelectObject (hdcDst
, ii
.hbmMask
);
1715 if (himl
->hbmMask
) {
1716 BitBlt (hdcDst
, 0, 0, himl
->cx
, himl
->cy
,
1717 himl
->hdcMask
, pt
.x
, pt
.y
, SRCCOPY
);
1720 PatBlt (hdcDst
, 0, 0, himl
->cx
, himl
->cy
, BLACKNESS
);
1723 SelectObject (hdcDst
, ii
.hbmColor
);
1724 BitBlt (hdcDst
, 0, 0, himl
->cx
, himl
->cy
,
1725 himl
->hdcImage
, pt
.x
, pt
.y
, SRCCOPY
);
1728 * CreateIconIndirect requires us to deselect the bitmaps from
1729 * the DCs before calling
1731 SelectObject(hdcDst
, hOldDstBitmap
);
1733 hIcon
= CreateIconIndirect (&ii
);
1735 DeleteObject (ii
.hbmMask
);
1736 DeleteObject (ii
.hbmColor
);
1743 /*************************************************************************
1744 * ImageList_GetIconSize [COMCTL32.@]
1746 * Retrieves the size of an image in an image list.
1749 * himl [I] handle to image list
1750 * cx [O] pointer to the image width.
1751 * cy [O] pointer to the image height.
1758 * All images in an image list have the same size.
1762 ImageList_GetIconSize (HIMAGELIST himl
, INT
*cx
, INT
*cy
)
1764 if (!is_valid(himl
) || !cx
|| !cy
)
1774 /*************************************************************************
1775 * ImageList_GetImageCount [COMCTL32.@]
1777 * Returns the number of images in an image list.
1780 * himl [I] handle to image list
1783 * Success: Number of images.
1788 ImageList_GetImageCount (HIMAGELIST himl
)
1790 if (!is_valid(himl
))
1793 return himl
->cCurImage
;
1797 /*************************************************************************
1798 * ImageList_GetImageInfo [COMCTL32.@]
1800 * Returns information about an image in an image list.
1803 * himl [I] handle to image list
1805 * pImageInfo [O] pointer to the image information
1813 ImageList_GetImageInfo (HIMAGELIST himl
, INT i
, IMAGEINFO
*pImageInfo
)
1817 if (!is_valid(himl
) || (pImageInfo
== NULL
))
1819 if ((i
< 0) || (i
>= himl
->cCurImage
))
1822 pImageInfo
->hbmImage
= himl
->hbmImage
;
1823 pImageInfo
->hbmMask
= himl
->hbmMask
;
1825 imagelist_point_from_index( himl
, i
, &pt
);
1826 pImageInfo
->rcImage
.top
= pt
.y
;
1827 pImageInfo
->rcImage
.bottom
= pt
.y
+ himl
->cy
;
1828 pImageInfo
->rcImage
.left
= pt
.x
;
1829 pImageInfo
->rcImage
.right
= pt
.x
+ himl
->cx
;
1835 /*************************************************************************
1836 * ImageList_GetImageRect [COMCTL32.@]
1838 * Retrieves the rectangle of the specified image in an image list.
1841 * himl [I] handle to image list
1843 * lpRect [O] pointer to the image rectangle
1850 * This is an UNDOCUMENTED function!!!
1854 ImageList_GetImageRect (HIMAGELIST himl
, INT i
, LPRECT lpRect
)
1858 if (!is_valid(himl
) || (lpRect
== NULL
))
1860 if ((i
< 0) || (i
>= himl
->cCurImage
))
1863 imagelist_point_from_index( himl
, i
, &pt
);
1864 lpRect
->left
= pt
.x
;
1866 lpRect
->right
= pt
.x
+ himl
->cx
;
1867 lpRect
->bottom
= pt
.y
+ himl
->cy
;
1873 /*************************************************************************
1874 * ImageList_LoadImage [COMCTL32.@]
1875 * ImageList_LoadImageA [COMCTL32.@]
1877 * Creates an image list from a bitmap, icon or cursor.
1879 * See ImageList_LoadImageW.
1883 ImageList_LoadImageA (HINSTANCE hi
, LPCSTR lpbmp
, INT cx
, INT cGrow
,
1884 COLORREF clrMask
, UINT uType
, UINT uFlags
)
1890 if (IS_INTRESOURCE(lpbmp
))
1891 return ImageList_LoadImageW(hi
, (LPCWSTR
)lpbmp
, cx
, cGrow
, clrMask
,
1894 len
= MultiByteToWideChar(CP_ACP
, 0, lpbmp
, -1, NULL
, 0);
1895 lpbmpW
= Alloc(len
* sizeof(WCHAR
));
1896 MultiByteToWideChar(CP_ACP
, 0, lpbmp
, -1, lpbmpW
, len
);
1898 himl
= ImageList_LoadImageW(hi
, lpbmpW
, cx
, cGrow
, clrMask
, uType
, uFlags
);
1904 /*************************************************************************
1905 * ImageList_LoadImageW [COMCTL32.@]
1907 * Creates an image list from a bitmap, icon or cursor.
1910 * hi [I] instance handle
1911 * lpbmp [I] name or id of the image
1912 * cx [I] width of each image
1913 * cGrow [I] number of images to expand
1914 * clrMask [I] mask color
1915 * uType [I] type of image to load
1916 * uFlags [I] loading flags
1919 * Success: handle to the loaded image list
1927 ImageList_LoadImageW (HINSTANCE hi
, LPCWSTR lpbmp
, INT cx
, INT cGrow
,
1928 COLORREF clrMask
, UINT uType
, UINT uFlags
)
1930 HIMAGELIST himl
= NULL
;
1934 handle
= LoadImageW (hi
, lpbmp
, uType
, 0, 0, uFlags
);
1936 WARN("Couldn't load image\n");
1940 if (uType
== IMAGE_BITMAP
) {
1944 if (GetObjectW (handle
, sizeof(dib
), &dib
) == sizeof(BITMAP
)) color
= ILC_COLOR
;
1945 else color
= dib
.dsBm
.bmBitsPixel
;
1947 /* To match windows behavior, if cx is set to zero and
1948 the flag DI_DEFAULTSIZE is specified, cx becomes the
1949 system metric value for icons. If the flag is not specified
1950 the function sets the size to the height of the bitmap */
1953 if (uFlags
& DI_DEFAULTSIZE
)
1954 cx
= GetSystemMetrics (SM_CXICON
);
1956 cx
= dib
.dsBm
.bmHeight
;
1959 nImageCount
= dib
.dsBm
.bmWidth
/ cx
;
1961 if (clrMask
!= CLR_NONE
) color
|= ILC_MASK
;
1962 himl
= ImageList_Create (cx
, dib
.dsBm
.bmHeight
, color
, nImageCount
, cGrow
);
1964 DeleteObject (handle
);
1967 ImageList_AddMasked (himl
, handle
, clrMask
);
1969 else if ((uType
== IMAGE_ICON
) || (uType
== IMAGE_CURSOR
)) {
1973 GetIconInfo (handle
, &ii
);
1974 GetObjectW (ii
.hbmColor
, sizeof(BITMAP
), &bmp
);
1975 himl
= ImageList_Create (bmp
.bmWidth
, bmp
.bmHeight
,
1976 ILC_MASK
| ILC_COLOR
, 1, cGrow
);
1978 DeleteObject (ii
.hbmColor
);
1979 DeleteObject (ii
.hbmMask
);
1980 DeleteObject (handle
);
1983 ImageList_Add (himl
, ii
.hbmColor
, ii
.hbmMask
);
1984 DeleteObject (ii
.hbmColor
);
1985 DeleteObject (ii
.hbmMask
);
1988 DeleteObject (handle
);
1994 /*************************************************************************
1995 * ImageList_Merge [COMCTL32.@]
1997 * Create an image list containing a merged image from two image lists.
2000 * himl1 [I] handle to first image list
2001 * i1 [I] first image index
2002 * himl2 [I] handle to second image list
2003 * i2 [I] second image index
2004 * dx [I] X offset of the second image relative to the first.
2005 * dy [I] Y offset of the second image relative to the first.
2008 * Success: The newly created image list. It contains a single image
2009 * consisting of the second image merged with the first.
2010 * Failure: NULL, if either himl1 or himl2 is invalid.
2013 * - The returned image list should be deleted by the caller using
2014 * ImageList_Destroy() when it is no longer required.
2015 * - If either i1 or i2 is not a valid image index, they will be treated
2019 ImageList_Merge (HIMAGELIST himl1
, INT i1
, HIMAGELIST himl2
, INT i2
,
2022 HIMAGELIST himlDst
= NULL
;
2024 INT xOff1
, yOff1
, xOff2
, yOff2
;
2028 TRACE("(himl1=%p i1=%d himl2=%p i2=%d dx=%d dy=%d)\n", himl1
, i1
, himl2
,
2031 if (!is_valid(himl1
) || !is_valid(himl2
))
2035 cxDst
= max (himl1
->cx
, dx
+ himl2
->cx
);
2040 cxDst
= max (himl2
->cx
, himl1
->cx
- dx
);
2045 cxDst
= max (himl1
->cx
, himl2
->cx
);
2051 cyDst
= max (himl1
->cy
, dy
+ himl2
->cy
);
2056 cyDst
= max (himl2
->cy
, himl1
->cy
- dy
);
2061 cyDst
= max (himl1
->cy
, himl2
->cy
);
2066 newFlags
= (himl1
->flags
> himl2
->flags
? himl1
->flags
: himl2
->flags
) & ILC_COLORDDB
;
2067 if (newFlags
== ILC_COLORDDB
&& (himl1
->flags
& ILC_COLORDDB
) == ILC_COLOR16
)
2068 newFlags
= ILC_COLOR16
; /* this is what native (at least v5) does, don't know why */
2069 himlDst
= ImageList_Create (cxDst
, cyDst
, ILC_MASK
| newFlags
, 1, 1);
2073 imagelist_point_from_index( himl1
, i1
, &pt1
);
2074 imagelist_point_from_index( himl2
, i2
, &pt2
);
2077 BitBlt (himlDst
->hdcImage
, 0, 0, cxDst
, cyDst
, himl1
->hdcImage
, 0, 0, BLACKNESS
);
2078 if (i1
>= 0 && i1
< himl1
->cCurImage
)
2079 BitBlt (himlDst
->hdcImage
, xOff1
, yOff1
, himl1
->cx
, himl1
->cy
, himl1
->hdcImage
, pt1
.x
, pt1
.y
, SRCCOPY
);
2080 if (i2
>= 0 && i2
< himl2
->cCurImage
)
2082 if (himl2
->flags
& ILC_MASK
)
2084 BitBlt (himlDst
->hdcImage
, xOff2
, yOff2
, himl2
->cx
, himl2
->cy
, himl2
->hdcMask
, pt2
.x
, pt2
.y
, SRCAND
);
2085 BitBlt (himlDst
->hdcImage
, xOff2
, yOff2
, himl2
->cx
, himl2
->cy
, himl2
->hdcImage
, pt2
.x
, pt2
.y
, SRCPAINT
);
2088 BitBlt (himlDst
->hdcImage
, xOff2
, yOff2
, himl2
->cx
, himl2
->cy
, himl2
->hdcImage
, pt2
.x
, pt2
.y
, SRCCOPY
);
2092 BitBlt (himlDst
->hdcMask
, 0, 0, cxDst
, cyDst
, himl1
->hdcMask
, 0, 0, WHITENESS
);
2093 if (i1
>= 0 && i1
< himl1
->cCurImage
)
2094 BitBlt (himlDst
->hdcMask
, xOff1
, yOff1
, himl1
->cx
, himl1
->cy
, himl1
->hdcMask
, pt1
.x
, pt1
.y
, SRCCOPY
);
2095 if (i2
>= 0 && i2
< himl2
->cCurImage
)
2096 BitBlt (himlDst
->hdcMask
, xOff2
, yOff2
, himl2
->cx
, himl2
->cy
, himl2
->hdcMask
, pt2
.x
, pt2
.y
, SRCAND
);
2098 himlDst
->cCurImage
= 1;
2105 /* helper for ImageList_Read, see comments below */
2106 static void *read_bitmap(IStream
*pstm
, BITMAPINFO
*bmi
)
2108 BITMAPFILEHEADER bmfh
;
2109 int bitsperpixel
, palspace
;
2112 if (FAILED(IStream_Read ( pstm
, &bmfh
, sizeof(bmfh
), NULL
)))
2115 if (bmfh
.bfType
!= (('M'<<8)|'B'))
2118 if (FAILED(IStream_Read ( pstm
, &bmi
->bmiHeader
, sizeof(bmi
->bmiHeader
), NULL
)))
2121 if ((bmi
->bmiHeader
.biSize
!= sizeof(bmi
->bmiHeader
)))
2124 TRACE("width %lu, height %lu, planes %u, bpp %u\n",
2125 bmi
->bmiHeader
.biWidth
, bmi
->bmiHeader
.biHeight
,
2126 bmi
->bmiHeader
.biPlanes
, bmi
->bmiHeader
.biBitCount
);
2128 bitsperpixel
= bmi
->bmiHeader
.biPlanes
* bmi
->bmiHeader
.biBitCount
;
2129 if (bitsperpixel
<=8)
2130 palspace
= (1<<bitsperpixel
)*sizeof(RGBQUAD
);
2134 bmi
->bmiHeader
.biSizeImage
= get_dib_image_size( bmi
);
2136 /* read the palette right after the end of the bitmapinfoheader */
2137 if (palspace
&& FAILED(IStream_Read(pstm
, bmi
->bmiColors
, palspace
, NULL
)))
2140 bits
= Alloc(bmi
->bmiHeader
.biSizeImage
);
2141 if (!bits
) return NULL
;
2143 if (FAILED(IStream_Read(pstm
, bits
, bmi
->bmiHeader
.biSizeImage
, NULL
)))
2151 /*************************************************************************
2152 * ImageList_Read [COMCTL32.@]
2154 * Reads an image list from a stream.
2157 * pstm [I] pointer to a stream
2160 * Success: handle to image list
2163 * The format is like this:
2164 * ILHEAD ilheadstruct;
2166 * for the color image part:
2167 * BITMAPFILEHEADER bmfh;
2168 * BITMAPINFOHEADER bmih;
2169 * only if it has a palette:
2170 * RGBQUAD rgbs[nr_of_paletted_colors];
2172 * BYTE colorbits[imagesize];
2174 * the following only if the ILC_MASK bit is set in ILHEAD.ilFlags:
2175 * BITMAPFILEHEADER bmfh_mask;
2176 * BITMAPINFOHEADER bmih_mask;
2177 * only if it has a palette (it usually does not):
2178 * RGBQUAD rgbs[nr_of_paletted_colors];
2180 * BYTE maskbits[imagesize];
2182 HIMAGELIST WINAPI
ImageList_Read(IStream
*pstm
)
2184 char image_buf
[sizeof(BITMAPINFOHEADER
) + sizeof(RGBQUAD
) * 256];
2185 char mask_buf
[sizeof(BITMAPINFOHEADER
) + sizeof(RGBQUAD
) * 256];
2186 BITMAPINFO
*image_info
= (BITMAPINFO
*)image_buf
;
2187 BITMAPINFO
*mask_info
= (BITMAPINFO
*)mask_buf
;
2188 void *image_bits
, *mask_bits
= NULL
;
2193 TRACE("%p\n", pstm
);
2195 if (FAILED(IStream_Read (pstm
, &ilHead
, sizeof(ILHEAD
), NULL
)))
2197 if (ilHead
.usMagic
!= (('L' << 8) | 'I'))
2199 if (ilHead
.usVersion
!= 0x101) /* probably version? */
2202 TRACE("cx %u, cy %u, flags 0x%04x, cCurImage %u, cMaxImage %u\n",
2203 ilHead
.cx
, ilHead
.cy
, ilHead
.flags
, ilHead
.cCurImage
, ilHead
.cMaxImage
);
2205 himl
= ImageList_Create(ilHead
.cx
, ilHead
.cy
, ilHead
.flags
, ilHead
.cMaxImage
, ilHead
.cGrow
);
2209 if (!(image_bits
= read_bitmap(pstm
, image_info
)))
2211 WARN("failed to read bitmap from stream\n");
2214 if (ilHead
.flags
& ILC_MASK
)
2216 if (!(mask_bits
= read_bitmap(pstm
, mask_info
)))
2218 WARN("failed to read mask bitmap from stream\n");
2222 else mask_info
= NULL
;
2224 if ((himl
->flags
& 0xfe) == ILC_COLOR32
&& image_info
->bmiHeader
.biBitCount
== 32)
2226 DWORD
*ptr
= image_bits
;
2227 BYTE
*mask_ptr
= mask_bits
;
2228 int stride
= himl
->cy
* image_info
->bmiHeader
.biWidth
;
2230 if (image_info
->bmiHeader
.biHeight
> 0) /* bottom-up */
2232 ptr
+= image_info
->bmiHeader
.biHeight
* image_info
->bmiHeader
.biWidth
- stride
;
2233 mask_ptr
+= (image_info
->bmiHeader
.biHeight
* image_info
->bmiHeader
.biWidth
- stride
) / 8;
2235 image_info
->bmiHeader
.biHeight
= himl
->cy
;
2237 else image_info
->bmiHeader
.biHeight
= -himl
->cy
;
2239 for (i
= 0; i
< ilHead
.cCurImage
; i
+= TILE_COUNT
)
2241 add_dib_bits( himl
, i
, min( ilHead
.cCurImage
- i
, TILE_COUNT
),
2242 himl
->cx
, himl
->cy
, image_info
, mask_info
, ptr
, mask_ptr
);
2244 mask_ptr
+= stride
/ 8;
2249 StretchDIBits( himl
->hdcImage
, 0, 0, image_info
->bmiHeader
.biWidth
, image_info
->bmiHeader
.biHeight
,
2250 0, 0, image_info
->bmiHeader
.biWidth
, image_info
->bmiHeader
.biHeight
,
2251 image_bits
, image_info
, DIB_RGB_COLORS
, SRCCOPY
);
2253 StretchDIBits( himl
->hdcMask
, 0, 0, mask_info
->bmiHeader
.biWidth
, mask_info
->bmiHeader
.biHeight
,
2254 0, 0, mask_info
->bmiHeader
.biWidth
, mask_info
->bmiHeader
.biHeight
,
2255 mask_bits
, mask_info
, DIB_RGB_COLORS
, SRCCOPY
);
2260 himl
->cCurImage
= ilHead
.cCurImage
;
2261 himl
->cMaxImage
= ilHead
.cMaxImage
;
2263 ImageList_SetBkColor(himl
,ilHead
.bkcolor
);
2265 ImageList_SetOverlayImage(himl
,ilHead
.ovls
[i
],i
+1);
2270 /*************************************************************************
2271 * ImageList_Remove [COMCTL32.@]
2273 * Removes an image from an image list
2276 * himl [I] image list handle
2283 * FIXME: as the image list storage test shows, native comctl32 simply shifts
2284 * images without creating a new bitmap.
2287 ImageList_Remove (HIMAGELIST himl
, INT i
)
2289 HBITMAP hbmNewImage
, hbmNewMask
;
2293 TRACE("(himl=%p i=%d)\n", himl
, i
);
2295 if (!is_valid(himl
)) {
2296 ERR("Invalid image list handle!\n");
2300 if ((i
< -1) || (i
>= himl
->cCurImage
)) {
2301 TRACE("index out of range! %d\n", i
);
2309 if (himl
->cCurImage
== 0) {
2310 /* remove all on empty ImageList is allowed */
2311 TRACE("remove all on empty ImageList!\n");
2315 himl
->cMaxImage
= himl
->cGrow
;
2316 himl
->cCurImage
= 0;
2317 for (nCount
= 0; nCount
< MAX_OVERLAYIMAGE
; nCount
++)
2318 himl
->nOvlIdx
[nCount
] = -1;
2320 Free( himl
->item_flags
);
2321 himl
->item_flags
= Alloc( himl
->cMaxImage
* sizeof(*himl
->item_flags
) );
2323 hbmNewImage
= ImageList_CreateImage(himl
->hdcImage
, himl
, himl
->cMaxImage
);
2324 SelectObject (himl
->hdcImage
, hbmNewImage
);
2325 DeleteObject (himl
->hbmImage
);
2326 himl
->hbmImage
= hbmNewImage
;
2328 if (himl
->hbmMask
) {
2330 imagelist_get_bitmap_size(himl
, himl
->cMaxImage
, &sz
);
2331 hbmNewMask
= CreateBitmap (sz
.cx
, sz
.cy
, 1, 1, NULL
);
2332 SelectObject (himl
->hdcMask
, hbmNewMask
);
2333 DeleteObject (himl
->hbmMask
);
2334 himl
->hbmMask
= hbmNewMask
;
2338 /* delete one image */
2339 TRACE("Remove single image! %d\n", i
);
2341 /* create new bitmap(s) */
2342 TRACE(" - Number of images: %d / %d (Old/New)\n",
2343 himl
->cCurImage
, himl
->cCurImage
- 1);
2345 hbmNewImage
= ImageList_CreateImage(himl
->hdcImage
, himl
, himl
->cMaxImage
);
2347 imagelist_get_bitmap_size(himl
, himl
->cMaxImage
, &sz
);
2349 hbmNewMask
= CreateBitmap (sz
.cx
, sz
.cy
, 1, 1, NULL
);
2351 hbmNewMask
= 0; /* Just to keep compiler happy! */
2353 hdcBmp
= CreateCompatibleDC (0);
2355 /* copy all images and masks prior to the "removed" image */
2357 TRACE("Pre image copy: Copy %d images\n", i
);
2359 SelectObject (hdcBmp
, hbmNewImage
);
2360 imagelist_copy_images( himl
, himl
->hdcImage
, hdcBmp
, 0, i
, 0 );
2362 if (himl
->hbmMask
) {
2363 SelectObject (hdcBmp
, hbmNewMask
);
2364 imagelist_copy_images( himl
, himl
->hdcMask
, hdcBmp
, 0, i
, 0 );
2368 /* copy all images and masks behind the removed image */
2369 if (i
< himl
->cCurImage
- 1) {
2370 TRACE("Post image copy!\n");
2372 SelectObject (hdcBmp
, hbmNewImage
);
2373 imagelist_copy_images( himl
, himl
->hdcImage
, hdcBmp
, i
+ 1,
2374 (himl
->cCurImage
- i
), i
);
2376 if (himl
->hbmMask
) {
2377 SelectObject (hdcBmp
, hbmNewMask
);
2378 imagelist_copy_images( himl
, himl
->hdcMask
, hdcBmp
, i
+ 1,
2379 (himl
->cCurImage
- i
), i
);
2385 /* delete old images and insert new ones */
2386 SelectObject (himl
->hdcImage
, hbmNewImage
);
2387 DeleteObject (himl
->hbmImage
);
2388 himl
->hbmImage
= hbmNewImage
;
2389 if (himl
->hbmMask
) {
2390 SelectObject (himl
->hdcMask
, hbmNewMask
);
2391 DeleteObject (himl
->hbmMask
);
2392 himl
->hbmMask
= hbmNewMask
;
2402 /*************************************************************************
2403 * ImageList_Replace [COMCTL32.@]
2405 * Replaces an image in an image list with a new image.
2408 * himl [I] handle to image list
2410 * hbmImage [I] handle to image bitmap
2411 * hbmMask [I] handle to mask bitmap. Can be NULL.
2419 ImageList_Replace (HIMAGELIST himl
, INT i
, HBITMAP hbmImage
,
2426 TRACE("%p %d %p %p\n", himl
, i
, hbmImage
, hbmMask
);
2428 if (!is_valid(himl
)) {
2429 ERR("Invalid image list handle!\n");
2433 if ((i
>= himl
->cMaxImage
) || (i
< 0)) {
2434 ERR("Invalid image index!\n");
2438 if (!GetObjectW(hbmImage
, sizeof(BITMAP
), &bmp
))
2441 hdcImage
= CreateCompatibleDC (0);
2444 SelectObject (hdcImage
, hbmImage
);
2446 if (add_with_alpha( himl
, hdcImage
, i
, 1, bmp
.bmWidth
, bmp
.bmHeight
, hbmImage
, hbmMask
))
2449 imagelist_point_from_index(himl
, i
, &pt
);
2450 StretchBlt (himl
->hdcImage
, pt
.x
, pt
.y
, himl
->cx
, himl
->cy
,
2451 hdcImage
, 0, 0, bmp
.bmWidth
, bmp
.bmHeight
, SRCCOPY
);
2456 HBITMAP hOldBitmapTemp
;
2458 hdcTemp
= CreateCompatibleDC(0);
2459 hOldBitmapTemp
= SelectObject(hdcTemp
, hbmMask
);
2461 StretchBlt (himl
->hdcMask
, pt
.x
, pt
.y
, himl
->cx
, himl
->cy
,
2462 hdcTemp
, 0, 0, bmp
.bmWidth
, bmp
.bmHeight
, SRCCOPY
);
2463 SelectObject(hdcTemp
, hOldBitmapTemp
);
2466 /* Remove the background from the image
2468 BitBlt (himl
->hdcImage
, pt
.x
, pt
.y
, bmp
.bmWidth
, bmp
.bmHeight
,
2469 himl
->hdcMask
, pt
.x
, pt
.y
, 0x220326); /* NOTSRCAND */
2473 DeleteDC (hdcImage
);
2479 /*************************************************************************
2480 * ImageList_ReplaceIcon [COMCTL32.@]
2482 * Replaces an image in an image list using an icon.
2485 * himl [I] handle to image list
2487 * hIcon [I] handle to icon
2490 * Success: index of the replaced image
2495 ImageList_ReplaceIcon (HIMAGELIST himl
, INT nIndex
, HICON hIcon
)
2503 TRACE("(%p %d %p)\n", himl
, nIndex
, hIcon
);
2505 if (!is_valid(himl
)) {
2506 ERR("invalid image list\n");
2509 if ((nIndex
>= himl
->cMaxImage
) || (nIndex
< -1)) {
2510 ERR("invalid image index %d / %d\n", nIndex
, himl
->cMaxImage
);
2514 hBestFitIcon
= CopyImage(
2517 LR_COPYFROMRESOURCE
);
2518 /* the above will fail if the icon wasn't loaded from a resource, so try
2519 * again without LR_COPYFROMRESOURCE flag */
2521 hBestFitIcon
= CopyImage(
2529 if (himl
->cCurImage
+ 1 >= himl
->cMaxImage
)
2530 IMAGELIST_InternalExpandBitmaps(himl
, 1);
2532 nIndex
= himl
->cCurImage
;
2536 if ((himl
->flags
& 0xfe) == ILC_COLOR32
&& GetIconInfo (hBestFitIcon
, &ii
))
2538 HDC hdcImage
= CreateCompatibleDC( 0 );
2539 GetObjectW (ii
.hbmMask
, sizeof(BITMAP
), &bmp
);
2543 UINT height
= bmp
.bmHeight
/ 2;
2544 HDC hdcMask
= CreateCompatibleDC( 0 );
2545 HBITMAP color
= CreateBitmap( bmp
.bmWidth
, height
, 1, 1, NULL
);
2546 SelectObject( hdcImage
, color
);
2547 SelectObject( hdcMask
, ii
.hbmMask
);
2548 BitBlt( hdcImage
, 0, 0, bmp
.bmWidth
, height
, hdcMask
, 0, height
, SRCCOPY
);
2549 ret
= add_with_alpha( himl
, hdcImage
, nIndex
, 1, bmp
.bmWidth
, height
, color
, ii
.hbmMask
);
2550 DeleteDC( hdcMask
);
2551 DeleteObject( color
);
2553 else ret
= add_with_alpha( himl
, hdcImage
, nIndex
, 1, bmp
.bmWidth
, bmp
.bmHeight
,
2554 ii
.hbmColor
, ii
.hbmMask
);
2556 DeleteDC( hdcImage
);
2557 DeleteObject (ii
.hbmMask
);
2558 if (ii
.hbmColor
) DeleteObject (ii
.hbmColor
);
2562 imagelist_point_from_index(himl
, nIndex
, &pt
);
2566 DrawIconEx( himl
->hdcImage
, pt
.x
, pt
.y
, hBestFitIcon
, himl
->cx
, himl
->cy
, 0, 0, DI_IMAGE
);
2567 PatBlt( himl
->hdcMask
, pt
.x
, pt
.y
, himl
->cx
, himl
->cy
, WHITENESS
);
2568 DrawIconEx( himl
->hdcMask
, pt
.x
, pt
.y
, hBestFitIcon
, himl
->cx
, himl
->cy
, 0, 0, DI_MASK
);
2572 COLORREF color
= himl
->clrBk
!= CLR_NONE
? himl
->clrBk
: comctl32_color
.clrWindow
;
2573 HBRUSH brush
= CreateSolidBrush( GetNearestColor( himl
->hdcImage
, color
));
2575 SelectObject( himl
->hdcImage
, brush
);
2576 PatBlt( himl
->hdcImage
, pt
.x
, pt
.y
, himl
->cx
, himl
->cy
, PATCOPY
);
2577 SelectObject( himl
->hdcImage
, GetStockObject(BLACK_BRUSH
) );
2578 DeleteObject( brush
);
2579 DrawIconEx( himl
->hdcImage
, pt
.x
, pt
.y
, hBestFitIcon
, himl
->cx
, himl
->cy
, 0, 0, DI_NORMAL
);
2583 DestroyIcon(hBestFitIcon
);
2585 TRACE("Insert index = %d, himl->cCurImage = %d\n", nIndex
, himl
->cCurImage
);
2590 /*************************************************************************
2591 * ImageList_SetBkColor [COMCTL32.@]
2593 * Sets the background color of an image list.
2596 * himl [I] handle to image list
2597 * clrBk [I] background color
2600 * Success: previous background color
2605 ImageList_SetBkColor (HIMAGELIST himl
, COLORREF clrBk
)
2609 if (!is_valid(himl
))
2612 clrOldBk
= himl
->clrBk
;
2613 himl
->clrBk
= clrBk
;
2618 /*************************************************************************
2619 * ImageList_SetDragCursorImage [COMCTL32.@]
2621 * Combines the specified image with the current drag image
2624 * himlDrag [I] handle to drag image list
2625 * iDrag [I] drag image index
2626 * dxHotspot [I] X position of the hot spot
2627 * dyHotspot [I] Y position of the hot spot
2634 * - The names dxHotspot, dyHotspot are misleading because they have nothing
2635 * to do with a hotspot but are only the offset of the origin of the new
2636 * image relative to the origin of the old image.
2638 * - When this function is called and the drag image is visible, a
2639 * short flickering occurs but this matches the Win9x behavior. It is
2640 * possible to fix the flickering using code like in ImageList_DragMove.
2644 ImageList_SetDragCursorImage (HIMAGELIST himlDrag
, INT iDrag
,
2645 INT dxHotspot
, INT dyHotspot
)
2647 HIMAGELIST himlTemp
;
2650 if (!is_valid(InternalDrag
.himl
) || !is_valid(himlDrag
))
2653 TRACE(" dxH=%d dyH=%d nX=%d nY=%d\n",
2654 dxHotspot
, dyHotspot
, InternalDrag
.dxHotspot
, InternalDrag
.dyHotspot
);
2656 visible
= InternalDrag
.bShow
;
2658 himlTemp
= ImageList_Merge (InternalDrag
.himlNoCursor
, 0, himlDrag
, iDrag
,
2659 dxHotspot
, dyHotspot
);
2662 /* hide the drag image */
2663 ImageList_DragShowNolock(FALSE
);
2665 if ((InternalDrag
.himl
->cx
!= himlTemp
->cx
) ||
2666 (InternalDrag
.himl
->cy
!= himlTemp
->cy
)) {
2667 /* the size of the drag image changed, invalidate the buffer */
2668 DeleteObject(InternalDrag
.hbmBg
);
2669 InternalDrag
.hbmBg
= 0;
2672 if (InternalDrag
.himl
!= InternalDrag
.himlNoCursor
)
2673 ImageList_Destroy (InternalDrag
.himl
);
2674 InternalDrag
.himl
= himlTemp
;
2677 /* show the drag image */
2678 ImageList_DragShowNolock(TRUE
);
2685 /*************************************************************************
2686 * ImageList_SetFilter [COMCTL32.@]
2688 * Sets a filter (or does something completely different)!!???
2689 * It removes 12 Bytes from the stack (3 Parameters).
2692 * himl [I] SHOULD be a handle to image list
2693 * i [I] COULD be an index?
2698 * Failure: FALSE ???
2701 * This is an UNDOCUMENTED function!!!!
2706 ImageList_SetFilter (HIMAGELIST himl
, INT i
, DWORD dwFilter
)
2708 FIXME("%p, %d, %#lx:empty stub!\n", himl
, i
, dwFilter
);
2714 /*************************************************************************
2715 * ImageList_SetFlags [COMCTL32.@]
2717 * Sets the image list flags.
2720 * himl [I] Handle to image list
2721 * flags [I] Flags to set
2731 ImageList_SetFlags(HIMAGELIST himl
, DWORD flags
)
2733 FIXME("(%p %#lx):empty stub\n", himl
, flags
);
2738 /*************************************************************************
2739 * ImageList_SetIconSize [COMCTL32.@]
2741 * Sets the image size of the bitmap and deletes all images.
2744 * himl [I] handle to image list
2745 * cx [I] image width
2746 * cy [I] image height
2754 ImageList_SetIconSize (HIMAGELIST himl
, INT cx
, INT cy
)
2759 if (!is_valid(himl
))
2762 /* remove all images */
2763 himl
->cMaxImage
= himl
->cInitial
+ 1;
2764 himl
->cCurImage
= 0;
2768 /* initialize overlay mask indices */
2769 for (nCount
= 0; nCount
< MAX_OVERLAYIMAGE
; nCount
++)
2770 himl
->nOvlIdx
[nCount
] = -1;
2772 hbmNew
= ImageList_CreateImage(himl
->hdcImage
, himl
, himl
->cMaxImage
);
2773 SelectObject (himl
->hdcImage
, hbmNew
);
2774 DeleteObject (himl
->hbmImage
);
2775 himl
->hbmImage
= hbmNew
;
2777 if (himl
->hbmMask
) {
2779 imagelist_get_bitmap_size(himl
, himl
->cMaxImage
, &sz
);
2780 hbmNew
= CreateBitmap (sz
.cx
, sz
.cy
, 1, 1, NULL
);
2781 SelectObject (himl
->hdcMask
, hbmNew
);
2782 DeleteObject (himl
->hbmMask
);
2783 himl
->hbmMask
= hbmNew
;
2790 /*************************************************************************
2791 * ImageList_SetImageCount [COMCTL32.@]
2793 * Resizes an image list to the specified number of images.
2796 * himl [I] handle to image list
2797 * iImageCount [I] number of images in the image list
2805 ImageList_SetImageCount (HIMAGELIST himl
, UINT iImageCount
)
2808 HBITMAP hbmNewBitmap
, hbmOld
;
2809 INT nNewCount
, nCopyCount
;
2811 TRACE("%p %d\n",himl
,iImageCount
);
2813 if (!is_valid(himl
))
2816 nNewCount
= iImageCount
+ 1;
2817 nCopyCount
= min(himl
->cCurImage
, iImageCount
);
2819 hdcBitmap
= CreateCompatibleDC (0);
2821 hbmNewBitmap
= ImageList_CreateImage(hdcBitmap
, himl
, nNewCount
);
2823 if (hbmNewBitmap
!= 0)
2825 hbmOld
= SelectObject (hdcBitmap
, hbmNewBitmap
);
2826 imagelist_copy_images( himl
, himl
->hdcImage
, hdcBitmap
, 0, nCopyCount
, 0 );
2827 SelectObject (hdcBitmap
, hbmOld
);
2829 /* FIXME: delete 'empty' image space? */
2831 SelectObject (himl
->hdcImage
, hbmNewBitmap
);
2832 DeleteObject (himl
->hbmImage
);
2833 himl
->hbmImage
= hbmNewBitmap
;
2836 ERR("Could not create new image bitmap!\n");
2841 imagelist_get_bitmap_size( himl
, nNewCount
, &sz
);
2842 hbmNewBitmap
= CreateBitmap (sz
.cx
, sz
.cy
, 1, 1, NULL
);
2843 if (hbmNewBitmap
!= 0)
2845 hbmOld
= SelectObject (hdcBitmap
, hbmNewBitmap
);
2846 imagelist_copy_images( himl
, himl
->hdcMask
, hdcBitmap
, 0, nCopyCount
, 0 );
2847 SelectObject (hdcBitmap
, hbmOld
);
2849 /* FIXME: delete 'empty' image space? */
2851 SelectObject (himl
->hdcMask
, hbmNewBitmap
);
2852 DeleteObject (himl
->hbmMask
);
2853 himl
->hbmMask
= hbmNewBitmap
;
2856 ERR("Could not create new mask bitmap!\n");
2859 DeleteDC (hdcBitmap
);
2861 himl
->item_flags
= HeapReAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, himl
->item_flags
,
2862 nNewCount
* sizeof(*himl
->item_flags
));
2864 /* Update max image count and current image count */
2865 himl
->cMaxImage
= nNewCount
;
2866 himl
->cCurImage
= iImageCount
;
2872 /*************************************************************************
2873 * ImageList_SetOverlayImage [COMCTL32.@]
2875 * Assigns an overlay mask index to an existing image in an image list.
2878 * himl [I] handle to image list
2879 * iImage [I] image index
2880 * iOverlay [I] overlay mask index
2888 ImageList_SetOverlayImage (HIMAGELIST himl
, INT iImage
, INT iOverlay
)
2890 if (!is_valid(himl
))
2892 if ((iOverlay
< 1) || (iOverlay
> MAX_OVERLAYIMAGE
))
2894 if ((iImage
!=-1) && ((iImage
< 0) || (iImage
> himl
->cCurImage
)))
2896 himl
->nOvlIdx
[iOverlay
- 1] = iImage
;
2902 /* helper for ImageList_Write - write bitmap to pstm
2903 * currently everything is written as 24 bit RGB, except masks
2905 static BOOL
_write_bitmap(HBITMAP hBitmap
, IStream
*pstm
)
2907 LPBITMAPFILEHEADER bmfh
;
2908 LPBITMAPINFOHEADER bmih
;
2909 LPBYTE data
= NULL
, lpBits
;
2911 INT bitCount
, sizeImage
, offBits
, totalSize
;
2913 BOOL result
= FALSE
;
2915 if (!GetObjectW(hBitmap
, sizeof(BITMAP
), &bm
))
2918 bitCount
= bm
.bmBitsPixel
;
2919 sizeImage
= get_dib_stride(bm
.bmWidth
, bitCount
) * bm
.bmHeight
;
2921 totalSize
= sizeof(BITMAPFILEHEADER
) + sizeof(BITMAPINFOHEADER
);
2923 totalSize
+= (1 << bitCount
) * sizeof(RGBQUAD
);
2924 offBits
= totalSize
;
2925 totalSize
+= sizeImage
;
2927 data
= Alloc(totalSize
);
2928 bmfh
= (LPBITMAPFILEHEADER
)data
;
2929 bmih
= (LPBITMAPINFOHEADER
)(data
+ sizeof(BITMAPFILEHEADER
));
2930 lpBits
= data
+ offBits
;
2932 /* setup BITMAPFILEHEADER */
2933 bmfh
->bfType
= (('M' << 8) | 'B');
2934 bmfh
->bfSize
= offBits
;
2935 bmfh
->bfReserved1
= 0;
2936 bmfh
->bfReserved2
= 0;
2937 bmfh
->bfOffBits
= offBits
;
2939 /* setup BITMAPINFOHEADER */
2940 bmih
->biSize
= sizeof(BITMAPINFOHEADER
);
2941 bmih
->biWidth
= bm
.bmWidth
;
2942 bmih
->biHeight
= bm
.bmHeight
;
2944 bmih
->biBitCount
= bitCount
;
2945 bmih
->biCompression
= BI_RGB
;
2946 bmih
->biSizeImage
= sizeImage
;
2947 bmih
->biXPelsPerMeter
= 0;
2948 bmih
->biYPelsPerMeter
= 0;
2949 bmih
->biClrUsed
= 0;
2950 bmih
->biClrImportant
= 0;
2953 result
= GetDIBits(xdc
, hBitmap
, 0, bm
.bmHeight
, lpBits
, (BITMAPINFO
*)bmih
, DIB_RGB_COLORS
) == bm
.bmHeight
;
2958 TRACE("width %lu, height %lu, planes %u, bpp %u\n",
2959 bmih
->biWidth
, bmih
->biHeight
,
2960 bmih
->biPlanes
, bmih
->biBitCount
);
2962 if(FAILED(IStream_Write(pstm
, data
, totalSize
, NULL
)))
2973 /*************************************************************************
2974 * ImageList_WriteEx [COMCTL32.@]
2976 HRESULT WINAPI
ImageList_WriteEx(HIMAGELIST himl
, DWORD flags
, IStream
*pstm
)
2978 FIXME("%p %#lx %p: semi-stub\n", himl
, flags
, pstm
);
2979 return ImageList_Write(himl
, pstm
) ? S_OK
: E_FAIL
;
2982 /*************************************************************************
2983 * ImageList_Write [COMCTL32.@]
2985 * Writes an image list to a stream.
2988 * himl [I] handle to image list
2989 * pstm [O] Pointer to a stream.
2999 BOOL WINAPI
ImageList_Write(HIMAGELIST himl
, IStream
*pstm
)
3004 TRACE("%p %p\n", himl
, pstm
);
3006 if (!is_valid(himl
))
3009 ilHead
.usMagic
= (('L' << 8) | 'I');
3010 ilHead
.usVersion
= 0x101;
3011 ilHead
.cCurImage
= himl
->cCurImage
;
3012 ilHead
.cMaxImage
= himl
->cMaxImage
;
3013 ilHead
.cGrow
= himl
->cGrow
;
3014 ilHead
.cx
= himl
->cx
;
3015 ilHead
.cy
= himl
->cy
;
3016 ilHead
.bkcolor
= himl
->clrBk
;
3017 ilHead
.flags
= himl
->flags
;
3018 for(i
= 0; i
< 4; i
++) {
3019 ilHead
.ovls
[i
] = himl
->nOvlIdx
[i
];
3022 TRACE("cx %u, cy %u, flags 0x04%x, cCurImage %u, cMaxImage %u\n",
3023 ilHead
.cx
, ilHead
.cy
, ilHead
.flags
, ilHead
.cCurImage
, ilHead
.cMaxImage
);
3025 if(FAILED(IStream_Write(pstm
, &ilHead
, sizeof(ILHEAD
), NULL
)))
3028 /* write the bitmap */
3029 if(!_write_bitmap(himl
->hbmImage
, pstm
))
3032 /* write the mask if we have one */
3033 if(himl
->flags
& ILC_MASK
) {
3034 if(!_write_bitmap(himl
->hbmMask
, pstm
))
3042 static HBITMAP
ImageList_CreateImage(HDC hdc
, HIMAGELIST himl
, UINT count
)
3044 HBITMAP hbmNewBitmap
;
3045 UINT ilc
= (himl
->flags
& 0xFE);
3048 imagelist_get_bitmap_size( himl
, count
, &sz
);
3050 if ((ilc
>= ILC_COLOR4
&& ilc
<= ILC_COLOR32
) || ilc
== ILC_COLOR
)
3052 char buffer
[sizeof(BITMAPINFOHEADER
) + 256 * sizeof(RGBQUAD
)];
3053 BITMAPINFO
*bmi
= (BITMAPINFO
*)buffer
;
3055 TRACE("Creating DIBSection %ld x %ld, %d Bits per Pixel\n",
3056 sz
.cx
, sz
.cy
, himl
->uBitsPixel
);
3058 memset( buffer
, 0, sizeof(buffer
) );
3059 bmi
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
3060 bmi
->bmiHeader
.biWidth
= sz
.cx
;
3061 bmi
->bmiHeader
.biHeight
= sz
.cy
;
3062 bmi
->bmiHeader
.biPlanes
= 1;
3063 bmi
->bmiHeader
.biBitCount
= himl
->uBitsPixel
;
3064 bmi
->bmiHeader
.biCompression
= BI_RGB
;
3066 if (himl
->uBitsPixel
<= ILC_COLOR8
)
3068 if (!himl
->color_table_set
)
3070 /* retrieve the default color map */
3071 HBITMAP tmp
= CreateBitmap( 1, 1, 1, 1, NULL
);
3072 GetDIBits( hdc
, tmp
, 0, 0, NULL
, bmi
, DIB_RGB_COLORS
);
3073 DeleteObject( tmp
);
3074 if (ilc
== ILC_COLOR4
)
3077 tmp
= bmi
->bmiColors
[7];
3078 bmi
->bmiColors
[7] = bmi
->bmiColors
[8];
3079 bmi
->bmiColors
[8] = tmp
;
3084 GetDIBColorTable(himl
->hdcImage
, 0, 1 << himl
->uBitsPixel
, bmi
->bmiColors
);
3087 hbmNewBitmap
= CreateDIBSection(hdc
, bmi
, DIB_RGB_COLORS
, NULL
, 0, 0);
3089 else /*if (ilc == ILC_COLORDDB)*/
3091 TRACE("Creating Bitmap: %d Bits per Pixel\n", himl
->uBitsPixel
);
3093 hbmNewBitmap
= CreateBitmap (sz
.cx
, sz
.cy
, 1, himl
->uBitsPixel
, NULL
);
3095 TRACE("returning %p\n", hbmNewBitmap
);
3096 return hbmNewBitmap
;
3099 /*************************************************************************
3100 * ImageList_SetColorTable [COMCTL32.@]
3102 * Sets the color table of an image list.
3105 * himl [I] Handle to the image list.
3106 * uStartIndex [I] The first index to set.
3107 * cEntries [I] Number of entries to set.
3108 * prgb [I] New color information for color table for the image list.
3111 * Success: Number of entries in the table that were set.
3115 * ImageList_Create(), SetDIBColorTable()
3119 ImageList_SetColorTable(HIMAGELIST himl
, UINT uStartIndex
, UINT cEntries
, const RGBQUAD
*prgb
)
3121 TRACE("(%p, %d, %d, %p)\n", himl
, uStartIndex
, cEntries
, prgb
);
3122 himl
->color_table_set
= TRUE
;
3123 return SetDIBColorTable(himl
->hdcImage
, uStartIndex
, cEntries
, prgb
);
3126 /*************************************************************************
3127 * ImageList_CoCreateInstance [COMCTL32.@]
3129 * Creates a new imagelist instance and returns an interface pointer to it.
3132 * rclsid [I] A reference to the CLSID (CLSID_ImageList).
3133 * punkOuter [I] Pointer to IUnknown interface for aggregation, if desired
3134 * riid [I] Identifier of the requested interface.
3135 * ppv [O] Returns the address of the pointer requested, or NULL.
3139 * Failure: Error value.
3142 ImageList_CoCreateInstance (REFCLSID rclsid
, const IUnknown
*punkOuter
, REFIID riid
, void **ppv
)
3144 TRACE("(%s,%p,%s,%p)\n", debugstr_guid(rclsid
), punkOuter
, debugstr_guid(riid
), ppv
);
3146 if (!IsEqualCLSID(&CLSID_ImageList
, rclsid
))
3147 return E_NOINTERFACE
;
3149 return ImageListImpl_CreateInstance(punkOuter
, riid
, ppv
);
3153 /*************************************************************************
3154 * IImageList implementation
3157 static HRESULT WINAPI
ImageListImpl_QueryInterface(IImageList2
*iface
,
3158 REFIID iid
, void **ppv
)
3160 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3162 TRACE("(%p,%s,%p)\n", iface
, debugstr_guid(iid
), ppv
);
3164 if (!ppv
) return E_INVALIDARG
;
3166 if (IsEqualIID(&IID_IUnknown
, iid
) ||
3167 IsEqualIID(&IID_IImageList
, iid
) ||
3168 IsEqualIID(&IID_IImageList2
, iid
))
3170 *ppv
= &imgl
->IImageList2_iface
;
3175 return E_NOINTERFACE
;
3178 IImageList2_AddRef(iface
);
3182 static ULONG WINAPI
ImageListImpl_AddRef(IImageList2
*iface
)
3184 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3185 ULONG ref
= InterlockedIncrement(&imgl
->ref
);
3187 TRACE("%p, refcount %lu\n", iface
, ref
);
3191 static ULONG WINAPI
ImageListImpl_Release(IImageList2
*iface
)
3193 HIMAGELIST This
= impl_from_IImageList2(iface
);
3194 ULONG ref
= InterlockedDecrement(&This
->ref
);
3196 TRACE("%p, refcount %lu\n", iface
, ref
);
3200 /* delete image bitmaps */
3201 if (This
->hbmImage
) DeleteObject (This
->hbmImage
);
3202 if (This
->hbmMask
) DeleteObject (This
->hbmMask
);
3204 /* delete image & mask DCs */
3205 if (This
->hdcImage
) DeleteDC (This
->hdcImage
);
3206 if (This
->hdcMask
) DeleteDC (This
->hdcMask
);
3208 /* delete blending brushes */
3209 if (This
->hbrBlend25
) DeleteObject (This
->hbrBlend25
);
3210 if (This
->hbrBlend50
) DeleteObject (This
->hbrBlend50
);
3212 This
->IImageList2_iface
.lpVtbl
= NULL
;
3213 Free(This
->item_flags
);
3220 static HRESULT WINAPI
ImageListImpl_Add(IImageList2
*iface
, HBITMAP hbmImage
,
3221 HBITMAP hbmMask
, int *pi
)
3223 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3229 ret
= ImageList_Add(imgl
, hbmImage
, hbmMask
);
3238 static HRESULT WINAPI
ImageListImpl_ReplaceIcon(IImageList2
*iface
, int i
,
3239 HICON hicon
, int *pi
)
3241 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3247 ret
= ImageList_ReplaceIcon(imgl
, i
, hicon
);
3256 static HRESULT WINAPI
ImageListImpl_SetOverlayImage(IImageList2
*iface
,
3257 int iImage
, int iOverlay
)
3259 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3260 return ImageList_SetOverlayImage(imgl
, iImage
, iOverlay
) ? S_OK
: E_FAIL
;
3263 static HRESULT WINAPI
ImageListImpl_Replace(IImageList2
*iface
, int i
,
3264 HBITMAP hbmImage
, HBITMAP hbmMask
)
3266 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3267 return ImageList_Replace(imgl
, i
, hbmImage
, hbmMask
) ? S_OK
: E_FAIL
;
3270 static HRESULT WINAPI
ImageListImpl_AddMasked(IImageList2
*iface
, HBITMAP hbmImage
,
3271 COLORREF crMask
, int *pi
)
3273 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3279 ret
= ImageList_AddMasked(imgl
, hbmImage
, crMask
);
3288 static HRESULT WINAPI
ImageListImpl_Draw(IImageList2
*iface
,
3289 IMAGELISTDRAWPARAMS
*pimldp
)
3291 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3292 HIMAGELIST old_himl
;
3295 /* As far as I can tell, Windows simply ignores the contents of pimldp->himl
3296 so we shall simulate the same */
3297 old_himl
= pimldp
->himl
;
3298 pimldp
->himl
= imgl
;
3300 ret
= ImageList_DrawIndirect(pimldp
);
3302 pimldp
->himl
= old_himl
;
3303 return ret
? S_OK
: E_INVALIDARG
;
3306 static HRESULT WINAPI
ImageListImpl_Remove(IImageList2
*iface
, int i
)
3308 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3309 return (ImageList_Remove(imgl
, i
) == 0) ? E_INVALIDARG
: S_OK
;
3312 static HRESULT WINAPI
ImageListImpl_GetIcon(IImageList2
*iface
, int i
, UINT flags
,
3315 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3321 hIcon
= ImageList_GetIcon(imgl
, i
, flags
);
3330 static HRESULT WINAPI
ImageListImpl_GetImageInfo(IImageList2
*iface
, int i
,
3331 IMAGEINFO
*pImageInfo
)
3333 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3334 return ImageList_GetImageInfo(imgl
, i
, pImageInfo
) ? S_OK
: E_FAIL
;
3337 static HRESULT WINAPI
ImageListImpl_Copy(IImageList2
*iface
, int dst_index
,
3338 IUnknown
*unk_src
, int src_index
, UINT flags
)
3340 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3341 IImageList
*src
= NULL
;
3347 /* TODO: Add test for IID_ImageList2 too */
3348 if (FAILED(IUnknown_QueryInterface(unk_src
, &IID_IImageList
,
3352 if (ImageList_Copy(imgl
, dst_index
, (HIMAGELIST
) src
, src_index
, flags
))
3357 IImageList_Release(src
);
3361 static HRESULT WINAPI
ImageListImpl_Merge(IImageList2
*iface
, int i1
,
3362 IUnknown
*punk2
, int i2
, int dx
, int dy
, REFIID riid
, void **ppv
)
3364 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3365 IImageList
*iml2
= NULL
;
3367 HRESULT ret
= E_FAIL
;
3369 TRACE("(%p)->(%d %p %d %d %d %s %p)\n", iface
, i1
, punk2
, i2
, dx
, dy
, debugstr_guid(riid
), ppv
);
3371 /* TODO: Add test for IID_ImageList2 too */
3372 if (FAILED(IUnknown_QueryInterface(punk2
, &IID_IImageList
,
3376 merged
= ImageList_Merge(imgl
, i1
, (HIMAGELIST
) iml2
, i2
, dx
, dy
);
3378 /* Get the interface for the new image list */
3381 ret
= HIMAGELIST_QueryInterface(merged
, riid
, ppv
);
3382 ImageList_Destroy(merged
);
3385 IImageList_Release(iml2
);
3389 static HRESULT WINAPI
ImageListImpl_Clone(IImageList2
*iface
, REFIID riid
, void **ppv
)
3391 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3393 HRESULT ret
= E_FAIL
;
3395 TRACE("(%p)->(%s %p)\n", iface
, debugstr_guid(riid
), ppv
);
3397 clone
= ImageList_Duplicate(imgl
);
3399 /* Get the interface for the new image list */
3402 ret
= HIMAGELIST_QueryInterface(clone
, riid
, ppv
);
3403 ImageList_Destroy(clone
);
3409 static HRESULT WINAPI
ImageListImpl_GetImageRect(IImageList2
*iface
, int i
,
3412 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3418 if (!ImageList_GetImageInfo(imgl
, i
, &info
))
3421 *prc
= info
.rcImage
;
3426 static HRESULT WINAPI
ImageListImpl_GetIconSize(IImageList2
*iface
, int *cx
,
3429 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3430 return ImageList_GetIconSize(imgl
, cx
, cy
) ? S_OK
: E_INVALIDARG
;
3433 static HRESULT WINAPI
ImageListImpl_SetIconSize(IImageList2
*iface
, int cx
,
3436 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3437 return ImageList_SetIconSize(imgl
, cx
, cy
) ? S_OK
: E_FAIL
;
3440 static HRESULT WINAPI
ImageListImpl_GetImageCount(IImageList2
*iface
, int *pi
)
3442 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3443 *pi
= ImageList_GetImageCount(imgl
);
3447 static HRESULT WINAPI
ImageListImpl_SetImageCount(IImageList2
*iface
, UINT count
)
3449 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3450 return ImageList_SetImageCount(imgl
, count
) ? S_OK
: E_FAIL
;
3453 static HRESULT WINAPI
ImageListImpl_SetBkColor(IImageList2
*iface
, COLORREF clrBk
,
3456 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3457 *pclr
= ImageList_SetBkColor(imgl
, clrBk
);
3461 static HRESULT WINAPI
ImageListImpl_GetBkColor(IImageList2
*iface
, COLORREF
*pclr
)
3463 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3464 *pclr
= ImageList_GetBkColor(imgl
);
3468 static HRESULT WINAPI
ImageListImpl_BeginDrag(IImageList2
*iface
, int iTrack
,
3469 int dxHotspot
, int dyHotspot
)
3471 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3472 return ImageList_BeginDrag(imgl
, iTrack
, dxHotspot
, dyHotspot
) ? S_OK
: E_FAIL
;
3475 static HRESULT WINAPI
ImageListImpl_EndDrag(IImageList2
*iface
)
3477 ImageList_EndDrag();
3481 static HRESULT WINAPI
ImageListImpl_DragEnter(IImageList2
*iface
, HWND hwndLock
,
3484 return ImageList_DragEnter(hwndLock
, x
, y
) ? S_OK
: E_FAIL
;
3487 static HRESULT WINAPI
ImageListImpl_DragLeave(IImageList2
*iface
, HWND hwndLock
)
3489 return ImageList_DragLeave(hwndLock
) ? S_OK
: E_FAIL
;
3492 static HRESULT WINAPI
ImageListImpl_DragMove(IImageList2
*iface
, int x
, int y
)
3494 return ImageList_DragMove(x
, y
) ? S_OK
: E_FAIL
;
3497 static HRESULT WINAPI
ImageListImpl_SetDragCursorImage(IImageList2
*iface
,
3498 IUnknown
*punk
, int iDrag
, int dxHotspot
, int dyHotspot
)
3500 IImageList
*iml2
= NULL
;
3506 /* TODO: Add test for IID_ImageList2 too */
3507 if (FAILED(IUnknown_QueryInterface(punk
, &IID_IImageList
,
3511 ret
= ImageList_SetDragCursorImage((HIMAGELIST
) iml2
, iDrag
, dxHotspot
,
3514 IImageList_Release(iml2
);
3516 return ret
? S_OK
: E_FAIL
;
3519 static HRESULT WINAPI
ImageListImpl_DragShowNolock(IImageList2
*iface
, BOOL fShow
)
3521 return ImageList_DragShowNolock(fShow
) ? S_OK
: E_FAIL
;
3524 static HRESULT WINAPI
ImageListImpl_GetDragImage(IImageList2
*iface
, POINT
*ppt
,
3525 POINT
*pptHotspot
, REFIID riid
, PVOID
*ppv
)
3527 HRESULT ret
= E_FAIL
;
3533 hNew
= ImageList_GetDragImage(ppt
, pptHotspot
);
3535 /* Get the interface for the new image list */
3538 IImageList
*idrag
= (IImageList
*)hNew
;
3540 ret
= HIMAGELIST_QueryInterface(hNew
, riid
, ppv
);
3541 IImageList_Release(idrag
);
3547 static HRESULT WINAPI
ImageListImpl_GetItemFlags(IImageList2
*iface
, int i
, DWORD
*flags
)
3549 HIMAGELIST This
= impl_from_IImageList2(iface
);
3551 if (i
< 0 || i
>= This
->cCurImage
)
3552 return E_INVALIDARG
;
3554 *flags
= This
->item_flags
[i
];
3559 static HRESULT WINAPI
ImageListImpl_GetOverlayImage(IImageList2
*iface
, int iOverlay
,
3562 HIMAGELIST This
= impl_from_IImageList2(iface
);
3565 if ((iOverlay
< 0) || (iOverlay
> This
->cCurImage
))
3568 for (i
= 0; i
< MAX_OVERLAYIMAGE
; i
++)
3570 if (This
->nOvlIdx
[i
] == iOverlay
)
3580 static HRESULT WINAPI
ImageListImpl_Resize(IImageList2
*iface
, INT cx
, INT cy
)
3582 FIXME("(%p)->(%d %d): stub\n", iface
, cx
, cy
);
3586 static HRESULT WINAPI
ImageListImpl_GetOriginalSize(IImageList2
*iface
, INT image
, DWORD flags
, INT
*cx
, INT
*cy
)
3588 FIXME("(%p)->(%d %lx %p %p): stub\n", iface
, image
, flags
, cx
, cy
);
3592 static HRESULT WINAPI
ImageListImpl_SetOriginalSize(IImageList2
*iface
, INT image
, INT cx
, INT cy
)
3594 FIXME("(%p)->(%d %d %d): stub\n", iface
, image
, cx
, cy
);
3598 static HRESULT WINAPI
ImageListImpl_SetCallback(IImageList2
*iface
, IUnknown
*callback
)
3600 FIXME("(%p)->(%p): stub\n", iface
, callback
);
3604 static HRESULT WINAPI
ImageListImpl_GetCallback(IImageList2
*iface
, REFIID riid
, void **ppv
)
3606 FIXME("(%p)->(%s %p): stub\n", iface
, debugstr_guid(riid
), ppv
);
3610 static HRESULT WINAPI
ImageListImpl_ForceImagePresent(IImageList2
*iface
, INT image
, DWORD flags
)
3612 FIXME("(%p)->(%d %lx): stub\n", iface
, image
, flags
);
3616 static HRESULT WINAPI
ImageListImpl_DiscardImages(IImageList2
*iface
, INT first_image
, INT last_image
, DWORD flags
)
3618 FIXME("(%p)->(%d %d %lx): stub\n", iface
, first_image
, last_image
, flags
);
3622 static HRESULT WINAPI
ImageListImpl_PreloadImages(IImageList2
*iface
, IMAGELISTDRAWPARAMS
*params
)
3624 FIXME("(%p)->(%p): stub\n", iface
, params
);
3628 static HRESULT WINAPI
ImageListImpl_GetStatistics(IImageList2
*iface
, IMAGELISTSTATS
*stats
)
3630 FIXME("(%p)->(%p): stub\n", iface
, stats
);
3634 static HRESULT WINAPI
ImageListImpl_Initialize(IImageList2
*iface
, INT cx
, INT cy
, UINT flags
, INT initial
, INT grow
)
3636 HIMAGELIST himl
= impl_from_IImageList2(iface
);
3639 UINT ilc
= (flags
& 0xFE);
3640 static const WORD aBitBlend25
[] =
3641 {0xAA, 0x00, 0x55, 0x00, 0xAA, 0x00, 0x55, 0x00};
3642 static const WORD aBitBlend50
[] =
3643 {0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA};
3645 TRACE("(%p)->(%d %d %d %d %d)\n", iface
, cx
, cy
, flags
, initial
, grow
);
3647 if (cx
< 0 || cy
< 0) return E_INVALIDARG
;
3648 if (!((flags
&ILC_COLORDDB
) == ILC_COLORDDB
) && (cx
== 0 || cy
== 0)) return E_INVALIDARG
;
3650 grow
= (WORD
)((max( grow
, 1 ) + 3) & ~3);
3654 /* Windows doesn't limit the size here, but X11 doesn't let us allocate such huge bitmaps */
3655 WARN( "grow %d too large, limiting to 256\n", grow
);
3661 himl
->flags
= flags
;
3662 himl
->cMaxImage
= initial
+ 1;
3663 himl
->cInitial
= initial
;
3665 himl
->clrFg
= CLR_DEFAULT
;
3666 himl
->clrBk
= CLR_NONE
;
3667 himl
->color_table_set
= FALSE
;
3669 /* initialize overlay mask indices */
3670 for (nCount
= 0; nCount
< MAX_OVERLAYIMAGE
; nCount
++)
3671 himl
->nOvlIdx
[nCount
] = -1;
3673 /* Create Image & Mask DCs */
3674 himl
->hdcImage
= CreateCompatibleDC (0);
3675 if (!himl
->hdcImage
)
3677 if (himl
->flags
& ILC_MASK
){
3678 himl
->hdcMask
= CreateCompatibleDC(0);
3683 /* Default to ILC_COLOR4 if none of the ILC_COLOR* flags are specified */
3684 if (ilc
== ILC_COLOR
)
3687 himl
->flags
|= ILC_COLOR4
;
3690 if (ilc
>= ILC_COLOR4
&& ilc
<= ILC_COLOR32
)
3691 himl
->uBitsPixel
= ilc
;
3693 himl
->uBitsPixel
= (UINT
)GetDeviceCaps (himl
->hdcImage
, BITSPIXEL
);
3695 if (himl
->cMaxImage
> 0) {
3696 himl
->hbmImage
= ImageList_CreateImage(himl
->hdcImage
, himl
, himl
->cMaxImage
);
3697 SelectObject(himl
->hdcImage
, himl
->hbmImage
);
3701 if ((himl
->cMaxImage
> 0) && (himl
->flags
& ILC_MASK
)) {
3704 imagelist_get_bitmap_size(himl
, himl
->cMaxImage
, &sz
);
3705 himl
->hbmMask
= CreateBitmap (sz
.cx
, sz
.cy
, 1, 1, NULL
);
3706 if (himl
->hbmMask
== 0) {
3707 ERR("Error creating mask bitmap!\n");
3710 SelectObject(himl
->hdcMask
, himl
->hbmMask
);
3715 himl
->item_flags
= Alloc( himl
->cMaxImage
* sizeof(*himl
->item_flags
) );
3717 /* create blending brushes */
3718 hbmTemp
= CreateBitmap (8, 8, 1, 1, aBitBlend25
);
3719 himl
->hbrBlend25
= CreatePatternBrush (hbmTemp
);
3720 DeleteObject (hbmTemp
);
3722 hbmTemp
= CreateBitmap (8, 8, 1, 1, aBitBlend50
);
3723 himl
->hbrBlend50
= CreatePatternBrush (hbmTemp
);
3724 DeleteObject (hbmTemp
);
3726 TRACE("created imagelist %p\n", himl
);
3731 static HRESULT WINAPI
ImageListImpl_Replace2(IImageList2
*iface
, INT i
, HBITMAP image
, HBITMAP mask
, IUnknown
*unk
, DWORD flags
)
3733 FIXME("(%p)->(%d %p %p %p %lx): stub\n", iface
, i
, image
, mask
, unk
, flags
);
3737 static HRESULT WINAPI
ImageListImpl_ReplaceFromImageList(IImageList2
*iface
, INT i
, IImageList
*imagelist
, INT src
,
3738 IUnknown
*unk
, DWORD flags
)
3740 FIXME("(%p)->(%d %p %d %p %lx): stub\n", iface
, i
, imagelist
, src
, unk
, flags
);
3744 static const IImageList2Vtbl ImageListImpl_Vtbl
= {
3745 ImageListImpl_QueryInterface
,
3746 ImageListImpl_AddRef
,
3747 ImageListImpl_Release
,
3749 ImageListImpl_ReplaceIcon
,
3750 ImageListImpl_SetOverlayImage
,
3751 ImageListImpl_Replace
,
3752 ImageListImpl_AddMasked
,
3754 ImageListImpl_Remove
,
3755 ImageListImpl_GetIcon
,
3756 ImageListImpl_GetImageInfo
,
3758 ImageListImpl_Merge
,
3759 ImageListImpl_Clone
,
3760 ImageListImpl_GetImageRect
,
3761 ImageListImpl_GetIconSize
,
3762 ImageListImpl_SetIconSize
,
3763 ImageListImpl_GetImageCount
,
3764 ImageListImpl_SetImageCount
,
3765 ImageListImpl_SetBkColor
,
3766 ImageListImpl_GetBkColor
,
3767 ImageListImpl_BeginDrag
,
3768 ImageListImpl_EndDrag
,
3769 ImageListImpl_DragEnter
,
3770 ImageListImpl_DragLeave
,
3771 ImageListImpl_DragMove
,
3772 ImageListImpl_SetDragCursorImage
,
3773 ImageListImpl_DragShowNolock
,
3774 ImageListImpl_GetDragImage
,
3775 ImageListImpl_GetItemFlags
,
3776 ImageListImpl_GetOverlayImage
,
3777 ImageListImpl_Resize
,
3778 ImageListImpl_GetOriginalSize
,
3779 ImageListImpl_SetOriginalSize
,
3780 ImageListImpl_SetCallback
,
3781 ImageListImpl_GetCallback
,
3782 ImageListImpl_ForceImagePresent
,
3783 ImageListImpl_DiscardImages
,
3784 ImageListImpl_PreloadImages
,
3785 ImageListImpl_GetStatistics
,
3786 ImageListImpl_Initialize
,
3787 ImageListImpl_Replace2
,
3788 ImageListImpl_ReplaceFromImageList
3791 static BOOL
is_valid(HIMAGELIST himl
)
3796 valid
= himl
&& himl
->IImageList2_iface
.lpVtbl
== &ImageListImpl_Vtbl
;
3806 /*************************************************************************
3807 * HIMAGELIST_QueryInterface [COMCTL32.@]
3809 * Returns a pointer to an IImageList or IImageList2 object for the given
3813 * himl [I] Image list handle.
3814 * riid [I] Identifier of the requested interface.
3815 * ppv [O] Returns the address of the pointer requested, or NULL.
3819 * Failure: Error value.
3822 HIMAGELIST_QueryInterface (HIMAGELIST himl
, REFIID riid
, void **ppv
)
3824 TRACE("(%p,%s,%p)\n", himl
, debugstr_guid(riid
), ppv
);
3825 return IImageList2_QueryInterface((IImageList2
*) himl
, riid
, ppv
);
3828 static HRESULT
ImageListImpl_CreateInstance(const IUnknown
*pUnkOuter
, REFIID iid
, void** ppv
)
3833 TRACE("(%p,%s,%p)\n", pUnkOuter
, debugstr_guid(iid
), ppv
);
3837 if (pUnkOuter
) return CLASS_E_NOAGGREGATION
;
3839 This
= Alloc(sizeof(struct _IMAGELIST
));
3840 if (!This
) return E_OUTOFMEMORY
;
3842 This
->IImageList2_iface
.lpVtbl
= &ImageListImpl_Vtbl
;
3845 ret
= IImageList2_QueryInterface(&This
->IImageList2_iface
, iid
, ppv
);
3846 IImageList2_Release(&This
->IImageList2_iface
);