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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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 width
, UINT height
);
82 static inline BOOL
is_valid(HIMAGELIST himl
)
84 return himl
&& himl
->magic
== IMAGELIST_MAGIC
;
88 /*************************************************************************
89 * IMAGELIST_InternalExpandBitmaps [Internal]
91 * Expands the bitmaps of an image list by the given number of images.
94 * himl [I] handle to image list
95 * nImageCount [I] number of images to add
101 * This function can NOT be used to reduce the number of images.
104 IMAGELIST_InternalExpandBitmaps (HIMAGELIST himl
, INT nImageCount
, INT cx
, INT cy
)
107 HBITMAP hbmNewBitmap
, hbmNull
;
108 INT nNewWidth
, nNewCount
;
110 if ((himl
->cCurImage
+ nImageCount
<= himl
->cMaxImage
)
114 if (cy
== 0) cy
= himl
->cy
;
115 nNewCount
= himl
->cCurImage
+ nImageCount
+ himl
->cGrow
;
116 nNewWidth
= nNewCount
* himl
->cx
;
118 TRACE("Create expanded bitmaps : himl=%p x=%d y=%d count=%d\n", himl
, nNewWidth
, cy
, nNewCount
);
119 hdcBitmap
= CreateCompatibleDC (0);
121 hbmNewBitmap
= ImageList_CreateImage(hdcBitmap
, himl
, nNewWidth
, cy
);
123 if (hbmNewBitmap
== 0)
124 ERR("creating new image bitmap (x=%d y=%d)!\n", nNewWidth
, cy
);
128 hbmNull
= SelectObject (hdcBitmap
, hbmNewBitmap
);
129 BitBlt (hdcBitmap
, 0, 0, himl
->cCurImage
* himl
->cx
, cy
,
130 himl
->hdcImage
, 0, 0, SRCCOPY
);
131 SelectObject (hdcBitmap
, hbmNull
);
133 SelectObject (himl
->hdcImage
, hbmNewBitmap
);
134 DeleteObject (himl
->hbmImage
);
135 himl
->hbmImage
= hbmNewBitmap
;
137 if (himl
->flags
& ILC_MASK
)
139 hbmNewBitmap
= CreateBitmap (nNewWidth
, cy
, 1, 1, NULL
);
141 if (hbmNewBitmap
== 0)
142 ERR("creating new mask bitmap!\n");
146 hbmNull
= SelectObject (hdcBitmap
, hbmNewBitmap
);
147 BitBlt (hdcBitmap
, 0, 0, himl
->cCurImage
* himl
->cx
, cy
,
148 himl
->hdcMask
, 0, 0, SRCCOPY
);
149 SelectObject (hdcBitmap
, hbmNull
);
151 SelectObject (himl
->hdcMask
, hbmNewBitmap
);
152 DeleteObject (himl
->hbmMask
);
153 himl
->hbmMask
= hbmNewBitmap
;
156 himl
->cMaxImage
= nNewCount
;
158 DeleteDC (hdcBitmap
);
162 /*************************************************************************
163 * ImageList_Add [COMCTL32.@]
165 * Add an image or images to an image list.
168 * himl [I] handle to image list
169 * hbmImage [I] handle to image bitmap
170 * hbmMask [I] handle to mask bitmap
173 * Success: Index of the first new image.
178 ImageList_Add (HIMAGELIST himl
, HBITMAP hbmImage
, HBITMAP hbmMask
)
181 INT nFirstIndex
, nImageCount
;
186 TRACE("himl=%p hbmimage=%p hbmmask=%p\n", himl
, hbmImage
, hbmMask
);
190 GetObjectA (hbmImage
, sizeof(BITMAP
), (LPVOID
)&bmp
);
191 nImageCount
= bmp
.bmWidth
/ himl
->cx
;
193 IMAGELIST_InternalExpandBitmaps (himl
, nImageCount
, bmp
.bmWidth
, bmp
.bmHeight
);
195 nStartX
= himl
->cCurImage
* himl
->cx
;
197 hdcBitmap
= CreateCompatibleDC(0);
199 hOldBitmap
= SelectObject(hdcBitmap
, hbmImage
);
201 /* Copy result to the imagelist
203 BitBlt (himl
->hdcImage
, nStartX
, 0, bmp
.bmWidth
, bmp
.bmHeight
,
204 hdcBitmap
, 0, 0, SRCCOPY
);
209 HBITMAP hOldBitmapTemp
;
211 hdcTemp
= CreateCompatibleDC(0);
212 hOldBitmapTemp
= SelectObject(hdcTemp
, hbmMask
);
214 BitBlt (himl
->hdcMask
,
215 nStartX
, 0, bmp
.bmWidth
, bmp
.bmHeight
,
220 SelectObject(hdcTemp
, hOldBitmapTemp
);
223 /* Remove the background from the image
225 BitBlt (himl
->hdcImage
,
226 nStartX
, 0, bmp
.bmWidth
, bmp
.bmHeight
,
229 0x220326); /* NOTSRCAND */
232 SelectObject(hdcBitmap
, hOldBitmap
);
235 nFirstIndex
= himl
->cCurImage
;
236 himl
->cCurImage
+= nImageCount
;
242 /*************************************************************************
243 * ImageList_AddIcon [COMCTL32.@]
245 * Adds an icon to an image list.
248 * himl [I] handle to image list
249 * hIcon [I] handle to icon
252 * Success: index of the new image
255 #undef ImageList_AddIcon
256 INT WINAPI
ImageList_AddIcon (HIMAGELIST himl
, HICON hIcon
)
258 return ImageList_ReplaceIcon (himl
, -1, hIcon
);
262 /*************************************************************************
263 * ImageList_AddMasked [COMCTL32.@]
265 * Adds an image or images to an image list and creates a mask from the
266 * specified bitmap using the mask color.
269 * himl [I] handle to image list.
270 * hBitmap [I] handle to bitmap
271 * clrMask [I] mask color.
274 * Success: Index of the first new image.
279 ImageList_AddMasked (HIMAGELIST himl
, HBITMAP hBitmap
, COLORREF clrMask
)
281 HDC hdcMask
, hdcBitmap
;
282 INT nIndex
, nImageCount
, nMaskXOffset
=0;
285 HBITMAP hMaskBitmap
=0;
288 TRACE("himl=%p hbitmap=%p clrmask=%lx\n", himl
, hBitmap
, clrMask
);
292 if (!GetObjectA (hBitmap
, sizeof(BITMAP
), &bmp
))
296 nImageCount
= bmp
.bmWidth
/ himl
->cx
;
300 IMAGELIST_InternalExpandBitmaps (himl
, nImageCount
, bmp
.bmWidth
, bmp
.bmHeight
);
302 nIndex
= himl
->cCurImage
;
303 himl
->cCurImage
+= nImageCount
;
305 hdcBitmap
= CreateCompatibleDC(0);
308 hOldBitmap
= SelectObject(hdcBitmap
, hBitmap
);
311 hdcMask
= himl
->hdcMask
;
312 nMaskXOffset
= nIndex
* himl
->cx
;
317 Create a temp Mask so we can remove the background of
318 the Image (Windows does this even if there is no mask)
320 hdcMask
= CreateCompatibleDC(0);
321 hMaskBitmap
= CreateBitmap(bmp
.bmWidth
, bmp
.bmHeight
, 1, 1, NULL
);
322 SelectObject(hdcMask
, hMaskBitmap
);
325 /* create monochrome image to the mask bitmap */
326 bkColor
= (clrMask
!= CLR_DEFAULT
) ? clrMask
:
327 GetPixel (hdcBitmap
, 0, 0);
328 SetBkColor (hdcBitmap
, bkColor
);
330 nMaskXOffset
, 0, bmp
.bmWidth
, bmp
.bmHeight
,
334 SetBkColor(hdcBitmap
, RGB(255,255,255));
335 /*Remove the background from the image
338 WINDOWS BUG ALERT!!!!!!
339 The statement below should not be done in common practice
340 but this is how ImageList_AddMasked works in Windows.
341 It overwrites the original bitmap passed, this was discovered
342 by using the same bitmap to iterate the different styles
343 on windows where it failed (BUT ImageList_Add is OK)
344 This is here in case some apps rely on this bug
347 0, 0, bmp
.bmWidth
, bmp
.bmHeight
,
350 0x220326); /* NOTSRCAND */
351 /* Copy result to the imagelist
353 BitBlt (himl
->hdcImage
,
354 nIndex
* himl
->cx
, 0, bmp
.bmWidth
, bmp
.bmHeight
,
360 SelectObject(hdcBitmap
, hOldBitmap
);
364 DeleteObject(hMaskBitmap
);
372 /*************************************************************************
373 * ImageList_BeginDrag [COMCTL32.@]
375 * Creates a temporary image list that contains one image. It will be used
379 * himlTrack [I] handle to the source image list
380 * iTrack [I] index of the drag image in the source image list
381 * dxHotspot [I] X position of the hot spot of the drag image
382 * dyHotspot [I] Y position of the hot spot of the drag image
390 ImageList_BeginDrag (HIMAGELIST himlTrack
, INT iTrack
,
391 INT dxHotspot
, INT dyHotspot
)
395 TRACE("(himlTrack=%p iTrack=%d dx=%d dy=%d)\n", himlTrack
, iTrack
,
396 dxHotspot
, dyHotspot
);
398 if (!is_valid(himlTrack
))
401 if (InternalDrag
.himl
)
402 ImageList_EndDrag ();
407 InternalDrag
.himl
= ImageList_Create (cx
, cy
, himlTrack
->flags
, 1, 1);
408 if (InternalDrag
.himl
== NULL
) {
409 WARN("Error creating drag image list!\n");
413 InternalDrag
.dxHotspot
= dxHotspot
;
414 InternalDrag
.dyHotspot
= dyHotspot
;
417 BitBlt (InternalDrag
.himl
->hdcImage
, 0, 0, cx
, cy
, himlTrack
->hdcImage
, iTrack
* cx
, 0, SRCCOPY
);
420 BitBlt (InternalDrag
.himl
->hdcMask
, 0, 0, cx
, cy
, himlTrack
->hdcMask
, iTrack
* cx
, 0, SRCCOPY
);
422 InternalDrag
.himl
->cCurImage
= 1;
428 /*************************************************************************
429 * ImageList_Copy [COMCTL32.@]
431 * Copies an image of the source image list to an image of the
432 * destination image list. Images can be copied or swapped.
435 * himlDst [I] handle to the destination image list
436 * iDst [I] destination image index.
437 * himlSrc [I] handle to the source image list
438 * iSrc [I] source image index
439 * uFlags [I] flags for the copy operation
446 * Copying from one image list to another is possible. The original
447 * implementation just copies or swaps within one image list.
448 * Could this feature become a bug??? ;-)
452 ImageList_Copy (HIMAGELIST himlDst
, INT iDst
, HIMAGELIST himlSrc
,
453 INT iSrc
, UINT uFlags
)
455 TRACE("himlDst=%p iDst=%d himlSrc=%p iSrc=%d\n", himlDst
, iDst
, himlSrc
, iSrc
);
457 if (!is_valid(himlSrc
) || !is_valid(himlDst
))
459 if ((iDst
< 0) || (iDst
>= himlDst
->cCurImage
))
461 if ((iSrc
< 0) || (iSrc
>= himlSrc
->cCurImage
))
464 if (uFlags
& ILCF_SWAP
) {
467 HBITMAP hbmTempImage
, hbmTempMask
;
469 hdcBmp
= CreateCompatibleDC (0);
471 /* create temporary bitmaps */
472 hbmTempImage
= CreateBitmap (himlSrc
->cx
, himlSrc
->cy
, 1,
473 himlSrc
->uBitsPixel
, NULL
);
474 hbmTempMask
= CreateBitmap (himlSrc
->cx
, himlSrc
->cy
, 1,
477 /* copy (and stretch) destination to temporary bitmaps.(save) */
479 SelectObject (hdcBmp
, hbmTempImage
);
480 StretchBlt (hdcBmp
, 0, 0, himlSrc
->cx
, himlSrc
->cy
,
481 himlDst
->hdcImage
, iDst
* himlDst
->cx
, 0, himlDst
->cx
, himlDst
->cy
,
484 SelectObject (hdcBmp
, hbmTempMask
);
485 StretchBlt (hdcBmp
, 0, 0, himlSrc
->cx
, himlSrc
->cy
,
486 himlDst
->hdcMask
, iDst
* himlDst
->cx
, 0, himlDst
->cx
, himlDst
->cy
,
489 /* copy (and stretch) source to destination */
491 StretchBlt (himlDst
->hdcImage
, iDst
* himlDst
->cx
, 0, himlDst
->cx
, himlDst
->cy
,
492 himlSrc
->hdcImage
, iSrc
* himlSrc
->cx
, 0, himlSrc
->cx
, himlSrc
->cy
,
495 StretchBlt (himlDst
->hdcMask
, iDst
* himlDst
->cx
, 0, himlDst
->cx
, himlDst
->cy
,
496 himlSrc
->hdcMask
, iSrc
* himlSrc
->cx
, 0, himlSrc
->cx
, himlSrc
->cy
,
499 /* copy (without stretching) temporary bitmaps to source (restore) */
501 BitBlt (himlSrc
->hdcMask
, iSrc
* himlSrc
->cx
, 0, himlSrc
->cx
, himlSrc
->cy
,
502 hdcBmp
, 0, 0, SRCCOPY
);
505 BitBlt (himlSrc
->hdcImage
, iSrc
* himlSrc
->cx
, 0, himlSrc
->cx
, himlSrc
->cy
,
506 hdcBmp
, 0, 0, SRCCOPY
);
507 /* delete temporary bitmaps */
508 DeleteObject (hbmTempMask
);
509 DeleteObject (hbmTempImage
);
514 StretchBlt (himlDst
->hdcImage
, iDst
* himlDst
->cx
, 0, himlDst
->cx
, himlDst
->cy
,
515 himlSrc
->hdcImage
, iSrc
* himlSrc
->cx
, 0, himlSrc
->cx
, himlSrc
->cy
,
519 StretchBlt (himlDst
->hdcMask
, iDst
* himlDst
->cx
, 0, himlDst
->cx
, himlDst
->cy
,
520 himlSrc
->hdcMask
, iSrc
* himlSrc
->cx
, 0, himlSrc
->cx
, himlSrc
->cy
,
528 /*************************************************************************
529 * ImageList_Create [COMCTL32.@]
531 * Creates a new image list.
534 * cx [I] image height
536 * flags [I] creation flags
537 * cInitial [I] initial number of images in the image list
538 * cGrow [I] number of images by which image list grows
541 * Success: Handle to the created image list
545 ImageList_Create (INT cx
, INT cy
, UINT flags
,
546 INT cInitial
, INT cGrow
)
551 UINT ilc
= (flags
& 0xFE);
552 static const WORD aBitBlend25
[] =
553 {0xAA, 0x00, 0x55, 0x00, 0xAA, 0x00, 0x55, 0x00};
555 static const WORD aBitBlend50
[] =
556 {0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA};
558 TRACE("(%d %d 0x%x %d %d)\n", cx
, cy
, flags
, cInitial
, cGrow
);
560 himl
= (HIMAGELIST
)Alloc (sizeof(struct _IMAGELIST
));
564 cGrow
= (cGrow
< 4) ? 4 : (cGrow
+ 3) & ~3;
566 himl
->magic
= IMAGELIST_MAGIC
;
570 himl
->cMaxImage
= cInitial
+ cGrow
;
571 himl
->cInitial
= cInitial
;
573 himl
->clrFg
= CLR_DEFAULT
;
574 himl
->clrBk
= CLR_NONE
;
576 /* initialize overlay mask indices */
577 for (nCount
= 0; nCount
< MAX_OVERLAYIMAGE
; nCount
++)
578 himl
->nOvlIdx
[nCount
] = -1;
580 /* Create Image & Mask DCs */
581 himl
->hdcImage
= CreateCompatibleDC (0);
584 if (himl
->flags
& ILC_MASK
){
585 himl
->hdcMask
= CreateCompatibleDC(0);
590 /* Default to ILC_COLOR4 if none of the ILC_COLOR* flags are specified */
591 if (ilc
== ILC_COLOR
)
594 if (ilc
>= ILC_COLOR4
&& ilc
<= ILC_COLOR32
)
595 himl
->uBitsPixel
= ilc
;
597 himl
->uBitsPixel
= (UINT
)GetDeviceCaps (himl
->hdcImage
, BITSPIXEL
);
599 if (himl
->cMaxImage
> 0) {
600 himl
->hbmImage
= ImageList_CreateImage(himl
->hdcImage
, himl
, cx
* himl
->cMaxImage
, cy
);
601 SelectObject(himl
->hdcImage
, himl
->hbmImage
);
605 if ((himl
->cMaxImage
> 0) && (himl
->flags
& ILC_MASK
)) {
607 CreateBitmap (himl
->cx
* himl
->cMaxImage
, himl
->cy
,
609 if (himl
->hbmMask
== 0) {
610 ERR("Error creating mask bitmap!\n");
613 SelectObject(himl
->hdcMask
, himl
->hbmMask
);
618 /* create blending brushes */
619 hbmTemp
= CreateBitmap (8, 8, 1, 1, &aBitBlend25
);
620 himl
->hbrBlend25
= CreatePatternBrush (hbmTemp
);
621 DeleteObject (hbmTemp
);
623 hbmTemp
= CreateBitmap (8, 8, 1, 1, &aBitBlend50
);
624 himl
->hbrBlend50
= CreatePatternBrush (hbmTemp
);
625 DeleteObject (hbmTemp
);
627 TRACE("created imagelist %p\n", himl
);
631 if (himl
) ImageList_Destroy(himl
);
636 /*************************************************************************
637 * ImageList_Destroy [COMCTL32.@]
639 * Destroys an image list.
642 * himl [I] handle to image list
650 ImageList_Destroy (HIMAGELIST himl
)
655 /* delete image bitmaps */
657 DeleteObject (himl
->hbmImage
);
659 DeleteObject (himl
->hbmMask
);
661 /* delete image & mask DCs */
663 DeleteDC(himl
->hdcImage
);
665 DeleteDC(himl
->hdcMask
);
667 /* delete blending brushes */
668 if (himl
->hbrBlend25
)
669 DeleteObject (himl
->hbrBlend25
);
670 if (himl
->hbrBlend50
)
671 DeleteObject (himl
->hbrBlend50
);
673 ZeroMemory(himl
, sizeof(*himl
));
680 /*************************************************************************
681 * ImageList_DragEnter [COMCTL32.@]
683 * Locks window update and displays the drag image at the given position.
686 * hwndLock [I] handle of the window that owns the drag image.
687 * x [I] X position of the drag image.
688 * y [I] Y position of the drag image.
695 * The position of the drag image is relative to the window, not
700 ImageList_DragEnter (HWND hwndLock
, INT x
, INT y
)
702 TRACE("(hwnd=%p x=%d y=%d)\n", hwndLock
, x
, y
);
704 if (!is_valid(InternalDrag
.himl
))
708 InternalDrag
.hwnd
= hwndLock
;
710 InternalDrag
.hwnd
= GetDesktopWindow ();
715 /* draw the drag image and save the background */
716 if (!ImageList_DragShowNolock(TRUE
)) {
724 /*************************************************************************
725 * ImageList_DragLeave [COMCTL32.@]
727 * Unlocks window update and hides the drag image.
730 * hwndLock [I] handle of the window that owns the drag image.
738 ImageList_DragLeave (HWND hwndLock
)
740 /* As we don't save drag info in the window this can lead to problems if
741 an app does not supply the same window as DragEnter */
743 InternalDrag.hwnd = hwndLock;
745 InternalDrag.hwnd = GetDesktopWindow (); */
747 hwndLock
= GetDesktopWindow();
748 if(InternalDrag
.hwnd
!= hwndLock
)
749 FIXME("DragLeave hWnd != DragEnter hWnd\n");
751 ImageList_DragShowNolock (FALSE
);
757 /*************************************************************************
758 * ImageList_InternalDragDraw [Internal]
760 * Draws the drag image.
763 * hdc [I] device context to draw into.
764 * x [I] X position of the drag image.
765 * y [I] Y position of the drag image.
772 * The position of the drag image is relative to the window, not
778 ImageList_InternalDragDraw (HDC hdc
, INT x
, INT y
)
780 IMAGELISTDRAWPARAMS imldp
;
782 ZeroMemory (&imldp
, sizeof(imldp
));
783 imldp
.cbSize
= sizeof(imldp
);
784 imldp
.himl
= InternalDrag
.himl
;
789 imldp
.rgbBk
= CLR_DEFAULT
;
790 imldp
.rgbFg
= CLR_DEFAULT
;
791 imldp
.fStyle
= ILD_NORMAL
;
792 imldp
.fState
= ILS_ALPHA
;
795 /* FIXME: instead of using the alpha blending, we should
796 * create a 50% mask, and draw it semitransparantly that way */
797 ImageList_DrawIndirect (&imldp
);
800 /*************************************************************************
801 * ImageList_DragMove [COMCTL32.@]
803 * Moves the drag image.
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
818 * The drag image should be drawn semitransparent.
822 ImageList_DragMove (INT x
, INT y
)
824 TRACE("(x=%d y=%d)\n", x
, y
);
826 if (!is_valid(InternalDrag
.himl
))
829 /* draw/update the drag image */
830 if (InternalDrag
.bShow
) {
834 HBITMAP hbmOffScreen
;
835 INT origNewX
, origNewY
;
836 INT origOldX
, origOldY
;
837 INT origRegX
, origRegY
;
838 INT sizeRegX
, sizeRegY
;
841 /* calculate the update region */
842 origNewX
= x
- InternalDrag
.dxHotspot
;
843 origNewY
= y
- InternalDrag
.dyHotspot
;
844 origOldX
= InternalDrag
.x
- InternalDrag
.dxHotspot
;
845 origOldY
= InternalDrag
.y
- InternalDrag
.dyHotspot
;
846 origRegX
= min(origNewX
, origOldX
);
847 origRegY
= min(origNewY
, origOldY
);
848 sizeRegX
= InternalDrag
.himl
->cx
+ abs(x
- InternalDrag
.x
);
849 sizeRegY
= InternalDrag
.himl
->cy
+ abs(y
- InternalDrag
.y
);
851 hdcDrag
= GetDCEx(InternalDrag
.hwnd
, 0,
852 DCX_WINDOW
| DCX_CACHE
| DCX_LOCKWINDOWUPDATE
);
853 hdcOffScreen
= CreateCompatibleDC(hdcDrag
);
854 hdcBg
= CreateCompatibleDC(hdcDrag
);
856 hbmOffScreen
= CreateCompatibleBitmap(hdcDrag
, sizeRegX
, sizeRegY
);
857 SelectObject(hdcOffScreen
, hbmOffScreen
);
858 SelectObject(hdcBg
, InternalDrag
.hbmBg
);
860 /* get the actual background of the update region */
861 BitBlt(hdcOffScreen
, 0, 0, sizeRegX
, sizeRegY
, hdcDrag
,
862 origRegX
, origRegY
, SRCCOPY
);
863 /* erase the old image */
864 BitBlt(hdcOffScreen
, origOldX
- origRegX
, origOldY
- origRegY
,
865 InternalDrag
.himl
->cx
, InternalDrag
.himl
->cy
, hdcBg
, 0, 0,
867 /* save the background */
868 BitBlt(hdcBg
, 0, 0, InternalDrag
.himl
->cx
, InternalDrag
.himl
->cy
,
869 hdcOffScreen
, origNewX
- origRegX
, origNewY
- origRegY
, SRCCOPY
);
871 ImageList_InternalDragDraw(hdcOffScreen
, origNewX
- origRegX
,
872 origNewY
- origRegY
);
873 /* draw the update region to the screen */
874 BitBlt(hdcDrag
, origRegX
, origRegY
, sizeRegX
, sizeRegY
,
875 hdcOffScreen
, 0, 0, SRCCOPY
);
878 DeleteDC(hdcOffScreen
);
879 DeleteObject(hbmOffScreen
);
880 ReleaseDC(InternalDrag
.hwnd
, hdcDrag
);
883 /* update the image position */
891 /*************************************************************************
892 * ImageList_DragShowNolock [COMCTL32.@]
894 * Shows or hides the drag image.
897 * bShow [I] TRUE shows the drag image, FALSE hides it.
904 * The drag image should be drawn semitransparent.
908 ImageList_DragShowNolock (BOOL bShow
)
914 if (!is_valid(InternalDrag
.himl
))
917 TRACE("bShow=0x%X!\n", bShow
);
919 /* DragImage is already visible/hidden */
920 if ((InternalDrag
.bShow
&& bShow
) || (!InternalDrag
.bShow
&& !bShow
)) {
924 /* position of the origin of the DragImage */
925 x
= InternalDrag
.x
- InternalDrag
.dxHotspot
;
926 y
= InternalDrag
.y
- InternalDrag
.dyHotspot
;
928 hdcDrag
= GetDCEx (InternalDrag
.hwnd
, 0,
929 DCX_WINDOW
| DCX_CACHE
| DCX_LOCKWINDOWUPDATE
);
934 hdcBg
= CreateCompatibleDC(hdcDrag
);
935 if (!InternalDrag
.hbmBg
) {
936 InternalDrag
.hbmBg
= CreateCompatibleBitmap(hdcDrag
,
937 InternalDrag
.himl
->cx
, InternalDrag
.himl
->cy
);
939 SelectObject(hdcBg
, InternalDrag
.hbmBg
);
942 /* save the background */
943 BitBlt(hdcBg
, 0, 0, InternalDrag
.himl
->cx
, InternalDrag
.himl
->cy
,
944 hdcDrag
, x
, y
, SRCCOPY
);
946 ImageList_InternalDragDraw(hdcDrag
, x
, y
);
949 BitBlt(hdcDrag
, x
, y
, InternalDrag
.himl
->cx
, InternalDrag
.himl
->cy
,
950 hdcBg
, 0, 0, SRCCOPY
);
953 InternalDrag
.bShow
= !InternalDrag
.bShow
;
956 ReleaseDC (InternalDrag
.hwnd
, hdcDrag
);
961 /*************************************************************************
962 * ImageList_Draw [COMCTL32.@]
967 * himl [I] handle to image list
969 * hdc [I] handle to device context
972 * fStyle [I] drawing flags
983 ImageList_Draw (HIMAGELIST himl
, INT i
, HDC hdc
, INT x
, INT y
, UINT fStyle
)
985 return ImageList_DrawEx (himl
, i
, hdc
, x
, y
, 0, 0,
986 CLR_DEFAULT
, CLR_DEFAULT
, fStyle
);
990 /*************************************************************************
991 * ImageList_DrawEx [COMCTL32.@]
993 * Draws an image and allows to use extended drawing features.
996 * himl [I] handle to image list
998 * hdc [I] handle to device context
1003 * rgbBk [I] background color
1004 * rgbFg [I] foreground color
1005 * fStyle [I] drawing flags
1012 * Calls ImageList_DrawIndirect.
1015 * ImageList_DrawIndirect.
1019 ImageList_DrawEx (HIMAGELIST himl
, INT i
, HDC hdc
, INT x
, INT y
,
1020 INT dx
, INT dy
, COLORREF rgbBk
, COLORREF rgbFg
,
1023 IMAGELISTDRAWPARAMS imldp
;
1025 ZeroMemory (&imldp
, sizeof(imldp
));
1026 imldp
.cbSize
= sizeof(imldp
);
1034 imldp
.rgbBk
= rgbBk
;
1035 imldp
.rgbFg
= rgbFg
;
1036 imldp
.fStyle
= fStyle
;
1038 return ImageList_DrawIndirect (&imldp
);
1042 /*************************************************************************
1043 * ImageList_DrawIndirect [COMCTL32.@]
1045 * Draws an image using various parameters specified in pimldp.
1048 * pimldp [I] pointer to IMAGELISTDRAWPARAMS structure.
1056 ImageList_DrawIndirect (IMAGELISTDRAWPARAMS
*pimldp
)
1058 INT cx
, cy
, lx
, ly
, nOvlIdx
;
1059 DWORD fState
, dwRop
;
1061 COLORREF oldImageBk
, oldImageFg
;
1062 HDC hImageDC
, hImageListDC
, hMaskListDC
;
1063 HBITMAP hImageBmp
, hOldImageBmp
, hBlendMaskBmp
;
1064 BOOL bIsTransparent
, bBlend
, bResult
= FALSE
, bMask
;
1067 if (!pimldp
|| !(himl
= pimldp
->himl
)) return FALSE
;
1068 if (!is_valid(himl
)) return FALSE
;
1069 if ((pimldp
->i
< 0) || (pimldp
->i
>= himl
->cCurImage
)) return FALSE
;
1071 lx
= himl
->cx
* pimldp
->i
+ pimldp
->xBitmap
;
1072 ly
= pimldp
->yBitmap
;
1074 fState
= pimldp
->cbSize
< sizeof(IMAGELISTDRAWPARAMS
) ? ILS_NORMAL
: pimldp
->fState
;
1075 fStyle
= pimldp
->fStyle
& ~ILD_OVERLAYMASK
;
1076 cx
= (pimldp
->cx
== 0) ? himl
->cx
: pimldp
->cx
;
1077 cy
= (pimldp
->cy
== 0) ? himl
->cy
: pimldp
->cy
;
1079 bIsTransparent
= (fStyle
& ILD_TRANSPARENT
);
1080 if( pimldp
->rgbBk
== CLR_NONE
)
1081 bIsTransparent
= TRUE
;
1082 if( ( pimldp
->rgbBk
== CLR_DEFAULT
) && ( himl
->clrBk
== CLR_NONE
) )
1083 bIsTransparent
= TRUE
;
1084 bMask
= (himl
->flags
& ILC_MASK
) && (fStyle
& ILD_MASK
) ;
1085 bBlend
= (fStyle
& (ILD_BLEND25
| ILD_BLEND50
) ) && !bMask
;
1087 TRACE("himl(0x%lx) hbmMask(%p) iImage(%d) x(%d) y(%d) cx(%d) cy(%d)\n",
1088 (DWORD
)himl
, himl
->hbmMask
, pimldp
->i
, pimldp
->x
, pimldp
->y
, cx
, cy
);
1090 /* we will use these DCs to access the images and masks in the ImageList */
1091 hImageListDC
= himl
->hdcImage
;
1092 hMaskListDC
= himl
->hdcMask
;
1094 /* these will accumulate the image and mask for the image we're drawing */
1095 hImageDC
= CreateCompatibleDC( pimldp
->hdcDst
);
1096 hImageBmp
= CreateCompatibleBitmap( pimldp
->hdcDst
, cx
, cy
);
1097 hBlendMaskBmp
= bBlend
? CreateBitmap(cx
, cy
, 1, 1, NULL
) : 0;
1099 /* Create a compatible DC. */
1100 if (!hImageListDC
|| !hImageDC
|| !hImageBmp
||
1101 (bBlend
&& !hBlendMaskBmp
) || (himl
->hbmMask
&& !hMaskListDC
))
1104 hOldImageBmp
= SelectObject(hImageDC
, hImageBmp
);
1107 * To obtain a transparent look, background color should be set
1108 * to white and foreground color to black when blting the
1111 oldImageFg
= SetTextColor( hImageDC
, RGB( 0, 0, 0 ) );
1112 oldImageBk
= SetBkColor( hImageDC
, RGB( 0xff, 0xff, 0xff ) );
1115 * Draw the initial image
1118 if (himl
->hbmMask
) {
1120 hOldBrush
= SelectObject (hImageDC
, CreateSolidBrush (GetTextColor(pimldp
->hdcDst
)));
1121 PatBlt( hImageDC
, 0, 0, cx
, cy
, PATCOPY
);
1122 BitBlt(hImageDC
, 0, 0, cx
, cy
, hMaskListDC
, lx
, ly
, SRCPAINT
);
1123 DeleteObject (SelectObject (hImageDC
, hOldBrush
));
1124 if( bIsTransparent
)
1126 BitBlt ( pimldp
->hdcDst
, pimldp
->x
, pimldp
->y
, cx
, cy
, hImageDC
, 0, 0, SRCAND
);
1131 HBRUSH hOldBrush
= SelectObject (hImageDC
, GetStockObject(BLACK_BRUSH
));
1132 PatBlt( hImageDC
, 0, 0, cx
, cy
, PATCOPY
);
1133 SelectObject(hImageDC
, hOldBrush
);
1136 /* blend the image with the needed solid background */
1137 COLORREF colour
= RGB(0,0,0);
1140 if( !bIsTransparent
)
1142 colour
= pimldp
->rgbBk
;
1143 if( colour
== CLR_DEFAULT
)
1144 colour
= himl
->clrBk
;
1145 if( colour
== CLR_NONE
)
1146 colour
= GetBkColor(pimldp
->hdcDst
);
1149 hOldBrush
= SelectObject (hImageDC
, CreateSolidBrush (colour
));
1150 PatBlt( hImageDC
, 0, 0, cx
, cy
, PATCOPY
);
1151 BitBlt( hImageDC
, 0, 0, cx
, cy
, hMaskListDC
, lx
, ly
, SRCAND
);
1152 BitBlt( hImageDC
, 0, 0, cx
, cy
, hImageListDC
, lx
, ly
, SRCPAINT
);
1153 DeleteObject (SelectObject (hImageDC
, hOldBrush
));
1156 /* Time for blending, if required */
1158 HBRUSH hBlendBrush
, hOldBrush
;
1159 COLORREF clrBlend
= pimldp
->rgbFg
;
1160 HDC hBlendMaskDC
= hImageListDC
;
1163 /* Create the blend Mask */
1164 hOldBitmap
= SelectObject(hBlendMaskDC
, hBlendMaskBmp
);
1165 hBlendBrush
= fStyle
& ILD_BLEND50
? himl
->hbrBlend50
: himl
->hbrBlend25
;
1166 hOldBrush
= (HBRUSH
) SelectObject(hBlendMaskDC
, hBlendBrush
);
1167 PatBlt(hBlendMaskDC
, 0, 0, cx
, cy
, PATCOPY
);
1168 SelectObject(hBlendMaskDC
, hOldBrush
);
1170 /* Modify the blend mask if an Image Mask exist */
1172 BitBlt(hBlendMaskDC
, 0, 0, cx
, cy
, hMaskListDC
, lx
, ly
, 0x220326); /* NOTSRCAND */
1173 BitBlt(hBlendMaskDC
, 0, 0, cx
, cy
, hBlendMaskDC
, 0, 0, NOTSRCCOPY
);
1176 /* now apply blend to the current image given the BlendMask */
1177 if (clrBlend
== CLR_DEFAULT
) clrBlend
= GetSysColor (COLOR_HIGHLIGHT
);
1178 else if (clrBlend
== CLR_NONE
) clrBlend
= GetTextColor (pimldp
->hdcDst
);
1179 hOldBrush
= (HBRUSH
) SelectObject (hImageDC
, CreateSolidBrush(clrBlend
));
1180 BitBlt (hImageDC
, 0, 0, cx
, cy
, hBlendMaskDC
, 0, 0, 0xB8074A); /* PSDPxax */
1181 DeleteObject(SelectObject(hImageDC
, hOldBrush
));
1182 SelectObject(hBlendMaskDC
, hOldBitmap
);
1185 /* Now do the overlay image, if any */
1186 nOvlIdx
= (pimldp
->fStyle
& ILD_OVERLAYMASK
) >> 8;
1187 if ( (nOvlIdx
>= 1) && (nOvlIdx
<= MAX_OVERLAYIMAGE
)) {
1188 nOvlIdx
= himl
->nOvlIdx
[nOvlIdx
- 1];
1189 if ((nOvlIdx
>= 0) && (nOvlIdx
< himl
->cCurImage
)) {
1190 const INT ox
= himl
->cx
* nOvlIdx
+ pimldp
->xBitmap
;
1191 if (himl
->hbmMask
&& !(fStyle
& ILD_IMAGE
))
1192 BitBlt (hImageDC
, 0, 0, cx
, cy
, hMaskListDC
, ox
, ly
, SRCAND
);
1193 BitBlt (hImageDC
, 0, 0, cx
, cy
, hImageListDC
, ox
, ly
, SRCPAINT
);
1197 if (fState
& ILS_SATURATE
) FIXME("ILS_SATURATE: unimplemented!\n");
1198 if (fState
& ILS_GLOW
) FIXME("ILS_GLOW: unimplemented!\n");
1199 if (fState
& ILS_SHADOW
) FIXME("ILS_SHADOW: unimplemented!\n");
1200 if (fState
& ILS_ALPHA
) FIXME("ILS_ALPHA: unimplemented!\n");
1202 if (fStyle
& ILD_PRESERVEALPHA
) FIXME("ILD_PRESERVEALPHA: unimplemented!\n");
1203 if (fStyle
& ILD_SCALE
) FIXME("ILD_SCALE: unimplemented!\n");
1204 if (fStyle
& ILD_DPISCALE
) FIXME("ILD_DPISCALE: unimplemented!\n");
1206 /* now copy the image to the screen */
1208 if (himl
->hbmMask
&& bIsTransparent
) {
1209 COLORREF oldDstFg
= SetTextColor(pimldp
->hdcDst
, RGB( 0, 0, 0 ) );
1210 COLORREF oldDstBk
= SetBkColor(pimldp
->hdcDst
, RGB( 0xff, 0xff, 0xff ));
1211 BitBlt (pimldp
->hdcDst
, pimldp
->x
, pimldp
->y
, cx
, cy
, hMaskListDC
, lx
, ly
, SRCAND
);
1212 SetBkColor(pimldp
->hdcDst
, oldDstBk
);
1213 SetTextColor(pimldp
->hdcDst
, oldDstFg
);
1216 if (fStyle
& ILD_ROP
) dwRop
= pimldp
->dwRop
;
1217 BitBlt (pimldp
->hdcDst
, pimldp
->x
, pimldp
->y
, cx
, cy
, hImageDC
, 0, 0, dwRop
);
1221 /* cleanup the mess */
1222 SetBkColor(hImageDC
, oldImageBk
);
1223 SetTextColor(hImageDC
, oldImageFg
);
1224 SelectObject(hImageDC
, hOldImageBmp
);
1226 DeleteObject(hBlendMaskBmp
);
1227 DeleteObject(hImageBmp
);
1234 /*************************************************************************
1235 * ImageList_Duplicate [COMCTL32.@]
1237 * Duplicates an image list.
1240 * himlSrc [I] source image list handle
1243 * Success: Handle of duplicated image list.
1248 ImageList_Duplicate (HIMAGELIST himlSrc
)
1252 if (!is_valid(himlSrc
)) {
1253 ERR("Invalid image list handle!\n");
1257 himlDst
= ImageList_Create (himlSrc
->cx
, himlSrc
->cy
, himlSrc
->flags
,
1258 himlSrc
->cInitial
, himlSrc
->cGrow
);
1262 BitBlt (himlDst
->hdcImage
, 0, 0, himlSrc
->cCurImage
* himlSrc
->cx
, himlSrc
->cy
,
1263 himlSrc
->hdcImage
, 0, 0, SRCCOPY
);
1265 if (himlDst
->hbmMask
)
1266 BitBlt (himlDst
->hdcMask
, 0, 0, himlSrc
->cCurImage
* himlSrc
->cx
, himlSrc
->cy
,
1267 himlSrc
->hdcMask
, 0, 0, SRCCOPY
);
1269 himlDst
->cCurImage
= himlSrc
->cCurImage
;
1270 himlDst
->cMaxImage
= himlSrc
->cMaxImage
;
1276 /*************************************************************************
1277 * ImageList_EndDrag [COMCTL32.@]
1279 * Finishes a drag operation.
1290 ImageList_EndDrag (void)
1292 /* cleanup the InternalDrag struct */
1293 InternalDrag
.hwnd
= 0;
1294 ImageList_Destroy (InternalDrag
.himl
);
1295 InternalDrag
.himl
= 0;
1298 InternalDrag
.dxHotspot
= 0;
1299 InternalDrag
.dyHotspot
= 0;
1300 InternalDrag
.bShow
= FALSE
;
1301 DeleteObject(InternalDrag
.hbmBg
);
1302 InternalDrag
.hbmBg
= 0;
1306 /*************************************************************************
1307 * ImageList_GetBkColor [COMCTL32.@]
1309 * Returns the background color of an image list.
1312 * himl [I] Image list handle.
1315 * Success: background color
1320 ImageList_GetBkColor (HIMAGELIST himl
)
1322 return himl
? himl
->clrBk
: CLR_NONE
;
1326 /*************************************************************************
1327 * ImageList_GetDragImage [COMCTL32.@]
1329 * Returns the handle to the internal drag image list.
1332 * ppt [O] Pointer to the drag position. Can be NULL.
1333 * pptHotspot [O] Pointer to the position of the hot spot. Can be NULL.
1336 * Success: Handle of the drag image list.
1341 ImageList_GetDragImage (POINT
*ppt
, POINT
*pptHotspot
)
1343 if (is_valid(InternalDrag
.himl
)) {
1345 ppt
->x
= InternalDrag
.x
;
1346 ppt
->y
= InternalDrag
.y
;
1349 pptHotspot
->x
= InternalDrag
.dxHotspot
;
1350 pptHotspot
->y
= InternalDrag
.dyHotspot
;
1352 return (InternalDrag
.himl
);
1359 /*************************************************************************
1360 * ImageList_GetFlags [COMCTL32.@]
1362 * Gets the flags of the specified image list.
1365 * himl [I] Handle to image list
1375 ImageList_GetFlags(HIMAGELIST himl
)
1377 FIXME("(%p):empty stub\n", himl
);
1382 /*************************************************************************
1383 * ImageList_GetIcon [COMCTL32.@]
1385 * Creates an icon from a masked image of an image list.
1388 * himl [I] handle to image list
1390 * flags [I] drawing style flags
1393 * Success: icon handle
1398 ImageList_GetIcon (HIMAGELIST himl
, INT i
, UINT fStyle
)
1402 HBITMAP hOldDstBitmap
;
1405 TRACE("%p %d %d\n", himl
, i
, fStyle
);
1406 if (!is_valid(himl
) || (i
< 0) || (i
>= himl
->cCurImage
)) return NULL
;
1408 hdcDst
= CreateCompatibleDC(0);
1415 ii
.hbmMask
= CreateCompatibleBitmap (hdcDst
, himl
->cx
, himl
->cy
);
1416 hOldDstBitmap
= SelectObject (hdcDst
, ii
.hbmMask
);
1417 if (himl
->hbmMask
) {
1418 BitBlt (hdcDst
, 0, 0, himl
->cx
, himl
->cy
,
1419 himl
->hdcMask
, i
* himl
->cx
, 0, SRCCOPY
);
1422 PatBlt (hdcDst
, 0, 0, himl
->cx
, himl
->cy
, BLACKNESS
);
1425 ii
.hbmColor
= CreateCompatibleBitmap (himl
->hdcImage
, himl
->cx
, himl
->cy
);
1426 SelectObject (hdcDst
, ii
.hbmColor
);
1427 BitBlt (hdcDst
, 0, 0, himl
->cx
, himl
->cy
,
1428 himl
->hdcImage
, i
* himl
->cx
, 0, SRCCOPY
);
1431 * CreateIconIndirect requires us to deselect the bitmaps from
1432 * the DCs before calling
1434 SelectObject(hdcDst
, hOldDstBitmap
);
1436 hIcon
= CreateIconIndirect (&ii
);
1438 DeleteObject (ii
.hbmMask
);
1439 DeleteObject (ii
.hbmColor
);
1446 /*************************************************************************
1447 * ImageList_GetIconSize [COMCTL32.@]
1449 * Retrieves the size of an image in an image list.
1452 * himl [I] handle to image list
1453 * cx [O] pointer to the image width.
1454 * cy [O] pointer to the image height.
1461 * All images in an image list have the same size.
1465 ImageList_GetIconSize (HIMAGELIST himl
, INT
*cx
, INT
*cy
)
1467 if (!is_valid(himl
))
1469 if ((himl
->cx
<= 0) || (himl
->cy
<= 0))
1481 /*************************************************************************
1482 * ImageList_GetImageCount [COMCTL32.@]
1484 * Returns the number of images in an image list.
1487 * himl [I] handle to image list
1490 * Success: Number of images.
1495 ImageList_GetImageCount (HIMAGELIST himl
)
1497 if (!is_valid(himl
))
1500 return himl
->cCurImage
;
1504 /*************************************************************************
1505 * ImageList_GetImageInfo [COMCTL32.@]
1507 * Returns information about an image in an image list.
1510 * himl [I] handle to image list
1512 * pImageInfo [O] pointer to the image information
1520 ImageList_GetImageInfo (HIMAGELIST himl
, INT i
, IMAGEINFO
*pImageInfo
)
1522 if (!is_valid(himl
) || (pImageInfo
== NULL
))
1524 if ((i
< 0) || (i
>= himl
->cCurImage
))
1527 pImageInfo
->hbmImage
= himl
->hbmImage
;
1528 pImageInfo
->hbmMask
= himl
->hbmMask
;
1530 pImageInfo
->rcImage
.top
= 0;
1531 pImageInfo
->rcImage
.bottom
= himl
->cy
;
1532 pImageInfo
->rcImage
.left
= i
* himl
->cx
;
1533 pImageInfo
->rcImage
.right
= (i
+1) * himl
->cx
;
1539 /*************************************************************************
1540 * ImageList_GetImageRect [COMCTL32.@]
1542 * Retrieves the rectangle of the specified image in an image list.
1545 * himl [I] handle to image list
1547 * lpRect [O] pointer to the image rectangle
1554 * This is an UNDOCUMENTED function!!!
1558 ImageList_GetImageRect (HIMAGELIST himl
, INT i
, LPRECT lpRect
)
1560 if (!is_valid(himl
) || (lpRect
== NULL
))
1562 if ((i
< 0) || (i
>= himl
->cCurImage
))
1565 lpRect
->left
= i
* himl
->cx
;
1567 lpRect
->right
= lpRect
->left
+ himl
->cx
;
1568 lpRect
->bottom
= himl
->cy
;
1574 /*************************************************************************
1575 * ImageList_LoadImage [COMCTL32.@]
1576 * ImageList_LoadImageA [COMCTL32.@]
1578 * Creates an image list from a bitmap, icon or cursor.
1581 * hi [I] instance handle
1582 * lpbmp [I] name or id of the image
1583 * cx [I] width of each image
1584 * cGrow [I] number of images to expand
1585 * clrMask [I] mask color
1586 * uType [I] type of image to load
1587 * uFlags [I] loading flags
1590 * Success: handle to the loaded image list
1598 ImageList_LoadImageA (HINSTANCE hi
, LPCSTR lpbmp
, INT cx
, INT cGrow
,
1599 COLORREF clrMask
, UINT uType
, UINT uFlags
)
1601 HIMAGELIST himl
= NULL
;
1605 handle
= LoadImageA (hi
, lpbmp
, uType
, 0, 0, uFlags
);
1607 ERR("Error loading image!\n");
1611 if (uType
== IMAGE_BITMAP
) {
1613 GetObjectA (handle
, sizeof(BITMAP
), &bmp
);
1615 /* To match windows behavior, if cx is set to zero and
1616 the flag DI_DEFAULTSIZE is specified, cx becomes the
1617 system metric value for icons. If the flag is not specified
1618 the function sets the size to the height of the bitmap */
1621 if (uFlags
& DI_DEFAULTSIZE
)
1622 cx
= GetSystemMetrics (SM_CXICON
);
1627 nImageCount
= bmp
.bmWidth
/ cx
;
1629 himl
= ImageList_Create (cx
, bmp
.bmHeight
, ILC_MASK
| ILC_COLOR
,
1630 nImageCount
, cGrow
);
1632 DeleteObject (handle
);
1635 ImageList_AddMasked (himl
, (HBITMAP
)handle
, clrMask
);
1637 else if ((uType
== IMAGE_ICON
) || (uType
== IMAGE_CURSOR
)) {
1641 GetIconInfo (handle
, &ii
);
1642 GetObjectA (ii
.hbmColor
, sizeof(BITMAP
), (LPVOID
)&bmp
);
1643 himl
= ImageList_Create (bmp
.bmWidth
, bmp
.bmHeight
,
1644 ILC_MASK
| ILC_COLOR
, 1, cGrow
);
1646 DeleteObject (ii
.hbmColor
);
1647 DeleteObject (ii
.hbmMask
);
1648 DeleteObject (handle
);
1651 ImageList_Add (himl
, ii
.hbmColor
, ii
.hbmMask
);
1652 DeleteObject (ii
.hbmColor
);
1653 DeleteObject (ii
.hbmMask
);
1656 DeleteObject (handle
);
1662 /*************************************************************************
1663 * ImageList_LoadImageW [COMCTL32.@]
1665 * Creates an image list from a bitmap, icon or cursor.
1668 * hi [I] instance handle
1669 * lpbmp [I] name or id of the image
1670 * cx [I] width of each image
1671 * cGrow [I] number of images to expand
1672 * clrMask [I] mask color
1673 * uType [I] type of image to load
1674 * uFlags [I] loading flags
1677 * Success: handle to the loaded image list
1685 ImageList_LoadImageW (HINSTANCE hi
, LPCWSTR lpbmp
, INT cx
, INT cGrow
,
1686 COLORREF clrMask
, UINT uType
, UINT uFlags
)
1688 HIMAGELIST himl
= NULL
;
1692 handle
= LoadImageW (hi
, lpbmp
, uType
, 0, 0, uFlags
);
1694 ERR("Error loading image!\n");
1698 if (uType
== IMAGE_BITMAP
) {
1700 GetObjectW (handle
, sizeof(BITMAP
), &bmp
);
1702 /* To match windows behavior, if cx is set to zero and
1703 the flag DI_DEFAULTSIZE is specified, cx becomes the
1704 system metric value for icons. If the flag is not specified
1705 the function sets the size to the height of the bitmap */
1708 if (uFlags
& DI_DEFAULTSIZE
)
1709 cx
= GetSystemMetrics (SM_CXICON
);
1714 nImageCount
= bmp
.bmWidth
/ cx
;
1716 himl
= ImageList_Create (cx
, bmp
.bmHeight
, ILC_MASK
| ILC_COLOR
,
1717 nImageCount
, cGrow
);
1719 DeleteObject (handle
);
1722 ImageList_AddMasked (himl
, (HBITMAP
)handle
, clrMask
);
1724 else if ((uType
== IMAGE_ICON
) || (uType
== IMAGE_CURSOR
)) {
1728 GetIconInfo (handle
, &ii
);
1729 GetObjectW (ii
.hbmMask
, sizeof(BITMAP
), (LPVOID
)&bmp
);
1730 himl
= ImageList_Create (bmp
.bmWidth
, bmp
.bmHeight
,
1731 ILC_MASK
| ILC_COLOR
, 1, cGrow
);
1733 DeleteObject (ii
.hbmColor
);
1734 DeleteObject (ii
.hbmMask
);
1735 DeleteObject (handle
);
1738 ImageList_Add (himl
, ii
.hbmColor
, ii
.hbmMask
);
1739 DeleteObject (ii
.hbmColor
);
1740 DeleteObject (ii
.hbmMask
);
1743 DeleteObject (handle
);
1749 /*************************************************************************
1750 * ImageList_Merge [COMCTL32.@]
1752 * Create an image list containing a merged image from two image lists.
1755 * himl1 [I] handle to first image list
1756 * i1 [I] first image index
1757 * himl2 [I] handle to second image list
1758 * i2 [I] second image index
1759 * dx [I] X offset of the second image relative to the first.
1760 * dy [I] Y offset of the second image relative to the first.
1763 * Success: The newly created image list. It contains a single image
1764 * consisting of the second image merged with the first.
1765 * Failure: NULL, if either himl1 or himl2 are invalid.
1768 * - The returned image list should be deleted by the caller using
1769 * ImageList_Destroy() when it is no longer required.
1770 * - If either i1 or i2 are not valid image indices they will be treated
1774 ImageList_Merge (HIMAGELIST himl1
, INT i1
, HIMAGELIST himl2
, INT i2
,
1777 HIMAGELIST himlDst
= NULL
;
1779 INT xOff1
, yOff1
, xOff2
, yOff2
;
1782 TRACE("(himl1=%p i1=%d himl2=%p i2=%d dx=%d dy=%d)\n", himl1
, i1
, himl2
,
1785 if (!is_valid(himl1
) || !is_valid(himl2
))
1789 cxDst
= max (himl1
->cx
, dx
+ himl2
->cx
);
1794 cxDst
= max (himl2
->cx
, himl1
->cx
- dx
);
1799 cxDst
= max (himl1
->cx
, himl2
->cx
);
1805 cyDst
= max (himl1
->cy
, dy
+ himl2
->cy
);
1810 cyDst
= max (himl2
->cy
, himl1
->cy
- dy
);
1815 cyDst
= max (himl1
->cy
, himl2
->cy
);
1820 himlDst
= ImageList_Create (cxDst
, cyDst
, ILC_MASK
| ILC_COLOR
, 1, 1);
1824 nX1
= i1
* himl1
->cx
;
1825 nX2
= i2
* himl2
->cx
;
1828 BitBlt (himlDst
->hdcImage
, 0, 0, cxDst
, cyDst
, himl1
->hdcImage
, 0, 0, BLACKNESS
);
1829 if (i1
>= 0 && i1
< himl1
->cCurImage
)
1830 BitBlt (himlDst
->hdcImage
, xOff1
, yOff1
, himl1
->cx
, himl1
->cy
, himl1
->hdcImage
, nX1
, 0, SRCCOPY
);
1831 if (i2
>= 0 && i2
< himl2
->cCurImage
)
1833 BitBlt (himlDst
->hdcImage
, xOff2
, yOff2
, himl2
->cx
, himl2
->cy
, himl2
->hdcMask
, nX2
, 0, SRCAND
);
1834 BitBlt (himlDst
->hdcImage
, xOff2
, yOff2
, himl2
->cx
, himl2
->cy
, himl2
->hdcImage
, nX2
, 0, SRCPAINT
);
1838 BitBlt (himlDst
->hdcMask
, 0, 0, cxDst
, cyDst
, himl1
->hdcMask
, 0, 0, WHITENESS
);
1839 if (i1
>= 0 && i1
< himl1
->cCurImage
)
1840 BitBlt (himlDst
->hdcMask
, xOff1
, yOff1
, himl1
->cx
, himl1
->cy
, himl1
->hdcMask
, nX1
, 0, SRCCOPY
);
1841 if (i2
>= 0 && i2
< himl2
->cCurImage
)
1842 BitBlt (himlDst
->hdcMask
, xOff2
, yOff2
, himl2
->cx
, himl2
->cy
, himl2
->hdcMask
, nX2
, 0, SRCAND
);
1844 himlDst
->cCurImage
= 1;
1851 /* helper for _read_bitmap currently unused */
1853 static int may_use_dibsection(HDC hdc
) {
1854 int bitspixel
= GetDeviceCaps(hdc
,BITSPIXEL
)*GetDeviceCaps(hdc
,PLANES
);
1859 return GetDeviceCaps(hdc
,CAPS1
) & C1_DIBENGINE
;
1863 /* helper for ImageList_Read, see comments below */
1864 static HBITMAP
_read_bitmap(LPSTREAM pstm
,int ilcFlag
,int cx
,int cy
) {
1865 HDC xdc
= 0, hBitmapDC
=0;
1866 BITMAPFILEHEADER bmfh
;
1867 BITMAPINFOHEADER bmih
;
1868 int bitsperpixel
,palspace
,longsperline
,width
,height
;
1869 LPBITMAPINFOHEADER bmihc
= NULL
;
1871 HBITMAP hbitmap
= 0, hDIB
= 0;
1874 if (!SUCCEEDED(IStream_Read ( pstm
, &bmfh
, sizeof(bmfh
), NULL
)) ||
1875 (bmfh
.bfType
!= (('M'<<8)|'B')) ||
1876 !SUCCEEDED(IStream_Read ( pstm
, &bmih
, sizeof(bmih
), NULL
)) ||
1877 (bmih
.biSize
!= sizeof(bmih
))
1881 bitsperpixel
= bmih
.biPlanes
* bmih
.biBitCount
;
1882 if (bitsperpixel
<=8)
1883 palspace
= (1<<bitsperpixel
)*sizeof(RGBQUAD
);
1886 width
= bmih
.biWidth
;
1887 height
= bmih
.biHeight
;
1888 bmihc
= (LPBITMAPINFOHEADER
)LocalAlloc(LMEM_ZEROINIT
,sizeof(bmih
)+palspace
);
1889 memcpy(bmihc
,&bmih
,sizeof(bmih
));
1890 longsperline
= ((width
*bitsperpixel
+31)&~0x1f)>>5;
1891 bmihc
->biSizeImage
= (longsperline
*height
)<<2;
1893 /* read the palette right after the end of the bitmapinfoheader */
1895 if (!SUCCEEDED(IStream_Read ( pstm
, bmihc
+1, palspace
, NULL
)))
1899 #if 0 /* Magic for NxM -> 1x(N*M) not implemented for DIB Sections */
1900 if ((bitsperpixel
>1) &&
1901 ((ilcFlag
!=ILC_COLORDDB
) && (!ilcFlag
|| may_use_dibsection(xdc
)))
1903 hbitmap
= CreateDIBSection(xdc
,(BITMAPINFO
*)bmihc
,0,(LPVOID
*)&bits
,0,0);
1906 if (!SUCCEEDED(IStream_Read( pstm
, bits
, bmihc
->biSizeImage
, NULL
)))
1912 int i
,nwidth
,nheight
,nRows
;
1914 nwidth
= width
*(height
/cy
);
1916 nRows
= (height
/cy
);
1918 if (bitsperpixel
==1)
1919 hbitmap
= CreateBitmap(nwidth
,nheight
,1,1,NULL
);
1921 hbitmap
= CreateCompatibleBitmap(xdc
,nwidth
,nheight
);
1923 hDIB
= CreateDIBSection(xdc
,(BITMAPINFO
*)bmihc
,0,(LPVOID
*)&bits
,0,0);
1926 if (!SUCCEEDED(IStream_Read( pstm
, bits
, bmihc
->biSizeImage
, NULL
)))
1929 hBitmapDC
= CreateCompatibleDC(0);
1930 SelectObject(hBitmapDC
, hbitmap
);
1932 /* Copy the NxM bitmap into a 1x(N*M) bitmap we need, linewise */
1933 /* Do not forget that windows bitmaps are bottom->top */
1934 TRACE("nRows=%d\n", nRows
);
1935 for (i
=0; i
< nRows
; i
++){
1936 StretchDIBits(hBitmapDC
, width
*i
, 0, width
, cy
, 0, cy
*(nRows
-1-i
), width
, cy
, bits
,
1937 (BITMAPINFO
*)bmihc
, DIB_RGB_COLORS
, SRCCOPY
);
1943 if (xdc
) ReleaseDC(0,xdc
);
1944 if (bmihc
) LocalFree((HLOCAL
)bmihc
);
1945 if (hDIB
) DeleteObject(hDIB
);
1946 if (hBitmapDC
) DeleteDC(hBitmapDC
);
1949 DeleteObject(hbitmap
);
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 * CAVEAT: Those images are within a NxM bitmap, not the 1xN we expect.
1988 * _read_bitmap needs to convert them.
1990 HIMAGELIST WINAPI
ImageList_Read (LPSTREAM pstm
)
1994 HBITMAP hbmColor
=0,hbmMask
=0;
1997 if (!SUCCEEDED(IStream_Read (pstm
, &ilHead
, sizeof(ILHEAD
), NULL
)))
1999 if (ilHead
.usMagic
!= (('L' << 8) | 'I'))
2001 if (ilHead
.usVersion
!= 0x101) /* probably version? */
2005 FIXME(" ilHead.cCurImage = %d\n",ilHead
.cCurImage
);
2006 FIXME(" ilHead.cMaxImage = %d\n",ilHead
.cMaxImage
);
2007 FIXME(" ilHead.cGrow = %d\n",ilHead
.cGrow
);
2008 FIXME(" ilHead.cx = %d\n",ilHead
.cx
);
2009 FIXME(" ilHead.cy = %d\n",ilHead
.cy
);
2010 FIXME(" ilHead.flags = %x\n",ilHead
.flags
);
2011 FIXME(" ilHead.ovls[0] = %d\n",ilHead
.ovls
[0]);
2012 FIXME(" ilHead.ovls[1] = %d\n",ilHead
.ovls
[1]);
2013 FIXME(" ilHead.ovls[2] = %d\n",ilHead
.ovls
[2]);
2014 FIXME(" ilHead.ovls[3] = %d\n",ilHead
.ovls
[3]);
2017 hbmColor
= _read_bitmap(pstm
,ilHead
.flags
& ~ILC_MASK
,ilHead
.cx
,ilHead
.cy
);
2020 if (ilHead
.flags
& ILC_MASK
) {
2021 hbmMask
= _read_bitmap(pstm
,0,ilHead
.cx
,ilHead
.cy
);
2023 DeleteObject(hbmColor
);
2028 himl
= ImageList_Create (
2036 DeleteObject(hbmColor
);
2037 DeleteObject(hbmMask
);
2040 SelectObject(himl
->hdcImage
, hbmColor
);
2041 DeleteObject(himl
->hbmImage
);
2042 himl
->hbmImage
= hbmColor
;
2044 SelectObject(himl
->hdcMask
, hbmMask
);
2045 DeleteObject(himl
->hbmMask
);
2046 himl
->hbmMask
= hbmMask
;
2048 himl
->cCurImage
= ilHead
.cCurImage
;
2049 himl
->cMaxImage
= ilHead
.cMaxImage
;
2051 ImageList_SetBkColor(himl
,ilHead
.bkcolor
);
2053 ImageList_SetOverlayImage(himl
,ilHead
.ovls
[i
],i
+1);
2058 /*************************************************************************
2059 * ImageList_Remove [COMCTL32.@]
2061 * Removes an image from an image list
2064 * himl [I] image list handle
2073 ImageList_Remove (HIMAGELIST himl
, INT i
)
2075 HBITMAP hbmNewImage
, hbmNewMask
;
2079 TRACE("(himl=%p i=%d)\n", himl
, i
);
2081 if (!is_valid(himl
)) {
2082 ERR("Invalid image list handle!\n");
2086 if ((i
< -1) || (i
>= himl
->cCurImage
)) {
2087 TRACE("index out of range! %d\n", i
);
2093 if (himl
->cCurImage
== 0) {
2094 /* remove all on empty ImageList is allowed */
2095 TRACE("remove all on empty ImageList!\n");
2099 himl
->cMaxImage
= himl
->cInitial
+ himl
->cGrow
;
2100 himl
->cCurImage
= 0;
2101 for (nCount
= 0; nCount
< MAX_OVERLAYIMAGE
; nCount
++)
2102 himl
->nOvlIdx
[nCount
] = -1;
2104 hbmNewImage
= ImageList_CreateImage(himl
->hdcImage
, himl
, himl
->cMaxImage
* himl
->cx
, himl
->cy
);
2105 SelectObject (himl
->hdcImage
, hbmNewImage
);
2106 DeleteObject (himl
->hbmImage
);
2107 himl
->hbmImage
= hbmNewImage
;
2109 if (himl
->hbmMask
) {
2110 hbmNewMask
= CreateBitmap (himl
->cMaxImage
* himl
->cx
, himl
->cy
,
2112 SelectObject (himl
->hdcMask
, hbmNewMask
);
2113 DeleteObject (himl
->hbmMask
);
2114 himl
->hbmMask
= hbmNewMask
;
2118 /* delete one image */
2119 TRACE("Remove single image! %d\n", i
);
2121 /* create new bitmap(s) */
2122 nCount
= (himl
->cCurImage
+ himl
->cGrow
- 1);
2123 cxNew
= nCount
* himl
->cx
;
2125 TRACE(" - Number of images: %d / %d (Old/New)\n",
2126 himl
->cCurImage
, himl
->cCurImage
- 1);
2127 TRACE(" - Max. number of images: %d / %d (Old/New)\n",
2128 himl
->cMaxImage
, himl
->cCurImage
+ himl
->cGrow
- 1);
2130 hbmNewImage
= ImageList_CreateImage(himl
->hdcImage
, himl
, cxNew
, himl
->cy
);
2133 hbmNewMask
= CreateBitmap (cxNew
, himl
->cy
, 1, 1, NULL
);
2135 hbmNewMask
= 0; /* Just to keep compiler happy! */
2137 hdcBmp
= CreateCompatibleDC (0);
2139 /* copy all images and masks prior to the "removed" image */
2141 TRACE("Pre image copy: Copy %d images\n", i
);
2143 SelectObject (hdcBmp
, hbmNewImage
);
2144 BitBlt (hdcBmp
, 0, 0, i
* himl
->cx
, himl
->cy
,
2145 himl
->hdcImage
, 0, 0, SRCCOPY
);
2147 if (himl
->hbmMask
) {
2148 SelectObject (hdcBmp
, hbmNewMask
);
2149 BitBlt (hdcBmp
, 0, 0, i
* himl
->cx
, himl
->cy
,
2150 himl
->hdcMask
, 0, 0, SRCCOPY
);
2154 /* copy all images and masks behind the removed image */
2155 if (i
< himl
->cCurImage
- 1) {
2156 TRACE("Post image copy!\n");
2157 SelectObject (hdcBmp
, hbmNewImage
);
2158 BitBlt (hdcBmp
, i
* himl
->cx
, 0, (himl
->cCurImage
- i
- 1) * himl
->cx
,
2159 himl
->cy
, himl
->hdcImage
, (i
+ 1) * himl
->cx
, 0, SRCCOPY
);
2161 if (himl
->hbmMask
) {
2162 SelectObject (hdcBmp
, hbmNewMask
);
2163 BitBlt (hdcBmp
, i
* himl
->cx
, 0,
2164 (himl
->cCurImage
- i
- 1) * himl
->cx
,
2165 himl
->cy
, himl
->hdcMask
, (i
+ 1) * himl
->cx
, 0, SRCCOPY
);
2171 /* delete old images and insert new ones */
2172 SelectObject (himl
->hdcImage
, hbmNewImage
);
2173 DeleteObject (himl
->hbmImage
);
2174 himl
->hbmImage
= hbmNewImage
;
2175 if (himl
->hbmMask
) {
2176 SelectObject (himl
->hdcMask
, hbmNewMask
);
2177 DeleteObject (himl
->hbmMask
);
2178 himl
->hbmMask
= hbmNewMask
;
2182 himl
->cMaxImage
= himl
->cCurImage
+ himl
->cGrow
;
2189 /*************************************************************************
2190 * ImageList_Replace [COMCTL32.@]
2192 * Replaces an image in an image list with a new image.
2195 * himl [I] handle to image list
2197 * hbmImage [I] handle to image bitmap
2198 * hbmMask [I] handle to mask bitmap. Can be NULL.
2206 ImageList_Replace (HIMAGELIST himl
, INT i
, HBITMAP hbmImage
,
2212 TRACE("%p %d %p %p\n", himl
, i
, hbmImage
, hbmMask
);
2214 if (!is_valid(himl
)) {
2215 ERR("Invalid image list handle!\n");
2219 if ((i
>= himl
->cMaxImage
) || (i
< 0)) {
2220 ERR("Invalid image index!\n");
2224 hdcImage
= CreateCompatibleDC (0);
2225 GetObjectA (hbmImage
, sizeof(BITMAP
), (LPVOID
)&bmp
);
2228 SelectObject (hdcImage
, hbmImage
);
2230 StretchBlt (himl
->hdcImage
, i
* himl
->cx
, 0, himl
->cx
, himl
->cy
,
2231 hdcImage
, 0, 0, bmp
.bmWidth
, bmp
.bmHeight
, SRCCOPY
);
2236 SelectObject (hdcImage
, hbmMask
);
2238 StretchBlt (himl
->hdcMask
, i
* himl
->cx
, 0, himl
->cx
, himl
->cy
,
2239 hdcImage
, 0, 0, bmp
.bmWidth
, bmp
.bmHeight
, SRCCOPY
);
2242 /* Remove the background from the image
2244 StretchBlt (himl
->hdcImage
,
2245 i
*himl
->cx
, 0, himl
->cx
, himl
->cy
,
2247 0, 0, bmp
.bmWidth
, bmp
.bmHeight
,
2248 0x220326); /* NOTSRCAND */
2251 DeleteDC (hdcImage
);
2257 /*************************************************************************
2258 * ImageList_ReplaceIcon [COMCTL32.@]
2260 * Replaces an image in an image list using an icon.
2263 * himl [I] handle to image list
2265 * hIcon [I] handle to icon
2268 * Success: index of the replaced image
2273 ImageList_ReplaceIcon (HIMAGELIST himl
, INT i
, HICON hIcon
)
2282 TRACE("(%p %d %p)\n", himl
, i
, hIcon
);
2284 if (!is_valid(himl
))
2286 if ((i
>= himl
->cMaxImage
) || (i
< -1))
2289 hBestFitIcon
= CopyImage(
2292 LR_COPYFROMRESOURCE
);
2294 GetIconInfo (hBestFitIcon
, &ii
);
2295 if (ii
.hbmMask
== 0)
2297 if (ii
.hbmColor
== 0)
2299 GetObjectA (ii
.hbmMask
, sizeof(BITMAP
), (LPVOID
)&bmp
);
2302 if (himl
->cCurImage
+ 1 > himl
->cMaxImage
)
2303 IMAGELIST_InternalExpandBitmaps (himl
, 1, 0, 0);
2305 nIndex
= himl
->cCurImage
;
2311 hdcImage
= CreateCompatibleDC (0);
2312 TRACE("hdcImage=%p\n", hdcImage
);
2314 ERR("invalid hdcImage!\n");
2316 SetTextColor(himl
->hdcImage
, RGB(0,0,0));
2317 SetBkColor (himl
->hdcImage
, RGB(255,255,255));
2318 hbmOldSrc
= SelectObject (hdcImage
, ii
.hbmColor
);
2320 StretchBlt (himl
->hdcImage
, nIndex
* himl
->cx
, 0, himl
->cx
, himl
->cy
,
2321 hdcImage
, 0, 0, bmp
.bmWidth
, bmp
.bmHeight
, SRCCOPY
);
2323 if (himl
->hbmMask
) {
2324 SelectObject (hdcImage
, ii
.hbmMask
);
2325 StretchBlt (himl
->hdcMask
, nIndex
* himl
->cx
, 0, himl
->cx
, himl
->cy
,
2326 hdcImage
, 0, 0, bmp
.bmWidth
, bmp
.bmHeight
, SRCCOPY
);
2329 SelectObject (hdcImage
, hbmOldSrc
);
2332 DestroyIcon(hBestFitIcon
);
2334 DeleteDC (hdcImage
);
2336 DeleteObject (ii
.hbmColor
);
2338 DeleteObject (ii
.hbmMask
);
2340 TRACE("Insert index = %d, himl->cCurImage = %d\n", nIndex
, himl
->cCurImage
);
2345 /*************************************************************************
2346 * ImageList_SetBkColor [COMCTL32.@]
2348 * Sets the background color of an image list.
2351 * himl [I] handle to image list
2352 * clrBk [I] background color
2355 * Success: previous background color
2360 ImageList_SetBkColor (HIMAGELIST himl
, COLORREF clrBk
)
2364 if (!is_valid(himl
))
2367 clrOldBk
= himl
->clrBk
;
2368 himl
->clrBk
= clrBk
;
2373 /*************************************************************************
2374 * ImageList_SetDragCursorImage [COMCTL32.@]
2376 * Combines the specified image with the current drag image
2379 * himlDrag [I] handle to drag image list
2380 * iDrag [I] drag image index
2381 * dxHotspot [I] X position of the hot spot
2382 * dyHotspot [I] Y position of the hot spot
2389 * - The names dxHotspot, dyHotspot are misleading because they have nothing
2390 * to do with a hotspot but are only the offset of the origin of the new
2391 * image relative to the origin of the old image.
2393 * - When this function is called and the drag image is visible, a
2394 * short flickering occurs but this matches the Win9x behavior. It is
2395 * possible to fix the flickering using code like in ImageList_DragMove.
2399 ImageList_SetDragCursorImage (HIMAGELIST himlDrag
, INT iDrag
,
2400 INT dxHotspot
, INT dyHotspot
)
2402 HIMAGELIST himlTemp
;
2405 if (!is_valid(InternalDrag
.himl
) || !is_valid(himlDrag
))
2408 TRACE(" dxH=%d dyH=%d nX=%d nY=%d\n",
2409 dxHotspot
, dyHotspot
, InternalDrag
.dxHotspot
, InternalDrag
.dyHotspot
);
2411 visible
= InternalDrag
.bShow
;
2413 himlTemp
= ImageList_Merge (InternalDrag
.himl
, 0, himlDrag
, iDrag
,
2414 dxHotspot
, dyHotspot
);
2417 /* hide the drag image */
2418 ImageList_DragShowNolock(FALSE
);
2420 if ((InternalDrag
.himl
->cx
!= himlTemp
->cx
) ||
2421 (InternalDrag
.himl
->cy
!= himlTemp
->cy
)) {
2422 /* the size of the drag image changed, invalidate the buffer */
2423 DeleteObject(InternalDrag
.hbmBg
);
2424 InternalDrag
.hbmBg
= 0;
2427 ImageList_Destroy (InternalDrag
.himl
);
2428 InternalDrag
.himl
= himlTemp
;
2431 /* show the drag image */
2432 ImageList_DragShowNolock(TRUE
);
2439 /*************************************************************************
2440 * ImageList_SetFilter [COMCTL32.@]
2442 * Sets a filter (or does something completely different)!!???
2443 * It removes 12 Bytes from the stack (3 Parameters).
2446 * himl [I] SHOULD be a handle to image list
2447 * i [I] COULD be an index?
2452 * Failure: FALSE ???
2455 * This is an UNDOCUMENTED function!!!!
2460 ImageList_SetFilter (HIMAGELIST himl
, INT i
, DWORD dwFilter
)
2462 FIXME("(%p 0x%x 0x%lx):empty stub!\n", himl
, i
, dwFilter
);
2468 /*************************************************************************
2469 * ImageList_SetFlags [COMCTL32.@]
2471 * Sets the image list flags.
2474 * himl [I] Handle to image list
2475 * flags [I] Flags to set
2485 ImageList_SetFlags(HIMAGELIST himl
, DWORD flags
)
2487 FIXME("(%p %08lx):empty stub\n", himl
, flags
);
2492 /*************************************************************************
2493 * ImageList_SetIconSize [COMCTL32.@]
2495 * Sets the image size of the bitmap and deletes all images.
2498 * himl [I] handle to image list
2499 * cx [I] image width
2500 * cy [I] image height
2508 ImageList_SetIconSize (HIMAGELIST himl
, INT cx
, INT cy
)
2513 if (!is_valid(himl
))
2516 /* remove all images */
2517 himl
->cMaxImage
= himl
->cInitial
+ himl
->cGrow
;
2518 himl
->cCurImage
= 0;
2522 /* initialize overlay mask indices */
2523 for (nCount
= 0; nCount
< MAX_OVERLAYIMAGE
; nCount
++)
2524 himl
->nOvlIdx
[nCount
] = -1;
2526 hbmNew
= ImageList_CreateImage(himl
->hdcImage
, himl
, himl
->cMaxImage
* himl
->cx
, himl
->cy
);
2527 SelectObject (himl
->hdcImage
, hbmNew
);
2528 DeleteObject (himl
->hbmImage
);
2529 himl
->hbmImage
= hbmNew
;
2531 if (himl
->hbmMask
) {
2532 hbmNew
= CreateBitmap (himl
->cMaxImage
* himl
->cx
, himl
->cy
,
2534 SelectObject (himl
->hdcMask
, hbmNew
);
2535 DeleteObject (himl
->hbmMask
);
2536 himl
->hbmMask
= hbmNew
;
2543 /*************************************************************************
2544 * ImageList_SetImageCount [COMCTL32.@]
2546 * Resizes an image list to the specified number of images.
2549 * himl [I] handle to image list
2550 * iImageCount [I] number of images in the image list
2558 ImageList_SetImageCount (HIMAGELIST himl
, UINT iImageCount
)
2561 HBITMAP hbmNewBitmap
;
2562 INT nNewCount
, nCopyCount
;
2564 TRACE("%p %d\n",himl
,iImageCount
);
2566 if (!is_valid(himl
))
2568 if (himl
->cCurImage
>= iImageCount
)
2570 if (himl
->cMaxImage
> iImageCount
)
2572 himl
->cCurImage
= iImageCount
;
2576 nNewCount
= iImageCount
+ himl
->cGrow
;
2577 nCopyCount
= min(himl
->cCurImage
, iImageCount
);
2579 hdcBitmap
= CreateCompatibleDC (0);
2581 hbmNewBitmap
= ImageList_CreateImage(hdcBitmap
, himl
, nNewCount
* himl
->cx
, himl
->cy
);
2583 if (hbmNewBitmap
!= 0)
2585 SelectObject (hdcBitmap
, hbmNewBitmap
);
2588 BitBlt (hdcBitmap
, 0, 0, nCopyCount
* himl
->cx
, himl
->cy
,
2589 himl
->hdcImage
, 0, 0, SRCCOPY
);
2591 /* delete 'empty' image space */
2592 SetBkColor (hdcBitmap
, RGB(255, 255, 255));
2593 SetTextColor (hdcBitmap
, RGB(0, 0, 0));
2594 PatBlt (hdcBitmap
, nCopyCount
* himl
->cx
, 0,
2595 (nNewCount
- nCopyCount
) * himl
->cx
, himl
->cy
, BLACKNESS
);
2597 SelectObject (himl
->hdcImage
, hbmNewBitmap
);
2598 DeleteObject (himl
->hbmImage
);
2599 himl
->hbmImage
= hbmNewBitmap
;
2602 ERR("Could not create new image bitmap !\n");
2606 hbmNewBitmap
= CreateBitmap (nNewCount
* himl
->cx
, himl
->cy
,
2608 if (hbmNewBitmap
!= 0)
2610 SelectObject (hdcBitmap
, hbmNewBitmap
);
2613 BitBlt (hdcBitmap
, 0, 0, nCopyCount
* himl
->cx
, himl
->cy
,
2614 himl
->hdcMask
, 0, 0, SRCCOPY
);
2616 /* delete 'empty' image space */
2617 SetBkColor (hdcBitmap
, RGB(255, 255, 255));
2618 SetTextColor (hdcBitmap
, RGB(0, 0, 0));
2619 PatBlt (hdcBitmap
, nCopyCount
* himl
->cx
, 0,
2620 (nNewCount
- nCopyCount
) * himl
->cx
, himl
->cy
, BLACKNESS
);
2622 SelectObject (himl
->hdcMask
, hbmNewBitmap
);
2623 DeleteObject (himl
->hbmMask
);
2624 himl
->hbmMask
= hbmNewBitmap
;
2627 ERR("Could not create new mask bitmap!\n");
2630 DeleteDC (hdcBitmap
);
2632 /* Update max image count and current image count */
2633 himl
->cMaxImage
= nNewCount
;
2634 himl
->cCurImage
= iImageCount
;
2640 /*************************************************************************
2641 * ImageList_SetOverlayImage [COMCTL32.@]
2643 * Assigns an overlay mask index to an existing image in an image list.
2646 * himl [I] handle to image list
2647 * iImage [I] image index
2648 * iOverlay [I] overlay mask index
2656 ImageList_SetOverlayImage (HIMAGELIST himl
, INT iImage
, INT iOverlay
)
2658 if (!is_valid(himl
))
2660 if ((iOverlay
< 1) || (iOverlay
> MAX_OVERLAYIMAGE
))
2662 if ((iImage
!=-1) && ((iImage
< 0) || (iImage
> himl
->cCurImage
)))
2664 himl
->nOvlIdx
[iOverlay
- 1] = iImage
;
2670 /* helper for ImageList_Write - write bitmap to pstm
2671 * currently everything is written as 24 bit RGB, except masks
2674 _write_bitmap(HBITMAP hBitmap
, LPSTREAM pstm
, int cx
, int cy
)
2676 LPBITMAPFILEHEADER bmfh
;
2677 LPBITMAPINFOHEADER bmih
;
2678 LPBYTE data
, lpBits
, lpBitsOrg
;
2680 INT bitCount
, sizeImage
, offBits
, totalSize
;
2681 INT nwidth
, nheight
, nsizeImage
, icount
;
2683 BOOL result
= FALSE
;
2687 GetObjectA(hBitmap
, sizeof(BITMAP
), (LPVOID
)&bm
);
2689 /* XXX is this always correct? */
2690 icount
= bm
.bmWidth
/ cx
;
2692 nheight
= cy
* icount
;
2694 bitCount
= bm
.bmBitsPixel
== 1 ? 1 : 24;
2695 sizeImage
= ((((bm
.bmWidth
* bitCount
)+31) & ~31) >> 3) * bm
.bmHeight
;
2696 nsizeImage
= ((((nwidth
* bitCount
)+31) & ~31) >> 3) * nheight
;
2698 totalSize
= sizeof(BITMAPFILEHEADER
) + sizeof(BITMAPINFOHEADER
);
2700 totalSize
+= (1 << bitCount
) * sizeof(RGBQUAD
);
2701 offBits
= totalSize
;
2702 totalSize
+= nsizeImage
;
2704 data
= (LPBYTE
)LocalAlloc(LMEM_ZEROINIT
, totalSize
);
2705 bmfh
= (LPBITMAPFILEHEADER
)data
;
2706 bmih
= (LPBITMAPINFOHEADER
)(data
+ sizeof(BITMAPFILEHEADER
));
2707 lpBits
= data
+ offBits
;
2709 /* setup BITMAPFILEHEADER */
2710 bmfh
->bfType
= (('M' << 8) | 'B');
2712 bmfh
->bfReserved1
= 0;
2713 bmfh
->bfReserved2
= 0;
2714 bmfh
->bfOffBits
= offBits
;
2716 /* setup BITMAPINFOHEADER */
2717 bmih
->biSize
= sizeof(BITMAPINFOHEADER
);
2718 bmih
->biWidth
= bm
.bmWidth
;
2719 bmih
->biHeight
= bm
.bmHeight
;
2721 bmih
->biBitCount
= bitCount
;
2722 bmih
->biCompression
= BI_RGB
;
2723 bmih
->biSizeImage
= sizeImage
;
2724 bmih
->biXPelsPerMeter
= 0;
2725 bmih
->biYPelsPerMeter
= 0;
2726 bmih
->biClrUsed
= 0;
2727 bmih
->biClrImportant
= 0;
2729 lpBitsOrg
= (LPBYTE
)LocalAlloc(LMEM_ZEROINIT
, sizeImage
);
2730 if(!GetDIBits(xdc
, hBitmap
, 0, bm
.bmHeight
, lpBitsOrg
,
2731 (BITMAPINFO
*)bmih
, DIB_RGB_COLORS
))
2735 int obpl
= (((bm
.bmWidth
*bitCount
+31) & ~31)>>3);
2736 int nbpl
= (((nwidth
*bitCount
+31) & ~31)>>3);
2738 for(i
= 0; i
< nheight
; i
++) {
2739 int ooff
= ((nheight
-1-i
)%cy
) * obpl
+ ((i
/cy
) * nbpl
);
2740 int noff
= (nbpl
* (nheight
-1-i
));
2741 memcpy(lpBits
+ noff
, lpBitsOrg
+ ooff
, nbpl
);
2745 bmih
->biWidth
= nwidth
;
2746 bmih
->biHeight
= nheight
;
2747 bmih
->biSizeImage
= nsizeImage
;
2751 LPBITMAPINFO inf
= (LPBITMAPINFO
)bmih
;
2752 inf
->bmiColors
[0].rgbRed
= inf
->bmiColors
[0].rgbGreen
= inf
->bmiColors
[0].rgbBlue
= 0;
2753 inf
->bmiColors
[1].rgbRed
= inf
->bmiColors
[1].rgbGreen
= inf
->bmiColors
[1].rgbBlue
= 0xff;
2756 if(!SUCCEEDED(IStream_Write(pstm
, data
, totalSize
, NULL
)))
2763 LocalFree((HLOCAL
)lpBitsOrg
);
2764 LocalFree((HLOCAL
)data
);
2770 /*************************************************************************
2771 * ImageList_Write [COMCTL32.@]
2773 * Writes an image list to a stream.
2776 * himl [I] handle to image list
2777 * pstm [O] Pointer to a stream.
2788 ImageList_Write (HIMAGELIST himl
, LPSTREAM pstm
)
2793 if (!is_valid(himl
))
2796 ilHead
.usMagic
= (('L' << 8) | 'I');
2797 ilHead
.usVersion
= 0x101;
2798 ilHead
.cCurImage
= himl
->cCurImage
;
2799 ilHead
.cMaxImage
= himl
->cMaxImage
;
2800 ilHead
.cGrow
= himl
->cGrow
;
2801 ilHead
.cx
= himl
->cx
;
2802 ilHead
.cy
= himl
->cy
;
2803 ilHead
.bkcolor
= himl
->clrBk
;
2804 ilHead
.flags
= himl
->flags
;
2805 for(i
= 0; i
< 4; i
++) {
2806 ilHead
.ovls
[i
] = himl
->nOvlIdx
[i
];
2809 if(!SUCCEEDED(IStream_Write(pstm
, &ilHead
, sizeof(ILHEAD
), NULL
)))
2812 /* write the bitmap */
2813 if(!_write_bitmap(himl
->hbmImage
, pstm
, himl
->cx
, himl
->cy
))
2816 /* write the mask if we have one */
2817 if(himl
->flags
& ILC_MASK
) {
2818 if(!_write_bitmap(himl
->hbmMask
, pstm
, himl
->cx
, himl
->cy
))
2826 static HBITMAP
ImageList_CreateImage(HDC hdc
, HIMAGELIST himl
, UINT width
, UINT height
)
2828 HBITMAP hbmNewBitmap
;
2829 UINT ilc
= (himl
->flags
& 0xFE);
2831 if ((ilc
>= ILC_COLOR4
&& ilc
<= ILC_COLOR32
) || ilc
== ILC_COLOR
)
2836 TRACE("Creating DIBSection: %d Bits per Pixel\n", himl
->uBitsPixel
);
2838 if (himl
->uBitsPixel
<= ILC_COLOR8
)
2844 colors
= 1 << himl
->uBitsPixel
;
2845 bmi
= HeapAlloc(GetProcessHeap(), 0, sizeof(BITMAPINFOHEADER
) +
2846 sizeof(PALETTEENTRY
) * colors
);
2848 pal
= (LPPALETTEENTRY
)bmi
->bmiColors
;
2849 GetPaletteEntries(GetStockObject(DEFAULT_PALETTE
), 0, colors
, pal
);
2851 /* Swap colors returned by GetPaletteEntries so we can use them for
2852 * CreateDIBSection call. */
2853 for (i
= 0; i
< colors
; i
++)
2855 temp
= pal
[i
].peBlue
;
2856 bmi
->bmiColors
[i
].rgbRed
= pal
[i
].peRed
;
2857 bmi
->bmiColors
[i
].rgbBlue
= temp
;
2862 bmi
= HeapAlloc(GetProcessHeap(), 0, sizeof(BITMAPINFOHEADER
));
2865 bmi
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
2866 bmi
->bmiHeader
.biWidth
= width
;
2867 bmi
->bmiHeader
.biHeight
= height
;
2868 bmi
->bmiHeader
.biPlanes
= 1;
2869 bmi
->bmiHeader
.biBitCount
= himl
->uBitsPixel
;
2870 bmi
->bmiHeader
.biCompression
= BI_RGB
;
2871 bmi
->bmiHeader
.biSizeImage
= 0;
2872 bmi
->bmiHeader
.biXPelsPerMeter
= 0;
2873 bmi
->bmiHeader
.biYPelsPerMeter
= 0;
2874 bmi
->bmiHeader
.biClrUsed
= 0;
2875 bmi
->bmiHeader
.biClrImportant
= 0;
2877 hbmNewBitmap
= CreateDIBSection(hdc
, bmi
, DIB_RGB_COLORS
, &bits
, 0, 0);
2879 HeapFree(GetProcessHeap(), 0, bmi
);
2881 else /*if (ilc == ILC_COLORDDB)*/
2883 TRACE("Creating Bitmap: %d Bits per Pixel\n", himl
->uBitsPixel
);
2885 hbmNewBitmap
= CreateBitmap (width
, height
, 1, himl
->uBitsPixel
, NULL
);
2887 TRACE("returning %p\n", hbmNewBitmap
);
2888 return hbmNewBitmap
;
2891 /*************************************************************************
2892 * ImageList_SetColorTable [COMCTL32.@]
2894 * Sets the color table of an image list.
2897 * himl [I] Handle to the image list.
2898 * uStartIndex [I] The first index to set.
2899 * cEntries [I] Number of entries to set.
2900 * prgb [I] New color information for color table for the image list.
2903 * Success: Number of entries in the table that were set.
2907 * ImageList_Create(), SetDIBColorTable()
2911 ImageList_SetColorTable (HIMAGELIST himl
, UINT uStartIndex
, UINT cEntries
, CONST RGBQUAD
* prgb
)
2913 return SetDIBColorTable(himl
->hdcImage
, uStartIndex
, cEntries
, prgb
);