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 "commoncontrols.h"
55 #include "imagelist.h"
56 #include "wine/debug.h"
58 WINE_DEFAULT_DEBUG_CHANNEL(imagelist
);
61 #define MAX_OVERLAYIMAGE 15
63 /* internal image list data used for Drag & Drop operations */
68 /* position of the drag image relative to the window */
71 /* offset of the hotspot relative to the origin of the image */
74 /* is the drag image visible */
76 /* saved background */
80 static INTERNALDRAG InternalDrag
= { 0, 0, 0, 0, 0, 0, FALSE
, 0 };
82 static HBITMAP
ImageList_CreateImage(HDC hdc
, HIMAGELIST himl
, UINT count
);
83 static HRESULT
ImageListImpl_CreateInstance(const IUnknown
*pUnkOuter
, REFIID iid
, void** ppv
);
84 static inline BOOL
is_valid(HIMAGELIST himl
);
87 * An imagelist with N images is tiled like this:
99 static inline UINT
imagelist_height( UINT count
)
101 return ((count
+ TILE_COUNT
- 1)/TILE_COUNT
);
104 static inline void imagelist_point_from_index( HIMAGELIST himl
, UINT index
, LPPOINT pt
)
106 pt
->x
= (index
%TILE_COUNT
) * himl
->cx
;
107 pt
->y
= (index
/TILE_COUNT
) * himl
->cy
;
110 static inline void imagelist_get_bitmap_size( HIMAGELIST himl
, UINT count
, SIZE
*sz
)
112 sz
->cx
= himl
->cx
* TILE_COUNT
;
113 sz
->cy
= imagelist_height( count
) * himl
->cy
;
117 * imagelist_copy_images()
119 * Copies a block of count images from offset src in the list to offset dest.
120 * Images are copied a row at at time. Assumes hdcSrc and hdcDest are different.
122 static inline void imagelist_copy_images( HIMAGELIST himl
, HDC hdcSrc
, HDC hdcDest
,
123 UINT src
, UINT count
, UINT dest
)
129 for ( i
=0; i
<TILE_COUNT
; i
++ )
131 imagelist_point_from_index( himl
, src
+i
, &ptSrc
);
132 imagelist_point_from_index( himl
, dest
+i
, &ptDest
);
134 sz
.cy
= himl
->cy
* imagelist_height( count
- i
);
136 BitBlt( hdcDest
, ptDest
.x
, ptDest
.y
, sz
.cx
, sz
.cy
,
137 hdcSrc
, ptSrc
.x
, ptSrc
.y
, SRCCOPY
);
141 /*************************************************************************
142 * IMAGELIST_InternalExpandBitmaps [Internal]
144 * Expands the bitmaps of an image list by the given number of images.
147 * himl [I] handle to image list
148 * nImageCount [I] number of images to add
154 * This function CANNOT be used to reduce the number of images.
157 IMAGELIST_InternalExpandBitmaps(HIMAGELIST himl
, INT nImageCount
)
160 HBITMAP hbmNewBitmap
, hbmNull
;
164 TRACE("%p has %d allocated %d images\n", himl
, himl
->cCurImage
, himl
->cMaxImage
);
166 if (himl
->cCurImage
+ nImageCount
<= himl
->cMaxImage
)
169 nNewCount
= himl
->cCurImage
+ max(nImageCount
, himl
->cGrow
) + 1;
171 imagelist_get_bitmap_size(himl
, nNewCount
, &sz
);
173 TRACE("Create expanded bitmaps : himl=%p x=%d y=%d count=%d\n", himl
, sz
.cx
, sz
.cy
, nNewCount
);
174 hdcBitmap
= CreateCompatibleDC (0);
176 hbmNewBitmap
= ImageList_CreateImage(hdcBitmap
, himl
, nNewCount
);
178 if (hbmNewBitmap
== 0)
179 ERR("creating new image bitmap (x=%d y=%d)!\n", sz
.cx
, sz
.cy
);
183 hbmNull
= SelectObject (hdcBitmap
, hbmNewBitmap
);
184 BitBlt (hdcBitmap
, 0, 0, sz
.cx
, sz
.cy
,
185 himl
->hdcImage
, 0, 0, SRCCOPY
);
186 SelectObject (hdcBitmap
, hbmNull
);
188 SelectObject (himl
->hdcImage
, hbmNewBitmap
);
189 DeleteObject (himl
->hbmImage
);
190 himl
->hbmImage
= hbmNewBitmap
;
192 if (himl
->flags
& ILC_MASK
)
194 hbmNewBitmap
= CreateBitmap (sz
.cx
, sz
.cy
, 1, 1, NULL
);
196 if (hbmNewBitmap
== 0)
197 ERR("creating new mask bitmap!\n");
201 hbmNull
= SelectObject (hdcBitmap
, hbmNewBitmap
);
202 BitBlt (hdcBitmap
, 0, 0, sz
.cx
, sz
.cy
,
203 himl
->hdcMask
, 0, 0, SRCCOPY
);
204 SelectObject (hdcBitmap
, hbmNull
);
206 SelectObject (himl
->hdcMask
, hbmNewBitmap
);
207 DeleteObject (himl
->hbmMask
);
208 himl
->hbmMask
= hbmNewBitmap
;
211 himl
->cMaxImage
= nNewCount
;
213 DeleteDC (hdcBitmap
);
217 /*************************************************************************
218 * ImageList_Add [COMCTL32.@]
220 * Add an image or images to an image list.
223 * himl [I] handle to image list
224 * hbmImage [I] handle to image bitmap
225 * hbmMask [I] handle to mask bitmap
228 * Success: Index of the first new image.
233 ImageList_Add (HIMAGELIST himl
, HBITMAP hbmImage
, HBITMAP hbmMask
)
235 HDC hdcBitmap
, hdcTemp
;
236 INT nFirstIndex
, nImageCount
, i
;
238 HBITMAP hOldBitmap
, hOldBitmapTemp
;
241 TRACE("himl=%p hbmimage=%p hbmmask=%p\n", himl
, hbmImage
, hbmMask
);
245 if (!GetObjectW(hbmImage
, sizeof(BITMAP
), &bmp
))
248 TRACE("himl %p, cCurImage %d, cMaxImage %d, cGrow %d, cx %d, cy %d\n",
249 himl
, himl
->cCurImage
, himl
->cMaxImage
, himl
->cGrow
, himl
->cx
, himl
->cy
);
251 nImageCount
= bmp
.bmWidth
/ himl
->cx
;
253 TRACE("%p has %d images (%d x %d)\n", hbmImage
, nImageCount
, bmp
.bmWidth
, bmp
.bmHeight
);
255 IMAGELIST_InternalExpandBitmaps(himl
, nImageCount
);
257 hdcBitmap
= CreateCompatibleDC(0);
259 hOldBitmap
= SelectObject(hdcBitmap
, hbmImage
);
261 for (i
=0; i
<nImageCount
; i
++)
263 imagelist_point_from_index( himl
, himl
->cCurImage
+ i
, &pt
);
265 /* Copy result to the imagelist
267 BitBlt( himl
->hdcImage
, pt
.x
, pt
.y
, himl
->cx
, bmp
.bmHeight
,
268 hdcBitmap
, i
*himl
->cx
, 0, SRCCOPY
);
273 hdcTemp
= CreateCompatibleDC(0);
274 hOldBitmapTemp
= SelectObject(hdcTemp
, hbmMask
);
276 BitBlt( himl
->hdcMask
, pt
.x
, pt
.y
, himl
->cx
, bmp
.bmHeight
,
277 hdcTemp
, i
*himl
->cx
, 0, SRCCOPY
);
279 SelectObject(hdcTemp
, hOldBitmapTemp
);
282 /* Remove the background from the image
284 BitBlt( himl
->hdcImage
, pt
.x
, pt
.y
, himl
->cx
, bmp
.bmHeight
,
285 himl
->hdcMask
, pt
.x
, pt
.y
, 0x220326 ); /* NOTSRCAND */
288 SelectObject(hdcBitmap
, hOldBitmap
);
291 nFirstIndex
= himl
->cCurImage
;
292 himl
->cCurImage
+= nImageCount
;
298 /*************************************************************************
299 * ImageList_AddIcon [COMCTL32.@]
301 * Adds an icon to an image list.
304 * himl [I] handle to image list
305 * hIcon [I] handle to icon
308 * Success: index of the new image
311 #undef ImageList_AddIcon
312 INT WINAPI
ImageList_AddIcon (HIMAGELIST himl
, HICON hIcon
)
314 return ImageList_ReplaceIcon (himl
, -1, hIcon
);
318 /*************************************************************************
319 * ImageList_AddMasked [COMCTL32.@]
321 * Adds an image or images to an image list and creates a mask from the
322 * specified bitmap using the mask color.
325 * himl [I] handle to image list.
326 * hBitmap [I] handle to bitmap
327 * clrMask [I] mask color.
330 * Success: Index of the first new image.
335 ImageList_AddMasked (HIMAGELIST himl
, HBITMAP hBitmap
, COLORREF clrMask
)
337 HDC hdcMask
, hdcBitmap
;
338 INT i
, nIndex
, nImageCount
;
341 HBITMAP hMaskBitmap
=0;
345 TRACE("himl=%p hbitmap=%p clrmask=%x\n", himl
, hBitmap
, clrMask
);
349 if (!GetObjectW(hBitmap
, sizeof(BITMAP
), &bmp
))
353 nImageCount
= bmp
.bmWidth
/ himl
->cx
;
357 IMAGELIST_InternalExpandBitmaps(himl
, nImageCount
);
359 nIndex
= himl
->cCurImage
;
360 himl
->cCurImage
+= nImageCount
;
362 hdcBitmap
= CreateCompatibleDC(0);
363 hOldBitmap
= SelectObject(hdcBitmap
, hBitmap
);
365 /* Create a temp Mask so we can remove the background of the Image */
366 hdcMask
= CreateCompatibleDC(0);
367 hMaskBitmap
= CreateBitmap(bmp
.bmWidth
, bmp
.bmHeight
, 1, 1, NULL
);
368 SelectObject(hdcMask
, hMaskBitmap
);
370 /* create monochrome image to the mask bitmap */
371 bkColor
= (clrMask
!= CLR_DEFAULT
) ? clrMask
: GetPixel (hdcBitmap
, 0, 0);
372 SetBkColor (hdcBitmap
, bkColor
);
373 BitBlt (hdcMask
, 0, 0, bmp
.bmWidth
, bmp
.bmHeight
, hdcBitmap
, 0, 0, SRCCOPY
);
375 SetBkColor(hdcBitmap
, RGB(255,255,255));
378 * Remove the background from the image
380 * WINDOWS BUG ALERT!!!!!!
381 * The statement below should not be done in common practice
382 * but this is how ImageList_AddMasked works in Windows.
383 * It overwrites the original bitmap passed, this was discovered
384 * by using the same bitmap to iterate the different styles
385 * on windows where it failed (BUT ImageList_Add is OK)
386 * This is here in case some apps rely on this bug
388 * Blt mode 0x220326 is NOTSRCAND
390 BitBlt(hdcBitmap
, 0, 0, bmp
.bmWidth
, bmp
.bmHeight
, hdcMask
, 0, 0, 0x220326);
392 /* Copy result to the imagelist */
393 for (i
=0; i
<nImageCount
; i
++)
395 imagelist_point_from_index( himl
, nIndex
+ i
, &pt
);
396 BitBlt(himl
->hdcImage
, pt
.x
, pt
.y
, himl
->cx
, bmp
.bmHeight
,
397 hdcBitmap
, i
*himl
->cx
, 0, SRCCOPY
);
398 BitBlt(himl
->hdcMask
, pt
.x
, pt
.y
, himl
->cx
, bmp
.bmHeight
,
399 hdcMask
, i
*himl
->cx
, 0, SRCCOPY
);
403 SelectObject(hdcBitmap
, hOldBitmap
);
405 DeleteObject(hMaskBitmap
);
412 /*************************************************************************
413 * ImageList_BeginDrag [COMCTL32.@]
415 * Creates a temporary image list that contains one image. It will be used
419 * himlTrack [I] handle to the source image list
420 * iTrack [I] index of the drag image in the source image list
421 * dxHotspot [I] X position of the hot spot of the drag image
422 * dyHotspot [I] Y position of the hot spot of the drag image
430 ImageList_BeginDrag (HIMAGELIST himlTrack
, INT iTrack
,
431 INT dxHotspot
, INT dyHotspot
)
435 TRACE("(himlTrack=%p iTrack=%d dx=%d dy=%d)\n", himlTrack
, iTrack
,
436 dxHotspot
, dyHotspot
);
438 if (!is_valid(himlTrack
))
441 if (InternalDrag
.himl
)
442 ImageList_EndDrag ();
447 InternalDrag
.himl
= ImageList_Create (cx
, cy
, himlTrack
->flags
, 1, 1);
448 if (InternalDrag
.himl
== NULL
) {
449 WARN("Error creating drag image list!\n");
453 InternalDrag
.dxHotspot
= dxHotspot
;
454 InternalDrag
.dyHotspot
= dyHotspot
;
457 BitBlt (InternalDrag
.himl
->hdcImage
, 0, 0, cx
, cy
, himlTrack
->hdcImage
, iTrack
* cx
, 0, SRCCOPY
);
460 BitBlt (InternalDrag
.himl
->hdcMask
, 0, 0, cx
, cy
, himlTrack
->hdcMask
, iTrack
* cx
, 0, SRCCOPY
);
462 InternalDrag
.himl
->cCurImage
= 1;
468 /*************************************************************************
469 * ImageList_Copy [COMCTL32.@]
471 * Copies an image of the source image list to an image of the
472 * destination image list. Images can be copied or swapped.
475 * himlDst [I] handle to the destination image list
476 * iDst [I] destination image index.
477 * himlSrc [I] handle to the source image list
478 * iSrc [I] source image index
479 * uFlags [I] flags for the copy operation
486 * Copying from one image list to another is possible. The original
487 * implementation just copies or swaps within one image list.
488 * Could this feature become a bug??? ;-)
492 ImageList_Copy (HIMAGELIST himlDst
, INT iDst
, HIMAGELIST himlSrc
,
493 INT iSrc
, UINT uFlags
)
497 TRACE("himlDst=%p iDst=%d himlSrc=%p iSrc=%d\n", himlDst
, iDst
, himlSrc
, iSrc
);
499 if (!is_valid(himlSrc
) || !is_valid(himlDst
))
501 if ((iDst
< 0) || (iDst
>= himlDst
->cCurImage
))
503 if ((iSrc
< 0) || (iSrc
>= himlSrc
->cCurImage
))
506 imagelist_point_from_index( himlDst
, iDst
, &ptDst
);
507 imagelist_point_from_index( himlSrc
, iSrc
, &ptSrc
);
509 if (uFlags
& ILCF_SWAP
) {
512 HBITMAP hbmTempImage
, hbmTempMask
;
514 hdcBmp
= CreateCompatibleDC (0);
516 /* create temporary bitmaps */
517 hbmTempImage
= CreateBitmap (himlSrc
->cx
, himlSrc
->cy
, 1,
518 himlSrc
->uBitsPixel
, NULL
);
519 hbmTempMask
= CreateBitmap (himlSrc
->cx
, himlSrc
->cy
, 1,
522 /* copy (and stretch) destination to temporary bitmaps.(save) */
524 SelectObject (hdcBmp
, hbmTempImage
);
525 StretchBlt (hdcBmp
, 0, 0, himlSrc
->cx
, himlSrc
->cy
,
526 himlDst
->hdcImage
, ptDst
.x
, ptDst
.y
, himlDst
->cx
, himlDst
->cy
,
529 SelectObject (hdcBmp
, hbmTempMask
);
530 StretchBlt (hdcBmp
, 0, 0, himlSrc
->cx
, himlSrc
->cy
,
531 himlDst
->hdcMask
, ptDst
.x
, ptDst
.y
, himlDst
->cx
, himlDst
->cy
,
534 /* copy (and stretch) source to destination */
536 StretchBlt (himlDst
->hdcImage
, ptDst
.x
, ptDst
.y
, himlDst
->cx
, himlDst
->cy
,
537 himlSrc
->hdcImage
, ptSrc
.x
, ptSrc
.y
, himlSrc
->cx
, himlSrc
->cy
,
540 StretchBlt (himlDst
->hdcMask
, ptDst
.x
, ptDst
.y
, himlDst
->cx
, himlDst
->cy
,
541 himlSrc
->hdcMask
, ptSrc
.x
, ptSrc
.y
, himlSrc
->cx
, himlSrc
->cy
,
544 /* copy (without stretching) temporary bitmaps to source (restore) */
546 BitBlt (himlSrc
->hdcMask
, ptSrc
.x
, ptSrc
.y
, himlSrc
->cx
, himlSrc
->cy
,
547 hdcBmp
, 0, 0, SRCCOPY
);
550 BitBlt (himlSrc
->hdcImage
, ptSrc
.x
, ptSrc
.y
, himlSrc
->cx
, himlSrc
->cy
,
551 hdcBmp
, 0, 0, SRCCOPY
);
552 /* delete temporary bitmaps */
553 DeleteObject (hbmTempMask
);
554 DeleteObject (hbmTempImage
);
559 StretchBlt (himlDst
->hdcImage
, ptDst
.x
, ptDst
.y
, himlDst
->cx
, himlDst
->cy
,
560 himlSrc
->hdcImage
, ptSrc
.x
, ptSrc
.y
, himlSrc
->cx
, himlSrc
->cy
,
564 StretchBlt (himlDst
->hdcMask
, ptDst
.x
, ptDst
.y
, himlDst
->cx
, himlDst
->cy
,
565 himlSrc
->hdcMask
, ptSrc
.x
, ptSrc
.y
, himlSrc
->cx
, himlSrc
->cy
,
573 /*************************************************************************
574 * ImageList_Create [COMCTL32.@]
576 * Creates a new image list.
579 * cx [I] image height
581 * flags [I] creation flags
582 * cInitial [I] initial number of images in the image list
583 * cGrow [I] number of images by which image list grows
586 * Success: Handle to the created image list
590 ImageList_Create (INT cx
, INT cy
, UINT flags
,
591 INT cInitial
, INT cGrow
)
596 UINT ilc
= (flags
& 0xFE);
597 static const WORD aBitBlend25
[] =
598 {0xAA, 0x00, 0x55, 0x00, 0xAA, 0x00, 0x55, 0x00};
600 static const WORD aBitBlend50
[] =
601 {0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA};
603 TRACE("(%d %d 0x%x %d %d)\n", cx
, cy
, flags
, cInitial
, cGrow
);
605 /* Create the IImageList interface for the image list */
606 if (FAILED(ImageListImpl_CreateInstance(NULL
, &IID_IImageList
, (void **)&himl
)))
609 cGrow
= (cGrow
< 4) ? 4 : (cGrow
+ 3) & ~3;
614 himl
->cMaxImage
= cInitial
+ 1;
615 himl
->cInitial
= cInitial
;
617 himl
->clrFg
= CLR_DEFAULT
;
618 himl
->clrBk
= CLR_NONE
;
620 /* initialize overlay mask indices */
621 for (nCount
= 0; nCount
< MAX_OVERLAYIMAGE
; nCount
++)
622 himl
->nOvlIdx
[nCount
] = -1;
624 /* Create Image & Mask DCs */
625 himl
->hdcImage
= CreateCompatibleDC (0);
628 if (himl
->flags
& ILC_MASK
){
629 himl
->hdcMask
= CreateCompatibleDC(0);
634 /* Default to ILC_COLOR4 if none of the ILC_COLOR* flags are specified */
635 if (ilc
== ILC_COLOR
)
638 if (ilc
>= ILC_COLOR4
&& ilc
<= ILC_COLOR32
)
639 himl
->uBitsPixel
= ilc
;
641 himl
->uBitsPixel
= (UINT
)GetDeviceCaps (himl
->hdcImage
, BITSPIXEL
);
643 if (himl
->cMaxImage
> 0) {
644 himl
->hbmImage
= ImageList_CreateImage(himl
->hdcImage
, himl
, himl
->cMaxImage
);
645 SelectObject(himl
->hdcImage
, himl
->hbmImage
);
649 if ((himl
->cMaxImage
> 0) && (himl
->flags
& ILC_MASK
)) {
652 imagelist_get_bitmap_size(himl
, himl
->cMaxImage
, &sz
);
653 himl
->hbmMask
= CreateBitmap (sz
.cx
, sz
.cy
, 1, 1, NULL
);
654 if (himl
->hbmMask
== 0) {
655 ERR("Error creating mask bitmap!\n");
658 SelectObject(himl
->hdcMask
, himl
->hbmMask
);
663 /* create blending brushes */
664 hbmTemp
= CreateBitmap (8, 8, 1, 1, aBitBlend25
);
665 himl
->hbrBlend25
= CreatePatternBrush (hbmTemp
);
666 DeleteObject (hbmTemp
);
668 hbmTemp
= CreateBitmap (8, 8, 1, 1, aBitBlend50
);
669 himl
->hbrBlend50
= CreatePatternBrush (hbmTemp
);
670 DeleteObject (hbmTemp
);
672 TRACE("created imagelist %p\n", himl
);
676 ImageList_Destroy(himl
);
681 /*************************************************************************
682 * ImageList_Destroy [COMCTL32.@]
684 * Destroys an image list.
687 * himl [I] handle to image list
695 ImageList_Destroy (HIMAGELIST himl
)
700 IImageList_Release((IImageList
*) himl
);
705 /*************************************************************************
706 * ImageList_DragEnter [COMCTL32.@]
708 * Locks window update and displays the drag image at the given position.
711 * hwndLock [I] handle of the window that owns the drag image.
712 * x [I] X position of the drag image.
713 * y [I] Y position of the drag image.
720 * The position of the drag image is relative to the window, not
725 ImageList_DragEnter (HWND hwndLock
, INT x
, INT y
)
727 TRACE("(hwnd=%p x=%d y=%d)\n", hwndLock
, x
, y
);
729 if (!is_valid(InternalDrag
.himl
))
733 InternalDrag
.hwnd
= hwndLock
;
735 InternalDrag
.hwnd
= GetDesktopWindow ();
740 /* draw the drag image and save the background */
741 if (!ImageList_DragShowNolock(TRUE
)) {
749 /*************************************************************************
750 * ImageList_DragLeave [COMCTL32.@]
752 * Unlocks window update and hides the drag image.
755 * hwndLock [I] handle of the window that owns the drag image.
763 ImageList_DragLeave (HWND hwndLock
)
765 /* As we don't save drag info in the window this can lead to problems if
766 an app does not supply the same window as DragEnter */
768 InternalDrag.hwnd = hwndLock;
770 InternalDrag.hwnd = GetDesktopWindow (); */
772 hwndLock
= GetDesktopWindow();
773 if(InternalDrag
.hwnd
!= hwndLock
)
774 FIXME("DragLeave hWnd != DragEnter hWnd\n");
776 ImageList_DragShowNolock (FALSE
);
782 /*************************************************************************
783 * ImageList_InternalDragDraw [Internal]
785 * Draws the drag image.
788 * hdc [I] device context to draw into.
789 * x [I] X position of the drag image.
790 * y [I] Y position of the drag image.
797 * The position of the drag image is relative to the window, not
803 ImageList_InternalDragDraw (HDC hdc
, INT x
, INT y
)
805 IMAGELISTDRAWPARAMS imldp
;
807 ZeroMemory (&imldp
, sizeof(imldp
));
808 imldp
.cbSize
= sizeof(imldp
);
809 imldp
.himl
= InternalDrag
.himl
;
814 imldp
.rgbBk
= CLR_DEFAULT
;
815 imldp
.rgbFg
= CLR_DEFAULT
;
816 imldp
.fStyle
= ILD_NORMAL
;
817 imldp
.fState
= ILS_ALPHA
;
820 /* FIXME: instead of using the alpha blending, we should
821 * create a 50% mask, and draw it semitransparantly that way */
822 ImageList_DrawIndirect (&imldp
);
825 /*************************************************************************
826 * ImageList_DragMove [COMCTL32.@]
828 * Moves the drag image.
831 * x [I] X position of the drag image.
832 * y [I] Y position of the drag image.
839 * The position of the drag image is relative to the window, not
843 * The drag image should be drawn semitransparent.
847 ImageList_DragMove (INT x
, INT y
)
849 TRACE("(x=%d y=%d)\n", x
, y
);
851 if (!is_valid(InternalDrag
.himl
))
854 /* draw/update the drag image */
855 if (InternalDrag
.bShow
) {
859 HBITMAP hbmOffScreen
;
860 INT origNewX
, origNewY
;
861 INT origOldX
, origOldY
;
862 INT origRegX
, origRegY
;
863 INT sizeRegX
, sizeRegY
;
866 /* calculate the update region */
867 origNewX
= x
- InternalDrag
.dxHotspot
;
868 origNewY
= y
- InternalDrag
.dyHotspot
;
869 origOldX
= InternalDrag
.x
- InternalDrag
.dxHotspot
;
870 origOldY
= InternalDrag
.y
- InternalDrag
.dyHotspot
;
871 origRegX
= min(origNewX
, origOldX
);
872 origRegY
= min(origNewY
, origOldY
);
873 sizeRegX
= InternalDrag
.himl
->cx
+ abs(x
- InternalDrag
.x
);
874 sizeRegY
= InternalDrag
.himl
->cy
+ abs(y
- InternalDrag
.y
);
876 hdcDrag
= GetDCEx(InternalDrag
.hwnd
, 0,
877 DCX_WINDOW
| DCX_CACHE
| DCX_LOCKWINDOWUPDATE
);
878 hdcOffScreen
= CreateCompatibleDC(hdcDrag
);
879 hdcBg
= CreateCompatibleDC(hdcDrag
);
881 hbmOffScreen
= CreateCompatibleBitmap(hdcDrag
, sizeRegX
, sizeRegY
);
882 SelectObject(hdcOffScreen
, hbmOffScreen
);
883 SelectObject(hdcBg
, InternalDrag
.hbmBg
);
885 /* get the actual background of the update region */
886 BitBlt(hdcOffScreen
, 0, 0, sizeRegX
, sizeRegY
, hdcDrag
,
887 origRegX
, origRegY
, SRCCOPY
);
888 /* erase the old image */
889 BitBlt(hdcOffScreen
, origOldX
- origRegX
, origOldY
- origRegY
,
890 InternalDrag
.himl
->cx
, InternalDrag
.himl
->cy
, hdcBg
, 0, 0,
892 /* save the background */
893 BitBlt(hdcBg
, 0, 0, InternalDrag
.himl
->cx
, InternalDrag
.himl
->cy
,
894 hdcOffScreen
, origNewX
- origRegX
, origNewY
- origRegY
, SRCCOPY
);
896 ImageList_InternalDragDraw(hdcOffScreen
, origNewX
- origRegX
,
897 origNewY
- origRegY
);
898 /* draw the update region to the screen */
899 BitBlt(hdcDrag
, origRegX
, origRegY
, sizeRegX
, sizeRegY
,
900 hdcOffScreen
, 0, 0, SRCCOPY
);
903 DeleteDC(hdcOffScreen
);
904 DeleteObject(hbmOffScreen
);
905 ReleaseDC(InternalDrag
.hwnd
, hdcDrag
);
908 /* update the image position */
916 /*************************************************************************
917 * ImageList_DragShowNolock [COMCTL32.@]
919 * Shows or hides the drag image.
922 * bShow [I] TRUE shows the drag image, FALSE hides it.
929 * The drag image should be drawn semitransparent.
933 ImageList_DragShowNolock (BOOL bShow
)
939 if (!is_valid(InternalDrag
.himl
))
942 TRACE("bShow=0x%X!\n", bShow
);
944 /* DragImage is already visible/hidden */
945 if ((InternalDrag
.bShow
&& bShow
) || (!InternalDrag
.bShow
&& !bShow
)) {
949 /* position of the origin of the DragImage */
950 x
= InternalDrag
.x
- InternalDrag
.dxHotspot
;
951 y
= InternalDrag
.y
- InternalDrag
.dyHotspot
;
953 hdcDrag
= GetDCEx (InternalDrag
.hwnd
, 0,
954 DCX_WINDOW
| DCX_CACHE
| DCX_LOCKWINDOWUPDATE
);
959 hdcBg
= CreateCompatibleDC(hdcDrag
);
960 if (!InternalDrag
.hbmBg
) {
961 InternalDrag
.hbmBg
= CreateCompatibleBitmap(hdcDrag
,
962 InternalDrag
.himl
->cx
, InternalDrag
.himl
->cy
);
964 SelectObject(hdcBg
, InternalDrag
.hbmBg
);
967 /* save the background */
968 BitBlt(hdcBg
, 0, 0, InternalDrag
.himl
->cx
, InternalDrag
.himl
->cy
,
969 hdcDrag
, x
, y
, SRCCOPY
);
971 ImageList_InternalDragDraw(hdcDrag
, x
, y
);
974 BitBlt(hdcDrag
, x
, y
, InternalDrag
.himl
->cx
, InternalDrag
.himl
->cy
,
975 hdcBg
, 0, 0, SRCCOPY
);
978 InternalDrag
.bShow
= !InternalDrag
.bShow
;
981 ReleaseDC (InternalDrag
.hwnd
, hdcDrag
);
986 /*************************************************************************
987 * ImageList_Draw [COMCTL32.@]
992 * himl [I] handle to image list
994 * hdc [I] handle to device context
997 * fStyle [I] drawing flags
1008 ImageList_Draw (HIMAGELIST himl
, INT i
, HDC hdc
, INT x
, INT y
, UINT fStyle
)
1010 return ImageList_DrawEx (himl
, i
, hdc
, x
, y
, 0, 0,
1011 CLR_DEFAULT
, CLR_DEFAULT
, fStyle
);
1015 /*************************************************************************
1016 * ImageList_DrawEx [COMCTL32.@]
1018 * Draws an image and allows to use extended drawing features.
1021 * himl [I] handle to image list
1023 * hdc [I] handle to device context
1028 * rgbBk [I] background color
1029 * rgbFg [I] foreground color
1030 * fStyle [I] drawing flags
1037 * Calls ImageList_DrawIndirect.
1040 * ImageList_DrawIndirect.
1044 ImageList_DrawEx (HIMAGELIST himl
, INT i
, HDC hdc
, INT x
, INT y
,
1045 INT dx
, INT dy
, COLORREF rgbBk
, COLORREF rgbFg
,
1048 IMAGELISTDRAWPARAMS imldp
;
1050 ZeroMemory (&imldp
, sizeof(imldp
));
1051 imldp
.cbSize
= sizeof(imldp
);
1059 imldp
.rgbBk
= rgbBk
;
1060 imldp
.rgbFg
= rgbFg
;
1061 imldp
.fStyle
= fStyle
;
1063 return ImageList_DrawIndirect (&imldp
);
1067 /*************************************************************************
1068 * ImageList_DrawIndirect [COMCTL32.@]
1070 * Draws an image using various parameters specified in pimldp.
1073 * pimldp [I] pointer to IMAGELISTDRAWPARAMS structure.
1081 ImageList_DrawIndirect (IMAGELISTDRAWPARAMS
*pimldp
)
1083 INT cx
, cy
, nOvlIdx
;
1084 DWORD fState
, dwRop
;
1086 COLORREF oldImageBk
, oldImageFg
;
1087 HDC hImageDC
, hImageListDC
, hMaskListDC
;
1088 HBITMAP hImageBmp
, hOldImageBmp
, hBlendMaskBmp
;
1089 BOOL bIsTransparent
, bBlend
, bResult
= FALSE
, bMask
;
1094 if (!pimldp
|| !(himl
= pimldp
->himl
)) return FALSE
;
1095 if (!is_valid(himl
)) return FALSE
;
1096 if ((pimldp
->i
< 0) || (pimldp
->i
>= himl
->cCurImage
)) return FALSE
;
1098 imagelist_point_from_index( himl
, pimldp
->i
, &pt
);
1099 pt
.x
+= pimldp
->xBitmap
;
1100 pt
.y
+= pimldp
->yBitmap
;
1102 fState
= pimldp
->cbSize
< sizeof(IMAGELISTDRAWPARAMS
) ? ILS_NORMAL
: pimldp
->fState
;
1103 fStyle
= pimldp
->fStyle
& ~ILD_OVERLAYMASK
;
1104 cx
= (pimldp
->cx
== 0) ? himl
->cx
: pimldp
->cx
;
1105 cy
= (pimldp
->cy
== 0) ? himl
->cy
: pimldp
->cy
;
1107 bIsTransparent
= (fStyle
& ILD_TRANSPARENT
);
1108 if( pimldp
->rgbBk
== CLR_NONE
)
1109 bIsTransparent
= TRUE
;
1110 if( ( pimldp
->rgbBk
== CLR_DEFAULT
) && ( himl
->clrBk
== CLR_NONE
) )
1111 bIsTransparent
= TRUE
;
1112 bMask
= (himl
->flags
& ILC_MASK
) && (fStyle
& ILD_MASK
) ;
1113 bBlend
= (fStyle
& (ILD_BLEND25
| ILD_BLEND50
) ) && !bMask
;
1115 TRACE("himl(%p) hbmMask(%p) iImage(%d) x(%d) y(%d) cx(%d) cy(%d)\n",
1116 himl
, himl
->hbmMask
, pimldp
->i
, pimldp
->x
, pimldp
->y
, cx
, cy
);
1118 /* we will use these DCs to access the images and masks in the ImageList */
1119 hImageListDC
= himl
->hdcImage
;
1120 hMaskListDC
= himl
->hdcMask
;
1122 /* these will accumulate the image and mask for the image we're drawing */
1123 hImageDC
= CreateCompatibleDC( pimldp
->hdcDst
);
1124 hImageBmp
= CreateCompatibleBitmap( pimldp
->hdcDst
, cx
, cy
);
1125 hBlendMaskBmp
= bBlend
? CreateBitmap(cx
, cy
, 1, 1, NULL
) : 0;
1127 /* Create a compatible DC. */
1128 if (!hImageListDC
|| !hImageDC
|| !hImageBmp
||
1129 (bBlend
&& !hBlendMaskBmp
) || (himl
->hbmMask
&& !hMaskListDC
))
1132 hOldImageBmp
= SelectObject(hImageDC
, hImageBmp
);
1135 * To obtain a transparent look, background color should be set
1136 * to white and foreground color to black when blting the
1139 oldImageFg
= SetTextColor( hImageDC
, RGB( 0, 0, 0 ) );
1140 oldImageBk
= SetBkColor( hImageDC
, RGB( 0xff, 0xff, 0xff ) );
1142 if (fState
& ILS_ALPHA
)
1147 func
.BlendOp
= AC_SRC_OVER
;
1148 func
.BlendFlags
= 0;
1149 func
.SourceConstantAlpha
= pimldp
->Frame
;
1150 func
.AlphaFormat
= AC_SRC_ALPHA
;
1153 bResult
= GdiAlphaBlend( pimldp
->hdcDst
, pimldp
->x
, pimldp
->y
, cx
, cy
,
1154 hImageListDC
, pt
.x
, pt
.y
, cx
, cy
, func
);
1157 colour
= pimldp
->rgbBk
;
1158 if (colour
== CLR_DEFAULT
) colour
= himl
->clrBk
;
1159 if (colour
== CLR_NONE
) colour
= GetBkColor( pimldp
->hdcDst
);
1161 hOldBrush
= SelectObject (hImageDC
, CreateSolidBrush (colour
));
1162 PatBlt( hImageDC
, 0, 0, cx
, cy
, PATCOPY
);
1163 GdiAlphaBlend( hImageDC
, 0, 0, cx
, cy
, hImageListDC
, pt
.x
, pt
.y
, cx
, cy
, func
);
1164 DeleteObject (SelectObject (hImageDC
, hOldBrush
));
1165 bResult
= BitBlt( pimldp
->hdcDst
, pimldp
->x
, pimldp
->y
, cx
, cy
, hImageDC
, 0, 0, SRCCOPY
);
1170 * Draw the initial image
1173 if (himl
->hbmMask
) {
1174 hOldBrush
= SelectObject (hImageDC
, CreateSolidBrush (GetTextColor(pimldp
->hdcDst
)));
1175 PatBlt( hImageDC
, 0, 0, cx
, cy
, PATCOPY
);
1176 BitBlt(hImageDC
, 0, 0, cx
, cy
, hMaskListDC
, pt
.x
, pt
.y
, SRCPAINT
);
1177 DeleteObject (SelectObject (hImageDC
, hOldBrush
));
1178 if( bIsTransparent
)
1180 BitBlt ( pimldp
->hdcDst
, pimldp
->x
, pimldp
->y
, cx
, cy
, hImageDC
, 0, 0, SRCAND
);
1185 hOldBrush
= SelectObject (hImageDC
, GetStockObject(BLACK_BRUSH
));
1186 PatBlt( hImageDC
, 0, 0, cx
, cy
, PATCOPY
);
1187 SelectObject(hImageDC
, hOldBrush
);
1190 /* blend the image with the needed solid background */
1191 COLORREF colour
= RGB(0,0,0);
1193 if( !bIsTransparent
)
1195 colour
= pimldp
->rgbBk
;
1196 if( colour
== CLR_DEFAULT
)
1197 colour
= himl
->clrBk
;
1198 if( colour
== CLR_NONE
)
1199 colour
= GetBkColor(pimldp
->hdcDst
);
1202 hOldBrush
= SelectObject (hImageDC
, CreateSolidBrush (colour
));
1203 PatBlt( hImageDC
, 0, 0, cx
, cy
, PATCOPY
);
1206 BitBlt( hImageDC
, 0, 0, cx
, cy
, hMaskListDC
, pt
.x
, pt
.y
, SRCAND
);
1207 BitBlt( hImageDC
, 0, 0, cx
, cy
, hImageListDC
, pt
.x
, pt
.y
, SRCPAINT
);
1210 BitBlt( hImageDC
, 0, 0, cx
, cy
, hImageListDC
, pt
.x
, pt
.y
, SRCCOPY
);
1211 DeleteObject (SelectObject (hImageDC
, hOldBrush
));
1214 /* Time for blending, if required */
1217 COLORREF clrBlend
= pimldp
->rgbFg
;
1218 HDC hBlendMaskDC
= hImageListDC
;
1221 /* Create the blend Mask */
1222 hOldBitmap
= SelectObject(hBlendMaskDC
, hBlendMaskBmp
);
1223 hBlendBrush
= fStyle
& ILD_BLEND50
? himl
->hbrBlend50
: himl
->hbrBlend25
;
1224 hOldBrush
= SelectObject(hBlendMaskDC
, hBlendBrush
);
1225 PatBlt(hBlendMaskDC
, 0, 0, cx
, cy
, PATCOPY
);
1226 SelectObject(hBlendMaskDC
, hOldBrush
);
1228 /* Modify the blend mask if an Image Mask exist */
1230 BitBlt(hBlendMaskDC
, 0, 0, cx
, cy
, hMaskListDC
, pt
.x
, pt
.y
, 0x220326); /* NOTSRCAND */
1231 BitBlt(hBlendMaskDC
, 0, 0, cx
, cy
, hBlendMaskDC
, 0, 0, NOTSRCCOPY
);
1234 /* now apply blend to the current image given the BlendMask */
1235 if (clrBlend
== CLR_DEFAULT
) clrBlend
= GetSysColor (COLOR_HIGHLIGHT
);
1236 else if (clrBlend
== CLR_NONE
) clrBlend
= GetTextColor (pimldp
->hdcDst
);
1237 hOldBrush
= SelectObject (hImageDC
, CreateSolidBrush(clrBlend
));
1238 BitBlt (hImageDC
, 0, 0, cx
, cy
, hBlendMaskDC
, 0, 0, 0xB8074A); /* PSDPxax */
1239 DeleteObject(SelectObject(hImageDC
, hOldBrush
));
1240 SelectObject(hBlendMaskDC
, hOldBitmap
);
1243 /* Now do the overlay image, if any */
1244 nOvlIdx
= (pimldp
->fStyle
& ILD_OVERLAYMASK
) >> 8;
1245 if ( (nOvlIdx
>= 1) && (nOvlIdx
<= MAX_OVERLAYIMAGE
)) {
1246 nOvlIdx
= himl
->nOvlIdx
[nOvlIdx
- 1];
1247 if ((nOvlIdx
>= 0) && (nOvlIdx
< himl
->cCurImage
)) {
1249 imagelist_point_from_index( himl
, nOvlIdx
, &ptOvl
);
1250 ptOvl
.x
+= pimldp
->xBitmap
;
1251 if (himl
->hbmMask
&& !(fStyle
& ILD_IMAGE
))
1252 BitBlt (hImageDC
, 0, 0, cx
, cy
, hMaskListDC
, ptOvl
.x
, ptOvl
.y
, SRCAND
);
1253 BitBlt (hImageDC
, 0, 0, cx
, cy
, hImageListDC
, ptOvl
.x
, ptOvl
.y
, SRCPAINT
);
1257 if (fState
& ILS_SATURATE
) FIXME("ILS_SATURATE: unimplemented!\n");
1258 if (fState
& ILS_GLOW
) FIXME("ILS_GLOW: unimplemented!\n");
1259 if (fState
& ILS_SHADOW
) FIXME("ILS_SHADOW: unimplemented!\n");
1261 if (fStyle
& ILD_PRESERVEALPHA
) FIXME("ILD_PRESERVEALPHA: unimplemented!\n");
1262 if (fStyle
& ILD_SCALE
) FIXME("ILD_SCALE: unimplemented!\n");
1263 if (fStyle
& ILD_DPISCALE
) FIXME("ILD_DPISCALE: unimplemented!\n");
1265 /* now copy the image to the screen */
1267 if (himl
->hbmMask
&& bIsTransparent
) {
1268 COLORREF oldDstFg
= SetTextColor(pimldp
->hdcDst
, RGB( 0, 0, 0 ) );
1269 COLORREF oldDstBk
= SetBkColor(pimldp
->hdcDst
, RGB( 0xff, 0xff, 0xff ));
1270 BitBlt (pimldp
->hdcDst
, pimldp
->x
, pimldp
->y
, cx
, cy
, hMaskListDC
, pt
.x
, pt
.y
, SRCAND
);
1271 SetBkColor(pimldp
->hdcDst
, oldDstBk
);
1272 SetTextColor(pimldp
->hdcDst
, oldDstFg
);
1275 if (fStyle
& ILD_ROP
) dwRop
= pimldp
->dwRop
;
1276 BitBlt (pimldp
->hdcDst
, pimldp
->x
, pimldp
->y
, cx
, cy
, hImageDC
, 0, 0, dwRop
);
1280 /* cleanup the mess */
1281 SetBkColor(hImageDC
, oldImageBk
);
1282 SetTextColor(hImageDC
, oldImageFg
);
1283 SelectObject(hImageDC
, hOldImageBmp
);
1285 DeleteObject(hBlendMaskBmp
);
1286 DeleteObject(hImageBmp
);
1293 /*************************************************************************
1294 * ImageList_Duplicate [COMCTL32.@]
1296 * Duplicates an image list.
1299 * himlSrc [I] source image list handle
1302 * Success: Handle of duplicated image list.
1307 ImageList_Duplicate (HIMAGELIST himlSrc
)
1311 if (!is_valid(himlSrc
)) {
1312 ERR("Invalid image list handle!\n");
1316 himlDst
= ImageList_Create (himlSrc
->cx
, himlSrc
->cy
, himlSrc
->flags
,
1317 himlSrc
->cInitial
, himlSrc
->cGrow
);
1323 imagelist_get_bitmap_size(himlSrc
, himlSrc
->cCurImage
, &sz
);
1324 BitBlt (himlDst
->hdcImage
, 0, 0, sz
.cx
, sz
.cy
,
1325 himlSrc
->hdcImage
, 0, 0, SRCCOPY
);
1327 if (himlDst
->hbmMask
)
1328 BitBlt (himlDst
->hdcMask
, 0, 0, sz
.cx
, sz
.cy
,
1329 himlSrc
->hdcMask
, 0, 0, SRCCOPY
);
1331 himlDst
->cCurImage
= himlSrc
->cCurImage
;
1332 himlDst
->cMaxImage
= himlSrc
->cMaxImage
;
1338 /*************************************************************************
1339 * ImageList_EndDrag [COMCTL32.@]
1341 * Finishes a drag operation.
1352 ImageList_EndDrag (void)
1354 /* cleanup the InternalDrag struct */
1355 InternalDrag
.hwnd
= 0;
1356 ImageList_Destroy (InternalDrag
.himl
);
1357 InternalDrag
.himl
= 0;
1360 InternalDrag
.dxHotspot
= 0;
1361 InternalDrag
.dyHotspot
= 0;
1362 InternalDrag
.bShow
= FALSE
;
1363 DeleteObject(InternalDrag
.hbmBg
);
1364 InternalDrag
.hbmBg
= 0;
1368 /*************************************************************************
1369 * ImageList_GetBkColor [COMCTL32.@]
1371 * Returns the background color of an image list.
1374 * himl [I] Image list handle.
1377 * Success: background color
1382 ImageList_GetBkColor (HIMAGELIST himl
)
1384 return himl
? himl
->clrBk
: CLR_NONE
;
1388 /*************************************************************************
1389 * ImageList_GetDragImage [COMCTL32.@]
1391 * Returns the handle to the internal drag image list.
1394 * ppt [O] Pointer to the drag position. Can be NULL.
1395 * pptHotspot [O] Pointer to the position of the hot spot. Can be NULL.
1398 * Success: Handle of the drag image list.
1403 ImageList_GetDragImage (POINT
*ppt
, POINT
*pptHotspot
)
1405 if (is_valid(InternalDrag
.himl
)) {
1407 ppt
->x
= InternalDrag
.x
;
1408 ppt
->y
= InternalDrag
.y
;
1411 pptHotspot
->x
= InternalDrag
.dxHotspot
;
1412 pptHotspot
->y
= InternalDrag
.dyHotspot
;
1414 return (InternalDrag
.himl
);
1421 /*************************************************************************
1422 * ImageList_GetFlags [COMCTL32.@]
1424 * Gets the flags of the specified image list.
1427 * himl [I] Handle to image list
1437 ImageList_GetFlags(HIMAGELIST himl
)
1439 TRACE("%p\n", himl
);
1441 return is_valid(himl
) ? himl
->flags
: 0;
1445 /*************************************************************************
1446 * ImageList_GetIcon [COMCTL32.@]
1448 * Creates an icon from a masked image of an image list.
1451 * himl [I] handle to image list
1453 * flags [I] drawing style flags
1456 * Success: icon handle
1461 ImageList_GetIcon (HIMAGELIST himl
, INT i
, UINT fStyle
)
1465 HBITMAP hOldDstBitmap
;
1469 TRACE("%p %d %d\n", himl
, i
, fStyle
);
1470 if (!is_valid(himl
) || (i
< 0) || (i
>= himl
->cCurImage
)) return NULL
;
1476 /* create colour bitmap */
1478 ii
.hbmColor
= CreateCompatibleBitmap(hdcDst
, himl
->cx
, himl
->cy
);
1479 ReleaseDC(0, hdcDst
);
1481 hdcDst
= CreateCompatibleDC(0);
1483 imagelist_point_from_index( himl
, i
, &pt
);
1486 ii
.hbmMask
= CreateBitmap (himl
->cx
, himl
->cy
, 1, 1, NULL
);
1487 hOldDstBitmap
= SelectObject (hdcDst
, ii
.hbmMask
);
1488 if (himl
->hbmMask
) {
1489 BitBlt (hdcDst
, 0, 0, himl
->cx
, himl
->cy
,
1490 himl
->hdcMask
, pt
.x
, pt
.y
, SRCCOPY
);
1493 PatBlt (hdcDst
, 0, 0, himl
->cx
, himl
->cy
, BLACKNESS
);
1496 SelectObject (hdcDst
, ii
.hbmColor
);
1497 BitBlt (hdcDst
, 0, 0, himl
->cx
, himl
->cy
,
1498 himl
->hdcImage
, pt
.x
, pt
.y
, SRCCOPY
);
1501 * CreateIconIndirect requires us to deselect the bitmaps from
1502 * the DCs before calling
1504 SelectObject(hdcDst
, hOldDstBitmap
);
1506 hIcon
= CreateIconIndirect (&ii
);
1508 DeleteObject (ii
.hbmMask
);
1509 DeleteObject (ii
.hbmColor
);
1516 /*************************************************************************
1517 * ImageList_GetIconSize [COMCTL32.@]
1519 * Retrieves the size of an image in an image list.
1522 * himl [I] handle to image list
1523 * cx [O] pointer to the image width.
1524 * cy [O] pointer to the image height.
1531 * All images in an image list have the same size.
1535 ImageList_GetIconSize (HIMAGELIST himl
, INT
*cx
, INT
*cy
)
1537 if (!is_valid(himl
))
1539 if ((himl
->cx
<= 0) || (himl
->cy
<= 0))
1551 /*************************************************************************
1552 * ImageList_GetImageCount [COMCTL32.@]
1554 * Returns the number of images in an image list.
1557 * himl [I] handle to image list
1560 * Success: Number of images.
1565 ImageList_GetImageCount (HIMAGELIST himl
)
1567 if (!is_valid(himl
))
1570 return himl
->cCurImage
;
1574 /*************************************************************************
1575 * ImageList_GetImageInfo [COMCTL32.@]
1577 * Returns information about an image in an image list.
1580 * himl [I] handle to image list
1582 * pImageInfo [O] pointer to the image information
1590 ImageList_GetImageInfo (HIMAGELIST himl
, INT i
, IMAGEINFO
*pImageInfo
)
1594 if (!is_valid(himl
) || (pImageInfo
== NULL
))
1596 if ((i
< 0) || (i
>= himl
->cCurImage
))
1599 pImageInfo
->hbmImage
= himl
->hbmImage
;
1600 pImageInfo
->hbmMask
= himl
->hbmMask
;
1602 imagelist_point_from_index( himl
, i
, &pt
);
1603 pImageInfo
->rcImage
.top
= pt
.y
;
1604 pImageInfo
->rcImage
.bottom
= pt
.y
+ himl
->cy
;
1605 pImageInfo
->rcImage
.left
= pt
.x
;
1606 pImageInfo
->rcImage
.right
= pt
.x
+ himl
->cx
;
1612 /*************************************************************************
1613 * ImageList_GetImageRect [COMCTL32.@]
1615 * Retrieves the rectangle of the specified image in an image list.
1618 * himl [I] handle to image list
1620 * lpRect [O] pointer to the image rectangle
1627 * This is an UNDOCUMENTED function!!!
1631 ImageList_GetImageRect (HIMAGELIST himl
, INT i
, LPRECT lpRect
)
1635 if (!is_valid(himl
) || (lpRect
== NULL
))
1637 if ((i
< 0) || (i
>= himl
->cCurImage
))
1640 imagelist_point_from_index( himl
, i
, &pt
);
1641 lpRect
->left
= pt
.x
;
1643 lpRect
->right
= pt
.x
+ himl
->cx
;
1644 lpRect
->bottom
= pt
.y
+ himl
->cy
;
1650 /*************************************************************************
1651 * ImageList_LoadImage [COMCTL32.@]
1652 * ImageList_LoadImageA [COMCTL32.@]
1654 * Creates an image list from a bitmap, icon or cursor.
1656 * See ImageList_LoadImageW.
1660 ImageList_LoadImageA (HINSTANCE hi
, LPCSTR lpbmp
, INT cx
, INT cGrow
,
1661 COLORREF clrMask
, UINT uType
, UINT uFlags
)
1667 if (IS_INTRESOURCE(lpbmp
))
1668 return ImageList_LoadImageW(hi
, (LPCWSTR
)lpbmp
, cx
, cGrow
, clrMask
,
1671 len
= MultiByteToWideChar(CP_ACP
, 0, lpbmp
, -1, NULL
, 0);
1672 lpbmpW
= Alloc(len
* sizeof(WCHAR
));
1673 MultiByteToWideChar(CP_ACP
, 0, lpbmp
, -1, lpbmpW
, len
);
1675 himl
= ImageList_LoadImageW(hi
, lpbmpW
, cx
, cGrow
, clrMask
, uType
, uFlags
);
1681 /*************************************************************************
1682 * ImageList_LoadImageW [COMCTL32.@]
1684 * Creates an image list from a bitmap, icon or cursor.
1687 * hi [I] instance handle
1688 * lpbmp [I] name or id of the image
1689 * cx [I] width of each image
1690 * cGrow [I] number of images to expand
1691 * clrMask [I] mask color
1692 * uType [I] type of image to load
1693 * uFlags [I] loading flags
1696 * Success: handle to the loaded image list
1704 ImageList_LoadImageW (HINSTANCE hi
, LPCWSTR lpbmp
, INT cx
, INT cGrow
,
1705 COLORREF clrMask
, UINT uType
, UINT uFlags
)
1707 HIMAGELIST himl
= NULL
;
1711 handle
= LoadImageW (hi
, lpbmp
, uType
, 0, 0, uFlags
);
1713 WARN("Couldn't load image\n");
1717 if (uType
== IMAGE_BITMAP
) {
1719 GetObjectW (handle
, sizeof(BITMAP
), &bmp
);
1721 /* To match windows behavior, if cx is set to zero and
1722 the flag DI_DEFAULTSIZE is specified, cx becomes the
1723 system metric value for icons. If the flag is not specified
1724 the function sets the size to the height of the bitmap */
1727 if (uFlags
& DI_DEFAULTSIZE
)
1728 cx
= GetSystemMetrics (SM_CXICON
);
1733 nImageCount
= bmp
.bmWidth
/ cx
;
1735 himl
= ImageList_Create (cx
, bmp
.bmHeight
, ILC_MASK
| ILC_COLOR
,
1736 nImageCount
, cGrow
);
1738 DeleteObject (handle
);
1741 ImageList_AddMasked (himl
, handle
, clrMask
);
1743 else if ((uType
== IMAGE_ICON
) || (uType
== IMAGE_CURSOR
)) {
1747 GetIconInfo (handle
, &ii
);
1748 GetObjectW (ii
.hbmColor
, sizeof(BITMAP
), &bmp
);
1749 himl
= ImageList_Create (bmp
.bmWidth
, bmp
.bmHeight
,
1750 ILC_MASK
| ILC_COLOR
, 1, cGrow
);
1752 DeleteObject (ii
.hbmColor
);
1753 DeleteObject (ii
.hbmMask
);
1754 DeleteObject (handle
);
1757 ImageList_Add (himl
, ii
.hbmColor
, ii
.hbmMask
);
1758 DeleteObject (ii
.hbmColor
);
1759 DeleteObject (ii
.hbmMask
);
1762 DeleteObject (handle
);
1768 /*************************************************************************
1769 * ImageList_Merge [COMCTL32.@]
1771 * Create an image list containing a merged image from two image lists.
1774 * himl1 [I] handle to first image list
1775 * i1 [I] first image index
1776 * himl2 [I] handle to second image list
1777 * i2 [I] second image index
1778 * dx [I] X offset of the second image relative to the first.
1779 * dy [I] Y offset of the second image relative to the first.
1782 * Success: The newly created image list. It contains a single image
1783 * consisting of the second image merged with the first.
1784 * Failure: NULL, if either himl1 or himl2 are invalid.
1787 * - The returned image list should be deleted by the caller using
1788 * ImageList_Destroy() when it is no longer required.
1789 * - If either i1 or i2 are not valid image indices they will be treated
1793 ImageList_Merge (HIMAGELIST himl1
, INT i1
, HIMAGELIST himl2
, INT i2
,
1796 HIMAGELIST himlDst
= NULL
;
1798 INT xOff1
, yOff1
, xOff2
, yOff2
;
1801 TRACE("(himl1=%p i1=%d himl2=%p i2=%d dx=%d dy=%d)\n", himl1
, i1
, himl2
,
1804 if (!is_valid(himl1
) || !is_valid(himl2
))
1808 cxDst
= max (himl1
->cx
, dx
+ himl2
->cx
);
1813 cxDst
= max (himl2
->cx
, himl1
->cx
- dx
);
1818 cxDst
= max (himl1
->cx
, himl2
->cx
);
1824 cyDst
= max (himl1
->cy
, dy
+ himl2
->cy
);
1829 cyDst
= max (himl2
->cy
, himl1
->cy
- dy
);
1834 cyDst
= max (himl1
->cy
, himl2
->cy
);
1839 himlDst
= ImageList_Create (cxDst
, cyDst
, ILC_MASK
| ILC_COLOR
, 1, 1);
1843 imagelist_point_from_index( himl1
, i1
, &pt1
);
1844 imagelist_point_from_index( himl1
, i2
, &pt2
);
1847 BitBlt (himlDst
->hdcImage
, 0, 0, cxDst
, cyDst
, himl1
->hdcImage
, 0, 0, BLACKNESS
);
1848 if (i1
>= 0 && i1
< himl1
->cCurImage
)
1849 BitBlt (himlDst
->hdcImage
, xOff1
, yOff1
, himl1
->cx
, himl1
->cy
, himl1
->hdcImage
, pt1
.x
, pt1
.y
, SRCCOPY
);
1850 if (i2
>= 0 && i2
< himl2
->cCurImage
)
1852 BitBlt (himlDst
->hdcImage
, xOff2
, yOff2
, himl2
->cx
, himl2
->cy
, himl2
->hdcMask
, pt2
.x
, pt2
.y
, SRCAND
);
1853 BitBlt (himlDst
->hdcImage
, xOff2
, yOff2
, himl2
->cx
, himl2
->cy
, himl2
->hdcImage
, pt2
.x
, pt2
.y
, SRCPAINT
);
1857 BitBlt (himlDst
->hdcMask
, 0, 0, cxDst
, cyDst
, himl1
->hdcMask
, 0, 0, WHITENESS
);
1858 if (i1
>= 0 && i1
< himl1
->cCurImage
)
1859 BitBlt (himlDst
->hdcMask
, xOff1
, yOff1
, himl1
->cx
, himl1
->cy
, himl1
->hdcMask
, pt1
.x
, pt1
.y
, SRCCOPY
);
1860 if (i2
>= 0 && i2
< himl2
->cCurImage
)
1861 BitBlt (himlDst
->hdcMask
, xOff2
, yOff2
, himl2
->cx
, himl2
->cy
, himl2
->hdcMask
, pt2
.x
, pt2
.y
, SRCAND
);
1863 himlDst
->cCurImage
= 1;
1870 /***********************************************************************
1871 * DIB_GetDIBWidthBytes
1873 * Return the width of a DIB bitmap in bytes. DIB bitmap data is 32-bit aligned.
1875 static int DIB_GetDIBWidthBytes( int width
, int depth
)
1881 case 1: words
= (width
+ 31) / 32; break;
1882 case 4: words
= (width
+ 7) / 8; break;
1883 case 8: words
= (width
+ 3) / 4; break;
1885 case 16: words
= (width
+ 1) / 2; break;
1886 case 24: words
= (width
* 3 + 3)/4; break;
1889 WARN("(%d): Unsupported depth\n", depth
);
1898 /***********************************************************************
1899 * DIB_GetDIBImageBytes
1901 * Return the number of bytes used to hold the image in a DIB bitmap.
1903 static int DIB_GetDIBImageBytes( int width
, int height
, int depth
)
1905 return DIB_GetDIBWidthBytes( width
, depth
) * abs( height
);
1909 /* helper for ImageList_Read, see comments below */
1910 static BOOL
_read_bitmap(HDC hdcIml
, LPSTREAM pstm
)
1912 BITMAPFILEHEADER bmfh
;
1913 int bitsperpixel
, palspace
;
1914 char bmi_buf
[sizeof(BITMAPINFOHEADER
) + sizeof(RGBQUAD
) * 256];
1915 LPBITMAPINFO bmi
= (LPBITMAPINFO
)bmi_buf
;
1919 if (FAILED(IStream_Read ( pstm
, &bmfh
, sizeof(bmfh
), NULL
)))
1922 if (bmfh
.bfType
!= (('M'<<8)|'B'))
1925 if (FAILED(IStream_Read ( pstm
, &bmi
->bmiHeader
, sizeof(bmi
->bmiHeader
), NULL
)))
1928 if ((bmi
->bmiHeader
.biSize
!= sizeof(bmi
->bmiHeader
)))
1931 TRACE("width %u, height %u, planes %u, bpp %u\n",
1932 bmi
->bmiHeader
.biWidth
, bmi
->bmiHeader
.biHeight
,
1933 bmi
->bmiHeader
.biPlanes
, bmi
->bmiHeader
.biBitCount
);
1935 bitsperpixel
= bmi
->bmiHeader
.biPlanes
* bmi
->bmiHeader
.biBitCount
;
1936 if (bitsperpixel
<=8)
1937 palspace
= (1<<bitsperpixel
)*sizeof(RGBQUAD
);
1941 bmi
->bmiHeader
.biSizeImage
= DIB_GetDIBImageBytes(bmi
->bmiHeader
.biWidth
, bmi
->bmiHeader
.biHeight
, bitsperpixel
);
1943 /* read the palette right after the end of the bitmapinfoheader */
1944 if (palspace
&& FAILED(IStream_Read(pstm
, bmi
->bmiColors
, palspace
, NULL
)))
1947 bits
= Alloc(bmi
->bmiHeader
.biSizeImage
);
1950 if (FAILED(IStream_Read(pstm
, bits
, bmi
->bmiHeader
.biSizeImage
, NULL
)))
1953 if (!StretchDIBits(hdcIml
, 0, 0, bmi
->bmiHeader
.biWidth
, bmi
->bmiHeader
.biHeight
,
1954 0, 0, bmi
->bmiHeader
.biWidth
, bmi
->bmiHeader
.biHeight
,
1955 bits
, bmi
, DIB_RGB_COLORS
, SRCCOPY
))
1964 /*************************************************************************
1965 * ImageList_Read [COMCTL32.@]
1967 * Reads an image list from a stream.
1970 * pstm [I] pointer to a stream
1973 * Success: handle to image list
1976 * The format is like this:
1977 * ILHEAD ilheadstruct;
1979 * for the color image part:
1980 * BITMAPFILEHEADER bmfh;
1981 * BITMAPINFOHEADER bmih;
1982 * only if it has a palette:
1983 * RGBQUAD rgbs[nr_of_paletted_colors];
1985 * BYTE colorbits[imagesize];
1987 * the following only if the ILC_MASK bit is set in ILHEAD.ilFlags:
1988 * BITMAPFILEHEADER bmfh_mask;
1989 * BITMAPINFOHEADER bmih_mask;
1990 * only if it has a palette (it usually does not):
1991 * RGBQUAD rgbs[nr_of_paletted_colors];
1993 * BYTE maskbits[imagesize];
1995 HIMAGELIST WINAPI
ImageList_Read (LPSTREAM pstm
)
2001 TRACE("%p\n", pstm
);
2003 if (FAILED(IStream_Read (pstm
, &ilHead
, sizeof(ILHEAD
), NULL
)))
2005 if (ilHead
.usMagic
!= (('L' << 8) | 'I'))
2007 if (ilHead
.usVersion
!= 0x101) /* probably version? */
2010 TRACE("cx %u, cy %u, flags 0x%04x, cCurImage %u, cMaxImage %u\n",
2011 ilHead
.cx
, ilHead
.cy
, ilHead
.flags
, ilHead
.cCurImage
, ilHead
.cMaxImage
);
2013 himl
= ImageList_Create(ilHead
.cx
, ilHead
.cy
, ilHead
.flags
, ilHead
.cCurImage
, ilHead
.cMaxImage
);
2017 if (!_read_bitmap(himl
->hdcImage
, pstm
))
2019 WARN("failed to read bitmap from stream\n");
2022 if (ilHead
.flags
& ILC_MASK
)
2024 if (!_read_bitmap(himl
->hdcMask
, pstm
))
2026 WARN("failed to read mask bitmap from stream\n");
2031 himl
->cCurImage
= ilHead
.cCurImage
;
2032 himl
->cMaxImage
= ilHead
.cMaxImage
;
2034 ImageList_SetBkColor(himl
,ilHead
.bkcolor
);
2036 ImageList_SetOverlayImage(himl
,ilHead
.ovls
[i
],i
+1);
2041 /*************************************************************************
2042 * ImageList_Remove [COMCTL32.@]
2044 * Removes an image from an image list
2047 * himl [I] image list handle
2054 * FIXME: as the image list storage test shows, native comctl32 simply shifts
2055 * images without creating a new bitmap.
2058 ImageList_Remove (HIMAGELIST himl
, INT i
)
2060 HBITMAP hbmNewImage
, hbmNewMask
;
2064 TRACE("(himl=%p i=%d)\n", himl
, i
);
2066 if (!is_valid(himl
)) {
2067 ERR("Invalid image list handle!\n");
2071 if ((i
< -1) || (i
>= himl
->cCurImage
)) {
2072 TRACE("index out of range! %d\n", i
);
2080 if (himl
->cCurImage
== 0) {
2081 /* remove all on empty ImageList is allowed */
2082 TRACE("remove all on empty ImageList!\n");
2086 himl
->cMaxImage
= himl
->cInitial
+ himl
->cGrow
- 1;
2087 himl
->cCurImage
= 0;
2088 for (nCount
= 0; nCount
< MAX_OVERLAYIMAGE
; nCount
++)
2089 himl
->nOvlIdx
[nCount
] = -1;
2091 hbmNewImage
= ImageList_CreateImage(himl
->hdcImage
, himl
, himl
->cMaxImage
);
2092 SelectObject (himl
->hdcImage
, hbmNewImage
);
2093 DeleteObject (himl
->hbmImage
);
2094 himl
->hbmImage
= hbmNewImage
;
2096 if (himl
->hbmMask
) {
2098 imagelist_get_bitmap_size(himl
, himl
->cMaxImage
, &sz
);
2099 hbmNewMask
= CreateBitmap (sz
.cx
, sz
.cy
, 1, 1, NULL
);
2100 SelectObject (himl
->hdcMask
, hbmNewMask
);
2101 DeleteObject (himl
->hbmMask
);
2102 himl
->hbmMask
= hbmNewMask
;
2106 /* delete one image */
2107 TRACE("Remove single image! %d\n", i
);
2109 /* create new bitmap(s) */
2110 TRACE(" - Number of images: %d / %d (Old/New)\n",
2111 himl
->cCurImage
, himl
->cCurImage
- 1);
2113 hbmNewImage
= ImageList_CreateImage(himl
->hdcImage
, himl
, himl
->cMaxImage
);
2115 imagelist_get_bitmap_size(himl
, himl
->cMaxImage
, &sz
);
2117 hbmNewMask
= CreateBitmap (sz
.cx
, sz
.cy
, 1, 1, NULL
);
2119 hbmNewMask
= 0; /* Just to keep compiler happy! */
2121 hdcBmp
= CreateCompatibleDC (0);
2123 /* copy all images and masks prior to the "removed" image */
2125 TRACE("Pre image copy: Copy %d images\n", i
);
2127 SelectObject (hdcBmp
, hbmNewImage
);
2128 imagelist_copy_images( himl
, himl
->hdcImage
, hdcBmp
, 0, i
, 0 );
2130 if (himl
->hbmMask
) {
2131 SelectObject (hdcBmp
, hbmNewMask
);
2132 imagelist_copy_images( himl
, himl
->hdcMask
, hdcBmp
, 0, i
, 0 );
2136 /* copy all images and masks behind the removed image */
2137 if (i
< himl
->cCurImage
- 1) {
2138 TRACE("Post image copy!\n");
2140 SelectObject (hdcBmp
, hbmNewImage
);
2141 imagelist_copy_images( himl
, himl
->hdcImage
, hdcBmp
, i
+ 1,
2142 (himl
->cCurImage
- i
), i
);
2144 if (himl
->hbmMask
) {
2145 SelectObject (hdcBmp
, hbmNewMask
);
2146 imagelist_copy_images( himl
, himl
->hdcMask
, hdcBmp
, i
+ 1,
2147 (himl
->cCurImage
- i
), i
);
2153 /* delete old images and insert new ones */
2154 SelectObject (himl
->hdcImage
, hbmNewImage
);
2155 DeleteObject (himl
->hbmImage
);
2156 himl
->hbmImage
= hbmNewImage
;
2157 if (himl
->hbmMask
) {
2158 SelectObject (himl
->hdcMask
, hbmNewMask
);
2159 DeleteObject (himl
->hbmMask
);
2160 himl
->hbmMask
= hbmNewMask
;
2170 /*************************************************************************
2171 * ImageList_Replace [COMCTL32.@]
2173 * Replaces an image in an image list with a new image.
2176 * himl [I] handle to image list
2178 * hbmImage [I] handle to image bitmap
2179 * hbmMask [I] handle to mask bitmap. Can be NULL.
2187 ImageList_Replace (HIMAGELIST himl
, INT i
, HBITMAP hbmImage
,
2195 TRACE("%p %d %p %p\n", himl
, i
, hbmImage
, hbmMask
);
2197 if (!is_valid(himl
)) {
2198 ERR("Invalid image list handle!\n");
2202 if ((i
>= himl
->cMaxImage
) || (i
< 0)) {
2203 ERR("Invalid image index!\n");
2207 if (!GetObjectW(hbmImage
, sizeof(BITMAP
), &bmp
))
2210 hdcImage
= CreateCompatibleDC (0);
2213 hOldBitmap
= SelectObject (hdcImage
, hbmImage
);
2215 imagelist_point_from_index(himl
, i
, &pt
);
2216 StretchBlt (himl
->hdcImage
, pt
.x
, pt
.y
, himl
->cx
, himl
->cy
,
2217 hdcImage
, 0, 0, bmp
.bmWidth
, bmp
.bmHeight
, SRCCOPY
);
2222 HBITMAP hOldBitmapTemp
;
2224 hdcTemp
= CreateCompatibleDC(0);
2225 hOldBitmapTemp
= SelectObject(hdcTemp
, hbmMask
);
2227 StretchBlt (himl
->hdcMask
, pt
.x
, pt
.y
, himl
->cx
, himl
->cy
,
2228 hdcTemp
, 0, 0, bmp
.bmWidth
, bmp
.bmHeight
, SRCCOPY
);
2229 SelectObject(hdcTemp
, hOldBitmapTemp
);
2232 /* Remove the background from the image
2234 BitBlt (himl
->hdcImage
, pt
.x
, pt
.y
, bmp
.bmWidth
, bmp
.bmHeight
,
2235 himl
->hdcMask
, pt
.x
, pt
.y
, 0x220326); /* NOTSRCAND */
2238 SelectObject (hdcImage
, hOldBitmap
);
2239 DeleteDC (hdcImage
);
2245 /*************************************************************************
2246 * ImageList_ReplaceIcon [COMCTL32.@]
2248 * Replaces an image in an image list using an icon.
2251 * himl [I] handle to image list
2253 * hIcon [I] handle to icon
2256 * Success: index of the replaced image
2261 ImageList_ReplaceIcon (HIMAGELIST himl
, INT nIndex
, HICON hIcon
)
2271 TRACE("(%p %d %p)\n", himl
, nIndex
, hIcon
);
2273 if (!is_valid(himl
)) {
2274 ERR("invalid image list\n");
2277 if ((nIndex
>= himl
->cMaxImage
) || (nIndex
< -1)) {
2278 ERR("invalid image index %d / %d\n", nIndex
, himl
->cMaxImage
);
2282 hBestFitIcon
= CopyImage(
2285 LR_COPYFROMRESOURCE
);
2286 /* the above will fail if the icon wasn't loaded from a resource, so try
2287 * again without LR_COPYFROMRESOURCE flag */
2289 hBestFitIcon
= CopyImage(
2296 ret
= GetIconInfo (hBestFitIcon
, &ii
);
2298 DestroyIcon(hBestFitIcon
);
2302 ret
= GetObjectW (ii
.hbmMask
, sizeof(BITMAP
), &bmp
);
2304 ERR("couldn't get mask bitmap info\n");
2306 DeleteObject (ii
.hbmColor
);
2308 DeleteObject (ii
.hbmMask
);
2309 DestroyIcon(hBestFitIcon
);
2314 if (himl
->cCurImage
+ 1 > himl
->cMaxImage
)
2315 IMAGELIST_InternalExpandBitmaps(himl
, 1);
2317 nIndex
= himl
->cCurImage
;
2321 hdcImage
= CreateCompatibleDC (0);
2322 TRACE("hdcImage=%p\n", hdcImage
);
2324 ERR("invalid hdcImage!\n");
2326 imagelist_point_from_index(himl
, nIndex
, &pt
);
2328 SetTextColor(himl
->hdcImage
, RGB(0,0,0));
2329 SetBkColor (himl
->hdcImage
, RGB(255,255,255));
2333 hbmOldSrc
= SelectObject (hdcImage
, ii
.hbmColor
);
2334 StretchBlt (himl
->hdcImage
, pt
.x
, pt
.y
, himl
->cx
, himl
->cy
,
2335 hdcImage
, 0, 0, bmp
.bmWidth
, bmp
.bmHeight
, SRCCOPY
);
2338 SelectObject (hdcImage
, ii
.hbmMask
);
2339 StretchBlt (himl
->hdcMask
, pt
.x
, pt
.y
, himl
->cx
, himl
->cy
,
2340 hdcImage
, 0, 0, bmp
.bmWidth
, bmp
.bmHeight
, SRCCOPY
);
2345 UINT height
= bmp
.bmHeight
/ 2;
2346 hbmOldSrc
= SelectObject (hdcImage
, ii
.hbmMask
);
2347 StretchBlt (himl
->hdcImage
, pt
.x
, pt
.y
, himl
->cx
, himl
->cy
,
2348 hdcImage
, 0, height
, bmp
.bmWidth
, height
, SRCCOPY
);
2350 StretchBlt (himl
->hdcMask
, pt
.x
, pt
.y
, himl
->cx
, himl
->cy
,
2351 hdcImage
, 0, 0, bmp
.bmWidth
, height
, SRCCOPY
);
2354 SelectObject (hdcImage
, hbmOldSrc
);
2356 DestroyIcon(hBestFitIcon
);
2358 DeleteDC (hdcImage
);
2360 DeleteObject (ii
.hbmColor
);
2362 DeleteObject (ii
.hbmMask
);
2364 TRACE("Insert index = %d, himl->cCurImage = %d\n", nIndex
, himl
->cCurImage
);
2369 /*************************************************************************
2370 * ImageList_SetBkColor [COMCTL32.@]
2372 * Sets the background color of an image list.
2375 * himl [I] handle to image list
2376 * clrBk [I] background color
2379 * Success: previous background color
2384 ImageList_SetBkColor (HIMAGELIST himl
, COLORREF clrBk
)
2388 if (!is_valid(himl
))
2391 clrOldBk
= himl
->clrBk
;
2392 himl
->clrBk
= clrBk
;
2397 /*************************************************************************
2398 * ImageList_SetDragCursorImage [COMCTL32.@]
2400 * Combines the specified image with the current drag image
2403 * himlDrag [I] handle to drag image list
2404 * iDrag [I] drag image index
2405 * dxHotspot [I] X position of the hot spot
2406 * dyHotspot [I] Y position of the hot spot
2413 * - The names dxHotspot, dyHotspot are misleading because they have nothing
2414 * to do with a hotspot but are only the offset of the origin of the new
2415 * image relative to the origin of the old image.
2417 * - When this function is called and the drag image is visible, a
2418 * short flickering occurs but this matches the Win9x behavior. It is
2419 * possible to fix the flickering using code like in ImageList_DragMove.
2423 ImageList_SetDragCursorImage (HIMAGELIST himlDrag
, INT iDrag
,
2424 INT dxHotspot
, INT dyHotspot
)
2426 HIMAGELIST himlTemp
;
2429 if (!is_valid(InternalDrag
.himl
) || !is_valid(himlDrag
))
2432 TRACE(" dxH=%d dyH=%d nX=%d nY=%d\n",
2433 dxHotspot
, dyHotspot
, InternalDrag
.dxHotspot
, InternalDrag
.dyHotspot
);
2435 visible
= InternalDrag
.bShow
;
2437 himlTemp
= ImageList_Merge (InternalDrag
.himl
, 0, himlDrag
, iDrag
,
2438 dxHotspot
, dyHotspot
);
2441 /* hide the drag image */
2442 ImageList_DragShowNolock(FALSE
);
2444 if ((InternalDrag
.himl
->cx
!= himlTemp
->cx
) ||
2445 (InternalDrag
.himl
->cy
!= himlTemp
->cy
)) {
2446 /* the size of the drag image changed, invalidate the buffer */
2447 DeleteObject(InternalDrag
.hbmBg
);
2448 InternalDrag
.hbmBg
= 0;
2451 ImageList_Destroy (InternalDrag
.himl
);
2452 InternalDrag
.himl
= himlTemp
;
2455 /* show the drag image */
2456 ImageList_DragShowNolock(TRUE
);
2463 /*************************************************************************
2464 * ImageList_SetFilter [COMCTL32.@]
2466 * Sets a filter (or does something completely different)!!???
2467 * It removes 12 Bytes from the stack (3 Parameters).
2470 * himl [I] SHOULD be a handle to image list
2471 * i [I] COULD be an index?
2476 * Failure: FALSE ???
2479 * This is an UNDOCUMENTED function!!!!
2484 ImageList_SetFilter (HIMAGELIST himl
, INT i
, DWORD dwFilter
)
2486 FIXME("(%p 0x%x 0x%x):empty stub!\n", himl
, i
, dwFilter
);
2492 /*************************************************************************
2493 * ImageList_SetFlags [COMCTL32.@]
2495 * Sets the image list flags.
2498 * himl [I] Handle to image list
2499 * flags [I] Flags to set
2509 ImageList_SetFlags(HIMAGELIST himl
, DWORD flags
)
2511 FIXME("(%p %08x):empty stub\n", himl
, flags
);
2516 /*************************************************************************
2517 * ImageList_SetIconSize [COMCTL32.@]
2519 * Sets the image size of the bitmap and deletes all images.
2522 * himl [I] handle to image list
2523 * cx [I] image width
2524 * cy [I] image height
2532 ImageList_SetIconSize (HIMAGELIST himl
, INT cx
, INT cy
)
2537 if (!is_valid(himl
))
2540 /* remove all images */
2541 himl
->cMaxImage
= himl
->cInitial
+ 1;
2542 himl
->cCurImage
= 0;
2546 /* initialize overlay mask indices */
2547 for (nCount
= 0; nCount
< MAX_OVERLAYIMAGE
; nCount
++)
2548 himl
->nOvlIdx
[nCount
] = -1;
2550 hbmNew
= ImageList_CreateImage(himl
->hdcImage
, himl
, himl
->cMaxImage
);
2551 SelectObject (himl
->hdcImage
, hbmNew
);
2552 DeleteObject (himl
->hbmImage
);
2553 himl
->hbmImage
= hbmNew
;
2555 if (himl
->hbmMask
) {
2557 imagelist_get_bitmap_size(himl
, himl
->cMaxImage
, &sz
);
2558 hbmNew
= CreateBitmap (sz
.cx
, sz
.cy
, 1, 1, NULL
);
2559 SelectObject (himl
->hdcMask
, hbmNew
);
2560 DeleteObject (himl
->hbmMask
);
2561 himl
->hbmMask
= hbmNew
;
2568 /*************************************************************************
2569 * ImageList_SetImageCount [COMCTL32.@]
2571 * Resizes an image list to the specified number of images.
2574 * himl [I] handle to image list
2575 * iImageCount [I] number of images in the image list
2583 ImageList_SetImageCount (HIMAGELIST himl
, UINT iImageCount
)
2586 HBITMAP hbmNewBitmap
, hbmOld
;
2587 INT nNewCount
, nCopyCount
;
2589 TRACE("%p %d\n",himl
,iImageCount
);
2591 if (!is_valid(himl
))
2593 if (himl
->cMaxImage
> iImageCount
)
2595 himl
->cCurImage
= iImageCount
;
2596 /* TODO: shrink the bitmap when cMaxImage-cCurImage>cGrow ? */
2600 nNewCount
= iImageCount
+ himl
->cGrow
;
2601 nCopyCount
= min(himl
->cCurImage
, iImageCount
);
2603 hdcBitmap
= CreateCompatibleDC (0);
2605 hbmNewBitmap
= ImageList_CreateImage(hdcBitmap
, himl
, nNewCount
);
2607 if (hbmNewBitmap
!= 0)
2609 hbmOld
= SelectObject (hdcBitmap
, hbmNewBitmap
);
2610 imagelist_copy_images( himl
, himl
->hdcImage
, hdcBitmap
, 0, nCopyCount
, 0 );
2611 SelectObject (hdcBitmap
, hbmOld
);
2613 /* FIXME: delete 'empty' image space? */
2615 SelectObject (himl
->hdcImage
, hbmNewBitmap
);
2616 DeleteObject (himl
->hbmImage
);
2617 himl
->hbmImage
= hbmNewBitmap
;
2620 ERR("Could not create new image bitmap !\n");
2625 imagelist_get_bitmap_size( himl
, nNewCount
, &sz
);
2626 hbmNewBitmap
= CreateBitmap (sz
.cx
, sz
.cy
, 1, 1, NULL
);
2627 if (hbmNewBitmap
!= 0)
2629 hbmOld
= SelectObject (hdcBitmap
, hbmNewBitmap
);
2630 imagelist_copy_images( himl
, himl
->hdcMask
, hdcBitmap
, 0, nCopyCount
, 0 );
2631 SelectObject (hdcBitmap
, hbmOld
);
2633 /* FIXME: delete 'empty' image space? */
2635 SelectObject (himl
->hdcMask
, hbmNewBitmap
);
2636 DeleteObject (himl
->hbmMask
);
2637 himl
->hbmMask
= hbmNewBitmap
;
2640 ERR("Could not create new mask bitmap!\n");
2643 DeleteDC (hdcBitmap
);
2645 /* Update max image count and current image count */
2646 himl
->cMaxImage
= nNewCount
;
2647 himl
->cCurImage
= iImageCount
;
2653 /*************************************************************************
2654 * ImageList_SetOverlayImage [COMCTL32.@]
2656 * Assigns an overlay mask index to an existing image in an image list.
2659 * himl [I] handle to image list
2660 * iImage [I] image index
2661 * iOverlay [I] overlay mask index
2669 ImageList_SetOverlayImage (HIMAGELIST himl
, INT iImage
, INT iOverlay
)
2671 if (!is_valid(himl
))
2673 if ((iOverlay
< 1) || (iOverlay
> MAX_OVERLAYIMAGE
))
2675 if ((iImage
!=-1) && ((iImage
< 0) || (iImage
> himl
->cCurImage
)))
2677 himl
->nOvlIdx
[iOverlay
- 1] = iImage
;
2683 /* helper for ImageList_Write - write bitmap to pstm
2684 * currently everything is written as 24 bit RGB, except masks
2687 _write_bitmap(HBITMAP hBitmap
, LPSTREAM pstm
)
2689 LPBITMAPFILEHEADER bmfh
;
2690 LPBITMAPINFOHEADER bmih
;
2691 LPBYTE data
= NULL
, lpBits
;
2693 INT bitCount
, sizeImage
, offBits
, totalSize
;
2695 BOOL result
= FALSE
;
2697 if (!GetObjectW(hBitmap
, sizeof(BITMAP
), &bm
))
2700 bitCount
= bm
.bmBitsPixel
== 1 ? 1 : 24;
2701 sizeImage
= DIB_GetDIBImageBytes(bm
.bmWidth
, bm
.bmHeight
, bitCount
);
2703 totalSize
= sizeof(BITMAPFILEHEADER
) + sizeof(BITMAPINFOHEADER
);
2705 totalSize
+= (1 << bitCount
) * sizeof(RGBQUAD
);
2706 offBits
= totalSize
;
2707 totalSize
+= sizeImage
;
2709 data
= Alloc(totalSize
);
2710 bmfh
= (LPBITMAPFILEHEADER
)data
;
2711 bmih
= (LPBITMAPINFOHEADER
)(data
+ sizeof(BITMAPFILEHEADER
));
2712 lpBits
= data
+ offBits
;
2714 /* setup BITMAPFILEHEADER */
2715 bmfh
->bfType
= (('M' << 8) | 'B');
2716 bmfh
->bfSize
= offBits
;
2717 bmfh
->bfReserved1
= 0;
2718 bmfh
->bfReserved2
= 0;
2719 bmfh
->bfOffBits
= offBits
;
2721 /* setup BITMAPINFOHEADER */
2722 bmih
->biSize
= sizeof(BITMAPINFOHEADER
);
2723 bmih
->biWidth
= bm
.bmWidth
;
2724 bmih
->biHeight
= bm
.bmHeight
;
2726 bmih
->biBitCount
= bitCount
;
2727 bmih
->biCompression
= BI_RGB
;
2728 bmih
->biSizeImage
= sizeImage
;
2729 bmih
->biXPelsPerMeter
= 0;
2730 bmih
->biYPelsPerMeter
= 0;
2731 bmih
->biClrUsed
= 0;
2732 bmih
->biClrImportant
= 0;
2735 result
= GetDIBits(xdc
, hBitmap
, 0, bm
.bmHeight
, lpBits
, (BITMAPINFO
*)bmih
, DIB_RGB_COLORS
) == bm
.bmHeight
;
2740 TRACE("width %u, height %u, planes %u, bpp %u\n",
2741 bmih
->biWidth
, bmih
->biHeight
,
2742 bmih
->biPlanes
, bmih
->biBitCount
);
2746 LPBITMAPINFO inf
= (LPBITMAPINFO
)bmih
;
2747 inf
->bmiColors
[0].rgbRed
= inf
->bmiColors
[0].rgbGreen
= inf
->bmiColors
[0].rgbBlue
= 0;
2748 inf
->bmiColors
[1].rgbRed
= inf
->bmiColors
[1].rgbGreen
= inf
->bmiColors
[1].rgbBlue
= 0xff;
2751 if(FAILED(IStream_Write(pstm
, data
, totalSize
, NULL
)))
2763 /*************************************************************************
2764 * ImageList_Write [COMCTL32.@]
2766 * Writes an image list to a stream.
2769 * himl [I] handle to image list
2770 * pstm [O] Pointer to a stream.
2781 ImageList_Write (HIMAGELIST himl
, LPSTREAM pstm
)
2786 TRACE("%p %p\n", himl
, pstm
);
2788 if (!is_valid(himl
))
2791 ilHead
.usMagic
= (('L' << 8) | 'I');
2792 ilHead
.usVersion
= 0x101;
2793 ilHead
.cCurImage
= himl
->cCurImage
;
2794 ilHead
.cMaxImage
= himl
->cMaxImage
;
2795 ilHead
.cGrow
= himl
->cGrow
;
2796 ilHead
.cx
= himl
->cx
;
2797 ilHead
.cy
= himl
->cy
;
2798 ilHead
.bkcolor
= himl
->clrBk
;
2799 ilHead
.flags
= himl
->flags
;
2800 for(i
= 0; i
< 4; i
++) {
2801 ilHead
.ovls
[i
] = himl
->nOvlIdx
[i
];
2804 TRACE("cx %u, cy %u, flags 0x04%x, cCurImage %u, cMaxImage %u\n",
2805 ilHead
.cx
, ilHead
.cy
, ilHead
.flags
, ilHead
.cCurImage
, ilHead
.cMaxImage
);
2807 if(FAILED(IStream_Write(pstm
, &ilHead
, sizeof(ILHEAD
), NULL
)))
2810 /* write the bitmap */
2811 if(!_write_bitmap(himl
->hbmImage
, pstm
))
2814 /* write the mask if we have one */
2815 if(himl
->flags
& ILC_MASK
) {
2816 if(!_write_bitmap(himl
->hbmMask
, pstm
))
2824 static HBITMAP
ImageList_CreateImage(HDC hdc
, HIMAGELIST himl
, UINT count
)
2826 HBITMAP hbmNewBitmap
;
2827 UINT ilc
= (himl
->flags
& 0xFE);
2830 imagelist_get_bitmap_size( himl
, count
, &sz
);
2832 if ((ilc
>= ILC_COLOR4
&& ilc
<= ILC_COLOR32
) || ilc
== ILC_COLOR
)
2837 TRACE("Creating DIBSection %d x %d, %d Bits per Pixel\n",
2838 sz
.cx
, sz
.cy
, himl
->uBitsPixel
);
2840 if (himl
->uBitsPixel
<= ILC_COLOR8
)
2846 colors
= 1 << himl
->uBitsPixel
;
2847 bmi
= Alloc(sizeof(BITMAPINFOHEADER
) +
2848 sizeof(PALETTEENTRY
) * colors
);
2850 pal
= (LPPALETTEENTRY
)bmi
->bmiColors
;
2851 GetPaletteEntries(GetStockObject(DEFAULT_PALETTE
), 0, colors
, pal
);
2853 /* Swap colors returned by GetPaletteEntries so we can use them for
2854 * CreateDIBSection call. */
2855 for (i
= 0; i
< colors
; i
++)
2857 temp
= pal
[i
].peBlue
;
2858 bmi
->bmiColors
[i
].rgbRed
= pal
[i
].peRed
;
2859 bmi
->bmiColors
[i
].rgbBlue
= temp
;
2864 bmi
= Alloc(sizeof(BITMAPINFOHEADER
));
2867 bmi
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
2868 bmi
->bmiHeader
.biWidth
= sz
.cx
;
2869 bmi
->bmiHeader
.biHeight
= sz
.cy
;
2870 bmi
->bmiHeader
.biPlanes
= 1;
2871 bmi
->bmiHeader
.biBitCount
= himl
->uBitsPixel
;
2872 bmi
->bmiHeader
.biCompression
= BI_RGB
;
2873 bmi
->bmiHeader
.biSizeImage
= 0;
2874 bmi
->bmiHeader
.biXPelsPerMeter
= 0;
2875 bmi
->bmiHeader
.biYPelsPerMeter
= 0;
2876 bmi
->bmiHeader
.biClrUsed
= 0;
2877 bmi
->bmiHeader
.biClrImportant
= 0;
2879 hbmNewBitmap
= CreateDIBSection(hdc
, bmi
, DIB_RGB_COLORS
, &bits
, 0, 0);
2883 else /*if (ilc == ILC_COLORDDB)*/
2885 TRACE("Creating Bitmap: %d Bits per Pixel\n", himl
->uBitsPixel
);
2887 hbmNewBitmap
= CreateBitmap (sz
.cx
, sz
.cy
, 1, himl
->uBitsPixel
, NULL
);
2889 TRACE("returning %p\n", hbmNewBitmap
);
2890 return hbmNewBitmap
;
2893 /*************************************************************************
2894 * ImageList_SetColorTable [COMCTL32.@]
2896 * Sets the color table of an image list.
2899 * himl [I] Handle to the image list.
2900 * uStartIndex [I] The first index to set.
2901 * cEntries [I] Number of entries to set.
2902 * prgb [I] New color information for color table for the image list.
2905 * Success: Number of entries in the table that were set.
2909 * ImageList_Create(), SetDIBColorTable()
2913 ImageList_SetColorTable (HIMAGELIST himl
, UINT uStartIndex
, UINT cEntries
, CONST RGBQUAD
* prgb
)
2915 return SetDIBColorTable(himl
->hdcImage
, uStartIndex
, cEntries
, prgb
);
2918 /*************************************************************************
2919 * ImageList_CoCreateInstance [COMCTL32.@]
2921 * Creates a new imagelist instance and returns an interface pointer to it.
2924 * rclsid [I] A reference to the CLSID (CLSID_ImageList).
2925 * punkOuter [I] Pointer to IUnknown interface for aggregation, if desired
2926 * riid [I] Identifier of the requested interface.
2927 * ppv [O] Returns the address of the pointer requested, or NULL.
2931 * Failure: Error value.
2934 ImageList_CoCreateInstance (REFCLSID rclsid
, const IUnknown
*punkOuter
, REFIID riid
, void **ppv
)
2936 TRACE("(%s,%p,%s,%p)\n", debugstr_guid(rclsid
), punkOuter
, debugstr_guid(riid
), ppv
);
2938 if (!IsEqualCLSID(&CLSID_ImageList
, rclsid
))
2939 return E_NOINTERFACE
;
2941 return ImageListImpl_CreateInstance(punkOuter
, riid
, ppv
);
2945 /*************************************************************************
2946 * IImageList implementation
2949 static HRESULT WINAPI
ImageListImpl_QueryInterface(IImageList
*iface
,
2950 REFIID iid
, void **ppv
)
2952 HIMAGELIST This
= (HIMAGELIST
) iface
;
2953 TRACE("(%p,%s,%p)\n", iface
, debugstr_guid(iid
), ppv
);
2955 if (!ppv
) return E_INVALIDARG
;
2957 if (IsEqualIID(&IID_IUnknown
, iid
) || IsEqualIID(&IID_IImageList
, iid
))
2962 return E_NOINTERFACE
;
2965 IUnknown_AddRef((IUnknown
*)*ppv
);
2969 static ULONG WINAPI
ImageListImpl_AddRef(IImageList
*iface
)
2971 HIMAGELIST This
= (HIMAGELIST
) iface
;
2972 ULONG ref
= InterlockedIncrement(&This
->ref
);
2974 TRACE("(%p) refcount=%u\n", iface
, ref
);
2978 static ULONG WINAPI
ImageListImpl_Release(IImageList
*iface
)
2980 HIMAGELIST This
= (HIMAGELIST
) iface
;
2981 ULONG ref
= InterlockedDecrement(&This
->ref
);
2983 TRACE("(%p) refcount=%u\n", iface
, ref
);
2987 /* delete image bitmaps */
2988 if (This
->hbmImage
) DeleteObject (This
->hbmImage
);
2989 if (This
->hbmMask
) DeleteObject (This
->hbmMask
);
2991 /* delete image & mask DCs */
2992 if (This
->hdcImage
) DeleteDC (This
->hdcImage
);
2993 if (This
->hdcMask
) DeleteDC (This
->hdcMask
);
2995 /* delete blending brushes */
2996 if (This
->hbrBlend25
) DeleteObject (This
->hbrBlend25
);
2997 if (This
->hbrBlend50
) DeleteObject (This
->hbrBlend50
);
2999 This
->lpVtbl
= NULL
;
3000 HeapFree(GetProcessHeap(), 0, This
);
3006 static HRESULT WINAPI
ImageListImpl_Add(IImageList
*iface
, HBITMAP hbmImage
,
3007 HBITMAP hbmMask
, int *pi
)
3009 HIMAGELIST This
= (HIMAGELIST
) iface
;
3015 ret
= ImageList_Add(This
, hbmImage
, hbmMask
);
3024 static HRESULT WINAPI
ImageListImpl_ReplaceIcon(IImageList
*iface
, int i
,
3025 HICON hicon
, int *pi
)
3027 HIMAGELIST This
= (HIMAGELIST
) iface
;
3033 ret
= ImageList_ReplaceIcon(This
, i
, hicon
);
3042 static HRESULT WINAPI
ImageListImpl_SetOverlayImage(IImageList
*iface
,
3043 int iImage
, int iOverlay
)
3045 return ImageList_SetOverlayImage((HIMAGELIST
) iface
, iImage
, iOverlay
)
3049 static HRESULT WINAPI
ImageListImpl_Replace(IImageList
*iface
, int i
,
3050 HBITMAP hbmImage
, HBITMAP hbmMask
)
3052 return ImageList_Replace((HIMAGELIST
) iface
, i
, hbmImage
, hbmMask
) ? S_OK
:
3056 static HRESULT WINAPI
ImageListImpl_AddMasked(IImageList
*iface
, HBITMAP hbmImage
,
3057 COLORREF crMask
, int *pi
)
3059 HIMAGELIST This
= (HIMAGELIST
) iface
;
3065 ret
= ImageList_AddMasked(This
, hbmImage
, crMask
);
3074 static HRESULT WINAPI
ImageListImpl_Draw(IImageList
*iface
,
3075 IMAGELISTDRAWPARAMS
*pimldp
)
3077 HIMAGELIST This
= (HIMAGELIST
) iface
;
3078 HIMAGELIST old_himl
= 0;
3084 /* As far as I can tell, Windows simply ignores the contents of pimldp->himl
3085 so we shall simulate the same */
3086 old_himl
= pimldp
->himl
;
3087 pimldp
->himl
= This
;
3089 ret
= ImageList_DrawIndirect(pimldp
);
3091 pimldp
->himl
= old_himl
;
3092 return ret
? S_OK
: E_FAIL
;
3095 static HRESULT WINAPI
ImageListImpl_Remove(IImageList
*iface
, int i
)
3097 return (ImageList_Remove((HIMAGELIST
) iface
, i
) == 0) ? E_FAIL
: S_OK
;
3100 static HRESULT WINAPI
ImageListImpl_GetIcon(IImageList
*iface
, int i
, UINT flags
,
3108 hIcon
= ImageList_GetIcon((HIMAGELIST
) iface
, i
, flags
);
3117 static HRESULT WINAPI
ImageListImpl_GetImageInfo(IImageList
*iface
, int i
,
3118 IMAGEINFO
*pImageInfo
)
3120 return ImageList_GetImageInfo((HIMAGELIST
) iface
, i
, pImageInfo
) ? S_OK
: E_FAIL
;
3123 static HRESULT WINAPI
ImageListImpl_Copy(IImageList
*iface
, int iDst
,
3124 IUnknown
*punkSrc
, int iSrc
, UINT uFlags
)
3126 HIMAGELIST This
= (HIMAGELIST
) iface
;
3127 IImageList
*src
= NULL
;
3133 /* TODO: Add test for IID_ImageList2 too */
3134 if (FAILED(IImageList_QueryInterface(punkSrc
, &IID_IImageList
,
3138 if (ImageList_Copy(This
, iDst
, (HIMAGELIST
) src
, iSrc
, uFlags
))
3143 IImageList_Release(src
);
3147 static HRESULT WINAPI
ImageListImpl_Merge(IImageList
*iface
, int i1
,
3148 IUnknown
*punk2
, int i2
, int dx
, int dy
, REFIID riid
, PVOID
*ppv
)
3150 HIMAGELIST This
= (HIMAGELIST
) iface
;
3151 IImageList
*iml2
= NULL
;
3153 HRESULT ret
= E_FAIL
;
3158 /* TODO: Add test for IID_ImageList2 too */
3159 if (FAILED(IImageList_QueryInterface(punk2
, &IID_IImageList
,
3163 hNew
= ImageList_Merge(This
, i1
, (HIMAGELIST
) iml2
, i2
, dx
, dy
);
3165 /* Get the interface for the new image list */
3167 ret
= HIMAGELIST_QueryInterface(hNew
, riid
, ppv
);
3169 IImageList_Release(iml2
);
3173 static HRESULT WINAPI
ImageListImpl_Clone(IImageList
*iface
, REFIID riid
,
3176 HIMAGELIST This
= (HIMAGELIST
) iface
;
3178 HRESULT ret
= E_FAIL
;
3183 hNew
= ImageList_Duplicate(This
);
3185 /* Get the interface for the new image list */
3187 ret
= HIMAGELIST_QueryInterface(hNew
, riid
, ppv
);
3192 static HRESULT WINAPI
ImageListImpl_GetImageRect(IImageList
*iface
, int i
,
3195 HIMAGELIST This
= (HIMAGELIST
) iface
;
3201 if (!ImageList_GetImageInfo(This
, i
, &info
))
3204 return CopyRect(prc
, &info
.rcImage
) ? S_OK
: E_FAIL
;
3207 static HRESULT WINAPI
ImageListImpl_GetIconSize(IImageList
*iface
, int *cx
,
3210 HIMAGELIST This
= (HIMAGELIST
) iface
;
3212 return ImageList_GetIconSize(This
, cx
, cy
) ? S_OK
: E_FAIL
;
3215 static HRESULT WINAPI
ImageListImpl_SetIconSize(IImageList
*iface
, int cx
,
3218 return ImageList_SetIconSize((HIMAGELIST
) iface
, cx
, cy
) ? S_OK
: E_FAIL
;
3221 static HRESULT WINAPI
ImageListImpl_GetImageCount(IImageList
*iface
, int *pi
)
3226 *pi
= ImageList_GetImageCount((HIMAGELIST
) iface
);
3230 static HRESULT WINAPI
ImageListImpl_SetImageCount(IImageList
*iface
,
3233 return ImageList_SetImageCount((HIMAGELIST
) iface
, uNewCount
) ? S_OK
: E_FAIL
;
3236 static HRESULT WINAPI
ImageListImpl_SetBkColor(IImageList
*iface
, COLORREF clrBk
,
3242 *pclr
= ImageList_SetBkColor((HIMAGELIST
) iface
, clrBk
);
3243 return *pclr
== CLR_NONE
? E_FAIL
: S_OK
;
3246 static HRESULT WINAPI
ImageListImpl_GetBkColor(IImageList
*iface
, COLORREF
*pclr
)
3251 *pclr
= ImageList_GetBkColor((HIMAGELIST
) iface
);
3255 static HRESULT WINAPI
ImageListImpl_BeginDrag(IImageList
*iface
, int iTrack
,
3256 int dxHotspot
, int dyHotspot
)
3258 return ImageList_BeginDrag((HIMAGELIST
) iface
, iTrack
, dxHotspot
, dyHotspot
) ? S_OK
: E_FAIL
;
3261 static HRESULT WINAPI
ImageListImpl_EndDrag(IImageList
*iface
)
3263 ImageList_EndDrag();
3267 static HRESULT WINAPI
ImageListImpl_DragEnter(IImageList
*iface
, HWND hwndLock
,
3270 return ImageList_DragEnter(hwndLock
, x
, y
) ? S_OK
: E_FAIL
;
3273 static HRESULT WINAPI
ImageListImpl_DragLeave(IImageList
*iface
, HWND hwndLock
)
3275 return ImageList_DragLeave(hwndLock
) ? S_OK
: E_FAIL
;
3278 static HRESULT WINAPI
ImageListImpl_DragMove(IImageList
*iface
, int x
, int y
)
3280 return ImageList_DragMove(x
, y
) ? S_OK
: E_FAIL
;
3283 static HRESULT WINAPI
ImageListImpl_SetDragCursorImage(IImageList
*iface
,
3284 IUnknown
*punk
, int iDrag
, int dxHotspot
, int dyHotspot
)
3286 IImageList
*iml2
= NULL
;
3292 /* TODO: Add test for IID_ImageList2 too */
3293 if (FAILED(IImageList_QueryInterface(punk
, &IID_IImageList
,
3297 ret
= ImageList_SetDragCursorImage((HIMAGELIST
) iml2
, iDrag
, dxHotspot
,
3300 IImageList_Release(iml2
);
3302 return ret
? S_OK
: E_FAIL
;
3305 static HRESULT WINAPI
ImageListImpl_DragShowNolock(IImageList
*iface
, BOOL fShow
)
3307 return ImageList_DragShowNolock(fShow
) ? S_OK
: E_FAIL
;
3310 static HRESULT WINAPI
ImageListImpl_GetDragImage(IImageList
*iface
, POINT
*ppt
,
3311 POINT
*pptHotspot
, REFIID riid
, PVOID
*ppv
)
3313 HRESULT ret
= E_FAIL
;
3319 hNew
= ImageList_GetDragImage(ppt
, pptHotspot
);
3321 /* Get the interface for the new image list */
3323 ret
= HIMAGELIST_QueryInterface(hNew
, riid
, ppv
);
3328 static HRESULT WINAPI
ImageListImpl_GetItemFlags(IImageList
*iface
, int i
,
3331 FIXME("STUB: %p %d %p\n", iface
, i
, dwFlags
);
3335 static HRESULT WINAPI
ImageListImpl_GetOverlayImage(IImageList
*iface
, int iOverlay
,
3338 HIMAGELIST This
= (HIMAGELIST
) iface
;
3341 if ((iOverlay
< 0) || (iOverlay
> This
->cCurImage
))
3344 for (i
= 0; i
< MAX_OVERLAYIMAGE
; i
++)
3346 if (This
->nOvlIdx
[i
] == iOverlay
)
3357 static const IImageListVtbl ImageListImpl_Vtbl
= {
3358 ImageListImpl_QueryInterface
,
3359 ImageListImpl_AddRef
,
3360 ImageListImpl_Release
,
3362 ImageListImpl_ReplaceIcon
,
3363 ImageListImpl_SetOverlayImage
,
3364 ImageListImpl_Replace
,
3365 ImageListImpl_AddMasked
,
3367 ImageListImpl_Remove
,
3368 ImageListImpl_GetIcon
,
3369 ImageListImpl_GetImageInfo
,
3371 ImageListImpl_Merge
,
3372 ImageListImpl_Clone
,
3373 ImageListImpl_GetImageRect
,
3374 ImageListImpl_GetIconSize
,
3375 ImageListImpl_SetIconSize
,
3376 ImageListImpl_GetImageCount
,
3377 ImageListImpl_SetImageCount
,
3378 ImageListImpl_SetBkColor
,
3379 ImageListImpl_GetBkColor
,
3380 ImageListImpl_BeginDrag
,
3381 ImageListImpl_EndDrag
,
3382 ImageListImpl_DragEnter
,
3383 ImageListImpl_DragLeave
,
3384 ImageListImpl_DragMove
,
3385 ImageListImpl_SetDragCursorImage
,
3386 ImageListImpl_DragShowNolock
,
3387 ImageListImpl_GetDragImage
,
3388 ImageListImpl_GetItemFlags
,
3389 ImageListImpl_GetOverlayImage
3392 static inline BOOL
is_valid(HIMAGELIST himl
)
3394 return himl
&& himl
->lpVtbl
== &ImageListImpl_Vtbl
;
3397 /*************************************************************************
3398 * HIMAGELIST_QueryInterface [COMCTL32.@]
3400 * Returns a pointer to an IImageList or IImageList2 object for the given
3404 * himl [I] Image list handle.
3405 * riid [I] Identifier of the requested interface.
3406 * ppv [O] Returns the address of the pointer requested, or NULL.
3410 * Failure: Error value.
3413 HIMAGELIST_QueryInterface (HIMAGELIST himl
, REFIID riid
, void **ppv
)
3415 TRACE("(%p,%s,%p)\n", himl
, debugstr_guid(riid
), ppv
);
3416 return IImageList_QueryInterface((IImageList
*) himl
, riid
, ppv
);
3419 static HRESULT
ImageListImpl_CreateInstance(const IUnknown
*pUnkOuter
, REFIID iid
, void** ppv
)
3424 TRACE("(%p,%s,%p)\n", pUnkOuter
, debugstr_guid(iid
), ppv
);
3428 if (pUnkOuter
) return CLASS_E_NOAGGREGATION
;
3430 This
= HeapAlloc(GetProcessHeap(), 0, sizeof(struct _IMAGELIST
));
3431 if (!This
) return E_OUTOFMEMORY
;
3433 ZeroMemory(This
, sizeof(struct _IMAGELIST
));
3435 This
->lpVtbl
= &ImageListImpl_Vtbl
;
3438 ret
= IUnknown_QueryInterface((IUnknown
*)This
, iid
, ppv
);
3439 IUnknown_Release((IUnknown
*)This
);