1 /* Unit test suite for header control.
3 * Copyright 2005 Vijay Kiran Kamuju
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 #include "wine/test.h"
27 typedef struct tagEXPECTEDNOTIFY
34 typedef LRESULT (*CUSTOMDRAWPROC)(int n, NMCUSTOMDRAW *nm);
36 static CUSTOMDRAWPROC g_CustomDrawProc;
37 static int g_CustomDrawCount;
38 static DRAWITEMSTRUCT g_DrawItem;
39 static BOOL g_DrawItemReceived;
41 static EXPECTEDNOTIFY expectedNotify[10];
42 static INT nExpectedNotify = 0;
43 static INT nReceivedNotify = 0;
44 static INT unexpectedNotify[10];
45 static INT nUnexpectedNotify = 0;
47 static HWND hHeaderParentWnd;
48 static HWND hWndHeader;
51 #define compare(val, exp, fmt) ok((val) == (exp), #val " value: " fmt ", expected: " fmt "\n", (val), (exp))
53 static void expect_notify(INT iCode, BOOL fUnicode, HDITEMA *lpItem)
55 assert(nExpectedNotify < 10);
56 expectedNotify[nExpectedNotify].iCode = iCode;
57 expectedNotify[nExpectedNotify].fUnicode = fUnicode;
58 expectedNotify[nExpectedNotify].hdItem = *lpItem;
62 static void dont_expect_notify(INT iCode)
64 assert(nUnexpectedNotify < 10);
65 unexpectedNotify[nUnexpectedNotify++] = iCode;
68 static BOOL notifies_received(void)
70 BOOL fRet = (nExpectedNotify == nReceivedNotify);
71 nExpectedNotify = nReceivedNotify = 0;
72 nUnexpectedNotify = 0;
76 static LONG addItem(HWND hdex, int idx, LPSTR text)
79 hdItem.mask = HDI_TEXT | HDI_WIDTH;
81 hdItem.pszText = text;
82 hdItem.cchTextMax = 0;
83 return (LONG)SendMessage(hdex, HDM_INSERTITEMA, (WPARAM)idx, (LPARAM)&hdItem);
86 static LONG setItem(HWND hdex, int idx, LPSTR text, BOOL fCheckNotifies)
90 hdexItem.mask = HDI_TEXT;
91 hdexItem.pszText = text;
92 hdexItem.cchTextMax = 0;
95 expect_notify(HDN_ITEMCHANGINGA, FALSE, &hdexItem);
96 expect_notify(HDN_ITEMCHANGEDA, FALSE, &hdexItem);
98 ret = (LONG)SendMessage(hdex, HDM_SETITEMA, (WPARAM)idx, (LPARAM)&hdexItem);
100 ok(notifies_received(), "setItem(): not all expected notifies were received\n");
104 static LONG setItemUnicodeNotify(HWND hdex, int idx, LPSTR text, LPWSTR wText)
109 hdexItem.mask = HDI_TEXT;
110 hdexItem.pszText = text;
111 hdexItem.cchTextMax = 0;
113 hdexNotify.mask = HDI_TEXT;
114 hdexNotify.pszText = wText;
116 expect_notify(HDN_ITEMCHANGINGW, TRUE, (HDITEMA*)&hdexNotify);
117 expect_notify(HDN_ITEMCHANGEDW, TRUE, (HDITEMA*)&hdexNotify);
118 ret = (LONG)SendMessage(hdex, HDM_SETITEMA, (WPARAM)idx, (LPARAM)&hdexItem);
119 ok(notifies_received(), "setItemUnicodeNotify(): not all expected notifies were received\n");
123 static LONG delItem(HWND hdex, int idx)
125 return (LONG)SendMessage(hdex, HDM_DELETEITEM, (WPARAM)idx, 0);
128 static LONG getItemCount(HWND hdex)
130 return (LONG)SendMessage(hdex, HDM_GETITEMCOUNT, 0, 0);
133 static LONG getItem(HWND hdex, int idx, LPSTR textBuffer)
136 hdItem.mask = HDI_TEXT;
137 hdItem.pszText = textBuffer;
138 hdItem.cchTextMax = MAX_CHARS;
139 return (LONG)SendMessage(hdex, HDM_GETITEMA, (WPARAM)idx, (LPARAM)&hdItem);
142 static void addReadDelItem(HWND hdex, HDITEMA *phdiCreate, int maskRead, HDITEMA *phdiRead)
144 ok(SendMessage(hdex, HDM_INSERTITEMA, (WPARAM)0, (LPARAM)phdiCreate)!=-1, "Adding item failed\n");
145 ZeroMemory(phdiRead, sizeof(HDITEMA));
146 phdiRead->mask = maskRead;
147 ok(SendMessage(hdex, HDM_GETITEMA, (WPARAM)0, (LPARAM)phdiRead)!=0, "Getting item data failed\n");
148 ok(SendMessage(hdex, HDM_DELETEITEM, (WPARAM)0, (LPARAM)0)!=0, "Deleting item failed\n");
151 static HWND create_header_control (void)
158 handle = CreateWindowEx(0, WC_HEADER, NULL,
159 WS_CHILD|WS_BORDER|WS_VISIBLE|HDS_BUTTONS|HDS_HORZ,
161 hHeaderParentWnd, NULL, NULL, NULL);
164 if (winetest_interactive)
165 ShowWindow (hHeaderParentWnd, SW_SHOW);
167 GetClientRect(hHeaderParentWnd,&rectwin);
168 hlayout.prc = &rectwin;
169 hlayout.pwpos = &winpos;
170 SendMessageA(handle,HDM_LAYOUT,0,(LPARAM) &hlayout);
171 SetWindowPos(handle, winpos.hwndInsertAfter, winpos.x, winpos.y,
172 winpos.cx, winpos.cy, 0);
177 static void compare_items(INT iCode, HDITEMA *hdi1, HDITEMA *hdi2, BOOL fUnicode)
179 ok(hdi1->mask == hdi2->mask, "Notify %d mask mismatch (%08x != %08x)\n", iCode, hdi1->mask, hdi2->mask);
180 if (hdi1->mask & HDI_WIDTH)
182 ok(hdi1->cxy == hdi2->cxy, "Notify %d cxy mismatch (%08x != %08x)\n", iCode, hdi1->cxy, hdi2->cxy);
184 if (hdi1->mask & HDI_TEXT)
186 if (hdi1->pszText == LPSTR_TEXTCALLBACKA)
188 ok(hdi1->pszText == LPSTR_TEXTCALLBACKA, "Notify %d - only one item is LPSTR_TEXTCALLBACK\n", iCode);
195 WideCharToMultiByte(CP_ACP, 0, (LPCWSTR)hdi1->pszText, -1, buf1, 260, NULL, NULL);
196 WideCharToMultiByte(CP_ACP, 0, (LPCWSTR)hdi2->pszText, -1, buf2, 260, NULL, NULL);
197 ok(lstrcmpW((LPWSTR)hdi1->pszText, (LPWSTR)hdi2->pszText)==0,
198 "Notify %d text mismatch (L\"%s\" vs L\"%s\")\n",
203 ok(strcmp(hdi1->pszText, hdi2->pszText)==0,
204 "Notify %d text mismatch (\"%s\" vs \"%s\")\n",
205 iCode, hdi1->pszText, hdi2->pszText);
210 static char pszFirstItem[] = "First Item";
211 static char pszSecondItem[] = "Second Item";
212 static char pszThirdItem[] = "Third Item";
213 static char pszFourthItem[] = "Fourth Item";
214 static char pszReplaceItem[] = "Replace Item";
215 static char pszOutOfRangeItem[] = "Out Of Range Item";
217 static char *str_items[] =
218 {pszFirstItem, pszSecondItem, pszThirdItem, pszFourthItem, pszReplaceItem, pszOutOfRangeItem};
220 static char pszUniTestA[] = "TST";
221 static WCHAR pszUniTestW[] = {'T','S','T',0};
224 #define TEST_GET_ITEM(i,c)\
225 { res = getItem(hWndHeader, i, buffer);\
226 ok(res != 0, "Getting item[%d] using valid index failed unexpectedly (%d)\n", i, res);\
227 ok(strcmp(str_items[c], buffer) == 0, "Getting item[%d] returned \"%s\" expecting \"%s\"\n", i, buffer, str_items[c]);\
230 #define TEST_GET_ITEMCOUNT(i)\
231 { res = getItemCount(hWndHeader);\
232 ok(res == i, "Got Item Count as %d\n", res);\
235 static void check_auto_format(void)
239 static CHAR text[] = "Test";
240 ZeroMemory(&hdiCreate, sizeof(HDITEMA));
242 /* Windows implicitly sets some format bits in INSERTITEM */
244 /* HDF_STRING is automatically set and cleared for no text */
245 hdiCreate.mask = HDI_TEXT|HDI_WIDTH|HDI_FORMAT;
246 hdiCreate.pszText = text;
248 hdiCreate.fmt=HDF_CENTER;
249 addReadDelItem(hWndHeader, &hdiCreate, HDI_FORMAT, &hdiRead);
250 ok(hdiRead.fmt == (HDF_STRING|HDF_CENTER), "HDF_STRING not set automatically (fmt=%x)\n", hdiRead.fmt);
252 hdiCreate.mask = HDI_WIDTH|HDI_FORMAT;
253 hdiCreate.pszText = text;
254 hdiCreate.fmt = HDF_CENTER|HDF_STRING;
255 addReadDelItem(hWndHeader, &hdiCreate, HDI_FORMAT, &hdiRead);
256 ok(hdiRead.fmt == (HDF_CENTER), "HDF_STRING should be automatically cleared (fmt=%x)\n", hdiRead.fmt);
258 /* HDF_BITMAP is automatically set and cleared for a NULL bitmap or no bitmap */
259 hdiCreate.mask = HDI_BITMAP|HDI_WIDTH|HDI_FORMAT;
260 hdiCreate.hbm = CreateBitmap(16, 16, 1, 8, NULL);
261 hdiCreate.fmt = HDF_CENTER;
262 addReadDelItem(hWndHeader, &hdiCreate, HDI_FORMAT, &hdiRead);
263 ok(hdiRead.fmt == (HDF_BITMAP|HDF_CENTER), "HDF_BITMAP not set automatically (fmt=%x)\n", hdiRead.fmt);
264 DeleteObject(hdiCreate.hbm);
266 hdiCreate.hbm = NULL;
267 hdiCreate.fmt = HDF_CENTER|HDF_BITMAP;
268 addReadDelItem(hWndHeader, &hdiCreate, HDI_FORMAT, &hdiRead);
269 ok(hdiRead.fmt == HDF_CENTER, "HDF_BITMAP not cleared automatically for NULL bitmap (fmt=%x)\n", hdiRead.fmt);
271 hdiCreate.mask = HDI_WIDTH|HDI_FORMAT;
272 hdiCreate.fmt = HDF_CENTER|HDF_BITMAP;
273 addReadDelItem(hWndHeader, &hdiCreate, HDI_FORMAT, &hdiRead);
274 ok(hdiRead.fmt == HDF_CENTER, "HDF_BITMAP not cleared automatically for no bitmap (fmt=%x)\n", hdiRead.fmt);
276 /* HDF_IMAGE is automatically set but not cleared */
277 hdiCreate.mask = HDI_IMAGE|HDI_WIDTH|HDI_FORMAT;
278 hdiCreate.iImage = 17;
279 addReadDelItem(hWndHeader, &hdiCreate, HDI_FORMAT, &hdiRead);
280 ok(hdiRead.fmt == (HDF_IMAGE|HDF_CENTER), "HDF_IMAGE not set automatically (fmt=%x)\n", hdiRead.fmt);
282 hdiCreate.mask = HDI_WIDTH|HDI_FORMAT;
283 hdiCreate.fmt = HDF_CENTER|HDF_IMAGE;
284 hdiCreate.iImage = 0;
285 addReadDelItem(hWndHeader, &hdiCreate, HDI_FORMAT, &hdiRead);
286 ok(hdiRead.fmt == (HDF_CENTER|HDF_IMAGE), "HDF_IMAGE shouldn't be cleared automatically (fmt=%x)\n", hdiRead.fmt);
289 static void check_auto_fields(void)
293 static CHAR text[] = "Test";
296 /* Windows stores the format, width, lparam even if they are not in the item's mask */
297 ZeroMemory(&hdiCreate, sizeof(HDITEMA));
298 hdiCreate.mask = HDI_TEXT;
300 hdiCreate.pszText = text;
301 addReadDelItem(hWndHeader, &hdiCreate, HDI_WIDTH, &hdiRead);
302 TEST_GET_ITEMCOUNT(6);
303 ok(hdiRead.cxy == hdiCreate.cxy, "cxy should be automatically set\n");
305 ZeroMemory(&hdiCreate, sizeof(HDITEMA));
306 hdiCreate.mask = HDI_TEXT;
307 hdiCreate.pszText = text;
308 hdiCreate.lParam = 0x12345678;
309 addReadDelItem(hWndHeader, &hdiCreate, HDI_LPARAM, &hdiRead);
310 TEST_GET_ITEMCOUNT(6);
311 ok(hdiRead.lParam == hdiCreate.lParam, "lParam should be automatically set\n");
313 ZeroMemory(&hdiCreate, sizeof(HDITEMA));
314 hdiCreate.mask = HDI_TEXT;
315 hdiCreate.pszText = text;
316 hdiCreate.fmt = HDF_STRING|HDF_CENTER;
317 addReadDelItem(hWndHeader, &hdiCreate, HDI_FORMAT, &hdiRead);
318 TEST_GET_ITEMCOUNT(6);
319 ok(hdiRead.fmt == hdiCreate.fmt, "fmt should be automatically set\n");
321 /* others fields are not set */
322 ZeroMemory(&hdiCreate, sizeof(HDITEMA));
323 hdiCreate.mask = HDI_TEXT;
324 hdiCreate.pszText = text;
325 hdiCreate.hbm = CreateBitmap(16, 16, 1, 8, NULL);
326 addReadDelItem(hWndHeader, &hdiCreate, HDI_BITMAP, &hdiRead);
327 TEST_GET_ITEMCOUNT(6);
328 ok(hdiRead.hbm == NULL, "hbm should not be automatically set\n");
329 DeleteObject(hdiCreate.hbm);
331 ZeroMemory(&hdiCreate, sizeof(HDITEMA));
332 hdiCreate.mask = HDI_IMAGE;
333 hdiCreate.iImage = 17;
334 hdiCreate.pszText = text;
335 addReadDelItem(hWndHeader, &hdiCreate, HDI_TEXT, &hdiRead);
336 TEST_GET_ITEMCOUNT(6);
337 ok(hdiRead.pszText==NULL, "pszText shouldn't be automatically set\n");
339 /* field from comctl >4.0 not tested as the system probably won't touch them */
342 static void check_mask(void)
345 static CHAR text[] = "ABC";
348 /* don't create items if the mask is zero */
349 ZeroMemory(&hdi, sizeof(hdi));
356 hdi.cchTextMax = 260;
357 ret = SendMessage(hWndHeader, HDM_INSERTITEM, (WPARAM)0, (LPARAM)&hdi);
358 ok(ret == -1, "Creating an item with a zero mask should have failed\n");
359 if (ret != -1) SendMessage(hWndHeader, HDM_DELETEITEM, (WPARAM)0, (LPARAM)0);
361 /* with a non-zero mask creation will succeed */
362 ZeroMemory(&hdi, sizeof(hdi));
363 hdi.mask = HDI_LPARAM;
364 ret = SendMessage(hWndHeader, HDM_INSERTITEM, (WPARAM)0, (LPARAM)&hdi);
365 ok(ret != -1, "Adding item with non-zero mask failed\n");
367 SendMessage(hWndHeader, HDM_DELETEITEM, (WPARAM)0, (LPARAM)0);
369 /* in SETITEM if the mask contains a unknown bit, it is ignored */
370 ZeroMemory(&hdi, sizeof(hdi));
371 hdi.mask = 0x08000000 | HDI_LPARAM | HDI_IMAGE;
374 ret = SendMessage(hWndHeader, HDM_INSERTITEM, (WPARAM)0, (LPARAM)&hdi);
375 ok(ret != -1, "Adding item failed\n");
380 ZeroMemory(&hdi, sizeof(hdi));
381 hdi.mask = HDI_LPARAM | HDI_IMAGE;
382 SendMessage(hWndHeader, HDM_GETITEM, (WPARAM)0, (LPARAM)&hdi);
383 ok(hdi.lParam == 133, "comctl32 4.0 field not set\n");
384 ok(hdi.iImage == 17, "comctl32 >4.0 field not set\n");
386 /* but in GETITEM if an unknown bit is set, comctl32 uses only version 4.0 fields */
387 ZeroMemory(&hdi, sizeof(hdi));
388 hdi.mask = 0x08000000 | HDI_LPARAM | HDI_IMAGE;
389 SendMessage(hWndHeader, HDM_GETITEM, (WPARAM)0, (LPARAM)&hdi);
390 ok(hdi.lParam == 133, "comctl32 4.0 field not read\n");
391 ok(hdi.iImage == 0, "comctl32 >4.0 field shouldn't be read\n");
393 SendMessage(hWndHeader, HDM_DELETEITEM, (WPARAM)0, (LPARAM)0);
397 static void test_header_control (void)
400 static char buffer[MAX_CHARS];
403 hWndHeader = create_header_control ();
405 for (i = 3; i >= 0; i--)
407 TEST_GET_ITEMCOUNT(3-i);
408 res = addItem(hWndHeader, 0, str_items[i]);
409 ok(res == 0, "Adding simple item failed (%d)\n", res);
412 TEST_GET_ITEMCOUNT(4);
413 res = addItem(hWndHeader, 99, str_items[i+1]);
414 ok(res != -1, "Adding Out of Range item should fail with -1 got (%d)\n", res);
415 TEST_GET_ITEMCOUNT(5);
416 res = addItem(hWndHeader, 5, 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(6);
420 for (i = 0; i < 4; i++) { TEST_GET_ITEM(i,i); TEST_GET_ITEMCOUNT(6); }
422 res=getItem(hWndHeader, 99, buffer);
423 ok(res == 0, "Getting Out of Range item should fail with 0 (%d), got %s\n", res,buffer);
424 res=getItem(hWndHeader, 5, buffer);
425 ok(res == 1, "Getting Out of Range item should fail with 1 (%d), got %s\n", res,buffer);
426 res=getItem(hWndHeader, -2, buffer);
427 ok(res == 0, "Getting Out of Range item should fail with 0 (%d), got %s\n", res,buffer);
429 if (winetest_interactive)
431 UpdateWindow(hHeaderParentWnd);
432 UpdateWindow(hWndHeader);
435 TEST_GET_ITEMCOUNT(6);
436 res=setItem(hWndHeader, 99, str_items[5], FALSE);
437 ok(res == 0, "Setting Out of Range item should fail with 0 (%d)\n", res);
438 res=setItem(hWndHeader, 5, str_items[5], TRUE);
439 ok(res == 1, "Setting Out of Range item should fail with 1 (%d)\n", res);
440 res=setItem(hWndHeader, -2, str_items[5], FALSE);
441 ok(res == 0, "Setting Out of Range item should fail with 0 (%d)\n", res);
442 TEST_GET_ITEMCOUNT(6);
444 for (i = 0; i < 4; i++)
446 res = setItem(hWndHeader, i, str_items[4], TRUE);
447 ok(res != 0, "Setting %d item failed (%d)\n", i+1, res);
449 TEST_GET_ITEMCOUNT(6);
452 SendMessageA(hWndHeader, HDM_SETUNICODEFORMAT, (WPARAM)TRUE, 0);
453 setItemUnicodeNotify(hWndHeader, 3, pszUniTestA, pszUniTestW);
454 SendMessageA(hWndHeader, WM_NOTIFYFORMAT, (WPARAM)hHeaderParentWnd, (LPARAM)NF_REQUERY);
455 setItem(hWndHeader, 3, str_items[4], TRUE);
457 dont_expect_notify(HDN_GETDISPINFOA);
458 dont_expect_notify(HDN_GETDISPINFOW);
459 addItem(hWndHeader, 0, LPSTR_TEXTCALLBACKA);
460 setItem(hWndHeader, 0, str_items[4], TRUE);
461 /* unexpected notifies cleared by notifies_received in setItem */
462 dont_expect_notify(HDN_GETDISPINFOA);
463 dont_expect_notify(HDN_GETDISPINFOW);
464 setItem(hWndHeader, 0, LPSTR_TEXTCALLBACKA, TRUE);
465 /* unexpected notifies cleared by notifies_received in setItem */
466 delItem(hWndHeader, 0);
469 TEST_GET_ITEMCOUNT(6);
471 TEST_GET_ITEMCOUNT(6);
473 TEST_GET_ITEMCOUNT(6);
475 res = delItem(hWndHeader, 5);
476 ok(res == 1, "Deleting Out of Range item should fail with 1 (%d)\n", res);
477 res = delItem(hWndHeader, -2);
478 ok(res == 0, "Deleting Out of Range item should fail with 0 (%d)\n", res);
479 TEST_GET_ITEMCOUNT(5);
481 res = delItem(hWndHeader, 3);
482 ok(res != 0, "Deleting using out of range index failed (%d)\n", res);
483 TEST_GET_ITEMCOUNT(4);
484 res = delItem(hWndHeader, 0);
485 ok(res != 0, "Deleting using out of range index failed (%d)\n", res);
486 TEST_GET_ITEMCOUNT(3);
487 res = delItem(hWndHeader, 0);
488 ok(res != 0, "Deleting using out of range index failed (%d)\n", res);
489 TEST_GET_ITEMCOUNT(2);
490 res = delItem(hWndHeader, 0);
491 ok(res != 0, "Deleting using out of range index failed (%d)\n", res);
492 TEST_GET_ITEMCOUNT(1);
494 DestroyWindow(hWndHeader);
498 #define TEST_NMCUSTOMDRAW(draw_stage, item_spec, lparam, _left, _top, _right, _bottom) \
499 ok(nm->dwDrawStage == draw_stage, "Invalid dwDrawStage %d vs %d\n", draw_stage, nm->dwDrawStage); \
500 if (item_spec != -1) \
501 ok(nm->dwItemSpec == item_spec, "Invalid dwItemSpec %d vs %ld\n", item_spec, nm->dwItemSpec); \
502 ok(nm->lItemlParam == lparam, "Invalid lItemlParam %d vs %ld\n", lparam, nm->lItemlParam); \
503 ok(nm->rc.top == _top && nm->rc.bottom == _bottom && nm->rc.left == _left && nm->rc.right == _right, \
504 "Invalid rect (%d,%d) (%d,%d) vs (%d,%d) (%d,%d)\n", _left, _top, _right, _bottom, \
505 nm->rc.left, nm->rc.top, nm->rc.right, nm->rc.bottom);
507 static LRESULT customdraw_1(int n, NMCUSTOMDRAW *nm)
509 if (nm == NULL) { /* test ended */
510 ok(n==1, "NM_CUSTOMDRAW messages: %d, expected: 1\n", n);
517 /* don't test dwItemSpec - it's 0 no comctl5 but 1308756 on comctl6 */
518 TEST_NMCUSTOMDRAW(CDDS_PREPAINT, -1, 0, 0, 0, 670, 18);
522 ok(FALSE, "To many custom draw messages (n=%d, nm->dwDrawStage=%d)\n", n, nm->dwDrawStage);
526 static LRESULT customdraw_2(int n, NMCUSTOMDRAW *nm)
528 if (nm == NULL) { /* test ended */
529 ok(n==4, "NM_CUSTOMDRAW messages: %d, expected: 4\n", n);
536 TEST_NMCUSTOMDRAW(CDDS_PREPAINT, -1, 0, 0, 0, 670, 18);
537 return CDRF_NOTIFYITEMDRAW;
539 TEST_NMCUSTOMDRAW(CDDS_ITEMPREPAINT, 0, 0, 0, 0, 50, 18);
542 TEST_NMCUSTOMDRAW(CDDS_ITEMPREPAINT, 1, 5, 50, 0, 150, 18);
545 TEST_NMCUSTOMDRAW(CDDS_ITEMPREPAINT, 2, 10, 150, 0, 300, 18);
549 ok(FALSE, "To many custom draw messages (n=%d, nm->dwDrawStage=%d)\n", n, nm->dwDrawStage);
553 static LRESULT customdraw_3(int n, NMCUSTOMDRAW *nm)
555 if (nm == NULL) { /* test ended */
556 ok(n==5, "NM_CUSTOMDRAW messages: %d, expected: 5\n", n);
563 TEST_NMCUSTOMDRAW(CDDS_PREPAINT, -1, 0, 0, 0, 670, 18);
564 return CDRF_NOTIFYITEMDRAW|CDRF_NOTIFYPOSTERASE|CDRF_NOTIFYPOSTPAINT|CDRF_SKIPDEFAULT;
566 TEST_NMCUSTOMDRAW(CDDS_ITEMPREPAINT, 0, 0, 0, 0, 50, 18);
569 TEST_NMCUSTOMDRAW(CDDS_ITEMPREPAINT, 1, 5, 50, 0, 150, 18);
572 TEST_NMCUSTOMDRAW(CDDS_ITEMPREPAINT, 2, 10, 150, 0, 300, 18);
575 TEST_NMCUSTOMDRAW(CDDS_POSTPAINT, -1, 0, 0, 0, 670, 18);
579 ok(FALSE, "To many custom draw messages (n=%d, nm->dwDrawStage=%d)\n", n, nm->dwDrawStage);
584 static LRESULT customdraw_4(int n, NMCUSTOMDRAW *nm)
586 if (nm == NULL) { /* test ended */
587 ok(n==4, "NM_CUSTOMDRAW messages: %d, expected: 4\n", n);
594 TEST_NMCUSTOMDRAW(CDDS_PREPAINT, -1, 0, 0, 0, 670, 18);
595 return CDRF_NOTIFYITEMDRAW|CDRF_NOTIFYPOSTPAINT;
597 TEST_NMCUSTOMDRAW(CDDS_ITEMPREPAINT, 0, 0, 0, 0, 50, 18);
600 TEST_NMCUSTOMDRAW(CDDS_ITEMPREPAINT, 2, 10, 150, 0, 300, 18);
603 TEST_NMCUSTOMDRAW(CDDS_POSTPAINT, -1, 0, 0, 0, 670, 18);
607 ok(FALSE, "To many custom draw messages (n=%d, nm->dwDrawStage=%d)\n", n, nm->dwDrawStage);
611 static void run_customdraw_scenario(CUSTOMDRAWPROC proc)
613 g_CustomDrawProc = proc;
614 g_CustomDrawCount = 0;
615 InvalidateRect(hWndHeader, NULL, TRUE);
616 UpdateWindow(hWndHeader);
617 proc(g_CustomDrawCount, NULL);
618 g_CustomDrawProc = NULL;
621 static void test_customdraw(void)
626 CHAR name[] = "Test";
627 hWndHeader = create_header_control();
628 GetClientRect(hWndHeader, &rect);
629 ok(rect.right - rect.left == 670 && rect.bottom - rect.top == 18,
630 "Tests will fail as header size is %dx%d instead of 670x18\n",
631 rect.right - rect.left == 670, rect.bottom - rect.top == 18);
633 for (i = 0; i < 3; i++)
635 ZeroMemory(&item, sizeof(item));
636 item.mask = HDI_TEXT|HDI_WIDTH;
640 SendMessage(hWndHeader, HDM_INSERTITEM, i, (LPARAM)&item);
643 run_customdraw_scenario(customdraw_1);
644 run_customdraw_scenario(customdraw_2);
645 run_customdraw_scenario(customdraw_3);
647 ZeroMemory(&item, sizeof(item));
648 item.mask = HDI_FORMAT;
649 item.fmt = HDF_OWNERDRAW;
650 SendMessage(hWndHeader, HDM_SETITEM, 1, (LPARAM)&item);
651 g_DrawItem.CtlID = 0;
652 g_DrawItem.CtlType = ODT_HEADER;
653 g_DrawItem.hwndItem = hWndHeader;
654 g_DrawItem.itemID = 1;
655 g_DrawItem.itemState = 0;
656 SendMessage(hWndHeader, HDM_GETITEMRECT, 1, (LPARAM)&g_DrawItem.rcItem);
657 run_customdraw_scenario(customdraw_4);
658 ok(g_DrawItemReceived, "WM_DRAWITEM not received\n");
659 DestroyWindow(hWndHeader);
661 g_DrawItem.CtlType = 0;
662 g_DrawItemReceived = FALSE;
665 static void check_order(const int expected_id[], const int expected_order[],
666 int count, const char *type)
671 ok(getItemCount(hWndHeader) == count, "Invalid item count in order tests\n");
672 for (i = 0; i < count; i++)
674 hdi.mask = HDI_LPARAM|HDI_ORDER;
675 SendMessage(hWndHeader, HDM_GETITEMA, i, (LPARAM)&hdi);
676 ok(hdi.lParam == expected_id[i],
677 "Invalid item ids after '%s'- item %d has lParam %d\n", type, i, (int)hdi.lParam);
678 ok(hdi.iOrder == expected_order[i],
679 "Invalid item order after '%s'- item %d has iOrder %d\n", type, i, hdi.iOrder);
683 static void test_header_order (void)
685 const int rand1[] = {0, 1, 1, 0, 4};
686 const int rand2[] = {4, 5, 6, 7, 4};
687 const int rand3[] = {5, 5, 1, 6, 1};
688 const int rand4[] = {1, 5, 2, 7, 6, 1, 4, 2, 3, 2};
689 const int rand5[] = {7, 8, 5, 6, 7, 2, 1, 9, 10, 10};
690 const int rand6[] = {2, 8, 3, 4, 0};
692 const int ids1[] = {3, 0, 2, 1, 4};
693 const int ord1[] = {0, 1, 2, 3, 4};
694 const int ids2[] = {3, 9, 7, 0, 2, 1, 4, 8, 6, 5};
695 const int ord2[] = {0, 4, 7, 1, 2, 3, 9, 8, 6, 5};
696 const int ord3[] = {0, 3, 9, 2, 1, 8, 7, 6, 5, 4};
697 const int ids4[] = {9, 0, 1, 8, 6};
698 const int ord4[] = {1, 0, 4, 3, 2};
704 hWndHeader = create_header_control();
706 ZeroMemory(&hdi, sizeof(HDITEMA));
707 hdi.mask = HDI_TEXT | HDI_LPARAM;
708 hdi.pszText = buffer;
709 strcpy(buffer, "test");
711 for (i = 0; i < 5; i++)
714 SendMessage(hWndHeader, HDM_INSERTITEMA, rand1[i], (LPARAM)&hdi);
717 check_order(ids1, ord1, 5, "insert without iOrder");
719 hdi.mask |= HDI_ORDER;
720 for (i = 0; i < 5; i++)
723 hdi.iOrder = rand2[i];
724 SendMessage(hWndHeader, HDM_INSERTITEMA, rand3[i], (LPARAM)&hdi);
727 check_order(ids2, ord2, 10, "insert with order");
729 hdi.mask = HDI_ORDER;
732 hdi.iOrder = rand5[i];
733 SendMessage(hWndHeader, HDM_SETITEMA, rand4[i], (LPARAM)&hdi);
736 check_order(ids2, ord3, 10, "setitems changing order");
739 SendMessage(hWndHeader, HDM_DELETEITEM, rand6[i], 0);
740 check_order(ids4, ord4, 5, "deleteitem");
742 DestroyWindow(hWndHeader);
745 static LRESULT CALLBACK HeaderTestWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
752 NMHEADERA *hdr = (NMHEADER *)lParam;
753 EXPECTEDNOTIFY *expected;
756 if (hdr->hdr.code == NM_CUSTOMDRAW)
757 if (g_CustomDrawProc)
758 return g_CustomDrawProc(g_CustomDrawCount++, (NMCUSTOMDRAW*)hdr);
760 for (i=0; i<nUnexpectedNotify; i++)
761 ok(hdr->hdr.code != unexpectedNotify[i], "Received invalid notify %d\n", hdr->hdr.code);
763 if (nReceivedNotify >= nExpectedNotify || hdr->hdr.hwndFrom != hWndHeader )
766 expected = &expectedNotify[nReceivedNotify];
767 if (hdr->hdr.code != expected->iCode)
771 compare_items(hdr->hdr.code, &expected->hdItem, hdr->pitem, expected->fUnicode);
776 di = (DRAWITEMSTRUCT *)lParam;
777 ok(g_DrawItem.CtlType != 0, "Unexpected WM_DRAWITEM\n");
778 if (g_DrawItem.CtlType == 0) return 0;
779 g_DrawItemReceived = TRUE;
780 compare(di->CtlType, g_DrawItem.CtlType, "%d");
781 compare(di->CtlID, g_DrawItem.CtlID, "%d");
782 compare(di->hwndItem, g_DrawItem.hwndItem, "%p");
783 compare(di->itemID, g_DrawItem.itemID, "%d");
784 compare(di->itemState, g_DrawItem.itemState, "%d");
785 compare(di->rcItem.left, g_DrawItem.rcItem.left, "%d");
786 compare(di->rcItem.top, g_DrawItem.rcItem.top, "%d");
787 compare(di->rcItem.right, g_DrawItem.rcItem.right, "%d");
788 compare(di->rcItem.bottom, g_DrawItem.rcItem.bottom, "%d");
796 return DefWindowProcA(hWnd, msg, wParam, lParam);
802 static void init(void) {
804 INITCOMMONCONTROLSEX icex;
806 icex.dwSize = sizeof(INITCOMMONCONTROLSEX);
807 icex.dwICC = ICC_USEREX_CLASSES;
808 InitCommonControlsEx(&icex);
810 wc.style = CS_HREDRAW | CS_VREDRAW;
813 wc.hInstance = GetModuleHandleA(NULL);
815 wc.hCursor = LoadCursorA(NULL, MAKEINTRESOURCEA(IDC_ARROW));
816 wc.hbrBackground = GetSysColorBrush(COLOR_WINDOW);
817 wc.lpszMenuName = NULL;
818 wc.lpszClassName = "HeaderTestClass";
819 wc.lpfnWndProc = HeaderTestWndProc;
822 hHeaderParentWnd = CreateWindowExA(0, "HeaderTestClass", "Header test", WS_OVERLAPPEDWINDOW,
823 CW_USEDEFAULT, CW_USEDEFAULT, 680, 260, NULL, NULL, GetModuleHandleA(NULL), 0);
824 assert(hHeaderParentWnd != NULL);
825 ShowWindow(hHeaderParentWnd, SW_SHOW);
832 test_header_control();
836 DestroyWindow(hHeaderParentWnd);