comctl32/tests: Remove useless message tracing.
[wine/multimedia.git] / dlls / comctl32 / tests / header.c
blob6ad0aa8f25ae72fcb194afa5aae3af8e8048b72f
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 "v6util.h"
28 #include "msg.h"
30 typedef struct tagEXPECTEDNOTIFY
32 INT iCode;
33 BOOL fUnicode;
34 HDITEMA hdItem;
35 } EXPECTEDNOTIFY;
37 typedef LRESULT (*CUSTOMDRAWPROC)(int n, NMCUSTOMDRAW *nm);
39 static CUSTOMDRAWPROC g_CustomDrawProc;
40 static int g_CustomDrawCount;
41 static DRAWITEMSTRUCT g_DrawItem;
42 static BOOL g_DrawItemReceived;
43 static DWORD g_customheight;
45 static EXPECTEDNOTIFY expectedNotify[10];
46 static INT nExpectedNotify = 0;
47 static INT nReceivedNotify = 0;
48 static INT unexpectedNotify[10];
49 static INT nUnexpectedNotify = 0;
51 static HWND hHeaderParentWnd;
52 static HWND hWndHeader;
53 #define MAX_CHARS 100
55 #define compare(val, exp, fmt) ok((val) == (exp), #val " value: " fmt ", expected: " fmt "\n", (val), (exp))
57 #define expect(expected, got) ok(expected == got, "expected %d, got %d\n", expected,got)
59 #define NUM_MSG_SEQUENCES 2
60 #define PARENT_SEQ_INDEX 0
61 #define HEADER_SEQ_INDEX 1
63 static struct msg_sequence *sequences[NUM_MSG_SEQUENCES];
65 static const struct message create_parent_wnd_seq[] = {
66 { WM_GETMINMAXINFO, sent },
67 { WM_NCCREATE, sent },
68 { WM_NCCALCSIZE, sent|wparam, 0 },
69 { WM_CREATE, sent },
70 { 0 }
73 static const struct message add_header_to_parent_seq_interactive[] = {
74 { WM_NOTIFYFORMAT, sent|lparam, 0, NF_QUERY },
75 { WM_QUERYUISTATE, sent },
76 { WM_PARENTNOTIFY, sent|wparam, 1 },
77 { WM_SHOWWINDOW, sent|wparam, 1 },
78 { WM_WINDOWPOSCHANGING, sent|wparam, 0 },
79 { WM_WINDOWPOSCHANGING, sent|wparam, 0 },
80 { WM_ACTIVATEAPP, sent|wparam, 1 },
81 { WM_NCACTIVATE, sent|wparam, 1 },
82 { WM_ACTIVATE, sent|wparam, 1 },
83 { WM_IME_SETCONTEXT, sent|defwinproc|wparam, 1 },
84 { WM_IME_NOTIFY, sent|defwinproc|wparam, 2 },
85 { WM_SETFOCUS, sent|defwinproc|wparam, 0 },
86 { WM_WINDOWPOSCHANGED, sent|wparam, 0 },
87 { WM_SIZE, sent|wparam, 0 },
88 { WM_MOVE, sent|wparam, 0 },
89 { 0 }
92 static const struct message add_header_to_parent_seq[] = {
93 { WM_NOTIFYFORMAT, sent|lparam, 0, NF_QUERY },
94 { WM_QUERYUISTATE, sent|optional },
95 { WM_PARENTNOTIFY, sent },
96 { 0 }
99 static const struct message insertItem_seq[] = {
100 { HDM_INSERTITEM, sent|wparam, 0 },
101 { HDM_INSERTITEM, sent|wparam, 1 },
102 { HDM_INSERTITEM, sent|wparam, 2 },
103 { HDM_INSERTITEM, sent|wparam, 3 },
104 { 0 }
107 static const struct message getItem_seq[] = {
108 { HDM_GETITEM, sent|wparam, 3 },
109 { HDM_GETITEM, sent|wparam, 0 },
110 { 0 }
114 static const struct message deleteItem_getItemCount_seq[] = {
115 { HDM_DELETEITEM, sent|wparam, 3 },
116 { HDM_GETITEMCOUNT, sent },
117 { HDM_DELETEITEM, sent|wparam, 3 },
118 { HDM_GETITEMCOUNT, sent },
119 { HDM_DELETEITEM, sent|wparam, 2 },
120 { HDM_GETITEMCOUNT, sent },
121 { 0 }
124 static const struct message orderArray_seq[] = {
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 SendMessage(hdex, HDM_INSERTITEMA, 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 = SendMessage(hdex, HDM_SETITEMA, 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 = SendMessage(hdex, HDM_SETITEMA, 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 SendMessage(hdex, HDM_DELETEITEM, idx, 0);
292 static LONG getItemCount(HWND hdex)
294 return 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 SendMessage(hdex, HDM_GETITEMA, 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 static LRESULT WINAPI header_subclass_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
401 WNDPROC oldproc = (WNDPROC)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
402 static LONG defwndproc_counter = 0;
403 LRESULT ret;
404 struct message msg;
406 msg.message = message;
407 msg.flags = sent|wparam|lparam;
408 if (defwndproc_counter) msg.flags |= defwinproc;
409 msg.wParam = wParam;
410 msg.lParam = lParam;
411 msg.id = 0;
412 add_message(sequences, HEADER_SEQ_INDEX, &msg);
414 defwndproc_counter++;
415 ret = CallWindowProcA(oldproc, hwnd, message, wParam, lParam);
416 defwndproc_counter--;
418 return ret;
421 static LRESULT WINAPI parent_wnd_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
423 static LONG defwndproc_counter = 0;
424 LRESULT ret;
425 struct message msg;
427 /* do not log painting messages */
428 if (message != WM_PAINT &&
429 message != WM_ERASEBKGND &&
430 message != WM_NCPAINT &&
431 message != WM_NCHITTEST &&
432 message != WM_GETTEXT &&
433 message != WM_GETICON &&
434 message != WM_DEVICECHANGE)
437 msg.message = message;
438 msg.flags = sent|wparam|lparam;
439 if (defwndproc_counter) msg.flags |= defwinproc;
440 msg.wParam = wParam;
441 msg.lParam = lParam;
442 add_message(sequences, PARENT_SEQ_INDEX, &msg);
445 defwndproc_counter++;
446 ret = DefWindowProcA(hwnd, message, wParam, lParam);
447 defwndproc_counter--;
449 return ret;
452 static BOOL register_parent_wnd_class(void)
454 WNDCLASSA cls;
456 cls.style = 0;
457 cls.lpfnWndProc = parent_wnd_proc;
458 cls.cbClsExtra = 0;
459 cls.cbWndExtra = 0;
460 cls.hInstance = GetModuleHandleA(NULL);
461 cls.hIcon = 0;
462 cls.hCursor = LoadCursorA(0, IDC_ARROW);
463 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
464 cls.lpszMenuName = NULL;
465 cls.lpszClassName = "Header test parent class";
466 return RegisterClassA(&cls);
469 static HWND create_custom_parent_window(void)
471 if (!register_parent_wnd_class())
472 return NULL;
474 return CreateWindowExA(0, "Header test parent class", "Header Message Sequence Testing",
475 WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT,
476 672+2*GetSystemMetrics(SM_CXSIZEFRAME),
477 226+GetSystemMetrics(SM_CYCAPTION)+2*GetSystemMetrics(SM_CYSIZEFRAME),
478 NULL, NULL, GetModuleHandleA(NULL), 0);
481 static HWND create_custom_header_control(HWND hParent, BOOL preloadHeaderItems)
483 WNDPROC oldproc;
484 HWND childHandle;
485 HDLAYOUT hlayout;
486 RECT rectwin;
487 WINDOWPOS winpos;
488 int retVal;
489 int loopcnt;
490 static char firstHeaderItem[] = "Name";
491 static char secondHeaderItem[] = "Size";
492 static char *items[] = {secondHeaderItem, firstHeaderItem};
493 HDITEM hdItem;
494 hdItem.mask = HDI_TEXT | HDI_WIDTH | HDI_FORMAT;
495 hdItem.fmt = HDF_LEFT;
496 hdItem.cxy = 80;
497 hdItem.cchTextMax = 260;
500 flush_sequences(sequences, NUM_MSG_SEQUENCES);
502 childHandle = CreateWindowEx(0, WC_HEADER, NULL,
503 WS_CHILD|WS_BORDER|WS_VISIBLE|HDS_BUTTONS|HDS_HORZ,
504 0, 0, 0, 0,
505 hParent, NULL, NULL, NULL);
506 assert(childHandle);
507 if (preloadHeaderItems)
509 for ( loopcnt = 0 ; loopcnt < 2 ; loopcnt++ )
511 hdItem.pszText = items[loopcnt];
512 retVal = SendMessage(childHandle, HDM_INSERTITEM, loopcnt, (LPARAM) &hdItem);
513 ok(retVal == loopcnt, "Adding item %d failed with return value %d\n", ( loopcnt + 1 ), retVal);
517 if (winetest_interactive)
518 ShowWindow (hParent, SW_SHOW);
520 GetClientRect(hParent,&rectwin);
521 hlayout.prc = &rectwin;
522 hlayout.pwpos = &winpos;
523 SendMessageA(childHandle,HDM_LAYOUT,0,(LPARAM) &hlayout);
524 SetWindowPos(childHandle, winpos.hwndInsertAfter, winpos.x, winpos.y,
525 winpos.cx, winpos.cy, 0);
527 oldproc = (WNDPROC)SetWindowLongPtrA(childHandle, GWLP_WNDPROC,
528 (LONG_PTR)header_subclass_proc);
529 SetWindowLongPtrA(childHandle, GWLP_USERDATA, (LONG_PTR)oldproc);
530 return childHandle;
533 static void check_auto_format(void)
535 HDITEMA hdiCreate;
536 HDITEMA hdiRead;
537 static CHAR text[] = "Test";
538 ZeroMemory(&hdiCreate, sizeof(HDITEMA));
540 /* Windows implicitly sets some format bits in INSERTITEM */
542 /* HDF_STRING is automatically set and cleared for no text */
543 hdiCreate.mask = HDI_TEXT|HDI_WIDTH|HDI_FORMAT;
544 hdiCreate.pszText = text;
545 hdiCreate.cxy = 100;
546 hdiCreate.fmt=HDF_CENTER;
547 addReadDelItem(hWndHeader, &hdiCreate, HDI_FORMAT, &hdiRead);
548 ok(hdiRead.fmt == (HDF_STRING|HDF_CENTER), "HDF_STRING not set automatically (fmt=%x)\n", hdiRead.fmt);
550 hdiCreate.mask = HDI_WIDTH|HDI_FORMAT;
551 hdiCreate.pszText = text;
552 hdiCreate.fmt = HDF_CENTER|HDF_STRING;
553 addReadDelItem(hWndHeader, &hdiCreate, HDI_FORMAT, &hdiRead);
554 ok(hdiRead.fmt == (HDF_CENTER), "HDF_STRING should be automatically cleared (fmt=%x)\n", hdiRead.fmt);
556 /* HDF_BITMAP is automatically set and cleared for a NULL bitmap or no bitmap */
557 hdiCreate.mask = HDI_BITMAP|HDI_WIDTH|HDI_FORMAT;
558 hdiCreate.hbm = CreateBitmap(16, 16, 1, 8, NULL);
559 hdiCreate.fmt = HDF_CENTER;
560 addReadDelItem(hWndHeader, &hdiCreate, HDI_FORMAT, &hdiRead);
561 ok(hdiRead.fmt == (HDF_BITMAP|HDF_CENTER), "HDF_BITMAP not set automatically (fmt=%x)\n", hdiRead.fmt);
562 DeleteObject(hdiCreate.hbm);
564 hdiCreate.hbm = NULL;
565 hdiCreate.fmt = HDF_CENTER|HDF_BITMAP;
566 addReadDelItem(hWndHeader, &hdiCreate, HDI_FORMAT, &hdiRead);
567 ok(hdiRead.fmt == HDF_CENTER, "HDF_BITMAP not cleared automatically for NULL bitmap (fmt=%x)\n", hdiRead.fmt);
569 hdiCreate.mask = HDI_WIDTH|HDI_FORMAT;
570 hdiCreate.fmt = HDF_CENTER|HDF_BITMAP;
571 addReadDelItem(hWndHeader, &hdiCreate, HDI_FORMAT, &hdiRead);
572 ok(hdiRead.fmt == HDF_CENTER, "HDF_BITMAP not cleared automatically for no bitmap (fmt=%x)\n", hdiRead.fmt);
574 /* HDF_IMAGE is automatically set but not cleared */
575 hdiCreate.mask = HDI_IMAGE|HDI_WIDTH|HDI_FORMAT;
576 hdiCreate.iImage = 17;
577 addReadDelItem(hWndHeader, &hdiCreate, HDI_FORMAT, &hdiRead);
578 ok(hdiRead.fmt == (HDF_IMAGE|HDF_CENTER), "HDF_IMAGE not set automatically (fmt=%x)\n", hdiRead.fmt);
580 hdiCreate.mask = HDI_WIDTH|HDI_FORMAT;
581 hdiCreate.fmt = HDF_CENTER|HDF_IMAGE;
582 hdiCreate.iImage = 0;
583 addReadDelItem(hWndHeader, &hdiCreate, HDI_FORMAT, &hdiRead);
584 ok(hdiRead.fmt == (HDF_CENTER|HDF_IMAGE), "HDF_IMAGE shouldn't be cleared automatically (fmt=%x)\n", hdiRead.fmt);
587 static void check_auto_fields(void)
589 HDITEMA hdiCreate;
590 HDITEMA hdiRead;
591 static CHAR text[] = "Test";
592 LONG res;
594 /* Windows stores the format, width, lparam even if they are not in the item's mask */
595 ZeroMemory(&hdiCreate, sizeof(HDITEMA));
596 hdiCreate.mask = HDI_TEXT;
597 hdiCreate.cxy = 100;
598 hdiCreate.pszText = text;
599 addReadDelItem(hWndHeader, &hdiCreate, HDI_WIDTH, &hdiRead);
600 TEST_GET_ITEMCOUNT(6);
601 ok(hdiRead.cxy == hdiCreate.cxy, "cxy should be automatically set\n");
603 ZeroMemory(&hdiCreate, sizeof(HDITEMA));
604 hdiCreate.mask = HDI_TEXT;
605 hdiCreate.pszText = text;
606 hdiCreate.lParam = 0x12345678;
607 addReadDelItem(hWndHeader, &hdiCreate, HDI_LPARAM, &hdiRead);
608 TEST_GET_ITEMCOUNT(6);
609 ok(hdiRead.lParam == hdiCreate.lParam, "lParam should be automatically set\n");
611 ZeroMemory(&hdiCreate, sizeof(HDITEMA));
612 hdiCreate.mask = HDI_TEXT;
613 hdiCreate.pszText = text;
614 hdiCreate.fmt = HDF_STRING|HDF_CENTER;
615 addReadDelItem(hWndHeader, &hdiCreate, HDI_FORMAT, &hdiRead);
616 TEST_GET_ITEMCOUNT(6);
617 ok(hdiRead.fmt == hdiCreate.fmt, "fmt should be automatically set\n");
619 /* others fields are not set */
620 ZeroMemory(&hdiCreate, sizeof(HDITEMA));
621 hdiCreate.mask = HDI_TEXT;
622 hdiCreate.pszText = text;
623 hdiCreate.hbm = CreateBitmap(16, 16, 1, 8, NULL);
624 addReadDelItem(hWndHeader, &hdiCreate, HDI_BITMAP, &hdiRead);
625 TEST_GET_ITEMCOUNT(6);
626 ok(hdiRead.hbm == NULL, "hbm should not be automatically set\n");
627 DeleteObject(hdiCreate.hbm);
629 ZeroMemory(&hdiCreate, sizeof(HDITEMA));
630 hdiCreate.mask = HDI_IMAGE;
631 hdiCreate.iImage = 17;
632 hdiCreate.pszText = text;
633 addReadDelItem(hWndHeader, &hdiCreate, HDI_TEXT, &hdiRead);
634 TEST_GET_ITEMCOUNT(6);
635 ok(hdiRead.pszText==NULL, "pszText shouldn't be automatically set\n");
637 /* field from comctl >4.0 not tested as the system probably won't touch them */
640 static void check_mask(void)
642 HDITEMA hdi;
643 static CHAR text[] = "ABC";
644 LRESULT ret;
646 /* don't create items if the mask is zero */
647 ZeroMemory(&hdi, sizeof(hdi));
648 hdi.mask = 0;
649 hdi.cxy = 200;
650 hdi.pszText = text;
651 hdi.fmt = 0;
652 hdi.iOrder = 0;
653 hdi.lParam = 17;
654 hdi.cchTextMax = 260;
655 ret = SendMessage(hWndHeader, HDM_INSERTITEM, 0, (LPARAM)&hdi);
656 ok(ret == -1, "Creating an item with a zero mask should have failed\n");
657 if (ret != -1) SendMessage(hWndHeader, HDM_DELETEITEM, 0, 0);
659 /* with a non-zero mask creation will succeed */
660 ZeroMemory(&hdi, sizeof(hdi));
661 hdi.mask = HDI_LPARAM;
662 ret = SendMessage(hWndHeader, HDM_INSERTITEM, 0, (LPARAM)&hdi);
663 ok(ret != -1, "Adding item with non-zero mask failed\n");
664 if (ret != -1)
665 SendMessage(hWndHeader, HDM_DELETEITEM, 0, 0);
667 /* in SETITEM if the mask contains a unknown bit, it is ignored */
668 ZeroMemory(&hdi, sizeof(hdi));
669 hdi.mask = 0x08000000 | HDI_LPARAM | HDI_IMAGE;
670 hdi.lParam = 133;
671 hdi.iImage = 17;
672 ret = SendMessage(hWndHeader, HDM_INSERTITEM, 0, (LPARAM)&hdi);
673 ok(ret != -1, "Adding item failed\n");
675 if (ret != -1)
677 /* check result */
678 ZeroMemory(&hdi, sizeof(hdi));
679 hdi.mask = HDI_LPARAM | HDI_IMAGE;
680 SendMessage(hWndHeader, HDM_GETITEM, 0, (LPARAM)&hdi);
681 ok(hdi.lParam == 133, "comctl32 4.0 field not set\n");
682 ok(hdi.iImage == 17, "comctl32 >4.0 field not set\n");
684 /* but in GETITEM if an unknown bit is set, comctl32 uses only version 4.0 fields */
685 ZeroMemory(&hdi, sizeof(hdi));
686 hdi.mask = 0x08000000 | HDI_LPARAM | HDI_IMAGE;
687 SendMessage(hWndHeader, HDM_GETITEM, 0, (LPARAM)&hdi);
688 ok(hdi.lParam == 133, "comctl32 4.0 field not read\n");
689 ok(hdi.iImage == 0, "comctl32 >4.0 field shouldn't be read\n");
691 SendMessage(hWndHeader, HDM_DELETEITEM, 0, 0);
695 static void test_header_control (void)
697 LONG res;
698 static char buffer[MAX_CHARS];
699 int i;
701 hWndHeader = create_header_control ();
703 for (i = 3; i >= 0; i--)
705 TEST_GET_ITEMCOUNT(3-i);
706 res = addItem(hWndHeader, 0, str_items[i]);
707 ok(res == 0, "Adding simple item failed (%d)\n", res);
710 TEST_GET_ITEMCOUNT(4);
711 res = addItem(hWndHeader, 99, str_items[i+1]);
712 ok(res != -1, "Adding Out of Range item should fail with -1 got (%d)\n", res);
713 TEST_GET_ITEMCOUNT(5);
714 res = addItem(hWndHeader, 5, str_items[i+1]);
715 ok(res != -1, "Adding Out of Range item should fail with -1 got (%d)\n", res);
716 TEST_GET_ITEMCOUNT(6);
718 for (i = 0; i < 4; i++) { TEST_GET_ITEM(i,i); TEST_GET_ITEMCOUNT(6); }
720 res=getItem(hWndHeader, 99, buffer);
721 ok(res == 0, "Getting Out of Range item should fail with 0 (%d), got %s\n", res,buffer);
722 res=getItem(hWndHeader, 5, buffer);
723 ok(res == 1, "Getting Out of Range item should fail with 1 (%d), got %s\n", res,buffer);
724 res=getItem(hWndHeader, -2, buffer);
725 ok(res == 0, "Getting Out of Range item should fail with 0 (%d), got %s\n", res,buffer);
727 if (winetest_interactive)
729 UpdateWindow(hHeaderParentWnd);
730 UpdateWindow(hWndHeader);
733 TEST_GET_ITEMCOUNT(6);
734 res=setItem(hWndHeader, 99, str_items[5], FALSE);
735 ok(res == 0, "Setting Out of Range item should fail with 0 (%d)\n", res);
736 res=setItem(hWndHeader, 5, str_items[5], TRUE);
737 ok(res == 1, "Setting Out of Range item should fail with 1 (%d)\n", res);
738 res=setItem(hWndHeader, -2, str_items[5], FALSE);
739 ok(res == 0, "Setting Out of Range item should fail with 0 (%d)\n", res);
740 TEST_GET_ITEMCOUNT(6);
742 for (i = 0; i < 4; i++)
744 res = setItem(hWndHeader, i, str_items[4], TRUE);
745 ok(res != 0, "Setting %d item failed (%d)\n", i+1, res);
746 TEST_GET_ITEM(i, 4);
747 TEST_GET_ITEMCOUNT(6);
750 SendMessageA(hWndHeader, HDM_SETUNICODEFORMAT, TRUE, 0);
751 setItemUnicodeNotify(hWndHeader, 3, pszUniTestA, pszUniTestW);
752 SendMessageA(hWndHeader, WM_NOTIFYFORMAT, (WPARAM)hHeaderParentWnd, NF_REQUERY);
753 setItem(hWndHeader, 3, str_items[4], TRUE);
755 dont_expect_notify(HDN_GETDISPINFOA);
756 dont_expect_notify(HDN_GETDISPINFOW);
757 addItem(hWndHeader, 0, LPSTR_TEXTCALLBACKA);
758 setItem(hWndHeader, 0, str_items[4], TRUE);
759 /* unexpected notifies cleared by notifies_received in setItem */
760 dont_expect_notify(HDN_GETDISPINFOA);
761 dont_expect_notify(HDN_GETDISPINFOW);
762 setItem(hWndHeader, 0, LPSTR_TEXTCALLBACKA, TRUE);
763 /* unexpected notifies cleared by notifies_received in setItem */
764 delItem(hWndHeader, 0);
766 check_auto_format();
767 TEST_GET_ITEMCOUNT(6);
768 check_auto_fields();
769 TEST_GET_ITEMCOUNT(6);
770 check_mask();
771 TEST_GET_ITEMCOUNT(6);
773 res = delItem(hWndHeader, 5);
774 ok(res == 1, "Deleting Out of Range item should fail with 1 (%d)\n", res);
775 res = delItem(hWndHeader, -2);
776 ok(res == 0, "Deleting Out of Range item should fail with 0 (%d)\n", res);
777 TEST_GET_ITEMCOUNT(5);
779 res = delItem(hWndHeader, 3);
780 ok(res != 0, "Deleting using out of range index failed (%d)\n", res);
781 TEST_GET_ITEMCOUNT(4);
782 res = delItem(hWndHeader, 0);
783 ok(res != 0, "Deleting using out of range index failed (%d)\n", res);
784 TEST_GET_ITEMCOUNT(3);
785 res = delItem(hWndHeader, 0);
786 ok(res != 0, "Deleting using out of range index failed (%d)\n", res);
787 TEST_GET_ITEMCOUNT(2);
788 res = delItem(hWndHeader, 0);
789 ok(res != 0, "Deleting using out of range index failed (%d)\n", res);
790 TEST_GET_ITEMCOUNT(1);
792 DestroyWindow(hWndHeader);
795 static void test_hdm_getitemrect(HWND hParent)
798 HWND hChild;
799 RECT rect;
800 int retVal;
802 flush_sequences(sequences, NUM_MSG_SEQUENCES);
803 hChild = create_custom_header_control(hParent, TRUE);
804 ok_sequence(sequences, PARENT_SEQ_INDEX, add_header_to_parent_seq,
805 "adder header control to parent", FALSE);
807 retVal = SendMessage(hChild, HDM_GETITEMRECT, 1, (LPARAM) &rect);
808 ok(retVal == TRUE, "Getting item rect should TRUE, got %d\n", retVal);
809 /* check bounding rectangle information of 2nd header item */
810 expect(80, rect.left);
811 expect(0, rect.top);
812 expect(160, rect.right);
813 expect(g_customheight, rect.bottom);
815 retVal = SendMessage(hChild, HDM_GETITEMRECT, 0, (LPARAM) &rect);
817 ok(retVal == TRUE, "Getting item rect should TRUE, got %d\n", retVal);
818 /* check bounding rectangle information of 1st header item */
819 expect(0, rect.left);
820 expect(0, rect.top);
822 expect(80, rect.right);
823 expect(g_customheight, rect.bottom);
825 retVal = SendMessage(hChild, HDM_GETITEMRECT, 10, (LPARAM) &rect);
826 ok(retVal == 0, "Getting rect of nonexistent item should return 0, got %d\n", retVal);
828 ok_sequence(sequences, HEADER_SEQ_INDEX, getItemRect_seq, "getItemRect sequence testing", FALSE);
829 DestroyWindow(hChild);
832 static void test_hdm_layout(HWND hParent)
834 HWND hChild;
835 int retVal;
836 RECT rect;
837 HDLAYOUT hdLayout;
838 WINDOWPOS windowPos;
839 hdLayout.prc = &rect;
840 hdLayout.pwpos = &windowPos;
842 flush_sequences(sequences, NUM_MSG_SEQUENCES);
843 hChild = create_custom_header_control(hParent, TRUE);
844 ok_sequence(sequences, PARENT_SEQ_INDEX, add_header_to_parent_seq,
845 "adder header control to parent", FALSE);
847 flush_sequences(sequences, NUM_MSG_SEQUENCES);
848 retVal = SendMessage(hChild, HDM_LAYOUT, 0, (LPARAM) &hdLayout);
849 expect(TRUE, retVal);
851 ok_sequence(sequences, HEADER_SEQ_INDEX, layout_seq, "layout sequence testing", FALSE);
853 DestroyWindow(hChild);
856 static void test_hdm_ordertoindex(HWND hParent)
858 HWND hChild;
859 int retVal;
861 flush_sequences(sequences, NUM_MSG_SEQUENCES);
862 hChild = create_custom_header_control(hParent, TRUE);
863 ok_sequence(sequences, PARENT_SEQ_INDEX, add_header_to_parent_seq,
864 "adder header control to parent", FALSE);
866 flush_sequences(sequences, NUM_MSG_SEQUENCES);
867 retVal = SendMessage(hChild, HDM_ORDERTOINDEX, 1, 0);
868 expect(1, retVal);
870 ok_sequence(sequences, HEADER_SEQ_INDEX, orderToIndex_seq, "orderToIndex sequence testing", FALSE);
871 DestroyWindow(hChild);
874 static void test_hdm_hittest(HWND hParent)
876 HWND hChild;
877 int retVal;
878 POINT pt;
879 HDHITTESTINFO hdHitTestInfo;
880 const int firstItemRightBoundary = 80;
881 const int secondItemRightBoundary = 160;
882 const int bottomBoundary = g_customheight;
884 pt.x = firstItemRightBoundary - 1;
885 pt.y = bottomBoundary - 1;
886 hdHitTestInfo.pt = pt;
889 flush_sequences(sequences, NUM_MSG_SEQUENCES);
890 hChild = create_custom_header_control(hParent, TRUE);
891 ok_sequence(sequences, PARENT_SEQ_INDEX, add_header_to_parent_seq,
892 "adder header control to parent", FALSE);
894 flush_sequences(sequences, NUM_MSG_SEQUENCES);
895 retVal = SendMessage(hChild, HDM_HITTEST, 0, (LPARAM) &hdHitTestInfo);
896 expect(0, retVal);
897 expect(0, hdHitTestInfo.iItem);
898 expect(HHT_ONDIVIDER, hdHitTestInfo.flags);
900 pt.x = secondItemRightBoundary - 1;
901 pt.y = bottomBoundary - 1;
902 hdHitTestInfo.pt = pt;
903 retVal = SendMessage(hChild, HDM_HITTEST, 1, (LPARAM) &hdHitTestInfo);
904 expect(1, retVal);
905 expect(1, hdHitTestInfo.iItem);
906 expect(HHT_ONDIVIDER, hdHitTestInfo.flags);
908 pt.x = secondItemRightBoundary;
909 pt.y = bottomBoundary + 1;
910 hdHitTestInfo.pt = pt;
911 retVal = SendMessage(hChild, HDM_HITTEST, 0, (LPARAM) &hdHitTestInfo);
912 expect(-1, retVal);
913 expect(-1, hdHitTestInfo.iItem);
914 expect(HHT_BELOW, hdHitTestInfo.flags);
916 ok_sequence(sequences, HEADER_SEQ_INDEX, hittest_seq, "hittest sequence testing", FALSE);
918 DestroyWindow(hChild);
921 static void test_hdm_sethotdivider(HWND hParent)
923 HWND hChild;
924 int retVal;
925 /* low word: x coordinate = 5
926 * high word: y coordinate = 5
929 flush_sequences(sequences, NUM_MSG_SEQUENCES);
930 hChild = create_custom_header_control(hParent, TRUE);
931 ok_sequence(sequences, PARENT_SEQ_INDEX, add_header_to_parent_seq,
932 "adder header control to parent", FALSE);
934 flush_sequences(sequences, NUM_MSG_SEQUENCES);
935 retVal = SendMessage(hChild, HDM_SETHOTDIVIDER, TRUE, MAKELPARAM(5, 5));
936 expect(0, retVal);
938 retVal = SendMessage(hChild, HDM_SETHOTDIVIDER, FALSE, 100);
939 expect(100, retVal);
940 retVal = SendMessage(hChild, HDM_SETHOTDIVIDER, FALSE, 1);
941 expect(1, retVal);
942 if (winetest_interactive)
943 ok_sequence(sequences, HEADER_SEQ_INDEX, setHotDivider_seq_interactive,
944 "setHotDivider sequence testing", TRUE);
945 else
946 ok_sequence(sequences, HEADER_SEQ_INDEX, setHotDivider_seq_noninteractive,
947 "setHotDivider sequence testing", FALSE);
949 DestroyWindow(hChild);
952 static void test_hdm_imageMessages(HWND hParent)
954 HIMAGELIST hImageList = ImageList_Create (4, 4, 0, 1, 0);
955 HIMAGELIST hIml;
956 BOOL wasValid;
957 HWND hChild;
959 flush_sequences(sequences, NUM_MSG_SEQUENCES);
960 hChild = create_custom_header_control(hParent, TRUE);
961 ok_sequence(sequences, PARENT_SEQ_INDEX, add_header_to_parent_seq,
962 "adder header control to parent", FALSE);
964 flush_sequences(sequences, NUM_MSG_SEQUENCES);
966 hIml = (HIMAGELIST) SendMessage(hChild, HDM_SETIMAGELIST, 0, (LPARAM) hImageList);
967 ok(hIml == NULL, "Expected NULL, got %p\n", hIml);
969 hIml = (HIMAGELIST) SendMessage(hChild, HDM_GETIMAGELIST, 0, 0);
970 ok(hIml != NULL, "Expected non-NULL handle, got %p\n", hIml);
972 hIml = (HIMAGELIST) SendMessage(hChild, HDM_CREATEDRAGIMAGE, 0, 0);
973 ok(hIml != NULL, "Expected non-NULL handle, got %p\n", hIml);
974 ImageList_Destroy(hIml);
976 ok_sequence(sequences, HEADER_SEQ_INDEX, imageMessages_seq, "imageMessages sequence testing", FALSE);
978 DestroyWindow(hChild);
980 wasValid = ImageList_Destroy(hImageList);
981 ok(wasValid, "Header must not free image list at destruction!\n");
984 static void test_hdm_filterMessages(HWND hParent)
986 HWND hChild;
987 int retVal, timeout;
989 flush_sequences(sequences, NUM_MSG_SEQUENCES);
990 hChild = create_custom_header_control(hParent, TRUE);
991 assert(hChild);
992 ok_sequence(sequences, PARENT_SEQ_INDEX, add_header_to_parent_seq,
993 "adder header control to parent", FALSE);
995 timeout = SendMessage(hChild, HDM_SETFILTERCHANGETIMEOUT, 1, 100);
996 SendMessage(hChild, HDM_SETFILTERCHANGETIMEOUT, 1, timeout);
998 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1000 /* msdn incorrectly states that return value
1001 * is the index of the filter control being
1002 * modified. The sendMessage here should
1003 * return previous filter timeout value
1006 retVal = SendMessage(hChild, HDM_SETFILTERCHANGETIMEOUT, 1, 100);
1007 expect(timeout, retVal);
1009 todo_wine
1011 retVal = SendMessage(hChild, HDM_CLEARFILTER, 0, 1);
1012 if (retVal == 0)
1013 win_skip("HDM_CLEARFILTER needs 5.80\n");
1014 else
1015 expect(1, retVal);
1017 retVal = SendMessage(hChild, HDM_EDITFILTER, 1, 0);
1018 if (retVal == 0)
1019 win_skip("HDM_EDITFILTER needs 5.80\n");
1020 else
1021 expect(1, retVal);
1023 if (winetest_interactive)
1024 ok_sequence(sequences, HEADER_SEQ_INDEX, filterMessages_seq_interactive,
1025 "filterMessages sequence testing", TRUE);
1026 else
1027 ok_sequence(sequences, HEADER_SEQ_INDEX, filterMessages_seq_noninteractive,
1028 "filterMessages sequence testing", FALSE);
1029 DestroyWindow(hChild);
1033 static void test_hdm_unicodeformatMessages(HWND hParent)
1035 HWND hChild;
1036 int retVal;
1038 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1039 hChild = create_custom_header_control(hParent, TRUE);
1040 ok_sequence(sequences, PARENT_SEQ_INDEX, add_header_to_parent_seq,
1041 "adder header control to parent", FALSE);
1043 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1044 retVal = SendMessage(hChild, HDM_SETUNICODEFORMAT, TRUE, 0);
1045 expect(0, retVal);
1046 retVal = SendMessage(hChild, HDM_GETUNICODEFORMAT, 0, 0);
1047 expect(1, retVal);
1049 ok_sequence(sequences, HEADER_SEQ_INDEX, unicodeformatMessages_seq,
1050 "unicodeformatMessages sequence testing", FALSE);
1051 DestroyWindow(hChild);
1054 static void test_hdm_bitmapmarginMessages(HWND hParent)
1056 HWND hChild;
1057 int retVal;
1059 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1060 hChild = create_custom_header_control(hParent, TRUE);
1061 ok_sequence(sequences, PARENT_SEQ_INDEX, add_header_to_parent_seq,
1062 "adder header control to parent", FALSE);
1064 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1065 retVal = SendMessage(hChild, HDM_GETBITMAPMARGIN, 0, 0);
1066 if (retVal == 0)
1067 win_skip("HDM_GETBITMAPMARGIN needs 5.80\n");
1068 else
1069 expect(6, retVal);
1071 ok_sequence(sequences, HEADER_SEQ_INDEX, bitmapmarginMessages_seq,
1072 "bitmapmarginMessages sequence testing", FALSE);
1073 DestroyWindow(hChild);
1076 static void test_hdm_index_messages(HWND hParent)
1078 HWND hChild;
1079 int retVal;
1080 int loopcnt;
1081 int strcmpResult;
1082 int iSize;
1083 static const int lpiarray[2] = {1, 0};
1084 static int lpiarrayReceived[2];
1085 static char firstHeaderItem[] = "Name";
1086 static char secondHeaderItem[] = "Size";
1087 static char thirdHeaderItem[] = "Type";
1088 static char fourthHeaderItem[] = "Date Modified";
1089 static char *items[] = {firstHeaderItem, secondHeaderItem, thirdHeaderItem, fourthHeaderItem};
1090 RECT rect;
1091 HDITEM hdItem;
1092 hdItem.mask = HDI_TEXT | HDI_WIDTH | HDI_FORMAT;
1093 hdItem.fmt = HDF_LEFT;
1094 hdItem.cxy = 80;
1095 hdItem.cchTextMax = 260;
1097 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1098 hChild = create_custom_header_control(hParent, FALSE);
1099 if (winetest_interactive)
1100 ok_sequence(sequences, PARENT_SEQ_INDEX, add_header_to_parent_seq_interactive,
1101 "adder header control to parent", TRUE);
1102 else
1103 ok_sequence(sequences, PARENT_SEQ_INDEX, add_header_to_parent_seq,
1104 "adder header control to parent", FALSE);
1105 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1106 for ( loopcnt = 0 ; loopcnt < 4 ; loopcnt++ )
1108 hdItem.pszText = items[loopcnt];
1109 retVal = SendMessage(hChild, HDM_INSERTITEM, loopcnt, (LPARAM) &hdItem);
1110 ok(retVal == loopcnt, "Adding item %d failed with return value %d\n", ( loopcnt + 1 ), retVal);
1112 ok_sequence(sequences, HEADER_SEQ_INDEX, insertItem_seq, "insertItem sequence testing", FALSE);
1114 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1116 retVal = SendMessage(hChild, HDM_DELETEITEM, 3, (LPARAM) &hdItem);
1117 ok(retVal == TRUE, "Deleting item 3 should return TRUE, got %d\n", retVal);
1118 retVal = SendMessage(hChild, HDM_GETITEMCOUNT, 0, 0);
1119 ok(retVal == 3, "Getting item count should return 3, got %d\n", retVal);
1121 retVal = SendMessage(hChild, HDM_DELETEITEM, 3, (LPARAM) &hdItem);
1122 ok(retVal == FALSE, "Deleting already-deleted item should return FALSE, got %d\n", retVal);
1123 retVal = SendMessage(hChild, HDM_GETITEMCOUNT, 0, 0);
1124 ok(retVal == 3, "Getting item count should return 3, got %d\n", retVal);
1126 retVal = SendMessage(hChild, HDM_DELETEITEM, 2, (LPARAM) &hdItem);
1127 ok(retVal == TRUE, "Deleting item 2 should return TRUE, got %d\n", retVal);
1128 retVal = SendMessage(hChild, HDM_GETITEMCOUNT, 0, 0);
1129 ok(retVal == 2, "Getting item count should return 2, got %d\n", retVal);
1131 ok_sequence(sequences, HEADER_SEQ_INDEX, deleteItem_getItemCount_seq,
1132 "deleteItem_getItemCount sequence testing", FALSE);
1134 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1136 retVal = SendMessage(hChild, HDM_GETITEM, 3, (LPARAM) &hdItem);
1137 ok(retVal == FALSE, "Getting already-deleted item should return FALSE, got %d\n", retVal);
1139 retVal = SendMessage(hChild, HDM_GETITEM, 0, (LPARAM) &hdItem);
1140 ok(retVal == TRUE, "Getting the 1st header item should return TRUE, got %d\n", retVal);
1142 ok_sequence(sequences, HEADER_SEQ_INDEX, getItem_seq, "getItem sequence testing", FALSE);
1144 /* check if the item is the right one */
1145 strcmpResult = strcmp(hdItem.pszText, firstHeaderItem);
1146 expect(0, strcmpResult);
1147 expect(80, hdItem.cxy);
1149 iSize = SendMessage(hChild, HDM_GETITEMCOUNT, 0, 0);
1151 /* item should be updated just after accepting new array */
1152 ShowWindow(hChild, SW_HIDE);
1153 retVal = SendMessage(hChild, HDM_SETORDERARRAY, iSize, (LPARAM) lpiarray);
1154 expect(TRUE, retVal);
1155 rect.left = 0;
1156 retVal = SendMessage(hChild, HDM_GETITEMRECT, 0, (LPARAM) &rect);
1157 expect(TRUE, retVal);
1158 ok(rect.left != 0, "Expected updated rectangle\n");
1160 flush_sequences(sequences, NUM_MSG_SEQUENCES);
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 static void test_hdf_fixedwidth(HWND hParent)
1192 HWND hChild;
1193 HDITEM hdItem;
1194 DWORD ret;
1195 RECT rect;
1196 HDHITTESTINFO ht;
1198 hChild = create_custom_header_control(hParent, FALSE);
1200 hdItem.mask = HDI_WIDTH | HDI_FORMAT;
1201 hdItem.fmt = HDF_FIXEDWIDTH;
1202 hdItem.cxy = 80;
1204 ret = SendMessage(hChild, HDM_INSERTITEM, 0, (LPARAM)&hdItem);
1205 expect(0, ret);
1207 /* try to change width */
1208 rect.right = rect.bottom = 0;
1209 SendMessage(hChild, HDM_GETITEMRECT, 0, (LPARAM)&rect);
1210 ok(rect.right != 0, "Expected not zero width\n");
1211 ok(rect.bottom != 0, "Expected not zero height\n");
1213 SendMessage(hChild, WM_LBUTTONDOWN, 0, MAKELPARAM(rect.right, rect.bottom / 2));
1214 SendMessage(hChild, WM_MOUSEMOVE, 0, MAKELPARAM(rect.right + 20, rect.bottom / 2));
1215 SendMessage(hChild, WM_LBUTTONUP, 0, MAKELPARAM(rect.right + 20, rect.bottom / 2));
1217 SendMessage(hChild, HDM_GETITEMRECT, 0, (LPARAM)&rect);
1219 if (hdItem.cxy != rect.right)
1221 win_skip("HDF_FIXEDWIDTH format not supported\n");
1222 DestroyWindow(hChild);
1223 return;
1226 /* try to adjust with message */
1227 hdItem.mask = HDI_WIDTH;
1228 hdItem.cxy = 90;
1230 ret = SendMessage(hChild, HDM_SETITEM, 0, (LPARAM)&hdItem);
1231 expect(TRUE, ret);
1233 rect.right = 0;
1234 SendMessage(hChild, HDM_GETITEMRECT, 0, (LPARAM)&rect);
1235 expect(90, rect.right);
1237 /* hittesting doesn't report ondivider flag for HDF_FIXEDWIDTH */
1238 ht.pt.x = rect.right - 1;
1239 ht.pt.y = rect.bottom / 2;
1240 SendMessage(hChild, HDM_HITTEST, 0, (LPARAM)&ht);
1241 expect(HHT_ONHEADER, ht.flags);
1243 /* try to adjust with message */
1244 hdItem.mask = HDI_FORMAT;
1245 hdItem.fmt = 0;
1247 ret = SendMessage(hChild, HDM_SETITEM, 0, (LPARAM)&hdItem);
1248 expect(TRUE, ret);
1250 ht.pt.x = 90;
1251 ht.pt.y = rect.bottom / 2;
1252 SendMessage(hChild, HDM_HITTEST, 0, (LPARAM)&ht);
1253 expect(HHT_ONDIVIDER, ht.flags);
1255 DestroyWindow(hChild);
1258 static void test_hds_nosizing(HWND hParent)
1260 HWND hChild;
1261 HDITEM hdItem;
1262 DWORD ret;
1263 RECT rect;
1264 HDHITTESTINFO ht;
1266 hChild = create_custom_header_control(hParent, FALSE);
1268 memset(&hdItem, 0, sizeof(hdItem));
1269 hdItem.mask = HDI_WIDTH;
1270 hdItem.cxy = 80;
1272 ret = SendMessage(hChild, HDM_INSERTITEM, 0, (LPARAM)&hdItem);
1273 expect(0, ret);
1275 /* HDS_NOSIZING only blocks hittesting */
1276 ret = GetWindowLong(hChild, GWL_STYLE);
1277 SetWindowLong(hChild, GWL_STYLE, ret | HDS_NOSIZING);
1279 /* try to change width with mouse gestures */
1280 rect.right = rect.bottom = 0;
1281 SendMessage(hChild, HDM_GETITEMRECT, 0, (LPARAM)&rect);
1282 ok(rect.right != 0, "Expected not zero width\n");
1283 ok(rect.bottom != 0, "Expected not zero height\n");
1285 SendMessage(hChild, WM_LBUTTONDOWN, 0, MAKELPARAM(rect.right, rect.bottom / 2));
1286 SendMessage(hChild, WM_MOUSEMOVE, 0, MAKELPARAM(rect.right + 20, rect.bottom / 2));
1287 SendMessage(hChild, WM_LBUTTONUP, 0, MAKELPARAM(rect.right + 20, rect.bottom / 2));
1289 SendMessage(hChild, HDM_GETITEMRECT, 0, (LPARAM)&rect);
1291 if (hdItem.cxy != rect.right)
1293 win_skip("HDS_NOSIZING style not supported\n");
1294 DestroyWindow(hChild);
1295 return;
1298 /* this style doesn't set HDF_FIXEDWIDTH for items */
1299 hdItem.mask = HDI_FORMAT;
1300 ret = SendMessage(hChild, HDM_GETITEM, 0, (LPARAM)&hdItem);
1301 expect(TRUE, ret);
1302 ok(!(hdItem.fmt & HDF_FIXEDWIDTH), "Unexpected HDF_FIXEDWIDTH\n");
1304 /* try to adjust with message */
1305 hdItem.mask = HDI_WIDTH;
1306 hdItem.cxy = 90;
1308 ret = SendMessage(hChild, HDM_SETITEM, 0, (LPARAM)&hdItem);
1309 expect(TRUE, ret);
1311 rect.right = 0;
1312 SendMessage(hChild, HDM_GETITEMRECT, 0, (LPARAM)&rect);
1313 expect(90, rect.right);
1315 /* hittesting doesn't report ondivider flags for HDS_NOSIZING */
1316 ht.pt.x = rect.right - 1;
1317 ht.pt.y = rect.bottom / 2;
1318 SendMessage(hChild, HDM_HITTEST, 0, (LPARAM)&ht);
1319 expect(HHT_ONHEADER, ht.flags);
1321 /* try to adjust with message */
1322 ret = GetWindowLong(hChild, GWL_STYLE);
1323 SetWindowLong(hChild, GWL_STYLE, ret & ~HDS_NOSIZING);
1325 ht.pt.x = 90;
1326 ht.pt.y = rect.bottom / 2;
1327 SendMessage(hChild, HDM_HITTEST, 0, (LPARAM)&ht);
1328 expect(HHT_ONDIVIDER, ht.flags);
1330 DestroyWindow(hChild);
1333 #define TEST_NMCUSTOMDRAW(draw_stage, item_spec, lparam, _left, _top, _right, _bottom) \
1334 ok(nm->dwDrawStage == draw_stage, "Invalid dwDrawStage %d vs %d\n", draw_stage, nm->dwDrawStage); \
1335 if (item_spec != -1) \
1336 ok(nm->dwItemSpec == item_spec, "Invalid dwItemSpec %d vs %ld\n", item_spec, nm->dwItemSpec); \
1337 ok(nm->lItemlParam == lparam, "Invalid lItemlParam %d vs %ld\n", lparam, nm->lItemlParam); \
1338 ok((nm->rc.top == _top && nm->rc.bottom == _bottom && nm->rc.left == _left && nm->rc.right == _right) || \
1339 broken(draw_stage != CDDS_ITEMPREPAINT), /* comctl32 < 5.80 */ \
1340 "Invalid rect (%d,%d) (%d,%d) vs (%d,%d) (%d,%d)\n", _left, _top, _right, _bottom, \
1341 nm->rc.left, nm->rc.top, nm->rc.right, nm->rc.bottom);
1343 static LRESULT customdraw_1(int n, NMCUSTOMDRAW *nm)
1345 if (nm == NULL) { /* test ended */
1346 ok(n==1, "NM_CUSTOMDRAW messages: %d, expected: 1\n", n);
1347 return 0;
1350 switch (n)
1352 case 0:
1353 /* don't test dwItemSpec - it's 0 no comctl5 but 1308756 on comctl6 */
1354 TEST_NMCUSTOMDRAW(CDDS_PREPAINT, -1, 0, 0, 0, 670, g_customheight);
1355 return 0;
1358 ok(FALSE, "To many custom draw messages (n=%d, nm->dwDrawStage=%d)\n", n, nm->dwDrawStage);
1359 return -1;
1362 static LRESULT customdraw_2(int n, NMCUSTOMDRAW *nm)
1364 if (nm == NULL) { /* test ended */
1365 ok(n==4, "NM_CUSTOMDRAW messages: %d, expected: 4\n", n);
1366 return 0;
1369 switch (n)
1371 case 0:
1372 TEST_NMCUSTOMDRAW(CDDS_PREPAINT, -1, 0, 0, 0, 670, g_customheight);
1373 return CDRF_NOTIFYITEMDRAW;
1374 case 1:
1375 TEST_NMCUSTOMDRAW(CDDS_ITEMPREPAINT, 0, 0, 0, 0, 50, g_customheight);
1376 return 0;
1377 case 2:
1378 TEST_NMCUSTOMDRAW(CDDS_ITEMPREPAINT, 1, 5, 50, 0, 150, g_customheight);
1379 return 0;
1380 case 3:
1381 TEST_NMCUSTOMDRAW(CDDS_ITEMPREPAINT, 2, 10, 150, 0, 300, g_customheight);
1382 return 0;
1385 ok(FALSE, "To many custom draw messages (n=%d, nm->dwDrawStage=%d)\n", n, nm->dwDrawStage);
1386 return 0;
1389 static LRESULT customdraw_3(int n, NMCUSTOMDRAW *nm)
1391 if (nm == NULL) { /* test ended */
1392 ok(n==5, "NM_CUSTOMDRAW messages: %d, expected: 5\n", n);
1393 return 0;
1396 switch (n)
1398 case 0:
1399 TEST_NMCUSTOMDRAW(CDDS_PREPAINT, -1, 0, 0, 0, 670, g_customheight);
1400 return CDRF_NOTIFYITEMDRAW|CDRF_NOTIFYPOSTERASE|CDRF_NOTIFYPOSTPAINT|CDRF_SKIPDEFAULT;
1401 case 1:
1402 TEST_NMCUSTOMDRAW(CDDS_ITEMPREPAINT, 0, 0, 0, 0, 50, g_customheight);
1403 return 0;
1404 case 2:
1405 TEST_NMCUSTOMDRAW(CDDS_ITEMPREPAINT, 1, 5, 50, 0, 150, g_customheight);
1406 return 0;
1407 case 3:
1408 TEST_NMCUSTOMDRAW(CDDS_ITEMPREPAINT, 2, 10, 150, 0, 300, g_customheight);
1409 return 0;
1410 case 4:
1411 TEST_NMCUSTOMDRAW(CDDS_POSTPAINT, -1, 0, 0, 0, 670, g_customheight);
1412 return 0;
1415 ok(FALSE, "To many custom draw messages (n=%d, nm->dwDrawStage=%d)\n", n, nm->dwDrawStage);
1416 return 0;
1420 static LRESULT customdraw_4(int n, NMCUSTOMDRAW *nm)
1422 if (nm == NULL) { /* test ended */
1423 ok(n==4, "NM_CUSTOMDRAW messages: %d, expected: 4\n", n);
1424 return 0;
1427 switch (n)
1429 case 0:
1430 TEST_NMCUSTOMDRAW(CDDS_PREPAINT, -1, 0, 0, 0, 670, g_customheight);
1431 return CDRF_NOTIFYITEMDRAW|CDRF_NOTIFYPOSTPAINT;
1432 case 1:
1433 TEST_NMCUSTOMDRAW(CDDS_ITEMPREPAINT, 0, 0, 0, 0, 50, g_customheight);
1434 return 0;
1435 case 2:
1436 TEST_NMCUSTOMDRAW(CDDS_ITEMPREPAINT, 2, 10, 150, 0, 300, g_customheight);
1437 return 0;
1438 case 3:
1439 TEST_NMCUSTOMDRAW(CDDS_POSTPAINT, -1, 0, 0, 0, 670, g_customheight);
1440 return 0;
1443 ok(FALSE, "To many custom draw messages (n=%d, nm->dwDrawStage=%d)\n", n, nm->dwDrawStage);
1444 return 0;
1447 static void run_customdraw_scenario(CUSTOMDRAWPROC proc)
1449 g_CustomDrawProc = proc;
1450 g_CustomDrawCount = 0;
1451 InvalidateRect(hWndHeader, NULL, TRUE);
1452 UpdateWindow(hWndHeader);
1453 proc(g_CustomDrawCount, NULL);
1454 g_CustomDrawProc = NULL;
1457 static void test_customdraw(void)
1459 int i;
1460 HDITEM item;
1461 RECT rect;
1462 CHAR name[] = "Test";
1463 hWndHeader = create_header_control();
1464 GetClientRect(hWndHeader, &rect);
1465 ok(rect.right - rect.left == 670 && rect.bottom - rect.top == g_customheight,
1466 "Tests will fail as header size is %dx%d instead of 670x%d\n",
1467 rect.right - rect.left, rect.bottom - rect.top, g_customheight);
1469 for (i = 0; i < 3; i++)
1471 ZeroMemory(&item, sizeof(item));
1472 item.mask = HDI_TEXT|HDI_WIDTH;
1473 item.cxy = 50*(i+1);
1474 item.pszText = name;
1475 item.lParam = i*5;
1476 SendMessage(hWndHeader, HDM_INSERTITEM, i, (LPARAM)&item);
1479 run_customdraw_scenario(customdraw_1);
1480 run_customdraw_scenario(customdraw_2);
1481 run_customdraw_scenario(customdraw_3);
1483 ZeroMemory(&item, sizeof(item));
1484 item.mask = HDI_FORMAT;
1485 item.fmt = HDF_OWNERDRAW;
1486 SendMessage(hWndHeader, HDM_SETITEM, 1, (LPARAM)&item);
1487 g_DrawItem.CtlID = 0;
1488 g_DrawItem.CtlType = ODT_HEADER;
1489 g_DrawItem.hwndItem = hWndHeader;
1490 g_DrawItem.itemID = 1;
1491 g_DrawItem.itemState = 0;
1492 SendMessage(hWndHeader, HDM_GETITEMRECT, 1, (LPARAM)&g_DrawItem.rcItem);
1493 run_customdraw_scenario(customdraw_4);
1494 ok(g_DrawItemReceived, "WM_DRAWITEM not received\n");
1495 DestroyWindow(hWndHeader);
1496 hWndHeader = NULL;
1497 g_DrawItem.CtlType = 0;
1498 g_DrawItemReceived = FALSE;
1501 static void check_order(const int expected_id[], const int expected_order[],
1502 int count, const char *type)
1504 int i;
1505 HDITEMA hdi;
1507 ok(getItemCount(hWndHeader) == count, "Invalid item count in order tests\n");
1508 for (i = 0; i < count; i++)
1510 hdi.mask = HDI_LPARAM|HDI_ORDER;
1511 SendMessage(hWndHeader, HDM_GETITEMA, i, (LPARAM)&hdi);
1512 ok(hdi.lParam == expected_id[i],
1513 "Invalid item ids after '%s'- item %d has lParam %d\n", type, i, (int)hdi.lParam);
1514 ok(hdi.iOrder == expected_order[i],
1515 "Invalid item order after '%s'- item %d has iOrder %d\n", type, i, hdi.iOrder);
1519 static void test_header_order (void)
1521 const int rand1[] = {0, 1, 1, 0, 4};
1522 const int rand2[] = {4, 5, 6, 7, 4};
1523 const int rand3[] = {5, 5, 1, 6, 1};
1524 const int rand4[] = {1, 5, 2, 7, 6, 1, 4, 2, 3, 2};
1525 const int rand5[] = {7, 8, 5, 6, 7, 2, 1, 9, 10, 10};
1526 const int rand6[] = {2, 8, 3, 4, 0};
1528 const int ids1[] = {3, 0, 2, 1, 4};
1529 const int ord1[] = {0, 1, 2, 3, 4};
1530 const int ids2[] = {3, 9, 7, 0, 2, 1, 4, 8, 6, 5};
1531 const int ord2[] = {0, 4, 7, 1, 2, 3, 9, 8, 6, 5};
1532 const int ord3[] = {0, 3, 9, 2, 1, 8, 7, 6, 5, 4};
1533 const int ids4[] = {9, 0, 1, 8, 6};
1534 const int ord4[] = {1, 0, 4, 3, 2};
1536 char buffer[20];
1537 HDITEMA hdi;
1538 int i;
1540 hWndHeader = create_header_control();
1542 ZeroMemory(&hdi, sizeof(HDITEMA));
1543 hdi.mask = HDI_TEXT | HDI_LPARAM;
1544 hdi.pszText = buffer;
1545 strcpy(buffer, "test");
1547 for (i = 0; i < 5; i++)
1549 hdi.lParam = i;
1550 SendMessage(hWndHeader, HDM_INSERTITEMA, rand1[i], (LPARAM)&hdi);
1551 rand();
1553 check_order(ids1, ord1, 5, "insert without iOrder");
1555 hdi.mask |= HDI_ORDER;
1556 for (i = 0; i < 5; i++)
1558 hdi.lParam = i + 5;
1559 hdi.iOrder = rand2[i];
1560 SendMessage(hWndHeader, HDM_INSERTITEMA, rand3[i], (LPARAM)&hdi);
1561 rand(); rand();
1563 check_order(ids2, ord2, 10, "insert with order");
1565 hdi.mask = HDI_ORDER;
1566 for (i=0; i<10; i++)
1568 hdi.iOrder = rand5[i];
1569 SendMessage(hWndHeader, HDM_SETITEMA, rand4[i], (LPARAM)&hdi);
1570 rand(); rand();
1572 check_order(ids2, ord3, 10, "setitems changing order");
1574 for (i=0; i<5; i++)
1575 SendMessage(hWndHeader, HDM_DELETEITEM, rand6[i], 0);
1576 check_order(ids4, ord4, 5, "deleteitem");
1578 DestroyWindow(hWndHeader);
1581 static LRESULT CALLBACK HeaderTestWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
1583 DRAWITEMSTRUCT *di;
1584 switch(msg) {
1586 case WM_NOTIFY:
1588 NMHEADERA *hdr = (NMHEADER *)lParam;
1589 EXPECTEDNOTIFY *expected;
1590 int i;
1592 if (hdr->hdr.code == NM_CUSTOMDRAW)
1593 if (g_CustomDrawProc)
1594 return g_CustomDrawProc(g_CustomDrawCount++, (NMCUSTOMDRAW*)hdr);
1596 for (i=0; i<nUnexpectedNotify; i++)
1597 ok(hdr->hdr.code != unexpectedNotify[i], "Received invalid notify %d\n", hdr->hdr.code);
1599 if (nReceivedNotify >= nExpectedNotify || hdr->hdr.hwndFrom != hWndHeader )
1600 break;
1602 expected = &expectedNotify[nReceivedNotify];
1603 if (hdr->hdr.code != expected->iCode)
1604 break;
1606 nReceivedNotify++;
1607 compare_items(hdr->hdr.code, &expected->hdItem, hdr->pitem, expected->fUnicode);
1608 break;
1611 case WM_DRAWITEM:
1612 di = (DRAWITEMSTRUCT *)lParam;
1613 ok(g_DrawItem.CtlType != 0, "Unexpected WM_DRAWITEM\n");
1614 if (g_DrawItem.CtlType == 0) return 0;
1615 g_DrawItemReceived = TRUE;
1616 compare(di->CtlType, g_DrawItem.CtlType, "%d");
1617 compare(di->CtlID, g_DrawItem.CtlID, "%d");
1618 compare(di->hwndItem, g_DrawItem.hwndItem, "%p");
1619 compare(di->itemID, g_DrawItem.itemID, "%d");
1620 compare(di->itemState, g_DrawItem.itemState, "%d");
1621 compare(di->rcItem.left, g_DrawItem.rcItem.left, "%d");
1622 compare(di->rcItem.top, g_DrawItem.rcItem.top, "%d");
1623 compare(di->rcItem.right, g_DrawItem.rcItem.right, "%d");
1624 compare(di->rcItem.bottom, g_DrawItem.rcItem.bottom, "%d");
1625 break;
1627 case WM_DESTROY:
1628 PostQuitMessage(0);
1629 break;
1631 default:
1632 return DefWindowProcA(hWnd, msg, wParam, lParam);
1635 return 0L;
1638 static int init(void)
1640 HMODULE hComctl32;
1641 BOOL (WINAPI *pInitCommonControlsEx)(const INITCOMMONCONTROLSEX*);
1642 WNDCLASSA wc;
1643 INITCOMMONCONTROLSEX iccex;
1644 TEXTMETRICA tm;
1645 HFONT hOldFont;
1646 HDC hdc;
1648 hComctl32 = GetModuleHandleA("comctl32.dll");
1649 pInitCommonControlsEx = (void*)GetProcAddress(hComctl32, "InitCommonControlsEx");
1650 if (!pInitCommonControlsEx)
1652 skip("InitCommonControlsEx() is missing. Skipping the tests\n");
1653 return 0;
1656 iccex.dwSize = sizeof(iccex);
1657 iccex.dwICC = ICC_USEREX_CLASSES;
1658 pInitCommonControlsEx(&iccex);
1660 wc.style = CS_HREDRAW | CS_VREDRAW;
1661 wc.cbClsExtra = 0;
1662 wc.cbWndExtra = 0;
1663 wc.hInstance = GetModuleHandleA(NULL);
1664 wc.hIcon = NULL;
1665 wc.hCursor = LoadCursorA(NULL, IDC_ARROW);
1666 wc.hbrBackground = GetSysColorBrush(COLOR_WINDOW);
1667 wc.lpszMenuName = NULL;
1668 wc.lpszClassName = "HeaderTestClass";
1669 wc.lpfnWndProc = HeaderTestWndProc;
1670 RegisterClassA(&wc);
1672 /* The height of the header control depends on the height of the system font.
1673 The height of the system font is dpi dependent */
1674 hdc = GetDC(0);
1675 hOldFont = SelectObject(hdc, GetStockObject(SYSTEM_FONT));
1676 GetTextMetricsA(hdc, &tm);
1677 /* 2 dot extra space are needed for the border */
1678 g_customheight = tm.tmHeight + 2;
1679 trace("customdraw height: %d (dpi: %d)\n", g_customheight, GetDeviceCaps(hdc, LOGPIXELSY));
1680 SelectObject(hdc, hOldFont);
1681 ReleaseDC(0, hdc);
1683 hHeaderParentWnd = CreateWindowExA(0, "HeaderTestClass", "Header test", WS_OVERLAPPEDWINDOW,
1684 CW_USEDEFAULT, CW_USEDEFAULT, 672+2*GetSystemMetrics(SM_CXSIZEFRAME),
1685 226+GetSystemMetrics(SM_CYCAPTION)+2*GetSystemMetrics(SM_CYSIZEFRAME),
1686 NULL, NULL, GetModuleHandleA(NULL), 0);
1687 assert(hHeaderParentWnd != NULL);
1688 ShowWindow(hHeaderParentWnd, SW_SHOW);
1689 return 1;
1692 /* maximum 8 items allowed */
1693 static void check_orderarray(HWND hwnd, DWORD start, DWORD set, DWORD expected,
1694 int todo, int line)
1696 int count, i;
1697 INT order[8];
1698 DWORD ret, array = 0;
1700 count = SendMessage(hwnd, HDM_GETITEMCOUNT, 0, 0);
1702 /* initial order */
1703 for(i = 1; i<=count; i++)
1704 order[i-1] = start>>(4*(count-i)) & 0xf;
1706 ret = SendMessage(hwnd, HDM_SETORDERARRAY, count, (LPARAM)order);
1707 ok_(__FILE__, line)(ret, "Expected HDM_SETORDERARAY to succeed, got %d\n", ret);
1709 /* new order */
1710 for(i = 1; i<=count; i++)
1711 order[i-1] = set>>(4*(count-i)) & 0xf;
1712 ret = SendMessage(hwnd, HDM_SETORDERARRAY, count, (LPARAM)order);
1713 ok_(__FILE__, line)(ret, "Expected HDM_SETORDERARAY to succeed, got %d\n", ret);
1715 /* check actual order */
1716 ret = SendMessage(hwnd, HDM_GETORDERARRAY, count, (LPARAM)order);
1717 ok_(__FILE__, line)(ret, "Expected HDM_GETORDERARAY to succeed, got %d\n", ret);
1718 for(i = 1; i<=count; i++)
1719 array |= order[i-1]<<(4*(count-i));
1721 if (todo) {
1722 todo_wine
1723 ok_(__FILE__, line)(array == expected, "Expected %x, got %x\n", expected, array);
1725 else
1726 ok_(__FILE__, line)(array == expected, "Expected %x, got %x\n", expected, array);
1729 static void test_hdm_orderarray(void)
1731 HWND hwnd;
1732 INT order[5];
1733 DWORD ret;
1735 hwnd = create_header_control();
1737 /* three items */
1738 addItem(hwnd, 0, NULL);
1739 addItem(hwnd, 1, NULL);
1740 addItem(hwnd, 2, NULL);
1742 ret = SendMessage(hwnd, HDM_GETORDERARRAY, 3, (LPARAM)order);
1743 if (!ret)
1745 win_skip("HDM_GETORDERARRAY not implemented.\n");
1746 DestroyWindow(hwnd);
1747 return;
1750 expect(0, order[0]);
1751 expect(1, order[1]);
1752 expect(2, order[2]);
1754 if (0)
1756 /* null pointer, crashes native */
1757 ret = SendMessage(hwnd, HDM_SETORDERARRAY, 3, 0);
1758 expect(FALSE, ret);
1760 /* count out of limits */
1761 ret = SendMessage(hwnd, HDM_SETORDERARRAY, 5, (LPARAM)order);
1762 expect(FALSE, ret);
1763 /* count out of limits */
1764 ret = SendMessage(hwnd, HDM_SETORDERARRAY, 2, (LPARAM)order);
1765 expect(FALSE, ret);
1767 /* try with out of range item index */
1768 /* (0,1,2)->(1,0,3) => (1,0,2) */
1769 check_orderarray(hwnd, 0x120, 0x103, 0x102, FALSE, __LINE__);
1770 /* (1,0,2)->(3,0,1) => (0,2,1) */
1771 check_orderarray(hwnd, 0x102, 0x301, 0x021, TRUE, __LINE__);
1772 /* (0,2,1)->(2,3,1) => (2,0,1) */
1773 check_orderarray(hwnd, 0x021, 0x231, 0x201, FALSE, __LINE__);
1775 /* (0,1,2)->(0,2,2) => (0,1,2) */
1776 check_orderarray(hwnd, 0x012, 0x022, 0x012, FALSE, __LINE__);
1778 addItem(hwnd, 3, NULL);
1780 /* (0,1,2,3)->(0,1,2,2) => (0,1,3,2) */
1781 check_orderarray(hwnd, 0x0123, 0x0122, 0x0132, FALSE, __LINE__);
1782 /* (0,1,2,3)->(0,1,3,3) => (0,1,2,3) */
1783 check_orderarray(hwnd, 0x0123, 0x0133, 0x0123, FALSE, __LINE__);
1784 /* (0,1,2,3)->(0,4,2,3) => (0,1,2,3) */
1785 check_orderarray(hwnd, 0x0123, 0x0423, 0x0123, FALSE, __LINE__);
1786 /* (0,1,2,3)->(4,0,1,2) => (0,1,3,2) */
1787 check_orderarray(hwnd, 0x0123, 0x4012, 0x0132, TRUE, __LINE__);
1788 /* (0,1,3,2)->(4,0,1,4) => (0,3,1,2) */
1789 check_orderarray(hwnd, 0x0132, 0x4014, 0x0312, TRUE, __LINE__);
1790 /* (0,1,2,3)->(4,1,0,2) => (1,0,3,2) */
1791 check_orderarray(hwnd, 0x0123, 0x4102, 0x1032, TRUE, __LINE__);
1792 /* (0,1,2,3)->(0,1,4,2) => (0,1,2,3) */
1793 check_orderarray(hwnd, 0x0123, 0x0142, 0x0132, FALSE, __LINE__);
1794 /* (0,1,2,3)->(4,4,4,4) => (0,1,2,3) */
1795 check_orderarray(hwnd, 0x0123, 0x4444, 0x0123, FALSE, __LINE__);
1796 /* (0,1,2,3)->(4,4,1,2) => (0,1,3,2) */
1797 check_orderarray(hwnd, 0x0123, 0x4412, 0x0132, TRUE, __LINE__);
1798 /* (0,1,2,3)->(4,4,4,1) => (0,2,3,1) */
1799 check_orderarray(hwnd, 0x0123, 0x4441, 0x0231, TRUE, __LINE__);
1800 /* (0,1,2,3)->(1,4,4,4) => (1,0,2,3) */
1801 check_orderarray(hwnd, 0x0123, 0x1444, 0x1023, FALSE, __LINE__);
1802 /* (0,1,2,3)->(4,2,4,1) => (0,2,3,1) */
1803 check_orderarray(hwnd, 0x0123, 0x4241, 0x0231, FALSE, __LINE__);
1804 /* (0,1,2,3)->(4,2,0,1) => (2,0,3,1) */
1805 check_orderarray(hwnd, 0x0123, 0x4201, 0x2031, TRUE, __LINE__);
1806 /* (3,2,1,0)->(4,2,0,1) => (3,2,0,1) */
1807 check_orderarray(hwnd, 0x3210, 0x4201, 0x3201, FALSE, __LINE__);
1809 DestroyWindow(hwnd);
1812 START_TEST(header)
1814 HWND parent_hwnd;
1815 ULONG_PTR ctx_cookie;
1816 HANDLE hCtx;
1817 HWND hwnd;
1819 if (!init())
1820 return;
1822 test_header_control();
1823 test_header_order();
1824 test_hdm_orderarray();
1825 test_customdraw();
1827 DestroyWindow(hHeaderParentWnd);
1829 init_msg_sequences(sequences, NUM_MSG_SEQUENCES);
1830 parent_hwnd = create_custom_parent_window();
1831 ok_sequence(sequences, PARENT_SEQ_INDEX, create_parent_wnd_seq, "create parent windows", FALSE);
1833 test_hdm_index_messages(parent_hwnd);
1834 test_hdm_getitemrect(parent_hwnd);
1835 test_hdm_hittest(parent_hwnd);
1836 test_hdm_layout(parent_hwnd);
1837 test_hdm_ordertoindex(parent_hwnd);
1838 test_hdm_sethotdivider(parent_hwnd);
1839 test_hdm_imageMessages(parent_hwnd);
1840 test_hdm_filterMessages(parent_hwnd);
1841 test_hdm_unicodeformatMessages(parent_hwnd);
1842 test_hdm_bitmapmarginMessages(parent_hwnd);
1844 if (!load_v6_module(&ctx_cookie, &hCtx))
1846 DestroyWindow(parent_hwnd);
1847 return;
1850 /* this is a XP SP3 failure workaround */
1851 hwnd = CreateWindowExA(0, WC_HEADER, NULL,
1852 WS_CHILD|WS_BORDER|WS_VISIBLE|HDS_BUTTONS|HDS_HORZ,
1853 0, 0, 100, 100,
1854 parent_hwnd, NULL, GetModuleHandleA(NULL), NULL);
1856 if (!IsWindow(hwnd))
1858 win_skip("FIXME: failed to create Header window.\n");
1859 unload_v6_module(ctx_cookie, hCtx);
1860 DestroyWindow(parent_hwnd);
1861 return;
1863 else
1864 DestroyWindow(hwnd);
1866 /* comctl32 version 6 tests start here */
1867 test_hdf_fixedwidth(parent_hwnd);
1868 test_hds_nosizing(parent_hwnd);
1870 unload_v6_module(ctx_cookie, hCtx);
1872 DestroyWindow(parent_hwnd);