push 0a0aa53cd365a71ca6121b6df157ca635450378f
[wine/hacks.git] / dlls / comctl32 / tests / header.c
blob76612530c98c822cbb94e363959c2c0ebc009eb8
1 /* Unit test suite for header control.
3 * Copyright 2005 Vijay Kiran Kamuju
4 * Copyright 2007 Shanren Zhou
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include <windows.h>
23 #include <commctrl.h>
24 #include <assert.h>
26 #include "wine/test.h"
27 #include "msg.h"
29 typedef struct tagEXPECTEDNOTIFY
31 INT iCode;
32 BOOL fUnicode;
33 HDITEMA hdItem;
34 } EXPECTEDNOTIFY;
36 typedef LRESULT (*CUSTOMDRAWPROC)(int n, NMCUSTOMDRAW *nm);
38 static CUSTOMDRAWPROC g_CustomDrawProc;
39 static int g_CustomDrawCount;
40 static DRAWITEMSTRUCT g_DrawItem;
41 static BOOL g_DrawItemReceived;
42 static DWORD g_customheight;
44 static EXPECTEDNOTIFY expectedNotify[10];
45 static INT nExpectedNotify = 0;
46 static INT nReceivedNotify = 0;
47 static INT unexpectedNotify[10];
48 static INT nUnexpectedNotify = 0;
50 static HWND hHeaderParentWnd;
51 static HWND hWndHeader;
52 #define MAX_CHARS 100
54 #define compare(val, exp, fmt) ok((val) == (exp), #val " value: " fmt ", expected: " fmt "\n", (val), (exp))
56 #define expect(expected, got) ok(expected == got, "expected %d, got %d\n", expected,got)
58 #define NUM_MSG_SEQUENCES 2
59 #define PARENT_SEQ_INDEX 0
60 #define HEADER_SEQ_INDEX 1
62 static struct msg_sequence *sequences[NUM_MSG_SEQUENCES];
64 static const struct message create_parent_wnd_seq[] = {
65 { WM_GETMINMAXINFO, sent },
66 { WM_NCCREATE, sent },
67 { WM_NCCALCSIZE, sent|wparam, 0 },
68 { WM_CREATE, sent },
69 { 0 }
72 static const struct message add_header_to_parent_seq_interactive[] = {
73 { WM_NOTIFYFORMAT, sent|lparam, 0, NF_QUERY },
74 { WM_QUERYUISTATE, sent },
75 { WM_PARENTNOTIFY, sent|wparam, 1 },
76 { WM_SHOWWINDOW, sent|wparam, 1 },
77 { WM_WINDOWPOSCHANGING, sent|wparam, 0 },
78 { WM_WINDOWPOSCHANGING, sent|wparam, 0 },
79 { WM_ACTIVATEAPP, sent|wparam, 1 },
80 { WM_NCACTIVATE, sent|wparam, 1 },
81 { WM_ACTIVATE, sent|wparam, 1 },
82 { WM_IME_SETCONTEXT, sent|defwinproc|wparam, 1 },
83 { WM_IME_NOTIFY, sent|defwinproc|wparam, 2 },
84 { WM_SETFOCUS, sent|defwinproc|wparam, 0 },
85 { WM_WINDOWPOSCHANGED, sent|wparam, 0 },
86 { WM_SIZE, sent|wparam, 0 },
87 { WM_MOVE, sent|wparam, 0 },
88 { 0 }
91 static const struct message add_header_to_parent_seq[] = {
92 { WM_NOTIFYFORMAT, sent|lparam, 0, NF_QUERY },
93 { WM_QUERYUISTATE, sent|optional },
94 { WM_PARENTNOTIFY, sent },
95 { 0 }
98 static const struct message insertItem_seq[] = {
99 { HDM_INSERTITEM, sent|wparam, 0 },
100 { HDM_INSERTITEM, sent|wparam, 1 },
101 { HDM_INSERTITEM, sent|wparam, 2 },
102 { HDM_INSERTITEM, sent|wparam, 3 },
103 { 0 }
106 static const struct message getItem_seq[] = {
107 { HDM_GETITEM, sent|wparam, 3 },
108 { HDM_GETITEM, sent|wparam, 0 },
109 { 0 }
113 static const struct message deleteItem_getItemCount_seq[] = {
114 { HDM_DELETEITEM, sent|wparam, 3 },
115 { HDM_GETITEMCOUNT, sent },
116 { HDM_DELETEITEM, sent|wparam, 3 },
117 { HDM_GETITEMCOUNT, sent },
118 { HDM_DELETEITEM, sent|wparam, 2 },
119 { HDM_GETITEMCOUNT, sent },
120 { 0 }
123 static const struct message orderArray_seq[] = {
124 { HDM_GETITEMCOUNT, sent },
125 { HDM_SETORDERARRAY, sent|wparam, 2 },
126 { HDM_GETORDERARRAY, sent|wparam, 2 },
127 { 0 }
130 static const struct message setItem_seq[] = {
131 { HDM_SETITEM, sent|wparam, 0 },
132 { HDM_SETITEM, sent|wparam, 1 },
133 { 0 }
136 static const struct message getItemRect_seq[] = {
137 { HDM_GETITEMRECT, sent|wparam, 1 },
138 { HDM_GETITEMRECT, sent|wparam, 0 },
139 { HDM_GETITEMRECT, sent|wparam, 10 },
140 { 0 }
143 static const struct message layout_seq[] = {
144 { HDM_LAYOUT, sent },
145 { 0 }
148 static const struct message orderToIndex_seq[] = {
149 { HDM_ORDERTOINDEX, sent|wparam, 1 },
150 { 0 }
153 static const struct message hittest_seq[] = {
154 { HDM_HITTEST, sent },
155 { HDM_HITTEST, sent },
156 { HDM_HITTEST, sent },
157 { 0 }
160 static const struct message setHotDivider_seq_interactive[] = {
161 { HDM_SETHOTDIVIDER, sent|wparam, TRUE },
162 { WM_PAINT, sent|defwinproc},
163 { WM_NCPAINT, sent|defwinproc},
164 { WM_ERASEBKGND, sent|defwinproc},
165 { HDM_SETHOTDIVIDER, sent|wparam|lparam, FALSE, 100 },
166 { WM_PAINT, sent|defwinproc},
167 { HDM_SETHOTDIVIDER, sent|wparam|lparam, FALSE, 1},
168 { WM_PAINT, sent|defwinproc},
169 { 0 }
172 static const struct message setHotDivider_seq_noninteractive[] = {
173 { HDM_SETHOTDIVIDER, sent|wparam, TRUE },
174 { HDM_SETHOTDIVIDER, sent|wparam|lparam, FALSE, 100 },
175 { HDM_SETHOTDIVIDER, sent|wparam|lparam, FALSE, 1},
176 { 0 }
179 static const struct message imageMessages_seq[] = {
180 { HDM_SETIMAGELIST, sent },
181 { HDM_GETIMAGELIST, sent },
182 { HDM_CREATEDRAGIMAGE, sent },
183 { 0 }
186 static const struct message filterMessages_seq_interactive[] = {
187 { HDM_SETFILTERCHANGETIMEOUT, sent|wparam|lparam, 1, 100 },
188 { HDM_CLEARFILTER, sent|wparam|lparam, 0, 1 },
189 { HDM_EDITFILTER, sent|wparam|lparam, 1, 0 },
190 { WM_PARENTNOTIFY, sent|wparam|defwinproc, WM_CREATE },
191 { WM_CTLCOLOREDIT, sent|defwinproc },
192 { WM_COMMAND, sent|defwinproc },
193 { 0 }
196 static const struct message filterMessages_seq_noninteractive[] = {
197 { HDM_SETFILTERCHANGETIMEOUT, sent|wparam|lparam, 1, 100 },
198 { HDM_CLEARFILTER, sent|wparam|lparam, 0, 1 },
199 { HDM_EDITFILTER, sent|wparam|lparam, 1, 0 },
200 { WM_PARENTNOTIFY, sent|wparam|defwinproc|optional, WM_CREATE },
201 { WM_COMMAND, sent|defwinproc|optional },
202 { 0 }
205 static const struct message unicodeformatMessages_seq[] = {
206 { HDM_SETUNICODEFORMAT, sent|wparam, TRUE },
207 { HDM_GETUNICODEFORMAT, sent },
208 { 0 }
211 static const struct message bitmapmarginMessages_seq[] = {
212 { HDM_GETBITMAPMARGIN, sent },
213 { 0 }
217 static void expect_notify(INT iCode, BOOL fUnicode, HDITEMA *lpItem)
219 assert(nExpectedNotify < 10);
220 expectedNotify[nExpectedNotify].iCode = iCode;
221 expectedNotify[nExpectedNotify].fUnicode = fUnicode;
222 expectedNotify[nExpectedNotify].hdItem = *lpItem;
223 nExpectedNotify++;
226 static void dont_expect_notify(INT iCode)
228 assert(nUnexpectedNotify < 10);
229 unexpectedNotify[nUnexpectedNotify++] = iCode;
232 static BOOL notifies_received(void)
234 BOOL fRet = (nExpectedNotify == nReceivedNotify);
235 nExpectedNotify = nReceivedNotify = 0;
236 nUnexpectedNotify = 0;
237 return fRet;
240 static LONG addItem(HWND hdex, int idx, LPSTR text)
242 HDITEMA hdItem;
243 hdItem.mask = HDI_TEXT | HDI_WIDTH;
244 hdItem.cxy = 100;
245 hdItem.pszText = text;
246 hdItem.cchTextMax = 0;
247 return (LONG)SendMessage(hdex, HDM_INSERTITEMA, (WPARAM)idx, (LPARAM)&hdItem);
250 static LONG setItem(HWND hdex, int idx, LPSTR text, BOOL fCheckNotifies)
252 LONG ret;
253 HDITEMA hdexItem;
254 hdexItem.mask = HDI_TEXT;
255 hdexItem.pszText = text;
256 hdexItem.cchTextMax = 0;
257 if (fCheckNotifies)
259 expect_notify(HDN_ITEMCHANGINGA, FALSE, &hdexItem);
260 expect_notify(HDN_ITEMCHANGEDA, FALSE, &hdexItem);
262 ret = (LONG)SendMessage(hdex, HDM_SETITEMA, (WPARAM)idx, (LPARAM)&hdexItem);
263 if (fCheckNotifies)
264 ok(notifies_received(), "setItem(): not all expected notifies were received\n");
265 return ret;
268 static LONG setItemUnicodeNotify(HWND hdex, int idx, LPSTR text, LPWSTR wText)
270 LONG ret;
271 HDITEMA hdexItem;
272 HDITEMW hdexNotify;
273 hdexItem.mask = HDI_TEXT;
274 hdexItem.pszText = text;
275 hdexItem.cchTextMax = 0;
277 hdexNotify.mask = HDI_TEXT;
278 hdexNotify.pszText = wText;
280 expect_notify(HDN_ITEMCHANGINGW, TRUE, (HDITEMA*)&hdexNotify);
281 expect_notify(HDN_ITEMCHANGEDW, TRUE, (HDITEMA*)&hdexNotify);
282 ret = (LONG)SendMessage(hdex, HDM_SETITEMA, (WPARAM)idx, (LPARAM)&hdexItem);
283 ok(notifies_received(), "setItemUnicodeNotify(): not all expected notifies were received\n");
284 return ret;
287 static LONG delItem(HWND hdex, int idx)
289 return (LONG)SendMessage(hdex, HDM_DELETEITEM, (WPARAM)idx, 0);
292 static LONG getItemCount(HWND hdex)
294 return (LONG)SendMessage(hdex, HDM_GETITEMCOUNT, 0, 0);
297 static LONG getItem(HWND hdex, int idx, LPSTR textBuffer)
299 HDITEMA hdItem;
300 hdItem.mask = HDI_TEXT;
301 hdItem.pszText = textBuffer;
302 hdItem.cchTextMax = MAX_CHARS;
303 return (LONG)SendMessage(hdex, HDM_GETITEMA, (WPARAM)idx, (LPARAM)&hdItem);
306 static void addReadDelItem(HWND hdex, HDITEMA *phdiCreate, int maskRead, HDITEMA *phdiRead)
308 ok(SendMessage(hdex, HDM_INSERTITEMA, 0, (LPARAM)phdiCreate)!=-1, "Adding item failed\n");
309 ZeroMemory(phdiRead, sizeof(HDITEMA));
310 phdiRead->mask = maskRead;
311 ok(SendMessage(hdex, HDM_GETITEMA, 0, (LPARAM)phdiRead)!=0, "Getting item data failed\n");
312 ok(SendMessage(hdex, HDM_DELETEITEM, 0, 0)!=0, "Deleting item failed\n");
315 static HWND create_header_control (void)
317 HWND handle;
318 HDLAYOUT hlayout;
319 RECT rectwin;
320 WINDOWPOS winpos;
322 handle = CreateWindowEx(0, WC_HEADER, NULL,
323 WS_CHILD|WS_BORDER|WS_VISIBLE|HDS_BUTTONS|HDS_HORZ,
324 0, 0, 0, 0,
325 hHeaderParentWnd, NULL, NULL, NULL);
326 assert(handle);
328 if (winetest_interactive)
329 ShowWindow (hHeaderParentWnd, SW_SHOW);
331 GetClientRect(hHeaderParentWnd,&rectwin);
332 hlayout.prc = &rectwin;
333 hlayout.pwpos = &winpos;
334 SendMessageA(handle,HDM_LAYOUT,0,(LPARAM) &hlayout);
335 SetWindowPos(handle, winpos.hwndInsertAfter, winpos.x, winpos.y,
336 winpos.cx, winpos.cy, 0);
338 return handle;
341 static void compare_items(INT iCode, HDITEMA *hdi1, HDITEMA *hdi2, BOOL fUnicode)
343 ok(hdi1->mask == hdi2->mask, "Notify %d mask mismatch (%08x != %08x)\n", iCode, hdi1->mask, hdi2->mask);
344 if (hdi1->mask & HDI_WIDTH)
346 ok(hdi1->cxy == hdi2->cxy, "Notify %d cxy mismatch (%08x != %08x)\n", iCode, hdi1->cxy, hdi2->cxy);
348 if (hdi1->mask & HDI_TEXT)
350 if (hdi1->pszText == LPSTR_TEXTCALLBACKA)
352 ok(hdi1->pszText == LPSTR_TEXTCALLBACKA, "Notify %d - only one item is LPSTR_TEXTCALLBACK\n", iCode);
354 else
355 if (fUnicode)
357 char buf1[260];
358 char buf2[260];
359 WideCharToMultiByte(CP_ACP, 0, (LPCWSTR)hdi1->pszText, -1, buf1, 260, NULL, NULL);
360 WideCharToMultiByte(CP_ACP, 0, (LPCWSTR)hdi2->pszText, -1, buf2, 260, NULL, NULL);
361 ok(lstrcmpW((LPWSTR)hdi1->pszText, (LPWSTR)hdi2->pszText)==0,
362 "Notify %d text mismatch (L\"%s\" vs L\"%s\")\n",
363 iCode, buf1, buf2);
365 else
367 ok(strcmp(hdi1->pszText, hdi2->pszText)==0,
368 "Notify %d text mismatch (\"%s\" vs \"%s\")\n",
369 iCode, hdi1->pszText, hdi2->pszText);
374 static char pszFirstItem[] = "First Item";
375 static char pszSecondItem[] = "Second Item";
376 static char pszThirdItem[] = "Third Item";
377 static char pszFourthItem[] = "Fourth Item";
378 static char pszReplaceItem[] = "Replace Item";
379 static char pszOutOfRangeItem[] = "Out Of Range Item";
381 static char *str_items[] =
382 {pszFirstItem, pszSecondItem, pszThirdItem, pszFourthItem, pszReplaceItem, pszOutOfRangeItem};
384 static char pszUniTestA[] = "TST";
385 static WCHAR pszUniTestW[] = {'T','S','T',0};
388 #define TEST_GET_ITEM(i,c)\
389 { res = getItem(hWndHeader, i, buffer);\
390 ok(res != 0, "Getting item[%d] using valid index failed unexpectedly (%d)\n", i, res);\
391 ok(strcmp(str_items[c], buffer) == 0, "Getting item[%d] returned \"%s\" expecting \"%s\"\n", i, buffer, str_items[c]);\
394 #define TEST_GET_ITEMCOUNT(i)\
395 { res = getItemCount(hWndHeader);\
396 ok(res == i, "Got Item Count as %d\n", res);\
399 struct subclass_info
401 WNDPROC oldproc;
404 static LRESULT WINAPI header_subclass_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
406 struct subclass_info *info = (struct subclass_info *)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
407 static LONG defwndproc_counter = 0;
408 LRESULT ret;
409 struct message msg;
411 trace("header: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
412 msg.message = message;
413 msg.flags = sent|wparam|lparam;
414 if (defwndproc_counter) msg.flags |= defwinproc;
415 msg.wParam = wParam;
416 msg.lParam = lParam;
417 add_message(sequences, HEADER_SEQ_INDEX, &msg);
419 defwndproc_counter++;
420 ret = CallWindowProcA(info->oldproc, hwnd, message, wParam, lParam);
421 defwndproc_counter--;
423 return ret;
426 static LRESULT WINAPI parent_wnd_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
428 static LONG defwndproc_counter = 0;
429 LRESULT ret;
430 struct message msg;
432 /* do not log painting messages */
433 if (message != WM_PAINT &&
434 message != WM_ERASEBKGND &&
435 message != WM_NCPAINT &&
436 message != WM_NCHITTEST &&
437 message != WM_GETTEXT &&
438 message != WM_GETICON &&
439 message != WM_DEVICECHANGE)
442 trace("parent: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
444 msg.message = message;
445 msg.flags = sent|wparam|lparam;
446 if (defwndproc_counter) msg.flags |= defwinproc;
447 msg.wParam = wParam;
448 msg.lParam = lParam;
449 add_message(sequences, PARENT_SEQ_INDEX, &msg);
452 defwndproc_counter++;
453 ret = DefWindowProcA(hwnd, message, wParam, lParam);
454 defwndproc_counter--;
456 return ret;
459 static BOOL register_parent_wnd_class(void)
461 WNDCLASSA cls;
463 cls.style = 0;
464 cls.lpfnWndProc = parent_wnd_proc;
465 cls.cbClsExtra = 0;
466 cls.cbWndExtra = 0;
467 cls.hInstance = GetModuleHandleA(NULL);
468 cls.hIcon = 0;
469 cls.hCursor = LoadCursorA(0, IDC_ARROW);
470 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
471 cls.lpszMenuName = NULL;
472 cls.lpszClassName = "Header test parent class";
473 return RegisterClassA(&cls);
476 static HWND create_custom_parent_window(void)
478 if (!register_parent_wnd_class())
479 return NULL;
481 return CreateWindowExA(0, "Header test parent class", "Header Message Sequence Testing",
482 WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT,
483 672+2*GetSystemMetrics(SM_CXSIZEFRAME),
484 226+GetSystemMetrics(SM_CYCAPTION)+2*GetSystemMetrics(SM_CYSIZEFRAME),
485 NULL, NULL, GetModuleHandleA(NULL), 0);
488 static HWND create_custom_header_control(HWND hParent, BOOL preloadHeaderItems)
490 struct subclass_info *info;
491 HWND childHandle;
492 HDLAYOUT hlayout;
493 RECT rectwin;
494 WINDOWPOS winpos;
495 int retVal;
496 int loopcnt;
497 static char firstHeaderItem[] = "Name";
498 static char secondHeaderItem[] = "Size";
499 static char *items[] = {secondHeaderItem, firstHeaderItem};
500 HDITEM hdItem;
501 hdItem.mask = HDI_TEXT | HDI_WIDTH | HDI_FORMAT;
502 hdItem.fmt = HDF_LEFT;
503 hdItem.cxy = 80;
504 hdItem.cchTextMax = 260;
507 flush_sequences(sequences, NUM_MSG_SEQUENCES);
508 info = HeapAlloc(GetProcessHeap(), 0, sizeof(struct subclass_info));
509 if (!info)
510 return NULL;
512 childHandle = CreateWindowEx(0, WC_HEADER, NULL,
513 WS_CHILD|WS_BORDER|WS_VISIBLE|HDS_BUTTONS|HDS_HORZ,
514 0, 0, 0, 0,
515 hParent, NULL, NULL, NULL);
516 assert(childHandle);
517 if (preloadHeaderItems)
519 for ( loopcnt = 0 ; loopcnt < 2 ; loopcnt++ )
521 hdItem.pszText = items[loopcnt];
522 retVal = SendMessage(childHandle, HDM_INSERTITEM, loopcnt, (LPARAM) &hdItem);
523 ok(retVal == loopcnt, "Adding item %d failed with return value %d\n", ( loopcnt + 1 ), retVal);
527 if (winetest_interactive)
528 ShowWindow (hParent, SW_SHOW);
530 GetClientRect(hParent,&rectwin);
531 hlayout.prc = &rectwin;
532 hlayout.pwpos = &winpos;
533 SendMessageA(childHandle,HDM_LAYOUT,0,(LPARAM) &hlayout);
534 SetWindowPos(childHandle, winpos.hwndInsertAfter, winpos.x, winpos.y,
535 winpos.cx, winpos.cy, 0);
537 info->oldproc = (WNDPROC)SetWindowLongPtrA(childHandle, GWLP_WNDPROC,
538 (LONG_PTR)header_subclass_proc);
539 SetWindowLongPtrA(childHandle, GWLP_USERDATA, (LONG_PTR)info);
540 return childHandle;
543 static void check_auto_format(void)
545 HDITEMA hdiCreate;
546 HDITEMA hdiRead;
547 static CHAR text[] = "Test";
548 ZeroMemory(&hdiCreate, sizeof(HDITEMA));
550 /* Windows implicitly sets some format bits in INSERTITEM */
552 /* HDF_STRING is automatically set and cleared for no text */
553 hdiCreate.mask = HDI_TEXT|HDI_WIDTH|HDI_FORMAT;
554 hdiCreate.pszText = text;
555 hdiCreate.cxy = 100;
556 hdiCreate.fmt=HDF_CENTER;
557 addReadDelItem(hWndHeader, &hdiCreate, HDI_FORMAT, &hdiRead);
558 ok(hdiRead.fmt == (HDF_STRING|HDF_CENTER), "HDF_STRING not set automatically (fmt=%x)\n", hdiRead.fmt);
560 hdiCreate.mask = HDI_WIDTH|HDI_FORMAT;
561 hdiCreate.pszText = text;
562 hdiCreate.fmt = HDF_CENTER|HDF_STRING;
563 addReadDelItem(hWndHeader, &hdiCreate, HDI_FORMAT, &hdiRead);
564 ok(hdiRead.fmt == (HDF_CENTER), "HDF_STRING should be automatically cleared (fmt=%x)\n", hdiRead.fmt);
566 /* HDF_BITMAP is automatically set and cleared for a NULL bitmap or no bitmap */
567 hdiCreate.mask = HDI_BITMAP|HDI_WIDTH|HDI_FORMAT;
568 hdiCreate.hbm = CreateBitmap(16, 16, 1, 8, NULL);
569 hdiCreate.fmt = HDF_CENTER;
570 addReadDelItem(hWndHeader, &hdiCreate, HDI_FORMAT, &hdiRead);
571 ok(hdiRead.fmt == (HDF_BITMAP|HDF_CENTER), "HDF_BITMAP not set automatically (fmt=%x)\n", hdiRead.fmt);
572 DeleteObject(hdiCreate.hbm);
574 hdiCreate.hbm = NULL;
575 hdiCreate.fmt = HDF_CENTER|HDF_BITMAP;
576 addReadDelItem(hWndHeader, &hdiCreate, HDI_FORMAT, &hdiRead);
577 ok(hdiRead.fmt == HDF_CENTER, "HDF_BITMAP not cleared automatically for NULL bitmap (fmt=%x)\n", hdiRead.fmt);
579 hdiCreate.mask = HDI_WIDTH|HDI_FORMAT;
580 hdiCreate.fmt = HDF_CENTER|HDF_BITMAP;
581 addReadDelItem(hWndHeader, &hdiCreate, HDI_FORMAT, &hdiRead);
582 ok(hdiRead.fmt == HDF_CENTER, "HDF_BITMAP not cleared automatically for no bitmap (fmt=%x)\n", hdiRead.fmt);
584 /* HDF_IMAGE is automatically set but not cleared */
585 hdiCreate.mask = HDI_IMAGE|HDI_WIDTH|HDI_FORMAT;
586 hdiCreate.iImage = 17;
587 addReadDelItem(hWndHeader, &hdiCreate, HDI_FORMAT, &hdiRead);
588 ok(hdiRead.fmt == (HDF_IMAGE|HDF_CENTER), "HDF_IMAGE not set automatically (fmt=%x)\n", hdiRead.fmt);
590 hdiCreate.mask = HDI_WIDTH|HDI_FORMAT;
591 hdiCreate.fmt = HDF_CENTER|HDF_IMAGE;
592 hdiCreate.iImage = 0;
593 addReadDelItem(hWndHeader, &hdiCreate, HDI_FORMAT, &hdiRead);
594 ok(hdiRead.fmt == (HDF_CENTER|HDF_IMAGE), "HDF_IMAGE shouldn't be cleared automatically (fmt=%x)\n", hdiRead.fmt);
597 static void check_auto_fields(void)
599 HDITEMA hdiCreate;
600 HDITEMA hdiRead;
601 static CHAR text[] = "Test";
602 LONG res;
604 /* Windows stores the format, width, lparam even if they are not in the item's mask */
605 ZeroMemory(&hdiCreate, sizeof(HDITEMA));
606 hdiCreate.mask = HDI_TEXT;
607 hdiCreate.cxy = 100;
608 hdiCreate.pszText = text;
609 addReadDelItem(hWndHeader, &hdiCreate, HDI_WIDTH, &hdiRead);
610 TEST_GET_ITEMCOUNT(6);
611 ok(hdiRead.cxy == hdiCreate.cxy, "cxy should be automatically set\n");
613 ZeroMemory(&hdiCreate, sizeof(HDITEMA));
614 hdiCreate.mask = HDI_TEXT;
615 hdiCreate.pszText = text;
616 hdiCreate.lParam = 0x12345678;
617 addReadDelItem(hWndHeader, &hdiCreate, HDI_LPARAM, &hdiRead);
618 TEST_GET_ITEMCOUNT(6);
619 ok(hdiRead.lParam == hdiCreate.lParam, "lParam should be automatically set\n");
621 ZeroMemory(&hdiCreate, sizeof(HDITEMA));
622 hdiCreate.mask = HDI_TEXT;
623 hdiCreate.pszText = text;
624 hdiCreate.fmt = HDF_STRING|HDF_CENTER;
625 addReadDelItem(hWndHeader, &hdiCreate, HDI_FORMAT, &hdiRead);
626 TEST_GET_ITEMCOUNT(6);
627 ok(hdiRead.fmt == hdiCreate.fmt, "fmt should be automatically set\n");
629 /* others fields are not set */
630 ZeroMemory(&hdiCreate, sizeof(HDITEMA));
631 hdiCreate.mask = HDI_TEXT;
632 hdiCreate.pszText = text;
633 hdiCreate.hbm = CreateBitmap(16, 16, 1, 8, NULL);
634 addReadDelItem(hWndHeader, &hdiCreate, HDI_BITMAP, &hdiRead);
635 TEST_GET_ITEMCOUNT(6);
636 ok(hdiRead.hbm == NULL, "hbm should not be automatically set\n");
637 DeleteObject(hdiCreate.hbm);
639 ZeroMemory(&hdiCreate, sizeof(HDITEMA));
640 hdiCreate.mask = HDI_IMAGE;
641 hdiCreate.iImage = 17;
642 hdiCreate.pszText = text;
643 addReadDelItem(hWndHeader, &hdiCreate, HDI_TEXT, &hdiRead);
644 TEST_GET_ITEMCOUNT(6);
645 ok(hdiRead.pszText==NULL, "pszText shouldn't be automatically set\n");
647 /* field from comctl >4.0 not tested as the system probably won't touch them */
650 static void check_mask(void)
652 HDITEMA hdi;
653 static CHAR text[] = "ABC";
654 LRESULT ret;
656 /* don't create items if the mask is zero */
657 ZeroMemory(&hdi, sizeof(hdi));
658 hdi.mask = 0;
659 hdi.cxy = 200;
660 hdi.pszText = text;
661 hdi.fmt = 0;
662 hdi.iOrder = 0;
663 hdi.lParam = 17;
664 hdi.cchTextMax = 260;
665 ret = SendMessage(hWndHeader, HDM_INSERTITEM, 0, (LPARAM)&hdi);
666 ok(ret == -1, "Creating an item with a zero mask should have failed\n");
667 if (ret != -1) SendMessage(hWndHeader, HDM_DELETEITEM, 0, 0);
669 /* with a non-zero mask creation will succeed */
670 ZeroMemory(&hdi, sizeof(hdi));
671 hdi.mask = HDI_LPARAM;
672 ret = SendMessage(hWndHeader, HDM_INSERTITEM, 0, (LPARAM)&hdi);
673 ok(ret != -1, "Adding item with non-zero mask failed\n");
674 if (ret != -1)
675 SendMessage(hWndHeader, HDM_DELETEITEM, 0, 0);
677 /* in SETITEM if the mask contains a unknown bit, it is ignored */
678 ZeroMemory(&hdi, sizeof(hdi));
679 hdi.mask = 0x08000000 | HDI_LPARAM | HDI_IMAGE;
680 hdi.lParam = 133;
681 hdi.iImage = 17;
682 ret = SendMessage(hWndHeader, HDM_INSERTITEM, 0, (LPARAM)&hdi);
683 ok(ret != -1, "Adding item failed\n");
685 if (ret != -1)
687 /* check result */
688 ZeroMemory(&hdi, sizeof(hdi));
689 hdi.mask = HDI_LPARAM | HDI_IMAGE;
690 SendMessage(hWndHeader, HDM_GETITEM, 0, (LPARAM)&hdi);
691 ok(hdi.lParam == 133, "comctl32 4.0 field not set\n");
692 ok(hdi.iImage == 17, "comctl32 >4.0 field not set\n");
694 /* but in GETITEM if an unknown bit is set, comctl32 uses only version 4.0 fields */
695 ZeroMemory(&hdi, sizeof(hdi));
696 hdi.mask = 0x08000000 | HDI_LPARAM | HDI_IMAGE;
697 SendMessage(hWndHeader, HDM_GETITEM, 0, (LPARAM)&hdi);
698 ok(hdi.lParam == 133, "comctl32 4.0 field not read\n");
699 ok(hdi.iImage == 0, "comctl32 >4.0 field shouldn't be read\n");
701 SendMessage(hWndHeader, HDM_DELETEITEM, 0, 0);
705 static void test_header_control (void)
707 LONG res;
708 static char buffer[MAX_CHARS];
709 int i;
711 hWndHeader = create_header_control ();
713 for (i = 3; i >= 0; i--)
715 TEST_GET_ITEMCOUNT(3-i);
716 res = addItem(hWndHeader, 0, str_items[i]);
717 ok(res == 0, "Adding simple item failed (%d)\n", res);
720 TEST_GET_ITEMCOUNT(4);
721 res = addItem(hWndHeader, 99, str_items[i+1]);
722 ok(res != -1, "Adding Out of Range item should fail with -1 got (%d)\n", res);
723 TEST_GET_ITEMCOUNT(5);
724 res = addItem(hWndHeader, 5, str_items[i+1]);
725 ok(res != -1, "Adding Out of Range item should fail with -1 got (%d)\n", res);
726 TEST_GET_ITEMCOUNT(6);
728 for (i = 0; i < 4; i++) { TEST_GET_ITEM(i,i); TEST_GET_ITEMCOUNT(6); }
730 res=getItem(hWndHeader, 99, buffer);
731 ok(res == 0, "Getting Out of Range item should fail with 0 (%d), got %s\n", res,buffer);
732 res=getItem(hWndHeader, 5, buffer);
733 ok(res == 1, "Getting Out of Range item should fail with 1 (%d), got %s\n", res,buffer);
734 res=getItem(hWndHeader, -2, buffer);
735 ok(res == 0, "Getting Out of Range item should fail with 0 (%d), got %s\n", res,buffer);
737 if (winetest_interactive)
739 UpdateWindow(hHeaderParentWnd);
740 UpdateWindow(hWndHeader);
743 TEST_GET_ITEMCOUNT(6);
744 res=setItem(hWndHeader, 99, str_items[5], FALSE);
745 ok(res == 0, "Setting Out of Range item should fail with 0 (%d)\n", res);
746 res=setItem(hWndHeader, 5, str_items[5], TRUE);
747 ok(res == 1, "Setting Out of Range item should fail with 1 (%d)\n", res);
748 res=setItem(hWndHeader, -2, str_items[5], FALSE);
749 ok(res == 0, "Setting Out of Range item should fail with 0 (%d)\n", res);
750 TEST_GET_ITEMCOUNT(6);
752 for (i = 0; i < 4; i++)
754 res = setItem(hWndHeader, i, str_items[4], TRUE);
755 ok(res != 0, "Setting %d item failed (%d)\n", i+1, res);
756 TEST_GET_ITEM(i, 4);
757 TEST_GET_ITEMCOUNT(6);
760 SendMessageA(hWndHeader, HDM_SETUNICODEFORMAT, (WPARAM)TRUE, 0);
761 setItemUnicodeNotify(hWndHeader, 3, pszUniTestA, pszUniTestW);
762 SendMessageA(hWndHeader, WM_NOTIFYFORMAT, (WPARAM)hHeaderParentWnd, (LPARAM)NF_REQUERY);
763 setItem(hWndHeader, 3, str_items[4], TRUE);
765 dont_expect_notify(HDN_GETDISPINFOA);
766 dont_expect_notify(HDN_GETDISPINFOW);
767 addItem(hWndHeader, 0, LPSTR_TEXTCALLBACKA);
768 setItem(hWndHeader, 0, str_items[4], TRUE);
769 /* unexpected notifies cleared by notifies_received in setItem */
770 dont_expect_notify(HDN_GETDISPINFOA);
771 dont_expect_notify(HDN_GETDISPINFOW);
772 setItem(hWndHeader, 0, LPSTR_TEXTCALLBACKA, TRUE);
773 /* unexpected notifies cleared by notifies_received in setItem */
774 delItem(hWndHeader, 0);
776 check_auto_format();
777 TEST_GET_ITEMCOUNT(6);
778 check_auto_fields();
779 TEST_GET_ITEMCOUNT(6);
780 check_mask();
781 TEST_GET_ITEMCOUNT(6);
783 res = delItem(hWndHeader, 5);
784 ok(res == 1, "Deleting Out of Range item should fail with 1 (%d)\n", res);
785 res = delItem(hWndHeader, -2);
786 ok(res == 0, "Deleting Out of Range item should fail with 0 (%d)\n", res);
787 TEST_GET_ITEMCOUNT(5);
789 res = delItem(hWndHeader, 3);
790 ok(res != 0, "Deleting using out of range index failed (%d)\n", res);
791 TEST_GET_ITEMCOUNT(4);
792 res = delItem(hWndHeader, 0);
793 ok(res != 0, "Deleting using out of range index failed (%d)\n", res);
794 TEST_GET_ITEMCOUNT(3);
795 res = delItem(hWndHeader, 0);
796 ok(res != 0, "Deleting using out of range index failed (%d)\n", res);
797 TEST_GET_ITEMCOUNT(2);
798 res = delItem(hWndHeader, 0);
799 ok(res != 0, "Deleting using out of range index failed (%d)\n", res);
800 TEST_GET_ITEMCOUNT(1);
802 DestroyWindow(hWndHeader);
805 static void test_hdm_getitemrect(HWND hParent)
808 HWND hChild;
809 RECT rect;
810 int retVal;
812 flush_sequences(sequences, NUM_MSG_SEQUENCES);
813 hChild = create_custom_header_control(hParent, TRUE);
814 ok_sequence(sequences, PARENT_SEQ_INDEX, add_header_to_parent_seq,
815 "adder header control to parent", FALSE);
817 retVal = SendMessage(hChild, HDM_GETITEMRECT, 1, (LPARAM) &rect);
818 ok(retVal == TRUE, "Getting item rect should TRUE, got %d\n", retVal);
819 /* check bounding rectangle information of 2nd header item */
820 expect(80, rect.left);
821 expect(0, rect.top);
822 expect(160, rect.right);
823 todo_wine
825 expect(g_customheight, rect.bottom);
827 retVal = SendMessage(hChild, HDM_GETITEMRECT, 0, (LPARAM) &rect);
829 ok(retVal == TRUE, "Getting item rect should TRUE, got %d\n", retVal);
830 /* check bounding rectangle information of 1st header item */
831 expect(0, rect.left);
832 expect(0, rect.top);
834 expect(80, rect.right);
835 todo_wine
837 expect(g_customheight, rect.bottom);
839 retVal = SendMessage(hChild, HDM_GETITEMRECT, 10, (LPARAM) &rect);
840 ok(retVal == 0, "Getting rect of nonexistent item should return 0, got %d\n", retVal);
842 ok_sequence(sequences, HEADER_SEQ_INDEX, getItemRect_seq, "getItemRect sequence testing", FALSE);
843 DestroyWindow(hChild);
846 static void test_hdm_layout(HWND hParent)
848 HWND hChild;
849 int retVal;
850 RECT rect;
851 HDLAYOUT hdLayout;
852 WINDOWPOS windowPos;
853 hdLayout.prc = &rect;
854 hdLayout.pwpos = &windowPos;
856 flush_sequences(sequences, NUM_MSG_SEQUENCES);
857 hChild = create_custom_header_control(hParent, TRUE);
858 ok_sequence(sequences, PARENT_SEQ_INDEX, add_header_to_parent_seq,
859 "adder header control to parent", FALSE);
861 flush_sequences(sequences, NUM_MSG_SEQUENCES);
862 retVal = SendMessage(hChild, HDM_LAYOUT, 0, (LPARAM) &hdLayout);
863 expect(TRUE, retVal);
865 ok_sequence(sequences, HEADER_SEQ_INDEX, layout_seq, "layout sequence testing", FALSE);
867 DestroyWindow(hChild);
870 static void test_hdm_ordertoindex(HWND hParent)
872 HWND hChild;
873 int retVal;
875 flush_sequences(sequences, NUM_MSG_SEQUENCES);
876 hChild = create_custom_header_control(hParent, TRUE);
877 ok_sequence(sequences, PARENT_SEQ_INDEX, add_header_to_parent_seq,
878 "adder header control to parent", FALSE);
880 flush_sequences(sequences, NUM_MSG_SEQUENCES);
881 retVal = SendMessage(hChild, HDM_ORDERTOINDEX, 1, 0);
882 expect(1, retVal);
884 ok_sequence(sequences, HEADER_SEQ_INDEX, orderToIndex_seq, "orderToIndex sequence testing", FALSE);
885 DestroyWindow(hChild);
888 static void test_hdm_hittest(HWND hParent)
890 HWND hChild;
891 int retVal;
892 POINT pt;
893 HDHITTESTINFO hdHitTestInfo;
894 const int firstItemRightBoundary = 80;
895 const int secondItemRightBoundary = 160;
896 const int bottomBoundary = g_customheight;
898 pt.x = firstItemRightBoundary - 1;
899 pt.y = bottomBoundary - 1;
900 hdHitTestInfo.pt = pt;
903 flush_sequences(sequences, NUM_MSG_SEQUENCES);
904 hChild = create_custom_header_control(hParent, TRUE);
905 ok_sequence(sequences, PARENT_SEQ_INDEX, add_header_to_parent_seq,
906 "adder header control to parent", FALSE);
908 flush_sequences(sequences, NUM_MSG_SEQUENCES);
909 retVal = SendMessage(hChild, HDM_HITTEST, 0, (LPARAM) &hdHitTestInfo);
910 todo_wine
912 expect(0, retVal);
913 expect(0, hdHitTestInfo.iItem);
916 pt.x = secondItemRightBoundary - 1;
917 pt.y = bottomBoundary - 1;
918 hdHitTestInfo.pt = pt;
919 retVal = SendMessage(hChild, HDM_HITTEST, 1, (LPARAM) &hdHitTestInfo);
920 todo_wine
922 expect(1, retVal);
924 expect(1, hdHitTestInfo.iItem);
926 pt.x = secondItemRightBoundary;
927 pt.y = bottomBoundary + 1;
928 hdHitTestInfo.pt = pt;
929 todo_wine
931 retVal = SendMessage(hChild, HDM_HITTEST, 0, (LPARAM) &hdHitTestInfo);
932 expect(-1, retVal);
935 ok_sequence(sequences, HEADER_SEQ_INDEX, hittest_seq, "hittest sequence testing", FALSE);
937 DestroyWindow(hChild);
940 static void test_hdm_sethotdivider(HWND hParent)
942 HWND hChild;
943 int retVal;
944 /* low word: x coordinate = 5
945 * high word: y coordinate = 5
948 flush_sequences(sequences, NUM_MSG_SEQUENCES);
949 hChild = create_custom_header_control(hParent, TRUE);
950 ok_sequence(sequences, PARENT_SEQ_INDEX, add_header_to_parent_seq,
951 "adder header control to parent", FALSE);
953 flush_sequences(sequences, NUM_MSG_SEQUENCES);
954 todo_wine
956 retVal = SendMessage(hChild, HDM_SETHOTDIVIDER, TRUE, 0X00050005);
957 expect(0, retVal);
959 retVal = SendMessage(hChild, HDM_SETHOTDIVIDER, FALSE, 100);
960 expect(100, retVal);
961 retVal = SendMessage(hChild, HDM_SETHOTDIVIDER, FALSE, 1);
962 expect(1, retVal);
963 if (winetest_interactive)
964 ok_sequence(sequences, HEADER_SEQ_INDEX, setHotDivider_seq_interactive,
965 "setHotDivider sequence testing", TRUE);
966 else
967 ok_sequence(sequences, HEADER_SEQ_INDEX, setHotDivider_seq_noninteractive,
968 "setHotDivider sequence testing", FALSE);
970 DestroyWindow(hChild);
973 static void test_hdm_imageMessages(HWND hParent)
975 HIMAGELIST hImageList = ImageList_Create (4, 4, 0, 1, 0);
976 HIMAGELIST hImageListRetVal;
977 HWND hChild;
979 flush_sequences(sequences, NUM_MSG_SEQUENCES);
980 hChild = create_custom_header_control(hParent, TRUE);
981 ok_sequence(sequences, PARENT_SEQ_INDEX, add_header_to_parent_seq,
982 "adder header control to parent", FALSE);
984 flush_sequences(sequences, NUM_MSG_SEQUENCES);
986 hImageListRetVal = (HIMAGELIST) SendMessage(hChild, HDM_SETIMAGELIST, 0, (LPARAM) hImageList);
987 ok(hImageListRetVal == NULL, "Expected NULL, got %p\n", hImageListRetVal);
989 hImageListRetVal = (HIMAGELIST) SendMessage(hChild, HDM_GETIMAGELIST, 0, 0);
990 ok(hImageListRetVal != NULL, "Expected non-NULL handle, got %p\n", hImageListRetVal);
992 hImageListRetVal = (HIMAGELIST) SendMessage(hChild, HDM_CREATEDRAGIMAGE, 0, 0);
993 ok(hImageListRetVal != NULL, "Expected non-NULL handle, got %p\n", hImageListRetVal);
995 ok_sequence(sequences, HEADER_SEQ_INDEX, imageMessages_seq, "imageMessages sequence testing", FALSE);
997 DestroyWindow(hChild);
1000 static void test_hdm_filterMessages(HWND hParent)
1002 HWND hChild;
1003 int retVal, timeout;
1005 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1006 hChild = create_custom_header_control(hParent, TRUE);
1007 assert(hChild);
1008 ok_sequence(sequences, PARENT_SEQ_INDEX, add_header_to_parent_seq,
1009 "adder header control to parent", FALSE);
1011 timeout = SendMessage(hChild, HDM_SETFILTERCHANGETIMEOUT, 1, 100);
1012 SendMessage(hChild, HDM_SETFILTERCHANGETIMEOUT, 1, timeout);
1014 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1016 /* msdn incorrectly states that return value
1017 * is the index of the filter control being
1018 * modified. The sendMessage here should
1019 * return previous filter timeout value
1022 retVal = SendMessage(hChild, HDM_SETFILTERCHANGETIMEOUT, 1, 100);
1023 expect(timeout, retVal);
1025 todo_wine
1027 retVal = SendMessage(hChild, HDM_CLEARFILTER, 0, 1);
1028 expect(1, retVal);
1029 retVal = SendMessage(hChild, HDM_EDITFILTER, 1, 0);
1030 expect(1, retVal);
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 /* Some Win9x versions don't send a WM_KILLFOCUS.
1039 * Set the focus explicitly to the parent to avoid a crash.
1041 SetFocus(hParent);
1042 DestroyWindow(hChild);
1046 static void test_hdm_unicodeformatMessages(HWND hParent)
1048 HWND hChild;
1049 int retVal;
1051 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1052 hChild = create_custom_header_control(hParent, TRUE);
1053 ok_sequence(sequences, PARENT_SEQ_INDEX, add_header_to_parent_seq,
1054 "adder header control to parent", FALSE);
1056 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1057 retVal = SendMessage(hChild, HDM_SETUNICODEFORMAT, TRUE, 0);
1058 expect(0, retVal);
1059 retVal = SendMessage(hChild, HDM_GETUNICODEFORMAT, 0, 0);
1060 expect(1, retVal);
1062 ok_sequence(sequences, HEADER_SEQ_INDEX, unicodeformatMessages_seq,
1063 "unicodeformatMessages sequence testing", FALSE);
1064 DestroyWindow(hChild);
1067 static void test_hdm_bitmapmarginMessages(HWND hParent)
1069 HWND hChild;
1070 int retVal;
1072 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1073 hChild = create_custom_header_control(hParent, TRUE);
1074 ok_sequence(sequences, PARENT_SEQ_INDEX, add_header_to_parent_seq,
1075 "adder header control to parent", FALSE);
1077 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1078 retVal = SendMessage(hChild, HDM_GETBITMAPMARGIN, 0, 0);
1079 expect(6, retVal);
1081 ok_sequence(sequences, HEADER_SEQ_INDEX, bitmapmarginMessages_seq,
1082 "bitmapmarginMessages sequence testing", FALSE);
1083 DestroyWindow(hChild);
1086 static void test_hdm_index_messages(HWND hParent)
1089 HWND hChild;
1090 int retVal;
1091 int loopcnt;
1092 int strcmpResult;
1093 int iSize;
1094 static const int lpiarray[2] = {1, 0};
1095 static int lpiarrayReceived[2];
1096 static char firstHeaderItem[] = "Name";
1097 static char secondHeaderItem[] = "Size";
1098 static char thirdHeaderItem[] = "Type";
1099 static char fourthHeaderItem[] = "Date Modified";
1100 static char *items[] = {firstHeaderItem, secondHeaderItem, thirdHeaderItem, fourthHeaderItem};
1101 HDITEM hdItem;
1102 hdItem.mask = HDI_TEXT | HDI_WIDTH | HDI_FORMAT;
1103 hdItem.fmt = HDF_LEFT;
1104 hdItem.cxy = 80;
1105 hdItem.cchTextMax = 260;
1107 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1108 hChild = create_custom_header_control(hParent, FALSE);
1109 if (winetest_interactive)
1110 ok_sequence(sequences, PARENT_SEQ_INDEX, add_header_to_parent_seq_interactive,
1111 "adder header control to parent", TRUE);
1112 else
1113 ok_sequence(sequences, PARENT_SEQ_INDEX, add_header_to_parent_seq,
1114 "adder header control to parent", FALSE);
1115 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1116 for ( loopcnt = 0 ; loopcnt < 4 ; loopcnt++ )
1118 hdItem.pszText = items[loopcnt];
1119 retVal = SendMessage(hChild, HDM_INSERTITEM, loopcnt, (LPARAM) &hdItem);
1120 ok(retVal == loopcnt, "Adding item %d failed with return value %d\n", ( loopcnt + 1 ), retVal);
1122 ok_sequence(sequences, HEADER_SEQ_INDEX, insertItem_seq, "insertItem sequence testing", FALSE);
1124 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1126 retVal = SendMessage(hChild, HDM_DELETEITEM, 3, (LPARAM) &hdItem);
1127 ok(retVal == TRUE, "Deleting item 3 should return TRUE, got %d\n", retVal);
1128 retVal = SendMessage(hChild, HDM_GETITEMCOUNT, 0, (LPARAM) &hdItem);
1129 ok(retVal == 3, "Getting item count should return 3, got %d\n", retVal);
1131 retVal = SendMessage(hChild, HDM_DELETEITEM, 3, (LPARAM) &hdItem);
1132 ok(retVal == FALSE, "Deleting already-deleted item should return FALSE, got %d\n", retVal);
1133 retVal = SendMessage(hChild, HDM_GETITEMCOUNT, 0, (LPARAM) &hdItem);
1134 ok(retVal == 3, "Getting item count should return 3, got %d\n", retVal);
1136 retVal = SendMessage(hChild, HDM_DELETEITEM, 2, (LPARAM) &hdItem);
1137 ok(retVal == TRUE, "Deleting item 2 should return TRUE, got %d\n", retVal);
1138 retVal = SendMessage(hChild, HDM_GETITEMCOUNT, 0, (LPARAM) &hdItem);
1139 ok(retVal == 2, "Getting item count should return 2, got %d\n", retVal);
1141 ok_sequence(sequences, HEADER_SEQ_INDEX, deleteItem_getItemCount_seq,
1142 "deleteItem_getItemCount sequence testing", FALSE);
1144 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1146 retVal = SendMessage(hChild, HDM_GETITEM, 3, (LPARAM) &hdItem);
1147 ok(retVal == FALSE, "Getting already-deleted item should return FALSE, got %d\n", retVal);
1149 retVal = SendMessage(hChild, HDM_GETITEM, 0, (LPARAM) &hdItem);
1150 ok(retVal == TRUE, "Getting the 1st header item should return TRUE, got %d\n", retVal);
1152 ok_sequence(sequences, HEADER_SEQ_INDEX, getItem_seq, "getItem sequence testing", FALSE);
1154 /* check if the item is the right one */
1155 strcmpResult = strcmp(hdItem.pszText, firstHeaderItem);
1156 expect(0, strcmpResult);
1157 expect(80, hdItem.cxy);
1159 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1161 iSize = SendMessage(hChild, HDM_GETITEMCOUNT, 0, (LPARAM) &hdItem);
1162 retVal = SendMessage(hChild, HDM_SETORDERARRAY, iSize, (LPARAM) lpiarray);
1163 ok(retVal == TRUE, "Setting header items order should return TRUE, got %d\n", retVal);
1165 retVal = SendMessage(hChild, HDM_GETORDERARRAY, iSize, (LPARAM) lpiarrayReceived);
1166 ok(retVal == TRUE, "Getting header items order should return TRUE, got %d\n", retVal);
1168 ok_sequence(sequences, HEADER_SEQ_INDEX, orderArray_seq, "set_get_orderArray sequence testing", FALSE);
1170 /* check if the array order is set correctly and the size of the array is correct. */
1171 expect(2, iSize);
1172 expect(lpiarray[0], lpiarrayReceived[0]);
1173 expect(lpiarray[1], lpiarrayReceived[1]);
1175 hdItem.mask = HDI_FORMAT;
1176 hdItem.fmt = HDF_CENTER | HDF_STRING;
1178 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1180 retVal = SendMessage(hChild, HDM_SETITEM, 0, (LPARAM) &hdItem);
1181 ok(retVal == TRUE, "Aligning 1st header item to center should return TRUE, got %d\n", retVal);
1182 hdItem.fmt = HDF_RIGHT | HDF_STRING;
1183 retVal = SendMessage(hChild, HDM_SETITEM, 1, (LPARAM) &hdItem);
1184 ok(retVal == TRUE, "Aligning 2nd header item to right should return TRUE, got %d\n", retVal);
1186 ok_sequence(sequences, HEADER_SEQ_INDEX, setItem_seq, "setItem sequence testing", FALSE);
1187 DestroyWindow(hChild);
1190 #define TEST_NMCUSTOMDRAW(draw_stage, item_spec, lparam, _left, _top, _right, _bottom) \
1191 ok(nm->dwDrawStage == draw_stage, "Invalid dwDrawStage %d vs %d\n", draw_stage, nm->dwDrawStage); \
1192 if (item_spec != -1) \
1193 ok(nm->dwItemSpec == item_spec, "Invalid dwItemSpec %d vs %ld\n", item_spec, nm->dwItemSpec); \
1194 ok(nm->lItemlParam == lparam, "Invalid lItemlParam %d vs %ld\n", lparam, nm->lItemlParam); \
1195 ok(nm->rc.top == _top && nm->rc.bottom == _bottom && nm->rc.left == _left && nm->rc.right == _right, \
1196 "Invalid rect (%d,%d) (%d,%d) vs (%d,%d) (%d,%d)\n", _left, _top, _right, _bottom, \
1197 nm->rc.left, nm->rc.top, nm->rc.right, nm->rc.bottom);
1199 static LRESULT customdraw_1(int n, NMCUSTOMDRAW *nm)
1201 if (nm == NULL) { /* test ended */
1202 ok(n==1, "NM_CUSTOMDRAW messages: %d, expected: 1\n", n);
1203 return 0;
1206 switch (n)
1208 case 0:
1209 /* don't test dwItemSpec - it's 0 no comctl5 but 1308756 on comctl6 */
1210 TEST_NMCUSTOMDRAW(CDDS_PREPAINT, -1, 0, 0, 0, 670, g_customheight);
1211 return 0;
1214 ok(FALSE, "To many custom draw messages (n=%d, nm->dwDrawStage=%d)\n", n, nm->dwDrawStage);
1215 return -1;
1218 static LRESULT customdraw_2(int n, NMCUSTOMDRAW *nm)
1220 if (nm == NULL) { /* test ended */
1221 ok(n==4, "NM_CUSTOMDRAW messages: %d, expected: 4\n", n);
1222 return 0;
1225 switch (n)
1227 case 0:
1228 TEST_NMCUSTOMDRAW(CDDS_PREPAINT, -1, 0, 0, 0, 670, g_customheight);
1229 return CDRF_NOTIFYITEMDRAW;
1230 case 1:
1231 TEST_NMCUSTOMDRAW(CDDS_ITEMPREPAINT, 0, 0, 0, 0, 50, g_customheight);
1232 return 0;
1233 case 2:
1234 TEST_NMCUSTOMDRAW(CDDS_ITEMPREPAINT, 1, 5, 50, 0, 150, g_customheight);
1235 return 0;
1236 case 3:
1237 TEST_NMCUSTOMDRAW(CDDS_ITEMPREPAINT, 2, 10, 150, 0, 300, g_customheight);
1238 return 0;
1241 ok(FALSE, "To many custom draw messages (n=%d, nm->dwDrawStage=%d)\n", n, nm->dwDrawStage);
1242 return 0;
1245 static LRESULT customdraw_3(int n, NMCUSTOMDRAW *nm)
1247 if (nm == NULL) { /* test ended */
1248 ok(n==5, "NM_CUSTOMDRAW messages: %d, expected: 5\n", n);
1249 return 0;
1252 switch (n)
1254 case 0:
1255 TEST_NMCUSTOMDRAW(CDDS_PREPAINT, -1, 0, 0, 0, 670, g_customheight);
1256 return CDRF_NOTIFYITEMDRAW|CDRF_NOTIFYPOSTERASE|CDRF_NOTIFYPOSTPAINT|CDRF_SKIPDEFAULT;
1257 case 1:
1258 TEST_NMCUSTOMDRAW(CDDS_ITEMPREPAINT, 0, 0, 0, 0, 50, g_customheight);
1259 return 0;
1260 case 2:
1261 TEST_NMCUSTOMDRAW(CDDS_ITEMPREPAINT, 1, 5, 50, 0, 150, g_customheight);
1262 return 0;
1263 case 3:
1264 TEST_NMCUSTOMDRAW(CDDS_ITEMPREPAINT, 2, 10, 150, 0, 300, g_customheight);
1265 return 0;
1266 case 4:
1267 TEST_NMCUSTOMDRAW(CDDS_POSTPAINT, -1, 0, 0, 0, 670, g_customheight);
1268 return 0;
1271 ok(FALSE, "To many custom draw messages (n=%d, nm->dwDrawStage=%d)\n", n, nm->dwDrawStage);
1272 return 0;
1276 static LRESULT customdraw_4(int n, NMCUSTOMDRAW *nm)
1278 if (nm == NULL) { /* test ended */
1279 ok(n==4, "NM_CUSTOMDRAW messages: %d, expected: 4\n", n);
1280 return 0;
1283 switch (n)
1285 case 0:
1286 TEST_NMCUSTOMDRAW(CDDS_PREPAINT, -1, 0, 0, 0, 670, g_customheight);
1287 return CDRF_NOTIFYITEMDRAW|CDRF_NOTIFYPOSTPAINT;
1288 case 1:
1289 TEST_NMCUSTOMDRAW(CDDS_ITEMPREPAINT, 0, 0, 0, 0, 50, g_customheight);
1290 return 0;
1291 case 2:
1292 TEST_NMCUSTOMDRAW(CDDS_ITEMPREPAINT, 2, 10, 150, 0, 300, g_customheight);
1293 return 0;
1294 case 3:
1295 TEST_NMCUSTOMDRAW(CDDS_POSTPAINT, -1, 0, 0, 0, 670, g_customheight);
1296 return 0;
1299 ok(FALSE, "To many custom draw messages (n=%d, nm->dwDrawStage=%d)\n", n, nm->dwDrawStage);
1300 return 0;
1303 static void run_customdraw_scenario(CUSTOMDRAWPROC proc)
1305 g_CustomDrawProc = proc;
1306 g_CustomDrawCount = 0;
1307 InvalidateRect(hWndHeader, NULL, TRUE);
1308 UpdateWindow(hWndHeader);
1309 proc(g_CustomDrawCount, NULL);
1310 g_CustomDrawProc = NULL;
1313 static void test_customdraw(void)
1315 int i;
1316 HDITEM item;
1317 RECT rect;
1318 CHAR name[] = "Test";
1319 hWndHeader = create_header_control();
1320 GetClientRect(hWndHeader, &rect);
1321 ok(rect.right - rect.left == 670 && rect.bottom - rect.top == g_customheight,
1322 "Tests will fail as header size is %dx%d instead of 670x%d\n",
1323 rect.right - rect.left, rect.bottom - rect.top, g_customheight);
1325 for (i = 0; i < 3; i++)
1327 ZeroMemory(&item, sizeof(item));
1328 item.mask = HDI_TEXT|HDI_WIDTH;
1329 item.cxy = 50*(i+1);
1330 item.pszText = name;
1331 item.lParam = i*5;
1332 SendMessage(hWndHeader, HDM_INSERTITEM, i, (LPARAM)&item);
1335 run_customdraw_scenario(customdraw_1);
1336 run_customdraw_scenario(customdraw_2);
1337 run_customdraw_scenario(customdraw_3);
1339 ZeroMemory(&item, sizeof(item));
1340 item.mask = HDI_FORMAT;
1341 item.fmt = HDF_OWNERDRAW;
1342 SendMessage(hWndHeader, HDM_SETITEM, 1, (LPARAM)&item);
1343 g_DrawItem.CtlID = 0;
1344 g_DrawItem.CtlType = ODT_HEADER;
1345 g_DrawItem.hwndItem = hWndHeader;
1346 g_DrawItem.itemID = 1;
1347 g_DrawItem.itemState = 0;
1348 SendMessage(hWndHeader, HDM_GETITEMRECT, 1, (LPARAM)&g_DrawItem.rcItem);
1349 run_customdraw_scenario(customdraw_4);
1350 ok(g_DrawItemReceived, "WM_DRAWITEM not received\n");
1351 DestroyWindow(hWndHeader);
1352 hWndHeader = NULL;
1353 g_DrawItem.CtlType = 0;
1354 g_DrawItemReceived = FALSE;
1357 static void check_order(const int expected_id[], const int expected_order[],
1358 int count, const char *type)
1360 int i;
1361 HDITEMA hdi;
1363 ok(getItemCount(hWndHeader) == count, "Invalid item count in order tests\n");
1364 for (i = 0; i < count; i++)
1366 hdi.mask = HDI_LPARAM|HDI_ORDER;
1367 SendMessage(hWndHeader, HDM_GETITEMA, i, (LPARAM)&hdi);
1368 ok(hdi.lParam == expected_id[i],
1369 "Invalid item ids after '%s'- item %d has lParam %d\n", type, i, (int)hdi.lParam);
1370 ok(hdi.iOrder == expected_order[i],
1371 "Invalid item order after '%s'- item %d has iOrder %d\n", type, i, hdi.iOrder);
1375 static void test_header_order (void)
1377 const int rand1[] = {0, 1, 1, 0, 4};
1378 const int rand2[] = {4, 5, 6, 7, 4};
1379 const int rand3[] = {5, 5, 1, 6, 1};
1380 const int rand4[] = {1, 5, 2, 7, 6, 1, 4, 2, 3, 2};
1381 const int rand5[] = {7, 8, 5, 6, 7, 2, 1, 9, 10, 10};
1382 const int rand6[] = {2, 8, 3, 4, 0};
1384 const int ids1[] = {3, 0, 2, 1, 4};
1385 const int ord1[] = {0, 1, 2, 3, 4};
1386 const int ids2[] = {3, 9, 7, 0, 2, 1, 4, 8, 6, 5};
1387 const int ord2[] = {0, 4, 7, 1, 2, 3, 9, 8, 6, 5};
1388 const int ord3[] = {0, 3, 9, 2, 1, 8, 7, 6, 5, 4};
1389 const int ids4[] = {9, 0, 1, 8, 6};
1390 const int ord4[] = {1, 0, 4, 3, 2};
1392 char buffer[20];
1393 HDITEMA hdi;
1394 int i;
1396 hWndHeader = create_header_control();
1398 ZeroMemory(&hdi, sizeof(HDITEMA));
1399 hdi.mask = HDI_TEXT | HDI_LPARAM;
1400 hdi.pszText = buffer;
1401 strcpy(buffer, "test");
1403 for (i = 0; i < 5; i++)
1405 hdi.lParam = i;
1406 SendMessage(hWndHeader, HDM_INSERTITEMA, rand1[i], (LPARAM)&hdi);
1407 rand();
1409 check_order(ids1, ord1, 5, "insert without iOrder");
1411 hdi.mask |= HDI_ORDER;
1412 for (i = 0; i < 5; i++)
1414 hdi.lParam = i + 5;
1415 hdi.iOrder = rand2[i];
1416 SendMessage(hWndHeader, HDM_INSERTITEMA, rand3[i], (LPARAM)&hdi);
1417 rand(); rand();
1419 check_order(ids2, ord2, 10, "insert with order");
1421 hdi.mask = HDI_ORDER;
1422 for (i=0; i<10; i++)
1424 hdi.iOrder = rand5[i];
1425 SendMessage(hWndHeader, HDM_SETITEMA, rand4[i], (LPARAM)&hdi);
1426 rand(); rand();
1428 check_order(ids2, ord3, 10, "setitems changing order");
1430 for (i=0; i<5; i++)
1431 SendMessage(hWndHeader, HDM_DELETEITEM, rand6[i], 0);
1432 check_order(ids4, ord4, 5, "deleteitem");
1434 DestroyWindow(hWndHeader);
1437 static LRESULT CALLBACK HeaderTestWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
1439 DRAWITEMSTRUCT *di;
1440 switch(msg) {
1442 case WM_NOTIFY:
1444 NMHEADERA *hdr = (NMHEADER *)lParam;
1445 EXPECTEDNOTIFY *expected;
1446 int i;
1448 if (hdr->hdr.code == NM_CUSTOMDRAW)
1449 if (g_CustomDrawProc)
1450 return g_CustomDrawProc(g_CustomDrawCount++, (NMCUSTOMDRAW*)hdr);
1452 for (i=0; i<nUnexpectedNotify; i++)
1453 ok(hdr->hdr.code != unexpectedNotify[i], "Received invalid notify %d\n", hdr->hdr.code);
1455 if (nReceivedNotify >= nExpectedNotify || hdr->hdr.hwndFrom != hWndHeader )
1456 break;
1458 expected = &expectedNotify[nReceivedNotify];
1459 if (hdr->hdr.code != expected->iCode)
1460 break;
1462 nReceivedNotify++;
1463 compare_items(hdr->hdr.code, &expected->hdItem, hdr->pitem, expected->fUnicode);
1464 break;
1467 case WM_DRAWITEM:
1468 di = (DRAWITEMSTRUCT *)lParam;
1469 ok(g_DrawItem.CtlType != 0, "Unexpected WM_DRAWITEM\n");
1470 if (g_DrawItem.CtlType == 0) return 0;
1471 g_DrawItemReceived = TRUE;
1472 compare(di->CtlType, g_DrawItem.CtlType, "%d");
1473 compare(di->CtlID, g_DrawItem.CtlID, "%d");
1474 compare(di->hwndItem, g_DrawItem.hwndItem, "%p");
1475 compare(di->itemID, g_DrawItem.itemID, "%d");
1476 compare(di->itemState, g_DrawItem.itemState, "%d");
1477 compare(di->rcItem.left, g_DrawItem.rcItem.left, "%d");
1478 compare(di->rcItem.top, g_DrawItem.rcItem.top, "%d");
1479 compare(di->rcItem.right, g_DrawItem.rcItem.right, "%d");
1480 compare(di->rcItem.bottom, g_DrawItem.rcItem.bottom, "%d");
1481 break;
1483 case WM_DESTROY:
1484 PostQuitMessage(0);
1485 break;
1487 default:
1488 return DefWindowProcA(hWnd, msg, wParam, lParam);
1491 return 0L;
1494 static int init(void)
1496 HMODULE hComctl32;
1497 BOOL (WINAPI *pInitCommonControlsEx)(const INITCOMMONCONTROLSEX*);
1498 WNDCLASSA wc;
1499 INITCOMMONCONTROLSEX iccex;
1500 TEXTMETRICA tm;
1501 HFONT hOldFont;
1502 HDC hdc;
1504 hComctl32 = GetModuleHandleA("comctl32.dll");
1505 pInitCommonControlsEx = (void*)GetProcAddress(hComctl32, "InitCommonControlsEx");
1506 if (!pInitCommonControlsEx)
1508 skip("InitCommonControlsEx() is missing. Skipping the tests\n");
1509 return 0;
1512 iccex.dwSize = sizeof(iccex);
1513 iccex.dwICC = ICC_USEREX_CLASSES;
1514 pInitCommonControlsEx(&iccex);
1516 wc.style = CS_HREDRAW | CS_VREDRAW;
1517 wc.cbClsExtra = 0;
1518 wc.cbWndExtra = 0;
1519 wc.hInstance = GetModuleHandleA(NULL);
1520 wc.hIcon = NULL;
1521 wc.hCursor = LoadCursorA(NULL, IDC_ARROW);
1522 wc.hbrBackground = GetSysColorBrush(COLOR_WINDOW);
1523 wc.lpszMenuName = NULL;
1524 wc.lpszClassName = "HeaderTestClass";
1525 wc.lpfnWndProc = HeaderTestWndProc;
1526 RegisterClassA(&wc);
1528 /* The height of the header control depends on the height of the system font.
1529 The height of the system font is dpi dependent */
1530 hdc = GetDC(0);
1531 hOldFont = SelectObject(hdc, GetStockObject(SYSTEM_FONT));
1532 GetTextMetricsA(hdc, &tm);
1533 /* 2 dot extra space are needed for the border */
1534 g_customheight = tm.tmHeight + 2;
1535 trace("customdraw height: %d (dpi: %d)\n", g_customheight, GetDeviceCaps(hdc, LOGPIXELSY));
1536 SelectObject(hdc, hOldFont);
1537 ReleaseDC(0, hdc);
1539 hHeaderParentWnd = CreateWindowExA(0, "HeaderTestClass", "Header test", WS_OVERLAPPEDWINDOW,
1540 CW_USEDEFAULT, CW_USEDEFAULT, 672+2*GetSystemMetrics(SM_CXSIZEFRAME),
1541 226+GetSystemMetrics(SM_CYCAPTION)+2*GetSystemMetrics(SM_CYSIZEFRAME),
1542 NULL, NULL, GetModuleHandleA(NULL), 0);
1543 assert(hHeaderParentWnd != NULL);
1544 ShowWindow(hHeaderParentWnd, SW_SHOW);
1545 return 1;
1548 START_TEST(header)
1550 HWND parent_hwnd;
1552 if (!init())
1553 return;
1555 test_header_control();
1556 test_header_order();
1557 test_customdraw();
1559 DestroyWindow(hHeaderParentWnd);
1561 init_msg_sequences(sequences, NUM_MSG_SEQUENCES);
1562 parent_hwnd = create_custom_parent_window();
1563 ok_sequence(sequences, PARENT_SEQ_INDEX, create_parent_wnd_seq, "create parent windows", FALSE);
1565 test_hdm_index_messages(parent_hwnd);
1566 test_hdm_getitemrect(parent_hwnd);
1567 test_hdm_hittest(parent_hwnd);
1568 test_hdm_layout(parent_hwnd);
1569 test_hdm_ordertoindex(parent_hwnd);
1570 test_hdm_sethotdivider(parent_hwnd);
1571 test_hdm_imageMessages(parent_hwnd);
1572 test_hdm_filterMessages(parent_hwnd);
1573 test_hdm_unicodeformatMessages(parent_hwnd);
1574 test_hdm_bitmapmarginMessages(parent_hwnd);
1576 DestroyWindow(parent_hwnd);