wined3d: Pass a wined3d_device_context to wined3d_cs_emit_blt_sub_resource().
[wine/zf.git] / dlls / comctl32 / tests / header.c
blob3428936cd7564fded74d6518992ebd56011a8368
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 static HIMAGELIST (WINAPI *pImageList_Create)(int, int, UINT, int, int);
30 static BOOL (WINAPI *pImageList_Destroy)(HIMAGELIST);
32 typedef struct tagEXPECTEDNOTIFY
34 INT iCode;
35 BOOL fUnicode;
36 HDITEMA hdItem;
37 } EXPECTEDNOTIFY;
39 typedef LRESULT (*CUSTOMDRAWPROC)(int n, NMCUSTOMDRAW *nm);
41 static CUSTOMDRAWPROC g_CustomDrawProc;
42 static int g_CustomDrawCount;
43 static DRAWITEMSTRUCT g_DrawItem;
44 static BOOL g_DrawItemReceived;
45 static DWORD g_customheight;
47 static EXPECTEDNOTIFY expectedNotify[10];
48 static INT nExpectedNotify = 0;
49 static INT nReceivedNotify = 0;
50 static INT unexpectedNotify[10];
51 static INT nUnexpectedNotify = 0;
53 static HWND hHeaderParentWnd;
54 static HWND hWndHeader;
55 #define MAX_CHARS 100
57 #define compare(val, exp, fmt) ok((val) == (exp), #val " value: " fmt ", expected: " fmt "\n", (val), (exp))
59 #define expect(expected, got) ok(expected == got, "expected %d, got %d\n", expected,got)
61 #define NUM_MSG_SEQUENCES 2
62 #define PARENT_SEQ_INDEX 0
63 #define HEADER_SEQ_INDEX 1
65 static struct msg_sequence *sequences[NUM_MSG_SEQUENCES];
67 static const struct message create_parent_wnd_seq[] = {
68 { WM_GETMINMAXINFO, sent },
69 { WM_NCCREATE, sent },
70 { WM_NCCALCSIZE, sent|wparam, 0 },
71 { WM_CREATE, sent },
72 { 0 }
75 static const struct message add_header_to_parent_seq_interactive[] = {
76 { WM_NOTIFYFORMAT, sent|lparam, 0, NF_QUERY },
77 { WM_QUERYUISTATE, sent },
78 { WM_PARENTNOTIFY, sent|wparam, 1 },
79 { WM_SHOWWINDOW, sent|wparam, 1 },
80 { WM_WINDOWPOSCHANGING, sent|wparam, 0 },
81 { WM_WINDOWPOSCHANGING, sent|wparam, 0 },
82 { WM_ACTIVATEAPP, sent|wparam, 1 },
83 { WM_NCACTIVATE, sent|wparam, 1 },
84 { WM_ACTIVATE, sent|wparam, 1 },
85 { WM_IME_SETCONTEXT, sent|defwinproc|wparam, 1 },
86 { WM_IME_NOTIFY, sent|defwinproc|wparam, 2 },
87 { WM_SETFOCUS, sent|defwinproc|wparam, 0 },
88 { WM_WINDOWPOSCHANGED, sent|wparam, 0 },
89 { WM_SIZE, sent|wparam, 0 },
90 { WM_MOVE, sent|wparam, 0 },
91 { 0 }
94 static const struct message add_header_to_parent_seq[] = {
95 { WM_NOTIFYFORMAT, sent|lparam, 0, NF_QUERY },
96 { WM_QUERYUISTATE, sent|optional },
97 { WM_PARENTNOTIFY, sent },
98 { 0 }
101 static const struct message insertItem_seq[] = {
102 { HDM_INSERTITEMA, sent|wparam, 0 },
103 { HDM_INSERTITEMA, sent|wparam, 1 },
104 { HDM_INSERTITEMA, sent|wparam, 2 },
105 { HDM_INSERTITEMA, sent|wparam, 3 },
106 { 0 }
109 static const struct message getItem_seq[] = {
110 { HDM_GETITEMA, sent|wparam, 3 },
111 { HDM_GETITEMA, sent|wparam, 0 },
112 { 0 }
116 static const struct message deleteItem_getItemCount_seq[] = {
117 { HDM_DELETEITEM, sent|wparam, 3 },
118 { HDM_GETITEMCOUNT, sent },
119 { HDM_DELETEITEM, sent|wparam, 3 },
120 { HDM_GETITEMCOUNT, sent },
121 { HDM_DELETEITEM, sent|wparam, 2 },
122 { HDM_GETITEMCOUNT, sent },
123 { 0 }
126 static const struct message orderArray_seq[] = {
127 { HDM_SETORDERARRAY, sent|wparam, 2 },
128 { HDM_GETORDERARRAY, sent|wparam, 2 },
129 { 0 }
132 static const struct message setItem_seq[] = {
133 { HDM_SETITEMA, sent|wparam, 0 },
134 { HDM_SETITEMA, sent|wparam, 1 },
135 { 0 }
138 static const struct message getItemRect_seq[] = {
139 { HDM_GETITEMRECT, sent|wparam, 1 },
140 { HDM_GETITEMRECT, sent|wparam, 0 },
141 { HDM_GETITEMRECT, sent|wparam, 10 },
142 { 0 }
145 static const struct message layout_seq[] = {
146 { HDM_LAYOUT, sent },
147 { 0 }
150 static const struct message orderToIndex_seq[] = {
151 { HDM_ORDERTOINDEX, sent|wparam, 1 },
152 { 0 }
155 static const struct message hittest_seq[] = {
156 { HDM_HITTEST, sent },
157 { HDM_HITTEST, sent },
158 { HDM_HITTEST, sent },
159 { 0 }
162 static const struct message setHotDivider_seq_interactive[] = {
163 { HDM_SETHOTDIVIDER, sent|wparam, TRUE },
164 { WM_PAINT, sent|defwinproc},
165 { WM_NCPAINT, sent|defwinproc},
166 { WM_ERASEBKGND, sent|defwinproc},
167 { HDM_SETHOTDIVIDER, sent|wparam|lparam, FALSE, 100 },
168 { WM_PAINT, sent|defwinproc},
169 { HDM_SETHOTDIVIDER, sent|wparam|lparam, FALSE, 1},
170 { WM_PAINT, sent|defwinproc},
171 { 0 }
174 static const struct message setHotDivider_seq_noninteractive[] = {
175 { HDM_SETHOTDIVIDER, sent|wparam, TRUE },
176 { HDM_SETHOTDIVIDER, sent|wparam|lparam, FALSE, 100 },
177 { HDM_SETHOTDIVIDER, sent|wparam|lparam, FALSE, 1},
178 { 0 }
181 static const struct message imageMessages_seq[] = {
182 { HDM_SETIMAGELIST, sent },
183 { HDM_GETIMAGELIST, sent },
184 { HDM_CREATEDRAGIMAGE, sent },
185 { 0 }
188 static const struct message filterMessages_seq_interactive[] = {
189 { HDM_SETFILTERCHANGETIMEOUT, sent|wparam|lparam, 1, 100 },
190 { HDM_CLEARFILTER, sent|wparam|lparam, 0, 1 },
191 { HDM_EDITFILTER, sent|wparam|lparam, 1, 0 },
192 { WM_PARENTNOTIFY, sent|wparam|defwinproc, WM_CREATE },
193 { WM_CTLCOLOREDIT, sent|defwinproc },
194 { WM_COMMAND, sent|defwinproc },
195 { 0 }
198 static const struct message filterMessages_seq_noninteractive[] = {
199 { HDM_SETFILTERCHANGETIMEOUT, sent|wparam|lparam, 1, 100 },
200 { HDM_CLEARFILTER, sent|wparam|lparam, 0, 1 },
201 { HDM_EDITFILTER, sent|wparam|lparam, 1, 0 },
202 { WM_PARENTNOTIFY, sent|wparam|defwinproc|optional, WM_CREATE },
203 { WM_COMMAND, sent|defwinproc|optional },
204 { 0 }
207 static const struct message unicodeformatMessages_seq[] = {
208 { HDM_SETUNICODEFORMAT, sent|wparam, TRUE },
209 { HDM_GETUNICODEFORMAT, sent },
210 { 0 }
213 static const struct message bitmapmarginMessages_seq[] = {
214 { HDM_GETBITMAPMARGIN, sent },
215 { 0 }
219 static void expect_notify(INT iCode, BOOL fUnicode, HDITEMA *lpItem)
221 ok(nExpectedNotify < 10, "notification count %d\n", nExpectedNotify);
222 if (nExpectedNotify < 10)
224 expectedNotify[nExpectedNotify].iCode = iCode;
225 expectedNotify[nExpectedNotify].fUnicode = fUnicode;
226 expectedNotify[nExpectedNotify].hdItem = *lpItem;
227 nExpectedNotify++;
231 static void dont_expect_notify(INT iCode)
233 ok(nExpectedNotify < 10, "notification count %d\n", nExpectedNotify);
234 if (nExpectedNotify < 10)
235 unexpectedNotify[nUnexpectedNotify++] = iCode;
238 static BOOL notifies_received(void)
240 BOOL fRet = (nExpectedNotify == nReceivedNotify);
241 nExpectedNotify = nReceivedNotify = 0;
242 nUnexpectedNotify = 0;
243 return fRet;
246 static LONG addItem(HWND hdex, int idx, LPSTR text)
248 HDITEMA hdItem;
249 hdItem.mask = HDI_TEXT | HDI_WIDTH;
250 hdItem.cxy = 100;
251 hdItem.pszText = text;
252 hdItem.cchTextMax = 0;
253 return SendMessageA(hdex, HDM_INSERTITEMA, idx, (LPARAM)&hdItem);
256 static LONG setItem(HWND hdex, int idx, LPSTR text, BOOL fCheckNotifies)
258 LONG ret;
259 HDITEMA hdexItem;
260 hdexItem.mask = HDI_TEXT;
261 hdexItem.pszText = text;
262 hdexItem.cchTextMax = 0;
263 if (fCheckNotifies)
265 expect_notify(HDN_ITEMCHANGINGA, FALSE, &hdexItem);
266 expect_notify(HDN_ITEMCHANGEDA, FALSE, &hdexItem);
268 ret = SendMessageA(hdex, HDM_SETITEMA, idx, (LPARAM)&hdexItem);
269 if (fCheckNotifies)
270 ok(notifies_received(), "setItem(): not all expected notifies were received\n");
271 return ret;
274 static LONG setItemUnicodeNotify(HWND hdex, int idx, LPSTR text, LPWSTR wText)
276 LONG ret;
277 HDITEMA hdexItem;
278 HDITEMW hdexNotify;
279 hdexItem.mask = HDI_TEXT;
280 hdexItem.pszText = text;
281 hdexItem.cchTextMax = 0;
283 hdexNotify.mask = HDI_TEXT;
284 hdexNotify.pszText = wText;
286 expect_notify(HDN_ITEMCHANGINGW, TRUE, (HDITEMA*)&hdexNotify);
287 expect_notify(HDN_ITEMCHANGEDW, TRUE, (HDITEMA*)&hdexNotify);
288 ret = SendMessageA(hdex, HDM_SETITEMA, idx, (LPARAM)&hdexItem);
289 ok(notifies_received(), "setItemUnicodeNotify(): not all expected notifies were received\n");
290 return ret;
293 static LONG delItem(HWND hdex, int idx)
295 return SendMessageA(hdex, HDM_DELETEITEM, idx, 0);
298 static LONG getItemCount(HWND hdex)
300 return SendMessageA(hdex, HDM_GETITEMCOUNT, 0, 0);
303 static LONG getItem(HWND hdex, int idx, LPSTR textBuffer)
305 HDITEMA hdItem;
306 hdItem.mask = HDI_TEXT;
307 hdItem.pszText = textBuffer;
308 hdItem.cchTextMax = MAX_CHARS;
309 return SendMessageA(hdex, HDM_GETITEMA, idx, (LPARAM)&hdItem);
312 static void addReadDelItem(HWND hdex, HDITEMA *phdiCreate, int maskRead, HDITEMA *phdiRead)
314 ok(SendMessageA(hdex, HDM_INSERTITEMA, 0, (LPARAM)phdiCreate)!=-1, "Adding item failed\n");
315 ZeroMemory(phdiRead, sizeof(HDITEMA));
316 phdiRead->mask = maskRead;
317 ok(SendMessageA(hdex, HDM_GETITEMA, 0, (LPARAM)phdiRead)!=0, "Getting item data failed\n");
318 ok(SendMessageA(hdex, HDM_DELETEITEM, 0, 0)!=0, "Deleting item failed\n");
321 static HWND create_header_control (void)
323 HWND handle;
324 HDLAYOUT hlayout;
325 RECT rectwin;
326 WINDOWPOS winpos;
328 handle = CreateWindowExA(0, WC_HEADERA, NULL,
329 WS_CHILD|WS_BORDER|WS_VISIBLE|HDS_BUTTONS|HDS_HORZ,
330 0, 0, 0, 0,
331 hHeaderParentWnd, NULL, NULL, NULL);
332 ok(handle != NULL, "failed to create header window\n");
334 if (winetest_interactive)
335 ShowWindow (hHeaderParentWnd, SW_SHOW);
337 GetClientRect(hHeaderParentWnd,&rectwin);
338 hlayout.prc = &rectwin;
339 hlayout.pwpos = &winpos;
340 SendMessageA(handle, HDM_LAYOUT, 0, (LPARAM)&hlayout);
341 SetWindowPos(handle, winpos.hwndInsertAfter, winpos.x, winpos.y,
342 winpos.cx, winpos.cy, 0);
344 return handle;
347 static void compare_items(INT iCode, HDITEMA *hdi1, HDITEMA *hdi2, BOOL fUnicode)
349 ok(hdi1->mask == hdi2->mask, "Notify %d mask mismatch (%08x != %08x)\n", iCode, hdi1->mask, hdi2->mask);
350 if (hdi1->mask & HDI_WIDTH)
352 ok(hdi1->cxy == hdi2->cxy, "Notify %d cxy mismatch (%08x != %08x)\n", iCode, hdi1->cxy, hdi2->cxy);
354 if (hdi1->mask & HDI_TEXT)
356 if (hdi1->pszText == LPSTR_TEXTCALLBACKA)
358 ok(hdi1->pszText == LPSTR_TEXTCALLBACKA, "Notify %d - only one item is LPSTR_TEXTCALLBACK\n", iCode);
360 else
361 if (fUnicode)
363 char buf1[260];
364 char buf2[260];
365 WideCharToMultiByte(CP_ACP, 0, (LPCWSTR)hdi1->pszText, -1, buf1, 260, NULL, NULL);
366 WideCharToMultiByte(CP_ACP, 0, (LPCWSTR)hdi2->pszText, -1, buf2, 260, NULL, NULL);
367 ok(lstrcmpW((LPWSTR)hdi1->pszText, (LPWSTR)hdi2->pszText)==0,
368 "Notify %d text mismatch (L\"%s\" vs L\"%s\")\n",
369 iCode, buf1, buf2);
371 else
373 ok(strcmp(hdi1->pszText, hdi2->pszText)==0,
374 "Notify %d text mismatch (\"%s\" vs \"%s\")\n",
375 iCode, hdi1->pszText, hdi2->pszText);
380 static char pszFirstItem[] = "First Item";
381 static char pszSecondItem[] = "Second Item";
382 static char pszThirdItem[] = "Third Item";
383 static char pszFourthItem[] = "Fourth Item";
384 static char pszReplaceItem[] = "Replace Item";
385 static char pszOutOfRangeItem[] = "Out Of Range Item";
387 static char *str_items[] =
388 {pszFirstItem, pszSecondItem, pszThirdItem, pszFourthItem, pszReplaceItem, pszOutOfRangeItem};
390 static char pszUniTestA[] = "TST";
391 static WCHAR pszUniTestW[] = {'T','S','T',0};
394 #define TEST_GET_ITEM(i,c)\
395 { res = getItem(hWndHeader, i, buffer);\
396 ok(res != 0, "Getting item[%d] using valid index failed unexpectedly (%d)\n", i, res);\
397 ok(strcmp(str_items[c], buffer) == 0, "Getting item[%d] returned \"%s\" expecting \"%s\"\n", i, buffer, str_items[c]);\
400 #define TEST_GET_ITEMCOUNT(i)\
401 { res = getItemCount(hWndHeader);\
402 ok(res == i, "Got Item Count as %d\n", res);\
405 static LRESULT WINAPI header_subclass_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
407 WNDPROC oldproc = (WNDPROC)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
408 static LONG defwndproc_counter = 0;
409 struct message msg = { 0 };
410 LRESULT ret;
412 msg.message = message;
413 msg.flags = sent|wparam|lparam;
414 if (defwndproc_counter) msg.flags |= defwinproc;
415 msg.wParam = wParam;
416 msg.lParam = lParam;
417 add_message(sequences, HEADER_SEQ_INDEX, &msg);
419 defwndproc_counter++;
420 ret = CallWindowProcA(oldproc, hwnd, message, wParam, lParam);
421 defwndproc_counter--;
423 return ret;
426 static LRESULT WINAPI parent_wnd_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
428 static LONG defwndproc_counter = 0;
429 LRESULT ret;
430 struct message msg;
432 /* do not log painting messages */
433 if (message != WM_PAINT &&
434 message != WM_ERASEBKGND &&
435 message != WM_NCPAINT &&
436 message != WM_NCHITTEST &&
437 message != WM_GETTEXT &&
438 message != WM_GETICON &&
439 message != WM_DEVICECHANGE)
442 msg.message = message;
443 msg.flags = sent|wparam|lparam;
444 if (defwndproc_counter) msg.flags |= defwinproc;
445 msg.wParam = wParam;
446 msg.lParam = lParam;
447 msg.id = 0;
448 add_message(sequences, PARENT_SEQ_INDEX, &msg);
451 defwndproc_counter++;
452 ret = DefWindowProcA(hwnd, message, wParam, lParam);
453 defwndproc_counter--;
455 return ret;
458 static BOOL register_parent_wnd_class(void)
460 WNDCLASSA cls;
462 cls.style = 0;
463 cls.lpfnWndProc = parent_wnd_proc;
464 cls.cbClsExtra = 0;
465 cls.cbWndExtra = 0;
466 cls.hInstance = GetModuleHandleA(NULL);
467 cls.hIcon = 0;
468 cls.hCursor = LoadCursorA(0, (LPCSTR)IDC_ARROW);
469 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
470 cls.lpszMenuName = NULL;
471 cls.lpszClassName = "Header test parent class";
472 return RegisterClassA(&cls);
475 static HWND create_custom_parent_window(void)
477 if (!register_parent_wnd_class())
478 return NULL;
480 return CreateWindowExA(0, "Header test parent class", "Header Message Sequence Testing",
481 WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT,
482 672+2*GetSystemMetrics(SM_CXSIZEFRAME),
483 226+GetSystemMetrics(SM_CYCAPTION)+2*GetSystemMetrics(SM_CYSIZEFRAME),
484 NULL, NULL, GetModuleHandleA(NULL), 0);
487 static HWND create_custom_header_control(HWND hParent, BOOL preloadHeaderItems)
489 WNDPROC oldproc;
490 HWND childHandle;
491 HDLAYOUT hlayout;
492 RECT rectwin;
493 WINDOWPOS winpos;
494 int retVal;
495 int loopcnt;
496 static char firstHeaderItem[] = "Name";
497 static char secondHeaderItem[] = "Size";
498 static char *items[] = {secondHeaderItem, firstHeaderItem};
499 HDITEMA hdItem;
500 hdItem.mask = HDI_TEXT | HDI_WIDTH | HDI_FORMAT;
501 hdItem.fmt = HDF_LEFT;
502 hdItem.cxy = 80;
503 hdItem.cchTextMax = 260;
505 flush_sequences(sequences, NUM_MSG_SEQUENCES);
507 childHandle = CreateWindowExA(0, WC_HEADERA, NULL,
508 WS_CHILD|WS_BORDER|WS_VISIBLE|HDS_BUTTONS|HDS_HORZ,
509 0, 0, 0, 0,
510 hParent, NULL, NULL, NULL);
511 ok(childHandle != NULL, "failed to create child window\n");
512 if (preloadHeaderItems)
514 for ( loopcnt = 0 ; loopcnt < 2 ; loopcnt++ )
516 hdItem.pszText = items[loopcnt];
517 retVal = SendMessageA(childHandle, HDM_INSERTITEMA, loopcnt, (LPARAM) &hdItem);
518 ok(retVal == loopcnt, "Adding item %d failed with return value %d\n", ( loopcnt + 1 ), retVal);
522 if (winetest_interactive)
523 ShowWindow (hParent, SW_SHOW);
525 GetClientRect(hParent,&rectwin);
526 hlayout.prc = &rectwin;
527 hlayout.pwpos = &winpos;
528 SendMessageA(childHandle,HDM_LAYOUT,0,(LPARAM) &hlayout);
529 SetWindowPos(childHandle, winpos.hwndInsertAfter, winpos.x, winpos.y,
530 winpos.cx, winpos.cy, 0);
532 oldproc = (WNDPROC)SetWindowLongPtrA(childHandle, GWLP_WNDPROC,
533 (LONG_PTR)header_subclass_proc);
534 SetWindowLongPtrA(childHandle, GWLP_USERDATA, (LONG_PTR)oldproc);
535 return childHandle;
538 static void header_item_getback(HWND hwnd, UINT mask, HDITEMA *item)
540 int ret;
542 ret = SendMessageA(hwnd, HDM_INSERTITEMA, 0, (LPARAM)item);
543 ok(ret != -1, "Failed to add header item.\n");
545 memset(item, 0, sizeof(*item));
546 item->mask = mask;
548 ret = SendMessageA(hwnd, HDM_GETITEMA, 0, (LPARAM)item);
549 ok(ret != 0, "Failed to get item data.\n");
550 ret = SendMessageA(hwnd, HDM_DELETEITEM, 0, 0);
551 ok(ret != 0, "Failed to delete item.\n");
554 static void test_item_auto_format(HWND parent)
556 static char text[] = "Test";
557 HDITEMA item;
558 HBITMAP hbm;
559 HWND hwnd;
561 hwnd = create_custom_header_control(parent, FALSE);
563 /* Windows implicitly sets some format bits in INSERTITEM */
565 /* HDF_STRING is automatically set and cleared for no text */
566 item.mask = HDI_TEXT | HDI_WIDTH | HDI_FORMAT;
567 item.pszText = text;
568 item.cxy = 100;
569 item.fmt = HDF_CENTER;
570 header_item_getback(hwnd, HDI_FORMAT, &item);
571 ok(item.fmt == (HDF_STRING | HDF_CENTER), "Unexpected item format mask %#x.\n", item.fmt);
573 item.mask = HDI_WIDTH | HDI_FORMAT;
574 item.pszText = text;
575 item.fmt = HDF_CENTER | HDF_STRING;
576 header_item_getback(hwnd, HDI_FORMAT, &item);
577 ok(item.fmt == HDF_CENTER, "Unexpected item format mask %#x.\n", item.fmt);
579 /* HDF_BITMAP is automatically set and cleared for a NULL bitmap or no bitmap */
580 item.mask = HDI_BITMAP | HDI_WIDTH | HDI_FORMAT;
581 item.hbm = hbm = CreateBitmap(16, 16, 1, 8, NULL);
582 item.fmt = HDF_CENTER;
583 header_item_getback(hwnd, HDI_FORMAT, &item);
584 ok(item.fmt == (HDF_BITMAP | HDF_CENTER), "Unexpected item format mask %#x.\n", item.fmt);
585 DeleteObject(hbm);
587 item.mask = HDI_BITMAP | HDI_WIDTH | HDI_FORMAT;
588 item.hbm = NULL;
589 item.fmt = HDF_CENTER | HDF_BITMAP;
590 header_item_getback(hwnd, HDI_FORMAT, &item);
591 ok(item.fmt == HDF_CENTER, "Unexpected item format mask %#x.\n", item.fmt);
593 item.mask = HDI_WIDTH | HDI_FORMAT;
594 item.fmt = HDF_CENTER | HDF_BITMAP;
595 header_item_getback(hwnd, HDI_FORMAT, &item);
596 ok(item.fmt == HDF_CENTER, "Unexpected item format mask %#x.\n", item.fmt);
598 /* HDF_IMAGE is automatically set but not cleared */
599 item.mask = HDI_IMAGE | HDI_WIDTH | HDI_FORMAT;
600 item.iImage = 17;
601 header_item_getback(hwnd, HDI_FORMAT, &item);
602 ok(item.fmt == (HDF_IMAGE | HDF_CENTER), "Unexpected item format mask %#x.\n", item.fmt);
604 item.mask = HDI_WIDTH | HDI_FORMAT;
605 item.fmt = HDF_CENTER | HDF_IMAGE;
606 item.iImage = 0;
607 header_item_getback(hwnd, HDI_FORMAT, &item);
608 ok(item.fmt == (HDF_CENTER | HDF_IMAGE), "Unexpected item format mask %#x.\n", item.fmt);
610 DestroyWindow(hwnd);
613 static void check_auto_fields(void)
615 HDITEMA hdiCreate;
616 HDITEMA hdiRead;
617 static CHAR text[] = "Test";
618 LONG res;
620 /* Windows stores the format, width, lparam even if they are not in the item's mask */
621 ZeroMemory(&hdiCreate, sizeof(HDITEMA));
622 hdiCreate.mask = HDI_TEXT;
623 hdiCreate.cxy = 100;
624 hdiCreate.pszText = text;
625 addReadDelItem(hWndHeader, &hdiCreate, HDI_WIDTH, &hdiRead);
626 TEST_GET_ITEMCOUNT(6);
627 ok(hdiRead.cxy == hdiCreate.cxy, "cxy should be automatically set\n");
629 ZeroMemory(&hdiCreate, sizeof(HDITEMA));
630 hdiCreate.mask = HDI_TEXT;
631 hdiCreate.pszText = text;
632 hdiCreate.lParam = 0x12345678;
633 addReadDelItem(hWndHeader, &hdiCreate, HDI_LPARAM, &hdiRead);
634 TEST_GET_ITEMCOUNT(6);
635 ok(hdiRead.lParam == hdiCreate.lParam, "lParam should be automatically set\n");
637 ZeroMemory(&hdiCreate, sizeof(HDITEMA));
638 hdiCreate.mask = HDI_TEXT;
639 hdiCreate.pszText = text;
640 hdiCreate.fmt = HDF_STRING|HDF_CENTER;
641 addReadDelItem(hWndHeader, &hdiCreate, HDI_FORMAT, &hdiRead);
642 TEST_GET_ITEMCOUNT(6);
643 ok(hdiRead.fmt == hdiCreate.fmt, "fmt should be automatically set\n");
645 /* others fields are not set */
646 ZeroMemory(&hdiCreate, sizeof(HDITEMA));
647 hdiCreate.mask = HDI_TEXT;
648 hdiCreate.pszText = text;
649 hdiCreate.hbm = CreateBitmap(16, 16, 1, 8, NULL);
650 addReadDelItem(hWndHeader, &hdiCreate, HDI_BITMAP, &hdiRead);
651 TEST_GET_ITEMCOUNT(6);
652 ok(hdiRead.hbm == NULL, "hbm should not be automatically set\n");
653 DeleteObject(hdiCreate.hbm);
655 ZeroMemory(&hdiCreate, sizeof(HDITEMA));
656 hdiCreate.mask = HDI_IMAGE;
657 hdiCreate.iImage = 17;
658 hdiCreate.pszText = text;
659 addReadDelItem(hWndHeader, &hdiCreate, HDI_TEXT, &hdiRead);
660 TEST_GET_ITEMCOUNT(6);
661 ok(hdiRead.pszText==NULL, "pszText shouldn't be automatically set\n");
663 /* field from comctl >4.0 not tested as the system probably won't touch them */
666 static void check_mask(void)
668 HDITEMA hdi;
669 static CHAR text[] = "ABC";
670 LRESULT ret;
672 /* don't create items if the mask is zero */
673 ZeroMemory(&hdi, sizeof(hdi));
674 hdi.mask = 0;
675 hdi.cxy = 200;
676 hdi.pszText = text;
677 hdi.fmt = 0;
678 hdi.iOrder = 0;
679 hdi.lParam = 17;
680 hdi.cchTextMax = 260;
681 ret = SendMessageA(hWndHeader, HDM_INSERTITEMA, 0, (LPARAM)&hdi);
682 ok(ret == -1, "Creating an item with a zero mask should have failed\n");
683 if (ret != -1) SendMessageA(hWndHeader, HDM_DELETEITEM, 0, 0);
685 /* with a non-zero mask creation will succeed */
686 ZeroMemory(&hdi, sizeof(hdi));
687 hdi.mask = HDI_LPARAM;
688 ret = SendMessageA(hWndHeader, HDM_INSERTITEMA, 0, (LPARAM)&hdi);
689 ok(ret != -1, "Adding item with non-zero mask failed\n");
690 if (ret != -1)
691 SendMessageA(hWndHeader, HDM_DELETEITEM, 0, 0);
693 /* in SETITEM if the mask contains a unknown bit, it is ignored */
694 ZeroMemory(&hdi, sizeof(hdi));
695 hdi.mask = 0x08000000 | HDI_LPARAM | HDI_IMAGE;
696 hdi.lParam = 133;
697 hdi.iImage = 17;
698 ret = SendMessageA(hWndHeader, HDM_INSERTITEMA, 0, (LPARAM)&hdi);
699 ok(ret != -1, "Adding item failed\n");
701 if (ret != -1)
703 /* check result */
704 ZeroMemory(&hdi, sizeof(hdi));
705 hdi.mask = HDI_LPARAM | HDI_IMAGE;
706 SendMessageA(hWndHeader, HDM_GETITEMA, 0, (LPARAM)&hdi);
707 ok(hdi.lParam == 133, "comctl32 4.0 field not set\n");
708 ok(hdi.iImage == 17, "comctl32 >4.0 field not set\n");
710 /* but in GETITEM if an unknown bit is set, comctl32 uses only version 4.0 fields */
711 ZeroMemory(&hdi, sizeof(hdi));
712 hdi.mask = 0x08000000 | HDI_LPARAM | HDI_IMAGE;
713 SendMessageA(hWndHeader, HDM_GETITEMA, 0, (LPARAM)&hdi);
714 ok(hdi.lParam == 133, "comctl32 4.0 field not read\n");
715 ok(hdi.iImage == 0, "comctl32 >4.0 field shouldn't be read\n");
717 SendMessageA(hWndHeader, HDM_DELETEITEM, 0, 0);
721 static void test_header_control (void)
723 LONG res;
724 static char buffer[MAX_CHARS];
725 int i;
727 hWndHeader = create_header_control ();
729 for (i = 3; i >= 0; i--)
731 TEST_GET_ITEMCOUNT(3-i);
732 res = addItem(hWndHeader, 0, str_items[i]);
733 ok(res == 0, "Adding simple item failed (%d)\n", res);
736 TEST_GET_ITEMCOUNT(4);
737 res = addItem(hWndHeader, 99, str_items[i+1]);
738 ok(res != -1, "Adding Out of Range item should fail with -1 got (%d)\n", res);
739 TEST_GET_ITEMCOUNT(5);
740 res = addItem(hWndHeader, 5, str_items[i+1]);
741 ok(res != -1, "Adding Out of Range item should fail with -1 got (%d)\n", res);
742 TEST_GET_ITEMCOUNT(6);
744 for (i = 0; i < 4; i++) { TEST_GET_ITEM(i,i); TEST_GET_ITEMCOUNT(6); }
746 res=getItem(hWndHeader, 99, buffer);
747 ok(res == 0, "Getting Out of Range item should fail with 0 (%d), got %s\n", res,buffer);
748 res=getItem(hWndHeader, 5, buffer);
749 ok(res == 1, "Getting Out of Range item should fail with 1 (%d), got %s\n", res,buffer);
750 res=getItem(hWndHeader, -2, buffer);
751 ok(res == 0, "Getting Out of Range item should fail with 0 (%d), got %s\n", res,buffer);
753 if (winetest_interactive)
755 UpdateWindow(hHeaderParentWnd);
756 UpdateWindow(hWndHeader);
759 TEST_GET_ITEMCOUNT(6);
760 res=setItem(hWndHeader, 99, str_items[5], FALSE);
761 ok(res == 0, "Setting Out of Range item should fail with 0 (%d)\n", res);
762 res=setItem(hWndHeader, 5, str_items[5], TRUE);
763 ok(res == 1, "Setting Out of Range item should fail with 1 (%d)\n", res);
764 res=setItem(hWndHeader, -2, str_items[5], FALSE);
765 ok(res == 0, "Setting Out of Range item should fail with 0 (%d)\n", res);
766 TEST_GET_ITEMCOUNT(6);
768 for (i = 0; i < 4; i++)
770 res = setItem(hWndHeader, i, str_items[4], TRUE);
771 ok(res != 0, "Setting %d item failed (%d)\n", i+1, res);
772 TEST_GET_ITEM(i, 4);
773 TEST_GET_ITEMCOUNT(6);
776 SendMessageA(hWndHeader, HDM_SETUNICODEFORMAT, TRUE, 0);
777 setItemUnicodeNotify(hWndHeader, 3, pszUniTestA, pszUniTestW);
778 SendMessageA(hWndHeader, WM_NOTIFYFORMAT, (WPARAM)hHeaderParentWnd, NF_REQUERY);
779 setItem(hWndHeader, 3, str_items[4], TRUE);
781 dont_expect_notify(HDN_GETDISPINFOA);
782 dont_expect_notify(HDN_GETDISPINFOW);
783 addItem(hWndHeader, 0, LPSTR_TEXTCALLBACKA);
784 setItem(hWndHeader, 0, str_items[4], TRUE);
785 /* unexpected notifies cleared by notifies_received in setItem */
786 dont_expect_notify(HDN_GETDISPINFOA);
787 dont_expect_notify(HDN_GETDISPINFOW);
788 setItem(hWndHeader, 0, LPSTR_TEXTCALLBACKA, TRUE);
789 /* unexpected notifies cleared by notifies_received in setItem */
790 delItem(hWndHeader, 0);
792 TEST_GET_ITEMCOUNT(6);
793 check_auto_fields();
794 TEST_GET_ITEMCOUNT(6);
795 check_mask();
796 TEST_GET_ITEMCOUNT(6);
798 res = delItem(hWndHeader, 5);
799 ok(res == 1, "Deleting Out of Range item should fail with 1 (%d)\n", res);
800 res = delItem(hWndHeader, -2);
801 ok(res == 0, "Deleting Out of Range item should fail with 0 (%d)\n", res);
802 TEST_GET_ITEMCOUNT(5);
804 res = delItem(hWndHeader, 3);
805 ok(res != 0, "Deleting using out of range index failed (%d)\n", res);
806 TEST_GET_ITEMCOUNT(4);
807 res = delItem(hWndHeader, 0);
808 ok(res != 0, "Deleting using out of range index failed (%d)\n", res);
809 TEST_GET_ITEMCOUNT(3);
810 res = delItem(hWndHeader, 0);
811 ok(res != 0, "Deleting using out of range index failed (%d)\n", res);
812 TEST_GET_ITEMCOUNT(2);
813 res = delItem(hWndHeader, 0);
814 ok(res != 0, "Deleting using out of range index failed (%d)\n", res);
815 TEST_GET_ITEMCOUNT(1);
817 DestroyWindow(hWndHeader);
820 static void test_hdm_getitemrect(HWND hParent)
823 HWND hChild;
824 RECT rect;
825 int retVal;
827 flush_sequences(sequences, NUM_MSG_SEQUENCES);
828 hChild = create_custom_header_control(hParent, TRUE);
829 ok_sequence(sequences, PARENT_SEQ_INDEX, add_header_to_parent_seq,
830 "adder header control to parent", FALSE);
832 retVal = SendMessageA(hChild, HDM_GETITEMRECT, 1, (LPARAM) &rect);
833 ok(retVal == TRUE, "Getting item rect should TRUE, got %d\n", retVal);
834 /* check bounding rectangle information of 2nd header item */
835 expect(80, rect.left);
836 expect(0, rect.top);
837 expect(160, rect.right);
838 expect(g_customheight, rect.bottom);
840 retVal = SendMessageA(hChild, HDM_GETITEMRECT, 0, (LPARAM) &rect);
842 ok(retVal == TRUE, "Getting item rect should TRUE, got %d\n", retVal);
843 /* check bounding rectangle information of 1st header item */
844 expect(0, rect.left);
845 expect(0, rect.top);
847 expect(80, rect.right);
848 expect(g_customheight, rect.bottom);
850 retVal = SendMessageA(hChild, HDM_GETITEMRECT, 10, (LPARAM) &rect);
851 ok(retVal == 0, "Getting rect of nonexistent item should return 0, got %d\n", retVal);
853 ok_sequence(sequences, HEADER_SEQ_INDEX, getItemRect_seq, "getItemRect sequence testing", FALSE);
854 DestroyWindow(hChild);
857 static void test_hdm_layout(HWND hParent)
859 HWND hChild;
860 int retVal;
861 RECT rect;
862 HDLAYOUT hdLayout;
863 WINDOWPOS windowPos;
864 hdLayout.prc = &rect;
865 hdLayout.pwpos = &windowPos;
867 flush_sequences(sequences, NUM_MSG_SEQUENCES);
868 hChild = create_custom_header_control(hParent, TRUE);
869 ok_sequence(sequences, PARENT_SEQ_INDEX, add_header_to_parent_seq,
870 "adder header control to parent", FALSE);
872 flush_sequences(sequences, NUM_MSG_SEQUENCES);
873 retVal = SendMessageA(hChild, HDM_LAYOUT, 0, (LPARAM) &hdLayout);
874 expect(TRUE, retVal);
876 ok_sequence(sequences, HEADER_SEQ_INDEX, layout_seq, "layout sequence testing", FALSE);
878 DestroyWindow(hChild);
881 static void test_hdm_ordertoindex(HWND hParent)
883 HWND hChild;
884 int retVal;
886 flush_sequences(sequences, NUM_MSG_SEQUENCES);
887 hChild = create_custom_header_control(hParent, TRUE);
888 ok_sequence(sequences, PARENT_SEQ_INDEX, add_header_to_parent_seq,
889 "adder header control to parent", FALSE);
891 flush_sequences(sequences, NUM_MSG_SEQUENCES);
892 retVal = SendMessageA(hChild, HDM_ORDERTOINDEX, 1, 0);
893 expect(1, retVal);
895 ok_sequence(sequences, HEADER_SEQ_INDEX, orderToIndex_seq, "orderToIndex sequence testing", FALSE);
896 DestroyWindow(hChild);
899 static void test_hdm_hittest(HWND hParent)
901 HWND hChild;
902 int retVal;
903 POINT pt;
904 HDHITTESTINFO hdHitTestInfo;
905 const int firstItemRightBoundary = 80;
906 const int secondItemRightBoundary = 160;
907 const int bottomBoundary = g_customheight;
909 pt.x = firstItemRightBoundary - 1;
910 pt.y = bottomBoundary - 1;
911 hdHitTestInfo.pt = pt;
914 flush_sequences(sequences, NUM_MSG_SEQUENCES);
915 hChild = create_custom_header_control(hParent, TRUE);
916 ok_sequence(sequences, PARENT_SEQ_INDEX, add_header_to_parent_seq,
917 "adder header control to parent", FALSE);
919 flush_sequences(sequences, NUM_MSG_SEQUENCES);
920 retVal = SendMessageA(hChild, HDM_HITTEST, 0, (LPARAM) &hdHitTestInfo);
921 expect(0, retVal);
922 expect(0, hdHitTestInfo.iItem);
923 expect(HHT_ONDIVIDER, hdHitTestInfo.flags);
925 pt.x = secondItemRightBoundary - 1;
926 pt.y = bottomBoundary - 1;
927 hdHitTestInfo.pt = pt;
928 retVal = SendMessageA(hChild, HDM_HITTEST, 1, (LPARAM) &hdHitTestInfo);
929 expect(1, retVal);
930 expect(1, hdHitTestInfo.iItem);
931 expect(HHT_ONDIVIDER, hdHitTestInfo.flags);
933 pt.x = secondItemRightBoundary;
934 pt.y = bottomBoundary + 1;
935 hdHitTestInfo.pt = pt;
936 retVal = SendMessageA(hChild, HDM_HITTEST, 0, (LPARAM) &hdHitTestInfo);
937 expect(-1, retVal);
938 expect(-1, hdHitTestInfo.iItem);
939 expect(HHT_BELOW, hdHitTestInfo.flags);
941 ok_sequence(sequences, HEADER_SEQ_INDEX, hittest_seq, "hittest sequence testing", FALSE);
943 DestroyWindow(hChild);
946 static void test_hdm_sethotdivider(HWND hParent)
948 HWND hChild;
949 int retVal;
950 /* low word: x coordinate = 5
951 * high word: y coordinate = 5
954 flush_sequences(sequences, NUM_MSG_SEQUENCES);
955 hChild = create_custom_header_control(hParent, TRUE);
956 ok_sequence(sequences, PARENT_SEQ_INDEX, add_header_to_parent_seq,
957 "adder header control to parent", FALSE);
959 flush_sequences(sequences, NUM_MSG_SEQUENCES);
960 retVal = SendMessageA(hChild, HDM_SETHOTDIVIDER, TRUE, MAKELPARAM(5, 5));
961 expect(0, retVal);
963 retVal = SendMessageA(hChild, HDM_SETHOTDIVIDER, FALSE, 100);
964 expect(100, retVal);
965 retVal = SendMessageA(hChild, HDM_SETHOTDIVIDER, FALSE, 1);
966 expect(1, retVal);
967 if (winetest_interactive)
968 ok_sequence(sequences, HEADER_SEQ_INDEX, setHotDivider_seq_interactive,
969 "setHotDivider sequence testing", TRUE);
970 else
971 ok_sequence(sequences, HEADER_SEQ_INDEX, setHotDivider_seq_noninteractive,
972 "setHotDivider sequence testing", FALSE);
974 DestroyWindow(hChild);
977 static void test_hdm_imageMessages(HWND hParent)
979 HIMAGELIST hImageList = pImageList_Create (4, 4, 0, 1, 0);
980 HIMAGELIST hIml;
981 BOOL wasValid;
982 HWND hChild;
984 flush_sequences(sequences, NUM_MSG_SEQUENCES);
985 hChild = create_custom_header_control(hParent, TRUE);
986 ok_sequence(sequences, PARENT_SEQ_INDEX, add_header_to_parent_seq,
987 "adder header control to parent", FALSE);
989 flush_sequences(sequences, NUM_MSG_SEQUENCES);
991 hIml = (HIMAGELIST) SendMessageA(hChild, HDM_SETIMAGELIST, 0, (LPARAM) hImageList);
992 ok(hIml == NULL, "Expected NULL, got %p\n", hIml);
994 hIml = (HIMAGELIST) SendMessageA(hChild, HDM_GETIMAGELIST, 0, 0);
995 ok(hIml != NULL, "Expected non-NULL handle, got %p\n", hIml);
997 hIml = (HIMAGELIST) SendMessageA(hChild, HDM_CREATEDRAGIMAGE, 0, 0);
998 ok(hIml != NULL, "Expected non-NULL handle, got %p\n", hIml);
999 pImageList_Destroy(hIml);
1001 ok_sequence(sequences, HEADER_SEQ_INDEX, imageMessages_seq, "imageMessages sequence testing", FALSE);
1003 DestroyWindow(hChild);
1005 wasValid = pImageList_Destroy(hImageList);
1006 ok(wasValid, "Header must not free image list at destruction!\n");
1009 static void test_hdm_filterMessages(HWND hParent)
1011 HWND hChild;
1012 int retVal, timeout;
1014 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1015 hChild = create_custom_header_control(hParent, TRUE);
1016 ok_sequence(sequences, PARENT_SEQ_INDEX, add_header_to_parent_seq,
1017 "adder header control to parent", FALSE);
1019 timeout = SendMessageA(hChild, HDM_SETFILTERCHANGETIMEOUT, 0, 0);
1020 ok(timeout == 1000, "got %d\n", timeout);
1022 timeout = SendMessageA(hChild, HDM_SETFILTERCHANGETIMEOUT, 0, 0);
1023 ok(timeout == 1000, "got %d\n", timeout);
1025 timeout = SendMessageA(hChild, HDM_SETFILTERCHANGETIMEOUT, 0, -100);
1026 ok(timeout == 1000, "got %d\n", timeout);
1028 timeout = SendMessageA(hChild, HDM_SETFILTERCHANGETIMEOUT, 1, 100);
1029 ok(timeout == -100, "got %d\n", timeout);
1030 retVal = SendMessageA(hChild, HDM_SETFILTERCHANGETIMEOUT, 1, timeout);
1031 ok(retVal == 100, "got %d\n", retVal);
1033 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1035 /* msdn incorrectly states that return value
1036 * is the index of the filter control being
1037 * modified. The sendMessage here should
1038 * return previous filter timeout value
1041 retVal = SendMessageA(hChild, HDM_SETFILTERCHANGETIMEOUT, 1, 100);
1042 expect(timeout, retVal);
1044 todo_wine
1046 retVal = SendMessageA(hChild, HDM_CLEARFILTER, 0, 1);
1047 if (retVal == 0)
1048 win_skip("HDM_CLEARFILTER needs 5.80\n");
1049 else
1050 expect(1, retVal);
1052 retVal = SendMessageA(hChild, HDM_EDITFILTER, 1, 0);
1053 if (retVal == 0)
1054 win_skip("HDM_EDITFILTER needs 5.80\n");
1055 else
1056 expect(1, retVal);
1058 if (winetest_interactive)
1059 ok_sequence(sequences, HEADER_SEQ_INDEX, filterMessages_seq_interactive,
1060 "filterMessages sequence testing", TRUE);
1061 else
1062 ok_sequence(sequences, HEADER_SEQ_INDEX, filterMessages_seq_noninteractive,
1063 "filterMessages sequence testing", FALSE);
1064 DestroyWindow(hChild);
1068 static void test_hdm_unicodeformatMessages(HWND hParent)
1070 HWND hChild;
1071 int retVal;
1073 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1074 hChild = create_custom_header_control(hParent, TRUE);
1075 ok_sequence(sequences, PARENT_SEQ_INDEX, add_header_to_parent_seq,
1076 "adder header control to parent", FALSE);
1078 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1079 retVal = SendMessageA(hChild, HDM_SETUNICODEFORMAT, TRUE, 0);
1080 expect(0, retVal);
1081 retVal = SendMessageA(hChild, HDM_GETUNICODEFORMAT, 0, 0);
1082 expect(1, retVal);
1084 ok_sequence(sequences, HEADER_SEQ_INDEX, unicodeformatMessages_seq,
1085 "unicodeformatMessages sequence testing", FALSE);
1086 DestroyWindow(hChild);
1089 static void test_hdm_bitmapmarginMessages(HWND hParent)
1091 HWND hChild;
1092 int retVal;
1094 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1095 hChild = create_custom_header_control(hParent, TRUE);
1096 ok_sequence(sequences, PARENT_SEQ_INDEX, add_header_to_parent_seq,
1097 "adder header control to parent", FALSE);
1099 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1100 retVal = SendMessageA(hChild, HDM_GETBITMAPMARGIN, 0, 0);
1101 if (retVal == 0)
1102 win_skip("HDM_GETBITMAPMARGIN needs 5.80\n");
1103 else
1104 expect(6, retVal);
1106 ok_sequence(sequences, HEADER_SEQ_INDEX, bitmapmarginMessages_seq,
1107 "bitmapmarginMessages sequence testing", FALSE);
1108 DestroyWindow(hChild);
1111 static void test_hdm_index_messages(HWND hParent)
1113 HWND hChild;
1114 int retVal, i, iSize;
1115 static const int lpiarray[2] = {1, 0};
1116 static const char *item_texts[] = {
1117 "Name", "Size", "Type", "Date Modified"
1119 RECT rect;
1120 HDITEMA hdItem;
1121 char buffA[32];
1122 int array[2];
1124 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1125 hChild = create_custom_header_control(hParent, FALSE);
1126 if (winetest_interactive)
1127 ok_sequence(sequences, PARENT_SEQ_INDEX, add_header_to_parent_seq_interactive,
1128 "adder header control to parent", TRUE);
1129 else
1130 ok_sequence(sequences, PARENT_SEQ_INDEX, add_header_to_parent_seq,
1131 "adder header control to parent", FALSE);
1132 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1133 for (i = 0; i < ARRAY_SIZE(item_texts); i++)
1135 hdItem.mask = HDI_TEXT | HDI_WIDTH | HDI_FORMAT;
1136 hdItem.pszText = (char*)item_texts[i];
1137 hdItem.fmt = HDF_LEFT;
1138 hdItem.cxy = 80;
1140 retVal = SendMessageA(hChild, HDM_INSERTITEMA, i, (LPARAM) &hdItem);
1141 ok(retVal == i, "Adding item %d failed with return value %d\n", i, retVal);
1143 ok_sequence(sequences, HEADER_SEQ_INDEX, insertItem_seq, "insertItem sequence testing", FALSE);
1145 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1147 retVal = SendMessageA(hChild, HDM_DELETEITEM, 3, (LPARAM) &hdItem);
1148 ok(retVal == TRUE, "Deleting item 3 should return TRUE, got %d\n", retVal);
1149 retVal = SendMessageA(hChild, HDM_GETITEMCOUNT, 0, 0);
1150 ok(retVal == 3, "Getting item count should return 3, got %d\n", retVal);
1152 retVal = SendMessageA(hChild, HDM_DELETEITEM, 3, (LPARAM) &hdItem);
1153 ok(retVal == FALSE, "Deleting already-deleted item should return FALSE, got %d\n", retVal);
1154 retVal = SendMessageA(hChild, HDM_GETITEMCOUNT, 0, 0);
1155 ok(retVal == 3, "Getting item count should return 3, got %d\n", retVal);
1157 retVal = SendMessageA(hChild, HDM_DELETEITEM, 2, (LPARAM) &hdItem);
1158 ok(retVal == TRUE, "Deleting item 2 should return TRUE, got %d\n", retVal);
1159 retVal = SendMessageA(hChild, HDM_GETITEMCOUNT, 0, 0);
1160 ok(retVal == 2, "Getting item count should return 2, got %d\n", retVal);
1162 ok_sequence(sequences, HEADER_SEQ_INDEX, deleteItem_getItemCount_seq,
1163 "deleteItem_getItemCount sequence testing", FALSE);
1165 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1167 hdItem.mask = HDI_WIDTH;
1168 retVal = SendMessageA(hChild, HDM_GETITEMA, 3, (LPARAM) &hdItem);
1169 ok(retVal == FALSE, "Getting already-deleted item should return FALSE, got %d\n", retVal);
1171 hdItem.mask = HDI_TEXT | HDI_WIDTH;
1172 hdItem.pszText = buffA;
1173 hdItem.cchTextMax = ARRAY_SIZE(buffA);
1174 retVal = SendMessageA(hChild, HDM_GETITEMA, 0, (LPARAM) &hdItem);
1175 ok(retVal == TRUE, "Getting the 1st header item should return TRUE, got %d\n", retVal);
1177 ok_sequence(sequences, HEADER_SEQ_INDEX, getItem_seq, "getItem sequence testing", FALSE);
1179 /* check if the item is the right one */
1180 ok(!strcmp(hdItem.pszText, item_texts[0]), "got wrong item %s, expected %s\n",
1181 hdItem.pszText, item_texts[0]);
1182 expect(80, hdItem.cxy);
1184 iSize = SendMessageA(hChild, HDM_GETITEMCOUNT, 0, 0);
1186 /* item should be updated just after accepting new array */
1187 ShowWindow(hChild, SW_HIDE);
1188 retVal = SendMessageA(hChild, HDM_SETORDERARRAY, iSize, (LPARAM) lpiarray);
1189 expect(TRUE, retVal);
1190 rect.left = 0;
1191 retVal = SendMessageA(hChild, HDM_GETITEMRECT, 0, (LPARAM) &rect);
1192 expect(TRUE, retVal);
1193 ok(rect.left != 0, "Expected updated rectangle\n");
1195 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1197 retVal = SendMessageA(hChild, HDM_SETORDERARRAY, iSize, (LPARAM) lpiarray);
1198 ok(retVal == TRUE, "Setting header items order should return TRUE, got %d\n", retVal);
1200 retVal = SendMessageA(hChild, HDM_GETORDERARRAY, 2, (LPARAM) array);
1201 ok(retVal == TRUE, "Getting header items order should return TRUE, got %d\n", retVal);
1203 ok_sequence(sequences, HEADER_SEQ_INDEX, orderArray_seq, "set_get_orderArray sequence testing", FALSE);
1205 /* check if the array order is set correctly and the size of the array is correct. */
1206 expect(2, iSize);
1207 ok(lpiarray[0] == array[0], "got %d, expected %d\n", array[0], lpiarray[0]);
1208 ok(lpiarray[1] == array[1], "got %d, expected %d\n", array[1], lpiarray[1]);
1210 hdItem.mask = HDI_FORMAT;
1211 hdItem.fmt = HDF_CENTER | HDF_STRING;
1213 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1215 retVal = SendMessageA(hChild, HDM_SETITEMA, 0, (LPARAM) &hdItem);
1216 ok(retVal == TRUE, "Aligning 1st header item to center should return TRUE, got %d\n", retVal);
1217 hdItem.fmt = HDF_RIGHT | HDF_STRING;
1218 retVal = SendMessageA(hChild, HDM_SETITEMA, 1, (LPARAM) &hdItem);
1219 ok(retVal == TRUE, "Aligning 2nd header item to right should return TRUE, got %d\n", retVal);
1221 ok_sequence(sequences, HEADER_SEQ_INDEX, setItem_seq, "setItem sequence testing", FALSE);
1222 DestroyWindow(hChild);
1225 static void test_hdf_fixedwidth(HWND hParent)
1227 HWND hChild;
1228 HDITEMA hdItem;
1229 DWORD ret;
1230 RECT rect;
1231 HDHITTESTINFO ht;
1233 hChild = create_custom_header_control(hParent, FALSE);
1235 hdItem.mask = HDI_WIDTH | HDI_FORMAT;
1236 hdItem.fmt = HDF_FIXEDWIDTH;
1237 hdItem.cxy = 80;
1239 ret = SendMessageA(hChild, HDM_INSERTITEMA, 0, (LPARAM)&hdItem);
1240 expect(0, ret);
1242 /* try to change width */
1243 rect.right = rect.bottom = 0;
1244 SendMessageA(hChild, HDM_GETITEMRECT, 0, (LPARAM)&rect);
1245 ok(rect.right != 0, "Expected not zero width\n");
1246 ok(rect.bottom != 0, "Expected not zero height\n");
1248 SendMessageA(hChild, WM_LBUTTONDOWN, 0, MAKELPARAM(rect.right, rect.bottom / 2));
1249 SendMessageA(hChild, WM_MOUSEMOVE, 0, MAKELPARAM(rect.right + 20, rect.bottom / 2));
1250 SendMessageA(hChild, WM_LBUTTONUP, 0, MAKELPARAM(rect.right + 20, rect.bottom / 2));
1252 SendMessageA(hChild, HDM_GETITEMRECT, 0, (LPARAM)&rect);
1254 if (hdItem.cxy != rect.right)
1256 win_skip("HDF_FIXEDWIDTH format not supported\n");
1257 DestroyWindow(hChild);
1258 return;
1261 /* try to adjust with message */
1262 hdItem.mask = HDI_WIDTH;
1263 hdItem.cxy = 90;
1265 ret = SendMessageA(hChild, HDM_SETITEMA, 0, (LPARAM)&hdItem);
1266 expect(TRUE, ret);
1268 rect.right = 0;
1269 SendMessageA(hChild, HDM_GETITEMRECT, 0, (LPARAM)&rect);
1270 expect(90, rect.right);
1272 /* hittesting doesn't report ondivider flag for HDF_FIXEDWIDTH */
1273 ht.pt.x = rect.right - 1;
1274 ht.pt.y = rect.bottom / 2;
1275 SendMessageA(hChild, HDM_HITTEST, 0, (LPARAM)&ht);
1276 expect(HHT_ONHEADER, ht.flags);
1278 /* try to adjust with message */
1279 hdItem.mask = HDI_FORMAT;
1280 hdItem.fmt = 0;
1282 ret = SendMessageA(hChild, HDM_SETITEMA, 0, (LPARAM)&hdItem);
1283 expect(TRUE, ret);
1285 ht.pt.x = 90;
1286 ht.pt.y = rect.bottom / 2;
1287 SendMessageA(hChild, HDM_HITTEST, 0, (LPARAM)&ht);
1288 expect(HHT_ONDIVIDER, ht.flags);
1290 DestroyWindow(hChild);
1293 static void test_hds_nosizing(HWND hParent)
1295 HWND hChild;
1296 HDITEMA hdItem;
1297 DWORD ret;
1298 RECT rect;
1299 HDHITTESTINFO ht;
1301 hChild = create_custom_header_control(hParent, FALSE);
1303 memset(&hdItem, 0, sizeof(hdItem));
1304 hdItem.mask = HDI_WIDTH;
1305 hdItem.cxy = 80;
1307 ret = SendMessageA(hChild, HDM_INSERTITEMA, 0, (LPARAM)&hdItem);
1308 expect(0, ret);
1310 /* HDS_NOSIZING only blocks hittesting */
1311 ret = GetWindowLongA(hChild, GWL_STYLE);
1312 SetWindowLongA(hChild, GWL_STYLE, ret | HDS_NOSIZING);
1314 /* try to change width with mouse gestures */
1315 rect.right = rect.bottom = 0;
1316 SendMessageA(hChild, HDM_GETITEMRECT, 0, (LPARAM)&rect);
1317 ok(rect.right != 0, "Expected not zero width\n");
1318 ok(rect.bottom != 0, "Expected not zero height\n");
1320 SendMessageA(hChild, WM_LBUTTONDOWN, 0, MAKELPARAM(rect.right, rect.bottom / 2));
1321 SendMessageA(hChild, WM_MOUSEMOVE, 0, MAKELPARAM(rect.right + 20, rect.bottom / 2));
1322 SendMessageA(hChild, WM_LBUTTONUP, 0, MAKELPARAM(rect.right + 20, rect.bottom / 2));
1324 SendMessageA(hChild, HDM_GETITEMRECT, 0, (LPARAM)&rect);
1326 if (hdItem.cxy != rect.right)
1328 win_skip("HDS_NOSIZING style not supported\n");
1329 DestroyWindow(hChild);
1330 return;
1333 /* this style doesn't set HDF_FIXEDWIDTH for items */
1334 hdItem.mask = HDI_FORMAT;
1335 ret = SendMessageA(hChild, HDM_GETITEMA, 0, (LPARAM)&hdItem);
1336 expect(TRUE, ret);
1337 ok(!(hdItem.fmt & HDF_FIXEDWIDTH), "Unexpected HDF_FIXEDWIDTH\n");
1339 /* try to adjust with message */
1340 hdItem.mask = HDI_WIDTH;
1341 hdItem.cxy = 90;
1343 ret = SendMessageA(hChild, HDM_SETITEMA, 0, (LPARAM)&hdItem);
1344 expect(TRUE, ret);
1346 rect.right = 0;
1347 SendMessageA(hChild, HDM_GETITEMRECT, 0, (LPARAM)&rect);
1348 expect(90, rect.right);
1350 /* hittesting doesn't report ondivider flags for HDS_NOSIZING */
1351 ht.pt.x = rect.right - 1;
1352 ht.pt.y = rect.bottom / 2;
1353 SendMessageA(hChild, HDM_HITTEST, 0, (LPARAM)&ht);
1354 expect(HHT_ONHEADER, ht.flags);
1356 /* try to adjust with message */
1357 ret = GetWindowLongA(hChild, GWL_STYLE);
1358 SetWindowLongA(hChild, GWL_STYLE, ret & ~HDS_NOSIZING);
1360 ht.pt.x = 90;
1361 ht.pt.y = rect.bottom / 2;
1362 SendMessageA(hChild, HDM_HITTEST, 0, (LPARAM)&ht);
1363 expect(HHT_ONDIVIDER, ht.flags);
1365 DestroyWindow(hChild);
1368 #define TEST_NMCUSTOMDRAW(draw_stage, item_spec, lparam, _left, _top, _right, _bottom) \
1369 ok(nm->dwDrawStage == draw_stage, "Invalid dwDrawStage %d vs %d\n", draw_stage, nm->dwDrawStage); \
1370 if (item_spec != -1) \
1371 ok(nm->dwItemSpec == item_spec, "Invalid dwItemSpec %d vs %ld\n", item_spec, nm->dwItemSpec); \
1372 ok(nm->lItemlParam == lparam, "Invalid lItemlParam %d vs %ld\n", lparam, nm->lItemlParam); \
1373 ok((nm->rc.top == _top && nm->rc.bottom == _bottom && nm->rc.left == _left && nm->rc.right == _right) || \
1374 broken(draw_stage != CDDS_ITEMPREPAINT), /* comctl32 < 5.80 */ \
1375 "Invalid rect (%d,%d)-(%d,%d) vs %s\n", _left, _top, _right, _bottom, \
1376 wine_dbgstr_rect(&nm->rc));
1378 static LRESULT customdraw_1(int n, NMCUSTOMDRAW *nm)
1380 if (nm == NULL) { /* test ended */
1381 ok(n==1, "NM_CUSTOMDRAW messages: %d, expected: 1\n", n);
1382 return 0;
1385 switch (n)
1387 case 0:
1388 /* don't test dwItemSpec - it's 0 no comctl5 but 1308756 on comctl6 */
1389 TEST_NMCUSTOMDRAW(CDDS_PREPAINT, -1, 0, 0, 0, 670, g_customheight);
1390 return 0;
1393 ok(FALSE, "Too many custom draw messages (n=%d, nm->dwDrawStage=%d)\n", n, nm->dwDrawStage);
1394 return -1;
1397 static LRESULT customdraw_2(int n, NMCUSTOMDRAW *nm)
1399 if (nm == NULL) { /* test ended */
1400 ok(n==4, "NM_CUSTOMDRAW messages: %d, expected: 4\n", n);
1401 return 0;
1404 switch (n)
1406 case 0:
1407 TEST_NMCUSTOMDRAW(CDDS_PREPAINT, -1, 0, 0, 0, 670, g_customheight);
1408 return CDRF_NOTIFYITEMDRAW;
1409 case 1:
1410 TEST_NMCUSTOMDRAW(CDDS_ITEMPREPAINT, 0, 0, 0, 0, 50, g_customheight);
1411 return 0;
1412 case 2:
1413 TEST_NMCUSTOMDRAW(CDDS_ITEMPREPAINT, 1, 5, 50, 0, 150, g_customheight);
1414 return 0;
1415 case 3:
1416 TEST_NMCUSTOMDRAW(CDDS_ITEMPREPAINT, 2, 10, 150, 0, 300, g_customheight);
1417 return 0;
1420 ok(FALSE, "Too many custom draw messages (n=%d, nm->dwDrawStage=%d)\n", n, nm->dwDrawStage);
1421 return 0;
1424 static LRESULT customdraw_3(int n, NMCUSTOMDRAW *nm)
1426 if (nm == NULL) { /* test ended */
1427 ok(n==5, "NM_CUSTOMDRAW messages: %d, expected: 5\n", n);
1428 return 0;
1431 switch (n)
1433 case 0:
1434 TEST_NMCUSTOMDRAW(CDDS_PREPAINT, -1, 0, 0, 0, 670, g_customheight);
1435 return CDRF_NOTIFYITEMDRAW|CDRF_NOTIFYPOSTERASE|CDRF_NOTIFYPOSTPAINT|CDRF_SKIPDEFAULT;
1436 case 1:
1437 TEST_NMCUSTOMDRAW(CDDS_ITEMPREPAINT, 0, 0, 0, 0, 50, g_customheight);
1438 return 0;
1439 case 2:
1440 TEST_NMCUSTOMDRAW(CDDS_ITEMPREPAINT, 1, 5, 50, 0, 150, g_customheight);
1441 return 0;
1442 case 3:
1443 TEST_NMCUSTOMDRAW(CDDS_ITEMPREPAINT, 2, 10, 150, 0, 300, g_customheight);
1444 return 0;
1445 case 4:
1446 TEST_NMCUSTOMDRAW(CDDS_POSTPAINT, -1, 0, 0, 0, 670, g_customheight);
1447 return 0;
1450 ok(FALSE, "Too many custom draw messages (n=%d, nm->dwDrawStage=%d)\n", n, nm->dwDrawStage);
1451 return 0;
1455 static LRESULT customdraw_4(int n, NMCUSTOMDRAW *nm)
1457 if (nm == NULL) { /* test ended */
1458 ok(n==4, "NM_CUSTOMDRAW messages: %d, expected: 4\n", n);
1459 return 0;
1462 switch (n)
1464 case 0:
1465 TEST_NMCUSTOMDRAW(CDDS_PREPAINT, -1, 0, 0, 0, 670, g_customheight);
1466 return CDRF_NOTIFYITEMDRAW|CDRF_NOTIFYPOSTPAINT;
1467 case 1:
1468 TEST_NMCUSTOMDRAW(CDDS_ITEMPREPAINT, 0, 0, 0, 0, 50, g_customheight);
1469 return 0;
1470 case 2:
1471 TEST_NMCUSTOMDRAW(CDDS_ITEMPREPAINT, 2, 10, 150, 0, 300, g_customheight);
1472 return 0;
1473 case 3:
1474 TEST_NMCUSTOMDRAW(CDDS_POSTPAINT, -1, 0, 0, 0, 670, g_customheight);
1475 return 0;
1478 ok(FALSE, "Too many custom draw messages (n=%d, nm->dwDrawStage=%d)\n", n, nm->dwDrawStage);
1479 return 0;
1482 static void run_customdraw_scenario(CUSTOMDRAWPROC proc)
1484 g_CustomDrawProc = proc;
1485 g_CustomDrawCount = 0;
1486 InvalidateRect(hWndHeader, NULL, TRUE);
1487 UpdateWindow(hWndHeader);
1488 proc(g_CustomDrawCount, NULL);
1489 g_CustomDrawProc = NULL;
1492 static void test_customdraw(void)
1494 int i;
1495 HDITEMA item;
1496 RECT rect;
1497 CHAR name[] = "Test";
1498 hWndHeader = create_header_control();
1499 GetClientRect(hWndHeader, &rect);
1500 ok(rect.right - rect.left == 670 && rect.bottom - rect.top == g_customheight,
1501 "Tests will fail as header size is %dx%d instead of 670x%d\n",
1502 rect.right - rect.left, rect.bottom - rect.top, g_customheight);
1504 for (i = 0; i < 3; i++)
1506 ZeroMemory(&item, sizeof(item));
1507 item.mask = HDI_TEXT|HDI_WIDTH;
1508 item.cxy = 50*(i+1);
1509 item.pszText = name;
1510 item.lParam = i*5;
1511 SendMessageA(hWndHeader, HDM_INSERTITEMA, i, (LPARAM)&item);
1514 run_customdraw_scenario(customdraw_1);
1515 run_customdraw_scenario(customdraw_2);
1516 run_customdraw_scenario(customdraw_3);
1518 ZeroMemory(&item, sizeof(item));
1519 item.mask = HDI_FORMAT;
1520 item.fmt = HDF_OWNERDRAW;
1521 SendMessageA(hWndHeader, HDM_SETITEMA, 1, (LPARAM)&item);
1522 g_DrawItem.CtlID = 0;
1523 g_DrawItem.CtlType = ODT_HEADER;
1524 g_DrawItem.hwndItem = hWndHeader;
1525 g_DrawItem.itemID = 1;
1526 g_DrawItem.itemState = 0;
1527 SendMessageA(hWndHeader, HDM_GETITEMRECT, 1, (LPARAM)&g_DrawItem.rcItem);
1528 run_customdraw_scenario(customdraw_4);
1529 ok(g_DrawItemReceived, "WM_DRAWITEM not received\n");
1530 DestroyWindow(hWndHeader);
1531 hWndHeader = NULL;
1532 g_DrawItem.CtlType = 0;
1533 g_DrawItemReceived = FALSE;
1536 static void check_order(const int expected_id[], const int expected_order[],
1537 int count, const char *type)
1539 int i;
1540 HDITEMA hdi;
1542 ok(getItemCount(hWndHeader) == count, "Invalid item count in order tests\n");
1543 for (i = 0; i < count; i++)
1545 hdi.mask = HDI_LPARAM|HDI_ORDER;
1546 SendMessageA(hWndHeader, HDM_GETITEMA, i, (LPARAM)&hdi);
1547 ok(hdi.lParam == expected_id[i],
1548 "Invalid item ids after '%s'- item %d has lParam %d\n", type, i, (int)hdi.lParam);
1549 ok(hdi.iOrder == expected_order[i],
1550 "Invalid item order after '%s'- item %d has iOrder %d\n", type, i, hdi.iOrder);
1554 static void test_header_order (void)
1556 const int rand1[] = {0, 1, 1, 0, 4};
1557 const int rand2[] = {4, 5, 6, 7, 4};
1558 const int rand3[] = {5, 5, 1, 6, 1};
1559 const int rand4[] = {1, 5, 2, 7, 6, 1, 4, 2, 3, 2};
1560 const int rand5[] = {7, 8, 5, 6, 7, 2, 1, 9, 10, 10};
1561 const int rand6[] = {2, 8, 3, 4, 0};
1563 const int ids1[] = {3, 0, 2, 1, 4};
1564 const int ord1[] = {0, 1, 2, 3, 4};
1565 const int ids2[] = {3, 9, 7, 0, 2, 1, 4, 8, 6, 5};
1566 const int ord2[] = {0, 4, 7, 1, 2, 3, 9, 8, 6, 5};
1567 const int ord3[] = {0, 3, 9, 2, 1, 8, 7, 6, 5, 4};
1568 const int ids4[] = {9, 0, 1, 8, 6};
1569 const int ord4[] = {1, 0, 4, 3, 2};
1571 char buffer[20];
1572 HDITEMA hdi;
1573 int i;
1575 hWndHeader = create_header_control();
1577 ZeroMemory(&hdi, sizeof(HDITEMA));
1578 hdi.mask = HDI_TEXT | HDI_LPARAM;
1579 hdi.pszText = buffer;
1580 strcpy(buffer, "test");
1582 for (i = 0; i < 5; i++)
1584 hdi.lParam = i;
1585 SendMessageA(hWndHeader, HDM_INSERTITEMA, rand1[i], (LPARAM)&hdi);
1587 check_order(ids1, ord1, 5, "insert without iOrder");
1589 hdi.mask |= HDI_ORDER;
1590 for (i = 0; i < 5; i++)
1592 hdi.lParam = i + 5;
1593 hdi.iOrder = rand2[i];
1594 SendMessageA(hWndHeader, HDM_INSERTITEMA, rand3[i], (LPARAM)&hdi);
1596 check_order(ids2, ord2, 10, "insert with order");
1598 hdi.mask = HDI_ORDER;
1599 for (i=0; i<10; i++)
1601 hdi.iOrder = rand5[i];
1602 SendMessageA(hWndHeader, HDM_SETITEMA, rand4[i], (LPARAM)&hdi);
1604 check_order(ids2, ord3, 10, "setitems changing order");
1606 for (i=0; i<5; i++)
1607 SendMessageA(hWndHeader, HDM_DELETEITEM, rand6[i], 0);
1608 check_order(ids4, ord4, 5, "deleteitem");
1610 DestroyWindow(hWndHeader);
1613 static LRESULT CALLBACK HeaderTestWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
1615 DRAWITEMSTRUCT *di;
1616 switch(msg) {
1618 case WM_NOTIFY:
1620 NMHEADERA *hdr = (NMHEADERA*)lParam;
1621 EXPECTEDNOTIFY *expected;
1622 int i;
1624 if (hdr->hdr.code == NM_CUSTOMDRAW)
1625 if (g_CustomDrawProc)
1626 return g_CustomDrawProc(g_CustomDrawCount++, (NMCUSTOMDRAW*)hdr);
1628 for (i=0; i<nUnexpectedNotify; i++)
1629 ok(hdr->hdr.code != unexpectedNotify[i], "Received invalid notify %d\n", hdr->hdr.code);
1631 if (nReceivedNotify >= nExpectedNotify || hdr->hdr.hwndFrom != hWndHeader )
1632 break;
1634 expected = &expectedNotify[nReceivedNotify];
1635 if (hdr->hdr.code != expected->iCode)
1636 break;
1638 nReceivedNotify++;
1639 compare_items(hdr->hdr.code, &expected->hdItem, hdr->pitem, expected->fUnicode);
1640 break;
1643 case WM_DRAWITEM:
1644 di = (DRAWITEMSTRUCT *)lParam;
1645 ok(g_DrawItem.CtlType != 0, "Unexpected WM_DRAWITEM\n");
1646 if (g_DrawItem.CtlType == 0) return 0;
1647 g_DrawItemReceived = TRUE;
1648 compare(di->CtlType, g_DrawItem.CtlType, "%d");
1649 compare(di->CtlID, g_DrawItem.CtlID, "%d");
1650 compare(di->hwndItem, g_DrawItem.hwndItem, "%p");
1651 compare(di->itemID, g_DrawItem.itemID, "%d");
1652 compare(di->itemState, g_DrawItem.itemState, "%d");
1653 compare(di->rcItem.left, g_DrawItem.rcItem.left, "%d");
1654 compare(di->rcItem.top, g_DrawItem.rcItem.top, "%d");
1655 compare(di->rcItem.right, g_DrawItem.rcItem.right, "%d");
1656 compare(di->rcItem.bottom, g_DrawItem.rcItem.bottom, "%d");
1657 break;
1659 case WM_DESTROY:
1660 PostQuitMessage(0);
1661 break;
1663 default:
1664 return DefWindowProcA(hWnd, msg, wParam, lParam);
1667 return 0L;
1670 static void init_functions(void)
1672 HMODULE hComCtl32 = LoadLibraryA("comctl32.dll");
1674 #define X(f) p##f = (void*)GetProcAddress(hComCtl32, #f);
1675 X(ImageList_Create);
1676 X(ImageList_Destroy);
1677 #undef X
1680 static BOOL init(void)
1682 WNDCLASSA wc;
1683 TEXTMETRICA tm;
1684 HFONT hOldFont;
1685 HDC hdc;
1687 wc.style = CS_HREDRAW | CS_VREDRAW;
1688 wc.cbClsExtra = 0;
1689 wc.cbWndExtra = 0;
1690 wc.hInstance = GetModuleHandleA(NULL);
1691 wc.hIcon = NULL;
1692 wc.hCursor = LoadCursorA(NULL, (LPCSTR)IDC_ARROW);
1693 wc.hbrBackground = GetSysColorBrush(COLOR_WINDOW);
1694 wc.lpszMenuName = NULL;
1695 wc.lpszClassName = "HeaderTestClass";
1696 wc.lpfnWndProc = HeaderTestWndProc;
1697 RegisterClassA(&wc);
1699 /* The height of the header control depends on the height of the system font.
1700 The height of the system font is dpi dependent */
1701 hdc = GetDC(0);
1702 hOldFont = SelectObject(hdc, GetStockObject(SYSTEM_FONT));
1703 GetTextMetricsA(hdc, &tm);
1704 /* 2 dot extra space are needed for the border */
1705 g_customheight = tm.tmHeight + 2;
1706 trace("customdraw height: %d (dpi: %d)\n", g_customheight, GetDeviceCaps(hdc, LOGPIXELSY));
1707 SelectObject(hdc, hOldFont);
1708 ReleaseDC(0, hdc);
1710 hHeaderParentWnd = CreateWindowExA(0, "HeaderTestClass", "Header test", WS_OVERLAPPEDWINDOW,
1711 CW_USEDEFAULT, CW_USEDEFAULT, 672+2*GetSystemMetrics(SM_CXSIZEFRAME),
1712 226+GetSystemMetrics(SM_CYCAPTION)+2*GetSystemMetrics(SM_CYSIZEFRAME),
1713 NULL, NULL, GetModuleHandleA(NULL), 0);
1714 ok(hHeaderParentWnd != NULL, "failed to create parent wnd\n");
1716 ShowWindow(hHeaderParentWnd, SW_SHOW);
1717 return hHeaderParentWnd != NULL;
1720 /* maximum 8 items allowed */
1721 static void check_orderarray(HWND hwnd, DWORD start, DWORD set, DWORD expected,
1722 BOOL todo, int line)
1724 int count, i;
1725 INT order[8];
1726 DWORD ret, array = 0;
1728 count = SendMessageA(hwnd, HDM_GETITEMCOUNT, 0, 0);
1730 /* initial order */
1731 for(i = 1; i<=count; i++)
1732 order[i-1] = start>>(4*(count-i)) & 0xf;
1734 ret = SendMessageA(hwnd, HDM_SETORDERARRAY, count, (LPARAM)order);
1735 ok_(__FILE__, line)(ret, "Expected HDM_SETORDERARRAY to succeed, got %d\n", ret);
1737 /* new order */
1738 for(i = 1; i<=count; i++)
1739 order[i-1] = set>>(4*(count-i)) & 0xf;
1740 ret = SendMessageA(hwnd, HDM_SETORDERARRAY, count, (LPARAM)order);
1741 ok_(__FILE__, line)(ret, "Expected HDM_SETORDERARRAY to succeed, got %d\n", ret);
1743 /* check actual order */
1744 ret = SendMessageA(hwnd, HDM_GETORDERARRAY, count, (LPARAM)order);
1745 ok_(__FILE__, line)(ret, "Expected HDM_GETORDERARRAY to succeed, got %d\n", ret);
1746 for(i = 1; i<=count; i++)
1747 array |= order[i-1]<<(4*(count-i));
1749 todo_wine_if(todo)
1750 ok_(__FILE__, line)(array == expected, "Expected %x, got %x\n", expected, array);
1753 static void test_hdm_orderarray(void)
1755 HWND hwnd;
1756 INT order[5];
1757 DWORD ret;
1759 hwnd = create_header_control();
1761 /* three items */
1762 addItem(hwnd, 0, NULL);
1763 addItem(hwnd, 1, NULL);
1764 addItem(hwnd, 2, NULL);
1766 ret = SendMessageA(hwnd, HDM_GETORDERARRAY, 3, (LPARAM)order);
1767 if (!ret)
1769 win_skip("HDM_GETORDERARRAY not implemented.\n");
1770 DestroyWindow(hwnd);
1771 return;
1774 expect(0, order[0]);
1775 expect(1, order[1]);
1776 expect(2, order[2]);
1778 if (0)
1780 /* null pointer, crashes native */
1781 ret = SendMessageA(hwnd, HDM_SETORDERARRAY, 3, 0);
1782 expect(FALSE, ret);
1784 /* count out of limits */
1785 ret = SendMessageA(hwnd, HDM_SETORDERARRAY, 5, (LPARAM)order);
1786 expect(FALSE, ret);
1787 /* count out of limits */
1788 ret = SendMessageA(hwnd, HDM_SETORDERARRAY, 2, (LPARAM)order);
1789 expect(FALSE, ret);
1791 /* try with out of range item index */
1792 /* (0,1,2)->(1,0,3) => (1,0,2) */
1793 check_orderarray(hwnd, 0x120, 0x103, 0x102, FALSE, __LINE__);
1794 /* (1,0,2)->(3,0,1) => (0,2,1) */
1795 check_orderarray(hwnd, 0x102, 0x301, 0x021, TRUE, __LINE__);
1796 /* (0,2,1)->(2,3,1) => (2,0,1) */
1797 check_orderarray(hwnd, 0x021, 0x231, 0x201, FALSE, __LINE__);
1799 /* (0,1,2)->(0,2,2) => (0,1,2) */
1800 check_orderarray(hwnd, 0x012, 0x022, 0x012, FALSE, __LINE__);
1802 addItem(hwnd, 3, NULL);
1804 /* (0,1,2,3)->(0,1,2,2) => (0,1,3,2) */
1805 check_orderarray(hwnd, 0x0123, 0x0122, 0x0132, FALSE, __LINE__);
1806 /* (0,1,2,3)->(0,1,3,3) => (0,1,2,3) */
1807 check_orderarray(hwnd, 0x0123, 0x0133, 0x0123, FALSE, __LINE__);
1808 /* (0,1,2,3)->(0,4,2,3) => (0,1,2,3) */
1809 check_orderarray(hwnd, 0x0123, 0x0423, 0x0123, FALSE, __LINE__);
1810 /* (0,1,2,3)->(4,0,1,2) => (0,1,3,2) */
1811 check_orderarray(hwnd, 0x0123, 0x4012, 0x0132, TRUE, __LINE__);
1812 /* (0,1,3,2)->(4,0,1,4) => (0,3,1,2) */
1813 check_orderarray(hwnd, 0x0132, 0x4014, 0x0312, TRUE, __LINE__);
1814 /* (0,1,2,3)->(4,1,0,2) => (1,0,3,2) */
1815 check_orderarray(hwnd, 0x0123, 0x4102, 0x1032, TRUE, __LINE__);
1816 /* (0,1,2,3)->(0,1,4,2) => (0,1,2,3) */
1817 check_orderarray(hwnd, 0x0123, 0x0142, 0x0132, FALSE, __LINE__);
1818 /* (0,1,2,3)->(4,4,4,4) => (0,1,2,3) */
1819 check_orderarray(hwnd, 0x0123, 0x4444, 0x0123, FALSE, __LINE__);
1820 /* (0,1,2,3)->(4,4,1,2) => (0,1,3,2) */
1821 check_orderarray(hwnd, 0x0123, 0x4412, 0x0132, TRUE, __LINE__);
1822 /* (0,1,2,3)->(4,4,4,1) => (0,2,3,1) */
1823 check_orderarray(hwnd, 0x0123, 0x4441, 0x0231, TRUE, __LINE__);
1824 /* (0,1,2,3)->(1,4,4,4) => (1,0,2,3) */
1825 check_orderarray(hwnd, 0x0123, 0x1444, 0x1023, FALSE, __LINE__);
1826 /* (0,1,2,3)->(4,2,4,1) => (0,2,3,1) */
1827 check_orderarray(hwnd, 0x0123, 0x4241, 0x0231, FALSE, __LINE__);
1828 /* (0,1,2,3)->(4,2,0,1) => (2,0,3,1) */
1829 check_orderarray(hwnd, 0x0123, 0x4201, 0x2031, TRUE, __LINE__);
1830 /* (3,2,1,0)->(4,2,0,1) => (3,2,0,1) */
1831 check_orderarray(hwnd, 0x3210, 0x4201, 0x3201, FALSE, __LINE__);
1833 DestroyWindow(hwnd);
1836 START_TEST(header)
1838 HWND parent_hwnd;
1839 ULONG_PTR ctx_cookie;
1840 HANDLE hCtx;
1842 init_functions();
1843 init_msg_sequences(sequences, NUM_MSG_SEQUENCES);
1845 if (!init())
1846 return;
1848 test_header_control();
1849 test_item_auto_format(hHeaderParentWnd);
1850 test_header_order();
1851 test_hdm_orderarray();
1852 test_customdraw();
1854 DestroyWindow(hHeaderParentWnd);
1856 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1857 parent_hwnd = create_custom_parent_window();
1858 ok_sequence(sequences, PARENT_SEQ_INDEX, create_parent_wnd_seq, "create parent windows", FALSE);
1860 test_hdm_index_messages(parent_hwnd);
1861 test_hdm_getitemrect(parent_hwnd);
1862 test_hdm_hittest(parent_hwnd);
1863 test_hdm_layout(parent_hwnd);
1864 test_hdm_ordertoindex(parent_hwnd);
1865 test_hdm_sethotdivider(parent_hwnd);
1866 test_hdm_imageMessages(parent_hwnd);
1867 test_hdm_filterMessages(parent_hwnd);
1868 test_hdm_unicodeformatMessages(parent_hwnd);
1869 test_hdm_bitmapmarginMessages(parent_hwnd);
1871 if (!load_v6_module(&ctx_cookie, &hCtx))
1873 DestroyWindow(parent_hwnd);
1874 return;
1877 init_functions();
1879 /* comctl32 version 6 tests start here */
1880 test_hdf_fixedwidth(parent_hwnd);
1881 test_hds_nosizing(parent_hwnd);
1882 test_item_auto_format(parent_hwnd);
1884 unload_v6_module(ctx_cookie, hCtx);
1886 DestroyWindow(parent_hwnd);