[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);
2791
2792 r = SendMessageA(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2793 expect(-1, r);
2794
2795 r = SendMessageA(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2796 expect(2, r);
2797
2798 r = SendMessageA(hwnd, LVM_SORTITEMS, 0, (LPARAM)test_CallBackCompare);
2799 expect(TRUE, r);
2800
2801 r = SendMessageA(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
2802 expect(2, r);
2803 r = SendMessageA(hwnd, LVM_GETSELECTIONMARK, 0, 0);
2804 expect(-1, r);
2805 r = SendMessageA(hwnd, LVM_GETITEMSTATE, 0, LVIS_SELECTED);
2806 expect(0, r);
2807 r = SendMessageA(hwnd, LVM_GETITEMSTATE, 1, LVIS_SELECTED);
2808 expect(LVIS_SELECTED, r);
2809 r = SendMessageA(hwnd, LVM_GETITEMSTATE, 2, LVIS_SELECTED);
2810 expect(LVIS_SELECTED, r);
2811
2812 DestroyWindow(hwnd);
2813
2814 /* switch to LVS_SORTASCENDING when some items added */
2815 hwnd = create_listview_control(LVS_REPORT);
2816 ok(hwnd != NULL, "failed to create a listview window\n");
2817
2818 item.mask = LVIF_TEXT;
2819 item.iItem = 0;
2820 item.iSubItem = 0;
2821 item.pszText = names[1];
2822 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
2823 expect(0, r);
2824
2825 item.mask = LVIF_TEXT;
2826 item.iItem = 1;
2827 item.iSubItem = 0;
2828 item.pszText = names[2];
2829 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
2830 expect(1, r);
2831
2832 item.mask = LVIF_TEXT;
2833 item.iItem = 2;
2834 item.iSubItem = 0;
2835 item.pszText = names[0];
2836 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
2837 expect(2, r);
2838
2839 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2840 SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_SORTASCENDING);
2841 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2842 ok(style & LVS_SORTASCENDING, "Expected LVS_SORTASCENDING to be set\n");
2843
2844 /* no sorting performed when switched to LVS_SORTASCENDING */
2845 item.mask = LVIF_TEXT;
2846 item.iItem = 0;
2847 item.pszText = buff;
2848 item.cchTextMax = sizeof(buff);
2849 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
2850 expect(TRUE, r);
2851 ok(lstrcmpA(buff, names[1]) == 0, "Expected '%s', got '%s'\n", names[1], buff);
2852
2853 item.iItem = 1;
2854 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
2855 expect(TRUE, r);
2856 ok(lstrcmpA(buff, names[2]) == 0, "Expected '%s', got '%s'\n", names[2], buff);
2857
2858 item.iItem = 2;
2859 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
2860 expect(TRUE, r);
2861 ok(lstrcmpA(buff, names[0]) == 0, "Expected '%s', got '%s'\n", names[0], buff);
2862
2863 /* adding new item doesn't resort list */
2864 item.mask = LVIF_TEXT;
2865 item.iItem = 3;
2866 item.iSubItem = 0;
2867 item.pszText = names[3];
2868 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
2869 expect(3, r);
2870
2871 item.mask = LVIF_TEXT;
2872 item.iItem = 0;
2873 item.pszText = buff;
2874 item.cchTextMax = sizeof(buff);
2875 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
2876 expect(TRUE, r);
2877 ok(lstrcmpA(buff, names[1]) == 0, "Expected '%s', got '%s'\n", names[1], buff);
2878
2879 item.iItem = 1;
2880 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
2881 expect(TRUE, r);
2882 ok(lstrcmpA(buff, names[2]) == 0, "Expected '%s', got '%s'\n", names[2], buff);
2883
2884 item.iItem = 2;
2885 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
2886 expect(TRUE, r);
2887 ok(lstrcmpA(buff, names[0]) == 0, "Expected '%s', got '%s'\n", names[0], buff);
2888
2889 item.iItem = 3;
2890 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
2891 expect(TRUE, r);
2892 ok(lstrcmpA(buff, names[3]) == 0, "Expected '%s', got '%s'\n", names[3], buff);
2893
2894 /* corner case - item should be placed at first position */
2895 item.mask = LVIF_TEXT;
2896 item.iItem = 4;
2897 item.iSubItem = 0;
2898 item.pszText = names[4];
2899 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM) &item);
2900 expect(0, r);
2901
2902 item.iItem = 0;
2903 item.pszText = buff;
2904 item.cchTextMax = sizeof(buff);
2905 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
2906 expect(TRUE, r);
2907 ok(lstrcmpA(buff, names[4]) == 0, "Expected '%s', got '%s'\n", names[4], buff);
2908
2909 item.iItem = 1;
2910 item.pszText = buff;
2911 item.cchTextMax = sizeof(buff);
2912 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
2913 expect(TRUE, r);
2914 ok(lstrcmpA(buff, names[1]) == 0, "Expected '%s', got '%s'\n", names[1], buff);
2915
2916 item.iItem = 2;
2917 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
2918 expect(TRUE, r);
2919 ok(lstrcmpA(buff, names[2]) == 0, "Expected '%s', got '%s'\n", names[2], buff);
2920
2921 item.iItem = 3;
2922 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
2923 expect(TRUE, r);
2924 ok(lstrcmpA(buff, names[0]) == 0, "Expected '%s', got '%s'\n", names[0], buff);
2925
2926 item.iItem = 4;
2927 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM) &item);
2928 expect(TRUE, r);
2929 ok(lstrcmpA(buff, names[3]) == 0, "Expected '%s', got '%s'\n", names[3], buff);
2930
2931 DestroyWindow(hwnd);
2932 }
2933
2934 static void test_ownerdata(void)
2935 {
2936 static char test_str[] = "test";
2937
2938 HWND hwnd;
2939 LONG_PTR style, ret;
2940 DWORD res;
2941 LVITEMA item;
2942
2943 /* it isn't possible to set LVS_OWNERDATA after creation */
2944 if (g_is_below_5)
2945 {
2946 win_skip("set LVS_OWNERDATA after creation leads to crash on < 5.80\n");
2947 }
2948 else
2949 {
2950 hwnd = create_listview_control(LVS_REPORT);
2951 ok(hwnd != NULL, "failed to create a listview window\n");
2952 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2953 ok(!(style & LVS_OWNERDATA) && style, "LVS_OWNERDATA isn't expected\n");
2954
2955 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2956
2957 ret = SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_OWNERDATA);
2958 ok(ret == style, "Expected set GWL_STYLE to succeed\n");
2959 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_ownerdata_switchto_seq,
2960 "try to switch to LVS_OWNERDATA seq", FALSE);
2961
2962 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2963 ok(!(style & LVS_OWNERDATA), "LVS_OWNERDATA isn't expected\n");
2964 DestroyWindow(hwnd);
2965 }
2966
2967 /* try to set LVS_OWNERDATA after creation just having it */
2968 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
2969 ok(hwnd != NULL, "failed to create a listview window\n");
2970 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2971 ok(style & LVS_OWNERDATA, "LVS_OWNERDATA is expected\n");
2972
2973 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2974
2975 ret = SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_OWNERDATA);
2976 ok(ret == style, "Expected set GWL_STYLE to succeed\n");
2977 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_ownerdata_switchto_seq,
2978 "try to switch to LVS_OWNERDATA seq", FALSE);
2979 DestroyWindow(hwnd);
2980
2981 /* try to remove LVS_OWNERDATA after creation just having it */
2982 if (g_is_below_5)
2983 {
2984 win_skip("remove LVS_OWNERDATA after creation leads to crash on < 5.80\n");
2985 }
2986 else
2987 {
2988 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
2989 ok(hwnd != NULL, "failed to create a listview window\n");
2990 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
2991 ok(style & LVS_OWNERDATA, "LVS_OWNERDATA is expected\n");
2992
2993 flush_sequences(sequences, NUM_MSG_SEQUENCES);
2994
2995 ret = SetWindowLongPtrA(hwnd, GWL_STYLE, style & ~LVS_OWNERDATA);
2996 ok(ret == style, "Expected set GWL_STYLE to succeed\n");
2997 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_ownerdata_switchto_seq,
2998 "try to switch to LVS_OWNERDATA seq", FALSE);
2999 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
3000 ok(style & LVS_OWNERDATA, "LVS_OWNERDATA is expected\n");
3001 DestroyWindow(hwnd);
3002 }
3003
3004 /* try select an item */
3005 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
3006 ok(hwnd != NULL, "failed to create a listview window\n");
3007 res = SendMessageA(hwnd, LVM_SETITEMCOUNT, 1, 0);
3008 expect(1, res);
3009 res = SendMessageA(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
3010 expect(0, res);
3011 memset(&item, 0, sizeof(item));
3012 item.stateMask = LVIS_SELECTED;
3013 item.state = LVIS_SELECTED;
3014 res = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
3015 expect(TRUE, res);
3016 res = SendMessageA(hwnd, LVM_GETSELECTEDCOUNT, 0, 0);
3017 expect(1, res);
3018 res = SendMessageA(hwnd, LVM_GETITEMCOUNT, 0, 0);
3019 expect(1, res);
3020 DestroyWindow(hwnd);
3021
3022 /* LVM_SETITEM and LVM_SETITEMTEXT is unsupported on LVS_OWNERDATA */
3023 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
3024 ok(hwnd != NULL, "failed to create a listview window\n");
3025 res = SendMessageA(hwnd, LVM_SETITEMCOUNT, 1, 0);
3026 expect(1, res);
3027 res = SendMessageA(hwnd, LVM_GETITEMCOUNT, 0, 0);
3028 expect(1, res);
3029 memset(&item, 0, sizeof(item));
3030 item.mask = LVIF_STATE;
3031 item.iItem = 0;
3032 item.stateMask = LVIS_SELECTED;
3033 item.state = LVIS_SELECTED;
3034 res = SendMessageA(hwnd, LVM_SETITEMA, 0, (LPARAM)&item);
3035 expect(FALSE, res);
3036 memset(&item, 0, sizeof(item));
3037 item.pszText = test_str;
3038 res = SendMessageA(hwnd, LVM_SETITEMTEXTA, 0, (LPARAM)&item);
3039 expect(FALSE, res);
3040 DestroyWindow(hwnd);
3041
3042 /* check notifications after focused/selected changed */
3043 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
3044 ok(hwnd != NULL, "failed to create a listview window\n");
3045 res = SendMessageA(hwnd, LVM_SETITEMCOUNT, 20, 0);
3046 expect(1, res);
3047
3048 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3049
3050 memset(&item, 0, sizeof(item));
3051 item.stateMask = LVIS_SELECTED;
3052 item.state = LVIS_SELECTED;
3053 res = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
3054 expect(TRUE, res);
3055
3056 ok_sequence(sequences, PARENT_SEQ_INDEX, ownderdata_select_focus_parent_seq,
3057 "ownerdata select notification", TRUE);
3058
3059 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3060
3061 memset(&item, 0, sizeof(item));
3062 item.stateMask = LVIS_FOCUSED;
3063 item.state = LVIS_FOCUSED;
3064 res = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
3065 expect(TRUE, res);
3066
3067 ok_sequence(sequences, PARENT_SEQ_INDEX, ownderdata_select_focus_parent_seq,
3068 "ownerdata focus notification", TRUE);
3069
3070 /* select all, check notifications */
3071 item.stateMask = LVIS_SELECTED;
3072 item.state = 0;
3073 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
3074 expect(TRUE, res);
3075
3076 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3077
3078 item.stateMask = LVIS_SELECTED;
3079 item.state = LVIS_SELECTED;
3080
3081 memset(&g_nmlistview, 0xcc, sizeof(g_nmlistview));
3082 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
3083 expect(TRUE, res);
3084 ok(g_nmlistview.iItem == -1, "got item %d\n", g_nmlistview.iItem);
3085 ok(g_nmlistview.iSubItem == 0, "got subitem %d\n", g_nmlistview.iSubItem);
3086 ok(g_nmlistview.uNewState == LVIS_SELECTED, "got new state 0x%08x\n", g_nmlistview.uNewState);
3087 ok(g_nmlistview.uOldState == 0, "got old state 0x%08x\n", g_nmlistview.uOldState);
3088 ok(g_nmlistview.uChanged == LVIF_STATE, "got changed 0x%08x\n", g_nmlistview.uChanged);
3089 ok(g_nmlistview.ptAction.x == 0 && g_nmlistview.ptAction.y == 0, "got wrong ptAction value\n");
3090 ok(g_nmlistview.lParam == 0, "got wrong lparam\n");
3091
3092 ok_sequence(sequences, PARENT_SEQ_INDEX, ownerdata_setstate_all_parent_seq,
3093 "ownerdata select all notification", FALSE);
3094
3095 /* select all again, note that all items are selected already */
3096 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3097 item.stateMask = LVIS_SELECTED;
3098 item.state = LVIS_SELECTED;
3099
3100 memset(&g_nmlistview, 0xcc, sizeof(g_nmlistview));
3101 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
3102 expect(TRUE, res);
3103 ok(g_nmlistview.iItem == -1, "got item %d\n", g_nmlistview.iItem);
3104 ok(g_nmlistview.iSubItem == 0, "got subitem %d\n", g_nmlistview.iSubItem);
3105 ok(g_nmlistview.uNewState == LVIS_SELECTED, "got new state 0x%08x\n", g_nmlistview.uNewState);
3106 ok(g_nmlistview.uOldState == 0, "got old state 0x%08x\n", g_nmlistview.uOldState);
3107 ok(g_nmlistview.uChanged == LVIF_STATE, "got changed 0x%08x\n", g_nmlistview.uChanged);
3108 ok(g_nmlistview.ptAction.x == 0 && g_nmlistview.ptAction.y == 0, "got wrong ptAction value\n");
3109 ok(g_nmlistview.lParam == 0, "got wrong lparam\n");
3110
3111 ok_sequence(sequences, PARENT_SEQ_INDEX, ownerdata_setstate_all_parent_seq,
3112 "ownerdata select all notification", FALSE);
3113
3114 /* deselect all */
3115 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3116 item.stateMask = LVIS_SELECTED;
3117 item.state = 0;
3118
3119 memset(&g_nmlistview, 0xcc, sizeof(g_nmlistview));
3120 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
3121 expect(TRUE, res);
3122 ok(g_nmlistview.iItem == -1, "got item %d\n", g_nmlistview.iItem);
3123 ok(g_nmlistview.iSubItem == 0, "got subitem %d\n", g_nmlistview.iSubItem);
3124 ok(g_nmlistview.uNewState == 0, "got new state 0x%08x\n", g_nmlistview.uNewState);
3125 ok(g_nmlistview.uOldState == LVIS_SELECTED, "got old state 0x%08x\n", g_nmlistview.uOldState);
3126 ok(g_nmlistview.uChanged == LVIF_STATE, "got changed 0x%08x\n", g_nmlistview.uChanged);
3127 ok(g_nmlistview.ptAction.x == 0 && g_nmlistview.ptAction.y == 0, "got wrong ptAction value\n");
3128 ok(g_nmlistview.lParam == 0, "got wrong lparam\n");
3129
3130 ok_sequence(sequences, PARENT_SEQ_INDEX, ownerdata_deselect_all_parent_seq,
3131 "ownerdata deselect all notification", TRUE);
3132
3133 /* nothing selected, deselect all again */
3134 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3135 item.stateMask = LVIS_SELECTED;
3136 item.state = 0;
3137
3138 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
3139 expect(TRUE, res);
3140
3141 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq, "ownerdata deselect all notification", FALSE);
3142
3143 /* select one, then deselect all */
3144 item.stateMask = LVIS_SELECTED;
3145 item.state = LVIS_SELECTED;
3146 res = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
3147 expect(TRUE, res);
3148 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3149 item.stateMask = LVIS_SELECTED;
3150 item.state = 0;
3151
3152 memset(&g_nmlistview, 0xcc, sizeof(g_nmlistview));
3153 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
3154 expect(TRUE, res);
3155 ok(g_nmlistview.iItem == -1, "got item %d\n", g_nmlistview.iItem);
3156 ok(g_nmlistview.iSubItem == 0, "got subitem %d\n", g_nmlistview.iSubItem);
3157 ok(g_nmlistview.uNewState == 0, "got new state 0x%08x\n", g_nmlistview.uNewState);
3158 ok(g_nmlistview.uOldState == LVIS_SELECTED, "got old state 0x%08x\n", g_nmlistview.uOldState);
3159 ok(g_nmlistview.uChanged == LVIF_STATE, "got changed 0x%08x\n", g_nmlistview.uChanged);
3160 ok(g_nmlistview.ptAction.x == 0 && g_nmlistview.ptAction.y == 0, "got wrong ptAction value\n");
3161 ok(g_nmlistview.lParam == 0, "got wrong lparam\n");
3162
3163 ok_sequence(sequences, PARENT_SEQ_INDEX, ownerdata_deselect_all_parent_seq,
3164 "ownerdata select all notification", TRUE);
3165
3166 /* remove focused, try to focus all */
3167 item.stateMask = LVIS_FOCUSED;
3168 item.state = LVIS_FOCUSED;
3169 res = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
3170 expect(TRUE, res);
3171 item.stateMask = LVIS_FOCUSED;
3172 item.state = 0;
3173 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
3174 expect(TRUE, res);
3175 item.stateMask = LVIS_FOCUSED;
3176 res = SendMessageA(hwnd, LVM_GETITEMSTATE, 0, LVIS_FOCUSED);
3177 expect(0, res);
3178
3179 /* setting all to focused returns failure value */
3180 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3181 item.stateMask = LVIS_FOCUSED;
3182 item.state = LVIS_FOCUSED;
3183
3184 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
3185 expect(FALSE, res);
3186
3187 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
3188 "ownerdata focus all notification", FALSE);
3189
3190 /* focus single item, remove all */
3191 item.stateMask = LVIS_FOCUSED;
3192 item.state = LVIS_FOCUSED;
3193 res = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
3194 expect(TRUE, res);
3195 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3196 item.stateMask = LVIS_FOCUSED;
3197 item.state = 0;
3198
3199 memset(&g_nmlistview, 0xcc, sizeof(g_nmlistview));
3200 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
3201 expect(TRUE, res);
3202 ok(g_nmlistview.iItem == -1, "got item %d\n", g_nmlistview.iItem);
3203 ok(g_nmlistview.iSubItem == 0, "got subitem %d\n", g_nmlistview.iSubItem);
3204 ok(g_nmlistview.uNewState == 0, "got new state 0x%08x\n", g_nmlistview.uNewState);
3205 ok(g_nmlistview.uOldState == LVIS_FOCUSED, "got old state 0x%08x\n", g_nmlistview.uOldState);
3206 ok(g_nmlistview.uChanged == LVIF_STATE, "got changed 0x%08x\n", g_nmlistview.uChanged);
3207 ok(g_nmlistview.ptAction.x == 0 && g_nmlistview.ptAction.y == 0, "got wrong ptAction value\n");
3208 ok(g_nmlistview.lParam == 0, "got wrong lparam\n");
3209
3210 ok_sequence(sequences, PARENT_SEQ_INDEX, ownerdata_defocus_all_parent_seq,
3211 "ownerdata remove focus all notification", TRUE);
3212
3213 /* set all cut */
3214 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3215 item.stateMask = LVIS_CUT;
3216 item.state = LVIS_CUT;
3217
3218 memset(&g_nmlistview, 0xcc, sizeof(g_nmlistview));
3219 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
3220 expect(TRUE, res);
3221 ok(g_nmlistview.iItem == -1, "got item %d\n", g_nmlistview.iItem);
3222 ok(g_nmlistview.iSubItem == 0, "got subitem %d\n", g_nmlistview.iSubItem);
3223 ok(g_nmlistview.uNewState == LVIS_CUT, "got new state 0x%08x\n", g_nmlistview.uNewState);
3224 ok(g_nmlistview.uOldState == 0, "got old state 0x%08x\n", g_nmlistview.uOldState);
3225 ok(g_nmlistview.uChanged == LVIF_STATE, "got changed 0x%08x\n", g_nmlistview.uChanged);
3226 ok(g_nmlistview.ptAction.x == 0 && g_nmlistview.ptAction.y == 0, "got wrong ptAction value\n");
3227 ok(g_nmlistview.lParam == 0, "got wrong lparam\n");
3228
3229 ok_sequence(sequences, PARENT_SEQ_INDEX, ownerdata_setstate_all_parent_seq,
3230 "ownerdata cut all notification", FALSE);
3231
3232 /* all marked cut, try again */
3233 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3234 item.stateMask = LVIS_CUT;
3235 item.state = LVIS_CUT;
3236
3237 memset(&g_nmlistview, 0xcc, sizeof(g_nmlistview));
3238 res = SendMessageA(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
3239 expect(TRUE, res);
3240 ok(g_nmlistview.iItem == -1, "got item %d\n", g_nmlistview.iItem);
3241 ok(g_nmlistview.iSubItem == 0, "got subitem %d\n", g_nmlistview.iSubItem);
3242 ok(g_nmlistview.uNewState == LVIS_CUT, "got new state 0x%08x\n", g_nmlistview.uNewState);
3243 ok(g_nmlistview.uOldState == 0, "got old state 0x%08x\n", g_nmlistview.uOldState);
3244 ok(g_nmlistview.uChanged == LVIF_STATE, "got changed 0x%08x\n", g_nmlistview.uChanged);
3245 ok(g_nmlistview.ptAction.x == 0 && g_nmlistview.ptAction.y == 0, "got wrong ptAction value\n");
3246 ok(g_nmlistview.lParam == 0, "got wrong lparam\n");
3247
3248 ok_sequence(sequences, PARENT_SEQ_INDEX, ownerdata_setstate_all_parent_seq,
3249 "ownerdata cut all notification #2", FALSE);
3250
3251 DestroyWindow(hwnd);
3252
3253 /* check notifications on LVM_GETITEM */
3254 /* zero callback mask */
3255 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
3256 ok(hwnd != NULL, "failed to create a listview window\n");
3257 res = SendMessageA(hwnd, LVM_SETITEMCOUNT, 1, 0);
3258 expect(1, res);
3259
3260 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3261
3262 memset(&item, 0, sizeof(item));
3263 item.stateMask = LVIS_SELECTED;
3264 item.mask = LVIF_STATE;
3265 res = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM)&item);
3266 expect(TRUE, res);
3267
3268 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
3269 "ownerdata getitem selected state 1", FALSE);
3270
3271 /* non zero callback mask but not we asking for */
3272 res = SendMessageA(hwnd, LVM_SETCALLBACKMASK, LVIS_OVERLAYMASK, 0);
3273 expect(TRUE, res);
3274
3275 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3276
3277 memset(&item, 0, sizeof(item));
3278 item.stateMask = LVIS_SELECTED;
3279 item.mask = LVIF_STATE;
3280 res = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM)&item);
3281 expect(TRUE, res);
3282
3283 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
3284 "ownerdata getitem selected state 2", FALSE);
3285
3286 /* LVIS_OVERLAYMASK callback mask, asking for index */
3287 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3288
3289 memset(&item, 0, sizeof(item));
3290 item.stateMask = LVIS_OVERLAYMASK;
3291 item.mask = LVIF_STATE;
3292 res = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM)&item);
3293 expect(TRUE, res);
3294
3295 ok_sequence(sequences, PARENT_SEQ_INDEX, single_getdispinfo_parent_seq,
3296 "ownerdata getitem selected state 2", FALSE);
3297
3298 DestroyWindow(hwnd);
3299
3300 /* LVS_SORTASCENDING/LVS_SORTDESCENDING aren't compatible with LVS_OWNERDATA */
3301 hwnd = create_listview_control(LVS_OWNERDATA | LVS_SORTASCENDING | LVS_REPORT);
3302 ok(hwnd != NULL, "failed to create a listview window\n");
3303 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
3304 ok(style & LVS_OWNERDATA, "Expected LVS_OWNERDATA\n");
3305 ok(style & LVS_SORTASCENDING, "Expected LVS_SORTASCENDING to be set\n");
3306 SetWindowLongPtrA(hwnd, GWL_STYLE, style & ~LVS_SORTASCENDING);
3307 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
3308 ok(!(style & LVS_SORTASCENDING), "Expected LVS_SORTASCENDING not set\n");
3309 DestroyWindow(hwnd);
3310 /* apparently it's allowed to switch these style on after creation */
3311 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
3312 ok(hwnd != NULL, "failed to create a listview window\n");
3313 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
3314 ok(style & LVS_OWNERDATA, "Expected LVS_OWNERDATA\n");
3315 SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_SORTASCENDING);
3316 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
3317 ok(style & LVS_SORTASCENDING, "Expected LVS_SORTASCENDING to be set\n");
3318 DestroyWindow(hwnd);
3319
3320 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
3321 ok(hwnd != NULL, "failed to create a listview window\n");
3322 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
3323 ok(style & LVS_OWNERDATA, "Expected LVS_OWNERDATA\n");
3324 SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_SORTDESCENDING);
3325 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
3326 ok(style & LVS_SORTDESCENDING, "Expected LVS_SORTDESCENDING to be set\n");
3327 DestroyWindow(hwnd);
3328 }
3329
3330 static void test_norecompute(void)
3331 {
3332 static CHAR testA[] = "test";
3333 CHAR buff[10];
3334 LVITEMA item;
3335 HWND hwnd;
3336 DWORD res;
3337
3338 /* self containing control */
3339 hwnd = create_listview_control(LVS_REPORT);
3340 ok(hwnd != NULL, "failed to create a listview window\n");
3341 memset(&item, 0, sizeof(item));
3342 item.mask = LVIF_TEXT | LVIF_STATE;
3343 item.iItem = 0;
3344 item.stateMask = LVIS_SELECTED;
3345 item.state = LVIS_SELECTED;
3346 item.pszText = testA;
3347 res = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
3348 expect(0, res);
3349 /* retrieve with LVIF_NORECOMPUTE */
3350 item.mask = LVIF_TEXT | LVIF_NORECOMPUTE;
3351 item.iItem = 0;
3352 item.pszText = buff;
3353 item.cchTextMax = sizeof(buff)/sizeof(CHAR);
3354 res = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM)&item);
3355 expect(TRUE, res);
3356 ok(lstrcmpA(buff, testA) == 0, "Expected (%s), got (%s)\n", testA, buff);
3357
3358 item.mask = LVIF_TEXT;
3359 item.iItem = 1;
3360 item.pszText = LPSTR_TEXTCALLBACKA;
3361 res = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
3362 expect(1, res);
3363
3364 item.mask = LVIF_TEXT | LVIF_NORECOMPUTE;
3365 item.iItem = 1;
3366 item.pszText = buff;
3367 item.cchTextMax = sizeof(buff)/sizeof(CHAR);
3368
3369 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3370 res = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM)&item);
3371 expect(TRUE, res);
3372 ok(item.pszText == LPSTR_TEXTCALLBACKA, "Expected (%p), got (%p)\n",
3373 LPSTR_TEXTCALLBACKA, (VOID*)item.pszText);
3374 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq, "retrieve with LVIF_NORECOMPUTE seq", FALSE);
3375
3376 DestroyWindow(hwnd);
3377
3378 /* LVS_OWNERDATA */
3379 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
3380 ok(hwnd != NULL, "failed to create a listview window\n");
3381
3382 item.mask = LVIF_STATE;
3383 item.stateMask = LVIS_SELECTED;
3384 item.state = LVIS_SELECTED;
3385 item.iItem = 0;
3386 res = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
3387 expect(0, res);
3388
3389 item.mask = LVIF_TEXT | LVIF_NORECOMPUTE;
3390 item.iItem = 0;
3391 item.pszText = buff;
3392 item.cchTextMax = sizeof(buff)/sizeof(CHAR);
3393 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3394 res = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM)&item);
3395 expect(TRUE, res);
3396 ok(item.pszText == LPSTR_TEXTCALLBACKA, "Expected (%p), got (%p)\n",
3397 LPSTR_TEXTCALLBACKA, (VOID*)item.pszText);
3398 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq, "retrieve with LVIF_NORECOMPUTE seq 2", FALSE);
3399
3400 DestroyWindow(hwnd);
3401 }
3402
3403 static void test_nosortheader(void)
3404 {
3405 HWND hwnd, header;
3406 LONG_PTR style;
3407
3408 hwnd = create_listview_control(LVS_REPORT);
3409 ok(hwnd != NULL, "failed to create a listview window\n");
3410
3411 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
3412 ok(IsWindow(header), "header expected\n");
3413
3414 style = GetWindowLongPtrA(header, GWL_STYLE);
3415 ok(style & HDS_BUTTONS, "expected header to have HDS_BUTTONS\n");
3416
3417 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
3418 SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_NOSORTHEADER);
3419 /* HDS_BUTTONS retained */
3420 style = GetWindowLongPtrA(header, GWL_STYLE);
3421 ok(style & HDS_BUTTONS, "expected header to retain HDS_BUTTONS\n");
3422
3423 DestroyWindow(hwnd);
3424
3425 /* create with LVS_NOSORTHEADER */
3426 hwnd = create_listview_control(LVS_NOSORTHEADER | LVS_REPORT);
3427 ok(hwnd != NULL, "failed to create a listview window\n");
3428
3429 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
3430 ok(IsWindow(header), "header expected\n");
3431
3432 style = GetWindowLongPtrA(header, GWL_STYLE);
3433 ok(!(style & HDS_BUTTONS), "expected header to have no HDS_BUTTONS\n");
3434
3435 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
3436 SetWindowLongPtrA(hwnd, GWL_STYLE, style & ~LVS_NOSORTHEADER);
3437 /* not changed here */
3438 style = GetWindowLongPtrA(header, GWL_STYLE);
3439 ok(!(style & HDS_BUTTONS), "expected header to have no HDS_BUTTONS\n");
3440
3441 DestroyWindow(hwnd);
3442 }
3443
3444 static void test_setredraw(void)
3445 {
3446 HWND hwnd;
3447 DWORD_PTR style;
3448 DWORD ret;
3449 HDC hdc;
3450 RECT rect;
3451
3452 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
3453 ok(hwnd != NULL, "failed to create a listview window\n");
3454
3455 /* Passing WM_SETREDRAW to DefWinProc removes WS_VISIBLE.
3456 ListView seems to handle it internally without DefWinProc */
3457
3458 /* default value first */
3459 ret = SendMessageA(hwnd, WM_SETREDRAW, TRUE, 0);
3460 expect(0, ret);
3461 /* disable */
3462 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
3463 ok(style & WS_VISIBLE, "Expected WS_VISIBLE to be set\n");
3464 ret = SendMessageA(hwnd, WM_SETREDRAW, FALSE, 0);
3465 expect(0, ret);
3466 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
3467 ok(style & WS_VISIBLE, "Expected WS_VISIBLE to be set\n");
3468 ret = SendMessageA(hwnd, WM_SETREDRAW, TRUE, 0);
3469 expect(0, ret);
3470
3471 /* check update rect after redrawing */
3472 ret = SendMessageA(hwnd, WM_SETREDRAW, FALSE, 0);
3473 expect(0, ret);
3474 InvalidateRect(hwnd, NULL, FALSE);
3475 RedrawWindow(hwnd, NULL, NULL, RDW_UPDATENOW);
3476 rect.right = rect.bottom = 1;
3477 GetUpdateRect(hwnd, &rect, FALSE);
3478 expect(0, rect.right);
3479 expect(0, rect.bottom);
3480
3481 /* WM_ERASEBKGND */
3482 hdc = GetWindowDC(hwndparent);
3483 ret = SendMessageA(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
3484 expect(TRUE, ret);
3485 ret = SendMessageA(hwnd, WM_SETREDRAW, FALSE, 0);
3486 expect(0, ret);
3487 ret = SendMessageA(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
3488 expect(TRUE, ret);
3489 ret = SendMessageA(hwnd, WM_SETREDRAW, TRUE, 0);
3490 expect(0, ret);
3491 ReleaseDC(hwndparent, hdc);
3492
3493 /* check notification messages to show that repainting is disabled */
3494 ret = SendMessageA(hwnd, LVM_SETITEMCOUNT, 1, 0);
3495 expect(TRUE, ret);
3496 ret = SendMessageA(hwnd, WM_SETREDRAW, FALSE, 0);
3497 expect(0, ret);
3498 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3499
3500 InvalidateRect(hwnd, NULL, TRUE);
3501 UpdateWindow(hwnd);
3502 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
3503 "redraw after WM_SETREDRAW (FALSE)", FALSE);
3504
3505 ret = SendMessageA(hwnd, LVM_SETBKCOLOR, 0, CLR_NONE);
3506 expect(TRUE, ret);
3507 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3508 InvalidateRect(hwnd, NULL, TRUE);
3509 UpdateWindow(hwnd);
3510 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
3511 "redraw after WM_SETREDRAW (FALSE) with CLR_NONE bkgnd", FALSE);
3512
3513 /* message isn't forwarded to header */
3514 subclass_header(hwnd);
3515 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3516 ret = SendMessageA(hwnd, WM_SETREDRAW, FALSE, 0);
3517 expect(0, ret);
3518 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, setredraw_seq,
3519 "WM_SETREDRAW: not forwarded to header", FALSE);
3520
3521 DestroyWindow(hwnd);
3522 }
3523
3524 static void test_hittest(void)
3525 {
3526 HWND hwnd;
3527 DWORD r;
3528 RECT bounds;
3529 LVITEMA item;
3530 static CHAR text[] = "1234567890ABCDEFGHIJKLMNOPQRST";
3531 POINT pos;
3532 INT x, y, i;
3533 WORD vert;
3534 HIMAGELIST himl, himl2;
3535 HBITMAP hbmp;
3536
3537 hwnd = create_listview_control(LVS_REPORT);
3538 ok(hwnd != NULL, "failed to create a listview window\n");
3539
3540 /* LVS_REPORT with a single subitem (2 columns) */
3541 insert_column(hwnd, 0);
3542 insert_column(hwnd, 1);
3543 insert_item(hwnd, 0);
3544
3545 item.iSubItem = 0;
3546 /* the only purpose of that line is to be as long as a half item rect */
3547 item.pszText = text;
3548 r = SendMessageA(hwnd, LVM_SETITEMTEXTA, 0, (LPARAM)&item);
3549 expect(TRUE, r);
3550
3551 r = SendMessageA(hwnd, LVM_SETCOLUMNWIDTH, 0, MAKELPARAM(100, 0));
3552 expect(TRUE, r);
3553 r = SendMessageA(hwnd, LVM_SETCOLUMNWIDTH, 1, MAKELPARAM(100, 0));
3554 expect(TRUE, r);
3555
3556 memset(&bounds, 0, sizeof(bounds));
3557 bounds.left = LVIR_BOUNDS;
3558 r = SendMessageA(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&bounds);
3559 expect(1, r);
3560 ok(bounds.bottom - bounds.top > 0, "Expected non zero item height\n");
3561 ok(bounds.right - bounds.left > 0, "Expected non zero item width\n");
3562 r = SendMessageA(hwnd, LVM_GETITEMSPACING, TRUE, 0);
3563 vert = HIWORD(r);
3564 ok(bounds.bottom - bounds.top == vert,
3565 "Vertical spacing inconsistent (%d != %d)\n", bounds.bottom - bounds.top, vert);
3566 r = SendMessageA(hwnd, LVM_GETITEMPOSITION, 0, (LPARAM)&pos);
3567 expect(TRUE, r);
3568
3569 /* LVS_EX_FULLROWSELECT not set, no icons attached */
3570
3571 /* outside columns by x position - valid is [0, 199] */
3572 x = -1;
3573 y = pos.y + (bounds.bottom - bounds.top) / 2;
3574 test_lvm_hittest(hwnd, x, y, -1, LVHT_TOLEFT, 0, FALSE, FALSE);
3575 test_lvm_subitemhittest(hwnd, x, y, -1, -1, LVHT_NOWHERE, FALSE, FALSE, FALSE);
3576
3577 x = pos.x + 50; /* column half width */
3578 y = pos.y + (bounds.bottom - bounds.top) / 2;
3579 test_lvm_hittest(hwnd, x, y, 0, LVHT_ONITEMLABEL, 0, FALSE, FALSE);
3580 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE);
3581 x = pos.x + 150; /* outside column */
3582 y = pos.y + (bounds.bottom - bounds.top) / 2;
3583 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, 0, FALSE, FALSE);
3584 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE);
3585 y = (bounds.bottom - bounds.top) / 2;
3586 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, 0, FALSE, TRUE);
3587 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE);
3588 /* outside possible client rectangle (to right) */
3589 x = pos.x + 500;
3590 y = pos.y + (bounds.bottom - bounds.top) / 2;
3591 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, 0, FALSE, FALSE);
3592 test_lvm_subitemhittest(hwnd, x, y, -1, -1, LVHT_NOWHERE, FALSE, FALSE, FALSE);
3593 y = (bounds.bottom - bounds.top) / 2;
3594 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, 0, FALSE, TRUE);
3595 test_lvm_subitemhittest(hwnd, x, y, -1, -1, LVHT_NOWHERE, FALSE, FALSE, FALSE);
3596 /* subitem returned with -1 item too */
3597 x = pos.x + 150;
3598 y = bounds.top - vert;
3599 test_lvm_subitemhittest(hwnd, x, y, -1, 1, LVHT_NOWHERE, FALSE, FALSE, FALSE);
3600 test_lvm_subitemhittest(hwnd, x, y - vert + 1, -1, 1, LVHT_NOWHERE, FALSE, FALSE, FALSE);
3601 /* return values appear to underflow with negative indices */
3602 i = -2;
3603 y = y - vert;
3604 while (i > -10) {
3605 test_lvm_subitemhittest(hwnd, x, y, i, 1, LVHT_ONITEMLABEL, TRUE, FALSE, TRUE);
3606 test_lvm_subitemhittest(hwnd, x, y - vert + 1, i, 1, LVHT_ONITEMLABEL, TRUE, FALSE, TRUE);
3607 y = y - vert;
3608 i--;
3609 }
3610 /* parent client area is 100x100 by default */
3611 MoveWindow(hwnd, 0, 0, 300, 100, FALSE);
3612 x = pos.x + 150; /* outside column */
3613 y = pos.y + (bounds.bottom - bounds.top) / 2;
3614 test_lvm_hittest(hwnd, x, y, -1, LVHT_NOWHERE, 0, FALSE, FALSE);
3615 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE);
3616 y = (bounds.bottom - bounds.top) / 2;
3617 test_lvm_hittest(hwnd, x, y, -1, LVHT_NOWHERE, 0, FALSE, TRUE);
3618 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE);
3619 /* the same with LVS_EX_FULLROWSELECT */
3620 SendMessageA(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_FULLROWSELECT);
3621 x = pos.x + 150; /* outside column */
3622 y = pos.y + (bounds.bottom - bounds.top) / 2;
3623 test_lvm_hittest(hwnd, x, y, 0, LVHT_ONITEM, LVHT_ONITEMLABEL, FALSE, FALSE);
3624 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE);
3625 y = (bounds.bottom - bounds.top) / 2;
3626 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE);
3627 MoveWindow(hwnd, 0, 0, 100, 100, FALSE);
3628 x = pos.x + 150; /* outside column */
3629 y = pos.y + (bounds.bottom - bounds.top) / 2;
3630 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, 0, FALSE, FALSE);
3631 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE);
3632 y = (bounds.bottom - bounds.top) / 2;
3633 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, 0, FALSE, TRUE);
3634 test_lvm_subitemhittest(hwnd, x, y, 0, 1, LVHT_ONITEMLABEL, FALSE, FALSE, FALSE);
3635 /* outside possible client rectangle (to right) */
3636 x = pos.x + 500;
3637 y = pos.y + (bounds.bottom - bounds.top) / 2;
3638 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, 0, FALSE, FALSE);
3639 test_lvm_subitemhittest(hwnd, x, y, -1, -1, LVHT_NOWHERE, FALSE, FALSE, FALSE);
3640 y = (bounds.bottom - bounds.top) / 2;
3641 test_lvm_hittest(hwnd, x, y, -1, LVHT_TORIGHT, 0, FALSE, TRUE);
3642 test_lvm_subitemhittest(hwnd, x, y, -1, -1, LVHT_NOWHERE, FALSE, FALSE, FALSE);
3643 /* try with icons, state icons index is 1 based so at least 2 bitmaps needed */
3644 himl = ImageList_Create(16, 16, 0, 4, 4);
3645 ok(himl != NULL, "failed to create imagelist\n");
3646 hbmp = CreateBitmap(16, 16, 1, 1, NULL);
3647 ok(hbmp != NULL, "failed to create bitmap\n");
3648 r = ImageList_Add(himl, hbmp, 0);
3649 ok(r == 0, "should be zero\n");
3650 hbmp = CreateBitmap(16, 16, 1, 1, NULL);
3651 ok(hbmp != NULL, "failed to create bitmap\n");
3652 r = ImageList_Add(himl, hbmp, 0);
3653 ok(r == 1, "should be one\n");
3654
3655 r = SendMessageA(hwnd, LVM_SETIMAGELIST, LVSIL_STATE, (LPARAM)himl);
3656 expect(0, r);
3657
3658 item.mask = LVIF_IMAGE;
3659 item.iImage = 0;
3660 item.iItem = 0;
3661 item.iSubItem = 0;
3662 r = SendMessageA(hwnd, LVM_SETITEMA, 0, (LPARAM)&item);
3663 expect(TRUE, r);
3664 /* on state icon */
3665 x = pos.x + 8;
3666 y = pos.y + (bounds.bottom - bounds.top) / 2;
3667 test_lvm_hittest(hwnd, x, y, 0, LVHT_ONITEMSTATEICON, 0, FALSE, FALSE);
3668 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMSTATEICON, FALSE, FALSE, FALSE);
3669 y = (bounds.bottom - bounds.top) / 2;
3670 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMSTATEICON, FALSE, FALSE, FALSE);
3671
3672 /* state icons indices are 1 based, check with valid index */
3673 item.mask = LVIF_STATE;
3674 item.state = INDEXTOSTATEIMAGEMASK(1);
3675 item.stateMask = LVIS_STATEIMAGEMASK;
3676 item.iItem = 0;
3677 item.iSubItem = 0;
3678 r = SendMessageA(hwnd, LVM_SETITEMA, 0, (LPARAM)&item);
3679 expect(TRUE, r);
3680 /* on state icon */
3681 x = pos.x + 8;
3682 y = pos.y + (bounds.bottom - bounds.top) / 2;
3683 test_lvm_hittest(hwnd, x, y, 0, LVHT_ONITEMSTATEICON, 0, FALSE, FALSE);
3684 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMSTATEICON, FALSE, FALSE, FALSE);
3685 y = (bounds.bottom - bounds.top) / 2;
3686 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMSTATEICON, FALSE, FALSE, FALSE);
3687
3688 himl2 = (HIMAGELIST)SendMessageA(hwnd, LVM_SETIMAGELIST, LVSIL_STATE, 0);
3689 ok(himl2 == himl, "should return handle\n");
3690
3691 r = SendMessageA(hwnd, LVM_SETIMAGELIST, LVSIL_SMALL, (LPARAM)himl);
3692 expect(0, r);
3693 /* on item icon */
3694 x = pos.x + 8;
3695 y = pos.y + (bounds.bottom - bounds.top) / 2;
3696 test_lvm_hittest(hwnd, x, y, 0, LVHT_ONITEMICON, 0, FALSE, FALSE);
3697 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMICON, FALSE, FALSE, FALSE);
3698 y = (bounds.bottom - bounds.top) / 2;
3699 test_lvm_subitemhittest(hwnd, x, y, 0, 0, LVHT_ONITEMICON, FALSE, FALSE, FALSE);
3700
3701 DestroyWindow(hwnd);
3702 }
3703
3704 static void test_getviewrect(void)
3705 {
3706 HWND hwnd;
3707 DWORD r;
3708 RECT rect;
3709 LVITEMA item;
3710
3711 hwnd = create_listview_control(LVS_REPORT);
3712 ok(hwnd != NULL, "failed to create a listview window\n");
3713
3714 /* empty */
3715 r = SendMessageA(hwnd, LVM_GETVIEWRECT, 0, (LPARAM)&rect);
3716 expect(TRUE, r);
3717
3718 insert_column(hwnd, 0);
3719 insert_column(hwnd, 1);
3720
3721 memset(&item, 0, sizeof(item));
3722 item.iItem = 0;
3723 item.iSubItem = 0;
3724 SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
3725
3726 r = SendMessageA(hwnd, LVM_SETCOLUMNWIDTH, 0, MAKELPARAM(100, 0));
3727 expect(TRUE, r);
3728 r = SendMessageA(hwnd, LVM_SETCOLUMNWIDTH, 1, MAKELPARAM(120, 0));
3729 expect(TRUE, r);
3730
3731 rect.left = rect.right = rect.top = rect.bottom = -1;
3732 r = SendMessageA(hwnd, LVM_GETVIEWRECT, 0, (LPARAM)&rect);
3733 expect(TRUE, r);
3734 /* left is set to (2e31-1) - XP SP2 */
3735 expect(0, rect.right);
3736 expect(0, rect.top);
3737 expect(0, rect.bottom);
3738
3739 /* switch to LVS_ICON */
3740 SetWindowLongA(hwnd, GWL_STYLE, GetWindowLongA(hwnd, GWL_STYLE) & ~LVS_REPORT);
3741
3742 rect.left = rect.right = rect.top = rect.bottom = -1;
3743 r = SendMessageA(hwnd, LVM_GETVIEWRECT, 0, (LPARAM)&rect);
3744 expect(TRUE, r);
3745 expect(0, rect.left);
3746 expect(0, rect.top);
3747 /* precise value differs for 2k, XP and Vista */
3748 ok(rect.bottom > 0, "Expected positive bottom value, got %d\n", rect.bottom);
3749 ok(rect.right > 0, "Expected positive right value, got %d\n", rect.right);
3750
3751 DestroyWindow(hwnd);
3752 }
3753
3754 static void test_getitemposition(void)
3755 {
3756 HWND hwnd, header;
3757 DWORD r;
3758 POINT pt;
3759 RECT rect;
3760
3761 hwnd = create_listview_control(LVS_REPORT);
3762 ok(hwnd != NULL, "failed to create a listview window\n");
3763 header = subclass_header(hwnd);
3764
3765 /* LVS_REPORT, single item, no columns added */
3766 insert_item(hwnd, 0);
3767
3768 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3769
3770 pt.x = pt.y = -1;
3771 r = SendMessageA(hwnd, LVM_GETITEMPOSITION, 0, (LPARAM)&pt);
3772 expect(TRUE, r);
3773 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, getitemposition_seq1, "get item position 1", FALSE);
3774
3775 /* LVS_REPORT, single item, single column */
3776 insert_column(hwnd, 0);
3777
3778 flush_sequences(sequences, NUM_MSG_SEQUENCES);
3779
3780 pt.x = pt.y = -1;
3781 r = SendMessageA(hwnd, LVM_GETITEMPOSITION, 0, (LPARAM)&pt);
3782 expect(TRUE, r);
3783 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, getitemposition_seq2, "get item position 2", TRUE);
3784
3785 memset(&rect, 0, sizeof(rect));
3786 SendMessageA(header, HDM_GETITEMRECT, 0, (LPARAM)&rect);
3787 /* some padding? */
3788 expect(2, pt.x);
3789 /* offset by header height */
3790 expect(rect.bottom - rect.top, pt.y);
3791
3792 DestroyWindow(hwnd);
3793 }
3794
3795 static void test_columnscreation(void)
3796 {
3797 HWND hwnd, header;
3798 DWORD r;
3799
3800 hwnd = create_listview_control(LVS_REPORT);
3801 ok(hwnd != NULL, "failed to create a listview window\n");
3802
3803 insert_item(hwnd, 0);
3804
3805 /* headers columns aren't created automatically */
3806 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
3807 ok(IsWindow(header), "Expected header handle\n");
3808 r = SendMessageA(header, HDM_GETITEMCOUNT, 0, 0);
3809 expect(0, r);
3810
3811 DestroyWindow(hwnd);
3812 }
3813
3814 static void test_getitemrect(void)
3815 {
3816 HWND hwnd;
3817 HIMAGELIST himl, himl_ret;
3818 HBITMAP hbm;
3819 RECT rect;
3820 DWORD r;
3821 LVITEMA item;
3822 LVCOLUMNA col;
3823 INT order[2];
3824 POINT pt;
3825 HDC hdc;
3826
3827 /* rectangle isn't empty for empty text items */
3828 hwnd = create_listview_control(LVS_LIST);
3829 memset(&item, 0, sizeof(item));
3830 item.mask = 0;
3831 item.iItem = 0;
3832 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
3833 expect(0, r);
3834 rect.left = LVIR_LABEL;
3835 r = SendMessageA(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3836 expect(TRUE, r);
3837 expect(0, rect.left);
3838 expect(0, rect.top);
3839 hdc = GetDC(hwnd);
3840 todo_wine expect(((GetDeviceCaps(hdc, LOGPIXELSX) + 15) / 16) * 16, rect.right);
3841 ReleaseDC(hwnd, hdc);
3842 DestroyWindow(hwnd);
3843
3844 hwnd = create_listview_control(LVS_REPORT);
3845 ok(hwnd != NULL, "failed to create a listview window\n");
3846
3847 /* empty item */
3848 memset(&item, 0, sizeof(item));
3849 item.iItem = 0;
3850 item.iSubItem = 0;
3851 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
3852 expect(0, r);
3853
3854 rect.left = LVIR_BOUNDS;
3855 rect.right = rect.top = rect.bottom = -1;
3856 r = SendMessageA(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3857 expect(TRUE, r);
3858
3859 /* zero width rectangle with no padding */
3860 expect(0, rect.left);
3861 expect(0, rect.right);
3862
3863 insert_column(hwnd, 0);
3864 insert_column(hwnd, 1);
3865
3866 col.mask = LVCF_WIDTH;
3867 col.cx = 50;
3868 r = SendMessageA(hwnd, LVM_SETCOLUMNA, 0, (LPARAM)&col);
3869 expect(TRUE, r);
3870
3871 col.mask = LVCF_WIDTH;
3872 col.cx = 100;
3873 r = SendMessageA(hwnd, LVM_SETCOLUMNA, 1, (LPARAM)&col);
3874 expect(TRUE, r);
3875
3876 rect.left = LVIR_BOUNDS;
3877 rect.right = rect.top = rect.bottom = -1;
3878 r = SendMessageA(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3879 expect(TRUE, r);
3880
3881 /* still no left padding */
3882 expect(0, rect.left);
3883 expect(150, rect.right);
3884
3885 rect.left = LVIR_SELECTBOUNDS;
3886 rect.right = rect.top = rect.bottom = -1;
3887 r = SendMessageA(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3888 expect(TRUE, r);
3889 /* padding */
3890 expect(2, rect.left);
3891
3892 rect.left = LVIR_LABEL;
3893 rect.right = rect.top = rect.bottom = -1;
3894 r = SendMessageA(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3895 expect(TRUE, r);
3896 /* padding, column width */
3897 expect(2, rect.left);
3898 expect(50, rect.right);
3899
3900 /* no icons attached */
3901 rect.left = LVIR_ICON;
3902 rect.right = rect.top = rect.bottom = -1;
3903 r = SendMessageA(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3904 expect(TRUE, r);
3905 /* padding */
3906 expect(2, rect.left);
3907 expect(2, rect.right);
3908
3909 /* change order */
3910 order[0] = 1; order[1] = 0;
3911 r = SendMessageA(hwnd, LVM_SETCOLUMNORDERARRAY, 2, (LPARAM)&order);
3912 expect(TRUE, r);
3913 pt.x = -1;
3914 r = SendMessageA(hwnd, LVM_GETITEMPOSITION, 0, (LPARAM)&pt);
3915 expect(TRUE, r);
3916 /* 1 indexed column width + padding */
3917 expect(102, pt.x);
3918 /* rect is at zero too */
3919 rect.left = LVIR_BOUNDS;
3920 rect.right = rect.top = rect.bottom = -1;
3921 r = SendMessageA(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3922 expect(TRUE, r);
3923 expect(0, rect.left);
3924 /* just width sum */
3925 expect(150, rect.right);
3926
3927 rect.left = LVIR_SELECTBOUNDS;
3928 rect.right = rect.top = rect.bottom = -1;
3929 r = SendMessageA(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3930 expect(TRUE, r);
3931 /* column width + padding */
3932 expect(102, rect.left);
3933
3934 /* back to initial order */
3935 order[0] = 0; order[1] = 1;
3936 r = SendMessageA(hwnd, LVM_SETCOLUMNORDERARRAY, 2, (LPARAM)&order);
3937 expect(TRUE, r);
3938
3939 /* state icons */
3940 himl = ImageList_Create(16, 16, 0, 2, 2);
3941 ok(himl != NULL, "failed to create imagelist\n");
3942 hbm = CreateBitmap(16, 16, 1, 1, NULL);
3943 ok(hbm != NULL, "failed to create bitmap\n");
3944 r = ImageList_Add(himl, hbm, 0);
3945 expect(0, r);
3946 hbm = CreateBitmap(16, 16, 1, 1, NULL);
3947 ok(hbm != NULL, "failed to create bitmap\n");
3948 r = ImageList_Add(himl, hbm, 0);
3949 expect(1, r);
3950
3951 r = SendMessageA(hwnd, LVM_SETIMAGELIST, LVSIL_STATE, (LPARAM)himl);
3952 expect(0, r);
3953
3954 item.mask = LVIF_STATE;
3955 item.state = INDEXTOSTATEIMAGEMASK(1);
3956 item.stateMask = LVIS_STATEIMAGEMASK;
3957 item.iItem = 0;
3958 item.iSubItem = 0;
3959 r = SendMessageA(hwnd, LVM_SETITEMA, 0, (LPARAM)&item);
3960 expect(TRUE, r);
3961
3962 /* icon bounds */
3963 rect.left = LVIR_ICON;
3964 rect.right = rect.top = rect.bottom = -1;
3965 r = SendMessageA(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3966 expect(TRUE, r);
3967 /* padding + stateicon width */
3968 expect(18, rect.left);
3969 expect(18, rect.right);
3970 /* label bounds */
3971 rect.left = LVIR_LABEL;
3972 rect.right = rect.top = rect.bottom = -1;
3973 r = SendMessageA(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3974 expect(TRUE, r);
3975 /* padding + stateicon width -> column width */
3976 expect(18, rect.left);
3977 expect(50, rect.right);
3978
3979 himl_ret = (HIMAGELIST)SendMessageA(hwnd, LVM_SETIMAGELIST, LVSIL_STATE, 0);
3980 ok(himl_ret == himl, "got %p, expected %p\n", himl_ret, himl);
3981
3982 r = SendMessageA(hwnd, LVM_SETIMAGELIST, LVSIL_SMALL, (LPARAM)himl);
3983 expect(0, r);
3984
3985 item.mask = LVIF_STATE | LVIF_IMAGE;
3986 item.iImage = 1;
3987 item.state = 0;
3988 item.stateMask = ~0;
3989 item.iItem = 0;
3990 item.iSubItem = 0;
3991 r = SendMessageA(hwnd, LVM_SETITEMA, 0, (LPARAM)&item);
3992 expect(TRUE, r);
3993
3994 /* icon bounds */
3995 rect.left = LVIR_ICON;
3996 rect.right = rect.top = rect.bottom = -1;
3997 r = SendMessageA(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
3998 expect(TRUE, r);
3999 /* padding, icon width */
4000 expect(2, rect.left);
4001 expect(18, rect.right);
4002 /* label bounds */
4003 rect.left = LVIR_LABEL;
4004 rect.right = rect.top = rect.bottom = -1;
4005 r = SendMessageA(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
4006 expect(TRUE, r);
4007 /* padding + icon width -> column width */
4008 expect(18, rect.left);
4009 expect(50, rect.right);
4010
4011 /* select bounds */
4012 rect.left = LVIR_SELECTBOUNDS;
4013 rect.right = rect.top = rect.bottom = -1;
4014 r = SendMessageA(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
4015 expect(TRUE, r);
4016 /* padding, column width */
4017 expect(2, rect.left);
4018 expect(50, rect.right);
4019
4020 /* try with indentation */
4021 item.mask = LVIF_INDENT;
4022 item.iIndent = 1;
4023 item.iItem = 0;
4024 item.iSubItem = 0;
4025 r = SendMessageA(hwnd, LVM_SETITEMA, 0, (LPARAM)&item);
4026 expect(TRUE, r);
4027
4028 /* bounds */
4029 rect.left = LVIR_BOUNDS;
4030 rect.right = rect.top = rect.bottom = -1;
4031 r = SendMessageA(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
4032 expect(TRUE, r);
4033 /* padding + 1 icon width, column width */
4034 expect(0, rect.left);
4035 expect(150, rect.right);
4036
4037 /* select bounds */
4038 rect.left = LVIR_SELECTBOUNDS;
4039 rect.right = rect.top = rect.bottom = -1;
4040 r = SendMessageA(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
4041 expect(TRUE, r);
4042 /* padding + 1 icon width, column width */
4043 expect(2 + 16, rect.left);
4044 expect(50, rect.right);
4045
4046 /* label bounds */
4047 rect.left = LVIR_LABEL;
4048 rect.right = rect.top = rect.bottom = -1;
4049 r = SendMessageA(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
4050 expect(TRUE, r);
4051 /* padding + 2 icon widths, column width */
4052 expect(2 + 16*2, rect.left);
4053 expect(50, rect.right);
4054
4055 /* icon bounds */
4056 rect.left = LVIR_ICON;
4057 rect.right = rect.top = rect.bottom = -1;
4058 r = SendMessageA(hwnd, LVM_GETITEMRECT, 0, (LPARAM)&rect);
4059 expect(TRUE, r);
4060 /* padding + 1 icon width indentation, icon width */
4061 expect(2 + 16, rect.left);
4062 expect(34, rect.right);
4063
4064 DestroyWindow(hwnd);
4065 }
4066
4067 static void test_editbox(void)
4068 {
4069 static CHAR testitemA[] = "testitem";
4070 static CHAR testitem1A[] = "testitem_quitelongname";
4071 static CHAR testitem2A[] = "testITEM_quitelongname";
4072 static CHAR buffer[25];
4073 HWND hwnd, hwndedit, hwndedit2, header;
4074 LVITEMA item;
4075 INT r;
4076
4077 hwnd = create_listview_control(LVS_EDITLABELS | LVS_REPORT);
4078 ok(hwnd != NULL, "failed to create a listview window\n");
4079
4080 insert_column(hwnd, 0);
4081
4082 memset(&item, 0, sizeof(item));
4083 item.mask = LVIF_TEXT;
4084 item.pszText = testitemA;
4085 item.iItem = 0;
4086 item.iSubItem = 0;
4087 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
4088 expect(0, r);
4089
4090 /* test notifications without edit created */
4091 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4092 r = SendMessageA(hwnd, WM_COMMAND, MAKEWPARAM(0, EN_SETFOCUS), (LPARAM)0xdeadbeef);
4093 expect(0, r);
4094 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
4095 "edit box WM_COMMAND (EN_SETFOCUS), no edit created", FALSE);
4096 /* same thing but with valid window */
4097 hwndedit = CreateWindowA("Edit", "Test edit", WS_VISIBLE | WS_CHILD, 0, 0, 20,
4098 10, hwnd, (HMENU)1, (HINSTANCE)GetWindowLongPtrA(hwnd, GWLP_HINSTANCE), 0);
4099 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4100 r = SendMessageA(hwnd, WM_COMMAND, MAKEWPARAM(0, EN_SETFOCUS), (LPARAM)hwndedit);
4101 expect(0, r);
4102 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
4103 "edit box WM_COMMAND (EN_SETFOCUS), no edit created #2", FALSE);
4104 DestroyWindow(hwndedit);
4105
4106 /* setting focus is necessary */
4107 SetFocus(hwnd);
4108 hwndedit = (HWND)SendMessageA(hwnd, LVM_EDITLABELA, 0, 0);
4109 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
4110
4111 /* test children Z-order after Edit box created */
4112 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
4113 ok(IsWindow(header), "Expected header to be created\n");
4114 ok(GetTopWindow(hwnd) == header, "Expected header to be on top\n");
4115 ok(GetNextWindow(header, GW_HWNDNEXT) == hwndedit, "got %p\n", GetNextWindow(header, GW_HWNDNEXT));
4116
4117 /* modify initial string */
4118 r = SendMessageA(hwndedit, WM_SETTEXT, 0, (LPARAM)testitem1A);
4119 expect(TRUE, r);
4120
4121 /* edit window is resized and repositioned,
4122 check again for Z-order - it should be preserved */
4123 ok(GetTopWindow(hwnd) == header, "Expected header to be on top\n");
4124 ok(GetNextWindow(header, GW_HWNDNEXT) == hwndedit, "got %p\n", GetNextWindow(header, GW_HWNDNEXT));
4125
4126 /* return focus to listview */
4127 SetFocus(hwnd);
4128
4129 memset(&item, 0, sizeof(item));
4130 item.mask = LVIF_TEXT;
4131 item.pszText = buffer;
4132 item.cchTextMax = sizeof(buffer);
4133 item.iItem = 0;
4134 item.iSubItem = 0;
4135 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM)&item);
4136 expect(TRUE, r);
4137
4138 ok(strcmp(buffer, testitem1A) == 0, "Expected item text to change\n");
4139
4140 /* send LVM_EDITLABEL on already created edit */
4141 SetFocus(hwnd);
4142 hwndedit = (HWND)SendMessageA(hwnd, LVM_EDITLABELA, 0, 0);
4143 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
4144 /* focus will be set to edit */
4145 ok(GetFocus() == hwndedit, "Expected Edit window to be focused\n");
4146 hwndedit2 = (HWND)SendMessageA(hwnd, LVM_EDITLABELA, 0, 0);
4147 ok(IsWindow(hwndedit2), "Expected Edit window to be created\n");
4148
4149 /* creating label disabled when control isn't focused */
4150 SetFocus(0);
4151 hwndedit = (HWND)SendMessageA(hwnd, LVM_EDITLABELA, 0, 0);
4152 todo_wine ok(hwndedit == NULL, "Expected Edit window not to be created\n");
4153
4154 /* check EN_KILLFOCUS handling */
4155 memset(&item, 0, sizeof(item));
4156 item.pszText = testitemA;
4157 item.iItem = 0;
4158 item.iSubItem = 0;
4159 r = SendMessageA(hwnd, LVM_SETITEMTEXTA, 0, (LPARAM)&item);
4160 expect(TRUE, r);
4161
4162 SetFocus(hwnd);
4163 hwndedit = (HWND)SendMessageA(hwnd, LVM_EDITLABELA, 0, 0);
4164 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
4165 /* modify edit and notify control that it lost focus */
4166 r = SendMessageA(hwndedit, WM_SETTEXT, 0, (LPARAM)testitem1A);
4167 expect(TRUE, r);
4168 g_editbox_disp_info.item.pszText = NULL;
4169 r = SendMessageA(hwnd, WM_COMMAND, MAKEWPARAM(0, EN_KILLFOCUS), (LPARAM)hwndedit);
4170 expect(0, r);
4171 ok(g_editbox_disp_info.item.pszText != NULL, "expected notification with not null text\n");
4172
4173 memset(&item, 0, sizeof(item));
4174 item.pszText = buffer;
4175 item.cchTextMax = sizeof(buffer);
4176 item.iItem = 0;
4177 item.iSubItem = 0;
4178 r = SendMessageA(hwnd, LVM_GETITEMTEXTA, 0, (LPARAM)&item);
4179 expect(lstrlenA(item.pszText), r);
4180 ok(strcmp(buffer, testitem1A) == 0, "Expected item text to change\n");
4181 ok(!IsWindow(hwndedit), "Expected Edit window to be freed\n");
4182
4183 /* change item name to differ in casing only */
4184 SetFocus(hwnd);
4185 hwndedit = (HWND)SendMessageA(hwnd, LVM_EDITLABELA, 0, 0);
4186 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
4187 /* modify edit and notify control that it lost focus */
4188 r = SendMessageA(hwndedit, WM_SETTEXT, 0, (LPARAM)testitem2A);
4189 expect(TRUE, r);
4190 g_editbox_disp_info.item.pszText = NULL;
4191 r = SendMessageA(hwnd, WM_COMMAND, MAKEWPARAM(0, EN_KILLFOCUS), (LPARAM)hwndedit);
4192 expect(0, r);
4193 ok(g_editbox_disp_info.item.pszText != NULL, "got %p\n", g_editbox_disp_info.item.pszText);
4194
4195 memset(&item, 0, sizeof(item));
4196 item.pszText = buffer;
4197 item.cchTextMax = sizeof(buffer);
4198 item.iItem = 0;
4199 item.iSubItem = 0;
4200 r = SendMessageA(hwnd, LVM_GETITEMTEXTA, 0, (LPARAM)&item);
4201 expect(lstrlenA(item.pszText), r);
4202 ok(strcmp(buffer, testitem2A) == 0, "got %s, expected %s\n", buffer, testitem2A);
4203 ok(!IsWindow(hwndedit), "Expected Edit window to be freed\n");
4204
4205 /* end edit without saving */
4206 SetFocus(hwnd);
4207 hwndedit = (HWND)SendMessageA(hwnd, LVM_EDITLABELA, 0, 0);
4208 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4209 r = SendMessageA(hwndedit, WM_KEYDOWN, VK_ESCAPE, 0);
4210 expect(0, r);
4211 ok_sequence(sequences, PARENT_SEQ_INDEX, edit_end_nochange,
4212 "edit box - end edit, no change, escape", TRUE);
4213 /* end edit with saving */
4214 SetFocus(hwnd);
4215 hwndedit = (HWND)SendMessageA(hwnd, LVM_EDITLABELA, 0, 0);
4216 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4217 r = SendMessageA(hwndedit, WM_KEYDOWN, VK_RETURN, 0);
4218 expect(0, r);
4219 ok_sequence(sequences, PARENT_SEQ_INDEX, edit_end_nochange,
4220 "edit box - end edit, no change, return", TRUE);
4221
4222 memset(&item, 0, sizeof(item));
4223 item.pszText = buffer;
4224 item.cchTextMax = sizeof(buffer);
4225 item.iItem = 0;
4226 item.iSubItem = 0;
4227 r = SendMessageA(hwnd, LVM_GETITEMTEXTA, 0, (LPARAM)&item);
4228 expect(lstrlenA(item.pszText), r);
4229 ok(strcmp(buffer, testitem2A) == 0, "Expected item text to change\n");
4230
4231 /* LVM_EDITLABEL with -1 destroys current edit */
4232 hwndedit = (HWND)SendMessageA(hwnd, LVM_GETEDITCONTROL, 0, 0);
4233 ok(hwndedit == NULL, "Expected Edit window not to be created\n");
4234 /* no edit present */
4235 hwndedit = (HWND)SendMessageA(hwnd, LVM_EDITLABELA, -1, 0);
4236 ok(hwndedit == NULL, "Expected Edit window not to be created\n");
4237 hwndedit = (HWND)SendMessageA(hwnd, LVM_EDITLABELA, 0, 0);
4238 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
4239 /* edit present */
4240 ok(GetFocus() == hwndedit, "Expected Edit to be focused\n");
4241 hwndedit2 = (HWND)SendMessageA(hwnd, LVM_EDITLABELA, -1, 0);
4242 ok(hwndedit2 == NULL, "Expected Edit window not to be created\n");
4243 ok(!IsWindow(hwndedit), "Expected Edit window to be destroyed\n");
4244 ok(GetFocus() == hwnd, "Expected List to be focused\n");
4245 /* check another negative value */
4246 hwndedit = (HWND)SendMessageA(hwnd, LVM_EDITLABELA, 0, 0);
4247 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
4248 ok(GetFocus() == hwndedit, "Expected Edit to be focused\n");
4249 hwndedit2 = (HWND)SendMessageA(hwnd, LVM_EDITLABELA, -2, 0);
4250 ok(hwndedit2 == NULL, "Expected Edit window not to be created\n");
4251 ok(!IsWindow(hwndedit), "Expected Edit window to be destroyed\n");
4252 ok(GetFocus() == hwnd, "Expected List to be focused\n");
4253 /* and value greater than max item index */
4254 hwndedit = (HWND)SendMessageA(hwnd, LVM_EDITLABELA, 0, 0);
4255 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
4256 ok(GetFocus() == hwndedit, "Expected Edit to be focused\n");
4257 r = SendMessageA(hwnd, LVM_GETITEMCOUNT, 0, 0);
4258 hwndedit2 = (HWND)SendMessageA(hwnd, LVM_EDITLABELA, r, 0);
4259 ok(hwndedit2 == NULL, "Expected Edit window not to be created\n");
4260 ok(!IsWindow(hwndedit), "Expected Edit window to be destroyed\n");
4261 ok(GetFocus() == hwnd, "Expected List to be focused\n");
4262
4263 /* messaging tests */
4264 SetFocus(hwnd);
4265 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4266 blockEdit = FALSE;
4267 hwndedit = (HWND)SendMessageA(hwnd, LVM_EDITLABELA, 0, 0);
4268 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
4269 /* testing only sizing messages */
4270 ok_sequence(sequences, EDITBOX_SEQ_INDEX, editbox_create_pos,
4271 "edit box create - sizing", FALSE);
4272
4273 /* WM_COMMAND with EN_KILLFOCUS isn't forwarded to parent */
4274 SetFocus(hwnd);
4275 hwndedit = (HWND)SendMessageA(hwnd, LVM_EDITLABELA, 0, 0);
4276 ok(IsWindow(hwndedit), "Expected Edit window to be created\n");
4277 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4278 r = SendMessageA(hwnd, WM_COMMAND, MAKEWPARAM(0, EN_KILLFOCUS), (LPARAM)hwndedit);
4279 expect(0, r);
4280 ok_sequence(sequences, PARENT_SEQ_INDEX, edit_end_nochange,
4281 "edit box WM_COMMAND (EN_KILLFOCUS)", TRUE);
4282
4283 DestroyWindow(hwnd);
4284 }
4285
4286 static void test_notifyformat(void)
4287 {
4288 HWND hwnd, header;
4289 DWORD r;
4290
4291 hwnd = create_listview_control(LVS_REPORT);
4292 ok(hwnd != NULL, "failed to create a listview window\n");
4293
4294 /* CCM_GETUNICODEFORMAT == LVM_GETUNICODEFORMAT,
4295 CCM_SETUNICODEFORMAT == LVM_SETUNICODEFORMAT */
4296 r = SendMessageA(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
4297 expect(0, r);
4298 SendMessageA(hwnd, WM_NOTIFYFORMAT, 0, NF_QUERY);
4299 /* set */
4300 r = SendMessageA(hwnd, LVM_SETUNICODEFORMAT, 1, 0);
4301 expect(0, r);
4302 r = SendMessageA(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
4303 if (r == 1)
4304 {
4305 r = SendMessageA(hwnd, LVM_SETUNICODEFORMAT, 0, 0);
4306 expect(1, r);
4307 r = SendMessageA(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
4308 expect(0, r);
4309 }
4310 else
4311 {
4312 win_skip("LVM_GETUNICODEFORMAT is unsupported\n");
4313 DestroyWindow(hwnd);
4314 return;
4315 }
4316
4317 DestroyWindow(hwnd);
4318
4319 /* test failure in parent WM_NOTIFYFORMAT */
4320 notifyFormat = 0;
4321 hwnd = create_listview_control(LVS_REPORT);
4322 ok(hwnd != NULL, "failed to create a listview window\n");
4323 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
4324 ok(IsWindow(header), "expected header to be created\n");
4325 r = SendMessageA(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
4326 expect(0, r);
4327 r = SendMessageA(header, HDM_GETUNICODEFORMAT, 0, 0);
4328 ok( r == 1, "Expected 1, got %d\n", r );
4329 r = SendMessageA(hwnd, WM_NOTIFYFORMAT, 0, NF_QUERY);
4330 ok(r != 0, "Expected valid format\n");
4331
4332 notifyFormat = NFR_UNICODE;
4333 r = SendMessageA(hwnd, WM_NOTIFYFORMAT, 0, NF_REQUERY);
4334 expect(NFR_UNICODE, r);
4335 r = SendMessageA(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
4336 expect(1, r);
4337 r = SendMessageA(header, HDM_GETUNICODEFORMAT, 0, 0);
4338 ok( r == 1, "Expected 1, got %d\n", r );
4339
4340 notifyFormat = NFR_ANSI;
4341 r = SendMessageA(hwnd, WM_NOTIFYFORMAT, 0, NF_REQUERY);
4342 expect(NFR_ANSI, r);
4343 r = SendMessageA(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
4344 expect(0, r);
4345 r = SendMessageA(header, HDM_GETUNICODEFORMAT, 0, 0);
4346 ok( r == 1, "Expected 1, got %d\n", r );
4347
4348 DestroyWindow(hwnd);
4349
4350 hwndparentW = create_parent_window(TRUE);
4351 ok(IsWindow(hwndparentW), "Unicode parent creation failed\n");
4352 if (!IsWindow(hwndparentW)) return;
4353
4354 notifyFormat = -1;
4355 hwnd = create_listview_controlW(LVS_REPORT, hwndparentW);
4356 ok(hwnd != NULL, "failed to create a listview window\n");
4357 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
4358 ok(IsWindow(header), "expected header to be created\n");
4359 r = SendMessageW(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
4360 expect(1, r);
4361 r = SendMessageA(header, HDM_GETUNICODEFORMAT, 0, 0);
4362 expect(1, r);
4363 DestroyWindow(hwnd);
4364 /* receiving error code defaulting to ansi */
4365 notifyFormat = 0;
4366 hwnd = create_listview_controlW(LVS_REPORT, hwndparentW);
4367 ok(hwnd != NULL, "failed to create a listview window\n");
4368 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
4369 ok(IsWindow(header), "expected header to be created\n");
4370 r = SendMessageW(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
4371 expect(0, r);
4372 r = SendMessageA(header, HDM_GETUNICODEFORMAT, 0, 0);
4373 expect(1, r);
4374 DestroyWindow(hwnd);
4375 /* receiving ansi code from unicode window, use it */
4376 notifyFormat = NFR_ANSI;
4377 hwnd = create_listview_controlW(LVS_REPORT, hwndparentW);
4378 ok(hwnd != NULL, "failed to create a listview window\n");
4379 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
4380 ok(IsWindow(header), "expected header to be created\n");
4381 r = SendMessageW(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
4382 expect(0, r);
4383 r = SendMessageA(header, HDM_GETUNICODEFORMAT, 0, 0);
4384 expect(1, r);
4385 DestroyWindow(hwnd);
4386 /* unicode listview with ansi parent window */
4387 notifyFormat = -1;
4388 hwnd = create_listview_controlW(LVS_REPORT, hwndparent);
4389 ok(hwnd != NULL, "failed to create a listview window\n");
4390 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
4391 ok(IsWindow(header), "expected header to be created\n");
4392 r = SendMessageW(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
4393 expect(0, r);
4394 r = SendMessageA(header, HDM_GETUNICODEFORMAT, 0, 0);
4395 expect(1, r);
4396 DestroyWindow(hwnd);
4397 /* unicode listview with ansi parent window, return error code */
4398 notifyFormat = 0;
4399 hwnd = create_listview_controlW(LVS_REPORT, hwndparent);
4400 ok(hwnd != NULL, "failed to create a listview window\n");
4401 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
4402 ok(IsWindow(header), "expected header to be created\n");
4403 r = SendMessageW(hwnd, LVM_GETUNICODEFORMAT, 0, 0);
4404 expect(0, r);
4405 r = SendMessageA(header, HDM_GETUNICODEFORMAT, 0, 0);
4406 expect(1, r);
4407 DestroyWindow(hwnd);
4408
4409 DestroyWindow(hwndparentW);
4410 }
4411
4412 static void test_indentation(void)
4413 {
4414 HWND hwnd;
4415 LVITEMA item;
4416 DWORD r;
4417
4418 hwnd = create_listview_control(LVS_REPORT);
4419 ok(hwnd != NULL, "failed to create a listview window\n");
4420
4421 memset(&item, 0, sizeof(item));
4422 item.mask = LVIF_INDENT;
4423 item.iItem = 0;
4424 item.iIndent = I_INDENTCALLBACK;
4425 r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
4426 expect(0, r);
4427
4428 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4429
4430 item.iItem = 0;
4431 item.mask = LVIF_INDENT;
4432 r = SendMessageA(hwnd, LVM_GETITEMA, 0, (LPARAM)&item);
4433 expect(TRUE, r);
4434
4435 ok_sequence(sequences, PARENT_SEQ_INDEX, single_getdispinfo_parent_seq,
4436 "get indent dispinfo", FALSE);
4437
4438 DestroyWindow(hwnd);
4439 }
4440
4441 static INT CALLBACK DummyCompareEx(LPARAM first, LPARAM second, LPARAM param)
4442 {
4443 return 0;
4444 }
4445
4446 static BOOL is_below_comctl_5(void)
4447 {
4448 HWND hwnd;
4449 BOOL ret;
4450
4451 hwnd = create_listview_control(LVS_REPORT);
4452 ok(hwnd != NULL, "failed to create a listview window\n");
4453 insert_item(hwnd, 0);
4454
4455 ret = SendMessageA(hwnd, LVM_SORTITEMSEX, 0, (LPARAM)&DummyCompareEx);
4456
4457 DestroyWindow(hwnd);
4458
4459 return !ret;
4460 }
4461
4462 static void test_get_set_view(void)
4463 {
4464 HWND hwnd;
4465 DWORD ret;
4466 DWORD_PTR style;
4467
4468 /* test style->view mapping */
4469 hwnd = create_listview_control(LVS_REPORT);
4470 ok(hwnd != NULL, "failed to create a listview window\n");
4471
4472 ret = SendMessageA(hwnd, LVM_GETVIEW, 0, 0);
4473 expect(LV_VIEW_DETAILS, ret);
4474
4475 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
4476 /* LVS_ICON == 0 */
4477 SetWindowLongPtrA(hwnd, GWL_STYLE, style & ~LVS_REPORT);
4478 ret = SendMessageA(hwnd, LVM_GETVIEW, 0, 0);
4479 expect(LV_VIEW_ICON, ret);
4480
4481 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
4482 SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_SMALLICON);
4483 ret = SendMessageA(hwnd, LVM_GETVIEW, 0, 0);
4484 expect(LV_VIEW_SMALLICON, ret);
4485
4486 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
4487 SetWindowLongPtrA(hwnd, GWL_STYLE, (style & ~LVS_SMALLICON) | LVS_LIST);
4488 ret = SendMessageA(hwnd, LVM_GETVIEW, 0, 0);
4489 expect(LV_VIEW_LIST, ret);
4490
4491 /* switching view doesn't touch window style */
4492 ret = SendMessageA(hwnd, LVM_SETVIEW, LV_VIEW_DETAILS, 0);
4493 expect(1, ret);
4494 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
4495 ok(style & LVS_LIST, "Expected style to be preserved\n");
4496 ret = SendMessageA(hwnd, LVM_SETVIEW, LV_VIEW_ICON, 0);
4497 expect(1, ret);
4498 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
4499 ok(style & LVS_LIST, "Expected style to be preserved\n");
4500 ret = SendMessageA(hwnd, LVM_SETVIEW, LV_VIEW_SMALLICON, 0);
4501 expect(1, ret);
4502 style = GetWindowLongPtrA(hwnd, GWL_STYLE);
4503 ok(style & LVS_LIST, "Expected style to be preserved\n");
4504
4505 DestroyWindow(hwnd);
4506 }
4507
4508 static void test_canceleditlabel(void)
4509 {
4510 HWND hwnd, hwndedit;
4511 DWORD ret;
4512 CHAR buff[10];
4513 LVITEMA itema;
4514 static CHAR test[] = "test";
4515 static const CHAR test1[] = "test1";
4516
4517 hwnd = create_listview_control(LVS_EDITLABELS | LVS_REPORT);
4518 ok(hwnd != NULL, "failed to create a listview window\n");
4519
4520 insert_item(hwnd, 0);
4521
4522 /* try without edit created */
4523 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4524 ret = SendMessageA(hwnd, LVM_CANCELEDITLABEL, 0, 0);
4525 expect(TRUE, ret);
4526 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
4527 "cancel edit label without edit", FALSE);
4528
4529 /* cancel without data change */
4530 SetFocus(hwnd);
4531 hwndedit = (HWND)SendMessageA(hwnd, LVM_EDITLABELA, 0, 0);
4532 ok(IsWindow(hwndedit), "Expected edit control to be created\n");
4533 ret = SendMessageA(hwnd, LVM_CANCELEDITLABEL, 0, 0);
4534 expect(TRUE, ret);
4535 ok(!IsWindow(hwndedit), "Expected edit control to be destroyed\n");
4536
4537 /* cancel after data change */
4538 memset(&itema, 0, sizeof(itema));
4539 itema.pszText = test;
4540 ret = SendMessageA(hwnd, LVM_SETITEMTEXTA, 0, (LPARAM)&itema);
4541 expect(TRUE, ret);
4542 SetFocus(hwnd);
4543 hwndedit = (HWND)SendMessageA(hwnd, LVM_EDITLABELA, 0, 0);
4544 ok(IsWindow(hwndedit), "Expected edit control to be created\n");
4545 ret = SetWindowTextA(hwndedit, test1);
4546 expect(1, ret);
4547 ret = SendMessageA(hwnd, LVM_CANCELEDITLABEL, 0, 0);
4548 expect(TRUE, ret);
4549 ok(!IsWindow(hwndedit), "Expected edit control to be destroyed\n");
4550 memset(&itema, 0, sizeof(itema));
4551 itema.pszText = buff;
4552 itema.cchTextMax = sizeof(buff)/sizeof(CHAR);
4553 ret = SendMessageA(hwnd, LVM_GETITEMTEXTA, 0, (LPARAM)&itema);
4554 expect(5, ret);
4555 ok(strcmp(buff, test1) == 0, "Expected label text not to change\n");
4556
4557 DestroyWindow(hwnd);
4558 }
4559
4560 static void test_mapidindex(void)
4561 {
4562 HWND hwnd;
4563 INT ret;
4564
4565 /* LVM_MAPINDEXTOID unsupported with LVS_OWNERDATA */
4566 hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT);
4567 ok(hwnd != NULL, "failed to create a listview window\n");
4568 insert_item(hwnd, 0);
4569 ret = SendMessageA(hwnd, LVM_MAPINDEXTOID, 0, 0);
4570 expect(-1, ret);
4571 DestroyWindow(hwnd);
4572
4573 hwnd = create_listview_control(LVS_REPORT);
4574 ok(hwnd != NULL, "failed to create a listview window\n");
4575
4576 /* LVM_MAPINDEXTOID with invalid index */
4577 ret = SendMessageA(hwnd, LVM_MAPINDEXTOID, 0, 0);
4578 expect(-1, ret);
4579
4580 insert_item(hwnd, 0);
4581 insert_item(hwnd, 1);
4582
4583 ret = SendMessageA(hwnd, LVM_MAPINDEXTOID, -1, 0);
4584 expect(-1, ret);
4585 ret = SendMessageA(hwnd, LVM_MAPINDEXTOID, 2, 0);
4586 expect(-1, ret);
4587
4588 ret = SendMessageA(hwnd, LVM_MAPINDEXTOID, 0, 0);
4589 expect(0, ret);
4590 ret = SendMessageA(hwnd, LVM_MAPINDEXTOID, 1, 0);
4591 expect(1, ret);
4592 /* remove 0 indexed item, id retained */
4593 SendMessageA(hwnd, LVM_DELETEITEM, 0, 0);
4594 ret = SendMessageA(hwnd, LVM_MAPINDEXTOID, 0, 0);
4595 expect(1, ret);
4596 /* new id starts from previous value */
4597 insert_item(hwnd, 1);
4598 ret = SendMessageA(hwnd, LVM_MAPINDEXTOID, 1, 0);
4599 expect(2, ret);
4600
4601 /* get index by id */
4602 ret = SendMessageA(hwnd, LVM_MAPIDTOINDEX, -1, 0);
4603 expect(-1, ret);
4604 ret = SendMessageA(hwnd, LVM_MAPIDTOINDEX, 0, 0);
4605 expect(-1, ret);
4606 ret = SendMessageA(hwnd, LVM_MAPIDTOINDEX, 1, 0);
4607 expect(0, ret);
4608 ret = SendMessageA(hwnd, LVM_MAPIDTOINDEX, 2, 0);
4609 expect(1, ret);
4610
4611 DestroyWindow(hwnd);
4612 }
4613
4614 static void test_getitemspacing(void)
4615 {
4616 HWND hwnd;
4617 DWORD ret;
4618 INT cx, cy;
4619 HIMAGELIST himl40, himl80;
4620
4621 cx = GetSystemMetrics(SM_CXICONSPACING) - GetSystemMetrics(SM_CXICON);
4622 cy = GetSystemMetrics(SM_CYICONSPACING) - GetSystemMetrics(SM_CYICON);
4623
4624 /* LVS_ICON */
4625 hwnd = create_listview_control(LVS_ICON);
4626 ret = SendMessageA(hwnd, LVM_GETITEMSPACING, FALSE, 0);
4627 expect(cx, LOWORD(ret));
4628 expect(cy, HIWORD(ret));
4629
4630 /* now try with icons */
4631 himl40 = ImageList_Create(40, 40, 0, 4, 4);
4632 ok(himl40 != NULL, "failed to create imagelist\n");
4633 himl80 = ImageList_Create(80, 80, 0, 4, 4);
4634 ok(himl80 != NULL, "failed to create imagelist\n");
4635 ret = SendMessageA(hwnd, LVM_SETIMAGELIST, LVSIL_NORMAL, (LPARAM)himl40);
4636 expect(0, ret);
4637
4638 ret = SendMessageA(hwnd, LVM_GETITEMSPACING, FALSE, 0);
4639 /* spacing + icon size returned */
4640 expect(cx + 40, LOWORD(ret));
4641 expect(cy + 40, HIWORD(ret));
4642 /* try changing icon size */
4643 SendMessageA(hwnd, LVM_SETIMAGELIST, LVSIL_NORMAL, (LPARAM)himl80);
4644
4645 ret = SendMessageA(hwnd, LVM_GETITEMSPACING, FALSE, 0);
4646 /* spacing + icon size returned */
4647 expect(cx + 80, LOWORD(ret));
4648 expect(cy + 80, HIWORD(ret));
4649
4650 /* set own icon spacing */
4651 ret = SendMessageA(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(100, 100));
4652 expect(cx + 80, LOWORD(ret));
4653 expect(cy + 80, HIWORD(ret));
4654
4655 ret = SendMessageA(hwnd, LVM_GETITEMSPACING, FALSE, 0);
4656 /* set size returned */
4657 expect(100, LOWORD(ret));
4658 expect(100, HIWORD(ret));
4659
4660 /* now change image list - icon spacing should be unaffected */
4661 SendMessageA(hwnd, LVM_SETIMAGELIST, LVSIL_NORMAL, (LPARAM)himl40);
4662
4663 ret = SendMessageA(hwnd, LVM_GETITEMSPACING, FALSE, 0);
4664 /* set size returned */
4665 expect(100, LOWORD(ret));
4666 expect(100, HIWORD(ret));
4667
4668 /* spacing = 0 - keep previous value */
4669 ret = SendMessageA(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(0, -1));
4670 expect(100, LOWORD(ret));
4671 expect(100, HIWORD(ret));
4672
4673 ret = SendMessageA(hwnd, LVM_GETITEMSPACING, FALSE, 0);
4674 expect(100, LOWORD(ret));
4675
4676 expect(0xFFFF, HIWORD(ret));
4677
4678 if (sizeof(void*) == 8)
4679 {
4680 /* NOTE: -1 is not treated the same as (DWORD)-1 by 64bit listview */
4681 ret = SendMessageA(hwnd, LVM_SETICONSPACING, 0, (DWORD)-1);
4682 expect(100, LOWORD(ret));
4683 expect(0xFFFF, HIWORD(ret));
4684
4685 ret = SendMessageA(hwnd, LVM_SETICONSPACING, 0, -1);
4686 expect(0xFFFF, LOWORD(ret));
4687 expect(0xFFFF, HIWORD(ret));
4688 }
4689 else
4690 {
4691 ret = SendMessageA(hwnd, LVM_SETICONSPACING, 0, -1);
4692 expect(100, LOWORD(ret));
4693 expect(0xFFFF, HIWORD(ret));
4694 }
4695 ret = SendMessageA(hwnd, LVM_GETITEMSPACING, FALSE, 0);
4696 /* spacing + icon size returned */
4697 expect(cx + 40, LOWORD(ret));
4698 expect(cy + 40, HIWORD(ret));
4699
4700 SendMessageA(hwnd, LVM_SETIMAGELIST, LVSIL_NORMAL, 0);
4701 ImageList_Destroy(himl80);
4702 DestroyWindow(hwnd);
4703 /* LVS_SMALLICON */
4704 hwnd = create_listview_control(LVS_SMALLICON);
4705 ret = SendMessageA(hwnd, LVM_GETITEMSPACING, FALSE, 0);
4706 expect(cx, LOWORD(ret));
4707 expect(cy, HIWORD(ret));
4708
4709 /* spacing does not depend on selected view type */
4710 ret = SendMessageA(hwnd, LVM_SETIMAGELIST, LVSIL_NORMAL, (LPARAM)himl40);
4711 expect(0, ret);
4712
4713 ret = SendMessageA(hwnd, LVM_GETITEMSPACING, FALSE, 0);
4714 /* spacing + icon size returned */
4715 expect(cx + 40, LOWORD(ret));
4716 expect(cy + 40, HIWORD(ret));
4717
4718 SendMessageA(hwnd, LVM_SETIMAGELIST, LVSIL_NORMAL, 0);
4719 ImageList_Destroy(himl40);
4720 DestroyWindow(hwnd);
4721 /* LVS_REPORT */
4722 hwnd = create_listview_control(LVS_REPORT);
4723 ret = SendMessageA(hwnd, LVM_GETITEMSPACING, FALSE, 0);
4724 expect(cx, LOWORD(ret));
4725 expect(cy, HIWORD(ret));
4726
4727 DestroyWindow(hwnd);
4728 /* LVS_LIST */
4729 hwnd = create_listview_control(LVS_LIST);
4730 ret = SendMessageA(hwnd, LVM_GETITEMSPACING, FALSE, 0);
4731 expect(cx, LOWORD(ret));
4732 expect(cy, HIWORD(ret));
4733
4734 DestroyWindow(hwnd);
4735 }
4736
4737 static void test_getcolumnwidth(void)
4738 {
4739 HWND hwnd;
4740 INT ret;
4741 DWORD_PTR style;
4742 LVCOLUMNA col;
4743 LVITEMA itema;
4744 HDC hdc;
4745
4746 /* default column width */
4747 hwnd = create_listview_control(LVS_ICON);
4748 ret = SendMessageA(hwnd, LVM_GETCOLUMNWIDTH, 0, 0);
4749 expect(0, ret);
4750 style = GetWindowLongA(hwnd, GWL_STYLE);
4751 SetWindowLongA(hwnd, GWL_STYLE, style | LVS_LIST);
4752 ret = SendMessageA(hwnd, LVM_GETCOLUMNWIDTH, 0, 0);
4753 todo_wine expect(8, ret);
4754 style = GetWindowLongA(hwnd, GWL_STYLE) & ~LVS_LIST;
4755 SetWindowLongA(hwnd, GWL_STYLE, style | LVS_REPORT);
4756 col.mask = 0;
4757 ret = SendMessageA(hwnd, LVM_INSERTCOLUMNA, 0, (LPARAM)&col);
4758 expect(0, ret);
4759 ret = SendMessageA(hwnd, LVM_GETCOLUMNWIDTH, 0, 0);
4760 expect(10, ret);
4761 DestroyWindow(hwnd);
4762
4763 /* default column width with item added */
4764 hwnd = create_listview_control(LVS_LIST);
4765 memset(&itema, 0, sizeof(itema));
4766 SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&itema);
4767 ret = SendMessageA(hwnd, LVM_GETCOLUMNWIDTH, 0, 0);
4768 hdc = GetDC(hwnd);
4769 todo_wine expect(((GetDeviceCaps(hdc, LOGPIXELSX) + 15) / 16) * 16, ret);
4770 ReleaseDC(hwnd, hdc);
4771 DestroyWindow(hwnd);
4772 }
4773
4774 static void test_scrollnotify(void)
4775 {
4776 HWND hwnd;
4777 DWORD ret;
4778
4779 hwnd = create_listview_control(LVS_REPORT);
4780
4781 insert_column(hwnd, 0);
4782 insert_column(hwnd, 1);
4783 insert_item(hwnd, 0);
4784
4785 /* make it scrollable - resize */
4786 ret = SendMessageA(hwnd, LVM_SETCOLUMNWIDTH, 0, MAKELPARAM(100, 0));
4787 expect(TRUE, ret);
4788 ret = SendMessageA(hwnd, LVM_SETCOLUMNWIDTH, 1, MAKELPARAM(100, 0));
4789 expect(TRUE, ret);
4790
4791 /* try with dummy call */
4792 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4793 ret = SendMessageA(hwnd, LVM_SCROLL, 0, 0);
4794 expect(TRUE, ret);
4795 ok_sequence(sequences, PARENT_SEQ_INDEX, scroll_parent_seq,
4796 "scroll notify 1", TRUE);
4797
4798 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4799 ret = SendMessageA(hwnd, LVM_SCROLL, 1, 0);
4800 expect(TRUE, ret);
4801 ok_sequence(sequences, PARENT_SEQ_INDEX, scroll_parent_seq,
4802 "scroll notify 2", TRUE);
4803
4804 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4805 ret = SendMessageA(hwnd, LVM_SCROLL, 1, 1);
4806 expect(TRUE, ret);
4807 ok_sequence(sequences, PARENT_SEQ_INDEX, scroll_parent_seq,
4808 "scroll notify 3", TRUE);
4809
4810 DestroyWindow(hwnd);
4811 }
4812
4813 static void test_LVS_EX_TRANSPARENTBKGND(void)
4814 {
4815 HWND hwnd;
4816 DWORD ret;
4817 HDC hdc;
4818
4819 hwnd = create_listview_control(LVS_REPORT);
4820
4821 ret = SendMessageA(hwnd, LVM_SETBKCOLOR, 0, RGB(0, 0, 0));
4822 expect(TRUE, ret);
4823
4824 SendMessageA(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_TRANSPARENTBKGND,
4825 LVS_EX_TRANSPARENTBKGND);
4826
4827 ret = SendMessageA(hwnd, LVM_GETBKCOLOR, 0, 0);
4828 if (ret != CLR_NONE)
4829 {
4830 win_skip("LVS_EX_TRANSPARENTBKGND unsupported\n");
4831 DestroyWindow(hwnd);
4832 return;
4833 }
4834
4835 /* try to set some back color and check this style bit */
4836 ret = SendMessageA(hwnd, LVM_SETBKCOLOR, 0, RGB(0, 0, 0));
4837 expect(TRUE, ret);
4838 ret = SendMessageA(hwnd, LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0);
4839 ok(!(ret & LVS_EX_TRANSPARENTBKGND), "Expected LVS_EX_TRANSPARENTBKGND to unset\n");
4840
4841 /* now test what this style actually does */
4842 SendMessageA(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_TRANSPARENTBKGND,
4843 LVS_EX_TRANSPARENTBKGND);
4844
4845 hdc = GetWindowDC(hwndparent);
4846
4847 flush_sequences(sequences, NUM_MSG_SEQUENCES);
4848 SendMessageA(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
4849 ok_sequence(sequences, PARENT_SEQ_INDEX, lvs_ex_transparentbkgnd_seq,
4850 "LVS_EX_TRANSPARENTBKGND parent", FALSE);
4851
4852 ReleaseDC(hwndparent, hdc);
4853
4854 DestroyWindow(hwnd);
4855 }
4856
4857 static void test_approximate_viewrect(void)
4858 {
4859 HWND hwnd;
4860 DWORD ret;
4861 HIMAGELIST himl;
4862 HBITMAP hbmp;
4863 LVITEMA itema;
4864 static CHAR test[] = "abracadabra, a very long item label";
4865
4866 hwnd = create_listview_control(LVS_ICON);
4867 himl = ImageList_Create(40, 40, 0, 4, 4);
4868 ok(himl != NULL, "failed to create imagelist\n");
4869 hbmp = CreateBitmap(40, 40, 1, 1, NULL);
4870 ok(hbmp != NULL, "failed to create bitmap\n");
4871 ret = ImageList_Add(himl, hbmp, 0);
4872 expect(0, ret);
4873 ret = SendMessageA(hwnd, LVM_SETIMAGELIST, 0, (LPARAM)himl);
4874 expect(0, ret);
4875
4876 itema.mask = LVIF_IMAGE;
4877 itema.iImage = 0;
4878 itema.iItem = 0;
4879 itema.iSubItem = 0;
4880 ret = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&itema);
4881 expect(0, ret);
4882
4883 ret = SendMessageA(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(75, 75));
4884 if (ret == 0)
4885 {
4886 /* version 4.0 */
4887 win_skip("LVM_SETICONSPACING unimplemented. Skipping.\n");
4888 return;
4889 }
4890
4891 ret = SendMessageA(hwnd, LVM_APPROXIMATEVIEWRECT, 11, MAKELPARAM(100,100));
4892 expect(MAKELONG(77,827), ret);
4893
4894 ret = SendMessageA(hwnd, LVM_SETICONSPACING, 0, MAKELPARAM(50, 50));
4895 ok(ret != 0, "got 0\n");
4896
4897 ret = SendMessageA(hwnd, LVM_APPROXIMATEVIEWRECT, 11, MAKELPARAM(100,100));
4898 expect(MAKELONG(102,302), ret);
4899
4900 ret = SendMessageA(hwnd, LVM_APPROXIMATEVIEWRECT, -1, MAKELPARAM(100,100));
4901 expect(MAKELONG(52,52), ret);
4902
4903 itema.pszText = test;
4904 ret = SendMessageA(hwnd, LVM_SETITEMTEXTA, 0, (LPARAM)&itema);
4905 expect(TRUE, ret);
4906 ret = SendMessageA(hwnd, LVM_APPROXIMATEVIEWRECT, -1, MAKELPARAM(100,100));
4907 expect(MAKELONG(52,52), ret);
4908
4909 ret = SendMessageA(hwnd, LVM_APPROXIMATEVIEWRECT, 0, MAKELPARAM(100,100));
4910 expect(MAKELONG(52,2), ret);
4911 ret = SendMessageA(hwnd, LVM_APPROXIMATEVIEWRECT, 1, MAKELPARAM(100,100));
4912 expect(MAKELONG(52,52), ret);
4913 ret = SendMessageA(hwnd, LVM_APPROXIMATEVIEWRECT, 2, MAKELPARAM(100,100));
4914 expect(MAKELONG(102,52), ret);
4915 ret = SendMessageA(hwnd, LVM_APPROXIMATEVIEWRECT, 3, MAKELPARAM(100,100));
4916 expect(MAKELONG(102,102), ret);
4917 ret = SendMessageA(hwnd, LVM_APPROXIMATEVIEWRECT, 4, MAKELPARAM(100,100));
4918 expect(MAKELONG(102,102), ret);
4919 ret = SendMessageA(hwnd, LVM_APPROXIMATEVIEWRECT, 5, MAKELPARAM(100,100));
4920 expect(MAKELONG(102,152), ret);
4921 ret = SendMessageA(hwnd, LVM_APPROXIMATEVIEWRECT, 6, MAKELPARAM(100,100));
4922 expect(MAKELONG(102,152), ret);
4923 ret = SendMessageA(hwnd, LVM_APPROXIMATEVIEWRECT, 7, MAKELPARAM(160,100));
4924 expect(MAKELONG(152,152), ret);
4925
4926 DestroyWindow(hwnd);
4927 }
4928
4929 static void test_finditem(void)
4930 {
4931 LVFINDINFOA fi;
4932 static char f[5];
4933 HWND hwnd;
4934 INT r;
4935
4936 hwnd = create_listview_control(LVS_REPORT);
4937 insert_item(hwnd, 0);
4938
4939 memset(&fi, 0, sizeof(fi));
4940
4941 /* full string search, inserted text was "foo" */
4942 strcpy(f, "foo");
4943 fi.flags = LVFI_STRING;
4944 fi.psz = f;
4945 r = SendMessageA(hwnd, LVM_FINDITEMA, -1, (LPARAM)&fi);
4946 expect(0, r);
4947 /* partial string search, inserted text was "foo" */
4948 strcpy(f, "fo");
4949 fi.flags = LVFI_STRING | LVFI_PARTIAL;
4950 fi.psz = f;
4951 r = SendMessageA(hwnd, LVM_FINDITEMA, -1, (LPARAM)&fi);
4952 expect(0, r);
4953 /* partial string search, part after start char */
4954 strcpy(f, "oo");
4955 fi.flags = LVFI_STRING | LVFI_PARTIAL;
4956 fi.psz = f;
4957 r = SendMessageA(hwnd, LVM_FINDITEMA, -1, (LPARAM)&fi);
4958 expect(-1, r);
4959
4960 /* try with LVFI_SUBSTRING */
4961 strcpy(f, "fo");
4962 fi.flags = LVFI_SUBSTRING;
4963 fi.psz = f;
4964 r = SendMessageA(hwnd, LVM_FINDITEMA, -1, (LPARAM)&fi);
4965 if (r == -1)
4966 {
4967 win_skip("LVFI_SUBSTRING not supported\n");
4968 DestroyWindow(hwnd);
4969 return;
4970 }
4971 expect(0, r);
4972 strcpy(f, "f");
4973 fi.flags = LVFI_SUBSTRING;
4974 fi.psz = f;
4975 r = SendMessageA(hwnd, LVM_FINDITEMA, -1, (LPARAM)&fi);
4976 expect(0, r);
4977 strcpy(f, "o");
4978 fi.flags = LVFI_SUBSTRING;
4979 fi.psz = f;
4980 r = SendMessageA(hwnd, LVM_FINDITEMA, -1, (LPARAM)&fi);
4981 expect(-1, r);
4982
4983 strcpy(f, "f");
4984 fi.flags = LVFI_SUBSTRING | LVFI_STRING;
4985 fi.psz = f;
4986 r = SendMessageA(hwnd, LVM_FINDITEMA, -1, (LPARAM)&fi);
4987 expect(0, r);
4988
4989 DestroyWindow(hwnd);
4990 }
4991
4992 static void test_LVS_EX_HEADERINALLVIEWS(void)
4993 {
4994 HWND hwnd, header;
4995 DWORD style;
4996
4997 hwnd = create_listview_control(LVS_ICON);
4998
4999 SendMessageA(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_HEADERINALLVIEWS,
5000 LVS_EX_HEADERINALLVIEWS);
5001
5002 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
5003 if (!IsWindow(header))
5004 {
5005 win_skip("LVS_EX_HEADERINALLVIEWS unsupported\n");
5006 DestroyWindow(hwnd);
5007 return;
5008 }
5009
5010 /* LVS_NOCOLUMNHEADER works as before */
5011 style = GetWindowLongA(hwnd, GWL_STYLE);
5012 SetWindowLongW(hwnd, GWL_STYLE, style | LVS_NOCOLUMNHEADER);
5013 style = GetWindowLongA(header, GWL_STYLE);
5014 ok(style & HDS_HIDDEN, "Expected HDS_HIDDEN\n");
5015 style = GetWindowLongA(hwnd, GWL_STYLE);
5016 SetWindowLongW(hwnd, GWL_STYLE, style & ~LVS_NOCOLUMNHEADER);
5017 style = GetWindowLongA(header, GWL_STYLE);
5018 ok(!(style & HDS_HIDDEN), "Expected HDS_HIDDEN to be unset\n");
5019
5020 /* try to remove style */
5021 SendMessageA(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_HEADERINALLVIEWS, 0);
5022 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
5023 ok(IsWindow(header), "Expected header to be created\n");
5024 style = GetWindowLongA(header, GWL_STYLE);
5025 ok(!(style & HDS_HIDDEN), "HDS_HIDDEN not expected\n");
5026
5027 DestroyWindow(hwnd);
5028
5029 /* check other styles */
5030 hwnd = create_listview_control(LVS_LIST);
5031 SendMessageA(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_HEADERINALLVIEWS,
5032 LVS_EX_HEADERINALLVIEWS);
5033 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
5034 ok(IsWindow(header), "Expected header to be created\n");
5035 DestroyWindow(hwnd);
5036
5037 hwnd = create_listview_control(LVS_SMALLICON);
5038 SendMessageA(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_HEADERINALLVIEWS,
5039 LVS_EX_HEADERINALLVIEWS);
5040 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
5041 ok(IsWindow(header), "Expected header to be created\n");
5042 DestroyWindow(hwnd);
5043
5044 hwnd = create_listview_control(LVS_REPORT);
5045 SendMessageA(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_HEADERINALLVIEWS,
5046 LVS_EX_HEADERINALLVIEWS);
5047 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
5048 ok(IsWindow(header), "Expected header to be created\n");
5049 DestroyWindow(hwnd);
5050 }
5051
5052 static void test_hover(void)
5053 {
5054 HWND hwnd;
5055 DWORD r;
5056
5057 hwnd = create_listview_control(LVS_ICON);
5058
5059 /* test WM_MOUSEHOVER forwarding */
5060 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5061 r = SendMessageA(hwnd, WM_MOUSEHOVER, 0, 0);
5062 expect(0, r);
5063 ok_sequence(sequences, PARENT_SEQ_INDEX, hover_parent, "NM_HOVER allow test", TRUE);
5064 g_block_hover = TRUE;
5065 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5066 r = SendMessageA(hwnd, WM_MOUSEHOVER, 0, 0);
5067 expect(0, r);
5068 ok_sequence(sequences, PARENT_SEQ_INDEX, hover_parent, "NM_HOVER block test", TRUE);
5069 g_block_hover = FALSE;
5070
5071 r = SendMessageA(hwnd, LVM_SETHOVERTIME, 0, 500);
5072 expect(HOVER_DEFAULT, r);
5073 r = SendMessageA(hwnd, LVM_GETHOVERTIME, 0, 0);
5074 expect(500, r);
5075
5076 DestroyWindow(hwnd);
5077 }
5078
5079 static void test_destroynotify(void)
5080 {
5081 HWND hwnd;
5082 BOOL ret;
5083
5084 hwnd = create_listview_control(LVS_REPORT);
5085 ok(hwnd != NULL, "failed to create listview window\n");
5086
5087 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5088 DestroyWindow(hwnd);
5089 ok_sequence(sequences, COMBINED_SEQ_INDEX, listview_destroy, "check destroy order", FALSE);
5090
5091 /* same for ownerdata list */
5092 hwnd = create_listview_control(LVS_REPORT|LVS_OWNERDATA);
5093 ok(hwnd != NULL, "failed to create listview window\n");
5094
5095 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5096 DestroyWindow(hwnd);
5097 ok_sequence(sequences, COMBINED_SEQ_INDEX, listview_ownerdata_destroy, "check destroy order, ownerdata", FALSE);
5098
5099 hwnd = create_listview_control(LVS_REPORT|LVS_OWNERDATA);
5100 ok(hwnd != NULL, "failed to create listview window\n");
5101
5102 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5103 ret = SendMessageA(hwnd, LVM_DELETEALLITEMS, 0, 0);
5104 ok(ret == TRUE, "got %d\n", ret);
5105 ok_sequence(sequences, COMBINED_SEQ_INDEX, listview_ownerdata_deleteall, "deleteall ownerdata", FALSE);
5106 DestroyWindow(hwnd);
5107 }
5108
5109 static void test_header_notification(void)
5110 {
5111 static char textA[] = "newtext";
5112 HWND list, header;
5113 HDITEMA item;
5114 NMHEADERA nmh;
5115 LVCOLUMNA col;
5116 DWORD ret;
5117 BOOL r;
5118
5119 list = create_listview_control(LVS_REPORT);
5120 ok(list != NULL, "failed to create listview window\n");
5121
5122 memset(&col, 0, sizeof(col));
5123 col.mask = LVCF_WIDTH;
5124 col.cx = 100;
5125 ret = SendMessageA(list, LVM_INSERTCOLUMNA, 0, (LPARAM)&col);
5126 expect(0, ret);
5127
5128 /* check list parent notification after header item changed,
5129 this test should be placed before header subclassing to avoid
5130 Listview -> Header messages to be logged */
5131 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5132
5133 col.mask = LVCF_TEXT;
5134 col.pszText = textA;
5135 r = SendMessageA(list, LVM_SETCOLUMNA, 0, (LPARAM)&col);
5136 expect(TRUE, r);
5137
5138 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_header_changed_seq,
5139 "header notify, listview", FALSE);
5140 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
5141 "header notify, parent", FALSE);
5142
5143 header = subclass_header(list);
5144
5145 ret = SendMessageA(header, HDM_GETITEMCOUNT, 0, 0);
5146 expect(1, ret);
5147
5148 memset(&item, 0, sizeof(item));
5149 item.mask = HDI_WIDTH;
5150 ret = SendMessageA(header, HDM_GETITEMA, 0, (LPARAM)&item);
5151 expect(1, ret);
5152 expect(100, item.cxy);
5153
5154 nmh.hdr.hwndFrom = header;
5155 nmh.hdr.idFrom = GetWindowLongPtrA(header, GWLP_ID);
5156 nmh.hdr.code = HDN_ITEMCHANGEDA;
5157 nmh.iItem = 0;
5158 nmh.iButton = 0;
5159 item.mask = HDI_WIDTH;
5160 item.cxy = 50;
5161 nmh.pitem = &item;
5162 ret = SendMessageA(list, WM_NOTIFY, 0, (LPARAM)&nmh);
5163 expect(0, ret);
5164
5165 DestroyWindow(list);
5166 }
5167
5168 static void test_header_notification2(void)
5169 {
5170 static char textA[] = "newtext";
5171 HWND list, header;
5172 HDITEMW itemW;
5173 NMHEADERW nmhdr;
5174 LVCOLUMNA col;
5175 DWORD ret;
5176 WCHAR buffer[100];
5177 struct message parent_header_notify_seq[] = {
5178 { WM_NOTIFY, sent|id, 0, 0, 0 },
5179 { 0 }
5180 };
5181
5182 list = create_listview_control(LVS_REPORT);
5183 ok(list != NULL, "failed to create listview window\n");
5184
5185 memset(&col, 0, sizeof(col));
5186 col.mask = LVCF_WIDTH | LVCF_TEXT;
5187 col.cx = 100;
5188 col.pszText = textA;
5189 ret = SendMessageA(list, LVM_INSERTCOLUMNA, 0, (LPARAM)&col);
5190 expect(0, ret);
5191
5192 header = (HWND)SendMessageA(list, LVM_GETHEADER, 0, 0);
5193 ok(header != 0, "No header\n");
5194 memset(&itemW, 0, sizeof(itemW));
5195 itemW.mask = HDI_WIDTH | HDI_ORDER | HDI_TEXT;
5196 itemW.pszText = buffer;
5197 itemW.cchTextMax = sizeof(buffer);
5198 ret = SendMessageW(header, HDM_GETITEMW, 0, (LPARAM)&itemW);
5199 expect(1, ret);
5200
5201 nmhdr.hdr.hwndFrom = header;
5202 nmhdr.hdr.idFrom = GetWindowLongPtrW(header, GWLP_ID);
5203 nmhdr.iItem = 0;
5204 nmhdr.iButton = 0;
5205 nmhdr.pitem = &itemW;
5206
5207 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5208 nmhdr.hdr.code = HDN_ITEMCHANGINGW;
5209 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5210 parent_header_notify_seq[0].id = HDN_ITEMCHANGINGA;
5211 ok_sequence(sequences, PARENT_SEQ_INDEX, parent_header_notify_seq,
5212 "header notify, parent", TRUE);
5213 todo_wine
5214 ok(nmhdr.hdr.code == HDN_ITEMCHANGINGA, "Expected ANSI notification code\n");
5215 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5216 nmhdr.hdr.code = HDN_ITEMCHANGEDW;
5217 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5218 parent_header_notify_seq[0].id = HDN_ITEMCHANGEDA;
5219 ok_sequence(sequences, PARENT_SEQ_INDEX, parent_header_notify_seq,
5220 "header notify, parent", TRUE);
5221 todo_wine
5222 ok(nmhdr.hdr.code == HDN_ITEMCHANGEDA, "Expected ANSI notification code\n");
5223 /* HDN_ITEMCLICK sets focus to list, which generates messages we don't want to check */
5224 SetFocus(list);
5225 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5226 nmhdr.hdr.code = HDN_ITEMCLICKW;
5227 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5228 ok_sequence(sequences, PARENT_SEQ_INDEX, parent_header_click_seq,
5229 "header notify, parent", FALSE);
5230 ok(nmhdr.hdr.code == HDN_ITEMCLICKA, "Expected ANSI notification code\n");
5231 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5232 nmhdr.hdr.code = HDN_ITEMDBLCLICKW;
5233 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5234 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
5235 "header notify, parent", FALSE);
5236 ok(nmhdr.hdr.code == HDN_ITEMDBLCLICKW, "Expected Unicode notification code\n");
5237 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5238 nmhdr.hdr.code = HDN_DIVIDERDBLCLICKW;
5239 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5240 ok_sequence(sequences, PARENT_SEQ_INDEX, parent_header_divider_dclick_seq,
5241 "header notify, parent", TRUE);
5242 ok(nmhdr.hdr.code == HDN_DIVIDERDBLCLICKA, "Expected ANSI notification code\n");
5243 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5244 nmhdr.hdr.code = HDN_BEGINTRACKW;
5245 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5246 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
5247 "header notify, parent", FALSE);
5248 ok(nmhdr.hdr.code == HDN_BEGINTRACKW, "Expected Unicode notification code\n");
5249 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5250 nmhdr.hdr.code = HDN_ENDTRACKW;
5251 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5252 parent_header_notify_seq[0].id = HDN_ENDTRACKA;
5253 ok_sequence(sequences, PARENT_SEQ_INDEX, parent_header_notify_seq,
5254 "header notify, parent", FALSE);
5255 ok(nmhdr.hdr.code == HDN_ENDTRACKA, "Expected ANSI notification code\n");
5256 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5257 nmhdr.hdr.code = HDN_TRACKW;
5258 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5259 parent_header_notify_seq[0].id = HDN_TRACKA;
5260 ok_sequence(sequences, PARENT_SEQ_INDEX, parent_header_notify_seq,
5261 "header notify, parent", FALSE);
5262 ok(nmhdr.hdr.code == HDN_TRACKA, "Expected ANSI notification code\n");
5263 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5264 nmhdr.hdr.code = HDN_BEGINDRAG;
5265 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5266 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
5267 "header notify, parent", FALSE);
5268 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5269 nmhdr.hdr.code = HDN_ENDDRAG;
5270 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5271 parent_header_notify_seq[0].id = HDN_ENDDRAG;
5272 ok_sequence(sequences, PARENT_SEQ_INDEX, parent_header_notify_seq,
5273 "header notify, parent", FALSE);
5274 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5275 nmhdr.hdr.code = HDN_FILTERCHANGE;
5276 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5277 parent_header_notify_seq[0].id = HDN_FILTERCHANGE;
5278 parent_header_notify_seq[0].flags |= optional; /* NT4 does not send this message */
5279 ok_sequence(sequences, PARENT_SEQ_INDEX, parent_header_notify_seq,
5280 "header notify, parent", FALSE);
5281 parent_header_notify_seq[0].flags &= ~optional;
5282 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5283 nmhdr.hdr.code = HDN_BEGINFILTEREDIT;
5284 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5285 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
5286 "header notify, parent", FALSE);
5287 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5288 nmhdr.hdr.code = HDN_ENDFILTEREDIT;
5289 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5290 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
5291 "header notify, parent", FALSE);
5292 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5293 nmhdr.hdr.code = HDN_ITEMSTATEICONCLICK;
5294 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5295 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
5296 "header notify, parent", FALSE);
5297 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5298 nmhdr.hdr.code = HDN_ITEMKEYDOWN;
5299 ret = SendMessageW(list, WM_NOTIFY, 0, (LPARAM)&nmhdr);
5300 ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq,
5301 "header notify, parent", FALSE);
5302
5303 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5304
5305 DestroyWindow(list);
5306 }
5307
5308 static void test_createdragimage(void)
5309 {
5310 HIMAGELIST himl;
5311 POINT pt;
5312 HWND list;
5313
5314 list = create_listview_control(LVS_ICON);
5315 ok(list != NULL, "failed to create listview window\n");
5316
5317 insert_item(list, 0);
5318
5319 /* NULL point */
5320 himl = (HIMAGELIST)SendMessageA(list, LVM_CREATEDRAGIMAGE, 0, 0);
5321 ok(himl == NULL, "got %p\n", himl);
5322
5323 himl = (HIMAGELIST)SendMessageA(list, LVM_CREATEDRAGIMAGE, 0, (LPARAM)&pt);
5324 ok(himl != NULL, "got %p\n", himl);
5325 ImageList_Destroy(himl);
5326
5327 DestroyWindow(list);
5328 }
5329
5330 static void test_dispinfo(void)
5331 {
5332 static const char testA[] = "TEST";
5333 WCHAR buff[10];
5334 LVITEMA item;
5335 HWND hwnd;
5336 DWORD ret;
5337
5338 hwnd = create_listview_control(LVS_ICON);
5339 ok(hwnd != NULL, "failed to create listview window\n");
5340
5341 insert_item(hwnd, 0);
5342
5343 memset(&item, 0, sizeof(item));
5344 item.pszText = LPSTR_TEXTCALLBACKA;
5345 ret = SendMessageA(hwnd, LVM_SETITEMTEXTA, 0, (LPARAM)&item);
5346 expect(1, ret);
5347
5348 g_disp_A_to_W = TRUE;
5349 item.pszText = (char*)buff;
5350 item.cchTextMax = sizeof(buff)/sizeof(WCHAR);
5351 ret = SendMessageA(hwnd, LVM_GETITEMTEXTA, 0, (LPARAM)&item);
5352 ok(ret == sizeof(testA)-1, "got %d, expected 4\n", ret);
5353 g_disp_A_to_W = FALSE;
5354
5355 ok(memcmp(item.pszText, testA, sizeof(testA)) == 0,
5356 "got %s, expected %s\n", item.pszText, testA);
5357
5358 DestroyWindow(hwnd);
5359 }
5360
5361 static void test_LVM_SETITEMTEXT(void)
5362 {
5363 static char testA[] = "TEST";
5364 LVITEMA item;
5365 HWND hwnd;
5366 DWORD ret;
5367
5368 hwnd = create_listview_control(LVS_ICON);
5369 ok(hwnd != NULL, "failed to create listview window\n");
5370
5371 insert_item(hwnd, 0);
5372
5373 /* null item pointer */
5374 ret = SendMessageA(hwnd, LVM_SETITEMTEXTA, 0, 0);
5375 expect(FALSE, ret);
5376
5377 ret = SendMessageA(hwnd, LVM_SETITEMTEXTW, 0, 0);
5378 expect(FALSE, ret);
5379
5380 /* index out of bounds */
5381 item.pszText = testA;
5382 item.cchTextMax = 0; /* ignored */
5383 item.iSubItem = 0;
5384
5385 ret = SendMessageA(hwnd, LVM_SETITEMTEXTA, 1, (LPARAM)&item);
5386 expect(FALSE, ret);
5387
5388 ret = SendMessageA(hwnd, LVM_SETITEMTEXTA, -1, (LPARAM)&item);
5389 expect(FALSE, ret);
5390
5391 ret = SendMessageA(hwnd, LVM_SETITEMTEXTA, 0, (LPARAM)&item);
5392 expect(TRUE, ret);
5393
5394 DestroyWindow(hwnd);
5395 }
5396
5397 static void test_imagelists(void)
5398 {
5399 HWND hwnd, header;
5400 HIMAGELIST himl1, himl2, himl3;
5401 LRESULT ret;
5402
5403 himl1 = ImageList_Create(40, 40, 0, 4, 4);
5404 himl2 = ImageList_Create(40, 40, 0, 4, 4);
5405 himl3 = ImageList_Create(40, 40, 0, 4, 4);
5406 ok(himl1 != NULL, "Failed to create imagelist\n");
5407 ok(himl2 != NULL, "Failed to create imagelist\n");
5408 ok(himl3 != NULL, "Failed to create imagelist\n");
5409
5410 hwnd = create_listview_control(LVS_REPORT | LVS_SHAREIMAGELISTS);
5411 header = subclass_header(hwnd);
5412
5413 ok(header != NULL, "Expected header\n");
5414 ret = SendMessageA(header, HDM_GETIMAGELIST, 0, 0);
5415 ok(ret == 0, "Expected no imagelist, got %p\n", (HIMAGELIST)ret);
5416
5417 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5418
5419 ret = SendMessageW(hwnd, LVM_SETIMAGELIST, LVSIL_NORMAL, (LPARAM)himl1);
5420 ok(ret == 0, "Expected no imagelist, got %p\n", (HIMAGELIST)ret);
5421 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_set_imagelist,
5422 "set normal image list", FALSE);
5423
5424 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5425
5426 ret = SendMessageW(hwnd, LVM_SETIMAGELIST, LVSIL_STATE, (LPARAM)himl2);
5427 ok(ret == 0, "Expected no imagelist, got %p\n", (HIMAGELIST)ret);
5428 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_set_imagelist,
5429 "set state image list", TRUE);
5430
5431 ret = SendMessageA(header, HDM_GETIMAGELIST, 0, 0);
5432 ok(ret == 0, "Expected no imagelist, got %p\n", (HIMAGELIST)ret);
5433
5434 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5435
5436 ret = SendMessageW(hwnd, LVM_SETIMAGELIST, LVSIL_SMALL, (LPARAM)himl3);
5437 ok(ret == 0, "Expected no imagelist, got %p\n", (HIMAGELIST)ret);
5438 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_header_set_imagelist,
5439 "set small image list", FALSE);
5440
5441 ret = SendMessageA(header, HDM_GETIMAGELIST, 0, 0);
5442 ok((HIMAGELIST)ret == himl3, "Expected imagelist %p, got %p\n", himl3, (HIMAGELIST)ret);
5443 DestroyWindow(hwnd);
5444
5445 hwnd = create_listview_control(WS_VISIBLE | LVS_ICON);
5446
5447 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5448
5449 ret = SendMessageW(hwnd, LVM_SETIMAGELIST, LVSIL_NORMAL, (LPARAM)himl1);
5450 ok(ret == 0, "Expected no imagelist, got %p\n", (HIMAGELIST)ret);
5451 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_set_imagelist,
5452 "set normal image list", FALSE);
5453
5454 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5455
5456 ret = SendMessageW(hwnd, LVM_SETIMAGELIST, LVSIL_STATE, (LPARAM)himl2);
5457 ok(ret == 0, "Expected no imagelist, got %p\n", (HIMAGELIST)ret);
5458 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_set_imagelist,
5459 "set state image list", FALSE);
5460
5461 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5462
5463 ret = SendMessageW(hwnd, LVM_SETIMAGELIST, LVSIL_SMALL, (LPARAM)himl3);
5464 ok(ret == 0, "Expected no imagelist, got %p\n", (HIMAGELIST)ret);
5465 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, listview_set_imagelist,
5466 "set small image list", FALSE);
5467
5468 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
5469 ok(header == NULL, "Expected no header, got %p\n", header);
5470
5471 SetWindowLongPtrA(hwnd, GWL_STYLE, GetWindowLongPtrA(hwnd, GWL_STYLE) | LVS_REPORT);
5472
5473 header = (HWND)SendMessageA(hwnd, LVM_GETHEADER, 0, 0);
5474 ok(header != NULL, "Expected header, got NULL\n");
5475
5476 ret = SendMessageA(header, HDM_GETIMAGELIST, 0, 0);
5477 ok((HIMAGELIST)ret == himl3, "Expected imagelist %p, got %p\n", himl3, (HIMAGELIST)ret);
5478
5479 DestroyWindow(hwnd);
5480 }
5481
5482 static void test_deleteitem(void)
5483 {
5484 LVITEMA item;
5485 UINT state;
5486 HWND hwnd;
5487 BOOL ret;
5488
5489 hwnd = create_listview_control(LVS_REPORT);
5490
5491 insert_item(hwnd, 0);
5492 insert_item(hwnd, 0);
5493 insert_item(hwnd, 0);
5494 insert_item(hwnd, 0);
5495 insert_item(hwnd, 0);
5496
5497 g_focus_test_LVN_DELETEITEM = TRUE;
5498
5499 /* delete focused item (not the last index) */
5500 item.stateMask = LVIS_FOCUSED;
5501 item.state = LVIS_FOCUSED;
5502 ret = SendMessageA(hwnd, LVM_SETITEMSTATE, 2, (LPARAM)&item);
5503 ok(ret == TRUE, "got %d\n", ret);
5504 ret = SendMessageA(hwnd, LVM_DELETEITEM, 2, 0);
5505 ok(ret == TRUE, "got %d\n", ret);
5506 /* next item gets focus */
5507 state = SendMessageA(hwnd, LVM_GETITEMSTATE, 2, LVIS_FOCUSED);
5508 ok(state == LVIS_FOCUSED, "got %x\n", state);
5509
5510 /* focus last item and delete it */
5511 item.stateMask = LVIS_FOCUSED;
5512 item.state = LVIS_FOCUSED;
5513 ret = SendMessageA(hwnd, LVM_SETITEMSTATE, 3, (LPARAM)&item);
5514 ok(ret == TRUE, "got %d\n", ret);
5515 ret = SendMessageA(hwnd, LVM_DELETEITEM, 3, 0);
5516 ok(ret == TRUE, "got %d\n", ret);
5517 /* new last item gets focus */
5518 state = SendMessageA(hwnd, LVM_GETITEMSTATE, 2, LVIS_FOCUSED);
5519 ok(state == LVIS_FOCUSED, "got %x\n", state);
5520
5521 /* focus first item and delete it */
5522 item.stateMask = LVIS_FOCUSED;
5523 item.state = LVIS_FOCUSED;
5524 ret = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
5525 ok(ret == TRUE, "got %d\n", ret);
5526 ret = SendMessageA(hwnd, LVM_DELETEITEM, 0, 0);
5527 ok(ret == TRUE, "got %d\n", ret);
5528 /* new first item gets focus */
5529 state = SendMessageA(hwnd, LVM_GETITEMSTATE, 0, LVIS_FOCUSED);
5530 ok(state == LVIS_FOCUSED, "got %x\n", state);
5531
5532 g_focus_test_LVN_DELETEITEM = FALSE;
5533
5534 DestroyWindow(hwnd);
5535 }
5536
5537 static void test_insertitem(void)
5538 {
5539 LVITEMA item;
5540 UINT state;
5541 HWND hwnd;
5542 INT ret;
5543
5544 hwnd = create_listview_control(LVS_REPORT);
5545
5546 /* insert item 0 focused */
5547 item.mask = LVIF_STATE;
5548 item.state = LVIS_FOCUSED;
5549 item.stateMask = LVIS_FOCUSED;
5550 item.iItem = 0;
5551 item.iSubItem = 0;
5552 ret = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
5553 ok(ret == 0, "got %d\n", ret);
5554
5555 state = SendMessageA(hwnd, LVM_GETITEMSTATE, 0, LVIS_FOCUSED);
5556 ok(state == LVIS_FOCUSED, "got %x\n", state);
5557
5558 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5559
5560 /* insert item 1, focus shift */
5561 item.mask = LVIF_STATE;
5562 item.state = LVIS_FOCUSED;
5563 item.stateMask = LVIS_FOCUSED;
5564 item.iItem = 1;
5565 item.iSubItem = 0;
5566 ret = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
5567 ok(ret == 1, "got %d\n", ret);
5568
5569 ok_sequence(sequences, PARENT_SEQ_INDEX, parent_insert_focused_seq, "insert focused", TRUE);
5570
5571 state = SendMessageA(hwnd, LVM_GETITEMSTATE, 1, LVIS_FOCUSED);
5572 ok(state == LVIS_FOCUSED, "got %x\n", state);
5573
5574 /* insert item 2, no focus shift */
5575 item.mask = LVIF_STATE;
5576 item.state = 0;
5577 item.stateMask = LVIS_FOCUSED;
5578 item.iItem = 2;
5579 item.iSubItem = 0;
5580 ret = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
5581 ok(ret == 2, "got %d\n", ret);
5582
5583 state = SendMessageA(hwnd, LVM_GETITEMSTATE, 1, LVIS_FOCUSED);
5584 ok(state == LVIS_FOCUSED, "got %x\n", state);
5585
5586 DestroyWindow(hwnd);
5587 }
5588
5589 START_TEST(listview)
5590 {
5591 HMODULE hComctl32;
5592 BOOL (WINAPI *pInitCommonControlsEx)(const INITCOMMONCONTROLSEX*);
5593
5594 ULONG_PTR ctx_cookie;
5595 HANDLE hCtx;
5596
5597 hComctl32 = GetModuleHandleA("comctl32.dll");
5598 pInitCommonControlsEx = (void*)GetProcAddress(hComctl32, "InitCommonControlsEx");
5599 if (pInitCommonControlsEx)
5600 {
5601 INITCOMMONCONTROLSEX iccex;
5602 iccex.dwSize = sizeof(iccex);
5603 iccex.dwICC = ICC_LISTVIEW_CLASSES;
5604 pInitCommonControlsEx(&iccex);
5605 }
5606 else
5607 InitCommonControls();
5608
5609 init_msg_sequences(sequences, NUM_MSG_SEQUENCES);
5610
5611 hwndparent = create_parent_window(FALSE);
5612 flush_sequences(sequences, NUM_MSG_SEQUENCES);
5613
5614 g_is_below_5 = is_below_comctl_5();
5615
5616 test_header_notification();
5617 test_header_notification2();
5618 test_images();
5619 test_checkboxes();
5620 test_items();
5621 test_create();
5622 test_redraw();
5623 test_customdraw();
5624 test_icon_spacing();
5625 test_color();
5626 test_item_count();
5627 test_item_position();
5628 test_columns();
5629 test_getorigin();
5630 test_multiselect();
5631 test_getitemrect();
5632 test_subitem_rect();
5633 test_sorting();
5634 test_ownerdata();
5635 test_norecompute();
5636 test_nosortheader();
5637 test_setredraw();
5638 test_hittest();
5639 test_getviewrect();
5640 test_getitemposition();
5641 test_columnscreation();
5642 test_editbox();
5643 test_notifyformat();
5644 test_indentation();
5645 test_getitemspacing();
5646 test_getcolumnwidth();
5647 test_approximate_viewrect();
5648 test_finditem();
5649 test_hover();
5650 test_destroynotify();
5651 test_createdragimage();
5652 test_dispinfo();
5653 test_LVM_SETITEMTEXT();
5654 test_imagelists();
5655 test_deleteitem();
5656 test_insertitem();
5657
5658 if (!load_v6_module(&ctx_cookie, &hCtx))
5659 {
5660 DestroyWindow(hwndparent);
5661 return;
5662 }
5663
5664 /* comctl32 version 6 tests start here */
5665 test_get_set_view();
5666 test_canceleditlabel();
5667 test_mapidindex();
5668 test_scrollnotify();
5669 test_LVS_EX_TRANSPARENTBKGND();
5670 test_LVS_EX_HEADERINALLVIEWS();
5671 test_deleteitem();
5672 test_multiselect();
5673 test_insertitem();
5674
5675 unload_v6_module(ctx_cookie, hCtx);
5676
5677 DestroyWindow(hwndparent);
5678 }