4 * Copyright 2006 Mike McCormack for CodeWeavers
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 #include "wine/test.h"
27 static void test_images(void)
29 HWND hwnd, hwndparent = 0;
35 static CHAR hello[] = "hello";
37 himl = ImageList_Create(40, 40, 0, 4, 4);
38 ok(himl != NULL, "failed to create imagelist\n");
40 hbmp = CreateBitmap(40, 40, 1, 1, NULL);
41 ok(hbmp != NULL, "failed to create bitmap\n");
43 r = ImageList_Add(himl, hbmp, 0);
44 ok(r == 0, "should be zero\n");
46 hwnd = CreateWindowEx(0, "SysListView32", "foo", LVS_OWNERDRAWFIXED,
47 10, 10, 100, 200, hwndparent, NULL, NULL, NULL);
48 ok(hwnd != NULL, "failed to create listview window\n");
50 r = SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, 0x940);
51 ok(r == 0, "should return zero\n");
53 r = SendMessage(hwnd, LVM_SETIMAGELIST, 0, (LPARAM)himl);
54 ok(r == 0, "should return zero\n");
56 r = SendMessage(hwnd, LVM_SETICONSPACING, 0, MAKELONG(100,50));
57 /* returns dimensions */
59 r = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
60 ok(r == 0, "should be zero items\n");
62 item.mask = LVIF_IMAGE | LVIF_TEXT;
67 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
68 ok(r == -1, "should fail\n");
72 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
73 ok(r == 0, "should not fail\n");
75 memset(&r1, 0, sizeof r1);
77 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM) &r1);
79 r = SendMessage(hwnd, LVM_DELETEALLITEMS, 0, 0);
80 ok(r == TRUE, "should not fail\n");
84 r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item);
85 ok(r == 0, "should not fail\n");
87 memset(&r2, 0, sizeof r2);
89 r = SendMessage(hwnd, LVM_GETITEMRECT, 0, (LPARAM) &r2);
91 ok(!memcmp(&r1, &r2, sizeof r1), "rectangle should be the same\n");
96 static void test_checkboxes(void)
98 HWND hwnd, hwndparent = 0;
101 static CHAR text[] = "Text",
105 hwnd = CreateWindowEx(0, "SysListView32", "foo", LVS_REPORT,
106 10, 10, 100, 200, hwndparent, NULL, NULL, NULL);
107 ok(hwnd != NULL, "failed to create listview window\n");
109 /* first without LVS_EX_CHECKBOXES set and an item and check that state is preserved */
110 item.mask = LVIF_TEXT | LVIF_STATE;
111 item.stateMask = 0xffff;
116 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
117 ok(r == 0, "ret %d\n", r);
120 item.mask = LVIF_STATE;
121 item.stateMask = 0xffff;
122 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
123 ok(item.state == 0xfccc, "state %x\n", item.state);
125 /* Don't set LVIF_STATE */
126 item.mask = LVIF_TEXT;
127 item.stateMask = 0xffff;
132 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
133 ok(r == 1, "ret %d\n", r);
136 item.mask = LVIF_STATE;
137 item.stateMask = 0xffff;
138 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
139 ok(item.state == 0, "state %x\n", item.state);
141 r = SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_CHECKBOXES, LVS_EX_CHECKBOXES);
142 ok(r == 0, "should return zero\n");
144 /* Having turned on checkboxes, check that all existing items are set to 0x1000 (unchecked) */
146 item.mask = LVIF_STATE;
147 item.stateMask = 0xffff;
148 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
149 ok(item.state == 0x1ccc, "state %x\n", item.state);
151 /* Now add an item without specifying a state and check that its state goes to 0x1000 */
153 item.mask = LVIF_TEXT;
155 item.pszText = text2;
156 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
157 ok(r == 2, "ret %d\n", r);
160 item.mask = LVIF_STATE;
161 item.stateMask = 0xffff;
162 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
163 ok(item.state == 0x1000, "state %x\n", item.state);
165 /* Add a further item this time specifying a state and still its state goes to 0x1000 */
167 item.mask = LVIF_TEXT | LVIF_STATE;
168 item.stateMask = 0xffff;
170 item.pszText = text3;
171 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
172 ok(r == 3, "ret %d\n", r);
175 item.mask = LVIF_STATE;
176 item.stateMask = 0xffff;
177 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
178 ok(item.state == 0x1aaa, "state %x\n", item.state);
180 /* Set an item's state to checked */
182 item.mask = LVIF_STATE;
183 item.stateMask = 0xf000;
185 r = SendMessage(hwnd, LVM_SETITEMA, 0, (LPARAM) &item);
188 item.mask = LVIF_STATE;
189 item.stateMask = 0xffff;
190 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
191 ok(item.state == 0x2aaa, "state %x\n", item.state);
193 /* Check that only the bits we asked for are returned,
194 * and that all the others are set to zero
197 item.mask = LVIF_STATE;
198 item.stateMask = 0xf000;
200 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
201 ok(item.state == 0x2000, "state %x\n", item.state);
203 /* Set the style again and check that doesn't change an item's state */
204 r = SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_CHECKBOXES, LVS_EX_CHECKBOXES);
205 ok(r == LVS_EX_CHECKBOXES, "ret %x\n", r);
208 item.mask = LVIF_STATE;
209 item.stateMask = 0xffff;
210 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
211 ok(item.state == 0x2aaa, "state %x\n", item.state);
213 /* Unsetting the checkbox extended style doesn't change an item's state */
214 r = SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_CHECKBOXES, 0);
215 ok(r == LVS_EX_CHECKBOXES, "ret %x\n", r);
218 item.mask = LVIF_STATE;
219 item.stateMask = 0xffff;
220 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
221 ok(item.state == 0x2aaa, "state %x\n", item.state);
223 /* Now setting the style again will change an item's state */
224 r = SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_CHECKBOXES, LVS_EX_CHECKBOXES);
225 ok(r == 0, "ret %x\n", r);
228 item.mask = LVIF_STATE;
229 item.stateMask = 0xffff;
230 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
231 ok(item.state == 0x1aaa, "state %x\n", item.state);
236 static void test_items(void)
238 const LPARAM lparamTest = 0x42;
239 HWND hwnd, hwndparent = 0;
243 static CHAR text[] = "Text";
245 hwnd = CreateWindowEx(0, "SysListView32", "foo", LVS_REPORT,
246 10, 10, 100, 200, hwndparent, NULL, NULL, NULL);
247 ok(hwnd != NULL, "failed to create listview window\n");
250 * Test setting/getting item params
253 /* Set up two columns */
254 column.mask = LVCF_SUBITEM;
256 r = SendMessage(hwnd, LVM_INSERTCOLUMNA, 0, (LPARAM)&column);
257 ok(r == 0, "ret %d\n", r);
259 r = SendMessage(hwnd, LVM_INSERTCOLUMNA, 1, (LPARAM)&column);
260 ok(r == 1, "ret %d\n", r);
262 /* Insert an item with just a param */
263 memset (&item, 0xaa, sizeof (item));
264 item.mask = LVIF_PARAM;
267 item.lParam = lparamTest;
268 r = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
269 ok(r == 0, "ret %d\n", r);
271 /* Test getting of the param */
272 memset (&item, 0xaa, sizeof (item));
273 item.mask = LVIF_PARAM;
276 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
277 ok(r != 0, "ret %d\n", r);
278 ok(item.lParam == lparamTest, "got lParam %lx, expected %lx\n", item.lParam, lparamTest);
280 /* Set up a subitem */
281 memset (&item, 0xaa, sizeof (item));
282 item.mask = LVIF_TEXT;
286 r = SendMessage(hwnd, LVM_SETITEMA, 0, (LPARAM) &item);
287 ok(r != 0, "ret %d\n", r);
289 /* Query param from subitem: returns main item param */
290 memset (&item, 0xaa, sizeof (item));
291 item.mask = LVIF_PARAM;
294 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
295 ok(r != 0, "ret %d\n", r);
296 ok(item.lParam == lparamTest, "got lParam %lx, expected %lx\n", item.lParam, lparamTest);
298 /* Set up param on first subitem: no effect */
299 memset (&item, 0xaa, sizeof (item));
300 item.mask = LVIF_PARAM;
303 item.lParam = lparamTest+1;
304 r = SendMessage(hwnd, LVM_SETITEMA, 0, (LPARAM) &item);
305 ok(r == 0, "ret %d\n", r);
307 /* Query param from subitem again: should still return main item param */
308 memset (&item, 0xaa, sizeof (item));
309 item.mask = LVIF_PARAM;
312 r = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
313 ok(r != 0, "ret %d\n", r);
314 ok(item.lParam == lparamTest, "got lParam %lx, expected %lx\n", item.lParam, lparamTest);
316 /**** Some tests of state highlighting ****/
317 memset (&item, 0xaa, sizeof (item));
318 item.mask = LVIF_STATE;
321 item.state = LVIS_SELECTED;
322 item.stateMask = LVIS_SELECTED | LVIS_DROPHILITED;
323 r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM) &item);
324 ok(r != 0, "ret %d\n", r);
326 item.state = LVIS_DROPHILITED;
327 r = SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM) &item);
328 ok(r != 0, "ret %d\n", r);
330 memset (&item, 0xaa, sizeof (item));
331 item.mask = LVIF_STATE;
335 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
336 ok(r != 0, "ret %d\n", r);
337 ok(item.state == LVIS_SELECTED, "got state %x, expected %x\n", item.state, LVIS_SELECTED);
339 r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item);
340 ok(r != 0, "ret %d\n", r);
341 todo_wine ok(item.state == LVIS_DROPHILITED, "got state %x, expected %x\n", item.state, LVIS_DROPHILITED);
348 INITCOMMONCONTROLSEX icc;
351 icc.dwSize = sizeof icc;
352 InitCommonControlsEx(&icc);