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, UINT width);
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, UINT cx, SIZE *sz )
112 sz->cx = 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, INT cx, INT cy)
160 HBITMAP hbmNewBitmap, hbmNull;
164 if ((himl->cCurImage + nImageCount <= himl->cMaxImage)
168 if (cx == 0) cx = himl->cx;
169 nNewCount = himl->cCurImage + nImageCount + himl->cGrow;
171 imagelist_get_bitmap_size(himl, nNewCount, cx, &sz);
173 TRACE("Create expanded bitmaps : himl=%p x=%d y=%d count=%d\n", himl, sz.cx, cy, nNewCount);
174 hdcBitmap = CreateCompatibleDC (0);
176 hbmNewBitmap = ImageList_CreateImage(hdcBitmap, himl, nNewCount, cx);
178 if (hbmNewBitmap == 0)
179 ERR("creating new image bitmap (x=%d y=%d)!\n", sz.cx, 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 nImageCount = bmp.bmWidth / himl->cx;
250 IMAGELIST_InternalExpandBitmaps (himl, nImageCount, bmp.bmWidth, bmp.bmHeight);
252 hdcBitmap = CreateCompatibleDC(0);
254 hOldBitmap = SelectObject(hdcBitmap, hbmImage);
256 for (i=0; i<nImageCount; i++)
258 imagelist_point_from_index( himl, himl->cCurImage + i, &pt );
260 /* Copy result to the imagelist
262 BitBlt( himl->hdcImage, pt.x, pt.y, himl->cx, bmp.bmHeight,
263 hdcBitmap, i*himl->cx, 0, SRCCOPY );
268 hdcTemp = CreateCompatibleDC(0);
269 hOldBitmapTemp = SelectObject(hdcTemp, hbmMask);
271 BitBlt( himl->hdcMask, pt.x, pt.y, himl->cx, bmp.bmHeight,
272 hdcTemp, i*himl->cx, 0, SRCCOPY );
274 SelectObject(hdcTemp, hOldBitmapTemp);
277 /* Remove the background from the image
279 BitBlt( himl->hdcImage, pt.x, pt.y, himl->cx, bmp.bmHeight,
280 himl->hdcMask, pt.x, pt.y, 0x220326 ); /* NOTSRCAND */
283 SelectObject(hdcBitmap, hOldBitmap);
286 nFirstIndex = himl->cCurImage;
287 himl->cCurImage += nImageCount;
293 /*************************************************************************
294 * ImageList_AddIcon [COMCTL32.@]
296 * Adds an icon to an image list.
299 * himl [I] handle to image list
300 * hIcon [I] handle to icon
303 * Success: index of the new image
306 #undef ImageList_AddIcon
307 INT WINAPI ImageList_AddIcon (HIMAGELIST himl, HICON hIcon)
309 return ImageList_ReplaceIcon (himl, -1, hIcon);
313 /*************************************************************************
314 * ImageList_AddMasked [COMCTL32.@]
316 * Adds an image or images to an image list and creates a mask from the
317 * specified bitmap using the mask color.
320 * himl [I] handle to image list.
321 * hBitmap [I] handle to bitmap
322 * clrMask [I] mask color.
325 * Success: Index of the first new image.
330 ImageList_AddMasked (HIMAGELIST himl, HBITMAP hBitmap, COLORREF clrMask)
332 HDC hdcMask, hdcBitmap;
333 INT i, nIndex, nImageCount;
336 HBITMAP hMaskBitmap=0;
340 TRACE("himl=%p hbitmap=%p clrmask=%x\n", himl, hBitmap, clrMask);
344 if (!GetObjectW(hBitmap, sizeof(BITMAP), &bmp))
348 nImageCount = bmp.bmWidth / himl->cx;
352 IMAGELIST_InternalExpandBitmaps (himl, nImageCount, bmp.bmWidth, bmp.bmHeight);
354 nIndex = himl->cCurImage;
355 himl->cCurImage += nImageCount;
357 hdcBitmap = CreateCompatibleDC(0);
358 hOldBitmap = SelectObject(hdcBitmap, hBitmap);
360 /* Create a temp Mask so we can remove the background of the Image */
361 hdcMask = CreateCompatibleDC(0);
362 hMaskBitmap = CreateBitmap(bmp.bmWidth, bmp.bmHeight, 1, 1, NULL);
363 SelectObject(hdcMask, hMaskBitmap);
365 /* create monochrome image to the mask bitmap */
366 bkColor = (clrMask != CLR_DEFAULT) ? clrMask : GetPixel (hdcBitmap, 0, 0);
367 SetBkColor (hdcBitmap, bkColor);
368 BitBlt (hdcMask, 0, 0, bmp.bmWidth, bmp.bmHeight, hdcBitmap, 0, 0, SRCCOPY);
370 SetBkColor(hdcBitmap, RGB(255,255,255));
373 * Remove the background from the image
375 * WINDOWS BUG ALERT!!!!!!
376 * The statement below should not be done in common practice
377 * but this is how ImageList_AddMasked works in Windows.
378 * It overwrites the original bitmap passed, this was discovered
379 * by using the same bitmap to iterate the different styles
380 * on windows where it failed (BUT ImageList_Add is OK)
381 * This is here in case some apps rely on this bug
383 * Blt mode 0x220326 is NOTSRCAND
385 BitBlt(hdcBitmap, 0, 0, bmp.bmWidth, bmp.bmHeight, hdcMask, 0, 0, 0x220326);
387 /* Copy result to the imagelist */
388 for (i=0; i<nImageCount; i++)
390 imagelist_point_from_index( himl, nIndex + i, &pt );
391 BitBlt(himl->hdcImage, pt.x, pt.y, himl->cx, bmp.bmHeight,
392 hdcBitmap, i*himl->cx, 0, SRCCOPY);
393 BitBlt(himl->hdcMask, pt.x, pt.y, himl->cx, bmp.bmHeight,
394 hdcMask, i*himl->cx, 0, SRCCOPY);
398 SelectObject(hdcBitmap, hOldBitmap);
400 DeleteObject(hMaskBitmap);
407 /*************************************************************************
408 * ImageList_BeginDrag [COMCTL32.@]
410 * Creates a temporary image list that contains one image. It will be used
414 * himlTrack [I] handle to the source image list
415 * iTrack [I] index of the drag image in the source image list
416 * dxHotspot [I] X position of the hot spot of the drag image
417 * dyHotspot [I] Y position of the hot spot of the drag image
425 ImageList_BeginDrag (HIMAGELIST himlTrack, INT iTrack,
426 INT dxHotspot, INT dyHotspot)
430 TRACE("(himlTrack=%p iTrack=%d dx=%d dy=%d)\n", himlTrack, iTrack,
431 dxHotspot, dyHotspot);
433 if (!is_valid(himlTrack))
436 if (InternalDrag.himl)
437 ImageList_EndDrag ();
442 InternalDrag.himl = ImageList_Create (cx, cy, himlTrack->flags, 1, 1);
443 if (InternalDrag.himl == NULL) {
444 WARN("Error creating drag image list!\n");
448 InternalDrag.dxHotspot = dxHotspot;
449 InternalDrag.dyHotspot = dyHotspot;
452 BitBlt (InternalDrag.himl->hdcImage, 0, 0, cx, cy, himlTrack->hdcImage, iTrack * cx, 0, SRCCOPY);
455 BitBlt (InternalDrag.himl->hdcMask, 0, 0, cx, cy, himlTrack->hdcMask, iTrack * cx, 0, SRCCOPY);
457 InternalDrag.himl->cCurImage = 1;
463 /*************************************************************************
464 * ImageList_Copy [COMCTL32.@]
466 * Copies an image of the source image list to an image of the
467 * destination image list. Images can be copied or swapped.
470 * himlDst [I] handle to the destination image list
471 * iDst [I] destination image index.
472 * himlSrc [I] handle to the source image list
473 * iSrc [I] source image index
474 * uFlags [I] flags for the copy operation
481 * Copying from one image list to another is possible. The original
482 * implementation just copies or swaps within one image list.
483 * Could this feature become a bug??? ;-)
487 ImageList_Copy (HIMAGELIST himlDst, INT iDst, HIMAGELIST himlSrc,
488 INT iSrc, UINT uFlags)
492 TRACE("himlDst=%p iDst=%d himlSrc=%p iSrc=%d\n", himlDst, iDst, himlSrc, iSrc);
494 if (!is_valid(himlSrc) || !is_valid(himlDst))
496 if ((iDst < 0) || (iDst >= himlDst->cCurImage))
498 if ((iSrc < 0) || (iSrc >= himlSrc->cCurImage))
501 imagelist_point_from_index( himlDst, iDst, &ptDst );
502 imagelist_point_from_index( himlSrc, iSrc, &ptSrc );
504 if (uFlags & ILCF_SWAP) {
507 HBITMAP hbmTempImage, hbmTempMask;
509 hdcBmp = CreateCompatibleDC (0);
511 /* create temporary bitmaps */
512 hbmTempImage = CreateBitmap (himlSrc->cx, himlSrc->cy, 1,
513 himlSrc->uBitsPixel, NULL);
514 hbmTempMask = CreateBitmap (himlSrc->cx, himlSrc->cy, 1,
517 /* copy (and stretch) destination to temporary bitmaps.(save) */
519 SelectObject (hdcBmp, hbmTempImage);
520 StretchBlt (hdcBmp, 0, 0, himlSrc->cx, himlSrc->cy,
521 himlDst->hdcImage, ptDst.x, ptDst.y, himlDst->cx, himlDst->cy,
524 SelectObject (hdcBmp, hbmTempMask);
525 StretchBlt (hdcBmp, 0, 0, himlSrc->cx, himlSrc->cy,
526 himlDst->hdcMask, ptDst.x, ptDst.y, himlDst->cx, himlDst->cy,
529 /* copy (and stretch) source to destination */
531 StretchBlt (himlDst->hdcImage, ptDst.x, ptDst.y, himlDst->cx, himlDst->cy,
532 himlSrc->hdcImage, ptSrc.x, ptSrc.y, himlSrc->cx, himlSrc->cy,
535 StretchBlt (himlDst->hdcMask, ptDst.x, ptDst.y, himlDst->cx, himlDst->cy,
536 himlSrc->hdcMask, ptSrc.x, ptSrc.y, himlSrc->cx, himlSrc->cy,
539 /* copy (without stretching) temporary bitmaps to source (restore) */
541 BitBlt (himlSrc->hdcMask, ptSrc.x, ptSrc.y, himlSrc->cx, himlSrc->cy,
542 hdcBmp, 0, 0, SRCCOPY);
545 BitBlt (himlSrc->hdcImage, ptSrc.x, ptSrc.y, himlSrc->cx, himlSrc->cy,
546 hdcBmp, 0, 0, SRCCOPY);
547 /* delete temporary bitmaps */
548 DeleteObject (hbmTempMask);
549 DeleteObject (hbmTempImage);
554 StretchBlt (himlDst->hdcImage, ptDst.x, ptDst.y, himlDst->cx, himlDst->cy,
555 himlSrc->hdcImage, ptSrc.x, ptSrc.y, himlSrc->cx, himlSrc->cy,
559 StretchBlt (himlDst->hdcMask, ptDst.x, ptDst.y, himlDst->cx, himlDst->cy,
560 himlSrc->hdcMask, ptSrc.x, ptSrc.y, himlSrc->cx, himlSrc->cy,
568 /*************************************************************************
569 * ImageList_Create [COMCTL32.@]
571 * Creates a new image list.
574 * cx [I] image height
576 * flags [I] creation flags
577 * cInitial [I] initial number of images in the image list
578 * cGrow [I] number of images by which image list grows
581 * Success: Handle to the created image list
585 ImageList_Create (INT cx, INT cy, UINT flags,
586 INT cInitial, INT cGrow)
591 UINT ilc = (flags & 0xFE);
592 static const WORD aBitBlend25[] =
593 {0xAA, 0x00, 0x55, 0x00, 0xAA, 0x00, 0x55, 0x00};
595 static const WORD aBitBlend50[] =
596 {0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA};
598 TRACE("(%d %d 0x%x %d %d)\n", cx, cy, flags, cInitial, cGrow);
600 /* Create the IImageList interface for the image list */
601 if (!SUCCEEDED(ImageListImpl_CreateInstance(NULL, &IID_IImageList, (void **) &himl)))
604 cGrow = (cGrow < 4) ? 4 : (cGrow + 3) & ~3;
609 himl->cMaxImage = cInitial + 1;
610 himl->cInitial = cInitial;
612 himl->clrFg = CLR_DEFAULT;
613 himl->clrBk = CLR_NONE;
615 /* initialize overlay mask indices */
616 for (nCount = 0; nCount < MAX_OVERLAYIMAGE; nCount++)
617 himl->nOvlIdx[nCount] = -1;
619 /* Create Image & Mask DCs */
620 himl->hdcImage = CreateCompatibleDC (0);
623 if (himl->flags & ILC_MASK){
624 himl->hdcMask = CreateCompatibleDC(0);
629 /* Default to ILC_COLOR4 if none of the ILC_COLOR* flags are specified */
630 if (ilc == ILC_COLOR)
633 if (ilc >= ILC_COLOR4 && ilc <= ILC_COLOR32)
634 himl->uBitsPixel = ilc;
636 himl->uBitsPixel = (UINT)GetDeviceCaps (himl->hdcImage, BITSPIXEL);
638 if (himl->cMaxImage > 0) {
639 himl->hbmImage = ImageList_CreateImage(himl->hdcImage, himl, himl->cMaxImage, cx);
640 SelectObject(himl->hdcImage, himl->hbmImage);
644 if ((himl->cMaxImage > 0) && (himl->flags & ILC_MASK)) {
647 imagelist_get_bitmap_size(himl, himl->cMaxImage, himl->cx, &sz);
648 himl->hbmMask = CreateBitmap (sz.cx, sz.cy, 1, 1, NULL);
649 if (himl->hbmMask == 0) {
650 ERR("Error creating mask bitmap!\n");
653 SelectObject(himl->hdcMask, himl->hbmMask);
658 /* create blending brushes */
659 hbmTemp = CreateBitmap (8, 8, 1, 1, aBitBlend25);
660 himl->hbrBlend25 = CreatePatternBrush (hbmTemp);
661 DeleteObject (hbmTemp);
663 hbmTemp = CreateBitmap (8, 8, 1, 1, aBitBlend50);
664 himl->hbrBlend50 = CreatePatternBrush (hbmTemp);
665 DeleteObject (hbmTemp);
667 TRACE("created imagelist %p\n", himl);
671 ImageList_Destroy(himl);
676 /*************************************************************************
677 * ImageList_Destroy [COMCTL32.@]
679 * Destroys an image list.
682 * himl [I] handle to image list
690 ImageList_Destroy (HIMAGELIST himl)
695 IImageList_Release((IImageList *) himl);
700 /*************************************************************************
701 * ImageList_DragEnter [COMCTL32.@]
703 * Locks window update and displays the drag image at the given position.
706 * hwndLock [I] handle of the window that owns the drag image.
707 * x [I] X position of the drag image.
708 * y [I] Y position of the drag image.
715 * The position of the drag image is relative to the window, not
720 ImageList_DragEnter (HWND hwndLock, INT x, INT y)
722 TRACE("(hwnd=%p x=%d y=%d)\n", hwndLock, x, y);
724 if (!is_valid(InternalDrag.himl))
728 InternalDrag.hwnd = hwndLock;
730 InternalDrag.hwnd = GetDesktopWindow ();
735 /* draw the drag image and save the background */
736 if (!ImageList_DragShowNolock(TRUE)) {
744 /*************************************************************************
745 * ImageList_DragLeave [COMCTL32.@]
747 * Unlocks window update and hides the drag image.
750 * hwndLock [I] handle of the window that owns the drag image.
758 ImageList_DragLeave (HWND hwndLock)
760 /* As we don't save drag info in the window this can lead to problems if
761 an app does not supply the same window as DragEnter */
763 InternalDrag.hwnd = hwndLock;
765 InternalDrag.hwnd = GetDesktopWindow (); */
767 hwndLock = GetDesktopWindow();
768 if(InternalDrag.hwnd != hwndLock)
769 FIXME("DragLeave hWnd != DragEnter hWnd\n");
771 ImageList_DragShowNolock (FALSE);
777 /*************************************************************************
778 * ImageList_InternalDragDraw [Internal]
780 * Draws the drag image.
783 * hdc [I] device context to draw into.
784 * x [I] X position of the drag image.
785 * y [I] Y position of the drag image.
792 * The position of the drag image is relative to the window, not
798 ImageList_InternalDragDraw (HDC hdc, INT x, INT y)
800 IMAGELISTDRAWPARAMS imldp;
802 ZeroMemory (&imldp, sizeof(imldp));
803 imldp.cbSize = sizeof(imldp);
804 imldp.himl = InternalDrag.himl;
809 imldp.rgbBk = CLR_DEFAULT;
810 imldp.rgbFg = CLR_DEFAULT;
811 imldp.fStyle = ILD_NORMAL;
812 imldp.fState = ILS_ALPHA;
815 /* FIXME: instead of using the alpha blending, we should
816 * create a 50% mask, and draw it semitransparantly that way */
817 ImageList_DrawIndirect (&imldp);
820 /*************************************************************************
821 * ImageList_DragMove [COMCTL32.@]
823 * Moves the drag image.
826 * x [I] X position of the drag image.
827 * y [I] Y position of the drag image.
834 * The position of the drag image is relative to the window, not
838 * The drag image should be drawn semitransparent.
842 ImageList_DragMove (INT x, INT y)
844 TRACE("(x=%d y=%d)\n", x, y);
846 if (!is_valid(InternalDrag.himl))
849 /* draw/update the drag image */
850 if (InternalDrag.bShow) {
854 HBITMAP hbmOffScreen;
855 INT origNewX, origNewY;
856 INT origOldX, origOldY;
857 INT origRegX, origRegY;
858 INT sizeRegX, sizeRegY;
861 /* calculate the update region */
862 origNewX = x - InternalDrag.dxHotspot;
863 origNewY = y - InternalDrag.dyHotspot;
864 origOldX = InternalDrag.x - InternalDrag.dxHotspot;
865 origOldY = InternalDrag.y - InternalDrag.dyHotspot;
866 origRegX = min(origNewX, origOldX);
867 origRegY = min(origNewY, origOldY);
868 sizeRegX = InternalDrag.himl->cx + abs(x - InternalDrag.x);
869 sizeRegY = InternalDrag.himl->cy + abs(y - InternalDrag.y);
871 hdcDrag = GetDCEx(InternalDrag.hwnd, 0,
872 DCX_WINDOW | DCX_CACHE | DCX_LOCKWINDOWUPDATE);
873 hdcOffScreen = CreateCompatibleDC(hdcDrag);
874 hdcBg = CreateCompatibleDC(hdcDrag);
876 hbmOffScreen = CreateCompatibleBitmap(hdcDrag, sizeRegX, sizeRegY);
877 SelectObject(hdcOffScreen, hbmOffScreen);
878 SelectObject(hdcBg, InternalDrag.hbmBg);
880 /* get the actual background of the update region */
881 BitBlt(hdcOffScreen, 0, 0, sizeRegX, sizeRegY, hdcDrag,
882 origRegX, origRegY, SRCCOPY);
883 /* erase the old image */
884 BitBlt(hdcOffScreen, origOldX - origRegX, origOldY - origRegY,
885 InternalDrag.himl->cx, InternalDrag.himl->cy, hdcBg, 0, 0,
887 /* save the background */
888 BitBlt(hdcBg, 0, 0, InternalDrag.himl->cx, InternalDrag.himl->cy,
889 hdcOffScreen, origNewX - origRegX, origNewY - origRegY, SRCCOPY);
891 ImageList_InternalDragDraw(hdcOffScreen, origNewX - origRegX,
892 origNewY - origRegY);
893 /* draw the update region to the screen */
894 BitBlt(hdcDrag, origRegX, origRegY, sizeRegX, sizeRegY,
895 hdcOffScreen, 0, 0, SRCCOPY);
898 DeleteDC(hdcOffScreen);
899 DeleteObject(hbmOffScreen);
900 ReleaseDC(InternalDrag.hwnd, hdcDrag);
903 /* update the image position */
911 /*************************************************************************
912 * ImageList_DragShowNolock [COMCTL32.@]
914 * Shows or hides the drag image.
917 * bShow [I] TRUE shows the drag image, FALSE hides it.
924 * The drag image should be drawn semitransparent.
928 ImageList_DragShowNolock (BOOL bShow)
934 if (!is_valid(InternalDrag.himl))
937 TRACE("bShow=0x%X!\n", bShow);
939 /* DragImage is already visible/hidden */
940 if ((InternalDrag.bShow && bShow) || (!InternalDrag.bShow && !bShow)) {
944 /* position of the origin of the DragImage */
945 x = InternalDrag.x - InternalDrag.dxHotspot;
946 y = InternalDrag.y - InternalDrag.dyHotspot;
948 hdcDrag = GetDCEx (InternalDrag.hwnd, 0,
949 DCX_WINDOW | DCX_CACHE | DCX_LOCKWINDOWUPDATE);
954 hdcBg = CreateCompatibleDC(hdcDrag);
955 if (!InternalDrag.hbmBg) {
956 InternalDrag.hbmBg = CreateCompatibleBitmap(hdcDrag,
957 InternalDrag.himl->cx, InternalDrag.himl->cy);
959 SelectObject(hdcBg, InternalDrag.hbmBg);
962 /* save the background */
963 BitBlt(hdcBg, 0, 0, InternalDrag.himl->cx, InternalDrag.himl->cy,
964 hdcDrag, x, y, SRCCOPY);
966 ImageList_InternalDragDraw(hdcDrag, x, y);
969 BitBlt(hdcDrag, x, y, InternalDrag.himl->cx, InternalDrag.himl->cy,
970 hdcBg, 0, 0, SRCCOPY);
973 InternalDrag.bShow = !InternalDrag.bShow;
976 ReleaseDC (InternalDrag.hwnd, hdcDrag);
981 /*************************************************************************
982 * ImageList_Draw [COMCTL32.@]
987 * himl [I] handle to image list
989 * hdc [I] handle to device context
992 * fStyle [I] drawing flags
1003 ImageList_Draw (HIMAGELIST himl, INT i, HDC hdc, INT x, INT y, UINT fStyle)
1005 return ImageList_DrawEx (himl, i, hdc, x, y, 0, 0,
1006 CLR_DEFAULT, CLR_DEFAULT, fStyle);
1010 /*************************************************************************
1011 * ImageList_DrawEx [COMCTL32.@]
1013 * Draws an image and allows to use extended drawing features.
1016 * himl [I] handle to image list
1018 * hdc [I] handle to device context
1023 * rgbBk [I] background color
1024 * rgbFg [I] foreground color
1025 * fStyle [I] drawing flags
1032 * Calls ImageList_DrawIndirect.
1035 * ImageList_DrawIndirect.
1039 ImageList_DrawEx (HIMAGELIST himl, INT i, HDC hdc, INT x, INT y,
1040 INT dx, INT dy, COLORREF rgbBk, COLORREF rgbFg,
1043 IMAGELISTDRAWPARAMS imldp;
1045 ZeroMemory (&imldp, sizeof(imldp));
1046 imldp.cbSize = sizeof(imldp);
1054 imldp.rgbBk = rgbBk;
1055 imldp.rgbFg = rgbFg;
1056 imldp.fStyle = fStyle;
1058 return ImageList_DrawIndirect (&imldp);
1062 /*************************************************************************
1063 * ImageList_DrawIndirect [COMCTL32.@]
1065 * Draws an image using various parameters specified in pimldp.
1068 * pimldp [I] pointer to IMAGELISTDRAWPARAMS structure.
1076 ImageList_DrawIndirect (IMAGELISTDRAWPARAMS *pimldp)
1078 INT cx, cy, nOvlIdx;
1079 DWORD fState, dwRop;
1081 COLORREF oldImageBk, oldImageFg;
1082 HDC hImageDC, hImageListDC, hMaskListDC;
1083 HBITMAP hImageBmp, hOldImageBmp, hBlendMaskBmp;
1084 BOOL bIsTransparent, bBlend, bResult = FALSE, bMask;
1088 if (!pimldp || !(himl = pimldp->himl)) return FALSE;
1089 if (!is_valid(himl)) return FALSE;
1090 if ((pimldp->i < 0) || (pimldp->i >= himl->cCurImage)) return FALSE;
1092 imagelist_point_from_index( himl, pimldp->i, &pt );
1093 pt.x += pimldp->xBitmap;
1094 pt.y += pimldp->yBitmap;
1096 fState = pimldp->cbSize < sizeof(IMAGELISTDRAWPARAMS) ? ILS_NORMAL : pimldp->fState;
1097 fStyle = pimldp->fStyle & ~ILD_OVERLAYMASK;
1098 cx = (pimldp->cx == 0) ? himl->cx : pimldp->cx;
1099 cy = (pimldp->cy == 0) ? himl->cy : pimldp->cy;
1101 bIsTransparent = (fStyle & ILD_TRANSPARENT);
1102 if( pimldp->rgbBk == CLR_NONE )
1103 bIsTransparent = TRUE;
1104 if( ( pimldp->rgbBk == CLR_DEFAULT ) && ( himl->clrBk == CLR_NONE ) )
1105 bIsTransparent = TRUE;
1106 bMask = (himl->flags & ILC_MASK) && (fStyle & ILD_MASK) ;
1107 bBlend = (fStyle & (ILD_BLEND25 | ILD_BLEND50) ) && !bMask;
1109 TRACE("himl(%p) hbmMask(%p) iImage(%d) x(%d) y(%d) cx(%d) cy(%d)\n",
1110 himl, himl->hbmMask, pimldp->i, pimldp->x, pimldp->y, cx, cy);
1112 /* we will use these DCs to access the images and masks in the ImageList */
1113 hImageListDC = himl->hdcImage;
1114 hMaskListDC = himl->hdcMask;
1116 /* these will accumulate the image and mask for the image we're drawing */
1117 hImageDC = CreateCompatibleDC( pimldp->hdcDst );
1118 hImageBmp = CreateCompatibleBitmap( pimldp->hdcDst, cx, cy );
1119 hBlendMaskBmp = bBlend ? CreateBitmap(cx, cy, 1, 1, NULL) : 0;
1121 /* Create a compatible DC. */
1122 if (!hImageListDC || !hImageDC || !hImageBmp ||
1123 (bBlend && !hBlendMaskBmp) || (himl->hbmMask && !hMaskListDC))
1126 hOldImageBmp = SelectObject(hImageDC, hImageBmp);
1129 * To obtain a transparent look, background color should be set
1130 * to white and foreground color to black when blting the
1133 oldImageFg = SetTextColor( hImageDC, RGB( 0, 0, 0 ) );
1134 oldImageBk = SetBkColor( hImageDC, RGB( 0xff, 0xff, 0xff ) );
1137 * Draw the initial image
1140 if (himl->hbmMask) {
1142 hOldBrush = SelectObject (hImageDC, CreateSolidBrush (GetTextColor(pimldp->hdcDst)));
1143 PatBlt( hImageDC, 0, 0, cx, cy, PATCOPY );
1144 BitBlt(hImageDC, 0, 0, cx, cy, hMaskListDC, pt.x, pt.y, SRCPAINT);
1145 DeleteObject (SelectObject (hImageDC, hOldBrush));
1146 if( bIsTransparent )
1148 BitBlt ( pimldp->hdcDst, pimldp->x, pimldp->y, cx, cy, hImageDC, 0, 0, SRCAND);
1153 HBRUSH hOldBrush = SelectObject (hImageDC, GetStockObject(BLACK_BRUSH));
1154 PatBlt( hImageDC, 0, 0, cx, cy, PATCOPY);
1155 SelectObject(hImageDC, hOldBrush);
1158 /* blend the image with the needed solid background */
1159 COLORREF colour = RGB(0,0,0);
1162 if( !bIsTransparent )
1164 colour = pimldp->rgbBk;
1165 if( colour == CLR_DEFAULT )
1166 colour = himl->clrBk;
1167 if( colour == CLR_NONE )
1168 colour = GetBkColor(pimldp->hdcDst);
1171 hOldBrush = SelectObject (hImageDC, CreateSolidBrush (colour));
1172 PatBlt( hImageDC, 0, 0, cx, cy, PATCOPY );
1175 BitBlt( hImageDC, 0, 0, cx, cy, hMaskListDC, pt.x, pt.y, SRCAND );
1176 BitBlt( hImageDC, 0, 0, cx, cy, hImageListDC, pt.x, pt.y, SRCPAINT );
1179 BitBlt( hImageDC, 0, 0, cx, cy, hImageListDC, pt.x, pt.y, SRCCOPY);
1180 DeleteObject (SelectObject (hImageDC, hOldBrush));
1183 /* Time for blending, if required */
1185 HBRUSH hBlendBrush, hOldBrush;
1186 COLORREF clrBlend = pimldp->rgbFg;
1187 HDC hBlendMaskDC = hImageListDC;
1190 /* Create the blend Mask */
1191 hOldBitmap = SelectObject(hBlendMaskDC, hBlendMaskBmp);
1192 hBlendBrush = fStyle & ILD_BLEND50 ? himl->hbrBlend50 : himl->hbrBlend25;
1193 hOldBrush = SelectObject(hBlendMaskDC, hBlendBrush);
1194 PatBlt(hBlendMaskDC, 0, 0, cx, cy, PATCOPY);
1195 SelectObject(hBlendMaskDC, hOldBrush);
1197 /* Modify the blend mask if an Image Mask exist */
1199 BitBlt(hBlendMaskDC, 0, 0, cx, cy, hMaskListDC, pt.x, pt.y, 0x220326); /* NOTSRCAND */
1200 BitBlt(hBlendMaskDC, 0, 0, cx, cy, hBlendMaskDC, 0, 0, NOTSRCCOPY);
1203 /* now apply blend to the current image given the BlendMask */
1204 if (clrBlend == CLR_DEFAULT) clrBlend = GetSysColor (COLOR_HIGHLIGHT);
1205 else if (clrBlend == CLR_NONE) clrBlend = GetTextColor (pimldp->hdcDst);
1206 hOldBrush = SelectObject (hImageDC, CreateSolidBrush(clrBlend));
1207 BitBlt (hImageDC, 0, 0, cx, cy, hBlendMaskDC, 0, 0, 0xB8074A); /* PSDPxax */
1208 DeleteObject(SelectObject(hImageDC, hOldBrush));
1209 SelectObject(hBlendMaskDC, hOldBitmap);
1212 /* Now do the overlay image, if any */
1213 nOvlIdx = (pimldp->fStyle & ILD_OVERLAYMASK) >> 8;
1214 if ( (nOvlIdx >= 1) && (nOvlIdx <= MAX_OVERLAYIMAGE)) {
1215 nOvlIdx = himl->nOvlIdx[nOvlIdx - 1];
1216 if ((nOvlIdx >= 0) && (nOvlIdx < himl->cCurImage)) {
1218 imagelist_point_from_index( himl, nOvlIdx, &ptOvl );
1219 ptOvl.x += pimldp->xBitmap;
1220 if (himl->hbmMask && !(fStyle & ILD_IMAGE))
1221 BitBlt (hImageDC, 0, 0, cx, cy, hMaskListDC, ptOvl.x, ptOvl.y, SRCAND);
1222 BitBlt (hImageDC, 0, 0, cx, cy, hImageListDC, ptOvl.x, ptOvl.y, SRCPAINT);
1226 if (fState & ILS_SATURATE) FIXME("ILS_SATURATE: unimplemented!\n");
1227 if (fState & ILS_GLOW) FIXME("ILS_GLOW: unimplemented!\n");
1228 if (fState & ILS_SHADOW) FIXME("ILS_SHADOW: unimplemented!\n");
1229 if (fState & ILS_ALPHA) FIXME("ILS_ALPHA: unimplemented!\n");
1231 if (fStyle & ILD_PRESERVEALPHA) FIXME("ILD_PRESERVEALPHA: unimplemented!\n");
1232 if (fStyle & ILD_SCALE) FIXME("ILD_SCALE: unimplemented!\n");
1233 if (fStyle & ILD_DPISCALE) FIXME("ILD_DPISCALE: unimplemented!\n");
1235 /* now copy the image to the screen */
1237 if (himl->hbmMask && bIsTransparent ) {
1238 COLORREF oldDstFg = SetTextColor(pimldp->hdcDst, RGB( 0, 0, 0 ) );
1239 COLORREF oldDstBk = SetBkColor(pimldp->hdcDst, RGB( 0xff, 0xff, 0xff ));
1240 BitBlt (pimldp->hdcDst, pimldp->x, pimldp->y, cx, cy, hMaskListDC, pt.x, pt.y, SRCAND);
1241 SetBkColor(pimldp->hdcDst, oldDstBk);
1242 SetTextColor(pimldp->hdcDst, oldDstFg);
1245 if (fStyle & ILD_ROP) dwRop = pimldp->dwRop;
1246 BitBlt (pimldp->hdcDst, pimldp->x, pimldp->y, cx, cy, hImageDC, 0, 0, dwRop);
1250 /* cleanup the mess */
1251 SetBkColor(hImageDC, oldImageBk);
1252 SetTextColor(hImageDC, oldImageFg);
1253 SelectObject(hImageDC, hOldImageBmp);
1255 DeleteObject(hBlendMaskBmp);
1256 DeleteObject(hImageBmp);
1263 /*************************************************************************
1264 * ImageList_Duplicate [COMCTL32.@]
1266 * Duplicates an image list.
1269 * himlSrc [I] source image list handle
1272 * Success: Handle of duplicated image list.
1277 ImageList_Duplicate (HIMAGELIST himlSrc)
1281 if (!is_valid(himlSrc)) {
1282 ERR("Invalid image list handle!\n");
1286 himlDst = ImageList_Create (himlSrc->cx, himlSrc->cy, himlSrc->flags,
1287 himlSrc->cInitial, himlSrc->cGrow);
1293 imagelist_get_bitmap_size(himlSrc, himlSrc->cCurImage, himlSrc->cx, &sz);
1294 BitBlt (himlDst->hdcImage, 0, 0, sz.cx, sz.cy,
1295 himlSrc->hdcImage, 0, 0, SRCCOPY);
1297 if (himlDst->hbmMask)
1298 BitBlt (himlDst->hdcMask, 0, 0, sz.cx, sz.cy,
1299 himlSrc->hdcMask, 0, 0, SRCCOPY);
1301 himlDst->cCurImage = himlSrc->cCurImage;
1302 himlDst->cMaxImage = himlSrc->cMaxImage;
1308 /*************************************************************************
1309 * ImageList_EndDrag [COMCTL32.@]
1311 * Finishes a drag operation.
1322 ImageList_EndDrag (void)
1324 /* cleanup the InternalDrag struct */
1325 InternalDrag.hwnd = 0;
1326 ImageList_Destroy (InternalDrag.himl);
1327 InternalDrag.himl = 0;
1330 InternalDrag.dxHotspot = 0;
1331 InternalDrag.dyHotspot = 0;
1332 InternalDrag.bShow = FALSE;
1333 DeleteObject(InternalDrag.hbmBg);
1334 InternalDrag.hbmBg = 0;
1338 /*************************************************************************
1339 * ImageList_GetBkColor [COMCTL32.@]
1341 * Returns the background color of an image list.
1344 * himl [I] Image list handle.
1347 * Success: background color
1352 ImageList_GetBkColor (HIMAGELIST himl)
1354 return himl ? himl->clrBk : CLR_NONE;
1358 /*************************************************************************
1359 * ImageList_GetDragImage [COMCTL32.@]
1361 * Returns the handle to the internal drag image list.
1364 * ppt [O] Pointer to the drag position. Can be NULL.
1365 * pptHotspot [O] Pointer to the position of the hot spot. Can be NULL.
1368 * Success: Handle of the drag image list.
1373 ImageList_GetDragImage (POINT *ppt, POINT *pptHotspot)
1375 if (is_valid(InternalDrag.himl)) {
1377 ppt->x = InternalDrag.x;
1378 ppt->y = InternalDrag.y;
1381 pptHotspot->x = InternalDrag.dxHotspot;
1382 pptHotspot->y = InternalDrag.dyHotspot;
1384 return (InternalDrag.himl);
1391 /*************************************************************************
1392 * ImageList_GetFlags [COMCTL32.@]
1394 * Gets the flags of the specified image list.
1397 * himl [I] Handle to image list
1407 ImageList_GetFlags(HIMAGELIST himl)
1409 TRACE("%p\n", himl);
1411 return is_valid(himl) ? himl->flags : 0;
1415 /*************************************************************************
1416 * ImageList_GetIcon [COMCTL32.@]
1418 * Creates an icon from a masked image of an image list.
1421 * himl [I] handle to image list
1423 * flags [I] drawing style flags
1426 * Success: icon handle
1431 ImageList_GetIcon (HIMAGELIST himl, INT i, UINT fStyle)
1435 HBITMAP hOldDstBitmap;
1439 TRACE("%p %d %d\n", himl, i, fStyle);
1440 if (!is_valid(himl) || (i < 0) || (i >= himl->cCurImage)) return NULL;
1446 /* create colour bitmap */
1448 ii.hbmColor = CreateCompatibleBitmap(hdcDst, himl->cx, himl->cy);
1449 ReleaseDC(0, hdcDst);
1451 hdcDst = CreateCompatibleDC(0);
1453 imagelist_point_from_index( himl, i, &pt );
1456 ii.hbmMask = CreateBitmap (himl->cx, himl->cy, 1, 1, NULL);
1457 hOldDstBitmap = SelectObject (hdcDst, ii.hbmMask);
1458 if (himl->hbmMask) {
1459 BitBlt (hdcDst, 0, 0, himl->cx, himl->cy,
1460 himl->hdcMask, pt.x, pt.y, SRCCOPY);
1463 PatBlt (hdcDst, 0, 0, himl->cx, himl->cy, BLACKNESS);
1466 SelectObject (hdcDst, ii.hbmColor);
1467 BitBlt (hdcDst, 0, 0, himl->cx, himl->cy,
1468 himl->hdcImage, pt.x, pt.y, SRCCOPY);
1471 * CreateIconIndirect requires us to deselect the bitmaps from
1472 * the DCs before calling
1474 SelectObject(hdcDst, hOldDstBitmap);
1476 hIcon = CreateIconIndirect (&ii);
1478 DeleteObject (ii.hbmMask);
1479 DeleteObject (ii.hbmColor);
1486 /*************************************************************************
1487 * ImageList_GetIconSize [COMCTL32.@]
1489 * Retrieves the size of an image in an image list.
1492 * himl [I] handle to image list
1493 * cx [O] pointer to the image width.
1494 * cy [O] pointer to the image height.
1501 * All images in an image list have the same size.
1505 ImageList_GetIconSize (HIMAGELIST himl, INT *cx, INT *cy)
1507 if (!is_valid(himl))
1509 if ((himl->cx <= 0) || (himl->cy <= 0))
1521 /*************************************************************************
1522 * ImageList_GetImageCount [COMCTL32.@]
1524 * Returns the number of images in an image list.
1527 * himl [I] handle to image list
1530 * Success: Number of images.
1535 ImageList_GetImageCount (HIMAGELIST himl)
1537 if (!is_valid(himl))
1540 return himl->cCurImage;
1544 /*************************************************************************
1545 * ImageList_GetImageInfo [COMCTL32.@]
1547 * Returns information about an image in an image list.
1550 * himl [I] handle to image list
1552 * pImageInfo [O] pointer to the image information
1560 ImageList_GetImageInfo (HIMAGELIST himl, INT i, IMAGEINFO *pImageInfo)
1564 if (!is_valid(himl) || (pImageInfo == NULL))
1566 if ((i < 0) || (i >= himl->cCurImage))
1569 pImageInfo->hbmImage = himl->hbmImage;
1570 pImageInfo->hbmMask = himl->hbmMask;
1572 imagelist_point_from_index( himl, i, &pt );
1573 pImageInfo->rcImage.top = pt.y;
1574 pImageInfo->rcImage.bottom = pt.y + himl->cy;
1575 pImageInfo->rcImage.left = pt.x;
1576 pImageInfo->rcImage.right = pt.x + himl->cx;
1582 /*************************************************************************
1583 * ImageList_GetImageRect [COMCTL32.@]
1585 * Retrieves the rectangle of the specified image in an image list.
1588 * himl [I] handle to image list
1590 * lpRect [O] pointer to the image rectangle
1597 * This is an UNDOCUMENTED function!!!
1601 ImageList_GetImageRect (HIMAGELIST himl, INT i, LPRECT lpRect)
1605 if (!is_valid(himl) || (lpRect == NULL))
1607 if ((i < 0) || (i >= himl->cCurImage))
1610 imagelist_point_from_index( himl, i, &pt );
1611 lpRect->left = pt.x;
1613 lpRect->right = pt.x + himl->cx;
1614 lpRect->bottom = pt.y + himl->cy;
1620 /*************************************************************************
1621 * ImageList_LoadImage [COMCTL32.@]
1622 * ImageList_LoadImageA [COMCTL32.@]
1624 * Creates an image list from a bitmap, icon or cursor.
1626 * See ImageList_LoadImageW.
1630 ImageList_LoadImageA (HINSTANCE hi, LPCSTR lpbmp, INT cx, INT cGrow,
1631 COLORREF clrMask, UINT uType, UINT uFlags)
1638 return ImageList_LoadImageW(hi, (LPCWSTR)lpbmp, cx, cGrow, clrMask,
1641 len = MultiByteToWideChar(CP_ACP, 0, lpbmp, -1, NULL, 0);
1642 lpbmpW = Alloc(len * sizeof(WCHAR));
1643 MultiByteToWideChar(CP_ACP, 0, lpbmp, -1, lpbmpW, len);
1645 himl = ImageList_LoadImageW(hi, lpbmpW, cx, cGrow, clrMask, uType, uFlags);
1651 /*************************************************************************
1652 * ImageList_LoadImageW [COMCTL32.@]
1654 * Creates an image list from a bitmap, icon or cursor.
1657 * hi [I] instance handle
1658 * lpbmp [I] name or id of the image
1659 * cx [I] width of each image
1660 * cGrow [I] number of images to expand
1661 * clrMask [I] mask color
1662 * uType [I] type of image to load
1663 * uFlags [I] loading flags
1666 * Success: handle to the loaded image list
1674 ImageList_LoadImageW (HINSTANCE hi, LPCWSTR lpbmp, INT cx, INT cGrow,
1675 COLORREF clrMask, UINT uType, UINT uFlags)
1677 HIMAGELIST himl = NULL;
1681 handle = LoadImageW (hi, lpbmp, uType, 0, 0, uFlags);
1683 WARN("Couldn't load image\n");
1687 if (uType == IMAGE_BITMAP) {
1689 GetObjectW (handle, sizeof(BITMAP), &bmp);
1691 /* To match windows behavior, if cx is set to zero and
1692 the flag DI_DEFAULTSIZE is specified, cx becomes the
1693 system metric value for icons. If the flag is not specified
1694 the function sets the size to the height of the bitmap */
1697 if (uFlags & DI_DEFAULTSIZE)
1698 cx = GetSystemMetrics (SM_CXICON);
1703 nImageCount = bmp.bmWidth / cx;
1705 himl = ImageList_Create (cx, bmp.bmHeight, ILC_MASK | ILC_COLOR,
1706 nImageCount, cGrow);
1708 DeleteObject (handle);
1711 ImageList_AddMasked (himl, handle, clrMask);
1713 else if ((uType == IMAGE_ICON) || (uType == IMAGE_CURSOR)) {
1717 GetIconInfo (handle, &ii);
1718 GetObjectW (ii.hbmColor, sizeof(BITMAP), &bmp);
1719 himl = ImageList_Create (bmp.bmWidth, bmp.bmHeight,
1720 ILC_MASK | ILC_COLOR, 1, cGrow);
1722 DeleteObject (ii.hbmColor);
1723 DeleteObject (ii.hbmMask);
1724 DeleteObject (handle);
1727 ImageList_Add (himl, ii.hbmColor, ii.hbmMask);
1728 DeleteObject (ii.hbmColor);
1729 DeleteObject (ii.hbmMask);
1732 DeleteObject (handle);
1738 /*************************************************************************
1739 * ImageList_Merge [COMCTL32.@]
1741 * Create an image list containing a merged image from two image lists.
1744 * himl1 [I] handle to first image list
1745 * i1 [I] first image index
1746 * himl2 [I] handle to second image list
1747 * i2 [I] second image index
1748 * dx [I] X offset of the second image relative to the first.
1749 * dy [I] Y offset of the second image relative to the first.
1752 * Success: The newly created image list. It contains a single image
1753 * consisting of the second image merged with the first.
1754 * Failure: NULL, if either himl1 or himl2 are invalid.
1757 * - The returned image list should be deleted by the caller using
1758 * ImageList_Destroy() when it is no longer required.
1759 * - If either i1 or i2 are not valid image indices they will be treated
1763 ImageList_Merge (HIMAGELIST himl1, INT i1, HIMAGELIST himl2, INT i2,
1766 HIMAGELIST himlDst = NULL;
1768 INT xOff1, yOff1, xOff2, yOff2;
1771 TRACE("(himl1=%p i1=%d himl2=%p i2=%d dx=%d dy=%d)\n", himl1, i1, himl2,
1774 if (!is_valid(himl1) || !is_valid(himl2))
1778 cxDst = max (himl1->cx, dx + himl2->cx);
1783 cxDst = max (himl2->cx, himl1->cx - dx);
1788 cxDst = max (himl1->cx, himl2->cx);
1794 cyDst = max (himl1->cy, dy + himl2->cy);
1799 cyDst = max (himl2->cy, himl1->cy - dy);
1804 cyDst = max (himl1->cy, himl2->cy);
1809 himlDst = ImageList_Create (cxDst, cyDst, ILC_MASK | ILC_COLOR, 1, 1);
1813 imagelist_point_from_index( himl1, i1, &pt1 );
1814 imagelist_point_from_index( himl1, i2, &pt2 );
1817 BitBlt (himlDst->hdcImage, 0, 0, cxDst, cyDst, himl1->hdcImage, 0, 0, BLACKNESS);
1818 if (i1 >= 0 && i1 < himl1->cCurImage)
1819 BitBlt (himlDst->hdcImage, xOff1, yOff1, himl1->cx, himl1->cy, himl1->hdcImage, pt1.x, pt1.y, SRCCOPY);
1820 if (i2 >= 0 && i2 < himl2->cCurImage)
1822 BitBlt (himlDst->hdcImage, xOff2, yOff2, himl2->cx, himl2->cy, himl2->hdcMask , pt2.x, pt2.y, SRCAND);
1823 BitBlt (himlDst->hdcImage, xOff2, yOff2, himl2->cx, himl2->cy, himl2->hdcImage, pt2.x, pt2.y, SRCPAINT);
1827 BitBlt (himlDst->hdcMask, 0, 0, cxDst, cyDst, himl1->hdcMask, 0, 0, WHITENESS);
1828 if (i1 >= 0 && i1 < himl1->cCurImage)
1829 BitBlt (himlDst->hdcMask, xOff1, yOff1, himl1->cx, himl1->cy, himl1->hdcMask, pt1.x, pt1.y, SRCCOPY);
1830 if (i2 >= 0 && i2 < himl2->cCurImage)
1831 BitBlt (himlDst->hdcMask, xOff2, yOff2, himl2->cx, himl2->cy, himl2->hdcMask, pt2.x, pt2.y, SRCAND);
1833 himlDst->cCurImage = 1;
1840 /***********************************************************************
1841 * DIB_GetDIBWidthBytes
1843 * Return the width of a DIB bitmap in bytes. DIB bitmap data is 32-bit aligned.
1845 static int DIB_GetDIBWidthBytes( int width, int depth )
1851 case 1: words = (width + 31) / 32; break;
1852 case 4: words = (width + 7) / 8; break;
1853 case 8: words = (width + 3) / 4; break;
1855 case 16: words = (width + 1) / 2; break;
1856 case 24: words = (width * 3 + 3)/4; break;
1859 WARN("(%d): Unsupported depth\n", depth );
1868 /***********************************************************************
1869 * DIB_GetDIBImageBytes
1871 * Return the number of bytes used to hold the image in a DIB bitmap.
1873 static int DIB_GetDIBImageBytes( int width, int height, int depth )
1875 return DIB_GetDIBWidthBytes( width, depth ) * abs( height );
1879 /* helper for ImageList_Read, see comments below */
1880 static BOOL _read_bitmap(HDC hdcIml, LPSTREAM pstm)
1882 BITMAPFILEHEADER bmfh;
1883 int bitsperpixel, palspace;
1884 char bmi_buf[sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD) * 256];
1885 LPBITMAPINFO bmi = (LPBITMAPINFO)bmi_buf;
1889 if (FAILED(IStream_Read ( pstm, &bmfh, sizeof(bmfh), NULL)))
1892 if (bmfh.bfType != (('M'<<8)|'B'))
1895 if (FAILED(IStream_Read ( pstm, &bmi->bmiHeader, sizeof(bmi->bmiHeader), NULL)))
1898 if ((bmi->bmiHeader.biSize != sizeof(bmi->bmiHeader)))
1901 TRACE("width %u, height %u, planes %u, bpp %u\n",
1902 bmi->bmiHeader.biWidth, bmi->bmiHeader.biHeight,
1903 bmi->bmiHeader.biPlanes, bmi->bmiHeader.biBitCount);
1905 bitsperpixel = bmi->bmiHeader.biPlanes * bmi->bmiHeader.biBitCount;
1906 if (bitsperpixel<=8)
1907 palspace = (1<<bitsperpixel)*sizeof(RGBQUAD);
1911 bmi->bmiHeader.biSizeImage = DIB_GetDIBImageBytes(bmi->bmiHeader.biWidth, bmi->bmiHeader.biHeight, bitsperpixel);
1913 /* read the palette right after the end of the bitmapinfoheader */
1914 if (palspace && FAILED(IStream_Read(pstm, bmi->bmiColors, palspace, NULL)))
1917 bits = Alloc(bmi->bmiHeader.biSizeImage);
1920 if (FAILED(IStream_Read(pstm, bits, bmi->bmiHeader.biSizeImage, NULL)))
1923 if (!StretchDIBits(hdcIml, 0, 0, bmi->bmiHeader.biWidth, bmi->bmiHeader.biHeight,
1924 0, 0, bmi->bmiHeader.biWidth, bmi->bmiHeader.biHeight,
1925 bits, bmi, DIB_RGB_COLORS, SRCCOPY))
1934 /*************************************************************************
1935 * ImageList_Read [COMCTL32.@]
1937 * Reads an image list from a stream.
1940 * pstm [I] pointer to a stream
1943 * Success: handle to image list
1946 * The format is like this:
1947 * ILHEAD ilheadstruct;
1949 * for the color image part:
1950 * BITMAPFILEHEADER bmfh;
1951 * BITMAPINFOHEADER bmih;
1952 * only if it has a palette:
1953 * RGBQUAD rgbs[nr_of_paletted_colors];
1955 * BYTE colorbits[imagesize];
1957 * the following only if the ILC_MASK bit is set in ILHEAD.ilFlags:
1958 * BITMAPFILEHEADER bmfh_mask;
1959 * BITMAPINFOHEADER bmih_mask;
1960 * only if it has a palette (it usually does not):
1961 * RGBQUAD rgbs[nr_of_paletted_colors];
1963 * BYTE maskbits[imagesize];
1965 HIMAGELIST WINAPI ImageList_Read (LPSTREAM pstm)
1971 TRACE("%p\n", pstm);
1973 if (FAILED(IStream_Read (pstm, &ilHead, sizeof(ILHEAD), NULL)))
1975 if (ilHead.usMagic != (('L' << 8) | 'I'))
1977 if (ilHead.usVersion != 0x101) /* probably version? */
1980 TRACE("cx %u, cy %u, flags 0x%04x, cCurImage %u, cMaxImage %u\n",
1981 ilHead.cx, ilHead.cy, ilHead.flags, ilHead.cCurImage, ilHead.cMaxImage);
1983 himl = ImageList_Create(ilHead.cx, ilHead.cy, ilHead.flags, ilHead.cCurImage, ilHead.cMaxImage);
1987 if (!_read_bitmap(himl->hdcImage, pstm))
1989 WARN("failed to read bitmap from stream\n");
1992 if (ilHead.flags & ILC_MASK)
1994 if (!_read_bitmap(himl->hdcMask, pstm))
1996 WARN("failed to read mask bitmap from stream\n");
2001 himl->cCurImage = ilHead.cCurImage;
2002 himl->cMaxImage = ilHead.cMaxImage;
2004 ImageList_SetBkColor(himl,ilHead.bkcolor);
2006 ImageList_SetOverlayImage(himl,ilHead.ovls[i],i+1);
2011 /*************************************************************************
2012 * ImageList_Remove [COMCTL32.@]
2014 * Removes an image from an image list
2017 * himl [I] image list handle
2024 * FIXME: as the image list storage test shows, native comctl32 simply shifts
2025 * images without creating a new bitmap.
2028 ImageList_Remove (HIMAGELIST himl, INT i)
2030 HBITMAP hbmNewImage, hbmNewMask;
2034 TRACE("(himl=%p i=%d)\n", himl, i);
2036 if (!is_valid(himl)) {
2037 ERR("Invalid image list handle!\n");
2041 if ((i < -1) || (i >= himl->cCurImage)) {
2042 TRACE("index out of range! %d\n", i);
2050 if (himl->cCurImage == 0) {
2051 /* remove all on empty ImageList is allowed */
2052 TRACE("remove all on empty ImageList!\n");
2056 himl->cMaxImage = himl->cInitial + himl->cGrow - 1;
2057 himl->cCurImage = 0;
2058 for (nCount = 0; nCount < MAX_OVERLAYIMAGE; nCount++)
2059 himl->nOvlIdx[nCount] = -1;
2061 hbmNewImage = ImageList_CreateImage(himl->hdcImage, himl, himl->cMaxImage, himl->cx);
2062 SelectObject (himl->hdcImage, hbmNewImage);
2063 DeleteObject (himl->hbmImage);
2064 himl->hbmImage = hbmNewImage;
2066 if (himl->hbmMask) {
2068 imagelist_get_bitmap_size(himl, himl->cMaxImage, himl->cx, &sz);
2069 hbmNewMask = CreateBitmap (sz.cx, sz.cy, 1, 1, NULL);
2070 SelectObject (himl->hdcMask, hbmNewMask);
2071 DeleteObject (himl->hbmMask);
2072 himl->hbmMask = hbmNewMask;
2076 /* delete one image */
2077 TRACE("Remove single image! %d\n", i);
2079 /* create new bitmap(s) */
2080 TRACE(" - Number of images: %d / %d (Old/New)\n",
2081 himl->cCurImage, himl->cCurImage - 1);
2083 hbmNewImage = ImageList_CreateImage(himl->hdcImage, himl, himl->cMaxImage, himl->cx);
2085 imagelist_get_bitmap_size(himl, himl->cMaxImage, himl->cx, &sz );
2087 hbmNewMask = CreateBitmap (sz.cx, sz.cy, 1, 1, NULL);
2089 hbmNewMask = 0; /* Just to keep compiler happy! */
2091 hdcBmp = CreateCompatibleDC (0);
2093 /* copy all images and masks prior to the "removed" image */
2095 TRACE("Pre image copy: Copy %d images\n", i);
2097 SelectObject (hdcBmp, hbmNewImage);
2098 imagelist_copy_images( himl, himl->hdcImage, hdcBmp, 0, i, 0 );
2100 if (himl->hbmMask) {
2101 SelectObject (hdcBmp, hbmNewMask);
2102 imagelist_copy_images( himl, himl->hdcMask, hdcBmp, 0, i, 0 );
2106 /* copy all images and masks behind the removed image */
2107 if (i < himl->cCurImage - 1) {
2108 TRACE("Post image copy!\n");
2110 SelectObject (hdcBmp, hbmNewImage);
2111 imagelist_copy_images( himl, himl->hdcImage, hdcBmp, i + 1,
2112 (himl->cCurImage - i), i );
2114 if (himl->hbmMask) {
2115 SelectObject (hdcBmp, hbmNewMask);
2116 imagelist_copy_images( himl, himl->hdcMask, hdcBmp, i + 1,
2117 (himl->cCurImage - i), i );
2123 /* delete old images and insert new ones */
2124 SelectObject (himl->hdcImage, hbmNewImage);
2125 DeleteObject (himl->hbmImage);
2126 himl->hbmImage = hbmNewImage;
2127 if (himl->hbmMask) {
2128 SelectObject (himl->hdcMask, hbmNewMask);
2129 DeleteObject (himl->hbmMask);
2130 himl->hbmMask = hbmNewMask;
2140 /*************************************************************************
2141 * ImageList_Replace [COMCTL32.@]
2143 * Replaces an image in an image list with a new image.
2146 * himl [I] handle to image list
2148 * hbmImage [I] handle to image bitmap
2149 * hbmMask [I] handle to mask bitmap. Can be NULL.
2157 ImageList_Replace (HIMAGELIST himl, INT i, HBITMAP hbmImage,
2165 TRACE("%p %d %p %p\n", himl, i, hbmImage, hbmMask);
2167 if (!is_valid(himl)) {
2168 ERR("Invalid image list handle!\n");
2172 if ((i >= himl->cMaxImage) || (i < 0)) {
2173 ERR("Invalid image index!\n");
2177 if (!GetObjectW(hbmImage, sizeof(BITMAP), &bmp))
2180 hdcImage = CreateCompatibleDC (0);
2183 hOldBitmap = SelectObject (hdcImage, hbmImage);
2185 imagelist_point_from_index(himl, i, &pt);
2186 StretchBlt (himl->hdcImage, pt.x, pt.y, himl->cx, himl->cy,
2187 hdcImage, 0, 0, bmp.bmWidth, bmp.bmHeight, SRCCOPY);
2192 HBITMAP hOldBitmapTemp;
2194 hdcTemp = CreateCompatibleDC(0);
2195 hOldBitmapTemp = SelectObject(hdcTemp, hbmMask);
2197 StretchBlt (himl->hdcMask, pt.x, pt.y, himl->cx, himl->cy,
2198 hdcTemp, 0, 0, bmp.bmWidth, bmp.bmHeight, SRCCOPY);
2199 SelectObject(hdcTemp, hOldBitmapTemp);
2202 /* Remove the background from the image
2204 BitBlt (himl->hdcImage, pt.x, pt.y, bmp.bmWidth, bmp.bmHeight,
2205 himl->hdcMask, pt.x, pt.y, 0x220326); /* NOTSRCAND */
2208 SelectObject (hdcImage, hOldBitmap);
2209 DeleteDC (hdcImage);
2215 /*************************************************************************
2216 * ImageList_ReplaceIcon [COMCTL32.@]
2218 * Replaces an image in an image list using an icon.
2221 * himl [I] handle to image list
2223 * hIcon [I] handle to icon
2226 * Success: index of the replaced image
2231 ImageList_ReplaceIcon (HIMAGELIST himl, INT nIndex, HICON hIcon)
2241 TRACE("(%p %d %p)\n", himl, nIndex, hIcon);
2243 if (!is_valid(himl)) {
2244 ERR("invalid image list\n");
2247 if ((nIndex >= himl->cMaxImage) || (nIndex < -1)) {
2248 ERR("invalid image index %d / %d\n", nIndex, himl->cMaxImage);
2252 hBestFitIcon = CopyImage(
2255 LR_COPYFROMRESOURCE);
2256 /* the above will fail if the icon wasn't loaded from a resource, so try
2257 * again without LR_COPYFROMRESOURCE flag */
2259 hBestFitIcon = CopyImage(
2266 ret = GetIconInfo (hBestFitIcon, &ii);
2268 DestroyIcon(hBestFitIcon);
2272 ret = GetObjectW (ii.hbmMask, sizeof(BITMAP), &bmp);
2274 ERR("couldn't get mask bitmap info\n");
2276 DeleteObject (ii.hbmColor);
2278 DeleteObject (ii.hbmMask);
2279 DestroyIcon(hBestFitIcon);
2284 if (himl->cCurImage + 1 > himl->cMaxImage)
2285 IMAGELIST_InternalExpandBitmaps (himl, 1, 0, 0);
2287 nIndex = himl->cCurImage;
2291 hdcImage = CreateCompatibleDC (0);
2292 TRACE("hdcImage=%p\n", hdcImage);
2294 ERR("invalid hdcImage!\n");
2296 imagelist_point_from_index(himl, nIndex, &pt);
2298 SetTextColor(himl->hdcImage, RGB(0,0,0));
2299 SetBkColor (himl->hdcImage, RGB(255,255,255));
2303 hbmOldSrc = SelectObject (hdcImage, ii.hbmColor);
2304 StretchBlt (himl->hdcImage, pt.x, pt.y, himl->cx, himl->cy,
2305 hdcImage, 0, 0, bmp.bmWidth, bmp.bmHeight, SRCCOPY);
2308 SelectObject (hdcImage, ii.hbmMask);
2309 StretchBlt (himl->hdcMask, pt.x, pt.y, himl->cx, himl->cy,
2310 hdcImage, 0, 0, bmp.bmWidth, bmp.bmHeight, SRCCOPY);
2315 UINT height = bmp.bmHeight / 2;
2316 hbmOldSrc = SelectObject (hdcImage, ii.hbmMask);
2317 StretchBlt (himl->hdcImage, pt.x, pt.y, himl->cx, himl->cy,
2318 hdcImage, 0, height, bmp.bmWidth, height, SRCCOPY);
2320 StretchBlt (himl->hdcMask, pt.x, pt.y, himl->cx, himl->cy,
2321 hdcImage, 0, 0, bmp.bmWidth, height, SRCCOPY);
2324 SelectObject (hdcImage, hbmOldSrc);
2326 DestroyIcon(hBestFitIcon);
2328 DeleteDC (hdcImage);
2330 DeleteObject (ii.hbmColor);
2332 DeleteObject (ii.hbmMask);
2334 TRACE("Insert index = %d, himl->cCurImage = %d\n", nIndex, himl->cCurImage);
2339 /*************************************************************************
2340 * ImageList_SetBkColor [COMCTL32.@]
2342 * Sets the background color of an image list.
2345 * himl [I] handle to image list
2346 * clrBk [I] background color
2349 * Success: previous background color
2354 ImageList_SetBkColor (HIMAGELIST himl, COLORREF clrBk)
2358 if (!is_valid(himl))
2361 clrOldBk = himl->clrBk;
2362 himl->clrBk = clrBk;
2367 /*************************************************************************
2368 * ImageList_SetDragCursorImage [COMCTL32.@]
2370 * Combines the specified image with the current drag image
2373 * himlDrag [I] handle to drag image list
2374 * iDrag [I] drag image index
2375 * dxHotspot [I] X position of the hot spot
2376 * dyHotspot [I] Y position of the hot spot
2383 * - The names dxHotspot, dyHotspot are misleading because they have nothing
2384 * to do with a hotspot but are only the offset of the origin of the new
2385 * image relative to the origin of the old image.
2387 * - When this function is called and the drag image is visible, a
2388 * short flickering occurs but this matches the Win9x behavior. It is
2389 * possible to fix the flickering using code like in ImageList_DragMove.
2393 ImageList_SetDragCursorImage (HIMAGELIST himlDrag, INT iDrag,
2394 INT dxHotspot, INT dyHotspot)
2396 HIMAGELIST himlTemp;
2399 if (!is_valid(InternalDrag.himl) || !is_valid(himlDrag))
2402 TRACE(" dxH=%d dyH=%d nX=%d nY=%d\n",
2403 dxHotspot, dyHotspot, InternalDrag.dxHotspot, InternalDrag.dyHotspot);
2405 visible = InternalDrag.bShow;
2407 himlTemp = ImageList_Merge (InternalDrag.himl, 0, himlDrag, iDrag,
2408 dxHotspot, dyHotspot);
2411 /* hide the drag image */
2412 ImageList_DragShowNolock(FALSE);
2414 if ((InternalDrag.himl->cx != himlTemp->cx) ||
2415 (InternalDrag.himl->cy != himlTemp->cy)) {
2416 /* the size of the drag image changed, invalidate the buffer */
2417 DeleteObject(InternalDrag.hbmBg);
2418 InternalDrag.hbmBg = 0;
2421 ImageList_Destroy (InternalDrag.himl);
2422 InternalDrag.himl = himlTemp;
2425 /* show the drag image */
2426 ImageList_DragShowNolock(TRUE);
2433 /*************************************************************************
2434 * ImageList_SetFilter [COMCTL32.@]
2436 * Sets a filter (or does something completely different)!!???
2437 * It removes 12 Bytes from the stack (3 Parameters).
2440 * himl [I] SHOULD be a handle to image list
2441 * i [I] COULD be an index?
2446 * Failure: FALSE ???
2449 * This is an UNDOCUMENTED function!!!!
2454 ImageList_SetFilter (HIMAGELIST himl, INT i, DWORD dwFilter)
2456 FIXME("(%p 0x%x 0x%x):empty stub!\n", himl, i, dwFilter);
2462 /*************************************************************************
2463 * ImageList_SetFlags [COMCTL32.@]
2465 * Sets the image list flags.
2468 * himl [I] Handle to image list
2469 * flags [I] Flags to set
2479 ImageList_SetFlags(HIMAGELIST himl, DWORD flags)
2481 FIXME("(%p %08x):empty stub\n", himl, flags);
2486 /*************************************************************************
2487 * ImageList_SetIconSize [COMCTL32.@]
2489 * Sets the image size of the bitmap and deletes all images.
2492 * himl [I] handle to image list
2493 * cx [I] image width
2494 * cy [I] image height
2502 ImageList_SetIconSize (HIMAGELIST himl, INT cx, INT cy)
2507 if (!is_valid(himl))
2510 /* remove all images */
2511 himl->cMaxImage = himl->cInitial + 1;
2512 himl->cCurImage = 0;
2516 /* initialize overlay mask indices */
2517 for (nCount = 0; nCount < MAX_OVERLAYIMAGE; nCount++)
2518 himl->nOvlIdx[nCount] = -1;
2520 hbmNew = ImageList_CreateImage(himl->hdcImage, himl, himl->cMaxImage, himl->cx);
2521 SelectObject (himl->hdcImage, hbmNew);
2522 DeleteObject (himl->hbmImage);
2523 himl->hbmImage = hbmNew;
2525 if (himl->hbmMask) {
2527 imagelist_get_bitmap_size(himl, himl->cMaxImage, himl->cx, &sz);
2528 hbmNew = CreateBitmap (sz.cx, sz.cy, 1, 1, NULL);
2529 SelectObject (himl->hdcMask, hbmNew);
2530 DeleteObject (himl->hbmMask);
2531 himl->hbmMask = hbmNew;
2538 /*************************************************************************
2539 * ImageList_SetImageCount [COMCTL32.@]
2541 * Resizes an image list to the specified number of images.
2544 * himl [I] handle to image list
2545 * iImageCount [I] number of images in the image list
2553 ImageList_SetImageCount (HIMAGELIST himl, UINT iImageCount)
2556 HBITMAP hbmNewBitmap, hbmOld;
2557 INT nNewCount, nCopyCount;
2559 TRACE("%p %d\n",himl,iImageCount);
2561 if (!is_valid(himl))
2563 if (himl->cMaxImage > iImageCount)
2565 himl->cCurImage = iImageCount;
2566 /* TODO: shrink the bitmap when cMaxImage-cCurImage>cGrow ? */
2570 nNewCount = iImageCount + himl->cGrow;
2571 nCopyCount = min(himl->cCurImage, iImageCount);
2573 hdcBitmap = CreateCompatibleDC (0);
2575 hbmNewBitmap = ImageList_CreateImage(hdcBitmap, himl, nNewCount, himl->cx);
2577 if (hbmNewBitmap != 0)
2579 hbmOld = SelectObject (hdcBitmap, hbmNewBitmap);
2580 imagelist_copy_images( himl, himl->hdcImage, hdcBitmap, 0, nCopyCount, 0 );
2581 SelectObject (hdcBitmap, hbmOld);
2583 /* FIXME: delete 'empty' image space? */
2585 SelectObject (himl->hdcImage, hbmNewBitmap);
2586 DeleteObject (himl->hbmImage);
2587 himl->hbmImage = hbmNewBitmap;
2590 ERR("Could not create new image bitmap !\n");
2595 imagelist_get_bitmap_size( himl, nNewCount, himl->cx, &sz );
2596 hbmNewBitmap = CreateBitmap (sz.cx, sz.cy, 1, 1, NULL);
2597 if (hbmNewBitmap != 0)
2599 hbmOld = SelectObject (hdcBitmap, hbmNewBitmap);
2600 imagelist_copy_images( himl, himl->hdcMask, hdcBitmap, 0, nCopyCount, 0 );
2601 SelectObject (hdcBitmap, hbmOld);
2603 /* FIXME: delete 'empty' image space? */
2605 SelectObject (himl->hdcMask, hbmNewBitmap);
2606 DeleteObject (himl->hbmMask);
2607 himl->hbmMask = hbmNewBitmap;
2610 ERR("Could not create new mask bitmap!\n");
2613 DeleteDC (hdcBitmap);
2615 /* Update max image count and current image count */
2616 himl->cMaxImage = nNewCount;
2617 himl->cCurImage = iImageCount;
2623 /*************************************************************************
2624 * ImageList_SetOverlayImage [COMCTL32.@]
2626 * Assigns an overlay mask index to an existing image in an image list.
2629 * himl [I] handle to image list
2630 * iImage [I] image index
2631 * iOverlay [I] overlay mask index
2639 ImageList_SetOverlayImage (HIMAGELIST himl, INT iImage, INT iOverlay)
2641 if (!is_valid(himl))
2643 if ((iOverlay < 1) || (iOverlay > MAX_OVERLAYIMAGE))
2645 if ((iImage!=-1) && ((iImage < 0) || (iImage > himl->cCurImage)))
2647 himl->nOvlIdx[iOverlay - 1] = iImage;
2653 /* helper for ImageList_Write - write bitmap to pstm
2654 * currently everything is written as 24 bit RGB, except masks
2657 _write_bitmap(HBITMAP hBitmap, LPSTREAM pstm)
2659 LPBITMAPFILEHEADER bmfh;
2660 LPBITMAPINFOHEADER bmih;
2661 LPBYTE data = NULL, lpBits;
2663 INT bitCount, sizeImage, offBits, totalSize;
2665 BOOL result = FALSE;
2667 if (!GetObjectW(hBitmap, sizeof(BITMAP), &bm))
2670 bitCount = bm.bmBitsPixel == 1 ? 1 : 24;
2671 sizeImage = DIB_GetDIBImageBytes(bm.bmWidth, bm.bmHeight, bitCount);
2673 totalSize = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);
2675 totalSize += (1 << bitCount) * sizeof(RGBQUAD);
2676 offBits = totalSize;
2677 totalSize += sizeImage;
2679 data = Alloc(totalSize);
2680 bmfh = (LPBITMAPFILEHEADER)data;
2681 bmih = (LPBITMAPINFOHEADER)(data + sizeof(BITMAPFILEHEADER));
2682 lpBits = data + offBits;
2684 /* setup BITMAPFILEHEADER */
2685 bmfh->bfType = (('M' << 8) | 'B');
2686 bmfh->bfSize = offBits;
2687 bmfh->bfReserved1 = 0;
2688 bmfh->bfReserved2 = 0;
2689 bmfh->bfOffBits = offBits;
2691 /* setup BITMAPINFOHEADER */
2692 bmih->biSize = sizeof(BITMAPINFOHEADER);
2693 bmih->biWidth = bm.bmWidth;
2694 bmih->biHeight = bm.bmHeight;
2696 bmih->biBitCount = bitCount;
2697 bmih->biCompression = BI_RGB;
2698 bmih->biSizeImage = sizeImage;
2699 bmih->biXPelsPerMeter = 0;
2700 bmih->biYPelsPerMeter = 0;
2701 bmih->biClrUsed = 0;
2702 bmih->biClrImportant = 0;
2705 result = GetDIBits(xdc, hBitmap, 0, bm.bmHeight, lpBits, (BITMAPINFO *)bmih, DIB_RGB_COLORS) == bm.bmHeight;
2710 TRACE("width %u, height %u, planes %u, bpp %u\n",
2711 bmih->biWidth, bmih->biHeight,
2712 bmih->biPlanes, bmih->biBitCount);
2716 LPBITMAPINFO inf = (LPBITMAPINFO)bmih;
2717 inf->bmiColors[0].rgbRed = inf->bmiColors[0].rgbGreen = inf->bmiColors[0].rgbBlue = 0;
2718 inf->bmiColors[1].rgbRed = inf->bmiColors[1].rgbGreen = inf->bmiColors[1].rgbBlue = 0xff;
2721 if(FAILED(IStream_Write(pstm, data, totalSize, NULL)))
2733 /*************************************************************************
2734 * ImageList_Write [COMCTL32.@]
2736 * Writes an image list to a stream.
2739 * himl [I] handle to image list
2740 * pstm [O] Pointer to a stream.
2751 ImageList_Write (HIMAGELIST himl, LPSTREAM pstm)
2756 TRACE("%p %p\n", himl, pstm);
2758 if (!is_valid(himl))
2761 ilHead.usMagic = (('L' << 8) | 'I');
2762 ilHead.usVersion = 0x101;
2763 ilHead.cCurImage = himl->cCurImage;
2764 ilHead.cMaxImage = himl->cMaxImage;
2765 ilHead.cGrow = himl->cGrow;
2766 ilHead.cx = himl->cx;
2767 ilHead.cy = himl->cy;
2768 ilHead.bkcolor = himl->clrBk;
2769 ilHead.flags = himl->flags;
2770 for(i = 0; i < 4; i++) {
2771 ilHead.ovls[i] = himl->nOvlIdx[i];
2774 TRACE("cx %u, cy %u, flags 0x04%x, cCurImage %u, cMaxImage %u\n",
2775 ilHead.cx, ilHead.cy, ilHead.flags, ilHead.cCurImage, ilHead.cMaxImage);
2777 if(FAILED(IStream_Write(pstm, &ilHead, sizeof(ILHEAD), NULL)))
2780 /* write the bitmap */
2781 if(!_write_bitmap(himl->hbmImage, pstm))
2784 /* write the mask if we have one */
2785 if(himl->flags & ILC_MASK) {
2786 if(!_write_bitmap(himl->hbmMask, pstm))
2794 static HBITMAP ImageList_CreateImage(HDC hdc, HIMAGELIST himl, UINT count, UINT width)
2796 HBITMAP hbmNewBitmap;
2797 UINT ilc = (himl->flags & 0xFE);
2800 imagelist_get_bitmap_size( himl, count, width, &sz );
2802 if ((ilc >= ILC_COLOR4 && ilc <= ILC_COLOR32) || ilc == ILC_COLOR)
2807 TRACE("Creating DIBSection %d x %d, %d Bits per Pixel\n",
2808 sz.cx, sz.cy, himl->uBitsPixel);
2810 if (himl->uBitsPixel <= ILC_COLOR8)
2816 colors = 1 << himl->uBitsPixel;
2817 bmi = Alloc(sizeof(BITMAPINFOHEADER) +
2818 sizeof(PALETTEENTRY) * colors);
2820 pal = (LPPALETTEENTRY)bmi->bmiColors;
2821 GetPaletteEntries(GetStockObject(DEFAULT_PALETTE), 0, colors, pal);
2823 /* Swap colors returned by GetPaletteEntries so we can use them for
2824 * CreateDIBSection call. */
2825 for (i = 0; i < colors; i++)
2827 temp = pal[i].peBlue;
2828 bmi->bmiColors[i].rgbRed = pal[i].peRed;
2829 bmi->bmiColors[i].rgbBlue = temp;
2834 bmi = Alloc(sizeof(BITMAPINFOHEADER));
2837 bmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
2838 bmi->bmiHeader.biWidth = sz.cx;
2839 bmi->bmiHeader.biHeight = sz.cy;
2840 bmi->bmiHeader.biPlanes = 1;
2841 bmi->bmiHeader.biBitCount = himl->uBitsPixel;
2842 bmi->bmiHeader.biCompression = BI_RGB;
2843 bmi->bmiHeader.biSizeImage = 0;
2844 bmi->bmiHeader.biXPelsPerMeter = 0;
2845 bmi->bmiHeader.biYPelsPerMeter = 0;
2846 bmi->bmiHeader.biClrUsed = 0;
2847 bmi->bmiHeader.biClrImportant = 0;
2849 hbmNewBitmap = CreateDIBSection(hdc, bmi, DIB_RGB_COLORS, &bits, 0, 0);
2853 else /*if (ilc == ILC_COLORDDB)*/
2855 TRACE("Creating Bitmap: %d Bits per Pixel\n", himl->uBitsPixel);
2857 hbmNewBitmap = CreateBitmap (sz.cx, sz.cy, 1, himl->uBitsPixel, NULL);
2859 TRACE("returning %p\n", hbmNewBitmap);
2860 return hbmNewBitmap;
2863 /*************************************************************************
2864 * ImageList_SetColorTable [COMCTL32.@]
2866 * Sets the color table of an image list.
2869 * himl [I] Handle to the image list.
2870 * uStartIndex [I] The first index to set.
2871 * cEntries [I] Number of entries to set.
2872 * prgb [I] New color information for color table for the image list.
2875 * Success: Number of entries in the table that were set.
2879 * ImageList_Create(), SetDIBColorTable()
2883 ImageList_SetColorTable (HIMAGELIST himl, UINT uStartIndex, UINT cEntries, CONST RGBQUAD * prgb)
2885 return SetDIBColorTable(himl->hdcImage, uStartIndex, cEntries, prgb);
2888 /*************************************************************************
2889 * ImageList_CoCreateInstance [COMCTL32.@]
2891 * Creates a new imagelist instance and returns an interface pointer to it.
2894 * rclsid [I] A reference to the CLSID (CLSID_ImageList).
2895 * punkOuter [I] Pointer to IUnknown interface for aggregation, if desired
2896 * riid [I] Identifier of the requested interface.
2897 * ppv [O] Returns the address of the pointer requested, or NULL.
2901 * Failure: Error value.
2904 ImageList_CoCreateInstance (REFCLSID rclsid, const IUnknown *punkOuter, REFIID riid, void **ppv)
2906 TRACE("(%s,%p,%s,%p)\n", debugstr_guid(rclsid), punkOuter, debugstr_guid(riid), ppv);
2908 if (!IsEqualCLSID(&CLSID_ImageList, rclsid))
2909 return E_NOINTERFACE;
2911 return ImageListImpl_CreateInstance(punkOuter, riid, ppv);
2915 /*************************************************************************
2916 * IImageList implementation
2919 static HRESULT WINAPI ImageListImpl_QueryInterface(IImageList *iface,
2920 REFIID iid, void **ppv)
2922 HIMAGELIST This = (HIMAGELIST) iface;
2923 TRACE("(%p,%s,%p)\n", iface, debugstr_guid(iid), ppv);
2925 if (!ppv) return E_INVALIDARG;
2927 if (IsEqualIID(&IID_IUnknown, iid) || IsEqualIID(&IID_IImageList, iid))
2932 return E_NOINTERFACE;
2935 IUnknown_AddRef((IUnknown*)*ppv);
2939 static ULONG WINAPI ImageListImpl_AddRef(IImageList *iface)
2941 HIMAGELIST This = (HIMAGELIST) iface;
2942 ULONG ref = InterlockedIncrement(&This->ref);
2944 TRACE("(%p) refcount=%u\n", iface, ref);
2948 static ULONG WINAPI ImageListImpl_Release(IImageList *iface)
2950 HIMAGELIST This = (HIMAGELIST) iface;
2951 ULONG ref = InterlockedDecrement(&This->ref);
2953 TRACE("(%p) refcount=%u\n", iface, ref);
2957 /* delete image bitmaps */
2958 if (This->hbmImage) DeleteObject (This->hbmImage);
2959 if (This->hbmMask) DeleteObject (This->hbmMask);
2961 /* delete image & mask DCs */
2962 if (This->hdcImage) DeleteDC (This->hdcImage);
2963 if (This->hdcMask) DeleteDC (This->hdcMask);
2965 /* delete blending brushes */
2966 if (This->hbrBlend25) DeleteObject (This->hbrBlend25);
2967 if (This->hbrBlend50) DeleteObject (This->hbrBlend50);
2969 This->lpVtbl = NULL;
2970 HeapFree(GetProcessHeap(), 0, This);
2976 static HRESULT WINAPI ImageListImpl_Add(IImageList *iface, HBITMAP hbmImage,
2977 HBITMAP hbmMask, int *pi)
2979 HIMAGELIST This = (HIMAGELIST) iface;
2985 ret = ImageList_Add(This, hbmImage, hbmMask);
2994 static HRESULT WINAPI ImageListImpl_ReplaceIcon(IImageList *iface, int i,
2995 HICON hicon, int *pi)
2997 HIMAGELIST This = (HIMAGELIST) iface;
3003 ret = ImageList_ReplaceIcon(This, i, hicon);
3012 static HRESULT WINAPI ImageListImpl_SetOverlayImage(IImageList *iface,
3013 int iImage, int iOverlay)
3015 return ImageList_SetOverlayImage((HIMAGELIST) iface, iImage, iOverlay)
3019 static HRESULT WINAPI ImageListImpl_Replace(IImageList *iface, int i,
3020 HBITMAP hbmImage, HBITMAP hbmMask)
3022 return ImageList_Replace((HIMAGELIST) iface, i, hbmImage, hbmMask) ? S_OK :
3026 static HRESULT WINAPI ImageListImpl_AddMasked(IImageList *iface, HBITMAP hbmImage,
3027 COLORREF crMask, int *pi)
3029 HIMAGELIST This = (HIMAGELIST) iface;
3035 ret = ImageList_AddMasked(This, hbmImage, crMask);
3044 static HRESULT WINAPI ImageListImpl_Draw(IImageList *iface,
3045 IMAGELISTDRAWPARAMS *pimldp)
3047 HIMAGELIST This = (HIMAGELIST) iface;
3048 HIMAGELIST old_himl = 0;
3054 /* As far as I can tell, Windows simply ignores the contents of pimldp->himl
3055 so we shall simulate the same */
3056 old_himl = pimldp->himl;
3057 pimldp->himl = This;
3059 ret = ImageList_DrawIndirect(pimldp);
3061 pimldp->himl = old_himl;
3062 return ret ? S_OK : E_FAIL;
3065 static HRESULT WINAPI ImageListImpl_Remove(IImageList *iface, int i)
3067 return (ImageList_Remove((HIMAGELIST) iface, i) == 0) ? E_FAIL : S_OK;
3070 static HRESULT WINAPI ImageListImpl_GetIcon(IImageList *iface, int i, UINT flags,
3078 hIcon = ImageList_GetIcon((HIMAGELIST) iface, i, flags);
3087 static HRESULT WINAPI ImageListImpl_GetImageInfo(IImageList *iface, int i,
3088 IMAGEINFO *pImageInfo)
3090 return ImageList_GetImageInfo((HIMAGELIST) iface, i, pImageInfo) ? S_OK : E_FAIL;
3093 static HRESULT WINAPI ImageListImpl_Copy(IImageList *iface, int iDst,
3094 IUnknown *punkSrc, int iSrc, UINT uFlags)
3096 HIMAGELIST This = (HIMAGELIST) iface;
3097 IImageList *src = NULL;
3103 /* TODO: Add test for IID_ImageList2 too */
3104 if (!SUCCEEDED(IImageList_QueryInterface(punkSrc, &IID_IImageList,
3108 if (ImageList_Copy(This, iDst, (HIMAGELIST) src, iSrc, uFlags))
3113 IImageList_Release(src);
3117 static HRESULT WINAPI ImageListImpl_Merge(IImageList *iface, int i1,
3118 IUnknown *punk2, int i2, int dx, int dy, REFIID riid, PVOID *ppv)
3120 HIMAGELIST This = (HIMAGELIST) iface;
3121 IImageList *iml2 = NULL;
3123 HRESULT ret = E_FAIL;
3128 /* TODO: Add test for IID_ImageList2 too */
3129 if (!SUCCEEDED(IImageList_QueryInterface(punk2, &IID_IImageList,
3133 hNew = ImageList_Merge(This, i1, (HIMAGELIST) iml2, i2, dx, dy);
3135 /* Get the interface for the new image list */
3137 ret = HIMAGELIST_QueryInterface(hNew, riid, ppv);
3139 IImageList_Release(iml2);
3143 static HRESULT WINAPI ImageListImpl_Clone(IImageList *iface, REFIID riid,
3146 HIMAGELIST This = (HIMAGELIST) iface;
3148 HRESULT ret = E_FAIL;
3153 hNew = ImageList_Duplicate(This);
3155 /* Get the interface for the new image list */
3157 ret = HIMAGELIST_QueryInterface(hNew, riid, ppv);
3162 static HRESULT WINAPI ImageListImpl_GetImageRect(IImageList *iface, int i,
3165 FIXME("STUB: %p %d %p\n", iface, i, prc);
3169 static HRESULT WINAPI ImageListImpl_GetIconSize(IImageList *iface, int *cx,
3172 FIXME("STUB: %p %p %p\n", iface, cx, cy);
3176 static HRESULT WINAPI ImageListImpl_SetIconSize(IImageList *iface, int cx,
3179 FIXME("STUB: %p %d %d\n", iface, cx, cy);
3183 static HRESULT WINAPI ImageListImpl_GetImageCount(IImageList *iface, int *pi)
3188 *pi = ImageList_GetImageCount((HIMAGELIST) iface);
3192 static HRESULT WINAPI ImageListImpl_SetImageCount(IImageList *iface,
3195 return ImageList_SetImageCount((HIMAGELIST) iface, uNewCount) ? S_OK : E_FAIL;
3198 static HRESULT WINAPI ImageListImpl_SetBkColor(IImageList *iface, COLORREF clrBk,
3201 FIXME("STUB: %p %x %p\n", iface, clrBk, pclr);
3205 static HRESULT WINAPI ImageListImpl_GetBkColor(IImageList *iface, COLORREF *pclr)
3207 FIXME("STUB: %p %p\n", iface, pclr);
3211 static HRESULT WINAPI ImageListImpl_BeginDrag(IImageList *iface, int iTrack,
3212 int dxHotspot, int dyHotspot)
3214 FIXME("STUB: %p %d %d %d\n", iface, iTrack, dxHotspot, dyHotspot);
3218 static HRESULT WINAPI ImageListImpl_EndDrag(IImageList *iface)
3220 FIXME("STUB: %p\n", iface);
3224 static HRESULT WINAPI ImageListImpl_DragEnter(IImageList *iface, HWND hwndLock,
3227 FIXME("STUB: %p %p %d %d\n", iface, hwndLock, x, y);
3231 static HRESULT WINAPI ImageListImpl_DragLeave(IImageList *iface, HWND hwndLock)
3233 FIXME("STUB: %p %p\n", iface, hwndLock);
3237 static HRESULT WINAPI ImageListImpl_DragMove(IImageList *iface, int x, int y)
3239 FIXME("STUB: %p %d %d\n", iface, x, y);
3243 static HRESULT WINAPI ImageListImpl_SetDragCursorImage(IImageList *iface,
3244 IUnknown *punk, int iDrag, int dxHotspot, int dyHotspot)
3246 FIXME("STUB: %p %p %d %d %d\n", iface, punk, iDrag, dxHotspot, dyHotspot);
3250 static HRESULT WINAPI ImageListImpl_DragShowNolock(IImageList *iface, BOOL fShow)
3252 FIXME("STUB: %p %d\n", iface, fShow);
3256 static HRESULT WINAPI ImageListImpl_GetDragImage(IImageList *iface, POINT *ppt,
3257 POINT *pptHotspot, REFIID riid, PVOID *ppv)
3259 FIXME("STUB: %p %p %p %s %p\n", iface, ppt, pptHotspot, debugstr_guid(riid),
3264 static HRESULT WINAPI ImageListImpl_GetItemFlags(IImageList *iface, int i,
3267 FIXME("STUB: %p %d %p\n", iface, i, dwFlags);
3271 static HRESULT WINAPI ImageListImpl_GetOverlayImage(IImageList *iface, int iOverlay,
3274 FIXME("STUB: %p %d %p\n", iface, iOverlay, piIndex);
3279 static const IImageListVtbl ImageListImpl_Vtbl = {
3280 ImageListImpl_QueryInterface,
3281 ImageListImpl_AddRef,
3282 ImageListImpl_Release,
3284 ImageListImpl_ReplaceIcon,
3285 ImageListImpl_SetOverlayImage,
3286 ImageListImpl_Replace,
3287 ImageListImpl_AddMasked,
3289 ImageListImpl_Remove,
3290 ImageListImpl_GetIcon,
3291 ImageListImpl_GetImageInfo,
3293 ImageListImpl_Merge,
3294 ImageListImpl_Clone,
3295 ImageListImpl_GetImageRect,
3296 ImageListImpl_GetIconSize,
3297 ImageListImpl_SetIconSize,
3298 ImageListImpl_GetImageCount,
3299 ImageListImpl_SetImageCount,
3300 ImageListImpl_SetBkColor,
3301 ImageListImpl_GetBkColor,
3302 ImageListImpl_BeginDrag,
3303 ImageListImpl_EndDrag,
3304 ImageListImpl_DragEnter,
3305 ImageListImpl_DragLeave,
3306 ImageListImpl_DragMove,
3307 ImageListImpl_SetDragCursorImage,
3308 ImageListImpl_DragShowNolock,
3309 ImageListImpl_GetDragImage,
3310 ImageListImpl_GetItemFlags,
3311 ImageListImpl_GetOverlayImage
3314 static inline BOOL is_valid(HIMAGELIST himl)
3316 return himl && himl->lpVtbl == &ImageListImpl_Vtbl;
3319 /*************************************************************************
3320 * HIMAGELIST_QueryInterface [COMCTL32.@]
3322 * Returns a pointer to an IImageList or IImageList2 object for the given
3326 * himl [I] Image list handle.
3327 * riid [I] Identifier of the requested interface.
3328 * ppv [O] Returns the address of the pointer requested, or NULL.
3332 * Failure: Error value.
3335 HIMAGELIST_QueryInterface (HIMAGELIST himl, REFIID riid, void **ppv)
3337 TRACE("(%p,%s,%p)\n", himl, debugstr_guid(riid), ppv);
3338 return IImageList_QueryInterface((IImageList *) himl, riid, ppv);
3341 static HRESULT ImageListImpl_CreateInstance(const IUnknown *pUnkOuter, REFIID iid, void** ppv)
3346 TRACE("(%p,%s,%p)\n", pUnkOuter, debugstr_guid(iid), ppv);
3350 if (pUnkOuter) return CLASS_E_NOAGGREGATION;
3352 This = HeapAlloc(GetProcessHeap(), 0, sizeof(struct _IMAGELIST));
3353 if (!This) return E_OUTOFMEMORY;
3355 ZeroMemory(This, sizeof(struct _IMAGELIST));
3357 This->lpVtbl = &ImageListImpl_Vtbl;
3360 ret = IUnknown_QueryInterface((IUnknown*)This, iid, ppv);
3361 IUnknown_Release((IUnknown*)This);