[COMCTL32_WINETEST] Sync with Wine Staging 1.9.4. CORE-10912
[reactos.git] / rostests / winetests / comctl32 / imagelist.c
1 /*
2 * Unit test suite for imagelist control.
3 *
4 * Copyright 2004 Michael Stefaniuc
5 * Copyright 2002 Mike McCormack for CodeWeavers
6 * Copyright 2007 Dmitry Timoshkov
7 * Copyright 2009 Owen Rudge for CodeWeavers
8 *
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
13 *
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
24 #define WIN32_NO_STATUS
25 #define _INC_WINDOWS
26 #define COM_NO_WINDOWS_H
27
28 #define COBJMACROS
29 #define CONST_VTABLE
30
31 //#include <stdarg.h>
32 #include <stdio.h>
33
34 #include <windef.h>
35 #include <winbase.h>
36 #include <wingdi.h>
37 #include <winuser.h>
38 #include <objbase.h>
39 #include <commctrl.h> /* must be included after objbase.h to get ImageList_Write */
40 #include <initguid.h>
41 #include <commoncontrols.h>
42 #include <shellapi.h>
43
44 #include <wine/test.h>
45 #include "v6util.h"
46
47 #define IMAGELIST_MAGIC (('L' << 8) | 'I')
48
49 #include "pshpack2.h"
50 /* Header used by ImageList_Read() and ImageList_Write() */
51 typedef struct _ILHEAD
52 {
53 USHORT usMagic;
54 USHORT usVersion;
55 WORD cCurImage;
56 WORD cMaxImage;
57 WORD cGrow;
58 WORD cx;
59 WORD cy;
60 COLORREF bkcolor;
61 WORD flags;
62 SHORT ovls[4];
63 } ILHEAD;
64 #include "poppack.h"
65
66 static HIMAGELIST (WINAPI *pImageList_Create)(int, int, UINT, int, int);
67 static int (WINAPI *pImageList_Add)(HIMAGELIST, HBITMAP, HBITMAP);
68 static BOOL (WINAPI *pImageList_DrawIndirect)(IMAGELISTDRAWPARAMS*);
69 static BOOL (WINAPI *pImageList_SetImageCount)(HIMAGELIST,UINT);
70 static HRESULT (WINAPI *pImageList_CoCreateInstance)(REFCLSID,const IUnknown *,
71 REFIID,void **);
72 static HRESULT (WINAPI *pHIMAGELIST_QueryInterface)(HIMAGELIST,REFIID,void **);
73
74 static HINSTANCE hinst;
75
76 /* only used in interactive mode */
77 static void force_redraw(HWND hwnd)
78 {
79 if (!winetest_interactive)
80 return;
81
82 RedrawWindow(hwnd, NULL, 0, RDW_UPDATENOW);
83 Sleep(1000);
84 }
85
86 /* These macros build cursor/bitmap data in 4x4 pixel blocks */
87 #define B(x,y) ((x?0xf0:0)|(y?0xf:0))
88 #define ROW1(a,b,c,d,e,f,g,h) B(a,b),B(c,d),B(e,f),B(g,h)
89 #define ROW32(a,b,c,d,e,f,g,h) ROW1(a,b,c,d,e,f,g,h), ROW1(a,b,c,d,e,f,g,h), \
90 ROW1(a,b,c,d,e,f,g,h), ROW1(a,b,c,d,e,f,g,h)
91 #define ROW2(a,b,c,d,e,f,g,h,i,j,k,l) ROW1(a,b,c,d,e,f,g,h),B(i,j),B(k,l)
92 #define ROW48(a,b,c,d,e,f,g,h,i,j,k,l) ROW2(a,b,c,d,e,f,g,h,i,j,k,l), \
93 ROW2(a,b,c,d,e,f,g,h,i,j,k,l), ROW2(a,b,c,d,e,f,g,h,i,j,k,l), \
94 ROW2(a,b,c,d,e,f,g,h,i,j,k,l)
95
96 static const BYTE empty_bits[48*48/8];
97
98 static const BYTE icon_bits[32*32/8] =
99 {
100 ROW32(0,0,0,0,0,0,0,0),
101 ROW32(0,0,1,1,1,1,0,0),
102 ROW32(0,1,1,1,1,1,1,0),
103 ROW32(0,1,1,0,0,1,1,0),
104 ROW32(0,1,1,0,0,1,1,0),
105 ROW32(0,1,1,1,1,1,1,0),
106 ROW32(0,0,1,1,1,1,0,0),
107 ROW32(0,0,0,0,0,0,0,0)
108 };
109
110 static const BYTE bitmap_bits[48*48/8] =
111 {
112 ROW48(0,0,0,0,0,0,0,0,0,0,0,0),
113 ROW48(0,1,1,1,1,1,1,1,1,1,1,0),
114 ROW48(0,1,1,0,0,0,0,0,0,1,1,0),
115 ROW48(0,1,0,0,0,0,0,0,1,0,1,0),
116 ROW48(0,1,0,0,0,0,0,1,0,0,1,0),
117 ROW48(0,1,0,0,0,0,1,0,0,0,1,0),
118 ROW48(0,1,0,0,0,1,0,0,0,0,1,0),
119 ROW48(0,1,0,0,1,0,0,0,0,0,1,0),
120 ROW48(0,1,0,1,0,0,0,0,0,0,1,0),
121 ROW48(0,1,1,0,0,0,0,0,0,1,1,0),
122 ROW48(0,1,1,1,1,1,1,1,1,1,1,0),
123 ROW48(0,0,0,0,0,0,0,0,0,0,0,0)
124 };
125
126 static HIMAGELIST createImageList(int cx, int cy)
127 {
128 /* Create an ImageList and put an image into it */
129 HIMAGELIST himl = ImageList_Create(cx, cy, ILC_COLOR, 1, 1);
130 HBITMAP hbm = CreateBitmap(48, 48, 1, 1, bitmap_bits);
131 ImageList_Add(himl, hbm, NULL);
132 DeleteObject(hbm);
133 return himl;
134 }
135
136 static HWND create_a_window(void)
137 {
138 char className[] = "bmwnd";
139 char winName[] = "Test Bitmap";
140 HWND hWnd;
141 static BOOL registered = FALSE;
142
143 if (!registered)
144 {
145 WNDCLASSA cls;
146
147 cls.style = CS_HREDRAW | CS_VREDRAW | CS_GLOBALCLASS;
148 cls.lpfnWndProc = DefWindowProcA;
149 cls.cbClsExtra = 0;
150 cls.cbWndExtra = 0;
151 cls.hInstance = 0;
152 cls.hIcon = LoadIconA(0, (LPCSTR)IDI_APPLICATION);
153 cls.hCursor = LoadCursorA(0, (LPCSTR)IDC_ARROW);
154 cls.hbrBackground = GetStockObject (WHITE_BRUSH);
155 cls.lpszMenuName = 0;
156 cls.lpszClassName = className;
157
158 RegisterClassA (&cls);
159 registered = TRUE;
160 }
161
162 /* Setup window */
163 hWnd = CreateWindowA (className, winName,
164 WS_OVERLAPPEDWINDOW ,
165 CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
166 0, hinst, 0);
167
168 if (winetest_interactive)
169 {
170 ShowWindow (hWnd, SW_SHOW);
171 force_redraw (hWnd);
172 }
173
174 return hWnd;
175 }
176
177 static HDC show_image(HWND hwnd, HIMAGELIST himl, int idx, int size,
178 LPCSTR loc, BOOL clear)
179 {
180 HDC hdc;
181
182 if (!winetest_interactive || !himl) return NULL;
183
184 SetWindowTextA(hwnd, loc);
185 hdc = GetDC(hwnd);
186 ImageList_Draw(himl, idx, hdc, 0, 0, ILD_TRANSPARENT);
187
188 force_redraw(hwnd);
189
190 if (clear)
191 {
192 BitBlt(hdc, 0, 0, size, size, hdc, size+1, size+1, SRCCOPY);
193 ReleaseDC(hwnd, hdc);
194 hdc = NULL;
195 }
196
197 return hdc;
198 }
199
200 /* Useful for checking differences */
201 static void dump_bits(const BYTE *p, const BYTE *q, int size)
202 {
203 int i, j;
204
205 size /= 8;
206
207 for (i = 0; i < size * 2; i++)
208 {
209 printf("|");
210 for (j = 0; j < size; j++)
211 printf("%c%c", p[j] & 0xf0 ? 'X' : ' ', p[j] & 0xf ? 'X' : ' ');
212 printf(" -- ");
213 for (j = 0; j < size; j++)
214 printf("%c%c", q[j] & 0xf0 ? 'X' : ' ', q[j] & 0xf ? 'X' : ' ');
215 printf("|\n");
216 p += size * 4;
217 q += size * 4;
218 }
219 printf("\n");
220 }
221
222 static void check_bits(HWND hwnd, HIMAGELIST himl, int idx, int size,
223 const BYTE *checkbits, LPCSTR loc)
224 {
225 BYTE bits[100*100/8];
226 COLORREF c;
227 HDC hdc;
228 int x, y, i = -1;
229
230 if (!winetest_interactive || !himl) return;
231
232 memset(bits, 0, sizeof(bits));
233 hdc = show_image(hwnd, himl, idx, size, loc, FALSE);
234
235 c = GetPixel(hdc, 0, 0);
236
237 for (y = 0; y < size; y ++)
238 {
239 for (x = 0; x < size; x++)
240 {
241 if (!(x & 0x7)) i++;
242 if (GetPixel(hdc, x, y) != c) bits[i] |= (0x80 >> (x & 0x7));
243 }
244 }
245
246 BitBlt(hdc, 0, 0, size, size, hdc, size+1, size+1, SRCCOPY);
247 ReleaseDC(hwnd, hdc);
248
249 ok (memcmp(bits, checkbits, (size * size)/8) == 0,
250 "%s: bits different\n", loc);
251 if (memcmp(bits, checkbits, (size * size)/8))
252 dump_bits(bits, checkbits, size);
253 }
254
255 static void test_begindrag(void)
256 {
257 HIMAGELIST himl = createImageList(7,13);
258 HIMAGELIST drag;
259 BOOL ret;
260 int count;
261 POINT hotspot;
262
263 count = ImageList_GetImageCount(himl);
264 ok(count > 2, "Tests need an ImageList with more than 2 images\n");
265
266 /* Two BeginDrag() without EndDrag() in between */
267 ret = ImageList_BeginDrag(himl, 1, 0, 0);
268 drag = ImageList_GetDragImage(NULL, NULL);
269 ok(ret && drag, "ImageList_BeginDrag() failed\n");
270 ret = ImageList_BeginDrag(himl, 0, 3, 5);
271 ok(!ret, "ImageList_BeginDrag() returned TRUE\n");
272 drag = ImageList_GetDragImage(NULL, &hotspot);
273 ok(!!drag, "No active ImageList drag left\n");
274 ok(hotspot.x == 0 && hotspot.y == 0, "New ImageList drag was created\n");
275 ImageList_EndDrag();
276 drag = ImageList_GetDragImage(NULL, NULL);
277 ok(!drag, "ImageList drag was not destroyed\n");
278
279 /* Invalid image index */
280 ImageList_BeginDrag(himl, 0, 0, 0);
281 ret = ImageList_BeginDrag(himl, count, 3, 5);
282 ok(!ret, "ImageList_BeginDrag() returned TRUE\n");
283 drag = ImageList_GetDragImage(NULL, &hotspot);
284 ok(drag && hotspot.x == 0 && hotspot.y == 0, "Active drag should not have been canceled\n");
285 ImageList_EndDrag();
286 drag = ImageList_GetDragImage(NULL, NULL);
287 ok(!drag, "ImageList drag was not destroyed\n");
288 /* Invalid negative image indexes succeed */
289 ret = ImageList_BeginDrag(himl, -17, 0, 0);
290 drag = ImageList_GetDragImage(NULL, NULL);
291 ok(ret && drag, "ImageList drag was created\n");
292 ImageList_EndDrag();
293 ret = ImageList_BeginDrag(himl, -1, 0, 0);
294 drag = ImageList_GetDragImage(NULL, NULL);
295 ok(ret && drag, "ImageList drag was created\n");
296 ImageList_EndDrag();
297 ImageList_Destroy(himl);
298 }
299
300 static void test_hotspot(void)
301 {
302 struct hotspot {
303 int dx;
304 int dy;
305 };
306
307 #define SIZEX1 47
308 #define SIZEY1 31
309 #define SIZEX2 11
310 #define SIZEY2 17
311 #define HOTSPOTS_MAX 4 /* Number of entries in hotspots */
312 static const struct hotspot hotspots[HOTSPOTS_MAX] = {
313 { 10, 7 },
314 { SIZEX1, SIZEY1 },
315 { -9, -8 },
316 { -7, 35 }
317 };
318 int i, j, ret;
319 HIMAGELIST himl1 = createImageList(SIZEX1, SIZEY1);
320 HIMAGELIST himl2 = createImageList(SIZEX2, SIZEY2);
321 HWND hwnd = create_a_window();
322
323
324 for (i = 0; i < HOTSPOTS_MAX; i++) {
325 for (j = 0; j < HOTSPOTS_MAX; j++) {
326 int dx1 = hotspots[i].dx;
327 int dy1 = hotspots[i].dy;
328 int dx2 = hotspots[j].dx;
329 int dy2 = hotspots[j].dy;
330 int correctx, correcty, newx, newy;
331 char loc[256];
332 HIMAGELIST himlNew;
333 POINT ppt;
334
335 ret = ImageList_BeginDrag(himl1, 0, dx1, dy1);
336 ok(ret != 0, "BeginDrag failed for { %d, %d }\n", dx1, dy1);
337 sprintf(loc, "BeginDrag (%d,%d)\n", i, j);
338 show_image(hwnd, himl1, 0, max(SIZEX1, SIZEY1), loc, TRUE);
339
340 /* check merging the dragged image with a second image */
341 ret = ImageList_SetDragCursorImage(himl2, 0, dx2, dy2);
342 ok(ret != 0, "SetDragCursorImage failed for {%d, %d}{%d, %d}\n",
343 dx1, dy1, dx2, dy2);
344 sprintf(loc, "SetDragCursorImage (%d,%d)\n", i, j);
345 show_image(hwnd, himl2, 0, max(SIZEX2, SIZEY2), loc, TRUE);
346
347 /* check new hotspot, it should be the same like the old one */
348 himlNew = ImageList_GetDragImage(NULL, &ppt);
349 ok(ppt.x == dx1 && ppt.y == dy1,
350 "Expected drag hotspot [%d,%d] got [%d,%d]\n",
351 dx1, dy1, ppt.x, ppt.y);
352 /* check size of new dragged image */
353 ImageList_GetIconSize(himlNew, &newx, &newy);
354 correctx = max(SIZEX1, max(SIZEX2 + dx2, SIZEX1 - dx2));
355 correcty = max(SIZEY1, max(SIZEY2 + dy2, SIZEY1 - dy2));
356 ok(newx == correctx && newy == correcty,
357 "Expected drag image size [%d,%d] got [%d,%d]\n",
358 correctx, correcty, newx, newy);
359 sprintf(loc, "GetDragImage (%d,%d)\n", i, j);
360 show_image(hwnd, himlNew, 0, max(correctx, correcty), loc, TRUE);
361 ImageList_EndDrag();
362 }
363 }
364 #undef SIZEX1
365 #undef SIZEY1
366 #undef SIZEX2
367 #undef SIZEY2
368 #undef HOTSPOTS_MAX
369 ImageList_Destroy(himl2);
370 ImageList_Destroy(himl1);
371 DestroyWindow(hwnd);
372 }
373
374 static void test_add_remove(void)
375 {
376 HIMAGELIST himl ;
377
378 HICON hicon1 ;
379 HICON hicon2 ;
380 HICON hicon3 ;
381
382 /* create an imagelist to play with */
383 himl = ImageList_Create(84, 84, ILC_COLOR16, 0, 3);
384 ok(himl!=0,"failed to create imagelist\n");
385
386 /* load the icons to add to the image list */
387 hicon1 = CreateIcon(hinst, 32, 32, 1, 1, icon_bits, icon_bits);
388 ok(hicon1 != 0, "no hicon1\n");
389 hicon2 = CreateIcon(hinst, 32, 32, 1, 1, icon_bits, icon_bits);
390 ok(hicon2 != 0, "no hicon2\n");
391 hicon3 = CreateIcon(hinst, 32, 32, 1, 1, icon_bits, icon_bits);
392 ok(hicon3 != 0, "no hicon3\n");
393
394 /* remove when nothing exists */
395 ok(!ImageList_Remove(himl,0),"removed nonexistent icon\n");
396 /* removing everything from an empty imagelist should succeed */
397 ok(ImageList_RemoveAll(himl),"removed nonexistent icon\n");
398
399 /* add three */
400 ok(0==ImageList_AddIcon(himl, hicon1),"failed to add icon1\n");
401 ok(1==ImageList_AddIcon(himl, hicon2),"failed to add icon2\n");
402 ok(2==ImageList_AddIcon(himl, hicon3),"failed to add icon3\n");
403
404 /* remove an index out of range */
405 ok(!ImageList_Remove(himl,4711),"removed nonexistent icon\n");
406
407 /* remove three */
408 ok(ImageList_Remove(himl,0),"can't remove 0\n");
409 ok(ImageList_Remove(himl,0),"can't remove 0\n");
410 ok(ImageList_Remove(himl,0),"can't remove 0\n");
411
412 /* remove one extra */
413 ok(!ImageList_Remove(himl,0),"removed nonexistent icon\n");
414
415 /* destroy it */
416 ok(ImageList_Destroy(himl),"destroy imagelist failed\n");
417
418 ok(-1==ImageList_AddIcon((HIMAGELIST)0xdeadbeef, hicon1),"don't crash on bad handle\n");
419
420 ok(DestroyIcon(hicon1),"icon 1 wasn't deleted\n");
421 ok(DestroyIcon(hicon2),"icon 2 wasn't deleted\n");
422 ok(DestroyIcon(hicon3),"icon 3 wasn't deleted\n");
423 }
424
425 static void test_imagecount(void)
426 {
427 HIMAGELIST himl;
428
429 ok(0==ImageList_GetImageCount((HIMAGELIST)0xdeadbeef),"don't crash on bad handle\n");
430
431 if (!pImageList_SetImageCount)
432 {
433 win_skip("ImageList_SetImageCount not available\n");
434 return;
435 }
436
437 himl = ImageList_Create(84, 84, ILC_COLOR16, 0, 3);
438 ok(himl!=0,"failed to create imagelist\n");
439
440 ok(pImageList_SetImageCount(himl, 3), "couldn't increase image count\n");
441 ok(ImageList_GetImageCount(himl) == 3, "invalid image count after increase\n");
442 ok(pImageList_SetImageCount(himl, 1), "couldn't decrease image count\n");
443 ok(ImageList_GetImageCount(himl) == 1, "invalid image count after decrease to 1\n");
444 ok(pImageList_SetImageCount(himl, 0), "couldn't decrease image count\n");
445 ok(ImageList_GetImageCount(himl) == 0, "invalid image count after decrease to 0\n");
446
447 ok(ImageList_Destroy(himl), "destroy imagelist failed\n");
448 }
449
450 static void test_DrawIndirect(void)
451 {
452 HIMAGELIST himl;
453
454 HBITMAP hbm1;
455 HBITMAP hbm2;
456 HBITMAP hbm3;
457
458 IMAGELISTDRAWPARAMS imldp;
459 HDC hdc;
460 HWND hwndfortest;
461
462 if (!pImageList_DrawIndirect)
463 {
464 win_skip("ImageList_DrawIndirect not available, skipping test\n");
465 return;
466 }
467
468 hwndfortest = create_a_window();
469 hdc = GetDC(hwndfortest);
470 ok(hdc!=NULL, "couldn't get DC\n");
471
472 /* create an imagelist to play with */
473 himl = ImageList_Create(48, 48, ILC_COLOR16, 0, 3);
474 ok(himl!=0,"failed to create imagelist\n");
475
476 /* load the icons to add to the image list */
477 hbm1 = CreateBitmap(48, 48, 1, 1, bitmap_bits);
478 ok(hbm1 != 0, "no bitmap 1\n");
479 hbm2 = CreateBitmap(48, 48, 1, 1, bitmap_bits);
480 ok(hbm2 != 0, "no bitmap 2\n");
481 hbm3 = CreateBitmap(48, 48, 1, 1, bitmap_bits);
482 ok(hbm3 != 0, "no bitmap 3\n");
483
484 /* add three */
485 ok(0==ImageList_Add(himl, hbm1, 0),"failed to add bitmap 1\n");
486 ok(1==ImageList_Add(himl, hbm2, 0),"failed to add bitmap 2\n");
487
488 if (pImageList_SetImageCount)
489 {
490 ok(pImageList_SetImageCount(himl,3),"Setimage count failed\n");
491 /*ok(2==ImageList_Add(himl, hbm3, NULL),"failed to add bitmap 3\n"); */
492 ok(ImageList_Replace(himl, 2, hbm3, 0),"failed to replace bitmap 3\n");
493 }
494
495 memset(&imldp, 0, sizeof (imldp));
496 ok(!pImageList_DrawIndirect(&imldp), "zero data succeeded!\n");
497 imldp.cbSize = IMAGELISTDRAWPARAMS_V3_SIZE;
498 ok(!pImageList_DrawIndirect(&imldp), "zero hdc succeeded!\n");
499 imldp.hdcDst = hdc;
500 ok(!pImageList_DrawIndirect(&imldp),"zero himl succeeded!\n");
501 imldp.himl = (HIMAGELIST)0xdeadbeef;
502 ok(!pImageList_DrawIndirect(&imldp),"bad himl succeeded!\n");
503 imldp.himl = himl;
504
505 force_redraw(hwndfortest);
506
507 imldp.fStyle = SRCCOPY;
508 imldp.rgbBk = CLR_DEFAULT;
509 imldp.rgbFg = CLR_DEFAULT;
510 imldp.y = 100;
511 imldp.x = 100;
512 ok(pImageList_DrawIndirect(&imldp),"should succeed\n");
513 imldp.i ++;
514 ok(pImageList_DrawIndirect(&imldp),"should succeed\n");
515 imldp.i ++;
516 ok(pImageList_DrawIndirect(&imldp),"should succeed\n");
517 imldp.i ++;
518 ok(!pImageList_DrawIndirect(&imldp),"should fail\n");
519
520 /* remove three */
521 ok(ImageList_Remove(himl, 0), "removing 1st bitmap\n");
522 ok(ImageList_Remove(himl, 0), "removing 2nd bitmap\n");
523 ok(ImageList_Remove(himl, 0), "removing 3rd bitmap\n");
524
525 /* destroy it */
526 ok(ImageList_Destroy(himl),"destroy imagelist failed\n");
527
528 /* bitmaps should not be deleted by the imagelist */
529 ok(DeleteObject(hbm1),"bitmap 1 can't be deleted\n");
530 ok(DeleteObject(hbm2),"bitmap 2 can't be deleted\n");
531 ok(DeleteObject(hbm3),"bitmap 3 can't be deleted\n");
532
533 ReleaseDC(hwndfortest, hdc);
534 DestroyWindow(hwndfortest);
535 }
536
537 static int get_color_format(HBITMAP bmp)
538 {
539 BITMAPINFO bmi;
540 HDC hdc = CreateCompatibleDC(0);
541 HBITMAP hOldBmp = SelectObject(hdc, bmp);
542 int ret;
543
544 memset(&bmi, 0, sizeof(bmi));
545 bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
546 ret = GetDIBits(hdc, bmp, 0, 0, 0, &bmi, DIB_RGB_COLORS);
547 ok(ret, "GetDIBits failed\n");
548
549 SelectObject(hdc, hOldBmp);
550 DeleteDC(hdc);
551 return bmi.bmiHeader.biBitCount;
552 }
553
554 static void test_merge_colors(void)
555 {
556 HIMAGELIST himl[8], hmerge;
557 int sizes[] = { ILC_COLOR, ILC_COLOR | ILC_MASK, ILC_COLOR4, ILC_COLOR8, ILC_COLOR16, ILC_COLOR24, ILC_COLOR32, ILC_COLORDDB };
558 HICON hicon1;
559 IMAGEINFO info;
560 int bpp, i, j;
561
562 hicon1 = CreateIcon(hinst, 32, 32, 1, 1, icon_bits, icon_bits);
563 ok(hicon1 != NULL, "failed to create hicon1\n");
564
565 for (i = 0; i < 8; i++)
566 {
567 himl[i] = ImageList_Create(32, 32, sizes[i], 0, 3);
568 ok(himl[i] != NULL, "failed to create himl[%d]\n", i);
569 ok(0 == ImageList_AddIcon(himl[i], hicon1), "add icon1 to himl[%d] failed\n", i);
570 if (i == 0 || i == 1 || i == 7)
571 {
572 ImageList_GetImageInfo(himl[i], 0, &info);
573 sizes[i] = get_color_format(info.hbmImage);
574 }
575 }
576 DestroyIcon(hicon1);
577 for (i = 0; i < 8; i++)
578 for (j = 0; j < 8; j++)
579 {
580 hmerge = ImageList_Merge(himl[i], 0, himl[j], 0, 0, 0);
581 ok(hmerge != NULL, "merge himl[%d], himl[%d] failed\n", i, j);
582
583 ImageList_GetImageInfo(hmerge, 0, &info);
584 bpp = get_color_format(info.hbmImage);
585 /* ILC_COLOR[X] is defined as [X] */
586 if (i == 4 && j == 7)
587 ok(bpp == 16, /* merging ILC_COLOR16 with ILC_COLORDDB seems to be a special case */
588 "wrong biBitCount %d when merging lists %d (%d) and %d (%d)\n", bpp, i, sizes[i], j, sizes[j]);
589 else
590 ok(bpp == (i > j ? sizes[i] : sizes[j]),
591 "wrong biBitCount %d when merging lists %d (%d) and %d (%d)\n", bpp, i, sizes[i], j, sizes[j]);
592 ok(info.hbmMask != 0, "Imagelist merged from %d and %d had no mask\n", i, j);
593
594 if (hmerge) ImageList_Destroy(hmerge);
595 }
596
597 for (i = 0; i < 8; i++)
598 ImageList_Destroy(himl[i]);
599 }
600
601 static void test_merge(void)
602 {
603 HIMAGELIST himl1, himl2, hmerge;
604 HICON hicon1;
605 HWND hwnd = create_a_window();
606
607 himl1 = ImageList_Create(32,32,0,0,3);
608 ok(himl1 != NULL,"failed to create himl1\n");
609
610 himl2 = ImageList_Create(32,32,0,0,3);
611 ok(himl2 != NULL,"failed to create himl2\n");
612
613 hicon1 = CreateIcon(hinst, 32, 32, 1, 1, icon_bits, icon_bits);
614 ok(hicon1 != NULL, "failed to create hicon1\n");
615
616 if (!himl1 || !himl2 || !hicon1)
617 return;
618
619 ok(0==ImageList_AddIcon(himl2, hicon1),"add icon1 to himl2 failed\n");
620 check_bits(hwnd, himl2, 0, 32, icon_bits, "add icon1 to himl2");
621
622 /* If himl1 has no images, merge still succeeds */
623 hmerge = ImageList_Merge(himl1, -1, himl2, 0, 0, 0);
624 ok(hmerge != NULL, "merge himl1,-1 failed\n");
625 check_bits(hwnd, hmerge, 0, 32, empty_bits, "merge himl1,-1");
626 if (hmerge) ImageList_Destroy(hmerge);
627
628 hmerge = ImageList_Merge(himl1, 0, himl2, 0, 0, 0);
629 ok(hmerge != NULL,"merge himl1,0 failed\n");
630 check_bits(hwnd, hmerge, 0, 32, empty_bits, "merge himl1,0");
631 if (hmerge) ImageList_Destroy(hmerge);
632
633 /* Same happens if himl2 is empty */
634 ImageList_Destroy(himl2);
635 himl2 = ImageList_Create(32,32,0,0,3);
636 ok(himl2 != NULL,"failed to recreate himl2\n");
637 if (!himl2)
638 return;
639
640 hmerge = ImageList_Merge(himl1, -1, himl2, -1, 0, 0);
641 ok(hmerge != NULL, "merge himl2,-1 failed\n");
642 check_bits(hwnd, hmerge, 0, 32, empty_bits, "merge himl2,-1");
643 if (hmerge) ImageList_Destroy(hmerge);
644
645 hmerge = ImageList_Merge(himl1, -1, himl2, 0, 0, 0);
646 ok(hmerge != NULL, "merge himl2,0 failed\n");
647 check_bits(hwnd, hmerge, 0, 32, empty_bits, "merge himl2,0");
648 if (hmerge) ImageList_Destroy(hmerge);
649
650 /* Now try merging an image with itself */
651 ok(0==ImageList_AddIcon(himl2, hicon1),"re-add icon1 to himl2 failed\n");
652
653 hmerge = ImageList_Merge(himl2, 0, himl2, 0, 0, 0);
654 ok(hmerge != NULL, "merge himl2 with itself failed\n");
655 check_bits(hwnd, hmerge, 0, 32, empty_bits, "merge himl2 with itself");
656 if (hmerge) ImageList_Destroy(hmerge);
657
658 /* Try merging 2 different image lists */
659 ok(0==ImageList_AddIcon(himl1, hicon1),"add icon1 to himl1 failed\n");
660
661 hmerge = ImageList_Merge(himl1, 0, himl2, 0, 0, 0);
662 ok(hmerge != NULL, "merge himl1 with himl2 failed\n");
663 check_bits(hwnd, hmerge, 0, 32, empty_bits, "merge himl1 with himl2");
664 if (hmerge) ImageList_Destroy(hmerge);
665
666 hmerge = ImageList_Merge(himl1, 0, himl2, 0, 8, 16);
667 ok(hmerge != NULL, "merge himl1 with himl2 8,16 failed\n");
668 check_bits(hwnd, hmerge, 0, 32, empty_bits, "merge himl1 with himl2, 8,16");
669 if (hmerge) ImageList_Destroy(hmerge);
670
671 ImageList_Destroy(himl1);
672 ImageList_Destroy(himl2);
673 DestroyIcon(hicon1);
674 DestroyWindow(hwnd);
675 }
676
677 /*********************** imagelist storage test ***************************/
678
679 #define BMP_CX 48
680
681 struct my_IStream
682 {
683 IStream IStream_iface;
684 char *iml_data; /* written imagelist data */
685 ULONG iml_data_size;
686 };
687
688 static struct my_IStream *impl_from_IStream(IStream *iface)
689 {
690 return CONTAINING_RECORD(iface, struct my_IStream, IStream_iface);
691 }
692
693 static HRESULT STDMETHODCALLTYPE Test_Stream_QueryInterface(IStream *iface, REFIID riid,
694 void **ppvObject)
695 {
696 ok(0, "unexpected call\n");
697 return E_NOTIMPL;
698 }
699
700 static ULONG STDMETHODCALLTYPE Test_Stream_AddRef(IStream *iface)
701 {
702 ok(0, "unexpected call\n");
703 return 2;
704 }
705
706 static ULONG STDMETHODCALLTYPE Test_Stream_Release(IStream *iface)
707 {
708 ok(0, "unexpected call\n");
709 return 1;
710 }
711
712 static HRESULT STDMETHODCALLTYPE Test_Stream_Read(IStream *iface, void *pv, ULONG cb,
713 ULONG *pcbRead)
714 {
715 ok(0, "unexpected call\n");
716 return E_NOTIMPL;
717 }
718
719 static BOOL allocate_storage(struct my_IStream *my_is, ULONG add)
720 {
721 my_is->iml_data_size += add;
722
723 if (!my_is->iml_data)
724 my_is->iml_data = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, my_is->iml_data_size);
725 else
726 my_is->iml_data = HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, my_is->iml_data, my_is->iml_data_size);
727
728 return my_is->iml_data != NULL;
729 }
730
731 static HRESULT STDMETHODCALLTYPE Test_Stream_Write(IStream *iface, const void *pv, ULONG cb,
732 ULONG *pcbWritten)
733 {
734 struct my_IStream *my_is = impl_from_IStream(iface);
735 ULONG current_iml_data_size = my_is->iml_data_size;
736
737 if (!allocate_storage(my_is, cb)) return E_FAIL;
738
739 memcpy(my_is->iml_data + current_iml_data_size, pv, cb);
740 if (pcbWritten) *pcbWritten = cb;
741
742 return S_OK;
743 }
744
745 static HRESULT STDMETHODCALLTYPE Test_Stream_Seek(IStream *iface, LARGE_INTEGER dlibMove,
746 DWORD dwOrigin, ULARGE_INTEGER *plibNewPosition)
747 {
748 ok(0, "unexpected call\n");
749 return E_NOTIMPL;
750 }
751
752 static HRESULT STDMETHODCALLTYPE Test_Stream_SetSize(IStream *iface, ULARGE_INTEGER libNewSize)
753 {
754 ok(0, "unexpected call\n");
755 return E_NOTIMPL;
756 }
757
758 static HRESULT STDMETHODCALLTYPE Test_Stream_CopyTo(IStream *iface, IStream *pstm,
759 ULARGE_INTEGER cb, ULARGE_INTEGER *pcbRead,
760 ULARGE_INTEGER *pcbWritten)
761 {
762 ok(0, "unexpected call\n");
763 return E_NOTIMPL;
764 }
765
766 static HRESULT STDMETHODCALLTYPE Test_Stream_Commit(IStream *iface, DWORD grfCommitFlags)
767 {
768 ok(0, "unexpected call\n");
769 return E_NOTIMPL;
770 }
771
772 static HRESULT STDMETHODCALLTYPE Test_Stream_Revert(IStream *iface)
773 {
774 ok(0, "unexpected call\n");
775 return E_NOTIMPL;
776 }
777
778 static HRESULT STDMETHODCALLTYPE Test_Stream_LockRegion(IStream *iface, ULARGE_INTEGER libOffset,
779 ULARGE_INTEGER cb, DWORD dwLockType)
780 {
781 ok(0, "unexpected call\n");
782 return E_NOTIMPL;
783 }
784
785 static HRESULT STDMETHODCALLTYPE Test_Stream_UnlockRegion(IStream *iface, ULARGE_INTEGER libOffset,
786 ULARGE_INTEGER cb, DWORD dwLockType)
787 {
788 ok(0, "unexpected call\n");
789 return E_NOTIMPL;
790 }
791
792 static HRESULT STDMETHODCALLTYPE Test_Stream_Stat(IStream *iface, STATSTG *pstatstg,
793 DWORD grfStatFlag)
794 {
795 ok(0, "unexpected call\n");
796 return E_NOTIMPL;
797 }
798
799 static HRESULT STDMETHODCALLTYPE Test_Stream_Clone(IStream *iface, IStream **ppstm)
800 {
801 ok(0, "unexpected call\n");
802 return E_NOTIMPL;
803 }
804
805 static const IStreamVtbl Test_Stream_Vtbl =
806 {
807 Test_Stream_QueryInterface,
808 Test_Stream_AddRef,
809 Test_Stream_Release,
810 Test_Stream_Read,
811 Test_Stream_Write,
812 Test_Stream_Seek,
813 Test_Stream_SetSize,
814 Test_Stream_CopyTo,
815 Test_Stream_Commit,
816 Test_Stream_Revert,
817 Test_Stream_LockRegion,
818 Test_Stream_UnlockRegion,
819 Test_Stream_Stat,
820 Test_Stream_Clone
821 };
822
823 static struct my_IStream Test_Stream = { { &Test_Stream_Vtbl }, 0, 0 };
824
825 static INT DIB_GetWidthBytes( int width, int bpp )
826 {
827 return ((width * bpp + 31) / 8) & ~3;
828 }
829
830 static ULONG check_bitmap_data(const char *bm_data, ULONG bm_data_size,
831 INT width, INT height, INT bpp,
832 const char *comment)
833 {
834 const BITMAPFILEHEADER *bmfh = (const BITMAPFILEHEADER *)bm_data;
835 const BITMAPINFOHEADER *bmih = (const BITMAPINFOHEADER *)(bm_data + sizeof(*bmfh));
836 ULONG hdr_size, image_size;
837
838 hdr_size = sizeof(*bmfh) + sizeof(*bmih);
839 if (bmih->biBitCount <= 8) hdr_size += (1 << bpp) * sizeof(RGBQUAD);
840
841 ok(bmfh->bfType == (('M' << 8) | 'B'), "wrong bfType 0x%02x\n", bmfh->bfType);
842 ok(bmfh->bfSize == hdr_size, "wrong bfSize 0x%02x\n", bmfh->bfSize);
843 ok(bmfh->bfReserved1 == 0, "wrong bfReserved1 0x%02x\n", bmfh->bfReserved1);
844 ok(bmfh->bfReserved2 == 0, "wrong bfReserved2 0x%02x\n", bmfh->bfReserved2);
845 ok(bmfh->bfOffBits == hdr_size, "wrong bfOffBits 0x%02x\n", bmfh->bfOffBits);
846
847 ok(bmih->biSize == sizeof(*bmih), "wrong biSize %d\n", bmih->biSize);
848 ok(bmih->biWidth == width, "wrong biWidth %d (expected %d)\n", bmih->biWidth, width);
849 ok(bmih->biHeight == height, "wrong biHeight %d (expected %d)\n", bmih->biHeight, height);
850 ok(bmih->biPlanes == 1, "wrong biPlanes %d\n", bmih->biPlanes);
851 ok(bmih->biBitCount == bpp, "wrong biBitCount %d\n", bmih->biBitCount);
852
853 image_size = DIB_GetWidthBytes(bmih->biWidth, bmih->biBitCount) * bmih->biHeight;
854 ok(bmih->biSizeImage == image_size, "wrong biSizeImage %u\n", bmih->biSizeImage);
855
856 if (0)
857 {
858 char fname[256];
859 FILE *f;
860 sprintf(fname, "bmp_%s.bmp", comment);
861 f = fopen(fname, "wb");
862 fwrite(bm_data, 1, bm_data_size, f);
863 fclose(f);
864 }
865
866 return hdr_size + image_size;
867 }
868
869 static void check_ilhead_data(const char *ilh_data, INT cx, INT cy, INT cur, INT max, INT grow, INT flags)
870 {
871 const ILHEAD *ilh = (const ILHEAD *)ilh_data;
872
873 ok(ilh->usMagic == IMAGELIST_MAGIC, "wrong usMagic %4x (expected %02x)\n", ilh->usMagic, IMAGELIST_MAGIC);
874 ok(ilh->usVersion == 0x101, "wrong usVersion %x (expected 0x101)\n", ilh->usVersion);
875 ok(ilh->cCurImage == cur, "wrong cCurImage %d (expected %d)\n", ilh->cCurImage, cur);
876 ok(ilh->cMaxImage == max, "wrong cMaxImage %d (expected %d)\n", ilh->cMaxImage, max);
877 ok(ilh->cGrow == grow, "wrong cGrow %d (expected %d)\n", ilh->cGrow, grow);
878 ok(ilh->cx == cx, "wrong cx %d (expected %d)\n", ilh->cx, cx);
879 ok(ilh->cy == cy, "wrong cy %d (expected %d)\n", ilh->cy, cy);
880 ok(ilh->bkcolor == CLR_NONE, "wrong bkcolor %x\n", ilh->bkcolor);
881 ok(ilh->flags == flags || broken(!(ilh->flags & 0xfe) && (flags & 0xfe) == ILC_COLOR4), /* <= w2k */
882 "wrong flags %04x\n", ilh->flags);
883 ok(ilh->ovls[0] == -1, "wrong ovls[0] %04x\n", ilh->ovls[0]);
884 ok(ilh->ovls[1] == -1, "wrong ovls[1] %04x\n", ilh->ovls[1]);
885 ok(ilh->ovls[2] == -1, "wrong ovls[2] %04x\n", ilh->ovls[2]);
886 ok(ilh->ovls[3] == -1, "wrong ovls[3] %04x\n", ilh->ovls[3]);
887 }
888
889 static HBITMAP create_bitmap(INT cx, INT cy, COLORREF color, const char *comment)
890 {
891 HDC hdc;
892 BITMAPINFO bmi;
893 HBITMAP hbmp, hbmp_old;
894 HBRUSH hbrush;
895 RECT rc = { 0, 0, cx, cy };
896
897 hdc = CreateCompatibleDC(0);
898
899 memset(&bmi, 0, sizeof(bmi));
900 bmi.bmiHeader.biSize = sizeof(bmi.bmiHeader);
901 bmi.bmiHeader.biHeight = cx;
902 bmi.bmiHeader.biWidth = cy;
903 bmi.bmiHeader.biBitCount = 24;
904 bmi.bmiHeader.biPlanes = 1;
905 bmi.bmiHeader.biCompression = BI_RGB;
906 hbmp = CreateDIBSection(hdc, &bmi, DIB_RGB_COLORS, NULL, NULL, 0);
907
908 hbmp_old = SelectObject(hdc, hbmp);
909
910 hbrush = CreateSolidBrush(color);
911 FillRect(hdc, &rc, hbrush);
912 DeleteObject(hbrush);
913
914 DrawTextA(hdc, comment, -1, &rc, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
915
916 SelectObject(hdc, hbmp_old);
917 DeleteDC(hdc);
918
919 return hbmp;
920 }
921
922 #define iml_clear_stream_data() \
923 HeapFree(GetProcessHeap(), 0, Test_Stream.iml_data); \
924 Test_Stream.iml_data = NULL; \
925 Test_Stream.iml_data_size = 0;
926
927 static void check_iml_data(HIMAGELIST himl, INT cx, INT cy, INT cur, INT max, INT grow,
928 INT width, INT height, INT flags, const char *comment)
929 {
930 INT ret, cxx, cyy, size;
931
932 trace("%s\n", comment);
933
934 ret = ImageList_GetImageCount(himl);
935 ok(ret == cur, "expected image count %d got %d\n", cur, ret);
936
937 ret = ImageList_GetIconSize(himl, &cxx, &cyy);
938 ok(ret, "ImageList_GetIconSize failed\n");
939 ok(cxx == cx, "wrong cx %d (expected %d)\n", cxx, cx);
940 ok(cyy == cy, "wrong cy %d (expected %d)\n", cyy, cy);
941
942 iml_clear_stream_data();
943 ret = ImageList_Write(himl, &Test_Stream.IStream_iface);
944 ok(ret, "ImageList_Write failed\n");
945
946 ok(Test_Stream.iml_data != 0, "ImageList_Write didn't write any data\n");
947 ok(Test_Stream.iml_data_size > sizeof(ILHEAD), "ImageList_Write wrote not enough data\n");
948
949 check_ilhead_data(Test_Stream.iml_data, cx, cy, cur, max, grow, flags);
950 size = check_bitmap_data(Test_Stream.iml_data + sizeof(ILHEAD),
951 Test_Stream.iml_data_size - sizeof(ILHEAD),
952 width, height, flags & 0xfe, comment);
953 if (size < Test_Stream.iml_data_size - sizeof(ILHEAD)) /* mask is present */
954 {
955 ok( flags & ILC_MASK, "extra data %u/%u but mask not expected\n",
956 Test_Stream.iml_data_size, size );
957 check_bitmap_data(Test_Stream.iml_data + sizeof(ILHEAD) + size,
958 Test_Stream.iml_data_size - sizeof(ILHEAD) - size,
959 width, height, 1, comment);
960 }
961 }
962
963 static void image_list_init(HIMAGELIST himl)
964 {
965 HBITMAP hbm;
966 char comment[16];
967 INT n = 1;
968 DWORD i;
969 static const struct test_data
970 {
971 BYTE grey;
972 INT cx, cy, cur, max, grow, width, height, bpp;
973 const char *comment;
974 } td[] =
975 {
976 { 255, BMP_CX, BMP_CX, 1, 2, 4, BMP_CX * 4, BMP_CX * 1, 24, "total 1" },
977 { 170, BMP_CX, BMP_CX, 2, 7, 4, BMP_CX * 4, BMP_CX * 2, 24, "total 2" },
978 { 85, BMP_CX, BMP_CX, 3, 7, 4, BMP_CX * 4, BMP_CX * 2, 24, "total 3" },
979 { 0, BMP_CX, BMP_CX, 4, 7, 4, BMP_CX * 4, BMP_CX * 2, 24, "total 4" },
980 { 0, BMP_CX, BMP_CX, 5, 7, 4, BMP_CX * 4, BMP_CX * 2, 24, "total 5" },
981 { 85, BMP_CX, BMP_CX, 6, 7, 4, BMP_CX * 4, BMP_CX * 2, 24, "total 6" },
982 { 170, BMP_CX, BMP_CX, 7, 12, 4, BMP_CX * 4, BMP_CX * 3, 24, "total 7" },
983 { 255, BMP_CX, BMP_CX, 8, 12, 4, BMP_CX * 4, BMP_CX * 3, 24, "total 8" },
984 { 255, BMP_CX, BMP_CX, 9, 12, 4, BMP_CX * 4, BMP_CX * 3, 24, "total 9" },
985 { 170, BMP_CX, BMP_CX, 10, 12, 4, BMP_CX * 4, BMP_CX * 3, 24, "total 10" },
986 { 85, BMP_CX, BMP_CX, 11, 12, 4, BMP_CX * 4, BMP_CX * 3, 24, "total 11" },
987 { 0, BMP_CX, BMP_CX, 12, 17, 4, BMP_CX * 4, BMP_CX * 5, 24, "total 12" },
988 { 0, BMP_CX, BMP_CX, 13, 17, 4, BMP_CX * 4, BMP_CX * 5, 24, "total 13" },
989 { 85, BMP_CX, BMP_CX, 14, 17, 4, BMP_CX * 4, BMP_CX * 5, 24, "total 14" },
990 { 170, BMP_CX, BMP_CX, 15, 17, 4, BMP_CX * 4, BMP_CX * 5, 24, "total 15" },
991 { 255, BMP_CX, BMP_CX, 16, 17, 4, BMP_CX * 4, BMP_CX * 5, 24, "total 16" },
992 { 255, BMP_CX, BMP_CX, 17, 22, 4, BMP_CX * 4, BMP_CX * 6, 24, "total 17" },
993 { 170, BMP_CX, BMP_CX, 18, 22, 4, BMP_CX * 4, BMP_CX * 6, 24, "total 18" },
994 { 85, BMP_CX, BMP_CX, 19, 22, 4, BMP_CX * 4, BMP_CX * 6, 24, "total 19" },
995 { 0, BMP_CX, BMP_CX, 20, 22, 4, BMP_CX * 4, BMP_CX * 6, 24, "total 20" },
996 { 0, BMP_CX, BMP_CX, 21, 22, 4, BMP_CX * 4, BMP_CX * 6, 24, "total 21" },
997 { 85, BMP_CX, BMP_CX, 22, 27, 4, BMP_CX * 4, BMP_CX * 7, 24, "total 22" },
998 { 170, BMP_CX, BMP_CX, 23, 27, 4, BMP_CX * 4, BMP_CX * 7, 24, "total 23" },
999 { 255, BMP_CX, BMP_CX, 24, 27, 4, BMP_CX * 4, BMP_CX * 7, 24, "total 24" }
1000 };
1001
1002 check_iml_data(himl, BMP_CX, BMP_CX, 0, 2, 4, BMP_CX * 4, BMP_CX * 1, ILC_COLOR24, "total 0");
1003
1004 #define add_bitmap(grey) \
1005 sprintf(comment, "%d", n++); \
1006 hbm = create_bitmap(BMP_CX, BMP_CX, RGB((grey),(grey),(grey)), comment); \
1007 ImageList_Add(himl, hbm, NULL); \
1008 DeleteObject(hbm);
1009
1010 for (i = 0; i < sizeof(td)/sizeof(td[0]); i++)
1011 {
1012 add_bitmap(td[i].grey);
1013 check_iml_data(himl, td[i].cx, td[i].cy, td[i].cur, td[i].max, td[i].grow,
1014 td[i].width, td[i].height, td[i].bpp, td[i].comment);
1015 }
1016 #undef add_bitmap
1017 }
1018
1019 static void test_imagelist_storage(void)
1020 {
1021 HIMAGELIST himl;
1022 HBITMAP hbm;
1023 HICON icon;
1024 INT ret;
1025
1026 himl = ImageList_Create(BMP_CX, BMP_CX, ILC_COLOR24, 1, 1);
1027 ok(himl != 0, "ImageList_Create failed\n");
1028
1029 check_iml_data(himl, BMP_CX, BMP_CX, 0, 2, 4, BMP_CX * 4, BMP_CX * 1, ILC_COLOR24, "empty");
1030
1031 image_list_init(himl);
1032 check_iml_data(himl, BMP_CX, BMP_CX, 24, 27, 4, BMP_CX * 4, BMP_CX * 7, ILC_COLOR24, "orig");
1033
1034 ret = ImageList_Remove(himl, 4);
1035 ok(ret, "ImageList_Remove failed\n");
1036 check_iml_data(himl, BMP_CX, BMP_CX, 23, 27, 4, BMP_CX * 4, BMP_CX * 7, ILC_COLOR24, "1");
1037
1038 ret = ImageList_Remove(himl, 5);
1039 ok(ret, "ImageList_Remove failed\n");
1040 check_iml_data(himl, BMP_CX, BMP_CX, 22, 27, 4, BMP_CX * 4, BMP_CX * 7, ILC_COLOR24, "2");
1041
1042 ret = ImageList_Remove(himl, 6);
1043 ok(ret, "ImageList_Remove failed\n");
1044 check_iml_data(himl, BMP_CX, BMP_CX, 21, 27, 4, BMP_CX * 4, BMP_CX * 7, ILC_COLOR24, "3");
1045
1046 ret = ImageList_Remove(himl, 7);
1047 ok(ret, "ImageList_Remove failed\n");
1048 check_iml_data(himl, BMP_CX, BMP_CX, 20, 27, 4, BMP_CX * 4, BMP_CX * 7, ILC_COLOR24, "4");
1049
1050 ret = ImageList_Remove(himl, -2);
1051 ok(!ret, "ImageList_Remove(-2) should fail\n");
1052 check_iml_data(himl, BMP_CX, BMP_CX, 20, 27, 4, BMP_CX * 4, BMP_CX * 7, ILC_COLOR24, "5");
1053
1054 ret = ImageList_Remove(himl, 20);
1055 ok(!ret, "ImageList_Remove(20) should fail\n");
1056 check_iml_data(himl, BMP_CX, BMP_CX, 20, 27, 4, BMP_CX * 4, BMP_CX * 7, ILC_COLOR24, "6");
1057
1058 ret = ImageList_Remove(himl, -1);
1059 ok(ret, "ImageList_Remove(-1) failed\n");
1060 check_iml_data(himl, BMP_CX, BMP_CX, 0, 4, 4, BMP_CX * 4, BMP_CX * 1, ILC_COLOR24, "7");
1061
1062 ret = ImageList_Destroy(himl);
1063 ok(ret, "ImageList_Destroy failed\n");
1064
1065 iml_clear_stream_data();
1066
1067 /* test ImageList_Create storage allocation */
1068
1069 himl = ImageList_Create(BMP_CX, BMP_CX, ILC_COLOR24, 0, 32);
1070 ok(himl != 0, "ImageList_Create failed\n");
1071 check_iml_data(himl, BMP_CX, BMP_CX, 0, 1, 32, BMP_CX * 4, BMP_CX * 1, ILC_COLOR24, "init 0 grow 32");
1072 hbm = create_bitmap(BMP_CX * 9, BMP_CX, 0, "9");
1073 ret = ImageList_Add(himl, hbm, NULL);
1074 ok(ret == 0, "ImageList_Add returned %d, expected 0\n", ret);
1075 check_iml_data(himl, BMP_CX, BMP_CX, 1, 34, 32, BMP_CX * 4, BMP_CX * 9, ILC_COLOR24, "add 1 x 9");
1076 DeleteObject(hbm);
1077 ret = ImageList_Destroy(himl);
1078 ok(ret, "ImageList_Destroy failed\n");
1079 iml_clear_stream_data();
1080
1081 himl = ImageList_Create(BMP_CX, BMP_CX, ILC_COLOR24, 4, 4);
1082 ok(himl != 0, "ImageList_Create failed\n");
1083 check_iml_data(himl, BMP_CX, BMP_CX, 0, 5, 4, BMP_CX * 4, BMP_CX * 2, ILC_COLOR24, "init 4 grow 4");
1084 hbm = create_bitmap(BMP_CX, BMP_CX * 9, 0, "9");
1085 ret = ImageList_Add(himl, hbm, NULL);
1086 ok(ret == 0, "ImageList_Add returned %d, expected 0\n", ret);
1087 check_iml_data(himl, BMP_CX, BMP_CX, 9, 15, 4, BMP_CX * 4, BMP_CX * 4, ILC_COLOR24, "add 9 x 1");
1088 ret = ImageList_Add(himl, hbm, NULL);
1089 ok(ret == 9, "ImageList_Add returned %d, expected 9\n", ret);
1090 check_iml_data(himl, BMP_CX, BMP_CX, 18, 25, 4, BMP_CX * 4, BMP_CX * 7, ILC_COLOR24, "add 9 x 1");
1091 DeleteObject(hbm);
1092 ret = ImageList_Destroy(himl);
1093 ok(ret, "ImageList_Destroy failed\n");
1094 iml_clear_stream_data();
1095
1096 himl = ImageList_Create(BMP_CX, BMP_CX, ILC_COLOR24, 207, 209);
1097 ok(himl != 0, "ImageList_Create failed\n");
1098 check_iml_data(himl, BMP_CX, BMP_CX, 0, 208, 212, BMP_CX * 4, BMP_CX * 52, ILC_COLOR24, "init 207 grow 209");
1099 ret = ImageList_Destroy(himl);
1100 ok(ret, "ImageList_Destroy failed\n");
1101 iml_clear_stream_data();
1102
1103 himl = ImageList_Create(BMP_CX, BMP_CX, ILC_COLOR24, 209, 207);
1104 ok(himl != 0, "ImageList_Create failed\n");
1105 check_iml_data(himl, BMP_CX, BMP_CX, 0, 210, 208, BMP_CX * 4, BMP_CX * 53, ILC_COLOR24, "init 209 grow 207");
1106 ret = ImageList_Destroy(himl);
1107 ok(ret, "ImageList_Destroy failed\n");
1108 iml_clear_stream_data();
1109
1110 himl = ImageList_Create(BMP_CX, BMP_CX, ILC_COLOR24, 14, 4);
1111 ok(himl != 0, "ImageList_Create failed\n");
1112 check_iml_data(himl, BMP_CX, BMP_CX, 0, 15, 4, BMP_CX * 4, BMP_CX * 4, ILC_COLOR24, "init 14 grow 4");
1113 ret = ImageList_Destroy(himl);
1114 ok(ret, "ImageList_Destroy failed\n");
1115 iml_clear_stream_data();
1116
1117 himl = ImageList_Create(BMP_CX, BMP_CX, ILC_COLOR24, 5, 9);
1118 ok(himl != 0, "ImageList_Create failed\n");
1119 check_iml_data(himl, BMP_CX, BMP_CX, 0, 6, 12, BMP_CX * 4, BMP_CX * 2, ILC_COLOR24, "init 5 grow 9");
1120 ret = ImageList_Destroy(himl);
1121 ok(ret, "ImageList_Destroy failed\n");
1122 iml_clear_stream_data();
1123
1124 himl = ImageList_Create(BMP_CX, BMP_CX, ILC_COLOR24, 9, 5);
1125 ok(himl != 0, "ImageList_Create failed\n");
1126 check_iml_data(himl, BMP_CX, BMP_CX, 0, 10, 8, BMP_CX * 4, BMP_CX * 3, ILC_COLOR24, "init 9 grow 5");
1127 ret = ImageList_Destroy(himl);
1128 ok(ret, "ImageList_Destroy failed\n");
1129 iml_clear_stream_data();
1130
1131 himl = ImageList_Create(BMP_CX, BMP_CX, ILC_COLOR24, 2, 4);
1132 ok(himl != 0, "ImageList_Create failed\n");
1133 check_iml_data(himl, BMP_CX, BMP_CX, 0, 3, 4, BMP_CX * 4, BMP_CX * 1, ILC_COLOR24, "init 2 grow 4");
1134 ret = ImageList_Destroy(himl);
1135 ok(ret, "ImageList_Destroy failed\n");
1136 iml_clear_stream_data();
1137
1138 himl = ImageList_Create(BMP_CX, BMP_CX, ILC_COLOR24, 4, 2);
1139 ok(himl != 0, "ImageList_Create failed\n");
1140 check_iml_data(himl, BMP_CX, BMP_CX, 0, 5, 4, BMP_CX * 4, BMP_CX * 2, ILC_COLOR24, "init 4 grow 2");
1141 ret = ImageList_Destroy(himl);
1142 ok(ret, "ImageList_Destroy failed\n");
1143 iml_clear_stream_data();
1144
1145 himl = ImageList_Create(BMP_CX, BMP_CX, ILC_COLOR8, 4, 2);
1146 ok(himl != 0, "ImageList_Create failed\n");
1147 check_iml_data(himl, BMP_CX, BMP_CX, 0, 5, 4, BMP_CX * 4, BMP_CX * 2, ILC_COLOR8, "bpp 8");
1148 ret = ImageList_Destroy(himl);
1149 ok(ret, "ImageList_Destroy failed\n");
1150 iml_clear_stream_data();
1151
1152 himl = ImageList_Create(BMP_CX, BMP_CX, ILC_COLOR4, 4, 2);
1153 ok(himl != 0, "ImageList_Create failed\n");
1154 check_iml_data(himl, BMP_CX, BMP_CX, 0, 5, 4, BMP_CX * 4, BMP_CX * 2, ILC_COLOR4, "bpp 4");
1155 ret = ImageList_Destroy(himl);
1156 ok(ret, "ImageList_Destroy failed\n");
1157 iml_clear_stream_data();
1158
1159 himl = ImageList_Create(BMP_CX, BMP_CX, 0, 4, 2);
1160 ok(himl != 0, "ImageList_Create failed\n");
1161 check_iml_data(himl, BMP_CX, BMP_CX, 0, 5, 4, BMP_CX * 4, BMP_CX * 2, ILC_COLOR4, "bpp default");
1162 icon = CreateIcon(hinst, 32, 32, 1, 1, icon_bits, icon_bits);
1163 ok( ImageList_AddIcon(himl, icon) == 0,"failed to add icon\n");
1164 ok( ImageList_AddIcon(himl, icon) == 1,"failed to add icon\n");
1165 DestroyIcon( icon );
1166 check_iml_data(himl, BMP_CX, BMP_CX, 2, 5, 4, BMP_CX * 4, BMP_CX * 2, ILC_COLOR4, "bpp default");
1167 ret = ImageList_Destroy(himl);
1168 ok(ret, "ImageList_Destroy failed\n");
1169 iml_clear_stream_data();
1170
1171 himl = ImageList_Create(BMP_CX, BMP_CX, ILC_COLOR24|ILC_MASK, 4, 2);
1172 ok(himl != 0, "ImageList_Create failed\n");
1173 check_iml_data(himl, BMP_CX, BMP_CX, 0, 5, 4, BMP_CX * 4, BMP_CX * 2, ILC_COLOR24|ILC_MASK,
1174 "bpp 24 + mask");
1175 icon = CreateIcon(hinst, 32, 32, 1, 1, icon_bits, icon_bits);
1176 ok( ImageList_AddIcon(himl, icon) == 0,"failed to add icon\n");
1177 ok( ImageList_AddIcon(himl, icon) == 1,"failed to add icon\n");
1178 DestroyIcon( icon );
1179 check_iml_data(himl, BMP_CX, BMP_CX, 2, 5, 4, BMP_CX * 4, BMP_CX * 2, ILC_COLOR24|ILC_MASK,
1180 "bpp 24 + mask");
1181 ret = ImageList_Destroy(himl);
1182 ok(ret, "ImageList_Destroy failed\n");
1183 iml_clear_stream_data();
1184
1185 himl = ImageList_Create(BMP_CX, BMP_CX, ILC_COLOR4|ILC_MASK, 4, 2);
1186 ok(himl != 0, "ImageList_Create failed\n");
1187 check_iml_data(himl, BMP_CX, BMP_CX, 0, 5, 4, BMP_CX * 4, BMP_CX * 2, ILC_COLOR4|ILC_MASK,
1188 "bpp 4 + mask");
1189 icon = CreateIcon(hinst, 32, 32, 1, 1, icon_bits, icon_bits);
1190 ok( ImageList_AddIcon(himl, icon) == 0,"failed to add icon\n");
1191 ok( ImageList_AddIcon(himl, icon) == 1,"failed to add icon\n");
1192 DestroyIcon( icon );
1193 check_iml_data(himl, BMP_CX, BMP_CX, 2, 5, 4, BMP_CX * 4, BMP_CX * 2, ILC_COLOR4|ILC_MASK,
1194 "bpp 4 + mask");
1195 ret = ImageList_Destroy(himl);
1196 ok(ret, "ImageList_Destroy failed\n");
1197 iml_clear_stream_data();
1198
1199 himl = ImageList_Create(BMP_CX, BMP_CX, ILC_COLOR4|ILC_MASK, 2, 99);
1200 ok(himl != 0, "ImageList_Create failed\n");
1201 check_iml_data(himl, BMP_CX, BMP_CX, 0, 3, 100, BMP_CX * 4, BMP_CX, ILC_COLOR4|ILC_MASK,
1202 "init 2 grow 99");
1203 icon = CreateIcon(hinst, 32, 32, 1, 1, icon_bits, icon_bits);
1204 ok( ImageList_AddIcon(himl, icon) == 0,"failed to add icon\n");
1205 ok( ImageList_AddIcon(himl, icon) == 1,"failed to add icon\n");
1206 check_iml_data(himl, BMP_CX, BMP_CX, 2, 3, 100, BMP_CX * 4, BMP_CX, ILC_COLOR4|ILC_MASK,
1207 "init 2 grow 99 2 icons");
1208 ok( ImageList_AddIcon(himl, icon) == 2,"failed to add icon\n");
1209 DestroyIcon( icon );
1210 check_iml_data(himl, BMP_CX, BMP_CX, 3, 104, 100, BMP_CX * 4, BMP_CX * 104/4, ILC_COLOR4|ILC_MASK,
1211 "init 2 grow 99 3 icons");
1212 ok( ImageList_Remove(himl, -1) == TRUE,"failed to remove icon\n");
1213 check_iml_data(himl, BMP_CX, BMP_CX, 0, 100, 100, BMP_CX * 4, BMP_CX * 100/4, ILC_COLOR4|ILC_MASK,
1214 "init 2 grow 99 empty");
1215 ok( ImageList_SetImageCount(himl, 22) == TRUE,"failed to set image count\n");
1216 check_iml_data(himl, BMP_CX, BMP_CX, 22, 23, 100, BMP_CX * 4, BMP_CX * 24/4, ILC_COLOR4|ILC_MASK,
1217 "init 2 grow 99 set count 22");
1218 ok( ImageList_SetImageCount(himl, 0) == TRUE,"failed to set image count\n");
1219 check_iml_data(himl, BMP_CX, BMP_CX, 0, 1, 100, BMP_CX * 4, BMP_CX, ILC_COLOR4|ILC_MASK,
1220 "init 2 grow 99 set count 0");
1221 ok( ImageList_SetImageCount(himl, 42) == TRUE,"failed to set image count\n");
1222 check_iml_data(himl, BMP_CX, BMP_CX, 42, 43, 100, BMP_CX * 4, BMP_CX * 44/4, ILC_COLOR4|ILC_MASK,
1223 "init 2 grow 99 set count 42");
1224 ret = ImageList_Destroy(himl);
1225 ok(ret, "ImageList_Destroy failed\n");
1226 iml_clear_stream_data();
1227
1228 himl = ImageList_Create(BMP_CX, BMP_CX, ILC_COLOR4|ILC_MASK, 2, 65536+12);
1229 ok(himl != 0, "ImageList_Create failed\n");
1230 check_iml_data(himl, BMP_CX, BMP_CX, 0, 3, 12, BMP_CX * 4, BMP_CX, ILC_COLOR4|ILC_MASK,
1231 "init 2 grow 65536+12");
1232 ret = ImageList_Destroy(himl);
1233 ok(ret, "ImageList_Destroy failed\n");
1234 iml_clear_stream_data();
1235
1236 himl = ImageList_Create(BMP_CX, BMP_CX, ILC_COLOR4|ILC_MASK, 2, 65535);
1237 ok(himl != 0, "ImageList_Create failed\n");
1238 check_iml_data(himl, BMP_CX, BMP_CX, 0, 3, 0, BMP_CX * 4, BMP_CX, ILC_COLOR4|ILC_MASK,
1239 "init 2 grow 65535");
1240 ret = ImageList_Destroy(himl);
1241 ok(ret, "ImageList_Destroy failed\n");
1242 iml_clear_stream_data();
1243
1244 himl = ImageList_Create(BMP_CX, BMP_CX, ILC_COLOR4|ILC_MASK, 2, -20);
1245 ok(himl != 0, "ImageList_Create failed\n");
1246 check_iml_data(himl, BMP_CX, BMP_CX, 0, 3, 4, BMP_CX * 4, BMP_CX, ILC_COLOR4|ILC_MASK,
1247 "init 2 grow -20");
1248 ret = ImageList_Destroy(himl);
1249 ok(ret, "ImageList_Destroy failed\n");
1250 iml_clear_stream_data();
1251 }
1252
1253 static void test_shell_imagelist(void)
1254 {
1255 HRESULT (WINAPI *pSHGetImageList)(INT, REFIID, void**);
1256 IImageList *iml = NULL;
1257 HMODULE hShell32;
1258 HRESULT hr;
1259 int out = 0;
1260 RECT rect;
1261 int cx, cy;
1262
1263 /* Try to load function from shell32 */
1264 hShell32 = LoadLibraryA("shell32.dll");
1265 pSHGetImageList = (void*)GetProcAddress(hShell32, (LPCSTR) 727);
1266
1267 if (!pSHGetImageList)
1268 {
1269 win_skip("SHGetImageList not available, skipping test\n");
1270 FreeLibrary(hShell32);
1271 return;
1272 }
1273
1274 /* Get system image list */
1275 hr = pSHGetImageList(SHIL_SYSSMALL, &IID_IImageList, (void**)&iml);
1276 ok(SUCCEEDED(hr), "SHGetImageList failed, hr=%x\n", hr);
1277
1278 if (hr != S_OK) {
1279 FreeLibrary(hShell32);
1280 return;
1281 }
1282
1283 IImageList_GetImageCount(iml, &out);
1284 ok(out > 0, "IImageList_GetImageCount returned out <= 0\n");
1285
1286 /* Fetch the small icon size */
1287 cx = GetSystemMetrics(SM_CXSMICON);
1288 cy = GetSystemMetrics(SM_CYSMICON);
1289
1290 /* Check icon size matches */
1291 IImageList_GetImageRect(iml, 0, &rect);
1292 ok(((rect.right == cx) && (rect.bottom == cy)),
1293 "IImageList_GetImageRect returned r:%d,b:%d\n",
1294 rect.right, rect.bottom);
1295
1296 IImageList_Release(iml);
1297 FreeLibrary(hShell32);
1298 }
1299
1300 static HBITMAP create_test_bitmap(HDC hdc, int bpp, UINT32 pixel1, UINT32 pixel2)
1301 {
1302 HBITMAP hBitmap;
1303 UINT32 *buffer = NULL;
1304 BITMAPINFO bitmapInfo = {{sizeof(BITMAPINFOHEADER), 2, 1, 1, bpp, BI_RGB,
1305 0, 0, 0, 0, 0}};
1306
1307 hBitmap = CreateDIBSection(hdc, &bitmapInfo, DIB_RGB_COLORS, (void**)&buffer, NULL, 0);
1308 ok(hBitmap != NULL && buffer != NULL, "CreateDIBSection failed.\n");
1309
1310 if(!hBitmap || !buffer)
1311 {
1312 DeleteObject(hBitmap);
1313 return NULL;
1314 }
1315
1316 buffer[0] = pixel1;
1317 buffer[1] = pixel2;
1318
1319 return hBitmap;
1320 }
1321
1322 static BOOL colour_match(UINT32 x, UINT32 y)
1323 {
1324 const INT32 tolerance = 8;
1325
1326 const INT32 dr = abs((INT32)(x & 0x000000FF) - (INT32)(y & 0x000000FF));
1327 const INT32 dg = abs((INT32)((x & 0x0000FF00) >> 8) - (INT32)((y & 0x0000FF00) >> 8));
1328 const INT32 db = abs((INT32)((x & 0x00FF0000) >> 16) - (INT32)((y & 0x00FF0000) >> 16));
1329
1330 return (dr <= tolerance && dg <= tolerance && db <= tolerance);
1331 }
1332
1333 static void check_ImageList_DrawIndirect(IMAGELISTDRAWPARAMS *ildp, UINT32 *bits,
1334 UINT32 expected, int line)
1335 {
1336 bits[0] = 0x00FFFFFF;
1337 pImageList_DrawIndirect(ildp);
1338 ok(colour_match(bits[0], expected),
1339 "ImageList_DrawIndirect: Pixel %08X, Expected a close match to %08X from line %d\n",
1340 bits[0] & 0x00FFFFFF, expected, line);
1341 }
1342
1343
1344 static void check_ImageList_DrawIndirect_fStyle(HDC hdc, HIMAGELIST himl, UINT32 *bits, int i,
1345 UINT fStyle, UINT32 expected, int line)
1346 {
1347 IMAGELISTDRAWPARAMS ildp = {sizeof(IMAGELISTDRAWPARAMS), himl, i, hdc,
1348 0, 0, 0, 0, 0, 0, CLR_NONE, CLR_NONE, fStyle, 0, ILS_NORMAL, 0, 0x00000000};
1349 check_ImageList_DrawIndirect(&ildp, bits, expected, line);
1350 }
1351
1352 static void check_ImageList_DrawIndirect_ILD_ROP(HDC hdc, HIMAGELIST himl, UINT32 *bits, int i,
1353 DWORD dwRop, UINT32 expected, int line)
1354 {
1355 IMAGELISTDRAWPARAMS ildp = {sizeof(IMAGELISTDRAWPARAMS), himl, i, hdc,
1356 0, 0, 0, 0, 0, 0, CLR_NONE, CLR_NONE, ILD_IMAGE | ILD_ROP, dwRop, ILS_NORMAL, 0, 0x00000000};
1357 check_ImageList_DrawIndirect(&ildp, bits, expected, line);
1358 }
1359
1360 static void check_ImageList_DrawIndirect_fState(HDC hdc, HIMAGELIST himl, UINT32 *bits, int i, UINT fStyle,
1361 UINT fState, DWORD Frame, UINT32 expected, int line)
1362 {
1363 IMAGELISTDRAWPARAMS ildp = {sizeof(IMAGELISTDRAWPARAMS), himl, i, hdc,
1364 0, 0, 0, 0, 0, 0, CLR_NONE, CLR_NONE, fStyle, 0, fState, Frame, 0x00000000};
1365 check_ImageList_DrawIndirect(&ildp, bits, expected, line);
1366 }
1367
1368 static void check_ImageList_DrawIndirect_broken(HDC hdc, HIMAGELIST himl, UINT32 *bits, int i,
1369 UINT fStyle, UINT fState, DWORD Frame, UINT32 expected,
1370 UINT32 broken_expected, int line)
1371 {
1372 IMAGELISTDRAWPARAMS ildp = {sizeof(IMAGELISTDRAWPARAMS), himl, i, hdc,
1373 0, 0, 0, 0, 0, 0, CLR_NONE, CLR_NONE, fStyle, 0, fState, Frame, 0x00000000};
1374 bits[0] = 0x00FFFFFF;
1375 pImageList_DrawIndirect(&ildp);
1376 ok(colour_match(bits[0], expected) ||
1377 broken(colour_match(bits[0], broken_expected)),
1378 "ImageList_DrawIndirect: Pixel %08X, Expected a close match to %08X from line %d\n",
1379 bits[0] & 0x00FFFFFF, expected, line);
1380 }
1381
1382 static void test_ImageList_DrawIndirect(void)
1383 {
1384 HIMAGELIST himl = NULL;
1385 int ret;
1386 HDC hdcDst = NULL;
1387 HBITMAP hbmOld = NULL, hbmDst = NULL;
1388 HBITMAP hbmMask = NULL, hbmInverseMask = NULL;
1389 HBITMAP hbmImage = NULL, hbmAlphaImage = NULL, hbmTransparentImage = NULL;
1390 int iImage = -1, iAlphaImage = -1, iTransparentImage = -1;
1391 UINT32 *bits = 0;
1392 UINT32 maskBits = 0x00000000, inverseMaskBits = 0xFFFFFFFF;
1393 int bpp, broken_value;
1394
1395 BITMAPINFO bitmapInfo = {{sizeof(BITMAPINFOHEADER), 2, 1, 1, 32, BI_RGB,
1396 0, 0, 0, 0, 0}};
1397
1398 hdcDst = CreateCompatibleDC(0);
1399 ok(hdcDst != 0, "CreateCompatibleDC(0) failed to return a valid DC\n");
1400 if (!hdcDst)
1401 return;
1402 bpp = GetDeviceCaps(hdcDst, BITSPIXEL);
1403
1404 hbmMask = CreateBitmap(2, 1, 1, 1, &maskBits);
1405 ok(hbmMask != 0, "CreateBitmap failed\n");
1406 if(!hbmMask) goto cleanup;
1407
1408 hbmInverseMask = CreateBitmap(2, 1, 1, 1, &inverseMaskBits);
1409 ok(hbmInverseMask != 0, "CreateBitmap failed\n");
1410 if(!hbmInverseMask) goto cleanup;
1411
1412 himl = pImageList_Create(2, 1, ILC_COLOR32, 0, 1);
1413 ok(himl != 0, "ImageList_Create failed\n");
1414 if(!himl) goto cleanup;
1415
1416 /* Add a no-alpha image */
1417 hbmImage = create_test_bitmap(hdcDst, 32, 0x00ABCDEF, 0x00ABCDEF);
1418 if(!hbmImage) goto cleanup;
1419
1420 iImage = pImageList_Add(himl, hbmImage, hbmMask);
1421 ok(iImage != -1, "ImageList_Add failed\n");
1422 if(iImage == -1) goto cleanup;
1423
1424 /* Add an alpha image */
1425 hbmAlphaImage = create_test_bitmap(hdcDst, 32, 0x89ABCDEF, 0x89ABCDEF);
1426 if(!hbmAlphaImage) goto cleanup;
1427
1428 iAlphaImage = pImageList_Add(himl, hbmAlphaImage, hbmMask);
1429 ok(iAlphaImage != -1, "ImageList_Add failed\n");
1430 if(iAlphaImage == -1) goto cleanup;
1431
1432 /* Add a transparent alpha image */
1433 hbmTransparentImage = create_test_bitmap(hdcDst, 32, 0x00ABCDEF, 0x89ABCDEF);
1434 if(!hbmTransparentImage) goto cleanup;
1435
1436 iTransparentImage = pImageList_Add(himl, hbmTransparentImage, hbmMask);
1437 ok(iTransparentImage != -1, "ImageList_Add failed\n");
1438 if(iTransparentImage == -1) goto cleanup;
1439
1440 /* 32-bit Tests */
1441 bitmapInfo.bmiHeader.biBitCount = 32;
1442 hbmDst = CreateDIBSection(hdcDst, &bitmapInfo, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
1443 ok (hbmDst && bits, "CreateDIBSection failed to return a valid bitmap and buffer\n");
1444 if (!hbmDst || !bits)
1445 goto cleanup;
1446 hbmOld = SelectObject(hdcDst, hbmDst);
1447
1448 check_ImageList_DrawIndirect_fStyle(hdcDst, himl, bits, iImage, ILD_NORMAL, 0x00ABCDEF, __LINE__);
1449 check_ImageList_DrawIndirect_fStyle(hdcDst, himl, bits, iImage, ILD_TRANSPARENT, 0x00ABCDEF, __LINE__);
1450 todo_wine check_ImageList_DrawIndirect_broken(hdcDst, himl, bits, iAlphaImage, ILD_BLEND25, ILS_NORMAL, 0, 0x00E8F1FA, 0x00D4D9DD, __LINE__);
1451 if (bpp == 16 || bpp == 24) broken_value = 0x00D4D9DD;
1452 else broken_value = 0x00B4BDC4;
1453 todo_wine check_ImageList_DrawIndirect_broken(hdcDst, himl, bits, iAlphaImage, ILD_BLEND50, ILS_NORMAL, 0, 0x00E8F1FA, broken_value, __LINE__);
1454 check_ImageList_DrawIndirect_fStyle(hdcDst, himl, bits, iImage, ILD_MASK, 0x00ABCDEF, __LINE__);
1455 check_ImageList_DrawIndirect_fStyle(hdcDst, himl, bits, iImage, ILD_IMAGE, 0x00ABCDEF, __LINE__);
1456 check_ImageList_DrawIndirect_fStyle(hdcDst, himl, bits, iImage, ILD_PRESERVEALPHA, 0x00ABCDEF, __LINE__);
1457
1458 check_ImageList_DrawIndirect_fStyle(hdcDst, himl, bits, iAlphaImage, ILD_NORMAL, 0x00D3E5F7, __LINE__);
1459 check_ImageList_DrawIndirect_fStyle(hdcDst, himl, bits, iAlphaImage, ILD_TRANSPARENT, 0x00D3E5F7, __LINE__);
1460
1461 if (bpp == 16 || bpp == 24) broken_value = 0x00D4D9DD;
1462 else broken_value = 0x009DA8B1;
1463 todo_wine check_ImageList_DrawIndirect_broken(hdcDst, himl, bits, iAlphaImage, ILD_BLEND25, ILS_NORMAL, 0, 0x00E8F1FA, broken_value, __LINE__);
1464 if (bpp == 16 || bpp == 24) broken_value = 0x00D4D9DD;
1465 else broken_value = 0x008C99A3;
1466 todo_wine check_ImageList_DrawIndirect_broken(hdcDst, himl, bits, iAlphaImage, ILD_BLEND50, ILS_NORMAL, 0, 0x00E8F1FA, broken_value, __LINE__);
1467 check_ImageList_DrawIndirect_fStyle(hdcDst, himl, bits, iAlphaImage, ILD_MASK, 0x00D3E5F7, __LINE__);
1468 check_ImageList_DrawIndirect_fStyle(hdcDst, himl, bits, iAlphaImage, ILD_IMAGE, 0x00D3E5F7, __LINE__);
1469 todo_wine check_ImageList_DrawIndirect_fStyle(hdcDst, himl, bits, iAlphaImage, ILD_PRESERVEALPHA, 0x005D6F81, __LINE__);
1470
1471 check_ImageList_DrawIndirect_fStyle(hdcDst, himl, bits, iTransparentImage, ILD_NORMAL, 0x00FFFFFF, __LINE__);
1472
1473 check_ImageList_DrawIndirect_ILD_ROP(hdcDst, himl, bits, iImage, SRCCOPY, 0x00ABCDEF, __LINE__);
1474 check_ImageList_DrawIndirect_ILD_ROP(hdcDst, himl, bits, iImage, SRCINVERT, 0x00543210, __LINE__);
1475
1476 /* ILD_ROP is ignored when the image has an alpha channel */
1477 check_ImageList_DrawIndirect_ILD_ROP(hdcDst, himl, bits, iAlphaImage, SRCCOPY, 0x00D3E5F7, __LINE__);
1478 check_ImageList_DrawIndirect_ILD_ROP(hdcDst, himl, bits, iAlphaImage, SRCINVERT, 0x00D3E5F7, __LINE__);
1479
1480 todo_wine check_ImageList_DrawIndirect_fState(hdcDst, himl, bits, iImage, ILD_NORMAL, ILS_SATURATE, 0, 0x00CCCCCC, __LINE__);
1481 todo_wine check_ImageList_DrawIndirect_broken(hdcDst, himl, bits, iAlphaImage, ILD_NORMAL, ILS_SATURATE, 0, 0x00AFAFAF, 0x00F0F0F0, __LINE__);
1482
1483 check_ImageList_DrawIndirect_fState(hdcDst, himl, bits, iImage, ILD_NORMAL, ILS_GLOW, 0, 0x00ABCDEF, __LINE__);
1484 check_ImageList_DrawIndirect_fState(hdcDst, himl, bits, iImage, ILD_NORMAL, ILS_SHADOW, 0, 0x00ABCDEF, __LINE__);
1485
1486 check_ImageList_DrawIndirect_fState(hdcDst, himl, bits, iImage, ILD_NORMAL, ILS_ALPHA, 127, 0x00D5E6F7, __LINE__);
1487 check_ImageList_DrawIndirect_broken(hdcDst, himl, bits, iAlphaImage, ILD_NORMAL, ILS_ALPHA, 127, 0x00E9F2FB, 0x00AEB7C0, __LINE__);
1488 todo_wine check_ImageList_DrawIndirect_broken(hdcDst, himl, bits, iAlphaImage, ILD_NORMAL, ILS_NORMAL, 127, 0x00E9F2FB, 0x00D3E5F7, __LINE__);
1489
1490 cleanup:
1491
1492 if(hbmOld)
1493 SelectObject(hdcDst, hbmOld);
1494 if(hbmDst)
1495 DeleteObject(hbmDst);
1496
1497 if(hdcDst)
1498 DeleteDC(hdcDst);
1499
1500 if(hbmMask)
1501 DeleteObject(hbmMask);
1502 if(hbmInverseMask)
1503 DeleteObject(hbmInverseMask);
1504
1505 if(hbmImage)
1506 DeleteObject(hbmImage);
1507 if(hbmAlphaImage)
1508 DeleteObject(hbmAlphaImage);
1509 if(hbmTransparentImage)
1510 DeleteObject(hbmTransparentImage);
1511
1512 if(himl)
1513 {
1514 ret = ImageList_Destroy(himl);
1515 ok(ret, "ImageList_Destroy failed\n");
1516 }
1517 }
1518
1519 static void test_iimagelist(void)
1520 {
1521 IImageList *imgl, *imgl2;
1522 IImageList2 *imagelist;
1523 HIMAGELIST himl;
1524 HRESULT hr;
1525 ULONG ret;
1526
1527 if (!pHIMAGELIST_QueryInterface)
1528 {
1529 win_skip("XP imagelist functions not available\n");
1530 return;
1531 }
1532
1533 /* test reference counting on destruction */
1534 imgl = (IImageList*)createImageList(32, 32);
1535 ret = IImageList_AddRef(imgl);
1536 ok(ret == 2, "Expected 2, got %d\n", ret);
1537 ret = ImageList_Destroy((HIMAGELIST)imgl);
1538 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1539 ret = ImageList_Destroy((HIMAGELIST)imgl);
1540 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1541 ret = ImageList_Destroy((HIMAGELIST)imgl);
1542 ok(ret == FALSE, "Expected FALSE, got %d\n", ret);
1543
1544 imgl = (IImageList*)createImageList(32, 32);
1545 ret = IImageList_AddRef(imgl);
1546 ok(ret == 2, "Expected 2, got %d\n", ret);
1547 ret = ImageList_Destroy((HIMAGELIST)imgl);
1548 ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
1549 ret = IImageList_Release(imgl);
1550 ok(ret == 0, "Expected 0, got %d\n", ret);
1551 ret = ImageList_Destroy((HIMAGELIST)imgl);
1552 ok(ret == FALSE, "Expected FALSE, got %d\n", ret);
1553
1554 /* ref counting, HIMAGELIST_QueryInterface adds a reference */
1555 imgl = (IImageList*)createImageList(32, 32);
1556 hr = pHIMAGELIST_QueryInterface((HIMAGELIST)imgl, &IID_IImageList, (void**)&imgl2);
1557 ok(hr == S_OK, "got 0x%08x\n", hr);
1558 ok(imgl2 == imgl, "got different pointer\n");
1559 ret = IImageList_Release(imgl);
1560 ok(ret == 1, "got %u\n", ret);
1561 IImageList_Release(imgl);
1562
1563 if (!pImageList_CoCreateInstance)
1564 {
1565 win_skip("Vista imagelist functions not available\n");
1566 return;
1567 }
1568
1569 hr = pImageList_CoCreateInstance(&CLSID_ImageList, NULL, &IID_IImageList, (void **) &imgl);
1570 ok(SUCCEEDED(hr), "ImageList_CoCreateInstance failed, hr=%x\n", hr);
1571
1572 if (hr == S_OK)
1573 IImageList_Release(imgl);
1574
1575 himl = createImageList(32, 32);
1576
1577 if (!himl)
1578 return;
1579
1580 hr = (pHIMAGELIST_QueryInterface)(himl, &IID_IImageList, (void **) &imgl);
1581 ok(SUCCEEDED(hr), "HIMAGELIST_QueryInterface failed, hr=%x\n", hr);
1582
1583 if (hr == S_OK)
1584 IImageList_Release(imgl);
1585
1586 ImageList_Destroy(himl);
1587
1588 /* IImageList2 */
1589 hr = pImageList_CoCreateInstance(&CLSID_ImageList, NULL, &IID_IImageList2, (void**)&imagelist);
1590 if (hr != S_OK)
1591 {
1592 win_skip("IImageList2 is not supported.\n");
1593 return;
1594 }
1595 ok(hr == S_OK, "got 0x%08x\n", hr);
1596 IImageList2_Release(imagelist);
1597 }
1598
1599 static void test_hotspot_v6(void)
1600 {
1601 struct hotspot {
1602 int dx;
1603 int dy;
1604 };
1605
1606 #define SIZEX1 47
1607 #define SIZEY1 31
1608 #define SIZEX2 11
1609 #define SIZEY2 17
1610 #define HOTSPOTS_MAX 4 /* Number of entries in hotspots */
1611 static const struct hotspot hotspots[HOTSPOTS_MAX] = {
1612 { 10, 7 },
1613 { SIZEX1, SIZEY1 },
1614 { -9, -8 },
1615 { -7, 35 }
1616 };
1617 int i, j;
1618 HIMAGELIST himl1 = createImageList(SIZEX1, SIZEY1);
1619 HIMAGELIST himl2 = createImageList(SIZEX2, SIZEY2);
1620 IImageList *imgl1, *imgl2;
1621 HRESULT hr;
1622
1623 /* cast to IImageList */
1624 imgl1 = (IImageList *) himl1;
1625 imgl2 = (IImageList *) himl2;
1626
1627 for (i = 0; i < HOTSPOTS_MAX; i++) {
1628 for (j = 0; j < HOTSPOTS_MAX; j++) {
1629 int dx1 = hotspots[i].dx;
1630 int dy1 = hotspots[i].dy;
1631 int dx2 = hotspots[j].dx;
1632 int dy2 = hotspots[j].dy;
1633 int correctx, correcty, newx, newy;
1634 char loc[256];
1635 IImageList *imglNew;
1636 POINT ppt;
1637
1638 hr = IImageList_BeginDrag(imgl1, 0, dx1, dy1);
1639 ok(SUCCEEDED(hr), "BeginDrag failed for { %d, %d }\n", dx1, dy1);
1640 sprintf(loc, "BeginDrag (%d,%d)\n", i, j);
1641
1642 /* check merging the dragged image with a second image */
1643 hr = IImageList_SetDragCursorImage(imgl2, (IUnknown *) imgl2, 0, dx2, dy2);
1644 ok(SUCCEEDED(hr), "SetDragCursorImage failed for {%d, %d}{%d, %d}\n",
1645 dx1, dy1, dx2, dy2);
1646 sprintf(loc, "SetDragCursorImage (%d,%d)\n", i, j);
1647
1648 /* check new hotspot, it should be the same like the old one */
1649 hr = IImageList_GetDragImage(imgl2, NULL, &ppt, &IID_IImageList, (PVOID *) &imglNew);
1650 ok(SUCCEEDED(hr), "GetDragImage failed\n");
1651 ok(ppt.x == dx1 && ppt.y == dy1,
1652 "Expected drag hotspot [%d,%d] got [%d,%d]\n",
1653 dx1, dy1, ppt.x, ppt.y);
1654 /* check size of new dragged image */
1655 IImageList_GetIconSize(imglNew, &newx, &newy);
1656 correctx = max(SIZEX1, max(SIZEX2 + dx2, SIZEX1 - dx2));
1657 correcty = max(SIZEY1, max(SIZEY2 + dy2, SIZEY1 - dy2));
1658 ok(newx == correctx && newy == correcty,
1659 "Expected drag image size [%d,%d] got [%d,%d]\n",
1660 correctx, correcty, newx, newy);
1661 sprintf(loc, "GetDragImage (%d,%d)\n", i, j);
1662 IImageList_EndDrag(imgl2);
1663 }
1664 }
1665 #undef SIZEX1
1666 #undef SIZEY1
1667 #undef SIZEX2
1668 #undef SIZEY2
1669 #undef HOTSPOTS_MAX
1670 IImageList_Release(imgl2);
1671 IImageList_Release(imgl1);
1672 }
1673
1674 static void test_IImageList_Add_Remove(void)
1675 {
1676 IImageList *imgl;
1677 HIMAGELIST himl;
1678 HRESULT hr;
1679
1680 HICON hicon1;
1681 HICON hicon2;
1682 HICON hicon3;
1683
1684 int ret;
1685
1686 /* create an imagelist to play with */
1687 himl = ImageList_Create(84, 84, ILC_COLOR16, 0, 3);
1688 ok(himl != 0,"failed to create imagelist\n");
1689
1690 imgl = (IImageList *) himl;
1691
1692 /* load the icons to add to the image list */
1693 hicon1 = CreateIcon(hinst, 32, 32, 1, 1, icon_bits, icon_bits);
1694 ok(hicon1 != 0, "no hicon1\n");
1695 hicon2 = CreateIcon(hinst, 32, 32, 1, 1, icon_bits, icon_bits);
1696 ok(hicon2 != 0, "no hicon2\n");
1697 hicon3 = CreateIcon(hinst, 32, 32, 1, 1, icon_bits, icon_bits);
1698 ok(hicon3 != 0, "no hicon3\n");
1699
1700 /* remove when nothing exists */
1701 hr = IImageList_Remove(imgl, 0);
1702 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
1703
1704 /* removing everything from an empty imagelist should succeed */
1705 hr = IImageList_Remove(imgl, -1);
1706 ok(hr == S_OK, "removed nonexistent icon\n");
1707
1708 /* add three */
1709 ret = -1;
1710 ok( IImageList_ReplaceIcon(imgl, -1, hicon1, &ret) == S_OK && (ret == 0),"failed to add icon1\n");
1711 ret = -1;
1712 ok( IImageList_ReplaceIcon(imgl, -1, hicon2, &ret) == S_OK && (ret == 1),"failed to add icon2\n");
1713 ret = -1;
1714 ok( IImageList_ReplaceIcon(imgl, -1, hicon3, &ret) == S_OK && (ret == 2),"failed to add icon3\n");
1715
1716 /* remove an index out of range */
1717 ok( IImageList_Remove(imgl, 4711) == E_INVALIDARG, "got 0x%08x\n", hr);
1718
1719 /* remove three */
1720 ok( IImageList_Remove(imgl,0) == S_OK, "can't remove 0\n");
1721 ok( IImageList_Remove(imgl,0) == S_OK, "can't remove 0\n");
1722 ok( IImageList_Remove(imgl,0) == S_OK, "can't remove 0\n");
1723
1724 /* remove one extra */
1725 ok( IImageList_Remove(imgl, 0) == E_INVALIDARG, "got 0x%08x\n", hr);
1726
1727 IImageList_Release(imgl);
1728 ok(DestroyIcon(hicon1),"icon 1 wasn't deleted\n");
1729 ok(DestroyIcon(hicon2),"icon 2 wasn't deleted\n");
1730 ok(DestroyIcon(hicon3),"icon 3 wasn't deleted\n");
1731 }
1732
1733 static void test_IImageList_Get_SetImageCount(void)
1734 {
1735 IImageList *imgl;
1736 HIMAGELIST himl;
1737 HRESULT hr;
1738 INT ret;
1739
1740 /* create an imagelist to play with */
1741 himl = ImageList_Create(84, 84, ILC_COLOR16, 0, 3);
1742 ok(himl != 0,"failed to create imagelist\n");
1743
1744 imgl = (IImageList *) himl;
1745
1746 /* check SetImageCount/GetImageCount */
1747 hr = IImageList_SetImageCount(imgl, 3);
1748 ok(hr == S_OK, "got 0x%08x\n", hr);
1749 ret = 0;
1750 hr = IImageList_GetImageCount(imgl, &ret);
1751 ok(hr == S_OK && ret == 3, "invalid image count after increase\n");
1752 hr = IImageList_SetImageCount(imgl, 1);
1753 ok(hr == S_OK, "got 0x%08x\n", hr);
1754 ret = 0;
1755 hr = IImageList_GetImageCount(imgl, &ret);
1756 ok(hr == S_OK && ret == 1, "invalid image count after decrease to 1\n");
1757 hr = IImageList_SetImageCount(imgl, 0);
1758 ok(hr == S_OK, "got 0x%08x\n", hr);
1759 ret = -1;
1760 hr = IImageList_GetImageCount(imgl, &ret);
1761 ok(hr == S_OK && ret == 0, "invalid image count after decrease to 0\n");
1762
1763 IImageList_Release(imgl);
1764 }
1765
1766 static void test_IImageList_Draw(void)
1767 {
1768 IImageList *imgl;
1769 HIMAGELIST himl;
1770
1771 HBITMAP hbm1;
1772 HBITMAP hbm2;
1773 HBITMAP hbm3;
1774
1775 IMAGELISTDRAWPARAMS imldp;
1776 HWND hwndfortest;
1777 HRESULT hr;
1778 HDC hdc;
1779 int ret;
1780
1781 hwndfortest = create_a_window();
1782 hdc = GetDC(hwndfortest);
1783 ok(hdc!=NULL, "couldn't get DC\n");
1784
1785 /* create an imagelist to play with */
1786 himl = ImageList_Create(48, 48, ILC_COLOR16, 0, 3);
1787 ok(himl!=0,"failed to create imagelist\n");
1788
1789 imgl = (IImageList *) himl;
1790
1791 /* load the icons to add to the image list */
1792 hbm1 = CreateBitmap(48, 48, 1, 1, bitmap_bits);
1793 ok(hbm1 != 0, "no bitmap 1\n");
1794 hbm2 = CreateBitmap(48, 48, 1, 1, bitmap_bits);
1795 ok(hbm2 != 0, "no bitmap 2\n");
1796 hbm3 = CreateBitmap(48, 48, 1, 1, bitmap_bits);
1797 ok(hbm3 != 0, "no bitmap 3\n");
1798
1799 /* add three */
1800 ret = -1;
1801 ok( IImageList_Add(imgl, hbm1, 0, &ret) == S_OK && (ret == 0), "failed to add bitmap 1\n");
1802 ret = -1;
1803 ok( IImageList_Add(imgl, hbm2, 0, &ret) == S_OK && (ret == 1), "failed to add bitmap 2\n");
1804
1805 ok( IImageList_SetImageCount(imgl, 3) == S_OK, "Setimage count failed\n");
1806 ok( IImageList_Replace(imgl, 2, hbm3, 0) == S_OK, "failed to replace bitmap 3\n");
1807
1808 if (0)
1809 {
1810 /* crashes on native */
1811 IImageList_Draw(imgl, NULL);
1812 }
1813
1814 memset(&imldp, 0, sizeof (imldp));
1815 hr = IImageList_Draw(imgl, &imldp);
1816 ok( hr == E_INVALIDARG, "got 0x%08x\n", hr);
1817
1818 imldp.cbSize = IMAGELISTDRAWPARAMS_V3_SIZE;
1819 imldp.hdcDst = hdc;
1820 imldp.himl = himl;
1821
1822 force_redraw(hwndfortest);
1823
1824 imldp.fStyle = SRCCOPY;
1825 imldp.rgbBk = CLR_DEFAULT;
1826 imldp.rgbFg = CLR_DEFAULT;
1827 imldp.y = 100;
1828 imldp.x = 100;
1829 ok( IImageList_Draw(imgl, &imldp) == S_OK, "should succeed\n");
1830 imldp.i ++;
1831 ok( IImageList_Draw(imgl, &imldp) == S_OK, "should succeed\n");
1832 imldp.i ++;
1833 ok( IImageList_Draw(imgl, &imldp) == S_OK, "should succeed\n");
1834 imldp.i ++;
1835 ok( IImageList_Draw(imgl, &imldp) == E_INVALIDARG, "should fail\n");
1836
1837 /* remove three */
1838 ok( IImageList_Remove(imgl, 0) == S_OK, "removing 1st bitmap\n");
1839 ok( IImageList_Remove(imgl, 0) == S_OK, "removing 2nd bitmap\n");
1840 ok( IImageList_Remove(imgl, 0) == S_OK, "removing 3rd bitmap\n");
1841
1842 /* destroy it */
1843 IImageList_Release(imgl);
1844
1845 /* bitmaps should not be deleted by the imagelist */
1846 ok(DeleteObject(hbm1),"bitmap 1 can't be deleted\n");
1847 ok(DeleteObject(hbm2),"bitmap 2 can't be deleted\n");
1848 ok(DeleteObject(hbm3),"bitmap 3 can't be deleted\n");
1849
1850 ReleaseDC(hwndfortest, hdc);
1851 DestroyWindow(hwndfortest);
1852 }
1853
1854 static void test_IImageList_Merge(void)
1855 {
1856 HIMAGELIST himl1, himl2;
1857 IImageList *imgl1, *imgl2, *merge;
1858 HICON hicon1;
1859 HWND hwnd = create_a_window();
1860 HRESULT hr;
1861 int ret;
1862
1863 himl1 = ImageList_Create(32,32,0,0,3);
1864 ok(himl1 != NULL,"failed to create himl1\n");
1865
1866 himl2 = ImageList_Create(32,32,0,0,3);
1867 ok(himl2 != NULL,"failed to create himl2\n");
1868
1869 hicon1 = CreateIcon(hinst, 32, 32, 1, 1, icon_bits, icon_bits);
1870 ok(hicon1 != NULL, "failed to create hicon1\n");
1871
1872 if (!himl1 || !himl2 || !hicon1)
1873 return;
1874
1875 /* cast to IImageList */
1876 imgl1 = (IImageList *) himl1;
1877 imgl2 = (IImageList *) himl2;
1878
1879 ret = -1;
1880 ok( IImageList_ReplaceIcon(imgl2, -1, hicon1, &ret) == S_OK && (ret == 0),"add icon1 to himl2 failed\n");
1881
1882 if (0)
1883 {
1884 /* null cases that crash on native */
1885 IImageList_Merge(imgl1, -1, NULL, 0, 0, 0, &IID_IImageList, (void**)&merge);
1886 IImageList_Merge(imgl1, -1, (IUnknown*) imgl2, 0, 0, 0, &IID_IImageList, NULL);
1887 }
1888
1889 /* If himl1 has no images, merge still succeeds */
1890 hr = IImageList_Merge(imgl1, -1, (IUnknown *) imgl2, 0, 0, 0, &IID_IImageList, (void **) &merge);
1891 ok(hr == S_OK, "merge himl1,-1 failed\n");
1892 if (hr == S_OK) IImageList_Release(merge);
1893
1894 hr = IImageList_Merge(imgl1, 0, (IUnknown *) imgl2, 0, 0, 0, &IID_IImageList, (void **) &merge);
1895 ok(hr == S_OK, "merge himl1,0 failed\n");
1896 if (hr == S_OK) IImageList_Release(merge);
1897
1898 /* Same happens if himl2 is empty */
1899 IImageList_Release(imgl2);
1900 himl2 = ImageList_Create(32,32,0,0,3);
1901 ok(himl2 != NULL,"failed to recreate himl2\n");
1902
1903 imgl2 = (IImageList *) himl2;
1904
1905 hr = IImageList_Merge(imgl1, -1, (IUnknown *) imgl2, -1, 0, 0, &IID_IImageList, (void **) &merge);
1906 ok(hr == S_OK, "merge himl2,-1 failed\n");
1907 if (hr == S_OK) IImageList_Release(merge);
1908
1909 hr = IImageList_Merge(imgl1, -1, (IUnknown *) imgl2, 0, 0, 0, &IID_IImageList, (void **) &merge);
1910 ok(hr == S_OK, "merge himl2,0 failed\n");
1911 if (hr == S_OK) IImageList_Release(merge);
1912
1913 /* Now try merging an image with itself */
1914 ret = -1;
1915 ok( IImageList_ReplaceIcon(imgl2, -1, hicon1, &ret) == S_OK && (ret == 0),"re-add icon1 to himl2 failed\n");
1916
1917 hr = IImageList_Merge(imgl2, 0, (IUnknown *) imgl2, 0, 0, 0, &IID_IImageList, (void **) &merge);
1918 ok(hr == S_OK, "merge himl2 with itself failed\n");
1919 if (hr == S_OK) IImageList_Release(merge);
1920
1921 /* Try merging 2 different image lists */
1922 ret = -1;
1923 ok( IImageList_ReplaceIcon(imgl1, -1, hicon1, &ret) == S_OK && (ret == 0),"add icon1 to himl1 failed\n");
1924
1925 hr = IImageList_Merge(imgl1, 0, (IUnknown *) imgl2, 0, 0, 0, &IID_IImageList, (void **) &merge);
1926 ok(hr == S_OK, "merge himl1 with himl2 failed\n");
1927 if (hr == S_OK) IImageList_Release(merge);
1928
1929 hr = IImageList_Merge(imgl1, 0, (IUnknown *) imgl2, 0, 8, 16, &IID_IImageList, (void **) &merge);
1930 ok(hr == S_OK, "merge himl1 with himl2 8,16 failed\n");
1931 if (hr == S_OK) IImageList_Release(merge);
1932
1933 IImageList_Release(imgl1);
1934 IImageList_Release(imgl2);
1935
1936 DestroyIcon(hicon1);
1937 DestroyWindow(hwnd);
1938 }
1939
1940 static void test_iconsize(void)
1941 {
1942 HIMAGELIST himl;
1943 INT cx, cy;
1944 BOOL ret;
1945
1946 himl = ImageList_Create(16, 16, ILC_COLOR16, 0, 3);
1947 /* null pointers, not zero imagelist dimensions */
1948 ret = ImageList_GetIconSize(himl, NULL, NULL);
1949 ok(!ret, "got %d\n", ret);
1950
1951 /* doesn't touch return pointers */
1952 cx = 0x1abe11ed;
1953 ret = ImageList_GetIconSize(himl, &cx, NULL);
1954 ok(!ret, "got %d\n", ret);
1955 ok(cx == 0x1abe11ed, "got %d\n", cx);
1956
1957 cy = 0x1abe11ed;
1958 ret = ImageList_GetIconSize(himl, NULL, &cy);
1959 ok(!ret, "got %d\n", ret);
1960 ok(cy == 0x1abe11ed, "got %d\n", cy);
1961
1962 ImageList_Destroy(himl);
1963
1964 ret = ImageList_GetIconSize((HIMAGELIST)0xdeadbeef, &cx, &cy);
1965 ok(!ret, "got %d\n", ret);
1966 }
1967
1968 static void test_create_destroy(void)
1969 {
1970 HIMAGELIST himl;
1971 IImageList *imgl;
1972 INT cx, cy;
1973 BOOL rc;
1974 HRESULT hr;
1975 INT ret;
1976
1977 /* list with zero or negative image dimensions */
1978 himl = ImageList_Create(0, 0, ILC_COLOR16, 0, 3);
1979 ok(himl == NULL, "got %p\n", himl);
1980
1981 himl = ImageList_Create(0, 16, ILC_COLOR16, 0, 3);
1982 ok(himl == NULL, "got %p\n", himl);
1983
1984 himl = ImageList_Create(16, 0, ILC_COLOR16, 0, 3);
1985 ok(himl == NULL, "got %p\n", himl);
1986
1987 himl = ImageList_Create(16, -1, ILC_COLOR16, 0, 3);
1988 ok(himl == NULL, "got %p\n", himl);
1989
1990 himl = ImageList_Create(-1, 16, ILC_COLOR16, 0, 3);
1991 ok(himl == NULL, "got %p\n", himl);
1992
1993 rc = ImageList_Destroy((HIMAGELIST)0xdeadbeef);
1994 ok(rc == FALSE, "ImageList_Destroy(0xdeadbeef) should fail and not crash\n");
1995
1996 /* DDB image lists */
1997 himl = ImageList_Create(0, 14, ILC_COLORDDB, 4, 4);
1998 ok(himl != NULL, "got %p\n", himl);
1999 imgl = (IImageList*)himl;
2000 IImageList_GetIconSize(imgl, &cx, &cy);
2001 ok (cx == 0, "Wrong cx (%i)\n", cx);
2002 ok (cy == 14, "Wrong cy (%i)\n", cy);
2003 ImageList_Destroy(himl);
2004
2005 himl = ImageList_Create(0, 0, ILC_COLORDDB, 4, 4);
2006 ok(himl != NULL, "got %p\n", himl);
2007 imgl = (IImageList*)himl;
2008 IImageList_GetIconSize(imgl, &cx, &cy);
2009 ok (cx == 0, "Wrong cx (%i)\n", cx);
2010 ok (cy == 0, "Wrong cy (%i)\n", cy);
2011 ImageList_Destroy(himl);
2012
2013 himl = ImageList_Create(0, 0, ILC_COLORDDB, 0, 4);
2014 ok(himl != NULL, "got %p\n", himl);
2015 imgl = (IImageList*)himl;
2016 IImageList_GetIconSize(imgl, &cx, &cy);
2017 ok (cx == 0, "Wrong cx (%i)\n", cx);
2018 ok (cy == 0, "Wrong cy (%i)\n", cy);
2019
2020 hr = IImageList_SetImageCount(imgl, 3);
2021 ok(hr == S_OK, "got 0x%08x\n", hr);
2022 hr = IImageList_GetImageCount(imgl, &ret);
2023 ok(hr == S_OK && ret == 3, "invalid image count after increase\n");
2024
2025 /* Trying to actually add an image causes a crash on Windows */
2026 ImageList_Destroy(himl);
2027
2028 /* Negative values fail */
2029 himl = ImageList_Create(-1, -1, ILC_COLORDDB, 4, 4);
2030 ok(himl == NULL, "got %p\n", himl);
2031 himl = ImageList_Create(-1, 1, ILC_COLORDDB, 4, 4);
2032 ok(himl == NULL, "got %p\n", himl);
2033 himl = ImageList_Create(1, -1, ILC_COLORDDB, 4, 4);
2034 ok(himl == NULL, "got %p\n", himl);
2035 }
2036
2037 static void test_IImageList_Clone(void)
2038 {
2039 IImageList *imgl, *imgl2;
2040 HIMAGELIST himl;
2041 HRESULT hr;
2042 ULONG ref;
2043
2044 himl = ImageList_Create(16, 16, ILC_COLOR16, 0, 3);
2045 imgl = (IImageList*)himl;
2046
2047 if (0)
2048 {
2049 /* crashes on native */
2050 IImageList_Clone(imgl, &IID_IImageList, NULL);
2051 }
2052
2053 hr = IImageList_Clone(imgl, &IID_IImageList, (void**)&imgl2);
2054 ok(hr == S_OK, "got 0x%08x\n", hr);
2055 ref = IImageList_Release(imgl2);
2056 ok(ref == 0, "got %u\n", ref);
2057
2058 IImageList_Release(imgl);
2059 }
2060
2061 static void test_IImageList_GetBkColor(void)
2062 {
2063 IImageList *imgl;
2064 HIMAGELIST himl;
2065 COLORREF color;
2066 HRESULT hr;
2067
2068 himl = ImageList_Create(16, 16, ILC_COLOR16, 0, 3);
2069 imgl = (IImageList*)himl;
2070
2071 if (0)
2072 {
2073 /* crashes on native */
2074 IImageList_GetBkColor(imgl, NULL);
2075 }
2076
2077 hr = IImageList_GetBkColor(imgl, &color);
2078 ok(hr == S_OK, "got 0x%08x\n", hr);
2079
2080 IImageList_Release(imgl);
2081 }
2082
2083 static void test_IImageList_SetBkColor(void)
2084 {
2085 IImageList *imgl;
2086 HIMAGELIST himl;
2087 COLORREF color;
2088 HRESULT hr;
2089
2090 himl = ImageList_Create(16, 16, ILC_COLOR16, 0, 3);
2091 imgl = (IImageList*)himl;
2092
2093 if (0)
2094 {
2095 /* crashes on native */
2096 IImageList_SetBkColor(imgl, RGB(0, 0, 0), NULL);
2097 }
2098
2099 hr = IImageList_SetBkColor(imgl, CLR_NONE, &color);
2100 ok(hr == S_OK, "got 0x%08x\n", hr);
2101
2102 hr = IImageList_SetBkColor(imgl, CLR_NONE, &color);
2103 ok(hr == S_OK, "got 0x%08x\n", hr);
2104
2105 color = 0xdeadbeef;
2106 hr = IImageList_GetBkColor(imgl, &color);
2107 ok(hr == S_OK, "got 0x%08x\n", hr);
2108 ok(color == CLR_NONE, "got %x\n", color);
2109
2110 IImageList_Release(imgl);
2111 }
2112
2113 static void test_IImageList_GetImageCount(void)
2114 {
2115 IImageList *imgl;
2116 HIMAGELIST himl;
2117 int count;
2118 HRESULT hr;
2119
2120 himl = ImageList_Create(16, 16, ILC_COLOR16, 0, 3);
2121 imgl = (IImageList*)himl;
2122
2123 if (0)
2124 {
2125 /* crashes on native */
2126 IImageList_GetImageCount(imgl, NULL);
2127 }
2128
2129 count = -1;
2130 hr = IImageList_GetImageCount(imgl, &count);
2131 ok(hr == S_OK, "got 0x%08x\n", hr);
2132 ok(count == 0, "got %d\n", count);
2133
2134 IImageList_Release(imgl);
2135 }
2136
2137 static void test_IImageList_GetIconSize(void)
2138 {
2139 IImageList *imgl;
2140 HIMAGELIST himl;
2141 int cx, cy;
2142 HRESULT hr;
2143
2144 himl = ImageList_Create(16, 16, ILC_COLOR16, 0, 3);
2145 imgl = (IImageList*)himl;
2146
2147 hr = IImageList_GetIconSize(imgl, NULL, NULL);
2148 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
2149
2150 hr = IImageList_GetIconSize(imgl, &cx, NULL);
2151 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
2152
2153 hr = IImageList_GetIconSize(imgl, NULL, &cy);
2154 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
2155
2156 IImageList_Release(imgl);
2157 }
2158
2159 START_TEST(imagelist)
2160 {
2161 ULONG_PTR ctx_cookie;
2162 HANDLE hCtx;
2163
2164 HMODULE hComCtl32 = GetModuleHandleA("comctl32.dll");
2165 pImageList_Create = NULL; /* These are not needed for non-v6.0 tests*/
2166 pImageList_Add = NULL;
2167 pImageList_DrawIndirect = (void*)GetProcAddress(hComCtl32, "ImageList_DrawIndirect");
2168 pImageList_SetImageCount = (void*)GetProcAddress(hComCtl32, "ImageList_SetImageCount");
2169
2170 hinst = GetModuleHandleA(NULL);
2171
2172 InitCommonControls();
2173
2174 test_create_destroy();
2175 test_begindrag();
2176 test_hotspot();
2177 test_add_remove();
2178 test_imagecount();
2179 test_DrawIndirect();
2180 test_merge();
2181 test_merge_colors();
2182 test_imagelist_storage();
2183 test_iconsize();
2184
2185 FreeLibrary(hComCtl32);
2186
2187 /* Now perform v6 tests */
2188
2189 if (!load_v6_module(&ctx_cookie, &hCtx))
2190 return;
2191
2192 /* Reload comctl32 */
2193 hComCtl32 = LoadLibraryA("comctl32.dll");
2194 pImageList_Create = (void*)GetProcAddress(hComCtl32, "ImageList_Create");
2195 pImageList_Add = (void*)GetProcAddress(hComCtl32, "ImageList_Add");
2196 pImageList_DrawIndirect = (void*)GetProcAddress(hComCtl32, "ImageList_DrawIndirect");
2197 pImageList_SetImageCount = (void*)GetProcAddress(hComCtl32, "ImageList_SetImageCount");
2198 pImageList_CoCreateInstance = (void*)GetProcAddress(hComCtl32, "ImageList_CoCreateInstance");
2199 pHIMAGELIST_QueryInterface = (void*)GetProcAddress(hComCtl32, "HIMAGELIST_QueryInterface");
2200
2201 CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
2202
2203 /* Do v6.0 tests */
2204 test_ImageList_DrawIndirect();
2205 test_shell_imagelist();
2206 test_iimagelist();
2207
2208 test_hotspot_v6();
2209 test_IImageList_Add_Remove();
2210 test_IImageList_Get_SetImageCount();
2211 test_IImageList_Draw();
2212 test_IImageList_Merge();
2213 test_IImageList_Clone();
2214 test_IImageList_GetBkColor();
2215 test_IImageList_SetBkColor();
2216 test_IImageList_GetImageCount();
2217 test_IImageList_GetIconSize();
2218
2219 CoUninitialize();
2220
2221 unload_v6_module(ctx_cookie, hCtx);
2222 }