1502970ad9bbd09e167e1b33614d8c1887189496
[reactos.git] / rostests / winetests / comctl32 / header.c
1 /* Unit test suite for header control.
2 *
3 * Copyright 2005 Vijay Kiran Kamuju
4 * Copyright 2007 Shanren Zhou
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 */
20
21 #define WIN32_NO_STATUS
22 #define _INC_WINDOWS
23 #define COM_NO_WINDOWS_H
24
25 //#include <windows.h>
26 #include <stdarg.h>
27 #include <windef.h>
28 #include <winbase.h>
29 #include <wingdi.h>
30 #include <winnls.h>
31 #include <objbase.h>
32 #include <commctrl.h>
33 #include <assert.h>
34
35 #include <wine/test.h>
36 #include "v6util.h"
37 #include "msg.h"
38
39 typedef struct tagEXPECTEDNOTIFY
40 {
41 INT iCode;
42 BOOL fUnicode;
43 HDITEMA hdItem;
44 } EXPECTEDNOTIFY;
45
46 typedef LRESULT (*CUSTOMDRAWPROC)(int n, NMCUSTOMDRAW *nm);
47
48 static CUSTOMDRAWPROC g_CustomDrawProc;
49 static int g_CustomDrawCount;
50 static DRAWITEMSTRUCT g_DrawItem;
51 static BOOL g_DrawItemReceived;
52 static DWORD g_customheight;
53
54 static EXPECTEDNOTIFY expectedNotify[10];
55 static INT nExpectedNotify = 0;
56 static INT nReceivedNotify = 0;
57 static INT unexpectedNotify[10];
58 static INT nUnexpectedNotify = 0;
59
60 static HWND hHeaderParentWnd;
61 static HWND hWndHeader;
62 #define MAX_CHARS 100
63
64 #define compare(val, exp, fmt) ok((val) == (exp), #val " value: " fmt ", expected: " fmt "\n", (val), (exp))
65
66 #define expect(expected, got) ok(expected == got, "expected %d, got %d\n", expected,got)
67
68 #define NUM_MSG_SEQUENCES 2
69 #define PARENT_SEQ_INDEX 0
70 #define HEADER_SEQ_INDEX 1
71
72 static struct msg_sequence *sequences[NUM_MSG_SEQUENCES];
73
74 static const struct message create_parent_wnd_seq[] = {
75 { WM_GETMINMAXINFO, sent },
76 { WM_NCCREATE, sent },
77 { WM_NCCALCSIZE, sent|wparam, 0 },
78 { WM_CREATE, sent },
79 { 0 }
80 };
81
82 static const struct message add_header_to_parent_seq_interactive[] = {
83 { WM_NOTIFYFORMAT, sent|lparam, 0, NF_QUERY },
84 { WM_QUERYUISTATE, sent },
85 { WM_PARENTNOTIFY, sent|wparam, 1 },
86 { WM_SHOWWINDOW, sent|wparam, 1 },
87 { WM_WINDOWPOSCHANGING, sent|wparam, 0 },
88 { WM_WINDOWPOSCHANGING, sent|wparam, 0 },
89 { WM_ACTIVATEAPP, sent|wparam, 1 },
90 { WM_NCACTIVATE, sent|wparam, 1 },
91 { WM_ACTIVATE, sent|wparam, 1 },
92 { WM_IME_SETCONTEXT, sent|defwinproc|wparam, 1 },
93 { WM_IME_NOTIFY, sent|defwinproc|wparam, 2 },
94 { WM_SETFOCUS, sent|defwinproc|wparam, 0 },
95 { WM_WINDOWPOSCHANGED, sent|wparam, 0 },
96 { WM_SIZE, sent|wparam, 0 },
97 { WM_MOVE, sent|wparam, 0 },
98 { 0 }
99 };
100
101 static const struct message add_header_to_parent_seq[] = {
102 { WM_NOTIFYFORMAT, sent|lparam, 0, NF_QUERY },
103 { WM_QUERYUISTATE, sent|optional },
104 { WM_PARENTNOTIFY, sent },
105 { 0 }
106 };
107
108 static const struct message insertItem_seq[] = {
109 { HDM_INSERTITEM, sent|wparam, 0 },
110 { HDM_INSERTITEM, sent|wparam, 1 },
111 { HDM_INSERTITEM, sent|wparam, 2 },
112 { HDM_INSERTITEM, sent|wparam, 3 },
113 { 0 }
114 };
115
116 static const struct message getItem_seq[] = {
117 { HDM_GETITEM, sent|wparam, 3 },
118 { HDM_GETITEM, sent|wparam, 0 },
119 { 0 }
120 };
121
122
123 static const struct message deleteItem_getItemCount_seq[] = {
124 { HDM_DELETEITEM, sent|wparam, 3 },
125 { HDM_GETITEMCOUNT, sent },
126 { HDM_DELETEITEM, sent|wparam, 3 },
127 { HDM_GETITEMCOUNT, sent },
128 { HDM_DELETEITEM, sent|wparam, 2 },
129 { HDM_GETITEMCOUNT, sent },
130 { 0 }
131 };
132
133 static const struct message orderArray_seq[] = {
134 { HDM_SETORDERARRAY, sent|wparam, 2 },
135 { HDM_GETORDERARRAY, sent|wparam, 2 },
136 { 0 }
137 };
138
139 static const struct message setItem_seq[] = {
140 { HDM_SETITEM, sent|wparam, 0 },
141 { HDM_SETITEM, sent|wparam, 1 },
142 { 0 }
143 };
144
145 static const struct message getItemRect_seq[] = {
146 { HDM_GETITEMRECT, sent|wparam, 1 },
147 { HDM_GETITEMRECT, sent|wparam, 0 },
148 { HDM_GETITEMRECT, sent|wparam, 10 },
149 { 0 }
150 };
151
152 static const struct message layout_seq[] = {
153 { HDM_LAYOUT, sent },
154 { 0 }
155 };
156
157 static const struct message orderToIndex_seq[] = {
158 { HDM_ORDERTOINDEX, sent|wparam, 1 },
159 { 0 }
160 };
161
162 static const struct message hittest_seq[] = {
163 { HDM_HITTEST, sent },
164 { HDM_HITTEST, sent },
165 { HDM_HITTEST, sent },
166 { 0 }
167 };
168
169 static const struct message setHotDivider_seq_interactive[] = {
170 { HDM_SETHOTDIVIDER, sent|wparam, TRUE },
171 { WM_PAINT, sent|defwinproc},
172 { WM_NCPAINT, sent|defwinproc},
173 { WM_ERASEBKGND, sent|defwinproc},
174 { HDM_SETHOTDIVIDER, sent|wparam|lparam, FALSE, 100 },
175 { WM_PAINT, sent|defwinproc},
176 { HDM_SETHOTDIVIDER, sent|wparam|lparam, FALSE, 1},
177 { WM_PAINT, sent|defwinproc},
178 { 0 }
179 };
180
181 static const struct message setHotDivider_seq_noninteractive[] = {
182 { HDM_SETHOTDIVIDER, sent|wparam, TRUE },
183 { HDM_SETHOTDIVIDER, sent|wparam|lparam, FALSE, 100 },
184 { HDM_SETHOTDIVIDER, sent|wparam|lparam, FALSE, 1},
185 { 0 }
186 };
187
188 static const struct message imageMessages_seq[] = {
189 { HDM_SETIMAGELIST, sent },
190 { HDM_GETIMAGELIST, sent },
191 { HDM_CREATEDRAGIMAGE, sent },
192 { 0 }
193 };
194
195 static const struct message filterMessages_seq_interactive[] = {
196 { HDM_SETFILTERCHANGETIMEOUT, sent|wparam|lparam, 1, 100 },
197 { HDM_CLEARFILTER, sent|wparam|lparam, 0, 1 },
198 { HDM_EDITFILTER, sent|wparam|lparam, 1, 0 },
199 { WM_PARENTNOTIFY, sent|wparam|defwinproc, WM_CREATE },
200 { WM_CTLCOLOREDIT, sent|defwinproc },
201 { WM_COMMAND, sent|defwinproc },
202 { 0 }
203 };
204
205 static const struct message filterMessages_seq_noninteractive[] = {
206 { HDM_SETFILTERCHANGETIMEOUT, sent|wparam|lparam, 1, 100 },
207 { HDM_CLEARFILTER, sent|wparam|lparam, 0, 1 },
208 { HDM_EDITFILTER, sent|wparam|lparam, 1, 0 },
209 { WM_PARENTNOTIFY, sent|wparam|defwinproc|optional, WM_CREATE },
210 { WM_COMMAND, sent|defwinproc|optional },
211 { 0 }
212 };
213
214 static const struct message unicodeformatMessages_seq[] = {
215 { HDM_SETUNICODEFORMAT, sent|wparam, TRUE },
216 { HDM_GETUNICODEFORMAT, sent },
217 { 0 }
218 };
219
220 static const struct message bitmapmarginMessages_seq[] = {
221 { HDM_GETBITMAPMARGIN, sent },
222 { 0 }
223 };
224
225
226 static void expect_notify(INT iCode, BOOL fUnicode, HDITEMA *lpItem)
227 {
228 assert(nExpectedNotify < 10);
229 expectedNotify[nExpectedNotify].iCode = iCode;
230 expectedNotify[nExpectedNotify].fUnicode = fUnicode;
231 expectedNotify[nExpectedNotify].hdItem = *lpItem;
232 nExpectedNotify++;
233 }
234
235 static void dont_expect_notify(INT iCode)
236 {
237 assert(nUnexpectedNotify < 10);
238 unexpectedNotify[nUnexpectedNotify++] = iCode;
239 }
240
241 static BOOL notifies_received(void)
242 {
243 BOOL fRet = (nExpectedNotify == nReceivedNotify);
244 nExpectedNotify = nReceivedNotify = 0;
245 nUnexpectedNotify = 0;
246 return fRet;
247 }
248
249 static LONG addItem(HWND hdex, int idx, LPSTR text)
250 {
251 HDITEMA hdItem;
252 hdItem.mask = HDI_TEXT | HDI_WIDTH;
253 hdItem.cxy = 100;
254 hdItem.pszText = text;
255 hdItem.cchTextMax = 0;
256 return SendMessage(hdex, HDM_INSERTITEMA, idx, (LPARAM)&hdItem);
257 }
258
259 static LONG setItem(HWND hdex, int idx, LPSTR text, BOOL fCheckNotifies)
260 {
261 LONG ret;
262 HDITEMA hdexItem;
263 hdexItem.mask = HDI_TEXT;
264 hdexItem.pszText = text;
265 hdexItem.cchTextMax = 0;
266 if (fCheckNotifies)
267 {
268 expect_notify(HDN_ITEMCHANGINGA, FALSE, &hdexItem);
269 expect_notify(HDN_ITEMCHANGEDA, FALSE, &hdexItem);
270 }
271 ret = SendMessage(hdex, HDM_SETITEMA, idx, (LPARAM)&hdexItem);
272 if (fCheckNotifies)
273 ok(notifies_received(), "setItem(): not all expected notifies were received\n");
274 return ret;
275 }
276
277 static LONG setItemUnicodeNotify(HWND hdex, int idx, LPSTR text, LPWSTR wText)
278 {
279 LONG ret;
280 HDITEMA hdexItem;
281 HDITEMW hdexNotify;
282 hdexItem.mask = HDI_TEXT;
283 hdexItem.pszText = text;
284 hdexItem.cchTextMax = 0;
285
286 hdexNotify.mask = HDI_TEXT;
287 hdexNotify.pszText = wText;
288
289 expect_notify(HDN_ITEMCHANGINGW, TRUE, (HDITEMA*)&hdexNotify);
290 expect_notify(HDN_ITEMCHANGEDW, TRUE, (HDITEMA*)&hdexNotify);
291 ret = SendMessage(hdex, HDM_SETITEMA, idx, (LPARAM)&hdexItem);
292 ok(notifies_received(), "setItemUnicodeNotify(): not all expected notifies were received\n");
293 return ret;
294 }
295
296 static LONG delItem(HWND hdex, int idx)
297 {
298 return SendMessage(hdex, HDM_DELETEITEM, idx, 0);
299 }
300
301 static LONG getItemCount(HWND hdex)
302 {
303 return SendMessage(hdex, HDM_GETITEMCOUNT, 0, 0);
304 }
305
306 static LONG getItem(HWND hdex, int idx, LPSTR textBuffer)
307 {
308 HDITEMA hdItem;
309 hdItem.mask = HDI_TEXT;
310 hdItem.pszText = textBuffer;
311 hdItem.cchTextMax = MAX_CHARS;
312 return SendMessage(hdex, HDM_GETITEMA, idx, (LPARAM)&hdItem);
313 }
314
315 static void addReadDelItem(HWND hdex, HDITEMA *phdiCreate, int maskRead, HDITEMA *phdiRead)
316 {
317 ok(SendMessage(hdex, HDM_INSERTITEMA, 0, (LPARAM)phdiCreate)!=-1, "Adding item failed\n");
318 ZeroMemory(phdiRead, sizeof(HDITEMA));
319 phdiRead->mask = maskRead;
320 ok(SendMessage(hdex, HDM_GETITEMA, 0, (LPARAM)phdiRead)!=0, "Getting item data failed\n");
321 ok(SendMessage(hdex, HDM_DELETEITEM, 0, 0)!=0, "Deleting item failed\n");
322 }
323
324 static HWND create_header_control (void)
325 {
326 HWND handle;
327 HDLAYOUT hlayout;
328 RECT rectwin;
329 WINDOWPOS winpos;
330
331 handle = CreateWindowEx(0, WC_HEADER, NULL,
332 WS_CHILD|WS_BORDER|WS_VISIBLE|HDS_BUTTONS|HDS_HORZ,
333 0, 0, 0, 0,
334 hHeaderParentWnd, NULL, NULL, NULL);
335 assert(handle);
336
337 if (winetest_interactive)
338 ShowWindow (hHeaderParentWnd, SW_SHOW);
339
340 GetClientRect(hHeaderParentWnd,&rectwin);
341 hlayout.prc = &rectwin;
342 hlayout.pwpos = &winpos;
343 SendMessageA(handle,HDM_LAYOUT,0,(LPARAM) &hlayout);
344 SetWindowPos(handle, winpos.hwndInsertAfter, winpos.x, winpos.y,
345 winpos.cx, winpos.cy, 0);
346
347 return handle;
348 }
349
350 static void compare_items(INT iCode, HDITEMA *hdi1, HDITEMA *hdi2, BOOL fUnicode)
351 {
352 ok(hdi1->mask == hdi2->mask, "Notify %d mask mismatch (%08x != %08x)\n", iCode, hdi1->mask, hdi2->mask);
353 if (hdi1->mask & HDI_WIDTH)
354 {
355 ok(hdi1->cxy == hdi2->cxy, "Notify %d cxy mismatch (%08x != %08x)\n", iCode, hdi1->cxy, hdi2->cxy);
356 }
357 if (hdi1->mask & HDI_TEXT)
358 {
359 if (hdi1->pszText == LPSTR_TEXTCALLBACKA)
360 {
361 ok(hdi1->pszText == LPSTR_TEXTCALLBACKA, "Notify %d - only one item is LPSTR_TEXTCALLBACK\n", iCode);
362 }
363 else
364 if (fUnicode)
365 {
366 char buf1[260];
367 char buf2[260];
368 WideCharToMultiByte(CP_ACP, 0, (LPCWSTR)hdi1->pszText, -1, buf1, 260, NULL, NULL);
369 WideCharToMultiByte(CP_ACP, 0, (LPCWSTR)hdi2->pszText, -1, buf2, 260, NULL, NULL);
370 ok(lstrcmpW((LPWSTR)hdi1->pszText, (LPWSTR)hdi2->pszText)==0,
371 "Notify %d text mismatch (L\"%s\" vs L\"%s\")\n",
372 iCode, buf1, buf2);
373 }
374 else
375 {
376 ok(strcmp(hdi1->pszText, hdi2->pszText)==0,
377 "Notify %d text mismatch (\"%s\" vs \"%s\")\n",
378 iCode, hdi1->pszText, hdi2->pszText);
379 }
380 }
381 }
382
383 static char pszFirstItem[] = "First Item";
384 static char pszSecondItem[] = "Second Item";
385 static char pszThirdItem[] = "Third Item";
386 static char pszFourthItem[] = "Fourth Item";
387 static char pszReplaceItem[] = "Replace Item";
388 static char pszOutOfRangeItem[] = "Out Of Range Item";
389
390 static char *str_items[] =
391 {pszFirstItem, pszSecondItem, pszThirdItem, pszFourthItem, pszReplaceItem, pszOutOfRangeItem};
392
393 static char pszUniTestA[] = "TST";
394 static WCHAR pszUniTestW[] = {'T','S','T',0};
395
396
397 #define TEST_GET_ITEM(i,c)\
398 { res = getItem(hWndHeader, i, buffer);\
399 ok(res != 0, "Getting item[%d] using valid index failed unexpectedly (%d)\n", i, res);\
400 ok(strcmp(str_items[c], buffer) == 0, "Getting item[%d] returned \"%s\" expecting \"%s\"\n", i, buffer, str_items[c]);\
401 }
402
403 #define TEST_GET_ITEMCOUNT(i)\
404 { res = getItemCount(hWndHeader);\
405 ok(res == i, "Got Item Count as %d\n", res);\
406 }
407
408 static LRESULT WINAPI header_subclass_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
409 {
410 WNDPROC oldproc = (WNDPROC)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
411 static LONG defwndproc_counter = 0;
412 LRESULT ret;
413 struct message msg;
414
415 msg.message = message;
416 msg.flags = sent|wparam|lparam;
417 if (defwndproc_counter) msg.flags |= defwinproc;
418 msg.wParam = wParam;
419 msg.lParam = lParam;
420 msg.id = 0;
421 add_message(sequences, HEADER_SEQ_INDEX, &msg);
422
423 defwndproc_counter++;
424 ret = CallWindowProcA(oldproc, hwnd, message, wParam, lParam);
425 defwndproc_counter--;
426
427 return ret;
428 }
429
430 static LRESULT WINAPI parent_wnd_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
431 {
432 static LONG defwndproc_counter = 0;
433 LRESULT ret;
434 struct message msg;
435
436 /* do not log painting messages */
437 if (message != WM_PAINT &&
438 message != WM_ERASEBKGND &&
439 message != WM_NCPAINT &&
440 message != WM_NCHITTEST &&
441 message != WM_GETTEXT &&
442 message != WM_GETICON &&
443 message != WM_DEVICECHANGE)
444
445 {
446 msg.message = message;
447 msg.flags = sent|wparam|lparam;
448 if (defwndproc_counter) msg.flags |= defwinproc;
449 msg.wParam = wParam;
450 msg.lParam = lParam;
451 add_message(sequences, PARENT_SEQ_INDEX, &msg);
452 }
453
454 defwndproc_counter++;
455 ret = DefWindowProcA(hwnd, message, wParam, lParam);
456 defwndproc_counter--;
457
458 return ret;
459 }
460
461 static BOOL register_parent_wnd_class(void)
462 {
463 WNDCLASSA cls;
464
465 cls.style = 0;
466 cls.lpfnWndProc = parent_wnd_proc;
467 cls.cbClsExtra = 0;
468 cls.cbWndExtra = 0;
469 cls.hInstance = GetModuleHandleA(NULL);
470 cls.hIcon = 0;
471 cls.hCursor = LoadCursorA(0, IDC_ARROW);
472 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
473 cls.lpszMenuName = NULL;
474 cls.lpszClassName = "Header test parent class";
475 return RegisterClassA(&cls);
476 }
477
478 static HWND create_custom_parent_window(void)
479 {
480 if (!register_parent_wnd_class())
481 return NULL;
482
483 return CreateWindowExA(0, "Header test parent class", "Header Message Sequence Testing",
484 WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT,
485 672+2*GetSystemMetrics(SM_CXSIZEFRAME),
486 226+GetSystemMetrics(SM_CYCAPTION)+2*GetSystemMetrics(SM_CYSIZEFRAME),
487 NULL, NULL, GetModuleHandleA(NULL), 0);
488 }
489
490 static HWND create_custom_header_control(HWND hParent, BOOL preloadHeaderItems)
491 {
492 WNDPROC oldproc;
493 HWND childHandle;
494 HDLAYOUT hlayout;
495 RECT rectwin;
496 WINDOWPOS winpos;
497 int retVal;
498 int loopcnt;
499 static char firstHeaderItem[] = "Name";
500 static char secondHeaderItem[] = "Size";
501 static char *items[] = {secondHeaderItem, firstHeaderItem};
502 HDITEM hdItem;
503 hdItem.mask = HDI_TEXT | HDI_WIDTH | HDI_FORMAT;
504 hdItem.fmt = HDF_LEFT;
505 hdItem.cxy = 80;
506 hdItem.cchTextMax = 260;
507
508
509 flush_sequences(sequences, NUM_MSG_SEQUENCES);
510
511 childHandle = CreateWindowEx(0, WC_HEADER, NULL,
512 WS_CHILD|WS_BORDER|WS_VISIBLE|HDS_BUTTONS|HDS_HORZ,
513 0, 0, 0, 0,
514 hParent, NULL, NULL, NULL);
515 assert(childHandle);
516 if (preloadHeaderItems)
517 {
518 for ( loopcnt = 0 ; loopcnt < 2 ; loopcnt++ )
519 {
520 hdItem.pszText = items[loopcnt];
521 retVal = SendMessage(childHandle, HDM_INSERTITEM, loopcnt, (LPARAM) &hdItem);
522 ok(retVal == loopcnt, "Adding item %d failed with return value %d\n", ( loopcnt + 1 ), retVal);
523 }
524 }
525
526 if (winetest_interactive)
527 ShowWindow (hParent, SW_SHOW);
528
529 GetClientRect(hParent,&rectwin);
530 hlayout.prc = &rectwin;
531 hlayout.pwpos = &winpos;
532 SendMessageA(childHandle,HDM_LAYOUT,0,(LPARAM) &hlayout);
533 SetWindowPos(childHandle, winpos.hwndInsertAfter, winpos.x, winpos.y,
534 winpos.cx, winpos.cy, 0);
535
536 oldproc = (WNDPROC)SetWindowLongPtrA(childHandle, GWLP_WNDPROC,
537 (LONG_PTR)header_subclass_proc);
538 SetWindowLongPtrA(childHandle, GWLP_USERDATA, (LONG_PTR)oldproc);
539 return childHandle;
540 }
541
542 static void check_auto_format(void)
543 {
544 HDITEMA hdiCreate;
545 HDITEMA hdiRead;
546 static CHAR text[] = "Test";
547 ZeroMemory(&hdiCreate, sizeof(HDITEMA));
548
549 /* Windows implicitly sets some format bits in INSERTITEM */
550
551 /* HDF_STRING is automatically set and cleared for no text */
552 hdiCreate.mask = HDI_TEXT|HDI_WIDTH|HDI_FORMAT;
553 hdiCreate.pszText = text;
554 hdiCreate.cxy = 100;
555 hdiCreate.fmt=HDF_CENTER;
556 addReadDelItem(hWndHeader, &hdiCreate, HDI_FORMAT, &hdiRead);
557 ok(hdiRead.fmt == (HDF_STRING|HDF_CENTER), "HDF_STRING not set automatically (fmt=%x)\n", hdiRead.fmt);
558
559 hdiCreate.mask = HDI_WIDTH|HDI_FORMAT;
560 hdiCreate.pszText = text;
561 hdiCreate.fmt = HDF_CENTER|HDF_STRING;
562 addReadDelItem(hWndHeader, &hdiCreate, HDI_FORMAT, &hdiRead);
563 ok(hdiRead.fmt == (HDF_CENTER), "HDF_STRING should be automatically cleared (fmt=%x)\n", hdiRead.fmt);
564
565 /* HDF_BITMAP is automatically set and cleared for a NULL bitmap or no bitmap */
566 hdiCreate.mask = HDI_BITMAP|HDI_WIDTH|HDI_FORMAT;
567 hdiCreate.hbm = CreateBitmap(16, 16, 1, 8, NULL);
568 hdiCreate.fmt = HDF_CENTER;
569 addReadDelItem(hWndHeader, &hdiCreate, HDI_FORMAT, &hdiRead);
570 ok(hdiRead.fmt == (HDF_BITMAP|HDF_CENTER), "HDF_BITMAP not set automatically (fmt=%x)\n", hdiRead.fmt);
571 DeleteObject(hdiCreate.hbm);
572
573 hdiCreate.hbm = NULL;
574 hdiCreate.fmt = HDF_CENTER|HDF_BITMAP;
575 addReadDelItem(hWndHeader, &hdiCreate, HDI_FORMAT, &hdiRead);
576 ok(hdiRead.fmt == HDF_CENTER, "HDF_BITMAP not cleared automatically for NULL bitmap (fmt=%x)\n", hdiRead.fmt);
577
578 hdiCreate.mask = HDI_WIDTH|HDI_FORMAT;
579 hdiCreate.fmt = HDF_CENTER|HDF_BITMAP;
580 addReadDelItem(hWndHeader, &hdiCreate, HDI_FORMAT, &hdiRead);
581 ok(hdiRead.fmt == HDF_CENTER, "HDF_BITMAP not cleared automatically for no bitmap (fmt=%x)\n", hdiRead.fmt);
582
583 /* HDF_IMAGE is automatically set but not cleared */
584 hdiCreate.mask = HDI_IMAGE|HDI_WIDTH|HDI_FORMAT;
585 hdiCreate.iImage = 17;
586 addReadDelItem(hWndHeader, &hdiCreate, HDI_FORMAT, &hdiRead);
587 ok(hdiRead.fmt == (HDF_IMAGE|HDF_CENTER), "HDF_IMAGE not set automatically (fmt=%x)\n", hdiRead.fmt);
588
589 hdiCreate.mask = HDI_WIDTH|HDI_FORMAT;
590 hdiCreate.fmt = HDF_CENTER|HDF_IMAGE;
591 hdiCreate.iImage = 0;
592 addReadDelItem(hWndHeader, &hdiCreate, HDI_FORMAT, &hdiRead);
593 ok(hdiRead.fmt == (HDF_CENTER|HDF_IMAGE), "HDF_IMAGE shouldn't be cleared automatically (fmt=%x)\n", hdiRead.fmt);
594 }
595
596 static void check_auto_fields(void)
597 {
598 HDITEMA hdiCreate;
599 HDITEMA hdiRead;
600 static CHAR text[] = "Test";
601 LONG res;
602
603 /* Windows stores the format, width, lparam even if they are not in the item's mask */
604 ZeroMemory(&hdiCreate, sizeof(HDITEMA));
605 hdiCreate.mask = HDI_TEXT;
606 hdiCreate.cxy = 100;
607 hdiCreate.pszText = text;
608 addReadDelItem(hWndHeader, &hdiCreate, HDI_WIDTH, &hdiRead);
609 TEST_GET_ITEMCOUNT(6);
610 ok(hdiRead.cxy == hdiCreate.cxy, "cxy should be automatically set\n");
611
612 ZeroMemory(&hdiCreate, sizeof(HDITEMA));
613 hdiCreate.mask = HDI_TEXT;
614 hdiCreate.pszText = text;
615 hdiCreate.lParam = 0x12345678;
616 addReadDelItem(hWndHeader, &hdiCreate, HDI_LPARAM, &hdiRead);
617 TEST_GET_ITEMCOUNT(6);
618 ok(hdiRead.lParam == hdiCreate.lParam, "lParam should be automatically set\n");
619
620 ZeroMemory(&hdiCreate, sizeof(HDITEMA));
621 hdiCreate.mask = HDI_TEXT;
622 hdiCreate.pszText = text;
623 hdiCreate.fmt = HDF_STRING|HDF_CENTER;
624 addReadDelItem(hWndHeader, &hdiCreate, HDI_FORMAT, &hdiRead);
625 TEST_GET_ITEMCOUNT(6);
626 ok(hdiRead.fmt == hdiCreate.fmt, "fmt should be automatically set\n");
627
628 /* others fields are not set */
629 ZeroMemory(&hdiCreate, sizeof(HDITEMA));
630 hdiCreate.mask = HDI_TEXT;
631 hdiCreate.pszText = text;
632 hdiCreate.hbm = CreateBitmap(16, 16, 1, 8, NULL);
633 addReadDelItem(hWndHeader, &hdiCreate, HDI_BITMAP, &hdiRead);
634 TEST_GET_ITEMCOUNT(6);
635 ok(hdiRead.hbm == NULL, "hbm should not be automatically set\n");
636 DeleteObject(hdiCreate.hbm);
637
638 ZeroMemory(&hdiCreate, sizeof(HDITEMA));
639 hdiCreate.mask = HDI_IMAGE;
640 hdiCreate.iImage = 17;
641 hdiCreate.pszText = text;
642 addReadDelItem(hWndHeader, &hdiCreate, HDI_TEXT, &hdiRead);
643 TEST_GET_ITEMCOUNT(6);
644 ok(hdiRead.pszText==NULL, "pszText shouldn't be automatically set\n");
645
646 /* field from comctl >4.0 not tested as the system probably won't touch them */
647 }
648
649 static void check_mask(void)
650 {
651 HDITEMA hdi;
652 static CHAR text[] = "ABC";
653 LRESULT ret;
654
655 /* don't create items if the mask is zero */
656 ZeroMemory(&hdi, sizeof(hdi));
657 hdi.mask = 0;
658 hdi.cxy = 200;
659 hdi.pszText = text;
660 hdi.fmt = 0;
661 hdi.iOrder = 0;
662 hdi.lParam = 17;
663 hdi.cchTextMax = 260;
664 ret = SendMessage(hWndHeader, HDM_INSERTITEM, 0, (LPARAM)&hdi);
665 ok(ret == -1, "Creating an item with a zero mask should have failed\n");
666 if (ret != -1) SendMessage(hWndHeader, HDM_DELETEITEM, 0, 0);
667
668 /* with a non-zero mask creation will succeed */
669 ZeroMemory(&hdi, sizeof(hdi));
670 hdi.mask = HDI_LPARAM;
671 ret = SendMessage(hWndHeader, HDM_INSERTITEM, 0, (LPARAM)&hdi);
672 ok(ret != -1, "Adding item with non-zero mask failed\n");
673 if (ret != -1)
674 SendMessage(hWndHeader, HDM_DELETEITEM, 0, 0);
675
676 /* in SETITEM if the mask contains a unknown bit, it is ignored */
677 ZeroMemory(&hdi, sizeof(hdi));
678 hdi.mask = 0x08000000 | HDI_LPARAM | HDI_IMAGE;
679 hdi.lParam = 133;
680 hdi.iImage = 17;
681 ret = SendMessage(hWndHeader, HDM_INSERTITEM, 0, (LPARAM)&hdi);
682 ok(ret != -1, "Adding item failed\n");
683
684 if (ret != -1)
685 {
686 /* check result */
687 ZeroMemory(&hdi, sizeof(hdi));
688 hdi.mask = HDI_LPARAM | HDI_IMAGE;
689 SendMessage(hWndHeader, HDM_GETITEM, 0, (LPARAM)&hdi);
690 ok(hdi.lParam == 133, "comctl32 4.0 field not set\n");
691 ok(hdi.iImage == 17, "comctl32 >4.0 field not set\n");
692
693 /* but in GETITEM if an unknown bit is set, comctl32 uses only version 4.0 fields */
694 ZeroMemory(&hdi, sizeof(hdi));
695 hdi.mask = 0x08000000 | HDI_LPARAM | HDI_IMAGE;
696 SendMessage(hWndHeader, HDM_GETITEM, 0, (LPARAM)&hdi);
697 ok(hdi.lParam == 133, "comctl32 4.0 field not read\n");
698 ok(hdi.iImage == 0, "comctl32 >4.0 field shouldn't be read\n");
699
700 SendMessage(hWndHeader, HDM_DELETEITEM, 0, 0);
701 }
702 }
703
704 static void test_header_control (void)
705 {
706 LONG res;
707 static char buffer[MAX_CHARS];
708 int i;
709
710 hWndHeader = create_header_control ();
711
712 for (i = 3; i >= 0; i--)
713 {
714 TEST_GET_ITEMCOUNT(3-i);
715 res = addItem(hWndHeader, 0, str_items[i]);
716 ok(res == 0, "Adding simple item failed (%d)\n", res);
717 }
718
719 TEST_GET_ITEMCOUNT(4);
720 res = addItem(hWndHeader, 99, str_items[i+1]);
721 ok(res != -1, "Adding Out of Range item should fail with -1 got (%d)\n", res);
722 TEST_GET_ITEMCOUNT(5);
723 res = addItem(hWndHeader, 5, str_items[i+1]);
724 ok(res != -1, "Adding Out of Range item should fail with -1 got (%d)\n", res);
725 TEST_GET_ITEMCOUNT(6);
726
727 for (i = 0; i < 4; i++) { TEST_GET_ITEM(i,i); TEST_GET_ITEMCOUNT(6); }
728
729 res=getItem(hWndHeader, 99, buffer);
730 ok(res == 0, "Getting Out of Range item should fail with 0 (%d), got %s\n", res,buffer);
731 res=getItem(hWndHeader, 5, buffer);
732 ok(res == 1, "Getting Out of Range item should fail with 1 (%d), got %s\n", res,buffer);
733 res=getItem(hWndHeader, -2, buffer);
734 ok(res == 0, "Getting Out of Range item should fail with 0 (%d), got %s\n", res,buffer);
735
736 if (winetest_interactive)
737 {
738 UpdateWindow(hHeaderParentWnd);
739 UpdateWindow(hWndHeader);
740 }
741
742 TEST_GET_ITEMCOUNT(6);
743 res=setItem(hWndHeader, 99, str_items[5], FALSE);
744 ok(res == 0, "Setting Out of Range item should fail with 0 (%d)\n", res);
745 res=setItem(hWndHeader, 5, str_items[5], TRUE);
746 ok(res == 1, "Setting Out of Range item should fail with 1 (%d)\n", res);
747 res=setItem(hWndHeader, -2, str_items[5], FALSE);
748 ok(res == 0, "Setting Out of Range item should fail with 0 (%d)\n", res);
749 TEST_GET_ITEMCOUNT(6);
750
751 for (i = 0; i < 4; i++)
752 {
753 res = setItem(hWndHeader, i, str_items[4], TRUE);
754 ok(res != 0, "Setting %d item failed (%d)\n", i+1, res);
755 TEST_GET_ITEM(i, 4);
756 TEST_GET_ITEMCOUNT(6);
757 }
758
759 SendMessageA(hWndHeader, HDM_SETUNICODEFORMAT, TRUE, 0);
760 setItemUnicodeNotify(hWndHeader, 3, pszUniTestA, pszUniTestW);
761 SendMessageA(hWndHeader, WM_NOTIFYFORMAT, (WPARAM)hHeaderParentWnd, NF_REQUERY);
762 setItem(hWndHeader, 3, str_items[4], TRUE);
763
764 dont_expect_notify(HDN_GETDISPINFOA);
765 dont_expect_notify(HDN_GETDISPINFOW);
766 addItem(hWndHeader, 0, LPSTR_TEXTCALLBACKA);
767 setItem(hWndHeader, 0, str_items[4], TRUE);
768 /* unexpected notifies cleared by notifies_received in setItem */
769 dont_expect_notify(HDN_GETDISPINFOA);
770 dont_expect_notify(HDN_GETDISPINFOW);
771 setItem(hWndHeader, 0, LPSTR_TEXTCALLBACKA, TRUE);
772 /* unexpected notifies cleared by notifies_received in setItem */
773 delItem(hWndHeader, 0);
774
775 check_auto_format();
776 TEST_GET_ITEMCOUNT(6);
777 check_auto_fields();
778 TEST_GET_ITEMCOUNT(6);
779 check_mask();
780 TEST_GET_ITEMCOUNT(6);
781
782 res = delItem(hWndHeader, 5);
783 ok(res == 1, "Deleting Out of Range item should fail with 1 (%d)\n", res);
784 res = delItem(hWndHeader, -2);
785 ok(res == 0, "Deleting Out of Range item should fail with 0 (%d)\n", res);
786 TEST_GET_ITEMCOUNT(5);
787
788 res = delItem(hWndHeader, 3);
789 ok(res != 0, "Deleting using out of range index failed (%d)\n", res);
790 TEST_GET_ITEMCOUNT(4);
791 res = delItem(hWndHeader, 0);
792 ok(res != 0, "Deleting using out of range index failed (%d)\n", res);
793 TEST_GET_ITEMCOUNT(3);
794 res = delItem(hWndHeader, 0);
795 ok(res != 0, "Deleting using out of range index failed (%d)\n", res);
796 TEST_GET_ITEMCOUNT(2);
797 res = delItem(hWndHeader, 0);
798 ok(res != 0, "Deleting using out of range index failed (%d)\n", res);
799 TEST_GET_ITEMCOUNT(1);
800
801 DestroyWindow(hWndHeader);
802 }
803
804 static void test_hdm_getitemrect(HWND hParent)
805 {
806
807 HWND hChild;
808 RECT rect;
809 int retVal;
810
811 flush_sequences(sequences, NUM_MSG_SEQUENCES);
812 hChild = create_custom_header_control(hParent, TRUE);
813 ok_sequence(sequences, PARENT_SEQ_INDEX, add_header_to_parent_seq,
814 "adder header control to parent", FALSE);
815
816 retVal = SendMessage(hChild, HDM_GETITEMRECT, 1, (LPARAM) &rect);
817 ok(retVal == TRUE, "Getting item rect should TRUE, got %d\n", retVal);
818 /* check bounding rectangle information of 2nd header item */
819 expect(80, rect.left);
820 expect(0, rect.top);
821 expect(160, rect.right);
822 expect(g_customheight, rect.bottom);
823
824 retVal = SendMessage(hChild, HDM_GETITEMRECT, 0, (LPARAM) &rect);
825
826 ok(retVal == TRUE, "Getting item rect should TRUE, got %d\n", retVal);
827 /* check bounding rectangle information of 1st header item */
828 expect(0, rect.left);
829 expect(0, rect.top);
830
831 expect(80, rect.right);
832 expect(g_customheight, rect.bottom);
833
834 retVal = SendMessage(hChild, HDM_GETITEMRECT, 10, (LPARAM) &rect);
835 ok(retVal == 0, "Getting rect of nonexistent item should return 0, got %d\n", retVal);
836
837 ok_sequence(sequences, HEADER_SEQ_INDEX, getItemRect_seq, "getItemRect sequence testing", FALSE);
838 DestroyWindow(hChild);
839 }
840
841 static void test_hdm_layout(HWND hParent)
842 {
843 HWND hChild;
844 int retVal;
845 RECT rect;
846 HDLAYOUT hdLayout;
847 WINDOWPOS windowPos;
848 hdLayout.prc = &rect;
849 hdLayout.pwpos = &windowPos;
850
851 flush_sequences(sequences, NUM_MSG_SEQUENCES);
852 hChild = create_custom_header_control(hParent, TRUE);
853 ok_sequence(sequences, PARENT_SEQ_INDEX, add_header_to_parent_seq,
854 "adder header control to parent", FALSE);
855
856 flush_sequences(sequences, NUM_MSG_SEQUENCES);
857 retVal = SendMessage(hChild, HDM_LAYOUT, 0, (LPARAM) &hdLayout);
858 expect(TRUE, retVal);
859
860 ok_sequence(sequences, HEADER_SEQ_INDEX, layout_seq, "layout sequence testing", FALSE);
861
862 DestroyWindow(hChild);
863 }
864
865 static void test_hdm_ordertoindex(HWND hParent)
866 {
867 HWND hChild;
868 int retVal;
869
870 flush_sequences(sequences, NUM_MSG_SEQUENCES);
871 hChild = create_custom_header_control(hParent, TRUE);
872 ok_sequence(sequences, PARENT_SEQ_INDEX, add_header_to_parent_seq,
873 "adder header control to parent", FALSE);
874
875 flush_sequences(sequences, NUM_MSG_SEQUENCES);
876 retVal = SendMessage(hChild, HDM_ORDERTOINDEX, 1, 0);
877 expect(1, retVal);
878
879 ok_sequence(sequences, HEADER_SEQ_INDEX, orderToIndex_seq, "orderToIndex sequence testing", FALSE);
880 DestroyWindow(hChild);
881 }
882
883 static void test_hdm_hittest(HWND hParent)
884 {
885 HWND hChild;
886 int retVal;
887 POINT pt;
888 HDHITTESTINFO hdHitTestInfo;
889 const int firstItemRightBoundary = 80;
890 const int secondItemRightBoundary = 160;
891 const int bottomBoundary = g_customheight;
892
893 pt.x = firstItemRightBoundary - 1;
894 pt.y = bottomBoundary - 1;
895 hdHitTestInfo.pt = pt;
896
897
898 flush_sequences(sequences, NUM_MSG_SEQUENCES);
899 hChild = create_custom_header_control(hParent, TRUE);
900 ok_sequence(sequences, PARENT_SEQ_INDEX, add_header_to_parent_seq,
901 "adder header control to parent", FALSE);
902
903 flush_sequences(sequences, NUM_MSG_SEQUENCES);
904 retVal = SendMessage(hChild, HDM_HITTEST, 0, (LPARAM) &hdHitTestInfo);
905 expect(0, retVal);
906 expect(0, hdHitTestInfo.iItem);
907 expect(HHT_ONDIVIDER, hdHitTestInfo.flags);
908
909 pt.x = secondItemRightBoundary - 1;
910 pt.y = bottomBoundary - 1;
911 hdHitTestInfo.pt = pt;
912 retVal = SendMessage(hChild, HDM_HITTEST, 1, (LPARAM) &hdHitTestInfo);
913 expect(1, retVal);
914 expect(1, hdHitTestInfo.iItem);
915 expect(HHT_ONDIVIDER, hdHitTestInfo.flags);
916
917 pt.x = secondItemRightBoundary;
918 pt.y = bottomBoundary + 1;
919 hdHitTestInfo.pt = pt;
920 retVal = SendMessage(hChild, HDM_HITTEST, 0, (LPARAM) &hdHitTestInfo);
921 expect(-1, retVal);
922 expect(-1, hdHitTestInfo.iItem);
923 expect(HHT_BELOW, hdHitTestInfo.flags);
924
925 ok_sequence(sequences, HEADER_SEQ_INDEX, hittest_seq, "hittest sequence testing", FALSE);
926
927 DestroyWindow(hChild);
928 }
929
930 static void test_hdm_sethotdivider(HWND hParent)
931 {
932 HWND hChild;
933 int retVal;
934 /* low word: x coordinate = 5
935 * high word: y coordinate = 5
936 */
937
938 flush_sequences(sequences, NUM_MSG_SEQUENCES);
939 hChild = create_custom_header_control(hParent, TRUE);
940 ok_sequence(sequences, PARENT_SEQ_INDEX, add_header_to_parent_seq,
941 "adder header control to parent", FALSE);
942
943 flush_sequences(sequences, NUM_MSG_SEQUENCES);
944 retVal = SendMessage(hChild, HDM_SETHOTDIVIDER, TRUE, MAKELPARAM(5, 5));
945 expect(0, retVal);
946
947 retVal = SendMessage(hChild, HDM_SETHOTDIVIDER, FALSE, 100);
948 expect(100, retVal);
949 retVal = SendMessage(hChild, HDM_SETHOTDIVIDER, FALSE, 1);
950 expect(1, retVal);
951 if (winetest_interactive)
952 ok_sequence(sequences, HEADER_SEQ_INDEX, setHotDivider_seq_interactive,
953 "setHotDivider sequence testing", TRUE);
954 else
955 ok_sequence(sequences, HEADER_SEQ_INDEX, setHotDivider_seq_noninteractive,
956 "setHotDivider sequence testing", FALSE);
957
958 DestroyWindow(hChild);
959 }
960
961 static void test_hdm_imageMessages(HWND hParent)
962 {
963 HIMAGELIST hImageList = ImageList_Create (4, 4, 0, 1, 0);
964 HIMAGELIST hIml;
965 BOOL wasValid;
966 HWND hChild;
967
968 flush_sequences(sequences, NUM_MSG_SEQUENCES);
969 hChild = create_custom_header_control(hParent, TRUE);
970 ok_sequence(sequences, PARENT_SEQ_INDEX, add_header_to_parent_seq,
971 "adder header control to parent", FALSE);
972
973 flush_sequences(sequences, NUM_MSG_SEQUENCES);
974
975 hIml = (HIMAGELIST) SendMessage(hChild, HDM_SETIMAGELIST, 0, (LPARAM) hImageList);
976 ok(hIml == NULL, "Expected NULL, got %p\n", hIml);
977
978 hIml = (HIMAGELIST) SendMessage(hChild, HDM_GETIMAGELIST, 0, 0);
979 ok(hIml != NULL, "Expected non-NULL handle, got %p\n", hIml);
980
981 hIml = (HIMAGELIST) SendMessage(hChild, HDM_CREATEDRAGIMAGE, 0, 0);
982 ok(hIml != NULL, "Expected non-NULL handle, got %p\n", hIml);
983 ImageList_Destroy(hIml);
984
985 ok_sequence(sequences, HEADER_SEQ_INDEX, imageMessages_seq, "imageMessages sequence testing", FALSE);
986
987 DestroyWindow(hChild);
988
989 wasValid = ImageList_Destroy(hImageList);
990 ok(wasValid, "Header must not free image list at destruction!\n");
991 }
992
993 static void test_hdm_filterMessages(HWND hParent)
994 {
995 HWND hChild;
996 int retVal, timeout;
997
998 flush_sequences(sequences, NUM_MSG_SEQUENCES);
999 hChild = create_custom_header_control(hParent, TRUE);
1000 assert(hChild);
1001 ok_sequence(sequences, PARENT_SEQ_INDEX, add_header_to_parent_seq,
1002 "adder header control to parent", FALSE);
1003
1004 timeout = SendMessage(hChild, HDM_SETFILTERCHANGETIMEOUT, 1, 100);
1005 SendMessage(hChild, HDM_SETFILTERCHANGETIMEOUT, 1, timeout);
1006
1007 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1008
1009 /* msdn incorrectly states that return value
1010 * is the index of the filter control being
1011 * modified. The sendMessage here should
1012 * return previous filter timeout value
1013 */
1014
1015 retVal = SendMessage(hChild, HDM_SETFILTERCHANGETIMEOUT, 1, 100);
1016 expect(timeout, retVal);
1017
1018 todo_wine
1019 {
1020 retVal = SendMessage(hChild, HDM_CLEARFILTER, 0, 1);
1021 if (retVal == 0)
1022 win_skip("HDM_CLEARFILTER needs 5.80\n");
1023 else
1024 expect(1, retVal);
1025
1026 retVal = SendMessage(hChild, HDM_EDITFILTER, 1, 0);
1027 if (retVal == 0)
1028 win_skip("HDM_EDITFILTER needs 5.80\n");
1029 else
1030 expect(1, retVal);
1031 }
1032 if (winetest_interactive)
1033 ok_sequence(sequences, HEADER_SEQ_INDEX, filterMessages_seq_interactive,
1034 "filterMessages sequence testing", TRUE);
1035 else
1036 ok_sequence(sequences, HEADER_SEQ_INDEX, filterMessages_seq_noninteractive,
1037 "filterMessages sequence testing", FALSE);
1038 DestroyWindow(hChild);
1039
1040 }
1041
1042 static void test_hdm_unicodeformatMessages(HWND hParent)
1043 {
1044 HWND hChild;
1045 int retVal;
1046
1047 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1048 hChild = create_custom_header_control(hParent, TRUE);
1049 ok_sequence(sequences, PARENT_SEQ_INDEX, add_header_to_parent_seq,
1050 "adder header control to parent", FALSE);
1051
1052 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1053 retVal = SendMessage(hChild, HDM_SETUNICODEFORMAT, TRUE, 0);
1054 expect(0, retVal);
1055 retVal = SendMessage(hChild, HDM_GETUNICODEFORMAT, 0, 0);
1056 expect(1, retVal);
1057
1058 ok_sequence(sequences, HEADER_SEQ_INDEX, unicodeformatMessages_seq,
1059 "unicodeformatMessages sequence testing", FALSE);
1060 DestroyWindow(hChild);
1061 }
1062
1063 static void test_hdm_bitmapmarginMessages(HWND hParent)
1064 {
1065 HWND hChild;
1066 int retVal;
1067
1068 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1069 hChild = create_custom_header_control(hParent, TRUE);
1070 ok_sequence(sequences, PARENT_SEQ_INDEX, add_header_to_parent_seq,
1071 "adder header control to parent", FALSE);
1072
1073 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1074 retVal = SendMessage(hChild, HDM_GETBITMAPMARGIN, 0, 0);
1075 if (retVal == 0)
1076 win_skip("HDM_GETBITMAPMARGIN needs 5.80\n");
1077 else
1078 expect(6, retVal);
1079
1080 ok_sequence(sequences, HEADER_SEQ_INDEX, bitmapmarginMessages_seq,
1081 "bitmapmarginMessages sequence testing", FALSE);
1082 DestroyWindow(hChild);
1083 }
1084
1085 static void test_hdm_index_messages(HWND hParent)
1086 {
1087 HWND hChild;
1088 int retVal;
1089 int loopcnt;
1090 int strcmpResult;
1091 int iSize;
1092 static const int lpiarray[2] = {1, 0};
1093 static int lpiarrayReceived[2];
1094 static char firstHeaderItem[] = "Name";
1095 static char secondHeaderItem[] = "Size";
1096 static char thirdHeaderItem[] = "Type";
1097 static char fourthHeaderItem[] = "Date Modified";
1098 static char *items[] = {firstHeaderItem, secondHeaderItem, thirdHeaderItem, fourthHeaderItem};
1099 RECT rect;
1100 HDITEM hdItem;
1101 hdItem.mask = HDI_TEXT | HDI_WIDTH | HDI_FORMAT;
1102 hdItem.fmt = HDF_LEFT;
1103 hdItem.cxy = 80;
1104 hdItem.cchTextMax = 260;
1105
1106 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1107 hChild = create_custom_header_control(hParent, FALSE);
1108 if (winetest_interactive)
1109 ok_sequence(sequences, PARENT_SEQ_INDEX, add_header_to_parent_seq_interactive,
1110 "adder header control to parent", TRUE);
1111 else
1112 ok_sequence(sequences, PARENT_SEQ_INDEX, add_header_to_parent_seq,
1113 "adder header control to parent", FALSE);
1114 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1115 for ( loopcnt = 0 ; loopcnt < 4 ; loopcnt++ )
1116 {
1117 hdItem.pszText = items[loopcnt];
1118 retVal = SendMessage(hChild, HDM_INSERTITEM, loopcnt, (LPARAM) &hdItem);
1119 ok(retVal == loopcnt, "Adding item %d failed with return value %d\n", ( loopcnt + 1 ), retVal);
1120 }
1121 ok_sequence(sequences, HEADER_SEQ_INDEX, insertItem_seq, "insertItem sequence testing", FALSE);
1122
1123 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1124
1125 retVal = SendMessage(hChild, HDM_DELETEITEM, 3, (LPARAM) &hdItem);
1126 ok(retVal == TRUE, "Deleting item 3 should return TRUE, got %d\n", retVal);
1127 retVal = SendMessage(hChild, HDM_GETITEMCOUNT, 0, 0);
1128 ok(retVal == 3, "Getting item count should return 3, got %d\n", retVal);
1129
1130 retVal = SendMessage(hChild, HDM_DELETEITEM, 3, (LPARAM) &hdItem);
1131 ok(retVal == FALSE, "Deleting already-deleted item should return FALSE, got %d\n", retVal);
1132 retVal = SendMessage(hChild, HDM_GETITEMCOUNT, 0, 0);
1133 ok(retVal == 3, "Getting item count should return 3, got %d\n", retVal);
1134
1135 retVal = SendMessage(hChild, HDM_DELETEITEM, 2, (LPARAM) &hdItem);
1136 ok(retVal == TRUE, "Deleting item 2 should return TRUE, got %d\n", retVal);
1137 retVal = SendMessage(hChild, HDM_GETITEMCOUNT, 0, 0);
1138 ok(retVal == 2, "Getting item count should return 2, got %d\n", retVal);
1139
1140 ok_sequence(sequences, HEADER_SEQ_INDEX, deleteItem_getItemCount_seq,
1141 "deleteItem_getItemCount sequence testing", FALSE);
1142
1143 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1144
1145 retVal = SendMessage(hChild, HDM_GETITEM, 3, (LPARAM) &hdItem);
1146 ok(retVal == FALSE, "Getting already-deleted item should return FALSE, got %d\n", retVal);
1147
1148 retVal = SendMessage(hChild, HDM_GETITEM, 0, (LPARAM) &hdItem);
1149 ok(retVal == TRUE, "Getting the 1st header item should return TRUE, got %d\n", retVal);
1150
1151 ok_sequence(sequences, HEADER_SEQ_INDEX, getItem_seq, "getItem sequence testing", FALSE);
1152
1153 /* check if the item is the right one */
1154 strcmpResult = strcmp(hdItem.pszText, firstHeaderItem);
1155 expect(0, strcmpResult);
1156 expect(80, hdItem.cxy);
1157
1158 iSize = SendMessage(hChild, HDM_GETITEMCOUNT, 0, 0);
1159
1160 /* item should be updated just after accepting new array */
1161 ShowWindow(hChild, SW_HIDE);
1162 retVal = SendMessage(hChild, HDM_SETORDERARRAY, iSize, (LPARAM) lpiarray);
1163 expect(TRUE, retVal);
1164 rect.left = 0;
1165 retVal = SendMessage(hChild, HDM_GETITEMRECT, 0, (LPARAM) &rect);
1166 expect(TRUE, retVal);
1167 ok(rect.left != 0, "Expected updated rectangle\n");
1168
1169 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1170
1171 retVal = SendMessage(hChild, HDM_SETORDERARRAY, iSize, (LPARAM) lpiarray);
1172 ok(retVal == TRUE, "Setting header items order should return TRUE, got %d\n", retVal);
1173
1174 retVal = SendMessage(hChild, HDM_GETORDERARRAY, iSize, (LPARAM) lpiarrayReceived);
1175 ok(retVal == TRUE, "Getting header items order should return TRUE, got %d\n", retVal);
1176
1177 ok_sequence(sequences, HEADER_SEQ_INDEX, orderArray_seq, "set_get_orderArray sequence testing", FALSE);
1178
1179 /* check if the array order is set correctly and the size of the array is correct. */
1180 expect(2, iSize);
1181 expect(lpiarray[0], lpiarrayReceived[0]);
1182 expect(lpiarray[1], lpiarrayReceived[1]);
1183
1184 hdItem.mask = HDI_FORMAT;
1185 hdItem.fmt = HDF_CENTER | HDF_STRING;
1186
1187 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1188
1189 retVal = SendMessage(hChild, HDM_SETITEM, 0, (LPARAM) &hdItem);
1190 ok(retVal == TRUE, "Aligning 1st header item to center should return TRUE, got %d\n", retVal);
1191 hdItem.fmt = HDF_RIGHT | HDF_STRING;
1192 retVal = SendMessage(hChild, HDM_SETITEM, 1, (LPARAM) &hdItem);
1193 ok(retVal == TRUE, "Aligning 2nd header item to right should return TRUE, got %d\n", retVal);
1194
1195 ok_sequence(sequences, HEADER_SEQ_INDEX, setItem_seq, "setItem sequence testing", FALSE);
1196 DestroyWindow(hChild);
1197 }
1198
1199 static void test_hdf_fixedwidth(HWND hParent)
1200 {
1201 HWND hChild;
1202 HDITEM hdItem;
1203 DWORD ret;
1204 RECT rect;
1205 HDHITTESTINFO ht;
1206
1207 hChild = create_custom_header_control(hParent, FALSE);
1208
1209 hdItem.mask = HDI_WIDTH | HDI_FORMAT;
1210 hdItem.fmt = HDF_FIXEDWIDTH;
1211 hdItem.cxy = 80;
1212
1213 ret = SendMessage(hChild, HDM_INSERTITEM, 0, (LPARAM)&hdItem);
1214 expect(0, ret);
1215
1216 /* try to change width */
1217 rect.right = rect.bottom = 0;
1218 SendMessage(hChild, HDM_GETITEMRECT, 0, (LPARAM)&rect);
1219 ok(rect.right != 0, "Expected not zero width\n");
1220 ok(rect.bottom != 0, "Expected not zero height\n");
1221
1222 SendMessage(hChild, WM_LBUTTONDOWN, 0, MAKELPARAM(rect.right, rect.bottom / 2));
1223 SendMessage(hChild, WM_MOUSEMOVE, 0, MAKELPARAM(rect.right + 20, rect.bottom / 2));
1224 SendMessage(hChild, WM_LBUTTONUP, 0, MAKELPARAM(rect.right + 20, rect.bottom / 2));
1225
1226 SendMessage(hChild, HDM_GETITEMRECT, 0, (LPARAM)&rect);
1227
1228 if (hdItem.cxy != rect.right)
1229 {
1230 win_skip("HDF_FIXEDWIDTH format not supported\n");
1231 DestroyWindow(hChild);
1232 return;
1233 }
1234
1235 /* try to adjust with message */
1236 hdItem.mask = HDI_WIDTH;
1237 hdItem.cxy = 90;
1238
1239 ret = SendMessage(hChild, HDM_SETITEM, 0, (LPARAM)&hdItem);
1240 expect(TRUE, ret);
1241
1242 rect.right = 0;
1243 SendMessage(hChild, HDM_GETITEMRECT, 0, (LPARAM)&rect);
1244 expect(90, rect.right);
1245
1246 /* hittesting doesn't report ondivider flag for HDF_FIXEDWIDTH */
1247 ht.pt.x = rect.right - 1;
1248 ht.pt.y = rect.bottom / 2;
1249 SendMessage(hChild, HDM_HITTEST, 0, (LPARAM)&ht);
1250 expect(HHT_ONHEADER, ht.flags);
1251
1252 /* try to adjust with message */
1253 hdItem.mask = HDI_FORMAT;
1254 hdItem.fmt = 0;
1255
1256 ret = SendMessage(hChild, HDM_SETITEM, 0, (LPARAM)&hdItem);
1257 expect(TRUE, ret);
1258
1259 ht.pt.x = 90;
1260 ht.pt.y = rect.bottom / 2;
1261 SendMessage(hChild, HDM_HITTEST, 0, (LPARAM)&ht);
1262 expect(HHT_ONDIVIDER, ht.flags);
1263
1264 DestroyWindow(hChild);
1265 }
1266
1267 static void test_hds_nosizing(HWND hParent)
1268 {
1269 HWND hChild;
1270 HDITEM hdItem;
1271 DWORD ret;
1272 RECT rect;
1273 HDHITTESTINFO ht;
1274
1275 hChild = create_custom_header_control(hParent, FALSE);
1276
1277 memset(&hdItem, 0, sizeof(hdItem));
1278 hdItem.mask = HDI_WIDTH;
1279 hdItem.cxy = 80;
1280
1281 ret = SendMessage(hChild, HDM_INSERTITEM, 0, (LPARAM)&hdItem);
1282 expect(0, ret);
1283
1284 /* HDS_NOSIZING only blocks hittesting */
1285 ret = GetWindowLong(hChild, GWL_STYLE);
1286 SetWindowLong(hChild, GWL_STYLE, ret | HDS_NOSIZING);
1287
1288 /* try to change width with mouse gestures */
1289 rect.right = rect.bottom = 0;
1290 SendMessage(hChild, HDM_GETITEMRECT, 0, (LPARAM)&rect);
1291 ok(rect.right != 0, "Expected not zero width\n");
1292 ok(rect.bottom != 0, "Expected not zero height\n");
1293
1294 SendMessage(hChild, WM_LBUTTONDOWN, 0, MAKELPARAM(rect.right, rect.bottom / 2));
1295 SendMessage(hChild, WM_MOUSEMOVE, 0, MAKELPARAM(rect.right + 20, rect.bottom / 2));
1296 SendMessage(hChild, WM_LBUTTONUP, 0, MAKELPARAM(rect.right + 20, rect.bottom / 2));
1297
1298 SendMessage(hChild, HDM_GETITEMRECT, 0, (LPARAM)&rect);
1299
1300 if (hdItem.cxy != rect.right)
1301 {
1302 win_skip("HDS_NOSIZING style not supported\n");
1303 DestroyWindow(hChild);
1304 return;
1305 }
1306
1307 /* this style doesn't set HDF_FIXEDWIDTH for items */
1308 hdItem.mask = HDI_FORMAT;
1309 ret = SendMessage(hChild, HDM_GETITEM, 0, (LPARAM)&hdItem);
1310 expect(TRUE, ret);
1311 ok(!(hdItem.fmt & HDF_FIXEDWIDTH), "Unexpected HDF_FIXEDWIDTH\n");
1312
1313 /* try to adjust with message */
1314 hdItem.mask = HDI_WIDTH;
1315 hdItem.cxy = 90;
1316
1317 ret = SendMessage(hChild, HDM_SETITEM, 0, (LPARAM)&hdItem);
1318 expect(TRUE, ret);
1319
1320 rect.right = 0;
1321 SendMessage(hChild, HDM_GETITEMRECT, 0, (LPARAM)&rect);
1322 expect(90, rect.right);
1323
1324 /* hittesting doesn't report ondivider flags for HDS_NOSIZING */
1325 ht.pt.x = rect.right - 1;
1326 ht.pt.y = rect.bottom / 2;
1327 SendMessage(hChild, HDM_HITTEST, 0, (LPARAM)&ht);
1328 expect(HHT_ONHEADER, ht.flags);
1329
1330 /* try to adjust with message */
1331 ret = GetWindowLong(hChild, GWL_STYLE);
1332 SetWindowLong(hChild, GWL_STYLE, ret & ~HDS_NOSIZING);
1333
1334 ht.pt.x = 90;
1335 ht.pt.y = rect.bottom / 2;
1336 SendMessage(hChild, HDM_HITTEST, 0, (LPARAM)&ht);
1337 expect(HHT_ONDIVIDER, ht.flags);
1338
1339 DestroyWindow(hChild);
1340 }
1341
1342 #define TEST_NMCUSTOMDRAW(draw_stage, item_spec, lparam, _left, _top, _right, _bottom) \
1343 ok(nm->dwDrawStage == draw_stage, "Invalid dwDrawStage %d vs %d\n", draw_stage, nm->dwDrawStage); \
1344 if (item_spec != -1) \
1345 ok(nm->dwItemSpec == item_spec, "Invalid dwItemSpec %d vs %ld\n", item_spec, nm->dwItemSpec); \
1346 ok(nm->lItemlParam == lparam, "Invalid lItemlParam %d vs %ld\n", lparam, nm->lItemlParam); \
1347 ok((nm->rc.top == _top && nm->rc.bottom == _bottom && nm->rc.left == _left && nm->rc.right == _right) || \
1348 broken(draw_stage != CDDS_ITEMPREPAINT), /* comctl32 < 5.80 */ \
1349 "Invalid rect (%d,%d) (%d,%d) vs (%d,%d) (%d,%d)\n", _left, _top, _right, _bottom, \
1350 nm->rc.left, nm->rc.top, nm->rc.right, nm->rc.bottom);
1351
1352 static LRESULT customdraw_1(int n, NMCUSTOMDRAW *nm)
1353 {
1354 if (nm == NULL) { /* test ended */
1355 ok(n==1, "NM_CUSTOMDRAW messages: %d, expected: 1\n", n);
1356 return 0;
1357 }
1358
1359 switch (n)
1360 {
1361 case 0:
1362 /* don't test dwItemSpec - it's 0 no comctl5 but 1308756 on comctl6 */
1363 TEST_NMCUSTOMDRAW(CDDS_PREPAINT, -1, 0, 0, 0, 670, g_customheight);
1364 return 0;
1365 }
1366
1367 ok(FALSE, "To many custom draw messages (n=%d, nm->dwDrawStage=%d)\n", n, nm->dwDrawStage);
1368 return -1;
1369 }
1370
1371 static LRESULT customdraw_2(int n, NMCUSTOMDRAW *nm)
1372 {
1373 if (nm == NULL) { /* test ended */
1374 ok(n==4, "NM_CUSTOMDRAW messages: %d, expected: 4\n", n);
1375 return 0;
1376 }
1377
1378 switch (n)
1379 {
1380 case 0:
1381 TEST_NMCUSTOMDRAW(CDDS_PREPAINT, -1, 0, 0, 0, 670, g_customheight);
1382 return CDRF_NOTIFYITEMDRAW;
1383 case 1:
1384 TEST_NMCUSTOMDRAW(CDDS_ITEMPREPAINT, 0, 0, 0, 0, 50, g_customheight);
1385 return 0;
1386 case 2:
1387 TEST_NMCUSTOMDRAW(CDDS_ITEMPREPAINT, 1, 5, 50, 0, 150, g_customheight);
1388 return 0;
1389 case 3:
1390 TEST_NMCUSTOMDRAW(CDDS_ITEMPREPAINT, 2, 10, 150, 0, 300, g_customheight);
1391 return 0;
1392 }
1393
1394 ok(FALSE, "To many custom draw messages (n=%d, nm->dwDrawStage=%d)\n", n, nm->dwDrawStage);
1395 return 0;
1396 }
1397
1398 static LRESULT customdraw_3(int n, NMCUSTOMDRAW *nm)
1399 {
1400 if (nm == NULL) { /* test ended */
1401 ok(n==5, "NM_CUSTOMDRAW messages: %d, expected: 5\n", n);
1402 return 0;
1403 }
1404
1405 switch (n)
1406 {
1407 case 0:
1408 TEST_NMCUSTOMDRAW(CDDS_PREPAINT, -1, 0, 0, 0, 670, g_customheight);
1409 return CDRF_NOTIFYITEMDRAW|CDRF_NOTIFYPOSTERASE|CDRF_NOTIFYPOSTPAINT|CDRF_SKIPDEFAULT;
1410 case 1:
1411 TEST_NMCUSTOMDRAW(CDDS_ITEMPREPAINT, 0, 0, 0, 0, 50, g_customheight);
1412 return 0;
1413 case 2:
1414 TEST_NMCUSTOMDRAW(CDDS_ITEMPREPAINT, 1, 5, 50, 0, 150, g_customheight);
1415 return 0;
1416 case 3:
1417 TEST_NMCUSTOMDRAW(CDDS_ITEMPREPAINT, 2, 10, 150, 0, 300, g_customheight);
1418 return 0;
1419 case 4:
1420 TEST_NMCUSTOMDRAW(CDDS_POSTPAINT, -1, 0, 0, 0, 670, g_customheight);
1421 return 0;
1422 }
1423
1424 ok(FALSE, "To many custom draw messages (n=%d, nm->dwDrawStage=%d)\n", n, nm->dwDrawStage);
1425 return 0;
1426 }
1427
1428
1429 static LRESULT customdraw_4(int n, NMCUSTOMDRAW *nm)
1430 {
1431 if (nm == NULL) { /* test ended */
1432 ok(n==4, "NM_CUSTOMDRAW messages: %d, expected: 4\n", n);
1433 return 0;
1434 }
1435
1436 switch (n)
1437 {
1438 case 0:
1439 TEST_NMCUSTOMDRAW(CDDS_PREPAINT, -1, 0, 0, 0, 670, g_customheight);
1440 return CDRF_NOTIFYITEMDRAW|CDRF_NOTIFYPOSTPAINT;
1441 case 1:
1442 TEST_NMCUSTOMDRAW(CDDS_ITEMPREPAINT, 0, 0, 0, 0, 50, g_customheight);
1443 return 0;
1444 case 2:
1445 TEST_NMCUSTOMDRAW(CDDS_ITEMPREPAINT, 2, 10, 150, 0, 300, g_customheight);
1446 return 0;
1447 case 3:
1448 TEST_NMCUSTOMDRAW(CDDS_POSTPAINT, -1, 0, 0, 0, 670, g_customheight);
1449 return 0;
1450 }
1451
1452 ok(FALSE, "To many custom draw messages (n=%d, nm->dwDrawStage=%d)\n", n, nm->dwDrawStage);
1453 return 0;
1454 }
1455
1456 static void run_customdraw_scenario(CUSTOMDRAWPROC proc)
1457 {
1458 g_CustomDrawProc = proc;
1459 g_CustomDrawCount = 0;
1460 InvalidateRect(hWndHeader, NULL, TRUE);
1461 UpdateWindow(hWndHeader);
1462 proc(g_CustomDrawCount, NULL);
1463 g_CustomDrawProc = NULL;
1464 }
1465
1466 static void test_customdraw(void)
1467 {
1468 int i;
1469 HDITEM item;
1470 RECT rect;
1471 CHAR name[] = "Test";
1472 hWndHeader = create_header_control();
1473 GetClientRect(hWndHeader, &rect);
1474 ok(rect.right - rect.left == 670 && rect.bottom - rect.top == g_customheight,
1475 "Tests will fail as header size is %dx%d instead of 670x%d\n",
1476 rect.right - rect.left, rect.bottom - rect.top, g_customheight);
1477
1478 for (i = 0; i < 3; i++)
1479 {
1480 ZeroMemory(&item, sizeof(item));
1481 item.mask = HDI_TEXT|HDI_WIDTH;
1482 item.cxy = 50*(i+1);
1483 item.pszText = name;
1484 item.lParam = i*5;
1485 SendMessage(hWndHeader, HDM_INSERTITEM, i, (LPARAM)&item);
1486 }
1487
1488 run_customdraw_scenario(customdraw_1);
1489 run_customdraw_scenario(customdraw_2);
1490 run_customdraw_scenario(customdraw_3);
1491
1492 ZeroMemory(&item, sizeof(item));
1493 item.mask = HDI_FORMAT;
1494 item.fmt = HDF_OWNERDRAW;
1495 SendMessage(hWndHeader, HDM_SETITEM, 1, (LPARAM)&item);
1496 g_DrawItem.CtlID = 0;
1497 g_DrawItem.CtlType = ODT_HEADER;
1498 g_DrawItem.hwndItem = hWndHeader;
1499 g_DrawItem.itemID = 1;
1500 g_DrawItem.itemState = 0;
1501 SendMessage(hWndHeader, HDM_GETITEMRECT, 1, (LPARAM)&g_DrawItem.rcItem);
1502 run_customdraw_scenario(customdraw_4);
1503 ok(g_DrawItemReceived, "WM_DRAWITEM not received\n");
1504 DestroyWindow(hWndHeader);
1505 hWndHeader = NULL;
1506 g_DrawItem.CtlType = 0;
1507 g_DrawItemReceived = FALSE;
1508 }
1509
1510 static void check_order(const int expected_id[], const int expected_order[],
1511 int count, const char *type)
1512 {
1513 int i;
1514 HDITEMA hdi;
1515
1516 ok(getItemCount(hWndHeader) == count, "Invalid item count in order tests\n");
1517 for (i = 0; i < count; i++)
1518 {
1519 hdi.mask = HDI_LPARAM|HDI_ORDER;
1520 SendMessage(hWndHeader, HDM_GETITEMA, i, (LPARAM)&hdi);
1521 ok(hdi.lParam == expected_id[i],
1522 "Invalid item ids after '%s'- item %d has lParam %d\n", type, i, (int)hdi.lParam);
1523 ok(hdi.iOrder == expected_order[i],
1524 "Invalid item order after '%s'- item %d has iOrder %d\n", type, i, hdi.iOrder);
1525 }
1526 }
1527
1528 static void test_header_order (void)
1529 {
1530 const int rand1[] = {0, 1, 1, 0, 4};
1531 const int rand2[] = {4, 5, 6, 7, 4};
1532 const int rand3[] = {5, 5, 1, 6, 1};
1533 const int rand4[] = {1, 5, 2, 7, 6, 1, 4, 2, 3, 2};
1534 const int rand5[] = {7, 8, 5, 6, 7, 2, 1, 9, 10, 10};
1535 const int rand6[] = {2, 8, 3, 4, 0};
1536
1537 const int ids1[] = {3, 0, 2, 1, 4};
1538 const int ord1[] = {0, 1, 2, 3, 4};
1539 const int ids2[] = {3, 9, 7, 0, 2, 1, 4, 8, 6, 5};
1540 const int ord2[] = {0, 4, 7, 1, 2, 3, 9, 8, 6, 5};
1541 const int ord3[] = {0, 3, 9, 2, 1, 8, 7, 6, 5, 4};
1542 const int ids4[] = {9, 0, 1, 8, 6};
1543 const int ord4[] = {1, 0, 4, 3, 2};
1544
1545 char buffer[20];
1546 HDITEMA hdi;
1547 int i;
1548
1549 hWndHeader = create_header_control();
1550
1551 ZeroMemory(&hdi, sizeof(HDITEMA));
1552 hdi.mask = HDI_TEXT | HDI_LPARAM;
1553 hdi.pszText = buffer;
1554 strcpy(buffer, "test");
1555
1556 for (i = 0; i < 5; i++)
1557 {
1558 hdi.lParam = i;
1559 SendMessage(hWndHeader, HDM_INSERTITEMA, rand1[i], (LPARAM)&hdi);
1560 rand();
1561 }
1562 check_order(ids1, ord1, 5, "insert without iOrder");
1563
1564 hdi.mask |= HDI_ORDER;
1565 for (i = 0; i < 5; i++)
1566 {
1567 hdi.lParam = i + 5;
1568 hdi.iOrder = rand2[i];
1569 SendMessage(hWndHeader, HDM_INSERTITEMA, rand3[i], (LPARAM)&hdi);
1570 rand(); rand();
1571 }
1572 check_order(ids2, ord2, 10, "insert with order");
1573
1574 hdi.mask = HDI_ORDER;
1575 for (i=0; i<10; i++)
1576 {
1577 hdi.iOrder = rand5[i];
1578 SendMessage(hWndHeader, HDM_SETITEMA, rand4[i], (LPARAM)&hdi);
1579 rand(); rand();
1580 }
1581 check_order(ids2, ord3, 10, "setitems changing order");
1582
1583 for (i=0; i<5; i++)
1584 SendMessage(hWndHeader, HDM_DELETEITEM, rand6[i], 0);
1585 check_order(ids4, ord4, 5, "deleteitem");
1586
1587 DestroyWindow(hWndHeader);
1588 }
1589
1590 static LRESULT CALLBACK HeaderTestWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
1591 {
1592 DRAWITEMSTRUCT *di;
1593 switch(msg) {
1594
1595 case WM_NOTIFY:
1596 {
1597 NMHEADERA *hdr = (NMHEADER *)lParam;
1598 EXPECTEDNOTIFY *expected;
1599 int i;
1600
1601 if (hdr->hdr.code == NM_CUSTOMDRAW)
1602 if (g_CustomDrawProc)
1603 return g_CustomDrawProc(g_CustomDrawCount++, (NMCUSTOMDRAW*)hdr);
1604
1605 for (i=0; i<nUnexpectedNotify; i++)
1606 ok(hdr->hdr.code != unexpectedNotify[i], "Received invalid notify %d\n", hdr->hdr.code);
1607
1608 if (nReceivedNotify >= nExpectedNotify || hdr->hdr.hwndFrom != hWndHeader )
1609 break;
1610
1611 expected = &expectedNotify[nReceivedNotify];
1612 if (hdr->hdr.code != expected->iCode)
1613 break;
1614
1615 nReceivedNotify++;
1616 compare_items(hdr->hdr.code, &expected->hdItem, hdr->pitem, expected->fUnicode);
1617 break;
1618 }
1619
1620 case WM_DRAWITEM:
1621 di = (DRAWITEMSTRUCT *)lParam;
1622 ok(g_DrawItem.CtlType != 0, "Unexpected WM_DRAWITEM\n");
1623 if (g_DrawItem.CtlType == 0) return 0;
1624 g_DrawItemReceived = TRUE;
1625 compare(di->CtlType, g_DrawItem.CtlType, "%d");
1626 compare(di->CtlID, g_DrawItem.CtlID, "%d");
1627 compare(di->hwndItem, g_DrawItem.hwndItem, "%p");
1628 compare(di->itemID, g_DrawItem.itemID, "%d");
1629 compare(di->itemState, g_DrawItem.itemState, "%d");
1630 compare(di->rcItem.left, g_DrawItem.rcItem.left, "%d");
1631 compare(di->rcItem.top, g_DrawItem.rcItem.top, "%d");
1632 compare(di->rcItem.right, g_DrawItem.rcItem.right, "%d");
1633 compare(di->rcItem.bottom, g_DrawItem.rcItem.bottom, "%d");
1634 break;
1635
1636 case WM_DESTROY:
1637 PostQuitMessage(0);
1638 break;
1639
1640 default:
1641 return DefWindowProcA(hWnd, msg, wParam, lParam);
1642 }
1643
1644 return 0L;
1645 }
1646
1647 static int init(void)
1648 {
1649 HMODULE hComctl32;
1650 BOOL (WINAPI *pInitCommonControlsEx)(const INITCOMMONCONTROLSEX*);
1651 WNDCLASSA wc;
1652 INITCOMMONCONTROLSEX iccex;
1653 TEXTMETRICA tm;
1654 HFONT hOldFont;
1655 HDC hdc;
1656
1657 hComctl32 = GetModuleHandleA("comctl32.dll");
1658 pInitCommonControlsEx = (void*)GetProcAddress(hComctl32, "InitCommonControlsEx");
1659 if (!pInitCommonControlsEx)
1660 {
1661 skip("InitCommonControlsEx() is missing. Skipping the tests\n");
1662 return 0;
1663 }
1664
1665 iccex.dwSize = sizeof(iccex);
1666 iccex.dwICC = ICC_USEREX_CLASSES;
1667 pInitCommonControlsEx(&iccex);
1668
1669 wc.style = CS_HREDRAW | CS_VREDRAW;
1670 wc.cbClsExtra = 0;
1671 wc.cbWndExtra = 0;
1672 wc.hInstance = GetModuleHandleA(NULL);
1673 wc.hIcon = NULL;
1674 wc.hCursor = LoadCursorA(NULL, IDC_ARROW);
1675 wc.hbrBackground = GetSysColorBrush(COLOR_WINDOW);
1676 wc.lpszMenuName = NULL;
1677 wc.lpszClassName = "HeaderTestClass";
1678 wc.lpfnWndProc = HeaderTestWndProc;
1679 RegisterClassA(&wc);
1680
1681 /* The height of the header control depends on the height of the system font.
1682 The height of the system font is dpi dependent */
1683 hdc = GetDC(0);
1684 hOldFont = SelectObject(hdc, GetStockObject(SYSTEM_FONT));
1685 GetTextMetricsA(hdc, &tm);
1686 /* 2 dot extra space are needed for the border */
1687 g_customheight = tm.tmHeight + 2;
1688 trace("customdraw height: %d (dpi: %d)\n", g_customheight, GetDeviceCaps(hdc, LOGPIXELSY));
1689 SelectObject(hdc, hOldFont);
1690 ReleaseDC(0, hdc);
1691
1692 hHeaderParentWnd = CreateWindowExA(0, "HeaderTestClass", "Header test", WS_OVERLAPPEDWINDOW,
1693 CW_USEDEFAULT, CW_USEDEFAULT, 672+2*GetSystemMetrics(SM_CXSIZEFRAME),
1694 226+GetSystemMetrics(SM_CYCAPTION)+2*GetSystemMetrics(SM_CYSIZEFRAME),
1695 NULL, NULL, GetModuleHandleA(NULL), 0);
1696 assert(hHeaderParentWnd != NULL);
1697 ShowWindow(hHeaderParentWnd, SW_SHOW);
1698 return 1;
1699 }
1700
1701 /* maximum 8 items allowed */
1702 static void check_orderarray(HWND hwnd, DWORD start, DWORD set, DWORD expected,
1703 int todo, int line)
1704 {
1705 int count, i;
1706 INT order[8];
1707 DWORD ret, array = 0;
1708
1709 count = SendMessage(hwnd, HDM_GETITEMCOUNT, 0, 0);
1710
1711 /* initial order */
1712 for(i = 1; i<=count; i++)
1713 order[i-1] = start>>(4*(count-i)) & 0xf;
1714
1715 ret = SendMessage(hwnd, HDM_SETORDERARRAY, count, (LPARAM)order);
1716 ok_(__FILE__, line)(ret, "Expected HDM_SETORDERARAY to succeed, got %d\n", ret);
1717
1718 /* new order */
1719 for(i = 1; i<=count; i++)
1720 order[i-1] = set>>(4*(count-i)) & 0xf;
1721 ret = SendMessage(hwnd, HDM_SETORDERARRAY, count, (LPARAM)order);
1722 ok_(__FILE__, line)(ret, "Expected HDM_SETORDERARAY to succeed, got %d\n", ret);
1723
1724 /* check actual order */
1725 ret = SendMessage(hwnd, HDM_GETORDERARRAY, count, (LPARAM)order);
1726 ok_(__FILE__, line)(ret, "Expected HDM_GETORDERARAY to succeed, got %d\n", ret);
1727 for(i = 1; i<=count; i++)
1728 array |= order[i-1]<<(4*(count-i));
1729
1730 if (todo) {
1731 todo_wine
1732 ok_(__FILE__, line)(array == expected, "Expected %x, got %x\n", expected, array);
1733 }
1734 else
1735 ok_(__FILE__, line)(array == expected, "Expected %x, got %x\n", expected, array);
1736 }
1737
1738 static void test_hdm_orderarray(void)
1739 {
1740 HWND hwnd;
1741 INT order[5];
1742 DWORD ret;
1743
1744 hwnd = create_header_control();
1745
1746 /* three items */
1747 addItem(hwnd, 0, NULL);
1748 addItem(hwnd, 1, NULL);
1749 addItem(hwnd, 2, NULL);
1750
1751 ret = SendMessage(hwnd, HDM_GETORDERARRAY, 3, (LPARAM)order);
1752 if (!ret)
1753 {
1754 win_skip("HDM_GETORDERARRAY not implemented.\n");
1755 DestroyWindow(hwnd);
1756 return;
1757 }
1758
1759 expect(0, order[0]);
1760 expect(1, order[1]);
1761 expect(2, order[2]);
1762
1763 if (0)
1764 {
1765 /* null pointer, crashes native */
1766 ret = SendMessage(hwnd, HDM_SETORDERARRAY, 3, 0);
1767 expect(FALSE, ret);
1768 }
1769 /* count out of limits */
1770 ret = SendMessage(hwnd, HDM_SETORDERARRAY, 5, (LPARAM)order);
1771 expect(FALSE, ret);
1772 /* count out of limits */
1773 ret = SendMessage(hwnd, HDM_SETORDERARRAY, 2, (LPARAM)order);
1774 expect(FALSE, ret);
1775
1776 /* try with out of range item index */
1777 /* (0,1,2)->(1,0,3) => (1,0,2) */
1778 check_orderarray(hwnd, 0x120, 0x103, 0x102, FALSE, __LINE__);
1779 /* (1,0,2)->(3,0,1) => (0,2,1) */
1780 check_orderarray(hwnd, 0x102, 0x301, 0x021, TRUE, __LINE__);
1781 /* (0,2,1)->(2,3,1) => (2,0,1) */
1782 check_orderarray(hwnd, 0x021, 0x231, 0x201, FALSE, __LINE__);
1783
1784 /* (0,1,2)->(0,2,2) => (0,1,2) */
1785 check_orderarray(hwnd, 0x012, 0x022, 0x012, FALSE, __LINE__);
1786
1787 addItem(hwnd, 3, NULL);
1788
1789 /* (0,1,2,3)->(0,1,2,2) => (0,1,3,2) */
1790 check_orderarray(hwnd, 0x0123, 0x0122, 0x0132, FALSE, __LINE__);
1791 /* (0,1,2,3)->(0,1,3,3) => (0,1,2,3) */
1792 check_orderarray(hwnd, 0x0123, 0x0133, 0x0123, FALSE, __LINE__);
1793 /* (0,1,2,3)->(0,4,2,3) => (0,1,2,3) */
1794 check_orderarray(hwnd, 0x0123, 0x0423, 0x0123, FALSE, __LINE__);
1795 /* (0,1,2,3)->(4,0,1,2) => (0,1,3,2) */
1796 check_orderarray(hwnd, 0x0123, 0x4012, 0x0132, TRUE, __LINE__);
1797 /* (0,1,3,2)->(4,0,1,4) => (0,3,1,2) */
1798 check_orderarray(hwnd, 0x0132, 0x4014, 0x0312, TRUE, __LINE__);
1799 /* (0,1,2,3)->(4,1,0,2) => (1,0,3,2) */
1800 check_orderarray(hwnd, 0x0123, 0x4102, 0x1032, TRUE, __LINE__);
1801 /* (0,1,2,3)->(0,1,4,2) => (0,1,2,3) */
1802 check_orderarray(hwnd, 0x0123, 0x0142, 0x0132, FALSE, __LINE__);
1803 /* (0,1,2,3)->(4,4,4,4) => (0,1,2,3) */
1804 check_orderarray(hwnd, 0x0123, 0x4444, 0x0123, FALSE, __LINE__);
1805 /* (0,1,2,3)->(4,4,1,2) => (0,1,3,2) */
1806 check_orderarray(hwnd, 0x0123, 0x4412, 0x0132, TRUE, __LINE__);
1807 /* (0,1,2,3)->(4,4,4,1) => (0,2,3,1) */
1808 check_orderarray(hwnd, 0x0123, 0x4441, 0x0231, TRUE, __LINE__);
1809 /* (0,1,2,3)->(1,4,4,4) => (1,0,2,3) */
1810 check_orderarray(hwnd, 0x0123, 0x1444, 0x1023, FALSE, __LINE__);
1811 /* (0,1,2,3)->(4,2,4,1) => (0,2,3,1) */
1812 check_orderarray(hwnd, 0x0123, 0x4241, 0x0231, FALSE, __LINE__);
1813 /* (0,1,2,3)->(4,2,0,1) => (2,0,3,1) */
1814 check_orderarray(hwnd, 0x0123, 0x4201, 0x2031, TRUE, __LINE__);
1815 /* (3,2,1,0)->(4,2,0,1) => (3,2,0,1) */
1816 check_orderarray(hwnd, 0x3210, 0x4201, 0x3201, FALSE, __LINE__);
1817
1818 DestroyWindow(hwnd);
1819 }
1820
1821 START_TEST(header)
1822 {
1823 HWND parent_hwnd;
1824 ULONG_PTR ctx_cookie;
1825 HANDLE hCtx;
1826 HWND hwnd;
1827
1828 if (!init())
1829 return;
1830
1831 test_header_control();
1832 test_header_order();
1833 test_hdm_orderarray();
1834 test_customdraw();
1835
1836 DestroyWindow(hHeaderParentWnd);
1837
1838 init_msg_sequences(sequences, NUM_MSG_SEQUENCES);
1839 parent_hwnd = create_custom_parent_window();
1840 ok_sequence(sequences, PARENT_SEQ_INDEX, create_parent_wnd_seq, "create parent windows", FALSE);
1841
1842 test_hdm_index_messages(parent_hwnd);
1843 test_hdm_getitemrect(parent_hwnd);
1844 test_hdm_hittest(parent_hwnd);
1845 test_hdm_layout(parent_hwnd);
1846 test_hdm_ordertoindex(parent_hwnd);
1847 test_hdm_sethotdivider(parent_hwnd);
1848 test_hdm_imageMessages(parent_hwnd);
1849 test_hdm_filterMessages(parent_hwnd);
1850 test_hdm_unicodeformatMessages(parent_hwnd);
1851 test_hdm_bitmapmarginMessages(parent_hwnd);
1852
1853 if (!load_v6_module(&ctx_cookie, &hCtx))
1854 {
1855 DestroyWindow(parent_hwnd);
1856 return;
1857 }
1858
1859 /* this is a XP SP3 failure workaround */
1860 hwnd = CreateWindowExA(0, WC_HEADER, NULL,
1861 WS_CHILD|WS_BORDER|WS_VISIBLE|HDS_BUTTONS|HDS_HORZ,
1862 0, 0, 100, 100,
1863 parent_hwnd, NULL, GetModuleHandleA(NULL), NULL);
1864
1865 if (!IsWindow(hwnd))
1866 {
1867 win_skip("FIXME: failed to create Header window.\n");
1868 unload_v6_module(ctx_cookie, hCtx);
1869 DestroyWindow(parent_hwnd);
1870 return;
1871 }
1872 else
1873 DestroyWindow(hwnd);
1874
1875 /* comctl32 version 6 tests start here */
1876 test_hdf_fixedwidth(parent_hwnd);
1877 test_hds_nosizing(parent_hwnd);
1878
1879 unload_v6_module(ctx_cookie, hCtx);
1880
1881 DestroyWindow(parent_hwnd);
1882 }