[COMCTL32_WINETEST]
[reactos.git] / rostests / winetests / comctl32 / listview.c
1 /*
2 * ListView tests
3 *
4 * Copyright 2006 Mike McCormack for CodeWeavers
5 * Copyright 2007 George Gov
6 * Copyright 2009-2013 Nikolay Sivov
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 */
22
23 #include <wine/test.h>
24
25 //#include <stdio.h>
26 //#include <windows.h>
27 #include <wingdi.h>
28 #include <winuser.h>
29 #include <commctrl.h>
30
31 #include "v6util.h"
32 #include "msg.h"
33
34 #define PARENT_SEQ_INDEX 0
35 #define PARENT_FULL_SEQ_INDEX 1
36 #define LISTVIEW_SEQ_INDEX 2
37 #define EDITBOX_SEQ_INDEX 3
38 #define COMBINED_SEQ_INDEX 4
39 #define NUM_MSG_SEQUENCES 5
40
41 #define LISTVIEW_ID 0
42 #define HEADER_ID 1
43
44 #define expect(expected, got) ok(got == expected, "Expected %d, got %d\n", expected, got)
45 #define expect2(expected1, expected2, got1, got2) ok(expected1 == got1 && expected2 == got2, \
46 "expected (%d,%d), got (%d,%d)\n", expected1, expected2, got1, got2)
47
48 static const WCHAR testparentclassW[] =
49 {'L','i','s','t','v','i','e','w',' ','t','e','s','t',' ','p','a','r','e','n','t','W', 0};
50
51 static HWND hwndparent, hwndparentW;
52 /* prevents edit box creation, LVN_BEGINLABELEDIT return value */
53 static BOOL blockEdit;
54 /* return nonzero on NM_HOVER */
55 static BOOL g_block_hover;
56 /* notification data for LVN_ITEMCHANGED */
57 static NMLISTVIEW g_nmlistview;
58 /* notification data for LVN_ITEMCHANGING */
59 static NMLISTVIEW g_nmlistview_changing;
60 /* format reported to control:
61 -1 falls to defproc, anything else returned */
62 static INT notifyFormat;
63 /* indicates we're running < 5.80 version */
64 static BOOL g_is_below_5;
65 /* item data passed to LVN_GETDISPINFOA */
66 static LVITEMA g_itema;
67 /* alter notification code A->W */
68 static BOOL g_disp_A_to_W;
69 /* dispinfo data sent with LVN_LVN_ENDLABELEDIT */
70 static NMLVDISPINFOA g_editbox_disp_info;
71 /* when this is set focus will be tested on LVN_DELETEITEM */
72 static BOOL g_focus_test_LVN_DELETEITEM;
73
74 static HWND subclass_editbox(HWND hwndListview);
75
76 static struct msg_sequence *sequences[NUM_MSG_SEQUENCES];
77
78 static const struct message create_ownerdrawfixed_parent_seq[] = {
79 { WM_NOTIFYFORMAT, sent },
80 { WM_QUERYUISTATE, sent|optional }, /* Win2K and higher */
81 { WM_MEASUREITEM, sent },
82 { WM_PARENTNOTIFY, sent },
83 { 0 }
84 };
85
86 static const struct message redraw_listview_seq[] = {
87 { WM_PAINT, sent|id, 0, 0, LISTVIEW_ID },
88 { WM_PAINT, sent|id, 0, 0, HEADER_ID },
89 { WM_NCPAINT, sent|id|defwinproc, 0, 0, HEADER_ID },
90 { WM_ERASEBKGND, sent|id|defwinproc|optional, 0, 0, HEADER_ID },
91 { WM_NOTIFY, sent|id|defwinproc, 0, 0, LISTVIEW_ID },
92 { WM_NCPAINT, sent|id|defwinproc, 0, 0, LISTVIEW_ID },
93 { WM_ERASEBKGND, sent|id|defwinproc|optional, 0, 0, LISTVIEW_ID },
94 { 0 }
95 };
96
97 static const struct message listview_icon_spacing_seq[] = {
98 { LVM_SETICONSPACING, sent|lparam, 0, MAKELPARAM(20, 30) },
99 { LVM_SETICONSPACING, sent|lparam, 0, MAKELPARAM(25, 35) },
100 { LVM_SETICONSPACING, sent|lparam, 0, MAKELPARAM(-1, -1) },
101 { 0 }
102 };
103
104 static const struct message listview_color_seq[] = {
105 { LVM_SETBKCOLOR, sent|lparam, 0, RGB(0,0,0) },
106 { LVM_GETBKCOLOR, sent },
107 { LVM_SETTEXTCOLOR, sent|lparam, 0, RGB(0,0,0) },
108 { LVM_GETTEXTCOLOR, sent },
109 { LVM_SETTEXTBKCOLOR, sent|lparam, 0, RGB(0,0,0) },
110 { LVM_GETTEXTBKCOLOR, sent },
111
112 { LVM_SETBKCOLOR, sent|lparam, 0, RGB(100,50,200) },
113 { LVM_GETBKCOLOR, sent },
114 { LVM_SETTEXTCOLOR, sent|lparam, 0, RGB(100,50,200) },
115 { LVM_GETTEXTCOLOR, sent },
116 { LVM_SETTEXTBKCOLOR, sent|lparam, 0, RGB(100,50,200) },
117 { LVM_GETTEXTBKCOLOR, sent },
118
119 { LVM_SETBKCOLOR, sent|lparam, 0, CLR_NONE },
120 { LVM_GETBKCOLOR, sent },
121 { LVM_SETTEXTCOLOR, sent|lparam, 0, CLR_NONE },
122 { LVM_GETTEXTCOLOR, sent },
123 { LVM_SETTEXTBKCOLOR, sent|lparam, 0, CLR_NONE },
124 { LVM_GETTEXTBKCOLOR, sent },
125
126 { LVM_SETBKCOLOR, sent|lparam, 0, RGB(255,255,255) },
127 { LVM_GETBKCOLOR, sent },
128 { LVM_SETTEXTCOLOR, sent|lparam, 0, RGB(255,255,255) },
129 { LVM_GETTEXTCOLOR, sent },
130 { LVM_SETTEXTBKCOLOR, sent|lparam, 0, RGB(255,255,255) },
131 { LVM_GETTEXTBKCOLOR, sent },
132 { 0 }
133 };
134
135 static const struct message listview_item_count_seq[] = {
136 { LVM_GETITEMCOUNT, sent },
137 { LVM_INSERTITEMA, sent },
138 { LVM_INSERTITEMA, sent },
139 { LVM_INSERTITEMA, sent },
140 { LVM_GETITEMCOUNT, sent },
141 { LVM_DELETEITEM, sent|wparam, 2 },
142 { WM_NCPAINT, sent|optional },
143 { WM_ERASEBKGND, sent|optional },
144 { LVM_GETITEMCOUNT, sent },
145 { LVM_DELETEALLITEMS, sent },
146 { LVM_GETITEMCOUNT, sent },
147 { LVM_INSERTITEMA, sent },
148 { LVM_INSERTITEMA, sent },
149 { LVM_GETITEMCOUNT, sent },
150 { LVM_INSERTITEMA, sent },
151 { LVM_GETITEMCOUNT, sent },
152 { 0 }
153 };
154
155 static const struct message listview_itempos_seq[] = {
156 { LVM_INSERTITEMA, sent },
157 { LVM_INSERTITEMA, sent },
158 { LVM_INSERTITEMA, sent },
159 { LVM_SETITEMPOSITION, sent|wparam|lparam, 1, MAKELPARAM(10,5) },
160 { WM_NCPAINT, sent|optional },
161 { WM_ERASEBKGND, sent|optional },
162 { LVM_GETITEMPOSITION, sent|wparam, 1 },
163 { LVM_SETITEMPOSITION, sent|wparam|lparam, 2, MAKELPARAM(0,0) },
164 { LVM_GETITEMPOSITION, sent|wparam, 2 },
165 { LVM_SETITEMPOSITION, sent|wparam|lparam, 0, MAKELPARAM(20,20) },
166 { LVM_GETITEMPOSITION, sent|wparam, 0 },
167 { 0 }
168 };
169
170 static const struct message listview_ownerdata_switchto_seq[] = {
171 { WM_STYLECHANGING, sent },
172 { WM_STYLECHANGED, sent },
173 { 0 }
174 };
175
176 static const struct message listview_getorderarray_seq[] = {
177 { LVM_GETCOLUMNORDERARRAY, sent|id|wparam, 2, 0, LISTVIEW_ID },
178 { HDM_GETORDERARRAY, sent|id|wparam, 2, 0, HEADER_ID },
179 { 0 }
180 };
181
182 static const struct message empty_seq[] = {
183 { 0 }
184 };
185
186 static const struct message forward_erasebkgnd_parent_seq[] = {
187 { WM_ERASEBKGND, sent },
188 { 0 }
189 };
190
191 static const struct message ownderdata_select_focus_parent_seq[] = {
192 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
193 { WM_NOTIFY, sent|id, 0, 0, LVN_GETDISPINFOA },
194 { WM_NOTIFY, sent|id|optional, 0, 0, LVN_GETDISPINFOA }, /* version 4.7x */
195 { 0 }
196 };
197
198 static const struct message ownerdata_setstate_all_parent_seq[] = {
199 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
200 { 0 }
201 };
202
203 static const struct message ownerdata_defocus_all_parent_seq[] = {
204 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
205 { WM_NOTIFY, sent|id, 0, 0, LVN_GETDISPINFOA },
206 { WM_NOTIFY, sent|id|optional, 0, 0, LVN_GETDISPINFOA },
207 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
208 { 0 }
209 };
210
211 static const struct message ownerdata_deselect_all_parent_seq[] = {
212 { WM_NOTIFY, sent|id, 0, 0, LVN_ODCACHEHINT },
213 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
214 { 0 }
215 };
216
217 static const struct message change_all_parent_seq[] = {
218 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGING },
219 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
220
221 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGING },
222 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
223
224 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGING },
225 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
226
227 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGING },
228 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
229
230 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGING },
231 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
232 { 0 }
233 };
234
235 static const struct message changing_all_parent_seq[] = {
236 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGING },
237 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGING },
238 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGING },
239 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGING },
240 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGING },
241 { 0 }
242 };
243
244 static const struct message textcallback_set_again_parent_seq[] = {
245 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGING },
246 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
247 { 0 }
248 };
249
250 static const struct message single_getdispinfo_parent_seq[] = {
251 { WM_NOTIFY, sent|id, 0, 0, LVN_GETDISPINFOA },
252 { 0 }
253 };
254
255 static const struct message getitemposition_seq1[] = {
256 { LVM_GETITEMPOSITION, sent|id, 0, 0, LISTVIEW_ID },
257 { 0 }
258 };
259
260 static const struct message getitemposition_seq2[] = {
261 { LVM_GETITEMPOSITION, sent|id, 0, 0, LISTVIEW_ID },
262 { HDM_GETITEMRECT, sent|id, 0, 0, HEADER_ID },
263 { 0 }
264 };
265
266 static const struct message getsubitemrect_seq[] = {
267 { LVM_GETSUBITEMRECT, sent|id|wparam, -1, 0, LISTVIEW_ID },
268 { HDM_GETITEMRECT, sent|id, 0, 0, HEADER_ID },
269 { LVM_GETSUBITEMRECT, sent|id|wparam, 0, 0, LISTVIEW_ID },
270 { HDM_GETITEMRECT, sent|id, 0, 0, HEADER_ID },
271 { LVM_GETSUBITEMRECT, sent|id|wparam, -10, 0, LISTVIEW_ID },
272 { HDM_GETITEMRECT, sent|id, 0, 0, HEADER_ID },
273 { LVM_GETSUBITEMRECT, sent|id|wparam, 20, 0, LISTVIEW_ID },
274 { HDM_GETITEMRECT, sent|id, 0, 0, HEADER_ID },
275 { 0 }
276 };
277
278 static const struct message editbox_create_pos[] = {
279 /* sequence sent after LVN_BEGINLABELEDIT */
280 /* next two are 4.7x specific */
281 { WM_WINDOWPOSCHANGING, sent },
282 { WM_WINDOWPOSCHANGED, sent|optional },
283
284 { WM_WINDOWPOSCHANGING, sent|optional },
285 { WM_NCCALCSIZE, sent },
286 { WM_WINDOWPOSCHANGED, sent },
287 { WM_MOVE, sent|defwinproc },
288 { WM_SIZE, sent|defwinproc },
289 /* the rest is todo, skipped in 4.7x */
290 { WM_WINDOWPOSCHANGING, sent|optional },
291 { WM_WINDOWPOSCHANGED, sent|optional },
292 { 0 }
293 };
294
295 static const struct message scroll_parent_seq[] = {
296 { WM_NOTIFY, sent|id, 0, 0, LVN_BEGINSCROLL },
297 { WM_NOTIFY, sent|id, 0, 0, LVN_ENDSCROLL },
298 { 0 }
299 };
300
301 static const struct message setredraw_seq[] = {
302 { WM_SETREDRAW, sent|id|wparam, FALSE, 0, LISTVIEW_ID },
303 { 0 }
304 };
305
306 static const struct message lvs_ex_transparentbkgnd_seq[] = {
307 { WM_PRINTCLIENT, sent|lparam, 0, PRF_ERASEBKGND },
308 { 0 }
309 };
310
311 static const struct message edit_end_nochange[] = {
312 { WM_NOTIFY, sent|id, 0, 0, LVN_ENDLABELEDITA },
313 { WM_NOTIFY, sent|id, 0, 0, NM_CUSTOMDRAW }, /* todo */
314 { WM_NOTIFY, sent|id, 0, 0, NM_SETFOCUS },
315 { 0 }
316 };
317
318 static const struct message hover_parent[] = {
319 { WM_GETDLGCODE, sent }, /* todo_wine */
320 { WM_NOTIFY, sent|id, 0, 0, NM_HOVER },
321 { 0 }
322 };
323
324 static const struct message listview_destroy[] = {
325 { 0x0090, sent|optional }, /* Vista */
326 { WM_PARENTNOTIFY, sent },
327 { WM_SHOWWINDOW, sent },
328 { WM_WINDOWPOSCHANGING, sent },
329 { WM_WINDOWPOSCHANGED, sent|optional },
330 { WM_DESTROY, sent },
331 { WM_NOTIFY, sent|id, 0, 0, LVN_DELETEALLITEMS },
332 { WM_NCDESTROY, sent },
333 { 0 }
334 };
335
336 static const struct message listview_ownerdata_destroy[] = {
337 { 0x0090, sent|optional }, /* Vista */
338 { WM_PARENTNOTIFY, sent },
339 { WM_SHOWWINDOW, sent },
340 { WM_WINDOWPOSCHANGING, sent },
341 { WM_WINDOWPOSCHANGED, sent|optional },
342 { WM_DESTROY, sent },
343 { WM_NCDESTROY, sent },
344 { 0 }
345 };
346
347 static const struct message listview_ownerdata_deleteall[] = {
348 { LVM_DELETEALLITEMS, sent },
349 { WM_NOTIFY, sent|id, 0, 0, LVN_DELETEALLITEMS },
350 { 0 }
351 };
352
353 static const struct message listview_header_changed_seq[] = {
354 { LVM_SETCOLUMNA, sent },
355 { WM_NOTIFY, sent|id|defwinproc, 0, 0, LISTVIEW_ID },
356 { WM_NOTIFY, sent|id|defwinproc, 0, 0, LISTVIEW_ID },
357 { 0 }
358 };
359
360 static const struct message parent_header_click_seq[] = {
361 { WM_NOTIFY, sent|id, 0, 0, LVN_COLUMNCLICK },
362 { WM_NOTIFY, sent|id, 0, 0, HDN_ITEMCLICKA },
363 { 0 }
364 };
365
366 static const struct message parent_header_divider_dclick_seq[] = {
367 { WM_NOTIFY, sent|id, 0, 0, HDN_ITEMCHANGINGA },
368 { WM_NOTIFY, sent|id, 0, 0, NM_CUSTOMDRAW },
369 { WM_NOTIFY, sent|id, 0, 0, NM_CUSTOMDRAW },
370 { WM_NOTIFY, sent|id, 0, 0, HDN_ITEMCHANGEDA },
371 { WM_NOTIFY, sent|id, 0, 0, HDN_DIVIDERDBLCLICKA },
372 { 0 }
373 };
374
375 static const struct message listview_set_imagelist[] = {
376 { LVM_SETIMAGELIST, sent|id, 0, 0, LISTVIEW_ID },
377 { 0 }
378 };
379
380 static const struct message listview_header_set_imagelist[] = {
381 { LVM_SETIMAGELIST, sent|id, 0, 0, LISTVIEW_ID },
382 { HDM_SETIMAGELIST, sent|id, 0, 0, HEADER_ID },
383 { 0 }
384 };
385
386 static const struct message parent_insert_focused_seq[] = {
387 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGING },
388 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGING },
389 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
390 { WM_NOTIFY, sent|id, 0, 0, LVN_ITEMCHANGED },
391 { WM_NOTIFY, sent|id, 0, 0, LVN_INSERTITEM },
392 { 0 }
393 };
394
395 static LRESULT WINAPI parent_wnd_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
396 {
397 static LONG defwndproc_counter = 0;
398 LRESULT ret;
399 struct message msg;
400
401 msg.message = message;
402 msg.flags = sent|wparam|lparam;
403 if (defwndproc_counter) msg.flags |= defwinproc;
404 msg.wParam = wParam;
405 msg.lParam = lParam;
406 if (message == WM_NOTIFY && lParam) msg.id = ((NMHDR*)lParam)->code;
407
408 /* log system messages, except for painting */
409 if (message < WM_USER &&
410 message != WM_PAINT &&
411 message != WM_ERASEBKGND &&
412 message != WM_NCPAINT &&
413 message != WM_NCHITTEST &&
414 message != WM_GETTEXT &&
415 message != WM_GETICON &&
416 message != WM_DEVICECHANGE)
417 {
418 add_message(sequences, PARENT_SEQ_INDEX, &msg);
419 add_message(sequences, COMBINED_SEQ_INDEX, &msg);
420 }
421 add_message(sequences, PARENT_FULL_SEQ_INDEX, &msg);
422
423 switch (message)
424 {
425 case WM_NOTIFY:
426 {
427 switch (((NMHDR*)lParam)->code)
428 {
429 case LVN_BEGINLABELEDITA:
430 {
431 HWND edit = NULL;
432
433 /* subclass edit box */
434 if (!blockEdit)
435 edit = subclass_editbox(((NMHDR*)lParam)->hwndFrom);
436
437 if (edit)
438 {
439 INT len = SendMessageA(edit, EM_GETLIMITTEXT, 0, 0);
440 ok(len == 259 || broken(len == 260) /* includes NULL in NT4 */,
441 "text limit %d, expected 259\n", len);
442 }
443
444 return blockEdit;
445 }
446 case LVN_ENDLABELEDITA:
447 {
448 HWND edit;
449
450 /* always accept new item text */
451 NMLVDISPINFOA *di = (NMLVDISPINFOA*)lParam;
452 g_editbox_disp_info = *di;
453 trace("LVN_ENDLABELEDIT: text=%s\n", di->item.pszText ? di->item.pszText : "(null)");
454
455 /* edit control still available from this notification */
456 edit = (HWND)SendMessageA(((NMHDR*)lParam)->hwndFrom, LVM_GETEDITCONTROL, 0, 0);
457 ok(IsWindow(edit), "expected valid edit control handle\n");
458 ok((GetWindowLongA(edit, GWL_STYLE) & ES_MULTILINE) == 0, "edit is multiline\n");
459
460 return TRUE;
461 }
462 case LVN_BEGINSCROLL:
463 case LVN_ENDSCROLL:
464 {
465 NMLVSCROLL *pScroll = (NMLVSCROLL*)lParam;
466
467 trace("LVN_%sSCROLL: (%d,%d)\n", pScroll->hdr.code == LVN_BEGINSCROLL ?
468 "BEGIN" : "END", pScroll->dx, pScroll->dy);
469 }
470 break;
471 case LVN_ITEMCHANGING:
472 {
473 NMLISTVIEW *nmlv = (NMLISTVIEW*)lParam;
474 g_nmlistview_changing = *nmlv;
475 }
476 break;
477 case LVN_ITEMCHANGED:
478 {
479 NMLISTVIEW *nmlv = (NMLISTVIEW*)lParam;
480 g_nmlistview = *nmlv;
481 }
482 break;
483 case LVN_GETDISPINFOA:
484 {
485 NMLVDISPINFOA *dispinfo = (NMLVDISPINFOA*)lParam;
486 g_itema = dispinfo->item;
487
488 if (g_disp_A_to_W && (dispinfo->item.mask & LVIF_TEXT))
489 {
490 static const WCHAR testW[] = {'T','E','S','T',0};
491 dispinfo->hdr.code = LVN_GETDISPINFOW;
492 memcpy(dispinfo->item.pszText, testW, sizeof(testW));
493 }
494
495 /* test control buffer size for text, 10 used to mask cases when control
496 is using caller buffer to process LVM_GETITEM for example */
497 if (dispinfo->item.mask & LVIF_TEXT && dispinfo->item.cchTextMax > 10)
498 ok(dispinfo->item.cchTextMax == 260 ||
499 broken(dispinfo->item.cchTextMax == 264) /* NT4 reports aligned size */,
500 "buffer size %d\n", dispinfo->item.cchTextMax);
501 }
502 break;
503 case LVN_DELETEITEM:
504 if (g_focus_test_LVN_DELETEITEM)
505 {
506 NMLISTVIEW *nmlv = (NMLISTVIEW*)lParam;
507 UINT state;
508
509 state = SendMessageA(((NMHDR*)lParam)->hwndFrom, LVM_GETITEMSTATE, nmlv->iItem, LVIS_FOCUSED);
510 ok(state == 0, "got state %x\n", state);
511 }
512 break;
513 case NM_HOVER:
514 if (g_block_hover) return 1;
515 break;
516 }
517 break;
518 }
519 case WM_NOTIFYFORMAT:
520 {
521 /* force to return format */
522 if (lParam == NF_QUERY && notifyFormat != -1) return notifyFormat;
523 break;
524 }
525 }
526
527 defwndproc_counter++;
528 ret = DefWindowProcA(hwnd, message, wParam, lParam);
529 defwndproc_counter--;
530
531 return ret;
532 }
533
534 static BOOL register_parent_wnd_class(BOOL Unicode)
535 {
536 WNDCLASSA clsA;
537 WNDCLASSW clsW;
538
539 if (Unicode)
540 {
541 clsW.style = 0;
542 clsW.lpfnWndProc = parent_wnd_proc;
543 clsW.cbClsExtra = 0;
544 clsW.cbWndExtra = 0;
545 clsW.hInstance = GetModuleHandleW(NULL);
546 clsW.hIcon = 0;
547 clsW.hCursor = LoadCursorA(0, (LPCSTR)IDC_ARROW);
548 clsW.hbrBackground = GetStockObject(WHITE_BRUSH);
549 clsW.lpszMenuName = NULL;
550 clsW.lpszClassName = testparentclassW;
551 }
552 else
553 {
554 clsA.style = 0;
555 clsA.lpfnWndProc = parent_wnd_proc;
556 clsA.cbClsExtra = 0;
557 clsA.cbWndExtra = 0;
558 clsA.hInstance = GetModuleHandleA(NULL);
559 clsA.hIcon = 0;
560 clsA.hCursor = LoadCursorA(0, (LPCSTR)IDC_ARROW);
561 clsA.hbrBackground = GetStockObject(WHITE_BRUSH);
562 clsA.lpszMenuName = NULL;
563 clsA.lpszClassName = "Listview test parent class";
564 }
565
566 return Unicode ? RegisterClassW(&clsW) : RegisterClassA(&clsA);
567 }
568
569 static HWND create_parent_window(BOOL Unicode)
570 {
571 static const WCHAR nameW[] = {'t','e','s','t','p','a','r','e','n','t','n','a','m','e','W',0};
572 HWND hwnd;
573
574 if (!register_parent_wnd_class(Unicode))
575 return NULL;
576
577 blockEdit = FALSE;
578 notifyFormat = -1;
579
580 if (Unicode)
581 hwnd = CreateWindowExW(0, testparentclassW, nameW,
582 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
583 WS_MAXIMIZEBOX | WS_VISIBLE,
584 0, 0, 100, 100,
585 GetDesktopWindow(), NULL, GetModuleHandleW(NULL), NULL);
586 else
587 hwnd = CreateWindowExA(0, "Listview test parent class",
588 "Listview test parent window",
589 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
590 WS_MAXIMIZEBOX | WS_VISIBLE,
591 0, 0, 100, 100,
592 GetDesktopWindow(), NULL, GetModuleHandleA(NULL), NULL);
593 SetWindowPos( hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE );
594 return hwnd;
595 }
596
597 static LRESULT WINAPI listview_subclass_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
598 {
599 WNDPROC oldproc = (WNDPROC)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
600 static LONG defwndproc_counter = 0;
601 LRESULT ret;
602 struct message msg;
603
604 /* some debug output for style changing */
605 if ((message == WM_STYLECHANGING ||
606 message == WM_STYLECHANGED) && lParam)
607 {
608 STYLESTRUCT *style = (STYLESTRUCT*)lParam;
609 trace("\told style: 0x%08x, new style: 0x%08x\n", style->styleOld, style->styleNew);
610 }
611
612 msg.message = message;
613 msg.flags = sent|wparam|lparam;
614 if (defwndproc_counter) msg.flags |= defwinproc;
615 msg.wParam = wParam;
616 msg.lParam = lParam;
617 msg.id = LISTVIEW_ID;
618 add_message(sequences, LISTVIEW_SEQ_INDEX, &msg);
619 add_message(sequences, COMBINED_SEQ_INDEX, &msg);
620
621 defwndproc_counter++;
622 ret = CallWindowProcA(oldproc, hwnd, message, wParam, lParam);
623 defwndproc_counter--;
624 return ret;
625 }
626
627 static HWND create_listview_control(DWORD style)
628 {
629 WNDPROC oldproc;
630 HWND hwnd;
631 RECT rect;
632
633 GetClientRect(hwndparent, &rect);
634 hwnd = CreateWindowExA(0, WC_LISTVIEWA, "foo",
635 WS_CHILD | WS_BORDER | WS_VISIBLE | style,
636 0, 0, rect.right, rect.bottom,
637 hwndparent, NULL, GetModuleHandleA(NULL), NULL);
638 ok(hwnd != NULL, "gle=%d\n", GetLastError());
639
640 if (!hwnd) return NULL;
641
642 oldproc = (WNDPROC)SetWindowLongPtrA(hwnd, GWLP_WNDPROC,
643 (LONG_PTR)listview_subclass_proc);
644 SetWindowLongPtrA(hwnd, GWLP_USERDATA, (LONG_PTR)oldproc);
645
646 return hwnd;
647 }
648
649 /* unicode listview window with specified parent */
650 static HWND create_listview_controlW(DWORD style, HWND parent)
651 {
652 WNDPROC oldproc;
653 HWND hwnd;
654 RECT rect;
655 static const WCHAR nameW[] = {'f','o','o',0};
656
657 GetClientRect(parent, &rect);
658 hwnd = CreateWindowExW(0, WC_LISTVIEWW, nameW,
659 WS_CHILD | WS_BORDER | WS_VISIBLE | style,
660 0, 0, rect.right, rect.bottom,
661 parent, NULL, GetModuleHandleW(NULL), NULL);
662 ok(hwnd != NULL, "gle=%d\n", GetLastError());
663
664 if (!hwnd) return NULL;
665
666 oldproc = (WNDPROC)SetWindowLongPtrW(hwnd, GWLP_WNDPROC,
667 (LONG_PTR)listview_subclass_proc);
668 SetWindowLongPtrW(hwnd, GWLP_USERDATA, (LONG_PTR)oldproc);
669
670 return hwnd;
671 }
672
673 static LRESULT WINAPI header_subclass_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
674 {
675 WNDPROC oldproc = (WNDPROC)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
676 static LONG defwndproc_counter = 0;
677 LRESULT ret;
678 struct message msg;
679
680 msg.message = message;
681 msg.flags = sent|wparam|lparam;
682 if (defwndproc_counter) msg.flags |= defwinproc;
683 msg.wParam = wParam;
684 msg.lParam = lParam;
685 msg.id = HEADER_ID;
686 add_message(sequences, LISTVIEW_SEQ_INDEX, &msg);
687
688 defwndproc_counter++;
689 ret = CallWindowProcA(oldproc, hwnd, message, wParam, lParam);
690 defwndproc_counter--;
691 return ret;
692 }
693
694 static HWND subclass_header(HWND hwndListview)
695 {
696 WNDPROC oldproc;
697 HWND hwnd;
698
699 hwnd = (HWND)SendMessageA(hwndListview, LVM_GETHEADER, 0, 0);
700 oldproc = (WNDPROC)SetWindowLongPtrA(hwnd, GWLP_WNDPROC,
701 (LONG_PTR)header_subclass_proc);
702 SetWindowLongPtrA(hwnd, GWLP_USERDATA, (LONG_PTR)oldproc);
703
704 return hwnd;
705 }
706
707 static LRESULT WINAPI editbox_subclass_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
708 {
709 WNDPROC oldproc = (WNDPROC)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
710 static LONG defwndproc_counter = 0;
711 LRESULT ret;
712 struct message msg;
713
714 msg.message = message;
715 msg.flags = sent|wparam|lparam;
716 if (defwndproc_counter) msg.flags |= defwinproc;
717 msg.wParam = wParam;
718 msg.lParam = lParam;
719 msg.id = 0;
720
721 /* all we need is sizing */
722 if (message == WM_WINDOWPOSCHANGING ||
723 message == WM_NCCALCSIZE ||
724 message == WM_WINDOWPOSCHANGED ||
725 message == WM_MOVE ||
726 message == WM_SIZE)
727 {
728 add_message(sequences, EDITBOX_SEQ_INDEX, &msg);
729 }
730
731 defwndproc_counter++;
732 ret = CallWindowProcA(oldproc, hwnd, message, wParam, lParam);
733 defwndproc_counter--;
734 return ret;
735 }
736
737 static HWND subclass_editbox(HWND hwndListview)
738 {
739 WNDPROC oldproc;
740 HWND hwnd;
741
742 hwnd = (HWND)SendMessageA(hwndListview, LVM_GETEDITCONTROL, 0, 0);
743 oldproc = (WNDPROC)SetWindowLongPtrA(hwnd, GWLP_WNDPROC,
744 (LONG_PTR)editbox_subclass_proc);
745 SetWindowLongPtrA(hwnd, GWLP_USERDATA, (LONG_PTR)oldproc);
746
747 return hwnd;
748 }
749
750 /* Performs a single LVM_HITTEST test */
751 static void test_lvm_hittest_(HWND hwnd, INT x, INT y, INT item, UINT flags, UINT broken_flags,
752 BOOL todo_item, BOOL todo_flags, int line)
753 {
754 LVHITTESTINFO lpht;
755 INT ret;
756
757 lpht.pt.x = x;
758 lpht.pt.y = y;
759 lpht.iSubItem = 10;
760
761 ret = SendMessageA(hwnd, LVM_HITTEST, 0, (LPARAM)&lpht);
762
763 if (todo_item)
764 {
765 todo_wine
766 {
767 ok_(__FILE__, line)(ret == item, "Expected %d retval, got %d\n", item, ret);
768 ok_(__FILE__, line)(lpht.iItem == item, "Expected %d item, got %d\n", item, lpht.iItem);
769 ok_(__FILE__, line)(lpht.iSubItem == 10, "Expected subitem not overwrited\n");
770 }
771 }
772 else
773 {
774 ok_(__FILE__, line)(ret == item, "Expected %d retval, got %d\n", item, ret);
775 ok_(__FILE__, line)(lpht.iItem == item, "Expected %d item, got %d\n", item, lpht.iItem);
776 ok_(__FILE__, line)(lpht.iSubItem == 10, "Expected subitem not overwrited\n");
777 }
778
779 if (todo_flags)
780 {
781 todo_wine
782 ok_(__FILE__, line)(lpht.flags == flags, "Expected flags 0x%x, got 0x%x\n", flags, lpht.flags);
783 }
784 else if (broken_flags)
785 ok_(__FILE__, line)(lpht.flags == flags || broken(lpht.flags == broken_flags),
786 "Expected flags %x, got %x\n", flags, lpht.flags);
787 else
788 ok_(__FILE__, line)(lpht.flags == flags, "Expected flags 0x%x, got 0x%x\n", flags, lpht.flags);
789 }
790
791 #define test_lvm_hittest(a,b,c,d,e,f,g,h) test_lvm_hittest_(a,b,c,d,e,f,g,h,__LINE__)
792
793 /* Performs a single LVM_SUBITEMHITTEST test */
794 static void test_lvm_subitemhittest_(HWND hwnd, INT x, INT y, INT item, INT subitem, UINT flags,
795 BOOL todo_item, BOOL todo_subitem, BOOL todo_flags, int line)
796 {
797 LVHITTESTINFO lpht;
798 INT ret;
799
800 lpht.pt.x = x;
801 lpht.pt.y = y;
802
803 ret = SendMessageA(hwnd, LVM_SUBITEMHITTEST, 0, (LPARAM)&lpht);
804
805 if (todo_item)
806 {
807 todo_wine
808 {
809 ok_(__FILE__, line)(ret == item, "Expected %d retval, got %d\n", item, ret);
810 ok_(__FILE__, line)(lpht.iItem == item, "Expected %d item, got %d\n", item, lpht.iItem);
811 }
812 }
813 else
814 {
815 ok_(__FILE__, line)(ret == item, "Expected %d retval, got %d\n", item, ret);
816 ok_(__FILE__, line)(lpht.iItem == item, "Expected %d item, got %d\n", item, lpht.iItem);
817 }
818
819 if (todo_subitem)
820 {
821 todo_wine
822 ok_(__FILE__, line)(lpht.iSubItem == subitem, "Expected subitem %d, got %d\n", subitem, lpht.iSubItem);
823 }
824 else
825 ok_(__FILE__, line)(lpht.iSubItem == subitem, "Expected subitem %d, got %d\n", subitem, lpht.iSubItem);
826
827 if (todo_flags)
828 {
829 todo_wine
830 ok_(__FILE__, line)(lpht.flags == flags, "Expected flags 0x%x, got 0x%x\n", flags, lpht.flags);
831 }
832 else
833 ok_(__FILE__, line)(lpht.flags == flags, "Expected flags 0x%x, got 0x%x\n", flags, lpht.flags);
834 }
835
836 #define test_lvm_subitemhittest(a,b,c,d,e,f,g,h,i) test_lvm_subitemhittest_(a,b,c,d,e,f,g,h,i,__LINE__)
837
838 static void test_images(void)
839 {
840 HWND hwnd;
841 INT r;
842 LVITEMA item;
843 HIMAGELIST himl;
844 HBITMAP hbmp;
845 RECT r1, r2;
846 static CHAR hello[] = "hello";
847
848 himl = ImageList_Create(40, 40, 0, 4, 4);
849 ok(himl != NULL, "failed to create imagelist\n");
850
851 hbmp = CreateBitmap(40, 40, 1, 1, NULL);
852 ok(hbmp != NULL, "failed to create bitmap\n");
853
854 r = ImageList_Add(himl, hbmp, 0);
855 ok(r == 0, "should be zero\n");
856
857 hwnd = CreateWindowExA(0, "SysListView32", "foo", LVS_OWNERDRAWFIXED,
858 10, 10, 100, 200, hwndparent, NULL, NULL, NULL);
859 ok(hwnd != NULL, "failed to create listview window\n");
860
861 r = SendMessageA(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, 0,
862 LVS_EX_UNDERLINEHOT | LVS_EX_FLATSB | LVS_EX_ONECLICKACTIVATE);
863
864 ok(r == 0, "should return zero\n");
865
866 r = SendMessageA(hwnd, LVM_SETIMAGELIST, 0, (LPARAM)himl);
867 ok(r == 0, "should return zero\n");
868
869 r = SendMessageA(hwnd, LVM_SETICONSPACING, 0, MAKELONG(100,50));
870 ok(r != 0, "got 0\n");
871
872 /* returns dimensions */
873
874 r = SendMessageA(hwnd, LVM_GETITEMCOUNT, 0, 0);
875 ok(r == 0, "should be zero items\n");
876
877 item.mask = LVIF_IMAGE | LVIF_TEXT;
878 item.iItem = 0;
879 item.iSubItem = 1;
880 item.iImage = 0;
881 item.pszText = 0;
882 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
883 ok(r == -1, "should fail\n");
884
885 item.iSubItem = 0;
886 item.pszText = hello;
887 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
888 ok(r == 0, "should not fail\n");
889
890 memset(&r1, 0, sizeof r1);
891 r1.left = LVIR_ICON;
892 r = SendMessageA(hwnd, LVM_GETITEMRECT, 0, (LPARAM) &r1);
893 expect(1, r);
894
895 r = SendMessageA(hwnd, LVM_DELETEALLITEMS, 0, 0);
896 ok(r == TRUE, "should not fail\n");
897
898 item.iSubItem = 0;
899 item.pszText = hello;
900 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
901 ok(r == 0, "should not fail\n");
902
903 memset(&r2, 0, sizeof r2);
904 r2.left = LVIR_ICON;
905 r = SendMessageA(hwnd, LVM_GETITEMRECT, 0, (LPARAM) &r2);
906 expect(1, r);
907
908 ok(!memcmp(&r1, &r2, sizeof r1), "rectangle should be the same\n");
909
910 DestroyWindow(hwnd);
911 }
912
913 static void test_checkboxes(void)
914 {
915 HWND hwnd;
916 LVITEMA item;
917 DWORD r;
918 static CHAR text[] = "Text",
919 text2[] = "Text2",
920 text3[] = "Text3";
921
922 hwnd = CreateWindowExA(0, "SysListView32", "foo", LVS_REPORT,
923 10, 10, 100, 200, hwndparent, NULL, NULL, NULL);
924 ok(hwnd != NULL, "failed to create listview window\n");
925
926 /* first without LVS_EX_CHECKBOXES set and an item and check that state is preserved */
927 item.mask = LVIF_TEXT | LVIF_STATE;
928 item.stateMask = 0xffff;
929 item.state = 0xfccc;
930 item.iItem = 0;
931 item.iSubItem = 0;
932 item.pszText = text;
933 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
934 expect(0, r);
935
936 item.iItem = 0;
937 item.mask = LVIF_STATE;
938 item.stateMask = 0xffff;
939 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
940 expect(1, r);
941 ok(item.state == 0xfccc, "state %x\n", item.state);
942
943 /* Don't set LVIF_STATE */
944 item.mask = LVIF_TEXT;
945 item.stateMask = 0xffff;
946 item.state = 0xfccc;
947 item.iItem = 1;
948 item.iSubItem = 0;
949 item.pszText = text;
950 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
951 expect(1, r);
952
953 item.iItem = 1;
954 item.mask = LVIF_STATE;
955 item.stateMask = 0xffff;
956 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
957 expect(1, r);
958 ok(item.state == 0, "state %x\n", item.state);
959
960 r = SendMessageA(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_CHECKBOXES, LVS_EX_CHECKBOXES);
961 expect(0, r);
962
963 /* Having turned on checkboxes, check that all existing items are set to 0x1000 (unchecked) */
964 item.iItem = 0;
965 item.mask = LVIF_STATE;
966 item.stateMask = 0xffff;
967 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
968 expect(1, r);
969 if (item.state != 0x1ccc)
970 {
971 win_skip("LVS_EX_CHECKBOXES style is unavailable. Skipping.\n");
972 DestroyWindow(hwnd);
973 return;
974 }
975
976 /* Now add an item without specifying a state and check that its state goes to 0x1000 */
977 item.iItem = 2;
978 item.mask = LVIF_TEXT;
979 item.state = 0;
980 item.pszText = text2;
981 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
982 expect(2, r);
983
984 item.iItem = 2;
985 item.mask = LVIF_STATE;
986 item.stateMask = 0xffff;
987 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
988 expect(1, r);
989 ok(item.state == 0x1000, "state %x\n", item.state);
990
991 /* Add a further item this time specifying a state and still its state goes to 0x1000 */
992 item.iItem = 3;
993 item.mask = LVIF_TEXT | LVIF_STATE;
994 item.stateMask = 0xffff;
995 item.state = 0x2aaa;
996 item.pszText = text3;
997 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
998 expect(3, r);
999
1000 item.iItem = 3;
1001 item.mask = LVIF_STATE;
1002 item.stateMask = 0xffff;
1003 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1004 expect(1, r);
1005 ok(item.state == 0x1aaa, "state %x\n", item.state);
1006
1007 /* Set an item's state to checked */
1008 item.iItem = 3;
1009 item.mask = LVIF_STATE;
1010 item.stateMask = 0xf000;
1011 item.state = 0x2000;
1012 r = SendMessageA(hwnd, LVM_SETITEMA, 0, (LPARAM) &item);
1013 expect(1, r);
1014
1015 item.iItem = 3;
1016 item.mask = LVIF_STATE;
1017 item.stateMask = 0xffff;
1018 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1019 expect(1, r);
1020 ok(item.state == 0x2aaa, "state %x\n", item.state);
1021
1022 /* Check that only the bits we asked for are returned,
1023 * and that all the others are set to zero
1024 */
1025 item.iItem = 3;
1026 item.mask = LVIF_STATE;
1027 item.stateMask = 0xf000;
1028 item.state = 0xffff;
1029 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1030 expect(1, r);
1031 ok(item.state == 0x2000, "state %x\n", item.state);
1032
1033 /* Set the style again and check that doesn't change an item's state */
1034 r = SendMessageA(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_CHECKBOXES, LVS_EX_CHECKBOXES);
1035 ok(r == LVS_EX_CHECKBOXES, "ret %x\n", r);
1036
1037 item.iItem = 3;
1038 item.mask = LVIF_STATE;
1039 item.stateMask = 0xffff;
1040 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1041 expect(1, r);
1042 ok(item.state == 0x2aaa, "state %x\n", item.state);
1043
1044 /* Unsetting the checkbox extended style doesn't change an item's state */
1045 r = SendMessageA(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_CHECKBOXES, 0);
1046 ok(r == LVS_EX_CHECKBOXES, "ret %x\n", r);
1047
1048 item.iItem = 3;
1049 item.mask = LVIF_STATE;
1050 item.stateMask = 0xffff;
1051 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1052 expect(1, r);
1053 ok(item.state == 0x2aaa, "state %x\n", item.state);
1054
1055 /* Now setting the style again will change an item's state */
1056 r = SendMessageA(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_CHECKBOXES, LVS_EX_CHECKBOXES);
1057 expect(0, r);
1058
1059 item.iItem = 3;
1060 item.mask = LVIF_STATE;
1061 item.stateMask = 0xffff;
1062 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1063 expect(1, r);
1064 ok(item.state == 0x1aaa, "state %x\n", item.state);
1065
1066 /* Toggle checkbox tests (bug 9934) */
1067 memset (&item, 0xcc, sizeof(item));
1068 item.mask = LVIF_STATE;
1069 item.iItem = 3;
1070 item.iSubItem = 0;
1071 item.state = LVIS_FOCUSED;
1072 item.stateMask = LVIS_FOCUSED;
1073 r = SendMessageA(hwnd, LVM_SETITEMA, 0, (LPARAM) &item);
1074 expect(1, r);
1075
1076 item.iItem = 3;
1077 item.mask = LVIF_STATE;
1078 item.stateMask = 0xffff;
1079 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1080 expect(1, r);
1081 ok(item.state == 0x1aab, "state %x\n", item.state);
1082
1083 r = SendMessageA(hwnd, WM_KEYDOWN, VK_SPACE, 0);
1084 expect(0, r);
1085 r = SendMessageA(hwnd, WM_KEYUP, VK_SPACE, 0);
1086 expect(0, r);
1087
1088 item.iItem = 3;
1089 item.mask = LVIF_STATE;
1090 item.stateMask = 0xffff;
1091 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1092 expect(1, r);
1093 ok(item.state == 0x2aab, "state %x\n", item.state);
1094
1095 r = SendMessageA(hwnd, WM_KEYDOWN, VK_SPACE, 0);
1096 expect(0, r);
1097 r = SendMessageA(hwnd, WM_KEYUP, VK_SPACE, 0);
1098 expect(0, r);
1099
1100 item.iItem = 3;
1101 item.mask = LVIF_STATE;
1102 item.stateMask = 0xffff;
1103 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1104 expect(1, r);
1105 ok(item.state == 0x1aab, "state %x\n", item.state);
1106
1107 DestroyWindow(hwnd);
1108 }
1109
1110 static void insert_column(HWND hwnd, int idx)
1111 {
1112 LVCOLUMNA column;
1113 INT rc;
1114
1115 memset(&column, 0xcc, sizeof(column));
1116 column.mask = LVCF_SUBITEM;
1117 column.iSubItem = idx;
1118
1119 rc = SendMessageA(hwnd, LVM_INSERTCOLUMNA, idx, (LPARAM)&column);
1120 expect(idx, rc);
1121 }
1122
1123 static void insert_item(HWND hwnd, int idx)
1124 {
1125 static CHAR text[] = "foo";
1126
1127 LVITEMA item;
1128 INT rc;
1129
1130 memset(&item, 0xcc, sizeof (item));
1131 item.mask = LVIF_TEXT;
1132 item.iItem = idx;
1133 item.iSubItem = 0;
1134 item.pszText = text;
1135
1136 rc = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
1137 expect(idx, rc);
1138 }
1139
1140 static void test_items(void)
1141 {
1142 const LPARAM lparamTest = 0x42;
1143 static CHAR text[] = "Text";
1144 char buffA[5];
1145 HWND hwnd;
1146 LVITEMA item;
1147 DWORD r;
1148
1149 hwnd = CreateWindowExA(0, "SysListView32", "foo", LVS_REPORT,
1150 10, 10, 100, 200, hwndparent, NULL, NULL, NULL);
1151 ok(hwnd != NULL, "failed to create listview window\n");
1152
1153 /*
1154 * Test setting/getting item params
1155 */
1156
1157 /* Set up two columns */
1158 insert_column(hwnd, 0);
1159 insert_column(hwnd, 1);
1160
1161 /* LVIS_SELECTED with zero stateMask */
1162 /* set */
1163 memset (&item, 0, sizeof (item));
1164 item.mask = LVIF_STATE;
1165 item.state = LVIS_SELECTED;
1166 item.stateMask = 0;
1167 item.iItem = 0;
1168 item.iSubItem = 0;
1169 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
1170 expect(0, r);
1171 /* get */
1172 memset (&item, 0xcc, sizeof (item));
1173 item.mask = LVIF_STATE;
1174 item.stateMask = LVIS_SELECTED;
1175 item.state = 0;
1176 item.iItem = 0;
1177 item.iSubItem = 0;
1178 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1179 expect(1, r);
1180 ok(item.state & LVIS_SELECTED, "Expected LVIS_SELECTED\n");
1181 SendMessageA(hwnd, LVM_DELETEITEM, 0, 0);
1182
1183 /* LVIS_SELECTED with zero stateMask */
1184 /* set */
1185 memset (&item, 0, sizeof (item));
1186 item.mask = LVIF_STATE;
1187 item.state = LVIS_FOCUSED;
1188 item.stateMask = 0;
1189 item.iItem = 0;
1190 item.iSubItem = 0;
1191 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
1192 expect(0, r);
1193 /* get */
1194 memset (&item, 0xcc, sizeof (item));
1195 item.mask = LVIF_STATE;
1196 item.stateMask = LVIS_FOCUSED;
1197 item.state = 0;
1198 item.iItem = 0;
1199 item.iSubItem = 0;
1200 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1201 expect(1, r);
1202 ok(item.state & LVIS_FOCUSED, "Expected LVIS_FOCUSED\n");
1203 SendMessageA(hwnd, LVM_DELETEITEM, 0, 0);
1204
1205 /* LVIS_CUT with LVIS_FOCUSED stateMask */
1206 /* set */
1207 memset (&item, 0, sizeof (item));
1208 item.mask = LVIF_STATE;
1209 item.state = LVIS_CUT;
1210 item.stateMask = LVIS_FOCUSED;
1211 item.iItem = 0;
1212 item.iSubItem = 0;
1213 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
1214 expect(0, r);
1215 /* get */
1216 memset (&item, 0xcc, sizeof (item));
1217 item.mask = LVIF_STATE;
1218 item.stateMask = LVIS_CUT;
1219 item.state = 0;
1220 item.iItem = 0;
1221 item.iSubItem = 0;
1222 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1223 expect(1, r);
1224 ok(item.state & LVIS_CUT, "Expected LVIS_CUT\n");
1225 SendMessageA(hwnd, LVM_DELETEITEM, 0, 0);
1226
1227 /* Insert an item with just a param */
1228 memset (&item, 0xcc, sizeof (item));
1229 item.mask = LVIF_PARAM;
1230 item.iItem = 0;
1231 item.iSubItem = 0;
1232 item.lParam = lparamTest;
1233 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
1234 expect(0, r);
1235
1236 /* Test getting of the param */
1237 memset (&item, 0xcc, sizeof (item));
1238 item.mask = LVIF_PARAM;
1239 item.iItem = 0;
1240 item.iSubItem = 0;
1241 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1242 expect(1, r);
1243 ok(item.lParam == lparamTest, "got lParam %lx, expected %lx\n", item.lParam, lparamTest);
1244
1245 /* Set up a subitem */
1246 memset (&item, 0xcc, sizeof (item));
1247 item.mask = LVIF_TEXT;
1248 item.iItem = 0;
1249 item.iSubItem = 1;
1250 item.pszText = text;
1251 r = SendMessageA(hwnd, LVM_SETITEMA, 0, (LPARAM) &item);
1252 expect(1, r);
1253
1254 item.mask = LVIF_TEXT;
1255 item.iItem = 0;
1256 item.iSubItem = 1;
1257 item.pszText = buffA;
1258 item.cchTextMax = sizeof(buffA);
1259 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1260 expect(1, r);
1261 ok(!memcmp(item.pszText, text, sizeof(text)), "got text %s, expected %s\n", item.pszText, text);
1262
1263 /* set up with extra flag */
1264 /* 1. reset subitem text */
1265 item.mask = LVIF_TEXT;
1266 item.iItem = 0;
1267 item.iSubItem = 1;
1268 item.pszText = NULL;
1269 r = SendMessageA(hwnd, LVM_SETITEMA, 0, (LPARAM) &item);
1270 expect(1, r);
1271
1272 item.mask = LVIF_TEXT;
1273 item.iItem = 0;
1274 item.iSubItem = 1;
1275 item.pszText = buffA;
1276 buffA[0] = 'a';
1277 item.cchTextMax = sizeof(buffA);
1278 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1279 expect(1, r);
1280 ok(item.pszText[0] == 0, "got %p\n", item.pszText);
1281
1282 /* 2. set new text with extra flag specified */
1283 item.mask = LVIF_TEXT | LVIF_DI_SETITEM;
1284 item.iItem = 0;
1285 item.iSubItem = 1;
1286 item.pszText = text;
1287 r = SendMessageA(hwnd, LVM_SETITEMA, 0, (LPARAM) &item);
1288 ok(r == 1 || broken(r == 0) /* NT4 */, "ret %d\n", r);
1289
1290 if (r == 1)
1291 {
1292 item.mask = LVIF_TEXT;
1293 item.iItem = 0;
1294 item.iSubItem = 1;
1295 item.pszText = buffA;
1296 buffA[0] = 'a';
1297 item.cchTextMax = sizeof(buffA);
1298 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1299 expect(1, r);
1300 ok(!memcmp(item.pszText, text, sizeof(text)), "got %s, expected %s\n", item.pszText, text);
1301 }
1302
1303 /* Query param from subitem: returns main item param */
1304 memset (&item, 0xcc, sizeof (item));
1305 item.mask = LVIF_PARAM;
1306 item.iItem = 0;
1307 item.iSubItem = 1;
1308 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1309 expect(1, r);
1310 ok(item.lParam == lparamTest, "got lParam %lx, expected %lx\n", item.lParam, lparamTest);
1311
1312 /* Set up param on first subitem: no effect */
1313 memset (&item, 0xcc, sizeof (item));
1314 item.mask = LVIF_PARAM;
1315 item.iItem = 0;
1316 item.iSubItem = 1;
1317 item.lParam = lparamTest+1;
1318 r = SendMessageA(hwnd, LVM_SETITEMA, 0, (LPARAM) &item);
1319 expect(0, r);
1320
1321 /* Query param from subitem again: should still return main item param */
1322 memset (&item, 0xcc, sizeof (item));
1323 item.mask = LVIF_PARAM;
1324 item.iItem = 0;
1325 item.iSubItem = 1;
1326 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1327 expect(1, r);
1328 ok(item.lParam == lparamTest, "got lParam %lx, expected %lx\n", item.lParam, lparamTest);
1329
1330 /**** Some tests of state highlighting ****/
1331 memset (&item, 0xcc, sizeof (item));
1332 item.mask = LVIF_STATE;
1333 item.iItem = 0;
1334 item.iSubItem = 0;
1335 item.state = LVIS_SELECTED;
1336 item.stateMask = LVIS_SELECTED | LVIS_DROPHILITED;
1337 r = SendMessageA(hwnd, LVM_SETITEMA, 0, (LPARAM) &item);
1338 expect(1, r);
1339 item.iSubItem = 1;
1340 item.state = LVIS_DROPHILITED;
1341 r = SendMessageA(hwnd, LVM_SETITEMA, 0, (LPARAM) &item);
1342 expect(1, r);
1343
1344 memset (&item, 0xcc, sizeof (item));
1345 item.mask = LVIF_STATE;
1346 item.iItem = 0;
1347 item.iSubItem = 0;
1348 item.stateMask = -1;
1349 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1350 expect(1, r);
1351 ok(item.state == LVIS_SELECTED, "got state %x, expected %x\n", item.state, LVIS_SELECTED);
1352 item.iSubItem = 1;
1353 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1354 expect(1, r);
1355 todo_wine ok(item.state == LVIS_DROPHILITED, "got state %x, expected %x\n", item.state, LVIS_DROPHILITED);
1356
1357 /* some notnull but meaningless masks */
1358 memset (&item, 0, sizeof(item));
1359 item.mask = LVIF_NORECOMPUTE;
1360 item.iItem = 0;
1361 item.iSubItem = 0;
1362 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1363 expect(1, r);
1364 memset (&item, 0, sizeof(item));
1365 item.mask = LVIF_DI_SETITEM;
1366 item.iItem = 0;
1367 item.iSubItem = 0;
1368 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
1369 expect(1, r);
1370
1371 /* set text to callback value already having it */
1372 r = SendMessageA(hwnd, LVM_DELETEALLITEMS, 0, 0);
1373 expect(TRUE, r);
1374 memset (&item, 0, sizeof (item));
1375 item.mask = LVIF_TEXT;
1376 item.pszText = LPSTR_TEXTCALLBACKA;
1377 item.iItem = 0;
1378 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
1379 expect(0, r);
1380 memset (&item, 0, sizeof (item));
1381
1382 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1383
1384 item.pszText = LPSTR_TEXTCALLBACKA;
1385 r = SendMessageA(hwnd, LVM_SETITEMTEXTA, 0 , (LPARAM) &item);
1386 expect(TRUE, r);
1387
1388 ok_sequence(sequences, PARENT_SEQ_INDEX, textcallback_set_again_parent_seq,
1389 "check callback text comparison rule", FALSE);
1390
1391 DestroyWindow(hwnd);
1392 }
1393
1394 static void test_columns(void)
1395 {
1396 HWND hwnd;
1397 LVCOLUMNA column;
1398 LVITEMA item;
1399 INT order[2];
1400 CHAR buff[5];
1401 DWORD rc;
1402
1403 hwnd = CreateWindowExA(0, "SysListView32", "foo", LVS_REPORT,
1404 10, 10, 100, 200, hwndparent, NULL, NULL, NULL);
1405 ok(hwnd != NULL, "failed to create listview window\n");
1406
1407 /* Add a column with no mask */
1408 memset(&column, 0xcc, sizeof(column));
1409 column.mask = 0;
1410 rc = SendMessageA(hwnd, LVM_INSERTCOLUMNA, 0, (LPARAM)&column);
1411 ok(rc == 0, "Inserting column with no mask failed with %d\n", rc);
1412
1413 /* Check its width */
1414 rc = SendMessageA(hwnd, LVM_GETCOLUMNWIDTH, 0, 0);
1415 ok(rc == 10, "Inserting column with no mask failed to set width to 10 with %d\n", rc);
1416
1417 DestroyWindow(hwnd);
1418
1419 /* LVM_GETCOLUMNORDERARRAY */
1420 hwnd = create_listview_control(LVS_REPORT);
1421 subclass_header(hwnd);
1422
1423 memset(&column, 0, sizeof(column));
1424 column.mask = LVCF_WIDTH;
1425 column.cx = 100;
1426 rc = SendMessageA(hwnd, LVM_INSERTCOLUMNA, 0, (LPARAM)&column);
1427 expect(0, rc);
1428
1429 column.cx = 200;
1430 rc = SendMessageA(hwnd, LVM_INSERTCOLUMNA, 1, (LPARAM)&column);
1431 expect(1, rc);
1432
1433 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1434
1435 rc = SendMessageA(hwnd, LVM_GETCOLUMNORDERARRAY, 2, (LPARAM)&order);
1436 expect(1, rc);
1437 ok(order[0] == 0, "Expected order 0, got %d\n", order[0]);
1438 ok(order[1] == 1, "Expected order 1, got %d\n", order[1]);
1439
1440 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_getorderarray_seq, "get order array", FALSE);
1441
1442 /* after column added subitem is considered as present */
1443 insert_item(hwnd, 0);
1444
1445 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1446
1447 item.pszText = buff;
1448 item.cchTextMax = sizeof(buff);
1449 item.iItem = 0;
1450 item.iSubItem = 1;
1451 item.mask = LVIF_TEXT;
1452 memset(&g_itema, 0, sizeof(g_itema));
1453 rc = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM)&item);
1454 expect(1, rc);
1455 ok(g_itema.iSubItem == 1, "got %d\n", g_itema.iSubItem);
1456
1457 ok_sequence(sequences, PARENT_SEQ_INDEX, single_getdispinfo_parent_seq,
1458 "get subitem text after column added", FALSE);
1459
1460 DestroyWindow(hwnd);
1461 }
1462
1463 /* test setting imagelist between WM_NCCREATE and WM_CREATE */
1464 static WNDPROC listviewWndProc;
1465 static HIMAGELIST test_create_imagelist;
1466
1467 static LRESULT CALLBACK create_test_wndproc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1468 {
1469 LRESULT ret;
1470
1471 if (uMsg == WM_CREATE)
1472 {
1473 CREATESTRUCTA *lpcs = (CREATESTRUCTA*)lParam;
1474 lpcs->style |= LVS_REPORT;
1475 }
1476 ret = CallWindowProcA(listviewWndProc, hwnd, uMsg, wParam, lParam);
1477 if (uMsg == WM_CREATE) SendMessageA(hwnd, LVM_SETIMAGELIST, 0, (LPARAM)test_create_imagelist);
1478 return ret;
1479 }
1480
1481 static void test_create(void)
1482 {
1483 HWND hList;
1484 HWND hHeader;
1485 LONG_PTR ret;
1486 LONG r;
1487 LVCOLUMNA col;
1488 RECT rect;
1489 WNDCLASSEXA cls;
1490 DWORD style;
1491
1492 cls.cbSize = sizeof(WNDCLASSEXA);
1493 ok(GetClassInfoExA(GetModuleHandleA(NULL), "SysListView32", &cls), "GetClassInfoEx failed\n");
1494 listviewWndProc = cls.lpfnWndProc;
1495 cls.lpfnWndProc = create_test_wndproc;
1496 cls.lpszClassName = "MyListView32";
1497 ok(RegisterClassExA(&cls), "RegisterClassEx failed\n");
1498
1499 test_create_imagelist = ImageList_Create(16, 16, 0, 5, 10);
1500 hList = CreateWindowA("MyListView32", "Test", WS_VISIBLE, 0, 0, 100, 100, NULL, NULL, GetModuleHandleA(NULL), 0);
1501 ok((HIMAGELIST)SendMessageA(hList, LVM_GETIMAGELIST, 0, 0) == test_create_imagelist, "Image list not obtained\n");
1502 hHeader = (HWND)SendMessageA(hList, LVM_GETHEADER, 0, 0);
1503
1504 if (!IsWindow(hHeader))
1505 {
1506 /* version 4.0 */
1507 win_skip("LVM_GETHEADER not implemented. Skipping.\n");
1508 DestroyWindow(hList);
1509 return;
1510 }
1511
1512 ok(IsWindow(hHeader) && IsWindowVisible(hHeader), "Listview not in report mode\n");
1513 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1514 DestroyWindow(hList);
1515
1516 /* header isn't created on LVS_ICON and LVS_LIST styles */
1517 hList = CreateWindowA("SysListView32", "Test", WS_VISIBLE, 0, 0, 100, 100, NULL, NULL,
1518 GetModuleHandleA(NULL), 0);
1519 hHeader = (HWND)SendMessageA(hList, LVM_GETHEADER, 0, 0);
1520 ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1521 ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1522 /* insert column */
1523 memset(&col, 0, sizeof(LVCOLUMNA));
1524 col.mask = LVCF_WIDTH;
1525 col.cx = 100;
1526 r = SendMessageA(hList, LVM_INSERTCOLUMNA, 0, (LPARAM)&col);
1527 expect(0, r);
1528 hHeader = (HWND)SendMessageA(hList, LVM_GETHEADER, 0, 0);
1529 ok(IsWindow(hHeader), "Header should be created\n");
1530 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1531 style = GetWindowLongA(hHeader, GWL_STYLE);
1532 ok(!(style & HDS_HIDDEN), "Not expected HDS_HIDDEN\n");
1533 DestroyWindow(hList);
1534
1535 hList = CreateWindowA("SysListView32", "Test", WS_VISIBLE|LVS_LIST, 0, 0, 100, 100, NULL, NULL,
1536 GetModuleHandleA(NULL), 0);
1537 hHeader = (HWND)SendMessageA(hList, LVM_GETHEADER, 0, 0);
1538 ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1539 ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1540 /* insert column */
1541 memset(&col, 0, sizeof(LVCOLUMNA));
1542 col.mask = LVCF_WIDTH;
1543 col.cx = 100;
1544 r = SendMessageA(hList, LVM_INSERTCOLUMNA, 0, (LPARAM)&col);
1545 expect(0, r);
1546 hHeader = (HWND)SendMessageA(hList, LVM_GETHEADER, 0, 0);
1547 ok(IsWindow(hHeader), "Header should be created\n");
1548 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1549 DestroyWindow(hList);
1550
1551 /* try to switch LVS_ICON -> LVS_REPORT and back LVS_ICON -> LVS_REPORT */
1552 hList = CreateWindowA("SysListView32", "Test", WS_VISIBLE, 0, 0, 100, 100, NULL, NULL,
1553 GetModuleHandleA(NULL), 0);
1554 ret = SetWindowLongPtrA(hList, GWL_STYLE, GetWindowLongPtrA(hList, GWL_STYLE) | LVS_REPORT);
1555 ok(ret & WS_VISIBLE, "Style wrong, should have WS_VISIBLE\n");
1556 hHeader = (HWND)SendMessageA(hList, LVM_GETHEADER, 0, 0);
1557 ok(IsWindow(hHeader), "Header should be created\n");
1558 ret = SetWindowLongPtrA(hList, GWL_STYLE, GetWindowLongA(hList, GWL_STYLE) & ~LVS_REPORT);
1559 ok((ret & WS_VISIBLE) && (ret & LVS_REPORT), "Style wrong, should have WS_VISIBLE|LVS_REPORT\n");
1560 hHeader = (HWND)SendMessageA(hList, LVM_GETHEADER, 0, 0);
1561 ok(IsWindow(hHeader), "Header should be created\n");
1562 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1563 DestroyWindow(hList);
1564
1565 /* try to switch LVS_LIST -> LVS_REPORT and back LVS_LIST -> LVS_REPORT */
1566 hList = CreateWindowA("SysListView32", "Test", WS_VISIBLE|LVS_LIST, 0, 0, 100, 100, NULL, NULL,
1567 GetModuleHandleA(NULL), 0);
1568 ret = SetWindowLongPtrA(hList, GWL_STYLE,
1569 (GetWindowLongPtrA(hList, GWL_STYLE) & ~LVS_LIST) | LVS_REPORT);
1570 ok(((ret & WS_VISIBLE) && (ret & LVS_LIST)), "Style wrong, should have WS_VISIBLE|LVS_LIST\n");
1571 hHeader = (HWND)SendMessageA(hList, LVM_GETHEADER, 0, 0);
1572 ok(IsWindow(hHeader), "Header should be created\n");
1573 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1574 ret = SetWindowLongPtrA(hList, GWL_STYLE,
1575 (GetWindowLongPtrA(hList, GWL_STYLE) & ~LVS_REPORT) | LVS_LIST);
1576 ok(((ret & WS_VISIBLE) && (ret & LVS_REPORT)), "Style wrong, should have WS_VISIBLE|LVS_REPORT\n");
1577 hHeader = (HWND)SendMessageA(hList, LVM_GETHEADER, 0, 0);
1578 ok(IsWindow(hHeader), "Header should be created\n");
1579 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1580 DestroyWindow(hList);
1581
1582 /* LVS_REPORT without WS_VISIBLE */
1583 hList = CreateWindowA("SysListView32", "Test", LVS_REPORT, 0, 0, 100, 100, NULL, NULL,
1584 GetModuleHandleA(NULL), 0);
1585 hHeader = (HWND)SendMessageA(hList, LVM_GETHEADER, 0, 0);
1586 ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1587 ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1588 /* insert column */
1589 memset(&col, 0, sizeof(LVCOLUMNA));
1590 col.mask = LVCF_WIDTH;
1591 col.cx = 100;
1592 r = SendMessageA(hList, LVM_INSERTCOLUMNA, 0, (LPARAM)&col);
1593 expect(0, r);
1594 hHeader = (HWND)SendMessageA(hList, LVM_GETHEADER, 0, 0);
1595 ok(IsWindow(hHeader), "Header should be created\n");
1596 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1597 DestroyWindow(hList);
1598
1599 /* LVS_REPORT without WS_VISIBLE, try to show it */
1600 hList = CreateWindowA("SysListView32", "Test", LVS_REPORT, 0, 0, 100, 100, NULL, NULL,
1601 GetModuleHandleA(NULL), 0);
1602 hHeader = (HWND)SendMessageA(hList, LVM_GETHEADER, 0, 0);
1603 ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1604 ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1605 ShowWindow(hList, SW_SHOW);
1606 hHeader = (HWND)SendMessageA(hList, LVM_GETHEADER, 0, 0);
1607 ok(IsWindow(hHeader), "Header should be created\n");
1608 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1609 DestroyWindow(hList);
1610
1611 /* LVS_REPORT with LVS_NOCOLUMNHEADER */
1612 hList = CreateWindowA("SysListView32", "Test", LVS_REPORT|LVS_NOCOLUMNHEADER|WS_VISIBLE,
1613 0, 0, 100, 100, NULL, NULL, GetModuleHandleA(NULL), 0);
1614 hHeader = (HWND)SendMessageA(hList, LVM_GETHEADER, 0, 0);
1615 ok(IsWindow(hHeader), "Header should be created\n");
1616 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1617 /* HDS_DRAGDROP set by default */
1618 ok(GetWindowLongPtrA(hHeader, GWL_STYLE) & HDS_DRAGDROP, "Expected header to have HDS_DRAGDROP\n");
1619 DestroyWindow(hList);
1620
1621 /* setting LVS_EX_HEADERDRAGDROP creates header */
1622 hList = CreateWindowA("SysListView32", "Test", LVS_REPORT, 0, 0, 100, 100, NULL, NULL,
1623 GetModuleHandleA(NULL), 0);
1624 hHeader = (HWND)SendMessageA(hList, LVM_GETHEADER, 0, 0);
1625 ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1626 ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1627 SendMessageA(hList, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_HEADERDRAGDROP);
1628 hHeader = (HWND)SendMessageA(hList, LVM_GETHEADER, 0, 0);
1629 ok(IsWindow(hHeader) ||
1630 broken(!IsWindow(hHeader)), /* 4.7x common controls */
1631 "Header should be created\n");
1632 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1633 DestroyWindow(hList);
1634
1635 /* setting LVS_EX_GRIDLINES creates header */
1636 hList = CreateWindowA("SysListView32", "Test", LVS_REPORT, 0, 0, 100, 100, NULL, NULL,
1637 GetModuleHandleA(NULL), 0);
1638 hHeader = (HWND)SendMessageA(hList, LVM_GETHEADER, 0, 0);
1639 ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1640 ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1641 SendMessageA(hList, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_GRIDLINES);
1642 hHeader = (HWND)SendMessageA(hList, LVM_GETHEADER, 0, 0);
1643 ok(IsWindow(hHeader) ||
1644 broken(!IsWindow(hHeader)), /* 4.7x common controls */
1645 "Header should be created\n");
1646 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1647 DestroyWindow(hList);
1648
1649 /* setting LVS_EX_FULLROWSELECT creates header */
1650 hList = CreateWindowA("SysListView32", "Test", LVS_REPORT, 0, 0, 100, 100, NULL, NULL,
1651 GetModuleHandleA(NULL), 0);
1652 hHeader = (HWND)SendMessageA(hList, LVM_GETHEADER, 0, 0);
1653 ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1654 ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1655 SendMessageA(hList, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_FULLROWSELECT);
1656 hHeader = (HWND)SendMessageA(hList, LVM_GETHEADER, 0, 0);
1657 ok(IsWindow(hHeader) ||
1658 broken(!IsWindow(hHeader)), /* 4.7x common controls */
1659 "Header should be created\n");
1660 ok(hHeader == GetDlgItem(hList, 0), "Expected header as dialog item\n");
1661 DestroyWindow(hList);
1662
1663 /* not report style accepts LVS_EX_HEADERDRAGDROP too */
1664 hList = create_listview_control(LVS_ICON);
1665 SendMessageA(hList, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_HEADERDRAGDROP);
1666 r = SendMessageA(hList, LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0);
1667 ok(r & LVS_EX_HEADERDRAGDROP, "Expected LVS_EX_HEADERDRAGDROP to be set\n");
1668 DestroyWindow(hList);
1669
1670 /* requesting header info with LVM_GETSUBITEMRECT doesn't create it */
1671 hList = CreateWindowA("SysListView32", "Test", LVS_REPORT, 0, 0, 100, 100, NULL, NULL,
1672 GetModuleHandleA(NULL), 0);
1673 ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1674 ok(NULL == GetDlgItem(hList, 0), "NULL dialog item expected\n");
1675
1676 rect.left = LVIR_BOUNDS;
1677 rect.top = 1;
1678 rect.right = rect.bottom = -10;
1679 r = SendMessageA(hList, LVM_GETSUBITEMRECT, -1, (LPARAM)&rect);
1680 /* right value contains garbage, probably because header columns are not set up */
1681 expect(0, rect.bottom);
1682 expect(1, r);
1683
1684 hHeader = (HWND)SendMessageA(hList, LVM_GETHEADER, 0, 0);
1685 ok(!IsWindow(hHeader), "Header shouldn't be created\n");
1686 ok(GetDlgItem(hList, 0) == NULL, "NULL dialog item expected\n");
1687
1688 DestroyWindow(hList);
1689
1690 /* WM_MEASUREITEM should be sent when created with LVS_OWNERDRAWFIXED */
1691 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1692 hList = create_listview_control(LVS_OWNERDRAWFIXED | LVS_REPORT);
1693 ok_sequence(sequences, PARENT_SEQ_INDEX, create_ownerdrawfixed_parent_seq,
1694 "created with LVS_OWNERDRAWFIXED|LVS_REPORT - parent seq", FALSE);
1695 DestroyWindow(hList);
1696 }
1697
1698 static void test_redraw(void)
1699 {
1700 HWND hwnd;
1701 HDC hdc;
1702 BOOL res;
1703 DWORD r;
1704
1705 hwnd = create_listview_control(LVS_REPORT);
1706 subclass_header(hwnd);
1707
1708 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1709
1710 InvalidateRect(hwnd, NULL, TRUE);
1711 UpdateWindow(hwnd);
1712 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, redraw_listview_seq, "redraw listview", FALSE);
1713
1714 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1715
1716 /* forward WM_ERASEBKGND to parent on CLR_NONE background color */
1717 /* 1. Without backbuffer */
1718 res = SendMessageA(hwnd, LVM_SETBKCOLOR, 0, CLR_NONE);
1719 expect(TRUE, res);
1720
1721 hdc = GetWindowDC(hwndparent);
1722
1723 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1724 r = SendMessageA(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
1725 ok(r == 1, "Expected not zero result\n");
1726 ok_sequence(sequences, PARENT_FULL_SEQ_INDEX, forward_erasebkgnd_parent_seq,
1727 "forward WM_ERASEBKGND on CLR_NONE", FALSE);
1728
1729 res = SendMessageA(hwnd, LVM_SETBKCOLOR, 0, CLR_DEFAULT);
1730 expect(TRUE, res);
1731
1732 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1733 r = SendMessageA(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
1734 expect(1, r);
1735 ok_sequence(sequences, PARENT_FULL_SEQ_INDEX, empty_seq,
1736 "don't forward WM_ERASEBKGND on non-CLR_NONE", FALSE);
1737
1738 /* 2. With backbuffer */
1739 SendMessageA(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_DOUBLEBUFFER,
1740 LVS_EX_DOUBLEBUFFER);
1741 res = SendMessageA(hwnd, LVM_SETBKCOLOR, 0, CLR_NONE);
1742 expect(TRUE, res);
1743
1744 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1745 r = SendMessageA(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
1746 expect(1, r);
1747 ok_sequence(sequences, PARENT_FULL_SEQ_INDEX, forward_erasebkgnd_parent_seq,
1748 "forward WM_ERASEBKGND on CLR_NONE", FALSE);
1749
1750 res = SendMessageA(hwnd, LVM_SETBKCOLOR, 0, CLR_DEFAULT);
1751 expect(TRUE, res);
1752
1753 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1754 r = SendMessageA(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
1755 todo_wine expect(1, r);
1756 ok_sequence(sequences, PARENT_FULL_SEQ_INDEX, empty_seq,
1757 "don't forward WM_ERASEBKGND on non-CLR_NONE", FALSE);
1758
1759 ReleaseDC(hwndparent, hdc);
1760
1761 DestroyWindow(hwnd);
1762 }
1763
1764 static LRESULT WINAPI cd_wndproc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
1765 {
1766 COLORREF clr, c0ffee = RGB(0xc0, 0xff, 0xee);
1767
1768 if(msg == WM_NOTIFY) {
1769 NMHDR *nmhdr = (PVOID)lp;
1770 if(nmhdr->code == NM_CUSTOMDRAW) {
1771 NMLVCUSTOMDRAW *nmlvcd = (NMLVCUSTOMDRAW*)nmhdr;
1772
1773 switch(nmlvcd->nmcd.dwDrawStage) {
1774 case CDDS_PREPAINT:
1775 SetBkColor(nmlvcd->nmcd.hdc, c0ffee);
1776 return CDRF_NOTIFYITEMDRAW;
1777 case CDDS_ITEMPREPAINT:
1778 nmlvcd->clrTextBk = CLR_DEFAULT;
1779 return CDRF_NOTIFYSUBITEMDRAW;
1780 case CDDS_ITEMPREPAINT | CDDS_SUBITEM:
1781 clr = GetBkColor(nmlvcd->nmcd.hdc);
1782 if (nmlvcd->iSubItem)
1783 todo_wine ok(clr == c0ffee, "clr=%.8x\n", clr);
1784 else
1785 ok(clr == c0ffee, "clr=%.8x\n", clr);
1786 return CDRF_NOTIFYPOSTPAINT;
1787 case CDDS_ITEMPOSTPAINT | CDDS_SUBITEM:
1788 clr = GetBkColor(nmlvcd->nmcd.hdc);
1789 todo_wine ok(clr == c0ffee, "clr=%.8x\n", clr);
1790 return CDRF_DODEFAULT;
1791 }
1792 return CDRF_DODEFAULT;
1793 }
1794 }
1795
1796 return DefWindowProcA(hwnd, msg, wp, lp);
1797 }
1798
1799 static void test_customdraw(void)
1800 {
1801 HWND hwnd;
1802 WNDPROC oldwndproc;
1803
1804 hwnd = create_listview_control(LVS_REPORT);
1805
1806 insert_column(hwnd, 0);
1807 insert_column(hwnd, 1);
1808 insert_item(hwnd, 0);
1809
1810 oldwndproc = (WNDPROC)SetWindowLongPtrA(hwndparent, GWLP_WNDPROC,
1811 (LONG_PTR)cd_wndproc);
1812
1813 InvalidateRect(hwnd, NULL, TRUE);
1814 UpdateWindow(hwnd);
1815
1816 SetWindowLongPtrA(hwndparent, GWLP_WNDPROC, (LONG_PTR)oldwndproc);
1817
1818 DestroyWindow(hwnd);
1819 }
1820
1821 static void test_icon_spacing(void)
1822 {
1823 /* LVM_SETICONSPACING */
1824 /* note: LVM_SETICONSPACING returns the previous icon spacing if successful */
1825
1826 HWND hwnd;
1827 WORD w, h;
1828 INT r;
1829
1830 hwnd = create_listview_control(LVS_ICON);
1831 ok(hwnd != NULL, "failed to create a listview window\n");
1832
1833 r = SendMessageA(hwnd, WM_NOTIFYFORMAT, (WPARAM)hwndparent, NF_REQUERY);
1834 expect(NFR_ANSI, r);
1835
1836 /* reset the icon spacing to defaults */
1837 SendMessageA(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(-1, -1));
1838
1839 /* now we can request what the defaults are */
1840 r = SendMessageA(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(-1, -1));
1841 w = LOWORD(r);
1842 h = HIWORD(r);
1843
1844 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1845
1846 r = SendMessageA(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(20, 30));
1847 ok(r == MAKELONG(w, h) ||
1848 broken(r == MAKELONG(w, w)), /* win98 */
1849 "Expected %d, got %d\n", MAKELONG(w, h), r);
1850
1851 r = SendMessageA(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(25, 35));
1852 if (r == 0)
1853 {
1854 /* version 4.0 */
1855 win_skip("LVM_SETICONSPACING unimplemented. Skipping.\n");
1856 DestroyWindow(hwnd);
1857 return;
1858 }
1859 expect(MAKELONG(20,30), r);
1860
1861 r = SendMessageA(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(-1,-1));
1862 expect(MAKELONG(25,35), r);
1863
1864 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_icon_spacing_seq, "test icon spacing seq", FALSE);
1865
1866 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1867 DestroyWindow(hwnd);
1868 }
1869
1870 static void test_color(void)
1871 {
1872 RECT rect;
1873 HWND hwnd;
1874 DWORD r;
1875 int i;
1876
1877 COLORREF color;
1878 COLORREF colors[4] = {RGB(0,0,0), RGB(100,50,200), CLR_NONE, RGB(255,255,255)};
1879
1880 hwnd = create_listview_control(LVS_REPORT);
1881 ok(hwnd != NULL, "failed to create a listview window\n");
1882
1883 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1884
1885 for (i = 0; i < 4; i++)
1886 {
1887 color = colors[i];
1888
1889 r = SendMessageA(hwnd, LVM_SETBKCOLOR, 0, color);
1890 expect(TRUE, r);
1891 r = SendMessageA(hwnd, LVM_GETBKCOLOR, 0, 0);
1892 expect(color, r);
1893
1894 r = SendMessageA(hwnd, LVM_SETTEXTCOLOR, 0, color);
1895 expect (TRUE, r);
1896 r = SendMessageA(hwnd, LVM_GETTEXTCOLOR, 0, 0);
1897 expect(color, r);
1898
1899 r = SendMessageA(hwnd, LVM_SETTEXTBKCOLOR, 0, color);
1900 expect(TRUE, r);
1901 r = SendMessageA(hwnd, LVM_GETTEXTBKCOLOR, 0, 0);
1902 expect(color, r);
1903 }
1904
1905 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_color_seq, "test color seq", FALSE);
1906 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1907
1908 /* invalidation test done separately to avoid a message chain mess */
1909 r = ValidateRect(hwnd, NULL);
1910 expect(TRUE, r);
1911 r = SendMessageA(hwnd, LVM_SETBKCOLOR, 0, colors[0]);
1912 expect(TRUE, r);
1913
1914 rect.right = rect.bottom = 1;
1915 r = GetUpdateRect(hwnd, &rect, TRUE);
1916 todo_wine expect(FALSE, r);
1917 ok(rect.right == 0 && rect.bottom == 0, "got update rectangle\n");
1918
1919 r = ValidateRect(hwnd, NULL);
1920 expect(TRUE, r);
1921 r = SendMessageA(hwnd, LVM_SETTEXTCOLOR, 0, colors[0]);
1922 expect(TRUE, r);
1923
1924 rect.right = rect.bottom = 1;
1925 r = GetUpdateRect(hwnd, &rect, TRUE);
1926 todo_wine expect(FALSE, r);
1927 ok(rect.right == 0 && rect.bottom == 0, "got update rectangle\n");
1928
1929 r = ValidateRect(hwnd, NULL);
1930 expect(TRUE, r);
1931 r = SendMessageA(hwnd, LVM_SETTEXTBKCOLOR, 0, colors[0]);
1932 expect(TRUE, r);
1933
1934 rect.right = rect.bottom = 1;
1935 r = GetUpdateRect(hwnd, &rect, TRUE);
1936 todo_wine expect(FALSE, r);
1937 ok(rect.right == 0 && rect.bottom == 0, "got update rectangle\n");
1938
1939 DestroyWindow(hwnd);
1940 }
1941
1942 static void test_item_count(void)
1943 {
1944 /* LVM_INSERTITEM, LVM_DELETEITEM, LVM_DELETEALLITEMS, LVM_GETITEMCOUNT */
1945
1946 HWND hwnd;
1947 DWORD r;
1948 HDC hdc;
1949 HFONT hOldFont;
1950 TEXTMETRICA tm;
1951 RECT rect;
1952 INT height;
1953
1954 LVITEMA item0;
1955 LVITEMA item1;
1956 LVITEMA item2;
1957 static CHAR item0text[] = "item0";
1958 static CHAR item1text[] = "item1";
1959 static CHAR item2text[] = "item2";
1960
1961 hwnd = create_listview_control(LVS_REPORT);
1962 ok(hwnd != NULL, "failed to create a listview window\n");
1963
1964 /* resize in dpiaware manner to fit all 3 items added */
1965 hdc = GetDC(0);
1966 hOldFont = SelectObject(hdc, GetStockObject(SYSTEM_FONT));
1967 GetTextMetricsA(hdc, &tm);
1968 /* 2 extra pixels for bounds and header border */
1969 height = tm.tmHeight + 2;
1970 SelectObject(hdc, hOldFont);
1971 ReleaseDC(0, hdc);
1972
1973 GetWindowRect(hwnd, &rect);
1974 /* 3 items + 1 header + 1 to be sure */
1975 MoveWindow(hwnd, 0, 0, rect.right - rect.left, 5 * height, FALSE);
1976
1977 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1978
1979 r = SendMessageA(hwnd, LVM_GETITEMCOUNT, 0, 0);
1980 expect(0, r);
1981
1982 /* [item0] */
1983 item0.mask = LVIF_TEXT;
1984 item0.iItem = 0;
1985 item0.iSubItem = 0;
1986 item0.pszText = item0text;
1987 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item0);
1988 expect(0, r);
1989
1990 /* [item0, item1] */
1991 item1.mask = LVIF_TEXT;
1992 item1.iItem = 1;
1993 item1.iSubItem = 0;
1994 item1.pszText = item1text;
1995 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item1);
1996 expect(1, r);
1997
1998 /* [item0, item1, item2] */
1999 item2.mask = LVIF_TEXT;
2000 item2.iItem = 2;
2001 item2.iSubItem = 0;
2002 item2.pszText = item2text;
2003 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item2);
2004 expect(2, r);
2005
2006 r = SendMessageA(hwnd, LVM_GETITEMCOUNT, 0, 0);
2007 expect(3, r);
2008
2009 /* [item0, item1] */
2010 r = SendMessageA(hwnd, LVM_DELETEITEM, 2, 0);
2011 expect(TRUE, r);
2012
2013 r = SendMessageA(hwnd, LVM_GETITEMCOUNT, 0, 0);
2014 expect(2, r);
2015
2016 /* [] */
2017 r = SendMessageA(hwnd, LVM_DELETEALLITEMS, 0, 0);
2018 expect(TRUE, r);
2019
2020 r = SendMessageA(hwnd, LVM_GETITEMCOUNT, 0, 0);
2021 expect(0, r);
2022
2023 /* [item0] */
2024 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item1);
2025 expect(0, r);
2026
2027 /* [item0, item1] */
2028 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item1);
2029 expect(1, r);
2030
2031 r = SendMessageA(hwnd, LVM_GETITEMCOUNT, 0, 0);
2032 expect(2, r);
2033
2034 /* [item0, item1, item2] */
2035 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item2);
2036 expect(2, r);
2037
2038 r = SendMessageA(hwnd, LVM_GETITEMCOUNT, 0, 0);
2039 expect(3, r);
2040
2041 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_item_count_seq, "test item count seq", FALSE);
2042
2043 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2044 DestroyWindow(hwnd);
2045 }
2046
2047 static void test_item_position(void)
2048 {
2049 /* LVM_SETITEMPOSITION/LVM_GETITEMPOSITION */
2050
2051 HWND hwnd;
2052 DWORD r;
2053 POINT position;
2054
2055 LVITEMA item0;
2056 LVITEMA item1;
2057 LVITEMA item2;
2058 static CHAR item0text[] = "item0";
2059 static CHAR item1text[] = "item1";
2060 static CHAR item2text[] = "item2";
2061
2062 hwnd = create_listview_control(LVS_ICON);
2063 ok(hwnd != NULL, "failed to create a listview window\n");
2064
2065 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2066
2067 /* [item0] */
2068 item0.mask = LVIF_TEXT;
2069 item0.iItem = 0;
2070 item0.iSubItem = 0;
2071 item0.pszText = item0text;
2072 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item0);
2073 expect(0, r);
2074
2075 /* [item0, item1] */
2076 item1.mask = LVIF_TEXT;
2077 item1.iItem = 1;
2078 item1.iSubItem = 0;
2079 item1.pszText = item1text;
2080 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item1);
2081 expect(1, r);
2082
2083 /* [item0, item1, item2] */
2084 item2.mask = LVIF_TEXT;
2085 item2.iItem = 2;
2086 item2.iSubItem = 0;
2087 item2.pszText = item2text;
2088 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item2);
2089 expect(2, r);
2090
2091 r = SendMessageA(hwnd, LVM_SETITEMPOSITION, 1, MAKELPARAM(10,5));
2092 expect(TRUE, r);
2093 r = SendMessageA(hwnd, LVM_GETITEMPOSITION, 1, (LPARAM) &position);
2094 expect(TRUE, r);
2095 expect2(10, 5, position.x, position.y);
2096
2097 r = SendMessageA(hwnd, LVM_SETITEMPOSITION, 2, MAKELPARAM(0,0));
2098 expect(TRUE, r);
2099 r = SendMessageA(hwnd, LVM_GETITEMPOSITION, 2, (LPARAM) &position);
2100 expect(TRUE, r);
2101 expect2(0, 0, position.x, position.y);
2102
2103 r = SendMessageA(hwnd, LVM_SETITEMPOSITION, 0, MAKELPARAM(20,20));
2104 expect(TRUE, r);
2105 r = SendMessageA(hwnd, LVM_GETITEMPOSITION, 0, (LPARAM) &position);
2106 expect(TRUE, r);
2107 expect2(20, 20, position.x, position.y);
2108
2109 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_itempos_seq, "test item position seq", TRUE);
2110
2111 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2112 DestroyWindow(hwnd);
2113 }
2114
2115 static void test_getorigin(void)
2116 {
2117 /* LVM_GETORIGIN */
2118
2119 HWND hwnd;
2120 DWORD r;
2121 POINT position;
2122
2123 position.x = position.y = 0;
2124
2125 hwnd = create_listview_control(LVS_ICON);
2126 ok(hwnd != NULL, "failed to create a listview window\n");
2127 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2128
2129 r = SendMessageA(hwnd, LVM_GETORIGIN, 0, (LPARAM)&position);
2130 expect(TRUE, r);
2131 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2132 DestroyWindow(hwnd);
2133
2134 hwnd = create_listview_control(LVS_SMALLICON);
2135 ok(hwnd != NULL, "failed to create a listview window\n");
2136 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2137
2138 r = SendMessageA(hwnd, LVM_GETORIGIN, 0, (LPARAM)&position);
2139 expect(TRUE, r);
2140 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2141 DestroyWindow(hwnd);
2142
2143 hwnd = create_listview_control(LVS_LIST);
2144 ok(hwnd != NULL, "failed to create a listview window\n");
2145 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2146
2147 r = SendMessageA(hwnd, LVM_GETORIGIN, 0, (LPARAM)&position);
2148 expect(FALSE, r);
2149 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2150 DestroyWindow(hwnd);
2151
2152 hwnd = create_listview_control(LVS_REPORT);
2153 ok(hwnd != NULL, "failed to create a listview window\n");
2154 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2155
2156 r = SendMessageA(hwnd, LVM_GETORIGIN, 0, (LPARAM)&position);
2157 expect(FALSE, r);
2158 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2159 DestroyWindow(hwnd);
2160 }
2161
2162 static void test_multiselect(void)
2163 {
2164 typedef struct t_select_task
2165 {
2166 const char *descr;
2167 int initPos;
2168 int loopVK;
2169 int count;
2170 int result;
2171 } select_task;
2172
2173 HWND hwnd;
2174 INT r;
2175 int i,j,item_count,selected_count;
2176 static const int items=5;
2177 BYTE kstate[256];
2178 select_task task;
2179 LONG_PTR style;
2180 LVITEMA item;
2181
2182 static struct t_select_task task_list[] = {
2183 { "using VK_DOWN", 0, VK_DOWN, -1, -1 },
2184 { "using VK_UP", -1, VK_UP, -1, -1 },
2185 { "using VK_END", 0, VK_END, 1, -1 },
2186 { "using VK_HOME", -1, VK_HOME, 1, -1 }
2187 };
2188
2189 hwnd = create_listview_control(LVS_REPORT);
2190
2191 for (i = 0; i < items; i++)
2192 insert_item(hwnd, 0);
2193
2194 item_count = (int)SendMessageA(hwnd, LVM_GETITEMCOUNT, 0, 0);
2195 expect(items, item_count);
2196
2197 for (i = 0; i < 4; i++) {
2198 LVITEMA item;
2199
2200 task = task_list[i];
2201
2202 /* deselect all items */
2203 item.state = 0;
2204 item.stateMask = LVIS_SELECTED;
2205 SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2206 SendMessageA(hwnd, LVM_SETSELECTIONMARK, 0, -1);
2207
2208 /* set initial position */
2209 SendMessageA(hwnd, LVM_SETSELECTIONMARK, 0, (task.initPos == -1 ? item_count -1 : task.initPos));
2210
2211 item.state = LVIS_SELECTED;
2212 item.stateMask = LVIS_SELECTED;
2213 SendMessageA(hwnd, LVM_SETITEMSTATE, task.initPos == -1 ? item_count-1 : task.initPos, (LPARAM)&item);
2214
2215 selected_count = SendMessageA(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2216 ok(selected_count == 1, "expected 1, got %d\n", selected_count);
2217
2218 /* Set SHIFT key pressed */
2219 GetKeyboardState(kstate);
2220 kstate[VK_SHIFT]=0x80;
2221 SetKeyboardState(kstate);
2222
2223 for (j=1;j<=(task.count == -1 ? item_count : task.count);j++) {
2224 r = SendMessageA(hwnd, WM_KEYDOWN, task.loopVK, 0);
2225 expect(0,r);
2226 r = SendMessageA(hwnd, WM_KEYUP, task.loopVK, 0);
2227 expect(0,r);
2228 }
2229
2230 selected_count = (int)SendMessageA(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2231
2232 ok((task.result == -1 ? item_count : task.result) == selected_count, "Failed multiple selection %s. There should be %d selected items (is %d)\n", task.descr, item_count, selected_count);
2233
2234 /* Set SHIFT key released */
2235 GetKeyboardState(kstate);
2236 kstate[VK_SHIFT]=0x00;
2237 SetKeyboardState(kstate);
2238 }
2239 DestroyWindow(hwnd);
2240
2241 /* make multiple selection, then switch to LVS_SINGLESEL */
2242 hwnd = create_listview_control(LVS_REPORT);
2243 for (i=0;i<items;i++) {
2244 insert_item(hwnd, 0);
2245 }
2246 item_count = (int)SendMessageA(hwnd, LVM_GETITEMCOUNT, 0, 0);
2247 expect(items,item_count);
2248
2249 /* try with NULL pointer */
2250 r = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, 0);
2251 expect(FALSE, r);
2252
2253 /* select all, check notifications */
2254 item.state = 0;
2255 item.stateMask = LVIS_SELECTED;
2256 SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2257
2258 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2259
2260 item.stateMask = LVIS_SELECTED;
2261 item.state = LVIS_SELECTED;
2262 r = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2263 expect(TRUE, r);
2264
2265 ok_sequence(sequences, PARENT_SEQ_INDEX, change_all_parent_seq,
2266 "select all notification", FALSE);
2267
2268 /* select all again (all selected already) */
2269 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2270
2271 memset(&g_nmlistview_changing, 0xcc, sizeof(g_nmlistview_changing));
2272
2273 item.stateMask = LVIS_SELECTED;
2274 item.state = LVIS_SELECTED;
2275 r = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2276 expect(TRUE, r);
2277
2278 ok(g_nmlistview_changing.uNewState == LVIS_SELECTED, "got 0x%x\n", g_nmlistview_changing.uNewState);
2279 ok(g_nmlistview_changing.uOldState == LVIS_SELECTED, "got 0x%x\n", g_nmlistview_changing.uOldState);
2280 ok(g_nmlistview_changing.uChanged == LVIF_STATE, "got 0x%x\n", g_nmlistview_changing.uChanged);
2281
2282 ok_sequence(sequences, PARENT_SEQ_INDEX, changing_all_parent_seq,
2283 "select all notification 2", FALSE);
2284
2285 /* deselect all items */
2286 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2287
2288 item.state = 0;
2289 item.stateMask = LVIS_SELECTED;
2290 SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2291
2292 ok_sequence(sequences, PARENT_SEQ_INDEX, change_all_parent_seq,
2293 "deselect all notification", FALSE);
2294
2295 /* deselect all items again */
2296 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2297 item.state = 0;
2298 item.stateMask = LVIS_SELECTED;
2299 SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2300 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq, "deselect all notification 2", FALSE);
2301
2302 /* any non-zero state value does the same */
2303 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2304
2305 memset(&g_nmlistview_changing, 0xcc, sizeof(g_nmlistview_changing));
2306
2307 item.stateMask = LVIS_SELECTED;
2308 item.state = LVIS_CUT;
2309 r = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2310 expect(TRUE, r);
2311
2312 ok(g_nmlistview_changing.uNewState == 0, "got 0x%x\n", g_nmlistview_changing.uNewState);
2313 ok(g_nmlistview_changing.uOldState == 0, "got 0x%x\n", g_nmlistview_changing.uOldState);
2314 ok(g_nmlistview_changing.uChanged == LVIF_STATE, "got 0x%x\n", g_nmlistview_changing.uChanged);
2315
2316 ok_sequence(sequences, PARENT_SEQ_INDEX, changing_all_parent_seq,
2317 "set state all notification 3", FALSE);
2318
2319 SendMessageA(hwnd, LVM_SETSELECTIONMARK, 0, -1);
2320 for (i = 0; i < 3; i++) {
2321 item.state = LVIS_SELECTED;
2322 item.stateMask = LVIS_SELECTED;
2323 SendMessageA(hwnd, LVM_SETITEMSTATE, i, (LPARAM)&item);
2324 }
2325
2326 r = SendMessageA(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2327 expect(3, r);
2328 r = SendMessageA(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2329 expect(-1, r);
2330
2331 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2332 ok(!(style & LVS_SINGLESEL), "LVS_SINGLESEL isn't expected\n");
2333 SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_SINGLESEL);
2334 /* check that style is accepted */
2335 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2336 ok(style & LVS_SINGLESEL, "LVS_SINGLESEL expected\n");
2337
2338 for (i=0;i<3;i++) {
2339 r = SendMessageA(hwnd, LVM_GETITEMSTATE, i, LVIS_SELECTED);
2340 ok(r & LVIS_SELECTED, "Expected item %d to be selected\n", i);
2341 }
2342 r = SendMessageA(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2343 expect(3, r);
2344 SendMessageA(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2345 expect(3, r);
2346
2347 /* select one more */
2348 item.state = LVIS_SELECTED;
2349 item.stateMask = LVIS_SELECTED;
2350 SendMessageA(hwnd, LVM_SETITEMSTATE, 3, (LPARAM)&item);
2351
2352 for (i=0;i<3;i++) {
2353 r = SendMessageA(hwnd, LVM_GETITEMSTATE, i, LVIS_SELECTED);
2354 ok(!(r & LVIS_SELECTED), "Expected item %d to be unselected\n", i);
2355 }
2356
2357 r = SendMessageA(hwnd, LVM_GETITEMSTATE, 3, LVIS_SELECTED);
2358 ok(r & LVIS_SELECTED, "Expected item %d to be selected\n", i);
2359
2360 r = SendMessageA(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2361 expect(1, r);
2362 r = SendMessageA(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2363 expect(-1, r);
2364
2365 /* try to select all on LVS_SINGLESEL */
2366 memset(&item, 0, sizeof(item));
2367 item.stateMask = LVIS_SELECTED;
2368 r = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2369 expect(TRUE, r);
2370 SendMessageA(hwnd, LVM_SETSELECTIONMARK, 0, -1);
2371
2372 item.stateMask = LVIS_SELECTED;
2373 item.state = LVIS_SELECTED;
2374 r = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2375 expect(FALSE, r);
2376
2377 r = SendMessageA(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2378 expect(0, r);
2379 r = SendMessageA(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2380 expect(-1, r);
2381
2382 /* try to deselect all on LVS_SINGLESEL */
2383 item.stateMask = LVIS_SELECTED;
2384 item.state = LVIS_SELECTED;
2385 r = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
2386 expect(TRUE, r);
2387
2388 item.stateMask = LVIS_SELECTED;
2389 item.state = 0;
2390 r = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2391 expect(TRUE, r);
2392 r = SendMessageA(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2393 expect(0, r);
2394
2395 /* 1. selection mark is update when new focused item is set */
2396 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2397 SetWindowLongPtrA(hwnd, GWL_STYLE, style & ~LVS_SINGLESEL);
2398
2399 r = SendMessageA(hwnd, LVM_SETSELECTIONMARK, 0, -1);
2400 expect(-1, r);
2401
2402 item.stateMask = LVIS_FOCUSED;
2403 item.state = LVIS_FOCUSED;
2404 r = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
2405 expect(TRUE, r);
2406
2407 r = SendMessageA(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2408 expect(0, r);
2409
2410 /* it's not updated if already set */
2411 item.stateMask = LVIS_FOCUSED;
2412 item.state = LVIS_FOCUSED;
2413 r = SendMessageA(hwnd, LVM_SETITEMSTATE, 1, (LPARAM)&item);
2414 expect(TRUE, r);
2415
2416 r = SendMessageA(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2417 expect(0, r);
2418
2419 r = SendMessageA(hwnd, LVM_SETSELECTIONMARK, 0, -1);
2420 expect(0, r);
2421
2422 item.stateMask = LVIS_FOCUSED;
2423 item.state = LVIS_FOCUSED;
2424 r = SendMessageA(hwnd, LVM_SETITEMSTATE, 1, (LPARAM)&item);
2425 expect(TRUE, r);
2426
2427 r = SendMessageA(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2428 expect(-1, r);
2429
2430 /* need to reset focused item first */
2431 item.stateMask = LVIS_FOCUSED;
2432 item.state = 0;
2433 r = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2434 expect(TRUE, r);
2435
2436 item.stateMask = LVIS_FOCUSED;
2437 item.state = LVIS_FOCUSED;
2438 r = SendMessageA(hwnd, LVM_SETITEMSTATE, 2, (LPARAM)&item);
2439 expect(TRUE, r);
2440
2441 r = SendMessageA(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2442 expect(2, r);
2443
2444 item.stateMask = LVIS_FOCUSED;
2445 item.state = 0;
2446 r = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2447 expect(TRUE, r);
2448
2449 r = SendMessageA(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2450 expect(2, r);
2451
2452 /* 2. same tests, with LVM_SETITEM */
2453 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2454 SetWindowLongPtrA(hwnd, GWL_STYLE, style & ~LVS_SINGLESEL);
2455
2456 r = SendMessageA(hwnd, LVM_SETSELECTIONMARK, 0, -1);
2457 expect(2, r);
2458
2459 item.stateMask = LVIS_FOCUSED;
2460 item.state = LVIS_FOCUSED;
2461 item.mask = LVIF_STATE;
2462 item.iItem = item.iSubItem = 0;
2463 r = SendMessageA(hwnd, LVM_SETITEMA, 0, (LPARAM)&item);
2464 expect(TRUE, r);
2465
2466 r = SendMessageA(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2467 expect(0, r);
2468
2469 /* it's not updated if already set */
2470 item.stateMask = LVIS_FOCUSED;
2471 item.state = LVIS_FOCUSED;
2472 item.mask = LVIF_STATE;
2473 item.iItem = 1;
2474 item.iSubItem = 0;
2475 r = SendMessageA(hwnd, LVM_SETITEMA, 0, (LPARAM)&item);
2476 expect(TRUE, r);
2477
2478 r = SendMessageA(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2479 expect(0, r);
2480
2481 r = SendMessageA(hwnd, LVM_SETSELECTIONMARK, 0, -1);
2482 expect(0, r);
2483
2484 item.stateMask = LVIS_FOCUSED;
2485 item.state = LVIS_FOCUSED;
2486 item.mask = LVIF_STATE;
2487 item.iItem = 1;
2488 item.iSubItem = 0;
2489 r = SendMessageA(hwnd, LVM_SETITEMA, 0, (LPARAM)&item);
2490 expect(TRUE, r);
2491
2492 r = SendMessageA(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2493 expect(-1, r);
2494
2495 /* need to reset focused item first */
2496 item.stateMask = LVIS_FOCUSED;
2497 item.state = 0;
2498 r = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2499 expect(TRUE, r);
2500
2501 item.stateMask = LVIS_FOCUSED;
2502 item.state = LVIS_FOCUSED;
2503 item.mask = LVIF_STATE;
2504 item.iItem = 2;
2505 item.iSubItem = 0;
2506 r = SendMessageA(hwnd, LVM_SETITEMA, 0, (LPARAM)&item);
2507 expect(TRUE, r);
2508
2509 r = SendMessageA(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2510 expect(2, r);
2511
2512 item.stateMask = LVIS_FOCUSED;
2513 item.state = 0;
2514 r = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
2515 expect(TRUE, r);
2516
2517 r = SendMessageA(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2518 expect(2, r);
2519
2520 DestroyWindow(hwnd);
2521 }
2522
2523 static void test_subitem_rect(void)
2524 {
2525 HWND hwnd;
2526 DWORD r;
2527 LVCOLUMNA col;
2528 RECT rect, rect2;
2529 INT arr[3];
2530
2531 /* test LVM_GETSUBITEMRECT for header */
2532 hwnd = create_listview_control(LVS_REPORT);
2533 ok(hwnd != NULL, "failed to create a listview window\n");
2534 /* add some columns */
2535 memset(&col, 0, sizeof(LVCOLUMNA));
2536 col.mask = LVCF_WIDTH;
2537 col.cx = 100;
2538 r = SendMessageA(hwnd, LVM_INSERTCOLUMNA, 0, (LPARAM)&col);
2539 expect(0, r);
2540 col.cx = 150;
2541 r = SendMessageA(hwnd, LVM_INSERTCOLUMNA, 1, (LPARAM)&col);
2542 expect(1, r);
2543 col.cx = 200;
2544 r = SendMessageA(hwnd, LVM_INSERTCOLUMNA, 2, (LPARAM)&col);
2545 expect(2, r);
2546 /* item = -1 means header, subitem index is 1 based */
2547 rect.left = LVIR_BOUNDS;
2548 rect.top = 0;
2549 rect.right = rect.bottom = 0;
2550 r = SendMessageA(hwnd, LVM_GETSUBITEMRECT, -1, (LPARAM)&rect);
2551 expect(0, r);
2552
2553 rect.left = LVIR_BOUNDS;
2554 rect.top = 1;
2555 rect.right = rect.bottom = 0;
2556 r = SendMessageA(hwnd, LVM_GETSUBITEMRECT, -1, (LPARAM)&rect);
2557 expect(1, r);
2558
2559 expect(100, rect.left);
2560 expect(250, rect.right);
2561 expect(3, rect.top);
2562
2563 rect.left = LVIR_BOUNDS;
2564 rect.top = 2;
2565 rect.right = rect.bottom = 0;
2566 r = SendMessageA(hwnd, LVM_GETSUBITEMRECT, -1, (LPARAM)&rect);
2567 expect(1, r);
2568
2569 expect(250, rect.left);
2570 expect(450, rect.right);
2571 expect(3, rect.top);
2572
2573 /* item LVS_REPORT padding isn't applied to subitems */
2574 insert_item(hwnd, 0);
2575
2576 rect.left = LVIR_BOUNDS;
2577 rect.top = 1;
2578 rect.right = rect.bottom = 0;
2579 r = SendMessageA(hwnd, LVM_GETSUBITEMRECT, 0, (LPARAM)&rect);
2580 expect(1, r);
2581 expect(100, rect.left);
2582 expect(250, rect.right);
2583
2584 rect.left = LVIR_ICON;
2585 rect.top = 1;
2586 rect.right = rect.bottom = 0;
2587 r = SendMessageA(hwnd, LVM_GETSUBITEMRECT, 0, (LPARAM)&rect);
2588 expect(1, r);
2589 /* no icon attached - zero width rectangle, with no left padding */
2590 expect(100, rect.left);
2591 expect(100, rect.right);
2592
2593 rect.left = LVIR_LABEL;
2594 rect.top = 1;
2595 rect.right = rect.bottom = 0;
2596 r = SendMessageA(hwnd, LVM_GETSUBITEMRECT, 0, (LPARAM)&rect);
2597 expect(1, r);
2598 /* same as full LVIR_BOUNDS */
2599 expect(100, rect.left);
2600 expect(250, rect.right);
2601
2602 SendMessageA(hwnd, LVM_SCROLL, 10, 0);
2603
2604 rect.left = LVIR_BOUNDS;
2605 rect.top = 1;
2606 rect.right = rect.bottom = 0;
2607 r = SendMessageA(hwnd, LVM_GETSUBITEMRECT, 0, (LPARAM)&rect);
2608 expect(1, r);
2609 expect(90, rect.left);
2610 expect(240, rect.right);
2611
2612 SendMessageA(hwnd, LVM_SCROLL, -10, 0);
2613
2614 /* test header interaction */
2615 subclass_header(hwnd);
2616 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2617
2618 rect.left = LVIR_BOUNDS;
2619 rect.top = 1;
2620 rect.right = rect.bottom = 0;
2621 r = SendMessageA(hwnd, LVM_GETSUBITEMRECT, -1, (LPARAM)&rect);
2622 expect(1, r);
2623
2624 rect.left = LVIR_BOUNDS;
2625 rect.top = 1;
2626 rect.right = rect.bottom = 0;
2627 r = SendMessageA(hwnd, LVM_GETSUBITEMRECT, 0, (LPARAM)&rect);
2628 expect(1, r);
2629
2630 rect.left = LVIR_BOUNDS;
2631 rect.top = 1;
2632 rect.right = rect.bottom = 0;
2633 r = SendMessageA(hwnd, LVM_GETSUBITEMRECT, -10, (LPARAM)&rect);
2634 expect(1, r);
2635
2636 rect.left = LVIR_BOUNDS;
2637 rect.top = 1;
2638 rect.right = rect.bottom = 0;
2639 r = SendMessageA(hwnd, LVM_GETSUBITEMRECT, 20, (LPARAM)&rect);
2640 expect(1, r);
2641
2642 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, getsubitemrect_seq, "LVM_GETSUBITEMRECT negative index", FALSE);
2643
2644 DestroyWindow(hwnd);
2645
2646 /* test subitem rects after re-arranging columns */
2647 hwnd = create_listview_control(LVS_REPORT);
2648 ok(hwnd != NULL, "failed to create a listview window\n");
2649 memset(&col, 0, sizeof(LVCOLUMNA));
2650 col.mask = LVCF_WIDTH;
2651
2652 col.cx = 100;
2653 r = SendMessageA(hwnd, LVM_INSERTCOLUMNA, 0, (LPARAM)&col);
2654 expect(0, r);
2655
2656 col.cx = 200;
2657 r = SendMessageA(hwnd, LVM_INSERTCOLUMNA, 1, (LPARAM)&col);
2658 expect(1, r);
2659
2660 col.cx = 300;
2661 r = SendMessageA(hwnd, LVM_INSERTCOLUMNA, 2, (LPARAM)&col);
2662 expect(2, r);
2663
2664 insert_item(hwnd, 0);
2665 insert_item(hwnd, 1);
2666
2667 /* wrong item is refused for main item */
2668 rect.left = LVIR_BOUNDS;
2669 rect.top = 0;
2670 rect.right = rect.bottom = -1;
2671 r = SendMessageA(hwnd, LVM_GETSUBITEMRECT, 2, (LPARAM)&rect);
2672 expect(FALSE, r);
2673
2674 /* for subitems rectangle is calculated even if there's no item added */
2675 rect.left = LVIR_BOUNDS;
2676 rect.top = 1;
2677 rect.right = rect.bottom = -1;
2678 r = SendMessageA(hwnd, LVM_GETSUBITEMRECT, 1, (LPARAM)&rect);
2679 expect(TRUE, r);
2680
2681 rect2.left = LVIR_BOUNDS;
2682 rect2.top = 1;
2683 rect2.right = rect2.bottom = -1;
2684 r = SendMessageA(hwnd, LVM_GETSUBITEMRECT, 2, (LPARAM)&rect2);
2685 expect(TRUE, r);
2686 expect(rect.right, rect2.right);
2687 expect(rect.left, rect2.left);
2688 expect(rect.bottom, rect2.top);
2689 ok(rect2.bottom > rect2.top, "expected not zero height\n");
2690
2691 arr[0] = 1; arr[1] = 0; arr[2] = 2;
2692 r = SendMessageA(hwnd, LVM_SETCOLUMNORDERARRAY, 3, (LPARAM)arr);
2693 expect(TRUE, r);
2694
2695 rect.left = LVIR_BOUNDS;
2696 rect.top = 0;
2697 rect.right = rect.bottom = -1;
2698 r = SendMessageA(hwnd, LVM_GETSUBITEMRECT, 0, (LPARAM)&rect);
2699 expect(TRUE, r);
2700 expect(0, rect.left);
2701 expect(600, rect.right);
2702
2703 rect.left = LVIR_BOUNDS;
2704 rect.top = 1;
2705 rect.right = rect.bottom = -1;
2706 r = SendMessageA(hwnd, LVM_GETSUBITEMRECT, 0, (LPARAM)&rect);
2707 expect(TRUE, r);
2708 expect(0, rect.left);
2709 expect(200, rect.right);
2710
2711 rect2.left = LVIR_BOUNDS;
2712 rect2.top = 1;
2713 rect2.right = rect2.bottom = -1;
2714 r = SendMessageA(hwnd, LVM_GETSUBITEMRECT, 1, (LPARAM)&rect2);
2715 expect(TRUE, r);
2716 expect(0, rect2.left);
2717 expect(200, rect2.right);
2718 /* items are of the same height */
2719 ok(rect2.top > 0, "expected positive item height\n");
2720 expect(rect.bottom, rect2.top);
2721 expect(rect.bottom * 2 - rect.top, rect2.bottom);
2722
2723 rect.left = LVIR_BOUNDS;
2724 rect.top = 2;
2725 rect.right = rect.bottom = -1;
2726 r = SendMessageA(hwnd, LVM_GETSUBITEMRECT, 0, (LPARAM)&rect);
2727 expect(TRUE, r);
2728 expect(300, rect.left);
2729 expect(600, rect.right);
2730
2731 DestroyWindow(hwnd);
2732
2733 /* try it for non LVS_REPORT style */
2734 hwnd = CreateWindowA("SysListView32", "Test", LVS_ICON, 0, 0, 100, 100, NULL, NULL,
2735 GetModuleHandleA(NULL), 0);
2736 rect.left = LVIR_BOUNDS;
2737 rect.top = 1;
2738 rect.right = rect.bottom = -10;
2739 r = SendMessageA(hwnd, LVM_GETSUBITEMRECT, -1, (LPARAM)&rect);
2740 expect(0, r);
2741 /* rect is unchanged */
2742 expect(0, rect.left);
2743 expect(-10, rect.right);
2744 expect(1, rect.top);
2745 expect(-10, rect.bottom);
2746 DestroyWindow(hwnd);
2747 }
2748
2749 /* comparison callback for test_sorting */
2750 static INT WINAPI test_CallBackCompare(LPARAM first, LPARAM second, LPARAM lParam)
2751 {
2752 if (first == second) return 0;
2753 return (first > second ? 1 : -1);
2754 }
2755
2756 static void test_sorting(void)
2757 {
2758 HWND hwnd;
2759 LVITEMA item = {0};
2760 INT r;
2761 LONG_PTR style;
2762 static CHAR names[][5] = {"A", "B", "C", "D", "0"};
2763 CHAR buff[10];
2764
2765 hwnd = create_listview_control(LVS_REPORT);
2766 ok(hwnd != NULL, "failed to create a listview window\n");
2767
2768 /* insert some items */
2769 item.mask = LVIF_PARAM | LVIF_STATE;
2770 item.state = LVIS_SELECTED;
2771 item.iItem = 0;
2772 item.iSubItem = 0;
2773 item.lParam = 3;
2774 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
2775 expect(0, r);
2776
2777 item.mask = LVIF_PARAM;
2778 item.iItem = 1;
2779 item.iSubItem = 0;
2780 item.lParam = 2;
2781 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
2782 expect(1, r);
2783
2784 item.mask = LVIF_STATE | LVIF_PARAM;
2785 item.state = LVIS_SELECTED;
2786 item.iItem = 2;
2787 item.iSubItem = 0;
2788 item.lParam = 4;
2789 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
2790 expect(2, r