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
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 * This code was audited for completeness against the documented features
27 * of Comctl32.dll version 6.0 on Sep. 12, 2002, by Dimitrie O. Paun.
29 * Unless otherwise noted, we believe this code to be complete, as per
30 * the specification mentioned above.
31 * If you discover missing features, or bugs, please note them below.
34 * - Add support for ILD_PRESERVEALPHA, ILD_SCALE, ILD_DPISCALE
35 * - Add support for ILS_GLOW, ILS_SHADOW, ILS_SATURATE, ILS_ALPHA
36 * - Thread-safe locking
53 #include "imagelist.h"
54 #include "wine/debug.h"
56 WINE_DEFAULT_DEBUG_CHANNEL(imagelist
);
59 #define MAX_OVERLAYIMAGE 15
61 /* internal image list data used for Drag & Drop operations */
66 /* position of the drag image relative to the window */
69 /* offset of the hotspot relative to the origin of the image */
72 /* is the drag image visible */
74 /* saved background */
78 static INTERNALDRAG InternalDrag
= { 0, 0, 0, 0, 0, 0, FALSE
, 0 };
80 static HBITMAP
ImageList_CreateImage(HDC hdc
, HIMAGELIST himl
, UINT count
, UINT width
);
82 static inline BOOL
is_valid(HIMAGELIST himl
)
84 return himl
&& himl
->magic
== IMAGELIST_MAGIC
;
88 * An imagelist with N images is tiled like this:
100 static inline UINT
imagelist_height( UINT count
)
102 return ((count
+ TILE_COUNT
- 1)/TILE_COUNT
);
105 static inline void imagelist_point_from_index( HIMAGELIST himl
, UINT index
, LPPOINT pt
)
107 pt
->x
= (index
%TILE_COUNT
) * himl
->cx
;
108 pt
->y
= (index
/TILE_COUNT
) * himl
->cy
;
111 static inline void imagelist_get_bitmap_size( HIMAGELIST himl
, UINT count
, UINT cx
, SIZE
*sz
)
113 sz
->cx
= cx
* TILE_COUNT
;
114 sz
->cy
= imagelist_height( count
) * himl
->cy
;
118 * imagelist_copy_images()
120 * Copies a block of count images from offset src in the list to offset dest.
121 * Images are copied a row at at time. Assumes hdcSrc and hdcDest are different.
123 static inline void imagelist_copy_images( HIMAGELIST himl
, HDC hdcSrc
, HDC hdcDest
,
124 UINT src
, UINT count
, UINT dest
)
130 for ( i
=0; i
<TILE_COUNT
; i
++ )
132 imagelist_point_from_index( himl
, src
+i
, &ptSrc
);
133 imagelist_point_from_index( himl
, dest
+i
, &ptDest
);
135 sz
.cy
= himl
->cy
* imagelist_height( count
- i
);
137 BitBlt( hdcDest
, ptDest
.x
, ptDest
.y
, sz
.cx
, sz
.cy
,
138 hdcSrc
, ptSrc
.x
, ptSrc
.y
, SRCCOPY
);
142 /*************************************************************************
143 * IMAGELIST_InternalExpandBitmaps [Internal]
145 * Expands the bitmaps of an image list by the given number of images.
148 * himl [I] handle to image list
149 * nImageCount [I] number of images to add
155 * This function CANNOT be used to reduce the number of images.
158 IMAGELIST_InternalExpandBitmaps (HIMAGELIST himl
, INT nImageCount
, INT cx
, INT cy
)
161 HBITMAP hbmNewBitmap
, hbmNull
;
165 if ((himl
->cCurImage
+ nImageCount
<= himl
->cMaxImage
)
169 if (cx
== 0) cx
= himl
->cx
;
170 nNewCount
= himl
->cCurImage
+ nImageCount
+ himl
->cGrow
;
172 imagelist_get_bitmap_size(himl
, nNewCount
, cx
, &sz
);
174 TRACE("Create expanded bitmaps : himl=%p x=%d y=%d count=%d\n", himl
, sz
.cx
, cy
, nNewCount
);
175 hdcBitmap
= CreateCompatibleDC (0);
177 hbmNewBitmap
= ImageList_CreateImage(hdcBitmap
, himl
, nNewCount
, cx
);
179 if (hbmNewBitmap
== 0)
180 ERR("creating new image bitmap (x=%d y=%d)!\n", sz
.cx
, cy
);
184 hbmNull
= SelectObject (hdcBitmap
, hbmNewBitmap
);
185 BitBlt (hdcBitmap
, 0, 0, sz
.cx
, sz
.cy
,
186 himl
->hdcImage
, 0, 0, SRCCOPY
);
187 SelectObject (hdcBitmap
, hbmNull
);
189 SelectObject (himl
->hdcImage
, hbmNewBitmap
);
190 DeleteObject (himl
->hbmImage
);
191 himl
->hbmImage
= hbmNewBitmap
;
193 if (himl
->flags
& ILC_MASK
)
195 hbmNewBitmap
= CreateBitmap (sz
.cx
, sz
.cy
, 1, 1, NULL
);
197 if (hbmNewBitmap
== 0)
198 ERR("creating new mask bitmap!\n");
202 hbmNull
= SelectObject (hdcBitmap
, hbmNewBitmap
);
203 BitBlt (hdcBitmap
, 0, 0, sz
.cx
, sz
.cy
,
204 himl
->hdcMask
, 0, 0, SRCCOPY
);
205 SelectObject (hdcBitmap
, hbmNull
);
207 SelectObject (himl
->hdcMask
, hbmNewBitmap
);
208 DeleteObject (himl
->hbmMask
);
209 himl
->hbmMask
= hbmNewBitmap
;
212 himl
->cMaxImage
= nNewCount
;
214 DeleteDC (hdcBitmap
);
218 /*************************************************************************
219 * ImageList_Add [COMCTL32.@]
221 * Add an image or images to an image list.
224 * himl [I] handle to image list
225 * hbmImage [I] handle to image bitmap
226 * hbmMask [I] handle to mask bitmap
229 * Success: Index of the first new image.
234 ImageList_Add (HIMAGELIST himl
, HBITMAP hbmImage
, HBITMAP hbmMask
)
236 HDC hdcBitmap
, hdcTemp
;
237 INT nFirstIndex
, nImageCount
, i
;
239 HBITMAP hOldBitmap
, hOldBitmapTemp
;
242 TRACE("himl=%p hbmimage=%p hbmmask=%p\n", himl
, hbmImage
, hbmMask
);
246 if (!GetObjectW(hbmImage
, sizeof(BITMAP
), (LPVOID
)&bmp
))
249 nImageCount
= bmp
.bmWidth
/ himl
->cx
;
251 IMAGELIST_InternalExpandBitmaps (himl
, nImageCount
, bmp
.bmWidth
, bmp
.bmHeight
);
253 hdcBitmap
= CreateCompatibleDC(0);
255 hOldBitmap
= SelectObject(hdcBitmap
, hbmImage
);
257 for (i
=0; i
<nImageCount
; i
++)
259 imagelist_point_from_index( himl
, himl
->cCurImage
+ i
, &pt
);
261 /* Copy result to the imagelist
263 BitBlt( himl
->hdcImage
, pt
.x
, pt
.y
, himl
->cx
, bmp
.bmHeight
,
264 hdcBitmap
, i
*himl
->cx
, 0, SRCCOPY
);
269 hdcTemp
= CreateCompatibleDC(0);
270 hOldBitmapTemp
= SelectObject(hdcTemp
, hbmMask
);
272 BitBlt( himl
->hdcMask
, pt
.x
, pt
.y
, himl
->cx
, bmp
.bmHeight
,
273 hdcTemp
, i
*himl
->cx
, 0, SRCCOPY
);
275 SelectObject(hdcTemp
, hOldBitmapTemp
);
278 /* Remove the background from the image
280 BitBlt( himl
->hdcImage
, pt
.x
, pt
.y
, himl
->cx
, bmp
.bmHeight
,
281 himl
->hdcMask
, pt
.x
, pt
.y
, 0x220326 ); /* NOTSRCAND */
284 SelectObject(hdcBitmap
, hOldBitmap
);
287 nFirstIndex
= himl
->cCurImage
;
288 himl
->cCurImage
+= nImageCount
;
294 /*************************************************************************
295 * ImageList_AddIcon [COMCTL32.@]
297 * Adds an icon to an image list.
300 * himl [I] handle to image list
301 * hIcon [I] handle to icon
304 * Success: index of the new image
307 #undef ImageList_AddIcon
308 INT WINAPI
ImageList_AddIcon (HIMAGELIST himl
, HICON hIcon
)
310 return ImageList_ReplaceIcon (himl
, -1, hIcon
);
314 /*************************************************************************
315 * ImageList_AddMasked [COMCTL32.@]
317 * Adds an image or images to an image list and creates a mask from the
318 * specified bitmap using the mask color.
321 * himl [I] handle to image list.
322 * hBitmap [I] handle to bitmap
323 * clrMask [I] mask color.
326 * Success: Index of the first new image.
331 ImageList_AddMasked (HIMAGELIST himl
, HBITMAP hBitmap
, COLORREF clrMask
)
333 HDC hdcMask
, hdcBitmap
;
334 INT i
, nIndex
, nImageCount
;
337 HBITMAP hMaskBitmap
=0;
341 TRACE("himl=%p hbitmap=%p clrmask=%x\n", himl
, hBitmap
, clrMask
);
345 if (!GetObjectW(hBitmap
, sizeof(BITMAP
), &bmp
))
349 nImageCount
= bmp
.bmWidth
/ himl
->cx
;
353 IMAGELIST_InternalExpandBitmaps (himl
, nImageCount
, bmp
.bmWidth
, bmp
.bmHeight
);
355 nIndex
= himl
->cCurImage
;
356 himl
->cCurImage
+= nImageCount
;
358 hdcBitmap
= CreateCompatibleDC(0);
359 hOldBitmap
= SelectObject(hdcBitmap
, hBitmap
);
361 /* Create a temp Mask so we can remove the background of the Image */
362 hdcMask
= CreateCompatibleDC(0);
363 hMaskBitmap
= CreateBitmap(bmp
.bmWidth
, bmp
.bmHeight
, 1, 1, NULL
);
364 SelectObject(hdcMask
, hMaskBitmap
);
366 /* create monochrome image to the mask bitmap */
367 bkColor
= (clrMask
!= CLR_DEFAULT
) ? clrMask
: GetPixel (hdcBitmap
, 0, 0);
368 SetBkColor (hdcBitmap
, bkColor
);
369 BitBlt (hdcMask
, 0, 0, bmp
.bmWidth
, bmp
.bmHeight
, hdcBitmap
, 0, 0, SRCCOPY
);
371 SetBkColor(hdcBitmap
, RGB(255,255,255));
374 * Remove the background from the image
376 * WINDOWS BUG ALERT!!!!!!
377 * The statement below should not be done in common practice
378 * but this is how ImageList_AddMasked works in Windows.
379 * It overwrites the original bitmap passed, this was discovered
380 * by using the same bitmap to iterate the different styles
381 * on windows where it failed (BUT ImageList_Add is OK)
382 * This is here in case some apps rely on this bug
384 * Blt mode 0x220326 is NOTSRCAND
386 BitBlt(hdcBitmap
, 0, 0, bmp
.bmWidth
, bmp
.bmHeight
, hdcMask
, 0, 0, 0x220326);
388 /* Copy result to the imagelist */
389 for (i
=0; i
<nImageCount
; i
++)
391 imagelist_point_from_index( himl
, nIndex
+ i
, &pt
);
392 BitBlt(himl
->hdcImage
, pt
.x
, pt
.y
, himl
->cx
, bmp
.bmHeight
,
393 hdcBitmap
, i
*himl
->cx
, 0, SRCCOPY
);
394 BitBlt(himl
->hdcMask
, pt
.x
, pt
.y
, himl
->cx
, bmp
.bmHeight
,
395 hdcMask
, i
*himl
->cx
, 0, SRCCOPY
);
399 SelectObject(hdcBitmap
, hOldBitmap
);
401 DeleteObject(hMaskBitmap
);
408 /*************************************************************************
409 * ImageList_BeginDrag [COMCTL32.@]
411 * Creates a temporary image list that contains one image. It will be used
415 * himlTrack [I] handle to the source image list
416 * iTrack [I] index of the drag image in the source image list
417 * dxHotspot [I] X position of the hot spot of the drag image
418 * dyHotspot [I] Y position of the hot spot of the drag image
426 ImageList_BeginDrag (HIMAGELIST himlTrack
, INT iTrack
,
427 INT dxHotspot
, INT dyHotspot
)
431 TRACE("(himlTrack=%p iTrack=%d dx=%d dy=%d)\n", himlTrack
, iTrack
,
432 dxHotspot
, dyHotspot
);
434 if (!is_valid(himlTrack
))
437 if (InternalDrag
.himl
)
438 ImageList_EndDrag ();
443 InternalDrag
.himl
= ImageList_Create (cx
, cy
, himlTrack
->flags
, 1, 1);
444 if (InternalDrag
.himl
== NULL
) {
445 WARN("Error creating drag image list!\n");
449 InternalDrag
.dxHotspot
= dxHotspot
;
450 InternalDrag
.dyHotspot
= dyHotspot
;
453 BitBlt (InternalDrag
.himl
->hdcImage
, 0, 0, cx
, cy
, himlTrack
->hdcImage
, iTrack
* cx
, 0, SRCCOPY
);
456 BitBlt (InternalDrag
.himl
->hdcMask
, 0, 0, cx
, cy
, himlTrack
->hdcMask
, iTrack
* cx
, 0, SRCCOPY
);
458 InternalDrag
.himl
->cCurImage
= 1;
464 /*************************************************************************
465 * ImageList_Copy [COMCTL32.@]
467 * Copies an image of the source image list to an image of the
468 * destination image list. Images can be copied or swapped.
471 * himlDst [I] handle to the destination image list
472 * iDst [I] destination image index.
473 * himlSrc [I] handle to the source image list
474 * iSrc [I] source image index
475 * uFlags [I] flags for the copy operation
482 * Copying from one image list to another is possible. The original
483 * implementation just copies or swaps within one image list.
484 * Could this feature become a bug??? ;-)
488 ImageList_Copy (HIMAGELIST himlDst
, INT iDst
, HIMAGELIST himlSrc
,
489 INT iSrc
, UINT uFlags
)
493 TRACE("himlDst=%p iDst=%d himlSrc=%p iSrc=%d\n", himlDst
, iDst
, himlSrc
, iSrc
);
495 if (!is_valid(himlSrc
) || !is_valid(himlDst
))
497 if ((iDst
< 0) || (iDst
>= himlDst
->cCurImage
))
499 if ((iSrc
< 0) || (iSrc
>= himlSrc
->cCurImage
))
502 imagelist_point_from_index( himlDst
, iDst
, &ptDst
);
503 imagelist_point_from_index( himlSrc
, iSrc
, &ptSrc
);
505 if (uFlags
& ILCF_SWAP
) {
508 HBITMAP hbmTempImage
, hbmTempMask
;
510 hdcBmp
= CreateCompatibleDC (0);
512 /* create temporary bitmaps */
513 hbmTempImage
= CreateBitmap (himlSrc
->cx
, himlSrc
->cy
, 1,
514 himlSrc
->uBitsPixel
, NULL
);
515 hbmTempMask
= CreateBitmap (himlSrc
->cx
, himlSrc
->cy
, 1,
518 /* copy (and stretch) destination to temporary bitmaps.(save) */
520 SelectObject (hdcBmp
, hbmTempImage
);
521 StretchBlt (hdcBmp
, 0, 0, himlSrc
->cx
, himlSrc
->cy
,
522 himlDst
->hdcImage
, ptDst
.x
, ptDst
.y
, himlDst
->cx
, himlDst
->cy
,
525 SelectObject (hdcBmp
, hbmTempMask
);
526 StretchBlt (hdcBmp
, 0, 0, himlSrc
->cx
, himlSrc
->cy
,
527 himlDst
->hdcMask
, ptDst
.x
, ptDst
.y
, himlDst
->cx
, himlDst
->cy
,
530 /* copy (and stretch) source to destination */
532 StretchBlt (himlDst
->hdcImage
, ptDst
.x
, ptDst
.y
, himlDst
->cx
, himlDst
->cy
,
533 himlSrc
->hdcImage
, ptSrc
.x
, ptSrc
.y
, himlSrc
->cx
, himlSrc
->cy
,
536 StretchBlt (himlDst
->hdcMask
, ptDst
.x
, ptDst
.y
, himlDst
->cx
, himlDst
->cy
,
537 himlSrc
->hdcMask
, ptSrc
.x
, ptSrc
.y
, himlSrc
->cx
, himlSrc
->cy
,
540 /* copy (without stretching) temporary bitmaps to source (restore) */
542 BitBlt (himlSrc
->hdcMask
, ptSrc
.x
, ptSrc
.y
, himlSrc
->cx
, himlSrc
->cy
,
543 hdcBmp
, 0, 0, SRCCOPY
);
546 BitBlt (himlSrc
->hdcImage
, ptSrc
.x
, ptSrc
.y
, himlSrc
->cx
, himlSrc
->cy
,
547 hdcBmp
, 0, 0, SRCCOPY
);
548 /* delete temporary bitmaps */
549 DeleteObject (hbmTempMask
);
550 DeleteObject (hbmTempImage
);
555 StretchBlt (himlDst
->hdcImage
, ptDst
.x
, ptDst
.y
, himlDst
->cx
, himlDst
->cy
,
556 himlSrc
->hdcImage
, ptSrc
.x
, ptSrc
.y
, himlSrc
->cx
, himlSrc
->cy
,
560 StretchBlt (himlDst
->hdcMask
, ptDst
.x
, ptDst
.y
, himlDst
->cx
, himlDst
->cy
,
561 himlSrc
->hdcMask
, ptSrc
.x
, ptSrc
.y
, himlSrc
->cx
, himlSrc
->cy
,
569 /*************************************************************************
570 * ImageList_Create [COMCTL32.@]
572 * Creates a new image list.
575 * cx [I] image height
577 * flags [I] creation flags
578 * cInitial [I] initial number of images in the image list
579 * cGrow [I] number of images by which image list grows
582 * Success: Handle to the created image list
586 ImageList_Create (INT cx
, INT cy
, UINT flags
,
587 INT cInitial
, INT cGrow
)
592 UINT ilc
= (flags
& 0xFE);
593 static const WORD aBitBlend25
[] =
594 {0xAA, 0x00, 0x55, 0x00, 0xAA, 0x00, 0x55, 0x00};
596 static const WORD aBitBlend50
[] =
597 {0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA};
599 TRACE("(%d %d 0x%x %d %d)\n", cx
, cy
, flags
, cInitial
, cGrow
);
601 himl
= Alloc (sizeof(struct _IMAGELIST
));
605 cGrow
= (cGrow
< 4) ? 4 : (cGrow
+ 3) & ~3;
607 himl
->magic
= IMAGELIST_MAGIC
;
611 himl
->cMaxImage
= cInitial
+ 1;
612 himl
->cInitial
= cInitial
;
614 himl
->clrFg
= CLR_DEFAULT
;
615 himl
->clrBk
= CLR_NONE
;
617 /* initialize overlay mask indices */
618 for (nCount
= 0; nCount
< MAX_OVERLAYIMAGE
; nCount
++)
619 himl
->nOvlIdx
[nCount
] = -1;
621 /* Create Image & Mask DCs */
622 himl
->hdcImage
= CreateCompatibleDC (0);
625 if (himl
->flags
& ILC_MASK
){
626 himl
->hdcMask
= CreateCompatibleDC(0);
631 /* Default to ILC_COLOR4 if none of the ILC_COLOR* flags are specified */
632 if (ilc
== ILC_COLOR
)
635 if (ilc
>= ILC_COLOR4
&& ilc
<= ILC_COLOR32
)
636 himl
->uBitsPixel
= ilc
;
638 himl
->uBitsPixel
= (UINT
)GetDeviceCaps (himl
->hdcImage
, BITSPIXEL
);
640 if (himl
->cMaxImage
> 0) {
641 himl
->hbmImage
= ImageList_CreateImage(himl
->hdcImage
, himl
, himl
->cMaxImage
, cx
);
642 SelectObject(himl
->hdcImage
, himl
->hbmImage
);
646 if ((himl
->cMaxImage
> 0) && (himl
->flags
& ILC_MASK
)) {
649 imagelist_get_bitmap_size(himl
, himl
->cMaxImage
, himl
->cx
, &sz
);
650 himl
->hbmMask
= CreateBitmap (sz
.cx
, sz
.cy
, 1, 1, NULL
);
651 if (himl
->hbmMask
== 0) {
652 ERR("Error creating mask bitmap!\n");
655 SelectObject(himl
->hdcMask
, himl
->hbmMask
);
660 /* create blending brushes */
661 hbmTemp
= CreateBitmap (8, 8, 1, 1, aBitBlend25
);
662 himl
->hbrBlend25
= CreatePatternBrush (hbmTemp
);
663 DeleteObject (hbmTemp
);
665 hbmTemp
= CreateBitmap (8, 8, 1, 1, aBitBlend50
);
666 himl
->hbrBlend50
= CreatePatternBrush (hbmTemp
);
667 DeleteObject (hbmTemp
);
669 TRACE("created imagelist %p\n", himl
);
673 if (himl
) ImageList_Destroy(himl
);
678 /*************************************************************************
679 * ImageList_Destroy [COMCTL32.@]
681 * Destroys an image list.
684 * himl [I] handle to image list
692 ImageList_Destroy (HIMAGELIST himl
)
697 /* delete image bitmaps */
699 DeleteObject (himl
->hbmImage
);
701 DeleteObject (himl
->hbmMask
);
703 /* delete image & mask DCs */
705 DeleteDC(himl
->hdcImage
);
707 DeleteDC(himl
->hdcMask
);
709 /* delete blending brushes */
710 if (himl
->hbrBlend25
)
711 DeleteObject (himl
->hbrBlend25
);
712 if (himl
->hbrBlend50
)
713 DeleteObject (himl
->hbrBlend50
);
715 ZeroMemory(himl
, sizeof(*himl
));
722 /*************************************************************************
723 * ImageList_DragEnter [COMCTL32.@]
725 * Locks window update and displays the drag image at the given position.
728 * hwndLock [I] handle of the window that owns the drag image.
729 * x [I] X position of the drag image.
730 * y [I] Y position of the drag image.
737 * The position of the drag image is relative to the window, not
742 ImageList_DragEnter (HWND hwndLock
, INT x
, INT y
)
744 TRACE("(hwnd=%p x=%d y=%d)\n", hwndLock
, x
, y
);
746 if (!is_valid(InternalDrag
.himl
))
750 InternalDrag
.hwnd
= hwndLock
;
752 InternalDrag
.hwnd
= GetDesktopWindow ();
757 /* draw the drag image and save the background */
758 if (!ImageList_DragShowNolock(TRUE
)) {
766 /*************************************************************************
767 * ImageList_DragLeave [COMCTL32.@]
769 * Unlocks window update and hides the drag image.
772 * hwndLock [I] handle of the window that owns the drag image.
780 ImageList_DragLeave (HWND hwndLock
)
782 /* As we don't save drag info in the window this can lead to problems if
783 an app does not supply the same window as DragEnter */
785 InternalDrag.hwnd = hwndLock;
787 InternalDrag.hwnd = GetDesktopWindow (); */
789 hwndLock
= GetDesktopWindow();
790 if(InternalDrag
.hwnd
!= hwndLock
)
791 FIXME("DragLeave hWnd != DragEnter hWnd\n");
793 ImageList_DragShowNolock (FALSE
);
799 /*************************************************************************
800 * ImageList_InternalDragDraw [Internal]
802 * Draws the drag image.
805 * hdc [I] device context to draw into.
806 * x [I] X position of the drag image.
807 * y [I] Y position of the drag image.
814 * The position of the drag image is relative to the window, not
820 ImageList_InternalDragDraw (HDC hdc
, INT x
, INT y
)
822 IMAGELISTDRAWPARAMS imldp
;
824 ZeroMemory (&imldp
, sizeof(imldp
));
825 imldp
.cbSize
= sizeof(imldp
);
826 imldp
.himl
= InternalDrag
.himl
;
831 imldp
.rgbBk
= CLR_DEFAULT
;
832 imldp
.rgbFg
= CLR_DEFAULT
;
833 imldp
.fStyle
= ILD_NORMAL
;
834 imldp
.fState
= ILS_ALPHA
;
837 /* FIXME: instead of using the alpha blending, we should
838 * create a 50% mask, and draw it semitransparantly that way */
839 ImageList_DrawIndirect (&imldp
);
842 /*************************************************************************
843 * ImageList_DragMove [COMCTL32.@]
845 * Moves the drag image.
848 * x [I] X position of the drag image.
849 * y [I] Y position of the drag image.
856 * The position of the drag image is relative to the window, not
860 * The drag image should be drawn semitransparent.
864 ImageList_DragMove (INT x
, INT y
)
866 TRACE("(x=%d y=%d)\n", x
, y
);
868 if (!is_valid(InternalDrag
.himl
))
871 /* draw/update the drag image */
872 if (InternalDrag
.bShow
) {
876 HBITMAP hbmOffScreen
;
877 INT origNewX
, origNewY
;
878 INT origOldX
, origOldY
;
879 INT origRegX
, origRegY
;
880 INT sizeRegX
, sizeRegY
;
883 /* calculate the update region */
884 origNewX
= x
- InternalDrag
.dxHotspot
;
885 origNewY
= y
- InternalDrag
.dyHotspot
;
886 origOldX
= InternalDrag
.x
- InternalDrag
.dxHotspot
;
887 origOldY
= InternalDrag
.y
- InternalDrag
.dyHotspot
;
888 origRegX
= min(origNewX
, origOldX
);
889 origRegY
= min(origNewY
, origOldY
);
890 sizeRegX
= InternalDrag
.himl
->cx
+ abs(x
- InternalDrag
.x
);
891 sizeRegY
= InternalDrag
.himl
->cy
+ abs(y
- InternalDrag
.y
);
893 hdcDrag
= GetDCEx(InternalDrag
.hwnd
, 0,
894 DCX_WINDOW
| DCX_CACHE
| DCX_LOCKWINDOWUPDATE
);
895 hdcOffScreen
= CreateCompatibleDC(hdcDrag
);
896 hdcBg
= CreateCompatibleDC(hdcDrag
);
898 hbmOffScreen
= CreateCompatibleBitmap(hdcDrag
, sizeRegX
, sizeRegY
);
899 SelectObject(hdcOffScreen
, hbmOffScreen
);
900 SelectObject(hdcBg
, InternalDrag
.hbmBg
);
902 /* get the actual background of the update region */
903 BitBlt(hdcOffScreen
, 0, 0, sizeRegX
, sizeRegY
, hdcDrag
,
904 origRegX
, origRegY
, SRCCOPY
);
905 /* erase the old image */
906 BitBlt(hdcOffScreen
, origOldX
- origRegX
, origOldY
- origRegY
,
907 InternalDrag
.himl
->cx
, InternalDrag
.himl
->cy
, hdcBg
, 0, 0,
909 /* save the background */
910 BitBlt(hdcBg
, 0, 0, InternalDrag
.himl
->cx
, InternalDrag
.himl
->cy
,
911 hdcOffScreen
, origNewX
- origRegX
, origNewY
- origRegY
, SRCCOPY
);
913 ImageList_InternalDragDraw(hdcOffScreen
, origNewX
- origRegX
,
914 origNewY
- origRegY
);
915 /* draw the update region to the screen */
916 BitBlt(hdcDrag
, origRegX
, origRegY
, sizeRegX
, sizeRegY
,
917 hdcOffScreen
, 0, 0, SRCCOPY
);
920 DeleteDC(hdcOffScreen
);
921 DeleteObject(hbmOffScreen
);
922 ReleaseDC(InternalDrag
.hwnd
, hdcDrag
);
925 /* update the image position */
933 /*************************************************************************
934 * ImageList_DragShowNolock [COMCTL32.@]
936 * Shows or hides the drag image.
939 * bShow [I] TRUE shows the drag image, FALSE hides it.
946 * The drag image should be drawn semitransparent.
950 ImageList_DragShowNolock (BOOL bShow
)
956 if (!is_valid(InternalDrag
.himl
))
959 TRACE("bShow=0x%X!\n", bShow
);
961 /* DragImage is already visible/hidden */
962 if ((InternalDrag
.bShow
&& bShow
) || (!InternalDrag
.bShow
&& !bShow
)) {
966 /* position of the origin of the DragImage */
967 x
= InternalDrag
.x
- InternalDrag
.dxHotspot
;
968 y
= InternalDrag
.y
- InternalDrag
.dyHotspot
;
970 hdcDrag
= GetDCEx (InternalDrag
.hwnd
, 0,
971 DCX_WINDOW
| DCX_CACHE
| DCX_LOCKWINDOWUPDATE
);
976 hdcBg
= CreateCompatibleDC(hdcDrag
);
977 if (!InternalDrag
.hbmBg
) {
978 InternalDrag
.hbmBg
= CreateCompatibleBitmap(hdcDrag
,
979 InternalDrag
.himl
->cx
, InternalDrag
.himl
->cy
);
981 SelectObject(hdcBg
, InternalDrag
.hbmBg
);
984 /* save the background */
985 BitBlt(hdcBg
, 0, 0, InternalDrag
.himl
->cx
, InternalDrag
.himl
->cy
,
986 hdcDrag
, x
, y
, SRCCOPY
);
988 ImageList_InternalDragDraw(hdcDrag
, x
, y
);
991 BitBlt(hdcDrag
, x
, y
, InternalDrag
.himl
->cx
, InternalDrag
.himl
->cy
,
992 hdcBg
, 0, 0, SRCCOPY
);
995 InternalDrag
.bShow
= !InternalDrag
.bShow
;
998 ReleaseDC (InternalDrag
.hwnd
, hdcDrag
);
1003 /*************************************************************************
1004 * ImageList_Draw [COMCTL32.@]
1009 * himl [I] handle to image list
1011 * hdc [I] handle to device context
1014 * fStyle [I] drawing flags
1025 ImageList_Draw (HIMAGELIST himl
, INT i
, HDC hdc
, INT x
, INT y
, UINT fStyle
)
1027 return ImageList_DrawEx (himl
, i
, hdc
, x
, y
, 0, 0,
1028 CLR_DEFAULT
, CLR_DEFAULT
, fStyle
);
1032 /*************************************************************************
1033 * ImageList_DrawEx [COMCTL32.@]
1035 * Draws an image and allows to use extended drawing features.
1038 * himl [I] handle to image list
1040 * hdc [I] handle to device context
1045 * rgbBk [I] background color
1046 * rgbFg [I] foreground color
1047 * fStyle [I] drawing flags
1054 * Calls ImageList_DrawIndirect.
1057 * ImageList_DrawIndirect.
1061 ImageList_DrawEx (HIMAGELIST himl
, INT i
, HDC hdc
, INT x
, INT y
,
1062 INT dx
, INT dy
, COLORREF rgbBk
, COLORREF rgbFg
,
1065 IMAGELISTDRAWPARAMS imldp
;
1067 ZeroMemory (&imldp
, sizeof(imldp
));
1068 imldp
.cbSize
= sizeof(imldp
);
1076 imldp
.rgbBk
= rgbBk
;
1077 imldp
.rgbFg
= rgbFg
;
1078 imldp
.fStyle
= fStyle
;
1080 return ImageList_DrawIndirect (&imldp
);
1084 /*************************************************************************
1085 * ImageList_DrawIndirect [COMCTL32.@]
1087 * Draws an image using various parameters specified in pimldp.
1090 * pimldp [I] pointer to IMAGELISTDRAWPARAMS structure.
1098 ImageList_DrawIndirect (IMAGELISTDRAWPARAMS
*pimldp
)
1100 INT cx
, cy
, nOvlIdx
;
1101 DWORD fState
, dwRop
;
1103 COLORREF oldImageBk
, oldImageFg
;
1104 HDC hImageDC
, hImageListDC
, hMaskListDC
;
1105 HBITMAP hImageBmp
, hOldImageBmp
, hBlendMaskBmp
;
1106 BOOL bIsTransparent
, bBlend
, bResult
= FALSE
, bMask
;
1110 if (!pimldp
|| !(himl
= pimldp
->himl
)) return FALSE
;
1111 if (!is_valid(himl
)) return FALSE
;
1112 if ((pimldp
->i
< 0) || (pimldp
->i
>= himl
->cCurImage
)) return FALSE
;
1114 imagelist_point_from_index( himl
, pimldp
->i
, &pt
);
1115 pt
.x
+= pimldp
->xBitmap
;
1116 pt
.y
+= pimldp
->yBitmap
;
1118 fState
= pimldp
->cbSize
< sizeof(IMAGELISTDRAWPARAMS
) ? ILS_NORMAL
: pimldp
->fState
;
1119 fStyle
= pimldp
->fStyle
& ~ILD_OVERLAYMASK
;
1120 cx
= (pimldp
->cx
== 0) ? himl
->cx
: pimldp
->cx
;
1121 cy
= (pimldp
->cy
== 0) ? himl
->cy
: pimldp
->cy
;
1123 bIsTransparent
= (fStyle
& ILD_TRANSPARENT
);
1124 if( pimldp
->rgbBk
== CLR_NONE
)
1125 bIsTransparent
= TRUE
;
1126 if( ( pimldp
->rgbBk
== CLR_DEFAULT
) && ( himl
->clrBk
== CLR_NONE
) )
1127 bIsTransparent
= TRUE
;
1128 bMask
= (himl
->flags
& ILC_MASK
) && (fStyle
& ILD_MASK
) ;
1129 bBlend
= (fStyle
& (ILD_BLEND25
| ILD_BLEND50
) ) && !bMask
;
1131 TRACE("himl(%p) hbmMask(%p) iImage(%d) x(%d) y(%d) cx(%d) cy(%d)\n",
1132 himl
, himl
->hbmMask
, pimldp
->i
, pimldp
->x
, pimldp
->y
, cx
, cy
);
1134 /* we will use these DCs to access the images and masks in the ImageList */
1135 hImageListDC
= himl
->hdcImage
;
1136 hMaskListDC
= himl
->hdcMask
;
1138 /* these will accumulate the image and mask for the image we're drawing */
1139 hImageDC
= CreateCompatibleDC( pimldp
->hdcDst
);
1140 hImageBmp
= CreateCompatibleBitmap( pimldp
->hdcDst
, cx
, cy
);
1141 hBlendMaskBmp
= bBlend
? CreateBitmap(cx
, cy
, 1, 1, NULL
) : 0;
1143 /* Create a compatible DC. */
1144 if (!hImageListDC
|| !hImageDC
|| !hImageBmp
||
1145 (bBlend
&& !hBlendMaskBmp
) || (himl
->hbmMask
&& !hMaskListDC
))
1148 hOldImageBmp
= SelectObject(hImageDC
, hImageBmp
);
1151 * To obtain a transparent look, background color should be set
1152 * to white and foreground color to black when blting the
1155 oldImageFg
= SetTextColor( hImageDC
, RGB( 0, 0, 0 ) );
1156 oldImageBk
= SetBkColor( hImageDC
, RGB( 0xff, 0xff, 0xff ) );
1159 * Draw the initial image
1162 if (himl
->hbmMask
) {
1164 hOldBrush
= SelectObject (hImageDC
, CreateSolidBrush (GetTextColor(pimldp
->hdcDst
)));
1165 PatBlt( hImageDC
, 0, 0, cx
, cy
, PATCOPY
);
1166 BitBlt(hImageDC
, 0, 0, cx
, cy
, hMaskListDC
, pt
.x
, pt
.y
, SRCPAINT
);
1167 DeleteObject (SelectObject (hImageDC
, hOldBrush
));
1168 if( bIsTransparent
)
1170 BitBlt ( pimldp
->hdcDst
, pimldp
->x
, pimldp
->y
, cx
, cy
, hImageDC
, 0, 0, SRCAND
);
1175 HBRUSH hOldBrush
= SelectObject (hImageDC
, GetStockObject(BLACK_BRUSH
));
1176 PatBlt( hImageDC
, 0, 0, cx
, cy
, PATCOPY
);
1177 SelectObject(hImageDC
, hOldBrush
);
1180 /* blend the image with the needed solid background */
1181 COLORREF colour
= RGB(0,0,0);
1184 if( !bIsTransparent
)
1186 colour
= pimldp
->rgbBk
;
1187 if( colour
== CLR_DEFAULT
)
1188 colour
= himl
->clrBk
;
1189 if( colour
== CLR_NONE
)
1190 colour
= GetBkColor(pimldp
->hdcDst
);
1193 hOldBrush
= SelectObject (hImageDC
, CreateSolidBrush (colour
));
1194 PatBlt( hImageDC
, 0, 0, cx
, cy
, PATCOPY
);
1197 BitBlt( hImageDC
, 0, 0, cx
, cy
, hMaskListDC
, pt
.x
, pt
.y
, SRCAND
);
1198 BitBlt( hImageDC
, 0, 0, cx
, cy
, hImageListDC
, pt
.x
, pt
.y
, SRCPAINT
);
1201 BitBlt( hImageDC
, 0, 0, cx
, cy
, hImageListDC
, pt
.x
, pt
.y
, SRCCOPY
);
1202 DeleteObject (SelectObject (hImageDC
, hOldBrush
));
1205 /* Time for blending, if required */
1207 HBRUSH hBlendBrush
, hOldBrush
;
1208 COLORREF clrBlend
= pimldp
->rgbFg
;
1209 HDC hBlendMaskDC
= hImageListDC
;
1212 /* Create the blend Mask */
1213 hOldBitmap
= SelectObject(hBlendMaskDC
, hBlendMaskBmp
);
1214 hBlendBrush
= fStyle
& ILD_BLEND50
? himl
->hbrBlend50
: himl
->hbrBlend25
;
1215 hOldBrush
= SelectObject(hBlendMaskDC
, hBlendBrush
);
1216 PatBlt(hBlendMaskDC
, 0, 0, cx
, cy
, PATCOPY
);
1217 SelectObject(hBlendMaskDC
, hOldBrush
);
1219 /* Modify the blend mask if an Image Mask exist */
1221 BitBlt(hBlendMaskDC
, 0, 0, cx
, cy
, hMaskListDC
, pt
.x
, pt
.y
, 0x220326); /* NOTSRCAND */
1222 BitBlt(hBlendMaskDC
, 0, 0, cx
, cy
, hBlendMaskDC
, 0, 0, NOTSRCCOPY
);
1225 /* now apply blend to the current image given the BlendMask */
1226 if (clrBlend
== CLR_DEFAULT
) clrBlend
= GetSysColor (COLOR_HIGHLIGHT
);
1227 else if (clrBlend
== CLR_NONE
) clrBlend
= GetTextColor (pimldp
->hdcDst
);
1228 hOldBrush
= SelectObject (hImageDC
, CreateSolidBrush(clrBlend
));
1229 BitBlt (hImageDC
, 0, 0, cx
, cy
, hBlendMaskDC
, 0, 0, 0xB8074A); /* PSDPxax */
1230 DeleteObject(SelectObject(hImageDC
, hOldBrush
));
1231 SelectObject(hBlendMaskDC
, hOldBitmap
);
1234 /* Now do the overlay image, if any */
1235 nOvlIdx
= (pimldp
->fStyle
& ILD_OVERLAYMASK
) >> 8;
1236 if ( (nOvlIdx
>= 1) && (nOvlIdx
<= MAX_OVERLAYIMAGE
)) {
1237 nOvlIdx
= himl
->nOvlIdx
[nOvlIdx
- 1];
1238 if ((nOvlIdx
>= 0) && (nOvlIdx
< himl
->cCurImage
)) {
1240 imagelist_point_from_index( himl
, nOvlIdx
, &ptOvl
);
1241 ptOvl
.x
+= pimldp
->xBitmap
;
1242 if (himl
->hbmMask
&& !(fStyle
& ILD_IMAGE
))
1243 BitBlt (hImageDC
, 0, 0, cx
, cy
, hMaskListDC
, ptOvl
.x
, ptOvl
.y
, SRCAND
);
1244 BitBlt (hImageDC
, 0, 0, cx
, cy
, hImageListDC
, ptOvl
.x
, ptOvl
.y
, SRCPAINT
);
1248 if (fState
& ILS_SATURATE
) FIXME("ILS_SATURATE: unimplemented!\n");
1249 if (fState
& ILS_GLOW
) FIXME("ILS_GLOW: unimplemented!\n");
1250 if (fState
& ILS_SHADOW
) FIXME("ILS_SHADOW: unimplemented!\n");
1251 if (fState
& ILS_ALPHA
) FIXME("ILS_ALPHA: unimplemented!\n");
1253 if (fStyle
& ILD_PRESERVEALPHA
) FIXME("ILD_PRESERVEALPHA: unimplemented!\n");
1254 if (fStyle
& ILD_SCALE
) FIXME("ILD_SCALE: unimplemented!\n");
1255 if (fStyle
& ILD_DPISCALE
) FIXME("ILD_DPISCALE: unimplemented!\n");
1257 /* now copy the image to the screen */
1259 if (himl
->hbmMask
&& bIsTransparent
) {
1260 COLORREF oldDstFg
= SetTextColor(pimldp
->hdcDst
, RGB( 0, 0, 0 ) );
1261 COLORREF oldDstBk
= SetBkColor(pimldp
->hdcDst
, RGB( 0xff, 0xff, 0xff ));
1262 BitBlt (pimldp
->hdcDst
, pimldp
->x
, pimldp
->y
, cx
, cy
, hMaskListDC
, pt
.x
, pt
.y
, SRCAND
);
1263 SetBkColor(pimldp
->hdcDst
, oldDstBk
);
1264 SetTextColor(pimldp
->hdcDst
, oldDstFg
);
1267 if (fStyle
& ILD_ROP
) dwRop
= pimldp
->dwRop
;
1268 BitBlt (pimldp
->hdcDst
, pimldp
->x
, pimldp
->y
, cx
, cy
, hImageDC
, 0, 0, dwRop
);
1272 /* cleanup the mess */
1273 SetBkColor(hImageDC
, oldImageBk
);
1274 SetTextColor(hImageDC
, oldImageFg
);
1275 SelectObject(hImageDC
, hOldImageBmp
);
1277 DeleteObject(hBlendMaskBmp
);
1278 DeleteObject(hImageBmp
);
1285 /*************************************************************************
1286 * ImageList_Duplicate [COMCTL32.@]
1288 * Duplicates an image list.
1291 * himlSrc [I] source image list handle
1294 * Success: Handle of duplicated image list.
1299 ImageList_Duplicate (HIMAGELIST himlSrc
)
1303 if (!is_valid(himlSrc
)) {
1304 ERR("Invalid image list handle!\n");
1308 himlDst
= ImageList_Create (himlSrc
->cx
, himlSrc
->cy
, himlSrc
->flags
,
1309 himlSrc
->cInitial
, himlSrc
->cGrow
);
1315 imagelist_get_bitmap_size(himlSrc
, himlSrc
->cCurImage
, himlSrc
->cx
, &sz
);
1316 BitBlt (himlDst
->hdcImage
, 0, 0, sz
.cx
, sz
.cy
,
1317 himlSrc
->hdcImage
, 0, 0, SRCCOPY
);
1319 if (himlDst
->hbmMask
)
1320 BitBlt (himlDst
->hdcMask
, 0, 0, sz
.cx
, sz
.cy
,
1321 himlSrc
->hdcMask
, 0, 0, SRCCOPY
);
1323 himlDst
->cCurImage
= himlSrc
->cCurImage
;
1324 himlDst
->cMaxImage
= himlSrc
->cMaxImage
;
1330 /*************************************************************************
1331 * ImageList_EndDrag [COMCTL32.@]
1333 * Finishes a drag operation.
1344 ImageList_EndDrag (void)
1346 /* cleanup the InternalDrag struct */
1347 InternalDrag
.hwnd
= 0;
1348 ImageList_Destroy (InternalDrag
.himl
);
1349 InternalDrag
.himl
= 0;
1352 InternalDrag
.dxHotspot
= 0;
1353 InternalDrag
.dyHotspot
= 0;
1354 InternalDrag
.bShow
= FALSE
;
1355 DeleteObject(InternalDrag
.hbmBg
);
1356 InternalDrag
.hbmBg
= 0;
1360 /*************************************************************************
1361 * ImageList_GetBkColor [COMCTL32.@]
1363 * Returns the background color of an image list.
1366 * himl [I] Image list handle.
1369 * Success: background color
1374 ImageList_GetBkColor (HIMAGELIST himl
)
1376 return himl
? himl
->clrBk
: CLR_NONE
;
1380 /*************************************************************************
1381 * ImageList_GetDragImage [COMCTL32.@]
1383 * Returns the handle to the internal drag image list.
1386 * ppt [O] Pointer to the drag position. Can be NULL.
1387 * pptHotspot [O] Pointer to the position of the hot spot. Can be NULL.
1390 * Success: Handle of the drag image list.
1395 ImageList_GetDragImage (POINT
*ppt
, POINT
*pptHotspot
)
1397 if (is_valid(InternalDrag
.himl
)) {
1399 ppt
->x
= InternalDrag
.x
;
1400 ppt
->y
= InternalDrag
.y
;
1403 pptHotspot
->x
= InternalDrag
.dxHotspot
;
1404 pptHotspot
->y
= InternalDrag
.dyHotspot
;
1406 return (InternalDrag
.himl
);
1413 /*************************************************************************
1414 * ImageList_GetFlags [COMCTL32.@]
1416 * Gets the flags of the specified image list.
1419 * himl [I] Handle to image list
1429 ImageList_GetFlags(HIMAGELIST himl
)
1431 TRACE("%p\n", himl
);
1433 return is_valid(himl
) ? himl
->flags
: 0;
1437 /*************************************************************************
1438 * ImageList_GetIcon [COMCTL32.@]
1440 * Creates an icon from a masked image of an image list.
1443 * himl [I] handle to image list
1445 * flags [I] drawing style flags
1448 * Success: icon handle
1453 ImageList_GetIcon (HIMAGELIST himl
, INT i
, UINT fStyle
)
1457 HBITMAP hOldDstBitmap
;
1461 TRACE("%p %d %d\n", himl
, i
, fStyle
);
1462 if (!is_valid(himl
) || (i
< 0) || (i
>= himl
->cCurImage
)) return NULL
;
1468 /* create colour bitmap */
1470 ii
.hbmColor
= CreateCompatibleBitmap(hdcDst
, himl
->cx
, himl
->cy
);
1471 ReleaseDC(0, hdcDst
);
1473 hdcDst
= CreateCompatibleDC(0);
1475 imagelist_point_from_index( himl
, i
, &pt
);
1478 ii
.hbmMask
= CreateBitmap (himl
->cx
, himl
->cy
, 1, 1, NULL
);
1479 hOldDstBitmap
= SelectObject (hdcDst
, ii
.hbmMask
);
1480 if (himl
->hbmMask
) {
1481 BitBlt (hdcDst
, 0, 0, himl
->cx
, himl
->cy
,
1482 himl
->hdcMask
, pt
.x
, pt
.y
, SRCCOPY
);
1485 PatBlt (hdcDst
, 0, 0, himl
->cx
, himl
->cy
, BLACKNESS
);
1488 SelectObject (hdcDst
, ii
.hbmColor
);
1489 BitBlt (hdcDst
, 0, 0, himl
->cx
, himl
->cy
,
1490 himl
->hdcImage
, pt
.x
, pt
.y
, SRCCOPY
);
1493 * CreateIconIndirect requires us to deselect the bitmaps from
1494 * the DCs before calling
1496 SelectObject(hdcDst
, hOldDstBitmap
);
1498 hIcon
= CreateIconIndirect (&ii
);
1500 DeleteObject (ii
.hbmMask
);
1501 DeleteObject (ii
.hbmColor
);
1508 /*************************************************************************
1509 * ImageList_GetIconSize [COMCTL32.@]
1511 * Retrieves the size of an image in an image list.
1514 * himl [I] handle to image list
1515 * cx [O] pointer to the image width.
1516 * cy [O] pointer to the image height.
1523 * All images in an image list have the same size.
1527 ImageList_GetIconSize (HIMAGELIST himl
, INT
*cx
, INT
*cy
)
1529 if (!is_valid(himl
))
1531 if ((himl
->cx
<= 0) || (himl
->cy
<= 0))
1543 /*************************************************************************
1544 * ImageList_GetImageCount [COMCTL32.@]
1546 * Returns the number of images in an image list.
1549 * himl [I] handle to image list
1552 * Success: Number of images.
1557 ImageList_GetImageCount (HIMAGELIST himl
)
1559 if (!is_valid(himl
))
1562 return himl
->cCurImage
;
1566 /*************************************************************************
1567 * ImageList_GetImageInfo [COMCTL32.@]
1569 * Returns information about an image in an image list.
1572 * himl [I] handle to image list
1574 * pImageInfo [O] pointer to the image information
1582 ImageList_GetImageInfo (HIMAGELIST himl
, INT i
, IMAGEINFO
*pImageInfo
)
1586 if (!is_valid(himl
) || (pImageInfo
== NULL
))
1588 if ((i
< 0) || (i
>= himl
->cCurImage
))
1591 pImageInfo
->hbmImage
= himl
->hbmImage
;
1592 pImageInfo
->hbmMask
= himl
->hbmMask
;
1594 imagelist_point_from_index( himl
, i
, &pt
);
1595 pImageInfo
->rcImage
.top
= pt
.y
;
1596 pImageInfo
->rcImage
.bottom
= pt
.y
+ himl
->cy
;
1597 pImageInfo
->rcImage
.left
= pt
.x
;
1598 pImageInfo
->rcImage
.right
= pt
.x
+ himl
->cx
;
1604 /*************************************************************************
1605 * ImageList_GetImageRect [COMCTL32.@]
1607 * Retrieves the rectangle of the specified image in an image list.
1610 * himl [I] handle to image list
1612 * lpRect [O] pointer to the image rectangle
1619 * This is an UNDOCUMENTED function!!!
1623 ImageList_GetImageRect (HIMAGELIST himl
, INT i
, LPRECT lpRect
)
1627 if (!is_valid(himl
) || (lpRect
== NULL
))
1629 if ((i
< 0) || (i
>= himl
->cCurImage
))
1632 imagelist_point_from_index( himl
, i
, &pt
);
1633 lpRect
->left
= pt
.x
;
1635 lpRect
->right
= pt
.x
+ himl
->cx
;
1636 lpRect
->bottom
= pt
.y
+ himl
->cy
;
1642 /*************************************************************************
1643 * ImageList_LoadImage [COMCTL32.@]
1644 * ImageList_LoadImageA [COMCTL32.@]
1646 * Creates an image list from a bitmap, icon or cursor.
1648 * See ImageList_LoadImageW.
1652 ImageList_LoadImageA (HINSTANCE hi
, LPCSTR lpbmp
, INT cx
, INT cGrow
,
1653 COLORREF clrMask
, UINT uType
, UINT uFlags
)
1660 return ImageList_LoadImageW(hi
, (LPCWSTR
)lpbmp
, cx
, cGrow
, clrMask
,
1663 len
= MultiByteToWideChar(CP_ACP
, 0, lpbmp
, -1, NULL
, 0);
1664 lpbmpW
= Alloc(len
* sizeof(WCHAR
));
1665 MultiByteToWideChar(CP_ACP
, 0, lpbmp
, -1, lpbmpW
, len
);
1667 himl
= ImageList_LoadImageW(hi
, lpbmpW
, cx
, cGrow
, clrMask
, uType
, uFlags
);
1673 /*************************************************************************
1674 * ImageList_LoadImageW [COMCTL32.@]
1676 * Creates an image list from a bitmap, icon or cursor.
1679 * hi [I] instance handle
1680 * lpbmp [I] name or id of the image
1681 * cx [I] width of each image
1682 * cGrow [I] number of images to expand
1683 * clrMask [I] mask color
1684 * uType [I] type of image to load
1685 * uFlags [I] loading flags
1688 * Success: handle to the loaded image list
1696 ImageList_LoadImageW (HINSTANCE hi
, LPCWSTR lpbmp
, INT cx
, INT cGrow
,
1697 COLORREF clrMask
, UINT uType
, UINT uFlags
)
1699 HIMAGELIST himl
= NULL
;
1703 handle
= LoadImageW (hi
, lpbmp
, uType
, 0, 0, uFlags
);
1705 WARN("Couldn't load image\n");
1709 if (uType
== IMAGE_BITMAP
) {
1711 GetObjectW (handle
, sizeof(BITMAP
), &bmp
);
1713 /* To match windows behavior, if cx is set to zero and
1714 the flag DI_DEFAULTSIZE is specified, cx becomes the
1715 system metric value for icons. If the flag is not specified
1716 the function sets the size to the height of the bitmap */
1719 if (uFlags
& DI_DEFAULTSIZE
)
1720 cx
= GetSystemMetrics (SM_CXICON
);
1725 nImageCount
= bmp
.bmWidth
/ cx
;
1727 himl
= ImageList_Create (cx
, bmp
.bmHeight
, ILC_MASK
| ILC_COLOR
,
1728 nImageCount
, cGrow
);
1730 DeleteObject (handle
);
1733 ImageList_AddMasked (himl
, (HBITMAP
)handle
, clrMask
);
1735 else if ((uType
== IMAGE_ICON
) || (uType
== IMAGE_CURSOR
)) {
1739 GetIconInfo (handle
, &ii
);
1740 GetObjectW (ii
.hbmColor
, sizeof(BITMAP
), (LPVOID
)&bmp
);
1741 himl
= ImageList_Create (bmp
.bmWidth
, bmp
.bmHeight
,
1742 ILC_MASK
| ILC_COLOR
, 1, cGrow
);
1744 DeleteObject (ii
.hbmColor
);
1745 DeleteObject (ii
.hbmMask
);
1746 DeleteObject (handle
);
1749 ImageList_Add (himl
, ii
.hbmColor
, ii
.hbmMask
);
1750 DeleteObject (ii
.hbmColor
);
1751 DeleteObject (ii
.hbmMask
);
1754 DeleteObject (handle
);
1760 /*************************************************************************
1761 * ImageList_Merge [COMCTL32.@]
1763 * Create an image list containing a merged image from two image lists.
1766 * himl1 [I] handle to first image list
1767 * i1 [I] first image index
1768 * himl2 [I] handle to second image list
1769 * i2 [I] second image index
1770 * dx [I] X offset of the second image relative to the first.
1771 * dy [I] Y offset of the second image relative to the first.
1774 * Success: The newly created image list. It contains a single image
1775 * consisting of the second image merged with the first.
1776 * Failure: NULL, if either himl1 or himl2 are invalid.
1779 * - The returned image list should be deleted by the caller using
1780 * ImageList_Destroy() when it is no longer required.
1781 * - If either i1 or i2 are not valid image indices they will be treated
1785 ImageList_Merge (HIMAGELIST himl1
, INT i1
, HIMAGELIST himl2
, INT i2
,
1788 HIMAGELIST himlDst
= NULL
;
1790 INT xOff1
, yOff1
, xOff2
, yOff2
;
1793 TRACE("(himl1=%p i1=%d himl2=%p i2=%d dx=%d dy=%d)\n", himl1
, i1
, himl2
,
1796 if (!is_valid(himl1
) || !is_valid(himl2
))
1800 cxDst
= max (himl1
->cx
, dx
+ himl2
->cx
);
1805 cxDst
= max (himl2
->cx
, himl1
->cx
- dx
);
1810 cxDst
= max (himl1
->cx
, himl2
->cx
);
1816 cyDst
= max (himl1
->cy
, dy
+ himl2
->cy
);
1821 cyDst
= max (himl2
->cy
, himl1
->cy
- dy
);
1826 cyDst
= max (himl1
->cy
, himl2
->cy
);
1831 himlDst
= ImageList_Create (cxDst
, cyDst
, ILC_MASK
| ILC_COLOR
, 1, 1);
1835 imagelist_point_from_index( himl1
, i1
, &pt1
);
1836 imagelist_point_from_index( himl1
, i2
, &pt2
);
1839 BitBlt (himlDst
->hdcImage
, 0, 0, cxDst
, cyDst
, himl1
->hdcImage
, 0, 0, BLACKNESS
);
1840 if (i1
>= 0 && i1
< himl1
->cCurImage
)
1841 BitBlt (himlDst
->hdcImage
, xOff1
, yOff1
, himl1
->cx
, himl1
->cy
, himl1
->hdcImage
, pt1
.x
, pt1
.y
, SRCCOPY
);
1842 if (i2
>= 0 && i2
< himl2
->cCurImage
)
1844 BitBlt (himlDst
->hdcImage
, xOff2
, yOff2
, himl2
->cx
, himl2
->cy
, himl2
->hdcMask
, pt2
.x
, pt2
.y
, SRCAND
);
1845 BitBlt (himlDst
->hdcImage
, xOff2
, yOff2
, himl2
->cx
, himl2
->cy
, himl2
->hdcImage
, pt2
.x
, pt2
.y
, SRCPAINT
);
1849 BitBlt (himlDst
->hdcMask
, 0, 0, cxDst
, cyDst
, himl1
->hdcMask
, 0, 0, WHITENESS
);
1850 if (i1
>= 0 && i1
< himl1
->cCurImage
)
1851 BitBlt (himlDst
->hdcMask
, xOff1
, yOff1
, himl1
->cx
, himl1
->cy
, himl1
->hdcMask
, pt1
.x
, pt1
.y
, SRCCOPY
);
1852 if (i2
>= 0 && i2
< himl2
->cCurImage
)
1853 BitBlt (himlDst
->hdcMask
, xOff2
, yOff2
, himl2
->cx
, himl2
->cy
, himl2
->hdcMask
, pt2
.x
, pt2
.y
, SRCAND
);
1855 himlDst
->cCurImage
= 1;
1862 /***********************************************************************
1863 * DIB_GetDIBWidthBytes
1865 * Return the width of a DIB bitmap in bytes. DIB bitmap data is 32-bit aligned.
1867 static int DIB_GetDIBWidthBytes( int width
, int depth
)
1873 case 1: words
= (width
+ 31) / 32; break;
1874 case 4: words
= (width
+ 7) / 8; break;
1875 case 8: words
= (width
+ 3) / 4; break;
1877 case 16: words
= (width
+ 1) / 2; break;
1878 case 24: words
= (width
* 3 + 3)/4; break;
1881 WARN("(%d): Unsupported depth\n", depth
);
1890 /***********************************************************************
1891 * DIB_GetDIBImageBytes
1893 * Return the number of bytes used to hold the image in a DIB bitmap.
1895 static int DIB_GetDIBImageBytes( int width
, int height
, int depth
)
1897 return DIB_GetDIBWidthBytes( width
, depth
) * abs( height
);
1901 /* helper for ImageList_Read, see comments below */
1902 static BOOL
_read_bitmap(HDC hdcIml
, LPSTREAM pstm
)
1904 BITMAPFILEHEADER bmfh
;
1905 int bitsperpixel
, palspace
;
1906 char bmi_buf
[sizeof(BITMAPINFOHEADER
) + sizeof(RGBQUAD
) * 256];
1907 LPBITMAPINFO bmi
= (LPBITMAPINFO
)bmi_buf
;
1911 if (FAILED(IStream_Read ( pstm
, &bmfh
, sizeof(bmfh
), NULL
)))
1914 if (bmfh
.bfType
!= (('M'<<8)|'B'))
1917 if (FAILED(IStream_Read ( pstm
, &bmi
->bmiHeader
, sizeof(bmi
->bmiHeader
), NULL
)))
1920 if ((bmi
->bmiHeader
.biSize
!= sizeof(bmi
->bmiHeader
)))
1923 TRACE("width %u, height %u, planes %u, bpp %u\n",
1924 bmi
->bmiHeader
.biWidth
, bmi
->bmiHeader
.biHeight
,
1925 bmi
->bmiHeader
.biPlanes
, bmi
->bmiHeader
.biBitCount
);
1927 bitsperpixel
= bmi
->bmiHeader
.biPlanes
* bmi
->bmiHeader
.biBitCount
;
1928 if (bitsperpixel
<=8)
1929 palspace
= (1<<bitsperpixel
)*sizeof(RGBQUAD
);
1933 bmi
->bmiHeader
.biSizeImage
= DIB_GetDIBImageBytes(bmi
->bmiHeader
.biWidth
, bmi
->bmiHeader
.biHeight
, bitsperpixel
);
1935 /* read the palette right after the end of the bitmapinfoheader */
1936 if (palspace
&& FAILED(IStream_Read(pstm
, bmi
->bmiColors
, palspace
, NULL
)))
1939 bits
= Alloc(bmi
->bmiHeader
.biSizeImage
);
1942 if (FAILED(IStream_Read(pstm
, bits
, bmi
->bmiHeader
.biSizeImage
, NULL
)))
1945 if (!StretchDIBits(hdcIml
, 0, 0, bmi
->bmiHeader
.biWidth
, bmi
->bmiHeader
.biHeight
,
1946 0, 0, bmi
->bmiHeader
.biWidth
, bmi
->bmiHeader
.biHeight
,
1947 bits
, bmi
, DIB_RGB_COLORS
, SRCCOPY
))
1956 /*************************************************************************
1957 * ImageList_Read [COMCTL32.@]
1959 * Reads an image list from a stream.
1962 * pstm [I] pointer to a stream
1965 * Success: handle to image list
1968 * The format is like this:
1969 * ILHEAD ilheadstruct;
1971 * for the color image part:
1972 * BITMAPFILEHEADER bmfh;
1973 * BITMAPINFOHEADER bmih;
1974 * only if it has a palette:
1975 * RGBQUAD rgbs[nr_of_paletted_colors];
1977 * BYTE colorbits[imagesize];
1979 * the following only if the ILC_MASK bit is set in ILHEAD.ilFlags:
1980 * BITMAPFILEHEADER bmfh_mask;
1981 * BITMAPINFOHEADER bmih_mask;
1982 * only if it has a palette (it usually does not):
1983 * RGBQUAD rgbs[nr_of_paletted_colors];
1985 * BYTE maskbits[imagesize];
1987 HIMAGELIST WINAPI
ImageList_Read (LPSTREAM pstm
)
1993 TRACE("%p\n", pstm
);
1995 if (FAILED(IStream_Read (pstm
, &ilHead
, sizeof(ILHEAD
), NULL
)))
1997 if (ilHead
.usMagic
!= (('L' << 8) | 'I'))
1999 if (ilHead
.usVersion
!= 0x101) /* probably version? */
2002 TRACE("cx %u, cy %u, flags 0x%04x, cCurImage %u, cMaxImage %u\n",
2003 ilHead
.cx
, ilHead
.cy
, ilHead
.flags
, ilHead
.cCurImage
, ilHead
.cMaxImage
);
2005 himl
= ImageList_Create(ilHead
.cx
, ilHead
.cy
, ilHead
.flags
, ilHead
.cCurImage
, ilHead
.cMaxImage
);
2009 if (!_read_bitmap(himl
->hdcImage
, pstm
))
2011 WARN("failed to read bitmap from stream\n");
2014 if (ilHead
.flags
& ILC_MASK
)
2016 if (!_read_bitmap(himl
->hdcMask
, pstm
))
2018 WARN("failed to read mask bitmap from stream\n");
2023 himl
->cCurImage
= ilHead
.cCurImage
;
2024 himl
->cMaxImage
= ilHead
.cMaxImage
;
2026 ImageList_SetBkColor(himl
,ilHead
.bkcolor
);
2028 ImageList_SetOverlayImage(himl
,ilHead
.ovls
[i
],i
+1);
2033 /*************************************************************************
2034 * ImageList_Remove [COMCTL32.@]
2036 * Removes an image from an image list
2039 * himl [I] image list handle
2046 * FIXME: as the image list storage test shows, native comctl32 simply shifts
2047 * images without creating a new bitmap.
2050 ImageList_Remove (HIMAGELIST himl
, INT i
)
2052 HBITMAP hbmNewImage
, hbmNewMask
;
2056 TRACE("(himl=%p i=%d)\n", himl
, i
);
2058 if (!is_valid(himl
)) {
2059 ERR("Invalid image list handle!\n");
2063 if ((i
< -1) || (i
>= himl
->cCurImage
)) {
2064 TRACE("index out of range! %d\n", i
);
2072 if (himl
->cCurImage
== 0) {
2073 /* remove all on empty ImageList is allowed */
2074 TRACE("remove all on empty ImageList!\n");
2078 himl
->cMaxImage
= himl
->cInitial
+ himl
->cGrow
- 1;
2079 himl
->cCurImage
= 0;
2080 for (nCount
= 0; nCount
< MAX_OVERLAYIMAGE
; nCount
++)
2081 himl
->nOvlIdx
[nCount
] = -1;
2083 hbmNewImage
= ImageList_CreateImage(himl
->hdcImage
, himl
, himl
->cMaxImage
, himl
->cx
);
2084 SelectObject (himl
->hdcImage
, hbmNewImage
);
2085 DeleteObject (himl
->hbmImage
);
2086 himl
->hbmImage
= hbmNewImage
;
2088 if (himl
->hbmMask
) {
2090 imagelist_get_bitmap_size(himl
, himl
->cMaxImage
, himl
->cx
, &sz
);
2091 hbmNewMask
= CreateBitmap (sz
.cx
, sz
.cy
, 1, 1, NULL
);
2092 SelectObject (himl
->hdcMask
, hbmNewMask
);
2093 DeleteObject (himl
->hbmMask
);
2094 himl
->hbmMask
= hbmNewMask
;
2098 /* delete one image */
2099 TRACE("Remove single image! %d\n", i
);
2101 /* create new bitmap(s) */
2102 TRACE(" - Number of images: %d / %d (Old/New)\n",
2103 himl
->cCurImage
, himl
->cCurImage
- 1);
2105 hbmNewImage
= ImageList_CreateImage(himl
->hdcImage
, himl
, himl
->cMaxImage
, himl
->cx
);
2107 imagelist_get_bitmap_size(himl
, himl
->cMaxImage
, himl
->cx
, &sz
);
2109 hbmNewMask
= CreateBitmap (sz
.cx
, sz
.cy
, 1, 1, NULL
);
2111 hbmNewMask
= 0; /* Just to keep compiler happy! */
2113 hdcBmp
= CreateCompatibleDC (0);
2115 /* copy all images and masks prior to the "removed" image */
2117 TRACE("Pre image copy: Copy %d images\n", i
);
2119 SelectObject (hdcBmp
, hbmNewImage
);
2120 imagelist_copy_images( himl
, himl
->hdcImage
, hdcBmp
, 0, i
, 0 );
2122 if (himl
->hbmMask
) {
2123 SelectObject (hdcBmp
, hbmNewMask
);
2124 imagelist_copy_images( himl
, himl
->hdcMask
, hdcBmp
, 0, i
, 0 );
2128 /* copy all images and masks behind the removed image */
2129 if (i
< himl
->cCurImage
- 1) {
2130 TRACE("Post image copy!\n");
2132 SelectObject (hdcBmp
, hbmNewImage
);
2133 imagelist_copy_images( himl
, himl
->hdcImage
, hdcBmp
, i
+ 1,
2134 (himl
->cCurImage
- i
), i
);
2136 if (himl
->hbmMask
) {
2137 SelectObject (hdcBmp
, hbmNewMask
);
2138 imagelist_copy_images( himl
, himl
->hdcMask
, hdcBmp
, i
+ 1,
2139 (himl
->cCurImage
- i
), i
);
2145 /* delete old images and insert new ones */
2146 SelectObject (himl
->hdcImage
, hbmNewImage
);
2147 DeleteObject (himl
->hbmImage
);
2148 himl
->hbmImage
= hbmNewImage
;
2149 if (himl
->hbmMask
) {
2150 SelectObject (himl
->hdcMask
, hbmNewMask
);
2151 DeleteObject (himl
->hbmMask
);
2152 himl
->hbmMask
= hbmNewMask
;
2162 /*************************************************************************
2163 * ImageList_Replace [COMCTL32.@]
2165 * Replaces an image in an image list with a new image.
2168 * himl [I] handle to image list
2170 * hbmImage [I] handle to image bitmap
2171 * hbmMask [I] handle to mask bitmap. Can be NULL.
2179 ImageList_Replace (HIMAGELIST himl
, INT i
, HBITMAP hbmImage
,
2187 TRACE("%p %d %p %p\n", himl
, i
, hbmImage
, hbmMask
);
2189 if (!is_valid(himl
)) {
2190 ERR("Invalid image list handle!\n");
2194 if ((i
>= himl
->cMaxImage
) || (i
< 0)) {
2195 ERR("Invalid image index!\n");
2199 if (!GetObjectW(hbmImage
, sizeof(BITMAP
), (LPVOID
)&bmp
))
2202 hdcImage
= CreateCompatibleDC (0);
2205 hOldBitmap
= SelectObject (hdcImage
, hbmImage
);
2207 imagelist_point_from_index(himl
, i
, &pt
);
2208 StretchBlt (himl
->hdcImage
, pt
.x
, pt
.y
, himl
->cx
, himl
->cy
,
2209 hdcImage
, 0, 0, bmp
.bmWidth
, bmp
.bmHeight
, SRCCOPY
);
2214 HBITMAP hOldBitmapTemp
;
2216 hdcTemp
= CreateCompatibleDC(0);
2217 hOldBitmapTemp
= SelectObject(hdcTemp
, hbmMask
);
2219 StretchBlt (himl
->hdcMask
, pt
.x
, pt
.y
, himl
->cx
, himl
->cy
,
2220 hdcTemp
, 0, 0, bmp
.bmWidth
, bmp
.bmHeight
, SRCCOPY
);
2221 SelectObject(hdcTemp
, hOldBitmapTemp
);
2224 /* Remove the background from the image
2226 BitBlt (himl
->hdcImage
, pt
.x
, pt
.y
, bmp
.bmWidth
, bmp
.bmHeight
,
2227 himl
->hdcMask
, pt
.x
, pt
.y
, 0x220326); /* NOTSRCAND */
2230 SelectObject (hdcImage
, hOldBitmap
);
2231 DeleteDC (hdcImage
);
2237 /*************************************************************************
2238 * ImageList_ReplaceIcon [COMCTL32.@]
2240 * Replaces an image in an image list using an icon.
2243 * himl [I] handle to image list
2245 * hIcon [I] handle to icon
2248 * Success: index of the replaced image
2253 ImageList_ReplaceIcon (HIMAGELIST himl
, INT nIndex
, HICON hIcon
)
2263 TRACE("(%p %d %p)\n", himl
, nIndex
, hIcon
);
2265 if (!is_valid(himl
)) {
2266 ERR("invalid image list\n");
2269 if ((nIndex
>= himl
->cMaxImage
) || (nIndex
< -1)) {
2270 ERR("invalid image index %d / %d\n", nIndex
, himl
->cMaxImage
);
2274 hBestFitIcon
= CopyImage(
2277 LR_COPYFROMRESOURCE
);
2278 /* the above will fail if the icon wasn't loaded from a resource, so try
2279 * again without LR_COPYFROMRESOURCE flag */
2281 hBestFitIcon
= CopyImage(
2288 ret
= GetIconInfo (hBestFitIcon
, &ii
);
2290 DestroyIcon(hBestFitIcon
);
2294 ret
= GetObjectW (ii
.hbmMask
, sizeof(BITMAP
), (LPVOID
)&bmp
);
2296 ERR("couldn't get mask bitmap info\n");
2298 DeleteObject (ii
.hbmColor
);
2300 DeleteObject (ii
.hbmMask
);
2301 DestroyIcon(hBestFitIcon
);
2306 if (himl
->cCurImage
+ 1 > himl
->cMaxImage
)
2307 IMAGELIST_InternalExpandBitmaps (himl
, 1, 0, 0);
2309 nIndex
= himl
->cCurImage
;
2313 hdcImage
= CreateCompatibleDC (0);
2314 TRACE("hdcImage=%p\n", hdcImage
);
2316 ERR("invalid hdcImage!\n");
2318 imagelist_point_from_index(himl
, nIndex
, &pt
);
2320 SetTextColor(himl
->hdcImage
, RGB(0,0,0));
2321 SetBkColor (himl
->hdcImage
, RGB(255,255,255));
2325 hbmOldSrc
= SelectObject (hdcImage
, ii
.hbmColor
);
2326 StretchBlt (himl
->hdcImage
, pt
.x
, pt
.y
, himl
->cx
, himl
->cy
,
2327 hdcImage
, 0, 0, bmp
.bmWidth
, bmp
.bmHeight
, SRCCOPY
);
2330 SelectObject (hdcImage
, ii
.hbmMask
);
2331 StretchBlt (himl
->hdcMask
, pt
.x
, pt
.y
, himl
->cx
, himl
->cy
,
2332 hdcImage
, 0, 0, bmp
.bmWidth
, bmp
.bmHeight
, SRCCOPY
);
2337 UINT height
= bmp
.bmHeight
/ 2;
2338 hbmOldSrc
= SelectObject (hdcImage
, ii
.hbmMask
);
2339 StretchBlt (himl
->hdcImage
, pt
.x
, pt
.y
, himl
->cx
, himl
->cy
,
2340 hdcImage
, 0, height
, bmp
.bmWidth
, height
, SRCCOPY
);
2342 StretchBlt (himl
->hdcMask
, pt
.x
, pt
.y
, himl
->cx
, himl
->cy
,
2343 hdcImage
, 0, 0, bmp
.bmWidth
, height
, SRCCOPY
);
2346 SelectObject (hdcImage
, hbmOldSrc
);
2348 DestroyIcon(hBestFitIcon
);
2350 DeleteDC (hdcImage
);
2352 DeleteObject (ii
.hbmColor
);
2354 DeleteObject (ii
.hbmMask
);
2356 TRACE("Insert index = %d, himl->cCurImage = %d\n", nIndex
, himl
->cCurImage
);
2361 /*************************************************************************
2362 * ImageList_SetBkColor [COMCTL32.@]
2364 * Sets the background color of an image list.
2367 * himl [I] handle to image list
2368 * clrBk [I] background color
2371 * Success: previous background color
2376 ImageList_SetBkColor (HIMAGELIST himl
, COLORREF clrBk
)
2380 if (!is_valid(himl
))
2383 clrOldBk
= himl
->clrBk
;
2384 himl
->clrBk
= clrBk
;
2389 /*************************************************************************
2390 * ImageList_SetDragCursorImage [COMCTL32.@]
2392 * Combines the specified image with the current drag image
2395 * himlDrag [I] handle to drag image list
2396 * iDrag [I] drag image index
2397 * dxHotspot [I] X position of the hot spot
2398 * dyHotspot [I] Y position of the hot spot
2405 * - The names dxHotspot, dyHotspot are misleading because they have nothing
2406 * to do with a hotspot but are only the offset of the origin of the new
2407 * image relative to the origin of the old image.
2409 * - When this function is called and the drag image is visible, a
2410 * short flickering occurs but this matches the Win9x behavior. It is
2411 * possible to fix the flickering using code like in ImageList_DragMove.
2415 ImageList_SetDragCursorImage (HIMAGELIST himlDrag
, INT iDrag
,
2416 INT dxHotspot
, INT dyHotspot
)
2418 HIMAGELIST himlTemp
;
2421 if (!is_valid(InternalDrag
.himl
) || !is_valid(himlDrag
))
2424 TRACE(" dxH=%d dyH=%d nX=%d nY=%d\n",
2425 dxHotspot
, dyHotspot
, InternalDrag
.dxHotspot
, InternalDrag
.dyHotspot
);
2427 visible
= InternalDrag
.bShow
;
2429 himlTemp
= ImageList_Merge (InternalDrag
.himl
, 0, himlDrag
, iDrag
,
2430 dxHotspot
, dyHotspot
);
2433 /* hide the drag image */
2434 ImageList_DragShowNolock(FALSE
);
2436 if ((InternalDrag
.himl
->cx
!= himlTemp
->cx
) ||
2437 (InternalDrag
.himl
->cy
!= himlTemp
->cy
)) {
2438 /* the size of the drag image changed, invalidate the buffer */
2439 DeleteObject(InternalDrag
.hbmBg
);
2440 InternalDrag
.hbmBg
= 0;
2443 ImageList_Destroy (InternalDrag
.himl
);
2444 InternalDrag
.himl
= himlTemp
;
2447 /* show the drag image */
2448 ImageList_DragShowNolock(TRUE
);
2455 /*************************************************************************
2456 * ImageList_SetFilter [COMCTL32.@]
2458 * Sets a filter (or does something completely different)!!???
2459 * It removes 12 Bytes from the stack (3 Parameters).
2462 * himl [I] SHOULD be a handle to image list
2463 * i [I] COULD be an index?
2468 * Failure: FALSE ???
2471 * This is an UNDOCUMENTED function!!!!
2476 ImageList_SetFilter (HIMAGELIST himl
, INT i
, DWORD dwFilter
)
2478 FIXME("(%p 0x%x 0x%x):empty stub!\n", himl
, i
, dwFilter
);
2484 /*************************************************************************
2485 * ImageList_SetFlags [COMCTL32.@]
2487 * Sets the image list flags.
2490 * himl [I] Handle to image list
2491 * flags [I] Flags to set
2501 ImageList_SetFlags(HIMAGELIST himl
, DWORD flags
)
2503 FIXME("(%p %08x):empty stub\n", himl
, flags
);
2508 /*************************************************************************
2509 * ImageList_SetIconSize [COMCTL32.@]
2511 * Sets the image size of the bitmap and deletes all images.
2514 * himl [I] handle to image list
2515 * cx [I] image width
2516 * cy [I] image height
2524 ImageList_SetIconSize (HIMAGELIST himl
, INT cx
, INT cy
)
2529 if (!is_valid(himl
))
2532 /* remove all images */
2533 himl
->cMaxImage
= himl
->cInitial
+ 1;
2534 himl
->cCurImage
= 0;
2538 /* initialize overlay mask indices */
2539 for (nCount
= 0; nCount
< MAX_OVERLAYIMAGE
; nCount
++)
2540 himl
->nOvlIdx
[nCount
] = -1;
2542 hbmNew
= ImageList_CreateImage(himl
->hdcImage
, himl
, himl
->cMaxImage
, himl
->cx
);
2543 SelectObject (himl
->hdcImage
, hbmNew
);
2544 DeleteObject (himl
->hbmImage
);
2545 himl
->hbmImage
= hbmNew
;
2547 if (himl
->hbmMask
) {
2549 imagelist_get_bitmap_size(himl
, himl
->cMaxImage
, himl
->cx
, &sz
);
2550 hbmNew
= CreateBitmap (sz
.cx
, sz
.cy
, 1, 1, NULL
);
2551 SelectObject (himl
->hdcMask
, hbmNew
);
2552 DeleteObject (himl
->hbmMask
);
2553 himl
->hbmMask
= hbmNew
;
2560 /*************************************************************************
2561 * ImageList_SetImageCount [COMCTL32.@]
2563 * Resizes an image list to the specified number of images.
2566 * himl [I] handle to image list
2567 * iImageCount [I] number of images in the image list
2575 ImageList_SetImageCount (HIMAGELIST himl
, UINT iImageCount
)
2578 HBITMAP hbmNewBitmap
, hbmOld
;
2579 INT nNewCount
, nCopyCount
;
2581 TRACE("%p %d\n",himl
,iImageCount
);
2583 if (!is_valid(himl
))
2585 if (himl
->cMaxImage
> iImageCount
)
2587 himl
->cCurImage
= iImageCount
;
2588 /* TODO: shrink the bitmap when cMaxImage-cCurImage>cGrow ? */
2592 nNewCount
= iImageCount
+ himl
->cGrow
;
2593 nCopyCount
= min(himl
->cCurImage
, iImageCount
);
2595 hdcBitmap
= CreateCompatibleDC (0);
2597 hbmNewBitmap
= ImageList_CreateImage(hdcBitmap
, himl
, nNewCount
, himl
->cx
);
2599 if (hbmNewBitmap
!= 0)
2601 hbmOld
= SelectObject (hdcBitmap
, hbmNewBitmap
);
2602 imagelist_copy_images( himl
, himl
->hdcImage
, hdcBitmap
, 0, nCopyCount
, 0 );
2603 SelectObject (hdcBitmap
, hbmOld
);
2605 /* FIXME: delete 'empty' image space? */
2607 SelectObject (himl
->hdcImage
, hbmNewBitmap
);
2608 DeleteObject (himl
->hbmImage
);
2609 himl
->hbmImage
= hbmNewBitmap
;
2612 ERR("Could not create new image bitmap !\n");
2617 imagelist_get_bitmap_size( himl
, nNewCount
, himl
->cx
, &sz
);
2618 hbmNewBitmap
= CreateBitmap (sz
.cx
, sz
.cy
, 1, 1, NULL
);
2619 if (hbmNewBitmap
!= 0)
2621 hbmOld
= SelectObject (hdcBitmap
, hbmNewBitmap
);
2622 imagelist_copy_images( himl
, himl
->hdcMask
, hdcBitmap
, 0, nCopyCount
, 0 );
2623 SelectObject (hdcBitmap
, hbmOld
);
2625 /* FIXME: delete 'empty' image space? */
2627 SelectObject (himl
->hdcMask
, hbmNewBitmap
);
2628 DeleteObject (himl
->hbmMask
);
2629 himl
->hbmMask
= hbmNewBitmap
;
2632 ERR("Could not create new mask bitmap!\n");
2635 DeleteDC (hdcBitmap
);
2637 /* Update max image count and current image count */
2638 himl
->cMaxImage
= nNewCount
;
2639 himl
->cCurImage
= iImageCount
;
2645 /*************************************************************************
2646 * ImageList_SetOverlayImage [COMCTL32.@]
2648 * Assigns an overlay mask index to an existing image in an image list.
2651 * himl [I] handle to image list
2652 * iImage [I] image index
2653 * iOverlay [I] overlay mask index
2661 ImageList_SetOverlayImage (HIMAGELIST himl
, INT iImage
, INT iOverlay
)
2663 if (!is_valid(himl
))
2665 if ((iOverlay
< 1) || (iOverlay
> MAX_OVERLAYIMAGE
))
2667 if ((iImage
!=-1) && ((iImage
< 0) || (iImage
> himl
->cCurImage
)))
2669 himl
->nOvlIdx
[iOverlay
- 1] = iImage
;
2675 /* helper for ImageList_Write - write bitmap to pstm
2676 * currently everything is written as 24 bit RGB, except masks
2679 _write_bitmap(HBITMAP hBitmap
, LPSTREAM pstm
)
2681 LPBITMAPFILEHEADER bmfh
;
2682 LPBITMAPINFOHEADER bmih
;
2683 LPBYTE data
= NULL
, lpBits
;
2685 INT bitCount
, sizeImage
, offBits
, totalSize
;
2687 BOOL result
= FALSE
;
2689 if (!GetObjectW(hBitmap
, sizeof(BITMAP
), (LPVOID
)&bm
))
2692 bitCount
= bm
.bmBitsPixel
== 1 ? 1 : 24;
2693 sizeImage
= DIB_GetDIBImageBytes(bm
.bmWidth
, bm
.bmHeight
, bitCount
);
2695 totalSize
= sizeof(BITMAPFILEHEADER
) + sizeof(BITMAPINFOHEADER
);
2697 totalSize
+= (1 << bitCount
) * sizeof(RGBQUAD
);
2698 offBits
= totalSize
;
2699 totalSize
+= sizeImage
;
2701 data
= Alloc(totalSize
);
2702 bmfh
= (LPBITMAPFILEHEADER
)data
;
2703 bmih
= (LPBITMAPINFOHEADER
)(data
+ sizeof(BITMAPFILEHEADER
));
2704 lpBits
= data
+ offBits
;
2706 /* setup BITMAPFILEHEADER */
2707 bmfh
->bfType
= (('M' << 8) | 'B');
2708 bmfh
->bfSize
= offBits
;
2709 bmfh
->bfReserved1
= 0;
2710 bmfh
->bfReserved2
= 0;
2711 bmfh
->bfOffBits
= offBits
;
2713 /* setup BITMAPINFOHEADER */
2714 bmih
->biSize
= sizeof(BITMAPINFOHEADER
);
2715 bmih
->biWidth
= bm
.bmWidth
;
2716 bmih
->biHeight
= bm
.bmHeight
;
2718 bmih
->biBitCount
= bitCount
;
2719 bmih
->biCompression
= BI_RGB
;
2720 bmih
->biSizeImage
= sizeImage
;
2721 bmih
->biXPelsPerMeter
= 0;
2722 bmih
->biYPelsPerMeter
= 0;
2723 bmih
->biClrUsed
= 0;
2724 bmih
->biClrImportant
= 0;
2727 result
= GetDIBits(xdc
, hBitmap
, 0, bm
.bmHeight
, lpBits
, (BITMAPINFO
*)bmih
, DIB_RGB_COLORS
) == bm
.bmHeight
;
2732 TRACE("width %u, height %u, planes %u, bpp %u\n",
2733 bmih
->biWidth
, bmih
->biHeight
,
2734 bmih
->biPlanes
, bmih
->biBitCount
);
2738 LPBITMAPINFO inf
= (LPBITMAPINFO
)bmih
;
2739 inf
->bmiColors
[0].rgbRed
= inf
->bmiColors
[0].rgbGreen
= inf
->bmiColors
[0].rgbBlue
= 0;
2740 inf
->bmiColors
[1].rgbRed
= inf
->bmiColors
[1].rgbGreen
= inf
->bmiColors
[1].rgbBlue
= 0xff;
2743 if(FAILED(IStream_Write(pstm
, data
, totalSize
, NULL
)))
2755 /*************************************************************************
2756 * ImageList_Write [COMCTL32.@]
2758 * Writes an image list to a stream.
2761 * himl [I] handle to image list
2762 * pstm [O] Pointer to a stream.
2773 ImageList_Write (HIMAGELIST himl
, LPSTREAM pstm
)
2778 TRACE("%p %p\n", himl
, pstm
);
2780 if (!is_valid(himl
))
2783 ilHead
.usMagic
= (('L' << 8) | 'I');
2784 ilHead
.usVersion
= 0x101;
2785 ilHead
.cCurImage
= himl
->cCurImage
;
2786 ilHead
.cMaxImage
= himl
->cMaxImage
;
2787 ilHead
.cGrow
= himl
->cGrow
;
2788 ilHead
.cx
= himl
->cx
;
2789 ilHead
.cy
= himl
->cy
;
2790 ilHead
.bkcolor
= himl
->clrBk
;
2791 ilHead
.flags
= himl
->flags
;
2792 for(i
= 0; i
< 4; i
++) {
2793 ilHead
.ovls
[i
] = himl
->nOvlIdx
[i
];
2796 TRACE("cx %u, cy %u, flags 0x04%x, cCurImage %u, cMaxImage %u\n",
2797 ilHead
.cx
, ilHead
.cy
, ilHead
.flags
, ilHead
.cCurImage
, ilHead
.cMaxImage
);
2799 if(FAILED(IStream_Write(pstm
, &ilHead
, sizeof(ILHEAD
), NULL
)))
2802 /* write the bitmap */
2803 if(!_write_bitmap(himl
->hbmImage
, pstm
))
2806 /* write the mask if we have one */
2807 if(himl
->flags
& ILC_MASK
) {
2808 if(!_write_bitmap(himl
->hbmMask
, pstm
))
2816 static HBITMAP
ImageList_CreateImage(HDC hdc
, HIMAGELIST himl
, UINT count
, UINT width
)
2818 HBITMAP hbmNewBitmap
;
2819 UINT ilc
= (himl
->flags
& 0xFE);
2822 imagelist_get_bitmap_size( himl
, count
, width
, &sz
);
2824 if ((ilc
>= ILC_COLOR4
&& ilc
<= ILC_COLOR32
) || ilc
== ILC_COLOR
)
2829 TRACE("Creating DIBSection %d x %d, %d Bits per Pixel\n",
2830 sz
.cx
, sz
.cy
, himl
->uBitsPixel
);
2832 if (himl
->uBitsPixel
<= ILC_COLOR8
)
2838 colors
= 1 << himl
->uBitsPixel
;
2839 bmi
= Alloc(sizeof(BITMAPINFOHEADER
) +
2840 sizeof(PALETTEENTRY
) * colors
);
2842 pal
= (LPPALETTEENTRY
)bmi
->bmiColors
;
2843 GetPaletteEntries(GetStockObject(DEFAULT_PALETTE
), 0, colors
, pal
);
2845 /* Swap colors returned by GetPaletteEntries so we can use them for
2846 * CreateDIBSection call. */
2847 for (i
= 0; i
< colors
; i
++)
2849 temp
= pal
[i
].peBlue
;
2850 bmi
->bmiColors
[i
].rgbRed
= pal
[i
].peRed
;
2851 bmi
->bmiColors
[i
].rgbBlue
= temp
;
2856 bmi
= Alloc(sizeof(BITMAPINFOHEADER
));
2859 bmi
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
2860 bmi
->bmiHeader
.biWidth
= sz
.cx
;
2861 bmi
->bmiHeader
.biHeight
= sz
.cy
;
2862 bmi
->bmiHeader
.biPlanes
= 1;
2863 bmi
->bmiHeader
.biBitCount
= himl
->uBitsPixel
;
2864 bmi
->bmiHeader
.biCompression
= BI_RGB
;
2865 bmi
->bmiHeader
.biSizeImage
= 0;
2866 bmi
->bmiHeader
.biXPelsPerMeter
= 0;
2867 bmi
->bmiHeader
.biYPelsPerMeter
= 0;
2868 bmi
->bmiHeader
.biClrUsed
= 0;
2869 bmi
->bmiHeader
.biClrImportant
= 0;
2871 hbmNewBitmap
= CreateDIBSection(hdc
, bmi
, DIB_RGB_COLORS
, &bits
, 0, 0);
2875 else /*if (ilc == ILC_COLORDDB)*/
2877 TRACE("Creating Bitmap: %d Bits per Pixel\n", himl
->uBitsPixel
);
2879 hbmNewBitmap
= CreateBitmap (sz
.cx
, sz
.cy
, 1, himl
->uBitsPixel
, NULL
);
2881 TRACE("returning %p\n", hbmNewBitmap
);
2882 return hbmNewBitmap
;
2885 /*************************************************************************
2886 * ImageList_SetColorTable [COMCTL32.@]
2888 * Sets the color table of an image list.
2891 * himl [I] Handle to the image list.
2892 * uStartIndex [I] The first index to set.
2893 * cEntries [I] Number of entries to set.
2894 * prgb [I] New color information for color table for the image list.
2897 * Success: Number of entries in the table that were set.
2901 * ImageList_Create(), SetDIBColorTable()
2905 ImageList_SetColorTable (HIMAGELIST himl
, UINT uStartIndex
, UINT cEntries
, CONST RGBQUAD
* prgb
)
2907 return SetDIBColorTable(himl
->hdcImage
, uStartIndex
, cEntries
, prgb
);