[COMCTL32]
[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
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 srce_dc, 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( srce_dc, info, DIB_RGB_COLORS, &bits, 0, 0 ))) goto done;
1256 SelectObject( hdc, bmp );
1257 BitBlt( hdc, 0, 0, cx, cy, srce_dc, 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 HDC saturate_image( HIMAGELIST himl, HDC dest_dc, int dest_x, int dest_y,
1331 int src_x, int src_y, int cx, int cy, COLORREF rgbFg)
1332 {
1333 HDC hdc = NULL;
1334 HBITMAP bmp = 0;
1335 BITMAPINFO *info;
1336
1337 unsigned int *ptr;
1338 void *bits;
1339 int i;
1340
1341 /* create a dc and its device independent bitmap for doing the work,
1342 shamelessly copied from the alpha-blending function above */
1343 if (!(hdc = CreateCompatibleDC( 0 ))) return FALSE;
1344 if (!(info = HeapAlloc( GetProcessHeap(), 0, FIELD_OFFSET( BITMAPINFO, bmiColors[256] )))) goto done;
1345 info->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
1346 info->bmiHeader.biWidth = cx;
1347 info->bmiHeader.biHeight = cy;
1348 info->bmiHeader.biPlanes = 1;
1349 info->bmiHeader.biBitCount = 32;
1350 info->bmiHeader.biCompression = BI_RGB;
1351 info->bmiHeader.biSizeImage = cx * cy * 4;
1352 info->bmiHeader.biXPelsPerMeter = 0;
1353 info->bmiHeader.biYPelsPerMeter = 0;
1354 info->bmiHeader.biClrUsed = 0;
1355 info->bmiHeader.biClrImportant = 0;
1356 if (!(bmp = CreateDIBSection(himl->hdcImage, info, DIB_RGB_COLORS, &bits, 0, 0 ))) goto done;
1357
1358 /* bind both surfaces */
1359 SelectObject(hdc, bmp);
1360
1361 /* copy into our dc the section that covers just the icon we we're asked for */
1362 BitBlt(hdc, 0, 0, cx, cy, himl->hdcImage, src_x, src_y, SRCCOPY);
1363
1364 /* loop every pixel of the bitmap */
1365 for (i = 0, ptr = bits; i < cx * cy; i++, ptr++)
1366 {
1367 COLORREF orig_color = *ptr;
1368
1369 /* calculate the effective luminance using the constants from here, adapted to the human eye:
1370 <http://bobpowell.net/grayscale.aspx> */
1371 float mixed_color = (GetRValue(orig_color) * .30 +
1372 GetGValue(orig_color) * .59 +
1373 GetBValue(orig_color) * .11);
1374
1375 *ptr = RGBA(mixed_color, mixed_color, mixed_color, GetAValue(orig_color));
1376 }
1377
1378 done:
1379
1380 if (bmp)
1381 DeleteObject(bmp);
1382
1383 if (info)
1384 HeapFree(GetProcessHeap(), 0, info);
1385
1386 /* return the handle to our desaturated dc, that will substitute its original counterpart in the next calls */
1387 return hdc;
1388 }
1389
1390 /*************************************************************************
1391 * ImageList_DrawIndirect [COMCTL32.@]
1392 *
1393 * Draws an image using various parameters specified in pimldp.
1394 *
1395 * PARAMS
1396 * pimldp [I] pointer to IMAGELISTDRAWPARAMS structure.
1397 *
1398 * RETURNS
1399 * Success: TRUE
1400 * Failure: FALSE
1401 */
1402
1403 BOOL WINAPI
1404 ImageList_DrawIndirect (IMAGELISTDRAWPARAMS *pimldp)
1405 {
1406 INT cx, cy, nOvlIdx;
1407 DWORD fState, dwRop;
1408 UINT fStyle;
1409 COLORREF oldImageBk, oldImageFg;
1410 HDC hImageDC, hImageListDC, hMaskListDC;
1411 HBITMAP hImageBmp, hOldImageBmp, hBlendMaskBmp;
1412 BOOL bIsTransparent, bBlend, bResult = FALSE, bMask;
1413 HIMAGELIST himl;
1414 HBRUSH hOldBrush;
1415 POINT pt;
1416 BOOL has_alpha;
1417
1418 if (!pimldp || !(himl = pimldp->himl)) return FALSE;
1419 if (!is_valid(himl)) return FALSE;
1420 if ((pimldp->i < 0) || (pimldp->i >= himl->cCurImage)) return FALSE;
1421
1422 imagelist_point_from_index( himl, pimldp->i, &pt );
1423 pt.x += pimldp->xBitmap;
1424 pt.y += pimldp->yBitmap;
1425
1426 fState = pimldp->cbSize < sizeof(IMAGELISTDRAWPARAMS) ? ILS_NORMAL : pimldp->fState;
1427 fStyle = pimldp->fStyle & ~ILD_OVERLAYMASK;
1428 cx = (pimldp->cx == 0) ? himl->cx : pimldp->cx;
1429 cy = (pimldp->cy == 0) ? himl->cy : pimldp->cy;
1430
1431 bIsTransparent = (fStyle & ILD_TRANSPARENT);
1432 if( pimldp->rgbBk == CLR_NONE )
1433 bIsTransparent = TRUE;
1434 if( ( pimldp->rgbBk == CLR_DEFAULT ) && ( himl->clrBk == CLR_NONE ) )
1435 bIsTransparent = TRUE;
1436 bMask = (himl->flags & ILC_MASK) && (fStyle & ILD_MASK) ;
1437 bBlend = (fStyle & (ILD_BLEND25 | ILD_BLEND50) ) && !bMask;
1438
1439 TRACE("himl(%p) hbmMask(%p) iImage(%d) x(%d) y(%d) cx(%d) cy(%d)\n",
1440 himl, himl->hbmMask, pimldp->i, pimldp->x, pimldp->y, cx, cy);
1441
1442 /* we will use these DCs to access the images and masks in the ImageList */
1443 hImageListDC = himl->hdcImage;
1444 hMaskListDC = himl->hdcMask;
1445
1446 /* these will accumulate the image and mask for the image we're drawing */
1447 hImageDC = CreateCompatibleDC( pimldp->hdcDst );
1448 hImageBmp = CreateCompatibleBitmap( pimldp->hdcDst, cx, cy );
1449 hBlendMaskBmp = bBlend ? CreateBitmap(cx, cy, 1, 1, NULL) : 0;
1450
1451 /* Create a compatible DC. */
1452 if (!hImageListDC || !hImageDC || !hImageBmp ||
1453 (bBlend && !hBlendMaskBmp) || (himl->hbmMask && !hMaskListDC))
1454 goto cleanup;
1455
1456 hOldImageBmp = SelectObject(hImageDC, hImageBmp);
1457
1458 /*
1459 * To obtain a transparent look, background color should be set
1460 * to white and foreground color to black when blitting the
1461 * monochrome mask.
1462 */
1463 oldImageFg = SetTextColor( hImageDC, RGB( 0, 0, 0 ) );
1464 oldImageBk = SetBkColor( hImageDC, RGB( 0xff, 0xff, 0xff ) );
1465
1466 /*
1467 * If the ILS_SATURATE bit is enabled we should multiply the
1468 * RGB colors of the original image by the contents of rgbFg.
1469 */
1470 if (fState & ILS_SATURATE)
1471 {
1472 hImageListDC = saturate_image(himl, pimldp->hdcDst, pimldp->x, pimldp->y,
1473 pt.x, pt.y, cx, cy, pimldp->rgbFg);
1474
1475 /* shitty way of getting subroutines to blit at the right place (top left corner),
1476 as our modified imagelist only contains a single image for performance reasons */
1477 pt.x = 0;
1478 pt.y = 0;
1479 }
1480
1481 has_alpha = (himl->has_alpha && himl->has_alpha[pimldp->i]);
1482 if (!bMask && (has_alpha || (fState & ILS_ALPHA)))
1483 {
1484 COLORREF colour, blend_col = CLR_NONE;
1485 BLENDFUNCTION func;
1486
1487 if (bBlend)
1488 {
1489 blend_col = pimldp->rgbFg;
1490 if (blend_col == CLR_DEFAULT) blend_col = GetSysColor( COLOR_HIGHLIGHT );
1491 else if (blend_col == CLR_NONE) blend_col = GetTextColor( pimldp->hdcDst );
1492 }
1493
1494 func.BlendOp = AC_SRC_OVER;
1495 func.BlendFlags = 0;
1496 func.SourceConstantAlpha = (fState & ILS_ALPHA) ? pimldp->Frame : 255;
1497 func.AlphaFormat = AC_SRC_ALPHA;
1498
1499 if (bIsTransparent)
1500 {
1501 bResult = alpha_blend_image( himl, hImageListDC, pimldp->hdcDst, pimldp->x, pimldp->y,
1502 pt.x, pt.y, cx, cy, func, fStyle, blend_col );
1503 goto end;
1504 }
1505 colour = pimldp->rgbBk;
1506 if (colour == CLR_DEFAULT) colour = himl->clrBk;
1507 if (colour == CLR_NONE) colour = GetBkColor( pimldp->hdcDst );
1508
1509 hOldBrush = SelectObject (hImageDC, CreateSolidBrush (colour));
1510 PatBlt( hImageDC, 0, 0, cx, cy, PATCOPY );
1511 alpha_blend_image( himl, hImageListDC, hImageDC, 0, 0, pt.x, pt.y, cx, cy, func, fStyle, blend_col );
1512 DeleteObject (SelectObject (hImageDC, hOldBrush));
1513 bResult = BitBlt( pimldp->hdcDst, pimldp->x, pimldp->y, cx, cy, hImageDC, 0, 0, SRCCOPY );
1514 goto end;
1515 }
1516
1517 /*
1518 * Draw the initial image
1519 */
1520 if( bMask ) {
1521 if (himl->hbmMask) {
1522 hOldBrush = SelectObject (hImageDC, CreateSolidBrush (GetTextColor(pimldp->hdcDst)));
1523 PatBlt( hImageDC, 0, 0, cx, cy, PATCOPY );
1524 BitBlt(hImageDC, 0, 0, cx, cy, hMaskListDC, pt.x, pt.y, SRCPAINT);
1525 DeleteObject (SelectObject (hImageDC, hOldBrush));
1526 if( bIsTransparent )
1527 {
1528 BitBlt ( pimldp->hdcDst, pimldp->x, pimldp->y, cx, cy, hImageDC, 0, 0, SRCAND);
1529 bResult = TRUE;
1530 goto end;
1531 }
1532 } else {
1533 hOldBrush = SelectObject (hImageDC, GetStockObject(BLACK_BRUSH));
1534 PatBlt( hImageDC, 0, 0, cx, cy, PATCOPY);
1535 SelectObject(hImageDC, hOldBrush);
1536 }
1537 } else {
1538 /* blend the image with the needed solid background */
1539 COLORREF colour = RGB(0,0,0);
1540
1541 if( !bIsTransparent )
1542 {
1543 colour = pimldp->rgbBk;
1544 if( colour == CLR_DEFAULT )
1545 colour = himl->clrBk;
1546 if( colour == CLR_NONE )
1547 colour = GetBkColor(pimldp->hdcDst);
1548 }
1549
1550 hOldBrush = SelectObject (hImageDC, CreateSolidBrush (colour));
1551 PatBlt( hImageDC, 0, 0, cx, cy, PATCOPY );
1552 if (himl->hbmMask)
1553 {
1554 BitBlt( hImageDC, 0, 0, cx, cy, hMaskListDC, pt.x, pt.y, SRCAND );
1555 BitBlt( hImageDC, 0, 0, cx, cy, hImageListDC, pt.x, pt.y, SRCPAINT );
1556 }
1557 else
1558 BitBlt( hImageDC, 0, 0, cx, cy, hImageListDC, pt.x, pt.y, SRCCOPY);
1559 DeleteObject (SelectObject (hImageDC, hOldBrush));
1560 }
1561
1562 /* Time for blending, if required */
1563 if (bBlend) {
1564 HBRUSH hBlendBrush;
1565 COLORREF clrBlend = pimldp->rgbFg;
1566 HDC hBlendMaskDC = hImageListDC;
1567 HBITMAP hOldBitmap;
1568
1569 /* Create the blend Mask */
1570 hOldBitmap = SelectObject(hBlendMaskDC, hBlendMaskBmp);
1571 hBlendBrush = fStyle & ILD_BLEND50 ? himl->hbrBlend50 : himl->hbrBlend25;
1572 hOldBrush = SelectObject(hBlendMaskDC, hBlendBrush);
1573 PatBlt(hBlendMaskDC, 0, 0, cx, cy, PATCOPY);
1574 SelectObject(hBlendMaskDC, hOldBrush);
1575
1576 /* Modify the blend mask if an Image Mask exist */
1577 if(himl->hbmMask) {
1578 BitBlt(hBlendMaskDC, 0, 0, cx, cy, hMaskListDC, pt.x, pt.y, 0x220326); /* NOTSRCAND */
1579 BitBlt(hBlendMaskDC, 0, 0, cx, cy, hBlendMaskDC, 0, 0, NOTSRCCOPY);
1580 }
1581
1582 /* now apply blend to the current image given the BlendMask */
1583 if (clrBlend == CLR_DEFAULT) clrBlend = GetSysColor (COLOR_HIGHLIGHT);
1584 else if (clrBlend == CLR_NONE) clrBlend = GetTextColor (pimldp->hdcDst);
1585 hOldBrush = SelectObject (hImageDC, CreateSolidBrush(clrBlend));
1586 BitBlt (hImageDC, 0, 0, cx, cy, hBlendMaskDC, 0, 0, 0xB8074A); /* PSDPxax */
1587 DeleteObject(SelectObject(hImageDC, hOldBrush));
1588 SelectObject(hBlendMaskDC, hOldBitmap);
1589 }
1590
1591 /* Now do the overlay image, if any */
1592 nOvlIdx = (pimldp->fStyle & ILD_OVERLAYMASK) >> 8;
1593 if ( (nOvlIdx >= 1) && (nOvlIdx <= MAX_OVERLAYIMAGE)) {
1594 nOvlIdx = himl->nOvlIdx[nOvlIdx - 1];
1595 if ((nOvlIdx >= 0) && (nOvlIdx < himl->cCurImage)) {
1596 POINT ptOvl;
1597 imagelist_point_from_index( himl, nOvlIdx, &ptOvl );
1598 ptOvl.x += pimldp->xBitmap;
1599 if (himl->hbmMask && !(fStyle & ILD_IMAGE))
1600 BitBlt (hImageDC, 0, 0, cx, cy, hMaskListDC, ptOvl.x, ptOvl.y, SRCAND);
1601 BitBlt (hImageDC, 0, 0, cx, cy, hImageListDC, ptOvl.x, ptOvl.y, SRCPAINT);
1602 }
1603 }
1604
1605 if (fState & ILS_GLOW) FIXME("ILS_GLOW: unimplemented!\n");
1606 if (fState & ILS_SHADOW) FIXME("ILS_SHADOW: unimplemented!\n");
1607
1608 if (fStyle & ILD_PRESERVEALPHA) FIXME("ILD_PRESERVEALPHA: unimplemented!\n");
1609 if (fStyle & ILD_SCALE) FIXME("ILD_SCALE: unimplemented!\n");
1610 if (fStyle & ILD_DPISCALE) FIXME("ILD_DPISCALE: unimplemented!\n");
1611
1612 /* now copy the image to the screen */
1613 dwRop = SRCCOPY;
1614 if (himl->hbmMask && bIsTransparent ) {
1615 COLORREF oldDstFg = SetTextColor(pimldp->hdcDst, RGB( 0, 0, 0 ) );
1616 COLORREF oldDstBk = SetBkColor(pimldp->hdcDst, RGB( 0xff, 0xff, 0xff ));
1617 BitBlt (pimldp->hdcDst, pimldp->x, pimldp->y, cx, cy, hMaskListDC, pt.x, pt.y, SRCAND);
1618 SetBkColor(pimldp->hdcDst, oldDstBk);
1619 SetTextColor(pimldp->hdcDst, oldDstFg);
1620 dwRop = SRCPAINT;
1621 }
1622 if (fStyle & ILD_ROP) dwRop = pimldp->dwRop;
1623 BitBlt (pimldp->hdcDst, pimldp->x, pimldp->y, cx, cy, hImageDC, 0, 0, dwRop);
1624
1625 bResult = TRUE;
1626 end:
1627 /* cleanup the mess */
1628 SetBkColor(hImageDC, oldImageBk);
1629 SetTextColor(hImageDC, oldImageFg);
1630 SelectObject(hImageDC, hOldImageBmp);
1631 cleanup:
1632 DeleteObject(hBlendMaskBmp);
1633 DeleteObject(hImageBmp);
1634 DeleteDC(hImageDC);
1635
1636 return bResult;
1637 }
1638
1639
1640 /*************************************************************************
1641 * ImageList_Duplicate [COMCTL32.@]
1642 *
1643 * Duplicates an image list.
1644 *
1645 * PARAMS
1646 * himlSrc [I] source image list handle
1647 *
1648 * RETURNS
1649 * Success: Handle of duplicated image list.
1650 * Failure: NULL
1651 */
1652
1653 HIMAGELIST WINAPI
1654 ImageList_Duplicate (HIMAGELIST himlSrc)
1655 {
1656 HIMAGELIST himlDst;
1657
1658 if (!is_valid(himlSrc)) {
1659 ERR("Invalid image list handle!\n");
1660 return NULL;
1661 }
1662
1663 himlDst = ImageList_Create (himlSrc->cx, himlSrc->cy, himlSrc->flags,
1664 himlSrc->cCurImage, himlSrc->cGrow);
1665
1666 if (himlDst)
1667 {
1668 SIZE sz;
1669
1670 imagelist_get_bitmap_size(himlSrc, himlSrc->cCurImage, &sz);
1671 BitBlt (himlDst->hdcImage, 0, 0, sz.cx, sz.cy,
1672 himlSrc->hdcImage, 0, 0, SRCCOPY);
1673
1674 if (himlDst->hbmMask)
1675 BitBlt (himlDst->hdcMask, 0, 0, sz.cx, sz.cy,
1676 himlSrc->hdcMask, 0, 0, SRCCOPY);
1677
1678 himlDst->cCurImage = himlSrc->cCurImage;
1679 if (himlSrc->has_alpha && himlDst->has_alpha)
1680 memcpy( himlDst->has_alpha, himlSrc->has_alpha, himlDst->cCurImage );
1681 }
1682 return himlDst;
1683 }
1684
1685
1686 /*************************************************************************
1687 * ImageList_EndDrag [COMCTL32.@]
1688 *
1689 * Finishes a drag operation.
1690 *
1691 * PARAMS
1692 * no Parameters
1693 *
1694 * RETURNS
1695 * Success: TRUE
1696 * Failure: FALSE
1697 */
1698
1699 VOID WINAPI
1700 ImageList_EndDrag (void)
1701 {
1702 /* cleanup the InternalDrag struct */
1703 InternalDrag.hwnd = 0;
1704 if (InternalDrag.himl != InternalDrag.himlNoCursor)
1705 ImageList_Destroy (InternalDrag.himlNoCursor);
1706 ImageList_Destroy (InternalDrag.himl);
1707 InternalDrag.himlNoCursor = InternalDrag.himl = 0;
1708 InternalDrag.x= 0;
1709 InternalDrag.y= 0;
1710 InternalDrag.dxHotspot = 0;
1711 InternalDrag.dyHotspot = 0;
1712 InternalDrag.bShow = FALSE;
1713 DeleteObject(InternalDrag.hbmBg);
1714 InternalDrag.hbmBg = 0;
1715 }
1716
1717
1718 /*************************************************************************
1719 * ImageList_GetBkColor [COMCTL32.@]
1720 *
1721 * Returns the background color of an image list.
1722 *
1723 * PARAMS
1724 * himl [I] Image list handle.
1725 *
1726 * RETURNS
1727 * Success: background color
1728 * Failure: CLR_NONE
1729 */
1730
1731 COLORREF WINAPI
1732 ImageList_GetBkColor (HIMAGELIST himl)
1733 {
1734 return himl ? himl->clrBk : CLR_NONE;
1735 }
1736
1737
1738 /*************************************************************************
1739 * ImageList_GetDragImage [COMCTL32.@]
1740 *
1741 * Returns the handle to the internal drag image list.
1742 *
1743 * PARAMS
1744 * ppt [O] Pointer to the drag position. Can be NULL.
1745 * pptHotspot [O] Pointer to the position of the hot spot. Can be NULL.
1746 *
1747 * RETURNS
1748 * Success: Handle of the drag image list.
1749 * Failure: NULL.
1750 */
1751
1752 HIMAGELIST WINAPI
1753 ImageList_GetDragImage (POINT *ppt, POINT *pptHotspot)
1754 {
1755 if (is_valid(InternalDrag.himl)) {
1756 if (ppt) {
1757 ppt->x = InternalDrag.x;
1758 ppt->y = InternalDrag.y;
1759 }
1760 if (pptHotspot) {
1761 pptHotspot->x = InternalDrag.dxHotspot;
1762 pptHotspot->y = InternalDrag.dyHotspot;
1763 }
1764 return (InternalDrag.himl);
1765 }
1766
1767 return NULL;
1768 }
1769
1770
1771 /*************************************************************************
1772 * ImageList_GetFlags [COMCTL32.@]
1773 *
1774 * Gets the flags of the specified image list.
1775 *
1776 * PARAMS
1777 * himl [I] Handle to image list
1778 *
1779 * RETURNS
1780 * Image list flags.
1781 *
1782 * BUGS
1783 * Stub.
1784 */
1785
1786 DWORD WINAPI
1787 ImageList_GetFlags(HIMAGELIST himl)
1788 {
1789 TRACE("%p\n", himl);
1790
1791 return is_valid(himl) ? himl->flags : 0;
1792 }
1793
1794
1795 /*************************************************************************
1796 * ImageList_GetIcon [COMCTL32.@]
1797 *
1798 * Creates an icon from a masked image of an image list.
1799 *
1800 * PARAMS
1801 * himl [I] handle to image list
1802 * i [I] image index
1803 * flags [I] drawing style flags
1804 *
1805 * RETURNS
1806 * Success: icon handle
1807 * Failure: NULL
1808 */
1809
1810 HICON WINAPI
1811 ImageList_GetIcon (HIMAGELIST himl, INT i, UINT fStyle)
1812 {
1813 ICONINFO ii;
1814 HICON hIcon;
1815 HBITMAP hOldDstBitmap;
1816 HDC hdcDst;
1817 POINT pt;
1818
1819 TRACE("%p %d %d\n", himl, i, fStyle);
1820 if (!is_valid(himl) || (i < 0) || (i >= himl->cCurImage)) return NULL;
1821
1822 ii.fIcon = TRUE;
1823 ii.xHotspot = 0;
1824 ii.yHotspot = 0;
1825
1826 /* create colour bitmap */
1827 hdcDst = GetDC(0);
1828 ii.hbmColor = CreateCompatibleBitmap(hdcDst, himl->cx, himl->cy);
1829 ReleaseDC(0, hdcDst);
1830
1831 hdcDst = CreateCompatibleDC(0);
1832
1833 imagelist_point_from_index( himl, i, &pt );
1834
1835 /* draw mask*/
1836 ii.hbmMask = CreateBitmap (himl->cx, himl->cy, 1, 1, NULL);
1837 hOldDstBitmap = SelectObject (hdcDst, ii.hbmMask);
1838 if (himl->hbmMask) {
1839 BitBlt (hdcDst, 0, 0, himl->cx, himl->cy,
1840 himl->hdcMask, pt.x, pt.y, SRCCOPY);
1841 }
1842 else
1843 PatBlt (hdcDst, 0, 0, himl->cx, himl->cy, BLACKNESS);
1844
1845 /* draw image*/
1846 SelectObject (hdcDst, ii.hbmColor);
1847 BitBlt (hdcDst, 0, 0, himl->cx, himl->cy,
1848 himl->hdcImage, pt.x, pt.y, SRCCOPY);
1849
1850 /*
1851 * CreateIconIndirect requires us to deselect the bitmaps from
1852 * the DCs before calling
1853 */
1854 SelectObject(hdcDst, hOldDstBitmap);
1855
1856 hIcon = CreateIconIndirect (&ii);
1857
1858 DeleteObject (ii.hbmMask);
1859 DeleteObject (ii.hbmColor);
1860 DeleteDC (hdcDst);
1861
1862 return hIcon;
1863 }
1864
1865
1866 /*************************************************************************
1867 * ImageList_GetIconSize [COMCTL32.@]
1868 *
1869 * Retrieves the size of an image in an image list.
1870 *
1871 * PARAMS
1872 * himl [I] handle to image list
1873 * cx [O] pointer to the image width.
1874 * cy [O] pointer to the image height.
1875 *
1876 * RETURNS
1877 * Success: TRUE
1878 * Failure: FALSE
1879 *
1880 * NOTES
1881 * All images in an image list have the same size.
1882 */
1883
1884 BOOL WINAPI
1885 ImageList_GetIconSize (HIMAGELIST himl, INT *cx, INT *cy)
1886 {
1887 if (!is_valid(himl) || !cx || !cy)
1888 return FALSE;
1889 if ((himl->cx <= 0) || (himl->cy <= 0))
1890 return FALSE;
1891
1892 *cx = himl->cx;
1893 *cy = himl->cy;
1894
1895 return TRUE;
1896 }
1897
1898
1899 /*************************************************************************
1900 * ImageList_GetImageCount [COMCTL32.@]
1901 *
1902 * Returns the number of images in an image list.
1903 *
1904 * PARAMS
1905 * himl [I] handle to image list
1906 *
1907 * RETURNS
1908 * Success: Number of images.
1909 * Failure: 0
1910 */
1911
1912 INT WINAPI
1913 ImageList_GetImageCount (HIMAGELIST himl)
1914 {
1915 if (!is_valid(himl))
1916 return 0;
1917
1918 return himl->cCurImage;
1919 }
1920
1921
1922 /*************************************************************************
1923 * ImageList_GetImageInfo [COMCTL32.@]
1924 *
1925 * Returns information about an image in an image list.
1926 *
1927 * PARAMS
1928 * himl [I] handle to image list
1929 * i [I] image index
1930 * pImageInfo [O] pointer to the image information
1931 *
1932 * RETURNS
1933 * Success: TRUE
1934 * Failure: FALSE
1935 */
1936
1937 BOOL WINAPI
1938 ImageList_GetImageInfo (HIMAGELIST himl, INT i, IMAGEINFO *pImageInfo)
1939 {
1940 POINT pt;
1941
1942 if (!is_valid(himl) || (pImageInfo == NULL))
1943 return FALSE;
1944 if ((i < 0) || (i >= himl->cCurImage))
1945 return FALSE;
1946
1947 pImageInfo->hbmImage = himl->hbmImage;
1948 pImageInfo->hbmMask = himl->hbmMask;
1949
1950 imagelist_point_from_index( himl, i, &pt );
1951 pImageInfo->rcImage.top = pt.y;
1952 pImageInfo->rcImage.bottom = pt.y + himl->cy;
1953 pImageInfo->rcImage.left = pt.x;
1954 pImageInfo->rcImage.right = pt.x + himl->cx;
1955
1956 return TRUE;
1957 }
1958
1959
1960 /*************************************************************************
1961 * ImageList_GetImageRect [COMCTL32.@]
1962 *
1963 * Retrieves the rectangle of the specified image in an image list.
1964 *
1965 * PARAMS
1966 * himl [I] handle to image list
1967 * i [I] image index
1968 * lpRect [O] pointer to the image rectangle
1969 *
1970 * RETURNS
1971 * Success: TRUE
1972 * Failure: FALSE
1973 *
1974 * NOTES
1975 * This is an UNDOCUMENTED function!!!
1976 */
1977
1978 BOOL WINAPI
1979 ImageList_GetImageRect (HIMAGELIST himl, INT i, LPRECT lpRect)
1980 {
1981 POINT pt;
1982
1983 if (!is_valid(himl) || (lpRect == NULL))
1984 return FALSE;
1985 if ((i < 0) || (i >= himl->cCurImage))
1986 return FALSE;
1987
1988 imagelist_point_from_index( himl, i, &pt );
1989 lpRect->left = pt.x;
1990 lpRect->top = pt.y;
1991 lpRect->right = pt.x + himl->cx;
1992 lpRect->bottom = pt.y + himl->cy;
1993
1994 return TRUE;
1995 }
1996
1997
1998 /*************************************************************************
1999 * ImageList_LoadImage [COMCTL32.@]
2000 * ImageList_LoadImageA [COMCTL32.@]
2001 *
2002 * Creates an image list from a bitmap, icon or cursor.
2003 *
2004 * See ImageList_LoadImageW.
2005 */
2006
2007 HIMAGELIST WINAPI
2008 ImageList_LoadImageA (HINSTANCE hi, LPCSTR lpbmp, INT cx, INT cGrow,
2009 COLORREF clrMask, UINT uType, UINT uFlags)
2010 {
2011 HIMAGELIST himl;
2012 LPWSTR lpbmpW;
2013 DWORD len;
2014
2015 if (IS_INTRESOURCE(lpbmp))
2016 return ImageList_LoadImageW(hi, (LPCWSTR)lpbmp, cx, cGrow, clrMask,
2017 uType, uFlags);
2018
2019 len = MultiByteToWideChar(CP_ACP, 0, lpbmp, -1, NULL, 0);
2020 lpbmpW = Alloc(len * sizeof(WCHAR));
2021 MultiByteToWideChar(CP_ACP, 0, lpbmp, -1, lpbmpW, len);
2022
2023 himl = ImageList_LoadImageW(hi, lpbmpW, cx, cGrow, clrMask, uType, uFlags);
2024 Free (lpbmpW);
2025 return himl;
2026 }
2027
2028
2029 /*************************************************************************
2030 * ImageList_LoadImageW [COMCTL32.@]
2031 *
2032 * Creates an image list from a bitmap, icon or cursor.
2033 *
2034 * PARAMS
2035 * hi [I] instance handle
2036 * lpbmp [I] name or id of the image
2037 * cx [I] width of each image
2038 * cGrow [I] number of images to expand
2039 * clrMask [I] mask color
2040 * uType [I] type of image to load
2041 * uFlags [I] loading flags
2042 *
2043 * RETURNS
2044 * Success: handle to the loaded image list
2045 * Failure: NULL
2046 *
2047 * SEE
2048 * LoadImage ()
2049 */
2050
2051 HIMAGELIST WINAPI
2052 ImageList_LoadImageW (HINSTANCE hi, LPCWSTR lpbmp, INT cx, INT cGrow,
2053 COLORREF clrMask, UINT uType, UINT uFlags)
2054 {
2055 HIMAGELIST himl = NULL;
2056 HANDLE handle;
2057 INT nImageCount;
2058
2059 handle = LoadImageW (hi, lpbmp, uType, 0, 0, uFlags);
2060 if (!handle) {
2061 WARN("Couldn't load image\n");
2062 return NULL;
2063 }
2064
2065 if (uType == IMAGE_BITMAP) {
2066 DIBSECTION dib;
2067 UINT color;
2068
2069 if (GetObjectW (handle, sizeof(dib), &dib) == sizeof(BITMAP)) color = ILC_COLOR;
2070 else color = dib.dsBm.bmBitsPixel;
2071
2072 /* To match windows behavior, if cx is set to zero and
2073 the flag DI_DEFAULTSIZE is specified, cx becomes the
2074 system metric value for icons. If the flag is not specified
2075 the function sets the size to the height of the bitmap */
2076 if (cx == 0)
2077 {
2078 if (uFlags & DI_DEFAULTSIZE)
2079 cx = GetSystemMetrics (SM_CXICON);
2080 else
2081 cx = dib.dsBm.bmHeight;
2082 }
2083
2084 nImageCount = dib.dsBm.bmWidth / cx;
2085
2086 himl = ImageList_Create (cx, dib.dsBm.bmHeight, ILC_MASK | color, nImageCount, cGrow);
2087 if (!himl) {
2088 DeleteObject (handle);
2089 return NULL;
2090 }
2091 ImageList_AddMasked (himl, handle, clrMask);
2092 }
2093 else if ((uType == IMAGE_ICON) || (uType == IMAGE_CURSOR)) {
2094 ICONINFO ii;
2095 BITMAP bmp;
2096
2097 GetIconInfo (handle, &ii);
2098 GetObjectW (ii.hbmColor, sizeof(BITMAP), &bmp);
2099 himl = ImageList_Create (bmp.bmWidth, bmp.bmHeight,
2100 ILC_MASK | ILC_COLOR, 1, cGrow);
2101 if (!himl) {
2102 DeleteObject (ii.hbmColor);
2103 DeleteObject (ii.hbmMask);
2104 DeleteObject (handle);
2105 return NULL;
2106 }
2107 ImageList_Add (himl, ii.hbmColor, ii.hbmMask);
2108 DeleteObject (ii.hbmColor);
2109 DeleteObject (ii.hbmMask);
2110 }
2111
2112 DeleteObject (handle);
2113
2114 return himl;
2115 }
2116
2117
2118 /*************************************************************************
2119 * ImageList_Merge [COMCTL32.@]
2120 *
2121 * Create an image list containing a merged image from two image lists.
2122 *
2123 * PARAMS
2124 * himl1 [I] handle to first image list
2125 * i1 [I] first image index
2126 * himl2 [I] handle to second image list
2127 * i2 [I] second image index
2128 * dx [I] X offset of the second image relative to the first.
2129 * dy [I] Y offset of the second image relative to the first.
2130 *
2131 * RETURNS
2132 * Success: The newly created image list. It contains a single image
2133 * consisting of the second image merged with the first.
2134 * Failure: NULL, if either himl1 or himl2 is invalid.
2135 *
2136 * NOTES
2137 * - The returned image list should be deleted by the caller using
2138 * ImageList_Destroy() when it is no longer required.
2139 * - If either i1 or i2 is not a valid image index, they will be treated
2140 * as blank images.
2141 */
2142 HIMAGELIST WINAPI
2143 ImageList_Merge (HIMAGELIST himl1, INT i1, HIMAGELIST himl2, INT i2,
2144 INT dx, INT dy)
2145 {
2146 HIMAGELIST himlDst = NULL;
2147 INT cxDst, cyDst;
2148 INT xOff1, yOff1, xOff2, yOff2;
2149 POINT pt1, pt2;
2150 INT newFlags;
2151
2152 TRACE("(himl1=%p i1=%d himl2=%p i2=%d dx=%d dy=%d)\n", himl1, i1, himl2,
2153 i2, dx, dy);
2154
2155 if (!is_valid(himl1) || !is_valid(himl2))
2156 return NULL;
2157
2158 if (dx > 0) {
2159 cxDst = max (himl1->cx, dx + himl2->cx);
2160 xOff1 = 0;
2161 xOff2 = dx;
2162 }
2163 else if (dx < 0) {
2164 cxDst = max (himl2->cx, himl1->cx - dx);
2165 xOff1 = -dx;
2166 xOff2 = 0;
2167 }
2168 else {
2169 cxDst = max (himl1->cx, himl2->cx);
2170 xOff1 = 0;
2171 xOff2 = 0;
2172 }
2173
2174 if (dy > 0) {
2175 cyDst = max (himl1->cy, dy + himl2->cy);
2176 yOff1 = 0;
2177 yOff2 = dy;
2178 }
2179 else if (dy < 0) {
2180 cyDst = max (himl2->cy, himl1->cy - dy);
2181 yOff1 = -dy;
2182 yOff2 = 0;
2183 }
2184 else {
2185 cyDst = max (himl1->cy, himl2->cy);
2186 yOff1 = 0;
2187 yOff2 = 0;
2188 }
2189
2190 newFlags = (himl1->flags > himl2->flags ? himl1->flags : himl2->flags) & ILC_COLORDDB;
2191 if (newFlags == ILC_COLORDDB && (himl1->flags & ILC_COLORDDB) == ILC_COLOR16)
2192 newFlags = ILC_COLOR16; /* this is what native (at least v5) does, don't know why */
2193 himlDst = ImageList_Create (cxDst, cyDst, ILC_MASK | newFlags, 1, 1);
2194
2195 if (himlDst)
2196 {
2197 imagelist_point_from_index( himl1, i1, &pt1 );
2198 imagelist_point_from_index( himl2, i2, &pt2 );
2199
2200 /* copy image */
2201 BitBlt (himlDst->hdcImage, 0, 0, cxDst, cyDst, himl1->hdcImage, 0, 0, BLACKNESS);
2202 if (i1 >= 0 && i1 < himl1->cCurImage)
2203 BitBlt (himlDst->hdcImage, xOff1, yOff1, himl1->cx, himl1->cy, himl1->hdcImage, pt1.x, pt1.y, SRCCOPY);
2204 if (i2 >= 0 && i2 < himl2->cCurImage)
2205 {
2206 if (himl2->flags & ILC_MASK)
2207 {
2208 BitBlt (himlDst->hdcImage, xOff2, yOff2, himl2->cx, himl2->cy, himl2->hdcMask , pt2.x, pt2.y, SRCAND);
2209 BitBlt (himlDst->hdcImage, xOff2, yOff2, himl2->cx, himl2->cy, himl2->hdcImage, pt2.x, pt2.y, SRCPAINT);
2210 }
2211 else
2212 BitBlt (himlDst->hdcImage, xOff2, yOff2, himl2->cx, himl2->cy, himl2->hdcImage, pt2.x, pt2.y, SRCCOPY);
2213 }
2214
2215 /* copy mask */
2216 BitBlt (himlDst->hdcMask, 0, 0, cxDst, cyDst, himl1->hdcMask, 0, 0, WHITENESS);
2217 if (i1 >= 0 && i1 < himl1->cCurImage)
2218 BitBlt (himlDst->hdcMask, xOff1, yOff1, himl1->cx, himl1->cy, himl1->hdcMask, pt1.x, pt1.y, SRCCOPY);
2219 if (i2 >= 0 && i2 < himl2->cCurImage)
2220 BitBlt (himlDst->hdcMask, xOff2, yOff2, himl2->cx, himl2->cy, himl2->hdcMask, pt2.x, pt2.y, SRCAND);
2221
2222 himlDst->cCurImage = 1;
2223 }
2224
2225 return himlDst;
2226 }
2227
2228
2229 /* helper for ImageList_Read, see comments below */
2230 static void *read_bitmap(LPSTREAM pstm, BITMAPINFO *bmi)
2231 {
2232 BITMAPFILEHEADER bmfh;
2233 int bitsperpixel, palspace;
2234 void *bits;
2235
2236 if (FAILED(IStream_Read ( pstm, &bmfh, sizeof(bmfh), NULL)))
2237 return NULL;
2238
2239 if (bmfh.bfType != (('M'<<8)|'B'))
2240 return NULL;
2241
2242 if (FAILED(IStream_Read ( pstm, &bmi->bmiHeader, sizeof(bmi->bmiHeader), NULL)))
2243 return NULL;
2244
2245 if ((bmi->bmiHeader.biSize != sizeof(bmi->bmiHeader)))
2246 return NULL;
2247
2248 TRACE("width %u, height %u, planes %u, bpp %u\n",
2249 bmi->bmiHeader.biWidth, bmi->bmiHeader.biHeight,
2250 bmi->bmiHeader.biPlanes, bmi->bmiHeader.biBitCount);
2251
2252 bitsperpixel = bmi->bmiHeader.biPlanes * bmi->bmiHeader.biBitCount;
2253 if (bitsperpixel<=8)
2254 palspace = (1<<bitsperpixel)*sizeof(RGBQUAD);
2255 else
2256 palspace = 0;
2257
2258 bmi->bmiHeader.biSizeImage = get_dib_image_size( bmi );
2259
2260 /* read the palette right after the end of the bitmapinfoheader */
2261 if (palspace && FAILED(IStream_Read(pstm, bmi->bmiColors, palspace, NULL)))
2262 return NULL;
2263
2264 bits = Alloc(bmi->bmiHeader.biSizeImage);
2265 if (!bits) return NULL;
2266
2267 if (FAILED(IStream_Read(pstm, bits, bmi->bmiHeader.biSizeImage, NULL)))
2268 {
2269 Free(bits);
2270 return NULL;
2271 }
2272 return bits;
2273 }
2274
2275 /*************************************************************************
2276 * ImageList_Read [COMCTL32.@]
2277 *
2278 * Reads an image list from a stream.
2279 *
2280 * PARAMS
2281 * pstm [I] pointer to a stream
2282 *
2283 * RETURNS
2284 * Success: handle to image list
2285 * Failure: NULL
2286 *
2287 * The format is like this:
2288 * ILHEAD ilheadstruct;
2289 *
2290 * for the color image part:
2291 * BITMAPFILEHEADER bmfh;
2292 * BITMAPINFOHEADER bmih;
2293 * only if it has a palette:
2294 * RGBQUAD rgbs[nr_of_paletted_colors];
2295 *
2296 * BYTE colorbits[imagesize];
2297 *
2298 * the following only if the ILC_MASK bit is set in ILHEAD.ilFlags:
2299 * BITMAPFILEHEADER bmfh_mask;
2300 * BITMAPINFOHEADER bmih_mask;
2301 * only if it has a palette (it usually does not):
2302 * RGBQUAD rgbs[nr_of_paletted_colors];
2303 *
2304 * BYTE maskbits[imagesize];
2305 */
2306 HIMAGELIST WINAPI ImageList_Read (LPSTREAM pstm)
2307 {
2308 char image_buf[sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD) * 256];
2309 char mask_buf[sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD) * 256];
2310 BITMAPINFO *image_info = (BITMAPINFO *)image_buf;
2311 BITMAPINFO *mask_info = (BITMAPINFO *)mask_buf;
2312 void *image_bits, *mask_bits = NULL;
2313 ILHEAD ilHead;
2314 HIMAGELIST himl;
2315 unsigned int i;
2316
2317 TRACE("%p\n", pstm);
2318
2319 if (FAILED(IStream_Read (pstm, &ilHead, sizeof(ILHEAD), NULL)))
2320 return NULL;
2321 if (ilHead.usMagic != (('L' << 8) | 'I'))
2322 return NULL;
2323 if (ilHead.usVersion != 0x101) /* probably version? */
2324 return NULL;
2325
2326 TRACE("cx %u, cy %u, flags 0x%04x, cCurImage %u, cMaxImage %u\n",
2327 ilHead.cx, ilHead.cy, ilHead.flags, ilHead.cCurImage, ilHead.cMaxImage);
2328
2329 himl = ImageList_Create(ilHead.cx, ilHead.cy, ilHead.flags, ilHead.cCurImage, ilHead.cMaxImage);
2330 if (!himl)
2331 return NULL;
2332
2333 if (!(image_bits = read_bitmap(pstm, image_info)))
2334 {
2335 WARN("failed to read bitmap from stream\n");
2336 return NULL;
2337 }
2338 if (ilHead.flags & ILC_MASK)
2339 {
2340 if (!(mask_bits = read_bitmap(pstm, mask_info)))
2341 {
2342 WARN("failed to read mask bitmap from stream\n");
2343 return NULL;
2344 }
2345 }
2346 else mask_info = NULL;
2347
2348 if (himl->has_alpha && image_info->bmiHeader.biBitCount == 32)
2349 {
2350 DWORD *ptr = image_bits;
2351 BYTE *mask_ptr = mask_bits;
2352 int stride = himl->cy * image_info->bmiHeader.biWidth;
2353
2354 if (image_info->bmiHeader.biHeight > 0) /* bottom-up */
2355 {
2356 ptr += image_info->bmiHeader.biHeight * image_info->bmiHeader.biWidth - stride;
2357 mask_ptr += (image_info->bmiHeader.biHeight * image_info->bmiHeader.biWidth - stride) / 8;
2358 stride = -stride;
2359 image_info->bmiHeader.biHeight = himl->cy;
2360 }
2361 else image_info->bmiHeader.biHeight = -himl->cy;
2362
2363 for (i = 0; i < ilHead.cCurImage; i += TILE_COUNT)
2364 {
2365 add_dib_bits( himl, i, min( ilHead.cCurImage - i, TILE_COUNT ),
2366 himl->cx, himl->cy, image_info, mask_info, ptr, mask_ptr );
2367 ptr += stride;
2368 mask_ptr += stride / 8;
2369 }
2370 }
2371 else
2372 {
2373 StretchDIBits( himl->hdcImage, 0, 0, image_info->bmiHeader.biWidth, image_info->bmiHeader.biHeight,
2374 0, 0, image_info->bmiHeader.biWidth, image_info->bmiHeader.biHeight,
2375 image_bits, image_info, DIB_RGB_COLORS, SRCCOPY);
2376 if (mask_info)
2377 StretchDIBits( himl->hdcMask, 0, 0, mask_info->bmiHeader.biWidth, mask_info->bmiHeader.biHeight,
2378 0, 0, mask_info->bmiHeader.biWidth, mask_info->bmiHeader.biHeight,
2379 mask_bits, mask_info, DIB_RGB_COLORS, SRCCOPY);
2380 }
2381 Free( image_bits );
2382 Free( mask_bits );
2383
2384 himl->cCurImage = ilHead.cCurImage;
2385 himl->cMaxImage = ilHead.cMaxImage;
2386
2387 ImageList_SetBkColor(himl,ilHead.bkcolor);
2388 for (i=0;i<4;i++)
2389 ImageList_SetOverlayImage(himl,ilHead.ovls[i],i+1);
2390 return himl;
2391 }
2392
2393
2394 /*************************************************************************
2395 * ImageList_Remove [COMCTL32.@]
2396 *
2397 * Removes an image from an image list
2398 *
2399 * PARAMS
2400 * himl [I] image list handle
2401 * i [I] image index
2402 *
2403 * RETURNS
2404 * Success: TRUE
2405 * Failure: FALSE
2406 *
2407 * FIXME: as the image list storage test shows, native comctl32 simply shifts
2408 * images without creating a new bitmap.
2409 */
2410 BOOL WINAPI
2411 ImageList_Remove (HIMAGELIST himl, INT i)
2412 {
2413 HBITMAP hbmNewImage, hbmNewMask;
2414 HDC hdcBmp;
2415 SIZE sz;
2416
2417 TRACE("(himl=%p i=%d)\n", himl, i);
2418
2419 if (!is_valid(himl)) {
2420 ERR("Invalid image list handle!\n");
2421 return FALSE;
2422 }
2423
2424 if ((i < -1) || (i >= himl->cCurImage)) {
2425 TRACE("index out of range! %d\n", i);
2426 return FALSE;
2427 }
2428
2429 if (i == -1) {
2430 INT nCount;
2431
2432 /* remove all */
2433 if (himl->cCurImage == 0) {
2434 /* remove all on empty ImageList is allowed */
2435 TRACE("remove all on empty ImageList!\n");
2436 return TRUE;
2437 }
2438
2439 himl->cMaxImage = himl->cGrow;
2440 himl->cCurImage = 0;
2441 for (nCount = 0; nCount < MAX_OVERLAYIMAGE; nCount++)
2442 himl->nOvlIdx[nCount] = -1;
2443
2444 if (himl->has_alpha)
2445 {
2446 HeapFree( GetProcessHeap(), 0, himl->has_alpha );
2447 himl->has_alpha = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, himl->cMaxImage );
2448 }
2449
2450 hbmNewImage = ImageList_CreateImage(himl->hdcImage, himl, himl->cMaxImage);
2451 SelectObject (himl->hdcImage, hbmNewImage);
2452 DeleteObject (himl->hbmImage);
2453 himl->hbmImage = hbmNewImage;
2454
2455 if (himl->hbmMask) {
2456
2457 imagelist_get_bitmap_size(himl, himl->cMaxImage, &sz);
2458 hbmNewMask = CreateBitmap (sz.cx, sz.cy, 1, 1, NULL);
2459 SelectObject (himl->hdcMask, hbmNewMask);
2460 DeleteObject (himl->hbmMask);
2461 himl->hbmMask = hbmNewMask;
2462 }
2463 }
2464 else {
2465 /* delete one image */
2466 TRACE("Remove single image! %d\n", i);
2467
2468 /* create new bitmap(s) */
2469 TRACE(" - Number of images: %d / %d (Old/New)\n",
2470 himl->cCurImage, himl->cCurImage - 1);
2471
2472 hbmNewImage = ImageList_CreateImage(himl->hdcImage, himl, himl->cMaxImage);
2473
2474 imagelist_get_bitmap_size(himl, himl->cMaxImage, &sz );
2475 if (himl->hbmMask)
2476 hbmNewMask = CreateBitmap (sz.cx, sz.cy, 1, 1, NULL);
2477 else
2478 hbmNewMask = 0; /* Just to keep compiler happy! */
2479
2480 hdcBmp = CreateCompatibleDC (0);
2481
2482 /* copy all images and masks prior to the "removed" image */
2483 if (i > 0) {
2484 TRACE("Pre image copy: Copy %d images\n", i);
2485
2486 SelectObject (hdcBmp, hbmNewImage);
2487 imagelist_copy_images( himl, himl->hdcImage, hdcBmp, 0, i, 0 );
2488
2489 if (himl->hbmMask) {
2490 SelectObject (hdcBmp, hbmNewMask);
2491 imagelist_copy_images( himl, himl->hdcMask, hdcBmp, 0, i, 0 );
2492 }
2493 }
2494
2495 /* copy all images and masks behind the removed image */
2496 if (i < himl->cCurImage - 1) {
2497 TRACE("Post image copy!\n");
2498
2499 SelectObject (hdcBmp, hbmNewImage);
2500 imagelist_copy_images( himl, himl->hdcImage, hdcBmp, i + 1,
2501 (himl->cCurImage - i), i );
2502
2503 if (himl->hbmMask) {
2504 SelectObject (hdcBmp, hbmNewMask);
2505 imagelist_copy_images( himl, himl->hdcMask, hdcBmp, i + 1,
2506 (himl->cCurImage - i), i );
2507 }
2508 }
2509
2510 DeleteDC (hdcBmp);
2511
2512 /* delete old images and insert new ones */
2513 SelectObject (himl->hdcImage, hbmNewImage);
2514 DeleteObject (himl->hbmImage);
2515 himl->hbmImage = hbmNewImage;
2516 if (himl->hbmMask) {
2517 SelectObject (himl->hdcMask, hbmNewMask);
2518 DeleteObject (himl->hbmMask);
2519 himl->hbmMask = hbmNewMask;
2520 }
2521
2522 himl->cCurImage--;
2523 }
2524
2525 return TRUE;
2526 }
2527
2528
2529 /*************************************************************************
2530 * ImageList_Replace [COMCTL32.@]
2531 *
2532 * Replaces an image in an image list with a new image.
2533 *
2534 * PARAMS
2535 * himl [I] handle to image list
2536 * i [I] image index
2537 * hbmImage [I] handle to image bitmap
2538 * hbmMask [I] handle to mask bitmap. Can be NULL.
2539 *
2540 * RETURNS
2541 * Success: TRUE
2542 * Failure: FALSE
2543 */
2544
2545 BOOL WINAPI
2546 ImageList_Replace (HIMAGELIST himl, INT i, HBITMAP hbmImage,
2547 HBITMAP hbmMask)
2548 {
2549 HDC hdcImage;
2550 BITMAP bmp;
2551 POINT pt;
2552
2553 TRACE("%p %d %p %p\n", himl, i, hbmImage, hbmMask);
2554
2555 if (!is_valid(himl)) {
2556 ERR("Invalid image list handle!\n");
2557 return FALSE;
2558 }
2559
2560 if ((i >= himl->cMaxImage) || (i < 0)) {
2561 ERR("Invalid image index!\n");
2562 return FALSE;
2563 }
2564
2565 if (!GetObjectW(hbmImage, sizeof(BITMAP), &bmp))
2566 return FALSE;
2567
2568 hdcImage = CreateCompatibleDC (0);
2569
2570 /* Replace Image */
2571 SelectObject (hdcImage, hbmImage);
2572
2573 if (add_with_alpha( himl, hdcImage, i, 1, bmp.bmWidth, bmp.bmHeight, hbmImage, hbmMask ))
2574 goto done;
2575
2576 imagelist_point_from_index(himl, i, &pt);
2577 StretchBlt (himl->hdcImage, pt.x, pt.y, himl->cx, himl->cy,
2578 hdcImage, 0, 0, bmp.bmWidth, bmp.bmHeight, SRCCOPY);
2579
2580 if (himl->hbmMask)
2581 {
2582 HDC hdcTemp;
2583 HBITMAP hOldBitmapTemp;
2584
2585 hdcTemp = CreateCompatibleDC(0);
2586 hOldBitmapTemp = SelectObject(hdcTemp, hbmMask);
2587
2588 StretchBlt (himl->hdcMask, pt.x, pt.y, himl->cx, himl->cy,
2589 hdcTemp, 0, 0, bmp.bmWidth, bmp.bmHeight, SRCCOPY);
2590 SelectObject(hdcTemp, hOldBitmapTemp);
2591 DeleteDC(hdcTemp);
2592
2593 /* Remove the background from the image
2594 */
2595 BitBlt (himl->hdcImage, pt.x, pt.y, bmp.bmWidth, bmp.bmHeight,
2596 himl->hdcMask, pt.x, pt.y, 0x220326); /* NOTSRCAND */
2597 }
2598
2599 done:
2600 DeleteDC (hdcImage);
2601
2602 return TRUE;
2603 }
2604
2605
2606 /*************************************************************************
2607 * ImageList_ReplaceIcon [COMCTL32.@]
2608 *
2609 * Replaces an image in an image list using an icon.
2610 *
2611 * PARAMS
2612 * himl [I] handle to image list
2613 * i [I] image index
2614 * hIcon [I] handle to icon
2615 *
2616 * RETURNS
2617 * Success: index of the replaced image
2618 * Failure: -1
2619 */
2620
2621 INT WINAPI
2622 ImageList_ReplaceIcon (HIMAGELIST himl, INT nIndex, HICON hIcon)
2623 {
2624 HICON hBestFitIcon;
2625 ICONINFO ii;
2626 BITMAP bmp;
2627 BOOL ret;
2628 POINT pt;
2629
2630 TRACE("(%p %d %p)\n", himl, nIndex, hIcon);
2631
2632 if (!is_valid(himl)) {
2633 ERR("invalid image list\n");
2634 return -1;
2635 }
2636 if ((nIndex >= himl->cMaxImage) || (nIndex < -1)) {
2637 ERR("invalid image index %d / %d\n", nIndex, himl->cMaxImage);
2638 return -1;
2639 }
2640
2641 hBestFitIcon = CopyImage(
2642 hIcon, IMAGE_ICON,
2643 himl->cx, himl->cy,
2644 LR_COPYFROMRESOURCE);
2645 /* the above will fail if the icon wasn't loaded from a resource, so try
2646 * again without LR_COPYFROMRESOURCE flag */
2647 if (!hBestFitIcon)
2648 hBestFitIcon = CopyImage(
2649 hIcon, IMAGE_ICON,
2650 himl->cx, himl->cy,
2651 0);
2652 if (!hBestFitIcon)
2653 return -1;
2654
2655 if (nIndex == -1) {
2656 if (himl->cCurImage + 1 >= himl->cMaxImage)
2657 IMAGELIST_InternalExpandBitmaps(himl, 1);
2658
2659 nIndex = himl->cCurImage;
2660 himl->cCurImage++;
2661 }
2662
2663 if (himl->has_alpha && GetIconInfo (hBestFitIcon, &ii))
2664 {
2665 HDC hdcImage = CreateCompatibleDC( 0 );
2666 GetObjectW (ii.hbmMask, sizeof(BITMAP), &bmp);
2667
2668 if (!ii.hbmColor)
2669 {
2670 UINT height = bmp.bmHeight / 2;
2671 HDC hdcMask = CreateCompatibleDC( 0 );
2672 HBITMAP color = CreateBitmap( bmp.bmWidth, height, 1, 1, NULL );
2673 SelectObject( hdcImage, color );
2674 SelectObject( hdcMask, ii.hbmMask );
2675 BitBlt( hdcImage, 0, 0, bmp.bmWidth, height, hdcMask, 0, height, SRCCOPY );
2676 ret = add_with_alpha( himl, hdcImage, nIndex, 1, bmp.bmWidth, height, color, ii.hbmMask );
2677 DeleteDC( hdcMask );
2678 DeleteObject( color );
2679 }
2680 else ret = add_with_alpha( himl, hdcImage, nIndex, 1, bmp.bmWidth, bmp.bmHeight,
2681 ii.hbmColor, ii.hbmMask );
2682
2683 DeleteDC( hdcImage );
2684 DeleteObject (ii.hbmMask);
2685 if (ii.hbmColor) DeleteObject (ii.hbmColor);
2686 if (ret) goto done;
2687 }
2688
2689 imagelist_point_from_index(himl, nIndex, &pt);
2690
2691 if (himl->hbmMask)
2692 {
2693 DrawIconEx( himl->hdcImage, pt.x, pt.y, hBestFitIcon, himl->cx, himl->cy, 0, 0, DI_IMAGE );
2694 PatBlt( himl->hdcMask, pt.x, pt.y, himl->cx, himl->cy, WHITENESS );
2695 DrawIconEx( himl->hdcMask, pt.x, pt.y, hBestFitIcon, himl->cx, himl->cy, 0, 0, DI_MASK );
2696 }
2697 else
2698 {
2699 COLORREF color = himl->clrBk != CLR_NONE ? himl->clrBk : comctl32_color.clrWindow;
2700 HBRUSH brush = CreateSolidBrush( GetNearestColor( himl->hdcImage, color ));
2701
2702 SelectObject( himl->hdcImage, brush );
2703 PatBlt( himl->hdcImage, pt.x, pt.y, himl->cx, himl->cy, PATCOPY );
2704 SelectObject( himl->hdcImage, GetStockObject(BLACK_BRUSH) );
2705 DeleteObject( brush );
2706 DrawIconEx( himl->hdcImage, pt.x, pt.y, hBestFitIcon, himl->cx, himl->cy, 0, 0, DI_NORMAL );
2707 }
2708
2709 done:
2710 DestroyIcon(hBestFitIcon);
2711
2712 TRACE("Insert index = %d, himl->cCurImage = %d\n", nIndex, himl->cCurImage);
2713 return nIndex;
2714 }
2715
2716
2717 /*************************************************************************
2718 * ImageList_SetBkColor [COMCTL32.@]
2719 *
2720 * Sets the background color of an image list.
2721 *
2722 * PARAMS
2723 * himl [I] handle to image list
2724 * clrBk [I] background color
2725 *
2726 * RETURNS
2727 * Success: previous background color
2728 * Failure: CLR_NONE
2729 */
2730
2731 COLORREF WINAPI
2732 ImageList_SetBkColor (HIMAGELIST himl, COLORREF clrBk)
2733 {
2734 COLORREF clrOldBk;
2735
2736 if (!is_valid(himl))
2737 return CLR_NONE;
2738
2739 clrOldBk = himl->clrBk;
2740 himl->clrBk = clrBk;
2741 return clrOldBk;
2742 }
2743
2744
2745 /*************************************************************************
2746 * ImageList_SetDragCursorImage [COMCTL32.@]
2747 *
2748 * Combines the specified image with the current drag image
2749 *
2750 * PARAMS
2751 * himlDrag [I] handle to drag image list
2752 * iDrag [I] drag image index
2753 * dxHotspot [I] X position of the hot spot
2754 * dyHotspot [I] Y position of the hot spot
2755 *
2756 * RETURNS
2757 * Success: TRUE
2758 * Failure: FALSE
2759 *
2760 * NOTES
2761 * - The names dxHotspot, dyHotspot are misleading because they have nothing
2762 * to do with a hotspot but are only the offset of the origin of the new
2763 * image relative to the origin of the old image.
2764 *
2765 * - When this function is called and the drag image is visible, a
2766 * short flickering occurs but this matches the Win9x behavior. It is
2767 * possible to fix the flickering using code like in ImageList_DragMove.
2768 */
2769
2770 BOOL WINAPI
2771 ImageList_SetDragCursorImage (HIMAGELIST himlDrag, INT iDrag,
2772 INT dxHotspot, INT dyHotspot)
2773 {
2774 HIMAGELIST himlTemp;
2775 BOOL visible;
2776
2777 if (!is_valid(InternalDrag.himl) || !is_valid(himlDrag))
2778 return FALSE;
2779
2780 TRACE(" dxH=%d dyH=%d nX=%d nY=%d\n",
2781 dxHotspot, dyHotspot, InternalDrag.dxHotspot, InternalDrag.dyHotspot);
2782
2783 visible = InternalDrag.bShow;
2784
2785 himlTemp = ImageList_Merge (InternalDrag.himlNoCursor, 0, himlDrag, iDrag,
2786 dxHotspot, dyHotspot);
2787
2788 if (visible) {
2789 /* hide the drag image */
2790 ImageList_DragShowNolock(FALSE);
2791 }
2792 if ((InternalDrag.himl->cx != himlTemp->cx) ||
2793 (InternalDrag.himl->cy != himlTemp->cy)) {
2794 /* the size of the drag image changed, invalidate the buffer */
2795 DeleteObject(InternalDrag.hbmBg);
2796 InternalDrag.hbmBg = 0;
2797 }
2798
2799 if (InternalDrag.himl != InternalDrag.himlNoCursor)
2800 ImageList_Destroy (InternalDrag.himl);
2801 InternalDrag.himl = himlTemp;
2802
2803 if (visible) {
2804 /* show the drag image */
2805 ImageList_DragShowNolock(TRUE);
2806 }
2807
2808 return TRUE;
2809 }
2810
2811
2812 /*************************************************************************
2813 * ImageList_SetFilter [COMCTL32.@]
2814 *
2815 * Sets a filter (or does something completely different)!!???
2816 * It removes 12 Bytes from the stack (3 Parameters).
2817 *
2818 * PARAMS
2819 * himl [I] SHOULD be a handle to image list
2820 * i [I] COULD be an index?
2821 * dwFilter [I] ???
2822 *
2823 * RETURNS
2824 * Success: TRUE ???
2825 * Failure: FALSE ???
2826 *
2827 * BUGS
2828 * This is an UNDOCUMENTED function!!!!
2829 * empty stub.
2830 */
2831
2832 BOOL WINAPI
2833 ImageList_SetFilter (HIMAGELIST himl, INT i, DWORD dwFilter)
2834 {
2835 FIXME("(%p 0x%x 0x%x):empty stub!\n", himl, i, dwFilter);
2836
2837 return FALSE;
2838 }
2839
2840
2841 /*************************************************************************
2842 * ImageList_SetFlags [COMCTL32.@]
2843 *
2844 * Sets the image list flags.
2845 *
2846 * PARAMS
2847 * himl [I] Handle to image list
2848 * flags [I] Flags to set
2849 *
2850 * RETURNS
2851 * Old flags?
2852 *
2853 * BUGS
2854 * Stub.
2855 */
2856
2857 DWORD WINAPI
2858 ImageList_SetFlags(HIMAGELIST himl, DWORD flags)
2859 {
2860 FIXME("(%p %08x):empty stub\n", himl, flags);
2861 return 0;
2862 }
2863
2864
2865 /*************************************************************************
2866 * ImageList_SetIconSize [COMCTL32.@]
2867 *
2868 * Sets the image size of the bitmap and deletes all images.
2869 *
2870 * PARAMS
2871 * himl [I] handle to image list
2872 * cx [I] image width
2873 * cy [I] image height
2874 *
2875 * RETURNS
2876 * Success: TRUE
2877 * Failure: FALSE
2878 */
2879
2880 BOOL WINAPI
2881 ImageList_SetIconSize (HIMAGELIST himl, INT cx, INT cy)
2882 {
2883 INT nCount;
2884 HBITMAP hbmNew;
2885
2886 if (!is_valid(himl))
2887 return FALSE;
2888
2889 /* remove all images */
2890 himl->cMaxImage = himl->cInitial + 1;
2891 himl->cCurImage = 0;
2892 himl->cx = cx;
2893 himl->cy = cy;
2894
2895 /* initialize overlay mask indices */
2896 for (nCount = 0; nCount < MAX_OVERLAYIMAGE; nCount++)
2897 himl->nOvlIdx[nCount] = -1;
2898
2899 hbmNew = ImageList_CreateImage(himl->hdcImage, himl, himl->cMaxImage);
2900 SelectObject (himl->hdcImage, hbmNew);
2901 DeleteObject (himl->hbmImage);
2902 himl->hbmImage = hbmNew;
2903
2904 if (himl->hbmMask) {
2905 SIZE sz;
2906 imagelist_get_bitmap_size(himl, himl->cMaxImage, &sz);
2907 hbmNew = CreateBitmap (sz.cx, sz.cy, 1, 1, NULL);
2908 SelectObject (himl->hdcMask, hbmNew);
2909 DeleteObject (himl->hbmMask);
2910 himl->hbmMask = hbmNew;
2911 }
2912
2913 return TRUE;
2914 }
2915
2916
2917 /*************************************************************************
2918 * ImageList_SetImageCount [COMCTL32.@]
2919 *
2920 * Resizes an image list to the specified number of images.
2921 *
2922 * PARAMS
2923 * himl [I] handle to image list
2924 * iImageCount [I] number of images in the image list
2925 *
2926 * RETURNS
2927 * Success: TRUE
2928 * Failure: FALSE
2929 */
2930
2931 BOOL WINAPI
2932 ImageList_SetImageCount (HIMAGELIST himl, UINT iImageCount)
2933 {
2934 HDC hdcBitmap;
2935 HBITMAP hbmNewBitmap, hbmOld;
2936 INT nNewCount, nCopyCount;
2937
2938 TRACE("%p %d\n",himl,iImageCount);
2939
2940 if (!is_valid(himl))
2941 return FALSE;
2942
2943 nNewCount = iImageCount + 1;
2944 nCopyCount = min(himl->cCurImage, iImageCount);
2945
2946 hdcBitmap = CreateCompatibleDC (0);
2947
2948 hbmNewBitmap = ImageList_CreateImage(hdcBitmap, himl, nNewCount);
2949
2950 if (hbmNewBitmap != 0)
2951 {
2952 hbmOld = SelectObject (hdcBitmap, hbmNewBitmap);
2953 imagelist_copy_images( himl, himl->hdcImage, hdcBitmap, 0, nCopyCount, 0 );
2954 SelectObject (hdcBitmap, hbmOld);
2955
2956 /* FIXME: delete 'empty' image space? */
2957
2958 SelectObject (himl->hdcImage, hbmNewBitmap);
2959 DeleteObject (himl->hbmImage);
2960 himl->hbmImage = hbmNewBitmap;
2961 }
2962 else
2963 ERR("Could not create new image bitmap!\n");
2964
2965 if (himl->hbmMask)
2966 {
2967 SIZE sz;
2968 imagelist_get_bitmap_size( himl, nNewCount, &sz );
2969 hbmNewBitmap = CreateBitmap (sz.cx, sz.cy, 1, 1, NULL);
2970 if (hbmNewBitmap != 0)
2971 {
2972 hbmOld = SelectObject (hdcBitmap, hbmNewBitmap);
2973 imagelist_copy_images( himl, himl->hdcMask, hdcBitmap, 0, nCopyCount, 0 );
2974 SelectObject (hdcBitmap, hbmOld);
2975
2976 /* FIXME: delete 'empty' image space? */
2977
2978 SelectObject (himl->hdcMask, hbmNewBitmap);
2979 DeleteObject (himl->hbmMask);
2980 himl->hbmMask = hbmNewBitmap;
2981 }
2982 else
2983 ERR("Could not create new mask bitmap!\n");
2984 }
2985
2986 DeleteDC (hdcBitmap);
2987
2988 if (himl->has_alpha)
2989 {
2990 char *new_alpha = HeapReAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, himl->has_alpha, nNewCount );
2991 if (new_alpha) himl->has_alpha = new_alpha;
2992 else
2993 {
2994 HeapFree( GetProcessHeap(), 0, himl->has_alpha );
2995 himl->has_alpha = NULL;
2996 }
2997 }
2998
2999 /* Update max image count and current image count */
3000 himl->cMaxImage = nNewCount;
3001 himl->cCurImage = iImageCount;
3002
3003 return TRUE;
3004 }
3005
3006
3007 /*************************************************************************
3008 * ImageList_SetOverlayImage [COMCTL32.@]
3009 *
3010 * Assigns an overlay mask index to an existing image in an image list.
3011 *
3012 * PARAMS
3013 * himl [I] handle to image list
3014 * iImage [I] image index
3015 * iOverlay [I] overlay mask index
3016 *
3017 * RETURNS
3018 * Success: TRUE
3019 * Failure: FALSE
3020 */
3021
3022 BOOL WINAPI
3023 ImageList_SetOverlayImage (HIMAGELIST himl, INT iImage, INT iOverlay)
3024 {
3025 if (!is_valid(himl))
3026 return FALSE;
3027 if ((iOverlay < 1) || (iOverlay > MAX_OVERLAYIMAGE))
3028 return FALSE;
3029 if ((iImage!=-1) && ((iImage < 0) || (iImage > himl->cCurImage)))
3030 return FALSE;
3031 himl->nOvlIdx[iOverlay - 1] = iImage;
3032 return TRUE;
3033 }
3034
3035
3036
3037 /* helper for ImageList_Write - write bitmap to pstm
3038 * currently everything is written as 24 bit RGB, except masks
3039 */
3040 static BOOL
3041 _write_bitmap(HBITMAP hBitmap, LPSTREAM pstm)
3042 {
3043 LPBITMAPFILEHEADER bmfh;
3044 LPBITMAPINFOHEADER bmih;
3045 LPBYTE data = NULL, lpBits;
3046 BITMAP bm;
3047 INT bitCount, sizeImage, offBits, totalSize;
3048 HDC xdc;
3049 BOOL result = FALSE;
3050
3051 if (!GetObjectW(hBitmap, sizeof(BITMAP), &bm))
3052 return FALSE;
3053
3054 bitCount = bm.bmBitsPixel;
3055 sizeImage = get_dib_stride(bm.bmWidth, bitCount) * bm.bmHeight;
3056
3057 totalSize = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);
3058 if(bitCount <= 8)
3059 totalSize += (1 << bitCount) * sizeof(RGBQUAD);
3060 offBits = totalSize;
3061 totalSize += sizeImage;
3062
3063 data = Alloc(totalSize);
3064 bmfh = (LPBITMAPFILEHEADER)data;
3065 bmih = (LPBITMAPINFOHEADER)(data + sizeof(BITMAPFILEHEADER));
3066 lpBits = data + offBits;
3067
3068 /* setup BITMAPFILEHEADER */
3069 bmfh->bfType = (('M' << 8) | 'B');
3070 bmfh->bfSize = offBits;
3071 bmfh->bfReserved1 = 0;
3072 bmfh->bfReserved2 = 0;
3073 bmfh->bfOffBits = offBits;
3074
3075 /* setup BITMAPINFOHEADER */
3076 bmih->biSize = sizeof(BITMAPINFOHEADER);
3077 bmih->biWidth = bm.bmWidth;
3078 bmih->biHeight = bm.bmHeight;
3079 bmih->biPlanes = 1;
3080 bmih->biBitCount = bitCount;
3081 bmih->biCompression = BI_RGB;
3082 bmih->biSizeImage = sizeImage;
3083 bmih->biXPelsPerMeter = 0;
3084 bmih->biYPelsPerMeter = 0;
3085 bmih->biClrUsed = 0;
3086 bmih->biClrImportant = 0;
3087
3088 xdc = GetDC(0);
3089 result = GetDIBits(xdc, hBitmap, 0, bm.bmHeight, lpBits, (BITMAPINFO *)bmih, DIB_RGB_COLORS) == bm.bmHeight;
3090 ReleaseDC(0, xdc);
3091 if (!result)
3092 goto failed;
3093
3094 TRACE("width %u, height %u, planes %u, bpp %u\n",
3095 bmih->biWidth, bmih->biHeight,
3096 bmih->biPlanes, bmih->biBitCount);
3097
3098 if(FAILED(IStream_Write(pstm, data, totalSize, NULL)))
3099 goto failed;
3100
3101 result = TRUE;
3102
3103 failed:
3104 Free(data);
3105
3106 return result;
3107 }
3108
3109
3110 /*************************************************************************
3111 * ImageList_Write [COMCTL32.@]
3112 *
3113 * Writes an image list to a stream.
3114 *
3115 * PARAMS
3116 * himl [I] handle to image list
3117 * pstm [O] Pointer to a stream.
3118 *
3119 * RETURNS
3120 * Success: TRUE
3121 * Failure: FALSE
3122 *
3123 * BUGS
3124 * probably.
3125 */
3126
3127 BOOL WINAPI
3128 ImageList_Write (HIMAGELIST himl, LPSTREAM pstm)
3129 {
3130 ILHEAD ilHead;
3131 int i;
3132
3133 TRACE("%p %p\n", himl, pstm);
3134
3135 if (!is_valid(himl))
3136 return FALSE;
3137
3138 ilHead.usMagic = (('L' << 8) | 'I');
3139 ilHead.usVersion = 0x101;
3140 ilHead.cCurImage = himl->cCurImage;
3141 ilHead.cMaxImage = himl->cMaxImage;
3142 ilHead.cGrow = himl->cGrow;
3143 ilHead.cx = himl->cx;
3144 ilHead.cy = himl->cy;
3145 ilHead.bkcolor = himl->clrBk;
3146 ilHead.flags = himl->flags;
3147 for(i = 0; i < 4; i++) {
3148 ilHead.ovls[i] = himl->nOvlIdx[i];
3149 }
3150
3151 TRACE("cx %u, cy %u, flags 0x04%x, cCurImage %u, cMaxImage %u\n",
3152 ilHead.cx, ilHead.cy, ilHead.flags, ilHead.cCurImage, ilHead.cMaxImage);
3153
3154 if(FAILED(IStream_Write(pstm, &ilHead, sizeof(ILHEAD), NULL)))
3155 return FALSE;
3156
3157 /* write the bitmap */
3158 if(!_write_bitmap(himl->hbmImage, pstm))
3159 return FALSE;
3160
3161 /* write the mask if we have one */
3162 if(himl->flags & ILC_MASK) {
3163 if(!_write_bitmap(himl->hbmMask, pstm))
3164 return FALSE;
3165 }
3166
3167 return TRUE;
3168 }
3169
3170
3171 static HBITMAP ImageList_CreateImage(HDC hdc, HIMAGELIST himl, UINT count)
3172 {
3173 HBITMAP hbmNewBitmap;
3174 UINT ilc = (himl->flags & 0xFE);
3175 SIZE sz;
3176
3177 imagelist_get_bitmap_size( himl, count, &sz );
3178
3179 if ((ilc >= ILC_COLOR4 && ilc <= ILC_COLOR32) || ilc == ILC_COLOR)
3180 {
3181 char buffer[sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD)];
3182 BITMAPINFO *bmi = (BITMAPINFO *)buffer;
3183
3184 TRACE("Creating DIBSection %d x %d, %d Bits per Pixel\n",
3185 sz.cx, sz.cy, himl->uBitsPixel);
3186
3187 memset( buffer, 0, sizeof(buffer) );
3188 bmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
3189 bmi->bmiHeader.biWidth = sz.cx;
3190 bmi->bmiHeader.biHeight = sz.cy;
3191 bmi->bmiHeader.biPlanes = 1;
3192 bmi->bmiHeader.biBitCount = himl->uBitsPixel;
3193 bmi->bmiHeader.biCompression = BI_RGB;
3194
3195 if (himl->uBitsPixel <= ILC_COLOR8)
3196 {
3197 /* retrieve the default color map */
3198 HBITMAP tmp = CreateBitmap( 1, 1, 1, 1, NULL );
3199 GetDIBits( hdc, tmp, 0, 0, NULL, bmi, DIB_RGB_COLORS );
3200 DeleteObject( tmp );
3201 }
3202 hbmNewBitmap = CreateDIBSection(hdc, bmi, DIB_RGB_COLORS, NULL, 0, 0);
3203 }
3204 else /*if (ilc == ILC_COLORDDB)*/
3205 {
3206 TRACE("Creating Bitmap: %d Bits per Pixel\n", himl->uBitsPixel);
3207
3208 hbmNewBitmap = CreateBitmap (sz.cx, sz.cy, 1, himl->uBitsPixel, NULL);
3209 }
3210 TRACE("returning %p\n", hbmNewBitmap);
3211 return hbmNewBitmap;
3212 }
3213
3214 /*************************************************************************
3215 * ImageList_SetColorTable [COMCTL32.@]
3216 *
3217 * Sets the color table of an image list.
3218 *
3219 * PARAMS
3220 * himl [I] Handle to the image list.
3221 * uStartIndex [I] The first index to set.
3222 * cEntries [I] Number of entries to set.
3223 * prgb [I] New color information for color table for the image list.
3224 *
3225 * RETURNS
3226 * Success: Number of entries in the table that were set.
3227 * Failure: Zero.
3228 *
3229 * SEE
3230 * ImageList_Create(), SetDIBColorTable()
3231 */
3232
3233 UINT WINAPI
3234 ImageList_SetColorTable(HIMAGELIST himl, UINT uStartIndex, UINT cEntries, const RGBQUAD *prgb)
3235 {
3236 return SetDIBColorTable(himl->hdcImage, uStartIndex, cEntries, prgb);
3237 }
3238
3239 /*************************************************************************
3240 * ImageList_CoCreateInstance [COMCTL32.@]
3241 *
3242 * Creates a new imagelist instance and returns an interface pointer to it.
3243 *
3244 * PARAMS
3245 * rclsid [I] A reference to the CLSID (CLSID_ImageList).
3246 * punkOuter [I] Pointer to IUnknown interface for aggregation, if desired
3247 * riid [I] Identifier of the requested interface.
3248 * ppv [O] Returns the address of the pointer requested, or NULL.
3249 *
3250 * RETURNS
3251 * Success: S_OK.
3252 * Failure: Error value.
3253 */
3254 HRESULT WINAPI
3255 ImageList_CoCreateInstance (REFCLSID rclsid, const IUnknown *punkOuter, REFIID riid, void **ppv)
3256 {
3257 TRACE("(%s,%p,%s,%p)\n", debugstr_guid(rclsid), punkOuter, debugstr_guid(riid), ppv);
3258
3259 if (!IsEqualCLSID(&CLSID_ImageList, rclsid))
3260 return E_NOINTERFACE;
3261
3262 return ImageListImpl_CreateInstance(punkOuter, riid, ppv);
3263 }
3264
3265
3266 /*************************************************************************
3267 * IImageList implementation
3268 */
3269
3270 static HRESULT WINAPI ImageListImpl_QueryInterface(IImageList2 *iface,
3271 REFIID iid, void **ppv)
3272 {
3273 HIMAGELIST imgl = impl_from_IImageList2(iface);
3274
3275 TRACE("(%p,%s,%p)\n", iface, debugstr_guid(iid), ppv);
3276
3277 if (!ppv) return E_INVALIDARG;
3278
3279 if (IsEqualIID(&IID_IUnknown, iid) ||
3280 IsEqualIID(&IID_IImageList, iid) ||
3281 IsEqualIID(&IID_IImageList2, iid))
3282 {
3283 *ppv = &imgl->IImageList2_iface;
3284 }
3285 else
3286 {
3287 *ppv = NULL;
3288 return E_NOINTERFACE;
3289 }
3290
3291 IImageList2_AddRef(iface);
3292 return S_OK;
3293 }
3294
3295 static ULONG WINAPI ImageListImpl_AddRef(IImageList2 *iface)
3296 {
3297 HIMAGELIST imgl = impl_from_IImageList2(iface);
3298 ULONG ref = InterlockedIncrement(&imgl->ref);
3299
3300 TRACE("(%p) refcount=%u\n", iface, ref);
3301 return ref;
3302 }
3303
3304 static ULONG WINAPI ImageListImpl_Release(IImageList2 *iface)
3305 {
3306 HIMAGELIST This = impl_from_IImageList2(iface);
3307 ULONG ref = InterlockedDecrement(&This->ref);
3308
3309 TRACE("(%p) refcount=%u\n", iface, ref);
3310
3311 if (ref == 0)
3312 {
3313 /* delete image bitmaps */
3314 if (This->hbmImage) DeleteObject (This->hbmImage);
3315 if (This->hbmMask) DeleteObject (This->hbmMask);
3316
3317 /* delete image & mask DCs */
3318 if (This->hdcImage) DeleteDC (This->hdcImage);
3319 if (This->hdcMask) DeleteDC (This->hdcMask);
3320
3321 /* delete blending brushes */
3322 if (This->hbrBlend25) DeleteObject (This->hbrBlend25);
3323 if (This->hbrBlend50) DeleteObject (This->hbrBlend50);
3324
3325 This->IImageList2_iface.lpVtbl = NULL;
3326 HeapFree(GetProcessHeap(), 0, This->has_alpha);
3327 HeapFree(GetProcessHeap(), 0, This);
3328 }
3329
3330 return ref;
3331 }
3332
3333 static HRESULT WINAPI ImageListImpl_Add(IImageList2 *iface, HBITMAP hbmImage,
3334 HBITMAP hbmMask, int *pi)
3335 {
3336 HIMAGELIST imgl = impl_from_IImageList2(iface);
3337 int ret;
3338
3339 if (!pi)
3340 return E_FAIL;
3341
3342 ret = ImageList_Add(imgl, hbmImage, hbmMask);
3343
3344 if (ret == -1)
3345 return E_FAIL;
3346
3347 *pi = ret;
3348 return S_OK;
3349 }
3350
3351 static HRESULT WINAPI ImageListImpl_ReplaceIcon(IImageList2 *iface, int i,
3352 HICON hicon, int *pi)
3353 {
3354 HIMAGELIST imgl = impl_from_IImageList2(iface);
3355 int ret;
3356
3357 if (!pi)
3358 return E_FAIL;
3359
3360 ret = ImageList_ReplaceIcon(imgl, i, hicon);
3361
3362 if (ret == -1)
3363 return E_FAIL;
3364
3365 *pi = ret;
3366 return S_OK;
3367 }
3368
3369 static HRESULT WINAPI ImageListImpl_SetOverlayImage(IImageList2 *iface,
3370 int iImage, int iOverlay)
3371 {
3372 HIMAGELIST imgl = impl_from_IImageList2(iface);
3373 return ImageList_SetOverlayImage(imgl, iImage, iOverlay) ? S_OK : E_FAIL;
3374 }
3375
3376 static HRESULT WINAPI ImageListImpl_Replace(IImageList2 *iface, int i,
3377 HBITMAP hbmImage, HBITMAP hbmMask)
3378 {
3379 HIMAGELIST imgl = impl_from_IImageList2(iface);
3380 return ImageList_Replace(imgl, i, hbmImage, hbmMask) ? S_OK : E_FAIL;
3381 }
3382
3383 static HRESULT WINAPI ImageListImpl_AddMasked(IImageList2 *iface, HBITMAP hbmImage,
3384 COLORREF crMask, int *pi)
3385 {
3386 HIMAGELIST imgl = impl_from_IImageList2(iface);
3387 int ret;
3388
3389 if (!pi)
3390 return E_FAIL;
3391
3392 ret = ImageList_AddMasked(imgl, hbmImage, crMask);
3393
3394 if (ret == -1)
3395 return E_FAIL;
3396
3397 *pi = ret;
3398 return S_OK;
3399 }
3400
3401 static HRESULT WINAPI ImageListImpl_Draw(IImageList2 *iface,
3402 IMAGELISTDRAWPARAMS *pimldp)
3403 {
3404 HIMAGELIST imgl = impl_from_IImageList2(iface);
3405 HIMAGELIST old_himl;
3406 int ret;
3407
3408 /* As far as I can tell, Windows simply ignores the contents of pimldp->himl
3409 so we shall simulate the same */
3410 old_himl = pimldp->himl;
3411 pimldp->himl = imgl;
3412
3413 ret = ImageList_DrawIndirect(pimldp);
3414
3415 pimldp->himl = old_himl;
3416 return ret ? S_OK : E_INVALIDARG;
3417 }
3418
3419 static HRESULT WINAPI ImageListImpl_Remove(IImageList2 *iface, int i)
3420 {
3421 HIMAGELIST imgl = impl_from_IImageList2(iface);
3422 return (ImageList_Remove(imgl, i) == 0) ? E_INVALIDARG : S_OK;
3423 }
3424
3425 static HRESULT WINAPI ImageListImpl_GetIcon(IImageList2 *iface, int i, UINT flags,
3426 HICON *picon)
3427 {
3428 HIMAGELIST imgl = impl_from_IImageList2(iface);
3429 HICON hIcon;
3430
3431 if (!picon)
3432 return E_FAIL;
3433
3434 hIcon = ImageList_GetIcon(imgl, i, flags);
3435
3436 if (hIcon == NULL)
3437 return E_FAIL;
3438
3439 *picon = hIcon;
3440 return S_OK;
3441 }
3442
3443 static HRESULT WINAPI ImageListImpl_GetImageInfo(IImageList2 *iface, int i,
3444 IMAGEINFO *pImageInfo)
3445 {
3446 HIMAGELIST imgl = impl_from_IImageList2(iface);
3447 return ImageList_GetImageInfo(imgl, i, pImageInfo) ? S_OK : E_FAIL;
3448 }
3449
3450 static HRESULT WINAPI ImageListImpl_Copy(IImageList2 *iface, int dst_index,
3451 IUnknown *unk_src, int src_index, UINT flags)
3452 {
3453 HIMAGELIST imgl = impl_from_IImageList2(iface);
3454 IImageList *src = NULL;
3455 HRESULT ret;
3456
3457 if (!unk_src)
3458 return E_FAIL;
3459
3460 /* TODO: Add test for IID_ImageList2 too */
3461 if (FAILED(IUnknown_QueryInterface(unk_src, &IID_IImageList,
3462 (void **) &src)))
3463 return E_FAIL;
3464
3465 if (ImageList_Copy(imgl, dst_index, (HIMAGELIST) src, src_index, flags))
3466 ret = S_OK;
3467 else
3468 ret = E_FAIL;
3469
3470 IImageList_Release(src);
3471 return ret;
3472 }
3473
3474 static HRESULT WINAPI ImageListImpl_Merge(IImageList2 *iface, int i1,
3475 IUnknown *punk2, int i2, int dx, int dy, REFIID riid, void **ppv)
3476 {
3477 HIMAGELIST imgl = impl_from_IImageList2(iface);
3478 IImageList *iml2 = NULL;
3479 HIMAGELIST merged;
3480 HRESULT ret = E_FAIL;
3481
3482 TRACE("(%p)->(%d %p %d %d %d %s %p)\n", iface, i1, punk2, i2, dx, dy, debugstr_guid(riid), ppv);
3483
3484 /* TODO: Add test for IID_ImageList2 too */
3485 if (FAILED(IUnknown_QueryInterface(punk2, &IID_IImageList,
3486 (void **) &iml2)))
3487 return E_FAIL;
3488
3489 merged = ImageList_Merge(imgl, i1, (HIMAGELIST) iml2, i2, dx, dy);
3490
3491 /* Get the interface for the new image list */
3492 if (merged)
3493 {
3494 ret = HIMAGELIST_QueryInterface(merged, riid, ppv);
3495 ImageList_Destroy(merged);
3496 }
3497
3498 IImageList_Release(iml2);
3499 return ret;
3500 }
3501
3502 static HRESULT WINAPI ImageListImpl_Clone(IImageList2 *iface, REFIID riid, void **ppv)
3503 {
3504 HIMAGELIST imgl = impl_from_IImageList2(iface);
3505 HIMAGELIST clone;
3506 HRESULT ret = E_FAIL;
3507
3508 TRACE("(%p)->(%s %p)\n", iface, debugstr_guid(riid), ppv);
3509
3510 clone = ImageList_Duplicate(imgl);
3511
3512 /* Get the interface for the new image list */
3513 if (clone)
3514 {
3515 ret = HIMAGELIST_QueryInterface(clone, riid, ppv);
3516 ImageList_Destroy(clone);
3517 }
3518
3519 return ret;
3520 }
3521
3522 static HRESULT WINAPI ImageListImpl_GetImageRect(IImageList2 *iface, int i,
3523 RECT *prc)
3524 {
3525 HIMAGELIST imgl = impl_from_IImageList2(iface);
3526 IMAGEINFO info;
3527
3528 if (!prc)
3529 return E_FAIL;
3530
3531 if (!ImageList_GetImageInfo(imgl, i, &info))
3532 return E_FAIL;
3533
3534 return CopyRect(prc, &info.rcImage) ? S_OK : E_FAIL;
3535 }
3536
3537 static HRESULT WINAPI ImageListImpl_GetIconSize(IImageList2 *iface, int *cx,
3538 int *cy)
3539 {
3540 HIMAGELIST imgl = impl_from_IImageList2(iface);
3541 return ImageList_GetIconSize(imgl, cx, cy) ? S_OK : E_INVALIDARG;
3542 }
3543
3544 static HRESULT WINAPI ImageListImpl_SetIconSize(IImageList2 *iface, int cx,
3545 int cy)
3546 {
3547 HIMAGELIST imgl = impl_from_IImageList2(iface);
3548 return ImageList_SetIconSize(imgl, cx, cy) ? S_OK : E_FAIL;
3549 }
3550
3551 static HRESULT WINAPI ImageListImpl_GetImageCount(IImageList2 *iface, int *pi)
3552 {
3553 HIMAGELIST imgl = impl_from_IImageList2(iface);
3554 *pi = ImageList_GetImageCount(imgl);
3555 return S_OK;
3556 }
3557
3558 static HRESULT WINAPI ImageListImpl_SetImageCount(IImageList2 *iface, UINT count)
3559 {
3560 HIMAGELIST imgl = impl_from_IImageList2(iface);
3561 return ImageList_SetImageCount(imgl, count) ? S_OK : E_FAIL;
3562 }
3563
3564 static HRESULT WINAPI ImageListImpl_SetBkColor(IImageList2 *iface, COLORREF clrBk,
3565 COLORREF *pclr)
3566 {
3567 HIMAGELIST imgl = impl_from_IImageList2(iface);
3568 *pclr = ImageList_SetBkColor(imgl, clrBk);
3569 return S_OK;
3570 }
3571
3572 static HRESULT WINAPI ImageListImpl_GetBkColor(IImageList2 *iface, COLORREF *pclr)
3573 {
3574 HIMAGELIST imgl = impl_from_IImageList2(iface);
3575 *pclr = ImageList_GetBkColor(imgl);
3576 return S_OK;
3577 }
3578
3579 static HRESULT WINAPI ImageListImpl_BeginDrag(IImageList2 *iface, int iTrack,
3580 int dxHotspot, int dyHotspot)
3581 {
3582 HIMAGELIST imgl = impl_from_IImageList2(iface);
3583 return ImageList_BeginDrag(imgl, iTrack, dxHotspot, dyHotspot) ? S_OK : E_FAIL;
3584 }
3585
3586 static HRESULT WINAPI ImageListImpl_EndDrag(IImageList2 *iface)
3587 {
3588 ImageList_EndDrag();
3589 return S_OK;
3590 }
3591
3592 static HRESULT WINAPI ImageListImpl_DragEnter(IImageList2 *iface, HWND hwndLock,
3593 int x, int y)
3594 {
3595 return ImageList_DragEnter(hwndLock, x, y) ? S_OK : E_FAIL;
3596 }
3597
3598 static HRESULT WINAPI ImageListImpl_DragLeave(IImageList2 *iface, HWND hwndLock)
3599 {
3600 return ImageList_DragLeave(hwndLock) ? S_OK : E_FAIL;
3601 }
3602
3603 static HRESULT WINAPI ImageListImpl_DragMove(IImageList2 *iface, int x, int y)
3604 {
3605 return ImageList_DragMove(x, y) ? S_OK : E_FAIL;
3606 }
3607
3608 static HRESULT WINAPI ImageListImpl_SetDragCursorImage(IImageList2 *iface,
3609 IUnknown *punk, int iDrag, int dxHotspot, int dyHotspot)
3610 {
3611 IImageList *iml2 = NULL;
3612 HRESULT ret;
3613
3614 if (!punk)
3615 return E_FAIL;
3616
3617 /* TODO: Add test for IID_ImageList2 too */
3618 if (FAILED(IUnknown_QueryInterface(punk, &IID_IImageList,
3619 (void **) &iml2)))
3620 return E_FAIL;
3621
3622 ret = ImageList_SetDragCursorImage((HIMAGELIST) iml2, iDrag, dxHotspot,
3623 dyHotspot);
3624
3625 IImageList_Release(iml2);
3626
3627 return ret ? S_OK : E_FAIL;
3628 }
3629
3630 static HRESULT WINAPI ImageListImpl_DragShowNolock(IImageList2 *iface, BOOL fShow)
3631 {
3632 return ImageList_DragShowNolock(fShow) ? S_OK : E_FAIL;
3633 }
3634
3635 static HRESULT WINAPI ImageListImpl_GetDragImage(IImageList2 *iface, POINT *ppt,
3636 POINT *pptHotspot, REFIID riid, PVOID *ppv)
3637 {
3638 HRESULT ret = E_FAIL;
3639 HIMAGELIST hNew;
3640
3641 if (!ppv)
3642 return E_FAIL;
3643
3644 hNew = ImageList_GetDragImage(ppt, pptHotspot);
3645
3646 /* Get the interface for the new image list */
3647 if (hNew)
3648 {
3649 IImageList *idrag = (IImageList*)hNew;
3650
3651 ret = HIMAGELIST_QueryInterface(hNew, riid, ppv);
3652 IImageList_Release(idrag);
3653 }
3654
3655 return ret;
3656 }
3657
3658 static HRESULT WINAPI ImageListImpl_GetItemFlags(IImageList2 *iface, int i,
3659 DWORD *dwFlags)
3660 {
3661 FIXME("STUB: %p %d %p\n", iface, i, dwFlags);
3662 return E_NOTIMPL;
3663 }
3664
3665 static HRESULT WINAPI ImageListImpl_GetOverlayImage(IImageList2 *iface, int iOverlay,
3666 int *piIndex)
3667 {
3668 HIMAGELIST This = impl_from_IImageList2(iface);
3669 int i;
3670
3671 if ((iOverlay < 0) || (iOverlay > This->cCurImage))
3672 return E_FAIL;
3673
3674 for (i = 0; i < MAX_OVERLAYIMAGE; i++)
3675 {
3676 if (This->nOvlIdx[i] == iOverlay)
3677 {
3678 *piIndex = i + 1;
3679 return S_OK;
3680 }
3681 }
3682
3683 return E_FAIL;
3684 }
3685
3686 static HRESULT WINAPI ImageListImpl_Resize(IImageList2 *iface, INT cx, INT cy)
3687 {
3688 FIXME("(%p)->(%d %d): stub\n", iface, cx, cy);
3689 return E_NOTIMPL;
3690 }
3691
3692 static HRESULT WINAPI ImageListImpl_GetOriginalSize(IImageList2 *iface, INT image, DWORD flags, INT *cx, INT *cy)
3693 {
3694 FIXME("(%p)->(%d %x %p %p): stub\n", iface, image, flags, cx, cy);
3695 return E_NOTIMPL;
3696 }
3697
3698 static HRESULT WINAPI ImageListImpl_SetOriginalSize(IImageList2 *iface, INT image, INT cx, INT cy)
3699 {
3700 FIXME("(%p)->(%d %d %d): stub\n", iface, image, cx, cy);
3701 return E_NOTIMPL;
3702 }
3703
3704 static HRESULT WINAPI ImageListImpl_SetCallback(IImageList2 *iface, IUnknown *callback)
3705 {
3706 FIXME("(%p)->(%p): stub\n", iface, callback);
3707 return E_NOTIMPL;
3708 }
3709
3710 static HRESULT WINAPI ImageListImpl_GetCallback(IImageList2 *iface, REFIID riid, void **ppv)
3711 {
3712 FIXME("(%p)->(%s %p): stub\n", iface, debugstr_guid(riid), ppv);
3713 return E_NOTIMPL;
3714 }
3715
3716 static HRESULT WINAPI ImageListImpl_ForceImagePresent(IImageList2 *iface, INT image, DWORD flags)
3717 {
3718 FIXME("(%p)->(%d %x): stub\n", iface, image, flags);
3719 return E_NOTIMPL;
3720 }
3721
3722 static HRESULT WINAPI ImageListImpl_DiscardImages(IImageList2 *iface, INT first_image, INT last_image, DWORD flags)
3723 {
3724 FIXME("(%p)->(%d %d %x): stub\n", iface, first_image, last_image, flags);
3725 return E_NOTIMPL;
3726 }
3727
3728 static HRESULT WINAPI ImageListImpl_PreloadImages(IImageList2 *iface, IMAGELISTDRAWPARAMS *params)
3729 {
3730 FIXME("(%p)->(%p): stub\n", iface, params);
3731 return E_NOTIMPL;
3732 }
3733
3734 static HRESULT WINAPI ImageListImpl_GetStatistics(IImageList2 *iface, IMAGELISTSTATS *stats)
3735 {
3736 FIXME("(%p)->(%p): stub\n", iface, stats);
3737 return E_NOTIMPL;
3738 }
3739
3740 static HRESULT WINAPI ImageListImpl_Initialize(IImageList2 *iface, INT cx, INT cy, UINT flags, INT initial, INT grow)
3741 {
3742 FIXME("(%p)->(%d %d %d %d %d): stub\n", iface, cx, cy, flags, initial, grow);
3743 return E_NOTIMPL;
3744 }
3745
3746 static HRESULT WINAPI ImageListImpl_Replace2(IImageList2 *iface, INT i, HBITMAP image, HBITMAP mask, IUnknown *unk, DWORD flags)
3747 {
3748 FIXME("(%p)->(%d %p %p %p %x): stub\n", iface, i, image, mask, unk, flags);
3749 return E_NOTIMPL;
3750 }
3751
3752 static HRESULT WINAPI ImageListImpl_ReplaceFromImageList(IImageList2 *iface, INT i, IImageList *imagelist, INT src,
3753 IUnknown *unk, DWORD flags)
3754 {
3755 FIXME("(%p)->(%d %p %d %p %x): stub\n", iface, i, imagelist, src, unk, flags);
3756 return E_NOTIMPL;
3757 }
3758
3759 static const IImageList2Vtbl ImageListImpl_Vtbl = {
3760 ImageListImpl_QueryInterface,
3761 ImageListImpl_AddRef,
3762 ImageListImpl_Release,
3763 ImageListImpl_Add,
3764 ImageListImpl_ReplaceIcon,
3765 ImageListImpl_SetOverlayImage,
3766 ImageListImpl_Replace,
3767 ImageListImpl_AddMasked,
3768 ImageListImpl_Draw,
3769 ImageListImpl_Remove,
3770 ImageListImpl_GetIcon,
3771 ImageListImpl_GetImageInfo,
3772 ImageListImpl_Copy,
3773 ImageListImpl_Merge,
3774 ImageListImpl_Clone,
3775 ImageListImpl_GetImageRect,
3776 ImageListImpl_GetIconSize,
3777 ImageListImpl_SetIconSize,
3778 ImageListImpl_GetImageCount,
3779 ImageListImpl_SetImageCount,
3780 ImageListImpl_SetBkColor,
3781 ImageListImpl_GetBkColor,
3782 ImageListImpl_BeginDrag,
3783 ImageListImpl_EndDrag,
3784 ImageListImpl_DragEnter,
3785 ImageListImpl_DragLeave,
3786 ImageListImpl_DragMove,
3787 ImageListImpl_SetDragCursorImage,
3788 ImageListImpl_DragShowNolock,
3789 ImageListImpl_GetDragImage,
3790 ImageListImpl_GetItemFlags,
3791 ImageListImpl_GetOverlayImage,
3792 ImageListImpl_Resize,
3793 ImageListImpl_GetOriginalSize,
3794 ImageListImpl_SetOriginalSize,
3795 ImageListImpl_SetCallback,
3796 ImageListImpl_GetCallback,
3797 ImageListImpl_ForceImagePresent,
3798 ImageListImpl_DiscardImages,
3799 ImageListImpl_PreloadImages,
3800 ImageListImpl_GetStatistics,
3801 ImageListImpl_Initialize,
3802 ImageListImpl_Replace2,
3803 ImageListImpl_ReplaceFromImageList
3804 };
3805
3806 static BOOL is_valid(HIMAGELIST himl)
3807 {
3808 BOOL valid;
3809 __TRY
3810 {
3811 valid = himl && himl->IImageList2_iface.lpVtbl == &ImageListImpl_Vtbl;
3812 }
3813 __EXCEPT_PAGE_FAULT
3814 {
3815 valid = FALSE;
3816 }
3817 __ENDTRY
3818 return valid;
3819 }
3820
3821 /*************************************************************************
3822 * HIMAGELIST_QueryInterface [COMCTL32.@]
3823 *
3824 * Returns a pointer to an IImageList or IImageList2 object for the given
3825 * HIMAGELIST.
3826 *
3827 * PARAMS
3828 * himl [I] Image list handle.
3829 * riid [I] Identifier of the requested interface.
3830 * ppv [O] Returns the address of the pointer requested, or NULL.
3831 *
3832 * RETURNS
3833 * Success: S_OK.
3834 * Failure: Error value.
3835 */
3836 HRESULT WINAPI
3837 HIMAGELIST_QueryInterface (HIMAGELIST himl, REFIID riid, void **ppv)
3838 {
3839 TRACE("(%p,%s,%p)\n", himl, debugstr_guid(riid), ppv);
3840 return IImageList2_QueryInterface((IImageList2 *) himl, riid, ppv);
3841 }
3842
3843 static HRESULT ImageListImpl_CreateInstance(const IUnknown *pUnkOuter, REFIID iid, void** ppv)
3844 {
3845 HIMAGELIST This;
3846 HRESULT ret;
3847
3848 TRACE("(%p,%s,%p)\n", pUnkOuter, debugstr_guid(iid), ppv);
3849
3850 *ppv = NULL;
3851
3852 if (pUnkOuter) return CLASS_E_NOAGGREGATION;
3853
3854 This = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(struct _IMAGELIST));
3855 if (!This) return E_OUTOFMEMORY;
3856
3857 This->IImageList2_iface.lpVtbl = &ImageListImpl_Vtbl;
3858 This->ref = 1;
3859
3860 ret = IImageList2_QueryInterface(&This->IImageList2_iface, iid, ppv);
3861 IImageList2_Release(&This->IImageList2_iface);
3862
3863 return ret;
3864 }