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"
58 WINE_DEFAULT_DEBUG_CHANNEL(imagelist
);
61 #define MAX_OVERLAYIMAGE 15
63 /* internal image list data used for Drag & Drop operations */
68 /* position of the drag image relative to the window */
71 /* offset of the hotspot relative to the origin of the image */
74 /* is the drag image visible */
76 /* saved background */
80 static INTERNALDRAG InternalDrag
= { 0, 0, 0, 0, 0, 0, FALSE
, 0 };
82 static HBITMAP
ImageList_CreateImage(HDC hdc
, HIMAGELIST himl
, UINT count
);
83 static HRESULT
ImageListImpl_CreateInstance(const IUnknown
*pUnkOuter
, REFIID iid
, void** ppv
);
84 static inline BOOL
is_valid(HIMAGELIST himl
);
87 * An imagelist with N images is tiled like this:
99 static inline UINT
imagelist_height( UINT count
)
101 return ((count
+ TILE_COUNT
- 1)/TILE_COUNT
);
104 static inline void imagelist_point_from_index( HIMAGELIST himl
, UINT index
, LPPOINT pt
)
106 pt
->x
= (index
%TILE_COUNT
) * himl
->cx
;
107 pt
->y
= (index
/TILE_COUNT
) * himl
->cy
;
110 static inline void imagelist_get_bitmap_size( HIMAGELIST himl
, UINT count
, SIZE
*sz
)
112 sz
->cx
= himl
->cx
* TILE_COUNT
;
113 sz
->cy
= imagelist_height( count
) * himl
->cy
;
117 * imagelist_copy_images()
119 * Copies a block of count images from offset src in the list to offset dest.
120 * Images are copied a row at at time. Assumes hdcSrc and hdcDest are different.
122 static inline void imagelist_copy_images( HIMAGELIST himl
, HDC hdcSrc
, HDC hdcDest
,
123 UINT src
, UINT count
, UINT dest
)
129 for ( i
=0; i
<TILE_COUNT
; i
++ )
131 imagelist_point_from_index( himl
, src
+i
, &ptSrc
);
132 imagelist_point_from_index( himl
, dest
+i
, &ptDest
);
134 sz
.cy
= himl
->cy
* imagelist_height( count
- i
);
136 BitBlt( hdcDest
, ptDest
.x
, ptDest
.y
, sz
.cx
, sz
.cy
,
137 hdcSrc
, ptSrc
.x
, ptSrc
.y
, SRCCOPY
);
141 /* add images with an alpha channel when the image list is 32 bpp */
142 static BOOL
add_with_alpha( HIMAGELIST himl
, HDC hdc
, int pos
, int count
,
143 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 neither the imagelist nor the source bitmap can have an alpha channel, bail out now */
158 if (himl
->uBitsPixel
!= 32 && bm
.bmBitsPixel
!= 32) return FALSE
;
160 SelectObject( hdc
, hbmImage
);
161 mask_width
= (bm
.bmWidth
+ 31) / 32 * 4;
163 if (!(info
= HeapAlloc( GetProcessHeap(), 0, FIELD_OFFSET( BITMAPINFO
, bmiColors
[256] )))) goto done
;
164 info
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
165 info
->bmiHeader
.biWidth
= bm
.bmWidth
;
166 info
->bmiHeader
.biHeight
= -height
;
167 info
->bmiHeader
.biPlanes
= 1;
168 info
->bmiHeader
.biBitCount
= 32;
169 info
->bmiHeader
.biCompression
= BI_RGB
;
170 info
->bmiHeader
.biSizeImage
= bm
.bmWidth
* height
* 4;
171 info
->bmiHeader
.biXPelsPerMeter
= 0;
172 info
->bmiHeader
.biYPelsPerMeter
= 0;
173 info
->bmiHeader
.biClrUsed
= 0;
174 info
->bmiHeader
.biClrImportant
= 0;
175 if (!(bits
= HeapAlloc( GetProcessHeap(), 0, info
->bmiHeader
.biSizeImage
))) goto done
;
176 if (!GetDIBits( hdc
, hbmImage
, 0, height
, bits
, info
, DIB_RGB_COLORS
)) goto done
;
180 if (!(mask_info
= HeapAlloc( GetProcessHeap(), 0, FIELD_OFFSET( BITMAPINFO
, bmiColors
[2] ))))
182 mask_info
->bmiHeader
= info
->bmiHeader
;
183 mask_info
->bmiHeader
.biBitCount
= 1;
184 mask_info
->bmiHeader
.biSizeImage
= mask_width
* height
;
185 if (!(mask_bits
= HeapAlloc( GetProcessHeap(), 0, info
->bmiHeader
.biSizeImage
))) goto done
;
186 if (!GetDIBits( hdc
, hbmMask
, 0, height
, mask_bits
, mask_info
, DIB_RGB_COLORS
)) goto done
;
187 hdcMask
= CreateCompatibleDC( 0 );
188 SelectObject( hdcMask
, hbmMask
);
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;
210 if (hdcMask
) StretchBlt( himl
->hdcMask
, pt
.x
, pt
.y
, himl
->cx
, himl
->cy
,
211 hdcMask
, n
* width
, 0, width
, height
, SRCCOPY
);
215 if (himl
->has_alpha
) himl
->has_alpha
[pos
+ n
] = 1;
217 if (mask_info
&& himl
->hbmMask
) /* generate the mask from the alpha channel */
219 for (i
= 0; i
< height
; i
++)
220 for (j
= n
* width
; j
< (n
+ 1) * width
; j
++)
221 if ((bits
[i
* bm
.bmWidth
+ j
] >> 24) > 25) /* more than 10% alpha */
222 mask_bits
[i
* mask_width
+ j
/ 8] &= ~(0x80 >> (j
% 8));
224 mask_bits
[i
* mask_width
+ j
/ 8] |= 0x80 >> (j
% 8);
225 StretchDIBits( himl
->hdcMask
, pt
.x
, pt
.y
, himl
->cx
, himl
->cy
,
226 n
* width
, 0, width
, height
, mask_bits
, mask_info
, DIB_RGB_COLORS
, SRCCOPY
);
229 StretchDIBits( himl
->hdcImage
, pt
.x
, pt
.y
, himl
->cx
, himl
->cy
,
230 n
* width
, 0, width
, height
, bits
, info
, DIB_RGB_COLORS
, SRCCOPY
);
236 if (hdcMask
) DeleteDC( hdcMask
);
237 HeapFree( GetProcessHeap(), 0, info
);
238 HeapFree( GetProcessHeap(), 0, mask_info
);
239 HeapFree( GetProcessHeap(), 0, bits
);
240 HeapFree( GetProcessHeap(), 0, mask_bits
);
244 /*************************************************************************
245 * IMAGELIST_InternalExpandBitmaps [Internal]
247 * Expands the bitmaps of an image list by the given number of images.
250 * himl [I] handle to image list
251 * nImageCount [I] number of images to add
257 * This function CANNOT be used to reduce the number of images.
260 IMAGELIST_InternalExpandBitmaps(HIMAGELIST himl
, INT nImageCount
)
263 HBITMAP hbmNewBitmap
, hbmNull
;
267 TRACE("%p has %d allocated %d images\n", himl
, himl
->cCurImage
, himl
->cMaxImage
);
269 if (himl
->cCurImage
+ nImageCount
<= himl
->cMaxImage
)
272 nNewCount
= himl
->cCurImage
+ max(nImageCount
, himl
->cGrow
) + 1;
274 imagelist_get_bitmap_size(himl
, nNewCount
, &sz
);
276 TRACE("Create expanded bitmaps : himl=%p x=%d y=%d count=%d\n", himl
, sz
.cx
, sz
.cy
, nNewCount
);
277 hdcBitmap
= CreateCompatibleDC (0);
279 hbmNewBitmap
= ImageList_CreateImage(hdcBitmap
, himl
, nNewCount
);
281 if (hbmNewBitmap
== 0)
282 ERR("creating new image bitmap (x=%d y=%d)!\n", sz
.cx
, sz
.cy
);
286 hbmNull
= SelectObject (hdcBitmap
, hbmNewBitmap
);
287 BitBlt (hdcBitmap
, 0, 0, sz
.cx
, sz
.cy
,
288 himl
->hdcImage
, 0, 0, SRCCOPY
);
289 SelectObject (hdcBitmap
, hbmNull
);
291 SelectObject (himl
->hdcImage
, hbmNewBitmap
);
292 DeleteObject (himl
->hbmImage
);
293 himl
->hbmImage
= hbmNewBitmap
;
295 if (himl
->flags
& ILC_MASK
)
297 hbmNewBitmap
= CreateBitmap (sz
.cx
, sz
.cy
, 1, 1, NULL
);
299 if (hbmNewBitmap
== 0)
300 ERR("creating new mask bitmap!\n");
304 hbmNull
= SelectObject (hdcBitmap
, hbmNewBitmap
);
305 BitBlt (hdcBitmap
, 0, 0, sz
.cx
, sz
.cy
,
306 himl
->hdcMask
, 0, 0, SRCCOPY
);
307 SelectObject (hdcBitmap
, hbmNull
);
309 SelectObject (himl
->hdcMask
, hbmNewBitmap
);
310 DeleteObject (himl
->hbmMask
);
311 himl
->hbmMask
= hbmNewBitmap
;
316 char *new_alpha
= HeapReAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, himl
->has_alpha
, nNewCount
);
317 if (new_alpha
) himl
->has_alpha
= new_alpha
;
320 HeapFree( GetProcessHeap(), 0, himl
->has_alpha
);
321 himl
->has_alpha
= NULL
;
325 himl
->cMaxImage
= nNewCount
;
327 DeleteDC (hdcBitmap
);
331 /*************************************************************************
332 * ImageList_Add [COMCTL32.@]
334 * Add an image or images to an image list.
337 * himl [I] handle to image list
338 * hbmImage [I] handle to image bitmap
339 * hbmMask [I] handle to mask bitmap
342 * Success: Index of the first new image.
347 ImageList_Add (HIMAGELIST himl
, HBITMAP hbmImage
, HBITMAP hbmMask
)
349 HDC hdcBitmap
, hdcTemp
= 0;
350 INT nFirstIndex
, nImageCount
, i
;
354 TRACE("himl=%p hbmimage=%p hbmmask=%p\n", himl
, hbmImage
, hbmMask
);
358 if (!GetObjectW(hbmImage
, sizeof(BITMAP
), &bmp
))
361 TRACE("himl %p, cCurImage %d, cMaxImage %d, cGrow %d, cx %d, cy %d\n",
362 himl
, himl
->cCurImage
, himl
->cMaxImage
, himl
->cGrow
, himl
->cx
, himl
->cy
);
364 nImageCount
= bmp
.bmWidth
/ himl
->cx
;
366 TRACE("%p has %d images (%d x %d)\n", hbmImage
, nImageCount
, bmp
.bmWidth
, bmp
.bmHeight
);
368 IMAGELIST_InternalExpandBitmaps(himl
, nImageCount
);
370 hdcBitmap
= CreateCompatibleDC(0);
372 SelectObject(hdcBitmap
, hbmImage
);
374 if (add_with_alpha( himl
, hdcBitmap
, himl
->cCurImage
, nImageCount
,
375 himl
->cx
, min( himl
->cy
, bmp
.bmHeight
), hbmImage
, hbmMask
))
380 hdcTemp
= CreateCompatibleDC(0);
381 SelectObject(hdcTemp
, hbmMask
);
384 for (i
=0; i
<nImageCount
; i
++)
386 imagelist_point_from_index( himl
, himl
->cCurImage
+ i
, &pt
);
388 /* Copy result to the imagelist
390 BitBlt( himl
->hdcImage
, pt
.x
, pt
.y
, himl
->cx
, bmp
.bmHeight
,
391 hdcBitmap
, i
*himl
->cx
, 0, SRCCOPY
);
396 BitBlt( himl
->hdcMask
, pt
.x
, pt
.y
, himl
->cx
, bmp
.bmHeight
,
397 hdcTemp
, i
*himl
->cx
, 0, SRCCOPY
);
399 /* Remove the background from the image
401 BitBlt( himl
->hdcImage
, pt
.x
, pt
.y
, himl
->cx
, bmp
.bmHeight
,
402 himl
->hdcMask
, pt
.x
, pt
.y
, 0x220326 ); /* NOTSRCAND */
404 if (hdcTemp
) DeleteDC(hdcTemp
);
409 nFirstIndex
= himl
->cCurImage
;
410 himl
->cCurImage
+= nImageCount
;
416 /*************************************************************************
417 * ImageList_AddIcon [COMCTL32.@]
419 * Adds an icon to an image list.
422 * himl [I] handle to image list
423 * hIcon [I] handle to icon
426 * Success: index of the new image
429 #undef ImageList_AddIcon
430 INT WINAPI
ImageList_AddIcon (HIMAGELIST himl
, HICON hIcon
)
432 return ImageList_ReplaceIcon (himl
, -1, hIcon
);
436 /*************************************************************************
437 * ImageList_AddMasked [COMCTL32.@]
439 * Adds an image or images to an image list and creates a mask from the
440 * specified bitmap using the mask color.
443 * himl [I] handle to image list.
444 * hBitmap [I] handle to bitmap
445 * clrMask [I] mask color.
448 * Success: Index of the first new image.
453 ImageList_AddMasked (HIMAGELIST himl
, HBITMAP hBitmap
, COLORREF clrMask
)
455 HDC hdcMask
, hdcBitmap
;
461 TRACE("himl=%p hbitmap=%p clrmask=%x\n", himl
, hBitmap
, clrMask
);
465 if (!GetObjectW(hBitmap
, sizeof(BITMAP
), &bmp
))
468 hdcBitmap
= CreateCompatibleDC(0);
469 SelectObject(hdcBitmap
, hBitmap
);
471 /* Create a temp Mask so we can remove the background of the Image */
472 hdcMask
= CreateCompatibleDC(0);
473 hMaskBitmap
= CreateBitmap(bmp
.bmWidth
, bmp
.bmHeight
, 1, 1, NULL
);
474 SelectObject(hdcMask
, hMaskBitmap
);
476 /* create monochrome image to the mask bitmap */
477 bkColor
= (clrMask
!= CLR_DEFAULT
) ? clrMask
: GetPixel (hdcBitmap
, 0, 0);
478 SetBkColor (hdcBitmap
, bkColor
);
479 BitBlt (hdcMask
, 0, 0, bmp
.bmWidth
, bmp
.bmHeight
, hdcBitmap
, 0, 0, SRCCOPY
);
481 SetBkColor(hdcBitmap
, RGB(255,255,255));
484 * Remove the background from the image
486 * WINDOWS BUG ALERT!!!!!!
487 * The statement below should not be done in common practice
488 * but this is how ImageList_AddMasked works in Windows.
489 * It overwrites the original bitmap passed, this was discovered
490 * by using the same bitmap to iterate the different styles
491 * on windows where it failed (BUT ImageList_Add is OK)
492 * This is here in case some apps rely on this bug
494 * Blt mode 0x220326 is NOTSRCAND
496 BitBlt(hdcBitmap
, 0, 0, bmp
.bmWidth
, bmp
.bmHeight
, hdcMask
, 0, 0, 0x220326);
501 ret
= ImageList_Add( himl
, hBitmap
, hMaskBitmap
);
503 DeleteObject(hMaskBitmap
);
508 /*************************************************************************
509 * ImageList_BeginDrag [COMCTL32.@]
511 * Creates a temporary image list that contains one image. It will be used
515 * himlTrack [I] handle to the source image list
516 * iTrack [I] index of the drag image in the source image list
517 * dxHotspot [I] X position of the hot spot of the drag image
518 * dyHotspot [I] Y position of the hot spot of the drag image
526 ImageList_BeginDrag (HIMAGELIST himlTrack
, INT iTrack
,
527 INT dxHotspot
, INT dyHotspot
)
531 TRACE("(himlTrack=%p iTrack=%d dx=%d dy=%d)\n", himlTrack
, iTrack
,
532 dxHotspot
, dyHotspot
);
534 if (!is_valid(himlTrack
))
537 if (InternalDrag
.himl
)
538 ImageList_EndDrag ();
543 InternalDrag
.himl
= ImageList_Create (cx
, cy
, himlTrack
->flags
, 1, 1);
544 if (InternalDrag
.himl
== NULL
) {
545 WARN("Error creating drag image list!\n");
549 InternalDrag
.dxHotspot
= dxHotspot
;
550 InternalDrag
.dyHotspot
= dyHotspot
;
553 BitBlt (InternalDrag
.himl
->hdcImage
, 0, 0, cx
, cy
, himlTrack
->hdcImage
, iTrack
* cx
, 0, SRCCOPY
);
556 BitBlt (InternalDrag
.himl
->hdcMask
, 0, 0, cx
, cy
, himlTrack
->hdcMask
, iTrack
* cx
, 0, SRCCOPY
);
558 InternalDrag
.himl
->cCurImage
= 1;
564 /*************************************************************************
565 * ImageList_Copy [COMCTL32.@]
567 * Copies an image of the source image list to an image of the
568 * destination image list. Images can be copied or swapped.
571 * himlDst [I] handle to the destination image list
572 * iDst [I] destination image index.
573 * himlSrc [I] handle to the source image list
574 * iSrc [I] source image index
575 * uFlags [I] flags for the copy operation
582 * Copying from one image list to another is possible. The original
583 * implementation just copies or swaps within one image list.
584 * Could this feature become a bug??? ;-)
588 ImageList_Copy (HIMAGELIST himlDst
, INT iDst
, HIMAGELIST himlSrc
,
589 INT iSrc
, UINT uFlags
)
593 TRACE("himlDst=%p iDst=%d himlSrc=%p iSrc=%d\n", himlDst
, iDst
, himlSrc
, iSrc
);
595 if (!is_valid(himlSrc
) || !is_valid(himlDst
))
597 if ((iDst
< 0) || (iDst
>= himlDst
->cCurImage
))
599 if ((iSrc
< 0) || (iSrc
>= himlSrc
->cCurImage
))
602 imagelist_point_from_index( himlDst
, iDst
, &ptDst
);
603 imagelist_point_from_index( himlSrc
, iSrc
, &ptSrc
);
605 if (uFlags
& ILCF_SWAP
) {
608 HBITMAP hbmTempImage
, hbmTempMask
;
610 hdcBmp
= CreateCompatibleDC (0);
612 /* create temporary bitmaps */
613 hbmTempImage
= CreateBitmap (himlSrc
->cx
, himlSrc
->cy
, 1,
614 himlSrc
->uBitsPixel
, NULL
);
615 hbmTempMask
= CreateBitmap (himlSrc
->cx
, himlSrc
->cy
, 1,
618 /* copy (and stretch) destination to temporary bitmaps.(save) */
620 SelectObject (hdcBmp
, hbmTempImage
);
621 StretchBlt (hdcBmp
, 0, 0, himlSrc
->cx
, himlSrc
->cy
,
622 himlDst
->hdcImage
, ptDst
.x
, ptDst
.y
, himlDst
->cx
, himlDst
->cy
,
625 SelectObject (hdcBmp
, hbmTempMask
);
626 StretchBlt (hdcBmp
, 0, 0, himlSrc
->cx
, himlSrc
->cy
,
627 himlDst
->hdcMask
, ptDst
.x
, ptDst
.y
, himlDst
->cx
, himlDst
->cy
,
630 /* copy (and stretch) source to destination */
632 StretchBlt (himlDst
->hdcImage
, ptDst
.x
, ptDst
.y
, himlDst
->cx
, himlDst
->cy
,
633 himlSrc
->hdcImage
, ptSrc
.x
, ptSrc
.y
, himlSrc
->cx
, himlSrc
->cy
,
636 StretchBlt (himlDst
->hdcMask
, ptDst
.x
, ptDst
.y
, himlDst
->cx
, himlDst
->cy
,
637 himlSrc
->hdcMask
, ptSrc
.x
, ptSrc
.y
, himlSrc
->cx
, himlSrc
->cy
,
640 /* copy (without stretching) temporary bitmaps to source (restore) */
642 BitBlt (himlSrc
->hdcMask
, ptSrc
.x
, ptSrc
.y
, himlSrc
->cx
, himlSrc
->cy
,
643 hdcBmp
, 0, 0, SRCCOPY
);
646 BitBlt (himlSrc
->hdcImage
, ptSrc
.x
, ptSrc
.y
, himlSrc
->cx
, himlSrc
->cy
,
647 hdcBmp
, 0, 0, SRCCOPY
);
648 /* delete temporary bitmaps */
649 DeleteObject (hbmTempMask
);
650 DeleteObject (hbmTempImage
);
655 StretchBlt (himlDst
->hdcImage
, ptDst
.x
, ptDst
.y
, himlDst
->cx
, himlDst
->cy
,
656 himlSrc
->hdcImage
, ptSrc
.x
, ptSrc
.y
, himlSrc
->cx
, himlSrc
->cy
,
660 StretchBlt (himlDst
->hdcMask
, ptDst
.x
, ptDst
.y
, himlDst
->cx
, himlDst
->cy
,
661 himlSrc
->hdcMask
, ptSrc
.x
, ptSrc
.y
, himlSrc
->cx
, himlSrc
->cy
,
669 /*************************************************************************
670 * ImageList_Create [COMCTL32.@]
672 * Creates a new image list.
675 * cx [I] image height
677 * flags [I] creation flags
678 * cInitial [I] initial number of images in the image list
679 * cGrow [I] number of images by which image list grows
682 * Success: Handle to the created image list
686 ImageList_Create (INT cx
, INT cy
, UINT flags
,
687 INT cInitial
, INT cGrow
)
692 UINT ilc
= (flags
& 0xFE);
693 static const WORD aBitBlend25
[] =
694 {0xAA, 0x00, 0x55, 0x00, 0xAA, 0x00, 0x55, 0x00};
696 static const WORD aBitBlend50
[] =
697 {0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA};
699 TRACE("(%d %d 0x%x %d %d)\n", cx
, cy
, flags
, cInitial
, cGrow
);
701 /* Create the IImageList interface for the image list */
702 if (FAILED(ImageListImpl_CreateInstance(NULL
, &IID_IImageList
, (void **)&himl
)))
705 cGrow
= (cGrow
< 4) ? 4 : (cGrow
+ 3) & ~3;
710 himl
->cMaxImage
= cInitial
+ 1;
711 himl
->cInitial
= cInitial
;
713 himl
->clrFg
= CLR_DEFAULT
;
714 himl
->clrBk
= CLR_NONE
;
716 /* initialize overlay mask indices */
717 for (nCount
= 0; nCount
< MAX_OVERLAYIMAGE
; nCount
++)
718 himl
->nOvlIdx
[nCount
] = -1;
720 /* Create Image & Mask DCs */
721 himl
->hdcImage
= CreateCompatibleDC (0);
724 if (himl
->flags
& ILC_MASK
){
725 himl
->hdcMask
= CreateCompatibleDC(0);
730 /* Default to ILC_COLOR4 if none of the ILC_COLOR* flags are specified */
731 if (ilc
== ILC_COLOR
)
734 if (ilc
>= ILC_COLOR4
&& ilc
<= ILC_COLOR32
)
735 himl
->uBitsPixel
= ilc
;
737 himl
->uBitsPixel
= (UINT
)GetDeviceCaps (himl
->hdcImage
, BITSPIXEL
);
739 if (himl
->cMaxImage
> 0) {
740 himl
->hbmImage
= ImageList_CreateImage(himl
->hdcImage
, himl
, himl
->cMaxImage
);
741 SelectObject(himl
->hdcImage
, himl
->hbmImage
);
745 if ((himl
->cMaxImage
> 0) && (himl
->flags
& ILC_MASK
)) {
748 imagelist_get_bitmap_size(himl
, himl
->cMaxImage
, &sz
);
749 himl
->hbmMask
= CreateBitmap (sz
.cx
, sz
.cy
, 1, 1, NULL
);
750 if (himl
->hbmMask
== 0) {
751 ERR("Error creating mask bitmap!\n");
754 SelectObject(himl
->hdcMask
, himl
->hbmMask
);
759 if (himl
->uBitsPixel
== 32)
760 himl
->has_alpha
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, himl
->cMaxImage
);
762 himl
->has_alpha
= NULL
;
764 /* create blending brushes */
765 hbmTemp
= CreateBitmap (8, 8, 1, 1, aBitBlend25
);
766 himl
->hbrBlend25
= CreatePatternBrush (hbmTemp
);
767 DeleteObject (hbmTemp
);
769 hbmTemp
= CreateBitmap (8, 8, 1, 1, aBitBlend50
);
770 himl
->hbrBlend50
= CreatePatternBrush (hbmTemp
);
771 DeleteObject (hbmTemp
);
773 TRACE("created imagelist %p\n", himl
);
777 ImageList_Destroy(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 if (!ImageList_DragShowNolock(TRUE
)) {
850 /*************************************************************************
851 * ImageList_DragLeave [COMCTL32.@]
853 * Unlocks window update and hides the drag image.
856 * hwndLock [I] handle of the window that owns the drag image.
864 ImageList_DragLeave (HWND hwndLock
)
866 /* As we don't save drag info in the window this can lead to problems if
867 an app does not supply the same window as DragEnter */
869 InternalDrag.hwnd = hwndLock;
871 InternalDrag.hwnd = GetDesktopWindow (); */
873 hwndLock
= GetDesktopWindow();
874 if(InternalDrag
.hwnd
!= hwndLock
)
875 FIXME("DragLeave hWnd != DragEnter hWnd\n");
877 ImageList_DragShowNolock (FALSE
);
883 /*************************************************************************
884 * ImageList_InternalDragDraw [Internal]
886 * Draws the drag image.
889 * hdc [I] device context to draw into.
890 * x [I] X position of the drag image.
891 * y [I] Y position of the drag image.
898 * The position of the drag image is relative to the window, not
904 ImageList_InternalDragDraw (HDC hdc
, INT x
, INT y
)
906 IMAGELISTDRAWPARAMS imldp
;
908 ZeroMemory (&imldp
, sizeof(imldp
));
909 imldp
.cbSize
= sizeof(imldp
);
910 imldp
.himl
= InternalDrag
.himl
;
915 imldp
.rgbBk
= CLR_DEFAULT
;
916 imldp
.rgbFg
= CLR_DEFAULT
;
917 imldp
.fStyle
= ILD_NORMAL
;
918 imldp
.fState
= ILS_ALPHA
;
920 ImageList_DrawIndirect (&imldp
);
923 /*************************************************************************
924 * ImageList_DragMove [COMCTL32.@]
926 * Moves the drag image.
929 * x [I] X position of the drag image.
930 * y [I] Y position of the drag image.
937 * The position of the drag image is relative to the window, not
942 ImageList_DragMove (INT x
, INT y
)
944 TRACE("(x=%d y=%d)\n", x
, y
);
946 if (!is_valid(InternalDrag
.himl
))
949 /* draw/update the drag image */
950 if (InternalDrag
.bShow
) {
954 HBITMAP hbmOffScreen
;
955 INT origNewX
, origNewY
;
956 INT origOldX
, origOldY
;
957 INT origRegX
, origRegY
;
958 INT sizeRegX
, sizeRegY
;
961 /* calculate the update region */
962 origNewX
= x
- InternalDrag
.dxHotspot
;
963 origNewY
= y
- InternalDrag
.dyHotspot
;
964 origOldX
= InternalDrag
.x
- InternalDrag
.dxHotspot
;
965 origOldY
= InternalDrag
.y
- InternalDrag
.dyHotspot
;
966 origRegX
= min(origNewX
, origOldX
);
967 origRegY
= min(origNewY
, origOldY
);
968 sizeRegX
= InternalDrag
.himl
->cx
+ abs(x
- InternalDrag
.x
);
969 sizeRegY
= InternalDrag
.himl
->cy
+ abs(y
- InternalDrag
.y
);
971 hdcDrag
= GetDCEx(InternalDrag
.hwnd
, 0,
972 DCX_WINDOW
| DCX_CACHE
| DCX_LOCKWINDOWUPDATE
);
973 hdcOffScreen
= CreateCompatibleDC(hdcDrag
);
974 hdcBg
= CreateCompatibleDC(hdcDrag
);
976 hbmOffScreen
= CreateCompatibleBitmap(hdcDrag
, sizeRegX
, sizeRegY
);
977 SelectObject(hdcOffScreen
, hbmOffScreen
);
978 SelectObject(hdcBg
, InternalDrag
.hbmBg
);
980 /* get the actual background of the update region */
981 BitBlt(hdcOffScreen
, 0, 0, sizeRegX
, sizeRegY
, hdcDrag
,
982 origRegX
, origRegY
, SRCCOPY
);
983 /* erase the old image */
984 BitBlt(hdcOffScreen
, origOldX
- origRegX
, origOldY
- origRegY
,
985 InternalDrag
.himl
->cx
, InternalDrag
.himl
->cy
, hdcBg
, 0, 0,
987 /* save the background */
988 BitBlt(hdcBg
, 0, 0, InternalDrag
.himl
->cx
, InternalDrag
.himl
->cy
,
989 hdcOffScreen
, origNewX
- origRegX
, origNewY
- origRegY
, SRCCOPY
);
991 ImageList_InternalDragDraw(hdcOffScreen
, origNewX
- origRegX
,
992 origNewY
- origRegY
);
993 /* draw the update region to the screen */
994 BitBlt(hdcDrag
, origRegX
, origRegY
, sizeRegX
, sizeRegY
,
995 hdcOffScreen
, 0, 0, SRCCOPY
);
998 DeleteDC(hdcOffScreen
);
999 DeleteObject(hbmOffScreen
);
1000 ReleaseDC(InternalDrag
.hwnd
, hdcDrag
);
1003 /* update the image position */
1011 /*************************************************************************
1012 * ImageList_DragShowNolock [COMCTL32.@]
1014 * Shows or hides the drag image.
1017 * bShow [I] TRUE shows the drag image, FALSE hides it.
1025 ImageList_DragShowNolock (BOOL bShow
)
1031 if (!is_valid(InternalDrag
.himl
))
1034 TRACE("bShow=0x%X!\n", bShow
);
1036 /* DragImage is already visible/hidden */
1037 if ((InternalDrag
.bShow
&& bShow
) || (!InternalDrag
.bShow
&& !bShow
)) {
1041 /* position of the origin of the DragImage */
1042 x
= InternalDrag
.x
- InternalDrag
.dxHotspot
;
1043 y
= InternalDrag
.y
- InternalDrag
.dyHotspot
;
1045 hdcDrag
= GetDCEx (InternalDrag
.hwnd
, 0,
1046 DCX_WINDOW
| DCX_CACHE
| DCX_LOCKWINDOWUPDATE
);
1051 hdcBg
= CreateCompatibleDC(hdcDrag
);
1052 if (!InternalDrag
.hbmBg
) {
1053 InternalDrag
.hbmBg
= CreateCompatibleBitmap(hdcDrag
,
1054 InternalDrag
.himl
->cx
, InternalDrag
.himl
->cy
);
1056 SelectObject(hdcBg
, InternalDrag
.hbmBg
);
1059 /* save the background */
1060 BitBlt(hdcBg
, 0, 0, InternalDrag
.himl
->cx
, InternalDrag
.himl
->cy
,
1061 hdcDrag
, x
, y
, SRCCOPY
);
1062 /* show the image */
1063 ImageList_InternalDragDraw(hdcDrag
, x
, y
);
1065 /* hide the image */
1066 BitBlt(hdcDrag
, x
, y
, InternalDrag
.himl
->cx
, InternalDrag
.himl
->cy
,
1067 hdcBg
, 0, 0, SRCCOPY
);
1070 InternalDrag
.bShow
= !InternalDrag
.bShow
;
1073 ReleaseDC (InternalDrag
.hwnd
, hdcDrag
);
1078 /*************************************************************************
1079 * ImageList_Draw [COMCTL32.@]
1084 * himl [I] handle to image list
1086 * hdc [I] handle to device context
1089 * fStyle [I] drawing flags
1100 ImageList_Draw (HIMAGELIST himl
, INT i
, HDC hdc
, INT x
, INT y
, UINT fStyle
)
1102 return ImageList_DrawEx (himl
, i
, hdc
, x
, y
, 0, 0,
1103 CLR_DEFAULT
, CLR_DEFAULT
, fStyle
);
1107 /*************************************************************************
1108 * ImageList_DrawEx [COMCTL32.@]
1110 * Draws an image and allows to use extended drawing features.
1113 * himl [I] handle to image list
1115 * hdc [I] handle to device context
1120 * rgbBk [I] background color
1121 * rgbFg [I] foreground color
1122 * fStyle [I] drawing flags
1129 * Calls ImageList_DrawIndirect.
1132 * ImageList_DrawIndirect.
1136 ImageList_DrawEx (HIMAGELIST himl
, INT i
, HDC hdc
, INT x
, INT y
,
1137 INT dx
, INT dy
, COLORREF rgbBk
, COLORREF rgbFg
,
1140 IMAGELISTDRAWPARAMS imldp
;
1142 ZeroMemory (&imldp
, sizeof(imldp
));
1143 imldp
.cbSize
= sizeof(imldp
);
1151 imldp
.rgbBk
= rgbBk
;
1152 imldp
.rgbFg
= rgbFg
;
1153 imldp
.fStyle
= fStyle
;
1155 return ImageList_DrawIndirect (&imldp
);
1159 static BOOL
alpha_blend_image( HIMAGELIST himl
, HDC dest_dc
, int dest_x
, int dest_y
,
1160 int src_x
, int src_y
, int cx
, int cy
, BLENDFUNCTION func
)
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 (himl
->uBitsPixel
== 32) /* we already have an alpha channel in this case */
1189 /* pre-multiply by the alpha channel */
1190 for (i
= 0, ptr
= bits
; i
< cx
* cy
; i
++, ptr
++)
1192 DWORD alpha
= *ptr
>> 24;
1193 *ptr
= ((*ptr
& 0xff000000) |
1194 (((*ptr
& 0x00ff0000) * alpha
/ 255) & 0x00ff0000) |
1195 (((*ptr
& 0x0000ff00) * alpha
/ 255) & 0x0000ff00) |
1196 (((*ptr
& 0x000000ff) * alpha
/ 255)));
1199 else if (himl
->hbmMask
)
1201 unsigned int width_bytes
= (cx
+ 31) / 32 * 4;
1202 /* generate alpha channel from the mask */
1203 info
->bmiHeader
.biBitCount
= 1;
1204 info
->bmiHeader
.biSizeImage
= width_bytes
* cy
;
1205 if (!(mask
= CreateDIBSection( himl
->hdcMask
, info
, DIB_RGB_COLORS
, &mask_bits
, 0, 0 )))
1207 SelectObject( hdc
, mask
);
1208 BitBlt( hdc
, 0, 0, cx
, cy
, himl
->hdcMask
, src_x
, src_y
, SRCCOPY
);
1209 SelectObject( hdc
, bmp
);
1210 for (i
= 0, ptr
= bits
; i
< cy
; i
++)
1211 for (j
= 0; j
< cx
; j
++, ptr
++)
1212 if ((((BYTE
*)mask_bits
)[i
* width_bytes
+ j
/ 8] << (j
% 8)) & 0x80) *ptr
= 0;
1213 else *ptr
|= 0xff000000;
1216 ret
= GdiAlphaBlend( dest_dc
, dest_x
, dest_y
, cx
, cy
, hdc
, 0, 0, cx
, cy
, func
);
1220 if (bmp
) DeleteObject( bmp
);
1221 if (mask
) DeleteObject( mask
);
1222 HeapFree( GetProcessHeap(), 0, info
);
1226 /*************************************************************************
1227 * ImageList_DrawIndirect [COMCTL32.@]
1229 * Draws an image using various parameters specified in pimldp.
1232 * pimldp [I] pointer to IMAGELISTDRAWPARAMS structure.
1240 ImageList_DrawIndirect (IMAGELISTDRAWPARAMS
*pimldp
)
1242 INT cx
, cy
, nOvlIdx
;
1243 DWORD fState
, dwRop
;
1245 COLORREF oldImageBk
, oldImageFg
;
1246 HDC hImageDC
, hImageListDC
, hMaskListDC
;
1247 HBITMAP hImageBmp
, hOldImageBmp
, hBlendMaskBmp
;
1248 BOOL bIsTransparent
, bBlend
, bResult
= FALSE
, bMask
;
1254 if (!pimldp
|| !(himl
= pimldp
->himl
)) return FALSE
;
1255 if (!is_valid(himl
)) return FALSE
;
1256 if ((pimldp
->i
< 0) || (pimldp
->i
>= himl
->cCurImage
)) return FALSE
;
1258 imagelist_point_from_index( himl
, pimldp
->i
, &pt
);
1259 pt
.x
+= pimldp
->xBitmap
;
1260 pt
.y
+= pimldp
->yBitmap
;
1262 fState
= pimldp
->cbSize
< sizeof(IMAGELISTDRAWPARAMS
) ? ILS_NORMAL
: pimldp
->fState
;
1263 fStyle
= pimldp
->fStyle
& ~ILD_OVERLAYMASK
;
1264 cx
= (pimldp
->cx
== 0) ? himl
->cx
: pimldp
->cx
;
1265 cy
= (pimldp
->cy
== 0) ? himl
->cy
: pimldp
->cy
;
1267 bIsTransparent
= (fStyle
& ILD_TRANSPARENT
);
1268 if( pimldp
->rgbBk
== CLR_NONE
)
1269 bIsTransparent
= TRUE
;
1270 if( ( pimldp
->rgbBk
== CLR_DEFAULT
) && ( himl
->clrBk
== CLR_NONE
) )
1271 bIsTransparent
= TRUE
;
1272 bMask
= (himl
->flags
& ILC_MASK
) && (fStyle
& ILD_MASK
) ;
1273 bBlend
= (fStyle
& (ILD_BLEND25
| ILD_BLEND50
) ) && !bMask
;
1275 TRACE("himl(%p) hbmMask(%p) iImage(%d) x(%d) y(%d) cx(%d) cy(%d)\n",
1276 himl
, himl
->hbmMask
, pimldp
->i
, pimldp
->x
, pimldp
->y
, cx
, cy
);
1278 /* we will use these DCs to access the images and masks in the ImageList */
1279 hImageListDC
= himl
->hdcImage
;
1280 hMaskListDC
= himl
->hdcMask
;
1282 /* these will accumulate the image and mask for the image we're drawing */
1283 hImageDC
= CreateCompatibleDC( pimldp
->hdcDst
);
1284 hImageBmp
= CreateCompatibleBitmap( pimldp
->hdcDst
, cx
, cy
);
1285 hBlendMaskBmp
= bBlend
? CreateBitmap(cx
, cy
, 1, 1, NULL
) : 0;
1287 /* Create a compatible DC. */
1288 if (!hImageListDC
|| !hImageDC
|| !hImageBmp
||
1289 (bBlend
&& !hBlendMaskBmp
) || (himl
->hbmMask
&& !hMaskListDC
))
1292 hOldImageBmp
= SelectObject(hImageDC
, hImageBmp
);
1295 * To obtain a transparent look, background color should be set
1296 * to white and foreground color to black when blitting the
1299 oldImageFg
= SetTextColor( hImageDC
, RGB( 0, 0, 0 ) );
1300 oldImageBk
= SetBkColor( hImageDC
, RGB( 0xff, 0xff, 0xff ) );
1302 has_alpha
= (himl
->has_alpha
&& himl
->has_alpha
[pimldp
->i
]);
1303 if (!bMask
&& (has_alpha
|| (fState
& ILS_ALPHA
)))
1308 func
.BlendOp
= AC_SRC_OVER
;
1309 func
.BlendFlags
= 0;
1310 func
.SourceConstantAlpha
= (fState
& ILS_ALPHA
) ? pimldp
->Frame
: 255;
1311 func
.AlphaFormat
= AC_SRC_ALPHA
;
1315 bResult
= alpha_blend_image( himl
, pimldp
->hdcDst
, pimldp
->x
, pimldp
->y
,
1316 pt
.x
, pt
.y
, cx
, cy
, func
);
1319 colour
= pimldp
->rgbBk
;
1320 if (colour
== CLR_DEFAULT
) colour
= himl
->clrBk
;
1321 if (colour
== CLR_NONE
) colour
= GetBkColor( pimldp
->hdcDst
);
1323 hOldBrush
= SelectObject (hImageDC
, CreateSolidBrush (colour
));
1324 PatBlt( hImageDC
, 0, 0, cx
, cy
, PATCOPY
);
1325 alpha_blend_image( himl
, hImageDC
, 0, 0, pt
.x
, pt
.y
, cx
, cy
, func
);
1326 DeleteObject (SelectObject (hImageDC
, hOldBrush
));
1327 bResult
= BitBlt( pimldp
->hdcDst
, pimldp
->x
, pimldp
->y
, cx
, cy
, hImageDC
, 0, 0, SRCCOPY
);
1332 * Draw the initial image
1335 if (himl
->hbmMask
) {
1336 hOldBrush
= SelectObject (hImageDC
, CreateSolidBrush (GetTextColor(pimldp
->hdcDst
)));
1337 PatBlt( hImageDC
, 0, 0, cx
, cy
, PATCOPY
);
1338 BitBlt(hImageDC
, 0, 0, cx
, cy
, hMaskListDC
, pt
.x
, pt
.y
, SRCPAINT
);
1339 DeleteObject (SelectObject (hImageDC
, hOldBrush
));
1340 if( bIsTransparent
)
1342 BitBlt ( pimldp
->hdcDst
, pimldp
->x
, pimldp
->y
, cx
, cy
, hImageDC
, 0, 0, SRCAND
);
1347 hOldBrush
= SelectObject (hImageDC
, GetStockObject(BLACK_BRUSH
));
1348 PatBlt( hImageDC
, 0, 0, cx
, cy
, PATCOPY
);
1349 SelectObject(hImageDC
, hOldBrush
);
1352 /* blend the image with the needed solid background */
1353 COLORREF colour
= RGB(0,0,0);
1355 if( !bIsTransparent
)
1357 colour
= pimldp
->rgbBk
;
1358 if( colour
== CLR_DEFAULT
)
1359 colour
= himl
->clrBk
;
1360 if( colour
== CLR_NONE
)
1361 colour
= GetBkColor(pimldp
->hdcDst
);
1364 hOldBrush
= SelectObject (hImageDC
, CreateSolidBrush (colour
));
1365 PatBlt( hImageDC
, 0, 0, cx
, cy
, PATCOPY
);
1368 BitBlt( hImageDC
, 0, 0, cx
, cy
, hMaskListDC
, pt
.x
, pt
.y
, SRCAND
);
1369 BitBlt( hImageDC
, 0, 0, cx
, cy
, hImageListDC
, pt
.x
, pt
.y
, SRCPAINT
);
1372 BitBlt( hImageDC
, 0, 0, cx
, cy
, hImageListDC
, pt
.x
, pt
.y
, SRCCOPY
);
1373 DeleteObject (SelectObject (hImageDC
, hOldBrush
));
1376 /* Time for blending, if required */
1379 COLORREF clrBlend
= pimldp
->rgbFg
;
1380 HDC hBlendMaskDC
= hImageListDC
;
1383 /* Create the blend Mask */
1384 hOldBitmap
= SelectObject(hBlendMaskDC
, hBlendMaskBmp
);
1385 hBlendBrush
= fStyle
& ILD_BLEND50
? himl
->hbrBlend50
: himl
->hbrBlend25
;
1386 hOldBrush
= SelectObject(hBlendMaskDC
, hBlendBrush
);
1387 PatBlt(hBlendMaskDC
, 0, 0, cx
, cy
, PATCOPY
);
1388 SelectObject(hBlendMaskDC
, hOldBrush
);
1390 /* Modify the blend mask if an Image Mask exist */
1392 BitBlt(hBlendMaskDC
, 0, 0, cx
, cy
, hMaskListDC
, pt
.x
, pt
.y
, 0x220326); /* NOTSRCAND */
1393 BitBlt(hBlendMaskDC
, 0, 0, cx
, cy
, hBlendMaskDC
, 0, 0, NOTSRCCOPY
);
1396 /* now apply blend to the current image given the BlendMask */
1397 if (clrBlend
== CLR_DEFAULT
) clrBlend
= GetSysColor (COLOR_HIGHLIGHT
);
1398 else if (clrBlend
== CLR_NONE
) clrBlend
= GetTextColor (pimldp
->hdcDst
);
1399 hOldBrush
= SelectObject (hImageDC
, CreateSolidBrush(clrBlend
));
1400 BitBlt (hImageDC
, 0, 0, cx
, cy
, hBlendMaskDC
, 0, 0, 0xB8074A); /* PSDPxax */
1401 DeleteObject(SelectObject(hImageDC
, hOldBrush
));
1402 SelectObject(hBlendMaskDC
, hOldBitmap
);
1405 /* Now do the overlay image, if any */
1406 nOvlIdx
= (pimldp
->fStyle
& ILD_OVERLAYMASK
) >> 8;
1407 if ( (nOvlIdx
>= 1) && (nOvlIdx
<= MAX_OVERLAYIMAGE
)) {
1408 nOvlIdx
= himl
->nOvlIdx
[nOvlIdx
- 1];
1409 if ((nOvlIdx
>= 0) && (nOvlIdx
< himl
->cCurImage
)) {
1411 imagelist_point_from_index( himl
, nOvlIdx
, &ptOvl
);
1412 ptOvl
.x
+= pimldp
->xBitmap
;
1413 if (himl
->hbmMask
&& !(fStyle
& ILD_IMAGE
))
1414 BitBlt (hImageDC
, 0, 0, cx
, cy
, hMaskListDC
, ptOvl
.x
, ptOvl
.y
, SRCAND
);
1415 BitBlt (hImageDC
, 0, 0, cx
, cy
, hImageListDC
, ptOvl
.x
, ptOvl
.y
, SRCPAINT
);
1419 if (fState
& ILS_SATURATE
) FIXME("ILS_SATURATE: unimplemented!\n");
1420 if (fState
& ILS_GLOW
) FIXME("ILS_GLOW: unimplemented!\n");
1421 if (fState
& ILS_SHADOW
) FIXME("ILS_SHADOW: unimplemented!\n");
1423 if (fStyle
& ILD_PRESERVEALPHA
) FIXME("ILD_PRESERVEALPHA: unimplemented!\n");
1424 if (fStyle
& ILD_SCALE
) FIXME("ILD_SCALE: unimplemented!\n");
1425 if (fStyle
& ILD_DPISCALE
) FIXME("ILD_DPISCALE: unimplemented!\n");
1427 /* now copy the image to the screen */
1429 if (himl
->hbmMask
&& bIsTransparent
) {
1430 COLORREF oldDstFg
= SetTextColor(pimldp
->hdcDst
, RGB( 0, 0, 0 ) );
1431 COLORREF oldDstBk
= SetBkColor(pimldp
->hdcDst
, RGB( 0xff, 0xff, 0xff ));
1432 BitBlt (pimldp
->hdcDst
, pimldp
->x
, pimldp
->y
, cx
, cy
, hMaskListDC
, pt
.x
, pt
.y
, SRCAND
);
1433 SetBkColor(pimldp
->hdcDst
, oldDstBk
);
1434 SetTextColor(pimldp
->hdcDst
, oldDstFg
);
1437 if (fStyle
& ILD_ROP
) dwRop
= pimldp
->dwRop
;
1438 BitBlt (pimldp
->hdcDst
, pimldp
->x
, pimldp
->y
, cx
, cy
, hImageDC
, 0, 0, dwRop
);
1442 /* cleanup the mess */
1443 SetBkColor(hImageDC
, oldImageBk
);
1444 SetTextColor(hImageDC
, oldImageFg
);
1445 SelectObject(hImageDC
, hOldImageBmp
);
1447 DeleteObject(hBlendMaskBmp
);
1448 DeleteObject(hImageBmp
);
1455 /*************************************************************************
1456 * ImageList_Duplicate [COMCTL32.@]
1458 * Duplicates an image list.
1461 * himlSrc [I] source image list handle
1464 * Success: Handle of duplicated image list.
1469 ImageList_Duplicate (HIMAGELIST himlSrc
)
1473 if (!is_valid(himlSrc
)) {
1474 ERR("Invalid image list handle!\n");
1478 himlDst
= ImageList_Create (himlSrc
->cx
, himlSrc
->cy
, himlSrc
->flags
,
1479 himlSrc
->cCurImage
, himlSrc
->cGrow
);
1485 imagelist_get_bitmap_size(himlSrc
, himlSrc
->cCurImage
, &sz
);
1486 BitBlt (himlDst
->hdcImage
, 0, 0, sz
.cx
, sz
.cy
,
1487 himlSrc
->hdcImage
, 0, 0, SRCCOPY
);
1489 if (himlDst
->hbmMask
)
1490 BitBlt (himlDst
->hdcMask
, 0, 0, sz
.cx
, sz
.cy
,
1491 himlSrc
->hdcMask
, 0, 0, SRCCOPY
);
1493 himlDst
->cCurImage
= himlSrc
->cCurImage
;
1494 himlDst
->cMaxImage
= himlSrc
->cMaxImage
;
1495 if (himlSrc
->has_alpha
&& himlDst
->has_alpha
)
1496 memcpy( himlDst
->has_alpha
, himlSrc
->has_alpha
, himlDst
->cCurImage
);
1502 /*************************************************************************
1503 * ImageList_EndDrag [COMCTL32.@]
1505 * Finishes a drag operation.
1516 ImageList_EndDrag (void)
1518 /* cleanup the InternalDrag struct */
1519 InternalDrag
.hwnd
= 0;
1520 ImageList_Destroy (InternalDrag
.himl
);
1521 InternalDrag
.himl
= 0;
1524 InternalDrag
.dxHotspot
= 0;
1525 InternalDrag
.dyHotspot
= 0;
1526 InternalDrag
.bShow
= FALSE
;
1527 DeleteObject(InternalDrag
.hbmBg
);
1528 InternalDrag
.hbmBg
= 0;
1532 /*************************************************************************
1533 * ImageList_GetBkColor [COMCTL32.@]
1535 * Returns the background color of an image list.
1538 * himl [I] Image list handle.
1541 * Success: background color
1546 ImageList_GetBkColor (HIMAGELIST himl
)
1548 return himl
? himl
->clrBk
: CLR_NONE
;
1552 /*************************************************************************
1553 * ImageList_GetDragImage [COMCTL32.@]
1555 * Returns the handle to the internal drag image list.
1558 * ppt [O] Pointer to the drag position. Can be NULL.
1559 * pptHotspot [O] Pointer to the position of the hot spot. Can be NULL.
1562 * Success: Handle of the drag image list.
1567 ImageList_GetDragImage (POINT
*ppt
, POINT
*pptHotspot
)
1569 if (is_valid(InternalDrag
.himl
)) {
1571 ppt
->x
= InternalDrag
.x
;
1572 ppt
->y
= InternalDrag
.y
;
1575 pptHotspot
->x
= InternalDrag
.dxHotspot
;
1576 pptHotspot
->y
= InternalDrag
.dyHotspot
;
1578 return (InternalDrag
.himl
);
1585 /*************************************************************************
1586 * ImageList_GetFlags [COMCTL32.@]
1588 * Gets the flags of the specified image list.
1591 * himl [I] Handle to image list
1601 ImageList_GetFlags(HIMAGELIST himl
)
1603 TRACE("%p\n", himl
);
1605 return is_valid(himl
) ? himl
->flags
: 0;
1609 /*************************************************************************
1610 * ImageList_GetIcon [COMCTL32.@]
1612 * Creates an icon from a masked image of an image list.
1615 * himl [I] handle to image list
1617 * flags [I] drawing style flags
1620 * Success: icon handle
1625 ImageList_GetIcon (HIMAGELIST himl
, INT i
, UINT fStyle
)
1629 HBITMAP hOldDstBitmap
;
1633 TRACE("%p %d %d\n", himl
, i
, fStyle
);
1634 if (!is_valid(himl
) || (i
< 0) || (i
>= himl
->cCurImage
)) return NULL
;
1640 /* create colour bitmap */
1642 ii
.hbmColor
= CreateCompatibleBitmap(hdcDst
, himl
->cx
, himl
->cy
);
1643 ReleaseDC(0, hdcDst
);
1645 hdcDst
= CreateCompatibleDC(0);
1647 imagelist_point_from_index( himl
, i
, &pt
);
1650 ii
.hbmMask
= CreateBitmap (himl
->cx
, himl
->cy
, 1, 1, NULL
);
1651 hOldDstBitmap
= SelectObject (hdcDst
, ii
.hbmMask
);
1652 if (himl
->hbmMask
) {
1653 BitBlt (hdcDst
, 0, 0, himl
->cx
, himl
->cy
,
1654 himl
->hdcMask
, pt
.x
, pt
.y
, SRCCOPY
);
1657 PatBlt (hdcDst
, 0, 0, himl
->cx
, himl
->cy
, BLACKNESS
);
1660 SelectObject (hdcDst
, ii
.hbmColor
);
1661 BitBlt (hdcDst
, 0, 0, himl
->cx
, himl
->cy
,
1662 himl
->hdcImage
, pt
.x
, pt
.y
, SRCCOPY
);
1665 * CreateIconIndirect requires us to deselect the bitmaps from
1666 * the DCs before calling
1668 SelectObject(hdcDst
, hOldDstBitmap
);
1670 hIcon
= CreateIconIndirect (&ii
);
1672 DeleteObject (ii
.hbmMask
);
1673 DeleteObject (ii
.hbmColor
);
1680 /*************************************************************************
1681 * ImageList_GetIconSize [COMCTL32.@]
1683 * Retrieves the size of an image in an image list.
1686 * himl [I] handle to image list
1687 * cx [O] pointer to the image width.
1688 * cy [O] pointer to the image height.
1695 * All images in an image list have the same size.
1699 ImageList_GetIconSize (HIMAGELIST himl
, INT
*cx
, INT
*cy
)
1701 if (!is_valid(himl
))
1703 if ((himl
->cx
<= 0) || (himl
->cy
<= 0))
1715 /*************************************************************************
1716 * ImageList_GetImageCount [COMCTL32.@]
1718 * Returns the number of images in an image list.
1721 * himl [I] handle to image list
1724 * Success: Number of images.
1729 ImageList_GetImageCount (HIMAGELIST himl
)
1731 if (!is_valid(himl
))
1734 return himl
->cCurImage
;
1738 /*************************************************************************
1739 * ImageList_GetImageInfo [COMCTL32.@]
1741 * Returns information about an image in an image list.
1744 * himl [I] handle to image list
1746 * pImageInfo [O] pointer to the image information
1754 ImageList_GetImageInfo (HIMAGELIST himl
, INT i
, IMAGEINFO
*pImageInfo
)
1758 if (!is_valid(himl
) || (pImageInfo
== NULL
))
1760 if ((i
< 0) || (i
>= himl
->cCurImage
))
1763 pImageInfo
->hbmImage
= himl
->hbmImage
;
1764 pImageInfo
->hbmMask
= himl
->hbmMask
;
1766 imagelist_point_from_index( himl
, i
, &pt
);
1767 pImageInfo
->rcImage
.top
= pt
.y
;
1768 pImageInfo
->rcImage
.bottom
= pt
.y
+ himl
->cy
;
1769 pImageInfo
->rcImage
.left
= pt
.x
;
1770 pImageInfo
->rcImage
.right
= pt
.x
+ himl
->cx
;
1776 /*************************************************************************
1777 * ImageList_GetImageRect [COMCTL32.@]
1779 * Retrieves the rectangle of the specified image in an image list.
1782 * himl [I] handle to image list
1784 * lpRect [O] pointer to the image rectangle
1791 * This is an UNDOCUMENTED function!!!
1795 ImageList_GetImageRect (HIMAGELIST himl
, INT i
, LPRECT lpRect
)
1799 if (!is_valid(himl
) || (lpRect
== NULL
))
1801 if ((i
< 0) || (i
>= himl
->cCurImage
))
1804 imagelist_point_from_index( himl
, i
, &pt
);
1805 lpRect
->left
= pt
.x
;
1807 lpRect
->right
= pt
.x
+ himl
->cx
;
1808 lpRect
->bottom
= pt
.y
+ himl
->cy
;
1814 /*************************************************************************
1815 * ImageList_LoadImage [COMCTL32.@]
1816 * ImageList_LoadImageA [COMCTL32.@]
1818 * Creates an image list from a bitmap, icon or cursor.
1820 * See ImageList_LoadImageW.
1824 ImageList_LoadImageA (HINSTANCE hi
, LPCSTR lpbmp
, INT cx
, INT cGrow
,
1825 COLORREF clrMask
, UINT uType
, UINT uFlags
)
1831 if (IS_INTRESOURCE(lpbmp
))
1832 return ImageList_LoadImageW(hi
, (LPCWSTR
)lpbmp
, cx
, cGrow
, clrMask
,
1835 len
= MultiByteToWideChar(CP_ACP
, 0, lpbmp
, -1, NULL
, 0);
1836 lpbmpW
= Alloc(len
* sizeof(WCHAR
));
1837 MultiByteToWideChar(CP_ACP
, 0, lpbmp
, -1, lpbmpW
, len
);
1839 himl
= ImageList_LoadImageW(hi
, lpbmpW
, cx
, cGrow
, clrMask
, uType
, uFlags
);
1845 /*************************************************************************
1846 * ImageList_LoadImageW [COMCTL32.@]
1848 * Creates an image list from a bitmap, icon or cursor.
1851 * hi [I] instance handle
1852 * lpbmp [I] name or id of the image
1853 * cx [I] width of each image
1854 * cGrow [I] number of images to expand
1855 * clrMask [I] mask color
1856 * uType [I] type of image to load
1857 * uFlags [I] loading flags
1860 * Success: handle to the loaded image list
1868 ImageList_LoadImageW (HINSTANCE hi
, LPCWSTR lpbmp
, INT cx
, INT cGrow
,
1869 COLORREF clrMask
, UINT uType
, UINT uFlags
)
1871 HIMAGELIST himl
= NULL
;
1875 handle
= LoadImageW (hi
, lpbmp
, uType
, 0, 0, uFlags
);
1877 WARN("Couldn't load image\n");
1881 if (uType
== IMAGE_BITMAP
) {
1883 GetObjectW (handle
, sizeof(BITMAP
), &bmp
);
1885 /* To match windows behavior, if cx is set to zero and
1886 the flag DI_DEFAULTSIZE is specified, cx becomes the
1887 system metric value for icons. If the flag is not specified
1888 the function sets the size to the height of the bitmap */
1891 if (uFlags
& DI_DEFAULTSIZE
)
1892 cx
= GetSystemMetrics (SM_CXICON
);
1897 nImageCount
= bmp
.bmWidth
/ cx
;
1899 himl
= ImageList_Create (cx
, bmp
.bmHeight
, ILC_MASK
| ILC_COLOR
,
1900 nImageCount
, cGrow
);
1902 DeleteObject (handle
);
1905 ImageList_AddMasked (himl
, handle
, clrMask
);
1907 else if ((uType
== IMAGE_ICON
) || (uType
== IMAGE_CURSOR
)) {
1911 GetIconInfo (handle
, &ii
);
1912 GetObjectW (ii
.hbmColor
, sizeof(BITMAP
), &bmp
);
1913 himl
= ImageList_Create (bmp
.bmWidth
, bmp
.bmHeight
,
1914 ILC_MASK
| ILC_COLOR
, 1, cGrow
);
1916 DeleteObject (ii
.hbmColor
);
1917 DeleteObject (ii
.hbmMask
);
1918 DeleteObject (handle
);
1921 ImageList_Add (himl
, ii
.hbmColor
, ii
.hbmMask
);
1922 DeleteObject (ii
.hbmColor
);
1923 DeleteObject (ii
.hbmMask
);
1926 DeleteObject (handle
);
1932 /*************************************************************************
1933 * ImageList_Merge [COMCTL32.@]
1935 * Create an image list containing a merged image from two image lists.
1938 * himl1 [I] handle to first image list
1939 * i1 [I] first image index
1940 * himl2 [I] handle to second image list
1941 * i2 [I] second image index
1942 * dx [I] X offset of the second image relative to the first.
1943 * dy [I] Y offset of the second image relative to the first.
1946 * Success: The newly created image list. It contains a single image
1947 * consisting of the second image merged with the first.
1948 * Failure: NULL, if either himl1 or himl2 are invalid.
1951 * - The returned image list should be deleted by the caller using
1952 * ImageList_Destroy() when it is no longer required.
1953 * - If either i1 or i2 are not valid image indices they will be treated
1957 ImageList_Merge (HIMAGELIST himl1
, INT i1
, HIMAGELIST himl2
, INT i2
,
1960 HIMAGELIST himlDst
= NULL
;
1962 INT xOff1
, yOff1
, xOff2
, yOff2
;
1965 TRACE("(himl1=%p i1=%d himl2=%p i2=%d dx=%d dy=%d)\n", himl1
, i1
, himl2
,
1968 if (!is_valid(himl1
) || !is_valid(himl2
))
1972 cxDst
= max (himl1
->cx
, dx
+ himl2
->cx
);
1977 cxDst
= max (himl2
->cx
, himl1
->cx
- dx
);
1982 cxDst
= max (himl1
->cx
, himl2
->cx
);
1988 cyDst
= max (himl1
->cy
, dy
+ himl2
->cy
);
1993 cyDst
= max (himl2
->cy
, himl1
->cy
- dy
);
1998 cyDst
= max (himl1
->cy
, himl2
->cy
);
2003 himlDst
= ImageList_Create (cxDst
, cyDst
, ILC_MASK
| ILC_COLOR
, 1, 1);
2007 imagelist_point_from_index( himl1
, i1
, &pt1
);
2008 imagelist_point_from_index( himl1
, i2
, &pt2
);
2011 BitBlt (himlDst
->hdcImage
, 0, 0, cxDst
, cyDst
, himl1
->hdcImage
, 0, 0, BLACKNESS
);
2012 if (i1
>= 0 && i1
< himl1
->cCurImage
)
2013 BitBlt (himlDst
->hdcImage
, xOff1
, yOff1
, himl1
->cx
, himl1
->cy
, himl1
->hdcImage
, pt1
.x
, pt1
.y
, SRCCOPY
);
2014 if (i2
>= 0 && i2
< himl2
->cCurImage
)
2016 BitBlt (himlDst
->hdcImage
, xOff2
, yOff2
, himl2
->cx
, himl2
->cy
, himl2
->hdcMask
, pt2
.x
, pt2
.y
, SRCAND
);
2017 BitBlt (himlDst
->hdcImage
, xOff2
, yOff2
, himl2
->cx
, himl2
->cy
, himl2
->hdcImage
, pt2
.x
, pt2
.y
, SRCPAINT
);
2021 BitBlt (himlDst
->hdcMask
, 0, 0, cxDst
, cyDst
, himl1
->hdcMask
, 0, 0, WHITENESS
);
2022 if (i1
>= 0 && i1
< himl1
->cCurImage
)
2023 BitBlt (himlDst
->hdcMask
, xOff1
, yOff1
, himl1
->cx
, himl1
->cy
, himl1
->hdcMask
, pt1
.x
, pt1
.y
, SRCCOPY
);
2024 if (i2
>= 0 && i2
< himl2
->cCurImage
)
2025 BitBlt (himlDst
->hdcMask
, xOff2
, yOff2
, himl2
->cx
, himl2
->cy
, himl2
->hdcMask
, pt2
.x
, pt2
.y
, SRCAND
);
2027 himlDst
->cCurImage
= 1;
2034 /***********************************************************************
2035 * DIB_GetDIBWidthBytes
2037 * Return the width of a DIB bitmap in bytes. DIB bitmap data is 32-bit aligned.
2039 static int DIB_GetDIBWidthBytes( int width
, int depth
)
2045 case 1: words
= (width
+ 31) / 32; break;
2046 case 4: words
= (width
+ 7) / 8; break;
2047 case 8: words
= (width
+ 3) / 4; break;
2049 case 16: words
= (width
+ 1) / 2; break;
2050 case 24: words
= (width
* 3 + 3)/4; break;
2053 WARN("(%d): Unsupported depth\n", depth
);
2062 /***********************************************************************
2063 * DIB_GetDIBImageBytes
2065 * Return the number of bytes used to hold the image in a DIB bitmap.
2067 static int DIB_GetDIBImageBytes( int width
, int height
, int depth
)
2069 return DIB_GetDIBWidthBytes( width
, depth
) * abs( height
);
2073 /* helper for ImageList_Read, see comments below */
2074 static BOOL
_read_bitmap(HDC hdcIml
, LPSTREAM pstm
)
2076 BITMAPFILEHEADER bmfh
;
2077 int bitsperpixel
, palspace
;
2078 char bmi_buf
[sizeof(BITMAPINFOHEADER
) + sizeof(RGBQUAD
) * 256];
2079 LPBITMAPINFO bmi
= (LPBITMAPINFO
)bmi_buf
;
2083 if (FAILED(IStream_Read ( pstm
, &bmfh
, sizeof(bmfh
), NULL
)))
2086 if (bmfh
.bfType
!= (('M'<<8)|'B'))
2089 if (FAILED(IStream_Read ( pstm
, &bmi
->bmiHeader
, sizeof(bmi
->bmiHeader
), NULL
)))
2092 if ((bmi
->bmiHeader
.biSize
!= sizeof(bmi
->bmiHeader
)))
2095 TRACE("width %u, height %u, planes %u, bpp %u\n",
2096 bmi
->bmiHeader
.biWidth
, bmi
->bmiHeader
.biHeight
,
2097 bmi
->bmiHeader
.biPlanes
, bmi
->bmiHeader
.biBitCount
);
2099 bitsperpixel
= bmi
->bmiHeader
.biPlanes
* bmi
->bmiHeader
.biBitCount
;
2100 if (bitsperpixel
<=8)
2101 palspace
= (1<<bitsperpixel
)*sizeof(RGBQUAD
);
2105 bmi
->bmiHeader
.biSizeImage
= DIB_GetDIBImageBytes(bmi
->bmiHeader
.biWidth
, bmi
->bmiHeader
.biHeight
, bitsperpixel
);
2107 /* read the palette right after the end of the bitmapinfoheader */
2108 if (palspace
&& FAILED(IStream_Read(pstm
, bmi
->bmiColors
, palspace
, NULL
)))
2111 bits
= Alloc(bmi
->bmiHeader
.biSizeImage
);
2114 if (FAILED(IStream_Read(pstm
, bits
, bmi
->bmiHeader
.biSizeImage
, NULL
)))
2117 if (!StretchDIBits(hdcIml
, 0, 0, bmi
->bmiHeader
.biWidth
, bmi
->bmiHeader
.biHeight
,
2118 0, 0, bmi
->bmiHeader
.biWidth
, bmi
->bmiHeader
.biHeight
,
2119 bits
, bmi
, DIB_RGB_COLORS
, SRCCOPY
))
2128 /*************************************************************************
2129 * ImageList_Read [COMCTL32.@]
2131 * Reads an image list from a stream.
2134 * pstm [I] pointer to a stream
2137 * Success: handle to image list
2140 * The format is like this:
2141 * ILHEAD ilheadstruct;
2143 * for the color image part:
2144 * BITMAPFILEHEADER bmfh;
2145 * BITMAPINFOHEADER bmih;
2146 * only if it has a palette:
2147 * RGBQUAD rgbs[nr_of_paletted_colors];
2149 * BYTE colorbits[imagesize];
2151 * the following only if the ILC_MASK bit is set in ILHEAD.ilFlags:
2152 * BITMAPFILEHEADER bmfh_mask;
2153 * BITMAPINFOHEADER bmih_mask;
2154 * only if it has a palette (it usually does not):
2155 * RGBQUAD rgbs[nr_of_paletted_colors];
2157 * BYTE maskbits[imagesize];
2159 HIMAGELIST WINAPI
ImageList_Read (LPSTREAM pstm
)
2165 TRACE("%p\n", pstm
);
2167 if (FAILED(IStream_Read (pstm
, &ilHead
, sizeof(ILHEAD
), NULL
)))
2169 if (ilHead
.usMagic
!= (('L' << 8) | 'I'))
2171 if (ilHead
.usVersion
!= 0x101) /* probably version? */
2174 TRACE("cx %u, cy %u, flags 0x%04x, cCurImage %u, cMaxImage %u\n",
2175 ilHead
.cx
, ilHead
.cy
, ilHead
.flags
, ilHead
.cCurImage
, ilHead
.cMaxImage
);
2177 himl
= ImageList_Create(ilHead
.cx
, ilHead
.cy
, ilHead
.flags
, ilHead
.cCurImage
, ilHead
.cMaxImage
);
2181 if (!_read_bitmap(himl
->hdcImage
, pstm
))
2183 WARN("failed to read bitmap from stream\n");
2186 if (ilHead
.flags
& ILC_MASK
)
2188 if (!_read_bitmap(himl
->hdcMask
, pstm
))
2190 WARN("failed to read mask bitmap from stream\n");
2195 himl
->cCurImage
= ilHead
.cCurImage
;
2196 himl
->cMaxImage
= ilHead
.cMaxImage
;
2198 ImageList_SetBkColor(himl
,ilHead
.bkcolor
);
2200 ImageList_SetOverlayImage(himl
,ilHead
.ovls
[i
],i
+1);
2205 /*************************************************************************
2206 * ImageList_Remove [COMCTL32.@]
2208 * Removes an image from an image list
2211 * himl [I] image list handle
2218 * FIXME: as the image list storage test shows, native comctl32 simply shifts
2219 * images without creating a new bitmap.
2222 ImageList_Remove (HIMAGELIST himl
, INT i
)
2224 HBITMAP hbmNewImage
, hbmNewMask
;
2228 TRACE("(himl=%p i=%d)\n", himl
, i
);
2230 if (!is_valid(himl
)) {
2231 ERR("Invalid image list handle!\n");
2235 if ((i
< -1) || (i
>= himl
->cCurImage
)) {
2236 TRACE("index out of range! %d\n", i
);
2244 if (himl
->cCurImage
== 0) {
2245 /* remove all on empty ImageList is allowed */
2246 TRACE("remove all on empty ImageList!\n");
2250 himl
->cMaxImage
= himl
->cInitial
+ himl
->cGrow
- 1;
2251 himl
->cCurImage
= 0;
2252 for (nCount
= 0; nCount
< MAX_OVERLAYIMAGE
; nCount
++)
2253 himl
->nOvlIdx
[nCount
] = -1;
2255 hbmNewImage
= ImageList_CreateImage(himl
->hdcImage
, himl
, himl
->cMaxImage
);
2256 SelectObject (himl
->hdcImage
, hbmNewImage
);
2257 DeleteObject (himl
->hbmImage
);
2258 himl
->hbmImage
= hbmNewImage
;
2260 if (himl
->hbmMask
) {
2262 imagelist_get_bitmap_size(himl
, himl
->cMaxImage
, &sz
);
2263 hbmNewMask
= CreateBitmap (sz
.cx
, sz
.cy
, 1, 1, NULL
);
2264 SelectObject (himl
->hdcMask
, hbmNewMask
);
2265 DeleteObject (himl
->hbmMask
);
2266 himl
->hbmMask
= hbmNewMask
;
2270 /* delete one image */
2271 TRACE("Remove single image! %d\n", i
);
2273 /* create new bitmap(s) */
2274 TRACE(" - Number of images: %d / %d (Old/New)\n",
2275 himl
->cCurImage
, himl
->cCurImage
- 1);
2277 hbmNewImage
= ImageList_CreateImage(himl
->hdcImage
, himl
, himl
->cMaxImage
);
2279 imagelist_get_bitmap_size(himl
, himl
->cMaxImage
, &sz
);
2281 hbmNewMask
= CreateBitmap (sz
.cx
, sz
.cy
, 1, 1, NULL
);
2283 hbmNewMask
= 0; /* Just to keep compiler happy! */
2285 hdcBmp
= CreateCompatibleDC (0);
2287 /* copy all images and masks prior to the "removed" image */
2289 TRACE("Pre image copy: Copy %d images\n", i
);
2291 SelectObject (hdcBmp
, hbmNewImage
);
2292 imagelist_copy_images( himl
, himl
->hdcImage
, hdcBmp
, 0, i
, 0 );
2294 if (himl
->hbmMask
) {
2295 SelectObject (hdcBmp
, hbmNewMask
);
2296 imagelist_copy_images( himl
, himl
->hdcMask
, hdcBmp
, 0, i
, 0 );
2300 /* copy all images and masks behind the removed image */
2301 if (i
< himl
->cCurImage
- 1) {
2302 TRACE("Post image copy!\n");
2304 SelectObject (hdcBmp
, hbmNewImage
);
2305 imagelist_copy_images( himl
, himl
->hdcImage
, hdcBmp
, i
+ 1,
2306 (himl
->cCurImage
- i
), i
);
2308 if (himl
->hbmMask
) {
2309 SelectObject (hdcBmp
, hbmNewMask
);
2310 imagelist_copy_images( himl
, himl
->hdcMask
, hdcBmp
, i
+ 1,
2311 (himl
->cCurImage
- i
), i
);
2317 /* delete old images and insert new ones */
2318 SelectObject (himl
->hdcImage
, hbmNewImage
);
2319 DeleteObject (himl
->hbmImage
);
2320 himl
->hbmImage
= hbmNewImage
;
2321 if (himl
->hbmMask
) {
2322 SelectObject (himl
->hdcMask
, hbmNewMask
);
2323 DeleteObject (himl
->hbmMask
);
2324 himl
->hbmMask
= hbmNewMask
;
2334 /*************************************************************************
2335 * ImageList_Replace [COMCTL32.@]
2337 * Replaces an image in an image list with a new image.
2340 * himl [I] handle to image list
2342 * hbmImage [I] handle to image bitmap
2343 * hbmMask [I] handle to mask bitmap. Can be NULL.
2351 ImageList_Replace (HIMAGELIST himl
, INT i
, HBITMAP hbmImage
,
2358 TRACE("%p %d %p %p\n", himl
, i
, hbmImage
, hbmMask
);
2360 if (!is_valid(himl
)) {
2361 ERR("Invalid image list handle!\n");
2365 if ((i
>= himl
->cMaxImage
) || (i
< 0)) {
2366 ERR("Invalid image index!\n");
2370 if (!GetObjectW(hbmImage
, sizeof(BITMAP
), &bmp
))
2373 hdcImage
= CreateCompatibleDC (0);
2376 SelectObject (hdcImage
, hbmImage
);
2378 if (add_with_alpha( himl
, hdcImage
, i
, 1, bmp
.bmWidth
, bmp
.bmHeight
, hbmImage
, hbmMask
))
2381 imagelist_point_from_index(himl
, i
, &pt
);
2382 StretchBlt (himl
->hdcImage
, pt
.x
, pt
.y
, himl
->cx
, himl
->cy
,
2383 hdcImage
, 0, 0, bmp
.bmWidth
, bmp
.bmHeight
, SRCCOPY
);
2388 HBITMAP hOldBitmapTemp
;
2390 hdcTemp
= CreateCompatibleDC(0);
2391 hOldBitmapTemp
= SelectObject(hdcTemp
, hbmMask
);
2393 StretchBlt (himl
->hdcMask
, pt
.x
, pt
.y
, himl
->cx
, himl
->cy
,
2394 hdcTemp
, 0, 0, bmp
.bmWidth
, bmp
.bmHeight
, SRCCOPY
);
2395 SelectObject(hdcTemp
, hOldBitmapTemp
);
2398 /* Remove the background from the image
2400 BitBlt (himl
->hdcImage
, pt
.x
, pt
.y
, bmp
.bmWidth
, bmp
.bmHeight
,
2401 himl
->hdcMask
, pt
.x
, pt
.y
, 0x220326); /* NOTSRCAND */
2405 DeleteDC (hdcImage
);
2411 /*************************************************************************
2412 * ImageList_ReplaceIcon [COMCTL32.@]
2414 * Replaces an image in an image list using an icon.
2417 * himl [I] handle to image list
2419 * hIcon [I] handle to icon
2422 * Success: index of the replaced image
2427 ImageList_ReplaceIcon (HIMAGELIST himl
, INT nIndex
, HICON hIcon
)
2436 TRACE("(%p %d %p)\n", himl
, nIndex
, hIcon
);
2438 if (!is_valid(himl
)) {
2439 ERR("invalid image list\n");
2442 if ((nIndex
>= himl
->cMaxImage
) || (nIndex
< -1)) {
2443 ERR("invalid image index %d / %d\n", nIndex
, himl
->cMaxImage
);
2447 hBestFitIcon
= CopyImage(
2450 LR_COPYFROMRESOURCE
);
2451 /* the above will fail if the icon wasn't loaded from a resource, so try
2452 * again without LR_COPYFROMRESOURCE flag */
2454 hBestFitIcon
= CopyImage(
2461 ret
= GetIconInfo (hBestFitIcon
, &ii
);
2463 DestroyIcon(hBestFitIcon
);
2467 ret
= GetObjectW (ii
.hbmMask
, sizeof(BITMAP
), &bmp
);
2469 ERR("couldn't get mask bitmap info\n");
2471 DeleteObject (ii
.hbmColor
);
2473 DeleteObject (ii
.hbmMask
);
2474 DestroyIcon(hBestFitIcon
);
2479 if (himl
->cCurImage
+ 1 > himl
->cMaxImage
)
2480 IMAGELIST_InternalExpandBitmaps(himl
, 1);
2482 nIndex
= himl
->cCurImage
;
2486 hdcImage
= CreateCompatibleDC (0);
2487 TRACE("hdcImage=%p\n", hdcImage
);
2489 ERR("invalid hdcImage!\n");
2491 if (himl
->uBitsPixel
== 32)
2495 UINT height
= bmp
.bmHeight
/ 2;
2496 HDC hdcMask
= CreateCompatibleDC( 0 );
2497 HBITMAP color
= CreateBitmap( bmp
.bmWidth
, height
, 1, 1, NULL
);
2498 SelectObject( hdcImage
, color
);
2499 SelectObject( hdcMask
, ii
.hbmMask
);
2500 BitBlt( hdcImage
, 0, 0, bmp
.bmWidth
, height
, hdcMask
, 0, height
, SRCCOPY
);
2501 add_with_alpha( himl
, hdcImage
, nIndex
, 1, bmp
.bmWidth
, height
, color
, ii
.hbmMask
);
2502 DeleteDC( hdcMask
);
2503 DeleteObject( color
);
2505 else add_with_alpha( himl
, hdcImage
, nIndex
, 1, bmp
.bmWidth
, bmp
.bmHeight
, ii
.hbmColor
, ii
.hbmMask
);
2510 imagelist_point_from_index(himl
, nIndex
, &pt
);
2512 SetTextColor(himl
->hdcImage
, RGB(0,0,0));
2513 SetBkColor (himl
->hdcImage
, RGB(255,255,255));
2517 SelectObject (hdcImage
, ii
.hbmColor
);
2518 StretchBlt (himl
->hdcImage
, pt
.x
, pt
.y
, himl
->cx
, himl
->cy
,
2519 hdcImage
, 0, 0, bmp
.bmWidth
, bmp
.bmHeight
, SRCCOPY
);
2522 SelectObject (hdcImage
, ii
.hbmMask
);
2523 StretchBlt (himl
->hdcMask
, pt
.x
, pt
.y
, himl
->cx
, himl
->cy
,
2524 hdcImage
, 0, 0, bmp
.bmWidth
, bmp
.bmHeight
, SRCCOPY
);
2529 UINT height
= bmp
.bmHeight
/ 2;
2530 SelectObject (hdcImage
, ii
.hbmMask
);
2531 StretchBlt (himl
->hdcImage
, pt
.x
, pt
.y
, himl
->cx
, himl
->cy
,
2532 hdcImage
, 0, height
, bmp
.bmWidth
, height
, SRCCOPY
);
2534 StretchBlt (himl
->hdcMask
, pt
.x
, pt
.y
, himl
->cx
, himl
->cy
,
2535 hdcImage
, 0, 0, bmp
.bmWidth
, height
, SRCCOPY
);
2539 DestroyIcon(hBestFitIcon
);
2541 DeleteDC (hdcImage
);
2543 DeleteObject (ii
.hbmColor
);
2545 DeleteObject (ii
.hbmMask
);
2547 TRACE("Insert index = %d, himl->cCurImage = %d\n", nIndex
, himl
->cCurImage
);
2552 /*************************************************************************
2553 * ImageList_SetBkColor [COMCTL32.@]
2555 * Sets the background color of an image list.
2558 * himl [I] handle to image list
2559 * clrBk [I] background color
2562 * Success: previous background color
2567 ImageList_SetBkColor (HIMAGELIST himl
, COLORREF clrBk
)
2571 if (!is_valid(himl
))
2574 clrOldBk
= himl
->clrBk
;
2575 himl
->clrBk
= clrBk
;
2580 /*************************************************************************
2581 * ImageList_SetDragCursorImage [COMCTL32.@]
2583 * Combines the specified image with the current drag image
2586 * himlDrag [I] handle to drag image list
2587 * iDrag [I] drag image index
2588 * dxHotspot [I] X position of the hot spot
2589 * dyHotspot [I] Y position of the hot spot
2596 * - The names dxHotspot, dyHotspot are misleading because they have nothing
2597 * to do with a hotspot but are only the offset of the origin of the new
2598 * image relative to the origin of the old image.
2600 * - When this function is called and the drag image is visible, a
2601 * short flickering occurs but this matches the Win9x behavior. It is
2602 * possible to fix the flickering using code like in ImageList_DragMove.
2606 ImageList_SetDragCursorImage (HIMAGELIST himlDrag
, INT iDrag
,
2607 INT dxHotspot
, INT dyHotspot
)
2609 HIMAGELIST himlTemp
;
2612 if (!is_valid(InternalDrag
.himl
) || !is_valid(himlDrag
))
2615 TRACE(" dxH=%d dyH=%d nX=%d nY=%d\n",
2616 dxHotspot
, dyHotspot
, InternalDrag
.dxHotspot
, InternalDrag
.dyHotspot
);
2618 visible
= InternalDrag
.bShow
;
2620 himlTemp
= ImageList_Merge (InternalDrag
.himl
, 0, himlDrag
, iDrag
,
2621 dxHotspot
, dyHotspot
);
2624 /* hide the drag image */
2625 ImageList_DragShowNolock(FALSE
);
2627 if ((InternalDrag
.himl
->cx
!= himlTemp
->cx
) ||
2628 (InternalDrag
.himl
->cy
!= himlTemp
->cy
)) {
2629 /* the size of the drag image changed, invalidate the buffer */
2630 DeleteObject(InternalDrag
.hbmBg
);
2631 InternalDrag
.hbmBg
= 0;
2634 ImageList_Destroy (InternalDrag
.himl
);
2635 InternalDrag
.himl
= himlTemp
;
2638 /* show the drag image */
2639 ImageList_DragShowNolock(TRUE
);
2646 /*************************************************************************
2647 * ImageList_SetFilter [COMCTL32.@]
2649 * Sets a filter (or does something completely different)!!???
2650 * It removes 12 Bytes from the stack (3 Parameters).
2653 * himl [I] SHOULD be a handle to image list
2654 * i [I] COULD be an index?
2659 * Failure: FALSE ???
2662 * This is an UNDOCUMENTED function!!!!
2667 ImageList_SetFilter (HIMAGELIST himl
, INT i
, DWORD dwFilter
)
2669 FIXME("(%p 0x%x 0x%x):empty stub!\n", himl
, i
, dwFilter
);
2675 /*************************************************************************
2676 * ImageList_SetFlags [COMCTL32.@]
2678 * Sets the image list flags.
2681 * himl [I] Handle to image list
2682 * flags [I] Flags to set
2692 ImageList_SetFlags(HIMAGELIST himl
, DWORD flags
)
2694 FIXME("(%p %08x):empty stub\n", himl
, flags
);
2699 /*************************************************************************
2700 * ImageList_SetIconSize [COMCTL32.@]
2702 * Sets the image size of the bitmap and deletes all images.
2705 * himl [I] handle to image list
2706 * cx [I] image width
2707 * cy [I] image height
2715 ImageList_SetIconSize (HIMAGELIST himl
, INT cx
, INT cy
)
2720 if (!is_valid(himl
))
2723 /* remove all images */
2724 himl
->cMaxImage
= himl
->cInitial
+ 1;
2725 himl
->cCurImage
= 0;
2729 /* initialize overlay mask indices */
2730 for (nCount
= 0; nCount
< MAX_OVERLAYIMAGE
; nCount
++)
2731 himl
->nOvlIdx
[nCount
] = -1;
2733 hbmNew
= ImageList_CreateImage(himl
->hdcImage
, himl
, himl
->cMaxImage
);
2734 SelectObject (himl
->hdcImage
, hbmNew
);
2735 DeleteObject (himl
->hbmImage
);
2736 himl
->hbmImage
= hbmNew
;
2738 if (himl
->hbmMask
) {
2740 imagelist_get_bitmap_size(himl
, himl
->cMaxImage
, &sz
);
2741 hbmNew
= CreateBitmap (sz
.cx
, sz
.cy
, 1, 1, NULL
);
2742 SelectObject (himl
->hdcMask
, hbmNew
);
2743 DeleteObject (himl
->hbmMask
);
2744 himl
->hbmMask
= hbmNew
;
2751 /*************************************************************************
2752 * ImageList_SetImageCount [COMCTL32.@]
2754 * Resizes an image list to the specified number of images.
2757 * himl [I] handle to image list
2758 * iImageCount [I] number of images in the image list
2766 ImageList_SetImageCount (HIMAGELIST himl
, UINT iImageCount
)
2769 HBITMAP hbmNewBitmap
, hbmOld
;
2770 INT nNewCount
, nCopyCount
;
2772 TRACE("%p %d\n",himl
,iImageCount
);
2774 if (!is_valid(himl
))
2776 if (himl
->cMaxImage
> iImageCount
)
2778 himl
->cCurImage
= iImageCount
;
2779 /* TODO: shrink the bitmap when cMaxImage-cCurImage>cGrow ? */
2783 nNewCount
= iImageCount
+ himl
->cGrow
;
2784 nCopyCount
= min(himl
->cCurImage
, iImageCount
);
2786 hdcBitmap
= CreateCompatibleDC (0);
2788 hbmNewBitmap
= ImageList_CreateImage(hdcBitmap
, himl
, nNewCount
);
2790 if (hbmNewBitmap
!= 0)
2792 hbmOld
= SelectObject (hdcBitmap
, hbmNewBitmap
);
2793 imagelist_copy_images( himl
, himl
->hdcImage
, hdcBitmap
, 0, nCopyCount
, 0 );
2794 SelectObject (hdcBitmap
, hbmOld
);
2796 /* FIXME: delete 'empty' image space? */
2798 SelectObject (himl
->hdcImage
, hbmNewBitmap
);
2799 DeleteObject (himl
->hbmImage
);
2800 himl
->hbmImage
= hbmNewBitmap
;
2803 ERR("Could not create new image bitmap !\n");
2808 imagelist_get_bitmap_size( himl
, nNewCount
, &sz
);
2809 hbmNewBitmap
= CreateBitmap (sz
.cx
, sz
.cy
, 1, 1, NULL
);
2810 if (hbmNewBitmap
!= 0)
2812 hbmOld
= SelectObject (hdcBitmap
, hbmNewBitmap
);
2813 imagelist_copy_images( himl
, himl
->hdcMask
, hdcBitmap
, 0, nCopyCount
, 0 );
2814 SelectObject (hdcBitmap
, hbmOld
);
2816 /* FIXME: delete 'empty' image space? */
2818 SelectObject (himl
->hdcMask
, hbmNewBitmap
);
2819 DeleteObject (himl
->hbmMask
);
2820 himl
->hbmMask
= hbmNewBitmap
;
2823 ERR("Could not create new mask bitmap!\n");
2826 DeleteDC (hdcBitmap
);
2828 /* Update max image count and current image count */
2829 himl
->cMaxImage
= nNewCount
;
2830 himl
->cCurImage
= iImageCount
;
2836 /*************************************************************************
2837 * ImageList_SetOverlayImage [COMCTL32.@]
2839 * Assigns an overlay mask index to an existing image in an image list.
2842 * himl [I] handle to image list
2843 * iImage [I] image index
2844 * iOverlay [I] overlay mask index
2852 ImageList_SetOverlayImage (HIMAGELIST himl
, INT iImage
, INT iOverlay
)
2854 if (!is_valid(himl
))
2856 if ((iOverlay
< 1) || (iOverlay
> MAX_OVERLAYIMAGE
))
2858 if ((iImage
!=-1) && ((iImage
< 0) || (iImage
> himl
->cCurImage
)))
2860 himl
->nOvlIdx
[iOverlay
- 1] = iImage
;
2866 /* helper for ImageList_Write - write bitmap to pstm
2867 * currently everything is written as 24 bit RGB, except masks
2870 _write_bitmap(HBITMAP hBitmap
, LPSTREAM pstm
)
2872 LPBITMAPFILEHEADER bmfh
;
2873 LPBITMAPINFOHEADER bmih
;
2874 LPBYTE data
= NULL
, lpBits
;
2876 INT bitCount
, sizeImage
, offBits
, totalSize
;
2878 BOOL result
= FALSE
;
2880 if (!GetObjectW(hBitmap
, sizeof(BITMAP
), &bm
))
2883 bitCount
= bm
.bmBitsPixel
== 1 ? 1 : 24;
2884 sizeImage
= DIB_GetDIBImageBytes(bm
.bmWidth
, bm
.bmHeight
, bitCount
);
2886 totalSize
= sizeof(BITMAPFILEHEADER
) + sizeof(BITMAPINFOHEADER
);
2888 totalSize
+= (1 << bitCount
) * sizeof(RGBQUAD
);
2889 offBits
= totalSize
;
2890 totalSize
+= sizeImage
;
2892 data
= Alloc(totalSize
);
2893 bmfh
= (LPBITMAPFILEHEADER
)data
;
2894 bmih
= (LPBITMAPINFOHEADER
)(data
+ sizeof(BITMAPFILEHEADER
));
2895 lpBits
= data
+ offBits
;
2897 /* setup BITMAPFILEHEADER */
2898 bmfh
->bfType
= (('M' << 8) | 'B');
2899 bmfh
->bfSize
= offBits
;
2900 bmfh
->bfReserved1
= 0;
2901 bmfh
->bfReserved2
= 0;
2902 bmfh
->bfOffBits
= offBits
;
2904 /* setup BITMAPINFOHEADER */
2905 bmih
->biSize
= sizeof(BITMAPINFOHEADER
);
2906 bmih
->biWidth
= bm
.bmWidth
;
2907 bmih
->biHeight
= bm
.bmHeight
;
2909 bmih
->biBitCount
= bitCount
;
2910 bmih
->biCompression
= BI_RGB
;
2911 bmih
->biSizeImage
= sizeImage
;
2912 bmih
->biXPelsPerMeter
= 0;
2913 bmih
->biYPelsPerMeter
= 0;
2914 bmih
->biClrUsed
= 0;
2915 bmih
->biClrImportant
= 0;
2918 result
= GetDIBits(xdc
, hBitmap
, 0, bm
.bmHeight
, lpBits
, (BITMAPINFO
*)bmih
, DIB_RGB_COLORS
) == bm
.bmHeight
;
2923 TRACE("width %u, height %u, planes %u, bpp %u\n",
2924 bmih
->biWidth
, bmih
->biHeight
,
2925 bmih
->biPlanes
, bmih
->biBitCount
);
2929 LPBITMAPINFO inf
= (LPBITMAPINFO
)bmih
;
2930 inf
->bmiColors
[0].rgbRed
= inf
->bmiColors
[0].rgbGreen
= inf
->bmiColors
[0].rgbBlue
= 0;
2931 inf
->bmiColors
[1].rgbRed
= inf
->bmiColors
[1].rgbGreen
= inf
->bmiColors
[1].rgbBlue
= 0xff;
2934 if(FAILED(IStream_Write(pstm
, data
, totalSize
, NULL
)))
2946 /*************************************************************************
2947 * ImageList_Write [COMCTL32.@]
2949 * Writes an image list to a stream.
2952 * himl [I] handle to image list
2953 * pstm [O] Pointer to a stream.
2964 ImageList_Write (HIMAGELIST himl
, LPSTREAM pstm
)
2969 TRACE("%p %p\n", himl
, pstm
);
2971 if (!is_valid(himl
))
2974 ilHead
.usMagic
= (('L' << 8) | 'I');
2975 ilHead
.usVersion
= 0x101;
2976 ilHead
.cCurImage
= himl
->cCurImage
;
2977 ilHead
.cMaxImage
= himl
->cMaxImage
;
2978 ilHead
.cGrow
= himl
->cGrow
;
2979 ilHead
.cx
= himl
->cx
;
2980 ilHead
.cy
= himl
->cy
;
2981 ilHead
.bkcolor
= himl
->clrBk
;
2982 ilHead
.flags
= himl
->flags
;
2983 for(i
= 0; i
< 4; i
++) {
2984 ilHead
.ovls
[i
] = himl
->nOvlIdx
[i
];
2987 TRACE("cx %u, cy %u, flags 0x04%x, cCurImage %u, cMaxImage %u\n",
2988 ilHead
.cx
, ilHead
.cy
, ilHead
.flags
, ilHead
.cCurImage
, ilHead
.cMaxImage
);
2990 if(FAILED(IStream_Write(pstm
, &ilHead
, sizeof(ILHEAD
), NULL
)))
2993 /* write the bitmap */
2994 if(!_write_bitmap(himl
->hbmImage
, pstm
))
2997 /* write the mask if we have one */
2998 if(himl
->flags
& ILC_MASK
) {
2999 if(!_write_bitmap(himl
->hbmMask
, pstm
))
3007 static HBITMAP
ImageList_CreateImage(HDC hdc
, HIMAGELIST himl
, UINT count
)
3009 HBITMAP hbmNewBitmap
;
3010 UINT ilc
= (himl
->flags
& 0xFE);
3013 imagelist_get_bitmap_size( himl
, count
, &sz
);
3015 if ((ilc
>= ILC_COLOR4
&& ilc
<= ILC_COLOR32
) || ilc
== ILC_COLOR
)
3020 TRACE("Creating DIBSection %d x %d, %d Bits per Pixel\n",
3021 sz
.cx
, sz
.cy
, himl
->uBitsPixel
);
3023 if (himl
->uBitsPixel
<= ILC_COLOR8
)
3029 colors
= 1 << himl
->uBitsPixel
;
3030 bmi
= Alloc(sizeof(BITMAPINFOHEADER
) +
3031 sizeof(PALETTEENTRY
) * colors
);
3033 pal
= (LPPALETTEENTRY
)bmi
->bmiColors
;
3034 GetPaletteEntries(GetStockObject(DEFAULT_PALETTE
), 0, colors
, pal
);
3036 /* Swap colors returned by GetPaletteEntries so we can use them for
3037 * CreateDIBSection call. */
3038 for (i
= 0; i
< colors
; i
++)
3040 temp
= pal
[i
].peBlue
;
3041 bmi
->bmiColors
[i
].rgbRed
= pal
[i
].peRed
;
3042 bmi
->bmiColors
[i
].rgbBlue
= temp
;
3047 bmi
= Alloc(sizeof(BITMAPINFOHEADER
));
3050 bmi
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
3051 bmi
->bmiHeader
.biWidth
= sz
.cx
;
3052 bmi
->bmiHeader
.biHeight
= sz
.cy
;
3053 bmi
->bmiHeader
.biPlanes
= 1;
3054 bmi
->bmiHeader
.biBitCount
= himl
->uBitsPixel
;
3055 bmi
->bmiHeader
.biCompression
= BI_RGB
;
3056 bmi
->bmiHeader
.biSizeImage
= 0;
3057 bmi
->bmiHeader
.biXPelsPerMeter
= 0;
3058 bmi
->bmiHeader
.biYPelsPerMeter
= 0;
3059 bmi
->bmiHeader
.biClrUsed
= 0;
3060 bmi
->bmiHeader
.biClrImportant
= 0;
3062 hbmNewBitmap
= CreateDIBSection(hdc
, bmi
, DIB_RGB_COLORS
, &bits
, 0, 0);
3066 else /*if (ilc == ILC_COLORDDB)*/
3068 TRACE("Creating Bitmap: %d Bits per Pixel\n", himl
->uBitsPixel
);
3070 hbmNewBitmap
= CreateBitmap (sz
.cx
, sz
.cy
, 1, himl
->uBitsPixel
, NULL
);
3072 TRACE("returning %p\n", hbmNewBitmap
);
3073 return hbmNewBitmap
;
3076 /*************************************************************************
3077 * ImageList_SetColorTable [COMCTL32.@]
3079 * Sets the color table of an image list.
3082 * himl [I] Handle to the image list.
3083 * uStartIndex [I] The first index to set.
3084 * cEntries [I] Number of entries to set.
3085 * prgb [I] New color information for color table for the image list.
3088 * Success: Number of entries in the table that were set.
3092 * ImageList_Create(), SetDIBColorTable()
3096 ImageList_SetColorTable (HIMAGELIST himl
, UINT uStartIndex
, UINT cEntries
, CONST RGBQUAD
* prgb
)
3098 return SetDIBColorTable(himl
->hdcImage
, uStartIndex
, cEntries
, prgb
);
3101 /*************************************************************************
3102 * ImageList_CoCreateInstance [COMCTL32.@]
3104 * Creates a new imagelist instance and returns an interface pointer to it.
3107 * rclsid [I] A reference to the CLSID (CLSID_ImageList).
3108 * punkOuter [I] Pointer to IUnknown interface for aggregation, if desired
3109 * riid [I] Identifier of the requested interface.
3110 * ppv [O] Returns the address of the pointer requested, or NULL.
3114 * Failure: Error value.
3117 ImageList_CoCreateInstance (REFCLSID rclsid
, const IUnknown
*punkOuter
, REFIID riid
, void **ppv
)
3119 TRACE("(%s,%p,%s,%p)\n", debugstr_guid(rclsid
), punkOuter
, debugstr_guid(riid
), ppv
);
3121 if (!IsEqualCLSID(&CLSID_ImageList
, rclsid
))
3122 return E_NOINTERFACE
;
3124 return ImageListImpl_CreateInstance(punkOuter
, riid
, ppv
);
3128 /*************************************************************************
3129 * IImageList implementation
3132 static HRESULT WINAPI
ImageListImpl_QueryInterface(IImageList
*iface
,
3133 REFIID iid
, void **ppv
)
3135 HIMAGELIST This
= (HIMAGELIST
) iface
;
3136 TRACE("(%p,%s,%p)\n", iface
, debugstr_guid(iid
), ppv
);
3138 if (!ppv
) return E_INVALIDARG
;
3140 if (IsEqualIID(&IID_IUnknown
, iid
) || IsEqualIID(&IID_IImageList
, iid
))
3145 return E_NOINTERFACE
;
3148 IUnknown_AddRef((IUnknown
*)*ppv
);
3152 static ULONG WINAPI
ImageListImpl_AddRef(IImageList
*iface
)
3154 HIMAGELIST This
= (HIMAGELIST
) iface
;
3155 ULONG ref
= InterlockedIncrement(&This
->ref
);
3157 TRACE("(%p) refcount=%u\n", iface
, ref
);
3161 static ULONG WINAPI
ImageListImpl_Release(IImageList
*iface
)
3163 HIMAGELIST This
= (HIMAGELIST
) iface
;
3164 ULONG ref
= InterlockedDecrement(&This
->ref
);
3166 TRACE("(%p) refcount=%u\n", iface
, ref
);
3170 /* delete image bitmaps */
3171 if (This
->hbmImage
) DeleteObject (This
->hbmImage
);
3172 if (This
->hbmMask
) DeleteObject (This
->hbmMask
);
3174 /* delete image & mask DCs */
3175 if (This
->hdcImage
) DeleteDC (This
->hdcImage
);
3176 if (This
->hdcMask
) DeleteDC (This
->hdcMask
);
3178 /* delete blending brushes */
3179 if (This
->hbrBlend25
) DeleteObject (This
->hbrBlend25
);
3180 if (This
->hbrBlend50
) DeleteObject (This
->hbrBlend50
);
3182 This
->lpVtbl
= NULL
;
3183 HeapFree(GetProcessHeap(), 0, This
->has_alpha
);
3184 HeapFree(GetProcessHeap(), 0, This
);
3190 static HRESULT WINAPI
ImageListImpl_Add(IImageList
*iface
, HBITMAP hbmImage
,
3191 HBITMAP hbmMask
, int *pi
)
3193 HIMAGELIST This
= (HIMAGELIST
) iface
;
3199 ret
= ImageList_Add(This
, hbmImage
, hbmMask
);
3208 static HRESULT WINAPI
ImageListImpl_ReplaceIcon(IImageList
*iface
, int i
,
3209 HICON hicon
, int *pi
)
3211 HIMAGELIST This
= (HIMAGELIST
) iface
;