2004-08-22 03:59:55 +02:00
|
|
|
/* Unit test suite for imagelist control.
|
|
|
|
*
|
|
|
|
* Copyright 2004 Michael Stefaniuc
|
2004-08-24 20:41:52 +02:00
|
|
|
* Copyright 2002 Mike McCormack for CodeWeavers
|
2004-08-22 03:59:55 +02:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2004-08-22 03:59:55 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <windows.h>
|
|
|
|
#include <commctrl.h>
|
2004-10-07 19:34:56 +02:00
|
|
|
#include <stdio.h>
|
2004-08-22 03:59:55 +02:00
|
|
|
|
|
|
|
#include "wine/test.h"
|
|
|
|
|
2004-10-07 19:34:56 +02:00
|
|
|
#undef VISIBLE
|
|
|
|
|
|
|
|
#ifdef VISIBLE
|
|
|
|
#define WAIT Sleep (1000)
|
|
|
|
#define REDRAW(hwnd) RedrawWindow (hwnd, NULL, 0, RDW_UPDATENOW)
|
|
|
|
#else
|
|
|
|
#define WAIT
|
|
|
|
#define REDRAW(hwnd)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2004-08-31 19:32:43 +02:00
|
|
|
static BOOL (WINAPI *pImageList_DrawIndirect)(IMAGELISTDRAWPARAMS*) = NULL;
|
2004-08-26 20:22:31 +02:00
|
|
|
|
|
|
|
static HDC desktopDC;
|
2004-10-07 19:34:56 +02:00
|
|
|
static HINSTANCE hinst;
|
|
|
|
|
|
|
|
/* These macros build cursor/bitmap data in 4x4 pixel blocks */
|
|
|
|
#define B(x,y) ((x?0xf0:0)|(y?0xf:0))
|
|
|
|
#define ROW1(a,b,c,d,e,f,g,h) B(a,b),B(c,d),B(e,f),B(g,h)
|
|
|
|
#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), \
|
|
|
|
ROW1(a,b,c,d,e,f,g,h), ROW1(a,b,c,d,e,f,g,h)
|
|
|
|
#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)
|
|
|
|
#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), \
|
|
|
|
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), \
|
|
|
|
ROW2(a,b,c,d,e,f,g,h,i,j,k,l)
|
|
|
|
|
|
|
|
static const BYTE empty_bits[48*48/8];
|
|
|
|
|
|
|
|
static const BYTE icon_bits[32*32/8] =
|
|
|
|
{
|
|
|
|
ROW32(0,0,0,0,0,0,0,0),
|
|
|
|
ROW32(0,0,1,1,1,1,0,0),
|
|
|
|
ROW32(0,1,1,1,1,1,1,0),
|
|
|
|
ROW32(0,1,1,0,0,1,1,0),
|
|
|
|
ROW32(0,1,1,0,0,1,1,0),
|
|
|
|
ROW32(0,1,1,1,1,1,1,0),
|
|
|
|
ROW32(0,0,1,1,1,1,0,0),
|
|
|
|
ROW32(0,0,0,0,0,0,0,0)
|
|
|
|
};
|
|
|
|
|
|
|
|
static const BYTE bitmap_bits[48*48/8] =
|
|
|
|
{
|
|
|
|
ROW48(0,0,0,0,0,0,0,0,0,0,0,0),
|
|
|
|
ROW48(0,1,1,1,1,1,1,1,1,1,1,0),
|
|
|
|
ROW48(0,1,1,0,0,0,0,0,0,1,1,0),
|
|
|
|
ROW48(0,1,0,0,0,0,0,0,1,0,1,0),
|
|
|
|
ROW48(0,1,0,0,0,0,0,1,0,0,1,0),
|
|
|
|
ROW48(0,1,0,0,0,0,1,0,0,0,1,0),
|
|
|
|
ROW48(0,1,0,0,0,1,0,0,0,0,1,0),
|
|
|
|
ROW48(0,1,0,0,1,0,0,0,0,0,1,0),
|
|
|
|
ROW48(0,1,0,1,0,0,0,0,0,0,1,0),
|
|
|
|
ROW48(0,1,1,0,0,0,0,0,0,1,1,0),
|
|
|
|
ROW48(0,1,1,1,1,1,1,1,1,1,1,0),
|
|
|
|
ROW48(0,0,0,0,0,0,0,0,0,0,0,0)
|
|
|
|
};
|
2004-08-22 03:59:55 +02:00
|
|
|
|
2004-12-13 22:19:01 +01:00
|
|
|
static HIMAGELIST createImageList(int cx, int cy)
|
2004-08-22 03:59:55 +02:00
|
|
|
{
|
|
|
|
/* Create an ImageList and put an image into it */
|
|
|
|
HIMAGELIST himl = ImageList_Create(cx, cy, ILC_COLOR, 1, 1);
|
2004-10-07 19:34:56 +02:00
|
|
|
HBITMAP hbm = CreateBitmap(48, 48, 1, 1, bitmap_bits);
|
2004-08-22 03:59:55 +02:00
|
|
|
ImageList_Add(himl, hbm, NULL);
|
|
|
|
return himl;
|
|
|
|
}
|
|
|
|
|
2004-10-07 19:34:56 +02:00
|
|
|
static HWND create_a_window(void)
|
|
|
|
{
|
|
|
|
char className[] = "bmwnd";
|
|
|
|
char winName[] = "Test Bitmap";
|
|
|
|
HWND hWnd;
|
|
|
|
static int registered = 0;
|
|
|
|
|
|
|
|
if (!registered)
|
|
|
|
{
|
|
|
|
WNDCLASSA cls;
|
|
|
|
|
|
|
|
cls.style = CS_HREDRAW | CS_VREDRAW | CS_GLOBALCLASS;
|
|
|
|
cls.lpfnWndProc = DefWindowProcA;
|
|
|
|
cls.cbClsExtra = 0;
|
|
|
|
cls.cbWndExtra = 0;
|
|
|
|
cls.hInstance = 0;
|
|
|
|
cls.hIcon = LoadIconA (0, (LPSTR)IDI_APPLICATION);
|
|
|
|
cls.hCursor = LoadCursorA (0, (LPSTR)IDC_ARROW);
|
|
|
|
cls.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH);
|
|
|
|
cls.lpszMenuName = 0;
|
|
|
|
cls.lpszClassName = className;
|
|
|
|
|
|
|
|
RegisterClassA (&cls);
|
|
|
|
registered = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Setup window */
|
|
|
|
hWnd = CreateWindowA (className, winName,
|
|
|
|
WS_OVERLAPPEDWINDOW ,
|
|
|
|
CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, 0,
|
|
|
|
0, hinst, 0);
|
|
|
|
|
|
|
|
#ifdef VISIBLE
|
|
|
|
ShowWindow (hWnd, SW_SHOW);
|
|
|
|
#endif
|
|
|
|
REDRAW(hWnd);
|
|
|
|
WAIT;
|
|
|
|
|
|
|
|
return hWnd;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HDC show_image(HWND hwnd, HIMAGELIST himl, int idx, int size,
|
|
|
|
LPCSTR loc, BOOL clear)
|
|
|
|
{
|
|
|
|
HDC hdc = NULL;
|
|
|
|
#ifdef VISIBLE
|
|
|
|
if (!himl) return NULL;
|
|
|
|
|
|
|
|
SetWindowText(hwnd, loc);
|
|
|
|
hdc = GetDC(hwnd);
|
|
|
|
ImageList_Draw(himl, idx, hdc, 0, 0, ILD_TRANSPARENT);
|
|
|
|
|
|
|
|
REDRAW(hwnd);
|
|
|
|
WAIT;
|
|
|
|
|
|
|
|
if (clear)
|
|
|
|
{
|
|
|
|
BitBlt(hdc, 0, 0, size, size, hdc, size+1, size+1, SRCCOPY);
|
|
|
|
ReleaseDC(hwnd, hdc);
|
|
|
|
hdc = NULL;
|
|
|
|
}
|
|
|
|
#endif /* VISIBLE */
|
|
|
|
return hdc;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Useful for checking differences */
|
2004-10-14 02:34:47 +02:00
|
|
|
#if 0
|
2004-10-07 19:34:56 +02:00
|
|
|
static void dump_bits(const BYTE *p, const BYTE *q, int size)
|
|
|
|
{
|
|
|
|
int i, j;
|
|
|
|
|
|
|
|
size /= 8;
|
|
|
|
|
|
|
|
for (i = 0; i < size * 2; i++)
|
|
|
|
{
|
|
|
|
printf("|");
|
|
|
|
for (j = 0; j < size; j++)
|
|
|
|
printf("%c%c", p[j] & 0xf0 ? 'X' : ' ', p[j] & 0xf ? 'X' : ' ');
|
|
|
|
printf(" -- ");
|
|
|
|
for (j = 0; j < size; j++)
|
|
|
|
printf("%c%c", q[j] & 0xf0 ? 'X' : ' ', q[j] & 0xf ? 'X' : ' ');
|
|
|
|
printf("|\n");
|
|
|
|
p += size * 4;
|
|
|
|
q += size * 4;
|
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
}
|
2004-10-14 02:34:47 +02:00
|
|
|
#endif
|
2004-10-07 19:34:56 +02:00
|
|
|
|
|
|
|
static void check_bits(HWND hwnd, HIMAGELIST himl, int idx, int size,
|
|
|
|
const BYTE *checkbits, LPCSTR loc)
|
|
|
|
{
|
|
|
|
#ifdef VISIBLE
|
|
|
|
BYTE bits[100*100/8];
|
|
|
|
COLORREF c;
|
|
|
|
HDC hdc;
|
|
|
|
int x, y, i = -1;
|
|
|
|
|
|
|
|
if (!himl) return;
|
|
|
|
|
|
|
|
memset(bits, 0, sizeof(bits));
|
|
|
|
hdc = show_image(hwnd, himl, idx, size, loc, FALSE);
|
|
|
|
|
|
|
|
c = GetPixel(hdc, 0, 0);
|
|
|
|
|
|
|
|
for (y = 0; y < size; y ++)
|
|
|
|
{
|
|
|
|
for (x = 0; x < size; x++)
|
|
|
|
{
|
|
|
|
if (!(x & 0x7)) i++;
|
|
|
|
if (GetPixel(hdc, x, y) != c) bits[i] |= (0x80 >> (x & 0x7));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
BitBlt(hdc, 0, 0, size, size, hdc, size+1, size+1, SRCCOPY);
|
|
|
|
ReleaseDC(hwnd, hdc);
|
|
|
|
|
|
|
|
ok (memcmp(bits, checkbits, (size * size)/8) == 0,
|
|
|
|
"%s: bits different\n", loc);
|
|
|
|
if (memcmp(bits, checkbits, (size * size)/8))
|
|
|
|
dump_bits(bits, checkbits, size);
|
|
|
|
#endif /* VISIBLE */
|
|
|
|
}
|
|
|
|
|
2004-08-22 03:59:55 +02:00
|
|
|
static void testHotspot (void)
|
|
|
|
{
|
|
|
|
struct hotspot {
|
|
|
|
int dx;
|
|
|
|
int dy;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define SIZEX1 47
|
|
|
|
#define SIZEY1 31
|
|
|
|
#define SIZEX2 11
|
|
|
|
#define SIZEY2 17
|
|
|
|
#define HOTSPOTS_MAX 4 /* Number of entries in hotspots */
|
|
|
|
static const struct hotspot hotspots[HOTSPOTS_MAX] = {
|
|
|
|
{ 10, 7 },
|
|
|
|
{ SIZEX1, SIZEY1 },
|
|
|
|
{ -9, -8 },
|
|
|
|
{ -7, 35 }
|
|
|
|
};
|
|
|
|
int i, j, ret;
|
|
|
|
HIMAGELIST himl1 = createImageList(SIZEX1, SIZEY1);
|
|
|
|
HIMAGELIST himl2 = createImageList(SIZEX2, SIZEY2);
|
2004-10-07 19:34:56 +02:00
|
|
|
HWND hwnd = create_a_window();
|
|
|
|
|
2004-08-22 03:59:55 +02:00
|
|
|
|
|
|
|
for (i = 0; i < HOTSPOTS_MAX; i++) {
|
|
|
|
for (j = 0; j < HOTSPOTS_MAX; j++) {
|
|
|
|
int dx1 = hotspots[i].dx;
|
|
|
|
int dy1 = hotspots[i].dy;
|
|
|
|
int dx2 = hotspots[j].dx;
|
|
|
|
int dy2 = hotspots[j].dy;
|
|
|
|
int correctx, correcty, newx, newy;
|
2004-10-07 19:34:56 +02:00
|
|
|
char loc[256];
|
2004-08-22 03:59:55 +02:00
|
|
|
HIMAGELIST himlNew;
|
|
|
|
POINT ppt;
|
|
|
|
|
|
|
|
ret = ImageList_BeginDrag(himl1, 0, dx1, dy1);
|
|
|
|
ok(ret != 0, "BeginDrag failed for { %d, %d }\n", dx1, dy1);
|
2004-10-07 19:34:56 +02:00
|
|
|
sprintf(loc, "BeginDrag (%d,%d)\n", i, j);
|
|
|
|
show_image(hwnd, himl1, 0, max(SIZEX1, SIZEY1), loc, TRUE);
|
|
|
|
|
2004-08-22 03:59:55 +02:00
|
|
|
/* check merging the dragged image with a second image */
|
|
|
|
ret = ImageList_SetDragCursorImage(himl2, 0, dx2, dy2);
|
|
|
|
ok(ret != 0, "SetDragCursorImage failed for {%d, %d}{%d, %d}\n",
|
|
|
|
dx1, dy1, dx2, dy2);
|
2004-10-07 19:34:56 +02:00
|
|
|
sprintf(loc, "SetDragCursorImage (%d,%d)\n", i, j);
|
|
|
|
show_image(hwnd, himl2, 0, max(SIZEX2, SIZEY2), loc, TRUE);
|
|
|
|
|
2004-08-22 03:59:55 +02:00
|
|
|
/* check new hotspot, it should be the same like the old one */
|
|
|
|
himlNew = ImageList_GetDragImage(NULL, &ppt);
|
|
|
|
ok(ppt.x == dx1 && ppt.y == dy1,
|
2006-10-13 15:17:40 +02:00
|
|
|
"Expected drag hotspot [%d,%d] got [%d,%d]\n",
|
2004-08-22 03:59:55 +02:00
|
|
|
dx1, dy1, ppt.x, ppt.y);
|
|
|
|
/* check size of new dragged image */
|
|
|
|
ImageList_GetIconSize(himlNew, &newx, &newy);
|
|
|
|
correctx = max(SIZEX1, max(SIZEX2 + dx2, SIZEX1 - dx2));
|
|
|
|
correcty = max(SIZEY1, max(SIZEY2 + dy2, SIZEY1 - dy2));
|
|
|
|
ok(newx == correctx && newy == correcty,
|
|
|
|
"Expected drag image size [%d,%d] got [%d,%d]\n",
|
|
|
|
correctx, correcty, newx, newy);
|
2004-10-07 19:34:56 +02:00
|
|
|
sprintf(loc, "GetDragImage (%d,%d)\n", i, j);
|
|
|
|
show_image(hwnd, himlNew, 0, max(correctx, correcty), loc, TRUE);
|
2004-08-22 03:59:55 +02:00
|
|
|
ImageList_EndDrag();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#undef SIZEX1
|
|
|
|
#undef SIZEY1
|
|
|
|
#undef SIZEX2
|
|
|
|
#undef SIZEY2
|
|
|
|
#undef HOTSPOTS_MAX
|
2004-10-07 19:34:56 +02:00
|
|
|
DestroyWindow(hwnd);
|
2004-08-22 03:59:55 +02:00
|
|
|
}
|
|
|
|
|
2004-08-24 20:41:52 +02:00
|
|
|
static BOOL DoTest1(void)
|
|
|
|
{
|
|
|
|
HIMAGELIST himl ;
|
|
|
|
|
|
|
|
HICON hicon1 ;
|
|
|
|
HICON hicon2 ;
|
|
|
|
HICON hicon3 ;
|
|
|
|
|
|
|
|
/* create an imagelist to play with */
|
|
|
|
himl = ImageList_Create(84,84,0x10,0,3);
|
2004-09-02 22:08:15 +02:00
|
|
|
ok(himl!=0,"failed to create imagelist\n");
|
2004-08-24 20:41:52 +02:00
|
|
|
|
|
|
|
/* load the icons to add to the image list */
|
|
|
|
hicon1 = CreateIcon(hinst, 32, 32, 1, 1, icon_bits, icon_bits);
|
2004-09-02 22:08:15 +02:00
|
|
|
ok(hicon1 != 0, "no hicon1\n");
|
2004-08-24 20:41:52 +02:00
|
|
|
hicon2 = CreateIcon(hinst, 32, 32, 1, 1, icon_bits, icon_bits);
|
2004-09-02 22:08:15 +02:00
|
|
|
ok(hicon2 != 0, "no hicon2\n");
|
2004-08-24 20:41:52 +02:00
|
|
|
hicon3 = CreateIcon(hinst, 32, 32, 1, 1, icon_bits, icon_bits);
|
2004-09-02 22:08:15 +02:00
|
|
|
ok(hicon3 != 0, "no hicon3\n");
|
2004-08-24 20:41:52 +02:00
|
|
|
|
|
|
|
/* remove when nothing exists */
|
2005-02-10 20:19:35 +01:00
|
|
|
ok(!ImageList_Remove(himl,0),"removed nonexistent icon\n");
|
2004-09-28 21:17:43 +02:00
|
|
|
/* removing everything from an empty imagelist should succeed */
|
2005-02-10 20:19:35 +01:00
|
|
|
ok(ImageList_RemoveAll(himl),"removed nonexistent icon\n");
|
2004-08-24 20:41:52 +02:00
|
|
|
|
|
|
|
/* add three */
|
2004-09-02 22:08:15 +02:00
|
|
|
ok(0==ImageList_AddIcon(himl, hicon1),"failed to add icon1\n");
|
|
|
|
ok(1==ImageList_AddIcon(himl, hicon2),"failed to add icon2\n");
|
|
|
|
ok(2==ImageList_AddIcon(himl, hicon3),"failed to add icon3\n");
|
2004-08-24 20:41:52 +02:00
|
|
|
|
2004-09-28 21:17:43 +02:00
|
|
|
/* remove an index out of range */
|
2005-02-10 20:19:35 +01:00
|
|
|
ok(!ImageList_Remove(himl,4711),"removed nonexistent icon\n");
|
2004-09-28 21:17:43 +02:00
|
|
|
|
2004-08-24 20:41:52 +02:00
|
|
|
/* remove three */
|
2004-09-02 22:08:15 +02:00
|
|
|
ok(ImageList_Remove(himl,0),"can't remove 0\n");
|
|
|
|
ok(ImageList_Remove(himl,0),"can't remove 0\n");
|
|
|
|
ok(ImageList_Remove(himl,0),"can't remove 0\n");
|
2004-08-24 20:41:52 +02:00
|
|
|
|
|
|
|
/* remove one extra */
|
2005-02-10 20:19:35 +01:00
|
|
|
ok(!ImageList_Remove(himl,0),"removed nonexistent icon\n");
|
2004-08-24 20:41:52 +02:00
|
|
|
|
2006-09-20 17:42:29 +02:00
|
|
|
/* check SetImageCount/GetImageCount */
|
|
|
|
ok(ImageList_SetImageCount(himl, 3), "couldn't increase image count\n");
|
|
|
|
ok(ImageList_GetImageCount(himl) == 3, "invalid image count after increase\n");
|
|
|
|
ok(ImageList_SetImageCount(himl, 1), "couldn't decrease image count\n");
|
|
|
|
ok(ImageList_GetImageCount(himl) == 1, "invalid image count after decrease to 1\n");
|
|
|
|
ok(ImageList_SetImageCount(himl, 0), "couldn't decrease image count\n");
|
|
|
|
ok(ImageList_GetImageCount(himl) == 0, "invalid image count after decrease to 0\n");
|
|
|
|
|
2004-08-24 20:41:52 +02:00
|
|
|
/* destroy it */
|
2004-09-02 22:08:15 +02:00
|
|
|
ok(ImageList_Destroy(himl),"destroy imagelist failed\n");
|
2004-08-24 20:41:52 +02:00
|
|
|
|
|
|
|
/* icons should be deleted by the imagelist */
|
2004-09-02 22:08:15 +02:00
|
|
|
ok(!DeleteObject(hicon1),"icon 1 wasn't deleted\n");
|
|
|
|
ok(!DeleteObject(hicon2),"icon 2 wasn't deleted\n");
|
|
|
|
ok(!DeleteObject(hicon3),"icon 3 wasn't deleted\n");
|
2004-08-24 20:41:52 +02:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL DoTest2(void)
|
|
|
|
{
|
|
|
|
HIMAGELIST himl ;
|
|
|
|
|
|
|
|
HICON hicon1 ;
|
|
|
|
HICON hicon2 ;
|
|
|
|
HICON hicon3 ;
|
|
|
|
|
|
|
|
/* create an imagelist to play with */
|
|
|
|
himl = ImageList_Create(84,84,0x10,0,3);
|
2004-09-02 22:08:15 +02:00
|
|
|
ok(himl!=0,"failed to create imagelist\n");
|
2004-08-24 20:41:52 +02:00
|
|
|
|
|
|
|
/* load the icons to add to the image list */
|
|
|
|
hicon1 = CreateIcon(hinst, 32, 32, 1, 1, icon_bits, icon_bits);
|
2004-09-02 22:08:15 +02:00
|
|
|
ok(hicon1 != 0, "no hicon1\n");
|
2004-08-24 20:41:52 +02:00
|
|
|
hicon2 = CreateIcon(hinst, 32, 32, 1, 1, icon_bits, icon_bits);
|
2004-09-02 22:08:15 +02:00
|
|
|
ok(hicon2 != 0, "no hicon2\n");
|
2004-08-24 20:41:52 +02:00
|
|
|
hicon3 = CreateIcon(hinst, 32, 32, 1, 1, icon_bits, icon_bits);
|
2004-09-02 22:08:15 +02:00
|
|
|
ok(hicon3 != 0, "no hicon3\n");
|
2004-08-24 20:41:52 +02:00
|
|
|
|
|
|
|
/* add three */
|
2004-09-02 22:08:15 +02:00
|
|
|
ok(0==ImageList_AddIcon(himl, hicon1),"failed to add icon1\n");
|
|
|
|
ok(1==ImageList_AddIcon(himl, hicon2),"failed to add icon2\n");
|
|
|
|
ok(2==ImageList_AddIcon(himl, hicon3),"failed to add icon3\n");
|
2004-08-24 20:41:52 +02:00
|
|
|
|
|
|
|
/* destroy it */
|
2004-09-02 22:08:15 +02:00
|
|
|
ok(ImageList_Destroy(himl),"destroy imagelist failed\n");
|
2004-08-24 20:41:52 +02:00
|
|
|
|
|
|
|
/* icons should be deleted by the imagelist */
|
2004-09-02 22:08:15 +02:00
|
|
|
ok(!DeleteObject(hicon1),"icon 1 wasn't deleted\n");
|
|
|
|
ok(!DeleteObject(hicon2),"icon 2 wasn't deleted\n");
|
|
|
|
ok(!DeleteObject(hicon3),"icon 3 wasn't deleted\n");
|
2004-08-24 20:41:52 +02:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL DoTest3(void)
|
|
|
|
{
|
2004-10-07 19:34:56 +02:00
|
|
|
HIMAGELIST himl;
|
2004-08-24 20:41:52 +02:00
|
|
|
|
2004-10-07 19:34:56 +02:00
|
|
|
HBITMAP hbm1;
|
|
|
|
HBITMAP hbm2;
|
|
|
|
HBITMAP hbm3;
|
2004-08-24 20:41:52 +02:00
|
|
|
|
|
|
|
IMAGELISTDRAWPARAMS imldp;
|
|
|
|
HDC hdc;
|
|
|
|
HWND hwndfortest;
|
|
|
|
|
2004-08-26 20:22:31 +02:00
|
|
|
if (!pImageList_DrawIndirect)
|
|
|
|
{
|
|
|
|
HMODULE hComCtl32 = LoadLibraryA("comctl32.dll");
|
2004-08-31 19:32:43 +02:00
|
|
|
pImageList_DrawIndirect = (void*)GetProcAddress(hComCtl32, "ImageList_DrawIndirect");
|
2004-08-26 20:22:31 +02:00
|
|
|
if (!pImageList_DrawIndirect)
|
|
|
|
{
|
|
|
|
trace("ImageList_DrawIndirect not available, skipping test\n");
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-08-24 20:41:52 +02:00
|
|
|
hwndfortest = create_a_window();
|
|
|
|
hdc = GetDC(hwndfortest);
|
|
|
|
ok(hdc!=NULL, "couldn't get DC\n");
|
|
|
|
|
|
|
|
/* create an imagelist to play with */
|
|
|
|
himl = ImageList_Create(48,48,0x10,0,3);
|
2004-09-02 22:08:15 +02:00
|
|
|
ok(himl!=0,"failed to create imagelist\n");
|
2004-08-24 20:41:52 +02:00
|
|
|
|
|
|
|
/* load the icons to add to the image list */
|
|
|
|
hbm1 = CreateBitmap(48, 48, 1, 1, bitmap_bits);
|
2004-09-02 22:08:15 +02:00
|
|
|
ok(hbm1 != 0, "no bitmap 1\n");
|
2004-08-24 20:41:52 +02:00
|
|
|
hbm2 = CreateBitmap(48, 48, 1, 1, bitmap_bits);
|
2004-09-02 22:08:15 +02:00
|
|
|
ok(hbm2 != 0, "no bitmap 2\n");
|
2004-08-24 20:41:52 +02:00
|
|
|
hbm3 = CreateBitmap(48, 48, 1, 1, bitmap_bits);
|
2004-09-02 22:08:15 +02:00
|
|
|
ok(hbm3 != 0, "no bitmap 3\n");
|
2004-08-24 20:41:52 +02:00
|
|
|
|
|
|
|
/* add three */
|
2004-09-02 22:08:15 +02:00
|
|
|
ok(0==ImageList_Add(himl, hbm1, 0),"failed to add bitmap 1\n");
|
|
|
|
ok(1==ImageList_Add(himl, hbm2, 0),"failed to add bitmap 2\n");
|
2004-08-24 20:41:52 +02:00
|
|
|
|
2004-09-02 22:08:15 +02:00
|
|
|
ok(ImageList_SetImageCount(himl,3),"Setimage count failed\n");
|
|
|
|
/*ok(2==ImageList_Add(himl, hbm3, NULL),"failed to add bitmap 3\n"); */
|
|
|
|
ok(ImageList_Replace(himl, 2, hbm3, 0),"failed to replace bitmap 3\n");
|
2004-08-24 20:41:52 +02:00
|
|
|
|
2004-10-07 19:34:56 +02:00
|
|
|
memset(&imldp, 0, sizeof (imldp));
|
2004-09-02 22:08:15 +02:00
|
|
|
ok(!pImageList_DrawIndirect(&imldp), "zero data succeeded!\n");
|
2004-10-07 19:34:56 +02:00
|
|
|
imldp.cbSize = sizeof (imldp);
|
2004-09-02 22:08:15 +02:00
|
|
|
ok(!pImageList_DrawIndirect(&imldp), "zero hdc succeeded!\n");
|
2004-08-24 20:41:52 +02:00
|
|
|
imldp.hdcDst = hdc;
|
2004-09-02 22:08:15 +02:00
|
|
|
ok(!pImageList_DrawIndirect(&imldp),"zero himl succeeded!\n");
|
2004-08-24 20:41:52 +02:00
|
|
|
imldp.himl = himl;
|
2004-10-07 19:34:56 +02:00
|
|
|
if (!pImageList_DrawIndirect(&imldp))
|
|
|
|
{
|
2004-10-23 00:27:51 +02:00
|
|
|
/* Earlier versions of native comctl32 use a smaller structure */
|
2004-10-07 19:34:56 +02:00
|
|
|
imldp.cbSize -= 3 * sizeof(DWORD);
|
|
|
|
ok(pImageList_DrawIndirect(&imldp),"DrawIndirect should succeed\n");
|
|
|
|
}
|
|
|
|
REDRAW(hwndfortest);
|
|
|
|
WAIT;
|
|
|
|
|
2004-08-24 20:41:52 +02:00
|
|
|
imldp.fStyle = SRCCOPY;
|
|
|
|
imldp.rgbBk = CLR_DEFAULT;
|
|
|
|
imldp.rgbFg = CLR_DEFAULT;
|
|
|
|
imldp.y = 100;
|
|
|
|
imldp.x = 100;
|
2004-10-07 19:34:56 +02:00
|
|
|
ok(pImageList_DrawIndirect(&imldp),"should succeed\n");
|
2004-08-24 20:41:52 +02:00
|
|
|
imldp.i ++;
|
2004-10-07 19:34:56 +02:00
|
|
|
ok(pImageList_DrawIndirect(&imldp),"should succeed\n");
|
2004-08-24 20:41:52 +02:00
|
|
|
imldp.i ++;
|
2004-10-07 19:34:56 +02:00
|
|
|
ok(pImageList_DrawIndirect(&imldp),"should succeed\n");
|
2004-08-24 20:41:52 +02:00
|
|
|
imldp.i ++;
|
2004-09-02 22:08:15 +02:00
|
|
|
ok(!pImageList_DrawIndirect(&imldp),"should fail\n");
|
2004-08-24 20:41:52 +02:00
|
|
|
|
|
|
|
/* remove three */
|
2004-09-02 22:08:15 +02:00
|
|
|
ok(ImageList_Remove(himl, 0), "removing 1st bitmap\n");
|
|
|
|
ok(ImageList_Remove(himl, 0), "removing 2nd bitmap\n");
|
|
|
|
ok(ImageList_Remove(himl, 0), "removing 3rd bitmap\n");
|
2004-08-24 20:41:52 +02:00
|
|
|
|
|
|
|
/* destroy it */
|
2004-09-02 22:08:15 +02:00
|
|
|
ok(ImageList_Destroy(himl),"destroy imagelist failed\n");
|
2004-08-24 20:41:52 +02:00
|
|
|
|
2004-10-07 19:34:56 +02:00
|
|
|
/* bitmaps should not be deleted by the imagelist */
|
2004-09-02 22:08:15 +02:00
|
|
|
ok(DeleteObject(hbm1),"bitmap 1 can't be deleted\n");
|
|
|
|
ok(DeleteObject(hbm2),"bitmap 2 can't be deleted\n");
|
|
|
|
ok(DeleteObject(hbm3),"bitmap 3 can't be deleted\n");
|
2004-08-24 20:41:52 +02:00
|
|
|
|
|
|
|
ReleaseDC(hwndfortest, hdc);
|
|
|
|
DestroyWindow(hwndfortest);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2005-06-20 16:18:03 +02:00
|
|
|
static void testMerge(void)
|
2004-10-07 19:34:56 +02:00
|
|
|
{
|
|
|
|
HIMAGELIST himl1, himl2, hmerge;
|
|
|
|
HICON hicon1;
|
|
|
|
HWND hwnd = create_a_window();
|
|
|
|
|
|
|
|
himl1 = ImageList_Create(32,32,0,0,3);
|
|
|
|
ok(himl1 != NULL,"failed to create himl1\n");
|
|
|
|
|
|
|
|
himl2 = ImageList_Create(32,32,0,0,3);
|
|
|
|
ok(himl2 != NULL,"failed to create himl2\n");
|
|
|
|
|
|
|
|
hicon1 = CreateIcon(hinst, 32, 32, 1, 1, icon_bits, icon_bits);
|
|
|
|
ok(hicon1 != NULL, "failed to create hicon1\n");
|
|
|
|
|
|
|
|
if (!himl1 || !himl2 || !hicon1)
|
|
|
|
return;
|
|
|
|
|
|
|
|
ok(0==ImageList_AddIcon(himl2, hicon1),"add icon1 to himl2 failed\n");
|
|
|
|
check_bits(hwnd, himl2, 0, 32, icon_bits, "add icon1 to himl2");
|
|
|
|
|
|
|
|
/* If himl1 has no images, merge still succeeds */
|
|
|
|
hmerge = ImageList_Merge(himl1, -1, himl2, 0, 0, 0);
|
|
|
|
ok(hmerge != NULL, "merge himl1,-1 failed\n");
|
|
|
|
check_bits(hwnd, hmerge, 0, 32, empty_bits, "merge himl1,-1");
|
|
|
|
if (hmerge) ImageList_Destroy(hmerge);
|
|
|
|
|
|
|
|
hmerge = ImageList_Merge(himl1, 0, himl2, 0, 0, 0);
|
|
|
|
ok(hmerge != NULL,"merge himl1,0 failed\n");
|
|
|
|
check_bits(hwnd, hmerge, 0, 32, empty_bits, "merge himl1,0");
|
|
|
|
if (hmerge) ImageList_Destroy(hmerge);
|
|
|
|
|
2004-10-23 00:27:51 +02:00
|
|
|
/* Same happens if himl2 is empty */
|
2004-10-07 19:34:56 +02:00
|
|
|
ImageList_Destroy(himl2);
|
|
|
|
himl2 = ImageList_Create(32,32,0,0,3);
|
|
|
|
ok(himl2 != NULL,"failed to recreate himl2\n");
|
|
|
|
if (!himl2)
|
|
|
|
return;
|
|
|
|
|
|
|
|
hmerge = ImageList_Merge(himl1, -1, himl2, -1, 0, 0);
|
|
|
|
ok(hmerge != NULL, "merge himl2,-1 failed\n");
|
|
|
|
check_bits(hwnd, hmerge, 0, 32, empty_bits, "merge himl2,-1");
|
|
|
|
if (hmerge) ImageList_Destroy(hmerge);
|
|
|
|
|
|
|
|
hmerge = ImageList_Merge(himl1, -1, himl2, 0, 0, 0);
|
|
|
|
ok(hmerge != NULL, "merge himl2,0 failed\n");
|
|
|
|
check_bits(hwnd, hmerge, 0, 32, empty_bits, "merge himl2,0");
|
|
|
|
if (hmerge) ImageList_Destroy(hmerge);
|
|
|
|
|
|
|
|
/* Now try merging an image with itself */
|
|
|
|
ok(0==ImageList_AddIcon(himl2, hicon1),"re-add icon1 to himl2 failed\n");
|
|
|
|
|
|
|
|
hmerge = ImageList_Merge(himl2, 0, himl2, 0, 0, 0);
|
|
|
|
ok(hmerge != NULL, "merge himl2 with itself failed\n");
|
|
|
|
check_bits(hwnd, hmerge, 0, 32, empty_bits, "merge himl2 with itself");
|
|
|
|
if (hmerge) ImageList_Destroy(hmerge);
|
|
|
|
|
|
|
|
/* Try merging 2 different image lists */
|
|
|
|
ok(0==ImageList_AddIcon(himl1, hicon1),"add icon1 to himl1 failed\n");
|
|
|
|
|
|
|
|
hmerge = ImageList_Merge(himl1, 0, himl2, 0, 0, 0);
|
|
|
|
ok(hmerge != NULL, "merge himl1 with himl2 failed\n");
|
|
|
|
check_bits(hwnd, hmerge, 0, 32, empty_bits, "merge himl1 with himl2");
|
|
|
|
if (hmerge) ImageList_Destroy(hmerge);
|
|
|
|
|
|
|
|
hmerge = ImageList_Merge(himl1, 0, himl2, 0, 8, 16);
|
|
|
|
ok(hmerge != NULL, "merge himl1 with himl2 8,16 failed\n");
|
|
|
|
check_bits(hwnd, hmerge, 0, 32, empty_bits, "merge himl1 with himl2, 8,16");
|
|
|
|
if (hmerge) ImageList_Destroy(hmerge);
|
|
|
|
|
|
|
|
ImageList_Destroy(himl1);
|
|
|
|
ImageList_Destroy(himl2);
|
|
|
|
DeleteObject(hicon1);
|
|
|
|
DestroyWindow(hwnd);
|
|
|
|
}
|
|
|
|
|
2004-08-22 03:59:55 +02:00
|
|
|
START_TEST(imagelist)
|
|
|
|
{
|
|
|
|
desktopDC=GetDC(NULL);
|
2004-08-24 20:41:52 +02:00
|
|
|
hinst = GetModuleHandleA(NULL);
|
2004-08-22 03:59:55 +02:00
|
|
|
|
|
|
|
InitCommonControls();
|
|
|
|
|
|
|
|
testHotspot();
|
2004-08-24 20:41:52 +02:00
|
|
|
DoTest1();
|
|
|
|
DoTest2();
|
|
|
|
DoTest3();
|
2004-10-07 19:34:56 +02:00
|
|
|
testMerge();
|
2004-08-22 03:59:55 +02:00
|
|
|
}
|