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 info
->bmiColors
[0].rgbRed
= 0;
1230 info
->bmiColors
[0].rgbGreen
= 0;
1231 info
->bmiColors
[0].rgbBlue
= 0;
1232 info
->bmiColors
[0].rgbReserved
= 0;
1233 info
->bmiColors
[1].rgbRed
= 0xff;
1234 info
->bmiColors
[1].rgbGreen
= 0xff;
1235 info
->bmiColors
[1].rgbBlue
= 0xff;
1236 info
->bmiColors
[1].rgbReserved
= 0;
1237 if (!(mask
= CreateDIBSection( himl
->hdcMask
, info
, DIB_RGB_COLORS
, &mask_bits
, 0, 0 )))
1239 SelectObject( hdc
, mask
);
1240 BitBlt( hdc
, 0, 0, cx
, cy
, himl
->hdcMask
, src_x
, src_y
, SRCCOPY
);
1241 SelectObject( hdc
, bmp
);
1242 for (i
= 0, ptr
= bits
; i
< cy
; i
++)
1243 for (j
= 0; j
< cx
; j
++, ptr
++)
1244 if ((((BYTE
*)mask_bits
)[i
* width_bytes
+ j
/ 8] << (j
% 8)) & 0x80) *ptr
= 0;
1245 else *ptr
|= 0xff000000;
1248 ret
= GdiAlphaBlend( dest_dc
, dest_x
, dest_y
, cx
, cy
, hdc
, 0, 0, cx
, cy
, func
);
1252 if (bmp
) DeleteObject( bmp
);
1253 if (mask
) DeleteObject( mask
);
1254 HeapFree( GetProcessHeap(), 0, info
);
1258 /*************************************************************************
1259 * ImageList_DrawIndirect [COMCTL32.@]
1261 * Draws an image using various parameters specified in pimldp.
1264 * pimldp [I] pointer to IMAGELISTDRAWPARAMS structure.
1272 ImageList_DrawIndirect (IMAGELISTDRAWPARAMS
*pimldp
)
1274 INT cx
, cy
, nOvlIdx
;
1275 DWORD fState
, dwRop
;
1277 COLORREF oldImageBk
, oldImageFg
;
1278 HDC hImageDC
, hImageListDC
, hMaskListDC
;
1279 HBITMAP hImageBmp
, hOldImageBmp
, hBlendMaskBmp
;
1280 BOOL bIsTransparent
, bBlend
, bResult
= FALSE
, bMask
;
1286 if (!pimldp
|| !(himl
= pimldp
->himl
)) return FALSE
;
1287 if (!is_valid(himl
)) return FALSE
;
1288 if ((pimldp
->i
< 0) || (pimldp
->i
>= himl
->cCurImage
)) return FALSE
;
1290 imagelist_point_from_index( himl
, pimldp
->i
, &pt
);
1291 pt
.x
+= pimldp
->xBitmap
;
1292 pt
.y
+= pimldp
->yBitmap
;
1294 fState
= pimldp
->cbSize
< sizeof(IMAGELISTDRAWPARAMS
) ? ILS_NORMAL
: pimldp
->fState
;
1295 fStyle
= pimldp
->fStyle
& ~ILD_OVERLAYMASK
;
1296 cx
= (pimldp
->cx
== 0) ? himl
->cx
: pimldp
->cx
;
1297 cy
= (pimldp
->cy
== 0) ? himl
->cy
: pimldp
->cy
;
1299 bIsTransparent
= (fStyle
& ILD_TRANSPARENT
);
1300 if( pimldp
->rgbBk
== CLR_NONE
)
1301 bIsTransparent
= TRUE
;
1302 if( ( pimldp
->rgbBk
== CLR_DEFAULT
) && ( himl
->clrBk
== CLR_NONE
) )
1303 bIsTransparent
= TRUE
;
1304 bMask
= (himl
->flags
& ILC_MASK
) && (fStyle
& ILD_MASK
) ;
1305 bBlend
= (fStyle
& (ILD_BLEND25
| ILD_BLEND50
) ) && !bMask
;
1307 TRACE("himl(%p) hbmMask(%p) iImage(%d) x(%d) y(%d) cx(%d) cy(%d)\n",
1308 himl
, himl
->hbmMask
, pimldp
->i
, pimldp
->x
, pimldp
->y
, cx
, cy
);
1310 /* we will use these DCs to access the images and masks in the ImageList */
1311 hImageListDC
= himl
->hdcImage
;
1312 hMaskListDC
= himl
->hdcMask
;
1314 /* these will accumulate the image and mask for the image we're drawing */
1315 hImageDC
= CreateCompatibleDC( pimldp
->hdcDst
);
1316 hImageBmp
= CreateCompatibleBitmap( pimldp
->hdcDst
, cx
, cy
);
1317 hBlendMaskBmp
= bBlend
? CreateBitmap(cx
, cy
, 1, 1, NULL
) : 0;
1319 /* Create a compatible DC. */
1320 if (!hImageListDC
|| !hImageDC
|| !hImageBmp
||
1321 (bBlend
&& !hBlendMaskBmp
) || (himl
->hbmMask
&& !hMaskListDC
))
1324 hOldImageBmp
= SelectObject(hImageDC
, hImageBmp
);
1327 * To obtain a transparent look, background color should be set
1328 * to white and foreground color to black when blitting the
1331 oldImageFg
= SetTextColor( hImageDC
, RGB( 0, 0, 0 ) );
1332 oldImageBk
= SetBkColor( hImageDC
, RGB( 0xff, 0xff, 0xff ) );
1334 has_alpha
= (himl
->has_alpha
&& himl
->has_alpha
[pimldp
->i
]);
1335 if (!bMask
&& (has_alpha
|| (fState
& ILS_ALPHA
)))
1337 COLORREF colour
, blend_col
= CLR_NONE
;
1342 blend_col
= pimldp
->rgbFg
;
1343 if (blend_col
== CLR_DEFAULT
) blend_col
= GetSysColor( COLOR_HIGHLIGHT
);
1344 else if (blend_col
== CLR_NONE
) blend_col
= GetTextColor( pimldp
->hdcDst
);
1347 func
.BlendOp
= AC_SRC_OVER
;
1348 func
.BlendFlags
= 0;
1349 func
.SourceConstantAlpha
= (fState
& ILS_ALPHA
) ? pimldp
->Frame
: 255;
1350 func
.AlphaFormat
= AC_SRC_ALPHA
;
1354 bResult
= alpha_blend_image( himl
, pimldp
->hdcDst
, pimldp
->x
, pimldp
->y
,
1355 pt
.x
, pt
.y
, cx
, cy
, func
, fStyle
, blend_col
);
1358 colour
= pimldp
->rgbBk
;
1359 if (colour
== CLR_DEFAULT
) colour
= himl
->clrBk
;
1360 if (colour
== CLR_NONE
) colour
= GetBkColor( pimldp
->hdcDst
);
1362 hOldBrush
= SelectObject (hImageDC
, CreateSolidBrush (colour
));
1363 PatBlt( hImageDC
, 0, 0, cx
, cy
, PATCOPY
);
1364 alpha_blend_image( himl
, hImageDC
, 0, 0, pt
.x
, pt
.y
, cx
, cy
, func
, fStyle
, blend_col
);
1365 DeleteObject (SelectObject (hImageDC
, hOldBrush
));
1366 bResult
= BitBlt( pimldp
->hdcDst
, pimldp
->x
, pimldp
->y
, cx
, cy
, hImageDC
, 0, 0, SRCCOPY
);
1371 * Draw the initial image
1374 if (himl
->hbmMask
) {
1375 hOldBrush
= SelectObject (hImageDC
, CreateSolidBrush (GetTextColor(pimldp
->hdcDst
)));
1376 PatBlt( hImageDC
, 0, 0, cx
, cy
, PATCOPY
);
1377 BitBlt(hImageDC
, 0, 0, cx
, cy
, hMaskListDC
, pt
.x
, pt
.y
, SRCPAINT
);
1378 DeleteObject (SelectObject (hImageDC
, hOldBrush
));
1379 if( bIsTransparent
)
1381 BitBlt ( pimldp
->hdcDst
, pimldp
->x
, pimldp
->y
, cx
, cy
, hImageDC
, 0, 0, SRCAND
);
1386 hOldBrush
= SelectObject (hImageDC
, GetStockObject(BLACK_BRUSH
));
1387 PatBlt( hImageDC
, 0, 0, cx
, cy
, PATCOPY
);
1388 SelectObject(hImageDC
, hOldBrush
);
1391 /* blend the image with the needed solid background */
1392 COLORREF colour
= RGB(0,0,0);
1394 if( !bIsTransparent
)
1396 colour
= pimldp
->rgbBk
;
1397 if( colour
== CLR_DEFAULT
)
1398 colour
= himl
->clrBk
;
1399 if( colour
== CLR_NONE
)
1400 colour
= GetBkColor(pimldp
->hdcDst
);
1403 hOldBrush
= SelectObject (hImageDC
, CreateSolidBrush (colour
));
1404 PatBlt( hImageDC
, 0, 0, cx
, cy
, PATCOPY
);
1407 BitBlt( hImageDC
, 0, 0, cx
, cy
, hMaskListDC
, pt
.x
, pt
.y
, SRCAND
);
1408 BitBlt( hImageDC
, 0, 0, cx
, cy
, hImageListDC
, pt
.x
, pt
.y
, SRCPAINT
);
1411 BitBlt( hImageDC
, 0, 0, cx
, cy
, hImageListDC
, pt
.x
, pt
.y
, SRCCOPY
);
1412 DeleteObject (SelectObject (hImageDC
, hOldBrush
));
1415 /* Time for blending, if required */
1418 COLORREF clrBlend
= pimldp
->rgbFg
;
1419 HDC hBlendMaskDC
= hImageListDC
;
1422 /* Create the blend Mask */
1423 hOldBitmap
= SelectObject(hBlendMaskDC
, hBlendMaskBmp
);
1424 hBlendBrush
= fStyle
& ILD_BLEND50
? himl
->hbrBlend50
: himl
->hbrBlend25
;
1425 hOldBrush
= SelectObject(hBlendMaskDC
, hBlendBrush
);
1426 PatBlt(hBlendMaskDC
, 0, 0, cx
, cy
, PATCOPY
);
1427 SelectObject(hBlendMaskDC
, hOldBrush
);
1429 /* Modify the blend mask if an Image Mask exist */
1431 BitBlt(hBlendMaskDC
, 0, 0, cx
, cy
, hMaskListDC
, pt
.x
, pt
.y
, 0x220326); /* NOTSRCAND */
1432 BitBlt(hBlendMaskDC
, 0, 0, cx
, cy
, hBlendMaskDC
, 0, 0, NOTSRCCOPY
);
1435 /* now apply blend to the current image given the BlendMask */
1436 if (clrBlend
== CLR_DEFAULT
) clrBlend
= GetSysColor (COLOR_HIGHLIGHT
);
1437 else if (clrBlend
== CLR_NONE
) clrBlend
= GetTextColor (pimldp
->hdcDst
);
1438 hOldBrush
= SelectObject (hImageDC
, CreateSolidBrush(clrBlend
));
1439 BitBlt (hImageDC
, 0, 0, cx
, cy
, hBlendMaskDC
, 0, 0, 0xB8074A); /* PSDPxax */
1440 DeleteObject(SelectObject(hImageDC
, hOldBrush
));
1441 SelectObject(hBlendMaskDC
, hOldBitmap
);
1444 /* Now do the overlay image, if any */
1445 nOvlIdx
= (pimldp
->fStyle
& ILD_OVERLAYMASK
) >> 8;
1446 if ( (nOvlIdx
>= 1) && (nOvlIdx
<= MAX_OVERLAYIMAGE
)) {
1447 nOvlIdx
= himl
->nOvlIdx
[nOvlIdx
- 1];
1448 if ((nOvlIdx
>= 0) && (nOvlIdx
< himl
->cCurImage
)) {
1450 imagelist_point_from_index( himl
, nOvlIdx
, &ptOvl
);
1451 ptOvl
.x
+= pimldp
->xBitmap
;
1452 if (himl
->hbmMask
&& !(fStyle
& ILD_IMAGE
))
1453 BitBlt (hImageDC
, 0, 0, cx
, cy
, hMaskListDC
, ptOvl
.x
, ptOvl
.y
, SRCAND
);
1454 BitBlt (hImageDC
, 0, 0, cx
, cy
, hImageListDC
, ptOvl
.x
, ptOvl
.y
, SRCPAINT
);
1458 if (fState
& ILS_SATURATE
) FIXME("ILS_SATURATE: unimplemented!\n");
1459 if (fState
& ILS_GLOW
) FIXME("ILS_GLOW: unimplemented!\n");
1460 if (fState
& ILS_SHADOW
) FIXME("ILS_SHADOW: unimplemented!\n");
1462 if (fStyle
& ILD_PRESERVEALPHA
) FIXME("ILD_PRESERVEALPHA: unimplemented!\n");
1463 if (fStyle
& ILD_SCALE
) FIXME("ILD_SCALE: unimplemented!\n");
1464 if (fStyle
& ILD_DPISCALE
) FIXME("ILD_DPISCALE: unimplemented!\n");
1466 /* now copy the image to the screen */
1468 if (himl
->hbmMask
&& bIsTransparent
) {
1469 COLORREF oldDstFg
= SetTextColor(pimldp
->hdcDst
, RGB( 0, 0, 0 ) );
1470 COLORREF oldDstBk
= SetBkColor(pimldp
->hdcDst
, RGB( 0xff, 0xff, 0xff ));
1471 BitBlt (pimldp
->hdcDst
, pimldp
->x
, pimldp
->y
, cx
, cy
, hMaskListDC
, pt
.x
, pt
.y
, SRCAND
);
1472 SetBkColor(pimldp
->hdcDst
, oldDstBk
);
1473 SetTextColor(pimldp
->hdcDst
, oldDstFg
);
1476 if (fStyle
& ILD_ROP
) dwRop
= pimldp
->dwRop
;
1477 BitBlt (pimldp
->hdcDst
, pimldp
->x
, pimldp
->y
, cx
, cy
, hImageDC
, 0, 0, dwRop
);
1481 /* cleanup the mess */
1482 SetBkColor(hImageDC
, oldImageBk
);
1483 SetTextColor(hImageDC
, oldImageFg
);
1484 SelectObject(hImageDC
, hOldImageBmp
);
1486 DeleteObject(hBlendMaskBmp
);
1487 DeleteObject(hImageBmp
);
1494 /*************************************************************************
1495 * ImageList_Duplicate [COMCTL32.@]
1497 * Duplicates an image list.
1500 * himlSrc [I] source image list handle
1503 * Success: Handle of duplicated image list.
1508 ImageList_Duplicate (HIMAGELIST himlSrc
)
1512 if (!is_valid(himlSrc
)) {
1513 ERR("Invalid image list handle!\n");
1517 himlDst
= ImageList_Create (himlSrc
->cx
, himlSrc
->cy
, himlSrc
->flags
,
1518 himlSrc
->cCurImage
, himlSrc
->cGrow
);
1524 imagelist_get_bitmap_size(himlSrc
, himlSrc
->cCurImage
, &sz
);
1525 BitBlt (himlDst
->hdcImage
, 0, 0, sz
.cx
, sz
.cy
,
1526 himlSrc
->hdcImage
, 0, 0, SRCCOPY
);
1528 if (himlDst
->hbmMask
)
1529 BitBlt (himlDst
->hdcMask
, 0, 0, sz
.cx
, sz
.cy
,
1530 himlSrc
->hdcMask
, 0, 0, SRCCOPY
);
1532 himlDst
->cCurImage
= himlSrc
->cCurImage
;
1533 if (himlSrc
->has_alpha
&& himlDst
->has_alpha
)
1534 memcpy( himlDst
->has_alpha
, himlSrc
->has_alpha
, himlDst
->cCurImage
);
1540 /*************************************************************************
1541 * ImageList_EndDrag [COMCTL32.@]
1543 * Finishes a drag operation.
1554 ImageList_EndDrag (void)
1556 /* cleanup the InternalDrag struct */
1557 InternalDrag
.hwnd
= 0;
1558 ImageList_Destroy (InternalDrag
.himl
);
1559 InternalDrag
.himl
= 0;
1562 InternalDrag
.dxHotspot
= 0;
1563 InternalDrag
.dyHotspot
= 0;
1564 InternalDrag
.bShow
= FALSE
;
1565 DeleteObject(InternalDrag
.hbmBg
);
1566 InternalDrag
.hbmBg
= 0;
1570 /*************************************************************************
1571 * ImageList_GetBkColor [COMCTL32.@]
1573 * Returns the background color of an image list.
1576 * himl [I] Image list handle.
1579 * Success: background color
1584 ImageList_GetBkColor (HIMAGELIST himl
)
1586 return himl
? himl
->clrBk
: CLR_NONE
;
1590 /*************************************************************************
1591 * ImageList_GetDragImage [COMCTL32.@]
1593 * Returns the handle to the internal drag image list.
1596 * ppt [O] Pointer to the drag position. Can be NULL.
1597 * pptHotspot [O] Pointer to the position of the hot spot. Can be NULL.
1600 * Success: Handle of the drag image list.
1605 ImageList_GetDragImage (POINT
*ppt
, POINT
*pptHotspot
)
1607 if (is_valid(InternalDrag
.himl
)) {
1609 ppt
->x
= InternalDrag
.x
;
1610 ppt
->y
= InternalDrag
.y
;
1613 pptHotspot
->x
= InternalDrag
.dxHotspot
;
1614 pptHotspot
->y
= InternalDrag
.dyHotspot
;
1616 return (InternalDrag
.himl
);
1623 /*************************************************************************
1624 * ImageList_GetFlags [COMCTL32.@]
1626 * Gets the flags of the specified image list.
1629 * himl [I] Handle to image list
1639 ImageList_GetFlags(HIMAGELIST himl
)
1641 TRACE("%p\n", himl
);
1643 return is_valid(himl
) ? himl
->flags
: 0;
1647 /*************************************************************************
1648 * ImageList_GetIcon [COMCTL32.@]
1650 * Creates an icon from a masked image of an image list.
1653 * himl [I] handle to image list
1655 * flags [I] drawing style flags
1658 * Success: icon handle
1663 ImageList_GetIcon (HIMAGELIST himl
, INT i
, UINT fStyle
)
1667 HBITMAP hOldDstBitmap
;
1671 TRACE("%p %d %d\n", himl
, i
, fStyle
);
1672 if (!is_valid(himl
) || (i
< 0) || (i
>= himl
->cCurImage
)) return NULL
;
1678 /* create colour bitmap */
1680 ii
.hbmColor
= CreateCompatibleBitmap(hdcDst
, himl
->cx
, himl
->cy
);
1681 ReleaseDC(0, hdcDst
);
1683 hdcDst
= CreateCompatibleDC(0);
1685 imagelist_point_from_index( himl
, i
, &pt
);
1688 ii
.hbmMask
= CreateBitmap (himl
->cx
, himl
->cy
, 1, 1, NULL
);
1689 hOldDstBitmap
= SelectObject (hdcDst
, ii
.hbmMask
);
1690 if (himl
->hbmMask
) {
1691 BitBlt (hdcDst
, 0, 0, himl
->cx
, himl
->cy
,
1692 himl
->hdcMask
, pt
.x
, pt
.y
, SRCCOPY
);
1695 PatBlt (hdcDst
, 0, 0, himl
->cx
, himl
->cy
, BLACKNESS
);
1698 SelectObject (hdcDst
, ii
.hbmColor
);
1699 BitBlt (hdcDst
, 0, 0, himl
->cx
, himl
->cy
,
1700 himl
->hdcImage
, pt
.x
, pt
.y
, SRCCOPY
);
1703 * CreateIconIndirect requires us to deselect the bitmaps from
1704 * the DCs before calling
1706 SelectObject(hdcDst
, hOldDstBitmap
);
1708 hIcon
= CreateIconIndirect (&ii
);
1710 DeleteObject (ii
.hbmMask
);
1711 DeleteObject (ii
.hbmColor
);
1718 /*************************************************************************
1719 * ImageList_GetIconSize [COMCTL32.@]
1721 * Retrieves the size of an image in an image list.
1724 * himl [I] handle to image list
1725 * cx [O] pointer to the image width.
1726 * cy [O] pointer to the image height.
1733 * All images in an image list have the same size.
1737 ImageList_GetIconSize (HIMAGELIST himl
, INT
*cx
, INT
*cy
)
1739 if (!is_valid(himl
) || !cx
|| !cy
)
1741 if ((himl
->cx
<= 0) || (himl
->cy
<= 0))
1751 /*************************************************************************
1752 * ImageList_GetImageCount [COMCTL32.@]
1754 * Returns the number of images in an image list.
1757 * himl [I] handle to image list
1760 * Success: Number of images.
1765 ImageList_GetImageCount (HIMAGELIST himl
)
1767 if (!is_valid(himl
))
1770 return himl
->cCurImage
;
1774 /*************************************************************************
1775 * ImageList_GetImageInfo [COMCTL32.@]
1777 * Returns information about an image in an image list.
1780 * himl [I] handle to image list
1782 * pImageInfo [O] pointer to the image information
1790 ImageList_GetImageInfo (HIMAGELIST himl
, INT i
, IMAGEINFO
*pImageInfo
)
1794 if (!is_valid(himl
) || (pImageInfo
== NULL
))
1796 if ((i
< 0) || (i
>= himl
->cCurImage
))
1799 pImageInfo
->hbmImage
= himl
->hbmImage
;
1800 pImageInfo
->hbmMask
= himl
->hbmMask
;
1802 imagelist_point_from_index( himl
, i
, &pt
);
1803 pImageInfo
->rcImage
.top
= pt
.y
;
1804 pImageInfo
->rcImage
.bottom
= pt
.y
+ himl
->cy
;
1805 pImageInfo
->rcImage
.left
= pt
.x
;
1806 pImageInfo
->rcImage
.right
= pt
.x
+ himl
->cx
;
1812 /*************************************************************************
1813 * ImageList_GetImageRect [COMCTL32.@]
1815 * Retrieves the rectangle of the specified image in an image list.
1818 * himl [I] handle to image list
1820 * lpRect [O] pointer to the image rectangle
1827 * This is an UNDOCUMENTED function!!!
1831 ImageList_GetImageRect (HIMAGELIST himl
, INT i
, LPRECT lpRect
)
1835 if (!is_valid(himl
) || (lpRect
== NULL
))
1837 if ((i
< 0) || (i
>= himl
->cCurImage
))
1840 imagelist_point_from_index( himl
, i
, &pt
);
1841 lpRect
->left
= pt
.x
;
1843 lpRect
->right
= pt
.x
+ himl
->cx
;
1844 lpRect
->bottom
= pt
.y
+ himl
->cy
;
1850 /*************************************************************************
1851 * ImageList_LoadImage [COMCTL32.@]
1852 * ImageList_LoadImageA [COMCTL32.@]
1854 * Creates an image list from a bitmap, icon or cursor.
1856 * See ImageList_LoadImageW.
1860 ImageList_LoadImageA (HINSTANCE hi
, LPCSTR lpbmp
, INT cx
, INT cGrow
,
1861 COLORREF clrMask
, UINT uType
, UINT uFlags
)
1867 if (IS_INTRESOURCE(lpbmp
))
1868 return ImageList_LoadImageW(hi
, (LPCWSTR
)lpbmp
, cx
, cGrow
, clrMask
,
1871 len
= MultiByteToWideChar(CP_ACP
, 0, lpbmp
, -1, NULL
, 0);
1872 lpbmpW
= Alloc(len
* sizeof(WCHAR
));
1873 MultiByteToWideChar(CP_ACP
, 0, lpbmp
, -1, lpbmpW
, len
);
1875 himl
= ImageList_LoadImageW(hi
, lpbmpW
, cx
, cGrow
, clrMask
, uType
, uFlags
);
1881 /*************************************************************************
1882 * ImageList_LoadImageW [COMCTL32.@]
1884 * Creates an image list from a bitmap, icon or cursor.
1887 * hi [I] instance handle
1888 * lpbmp [I] name or id of the image
1889 * cx [I] width of each image
1890 * cGrow [I] number of images to expand
1891 * clrMask [I] mask color
1892 * uType [I] type of image to load
1893 * uFlags [I] loading flags
1896 * Success: handle to the loaded image list
1904 ImageList_LoadImageW (HINSTANCE hi
, LPCWSTR lpbmp
, INT cx
, INT cGrow
,
1905 COLORREF clrMask
, UINT uType
, UINT uFlags
)
1907 HIMAGELIST himl
= NULL
;
1911 handle
= LoadImageW (hi
, lpbmp
, uType
, 0, 0, uFlags
);
1913 WARN("Couldn't load image\n");
1917 if (uType
== IMAGE_BITMAP
) {
1921 if (GetObjectW (handle
, sizeof(dib
), &dib
) == sizeof(BITMAP
)) color
= ILC_COLOR
;
1922 else color
= dib
.dsBm
.bmBitsPixel
;
1924 /* To match windows behavior, if cx is set to zero and
1925 the flag DI_DEFAULTSIZE is specified, cx becomes the
1926 system metric value for icons. If the flag is not specified
1927 the function sets the size to the height of the bitmap */
1930 if (uFlags
& DI_DEFAULTSIZE
)
1931 cx
= GetSystemMetrics (SM_CXICON
);
1933 cx
= dib
.dsBm
.bmHeight
;
1936 nImageCount
= dib
.dsBm
.bmWidth
/ cx
;
1938 himl
= ImageList_Create (cx
, dib
.dsBm
.bmHeight
, ILC_MASK
| color
, nImageCount
, cGrow
);
1940 DeleteObject (handle
);
1943 ImageList_AddMasked (himl
, handle
, clrMask
);
1945 else if ((uType
== IMAGE_ICON
) || (uType
== IMAGE_CURSOR
)) {
1949 GetIconInfo (handle
, &ii
);
1950 GetObjectW (ii
.hbmColor
, sizeof(BITMAP
), &bmp
);
1951 himl
= ImageList_Create (bmp
.bmWidth
, bmp
.bmHeight
,
1952 ILC_MASK
| ILC_COLOR
, 1, cGrow
);
1954 DeleteObject (ii
.hbmColor
);
1955 DeleteObject (ii
.hbmMask
);
1956 DeleteObject (handle
);
1959 ImageList_Add (himl
, ii
.hbmColor
, ii
.hbmMask
);
1960 DeleteObject (ii
.hbmColor
);
1961 DeleteObject (ii
.hbmMask
);
1964 DeleteObject (handle
);
1970 /*************************************************************************
1971 * ImageList_Merge [COMCTL32.@]
1973 * Create an image list containing a merged image from two image lists.
1976 * himl1 [I] handle to first image list
1977 * i1 [I] first image index
1978 * himl2 [I] handle to second image list
1979 * i2 [I] second image index
1980 * dx [I] X offset of the second image relative to the first.
1981 * dy [I] Y offset of the second image relative to the first.
1984 * Success: The newly created image list. It contains a single image
1985 * consisting of the second image merged with the first.
1986 * Failure: NULL, if either himl1 or himl2 are invalid.
1989 * - The returned image list should be deleted by the caller using
1990 * ImageList_Destroy() when it is no longer required.
1991 * - If either i1 or i2 are not valid image indices they will be treated
1995 ImageList_Merge (HIMAGELIST himl1
, INT i1
, HIMAGELIST himl2
, INT i2
,
1998 HIMAGELIST himlDst
= NULL
;
2000 INT xOff1
, yOff1
, xOff2
, yOff2
;
2003 TRACE("(himl1=%p i1=%d himl2=%p i2=%d dx=%d dy=%d)\n", himl1
, i1
, himl2
,
2006 if (!is_valid(himl1
) || !is_valid(himl2
))
2010 cxDst
= max (himl1
->cx
, dx
+ himl2
->cx
);
2015 cxDst
= max (himl2
->cx
, himl1
->cx
- dx
);
2020 cxDst
= max (himl1
->cx
, himl2
->cx
);
2026 cyDst
= max (himl1
->cy
, dy
+ himl2
->cy
);
2031 cyDst
= max (himl2
->cy
, himl1
->cy
- dy
);
2036 cyDst
= max (himl1
->cy
, himl2
->cy
);
2041 himlDst
= ImageList_Create (cxDst
, cyDst
, ILC_MASK
| ILC_COLOR
, 1, 1);
2045 imagelist_point_from_index( himl1
, i1
, &pt1
);
2046 imagelist_point_from_index( himl2
, i2
, &pt2
);
2049 BitBlt (himlDst
->hdcImage
, 0, 0, cxDst
, cyDst
, himl1
->hdcImage
, 0, 0, BLACKNESS
);
2050 if (i1
>= 0 && i1
< himl1
->cCurImage
)
2051 BitBlt (himlDst
->hdcImage
, xOff1
, yOff1
, himl1
->cx
, himl1
->cy
, himl1
->hdcImage
, pt1
.x
, pt1
.y
, SRCCOPY
);
2052 if (i2
>= 0 && i2
< himl2
->cCurImage
)
2054 BitBlt (himlDst
->hdcImage
, xOff2
, yOff2
, himl2
->cx
, himl2
->cy
, himl2
->hdcMask
, pt2
.x
, pt2
.y
, SRCAND
);
2055 BitBlt (himlDst
->hdcImage
, xOff2
, yOff2
, himl2
->cx
, himl2
->cy
, himl2
->hdcImage
, pt2
.x
, pt2
.y
, SRCPAINT
);
2059 BitBlt (himlDst
->hdcMask
, 0, 0, cxDst
, cyDst
, himl1
->hdcMask
, 0, 0, WHITENESS
);
2060 if (i1
>= 0 && i1
< himl1
->cCurImage
)
2061 BitBlt (himlDst
->hdcMask
, xOff1
, yOff1
, himl1
->cx
, himl1
->cy
, himl1
->hdcMask
, pt1
.x
, pt1
.y
, SRCCOPY
);
2062 if (i2
>= 0 && i2
< himl2
->cCurImage
)
2063 BitBlt (himlDst
->hdcMask
, xOff2
, yOff2
, himl2
->cx
, himl2
->cy
, himl2
->hdcMask
, pt2
.x
, pt2
.y
, SRCAND
);
2065 himlDst
->cCurImage
= 1;
2072 /***********************************************************************
2073 * DIB_GetDIBImageBytes
2075 * Return the number of bytes used to hold the image in a DIB bitmap.
2077 static int DIB_GetDIBImageBytes( int width
, int height
, int depth
)
2079 return (((width
* depth
+ 31) / 8) & ~3) * abs( height
);
2083 /* helper for ImageList_Read, see comments below */
2084 static BOOL
_read_bitmap(HDC hdcIml
, LPSTREAM pstm
)
2086 BITMAPFILEHEADER bmfh
;
2087 int bitsperpixel
, palspace
;
2088 char bmi_buf
[sizeof(BITMAPINFOHEADER
) + sizeof(RGBQUAD
) * 256];
2089 LPBITMAPINFO bmi
= (LPBITMAPINFO
)bmi_buf
;
2093 if (FAILED(IStream_Read ( pstm
, &bmfh
, sizeof(bmfh
), NULL
)))
2096 if (bmfh
.bfType
!= (('M'<<8)|'B'))
2099 if (FAILED(IStream_Read ( pstm
, &bmi
->bmiHeader
, sizeof(bmi
->bmiHeader
), NULL
)))
2102 if ((bmi
->bmiHeader
.biSize
!= sizeof(bmi
->bmiHeader
)))
2105 TRACE("width %u, height %u, planes %u, bpp %u\n",
2106 bmi
->bmiHeader
.biWidth
, bmi
->bmiHeader
.biHeight
,
2107 bmi
->bmiHeader
.biPlanes
, bmi
->bmiHeader
.biBitCount
);
2109 bitsperpixel
= bmi
->bmiHeader
.biPlanes
* bmi
->bmiHeader
.biBitCount
;
2110 if (bitsperpixel
<=8)
2111 palspace
= (1<<bitsperpixel
)*sizeof(RGBQUAD
);
2115 bmi
->bmiHeader
.biSizeImage
= DIB_GetDIBImageBytes(bmi
->bmiHeader
.biWidth
, bmi
->bmiHeader
.biHeight
, bitsperpixel
);
2117 /* read the palette right after the end of the bitmapinfoheader */
2118 if (palspace
&& FAILED(IStream_Read(pstm
, bmi
->bmiColors
, palspace
, NULL
)))
2121 bits
= Alloc(bmi
->bmiHeader
.biSizeImage
);
2124 if (FAILED(IStream_Read(pstm
, bits
, bmi
->bmiHeader
.biSizeImage
, NULL
)))
2127 if (!StretchDIBits(hdcIml
, 0, 0, bmi
->bmiHeader
.biWidth
, bmi
->bmiHeader
.biHeight
,
2128 0, 0, bmi
->bmiHeader
.biWidth
, bmi
->bmiHeader
.biHeight
,
2129 bits
, bmi
, DIB_RGB_COLORS
, SRCCOPY
))
2138 /*************************************************************************
2139 * ImageList_Read [COMCTL32.@]
2141 * Reads an image list from a stream.
2144 * pstm [I] pointer to a stream
2147 * Success: handle to image list
2150 * The format is like this:
2151 * ILHEAD ilheadstruct;
2153 * for the color image part:
2154 * BITMAPFILEHEADER bmfh;
2155 * BITMAPINFOHEADER bmih;
2156 * only if it has a palette:
2157 * RGBQUAD rgbs[nr_of_paletted_colors];
2159 * BYTE colorbits[imagesize];
2161 * the following only if the ILC_MASK bit is set in ILHEAD.ilFlags:
2162 * BITMAPFILEHEADER bmfh_mask;
2163 * BITMAPINFOHEADER bmih_mask;
2164 * only if it has a palette (it usually does not):
2165 * RGBQUAD rgbs[nr_of_paletted_colors];
2167 * BYTE maskbits[imagesize];
2169 HIMAGELIST WINAPI
ImageList_Read (LPSTREAM pstm
)
2175 TRACE("%p\n", pstm
);
2177 if (FAILED(IStream_Read (pstm
, &ilHead
, sizeof(ILHEAD
), NULL
)))
2179 if (ilHead
.usMagic
!= (('L' << 8) | 'I'))
2181 if (ilHead
.usVersion
!= 0x101) /* probably version? */
2184 TRACE("cx %u, cy %u, flags 0x%04x, cCurImage %u, cMaxImage %u\n",
2185 ilHead
.cx
, ilHead
.cy
, ilHead
.flags
, ilHead
.cCurImage
, ilHead
.cMaxImage
);
2187 himl
= ImageList_Create(ilHead
.cx
, ilHead
.cy
, ilHead
.flags
, ilHead
.cCurImage
, ilHead
.cMaxImage
);
2191 if (!_read_bitmap(himl
->hdcImage
, pstm
))
2193 WARN("failed to read bitmap from stream\n");
2196 if (ilHead
.flags
& ILC_MASK
)
2198 if (!_read_bitmap(himl
->hdcMask
, pstm
))
2200 WARN("failed to read mask bitmap from stream\n");
2205 himl
->cCurImage
= ilHead
.cCurImage
;
2206 himl
->cMaxImage
= ilHead
.cMaxImage
;
2208 ImageList_SetBkColor(himl
,ilHead
.bkcolor
);
2210 ImageList_SetOverlayImage(himl
,ilHead
.ovls
[i
],i
+1);
2215 /*************************************************************************
2216 * ImageList_Remove [COMCTL32.@]
2218 * Removes an image from an image list
2221 * himl [I] image list handle
2228 * FIXME: as the image list storage test shows, native comctl32 simply shifts
2229 * images without creating a new bitmap.
2232 ImageList_Remove (HIMAGELIST himl
, INT i
)
2234 HBITMAP hbmNewImage
, hbmNewMask
;
2238 TRACE("(himl=%p i=%d)\n", himl
, i
);
2240 if (!is_valid(himl
)) {
2241 ERR("Invalid image list handle!\n");
2245 if ((i
< -1) || (i
>= himl
->cCurImage
)) {
2246 TRACE("index out of range! %d\n", i
);
2254 if (himl
->cCurImage
== 0) {
2255 /* remove all on empty ImageList is allowed */
2256 TRACE("remove all on empty ImageList!\n");
2260 himl
->cMaxImage
= himl
->cInitial
+ himl
->cGrow
- 1;
2261 himl
->cCurImage
= 0;
2262 for (nCount
= 0; nCount
< MAX_OVERLAYIMAGE
; nCount
++)
2263 himl
->nOvlIdx
[nCount
] = -1;
2265 hbmNewImage
= ImageList_CreateImage(himl
->hdcImage
, himl
, himl
->cMaxImage
);
2266 SelectObject (himl
->hdcImage
, hbmNewImage
);
2267 DeleteObject (himl
->hbmImage
);
2268 himl
->hbmImage
= hbmNewImage
;
2270 if (himl
->hbmMask
) {
2272 imagelist_get_bitmap_size(himl
, himl
->cMaxImage
, &sz
);
2273 hbmNewMask
= CreateBitmap (sz
.cx
, sz
.cy
, 1, 1, NULL
);
2274 SelectObject (himl
->hdcMask
, hbmNewMask
);
2275 DeleteObject (himl
->hbmMask
);
2276 himl
->hbmMask
= hbmNewMask
;
2280 /* delete one image */
2281 TRACE("Remove single image! %d\n", i
);
2283 /* create new bitmap(s) */
2284 TRACE(" - Number of images: %d / %d (Old/New)\n",
2285 himl
->cCurImage
, himl
->cCurImage
- 1);
2287 hbmNewImage
= ImageList_CreateImage(himl
->hdcImage
, himl
, himl
->cMaxImage
);
2289 imagelist_get_bitmap_size(himl
, himl
->cMaxImage
, &sz
);
2291 hbmNewMask
= CreateBitmap (sz
.cx
, sz
.cy
, 1, 1, NULL
);
2293 hbmNewMask
= 0; /* Just to keep compiler happy! */
2295 hdcBmp
= CreateCompatibleDC (0);
2297 /* copy all images and masks prior to the "removed" image */
2299 TRACE("Pre image copy: Copy %d images\n", i
);
2301 SelectObject (hdcBmp
, hbmNewImage
);
2302 imagelist_copy_images( himl
, himl
->hdcImage
, hdcBmp
, 0, i
, 0 );
2304 if (himl
->hbmMask
) {
2305 SelectObject (hdcBmp
, hbmNewMask
);
2306 imagelist_copy_images( himl
, himl
->hdcMask
, hdcBmp
, 0, i
, 0 );
2310 /* copy all images and masks behind the removed image */
2311 if (i
< himl
->cCurImage
- 1) {
2312 TRACE("Post image copy!\n");
2314 SelectObject (hdcBmp
, hbmNewImage
);
2315 imagelist_copy_images( himl
, himl
->hdcImage
, hdcBmp
, i
+ 1,
2316 (himl
->cCurImage
- i
), i
);
2318 if (himl
->hbmMask
) {
2319 SelectObject (hdcBmp
, hbmNewMask
);
2320 imagelist_copy_images( himl
, himl
->hdcMask
, hdcBmp
, i
+ 1,
2321 (himl
->cCurImage
- i
), i
);
2327 /* delete old images and insert new ones */
2328 SelectObject (himl
->hdcImage
, hbmNewImage
);
2329 DeleteObject (himl
->hbmImage
);
2330 himl
->hbmImage
= hbmNewImage
;
2331 if (himl
->hbmMask
) {
2332 SelectObject (himl
->hdcMask
, hbmNewMask
);
2333 DeleteObject (himl
->hbmMask
);
2334 himl
->hbmMask
= hbmNewMask
;
2344 /*************************************************************************
2345 * ImageList_Replace [COMCTL32.@]
2347 * Replaces an image in an image list with a new image.
2350 * himl [I] handle to image list
2352 * hbmImage [I] handle to image bitmap
2353 * hbmMask [I] handle to mask bitmap. Can be NULL.
2361 ImageList_Replace (HIMAGELIST himl
, INT i
, HBITMAP hbmImage
,
2368 TRACE("%p %d %p %p\n", himl
, i
, hbmImage
, hbmMask
);
2370 if (!is_valid(himl
)) {
2371 ERR("Invalid image list handle!\n");
2375 if ((i
>= himl
->cMaxImage
) || (i
< 0)) {
2376 ERR("Invalid image index!\n");
2380 if (!GetObjectW(hbmImage
, sizeof(BITMAP
), &bmp
))
2383 hdcImage
= CreateCompatibleDC (0);
2386 SelectObject (hdcImage
, hbmImage
);
2388 if (add_with_alpha( himl
, hdcImage
, i
, 1, bmp
.bmWidth
, bmp
.bmHeight
, hbmImage
, hbmMask
))
2391 imagelist_point_from_index(himl
, i
, &pt
);
2392 StretchBlt (himl
->hdcImage
, pt
.x
, pt
.y
, himl
->cx
, himl
->cy
,
2393 hdcImage
, 0, 0, bmp
.bmWidth
, bmp
.bmHeight
, SRCCOPY
);
2398 HBITMAP hOldBitmapTemp
;
2400 hdcTemp
= CreateCompatibleDC(0);
2401 hOldBitmapTemp
= SelectObject(hdcTemp
, hbmMask
);
2403 StretchBlt (himl
->hdcMask
, pt
.x
, pt
.y
, himl
->cx
, himl
->cy
,
2404 hdcTemp
, 0, 0, bmp
.bmWidth
, bmp
.bmHeight
, SRCCOPY
);
2405 SelectObject(hdcTemp
, hOldBitmapTemp
);
2408 /* Remove the background from the image
2410 BitBlt (himl
->hdcImage
, pt
.x
, pt
.y
, bmp
.bmWidth
, bmp
.bmHeight
,
2411 himl
->hdcMask
, pt
.x
, pt
.y
, 0x220326); /* NOTSRCAND */
2415 DeleteDC (hdcImage
);
2421 /*************************************************************************
2422 * ImageList_ReplaceIcon [COMCTL32.@]
2424 * Replaces an image in an image list using an icon.
2427 * himl [I] handle to image list
2429 * hIcon [I] handle to icon
2432 * Success: index of the replaced image
2437 ImageList_ReplaceIcon (HIMAGELIST himl
, INT nIndex
, HICON hIcon
)
2446 TRACE("(%p %d %p)\n", himl
, nIndex
, hIcon
);
2448 if (!is_valid(himl
)) {
2449 ERR("invalid image list\n");
2452 if ((nIndex
>= himl
->cMaxImage
) || (nIndex
< -1)) {
2453 ERR("invalid image index %d / %d\n", nIndex
, himl
->cMaxImage
);
2457 hBestFitIcon
= CopyImage(
2460 LR_COPYFROMRESOURCE
);
2461 /* the above will fail if the icon wasn't loaded from a resource, so try
2462 * again without LR_COPYFROMRESOURCE flag */
2464 hBestFitIcon
= CopyImage(
2471 ret
= GetIconInfo (hBestFitIcon
, &ii
);
2473 DestroyIcon(hBestFitIcon
);
2477 ret
= GetObjectW (ii
.hbmMask
, sizeof(BITMAP
), &bmp
);
2479 ERR("couldn't get mask bitmap info\n");
2481 DeleteObject (ii
.hbmColor
);
2483 DeleteObject (ii
.hbmMask
);
2484 DestroyIcon(hBestFitIcon
);
2489 if (himl
->cCurImage
+ 1 > himl
->cMaxImage
)
2490 IMAGELIST_InternalExpandBitmaps(himl
, 1);
2492 nIndex
= himl
->cCurImage
;
2496 hdcImage
= CreateCompatibleDC (0);
2497 TRACE("hdcImage=%p\n", hdcImage
);
2499 ERR("invalid hdcImage!\n");
2501 if (himl
->has_alpha
)
2505 UINT height
= bmp
.bmHeight
/ 2;
2506 HDC hdcMask
= CreateCompatibleDC( 0 );
2507 HBITMAP color
= CreateBitmap( bmp
.bmWidth
, height
, 1, 1, NULL
);
2508 SelectObject( hdcImage
, color
);
2509 SelectObject( hdcMask
, ii
.hbmMask
);
2510 BitBlt( hdcImage
, 0, 0, bmp
.bmWidth
, height
, hdcMask
, 0, height
, SRCCOPY
);
2511 ret
= add_with_alpha( himl
, hdcImage
, nIndex
, 1, bmp
.bmWidth
, height
, color
, ii
.hbmMask
);
2512 DeleteDC( hdcMask
);
2513 DeleteObject( color
);
2516 else if (add_with_alpha( himl
, hdcImage
, nIndex
, 1, bmp
.bmWidth
, bmp
.bmHeight
,
2517 ii
.hbmColor
, ii
.hbmMask
)) goto done
;
2520 imagelist_point_from_index(himl
, nIndex
, &pt
);
2522 SetTextColor(himl
->hdcImage
, RGB(0,0,0));
2523 SetBkColor (himl
->hdcImage
, RGB(255,255,255));
2527 SelectObject (hdcImage
, ii
.hbmColor
);
2528 StretchBlt (himl
->hdcImage
, pt
.x
, pt
.y
, himl
->cx
, himl
->cy
,
2529 hdcImage
, 0, 0, bmp
.bmWidth
, bmp
.bmHeight
, SRCCOPY
);
2532 SelectObject (hdcImage
, ii
.hbmMask
);
2533 StretchBlt (himl
->hdcMask
, pt
.x
, pt
.y
, himl
->cx
, himl
->cy
,
2534 hdcImage
, 0, 0, bmp
.bmWidth
, bmp
.bmHeight
, SRCCOPY
);
2539 UINT height
= bmp
.bmHeight
/ 2;
2540 SelectObject (hdcImage
, ii
.hbmMask
);
2541 StretchBlt (himl
->hdcImage
, pt
.x
, pt
.y
, himl
->cx
, himl
->cy
,
2542 hdcImage
, 0, height
, bmp
.bmWidth
, height
, SRCCOPY
);
2544 StretchBlt (himl
->hdcMask
, pt
.x
, pt
.y
, himl
->cx
, himl
->cy
,
2545 hdcImage
, 0, 0, bmp
.bmWidth
, height
, SRCCOPY
);
2549 DestroyIcon(hBestFitIcon
);
2551 DeleteDC (hdcImage
);
2553 DeleteObject (ii
.hbmColor
);
2555 DeleteObject (ii
.hbmMask
);
2557 TRACE("Insert index = %d, himl->cCurImage = %d\n", nIndex
, himl
->cCurImage
);
2562 /*************************************************************************
2563 * ImageList_SetBkColor [COMCTL32.@]
2565 * Sets the background color of an image list.
2568 * himl [I] handle to image list
2569 * clrBk [I] background color
2572 * Success: previous background color
2577 ImageList_SetBkColor (HIMAGELIST himl
, COLORREF clrBk
)
2581 if (!is_valid(himl
))
2584 clrOldBk
= himl
->clrBk
;
2585 himl
->clrBk
= clrBk
;
2590 /*************************************************************************
2591 * ImageList_SetDragCursorImage [COMCTL32.@]
2593 * Combines the specified image with the current drag image
2596 * himlDrag [I] handle to drag image list
2597 * iDrag [I] drag image index
2598 * dxHotspot [I] X position of the hot spot
2599 * dyHotspot [I] Y position of the hot spot
2606 * - The names dxHotspot, dyHotspot are misleading because they have nothing
2607 * to do with a hotspot but are only the offset of the origin of the new
2608 * image relative to the origin of the old image.
2610 * - When this function is called and the drag image is visible, a
2611 * short flickering occurs but this matches the Win9x behavior. It is
2612 * possible to fix the flickering using code like in ImageList_DragMove.
2616 ImageList_SetDragCursorImage (HIMAGELIST himlDrag
, INT iDrag
,
2617 INT dxHotspot
, INT dyHotspot
)
2619 HIMAGELIST himlTemp
;
2622 if (!is_valid(InternalDrag
.himl
) || !is_valid(himlDrag
))
2625 TRACE(" dxH=%d dyH=%d nX=%d nY=%d\n",
2626 dxHotspot
, dyHotspot
, InternalDrag
.dxHotspot
, InternalDrag
.dyHotspot
);
2628 visible
= InternalDrag
.bShow
;
2630 himlTemp
= ImageList_Merge (InternalDrag
.himl
, 0, himlDrag
, iDrag
,
2631 dxHotspot
, dyHotspot
);
2634 /* hide the drag image */
2635 ImageList_DragShowNolock(FALSE
);
2637 if ((InternalDrag
.himl
->cx
!= himlTemp
->cx
) ||
2638 (InternalDrag
.himl
->cy
!= himlTemp
->cy
)) {
2639 /* the size of the drag image changed, invalidate the buffer */
2640 DeleteObject(InternalDrag
.hbmBg
);
2641 InternalDrag
.hbmBg
= 0;
2644 ImageList_Destroy (InternalDrag
.himl
);
2645 InternalDrag
.himl
= himlTemp
;
2648 /* show the drag image */
2649 ImageList_DragShowNolock(TRUE
);
2656 /*************************************************************************
2657 * ImageList_SetFilter [COMCTL32.@]
2659 * Sets a filter (or does something completely different)!!???
2660 * It removes 12 Bytes from the stack (3 Parameters).
2663 * himl [I] SHOULD be a handle to image list
2664 * i [I] COULD be an index?
2669 * Failure: FALSE ???
2672 * This is an UNDOCUMENTED function!!!!
2677 ImageList_SetFilter (HIMAGELIST himl
, INT i
, DWORD dwFilter
)
2679 FIXME("(%p 0x%x 0x%x):empty stub!\n", himl
, i
, dwFilter
);
2685 /*************************************************************************
2686 * ImageList_SetFlags [COMCTL32.@]
2688 * Sets the image list flags.
2691 * himl [I] Handle to image list
2692 * flags [I] Flags to set
2702 ImageList_SetFlags(HIMAGELIST himl
, DWORD flags
)
2704 FIXME("(%p %08x):empty stub\n", himl
, flags
);
2709 /*************************************************************************
2710 * ImageList_SetIconSize [COMCTL32.@]
2712 * Sets the image size of the bitmap and deletes all images.
2715 * himl [I] handle to image list
2716 * cx [I] image width
2717 * cy [I] image height
2725 ImageList_SetIconSize (HIMAGELIST himl
, INT cx
, INT cy
)
2730 if (!is_valid(himl
))
2733 /* remove all images */
2734 himl
->cMaxImage
= himl
->cInitial
+ 1;
2735 himl
->cCurImage
= 0;
2739 /* initialize overlay mask indices */
2740 for (nCount
= 0; nCount
< MAX_OVERLAYIMAGE
; nCount
++)
2741 himl
->nOvlIdx
[nCount
] = -1;
2743 hbmNew
= ImageList_CreateImage(himl
->hdcImage
, himl
, himl
->cMaxImage
);
2744 SelectObject (himl
->hdcImage
, hbmNew
);
2745 DeleteObject (himl
->hbmImage
);
2746 himl
->hbmImage
= hbmNew
;
2748 if (himl
->hbmMask
) {
2750 imagelist_get_bitmap_size(himl
, himl
->cMaxImage
, &sz
);
2751 hbmNew
= CreateBitmap (sz
.cx
, sz
.cy
, 1, 1, NULL
);
2752 SelectObject (himl
->hdcMask
, hbmNew
);
2753 DeleteObject (himl
->hbmMask
);
2754 himl
->hbmMask
= hbmNew
;
2761 /*************************************************************************
2762 * ImageList_SetImageCount [COMCTL32.@]
2764 * Resizes an image list to the specified number of images.
2767 * himl [I] handle to image list
2768 * iImageCount [I] number of images in the image list
2776 ImageList_SetImageCount (HIMAGELIST himl
, UINT iImageCount
)
2779 HBITMAP hbmNewBitmap
, hbmOld
;
2780 INT nNewCount
, nCopyCount
;
2782 TRACE("%p %d\n",himl
,iImageCount
);
2784 if (!is_valid(himl
))
2786 if (himl
->cMaxImage
> iImageCount
)
2788 himl
->cCurImage
= iImageCount
;
2789 /* TODO: shrink the bitmap when cMaxImage-cCurImage>cGrow ? */
2793 nNewCount
= iImageCount
+ himl
->cGrow
;
2794 nCopyCount
= min(himl
->cCurImage
, iImageCount
);
2796 hdcBitmap
= CreateCompatibleDC (0);
2798 hbmNewBitmap
= ImageList_CreateImage(hdcBitmap
, himl
, nNewCount
);
2800 if (hbmNewBitmap
!= 0)
2802 hbmOld
= SelectObject (hdcBitmap
, hbmNewBitmap
);
2803 imagelist_copy_images( himl
, himl
->hdcImage
, hdcBitmap
, 0, nCopyCount
, 0 );
2804 SelectObject (hdcBitmap
, hbmOld
);
2806 /* FIXME: delete 'empty' image space? */
2808 SelectObject (himl
->hdcImage
, hbmNewBitmap
);
2809 DeleteObject (himl
->hbmImage
);
2810 himl
->hbmImage
= hbmNewBitmap
;
2813 ERR("Could not create new image bitmap !\n");
2818 imagelist_get_bitmap_size( himl
, nNewCount
, &sz
);
2819 hbmNewBitmap
= CreateBitmap (sz
.cx
, sz
.cy
, 1, 1, NULL
);
2820 if (hbmNewBitmap
!= 0)
2822 hbmOld
= SelectObject (hdcBitmap
, hbmNewBitmap
);
2823 imagelist_copy_images( himl
, himl
->hdcMask
, hdcBitmap
, 0, nCopyCount
, 0 );
2824 SelectObject (hdcBitmap
, hbmOld
);
2826 /* FIXME: delete 'empty' image space? */
2828 SelectObject (himl
->hdcMask
, hbmNewBitmap
);
2829 DeleteObject (himl
->hbmMask
);
2830 himl
->hbmMask
= hbmNewBitmap
;
2833 ERR("Could not create new mask bitmap!\n");
2836 DeleteDC (hdcBitmap
);
2838 if (himl
->has_alpha
)
2840 char *new_alpha
= HeapReAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, himl
->has_alpha
, nNewCount
);
2841 if (new_alpha
) himl
->has_alpha
= new_alpha
;
2844 HeapFree( GetProcessHeap(), 0, himl
->has_alpha
);
2845 himl
->has_alpha
= NULL
;
2849 /* Update max image count and current image count */
2850 himl
->cMaxImage
= nNewCount
;
2851 himl
->cCurImage
= iImageCount
;
2857 /*************************************************************************
2858 * ImageList_SetOverlayImage [COMCTL32.@]
2860 * Assigns an overlay mask index to an existing image in an image list.
2863 * himl [I] handle to image list
2864 * iImage [I] image index
2865 * iOverlay [I] overlay mask index
2873 ImageList_SetOverlayImage (HIMAGELIST himl
, INT iImage
, INT iOverlay
)
2875 if (!is_valid(himl
))
2877 if ((iOverlay
< 1) || (iOverlay
> MAX_OVERLAYIMAGE
))
2879 if ((iImage
!=-1) && ((iImage
< 0) || (iImage
> himl
->cCurImage
)))
2881 himl
->nOvlIdx
[iOverlay
- 1] = iImage
;
2887 /* helper for ImageList_Write - write bitmap to pstm
2888 * currently everything is written as 24 bit RGB, except masks
2891 _write_bitmap(HBITMAP hBitmap
, LPSTREAM pstm
)
2893 LPBITMAPFILEHEADER bmfh
;
2894 LPBITMAPINFOHEADER bmih
;
2895 LPBYTE data
= NULL
, lpBits
;
2897 INT bitCount
, sizeImage
, offBits
, totalSize
;
2899 BOOL result
= FALSE
;
2901 if (!GetObjectW(hBitmap
, sizeof(BITMAP
), &bm
))
2904 bitCount
= bm
.bmBitsPixel
== 1 ? 1 : 24;
2905 sizeImage
= DIB_GetDIBImageBytes(bm
.bmWidth
, bm
.bmHeight
, bitCount
);
2907 totalSize
= sizeof(BITMAPFILEHEADER
) + sizeof(BITMAPINFOHEADER
);
2909 totalSize
+= (1 << bitCount
) * sizeof(RGBQUAD
);
2910 offBits
= totalSize
;
2911 totalSize
+= sizeImage
;
2913 data
= Alloc(totalSize
);
2914 bmfh
= (LPBITMAPFILEHEADER
)data
;
2915 bmih
= (LPBITMAPINFOHEADER
)(data
+ sizeof(BITMAPFILEHEADER
));
2916 lpBits
= data
+ offBits
;
2918 /* setup BITMAPFILEHEADER */
2919 bmfh
->bfType
= (('M' << 8) | 'B');
2920 bmfh
->bfSize
= offBits
;
2921 bmfh
->bfReserved1
= 0;
2922 bmfh
->bfReserved2
= 0;
2923 bmfh
->bfOffBits
= offBits
;
2925 /* setup BITMAPINFOHEADER */
2926 bmih
->biSize
= sizeof(BITMAPINFOHEADER
);
2927 bmih
->biWidth
= bm
.bmWidth
;
2928 bmih
->biHeight
= bm
.bmHeight
;
2930 bmih
->biBitCount
= bitCount
;
2931 bmih
->biCompression
= BI_RGB
;
2932 bmih
->biSizeImage
= sizeImage
;
2933 bmih
->biXPelsPerMeter
= 0;
2934 bmih
->biYPelsPerMeter
= 0;
2935 bmih
->biClrUsed
= 0;
2936 bmih
->biClrImportant
= 0;
2939 result
= GetDIBits(xdc
, hBitmap
, 0, bm
.bmHeight
, lpBits
, (BITMAPINFO
*)bmih
, DIB_RGB_COLORS
) == bm
.bmHeight
;
2944 TRACE("width %u, height %u, planes %u, bpp %u\n",
2945 bmih
->biWidth
, bmih
->biHeight
,
2946 bmih
->biPlanes
, bmih
->biBitCount
);
2950 LPBITMAPINFO inf
= (LPBITMAPINFO
)bmih
;
2951 inf
->bmiColors
[0].rgbRed
= inf
->bmiColors
[0].rgbGreen
= inf
->bmiColors
[0].rgbBlue
= 0;
2952 inf
->bmiColors
[1].rgbRed
= inf
->bmiColors
[1].rgbGreen
= inf
->bmiColors
[1].rgbBlue
= 0xff;
2955 if(FAILED(IStream_Write(pstm
, data
, totalSize
, NULL
)))
2967 /*************************************************************************
2968 * ImageList_Write [COMCTL32.@]
2970 * Writes an image list to a stream.
2973 * himl [I] handle to image list
2974 * pstm [O] Pointer to a stream.
2985 ImageList_Write (HIMAGELIST himl
, LPSTREAM pstm
)
2990 TRACE("%p %p\n", himl
, pstm
);
2992 if (!is_valid(himl
))
2995 ilHead
.usMagic
= (('L' << 8) | 'I');
2996 ilHead
.usVersion
= 0x101;
2997 ilHead
.cCurImage
= himl
->cCurImage
;
2998 ilHead
.cMaxImage
= himl
->cMaxImage
;
2999 ilHead
.cGrow
= himl
->cGrow
;
3000 ilHead
.cx
= himl
->cx
;
3001 ilHead
.cy
= himl
->cy
;
3002 ilHead
.bkcolor
= himl
->clrBk
;
3003 ilHead
.flags
= himl
->flags
;
3004 for(i
= 0; i
< 4; i
++) {
3005 ilHead
.ovls
[i
] = himl
->nOvlIdx
[i
];
3008 TRACE("cx %u, cy %u, flags 0x04%x, cCurImage %u, cMaxImage %u\n",
3009 ilHead
.cx
, ilHead
.cy
, ilHead
.flags
, ilHead
.cCurImage
, ilHead
.cMaxImage
);
3011 if(FAILED(IStream_Write(pstm
, &ilHead
, sizeof(ILHEAD
), NULL
)))
3014 /* write the bitmap */
3015 if(!_write_bitmap(himl
->hbmImage
, pstm
))
3018 /* write the mask if we have one */
3019 if(himl
->flags
& ILC_MASK
) {
3020 if(!_write_bitmap(himl
->hbmMask
, pstm
))
3028 static HBITMAP
ImageList_CreateImage(HDC hdc
, HIMAGELIST himl
, UINT count
)
3030 HBITMAP hbmNewBitmap
;
3031 UINT ilc
= (himl
->flags
& 0xFE);
3034 imagelist_get_bitmap_size( himl
, count
, &sz
);
3036 if ((ilc
>= ILC_COLOR4
&& ilc
<= ILC_COLOR32
) || ilc
== ILC_COLOR
)
3041 TRACE("Creating DIBSection %d x %d, %d Bits per Pixel\n",
3042 sz
.cx
, sz
.cy
, himl
->uBitsPixel
);
3044 if (himl
->uBitsPixel
<= ILC_COLOR8
)
3050 colors
= 1 << himl
->uBitsPixel
;
3051 bmi
= Alloc(sizeof(BITMAPINFOHEADER
) +
3052 sizeof(PALETTEENTRY
) * colors
);
3054 pal
= (LPPALETTEENTRY
)bmi
->bmiColors
;
3055 GetPaletteEntries(GetStockObject(DEFAULT_PALETTE
), 0, colors
, pal
);
3057 /* Swap colors returned by GetPaletteEntries so we can use them for
3058 * CreateDIBSection call. */
3059 for (i
= 0; i
< colors
; i
++)
3061 temp
= pal
[i
].peBlue
;
3062 bmi
->bmiColors
[i
].rgbRed
= pal
[i
].peRed
;
3063 bmi
->bmiColors
[i
].rgbBlue
= temp
;
3068 bmi
= Alloc(sizeof(BITMAPINFOHEADER
));
3071 bmi
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
3072 bmi
->bmiHeader
.biWidth
= sz
.cx
;
3073 bmi
->bmiHeader
.biHeight
= sz
.cy
;
3074 bmi
->bmiHeader
.biPlanes
= 1;
3075 bmi
->bmiHeader
.biBitCount
= himl
->uBitsPixel
;
3076 bmi
->bmiHeader
.biCompression
= BI_RGB
;
3077 bmi
->bmiHeader
.biSizeImage
= 0;
3078 bmi
->bmiHeader
.biXPelsPerMeter
= 0;
3079 bmi
->bmiHeader
.biYPelsPerMeter
= 0;
3080 bmi
->bmiHeader
.biClrUsed
= 0;
3081 bmi
->bmiHeader
.biClrImportant
= 0;
3083 hbmNewBitmap
= CreateDIBSection(hdc
, bmi
, DIB_RGB_COLORS
, &bits
, 0, 0);
3087 else /*if (ilc == ILC_COLORDDB)*/
3089 TRACE("Creating Bitmap: %d Bits per Pixel\n", himl
->uBitsPixel
);
3091 hbmNewBitmap
= CreateBitmap (sz
.cx
, sz
.cy
, 1, himl
->uBitsPixel
, NULL
);
3093 TRACE("returning %p\n", hbmNewBitmap
);
3094 return hbmNewBitmap
;
3097 /*************************************************************************
3098 * ImageList_SetColorTable [COMCTL32.@]
3100 * Sets the color table of an image list.
3103 * himl [I] Handle to the image list.
3104 * uStartIndex [I] The first index to set.
3105 * cEntries [I] Number of entries to set.
3106 * prgb [I] New color information for color table for the image list.
3109 * Success: Number of entries in the table that were set.
3113 * ImageList_Create(), SetDIBColorTable()
3117 ImageList_SetColorTable (HIMAGELIST himl
, UINT uStartIndex
, UINT cEntries
, CONST RGBQUAD
* prgb
)
3119 return SetDIBColorTable(himl
->hdcImage
, uStartIndex
, cEntries
, prgb
);
3122 /*************************************************************************
3123 * ImageList_CoCreateInstance [COMCTL32.@]
3125 * Creates a new imagelist instance and returns an interface pointer to it.
3128 * rclsid [I] A reference to the CLSID (CLSID_ImageList).
3129 * punkOuter [I] Pointer to IUnknown interface for aggregation, if desired
3130 * riid [I] Identifier of the requested interface.
3131 * ppv [O] Returns the address of the pointer requested, or NULL.
3135 * Failure: Error value.
3138 ImageList_CoCreateInstance (REFCLSID rclsid
, const IUnknown
*punkOuter
, REFIID riid
, void **ppv
)
3140 TRACE("(%s,%p,%s,%p)\n", debugstr_guid(rclsid
), punkOuter
, debugstr_guid(riid
), ppv
);
3142 if (!IsEqualCLSID(&CLSID_ImageList
, rclsid
))
3143 return E_NOINTERFACE
;
3145 return ImageListImpl_CreateInstance(punkOuter
, riid
, ppv
);
3149 /*************************************************************************
3150 * IImageList implementation
3153 static HRESULT WINAPI
ImageListImpl_QueryInterface(IImageList
*iface
,
3154 REFIID iid
, void **ppv
)
3156 HIMAGELIST This
= (HIMAGELIST
) iface
;
3157 TRACE("(%p,%s,%p)\n", iface
, debugstr_guid(iid
), ppv
);
3159 if (!ppv
) return E_INVALIDARG
;
3161 if (IsEqualIID(&IID_IUnknown
, iid
) || IsEqualIID(&IID_IImageList
, iid
))
3166 return E_NOINTERFACE
;
3169 IUnknown_AddRef((IUnknown
*)*ppv
);
3173 static ULONG WINAPI
ImageListImpl_AddRef(IImageList
*iface
)
3175 HIMAGELIST This
= (HIMAGELIST
) iface
;
3176 ULONG ref
= InterlockedIncrement(&This
->ref
);
3178 TRACE("(%p) refcount=%u\n", iface
, ref
);
3182 static ULONG WINAPI
ImageListImpl_Release(IImageList
*iface
)
3184 HIMAGELIST This
= (HIMAGELIST
) iface
;
3185 ULONG ref
= InterlockedDecrement(&This
->ref
);
3187 TRACE("(%p) refcount=%u\n", iface
, ref
);
3191 /* delete image bitmaps */
3192 if (This
->hbmImage
) DeleteObject (This
->hbmImage
);
3193 if (This
->hbmMask
) DeleteObject (This
->hbmMask
);
3195 /* delete image & mask DCs */
3196 if (This
->hdcImage
) DeleteDC (This
->hdcImage
);
3197 if (This
->hdcMask
) DeleteDC (This
->hdcMask
);
3199 /* delete blending brushes */
3200 if (This
->hbrBlend25
) DeleteObject (This
->hbrBlend25
);
3201 if (This
->hbrBlend50
) DeleteObject (This
->hbrBlend50
);
3203 This
->lpVtbl
= NULL
;
3204 HeapFree(GetProcessHeap(), 0, This
->has_alpha
);
3205 HeapFree(GetProcessHeap(), 0, This
);
3211 static HRESULT WINAPI
ImageListImpl_Add(IImageList
*iface
, HBITMAP hbmImage
,
3212 HBITMAP hbmMask
, int *pi
)
3214 HIMAGELIST This
= (HIMAGELIST
) iface
;
3220 ret
= ImageList_Add(This
, hbmImage
, hbmMask
);
3229 static HRESULT WINAPI
ImageListImpl_ReplaceIcon(IImageList
*iface
, int i
,
3230 HICON hicon
, int *pi
)
3232 HIMAGELIST This
= (HIMAGELIST
) iface
;
3238 ret
= ImageList_ReplaceIcon(This
, i
, hicon
);
3247 static HRESULT WINAPI
ImageListImpl_SetOverlayImage(IImageList
*iface
,
3248 int iImage
, int iOverlay
)
3250 return ImageList_SetOverlayImage((HIMAGELIST
) iface
, iImage
, iOverlay
)
3254 static HRESULT WINAPI
ImageListImpl_Replace(IImageList
*iface
, int i
,
3255 HBITMAP hbmImage
, HBITMAP hbmMask
)
3257 return ImageList_Replace((HIMAGELIST
) iface
, i
, hbmImage
, hbmMask
) ? S_OK
:
3261 static HRESULT WINAPI
ImageListImpl_AddMasked(IImageList
*iface
, HBITMAP hbmImage
,
3262 COLORREF crMask
, int *pi
)
3264 HIMAGELIST This
= (HIMAGELIST
) iface
;
3270 ret
= ImageList_AddMasked(This
, hbmImage
, crMask
);
3279 static HRESULT WINAPI
ImageListImpl_Draw(IImageList
*iface
,
3280 IMAGELISTDRAWPARAMS
*pimldp
)
3282 HIMAGELIST This
= (HIMAGELIST
) iface
;
3283 HIMAGELIST old_himl
;
3286 /* As far as I can tell, Windows simply ignores the contents of pimldp->himl
3287 so we shall simulate the same */
3288 old_himl
= pimldp
->himl
;
3289 pimldp
->himl
= This
;
3291 ret
= ImageList_DrawIndirect(pimldp
);
3293 pimldp
->himl
= old_himl
;
3294 return ret
? S_OK
: E_INVALIDARG
;
3297 static HRESULT WINAPI
ImageListImpl_Remove(IImageList
*iface
, int i
)
3299 return (ImageList_Remove((HIMAGELIST
) iface
, i
) == 0) ? E_INVALIDARG
: S_OK
;
3302 static HRESULT WINAPI
ImageListImpl_GetIcon(IImageList
*iface
, int i
, UINT flags
,
3310 hIcon
= ImageList_GetIcon((HIMAGELIST
) iface
, i
, flags
);
3319 static HRESULT WINAPI
ImageListImpl_GetImageInfo(IImageList
*iface
, int i
,
3320 IMAGEINFO
*pImageInfo
)
3322 return ImageList_GetImageInfo((HIMAGELIST
) iface
, i
, pImageInfo
) ? S_OK
: E_FAIL
;
3325 static HRESULT WINAPI
ImageListImpl_Copy(IImageList
*iface
, int iDst
,
3326 IUnknown
*punkSrc
, int iSrc
, UINT uFlags
)
3328 HIMAGELIST This
= (HIMAGELIST
) iface
;
3329 IImageList
*src
= NULL
;
3335 /* TODO: Add test for IID_ImageList2 too */
3336 if (FAILED(IImageList_QueryInterface(punkSrc
, &IID_IImageList
,
3340 if (ImageList_Copy(This
, iDst
, (HIMAGELIST
) src
, iSrc
, uFlags
))
3345 IImageList_Release(src
);
3349 static HRESULT WINAPI
ImageListImpl_Merge(IImageList
*iface
, int i1
,
3350 IUnknown
*punk2
, int i2
, int dx
, int dy
, REFIID riid
, void **ppv
)
3352 HIMAGELIST This
= (HIMAGELIST
) iface
;
3353 IImageList
*iml2
= NULL
;
3355 HRESULT ret
= E_FAIL
;
3357 TRACE("(%p)->(%d %p %d %d %d %s %p)\n", iface
, i1
, punk2
, i2
, dx
, dy
, debugstr_guid(riid
), ppv
);
3359 /* TODO: Add test for IID_ImageList2 too */
3360 if (FAILED(IImageList_QueryInterface(punk2
, &IID_IImageList
,
3364 hNew
= ImageList_Merge(This
, i1
, (HIMAGELIST
) iml2
, i2
, dx
, dy
);
3366 /* Get the interface for the new image list */
3369 IImageList
*imerge
= (IImageList
*)hNew
;
3371 ret
= HIMAGELIST_QueryInterface(hNew
, riid
, ppv
);
3372 IImageList_Release(imerge
);
3375 IImageList_Release(iml2
);
3379 static HRESULT WINAPI
ImageListImpl_Clone(IImageList
*iface
, REFIID riid
, void **ppv
)
3381 HIMAGELIST This
= (HIMAGELIST
) iface
;
3383 HRESULT ret
= E_FAIL
;
3385 TRACE("(%p)->(%s %p)\n", iface
, debugstr_guid(riid
), ppv
);
3387 clone
= ImageList_Duplicate(This
);
3389 /* Get the interface for the new image list */
3392 IImageList
*iclone
= (IImageList
*)clone
;
3394 ret
= HIMAGELIST_QueryInterface(clone
, riid
, ppv
);
3395 IImageList_Release(iclone
);
3401 static HRESULT WINAPI
ImageListImpl_GetImageRect(IImageList
*iface
, int i
,
3404 HIMAGELIST This
= (HIMAGELIST
) iface
;
3410 if (!ImageList_GetImageInfo(This
, i
, &info
))
3413 return CopyRect(prc
, &info
.rcImage
) ? S_OK
: E_FAIL
;
3416 static HRESULT WINAPI
ImageListImpl_GetIconSize(IImageList
*iface
, int *cx
,
3419 HIMAGELIST This
= (HIMAGELIST
) iface
;
3421 return ImageList_GetIconSize(This
, cx
, cy
) ? S_OK
: E_INVALIDARG
;
3424 static HRESULT WINAPI
ImageListImpl_SetIconSize(IImageList
*iface
, int cx
,
3427 return ImageList_SetIconSize((HIMAGELIST
) iface
, cx
, cy
) ? S_OK
: E_FAIL
;
3430 static HRESULT WINAPI
ImageListImpl_GetImageCount(IImageList
*iface
, int *pi
)
3432 *pi
= ImageList_GetImageCount((HIMAGELIST
) iface
);
3436 static HRESULT WINAPI
ImageListImpl_SetImageCount(IImageList
*iface
,
3439 return ImageList_SetImageCount((HIMAGELIST
) iface
, uNewCount
) ? S_OK
: E_FAIL
;
3442 static HRESULT WINAPI
ImageListImpl_SetBkColor(IImageList
*iface
, COLORREF clrBk
,
3445 *pclr
= ImageList_SetBkColor((HIMAGELIST
) iface
, clrBk
);
3449 static HRESULT WINAPI
ImageListImpl_GetBkColor(IImageList
*iface
, COLORREF
*pclr
)
3451 *pclr
= ImageList_GetBkColor((HIMAGELIST
) iface
);
3455 static HRESULT WINAPI
ImageListImpl_BeginDrag(IImageList
*iface
, int iTrack
,
3456 int dxHotspot
, int dyHotspot
)
3458 return ImageList_BeginDrag((HIMAGELIST
) iface
, iTrack
, dxHotspot
, dyHotspot
) ? S_OK
: E_FAIL
;
3461 static HRESULT WINAPI
ImageListImpl_EndDrag(IImageList
*iface
)
3463 ImageList_EndDrag();
3467 static HRESULT WINAPI
ImageListImpl_DragEnter(IImageList
*iface
, HWND hwndLock
,
3470 return ImageList_DragEnter(hwndLock
, x
, y
) ? S_OK
: E_FAIL
;
3473 static HRESULT WINAPI
ImageListImpl_DragLeave(IImageList
*iface
, HWND hwndLock
)
3475 return ImageList_DragLeave(hwndLock
) ? S_OK
: E_FAIL
;
3478 static HRESULT WINAPI
ImageListImpl_DragMove(IImageList
*iface
, int x
, int y
)
3480 return ImageList_DragMove(x
, y
) ? S_OK
: E_FAIL
;
3483 static HRESULT WINAPI
ImageListImpl_SetDragCursorImage(IImageList
*iface
,
3484 IUnknown
*punk
, int iDrag
, int dxHotspot
, int dyHotspot
)
3486 IImageList
*iml2
= NULL
;
3492 /* TODO: Add test for IID_ImageList2 too */
3493 if (FAILED(IImageList_QueryInterface(punk
, &IID_IImageList
,
3497 ret
= ImageList_SetDragCursorImage((HIMAGELIST
) iml2
, iDrag
, dxHotspot
,
3500 IImageList_Release(iml2
);
3502 return ret
? S_OK
: E_FAIL
;
3505 static HRESULT WINAPI
ImageListImpl_DragShowNolock(IImageList
*iface
, BOOL fShow
)
3507 return ImageList_DragShowNolock(fShow
) ? S_OK
: E_FAIL
;
3510 static HRESULT WINAPI
ImageListImpl_GetDragImage(IImageList
*iface
, POINT
*ppt
,
3511 POINT
*pptHotspot
, REFIID riid
, PVOID
*ppv
)
3513 HRESULT ret
= E_FAIL
;
3519 hNew
= ImageList_GetDragImage(ppt
, pptHotspot
);
3521 /* Get the interface for the new image list */
3524 IImageList
*idrag
= (IImageList
*)hNew
;
3526 ret
= HIMAGELIST_QueryInterface(hNew
, riid
, ppv
);
3527 IImageList_Release(idrag
);
3533 static HRESULT WINAPI
ImageListImpl_GetItemFlags(IImageList
*iface
, int i
,
3536 FIXME("STUB: %p %d %p\n", iface
, i
, dwFlags
);
3540 static HRESULT WINAPI
ImageListImpl_GetOverlayImage(IImageList
*iface
, int iOverlay
,
3543 HIMAGELIST This
= (HIMAGELIST
) iface
;
3546 if ((iOverlay
< 0) || (iOverlay
> This
->cCurImage
))
3549 for (i
= 0; i
< MAX_OVERLAYIMAGE
; i
++)
3551 if (This
->nOvlIdx
[i
] == iOverlay
)
3562 static const IImageListVtbl ImageListImpl_Vtbl
= {
3563 ImageListImpl_QueryInterface
,
3564 ImageListImpl_AddRef
,
3565 ImageListImpl_Release
,
3567 ImageListImpl_ReplaceIcon
,
3568 ImageListImpl_SetOverlayImage
,
3569 ImageListImpl_Replace
,
3570 ImageListImpl_AddMasked
,
3572 ImageListImpl_Remove
,
3573 ImageListImpl_GetIcon
,
3574 ImageListImpl_GetImageInfo
,
3576 ImageListImpl_Merge
,
3577 ImageListImpl_Clone
,
3578 ImageListImpl_GetImageRect
,
3579 ImageListImpl_GetIconSize
,
3580 ImageListImpl_SetIconSize
,
3581 ImageListImpl_GetImageCount
,
3582 ImageListImpl_SetImageCount
,
3583 ImageListImpl_SetBkColor
,
3584 ImageListImpl_GetBkColor
,
3585 ImageListImpl_BeginDrag
,
3586 ImageListImpl_EndDrag
,
3587 ImageListImpl_DragEnter
,
3588 ImageListImpl_DragLeave
,
3589 ImageListImpl_DragMove
,
3590 ImageListImpl_SetDragCursorImage
,
3591 ImageListImpl_DragShowNolock
,
3592 ImageListImpl_GetDragImage
,
3593 ImageListImpl_GetItemFlags
,
3594 ImageListImpl_GetOverlayImage
3597 static inline BOOL
is_valid(HIMAGELIST himl
)
3602 valid
= himl
&& himl
->lpVtbl
== &ImageListImpl_Vtbl
;
3612 /*************************************************************************
3613 * HIMAGELIST_QueryInterface [COMCTL32.@]
3615 * Returns a pointer to an IImageList or IImageList2 object for the given
3619 * himl [I] Image list handle.
3620 * riid [I] Identifier of the requested interface.
3621 * ppv [O] Returns the address of the pointer requested, or NULL.
3625 * Failure: Error value.
3628 HIMAGELIST_QueryInterface (HIMAGELIST himl
, REFIID riid
, void **ppv
)
3630 TRACE("(%p,%s,%p)\n", himl
, debugstr_guid(riid
), ppv
);
3631 return IImageList_QueryInterface((IImageList
*) himl
, riid
, ppv
);
3634 static HRESULT
ImageListImpl_CreateInstance(const IUnknown
*pUnkOuter
, REFIID iid
, void** ppv
)
3639 TRACE("(%p,%s,%p)\n", pUnkOuter
, debugstr_guid(iid
), ppv
);
3643 if (pUnkOuter
) return CLASS_E_NOAGGREGATION
;
3645 This
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(struct _IMAGELIST
));
3646 if (!This
) return E_OUTOFMEMORY
;
3648 This
->lpVtbl
= &ImageListImpl_Vtbl
;
3651 ret
= IUnknown_QueryInterface((IUnknown
*)This
, iid
, ppv
);
3652 IUnknown_Release((IUnknown
*)This
);