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 CUSTOMDRAWPROC g_CustomDrawProc;
37 int g_CustomDrawCount;
38 DRAWITEMSTRUCT g_DrawItem;
39 BOOL g_DrawItemReceived;
41 EXPECTEDNOTIFY expectedNotify[10];
42 INT nExpectedNotify = 0;
43 INT nReceivedNotify = 0;
44 INT unexpectedNotify[10];
45 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, LPCSTR text)
79 hdItem.mask = HDI_TEXT | HDI_WIDTH;
81 hdItem.pszText = (LPSTR)text;
82 hdItem.cchTextMax = 0;
83 return (LONG)SendMessage(hdex, HDM_INSERTITEMA, (WPARAM)idx, (LPARAM)&hdItem);
86 static LONG setItem(HWND hdex, int idx, LPCSTR text, BOOL fCheckNotifies)
90 hdexItem.mask = HDI_TEXT;
91 hdexItem.pszText = (LPSTR)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, LPCSTR text, LPCWSTR wText)
109 hdexItem.mask = HDI_TEXT;
110 hdexItem.pszText = (LPSTR)text;
111 hdexItem.cchTextMax = 0;
113 hdexNotify.mask = HDI_TEXT;
114 hdexNotify.pszText = (LPWSTR)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, "Deleteing 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 const char *str_items[] =
211 {"First Item", "Second Item", "Third Item", "Fourth Item", "Replace Item", "Out Of Range Item"};
213 static const char pszUniTestA[] = "TST";
214 static const WCHAR pszUniTestW[] = {'T','S','T',0};
217 #define TEST_GET_ITEM(i,c)\
218 { res = getItem(hWndHeader, i, buffer);\
219 ok(res != 0, "Getting item[%d] using valid index failed unexpectedly (%d)\n", i, res);\
220 ok(strcmp(str_items[c], buffer) == 0, "Getting item[%d] returned \"%s\" expecting \"%s\"\n", i, buffer, str_items[c]);\
223 #define TEST_GET_ITEMCOUNT(i)\
224 { res = getItemCount(hWndHeader);\
225 ok(res == i, "Got Item Count as %d\n", res);\
228 static void check_auto_format(void)
232 static CHAR text[] = "Test";
233 ZeroMemory(&hdiCreate, sizeof(HDITEMA));
235 /* Windows implicitly sets some format bits in INSERTITEM */
237 /* HDF_STRING is automatically set and cleared for no text */
238 hdiCreate.mask = HDI_TEXT|HDI_WIDTH|HDI_FORMAT;
239 hdiCreate.pszText = text;
241 hdiCreate.fmt=HDF_CENTER;
242 addReadDelItem(hWndHeader, &hdiCreate, HDI_FORMAT, &hdiRead);
243 ok(hdiRead.fmt == (HDF_STRING|HDF_CENTER), "HDF_STRING not set automatically (fmt=%x)\n", hdiRead.fmt);
245 hdiCreate.mask = HDI_WIDTH|HDI_FORMAT;
246 hdiCreate.pszText = text;
247 hdiCreate.fmt = HDF_CENTER|HDF_STRING;
248 addReadDelItem(hWndHeader, &hdiCreate, HDI_FORMAT, &hdiRead);
249 ok(hdiRead.fmt == (HDF_CENTER), "HDF_STRING should be automatically cleared (fmt=%x)\n", hdiRead.fmt);
251 /* HDF_BITMAP is automatically set and cleared for a NULL bitmap or no bitmap */
252 hdiCreate.mask = HDI_BITMAP|HDI_WIDTH|HDI_FORMAT;
253 hdiCreate.hbm = CreateBitmap(16, 16, 1, 8, NULL);
254 hdiCreate.fmt = HDF_CENTER;
255 addReadDelItem(hWndHeader, &hdiCreate, HDI_FORMAT, &hdiRead);
256 ok(hdiRead.fmt == (HDF_BITMAP|HDF_CENTER), "HDF_BITMAP not set automatically (fmt=%x)\n", hdiRead.fmt);
257 DeleteObject(hdiCreate.hbm);
259 hdiCreate.hbm = NULL;
260 hdiCreate.fmt = HDF_CENTER|HDF_BITMAP;
261 addReadDelItem(hWndHeader, &hdiCreate, HDI_FORMAT, &hdiRead);
262 ok(hdiRead.fmt == HDF_CENTER, "HDF_BITMAP not cleared automatically for NULL bitmap (fmt=%x)\n", hdiRead.fmt);
264 hdiCreate.mask = HDI_WIDTH|HDI_FORMAT;
265 hdiCreate.fmt = HDF_CENTER|HDF_BITMAP;
266 addReadDelItem(hWndHeader, &hdiCreate, HDI_FORMAT, &hdiRead);
267 ok(hdiRead.fmt == HDF_CENTER, "HDF_BITMAP not cleared automatically for no bitmap (fmt=%x)\n", hdiRead.fmt);
269 /* HDF_IMAGE is automatically set but not cleared */
270 hdiCreate.mask = HDI_IMAGE|HDI_WIDTH|HDI_FORMAT;
271 hdiCreate.iImage = 17;
272 addReadDelItem(hWndHeader, &hdiCreate, HDI_FORMAT, &hdiRead);
273 ok(hdiRead.fmt == (HDF_IMAGE|HDF_CENTER), "HDF_IMAGE not set automatically (fmt=%x)\n", hdiRead.fmt);
275 hdiCreate.mask = HDI_WIDTH|HDI_FORMAT;
276 hdiCreate.fmt = HDF_CENTER|HDF_IMAGE;
277 hdiCreate.iImage = 0;
278 addReadDelItem(hWndHeader, &hdiCreate, HDI_FORMAT, &hdiRead);
279 ok(hdiRead.fmt == (HDF_CENTER|HDF_IMAGE), "HDF_IMAGE shouldn't be cleared automatically (fmt=%x)\n", hdiRead.fmt);
282 static void check_auto_fields(void)
286 static CHAR text[] = "Test";
289 /* Windows stores the format, width, lparam even if they are not in the item's mask */
290 ZeroMemory(&hdiCreate, sizeof(HDITEMA));
291 hdiCreate.mask = HDI_TEXT;
293 hdiCreate.pszText = text;
294 addReadDelItem(hWndHeader, &hdiCreate, HDI_WIDTH, &hdiRead);
295 TEST_GET_ITEMCOUNT(6);
296 ok(hdiRead.cxy == hdiCreate.cxy, "cxy should be automatically set\n");
298 ZeroMemory(&hdiCreate, sizeof(HDITEMA));
299 hdiCreate.mask = HDI_TEXT;
300 hdiCreate.pszText = text;
301 hdiCreate.lParam = 0x12345678;
302 addReadDelItem(hWndHeader, &hdiCreate, HDI_LPARAM, &hdiRead);
303 TEST_GET_ITEMCOUNT(6);
304 ok(hdiRead.lParam == hdiCreate.lParam, "lParam should be automatically set\n");
306 ZeroMemory(&hdiCreate, sizeof(HDITEMA));
307 hdiCreate.mask = HDI_TEXT;
308 hdiCreate.pszText = text;
309 hdiCreate.fmt = HDF_STRING|HDF_CENTER;
310 addReadDelItem(hWndHeader, &hdiCreate, HDI_FORMAT, &hdiRead);
311 TEST_GET_ITEMCOUNT(6);
312 ok(hdiRead.fmt == hdiCreate.fmt, "fmt should be automatically set\n");
314 /* others fields are not set */
315 ZeroMemory(&hdiCreate, sizeof(HDITEMA));
316 hdiCreate.mask = HDI_TEXT;
317 hdiCreate.pszText = text;
318 hdiCreate.hbm = CreateBitmap(16, 16, 1, 8, NULL);
319 addReadDelItem(hWndHeader, &hdiCreate, HDI_BITMAP, &hdiRead);
320 TEST_GET_ITEMCOUNT(6);
321 ok(hdiRead.hbm == NULL, "hbm should not be automatically set\n");
322 DeleteObject(hdiCreate.hbm);
324 ZeroMemory(&hdiCreate, sizeof(HDITEMA));
325 hdiCreate.mask = HDI_IMAGE;
326 hdiCreate.iImage = 17;
327 hdiCreate.pszText = text;
328 addReadDelItem(hWndHeader, &hdiCreate, HDI_TEXT, &hdiRead);
329 TEST_GET_ITEMCOUNT(6);
330 ok(hdiRead.pszText==NULL, "pszText shouldn't be automatically set\n");
332 /* field from comctl >4.0 not tested as the system probably won't touch them */
335 static void check_mask(void)
338 static CHAR text[] = "ABC";
341 /* don't create items if the mask is zero */
342 ZeroMemory(&hdi, sizeof(hdi));
349 hdi.cchTextMax = 260;
350 ret = SendMessage(hWndHeader, HDM_INSERTITEM, (WPARAM)0, (LPARAM)&hdi);
351 ok(ret == -1, "Creating an item with a zero mask should have failed\n");
352 if (ret != -1) SendMessage(hWndHeader, HDM_DELETEITEM, (WPARAM)0, (LPARAM)0);
354 /* with a non-zero mask creation will succeed */
355 ZeroMemory(&hdi, sizeof(hdi));
356 hdi.mask = HDI_LPARAM;
357 ret = SendMessage(hWndHeader, HDM_INSERTITEM, (WPARAM)0, (LPARAM)&hdi);
358 ok(ret != -1, "Adding item with non-zero mask failed\n");
360 SendMessage(hWndHeader, HDM_DELETEITEM, (WPARAM)0, (LPARAM)0);
362 /* in SETITEM if the mask contains a unknown bit, it is ignored */
363 ZeroMemory(&hdi, sizeof(hdi));
364 hdi.mask = 0x08000000 | HDI_LPARAM | HDI_IMAGE;
367 ret = SendMessage(hWndHeader, HDM_INSERTITEM, (WPARAM)0, (LPARAM)&hdi);
368 ok(ret != -1, "Adding item failed\n");
373 ZeroMemory(&hdi, sizeof(hdi));
374 hdi.mask = HDI_LPARAM | HDI_IMAGE;
375 SendMessage(hWndHeader, HDM_GETITEM, (WPARAM)0, (LPARAM)&hdi);
376 ok(hdi.lParam == 133, "comctl32 4.0 field not set\n");
377 ok(hdi.iImage == 17, "comctl32 >4.0 field not set\n");
379 /* but in GETITEM if an unknown bit is set, comctl32 uses only version 4.0 fields */
380 ZeroMemory(&hdi, sizeof(hdi));
381 hdi.mask = 0x08000000 | HDI_LPARAM | HDI_IMAGE;
382 SendMessage(hWndHeader, HDM_GETITEM, (WPARAM)0, (LPARAM)&hdi);
383 ok(hdi.lParam == 133, "comctl32 4.0 field not read\n");
384 ok(hdi.iImage == 0, "comctl32 >4.0 field shouldn't be read\n");
386 SendMessage(hWndHeader, HDM_DELETEITEM, (WPARAM)0, (LPARAM)0);
390 static void test_header_control (void)
393 static char buffer[MAX_CHARS];
396 hWndHeader = create_header_control ();
398 for (i = 3; i >= 0; i--)
400 TEST_GET_ITEMCOUNT(3-i);
401 res = addItem(hWndHeader, 0, str_items[i]);
402 ok(res == 0, "Adding simple item failed (%d)\n", res);
405 TEST_GET_ITEMCOUNT(4);
406 res = addItem(hWndHeader, 99, str_items[i+1]);
407 ok(res != -1, "Adding Out of Range item should fail with -1 got (%d)\n", res);
408 TEST_GET_ITEMCOUNT(5);
409 res = addItem(hWndHeader, 5, str_items[i+1]);
410 ok(res != -1, "Adding Out of Range item should fail with -1 got (%d)\n", res);
411 TEST_GET_ITEMCOUNT(6);
413 for (i = 0; i < 4; i++) { TEST_GET_ITEM(i,i); TEST_GET_ITEMCOUNT(6); }
415 res=getItem(hWndHeader, 99, buffer);
416 ok(res == 0, "Getting Out of Range item should fail with 0 (%d), got %s\n", res,buffer);
417 res=getItem(hWndHeader, 5, buffer);
418 ok(res == 1, "Getting Out of Range item should fail with 1 (%d), got %s\n", res,buffer);
419 res=getItem(hWndHeader, -2, buffer);
420 ok(res == 0, "Getting Out of Range item should fail with 0 (%d), got %s\n", res,buffer);
422 if (winetest_interactive)
424 UpdateWindow(hHeaderParentWnd);
425 UpdateWindow(hWndHeader);
428 TEST_GET_ITEMCOUNT(6);
429 res=setItem(hWndHeader, 99, str_items[5], FALSE);
430 ok(res == 0, "Setting Out of Range item should fail with 0 (%d)\n", res);
431 res=setItem(hWndHeader, 5, str_items[5], TRUE);
432 ok(res == 1, "Setting Out of Range item should fail with 1 (%d)\n", res);
433 res=setItem(hWndHeader, -2, str_items[5], FALSE);
434 ok(res == 0, "Setting Out of Range item should fail with 0 (%d)\n", res);
435 TEST_GET_ITEMCOUNT(6);
437 for (i = 0; i < 4; i++)
439 res = setItem(hWndHeader, i, str_items[4], TRUE);
440 ok(res != 0, "Setting %d item failed (%d)\n", i+1, res);
442 TEST_GET_ITEMCOUNT(6);
445 SendMessageA(hWndHeader, HDM_SETUNICODEFORMAT, (WPARAM)TRUE, 0);
446 setItemUnicodeNotify(hWndHeader, 3, pszUniTestA, pszUniTestW);
447 SendMessageA(hWndHeader, WM_NOTIFYFORMAT, (WPARAM)hHeaderParentWnd, (LPARAM)NF_REQUERY);
448 setItem(hWndHeader, 3, str_items[4], TRUE);
450 dont_expect_notify(HDN_GETDISPINFOA);
451 dont_expect_notify(HDN_GETDISPINFOW);
452 addItem(hWndHeader, 0, LPSTR_TEXTCALLBACKA);
453 setItem(hWndHeader, 0, str_items[4], TRUE);
454 /* unexpected notifies cleared by notifies_received in setItem */
455 dont_expect_notify(HDN_GETDISPINFOA);
456 dont_expect_notify(HDN_GETDISPINFOW);
457 setItem(hWndHeader, 0, LPSTR_TEXTCALLBACKA, TRUE);
458 /* unexpected notifies cleared by notifies_received in setItem */
459 delItem(hWndHeader, 0);
462 TEST_GET_ITEMCOUNT(6);
464 TEST_GET_ITEMCOUNT(6);
466 TEST_GET_ITEMCOUNT(6);
468 res = delItem(hWndHeader, 5);
469 ok(res == 1, "Deleting Out of Range item should fail with 1 (%d)\n", res);
470 res = delItem(hWndHeader, -2);
471 ok(res == 0, "Deleting Out of Range item should fail with 0 (%d)\n", res);
472 TEST_GET_ITEMCOUNT(5);
474 res = delItem(hWndHeader, 3);
475 ok(res != 0, "Deleting using out of range index failed (%d)\n", res);
476 TEST_GET_ITEMCOUNT(4);
477 res = delItem(hWndHeader, 0);
478 ok(res != 0, "Deleting using out of range index failed (%d)\n", res);
479 TEST_GET_ITEMCOUNT(3);
480 res = delItem(hWndHeader, 0);
481 ok(res != 0, "Deleting using out of range index failed (%d)\n", res);
482 TEST_GET_ITEMCOUNT(2);
483 res = delItem(hWndHeader, 0);
484 ok(res != 0, "Deleting using out of range index failed (%d)\n", res);
485 TEST_GET_ITEMCOUNT(1);
487 DestroyWindow(hWndHeader);
491 #define TEST_NMCUSTOMDRAW(draw_stage, item_spec, lparam, _left, _top, _right, _bottom) \
492 ok(nm->dwDrawStage == draw_stage, "Invalid dwDrawStage %d vs %d\n", draw_stage, nm->dwDrawStage); \
493 if (item_spec != -1) \
494 ok(nm->dwItemSpec == item_spec, "Invalid dwItemSpec %d vs %ld\n", item_spec, nm->dwItemSpec); \
495 ok(nm->lItemlParam == lparam, "Invalid lItemlParam %d vs %ld\n", lparam, nm->lItemlParam); \
496 ok(nm->rc.top == _top && nm->rc.bottom == _bottom && nm->rc.left == _left && nm->rc.right == _right, \
497 "Invalid rect (%d,%d) (%d,%d) vs (%d,%d) (%d,%d)\n", _left, _top, _right, _bottom, \
498 nm->rc.left, nm->rc.top, nm->rc.right, nm->rc.bottom);
500 static LRESULT customdraw_1(int n, NMCUSTOMDRAW *nm)
502 if (nm == NULL) { /* test ended */
503 ok(n==1, "NM_CUSTOMDRAW messages: %d, expected: 1\n", n);
510 /* don't test dwItemSpec - it's 0 no comctl5 but 1308756 on comctl6 */
511 TEST_NMCUSTOMDRAW(CDDS_PREPAINT, -1, 0, 0, 0, 670, 18);
515 ok(FALSE, "To many custom draw messages (n=%d, nm->dwDrawStage=%d)\n", n, nm->dwDrawStage);
519 static LRESULT customdraw_2(int n, NMCUSTOMDRAW *nm)
521 if (nm == NULL) { /* test ended */
522 ok(n==4, "NM_CUSTOMDRAW messages: %d, expected: 4\n", n);
529 TEST_NMCUSTOMDRAW(CDDS_PREPAINT, -1, 0, 0, 0, 670, 18);
530 return CDRF_NOTIFYITEMDRAW;
532 TEST_NMCUSTOMDRAW(CDDS_ITEMPREPAINT, 0, 0, 0, 0, 50, 18);
535 TEST_NMCUSTOMDRAW(CDDS_ITEMPREPAINT, 1, 5, 50, 0, 150, 18);
538 TEST_NMCUSTOMDRAW(CDDS_ITEMPREPAINT, 2, 10, 150, 0, 300, 18);
542 ok(FALSE, "To many custom draw messages (n=%d, nm->dwDrawStage=%d)\n", n, nm->dwDrawStage);
546 static LRESULT customdraw_3(int n, NMCUSTOMDRAW *nm)
548 if (nm == NULL) { /* test ended */
549 ok(n==5, "NM_CUSTOMDRAW messages: %d, expected: 5\n", n);
556 TEST_NMCUSTOMDRAW(CDDS_PREPAINT, -1, 0, 0, 0, 670, 18);
557 return CDRF_NOTIFYITEMDRAW|CDRF_NOTIFYPOSTERASE|CDRF_NOTIFYPOSTPAINT|CDRF_SKIPDEFAULT;
559 TEST_NMCUSTOMDRAW(CDDS_ITEMPREPAINT, 0, 0, 0, 0, 50, 18);
562 TEST_NMCUSTOMDRAW(CDDS_ITEMPREPAINT, 1, 5, 50, 0, 150, 18);
565 TEST_NMCUSTOMDRAW(CDDS_ITEMPREPAINT, 2, 10, 150, 0, 300, 18);
568 TEST_NMCUSTOMDRAW(CDDS_POSTPAINT, -1, 0, 0, 0, 670, 18);
572 ok(FALSE, "To many custom draw messages (n=%d, nm->dwDrawStage=%d)\n", n, nm->dwDrawStage);
577 static LRESULT customdraw_4(int n, NMCUSTOMDRAW *nm)
579 if (nm == NULL) { /* test ended */
580 ok(n==4, "NM_CUSTOMDRAW messages: %d, expected: 4\n", n);
587 TEST_NMCUSTOMDRAW(CDDS_PREPAINT, -1, 0, 0, 0, 670, 18);
588 return CDRF_NOTIFYITEMDRAW|CDRF_NOTIFYPOSTPAINT;
590 TEST_NMCUSTOMDRAW(CDDS_ITEMPREPAINT, 0, 0, 0, 0, 50, 18);
593 TEST_NMCUSTOMDRAW(CDDS_ITEMPREPAINT, 2, 10, 150, 0, 300, 18);
596 TEST_NMCUSTOMDRAW(CDDS_POSTPAINT, -1, 0, 0, 0, 670, 18);
600 ok(FALSE, "To many custom draw messages (n=%d, nm->dwDrawStage=%d)\n", n, nm->dwDrawStage);
604 static void run_customdraw_scenario(CUSTOMDRAWPROC proc)
606 g_CustomDrawProc = proc;
607 g_CustomDrawCount = 0;
608 InvalidateRect(hWndHeader, NULL, TRUE);
609 UpdateWindow(hWndHeader);
610 proc(g_CustomDrawCount, NULL);
611 g_CustomDrawProc = NULL;
614 void test_customdraw()
619 CHAR name[] = "Test";
620 hWndHeader = create_header_control();
621 GetClientRect(hWndHeader, &rect);
622 ok(rect.right - rect.left == 670 && rect.bottom - rect.top == 18,
623 "Tests will fail as header size is %dx%d instead of 670x18\n",
624 rect.right - rect.left == 670, rect.bottom - rect.top == 18);
626 for (i = 0; i < 3; i++)
628 ZeroMemory(&item, sizeof(item));
629 item.mask = HDI_TEXT|HDI_WIDTH;
633 SendMessage(hWndHeader, HDM_INSERTITEM, i, (LPARAM)&item);
636 run_customdraw_scenario(customdraw_1);
637 run_customdraw_scenario(customdraw_2);
638 run_customdraw_scenario(customdraw_3);
640 ZeroMemory(&item, sizeof(item));
641 item.mask = HDI_FORMAT;
642 item.fmt = HDF_OWNERDRAW;
643 SendMessage(hWndHeader, HDM_SETITEM, 1, (LPARAM)&item);
644 g_DrawItem.CtlID = 0;
645 g_DrawItem.CtlType = ODT_HEADER;
646 g_DrawItem.hwndItem = hWndHeader;
647 g_DrawItem.itemID = 1;
648 g_DrawItem.itemState = 0;
649 SendMessage(hWndHeader, HDM_GETITEMRECT, 1, (LPARAM)&g_DrawItem.rcItem);
650 run_customdraw_scenario(customdraw_4);
651 ok(g_DrawItemReceived, "WM_DRAWITEM not received\n");
652 DestroyWindow(hWndHeader);
654 g_DrawItem.CtlType = 0;
655 g_DrawItemReceived = FALSE;
658 static void check_order(const int expected_id[], const int expected_order[],
659 int count, const char *type)
664 ok(getItemCount(hWndHeader) == count, "Invalid item count in order tests\n");
665 for (i = 0; i < count; i++)
667 hdi.mask = HDI_LPARAM|HDI_ORDER;
668 SendMessage(hWndHeader, HDM_GETITEMA, i, (LPARAM)&hdi);
669 ok(hdi.lParam == expected_id[i],
670 "Invalid item ids after '%s'- item %d has lParam %d\n", type, i, (int)hdi.lParam);
671 ok(hdi.iOrder == expected_order[i],
672 "Invalid item order after '%s'- item %d has iOrder %d\n", type, i, hdi.iOrder);
676 static void test_header_order (void)
678 const int rand1[] = {0, 1, 1, 0, 4};
679 const int rand2[] = {4, 5, 6, 7, 4};
680 const int rand3[] = {5, 5, 1, 6, 1};
681 const int rand4[] = {1, 5, 2, 7, 6, 1, 4, 2, 3, 2};
682 const int rand5[] = {7, 8, 5, 6, 7, 2, 1, 9, 10, 10};
683 const int rand6[] = {2, 8, 3, 4, 0};
685 const int ids1[] = {3, 0, 2, 1, 4};
686 const int ord1[] = {0, 1, 2, 3, 4};
687 const int ids2[] = {3, 9, 7, 0, 2, 1, 4, 8, 6, 5};
688 const int ord2[] = {0, 4, 7, 1, 2, 3, 9, 8, 6, 5};
689 const int ord3[] = {0, 3, 9, 2, 1, 8, 7, 6, 5, 4};
690 const int ids4[] = {9, 0, 1, 8, 6};
691 const int ord4[] = {1, 0, 4, 3, 2};
697 hWndHeader = create_header_control();
699 ZeroMemory(&hdi, sizeof(HDITEMA));
700 hdi.mask = HDI_TEXT | HDI_LPARAM;
701 hdi.pszText = buffer;
702 strcpy(buffer, "test");
704 for (i = 0; i < 5; i++)
707 SendMessage(hWndHeader, HDM_INSERTITEMA, rand1[i], (LPARAM)&hdi);
710 check_order(ids1, ord1, 5, "insert without iOrder");
712 hdi.mask |= HDI_ORDER;
713 for (i = 0; i < 5; i++)
716 hdi.iOrder = rand2[i];
717 SendMessage(hWndHeader, HDM_INSERTITEMA, rand3[i], (LPARAM)&hdi);
720 check_order(ids2, ord2, 10, "insert with order");
722 hdi.mask = HDI_ORDER;
725 hdi.iOrder = rand5[i];
726 SendMessage(hWndHeader, HDM_SETITEMA, rand4[i], (LPARAM)&hdi);
729 check_order(ids2, ord3, 10, "setitems changing order");
732 SendMessage(hWndHeader, HDM_DELETEITEM, rand6[i], 0);
733 check_order(ids4, ord4, 5, "deleteitem");
735 DestroyWindow(hWndHeader);
738 LRESULT CALLBACK HeaderTestWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
745 NMHEADERA *hdr = (NMHEADER *)lParam;
746 EXPECTEDNOTIFY *expected;
749 if (hdr->hdr.code == NM_CUSTOMDRAW)
750 if (g_CustomDrawProc)
751 return g_CustomDrawProc(g_CustomDrawCount++, (NMCUSTOMDRAW*)hdr);
753 for (i=0; i<nUnexpectedNotify; i++)
754 ok(hdr->hdr.code != unexpectedNotify[i], "Received invalid notify %d\n", hdr->hdr.code);
756 if (nReceivedNotify >= nExpectedNotify || hdr->hdr.hwndFrom != hWndHeader )
759 expected = &expectedNotify[nReceivedNotify];
760 if (hdr->hdr.code != expected->iCode)
764 compare_items(hdr->hdr.code, &expected->hdItem, hdr->pitem, expected->fUnicode);
769 di = (DRAWITEMSTRUCT *)lParam;
770 ok(g_DrawItem.CtlType != 0, "Unexpected WM_DRAWITEM\n");
771 if (g_DrawItem.CtlType == 0) return 0;
772 g_DrawItemReceived = TRUE;
773 compare(di->CtlType, g_DrawItem.CtlType, "%d");
774 compare(di->CtlID, g_DrawItem.CtlID, "%d");
775 compare(di->hwndItem, g_DrawItem.hwndItem, "%p");
776 compare(di->itemID, g_DrawItem.itemID, "%d");
777 compare(di->itemState, g_DrawItem.itemState, "%d");
778 compare(di->rcItem.left, g_DrawItem.rcItem.left, "%d");
779 compare(di->rcItem.top, g_DrawItem.rcItem.top, "%d");
780 compare(di->rcItem.right, g_DrawItem.rcItem.right, "%d");
781 compare(di->rcItem.bottom, g_DrawItem.rcItem.bottom, "%d");
789 return DefWindowProcA(hWnd, msg, wParam, lParam);
795 static void init(void) {
797 INITCOMMONCONTROLSEX icex;
799 icex.dwSize = sizeof(INITCOMMONCONTROLSEX);
800 icex.dwICC = ICC_USEREX_CLASSES;
801 InitCommonControlsEx(&icex);
803 wc.style = CS_HREDRAW | CS_VREDRAW;
806 wc.hInstance = GetModuleHandleA(NULL);
808 wc.hCursor = LoadCursorA(NULL, MAKEINTRESOURCEA(IDC_ARROW));
809 wc.hbrBackground = GetSysColorBrush(COLOR_WINDOW);
810 wc.lpszMenuName = NULL;
811 wc.lpszClassName = "HeaderTestClass";
812 wc.lpfnWndProc = HeaderTestWndProc;
815 hHeaderParentWnd = CreateWindowExA(0, "HeaderTestClass", "Header test", WS_OVERLAPPEDWINDOW,
816 CW_USEDEFAULT, CW_USEDEFAULT, 680, 260, NULL, NULL, GetModuleHandleA(NULL), 0);
817 assert(hHeaderParentWnd != NULL);
818 ShowWindow(hHeaderParentWnd, SW_SHOW);
825 test_header_control();
829 DestroyWindow(hHeaderParentWnd);