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