2 * ImageList implementation
4 * Copyright 1998 Eric Kohl
5 * Copyright 2000 Jason Mawdsley
6 * Copyright 2001, 2004 Michael Stefaniuc
7 * Copyright 2001 Charles Loep for CodeWeavers
8 * Copyright 2002 Dimitrie O. Paun
9 * Copyright 2009 Owen Rudge for CodeWeavers
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public
13 * License as published by the Free Software Foundation; either
14 * version 2.1 of the License, or (at your option) any later version.
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with this library; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 * - Add support for ILD_PRESERVEALPHA, ILD_SCALE, ILD_DPISCALE
27 * - Add support for ILS_GLOW, ILS_SHADOW
28 * - Thread-safe locking
45 #include "commoncontrols.h"
46 #include "wine/debug.h"
47 #include "wine/exception.h"
48 #include "wine/heap.h"
50 WINE_DEFAULT_DEBUG_CHANNEL(imagelist
);
52 #define MAX_OVERLAYIMAGE 15
55 //The big bad reactos image list hack!
56 BOOL
is_valid2(HIMAGELIST himl
);
57 INT WINAPI
Internal_ReplaceIcon (HIMAGELIST himl
, INT nIndex
, HICON hIcon
);
58 BOOL WINAPI
Internal_DrawIndirect (IMAGELISTDRAWPARAMS
*pimldp
);
59 COLORREF WINAPI
Internal_SetBkColor (HIMAGELIST himl
, COLORREF clrBk
);
60 BOOL WINAPI
Internal_SetOverlayImage (HIMAGELIST himl
, INT iImage
, INT iOverlay
);
62 #define ImageList_Add Internal_Add
63 #define ImageList_ReplaceIcon Internal_ReplaceIcon
64 #define ImageList_SetOverlayImage Internal_SetOverlayImage
65 #define ImageList_Replace Internal_Replace
66 #define ImageList_AddMasked Internal_AddMasked
67 #define ImageList_Remove Internal_Remove
68 #define ImageList_GetIcon Internal_GetIcon
69 #define ImageList_GetImageInfo Internal_GetImageInfo
70 #define ImageList_Copy Internal_Copy
71 #define ImageList_Merge Internal_Merge
72 #define ImageList_Duplicate Internal_Duplicate
73 #define ImageList_GetIconSize Internal_GetIconSize
74 #define ImageList_SetIconSize Internal_SetIconSize
75 #define ImageList_GetImageCount Internal_GetImageCount
76 #define ImageList_SetImageCount Internal_SetImageCount
77 #define ImageList_SetBkColor Internal_SetBkColor
78 #define ImageList_GetBkColor Internal_GetBkColor
79 #define ImageList_BeginDrag Internal_BeginDrag
80 #define ImageList_DrawIndirect Internal_DrawIndirect
85 IImageList2 IImageList2_iface
; /* 00: IImageList vtable */
86 INT cCurImage
; /* 04: ImageCount */
87 INT cMaxImage
; /* 08: maximages */
88 INT cGrow
; /* 0C: cGrow */
92 UINT flags
; /* 1C: flags */
93 COLORREF clrFg
; /* 20: foreground color */
94 COLORREF clrBk
; /* 24: background color */
97 HBITMAP hbmImage
; /* 28: images Bitmap */
98 HBITMAP hbmMask
; /* 2C: masks Bitmap */
99 HDC hdcImage
; /* 30: images MemDC */
100 HDC hdcMask
; /* 34: masks MemDC */
101 INT nOvlIdx
[MAX_OVERLAYIMAGE
]; /* 38: overlay images index */
103 /* not yet found out */
112 BOOL color_table_set
;
114 LONG ref
; /* reference count */
117 #define IMAGELIST_MAGIC 0x53414D58
119 /* Header used by ImageList_Read() and ImageList_Write() */
120 #include "pshpack2.h"
121 typedef struct _ILHEAD
136 /* internal image list data used for Drag & Drop operations */
141 HIMAGELIST himlNoCursor
;
142 /* position of the drag image relative to the window */
145 /* offset of the hotspot relative to the origin of the image */
148 /* is the drag image visible */
150 /* saved background */
154 static INTERNALDRAG InternalDrag
= { 0, 0, 0, 0, 0, 0, 0, FALSE
, 0 };
156 static inline HIMAGELIST
impl_from_IImageList2(IImageList2
*iface
)
158 return CONTAINING_RECORD(iface
, struct _IMAGELIST
, IImageList2_iface
);
161 static HBITMAP
ImageList_CreateImage(HDC hdc
, HIMAGELIST himl
, UINT count
);
162 static HRESULT
ImageListImpl_CreateInstance(const IUnknown
*pUnkOuter
, REFIID iid
, void** ppv
);
163 static BOOL
is_valid(HIMAGELIST himl
);
166 * An imagelist with N images is tiled like this:
178 static inline UINT
imagelist_height( UINT count
)
180 return ((count
+ TILE_COUNT
- 1)/TILE_COUNT
);
183 static inline void imagelist_point_from_index( HIMAGELIST himl
, UINT index
, LPPOINT pt
)
185 pt
->x
= (index
%TILE_COUNT
) * himl
->cx
;
186 pt
->y
= (index
/TILE_COUNT
) * himl
->cy
;
189 static inline void imagelist_get_bitmap_size( HIMAGELIST himl
, UINT count
, SIZE
*sz
)
191 sz
->cx
= himl
->cx
* TILE_COUNT
;
192 sz
->cy
= imagelist_height( count
) * himl
->cy
;
195 static inline int get_dib_stride( int width
, int bpp
)
197 return ((width
* bpp
+ 31) >> 3) & ~3;
200 static inline int get_dib_image_size( const BITMAPINFO
*info
)
202 return get_dib_stride( info
->bmiHeader
.biWidth
, info
->bmiHeader
.biBitCount
)
203 * abs( info
->bmiHeader
.biHeight
);
207 * imagelist_copy_images()
209 * Copies a block of count images from offset src in the list to offset dest.
210 * Images are copied a row at at time. Assumes hdcSrc and hdcDest are different.
212 static inline void imagelist_copy_images( HIMAGELIST himl
, HDC hdcSrc
, HDC hdcDest
,
213 UINT src
, UINT count
, UINT dest
)
219 for ( i
=0; i
<TILE_COUNT
; i
++ )
221 imagelist_point_from_index( himl
, src
+i
, &ptSrc
);
222 imagelist_point_from_index( himl
, dest
+i
, &ptDest
);
224 sz
.cy
= himl
->cy
* imagelist_height( count
- i
);
226 BitBlt( hdcDest
, ptDest
.x
, ptDest
.y
, sz
.cx
, sz
.cy
,
227 hdcSrc
, ptSrc
.x
, ptSrc
.y
, SRCCOPY
);
231 static void add_dib_bits( HIMAGELIST himl
, int pos
, int count
, int width
, int height
,
232 BITMAPINFO
*info
, BITMAPINFO
*mask_info
, DWORD
*bits
, BYTE
*mask_bits
)
236 int stride
= info
->bmiHeader
.biWidth
;
237 int mask_stride
= (info
->bmiHeader
.biWidth
+ 31) / 32 * 4;
239 for (n
= 0; n
< count
; n
++)
241 BOOL has_alpha
= FALSE
;
243 imagelist_point_from_index( himl
, pos
+ n
, &pt
);
245 /* check if bitmap has an alpha channel */
246 for (i
= 0; i
< height
&& !has_alpha
; i
++)
247 for (j
= n
* width
; j
< (n
+ 1) * width
; j
++)
248 if ((has_alpha
= ((bits
[i
* stride
+ j
] & 0xff000000) != 0))) break;
250 if (!has_alpha
) /* generate alpha channel from the mask */
252 for (i
= 0; i
< height
; i
++)
253 for (j
= n
* width
; j
< (n
+ 1) * width
; j
++)
254 if (!mask_info
|| !((mask_bits
[i
* mask_stride
+ j
/ 8] << (j
% 8)) & 0x80))
255 bits
[i
* stride
+ j
] |= 0xff000000;
257 bits
[i
* stride
+ j
] = 0;
261 himl
->has_alpha
[pos
+ n
] = 1;
263 if (mask_info
&& himl
->hbmMask
) /* generate the mask from the alpha channel */
265 for (i
= 0; i
< height
; i
++)
266 for (j
= n
* width
; j
< (n
+ 1) * width
; j
++)
267 if ((bits
[i
* stride
+ j
] >> 24) > 25) /* more than 10% alpha */
268 mask_bits
[i
* mask_stride
+ j
/ 8] &= ~(0x80 >> (j
% 8));
270 mask_bits
[i
* mask_stride
+ j
/ 8] |= 0x80 >> (j
% 8);
273 StretchDIBits( himl
->hdcImage
, pt
.x
, pt
.y
, himl
->cx
, himl
->cy
,
274 n
* width
, 0, width
, height
, bits
, info
, DIB_RGB_COLORS
, SRCCOPY
);
276 StretchDIBits( himl
->hdcMask
, pt
.x
, pt
.y
, himl
->cx
, himl
->cy
,
277 n
* width
, 0, width
, height
, mask_bits
, mask_info
, DIB_RGB_COLORS
, SRCCOPY
);
281 /* add images with an alpha channel when the image list is 32 bpp */
282 static BOOL
add_with_alpha( HIMAGELIST himl
, HDC hdc
, int pos
, int count
,
283 int width
, int height
, HBITMAP hbmImage
, HBITMAP hbmMask
)
287 BITMAPINFO
*info
, *mask_info
= NULL
;
289 BYTE
*mask_bits
= NULL
;
292 if (!GetObjectW( hbmImage
, sizeof(bm
), &bm
)) return FALSE
;
294 /* if either the imagelist or the source bitmap don't have an alpha channel, bail out now */
295 if (!himl
->has_alpha
) return FALSE
;
296 if (bm
.bmBitsPixel
!= 32) return FALSE
;
298 SelectObject( hdc
, hbmImage
);
299 mask_width
= (bm
.bmWidth
+ 31) / 32 * 4;
301 if (!(info
= heap_alloc( FIELD_OFFSET( BITMAPINFO
, bmiColors
[256] )))) goto done
;
302 info
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
303 info
->bmiHeader
.biWidth
= bm
.bmWidth
;
304 info
->bmiHeader
.biHeight
= -height
;
305 info
->bmiHeader
.biPlanes
= 1;
306 info
->bmiHeader
.biBitCount
= 32;
307 info
->bmiHeader
.biCompression
= BI_RGB
;
308 info
->bmiHeader
.biSizeImage
= bm
.bmWidth
* height
* 4;
309 info
->bmiHeader
.biXPelsPerMeter
= 0;
310 info
->bmiHeader
.biYPelsPerMeter
= 0;
311 info
->bmiHeader
.biClrUsed
= 0;
312 info
->bmiHeader
.biClrImportant
= 0;
313 if (!(bits
= heap_alloc( info
->bmiHeader
.biSizeImage
))) goto done
;
314 if (!GetDIBits( hdc
, hbmImage
, 0, height
, bits
, info
, DIB_RGB_COLORS
)) goto done
;
318 if (!(mask_info
= heap_alloc( FIELD_OFFSET( BITMAPINFO
, bmiColors
[2] ))))
320 mask_info
->bmiHeader
= info
->bmiHeader
;
321 mask_info
->bmiHeader
.biBitCount
= 1;
322 mask_info
->bmiHeader
.biSizeImage
= mask_width
* height
;
323 if (!(mask_bits
= heap_alloc_zero( mask_info
->bmiHeader
.biSizeImage
)))
325 if (!GetDIBits( hdc
, hbmMask
, 0, height
, mask_bits
, mask_info
, DIB_RGB_COLORS
)) goto done
;
328 add_dib_bits( himl
, pos
, count
, width
, height
, info
, mask_info
, bits
, mask_bits
);
333 heap_free( mask_info
);
335 heap_free( mask_bits
);
340 ImageList_SetColorTable(HIMAGELIST himl
, UINT uStartIndex
, UINT cEntries
, const RGBQUAD
*prgb
);
342 /*************************************************************************
343 * IMAGELIST_InternalExpandBitmaps [Internal]
345 * Expands the bitmaps of an image list by the given number of images.
348 * himl [I] handle to image list
349 * nImageCount [I] number of images to add
355 * This function CANNOT be used to reduce the number of images.
358 IMAGELIST_InternalExpandBitmaps(HIMAGELIST himl
, INT nImageCount
)
361 HBITMAP hbmNewBitmap
, hbmNull
;
365 TRACE("%p has allocated %d, max %d, grow %d images\n", himl
, himl
->cCurImage
, himl
->cMaxImage
, himl
->cGrow
);
367 if (himl
->cCurImage
+ nImageCount
< himl
->cMaxImage
)
370 nNewCount
= himl
->cMaxImage
+ max(nImageCount
, himl
->cGrow
) + 1;
372 imagelist_get_bitmap_size(himl
, nNewCount
, &sz
);
374 TRACE("Create expanded bitmaps : himl=%p x=%d y=%d count=%d\n", himl
, sz
.cx
, sz
.cy
, nNewCount
);
375 hdcBitmap
= CreateCompatibleDC (0);
377 hbmNewBitmap
= ImageList_CreateImage(hdcBitmap
, himl
, nNewCount
);
379 if (hbmNewBitmap
== 0)
380 ERR("creating new image bitmap (x=%d y=%d)!\n", sz
.cx
, sz
.cy
);
384 hbmNull
= SelectObject (hdcBitmap
, hbmNewBitmap
);
385 BitBlt (hdcBitmap
, 0, 0, sz
.cx
, sz
.cy
,
386 himl
->hdcImage
, 0, 0, SRCCOPY
);
387 SelectObject (hdcBitmap
, hbmNull
);
389 SelectObject (himl
->hdcImage
, hbmNewBitmap
);
390 DeleteObject (himl
->hbmImage
);
391 himl
->hbmImage
= hbmNewBitmap
;
393 if (himl
->flags
& ILC_MASK
)
395 hbmNewBitmap
= CreateBitmap (sz
.cx
, sz
.cy
, 1, 1, NULL
);
397 if (hbmNewBitmap
== 0)
398 ERR("creating new mask bitmap!\n");
402 hbmNull
= SelectObject (hdcBitmap
, hbmNewBitmap
);
403 BitBlt (hdcBitmap
, 0, 0, sz
.cx
, sz
.cy
,
404 himl
->hdcMask
, 0, 0, SRCCOPY
);
405 SelectObject (hdcBitmap
, hbmNull
);
407 SelectObject (himl
->hdcMask
, hbmNewBitmap
);
408 DeleteObject (himl
->hbmMask
);
409 himl
->hbmMask
= hbmNewBitmap
;
414 char *new_alpha
= HeapReAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, himl
->has_alpha
, nNewCount
);
415 if (new_alpha
) himl
->has_alpha
= new_alpha
;
418 heap_free( himl
->has_alpha
);
419 himl
->has_alpha
= NULL
;
423 himl
->cMaxImage
= nNewCount
;
425 DeleteDC (hdcBitmap
);
429 /*************************************************************************
430 * ImageList_Add [COMCTL32.@]
432 * Add an image or images to an image list.
435 * himl [I] handle to image list
436 * hbmImage [I] handle to image bitmap
437 * hbmMask [I] handle to mask bitmap
440 * Success: Index of the first new image.
445 ImageList_Add (HIMAGELIST himl
, HBITMAP hbmImage
, HBITMAP hbmMask
)
447 HDC hdcBitmap
, hdcTemp
= 0;
448 INT nFirstIndex
, nImageCount
, i
;
452 TRACE("himl=%p hbmimage=%p hbmmask=%p\n", himl
, hbmImage
, hbmMask
);
456 if (!GetObjectW(hbmImage
, sizeof(BITMAP
), &bmp
))
459 TRACE("himl %p, cCurImage %d, cMaxImage %d, cGrow %d, cx %d, cy %d\n",
460 himl
, himl
->cCurImage
, himl
->cMaxImage
, himl
->cGrow
, himl
->cx
, himl
->cy
);
462 nImageCount
= bmp
.bmWidth
/ himl
->cx
;
464 TRACE("%p has %d images (%d x %d) bpp %d\n", hbmImage
, nImageCount
, bmp
.bmWidth
, bmp
.bmHeight
,
467 IMAGELIST_InternalExpandBitmaps(himl
, nImageCount
);
469 hdcBitmap
= CreateCompatibleDC(0);
471 SelectObject(hdcBitmap
, hbmImage
);
473 if (add_with_alpha( himl
, hdcBitmap
, himl
->cCurImage
, nImageCount
,
474 himl
->cx
, min( himl
->cy
, bmp
.bmHeight
), hbmImage
, hbmMask
))
479 hdcTemp
= CreateCompatibleDC(0);
480 SelectObject(hdcTemp
, hbmMask
);
483 if (himl
->uBitsPixel
<= 8 && bmp
.bmBitsPixel
<= 8 &&
484 !himl
->color_table_set
&& himl
->cCurImage
== 0)
487 UINT num
= GetDIBColorTable( hdcBitmap
, 0, 1 << bmp
.bmBitsPixel
, colors
);
488 if (num
) ImageList_SetColorTable( himl
, 0, num
, colors
);
491 for (i
=0; i
<nImageCount
; i
++)
493 imagelist_point_from_index( himl
, himl
->cCurImage
+ i
, &pt
);
495 /* Copy result to the imagelist
497 BitBlt( himl
->hdcImage
, pt
.x
, pt
.y
, himl
->cx
, bmp
.bmHeight
,
498 hdcBitmap
, i
*himl
->cx
, 0, SRCCOPY
);
503 BitBlt( himl
->hdcMask
, pt
.x
, pt
.y
, himl
->cx
, bmp
.bmHeight
,
504 hdcTemp
, i
*himl
->cx
, 0, SRCCOPY
);
506 /* Remove the background from the image
508 BitBlt( himl
->hdcImage
, pt
.x
, pt
.y
, himl
->cx
, bmp
.bmHeight
,
509 himl
->hdcMask
, pt
.x
, pt
.y
, 0x220326 ); /* NOTSRCAND */
511 if (hdcTemp
) DeleteDC(hdcTemp
);
516 nFirstIndex
= himl
->cCurImage
;
517 himl
->cCurImage
+= nImageCount
;
523 /*************************************************************************
524 * ImageList_AddIcon [COMCTL32.@]
526 * Adds an icon to an image list.
529 * himl [I] handle to image list
530 * hIcon [I] handle to icon
533 * Success: index of the new image
536 #undef ImageList_AddIcon
537 INT WINAPI
ImageList_AddIcon (HIMAGELIST himl
, HICON hIcon
)
539 return ImageList_ReplaceIcon (himl
, -1, hIcon
);
543 /*************************************************************************
544 * ImageList_AddMasked [COMCTL32.@]
546 * Adds an image or images to an image list and creates a mask from the
547 * specified bitmap using the mask color.
550 * himl [I] handle to image list.
551 * hBitmap [I] handle to bitmap
552 * clrMask [I] mask color.
555 * Success: Index of the first new image.
560 ImageList_AddMasked (HIMAGELIST himl
, HBITMAP hBitmap
, COLORREF clrMask
)
562 HDC hdcMask
, hdcBitmap
;
568 TRACE("himl=%p hbitmap=%p clrmask=%x\n", himl
, hBitmap
, clrMask
);
572 if (!GetObjectW(hBitmap
, sizeof(BITMAP
), &bmp
))
575 hdcBitmap
= CreateCompatibleDC(0);
576 SelectObject(hdcBitmap
, hBitmap
);
578 /* Create a temp Mask so we can remove the background of the Image */
579 hdcMask
= CreateCompatibleDC(0);
580 hMaskBitmap
= CreateBitmap(bmp
.bmWidth
, bmp
.bmHeight
, 1, 1, NULL
);
581 SelectObject(hdcMask
, hMaskBitmap
);
583 /* create monochrome image to the mask bitmap */
584 bkColor
= (clrMask
!= CLR_DEFAULT
) ? clrMask
: GetPixel (hdcBitmap
, 0, 0);
585 SetBkColor (hdcBitmap
, bkColor
);
586 BitBlt (hdcMask
, 0, 0, bmp
.bmWidth
, bmp
.bmHeight
, hdcBitmap
, 0, 0, SRCCOPY
);
589 * Remove the background from the image
591 * WINDOWS BUG ALERT!!!!!!
592 * The statement below should not be done in common practice
593 * but this is how ImageList_AddMasked works in Windows.
594 * It overwrites the original bitmap passed, this was discovered
595 * by using the same bitmap to iterate the different styles
596 * on windows where it failed (BUT ImageList_Add is OK)
597 * This is here in case some apps rely on this bug
599 * Blt mode 0x220326 is NOTSRCAND
601 if (bmp
.bmBitsPixel
> 8) /* NOTSRCAND can't work with palettes */
603 SetBkColor(hdcBitmap
, RGB(255,255,255));
604 BitBlt(hdcBitmap
, 0, 0, bmp
.bmWidth
, bmp
.bmHeight
, hdcMask
, 0, 0, 0x220326);
610 ret
= ImageList_Add( himl
, hBitmap
, hMaskBitmap
);
612 DeleteObject(hMaskBitmap
);
617 /*************************************************************************
618 * ImageList_BeginDrag [COMCTL32.@]
620 * Creates a temporary image list that contains one image. It will be used
624 * himlTrack [I] handle to the source image list
625 * iTrack [I] index of the drag image in the source image list
626 * dxHotspot [I] X position of the hot spot of the drag image
627 * dyHotspot [I] Y position of the hot spot of the drag image
635 ImageList_BeginDrag (HIMAGELIST himlTrack
, INT iTrack
,
636 INT dxHotspot
, INT dyHotspot
)
641 TRACE("(himlTrack=%p iTrack=%d dx=%d dy=%d)\n", himlTrack
, iTrack
,
642 dxHotspot
, dyHotspot
);
644 if (!is_valid(himlTrack
))
647 if (iTrack
>= himlTrack
->cCurImage
)
650 if (InternalDrag
.himl
)
656 InternalDrag
.himlNoCursor
= InternalDrag
.himl
= ImageList_Create (cx
, cy
, himlTrack
->flags
, 1, 1);
657 if (InternalDrag
.himl
== NULL
) {
658 WARN("Error creating drag image list!\n");
662 InternalDrag
.dxHotspot
= dxHotspot
;
663 InternalDrag
.dyHotspot
= dyHotspot
;
666 imagelist_point_from_index(InternalDrag
.himl
, 0, &dst
);
667 imagelist_point_from_index(himlTrack
, iTrack
, &src
);
668 BitBlt(InternalDrag
.himl
->hdcImage
, dst
.x
, dst
.y
, cx
, cy
, himlTrack
->hdcImage
, src
.x
, src
.y
,
670 BitBlt(InternalDrag
.himl
->hdcMask
, dst
.x
, dst
.y
, cx
, cy
, himlTrack
->hdcMask
, src
.x
, src
.y
,
673 InternalDrag
.himl
->cCurImage
= 1;
679 /*************************************************************************
680 * ImageList_Copy [COMCTL32.@]
682 * Copies an image of the source image list to an image of the
683 * destination image list. Images can be copied or swapped.
686 * himlDst [I] handle to the destination image list
687 * iDst [I] destination image index.
688 * himlSrc [I] handle to the source image list
689 * iSrc [I] source image index
690 * uFlags [I] flags for the copy operation
697 * Copying from one image list to another is possible. The original
698 * implementation just copies or swaps within one image list.
699 * Could this feature become a bug??? ;-)
703 ImageList_Copy (HIMAGELIST himlDst
, INT iDst
, HIMAGELIST himlSrc
,
704 INT iSrc
, UINT uFlags
)
708 TRACE("himlDst=%p iDst=%d himlSrc=%p iSrc=%d\n", himlDst
, iDst
, himlSrc
, iSrc
);
710 if (!is_valid(himlSrc
) || !is_valid(himlDst
))
712 if ((iDst
< 0) || (iDst
>= himlDst
->cCurImage
))
714 if ((iSrc
< 0) || (iSrc
>= himlSrc
->cCurImage
))
717 imagelist_point_from_index( himlDst
, iDst
, &ptDst
);
718 imagelist_point_from_index( himlSrc
, iSrc
, &ptSrc
);
720 if (uFlags
& ILCF_SWAP
) {
723 HBITMAP hbmTempImage
, hbmTempMask
;
725 hdcBmp
= CreateCompatibleDC (0);
727 /* create temporary bitmaps */
728 hbmTempImage
= CreateBitmap (himlSrc
->cx
, himlSrc
->cy
, 1,
729 himlSrc
->uBitsPixel
, NULL
);
730 hbmTempMask
= CreateBitmap (himlSrc
->cx
, himlSrc
->cy
, 1,
733 /* copy (and stretch) destination to temporary bitmaps.(save) */
735 SelectObject (hdcBmp
, hbmTempImage
);
736 StretchBlt (hdcBmp
, 0, 0, himlSrc
->cx
, himlSrc
->cy
,
737 himlDst
->hdcImage
, ptDst
.x
, ptDst
.y
, himlDst
->cx
, himlDst
->cy
,
740 SelectObject (hdcBmp
, hbmTempMask
);
741 StretchBlt (hdcBmp
, 0, 0, himlSrc
->cx
, himlSrc
->cy
,
742 himlDst
->hdcMask
, ptDst
.x
, ptDst
.y
, himlDst
->cx
, himlDst
->cy
,
745 /* copy (and stretch) source to destination */
747 StretchBlt (himlDst
->hdcImage
, ptDst
.x
, ptDst
.y
, himlDst
->cx
, himlDst
->cy
,
748 himlSrc
->hdcImage
, ptSrc
.x
, ptSrc
.y
, himlSrc
->cx
, himlSrc
->cy
,
751 StretchBlt (himlDst
->hdcMask
, ptDst
.x
, ptDst
.y
, himlDst
->cx
, himlDst
->cy
,
752 himlSrc
->hdcMask
, ptSrc
.x
, ptSrc
.y
, himlSrc
->cx
, himlSrc
->cy
,
755 /* copy (without stretching) temporary bitmaps to source (restore) */
757 BitBlt (himlSrc
->hdcMask
, ptSrc
.x
, ptSrc
.y
, himlSrc
->cx
, himlSrc
->cy
,
758 hdcBmp
, 0, 0, SRCCOPY
);
761 BitBlt (himlSrc
->hdcImage
, ptSrc
.x
, ptSrc
.y
, himlSrc
->cx
, himlSrc
->cy
,
762 hdcBmp
, 0, 0, SRCCOPY
);
763 /* delete temporary bitmaps */
764 DeleteObject (hbmTempMask
);
765 DeleteObject (hbmTempImage
);
770 StretchBlt (himlDst
->hdcImage
, ptDst
.x
, ptDst
.y
, himlDst
->cx
, himlDst
->cy
,
771 himlSrc
->hdcImage
, ptSrc
.x
, ptSrc
.y
, himlSrc
->cx
, himlSrc
->cy
,
775 StretchBlt (himlDst
->hdcMask
, ptDst
.x
, ptDst
.y
, himlDst
->cx
, himlDst
->cy
,
776 himlSrc
->hdcMask
, ptSrc
.x
, ptSrc
.y
, himlSrc
->cx
, himlSrc
->cy
,
784 /*************************************************************************
785 * ImageList_Create [COMCTL32.@]
787 * Creates a new image list.
790 * cx [I] image height
792 * flags [I] creation flags
793 * cInitial [I] initial number of images in the image list
794 * cGrow [I] number of images by which image list grows
797 * Success: Handle to the created image list
801 ImageList_Create (INT cx
, INT cy
, UINT flags
,
802 INT cInitial
, INT cGrow
)
807 UINT ilc
= (flags
& 0xFE);
808 static const WORD aBitBlend25
[] =
809 {0xAA, 0x00, 0x55, 0x00, 0xAA, 0x00, 0x55, 0x00};
811 static const WORD aBitBlend50
[] =
812 {0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA};
814 TRACE("(%d %d 0x%x %d %d)\n", cx
, cy
, flags
, cInitial
, cGrow
);
816 if (cx
< 0 || cy
< 0) return NULL
;
817 if (!((flags
&ILC_COLORDDB
) == ILC_COLORDDB
) && (cx
== 0 || cy
== 0)) return NULL
;
819 /* Create the IImageList interface for the image list */
820 if (FAILED(ImageListImpl_CreateInstance(NULL
, &IID_IImageList
, (void **)&himl
)))
823 cGrow
= (WORD
)((max( cGrow
, 1 ) + 3) & ~3);
827 /* Windows doesn't limit the size here, but X11 doesn't let us allocate such huge bitmaps */
828 WARN( "grow %d too large, limiting to 256\n", cGrow
);
835 himl
->cMaxImage
= cInitial
+ 1;
836 himl
->cInitial
= cInitial
;
838 himl
->clrFg
= CLR_DEFAULT
;
839 himl
->clrBk
= CLR_NONE
;
840 himl
->color_table_set
= FALSE
;
842 /* initialize overlay mask indices */
843 for (nCount
= 0; nCount
< MAX_OVERLAYIMAGE
; nCount
++)
844 himl
->nOvlIdx
[nCount
] = -1;
846 /* Create Image & Mask DCs */
847 himl
->hdcImage
= CreateCompatibleDC (0);
850 if (himl
->flags
& ILC_MASK
){
851 himl
->hdcMask
= CreateCompatibleDC(0);
856 /* Default to ILC_COLOR4 if none of the ILC_COLOR* flags are specified */
857 if (ilc
== ILC_COLOR
)
860 himl
->flags
|= ILC_COLOR4
;
863 if (ilc
>= ILC_COLOR4
&& ilc
<= ILC_COLOR32
)
864 himl
->uBitsPixel
= ilc
;
866 himl
->uBitsPixel
= (UINT
)GetDeviceCaps (himl
->hdcImage
, BITSPIXEL
);
868 if (himl
->cMaxImage
> 0) {
869 himl
->hbmImage
= ImageList_CreateImage(himl
->hdcImage
, himl
, himl
->cMaxImage
);
870 SelectObject(himl
->hdcImage
, himl
->hbmImage
);
874 if ((himl
->cMaxImage
> 0) && (himl
->flags
& ILC_MASK
)) {
877 imagelist_get_bitmap_size(himl
, himl
->cMaxImage
, &sz
);
878 himl
->hbmMask
= CreateBitmap (sz
.cx
, sz
.cy
, 1, 1, NULL
);
879 if (himl
->hbmMask
== 0) {
880 ERR("Error creating mask bitmap!\n");
883 SelectObject(himl
->hdcMask
, himl
->hbmMask
);
888 if (ilc
== ILC_COLOR32
)
889 himl
->has_alpha
= heap_alloc_zero( himl
->cMaxImage
);
891 himl
->has_alpha
= NULL
;
893 /* create blending brushes */
894 hbmTemp
= CreateBitmap (8, 8, 1, 1, aBitBlend25
);
895 himl
->hbrBlend25
= CreatePatternBrush (hbmTemp
);
896 DeleteObject (hbmTemp
);
898 hbmTemp
= CreateBitmap (8, 8, 1, 1, aBitBlend50
);
899 himl
->hbrBlend50
= CreatePatternBrush (hbmTemp
);
900 DeleteObject (hbmTemp
);
902 TRACE("created imagelist %p\n", himl
);
906 ImageList_Destroy(himl
);
911 /*************************************************************************
912 * ImageList_Destroy [COMCTL32.@]
914 * Destroys an image list.
917 * himl [I] handle to image list
925 ImageList_Destroy (HIMAGELIST himl
)
930 IImageList_Release((IImageList
*) himl
);
935 /*************************************************************************
936 * ImageList_DragEnter [COMCTL32.@]
938 * Locks window update and displays the drag image at the given position.
941 * hwndLock [I] handle of the window that owns the drag image.
942 * x [I] X position of the drag image.
943 * y [I] Y position of the drag image.
950 * The position of the drag image is relative to the window, not
955 ImageList_DragEnter (HWND hwndLock
, INT x
, INT y
)
957 TRACE("(hwnd=%p x=%d y=%d)\n", hwndLock
, x
, y
);
959 if (!is_valid(InternalDrag
.himl
))
963 InternalDrag
.hwnd
= hwndLock
;
965 InternalDrag
.hwnd
= GetDesktopWindow ();
970 /* draw the drag image and save the background */
971 return ImageList_DragShowNolock(TRUE
);
975 /*************************************************************************
976 * ImageList_DragLeave [COMCTL32.@]
978 * Unlocks window update and hides the drag image.
981 * hwndLock [I] handle of the window that owns the drag image.
989 ImageList_DragLeave (HWND hwndLock
)
991 /* As we don't save drag info in the window this can lead to problems if
992 an app does not supply the same window as DragEnter */
994 InternalDrag.hwnd = hwndLock;
996 InternalDrag.hwnd = GetDesktopWindow (); */
998 hwndLock
= GetDesktopWindow();
999 if(InternalDrag
.hwnd
!= hwndLock
)
1000 FIXME("DragLeave hWnd != DragEnter hWnd\n");
1002 ImageList_DragShowNolock (FALSE
);
1008 /*************************************************************************
1009 * ImageList_InternalDragDraw [Internal]
1011 * Draws the drag image.
1014 * hdc [I] device context to draw into.
1015 * x [I] X position of the drag image.
1016 * y [I] Y position of the drag image.
1023 * The position of the drag image is relative to the window, not
1029 ImageList_InternalDragDraw (HDC hdc
, INT x
, INT y
)
1031 IMAGELISTDRAWPARAMS imldp
;
1033 ZeroMemory (&imldp
, sizeof(imldp
));
1034 imldp
.cbSize
= sizeof(imldp
);
1035 imldp
.himl
= InternalDrag
.himl
;
1040 imldp
.rgbBk
= CLR_DEFAULT
;
1041 imldp
.rgbFg
= CLR_DEFAULT
;
1042 imldp
.fStyle
= ILD_NORMAL
;
1043 imldp
.fState
= ILS_ALPHA
;
1045 ImageList_DrawIndirect (&imldp
);
1048 /*************************************************************************
1049 * ImageList_DragMove [COMCTL32.@]
1051 * Moves the drag image.
1054 * x [I] X position of the drag image.
1055 * y [I] Y position of the drag image.
1062 * The position of the drag image is relative to the window, not
1067 ImageList_DragMove (INT x
, INT y
)
1069 TRACE("(x=%d y=%d)\n", x
, y
);
1071 if (!is_valid(InternalDrag
.himl
))
1074 /* draw/update the drag image */
1075 if (InternalDrag
.bShow
) {
1079 HBITMAP hbmOffScreen
;
1080 INT origNewX
, origNewY
;
1081 INT origOldX
, origOldY
;
1082 INT origRegX
, origRegY
;
1083 INT sizeRegX
, sizeRegY
;
1086 /* calculate the update region */
1087 origNewX
= x
- InternalDrag
.dxHotspot
;
1088 origNewY
= y
- InternalDrag
.dyHotspot
;
1089 origOldX
= InternalDrag
.x
- InternalDrag
.dxHotspot
;
1090 origOldY
= InternalDrag
.y
- InternalDrag
.dyHotspot
;
1091 origRegX
= min(origNewX
, origOldX
);
1092 origRegY
= min(origNewY
, origOldY
);
1093 sizeRegX
= InternalDrag
.himl
->cx
+ abs(x
- InternalDrag
.x
);
1094 sizeRegY
= InternalDrag
.himl
->cy
+ abs(y
- InternalDrag
.y
);
1096 hdcDrag
= GetDCEx(InternalDrag
.hwnd
, 0,
1097 DCX_WINDOW
| DCX_CACHE
| DCX_LOCKWINDOWUPDATE
);
1098 hdcOffScreen
= CreateCompatibleDC(hdcDrag
);
1099 hdcBg
= CreateCompatibleDC(hdcDrag
);
1101 hbmOffScreen
= CreateCompatibleBitmap(hdcDrag
, sizeRegX
, sizeRegY
);
1102 SelectObject(hdcOffScreen
, hbmOffScreen
);
1103 SelectObject(hdcBg
, InternalDrag
.hbmBg
);
1105 /* get the actual background of the update region */
1106 BitBlt(hdcOffScreen
, 0, 0, sizeRegX
, sizeRegY
, hdcDrag
,
1107 origRegX
, origRegY
, SRCCOPY
);
1108 /* erase the old image */
1109 BitBlt(hdcOffScreen
, origOldX
- origRegX
, origOldY
- origRegY
,
1110 InternalDrag
.himl
->cx
, InternalDrag
.himl
->cy
, hdcBg
, 0, 0,
1112 /* save the background */
1113 BitBlt(hdcBg
, 0, 0, InternalDrag
.himl
->cx
, InternalDrag
.himl
->cy
,
1114 hdcOffScreen
, origNewX
- origRegX
, origNewY
- origRegY
, SRCCOPY
);
1115 /* draw the image */
1116 ImageList_InternalDragDraw(hdcOffScreen
, origNewX
- origRegX
,
1117 origNewY
- origRegY
);
1118 /* draw the update region to the screen */
1119 BitBlt(hdcDrag
, origRegX
, origRegY
, sizeRegX
, sizeRegY
,
1120 hdcOffScreen
, 0, 0, SRCCOPY
);
1123 DeleteDC(hdcOffScreen
);
1124 DeleteObject(hbmOffScreen
);
1125 ReleaseDC(InternalDrag
.hwnd
, hdcDrag
);
1128 /* update the image position */
1136 /*************************************************************************
1137 * ImageList_DragShowNolock [COMCTL32.@]
1139 * Shows or hides the drag image.
1142 * bShow [I] TRUE shows the drag image, FALSE hides it.
1150 ImageList_DragShowNolock (BOOL bShow
)
1156 if (!is_valid(InternalDrag
.himl
))
1159 TRACE("bShow=0x%X!\n", bShow
);
1161 /* DragImage is already visible/hidden */
1162 if ((InternalDrag
.bShow
&& bShow
) || (!InternalDrag
.bShow
&& !bShow
)) {
1166 /* position of the origin of the DragImage */
1167 x
= InternalDrag
.x
- InternalDrag
.dxHotspot
;
1168 y
= InternalDrag
.y
- InternalDrag
.dyHotspot
;
1170 hdcDrag
= GetDCEx (InternalDrag
.hwnd
, 0,
1171 DCX_WINDOW
| DCX_CACHE
| DCX_LOCKWINDOWUPDATE
);
1176 hdcBg
= CreateCompatibleDC(hdcDrag
);
1177 if (!InternalDrag
.hbmBg
) {
1178 InternalDrag
.hbmBg
= CreateCompatibleBitmap(hdcDrag
,
1179 InternalDrag
.himl
->cx
, InternalDrag
.himl
->cy
);
1181 SelectObject(hdcBg
, InternalDrag
.hbmBg
);
1184 /* save the background */
1185 BitBlt(hdcBg
, 0, 0, InternalDrag
.himl
->cx
, InternalDrag
.himl
->cy
,
1186 hdcDrag
, x
, y
, SRCCOPY
);
1187 /* show the image */
1188 ImageList_InternalDragDraw(hdcDrag
, x
, y
);
1190 /* hide the image */
1191 BitBlt(hdcDrag
, x
, y
, InternalDrag
.himl
->cx
, InternalDrag
.himl
->cy
,
1192 hdcBg
, 0, 0, SRCCOPY
);
1195 InternalDrag
.bShow
= !InternalDrag
.bShow
;
1198 ReleaseDC (InternalDrag
.hwnd
, hdcDrag
);
1203 /*************************************************************************
1204 * ImageList_Draw [COMCTL32.@]
1209 * himl [I] handle to image list
1211 * hdc [I] handle to device context
1214 * fStyle [I] drawing flags
1225 ImageList_Draw (HIMAGELIST himl
, INT i
, HDC hdc
, INT x
, INT y
, UINT fStyle
)
1227 return ImageList_DrawEx (himl
, i
, hdc
, x
, y
, 0, 0,
1228 CLR_DEFAULT
, CLR_DEFAULT
, fStyle
);
1232 /*************************************************************************
1233 * ImageList_DrawEx [COMCTL32.@]
1235 * Draws an image and allows using extended drawing features.
1238 * himl [I] handle to image list
1240 * hdc [I] handle to device context
1245 * rgbBk [I] background color
1246 * rgbFg [I] foreground color
1247 * fStyle [I] drawing flags
1254 * Calls ImageList_DrawIndirect.
1257 * ImageList_DrawIndirect.
1261 ImageList_DrawEx (HIMAGELIST himl
, INT i
, HDC hdc
, INT x
, INT y
,
1262 INT dx
, INT dy
, COLORREF rgbBk
, COLORREF rgbFg
,
1265 IMAGELISTDRAWPARAMS imldp
;
1267 ZeroMemory (&imldp
, sizeof(imldp
));
1268 imldp
.cbSize
= sizeof(imldp
);
1276 imldp
.rgbBk
= rgbBk
;
1277 imldp
.rgbFg
= rgbFg
;
1278 imldp
.fStyle
= fStyle
;
1280 return ImageList_DrawIndirect (&imldp
);
1284 static BOOL
alpha_blend_image( HIMAGELIST himl
, HDC srce_dc
, HDC dest_dc
, int dest_x
, int dest_y
,
1286 static BOOL
alpha_blend_image( HIMAGELIST himl
, HDC dest_dc
, int dest_x
, int dest_y
,
1288 int src_x
, int src_y
, int cx
, int cy
, BLENDFUNCTION func
,
1289 UINT style
, COLORREF blend_col
)
1293 HBITMAP bmp
= 0, mask
= 0;
1295 void *bits
, *mask_bits
;
1299 if (!(hdc
= CreateCompatibleDC( 0 ))) return FALSE
;
1300 if (!(info
= heap_alloc( FIELD_OFFSET( BITMAPINFO
, bmiColors
[256] )))) goto done
;
1301 info
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
1302 info
->bmiHeader
.biWidth
= cx
;
1303 info
->bmiHeader
.biHeight
= cy
;
1304 info
->bmiHeader
.biPlanes
= 1;
1305 info
->bmiHeader
.biBitCount
= 32;
1306 info
->bmiHeader
.biCompression
= BI_RGB
;
1307 info
->bmiHeader
.biSizeImage
= cx
* cy
* 4;
1308 info
->bmiHeader
.biXPelsPerMeter
= 0;
1309 info
->bmiHeader
.biYPelsPerMeter
= 0;
1310 info
->bmiHeader
.biClrUsed
= 0;
1311 info
->bmiHeader
.biClrImportant
= 0;
1313 if (!(bmp
= CreateDIBSection( srce_dc
, info
, DIB_RGB_COLORS
, &bits
, 0, 0 ))) goto done
;
1315 if (!(bmp
= CreateDIBSection( himl
->hdcImage
, info
, DIB_RGB_COLORS
, &bits
, 0, 0 ))) goto done
;
1317 SelectObject( hdc
, bmp
);
1319 if (!BitBlt( hdc
, 0, 0, cx
, cy
, srce_dc
, src_x
, src_y
, SRCCOPY
))
1321 TRACE("BitBlt failed\n");
1325 BitBlt( hdc
, 0, 0, cx
, cy
, himl
->hdcImage
, src_x
, src_y
, SRCCOPY
);
1328 if (blend_col
!= CLR_NONE
)
1330 BYTE r
= GetRValue( blend_col
);
1331 BYTE g
= GetGValue( blend_col
);
1332 BYTE b
= GetBValue( blend_col
);
1334 if (style
& ILD_BLEND25
)
1336 for (i
= 0, ptr
= bits
; i
< cx
* cy
; i
++, ptr
++)
1337 *ptr
= ((*ptr
& 0xff000000) |
1338 ((((*ptr
& 0x00ff0000) * 3 + (r
<< 16)) / 4) & 0x00ff0000) |
1339 ((((*ptr
& 0x0000ff00) * 3 + (g
<< 8)) / 4) & 0x0000ff00) |
1340 ((((*ptr
& 0x000000ff) * 3 + (b
<< 0)) / 4) & 0x000000ff));
1342 else if (style
& ILD_BLEND50
)
1344 for (i
= 0, ptr
= bits
; i
< cx
* cy
; i
++, ptr
++)
1345 *ptr
= ((*ptr
& 0xff000000) |
1346 ((((*ptr
& 0x00ff0000) + (r
<< 16)) / 2) & 0x00ff0000) |
1347 ((((*ptr
& 0x0000ff00) + (g
<< 8)) / 2) & 0x0000ff00) |
1348 ((((*ptr
& 0x000000ff) + (b
<< 0)) / 2) & 0x000000ff));
1352 if (himl
->has_alpha
) /* we already have an alpha channel in this case */
1354 /* pre-multiply by the alpha channel */
1355 for (i
= 0, ptr
= bits
; i
< cx
* cy
; i
++, ptr
++)
1357 DWORD alpha
= *ptr
>> 24;
1358 *ptr
= ((*ptr
& 0xff000000) |
1359 (((*ptr
& 0x00ff0000) * alpha
/ 255) & 0x00ff0000) |
1360 (((*ptr
& 0x0000ff00) * alpha
/ 255) & 0x0000ff00) |
1361 (((*ptr
& 0x000000ff) * alpha
/ 255)));
1364 else if (himl
->hbmMask
)
1366 unsigned int width_bytes
= (cx
+ 31) / 32 * 4;
1367 /* generate alpha channel from the mask */
1368 info
->bmiHeader
.biBitCount
= 1;
1369 info
->bmiHeader
.biSizeImage
= width_bytes
* cy
;
1370 info
->bmiColors
[0].rgbRed
= 0;
1371 info
->bmiColors
[0].rgbGreen
= 0;
1372 info
->bmiColors
[0].rgbBlue
= 0;
1373 info
->bmiColors
[0].rgbReserved
= 0;
1374 info
->bmiColors
[1].rgbRed
= 0xff;
1375 info
->bmiColors
[1].rgbGreen
= 0xff;
1376 info
->bmiColors
[1].rgbBlue
= 0xff;
1377 info
->bmiColors
[1].rgbReserved
= 0;
1378 if (!(mask
= CreateDIBSection( himl
->hdcMask
, info
, DIB_RGB_COLORS
, &mask_bits
, 0, 0 )))
1380 TRACE("CreateDIBSection failed %i\n", GetLastError());
1383 if (SelectObject(hdc
, mask
) == NULL
)
1385 TRACE("SelectObject failed %i\n", GetLastError());
1386 SelectObject(hdc
, bmp
);
1389 if (!BitBlt(hdc
, 0, 0, cx
, cy
, himl
->hdcMask
, src_x
, src_y
, SRCCOPY
))
1391 TRACE("BitBlt failed %i\n", GetLastError());
1392 SelectObject(hdc
, bmp
);
1395 if (SelectObject(hdc
, bmp
) == NULL
)
1397 TRACE("SelectObject failed %i\n", GetLastError());
1400 for (i
= 0, ptr
= bits
; i
< cy
; i
++)
1401 for (j
= 0; j
< cx
; j
++, ptr
++)
1402 if ((((BYTE
*)mask_bits
)[i
* width_bytes
+ j
/ 8] << (j
% 8)) & 0x80) *ptr
= 0;
1403 else *ptr
|= 0xff000000;
1406 ret
= GdiAlphaBlend( dest_dc
, dest_x
, dest_y
, cx
, cy
, hdc
, 0, 0, cx
, cy
, func
);
1410 if (bmp
) DeleteObject( bmp
);
1411 if (mask
) DeleteObject( mask
);
1417 HDC
saturate_image( HIMAGELIST himl
, HDC dest_dc
, int dest_x
, int dest_y
,
1418 int src_x
, int src_y
, int cx
, int cy
, COLORREF rgbFg
)
1428 /* create a dc and its device independent bitmap for doing the work,
1429 shamelessly copied from the alpha-blending function above */
1430 if (!(hdc
= CreateCompatibleDC( 0 ))) return FALSE
;
1431 if (!(info
= HeapAlloc( GetProcessHeap(), 0, FIELD_OFFSET( BITMAPINFO
, bmiColors
[256] )))) goto done
;
1432 info
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
1433 info
->bmiHeader
.biWidth
= cx
;
1434 info
->bmiHeader
.biHeight
= cy
;
1435 info
->bmiHeader
.biPlanes
= 1;
1436 info
->bmiHeader
.biBitCount
= 32;
1437 info
->bmiHeader
.biCompression
= BI_RGB
;
1438 info
->bmiHeader
.biSizeImage
= cx
* cy
* 4;
1439 info
->bmiHeader
.biXPelsPerMeter
= 0;
1440 info
->bmiHeader
.biYPelsPerMeter
= 0;
1441 info
->bmiHeader
.biClrUsed
= 0;
1442 info
->bmiHeader
.biClrImportant
= 0;
1443 if (!(bmp
= CreateDIBSection(himl
->hdcImage
, info
, DIB_RGB_COLORS
, &bits
, 0, 0 ))) goto done
;
1445 /* bind both surfaces */
1446 if (SelectObject(hdc
, bmp
) == NULL
)
1448 TRACE("SelectObject failed\n");
1452 /* copy into our dc the section that covers just the icon we we're asked for */
1453 if (!BitBlt(hdc
, 0, 0, cx
, cy
, himl
->hdcImage
, src_x
, src_y
, SRCCOPY
))
1455 TRACE("BitBlt failed!\n");
1459 /* loop every pixel of the bitmap */
1460 for (i
= 0, ptr
= bits
; i
< cx
* cy
; i
++, ptr
++)
1462 COLORREF orig_color
= *ptr
;
1464 /* calculate the effective luminance using the constants from here, adapted to the human eye:
1465 <http://bobpowell.net/grayscale.aspx> */
1466 float mixed_color
= (GetRValue(orig_color
) * .30 +
1467 GetGValue(orig_color
) * .59 +
1468 GetBValue(orig_color
) * .11);
1470 *ptr
= RGBA(mixed_color
, mixed_color
, mixed_color
, GetAValue(orig_color
));
1479 HeapFree(GetProcessHeap(), 0, info
);
1481 /* return the handle to our desaturated dc, that will substitute its original counterpart in the next calls */
1484 #endif /* __REACTOS__ */
1486 /*************************************************************************
1487 * ImageList_DrawIndirect [COMCTL32.@]
1489 * Draws an image using various parameters specified in pimldp.
1492 * pimldp [I] pointer to IMAGELISTDRAWPARAMS structure.
1500 ImageList_DrawIndirect (IMAGELISTDRAWPARAMS
*pimldp
)
1502 INT cx
, cy
, nOvlIdx
;
1503 DWORD fState
, dwRop
;
1505 COLORREF oldImageBk
, oldImageFg
;
1506 HDC hImageDC
, hImageListDC
, hMaskListDC
;
1507 HBITMAP hImageBmp
, hOldImageBmp
, hBlendMaskBmp
;
1508 BOOL bIsTransparent
, bBlend
, bResult
= FALSE
, bMask
;
1514 HDC hdcSaturated
= NULL
;
1517 if (!pimldp
|| !(himl
= pimldp
->himl
)) return FALSE
;
1518 if (!is_valid(himl
)) return FALSE
;
1519 if ((pimldp
->i
< 0) || (pimldp
->i
>= himl
->cCurImage
)) return FALSE
;
1521 imagelist_point_from_index( himl
, pimldp
->i
, &pt
);
1522 pt
.x
+= pimldp
->xBitmap
;
1523 pt
.y
+= pimldp
->yBitmap
;
1525 fState
= pimldp
->cbSize
< sizeof(IMAGELISTDRAWPARAMS
) ? ILS_NORMAL
: pimldp
->fState
;
1526 fStyle
= pimldp
->fStyle
& ~ILD_OVERLAYMASK
;
1527 cx
= (pimldp
->cx
== 0) ? himl
->cx
: pimldp
->cx
;
1528 cy
= (pimldp
->cy
== 0) ? himl
->cy
: pimldp
->cy
;
1530 bIsTransparent
= (fStyle
& ILD_TRANSPARENT
);
1531 if( pimldp
->rgbBk
== CLR_NONE
)
1532 bIsTransparent
= TRUE
;
1533 if( ( pimldp
->rgbBk
== CLR_DEFAULT
) && ( himl
->clrBk
== CLR_NONE
) )
1534 bIsTransparent
= TRUE
;
1535 bMask
= (himl
->flags
& ILC_MASK
) && (fStyle
& ILD_MASK
) ;
1536 bBlend
= (fStyle
& (ILD_BLEND25
| ILD_BLEND50
) ) && !bMask
;
1538 TRACE("himl(%p) hbmMask(%p) iImage(%d) x(%d) y(%d) cx(%d) cy(%d)\n",
1539 himl
, himl
->hbmMask
, pimldp
->i
, pimldp
->x
, pimldp
->y
, cx
, cy
);
1541 /* we will use these DCs to access the images and masks in the ImageList */
1542 hImageListDC
= himl
->hdcImage
;
1543 hMaskListDC
= himl
->hdcMask
;
1545 /* these will accumulate the image and mask for the image we're drawing */
1546 hImageDC
= CreateCompatibleDC( pimldp
->hdcDst
);
1547 hImageBmp
= CreateCompatibleBitmap( pimldp
->hdcDst
, cx
, cy
);
1548 hBlendMaskBmp
= bBlend
? CreateBitmap(cx
, cy
, 1, 1, NULL
) : 0;
1550 /* Create a compatible DC. */
1551 if (!hImageListDC
|| !hImageDC
|| !hImageBmp
||
1552 (bBlend
&& !hBlendMaskBmp
) || (himl
->hbmMask
&& !hMaskListDC
))
1555 hOldImageBmp
= SelectObject(hImageDC
, hImageBmp
);
1558 * To obtain a transparent look, background color should be set
1559 * to white and foreground color to black when blitting the
1562 oldImageFg
= SetTextColor( hImageDC
, RGB( 0, 0, 0 ) );
1563 oldImageBk
= SetBkColor( hImageDC
, RGB( 0xff, 0xff, 0xff ) );
1567 * If the ILS_SATURATE bit is enabled we should multiply the
1568 * RGB colors of the original image by the contents of rgbFg.
1570 if (fState
& ILS_SATURATE
)
1572 hdcSaturated
= saturate_image(himl
, pimldp
->hdcDst
, pimldp
->x
, pimldp
->y
,
1573 pt
.x
, pt
.y
, cx
, cy
, pimldp
->rgbFg
);
1575 if (hdcSaturated
!= NULL
)
1577 hImageListDC
= hdcSaturated
;
1578 /* shitty way of getting subroutines to blit at the right place (top left corner),
1579 as our modified imagelist only contains a single image for performance reasons */
1586 has_alpha
= (himl
->has_alpha
&& himl
->has_alpha
[pimldp
->i
]);
1587 if (!bMask
&& (has_alpha
|| (fState
& ILS_ALPHA
)))
1589 COLORREF colour
, blend_col
= CLR_NONE
;
1594 blend_col
= pimldp
->rgbFg
;
1595 if (blend_col
== CLR_DEFAULT
) blend_col
= GetSysColor( COLOR_HIGHLIGHT
);
1596 else if (blend_col
== CLR_NONE
) blend_col
= GetTextColor( pimldp
->hdcDst
);
1599 func
.BlendOp
= AC_SRC_OVER
;
1600 func
.BlendFlags
= 0;
1601 func
.SourceConstantAlpha
= (fState
& ILS_ALPHA
) ? pimldp
->Frame
: 255;
1602 func
.AlphaFormat
= AC_SRC_ALPHA
;
1607 bResult
= alpha_blend_image( himl
, hImageListDC
, pimldp
->hdcDst
, pimldp
->x
, pimldp
->y
,
1609 bResult
= alpha_blend_image( himl
, pimldp
->hdcDst
, pimldp
->x
, pimldp
->y
,
1611 pt
.x
, pt
.y
, cx
, cy
, func
, fStyle
, blend_col
);
1614 colour
= pimldp
->rgbBk
;
1615 if (colour
== CLR_DEFAULT
) colour
= himl
->clrBk
;
1616 if (colour
== CLR_NONE
) colour
= GetBkColor( pimldp
->hdcDst
);
1618 hOldBrush
= SelectObject (hImageDC
, CreateSolidBrush (colour
));
1619 PatBlt( hImageDC
, 0, 0, cx
, cy
, PATCOPY
);
1621 alpha_blend_image( himl
, hImageListDC
, hImageDC
, 0, 0, pt
.x
, pt
.y
, cx
, cy
, func
, fStyle
, blend_col
);
1623 alpha_blend_image( himl
, hImageDC
, 0, 0, pt
.x
, pt
.y
, cx
, cy
, func
, fStyle
, blend_col
);
1625 DeleteObject (SelectObject (hImageDC
, hOldBrush
));
1626 bResult
= BitBlt( pimldp
->hdcDst
, pimldp
->x
, pimldp
->y
, cx
, cy
, hImageDC
, 0, 0, SRCCOPY
);
1631 * Draw the initial image
1634 if (himl
->hbmMask
) {
1635 hOldBrush
= SelectObject (hImageDC
, CreateSolidBrush (GetTextColor(pimldp
->hdcDst
)));
1636 PatBlt( hImageDC
, 0, 0, cx
, cy
, PATCOPY
);
1637 BitBlt(hImageDC
, 0, 0, cx
, cy
, hMaskListDC
, pt
.x
, pt
.y
, SRCPAINT
);
1638 DeleteObject (SelectObject (hImageDC
, hOldBrush
));
1639 if( bIsTransparent
)
1641 BitBlt ( pimldp
->hdcDst
, pimldp
->x
, pimldp
->y
, cx
, cy
, hImageDC
, 0, 0, SRCAND
);
1646 hOldBrush
= SelectObject (hImageDC
, GetStockObject(BLACK_BRUSH
));
1647 PatBlt( hImageDC
, 0, 0, cx
, cy
, PATCOPY
);
1648 SelectObject(hImageDC
, hOldBrush
);
1651 /* blend the image with the needed solid background */
1652 COLORREF colour
= RGB(0,0,0);
1654 if( !bIsTransparent
)
1656 colour
= pimldp
->rgbBk
;
1657 if( colour
== CLR_DEFAULT
)
1658 colour
= himl
->clrBk
;
1659 if( colour
== CLR_NONE
)
1660 colour
= GetBkColor(pimldp
->hdcDst
);
1663 hOldBrush
= SelectObject (hImageDC
, CreateSolidBrush (colour
));
1664 PatBlt( hImageDC
, 0, 0, cx
, cy
, PATCOPY
);
1667 BitBlt( hImageDC
, 0, 0, cx
, cy
, hMaskListDC
, pt
.x
, pt
.y
, SRCAND
);
1668 BitBlt( hImageDC
, 0, 0, cx
, cy
, hImageListDC
, pt
.x
, pt
.y
, SRCPAINT
);
1671 BitBlt( hImageDC
, 0, 0, cx
, cy
, hImageListDC
, pt
.x
, pt
.y
, SRCCOPY
);
1672 DeleteObject (SelectObject (hImageDC
, hOldBrush
));
1675 /* Time for blending, if required */
1678 COLORREF clrBlend
= pimldp
->rgbFg
;
1679 HDC hBlendMaskDC
= hImageListDC
;
1682 /* Create the blend Mask */
1683 hOldBitmap
= SelectObject(hBlendMaskDC
, hBlendMaskBmp
);
1684 hBlendBrush
= fStyle
& ILD_BLEND50
? himl
->hbrBlend50
: himl
->hbrBlend25
;
1685 hOldBrush
= SelectObject(hBlendMaskDC
, hBlendBrush
);
1686 PatBlt(hBlendMaskDC
, 0, 0, cx
, cy
, PATCOPY
);
1687 SelectObject(hBlendMaskDC
, hOldBrush
);
1689 /* Modify the blend mask if an Image Mask exist */
1691 BitBlt(hBlendMaskDC
, 0, 0, cx
, cy
, hMaskListDC
, pt
.x
, pt
.y
, 0x220326); /* NOTSRCAND */
1692 BitBlt(hBlendMaskDC
, 0, 0, cx
, cy
, hBlendMaskDC
, 0, 0, NOTSRCCOPY
);
1695 /* now apply blend to the current image given the BlendMask */
1696 if (clrBlend
== CLR_DEFAULT
) clrBlend
= GetSysColor (COLOR_HIGHLIGHT
);
1697 else if (clrBlend
== CLR_NONE
) clrBlend
= GetTextColor (pimldp
->hdcDst
);
1698 hOldBrush
= SelectObject (hImageDC
, CreateSolidBrush(clrBlend
));
1699 BitBlt (hImageDC
, 0, 0, cx
, cy
, hBlendMaskDC
, 0, 0, 0xB8074A); /* PSDPxax */
1700 DeleteObject(SelectObject(hImageDC
, hOldBrush
));
1701 SelectObject(hBlendMaskDC
, hOldBitmap
);
1704 /* Now do the overlay image, if any */
1705 nOvlIdx
= (pimldp
->fStyle
& ILD_OVERLAYMASK
) >> 8;
1706 if ( (nOvlIdx
>= 1) && (nOvlIdx
<= MAX_OVERLAYIMAGE
)) {
1707 nOvlIdx
= himl
->nOvlIdx
[nOvlIdx
- 1];
1708 if ((nOvlIdx
>= 0) && (nOvlIdx
< himl
->cCurImage
)) {
1710 imagelist_point_from_index( himl
, nOvlIdx
, &ptOvl
);
1711 ptOvl
.x
+= pimldp
->xBitmap
;
1712 if (himl
->hbmMask
&& !(fStyle
& ILD_IMAGE
))
1713 BitBlt (hImageDC
, 0, 0, cx
, cy
, hMaskListDC
, ptOvl
.x
, ptOvl
.y
, SRCAND
);
1714 BitBlt (hImageDC
, 0, 0, cx
, cy
, hImageListDC
, ptOvl
.x
, ptOvl
.y
, SRCPAINT
);
1719 if (fState
& ILS_SATURATE
) FIXME("ILS_SATURATE: unimplemented!\n");
1721 if (fState
& ILS_GLOW
) FIXME("ILS_GLOW: unimplemented!\n");
1722 if (fState
& ILS_SHADOW
) FIXME("ILS_SHADOW: unimplemented!\n");
1724 if (fStyle
& ILD_PRESERVEALPHA
) FIXME("ILD_PRESERVEALPHA: unimplemented!\n");
1725 if (fStyle
& ILD_SCALE
) FIXME("ILD_SCALE: unimplemented!\n");
1726 if (fStyle
& ILD_DPISCALE
) FIXME("ILD_DPISCALE: unimplemented!\n");
1728 /* now copy the image to the screen */
1730 if (himl
->hbmMask
&& bIsTransparent
) {
1731 COLORREF oldDstFg
= SetTextColor(pimldp
->hdcDst
, RGB( 0, 0, 0 ) );
1732 COLORREF oldDstBk
= SetBkColor(pimldp
->hdcDst
, RGB( 0xff, 0xff, 0xff ));
1733 BitBlt (pimldp
->hdcDst
, pimldp
->x
, pimldp
->y
, cx
, cy
, hMaskListDC
, pt
.x
, pt
.y
, SRCAND
);
1734 SetBkColor(pimldp
->hdcDst
, oldDstBk
);
1735 SetTextColor(pimldp
->hdcDst
, oldDstFg
);
1738 if (fStyle
& ILD_ROP
) dwRop
= pimldp
->dwRop
;
1739 BitBlt (pimldp
->hdcDst
, pimldp
->x
, pimldp
->y
, cx
, cy
, hImageDC
, 0, 0, dwRop
);
1743 /* cleanup the mess */
1744 SetBkColor(hImageDC
, oldImageBk
);
1745 SetTextColor(hImageDC
, oldImageFg
);
1746 SelectObject(hImageDC
, hOldImageBmp
);
1750 DeleteDC(hdcSaturated
);
1752 DeleteObject(hBlendMaskBmp
);
1753 DeleteObject(hImageBmp
);
1760 /*************************************************************************
1761 * ImageList_Duplicate [COMCTL32.@]
1763 * Duplicates an image list.
1766 * himlSrc [I] source image list handle
1769 * Success: Handle of duplicated image list.
1774 ImageList_Duplicate (HIMAGELIST himlSrc
)
1778 if (!is_valid(himlSrc
)) {
1779 ERR("Invalid image list handle!\n");
1783 himlDst
= ImageList_Create (himlSrc
->cx
, himlSrc
->cy
, himlSrc
->flags
,
1784 himlSrc
->cCurImage
, himlSrc
->cGrow
);
1790 imagelist_get_bitmap_size(himlSrc
, himlSrc
->cCurImage
, &sz
);
1791 BitBlt (himlDst
->hdcImage
, 0, 0, sz
.cx
, sz
.cy
,
1792 himlSrc
->hdcImage
, 0, 0, SRCCOPY
);
1794 if (himlDst
->hbmMask
)
1795 BitBlt (himlDst
->hdcMask
, 0, 0, sz
.cx
, sz
.cy
,
1796 himlSrc
->hdcMask
, 0, 0, SRCCOPY
);
1798 himlDst
->cCurImage
= himlSrc
->cCurImage
;
1799 if (himlSrc
->has_alpha
&& himlDst
->has_alpha
)
1800 memcpy( himlDst
->has_alpha
, himlSrc
->has_alpha
, himlDst
->cCurImage
);
1806 /*************************************************************************
1807 * ImageList_EndDrag [COMCTL32.@]
1809 * Finishes a drag operation.
1820 ImageList_EndDrag (void)
1822 /* cleanup the InternalDrag struct */
1823 InternalDrag
.hwnd
= 0;
1824 if (InternalDrag
.himl
!= InternalDrag
.himlNoCursor
)
1825 ImageList_Destroy (InternalDrag
.himlNoCursor
);
1826 ImageList_Destroy (InternalDrag
.himl
);
1827 InternalDrag
.himlNoCursor
= InternalDrag
.himl
= 0;
1830 InternalDrag
.dxHotspot
= 0;
1831 InternalDrag
.dyHotspot
= 0;
1832 InternalDrag
.bShow
= FALSE
;
1833 DeleteObject(InternalDrag
.hbmBg
);
1834 InternalDrag
.hbmBg
= 0;
1838 /*************************************************************************
1839 * ImageList_GetBkColor [COMCTL32.@]
1841 * Returns the background color of an image list.
1844 * himl [I] Image list handle.
1847 * Success: background color
1852 ImageList_GetBkColor (HIMAGELIST himl
)
1854 return himl
? himl
->clrBk
: CLR_NONE
;
1858 /*************************************************************************
1859 * ImageList_GetDragImage [COMCTL32.@]
1861 * Returns the handle to the internal drag image list.
1864 * ppt [O] Pointer to the drag position. Can be NULL.
1865 * pptHotspot [O] Pointer to the position of the hot spot. Can be NULL.
1868 * Success: Handle of the drag image list.
1873 ImageList_GetDragImage (POINT
*ppt
, POINT
*pptHotspot
)
1875 if (is_valid(InternalDrag
.himl
)) {
1877 ppt
->x
= InternalDrag
.x
;
1878 ppt
->y
= InternalDrag
.y
;
1881 pptHotspot
->x
= InternalDrag
.dxHotspot
;
1882 pptHotspot
->y
= InternalDrag
.dyHotspot
;
1884 return (InternalDrag
.himl
);
1891 /*************************************************************************
1892 * ImageList_GetFlags [COMCTL32.@]
1894 * Gets the flags of the specified image list.
1897 * himl [I] Handle to image list
1907 ImageList_GetFlags(HIMAGELIST himl
)
1909 TRACE("%p\n", himl
);
1911 if(!is_valid2(himl
))
1915 return is_valid(himl
) ? himl
->flags
: 0;
1920 /*************************************************************************
1921 * ImageList_GetIcon [COMCTL32.@]
1923 * Creates an icon from a masked image of an image list.
1926 * himl [I] handle to image list
1928 * flags [I] drawing style flags
1931 * Success: icon handle
1936 ImageList_GetIcon (HIMAGELIST himl
, INT i
, UINT fStyle
)
1940 HBITMAP hOldDstBitmap
;
1944 TRACE("%p %d %d\n", himl
, i
, fStyle
);
1945 if (!is_valid(himl
) || (i
< 0) || (i
>= himl
->cCurImage
)) return NULL
;
1951 /* create colour bitmap */
1953 ii
.hbmColor
= CreateCompatibleBitmap(hdcDst
, himl
->cx
, himl
->cy
);
1954 ReleaseDC(0, hdcDst
);
1956 hdcDst
= CreateCompatibleDC(0);
1958 imagelist_point_from_index( himl
, i
, &pt
);
1961 ii
.hbmMask
= CreateBitmap (himl
->cx
, himl
->cy
, 1, 1, NULL
);
1962 hOldDstBitmap
= SelectObject (hdcDst
, ii
.hbmMask
);
1963 if (himl
->hbmMask
) {
1964 BitBlt (hdcDst
, 0, 0, himl
->cx
, himl
->cy
,
1965 himl
->hdcMask
, pt
.x
, pt
.y
, SRCCOPY
);
1968 PatBlt (hdcDst
, 0, 0, himl
->cx
, himl
->cy
, BLACKNESS
);
1971 SelectObject (hdcDst
, ii
.hbmColor
);
1972 BitBlt (hdcDst
, 0, 0, himl
->cx
, himl
->cy
,
1973 himl
->hdcImage
, pt
.x
, pt
.y
, SRCCOPY
);
1976 * CreateIconIndirect requires us to deselect the bitmaps from
1977 * the DCs before calling
1979 SelectObject(hdcDst
, hOldDstBitmap
);
1981 hIcon
= CreateIconIndirect (&ii
);
1983 DeleteObject (ii
.hbmMask
);
1984 DeleteObject (ii
.hbmColor
);
1991 /*************************************************************************
1992 * ImageList_GetIconSize [COMCTL32.@]
1994 * Retrieves the size of an image in an image list.
1997 * himl [I] handle to image list
1998 * cx [O] pointer to the image width.
1999 * cy [O] pointer to the image height.
2006 * All images in an image list have the same size.
2010 ImageList_GetIconSize (HIMAGELIST himl
, INT
*cx
, INT
*cy
)
2012 if (!is_valid(himl
) || !cx
|| !cy
)
2022 /*************************************************************************
2023 * ImageList_GetImageCount [COMCTL32.@]
2025 * Returns the number of images in an image list.
2028 * himl [I] handle to image list
2031 * Success: Number of images.
2036 ImageList_GetImageCount (HIMAGELIST himl
)
2038 if (!is_valid(himl
))
2041 return himl
->cCurImage
;
2045 /*************************************************************************
2046 * ImageList_GetImageInfo [COMCTL32.@]
2048 * Returns information about an image in an image list.
2051 * himl [I] handle to image list
2053 * pImageInfo [O] pointer to the image information
2061 ImageList_GetImageInfo (HIMAGELIST himl
, INT i
, IMAGEINFO
*pImageInfo
)
2065 if (!is_valid(himl
) || (pImageInfo
== NULL
))
2067 if ((i
< 0) || (i
>= himl
->cCurImage
))
2070 pImageInfo
->hbmImage
= himl
->hbmImage
;
2071 pImageInfo
->hbmMask
= himl
->hbmMask
;
2073 imagelist_point_from_index( himl
, i
, &pt
);
2074 pImageInfo
->rcImage
.top
= pt
.y
;
2075 pImageInfo
->rcImage
.bottom
= pt
.y
+ himl
->cy
;
2076 pImageInfo
->rcImage
.left
= pt
.x
;
2077 pImageInfo
->rcImage
.right
= pt
.x
+ himl
->cx
;
2083 /*************************************************************************
2084 * ImageList_GetImageRect [COMCTL32.@]
2086 * Retrieves the rectangle of the specified image in an image list.
2089 * himl [I] handle to image list
2091 * lpRect [O] pointer to the image rectangle
2098 * This is an UNDOCUMENTED function!!!
2102 ImageList_GetImageRect (HIMAGELIST himl
, INT i
, LPRECT lpRect
)
2105 IMAGEINFO ImageInfo
;
2106 if (!ImageList_GetImageInfo(himl
, i
, &ImageInfo
))
2108 *lpRect
= ImageInfo
.rcImage
;
2112 if (!is_valid(himl
) || (lpRect
== NULL
))
2114 if ((i
< 0) || (i
>= himl
->cCurImage
))
2117 imagelist_point_from_index( himl
, i
, &pt
);
2118 lpRect
->left
= pt
.x
;
2120 lpRect
->right
= pt
.x
+ himl
->cx
;
2121 lpRect
->bottom
= pt
.y
+ himl
->cy
;
2127 /*************************************************************************
2128 * ImageList_LoadImage [COMCTL32.@]
2129 * ImageList_LoadImageA [COMCTL32.@]
2131 * Creates an image list from a bitmap, icon or cursor.
2133 * See ImageList_LoadImageW.
2137 ImageList_LoadImageA (HINSTANCE hi
, LPCSTR lpbmp
, INT cx
, INT cGrow
,
2138 COLORREF clrMask
, UINT uType
, UINT uFlags
)
2144 if (IS_INTRESOURCE(lpbmp
))
2145 return ImageList_LoadImageW(hi
, (LPCWSTR
)lpbmp
, cx
, cGrow
, clrMask
,
2148 len
= MultiByteToWideChar(CP_ACP
, 0, lpbmp
, -1, NULL
, 0);
2149 lpbmpW
= heap_alloc(len
* sizeof(WCHAR
));
2150 MultiByteToWideChar(CP_ACP
, 0, lpbmp
, -1, lpbmpW
, len
);
2152 himl
= ImageList_LoadImageW(hi
, lpbmpW
, cx
, cGrow
, clrMask
, uType
, uFlags
);
2158 /*************************************************************************
2159 * ImageList_LoadImageW [COMCTL32.@]
2161 * Creates an image list from a bitmap, icon or cursor.
2164 * hi [I] instance handle
2165 * lpbmp [I] name or id of the image
2166 * cx [I] width of each image
2167 * cGrow [I] number of images to expand
2168 * clrMask [I] mask color
2169 * uType [I] type of image to load
2170 * uFlags [I] loading flags
2173 * Success: handle to the loaded image list
2181 ImageList_LoadImageW (HINSTANCE hi
, LPCWSTR lpbmp
, INT cx
, INT cGrow
,
2182 COLORREF clrMask
, UINT uType
, UINT uFlags
)
2184 HIMAGELIST himl
= NULL
;
2188 handle
= LoadImageW (hi
, lpbmp
, uType
, 0, 0, uFlags
);
2190 WARN("Couldn't load image\n");
2194 if (uType
== IMAGE_BITMAP
) {
2198 if (GetObjectW (handle
, sizeof(dib
), &dib
) == sizeof(BITMAP
)) color
= ILC_COLOR
;
2199 else color
= dib
.dsBm
.bmBitsPixel
;
2201 /* To match windows behavior, if cx is set to zero and
2202 the flag DI_DEFAULTSIZE is specified, cx becomes the
2203 system metric value for icons. If the flag is not specified
2204 the function sets the size to the height of the bitmap */
2207 if (uFlags
& DI_DEFAULTSIZE
)
2208 cx
= GetSystemMetrics (SM_CXICON
);
2210 cx
= dib
.dsBm
.bmHeight
;
2213 nImageCount
= dib
.dsBm
.bmWidth
/ cx
;
2215 if (clrMask
!= CLR_NONE
) color
|= ILC_MASK
;
2216 himl
= ImageList_Create (cx
, dib
.dsBm
.bmHeight
, color
, nImageCount
, cGrow
);
2218 DeleteObject (handle
);
2221 ImageList_AddMasked (himl
, handle
, clrMask
);
2223 else if ((uType
== IMAGE_ICON
) || (uType
== IMAGE_CURSOR
)) {
2227 GetIconInfo (handle
, &ii
);
2228 GetObjectW (ii
.hbmColor
, sizeof(BITMAP
), &bmp
);
2229 himl
= ImageList_Create (bmp
.bmWidth
, bmp
.bmHeight
,
2230 ILC_MASK
| ILC_COLOR
, 1, cGrow
);
2232 DeleteObject (ii
.hbmColor
);
2233 DeleteObject (ii
.hbmMask
);
2234 DeleteObject (handle
);
2237 ImageList_Add (himl
, ii
.hbmColor
, ii
.hbmMask
);
2238 DeleteObject (ii
.hbmColor
);
2239 DeleteObject (ii
.hbmMask
);
2242 DeleteObject (handle
);
2248 /*************************************************************************
2249 * ImageList_Merge [COMCTL32.@]
2251 * Create an image list containing a merged image from two image lists.
2254 * himl1 [I] handle to first image list
2255 * i1 [I] first image index
2256 * himl2 [I] handle to second image list
2257 * i2 [I] second image index
2258 * dx [I] X offset of the second image relative to the first.
2259 * dy [I] Y offset of the second image relative to the first.
2262 * Success: The newly created image list. It contains a single image
2263 * consisting of the second image merged with the first.
2264 * Failure: NULL, if either himl1 or himl2 is invalid.
2267 * - The returned image list should be deleted by the caller using
2268 * ImageList_Destroy() when it is no longer required.
2269 * - If either i1 or i2 is not a valid image index, they will be treated
2273 ImageList_Merge (HIMAGELIST himl1
, INT i1
, HIMAGELIST himl2
, INT i2
,
2276 HIMAGELIST himlDst
= NULL
;
2278 INT xOff1
, yOff1
, xOff2
, yOff2
;
2282 TRACE("(himl1=%p i1=%d himl2=%p i2=%d dx=%d dy=%d)\n", himl1
, i1
, himl2
,
2285 if (!is_valid(himl1
) || !is_valid(himl2
))
2289 cxDst
= max (himl1
->cx
, dx
+ himl2
->cx
);
2294 cxDst
= max (himl2
->cx
, himl1
->cx
- dx
);
2299 cxDst
= max (himl1
->cx
, himl2
->cx
);
2305 cyDst
= max (himl1
->cy
, dy
+ himl2
->cy
);
2310 cyDst
= max (himl2
->cy
, himl1
->cy
- dy
);
2315 cyDst
= max (himl1
->cy
, himl2
->cy
);
2320 newFlags
= (himl1
->flags
> himl2
->flags
? himl1
->flags
: himl2
->flags
) & ILC_COLORDDB
;
2321 if (newFlags
== ILC_COLORDDB
&& (himl1
->flags
& ILC_COLORDDB
) == ILC_COLOR16
)
2322 newFlags
= ILC_COLOR16
; /* this is what native (at least v5) does, don't know why */
2323 himlDst
= ImageList_Create (cxDst
, cyDst
, ILC_MASK
| newFlags
, 1, 1);
2327 imagelist_point_from_index( himl1
, i1
, &pt1
);
2328 imagelist_point_from_index( himl2
, i2
, &pt2
);
2331 BitBlt (himlDst
->hdcImage
, 0, 0, cxDst
, cyDst
, himl1
->hdcImage
, 0, 0, BLACKNESS
);
2332 if (i1
>= 0 && i1
< himl1
->cCurImage
)
2333 BitBlt (himlDst
->hdcImage
, xOff1
, yOff1
, himl1
->cx
, himl1
->cy
, himl1
->hdcImage
, pt1
.x
, pt1
.y
, SRCCOPY
);
2334 if (i2
>= 0 && i2
< himl2
->cCurImage
)
2336 if (himl2
->flags
& ILC_MASK
)
2338 BitBlt (himlDst
->hdcImage
, xOff2
, yOff2
, himl2
->cx
, himl2
->cy
, himl2
->hdcMask
, pt2
.x
, pt2
.y
, SRCAND
);
2339 BitBlt (himlDst
->hdcImage
, xOff2
, yOff2
, himl2
->cx
, himl2
->cy
, himl2
->hdcImage
, pt2
.x
, pt2
.y
, SRCPAINT
);
2342 BitBlt (himlDst
->hdcImage
, xOff2
, yOff2
, himl2
->cx
, himl2
->cy
, himl2
->hdcImage
, pt2
.x
, pt2
.y
, SRCCOPY
);
2346 BitBlt (himlDst
->hdcMask
, 0, 0, cxDst
, cyDst
, himl1
->hdcMask
, 0, 0, WHITENESS
);
2347 if (i1
>= 0 && i1
< himl1
->cCurImage
)
2348 BitBlt (himlDst
->hdcMask
, xOff1
, yOff1
, himl1
->cx
, himl1
->cy
, himl1
->hdcMask
, pt1
.x
, pt1
.y
, SRCCOPY
);
2349 if (i2
>= 0 && i2
< himl2
->cCurImage
)
2350 BitBlt (himlDst
->hdcMask
, xOff2
, yOff2
, himl2
->cx
, himl2
->cy
, himl2
->hdcMask
, pt2
.x
, pt2
.y
, SRCAND
);
2352 himlDst
->cCurImage
= 1;
2359 /* helper for ImageList_Read, see comments below */
2360 static void *read_bitmap(IStream
*pstm
, BITMAPINFO
*bmi
)
2362 BITMAPFILEHEADER bmfh
;
2363 int bitsperpixel
, palspace
;
2366 if (FAILED(IStream_Read ( pstm
, &bmfh
, sizeof(bmfh
), NULL
)))
2369 if (bmfh
.bfType
!= (('M'<<8)|'B'))
2372 if (FAILED(IStream_Read ( pstm
, &bmi
->bmiHeader
, sizeof(bmi
->bmiHeader
), NULL
)))
2375 if ((bmi
->bmiHeader
.biSize
!= sizeof(bmi
->bmiHeader
)))
2378 TRACE("width %u, height %u, planes %u, bpp %u\n",
2379 bmi
->bmiHeader
.biWidth
, bmi
->bmiHeader
.biHeight
,
2380 bmi
->bmiHeader
.biPlanes
, bmi
->bmiHeader
.biBitCount
);
2382 bitsperpixel
= bmi
->bmiHeader
.biPlanes
* bmi
->bmiHeader
.biBitCount
;
2383 if (bitsperpixel
<=8)
2384 palspace
= (1<<bitsperpixel
)*sizeof(RGBQUAD
);
2388 bmi
->bmiHeader
.biSizeImage
= get_dib_image_size( bmi
);
2390 /* read the palette right after the end of the bitmapinfoheader */
2391 if (palspace
&& FAILED(IStream_Read(pstm
, bmi
->bmiColors
, palspace
, NULL
)))
2394 bits
= heap_alloc_zero(bmi
->bmiHeader
.biSizeImage
);
2395 if (!bits
) return NULL
;
2397 if (FAILED(IStream_Read(pstm
, bits
, bmi
->bmiHeader
.biSizeImage
, NULL
)))
2405 /*************************************************************************
2406 * ImageList_Read [COMCTL32.@]
2408 * Reads an image list from a stream.
2411 * pstm [I] pointer to a stream
2414 * Success: handle to image list
2417 * The format is like this:
2418 * ILHEAD ilheadstruct;
2420 * for the color image part:
2421 * BITMAPFILEHEADER bmfh;
2422 * BITMAPINFOHEADER bmih;
2423 * only if it has a palette:
2424 * RGBQUAD rgbs[nr_of_paletted_colors];
2426 * BYTE colorbits[imagesize];
2428 * the following only if the ILC_MASK bit is set in ILHEAD.ilFlags:
2429 * BITMAPFILEHEADER bmfh_mask;
2430 * BITMAPINFOHEADER bmih_mask;
2431 * only if it has a palette (it usually does not):
2432 * RGBQUAD rgbs[nr_of_paletted_colors];
2434 * BYTE maskbits[imagesize];
2436 HIMAGELIST WINAPI
ImageList_Read(IStream
*pstm
)
2438 char image_buf
[sizeof(BITMAPINFOHEADER
) + sizeof(RGBQUAD
) * 256];
2439 char mask_buf
[sizeof(BITMAPINFOHEADER
) + sizeof(RGBQUAD
) * 256];
2440 BITMAPINFO
*image_info
= (BITMAPINFO
*)image_buf
;
2441 BITMAPINFO
*mask_info
= (BITMAPINFO
*)mask_buf
;
2442 void *image_bits
, *mask_bits
= NULL
;
2447 TRACE("%p\n", pstm
);
2449 if (FAILED(IStream_Read (pstm
, &ilHead
, sizeof(ILHEAD
), NULL
)))
2451 if (ilHead
.usMagic
!= (('L' << 8) | 'I'))
2453 if (ilHead
.usVersion
!= 0x101) /* probably version? */
2456 TRACE("cx %u, cy %u, flags 0x%04x, cCurImage %u, cMaxImage %u\n",
2457 ilHead
.cx
, ilHead
.cy
, ilHead
.flags
, ilHead
.cCurImage
, ilHead
.cMaxImage
);
2459 himl
= ImageList_Create(ilHead
.cx
, ilHead
.cy
, ilHead
.flags
, ilHead
.cCurImage
, ilHead
.cMaxImage
);
2463 if (!(image_bits
= read_bitmap(pstm
, image_info
)))
2465 WARN("failed to read bitmap from stream\n");
2468 if (ilHead
.flags
& ILC_MASK
)
2470 if (!(mask_bits
= read_bitmap(pstm
, mask_info
)))
2472 WARN("failed to read mask bitmap from stream\n");
2476 else mask_info
= NULL
;
2478 if (himl
->has_alpha
&& image_info
->bmiHeader
.biBitCount
== 32)
2480 DWORD
*ptr
= image_bits
;
2481 BYTE
*mask_ptr
= mask_bits
;
2482 int stride
= himl
->cy
* image_info
->bmiHeader
.biWidth
;
2484 if (image_info
->bmiHeader
.biHeight
> 0) /* bottom-up */
2486 ptr
+= image_info
->bmiHeader
.biHeight
* image_info
->bmiHeader
.biWidth
- stride
;
2487 mask_ptr
+= (image_info
->bmiHeader
.biHeight
* image_info
->bmiHeader
.biWidth
- stride
) / 8;
2489 image_info
->bmiHeader
.biHeight
= himl
->cy
;
2491 else image_info
->bmiHeader
.biHeight
= -himl
->cy
;
2493 for (i
= 0; i
< ilHead
.cCurImage
; i
+= TILE_COUNT
)
2495 add_dib_bits( himl
, i
, min( ilHead
.cCurImage
- i
, TILE_COUNT
),
2496 himl
->cx
, himl
->cy
, image_info
, mask_info
, ptr
, mask_ptr
);
2498 mask_ptr
+= stride
/ 8;
2503 StretchDIBits( himl
->hdcImage
, 0, 0, image_info
->bmiHeader
.biWidth
, image_info
->bmiHeader
.biHeight
,
2504 0, 0, image_info
->bmiHeader
.biWidth
, image_info
->bmiHeader
.biHeight
,
2505 image_bits
, image_info
, DIB_RGB_COLORS
, SRCCOPY
);
2507 StretchDIBits( himl
->hdcMask
, 0, 0, mask_info
->bmiHeader
.biWidth
, mask_info
->bmiHeader
.biHeight
,
2508 0, 0, mask_info
->bmiHeader
.biWidth
, mask_info
->bmiHeader
.biHeight
,
2509 mask_bits
, mask_info
, DIB_RGB_COLORS
, SRCCOPY
);
2511 heap_free( image_bits
);
2512 heap_free( mask_bits
);
2514 himl
->cCurImage
= ilHead
.cCurImage
;
2515 himl
->cMaxImage
= ilHead
.cMaxImage
;
2517 ImageList_SetBkColor(himl
,ilHead
.bkcolor
);
2519 ImageList_SetOverlayImage(himl
,ilHead
.ovls
[i
],i
+1);
2524 /*************************************************************************
2525 * ImageList_Remove [COMCTL32.@]
2527 * Removes an image from an image list
2530 * himl [I] image list handle
2537 * FIXME: as the image list storage test shows, native comctl32 simply shifts
2538 * images without creating a new bitmap.
2541 ImageList_Remove (HIMAGELIST himl
, INT i
)
2543 HBITMAP hbmNewImage
, hbmNewMask
;
2547 TRACE("(himl=%p i=%d)\n", himl
, i
);
2549 if (!is_valid(himl
)) {
2550 ERR("Invalid image list handle!\n");
2554 if ((i
< -1) || (i
>= himl
->cCurImage
)) {
2555 TRACE("index out of range! %d\n", i
);
2563 if (himl
->cCurImage
== 0) {
2564 /* remove all on empty ImageList is allowed */
2565 TRACE("remove all on empty ImageList!\n");
2569 himl
->cMaxImage
= himl
->cGrow
;
2570 himl
->cCurImage
= 0;
2571 for (nCount
= 0; nCount
< MAX_OVERLAYIMAGE
; nCount
++)
2572 himl
->nOvlIdx
[nCount
] = -1;
2574 if (himl
->has_alpha
)
2576 heap_free( himl
->has_alpha
);
2577 himl
->has_alpha
= heap_alloc_zero( himl
->cMaxImage
);
2580 hbmNewImage
= ImageList_CreateImage(himl
->hdcImage
, himl
, himl
->cMaxImage
);
2581 SelectObject (himl
->hdcImage
, hbmNewImage
);
2582 DeleteObject (himl
->hbmImage
);
2583 himl
->hbmImage
= hbmNewImage
;
2585 if (himl
->hbmMask
) {
2587 imagelist_get_bitmap_size(himl
, himl
->cMaxImage
, &sz
);
2588 hbmNewMask
= CreateBitmap (sz
.cx
, sz
.cy
, 1, 1, NULL
);
2589 SelectObject (himl
->hdcMask
, hbmNewMask
);
2590 DeleteObject (himl
->hbmMask
);
2591 himl
->hbmMask
= hbmNewMask
;
2595 /* delete one image */
2596 TRACE("Remove single image! %d\n", i
);
2598 /* create new bitmap(s) */
2599 TRACE(" - Number of images: %d / %d (Old/New)\n",
2600 himl
->cCurImage
, himl
->cCurImage
- 1);
2602 hbmNewImage
= ImageList_CreateImage(himl
->hdcImage
, himl
, himl
->cMaxImage
);
2604 imagelist_get_bitmap_size(himl
, himl
->cMaxImage
, &sz
);
2606 hbmNewMask
= CreateBitmap (sz
.cx
, sz
.cy
, 1, 1, NULL
);
2608 hbmNewMask
= 0; /* Just to keep compiler happy! */
2610 hdcBmp
= CreateCompatibleDC (0);
2612 /* copy all images and masks prior to the "removed" image */
2614 TRACE("Pre image copy: Copy %d images\n", i
);
2616 SelectObject (hdcBmp
, hbmNewImage
);
2617 imagelist_copy_images( himl
, himl
->hdcImage
, hdcBmp
, 0, i
, 0 );
2619 if (himl
->hbmMask
) {
2620 SelectObject (hdcBmp
, hbmNewMask
);
2621 imagelist_copy_images( himl
, himl
->hdcMask
, hdcBmp
, 0, i
, 0 );
2625 /* copy all images and masks behind the removed image */
2626 if (i
< himl
->cCurImage
- 1) {
2627 TRACE("Post image copy!\n");
2629 SelectObject (hdcBmp
, hbmNewImage
);
2630 imagelist_copy_images( himl
, himl
->hdcImage
, hdcBmp
, i
+ 1,
2631 (himl
->cCurImage
- i
), i
);
2633 if (himl
->hbmMask
) {
2634 SelectObject (hdcBmp
, hbmNewMask
);
2635 imagelist_copy_images( himl
, himl
->hdcMask
, hdcBmp
, i
+ 1,
2636 (himl
->cCurImage
- i
), i
);
2642 /* delete old images and insert new ones */
2643 SelectObject (himl
->hdcImage
, hbmNewImage
);
2644 DeleteObject (himl
->hbmImage
);
2645 himl
->hbmImage
= hbmNewImage
;
2646 if (himl
->hbmMask
) {
2647 SelectObject (himl
->hdcMask
, hbmNewMask
);
2648 DeleteObject (himl
->hbmMask
);
2649 himl
->hbmMask
= hbmNewMask
;
2659 /*************************************************************************
2660 * ImageList_Replace [COMCTL32.@]
2662 * Replaces an image in an image list with a new image.
2665 * himl [I] handle to image list
2667 * hbmImage [I] handle to image bitmap
2668 * hbmMask [I] handle to mask bitmap. Can be NULL.
2676 ImageList_Replace (HIMAGELIST himl
, INT i
, HBITMAP hbmImage
,
2683 TRACE("%p %d %p %p\n", himl
, i
, hbmImage
, hbmMask
);
2685 if (!is_valid(himl
)) {
2686 ERR("Invalid image list handle!\n");
2690 if ((i
>= himl
->cMaxImage
) || (i
< 0)) {
2691 ERR("Invalid image index!\n");
2695 if (!GetObjectW(hbmImage
, sizeof(BITMAP
), &bmp
))
2698 hdcImage
= CreateCompatibleDC (0);
2701 SelectObject (hdcImage
, hbmImage
);
2703 if (add_with_alpha( himl
, hdcImage
, i
, 1, bmp
.bmWidth
, bmp
.bmHeight
, hbmImage
, hbmMask
))
2706 imagelist_point_from_index(himl
, i
, &pt
);
2707 StretchBlt (himl
->hdcImage
, pt
.x
, pt
.y
, himl
->cx
, himl
->cy
,
2708 hdcImage
, 0, 0, bmp
.bmWidth
, bmp
.bmHeight
, SRCCOPY
);
2713 HBITMAP hOldBitmapTemp
;
2715 hdcTemp
= CreateCompatibleDC(0);
2716 hOldBitmapTemp
= SelectObject(hdcTemp
, hbmMask
);
2718 StretchBlt (himl
->hdcMask
, pt
.x
, pt
.y
, himl
->cx
, himl
->cy
,
2719 hdcTemp
, 0, 0, bmp
.bmWidth
, bmp
.bmHeight
, SRCCOPY
);
2720 SelectObject(hdcTemp
, hOldBitmapTemp
);
2723 /* Remove the background from the image
2725 BitBlt (himl
->hdcImage
, pt
.x
, pt
.y
, bmp
.bmWidth
, bmp
.bmHeight
,
2726 himl
->hdcMask
, pt
.x
, pt
.y
, 0x220326); /* NOTSRCAND */
2730 DeleteDC (hdcImage
);
2736 /*************************************************************************
2737 * ImageList_ReplaceIcon [COMCTL32.@]
2739 * Replaces an image in an image list using an icon.
2742 * himl [I] handle to image list
2744 * hIcon [I] handle to icon
2747 * Success: index of the replaced image
2752 ImageList_ReplaceIcon (HIMAGELIST himl
, INT nIndex
, HICON hIcon
)
2760 TRACE("(%p %d %p)\n", himl
, nIndex
, hIcon
);
2762 if (!is_valid(himl
)) {
2763 ERR("invalid image list\n");
2766 if ((nIndex
>= himl
->cMaxImage
) || (nIndex
< -1)) {
2767 ERR("invalid image index %d / %d\n", nIndex
, himl
->cMaxImage
);
2771 hBestFitIcon
= CopyImage(
2774 LR_COPYFROMRESOURCE
);
2775 /* the above will fail if the icon wasn't loaded from a resource, so try
2776 * again without LR_COPYFROMRESOURCE flag */
2778 hBestFitIcon
= CopyImage(
2786 if (himl
->cCurImage
+ 1 >= himl
->cMaxImage
)
2787 IMAGELIST_InternalExpandBitmaps(himl
, 1);
2789 nIndex
= himl
->cCurImage
;
2793 if (himl
->has_alpha
&& GetIconInfo (hBestFitIcon
, &ii
))
2795 HDC hdcImage
= CreateCompatibleDC( 0 );
2796 GetObjectW (ii
.hbmMask
, sizeof(BITMAP
), &bmp
);
2800 UINT height
= bmp
.bmHeight
/ 2;
2801 HDC hdcMask
= CreateCompatibleDC( 0 );
2802 HBITMAP color
= CreateBitmap( bmp
.bmWidth
, height
, 1, 1, NULL
);
2803 SelectObject( hdcImage
, color
);
2804 SelectObject( hdcMask
, ii
.hbmMask
);
2805 BitBlt( hdcImage
, 0, 0, bmp
.bmWidth
, height
, hdcMask
, 0, height
, SRCCOPY
);
2806 ret
= add_with_alpha( himl
, hdcImage
, nIndex
, 1, bmp
.bmWidth
, height
, color
, ii
.hbmMask
);
2807 DeleteDC( hdcMask
);
2808 DeleteObject( color
);
2810 else ret
= add_with_alpha( himl
, hdcImage
, nIndex
, 1, bmp
.bmWidth
, bmp
.bmHeight
,
2811 ii
.hbmColor
, ii
.hbmMask
);
2813 DeleteDC( hdcImage
);
2814 DeleteObject (ii
.hbmMask
);
2815 if (ii
.hbmColor
) DeleteObject (ii
.hbmColor
);
2819 imagelist_point_from_index(himl
, nIndex
, &pt
);
2823 DrawIconEx( himl
->hdcImage
, pt
.x
, pt
.y
, hBestFitIcon
, himl
->cx
, himl
->cy
, 0, 0, DI_IMAGE
);
2824 PatBlt( himl
->hdcMask
, pt
.x
, pt
.y
, himl
->cx
, himl
->cy
, WHITENESS
);
2825 DrawIconEx( himl
->hdcMask
, pt
.x
, pt
.y
, hBestFitIcon
, himl
->cx
, himl
->cy
, 0, 0, DI_MASK
);
2829 COLORREF color
= himl
->clrBk
!= CLR_NONE
? himl
->clrBk
: comctl32_color
.clrWindow
;
2830 HBRUSH brush
= CreateSolidBrush( GetNearestColor( himl
->hdcImage
, color
));
2832 SelectObject( himl
->hdcImage
, brush
);
2833 PatBlt( himl
->hdcImage
, pt
.x
, pt
.y
, himl
->cx
, himl
->cy
, PATCOPY
);
2834 SelectObject( himl
->hdcImage
, GetStockObject(BLACK_BRUSH
) );
2835 DeleteObject( brush
);
2836 DrawIconEx( himl
->hdcImage
, pt
.x
, pt
.y
, hBestFitIcon
, himl
->cx
, himl
->cy
, 0, 0, DI_NORMAL
);
2840 DestroyIcon(hBestFitIcon
);
2842 TRACE("Insert index = %d, himl->cCurImage = %d\n", nIndex
, himl
->cCurImage
);
2847 /*************************************************************************
2848 * ImageList_SetBkColor [COMCTL32.@]
2850 * Sets the background color of an image list.
2853 * himl [I] handle to image list
2854 * clrBk [I] background color
2857 * Success: previous background color
2862 ImageList_SetBkColor (HIMAGELIST himl
, COLORREF clrBk
)
2866 if (!is_valid(himl
))
2869 clrOldBk
= himl
->clrBk
;
2870 himl
->clrBk
= clrBk
;
2875 /*************************************************************************
2876 * ImageList_SetDragCursorImage [COMCTL32.@]
2878 * Combines the specified image with the current drag image
2881 * himlDrag [I] handle to drag image list
2882 * iDrag [I] drag image index
2883 * dxHotspot [I] X position of the hot spot
2884 * dyHotspot [I] Y position of the hot spot
2891 * - The names dxHotspot, dyHotspot are misleading because they have nothing
2892 * to do with a hotspot but are only the offset of the origin of the new
2893 * image relative to the origin of the old image.
2895 * - When this function is called and the drag image is visible, a
2896 * short flickering occurs but this matches the Win9x behavior. It is
2897 * possible to fix the flickering using code like in ImageList_DragMove.
2901 ImageList_SetDragCursorImage (HIMAGELIST himlDrag
, INT iDrag
,
2902 INT dxHotspot
, INT dyHotspot
)
2904 HIMAGELIST himlTemp
;
2907 if (!is_valid(InternalDrag
.himl
) || !is_valid(himlDrag
))
2910 TRACE(" dxH=%d dyH=%d nX=%d nY=%d\n",
2911 dxHotspot
, dyHotspot
, InternalDrag
.dxHotspot
, InternalDrag
.dyHotspot
);
2913 visible
= InternalDrag
.bShow
;
2915 himlTemp
= ImageList_Merge (InternalDrag
.himlNoCursor
, 0, himlDrag
, iDrag
,
2916 dxHotspot
, dyHotspot
);
2919 /* hide the drag image */
2920 ImageList_DragShowNolock(FALSE
);
2922 if ((InternalDrag
.himl
->cx
!= himlTemp
->cx
) ||
2923 (InternalDrag
.himl
->cy
!= himlTemp
->cy
)) {
2924 /* the size of the drag image changed, invalidate the buffer */
2925 DeleteObject(InternalDrag
.hbmBg
);
2926 InternalDrag
.hbmBg
= 0;
2929 if (InternalDrag
.himl
!= InternalDrag
.himlNoCursor
)
2930 ImageList_Destroy (InternalDrag
.himl
);
2931 InternalDrag
.himl
= himlTemp
;
2934 /* show the drag image */
2935 ImageList_DragShowNolock(TRUE
);
2942 /*************************************************************************
2943 * ImageList_SetFilter [COMCTL32.@]
2945 * Sets a filter (or does something completely different)!!???
2946 * It removes 12 Bytes from the stack (3 Parameters).
2949 * himl [I] SHOULD be a handle to image list
2950 * i [I] COULD be an index?
2955 * Failure: FALSE ???
2958 * This is an UNDOCUMENTED function!!!!
2963 ImageList_SetFilter (HIMAGELIST himl
, INT i
, DWORD dwFilter
)
2965 FIXME("(%p 0x%x 0x%x):empty stub!\n", himl
, i
, dwFilter
);
2971 /*************************************************************************
2972 * ImageList_SetFlags [COMCTL32.@]
2974 * Sets the image list flags.
2977 * himl [I] Handle to image list
2978 * flags [I] Flags to set
2988 ImageList_SetFlags(HIMAGELIST himl
, DWORD flags
)
2990 FIXME("(%p %08x):empty stub\n", himl
, flags
);
2995 /*************************************************************************
2996 * ImageList_SetIconSize [COMCTL32.@]
2998 * Sets the image size of the bitmap and deletes all images.
3001 * himl [I] handle to image list
3002 * cx [I] image width
3003 * cy [I] image height
3011 ImageList_SetIconSize (HIMAGELIST himl
, INT cx
, INT cy
)
3016 if (!is_valid(himl
))
3019 /* remove all images */
3020 himl
->cMaxImage
= himl
->cInitial
+ 1;
3021 himl
->cCurImage
= 0;
3025 /* initialize overlay mask indices */
3026 for (nCount
= 0; nCount
< MAX_OVERLAYIMAGE
; nCount
++)
3027 himl
->nOvlIdx
[nCount
] = -1;
3029 hbmNew
= ImageList_CreateImage(himl
->hdcImage
, himl
, himl
->cMaxImage
);
3030 SelectObject (himl
->hdcImage
, hbmNew
);
3031 DeleteObject (himl
->hbmImage
);
3032 himl
->hbmImage
= hbmNew
;
3034 if (himl
->hbmMask
) {
3036 imagelist_get_bitmap_size(himl
, himl
->cMaxImage
, &sz
);
3037 hbmNew
= CreateBitmap (sz
.cx
, sz
.cy
, 1, 1, NULL
);
3038 SelectObject (himl
->hdcMask
, hbmNew
);
3039 DeleteObject (himl
->hbmMask
);
3040 himl
->hbmMask
= hbmNew
;
3047 /*************************************************************************
3048 * ImageList_SetImageCount [COMCTL32.@]
3050 * Resizes an image list to the specified number of images.
3053 * himl [I] handle to image list
3054 * iImageCount [I] number of images in the image list
3062 ImageList_SetImageCount (HIMAGELIST himl
, UINT iImageCount
)
3065 HBITMAP hbmNewBitmap
, hbmOld
;
3066 INT nNewCount
, nCopyCount
;
3068 TRACE("%p %d\n",himl
,iImageCount
);
3070 if (!is_valid(himl
))
3073 nNewCount
= iImageCount
+ 1;
3074 nCopyCount
= min(himl
->cCurImage
, iImageCount
);
3076 hdcBitmap
= CreateCompatibleDC (0);
3078 hbmNewBitmap
= ImageList_CreateImage(hdcBitmap
, himl
, nNewCount
);
3080 if (hbmNewBitmap
!= 0)
3082 hbmOld
= SelectObject (hdcBitmap
, hbmNewBitmap
);
3083 imagelist_copy_images( himl
, himl
->hdcImage
, hdcBitmap
, 0, nCopyCount
, 0 );
3084 SelectObject (hdcBitmap
, hbmOld
);
3086 /* FIXME: delete 'empty' image space? */
3088 SelectObject (himl
->hdcImage
, hbmNewBitmap
);
3089 DeleteObject (himl
->hbmImage
);
3090 himl
->hbmImage
= hbmNewBitmap
;
3093 ERR("Could not create new image bitmap!\n");
3098 imagelist_get_bitmap_size( himl
, nNewCount
, &sz
);
3099 hbmNewBitmap
= CreateBitmap (sz
.cx
, sz
.cy
, 1, 1, NULL
);
3100 if (hbmNewBitmap
!= 0)
3102 hbmOld
= SelectObject (hdcBitmap
, hbmNewBitmap
);
3103 imagelist_copy_images( himl
, himl
->hdcMask
, hdcBitmap
, 0, nCopyCount
, 0 );
3104 SelectObject (hdcBitmap
, hbmOld
);
3106 /* FIXME: delete 'empty' image space? */
3108 SelectObject (himl
->hdcMask
, hbmNewBitmap
);
3109 DeleteObject (himl
->hbmMask
);
3110 himl
->hbmMask
= hbmNewBitmap
;
3113 ERR("Could not create new mask bitmap!\n");
3116 DeleteDC (hdcBitmap
);
3118 if (himl
->has_alpha
)
3120 char *new_alpha
= HeapReAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, himl
->has_alpha
, nNewCount
);
3121 if (new_alpha
) himl
->has_alpha
= new_alpha
;
3124 heap_free( himl
->has_alpha
);
3125 himl
->has_alpha
= NULL
;
3129 /* Update max image count and current image count */
3130 himl
->cMaxImage
= nNewCount
;
3131 himl
->cCurImage
= iImageCount
;
3137 /*************************************************************************
3138 * ImageList_SetOverlayImage [COMCTL32.@]
3140 * Assigns an overlay mask index to an existing image in an image list.
3143 * himl [I] handle to image list
3144 * iImage [I] image index
3145 * iOverlay [I] overlay mask index
3153 ImageList_SetOverlayImage (HIMAGELIST himl
, INT iImage
, INT iOverlay
)
3155 if (!is_valid(himl
))
3157 if ((iOverlay
< 1) || (iOverlay
> MAX_OVERLAYIMAGE
))
3159 if ((iImage
!=-1) && ((iImage
< 0) || (iImage
> himl
->cCurImage
)))
3161 himl
->nOvlIdx
[iOverlay
- 1] = iImage
;
3167 /* helper for ImageList_Write - write bitmap to pstm
3168 * currently everything is written as 24 bit RGB, except masks
3170 static BOOL
_write_bitmap(HBITMAP hBitmap
, IStream
*pstm
)
3172 LPBITMAPFILEHEADER bmfh
;
3173 LPBITMAPINFOHEADER bmih
;
3174 LPBYTE data
= NULL
, lpBits
;
3176 INT bitCount
, sizeImage
, offBits
, totalSize
;
3178 BOOL result
= FALSE
;
3180 if (!GetObjectW(hBitmap
, sizeof(BITMAP
), &bm
))
3183 bitCount
= bm
.bmBitsPixel
;
3184 sizeImage
= get_dib_stride(bm
.bmWidth
, bitCount
) * bm
.bmHeight
;
3186 totalSize
= sizeof(BITMAPFILEHEADER
) + sizeof(BITMAPINFOHEADER
);
3188 totalSize
+= (1 << bitCount
) * sizeof(RGBQUAD
);
3189 offBits
= totalSize
;
3190 totalSize
+= sizeImage
;
3192 data
= heap_alloc_zero(totalSize
);
3193 bmfh
= (LPBITMAPFILEHEADER
)data
;
3194 bmih
= (LPBITMAPINFOHEADER
)(data
+ sizeof(BITMAPFILEHEADER
));
3195 lpBits
= data
+ offBits
;
3197 /* setup BITMAPFILEHEADER */
3198 bmfh
->bfType
= (('M' << 8) | 'B');
3199 bmfh
->bfSize
= offBits
;
3200 bmfh
->bfReserved1
= 0;
3201 bmfh
->bfReserved2
= 0;
3202 bmfh
->bfOffBits
= offBits
;
3204 /* setup BITMAPINFOHEADER */
3205 bmih
->biSize
= sizeof(BITMAPINFOHEADER
);
3206 bmih
->biWidth
= bm
.bmWidth
;
3207 bmih
->biHeight
= bm
.bmHeight
;
3209 bmih
->biBitCount
= bitCount
;
3210 bmih
->biCompression
= BI_RGB
;
3211 bmih
->biSizeImage
= sizeImage
;
3212 bmih
->biXPelsPerMeter
= 0;
3213 bmih
->biYPelsPerMeter
= 0;
3214 bmih
->biClrUsed
= 0;
3215 bmih
->biClrImportant
= 0;
3218 result
= GetDIBits(xdc
, hBitmap
, 0, bm
.bmHeight
, lpBits
, (BITMAPINFO
*)bmih
, DIB_RGB_COLORS
) == bm
.bmHeight
;
3223 TRACE("width %u, height %u, planes %u, bpp %u\n",
3224 bmih
->biWidth
, bmih
->biHeight
,
3225 bmih
->biPlanes
, bmih
->biBitCount
);
3227 if(FAILED(IStream_Write(pstm
, data
, totalSize
, NULL
)))
3239 /*************************************************************************
3240 * ImageList_Write [COMCTL32.@]
3242 * Writes an image list to a stream.
3245 * himl [I] handle to image list
3246 * pstm [O] Pointer to a stream.
3256 BOOL WINAPI
ImageList_Write(HIMAGELIST himl
, IStream
*pstm
)
3261 TRACE("%p %p\n", himl
, pstm
);
3263 if (!is_valid(himl
))
3266 ilHead
.usMagic
= (('L' << 8) | 'I');
3267 ilHead
.usVersion
= 0x101;
3268 ilHead
.cCurImage
= himl
->cCurImage
;
3269 ilHead
.cMaxImage
= himl
->cMaxImage
;
3270 ilHead
.cGrow
= himl
->cGrow
;
3271 ilHead
.cx
= himl
->cx
;
3272 ilHead
.cy
= himl
->cy
;
3273 ilHead
.bkcolor
= himl
->clrBk
;
3274 ilHead
.flags
= himl
->flags
;
3275 for(i
= 0; i
< 4; i
++) {
3276 ilHead
.ovls
[i
] = himl
->nOvlIdx
[i
];
3279 TRACE("cx %u, cy %u, flags 0x04%x, cCurImage %u, cMaxImage %u\n",
3280 ilHead
.cx
, ilHead
.cy
, ilHead
.flags
, ilHead
.cCurImage
, ilHead
.cMaxImage
);
3282 if(FAILED(IStream_Write(pstm
, &ilHead
, sizeof(ILHEAD
), NULL
)))
3285 /* write the bitmap */
3286 if(!_write_bitmap(himl
->hbmImage
, pstm
))
3289 /* write the mask if we have one */
3290 if(himl
->flags
& ILC_MASK
) {
3291 if(!_write_bitmap(himl
->hbmMask
, pstm
))
3299 static HBITMAP
ImageList_CreateImage(HDC hdc
, HIMAGELIST himl
, UINT count
)
3301 HBITMAP hbmNewBitmap
;
3302 UINT ilc
= (himl
->flags
& 0xFE);
3305 imagelist_get_bitmap_size( himl
, count
, &sz
);
3307 if ((ilc
>= ILC_COLOR4
&& ilc
<= ILC_COLOR32
) || ilc
== ILC_COLOR
)
3309 char buffer
[sizeof(BITMAPINFOHEADER
) + 256 * sizeof(RGBQUAD
)];
3310 BITMAPINFO
*bmi
= (BITMAPINFO
*)buffer
;
3312 TRACE("Creating DIBSection %d x %d, %d Bits per Pixel\n",
3313 sz
.cx
, sz
.cy
, himl
->uBitsPixel
);
3315 memset( buffer
, 0, sizeof(buffer
) );
3316 bmi
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
3317 bmi
->bmiHeader
.biWidth
= sz
.cx
;
3318 bmi
->bmiHeader
.biHeight
= sz
.cy
;
3319 bmi
->bmiHeader
.biPlanes
= 1;
3320 bmi
->bmiHeader
.biBitCount
= himl
->uBitsPixel
;
3321 bmi
->bmiHeader
.biCompression
= BI_RGB
;
3323 if (himl
->uBitsPixel
<= ILC_COLOR8
)
3325 if (!himl
->color_table_set
)
3327 /* retrieve the default color map */
3328 HBITMAP tmp
= CreateBitmap( 1, 1, 1, 1, NULL
);
3329 GetDIBits( hdc
, tmp
, 0, 0, NULL
, bmi
, DIB_RGB_COLORS
);
3330 DeleteObject( tmp
);
3331 if (ilc
== ILC_COLOR4
)
3334 tmp
= bmi
->bmiColors
[7];
3335 bmi
->bmiColors
[7] = bmi
->bmiColors
[8];
3336 bmi
->bmiColors
[8] = tmp
;
3341 GetDIBColorTable(himl
->hdcImage
, 0, 1 << himl
->uBitsPixel
, bmi
->bmiColors
);
3344 hbmNewBitmap
= CreateDIBSection(hdc
, bmi
, DIB_RGB_COLORS
, NULL
, 0, 0);
3346 else /*if (ilc == ILC_COLORDDB)*/
3348 TRACE("Creating Bitmap: %d Bits per Pixel\n", himl
->uBitsPixel
);
3350 hbmNewBitmap
= CreateBitmap (sz
.cx
, sz
.cy
, 1, himl
->uBitsPixel
, NULL
);
3352 TRACE("returning %p\n", hbmNewBitmap
);
3353 return hbmNewBitmap
;
3356 /*************************************************************************
3357 * ImageList_SetColorTable [COMCTL32.@]
3359 * Sets the color table of an image list.
3362 * himl [I] Handle to the image list.
3363 * uStartIndex [I] The first index to set.
3364 * cEntries [I] Number of entries to set.
3365 * prgb [I] New color information for color table for the image list.
3368 * Success: Number of entries in the table that were set.
3372 * ImageList_Create(), SetDIBColorTable()
3376 ImageList_SetColorTable(HIMAGELIST himl
, UINT uStartIndex
, UINT cEntries
, const RGBQUAD
*prgb
)
3379 if(!is_valid2(himl
))
3382 TRACE("(%p, %d, %d, %p)\n", himl
, uStartIndex
, cEntries
, prgb
);
3383 himl
->color_table_set
= TRUE
;
3384 return SetDIBColorTable(himl
->hdcImage
, uStartIndex
, cEntries
, prgb
);
3387 /*************************************************************************
3388 * ImageList_CoCreateInstance [COMCTL32.@]
3390 * Creates a new imagelist instance and returns an interface pointer to it.
3393 * rclsid [I] A reference to the CLSID (CLSID_ImageList).
3394 * punkOuter [I] Pointer to IUnknown interface for aggregation, if desired
3395 * riid [I] Identifier of the requested interface.
3396 * ppv [O] Returns the address of the pointer requested, or NULL.
3400 * Failure: Error value.
3403 ImageList_CoCreateInstance (REFCLSID rclsid
, const IUnknown
*punkOuter
, REFIID riid
, void **ppv
)
3405 TRACE("(%s,%p,%s,%p)\n", debugstr_guid(rclsid
), punkOuter
, debugstr_guid(riid
), ppv
);
3407 if (!IsEqualCLSID(&CLSID_ImageList
, rclsid
))
3408 return E_NOINTERFACE
;
3410 return ImageListImpl_CreateInstance(punkOuter
, riid
, ppv
);
3414 /*************************************************************************
3415 * IImageList implementation
3418 static HRESULT WINAPI
ImageListImpl_QueryInterface(IImageList2
*iface
,
3419 REFIID iid
, void **ppv
)
3421 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3423 TRACE("(%p,%s,%p)\n", iface
, debugstr_guid(iid
), ppv
);
3425 if (!ppv
) return E_INVALIDARG
;
3427 if (IsEqualIID(&IID_IUnknown
, iid
) ||
3428 IsEqualIID(&IID_IImageList
, iid
) ||
3429 IsEqualIID(&IID_IImageList2
, iid
))
3431 *ppv
= &imgl
->IImageList2_iface
;
3436 return E_NOINTERFACE
;
3439 IImageList2_AddRef(iface
);
3443 static ULONG WINAPI
ImageListImpl_AddRef(IImageList2
*iface
)
3445 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3446 ULONG ref
= InterlockedIncrement(&imgl
->ref
);
3448 TRACE("(%p) refcount=%u\n", iface
, ref
);
3452 static ULONG WINAPI
ImageListImpl_Release(IImageList2
*iface
)
3454 HIMAGELIST This
= impl_from_IImageList2(iface
);
3455 ULONG ref
= InterlockedDecrement(&This
->ref
);
3457 TRACE("(%p) refcount=%u\n", iface
, ref
);
3461 /* delete image bitmaps */
3462 if (This
->hbmImage
) DeleteObject (This
->hbmImage
);
3463 if (This
->hbmMask
) DeleteObject (This
->hbmMask
);
3465 /* delete image & mask DCs */
3466 if (This
->hdcImage
) DeleteDC (This
->hdcImage
);
3467 if (This
->hdcMask
) DeleteDC (This
->hdcMask
);
3469 /* delete blending brushes */
3470 if (This
->hbrBlend25
) DeleteObject (This
->hbrBlend25
);
3471 if (This
->hbrBlend50
) DeleteObject (This
->hbrBlend50
);
3473 This
->IImageList2_iface
.lpVtbl
= NULL
;
3474 heap_free(This
->has_alpha
);
3481 static HRESULT WINAPI
ImageListImpl_Add(IImageList2
*iface
, HBITMAP hbmImage
,
3482 HBITMAP hbmMask
, int *pi
)
3484 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3490 ret
= ImageList_Add(imgl
, hbmImage
, hbmMask
);
3499 static HRESULT WINAPI
ImageListImpl_ReplaceIcon(IImageList2
*iface
, int i
,
3500 HICON hicon
, int *pi
)
3502 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3508 ret
= ImageList_ReplaceIcon(imgl
, i
, hicon
);
3517 static HRESULT WINAPI
ImageListImpl_SetOverlayImage(IImageList2
*iface
,
3518 int iImage
, int iOverlay
)
3520 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3521 return ImageList_SetOverlayImage(imgl
, iImage
, iOverlay
) ? S_OK
: E_FAIL
;
3524 static HRESULT WINAPI
ImageListImpl_Replace(IImageList2
*iface
, int i
,
3525 HBITMAP hbmImage
, HBITMAP hbmMask
)
3527 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3528 return ImageList_Replace(imgl
, i
, hbmImage
, hbmMask
) ? S_OK
: E_FAIL
;
3531 static HRESULT WINAPI
ImageListImpl_AddMasked(IImageList2
*iface
, HBITMAP hbmImage
,
3532 COLORREF crMask
, int *pi
)
3534 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3540 ret
= ImageList_AddMasked(imgl
, hbmImage
, crMask
);
3549 static HRESULT WINAPI
ImageListImpl_Draw(IImageList2
*iface
,
3550 IMAGELISTDRAWPARAMS
*pimldp
)
3552 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3553 HIMAGELIST old_himl
;
3556 /* As far as I can tell, Windows simply ignores the contents of pimldp->himl
3557 so we shall simulate the same */
3558 old_himl
= pimldp
->himl
;
3559 pimldp
->himl
= imgl
;
3561 ret
= ImageList_DrawIndirect(pimldp
);
3563 pimldp
->himl
= old_himl
;
3564 return ret
? S_OK
: E_INVALIDARG
;
3567 static HRESULT WINAPI
ImageListImpl_Remove(IImageList2
*iface
, int i
)
3569 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3570 return (ImageList_Remove(imgl
, i
) == 0) ? E_INVALIDARG
: S_OK
;
3573 static HRESULT WINAPI
ImageListImpl_GetIcon(IImageList2
*iface
, int i
, UINT flags
,
3576 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3582 hIcon
= ImageList_GetIcon(imgl
, i
, flags
);
3591 static HRESULT WINAPI
ImageListImpl_GetImageInfo(IImageList2
*iface
, int i
,
3592 IMAGEINFO
*pImageInfo
)
3594 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3595 return ImageList_GetImageInfo(imgl
, i
, pImageInfo
) ? S_OK
: E_FAIL
;
3598 static HRESULT WINAPI
ImageListImpl_Copy(IImageList2
*iface
, int dst_index
,
3599 IUnknown
*unk_src
, int src_index
, UINT flags
)
3601 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3602 IImageList
*src
= NULL
;
3609 /* Make sure that the second image list uses the same implementation with the first */
3610 if (!is_valid2((HIMAGELIST
)unk_src
))
3614 /* TODO: Add test for IID_ImageList2 too */
3615 if (FAILED(IUnknown_QueryInterface(unk_src
, &IID_IImageList
,
3619 if (ImageList_Copy(imgl
, dst_index
, (HIMAGELIST
) src
, src_index
, flags
))
3624 IImageList_Release(src
);
3628 static HRESULT WINAPI
ImageListImpl_Merge(IImageList2
*iface
, int i1
,
3629 IUnknown
*punk2
, int i2
, int dx
, int dy
, REFIID riid
, void **ppv
)
3631 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3632 IImageList
*iml2
= NULL
;
3634 HRESULT ret
= E_FAIL
;
3636 TRACE("(%p)->(%d %p %d %d %d %s %p)\n", iface
, i1
, punk2
, i2
, dx
, dy
, debugstr_guid(riid
), ppv
);
3639 /* Make sure that the second image list uses the same implementation with the first */
3640 if (!is_valid2((HIMAGELIST
)punk2
))
3644 /* TODO: Add test for IID_ImageList2 too */
3645 if (FAILED(IUnknown_QueryInterface(punk2
, &IID_IImageList
,
3649 merged
= ImageList_Merge(imgl
, i1
, (HIMAGELIST
) iml2
, i2
, dx
, dy
);
3651 /* Get the interface for the new image list */
3654 ret
= HIMAGELIST_QueryInterface(merged
, riid
, ppv
);
3655 ImageList_Destroy(merged
);
3658 IImageList_Release(iml2
);
3662 static HRESULT WINAPI
ImageListImpl_Clone(IImageList2
*iface
, REFIID riid
, void **ppv
)
3664 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3666 HRESULT ret
= E_FAIL
;
3668 TRACE("(%p)->(%s %p)\n", iface
, debugstr_guid(riid
), ppv
);
3670 clone
= ImageList_Duplicate(imgl
);
3672 /* Get the interface for the new image list */
3675 ret
= HIMAGELIST_QueryInterface(clone
, riid
, ppv
);
3676 ImageList_Destroy(clone
);
3682 static HRESULT WINAPI
ImageListImpl_GetImageRect(IImageList2
*iface
, int i
,
3685 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3691 if (!ImageList_GetImageInfo(imgl
, i
, &info
))
3694 *prc
= info
.rcImage
;
3699 static HRESULT WINAPI
ImageListImpl_GetIconSize(IImageList2
*iface
, int *cx
,
3702 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3703 return ImageList_GetIconSize(imgl
, cx
, cy
) ? S_OK
: E_INVALIDARG
;
3706 static HRESULT WINAPI
ImageListImpl_SetIconSize(IImageList2
*iface
, int cx
,
3709 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3710 return ImageList_SetIconSize(imgl
, cx
, cy
) ? S_OK
: E_FAIL
;
3713 static HRESULT WINAPI
ImageListImpl_GetImageCount(IImageList2
*iface
, int *pi
)
3715 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3716 *pi
= ImageList_GetImageCount(imgl
);
3720 static HRESULT WINAPI
ImageListImpl_SetImageCount(IImageList2
*iface
, UINT count
)
3722 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3723 return ImageList_SetImageCount(imgl
, count
) ? S_OK
: E_FAIL
;
3726 static HRESULT WINAPI
ImageListImpl_SetBkColor(IImageList2
*iface
, COLORREF clrBk
,
3729 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3730 *pclr
= ImageList_SetBkColor(imgl
, clrBk
);
3734 static HRESULT WINAPI
ImageListImpl_GetBkColor(IImageList2
*iface
, COLORREF
*pclr
)
3736 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3737 *pclr
= ImageList_GetBkColor(imgl
);
3741 static HRESULT WINAPI
ImageListImpl_BeginDrag(IImageList2
*iface
, int iTrack
,
3742 int dxHotspot
, int dyHotspot
)
3744 HIMAGELIST imgl
= impl_from_IImageList2(iface
);
3745 return ImageList_BeginDrag(imgl
, iTrack
, dxHotspot
, dyHotspot
) ? S_OK
: E_FAIL
;
3748 static HRESULT WINAPI
ImageListImpl_EndDrag(IImageList2
*iface
)
3750 ImageList_EndDrag();
3754 static HRESULT WINAPI
ImageListImpl_DragEnter(IImageList2
*iface
, HWND hwndLock
,
3757 return ImageList_DragEnter(hwndLock
, x
, y
) ? S_OK
: E_FAIL
;
3760 static HRESULT WINAPI
ImageListImpl_DragLeave(IImageList2
*iface
, HWND hwndLock
)
3762 return ImageList_DragLeave(hwndLock
) ? S_OK
: E_FAIL
;
3765 static HRESULT WINAPI
ImageListImpl_DragMove(IImageList2
*iface
, int x
, int y
)
3767 return ImageList_DragMove(x
, y
) ? S_OK
: E_FAIL
;
3770 static HRESULT WINAPI
ImageListImpl_SetDragCursorImage(IImageList2
*iface
,
3771 IUnknown
*punk
, int iDrag
, int dxHotspot
, int dyHotspot
)
3773 IImageList
*iml2
= NULL
;
3779 /* TODO: Add test for IID_ImageList2 too */
3780 if (FAILED(IUnknown_QueryInterface(punk
, &IID_IImageList
,
3784 ret
= ImageList_SetDragCursorImage((HIMAGELIST
) iml2
, iDrag
, dxHotspot
,
3787 IImageList_Release(iml2
);
3789 return ret
? S_OK
: E_FAIL
;
3792 static HRESULT WINAPI
ImageListImpl_DragShowNolock(IImageList2
*iface
, BOOL fShow
)
3794 return ImageList_DragShowNolock(fShow
) ? S_OK
: E_FAIL
;
3797 static HRESULT WINAPI
ImageListImpl_GetDragImage(IImageList2
*iface
, POINT
*ppt
,
3798 POINT
*pptHotspot
, REFIID riid
, PVOID
*ppv
)
3800 HRESULT ret
= E_FAIL
;
3806 hNew
= ImageList_GetDragImage(ppt
, pptHotspot
);
3808 /* Get the interface for the new image list */
3811 IImageList
*idrag
= (IImageList
*)hNew
;
3813 ret
= HIMAGELIST_QueryInterface(hNew
, riid
, ppv
);
3814 IImageList_Release(idrag
);
3820 static HRESULT WINAPI
ImageListImpl_GetItemFlags(IImageList2
*iface
, int i
,
3823 FIXME("STUB: %p %d %p\n", iface
, i
, dwFlags
);
3827 static HRESULT WINAPI
ImageListImpl_GetOverlayImage(IImageList2
*iface
, int iOverlay
,
3830 HIMAGELIST This
= impl_from_IImageList2(iface
);
3833 if ((iOverlay
< 0) || (iOverlay
> This
->cCurImage
))
3836 for (i
= 0; i
< MAX_OVERLAYIMAGE
; i
++)
3838 if (This
->nOvlIdx
[i
] == iOverlay
)
3848 static HRESULT WINAPI
ImageListImpl_Resize(IImageList2
*iface
, INT cx
, INT cy
)
3850 FIXME("(%p)->(%d %d): stub\n", iface
, cx
, cy
);
3854 static HRESULT WINAPI
ImageListImpl_GetOriginalSize(IImageList2
*iface
, INT image
, DWORD flags
, INT
*cx
, INT
*cy
)
3856 FIXME("(%p)->(%d %x %p %p): stub\n", iface
, image
, flags
, cx
, cy
);
3860 static HRESULT WINAPI
ImageListImpl_SetOriginalSize(IImageList2
*iface
, INT image
, INT cx
, INT cy
)
3862 FIXME("(%p)->(%d %d %d): stub\n", iface
, image
, cx
, cy
);
3866 static HRESULT WINAPI
ImageListImpl_SetCallback(IImageList2
*iface
, IUnknown
*callback
)
3868 FIXME("(%p)->(%p): stub\n", iface
, callback
);
3872 static HRESULT WINAPI
ImageListImpl_GetCallback(IImageList2
*iface
, REFIID riid
, void **ppv
)
3874 FIXME("(%p)->(%s %p): stub\n", iface
, debugstr_guid(riid
), ppv
);
3878 static HRESULT WINAPI
ImageListImpl_ForceImagePresent(IImageList2
*iface
, INT image
, DWORD flags
)
3880 FIXME("(%p)->(%d %x): stub\n", iface
, image
, flags
);
3884 static HRESULT WINAPI
ImageListImpl_DiscardImages(IImageList2
*iface
, INT first_image
, INT last_image
, DWORD flags
)
3886 FIXME("(%p)->(%d %d %x): stub\n", iface
, first_image
, last_image
, flags
);
3890 static HRESULT WINAPI
ImageListImpl_PreloadImages(IImageList2
*iface
, IMAGELISTDRAWPARAMS
*params
)
3892 FIXME("(%p)->(%p): stub\n", iface
, params
);
3896 static HRESULT WINAPI
ImageListImpl_GetStatistics(IImageList2
*iface
, IMAGELISTSTATS
*stats
)
3898 FIXME("(%p)->(%p): stub\n", iface
, stats
);
3902 static HRESULT WINAPI
ImageListImpl_Initialize(IImageList2
*iface
, INT cx
, INT cy
, UINT flags
, INT initial
, INT grow
)
3904 FIXME("(%p)->(%d %d %d %d %d): stub\n", iface
, cx
, cy
, flags
, initial
, grow
);
3908 static HRESULT WINAPI
ImageListImpl_Replace2(IImageList2
*iface
, INT i
, HBITMAP image
, HBITMAP mask
, IUnknown
*unk
, DWORD flags
)
3910 FIXME("(%p)->(%d %p %p %p %x): stub\n", iface
, i
, image
, mask
, unk
, flags
);
3914 static HRESULT WINAPI
ImageListImpl_ReplaceFromImageList(IImageList2
*iface
, INT i
, IImageList
*imagelist
, INT src
,
3915 IUnknown
*unk
, DWORD flags
)
3917 FIXME("(%p)->(%d %p %d %p %x): stub\n", iface
, i
, imagelist
, src
, unk
, flags
);
3921 static const IImageList2Vtbl ImageListImpl_Vtbl
= {
3922 ImageListImpl_QueryInterface
,
3923 ImageListImpl_AddRef
,
3924 ImageListImpl_Release
,
3926 ImageListImpl_ReplaceIcon
,
3927 ImageListImpl_SetOverlayImage
,
3928 ImageListImpl_Replace
,
3929 ImageListImpl_AddMasked
,
3931 ImageListImpl_Remove
,
3932 ImageListImpl_GetIcon
,
3933 ImageListImpl_GetImageInfo
,
3935 ImageListImpl_Merge
,
3936 ImageListImpl_Clone
,
3937 ImageListImpl_GetImageRect
,
3938 ImageListImpl_GetIconSize
,
3939 ImageListImpl_SetIconSize
,
3940 ImageListImpl_GetImageCount
,
3941 ImageListImpl_SetImageCount
,
3942 ImageListImpl_SetBkColor
,
3943 ImageListImpl_GetBkColor
,
3944 ImageListImpl_BeginDrag
,
3945 ImageListImpl_EndDrag
,
3946 ImageListImpl_DragEnter
,
3947 ImageListImpl_DragLeave
,
3948 ImageListImpl_DragMove
,
3949 ImageListImpl_SetDragCursorImage
,
3950 ImageListImpl_DragShowNolock
,
3951 ImageListImpl_GetDragImage
,
3952 ImageListImpl_GetItemFlags
,
3953 ImageListImpl_GetOverlayImage
,
3954 ImageListImpl_Resize
,
3955 ImageListImpl_GetOriginalSize
,
3956 ImageListImpl_SetOriginalSize
,
3957 ImageListImpl_SetCallback
,
3958 ImageListImpl_GetCallback
,
3959 ImageListImpl_ForceImagePresent
,
3960 ImageListImpl_DiscardImages
,
3961 ImageListImpl_PreloadImages
,
3962 ImageListImpl_GetStatistics
,
3963 ImageListImpl_Initialize
,
3964 ImageListImpl_Replace2
,
3965 ImageListImpl_ReplaceFromImageList
3968 static BOOL
is_valid(HIMAGELIST himl
)
3974 valid
= himl
&& himl
->usMagic
== IMAGELIST_MAGIC
;
3976 valid
= himl
&& himl
->IImageList2_iface
.lpVtbl
== &ImageListImpl_Vtbl
;
3988 /*************************************************************************
3989 * HIMAGELIST_QueryInterface [COMCTL32.@]
3991 * Returns a pointer to an IImageList or IImageList2 object for the given
3995 * himl [I] Image list handle.
3996 * riid [I] Identifier of the requested interface.
3997 * ppv [O] Returns the address of the pointer requested, or NULL.
4001 * Failure: Error value.
4004 HIMAGELIST_QueryInterface (HIMAGELIST himl
, REFIID riid
, void **ppv
)
4006 TRACE("(%p,%s,%p)\n", himl
, debugstr_guid(riid
), ppv
);
4007 return IImageList2_QueryInterface((IImageList2
*) himl
, riid
, ppv
);
4010 static HRESULT
ImageListImpl_CreateInstance(const IUnknown
*pUnkOuter
, REFIID iid
, void** ppv
)
4015 TRACE("(%p,%s,%p)\n", pUnkOuter
, debugstr_guid(iid
), ppv
);
4019 if (pUnkOuter
) return CLASS_E_NOAGGREGATION
;
4021 This
= heap_alloc_zero(sizeof(struct _IMAGELIST
));
4022 if (!This
) return E_OUTOFMEMORY
;
4024 This
->IImageList2_iface
.lpVtbl
= &ImageListImpl_Vtbl
;
4026 This
->usMagic
= IMAGELIST_MAGIC
;
4030 ret
= IImageList2_QueryInterface(&This
->IImageList2_iface
, iid
, ppv
);
4031 IImageList2_Release(&This
->IImageList2_iface
);
4039 //The big bad reactos image list hack!
4040 #undef ImageList_Add
4041 #undef ImageList_ReplaceIcon
4042 #undef ImageList_SetOverlayImage
4043 #undef ImageList_Replace
4044 #undef ImageList_AddMasked
4045 #undef ImageList_Remove
4046 #undef ImageList_GetIcon
4047 #undef ImageList_GetImageInfo
4048 #undef ImageList_Copy
4049 #undef ImageList_Merge
4050 #undef ImageList_Duplicate
4051 #undef ImageList_GetIconSize
4052 #undef ImageList_SetIconSize
4053 #undef ImageList_GetImageCount
4054 #undef ImageList_SetImageCount
4055 #undef ImageList_SetBkColor
4056 #undef ImageList_GetBkColor
4057 #undef ImageList_BeginDrag
4058 #undef ImageList_DrawIndirect
4060 static inline IImageList2
* IImageList2_from_impl(HIMAGELIST himl
)
4064 return &himl
->IImageList2_iface
;
4069 BOOL
is_valid2(HIMAGELIST himl
)
4075 himl
->IImageList2_iface
.lpVtbl
== &ImageListImpl_Vtbl
&&
4076 himl
->usMagic
== IMAGELIST_MAGIC
;
4087 ImageList_Add (HIMAGELIST himl
, HBITMAP hbmImage
, HBITMAP hbmMask
)
4091 IImageList2
* piml
= IImageList2_from_impl(himl
);
4095 hr
= piml
->lpVtbl
->Add(piml
, hbmImage
, hbmMask
, &res
);
4103 ImageList_ReplaceIcon (HIMAGELIST himl
, INT nIndex
, HICON hIcon
)
4107 IImageList2
* piml
= IImageList2_from_impl(himl
);
4111 hr
= piml
->lpVtbl
->ReplaceIcon(piml
, nIndex
, hIcon
, &res
);
4119 ImageList_SetOverlayImage (HIMAGELIST himl
, INT iImage
, INT iOverlay
)
4121 IImageList2
* piml
= IImageList2_from_impl(himl
);
4125 return (piml
->lpVtbl
->SetOverlayImage(piml
, iImage
, iOverlay
) == S_OK
) ? TRUE
: FALSE
;
4129 ImageList_Replace (HIMAGELIST himl
, INT i
, HBITMAP hbmImage
,
4132 IImageList2
* piml
= IImageList2_from_impl(himl
);
4136 return (piml
->lpVtbl
->Replace(piml
, i
, hbmImage
, hbmMask
) == S_OK
) ? TRUE
: FALSE
;
4140 ImageList_AddMasked (HIMAGELIST himl
, HBITMAP hBitmap
, COLORREF clrMask
)
4143 IImageList2
* piml
= IImageList2_from_impl(himl
);
4148 hr
= piml
->lpVtbl
->AddMasked(piml
, hBitmap
, clrMask
, &res
);
4156 ImageList_Remove (HIMAGELIST himl
, INT i
)
4158 IImageList2
* piml
= IImageList2_from_impl(himl
);
4162 return (piml
->lpVtbl
->Remove(piml
, i
) == S_OK
) ? TRUE
: FALSE
;
4166 ImageList_GetIcon (HIMAGELIST himl
, INT i
, UINT fStyle
)
4169 IImageList2
* piml
= IImageList2_from_impl(himl
);
4174 hr
= piml
->lpVtbl
->GetIcon(piml
, i
, fStyle
, &res
);
4182 ImageList_GetImageInfo (HIMAGELIST himl
, INT i
, IMAGEINFO
*pImageInfo
)
4184 IImageList2
* piml
= IImageList2_from_impl(himl
);
4188 return (piml
->lpVtbl
->GetImageInfo(piml
, i
, pImageInfo
) == S_OK
) ? TRUE
: FALSE
;
4192 ImageList_Copy (HIMAGELIST himlDst
, INT iDst
, HIMAGELIST himlSrc
,
4193 INT iSrc
, UINT uFlags
)
4195 IImageList2
*pimlDst
, *pimlSrc
;
4196 pimlDst
= IImageList2_from_impl(himlDst
);
4197 pimlSrc
= IImageList2_from_impl(himlSrc
);
4198 if (!pimlDst
|| !pimlSrc
)
4201 return (pimlDst
->lpVtbl
->Copy(pimlDst
, iDst
, (IUnknown
*)pimlSrc
, iSrc
, uFlags
) == S_OK
) ? TRUE
: FALSE
;
4205 ImageList_Merge (HIMAGELIST himl1
, INT i1
, HIMAGELIST himl2
, INT i2
,
4209 IImageList2
*piml1
, *piml2
, *pimlMerged
;
4210 piml1
= IImageList2_from_impl(himl1
);
4211 piml2
= IImageList2_from_impl(himl2
);
4212 if (!piml1
|| !piml2
)
4215 hr
= piml1
->lpVtbl
->Merge(piml1
, i1
, (IUnknown
*)piml2
, i2
, dx
, dy
, &IID_IImageList2
, (void**)&pimlMerged
);
4219 return (HIMAGELIST
)pimlMerged
;
4223 ImageList_Duplicate (HIMAGELIST himlSrc
)
4226 IImageList2
*piml
, *pimlCloned
;
4227 piml
= IImageList2_from_impl(himlSrc
);
4231 hr
= piml
->lpVtbl
->Clone(piml
, &IID_IImageList2
, (void**)&pimlCloned
);
4235 return (HIMAGELIST
)pimlCloned
;
4239 ImageList_GetIconSize (HIMAGELIST himl
, INT
*cx
, INT
*cy
)
4241 IImageList2
* piml
= IImageList2_from_impl(himl
);
4245 return (piml
->lpVtbl
->GetIconSize(piml
, cx
, cy
) == S_OK
) ? TRUE
: FALSE
;
4249 ImageList_SetIconSize (HIMAGELIST himl
, INT cx
, INT cy
)
4251 IImageList2
* piml
= IImageList2_from_impl(himl
);
4255 return (piml
->lpVtbl
->SetIconSize(piml
, cx
, cy
) == S_OK
) ? TRUE
: FALSE
;
4259 ImageList_GetImageCount (HIMAGELIST himl
)
4263 IImageList2
* piml
= IImageList2_from_impl(himl
);
4267 hr
= piml
->lpVtbl
->GetImageCount(piml
, &res
);
4275 ImageList_SetImageCount (HIMAGELIST himl
, UINT iImageCount
)
4277 IImageList2
* piml
= IImageList2_from_impl(himl
);
4281 return (piml
->lpVtbl
->SetImageCount(piml
, iImageCount
) == S_OK
) ? TRUE
: FALSE
;
4285 ImageList_SetBkColor (HIMAGELIST himl
, COLORREF clrBk
)
4289 IImageList2
* piml
= IImageList2_from_impl(himl
);
4293 hr
= piml
->lpVtbl
->SetBkColor(piml
, clrBk
, &res
);
4301 ImageList_GetBkColor (HIMAGELIST himl
)
4305 IImageList2
* piml
= IImageList2_from_impl(himl
);
4309 hr
= piml
->lpVtbl
->GetBkColor(piml
, &res
);
4317 ImageList_BeginDrag (HIMAGELIST himlTrack
, INT iTrack
,
4318 INT dxHotspot
, INT dyHotspot
)
4320 IImageList2
* piml
= IImageList2_from_impl(himlTrack
);
4324 return (piml
->lpVtbl
->BeginDrag(piml
, iTrack
, dxHotspot
, dyHotspot
) == S_OK
) ? TRUE
: FALSE
;
4328 ImageList_DrawIndirect (IMAGELISTDRAWPARAMS
*pimldp
)
4335 piml
= IImageList2_from_impl(pimldp
->himl
);
4339 return (piml
->lpVtbl
->Draw(piml
, pimldp
) == S_OK
) ? TRUE
: FALSE
;