dbbb4949704c24060f33ff196d0c038230bf1232
[reactos.git] / reactos / dll / win32 / comctl32 / imagelist.c
1 /*
2 * ImageList implementation
3 *
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
10 *
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.
15 *
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.
20 *
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
24 *
25 * NOTE
26 *
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.
29 *
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.
33 *
34 * TODO:
35 * - Add support for ILD_PRESERVEALPHA, ILD_SCALE, ILD_DPISCALE
36 * - Add support for ILS_GLOW, ILS_SHADOW, ILS_SATURATE
37 * - Thread-safe locking
38 */
39
40 #include "comctl32.h"
41
42 #include <commoncontrols.h>
43 #include <wine/exception.h>
44
45 WINE_DEFAULT_DEBUG_CHANNEL(imagelist);
46
47 #define MAX_OVERLAYIMAGE 15
48
49 struct _IMAGELIST
50 {
51 IImageList2 IImageList2_iface; /* 00: IImageList vtable */
52 INT cCurImage; /* 04: ImageCount */
53 INT cMaxImage; /* 08: maximages */
54 INT cGrow; /* 0C: cGrow */
55 INT cx; /* 10: cx */
56 INT cy; /* 14: cy */
57 DWORD x4;
58 UINT flags; /* 1C: flags */
59 COLORREF clrFg; /* 20: foreground color */
60 COLORREF clrBk; /* 24: background color */
61
62
63 HBITMAP hbmImage; /* 28: images Bitmap */
64 HBITMAP hbmMask; /* 2C: masks Bitmap */
65 HDC hdcImage; /* 30: images MemDC */
66 HDC hdcMask; /* 34: masks MemDC */
67 INT nOvlIdx[MAX_OVERLAYIMAGE]; /* 38: overlay images index */
68
69 /* not yet found out */
70 HBRUSH hbrBlend25;
71 HBRUSH hbrBlend50;
72 INT cInitial;
73 UINT uBitsPixel;
74 char *has_alpha;
75
76 LONG ref; /* reference count */
77 };
78
79 #define IMAGELIST_MAGIC 0x53414D58
80
81 /* Header used by ImageList_Read() and ImageList_Write() */
82 #include "pshpack2.h"
83 typedef struct _ILHEAD
84 {
85 USHORT usMagic;
86 USHORT usVersion;
87 WORD cCurImage;
88 WORD cMaxImage;
89 WORD cGrow;
90 WORD cx;
91 WORD cy;
92 COLORREF bkcolor;
93 WORD flags;
94 SHORT ovls[4];
95 } ILHEAD;
96 #include "poppack.h"
97
98 /* internal image list data used for Drag & Drop operations */
99 typedef struct
100 {
101 HWND hwnd;
102 HIMAGELIST himl;
103 HIMAGELIST himlNoCursor;
104 /* position of the drag image relative to the window */
105 INT x;
106 INT y;
107 /* offset of the hotspot relative to the origin of the image */
108 INT dxHotspot;
109 INT dyHotspot;
110 /* is the drag image visible */
111 BOOL bShow;
112 /* saved background */
113 HBITMAP hbmBg;
114 } INTERNALDRAG;
115
116 static INTERNALDRAG InternalDrag = { 0, 0, 0, 0, 0, 0, 0, FALSE, 0 };
117
118 static inline HIMAGELIST impl_from_IImageList2(IImageList2 *iface)
119 {
120 return CONTAINING_RECORD(iface, struct _IMAGELIST, IImageList2_iface);
121 }
122
123 static HBITMAP ImageList_CreateImage(HDC hdc, HIMAGELIST himl, UINT count);
124 static HRESULT ImageListImpl_CreateInstance(const IUnknown *pUnkOuter, REFIID iid, void** ppv);
125 static BOOL is_valid(HIMAGELIST himl);
126
127 /*
128 * An imagelist with N images is tiled like this:
129 *
130 * N/4 ->
131 *
132 * 4 048C..
133 * 159D..
134 * | 26AE.N
135 * V 37BF.
136 */
137
138 #define TILE_COUNT 4
139
140 static inline UINT imagelist_height( UINT count )
141 {
142 return ((count + TILE_COUNT - 1)/TILE_COUNT);
143 }
144
145 static inline void imagelist_point_from_index( HIMAGELIST himl, UINT index, LPPOINT pt )
146 {
147 pt->x = (index%TILE_COUNT) * himl->cx;
148 pt->y = (index/TILE_COUNT) * himl->cy;
149 }
150
151 static inline void imagelist_get_bitmap_size( HIMAGELIST himl, UINT count, SIZE *sz )
152 {
153 sz->cx = himl->cx * TILE_COUNT;
154 sz->cy = imagelist_height( count ) * himl->cy;
155 }
156
157 static inline int get_dib_stride( int width, int bpp )
158 {
159 return ((width * bpp + 31) >> 3) & ~3;
160 }
161
162 static inline int get_dib_image_size( const BITMAPINFO *info )
163 {
164 return get_dib_stride( info->bmiHeader.biWidth, info->bmiHeader.biBitCount )
165 * abs( info->bmiHeader.biHeight );
166 }
167
168 /*
169 * imagelist_copy_images()
170 *
171 * Copies a block of count images from offset src in the list to offset dest.
172 * Images are copied a row at at time. Assumes hdcSrc and hdcDest are different.
173 */
174 static inline void imagelist_copy_images( HIMAGELIST himl, HDC hdcSrc, HDC hdcDest,
175 UINT src, UINT count, UINT dest )
176 {
177 POINT ptSrc, ptDest;
178 SIZE sz;
179 UINT i;
180
181 for ( i=0; i<TILE_COUNT; i++ )
182 {
183 imagelist_point_from_index( himl, src+i, &ptSrc );
184 imagelist_point_from_index( himl, dest+i, &ptDest );
185 sz.cx = himl->cx;
186 sz.cy = himl->cy * imagelist_height( count - i );
187
188 BitBlt( hdcDest, ptDest.x, ptDest.y, sz.cx, sz.cy,
189 hdcSrc, ptSrc.x, ptSrc.y, SRCCOPY );
190 }
191 }
192
193 static void add_dib_bits( HIMAGELIST himl, int pos, int count, int width, int height,
194 BITMAPINFO *info, BITMAPINFO *mask_info, DWORD *bits, BYTE *mask_bits )
195 {
196 int i, j, n;
197 POINT pt;
198 int stride = info->bmiHeader.biWidth;
199 int mask_stride = (info->bmiHeader.biWidth + 31) / 32 * 4;
200
201 for (n = 0; n < count; n++)
202 {
203 BOOL has_alpha = FALSE;
204
205 imagelist_point_from_index( himl, pos + n, &pt );
206
207 /* check if bitmap has an alpha channel */
208 for (i = 0; i < height && !has_alpha; i++)
209 for (j = n * width; j < (n + 1) * width; j++)
210 if ((has_alpha = ((bits[i * stride + j] & 0xff000000) != 0))) break;
211
212 if (!has_alpha) /* generate alpha channel from the mask */
213 {
214 for (i = 0; i < height; i++)
215 for (j = n * width; j < (n + 1) * width; j++)
216 if (!mask_info || !((mask_bits[i * mask_stride + j / 8] << (j % 8)) & 0x80))
217 bits[i * stride + j] |= 0xff000000;
218 else
219 bits[i * stride + j] = 0;
220 }
221 else
222 {
223 himl->has_alpha[pos + n] = 1;
224
225 if (mask_info && himl->hbmMask) /* generate the mask from the alpha channel */
226 {
227 for (i = 0; i < height; i++)
228 for (j = n * width; j < (n + 1) * width; j++)
229 if ((bits[i * stride + j] >> 24) > 25) /* more than 10% alpha */
230 mask_bits[i * mask_stride + j / 8] &= ~(0x80 >> (j % 8));
231 else
232 mask_bits[i * mask_stride + j / 8] |= 0x80 >> (j % 8);
233 }
234 }
235 StretchDIBits( himl->hdcImage, pt.x, pt.y, himl->cx, himl->cy,
236 n * width, 0, width, height, bits, info, DIB_RGB_COLORS, SRCCOPY );
237 if (mask_info)
238 StretchDIBits( himl->hdcMask, pt.x, pt.y, himl->cx, himl->cy,
239 n * width, 0, width, height, mask_bits, mask_info, DIB_RGB_COLORS, SRCCOPY );
240 }
241 }
242
243 /* add images with an alpha channel when the image list is 32 bpp */
244 static BOOL add_with_alpha( HIMAGELIST himl, HDC hdc, int pos, int count,
245 int width, int height, HBITMAP hbmImage, HBITMAP hbmMask )
246 {
247 BOOL ret = FALSE;
248 BITMAP bm;
249 BITMAPINFO *info, *mask_info = NULL;
250 DWORD *bits = NULL;
251 BYTE *mask_bits = NULL;
252 DWORD mask_width;
253
254 if (!GetObjectW( hbmImage, sizeof(bm), &bm )) return FALSE;
255
256 /* if either the imagelist or the source bitmap don't have an alpha channel, bail out now */
257 if (!himl->has_alpha) return FALSE;
258 if (bm.bmBitsPixel != 32) return FALSE;
259
260 SelectObject( hdc, hbmImage );
261 mask_width = (bm.bmWidth + 31) / 32 * 4;
262
263 if (!(info = HeapAlloc( GetProcessHeap(), 0, FIELD_OFFSET( BITMAPINFO, bmiColors[256] )))) goto done;
264 info->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
265 info->bmiHeader.biWidth = bm.bmWidth;
266 info->bmiHeader.biHeight = -height;
267 info->bmiHeader.biPlanes = 1;
268 info->bmiHeader.biBitCount = 32;
269 info->bmiHeader.biCompression = BI_RGB;
270 info->bmiHeader.biSizeImage = bm.bmWidth * height * 4;
271 info->bmiHeader.biXPelsPerMeter = 0;
272 info->bmiHeader.biYPelsPerMeter = 0;
273 info->bmiHeader.biClrUsed = 0;
274 info->bmiHeader.biClrImportant = 0;
275 if (!(bits = HeapAlloc( GetProcessHeap(), 0, info->bmiHeader.biSizeImage ))) goto done;
276 if (!GetDIBits( hdc, hbmImage, 0, height, bits, info, DIB_RGB_COLORS )) goto done;
277
278 if (hbmMask)
279 {
280 if (!(mask_info = HeapAlloc( GetProcessHeap(), 0, FIELD_OFFSET( BITMAPINFO, bmiColors[2] ))))
281 goto done;
282 mask_info->bmiHeader = info->bmiHeader;
283 mask_info->bmiHeader.biBitCount = 1;
284 mask_info->bmiHeader.biSizeImage = mask_width * height;
285 if (!(mask_bits = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, info->bmiHeader.biSizeImage )))
286 goto done;
287 if (!GetDIBits( hdc, hbmMask, 0, height, mask_bits, mask_info, DIB_RGB_COLORS )) goto done;
288 }
289
290 add_dib_bits( himl, pos, count, width, height, info, mask_info, bits, mask_bits );
291 ret = TRUE;
292
293 done:
294 HeapFree( GetProcessHeap(), 0, info );
295 HeapFree( GetProcessHeap(), 0, mask_info );
296 HeapFree( GetProcessHeap(), 0, bits );
297 HeapFree( GetProcessHeap(), 0, mask_bits );
298 return ret;
299 }
300
301 /*************************************************************************
302 * IMAGELIST_InternalExpandBitmaps [Internal]
303 *
304 * Expands the bitmaps of an image list by the given number of images.
305 *
306 * PARAMS
307 * himl [I] handle to image list
308 * nImageCount [I] number of images to add
309 *
310 * RETURNS
311 * nothing
312 *
313 * NOTES
314 * This function CANNOT be used to reduce the number of images.
315 */
316 static void
317 IMAGELIST_InternalExpandBitmaps(HIMAGELIST himl, INT nImageCount)
318 {
319 HDC hdcBitmap;
320 HBITMAP hbmNewBitmap, hbmNull;
321 INT nNewCount;
322 SIZE sz;
323
324 TRACE("%p has allocated %d, max %d, grow %d images\n", himl, himl->cCurImage, himl->cMaxImage, himl->cGrow);
325
326 if (himl->cCurImage + nImageCount < himl->cMaxImage)
327 return;
328
329 nNewCount = himl->cMaxImage + max(nImageCount, himl->cGrow) + 1;
330
331 imagelist_get_bitmap_size(himl, nNewCount, &sz);
332
333 TRACE("Create expanded bitmaps : himl=%p x=%d y=%d count=%d\n", himl, sz.cx, sz.cy, nNewCount);
334 hdcBitmap = CreateCompatibleDC (0);
335
336 hbmNewBitmap = ImageList_CreateImage(hdcBitmap, himl, nNewCount);
337
338 if (hbmNewBitmap == 0)
339 ERR("creating new image bitmap (x=%d y=%d)!\n", sz.cx, sz.cy);
340
341 if (himl->cCurImage)
342 {
343 hbmNull = SelectObject (hdcBitmap, hbmNewBitmap);
344 BitBlt (hdcBitmap, 0, 0, sz.cx, sz.cy,
345 himl->hdcImage, 0, 0, SRCCOPY);
346 SelectObject (hdcBitmap, hbmNull);
347 }
348 SelectObject (himl->hdcImage, hbmNewBitmap);
349 DeleteObject (himl->hbmImage);
350 himl->hbmImage = hbmNewBitmap;
351
352 if (himl->flags & ILC_MASK)
353 {
354 hbmNewBitmap = CreateBitmap (sz.cx, sz.cy, 1, 1, NULL);
355
356 if (hbmNewBitmap == 0)
357 ERR("creating new mask bitmap!\n");
358
359 if(himl->cCurImage)
360 {
361 hbmNull = SelectObject (hdcBitmap, hbmNewBitmap);
362 BitBlt (hdcBitmap, 0, 0, sz.cx, sz.cy,
363 himl->hdcMask, 0, 0, SRCCOPY);
364 SelectObject (hdcBitmap, hbmNull);
365 }
366 SelectObject (himl->hdcMask, hbmNewBitmap);
367 DeleteObject (himl->hbmMask);
368 himl->hbmMask = hbmNewBitmap;
369 }
370
371 if (himl->has_alpha)
372 {
373 char *new_alpha = HeapReAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, himl->has_alpha, nNewCount );
374 if (new_alpha) himl->has_alpha = new_alpha;
375 else
376 {
377 HeapFree( GetProcessHeap(), 0, himl->has_alpha );
378 himl->has_alpha = NULL;
379 }
380 }
381
382 himl->cMaxImage = nNewCount;
383
384 DeleteDC (hdcBitmap);
385 }
386
387
388 /*************************************************************************
389 * ImageList_Add [COMCTL32.@]
390 *
391 * Add an image or images to an image list.
392 *
393 * PARAMS
394 * himl [I] handle to image list
395 * hbmImage [I] handle to image bitmap
396 * hbmMask [I] handle to mask bitmap
397 *
398 * RETURNS
399 * Success: Index of the first new image.
400 * Failure: -1
401 */
402
403 INT WINAPI
404 ImageList_Add (HIMAGELIST himl, HBITMAP hbmImage, HBITMAP hbmMask)
405 {
406 HDC hdcBitmap, hdcTemp = 0;
407 INT nFirstIndex, nImageCount, i;
408 BITMAP bmp;
409 POINT pt;
410
411 TRACE("himl=%p hbmimage=%p hbmmask=%p\n", himl, hbmImage, hbmMask);
412 if (!is_valid(himl))
413 return -1;
414
415 if (!GetObjectW(hbmImage, sizeof(BITMAP), &bmp))
416 return -1;
417
418 TRACE("himl %p, cCurImage %d, cMaxImage %d, cGrow %d, cx %d, cy %d\n",
419 himl, himl->cCurImage, himl->cMaxImage, himl->cGrow, himl->cx, himl->cy);
420
421 nImageCount = bmp.bmWidth / himl->cx;
422
423 TRACE("%p has %d images (%d x %d)\n", hbmImage, nImageCount, bmp.bmWidth, bmp.bmHeight);
424
425 IMAGELIST_InternalExpandBitmaps(himl, nImageCount);
426
427 hdcBitmap = CreateCompatibleDC(0);
428
429 SelectObject(hdcBitmap, hbmImage);
430
431 if (add_with_alpha( himl, hdcBitmap, himl->cCurImage, nImageCount,
432 himl->cx, min( himl->cy, bmp.bmHeight), hbmImage, hbmMask ))
433 goto done;
434
435 if (himl->hbmMask)
436 {
437 hdcTemp = CreateCompatibleDC(0);
438 SelectObject(hdcTemp, hbmMask);
439 }
440
441 for (i=0; i<nImageCount; i++)
442 {
443 imagelist_point_from_index( himl, himl->cCurImage + i, &pt );
444
445 /* Copy result to the imagelist
446 */
447 BitBlt( himl->hdcImage, pt.x, pt.y, himl->cx, bmp.bmHeight,
448 hdcBitmap, i*himl->cx, 0, SRCCOPY );
449
450 if (!himl->hbmMask)
451 continue;
452
453 BitBlt( himl->hdcMask, pt.x, pt.y, himl->cx, bmp.bmHeight,
454 hdcTemp, i*himl->cx, 0, SRCCOPY );
455
456 /* Remove the background from the image
457 */
458 BitBlt( himl->hdcImage, pt.x, pt.y, himl->cx, bmp.bmHeight,
459 himl->hdcMask, pt.x, pt.y, 0x220326 ); /* NOTSRCAND */
460 }
461 if (hdcTemp) DeleteDC(hdcTemp);
462
463 done:
464 DeleteDC(hdcBitmap);
465
466 nFirstIndex = himl->cCurImage;
467 himl->cCurImage += nImageCount;
468
469 return nFirstIndex;
470 }
471
472
473 /*************************************************************************
474 * ImageList_AddIcon [COMCTL32.@]
475 *
476 * Adds an icon to an image list.
477 *
478 * PARAMS
479 * himl [I] handle to image list
480 * hIcon [I] handle to icon
481 *
482 * RETURNS
483 * Success: index of the new image
484 * Failure: -1
485 */
486 #undef ImageList_AddIcon
487 INT WINAPI ImageList_AddIcon (HIMAGELIST himl, HICON hIcon)
488 {
489 return ImageList_ReplaceIcon (himl, -1, hIcon);
490 }
491
492
493 /*************************************************************************
494 * ImageList_AddMasked [COMCTL32.@]
495 *
496 * Adds an image or images to an image list and creates a mask from the
497 * specified bitmap using the mask color.
498 *
499 * PARAMS
500 * himl [I] handle to image list.
501 * hBitmap [I] handle to bitmap
502 * clrMask [I] mask color.
503 *
504 * RETURNS
505 * Success: Index of the first new image.
506 * Failure: -1
507 */
508
509 INT WINAPI
510 ImageList_AddMasked (HIMAGELIST himl, HBITMAP hBitmap, COLORREF clrMask)
511 {
512 HDC hdcMask, hdcBitmap;
513 INT ret;
514 BITMAP bmp;
515 HBITMAP hMaskBitmap;
516 COLORREF bkColor;
517
518 TRACE("himl=%p hbitmap=%p clrmask=%x\n", himl, hBitmap, clrMask);
519 if (!is_valid(himl))
520 return -1;
521
522 if (!GetObjectW(hBitmap, sizeof(BITMAP), &bmp))
523 return -1;
524
525 hdcBitmap = CreateCompatibleDC(0);
526 SelectObject(hdcBitmap, hBitmap);
527
528 /* Create a temp Mask so we can remove the background of the Image */
529 hdcMask = CreateCompatibleDC(0);
530 hMaskBitmap = CreateBitmap(bmp.bmWidth, bmp.bmHeight, 1, 1, NULL);
531 SelectObject(hdcMask, hMaskBitmap);
532
533 /* create monochrome image to the mask bitmap */
534 bkColor = (clrMask != CLR_DEFAULT) ? clrMask : GetPixel (hdcBitmap, 0, 0);
535 SetBkColor (hdcBitmap, bkColor);
536 BitBlt (hdcMask, 0, 0, bmp.bmWidth, bmp.bmHeight, hdcBitmap, 0, 0, SRCCOPY);
537
538 /*
539 * Remove the background from the image
540 *
541 * WINDOWS BUG ALERT!!!!!!
542 * The statement below should not be done in common practice
543 * but this is how ImageList_AddMasked works in Windows.
544 * It overwrites the original bitmap passed, this was discovered
545 * by using the same bitmap to iterate the different styles
546 * on windows where it failed (BUT ImageList_Add is OK)
547 * This is here in case some apps rely on this bug
548 *
549 * Blt mode 0x220326 is NOTSRCAND
550 */
551 if (bmp.bmBitsPixel > 8) /* NOTSRCAND can't work with palettes */
552 {
553 SetBkColor(hdcBitmap, RGB(255,255,255));
554 BitBlt(hdcBitmap, 0, 0, bmp.bmWidth, bmp.bmHeight, hdcMask, 0, 0, 0x220326);
555 }
556
557 DeleteDC(hdcBitmap);
558 DeleteDC(hdcMask);
559
560 ret = ImageList_Add( himl, hBitmap, hMaskBitmap );
561
562 DeleteObject(hMaskBitmap);
563 return ret;
564 }
565
566
567 /*************************************************************************
568 * ImageList_BeginDrag [COMCTL32.@]
569 *
570 * Creates a temporary image list that contains one image. It will be used
571 * as a drag image.
572 *
573 * PARAMS
574 * himlTrack [I] handle to the source image list
575 * iTrack [I] index of the drag image in the source image list
576 * dxHotspot [I] X position of the hot spot of the drag image
577 * dyHotspot [I] Y position of the hot spot of the drag image
578 *
579 * RETURNS
580 * Success: TRUE
581 * Failure: FALSE
582 */
583
584 BOOL WINAPI
585 ImageList_BeginDrag (HIMAGELIST himlTrack, INT iTrack,
586 INT dxHotspot, INT dyHotspot)
587 {
588 INT cx, cy;
589
590 TRACE("(himlTrack=%p iTrack=%d dx=%d dy=%d)\n", himlTrack, iTrack,
591 dxHotspot, dyHotspot);
592
593 if (!is_valid(himlTrack))
594 return FALSE;
595
596 if (InternalDrag.himl)
597 ImageList_EndDrag ();
598
599 cx = himlTrack->cx;
600 cy = himlTrack->cy;
601
602 InternalDrag.himlNoCursor = InternalDrag.himl = ImageList_Create (cx, cy, himlTrack->flags, 1, 1);
603 if (InternalDrag.himl == NULL) {
604 WARN("Error creating drag image list!\n");
605 return FALSE;
606 }
607
608 InternalDrag.dxHotspot = dxHotspot;
609 InternalDrag.dyHotspot = dyHotspot;
610
611 /* copy image */
612 BitBlt (InternalDrag.himl->hdcImage, 0, 0, cx, cy, himlTrack->hdcImage, iTrack * cx, 0, SRCCOPY);
613
614 /* copy mask */
615 BitBlt (InternalDrag.himl->hdcMask, 0, 0, cx, cy, himlTrack->hdcMask, iTrack * cx, 0, SRCCOPY);
616
617 InternalDrag.himl->cCurImage = 1;
618
619 return TRUE;
620 }
621
622
623 /*************************************************************************
624 * ImageList_Copy [COMCTL32.@]
625 *
626 * Copies an image of the source image list to an image of the
627 * destination image list. Images can be copied or swapped.
628 *
629 * PARAMS
630 * himlDst [I] handle to the destination image list
631 * iDst [I] destination image index.
632 * himlSrc [I] handle to the source image list
633 * iSrc [I] source image index
634 * uFlags [I] flags for the copy operation
635 *
636 * RETURNS
637 * Success: TRUE
638 * Failure: FALSE
639 *
640 * NOTES
641 * Copying from one image list to another is possible. The original
642 * implementation just copies or swaps within one image list.
643 * Could this feature become a bug??? ;-)
644 */
645
646 BOOL WINAPI
647 ImageList_Copy (HIMAGELIST himlDst, INT iDst, HIMAGELIST himlSrc,
648 INT iSrc, UINT uFlags)
649 {
650 POINT ptSrc, ptDst;
651
652 TRACE("himlDst=%p iDst=%d himlSrc=%p iSrc=%d\n", himlDst, iDst, himlSrc, iSrc);
653
654 if (!is_valid(himlSrc) || !is_valid(himlDst))
655 return FALSE;
656 if ((iDst < 0) || (iDst >= himlDst->cCurImage))
657 return FALSE;
658 if ((iSrc < 0) || (iSrc >= himlSrc->cCurImage))
659 return FALSE;
660
661 imagelist_point_from_index( himlDst, iDst, &ptDst );
662 imagelist_point_from_index( himlSrc, iSrc, &ptSrc );
663
664 if (uFlags & ILCF_SWAP) {
665 /* swap */
666 HDC hdcBmp;
667 HBITMAP hbmTempImage, hbmTempMask;
668
669 hdcBmp = CreateCompatibleDC (0);
670
671 /* create temporary bitmaps */
672 hbmTempImage = CreateBitmap (himlSrc->cx, himlSrc->cy, 1,
673 himlSrc->uBitsPixel, NULL);
674 hbmTempMask = CreateBitmap (himlSrc->cx, himlSrc->cy, 1,
675 1, NULL);
676
677 /* copy (and stretch) destination to temporary bitmaps.(save) */
678 /* image */
679 SelectObject (hdcBmp, hbmTempImage);
680 StretchBlt (hdcBmp, 0, 0, himlSrc->cx, himlSrc->cy,
681 himlDst->hdcImage, ptDst.x, ptDst.y, himlDst->cx, himlDst->cy,
682 SRCCOPY);
683 /* mask */
684 SelectObject (hdcBmp, hbmTempMask);
685 StretchBlt (hdcBmp, 0, 0, himlSrc->cx, himlSrc->cy,
686 himlDst->hdcMask, ptDst.x, ptDst.y, himlDst->cx, himlDst->cy,
687 SRCCOPY);
688
689 /* copy (and stretch) source to destination */
690 /* image */
691 StretchBlt (himlDst->hdcImage, ptDst.x, ptDst.y, himlDst->cx, himlDst->cy,
692 himlSrc->hdcImage, ptSrc.x, ptSrc.y, himlSrc->cx, himlSrc->cy,
693 SRCCOPY);
694 /* mask */
695 StretchBlt (himlDst->hdcMask, ptDst.x, ptDst.y, himlDst->cx, himlDst->cy,
696 himlSrc->hdcMask, ptSrc.x, ptSrc.y, himlSrc->cx, himlSrc->cy,
697 SRCCOPY);
698
699 /* copy (without stretching) temporary bitmaps to source (restore) */
700 /* mask */
701 BitBlt (himlSrc->hdcMask, ptSrc.x, ptSrc.y, himlSrc->cx, himlSrc->cy,
702 hdcBmp, 0, 0, SRCCOPY);
703
704 /* image */
705 BitBlt (himlSrc->hdcImage, ptSrc.x, ptSrc.y, himlSrc->cx, himlSrc->cy,
706 hdcBmp, 0, 0, SRCCOPY);
707 /* delete temporary bitmaps */
708 DeleteObject (hbmTempMask);
709 DeleteObject (hbmTempImage);
710 DeleteDC(hdcBmp);
711 }
712 else {
713 /* copy image */
714 StretchBlt (himlDst->hdcImage, ptDst.x, ptDst.y, himlDst->cx, himlDst->cy,
715 himlSrc->hdcImage, ptSrc.x, ptSrc.y, himlSrc->cx, himlSrc->cy,
716 SRCCOPY);
717
718 /* copy mask */
719 StretchBlt (himlDst->hdcMask, ptDst.x, ptDst.y, himlDst->cx, himlDst->cy,
720 himlSrc->hdcMask, ptSrc.x, ptSrc.y, himlSrc->cx, himlSrc->cy,
721 SRCCOPY);
722 }
723
724 return TRUE;
725 }
726
727
728 /*************************************************************************
729 * ImageList_Create [COMCTL32.@]
730 *
731 * Creates a new image list.
732 *
733 * PARAMS
734 * cx [I] image height
735 * cy [I] image width
736 * flags [I] creation flags
737 * cInitial [I] initial number of images in the image list
738 * cGrow [I] number of images by which image list grows
739 *
740 * RETURNS
741 * Success: Handle to the created image list
742 * Failure: NULL
743 */
744 HIMAGELIST WINAPI
745 ImageList_Create (INT cx, INT cy, UINT flags,
746 INT cInitial, INT cGrow)
747 {
748 HIMAGELIST himl;
749 INT nCount;
750 HBITMAP hbmTemp;
751 UINT ilc = (flags & 0xFE);
752 static const WORD aBitBlend25[] =
753 {0xAA, 0x00, 0x55, 0x00, 0xAA, 0x00, 0x55, 0x00};
754
755 static const WORD aBitBlend50[] =
756 {0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA};
757
758 TRACE("(%d %d 0x%x %d %d)\n", cx, cy, flags, cInitial, cGrow);
759
760 if (cx <= 0 || cy <= 0) return NULL;
761
762 /* Create the IImageList interface for the image list */
763 if (FAILED(ImageListImpl_CreateInstance(NULL, &IID_IImageList, (void **)&himl)))
764 return NULL;
765
766 cGrow = (WORD)((max( cGrow, 1 ) + 3) & ~3);
767
768 if (cGrow > 256)
769 {
770 /* Windows doesn't limit the size here, but X11 doesn't let us allocate such huge bitmaps */
771 WARN( "grow %d too large, limiting to 256\n", cGrow );
772 cGrow = 256;
773 }
774
775 himl->cx = cx;
776 himl->cy = cy;
777 himl->flags = flags;
778 himl->cMaxImage = cInitial + 1;
779 himl->cInitial = cInitial;
780 himl->cGrow = cGrow;
781 himl->clrFg = CLR_DEFAULT;
782 himl->clrBk = CLR_NONE;
783
784 /* initialize overlay mask indices */
785 for (nCount = 0; nCount < MAX_OVERLAYIMAGE; nCount++)
786 himl->nOvlIdx[nCount] = -1;
787
788 /* Create Image & Mask DCs */
789 himl->hdcImage = CreateCompatibleDC (0);
790 if (!himl->hdcImage)
791 goto cleanup;
792 if (himl->flags & ILC_MASK){
793 himl->hdcMask = CreateCompatibleDC(0);
794 if (!himl->hdcMask)
795 goto cleanup;
796 }
797
798 /* Default to ILC_COLOR4 if none of the ILC_COLOR* flags are specified */
799 if (ilc == ILC_COLOR)
800 {
801 ilc = ILC_COLOR4;
802 himl->flags |= ILC_COLOR4;
803 }
804
805 if (ilc >= ILC_COLOR4 && ilc <= ILC_COLOR32)
806 himl->uBitsPixel = ilc;
807 else
808 himl->uBitsPixel = (UINT)GetDeviceCaps (himl->hdcImage, BITSPIXEL);
809
810 if (himl->cMaxImage > 0) {
811 himl->hbmImage = ImageList_CreateImage(himl->hdcImage, himl, himl->cMaxImage);
812 SelectObject(himl->hdcImage, himl->hbmImage);
813 } else
814 himl->hbmImage = 0;
815
816 if ((himl->cMaxImage > 0) && (himl->flags & ILC_MASK)) {
817 SIZE sz;
818
819 imagelist_get_bitmap_size(himl, himl->cMaxImage, &sz);
820 himl->hbmMask = CreateBitmap (sz.cx, sz.cy, 1, 1, NULL);
821 if (himl->hbmMask == 0) {
822 ERR("Error creating mask bitmap!\n");
823 goto cleanup;
824 }
825 SelectObject(himl->hdcMask, himl->hbmMask);
826 }
827 else
828 himl->hbmMask = 0;
829
830 if (ilc == ILC_COLOR32)
831 himl->has_alpha = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, himl->cMaxImage );
832 else
833 himl->has_alpha = NULL;
834
835 /* create blending brushes */
836 hbmTemp = CreateBitmap (8, 8, 1, 1, aBitBlend25);
837 himl->hbrBlend25 = CreatePatternBrush (hbmTemp);
838 DeleteObject (hbmTemp);
839
840 hbmTemp = CreateBitmap (8, 8, 1, 1, aBitBlend50);
841 himl->hbrBlend50 = CreatePatternBrush (hbmTemp);
842 DeleteObject (hbmTemp);
843
844 TRACE("created imagelist %p\n", himl);
845 return himl;
846
847 cleanup:
848 ImageList_Destroy(himl);
849 return NULL;
850 }
851
852
853 /*************************************************************************
854 * ImageList_Destroy [COMCTL32.@]
855 *
856 * Destroys an image list.
857 *
858 * PARAMS
859 * himl [I] handle to image list
860 *
861 * RETURNS
862 * Success: TRUE
863 * Failure: FALSE
864 */
865
866 BOOL WINAPI
867 ImageList_Destroy (HIMAGELIST himl)
868 {
869 if (!is_valid(himl))
870 return FALSE;
871
872 IImageList_Release((IImageList *) himl);
873 return TRUE;
874 }
875
876
877 /*************************************************************************
878 * ImageList_DragEnter [COMCTL32.@]
879 *
880 * Locks window update and displays the drag image at the given position.
881 *
882 * PARAMS
883 * hwndLock [I] handle of the window that owns the drag image.
884 * x [I] X position of the drag image.
885 * y [I] Y position of the drag image.
886 *
887 * RETURNS
888 * Success: TRUE
889 * Failure: FALSE
890 *
891 * NOTES
892 * The position of the drag image is relative to the window, not
893 * the client area.
894 */
895
896 BOOL WINAPI
897 ImageList_DragEnter (HWND hwndLock, INT x, INT y)
898 {
899 TRACE("(hwnd=%p x=%d y=%d)\n", hwndLock, x, y);
900
901 if (!is_valid(InternalDrag.himl))
902 return FALSE;
903
904 if (hwndLock)
905 InternalDrag.hwnd = hwndLock;
906 else
907 InternalDrag.hwnd = GetDesktopWindow ();
908
909 InternalDrag.x = x;
910 InternalDrag.y = y;
911
912 /* draw the drag image and save the background */
913 if (!ImageList_DragShowNolock(TRUE)) {
914 return FALSE;
915 }
916
917 return TRUE;
918 }
919
920
921 /*************************************************************************
922 * ImageList_DragLeave [COMCTL32.@]
923 *
924 * Unlocks window update and hides the drag image.
925 *
926 * PARAMS
927 * hwndLock [I] handle of the window that owns the drag image.
928 *
929 * RETURNS
930 * Success: TRUE
931 * Failure: FALSE
932 */
933
934 BOOL WINAPI
935 ImageList_DragLeave (HWND hwndLock)
936 {
937 /* As we don't save drag info in the window this can lead to problems if
938 an app does not supply the same window as DragEnter */
939 /* if (hwndLock)
940 InternalDrag.hwnd = hwndLock;
941 else
942 InternalDrag.hwnd = GetDesktopWindow (); */
943 if(!hwndLock)
944 hwndLock = GetDesktopWindow();
945 if(InternalDrag.hwnd != hwndLock)
946 FIXME("DragLeave hWnd != DragEnter hWnd\n");
947
948 ImageList_DragShowNolock (FALSE);
949
950 return TRUE;
951 }
952
953
954 /*************************************************************************
955 * ImageList_InternalDragDraw [Internal]
956 *
957 * Draws the drag image.
958 *
959 * PARAMS
960 * hdc [I] device context to draw into.
961 * x [I] X position of the drag image.
962 * y [I] Y position of the drag image.
963 *
964 * RETURNS
965 * Success: TRUE
966 * Failure: FALSE
967 *
968 * NOTES
969 * The position of the drag image is relative to the window, not
970 * the client area.
971 *
972 */
973
974 static inline void
975 ImageList_InternalDragDraw (HDC hdc, INT x, INT y)
976 {
977 IMAGELISTDRAWPARAMS imldp;
978
979 ZeroMemory (&imldp, sizeof(imldp));
980 imldp.cbSize = sizeof(imldp);
981 imldp.himl = InternalDrag.himl;
982 imldp.i = 0;
983 imldp.hdcDst = hdc,
984 imldp.x = x;
985 imldp.y = y;
986 imldp.rgbBk = CLR_DEFAULT;
987 imldp.rgbFg = CLR_DEFAULT;
988 imldp.fStyle = ILD_NORMAL;
989 imldp.fState = ILS_ALPHA;
990 imldp.Frame = 192;
991 ImageList_DrawIndirect (&imldp);
992 }
993
994 /*************************************************************************
995 * ImageList_DragMove [COMCTL32.@]
996 *
997 * Moves the drag image.
998 *
999 * PARAMS
1000 * x [I] X position of the drag image.
1001 * y [I] Y position of the drag image.
1002 *
1003 * RETURNS
1004 * Success: TRUE
1005 * Failure: FALSE
1006 *
1007 * NOTES
1008 * The position of the drag image is relative to the window, not
1009 * the client area.
1010 */
1011
1012 BOOL WINAPI
1013 ImageList_DragMove (INT x, INT y)
1014 {
1015 TRACE("(x=%d y=%d)\n", x, y);
1016
1017 if (!is_valid(InternalDrag.himl))
1018 return FALSE;
1019
1020 /* draw/update the drag image */
1021 if (InternalDrag.bShow) {
1022 HDC hdcDrag;
1023 HDC hdcOffScreen;
1024 HDC hdcBg;
1025 HBITMAP hbmOffScreen;
1026 INT origNewX, origNewY;
1027 INT origOldX, origOldY;
1028 INT origRegX, origRegY;
1029 INT sizeRegX, sizeRegY;
1030
1031
1032 /* calculate the update region */
1033 origNewX = x - InternalDrag.dxHotspot;
1034 origNewY = y - InternalDrag.dyHotspot;
1035 origOldX = InternalDrag.x - InternalDrag.dxHotspot;
1036 origOldY = InternalDrag.y - InternalDrag.dyHotspot;
1037 origRegX = min(origNewX, origOldX);
1038 origRegY = min(origNewY, origOldY);
1039 sizeRegX = InternalDrag.himl->cx + abs(x - InternalDrag.x);
1040 sizeRegY = InternalDrag.himl->cy + abs(y - InternalDrag.y);
1041
1042 hdcDrag = GetDCEx(InternalDrag.hwnd, 0,
1043 DCX_WINDOW | DCX_CACHE | DCX_LOCKWINDOWUPDATE);
1044 hdcOffScreen = CreateCompatibleDC(hdcDrag);
1045 hdcBg = CreateCompatibleDC(hdcDrag);
1046
1047 hbmOffScreen = CreateCompatibleBitmap(hdcDrag, sizeRegX, sizeRegY);
1048 SelectObject(hdcOffScreen, hbmOffScreen);
1049 SelectObject(hdcBg, InternalDrag.hbmBg);
1050
1051 /* get the actual background of the update region */
1052 BitBlt(hdcOffScreen, 0, 0, sizeRegX, sizeRegY, hdcDrag,
1053 origRegX, origRegY, SRCCOPY);
1054 /* erase the old image */
1055 BitBlt(hdcOffScreen, origOldX - origRegX, origOldY - origRegY,
1056 InternalDrag.himl->cx, InternalDrag.himl->cy, hdcBg, 0, 0,
1057 SRCCOPY);
1058 /* save the background */
1059 BitBlt(hdcBg, 0, 0, InternalDrag.himl->cx, InternalDrag.himl->cy,
1060 hdcOffScreen, origNewX - origRegX, origNewY - origRegY, SRCCOPY);
1061 /* draw the image */
1062 ImageList_InternalDragDraw(hdcOffScreen, origNewX - origRegX,
1063 origNewY - origRegY);
1064 /* draw the update region to the screen */
1065 BitBlt(hdcDrag, origRegX, origRegY, sizeRegX, sizeRegY,
1066 hdcOffScreen, 0, 0, SRCCOPY);
1067
1068 DeleteDC(hdcBg);
1069 DeleteDC(hdcOffScreen);
1070 DeleteObject(hbmOffScreen);
1071 ReleaseDC(InternalDrag.hwnd, hdcDrag);
1072 }
1073
1074 /* update the image position */
1075 InternalDrag.x = x;
1076 InternalDrag.y = y;
1077
1078 return TRUE;
1079 }
1080
1081
1082 /*************************************************************************
1083 * ImageList_DragShowNolock [COMCTL32.@]
1084 *
1085 * Shows or hides the drag image.
1086 *
1087 * PARAMS
1088 * bShow [I] TRUE shows the drag image, FALSE hides it.
1089 *
1090 * RETURNS
1091 * Success: TRUE
1092 * Failure: FALSE
1093 */
1094
1095 BOOL WINAPI
1096 ImageList_DragShowNolock (BOOL bShow)
1097 {
1098 HDC hdcDrag;
1099 HDC hdcBg;
1100 INT x, y;
1101
1102 if (!is_valid(InternalDrag.himl))
1103 return FALSE;
1104
1105 TRACE("bShow=0x%X!\n", bShow);
1106
1107 /* DragImage is already visible/hidden */
1108 if ((InternalDrag.bShow && bShow) || (!InternalDrag.bShow && !bShow)) {
1109 return FALSE;
1110 }
1111
1112 /* position of the origin of the DragImage */
1113 x = InternalDrag.x - InternalDrag.dxHotspot;
1114 y = InternalDrag.y - InternalDrag.dyHotspot;
1115
1116 hdcDrag = GetDCEx (InternalDrag.hwnd, 0,
1117 DCX_WINDOW | DCX_CACHE | DCX_LOCKWINDOWUPDATE);
1118 if (!hdcDrag) {
1119 return FALSE;
1120 }
1121
1122 hdcBg = CreateCompatibleDC(hdcDrag);
1123 if (!InternalDrag.hbmBg) {
1124 InternalDrag.hbmBg = CreateCompatibleBitmap(hdcDrag,
1125 InternalDrag.himl->cx, InternalDrag.himl->cy);
1126 }
1127 SelectObject(hdcBg, InternalDrag.hbmBg);
1128
1129 if (bShow) {
1130 /* save the background */
1131 BitBlt(hdcBg, 0, 0, InternalDrag.himl->cx, InternalDrag.himl->cy,
1132 hdcDrag, x, y, SRCCOPY);
1133 /* show the image */
1134 ImageList_InternalDragDraw(hdcDrag, x, y);
1135 } else {
1136 /* hide the image */
1137 BitBlt(hdcDrag, x, y, InternalDrag.himl->cx, InternalDrag.himl->cy,
1138 hdcBg, 0, 0, SRCCOPY);
1139 }
1140
1141 InternalDrag.bShow = !InternalDrag.bShow;
1142
1143 DeleteDC(hdcBg);
1144 ReleaseDC (InternalDrag.hwnd, hdcDrag);
1145 return TRUE;
1146 }
1147
1148
1149 /*************************************************************************
1150 * ImageList_Draw [COMCTL32.@]
1151 *
1152 * Draws an image.
1153 *
1154 * PARAMS
1155 * himl [I] handle to image list
1156 * i [I] image index
1157 * hdc [I] handle to device context
1158 * x [I] x position
1159 * y [I] y position
1160 * fStyle [I] drawing flags
1161 *
1162 * RETURNS
1163 * Success: TRUE
1164 * Failure: FALSE
1165 *
1166 * SEE
1167 * ImageList_DrawEx.
1168 */
1169
1170 BOOL WINAPI
1171 ImageList_Draw (HIMAGELIST himl, INT i, HDC hdc, INT x, INT y, UINT fStyle)
1172 {
1173 return ImageList_DrawEx (himl, i, hdc, x, y, 0, 0,
1174 CLR_DEFAULT, CLR_DEFAULT, fStyle);
1175 }
1176
1177
1178 /*************************************************************************
1179 * ImageList_DrawEx [COMCTL32.@]
1180 *
1181 * Draws an image and allows using extended drawing features.
1182 *
1183 * PARAMS
1184 * himl [I] handle to image list
1185 * i [I] image index
1186 * hdc [I] handle to device context
1187 * x [I] X position
1188 * y [I] Y position
1189 * dx [I] X offset
1190 * dy [I] Y offset
1191 * rgbBk [I] background color
1192 * rgbFg [I] foreground color
1193 * fStyle [I] drawing flags
1194 *
1195 * RETURNS
1196 * Success: TRUE
1197 * Failure: FALSE
1198 *
1199 * NOTES
1200 * Calls ImageList_DrawIndirect.
1201 *
1202 * SEE
1203 * ImageList_DrawIndirect.
1204 */
1205
1206 BOOL WINAPI
1207 ImageList_DrawEx (HIMAGELIST himl, INT i, HDC hdc, INT x, INT y,
1208 INT dx, INT dy, COLORREF rgbBk, COLORREF rgbFg,
1209 UINT fStyle)
1210 {
1211 IMAGELISTDRAWPARAMS imldp;
1212
1213 ZeroMemory (&imldp, sizeof(imldp));
1214 imldp.cbSize = sizeof(imldp);
1215 imldp.himl = himl;
1216 imldp.i = i;
1217 imldp.hdcDst = hdc,
1218 imldp.x = x;
1219 imldp.y = y;
1220 imldp.cx = dx;
1221 imldp.cy = dy;
1222 imldp.rgbBk = rgbBk;
1223 imldp.rgbFg = rgbFg;
1224 imldp.fStyle = fStyle;
1225
1226 return ImageList_DrawIndirect (&imldp);
1227 }
1228
1229
1230 static BOOL alpha_blend_image( HIMAGELIST himl, HDC dest_dc, int dest_x, int dest_y,
1231 int src_x, int src_y, int cx, int cy, BLENDFUNCTION func,
1232 UINT style, COLORREF blend_col )
1233 {
1234 BOOL ret = FALSE;
1235 HDC hdc;
1236 HBITMAP bmp = 0, mask = 0;
1237 BITMAPINFO *info;
1238 void *bits, *mask_bits;
1239 unsigned int *ptr;
1240 int i, j;
1241
1242 if (!(hdc = CreateCompatibleDC( 0 ))) return FALSE;
1243 if (!(info = HeapAlloc( GetProcessHeap(), 0, FIELD_OFFSET( BITMAPINFO, bmiColors[256] )))) goto done;
1244 info->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
1245 info->bmiHeader.biWidth = cx;
1246 info->bmiHeader.biHeight = cy;
1247 info->bmiHeader.biPlanes = 1;
1248 info->bmiHeader.biBitCount = 32;
1249 info->bmiHeader.biCompression = BI_RGB;
1250 info->bmiHeader.biSizeImage = cx * cy * 4;
1251 info->bmiHeader.biXPelsPerMeter = 0;
1252 info->bmiHeader.biYPelsPerMeter = 0;
1253 info->bmiHeader.biClrUsed = 0;
1254 info->bmiHeader.biClrImportant = 0;
1255 if (!(bmp = CreateDIBSection( himl->hdcImage, info, DIB_RGB_COLORS, &bits, 0, 0 ))) goto done;
1256 SelectObject( hdc, bmp );
1257 BitBlt( hdc, 0, 0, cx, cy, himl->hdcImage, src_x, src_y, SRCCOPY );
1258
1259 if (blend_col != CLR_NONE)
1260 {
1261 BYTE r = GetRValue( blend_col );
1262 BYTE g = GetGValue( blend_col );
1263 BYTE b = GetBValue( blend_col );
1264
1265 if (style & ILD_BLEND25)
1266 {
1267 for (i = 0, ptr = bits; i < cx * cy; i++, ptr++)
1268 *ptr = ((*ptr & 0xff000000) |
1269 ((((*ptr & 0x00ff0000) * 3 + (r << 16)) / 4) & 0x00ff0000) |
1270 ((((*ptr & 0x0000ff00) * 3 + (g << 8)) / 4) & 0x0000ff00) |
1271 ((((*ptr & 0x000000ff) * 3 + (b << 0)) / 4) & 0x000000ff));
1272 }
1273 else if (style & ILD_BLEND50)
1274 {
1275 for (i = 0, ptr = bits; i < cx * cy; i++, ptr++)
1276 *ptr = ((*ptr & 0xff000000) |
1277 ((((*ptr & 0x00ff0000) + (r << 16)) / 2) & 0x00ff0000) |
1278 ((((*ptr & 0x0000ff00) + (g << 8)) / 2) & 0x0000ff00) |
1279 ((((*ptr & 0x000000ff) + (b << 0)) / 2) & 0x000000ff));
1280 }
1281 }
1282
1283 if (himl->has_alpha) /* we already have an alpha channel in this case */
1284 {
1285 /* pre-multiply by the alpha channel */
1286 for (i = 0, ptr = bits; i < cx * cy; i++, ptr++)
1287 {
1288 DWORD alpha = *ptr >> 24;
1289 *ptr = ((*ptr & 0xff000000) |
1290 (((*ptr & 0x00ff0000) * alpha / 255) & 0x00ff0000) |
1291 (((*ptr & 0x0000ff00) * alpha / 255) & 0x0000ff00) |
1292 (((*ptr & 0x000000ff) * alpha / 255)));
1293 }
1294 }
1295 else if (himl->hbmMask)
1296 {
1297 unsigned int width_bytes = (cx + 31) / 32 * 4;
1298 /* generate alpha channel from the mask */
1299 info->bmiHeader.biBitCount = 1;
1300 info->bmiHeader.biSizeImage = width_bytes * cy;
1301 info->bmiColors[0].rgbRed = 0;
1302 info->bmiColors[0].rgbGreen = 0;
1303 info->bmiColors[0].rgbBlue = 0;
1304 info->bmiColors[0].rgbReserved = 0;
1305 info->bmiColors[1].rgbRed = 0xff;
1306 info->bmiColors[1].rgbGreen = 0xff;
1307 info->bmiColors[1].rgbBlue = 0xff;
1308 info->bmiColors[1].rgbReserved = 0;
1309 if (!(mask = CreateDIBSection( himl->hdcMask, info, DIB_RGB_COLORS, &mask_bits, 0, 0 )))
1310 goto done;
1311 SelectObject( hdc, mask );
1312 BitBlt( hdc, 0, 0, cx, cy, himl->hdcMask, src_x, src_y, SRCCOPY );
1313 SelectObject( hdc, bmp );
1314 for (i = 0, ptr = bits; i < cy; i++)
1315 for (j = 0; j < cx; j++, ptr++)
1316 if ((((BYTE *)mask_bits)[i * width_bytes + j / 8] << (j % 8)) & 0x80) *ptr = 0;
1317 else *ptr |= 0xff000000;
1318 }
1319
1320 ret = GdiAlphaBlend( dest_dc, dest_x, dest_y, cx, cy, hdc, 0, 0, cx, cy, func );
1321
1322 done:
1323 DeleteDC( hdc );
1324 if (bmp) DeleteObject( bmp );
1325 if (mask) DeleteObject( mask );
1326 HeapFree( GetProcessHeap(), 0, info );
1327 return ret;
1328 }
1329
1330 /*************************************************************************
1331 * ImageList_DrawIndirect [COMCTL32.@]
1332 *
1333 * Draws an image using various parameters specified in pimldp.
1334 *
1335 * PARAMS
1336 * pimldp [I] pointer to IMAGELISTDRAWPARAMS structure.
1337 *
1338 * RETURNS
1339 * Success: TRUE
1340 * Failure: FALSE
1341 */
1342
1343 BOOL WINAPI
1344 ImageList_DrawIndirect (IMAGELISTDRAWPARAMS *pimldp)
1345 {
1346 INT cx, cy, nOvlIdx;
1347 DWORD fState, dwRop;
1348 UINT fStyle;
1349 COLORREF oldImageBk, oldImageFg;
1350 HDC hImageDC, hImageListDC, hMaskListDC;
1351 HBITMAP hImageBmp, hOldImageBmp, hBlendMaskBmp;
1352 BOOL bIsTransparent, bBlend, bResult = FALSE, bMask;
1353 HIMAGELIST himl;
1354 HBRUSH hOldBrush;
1355 POINT pt;
1356 BOOL has_alpha;
1357
1358 if (!pimldp || !(himl = pimldp->himl)) return FALSE;
1359 if (!is_valid(himl)) return FALSE;
1360 if ((pimldp->i < 0) || (pimldp->i >= himl->cCurImage)) return FALSE;
1361
1362 imagelist_point_from_index( himl, pimldp->i, &pt );
1363 pt.x += pimldp->xBitmap;
1364 pt.y += pimldp->yBitmap;
1365
1366 fState = pimldp->cbSize < sizeof(IMAGELISTDRAWPARAMS) ? ILS_NORMAL : pimldp->fState;
1367 fStyle = pimldp->fStyle & ~ILD_OVERLAYMASK;
1368 cx = (pimldp->cx == 0) ? himl->cx : pimldp->cx;
1369 cy = (pimldp->cy == 0) ? himl->cy : pimldp->cy;
1370
1371 bIsTransparent = (fStyle & ILD_TRANSPARENT);
1372 if( pimldp->rgbBk == CLR_NONE )
1373 bIsTransparent = TRUE;
1374 if( ( pimldp->rgbBk == CLR_DEFAULT ) && ( himl->clrBk == CLR_NONE ) )
1375 bIsTransparent = TRUE;
1376 bMask = (himl->flags & ILC_MASK) && (fStyle & ILD_MASK) ;
1377 bBlend = (fStyle & (ILD_BLEND25 | ILD_BLEND50) ) && !bMask;
1378
1379 TRACE("himl(%p) hbmMask(%p) iImage(%d) x(%d) y(%d) cx(%d) cy(%d)\n",
1380 himl, himl->hbmMask, pimldp->i, pimldp->x, pimldp->y, cx, cy);
1381
1382 /* we will use these DCs to access the images and masks in the ImageList */
1383 hImageListDC = himl->hdcImage;
1384 hMaskListDC = himl->hdcMask;
1385
1386 /* these will accumulate the image and mask for the image we're drawing */
1387 hImageDC = CreateCompatibleDC( pimldp->hdcDst );
1388 hImageBmp = CreateCompatibleBitmap( pimldp->hdcDst, cx, cy );
1389 hBlendMaskBmp = bBlend ? CreateBitmap(cx, cy, 1, 1, NULL) : 0;
1390
1391 /* Create a compatible DC. */
1392 if (!hImageListDC || !hImageDC || !hImageBmp ||
1393 (bBlend && !hBlendMaskBmp) || (himl->hbmMask && !hMaskListDC))
1394 goto cleanup;
1395
1396 hOldImageBmp = SelectObject(hImageDC, hImageBmp);
1397
1398 /*
1399 * To obtain a transparent look, background color should be set
1400 * to white and foreground color to black when blitting the
1401 * monochrome mask.
1402 */
1403 oldImageFg = SetTextColor( hImageDC, RGB( 0, 0, 0 ) );
1404 oldImageBk = SetBkColor( hImageDC, RGB( 0xff, 0xff, 0xff ) );
1405
1406 has_alpha = (himl->has_alpha && himl->has_alpha[pimldp->i]);
1407 if (!bMask && (has_alpha || (fState & ILS_ALPHA)))
1408 {
1409 COLORREF colour, blend_col = CLR_NONE;
1410 BLENDFUNCTION func;
1411
1412 if (bBlend)
1413 {
1414 blend_col = pimldp->rgbFg;
1415 if (blend_col == CLR_DEFAULT) blend_col = GetSysColor( COLOR_HIGHLIGHT );
1416 else if (blend_col == CLR_NONE) blend_col = GetTextColor( pimldp->hdcDst );
1417 }
1418
1419 func.BlendOp = AC_SRC_OVER;
1420 func.BlendFlags = 0;
1421 func.SourceConstantAlpha = (fState & ILS_ALPHA) ? pimldp->Frame : 255;
1422 func.AlphaFormat = AC_SRC_ALPHA;
1423
1424 if (bIsTransparent)
1425 {
1426 bResult = alpha_blend_image( himl, pimldp->hdcDst, pimldp->x, pimldp->y,
1427 pt.x, pt.y, cx, cy, func, fStyle, blend_col );
1428 goto end;
1429 }
1430 colour = pimldp->rgbBk;
1431 if (colour == CLR_DEFAULT) colour = himl->clrBk;
1432 if (colour == CLR_NONE) colour = GetBkColor( pimldp->hdcDst );
1433
1434 hOldBrush = SelectObject (hImageDC, CreateSolidBrush (colour));
1435 PatBlt( hImageDC, 0, 0, cx, cy, PATCOPY );
1436 alpha_blend_image( himl, hImageDC, 0, 0, pt.x, pt.y, cx, cy, func, fStyle, blend_col );
1437 DeleteObject (SelectObject (hImageDC, hOldBrush));
1438 bResult = BitBlt( pimldp->hdcDst, pimldp->x, pimldp->y, cx, cy, hImageDC, 0, 0, SRCCOPY );
1439 goto end;
1440 }
1441
1442 /*
1443 * Draw the initial image
1444 */
1445 if( bMask ) {
1446 if (himl->hbmMask) {
1447 hOldBrush = SelectObject (hImageDC, CreateSolidBrush (GetTextColor(pimldp->hdcDst)));
1448 PatBlt( hImageDC, 0, 0, cx, cy, PATCOPY );
1449 BitBlt(hImageDC, 0, 0, cx, cy, hMaskListDC, pt.x, pt.y, SRCPAINT);
1450 DeleteObject (SelectObject (hImageDC, hOldBrush));
1451 if( bIsTransparent )
1452 {
1453 BitBlt ( pimldp->hdcDst, pimldp->x, pimldp->y, cx, cy, hImageDC, 0, 0, SRCAND);
1454 bResult = TRUE;
1455 goto end;
1456 }
1457 } else {
1458 hOldBrush = SelectObject (hImageDC, GetStockObject(BLACK_BRUSH));
1459 PatBlt( hImageDC, 0, 0, cx, cy, PATCOPY);
1460 SelectObject(hImageDC, hOldBrush);
1461 }
1462 } else {
1463 /* blend the image with the needed solid background */
1464 COLORREF colour = RGB(0,0,0);
1465
1466 if( !bIsTransparent )
1467 {
1468 colour = pimldp->rgbBk;
1469 if( colour == CLR_DEFAULT )
1470 colour = himl->clrBk;
1471 if( colour == CLR_NONE )
1472 colour = GetBkColor(pimldp->hdcDst);
1473 }
1474
1475 hOldBrush = SelectObject (hImageDC, CreateSolidBrush (colour));
1476 PatBlt( hImageDC, 0, 0, cx, cy, PATCOPY );
1477 if (himl->hbmMask)
1478 {
1479 BitBlt( hImageDC, 0, 0, cx, cy, hMaskListDC, pt.x, pt.y, SRCAND );
1480 BitBlt( hImageDC, 0, 0, cx, cy, hImageListDC, pt.x, pt.y, SRCPAINT );
1481 }
1482 else
1483 BitBlt( hImageDC, 0, 0, cx, cy, hImageListDC, pt.x, pt.y, SRCCOPY);
1484 DeleteObject (SelectObject (hImageDC, hOldBrush));
1485 }
1486
1487 /* Time for blending, if required */
1488 if (bBlend) {
1489 HBRUSH hBlendBrush;
1490 COLORREF clrBlend = pimldp->rgbFg;
1491 HDC hBlendMaskDC = hImageListDC;
1492 HBITMAP hOldBitmap;
1493
1494 /* Create the blend Mask */
1495 hOldBitmap = SelectObject(hBlendMaskDC, hBlendMaskBmp);
1496 hBlendBrush = fStyle & ILD_BLEND50 ? himl->hbrBlend50 : himl->hbrBlend25;
1497 hOldBrush = SelectObject(hBlendMaskDC, hBlendBrush);
1498 PatBlt(hBlendMaskDC, 0, 0, cx, cy, PATCOPY);
1499 SelectObject(hBlendMaskDC, hOldBrush);
1500
1501 /* Modify the blend mask if an Image Mask exist */
1502 if(himl->hbmMask) {
1503 BitBlt(hBlendMaskDC, 0, 0, cx, cy, hMaskListDC, pt.x, pt.y, 0x220326); /* NOTSRCAND */
1504 BitBlt(hBlendMaskDC, 0, 0, cx, cy, hBlendMaskDC, 0, 0, NOTSRCCOPY);
1505 }
1506
1507 /* now apply blend to the current image given the BlendMask */
1508 if (clrBlend == CLR_DEFAULT) clrBlend = GetSysColor (COLOR_HIGHLIGHT);
1509 else if (clrBlend == CLR_NONE) clrBlend = GetTextColor (pimldp->hdcDst);
1510 hOldBrush = SelectObject (hImageDC, CreateSolidBrush(clrBlend));
1511 BitBlt (hImageDC, 0, 0, cx, cy, hBlendMaskDC, 0, 0, 0xB8074A); /* PSDPxax */
1512 DeleteObject(SelectObject(hImageDC, hOldBrush));
1513 SelectObject(hBlendMaskDC, hOldBitmap);
1514 }
1515
1516 /* Now do the overlay image, if any */
1517 nOvlIdx = (pimldp->fStyle & ILD_OVERLAYMASK) >> 8;
1518 if ( (nOvlIdx >= 1) && (nOvlIdx <= MAX_OVERLAYIMAGE)) {
1519 nOvlIdx = himl->nOvlIdx[nOvlIdx - 1];
1520 if ((nOvlIdx >= 0) && (nOvlIdx < himl->cCurImage)) {
1521 POINT ptOvl;
1522 imagelist_point_from_index( himl, nOvlIdx, &ptOvl );
1523 ptOvl.x += pimldp->xBitmap;
1524 if (himl->hbmMask && !(fStyle & ILD_IMAGE))
1525 BitBlt (hImageDC, 0, 0, cx, cy, hMaskListDC, ptOvl.x, ptOvl.y, SRCAND);
1526 BitBlt (hImageDC, 0, 0, cx, cy, hImageListDC, ptOvl.x, ptOvl.y, SRCPAINT);
1527 }
1528 }
1529
1530 if (fState & ILS_SATURATE) FIXME("ILS_SATURATE: unimplemented!\n");
1531 if (fState & ILS_GLOW) FIXME("ILS_GLOW: unimplemented!\n");
1532 if (fState & ILS_SHADOW) FIXME("ILS_SHADOW: unimplemented!\n");
1533
1534 if (fStyle & ILD_PRESERVEALPHA) FIXME("ILD_PRESERVEALPHA: unimplemented!\n");
1535 if (fStyle & ILD_SCALE) FIXME("ILD_SCALE: unimplemented!\n");
1536 if (fStyle & ILD_DPISCALE) FIXME("ILD_DPISCALE: unimplemented!\n");
1537
1538 /* now copy the image to the screen */
1539 dwRop = SRCCOPY;
1540 if (himl->hbmMask && bIsTransparent ) {
1541 COLORREF oldDstFg = SetTextColor(pimldp->hdcDst, RGB( 0, 0, 0 ) );
1542 COLORREF oldDstBk = SetBkColor(pimldp->hdcDst, RGB( 0xff, 0xff, 0xff ));
1543 BitBlt (pimldp->hdcDst, pimldp->x, pimldp->y, cx, cy, hMaskListDC, pt.x, pt.y, SRCAND);
1544 SetBkColor(pimldp->hdcDst, oldDstBk);
1545 SetTextColor(pimldp->hdcDst, oldDstFg);
1546 dwRop = SRCPAINT;
1547 }
1548 if (fStyle & ILD_ROP) dwRop = pimldp->dwRop;
1549 BitBlt (pimldp->hdcDst, pimldp->x, pimldp->y, cx, cy, hImageDC, 0, 0, dwRop);
1550
1551 bResult = TRUE;
1552 end:
1553 /* cleanup the mess */
1554 SetBkColor(hImageDC, oldImageBk);
1555 SetTextColor(hImageDC, oldImageFg);
1556 SelectObject(hImageDC, hOldImageBmp);
1557 cleanup:
1558 DeleteObject(hBlendMaskBmp);
1559 DeleteObject(hImageBmp);
1560 DeleteDC(hImageDC);
1561
1562 return bResult;
1563 }
1564
1565
1566 /*************************************************************************
1567 * ImageList_Duplicate [COMCTL32.@]
1568 *
1569 * Duplicates an image list.
1570 *
1571 * PARAMS
1572 * himlSrc [I] source image list handle
1573 *
1574 * RETURNS
1575 * Success: Handle of duplicated image list.
1576 * Failure: NULL
1577 */
1578
1579 HIMAGELIST WINAPI
1580 ImageList_Duplicate (HIMAGELIST himlSrc)
1581 {
1582 HIMAGELIST himlDst;
1583
1584 if (!is_valid(himlSrc)) {
1585 ERR("Invalid image list handle!\n");
1586 return NULL;
1587 }
1588
1589 himlDst = ImageList_Create (himlSrc->cx, himlSrc->cy, himlSrc->flags,
1590 himlSrc->cCurImage, himlSrc->cGrow);
1591
1592 if (himlDst)
1593 {
1594 SIZE sz;
1595
1596 imagelist_get_bitmap_size(himlSrc, himlSrc->cCurImage, &sz);
1597 BitBlt (himlDst->hdcImage, 0, 0, sz.cx, sz.cy,
1598 himlSrc->hdcImage, 0, 0, SRCCOPY);
1599
1600 if (himlDst->hbmMask)
1601 BitBlt (himlDst->hdcMask, 0, 0, sz.cx, sz.cy,
1602 himlSrc->hdcMask, 0, 0, SRCCOPY);
1603
1604 himlDst->cCurImage = himlSrc->cCurImage;
1605 if (himlSrc->has_alpha && himlDst->has_alpha)
1606 memcpy( himlDst->has_alpha, himlSrc->has_alpha, himlDst->cCurImage );
1607 }
1608 return himlDst;
1609 }
1610
1611
1612 /*************************************************************************
1613 * ImageList_EndDrag [COMCTL32.@]
1614 *
1615 * Finishes a drag operation.
1616 *
1617 * PARAMS
1618 * no Parameters
1619 *
1620 * RETURNS
1621 * Success: TRUE
1622 * Failure: FALSE
1623 */
1624
1625 VOID WINAPI
1626 ImageList_EndDrag (void)
1627 {
1628 /* cleanup the InternalDrag struct */
1629 InternalDrag.hwnd = 0;
1630 if (InternalDrag.himl != InternalDrag.himlNoCursor)
1631 ImageList_Destroy (InternalDrag.himlNoCursor);
1632 ImageList_Destroy (InternalDrag.himl);
1633 InternalDrag.himlNoCursor = InternalDrag.himl = 0;
1634 InternalDrag.x= 0;
1635 InternalDrag.y= 0;
1636 InternalDrag.dxHotspot = 0;
1637 InternalDrag.dyHotspot = 0;
1638 InternalDrag.bShow = FALSE;
1639 DeleteObject(InternalDrag.hbmBg);
1640 InternalDrag.hbmBg = 0;
1641 }
1642
1643
1644 /*************************************************************************
1645 * ImageList_GetBkColor [COMCTL32.@]
1646 *
1647 * Returns the background color of an image list.
1648 *
1649 * PARAMS
1650 * himl [I] Image list handle.
1651 *
1652 * RETURNS
1653 * Success: background color
1654 * Failure: CLR_NONE
1655 */
1656
1657 COLORREF WINAPI
1658 ImageList_GetBkColor (HIMAGELIST himl)
1659 {
1660 return himl ? himl->clrBk : CLR_NONE;
1661 }
1662
1663
1664 /*************************************************************************
1665 * ImageList_GetDragImage [COMCTL32.@]
1666 *
1667 * Returns the handle to the internal drag image list.
1668 *
1669 * PARAMS
1670 * ppt [O] Pointer to the drag position. Can be NULL.
1671 * pptHotspot [O] Pointer to the position of the hot spot. Can be NULL.
1672 *
1673 * RETURNS
1674 * Success: Handle of the drag image list.
1675 * Failure: NULL.
1676 */
1677
1678 HIMAGELIST WINAPI
1679 ImageList_GetDragImage (POINT *ppt, POINT *pptHotspot)
1680 {
1681 if (is_valid(InternalDrag.himl)) {
1682 if (ppt) {
1683 ppt->x = InternalDrag.x;
1684 ppt->y = InternalDrag.y;
1685 }
1686 if (pptHotspot) {
1687 pptHotspot->x = InternalDrag.dxHotspot;
1688 pptHotspot->y = InternalDrag.dyHotspot;
1689 }
1690 return (InternalDrag.himl);
1691 }
1692
1693 return NULL;
1694 }
1695
1696
1697 /*************************************************************************
1698 * ImageList_GetFlags [COMCTL32.@]
1699 *
1700 * Gets the flags of the specified image list.
1701 *
1702 * PARAMS
1703 * himl [I] Handle to image list
1704 *
1705 * RETURNS
1706 * Image list flags.
1707 *
1708 * BUGS
1709 * Stub.
1710 */
1711
1712 DWORD WINAPI
1713 ImageList_GetFlags(HIMAGELIST himl)
1714 {
1715 TRACE("%p\n", himl);
1716
1717 return is_valid(himl) ? himl->flags : 0;
1718 }
1719
1720
1721 /*************************************************************************
1722 * ImageList_GetIcon [COMCTL32.@]
1723 *
1724 * Creates an icon from a masked image of an image list.
1725 *
1726 * PARAMS
1727 * himl [I] handle to image list
1728 * i [I] image index
1729 * flags [I] drawing style flags
1730 *
1731 * RETURNS
1732 * Success: icon handle
1733 * Failure: NULL
1734 */
1735
1736 HICON WINAPI
1737 ImageList_GetIcon (HIMAGELIST himl, INT i, UINT fStyle)
1738 {
1739 ICONINFO ii;
1740 HICON hIcon;
1741 HBITMAP hOldDstBitmap;
1742 HDC hdcDst;
1743 POINT pt;
1744
1745 TRACE("%p %d %d\n", himl, i, fStyle);
1746 if (!is_valid(himl) || (i < 0) || (i >= himl->cCurImage)) return NULL;
1747
1748 ii.fIcon = TRUE;
1749 ii.xHotspot = 0;
1750 ii.yHotspot = 0;
1751
1752 /* create colour bitmap */
1753 hdcDst = GetDC(0);
1754 ii.hbmColor = CreateCompatibleBitmap(hdcDst, himl->cx, himl->cy);
1755 ReleaseDC(0, hdcDst);
1756
1757 hdcDst = CreateCompatibleDC(0);
1758
1759 imagelist_point_from_index( himl, i, &pt );
1760
1761 /* draw mask*/
1762 ii.hbmMask = CreateBitmap (himl->cx, himl->cy, 1, 1, NULL);
1763 hOldDstBitmap = SelectObject (hdcDst, ii.hbmMask);
1764 if (himl->hbmMask) {
1765 BitBlt (hdcDst, 0, 0, himl->cx, himl->cy,
1766 himl->hdcMask, pt.x, pt.y, SRCCOPY);
1767 }
1768 else
1769 PatBlt (hdcDst, 0, 0, himl->cx, himl->cy, BLACKNESS);
1770
1771 /* draw image*/
1772 SelectObject (hdcDst, ii.hbmColor);
1773 BitBlt (hdcDst, 0, 0, himl->cx, himl->cy,
1774 himl->hdcImage, pt.x, pt.y, SRCCOPY);
1775
1776 /*
1777 * CreateIconIndirect requires us to deselect the bitmaps from
1778 * the DCs before calling
1779 */
1780 SelectObject(hdcDst, hOldDstBitmap);
1781
1782 hIcon = CreateIconIndirect (&ii);
1783
1784 DeleteObject (ii.hbmMask);
1785 DeleteObject (ii.hbmColor);
1786 DeleteDC (hdcDst);
1787
1788 return hIcon;
1789 }
1790
1791
1792 /*************************************************************************
1793 * ImageList_GetIconSize [COMCTL32.@]
1794 *
1795 * Retrieves the size of an image in an image list.
1796 *
1797 * PARAMS
1798 * himl [I] handle to image list
1799 * cx [O] pointer to the image width.
1800 * cy [O] pointer to the image height.
1801 *
1802 * RETURNS
1803 * Success: TRUE
1804 * Failure: FALSE
1805 *
1806 * NOTES
1807 * All images in an image list have the same size.
1808 */
1809
1810 BOOL WINAPI
1811 ImageList_GetIconSize (HIMAGELIST himl, INT *cx, INT *cy)
1812 {
1813 if (!is_valid(himl) || !cx || !cy)
1814 return FALSE;
1815 if ((himl->cx <= 0) || (himl->cy <= 0))
1816 return FALSE;
1817
1818 *cx = himl->cx;
1819 *cy = himl->cy;
1820
1821 return TRUE;
1822 }
1823
1824
1825 /*************************************************************************
1826 * ImageList_GetImageCount [COMCTL32.@]
1827 *
1828 * Returns the number of images in an image list.
1829 *
1830 * PARAMS
1831 * himl [I] handle to image list
1832 *
1833 * RETURNS
1834 * Success: Number of images.
1835 * Failure: 0
1836 */
1837
1838 INT WINAPI
1839 ImageList_GetImageCount (HIMAGELIST himl)
1840 {
1841 if (!is_valid(himl))
1842 return 0;
1843
1844 return himl->cCurImage;
1845 }
1846
1847
1848 /*************************************************************************
1849 * ImageList_GetImageInfo [COMCTL32.@]
1850 *
1851 * Returns information about an image in an image list.
1852 *
1853 * PARAMS
1854 * himl [I] handle to image list
1855 * i [I] image index
1856 * pImageInfo [O] pointer to the image information
1857 *
1858 * RETURNS
1859 * Success: TRUE
1860 * Failure: FALSE
1861 */
1862
1863 BOOL WINAPI
1864 ImageList_GetImageInfo (HIMAGELIST himl, INT i, IMAGEINFO *pImageInfo)
1865 {
1866 POINT pt;
1867
1868 if (!is_valid(himl) || (pImageInfo == NULL))
1869 return FALSE;
1870 if ((i < 0) || (i >= himl->cCurImage))
1871 return FALSE;
1872
1873 pImageInfo->hbmImage = himl->hbmImage;
1874 pImageInfo->hbmMask = himl->hbmMask;
1875
1876 imagelist_point_from_index( himl, i, &pt );
1877 pImageInfo->rcImage.top = pt.y;
1878 pImageInfo->rcImage.bottom = pt.y + himl->cy;
1879 pImageInfo->rcImage.left = pt.x;
1880 pImageInfo->rcImage.right = pt.x + himl->cx;
1881
1882 return TRUE;
1883 }
1884
1885
1886 /*************************************************************************
1887 * ImageList_GetImageRect [COMCTL32.@]
1888 *
1889 * Retrieves the rectangle of the specified image in an image list.
1890 *
1891 * PARAMS
1892 * himl [I] handle to image list
1893 * i [I] image index
1894 * lpRect [O] pointer to the image rectangle
1895 *
1896 * RETURNS
1897 * Success: TRUE
1898 * Failure: FALSE
1899 *
1900 * NOTES
1901 * This is an UNDOCUMENTED function!!!
1902 */
1903
1904 BOOL WINAPI
1905 ImageList_GetImageRect (HIMAGELIST himl, INT i, LPRECT lpRect)
1906 {
1907 POINT pt;
1908
1909 if (!is_valid(himl) || (lpRect == NULL))
1910 return FALSE;
1911 if ((i < 0) || (i >= himl->cCurImage))
1912 return FALSE;
1913
1914 imagelist_point_from_index( himl, i, &pt );
1915 lpRect->left = pt.x;
1916 lpRect->top = pt.y;
1917 lpRect->right = pt.x + himl->cx;
1918 lpRect->bottom = pt.y + himl->cy;
1919
1920 return TRUE;
1921 }
1922
1923
1924 /*************************************************************************
1925 * ImageList_LoadImage [COMCTL32.@]
1926 * ImageList_LoadImageA [COMCTL32.@]
1927 *
1928 * Creates an image list from a bitmap, icon or cursor.
1929 *
1930 * See ImageList_LoadImageW.
1931 */
1932
1933 HIMAGELIST WINAPI
1934 ImageList_LoadImageA (HINSTANCE hi, LPCSTR lpbmp, INT cx, INT cGrow,
1935 COLORREF clrMask, UINT uType, UINT uFlags)
1936 {
1937 HIMAGELIST himl;
1938 LPWSTR lpbmpW;
1939 DWORD len;
1940
1941 if (IS_INTRESOURCE(lpbmp))
1942 return ImageList_LoadImageW(hi, (LPCWSTR)lpbmp, cx, cGrow, clrMask,
1943 uType, uFlags);
1944
1945 len = MultiByteToWideChar(CP_ACP, 0, lpbmp, -1, NULL, 0);
1946 lpbmpW = Alloc(len * sizeof(WCHAR));
1947 MultiByteToWideChar(CP_ACP, 0, lpbmp, -1, lpbmpW, len);
1948
1949 himl = ImageList_LoadImageW(hi, lpbmpW, cx, cGrow, clrMask, uType, uFlags);
1950 Free (lpbmpW);
1951 return himl;
1952 }
1953
1954
1955 /*************************************************************************
1956 * ImageList_LoadImageW [COMCTL32.@]
1957 *
1958 * Creates an image list from a bitmap, icon or cursor.
1959 *
1960 * PARAMS
1961 * hi [I] instance handle
1962 * lpbmp [I] name or id of the image
1963 * cx [I] width of each image
1964 * cGrow [I] number of images to expand
1965 * clrMask [I] mask color
1966 * uType [I] type of image to load
1967 * uFlags [I] loading flags
1968 *
1969 * RETURNS
1970 * Success: handle to the loaded image list
1971 * Failure: NULL
1972 *
1973 * SEE
1974 * LoadImage ()
1975 */
1976
1977 HIMAGELIST WINAPI
1978 ImageList_LoadImageW (HINSTANCE hi, LPCWSTR lpbmp, INT cx, INT cGrow,
1979 COLORREF clrMask, UINT uType, UINT uFlags)
1980 {
1981 HIMAGELIST himl = NULL;
1982 HANDLE handle;
1983 INT nImageCount;
1984
1985 handle = LoadImageW (hi, lpbmp, uType, 0, 0, uFlags);
1986 if (!handle) {
1987 WARN("Couldn't load image\n");
1988 return NULL;
1989 }
1990
1991 if (uType == IMAGE_BITMAP) {
1992 DIBSECTION dib;
1993 UINT color;
1994
1995 if (GetObjectW (handle, sizeof(dib), &dib) == sizeof(BITMAP)) color = ILC_COLOR;
1996 else color = dib.dsBm.bmBitsPixel;
1997
1998 /* To match windows behavior, if cx is set to zero and
1999 the flag DI_DEFAULTSIZE is specified, cx becomes the
2000 system metric value for icons. If the flag is not specified
2001 the function sets the size to the height of the bitmap */
2002 if (cx == 0)
2003 {
2004 if (uFlags & DI_DEFAULTSIZE)
2005 cx = GetSystemMetrics (SM_CXICON);
2006 else
2007 cx = dib.dsBm.bmHeight;
2008 }
2009
2010 nImageCount = dib.dsBm.bmWidth / cx;
2011
2012 himl = ImageList_Create (cx, dib.dsBm.bmHeight, ILC_MASK | color, nImageCount, cGrow);
2013 if (!himl) {
2014 DeleteObject (handle);
2015 return NULL;
2016 }
2017 ImageList_AddMasked (himl, handle, clrMask);
2018 }
2019 else if ((uType == IMAGE_ICON) || (uType == IMAGE_CURSOR)) {
2020 ICONINFO ii;
2021 BITMAP bmp;
2022
2023 GetIconInfo (handle, &ii);
2024 GetObjectW (ii.hbmColor, sizeof(BITMAP), &bmp);
2025 himl = ImageList_Create (bmp.bmWidth, bmp.bmHeight,
2026 ILC_MASK | ILC_COLOR, 1, cGrow);
2027 if (!himl) {
2028 DeleteObject (ii.hbmColor);
2029 DeleteObject (ii.hbmMask);
2030 DeleteObject (handle);
2031 return NULL;
2032 }
2033 ImageList_Add (himl, ii.hbmColor, ii.hbmMask);
2034 DeleteObject (ii.hbmColor);
2035 DeleteObject (ii.hbmMask);
2036 }
2037
2038 DeleteObject (handle);
2039
2040 return himl;
2041 }
2042
2043
2044 /*************************************************************************
2045 * ImageList_Merge [COMCTL32.@]
2046 *
2047 * Create an image list containing a merged image from two image lists.
2048 *
2049 * PARAMS
2050 * himl1 [I] handle to first image list
2051 * i1 [I] first image index
2052 * himl2 [I] handle to second image list
2053 * i2 [I] second image index
2054 * dx [I] X offset of the second image relative to the first.
2055 * dy [I] Y offset of the second image relative to the first.
2056 *
2057 * RETURNS
2058 * Success: The newly created image list. It contains a single image
2059 * consisting of the second image merged with the first.
2060 * Failure: NULL, if either himl1 or himl2 is invalid.
2061 *
2062 * NOTES
2063 * - The returned image list should be deleted by the caller using
2064 * ImageList_Destroy() when it is no longer required.
2065 * - If either i1 or i2 is not a valid image index, they will be treated
2066 * as blank images.
2067 */
2068 HIMAGELIST WINAPI
2069 ImageList_Merge (HIMAGELIST himl1, INT i1, HIMAGELIST himl2, INT i2,
2070 INT dx, INT dy)
2071 {
2072 HIMAGELIST himlDst = NULL;
2073 INT cxDst, cyDst;
2074 INT xOff1, yOff1, xOff2, yOff2;
2075 POINT pt1, pt2;
2076 INT newFlags;
2077
2078 TRACE("(himl1=%p i1=%d himl2=%p i2=%d dx=%d dy=%d)\n", himl1, i1, himl2,
2079 i2, dx, dy);
2080
2081 if (!is_valid(himl1) || !is_valid(himl2))
2082 return NULL;
2083
2084 if (dx > 0) {
2085 cxDst = max (himl1->cx, dx + himl2->cx);
2086 xOff1 = 0;
2087 xOff2 = dx;
2088 }
2089 else if (dx < 0) {
2090 cxDst = max (himl2->cx, himl1->cx - dx);
2091 xOff1 = -dx;
2092 xOff2 = 0;
2093 }
2094 else {
2095 cxDst = max (himl1->cx, himl2->cx);
2096 xOff1 = 0;
2097 xOff2 = 0;
2098 }
2099
2100 if (dy > 0) {
2101 cyDst = max (himl1->cy, dy + himl2->cy);
2102 yOff1 = 0;
2103 yOff2 = dy;
2104 }
2105 else if (dy < 0) {
2106 cyDst = max (himl2->cy, himl1->cy - dy);
2107 yOff1 = -dy;
2108 yOff2 = 0;
2109 }
2110 else {
2111 cyDst = max (himl1->cy, himl2->cy);
2112 yOff1 = 0;
2113 yOff2 = 0;
2114 }
2115
2116 newFlags = (himl1->flags > himl2->flags ? himl1->flags : himl2->flags) & ILC_COLORDDB;
2117 if (newFlags == ILC_COLORDDB && (himl1->flags & ILC_COLORDDB) == ILC_COLOR16)
2118 newFlags = ILC_COLOR16; /* this is what native (at least v5) does, don't know why */
2119 himlDst = ImageList_Create (cxDst, cyDst, ILC_MASK | newFlags, 1, 1);
2120
2121 if (himlDst)
2122 {
2123 imagelist_point_from_index( himl1, i1, &pt1 );
2124 imagelist_point_from_index( himl2, i2, &pt2 );
2125
2126 /* copy image */
2127 BitBlt (himlDst->hdcImage, 0, 0, cxDst, cyDst, himl1->hdcImage, 0, 0, BLACKNESS);
2128 if (i1 >= 0 && i1 < himl1->cCurImage)
2129 BitBlt (himlDst->hdcImage, xOff1, yOff1, himl1->cx, himl1->cy, himl1->hdcImage, pt1.x, pt1.y, SRCCOPY);
2130 if (i2 >= 0 && i2 < himl2->cCurImage)
2131 {
2132 if (himl2->flags & ILC_MASK)
2133 {
2134 BitBlt (himlDst->hdcImage, xOff2, yOff2, himl2->cx, himl2->cy, himl2->hdcMask , pt2.x, pt2.y, SRCAND);
2135 BitBlt (himlDst->hdcImage, xOff2, yOff2, himl2->cx, himl2->cy, himl2->hdcImage, pt2.x, pt2.y, SRCPAINT);
2136 }
2137 else
2138 BitBlt (himlDst->hdcImage, xOff2, yOff2, himl2->cx, himl2->cy, himl2->hdcImage, pt2.x, pt2.y, SRCCOPY);
2139 }
2140
2141 /* copy mask */
2142 BitBlt (himlDst->hdcMask, 0, 0, cxDst, cyDst, himl1->hdcMask, 0, 0, WHITENESS);
2143 if (i1 >= 0 && i1 < himl1->cCurImage)
2144 BitBlt (himlDst->hdcMask, xOff1, yOff1, himl1->cx, himl1->cy, himl1->hdcMask, pt1.x, pt1.y, SRCCOPY);
2145 if (i2 >= 0 && i2 < himl2->cCurImage)
2146 BitBlt (himlDst->hdcMask, xOff2, yOff2, himl2->cx, himl2->cy, himl2->hdcMask, pt2.x, pt2.y, SRCAND);
2147
2148 himlDst->cCurImage = 1;
2149 }
2150
2151 return himlDst;
2152 }
2153
2154
2155 /* helper for ImageList_Read, see comments below */
2156 static void *read_bitmap(LPSTREAM pstm, BITMAPINFO *bmi)
2157 {
2158 BITMAPFILEHEADER bmfh;
2159 int bitsperpixel, palspace;
2160 void *bits;
2161
2162 if (FAILED(IStream_Read ( pstm, &bmfh, sizeof(bmfh), NULL)))
2163 return NULL;
2164
2165 if (bmfh.bfType != (('M'<<8)|'B'))
2166 return NULL;
2167
2168 if (FAILED(IStream_Read ( pstm, &bmi->bmiHeader, sizeof(bmi->bmiHeader), NULL)))
2169 return NULL;
2170
2171 if ((bmi->bmiHeader.biSize != sizeof(bmi->bmiHeader)))
2172 return NULL;
2173
2174 TRACE("width %u, height %u, planes %u, bpp %u\n",
2175 bmi->bmiHeader.biWidth, bmi->bmiHeader.biHeight,
2176 bmi->bmiHeader.biPlanes, bmi->bmiHeader.biBitCount);
2177
2178 bitsperpixel = bmi->bmiHeader.biPlanes * bmi->bmiHeader.biBitCount;
2179 if (bitsperpixel<=8)
2180 palspace = (1<<bitsperpixel)*sizeof(RGBQUAD);
2181 else
2182 palspace = 0;
2183
2184 bmi->bmiHeader.biSizeImage = get_dib_image_size( bmi );
2185
2186 /* read the palette right after the end of the bitmapinfoheader */
2187 if (palspace && FAILED(IStream_Read(pstm, bmi->bmiColors, palspace, NULL)))
2188 return NULL;
2189
2190 bits = Alloc(bmi->bmiHeader.biSizeImage);
2191 if (!bits) return NULL;
2192
2193 if (FAILED(IStream_Read(pstm, bits, bmi->bmiHeader.biSizeImage, NULL)))
2194 {
2195 Free(bits);
2196 return NULL;
2197 }
2198 return bits;
2199 }
2200
2201 /*************************************************************************
2202 * ImageList_Read [COMCTL32.@]
2203 *
2204 * Reads an image list from a stream.
2205 *
2206 * PARAMS
2207 * pstm [I] pointer to a stream
2208 *
2209 * RETURNS
2210 * Success: handle to image list
2211 * Failure: NULL
2212 *
2213 * The format is like this:
2214 * ILHEAD ilheadstruct;
2215 *
2216 * for the color image part:
2217 * BITMAPFILEHEADER bmfh;
2218 * BITMAPINFOHEADER bmih;
2219 * only if it has a palette:
2220 * RGBQUAD rgbs[nr_of_paletted_colors];
2221 *
2222 * BYTE colorbits[imagesize];
2223 *
2224 * the following only if the ILC_MASK bit is set in ILHEAD.ilFlags:
2225 * BITMAPFILEHEADER bmfh_mask;
2226 * BITMAPINFOHEADER bmih_mask;
2227 * only if it has a palette (it usually does not):
2228 * RGBQUAD rgbs[nr_of_paletted_colors];
2229 *
2230 * BYTE maskbits[imagesize];
2231 */
2232 HIMAGELIST WINAPI ImageList_Read (LPSTREAM pstm)
2233 {
2234 char image_buf[sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD) * 256];
2235 char mask_buf[sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD) * 256];
2236 BITMAPINFO *image_info = (BITMAPINFO *)image_buf;
2237 BITMAPINFO *mask_info = (BITMAPINFO *)mask_buf;
2238 void *image_bits, *mask_bits = NULL;
2239 ILHEAD ilHead;
2240 HIMAGELIST himl;
2241 unsigned int i;
2242
2243 TRACE("%p\n", pstm);
2244
2245 if (FAILED(IStream_Read (pstm, &ilHead, sizeof(ILHEAD), NULL)))
2246 return NULL;
2247 if (ilHead.usMagic != (('L' << 8) | 'I'))
2248 return NULL;
2249 if (ilHead.usVersion != 0x101) /* probably version? */
2250 return NULL;
2251
2252 TRACE("cx %u, cy %u, flags 0x%04x, cCurImage %u, cMaxImage %u\n",
2253 ilHead.cx, ilHead.cy, ilHead.flags, ilHead.cCurImage, ilHead.cMaxImage);
2254
2255 himl = ImageList_Create(ilHead.cx, ilHead.cy, ilHead.flags, ilHead.cCurImage, ilHead.cMaxImage);
2256 if (!himl)
2257 return NULL;
2258
2259 if (!(image_bits = read_bitmap(pstm, image_info)))
2260 {
2261 WARN("failed to read bitmap from stream\n");
2262 return NULL;
2263 }
2264 if (ilHead.flags & ILC_MASK)
2265 {
2266 if (!(mask_bits = read_bitmap(pstm, mask_info)))
2267 {
2268 WARN("failed to read mask bitmap from stream\n");
2269 return NULL;
2270 }
2271 }
2272 else mask_info = NULL;
2273
2274 if (himl->has_alpha && image_info->bmiHeader.biBitCount == 32)
2275 {
2276 DWORD *ptr = image_bits;
2277 BYTE *mask_ptr = mask_bits;
2278 int stride = himl->cy * image_info->bmiHeader.biWidth;
2279
2280 if (image_info->bmiHeader.biHeight > 0) /* bottom-up */
2281 {
2282 ptr += image_info->bmiHeader.biHeight * image_info->bmiHeader.biWidth - stride;
2283 mask_ptr += (image_info->bmiHeader.biHeight * image_info->bmiHeader.biWidth - stride) / 8;
2284 stride = -stride;
2285 image_info->bmiHeader.biHeight = himl->cy;
2286 }
2287 else image_info->bmiHeader.biHeight = -himl->cy;
2288
2289 for (i = 0; i < ilHead.cCurImage; i += TILE_COUNT)
2290 {
2291 add_dib_bits( himl, i, min( ilHead.cCurImage - i, TILE_COUNT ),
2292 himl->cx, himl->cy, image_info, mask_info, ptr, mask_ptr );
2293 ptr += stride;
2294 mask_ptr += stride / 8;
2295 }
2296 }
2297 else
2298 {
2299 StretchDIBits( himl->hdcImage, 0, 0, image_info->bmiHeader.biWidth, image_info->bmiHeader.biHeight,
2300 0, 0, image_info->bmiHeader.biWidth, image_info->bmiHeader.biHeight,
2301 image_bits, image_info, DIB_RGB_COLORS, SRCCOPY);
2302 if (mask_info)
2303 StretchDIBits( himl->hdcMask, 0, 0, mask_info->bmiHeader.biWidth, mask_info->bmiHeader.biHeight,
2304 0, 0, mask_info->bmiHeader.biWidth, mask_info->bmiHeader.biHeight,
2305 mask_bits, mask_info, DIB_RGB_COLORS, SRCCOPY);
2306 }
2307 Free( image_bits );
2308 Free( mask_bits );
2309
2310 himl->cCurImage = ilHead.cCurImage;
2311 himl->cMaxImage = ilHead.cMaxImage;
2312
2313 ImageList_SetBkColor(himl,ilHead.bkcolor);
2314 for (i=0;i<4;i++)
2315 ImageList_SetOverlayImage(himl,ilHead.ovls[i],i+1);
2316 return himl;
2317 }
2318
2319
2320 /*************************************************************************
2321 * ImageList_Remove [COMCTL32.@]
2322 *
2323 * Removes an image from an image list
2324 *
2325 * PARAMS
2326 * himl [I] image list handle
2327 * i [I] image index
2328 *
2329 * RETURNS
2330 * Success: TRUE
2331 * Failure: FALSE
2332 *
2333 * FIXME: as the image list storage test shows, native comctl32 simply shifts
2334 * images without creating a new bitmap.
2335 */
2336 BOOL WINAPI
2337 ImageList_Remove (HIMAGELIST himl, INT i)
2338 {
2339 HBITMAP hbmNewImage, hbmNewMask;
2340 HDC hdcBmp;
2341 SIZE sz;
2342
2343 TRACE("(himl=%p i=%d)\n", himl, i);
2344
2345 if (!is_valid(himl)) {
2346 ERR("Invalid image list handle!\n");
2347 return FALSE;
2348 }
2349
2350 if ((i < -1) || (i >= himl->cCurImage)) {
2351 TRACE("index out of range! %d\n", i);
2352 return FALSE;
2353 }
2354
2355 if (i == -1) {
2356 INT nCount;
2357
2358 /* remove all */
2359 if (himl->cCurImage == 0) {
2360 /* remove all on empty ImageList is allowed */
2361 TRACE("remove all on empty ImageList!\n");
2362 return TRUE;
2363 }
2364
2365 himl->cMaxImage = himl->cGrow;
2366 himl->cCurImage = 0;
2367 for (nCount = 0; nCount < MAX_OVERLAYIMAGE; nCount++)
2368 himl->nOvlIdx[nCount] = -1;
2369
2370 if (himl->has_alpha)
2371 {
2372 HeapFree( GetProcessHeap(), 0, himl->has_alpha );
2373 himl->has_alpha = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, himl->cMaxImage );
2374 }
2375
2376 hbmNewImage = ImageList_CreateImage(himl->hdcImage, himl, himl->cMaxImage);
2377 SelectObject (himl->hdcImage, hbmNewImage);
2378 DeleteObject (himl->hbmImage);
2379 himl->hbmImage = hbmNewImage;
2380
2381 if (himl->hbmMask) {
2382
2383 imagelist_get_bitmap_size(himl, himl->cMaxImage, &sz);
2384 hbmNewMask = CreateBitmap (sz.cx, sz.cy, 1, 1, NULL);
2385 SelectObject (himl->hdcMask, hbmNewMask);
2386 DeleteObject (himl->hbmMask);
2387 himl->hbmMask = hbmNewMask;
2388 }
2389 }
2390 else {
2391 /* delete one image */
2392 TRACE("Remove single image! %d\n", i);
2393
2394 /* create new bitmap(s) */
2395 TRACE(" - Number of images: %d / %d (Old/New)\n",
2396 himl->cCurImage, himl->cCurImage - 1);
2397
2398 hbmNewImage = ImageList_CreateImage(himl->hdcImage, himl, himl->cMaxImage);
2399
2400 imagelist_get_bitmap_size(himl, himl->cMaxImage, &sz );
2401 if (himl->hbmMask)
2402 hbmNewMask = CreateBitmap (sz.cx, sz.cy, 1, 1, NULL);
2403 else
2404 hbmNewMask = 0; /* Just to keep compiler happy! */
2405
2406 hdcBmp = CreateCompatibleDC (0);
2407
2408 /* copy all images and masks prior to the "removed" image */
2409 if (i > 0) {
2410 TRACE("Pre image copy: Copy %d images\n", i);
2411
2412 SelectObject (hdcBmp, hbmNewImage);
2413 imagelist_copy_images( himl, himl->hdcImage, hdcBmp, 0, i, 0 );
2414
2415 if (himl->hbmMask) {
2416 SelectObject (hdcBmp, hbmNewMask);
2417 imagelist_copy_images( himl, himl->hdcMask, hdcBmp, 0, i, 0 );
2418 }
2419 }
2420
2421 /* copy all images and masks behind the removed image */
2422 if (i < himl->cCurImage - 1) {
2423 TRACE("Post image copy!\n");
2424
2425 SelectObject (hdcBmp, hbmNewImage);
2426 imagelist_copy_images( himl, himl->hdcImage, hdcBmp, i + 1,
2427 (himl->cCurImage - i), i );
2428
2429 if (himl->hbmMask) {
2430 SelectObject (hdcBmp, hbmNewMask);
2431 imagelist_copy_images( himl, himl->hdcMask, hdcBmp, i + 1,
2432 (himl->cCurImage - i), i );
2433 }
2434 }
2435
2436 DeleteDC (hdcBmp);
2437
2438 /* delete old images and insert new ones */
2439 SelectObject (himl->hdcImage, hbmNewImage);
2440 DeleteObject (himl->hbmImage);
2441 himl->hbmImage = hbmNewImage;
2442 if (himl->hbmMask) {
2443 SelectObject (himl->hdcMask, hbmNewMask);
2444 DeleteObject (himl->hbmMask);
2445 himl->hbmMask = hbmNewMask;
2446 }
2447
2448 himl->cCurImage--;
2449 }
2450
2451 return TRUE;
2452 }
2453
2454
2455 /*************************************************************************
2456 * ImageList_Replace [COMCTL32.@]
2457 *
2458 * Replaces an image in an image list with a new image.
2459 *
2460 * PARAMS
2461 * himl [I] handle to image list
2462 * i [I] image index
2463 * hbmImage [I] handle to image bitmap
2464 * hbmMask [I] handle to mask bitmap. Can be NULL.
2465 *
2466 * RETURNS
2467 * Success: TRUE
2468 * Failure: FALSE
2469 */
2470
2471 BOOL WINAPI
2472 ImageList_Replace (HIMAGELIST himl, INT i, HBITMAP hbmImage,
2473 HBITMAP hbmMask)
2474 {
2475 HDC hdcImage;
2476 BITMAP bmp;
2477 POINT pt;
2478
2479 TRACE("%p %d %p %p\n", himl, i, hbmImage, hbmMask);
2480
2481 if (!is_valid(himl)) {
2482 ERR("Invalid image list handle!\n");
2483 return FALSE;
2484 }
2485
2486 if ((i >= himl->cMaxImage) || (i < 0)) {
2487 ERR("Invalid image index!\n");
2488 return FALSE;
2489 }
2490
2491 if (!GetObjectW(hbmImage, sizeof(BITMAP), &bmp))
2492 return FALSE;
2493
2494 hdcImage = CreateCompatibleDC (0);
2495
2496 /* Replace Image */
2497 SelectObject (hdcImage, hbmImage);
2498
2499 if (add_with_alpha( himl, hdcImage, i, 1, bmp.bmWidth, bmp.bmHeight, hbmImage, hbmMask ))
2500 goto done;
2501
2502 imagelist_point_from_index(himl, i, &pt);
2503 StretchBlt (himl->hdcImage, pt.x, pt.y, himl->cx, himl->cy,
2504 hdcImage, 0, 0, bmp.bmWidth, bmp.bmHeight, SRCCOPY);
2505
2506 if (himl->hbmMask)
2507 {
2508 HDC hdcTemp;
2509 HBITMAP hOldBitmapTemp;
2510
2511 hdcTemp = CreateCompatibleDC(0);
2512 hOldBitmapTemp = SelectObject(hdcTemp, hbmMask);
2513
2514 StretchBlt (himl->hdcMask, pt.x, pt.y, himl->cx, himl->cy,
2515 hdcTemp, 0, 0, bmp.bmWidth, bmp.bmHeight, SRCCOPY);
2516 SelectObject(hdcTemp, hOldBitmapTemp);
2517 DeleteDC(hdcTemp);
2518
2519 /* Remove the background from the image
2520 */
2521 BitBlt (himl->hdcImage, pt.x, pt.y, bmp.bmWidth, bmp.bmHeight,
2522 himl->hdcMask, pt.x, pt.y, 0x220326); /* NOTSRCAND */
2523 }
2524
2525 done:
2526 DeleteDC (hdcImage);
2527
2528 return TRUE;
2529 }
2530
2531
2532 /*************************************************************************
2533 * ImageList_ReplaceIcon [COMCTL32.@]
2534 *
2535 * Replaces an image in an image list using an icon.
2536 *
2537 * PARAMS
2538 * himl [I] handle to image list
2539 * i [I] image index
2540 * hIcon [I] handle to icon
2541 *
2542 * RETURNS
2543 * Success: index of the replaced image
2544 * Failure: -1
2545 */
2546
2547 INT WINAPI
2548 ImageList_ReplaceIcon (HIMAGELIST himl, INT nIndex, HICON hIcon)
2549 {
2550 HICON hBestFitIcon;
2551 ICONINFO ii;
2552 BITMAP bmp;
2553 BOOL ret;
2554 POINT pt;
2555
2556 TRACE("(%p %d %p)\n", himl, nIndex, hIcon);
2557
2558 if (!is_valid(himl)) {
2559 ERR("invalid image list\n");
2560 return -1;
2561 }
2562 if ((nIndex >= himl->cMaxImage) || (nIndex < -1)) {
2563 ERR("invalid image index %d / %d\n", nIndex, himl->cMaxImage);
2564 return -1;
2565 }
2566
2567 hBestFitIcon = CopyImage(
2568 hIcon, IMAGE_ICON,
2569 himl->cx, himl->cy,
2570 LR_COPYFROMRESOURCE);
2571 /* the above will fail if the icon wasn't loaded from a resource, so try
2572 * again without LR_COPYFROMRESOURCE flag */
2573 if (!hBestFitIcon)
2574 hBestFitIcon = CopyImage(
2575 hIcon, IMAGE_ICON,
2576 himl->cx, himl->cy,
2577 0);
2578 if (!hBestFitIcon)
2579 return -1;
2580
2581 if (nIndex == -1) {
2582 if (himl->cCurImage + 1 >= himl->cMaxImage)
2583 IMAGELIST_InternalExpandBitmaps(himl, 1);
2584
2585 nIndex = himl->cCurImage;
2586 himl->cCurImage++;
2587 }
2588
2589 if (himl->has_alpha && GetIconInfo (hBestFitIcon, &ii))
2590 {
2591 HDC hdcImage = CreateCompatibleDC( 0 );
2592 GetObjectW (ii.hbmMask, sizeof(BITMAP), &bmp);
2593
2594 if (!ii.hbmColor)
2595 {
2596 UINT height = bmp.bmHeight / 2;
2597 HDC hdcMask = CreateCompatibleDC( 0 );
2598 HBITMAP color = CreateBitmap( bmp.bmWidth, height, 1, 1, NULL );
2599 SelectObject( hdcImage, color );
2600 SelectObject( hdcMask, ii.hbmMask );
2601 BitBlt( hdcImage, 0, 0, bmp.bmWidth, height, hdcMask, 0, height, SRCCOPY );
2602 ret = add_with_alpha( himl, hdcImage, nIndex, 1, bmp.bmWidth, height, color, ii.hbmMask );
2603 DeleteDC( hdcMask );
2604 DeleteObject( color );
2605 }
2606 else ret = add_with_alpha( himl, hdcImage, nIndex, 1, bmp.bmWidth, bmp.bmHeight,
2607 ii.hbmColor, ii.hbmMask );
2608
2609 DeleteDC( hdcImage );
2610 DeleteObject (ii.hbmMask);
2611 if (ii.hbmColor) DeleteObject (ii.hbmColor);
2612 if (ret) goto done;
2613 }
2614
2615 imagelist_point_from_index(himl, nIndex, &pt);
2616
2617 if (himl->hbmMask)
2618 {
2619 DrawIconEx( himl->hdcImage, pt.x, pt.y, hBestFitIcon, himl->cx, himl->cy, 0, 0, DI_IMAGE );
2620 PatBlt( himl->hdcMask, pt.x, pt.y, himl->cx, himl->cy, WHITENESS );
2621 DrawIconEx( himl->hdcMask, pt.x, pt.y, hBestFitIcon, himl->cx, himl->cy, 0, 0, DI_MASK );
2622 }
2623 else
2624 {
2625 COLORREF color = himl->clrBk != CLR_NONE ? himl->clrBk : comctl32_color.clrWindow;
2626 HBRUSH brush = CreateSolidBrush( GetNearestColor( himl->hdcImage, color ));
2627
2628 SelectObject( himl->hdcImage, brush );
2629 PatBlt( himl->hdcImage, pt.x, pt.y, himl->cx, himl->cy, PATCOPY );
2630 SelectObject( himl->hdcImage, GetStockObject(BLACK_BRUSH) );
2631 DeleteObject( brush );
2632 DrawIconEx( himl->hdcImage, pt.x, pt.y, hBestFitIcon, himl->cx, himl->cy, 0, 0, DI_NORMAL );
2633 }
2634
2635 done:
2636 DestroyIcon(hBestFitIcon);
2637
2638 TRACE("Insert index = %d, himl->cCurImage = %d\n", nIndex, himl->cCurImage);
2639 return nIndex;
2640 }
2641
2642
2643 /*************************************************************************
2644 * ImageList_SetBkColor [COMCTL32.@]
2645 *
2646 * Sets the background color of an image list.
2647 *
2648 * PARAMS
2649 * himl [I] handle to image list
2650 * clrBk [I] background color
2651 *
2652 * RETURNS
2653 * Success: previous background color
2654 * Failure: CLR_NONE
2655 */
2656
2657 COLORREF WINAPI
2658 ImageList_SetBkColor (HIMAGELIST himl, COLORREF clrBk)
2659 {
2660 COLORREF clrOldBk;
2661
2662 if (!is_valid(himl))
2663 return CLR_NONE;
2664
2665 clrOldBk = himl->clrBk;
2666 himl->clrBk = clrBk;
2667 return clrOldBk;
2668 }
2669
2670
2671 /*************************************************************************
2672 * ImageList_SetDragCursorImage [COMCTL32.@]
2673 *
2674 * Combines the specified image with the current drag image
2675 *
2676 * PARAMS
2677 * himlDrag [I] handle to drag image list
2678 * iDrag [I] drag image index
2679 * dxHotspot [I] X position of the hot spot
2680 * dyHotspot [I] Y position of the hot spot
2681 *
2682 * RETURNS
2683 * Success: TRUE
2684 * Failure: FALSE
2685 *
2686 * NOTES
2687 * - The names dxHotspot, dyHotspot are misleading because they have nothing
2688 * to do with a hotspot but are only the offset of the origin of the new
2689 * image relative to the origin of the old image.
2690 *
2691 * - When this function is called and the drag image is visible, a
2692 * short flickering occurs but this matches the Win9x behavior. It is
2693 * possible to fix the flickering using code like in ImageList_DragMove.
2694 */
2695
2696 BOOL WINAPI
2697 ImageList_SetDragCursorImage (HIMAGELIST himlDrag, INT iDrag,
2698 INT dxHotspot, INT dyHotspot)
2699 {
2700 HIMAGELIST himlTemp;
2701 BOOL visible;
2702
2703 if (!is_valid(InternalDrag.himl) || !is_valid(himlDrag))
2704 return FALSE;
2705
2706 TRACE(" dxH=%d dyH=%d nX=%d nY=%d\n",
2707 dxHotspot, dyHotspot, InternalDrag.dxHotspot, InternalDrag.dyHotspot);
2708
2709 visible = InternalDrag.bShow;
2710
2711 himlTemp = ImageList_Merge (InternalDrag.himlNoCursor, 0, himlDrag, iDrag,
2712 dxHotspot, dyHotspot);
2713
2714 if (visible) {
2715 /* hide the drag image */
2716 ImageList_DragShowNolock(FALSE);
2717 }
2718 if ((InternalDrag.himl->cx != himlTemp->cx) ||
2719 (InternalDrag.himl->cy != himlTemp->cy)) {
2720 /* the size of the drag image changed, invalidate the buffer */
2721 DeleteObject(InternalDrag.hbmBg);
2722 InternalDrag.hbmBg = 0;
2723 }
2724
2725 if (InternalDrag.himl != InternalDrag.himlNoCursor)
2726 ImageList_Destroy (InternalDrag.himl);
2727 InternalDrag.himl = himlTemp;
2728
2729 if (visible) {
2730 /* show the drag image */
2731 ImageList_DragShowNolock(TRUE);
2732 }
2733
2734 return TRUE;
2735 }
2736
2737
2738 /*************************************************************************
2739 * ImageList_SetFilter [COMCTL32.@]
2740 *
2741 * Sets a filter (or does something completely different)!!???
2742 * It removes 12 Bytes from the stack (3 Parameters).
2743 *
2744 * PARAMS
2745 * himl [I] SHOULD be a handle to image list
2746 * i [I] COULD be an index?
2747 * dwFilter [I] ???
2748 *
2749 * RETURNS
2750 * Success: TRUE ???
2751 * Failure: FALSE ???
2752 *
2753 * BUGS
2754 * This is an UNDOCUMENTED function!!!!
2755 * empty stub.
2756 */
2757
2758 BOOL WINAPI
2759 ImageList_SetFilter (HIMAGELIST himl, INT i, DWORD dwFilter)
2760 {
2761 FIXME("(%p 0x%x 0x%x):empty stub!\n", himl, i, dwFilter);
2762
2763 return FALSE;
2764 }
2765
2766
2767 /*************************************************************************
2768 * ImageList_SetFlags [COMCTL32.@]
2769 *
2770 * Sets the image list flags.
2771 *
2772 * PARAMS
2773 * himl [I] Handle to image list
2774 * flags [I] Flags to set
2775 *
2776 * RETURNS
2777 * Old flags?
2778 *
2779 * BUGS
2780 * Stub.
2781 */
2782
2783 DWORD WINAPI
2784 ImageList_SetFlags(HIMAGELIST himl, DWORD flags)
2785 {
2786 FIXME("(%p %08x):empty stub\n", himl, flags);
2787 return 0;
2788 }
2789
2790
2791 /*************************************************************************
2792 * ImageList_SetIconSize [COMCTL32.@]
2793 *
2794 * Sets the image size of the bitmap and deletes all images.
2795 *
2796 * PARAMS
2797 * himl [I] handle to image list
2798 * cx [I] image width
2799 * cy [I] image height
2800 *
2801 * RETURNS
2802 * Success: TRUE
2803 * Failure: FALSE
2804 */
2805
2806 BOOL WINAPI
2807 ImageList_SetIconSize (HIMAGELIST himl, INT cx, INT cy)
2808 {
2809 INT nCount;
2810 HBITMAP hbmNew;
2811
2812 if (!is_valid(himl))
2813 return FALSE;
2814
2815 /* remove all images */
2816 himl->cMaxImage = himl->cInitial + 1;
2817 himl->cCurImage = 0;
2818 himl->cx = cx;
2819 himl->cy = cy;
2820
2821 /* initialize overlay mask indices */
2822 for (nCount = 0; nCount < MAX_OVERLAYIMAGE; nCount++)
2823 himl->nOvlIdx[nCount] = -1;
2824
2825 hbmNew = ImageList_CreateImage(himl->hdcImage, himl, himl->cMaxImage);
2826 SelectObject (himl->hdcImage, hbmNew);
2827 DeleteObject (himl->hbmImage);
2828 himl->hbmImage = hbmNew;
2829
2830 if (himl->hbmMask) {
2831 SIZE sz;
2832 imagelist_get_bitmap_size(himl, himl->cMaxImage, &sz);
2833 hbmNew = CreateBitmap (sz.cx, sz.cy, 1, 1, NULL);
2834 SelectObject (himl->hdcMask, hbmNew);
2835 DeleteObject (himl->hbmMask);
2836 himl->hbmMask = hbmNew;
2837 }
2838
2839 return TRUE;
2840 }
2841
2842
2843 /*************************************************************************
2844 * ImageList_SetImageCount [COMCTL32.@]
2845 *
2846 * Resizes an image list to the specified number of images.
2847 *
2848 * PARAMS
2849 * himl [I] handle to image list
2850 * iImageCount [I] number of images in the image list
2851 *
2852 * RETURNS
2853 * Success: TRUE
2854 * Failure: FALSE
2855 */
2856
2857 BOOL WINAPI
2858 ImageList_SetImageCount (HIMAGELIST himl, UINT iImageCount)
2859 {
2860 HDC hdcBitmap;
2861 HBITMAP hbmNewBitmap, hbmOld;
2862 INT nNewCount, nCopyCount;
2863
2864 TRACE("%p %d\n",himl,iImageCount);
2865
2866 if (!is_valid(himl))
2867 return FALSE;
2868
2869 nNewCount = iImageCount + 1;
2870 nCopyCount = min(himl->cCurImage, iImageCount);
2871
2872 hdcBitmap = CreateCompatibleDC (0);
2873
2874 hbmNewBitmap = ImageList_CreateImage(hdcBitmap, himl, nNewCount);
2875
2876 if (hbmNewBitmap != 0)
2877 {
2878 hbmOld = SelectObject (hdcBitmap, hbmNewBitmap);
2879 imagelist_copy_images( himl, himl->hdcImage, hdcBitmap, 0, nCopyCount, 0 );
2880 SelectObject (hdcBitmap, hbmOld);
2881
2882 /* FIXME: delete 'empty' image space? */
2883
2884 SelectObject (himl->hdcImage, hbmNewBitmap);
2885 DeleteObject (himl->hbmImage);
2886 himl->hbmImage = hbmNewBitmap;
2887 }
2888 else
2889 ERR("Could not create new image bitmap!\n");
2890
2891 if (himl->hbmMask)
2892 {
2893 SIZE sz;
2894 imagelist_get_bitmap_size( himl, nNewCount, &sz );
2895 hbmNewBitmap = CreateBitmap (sz.cx, sz.cy, 1, 1, NULL);
2896 if (hbmNewBitmap != 0)
2897 {
2898 hbmOld = SelectObject (hdcBitmap, hbmNewBitmap);
2899 imagelist_copy_images( himl, himl->hdcMask, hdcBitmap, 0, nCopyCount, 0 );
2900 SelectObject (hdcBitmap, hbmOld);
2901
2902 /* FIXME: delete 'empty' image space? */
2903
2904 SelectObject (himl->hdcMask, hbmNewBitmap);
2905 DeleteObject (himl->hbmMask);
2906 himl->hbmMask = hbmNewBitmap;
2907 }
2908 else
2909 ERR("Could not create new mask bitmap!\n");
2910 }
2911
2912 DeleteDC (hdcBitmap);
2913
2914 if (himl->has_alpha)
2915 {
2916 char *new_alpha = HeapReAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, himl->has_alpha, nNewCount );
2917 if (new_alpha) himl->has_alpha = new_alpha;
2918 else
2919 {
2920 HeapFree( GetProcessHeap(), 0, himl->has_alpha );
2921 himl->has_alpha = NULL;
2922 }
2923 }
2924
2925 /* Update max image count and current image count */
2926 himl->cMaxImage = nNewCount;
2927 himl->cCurImage = iImageCount;
2928
2929 return TRUE;
2930 }
2931
2932
2933 /*************************************************************************
2934 * ImageList_SetOverlayImage [COMCTL32.@]
2935 *
2936 * Assigns an overlay mask index to an existing image in an image list.
2937 *
2938 * PARAMS
2939 * himl [I] handle to image list
2940 * iImage [I] image index
2941 * iOverlay [I] overlay mask index
2942 *
2943 * RETURNS
2944 * Success: TRUE
2945 * Failure: FALSE
2946 */
2947
2948 BOOL WINAPI
2949 ImageList_SetOverlayImage (HIMAGELIST himl, INT iImage, INT iOverlay)
2950 {
2951 if (!is_valid(himl))
2952 return FALSE;
2953 if ((iOverlay < 1) || (iOverlay > MAX_OVERLAYIMAGE))
2954 return FALSE;
2955 if ((iImage!=-1) && ((iImage < 0) || (iImage > himl->cCurImage)))
2956 return FALSE;
2957 himl->nOvlIdx[iOverlay - 1] = iImage;
2958 return TRUE;
2959 }
2960
2961
2962
2963 /* helper for ImageList_Write - write bitmap to pstm
2964 * currently everything is written as 24 bit RGB, except masks
2965 */
2966 static BOOL
2967 _write_bitmap(HBITMAP hBitmap, LPSTREAM pstm)
2968 {
2969 LPBITMAPFILEHEADER bmfh;
2970 LPBITMAPINFOHEADER bmih;
2971 LPBYTE data = NULL, lpBits;
2972 BITMAP bm;
2973 INT bitCount, sizeImage, offBits, totalSize;
2974 HDC xdc;
2975 BOOL result = FALSE;
2976
2977 if (!GetObjectW(hBitmap, sizeof(BITMAP), &bm))
2978 return FALSE;
2979
2980 bitCount = bm.bmBitsPixel;
2981 sizeImage = get_dib_stride(bm.bmWidth, bitCount) * bm.bmHeight;
2982
2983 totalSize = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);
2984 if(bitCount <= 8)
2985 totalSize += (1 << bitCount) * sizeof(RGBQUAD);
2986 offBits = totalSize;
2987 totalSize += sizeImage;
2988
2989 data = Alloc(totalSize);
2990 bmfh = (LPBITMAPFILEHEADER)data;
2991 bmih = (LPBITMAPINFOHEADER)(data + sizeof(BITMAPFILEHEADER));
2992 lpBits = data + offBits;
2993
2994 /* setup BITMAPFILEHEADER */
2995 bmfh->bfType = (('M' << 8) | 'B');
2996 bmfh->bfSize = offBits;
2997 bmfh->bfReserved1 = 0;
2998 bmfh->bfReserved2 = 0;
2999 bmfh->bfOffBits = offBits;
3000
3001 /* setup BITMAPINFOHEADER */
3002 bmih->biSize = sizeof(BITMAPINFOHEADER);
3003 bmih->biWidth = bm.bmWidth;
3004 bmih->biHeight = bm.bmHeight;
3005 bmih->biPlanes = 1;
3006 bmih->biBitCount = bitCount;
3007 bmih->biCompression = BI_RGB;
3008 bmih->biSizeImage = sizeImage;
3009 bmih->biXPelsPerMeter = 0;
3010 bmih->biYPelsPerMeter = 0;
3011 bmih->biClrUsed = 0;
3012 bmih->biClrImportant = 0;
3013
3014 xdc = GetDC(0);
3015 result = GetDIBits(xdc, hBitmap, 0, bm.bmHeight, lpBits, (BITMAPINFO *)bmih, DIB_RGB_COLORS) == bm.bmHeight;
3016 ReleaseDC(0, xdc);
3017 if (!result)
3018 goto failed;
3019
3020 TRACE("width %u, height %u, planes %u, bpp %u\n",
3021 bmih->biWidth, bmih->biHeight,
3022 bmih->biPlanes, bmih->biBitCount);
3023
3024 if(FAILED(IStream_Write(pstm, data, totalSize, NULL)))
3025 goto failed;
3026
3027 result = TRUE;
3028
3029 failed:
3030 Free(data);
3031
3032 return result;
3033 }
3034
3035
3036 /*************************************************************************
3037 * ImageList_Write [COMCTL32.@]
3038 *
3039 * Writes an image list to a stream.
3040 *
3041 * PARAMS
3042 * himl [I] handle to image list
3043 * pstm [O] Pointer to a stream.
3044 *
3045 * RETURNS
3046 * Success: TRUE
3047 * Failure: FALSE
3048 *
3049 * BUGS
3050 * probably.
3051 */
3052
3053 BOOL WINAPI
3054 ImageList_Write (HIMAGELIST himl, LPSTREAM pstm)
3055 {
3056 ILHEAD ilHead;
3057 int i;
3058
3059 TRACE("%p %p\n", himl, pstm);
3060
3061 if (!is_valid(himl))
3062 return FALSE;
3063
3064 ilHead.usMagic = (('L' << 8) | 'I');
3065 ilHead.usVersion = 0x101;
3066 ilHead.cCurImage = himl->cCurImage;
3067 ilHead.cMaxImage = himl->cMaxImage;
3068 ilHead.cGrow = himl->cGrow;
3069 ilHead.cx = himl->cx;
3070 ilHead.cy = himl->cy;
3071 ilHead.bkcolor = himl->clrBk;
3072 ilHead.flags = himl->flags;
3073 for(i = 0; i < 4; i++) {
3074 ilHead.ovls[i] = himl->nOvlIdx[i];
3075 }
3076
3077 TRACE("cx %u, cy %u, flags 0x04%x, cCurImage %u, cMaxImage %u\n",
3078 ilHead.cx, ilHead.cy, ilHead.flags, ilHead.cCurImage, ilHead.cMaxImage);
3079
3080 if(FAILED(IStream_Write(pstm, &ilHead, sizeof(ILHEAD), NULL)))
3081 return FALSE;
3082
3083 /* write the bitmap */
3084 if(!_write_bitmap(himl->hbmImage, pstm))
3085 return FALSE;
3086
3087 /* write the mask if we have one */
3088 if(himl->flags & ILC_MASK) {
3089 if(!_write_bitmap(himl->hbmMask, pstm))
3090 return FALSE;
3091 }
3092
3093 return TRUE;
3094 }
3095
3096
3097 static HBITMAP ImageList_CreateImage(HDC hdc, HIMAGELIST himl, UINT count)
3098 {
3099 HBITMAP hbmNewBitmap;
3100 UINT ilc = (himl->flags & 0xFE);
3101 SIZE sz;
3102
3103 imagelist_get_bitmap_size( himl, count, &sz );
3104
3105 if ((ilc >= ILC_COLOR4 && ilc <= ILC_COLOR32) || ilc == ILC_COLOR)
3106 {
3107 char buffer[sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD)];
3108 BITMAPINFO *bmi = (BITMAPINFO *)buffer;
3109
3110 TRACE("Creating DIBSection %d x %d, %d Bits per Pixel\n",
3111 sz.cx, sz.cy, himl->uBitsPixel);
3112
3113 memset( buffer, 0, sizeof(buffer) );
3114 bmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
3115 bmi->bmiHeader.biWidth = sz.cx;
3116 bmi->bmiHeader.biHeight = sz.cy;
3117 bmi->bmiHeader.biPlanes = 1;
3118 bmi->bmiHeader.biBitCount = himl->uBitsPixel;
3119 bmi->bmiHeader.biCompression = BI_RGB;
3120
3121 if (himl->uBitsPixel <= ILC_COLOR8)
3122 {
3123 /* retrieve the default color map */
3124 HBITMAP tmp = CreateBitmap( 1, 1, 1, 1, NULL );
3125 GetDIBits( hdc, tmp, 0, 0, NULL, bmi, DIB_RGB_COLORS );
3126 DeleteObject( tmp );
3127 }
3128 hbmNewBitmap = CreateDIBSection(hdc, bmi, DIB_RGB_COLORS, NULL, 0, 0);
3129 }
3130 else /*if (ilc == ILC_COLORDDB)*/
3131 {
3132 TRACE("Creating Bitmap: %d Bits per Pixel\n", himl->uBitsPixel);
3133
3134 hbmNewBitmap = CreateBitmap (sz.cx, sz.cy, 1, himl->uBitsPixel, NULL);
3135 }
3136 TRACE("returning %p\n", hbmNewBitmap);
3137 return hbmNewBitmap;
3138 }
3139
3140 /*************************************************************************
3141 * ImageList_SetColorTable [COMCTL32.@]
3142 *
3143 * Sets the color table of an image list.
3144 *
3145 * PARAMS
3146 * himl [I] Handle to the image list.
3147 * uStartIndex [I] The first index to set.
3148 * cEntries [I] Number of entries to set.
3149 * prgb [I] New color information for color table for the image list.
3150 *
3151 * RETURNS
3152 * Success: Number of entries in the table that were set.
3153 * Failure: Zero.
3154 *
3155 * SEE
3156 * ImageList_Create(), SetDIBColorTable()
3157 */
3158
3159 UINT WINAPI
3160 ImageList_SetColorTable(HIMAGELIST himl, UINT uStartIndex, UINT cEntries, const RGBQUAD *prgb)
3161 {
3162 return SetDIBColorTable(himl->hdcImage, uStartIndex, cEntries, prgb);
3163 }
3164
3165 /*************************************************************************
3166 * ImageList_CoCreateInstance [COMCTL32.@]
3167 *
3168 * Creates a new imagelist instance and returns an interface pointer to it.
3169 *
3170 * PARAMS
3171 * rclsid [I] A reference to the CLSID (CLSID_ImageList).
3172 * punkOuter [I] Pointer to IUnknown interface for aggregation, if desired
3173 * riid [I] Identifier of the requested interface.
3174 * ppv [O] Returns the address of the pointer requested, or NULL.
3175 *
3176 * RETURNS
3177 * Success: S_OK.
3178 * Failure: Error value.
3179 */
3180 HRESULT WINAPI
3181 ImageList_CoCreateInstance (REFCLSID rclsid, const IUnknown *punkOuter, REFIID riid, void **ppv)
3182 {
3183 TRACE("(%s,%p,%s,%p)\n", debugstr_guid(rclsid), punkOuter, debugstr_guid(riid), ppv);
3184
3185 if (!IsEqualCLSID(&CLSID_ImageList, rclsid))
3186 return E_NOINTERFACE;
3187
3188 return ImageListImpl_CreateInstance(punkOuter, riid, ppv);
3189 }
3190
3191
3192 /*************************************************************************
3193 * IImageList implementation
3194 */
3195
3196 static HRESULT WINAPI ImageListImpl_QueryInterface(IImageList2 *iface,
3197 REFIID iid, void **ppv)
3198 {
3199 HIMAGELIST imgl = impl_from_IImageList2(iface);
3200
3201 TRACE("(%p,%s,%p)\n", iface, debugstr_guid(iid), ppv);
3202
3203 if (!ppv) return E_INVALIDARG;
3204
3205 if (IsEqualIID(&IID_IUnknown, iid) ||
3206 IsEqualIID(&IID_IImageList, iid) ||
3207 IsEqualIID(&IID_IImageList2, iid))
3208 {
3209 *ppv = &imgl->IImageList2_iface;
3210 }
3211 else
3212 {
3213 *ppv = NULL;
3214 return E_NOINTERFACE;
3215 }
3216
3217 IImageList2_AddRef(iface);
3218 return S_OK;
3219 }
3220
3221 static ULONG WINAPI ImageListImpl_AddRef(IImageList2 *iface)
3222 {
3223 HIMAGELIST imgl = impl_from_IImageList2(iface);
3224 ULONG ref = InterlockedIncrement(&imgl->ref);
3225
3226 TRACE("(%p) refcount=%u\n", iface, ref);
3227 return ref;
3228 }
3229
3230 static ULONG WINAPI ImageListImpl_Release(IImageList2 *iface)
3231 {
3232 HIMAGELIST This = impl_from_IImageList2(iface);
3233 ULONG ref = InterlockedDecrement(&This->ref);
3234
3235 TRACE("(%p) refcount=%u\n", iface, ref);
3236
3237 if (ref == 0)
3238 {
3239 /* delete image bitmaps */
3240 if (This->hbmImage) DeleteObject (This->hbmImage);
3241 if (This->hbmMask) DeleteObject (This->hbmMask);
3242
3243 /* delete image & mask DCs */
3244 if (This->hdcImage) DeleteDC (This->hdcImage);
3245 if (This->hdcMask) DeleteDC (This->hdcMask);
3246
3247 /* delete blending brushes */
3248 if (This->hbrBlend25) DeleteObject (This->hbrBlend25);
3249 if (This->hbrBlend50) DeleteObject (This->hbrBlend50);
3250
3251 This->IImageList2_iface.lpVtbl = NULL;
3252 HeapFree(GetProcessHeap(), 0, This->has_alpha);
3253 HeapFree(GetProcessHeap(), 0, This);
3254 }
3255
3256 return ref;
3257 }
3258
3259 static HRESULT WINAPI ImageListImpl_Add(IImageList2 *iface, HBITMAP hbmImage,
3260 HBITMAP hbmMask, int *pi)
3261 {
3262 HIMAGELIST imgl = impl_from_IImageList2(iface);
3263 int ret;
3264
3265 if (!pi)
3266 return E_FAIL;
3267
3268 ret = ImageList_Add(imgl, hbmImage, hbmMask);
3269
3270 if (ret == -1)
3271 return E_FAIL;
3272
3273 *pi = ret;
3274 return S_OK;
3275 }
3276
3277 static HRESULT WINAPI ImageListImpl_ReplaceIcon(IImageList2 *iface, int i,
3278 HICON hicon, int *pi)
3279 {
3280 HIMAGELIST imgl = impl_from_IImageList2(iface);
3281 int ret;
3282
3283 if (!pi)
3284 return E_FAIL;
3285
3286 ret = ImageList_ReplaceIcon(imgl, i, hicon);
3287
3288 if (ret == -1)
3289 return E_FAIL;
3290
3291 *pi = ret;
3292 return S_OK;
3293 }
3294
3295 static HRESULT WINAPI ImageListImpl_SetOverlayImage(IImageList2 *iface,
3296 int iImage, int iOverlay)
3297 {
3298 HIMAGELIST imgl = impl_from_IImageList2(iface);
3299 return ImageList_SetOverlayImage(imgl, iImage, iOverlay) ? S_OK : E_FAIL;
3300 }
3301
3302 static HRESULT WINAPI ImageListImpl_Replace(IImageList2 *iface, int i,
3303 HBITMAP hbmImage, HBITMAP hbmMask)
3304 {
3305 HIMAGELIST imgl = impl_from_IImageList2(iface);
3306 return ImageList_Replace(imgl, i, hbmImage, hbmMask) ? S_OK : E_FAIL;
3307 }
3308
3309 static HRESULT WINAPI ImageListImpl_AddMasked(IImageList2 *iface, HBITMAP hbmImage,
3310 COLORREF crMask, int *pi)
3311 {
3312 HIMAGELIST imgl = impl_from_IImageList2(iface);
3313 int ret;
3314
3315 if (!pi)
3316 return E_FAIL;
3317
3318 ret = ImageList_AddMasked(imgl, hbmImage, crMask);
3319
3320 if (ret == -1)
3321 return E_FAIL;
3322
3323 *pi = ret;
3324 return S_OK;
3325 }
3326
3327 static HRESULT WINAPI ImageListImpl_Draw(IImageList2 *iface,
3328 IMAGELISTDRAWPARAMS *pimldp)
3329 {
3330 HIMAGELIST imgl = impl_from_IImageList2(iface);
3331 HIMAGELIST old_himl;
3332 int ret;
3333
3334 /* As far as I can tell, Windows simply ignores the contents of pimldp->himl
3335 so we shall simulate the same */
3336 old_himl = pimldp->himl;
3337 pimldp->himl = imgl;
3338
3339 ret = ImageList_DrawIndirect(pimldp);
3340
3341 pimldp->himl = old_himl;
3342 return ret ? S_OK : E_INVALIDARG;
3343 }
3344
3345 static HRESULT WINAPI ImageListImpl_Remove(IImageList2 *iface, int i)
3346 {
3347 HIMAGELIST imgl = impl_from_IImageList2(iface);
3348 return (ImageList_Remove(imgl, i) == 0) ? E_INVALIDARG : S_OK;
3349 }
3350
3351 static HRESULT WINAPI ImageListImpl_GetIcon(IImageList2 *iface, int i, UINT flags,
3352 HICON *picon)
3353 {
3354 HIMAGELIST imgl = impl_from_IImageList2(iface);
3355 HICON hIcon;
3356
3357 if (!picon)
3358 return E_FAIL;
3359
3360 hIcon = ImageList_GetIcon(imgl, i, flags);
3361
3362 if (hIcon == NULL)
3363 return E_FAIL;
3364
3365 *picon = hIcon;
3366 return S_OK;
3367 }
3368
3369 static HRESULT WINAPI ImageListImpl_GetImageInfo(IImageList2 *iface, int i,
3370 IMAGEINFO *pImageInfo)
3371 {
3372 HIMAGELIST imgl = impl_from_IImageList2(iface);
3373 return ImageList_GetImageInfo(imgl, i, pImageInfo) ? S_OK : E_FAIL;
3374 }
3375
3376 static HRESULT WINAPI ImageListImpl_Copy(IImageList2 *iface, int dst_index,
3377 IUnknown *unk_src, int src_index, UINT flags)
3378 {
3379 HIMAGELIST imgl = impl_from_IImageList2(iface);
3380 IImageList *src = NULL;
3381 HRESULT ret;
3382
3383 if (!unk_src)
3384 return E_FAIL;
3385
3386 /* TODO: Add test for IID_ImageList2 too */
3387 if (FAILED(IUnknown_QueryInterface(unk_src, &IID_IImageList,
3388 (void **) &src)))
3389 return E_FAIL;
3390
3391 if (ImageList_Copy(imgl, dst_index, (HIMAGELIST) src, src_index, flags))
3392 ret = S_OK;
3393 else
3394 ret = E_FAIL;
3395
3396 IImageList_Release(src);
3397 return ret;
3398 }
3399
3400 static HRESULT WINAPI ImageListImpl_Merge(IImageList2 *iface, int i1,
3401 IUnknown *punk2, int i2, int dx, int dy, REFIID riid, void **ppv)
3402 {
3403 HIMAGELIST imgl = impl_from_IImageList2(iface);
3404 IImageList *iml2 = NULL;
3405 HIMAGELIST merged;
3406 HRESULT ret = E_FAIL;
3407
3408 TRACE("(%p)->(%d %p %d %d %d %s %p)\n", iface, i1, punk2, i2, dx, dy, debugstr_guid(riid), ppv);
3409
3410 /* TODO: Add test for IID_ImageList2 too */
3411 if (FAILED(IUnknown_QueryInterface(punk2, &IID_IImageList,
3412 (void **) &iml2)))
3413 return E_FAIL;
3414
3415 merged = ImageList_Merge(imgl, i1, (HIMAGELIST) iml2, i2, dx, dy);
3416
3417 /* Get the interface for the new image list */
3418 if (merged)
3419 {
3420 ret = HIMAGELIST_QueryInterface(merged, riid, ppv);
3421 ImageList_Destroy(merged);
3422 }
3423
3424 IImageList_Release(iml2);
3425 return ret;
3426 }
3427
3428 static HRESULT WINAPI ImageListImpl_Clone(IImageList2 *iface, REFIID riid, void **ppv)
3429 {
3430 HIMAGELIST imgl = impl_from_IImageList2(iface);
3431 HIMAGELIST clone;
3432 HRESULT ret = E_FAIL;
3433
3434 TRACE("(%p)->(%s %p)\n", iface, debugstr_guid(riid), ppv);
3435
3436 clone = ImageList_Duplicate(imgl);
3437
3438 /* Get the interface for the new image list */
3439 if (clone)
3440 {
3441 ret = HIMAGELIST_QueryInterface(clone, riid, ppv);
3442 ImageList_Destroy(clone);
3443 }
3444
3445 return ret;
3446 }
3447
3448 static HRESULT WINAPI ImageListImpl_GetImageRect(IImageList2 *iface, int i,
3449 RECT *prc)
3450 {
3451 HIMAGELIST imgl = impl_from_IImageList2(iface);
3452 IMAGEINFO info;
3453
3454 if (!prc)
3455 return E_FAIL;
3456
3457 if (!ImageList_GetImageInfo(imgl, i, &info))
3458 return E_FAIL;
3459
3460 return CopyRect(prc, &info.rcImage) ? S_OK : E_FAIL;
3461 }
3462
3463 static HRESULT WINAPI ImageListImpl_GetIconSize(IImageList2 *iface, int *cx,
3464 int *cy)
3465 {
3466 HIMAGELIST imgl = impl_from_IImageList2(iface);
3467 return ImageList_GetIconSize(imgl, cx, cy) ? S_OK : E_INVALIDARG;
3468 }
3469
3470 static HRESULT WINAPI ImageListImpl_SetIconSize(IImageList2 *iface, int cx,
3471 int cy)
3472 {
3473 HIMAGELIST imgl = impl_from_IImageList2(iface);
3474 return ImageList_SetIconSize(imgl, cx, cy) ? S_OK : E_FAIL;
3475 }
3476
3477 static HRESULT WINAPI ImageListImpl_GetImageCount(IImageList2 *iface, int *pi)
3478 {
3479 HIMAGELIST imgl = impl_from_IImageList2(iface);
3480 *pi = ImageList_GetImageCount(imgl);
3481 return S_OK;
3482 }
3483
3484 static HRESULT WINAPI ImageListImpl_SetImageCount(IImageList2 *iface, UINT count)
3485 {
3486 HIMAGELIST imgl = impl_from_IImageList2(iface);
3487 return ImageList_SetImageCount(imgl, count) ? S_OK : E_FAIL;
3488 }
3489
3490 static HRESULT WINAPI ImageListImpl_SetBkColor(IImageList2 *iface, COLORREF clrBk,
3491 COLORREF *pclr)
3492 {
3493 HIMAGELIST imgl = impl_from_IImageList2(iface);
3494 *pclr = ImageList_SetBkColor(imgl, clrBk);
3495 return S_OK;
3496 }
3497
3498 static HRESULT WINAPI ImageListImpl_GetBkColor(IImageList2 *iface, COLORREF *pclr)
3499 {
3500 HIMAGELIST imgl = impl_from_IImageList2(iface);
3501 *pclr = ImageList_GetBkColor(imgl);
3502 return S_OK;
3503 }
3504
3505 static HRESULT WINAPI ImageListImpl_BeginDrag(IImageList2 *iface, int iTrack,
3506 int dxHotspot, int dyHotspot)
3507 {
3508 HIMAGELIST imgl = impl_from_IImageList2(iface);
3509 return ImageList_BeginDrag(imgl, iTrack, dxHotspot, dyHotspot) ? S_OK : E_FAIL;
3510 }
3511
3512 static HRESULT WINAPI ImageListImpl_EndDrag(IImageList2 *iface)
3513 {
3514 ImageList_EndDrag();
3515 return S_OK;
3516 }
3517
3518 static HRESULT WINAPI ImageListImpl_DragEnter(IImageList2 *iface, HWND hwndLock,
3519 int x, int y)
3520 {
3521 return ImageList_DragEnter(hwndLock, x, y) ? S_OK : E_FAIL;
3522 }
3523
3524 static HRESULT WINAPI ImageListImpl_DragLeave(IImageList2 *iface, HWND hwndLock)
3525 {
3526 return ImageList_DragLeave(hwndLock) ? S_OK : E_FAIL;
3527 }
3528
3529 static HRESULT WINAPI ImageListImpl_DragMove(IImageList2 *iface, int x, int y)
3530 {
3531 return ImageList_DragMove(x, y) ? S_OK : E_FAIL;
3532 }
3533
3534 static HRESULT WINAPI ImageListImpl_SetDragCursorImage(IImageList2 *iface,
3535 IUnknown *punk, int iDrag, int dxHotspot, int dyHotspot)
3536 {
3537 IImageList *iml2 = NULL;
3538 HRESULT ret;
3539
3540 if (!punk)
3541 return E_FAIL;
3542
3543 /* TODO: Add test for IID_ImageList2 too */
3544 if (FAILED(IUnknown_QueryInterface(punk, &IID_IImageList,
3545 (void **) &iml2)))
3546 return E_FAIL;
3547
3548 ret = ImageList_SetDragCursorImage((HIMAGELIST) iml2, iDrag, dxHotspot,
3549 dyHotspot);
3550
3551 IImageList_Release(iml2);
3552
3553 return ret ? S_OK : E_FAIL;
3554 }
3555
3556 static HRESULT WINAPI ImageListImpl_DragShowNolock(IImageList2 *iface, BOOL fShow)
3557 {
3558 return ImageList_DragShowNolock(fShow) ? S_OK : E_FAIL;
3559 }
3560
3561 static HRESULT WINAPI ImageListImpl_GetDragImage(IImageList2 *iface, POINT *ppt,
3562 POINT *pptHotspot, REFIID riid, PVOID *ppv)
3563 {
3564 HRESULT ret = E_FAIL;
3565 HIMAGELIST hNew;
3566
3567 if (!ppv)
3568 return E_FAIL;
3569
3570 hNew = ImageList_GetDragImage(ppt, pptHotspot);
3571
3572 /* Get the interface for the new image list */
3573 if (hNew)
3574 {
3575 IImageList *idrag = (IImageList*)hNew;
3576
3577 ret = HIMAGELIST_QueryInterface(hNew, riid, ppv);
3578 IImageList_Release(idrag);
3579 }
3580
3581 return ret;
3582 }
3583
3584 static HRESULT WINAPI ImageListImpl_GetItemFlags(IImageList2 *iface, int i,
3585 DWORD *dwFlags)
3586 {
3587 FIXME("STUB: %p %d %p\n", iface, i, dwFlags);
3588 return E_NOTIMPL;
3589 }
3590
3591 static HRESULT WINAPI ImageListImpl_GetOverlayImage(IImageList2 *iface, int iOverlay,
3592 int *piIndex)
3593 {
3594 HIMAGELIST This = impl_from_IImageList2(iface);
3595 int i;
3596
3597 if ((iOverlay < 0) || (iOverlay > This->cCurImage))
3598 return E_FAIL;
3599
3600 for (i = 0; i < MAX_OVERLAYIMAGE; i++)
3601 {
3602 if (This->nOvlIdx[i] == iOverlay)
3603 {
3604 *piIndex = i + 1;
3605 return S_OK;
3606 }
3607 }
3608
3609 return E_FAIL;
3610 }
3611
3612 static HRESULT WINAPI ImageListImpl_Resize(IImageList2 *iface, INT cx, INT cy)
3613 {
3614 FIXME("(%p)->(%d %d): stub\n", iface, cx, cy);
3615 return E_NOTIMPL;
3616 }
3617
3618 static HRESULT WINAPI ImageListImpl_GetOriginalSize(IImageList2 *iface, INT image, DWORD flags, INT *cx, INT *cy)
3619 {
3620 FIXME("(%p)->(%d %x %p %p): stub\n", iface, image, flags, cx, cy);
3621 return E_NOTIMPL;
3622 }
3623
3624 static HRESULT WINAPI ImageListImpl_SetOriginalSize(IImageList2 *iface, INT image, INT cx, INT cy)
3625 {
3626 FIXME("(%p)->(%d %d %d): stub\n", iface, image, cx, cy);
3627 return E_NOTIMPL;
3628 }
3629
3630 static HRESULT WINAPI ImageListImpl_SetCallback(IImageList2 *iface, IUnknown *callback)
3631 {
3632 FIXME("(%p)->(%p): stub\n", iface, callback);
3633 return E_NOTIMPL;
3634 }
3635
3636 static HRESULT WINAPI ImageListImpl_GetCallback(IImageList2 *iface, REFIID riid, void **ppv)
3637 {
3638 FIXME("(%p)->(%s %p): stub\n", iface, debugstr_guid(riid), ppv);
3639 return E_NOTIMPL;
3640 }
3641
3642 static HRESULT WINAPI ImageListImpl_ForceImagePresent(IImageList2 *iface, INT image, DWORD flags)
3643 {
3644 FIXME("(%p)->(%d %x): stub\n", iface, image, flags);
3645 return E_NOTIMPL;
3646 }
3647
3648 static HRESULT WINAPI ImageListImpl_DiscardImages(IImageList2 *iface, INT first_image, INT last_image, DWORD flags)
3649 {
3650 FIXME("(%p)->(%d %d %x): stub\n", iface, first_image, last_image, flags);
3651 return E_NOTIMPL;
3652 }
3653
3654 static HRESULT WINAPI ImageListImpl_PreloadImages(IImageList2 *iface, IMAGELISTDRAWPARAMS *params)
3655 {
3656 FIXME("(%p)->(%p): stub\n", iface, params);
3657 return E_NOTIMPL;
3658 }
3659
3660 static HRESULT WINAPI ImageListImpl_GetStatistics(IImageList2 *iface, IMAGELISTSTATS *stats)
3661 {
3662 FIXME("(%p)->(%p): stub\n", iface, stats);
3663 return E_NOTIMPL;
3664 }
3665
3666 static HRESULT WINAPI ImageListImpl_Initialize(IImageList2 *iface, INT cx, INT cy, UINT flags, INT initial, INT grow)
3667 {
3668 FIXME("(%p)->(%d %d %d %d %d): stub\n", iface, cx, cy, flags, initial, grow);
3669 return E_NOTIMPL;
3670 }
3671
3672 static HRESULT WINAPI ImageListImpl_Replace2(IImageList2 *iface, INT i, HBITMAP image, HBITMAP mask, IUnknown *unk, DWORD flags)
3673 {
3674 FIXME("(%p)->(%d %p %p %p %x): stub\n", iface, i, image, mask, unk, flags);
3675 return E_NOTIMPL;
3676 }
3677
3678 static HRESULT WINAPI ImageListImpl_ReplaceFromImageList(IImageList2 *iface, INT i, IImageList *imagelist, INT src,
3679 IUnknown *unk, DWORD flags)
3680 {
3681 FIXME("(%p)->(%d %p %d %p %x): stub\n", iface, i, imagelist, src, unk, flags);
3682 return E_NOTIMPL;
3683 }
3684
3685 static const IImageList2Vtbl ImageListImpl_Vtbl = {
3686 ImageListImpl_QueryInterface,
3687 ImageListImpl_AddRef,
3688 ImageListImpl_Release,
3689 ImageListImpl_Add,
3690 ImageListImpl_ReplaceIcon,
3691 ImageListImpl_SetOverlayImage,
3692 ImageListImpl_Replace,
3693 ImageListImpl_AddMasked,
3694 ImageListImpl_Draw,
3695 ImageListImpl_Remove,
3696 ImageListImpl_GetIcon,
3697 ImageListImpl_GetImageInfo,
3698 ImageListImpl_Copy,
3699 ImageListImpl_Merge,
3700 ImageListImpl_Clone,
3701 ImageListImpl_GetImageRect,
3702 ImageListImpl_GetIconSize,
3703 ImageListImpl_SetIconSize,
3704 ImageListImpl_GetImageCount,
3705 ImageListImpl_SetImageCount,
3706 ImageListImpl_SetBkColor,
3707 ImageListImpl_GetBkColor,
3708 ImageListImpl_BeginDrag,
3709 ImageListImpl_EndDrag,
3710 ImageListImpl_DragEnter,
3711 ImageListImpl_DragLeave,
3712 ImageListImpl_DragMove,
3713 ImageListImpl_SetDragCursorImage,
3714 ImageListImpl_DragShowNolock,
3715 ImageListImpl_GetDragImage,
3716 ImageListImpl_GetItemFlags,
3717 ImageListImpl_GetOverlayImage,
3718 ImageListImpl_Resize,
3719 ImageListImpl_GetOriginalSize,
3720 ImageListImpl_SetOriginalSize,
3721 ImageListImpl_SetCallback,
3722 ImageListImpl_GetCallback,
3723 ImageListImpl_ForceImagePresent,
3724 ImageListImpl_DiscardImages,
3725 ImageListImpl_PreloadImages,
3726 ImageListImpl_GetStatistics,
3727 ImageListImpl_Initialize,
3728 ImageListImpl_Replace2,
3729 ImageListImpl_ReplaceFromImageList
3730 };
3731
3732 static BOOL is_valid(HIMAGELIST himl)
3733 {
3734 BOOL valid;
3735 __TRY
3736 {
3737 valid = himl && himl->IImageList2_iface.lpVtbl == &ImageListImpl_Vtbl;
3738 }
3739 __EXCEPT_PAGE_FAULT
3740 {
3741 valid = FALSE;
3742 }
3743 __ENDTRY
3744 return valid;
3745 }
3746
3747 /*************************************************************************
3748 * HIMAGELIST_QueryInterface [COMCTL32.@]
3749 *
3750 * Returns a pointer to an IImageList or IImageList2 object for the given
3751 * HIMAGELIST.
3752 *
3753 * PARAMS
3754 * himl [I] Image list handle.
3755 * riid [I] Identifier of the requested interface.
3756 * ppv [O] Returns the address of the pointer requested, or NULL.
3757 *
3758 * RETURNS
3759 * Success: S_OK.
3760 * Failure: Error value.
3761 */
3762 HRESULT WINAPI
3763 HIMAGELIST_QueryInterface (HIMAGELIST himl, REFIID riid, void **ppv)
3764 {
3765 TRACE("(%p,%s,%p)\n", himl, debugstr_guid(riid), ppv);
3766 return IImageList2_QueryInterface((IImageList2 *) himl, riid, ppv);
3767 }
3768
3769 static HRESULT ImageListImpl_CreateInstance(const IUnknown *pUnkOuter, REFIID iid, void** ppv)
3770 {
3771 HIMAGELIST This;
3772 HRESULT ret;
3773
3774 TRACE("(%p,%s,%p)\n", pUnkOuter, debugstr_guid(iid), ppv);
3775
3776 *ppv = NULL;
3777
3778 if (pUnkOuter) return CLASS_E_NOAGGREGATION;
3779
3780 This = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(struct _IMAGELIST));
3781 if (!This) return E_OUTOFMEMORY;
3782
3783 This->IImageList2_iface.lpVtbl = &ImageListImpl_Vtbl;
3784 This->ref = 1;
3785
3786 ret = IImageList2_QueryInterface(&This->IImageList2_iface, iid, ppv);
3787 IImageList2_Release(&This->IImageList2_iface);
3788
3789 return ret;
3790 }