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;
1093 if (!pimldp || !(himl = pimldp->himl)) return FALSE;
1094 if (!is_valid(himl)) return FALSE;
1095 if ((pimldp->i < 0) || (pimldp->i >= himl->cCurImage)) return FALSE;
1097 imagelist_point_from_index( himl, pimldp->i, &pt );
1098 pt.x += pimldp->xBitmap;
1099 pt.y += pimldp->yBitmap;
1101 fState = pimldp->cbSize < sizeof(IMAGELISTDRAWPARAMS) ? ILS_NORMAL : pimldp->fState;
1102 fStyle = pimldp->fStyle & ~ILD_OVERLAYMASK;
1103 cx = (pimldp->cx == 0) ? himl->cx : pimldp->cx;
1104 cy = (pimldp->cy == 0) ? himl->cy : pimldp->cy;
1106 bIsTransparent = (fStyle & ILD_TRANSPARENT);
1107 if( pimldp->rgbBk == CLR_NONE )
1108 bIsTransparent = TRUE;
1109 if( ( pimldp->rgbBk == CLR_DEFAULT ) && ( himl->clrBk == CLR_NONE ) )
1110 bIsTransparent = TRUE;
1111 bMask = (himl->flags & ILC_MASK) && (fStyle & ILD_MASK) ;
1112 bBlend = (fStyle & (ILD_BLEND25 | ILD_BLEND50) ) && !bMask;
1114 TRACE("himl(%p) hbmMask(%p) iImage(%d) x(%d) y(%d) cx(%d) cy(%d)\n",
1115 himl, himl->hbmMask, pimldp->i, pimldp->x, pimldp->y, cx, cy);
1117 /* we will use these DCs to access the images and masks in the ImageList */
1118 hImageListDC = himl->hdcImage;
1119 hMaskListDC = himl->hdcMask;
1121 /* these will accumulate the image and mask for the image we're drawing */
1122 hImageDC = CreateCompatibleDC( pimldp->hdcDst );
1123 hImageBmp = CreateCompatibleBitmap( pimldp->hdcDst, cx, cy );
1124 hBlendMaskBmp = bBlend ? CreateBitmap(cx, cy, 1, 1, NULL) : 0;
1126 /* Create a compatible DC. */
1127 if (!hImageListDC || !hImageDC || !hImageBmp ||
1128 (bBlend && !hBlendMaskBmp) || (himl->hbmMask && !hMaskListDC))
1131 hOldImageBmp = SelectObject(hImageDC, hImageBmp);
1134 * To obtain a transparent look, background color should be set
1135 * to white and foreground color to black when blting the
1138 oldImageFg = SetTextColor( hImageDC, RGB( 0, 0, 0 ) );
1139 oldImageBk = SetBkColor( hImageDC, RGB( 0xff, 0xff, 0xff ) );
1142 * Draw the initial image
1145 if (himl->hbmMask) {
1147 hOldBrush = SelectObject (hImageDC, CreateSolidBrush (GetTextColor(pimldp->hdcDst)));
1148 PatBlt( hImageDC, 0, 0, cx, cy, PATCOPY );
1149 BitBlt(hImageDC, 0, 0, cx, cy, hMaskListDC, pt.x, pt.y, SRCPAINT);
1150 DeleteObject (SelectObject (hImageDC, hOldBrush));
1151 if( bIsTransparent )
1153 BitBlt ( pimldp->hdcDst, pimldp->x, pimldp->y, cx, cy, hImageDC, 0, 0, SRCAND);
1158 HBRUSH hOldBrush = SelectObject (hImageDC, GetStockObject(BLACK_BRUSH));
1159 PatBlt( hImageDC, 0, 0, cx, cy, PATCOPY);
1160 SelectObject(hImageDC, hOldBrush);
1163 /* blend the image with the needed solid background */
1164 COLORREF colour = RGB(0,0,0);
1167 if( !bIsTransparent )
1169 colour = pimldp->rgbBk;
1170 if( colour == CLR_DEFAULT )
1171 colour = himl->clrBk;
1172 if( colour == CLR_NONE )
1173 colour = GetBkColor(pimldp->hdcDst);
1176 hOldBrush = SelectObject (hImageDC, CreateSolidBrush (colour));
1177 PatBlt( hImageDC, 0, 0, cx, cy, PATCOPY );
1180 BitBlt( hImageDC, 0, 0, cx, cy, hMaskListDC, pt.x, pt.y, SRCAND );
1181 BitBlt( hImageDC, 0, 0, cx, cy, hImageListDC, pt.x, pt.y, SRCPAINT );
1184 BitBlt( hImageDC, 0, 0, cx, cy, hImageListDC, pt.x, pt.y, SRCCOPY);
1185 DeleteObject (SelectObject (hImageDC, hOldBrush));
1188 /* Time for blending, if required */
1190 HBRUSH hBlendBrush, hOldBrush;
1191 COLORREF clrBlend = pimldp->rgbFg;
1192 HDC hBlendMaskDC = hImageListDC;
1195 /* Create the blend Mask */
1196 hOldBitmap = SelectObject(hBlendMaskDC, hBlendMaskBmp);
1197 hBlendBrush = fStyle & ILD_BLEND50 ? himl->hbrBlend50 : himl->hbrBlend25;
1198 hOldBrush = SelectObject(hBlendMaskDC, hBlendBrush);
1199 PatBlt(hBlendMaskDC, 0, 0, cx, cy, PATCOPY);
1200 SelectObject(hBlendMaskDC, hOldBrush);
1202 /* Modify the blend mask if an Image Mask exist */
1204 BitBlt(hBlendMaskDC, 0, 0, cx, cy, hMaskListDC, pt.x, pt.y, 0x220326); /* NOTSRCAND */
1205 BitBlt(hBlendMaskDC, 0, 0, cx, cy, hBlendMaskDC, 0, 0, NOTSRCCOPY);
1208 /* now apply blend to the current image given the BlendMask */
1209 if (clrBlend == CLR_DEFAULT) clrBlend = GetSysColor (COLOR_HIGHLIGHT);
1210 else if (clrBlend == CLR_NONE) clrBlend = GetTextColor (pimldp->hdcDst);
1211 hOldBrush = SelectObject (hImageDC, CreateSolidBrush(clrBlend));
1212 BitBlt (hImageDC, 0, 0, cx, cy, hBlendMaskDC, 0, 0, 0xB8074A); /* PSDPxax */
1213 DeleteObject(SelectObject(hImageDC, hOldBrush));
1214 SelectObject(hBlendMaskDC, hOldBitmap);
1217 /* Now do the overlay image, if any */
1218 nOvlIdx = (pimldp->fStyle & ILD_OVERLAYMASK) >> 8;
1219 if ( (nOvlIdx >= 1) && (nOvlIdx <= MAX_OVERLAYIMAGE)) {
1220 nOvlIdx = himl->nOvlIdx[nOvlIdx - 1];
1221 if ((nOvlIdx >= 0) && (nOvlIdx < himl->cCurImage)) {
1223 imagelist_point_from_index( himl, nOvlIdx, &ptOvl );
1224 ptOvl.x += pimldp->xBitmap;
1225 if (himl->hbmMask && !(fStyle & ILD_IMAGE))
1226 BitBlt (hImageDC, 0, 0, cx, cy, hMaskListDC, ptOvl.x, ptOvl.y, SRCAND);
1227 BitBlt (hImageDC, 0, 0, cx, cy, hImageListDC, ptOvl.x, ptOvl.y, SRCPAINT);
1231 if (fState & ILS_SATURATE) FIXME("ILS_SATURATE: unimplemented!\n");
1232 if (fState & ILS_GLOW) FIXME("ILS_GLOW: unimplemented!\n");
1233 if (fState & ILS_SHADOW) FIXME("ILS_SHADOW: unimplemented!\n");
1234 if (fState & ILS_ALPHA) FIXME("ILS_ALPHA: unimplemented!\n");
1236 if (fStyle & ILD_PRESERVEALPHA) FIXME("ILD_PRESERVEALPHA: unimplemented!\n");
1237 if (fStyle & ILD_SCALE) FIXME("ILD_SCALE: unimplemented!\n");
1238 if (fStyle & ILD_DPISCALE) FIXME("ILD_DPISCALE: unimplemented!\n");
1240 /* now copy the image to the screen */
1242 if (himl->hbmMask && bIsTransparent ) {
1243 COLORREF oldDstFg = SetTextColor(pimldp->hdcDst, RGB( 0, 0, 0 ) );
1244 COLORREF oldDstBk = SetBkColor(pimldp->hdcDst, RGB( 0xff, 0xff, 0xff ));
1245 BitBlt (pimldp->hdcDst, pimldp->x, pimldp->y, cx, cy, hMaskListDC, pt.x, pt.y, SRCAND);
1246 SetBkColor(pimldp->hdcDst, oldDstBk);
1247 SetTextColor(pimldp->hdcDst, oldDstFg);
1250 if (fStyle & ILD_ROP) dwRop = pimldp->dwRop;
1251 BitBlt (pimldp->hdcDst, pimldp->x, pimldp->y, cx, cy, hImageDC, 0, 0, dwRop);
1255 /* cleanup the mess */
1256 SetBkColor(hImageDC, oldImageBk);
1257 SetTextColor(hImageDC, oldImageFg);
1258 SelectObject(hImageDC, hOldImageBmp);
1260 DeleteObject(hBlendMaskBmp);
1261 DeleteObject(hImageBmp);
1268 /*************************************************************************
1269 * ImageList_Duplicate [COMCTL32.@]
1271 * Duplicates an image list.
1274 * himlSrc [I] source image list handle
1277 * Success: Handle of duplicated image list.
1282 ImageList_Duplicate (HIMAGELIST himlSrc)
1286 if (!is_valid(himlSrc)) {
1287 ERR("Invalid image list handle!\n");
1291 himlDst = ImageList_Create (himlSrc->cx, himlSrc->cy, himlSrc->flags,
1292 himlSrc->cInitial, himlSrc->cGrow);
1298 imagelist_get_bitmap_size(himlSrc, himlSrc->cCurImage, &sz);
1299 BitBlt (himlDst->hdcImage, 0, 0, sz.cx, sz.cy,
1300 himlSrc->hdcImage, 0, 0, SRCCOPY);
1302 if (himlDst->hbmMask)
1303 BitBlt (himlDst->hdcMask, 0, 0, sz.cx, sz.cy,
1304 himlSrc->hdcMask, 0, 0, SRCCOPY);
1306 himlDst->cCurImage = himlSrc->cCurImage;
1307 himlDst->cMaxImage = himlSrc->cMaxImage;
1313 /*************************************************************************
1314 * ImageList_EndDrag [COMCTL32.@]
1316 * Finishes a drag operation.
1327 ImageList_EndDrag (void)
1329 /* cleanup the InternalDrag struct */
1330 InternalDrag.hwnd = 0;
1331 ImageList_Destroy (InternalDrag.himl);
1332 InternalDrag.himl = 0;
1335 InternalDrag.dxHotspot = 0;
1336 InternalDrag.dyHotspot = 0;
1337 InternalDrag.bShow = FALSE;
1338 DeleteObject(InternalDrag.hbmBg);
1339 InternalDrag.hbmBg = 0;
1343 /*************************************************************************
1344 * ImageList_GetBkColor [COMCTL32.@]
1346 * Returns the background color of an image list.
1349 * himl [I] Image list handle.
1352 * Success: background color
1357 ImageList_GetBkColor (HIMAGELIST himl)
1359 return himl ? himl->clrBk : CLR_NONE;
1363 /*************************************************************************
1364 * ImageList_GetDragImage [COMCTL32.@]
1366 * Returns the handle to the internal drag image list.
1369 * ppt [O] Pointer to the drag position. Can be NULL.
1370 * pptHotspot [O] Pointer to the position of the hot spot. Can be NULL.
1373 * Success: Handle of the drag image list.
1378 ImageList_GetDragImage (POINT *ppt, POINT *pptHotspot)
1380 if (is_valid(InternalDrag.himl)) {
1382 ppt->x = InternalDrag.x;
1383 ppt->y = InternalDrag.y;
1386 pptHotspot->x = InternalDrag.dxHotspot;
1387 pptHotspot->y = InternalDrag.dyHotspot;
1389 return (InternalDrag.himl);
1396 /*************************************************************************
1397 * ImageList_GetFlags [COMCTL32.@]
1399 * Gets the flags of the specified image list.
1402 * himl [I] Handle to image list
1412 ImageList_GetFlags(HIMAGELIST himl)
1414 TRACE("%p\n", himl);
1416 return is_valid(himl) ? himl->flags : 0;
1420 /*************************************************************************
1421 * ImageList_GetIcon [COMCTL32.@]
1423 * Creates an icon from a masked image of an image list.
1426 * himl [I] handle to image list
1428 * flags [I] drawing style flags
1431 * Success: icon handle
1436 ImageList_GetIcon (HIMAGELIST himl, INT i, UINT fStyle)
1440 HBITMAP hOldDstBitmap;
1444 TRACE("%p %d %d\n", himl, i, fStyle);
1445 if (!is_valid(himl) || (i < 0) || (i >= himl->cCurImage)) return NULL;
1451 /* create colour bitmap */
1453 ii.hbmColor = CreateCompatibleBitmap(hdcDst, himl->cx, himl->cy);
1454 ReleaseDC(0, hdcDst);
1456 hdcDst = CreateCompatibleDC(0);
1458 imagelist_point_from_index( himl, i, &pt );
1461 ii.hbmMask = CreateBitmap (himl->cx, himl->cy, 1, 1, NULL);
1462 hOldDstBitmap = SelectObject (hdcDst, ii.hbmMask);
1463 if (himl->hbmMask) {
1464 BitBlt (hdcDst, 0, 0, himl->cx, himl->cy,
1465 himl->hdcMask, pt.x, pt.y, SRCCOPY);
1468 PatBlt (hdcDst, 0, 0, himl->cx, himl->cy, BLACKNESS);
1471 SelectObject (hdcDst, ii.hbmColor);
1472 BitBlt (hdcDst, 0, 0, himl->cx, himl->cy,
1473 himl->hdcImage, pt.x, pt.y, SRCCOPY);
1476 * CreateIconIndirect requires us to deselect the bitmaps from
1477 * the DCs before calling
1479 SelectObject(hdcDst, hOldDstBitmap);
1481 hIcon = CreateIconIndirect (&ii);
1483 DeleteObject (ii.hbmMask);
1484 DeleteObject (ii.hbmColor);
1491 /*************************************************************************
1492 * ImageList_GetIconSize [COMCTL32.@]
1494 * Retrieves the size of an image in an image list.
1497 * himl [I] handle to image list
1498 * cx [O] pointer to the image width.
1499 * cy [O] pointer to the image height.
1506 * All images in an image list have the same size.
1510 ImageList_GetIconSize (HIMAGELIST himl, INT *cx, INT *cy)
1512 if (!is_valid(himl))
1514 if ((himl->cx <= 0) || (himl->cy <= 0))
1526 /*************************************************************************
1527 * ImageList_GetImageCount [COMCTL32.@]
1529 * Returns the number of images in an image list.
1532 * himl [I] handle to image list
1535 * Success: Number of images.
1540 ImageList_GetImageCount (HIMAGELIST himl)
1542 if (!is_valid(himl))
1545 return himl->cCurImage;
1549 /*************************************************************************
1550 * ImageList_GetImageInfo [COMCTL32.@]
1552 * Returns information about an image in an image list.
1555 * himl [I] handle to image list
1557 * pImageInfo [O] pointer to the image information
1565 ImageList_GetImageInfo (HIMAGELIST himl, INT i, IMAGEINFO *pImageInfo)
1569 if (!is_valid(himl) || (pImageInfo == NULL))
1571 if ((i < 0) || (i >= himl->cCurImage))
1574 pImageInfo->hbmImage = himl->hbmImage;
1575 pImageInfo->hbmMask = himl->hbmMask;
1577 imagelist_point_from_index( himl, i, &pt );
1578 pImageInfo->rcImage.top = pt.y;
1579 pImageInfo->rcImage.bottom = pt.y + himl->cy;
1580 pImageInfo->rcImage.left = pt.x;
1581 pImageInfo->rcImage.right = pt.x + himl->cx;
1587 /*************************************************************************
1588 * ImageList_GetImageRect [COMCTL32.@]
1590 * Retrieves the rectangle of the specified image in an image list.
1593 * himl [I] handle to image list
1595 * lpRect [O] pointer to the image rectangle
1602 * This is an UNDOCUMENTED function!!!
1606 ImageList_GetImageRect (HIMAGELIST himl, INT i, LPRECT lpRect)
1610 if (!is_valid(himl) || (lpRect == NULL))
1612 if ((i < 0) || (i >= himl->cCurImage))
1615 imagelist_point_from_index( himl, i, &pt );
1616 lpRect->left = pt.x;
1618 lpRect->right = pt.x + himl->cx;
1619 lpRect->bottom = pt.y + himl->cy;
1625 /*************************************************************************
1626 * ImageList_LoadImage [COMCTL32.@]
1627 * ImageList_LoadImageA [COMCTL32.@]
1629 * Creates an image list from a bitmap, icon or cursor.
1631 * See ImageList_LoadImageW.
1635 ImageList_LoadImageA (HINSTANCE hi, LPCSTR lpbmp, INT cx, INT cGrow,
1636 COLORREF clrMask, UINT uType, UINT uFlags)
1642 if (IS_INTRESOURCE(lpbmp))
1643 return ImageList_LoadImageW(hi, (LPCWSTR)lpbmp, cx, cGrow, clrMask,
1646 len = MultiByteToWideChar(CP_ACP, 0, lpbmp, -1, NULL, 0);
1647 lpbmpW = Alloc(len * sizeof(WCHAR));
1648 MultiByteToWideChar(CP_ACP, 0, lpbmp, -1, lpbmpW, len);
1650 himl = ImageList_LoadImageW(hi, lpbmpW, cx, cGrow, clrMask, uType, uFlags);
1656 /*************************************************************************
1657 * ImageList_LoadImageW [COMCTL32.@]
1659 * Creates an image list from a bitmap, icon or cursor.
1662 * hi [I] instance handle
1663 * lpbmp [I] name or id of the image
1664 * cx [I] width of each image
1665 * cGrow [I] number of images to expand
1666 * clrMask [I] mask color
1667 * uType [I] type of image to load
1668 * uFlags [I] loading flags
1671 * Success: handle to the loaded image list
1679 ImageList_LoadImageW (HINSTANCE hi, LPCWSTR lpbmp, INT cx, INT cGrow,
1680 COLORREF clrMask, UINT uType, UINT uFlags)
1682 HIMAGELIST himl = NULL;
1686 handle = LoadImageW (hi, lpbmp, uType, 0, 0, uFlags);
1688 WARN("Couldn't load image\n");
1692 if (uType == IMAGE_BITMAP) {
1694 GetObjectW (handle, sizeof(BITMAP), &bmp);
1696 /* To match windows behavior, if cx is set to zero and
1697 the flag DI_DEFAULTSIZE is specified, cx becomes the
1698 system metric value for icons. If the flag is not specified
1699 the function sets the size to the height of the bitmap */
1702 if (uFlags & DI_DEFAULTSIZE)
1703 cx = GetSystemMetrics (SM_CXICON);
1708 nImageCount = bmp.bmWidth / cx;
1710 himl = ImageList_Create (cx, bmp.bmHeight, ILC_MASK | ILC_COLOR,
1711 nImageCount, cGrow);
1713 DeleteObject (handle);
1716 ImageList_AddMasked (himl, handle, clrMask);
1718 else if ((uType == IMAGE_ICON) || (uType == IMAGE_CURSOR)) {
1722 GetIconInfo (handle, &ii);
1723 GetObjectW (ii.hbmColor, sizeof(BITMAP), &bmp);
1724 himl = ImageList_Create (bmp.bmWidth, bmp.bmHeight,
1725 ILC_MASK | ILC_COLOR, 1, cGrow);
1727 DeleteObject (ii.hbmColor);
1728 DeleteObject (ii.hbmMask);
1729 DeleteObject (handle);
1732 ImageList_Add (himl, ii.hbmColor, ii.hbmMask);
1733 DeleteObject (ii.hbmColor);
1734 DeleteObject (ii.hbmMask);
1737 DeleteObject (handle);
1743 /*************************************************************************
1744 * ImageList_Merge [COMCTL32.@]
1746 * Create an image list containing a merged image from two image lists.
1749 * himl1 [I] handle to first image list
1750 * i1 [I] first image index
1751 * himl2 [I] handle to second image list
1752 * i2 [I] second image index
1753 * dx [I] X offset of the second image relative to the first.
1754 * dy [I] Y offset of the second image relative to the first.
1757 * Success: The newly created image list. It contains a single image
1758 * consisting of the second image merged with the first.
1759 * Failure: NULL, if either himl1 or himl2 are invalid.
1762 * - The returned image list should be deleted by the caller using
1763 * ImageList_Destroy() when it is no longer required.
1764 * - If either i1 or i2 are not valid image indices they will be treated
1768 ImageList_Merge (HIMAGELIST himl1, INT i1, HIMAGELIST himl2, INT i2,
1771 HIMAGELIST himlDst = NULL;
1773 INT xOff1, yOff1, xOff2, yOff2;
1776 TRACE("(himl1=%p i1=%d himl2=%p i2=%d dx=%d dy=%d)\n", himl1, i1, himl2,
1779 if (!is_valid(himl1) || !is_valid(himl2))
1783 cxDst = max (himl1->cx, dx + himl2->cx);
1788 cxDst = max (himl2->cx, himl1->cx - dx);
1793 cxDst = max (himl1->cx, himl2->cx);
1799 cyDst = max (himl1->cy, dy + himl2->cy);
1804 cyDst = max (himl2->cy, himl1->cy - dy);
1809 cyDst = max (himl1->cy, himl2->cy);
1814 himlDst = ImageList_Create (cxDst, cyDst, ILC_MASK | ILC_COLOR, 1, 1);
1818 imagelist_point_from_index( himl1, i1, &pt1 );
1819 imagelist_point_from_index( himl1, i2, &pt2 );
1822 BitBlt (himlDst->hdcImage, 0, 0, cxDst, cyDst, himl1->hdcImage, 0, 0, BLACKNESS);
1823 if (i1 >= 0 && i1 < himl1->cCurImage)
1824 BitBlt (himlDst->hdcImage, xOff1, yOff1, himl1->cx, himl1->cy, himl1->hdcImage, pt1.x, pt1.y, SRCCOPY);
1825 if (i2 >= 0 && i2 < himl2->cCurImage)
1827 BitBlt (himlDst->hdcImage, xOff2, yOff2, himl2->cx, himl2->cy, himl2->hdcMask , pt2.x, pt2.y, SRCAND);
1828 BitBlt (himlDst->hdcImage, xOff2, yOff2, himl2->cx, himl2->cy, himl2->hdcImage, pt2.x, pt2.y, SRCPAINT);
1832 BitBlt (himlDst->hdcMask, 0, 0, cxDst, cyDst, himl1->hdcMask, 0, 0, WHITENESS);
1833 if (i1 >= 0 && i1 < himl1->cCurImage)
1834 BitBlt (himlDst->hdcMask, xOff1, yOff1, himl1->cx, himl1->cy, himl1->hdcMask, pt1.x, pt1.y, SRCCOPY);
1835 if (i2 >= 0 && i2 < himl2->cCurImage)
1836 BitBlt (himlDst->hdcMask, xOff2, yOff2, himl2->cx, himl2->cy, himl2->hdcMask, pt2.x, pt2.y, SRCAND);
1838 himlDst->cCurImage = 1;
1845 /***********************************************************************
1846 * DIB_GetDIBWidthBytes
1848 * Return the width of a DIB bitmap in bytes. DIB bitmap data is 32-bit aligned.
1850 static int DIB_GetDIBWidthBytes( int width, int depth )
1856 case 1: words = (width + 31) / 32; break;
1857 case 4: words = (width + 7) / 8; break;
1858 case 8: words = (width + 3) / 4; break;
1860 case 16: words = (width + 1) / 2; break;
1861 case 24: words = (width * 3 + 3)/4; break;
1864 WARN("(%d): Unsupported depth\n", depth );
1873 /***********************************************************************
1874 * DIB_GetDIBImageBytes
1876 * Return the number of bytes used to hold the image in a DIB bitmap.
1878 static int DIB_GetDIBImageBytes( int width, int height, int depth )
1880 return DIB_GetDIBWidthBytes( width, depth ) * abs( height );
1884 /* helper for ImageList_Read, see comments below */
1885 static BOOL _read_bitmap(HDC hdcIml, LPSTREAM pstm)
1887 BITMAPFILEHEADER bmfh;
1888 int bitsperpixel, palspace;
1889 char bmi_buf[sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD) * 256];
1890 LPBITMAPINFO bmi = (LPBITMAPINFO)bmi_buf;
1894 if (FAILED(IStream_Read ( pstm, &bmfh, sizeof(bmfh), NULL)))
1897 if (bmfh.bfType != (('M'<<8)|'B'))
1900 if (FAILED(IStream_Read ( pstm, &bmi->bmiHeader, sizeof(bmi->bmiHeader), NULL)))
1903 if ((bmi->bmiHeader.biSize != sizeof(bmi->bmiHeader)))
1906 TRACE("width %u, height %u, planes %u, bpp %u\n",
1907 bmi->bmiHeader.biWidth, bmi->bmiHeader.biHeight,
1908 bmi->bmiHeader.biPlanes, bmi->bmiHeader.biBitCount);
1910 bitsperpixel = bmi->bmiHeader.biPlanes * bmi->bmiHeader.biBitCount;
1911 if (bitsperpixel<=8)
1912 palspace = (1<<bitsperpixel)*sizeof(RGBQUAD);
1916 bmi->bmiHeader.biSizeImage = DIB_GetDIBImageBytes(bmi->bmiHeader.biWidth, bmi->bmiHeader.biHeight, bitsperpixel);
1918 /* read the palette right after the end of the bitmapinfoheader */
1919 if (palspace && FAILED(IStream_Read(pstm, bmi->bmiColors, palspace, NULL)))
1922 bits = Alloc(bmi->bmiHeader.biSizeImage);
1925 if (FAILED(IStream_Read(pstm, bits, bmi->bmiHeader.biSizeImage, NULL)))
1928 if (!StretchDIBits(hdcIml, 0, 0, bmi->bmiHeader.biWidth, bmi->bmiHeader.biHeight,
1929 0, 0, bmi->bmiHeader.biWidth, bmi->bmiHeader.biHeight,
1930 bits, bmi, DIB_RGB_COLORS, SRCCOPY))
1939 /*************************************************************************
1940 * ImageList_Read [COMCTL32.@]
1942 * Reads an image list from a stream.
1945 * pstm [I] pointer to a stream
1948 * Success: handle to image list
1951 * The format is like this:
1952 * ILHEAD ilheadstruct;
1954 * for the color image part:
1955 * BITMAPFILEHEADER bmfh;
1956 * BITMAPINFOHEADER bmih;
1957 * only if it has a palette:
1958 * RGBQUAD rgbs[nr_of_paletted_colors];
1960 * BYTE colorbits[imagesize];
1962 * the following only if the ILC_MASK bit is set in ILHEAD.ilFlags:
1963 * BITMAPFILEHEADER bmfh_mask;
1964 * BITMAPINFOHEADER bmih_mask;
1965 * only if it has a palette (it usually does not):
1966 * RGBQUAD rgbs[nr_of_paletted_colors];
1968 * BYTE maskbits[imagesize];
1970 HIMAGELIST WINAPI ImageList_Read (LPSTREAM pstm)
1976 TRACE("%p\n", pstm);
1978 if (FAILED(IStream_Read (pstm, &ilHead, sizeof(ILHEAD), NULL)))
1980 if (ilHead.usMagic != (('L' << 8) | 'I'))
1982 if (ilHead.usVersion != 0x101) /* probably version? */
1985 TRACE("cx %u, cy %u, flags 0x%04x, cCurImage %u, cMaxImage %u\n",
1986 ilHead.cx, ilHead.cy, ilHead.flags, ilHead.cCurImage, ilHead.cMaxImage);
1988 himl = ImageList_Create(ilHead.cx, ilHead.cy, ilHead.flags, ilHead.cCurImage, ilHead.cMaxImage);
1992 if (!_read_bitmap(himl->hdcImage, pstm))
1994 WARN("failed to read bitmap from stream\n");
1997 if (ilHead.flags & ILC_MASK)
1999 if (!_read_bitmap(himl->hdcMask, pstm))
2001 WARN("failed to read mask bitmap from stream\n");
2006 himl->cCurImage = ilHead.cCurImage;
2007 himl->cMaxImage = ilHead.cMaxImage;
2009 ImageList_SetBkColor(himl,ilHead.bkcolor);
2011 ImageList_SetOverlayImage(himl,ilHead.ovls[i],i+1);
2016 /*************************************************************************
2017 * ImageList_Remove [COMCTL32.@]
2019 * Removes an image from an image list
2022 * himl [I] image list handle
2029 * FIXME: as the image list storage test shows, native comctl32 simply shifts
2030 * images without creating a new bitmap.
2033 ImageList_Remove (HIMAGELIST himl, INT i)
2035 HBITMAP hbmNewImage, hbmNewMask;
2039 TRACE("(himl=%p i=%d)\n", himl, i);
2041 if (!is_valid(himl)) {
2042 ERR("Invalid image list handle!\n");
2046 if ((i < -1) || (i >= himl->cCurImage)) {
2047 TRACE("index out of range! %d\n", i);
2055 if (himl->cCurImage == 0) {
2056 /* remove all on empty ImageList is allowed */
2057 TRACE("remove all on empty ImageList!\n");
2061 himl->cMaxImage = himl->cInitial + himl->cGrow - 1;
2062 himl->cCurImage = 0;
2063 for (nCount = 0; nCount < MAX_OVERLAYIMAGE; nCount++)
2064 himl->nOvlIdx[nCount] = -1;
2066 hbmNewImage = ImageList_CreateImage(himl->hdcImage, himl, himl->cMaxImage);
2067 SelectObject (himl->hdcImage, hbmNewImage);
2068 DeleteObject (himl->hbmImage);
2069 himl->hbmImage = hbmNewImage;
2071 if (himl->hbmMask) {
2073 imagelist_get_bitmap_size(himl, himl->cMaxImage, &sz);
2074 hbmNewMask = CreateBitmap (sz.cx, sz.cy, 1, 1, NULL);
2075 SelectObject (himl->hdcMask, hbmNewMask);
2076 DeleteObject (himl->hbmMask);
2077 himl->hbmMask = hbmNewMask;
2081 /* delete one image */
2082 TRACE("Remove single image! %d\n", i);
2084 /* create new bitmap(s) */
2085 TRACE(" - Number of images: %d / %d (Old/New)\n",
2086 himl->cCurImage, himl->cCurImage - 1);
2088 hbmNewImage = ImageList_CreateImage(himl->hdcImage, himl, himl->cMaxImage);
2090 imagelist_get_bitmap_size(himl, himl->cMaxImage, &sz );
2092 hbmNewMask = CreateBitmap (sz.cx, sz.cy, 1, 1, NULL);
2094 hbmNewMask = 0; /* Just to keep compiler happy! */
2096 hdcBmp = CreateCompatibleDC (0);
2098 /* copy all images and masks prior to the "removed" image */
2100 TRACE("Pre image copy: Copy %d images\n", i);
2102 SelectObject (hdcBmp, hbmNewImage);
2103 imagelist_copy_images( himl, himl->hdcImage, hdcBmp, 0, i, 0 );
2105 if (himl->hbmMask) {
2106 SelectObject (hdcBmp, hbmNewMask);
2107 imagelist_copy_images( himl, himl->hdcMask, hdcBmp, 0, i, 0 );
2111 /* copy all images and masks behind the removed image */
2112 if (i < himl->cCurImage - 1) {
2113 TRACE("Post image copy!\n");
2115 SelectObject (hdcBmp, hbmNewImage);
2116 imagelist_copy_images( himl, himl->hdcImage, hdcBmp, i + 1,
2117 (himl->cCurImage - i), i );
2119 if (himl->hbmMask) {
2120 SelectObject (hdcBmp, hbmNewMask);
2121 imagelist_copy_images( himl, himl->hdcMask, hdcBmp, i + 1,
2122 (himl->cCurImage - i), i );
2128 /* delete old images and insert new ones */
2129 SelectObject (himl->hdcImage, hbmNewImage);
2130 DeleteObject (himl->hbmImage);
2131 himl->hbmImage = hbmNewImage;
2132 if (himl->hbmMask) {
2133 SelectObject (himl->hdcMask, hbmNewMask);
2134 DeleteObject (himl->hbmMask);
2135 himl->hbmMask = hbmNewMask;
2145 /*************************************************************************
2146 * ImageList_Replace [COMCTL32.@]
2148 * Replaces an image in an image list with a new image.
2151 * himl [I] handle to image list
2153 * hbmImage [I] handle to image bitmap
2154 * hbmMask [I] handle to mask bitmap. Can be NULL.
2162 ImageList_Replace (HIMAGELIST himl, INT i, HBITMAP hbmImage,
2170 TRACE("%p %d %p %p\n", himl, i, hbmImage, hbmMask);
2172 if (!is_valid(himl)) {
2173 ERR("Invalid image list handle!\n");
2177 if ((i >= himl->cMaxImage) || (i < 0)) {
2178 ERR("Invalid image index!\n");
2182 if (!GetObjectW(hbmImage, sizeof(BITMAP), &bmp))
2185 hdcImage = CreateCompatibleDC (0);
2188 hOldBitmap = SelectObject (hdcImage, hbmImage);
2190 imagelist_point_from_index(himl, i, &pt);
2191 StretchBlt (himl->hdcImage, pt.x, pt.y, himl->cx, himl->cy,
2192 hdcImage, 0, 0, bmp.bmWidth, bmp.bmHeight, SRCCOPY);
2197 HBITMAP hOldBitmapTemp;
2199 hdcTemp = CreateCompatibleDC(0);
2200 hOldBitmapTemp = SelectObject(hdcTemp, hbmMask);
2202 StretchBlt (himl->hdcMask, pt.x, pt.y, himl->cx, himl->cy,
2203 hdcTemp, 0, 0, bmp.bmWidth, bmp.bmHeight, SRCCOPY);
2204 SelectObject(hdcTemp, hOldBitmapTemp);
2207 /* Remove the background from the image
2209 BitBlt (himl->hdcImage, pt.x, pt.y, bmp.bmWidth, bmp.bmHeight,
2210 himl->hdcMask, pt.x, pt.y, 0x220326); /* NOTSRCAND */
2213 SelectObject (hdcImage, hOldBitmap);
2214 DeleteDC (hdcImage);
2220 /*************************************************************************
2221 * ImageList_ReplaceIcon [COMCTL32.@]
2223 * Replaces an image in an image list using an icon.
2226 * himl [I] handle to image list
2228 * hIcon [I] handle to icon
2231 * Success: index of the replaced image
2236 ImageList_ReplaceIcon (HIMAGELIST himl, INT nIndex, HICON hIcon)
2246 TRACE("(%p %d %p)\n", himl, nIndex, hIcon);
2248 if (!is_valid(himl)) {
2249 ERR("invalid image list\n");
2252 if ((nIndex >= himl->cMaxImage) || (nIndex < -1)) {
2253 ERR("invalid image index %d / %d\n", nIndex, himl->cMaxImage);
2257 hBestFitIcon = CopyImage(
2260 LR_COPYFROMRESOURCE);
2261 /* the above will fail if the icon wasn't loaded from a resource, so try
2262 * again without LR_COPYFROMRESOURCE flag */
2264 hBestFitIcon = CopyImage(
2271 ret = GetIconInfo (hBestFitIcon, &ii);
2273 DestroyIcon(hBestFitIcon);
2277 ret = GetObjectW (ii.hbmMask, sizeof(BITMAP), &bmp);
2279 ERR("couldn't get mask bitmap info\n");
2281 DeleteObject (ii.hbmColor);
2283 DeleteObject (ii.hbmMask);
2284 DestroyIcon(hBestFitIcon);
2289 if (himl->cCurImage + 1 > himl->cMaxImage)
2290 IMAGELIST_InternalExpandBitmaps(himl, 1);
2292 nIndex = himl->cCurImage;
2296 hdcImage = CreateCompatibleDC (0);
2297 TRACE("hdcImage=%p\n", hdcImage);
2299 ERR("invalid hdcImage!\n");
2301 imagelist_point_from_index(himl, nIndex, &pt);
2303 SetTextColor(himl->hdcImage, RGB(0,0,0));
2304 SetBkColor (himl->hdcImage, RGB(255,255,255));
2308 hbmOldSrc = SelectObject (hdcImage, ii.hbmColor);
2309 StretchBlt (himl->hdcImage, pt.x, pt.y, himl->cx, himl->cy,
2310 hdcImage, 0, 0, bmp.bmWidth, bmp.bmHeight, SRCCOPY);
2313 SelectObject (hdcImage, ii.hbmMask);
2314 StretchBlt (himl->hdcMask, pt.x, pt.y, himl->cx, himl->cy,
2315 hdcImage, 0, 0, bmp.bmWidth, bmp.bmHeight, SRCCOPY);
2320 UINT height = bmp.bmHeight / 2;
2321 hbmOldSrc = SelectObject (hdcImage, ii.hbmMask);
2322 StretchBlt (himl->hdcImage, pt.x, pt.y, himl->cx, himl->cy,
2323 hdcImage, 0, height, bmp.bmWidth, height, SRCCOPY);
2325 StretchBlt (himl->hdcMask, pt.x, pt.y, himl->cx, himl->cy,
2326 hdcImage, 0, 0, bmp.bmWidth, height, SRCCOPY);
2329 SelectObject (hdcImage, hbmOldSrc);
2331 DestroyIcon(hBestFitIcon);
2333 DeleteDC (hdcImage);
2335 DeleteObject (ii.hbmColor);
2337 DeleteObject (ii.hbmMask);
2339 TRACE("Insert index = %d, himl->cCurImage = %d\n", nIndex, himl->cCurImage);
2344 /*************************************************************************
2345 * ImageList_SetBkColor [COMCTL32.@]
2347 * Sets the background color of an image list.
2350 * himl [I] handle to image list
2351 * clrBk [I] background color
2354 * Success: previous background color
2359 ImageList_SetBkColor (HIMAGELIST himl, COLORREF clrBk)
2363 if (!is_valid(himl))
2366 clrOldBk = himl->clrBk;
2367 himl->clrBk = clrBk;
2372 /*************************************************************************
2373 * ImageList_SetDragCursorImage [COMCTL32.@]
2375 * Combines the specified image with the current drag image
2378 * himlDrag [I] handle to drag image list
2379 * iDrag [I] drag image index
2380 * dxHotspot [I] X position of the hot spot
2381 * dyHotspot [I] Y position of the hot spot
2388 * - The names dxHotspot, dyHotspot are misleading because they have nothing
2389 * to do with a hotspot but are only the offset of the origin of the new
2390 * image relative to the origin of the old image.
2392 * - When this function is called and the drag image is visible, a
2393 * short flickering occurs but this matches the Win9x behavior. It is
2394 * possible to fix the flickering using code like in ImageList_DragMove.
2398 ImageList_SetDragCursorImage (HIMAGELIST himlDrag, INT iDrag,
2399 INT dxHotspot, INT dyHotspot)
2401 HIMAGELIST himlTemp;
2404 if (!is_valid(InternalDrag.himl) || !is_valid(himlDrag))
2407 TRACE(" dxH=%d dyH=%d nX=%d nY=%d\n",
2408 dxHotspot, dyHotspot, InternalDrag.dxHotspot, InternalDrag.dyHotspot);
2410 visible = InternalDrag.bShow;
2412 himlTemp = ImageList_Merge (InternalDrag.himl, 0, himlDrag, iDrag,
2413 dxHotspot, dyHotspot);
2416 /* hide the drag image */
2417 ImageList_DragShowNolock(FALSE);
2419 if ((InternalDrag.himl->cx != himlTemp->cx) ||
2420 (InternalDrag.himl->cy != himlTemp->cy)) {
2421 /* the size of the drag image changed, invalidate the buffer */
2422 DeleteObject(InternalDrag.hbmBg);
2423 InternalDrag.hbmBg = 0;
2426 ImageList_Destroy (InternalDrag.himl);
2427 InternalDrag.himl = himlTemp;
2430 /* show the drag image */
2431 ImageList_DragShowNolock(TRUE);
2438 /*************************************************************************
2439 * ImageList_SetFilter [COMCTL32.@]
2441 * Sets a filter (or does something completely different)!!???
2442 * It removes 12 Bytes from the stack (3 Parameters).
2445 * himl [I] SHOULD be a handle to image list
2446 * i [I] COULD be an index?
2451 * Failure: FALSE ???
2454 * This is an UNDOCUMENTED function!!!!
2459 ImageList_SetFilter (HIMAGELIST himl, INT i, DWORD dwFilter)
2461 FIXME("(%p 0x%x 0x%x):empty stub!\n", himl, i, dwFilter);
2467 /*************************************************************************
2468 * ImageList_SetFlags [COMCTL32.@]
2470 * Sets the image list flags.
2473 * himl [I] Handle to image list
2474 * flags [I] Flags to set
2484 ImageList_SetFlags(HIMAGELIST himl, DWORD flags)
2486 FIXME("(%p %08x):empty stub\n", himl, flags);
2491 /*************************************************************************
2492 * ImageList_SetIconSize [COMCTL32.@]
2494 * Sets the image size of the bitmap and deletes all images.
2497 * himl [I] handle to image list
2498 * cx [I] image width
2499 * cy [I] image height
2507 ImageList_SetIconSize (HIMAGELIST himl, INT cx, INT cy)
2512 if (!is_valid(himl))
2515 /* remove all images */
2516 himl->cMaxImage = himl->cInitial + 1;
2517 himl->cCurImage = 0;
2521 /* initialize overlay mask indices */
2522 for (nCount = 0; nCount < MAX_OVERLAYIMAGE; nCount++)
2523 himl->nOvlIdx[nCount] = -1;
2525 hbmNew = ImageList_CreateImage(himl->hdcImage, himl, himl->cMaxImage);
2526 SelectObject (himl->hdcImage, hbmNew);
2527 DeleteObject (himl->hbmImage);
2528 himl->hbmImage = hbmNew;
2530 if (himl->hbmMask) {
2532 imagelist_get_bitmap_size(himl, himl->cMaxImage, &sz);
2533 hbmNew = CreateBitmap (sz.cx, sz.cy, 1, 1, NULL);
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, hbmOld;
2562 INT nNewCount, nCopyCount;
2564 TRACE("%p %d\n",himl,iImageCount);
2566 if (!is_valid(himl))
2568 if (himl->cMaxImage > iImageCount)
2570 himl->cCurImage = iImageCount;
2571 /* TODO: shrink the bitmap when cMaxImage-cCurImage>cGrow ? */
2575 nNewCount = iImageCount + himl->cGrow;
2576 nCopyCount = min(himl->cCurImage, iImageCount);
2578 hdcBitmap = CreateCompatibleDC (0);
2580 hbmNewBitmap = ImageList_CreateImage(hdcBitmap, himl, nNewCount);
2582 if (hbmNewBitmap != 0)
2584 hbmOld = SelectObject (hdcBitmap, hbmNewBitmap);
2585 imagelist_copy_images( himl, himl->hdcImage, hdcBitmap, 0, nCopyCount, 0 );
2586 SelectObject (hdcBitmap, hbmOld);
2588 /* FIXME: delete 'empty' image space? */
2590 SelectObject (himl->hdcImage, hbmNewBitmap);
2591 DeleteObject (himl->hbmImage);
2592 himl->hbmImage = hbmNewBitmap;
2595 ERR("Could not create new image bitmap !\n");
2600 imagelist_get_bitmap_size( himl, nNewCount, &sz );
2601 hbmNewBitmap = CreateBitmap (sz.cx, sz.cy, 1, 1, NULL);
2602 if (hbmNewBitmap != 0)
2604 hbmOld = SelectObject (hdcBitmap, hbmNewBitmap);
2605 imagelist_copy_images( himl, himl->hdcMask, hdcBitmap, 0, nCopyCount, 0 );
2606 SelectObject (hdcBitmap, hbmOld);
2608 /* FIXME: delete 'empty' image space? */
2610 SelectObject (himl->hdcMask, hbmNewBitmap);
2611 DeleteObject (himl->hbmMask);
2612 himl->hbmMask = hbmNewBitmap;
2615 ERR("Could not create new mask bitmap!\n");
2618 DeleteDC (hdcBitmap);
2620 /* Update max image count and current image count */
2621 himl->cMaxImage = nNewCount;
2622 himl->cCurImage = iImageCount;
2628 /*************************************************************************
2629 * ImageList_SetOverlayImage [COMCTL32.@]
2631 * Assigns an overlay mask index to an existing image in an image list.
2634 * himl [I] handle to image list
2635 * iImage [I] image index
2636 * iOverlay [I] overlay mask index
2644 ImageList_SetOverlayImage (HIMAGELIST himl, INT iImage, INT iOverlay)
2646 if (!is_valid(himl))
2648 if ((iOverlay < 1) || (iOverlay > MAX_OVERLAYIMAGE))
2650 if ((iImage!=-1) && ((iImage < 0) || (iImage > himl->cCurImage)))
2652 himl->nOvlIdx[iOverlay - 1] = iImage;
2658 /* helper for ImageList_Write - write bitmap to pstm
2659 * currently everything is written as 24 bit RGB, except masks
2662 _write_bitmap(HBITMAP hBitmap, LPSTREAM pstm)
2664 LPBITMAPFILEHEADER bmfh;
2665 LPBITMAPINFOHEADER bmih;
2666 LPBYTE data = NULL, lpBits;
2668 INT bitCount, sizeImage, offBits, totalSize;
2670 BOOL result = FALSE;
2672 if (!GetObjectW(hBitmap, sizeof(BITMAP), &bm))
2675 bitCount = bm.bmBitsPixel == 1 ? 1 : 24;
2676 sizeImage = DIB_GetDIBImageBytes(bm.bmWidth, bm.bmHeight, bitCount);
2678 totalSize = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);
2680 totalSize += (1 << bitCount) * sizeof(RGBQUAD);
2681 offBits = totalSize;
2682 totalSize += sizeImage;
2684 data = Alloc(totalSize);
2685 bmfh = (LPBITMAPFILEHEADER)data;
2686 bmih = (LPBITMAPINFOHEADER)(data + sizeof(BITMAPFILEHEADER));
2687 lpBits = data + offBits;
2689 /* setup BITMAPFILEHEADER */
2690 bmfh->bfType = (('M' << 8) | 'B');
2691 bmfh->bfSize = offBits;
2692 bmfh->bfReserved1 = 0;
2693 bmfh->bfReserved2 = 0;
2694 bmfh->bfOffBits = offBits;
2696 /* setup BITMAPINFOHEADER */
2697 bmih->biSize = sizeof(BITMAPINFOHEADER);
2698 bmih->biWidth = bm.bmWidth;
2699 bmih->biHeight = bm.bmHeight;
2701 bmih->biBitCount = bitCount;
2702 bmih->biCompression = BI_RGB;
2703 bmih->biSizeImage = sizeImage;
2704 bmih->biXPelsPerMeter = 0;
2705 bmih->biYPelsPerMeter = 0;
2706 bmih->biClrUsed = 0;
2707 bmih->biClrImportant = 0;
2710 result = GetDIBits(xdc, hBitmap, 0, bm.bmHeight, lpBits, (BITMAPINFO *)bmih, DIB_RGB_COLORS) == bm.bmHeight;
2715 TRACE("width %u, height %u, planes %u, bpp %u\n",
2716 bmih->biWidth, bmih->biHeight,
2717 bmih->biPlanes, bmih->biBitCount);
2721 LPBITMAPINFO inf = (LPBITMAPINFO)bmih;
2722 inf->bmiColors[0].rgbRed = inf->bmiColors[0].rgbGreen = inf->bmiColors[0].rgbBlue = 0;
2723 inf->bmiColors[1].rgbRed = inf->bmiColors[1].rgbGreen = inf->bmiColors[1].rgbBlue = 0xff;
2726 if(FAILED(IStream_Write(pstm, data, totalSize, NULL)))
2738 /*************************************************************************
2739 * ImageList_Write [COMCTL32.@]
2741 * Writes an image list to a stream.
2744 * himl [I] handle to image list
2745 * pstm [O] Pointer to a stream.
2756 ImageList_Write (HIMAGELIST himl, LPSTREAM pstm)
2761 TRACE("%p %p\n", himl, pstm);
2763 if (!is_valid(himl))
2766 ilHead.usMagic = (('L' << 8) | 'I');
2767 ilHead.usVersion = 0x101;
2768 ilHead.cCurImage = himl->cCurImage;
2769 ilHead.cMaxImage = himl->cMaxImage;
2770 ilHead.cGrow = himl->cGrow;
2771 ilHead.cx = himl->cx;
2772 ilHead.cy = himl->cy;
2773 ilHead.bkcolor = himl->clrBk;
2774 ilHead.flags = himl->flags;
2775 for(i = 0; i < 4; i++) {
2776 ilHead.ovls[i] = himl->nOvlIdx[i];
2779 TRACE("cx %u, cy %u, flags 0x04%x, cCurImage %u, cMaxImage %u\n",
2780 ilHead.cx, ilHead.cy, ilHead.flags, ilHead.cCurImage, ilHead.cMaxImage);
2782 if(FAILED(IStream_Write(pstm, &ilHead, sizeof(ILHEAD), NULL)))
2785 /* write the bitmap */
2786 if(!_write_bitmap(himl->hbmImage, pstm))
2789 /* write the mask if we have one */
2790 if(himl->flags & ILC_MASK) {
2791 if(!_write_bitmap(himl->hbmMask, pstm))
2799 static HBITMAP ImageList_CreateImage(HDC hdc, HIMAGELIST himl, UINT count)
2801 HBITMAP hbmNewBitmap;
2802 UINT ilc = (himl->flags & 0xFE);
2805 imagelist_get_bitmap_size( himl, count, &sz );
2807 if ((ilc >= ILC_COLOR4 && ilc <= ILC_COLOR32) || ilc == ILC_COLOR)
2812 TRACE("Creating DIBSection %d x %d, %d Bits per Pixel\n",
2813 sz.cx, sz.cy, himl->uBitsPixel);
2815 if (himl->uBitsPixel <= ILC_COLOR8)
2821 colors = 1 << himl->uBitsPixel;
2822 bmi = Alloc(sizeof(BITMAPINFOHEADER) +
2823 sizeof(PALETTEENTRY) * colors);
2825 pal = (LPPALETTEENTRY)bmi->bmiColors;
2826 GetPaletteEntries(GetStockObject(DEFAULT_PALETTE), 0, colors, pal);
2828 /* Swap colors returned by GetPaletteEntries so we can use them for
2829 * CreateDIBSection call. */
2830 for (i = 0; i < colors; i++)
2832 temp = pal[i].peBlue;
2833 bmi->bmiColors[i].rgbRed = pal[i].peRed;
2834 bmi->bmiColors[i].rgbBlue = temp;
2839 bmi = Alloc(sizeof(BITMAPINFOHEADER));
2842 bmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
2843 bmi->bmiHeader.biWidth = sz.cx;
2844 bmi->bmiHeader.biHeight = sz.cy;
2845 bmi->bmiHeader.biPlanes = 1;
2846 bmi->bmiHeader.biBitCount = himl->uBitsPixel;
2847 bmi->bmiHeader.biCompression = BI_RGB;
2848 bmi->bmiHeader.biSizeImage = 0;
2849 bmi->bmiHeader.biXPelsPerMeter = 0;
2850 bmi->bmiHeader.biYPelsPerMeter = 0;
2851 bmi->bmiHeader.biClrUsed = 0;
2852 bmi->bmiHeader.biClrImportant = 0;
2854 hbmNewBitmap = CreateDIBSection(hdc, bmi, DIB_RGB_COLORS, &bits, 0, 0);
2858 else /*if (ilc == ILC_COLORDDB)*/
2860 TRACE("Creating Bitmap: %d Bits per Pixel\n", himl->uBitsPixel);
2862 hbmNewBitmap = CreateBitmap (sz.cx, sz.cy, 1, himl->uBitsPixel, NULL);
2864 TRACE("returning %p\n", hbmNewBitmap);
2865 return hbmNewBitmap;
2868 /*************************************************************************
2869 * ImageList_SetColorTable [COMCTL32.@]
2871 * Sets the color table of an image list.
2874 * himl [I] Handle to the image list.
2875 * uStartIndex [I] The first index to set.
2876 * cEntries [I] Number of entries to set.
2877 * prgb [I] New color information for color table for the image list.
2880 * Success: Number of entries in the table that were set.
2884 * ImageList_Create(), SetDIBColorTable()
2888 ImageList_SetColorTable (HIMAGELIST himl, UINT uStartIndex, UINT cEntries, CONST RGBQUAD * prgb)
2890 return SetDIBColorTable(himl->hdcImage, uStartIndex, cEntries, prgb);
2893 /*************************************************************************
2894 * ImageList_CoCreateInstance [COMCTL32.@]
2896 * Creates a new imagelist instance and returns an interface pointer to it.
2899 * rclsid [I] A reference to the CLSID (CLSID_ImageList).
2900 * punkOuter [I] Pointer to IUnknown interface for aggregation, if desired
2901 * riid [I] Identifier of the requested interface.
2902 * ppv [O] Returns the address of the pointer requested, or NULL.
2906 * Failure: Error value.
2909 ImageList_CoCreateInstance (REFCLSID rclsid, const IUnknown *punkOuter, REFIID riid, void **ppv)
2911 TRACE("(%s,%p,%s,%p)\n", debugstr_guid(rclsid), punkOuter, debugstr_guid(riid), ppv);
2913 if (!IsEqualCLSID(&CLSID_ImageList, rclsid))
2914 return E_NOINTERFACE;
2916 return ImageListImpl_CreateInstance(punkOuter, riid, ppv);
2920 /*************************************************************************
2921 * IImageList implementation
2924 static HRESULT WINAPI ImageListImpl_QueryInterface(IImageList *iface,
2925 REFIID iid, void **ppv)
2927 HIMAGELIST This = (HIMAGELIST) iface;
2928 TRACE("(%p,%s,%p)\n", iface, debugstr_guid(iid), ppv);
2930 if (!ppv) return E_INVALIDARG;
2932 if (IsEqualIID(&IID_IUnknown, iid) || IsEqualIID(&IID_IImageList, iid))
2937 return E_NOINTERFACE;
2940 IUnknown_AddRef((IUnknown*)*ppv);
2944 static ULONG WINAPI ImageListImpl_AddRef(IImageList *iface)
2946 HIMAGELIST This = (HIMAGELIST) iface;
2947 ULONG ref = InterlockedIncrement(&This->ref);
2949 TRACE("(%p) refcount=%u\n", iface, ref);
2953 static ULONG WINAPI ImageListImpl_Release(IImageList *iface)
2955 HIMAGELIST This = (HIMAGELIST) iface;
2956 ULONG ref = InterlockedDecrement(&This->ref);
2958 TRACE("(%p) refcount=%u\n", iface, ref);
2962 /* delete image bitmaps */
2963 if (This->hbmImage) DeleteObject (This->hbmImage);
2964 if (This->hbmMask) DeleteObject (This->hbmMask);
2966 /* delete image & mask DCs */
2967 if (This->hdcImage) DeleteDC (This->hdcImage);
2968 if (This->hdcMask) DeleteDC (This->hdcMask);
2970 /* delete blending brushes */
2971 if (This->hbrBlend25) DeleteObject (This->hbrBlend25);
2972 if (This->hbrBlend50) DeleteObject (This->hbrBlend50);
2974 This->lpVtbl = NULL;
2975 HeapFree(GetProcessHeap(), 0, This);
2981 static HRESULT WINAPI ImageListImpl_Add(IImageList *iface, HBITMAP hbmImage,
2982 HBITMAP hbmMask, int *pi)
2984 HIMAGELIST This = (HIMAGELIST) iface;
2990 ret = ImageList_Add(This, hbmImage, hbmMask);
2999 static HRESULT WINAPI ImageListImpl_ReplaceIcon(IImageList *iface, int i,
3000 HICON hicon, int *pi)
3002 HIMAGELIST This = (HIMAGELIST) iface;
3008 ret = ImageList_ReplaceIcon(This, i, hicon);
3017 static HRESULT WINAPI ImageListImpl_SetOverlayImage(IImageList *iface,
3018 int iImage, int iOverlay)
3020 return ImageList_SetOverlayImage((HIMAGELIST) iface, iImage, iOverlay)
3024 static HRESULT WINAPI ImageListImpl_Replace(IImageList *iface, int i,
3025 HBITMAP hbmImage, HBITMAP hbmMask)
3027 return ImageList_Replace((HIMAGELIST) iface, i, hbmImage, hbmMask) ? S_OK :
3031 static HRESULT WINAPI ImageListImpl_AddMasked(IImageList *iface, HBITMAP hbmImage,
3032 COLORREF crMask, int *pi)
3034 HIMAGELIST This = (HIMAGELIST) iface;
3040 ret = ImageList_AddMasked(This, hbmImage, crMask);
3049 static HRESULT WINAPI ImageListImpl_Draw(IImageList *iface,
3050 IMAGELISTDRAWPARAMS *pimldp)
3052 HIMAGELIST This = (HIMAGELIST) iface;
3053 HIMAGELIST old_himl = 0;
3059 /* As far as I can tell, Windows simply ignores the contents of pimldp->himl
3060 so we shall simulate the same */
3061 old_himl = pimldp->himl;
3062 pimldp->himl = This;
3064 ret = ImageList_DrawIndirect(pimldp);
3066 pimldp->himl = old_himl;
3067 return ret ? S_OK : E_FAIL;
3070 static HRESULT WINAPI ImageListImpl_Remove(IImageList *iface, int i)
3072 return (ImageList_Remove((HIMAGELIST) iface, i) == 0) ? E_FAIL : S_OK;
3075 static HRESULT WINAPI ImageListImpl_GetIcon(IImageList *iface, int i, UINT flags,
3083 hIcon = ImageList_GetIcon((HIMAGELIST) iface, i, flags);
3092 static HRESULT WINAPI ImageListImpl_GetImageInfo(IImageList *iface, int i,
3093 IMAGEINFO *pImageInfo)
3095 return ImageList_GetImageInfo((HIMAGELIST) iface, i, pImageInfo) ? S_OK : E_FAIL;
3098 static HRESULT WINAPI ImageListImpl_Copy(IImageList *iface, int iDst,
3099 IUnknown *punkSrc, int iSrc, UINT uFlags)
3101 HIMAGELIST This = (HIMAGELIST) iface;
3102 IImageList *src = NULL;
3108 /* TODO: Add test for IID_ImageList2 too */
3109 if (FAILED(IImageList_QueryInterface(punkSrc, &IID_IImageList,
3113 if (ImageList_Copy(This, iDst, (HIMAGELIST) src, iSrc, uFlags))
3118 IImageList_Release(src);
3122 static HRESULT WINAPI ImageListImpl_Merge(IImageList *iface, int i1,
3123 IUnknown *punk2, int i2, int dx, int dy, REFIID riid, PVOID *ppv)
3125 HIMAGELIST This = (HIMAGELIST) iface;
3126 IImageList *iml2 = NULL;
3128 HRESULT ret = E_FAIL;
3133 /* TODO: Add test for IID_ImageList2 too */
3134 if (FAILED(IImageList_QueryInterface(punk2, &IID_IImageList,
3138 hNew = ImageList_Merge(This, i1, (HIMAGELIST) iml2, i2, dx, dy);
3140 /* Get the interface for the new image list */
3142 ret = HIMAGELIST_QueryInterface(hNew, riid, ppv);
3144 IImageList_Release(iml2);
3148 static HRESULT WINAPI ImageListImpl_Clone(IImageList *iface, REFIID riid,
3151 HIMAGELIST This = (HIMAGELIST) iface;
3153 HRESULT ret = E_FAIL;
3158 hNew = ImageList_Duplicate(This);
3160 /* Get the interface for the new image list */
3162 ret = HIMAGELIST_QueryInterface(hNew, riid, ppv);
3167 static HRESULT WINAPI ImageListImpl_GetImageRect(IImageList *iface, int i,
3170 HIMAGELIST This = (HIMAGELIST) iface;
3176 if (!ImageList_GetImageInfo(This, i, &info))
3179 return CopyRect(prc, &info.rcImage) ? S_OK : E_FAIL;
3182 static HRESULT WINAPI ImageListImpl_GetIconSize(IImageList *iface, int *cx,
3185 HIMAGELIST This = (HIMAGELIST) iface;
3187 return ImageList_GetIconSize(This, cx, cy) ? S_OK : E_FAIL;
3190 static HRESULT WINAPI ImageListImpl_SetIconSize(IImageList *iface, int cx,
3193 return ImageList_SetIconSize((HIMAGELIST) iface, cx, cy) ? S_OK : E_FAIL;
3196 static HRESULT WINAPI ImageListImpl_GetImageCount(IImageList *iface, int *pi)
3201 *pi = ImageList_GetImageCount((HIMAGELIST) iface);
3205 static HRESULT WINAPI ImageListImpl_SetImageCount(IImageList *iface,
3208 return ImageList_SetImageCount((HIMAGELIST) iface, uNewCount) ? S_OK : E_FAIL;
3211 static HRESULT WINAPI ImageListImpl_SetBkColor(IImageList *iface, COLORREF clrBk,
3217 *pclr = ImageList_SetBkColor((HIMAGELIST) iface, clrBk);
3218 return *pclr == CLR_NONE ? E_FAIL : S_OK;
3221 static HRESULT WINAPI ImageListImpl_GetBkColor(IImageList *iface, COLORREF *pclr)
3226 *pclr = ImageList_GetBkColor((HIMAGELIST) iface);
3230 static HRESULT WINAPI ImageListImpl_BeginDrag(IImageList *iface, int iTrack,
3231 int dxHotspot, int dyHotspot)
3233 return ImageList_BeginDrag((HIMAGELIST) iface, iTrack, dxHotspot, dyHotspot) ? S_OK : E_FAIL;
3236 static HRESULT WINAPI ImageListImpl_EndDrag(IImageList *iface)
3238 ImageList_EndDrag();
3242 static HRESULT WINAPI ImageListImpl_DragEnter(IImageList *iface, HWND hwndLock,
3245 return ImageList_DragEnter(hwndLock, x, y) ? S_OK : E_FAIL;
3248 static HRESULT WINAPI ImageListImpl_DragLeave(IImageList *iface, HWND hwndLock)
3250 return ImageList_DragLeave(hwndLock) ? S_OK : E_FAIL;
3253 static HRESULT WINAPI ImageListImpl_DragMove(IImageList *iface, int x, int y)
3255 return ImageList_DragMove(x, y) ? S_OK : E_FAIL;
3258 static HRESULT WINAPI ImageListImpl_SetDragCursorImage(IImageList *iface,
3259 IUnknown *punk, int iDrag, int dxHotspot, int dyHotspot)
3261 IImageList *iml2 = NULL;
3267 /* TODO: Add test for IID_ImageList2 too */
3268 if (FAILED(IImageList_QueryInterface(punk, &IID_IImageList,
3272 ret = ImageList_SetDragCursorImage((HIMAGELIST) iml2, iDrag, dxHotspot,
3275 IImageList_Release(iml2);
3277 return ret ? S_OK : E_FAIL;
3280 static HRESULT WINAPI ImageListImpl_DragShowNolock(IImageList *iface, BOOL fShow)
3282 return ImageList_DragShowNolock(fShow) ? S_OK : E_FAIL;
3285 static HRESULT WINAPI ImageListImpl_GetDragImage(IImageList *iface, POINT *ppt,
3286 POINT *pptHotspot, REFIID riid, PVOID *ppv)
3288 HRESULT ret = E_FAIL;
3294 hNew = ImageList_GetDragImage(ppt, pptHotspot);
3296 /* Get the interface for the new image list */
3298 ret = HIMAGELIST_QueryInterface(hNew, riid, ppv);
3303 static HRESULT WINAPI ImageListImpl_GetItemFlags(IImageList *iface, int i,
3306 FIXME("STUB: %p %d %p\n", iface, i, dwFlags);
3310 static HRESULT WINAPI ImageListImpl_GetOverlayImage(IImageList *iface, int iOverlay,
3313 HIMAGELIST This = (HIMAGELIST) iface;
3316 if ((iOverlay < 0) || (iOverlay > This->cCurImage))
3319 for (i = 0; i < MAX_OVERLAYIMAGE; i++)
3321 if (This->nOvlIdx[i] == iOverlay)
3332 static const IImageListVtbl ImageListImpl_Vtbl = {
3333 ImageListImpl_QueryInterface,
3334 ImageListImpl_AddRef,
3335 ImageListImpl_Release,
3337 ImageListImpl_ReplaceIcon,
3338 ImageListImpl_SetOverlayImage,
3339 ImageListImpl_Replace,
3340 ImageListImpl_AddMasked,
3342 ImageListImpl_Remove,
3343 ImageListImpl_GetIcon,
3344 ImageListImpl_GetImageInfo,
3346 ImageListImpl_Merge,
3347 ImageListImpl_Clone,
3348 ImageListImpl_GetImageRect,
3349 ImageListImpl_GetIconSize,
3350 ImageListImpl_SetIconSize,
3351 ImageListImpl_GetImageCount,
3352 ImageListImpl_SetImageCount,
3353 ImageListImpl_SetBkColor,
3354 ImageListImpl_GetBkColor,
3355 ImageListImpl_BeginDrag,
3356 ImageListImpl_EndDrag,
3357 ImageListImpl_DragEnter,
3358 ImageListImpl_DragLeave,
3359 ImageListImpl_DragMove,
3360 ImageListImpl_SetDragCursorImage,
3361 ImageListImpl_DragShowNolock,
3362 ImageListImpl_GetDragImage,
3363 ImageListImpl_GetItemFlags,
3364 ImageListImpl_GetOverlayImage
3367 static inline BOOL is_valid(HIMAGELIST himl)
3369 return himl && himl->lpVtbl == &ImageListImpl_Vtbl;
3372 /*************************************************************************
3373 * HIMAGELIST_QueryInterface [COMCTL32.@]
3375 * Returns a pointer to an IImageList or IImageList2 object for the given
3379 * himl [I] Image list handle.
3380 * riid [I] Identifier of the requested interface.
3381 * ppv [O] Returns the address of the pointer requested, or NULL.
3385 * Failure: Error value.
3388 HIMAGELIST_QueryInterface (HIMAGELIST himl, REFIID riid, void **ppv)
3390 TRACE("(%p,%s,%p)\n", himl, debugstr_guid(riid), ppv);
3391 return IImageList_QueryInterface((IImageList *) himl, riid, ppv);
3394 static HRESULT ImageListImpl_CreateInstance(const IUnknown *pUnkOuter, REFIID iid, void** ppv)
3399 TRACE("(%p,%s,%p)\n", pUnkOuter, debugstr_guid(iid), ppv);
3403 if (pUnkOuter) return CLASS_E_NOAGGREGATION;
3405 This = HeapAlloc(GetProcessHeap(), 0, sizeof(struct _IMAGELIST));
3406 if (!This) return E_OUTOFMEMORY;
3408 ZeroMemory(This, sizeof(struct _IMAGELIST));
3410 This->lpVtbl = &ImageListImpl_Vtbl;
3413 ret = IUnknown_QueryInterface((IUnknown*)This, iid, ppv);
3414 IUnknown_Release((IUnknown*)This);