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
26 #include "wine/test.h"
28 typedef struct tagEXPECTEDNOTIFY
35 typedef LRESULT (*CUSTOMDRAWPROC)(int n, NMCUSTOMDRAW *nm);
37 static CUSTOMDRAWPROC g_CustomDrawProc;
38 static int g_CustomDrawCount;
39 static DRAWITEMSTRUCT g_DrawItem;
40 static BOOL g_DrawItemReceived;
42 static EXPECTEDNOTIFY expectedNotify[10];
43 static INT nExpectedNotify = 0;
44 static INT nReceivedNotify = 0;
45 static INT unexpectedNotify[10];
46 static INT nUnexpectedNotify = 0;
48 static HWND hHeaderParentWnd;
49 static HWND hWndHeader;
52 #define compare(val, exp, fmt) ok((val) == (exp), #val " value: " fmt ", expected: " fmt "\n", (val), (exp))
54 #define expect(expected, got) ok(expected == got, "expected %d, got %d\n", expected,got)
56 static void expect_notify(INT iCode, BOOL fUnicode, HDITEMA *lpItem)
58 assert(nExpectedNotify < 10);
59 expectedNotify[nExpectedNotify].iCode = iCode;
60 expectedNotify[nExpectedNotify].fUnicode = fUnicode;
61 expectedNotify[nExpectedNotify].hdItem = *lpItem;
65 static void dont_expect_notify(INT iCode)
67 assert(nUnexpectedNotify < 10);
68 unexpectedNotify[nUnexpectedNotify++] = iCode;
71 static BOOL notifies_received(void)
73 BOOL fRet = (nExpectedNotify == nReceivedNotify);
74 nExpectedNotify = nReceivedNotify = 0;
75 nUnexpectedNotify = 0;
79 static LONG addItem(HWND hdex, int idx, LPSTR text)
82 hdItem.mask = HDI_TEXT | HDI_WIDTH;
84 hdItem.pszText = text;
85 hdItem.cchTextMax = 0;
86 return (LONG)SendMessage(hdex, HDM_INSERTITEMA, (WPARAM)idx, (LPARAM)&hdItem);
89 static LONG setItem(HWND hdex, int idx, LPSTR text, BOOL fCheckNotifies)
93 hdexItem.mask = HDI_TEXT;
94 hdexItem.pszText = text;
95 hdexItem.cchTextMax = 0;
98 expect_notify(HDN_ITEMCHANGINGA, FALSE, &hdexItem);
99 expect_notify(HDN_ITEMCHANGEDA, FALSE, &hdexItem);
101 ret = (LONG)SendMessage(hdex, HDM_SETITEMA, (WPARAM)idx, (LPARAM)&hdexItem);
103 ok(notifies_received(), "setItem(): not all expected notifies were received\n");
107 static LONG setItemUnicodeNotify(HWND hdex, int idx, LPSTR text, LPWSTR wText)
112 hdexItem.mask = HDI_TEXT;
113 hdexItem.pszText = text;
114 hdexItem.cchTextMax = 0;
116 hdexNotify.mask = HDI_TEXT;
117 hdexNotify.pszText = wText;
119 expect_notify(HDN_ITEMCHANGINGW, TRUE, (HDITEMA*)&hdexNotify);
120 expect_notify(HDN_ITEMCHANGEDW, TRUE, (HDITEMA*)&hdexNotify);
121 ret = (LONG)SendMessage(hdex, HDM_SETITEMA, (WPARAM)idx, (LPARAM)&hdexItem);
122 ok(notifies_received(), "setItemUnicodeNotify(): not all expected notifies were received\n");
126 static LONG delItem(HWND hdex, int idx)
128 return (LONG)SendMessage(hdex, HDM_DELETEITEM, (WPARAM)idx, 0);
131 static LONG getItemCount(HWND hdex)
133 return (LONG)SendMessage(hdex, HDM_GETITEMCOUNT, 0, 0);
136 static LONG getItem(HWND hdex, int idx, LPSTR textBuffer)
139 hdItem.mask = HDI_TEXT;
140 hdItem.pszText = textBuffer;
141 hdItem.cchTextMax = MAX_CHARS;
142 return (LONG)SendMessage(hdex, HDM_GETITEMA, (WPARAM)idx, (LPARAM)&hdItem);
145 static void addReadDelItem(HWND hdex, HDITEMA *phdiCreate, int maskRead, HDITEMA *phdiRead)
147 ok(SendMessage(hdex, HDM_INSERTITEMA, (WPARAM)0, (LPARAM)phdiCreate)!=-1, "Adding item failed\n");
148 ZeroMemory(phdiRead, sizeof(HDITEMA));
149 phdiRead->mask = maskRead;
150 ok(SendMessage(hdex, HDM_GETITEMA, (WPARAM)0, (LPARAM)phdiRead)!=0, "Getting item data failed\n");
151 ok(SendMessage(hdex, HDM_DELETEITEM, (WPARAM)0, (LPARAM)0)!=0, "Deleting item failed\n");
154 static HWND create_header_control (void)
161 handle = CreateWindowEx(0, WC_HEADER, NULL,
162 WS_CHILD|WS_BORDER|WS_VISIBLE|HDS_BUTTONS|HDS_HORZ,
164 hHeaderParentWnd, NULL, NULL, NULL);
167 if (winetest_interactive)
168 ShowWindow (hHeaderParentWnd, SW_SHOW);
170 GetClientRect(hHeaderParentWnd,&rectwin);
171 hlayout.prc = &rectwin;
172 hlayout.pwpos = &winpos;
173 SendMessageA(handle,HDM_LAYOUT,0,(LPARAM) &hlayout);
174 SetWindowPos(handle, winpos.hwndInsertAfter, winpos.x, winpos.y,
175 winpos.cx, winpos.cy, 0);
180 static void compare_items(INT iCode, HDITEMA *hdi1, HDITEMA *hdi2, BOOL fUnicode)
182 ok(hdi1->mask == hdi2->mask, "Notify %d mask mismatch (%08x != %08x)\n", iCode, hdi1->mask, hdi2->mask);
183 if (hdi1->mask & HDI_WIDTH)
185 ok(hdi1->cxy == hdi2->cxy, "Notify %d cxy mismatch (%08x != %08x)\n", iCode, hdi1->cxy, hdi2->cxy);
187 if (hdi1->mask & HDI_TEXT)
189 if (hdi1->pszText == LPSTR_TEXTCALLBACKA)
191 ok(hdi1->pszText == LPSTR_TEXTCALLBACKA, "Notify %d - only one item is LPSTR_TEXTCALLBACK\n", iCode);
198 WideCharToMultiByte(CP_ACP, 0, (LPCWSTR)hdi1->pszText, -1, buf1, 260, NULL, NULL);
199 WideCharToMultiByte(CP_ACP, 0, (LPCWSTR)hdi2->pszText, -1, buf2, 260, NULL, NULL);
200 ok(lstrcmpW((LPWSTR)hdi1->pszText, (LPWSTR)hdi2->pszText)==0,
201 "Notify %d text mismatch (L\"%s\" vs L\"%s\")\n",
206 ok(strcmp(hdi1->pszText, hdi2->pszText)==0,
207 "Notify %d text mismatch (\"%s\" vs \"%s\")\n",
208 iCode, hdi1->pszText, hdi2->pszText);
213 static char pszFirstItem[] = "First Item";
214 static char pszSecondItem[] = "Second Item";
215 static char pszThirdItem[] = "Third Item";
216 static char pszFourthItem[] = "Fourth Item";
217 static char pszReplaceItem[] = "Replace Item";
218 static char pszOutOfRangeItem[] = "Out Of Range Item";
220 static char *str_items[] =
221 {pszFirstItem, pszSecondItem, pszThirdItem, pszFourthItem, pszReplaceItem, pszOutOfRangeItem};
223 static char pszUniTestA[] = "TST";
224 static WCHAR pszUniTestW[] = {'T','S','T',0};
227 #define TEST_GET_ITEM(i,c)\
228 { res = getItem(hWndHeader, i, buffer);\
229 ok(res != 0, "Getting item[%d] using valid index failed unexpectedly (%d)\n", i, res);\
230 ok(strcmp(str_items[c], buffer) == 0, "Getting item[%d] returned \"%s\" expecting \"%s\"\n", i, buffer, str_items[c]);\
233 #define TEST_GET_ITEMCOUNT(i)\
234 { res = getItemCount(hWndHeader);\
235 ok(res == i, "Got Item Count as %d\n", res);\
238 static void check_auto_format(void)
242 static CHAR text[] = "Test";
243 ZeroMemory(&hdiCreate, sizeof(HDITEMA));
245 /* Windows implicitly sets some format bits in INSERTITEM */
247 /* HDF_STRING is automatically set and cleared for no text */
248 hdiCreate.mask = HDI_TEXT|HDI_WIDTH|HDI_FORMAT;
249 hdiCreate.pszText = text;
251 hdiCreate.fmt=HDF_CENTER;
252 addReadDelItem(hWndHeader, &hdiCreate, HDI_FORMAT, &hdiRead);
253 ok(hdiRead.fmt == (HDF_STRING|HDF_CENTER), "HDF_STRING not set automatically (fmt=%x)\n", hdiRead.fmt);
255 hdiCreate.mask = HDI_WIDTH|HDI_FORMAT;
256 hdiCreate.pszText = text;
257 hdiCreate.fmt = HDF_CENTER|HDF_STRING;
258 addReadDelItem(hWndHeader, &hdiCreate, HDI_FORMAT, &hdiRead);
259 ok(hdiRead.fmt == (HDF_CENTER), "HDF_STRING should be automatically cleared (fmt=%x)\n", hdiRead.fmt);
261 /* HDF_BITMAP is automatically set and cleared for a NULL bitmap or no bitmap */
262 hdiCreate.mask = HDI_BITMAP|HDI_WIDTH|HDI_FORMAT;
263 hdiCreate.hbm = CreateBitmap(16, 16, 1, 8, NULL);
264 hdiCreate.fmt = HDF_CENTER;
265 addReadDelItem(hWndHeader, &hdiCreate, HDI_FORMAT, &hdiRead);
266 ok(hdiRead.fmt == (HDF_BITMAP|HDF_CENTER), "HDF_BITMAP not set automatically (fmt=%x)\n", hdiRead.fmt);
267 DeleteObject(hdiCreate.hbm);
269 hdiCreate.hbm = NULL;
270 hdiCreate.fmt = HDF_CENTER|HDF_BITMAP;
271 addReadDelItem(hWndHeader, &hdiCreate, HDI_FORMAT, &hdiRead);
272 ok(hdiRead.fmt == HDF_CENTER, "HDF_BITMAP not cleared automatically for NULL bitmap (fmt=%x)\n", hdiRead.fmt);
274 hdiCreate.mask = HDI_WIDTH|HDI_FORMAT;
275 hdiCreate.fmt = HDF_CENTER|HDF_BITMAP;
276 addReadDelItem(hWndHeader, &hdiCreate, HDI_FORMAT, &hdiRead);
277 ok(hdiRead.fmt == HDF_CENTER, "HDF_BITMAP not cleared automatically for no bitmap (fmt=%x)\n", hdiRead.fmt);
279 /* HDF_IMAGE is automatically set but not cleared */
280 hdiCreate.mask = HDI_IMAGE|HDI_WIDTH|HDI_FORMAT;
281 hdiCreate.iImage = 17;
282 addReadDelItem(hWndHeader, &hdiCreate, HDI_FORMAT, &hdiRead);
283 ok(hdiRead.fmt == (HDF_IMAGE|HDF_CENTER), "HDF_IMAGE not set automatically (fmt=%x)\n", hdiRead.fmt);
285 hdiCreate.mask = HDI_WIDTH|HDI_FORMAT;
286 hdiCreate.fmt = HDF_CENTER|HDF_IMAGE;
287 hdiCreate.iImage = 0;
288 addReadDelItem(hWndHeader, &hdiCreate, HDI_FORMAT, &hdiRead);
289 ok(hdiRead.fmt == (HDF_CENTER|HDF_IMAGE), "HDF_IMAGE shouldn't be cleared automatically (fmt=%x)\n", hdiRead.fmt);
292 static void check_auto_fields(void)
296 static CHAR text[] = "Test";
299 /* Windows stores the format, width, lparam even if they are not in the item's mask */
300 ZeroMemory(&hdiCreate, sizeof(HDITEMA));
301 hdiCreate.mask = HDI_TEXT;
303 hdiCreate.pszText = text;
304 addReadDelItem(hWndHeader, &hdiCreate, HDI_WIDTH, &hdiRead);
305 TEST_GET_ITEMCOUNT(6);
306 ok(hdiRead.cxy == hdiCreate.cxy, "cxy should be automatically set\n");
308 ZeroMemory(&hdiCreate, sizeof(HDITEMA));
309 hdiCreate.mask = HDI_TEXT;
310 hdiCreate.pszText = text;
311 hdiCreate.lParam = 0x12345678;
312 addReadDelItem(hWndHeader, &hdiCreate, HDI_LPARAM, &hdiRead);
313 TEST_GET_ITEMCOUNT(6);
314 ok(hdiRead.lParam == hdiCreate.lParam, "lParam should be automatically set\n");
316 ZeroMemory(&hdiCreate, sizeof(HDITEMA));
317 hdiCreate.mask = HDI_TEXT;
318 hdiCreate.pszText = text;
319 hdiCreate.fmt = HDF_STRING|HDF_CENTER;
320 addReadDelItem(hWndHeader, &hdiCreate, HDI_FORMAT, &hdiRead);
321 TEST_GET_ITEMCOUNT(6);
322 ok(hdiRead.fmt == hdiCreate.fmt, "fmt should be automatically set\n");
324 /* others fields are not set */
325 ZeroMemory(&hdiCreate, sizeof(HDITEMA));
326 hdiCreate.mask = HDI_TEXT;
327 hdiCreate.pszText = text;
328 hdiCreate.hbm = CreateBitmap(16, 16, 1, 8, NULL);
329 addReadDelItem(hWndHeader, &hdiCreate, HDI_BITMAP, &hdiRead);
330 TEST_GET_ITEMCOUNT(6);
331 ok(hdiRead.hbm == NULL, "hbm should not be automatically set\n");
332 DeleteObject(hdiCreate.hbm);
334 ZeroMemory(&hdiCreate, sizeof(HDITEMA));
335 hdiCreate.mask = HDI_IMAGE;
336 hdiCreate.iImage = 17;
337 hdiCreate.pszText = text;
338 addReadDelItem(hWndHeader, &hdiCreate, HDI_TEXT, &hdiRead);
339 TEST_GET_ITEMCOUNT(6);
340 ok(hdiRead.pszText==NULL, "pszText shouldn't be automatically set\n");
342 /* field from comctl >4.0 not tested as the system probably won't touch them */
345 static void check_mask(void)
348 static CHAR text[] = "ABC";
351 /* don't create items if the mask is zero */
352 ZeroMemory(&hdi, sizeof(hdi));
359 hdi.cchTextMax = 260;
360 ret = SendMessage(hWndHeader, HDM_INSERTITEM, (WPARAM)0, (LPARAM)&hdi);
361 ok(ret == -1, "Creating an item with a zero mask should have failed\n");
362 if (ret != -1) SendMessage(hWndHeader, HDM_DELETEITEM, (WPARAM)0, (LPARAM)0);
364 /* with a non-zero mask creation will succeed */
365 ZeroMemory(&hdi, sizeof(hdi));
366 hdi.mask = HDI_LPARAM;
367 ret = SendMessage(hWndHeader, HDM_INSERTITEM, (WPARAM)0, (LPARAM)&hdi);
368 ok(ret != -1, "Adding item with non-zero mask failed\n");
370 SendMessage(hWndHeader, HDM_DELETEITEM, (WPARAM)0, (LPARAM)0);
372 /* in SETITEM if the mask contains a unknown bit, it is ignored */
373 ZeroMemory(&hdi, sizeof(hdi));
374 hdi.mask = 0x08000000 | HDI_LPARAM | HDI_IMAGE;
377 ret = SendMessage(hWndHeader, HDM_INSERTITEM, (WPARAM)0, (LPARAM)&hdi);
378 ok(ret != -1, "Adding item failed\n");
383 ZeroMemory(&hdi, sizeof(hdi));
384 hdi.mask = HDI_LPARAM | HDI_IMAGE;
385 SendMessage(hWndHeader, HDM_GETITEM, (WPARAM)0, (LPARAM)&hdi);
386 ok(hdi.lParam == 133, "comctl32 4.0 field not set\n");
387 ok(hdi.iImage == 17, "comctl32 >4.0 field not set\n");
389 /* but in GETITEM if an unknown bit is set, comctl32 uses only version 4.0 fields */
390 ZeroMemory(&hdi, sizeof(hdi));
391 hdi.mask = 0x08000000 | HDI_LPARAM | HDI_IMAGE;
392 SendMessage(hWndHeader, HDM_GETITEM, (WPARAM)0, (LPARAM)&hdi);
393 ok(hdi.lParam == 133, "comctl32 4.0 field not read\n");
394 ok(hdi.iImage == 0, "comctl32 >4.0 field shouldn't be read\n");
396 SendMessage(hWndHeader, HDM_DELETEITEM, (WPARAM)0, (LPARAM)0);
400 static void test_header_control (void)
403 static char buffer[MAX_CHARS];
406 hWndHeader = create_header_control ();
408 for (i = 3; i >= 0; i--)
410 TEST_GET_ITEMCOUNT(3-i);
411 res = addItem(hWndHeader, 0, str_items[i]);
412 ok(res == 0, "Adding simple item failed (%d)\n", res);
415 TEST_GET_ITEMCOUNT(4);
416 res = addItem(hWndHeader, 99, str_items[i+1]);
417 ok(res != -1, "Adding Out of Range item should fail with -1 got (%d)\n", res);
418 TEST_GET_ITEMCOUNT(5);
419 res = addItem(hWndHeader, 5, str_items[i+1]);
420 ok(res != -1, "Adding Out of Range item should fail with -1 got (%d)\n", res);
421 TEST_GET_ITEMCOUNT(6);
423 for (i = 0; i < 4; i++) { TEST_GET_ITEM(i,i); TEST_GET_ITEMCOUNT(6); }
425 res=getItem(hWndHeader, 99, buffer);
426 ok(res == 0, "Getting Out of Range item should fail with 0 (%d), got %s\n", res,buffer);
427 res=getItem(hWndHeader, 5, buffer);
428 ok(res == 1, "Getting Out of Range item should fail with 1 (%d), got %s\n", res,buffer);
429 res=getItem(hWndHeader, -2, buffer);
430 ok(res == 0, "Getting Out of Range item should fail with 0 (%d), got %s\n", res,buffer);
432 if (winetest_interactive)
434 UpdateWindow(hHeaderParentWnd);
435 UpdateWindow(hWndHeader);
438 TEST_GET_ITEMCOUNT(6);
439 res=setItem(hWndHeader, 99, str_items[5], FALSE);
440 ok(res == 0, "Setting Out of Range item should fail with 0 (%d)\n", res);
441 res=setItem(hWndHeader, 5, str_items[5], TRUE);
442 ok(res == 1, "Setting Out of Range item should fail with 1 (%d)\n", res);
443 res=setItem(hWndHeader, -2, str_items[5], FALSE);
444 ok(res == 0, "Setting Out of Range item should fail with 0 (%d)\n", res);
445 TEST_GET_ITEMCOUNT(6);
447 for (i = 0; i < 4; i++)
449 res = setItem(hWndHeader, i, str_items[4], TRUE);
450 ok(res != 0, "Setting %d item failed (%d)\n", i+1, res);
452 TEST_GET_ITEMCOUNT(6);
455 SendMessageA(hWndHeader, HDM_SETUNICODEFORMAT, (WPARAM)TRUE, 0);
456 setItemUnicodeNotify(hWndHeader, 3, pszUniTestA, pszUniTestW);
457 SendMessageA(hWndHeader, WM_NOTIFYFORMAT, (WPARAM)hHeaderParentWnd, (LPARAM)NF_REQUERY);
458 setItem(hWndHeader, 3, str_items[4], TRUE);
460 dont_expect_notify(HDN_GETDISPINFOA);
461 dont_expect_notify(HDN_GETDISPINFOW);
462 addItem(hWndHeader, 0, LPSTR_TEXTCALLBACKA);
463 setItem(hWndHeader, 0, str_items[4], TRUE);
464 /* unexpected notifies cleared by notifies_received in setItem */
465 dont_expect_notify(HDN_GETDISPINFOA);
466 dont_expect_notify(HDN_GETDISPINFOW);
467 setItem(hWndHeader, 0, LPSTR_TEXTCALLBACKA, TRUE);
468 /* unexpected notifies cleared by notifies_received in setItem */
469 delItem(hWndHeader, 0);
472 TEST_GET_ITEMCOUNT(6);
474 TEST_GET_ITEMCOUNT(6);
476 TEST_GET_ITEMCOUNT(6);
478 res = delItem(hWndHeader, 5);
479 ok(res == 1, "Deleting Out of Range item should fail with 1 (%d)\n", res);
480 res = delItem(hWndHeader, -2);
481 ok(res == 0, "Deleting Out of Range item should fail with 0 (%d)\n", res);
482 TEST_GET_ITEMCOUNT(5);
484 res = delItem(hWndHeader, 3);
485 ok(res != 0, "Deleting using out of range index failed (%d)\n", res);
486 TEST_GET_ITEMCOUNT(4);
487 res = delItem(hWndHeader, 0);
488 ok(res != 0, "Deleting using out of range index failed (%d)\n", res);
489 TEST_GET_ITEMCOUNT(3);
490 res = delItem(hWndHeader, 0);
491 ok(res != 0, "Deleting using out of range index failed (%d)\n", res);
492 TEST_GET_ITEMCOUNT(2);
493 res = delItem(hWndHeader, 0);
494 ok(res != 0, "Deleting using out of range index failed (%d)\n", res);
495 TEST_GET_ITEMCOUNT(1);
497 DestroyWindow(hWndHeader);
500 static void test_hdm_getitemrect(void)
502 /* Afer the setorderarray is called, item with index 0 becomes
503 * the 2nd item and item with index 1 becomes 1st item
507 retVal = SendMessage(hWndHeader, HDM_GETITEMRECT, 0, (LPARAM) &rect);
508 ok(retVal == TRUE, "Getting item rect should TRUE, got %d\n", retVal);
509 /* check bounding rectangle information */
510 expect(80, rect.left);
512 expect(160, rect.right);
513 expect(18, rect.bottom);
515 retVal = SendMessage(hWndHeader, HDM_GETITEMRECT, 1, (LPARAM) &rect);
516 ok(retVal == TRUE, "Getting item rect should TRUE, got %d\n", retVal);
517 /* check bounding rectangle information */
518 expect(0, rect.left);
520 expect(80, rect.right);
521 expect(18, rect.bottom);
522 retVal = SendMessage(hWndHeader, HDM_GETITEMRECT, 10, (LPARAM) &rect);
523 ok(retVal == 0, "Getting rect of nonexistent item should return 0, got %d\n", retVal);
526 static void test_hdm_layout (void)
532 hdLayout.prc = ▭
533 hdLayout.pwpos = &windowPos;
534 retVal = SendMessage(hWndHeader, HDM_LAYOUT, 0, (LPARAM) &hdLayout);
535 expect(TRUE, retVal);
538 static void test_hdm_ordertoindex (void)
541 retVal = SendMessage(hWndHeader, HDM_ORDERTOINDEX, 1, 0);
545 static void test_hdm_hittest (void)
549 HDHITTESTINFO hdHitTestInfo;
550 const int firstItemMaxRight = 80;
551 const int secondItemMaxRight = 160;
552 const int maxBottom = 18;
553 /* Afer the setorderarray is called, item with index 0 becomes
554 * the 2nd item and item with index 1 becomes 1st item
556 pt.x = firstItemMaxRight - 1;
557 pt.y = maxBottom - 1;
558 hdHitTestInfo.pt = pt;
559 retVal = SendMessage(hWndHeader, HDM_HITTEST, 0, (LPARAM) &hdHitTestInfo);
561 expect(1, hdHitTestInfo.iItem);
563 pt.x = secondItemMaxRight - 1;
564 pt.y = maxBottom - 1;
565 hdHitTestInfo.pt = pt;
566 retVal = SendMessage(hWndHeader, HDM_HITTEST, 0, (LPARAM) &hdHitTestInfo);
568 expect(0, hdHitTestInfo.iItem);
570 pt.x = secondItemMaxRight;
571 pt.y = maxBottom + 1;
572 hdHitTestInfo.pt = pt;
575 retVal = SendMessage(hWndHeader, HDM_HITTEST, 0, (LPARAM) &hdHitTestInfo);
580 static void test_hdm_sethotdivider (void)
583 /* low word: x coordinate = 5
584 * high word: y coordinate = 5
588 retVal = SendMessage(hWndHeader, HDM_SETHOTDIVIDER, TRUE, (LPARAM) 0X00050005);
591 retVal = SendMessage(hWndHeader, HDM_SETHOTDIVIDER, FALSE, 100);
593 retVal = SendMessage(hWndHeader, HDM_SETHOTDIVIDER, FALSE, 1);
597 static void test_hdm_imageMessages (void)
599 HIMAGELIST hImageList = ImageList_Create (4, 4, 0, 1, 0);
600 HIMAGELIST hImageListRetVal;
601 hImageListRetVal = (HIMAGELIST) SendMessage(hWndHeader, HDM_SETIMAGELIST, 0, (LPARAM) hImageList);
602 ok(hImageListRetVal == NULL, "Expected NULL, got %d\n", (int) hImageListRetVal);
603 hImageListRetVal = (HIMAGELIST) SendMessage(hWndHeader, HDM_GETIMAGELIST, 0, 0);
604 ok(hImageListRetVal != NULL, "Expected non-NULL handle, got %d\n", (int) hImageListRetVal);
605 hImageListRetVal = (HIMAGELIST) SendMessage(hWndHeader, HDM_CREATEDRAGIMAGE, 0, 0);
606 ok(hImageListRetVal != NULL, "Expected non-NULL handle, got %d\n", (int) hImageListRetVal);
609 static void test_hdm_filterMessages (void)
614 /* msdn incorrecly states that return value
615 * is the index of the filter control being
616 * modified. The sendMessage here should
617 * return previous filter timeout value
619 retVal = SendMessage(hWndHeader, HDM_SETFILTERCHANGETIMEOUT, 1, 100);
620 expect(1000, retVal);
621 retVal = SendMessage(hWndHeader, HDM_CLEARFILTER, 0, 1);
623 retVal = SendMessage(hWndHeader, HDM_EDITFILTER, 1, 0);
628 static void test_hdm_unicodeformatMessages (void)
631 retVal = SendMessage(hWndHeader, HDM_SETUNICODEFORMAT, TRUE, 0);
633 retVal = SendMessage(hWndHeader, HDM_GETUNICODEFORMAT, 0, 0);
637 static void test_hdm_bitmapmarginMessages (void)
640 retVal = SendMessage(hWndHeader, HDM_GETBITMAPMARGIN, 0, 0);
644 static void test_hdm_index_messages (void)
650 static const int lpiarray[2] = {1, 0};
651 static int lpiarrayReceived[2];
652 static char firstHeaderItem[] = "Name";
653 static char secondHeaderItem[] = "Size";
654 static char thirdHeaderItem[] = "Type";
655 static char fourthHeaderItem[] = "Data Modified";
656 static char *items[] = {firstHeaderItem, secondHeaderItem, thirdHeaderItem, fourthHeaderItem};
658 hdItem.mask = HDI_TEXT | HDI_WIDTH | HDI_FORMAT;
659 hdItem.fmt = HDF_LEFT;
661 hdItem.cchTextMax = 260;
662 hWndHeader = create_header_control();
663 for ( loopcnt = 0 ; loopcnt < 4 ; loopcnt++ )
665 hdItem.pszText = items[loopcnt];
666 retVal = SendMessage(hWndHeader, HDM_INSERTITEM, loopcnt, (LPARAM) &hdItem);
667 ok(retVal == loopcnt, "Adding item %d failed with return value %d\n", ( loopcnt + 1 ), retVal);
670 retVal = SendMessage(hWndHeader, HDM_DELETEITEM, 3, (LPARAM) &hdItem);
671 ok(retVal == TRUE, "Deleting item 3 should return TRUE, got %d\n", retVal);
672 retVal = SendMessage(hWndHeader, HDM_GETITEMCOUNT, 0, (LPARAM) &hdItem);
673 ok(retVal == 3, "Getting item count should return 3, got %d\n", retVal);
675 retVal = SendMessage(hWndHeader, HDM_DELETEITEM, 3, (LPARAM) &hdItem);
676 ok(retVal == FALSE, "Deleting already-deleted item should return FALSE, got %d\n", retVal);
677 retVal = SendMessage(hWndHeader, HDM_GETITEMCOUNT, 0, (LPARAM) &hdItem);
678 ok(retVal == 3, "Getting item count should return 3, got %d\n", retVal);
680 retVal = SendMessage(hWndHeader, HDM_DELETEITEM, 2, (LPARAM) &hdItem);
681 ok(retVal == TRUE, "Deleting item 2 should return TRUE, got %d\n", retVal);
682 retVal = SendMessage(hWndHeader, HDM_GETITEMCOUNT, 0, (LPARAM) &hdItem);
683 ok(retVal == 2, "Getting item count should return 2, got %d\n", retVal);
685 retVal = SendMessage(hWndHeader, HDM_GETITEM, 3, (LPARAM) &hdItem);
686 ok(retVal == FALSE, "Getting already-deleted item should return FALSE, got %d\n", retVal);
688 retVal = SendMessage(hWndHeader, HDM_GETITEM, 0, (LPARAM) &hdItem);
689 ok(retVal == TRUE, "Getting the 1st header item should return TRUE, got %d\n", retVal);
690 /* check if the item is the right one */
691 strcmpResult = strcmp(hdItem.pszText, firstHeaderItem);
692 expect(0, strcmpResult);
693 expect(80, hdItem.cxy);
695 iSize = SendMessage(hWndHeader, HDM_GETITEMCOUNT, 0, (LPARAM) &hdItem);
696 retVal = SendMessage(hWndHeader, HDM_SETORDERARRAY, (WPARAM) iSize , (LPARAM) (LPINT) lpiarray );
697 ok(retVal == TRUE, "Setting header items order should return TRUE, got %d\n", retVal);
698 retVal = SendMessage(hWndHeader, HDM_GETORDERARRAY, (WPARAM) iSize, (LPARAM) (LPINT) lpiarrayReceived );
699 ok(retVal == TRUE, "Getting header items order should return TRUE, got %d\n", retVal);
700 /* check if the array order is set correctly and the size of the array is corret. */
702 expect(lpiarray[0], lpiarrayReceived[0]);
703 expect(lpiarray[1], lpiarrayReceived[1]);
705 hdItem.mask = HDI_FORMAT;
706 hdItem.fmt = HDF_CENTER | HDF_STRING;
707 retVal = SendMessage(hWndHeader, HDM_SETITEM, 0, (LPARAM) &hdItem);
708 ok(retVal == TRUE, "Aligning 1st header item to center should return TRUE, got %d\n", retVal);
709 hdItem.fmt = HDF_RIGHT | HDF_STRING;
710 retVal = SendMessage(hWndHeader, HDM_SETITEM, 1, (LPARAM) &hdItem);
711 ok(retVal == TRUE, "Aligning 2nd header item to right should return TRUE, got %d\n", retVal);
714 static void test_header_messages (void)
717 test_hdm_index_messages();
718 test_hdm_getitemrect();
721 test_hdm_ordertoindex();
722 test_hdm_sethotdivider();
724 test_hdm_imageMessages();
725 test_hdm_filterMessages();
726 test_hdm_unicodeformatMessages();
727 test_hdm_bitmapmarginMessages();
730 #define TEST_NMCUSTOMDRAW(draw_stage, item_spec, lparam, _left, _top, _right, _bottom) \
731 ok(nm->dwDrawStage == draw_stage, "Invalid dwDrawStage %d vs %d\n", draw_stage, nm->dwDrawStage); \
732 if (item_spec != -1) \
733 ok(nm->dwItemSpec == item_spec, "Invalid dwItemSpec %d vs %ld\n", item_spec, nm->dwItemSpec); \
734 ok(nm->lItemlParam == lparam, "Invalid lItemlParam %d vs %ld\n", lparam, nm->lItemlParam); \
735 ok(nm->rc.top == _top && nm->rc.bottom == _bottom && nm->rc.left == _left && nm->rc.right == _right, \
736 "Invalid rect (%d,%d) (%d,%d) vs (%d,%d) (%d,%d)\n", _left, _top, _right, _bottom, \
737 nm->rc.left, nm->rc.top, nm->rc.right, nm->rc.bottom);
739 static LRESULT customdraw_1(int n, NMCUSTOMDRAW *nm)
741 if (nm == NULL) { /* test ended */
742 ok(n==1, "NM_CUSTOMDRAW messages: %d, expected: 1\n", n);
749 /* don't test dwItemSpec - it's 0 no comctl5 but 1308756 on comctl6 */
750 TEST_NMCUSTOMDRAW(CDDS_PREPAINT, -1, 0, 0, 0, 670, 18);
754 ok(FALSE, "To many custom draw messages (n=%d, nm->dwDrawStage=%d)\n", n, nm->dwDrawStage);
758 static LRESULT customdraw_2(int n, NMCUSTOMDRAW *nm)
760 if (nm == NULL) { /* test ended */
761 ok(n==4, "NM_CUSTOMDRAW messages: %d, expected: 4\n", n);
768 TEST_NMCUSTOMDRAW(CDDS_PREPAINT, -1, 0, 0, 0, 670, 18);
769 return CDRF_NOTIFYITEMDRAW;
771 TEST_NMCUSTOMDRAW(CDDS_ITEMPREPAINT, 0, 0, 0, 0, 50, 18);
774 TEST_NMCUSTOMDRAW(CDDS_ITEMPREPAINT, 1, 5, 50, 0, 150, 18);
777 TEST_NMCUSTOMDRAW(CDDS_ITEMPREPAINT, 2, 10, 150, 0, 300, 18);
781 ok(FALSE, "To many custom draw messages (n=%d, nm->dwDrawStage=%d)\n", n, nm->dwDrawStage);
785 static LRESULT customdraw_3(int n, NMCUSTOMDRAW *nm)
787 if (nm == NULL) { /* test ended */
788 ok(n==5, "NM_CUSTOMDRAW messages: %d, expected: 5\n", n);
795 TEST_NMCUSTOMDRAW(CDDS_PREPAINT, -1, 0, 0, 0, 670, 18);
796 return CDRF_NOTIFYITEMDRAW|CDRF_NOTIFYPOSTERASE|CDRF_NOTIFYPOSTPAINT|CDRF_SKIPDEFAULT;
798 TEST_NMCUSTOMDRAW(CDDS_ITEMPREPAINT, 0, 0, 0, 0, 50, 18);
801 TEST_NMCUSTOMDRAW(CDDS_ITEMPREPAINT, 1, 5, 50, 0, 150, 18);
804 TEST_NMCUSTOMDRAW(CDDS_ITEMPREPAINT, 2, 10, 150, 0, 300, 18);
807 TEST_NMCUSTOMDRAW(CDDS_POSTPAINT, -1, 0, 0, 0, 670, 18);
811 ok(FALSE, "To many custom draw messages (n=%d, nm->dwDrawStage=%d)\n", n, nm->dwDrawStage);
816 static LRESULT customdraw_4(int n, NMCUSTOMDRAW *nm)
818 if (nm == NULL) { /* test ended */
819 ok(n==4, "NM_CUSTOMDRAW messages: %d, expected: 4\n", n);
826 TEST_NMCUSTOMDRAW(CDDS_PREPAINT, -1, 0, 0, 0, 670, 18);
827 return CDRF_NOTIFYITEMDRAW|CDRF_NOTIFYPOSTPAINT;
829 TEST_NMCUSTOMDRAW(CDDS_ITEMPREPAINT, 0, 0, 0, 0, 50, 18);
832 TEST_NMCUSTOMDRAW(CDDS_ITEMPREPAINT, 2, 10, 150, 0, 300, 18);
835 TEST_NMCUSTOMDRAW(CDDS_POSTPAINT, -1, 0, 0, 0, 670, 18);
839 ok(FALSE, "To many custom draw messages (n=%d, nm->dwDrawStage=%d)\n", n, nm->dwDrawStage);
843 static void run_customdraw_scenario(CUSTOMDRAWPROC proc)
845 g_CustomDrawProc = proc;
846 g_CustomDrawCount = 0;
847 InvalidateRect(hWndHeader, NULL, TRUE);
848 UpdateWindow(hWndHeader);
849 proc(g_CustomDrawCount, NULL);
850 g_CustomDrawProc = NULL;
853 static void test_customdraw(void)
858 CHAR name[] = "Test";
859 hWndHeader = create_header_control();
860 GetClientRect(hWndHeader, &rect);
861 ok(rect.right - rect.left == 670 && rect.bottom - rect.top == 18,
862 "Tests will fail as header size is %dx%d instead of 670x18\n",
863 rect.right - rect.left == 670, rect.bottom - rect.top == 18);
865 for (i = 0; i < 3; i++)
867 ZeroMemory(&item, sizeof(item));
868 item.mask = HDI_TEXT|HDI_WIDTH;
872 SendMessage(hWndHeader, HDM_INSERTITEM, i, (LPARAM)&item);
875 run_customdraw_scenario(customdraw_1);
876 run_customdraw_scenario(customdraw_2);
877 run_customdraw_scenario(customdraw_3);
879 ZeroMemory(&item, sizeof(item));
880 item.mask = HDI_FORMAT;
881 item.fmt = HDF_OWNERDRAW;
882 SendMessage(hWndHeader, HDM_SETITEM, 1, (LPARAM)&item);
883 g_DrawItem.CtlID = 0;
884 g_DrawItem.CtlType = ODT_HEADER;
885 g_DrawItem.hwndItem = hWndHeader;
886 g_DrawItem.itemID = 1;
887 g_DrawItem.itemState = 0;
888 SendMessage(hWndHeader, HDM_GETITEMRECT, 1, (LPARAM)&g_DrawItem.rcItem);
889 run_customdraw_scenario(customdraw_4);
890 ok(g_DrawItemReceived, "WM_DRAWITEM not received\n");
891 DestroyWindow(hWndHeader);
893 g_DrawItem.CtlType = 0;
894 g_DrawItemReceived = FALSE;
897 static void check_order(const int expected_id[], const int expected_order[],
898 int count, const char *type)
903 ok(getItemCount(hWndHeader) == count, "Invalid item count in order tests\n");
904 for (i = 0; i < count; i++)
906 hdi.mask = HDI_LPARAM|HDI_ORDER;
907 SendMessage(hWndHeader, HDM_GETITEMA, i, (LPARAM)&hdi);
908 ok(hdi.lParam == expected_id[i],
909 "Invalid item ids after '%s'- item %d has lParam %d\n", type, i, (int)hdi.lParam);
910 ok(hdi.iOrder == expected_order[i],
911 "Invalid item order after '%s'- item %d has iOrder %d\n", type, i, hdi.iOrder);
915 static void test_header_order (void)
917 const int rand1[] = {0, 1, 1, 0, 4};
918 const int rand2[] = {4, 5, 6, 7, 4};
919 const int rand3[] = {5, 5, 1, 6, 1};
920 const int rand4[] = {1, 5, 2, 7, 6, 1, 4, 2, 3, 2};
921 const int rand5[] = {7, 8, 5, 6, 7, 2, 1, 9, 10, 10};
922 const int rand6[] = {2, 8, 3, 4, 0};
924 const int ids1[] = {3, 0, 2, 1, 4};
925 const int ord1[] = {0, 1, 2, 3, 4};
926 const int ids2[] = {3, 9, 7, 0, 2, 1, 4, 8, 6, 5};
927 const int ord2[] = {0, 4, 7, 1, 2, 3, 9, 8, 6, 5};
928 const int ord3[] = {0, 3, 9, 2, 1, 8, 7, 6, 5, 4};
929 const int ids4[] = {9, 0, 1, 8, 6};
930 const int ord4[] = {1, 0, 4, 3, 2};
936 hWndHeader = create_header_control();
938 ZeroMemory(&hdi, sizeof(HDITEMA));
939 hdi.mask = HDI_TEXT | HDI_LPARAM;
940 hdi.pszText = buffer;
941 strcpy(buffer, "test");
943 for (i = 0; i < 5; i++)
946 SendMessage(hWndHeader, HDM_INSERTITEMA, rand1[i], (LPARAM)&hdi);
949 check_order(ids1, ord1, 5, "insert without iOrder");
951 hdi.mask |= HDI_ORDER;
952 for (i = 0; i < 5; i++)
955 hdi.iOrder = rand2[i];
956 SendMessage(hWndHeader, HDM_INSERTITEMA, rand3[i], (LPARAM)&hdi);
959 check_order(ids2, ord2, 10, "insert with order");
961 hdi.mask = HDI_ORDER;
964 hdi.iOrder = rand5[i];
965 SendMessage(hWndHeader, HDM_SETITEMA, rand4[i], (LPARAM)&hdi);
968 check_order(ids2, ord3, 10, "setitems changing order");
971 SendMessage(hWndHeader, HDM_DELETEITEM, rand6[i], 0);
972 check_order(ids4, ord4, 5, "deleteitem");
974 DestroyWindow(hWndHeader);
977 static LRESULT CALLBACK HeaderTestWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
984 NMHEADERA *hdr = (NMHEADER *)lParam;
985 EXPECTEDNOTIFY *expected;
988 if (hdr->hdr.code == NM_CUSTOMDRAW)
989 if (g_CustomDrawProc)
990 return g_CustomDrawProc(g_CustomDrawCount++, (NMCUSTOMDRAW*)hdr);
992 for (i=0; i<nUnexpectedNotify; i++)
993 ok(hdr->hdr.code != unexpectedNotify[i], "Received invalid notify %d\n", hdr->hdr.code);
995 if (nReceivedNotify >= nExpectedNotify || hdr->hdr.hwndFrom != hWndHeader )
998 expected = &expectedNotify[nReceivedNotify];
999 if (hdr->hdr.code != expected->iCode)
1003 compare_items(hdr->hdr.code, &expected->hdItem, hdr->pitem, expected->fUnicode);
1008 di = (DRAWITEMSTRUCT *)lParam;
1009 ok(g_DrawItem.CtlType != 0, "Unexpected WM_DRAWITEM\n");
1010 if (g_DrawItem.CtlType == 0) return 0;
1011 g_DrawItemReceived = TRUE;
1012 compare(di->CtlType, g_DrawItem.CtlType, "%d");
1013 compare(di->CtlID, g_DrawItem.CtlID, "%d");
1014 compare(di->hwndItem, g_DrawItem.hwndItem, "%p");
1015 compare(di->itemID, g_DrawItem.itemID, "%d");
1016 compare(di->itemState, g_DrawItem.itemState, "%d");
1017 compare(di->rcItem.left, g_DrawItem.rcItem.left, "%d");
1018 compare(di->rcItem.top, g_DrawItem.rcItem.top, "%d");
1019 compare(di->rcItem.right, g_DrawItem.rcItem.right, "%d");
1020 compare(di->rcItem.bottom, g_DrawItem.rcItem.bottom, "%d");
1028 return DefWindowProcA(hWnd, msg, wParam, lParam);
1034 static void init(void) {
1036 INITCOMMONCONTROLSEX icex;
1038 icex.dwSize = sizeof(INITCOMMONCONTROLSEX);
1039 icex.dwICC = ICC_USEREX_CLASSES;
1040 InitCommonControlsEx(&icex);
1042 wc.style = CS_HREDRAW | CS_VREDRAW;
1045 wc.hInstance = GetModuleHandleA(NULL);
1047 wc.hCursor = LoadCursorA(NULL, MAKEINTRESOURCEA(IDC_ARROW));
1048 wc.hbrBackground = GetSysColorBrush(COLOR_WINDOW);
1049 wc.lpszMenuName = NULL;
1050 wc.lpszClassName = "HeaderTestClass";
1051 wc.lpfnWndProc = HeaderTestWndProc;
1052 RegisterClassA(&wc);
1054 hHeaderParentWnd = CreateWindowExA(0, "HeaderTestClass", "Header test", WS_OVERLAPPEDWINDOW,
1055 CW_USEDEFAULT, CW_USEDEFAULT, 672+2*GetSystemMetrics(SM_CXSIZEFRAME),
1056 226+GetSystemMetrics(SM_CYCAPTION)+2*GetSystemMetrics(SM_CYSIZEFRAME),
1057 NULL, NULL, GetModuleHandleA(NULL), 0);
1058 assert(hHeaderParentWnd != NULL);
1059 ShowWindow(hHeaderParentWnd, SW_SHOW);
1066 test_header_control();
1067 test_header_order();
1069 test_header_messages();
1071 DestroyWindow(hHeaderParentWnd);