mshtml: Use popup menu from shdoclc.dll.
[wine/multimedia.git] / dlls / comctl32 / imagelist.c
blob36fe3842597c2cc364044848e188c21acf24c4ec
1 /*
2 * ImageList implementation
4 * Copyright 1998 Eric Kohl
5 * Copyright 2000 Jason Mawdsley
6 * Copyright 2001, 2004 Michael Stefaniuc
7 * Copyright 2001 Charles Loep for CodeWeavers
8 * Copyright 2002 Dimitrie O. Paun
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 * NOTE
26 * This code was audited for completeness against the documented features
27 * of Comctl32.dll version 6.0 on Sep. 12, 2002, by Dimitrie O. Paun.
29 * Unless otherwise noted, we believe this code to be complete, as per
30 * the specification mentioned above.
31 * If you discover missing features, or bugs, please note them below.
33 * TODO:
34 * - Add support for ILD_PRESERVEALPHA, ILD_SCALE, ILD_DPISCALE
35 * - Add support for ILS_GLOW, ILS_SHADOW, ILS_SATURATE, ILS_ALPHA
36 * - Thread-safe locking
39 #include <stdarg.h>
40 #include <stdlib.h>
41 #include <string.h>
43 #define COBJMACROS
45 #include "winerror.h"
46 #include "windef.h"
47 #include "winbase.h"
48 #include "objbase.h"
49 #include "wingdi.h"
50 #include "winuser.h"
51 #include "commctrl.h"
52 #include "comctl32.h"
53 #include "imagelist.h"
54 #include "wine/debug.h"
56 WINE_DEFAULT_DEBUG_CHANNEL(imagelist);
59 #define MAX_OVERLAYIMAGE 15
61 /* internal image list data used for Drag & Drop operations */
62 typedef struct
64 HWND hwnd;
65 HIMAGELIST himl;
66 /* position of the drag image relative to the window */
67 INT x;
68 INT y;
69 /* offset of the hotspot relative to the origin of the image */
70 INT dxHotspot;
71 INT dyHotspot;
72 /* is the drag image visible */
73 BOOL bShow;
74 /* saved background */
75 HBITMAP hbmBg;
76 } INTERNALDRAG;
78 static INTERNALDRAG InternalDrag = { 0, 0, 0, 0, 0, 0, FALSE, 0 };
80 static HBITMAP ImageList_CreateImage(HDC hdc, HIMAGELIST himl, UINT count, UINT height);
82 static inline BOOL is_valid(HIMAGELIST himl)
84 return himl && himl->magic == IMAGELIST_MAGIC;
88 * An imagelist with N images is tiled like this:
90 * N/4 ->
92 * 4 048C..
93 * 159D..
94 * | 26AE.N
95 * V 37BF.
98 #define TILE_COUNT 4
100 static inline UINT imagelist_width( UINT count )
102 return ((count + TILE_COUNT - 1)/TILE_COUNT);
105 static inline void imagelist_point_from_index( HIMAGELIST himl, UINT index, LPPOINT pt )
107 pt->x = (index/TILE_COUNT) * himl->cx;
108 pt->y = (index%TILE_COUNT) * himl->cy;
111 static inline void imagelist_get_bitmap_size( HIMAGELIST himl, UINT count, UINT cy, SIZE *sz )
113 sz->cx = imagelist_width( count ) * himl->cx;
114 sz->cy = cy*TILE_COUNT;
118 * imagelist_copy_images()
120 * Copies a block of count images from offset src in the list to offset dest.
121 * Images are copied a row at at time. Assumes hdcSrc and hdcDest are different.
123 static inline void imagelist_copy_images( HIMAGELIST himl, HDC hdcSrc, HDC hdcDest,
124 UINT src, UINT count, UINT dest )
126 POINT ptSrc, ptDest;
127 SIZE sz;
128 UINT i;
130 for ( i=0; i<TILE_COUNT; i++ )
132 imagelist_point_from_index( himl, src+i, &ptSrc );
133 imagelist_point_from_index( himl, dest+i, &ptDest );
134 sz.cx = himl->cx * imagelist_width( count - i );
135 sz.cy = himl->cy;
137 BitBlt( hdcDest, ptDest.x, ptDest.y, sz.cx, sz.cy,
138 hdcSrc, ptSrc.x, ptSrc.y, SRCCOPY );
142 /*************************************************************************
143 * IMAGELIST_InternalExpandBitmaps [Internal]
145 * Expands the bitmaps of an image list by the given number of images.
147 * PARAMS
148 * himl [I] handle to image list
149 * nImageCount [I] number of images to add
151 * RETURNS
152 * nothing
154 * NOTES
155 * This function CANNOT be used to reduce the number of images.
157 static void
158 IMAGELIST_InternalExpandBitmaps (HIMAGELIST himl, INT nImageCount, INT cx, INT cy)
160 HDC hdcBitmap;
161 HBITMAP hbmNewBitmap, hbmNull;
162 INT nNewCount;
163 SIZE sz;
165 if ((himl->cCurImage + nImageCount <= himl->cMaxImage)
166 && (himl->cy >= cy))
167 return;
169 if (cy == 0) cy = himl->cy;
170 nNewCount = himl->cCurImage + nImageCount + himl->cGrow;
172 imagelist_get_bitmap_size(himl, nNewCount, cy, &sz);
174 TRACE("Create expanded bitmaps : himl=%p x=%d y=%d count=%d\n", himl, sz.cx, cy, nNewCount);
175 hdcBitmap = CreateCompatibleDC (0);
177 hbmNewBitmap = ImageList_CreateImage(hdcBitmap, himl, nNewCount, cy);
179 if (hbmNewBitmap == 0)
180 ERR("creating new image bitmap (x=%d y=%d)!\n", sz.cx, cy);
182 if (himl->cCurImage)
184 hbmNull = SelectObject (hdcBitmap, hbmNewBitmap);
185 BitBlt (hdcBitmap, 0, 0, sz.cx, sz.cy,
186 himl->hdcImage, 0, 0, SRCCOPY);
187 SelectObject (hdcBitmap, hbmNull);
189 SelectObject (himl->hdcImage, hbmNewBitmap);
190 DeleteObject (himl->hbmImage);
191 himl->hbmImage = hbmNewBitmap;
193 if (himl->flags & ILC_MASK)
195 hbmNewBitmap = CreateBitmap (sz.cx, sz.cy, 1, 1, NULL);
197 if (hbmNewBitmap == 0)
198 ERR("creating new mask bitmap!\n");
200 if(himl->cCurImage)
202 hbmNull = SelectObject (hdcBitmap, hbmNewBitmap);
203 BitBlt (hdcBitmap, 0, 0, sz.cx, sz.cy,
204 himl->hdcMask, 0, 0, SRCCOPY);
205 SelectObject (hdcBitmap, hbmNull);
207 SelectObject (himl->hdcMask, hbmNewBitmap);
208 DeleteObject (himl->hbmMask);
209 himl->hbmMask = hbmNewBitmap;
212 himl->cMaxImage = nNewCount;
214 DeleteDC (hdcBitmap);
218 /*************************************************************************
219 * ImageList_Add [COMCTL32.@]
221 * Add an image or images to an image list.
223 * PARAMS
224 * himl [I] handle to image list
225 * hbmImage [I] handle to image bitmap
226 * hbmMask [I] handle to mask bitmap
228 * RETURNS
229 * Success: Index of the first new image.
230 * Failure: -1
233 INT WINAPI
234 ImageList_Add (HIMAGELIST himl, HBITMAP hbmImage, HBITMAP hbmMask)
236 HDC hdcBitmap, hdcTemp;
237 INT nFirstIndex, nImageCount, i;
238 BITMAP bmp;
239 HBITMAP hOldBitmap, hOldBitmapTemp;
240 POINT pt;
242 TRACE("himl=%p hbmimage=%p hbmmask=%p\n", himl, hbmImage, hbmMask);
243 if (!is_valid(himl))
244 return -1;
246 if (!GetObjectW(hbmImage, sizeof(BITMAP), (LPVOID)&bmp))
247 return -1;
249 nImageCount = bmp.bmWidth / himl->cx;
251 IMAGELIST_InternalExpandBitmaps (himl, nImageCount, bmp.bmWidth, bmp.bmHeight);
253 hdcBitmap = CreateCompatibleDC(0);
255 hOldBitmap = SelectObject(hdcBitmap, hbmImage);
257 for (i=0; i<nImageCount; i++)
259 imagelist_point_from_index( himl, himl->cCurImage + i, &pt );
261 /* Copy result to the imagelist
263 BitBlt( himl->hdcImage, pt.x, pt.y, himl->cx, bmp.bmHeight,
264 hdcBitmap, i*himl->cx, 0, SRCCOPY );
266 if (!himl->hbmMask)
267 continue;
269 hdcTemp = CreateCompatibleDC(0);
270 hOldBitmapTemp = SelectObject(hdcTemp, hbmMask);
272 BitBlt( himl->hdcMask, pt.x, pt.y, himl->cx, bmp.bmHeight,
273 hdcTemp, i*himl->cx, 0, SRCCOPY );
275 SelectObject(hdcTemp, hOldBitmapTemp);
276 DeleteDC(hdcTemp);
278 /* Remove the background from the image
280 BitBlt( himl->hdcImage, pt.x, pt.y, himl->cx, bmp.bmHeight,
281 himl->hdcMask, pt.x, pt.y, 0x220326 ); /* NOTSRCAND */
284 SelectObject(hdcBitmap, hOldBitmap);
285 DeleteDC(hdcBitmap);
287 nFirstIndex = himl->cCurImage;
288 himl->cCurImage += nImageCount;
290 return nFirstIndex;
294 /*************************************************************************
295 * ImageList_AddIcon [COMCTL32.@]
297 * Adds an icon to an image list.
299 * PARAMS
300 * himl [I] handle to image list
301 * hIcon [I] handle to icon
303 * RETURNS
304 * Success: index of the new image
305 * Failure: -1
307 #undef ImageList_AddIcon
308 INT WINAPI ImageList_AddIcon (HIMAGELIST himl, HICON hIcon)
310 return ImageList_ReplaceIcon (himl, -1, hIcon);
314 /*************************************************************************
315 * ImageList_AddMasked [COMCTL32.@]
317 * Adds an image or images to an image list and creates a mask from the
318 * specified bitmap using the mask color.
320 * PARAMS
321 * himl [I] handle to image list.
322 * hBitmap [I] handle to bitmap
323 * clrMask [I] mask color.
325 * RETURNS
326 * Success: Index of the first new image.
327 * Failure: -1
330 INT WINAPI
331 ImageList_AddMasked (HIMAGELIST himl, HBITMAP hBitmap, COLORREF clrMask)
333 HDC hdcMask, hdcBitmap;
334 INT i, nIndex, nImageCount;
335 BITMAP bmp;
336 HBITMAP hOldBitmap;
337 HBITMAP hMaskBitmap=0;
338 COLORREF bkColor;
339 POINT pt;
341 TRACE("himl=%p hbitmap=%p clrmask=%x\n", himl, hBitmap, clrMask);
342 if (!is_valid(himl))
343 return -1;
345 if (!GetObjectW(hBitmap, sizeof(BITMAP), &bmp))
346 return -1;
348 if (himl->cx > 0)
349 nImageCount = bmp.bmWidth / himl->cx;
350 else
351 nImageCount = 0;
353 IMAGELIST_InternalExpandBitmaps (himl, nImageCount, bmp.bmWidth, bmp.bmHeight);
355 nIndex = himl->cCurImage;
356 himl->cCurImage += nImageCount;
358 hdcBitmap = CreateCompatibleDC(0);
359 hOldBitmap = SelectObject(hdcBitmap, hBitmap);
361 /* Create a temp Mask so we can remove the background of the Image */
362 hdcMask = CreateCompatibleDC(0);
363 hMaskBitmap = CreateBitmap(bmp.bmWidth, bmp.bmHeight, 1, 1, NULL);
364 SelectObject(hdcMask, hMaskBitmap);
366 /* create monochrome image to the mask bitmap */
367 bkColor = (clrMask != CLR_DEFAULT) ? clrMask : GetPixel (hdcBitmap, 0, 0);
368 SetBkColor (hdcBitmap, bkColor);
369 BitBlt (hdcMask, 0, 0, bmp.bmWidth, bmp.bmHeight, hdcBitmap, 0, 0, SRCCOPY);
371 SetBkColor(hdcBitmap, RGB(255,255,255));
374 * Remove the background from the image
376 * WINDOWS BUG ALERT!!!!!!
377 * The statement below should not be done in common practice
378 * but this is how ImageList_AddMasked works in Windows.
379 * It overwrites the original bitmap passed, this was discovered
380 * by using the same bitmap to iterate the different styles
381 * on windows where it failed (BUT ImageList_Add is OK)
382 * This is here in case some apps rely on this bug
384 * Blt mode 0x220326 is NOTSRCAND
386 BitBlt(hdcBitmap, 0, 0, bmp.bmWidth, bmp.bmHeight, hdcMask, 0, 0, 0x220326);
388 /* Copy result to the imagelist */
389 for (i=0; i<nImageCount; i++)
391 imagelist_point_from_index( himl, nIndex + i, &pt );
392 BitBlt(himl->hdcImage, pt.x, pt.y, himl->cx, bmp.bmHeight,
393 hdcBitmap, i*himl->cx, 0, SRCCOPY);
394 BitBlt(himl->hdcMask, pt.x, pt.y, himl->cx, bmp.bmHeight,
395 hdcMask, i*himl->cx, 0, SRCCOPY);
398 /* Clean up */
399 SelectObject(hdcBitmap, hOldBitmap);
400 DeleteDC(hdcBitmap);
401 DeleteObject(hMaskBitmap);
402 DeleteDC(hdcMask);
404 return nIndex;
408 /*************************************************************************
409 * ImageList_BeginDrag [COMCTL32.@]
411 * Creates a temporary image list that contains one image. It will be used
412 * as a drag image.
414 * PARAMS
415 * himlTrack [I] handle to the source image list
416 * iTrack [I] index of the drag image in the source image list
417 * dxHotspot [I] X position of the hot spot of the drag image
418 * dyHotspot [I] Y position of the hot spot of the drag image
420 * RETURNS
421 * Success: TRUE
422 * Failure: FALSE
425 BOOL WINAPI
426 ImageList_BeginDrag (HIMAGELIST himlTrack, INT iTrack,
427 INT dxHotspot, INT dyHotspot)
429 INT cx, cy;
431 TRACE("(himlTrack=%p iTrack=%d dx=%d dy=%d)\n", himlTrack, iTrack,
432 dxHotspot, dyHotspot);
434 if (!is_valid(himlTrack))
435 return FALSE;
437 if (InternalDrag.himl)
438 ImageList_EndDrag ();
440 cx = himlTrack->cx;
441 cy = himlTrack->cy;
443 InternalDrag.himl = ImageList_Create (cx, cy, himlTrack->flags, 1, 1);
444 if (InternalDrag.himl == NULL) {
445 WARN("Error creating drag image list!\n");
446 return FALSE;
449 InternalDrag.dxHotspot = dxHotspot;
450 InternalDrag.dyHotspot = dyHotspot;
452 /* copy image */
453 BitBlt (InternalDrag.himl->hdcImage, 0, 0, cx, cy, himlTrack->hdcImage, iTrack * cx, 0, SRCCOPY);
455 /* copy mask */
456 BitBlt (InternalDrag.himl->hdcMask, 0, 0, cx, cy, himlTrack->hdcMask, iTrack * cx, 0, SRCCOPY);
458 InternalDrag.himl->cCurImage = 1;
460 return TRUE;
464 /*************************************************************************
465 * ImageList_Copy [COMCTL32.@]
467 * Copies an image of the source image list to an image of the
468 * destination image list. Images can be copied or swapped.
470 * PARAMS
471 * himlDst [I] handle to the destination image list
472 * iDst [I] destination image index.
473 * himlSrc [I] handle to the source image list
474 * iSrc [I] source image index
475 * uFlags [I] flags for the copy operation
477 * RETURNS
478 * Success: TRUE
479 * Failure: FALSE
481 * NOTES
482 * Copying from one image list to another is possible. The original
483 * implementation just copies or swaps within one image list.
484 * Could this feature become a bug??? ;-)
487 BOOL WINAPI
488 ImageList_Copy (HIMAGELIST himlDst, INT iDst, HIMAGELIST himlSrc,
489 INT iSrc, UINT uFlags)
491 POINT ptSrc, ptDst;
493 TRACE("himlDst=%p iDst=%d himlSrc=%p iSrc=%d\n", himlDst, iDst, himlSrc, iSrc);
495 if (!is_valid(himlSrc) || !is_valid(himlDst))
496 return FALSE;
497 if ((iDst < 0) || (iDst >= himlDst->cCurImage))
498 return FALSE;
499 if ((iSrc < 0) || (iSrc >= himlSrc->cCurImage))
500 return FALSE;
502 imagelist_point_from_index( himlDst, iDst, &ptDst );
503 imagelist_point_from_index( himlSrc, iSrc, &ptSrc );
505 if (uFlags & ILCF_SWAP) {
506 /* swap */
507 HDC hdcBmp;
508 HBITMAP hbmTempImage, hbmTempMask;
510 hdcBmp = CreateCompatibleDC (0);
512 /* create temporary bitmaps */
513 hbmTempImage = CreateBitmap (himlSrc->cx, himlSrc->cy, 1,
514 himlSrc->uBitsPixel, NULL);
515 hbmTempMask = CreateBitmap (himlSrc->cx, himlSrc->cy, 1,
516 1, NULL);
518 /* copy (and stretch) destination to temporary bitmaps.(save) */
519 /* image */
520 SelectObject (hdcBmp, hbmTempImage);
521 StretchBlt (hdcBmp, 0, 0, himlSrc->cx, himlSrc->cy,
522 himlDst->hdcImage, ptDst.x, ptDst.y, himlDst->cx, himlDst->cy,
523 SRCCOPY);
524 /* mask */
525 SelectObject (hdcBmp, hbmTempMask);
526 StretchBlt (hdcBmp, 0, 0, himlSrc->cx, himlSrc->cy,
527 himlDst->hdcMask, ptDst.x, ptDst.y, himlDst->cx, himlDst->cy,
528 SRCCOPY);
530 /* copy (and stretch) source to destination */
531 /* image */
532 StretchBlt (himlDst->hdcImage, ptDst.x, ptDst.y, himlDst->cx, himlDst->cy,
533 himlSrc->hdcImage, ptSrc.x, ptSrc.y, himlSrc->cx, himlSrc->cy,
534 SRCCOPY);
535 /* mask */
536 StretchBlt (himlDst->hdcMask, ptDst.x, ptDst.y, himlDst->cx, himlDst->cy,
537 himlSrc->hdcMask, ptSrc.x, ptSrc.y, himlSrc->cx, himlSrc->cy,
538 SRCCOPY);
540 /* copy (without stretching) temporary bitmaps to source (restore) */
541 /* mask */
542 BitBlt (himlSrc->hdcMask, ptSrc.x, ptSrc.y, himlSrc->cx, himlSrc->cy,
543 hdcBmp, 0, 0, SRCCOPY);
545 /* image */
546 BitBlt (himlSrc->hdcImage, ptSrc.x, ptSrc.y, himlSrc->cx, himlSrc->cy,
547 hdcBmp, 0, 0, SRCCOPY);
548 /* delete temporary bitmaps */
549 DeleteObject (hbmTempMask);
550 DeleteObject (hbmTempImage);
551 DeleteDC(hdcBmp);
553 else {
554 /* copy image */
555 StretchBlt (himlDst->hdcImage, ptDst.x, ptDst.y, himlDst->cx, himlDst->cy,
556 himlSrc->hdcImage, ptSrc.x, ptSrc.y, himlSrc->cx, himlSrc->cy,
557 SRCCOPY);
559 /* copy mask */
560 StretchBlt (himlDst->hdcMask, ptDst.x, ptDst.y, himlDst->cx, himlDst->cy,
561 himlSrc->hdcMask, ptSrc.x, ptSrc.y, himlSrc->cx, himlSrc->cy,
562 SRCCOPY);
565 return TRUE;
569 /*************************************************************************
570 * ImageList_Create [COMCTL32.@]
572 * Creates a new image list.
574 * PARAMS
575 * cx [I] image height
576 * cy [I] image width
577 * flags [I] creation flags
578 * cInitial [I] initial number of images in the image list
579 * cGrow [I] number of images by which image list grows
581 * RETURNS
582 * Success: Handle to the created image list
583 * Failure: NULL
585 HIMAGELIST WINAPI
586 ImageList_Create (INT cx, INT cy, UINT flags,
587 INT cInitial, INT cGrow)
589 HIMAGELIST himl;
590 INT nCount;
591 HBITMAP hbmTemp;
592 UINT ilc = (flags & 0xFE);
593 static const WORD aBitBlend25[] =
594 {0xAA, 0x00, 0x55, 0x00, 0xAA, 0x00, 0x55, 0x00};
596 static const WORD aBitBlend50[] =
597 {0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA};
599 TRACE("(%d %d 0x%x %d %d)\n", cx, cy, flags, cInitial, cGrow);
601 himl = (HIMAGELIST)Alloc (sizeof(struct _IMAGELIST));
602 if (!himl)
603 return NULL;
605 cGrow = (cGrow < 4) ? 4 : (cGrow + 3) & ~3;
607 himl->magic = IMAGELIST_MAGIC;
608 himl->cx = cx;
609 himl->cy = cy;
610 himl->flags = flags;
611 himl->cMaxImage = cInitial + cGrow;
612 himl->cInitial = cInitial;
613 himl->cGrow = cGrow;
614 himl->clrFg = CLR_DEFAULT;
615 himl->clrBk = CLR_NONE;
617 /* initialize overlay mask indices */
618 for (nCount = 0; nCount < MAX_OVERLAYIMAGE; nCount++)
619 himl->nOvlIdx[nCount] = -1;
621 /* Create Image & Mask DCs */
622 himl->hdcImage = CreateCompatibleDC (0);
623 if (!himl->hdcImage)
624 goto cleanup;
625 if (himl->flags & ILC_MASK){
626 himl->hdcMask = CreateCompatibleDC(0);
627 if (!himl->hdcMask)
628 goto cleanup;
631 /* Default to ILC_COLOR4 if none of the ILC_COLOR* flags are specified */
632 if (ilc == ILC_COLOR)
633 ilc = ILC_COLOR4;
635 if (ilc >= ILC_COLOR4 && ilc <= ILC_COLOR32)
636 himl->uBitsPixel = ilc;
637 else
638 himl->uBitsPixel = (UINT)GetDeviceCaps (himl->hdcImage, BITSPIXEL);
640 if (himl->cMaxImage > 0) {
641 himl->hbmImage = ImageList_CreateImage(himl->hdcImage, himl, himl->cMaxImage, cy);
642 SelectObject(himl->hdcImage, himl->hbmImage);
643 } else
644 himl->hbmImage = 0;
646 if ((himl->cMaxImage > 0) && (himl->flags & ILC_MASK)) {
647 SIZE sz;
649 imagelist_get_bitmap_size(himl, himl->cMaxImage, himl->cy, &sz);
650 himl->hbmMask = CreateBitmap (sz.cx, sz.cy, 1, 1, NULL);
651 if (himl->hbmMask == 0) {
652 ERR("Error creating mask bitmap!\n");
653 goto cleanup;
655 SelectObject(himl->hdcMask, himl->hbmMask);
657 else
658 himl->hbmMask = 0;
660 /* create blending brushes */
661 hbmTemp = CreateBitmap (8, 8, 1, 1, &aBitBlend25);
662 himl->hbrBlend25 = CreatePatternBrush (hbmTemp);
663 DeleteObject (hbmTemp);
665 hbmTemp = CreateBitmap (8, 8, 1, 1, &aBitBlend50);
666 himl->hbrBlend50 = CreatePatternBrush (hbmTemp);
667 DeleteObject (hbmTemp);
669 TRACE("created imagelist %p\n", himl);
670 return himl;
672 cleanup:
673 if (himl) ImageList_Destroy(himl);
674 return NULL;
678 /*************************************************************************
679 * ImageList_Destroy [COMCTL32.@]
681 * Destroys an image list.
683 * PARAMS
684 * himl [I] handle to image list
686 * RETURNS
687 * Success: TRUE
688 * Failure: FALSE
691 BOOL WINAPI
692 ImageList_Destroy (HIMAGELIST himl)
694 if (!is_valid(himl))
695 return FALSE;
697 /* delete image bitmaps */
698 if (himl->hbmImage)
699 DeleteObject (himl->hbmImage);
700 if (himl->hbmMask)
701 DeleteObject (himl->hbmMask);
703 /* delete image & mask DCs */
704 if (himl->hdcImage)
705 DeleteDC(himl->hdcImage);
706 if (himl->hdcMask)
707 DeleteDC(himl->hdcMask);
709 /* delete blending brushes */
710 if (himl->hbrBlend25)
711 DeleteObject (himl->hbrBlend25);
712 if (himl->hbrBlend50)
713 DeleteObject (himl->hbrBlend50);
715 ZeroMemory(himl, sizeof(*himl));
716 Free (himl);
718 return TRUE;
722 /*************************************************************************
723 * ImageList_DragEnter [COMCTL32.@]
725 * Locks window update and displays the drag image at the given position.
727 * PARAMS
728 * hwndLock [I] handle of the window that owns the drag image.
729 * x [I] X position of the drag image.
730 * y [I] Y position of the drag image.
732 * RETURNS
733 * Success: TRUE
734 * Failure: FALSE
736 * NOTES
737 * The position of the drag image is relative to the window, not
738 * the client area.
741 BOOL WINAPI
742 ImageList_DragEnter (HWND hwndLock, INT x, INT y)
744 TRACE("(hwnd=%p x=%d y=%d)\n", hwndLock, x, y);
746 if (!is_valid(InternalDrag.himl))
747 return FALSE;
749 if (hwndLock)
750 InternalDrag.hwnd = hwndLock;
751 else
752 InternalDrag.hwnd = GetDesktopWindow ();
754 InternalDrag.x = x;
755 InternalDrag.y = y;
757 /* draw the drag image and save the background */
758 if (!ImageList_DragShowNolock(TRUE)) {
759 return FALSE;
762 return TRUE;
766 /*************************************************************************
767 * ImageList_DragLeave [COMCTL32.@]
769 * Unlocks window update and hides the drag image.
771 * PARAMS
772 * hwndLock [I] handle of the window that owns the drag image.
774 * RETURNS
775 * Success: TRUE
776 * Failure: FALSE
779 BOOL WINAPI
780 ImageList_DragLeave (HWND hwndLock)
782 /* As we don't save drag info in the window this can lead to problems if
783 an app does not supply the same window as DragEnter */
784 /* if (hwndLock)
785 InternalDrag.hwnd = hwndLock;
786 else
787 InternalDrag.hwnd = GetDesktopWindow (); */
788 if(!hwndLock)
789 hwndLock = GetDesktopWindow();
790 if(InternalDrag.hwnd != hwndLock)
791 FIXME("DragLeave hWnd != DragEnter hWnd\n");
793 ImageList_DragShowNolock (FALSE);
795 return TRUE;
799 /*************************************************************************
800 * ImageList_InternalDragDraw [Internal]
802 * Draws the drag image.
804 * PARAMS
805 * hdc [I] device context to draw into.
806 * x [I] X position of the drag image.
807 * y [I] Y position of the drag image.
809 * RETURNS
810 * Success: TRUE
811 * Failure: FALSE
813 * NOTES
814 * The position of the drag image is relative to the window, not
815 * the client area.
819 static inline void
820 ImageList_InternalDragDraw (HDC hdc, INT x, INT y)
822 IMAGELISTDRAWPARAMS imldp;
824 ZeroMemory (&imldp, sizeof(imldp));
825 imldp.cbSize = sizeof(imldp);
826 imldp.himl = InternalDrag.himl;
827 imldp.i = 0;
828 imldp.hdcDst = hdc,
829 imldp.x = x;
830 imldp.y = y;
831 imldp.rgbBk = CLR_DEFAULT;
832 imldp.rgbFg = CLR_DEFAULT;
833 imldp.fStyle = ILD_NORMAL;
834 imldp.fState = ILS_ALPHA;
835 imldp.Frame = 128;
837 /* FIXME: instead of using the alpha blending, we should
838 * create a 50% mask, and draw it semitransparantly that way */
839 ImageList_DrawIndirect (&imldp);
842 /*************************************************************************
843 * ImageList_DragMove [COMCTL32.@]
845 * Moves the drag image.
847 * PARAMS
848 * x [I] X position of the drag image.
849 * y [I] Y position of the drag image.
851 * RETURNS
852 * Success: TRUE
853 * Failure: FALSE
855 * NOTES
856 * The position of the drag image is relative to the window, not
857 * the client area.
859 * BUGS
860 * The drag image should be drawn semitransparent.
863 BOOL WINAPI
864 ImageList_DragMove (INT x, INT y)
866 TRACE("(x=%d y=%d)\n", x, y);
868 if (!is_valid(InternalDrag.himl))
869 return FALSE;
871 /* draw/update the drag image */
872 if (InternalDrag.bShow) {
873 HDC hdcDrag;
874 HDC hdcOffScreen;
875 HDC hdcBg;
876 HBITMAP hbmOffScreen;
877 INT origNewX, origNewY;
878 INT origOldX, origOldY;
879 INT origRegX, origRegY;
880 INT sizeRegX, sizeRegY;
883 /* calculate the update region */
884 origNewX = x - InternalDrag.dxHotspot;
885 origNewY = y - InternalDrag.dyHotspot;
886 origOldX = InternalDrag.x - InternalDrag.dxHotspot;
887 origOldY = InternalDrag.y - InternalDrag.dyHotspot;
888 origRegX = min(origNewX, origOldX);
889 origRegY = min(origNewY, origOldY);
890 sizeRegX = InternalDrag.himl->cx + abs(x - InternalDrag.x);
891 sizeRegY = InternalDrag.himl->cy + abs(y - InternalDrag.y);
893 hdcDrag = GetDCEx(InternalDrag.hwnd, 0,
894 DCX_WINDOW | DCX_CACHE | DCX_LOCKWINDOWUPDATE);
895 hdcOffScreen = CreateCompatibleDC(hdcDrag);
896 hdcBg = CreateCompatibleDC(hdcDrag);
898 hbmOffScreen = CreateCompatibleBitmap(hdcDrag, sizeRegX, sizeRegY);
899 SelectObject(hdcOffScreen, hbmOffScreen);
900 SelectObject(hdcBg, InternalDrag.hbmBg);
902 /* get the actual background of the update region */
903 BitBlt(hdcOffScreen, 0, 0, sizeRegX, sizeRegY, hdcDrag,
904 origRegX, origRegY, SRCCOPY);
905 /* erase the old image */
906 BitBlt(hdcOffScreen, origOldX - origRegX, origOldY - origRegY,
907 InternalDrag.himl->cx, InternalDrag.himl->cy, hdcBg, 0, 0,
908 SRCCOPY);
909 /* save the background */
910 BitBlt(hdcBg, 0, 0, InternalDrag.himl->cx, InternalDrag.himl->cy,
911 hdcOffScreen, origNewX - origRegX, origNewY - origRegY, SRCCOPY);
912 /* draw the image */
913 ImageList_InternalDragDraw(hdcOffScreen, origNewX - origRegX,
914 origNewY - origRegY);
915 /* draw the update region to the screen */
916 BitBlt(hdcDrag, origRegX, origRegY, sizeRegX, sizeRegY,
917 hdcOffScreen, 0, 0, SRCCOPY);
919 DeleteDC(hdcBg);
920 DeleteDC(hdcOffScreen);
921 DeleteObject(hbmOffScreen);
922 ReleaseDC(InternalDrag.hwnd, hdcDrag);
925 /* update the image position */
926 InternalDrag.x = x;
927 InternalDrag.y = y;
929 return TRUE;
933 /*************************************************************************
934 * ImageList_DragShowNolock [COMCTL32.@]
936 * Shows or hides the drag image.
938 * PARAMS
939 * bShow [I] TRUE shows the drag image, FALSE hides it.
941 * RETURNS
942 * Success: TRUE
943 * Failure: FALSE
945 * BUGS
946 * The drag image should be drawn semitransparent.
949 BOOL WINAPI
950 ImageList_DragShowNolock (BOOL bShow)
952 HDC hdcDrag;
953 HDC hdcBg;
954 INT x, y;
956 if (!is_valid(InternalDrag.himl))
957 return FALSE;
959 TRACE("bShow=0x%X!\n", bShow);
961 /* DragImage is already visible/hidden */
962 if ((InternalDrag.bShow && bShow) || (!InternalDrag.bShow && !bShow)) {
963 return FALSE;
966 /* position of the origin of the DragImage */
967 x = InternalDrag.x - InternalDrag.dxHotspot;
968 y = InternalDrag.y - InternalDrag.dyHotspot;
970 hdcDrag = GetDCEx (InternalDrag.hwnd, 0,
971 DCX_WINDOW | DCX_CACHE | DCX_LOCKWINDOWUPDATE);
972 if (!hdcDrag) {
973 return FALSE;
976 hdcBg = CreateCompatibleDC(hdcDrag);
977 if (!InternalDrag.hbmBg) {
978 InternalDrag.hbmBg = CreateCompatibleBitmap(hdcDrag,
979 InternalDrag.himl->cx, InternalDrag.himl->cy);
981 SelectObject(hdcBg, InternalDrag.hbmBg);
983 if (bShow) {
984 /* save the background */
985 BitBlt(hdcBg, 0, 0, InternalDrag.himl->cx, InternalDrag.himl->cy,
986 hdcDrag, x, y, SRCCOPY);
987 /* show the image */
988 ImageList_InternalDragDraw(hdcDrag, x, y);
989 } else {
990 /* hide the image */
991 BitBlt(hdcDrag, x, y, InternalDrag.himl->cx, InternalDrag.himl->cy,
992 hdcBg, 0, 0, SRCCOPY);
995 InternalDrag.bShow = !InternalDrag.bShow;
997 DeleteDC(hdcBg);
998 ReleaseDC (InternalDrag.hwnd, hdcDrag);
999 return TRUE;
1003 /*************************************************************************
1004 * ImageList_Draw [COMCTL32.@]
1006 * Draws an image.
1008 * PARAMS
1009 * himl [I] handle to image list
1010 * i [I] image index
1011 * hdc [I] handle to device context
1012 * x [I] x position
1013 * y [I] y position
1014 * fStyle [I] drawing flags
1016 * RETURNS
1017 * Success: TRUE
1018 * Failure: FALSE
1020 * SEE
1021 * ImageList_DrawEx.
1024 BOOL WINAPI
1025 ImageList_Draw (HIMAGELIST himl, INT i, HDC hdc, INT x, INT y, UINT fStyle)
1027 return ImageList_DrawEx (himl, i, hdc, x, y, 0, 0,
1028 CLR_DEFAULT, CLR_DEFAULT, fStyle);
1032 /*************************************************************************
1033 * ImageList_DrawEx [COMCTL32.@]
1035 * Draws an image and allows to use extended drawing features.
1037 * PARAMS
1038 * himl [I] handle to image list
1039 * i [I] image index
1040 * hdc [I] handle to device context
1041 * x [I] X position
1042 * y [I] Y position
1043 * dx [I] X offset
1044 * dy [I] Y offset
1045 * rgbBk [I] background color
1046 * rgbFg [I] foreground color
1047 * fStyle [I] drawing flags
1049 * RETURNS
1050 * Success: TRUE
1051 * Failure: FALSE
1053 * NOTES
1054 * Calls ImageList_DrawIndirect.
1056 * SEE
1057 * ImageList_DrawIndirect.
1060 BOOL WINAPI
1061 ImageList_DrawEx (HIMAGELIST himl, INT i, HDC hdc, INT x, INT y,
1062 INT dx, INT dy, COLORREF rgbBk, COLORREF rgbFg,
1063 UINT fStyle)
1065 IMAGELISTDRAWPARAMS imldp;
1067 ZeroMemory (&imldp, sizeof(imldp));
1068 imldp.cbSize = sizeof(imldp);
1069 imldp.himl = himl;
1070 imldp.i = i;
1071 imldp.hdcDst = hdc,
1072 imldp.x = x;
1073 imldp.y = y;
1074 imldp.cx = dx;
1075 imldp.cy = dy;
1076 imldp.rgbBk = rgbBk;
1077 imldp.rgbFg = rgbFg;
1078 imldp.fStyle = fStyle;
1080 return ImageList_DrawIndirect (&imldp);
1084 /*************************************************************************
1085 * ImageList_DrawIndirect [COMCTL32.@]
1087 * Draws an image using various parameters specified in pimldp.
1089 * PARAMS
1090 * pimldp [I] pointer to IMAGELISTDRAWPARAMS structure.
1092 * RETURNS
1093 * Success: TRUE
1094 * Failure: FALSE
1097 BOOL WINAPI
1098 ImageList_DrawIndirect (IMAGELISTDRAWPARAMS *pimldp)
1100 INT cx, cy, nOvlIdx;
1101 DWORD fState, dwRop;
1102 UINT fStyle;
1103 COLORREF oldImageBk, oldImageFg;
1104 HDC hImageDC, hImageListDC, hMaskListDC;
1105 HBITMAP hImageBmp, hOldImageBmp, hBlendMaskBmp;
1106 BOOL bIsTransparent, bBlend, bResult = FALSE, bMask;
1107 HIMAGELIST himl;
1108 POINT pt;
1110 if (!pimldp || !(himl = pimldp->himl)) return FALSE;
1111 if (!is_valid(himl)) return FALSE;
1112 if ((pimldp->i < 0) || (pimldp->i >= himl->cCurImage)) return FALSE;
1114 imagelist_point_from_index( himl, pimldp->i, &pt );
1115 pt.x += pimldp->xBitmap;
1116 pt.y += pimldp->yBitmap;
1118 fState = pimldp->cbSize < sizeof(IMAGELISTDRAWPARAMS) ? ILS_NORMAL : pimldp->fState;
1119 fStyle = pimldp->fStyle & ~ILD_OVERLAYMASK;
1120 cx = (pimldp->cx == 0) ? himl->cx : pimldp->cx;
1121 cy = (pimldp->cy == 0) ? himl->cy : pimldp->cy;
1123 bIsTransparent = (fStyle & ILD_TRANSPARENT);
1124 if( pimldp->rgbBk == CLR_NONE )
1125 bIsTransparent = TRUE;
1126 if( ( pimldp->rgbBk == CLR_DEFAULT ) && ( himl->clrBk == CLR_NONE ) )
1127 bIsTransparent = TRUE;
1128 bMask = (himl->flags & ILC_MASK) && (fStyle & ILD_MASK) ;
1129 bBlend = (fStyle & (ILD_BLEND25 | ILD_BLEND50) ) && !bMask;
1131 TRACE("himl(%p) hbmMask(%p) iImage(%d) x(%d) y(%d) cx(%d) cy(%d)\n",
1132 himl, himl->hbmMask, pimldp->i, pimldp->x, pimldp->y, cx, cy);
1134 /* we will use these DCs to access the images and masks in the ImageList */
1135 hImageListDC = himl->hdcImage;
1136 hMaskListDC = himl->hdcMask;
1138 /* these will accumulate the image and mask for the image we're drawing */
1139 hImageDC = CreateCompatibleDC( pimldp->hdcDst );
1140 hImageBmp = CreateCompatibleBitmap( pimldp->hdcDst, cx, cy );
1141 hBlendMaskBmp = bBlend ? CreateBitmap(cx, cy, 1, 1, NULL) : 0;
1143 /* Create a compatible DC. */
1144 if (!hImageListDC || !hImageDC || !hImageBmp ||
1145 (bBlend && !hBlendMaskBmp) || (himl->hbmMask && !hMaskListDC))
1146 goto cleanup;
1148 hOldImageBmp = SelectObject(hImageDC, hImageBmp);
1151 * To obtain a transparent look, background color should be set
1152 * to white and foreground color to black when blting the
1153 * monochrome mask.
1155 oldImageFg = SetTextColor( hImageDC, RGB( 0, 0, 0 ) );
1156 oldImageBk = SetBkColor( hImageDC, RGB( 0xff, 0xff, 0xff ) );
1159 * Draw the initial image
1161 if( bMask ) {
1162 if (himl->hbmMask) {
1163 HBRUSH hOldBrush;
1164 hOldBrush = SelectObject (hImageDC, CreateSolidBrush (GetTextColor(pimldp->hdcDst)));
1165 PatBlt( hImageDC, 0, 0, cx, cy, PATCOPY );
1166 BitBlt(hImageDC, 0, 0, cx, cy, hMaskListDC, pt.x, pt.y, SRCPAINT);
1167 DeleteObject (SelectObject (hImageDC, hOldBrush));
1168 if( bIsTransparent )
1170 BitBlt ( pimldp->hdcDst, pimldp->x, pimldp->y, cx, cy, hImageDC, 0, 0, SRCAND);
1171 bResult = TRUE;
1172 goto end;
1174 } else {
1175 HBRUSH hOldBrush = SelectObject (hImageDC, GetStockObject(BLACK_BRUSH));
1176 PatBlt( hImageDC, 0, 0, cx, cy, PATCOPY);
1177 SelectObject(hImageDC, hOldBrush);
1179 } else {
1180 /* blend the image with the needed solid background */
1181 COLORREF colour = RGB(0,0,0);
1182 HBRUSH hOldBrush;
1184 if( !bIsTransparent )
1186 colour = pimldp->rgbBk;
1187 if( colour == CLR_DEFAULT )
1188 colour = himl->clrBk;
1189 if( colour == CLR_NONE )
1190 colour = GetBkColor(pimldp->hdcDst);
1193 hOldBrush = SelectObject (hImageDC, CreateSolidBrush (colour));
1194 PatBlt( hImageDC, 0, 0, cx, cy, PATCOPY );
1195 BitBlt( hImageDC, 0, 0, cx, cy, hMaskListDC, pt.x, pt.y, SRCAND );
1196 BitBlt( hImageDC, 0, 0, cx, cy, hImageListDC, pt.x, pt.y, SRCPAINT );
1197 DeleteObject (SelectObject (hImageDC, hOldBrush));
1200 /* Time for blending, if required */
1201 if (bBlend) {
1202 HBRUSH hBlendBrush, hOldBrush;
1203 COLORREF clrBlend = pimldp->rgbFg;
1204 HDC hBlendMaskDC = hImageListDC;
1205 HBITMAP hOldBitmap;
1207 /* Create the blend Mask */
1208 hOldBitmap = SelectObject(hBlendMaskDC, hBlendMaskBmp);
1209 hBlendBrush = fStyle & ILD_BLEND50 ? himl->hbrBlend50 : himl->hbrBlend25;
1210 hOldBrush = (HBRUSH) SelectObject(hBlendMaskDC, hBlendBrush);
1211 PatBlt(hBlendMaskDC, 0, 0, cx, cy, PATCOPY);
1212 SelectObject(hBlendMaskDC, hOldBrush);
1214 /* Modify the blend mask if an Image Mask exist */
1215 if(himl->hbmMask) {
1216 BitBlt(hBlendMaskDC, 0, 0, cx, cy, hMaskListDC, pt.x, pt.y, 0x220326); /* NOTSRCAND */
1217 BitBlt(hBlendMaskDC, 0, 0, cx, cy, hBlendMaskDC, 0, 0, NOTSRCCOPY);
1220 /* now apply blend to the current image given the BlendMask */
1221 if (clrBlend == CLR_DEFAULT) clrBlend = GetSysColor (COLOR_HIGHLIGHT);
1222 else if (clrBlend == CLR_NONE) clrBlend = GetTextColor (pimldp->hdcDst);
1223 hOldBrush = (HBRUSH) SelectObject (hImageDC, CreateSolidBrush(clrBlend));
1224 BitBlt (hImageDC, 0, 0, cx, cy, hBlendMaskDC, 0, 0, 0xB8074A); /* PSDPxax */
1225 DeleteObject(SelectObject(hImageDC, hOldBrush));
1226 SelectObject(hBlendMaskDC, hOldBitmap);
1229 /* Now do the overlay image, if any */
1230 nOvlIdx = (pimldp->fStyle & ILD_OVERLAYMASK) >> 8;
1231 if ( (nOvlIdx >= 1) && (nOvlIdx <= MAX_OVERLAYIMAGE)) {
1232 nOvlIdx = himl->nOvlIdx[nOvlIdx - 1];
1233 if ((nOvlIdx >= 0) && (nOvlIdx < himl->cCurImage)) {
1234 POINT ptOvl;
1235 imagelist_point_from_index( himl, nOvlIdx, &ptOvl );
1236 ptOvl.x += pimldp->xBitmap;
1237 if (himl->hbmMask && !(fStyle & ILD_IMAGE))
1238 BitBlt (hImageDC, 0, 0, cx, cy, hMaskListDC, ptOvl.x, ptOvl.y, SRCAND);
1239 BitBlt (hImageDC, 0, 0, cx, cy, hImageListDC, ptOvl.x, ptOvl.y, SRCPAINT);
1243 if (fState & ILS_SATURATE) FIXME("ILS_SATURATE: unimplemented!\n");
1244 if (fState & ILS_GLOW) FIXME("ILS_GLOW: unimplemented!\n");
1245 if (fState & ILS_SHADOW) FIXME("ILS_SHADOW: unimplemented!\n");
1246 if (fState & ILS_ALPHA) FIXME("ILS_ALPHA: unimplemented!\n");
1248 if (fStyle & ILD_PRESERVEALPHA) FIXME("ILD_PRESERVEALPHA: unimplemented!\n");
1249 if (fStyle & ILD_SCALE) FIXME("ILD_SCALE: unimplemented!\n");
1250 if (fStyle & ILD_DPISCALE) FIXME("ILD_DPISCALE: unimplemented!\n");
1252 /* now copy the image to the screen */
1253 dwRop = SRCCOPY;
1254 if (himl->hbmMask && bIsTransparent ) {
1255 COLORREF oldDstFg = SetTextColor(pimldp->hdcDst, RGB( 0, 0, 0 ) );
1256 COLORREF oldDstBk = SetBkColor(pimldp->hdcDst, RGB( 0xff, 0xff, 0xff ));
1257 BitBlt (pimldp->hdcDst, pimldp->x, pimldp->y, cx, cy, hMaskListDC, pt.x, pt.y, SRCAND);
1258 SetBkColor(pimldp->hdcDst, oldDstBk);
1259 SetTextColor(pimldp->hdcDst, oldDstFg);
1260 dwRop = SRCPAINT;
1262 if (fStyle & ILD_ROP) dwRop = pimldp->dwRop;
1263 BitBlt (pimldp->hdcDst, pimldp->x, pimldp->y, cx, cy, hImageDC, 0, 0, dwRop);
1265 bResult = TRUE;
1266 end:
1267 /* cleanup the mess */
1268 SetBkColor(hImageDC, oldImageBk);
1269 SetTextColor(hImageDC, oldImageFg);
1270 SelectObject(hImageDC, hOldImageBmp);
1271 cleanup:
1272 DeleteObject(hBlendMaskBmp);
1273 DeleteObject(hImageBmp);
1274 DeleteDC(hImageDC);
1276 return bResult;
1280 /*************************************************************************
1281 * ImageList_Duplicate [COMCTL32.@]
1283 * Duplicates an image list.
1285 * PARAMS
1286 * himlSrc [I] source image list handle
1288 * RETURNS
1289 * Success: Handle of duplicated image list.
1290 * Failure: NULL
1293 HIMAGELIST WINAPI
1294 ImageList_Duplicate (HIMAGELIST himlSrc)
1296 HIMAGELIST himlDst;
1298 if (!is_valid(himlSrc)) {
1299 ERR("Invalid image list handle!\n");
1300 return NULL;
1303 himlDst = ImageList_Create (himlSrc->cx, himlSrc->cy, himlSrc->flags,
1304 himlSrc->cInitial, himlSrc->cGrow);
1306 if (himlDst)
1308 SIZE sz;
1310 imagelist_get_bitmap_size(himlSrc, himlSrc->cCurImage, himlSrc->cy, &sz);
1311 BitBlt (himlDst->hdcImage, 0, 0, sz.cx, sz.cy,
1312 himlSrc->hdcImage, 0, 0, SRCCOPY);
1314 if (himlDst->hbmMask)
1315 BitBlt (himlDst->hdcMask, 0, 0, sz.cx, sz.cy,
1316 himlSrc->hdcMask, 0, 0, SRCCOPY);
1318 himlDst->cCurImage = himlSrc->cCurImage;
1319 himlDst->cMaxImage = himlSrc->cMaxImage;
1321 return himlDst;
1325 /*************************************************************************
1326 * ImageList_EndDrag [COMCTL32.@]
1328 * Finishes a drag operation.
1330 * PARAMS
1331 * no Parameters
1333 * RETURNS
1334 * Success: TRUE
1335 * Failure: FALSE
1338 VOID WINAPI
1339 ImageList_EndDrag (void)
1341 /* cleanup the InternalDrag struct */
1342 InternalDrag.hwnd = 0;
1343 ImageList_Destroy (InternalDrag.himl);
1344 InternalDrag.himl = 0;
1345 InternalDrag.x= 0;
1346 InternalDrag.y= 0;
1347 InternalDrag.dxHotspot = 0;
1348 InternalDrag.dyHotspot = 0;
1349 InternalDrag.bShow = FALSE;
1350 DeleteObject(InternalDrag.hbmBg);
1351 InternalDrag.hbmBg = 0;
1355 /*************************************************************************
1356 * ImageList_GetBkColor [COMCTL32.@]
1358 * Returns the background color of an image list.
1360 * PARAMS
1361 * himl [I] Image list handle.
1363 * RETURNS
1364 * Success: background color
1365 * Failure: CLR_NONE
1368 COLORREF WINAPI
1369 ImageList_GetBkColor (HIMAGELIST himl)
1371 return himl ? himl->clrBk : CLR_NONE;
1375 /*************************************************************************
1376 * ImageList_GetDragImage [COMCTL32.@]
1378 * Returns the handle to the internal drag image list.
1380 * PARAMS
1381 * ppt [O] Pointer to the drag position. Can be NULL.
1382 * pptHotspot [O] Pointer to the position of the hot spot. Can be NULL.
1384 * RETURNS
1385 * Success: Handle of the drag image list.
1386 * Failure: NULL.
1389 HIMAGELIST WINAPI
1390 ImageList_GetDragImage (POINT *ppt, POINT *pptHotspot)
1392 if (is_valid(InternalDrag.himl)) {
1393 if (ppt) {
1394 ppt->x = InternalDrag.x;
1395 ppt->y = InternalDrag.y;
1397 if (pptHotspot) {
1398 pptHotspot->x = InternalDrag.dxHotspot;
1399 pptHotspot->y = InternalDrag.dyHotspot;
1401 return (InternalDrag.himl);
1404 return NULL;
1408 /*************************************************************************
1409 * ImageList_GetFlags [COMCTL32.@]
1411 * Gets the flags of the specified image list.
1413 * PARAMS
1414 * himl [I] Handle to image list
1416 * RETURNS
1417 * Image list flags.
1419 * BUGS
1420 * Stub.
1423 DWORD WINAPI
1424 ImageList_GetFlags(HIMAGELIST himl)
1426 FIXME("(%p):empty stub\n", himl);
1427 return 0;
1431 /*************************************************************************
1432 * ImageList_GetIcon [COMCTL32.@]
1434 * Creates an icon from a masked image of an image list.
1436 * PARAMS
1437 * himl [I] handle to image list
1438 * i [I] image index
1439 * flags [I] drawing style flags
1441 * RETURNS
1442 * Success: icon handle
1443 * Failure: NULL
1446 HICON WINAPI
1447 ImageList_GetIcon (HIMAGELIST himl, INT i, UINT fStyle)
1449 ICONINFO ii;
1450 HICON hIcon;
1451 HBITMAP hOldDstBitmap;
1452 HDC hdcDst;
1453 POINT pt;
1455 TRACE("%p %d %d\n", himl, i, fStyle);
1456 if (!is_valid(himl) || (i < 0) || (i >= himl->cCurImage)) return NULL;
1458 ii.fIcon = TRUE;
1459 ii.xHotspot = 0;
1460 ii.yHotspot = 0;
1462 /* create colour bitmap */
1463 hdcDst = GetDC(0);
1464 ii.hbmColor = CreateCompatibleBitmap(hdcDst, himl->cx, himl->cy);
1465 ReleaseDC(0, hdcDst);
1467 hdcDst = CreateCompatibleDC(0);
1469 imagelist_point_from_index( himl, i, &pt );
1471 /* draw mask*/
1472 ii.hbmMask = CreateBitmap (himl->cx, himl->cy, 1, 1, NULL);
1473 hOldDstBitmap = SelectObject (hdcDst, ii.hbmMask);
1474 if (himl->hbmMask) {
1475 BitBlt (hdcDst, 0, 0, himl->cx, himl->cy,
1476 himl->hdcMask, pt.x, pt.y, SRCCOPY);
1478 else
1479 PatBlt (hdcDst, 0, 0, himl->cx, himl->cy, BLACKNESS);
1481 /* draw image*/
1482 SelectObject (hdcDst, ii.hbmColor);
1483 BitBlt (hdcDst, 0, 0, himl->cx, himl->cy,
1484 himl->hdcImage, pt.x, pt.y, SRCCOPY);
1487 * CreateIconIndirect requires us to deselect the bitmaps from
1488 * the DCs before calling
1490 SelectObject(hdcDst, hOldDstBitmap);
1492 hIcon = CreateIconIndirect (&ii);
1494 DeleteObject (ii.hbmMask);
1495 DeleteObject (ii.hbmColor);
1496 DeleteDC (hdcDst);
1498 return hIcon;
1502 /*************************************************************************
1503 * ImageList_GetIconSize [COMCTL32.@]
1505 * Retrieves the size of an image in an image list.
1507 * PARAMS
1508 * himl [I] handle to image list
1509 * cx [O] pointer to the image width.
1510 * cy [O] pointer to the image height.
1512 * RETURNS
1513 * Success: TRUE
1514 * Failure: FALSE
1516 * NOTES
1517 * All images in an image list have the same size.
1520 BOOL WINAPI
1521 ImageList_GetIconSize (HIMAGELIST himl, INT *cx, INT *cy)
1523 if (!is_valid(himl))
1524 return FALSE;
1525 if ((himl->cx <= 0) || (himl->cy <= 0))
1526 return FALSE;
1528 if (cx)
1529 *cx = himl->cx;
1530 if (cy)
1531 *cy = himl->cy;
1533 return TRUE;
1537 /*************************************************************************
1538 * ImageList_GetImageCount [COMCTL32.@]
1540 * Returns the number of images in an image list.
1542 * PARAMS
1543 * himl [I] handle to image list
1545 * RETURNS
1546 * Success: Number of images.
1547 * Failure: 0
1550 INT WINAPI
1551 ImageList_GetImageCount (HIMAGELIST himl)
1553 if (!is_valid(himl))
1554 return 0;
1556 return himl->cCurImage;
1560 /*************************************************************************
1561 * ImageList_GetImageInfo [COMCTL32.@]
1563 * Returns information about an image in an image list.
1565 * PARAMS
1566 * himl [I] handle to image list
1567 * i [I] image index
1568 * pImageInfo [O] pointer to the image information
1570 * RETURNS
1571 * Success: TRUE
1572 * Failure: FALSE
1575 BOOL WINAPI
1576 ImageList_GetImageInfo (HIMAGELIST himl, INT i, IMAGEINFO *pImageInfo)
1578 POINT pt;
1580 if (!is_valid(himl) || (pImageInfo == NULL))
1581 return FALSE;
1582 if ((i < 0) || (i >= himl->cCurImage))
1583 return FALSE;
1585 pImageInfo->hbmImage = himl->hbmImage;
1586 pImageInfo->hbmMask = himl->hbmMask;
1588 imagelist_point_from_index( himl, i, &pt );
1589 pImageInfo->rcImage.top = pt.y;
1590 pImageInfo->rcImage.bottom = pt.y + himl->cy;
1591 pImageInfo->rcImage.left = pt.x;
1592 pImageInfo->rcImage.right = pt.x + himl->cx;
1594 return TRUE;
1598 /*************************************************************************
1599 * ImageList_GetImageRect [COMCTL32.@]
1601 * Retrieves the rectangle of the specified image in an image list.
1603 * PARAMS
1604 * himl [I] handle to image list
1605 * i [I] image index
1606 * lpRect [O] pointer to the image rectangle
1608 * RETURNS
1609 * Success: TRUE
1610 * Failure: FALSE
1612 * NOTES
1613 * This is an UNDOCUMENTED function!!!
1616 BOOL WINAPI
1617 ImageList_GetImageRect (HIMAGELIST himl, INT i, LPRECT lpRect)
1619 POINT pt;
1621 if (!is_valid(himl) || (lpRect == NULL))
1622 return FALSE;
1623 if ((i < 0) || (i >= himl->cCurImage))
1624 return FALSE;
1626 imagelist_point_from_index( himl, i, &pt );
1627 lpRect->left = pt.x;
1628 lpRect->top = pt.y;
1629 lpRect->right = pt.x + himl->cx;
1630 lpRect->bottom = pt.y + himl->cy;
1632 return TRUE;
1636 /*************************************************************************
1637 * ImageList_LoadImage [COMCTL32.@]
1638 * ImageList_LoadImageA [COMCTL32.@]
1640 * Creates an image list from a bitmap, icon or cursor.
1642 * See ImageList_LoadImageW.
1645 HIMAGELIST WINAPI
1646 ImageList_LoadImageA (HINSTANCE hi, LPCSTR lpbmp, INT cx, INT cGrow,
1647 COLORREF clrMask, UINT uType, UINT uFlags)
1649 HIMAGELIST himl;
1650 LPWSTR lpbmpW;
1651 DWORD len;
1653 if (!HIWORD(lpbmp))
1654 return ImageList_LoadImageW(hi, (LPCWSTR)lpbmp, cx, cGrow, clrMask,
1655 uType, uFlags);
1657 len = MultiByteToWideChar(CP_ACP, 0, lpbmp, -1, NULL, 0);
1658 lpbmpW = Alloc(len * sizeof(WCHAR));
1659 MultiByteToWideChar(CP_ACP, 0, lpbmp, -1, lpbmpW, len);
1661 himl = ImageList_LoadImageW(hi, lpbmpW, cx, cGrow, clrMask, uType, uFlags);
1662 Free (lpbmpW);
1663 return himl;
1667 /*************************************************************************
1668 * ImageList_LoadImageW [COMCTL32.@]
1670 * Creates an image list from a bitmap, icon or cursor.
1672 * PARAMS
1673 * hi [I] instance handle
1674 * lpbmp [I] name or id of the image
1675 * cx [I] width of each image
1676 * cGrow [I] number of images to expand
1677 * clrMask [I] mask color
1678 * uType [I] type of image to load
1679 * uFlags [I] loading flags
1681 * RETURNS
1682 * Success: handle to the loaded image list
1683 * Failure: NULL
1685 * SEE
1686 * LoadImage ()
1689 HIMAGELIST WINAPI
1690 ImageList_LoadImageW (HINSTANCE hi, LPCWSTR lpbmp, INT cx, INT cGrow,
1691 COLORREF clrMask, UINT uType, UINT uFlags)
1693 HIMAGELIST himl = NULL;
1694 HANDLE handle;
1695 INT nImageCount;
1697 handle = LoadImageW (hi, lpbmp, uType, 0, 0, uFlags);
1698 if (!handle) {
1699 ERR("Error loading image!\n");
1700 return NULL;
1703 if (uType == IMAGE_BITMAP) {
1704 BITMAP bmp;
1705 GetObjectW (handle, sizeof(BITMAP), &bmp);
1707 /* To match windows behavior, if cx is set to zero and
1708 the flag DI_DEFAULTSIZE is specified, cx becomes the
1709 system metric value for icons. If the flag is not specified
1710 the function sets the size to the height of the bitmap */
1711 if (cx == 0)
1713 if (uFlags & DI_DEFAULTSIZE)
1714 cx = GetSystemMetrics (SM_CXICON);
1715 else
1716 cx = bmp.bmHeight;
1719 nImageCount = bmp.bmWidth / cx;
1721 himl = ImageList_Create (cx, bmp.bmHeight, ILC_MASK | ILC_COLOR,
1722 nImageCount, cGrow);
1723 if (!himl) {
1724 DeleteObject (handle);
1725 return NULL;
1727 ImageList_AddMasked (himl, (HBITMAP)handle, clrMask);
1729 else if ((uType == IMAGE_ICON) || (uType == IMAGE_CURSOR)) {
1730 ICONINFO ii;
1731 BITMAP bmp;
1733 GetIconInfo (handle, &ii);
1734 GetObjectW (ii.hbmColor, sizeof(BITMAP), (LPVOID)&bmp);
1735 himl = ImageList_Create (bmp.bmWidth, bmp.bmHeight,
1736 ILC_MASK | ILC_COLOR, 1, cGrow);
1737 if (!himl) {
1738 DeleteObject (ii.hbmColor);
1739 DeleteObject (ii.hbmMask);
1740 DeleteObject (handle);
1741 return NULL;
1743 ImageList_Add (himl, ii.hbmColor, ii.hbmMask);
1744 DeleteObject (ii.hbmColor);
1745 DeleteObject (ii.hbmMask);
1748 DeleteObject (handle);
1750 return himl;
1754 /*************************************************************************
1755 * ImageList_Merge [COMCTL32.@]
1757 * Create an image list containing a merged image from two image lists.
1759 * PARAMS
1760 * himl1 [I] handle to first image list
1761 * i1 [I] first image index
1762 * himl2 [I] handle to second image list
1763 * i2 [I] second image index
1764 * dx [I] X offset of the second image relative to the first.
1765 * dy [I] Y offset of the second image relative to the first.
1767 * RETURNS
1768 * Success: The newly created image list. It contains a single image
1769 * consisting of the second image merged with the first.
1770 * Failure: NULL, if either himl1 or himl2 are invalid.
1772 * NOTES
1773 * - The returned image list should be deleted by the caller using
1774 * ImageList_Destroy() when it is no longer required.
1775 * - If either i1 or i2 are not valid image indices they will be treated
1776 * as a blank image.
1778 HIMAGELIST WINAPI
1779 ImageList_Merge (HIMAGELIST himl1, INT i1, HIMAGELIST himl2, INT i2,
1780 INT dx, INT dy)
1782 HIMAGELIST himlDst = NULL;
1783 INT cxDst, cyDst;
1784 INT xOff1, yOff1, xOff2, yOff2;
1785 POINT pt1, pt2;
1787 TRACE("(himl1=%p i1=%d himl2=%p i2=%d dx=%d dy=%d)\n", himl1, i1, himl2,
1788 i2, dx, dy);
1790 if (!is_valid(himl1) || !is_valid(himl2))
1791 return NULL;
1793 if (dx > 0) {
1794 cxDst = max (himl1->cx, dx + himl2->cx);
1795 xOff1 = 0;
1796 xOff2 = dx;
1798 else if (dx < 0) {
1799 cxDst = max (himl2->cx, himl1->cx - dx);
1800 xOff1 = -dx;
1801 xOff2 = 0;
1803 else {
1804 cxDst = max (himl1->cx, himl2->cx);
1805 xOff1 = 0;
1806 xOff2 = 0;
1809 if (dy > 0) {
1810 cyDst = max (himl1->cy, dy + himl2->cy);
1811 yOff1 = 0;
1812 yOff2 = dy;
1814 else if (dy < 0) {
1815 cyDst = max (himl2->cy, himl1->cy - dy);
1816 yOff1 = -dy;
1817 yOff2 = 0;
1819 else {
1820 cyDst = max (himl1->cy, himl2->cy);
1821 yOff1 = 0;
1822 yOff2 = 0;
1825 himlDst = ImageList_Create (cxDst, cyDst, ILC_MASK | ILC_COLOR, 1, 1);
1827 if (himlDst)
1829 imagelist_point_from_index( himl1, i1, &pt1 );
1830 imagelist_point_from_index( himl1, i2, &pt2 );
1832 /* copy image */
1833 BitBlt (himlDst->hdcImage, 0, 0, cxDst, cyDst, himl1->hdcImage, 0, 0, BLACKNESS);
1834 if (i1 >= 0 && i1 < himl1->cCurImage)
1835 BitBlt (himlDst->hdcImage, xOff1, yOff1, himl1->cx, himl1->cy, himl1->hdcImage, pt1.x, pt1.y, SRCCOPY);
1836 if (i2 >= 0 && i2 < himl2->cCurImage)
1838 BitBlt (himlDst->hdcImage, xOff2, yOff2, himl2->cx, himl2->cy, himl2->hdcMask , pt2.x, pt2.y, SRCAND);
1839 BitBlt (himlDst->hdcImage, xOff2, yOff2, himl2->cx, himl2->cy, himl2->hdcImage, pt2.x, pt2.y, SRCPAINT);
1842 /* copy mask */
1843 BitBlt (himlDst->hdcMask, 0, 0, cxDst, cyDst, himl1->hdcMask, 0, 0, WHITENESS);
1844 if (i1 >= 0 && i1 < himl1->cCurImage)
1845 BitBlt (himlDst->hdcMask, xOff1, yOff1, himl1->cx, himl1->cy, himl1->hdcMask, pt1.x, pt1.y, SRCCOPY);
1846 if (i2 >= 0 && i2 < himl2->cCurImage)
1847 BitBlt (himlDst->hdcMask, xOff2, yOff2, himl2->cx, himl2->cy, himl2->hdcMask, pt2.x, pt2.y, SRCAND);
1849 himlDst->cCurImage = 1;
1852 return himlDst;
1856 /* helper for _read_bitmap currently unused */
1857 #if 0
1858 static int may_use_dibsection(HDC hdc) {
1859 int bitspixel = GetDeviceCaps(hdc,BITSPIXEL)*GetDeviceCaps(hdc,PLANES);
1860 if (bitspixel>8)
1861 return TRUE;
1862 if (bitspixel<=4)
1863 return FALSE;
1864 return GetDeviceCaps(hdc,CAPS1) & C1_DIBENGINE;
1866 #endif
1868 /* helper for ImageList_Read, see comments below */
1869 static BOOL _read_bitmap(HIMAGELIST himl, HDC hdcIml, LPSTREAM pstm, int ilcFlag)
1871 HDC xdc = 0;
1872 BITMAPFILEHEADER bmfh;
1873 BITMAPINFOHEADER bmih;
1874 int bitsperpixel,palspace,longsperline,width,height;
1875 LPBITMAPINFO bmi = NULL;
1876 int result = FALSE;
1877 HBITMAP hDIB = 0;
1878 LPBYTE bits = NULL;
1879 int i, j, nheight, nRows, nCols;
1880 POINT pt;
1881 int cy = himl->cy;
1883 if (!SUCCEEDED(IStream_Read ( pstm, &bmfh, sizeof(bmfh), NULL)))
1884 return result;
1886 if (bmfh.bfType != (('M'<<8)|'B'))
1887 return result;
1889 if (!SUCCEEDED(IStream_Read ( pstm, &bmih, sizeof(bmih), NULL)))
1890 return result;
1892 if ((bmih.biSize != sizeof(bmih)))
1893 return 0;
1895 bitsperpixel = bmih.biPlanes * bmih.biBitCount;
1896 if (bitsperpixel<=8)
1897 palspace = (1<<bitsperpixel)*sizeof(RGBQUAD);
1898 else
1899 palspace = 0;
1900 width = bmih.biWidth;
1901 height = bmih.biHeight;
1902 bmi = Alloc(sizeof(bmih)+palspace);
1903 if (!bmi)
1904 return result;
1906 memcpy(bmi, &bmih, sizeof(bmih));
1907 longsperline = ((width*bitsperpixel+31)&~0x1f)>>5;
1908 bmi->bmiHeader.biSizeImage = (longsperline*height)<<2;
1910 /* read the palette right after the end of the bitmapinfoheader */
1911 if (palspace && !SUCCEEDED(IStream_Read(pstm, bmi->bmiColors, palspace, NULL)))
1912 goto error;
1914 xdc = GetDC(0);
1916 nheight = cy;
1917 nRows = height/cy;
1918 nCols = width/himl->cx;
1920 hDIB = CreateDIBSection(xdc, bmi, 0, (LPVOID*) &bits, 0, 0);
1921 if (!hDIB)
1922 goto error;
1923 if (!SUCCEEDED(IStream_Read(pstm, bits, bmi->bmiHeader.biSizeImage, NULL)))
1924 goto error;
1926 /* Copy the NxM bitmap into a 1x(N*M) bitmap we need, linewise */
1927 /* Do not forget that windows bitmaps are bottom->top */
1928 for (i=0; i < nRows; i++) {
1929 for (j=0; j < nCols; j++) {
1930 imagelist_point_from_index(himl, i*nCols + j, &pt);
1931 StretchDIBits(hdcIml, pt.x, pt.y, himl->cx, cy,
1932 j*himl->cx, (nRows - 1 - i)*himl->cy, himl->cx, cy, bits,
1933 bmi, DIB_RGB_COLORS, SRCCOPY);
1937 result = TRUE;
1938 error:
1939 if (xdc) ReleaseDC(0,xdc);
1940 Free(bmi);
1941 if (hDIB) DeleteObject(hDIB);
1942 return result;
1945 /*************************************************************************
1946 * ImageList_Read [COMCTL32.@]
1948 * Reads an image list from a stream.
1950 * PARAMS
1951 * pstm [I] pointer to a stream
1953 * RETURNS
1954 * Success: handle to image list
1955 * Failure: NULL
1957 * The format is like this:
1958 * ILHEAD ilheadstruct;
1960 * for the color image part:
1961 * BITMAPFILEHEADER bmfh;
1962 * BITMAPINFOHEADER bmih;
1963 * only if it has a palette:
1964 * RGBQUAD rgbs[nr_of_paletted_colors];
1966 * BYTE colorbits[imagesize];
1968 * the following only if the ILC_MASK bit is set in ILHEAD.ilFlags:
1969 * BITMAPFILEHEADER bmfh_mask;
1970 * BITMAPINFOHEADER bmih_mask;
1971 * only if it has a palette (it usually does not):
1972 * RGBQUAD rgbs[nr_of_paletted_colors];
1974 * BYTE maskbits[imagesize];
1976 * CAVEAT: Those images are within a NxM bitmap, not the 1xN we expect.
1977 * _read_bitmap needs to convert them.
1979 HIMAGELIST WINAPI ImageList_Read (LPSTREAM pstm)
1981 ILHEAD ilHead;
1982 HIMAGELIST himl;
1983 HBITMAP hbmColor=0,hbmMask=0;
1984 int i;
1986 TRACE("%p\n", pstm);
1988 if (!SUCCEEDED(IStream_Read (pstm, &ilHead, sizeof(ILHEAD), NULL)))
1989 return NULL;
1990 if (ilHead.usMagic != (('L' << 8) | 'I'))
1991 return NULL;
1992 if (ilHead.usVersion != 0x101) /* probably version? */
1993 return NULL;
1995 himl = ImageList_Create(ilHead.cx, ilHead.cy, ilHead.flags, ilHead.cCurImage, ilHead.cMaxImage);
1996 if (!himl) {
1997 DeleteObject(hbmColor);
1998 DeleteObject(hbmMask);
1999 return NULL;
2001 if (!_read_bitmap(himl, himl->hdcImage, pstm, ilHead.flags & ~ILC_MASK)) {
2002 WARN("failed to read bitmap from stream\n");
2003 return NULL;
2005 if (ilHead.flags & ILC_MASK) {
2006 if (!_read_bitmap(himl, himl->hdcMask, pstm, 0)) {
2007 DeleteObject(hbmColor);
2008 return NULL;
2012 SelectObject(himl->hdcImage, hbmColor);
2013 DeleteObject(himl->hbmImage);
2014 himl->hbmImage = hbmColor;
2015 if (hbmMask){
2016 SelectObject(himl->hdcMask, hbmMask);
2017 DeleteObject(himl->hbmMask);
2018 himl->hbmMask = hbmMask;
2020 himl->cCurImage = ilHead.cCurImage;
2021 himl->cMaxImage = ilHead.cMaxImage;
2023 ImageList_SetBkColor(himl,ilHead.bkcolor);
2024 for (i=0;i<4;i++)
2025 ImageList_SetOverlayImage(himl,ilHead.ovls[i],i+1);
2026 return himl;
2030 /*************************************************************************
2031 * ImageList_Remove [COMCTL32.@]
2033 * Removes an image from an image list
2035 * PARAMS
2036 * himl [I] image list handle
2037 * i [I] image index
2039 * RETURNS
2040 * Success: TRUE
2041 * Failure: FALSE
2044 BOOL WINAPI
2045 ImageList_Remove (HIMAGELIST himl, INT i)
2047 HBITMAP hbmNewImage, hbmNewMask;
2048 HDC hdcBmp;
2049 INT nCount;
2050 SIZE sz;
2052 TRACE("(himl=%p i=%d)\n", himl, i);
2054 if (!is_valid(himl)) {
2055 ERR("Invalid image list handle!\n");
2056 return FALSE;
2059 if ((i < -1) || (i >= himl->cCurImage)) {
2060 TRACE("index out of range! %d\n", i);
2061 return FALSE;
2064 if (i == -1) {
2065 /* remove all */
2066 if (himl->cCurImage == 0) {
2067 /* remove all on empty ImageList is allowed */
2068 TRACE("remove all on empty ImageList!\n");
2069 return TRUE;
2072 himl->cMaxImage = himl->cInitial + himl->cGrow;
2073 himl->cCurImage = 0;
2074 for (nCount = 0; nCount < MAX_OVERLAYIMAGE; nCount++)
2075 himl->nOvlIdx[nCount] = -1;
2077 hbmNewImage = ImageList_CreateImage(himl->hdcImage, himl, himl->cMaxImage, himl->cy);
2078 SelectObject (himl->hdcImage, hbmNewImage);
2079 DeleteObject (himl->hbmImage);
2080 himl->hbmImage = hbmNewImage;
2082 if (himl->hbmMask) {
2084 imagelist_get_bitmap_size(himl, himl->cMaxImage, himl->cy, &sz);
2085 hbmNewMask = CreateBitmap (sz.cx, sz.cy, 1, 1, NULL);
2086 SelectObject (himl->hdcMask, hbmNewMask);
2087 DeleteObject (himl->hbmMask);
2088 himl->hbmMask = hbmNewMask;
2091 else {
2092 /* delete one image */
2093 TRACE("Remove single image! %d\n", i);
2095 /* create new bitmap(s) */
2096 nCount = (himl->cCurImage + himl->cGrow - 1);
2098 TRACE(" - Number of images: %d / %d (Old/New)\n",
2099 himl->cCurImage, himl->cCurImage - 1);
2100 TRACE(" - Max. number of images: %d / %d (Old/New)\n",
2101 himl->cMaxImage, himl->cCurImage + himl->cGrow - 1);
2103 hbmNewImage = ImageList_CreateImage(himl->hdcImage, himl, nCount, himl->cy);
2105 imagelist_get_bitmap_size(himl, nCount, himl->cy, &sz );
2106 if (himl->hbmMask)
2107 hbmNewMask = CreateBitmap (sz.cx, sz.cy, 1, 1, NULL);
2108 else
2109 hbmNewMask = 0; /* Just to keep compiler happy! */
2111 hdcBmp = CreateCompatibleDC (0);
2113 /* copy all images and masks prior to the "removed" image */
2114 if (i > 0) {
2115 TRACE("Pre image copy: Copy %d images\n", i);
2117 SelectObject (hdcBmp, hbmNewImage);
2118 imagelist_copy_images( himl, himl->hdcImage, hdcBmp, 0, i, 0 );
2120 if (himl->hbmMask) {
2121 SelectObject (hdcBmp, hbmNewMask);
2122 imagelist_copy_images( himl, himl->hdcMask, hdcBmp, 0, i, 0 );
2126 /* copy all images and masks behind the removed image */
2127 if (i < himl->cCurImage - 1) {
2128 TRACE("Post image copy!\n");
2130 SelectObject (hdcBmp, hbmNewImage);
2131 imagelist_copy_images( himl, himl->hdcImage, hdcBmp, i,
2132 (himl->cCurImage - i - 1), i + 1 );
2134 if (himl->hbmMask) {
2135 SelectObject (hdcBmp, hbmNewMask);
2136 imagelist_copy_images( himl, himl->hdcMask, hdcBmp, i,
2137 (himl->cCurImage - i - 1), i + 1 );
2141 DeleteDC (hdcBmp);
2143 /* delete old images and insert new ones */
2144 SelectObject (himl->hdcImage, hbmNewImage);
2145 DeleteObject (himl->hbmImage);
2146 himl->hbmImage = hbmNewImage;
2147 if (himl->hbmMask) {
2148 SelectObject (himl->hdcMask, hbmNewMask);
2149 DeleteObject (himl->hbmMask);
2150 himl->hbmMask = hbmNewMask;
2153 himl->cCurImage--;
2154 himl->cMaxImage = himl->cCurImage + himl->cGrow;
2157 return TRUE;
2161 /*************************************************************************
2162 * ImageList_Replace [COMCTL32.@]
2164 * Replaces an image in an image list with a new image.
2166 * PARAMS
2167 * himl [I] handle to image list
2168 * i [I] image index
2169 * hbmImage [I] handle to image bitmap
2170 * hbmMask [I] handle to mask bitmap. Can be NULL.
2172 * RETURNS
2173 * Success: TRUE
2174 * Failure: FALSE
2177 BOOL WINAPI
2178 ImageList_Replace (HIMAGELIST himl, INT i, HBITMAP hbmImage,
2179 HBITMAP hbmMask)
2181 HDC hdcImage;
2182 BITMAP bmp;
2183 HBITMAP hOldBitmap;
2184 POINT pt;
2186 TRACE("%p %d %p %p\n", himl, i, hbmImage, hbmMask);
2188 if (!is_valid(himl)) {
2189 ERR("Invalid image list handle!\n");
2190 return FALSE;
2193 if ((i >= himl->cMaxImage) || (i < 0)) {
2194 ERR("Invalid image index!\n");
2195 return FALSE;
2198 if (!GetObjectW(hbmImage, sizeof(BITMAP), (LPVOID)&bmp))
2199 return FALSE;
2201 hdcImage = CreateCompatibleDC (0);
2203 /* Replace Image */
2204 hOldBitmap = SelectObject (hdcImage, hbmImage);
2206 imagelist_point_from_index(himl, i, &pt);
2207 StretchBlt (himl->hdcImage, pt.x, pt.y, himl->cx, himl->cy,
2208 hdcImage, 0, 0, bmp.bmWidth, bmp.bmHeight, SRCCOPY);
2210 if (himl->hbmMask)
2212 HDC hdcTemp;
2213 HBITMAP hOldBitmapTemp;
2215 hdcTemp = CreateCompatibleDC(0);
2216 hOldBitmapTemp = SelectObject(hdcTemp, hbmMask);
2218 StretchBlt (himl->hdcMask, pt.x, pt.y, himl->cx, himl->cy,
2219 hdcTemp, 0, 0, bmp.bmWidth, bmp.bmHeight, SRCCOPY);
2220 SelectObject(hdcTemp, hOldBitmapTemp);
2221 DeleteDC(hdcTemp);
2223 /* Remove the background from the image
2225 BitBlt (himl->hdcImage, pt.x, pt.y, bmp.bmWidth, bmp.bmHeight,
2226 himl->hdcMask, pt.x, pt.y, 0x220326); /* NOTSRCAND */
2229 SelectObject (hdcImage, hOldBitmap);
2230 DeleteDC (hdcImage);
2232 return TRUE;
2236 /*************************************************************************
2237 * ImageList_ReplaceIcon [COMCTL32.@]
2239 * Replaces an image in an image list using an icon.
2241 * PARAMS
2242 * himl [I] handle to image list
2243 * i [I] image index
2244 * hIcon [I] handle to icon
2246 * RETURNS
2247 * Success: index of the replaced image
2248 * Failure: -1
2251 INT WINAPI
2252 ImageList_ReplaceIcon (HIMAGELIST himl, INT i, HICON hIcon)
2254 HDC hdcImage;
2255 INT nIndex;
2256 HICON hBestFitIcon;
2257 HBITMAP hbmOldSrc;
2258 ICONINFO ii;
2259 BITMAP bmp;
2260 BOOL ret;
2261 POINT pt;
2263 TRACE("(%p %d %p)\n", himl, i, hIcon);
2265 if (!is_valid(himl)) {
2266 ERR("invalid image list\n");
2267 return -1;
2269 if ((i >= himl->cMaxImage) || (i < -1)) {
2270 ERR("invalid image index %d / %d\n", i, himl->cMaxImage);
2271 return -1;
2274 hBestFitIcon = CopyImage(
2275 hIcon, IMAGE_ICON,
2276 himl->cx, himl->cy,
2277 LR_COPYFROMRESOURCE);
2278 /* the above will fail if the icon wasn't loaded from a resource, so try
2279 * again without LR_COPYFROMRESOURCE flag */
2280 if (!hBestFitIcon)
2281 hBestFitIcon = CopyImage(
2282 hIcon, IMAGE_ICON,
2283 himl->cx, himl->cy,
2285 if (!hBestFitIcon)
2286 return -1;
2288 ret = GetIconInfo (hBestFitIcon, &ii);
2289 if (!ret) {
2290 DestroyIcon(hBestFitIcon);
2291 return -1;
2294 if (ii.hbmColor == 0)
2295 ERR("no color!\n");
2296 ret = GetObjectW (ii.hbmMask, sizeof(BITMAP), (LPVOID)&bmp);
2297 if (!ret) {
2298 ERR("couldn't get mask bitmap info\n");
2299 if (ii.hbmColor)
2300 DeleteObject (ii.hbmColor);
2301 if (ii.hbmMask)
2302 DeleteObject (ii.hbmMask);
2303 DestroyIcon(hBestFitIcon);
2304 return -1;
2307 if (i == -1) {
2308 if (himl->cCurImage + 1 > himl->cMaxImage)
2309 IMAGELIST_InternalExpandBitmaps (himl, 1, 0, 0);
2311 nIndex = himl->cCurImage;
2312 himl->cCurImage++;
2314 else
2315 nIndex = i;
2317 hdcImage = CreateCompatibleDC (0);
2318 TRACE("hdcImage=%p\n", hdcImage);
2319 if (hdcImage == 0)
2320 ERR("invalid hdcImage!\n");
2322 SetTextColor(himl->hdcImage, RGB(0,0,0));
2323 SetBkColor (himl->hdcImage, RGB(255,255,255));
2324 hbmOldSrc = SelectObject (hdcImage, ii.hbmColor);
2326 imagelist_point_from_index(himl, nIndex, &pt);
2327 StretchBlt (himl->hdcImage, pt.x, pt.y, himl->cx, himl->cy,
2328 hdcImage, 0, 0, bmp.bmWidth, bmp.bmHeight, SRCCOPY);
2330 if (himl->hbmMask) {
2331 SelectObject (hdcImage, ii.hbmMask);
2332 StretchBlt (himl->hdcMask, pt.x, pt.y, himl->cx, himl->cy,
2333 hdcImage, 0, 0, bmp.bmWidth, bmp.bmHeight, SRCCOPY);
2336 SelectObject (hdcImage, hbmOldSrc);
2338 DestroyIcon(hBestFitIcon);
2339 if (hdcImage)
2340 DeleteDC (hdcImage);
2341 if (ii.hbmColor)
2342 DeleteObject (ii.hbmColor);
2343 if (ii.hbmMask)
2344 DeleteObject (ii.hbmMask);
2346 TRACE("Insert index = %d, himl->cCurImage = %d\n", nIndex, himl->cCurImage);
2347 return nIndex;
2351 /*************************************************************************
2352 * ImageList_SetBkColor [COMCTL32.@]
2354 * Sets the background color of an image list.
2356 * PARAMS
2357 * himl [I] handle to image list
2358 * clrBk [I] background color
2360 * RETURNS
2361 * Success: previous background color
2362 * Failure: CLR_NONE
2365 COLORREF WINAPI
2366 ImageList_SetBkColor (HIMAGELIST himl, COLORREF clrBk)
2368 COLORREF clrOldBk;
2370 if (!is_valid(himl))
2371 return CLR_NONE;
2373 clrOldBk = himl->clrBk;
2374 himl->clrBk = clrBk;
2375 return clrOldBk;
2379 /*************************************************************************
2380 * ImageList_SetDragCursorImage [COMCTL32.@]
2382 * Combines the specified image with the current drag image
2384 * PARAMS
2385 * himlDrag [I] handle to drag image list
2386 * iDrag [I] drag image index
2387 * dxHotspot [I] X position of the hot spot
2388 * dyHotspot [I] Y position of the hot spot
2390 * RETURNS
2391 * Success: TRUE
2392 * Failure: FALSE
2394 * NOTES
2395 * - The names dxHotspot, dyHotspot are misleading because they have nothing
2396 * to do with a hotspot but are only the offset of the origin of the new
2397 * image relative to the origin of the old image.
2399 * - When this function is called and the drag image is visible, a
2400 * short flickering occurs but this matches the Win9x behavior. It is
2401 * possible to fix the flickering using code like in ImageList_DragMove.
2404 BOOL WINAPI
2405 ImageList_SetDragCursorImage (HIMAGELIST himlDrag, INT iDrag,
2406 INT dxHotspot, INT dyHotspot)
2408 HIMAGELIST himlTemp;
2409 BOOL visible;
2411 if (!is_valid(InternalDrag.himl) || !is_valid(himlDrag))
2412 return FALSE;
2414 TRACE(" dxH=%d dyH=%d nX=%d nY=%d\n",
2415 dxHotspot, dyHotspot, InternalDrag.dxHotspot, InternalDrag.dyHotspot);
2417 visible = InternalDrag.bShow;
2419 himlTemp = ImageList_Merge (InternalDrag.himl, 0, himlDrag, iDrag,
2420 dxHotspot, dyHotspot);
2422 if (visible) {
2423 /* hide the drag image */
2424 ImageList_DragShowNolock(FALSE);
2426 if ((InternalDrag.himl->cx != himlTemp->cx) ||
2427 (InternalDrag.himl->cy != himlTemp->cy)) {
2428 /* the size of the drag image changed, invalidate the buffer */
2429 DeleteObject(InternalDrag.hbmBg);
2430 InternalDrag.hbmBg = 0;
2433 ImageList_Destroy (InternalDrag.himl);
2434 InternalDrag.himl = himlTemp;
2436 if (visible) {
2437 /* show the drag image */
2438 ImageList_DragShowNolock(TRUE);
2441 return TRUE;
2445 /*************************************************************************
2446 * ImageList_SetFilter [COMCTL32.@]
2448 * Sets a filter (or does something completely different)!!???
2449 * It removes 12 Bytes from the stack (3 Parameters).
2451 * PARAMS
2452 * himl [I] SHOULD be a handle to image list
2453 * i [I] COULD be an index?
2454 * dwFilter [I] ???
2456 * RETURNS
2457 * Success: TRUE ???
2458 * Failure: FALSE ???
2460 * BUGS
2461 * This is an UNDOCUMENTED function!!!!
2462 * empty stub.
2465 BOOL WINAPI
2466 ImageList_SetFilter (HIMAGELIST himl, INT i, DWORD dwFilter)
2468 FIXME("(%p 0x%x 0x%x):empty stub!\n", himl, i, dwFilter);
2470 return FALSE;
2474 /*************************************************************************
2475 * ImageList_SetFlags [COMCTL32.@]
2477 * Sets the image list flags.
2479 * PARAMS
2480 * himl [I] Handle to image list
2481 * flags [I] Flags to set
2483 * RETURNS
2484 * Old flags?
2486 * BUGS
2487 * Stub.
2490 DWORD WINAPI
2491 ImageList_SetFlags(HIMAGELIST himl, DWORD flags)
2493 FIXME("(%p %08x):empty stub\n", himl, flags);
2494 return 0;
2498 /*************************************************************************
2499 * ImageList_SetIconSize [COMCTL32.@]
2501 * Sets the image size of the bitmap and deletes all images.
2503 * PARAMS
2504 * himl [I] handle to image list
2505 * cx [I] image width
2506 * cy [I] image height
2508 * RETURNS
2509 * Success: TRUE
2510 * Failure: FALSE
2513 BOOL WINAPI
2514 ImageList_SetIconSize (HIMAGELIST himl, INT cx, INT cy)
2516 INT nCount;
2517 HBITMAP hbmNew;
2519 if (!is_valid(himl))
2520 return FALSE;
2522 /* remove all images */
2523 himl->cMaxImage = himl->cInitial + himl->cGrow;
2524 himl->cCurImage = 0;
2525 himl->cx = cx;
2526 himl->cy = cy;
2528 /* initialize overlay mask indices */
2529 for (nCount = 0; nCount < MAX_OVERLAYIMAGE; nCount++)
2530 himl->nOvlIdx[nCount] = -1;
2532 hbmNew = ImageList_CreateImage(himl->hdcImage, himl, himl->cMaxImage, himl->cy);
2533 SelectObject (himl->hdcImage, hbmNew);
2534 DeleteObject (himl->hbmImage);
2535 himl->hbmImage = hbmNew;
2537 if (himl->hbmMask) {
2538 SIZE sz;
2539 imagelist_get_bitmap_size(himl, himl->cMaxImage, himl->cy, &sz);
2540 hbmNew = CreateBitmap (sz.cx, sz.cy, 1, 1, NULL);
2541 SelectObject (himl->hdcMask, hbmNew);
2542 DeleteObject (himl->hbmMask);
2543 himl->hbmMask = hbmNew;
2546 return TRUE;
2550 /*************************************************************************
2551 * ImageList_SetImageCount [COMCTL32.@]
2553 * Resizes an image list to the specified number of images.
2555 * PARAMS
2556 * himl [I] handle to image list
2557 * iImageCount [I] number of images in the image list
2559 * RETURNS
2560 * Success: TRUE
2561 * Failure: FALSE
2564 BOOL WINAPI
2565 ImageList_SetImageCount (HIMAGELIST himl, UINT iImageCount)
2567 HDC hdcBitmap;
2568 HBITMAP hbmNewBitmap;
2569 INT nNewCount, nCopyCount;
2571 TRACE("%p %d\n",himl,iImageCount);
2573 if (!is_valid(himl))
2574 return FALSE;
2575 if (iImageCount < 0)
2576 return FALSE;
2577 if (himl->cMaxImage > iImageCount)
2579 himl->cCurImage = iImageCount;
2580 /* TODO: shrink the bitmap when cMaxImage-cCurImage>cGrow ? */
2581 return TRUE;
2584 nNewCount = iImageCount + himl->cGrow;
2585 nCopyCount = min(himl->cCurImage, iImageCount);
2587 hdcBitmap = CreateCompatibleDC (0);
2589 hbmNewBitmap = ImageList_CreateImage(hdcBitmap, himl, nNewCount, himl->cy);
2591 if (hbmNewBitmap != 0)
2593 SelectObject (hdcBitmap, hbmNewBitmap);
2594 imagelist_copy_images( himl, himl->hdcImage, hdcBitmap, 0, nCopyCount, 0 );
2596 /* FIXME: delete 'empty' image space? */
2598 SelectObject (himl->hdcImage, hbmNewBitmap);
2599 DeleteObject (himl->hbmImage);
2600 himl->hbmImage = hbmNewBitmap;
2602 else
2603 ERR("Could not create new image bitmap !\n");
2605 if (himl->hbmMask)
2607 SIZE sz;
2608 imagelist_get_bitmap_size( himl, nNewCount, himl->cy, &sz );
2609 hbmNewBitmap = CreateBitmap (sz.cx, sz.cy, 1, 1, NULL);
2610 if (hbmNewBitmap != 0)
2612 SelectObject (hdcBitmap, hbmNewBitmap);
2613 imagelist_copy_images( himl, himl->hdcMask, hdcBitmap, 0, nCopyCount, 0 );
2615 /* FIXME: delete 'empty' image space? */
2617 SelectObject (himl->hdcMask, hbmNewBitmap);
2618 DeleteObject (himl->hbmMask);
2619 himl->hbmMask = hbmNewBitmap;
2621 else
2622 ERR("Could not create new mask bitmap!\n");
2625 DeleteDC (hdcBitmap);
2627 /* Update max image count and current image count */
2628 himl->cMaxImage = nNewCount;
2629 himl->cCurImage = iImageCount;
2631 return TRUE;
2635 /*************************************************************************
2636 * ImageList_SetOverlayImage [COMCTL32.@]
2638 * Assigns an overlay mask index to an existing image in an image list.
2640 * PARAMS
2641 * himl [I] handle to image list
2642 * iImage [I] image index
2643 * iOverlay [I] overlay mask index
2645 * RETURNS
2646 * Success: TRUE
2647 * Failure: FALSE
2650 BOOL WINAPI
2651 ImageList_SetOverlayImage (HIMAGELIST himl, INT iImage, INT iOverlay)
2653 if (!is_valid(himl))
2654 return FALSE;
2655 if ((iOverlay < 1) || (iOverlay > MAX_OVERLAYIMAGE))
2656 return FALSE;
2657 if ((iImage!=-1) && ((iImage < 0) || (iImage > himl->cCurImage)))
2658 return FALSE;
2659 himl->nOvlIdx[iOverlay - 1] = iImage;
2660 return TRUE;
2665 /* helper for ImageList_Write - write bitmap to pstm
2666 * currently everything is written as 24 bit RGB, except masks
2668 static BOOL
2669 _write_bitmap(HBITMAP hBitmap, LPSTREAM pstm, int cx, int cy)
2671 LPBITMAPFILEHEADER bmfh;
2672 LPBITMAPINFOHEADER bmih;
2673 LPBYTE data = NULL, lpBits = NULL, lpBitsOrg = NULL;
2674 BITMAP bm;
2675 INT bitCount, sizeImage, offBits, totalSize;
2676 INT nwidth, nheight, nsizeImage, icount;
2677 HDC xdc;
2678 BOOL result = FALSE;
2681 xdc = GetDC(0);
2682 if (!GetObjectW(hBitmap, sizeof(BITMAP), (LPVOID)&bm))
2683 goto failed;
2685 /* XXX is this always correct? */
2686 icount = bm.bmWidth / cx;
2687 nwidth = cx;
2688 nheight = cy * icount;
2690 bitCount = bm.bmBitsPixel == 1 ? 1 : 24;
2691 sizeImage = ((((bm.bmWidth * bitCount)+31) & ~31) >> 3) * bm.bmHeight;
2692 nsizeImage = ((((nwidth * bitCount)+31) & ~31) >> 3) * nheight;
2694 totalSize = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);
2695 if(bitCount != 24)
2696 totalSize += (1 << bitCount) * sizeof(RGBQUAD);
2697 offBits = totalSize;
2698 totalSize += nsizeImage;
2700 data = (LPBYTE)LocalAlloc(LMEM_ZEROINIT, totalSize);
2701 bmfh = (LPBITMAPFILEHEADER)data;
2702 bmih = (LPBITMAPINFOHEADER)(data + sizeof(BITMAPFILEHEADER));
2703 lpBits = data + offBits;
2705 /* setup BITMAPFILEHEADER */
2706 bmfh->bfType = (('M' << 8) | 'B');
2707 bmfh->bfSize = 0;
2708 bmfh->bfReserved1 = 0;
2709 bmfh->bfReserved2 = 0;
2710 bmfh->bfOffBits = offBits;
2712 /* setup BITMAPINFOHEADER */
2713 bmih->biSize = sizeof(BITMAPINFOHEADER);
2714 bmih->biWidth = bm.bmWidth;
2715 bmih->biHeight = bm.bmHeight;
2716 bmih->biPlanes = 1;
2717 bmih->biBitCount = bitCount;
2718 bmih->biCompression = BI_RGB;
2719 bmih->biSizeImage = sizeImage;
2720 bmih->biXPelsPerMeter = 0;
2721 bmih->biYPelsPerMeter = 0;
2722 bmih->biClrUsed = 0;
2723 bmih->biClrImportant = 0;
2725 lpBitsOrg = (LPBYTE)LocalAlloc(LMEM_ZEROINIT, sizeImage);
2726 if(!GetDIBits(xdc, hBitmap, 0, bm.bmHeight, lpBitsOrg,
2727 (BITMAPINFO *)bmih, DIB_RGB_COLORS))
2728 goto failed;
2729 else {
2730 int i;
2731 int obpl = (((bm.bmWidth*bitCount+31) & ~31)>>3);
2732 int nbpl = (((nwidth*bitCount+31) & ~31)>>3);
2734 for(i = 0; i < nheight; i++) {
2735 int ooff = ((nheight-1-i)%cy) * obpl + ((i/cy) * nbpl);
2736 int noff = (nbpl * (nheight-1-i));
2737 memcpy(lpBits + noff, lpBitsOrg + ooff, nbpl);
2741 bmih->biWidth = nwidth;
2742 bmih->biHeight = nheight;
2743 bmih->biSizeImage = nsizeImage;
2745 if(bitCount == 1) {
2746 /* Hack. */
2747 LPBITMAPINFO inf = (LPBITMAPINFO)bmih;
2748 inf->bmiColors[0].rgbRed = inf->bmiColors[0].rgbGreen = inf->bmiColors[0].rgbBlue = 0;
2749 inf->bmiColors[1].rgbRed = inf->bmiColors[1].rgbGreen = inf->bmiColors[1].rgbBlue = 0xff;
2752 if(!SUCCEEDED(IStream_Write(pstm, data, totalSize, NULL)))
2753 goto failed;
2755 result = TRUE;
2757 failed:
2758 ReleaseDC(0, xdc);
2759 LocalFree((HLOCAL)lpBitsOrg);
2760 LocalFree((HLOCAL)data);
2762 return result;
2766 /*************************************************************************
2767 * ImageList_Write [COMCTL32.@]
2769 * Writes an image list to a stream.
2771 * PARAMS
2772 * himl [I] handle to image list
2773 * pstm [O] Pointer to a stream.
2775 * RETURNS
2776 * Success: TRUE
2777 * Failure: FALSE
2779 * BUGS
2780 * probably.
2783 BOOL WINAPI
2784 ImageList_Write (HIMAGELIST himl, LPSTREAM pstm)
2786 ILHEAD ilHead;
2787 int i;
2789 if (!is_valid(himl))
2790 return FALSE;
2792 ilHead.usMagic = (('L' << 8) | 'I');
2793 ilHead.usVersion = 0x101;
2794 ilHead.cCurImage = himl->cCurImage;
2795 ilHead.cMaxImage = himl->cMaxImage;
2796 ilHead.cGrow = himl->cGrow;
2797 ilHead.cx = himl->cx;
2798 ilHead.cy = himl->cy;
2799 ilHead.bkcolor = himl->clrBk;
2800 ilHead.flags = himl->flags;
2801 for(i = 0; i < 4; i++) {
2802 ilHead.ovls[i] = himl->nOvlIdx[i];
2805 if(!SUCCEEDED(IStream_Write(pstm, &ilHead, sizeof(ILHEAD), NULL)))
2806 return FALSE;
2808 /* write the bitmap */
2809 if(!_write_bitmap(himl->hbmImage, pstm, himl->cx, himl->cy))
2810 return FALSE;
2812 /* write the mask if we have one */
2813 if(himl->flags & ILC_MASK) {
2814 if(!_write_bitmap(himl->hbmMask, pstm, himl->cx, himl->cy))
2815 return FALSE;
2818 return TRUE;
2822 static HBITMAP ImageList_CreateImage(HDC hdc, HIMAGELIST himl, UINT count, UINT height)
2824 HBITMAP hbmNewBitmap;
2825 UINT ilc = (himl->flags & 0xFE);
2826 SIZE sz;
2828 imagelist_get_bitmap_size( himl, count, height, &sz );
2830 if ((ilc >= ILC_COLOR4 && ilc <= ILC_COLOR32) || ilc == ILC_COLOR)
2832 VOID* bits;
2833 BITMAPINFO *bmi;
2835 TRACE("Creating DIBSection: %d Bits per Pixel\n", himl->uBitsPixel);
2837 if (himl->uBitsPixel <= ILC_COLOR8)
2839 LPPALETTEENTRY pal;
2840 ULONG i, colors;
2841 BYTE temp;
2843 colors = 1 << himl->uBitsPixel;
2844 bmi = Alloc(sizeof(BITMAPINFOHEADER) +
2845 sizeof(PALETTEENTRY) * colors);
2847 pal = (LPPALETTEENTRY)bmi->bmiColors;
2848 GetPaletteEntries(GetStockObject(DEFAULT_PALETTE), 0, colors, pal);
2850 /* Swap colors returned by GetPaletteEntries so we can use them for
2851 * CreateDIBSection call. */
2852 for (i = 0; i < colors; i++)
2854 temp = pal[i].peBlue;
2855 bmi->bmiColors[i].rgbRed = pal[i].peRed;
2856 bmi->bmiColors[i].rgbBlue = temp;
2859 else
2861 bmi = Alloc(sizeof(BITMAPINFOHEADER));
2864 bmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
2865 bmi->bmiHeader.biWidth = sz.cx;
2866 bmi->bmiHeader.biHeight = sz.cy;
2867 bmi->bmiHeader.biPlanes = 1;
2868 bmi->bmiHeader.biBitCount = himl->uBitsPixel;
2869 bmi->bmiHeader.biCompression = BI_RGB;
2870 bmi->bmiHeader.biSizeImage = 0;
2871 bmi->bmiHeader.biXPelsPerMeter = 0;
2872 bmi->bmiHeader.biYPelsPerMeter = 0;
2873 bmi->bmiHeader.biClrUsed = 0;
2874 bmi->bmiHeader.biClrImportant = 0;
2876 hbmNewBitmap = CreateDIBSection(hdc, bmi, DIB_RGB_COLORS, &bits, 0, 0);
2878 Free (bmi);
2880 else /*if (ilc == ILC_COLORDDB)*/
2882 TRACE("Creating Bitmap: %d Bits per Pixel\n", himl->uBitsPixel);
2884 hbmNewBitmap = CreateBitmap (sz.cx, sz.cy, 1, himl->uBitsPixel, NULL);
2886 TRACE("returning %p\n", hbmNewBitmap);
2887 return hbmNewBitmap;
2890 /*************************************************************************
2891 * ImageList_SetColorTable [COMCTL32.@]
2893 * Sets the color table of an image list.
2895 * PARAMS
2896 * himl [I] Handle to the image list.
2897 * uStartIndex [I] The first index to set.
2898 * cEntries [I] Number of entries to set.
2899 * prgb [I] New color information for color table for the image list.
2901 * RETURNS
2902 * Success: Number of entries in the table that were set.
2903 * Failure: Zero.
2905 * SEE
2906 * ImageList_Create(), SetDIBColorTable()
2909 UINT WINAPI
2910 ImageList_SetColorTable (HIMAGELIST himl, UINT uStartIndex, UINT cEntries, CONST RGBQUAD * prgb)
2912 return SetDIBColorTable(himl->hdcImage, uStartIndex, cEntries, prgb);