2 * ImageList implementation
4 * Copyright 1998 Eric Kohl
5 * Copyright 2000 Jason Mawdsley
6 * Copyright 2001, 2004 Michael Stefaniuc
7 * Copyright 2001 Charles Loep for CodeWeavers
8 * Copyright 2002 Dimitrie O. Paun
9 * Copyright 2009 Owen Rudge for CodeWeavers
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public
13 * License as published by the Free Software Foundation; either
14 * version 2.1 of the License, or (at your option) any later version.
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with this library; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
27 * This code was audited for completeness against the documented features
28 * of Comctl32.dll version 6.0 on Sep. 12, 2002, by Dimitrie O. Paun.
30 * Unless otherwise noted, we believe this code to be complete, as per
31 * the specification mentioned above.
32 * If you discover missing features, or bugs, please note them below.
35 * - Add support for ILD_PRESERVEALPHA, ILD_SCALE, ILD_DPISCALE
36 * - Add support for ILS_GLOW, ILS_SHADOW, ILS_SATURATE, ILS_ALPHA
37 * - Thread-safe locking
54 #include "imagelist.h"
55 #include "wine/debug.h"
57 WINE_DEFAULT_DEBUG_CHANNEL(imagelist
);
60 #define MAX_OVERLAYIMAGE 15
62 /* internal image list data used for Drag & Drop operations */
67 /* position of the drag image relative to the window */
70 /* offset of the hotspot relative to the origin of the image */
73 /* is the drag image visible */
75 /* saved background */
79 static INTERNALDRAG InternalDrag
= { 0, 0, 0, 0, 0, 0, FALSE
, 0 };
81 static HBITMAP
ImageList_CreateImage(HDC hdc
, HIMAGELIST himl
, UINT count
, UINT width
);
83 static inline BOOL
is_valid(HIMAGELIST himl
)
85 return himl
&& himl
->magic
== IMAGELIST_MAGIC
;
89 * An imagelist with N images is tiled like this:
101 static inline UINT
imagelist_height( UINT count
)
103 return ((count
+ TILE_COUNT
- 1)/TILE_COUNT
);
106 static inline void imagelist_point_from_index( HIMAGELIST himl
, UINT index
, LPPOINT pt
)
108 pt
->x
= (index
%TILE_COUNT
) * himl
->cx
;
109 pt
->y
= (index
/TILE_COUNT
) * himl
->cy
;
112 static inline void imagelist_get_bitmap_size( HIMAGELIST himl
, UINT count
, UINT cx
, SIZE
*sz
)
114 sz
->cx
= cx
* TILE_COUNT
;
115 sz
->cy
= imagelist_height( count
) * himl
->cy
;
119 * imagelist_copy_images()
121 * Copies a block of count images from offset src in the list to offset dest.
122 * Images are copied a row at at time. Assumes hdcSrc and hdcDest are different.
124 static inline void imagelist_copy_images( HIMAGELIST himl
, HDC hdcSrc
, HDC hdcDest
,
125 UINT src
, UINT count
, UINT dest
)
131 for ( i
=0; i
<TILE_COUNT
; i
++ )
133 imagelist_point_from_index( himl
, src
+i
, &ptSrc
);
134 imagelist_point_from_index( himl
, dest
+i
, &ptDest
);
136 sz
.cy
= himl
->cy
* imagelist_height( count
- i
);
138 BitBlt( hdcDest
, ptDest
.x
, ptDest
.y
, sz
.cx
, sz
.cy
,
139 hdcSrc
, ptSrc
.x
, ptSrc
.y
, SRCCOPY
);
143 /*************************************************************************
144 * IMAGELIST_InternalExpandBitmaps [Internal]
146 * Expands the bitmaps of an image list by the given number of images.
149 * himl [I] handle to image list
150 * nImageCount [I] number of images to add
156 * This function CANNOT be used to reduce the number of images.
159 IMAGELIST_InternalExpandBitmaps (HIMAGELIST himl
, INT nImageCount
, INT cx
, INT cy
)
162 HBITMAP hbmNewBitmap
, hbmNull
;
166 if ((himl
->cCurImage
+ nImageCount
<= himl
->cMaxImage
)
170 if (cx
== 0) cx
= himl
->cx
;
171 nNewCount
= himl
->cCurImage
+ nImageCount
+ himl
->cGrow
;
173 imagelist_get_bitmap_size(himl
, nNewCount
, cx
, &sz
);
175 TRACE("Create expanded bitmaps : himl=%p x=%d y=%d count=%d\n", himl
, sz
.cx
, cy
, nNewCount
);
176 hdcBitmap
= CreateCompatibleDC (0);
178 hbmNewBitmap
= ImageList_CreateImage(hdcBitmap
, himl
, nNewCount
, cx
);
180 if (hbmNewBitmap
== 0)
181 ERR("creating new image bitmap (x=%d y=%d)!\n", sz
.cx
, cy
);
185 hbmNull
= SelectObject (hdcBitmap
, hbmNewBitmap
);
186 BitBlt (hdcBitmap
, 0, 0, sz
.cx
, sz
.cy
,
187 himl
->hdcImage
, 0, 0, SRCCOPY
);
188 SelectObject (hdcBitmap
, hbmNull
);
190 SelectObject (himl
->hdcImage
, hbmNewBitmap
);
191 DeleteObject (himl
->hbmImage
);
192 himl
->hbmImage
= hbmNewBitmap
;
194 if (himl
->flags
& ILC_MASK
)
196 hbmNewBitmap
= CreateBitmap (sz
.cx
, sz
.cy
, 1, 1, NULL
);
198 if (hbmNewBitmap
== 0)
199 ERR("creating new mask bitmap!\n");
203 hbmNull
= SelectObject (hdcBitmap
, hbmNewBitmap
);
204 BitBlt (hdcBitmap
, 0, 0, sz
.cx
, sz
.cy
,
205 himl
->hdcMask
, 0, 0, SRCCOPY
);
206 SelectObject (hdcBitmap
, hbmNull
);
208 SelectObject (himl
->hdcMask
, hbmNewBitmap
);
209 DeleteObject (himl
->hbmMask
);
210 himl
->hbmMask
= hbmNewBitmap
;
213 himl
->cMaxImage
= nNewCount
;
215 DeleteDC (hdcBitmap
);
219 /*************************************************************************
220 * ImageList_Add [COMCTL32.@]
222 * Add an image or images to an image list.
225 * himl [I] handle to image list
226 * hbmImage [I] handle to image bitmap
227 * hbmMask [I] handle to mask bitmap
230 * Success: Index of the first new image.
235 ImageList_Add (HIMAGELIST himl
, HBITMAP hbmImage
, HBITMAP hbmMask
)
237 HDC hdcBitmap
, hdcTemp
;
238 INT nFirstIndex
, nImageCount
, i
;
240 HBITMAP hOldBitmap
, hOldBitmapTemp
;
243 TRACE("himl=%p hbmimage=%p hbmmask=%p\n", himl
, hbmImage
, hbmMask
);
247 if (!GetObjectW(hbmImage
, sizeof(BITMAP
), &bmp
))
250 nImageCount
= bmp
.bmWidth
/ himl
->cx
;
252 IMAGELIST_InternalExpandBitmaps (himl
, nImageCount
, bmp
.bmWidth
, bmp
.bmHeight
);
254 hdcBitmap
= CreateCompatibleDC(0);
256 hOldBitmap
= SelectObject(hdcBitmap
, hbmImage
);
258 for (i
=0; i
<nImageCount
; i
++)
260 imagelist_point_from_index( himl
, himl
->cCurImage
+ i
, &pt
);
262 /* Copy result to the imagelist
264 BitBlt( himl
->hdcImage
, pt
.x
, pt
.y
, himl
->cx
, bmp
.bmHeight
,
265 hdcBitmap
, i
*himl
->cx
, 0, SRCCOPY
);
270 hdcTemp
= CreateCompatibleDC(0);
271 hOldBitmapTemp
= SelectObject(hdcTemp
, hbmMask
);
273 BitBlt( himl
->hdcMask
, pt
.x
, pt
.y
, himl
->cx
, bmp
.bmHeight
,
274 hdcTemp
, i
*himl
->cx
, 0, SRCCOPY
);
276 SelectObject(hdcTemp
, hOldBitmapTemp
);
279 /* Remove the background from the image
281 BitBlt( himl
->hdcImage
, pt
.x
, pt
.y
, himl
->cx
, bmp
.bmHeight
,
282 himl
->hdcMask
, pt
.x
, pt
.y
, 0x220326 ); /* NOTSRCAND */
285 SelectObject(hdcBitmap
, hOldBitmap
);
288 nFirstIndex
= himl
->cCurImage
;
289 himl
->cCurImage
+= nImageCount
;
295 /*************************************************************************
296 * ImageList_AddIcon [COMCTL32.@]
298 * Adds an icon to an image list.
301 * himl [I] handle to image list
302 * hIcon [I] handle to icon
305 * Success: index of the new image
308 #undef ImageList_AddIcon
309 INT WINAPI
ImageList_AddIcon (HIMAGELIST himl
, HICON hIcon
)
311 return ImageList_ReplaceIcon (himl
, -1, hIcon
);
315 /*************************************************************************
316 * ImageList_AddMasked [COMCTL32.@]
318 * Adds an image or images to an image list and creates a mask from the
319 * specified bitmap using the mask color.
322 * himl [I] handle to image list.
323 * hBitmap [I] handle to bitmap
324 * clrMask [I] mask color.
327 * Success: Index of the first new image.
332 ImageList_AddMasked (HIMAGELIST himl
, HBITMAP hBitmap
, COLORREF clrMask
)
334 HDC hdcMask
, hdcBitmap
;
335 INT i
, nIndex
, nImageCount
;
338 HBITMAP hMaskBitmap
=0;
342 TRACE("himl=%p hbitmap=%p clrmask=%x\n", himl
, hBitmap
, clrMask
);
346 if (!GetObjectW(hBitmap
, sizeof(BITMAP
), &bmp
))
350 nImageCount
= bmp
.bmWidth
/ himl
->cx
;
354 IMAGELIST_InternalExpandBitmaps (himl
, nImageCount
, bmp
.bmWidth
, bmp
.bmHeight
);
356 nIndex
= himl
->cCurImage
;
357 himl
->cCurImage
+= nImageCount
;
359 hdcBitmap
= CreateCompatibleDC(0);
360 hOldBitmap
= SelectObject(hdcBitmap
, hBitmap
);
362 /* Create a temp Mask so we can remove the background of the Image */
363 hdcMask
= CreateCompatibleDC(0);
364 hMaskBitmap
= CreateBitmap(bmp
.bmWidth
, bmp
.bmHeight
, 1, 1, NULL
);
365 SelectObject(hdcMask
, hMaskBitmap
);
367 /* create monochrome image to the mask bitmap */
368 bkColor
= (clrMask
!= CLR_DEFAULT
) ? clrMask
: GetPixel (hdcBitmap
, 0, 0);
369 SetBkColor (hdcBitmap
, bkColor
);
370 BitBlt (hdcMask
, 0, 0, bmp
.bmWidth
, bmp
.bmHeight
, hdcBitmap
, 0, 0, SRCCOPY
);
372 SetBkColor(hdcBitmap
, RGB(255,255,255));
375 * Remove the background from the image
377 * WINDOWS BUG ALERT!!!!!!
378 * The statement below should not be done in common practice
379 * but this is how ImageList_AddMasked works in Windows.
380 * It overwrites the original bitmap passed, this was discovered
381 * by using the same bitmap to iterate the different styles
382 * on windows where it failed (BUT ImageList_Add is OK)
383 * This is here in case some apps rely on this bug
385 * Blt mode 0x220326 is NOTSRCAND
387 BitBlt(hdcBitmap
, 0, 0, bmp
.bmWidth
, bmp
.bmHeight
, hdcMask
, 0, 0, 0x220326);
389 /* Copy result to the imagelist */
390 for (i
=0; i
<nImageCount
; i
++)
392 imagelist_point_from_index( himl
, nIndex
+ i
, &pt
);
393 BitBlt(himl
->hdcImage
, pt
.x
, pt
.y
, himl
->cx
, bmp
.bmHeight
,
394 hdcBitmap
, i
*himl
->cx
, 0, SRCCOPY
);
395 BitBlt(himl
->hdcMask
, pt
.x
, pt
.y
, himl
->cx
, bmp
.bmHeight
,
396 hdcMask
, i
*himl
->cx
, 0, SRCCOPY
);
400 SelectObject(hdcBitmap
, hOldBitmap
);
402 DeleteObject(hMaskBitmap
);
409 /*************************************************************************
410 * ImageList_BeginDrag [COMCTL32.@]
412 * Creates a temporary image list that contains one image. It will be used
416 * himlTrack [I] handle to the source image list
417 * iTrack [I] index of the drag image in the source image list
418 * dxHotspot [I] X position of the hot spot of the drag image
419 * dyHotspot [I] Y position of the hot spot of the drag image
427 ImageList_BeginDrag (HIMAGELIST himlTrack
, INT iTrack
,
428 INT dxHotspot
, INT dyHotspot
)
432 TRACE("(himlTrack=%p iTrack=%d dx=%d dy=%d)\n", himlTrack
, iTrack
,
433 dxHotspot
, dyHotspot
);
435 if (!is_valid(himlTrack
))
438 if (InternalDrag
.himl
)
439 ImageList_EndDrag ();
444 InternalDrag
.himl
= ImageList_Create (cx
, cy
, himlTrack
->flags
, 1, 1);
445 if (InternalDrag
.himl
== NULL
) {
446 WARN("Error creating drag image list!\n");
450 InternalDrag
.dxHotspot
= dxHotspot
;
451 InternalDrag
.dyHotspot
= dyHotspot
;
454 BitBlt (InternalDrag
.himl
->hdcImage
, 0, 0, cx
, cy
, himlTrack
->hdcImage
, iTrack
* cx
, 0, SRCCOPY
);
457 BitBlt (InternalDrag
.himl
->hdcMask
, 0, 0, cx
, cy
, himlTrack
->hdcMask
, iTrack
* cx
, 0, SRCCOPY
);
459 InternalDrag
.himl
->cCurImage
= 1;
465 /*************************************************************************
466 * ImageList_Copy [COMCTL32.@]
468 * Copies an image of the source image list to an image of the
469 * destination image list. Images can be copied or swapped.
472 * himlDst [I] handle to the destination image list
473 * iDst [I] destination image index.
474 * himlSrc [I] handle to the source image list
475 * iSrc [I] source image index
476 * uFlags [I] flags for the copy operation
483 * Copying from one image list to another is possible. The original
484 * implementation just copies or swaps within one image list.
485 * Could this feature become a bug??? ;-)
489 ImageList_Copy (HIMAGELIST himlDst
, INT iDst
, HIMAGELIST himlSrc
,
490 INT iSrc
, UINT uFlags
)
494 TRACE("himlDst=%p iDst=%d himlSrc=%p iSrc=%d\n", himlDst
, iDst
, himlSrc
, iSrc
);
496 if (!is_valid(himlSrc
) || !is_valid(himlDst
))
498 if ((iDst
< 0) || (iDst
>= himlDst
->cCurImage
))
500 if ((iSrc
< 0) || (iSrc
>= himlSrc
->cCurImage
))
503 imagelist_point_from_index( himlDst
, iDst
, &ptDst
);
504 imagelist_point_from_index( himlSrc
, iSrc
, &ptSrc
);
506 if (uFlags
& ILCF_SWAP
) {
509 HBITMAP hbmTempImage
, hbmTempMask
;
511 hdcBmp
= CreateCompatibleDC (0);
513 /* create temporary bitmaps */
514 hbmTempImage
= CreateBitmap (himlSrc
->cx
, himlSrc
->cy
, 1,
515 himlSrc
->uBitsPixel
, NULL
);
516 hbmTempMask
= CreateBitmap (himlSrc
->cx
, himlSrc
->cy
, 1,
519 /* copy (and stretch) destination to temporary bitmaps.(save) */
521 SelectObject (hdcBmp
, hbmTempImage
);
522 StretchBlt (hdcBmp
, 0, 0, himlSrc
->cx
, himlSrc
->cy
,
523 himlDst
->hdcImage
, ptDst
.x
, ptDst
.y
, himlDst
->cx
, himlDst
->cy
,
526 SelectObject (hdcBmp
, hbmTempMask
);
527 StretchBlt (hdcBmp
, 0, 0, himlSrc
->cx
, himlSrc
->cy
,
528 himlDst
->hdcMask
, ptDst
.x
, ptDst
.y
, himlDst
->cx
, himlDst
->cy
,
531 /* copy (and stretch) source to destination */
533 StretchBlt (himlDst
->hdcImage
, ptDst
.x
, ptDst
.y
, himlDst
->cx
, himlDst
->cy
,
534 himlSrc
->hdcImage
, ptSrc
.x
, ptSrc
.y
, himlSrc
->cx
, himlSrc
->cy
,
537 StretchBlt (himlDst
->hdcMask
, ptDst
.x
, ptDst
.y
, himlDst
->cx
, himlDst
->cy
,
538 himlSrc
->hdcMask
, ptSrc
.x
, ptSrc
.y
, himlSrc
->cx
, himlSrc
->cy
,
541 /* copy (without stretching) temporary bitmaps to source (restore) */
543 BitBlt (himlSrc
->hdcMask
, ptSrc
.x
, ptSrc
.y
, himlSrc
->cx
, himlSrc
->cy
,
544 hdcBmp
, 0, 0, SRCCOPY
);
547 BitBlt (himlSrc
->hdcImage
, ptSrc
.x
, ptSrc
.y
, himlSrc
->cx
, himlSrc
->cy
,
548 hdcBmp
, 0, 0, SRCCOPY
);
549 /* delete temporary bitmaps */
550 DeleteObject (hbmTempMask
);
551 DeleteObject (hbmTempImage
);
556 StretchBlt (himlDst
->hdcImage
, ptDst
.x
, ptDst
.y
, himlDst
->cx
, himlDst
->cy
,
557 himlSrc
->hdcImage
, ptSrc
.x
, ptSrc
.y
, himlSrc
->cx
, himlSrc
->cy
,
561 StretchBlt (himlDst
->hdcMask
, ptDst
.x
, ptDst
.y
, himlDst
->cx
, himlDst
->cy
,
562 himlSrc
->hdcMask
, ptSrc
.x
, ptSrc
.y
, himlSrc
->cx
, himlSrc
->cy
,
570 /*************************************************************************
571 * ImageList_Create [COMCTL32.@]
573 * Creates a new image list.
576 * cx [I] image height
578 * flags [I] creation flags
579 * cInitial [I] initial number of images in the image list
580 * cGrow [I] number of images by which image list grows
583 * Success: Handle to the created image list
587 ImageList_Create (INT cx
, INT cy
, UINT flags
,
588 INT cInitial
, INT cGrow
)
593 UINT ilc
= (flags
& 0xFE);
594 static const WORD aBitBlend25
[] =
595 {0xAA, 0x00, 0x55, 0x00, 0xAA, 0x00, 0x55, 0x00};
597 static const WORD aBitBlend50
[] =
598 {0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA};
600 TRACE("(%d %d 0x%x %d %d)\n", cx
, cy
, flags
, cInitial
, cGrow
);
602 himl
= Alloc (sizeof(struct _IMAGELIST
));
606 cGrow
= (cGrow
< 4) ? 4 : (cGrow
+ 3) & ~3;
608 himl
->magic
= IMAGELIST_MAGIC
;
612 himl
->cMaxImage
= cInitial
+ 1;
613 himl
->cInitial
= cInitial
;
615 himl
->clrFg
= CLR_DEFAULT
;
616 himl
->clrBk
= CLR_NONE
;
618 /* initialize overlay mask indices */
619 for (nCount
= 0; nCount
< MAX_OVERLAYIMAGE
; nCount
++)
620 himl
->nOvlIdx
[nCount
] = -1;
622 /* Create Image & Mask DCs */
623 himl
->hdcImage
= CreateCompatibleDC (0);
626 if (himl
->flags
& ILC_MASK
){
627 himl
->hdcMask
= CreateCompatibleDC(0);
632 /* Default to ILC_COLOR4 if none of the ILC_COLOR* flags are specified */
633 if (ilc
== ILC_COLOR
)
636 if (ilc
>= ILC_COLOR4
&& ilc
<= ILC_COLOR32
)
637 himl
->uBitsPixel
= ilc
;
639 himl
->uBitsPixel
= (UINT
)GetDeviceCaps (himl
->hdcImage
, BITSPIXEL
);
641 if (himl
->cMaxImage
> 0) {
642 himl
->hbmImage
= ImageList_CreateImage(himl
->hdcImage
, himl
, himl
->cMaxImage
, cx
);
643 SelectObject(himl
->hdcImage
, himl
->hbmImage
);
647 if ((himl
->cMaxImage
> 0) && (himl
->flags
& ILC_MASK
)) {
650 imagelist_get_bitmap_size(himl
, himl
->cMaxImage
, himl
->cx
, &sz
);
651 himl
->hbmMask
= CreateBitmap (sz
.cx
, sz
.cy
, 1, 1, NULL
);
652 if (himl
->hbmMask
== 0) {
653 ERR("Error creating mask bitmap!\n");
656 SelectObject(himl
->hdcMask
, himl
->hbmMask
);
661 /* create blending brushes */
662 hbmTemp
= CreateBitmap (8, 8, 1, 1, aBitBlend25
);
663 himl
->hbrBlend25
= CreatePatternBrush (hbmTemp
);
664 DeleteObject (hbmTemp
);
666 hbmTemp
= CreateBitmap (8, 8, 1, 1, aBitBlend50
);
667 himl
->hbrBlend50
= CreatePatternBrush (hbmTemp
);
668 DeleteObject (hbmTemp
);
670 TRACE("created imagelist %p\n", himl
);
674 if (himl
) ImageList_Destroy(himl
);
679 /*************************************************************************
680 * ImageList_Destroy [COMCTL32.@]
682 * Destroys an image list.
685 * himl [I] handle to image list
693 ImageList_Destroy (HIMAGELIST himl
)
698 /* delete image bitmaps */
700 DeleteObject (himl
->hbmImage
);
702 DeleteObject (himl
->hbmMask
);
704 /* delete image & mask DCs */
706 DeleteDC(himl
->hdcImage
);
708 DeleteDC(himl
->hdcMask
);
710 /* delete blending brushes */
711 if (himl
->hbrBlend25
)
712 DeleteObject (himl
->hbrBlend25
);
713 if (himl
->hbrBlend50
)
714 DeleteObject (himl
->hbrBlend50
);
716 ZeroMemory(himl
, sizeof(*himl
));
723 /*************************************************************************
724 * ImageList_DragEnter [COMCTL32.@]
726 * Locks window update and displays the drag image at the given position.
729 * hwndLock [I] handle of the window that owns the drag image.
730 * x [I] X position of the drag image.
731 * y [I] Y position of the drag image.
738 * The position of the drag image is relative to the window, not
743 ImageList_DragEnter (HWND hwndLock
, INT x
, INT y
)
745 TRACE("(hwnd=%p x=%d y=%d)\n", hwndLock
, x
, y
);
747 if (!is_valid(InternalDrag
.himl
))
751 InternalDrag
.hwnd
= hwndLock
;
753 InternalDrag
.hwnd
= GetDesktopWindow ();
758 /* draw the drag image and save the background */
759 if (!ImageList_DragShowNolock(TRUE
)) {
767 /*************************************************************************
768 * ImageList_DragLeave [COMCTL32.@]
770 * Unlocks window update and hides the drag image.
773 * hwndLock [I] handle of the window that owns the drag image.
781 ImageList_DragLeave (HWND hwndLock
)
783 /* As we don't save drag info in the window this can lead to problems if
784 an app does not supply the same window as DragEnter */
786 InternalDrag.hwnd = hwndLock;
788 InternalDrag.hwnd = GetDesktopWindow (); */
790 hwndLock
= GetDesktopWindow();
791 if(InternalDrag
.hwnd
!= hwndLock
)
792 FIXME("DragLeave hWnd != DragEnter hWnd\n");
794 ImageList_DragShowNolock (FALSE
);
800 /*************************************************************************
801 * ImageList_InternalDragDraw [Internal]
803 * Draws the drag image.
806 * hdc [I] device context to draw into.
807 * x [I] X position of the drag image.
808 * y [I] Y position of the drag image.
815 * The position of the drag image is relative to the window, not
821 ImageList_InternalDragDraw (HDC hdc
, INT x
, INT y
)
823 IMAGELISTDRAWPARAMS imldp
;
825 ZeroMemory (&imldp
, sizeof(imldp
));
826 imldp
.cbSize
= sizeof(imldp
);
827 imldp
.himl
= InternalDrag
.himl
;
832 imldp
.rgbBk
= CLR_DEFAULT
;
833 imldp
.rgbFg
= CLR_DEFAULT
;
834 imldp
.fStyle
= ILD_NORMAL
;
835 imldp
.fState
= ILS_ALPHA
;
838 /* FIXME: instead of using the alpha blending, we should
839 * create a 50% mask, and draw it semitransparantly that way */
840 ImageList_DrawIndirect (&imldp
);
843 /*************************************************************************
844 * ImageList_DragMove [COMCTL32.@]
846 * Moves the drag image.
849 * x [I] X position of the drag image.
850 * y [I] Y position of the drag image.
857 * The position of the drag image is relative to the window, not
861 * The drag image should be drawn semitransparent.
865 ImageList_DragMove (INT x
, INT y
)
867 TRACE("(x=%d y=%d)\n", x
, y
);
869 if (!is_valid(InternalDrag
.himl
))
872 /* draw/update the drag image */
873 if (InternalDrag
.bShow
) {
877 HBITMAP hbmOffScreen
;
878 INT origNewX
, origNewY
;
879 INT origOldX
, origOldY
;
880 INT origRegX
, origRegY
;
881 INT sizeRegX
, sizeRegY
;
884 /* calculate the update region */
885 origNewX
= x
- InternalDrag
.dxHotspot
;
886 origNewY
= y
- InternalDrag
.dyHotspot
;
887 origOldX
= InternalDrag
.x
- InternalDrag
.dxHotspot
;
888 origOldY
= InternalDrag
.y
- InternalDrag
.dyHotspot
;
889 origRegX
= min(origNewX
, origOldX
);
890 origRegY
= min(origNewY
, origOldY
);
891 sizeRegX
= InternalDrag
.himl
->cx
+ abs(x
- InternalDrag
.x
);
892 sizeRegY
= InternalDrag
.himl
->cy
+ abs(y
- InternalDrag
.y
);
894 hdcDrag
= GetDCEx(InternalDrag
.hwnd
, 0,
895 DCX_WINDOW
| DCX_CACHE
| DCX_LOCKWINDOWUPDATE
);
896 hdcOffScreen
= CreateCompatibleDC(hdcDrag
);
897 hdcBg
= CreateCompatibleDC(hdcDrag
);
899 hbmOffScreen
= CreateCompatibleBitmap(hdcDrag
, sizeRegX
, sizeRegY
);
900 SelectObject(hdcOffScreen
, hbmOffScreen
);
901 SelectObject(hdcBg
, InternalDrag
.hbmBg
);
903 /* get the actual background of the update region */
904 BitBlt(hdcOffScreen
, 0, 0, sizeRegX
, sizeRegY
, hdcDrag
,
905 origRegX
, origRegY
, SRCCOPY
);
906 /* erase the old image */
907 BitBlt(hdcOffScreen
, origOldX
- origRegX
, origOldY
- origRegY
,
908 InternalDrag
.himl
->cx
, InternalDrag
.himl
->cy
, hdcBg
, 0, 0,
910 /* save the background */
911 BitBlt(hdcBg
, 0, 0, InternalDrag
.himl
->cx
, InternalDrag
.himl
->cy
,
912 hdcOffScreen
, origNewX
- origRegX
, origNewY
- origRegY
, SRCCOPY
);
914 ImageList_InternalDragDraw(hdcOffScreen
, origNewX
- origRegX
,
915 origNewY
- origRegY
);
916 /* draw the update region to the screen */
917 BitBlt(hdcDrag
, origRegX
, origRegY
, sizeRegX
, sizeRegY
,
918 hdcOffScreen
, 0, 0, SRCCOPY
);
921 DeleteDC(hdcOffScreen
);
922 DeleteObject(hbmOffScreen
);
923 ReleaseDC(InternalDrag
.hwnd
, hdcDrag
);
926 /* update the image position */
934 /*************************************************************************
935 * ImageList_DragShowNolock [COMCTL32.@]
937 * Shows or hides the drag image.
940 * bShow [I] TRUE shows the drag image, FALSE hides it.
947 * The drag image should be drawn semitransparent.
951 ImageList_DragShowNolock (BOOL bShow
)
957 if (!is_valid(InternalDrag
.himl
))
960 TRACE("bShow=0x%X!\n", bShow
);
962 /* DragImage is already visible/hidden */
963 if ((InternalDrag
.bShow
&& bShow
) || (!InternalDrag
.bShow
&& !bShow
)) {
967 /* position of the origin of the DragImage */
968 x
= InternalDrag
.x
- InternalDrag
.dxHotspot
;
969 y
= InternalDrag
.y
- InternalDrag
.dyHotspot
;
971 hdcDrag
= GetDCEx (InternalDrag
.hwnd
, 0,
972 DCX_WINDOW
| DCX_CACHE
| DCX_LOCKWINDOWUPDATE
);
977 hdcBg
= CreateCompatibleDC(hdcDrag
);
978 if (!InternalDrag
.hbmBg
) {
979 InternalDrag
.hbmBg
= CreateCompatibleBitmap(hdcDrag
,
980 InternalDrag
.himl
->cx
, InternalDrag
.himl
->cy
);
982 SelectObject(hdcBg
, InternalDrag
.hbmBg
);
985 /* save the background */
986 BitBlt(hdcBg
, 0, 0, InternalDrag
.himl
->cx
, InternalDrag
.himl
->cy
,
987 hdcDrag
, x
, y
, SRCCOPY
);
989 ImageList_InternalDragDraw(hdcDrag
, x
, y
);
992 BitBlt(hdcDrag
, x
, y
, InternalDrag
.himl
->cx
, InternalDrag
.himl
->cy
,
993 hdcBg
, 0, 0, SRCCOPY
);
996 InternalDrag
.bShow
= !InternalDrag
.bShow
;
999 ReleaseDC (InternalDrag
.hwnd
, hdcDrag
);
1004 /*************************************************************************
1005 * ImageList_Draw [COMCTL32.@]
1010 * himl [I] handle to image list
1012 * hdc [I] handle to device context
1015 * fStyle [I] drawing flags
1026 ImageList_Draw (HIMAGELIST himl
, INT i
, HDC hdc
, INT x
, INT y
, UINT fStyle
)
1028 return ImageList_DrawEx (himl
, i
, hdc
, x
, y
, 0, 0,
1029 CLR_DEFAULT
, CLR_DEFAULT
, fStyle
);
1033 /*************************************************************************
1034 * ImageList_DrawEx [COMCTL32.@]
1036 * Draws an image and allows to use extended drawing features.
1039 * himl [I] handle to image list
1041 * hdc [I] handle to device context
1046 * rgbBk [I] background color
1047 * rgbFg [I] foreground color
1048 * fStyle [I] drawing flags
1055 * Calls ImageList_DrawIndirect.
1058 * ImageList_DrawIndirect.
1062 ImageList_DrawEx (HIMAGELIST himl
, INT i
, HDC hdc
, INT x
, INT y
,
1063 INT dx
, INT dy
, COLORREF rgbBk
, COLORREF rgbFg
,
1066 IMAGELISTDRAWPARAMS imldp
;
1068 ZeroMemory (&imldp
, sizeof(imldp
));
1069 imldp
.cbSize
= sizeof(imldp
);
1077 imldp
.rgbBk
= rgbBk
;
1078 imldp
.rgbFg
= rgbFg
;
1079 imldp
.fStyle
= fStyle
;
1081 return ImageList_DrawIndirect (&imldp
);
1085 /*************************************************************************
1086 * ImageList_DrawIndirect [COMCTL32.@]
1088 * Draws an image using various parameters specified in pimldp.
1091 * pimldp [I] pointer to IMAGELISTDRAWPARAMS structure.
1099 ImageList_DrawIndirect (IMAGELISTDRAWPARAMS
*pimldp
)
1101 INT cx
, cy
, nOvlIdx
;
1102 DWORD fState
, dwRop
;
1104 COLORREF oldImageBk
, oldImageFg
;
1105 HDC hImageDC
, hImageListDC
, hMaskListDC
;
1106 HBITMAP hImageBmp
, hOldImageBmp
, hBlendMaskBmp
;
1107 BOOL bIsTransparent
, bBlend
, bResult
= FALSE
, bMask
;
1111 if (!pimldp
|| !(himl
= pimldp
->himl
)) return FALSE
;
1112 if (!is_valid(himl
)) return FALSE
;
1113 if ((pimldp
->i
< 0) || (pimldp
->i
>= himl
->cCurImage
)) return FALSE
;
1115 imagelist_point_from_index( himl
, pimldp
->i
, &pt
);
1116 pt
.x
+= pimldp
->xBitmap
;
1117 pt
.y
+= pimldp
->yBitmap
;
1119 fState
= pimldp
->cbSize
< sizeof(IMAGELISTDRAWPARAMS
) ? ILS_NORMAL
: pimldp
->fState
;
1120 fStyle
= pimldp
->fStyle
& ~ILD_OVERLAYMASK
;
1121 cx
= (pimldp
->cx
== 0) ? himl
->cx
: pimldp
->cx
;
1122 cy
= (pimldp
->cy
== 0) ? himl
->cy
: pimldp
->cy
;
1124 bIsTransparent
= (fStyle
& ILD_TRANSPARENT
);
1125 if( pimldp
->rgbBk
== CLR_NONE
)
1126 bIsTransparent
= TRUE
;
1127 if( ( pimldp
->rgbBk
== CLR_DEFAULT
) && ( himl
->clrBk
== CLR_NONE
) )
1128 bIsTransparent
= TRUE
;
1129 bMask
= (himl
->flags
& ILC_MASK
) && (fStyle
& ILD_MASK
) ;
1130 bBlend
= (fStyle
& (ILD_BLEND25
| ILD_BLEND50
) ) && !bMask
;
1132 TRACE("himl(%p) hbmMask(%p) iImage(%d) x(%d) y(%d) cx(%d) cy(%d)\n",
1133 himl
, himl
->hbmMask
, pimldp
->i
, pimldp
->x
, pimldp
->y
, cx
, cy
);
1135 /* we will use these DCs to access the images and masks in the ImageList */
1136 hImageListDC
= himl
->hdcImage
;
1137 hMaskListDC
= himl
->hdcMask
;
1139 /* these will accumulate the image and mask for the image we're drawing */
1140 hImageDC
= CreateCompatibleDC( pimldp
->hdcDst
);
1141 hImageBmp
= CreateCompatibleBitmap( pimldp
->hdcDst
, cx
, cy
);
1142 hBlendMaskBmp
= bBlend
? CreateBitmap(cx
, cy
, 1, 1, NULL
) : 0;
1144 /* Create a compatible DC. */
1145 if (!hImageListDC
|| !hImageDC
|| !hImageBmp
||
1146 (bBlend
&& !hBlendMaskBmp
) || (himl
->hbmMask
&& !hMaskListDC
))
1149 hOldImageBmp
= SelectObject(hImageDC
, hImageBmp
);
1152 * To obtain a transparent look, background color should be set
1153 * to white and foreground color to black when blting the
1156 oldImageFg
= SetTextColor( hImageDC
, RGB( 0, 0, 0 ) );
1157 oldImageBk
= SetBkColor( hImageDC
, RGB( 0xff, 0xff, 0xff ) );
1160 * Draw the initial image
1163 if (himl
->hbmMask
) {
1165 hOldBrush
= SelectObject (hImageDC
, CreateSolidBrush (GetTextColor(pimldp
->hdcDst
)));
1166 PatBlt( hImageDC
, 0, 0, cx
, cy
, PATCOPY
);
1167 BitBlt(hImageDC
, 0, 0, cx
, cy
, hMaskListDC
, pt
.x
, pt
.y
, SRCPAINT
);
1168 DeleteObject (SelectObject (hImageDC
, hOldBrush
));
1169 if( bIsTransparent
)
1171 BitBlt ( pimldp
->hdcDst
, pimldp
->x
, pimldp
->y
, cx
, cy
, hImageDC
, 0, 0, SRCAND
);
1176 HBRUSH hOldBrush
= SelectObject (hImageDC
, GetStockObject(BLACK_BRUSH
));
1177 PatBlt( hImageDC
, 0, 0, cx
, cy
, PATCOPY
);
1178 SelectObject(hImageDC
, hOldBrush
);
1181 /* blend the image with the needed solid background */
1182 COLORREF colour
= RGB(0,0,0);
1185 if( !bIsTransparent
)
1187 colour
= pimldp
->rgbBk
;
1188 if( colour
== CLR_DEFAULT
)
1189 colour
= himl
->clrBk
;
1190 if( colour
== CLR_NONE
)
1191 colour
= GetBkColor(pimldp
->hdcDst
);
1194 hOldBrush
= SelectObject (hImageDC
, CreateSolidBrush (colour
));
1195 PatBlt( hImageDC
, 0, 0, cx
, cy
, PATCOPY
);
1198 BitBlt( hImageDC
, 0, 0, cx
, cy
, hMaskListDC
, pt
.x
, pt
.y
, SRCAND
);
1199 BitBlt( hImageDC
, 0, 0, cx
, cy
, hImageListDC
, pt
.x
, pt
.y
, SRCPAINT
);
1202 BitBlt( hImageDC
, 0, 0, cx
, cy
, hImageListDC
, pt
.x
, pt
.y
, SRCCOPY
);
1203 DeleteObject (SelectObject (hImageDC
, hOldBrush
));
1206 /* Time for blending, if required */
1208 HBRUSH hBlendBrush
, hOldBrush
;
1209 COLORREF clrBlend
= pimldp
->rgbFg
;
1210 HDC hBlendMaskDC
= hImageListDC
;
1213 /* Create the blend Mask */
1214 hOldBitmap
= SelectObject(hBlendMaskDC
, hBlendMaskBmp
);
1215 hBlendBrush
= fStyle
& ILD_BLEND50
? himl
->hbrBlend50
: himl
->hbrBlend25
;
1216 hOldBrush
= SelectObject(hBlendMaskDC
, hBlendBrush
);
1217 PatBlt(hBlendMaskDC
, 0, 0, cx
, cy
, PATCOPY
);
1218 SelectObject(hBlendMaskDC
, hOldBrush
);
1220 /* Modify the blend mask if an Image Mask exist */
1222 BitBlt(hBlendMaskDC
, 0, 0, cx
, cy
, hMaskListDC
, pt
.x
, pt
.y
, 0x220326); /* NOTSRCAND */
1223 BitBlt(hBlendMaskDC
, 0, 0, cx
, cy
, hBlendMaskDC
, 0, 0, NOTSRCCOPY
);
1226 /* now apply blend to the current image given the BlendMask */
1227 if (clrBlend
== CLR_DEFAULT
) clrBlend
= GetSysColor (COLOR_HIGHLIGHT
);
1228 else if (clrBlend
== CLR_NONE
) clrBlend
= GetTextColor (pimldp
->hdcDst
);
1229 hOldBrush
= SelectObject (hImageDC
, CreateSolidBrush(clrBlend
));
1230 BitBlt (hImageDC
, 0, 0, cx
, cy
, hBlendMaskDC
, 0, 0, 0xB8074A); /* PSDPxax */
1231 DeleteObject(SelectObject(hImageDC
, hOldBrush
));
1232 SelectObject(hBlendMaskDC
, hOldBitmap
);
1235 /* Now do the overlay image, if any */
1236 nOvlIdx
= (pimldp
->fStyle
& ILD_OVERLAYMASK
) >> 8;
1237 if ( (nOvlIdx
>= 1) && (nOvlIdx
<= MAX_OVERLAYIMAGE
)) {
1238 nOvlIdx
= himl
->nOvlIdx
[nOvlIdx
- 1];
1239 if ((nOvlIdx
>= 0) && (nOvlIdx
< himl
->cCurImage
)) {
1241 imagelist_point_from_index( himl
, nOvlIdx
, &ptOvl
);
1242 ptOvl
.x
+= pimldp
->xBitmap
;
1243 if (himl
->hbmMask
&& !(fStyle
& ILD_IMAGE
))
1244 BitBlt (hImageDC
, 0, 0, cx
, cy
, hMaskListDC
, ptOvl
.x
, ptOvl
.y
, SRCAND
);
1245 BitBlt (hImageDC
, 0, 0, cx
, cy
, hImageListDC
, ptOvl
.x
, ptOvl
.y
, SRCPAINT
);
1249 if (fState
& ILS_SATURATE
) FIXME("ILS_SATURATE: unimplemented!\n");
1250 if (fState
& ILS_GLOW
) FIXME("ILS_GLOW: unimplemented!\n");
1251 if (fState
& ILS_SHADOW
) FIXME("ILS_SHADOW: unimplemented!\n");
1252 if (fState
& ILS_ALPHA
) FIXME("ILS_ALPHA: unimplemented!\n");
1254 if (fStyle
& ILD_PRESERVEALPHA
) FIXME("ILD_PRESERVEALPHA: unimplemented!\n");
1255 if (fStyle
& ILD_SCALE
) FIXME("ILD_SCALE: unimplemented!\n");
1256 if (fStyle
& ILD_DPISCALE
) FIXME("ILD_DPISCALE: unimplemented!\n");
1258 /* now copy the image to the screen */
1260 if (himl
->hbmMask
&& bIsTransparent
) {
1261 COLORREF oldDstFg
= SetTextColor(pimldp
->hdcDst
, RGB( 0, 0, 0 ) );
1262 COLORREF oldDstBk
= SetBkColor(pimldp
->hdcDst
, RGB( 0xff, 0xff, 0xff ));
1263 BitBlt (pimldp
->hdcDst
, pimldp
->x
, pimldp
->y
, cx
, cy
, hMaskListDC
, pt
.x
, pt
.y
, SRCAND
);
1264 SetBkColor(pimldp
->hdcDst
, oldDstBk
);
1265 SetTextColor(pimldp
->hdcDst
, oldDstFg
);
1268 if (fStyle
& ILD_ROP
) dwRop
= pimldp
->dwRop
;
1269 BitBlt (pimldp
->hdcDst
, pimldp
->x
, pimldp
->y
, cx
, cy
, hImageDC
, 0, 0, dwRop
);
1273 /* cleanup the mess */
1274 SetBkColor(hImageDC
, oldImageBk
);
1275 SetTextColor(hImageDC
, oldImageFg
);
1276 SelectObject(hImageDC
, hOldImageBmp
);
1278 DeleteObject(hBlendMaskBmp
);
1279 DeleteObject(hImageBmp
);
1286 /*************************************************************************
1287 * ImageList_Duplicate [COMCTL32.@]
1289 * Duplicates an image list.
1292 * himlSrc [I] source image list handle
1295 * Success: Handle of duplicated image list.
1300 ImageList_Duplicate (HIMAGELIST himlSrc
)
1304 if (!is_valid(himlSrc
)) {
1305 ERR("Invalid image list handle!\n");
1309 himlDst
= ImageList_Create (himlSrc
->cx
, himlSrc
->cy
, himlSrc
->flags
,
1310 himlSrc
->cInitial
, himlSrc
->cGrow
);
1316 imagelist_get_bitmap_size(himlSrc
, himlSrc
->cCurImage
, himlSrc
->cx
, &sz
);
1317 BitBlt (himlDst
->hdcImage
, 0, 0, sz
.cx
, sz
.cy
,
1318 himlSrc
->hdcImage
, 0, 0, SRCCOPY
);
1320 if (himlDst
->hbmMask
)
1321 BitBlt (himlDst
->hdcMask
, 0, 0, sz
.cx
, sz
.cy
,
1322 himlSrc
->hdcMask
, 0, 0, SRCCOPY
);
1324 himlDst
->cCurImage
= himlSrc
->cCurImage
;
1325 himlDst
->cMaxImage
= himlSrc
->cMaxImage
;
1331 /*************************************************************************
1332 * ImageList_EndDrag [COMCTL32.@]
1334 * Finishes a drag operation.
1345 ImageList_EndDrag (void)
1347 /* cleanup the InternalDrag struct */
1348 InternalDrag
.hwnd
= 0;
1349 ImageList_Destroy (InternalDrag
.himl
);
1350 InternalDrag
.himl
= 0;
1353 InternalDrag
.dxHotspot
= 0;
1354 InternalDrag
.dyHotspot
= 0;
1355 InternalDrag
.bShow
= FALSE
;
1356 DeleteObject(InternalDrag
.hbmBg
);
1357 InternalDrag
.hbmBg
= 0;
1361 /*************************************************************************
1362 * ImageList_GetBkColor [COMCTL32.@]
1364 * Returns the background color of an image list.
1367 * himl [I] Image list handle.
1370 * Success: background color
1375 ImageList_GetBkColor (HIMAGELIST himl
)
1377 return himl
? himl
->clrBk
: CLR_NONE
;
1381 /*************************************************************************
1382 * ImageList_GetDragImage [COMCTL32.@]
1384 * Returns the handle to the internal drag image list.
1387 * ppt [O] Pointer to the drag position. Can be NULL.
1388 * pptHotspot [O] Pointer to the position of the hot spot. Can be NULL.
1391 * Success: Handle of the drag image list.
1396 ImageList_GetDragImage (POINT
*ppt
, POINT
*pptHotspot
)
1398 if (is_valid(InternalDrag
.himl
)) {
1400 ppt
->x
= InternalDrag
.x
;
1401 ppt
->y
= InternalDrag
.y
;
1404 pptHotspot
->x
= InternalDrag
.dxHotspot
;
1405 pptHotspot
->y
= InternalDrag
.dyHotspot
;
1407 return (InternalDrag
.himl
);
1414 /*************************************************************************
1415 * ImageList_GetFlags [COMCTL32.@]
1417 * Gets the flags of the specified image list.
1420 * himl [I] Handle to image list
1430 ImageList_GetFlags(HIMAGELIST himl
)
1432 TRACE("%p\n", himl
);
1434 return is_valid(himl
) ? himl
->flags
: 0;
1438 /*************************************************************************
1439 * ImageList_GetIcon [COMCTL32.@]
1441 * Creates an icon from a masked image of an image list.
1444 * himl [I] handle to image list
1446 * flags [I] drawing style flags
1449 * Success: icon handle
1454 ImageList_GetIcon (HIMAGELIST himl
, INT i
, UINT fStyle
)
1458 HBITMAP hOldDstBitmap
;
1462 TRACE("%p %d %d\n", himl
, i
, fStyle
);
1463 if (!is_valid(himl
) || (i
< 0) || (i
>= himl
->cCurImage
)) return NULL
;
1469 /* create colour bitmap */
1471 ii
.hbmColor
= CreateCompatibleBitmap(hdcDst
, himl
->cx
, himl
->cy
);
1472 ReleaseDC(0, hdcDst
);
1474 hdcDst
= CreateCompatibleDC(0);
1476 imagelist_point_from_index( himl
, i
, &pt
);
1479 ii
.hbmMask
= CreateBitmap (himl
->cx
, himl
->cy
, 1, 1, NULL
);
1480 hOldDstBitmap
= SelectObject (hdcDst
, ii
.hbmMask
);
1481 if (himl
->hbmMask
) {
1482 BitBlt (hdcDst
, 0, 0, himl
->cx
, himl
->cy
,
1483 himl
->hdcMask
, pt
.x
, pt
.y
, SRCCOPY
);
1486 PatBlt (hdcDst
, 0, 0, himl
->cx
, himl
->cy
, BLACKNESS
);
1489 SelectObject (hdcDst
, ii
.hbmColor
);
1490 BitBlt (hdcDst
, 0, 0, himl
->cx
, himl
->cy
,
1491 himl
->hdcImage
, pt
.x
, pt
.y
, SRCCOPY
);
1494 * CreateIconIndirect requires us to deselect the bitmaps from
1495 * the DCs before calling
1497 SelectObject(hdcDst
, hOldDstBitmap
);
1499 hIcon
= CreateIconIndirect (&ii
);
1501 DeleteObject (ii
.hbmMask
);
1502 DeleteObject (ii
.hbmColor
);
1509 /*************************************************************************
1510 * ImageList_GetIconSize [COMCTL32.@]
1512 * Retrieves the size of an image in an image list.
1515 * himl [I] handle to image list
1516 * cx [O] pointer to the image width.
1517 * cy [O] pointer to the image height.
1524 * All images in an image list have the same size.
1528 ImageList_GetIconSize (HIMAGELIST himl
, INT
*cx
, INT
*cy
)
1530 if (!is_valid(himl
))
1532 if ((himl
->cx
<= 0) || (himl
->cy
<= 0))
1544 /*************************************************************************
1545 * ImageList_GetImageCount [COMCTL32.@]
1547 * Returns the number of images in an image list.
1550 * himl [I] handle to image list
1553 * Success: Number of images.
1558 ImageList_GetImageCount (HIMAGELIST himl
)
1560 if (!is_valid(himl
))
1563 return himl
->cCurImage
;
1567 /*************************************************************************
1568 * ImageList_GetImageInfo [COMCTL32.@]
1570 * Returns information about an image in an image list.
1573 * himl [I] handle to image list
1575 * pImageInfo [O] pointer to the image information
1583 ImageList_GetImageInfo (HIMAGELIST himl
, INT i
, IMAGEINFO
*pImageInfo
)
1587 if (!is_valid(himl
) || (pImageInfo
== NULL
))
1589 if ((i
< 0) || (i
>= himl
->cCurImage
))
1592 pImageInfo
->hbmImage
= himl
->hbmImage
;
1593 pImageInfo
->hbmMask
= himl
->hbmMask
;
1595 imagelist_point_from_index( himl
, i
, &pt
);
1596 pImageInfo
->rcImage
.top
= pt
.y
;
1597 pImageInfo
->rcImage
.bottom
= pt
.y
+ himl
->cy
;
1598 pImageInfo
->rcImage
.left
= pt
.x
;
1599 pImageInfo
->rcImage
.right
= pt
.x
+ himl
->cx
;
1605 /*************************************************************************
1606 * ImageList_GetImageRect [COMCTL32.@]
1608 * Retrieves the rectangle of the specified image in an image list.
1611 * himl [I] handle to image list
1613 * lpRect [O] pointer to the image rectangle
1620 * This is an UNDOCUMENTED function!!!
1624 ImageList_GetImageRect (HIMAGELIST himl
, INT i
, LPRECT lpRect
)
1628 if (!is_valid(himl
) || (lpRect
== NULL
))
1630 if ((i
< 0) || (i
>= himl
->cCurImage
))
1633 imagelist_point_from_index( himl
, i
, &pt
);
1634 lpRect
->left
= pt
.x
;
1636 lpRect
->right
= pt
.x
+ himl
->cx
;
1637 lpRect
->bottom
= pt
.y
+ himl
->cy
;
1643 /*************************************************************************
1644 * ImageList_LoadImage [COMCTL32.@]
1645 * ImageList_LoadImageA [COMCTL32.@]
1647 * Creates an image list from a bitmap, icon or cursor.
1649 * See ImageList_LoadImageW.
1653 ImageList_LoadImageA (HINSTANCE hi
, LPCSTR lpbmp
, INT cx
, INT cGrow
,
1654 COLORREF clrMask
, UINT uType
, UINT uFlags
)
1661 return ImageList_LoadImageW(hi
, (LPCWSTR
)lpbmp
, cx
, cGrow
, clrMask
,
1664 len
= MultiByteToWideChar(CP_ACP
, 0, lpbmp
, -1, NULL
, 0);
1665 lpbmpW
= Alloc(len
* sizeof(WCHAR
));
1666 MultiByteToWideChar(CP_ACP
, 0, lpbmp
, -1, lpbmpW
, len
);
1668 himl
= ImageList_LoadImageW(hi
, lpbmpW
, cx
, cGrow
, clrMask
, uType
, uFlags
);
1674 /*************************************************************************
1675 * ImageList_LoadImageW [COMCTL32.@]
1677 * Creates an image list from a bitmap, icon or cursor.
1680 * hi [I] instance handle
1681 * lpbmp [I] name or id of the image
1682 * cx [I] width of each image
1683 * cGrow [I] number of images to expand
1684 * clrMask [I] mask color
1685 * uType [I] type of image to load
1686 * uFlags [I] loading flags
1689 * Success: handle to the loaded image list
1697 ImageList_LoadImageW (HINSTANCE hi
, LPCWSTR lpbmp
, INT cx
, INT cGrow
,
1698 COLORREF clrMask
, UINT uType
, UINT uFlags
)
1700 HIMAGELIST himl
= NULL
;
1704 handle
= LoadImageW (hi
, lpbmp
, uType
, 0, 0, uFlags
);
1706 WARN("Couldn't load image\n");
1710 if (uType
== IMAGE_BITMAP
) {
1712 GetObjectW (handle
, sizeof(BITMAP
), &bmp
);
1714 /* To match windows behavior, if cx is set to zero and
1715 the flag DI_DEFAULTSIZE is specified, cx becomes the
1716 system metric value for icons. If the flag is not specified
1717 the function sets the size to the height of the bitmap */
1720 if (uFlags
& DI_DEFAULTSIZE
)
1721 cx
= GetSystemMetrics (SM_CXICON
);
1726 nImageCount
= bmp
.bmWidth
/ cx
;
1728 himl
= ImageList_Create (cx
, bmp
.bmHeight
, ILC_MASK
| ILC_COLOR
,
1729 nImageCount
, cGrow
);
1731 DeleteObject (handle
);
1734 ImageList_AddMasked (himl
, handle
, clrMask
);
1736 else if ((uType
== IMAGE_ICON
) || (uType
== IMAGE_CURSOR
)) {
1740 GetIconInfo (handle
, &ii
);
1741 GetObjectW (ii
.hbmColor
, sizeof(BITMAP
), &bmp
);
1742 himl
= ImageList_Create (bmp
.bmWidth
, bmp
.bmHeight
,
1743 ILC_MASK
| ILC_COLOR
, 1, cGrow
);
1745 DeleteObject (ii
.hbmColor
);
1746 DeleteObject (ii
.hbmMask
);
1747 DeleteObject (handle
);
1750 ImageList_Add (himl
, ii
.hbmColor
, ii
.hbmMask
);
1751 DeleteObject (ii
.hbmColor
);
1752 DeleteObject (ii
.hbmMask
);
1755 DeleteObject (handle
);
1761 /*************************************************************************
1762 * ImageList_Merge [COMCTL32.@]
1764 * Create an image list containing a merged image from two image lists.
1767 * himl1 [I] handle to first image list
1768 * i1 [I] first image index
1769 * himl2 [I] handle to second image list
1770 * i2 [I] second image index
1771 * dx [I] X offset of the second image relative to the first.
1772 * dy [I] Y offset of the second image relative to the first.
1775 * Success: The newly created image list. It contains a single image
1776 * consisting of the second image merged with the first.
1777 * Failure: NULL, if either himl1 or himl2 are invalid.
1780 * - The returned image list should be deleted by the caller using
1781 * ImageList_Destroy() when it is no longer required.
1782 * - If either i1 or i2 are not valid image indices they will be treated
1786 ImageList_Merge (HIMAGELIST himl1
, INT i1
, HIMAGELIST himl2
, INT i2
,
1789 HIMAGELIST himlDst
= NULL
;
1791 INT xOff1
, yOff1
, xOff2
, yOff2
;
1794 TRACE("(himl1=%p i1=%d himl2=%p i2=%d dx=%d dy=%d)\n", himl1
, i1
, himl2
,
1797 if (!is_valid(himl1
) || !is_valid(himl2
))
1801 cxDst
= max (himl1
->cx
, dx
+ himl2
->cx
);
1806 cxDst
= max (himl2
->cx
, himl1
->cx
- dx
);
1811 cxDst
= max (himl1
->cx
, himl2
->cx
);
1817 cyDst
= max (himl1
->cy
, dy
+ himl2
->cy
);
1822 cyDst
= max (himl2
->cy
, himl1
->cy
- dy
);
1827 cyDst
= max (himl1
->cy
, himl2
->cy
);
1832 himlDst
= ImageList_Create (cxDst
, cyDst
, ILC_MASK
| ILC_COLOR
, 1, 1);
1836 imagelist_point_from_index( himl1
, i1
, &pt1
);
1837 imagelist_point_from_index( himl1
, i2
, &pt2
);
1840 BitBlt (himlDst
->hdcImage
, 0, 0, cxDst
, cyDst
, himl1
->hdcImage
, 0, 0, BLACKNESS
);
1841 if (i1
>= 0 && i1
< himl1
->cCurImage
)
1842 BitBlt (himlDst
->hdcImage
, xOff1
, yOff1
, himl1
->cx
, himl1
->cy
, himl1
->hdcImage
, pt1
.x
, pt1
.y
, SRCCOPY
);
1843 if (i2
>= 0 && i2
< himl2
->cCurImage
)
1845 BitBlt (himlDst
->hdcImage
, xOff2
, yOff2
, himl2
->cx
, himl2
->cy
, himl2
->hdcMask
, pt2
.x
, pt2
.y
, SRCAND
);
1846 BitBlt (himlDst
->hdcImage
, xOff2
, yOff2
, himl2
->cx
, himl2
->cy
, himl2
->hdcImage
, pt2
.x
, pt2
.y
, SRCPAINT
);
1850 BitBlt (himlDst
->hdcMask
, 0, 0, cxDst
, cyDst
, himl1
->hdcMask
, 0, 0, WHITENESS
);
1851 if (i1
>= 0 && i1
< himl1
->cCurImage
)
1852 BitBlt (himlDst
->hdcMask
, xOff1
, yOff1
, himl1
->cx
, himl1
->cy
, himl1
->hdcMask
, pt1
.x
, pt1
.y
, SRCCOPY
);
1853 if (i2
>= 0 && i2
< himl2
->cCurImage
)
1854 BitBlt (himlDst
->hdcMask
, xOff2
, yOff2
, himl2
->cx
, himl2
->cy
, himl2
->hdcMask
, pt2
.x
, pt2
.y
, SRCAND
);
1856 himlDst
->cCurImage
= 1;
1863 /***********************************************************************
1864 * DIB_GetDIBWidthBytes
1866 * Return the width of a DIB bitmap in bytes. DIB bitmap data is 32-bit aligned.
1868 static int DIB_GetDIBWidthBytes( int width
, int depth
)
1874 case 1: words
= (width
+ 31) / 32; break;
1875 case 4: words
= (width
+ 7) / 8; break;
1876 case 8: words
= (width
+ 3) / 4; break;
1878 case 16: words
= (width
+ 1) / 2; break;
1879 case 24: words
= (width
* 3 + 3)/4; break;
1882 WARN("(%d): Unsupported depth\n", depth
);
1891 /***********************************************************************
1892 * DIB_GetDIBImageBytes
1894 * Return the number of bytes used to hold the image in a DIB bitmap.
1896 static int DIB_GetDIBImageBytes( int width
, int height
, int depth
)
1898 return DIB_GetDIBWidthBytes( width
, depth
) * abs( height
);
1902 /* helper for ImageList_Read, see comments below */
1903 static BOOL
_read_bitmap(HDC hdcIml
, LPSTREAM pstm
)
1905 BITMAPFILEHEADER bmfh
;
1906 int bitsperpixel
, palspace
;
1907 char bmi_buf
[sizeof(BITMAPINFOHEADER
) + sizeof(RGBQUAD
) * 256];
1908 LPBITMAPINFO bmi
= (LPBITMAPINFO
)bmi_buf
;
1912 if (FAILED(IStream_Read ( pstm
, &bmfh
, sizeof(bmfh
), NULL
)))
1915 if (bmfh
.bfType
!= (('M'<<8)|'B'))
1918 if (FAILED(IStream_Read ( pstm
, &bmi
->bmiHeader
, sizeof(bmi
->bmiHeader
), NULL
)))
1921 if ((bmi
->bmiHeader
.biSize
!= sizeof(bmi
->bmiHeader
)))
1924 TRACE("width %u, height %u, planes %u, bpp %u\n",
1925 bmi
->bmiHeader
.biWidth
, bmi
->bmiHeader
.biHeight
,
1926 bmi
->bmiHeader
.biPlanes
, bmi
->bmiHeader
.biBitCount
);
1928 bitsperpixel
= bmi
->bmiHeader
.biPlanes
* bmi
->bmiHeader
.biBitCount
;
1929 if (bitsperpixel
<=8)
1930 palspace
= (1<<bitsperpixel
)*sizeof(RGBQUAD
);
1934 bmi
->bmiHeader
.biSizeImage
= DIB_GetDIBImageBytes(bmi
->bmiHeader
.biWidth
, bmi
->bmiHeader
.biHeight
, bitsperpixel
);
1936 /* read the palette right after the end of the bitmapinfoheader */
1937 if (palspace
&& FAILED(IStream_Read(pstm
, bmi
->bmiColors
, palspace
, NULL
)))
1940 bits
= Alloc(bmi
->bmiHeader
.biSizeImage
);
1943 if (FAILED(IStream_Read(pstm
, bits
, bmi
->bmiHeader
.biSizeImage
, NULL
)))
1946 if (!StretchDIBits(hdcIml
, 0, 0, bmi
->bmiHeader
.biWidth
, bmi
->bmiHeader
.biHeight
,
1947 0, 0, bmi
->bmiHeader
.biWidth
, bmi
->bmiHeader
.biHeight
,
1948 bits
, bmi
, DIB_RGB_COLORS
, SRCCOPY
))
1957 /*************************************************************************
1958 * ImageList_Read [COMCTL32.@]
1960 * Reads an image list from a stream.
1963 * pstm [I] pointer to a stream
1966 * Success: handle to image list
1969 * The format is like this:
1970 * ILHEAD ilheadstruct;
1972 * for the color image part:
1973 * BITMAPFILEHEADER bmfh;
1974 * BITMAPINFOHEADER bmih;
1975 * only if it has a palette:
1976 * RGBQUAD rgbs[nr_of_paletted_colors];
1978 * BYTE colorbits[imagesize];
1980 * the following only if the ILC_MASK bit is set in ILHEAD.ilFlags:
1981 * BITMAPFILEHEADER bmfh_mask;
1982 * BITMAPINFOHEADER bmih_mask;
1983 * only if it has a palette (it usually does not):
1984 * RGBQUAD rgbs[nr_of_paletted_colors];
1986 * BYTE maskbits[imagesize];
1988 HIMAGELIST WINAPI
ImageList_Read (LPSTREAM pstm
)
1994 TRACE("%p\n", pstm
);
1996 if (FAILED(IStream_Read (pstm
, &ilHead
, sizeof(ILHEAD
), NULL
)))
1998 if (ilHead
.usMagic
!= (('L' << 8) | 'I'))
2000 if (ilHead
.usVersion
!= 0x101) /* probably version? */
2003 TRACE("cx %u, cy %u, flags 0x%04x, cCurImage %u, cMaxImage %u\n",
2004 ilHead
.cx
, ilHead
.cy
, ilHead
.flags
, ilHead
.cCurImage
, ilHead
.cMaxImage
);
2006 himl
= ImageList_Create(ilHead
.cx
, ilHead
.cy
, ilHead
.flags
, ilHead
.cCurImage
, ilHead
.cMaxImage
);
2010 if (!_read_bitmap(himl
->hdcImage
, pstm
))
2012 WARN("failed to read bitmap from stream\n");
2015 if (ilHead
.flags
& ILC_MASK
)
2017 if (!_read_bitmap(himl
->hdcMask
, pstm
))
2019 WARN("failed to read mask bitmap from stream\n");
2024 himl
->cCurImage
= ilHead
.cCurImage
;
2025 himl
->cMaxImage
= ilHead
.cMaxImage
;
2027 ImageList_SetBkColor(himl
,ilHead
.bkcolor
);
2029 ImageList_SetOverlayImage(himl
,ilHead
.ovls
[i
],i
+1);
2034 /*************************************************************************
2035 * ImageList_Remove [COMCTL32.@]
2037 * Removes an image from an image list
2040 * himl [I] image list handle
2047 * FIXME: as the image list storage test shows, native comctl32 simply shifts
2048 * images without creating a new bitmap.
2051 ImageList_Remove (HIMAGELIST himl
, INT i
)
2053 HBITMAP hbmNewImage
, hbmNewMask
;
2057 TRACE("(himl=%p i=%d)\n", himl
, i
);
2059 if (!is_valid(himl
)) {
2060 ERR("Invalid image list handle!\n");
2064 if ((i
< -1) || (i
>= himl
->cCurImage
)) {
2065 TRACE("index out of range! %d\n", i
);
2073 if (himl
->cCurImage
== 0) {
2074 /* remove all on empty ImageList is allowed */
2075 TRACE("remove all on empty ImageList!\n");
2079 himl
->cMaxImage
= himl
->cInitial
+ himl
->cGrow
- 1;
2080 himl
->cCurImage
= 0;
2081 for (nCount
= 0; nCount
< MAX_OVERLAYIMAGE
; nCount
++)
2082 himl
->nOvlIdx
[nCount
] = -1;
2084 hbmNewImage
= ImageList_CreateImage(himl
->hdcImage
, himl
, himl
->cMaxImage
, himl
->cx
);
2085 SelectObject (himl
->hdcImage
, hbmNewImage
);
2086 DeleteObject (himl
->hbmImage
);
2087 himl
->hbmImage
= hbmNewImage
;
2089 if (himl
->hbmMask
) {
2091 imagelist_get_bitmap_size(himl
, himl
->cMaxImage
, himl
->cx
, &sz
);
2092 hbmNewMask
= CreateBitmap (sz
.cx
, sz
.cy
, 1, 1, NULL
);
2093 SelectObject (himl
->hdcMask
, hbmNewMask
);
2094 DeleteObject (himl
->hbmMask
);
2095 himl
->hbmMask
= hbmNewMask
;
2099 /* delete one image */
2100 TRACE("Remove single image! %d\n", i
);
2102 /* create new bitmap(s) */
2103 TRACE(" - Number of images: %d / %d (Old/New)\n",
2104 himl
->cCurImage
, himl
->cCurImage
- 1);
2106 hbmNewImage
= ImageList_CreateImage(himl
->hdcImage
, himl
, himl
->cMaxImage
, himl
->cx
);
2108 imagelist_get_bitmap_size(himl
, himl
->cMaxImage
, himl
->cx
, &sz
);
2110 hbmNewMask
= CreateBitmap (sz
.cx
, sz
.cy
, 1, 1, NULL
);
2112 hbmNewMask
= 0; /* Just to keep compiler happy! */
2114 hdcBmp
= CreateCompatibleDC (0);
2116 /* copy all images and masks prior to the "removed" image */
2118 TRACE("Pre image copy: Copy %d images\n", i
);
2120 SelectObject (hdcBmp
, hbmNewImage
);
2121 imagelist_copy_images( himl
, himl
->hdcImage
, hdcBmp
, 0, i
, 0 );
2123 if (himl
->hbmMask
) {
2124 SelectObject (hdcBmp
, hbmNewMask
);
2125 imagelist_copy_images( himl
, himl
->hdcMask
, hdcBmp
, 0, i
, 0 );
2129 /* copy all images and masks behind the removed image */
2130 if (i
< himl
->cCurImage
- 1) {
2131 TRACE("Post image copy!\n");
2133 SelectObject (hdcBmp
, hbmNewImage
);
2134 imagelist_copy_images( himl
, himl
->hdcImage
, hdcBmp
, i
+ 1,
2135 (himl
->cCurImage
- i
), i
);
2137 if (himl
->hbmMask
) {
2138 SelectObject (hdcBmp
, hbmNewMask
);
2139 imagelist_copy_images( himl
, himl
->hdcMask
, hdcBmp
, i
+ 1,
2140 (himl
->cCurImage
- i
), i
);
2146 /* delete old images and insert new ones */
2147 SelectObject (himl
->hdcImage
, hbmNewImage
);
2148 DeleteObject (himl
->hbmImage
);
2149 himl
->hbmImage
= hbmNewImage
;
2150 if (himl
->hbmMask
) {
2151 SelectObject (himl
->hdcMask
, hbmNewMask
);
2152 DeleteObject (himl
->hbmMask
);
2153 himl
->hbmMask
= hbmNewMask
;
2163 /*************************************************************************
2164 * ImageList_Replace [COMCTL32.@]
2166 * Replaces an image in an image list with a new image.
2169 * himl [I] handle to image list
2171 * hbmImage [I] handle to image bitmap
2172 * hbmMask [I] handle to mask bitmap. Can be NULL.
2180 ImageList_Replace (HIMAGELIST himl
, INT i
, HBITMAP hbmImage
,
2188 TRACE("%p %d %p %p\n", himl
, i
, hbmImage
, hbmMask
);
2190 if (!is_valid(himl
)) {
2191 ERR("Invalid image list handle!\n");
2195 if ((i
>= himl
->cMaxImage
) || (i
< 0)) {
2196 ERR("Invalid image index!\n");
2200 if (!GetObjectW(hbmImage
, sizeof(BITMAP
), &bmp
))
2203 hdcImage
= CreateCompatibleDC (0);
2206 hOldBitmap
= SelectObject (hdcImage
, hbmImage
);
2208 imagelist_point_from_index(himl
, i
, &pt
);
2209 StretchBlt (himl
->hdcImage
, pt
.x
, pt
.y
, himl
->cx
, himl
->cy
,
2210 hdcImage
, 0, 0, bmp
.bmWidth
, bmp
.bmHeight
, SRCCOPY
);
2215 HBITMAP hOldBitmapTemp
;
2217 hdcTemp
= CreateCompatibleDC(0);
2218 hOldBitmapTemp
= SelectObject(hdcTemp
, hbmMask
);
2220 StretchBlt (himl
->hdcMask
, pt
.x
, pt
.y
, himl
->cx
, himl
->cy
,
2221 hdcTemp
, 0, 0, bmp
.bmWidth
, bmp
.bmHeight
, SRCCOPY
);
2222 SelectObject(hdcTemp
, hOldBitmapTemp
);
2225 /* Remove the background from the image
2227 BitBlt (himl
->hdcImage
, pt
.x
, pt
.y
, bmp
.bmWidth
, bmp
.bmHeight
,
2228 himl
->hdcMask
, pt
.x
, pt
.y
, 0x220326); /* NOTSRCAND */
2231 SelectObject (hdcImage
, hOldBitmap
);
2232 DeleteDC (hdcImage
);
2238 /*************************************************************************
2239 * ImageList_ReplaceIcon [COMCTL32.@]
2241 * Replaces an image in an image list using an icon.
2244 * himl [I] handle to image list
2246 * hIcon [I] handle to icon
2249 * Success: index of the replaced image
2254 ImageList_ReplaceIcon (HIMAGELIST himl
, INT nIndex
, HICON hIcon
)
2264 TRACE("(%p %d %p)\n", himl
, nIndex
, hIcon
);
2266 if (!is_valid(himl
)) {
2267 ERR("invalid image list\n");
2270 if ((nIndex
>= himl
->cMaxImage
) || (nIndex
< -1)) {
2271 ERR("invalid image index %d / %d\n", nIndex
, himl
->cMaxImage
);
2275 hBestFitIcon
= CopyImage(
2278 LR_COPYFROMRESOURCE
);
2279 /* the above will fail if the icon wasn't loaded from a resource, so try
2280 * again without LR_COPYFROMRESOURCE flag */
2282 hBestFitIcon
= CopyImage(
2289 ret
= GetIconInfo (hBestFitIcon
, &ii
);
2291 DestroyIcon(hBestFitIcon
);
2295 ret
= GetObjectW (ii
.hbmMask
, sizeof(BITMAP
), &bmp
);
2297 ERR("couldn't get mask bitmap info\n");
2299 DeleteObject (ii
.hbmColor
);
2301 DeleteObject (ii
.hbmMask
);
2302 DestroyIcon(hBestFitIcon
);
2307 if (himl
->cCurImage
+ 1 > himl
->cMaxImage
)
2308 IMAGELIST_InternalExpandBitmaps (himl
, 1, 0, 0);
2310 nIndex
= himl
->cCurImage
;
2314 hdcImage
= CreateCompatibleDC (0);
2315 TRACE("hdcImage=%p\n", hdcImage
);
2317 ERR("invalid hdcImage!\n");
2319 imagelist_point_from_index(himl
, nIndex
, &pt
);
2321 SetTextColor(himl
->hdcImage
, RGB(0,0,0));
2322 SetBkColor (himl
->hdcImage
, RGB(255,255,255));
2326 hbmOldSrc
= SelectObject (hdcImage
, ii
.hbmColor
);
2327 StretchBlt (himl
->hdcImage
, pt
.x
, pt
.y
, himl
->cx
, himl
->cy
,
2328 hdcImage
, 0, 0, bmp
.bmWidth
, bmp
.bmHeight
, SRCCOPY
);
2331 SelectObject (hdcImage
, ii
.hbmMask
);
2332 StretchBlt (himl
->hdcMask
, pt
.x
, pt
.y
, himl
->cx
, himl
->cy
,
2333 hdcImage
, 0, 0, bmp
.bmWidth
, bmp
.bmHeight
, SRCCOPY
);
2338 UINT height
= bmp
.bmHeight
/ 2;
2339 hbmOldSrc
= SelectObject (hdcImage
, ii
.hbmMask
);
2340 StretchBlt (himl
->hdcImage
, pt
.x
, pt
.y
, himl
->cx
, himl
->cy
,
2341 hdcImage
, 0, height
, bmp
.bmWidth
, height
, SRCCOPY
);
2343 StretchBlt (himl
->hdcMask
, pt
.x
, pt
.y
, himl
->cx
, himl
->cy
,
2344 hdcImage
, 0, 0, bmp
.bmWidth
, height
, SRCCOPY
);
2347 SelectObject (hdcImage
, hbmOldSrc
);
2349 DestroyIcon(hBestFitIcon
);
2351 DeleteDC (hdcImage
);
2353 DeleteObject (ii
.hbmColor
);
2355 DeleteObject (ii
.hbmMask
);
2357 TRACE("Insert index = %d, himl->cCurImage = %d\n", nIndex
, himl
->cCurImage
);
2362 /*************************************************************************
2363 * ImageList_SetBkColor [COMCTL32.@]
2365 * Sets the background color of an image list.
2368 * himl [I] handle to image list
2369 * clrBk [I] background color
2372 * Success: previous background color
2377 ImageList_SetBkColor (HIMAGELIST himl
, COLORREF clrBk
)
2381 if (!is_valid(himl
))
2384 clrOldBk
= himl
->clrBk
;
2385 himl
->clrBk
= clrBk
;
2390 /*************************************************************************
2391 * ImageList_SetDragCursorImage [COMCTL32.@]
2393 * Combines the specified image with the current drag image
2396 * himlDrag [I] handle to drag image list
2397 * iDrag [I] drag image index
2398 * dxHotspot [I] X position of the hot spot
2399 * dyHotspot [I] Y position of the hot spot
2406 * - The names dxHotspot, dyHotspot are misleading because they have nothing
2407 * to do with a hotspot but are only the offset of the origin of the new
2408 * image relative to the origin of the old image.
2410 * - When this function is called and the drag image is visible, a
2411 * short flickering occurs but this matches the Win9x behavior. It is
2412 * possible to fix the flickering using code like in ImageList_DragMove.
2416 ImageList_SetDragCursorImage (HIMAGELIST himlDrag
, INT iDrag
,
2417 INT dxHotspot
, INT dyHotspot
)
2419 HIMAGELIST himlTemp
;
2422 if (!is_valid(InternalDrag
.himl
) || !is_valid(himlDrag
))
2425 TRACE(" dxH=%d dyH=%d nX=%d nY=%d\n",
2426 dxHotspot
, dyHotspot
, InternalDrag
.dxHotspot
, InternalDrag
.dyHotspot
);
2428 visible
= InternalDrag
.bShow
;
2430 himlTemp
= ImageList_Merge (InternalDrag
.himl
, 0, himlDrag
, iDrag
,
2431 dxHotspot
, dyHotspot
);
2434 /* hide the drag image */
2435 ImageList_DragShowNolock(FALSE
);
2437 if ((InternalDrag
.himl
->cx
!= himlTemp
->cx
) ||
2438 (InternalDrag
.himl
->cy
!= himlTemp
->cy
)) {
2439 /* the size of the drag image changed, invalidate the buffer */
2440 DeleteObject(InternalDrag
.hbmBg
);
2441 InternalDrag
.hbmBg
= 0;
2444 ImageList_Destroy (InternalDrag
.himl
);
2445 InternalDrag
.himl
= himlTemp
;
2448 /* show the drag image */
2449 ImageList_DragShowNolock(TRUE
);
2456 /*************************************************************************
2457 * ImageList_SetFilter [COMCTL32.@]
2459 * Sets a filter (or does something completely different)!!???
2460 * It removes 12 Bytes from the stack (3 Parameters).
2463 * himl [I] SHOULD be a handle to image list
2464 * i [I] COULD be an index?
2469 * Failure: FALSE ???
2472 * This is an UNDOCUMENTED function!!!!
2477 ImageList_SetFilter (HIMAGELIST himl
, INT i
, DWORD dwFilter
)
2479 FIXME("(%p 0x%x 0x%x):empty stub!\n", himl
, i
, dwFilter
);
2485 /*************************************************************************
2486 * ImageList_SetFlags [COMCTL32.@]
2488 * Sets the image list flags.
2491 * himl [I] Handle to image list
2492 * flags [I] Flags to set
2502 ImageList_SetFlags(HIMAGELIST himl
, DWORD flags
)
2504 FIXME("(%p %08x):empty stub\n", himl
, flags
);
2509 /*************************************************************************
2510 * ImageList_SetIconSize [COMCTL32.@]
2512 * Sets the image size of the bitmap and deletes all images.
2515 * himl [I] handle to image list
2516 * cx [I] image width
2517 * cy [I] image height
2525 ImageList_SetIconSize (HIMAGELIST himl
, INT cx
, INT cy
)
2530 if (!is_valid(himl
))
2533 /* remove all images */
2534 himl
->cMaxImage
= himl
->cInitial
+ 1;
2535 himl
->cCurImage
= 0;
2539 /* initialize overlay mask indices */
2540 for (nCount
= 0; nCount
< MAX_OVERLAYIMAGE
; nCount
++)
2541 himl
->nOvlIdx
[nCount
] = -1;
2543 hbmNew
= ImageList_CreateImage(himl
->hdcImage
, himl
, himl
->cMaxImage
, himl
->cx
);
2544 SelectObject (himl
->hdcImage
, hbmNew
);
2545 DeleteObject (himl
->hbmImage
);
2546 himl
->hbmImage
= hbmNew
;
2548 if (himl
->hbmMask
) {
2550 imagelist_get_bitmap_size(himl
, himl
->cMaxImage
, himl
->cx
, &sz
);
2551 hbmNew
= CreateBitmap (sz
.cx
, sz
.cy
, 1, 1, NULL
);
2552 SelectObject (himl
->hdcMask
, hbmNew
);
2553 DeleteObject (himl
->hbmMask
);
2554 himl
->hbmMask
= hbmNew
;
2561 /*************************************************************************
2562 * ImageList_SetImageCount [COMCTL32.@]
2564 * Resizes an image list to the specified number of images.
2567 * himl [I] handle to image list
2568 * iImageCount [I] number of images in the image list
2576 ImageList_SetImageCount (HIMAGELIST himl
, UINT iImageCount
)
2579 HBITMAP hbmNewBitmap
, hbmOld
;
2580 INT nNewCount
, nCopyCount
;
2582 TRACE("%p %d\n",himl
,iImageCount
);
2584 if (!is_valid(himl
))
2586 if (himl
->cMaxImage
> iImageCount
)
2588 himl
->cCurImage
= iImageCount
;
2589 /* TODO: shrink the bitmap when cMaxImage-cCurImage>cGrow ? */
2593 nNewCount
= iImageCount
+ himl
->cGrow
;
2594 nCopyCount
= min(himl
->cCurImage
, iImageCount
);
2596 hdcBitmap
= CreateCompatibleDC (0);
2598 hbmNewBitmap
= ImageList_CreateImage(hdcBitmap
, himl
, nNewCount
, himl
->cx
);
2600 if (hbmNewBitmap
!= 0)
2602 hbmOld
= SelectObject (hdcBitmap
, hbmNewBitmap
);
2603 imagelist_copy_images( himl
, himl
->hdcImage
, hdcBitmap
, 0, nCopyCount
, 0 );
2604 SelectObject (hdcBitmap
, hbmOld
);
2606 /* FIXME: delete 'empty' image space? */
2608 SelectObject (himl
->hdcImage
, hbmNewBitmap
);
2609 DeleteObject (himl
->hbmImage
);
2610 himl
->hbmImage
= hbmNewBitmap
;
2613 ERR("Could not create new image bitmap !\n");
2618 imagelist_get_bitmap_size( himl
, nNewCount
, himl
->cx
, &sz
);
2619 hbmNewBitmap
= CreateBitmap (sz
.cx
, sz
.cy
, 1, 1, NULL
);
2620 if (hbmNewBitmap
!= 0)
2622 hbmOld
= SelectObject (hdcBitmap
, hbmNewBitmap
);
2623 imagelist_copy_images( himl
, himl
->hdcMask
, hdcBitmap
, 0, nCopyCount
, 0 );
2624 SelectObject (hdcBitmap
, hbmOld
);
2626 /* FIXME: delete 'empty' image space? */
2628 SelectObject (himl
->hdcMask
, hbmNewBitmap
);
2629 DeleteObject (himl
->hbmMask
);
2630 himl
->hbmMask
= hbmNewBitmap
;
2633 ERR("Could not create new mask bitmap!\n");
2636 DeleteDC (hdcBitmap
);
2638 /* Update max image count and current image count */
2639 himl
->cMaxImage
= nNewCount
;
2640 himl
->cCurImage
= iImageCount
;
2646 /*************************************************************************
2647 * ImageList_SetOverlayImage [COMCTL32.@]
2649 * Assigns an overlay mask index to an existing image in an image list.
2652 * himl [I] handle to image list
2653 * iImage [I] image index
2654 * iOverlay [I] overlay mask index
2662 ImageList_SetOverlayImage (HIMAGELIST himl
, INT iImage
, INT iOverlay
)
2664 if (!is_valid(himl
))
2666 if ((iOverlay
< 1) || (iOverlay
> MAX_OVERLAYIMAGE
))
2668 if ((iImage
!=-1) && ((iImage
< 0) || (iImage
> himl
->cCurImage
)))
2670 himl
->nOvlIdx
[iOverlay
- 1] = iImage
;
2676 /* helper for ImageList_Write - write bitmap to pstm
2677 * currently everything is written as 24 bit RGB, except masks
2680 _write_bitmap(HBITMAP hBitmap
, LPSTREAM pstm
)
2682 LPBITMAPFILEHEADER bmfh
;
2683 LPBITMAPINFOHEADER bmih
;
2684 LPBYTE data
= NULL
, lpBits
;
2686 INT bitCount
, sizeImage
, offBits
, totalSize
;
2688 BOOL result
= FALSE
;
2690 if (!GetObjectW(hBitmap
, sizeof(BITMAP
), &bm
))
2693 bitCount
= bm
.bmBitsPixel
== 1 ? 1 : 24;
2694 sizeImage
= DIB_GetDIBImageBytes(bm
.bmWidth
, bm
.bmHeight
, bitCount
);
2696 totalSize
= sizeof(BITMAPFILEHEADER
) + sizeof(BITMAPINFOHEADER
);
2698 totalSize
+= (1 << bitCount
) * sizeof(RGBQUAD
);
2699 offBits
= totalSize
;
2700 totalSize
+= sizeImage
;
2702 data
= Alloc(totalSize
);
2703 bmfh
= (LPBITMAPFILEHEADER
)data
;
2704 bmih
= (LPBITMAPINFOHEADER
)(data
+ sizeof(BITMAPFILEHEADER
));
2705 lpBits
= data
+ offBits
;
2707 /* setup BITMAPFILEHEADER */
2708 bmfh
->bfType
= (('M' << 8) | 'B');
2709 bmfh
->bfSize
= offBits
;
2710 bmfh
->bfReserved1
= 0;
2711 bmfh
->bfReserved2
= 0;
2712 bmfh
->bfOffBits
= offBits
;
2714 /* setup BITMAPINFOHEADER */
2715 bmih
->biSize
= sizeof(BITMAPINFOHEADER
);
2716 bmih
->biWidth
= bm
.bmWidth
;
2717 bmih
->biHeight
= bm
.bmHeight
;
2719 bmih
->biBitCount
= bitCount
;
2720 bmih
->biCompression
= BI_RGB
;
2721 bmih
->biSizeImage
= sizeImage
;
2722 bmih
->biXPelsPerMeter
= 0;
2723 bmih
->biYPelsPerMeter
= 0;
2724 bmih
->biClrUsed
= 0;
2725 bmih
->biClrImportant
= 0;
2728 result
= GetDIBits(xdc
, hBitmap
, 0, bm
.bmHeight
, lpBits
, (BITMAPINFO
*)bmih
, DIB_RGB_COLORS
) == bm
.bmHeight
;
2733 TRACE("width %u, height %u, planes %u, bpp %u\n",
2734 bmih
->biWidth
, bmih
->biHeight
,
2735 bmih
->biPlanes
, bmih
->biBitCount
);
2739 LPBITMAPINFO inf
= (LPBITMAPINFO
)bmih
;
2740 inf
->bmiColors
[0].rgbRed
= inf
->bmiColors
[0].rgbGreen
= inf
->bmiColors
[0].rgbBlue
= 0;
2741 inf
->bmiColors
[1].rgbRed
= inf
->bmiColors
[1].rgbGreen
= inf
->bmiColors
[1].rgbBlue
= 0xff;
2744 if(FAILED(IStream_Write(pstm
, data
, totalSize
, NULL
)))
2756 /*************************************************************************
2757 * ImageList_Write [COMCTL32.@]
2759 * Writes an image list to a stream.
2762 * himl [I] handle to image list
2763 * pstm [O] Pointer to a stream.
2774 ImageList_Write (HIMAGELIST himl
, LPSTREAM pstm
)
2779 TRACE("%p %p\n", himl
, pstm
);
2781 if (!is_valid(himl
))
2784 ilHead
.usMagic
= (('L' << 8) | 'I');
2785 ilHead
.usVersion
= 0x101;
2786 ilHead
.cCurImage
= himl
->cCurImage
;
2787 ilHead
.cMaxImage
= himl
->cMaxImage
;
2788 ilHead
.cGrow
= himl
->cGrow
;
2789 ilHead
.cx
= himl
->cx
;
2790 ilHead
.cy
= himl
->cy
;
2791 ilHead
.bkcolor
= himl
->clrBk
;
2792 ilHead
.flags
= himl
->flags
;
2793 for(i
= 0; i
< 4; i
++) {
2794 ilHead
.ovls
[i
] = himl
->nOvlIdx
[i
];
2797 TRACE("cx %u, cy %u, flags 0x04%x, cCurImage %u, cMaxImage %u\n",
2798 ilHead
.cx
, ilHead
.cy
, ilHead
.flags
, ilHead
.cCurImage
, ilHead
.cMaxImage
);
2800 if(FAILED(IStream_Write(pstm
, &ilHead
, sizeof(ILHEAD
), NULL
)))
2803 /* write the bitmap */
2804 if(!_write_bitmap(himl
->hbmImage
, pstm
))
2807 /* write the mask if we have one */
2808 if(himl
->flags
& ILC_MASK
) {
2809 if(!_write_bitmap(himl
->hbmMask
, pstm
))
2817 static HBITMAP
ImageList_CreateImage(HDC hdc
, HIMAGELIST himl
, UINT count
, UINT width
)
2819 HBITMAP hbmNewBitmap
;
2820 UINT ilc
= (himl
->flags
& 0xFE);
2823 imagelist_get_bitmap_size( himl
, count
, width
, &sz
);
2825 if ((ilc
>= ILC_COLOR4
&& ilc
<= ILC_COLOR32
) || ilc
== ILC_COLOR
)
2830 TRACE("Creating DIBSection %d x %d, %d Bits per Pixel\n",
2831 sz
.cx
, sz
.cy
, himl
->uBitsPixel
);
2833 if (himl
->uBitsPixel
<= ILC_COLOR8
)
2839 colors
= 1 << himl
->uBitsPixel
;
2840 bmi
= Alloc(sizeof(BITMAPINFOHEADER
) +
2841 sizeof(PALETTEENTRY
) * colors
);
2843 pal
= (LPPALETTEENTRY
)bmi
->bmiColors
;
2844 GetPaletteEntries(GetStockObject(DEFAULT_PALETTE
), 0, colors
, pal
);
2846 /* Swap colors returned by GetPaletteEntries so we can use them for
2847 * CreateDIBSection call. */
2848 for (i
= 0; i
< colors
; i
++)
2850 temp
= pal
[i
].peBlue
;
2851 bmi
->bmiColors
[i
].rgbRed
= pal
[i
].peRed
;
2852 bmi
->bmiColors
[i
].rgbBlue
= temp
;
2857 bmi
= Alloc(sizeof(BITMAPINFOHEADER
));
2860 bmi
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
2861 bmi
->bmiHeader
.biWidth
= sz
.cx
;
2862 bmi
->bmiHeader
.biHeight
= sz
.cy
;
2863 bmi
->bmiHeader
.biPlanes
= 1;
2864 bmi
->bmiHeader
.biBitCount
= himl
->uBitsPixel
;
2865 bmi
->bmiHeader
.biCompression
= BI_RGB
;
2866 bmi
->bmiHeader
.biSizeImage
= 0;
2867 bmi
->bmiHeader
.biXPelsPerMeter
= 0;
2868 bmi
->bmiHeader
.biYPelsPerMeter
= 0;
2869 bmi
->bmiHeader
.biClrUsed
= 0;
2870 bmi
->bmiHeader
.biClrImportant
= 0;
2872 hbmNewBitmap
= CreateDIBSection(hdc
, bmi
, DIB_RGB_COLORS
, &bits
, 0, 0);
2876 else /*if (ilc == ILC_COLORDDB)*/
2878 TRACE("Creating Bitmap: %d Bits per Pixel\n", himl
->uBitsPixel
);
2880 hbmNewBitmap
= CreateBitmap (sz
.cx
, sz
.cy
, 1, himl
->uBitsPixel
, NULL
);
2882 TRACE("returning %p\n", hbmNewBitmap
);
2883 return hbmNewBitmap
;
2886 /*************************************************************************
2887 * ImageList_SetColorTable [COMCTL32.@]
2889 * Sets the color table of an image list.
2892 * himl [I] Handle to the image list.
2893 * uStartIndex [I] The first index to set.
2894 * cEntries [I] Number of entries to set.
2895 * prgb [I] New color information for color table for the image list.
2898 * Success: Number of entries in the table that were set.
2902 * ImageList_Create(), SetDIBColorTable()
2906 ImageList_SetColorTable (HIMAGELIST himl
, UINT uStartIndex
, UINT cEntries
, CONST RGBQUAD
* prgb
)
2908 return SetDIBColorTable(himl
->hdcImage
, uStartIndex
, cEntries
, prgb
);
2911 /*************************************************************************
2912 * ImageList_CoCreateInstance [COMCTL32.@]
2914 * Creates a new imagelist instance and returns an interface pointer to it.
2917 * rclsid [I] A reference to the CLSID (CLSID_ImageList).
2918 * punkOuter [I] Pointer to IUnknown interface for aggregation, if desired
2919 * riid [I] Identifier of the requested interface.
2920 * ppv [O] Returns the address of the pointer requested, or NULL.
2924 * Failure: Error value.
2927 ImageList_CoCreateInstance (REFCLSID rclsid
, const IUnknown
*punkOuter
, REFIID riid
, void **ppv
)
2929 FIXME("STUB: %s %p %s %p\n", debugstr_guid(rclsid
), punkOuter
, debugstr_guid(riid
), ppv
);
2930 return E_NOINTERFACE
;
2933 /*************************************************************************
2934 * HIMAGELIST_QueryInterface [COMCTL32.@]
2936 * Returns a pointer to an IImageList or IImageList2 object for the given
2940 * himl [I] Image list handle.
2941 * riid [I] Identifier of the requested interface.
2942 * ppv [O] Returns the address of the pointer requested, or NULL.
2946 * Failure: Error value.
2949 HIMAGELIST_QueryInterface (HIMAGELIST himl
, REFIID riid
, void **ppv
)
2951 FIXME("STUB: %p %s %p\n", himl
, debugstr_guid(riid
), ppv
);
2952 return E_NOINTERFACE
;