include: Use the hard-float calling convention for Windows APIs on ARM
[wine.git] / dlls / comctl32 / tests / header.c
blobae75199be297cf366ef03e02040c24868c557215
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>
25 #include "wine/test.h"
26 #include "v6util.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_INSERTITEMA, sent|wparam, 0 },
100 { HDM_INSERTITEMA, sent|wparam, 1 },
101 { HDM_INSERTITEMA, sent|wparam, 2 },
102 { HDM_INSERTITEMA, sent|wparam, 3 },
103 { 0 }
106 static const struct message getItem_seq[] = {
107 { HDM_GETITEMA, sent|wparam, 3 },
108 { HDM_GETITEMA, 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_SETORDERARRAY, sent|wparam, 2 },
125 { HDM_GETORDERARRAY, sent|wparam, 2 },
126 { 0 }
129 static const struct message setItem_seq[] = {
130 { HDM_SETITEMA, sent|wparam, 0 },
131 { HDM_SETITEMA, sent|wparam, 1 },
132 { 0 }
135 static const struct message getItemRect_seq[] = {
136 { HDM_GETITEMRECT, sent|wparam, 1 },
137 { HDM_GETITEMRECT, sent|wparam, 0 },
138 { HDM_GETITEMRECT, sent|wparam, 10 },
139 { 0 }
142 static const struct message layout_seq[] = {
143 { HDM_LAYOUT, sent },
144 { 0 }
147 static const struct message orderToIndex_seq[] = {
148 { HDM_ORDERTOINDEX, sent|wparam, 1 },
149 { 0 }
152 static const struct message hittest_seq[] = {
153 { HDM_HITTEST, sent },
154 { HDM_HITTEST, sent },
155 { HDM_HITTEST, sent },
156 { 0 }
159 static const struct message setHotDivider_seq_interactive[] = {
160 { HDM_SETHOTDIVIDER, sent|wparam, TRUE },
161 { WM_PAINT, sent|defwinproc},
162 { WM_NCPAINT, sent|defwinproc},
163 { WM_ERASEBKGND, sent|defwinproc},
164 { HDM_SETHOTDIVIDER, sent|wparam|lparam, FALSE, 100 },
165 { WM_PAINT, sent|defwinproc},
166 { HDM_SETHOTDIVIDER, sent|wparam|lparam, FALSE, 1},
167 { WM_PAINT, sent|defwinproc},
168 { 0 }
171 static const struct message setHotDivider_seq_noninteractive[] = {
172 { HDM_SETHOTDIVIDER, sent|wparam, TRUE },
173 { HDM_SETHOTDIVIDER, sent|wparam|lparam, FALSE, 100 },
174 { HDM_SETHOTDIVIDER, sent|wparam|lparam, FALSE, 1},
175 { 0 }
178 static const struct message imageMessages_seq[] = {
179 { HDM_SETIMAGELIST, sent },
180 { HDM_GETIMAGELIST, sent },
181 { HDM_CREATEDRAGIMAGE, sent },
182 { 0 }
185 static const struct message filterMessages_seq_interactive[] = {
186 { HDM_SETFILTERCHANGETIMEOUT, sent|wparam|lparam, 1, 100 },
187 { HDM_CLEARFILTER, sent|wparam|lparam, 0, 1 },
188 { HDM_EDITFILTER, sent|wparam|lparam, 1, 0 },
189 { WM_PARENTNOTIFY, sent|wparam|defwinproc, WM_CREATE },
190 { WM_CTLCOLOREDIT, sent|defwinproc },
191 { WM_COMMAND, sent|defwinproc },
192 { 0 }
195 static const struct message filterMessages_seq_noninteractive[] = {
196 { HDM_SETFILTERCHANGETIMEOUT, sent|wparam|lparam, 1, 100 },
197 { HDM_CLEARFILTER, sent|wparam|lparam, 0, 1 },
198 { HDM_EDITFILTER, sent|wparam|lparam, 1, 0 },
199 { WM_PARENTNOTIFY, sent|wparam|defwinproc|optional, WM_CREATE },
200 { WM_COMMAND, sent|defwinproc|optional },
201 { 0 }
204 static const struct message unicodeformatMessages_seq[] = {
205 { HDM_SETUNICODEFORMAT, sent|wparam, TRUE },
206 { HDM_GETUNICODEFORMAT, sent },
207 { 0 }
210 static const struct message bitmapmarginMessages_seq[] = {
211 { HDM_GETBITMAPMARGIN, sent },
212 { 0 }
216 static void expect_notify(INT iCode, BOOL fUnicode, HDITEMA *lpItem)
218 ok(nExpectedNotify < 10, "notification count %d\n", nExpectedNotify);
219 if (nExpectedNotify < 10)
221 expectedNotify[nExpectedNotify].iCode = iCode;
222 expectedNotify[nExpectedNotify].fUnicode = fUnicode;
223 expectedNotify[nExpectedNotify].hdItem = *lpItem;
224 nExpectedNotify++;
228 static void dont_expect_notify(INT iCode)
230 ok(nExpectedNotify < 10, "notification count %d\n", nExpectedNotify);
231 if (nExpectedNotify < 10)
232 unexpectedNotify[nUnexpectedNotify++] = iCode;
235 static BOOL notifies_received(void)
237 BOOL fRet = (nExpectedNotify == nReceivedNotify);
238 nExpectedNotify = nReceivedNotify = 0;
239 nUnexpectedNotify = 0;
240 return fRet;
243 static LONG addItem(HWND hdex, int idx, LPSTR text)
245 HDITEMA hdItem;
246 hdItem.mask = HDI_TEXT | HDI_WIDTH;
247 hdItem.cxy = 100;
248 hdItem.pszText = text;
249 hdItem.cchTextMax = 0;
250 return SendMessageA(hdex, HDM_INSERTITEMA, idx, (LPARAM)&hdItem);
253 static LONG setItem(HWND hdex, int idx, LPSTR text, BOOL fCheckNotifies)
255 LONG ret;
256 HDITEMA hdexItem;
257 hdexItem.mask = HDI_TEXT;
258 hdexItem.pszText = text;
259 hdexItem.cchTextMax = 0;
260 if (fCheckNotifies)
262 expect_notify(HDN_ITEMCHANGINGA, FALSE, &hdexItem);
263 expect_notify(HDN_ITEMCHANGEDA, FALSE, &hdexItem);
265 ret = SendMessageA(hdex, HDM_SETITEMA, idx, (LPARAM)&hdexItem);
266 if (fCheckNotifies)
267 ok(notifies_received(), "setItem(): not all expected notifies were received\n");
268 return ret;
271 static LONG setItemUnicodeNotify(HWND hdex, int idx, LPSTR text, LPWSTR wText)
273 LONG ret;
274 HDITEMA hdexItem;
275 HDITEMW hdexNotify;
276 hdexItem.mask = HDI_TEXT;
277 hdexItem.pszText = text;
278 hdexItem.cchTextMax = 0;
280 hdexNotify.mask = HDI_TEXT;
281 hdexNotify.pszText = wText;
283 expect_notify(HDN_ITEMCHANGINGW, TRUE, (HDITEMA*)&hdexNotify);
284 expect_notify(HDN_ITEMCHANGEDW, TRUE, (HDITEMA*)&hdexNotify);
285 ret = SendMessageA(hdex, HDM_SETITEMA, idx, (LPARAM)&hdexItem);
286 ok(notifies_received(), "setItemUnicodeNotify(): not all expected notifies were received\n");
287 return ret;
290 static LONG delItem(HWND hdex, int idx)
292 return SendMessageA(hdex, HDM_DELETEITEM, idx, 0);
295 static LONG getItemCount(HWND hdex)
297 return SendMessageA(hdex, HDM_GETITEMCOUNT, 0, 0);
300 static LONG getItem(HWND hdex, int idx, LPSTR textBuffer)
302 HDITEMA hdItem;
303 hdItem.mask = HDI_TEXT;
304 hdItem.pszText = textBuffer;
305 hdItem.cchTextMax = MAX_CHARS;
306 return SendMessageA(hdex, HDM_GETITEMA, idx, (LPARAM)&hdItem);
309 static void addReadDelItem(HWND hdex, HDITEMA *phdiCreate, int maskRead, HDITEMA *phdiRead)
311 ok(SendMessageA(hdex, HDM_INSERTITEMA, 0, (LPARAM)phdiCreate)!=-1, "Adding item failed\n");
312 ZeroMemory(phdiRead, sizeof(HDITEMA));
313 phdiRead->mask = maskRead;
314 ok(SendMessageA(hdex, HDM_GETITEMA, 0, (LPARAM)phdiRead)!=0, "Getting item data failed\n");
315 ok(SendMessageA(hdex, HDM_DELETEITEM, 0, 0)!=0, "Deleting item failed\n");
318 static HWND create_header_control (void)
320 HWND handle;
321 HDLAYOUT hlayout;
322 RECT rectwin;
323 WINDOWPOS winpos;
325 handle = CreateWindowExA(0, WC_HEADERA, NULL,
326 WS_CHILD|WS_BORDER|WS_VISIBLE|HDS_BUTTONS|HDS_HORZ,
327 0, 0, 0, 0,
328 hHeaderParentWnd, NULL, NULL, NULL);
329 ok(handle != NULL, "failed to create header window\n");
331 if (winetest_interactive)
332 ShowWindow (hHeaderParentWnd, SW_SHOW);
334 GetClientRect(hHeaderParentWnd,&rectwin);
335 hlayout.prc = &rectwin;
336 hlayout.pwpos = &winpos;
337 SendMessageA(handle, HDM_LAYOUT, 0, (LPARAM)&hlayout);
338 SetWindowPos(handle, winpos.hwndInsertAfter, winpos.x, winpos.y,
339 winpos.cx, winpos.cy, 0);
341 return handle;
344 static void compare_items(INT iCode, HDITEMA *hdi1, HDITEMA *hdi2, BOOL fUnicode)
346 ok(hdi1->mask == hdi2->mask, "Notify %d mask mismatch (%08x != %08x)\n", iCode, hdi1->mask, hdi2->mask);
347 if (hdi1->mask & HDI_WIDTH)
349 ok(hdi1->cxy == hdi2->cxy, "Notify %d cxy mismatch (%08x != %08x)\n", iCode, hdi1->cxy, hdi2->cxy);
351 if (hdi1->mask & HDI_TEXT)
353 if (hdi1->pszText == LPSTR_TEXTCALLBACKA)
355 ok(hdi1->pszText == LPSTR_TEXTCALLBACKA, "Notify %d - only one item is LPSTR_TEXTCALLBACK\n", iCode);
357 else
358 if (fUnicode)
360 char buf1[260];
361 char buf2[260];
362 WideCharToMultiByte(CP_ACP, 0, (LPCWSTR)hdi1->pszText, -1, buf1, 260, NULL, NULL);
363 WideCharToMultiByte(CP_ACP, 0, (LPCWSTR)hdi2->pszText, -1, buf2, 260, NULL, NULL);
364 ok(lstrcmpW((LPWSTR)hdi1->pszText, (LPWSTR)hdi2->pszText)==0,
365 "Notify %d text mismatch (L\"%s\" vs L\"%s\")\n",
366 iCode, buf1, buf2);
368 else
370 ok(strcmp(hdi1->pszText, hdi2->pszText)==0,
371 "Notify %d text mismatch (\"%s\" vs \"%s\")\n",
372 iCode, hdi1->pszText, hdi2->pszText);
377 static char pszFirstItem[] = "First Item";
378 static char pszSecondItem[] = "Second Item";
379 static char pszThirdItem[] = "Third Item";
380 static char pszFourthItem[] = "Fourth Item";
381 static char pszReplaceItem[] = "Replace Item";
382 static char pszOutOfRangeItem[] = "Out Of Range Item";
384 static char *str_items[] =
385 {pszFirstItem, pszSecondItem, pszThirdItem, pszFourthItem, pszReplaceItem, pszOutOfRangeItem};
387 static char pszUniTestA[] = "TST";
388 static WCHAR pszUniTestW[] = {'T','S','T',0};
391 #define TEST_GET_ITEM(i,c)\
392 { res = getItem(hWndHeader, i, buffer);\
393 ok(res != 0, "Getting item[%d] using valid index failed unexpectedly (%d)\n", i, res);\
394 ok(strcmp(str_items[c], buffer) == 0, "Getting item[%d] returned \"%s\" expecting \"%s\"\n", i, buffer, str_items[c]);\
397 #define TEST_GET_ITEMCOUNT(i)\
398 { res = getItemCount(hWndHeader);\
399 ok(res == i, "Got Item Count as %d\n", res);\
402 static LRESULT WINAPI header_subclass_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
404 WNDPROC oldproc = (WNDPROC)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
405 static LONG defwndproc_counter = 0;
406 struct message msg = { 0 };
407 LRESULT ret;
409 msg.message = message;
410 msg.flags = sent|wparam|lparam;
411 if (defwndproc_counter) msg.flags |= defwinproc;
412 msg.wParam = wParam;
413 msg.lParam = lParam;
414 add_message(sequences, HEADER_SEQ_INDEX, &msg);
416 defwndproc_counter++;
417 ret = CallWindowProcA(oldproc, hwnd, message, wParam, lParam);
418 defwndproc_counter--;
420 return ret;
423 static LRESULT WINAPI parent_wnd_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
425 static LONG defwndproc_counter = 0;
426 LRESULT ret;
427 struct message msg;
429 /* do not log painting messages */
430 if (message != WM_PAINT &&
431 message != WM_ERASEBKGND &&
432 message != WM_NCPAINT &&
433 message != WM_NCHITTEST &&
434 message != WM_GETTEXT &&
435 message != WM_GETICON &&
436 message != WM_DEVICECHANGE)
439 msg.message = message;
440 msg.flags = sent|wparam|lparam;
441 if (defwndproc_counter) msg.flags |= defwinproc;
442 msg.wParam = wParam;
443 msg.lParam = lParam;
444 msg.id = 0;
445 add_message(sequences, PARENT_SEQ_INDEX, &msg);
448 defwndproc_counter++;
449 ret = DefWindowProcA(hwnd, message, wParam, lParam);
450 defwndproc_counter--;
452 return ret;
455 static BOOL register_parent_wnd_class(void)
457 WNDCLASSA cls;
459 cls.style = 0;
460 cls.lpfnWndProc = parent_wnd_proc;
461 cls.cbClsExtra = 0;
462 cls.cbWndExtra = 0;
463 cls.hInstance = GetModuleHandleA(NULL);
464 cls.hIcon = 0;
465 cls.hCursor = LoadCursorA(0, (LPCSTR)IDC_ARROW);
466 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
467 cls.lpszMenuName = NULL;
468 cls.lpszClassName = "Header test parent class";
469 return RegisterClassA(&cls);
472 static HWND create_custom_parent_window(void)
474 if (!register_parent_wnd_class())
475 return NULL;
477 return CreateWindowExA(0, "Header test parent class", "Header Message Sequence Testing",
478 WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT,
479 672+2*GetSystemMetrics(SM_CXSIZEFRAME),
480 226+GetSystemMetrics(SM_CYCAPTION)+2*GetSystemMetrics(SM_CYSIZEFRAME),
481 NULL, NULL, GetModuleHandleA(NULL), 0);
484 static HWND create_custom_header_control(HWND hParent, BOOL preloadHeaderItems)
486 WNDPROC oldproc;
487 HWND childHandle;
488 HDLAYOUT hlayout;
489 RECT rectwin;
490 WINDOWPOS winpos;
491 int retVal;
492 int loopcnt;
493 static char firstHeaderItem[] = "Name";
494 static char secondHeaderItem[] = "Size";
495 static char *items[] = {secondHeaderItem, firstHeaderItem};
496 HDITEMA hdItem;
497 hdItem.mask = HDI_TEXT | HDI_WIDTH | HDI_FORMAT;
498 hdItem.fmt = HDF_LEFT;
499 hdItem.cxy = 80;
500 hdItem.cchTextMax = 260;
502 flush_sequences(sequences, NUM_MSG_SEQUENCES);
504 childHandle = CreateWindowExA(0, WC_HEADERA, NULL,
505 WS_CHILD|WS_BORDER|WS_VISIBLE|HDS_BUTTONS|HDS_HORZ,
506 0, 0, 0, 0,
507 hParent, NULL, NULL, NULL);
508 ok(childHandle != NULL, "failed to create child window\n");
509 if (preloadHeaderItems)
511 for ( loopcnt = 0 ; loopcnt < 2 ; loopcnt++ )
513 hdItem.pszText = items[loopcnt];
514 retVal = SendMessageA(childHandle, HDM_INSERTITEMA, loopcnt, (LPARAM) &hdItem);
515 ok(retVal == loopcnt, "Adding item %d failed with return value %d\n", ( loopcnt + 1 ), retVal);
519 if (winetest_interactive)
520 ShowWindow (hParent, SW_SHOW);
522 GetClientRect(hParent,&rectwin);
523 hlayout.prc = &rectwin;
524 hlayout.pwpos = &winpos;
525 SendMessageA(childHandle,HDM_LAYOUT,0,(LPARAM) &hlayout);
526 SetWindowPos(childHandle, winpos.hwndInsertAfter, winpos.x, winpos.y,
527 winpos.cx, winpos.cy, 0);
529 oldproc = (WNDPROC)SetWindowLongPtrA(childHandle, GWLP_WNDPROC,
530 (LONG_PTR)header_subclass_proc);
531 SetWindowLongPtrA(childHandle, GWLP_USERDATA, (LONG_PTR)oldproc);
532 return childHandle;
535 static void check_auto_format(void)
537 HDITEMA hdiCreate;
538 HDITEMA hdiRead;
539 static CHAR text[] = "Test";
540 ZeroMemory(&hdiCreate, sizeof(HDITEMA));
542 /* Windows implicitly sets some format bits in INSERTITEM */
544 /* HDF_STRING is automatically set and cleared for no text */
545 hdiCreate.mask = HDI_TEXT|HDI_WIDTH|HDI_FORMAT;
546 hdiCreate.pszText = text;
547 hdiCreate.cxy = 100;
548 hdiCreate.fmt=HDF_CENTER;
549 addReadDelItem(hWndHeader, &hdiCreate, HDI_FORMAT, &hdiRead);
550 ok(hdiRead.fmt == (HDF_STRING|HDF_CENTER), "HDF_STRING not set automatically (fmt=%x)\n", hdiRead.fmt);
552 hdiCreate.mask = HDI_WIDTH|HDI_FORMAT;
553 hdiCreate.pszText = text;
554 hdiCreate.fmt = HDF_CENTER|HDF_STRING;
555 addReadDelItem(hWndHeader, &hdiCreate, HDI_FORMAT, &hdiRead);
556 ok(hdiRead.fmt == (HDF_CENTER), "HDF_STRING should be automatically cleared (fmt=%x)\n", hdiRead.fmt);
558 /* HDF_BITMAP is automatically set and cleared for a NULL bitmap or no bitmap */
559 hdiCreate.mask = HDI_BITMAP|HDI_WIDTH|HDI_FORMAT;
560 hdiCreate.hbm = CreateBitmap(16, 16, 1, 8, NULL);
561 hdiCreate.fmt = HDF_CENTER;
562 addReadDelItem(hWndHeader, &hdiCreate, HDI_FORMAT, &hdiRead);
563 ok(hdiRead.fmt == (HDF_BITMAP|HDF_CENTER), "HDF_BITMAP not set automatically (fmt=%x)\n", hdiRead.fmt);
564 DeleteObject(hdiCreate.hbm);
566 hdiCreate.hbm = NULL;
567 hdiCreate.fmt = HDF_CENTER|HDF_BITMAP;
568 addReadDelItem(hWndHeader, &hdiCreate, HDI_FORMAT, &hdiRead);
569 ok(hdiRead.fmt == HDF_CENTER, "HDF_BITMAP not cleared automatically for NULL bitmap (fmt=%x)\n", hdiRead.fmt);
571 hdiCreate.mask = HDI_WIDTH|HDI_FORMAT;
572 hdiCreate.fmt = HDF_CENTER|HDF_BITMAP;
573 addReadDelItem(hWndHeader, &hdiCreate, HDI_FORMAT, &hdiRead);
574 ok(hdiRead.fmt == HDF_CENTER, "HDF_BITMAP not cleared automatically for no bitmap (fmt=%x)\n", hdiRead.fmt);
576 /* HDF_IMAGE is automatically set but not cleared */
577 hdiCreate.mask = HDI_IMAGE|HDI_WIDTH|HDI_FORMAT;
578 hdiCreate.iImage = 17;
579 addReadDelItem(hWndHeader, &hdiCreate, HDI_FORMAT, &hdiRead);
580 ok(hdiRead.fmt == (HDF_IMAGE|HDF_CENTER), "HDF_IMAGE not set automatically (fmt=%x)\n", hdiRead.fmt);
582 hdiCreate.mask = HDI_WIDTH|HDI_FORMAT;
583 hdiCreate.fmt = HDF_CENTER|HDF_IMAGE;
584 hdiCreate.iImage = 0;
585 addReadDelItem(hWndHeader, &hdiCreate, HDI_FORMAT, &hdiRead);
586 ok(hdiRead.fmt == (HDF_CENTER|HDF_IMAGE), "HDF_IMAGE shouldn't be cleared automatically (fmt=%x)\n", hdiRead.fmt);
589 static void check_auto_fields(void)
591 HDITEMA hdiCreate;
592 HDITEMA hdiRead;
593 static CHAR text[] = "Test";
594 LONG res;
596 /* Windows stores the format, width, lparam even if they are not in the item's mask */
597 ZeroMemory(&hdiCreate, sizeof(HDITEMA));
598 hdiCreate.mask = HDI_TEXT;
599 hdiCreate.cxy = 100;
600 hdiCreate.pszText = text;
601 addReadDelItem(hWndHeader, &hdiCreate, HDI_WIDTH, &hdiRead);
602 TEST_GET_ITEMCOUNT(6);
603 ok(hdiRead.cxy == hdiCreate.cxy, "cxy should be automatically set\n");
605 ZeroMemory(&hdiCreate, sizeof(HDITEMA));
606 hdiCreate.mask = HDI_TEXT;
607 hdiCreate.pszText = text;
608 hdiCreate.lParam = 0x12345678;
609 addReadDelItem(hWndHeader, &hdiCreate, HDI_LPARAM, &hdiRead);
610 TEST_GET_ITEMCOUNT(6);
611 ok(hdiRead.lParam == hdiCreate.lParam, "lParam should be automatically set\n");
613 ZeroMemory(&hdiCreate, sizeof(HDITEMA));
614 hdiCreate.mask = HDI_TEXT;
615 hdiCreate.pszText = text;
616 hdiCreate.fmt = HDF_STRING|HDF_CENTER;
617 addReadDelItem(hWndHeader, &hdiCreate, HDI_FORMAT, &hdiRead);
618 TEST_GET_ITEMCOUNT(6);
619 ok(hdiRead.fmt == hdiCreate.fmt, "fmt should be automatically set\n");
621 /* others fields are not set */
622 ZeroMemory(&hdiCreate, sizeof(HDITEMA));
623 hdiCreate.mask = HDI_TEXT;
624 hdiCreate.pszText = text;
625 hdiCreate.hbm = CreateBitmap(16, 16, 1, 8, NULL);
626 addReadDelItem(hWndHeader, &hdiCreate, HDI_BITMAP, &hdiRead);
627 TEST_GET_ITEMCOUNT(6);
628 ok(hdiRead.hbm == NULL, "hbm should not be automatically set\n");
629 DeleteObject(hdiCreate.hbm);
631 ZeroMemory(&hdiCreate, sizeof(HDITEMA));
632 hdiCreate.mask = HDI_IMAGE;
633 hdiCreate.iImage = 17;
634 hdiCreate.pszText = text;
635 addReadDelItem(hWndHeader, &hdiCreate, HDI_TEXT, &hdiRead);
636 TEST_GET_ITEMCOUNT(6);
637 ok(hdiRead.pszText==NULL, "pszText shouldn't be automatically set\n");
639 /* field from comctl >4.0 not tested as the system probably won't touch them */
642 static void check_mask(void)
644 HDITEMA hdi;
645 static CHAR text[] = "ABC";
646 LRESULT ret;
648 /* don't create items if the mask is zero */
649 ZeroMemory(&hdi, sizeof(hdi));
650 hdi.mask = 0;
651 hdi.cxy = 200;
652 hdi.pszText = text;
653 hdi.fmt = 0;
654 hdi.iOrder = 0;
655 hdi.lParam = 17;
656 hdi.cchTextMax = 260;
657 ret = SendMessageA(hWndHeader, HDM_INSERTITEMA, 0, (LPARAM)&hdi);
658 ok(ret == -1, "Creating an item with a zero mask should have failed\n");
659 if (ret != -1) SendMessageA(hWndHeader, HDM_DELETEITEM, 0, 0);
661 /* with a non-zero mask creation will succeed */
662 ZeroMemory(&hdi, sizeof(hdi));
663 hdi.mask = HDI_LPARAM;
664 ret = SendMessageA(hWndHeader, HDM_INSERTITEMA, 0, (LPARAM)&hdi);
665 ok(ret != -1, "Adding item with non-zero mask failed\n");
666 if (ret != -1)
667 SendMessageA(hWndHeader, HDM_DELETEITEM, 0, 0);
669 /* in SETITEM if the mask contains a unknown bit, it is ignored */
670 ZeroMemory(&hdi, sizeof(hdi));
671 hdi.mask = 0x08000000 | HDI_LPARAM | HDI_IMAGE;
672 hdi.lParam = 133;
673 hdi.iImage = 17;
674 ret = SendMessageA(hWndHeader, HDM_INSERTITEMA, 0, (LPARAM)&hdi);
675 ok(ret != -1, "Adding item failed\n");
677 if (ret != -1)
679 /* check result */
680 ZeroMemory(&hdi, sizeof(hdi));
681 hdi.mask = HDI_LPARAM | HDI_IMAGE;
682 SendMessageA(hWndHeader, HDM_GETITEMA, 0, (LPARAM)&hdi);
683 ok(hdi.lParam == 133, "comctl32 4.0 field not set\n");
684 ok(hdi.iImage == 17, "comctl32 >4.0 field not set\n");
686 /* but in GETITEM if an unknown bit is set, comctl32 uses only version 4.0 fields */
687 ZeroMemory(&hdi, sizeof(hdi));
688 hdi.mask = 0x08000000 | HDI_LPARAM | HDI_IMAGE;
689 SendMessageA(hWndHeader, HDM_GETITEMA, 0, (LPARAM)&hdi);
690 ok(hdi.lParam == 133, "comctl32 4.0 field not read\n");
691 ok(hdi.iImage == 0, "comctl32 >4.0 field shouldn't be read\n");
693 SendMessageA(hWndHeader, HDM_DELETEITEM, 0, 0);
697 static void test_header_control (void)
699 LONG res;
700 static char buffer[MAX_CHARS];
701 int i;
703 hWndHeader = create_header_control ();
705 for (i = 3; i >= 0; i--)
707 TEST_GET_ITEMCOUNT(3-i);
708 res = addItem(hWndHeader, 0, str_items[i]);
709 ok(res == 0, "Adding simple item failed (%d)\n", res);
712 TEST_GET_ITEMCOUNT(4);
713 res = addItem(hWndHeader, 99, str_items[i+1]);
714 ok(res != -1, "Adding Out of Range item should fail with -1 got (%d)\n", res);
715 TEST_GET_ITEMCOUNT(5);
716 res = addItem(hWndHeader, 5, str_items[i+1]);
717 ok(res != -1, "Adding Out of Range item should fail with -1 got (%d)\n", res);
718 TEST_GET_ITEMCOUNT(6);
720 for (i = 0; i < 4; i++) { TEST_GET_ITEM(i,i); TEST_GET_ITEMCOUNT(6); }
722 res=getItem(hWndHeader, 99, buffer);
723 ok(res == 0, "Getting Out of Range item should fail with 0 (%d), got %s\n", res,buffer);
724 res=getItem(hWndHeader, 5, buffer);
725 ok(res == 1, "Getting Out of Range item should fail with 1 (%d), got %s\n", res,buffer);
726 res=getItem(hWndHeader, -2, buffer);
727 ok(res == 0, "Getting Out of Range item should fail with 0 (%d), got %s\n", res,buffer);
729 if (winetest_interactive)
731 UpdateWindow(hHeaderParentWnd);
732 UpdateWindow(hWndHeader);
735 TEST_GET_ITEMCOUNT(6);
736 res=setItem(hWndHeader, 99, str_items[5], FALSE);
737 ok(res == 0, "Setting Out of Range item should fail with 0 (%d)\n", res);
738 res=setItem(hWndHeader, 5, str_items[5], TRUE);
739 ok(res == 1, "Setting Out of Range item should fail with 1 (%d)\n", res);
740 res=setItem(hWndHeader, -2, str_items[5], FALSE);
741 ok(res == 0, "Setting Out of Range item should fail with 0 (%d)\n", res);
742 TEST_GET_ITEMCOUNT(6);
744 for (i = 0; i < 4; i++)
746 res = setItem(hWndHeader, i, str_items[4], TRUE);
747 ok(res != 0, "Setting %d item failed (%d)\n", i+1, res);
748 TEST_GET_ITEM(i, 4);
749 TEST_GET_ITEMCOUNT(6);
752 SendMessageA(hWndHeader, HDM_SETUNICODEFORMAT, TRUE, 0);
753 setItemUnicodeNotify(hWndHeader, 3, pszUniTestA, pszUniTestW);
754 SendMessageA(hWndHeader, WM_NOTIFYFORMAT, (WPARAM)hHeaderParentWnd, NF_REQUERY);
755 setItem(hWndHeader, 3, str_items[4], TRUE);
757 dont_expect_notify(HDN_GETDISPINFOA);
758 dont_expect_notify(HDN_GETDISPINFOW);
759 addItem(hWndHeader, 0, LPSTR_TEXTCALLBACKA);
760 setItem(hWndHeader, 0, str_items[4], TRUE);
761 /* unexpected notifies cleared by notifies_received in setItem */
762 dont_expect_notify(HDN_GETDISPINFOA);
763 dont_expect_notify(HDN_GETDISPINFOW);
764 setItem(hWndHeader, 0, LPSTR_TEXTCALLBACKA, TRUE);
765 /* unexpected notifies cleared by notifies_received in setItem */
766 delItem(hWndHeader, 0);
768 check_auto_format();
769 TEST_GET_ITEMCOUNT(6);
770 check_auto_fields();
771 TEST_GET_ITEMCOUNT(6);
772 check_mask();
773 TEST_GET_ITEMCOUNT(6);
775 res = delItem(hWndHeader, 5);
776 ok(res == 1, "Deleting Out of Range item should fail with 1 (%d)\n", res);
777 res = delItem(hWndHeader, -2);
778 ok(res == 0, "Deleting Out of Range item should fail with 0 (%d)\n", res);
779 TEST_GET_ITEMCOUNT(5);
781 res = delItem(hWndHeader, 3);
782 ok(res != 0, "Deleting using out of range index failed (%d)\n", res);
783 TEST_GET_ITEMCOUNT(4);
784 res = delItem(hWndHeader, 0);
785 ok(res != 0, "Deleting using out of range index failed (%d)\n", res);
786 TEST_GET_ITEMCOUNT(3);
787 res = delItem(hWndHeader, 0);
788 ok(res != 0, "Deleting using out of range index failed (%d)\n", res);
789 TEST_GET_ITEMCOUNT(2);
790 res = delItem(hWndHeader, 0);
791 ok(res != 0, "Deleting using out of range index failed (%d)\n", res);
792 TEST_GET_ITEMCOUNT(1);
794 DestroyWindow(hWndHeader);
797 static void test_hdm_getitemrect(HWND hParent)
800 HWND hChild;
801 RECT rect;
802 int retVal;
804 flush_sequences(sequences, NUM_MSG_SEQUENCES);
805 hChild = create_custom_header_control(hParent, TRUE);
806 ok_sequence(sequences, PARENT_SEQ_INDEX, add_header_to_parent_seq,
807 "adder header control to parent", FALSE);
809 retVal = SendMessageA(hChild, HDM_GETITEMRECT, 1, (LPARAM) &rect);
810 ok(retVal == TRUE, "Getting item rect should TRUE, got %d\n", retVal);
811 /* check bounding rectangle information of 2nd header item */
812 expect(80, rect.left);
813 expect(0, rect.top);
814 expect(160, rect.right);
815 expect(g_customheight, rect.bottom);
817 retVal = SendMessageA(hChild, HDM_GETITEMRECT, 0, (LPARAM) &rect);
819 ok(retVal == TRUE, "Getting item rect should TRUE, got %d\n", retVal);
820 /* check bounding rectangle information of 1st header item */
821 expect(0, rect.left);
822 expect(0, rect.top);
824 expect(80, rect.right);
825 expect(g_customheight, rect.bottom);
827 retVal = SendMessageA(hChild, HDM_GETITEMRECT, 10, (LPARAM) &rect);
828 ok(retVal == 0, "Getting rect of nonexistent item should return 0, got %d\n", retVal);
830 ok_sequence(sequences, HEADER_SEQ_INDEX, getItemRect_seq, "getItemRect sequence testing", FALSE);
831 DestroyWindow(hChild);
834 static void test_hdm_layout(HWND hParent)
836 HWND hChild;
837 int retVal;
838 RECT rect;
839 HDLAYOUT hdLayout;
840 WINDOWPOS windowPos;
841 hdLayout.prc = &rect;
842 hdLayout.pwpos = &windowPos;
844 flush_sequences(sequences, NUM_MSG_SEQUENCES);
845 hChild = create_custom_header_control(hParent, TRUE);
846 ok_sequence(sequences, PARENT_SEQ_INDEX, add_header_to_parent_seq,
847 "adder header control to parent", FALSE);
849 flush_sequences(sequences, NUM_MSG_SEQUENCES);
850 retVal = SendMessageA(hChild, HDM_LAYOUT, 0, (LPARAM) &hdLayout);
851 expect(TRUE, retVal);
853 ok_sequence(sequences, HEADER_SEQ_INDEX, layout_seq, "layout sequence testing", FALSE);
855 DestroyWindow(hChild);
858 static void test_hdm_ordertoindex(HWND hParent)
860 HWND hChild;
861 int retVal;
863 flush_sequences(sequences, NUM_MSG_SEQUENCES);
864 hChild = create_custom_header_control(hParent, TRUE);
865 ok_sequence(sequences, PARENT_SEQ_INDEX, add_header_to_parent_seq,
866 "adder header control to parent", FALSE);
868 flush_sequences(sequences, NUM_MSG_SEQUENCES);
869 retVal = SendMessageA(hChild, HDM_ORDERTOINDEX, 1, 0);
870 expect(1, retVal);
872 ok_sequence(sequences, HEADER_SEQ_INDEX, orderToIndex_seq, "orderToIndex sequence testing", FALSE);
873 DestroyWindow(hChild);
876 static void test_hdm_hittest(HWND hParent)
878 HWND hChild;
879 int retVal;
880 POINT pt;
881 HDHITTESTINFO hdHitTestInfo;
882 const int firstItemRightBoundary = 80;
883 const int secondItemRightBoundary = 160;
884 const int bottomBoundary = g_customheight;
886 pt.x = firstItemRightBoundary - 1;
887 pt.y = bottomBoundary - 1;
888 hdHitTestInfo.pt = pt;
891 flush_sequences(sequences, NUM_MSG_SEQUENCES);
892 hChild = create_custom_header_control(hParent, TRUE);
893 ok_sequence(sequences, PARENT_SEQ_INDEX, add_header_to_parent_seq,
894 "adder header control to parent", FALSE);
896 flush_sequences(sequences, NUM_MSG_SEQUENCES);
897 retVal = SendMessageA(hChild, HDM_HITTEST, 0, (LPARAM) &hdHitTestInfo);
898 expect(0, retVal);
899 expect(0, hdHitTestInfo.iItem);
900 expect(HHT_ONDIVIDER, hdHitTestInfo.flags);
902 pt.x = secondItemRightBoundary - 1;
903 pt.y = bottomBoundary - 1;
904 hdHitTestInfo.pt = pt;
905 retVal = SendMessageA(hChild, HDM_HITTEST, 1, (LPARAM) &hdHitTestInfo);
906 expect(1, retVal);
907 expect(1, hdHitTestInfo.iItem);
908 expect(HHT_ONDIVIDER, hdHitTestInfo.flags);
910 pt.x = secondItemRightBoundary;
911 pt.y = bottomBoundary + 1;
912 hdHitTestInfo.pt = pt;
913 retVal = SendMessageA(hChild, HDM_HITTEST, 0, (LPARAM) &hdHitTestInfo);
914 expect(-1, retVal);
915 expect(-1, hdHitTestInfo.iItem);
916 expect(HHT_BELOW, hdHitTestInfo.flags);
918 ok_sequence(sequences, HEADER_SEQ_INDEX, hittest_seq, "hittest sequence testing", FALSE);
920 DestroyWindow(hChild);
923 static void test_hdm_sethotdivider(HWND hParent)
925 HWND hChild;
926 int retVal;
927 /* low word: x coordinate = 5
928 * high word: y coordinate = 5
931 flush_sequences(sequences, NUM_MSG_SEQUENCES);
932 hChild = create_custom_header_control(hParent, TRUE);
933 ok_sequence(sequences, PARENT_SEQ_INDEX, add_header_to_parent_seq,
934 "adder header control to parent", FALSE);
936 flush_sequences(sequences, NUM_MSG_SEQUENCES);
937 retVal = SendMessageA(hChild, HDM_SETHOTDIVIDER, TRUE, MAKELPARAM(5, 5));
938 expect(0, retVal);
940 retVal = SendMessageA(hChild, HDM_SETHOTDIVIDER, FALSE, 100);
941 expect(100, retVal);
942 retVal = SendMessageA(hChild, HDM_SETHOTDIVIDER, FALSE, 1);
943 expect(1, retVal);
944 if (winetest_interactive)
945 ok_sequence(sequences, HEADER_SEQ_INDEX, setHotDivider_seq_interactive,
946 "setHotDivider sequence testing", TRUE);
947 else
948 ok_sequence(sequences, HEADER_SEQ_INDEX, setHotDivider_seq_noninteractive,
949 "setHotDivider sequence testing", FALSE);
951 DestroyWindow(hChild);
954 static void test_hdm_imageMessages(HWND hParent)
956 HIMAGELIST hImageList = ImageList_Create (4, 4, 0, 1, 0);
957 HIMAGELIST hIml;
958 BOOL wasValid;
959 HWND hChild;
961 flush_sequences(sequences, NUM_MSG_SEQUENCES);
962 hChild = create_custom_header_control(hParent, TRUE);
963 ok_sequence(sequences, PARENT_SEQ_INDEX, add_header_to_parent_seq,
964 "adder header control to parent", FALSE);
966 flush_sequences(sequences, NUM_MSG_SEQUENCES);
968 hIml = (HIMAGELIST) SendMessageA(hChild, HDM_SETIMAGELIST, 0, (LPARAM) hImageList);
969 ok(hIml == NULL, "Expected NULL, got %p\n", hIml);
971 hIml = (HIMAGELIST) SendMessageA(hChild, HDM_GETIMAGELIST, 0, 0);
972 ok(hIml != NULL, "Expected non-NULL handle, got %p\n", hIml);
974 hIml = (HIMAGELIST) SendMessageA(hChild, HDM_CREATEDRAGIMAGE, 0, 0);
975 ok(hIml != NULL, "Expected non-NULL handle, got %p\n", hIml);
976 ImageList_Destroy(hIml);
978 ok_sequence(sequences, HEADER_SEQ_INDEX, imageMessages_seq, "imageMessages sequence testing", FALSE);
980 DestroyWindow(hChild);
982 wasValid = ImageList_Destroy(hImageList);
983 ok(wasValid, "Header must not free image list at destruction!\n");
986 static void test_hdm_filterMessages(HWND hParent)
988 HWND hChild;
989 int retVal, timeout;
991 flush_sequences(sequences, NUM_MSG_SEQUENCES);
992 hChild = create_custom_header_control(hParent, TRUE);
993 ok_sequence(sequences, PARENT_SEQ_INDEX, add_header_to_parent_seq,
994 "adder header control to parent", FALSE);
996 timeout = SendMessageA(hChild, HDM_SETFILTERCHANGETIMEOUT, 0, 0);
997 ok(timeout == 1000, "got %d\n", timeout);
999 timeout = SendMessageA(hChild, HDM_SETFILTERCHANGETIMEOUT, 0, 0);
1000 ok(timeout == 1000, "got %d\n", timeout);
1002 timeout = SendMessageA(hChild, HDM_SETFILTERCHANGETIMEOUT, 0, -100);
1003 ok(timeout == 1000, "got %d\n", timeout);
1005 timeout = SendMessageA(hChild, HDM_SETFILTERCHANGETIMEOUT, 1, 100);
1006 ok(timeout == -100, "got %d\n", timeout);
1007 retVal = SendMessageA(hChild, HDM_SETFILTERCHANGETIMEOUT, 1, timeout);
1008 ok(retVal == 100, "got %d\n", retVal);
1010 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1012 /* msdn incorrectly states that return value
1013 * is the index of the filter control being
1014 * modified. The sendMessage here should
1015 * return previous filter timeout value
1018 retVal = SendMessageA(hChild, HDM_SETFILTERCHANGETIMEOUT, 1, 100);
1019 expect(timeout, retVal);
1021 todo_wine
1023 retVal = SendMessageA(hChild, HDM_CLEARFILTER, 0, 1);
1024 if (retVal == 0)
1025 win_skip("HDM_CLEARFILTER needs 5.80\n");
1026 else
1027 expect(1, retVal);
1029 retVal = SendMessageA(hChild, HDM_EDITFILTER, 1, 0);
1030 if (retVal == 0)
1031 win_skip("HDM_EDITFILTER needs 5.80\n");
1032 else
1033 expect(1, retVal);
1035 if (winetest_interactive)
1036 ok_sequence(sequences, HEADER_SEQ_INDEX, filterMessages_seq_interactive,
1037 "filterMessages sequence testing", TRUE);
1038 else
1039 ok_sequence(sequences, HEADER_SEQ_INDEX, filterMessages_seq_noninteractive,
1040 "filterMessages sequence testing", FALSE);
1041 DestroyWindow(hChild);
1045 static void test_hdm_unicodeformatMessages(HWND hParent)
1047 HWND hChild;
1048 int retVal;
1050 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1051 hChild = create_custom_header_control(hParent, TRUE);
1052 ok_sequence(sequences, PARENT_SEQ_INDEX, add_header_to_parent_seq,
1053 "adder header control to parent", FALSE);
1055 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1056 retVal = SendMessageA(hChild, HDM_SETUNICODEFORMAT, TRUE, 0);
1057 expect(0, retVal);
1058 retVal = SendMessageA(hChild, HDM_GETUNICODEFORMAT, 0, 0);
1059 expect(1, retVal);
1061 ok_sequence(sequences, HEADER_SEQ_INDEX, unicodeformatMessages_seq,
1062 "unicodeformatMessages sequence testing", FALSE);
1063 DestroyWindow(hChild);
1066 static void test_hdm_bitmapmarginMessages(HWND hParent)
1068 HWND hChild;
1069 int retVal;
1071 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1072 hChild = create_custom_header_control(hParent, TRUE);
1073 ok_sequence(sequences, PARENT_SEQ_INDEX, add_header_to_parent_seq,
1074 "adder header control to parent", FALSE);
1076 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1077 retVal = SendMessageA(hChild, HDM_GETBITMAPMARGIN, 0, 0);
1078 if (retVal == 0)
1079 win_skip("HDM_GETBITMAPMARGIN needs 5.80\n");
1080 else
1081 expect(6, retVal);
1083 ok_sequence(sequences, HEADER_SEQ_INDEX, bitmapmarginMessages_seq,
1084 "bitmapmarginMessages sequence testing", FALSE);
1085 DestroyWindow(hChild);
1088 static void test_hdm_index_messages(HWND hParent)
1090 HWND hChild;
1091 int retVal, i, iSize;
1092 static const int lpiarray[2] = {1, 0};
1093 static const char *item_texts[] = {
1094 "Name", "Size", "Type", "Date Modified"
1096 RECT rect;
1097 HDITEMA hdItem;
1098 char buffA[32];
1099 int array[2];
1101 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1102 hChild = create_custom_header_control(hParent, FALSE);
1103 if (winetest_interactive)
1104 ok_sequence(sequences, PARENT_SEQ_INDEX, add_header_to_parent_seq_interactive,
1105 "adder header control to parent", TRUE);
1106 else
1107 ok_sequence(sequences, PARENT_SEQ_INDEX, add_header_to_parent_seq,
1108 "adder header control to parent", FALSE);
1109 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1110 for (i = 0; i < sizeof(item_texts)/sizeof(item_texts[0]); i++)
1112 hdItem.mask = HDI_TEXT | HDI_WIDTH | HDI_FORMAT;
1113 hdItem.pszText = (char*)item_texts[i];
1114 hdItem.fmt = HDF_LEFT;
1115 hdItem.cxy = 80;
1117 retVal = SendMessageA(hChild, HDM_INSERTITEMA, i, (LPARAM) &hdItem);
1118 ok(retVal == i, "Adding item %d failed with return value %d\n", i, retVal);
1120 ok_sequence(sequences, HEADER_SEQ_INDEX, insertItem_seq, "insertItem sequence testing", FALSE);
1122 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1124 retVal = SendMessageA(hChild, HDM_DELETEITEM, 3, (LPARAM) &hdItem);
1125 ok(retVal == TRUE, "Deleting item 3 should return TRUE, got %d\n", retVal);
1126 retVal = SendMessageA(hChild, HDM_GETITEMCOUNT, 0, 0);
1127 ok(retVal == 3, "Getting item count should return 3, got %d\n", retVal);
1129 retVal = SendMessageA(hChild, HDM_DELETEITEM, 3, (LPARAM) &hdItem);
1130 ok(retVal == FALSE, "Deleting already-deleted item should return FALSE, got %d\n", retVal);
1131 retVal = SendMessageA(hChild, HDM_GETITEMCOUNT, 0, 0);
1132 ok(retVal == 3, "Getting item count should return 3, got %d\n", retVal);
1134 retVal = SendMessageA(hChild, HDM_DELETEITEM, 2, (LPARAM) &hdItem);
1135 ok(retVal == TRUE, "Deleting item 2 should return TRUE, got %d\n", retVal);
1136 retVal = SendMessageA(hChild, HDM_GETITEMCOUNT, 0, 0);
1137 ok(retVal == 2, "Getting item count should return 2, got %d\n", retVal);
1139 ok_sequence(sequences, HEADER_SEQ_INDEX, deleteItem_getItemCount_seq,
1140 "deleteItem_getItemCount sequence testing", FALSE);
1142 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1144 hdItem.mask = HDI_WIDTH;
1145 retVal = SendMessageA(hChild, HDM_GETITEMA, 3, (LPARAM) &hdItem);
1146 ok(retVal == FALSE, "Getting already-deleted item should return FALSE, got %d\n", retVal);
1148 hdItem.mask = HDI_TEXT | HDI_WIDTH;
1149 hdItem.pszText = buffA;
1150 hdItem.cchTextMax = sizeof(buffA)/sizeof(buffA[0]);
1151 retVal = SendMessageA(hChild, HDM_GETITEMA, 0, (LPARAM) &hdItem);
1152 ok(retVal == TRUE, "Getting the 1st header item should return TRUE, got %d\n", retVal);
1154 ok_sequence(sequences, HEADER_SEQ_INDEX, getItem_seq, "getItem sequence testing", FALSE);
1156 /* check if the item is the right one */
1157 ok(!strcmp(hdItem.pszText, item_texts[0]), "got wrong item %s, expected %s\n",
1158 hdItem.pszText, item_texts[0]);
1159 expect(80, hdItem.cxy);
1161 iSize = SendMessageA(hChild, HDM_GETITEMCOUNT, 0, 0);
1163 /* item should be updated just after accepting new array */
1164 ShowWindow(hChild, SW_HIDE);
1165 retVal = SendMessageA(hChild, HDM_SETORDERARRAY, iSize, (LPARAM) lpiarray);
1166 expect(TRUE, retVal);
1167 rect.left = 0;
1168 retVal = SendMessageA(hChild, HDM_GETITEMRECT, 0, (LPARAM) &rect);
1169 expect(TRUE, retVal);
1170 ok(rect.left != 0, "Expected updated rectangle\n");
1172 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1174 retVal = SendMessageA(hChild, HDM_SETORDERARRAY, iSize, (LPARAM) lpiarray);
1175 ok(retVal == TRUE, "Setting header items order should return TRUE, got %d\n", retVal);
1177 retVal = SendMessageA(hChild, HDM_GETORDERARRAY, 2, (LPARAM) array);
1178 ok(retVal == TRUE, "Getting header items order should return TRUE, got %d\n", retVal);
1180 ok_sequence(sequences, HEADER_SEQ_INDEX, orderArray_seq, "set_get_orderArray sequence testing", FALSE);
1182 /* check if the array order is set correctly and the size of the array is correct. */
1183 expect(2, iSize);
1184 ok(lpiarray[0] == array[0], "got %d, expected %d\n", array[0], lpiarray[0]);
1185 ok(lpiarray[1] == array[1], "got %d, expected %d\n", array[1], lpiarray[1]);
1187 hdItem.mask = HDI_FORMAT;
1188 hdItem.fmt = HDF_CENTER | HDF_STRING;
1190 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1192 retVal = SendMessageA(hChild, HDM_SETITEMA, 0, (LPARAM) &hdItem);
1193 ok(retVal == TRUE, "Aligning 1st header item to center should return TRUE, got %d\n", retVal);
1194 hdItem.fmt = HDF_RIGHT | HDF_STRING;
1195 retVal = SendMessageA(hChild, HDM_SETITEMA, 1, (LPARAM) &hdItem);
1196 ok(retVal == TRUE, "Aligning 2nd header item to right should return TRUE, got %d\n", retVal);
1198 ok_sequence(sequences, HEADER_SEQ_INDEX, setItem_seq, "setItem sequence testing", FALSE);
1199 DestroyWindow(hChild);
1202 static void test_hdf_fixedwidth(HWND hParent)
1204 HWND hChild;
1205 HDITEMA hdItem;
1206 DWORD ret;
1207 RECT rect;
1208 HDHITTESTINFO ht;
1210 hChild = create_custom_header_control(hParent, FALSE);
1212 hdItem.mask = HDI_WIDTH | HDI_FORMAT;
1213 hdItem.fmt = HDF_FIXEDWIDTH;
1214 hdItem.cxy = 80;
1216 ret = SendMessageA(hChild, HDM_INSERTITEMA, 0, (LPARAM)&hdItem);
1217 expect(0, ret);
1219 /* try to change width */
1220 rect.right = rect.bottom = 0;
1221 SendMessageA(hChild, HDM_GETITEMRECT, 0, (LPARAM)&rect);
1222 ok(rect.right != 0, "Expected not zero width\n");
1223 ok(rect.bottom != 0, "Expected not zero height\n");
1225 SendMessageA(hChild, WM_LBUTTONDOWN, 0, MAKELPARAM(rect.right, rect.bottom / 2));
1226 SendMessageA(hChild, WM_MOUSEMOVE, 0, MAKELPARAM(rect.right + 20, rect.bottom / 2));
1227 SendMessageA(hChild, WM_LBUTTONUP, 0, MAKELPARAM(rect.right + 20, rect.bottom / 2));
1229 SendMessageA(hChild, HDM_GETITEMRECT, 0, (LPARAM)&rect);
1231 if (hdItem.cxy != rect.right)
1233 win_skip("HDF_FIXEDWIDTH format not supported\n");
1234 DestroyWindow(hChild);
1235 return;
1238 /* try to adjust with message */
1239 hdItem.mask = HDI_WIDTH;
1240 hdItem.cxy = 90;
1242 ret = SendMessageA(hChild, HDM_SETITEMA, 0, (LPARAM)&hdItem);
1243 expect(TRUE, ret);
1245 rect.right = 0;
1246 SendMessageA(hChild, HDM_GETITEMRECT, 0, (LPARAM)&rect);
1247 expect(90, rect.right);
1249 /* hittesting doesn't report ondivider flag for HDF_FIXEDWIDTH */
1250 ht.pt.x = rect.right - 1;
1251 ht.pt.y = rect.bottom / 2;
1252 SendMessageA(hChild, HDM_HITTEST, 0, (LPARAM)&ht);
1253 expect(HHT_ONHEADER, ht.flags);
1255 /* try to adjust with message */
1256 hdItem.mask = HDI_FORMAT;
1257 hdItem.fmt = 0;
1259 ret = SendMessageA(hChild, HDM_SETITEMA, 0, (LPARAM)&hdItem);
1260 expect(TRUE, ret);
1262 ht.pt.x = 90;
1263 ht.pt.y = rect.bottom / 2;
1264 SendMessageA(hChild, HDM_HITTEST, 0, (LPARAM)&ht);
1265 expect(HHT_ONDIVIDER, ht.flags);
1267 DestroyWindow(hChild);
1270 static void test_hds_nosizing(HWND hParent)
1272 HWND hChild;
1273 HDITEMA hdItem;
1274 DWORD ret;
1275 RECT rect;
1276 HDHITTESTINFO ht;
1278 hChild = create_custom_header_control(hParent, FALSE);
1280 memset(&hdItem, 0, sizeof(hdItem));
1281 hdItem.mask = HDI_WIDTH;
1282 hdItem.cxy = 80;
1284 ret = SendMessageA(hChild, HDM_INSERTITEMA, 0, (LPARAM)&hdItem);
1285 expect(0, ret);
1287 /* HDS_NOSIZING only blocks hittesting */
1288 ret = GetWindowLongA(hChild, GWL_STYLE);
1289 SetWindowLongA(hChild, GWL_STYLE, ret | HDS_NOSIZING);
1291 /* try to change width with mouse gestures */
1292 rect.right = rect.bottom = 0;
1293 SendMessageA(hChild, HDM_GETITEMRECT, 0, (LPARAM)&rect);
1294 ok(rect.right != 0, "Expected not zero width\n");
1295 ok(rect.bottom != 0, "Expected not zero height\n");
1297 SendMessageA(hChild, WM_LBUTTONDOWN, 0, MAKELPARAM(rect.right, rect.bottom / 2));
1298 SendMessageA(hChild, WM_MOUSEMOVE, 0, MAKELPARAM(rect.right + 20, rect.bottom / 2));
1299 SendMessageA(hChild, WM_LBUTTONUP, 0, MAKELPARAM(rect.right + 20, rect.bottom / 2));
1301 SendMessageA(hChild, HDM_GETITEMRECT, 0, (LPARAM)&rect);
1303 if (hdItem.cxy != rect.right)
1305 win_skip("HDS_NOSIZING style not supported\n");
1306 DestroyWindow(hChild);
1307 return;
1310 /* this style doesn't set HDF_FIXEDWIDTH for items */
1311 hdItem.mask = HDI_FORMAT;
1312 ret = SendMessageA(hChild, HDM_GETITEMA, 0, (LPARAM)&hdItem);
1313 expect(TRUE, ret);
1314 ok(!(hdItem.fmt & HDF_FIXEDWIDTH), "Unexpected HDF_FIXEDWIDTH\n");
1316 /* try to adjust with message */
1317 hdItem.mask = HDI_WIDTH;
1318 hdItem.cxy = 90;
1320 ret = SendMessageA(hChild, HDM_SETITEMA, 0, (LPARAM)&hdItem);
1321 expect(TRUE, ret);
1323 rect.right = 0;
1324 SendMessageA(hChild, HDM_GETITEMRECT, 0, (LPARAM)&rect);
1325 expect(90, rect.right);
1327 /* hittesting doesn't report ondivider flags for HDS_NOSIZING */
1328 ht.pt.x = rect.right - 1;
1329 ht.pt.y = rect.bottom / 2;
1330 SendMessageA(hChild, HDM_HITTEST, 0, (LPARAM)&ht);
1331 expect(HHT_ONHEADER, ht.flags);
1333 /* try to adjust with message */
1334 ret = GetWindowLongA(hChild, GWL_STYLE);
1335 SetWindowLongA(hChild, GWL_STYLE, ret & ~HDS_NOSIZING);
1337 ht.pt.x = 90;
1338 ht.pt.y = rect.bottom / 2;
1339 SendMessageA(hChild, HDM_HITTEST, 0, (LPARAM)&ht);
1340 expect(HHT_ONDIVIDER, ht.flags);
1342 DestroyWindow(hChild);
1345 #define TEST_NMCUSTOMDRAW(draw_stage, item_spec, lparam, _left, _top, _right, _bottom) \
1346 ok(nm->dwDrawStage == draw_stage, "Invalid dwDrawStage %d vs %d\n", draw_stage, nm->dwDrawStage); \
1347 if (item_spec != -1) \
1348 ok(nm->dwItemSpec == item_spec, "Invalid dwItemSpec %d vs %ld\n", item_spec, nm->dwItemSpec); \
1349 ok(nm->lItemlParam == lparam, "Invalid lItemlParam %d vs %ld\n", lparam, nm->lItemlParam); \
1350 ok((nm->rc.top == _top && nm->rc.bottom == _bottom && nm->rc.left == _left && nm->rc.right == _right) || \
1351 broken(draw_stage != CDDS_ITEMPREPAINT), /* comctl32 < 5.80 */ \
1352 "Invalid rect (%d,%d)-(%d,%d) vs %s\n", _left, _top, _right, _bottom, \
1353 wine_dbgstr_rect(&nm->rc));
1355 static LRESULT customdraw_1(int n, NMCUSTOMDRAW *nm)
1357 if (nm == NULL) { /* test ended */
1358 ok(n==1, "NM_CUSTOMDRAW messages: %d, expected: 1\n", n);
1359 return 0;
1362 switch (n)
1364 case 0:
1365 /* don't test dwItemSpec - it's 0 no comctl5 but 1308756 on comctl6 */
1366 TEST_NMCUSTOMDRAW(CDDS_PREPAINT, -1, 0, 0, 0, 670, g_customheight);
1367 return 0;
1370 ok(FALSE, "Too many custom draw messages (n=%d, nm->dwDrawStage=%d)\n", n, nm->dwDrawStage);
1371 return -1;
1374 static LRESULT customdraw_2(int n, NMCUSTOMDRAW *nm)
1376 if (nm == NULL) { /* test ended */
1377 ok(n==4, "NM_CUSTOMDRAW messages: %d, expected: 4\n", n);
1378 return 0;
1381 switch (n)
1383 case 0:
1384 TEST_NMCUSTOMDRAW(CDDS_PREPAINT, -1, 0, 0, 0, 670, g_customheight);
1385 return CDRF_NOTIFYITEMDRAW;
1386 case 1:
1387 TEST_NMCUSTOMDRAW(CDDS_ITEMPREPAINT, 0, 0, 0, 0, 50, g_customheight);
1388 return 0;
1389 case 2:
1390 TEST_NMCUSTOMDRAW(CDDS_ITEMPREPAINT, 1, 5, 50, 0, 150, g_customheight);
1391 return 0;
1392 case 3:
1393 TEST_NMCUSTOMDRAW(CDDS_ITEMPREPAINT, 2, 10, 150, 0, 300, g_customheight);
1394 return 0;
1397 ok(FALSE, "Too many custom draw messages (n=%d, nm->dwDrawStage=%d)\n", n, nm->dwDrawStage);
1398 return 0;
1401 static LRESULT customdraw_3(int n, NMCUSTOMDRAW *nm)
1403 if (nm == NULL) { /* test ended */
1404 ok(n==5, "NM_CUSTOMDRAW messages: %d, expected: 5\n", n);
1405 return 0;
1408 switch (n)
1410 case 0:
1411 TEST_NMCUSTOMDRAW(CDDS_PREPAINT, -1, 0, 0, 0, 670, g_customheight);
1412 return CDRF_NOTIFYITEMDRAW|CDRF_NOTIFYPOSTERASE|CDRF_NOTIFYPOSTPAINT|CDRF_SKIPDEFAULT;
1413 case 1:
1414 TEST_NMCUSTOMDRAW(CDDS_ITEMPREPAINT, 0, 0, 0, 0, 50, g_customheight);
1415 return 0;
1416 case 2:
1417 TEST_NMCUSTOMDRAW(CDDS_ITEMPREPAINT, 1, 5, 50, 0, 150, g_customheight);
1418 return 0;
1419 case 3:
1420 TEST_NMCUSTOMDRAW(CDDS_ITEMPREPAINT, 2, 10, 150, 0, 300, g_customheight);
1421 return 0;
1422 case 4:
1423 TEST_NMCUSTOMDRAW(CDDS_POSTPAINT, -1, 0, 0, 0, 670, g_customheight);
1424 return 0;
1427 ok(FALSE, "Too many custom draw messages (n=%d, nm->dwDrawStage=%d)\n", n, nm->dwDrawStage);
1428 return 0;
1432 static LRESULT customdraw_4(int n, NMCUSTOMDRAW *nm)
1434 if (nm == NULL) { /* test ended */
1435 ok(n==4, "NM_CUSTOMDRAW messages: %d, expected: 4\n", n);
1436 return 0;
1439 switch (n)
1441 case 0:
1442 TEST_NMCUSTOMDRAW(CDDS_PREPAINT, -1, 0, 0, 0, 670, g_customheight);
1443 return CDRF_NOTIFYITEMDRAW|CDRF_NOTIFYPOSTPAINT;
1444 case 1:
1445 TEST_NMCUSTOMDRAW(CDDS_ITEMPREPAINT, 0, 0, 0, 0, 50, g_customheight);
1446 return 0;
1447 case 2:
1448 TEST_NMCUSTOMDRAW(CDDS_ITEMPREPAINT, 2, 10, 150, 0, 300, g_customheight);
1449 return 0;
1450 case 3:
1451 TEST_NMCUSTOMDRAW(CDDS_POSTPAINT, -1, 0, 0, 0, 670, g_customheight);
1452 return 0;
1455 ok(FALSE, "Too many custom draw messages (n=%d, nm->dwDrawStage=%d)\n", n, nm->dwDrawStage);
1456 return 0;
1459 static void run_customdraw_scenario(CUSTOMDRAWPROC proc)
1461 g_CustomDrawProc = proc;
1462 g_CustomDrawCount = 0;
1463 InvalidateRect(hWndHeader, NULL, TRUE);
1464 UpdateWindow(hWndHeader);
1465 proc(g_CustomDrawCount, NULL);
1466 g_CustomDrawProc = NULL;
1469 static void test_customdraw(void)
1471 int i;
1472 HDITEMA item;
1473 RECT rect;
1474 CHAR name[] = "Test";
1475 hWndHeader = create_header_control();
1476 GetClientRect(hWndHeader, &rect);
1477 ok(rect.right - rect.left == 670 && rect.bottom - rect.top == g_customheight,
1478 "Tests will fail as header size is %dx%d instead of 670x%d\n",
1479 rect.right - rect.left, rect.bottom - rect.top, g_customheight);
1481 for (i = 0; i < 3; i++)
1483 ZeroMemory(&item, sizeof(item));
1484 item.mask = HDI_TEXT|HDI_WIDTH;
1485 item.cxy = 50*(i+1);
1486 item.pszText = name;
1487 item.lParam = i*5;
1488 SendMessageA(hWndHeader, HDM_INSERTITEMA, i, (LPARAM)&item);
1491 run_customdraw_scenario(customdraw_1);
1492 run_customdraw_scenario(customdraw_2);
1493 run_customdraw_scenario(customdraw_3);
1495 ZeroMemory(&item, sizeof(item));
1496 item.mask = HDI_FORMAT;
1497 item.fmt = HDF_OWNERDRAW;
1498 SendMessageA(hWndHeader, HDM_SETITEMA, 1, (LPARAM)&item);
1499 g_DrawItem.CtlID = 0;
1500 g_DrawItem.CtlType = ODT_HEADER;
1501 g_DrawItem.hwndItem = hWndHeader;
1502 g_DrawItem.itemID = 1;
1503 g_DrawItem.itemState = 0;
1504 SendMessageA(hWndHeader, HDM_GETITEMRECT, 1, (LPARAM)&g_DrawItem.rcItem);
1505 run_customdraw_scenario(customdraw_4);
1506 ok(g_DrawItemReceived, "WM_DRAWITEM not received\n");
1507 DestroyWindow(hWndHeader);
1508 hWndHeader = NULL;
1509 g_DrawItem.CtlType = 0;
1510 g_DrawItemReceived = FALSE;
1513 static void check_order(const int expected_id[], const int expected_order[],
1514 int count, const char *type)
1516 int i;
1517 HDITEMA hdi;
1519 ok(getItemCount(hWndHeader) == count, "Invalid item count in order tests\n");
1520 for (i = 0; i < count; i++)
1522 hdi.mask = HDI_LPARAM|HDI_ORDER;
1523 SendMessageA(hWndHeader, HDM_GETITEMA, i, (LPARAM)&hdi);
1524 ok(hdi.lParam == expected_id[i],
1525 "Invalid item ids after '%s'- item %d has lParam %d\n", type, i, (int)hdi.lParam);
1526 ok(hdi.iOrder == expected_order[i],
1527 "Invalid item order after '%s'- item %d has iOrder %d\n", type, i, hdi.iOrder);
1531 static void test_header_order (void)
1533 const int rand1[] = {0, 1, 1, 0, 4};
1534 const int rand2[] = {4, 5, 6, 7, 4};
1535 const int rand3[] = {5, 5, 1, 6, 1};
1536 const int rand4[] = {1, 5, 2, 7, 6, 1, 4, 2, 3, 2};
1537 const int rand5[] = {7, 8, 5, 6, 7, 2, 1, 9, 10, 10};
1538 const int rand6[] = {2, 8, 3, 4, 0};
1540 const int ids1[] = {3, 0, 2, 1, 4};
1541 const int ord1[] = {0, 1, 2, 3, 4};
1542 const int ids2[] = {3, 9, 7, 0, 2, 1, 4, 8, 6, 5};
1543 const int ord2[] = {0, 4, 7, 1, 2, 3, 9, 8, 6, 5};
1544 const int ord3[] = {0, 3, 9, 2, 1, 8, 7, 6, 5, 4};
1545 const int ids4[] = {9, 0, 1, 8, 6};
1546 const int ord4[] = {1, 0, 4, 3, 2};
1548 char buffer[20];
1549 HDITEMA hdi;
1550 int i;
1552 hWndHeader = create_header_control();
1554 ZeroMemory(&hdi, sizeof(HDITEMA));
1555 hdi.mask = HDI_TEXT | HDI_LPARAM;
1556 hdi.pszText = buffer;
1557 strcpy(buffer, "test");
1559 for (i = 0; i < 5; i++)
1561 hdi.lParam = i;
1562 SendMessageA(hWndHeader, HDM_INSERTITEMA, rand1[i], (LPARAM)&hdi);
1564 check_order(ids1, ord1, 5, "insert without iOrder");
1566 hdi.mask |= HDI_ORDER;
1567 for (i = 0; i < 5; i++)
1569 hdi.lParam = i + 5;
1570 hdi.iOrder = rand2[i];
1571 SendMessageA(hWndHeader, HDM_INSERTITEMA, rand3[i], (LPARAM)&hdi);
1573 check_order(ids2, ord2, 10, "insert with order");
1575 hdi.mask = HDI_ORDER;
1576 for (i=0; i<10; i++)
1578 hdi.iOrder = rand5[i];
1579 SendMessageA(hWndHeader, HDM_SETITEMA, rand4[i], (LPARAM)&hdi);
1581 check_order(ids2, ord3, 10, "setitems changing order");
1583 for (i=0; i<5; i++)
1584 SendMessageA(hWndHeader, HDM_DELETEITEM, rand6[i], 0);
1585 check_order(ids4, ord4, 5, "deleteitem");
1587 DestroyWindow(hWndHeader);
1590 static LRESULT CALLBACK HeaderTestWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
1592 DRAWITEMSTRUCT *di;
1593 switch(msg) {
1595 case WM_NOTIFY:
1597 NMHEADERA *hdr = (NMHEADERA*)lParam;
1598 EXPECTEDNOTIFY *expected;
1599 int i;
1601 if (hdr->hdr.code == NM_CUSTOMDRAW)
1602 if (g_CustomDrawProc)
1603 return g_CustomDrawProc(g_CustomDrawCount++, (NMCUSTOMDRAW*)hdr);
1605 for (i=0; i<nUnexpectedNotify; i++)
1606 ok(hdr->hdr.code != unexpectedNotify[i], "Received invalid notify %d\n", hdr->hdr.code);
1608 if (nReceivedNotify >= nExpectedNotify || hdr->hdr.hwndFrom != hWndHeader )
1609 break;
1611 expected = &expectedNotify[nReceivedNotify];
1612 if (hdr->hdr.code != expected->iCode)
1613 break;
1615 nReceivedNotify++;
1616 compare_items(hdr->hdr.code, &expected->hdItem, hdr->pitem, expected->fUnicode);
1617 break;
1620 case WM_DRAWITEM:
1621 di = (DRAWITEMSTRUCT *)lParam;
1622 ok(g_DrawItem.CtlType != 0, "Unexpected WM_DRAWITEM\n");
1623 if (g_DrawItem.CtlType == 0) return 0;
1624 g_DrawItemReceived = TRUE;
1625 compare(di->CtlType, g_DrawItem.CtlType, "%d");
1626 compare(di->CtlID, g_DrawItem.CtlID, "%d");
1627 compare(di->hwndItem, g_DrawItem.hwndItem, "%p");
1628 compare(di->itemID, g_DrawItem.itemID, "%d");
1629 compare(di->itemState, g_DrawItem.itemState, "%d");
1630 compare(di->rcItem.left, g_DrawItem.rcItem.left, "%d");
1631 compare(di->rcItem.top, g_DrawItem.rcItem.top, "%d");
1632 compare(di->rcItem.right, g_DrawItem.rcItem.right, "%d");
1633 compare(di->rcItem.bottom, g_DrawItem.rcItem.bottom, "%d");
1634 break;
1636 case WM_DESTROY:
1637 PostQuitMessage(0);
1638 break;
1640 default:
1641 return DefWindowProcA(hWnd, msg, wParam, lParam);
1644 return 0L;
1647 static BOOL init(void)
1649 HMODULE hComctl32;
1650 BOOL (WINAPI *pInitCommonControlsEx)(const INITCOMMONCONTROLSEX*);
1651 WNDCLASSA wc;
1652 INITCOMMONCONTROLSEX iccex;
1653 TEXTMETRICA tm;
1654 HFONT hOldFont;
1655 HDC hdc;
1657 hComctl32 = GetModuleHandleA("comctl32.dll");
1658 pInitCommonControlsEx = (void*)GetProcAddress(hComctl32, "InitCommonControlsEx");
1659 if (!pInitCommonControlsEx)
1661 win_skip("InitCommonControlsEx() is missing. Skipping the tests\n");
1662 return FALSE;
1665 iccex.dwSize = sizeof(iccex);
1666 iccex.dwICC = ICC_USEREX_CLASSES;
1667 pInitCommonControlsEx(&iccex);
1669 wc.style = CS_HREDRAW | CS_VREDRAW;
1670 wc.cbClsExtra = 0;
1671 wc.cbWndExtra = 0;
1672 wc.hInstance = GetModuleHandleA(NULL);
1673 wc.hIcon = NULL;
1674 wc.hCursor = LoadCursorA(NULL, (LPCSTR)IDC_ARROW);
1675 wc.hbrBackground = GetSysColorBrush(COLOR_WINDOW);
1676 wc.lpszMenuName = NULL;
1677 wc.lpszClassName = "HeaderTestClass";
1678 wc.lpfnWndProc = HeaderTestWndProc;
1679 RegisterClassA(&wc);
1681 /* The height of the header control depends on the height of the system font.
1682 The height of the system font is dpi dependent */
1683 hdc = GetDC(0);
1684 hOldFont = SelectObject(hdc, GetStockObject(SYSTEM_FONT));
1685 GetTextMetricsA(hdc, &tm);
1686 /* 2 dot extra space are needed for the border */
1687 g_customheight = tm.tmHeight + 2;
1688 trace("customdraw height: %d (dpi: %d)\n", g_customheight, GetDeviceCaps(hdc, LOGPIXELSY));
1689 SelectObject(hdc, hOldFont);
1690 ReleaseDC(0, hdc);
1692 hHeaderParentWnd = CreateWindowExA(0, "HeaderTestClass", "Header test", WS_OVERLAPPEDWINDOW,
1693 CW_USEDEFAULT, CW_USEDEFAULT, 672+2*GetSystemMetrics(SM_CXSIZEFRAME),
1694 226+GetSystemMetrics(SM_CYCAPTION)+2*GetSystemMetrics(SM_CYSIZEFRAME),
1695 NULL, NULL, GetModuleHandleA(NULL), 0);
1696 ok(hHeaderParentWnd != NULL, "failed to create parent wnd\n");
1698 ShowWindow(hHeaderParentWnd, SW_SHOW);
1699 return hHeaderParentWnd != NULL;
1702 /* maximum 8 items allowed */
1703 static void check_orderarray(HWND hwnd, DWORD start, DWORD set, DWORD expected,
1704 BOOL todo, int line)
1706 int count, i;
1707 INT order[8];
1708 DWORD ret, array = 0;
1710 count = SendMessageA(hwnd, HDM_GETITEMCOUNT, 0, 0);
1712 /* initial order */
1713 for(i = 1; i<=count; i++)
1714 order[i-1] = start>>(4*(count-i)) & 0xf;
1716 ret = SendMessageA(hwnd, HDM_SETORDERARRAY, count, (LPARAM)order);
1717 ok_(__FILE__, line)(ret, "Expected HDM_SETORDERARRAY to succeed, got %d\n", ret);
1719 /* new order */
1720 for(i = 1; i<=count; i++)
1721 order[i-1] = set>>(4*(count-i)) & 0xf;
1722 ret = SendMessageA(hwnd, HDM_SETORDERARRAY, count, (LPARAM)order);
1723 ok_(__FILE__, line)(ret, "Expected HDM_SETORDERARRAY to succeed, got %d\n", ret);
1725 /* check actual order */
1726 ret = SendMessageA(hwnd, HDM_GETORDERARRAY, count, (LPARAM)order);
1727 ok_(__FILE__, line)(ret, "Expected HDM_GETORDERARRAY to succeed, got %d\n", ret);
1728 for(i = 1; i<=count; i++)
1729 array |= order[i-1]<<(4*(count-i));
1731 todo_wine_if(todo)
1732 ok_(__FILE__, line)(array == expected, "Expected %x, got %x\n", expected, array);
1735 static void test_hdm_orderarray(void)
1737 HWND hwnd;
1738 INT order[5];
1739 DWORD ret;
1741 hwnd = create_header_control();
1743 /* three items */
1744 addItem(hwnd, 0, NULL);
1745 addItem(hwnd, 1, NULL);
1746 addItem(hwnd, 2, NULL);
1748 ret = SendMessageA(hwnd, HDM_GETORDERARRAY, 3, (LPARAM)order);
1749 if (!ret)
1751 win_skip("HDM_GETORDERARRAY not implemented.\n");
1752 DestroyWindow(hwnd);
1753 return;
1756 expect(0, order[0]);
1757 expect(1, order[1]);
1758 expect(2, order[2]);
1760 if (0)
1762 /* null pointer, crashes native */
1763 ret = SendMessageA(hwnd, HDM_SETORDERARRAY, 3, 0);
1764 expect(FALSE, ret);
1766 /* count out of limits */
1767 ret = SendMessageA(hwnd, HDM_SETORDERARRAY, 5, (LPARAM)order);
1768 expect(FALSE, ret);
1769 /* count out of limits */
1770 ret = SendMessageA(hwnd, HDM_SETORDERARRAY, 2, (LPARAM)order);
1771 expect(FALSE, ret);
1773 /* try with out of range item index */
1774 /* (0,1,2)->(1,0,3) => (1,0,2) */
1775 check_orderarray(hwnd, 0x120, 0x103, 0x102, FALSE, __LINE__);
1776 /* (1,0,2)->(3,0,1) => (0,2,1) */
1777 check_orderarray(hwnd, 0x102, 0x301, 0x021, TRUE, __LINE__);
1778 /* (0,2,1)->(2,3,1) => (2,0,1) */
1779 check_orderarray(hwnd, 0x021, 0x231, 0x201, FALSE, __LINE__);
1781 /* (0,1,2)->(0,2,2) => (0,1,2) */
1782 check_orderarray(hwnd, 0x012, 0x022, 0x012, FALSE, __LINE__);
1784 addItem(hwnd, 3, NULL);
1786 /* (0,1,2,3)->(0,1,2,2) => (0,1,3,2) */
1787 check_orderarray(hwnd, 0x0123, 0x0122, 0x0132, FALSE, __LINE__);
1788 /* (0,1,2,3)->(0,1,3,3) => (0,1,2,3) */
1789 check_orderarray(hwnd, 0x0123, 0x0133, 0x0123, FALSE, __LINE__);
1790 /* (0,1,2,3)->(0,4,2,3) => (0,1,2,3) */
1791 check_orderarray(hwnd, 0x0123, 0x0423, 0x0123, FALSE, __LINE__);
1792 /* (0,1,2,3)->(4,0,1,2) => (0,1,3,2) */
1793 check_orderarray(hwnd, 0x0123, 0x4012, 0x0132, TRUE, __LINE__);
1794 /* (0,1,3,2)->(4,0,1,4) => (0,3,1,2) */
1795 check_orderarray(hwnd, 0x0132, 0x4014, 0x0312, TRUE, __LINE__);
1796 /* (0,1,2,3)->(4,1,0,2) => (1,0,3,2) */
1797 check_orderarray(hwnd, 0x0123, 0x4102, 0x1032, TRUE, __LINE__);
1798 /* (0,1,2,3)->(0,1,4,2) => (0,1,2,3) */
1799 check_orderarray(hwnd, 0x0123, 0x0142, 0x0132, FALSE, __LINE__);
1800 /* (0,1,2,3)->(4,4,4,4) => (0,1,2,3) */
1801 check_orderarray(hwnd, 0x0123, 0x4444, 0x0123, FALSE, __LINE__);
1802 /* (0,1,2,3)->(4,4,1,2) => (0,1,3,2) */
1803 check_orderarray(hwnd, 0x0123, 0x4412, 0x0132, TRUE, __LINE__);
1804 /* (0,1,2,3)->(4,4,4,1) => (0,2,3,1) */
1805 check_orderarray(hwnd, 0x0123, 0x4441, 0x0231, TRUE, __LINE__);
1806 /* (0,1,2,3)->(1,4,4,4) => (1,0,2,3) */
1807 check_orderarray(hwnd, 0x0123, 0x1444, 0x1023, FALSE, __LINE__);
1808 /* (0,1,2,3)->(4,2,4,1) => (0,2,3,1) */
1809 check_orderarray(hwnd, 0x0123, 0x4241, 0x0231, FALSE, __LINE__);
1810 /* (0,1,2,3)->(4,2,0,1) => (2,0,3,1) */
1811 check_orderarray(hwnd, 0x0123, 0x4201, 0x2031, TRUE, __LINE__);
1812 /* (3,2,1,0)->(4,2,0,1) => (3,2,0,1) */
1813 check_orderarray(hwnd, 0x3210, 0x4201, 0x3201, FALSE, __LINE__);
1815 DestroyWindow(hwnd);
1818 START_TEST(header)
1820 HWND parent_hwnd;
1821 ULONG_PTR ctx_cookie;
1822 HANDLE hCtx;
1824 if (!init())
1825 return;
1827 test_header_control();
1828 test_header_order();
1829 test_hdm_orderarray();
1830 test_customdraw();
1832 DestroyWindow(hHeaderParentWnd);
1834 init_msg_sequences(sequences, NUM_MSG_SEQUENCES);
1835 parent_hwnd = create_custom_parent_window();
1836 ok_sequence(sequences, PARENT_SEQ_INDEX, create_parent_wnd_seq, "create parent windows", FALSE);
1838 test_hdm_index_messages(parent_hwnd);
1839 test_hdm_getitemrect(parent_hwnd);
1840 test_hdm_hittest(parent_hwnd);
1841 test_hdm_layout(parent_hwnd);
1842 test_hdm_ordertoindex(parent_hwnd);
1843 test_hdm_sethotdivider(parent_hwnd);
1844 test_hdm_imageMessages(parent_hwnd);
1845 test_hdm_filterMessages(parent_hwnd);
1846 test_hdm_unicodeformatMessages(parent_hwnd);
1847 test_hdm_bitmapmarginMessages(parent_hwnd);
1849 if (!load_v6_module(&ctx_cookie, &hCtx))
1851 DestroyWindow(parent_hwnd);
1852 return;
1855 /* comctl32 version 6 tests start here */
1856 test_hdf_fixedwidth(parent_hwnd);
1857 test_hds_nosizing(parent_hwnd);
1859 unload_v6_module(ctx_cookie, hCtx);
1861 DestroyWindow(parent_hwnd);