394 lines
13 KiB
C
394 lines
13 KiB
C
/*
|
|
* ListView tests
|
|
*
|
|
* Copyright 2006 Mike McCormack for CodeWeavers
|
|
*
|
|
* 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
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
*/
|
|
|
|
#include <stdio.h>
|
|
#include <windows.h>
|
|
#include <commctrl.h>
|
|
|
|
#include "wine/test.h"
|
|
|
|
static void test_images(void)
|
|
{
|
|
HWND hwnd, hwndparent = 0;
|
|
DWORD r;
|
|
LVITEM item;
|
|
HIMAGELIST himl;
|
|
HBITMAP hbmp;
|
|
RECT r1, r2;
|
|
static CHAR hello[] = "hello";
|
|
|
|
himl = ImageList_Create(40, 40, 0, 4, 4);
|
|
ok(himl != NULL, "failed to create imagelist\n");
|
|
|
|
hbmp = CreateBitmap(40, 40, 1, 1, NULL);
|
|
ok(hbmp != NULL, "failed to create bitmap\n");
|
|
|
|
r = ImageList_Add(himl, hbmp, 0);
|
|
ok(r == 0, "should be zero\n");
|
|
|
|
hwnd = CreateWindowEx(0, "SysListView32", "foo", LVS_OWNERDRAWFIXED,
|
|
10, 10, 100, 200, hwndparent, NULL, NULL, NULL);
|
|
ok(hwnd != NULL, "failed to create listview window\n");
|
|
|
|
r = SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, 0x940);
|
|
ok(r == 0, "should return zero\n");
|
|
|
|
r = SendMessage(hwnd, LVM_SETIMAGELIST, 0, (LPARAM)himl);
|
|
ok(r == 0, "should return zero\n");
|
|
|
|
r = SendMessage(hwnd, LVM_SETICONSPACING, 0, MAKELONG(100,50));
|
|
/* returns dimensions */
|
|
|
|
r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
|
|
ok(r == 0, "should be zero items\n");
|
|
|
|
item.mask = LVIF_IMAGE | LVIF_TEXT;
|
|
item.iItem = 0;
|
|
item.iSubItem = 1;
|
|
item.iImage = 0;
|
|
item.pszText = 0;
|
|
r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
|
|
ok(r == -1, "should fail\n");
|
|
|
|
item.iSubItem = 0;
|
|
item.pszText = hello;
|
|
r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
|
|
ok(r == 0, "should not fail\n");
|
|
|
|
memset(&r1, 0, sizeof r1);
|
|
r1.left = LVIR_ICON;
|
|
r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM) &r1);
|
|
|
|
r = SendMessage(hwnd, LVM_DELETEALLITEMS, 0, 0);
|
|
ok(r == TRUE, "should not fail\n");
|
|
|
|
item.iSubItem = 0;
|
|
item.pszText = hello;
|
|
r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
|
|
ok(r == 0, "should not fail\n");
|
|
|
|
memset(&r2, 0, sizeof r2);
|
|
r2.left = LVIR_ICON;
|
|
r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM) &r2);
|
|
|
|
ok(!memcmp(&r1, &r2, sizeof r1), "rectangle should be the same\n");
|
|
|
|
DestroyWindow(hwnd);
|
|
}
|
|
|
|
static void test_checkboxes(void)
|
|
{
|
|
HWND hwnd, hwndparent = 0;
|
|
LVITEMA item;
|
|
DWORD r;
|
|
static CHAR text[] = "Text",
|
|
text2[] = "Text2",
|
|
text3[] = "Text3";
|
|
|
|
hwnd = CreateWindowEx(0, "SysListView32", "foo", LVS_REPORT,
|
|
10, 10, 100, 200, hwndparent, NULL, NULL, NULL);
|
|
ok(hwnd != NULL, "failed to create listview window\n");
|
|
|
|
/* first without LVS_EX_CHECKBOXES set and an item and check that state is preserved */
|
|
item.mask = LVIF_TEXT | LVIF_STATE;
|
|
item.stateMask = 0xffff;
|
|
item.state = 0xfccc;
|
|
item.iItem = 0;
|
|
item.iSubItem = 0;
|
|
item.pszText = text;
|
|
r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
|
|
ok(r == 0, "ret %d\n", r);
|
|
|
|
item.iItem = 0;
|
|
item.mask = LVIF_STATE;
|
|
item.stateMask = 0xffff;
|
|
r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
|
|
ok(item.state == 0xfccc, "state %x\n", item.state);
|
|
|
|
/* Don't set LVIF_STATE */
|
|
item.mask = LVIF_TEXT;
|
|
item.stateMask = 0xffff;
|
|
item.state = 0xfccc;
|
|
item.iItem = 1;
|
|
item.iSubItem = 0;
|
|
item.pszText = text;
|
|
r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
|
|
ok(r == 1, "ret %d\n", r);
|
|
|
|
item.iItem = 1;
|
|
item.mask = LVIF_STATE;
|
|
item.stateMask = 0xffff;
|
|
r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
|
|
ok(item.state == 0, "state %x\n", item.state);
|
|
|
|
r = SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_CHECKBOXES, LVS_EX_CHECKBOXES);
|
|
ok(r == 0, "should return zero\n");
|
|
|
|
/* Having turned on checkboxes, check that all existing items are set to 0x1000 (unchecked) */
|
|
item.iItem = 0;
|
|
item.mask = LVIF_STATE;
|
|
item.stateMask = 0xffff;
|
|
r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
|
|
ok(item.state == 0x1ccc, "state %x\n", item.state);
|
|
|
|
/* Now add an item without specifying a state and check that its state goes to 0x1000 */
|
|
item.iItem = 2;
|
|
item.mask = LVIF_TEXT;
|
|
item.state = 0;
|
|
item.pszText = text2;
|
|
r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
|
|
ok(r == 2, "ret %d\n", r);
|
|
|
|
item.iItem = 2;
|
|
item.mask = LVIF_STATE;
|
|
item.stateMask = 0xffff;
|
|
r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
|
|
ok(item.state == 0x1000, "state %x\n", item.state);
|
|
|
|
/* Add a further item this time specifying a state and still its state goes to 0x1000 */
|
|
item.iItem = 3;
|
|
item.mask = LVIF_TEXT | LVIF_STATE;
|
|
item.stateMask = 0xffff;
|
|
item.state = 0x2aaa;
|
|
item.pszText = text3;
|
|
r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
|
|
ok(r == 3, "ret %d\n", r);
|
|
|
|
item.iItem = 3;
|
|
item.mask = LVIF_STATE;
|
|
item.stateMask = 0xffff;
|
|
r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
|
|
ok(item.state == 0x1aaa, "state %x\n", item.state);
|
|
|
|
/* Set an item's state to checked */
|
|
item.iItem = 3;
|
|
item.mask = LVIF_STATE;
|
|
item.stateMask = 0xf000;
|
|
item.state = 0x2000;
|
|
r = SendMessage(hwnd, LVM_SETITEMA, 0, (LPARAM) &item);
|
|
|
|
item.iItem = 3;
|
|
item.mask = LVIF_STATE;
|
|
item.stateMask = 0xffff;
|
|
r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
|
|
ok(item.state == 0x2aaa, "state %x\n", item.state);
|
|
|
|
/* Check that only the bits we asked for are returned,
|
|
* and that all the others are set to zero
|
|
*/
|
|
item.iItem = 3;
|
|
item.mask = LVIF_STATE;
|
|
item.stateMask = 0xf000;
|
|
item.state = 0xffff;
|
|
r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
|
|
ok(item.state == 0x2000, "state %x\n", item.state);
|
|
|
|
/* Set the style again and check that doesn't change an item's state */
|
|
r = SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_CHECKBOXES, LVS_EX_CHECKBOXES);
|
|
ok(r == LVS_EX_CHECKBOXES, "ret %x\n", r);
|
|
|
|
item.iItem = 3;
|
|
item.mask = LVIF_STATE;
|
|
item.stateMask = 0xffff;
|
|
r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
|
|
ok(item.state == 0x2aaa, "state %x\n", item.state);
|
|
|
|
/* Unsetting the checkbox extended style doesn't change an item's state */
|
|
r = SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_CHECKBOXES, 0);
|
|
ok(r == LVS_EX_CHECKBOXES, "ret %x\n", r);
|
|
|
|
item.iItem = 3;
|
|
item.mask = LVIF_STATE;
|
|
item.stateMask = 0xffff;
|
|
r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
|
|
ok(item.state == 0x2aaa, "state %x\n", item.state);
|
|
|
|
/* Now setting the style again will change an item's state */
|
|
r = SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_CHECKBOXES, LVS_EX_CHECKBOXES);
|
|
ok(r == 0, "ret %x\n", r);
|
|
|
|
item.iItem = 3;
|
|
item.mask = LVIF_STATE;
|
|
item.stateMask = 0xffff;
|
|
r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
|
|
ok(item.state == 0x1aaa, "state %x\n", item.state);
|
|
|
|
DestroyWindow(hwnd);
|
|
}
|
|
|
|
static void test_items(void)
|
|
{
|
|
const LPARAM lparamTest = 0x42;
|
|
HWND hwnd, hwndparent = 0;
|
|
LVITEMA item;
|
|
LVCOLUMNA column;
|
|
DWORD r;
|
|
static CHAR text[] = "Text";
|
|
|
|
hwnd = CreateWindowEx(0, "SysListView32", "foo", LVS_REPORT,
|
|
10, 10, 100, 200, hwndparent, NULL, NULL, NULL);
|
|
ok(hwnd != NULL, "failed to create listview window\n");
|
|
|
|
/*
|
|
* Test setting/getting item params
|
|
*/
|
|
|
|
/* Set up two columns */
|
|
column.mask = LVCF_SUBITEM;
|
|
column.iSubItem = 0;
|
|
r = SendMessage(hwnd, LVM_INSERTCOLUMNA, 0, (LPARAM)&column);
|
|
ok(r == 0, "ret %d\n", r);
|
|
column.iSubItem = 1;
|
|
r = SendMessage(hwnd, LVM_INSERTCOLUMNA, 1, (LPARAM)&column);
|
|
ok(r == 1, "ret %d\n", r);
|
|
|
|
/* Insert an item with just a param */
|
|
memset (&item, 0xaa, sizeof (item));
|
|
item.mask = LVIF_PARAM;
|
|
item.iItem = 0;
|
|
item.iSubItem = 0;
|
|
item.lParam = lparamTest;
|
|
r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
|
|
ok(r == 0, "ret %d\n", r);
|
|
|
|
/* Test getting of the param */
|
|
memset (&item, 0xaa, sizeof (item));
|
|
item.mask = LVIF_PARAM;
|
|
item.iItem = 0;
|
|
item.iSubItem = 0;
|
|
r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
|
|
ok(r != 0, "ret %d\n", r);
|
|
ok(item.lParam == lparamTest, "got lParam %lx, expected %lx\n", item.lParam, lparamTest);
|
|
|
|
/* Set up a subitem */
|
|
memset (&item, 0xaa, sizeof (item));
|
|
item.mask = LVIF_TEXT;
|
|
item.iItem = 0;
|
|
item.iSubItem = 1;
|
|
item.pszText = text;
|
|
r = SendMessage(hwnd, LVM_SETITEMA, 0, (LPARAM) &item);
|
|
ok(r != 0, "ret %d\n", r);
|
|
|
|
/* Query param from subitem: returns main item param */
|
|
memset (&item, 0xaa, sizeof (item));
|
|
item.mask = LVIF_PARAM;
|
|
item.iItem = 0;
|
|
item.iSubItem = 1;
|
|
r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
|
|
ok(r != 0, "ret %d\n", r);
|
|
ok(item.lParam == lparamTest, "got lParam %lx, expected %lx\n", item.lParam, lparamTest);
|
|
|
|
/* Set up param on first subitem: no effect */
|
|
memset (&item, 0xaa, sizeof (item));
|
|
item.mask = LVIF_PARAM;
|
|
item.iItem = 0;
|
|
item.iSubItem = 1;
|
|
item.lParam = lparamTest+1;
|
|
r = SendMessage(hwnd, LVM_SETITEMA, 0, (LPARAM) &item);
|
|
ok(r == 0, "ret %d\n", r);
|
|
|
|
/* Query param from subitem again: should still return main item param */
|
|
memset (&item, 0xaa, sizeof (item));
|
|
item.mask = LVIF_PARAM;
|
|
item.iItem = 0;
|
|
item.iSubItem = 1;
|
|
r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
|
|
ok(r != 0, "ret %d\n", r);
|
|
ok(item.lParam == lparamTest, "got lParam %lx, expected %lx\n", item.lParam, lparamTest);
|
|
|
|
/**** Some tests of state highlighting ****/
|
|
memset (&item, 0xaa, sizeof (item));
|
|
item.mask = LVIF_STATE;
|
|
item.iItem = 0;
|
|
item.iSubItem = 0;
|
|
item.state = LVIS_SELECTED;
|
|
item.stateMask = LVIS_SELECTED | LVIS_DROPHILITED;
|
|
r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM) &item);
|
|
ok(r != 0, "ret %d\n", r);
|
|
item.iSubItem = 1;
|
|
item.state = LVIS_DROPHILITED;
|
|
r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM) &item);
|
|
ok(r != 0, "ret %d\n", r);
|
|
|
|
memset (&item, 0xaa, sizeof (item));
|
|
item.mask = LVIF_STATE;
|
|
item.iItem = 0;
|
|
item.iSubItem = 0;
|
|
item.stateMask = -1;
|
|
r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
|
|
ok(r != 0, "ret %d\n", r);
|
|
ok(item.state == LVIS_SELECTED, "got state %x, expected %x\n", item.state, LVIS_SELECTED);
|
|
item.iSubItem = 1;
|
|
r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
|
|
ok(r != 0, "ret %d\n", r);
|
|
todo_wine ok(item.state == LVIS_DROPHILITED, "got state %x, expected %x\n", item.state, LVIS_DROPHILITED);
|
|
|
|
DestroyWindow(hwnd);
|
|
}
|
|
|
|
/* test setting imagelist between WM_NCCREATE and WM_CREATE */
|
|
static WNDPROC listviewWndProc;
|
|
static HIMAGELIST test_create_imagelist;
|
|
|
|
static LRESULT CALLBACK create_test_wndproc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
|
{
|
|
if (uMsg == WM_CREATE)
|
|
{
|
|
LPCREATESTRUCT lpcs = (LPCREATESTRUCT)lParam;
|
|
lpcs->style |= LVS_REPORT;
|
|
SendMessage(hwnd, LVM_SETIMAGELIST, 0, (LPARAM)test_create_imagelist);
|
|
}
|
|
return CallWindowProc(listviewWndProc, hwnd, uMsg, wParam, lParam);
|
|
}
|
|
|
|
static void test_create()
|
|
{
|
|
HWND hList;
|
|
HWND hHeader;
|
|
WNDCLASSEX cls;
|
|
cls.cbSize = sizeof(WNDCLASSEX);
|
|
ok(GetClassInfoEx(GetModuleHandle(NULL), "SysListView32", &cls), "GetClassInfoEx failed\n");
|
|
listviewWndProc = cls.lpfnWndProc;
|
|
cls.lpfnWndProc = create_test_wndproc;
|
|
cls.lpszClassName = "MyListView32";
|
|
ok(RegisterClassEx(&cls), "RegisterClassEx failed\n");
|
|
|
|
test_create_imagelist = ImageList_Create(16, 16, 0, 5, 10);
|
|
hList = CreateWindow("MyListView32", "Test", WS_VISIBLE, 0, 0, 100, 100, NULL, NULL, GetModuleHandle(NULL), 0);
|
|
ok((HIMAGELIST)SendMessage(hList, LVM_GETIMAGELIST, 0, 0) == test_create_imagelist, "Image list not obtained\n");
|
|
hHeader = (HWND)SendMessage(hList, LVM_GETHEADER, 0, 0);
|
|
ok(IsWindow(hHeader) && IsWindowVisible(hHeader), "Listview not in report mode\n");
|
|
DestroyWindow(hList);
|
|
}
|
|
|
|
START_TEST(listview)
|
|
{
|
|
INITCOMMONCONTROLSEX icc;
|
|
|
|
icc.dwICC = 0;
|
|
icc.dwSize = sizeof icc;
|
|
InitCommonControlsEx(&icc);
|
|
|
|
test_images();
|
|
test_checkboxes();
|
|
test_items();
|
|
test_create();
|
|
}
|