2 * ImageList implementation
4 * Copyright 1998 Eric Kohl
5 * Copyright 2000 Jason Mawdsley
6 * Copyright 2001, 2004 Michael Stefaniuc
7 * Copyright 2001 Charles Loep for CodeWeavers
8 * Copyright 2002 Dimitrie O. Paun
9 * Copyright 2009 Owen Rudge for CodeWeavers
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public
13 * License as published by the Free Software Foundation; either
14 * version 2.1 of the License, or (at your option) any later version.
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with this library; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
27 * This code was audited for completeness against the documented features
28 * of Comctl32.dll version 6.0 on Sep. 12, 2002, by Dimitrie O. Paun.
30 * Unless otherwise noted, we believe this code to be complete, as per
31 * the specification mentioned above.
32 * If you discover missing features, or bugs, please note them below.
35 * - Add support for ILD_PRESERVEALPHA, ILD_SCALE, ILD_DPISCALE
36 * - Add support for ILS_GLOW, ILS_SHADOW, ILS_SATURATE
37 * - Thread-safe locking
54 #include "commoncontrols.h"
55 #include "imagelist.h"
56 #include "wine/debug.h"
57 #include "wine/exception.h"
59 WINE_DEFAULT_DEBUG_CHANNEL(imagelist
);
62 #define MAX_OVERLAYIMAGE 15
64 /* internal image list data used for Drag & Drop operations */
69 /* position of the drag image relative to the window */
72 /* offset of the hotspot relative to the origin of the image */
75 /* is the drag image visible */
77 /* saved background */
81 static INTERNALDRAG InternalDrag
= { 0, 0, 0, 0, 0, 0, FALSE
, 0 };
83 static HBITMAP
ImageList_CreateImage(HDC hdc
, HIMAGELIST himl
, UINT count
);
84 static HRESULT
ImageListImpl_CreateInstance(const IUnknown
*pUnkOuter
, REFIID iid
, void** ppv
);
85 static inline BOOL
is_valid(HIMAGELIST himl
);
88 * An imagelist with N images is tiled like this:
100 static inline UINT
imagelist_height( UINT count
)
102 return ((count
+ TILE_COUNT
- 1)/TILE_COUNT
);
105 static inline void imagelist_point_from_index( HIMAGELIST himl
, UINT index
, LPPOINT pt
)
107 pt
->x
= (index
%TILE_COUNT
) * himl
->cx
;
108 pt
->y
= (index
/TILE_COUNT
) * himl
->cy
;
111 static inline void imagelist_get_bitmap_size( HIMAGELIST himl
, UINT count
, SIZE
*sz
)
113 sz
->cx
= himl
->cx
* TILE_COUNT
;
114 sz
->cy
= imagelist_height( count
) * himl
->cy
;
118 * imagelist_copy_images()
120 * Copies a block of count images from offset src in the list to offset dest.
121 * Images are copied a row at at time. Assumes hdcSrc and hdcDest are different.
123 static inline void imagelist_copy_images( HIMAGELIST himl
, HDC hdcSrc
, HDC hdcDest
,
124 UINT src
, UINT count
, UINT dest
)
130 for ( i
=0; i
<TILE_COUNT
; i
++ )
132 imagelist_point_from_index( himl
, src
+i
, &ptSrc
);
133 imagelist_point_from_index( himl
, dest
+i
, &ptDest
);
135 sz
.cy
= himl
->cy
* imagelist_height( count
- i
);
137 BitBlt( hdcDest
, ptDest
.x
, ptDest
.y
, sz
.cx
, sz
.cy
,
138 hdcSrc
, ptSrc
.x
, ptSrc
.y
, SRCCOPY
);
142 /* add images with an alpha channel when the image list is 32 bpp */
143 static BOOL
add_with_alpha( HIMAGELIST himl
, HDC hdc
, int pos
, int count
,
144 int width
, int height
, HBITMAP hbmImage
, HBITMAP hbmMask
)
148 BITMAPINFO
*info
, *mask_info
= NULL
;
150 BYTE
*mask_bits
= NULL
;
155 if (!GetObjectW( hbmImage
, sizeof(bm
), &bm
)) return FALSE
;
157 /* if either the imagelist or the source bitmap don't have an alpha channel, bail out now */
158 if (!himl
->has_alpha
) return FALSE
;
159 if (bm
.bmBitsPixel
!= 32) return FALSE
;
161 SelectObject( hdc
, hbmImage
);
162 mask_width
= (bm
.bmWidth
+ 31) / 32 * 4;
164 if (!(info
= HeapAlloc( GetProcessHeap(), 0, FIELD_OFFSET( BITMAPINFO
, bmiColors
[256] )))) goto done
;
165 info
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
166 info
->bmiHeader
.biWidth
= bm
.bmWidth
;
167 info
->bmiHeader
.biHeight
= -height
;
168 info
->bmiHeader
.biPlanes
= 1;
169 info
->bmiHeader
.biBitCount
= 32;
170 info
->bmiHeader
.biCompression
= BI_RGB
;
171 info
->bmiHeader
.biSizeImage
= bm
.bmWidth
* height
* 4;
172 info
->bmiHeader
.biXPelsPerMeter
= 0;
173 info
->bmiHeader
.biYPelsPerMeter
= 0;
174 info
->bmiHeader
.biClrUsed
= 0;
175 info
->bmiHeader
.biClrImportant
= 0;
176 if (!(bits
= HeapAlloc( GetProcessHeap(), 0, info
->bmiHeader
.biSizeImage
))) goto done
;
177 if (!GetDIBits( hdc
, hbmImage
, 0, height
, bits
, info
, DIB_RGB_COLORS
)) goto done
;
181 if (!(mask_info
= HeapAlloc( GetProcessHeap(), 0, FIELD_OFFSET( BITMAPINFO
, bmiColors
[2] ))))
183 mask_info
->bmiHeader
= info
->bmiHeader
;
184 mask_info
->bmiHeader
.biBitCount
= 1;
185 mask_info
->bmiHeader
.biSizeImage
= mask_width
* height
;
186 if (!(mask_bits
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, info
->bmiHeader
.biSizeImage
)))
188 if (!GetDIBits( hdc
, hbmMask
, 0, height
, mask_bits
, mask_info
, DIB_RGB_COLORS
)) goto done
;
191 for (n
= 0; n
< count
; n
++)
195 imagelist_point_from_index( himl
, pos
+ n
, &pt
);
197 /* check if bitmap has an alpha channel */
198 for (i
= 0; i
< height
&& !has_alpha
; i
++)
199 for (j
= n
* width
; j
< (n
+ 1) * width
; j
++)
200 if ((has_alpha
= ((bits
[i
* bm
.bmWidth
+ j
] & 0xff000000) != 0))) break;
202 if (!has_alpha
) /* generate alpha channel from the mask */
204 for (i
= 0; i
< height
; i
++)
205 for (j
= n
* width
; j
< (n
+ 1) * width
; j
++)
206 if (!mask_bits
|| !((mask_bits
[i
* mask_width
+ j
/ 8] << (j
% 8)) & 0x80))
207 bits
[i
* bm
.bmWidth
+ j
] |= 0xff000000;
209 bits
[i
* bm
.bmWidth
+ j
] = 0;
213 himl
->has_alpha
[pos
+ n
] = 1;
215 if (mask_info
&& himl
->hbmMask
) /* generate the mask from the alpha channel */
217 for (i
= 0; i
< height
; i
++)
218 for (j
= n
* width
; j
< (n
+ 1) * width
; j
++)
219 if ((bits
[i
* bm
.bmWidth
+ j
] >> 24) > 25) /* more than 10% alpha */
220 mask_bits
[i
* mask_width
+ j
/ 8] &= ~(0x80 >> (j
% 8));
222 mask_bits
[i
* mask_width
+ j
/ 8] |= 0x80 >> (j
% 8);
225 StretchDIBits( himl
->hdcImage
, pt
.x
, pt
.y
, himl
->cx
, himl
->cy
,
226 n
* width
, 0, width
, height
, bits
, info
, DIB_RGB_COLORS
, SRCCOPY
);
228 StretchDIBits( himl
->hdcMask
, pt
.x
, pt
.y
, himl
->cx
, himl
->cy
,
229 n
* width
, 0, width
, height
, mask_bits
, mask_info
, DIB_RGB_COLORS
, SRCCOPY
);
234 HeapFree( GetProcessHeap(), 0, info
);
235 HeapFree( GetProcessHeap(), 0, mask_info
);
236 HeapFree( GetProcessHeap(), 0, bits
);
237 HeapFree( GetProcessHeap(), 0, mask_bits
);
241 /*************************************************************************
242 * IMAGELIST_InternalExpandBitmaps [Internal]
244 * Expands the bitmaps of an image list by the given number of images.
247 * himl [I] handle to image list
248 * nImageCount [I] number of images to add
254 * This function CANNOT be used to reduce the number of images.
257 IMAGELIST_InternalExpandBitmaps(HIMAGELIST himl
, INT nImageCount
)
260 HBITMAP hbmNewBitmap
, hbmNull
;
264 TRACE("%p has allocated %d, max %d, grow %d images\n", himl
, himl
->cCurImage
, himl
->cMaxImage
, himl
->cGrow
);
266 if (himl
->cCurImage
+ nImageCount
< himl
->cMaxImage
)
269 nNewCount
= himl
->cMaxImage
+ max(nImageCount
, himl
->cGrow
) + 1;
271 imagelist_get_bitmap_size(himl
, nNewCount
, &sz
);
273 TRACE("Create expanded bitmaps : himl=%p x=%d y=%d count=%d\n", himl
, sz
.cx
, sz
.cy
, nNewCount
);
274 hdcBitmap
= CreateCompatibleDC (0);
276 hbmNewBitmap
= ImageList_CreateImage(hdcBitmap
, himl
, nNewCount
);
278 if (hbmNewBitmap
== 0)
279 ERR("creating new image bitmap (x=%d y=%d)!\n", sz
.cx
, sz
.cy
);
283 hbmNull
= SelectObject (hdcBitmap
, hbmNewBitmap
);
284 BitBlt (hdcBitmap
, 0, 0, sz
.cx
, sz
.cy
,
285 himl
->hdcImage
, 0, 0, SRCCOPY
);
286 SelectObject (hdcBitmap
, hbmNull
);
288 SelectObject (himl
->hdcImage
, hbmNewBitmap
);
289 DeleteObject (himl
->hbmImage
);
290 himl
->hbmImage
= hbmNewBitmap
;
292 if (himl
->flags
& ILC_MASK
)
294 hbmNewBitmap
= CreateBitmap (sz
.cx
, sz
.cy
, 1, 1, NULL
);
296 if (hbmNewBitmap
== 0)
297 ERR("creating new mask bitmap!\n");
301 hbmNull
= SelectObject (hdcBitmap
, hbmNewBitmap
);
302 BitBlt (hdcBitmap
, 0, 0, sz
.cx
, sz
.cy
,
303 himl
->hdcMask
, 0, 0, SRCCOPY
);
304 SelectObject (hdcBitmap
, hbmNull
);
306 SelectObject (himl
->hdcMask
, hbmNewBitmap
);
307 DeleteObject (himl
->hbmMask
);
308 himl
->hbmMask
= hbmNewBitmap
;
313 char *new_alpha
= HeapReAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, himl
->has_alpha
, nNewCount
);
314 if (new_alpha
) himl
->has_alpha
= new_alpha
;
317 HeapFree( GetProcessHeap(), 0, himl
->has_alpha
);
318 himl
->has_alpha
= NULL
;
322 himl
->cMaxImage
= nNewCount
;
324 DeleteDC (hdcBitmap
);
328 /*************************************************************************
329 * ImageList_Add [COMCTL32.@]
331 * Add an image or images to an image list.
334 * himl [I] handle to image list
335 * hbmImage [I] handle to image bitmap
336 * hbmMask [I] handle to mask bitmap
339 * Success: Index of the first new image.
344 ImageList_Add (HIMAGELIST himl
, HBITMAP hbmImage
, HBITMAP hbmMask
)
346 HDC hdcBitmap
, hdcTemp
= 0;
347 INT nFirstIndex
, nImageCount
, i
;
351 TRACE("himl=%p hbmimage=%p hbmmask=%p\n", himl
, hbmImage
, hbmMask
);
355 if (!GetObjectW(hbmImage
, sizeof(BITMAP
), &bmp
))
358 TRACE("himl %p, cCurImage %d, cMaxImage %d, cGrow %d, cx %d, cy %d\n",
359 himl
, himl
->cCurImage
, himl
->cMaxImage
, himl
->cGrow
, himl
->cx
, himl
->cy
);
361 nImageCount
= bmp
.bmWidth
/ himl
->cx
;
363 TRACE("%p has %d images (%d x %d)\n", hbmImage
, nImageCount
, bmp
.bmWidth
, bmp
.bmHeight
);
365 IMAGELIST_InternalExpandBitmaps(himl
, nImageCount
);
367 hdcBitmap
= CreateCompatibleDC(0);
369 SelectObject(hdcBitmap
, hbmImage
);
371 if (add_with_alpha( himl
, hdcBitmap
, himl
->cCurImage
, nImageCount
,
372 himl
->cx
, min( himl
->cy
, bmp
.bmHeight
), hbmImage
, hbmMask
))
377 hdcTemp
= CreateCompatibleDC(0);
378 SelectObject(hdcTemp
, hbmMask
);
381 for (i
=0; i
<nImageCount
; i
++)
383 imagelist_point_from_index( himl
, himl
->cCurImage
+ i
, &pt
);
385 /* Copy result to the imagelist
387 BitBlt( himl
->hdcImage
, pt
.x
, pt
.y
, himl
->cx
, bmp
.bmHeight
,
388 hdcBitmap
, i
*himl
->cx
, 0, SRCCOPY
);
393 BitBlt( himl
->hdcMask
, pt
.x
, pt
.y
, himl
->cx
, bmp
.bmHeight
,
394 hdcTemp
, i
*himl
->cx
, 0, SRCCOPY
);
396 /* Remove the background from the image
398 BitBlt( himl
->hdcImage
, pt
.x
, pt
.y
, himl
->cx
, bmp
.bmHeight
,
399 himl
->hdcMask
, pt
.x
, pt
.y
, 0x220326 ); /* NOTSRCAND */
401 if (hdcTemp
) DeleteDC(hdcTemp
);
406 nFirstIndex
= himl
->cCurImage
;
407 himl
->cCurImage
+= nImageCount
;
413 /*************************************************************************
414 * ImageList_AddIcon [COMCTL32.@]
416 * Adds an icon to an image list.
419 * himl [I] handle to image list
420 * hIcon [I] handle to icon
423 * Success: index of the new image
426 #undef ImageList_AddIcon
427 INT WINAPI
ImageList_AddIcon (HIMAGELIST himl
, HICON hIcon
)
429 return ImageList_ReplaceIcon (himl
, -1, hIcon
);
433 /*************************************************************************
434 * ImageList_AddMasked [COMCTL32.@]
436 * Adds an image or images to an image list and creates a mask from the
437 * specified bitmap using the mask color.
440 * himl [I] handle to image list.
441 * hBitmap [I] handle to bitmap
442 * clrMask [I] mask color.
445 * Success: Index of the first new image.
450 ImageList_AddMasked (HIMAGELIST himl
, HBITMAP hBitmap
, COLORREF clrMask
)
452 HDC hdcMask
, hdcBitmap
;
458 TRACE("himl=%p hbitmap=%p clrmask=%x\n", himl
, hBitmap
, clrMask
);
462 if (!GetObjectW(hBitmap
, sizeof(BITMAP
), &bmp
))
465 hdcBitmap
= CreateCompatibleDC(0);
466 SelectObject(hdcBitmap
, hBitmap
);
468 /* Create a temp Mask so we can remove the background of the Image */
469 hdcMask
= CreateCompatibleDC(0);
470 hMaskBitmap
= CreateBitmap(bmp
.bmWidth
, bmp
.bmHeight
, 1, 1, NULL
);
471 SelectObject(hdcMask
, hMaskBitmap
);
473 /* create monochrome image to the mask bitmap */
474 bkColor
= (clrMask
!= CLR_DEFAULT
) ? clrMask
: GetPixel (hdcBitmap
, 0, 0);
475 SetBkColor (hdcBitmap
, bkColor
);
476 BitBlt (hdcMask
, 0, 0, bmp
.bmWidth
, bmp
.bmHeight
, hdcBitmap
, 0, 0, SRCCOPY
);
478 SetBkColor(hdcBitmap
, RGB(255,255,255));
481 * Remove the background from the image
483 * WINDOWS BUG ALERT!!!!!!
484 * The statement below should not be done in common practice
485 * but this is how ImageList_AddMasked works in Windows.
486 * It overwrites the original bitmap passed, this was discovered
487 * by using the same bitmap to iterate the different styles
488 * on windows where it failed (BUT ImageList_Add is OK)
489 * This is here in case some apps rely on this bug
491 * Blt mode 0x220326 is NOTSRCAND
493 BitBlt(hdcBitmap
, 0, 0, bmp
.bmWidth
, bmp
.bmHeight
, hdcMask
, 0, 0, 0x220326);
498 ret
= ImageList_Add( himl
, hBitmap
, hMaskBitmap
);
500 DeleteObject(hMaskBitmap
);
505 /*************************************************************************
506 * ImageList_BeginDrag [COMCTL32.@]
508 * Creates a temporary image list that contains one image. It will be used
512 * himlTrack [I] handle to the source image list
513 * iTrack [I] index of the drag image in the source image list
514 * dxHotspot [I] X position of the hot spot of the drag image
515 * dyHotspot [I] Y position of the hot spot of the drag image
523 ImageList_BeginDrag (HIMAGELIST himlTrack
, INT iTrack
,
524 INT dxHotspot
, INT dyHotspot
)
528 TRACE("(himlTrack=%p iTrack=%d dx=%d dy=%d)\n", himlTrack
, iTrack
,
529 dxHotspot
, dyHotspot
);
531 if (!is_valid(himlTrack
))
534 if (InternalDrag
.himl
)
535 ImageList_EndDrag ();
540 InternalDrag
.himl
= ImageList_Create (cx
, cy
, himlTrack
->flags
, 1, 1);
541 if (InternalDrag
.himl
== NULL
) {
542 WARN("Error creating drag image list!\n");
546 InternalDrag
.dxHotspot
= dxHotspot
;
547 InternalDrag
.dyHotspot
= dyHotspot
;
550 BitBlt (InternalDrag
.himl
->hdcImage
, 0, 0, cx
, cy
, himlTrack
->hdcImage
, iTrack
* cx
, 0, SRCCOPY
);
553 BitBlt (InternalDrag
.himl
->hdcMask
, 0, 0, cx
, cy
, himlTrack
->hdcMask
, iTrack
* cx
, 0, SRCCOPY
);
555 InternalDrag
.himl
->cCurImage
= 1;
561 /*************************************************************************
562 * ImageList_Copy [COMCTL32.@]
564 * Copies an image of the source image list to an image of the
565 * destination image list. Images can be copied or swapped.
568 * himlDst [I] handle to the destination image list
569 * iDst [I] destination image index.
570 * himlSrc [I] handle to the source image list
571 * iSrc [I] source image index
572 * uFlags [I] flags for the copy operation
579 * Copying from one image list to another is possible. The original
580 * implementation just copies or swaps within one image list.
581 * Could this feature become a bug??? ;-)
585 ImageList_Copy (HIMAGELIST himlDst
, INT iDst
, HIMAGELIST himlSrc
,
586 INT iSrc
, UINT uFlags
)
590 TRACE("himlDst=%p iDst=%d himlSrc=%p iSrc=%d\n", himlDst
, iDst
, himlSrc
, iSrc
);
592 if (!is_valid(himlSrc
) || !is_valid(himlDst
))
594 if ((iDst
< 0) || (iDst
>= himlDst
->cCurImage
))
596 if ((iSrc
< 0) || (iSrc
>= himlSrc
->cCurImage
))
599 imagelist_point_from_index( himlDst
, iDst
, &ptDst
);
600 imagelist_point_from_index( himlSrc
, iSrc
, &ptSrc
);
602 if (uFlags
& ILCF_SWAP
) {
605 HBITMAP hbmTempImage
, hbmTempMask
;
607 hdcBmp
= CreateCompatibleDC (0);
609 /* create temporary bitmaps */
610 hbmTempImage
= CreateBitmap (himlSrc
->cx
, himlSrc
->cy
, 1,
611 himlSrc
->uBitsPixel
, NULL
);
612 hbmTempMask
= CreateBitmap (himlSrc
->cx
, himlSrc
->cy
, 1,
615 /* copy (and stretch) destination to temporary bitmaps.(save) */
617 SelectObject (hdcBmp
, hbmTempImage
);
618 StretchBlt (hdcBmp
, 0, 0, himlSrc
->cx
, himlSrc
->cy
,
619 himlDst
->hdcImage
, ptDst
.x
, ptDst
.y
, himlDst
->cx
, himlDst
->cy
,
622 SelectObject (hdcBmp
, hbmTempMask
);
623 StretchBlt (hdcBmp
, 0, 0, himlSrc
->cx
, himlSrc
->cy
,
624 himlDst
->hdcMask
, ptDst
.x
, ptDst
.y
, himlDst
->cx
, himlDst
->cy
,
627 /* copy (and stretch) source to destination */
629 StretchBlt (himlDst
->hdcImage
, ptDst
.x
, ptDst
.y
, himlDst
->cx
, himlDst
->cy
,
630 himlSrc
->hdcImage
, ptSrc
.x
, ptSrc
.y
, himlSrc
->cx
, himlSrc
->cy
,
633 StretchBlt (himlDst
->hdcMask
, ptDst
.x
, ptDst
.y
, himlDst
->cx
, himlDst
->cy
,
634 himlSrc
->hdcMask
, ptSrc
.x
, ptSrc
.y
, himlSrc
->cx
, himlSrc
->cy
,
637 /* copy (without stretching) temporary bitmaps to source (restore) */
639 BitBlt (himlSrc
->hdcMask
, ptSrc
.x
, ptSrc
.y
, himlSrc
->cx
, himlSrc
->cy
,
640 hdcBmp
, 0, 0, SRCCOPY
);
643 BitBlt (himlSrc
->hdcImage
, ptSrc
.x
, ptSrc
.y
, himlSrc
->cx
, himlSrc
->cy
,
644 hdcBmp
, 0, 0, SRCCOPY
);
645 /* delete temporary bitmaps */
646 DeleteObject (hbmTempMask
);
647 DeleteObject (hbmTempImage
);
652 StretchBlt (himlDst
->hdcImage
, ptDst
.x
, ptDst
.y
, himlDst
->cx
, himlDst
->cy
,
653 himlSrc
->hdcImage
, ptSrc
.x
, ptSrc
.y
, himlSrc
->cx
, himlSrc
->cy
,
657 StretchBlt (himlDst
->hdcMask
, ptDst
.x
, ptDst
.y
, himlDst
->cx
, himlDst
->cy
,
658 himlSrc
->hdcMask
, ptSrc
.x
, ptSrc
.y
, himlSrc
->cx
, himlSrc
->cy
,
666 /*************************************************************************
667 * ImageList_Create [COMCTL32.@]
669 * Creates a new image list.
672 * cx [I] image height
674 * flags [I] creation flags
675 * cInitial [I] initial number of images in the image list
676 * cGrow [I] number of images by which image list grows
679 * Success: Handle to the created image list
683 ImageList_Create (INT cx
, INT cy
, UINT flags
,
684 INT cInitial
, INT cGrow
)
689 UINT ilc
= (flags
& 0xFE);
690 static const WORD aBitBlend25
[] =
691 {0xAA, 0x00, 0x55, 0x00, 0xAA, 0x00, 0x55, 0x00};
693 static const WORD aBitBlend50
[] =
694 {0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA};
696 TRACE("(%d %d 0x%x %d %d)\n", cx
, cy
, flags
, cInitial
, cGrow
);
698 if (cx
<= 0 || cy
<= 0) return NULL
;
700 /* Create the IImageList interface for the image list */
701 if (FAILED(ImageListImpl_CreateInstance(NULL
, &IID_IImageList
, (void **)&himl
)))
704 cGrow
= (cGrow
< 4) ? 4 : (cGrow
+ 3) & ~3;
709 himl
->cMaxImage
= cInitial
+ 1;
710 himl
->cInitial
= cInitial
;
712 himl
->clrFg
= CLR_DEFAULT
;
713 himl
->clrBk
= CLR_NONE
;
715 /* initialize overlay mask indices */
716 for (nCount
= 0; nCount
< MAX_OVERLAYIMAGE
; nCount
++)
717 himl
->nOvlIdx
[nCount
] = -1;
719 /* Create Image & Mask DCs */
720 himl
->hdcImage
= CreateCompatibleDC (0);
723 if (himl
->flags
& ILC_MASK
){
724 himl
->hdcMask
= CreateCompatibleDC(0);
729 /* Default to ILC_COLOR4 if none of the ILC_COLOR* flags are specified */
730 if (ilc
== ILC_COLOR
)
733 if (ilc
>= ILC_COLOR4
&& ilc
<= ILC_COLOR32
)
734 himl
->uBitsPixel
= ilc
;
736 himl
->uBitsPixel
= (UINT
)GetDeviceCaps (himl
->hdcImage
, BITSPIXEL
);
738 if (himl
->cMaxImage
> 0) {
739 himl
->hbmImage
= ImageList_CreateImage(himl
->hdcImage
, himl
, himl
->cMaxImage
);
740 SelectObject(himl
->hdcImage
, himl
->hbmImage
);
744 if ((himl
->cMaxImage
> 0) && (himl
->flags
& ILC_MASK
)) {
747 imagelist_get_bitmap_size(himl
, himl
->cMaxImage
, &sz
);
748 himl
->hbmMask
= CreateBitmap (sz
.cx
, sz
.cy
, 1, 1, NULL
);
749 if (himl
->hbmMask
== 0) {
750 ERR("Error creating mask bitmap!\n");
753 SelectObject(himl
->hdcMask
, himl
->hbmMask
);
758 if (ilc
== ILC_COLOR32
)
759 himl
->has_alpha
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, himl
->cMaxImage
);
761 himl
->has_alpha
= NULL
;
763 /* create blending brushes */
764 hbmTemp
= CreateBitmap (8, 8, 1, 1, aBitBlend25
);
765 himl
->hbrBlend25
= CreatePatternBrush (hbmTemp
);
766 DeleteObject (hbmTemp
);
768 hbmTemp
= CreateBitmap (8, 8, 1, 1, aBitBlend50
);
769 himl
->hbrBlend50
= CreatePatternBrush (hbmTemp
);
770 DeleteObject (hbmTemp
);
772 TRACE("created imagelist %p\n", himl
);
776 ImageList_Destroy(himl
);
781 /*************************************************************************
782 * ImageList_Destroy [COMCTL32.@]
784 * Destroys an image list.
787 * himl [I] handle to image list
795 ImageList_Destroy (HIMAGELIST himl
)
800 IImageList_Release((IImageList
*) himl
);
805 /*************************************************************************
806 * ImageList_DragEnter [COMCTL32.@]
808 * Locks window update and displays the drag image at the given position.
811 * hwndLock [I] handle of the window that owns the drag image.
812 * x [I] X position of the drag image.
813 * y [I] Y position of the drag image.
820 * The position of the drag image is relative to the window, not
825 ImageList_DragEnter (HWND hwndLock
, INT x
, INT y
)
827 TRACE("(hwnd=%p x=%d y=%d)\n", hwndLock
, x
, y
);
829 if (!is_valid(InternalDrag
.himl
))
833 InternalDrag
.hwnd
= hwndLock
;
835 InternalDrag
.hwnd
= GetDesktopWindow ();
840 /* draw the drag image and save the background */
841 if (!ImageList_DragShowNolock(TRUE
)) {
849 /*************************************************************************
850 * ImageList_DragLeave [COMCTL32.@]
852 * Unlocks window update and hides the drag image.
855 * hwndLock [I] handle of the window that owns the drag image.
863 ImageList_DragLeave (HWND hwndLock
)
865 /* As we don't save drag info in the window this can lead to problems if
866 an app does not supply the same window as DragEnter */
868 InternalDrag.hwnd = hwndLock;
870 InternalDrag.hwnd = GetDesktopWindow (); */
872 hwndLock
= GetDesktopWindow();
873 if(InternalDrag
.hwnd
!= hwndLock
)
874 FIXME("DragLeave hWnd != DragEnter hWnd\n");
876 ImageList_DragShowNolock (FALSE
);
882 /*************************************************************************
883 * ImageList_InternalDragDraw [Internal]
885 * Draws the drag image.
888 * hdc [I] device context to draw into.
889 * x [I] X position of the drag image.
890 * y [I] Y position of the drag image.
897 * The position of the drag image is relative to the window, not
903 ImageList_InternalDragDraw (HDC hdc
, INT x
, INT y
)
905 IMAGELISTDRAWPARAMS imldp
;
907 ZeroMemory (&imldp
, sizeof(imldp
));
908 imldp
.cbSize
= sizeof(imldp
);
909 imldp
.himl
= InternalDrag
.himl
;
914 imldp
.rgbBk
= CLR_DEFAULT
;
915 imldp
.rgbFg
= CLR_DEFAULT
;
916 imldp
.fStyle
= ILD_NORMAL
;
917 imldp
.fState
= ILS_ALPHA
;
919 ImageList_DrawIndirect (&imldp
);
922 /*************************************************************************
923 * ImageList_DragMove [COMCTL32.@]
925 * Moves the drag image.
928 * x [I] X position of the drag image.
929 * y [I] Y position of the drag image.
936 * The position of the drag image is relative to the window, not
941 ImageList_DragMove (INT x
, INT y
)
943 TRACE("(x=%d y=%d)\n", x
, y
);
945 if (!is_valid(InternalDrag
.himl
))
948 /* draw/update the drag image */
949 if (InternalDrag
.bShow
) {
953 HBITMAP hbmOffScreen
;
954 INT origNewX
, origNewY
;
955 INT origOldX
, origOldY
;
956 INT origRegX
, origRegY
;
957 INT sizeRegX
, sizeRegY
;
960 /* calculate the update region */
961 origNewX
= x
- InternalDrag
.dxHotspot
;
962 origNewY
= y
- InternalDrag
.dyHotspot
;
963 origOldX
= InternalDrag
.x
- InternalDrag
.dxHotspot
;
964 origOldY
= InternalDrag
.y
- InternalDrag
.dyHotspot
;
965 origRegX
= min(origNewX
, origOldX
);
966 origRegY
= min(origNewY
, origOldY
);
967 sizeRegX
= InternalDrag
.himl
->cx
+ abs(x
- InternalDrag
.x
);
968 sizeRegY
= InternalDrag
.himl
->cy
+ abs(y
- InternalDrag
.y
);
970 hdcDrag
= GetDCEx(InternalDrag
.hwnd
, 0,
971 DCX_WINDOW
| DCX_CACHE
| DCX_LOCKWINDOWUPDATE
);
972 hdcOffScreen
= CreateCompatibleDC(hdcDrag
);
973 hdcBg
= CreateCompatibleDC(hdcDrag
);
975 hbmOffScreen
= CreateCompatibleBitmap(hdcDrag
, sizeRegX
, sizeRegY
);
976 SelectObject(hdcOffScreen
, hbmOffScreen
);
977 SelectObject(hdcBg
, InternalDrag
.hbmBg
);
979 /* get the actual background of the update region */
980 BitBlt(hdcOffScreen
, 0, 0, sizeRegX
, sizeRegY
, hdcDrag
,
981 origRegX
, origRegY
, SRCCOPY
);
982 /* erase the old image */
983 BitBlt(hdcOffScreen
, origOldX
- origRegX
, origOldY
- origRegY
,
984 InternalDrag
.himl
->cx
, InternalDrag
.himl
->cy
, hdcBg
, 0, 0,
986 /* save the background */
987 BitBlt(hdcBg
, 0, 0, InternalDrag
.himl
->cx
, InternalDrag
.himl
->cy
,
988 hdcOffScreen
, origNewX
- origRegX
, origNewY
- origRegY
, SRCCOPY
);
990 ImageList_InternalDragDraw(hdcOffScreen
, origNewX
- origRegX
,
991 origNewY
- origRegY
);
992 /* draw the update region to the screen */
993 BitBlt(hdcDrag
, origRegX
, origRegY
, sizeRegX
, sizeRegY
,
994 hdcOffScreen
, 0, 0, SRCCOPY
);
997 DeleteDC(hdcOffScreen
);
998 DeleteObject(hbmOffScreen
);
999 ReleaseDC(InternalDrag
.hwnd
, hdcDrag
);
1002 /* update the image position */
1010 /*************************************************************************
1011 * ImageList_DragShowNolock [COMCTL32.@]
1013 * Shows or hides the drag image.
1016 * bShow [I] TRUE shows the drag image, FALSE hides it.
1024 ImageList_DragShowNolock (BOOL bShow
)
1030 if (!is_valid(InternalDrag
.himl
))
1033 TRACE("bShow=0x%X!\n", bShow
);
1035 /* DragImage is already visible/hidden */
1036 if ((InternalDrag
.bShow
&& bShow
) || (!InternalDrag
.bShow
&& !bShow
)) {
1040 /* position of the origin of the DragImage */
1041 x
= InternalDrag
.x
- InternalDrag
.dxHotspot
;
1042 y
= InternalDrag
.y
- InternalDrag
.dyHotspot
;
1044 hdcDrag
= GetDCEx (InternalDrag
.hwnd
, 0,
1045 DCX_WINDOW
| DCX_CACHE
| DCX_LOCKWINDOWUPDATE
);
1050 hdcBg
= CreateCompatibleDC(hdcDrag
);
1051 if (!InternalDrag
.hbmBg
) {
1052 InternalDrag
.hbmBg
= CreateCompatibleBitmap(hdcDrag
,
1053 InternalDrag
.himl
->cx
, InternalDrag
.himl
->cy
);
1055 SelectObject(hdcBg
, InternalDrag
.hbmBg
);
1058 /* save the background */
1059 BitBlt(hdcBg
, 0, 0, InternalDrag
.himl
->cx
, InternalDrag
.himl
->cy
,
1060 hdcDrag
, x
, y
, SRCCOPY
);
1061 /* show the image */
1062 ImageList_InternalDragDraw(hdcDrag
, x
, y
);
1064 /* hide the image */
1065 BitBlt(hdcDrag
, x
, y
, InternalDrag
.himl
->cx
, InternalDrag
.himl
->cy
,
1066 hdcBg
, 0, 0, SRCCOPY
);
1069 InternalDrag
.bShow
= !InternalDrag
.bShow
;
1072 ReleaseDC (InternalDrag
.hwnd
, hdcDrag
);
1077 /*************************************************************************
1078 * ImageList_Draw [COMCTL32.@]
1083 * himl [I] handle to image list
1085 * hdc [I] handle to device context
1088 * fStyle [I] drawing flags
1099 ImageList_Draw (HIMAGELIST himl
, INT i
, HDC hdc
, INT x
, INT y
, UINT fStyle
)
1101 return ImageList_DrawEx (himl
, i
, hdc
, x
, y
, 0, 0,
1102 CLR_DEFAULT
, CLR_DEFAULT
, fStyle
);
1106 /*************************************************************************
1107 * ImageList_DrawEx [COMCTL32.@]
1109 * Draws an image and allows to use extended drawing features.
1112 * himl [I] handle to image list
1114 * hdc [I] handle to device context
1119 * rgbBk [I] background color
1120 * rgbFg [I] foreground color
1121 * fStyle [I] drawing flags
1128 * Calls ImageList_DrawIndirect.
1131 * ImageList_DrawIndirect.
1135 ImageList_DrawEx (HIMAGELIST himl
, INT i
, HDC hdc
, INT x
, INT y
,
1136 INT dx
, INT dy
, COLORREF rgbBk
, COLORREF rgbFg
,
1139 IMAGELISTDRAWPARAMS imldp
;
1141 ZeroMemory (&imldp
, sizeof(imldp
));
1142 imldp
.cbSize
= sizeof(imldp
);
1150 imldp
.rgbBk
= rgbBk
;
1151 imldp
.rgbFg
= rgbFg
;
1152 imldp
.fStyle
= fStyle
;
1154 return ImageList_DrawIndirect (&imldp
);
1158 static BOOL
alpha_blend_image( HIMAGELIST himl
, HDC dest_dc
, int dest_x
, int dest_y
,
1159 int src_x
, int src_y
, int cx
, int cy
, BLENDFUNCTION func
,
1160 UINT style
, COLORREF blend_col
)
1164 HBITMAP bmp
= 0, mask
= 0;
1166 void *bits
, *mask_bits
;
1170 if (!(hdc
= CreateCompatibleDC( 0 ))) return FALSE
;
1171 if (!(info
= HeapAlloc( GetProcessHeap(), 0, FIELD_OFFSET( BITMAPINFO
, bmiColors
[256] )))) goto done
;
1172 info
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
1173 info
->bmiHeader
.biWidth
= cx
;
1174 info
->bmiHeader
.biHeight
= cy
;
1175 info
->bmiHeader
.biPlanes
= 1;
1176 info
->bmiHeader
.biBitCount
= 32;
1177 info
->bmiHeader
.biCompression
= BI_RGB
;
1178 info
->bmiHeader
.biSizeImage
= cx
* cy
* 4;
1179 info
->bmiHeader
.biXPelsPerMeter
= 0;
1180 info
->bmiHeader
.biYPelsPerMeter
= 0;
1181 info
->bmiHeader
.biClrUsed
= 0;
1182 info
->bmiHeader
.biClrImportant
= 0;
1183 if (!(bmp
= CreateDIBSection( himl
->hdcImage
, info
, DIB_RGB_COLORS
, &bits
, 0, 0 ))) goto done
;
1184 SelectObject( hdc
, bmp
);
1185 BitBlt( hdc
, 0, 0, cx
, cy
, himl
->hdcImage
, src_x
, src_y
, SRCCOPY
);
1187 if (blend_col
!= CLR_NONE
)
1189 BYTE r
= GetRValue( blend_col
);
1190 BYTE g
= GetGValue( blend_col
);
1191 BYTE b
= GetBValue( blend_col
);
1193 if (style
& ILD_BLEND25
)
1195 for (i
= 0, ptr
= bits
; i
< cx
* cy
; i
++, ptr
++)
1196 *ptr
= ((*ptr
& 0xff000000) |
1197 ((((*ptr
& 0x00ff0000) * 3 + (r
<< 16)) / 4) & 0x00ff0000) |
1198 ((((*ptr
& 0x0000ff00) * 3 + (g
<< 8)) / 4) & 0x0000ff00) |
1199 ((((*ptr
& 0x000000ff) * 3 + (b
<< 0)) / 4) & 0x000000ff));
1201 else if (style
& ILD_BLEND50
)
1203 for (i
= 0, ptr
= bits
; i
< cx
* cy
; i
++, ptr
++)
1204 *ptr
= ((*ptr
& 0xff000000) |
1205 ((((*ptr
& 0x00ff0000) + (r
<< 16)) / 2) & 0x00ff0000) |
1206 ((((*ptr
& 0x0000ff00) + (g
<< 8)) / 2) & 0x0000ff00) |
1207 ((((*ptr
& 0x000000ff) + (b
<< 0)) / 2) & 0x000000ff));
1211 if (himl
->has_alpha
) /* we already have an alpha channel in this case */
1213 /* pre-multiply by the alpha channel */
1214 for (i
= 0, ptr
= bits
; i
< cx
* cy
; i
++, ptr
++)
1216 DWORD alpha
= *ptr
>> 24;
1217 *ptr
= ((*ptr
& 0xff000000) |
1218 (((*ptr
& 0x00ff0000) * alpha
/ 255) & 0x00ff0000) |
1219 (((*ptr
& 0x0000ff00) * alpha
/ 255) & 0x0000ff00) |
1220 (((*ptr
& 0x000000ff) * alpha
/ 255)));
1223 else if (himl
->hbmMask
)
1225 unsigned int width_bytes
= (cx
+ 31) / 32 * 4;
1226 /* generate alpha channel from the mask */
1227 info
->bmiHeader
.biBitCount
= 1;
1228 info
->bmiHeader
.biSizeImage
= width_bytes
* cy
;
1229 if (!(mask
= CreateDIBSection( himl
->hdcMask
, info
, DIB_RGB_COLORS
, &mask_bits
, 0, 0 )))
1231 SelectObject( hdc
, mask
);
1232 BitBlt( hdc
, 0, 0, cx
, cy
, himl
->hdcMask
, src_x
, src_y
, SRCCOPY
);
1233 SelectObject( hdc
, bmp
);
1234 for (i
= 0, ptr
= bits
; i
< cy
; i
++)
1235 for (j
= 0; j
< cx
; j
++, ptr
++)
1236 if ((((BYTE
*)mask_bits
)[i
* width_bytes
+ j
/ 8] << (j
% 8)) & 0x80) *ptr
= 0;
1237 else *ptr
|= 0xff000000;
1240 ret
= GdiAlphaBlend( dest_dc
, dest_x
, dest_y
, cx
, cy
, hdc
, 0, 0, cx
, cy
, func
);
1244 if (bmp
) DeleteObject( bmp
);
1245 if (mask
) DeleteObject( mask
);
1246 HeapFree( GetProcessHeap(), 0, info
);
1250 /*************************************************************************
1251 * ImageList_DrawIndirect [COMCTL32.@]
1253 * Draws an image using various parameters specified in pimldp.
1256 * pimldp [I] pointer to IMAGELISTDRAWPARAMS structure.
1264 ImageList_DrawIndirect (IMAGELISTDRAWPARAMS
*pimldp
)
1266 INT cx
, cy
, nOvlIdx
;
1267 DWORD fState
, dwRop
;
1269 COLORREF oldImageBk
, oldImageFg
;
1270 HDC hImageDC
, hImageListDC
, hMaskListDC
;
1271 HBITMAP hImageBmp
, hOldImageBmp
, hBlendMaskBmp
;
1272 BOOL bIsTransparent
, bBlend
, bResult
= FALSE
, bMask
;
1278 if (!pimldp
|| !(himl
= pimldp
->himl
)) return FALSE
;
1279 if (!is_valid(himl
)) return FALSE
;
1280 if ((pimldp
->i
< 0) || (pimldp
->i
>= himl
->cCurImage
)) return FALSE
;
1282 imagelist_point_from_index( himl
, pimldp
->i
, &pt
);
1283 pt
.x
+= pimldp
->xBitmap
;
1284 pt
.y
+= pimldp
->yBitmap
;
1286 fState
= pimldp
->cbSize
< sizeof(IMAGELISTDRAWPARAMS
) ? ILS_NORMAL
: pimldp
->fState
;
1287 fStyle
= pimldp
->fStyle
& ~ILD_OVERLAYMASK
;
1288 cx
= (pimldp
->cx
== 0) ? himl
->cx
: pimldp
->cx
;
1289 cy
= (pimldp
->cy
== 0) ? himl
->cy
: pimldp
->cy
;
1291 bIsTransparent
= (fStyle
& ILD_TRANSPARENT
);
1292 if( pimldp
->rgbBk
== CLR_NONE
)
1293 bIsTransparent
= TRUE
;
1294 if( ( pimldp
->rgbBk
== CLR_DEFAULT
) && ( himl
->clrBk
== CLR_NONE
) )
1295 bIsTransparent
= TRUE
;
1296 bMask
= (himl
->flags
& ILC_MASK
) && (fStyle
& ILD_MASK
) ;
1297 bBlend
= (fStyle
& (ILD_BLEND25
| ILD_BLEND50
) ) && !bMask
;
1299 TRACE("himl(%p) hbmMask(%p) iImage(%d) x(%d) y(%d) cx(%d) cy(%d)\n",
1300 himl
, himl
->hbmMask
, pimldp
->i
, pimldp
->x
, pimldp
->y
, cx
, cy
);
1302 /* we will use these DCs to access the images and masks in the ImageList */
1303 hImageListDC
= himl
->hdcImage
;
1304 hMaskListDC
= himl
->hdcMask
;
1306 /* these will accumulate the image and mask for the image we're drawing */
1307 hImageDC
= CreateCompatibleDC( pimldp
->hdcDst
);
1308 hImageBmp
= CreateCompatibleBitmap( pimldp
->hdcDst
, cx
, cy
);
1309 hBlendMaskBmp
= bBlend
? CreateBitmap(cx
, cy
, 1, 1, NULL
) : 0;
1311 /* Create a compatible DC. */
1312 if (!hImageListDC
|| !hImageDC
|| !hImageBmp
||
1313 (bBlend
&& !hBlendMaskBmp
) || (himl
->hbmMask
&& !hMaskListDC
))
1316 hOldImageBmp
= SelectObject(hImageDC
, hImageBmp
);
1319 * To obtain a transparent look, background color should be set
1320 * to white and foreground color to black when blitting the
1323 oldImageFg
= SetTextColor( hImageDC
, RGB( 0, 0, 0 ) );
1324 oldImageBk
= SetBkColor( hImageDC
, RGB( 0xff, 0xff, 0xff ) );
1326 has_alpha
= (himl
->has_alpha
&& himl
->has_alpha
[pimldp
->i
]);
1327 if (!bMask
&& (has_alpha
|| (fState
& ILS_ALPHA
)))
1329 COLORREF colour
, blend_col
= CLR_NONE
;
1334 blend_col
= pimldp
->rgbFg
;
1335 if (blend_col
== CLR_DEFAULT
) blend_col
= GetSysColor( COLOR_HIGHLIGHT
);
1336 else if (blend_col
== CLR_NONE
) blend_col
= GetTextColor( pimldp
->hdcDst
);
1339 func
.BlendOp
= AC_SRC_OVER
;
1340 func
.BlendFlags
= 0;
1341 func
.SourceConstantAlpha
= (fState
& ILS_ALPHA
) ? pimldp
->Frame
: 255;
1342 func
.AlphaFormat
= AC_SRC_ALPHA
;
1346 bResult
= alpha_blend_image( himl
, pimldp
->hdcDst
, pimldp
->x
, pimldp
->y
,
1347 pt
.x
, pt
.y
, cx
, cy
, func
, fStyle
, blend_col
);
1350 colour
= pimldp
->rgbBk
;
1351 if (colour
== CLR_DEFAULT
) colour
= himl
->clrBk
;
1352 if (colour
== CLR_NONE
) colour
= GetBkColor( pimldp
->hdcDst
);
1354 hOldBrush
= SelectObject (hImageDC
, CreateSolidBrush (colour
));
1355 PatBlt( hImageDC
, 0, 0, cx
, cy
, PATCOPY
);
1356 alpha_blend_image( himl
, hImageDC
, 0, 0, pt
.x
, pt
.y
, cx
, cy
, func
, fStyle
, blend_col
);
1357 DeleteObject (SelectObject (hImageDC
, hOldBrush
));
1358 bResult
= BitBlt( pimldp
->hdcDst
, pimldp
->x
, pimldp
->y
, cx
, cy
, hImageDC
, 0, 0, SRCCOPY
);
1363 * Draw the initial image
1366 if (himl
->hbmMask
) {
1367 hOldBrush
= SelectObject (hImageDC
, CreateSolidBrush (GetTextColor(pimldp
->hdcDst
)));
1368 PatBlt( hImageDC
, 0, 0, cx
, cy
, PATCOPY
);
1369 BitBlt(hImageDC
, 0, 0, cx
, cy
, hMaskListDC
, pt
.x
, pt
.y
, SRCPAINT
);
1370 DeleteObject (SelectObject (hImageDC
, hOldBrush
));
1371 if( bIsTransparent
)
1373 BitBlt ( pimldp
->hdcDst
, pimldp
->x
, pimldp
->y
, cx
, cy
, hImageDC
, 0, 0, SRCAND
);
1378 hOldBrush
= SelectObject (hImageDC
, GetStockObject(BLACK_BRUSH
));
1379 PatBlt( hImageDC
, 0, 0, cx
, cy
, PATCOPY
);
1380 SelectObject(hImageDC
, hOldBrush
);
1383 /* blend the image with the needed solid background */
1384 COLORREF colour
= RGB(0,0,0);
1386 if( !bIsTransparent
)
1388 colour
= pimldp
->rgbBk
;
1389 if( colour
== CLR_DEFAULT
)
1390 colour
= himl
->clrBk
;
1391 if( colour
== CLR_NONE
)
1392 colour
= GetBkColor(pimldp
->hdcDst
);
1395 hOldBrush
= SelectObject (hImageDC
, CreateSolidBrush (colour
));
1396 PatBlt( hImageDC
, 0, 0, cx
, cy
, PATCOPY
);
1399 BitBlt( hImageDC
, 0, 0, cx
, cy
, hMaskListDC
, pt
.x
, pt
.y
, SRCAND
);
1400 BitBlt( hImageDC
, 0, 0, cx
, cy
, hImageListDC
, pt
.x
, pt
.y
, SRCPAINT
);
1403 BitBlt( hImageDC
, 0, 0, cx
, cy
, hImageListDC
, pt
.x
, pt
.y
, SRCCOPY
);
1404 DeleteObject (SelectObject (hImageDC
, hOldBrush
));
1407 /* Time for blending, if required */
1410 COLORREF clrBlend
= pimldp
->rgbFg
;
1411 HDC hBlendMaskDC
= hImageListDC
;
1414 /* Create the blend Mask */
1415 hOldBitmap
= SelectObject(hBlendMaskDC
, hBlendMaskBmp
);
1416 hBlendBrush
= fStyle
& ILD_BLEND50
? himl
->hbrBlend50
: himl
->hbrBlend25
;
1417 hOldBrush
= SelectObject(hBlendMaskDC
, hBlendBrush
);
1418 PatBlt(hBlendMaskDC
, 0, 0, cx
, cy
, PATCOPY
);
1419 SelectObject(hBlendMaskDC
, hOldBrush
);
1421 /* Modify the blend mask if an Image Mask exist */
1423 BitBlt(hBlendMaskDC
, 0, 0, cx
, cy
, hMaskListDC
, pt
.x
, pt
.y
, 0x220326); /* NOTSRCAND */
1424 BitBlt(hBlendMaskDC
, 0, 0, cx
, cy
, hBlendMaskDC
, 0, 0, NOTSRCCOPY
);
1427 /* now apply blend to the current image given the BlendMask */
1428 if (clrBlend
== CLR_DEFAULT
) clrBlend
= GetSysColor (COLOR_HIGHLIGHT
);
1429 else if (clrBlend
== CLR_NONE
) clrBlend
= GetTextColor (pimldp
->hdcDst
);
1430 hOldBrush
= SelectObject (hImageDC
, CreateSolidBrush(clrBlend
));
1431 BitBlt (hImageDC
, 0, 0, cx
, cy
, hBlendMaskDC
, 0, 0, 0xB8074A); /* PSDPxax */
1432 DeleteObject(SelectObject(hImageDC
, hOldBrush
));
1433 SelectObject(hBlendMaskDC
, hOldBitmap
);
1436 /* Now do the overlay image, if any */
1437 nOvlIdx
= (pimldp
->fStyle
& ILD_OVERLAYMASK
) >> 8;
1438 if ( (nOvlIdx
>= 1) && (nOvlIdx
<= MAX_OVERLAYIMAGE
)) {
1439 nOvlIdx
= himl
->nOvlIdx
[nOvlIdx
- 1];
1440 if ((nOvlIdx
>= 0) && (nOvlIdx
< himl
->cCurImage
)) {
1442 imagelist_point_from_index( himl
, nOvlIdx
, &ptOvl
);
1443 ptOvl
.x
+= pimldp
->xBitmap
;
1444 if (himl
->hbmMask
&& !(fStyle
& ILD_IMAGE
))
1445 BitBlt (hImageDC
, 0, 0, cx
, cy
, hMaskListDC
, ptOvl
.x
, ptOvl
.y
, SRCAND
);
1446 BitBlt (hImageDC
, 0, 0, cx
, cy
, hImageListDC
, ptOvl
.x
, ptOvl
.y
, SRCPAINT
);
1450 if (fState
& ILS_SATURATE
) FIXME("ILS_SATURATE: unimplemented!\n");
1451 if (fState
& ILS_GLOW
) FIXME("ILS_GLOW: unimplemented!\n");
1452 if (fState
& ILS_SHADOW
) FIXME("ILS_SHADOW: unimplemented!\n");
1454 if (fStyle
& ILD_PRESERVEALPHA
) FIXME("ILD_PRESERVEALPHA: unimplemented!\n");
1455 if (fStyle
& ILD_SCALE
) FIXME("ILD_SCALE: unimplemented!\n");
1456 if (fStyle
& ILD_DPISCALE
) FIXME("ILD_DPISCALE: unimplemented!\n");
1458 /* now copy the image to the screen */
1460 if (himl
->hbmMask
&& bIsTransparent
) {
1461 COLORREF oldDstFg
= SetTextColor(pimldp
->hdcDst
, RGB( 0, 0, 0 ) );
1462 COLORREF oldDstBk
= SetBkColor(pimldp
->hdcDst
, RGB( 0xff, 0xff, 0xff ));
1463 BitBlt (pimldp
->hdcDst
, pimldp
->x
, pimldp
->y
, cx
, cy
, hMaskListDC
, pt
.x
, pt
.y
, SRCAND
);
1464 SetBkColor(pimldp
->hdcDst
, oldDstBk
);
1465 SetTextColor(pimldp
->hdcDst
, oldDstFg
);
1468 if (fStyle
& ILD_ROP
) dwRop
= pimldp
->dwRop
;
1469 BitBlt (pimldp
->hdcDst
, pimldp
->x
, pimldp
->y
, cx
, cy
, hImageDC
, 0, 0, dwRop
);
1473 /* cleanup the mess */
1474 SetBkColor(hImageDC
, oldImageBk
);
1475 SetTextColor(hImageDC
, oldImageFg
);
1476 SelectObject(hImageDC
, hOldImageBmp
);
1478 DeleteObject(hBlendMaskBmp
);
1479 DeleteObject(hImageBmp
);
1486 /*************************************************************************
1487 * ImageList_Duplicate [COMCTL32.@]
1489 * Duplicates an image list.
1492 * himlSrc [I] source image list handle
1495 * Success: Handle of duplicated image list.
1500 ImageList_Duplicate (HIMAGELIST himlSrc
)
1504 if (!is_valid(himlSrc
)) {
1505 ERR("Invalid image list handle!\n");
1509 himlDst
= ImageList_Create (himlSrc
->cx
, himlSrc
->cy
, himlSrc
->flags
,
1510 himlSrc
->cCurImage
, himlSrc
->cGrow
);
1516 imagelist_get_bitmap_size(himlSrc
, himlSrc
->cCurImage
, &sz
);
1517 BitBlt (himlDst
->hdcImage
, 0, 0, sz
.cx
, sz
.cy
,
1518 himlSrc
->hdcImage
, 0, 0, SRCCOPY
);
1520 if (himlDst
->hbmMask
)
1521 BitBlt (himlDst
->hdcMask
, 0, 0, sz
.cx
, sz
.cy
,
1522 himlSrc
->hdcMask
, 0, 0, SRCCOPY
);
1524 himlDst
->cCurImage
= himlSrc
->cCurImage
;
1525 if (himlSrc
->has_alpha
&& himlDst
->has_alpha
)
1526 memcpy( himlDst
->has_alpha
, himlSrc
->has_alpha
, himlDst
->cCurImage
);
1532 /*************************************************************************
1533 * ImageList_EndDrag [COMCTL32.@]
1535 * Finishes a drag operation.
1546 ImageList_EndDrag (void)
1548 /* cleanup the InternalDrag struct */
1549 InternalDrag
.hwnd
= 0;
1550 ImageList_Destroy (InternalDrag
.himl
);
1551 InternalDrag
.himl
= 0;
1554 InternalDrag
.dxHotspot
= 0;
1555 InternalDrag
.dyHotspot
= 0;
1556 InternalDrag
.bShow
= FALSE
;
1557 DeleteObject(InternalDrag
.hbmBg
);
1558 InternalDrag
.hbmBg
= 0;
1562 /*************************************************************************
1563 * ImageList_GetBkColor [COMCTL32.@]
1565 * Returns the background color of an image list.
1568 * himl [I] Image list handle.
1571 * Success: background color
1576 ImageList_GetBkColor (HIMAGELIST himl
)
1578 return himl
? himl
->clrBk
: CLR_NONE
;
1582 /*************************************************************************
1583 * ImageList_GetDragImage [COMCTL32.@]
1585 * Returns the handle to the internal drag image list.
1588 * ppt [O] Pointer to the drag position. Can be NULL.
1589 * pptHotspot [O] Pointer to the position of the hot spot. Can be NULL.
1592 * Success: Handle of the drag image list.
1597 ImageList_GetDragImage (POINT
*ppt
, POINT
*pptHotspot
)
1599 if (is_valid(InternalDrag
.himl
)) {
1601 ppt
->x
= InternalDrag
.x
;
1602 ppt
->y
= InternalDrag
.y
;
1605 pptHotspot
->x
= InternalDrag
.dxHotspot
;
1606 pptHotspot
->y
= InternalDrag
.dyHotspot
;
1608 return (InternalDrag
.himl
);
1615 /*************************************************************************
1616 * ImageList_GetFlags [COMCTL32.@]
1618 * Gets the flags of the specified image list.
1621 * himl [I] Handle to image list
1631 ImageList_GetFlags(HIMAGELIST himl
)
1633 TRACE("%p\n", himl
);
1635 return is_valid(himl
) ? himl
->flags
: 0;
1639 /*************************************************************************
1640 * ImageList_GetIcon [COMCTL32.@]
1642 * Creates an icon from a masked image of an image list.
1645 * himl [I] handle to image list
1647 * flags [I] drawing style flags
1650 * Success: icon handle
1655 ImageList_GetIcon (HIMAGELIST himl
, INT i
, UINT fStyle
)
1659 HBITMAP hOldDstBitmap
;
1663 TRACE("%p %d %d\n", himl
, i
, fStyle
);
1664 if (!is_valid(himl
) || (i
< 0) || (i
>= himl
->cCurImage
)) return NULL
;
1670 /* create colour bitmap */
1672 ii
.hbmColor
= CreateCompatibleBitmap(hdcDst
, himl
->cx
, himl
->cy
);
1673 ReleaseDC(0, hdcDst
);
1675 hdcDst
= CreateCompatibleDC(0);
1677 imagelist_point_from_index( himl
, i
, &pt
);
1680 ii
.hbmMask
= CreateBitmap (himl
->cx
, himl
->cy
, 1, 1, NULL
);
1681 hOldDstBitmap
= SelectObject (hdcDst
, ii
.hbmMask
);
1682 if (himl
->hbmMask
) {
1683 BitBlt (hdcDst
, 0, 0, himl
->cx
, himl
->cy
,
1684 himl
->hdcMask
, pt
.x
, pt
.y
, SRCCOPY
);
1687 PatBlt (hdcDst
, 0, 0, himl
->cx
, himl
->cy
, BLACKNESS
);
1690 SelectObject (hdcDst
, ii
.hbmColor
);
1691 BitBlt (hdcDst
, 0, 0, himl
->cx
, himl
->cy
,
1692 himl
->hdcImage
, pt
.x
, pt
.y
, SRCCOPY
);
1695 * CreateIconIndirect requires us to deselect the bitmaps from
1696 * the DCs before calling
1698 SelectObject(hdcDst
, hOldDstBitmap
);
1700 hIcon
= CreateIconIndirect (&ii
);
1702 DeleteObject (ii
.hbmMask
);
1703 DeleteObject (ii
.hbmColor
);
1710 /*************************************************************************
1711 * ImageList_GetIconSize [COMCTL32.@]
1713 * Retrieves the size of an image in an image list.
1716 * himl [I] handle to image list
1717 * cx [O] pointer to the image width.
1718 * cy [O] pointer to the image height.
1725 * All images in an image list have the same size.
1729 ImageList_GetIconSize (HIMAGELIST himl
, INT
*cx
, INT
*cy
)
1731 if (!is_valid(himl
) || !cx
|| !cy
)
1733 if ((himl
->cx
<= 0) || (himl
->cy
<= 0))
1743 /*************************************************************************
1744 * ImageList_GetImageCount [COMCTL32.@]
1746 * Returns the number of images in an image list.
1749 * himl [I] handle to image list
1752 * Success: Number of images.
1757 ImageList_GetImageCount (HIMAGELIST himl
)
1759 if (!is_valid(himl
))
1762 return himl
->cCurImage
;
1766 /*************************************************************************
1767 * ImageList_GetImageInfo [COMCTL32.@]
1769 * Returns information about an image in an image list.
1772 * himl [I] handle to image list
1774 * pImageInfo [O] pointer to the image information
1782 ImageList_GetImageInfo (HIMAGELIST himl
, INT i
, IMAGEINFO
*pImageInfo
)
1786 if (!is_valid(himl
) || (pImageInfo
== NULL
))
1788 if ((i
< 0) || (i
>= himl
->cCurImage
))
1791 pImageInfo
->hbmImage
= himl
->hbmImage
;
1792 pImageInfo
->hbmMask
= himl
->hbmMask
;
1794 imagelist_point_from_index( himl
, i
, &pt
);
1795 pImageInfo
->rcImage
.top
= pt
.y
;
1796 pImageInfo
->rcImage
.bottom
= pt
.y
+ himl
->cy
;
1797 pImageInfo
->rcImage
.left
= pt
.x
;
1798 pImageInfo
->rcImage
.right
= pt
.x
+ himl
->cx
;
1804 /*************************************************************************
1805 * ImageList_GetImageRect [COMCTL32.@]
1807 * Retrieves the rectangle of the specified image in an image list.
1810 * himl [I] handle to image list
1812 * lpRect [O] pointer to the image rectangle
1819 * This is an UNDOCUMENTED function!!!
1823 ImageList_GetImageRect (HIMAGELIST himl
, INT i
, LPRECT lpRect
)
1827 if (!is_valid(himl
) || (lpRect
== NULL
))
1829 if ((i
< 0) || (i
>= himl
->cCurImage
))
1832 imagelist_point_from_index( himl
, i
, &pt
);
1833 lpRect
->left
= pt
.x
;
1835 lpRect
->right
= pt
.x
+ himl
->cx
;
1836 lpRect
->bottom
= pt
.y
+ himl
->cy
;
1842 /*************************************************************************
1843 * ImageList_LoadImage [COMCTL32.@]
1844 * ImageList_LoadImageA [COMCTL32.@]
1846 * Creates an image list from a bitmap, icon or cursor.
1848 * See ImageList_LoadImageW.
1852 ImageList_LoadImageA (HINSTANCE hi
, LPCSTR lpbmp
, INT cx
, INT cGrow
,
1853 COLORREF clrMask
, UINT uType
, UINT uFlags
)
1859 if (IS_INTRESOURCE(lpbmp
))
1860 return ImageList_LoadImageW(hi
, (LPCWSTR
)lpbmp
, cx
, cGrow
, clrMask
,
1863 len
= MultiByteToWideChar(CP_ACP
, 0, lpbmp
, -1, NULL
, 0);
1864 lpbmpW
= Alloc(len
* sizeof(WCHAR
));
1865 MultiByteToWideChar(CP_ACP
, 0, lpbmp
, -1, lpbmpW
, len
);
1867 himl
= ImageList_LoadImageW(hi
, lpbmpW
, cx
, cGrow
, clrMask
, uType
, uFlags
);
1873 /*************************************************************************
1874 * ImageList_LoadImageW [COMCTL32.@]
1876 * Creates an image list from a bitmap, icon or cursor.
1879 * hi [I] instance handle
1880 * lpbmp [I] name or id of the image
1881 * cx [I] width of each image
1882 * cGrow [I] number of images to expand
1883 * clrMask [I] mask color
1884 * uType [I] type of image to load
1885 * uFlags [I] loading flags
1888 * Success: handle to the loaded image list
1896 ImageList_LoadImageW (HINSTANCE hi
, LPCWSTR lpbmp
, INT cx
, INT cGrow
,
1897 COLORREF clrMask
, UINT uType
, UINT uFlags
)
1899 HIMAGELIST himl
= NULL
;
1903 handle
= LoadImageW (hi
, lpbmp
, uType
, 0, 0, uFlags
);
1905 WARN("Couldn't load image\n");
1909 if (uType
== IMAGE_BITMAP
) {
1913 if (GetObjectW (handle
, sizeof(dib
), &dib
) == sizeof(BITMAP
)) color
= ILC_COLOR
;
1914 else color
= dib
.dsBm
.bmBitsPixel
;
1916 /* To match windows behavior, if cx is set to zero and
1917 the flag DI_DEFAULTSIZE is specified, cx becomes the
1918 system metric value for icons. If the flag is not specified
1919 the function sets the size to the height of the bitmap */
1922 if (uFlags
& DI_DEFAULTSIZE
)
1923 cx
= GetSystemMetrics (SM_CXICON
);
1925 cx
= dib
.dsBm
.bmHeight
;
1928 nImageCount
= dib
.dsBm
.bmWidth
/ cx
;
1930 himl
= ImageList_Create (cx
, dib
.dsBm
.bmHeight
, ILC_MASK
| color
, nImageCount
, cGrow
);
1932 DeleteObject (handle
);
1935 ImageList_AddMasked (himl
, handle
, clrMask
);
1937 else if ((uType
== IMAGE_ICON
) || (uType
== IMAGE_CURSOR
)) {
1941 GetIconInfo (handle
, &ii
);
1942 GetObjectW (ii
.hbmColor
, sizeof(BITMAP
), &bmp
);
1943 himl
= ImageList_Create (bmp
.bmWidth
, bmp
.bmHeight
,
1944 ILC_MASK
| ILC_COLOR
, 1, cGrow
);
1946 DeleteObject (ii
.hbmColor
);
1947 DeleteObject (ii
.hbmMask
);
1948 DeleteObject (handle
);
1951 ImageList_Add (himl
, ii
.hbmColor
, ii
.hbmMask
);
1952 DeleteObject (ii
.hbmColor
);
1953 DeleteObject (ii
.hbmMask
);
1956 DeleteObject (handle
);
1962 /*************************************************************************
1963 * ImageList_Merge [COMCTL32.@]
1965 * Create an image list containing a merged image from two image lists.
1968 * himl1 [I] handle to first image list
1969 * i1 [I] first image index
1970 * himl2 [I] handle to second image list
1971 * i2 [I] second image index
1972 * dx [I] X offset of the second image relative to the first.
1973 * dy [I] Y offset of the second image relative to the first.
1976 * Success: The newly created image list. It contains a single image
1977 * consisting of the second image merged with the first.
1978 * Failure: NULL, if either himl1 or himl2 are invalid.
1981 * - The returned image list should be deleted by the caller using
1982 * ImageList_Destroy() when it is no longer required.
1983 * - If either i1 or i2 are not valid image indices they will be treated
1987 ImageList_Merge (HIMAGELIST himl1
, INT i1
, HIMAGELIST himl2
, INT i2
,
1990 HIMAGELIST himlDst
= NULL
;
1992 INT xOff1
, yOff1
, xOff2
, yOff2
;
1995 TRACE("(himl1=%p i1=%d himl2=%p i2=%d dx=%d dy=%d)\n", himl1
, i1
, himl2
,
1998 if (!is_valid(himl1
) || !is_valid(himl2
))
2002 cxDst
= max (himl1
->cx
, dx
+ himl2
->cx
);
2007 cxDst
= max (himl2
->cx
, himl1
->cx
- dx
);
2012 cxDst
= max (himl1
->cx
, himl2
->cx
);
2018 cyDst
= max (himl1
->cy
, dy
+ himl2
->cy
);
2023 cyDst
= max (himl2
->cy
, himl1
->cy
- dy
);
2028 cyDst
= max (himl1
->cy
, himl2
->cy
);
2033 himlDst
= ImageList_Create (cxDst
, cyDst
, ILC_MASK
| ILC_COLOR
, 1, 1);
2037 imagelist_point_from_index( himl1
, i1
, &pt1
);
2038 imagelist_point_from_index( himl2
, i2
, &pt2
);
2041 BitBlt (himlDst
->hdcImage
, 0, 0, cxDst
, cyDst
, himl1
->hdcImage
, 0, 0, BLACKNESS
);
2042 if (i1
>= 0 && i1
< himl1
->cCurImage
)
2043 BitBlt (himlDst
->hdcImage
, xOff1
, yOff1
, himl1
->cx
, himl1
->cy
, himl1
->hdcImage
, pt1
.x
, pt1
.y
, SRCCOPY
);
2044 if (i2
>= 0 && i2
< himl2
->cCurImage
)
2046 BitBlt (himlDst
->hdcImage
, xOff2
, yOff2
, himl2
->cx
, himl2
->cy
, himl2
->hdcMask
, pt2
.x
, pt2
.y
, SRCAND
);
2047 BitBlt (himlDst
->hdcImage
, xOff2
, yOff2
, himl2
->cx
, himl2
->cy
, himl2
->hdcImage
, pt2
.x
, pt2
.y
, SRCPAINT
);
2051 BitBlt (himlDst
->hdcMask
, 0, 0, cxDst
, cyDst
, himl1
->hdcMask
, 0, 0, WHITENESS
);
2052 if (i1
>= 0 && i1
< himl1
->cCurImage
)
2053 BitBlt (himlDst
->hdcMask
, xOff1
, yOff1
, himl1
->cx
, himl1
->cy
, himl1
->hdcMask
, pt1
.x
, pt1
.y
, SRCCOPY
);
2054 if (i2
>= 0 && i2
< himl2
->cCurImage
)
2055 BitBlt (himlDst
->hdcMask
, xOff2
, yOff2
, himl2
->cx
, himl2
->cy
, himl2
->hdcMask
, pt2
.x
, pt2
.y
, SRCAND
);
2057 himlDst
->cCurImage
= 1;
2064 /***********************************************************************
2065 * DIB_GetDIBImageBytes
2067 * Return the number of bytes used to hold the image in a DIB bitmap.
2069 static int DIB_GetDIBImageBytes( int width
, int height
, int depth
)
2071 return (((width
* depth
+ 31) / 8) & ~3) * abs( height
);
2075 /* helper for ImageList_Read, see comments below */
2076 static BOOL
_read_bitmap(HDC hdcIml
, LPSTREAM pstm
)
2078 BITMAPFILEHEADER bmfh
;
2079 int bitsperpixel
, palspace
;
2080 char bmi_buf
[sizeof(BITMAPINFOHEADER
) + sizeof(RGBQUAD
) * 256];
2081 LPBITMAPINFO bmi
= (LPBITMAPINFO
)bmi_buf
;
2085 if (FAILED(IStream_Read ( pstm
, &bmfh
, sizeof(bmfh
), NULL
)))
2088 if (bmfh
.bfType
!= (('M'<<8)|'B'))
2091 if (FAILED(IStream_Read ( pstm
, &bmi
->bmiHeader
, sizeof(bmi
->bmiHeader
), NULL
)))
2094 if ((bmi
->bmiHeader
.biSize
!= sizeof(bmi
->bmiHeader
)))
2097 TRACE("width %u, height %u, planes %u, bpp %u\n",
2098 bmi
->bmiHeader
.biWidth
, bmi
->bmiHeader
.biHeight
,
2099 bmi
->bmiHeader
.biPlanes
, bmi
->bmiHeader
.biBitCount
);
2101 bitsperpixel
= bmi
->bmiHeader
.biPlanes
* bmi
->bmiHeader
.biBitCount
;
2102 if (bitsperpixel
<=8)
2103 palspace
= (1<<bitsperpixel
)*sizeof(RGBQUAD
);
2107 bmi
->bmiHeader
.biSizeImage
= DIB_GetDIBImageBytes(bmi
->bmiHeader
.biWidth
, bmi
->bmiHeader
.biHeight
, bitsperpixel
);
2109 /* read the palette right after the end of the bitmapinfoheader */
2110 if (palspace
&& FAILED(IStream_Read(pstm
, bmi
->bmiColors
, palspace
, NULL
)))
2113 bits
= Alloc(bmi
->bmiHeader
.biSizeImage
);
2116 if (FAILED(IStream_Read(pstm
, bits
, bmi
->bmiHeader
.biSizeImage
, NULL
)))
2119 if (!StretchDIBits(hdcIml
, 0, 0, bmi
->bmiHeader
.biWidth
, bmi
->bmiHeader
.biHeight
,
2120 0, 0, bmi
->bmiHeader
.biWidth
, bmi
->bmiHeader
.biHeight
,
2121 bits
, bmi
, DIB_RGB_COLORS
, SRCCOPY
))
2130 /*************************************************************************
2131 * ImageList_Read [COMCTL32.@]
2133 * Reads an image list from a stream.
2136 * pstm [I] pointer to a stream
2139 * Success: handle to image list
2142 * The format is like this:
2143 * ILHEAD ilheadstruct;
2145 * for the color image part:
2146 * BITMAPFILEHEADER bmfh;
2147 * BITMAPINFOHEADER bmih;
2148 * only if it has a palette:
2149 * RGBQUAD rgbs[nr_of_paletted_colors];
2151 * BYTE colorbits[imagesize];
2153 * the following only if the ILC_MASK bit is set in ILHEAD.ilFlags:
2154 * BITMAPFILEHEADER bmfh_mask;
2155 * BITMAPINFOHEADER bmih_mask;
2156 * only if it has a palette (it usually does not):
2157 * RGBQUAD rgbs[nr_of_paletted_colors];
2159 * BYTE maskbits[imagesize];
2161 HIMAGELIST WINAPI
ImageList_Read (LPSTREAM pstm
)
2167 TRACE("%p\n", pstm
);
2169 if (FAILED(IStream_Read (pstm
, &ilHead
, sizeof(ILHEAD
), NULL
)))
2171 if (ilHead
.usMagic
!= (('L' << 8) | 'I'))
2173 if (ilHead
.usVersion
!= 0x101) /* probably version? */
2176 TRACE("cx %u, cy %u, flags 0x%04x, cCurImage %u, cMaxImage %u\n",
2177 ilHead
.cx
, ilHead
.cy
, ilHead
.flags
, ilHead
.cCurImage
, ilHead
.cMaxImage
);
2179 himl
= ImageList_Create(ilHead
.cx
, ilHead
.cy
, ilHead
.flags
, ilHead
.cCurImage
, ilHead
.cMaxImage
);
2183 if (!_read_bitmap(himl
->hdcImage
, pstm
))
2185 WARN("failed to read bitmap from stream\n");
2188 if (ilHead
.flags
& ILC_MASK
)
2190 if (!_read_bitmap(himl
->hdcMask
, pstm
))
2192 WARN("failed to read mask bitmap from stream\n");
2197 himl
->cCurImage
= ilHead
.cCurImage
;
2198 himl
->cMaxImage
= ilHead
.cMaxImage
;
2200 ImageList_SetBkColor(himl
,ilHead
.bkcolor
);
2202 ImageList_SetOverlayImage(himl
,ilHead
.ovls
[i
],i
+1);
2207 /*************************************************************************
2208 * ImageList_Remove [COMCTL32.@]
2210 * Removes an image from an image list
2213 * himl [I] image list handle
2220 * FIXME: as the image list storage test shows, native comctl32 simply shifts
2221 * images without creating a new bitmap.
2224 ImageList_Remove (HIMAGELIST himl
, INT i
)
2226 HBITMAP hbmNewImage
, hbmNewMask
;
2230 TRACE("(himl=%p i=%d)\n", himl
, i
);
2232 if (!is_valid(himl
)) {
2233 ERR("Invalid image list handle!\n");
2237 if ((i
< -1) || (i
>= himl
->cCurImage
)) {
2238 TRACE("index out of range! %d\n", i
);
2246 if (himl
->cCurImage
== 0) {
2247 /* remove all on empty ImageList is allowed */
2248 TRACE("remove all on empty ImageList!\n");
2252 himl
->cMaxImage
= himl
->cInitial
+ himl
->cGrow
- 1;
2253 himl
->cCurImage
= 0;
2254 for (nCount
= 0; nCount
< MAX_OVERLAYIMAGE
; nCount
++)
2255 himl
->nOvlIdx
[nCount
] = -1;
2257 hbmNewImage
= ImageList_CreateImage(himl
->hdcImage
, himl
, himl
->cMaxImage
);
2258 SelectObject (himl
->hdcImage
, hbmNewImage
);
2259 DeleteObject (himl
->hbmImage
);
2260 himl
->hbmImage
= hbmNewImage
;
2262 if (himl
->hbmMask
) {
2264 imagelist_get_bitmap_size(himl
, himl
->cMaxImage
, &sz
);
2265 hbmNewMask
= CreateBitmap (sz
.cx
, sz
.cy
, 1, 1, NULL
);
2266 SelectObject (himl
->hdcMask
, hbmNewMask
);
2267 DeleteObject (himl
->hbmMask
);
2268 himl
->hbmMask
= hbmNewMask
;
2272 /* delete one image */
2273 TRACE("Remove single image! %d\n", i
);
2275 /* create new bitmap(s) */
2276 TRACE(" - Number of images: %d / %d (Old/New)\n",
2277 himl
->cCurImage
, himl
->cCurImage
- 1);
2279 hbmNewImage
= ImageList_CreateImage(himl
->hdcImage
, himl
, himl
->cMaxImage
);
2281 imagelist_get_bitmap_size(himl
, himl
->cMaxImage
, &sz
);
2283 hbmNewMask
= CreateBitmap (sz
.cx
, sz
.cy
, 1, 1, NULL
);
2285 hbmNewMask
= 0; /* Just to keep compiler happy! */
2287 hdcBmp
= CreateCompatibleDC (0);
2289 /* copy all images and masks prior to the "removed" image */
2291 TRACE("Pre image copy: Copy %d images\n", i
);
2293 SelectObject (hdcBmp
, hbmNewImage
);
2294 imagelist_copy_images( himl
, himl
->hdcImage
, hdcBmp
, 0, i
, 0 );
2296 if (himl
->hbmMask
) {
2297 SelectObject (hdcBmp
, hbmNewMask
);
2298 imagelist_copy_images( himl
, himl
->hdcMask
, hdcBmp
, 0, i
, 0 );
2302 /* copy all images and masks behind the removed image */
2303 if (i
< himl
->cCurImage
- 1) {
2304 TRACE("Post image copy!\n");
2306 SelectObject (hdcBmp
, hbmNewImage
);
2307 imagelist_copy_images( himl
, himl
->hdcImage
, hdcBmp
, i
+ 1,
2308 (himl
->cCurImage
- i
), i
);
2310 if (himl
->hbmMask
) {
2311 SelectObject (hdcBmp
, hbmNewMask
);
2312 imagelist_copy_images( himl
, himl
->hdcMask
, hdcBmp
, i
+ 1,
2313 (himl
->cCurImage
- i
), i
);
2319 /* delete old images and insert new ones */
2320 SelectObject (himl
->hdcImage
, hbmNewImage
);
2321 DeleteObject (himl
->hbmImage
);
2322 himl
->hbmImage
= hbmNewImage
;
2323 if (himl
->hbmMask
) {
2324 SelectObject (himl
->hdcMask
, hbmNewMask
);
2325 DeleteObject (himl
->hbmMask
);
2326 himl
->hbmMask
= hbmNewMask
;
2336 /*************************************************************************
2337 * ImageList_Replace [COMCTL32.@]
2339 * Replaces an image in an image list with a new image.
2342 * himl [I] handle to image list
2344 * hbmImage [I] handle to image bitmap
2345 * hbmMask [I] handle to mask bitmap. Can be NULL.
2353 ImageList_Replace (HIMAGELIST himl
, INT i
, HBITMAP hbmImage
,
2360 TRACE("%p %d %p %p\n", himl
, i
, hbmImage
, hbmMask
);
2362 if (!is_valid(himl
)) {
2363 ERR("Invalid image list handle!\n");
2367 if ((i
>= himl
->cMaxImage
) || (i
< 0)) {
2368 ERR("Invalid image index!\n");
2372 if (!GetObjectW(hbmImage
, sizeof(BITMAP
), &bmp
))
2375 hdcImage
= CreateCompatibleDC (0);
2378 SelectObject (hdcImage
, hbmImage
);
2380 if (add_with_alpha( himl
, hdcImage
, i
, 1, bmp
.bmWidth
, bmp
.bmHeight
, hbmImage
, hbmMask
))
2383 imagelist_point_from_index(himl
, i
, &pt
);
2384 StretchBlt (himl
->hdcImage
, pt
.x
, pt
.y
, himl
->cx
, himl
->cy
,
2385 hdcImage
, 0, 0, bmp
.bmWidth
, bmp
.bmHeight
, SRCCOPY
);
2390 HBITMAP hOldBitmapTemp
;
2392 hdcTemp
= CreateCompatibleDC(0);
2393 hOldBitmapTemp
= SelectObject(hdcTemp
, hbmMask
);
2395 StretchBlt (himl
->hdcMask
, pt
.x
, pt
.y
, himl
->cx
, himl
->cy
,
2396 hdcTemp
, 0, 0, bmp
.bmWidth
, bmp
.bmHeight
, SRCCOPY
);
2397 SelectObject(hdcTemp
, hOldBitmapTemp
);
2400 /* Remove the background from the image
2402 BitBlt (himl
->hdcImage
, pt
.x
, pt
.y
, bmp
.bmWidth
, bmp
.bmHeight
,
2403 himl
->hdcMask
, pt
.x
, pt
.y
, 0x220326); /* NOTSRCAND */
2407 DeleteDC (hdcImage
);
2413 /*************************************************************************
2414 * ImageList_ReplaceIcon [COMCTL32.@]
2416 * Replaces an image in an image list using an icon.
2419 * himl [I] handle to image list
2421 * hIcon [I] handle to icon
2424 * Success: index of the replaced image
2429 ImageList_ReplaceIcon (HIMAGELIST himl
, INT nIndex
, HICON hIcon
)
2438 TRACE("(%p %d %p)\n", himl
, nIndex
, hIcon
);
2440 if (!is_valid(himl
)) {
2441 ERR("invalid image list\n");
2444 if ((nIndex
>= himl
->cMaxImage
) || (nIndex
< -1)) {
2445 ERR("invalid image index %d / %d\n", nIndex
, himl
->cMaxImage
);
2449 hBestFitIcon
= CopyImage(
2452 LR_COPYFROMRESOURCE
);
2453 /* the above will fail if the icon wasn't loaded from a resource, so try
2454 * again without LR_COPYFROMRESOURCE flag */
2456 hBestFitIcon
= CopyImage(
2463 ret
= GetIconInfo (hBestFitIcon
, &ii
);
2465 DestroyIcon(hBestFitIcon
);
2469 ret
= GetObjectW (ii
.hbmMask
, sizeof(BITMAP
), &bmp
);
2471 ERR("couldn't get mask bitmap info\n");
2473 DeleteObject (ii
.hbmColor
);
2475 DeleteObject (ii
.hbmMask
);
2476 DestroyIcon(hBestFitIcon
);
2481 if (himl
->cCurImage
+ 1 > himl
->cMaxImage
)
2482 IMAGELIST_InternalExpandBitmaps(himl
, 1);
2484 nIndex
= himl
->cCurImage
;
2488 hdcImage
= CreateCompatibleDC (0);
2489 TRACE("hdcImage=%p\n", hdcImage
);
2491 ERR("invalid hdcImage!\n");
2493 if (himl
->has_alpha
)
2497 UINT height
= bmp
.bmHeight
/ 2;
2498 HDC hdcMask
= CreateCompatibleDC( 0 );
2499 HBITMAP color
= CreateBitmap( bmp
.bmWidth
, height
, 1, 1, NULL
);
2500 SelectObject( hdcImage
, color
);
2501 SelectObject( hdcMask
, ii
.hbmMask
);
2502 BitBlt( hdcImage
, 0, 0, bmp
.bmWidth
, height
, hdcMask
, 0, height
, SRCCOPY
);
2503 ret
= add_with_alpha( himl
, hdcImage
, nIndex
, 1, bmp
.bmWidth
, height
, color
, ii
.hbmMask
);
2504 DeleteDC( hdcMask
);
2505 DeleteObject( color
);
2508 else if (add_with_alpha( himl
, hdcImage
, nIndex
, 1, bmp
.bmWidth
, bmp
.bmHeight
,
2509 ii
.hbmColor
, ii
.hbmMask
)) goto done
;
2512 imagelist_point_from_index(himl
, nIndex
, &pt
);
2514 SetTextColor(himl
->hdcImage
, RGB(0,0,0));
2515 SetBkColor (himl
->hdcImage
, RGB(255,255,255));
2519 SelectObject (hdcImage
, ii
.hbmColor
);
2520 StretchBlt (himl
->hdcImage
, pt
.x
, pt
.y
, himl
->cx
, himl
->cy
,
2521 hdcImage
, 0, 0, bmp
.bmWidth
, bmp
.bmHeight
, SRCCOPY
);
2524 SelectObject (hdcImage
, ii
.hbmMask
);
2525 StretchBlt (himl
->hdcMask
, pt
.x
, pt
.y
, himl
->cx
, himl
->cy
,
2526 hdcImage
, 0, 0, bmp
.bmWidth
, bmp
.bmHeight
, SRCCOPY
);
2531 UINT height
= bmp
.bmHeight
/ 2;
2532 SelectObject (hdcImage
, ii
.hbmMask
);
2533 StretchBlt (himl
->hdcImage
, pt
.x
, pt
.y
, himl
->cx
, himl
->cy
,
2534 hdcImage
, 0, height
, bmp
.bmWidth
, height
, SRCCOPY
);
2536 StretchBlt (himl
->hdcMask
, pt
.x
, pt
.y
, himl
->cx
, himl
->cy
,
2537 hdcImage
, 0, 0, bmp
.bmWidth
, height
, SRCCOPY
);
2541 DestroyIcon(hBestFitIcon
);
2543 DeleteDC (hdcImage
);
2545 DeleteObject (ii
.hbmColor
);
2547 DeleteObject (ii
.hbmMask
);
2549 TRACE("Insert index = %d, himl->cCurImage = %d\n", nIndex
, himl
->cCurImage
);
2554 /*************************************************************************
2555 * ImageList_SetBkColor [COMCTL32.@]
2557 * Sets the background color of an image list.
2560 * himl [I] handle to image list
2561 * clrBk [I] background color
2564 * Success: previous background color
2569 ImageList_SetBkColor (HIMAGELIST himl
, COLORREF clrBk
)
2573 if (!is_valid(himl
))
2576 clrOldBk
= himl
->clrBk
;
2577 himl
->clrBk
= clrBk
;
2582 /*************************************************************************
2583 * ImageList_SetDragCursorImage [COMCTL32.@]
2585 * Combines the specified image with the current drag image
2588 * himlDrag [I] handle to drag image list
2589 * iDrag [I] drag image index
2590 * dxHotspot [I] X position of the hot spot
2591 * dyHotspot [I] Y position of the hot spot
2598 * - The names dxHotspot, dyHotspot are misleading because they have nothing
2599 * to do with a hotspot but are only the offset of the origin of the new
2600 * image relative to the origin of the old image.
2602 * - When this function is called and the drag image is visible, a
2603 * short flickering occurs but this matches the Win9x behavior. It is
2604 * possible to fix the flickering using code like in ImageList_DragMove.
2608 ImageList_SetDragCursorImage (HIMAGELIST himlDrag
, INT iDrag
,
2609 INT dxHotspot
, INT dyHotspot
)
2611 HIMAGELIST himlTemp
;
2614 if (!is_valid(InternalDrag
.himl
) || !is_valid(himlDrag
))
2617 TRACE(" dxH=%d dyH=%d nX=%d nY=%d\n",
2618 dxHotspot
, dyHotspot
, InternalDrag
.dxHotspot
, InternalDrag
.dyHotspot
);
2620 visible
= InternalDrag
.bShow
;
2622 himlTemp
= ImageList_Merge (InternalDrag
.himl
, 0, himlDrag
, iDrag
,
2623 dxHotspot
, dyHotspot
);
2626 /* hide the drag image */
2627 ImageList_DragShowNolock(FALSE
);
2629 if ((InternalDrag
.himl
->cx
!= himlTemp
->cx
) ||
2630 (InternalDrag
.himl
->cy
!= himlTemp
->cy
)) {
2631 /* the size of the drag image changed, invalidate the buffer */
2632 DeleteObject(InternalDrag
.hbmBg
);
2633 InternalDrag
.hbmBg
= 0;
2636 ImageList_Destroy (InternalDrag
.himl
);
2637 InternalDrag
.himl
= himlTemp
;
2640 /* show the drag image */
2641 ImageList_DragShowNolock(TRUE
);
2648 /*************************************************************************
2649 * ImageList_SetFilter [COMCTL32.@]
2651 * Sets a filter (or does something completely different)!!???
2652 * It removes 12 Bytes from the stack (3 Parameters).
2655 * himl [I] SHOULD be a handle to image list
2656 * i [I] COULD be an index?
2661 * Failure: FALSE ???
2664 * This is an UNDOCUMENTED function!!!!
2669 ImageList_SetFilter (HIMAGELIST himl
, INT i
, DWORD dwFilter
)
2671 FIXME("(%p 0x%x 0x%x):empty stub!\n", himl
, i
, dwFilter
);
2677 /*************************************************************************
2678 * ImageList_SetFlags [COMCTL32.@]
2680 * Sets the image list flags.
2683 * himl [I] Handle to image list
2684 * flags [I] Flags to set
2694 ImageList_SetFlags(HIMAGELIST himl
, DWORD flags
)
2696 FIXME("(%p %08x):empty stub\n", himl
, flags
);
2701 /*************************************************************************
2702 * ImageList_SetIconSize [COMCTL32.@]
2704 * Sets the image size of the bitmap and deletes all images.
2707 * himl [I] handle to image list
2708 * cx [I] image width
2709 * cy [I] image height
2717 ImageList_SetIconSize (HIMAGELIST himl
, INT cx
, INT cy
)
2722 if (!is_valid(himl
))
2725 /* remove all images */
2726 himl
->cMaxImage
= himl
->cInitial
+ 1;
2727 himl
->cCurImage
= 0;
2731 /* initialize overlay mask indices */
2732 for (nCount
= 0; nCount
< MAX_OVERLAYIMAGE
; nCount
++)
2733 himl
->nOvlIdx
[nCount
] = -1;
2735 hbmNew
= ImageList_CreateImage(himl
->hdcImage
, himl
, himl
->cMaxImage
);
2736 SelectObject (himl
->hdcImage
, hbmNew
);
2737 DeleteObject (himl
->hbmImage
);
2738 himl
->hbmImage
= hbmNew
;
2740 if (himl
->hbmMask
) {
2742 imagelist_get_bitmap_size(himl
, himl
->cMaxImage
, &sz
);
2743 hbmNew
= CreateBitmap (sz
.cx
, sz
.cy
, 1, 1, NULL
);
2744 SelectObject (himl
->hdcMask
, hbmNew
);
2745 DeleteObject (himl
->hbmMask
);
2746 himl
->hbmMask
= hbmNew
;
2753 /*************************************************************************
2754 * ImageList_SetImageCount [COMCTL32.@]
2756 * Resizes an image list to the specified number of images.
2759 * himl [I] handle to image list
2760 * iImageCount [I] number of images in the image list
2768 ImageList_SetImageCount (HIMAGELIST himl
, UINT iImageCount
)
2771 HBITMAP hbmNewBitmap
, hbmOld
;
2772 INT nNewCount
, nCopyCount
;
2774 TRACE("%p %d\n",himl
,iImageCount
);
2776 if (!is_valid(himl
))
2778 if (himl
->cMaxImage
> iImageCount
)
2780 himl
->cCurImage
= iImageCount
;
2781 /* TODO: shrink the bitmap when cMaxImage-cCurImage>cGrow ? */
2785 nNewCount
= iImageCount
+ himl
->cGrow
;
2786 nCopyCount
= min(himl
->cCurImage
, iImageCount
);
2788 hdcBitmap
= CreateCompatibleDC (0);
2790 hbmNewBitmap
= ImageList_CreateImage(hdcBitmap
, himl
, nNewCount
);
2792 if (hbmNewBitmap
!= 0)
2794 hbmOld
= SelectObject (hdcBitmap
, hbmNewBitmap
);
2795 imagelist_copy_images( himl
, himl
->hdcImage
, hdcBitmap
, 0, nCopyCount
, 0 );
2796 SelectObject (hdcBitmap
, hbmOld
);
2798 /* FIXME: delete 'empty' image space? */
2800 SelectObject (himl
->hdcImage
, hbmNewBitmap
);
2801 DeleteObject (himl
->hbmImage
);
2802 himl
->hbmImage
= hbmNewBitmap
;
2805 ERR("Could not create new image bitmap !\n");
2810 imagelist_get_bitmap_size( himl
, nNewCount
, &sz
);
2811 hbmNewBitmap
= CreateBitmap (sz
.cx
, sz
.cy
, 1, 1, NULL
);
2812 if (hbmNewBitmap
!= 0)
2814 hbmOld
= SelectObject (hdcBitmap
, hbmNewBitmap
);
2815 imagelist_copy_images( himl
, himl
->hdcMask
, hdcBitmap
, 0, nCopyCount
, 0 );
2816 SelectObject (hdcBitmap
, hbmOld
);
2818 /* FIXME: delete 'empty' image space? */
2820 SelectObject (himl
->hdcMask
, hbmNewBitmap
);
2821 DeleteObject (himl
->hbmMask
);
2822 himl
->hbmMask
= hbmNewBitmap
;
2825 ERR("Could not create new mask bitmap!\n");
2828 DeleteDC (hdcBitmap
);
2830 if (himl
->has_alpha
)
2832 char *new_alpha
= HeapReAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, himl
->has_alpha
, nNewCount
);
2833 if (new_alpha
) himl
->has_alpha
= new_alpha
;
2836 HeapFree( GetProcessHeap(), 0, himl
->has_alpha
);
2837 himl
->has_alpha
= NULL
;
2841 /* Update max image count and current image count */
2842 himl
->cMaxImage
= nNewCount
;
2843 himl
->cCurImage
= iImageCount
;
2849 /*************************************************************************
2850 * ImageList_SetOverlayImage [COMCTL32.@]
2852 * Assigns an overlay mask index to an existing image in an image list.
2855 * himl [I] handle to image list
2856 * iImage [I] image index
2857 * iOverlay [I] overlay mask index
2865 ImageList_SetOverlayImage (HIMAGELIST himl
, INT iImage
, INT iOverlay
)
2867 if (!is_valid(himl
))
2869 if ((iOverlay
< 1) || (iOverlay
> MAX_OVERLAYIMAGE
))
2871 if ((iImage
!=-1) && ((iImage
< 0) || (iImage
> himl
->cCurImage
)))
2873 himl
->nOvlIdx
[iOverlay
- 1] = iImage
;
2879 /* helper for ImageList_Write - write bitmap to pstm
2880 * currently everything is written as 24 bit RGB, except masks
2883 _write_bitmap(HBITMAP hBitmap
, LPSTREAM pstm
)
2885 LPBITMAPFILEHEADER bmfh
;
2886 LPBITMAPINFOHEADER bmih
;
2887 LPBYTE data
= NULL
, lpBits
;
2889 INT bitCount
, sizeImage
, offBits
, totalSize
;
2891 BOOL result
= FALSE
;
2893 if (!GetObjectW(hBitmap
, sizeof(BITMAP
), &bm
))
2896 bitCount
= bm
.bmBitsPixel
== 1 ? 1 : 24;
2897 sizeImage
= DIB_GetDIBImageBytes(bm
.bmWidth
, bm
.bmHeight
, bitCount
);
2899 totalSize
= sizeof(BITMAPFILEHEADER
) + sizeof(BITMAPINFOHEADER
);
2901 totalSize
+= (1 << bitCount
) * sizeof(RGBQUAD
);
2902 offBits
= totalSize
;
2903 totalSize
+= sizeImage
;
2905 data
= Alloc(totalSize
);
2906 bmfh
= (LPBITMAPFILEHEADER
)data
;
2907 bmih
= (LPBITMAPINFOHEADER
)(data
+ sizeof(BITMAPFILEHEADER
));
2908 lpBits
= data
+ offBits
;
2910 /* setup BITMAPFILEHEADER */
2911 bmfh
->bfType
= (('M' << 8) | 'B');
2912 bmfh
->bfSize
= offBits
;
2913 bmfh
->bfReserved1
= 0;
2914 bmfh
->bfReserved2
= 0;
2915 bmfh
->bfOffBits
= offBits
;
2917 /* setup BITMAPINFOHEADER */
2918 bmih
->biSize
= sizeof(BITMAPINFOHEADER
);
2919 bmih
->biWidth
= bm
.bmWidth
;
2920 bmih
->biHeight
= bm
.bmHeight
;
2922 bmih
->biBitCount
= bitCount
;
2923 bmih
->biCompression
= BI_RGB
;
2924 bmih
->biSizeImage
= sizeImage
;
2925 bmih
->biXPelsPerMeter
= 0;
2926 bmih
->biYPelsPerMeter
= 0;
2927 bmih
->biClrUsed
= 0;
2928 bmih
->biClrImportant
= 0;
2931 result
= GetDIBits(xdc
, hBitmap
, 0, bm
.bmHeight
, lpBits
, (BITMAPINFO
*)bmih
, DIB_RGB_COLORS
) == bm
.bmHeight
;
2936 TRACE("width %u, height %u, planes %u, bpp %u\n",
2937 bmih
->biWidth
, bmih
->biHeight
,
2938 bmih
->biPlanes
, bmih
->biBitCount
);
2942 LPBITMAPINFO inf
= (LPBITMAPINFO
)bmih
;
2943 inf
->bmiColors
[0].rgbRed
= inf
->bmiColors
[0].rgbGreen
= inf
->bmiColors
[0].rgbBlue
= 0;
2944 inf
->bmiColors
[1].rgbRed
= inf
->bmiColors
[1].rgbGreen
= inf
->bmiColors
[1].rgbBlue
= 0xff;
2947 if(FAILED(IStream_Write(pstm
, data
, totalSize
, NULL
)))
2959 /*************************************************************************
2960 * ImageList_Write [COMCTL32.@]
2962 * Writes an image list to a stream.
2965 * himl [I] handle to image list
2966 * pstm [O] Pointer to a stream.
2977 ImageList_Write (HIMAGELIST himl
, LPSTREAM pstm
)
2982 TRACE("%p %p\n", himl
, pstm
);
2984 if (!is_valid(himl
))
2987 ilHead
.usMagic
= (('L' << 8) | 'I');
2988 ilHead
.usVersion
= 0x101;
2989 ilHead
.cCurImage
= himl
->cCurImage
;
2990 ilHead
.cMaxImage
= himl
->cMaxImage
;
2991 ilHead
.cGrow
= himl
->cGrow
;
2992 ilHead
.cx
= himl
->cx
;
2993 ilHead
.cy
= himl
->cy
;
2994 ilHead
.bkcolor
= himl
->clrBk
;
2995 ilHead
.flags
= himl
->flags
;
2996 for(i
= 0; i
< 4; i
++) {
2997 ilHead
.ovls
[i
] = himl
->nOvlIdx
[i
];
3000 TRACE("cx %u, cy %u, flags 0x04%x, cCurImage %u, cMaxImage %u\n",
3001 ilHead
.cx
, ilHead
.cy
, ilHead
.flags
, ilHead
.cCurImage
, ilHead
.cMaxImage
);
3003 if(FAILED(IStream_Write(pstm
, &ilHead
, sizeof(ILHEAD
), NULL
)))
3006 /* write the bitmap */
3007 if(!_write_bitmap(himl
->hbmImage
, pstm
))
3010 /* write the mask if we have one */
3011 if(himl
->flags
& ILC_MASK
) {
3012 if(!_write_bitmap(himl
->hbmMask
, pstm
))
3020 static HBITMAP
ImageList_CreateImage(HDC hdc
, HIMAGELIST himl
, UINT count
)
3022 HBITMAP hbmNewBitmap
;
3023 UINT ilc
= (himl
->flags
& 0xFE);
3026 imagelist_get_bitmap_size( himl
, count
, &sz
);
3028 if ((ilc
>= ILC_COLOR4
&& ilc
<= ILC_COLOR32
) || ilc
== ILC_COLOR
)
3033 TRACE("Creating DIBSection %d x %d, %d Bits per Pixel\n",
3034 sz
.cx
, sz
.cy
, himl
->uBitsPixel
);
3036 if (himl
->uBitsPixel
<= ILC_COLOR8
)
3042 colors
= 1 << himl
->uBitsPixel
;
3043 bmi
= Alloc(sizeof(BITMAPINFOHEADER
) +
3044 sizeof(PALETTEENTRY
) * colors
);
3046 pal
= (LPPALETTEENTRY
)bmi
->bmiColors
;
3047 GetPaletteEntries(GetStockObject(DEFAULT_PALETTE
), 0, colors
, pal
);
3049 /* Swap colors returned by GetPaletteEntries so we can use them for
3050 * CreateDIBSection call. */
3051 for (i
= 0; i
< colors
; i
++)
3053 temp
= pal
[i
].peBlue
;
3054 bmi
->bmiColors
[i
].rgbRed
= pal
[i
].peRed
;
3055 bmi
->bmiColors
[i
].rgbBlue
= temp
;
3060 bmi
= Alloc(sizeof(BITMAPINFOHEADER
));
3063 bmi
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
3064 bmi
->bmiHeader
.biWidth
= sz
.cx
;
3065 bmi
->bmiHeader
.biHeight
= sz
.cy
;
3066 bmi
->bmiHeader
.biPlanes
= 1;
3067 bmi
->bmiHeader
.biBitCount
= himl
->uBitsPixel
;
3068 bmi
->bmiHeader
.biCompression
= BI_RGB
;
3069 bmi
->bmiHeader
.biSizeImage
= 0;
3070 bmi
->bmiHeader
.biXPelsPerMeter
= 0;
3071 bmi
->bmiHeader
.biYPelsPerMeter
= 0;
3072 bmi
->bmiHeader
.biClrUsed
= 0;
3073 bmi
->bmiHeader
.biClrImportant
= 0;
3075 hbmNewBitmap
= CreateDIBSection(hdc
, bmi
, DIB_RGB_COLORS
, &bits
, 0, 0);
3079 else /*if (ilc == ILC_COLORDDB)*/
3081 TRACE("Creating Bitmap: %d Bits per Pixel\n", himl
->uBitsPixel
);
3083 hbmNewBitmap
= CreateBitmap (sz
.cx
, sz
.cy
, 1, himl
->uBitsPixel
, NULL
);
3085 TRACE("returning %p\n", hbmNewBitmap
);
3086 return hbmNewBitmap
;
3089 /*************************************************************************
3090 * ImageList_SetColorTable [COMCTL32.@]
3092 * Sets the color table of an image list.
3095 * himl [I] Handle to the image list.
3096 * uStartIndex [I] The first index to set.
3097 * cEntries [I] Number of entries to set.
3098 * prgb [I] New color information for color table for the image list.
3101 * Success: Number of entries in the table that were set.
3105 * ImageList_Create(), SetDIBColorTable()
3109 ImageList_SetColorTable (HIMAGELIST himl
, UINT uStartIndex
, UINT cEntries
, CONST RGBQUAD
* prgb
)
3111 return SetDIBColorTable(himl
->hdcImage
, uStartIndex
, cEntries
, prgb
);
3114 /*************************************************************************
3115 * ImageList_CoCreateInstance [COMCTL32.@]
3117 * Creates a new imagelist instance and returns an interface pointer to it.
3120 * rclsid [I] A reference to the CLSID (CLSID_ImageList).
3121 * punkOuter [I] Pointer to IUnknown interface for aggregation, if desired
3122 * riid [I] Identifier of the requested interface.
3123 * ppv [O] Returns the address of the pointer requested, or NULL.
3127 * Failure: Error value.
3130 ImageList_CoCreateInstance (REFCLSID rclsid
, const IUnknown
*punkOuter
, REFIID riid
, void **ppv
)
3132 TRACE("(%s,%p,%s,%p)\n", debugstr_guid(rclsid
), punkOuter
, debugstr_guid(riid
), ppv
);
3134 if (!IsEqualCLSID(&CLSID_ImageList
, rclsid
))
3135 return E_NOINTERFACE
;
3137 return ImageListImpl_CreateInstance(punkOuter
, riid
, ppv
);
3141 /*************************************************************************
3142 * IImageList implementation
3145 static HRESULT WINAPI
ImageListImpl_QueryInterface(IImageList
*iface
,
3146 REFIID iid
, void **ppv
)
3148 HIMAGELIST This
= (HIMAGELIST
) iface
;
3149 TRACE("(%p,%s,%p)\n", iface
, debugstr_guid(iid
), ppv
);
3151 if (!ppv
) return E_INVALIDARG
;
3153 if (IsEqualIID(&IID_IUnknown
, iid
) || IsEqualIID(&IID_IImageList
, iid
))
3158 return E_NOINTERFACE
;
3161 IUnknown_AddRef((IUnknown
*)*ppv
);
3165 static ULONG WINAPI
ImageListImpl_AddRef(IImageList
*iface
)
3167 HIMAGELIST This
= (HIMAGELIST
) iface
;
3168 ULONG ref
= InterlockedIncrement(&This
->ref
);
3170 TRACE("(%p) refcount=%u\n", iface
, ref
);
3174 static ULONG WINAPI
ImageListImpl_Release(IImageList
*iface
)
3176 HIMAGELIST This
= (HIMAGELIST
) iface
;
3177 ULONG ref
= InterlockedDecrement(&This
->ref
);
3179 TRACE("(%p) refcount=%u\n", iface
, ref
);
3183 /* delete image bitmaps */
3184 if (This
->hbmImage
) DeleteObject (This
->hbmImage
);
3185 if (This
->hbmMask
) DeleteObject (This
->hbmMask
);
3187 /* delete image & mask DCs */
3188 if (This
->hdcImage
) DeleteDC (This
->hdcImage
);
3189 if (This
->hdcMask
) DeleteDC (This
->hdcMask
);
3191 /* delete blending brushes */
3192 if (This
->hbrBlend25
) DeleteObject (This
->hbrBlend25
);
3193 if (This
->hbrBlend50
) DeleteObject (This
->hbrBlend50
);
3195 This
->lpVtbl
= NULL
;
3196 HeapFree(GetProcessHeap(), 0, This
->has_alpha
);
3197 HeapFree(GetProcessHeap(), 0, This
);
3203 static HRESULT WINAPI
ImageListImpl_Add(IImageList
*iface
, HBITMAP hbmImage
,
3204 HBITMAP hbmMask
, int *pi
)
3206 HIMAGELIST This
= (HIMAGELIST
) iface
;
3212 ret
= ImageList_Add(This
, hbmImage
, hbmMask
);
3221 static HRESULT WINAPI
ImageListImpl_ReplaceIcon(IImageList
*iface
, int i
,
3222 HICON hicon
, int *pi
)
3224 HIMAGELIST This
= (HIMAGELIST
) iface
;
3230 ret
= ImageList_ReplaceIcon(This
, i
, hicon
);
3239 static HRESULT WINAPI
ImageListImpl_SetOverlayImage(IImageList
*iface
,
3240 int iImage
, int iOverlay
)
3242 return ImageList_SetOverlayImage((HIMAGELIST
) iface
, iImage
, iOverlay
)
3246 static HRESULT WINAPI
ImageListImpl_Replace(IImageList
*iface
, int i
,
3247 HBITMAP hbmImage
, HBITMAP hbmMask
)
3249 return ImageList_Replace((HIMAGELIST
) iface
, i
, hbmImage
, hbmMask
) ? S_OK
:
3253 static HRESULT WINAPI
ImageListImpl_AddMasked(IImageList
*iface
, HBITMAP hbmImage
,
3254 COLORREF crMask
, int *pi
)
3256 HIMAGELIST This
= (HIMAGELIST
) iface
;
3262 ret
= ImageList_AddMasked(This
, hbmImage
, crMask
);
3271 static HRESULT WINAPI
ImageListImpl_Draw(IImageList
*iface
,
3272 IMAGELISTDRAWPARAMS
*pimldp
)
3274 HIMAGELIST This
= (HIMAGELIST
) iface
;
3275 HIMAGELIST old_himl
;
3278 /* As far as I can tell, Windows simply ignores the contents of pimldp->himl
3279 so we shall simulate the same */
3280 old_himl
= pimldp
->himl
;
3281 pimldp
->himl
= This
;
3283 ret
= ImageList_DrawIndirect(pimldp
);
3285 pimldp
->himl
= old_himl
;
3286 return ret
? S_OK
: E_INVALIDARG
;
3289 static HRESULT WINAPI
ImageListImpl_Remove(IImageList
*iface
, int i
)
3291 return (ImageList_Remove((HIMAGELIST
) iface
, i
) == 0) ? E_INVALIDARG
: S_OK
;
3294 static HRESULT WINAPI
ImageListImpl_GetIcon(IImageList
*iface
, int i
, UINT flags
,
3302 hIcon
= ImageList_GetIcon((HIMAGELIST
) iface
, i
, flags
);
3311 static HRESULT WINAPI
ImageListImpl_GetImageInfo(IImageList
*iface
, int i
,
3312 IMAGEINFO
*pImageInfo
)
3314 return ImageList_GetImageInfo((HIMAGELIST
) iface
, i
, pImageInfo
) ? S_OK
: E_FAIL
;
3317 static HRESULT WINAPI
ImageListImpl_Copy(IImageList
*iface
, int iDst
,
3318 IUnknown
*punkSrc
, int iSrc
, UINT uFlags
)
3320 HIMAGELIST This
= (HIMAGELIST
) iface
;
3321 IImageList
*src
= NULL
;
3327 /* TODO: Add test for IID_ImageList2 too */
3328 if (FAILED(IImageList_QueryInterface(punkSrc
, &IID_IImageList
,
3332 if (ImageList_Copy(This
, iDst
, (HIMAGELIST
) src
, iSrc
, uFlags
))
3337 IImageList_Release(src
);
3341 static HRESULT WINAPI
ImageListImpl_Merge(IImageList
*iface
, int i1
,
3342 IUnknown
*punk2
, int i2
, int dx
, int dy
, REFIID riid
, void **ppv
)
3344 HIMAGELIST This
= (HIMAGELIST
) iface
;
3345 IImageList
*iml2
= NULL
;
3347 HRESULT ret
= E_FAIL
;
3349 TRACE("(%p)->(%d %p %d %d %d %s %p)\n", iface
, i1
, punk2
, i2
, dx
, dy
, debugstr_guid(riid
), ppv
);
3351 /* TODO: Add test for IID_ImageList2 too */
3352 if (FAILED(IImageList_QueryInterface(punk2
, &IID_IImageList
,
3356 hNew
= ImageList_Merge(This
, i1
, (HIMAGELIST
) iml2
, i2
, dx
, dy
);
3358 /* Get the interface for the new image list */
3361 IImageList
*imerge
= (IImageList
*)hNew
;
3363 ret
= HIMAGELIST_QueryInterface(hNew
, riid
, ppv
);
3364 IImageList_Release(imerge
);
3367 IImageList_Release(iml2
);
3371 static HRESULT WINAPI
ImageListImpl_Clone(IImageList
*iface
, REFIID riid
, void **ppv
)
3373 HIMAGELIST This
= (HIMAGELIST
) iface
;
3375 HRESULT ret
= E_FAIL
;
3377 TRACE("(%p)->(%s %p)\n", iface
, debugstr_guid(riid
), ppv
);
3379 clone
= ImageList_Duplicate(This
);
3381 /* Get the interface for the new image list */
3384 IImageList
*iclone
= (IImageList
*)clone
;
3386 ret
= HIMAGELIST_QueryInterface(clone
, riid
, ppv
);
3387 IImageList_Release(iclone
);
3393 static HRESULT WINAPI
ImageListImpl_GetImageRect(IImageList
*iface
, int i
,
3396 HIMAGELIST This
= (HIMAGELIST
) iface
;
3402 if (!ImageList_GetImageInfo(This
, i
, &info
))
3405 return CopyRect(prc
, &info
.rcImage
) ? S_OK
: E_FAIL
;
3408 static HRESULT WINAPI
ImageListImpl_GetIconSize(IImageList
*iface
, int *cx
,
3411 HIMAGELIST This
= (HIMAGELIST
) iface
;
3413 return ImageList_GetIconSize(This
, cx
, cy
) ? S_OK
: E_INVALIDARG
;
3416 static HRESULT WINAPI
ImageListImpl_SetIconSize(IImageList
*iface
, int cx
,
3419 return ImageList_SetIconSize((HIMAGELIST
) iface
, cx
, cy
) ? S_OK
: E_FAIL
;
3422 static HRESULT WINAPI
ImageListImpl_GetImageCount(IImageList
*iface
, int *pi
)
3424 *pi
= ImageList_GetImageCount((HIMAGELIST
) iface
);
3428 static HRESULT WINAPI
ImageListImpl_SetImageCount(IImageList
*iface
,
3431 return ImageList_SetImageCount((HIMAGELIST
) iface
, uNewCount
) ? S_OK
: E_FAIL
;
3434 static HRESULT WINAPI
ImageListImpl_SetBkColor(IImageList
*iface
, COLORREF clrBk
,
3437 *pclr
= ImageList_SetBkColor((HIMAGELIST
) iface
, clrBk
);
3441 static HRESULT WINAPI
ImageListImpl_GetBkColor(IImageList
*iface
, COLORREF
*pclr
)
3443 *pclr
= ImageList_GetBkColor((HIMAGELIST
) iface
);
3447 static HRESULT WINAPI
ImageListImpl_BeginDrag(IImageList
*iface
, int iTrack
,
3448 int dxHotspot
, int dyHotspot
)
3450 return ImageList_BeginDrag((HIMAGELIST
) iface
, iTrack
, dxHotspot
, dyHotspot
) ? S_OK
: E_FAIL
;
3453 static HRESULT WINAPI
ImageListImpl_EndDrag(IImageList
*iface
)
3455 ImageList_EndDrag();
3459 static HRESULT WINAPI
ImageListImpl_DragEnter(IImageList
*iface
, HWND hwndLock
,
3462 return ImageList_DragEnter(hwndLock
, x
, y
) ? S_OK
: E_FAIL
;
3465 static HRESULT WINAPI
ImageListImpl_DragLeave(IImageList
*iface
, HWND hwndLock
)
3467 return ImageList_DragLeave(hwndLock
) ? S_OK
: E_FAIL
;
3470 static HRESULT WINAPI
ImageListImpl_DragMove(IImageList
*iface
, int x
, int y
)
3472 return ImageList_DragMove(x
, y
) ? S_OK
: E_FAIL
;
3475 static HRESULT WINAPI
ImageListImpl_SetDragCursorImage(IImageList
*iface
,
3476 IUnknown
*punk
, int iDrag
, int dxHotspot
, int dyHotspot
)
3478 IImageList
*iml2
= NULL
;
3484 /* TODO: Add test for IID_ImageList2 too */
3485 if (FAILED(IImageList_QueryInterface(punk
, &IID_IImageList
,
3489 ret
= ImageList_SetDragCursorImage((HIMAGELIST
) iml2
, iDrag
, dxHotspot
,
3492 IImageList_Release(iml2
);
3494 return ret
? S_OK
: E_FAIL
;
3497 static HRESULT WINAPI
ImageListImpl_DragShowNolock(IImageList
*iface
, BOOL fShow
)
3499 return ImageList_DragShowNolock(fShow
) ? S_OK
: E_FAIL
;
3502 static HRESULT WINAPI
ImageListImpl_GetDragImage(IImageList
*iface
, POINT
*ppt
,
3503 POINT
*pptHotspot
, REFIID riid
, PVOID
*ppv
)
3505 HRESULT ret
= E_FAIL
;
3511 hNew
= ImageList_GetDragImage(ppt
, pptHotspot
);
3513 /* Get the interface for the new image list */
3516 IImageList
*idrag
= (IImageList
*)hNew
;
3518 ret
= HIMAGELIST_QueryInterface(hNew
, riid
, ppv
);
3519 IImageList_Release(idrag
);
3525 static HRESULT WINAPI
ImageListImpl_GetItemFlags(IImageList
*iface
, int i
,
3528 FIXME("STUB: %p %d %p\n", iface
, i
, dwFlags
);
3532 static HRESULT WINAPI
ImageListImpl_GetOverlayImage(IImageList
*iface
, int iOverlay
,
3535 HIMAGELIST This
= (HIMAGELIST
) iface
;
3538 if ((iOverlay
< 0) || (iOverlay
> This
->cCurImage
))
3541 for (i
= 0; i
< MAX_OVERLAYIMAGE
; i
++)
3543 if (This
->nOvlIdx
[i
] == iOverlay
)
3554 static const IImageListVtbl ImageListImpl_Vtbl
= {
3555 ImageListImpl_QueryInterface
,
3556 ImageListImpl_AddRef
,
3557 ImageListImpl_Release
,
3559 ImageListImpl_ReplaceIcon
,
3560 ImageListImpl_SetOverlayImage
,
3561 ImageListImpl_Replace
,
3562 ImageListImpl_AddMasked
,
3564 ImageListImpl_Remove
,
3565 ImageListImpl_GetIcon
,
3566 ImageListImpl_GetImageInfo
,
3568 ImageListImpl_Merge
,
3569 ImageListImpl_Clone
,
3570 ImageListImpl_GetImageRect
,
3571 ImageListImpl_GetIconSize
,
3572 ImageListImpl_SetIconSize
,
3573 ImageListImpl_GetImageCount
,
3574 ImageListImpl_SetImageCount
,
3575 ImageListImpl_SetBkColor
,
3576 ImageListImpl_GetBkColor
,
3577 ImageListImpl_BeginDrag
,
3578 ImageListImpl_EndDrag
,
3579 ImageListImpl_DragEnter
,
3580 ImageListImpl_DragLeave
,
3581 ImageListImpl_DragMove
,
3582 ImageListImpl_SetDragCursorImage
,
3583 ImageListImpl_DragShowNolock
,
3584 ImageListImpl_GetDragImage
,
3585 ImageListImpl_GetItemFlags
,
3586 ImageListImpl_GetOverlayImage
3589 static inline BOOL
is_valid(HIMAGELIST himl
)
3594 valid
= himl
&& himl
->lpVtbl
== &ImageListImpl_Vtbl
;
3604 /*************************************************************************
3605 * HIMAGELIST_QueryInterface [COMCTL32.@]
3607 * Returns a pointer to an IImageList or IImageList2 object for the given
3611 * himl [I] Image list handle.
3612 * riid [I] Identifier of the requested interface.
3613 * ppv [O] Returns the address of the pointer requested, or NULL.
3617 * Failure: Error value.
3620 HIMAGELIST_QueryInterface (HIMAGELIST himl
, REFIID riid
, void **ppv
)
3622 TRACE("(%p,%s,%p)\n", himl
, debugstr_guid(riid
), ppv
);
3623 return IImageList_QueryInterface((IImageList
*) himl
, riid
, ppv
);
3626 static HRESULT
ImageListImpl_CreateInstance(const IUnknown
*pUnkOuter
, REFIID iid
, void** ppv
)
3631 TRACE("(%p,%s,%p)\n", pUnkOuter
, debugstr_guid(iid
), ppv
);
3635 if (pUnkOuter
) return CLASS_E_NOAGGREGATION
;
3637 This
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(struct _IMAGELIST
));
3638 if (!This
) return E_OUTOFMEMORY
;
3640 This
->lpVtbl
= &ImageListImpl_Vtbl
;
3643 ret
= IUnknown_QueryInterface((IUnknown
*)This
, iid
, ppv
);
3644 IUnknown_Release((IUnknown
*)This
);