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
25 #include "wine/test.h"
29 typedef struct tagEXPECTEDNOTIFY
36 typedef LRESULT (*CUSTOMDRAWPROC
)(int n
, NMCUSTOMDRAW
*nm
);
38 static CUSTOMDRAWPROC g_CustomDrawProc
;
39 static int g_CustomDrawCount
;
40 static DRAWITEMSTRUCT g_DrawItem
;
41 static BOOL g_DrawItemReceived
;
42 static DWORD g_customheight
;
44 static EXPECTEDNOTIFY expectedNotify
[10];
45 static INT nExpectedNotify
= 0;
46 static INT nReceivedNotify
= 0;
47 static INT unexpectedNotify
[10];
48 static INT nUnexpectedNotify
= 0;
50 static HWND hHeaderParentWnd
;
51 static HWND hWndHeader
;
54 #define compare(val, exp, fmt) ok((val) == (exp), #val " value: " fmt ", expected: " fmt "\n", (val), (exp))
56 #define expect(expected, got) ok(expected == got, "expected %d, got %d\n", expected,got)
58 #define NUM_MSG_SEQUENCES 2
59 #define PARENT_SEQ_INDEX 0
60 #define HEADER_SEQ_INDEX 1
62 static struct msg_sequence
*sequences
[NUM_MSG_SEQUENCES
];
64 static const struct message create_parent_wnd_seq
[] = {
65 { WM_GETMINMAXINFO
, sent
},
66 { WM_NCCREATE
, sent
},
67 { WM_NCCALCSIZE
, sent
|wparam
, 0 },
72 static const struct message add_header_to_parent_seq_interactive
[] = {
73 { WM_NOTIFYFORMAT
, sent
|lparam
, 0, NF_QUERY
},
74 { WM_QUERYUISTATE
, sent
},
75 { WM_PARENTNOTIFY
, sent
|wparam
, 1 },
76 { WM_SHOWWINDOW
, sent
|wparam
, 1 },
77 { WM_WINDOWPOSCHANGING
, sent
|wparam
, 0 },
78 { WM_WINDOWPOSCHANGING
, sent
|wparam
, 0 },
79 { WM_ACTIVATEAPP
, sent
|wparam
, 1 },
80 { WM_NCACTIVATE
, sent
|wparam
, 1 },
81 { WM_ACTIVATE
, sent
|wparam
, 1 },
82 { WM_IME_SETCONTEXT
, sent
|defwinproc
|wparam
, 1 },
83 { WM_IME_NOTIFY
, sent
|defwinproc
|wparam
, 2 },
84 { WM_SETFOCUS
, sent
|defwinproc
|wparam
, 0 },
85 { WM_WINDOWPOSCHANGED
, sent
|wparam
, 0 },
86 { WM_SIZE
, sent
|wparam
, 0 },
87 { WM_MOVE
, sent
|wparam
, 0 },
91 static const struct message add_header_to_parent_seq
[] = {
92 { WM_NOTIFYFORMAT
, sent
|lparam
, 0, NF_QUERY
},
93 { WM_QUERYUISTATE
, sent
|optional
},
94 { WM_PARENTNOTIFY
, sent
},
98 static const struct message insertItem_seq
[] = {
99 { HDM_INSERTITEMA
, sent
|wparam
, 0 },
100 { HDM_INSERTITEMA
, sent
|wparam
, 1 },
101 { HDM_INSERTITEMA
, sent
|wparam
, 2 },
102 { HDM_INSERTITEMA
, sent
|wparam
, 3 },
106 static const struct message getItem_seq
[] = {
107 { HDM_GETITEMA
, sent
|wparam
, 3 },
108 { HDM_GETITEMA
, sent
|wparam
, 0 },
113 static const struct message deleteItem_getItemCount_seq
[] = {
114 { HDM_DELETEITEM
, sent
|wparam
, 3 },
115 { HDM_GETITEMCOUNT
, sent
},
116 { HDM_DELETEITEM
, sent
|wparam
, 3 },
117 { HDM_GETITEMCOUNT
, sent
},
118 { HDM_DELETEITEM
, sent
|wparam
, 2 },
119 { HDM_GETITEMCOUNT
, sent
},
123 static const struct message orderArray_seq
[] = {
124 { HDM_SETORDERARRAY
, sent
|wparam
, 2 },
125 { HDM_GETORDERARRAY
, sent
|wparam
, 2 },
129 static const struct message setItem_seq
[] = {
130 { HDM_SETITEMA
, sent
|wparam
, 0 },
131 { HDM_SETITEMA
, sent
|wparam
, 1 },
135 static const struct message getItemRect_seq
[] = {
136 { HDM_GETITEMRECT
, sent
|wparam
, 1 },
137 { HDM_GETITEMRECT
, sent
|wparam
, 0 },
138 { HDM_GETITEMRECT
, sent
|wparam
, 10 },
142 static const struct message layout_seq
[] = {
143 { HDM_LAYOUT
, sent
},
147 static const struct message orderToIndex_seq
[] = {
148 { HDM_ORDERTOINDEX
, sent
|wparam
, 1 },
152 static const struct message hittest_seq
[] = {
153 { HDM_HITTEST
, sent
},
154 { HDM_HITTEST
, sent
},
155 { HDM_HITTEST
, sent
},
159 static const struct message setHotDivider_seq_interactive
[] = {
160 { HDM_SETHOTDIVIDER
, sent
|wparam
, TRUE
},
161 { WM_PAINT
, sent
|defwinproc
},
162 { WM_NCPAINT
, sent
|defwinproc
},
163 { WM_ERASEBKGND
, sent
|defwinproc
},
164 { HDM_SETHOTDIVIDER
, sent
|wparam
|lparam
, FALSE
, 100 },
165 { WM_PAINT
, sent
|defwinproc
},
166 { HDM_SETHOTDIVIDER
, sent
|wparam
|lparam
, FALSE
, 1},
167 { WM_PAINT
, sent
|defwinproc
},
171 static const struct message setHotDivider_seq_noninteractive
[] = {
172 { HDM_SETHOTDIVIDER
, sent
|wparam
, TRUE
},
173 { HDM_SETHOTDIVIDER
, sent
|wparam
|lparam
, FALSE
, 100 },
174 { HDM_SETHOTDIVIDER
, sent
|wparam
|lparam
, FALSE
, 1},
178 static const struct message imageMessages_seq
[] = {
179 { HDM_SETIMAGELIST
, sent
},
180 { HDM_GETIMAGELIST
, sent
},
181 { HDM_CREATEDRAGIMAGE
, sent
},
185 static const struct message filterMessages_seq_interactive
[] = {
186 { HDM_SETFILTERCHANGETIMEOUT
, sent
|wparam
|lparam
, 1, 100 },
187 { HDM_CLEARFILTER
, sent
|wparam
|lparam
, 0, 1 },
188 { HDM_EDITFILTER
, sent
|wparam
|lparam
, 1, 0 },
189 { WM_PARENTNOTIFY
, sent
|wparam
|defwinproc
, WM_CREATE
},
190 { WM_CTLCOLOREDIT
, sent
|defwinproc
},
191 { WM_COMMAND
, sent
|defwinproc
},
195 static const struct message filterMessages_seq_noninteractive
[] = {
196 { HDM_SETFILTERCHANGETIMEOUT
, sent
|wparam
|lparam
, 1, 100 },
197 { HDM_CLEARFILTER
, sent
|wparam
|lparam
, 0, 1 },
198 { HDM_EDITFILTER
, sent
|wparam
|lparam
, 1, 0 },
199 { WM_PARENTNOTIFY
, sent
|wparam
|defwinproc
|optional
, WM_CREATE
},
200 { WM_COMMAND
, sent
|defwinproc
|optional
},
204 static const struct message unicodeformatMessages_seq
[] = {
205 { HDM_SETUNICODEFORMAT
, sent
|wparam
, TRUE
},
206 { HDM_GETUNICODEFORMAT
, sent
},
210 static const struct message bitmapmarginMessages_seq
[] = {
211 { HDM_GETBITMAPMARGIN
, sent
},
216 static void expect_notify(INT iCode
, BOOL fUnicode
, HDITEMA
*lpItem
)
218 ok(nExpectedNotify
< 10, "notification count %d\n", nExpectedNotify
);
219 if (nExpectedNotify
< 10)
221 expectedNotify
[nExpectedNotify
].iCode
= iCode
;
222 expectedNotify
[nExpectedNotify
].fUnicode
= fUnicode
;
223 expectedNotify
[nExpectedNotify
].hdItem
= *lpItem
;
228 static void dont_expect_notify(INT iCode
)
230 ok(nExpectedNotify
< 10, "notification count %d\n", nExpectedNotify
);
231 if (nExpectedNotify
< 10)
232 unexpectedNotify
[nUnexpectedNotify
++] = iCode
;
235 static BOOL
notifies_received(void)
237 BOOL fRet
= (nExpectedNotify
== nReceivedNotify
);
238 nExpectedNotify
= nReceivedNotify
= 0;
239 nUnexpectedNotify
= 0;
243 static LONG
addItem(HWND hdex
, int idx
, LPSTR text
)
246 hdItem
.mask
= HDI_TEXT
| HDI_WIDTH
;
248 hdItem
.pszText
= text
;
249 hdItem
.cchTextMax
= 0;
250 return SendMessageA(hdex
, HDM_INSERTITEMA
, idx
, (LPARAM
)&hdItem
);
253 static LONG
setItem(HWND hdex
, int idx
, LPSTR text
, BOOL fCheckNotifies
)
257 hdexItem
.mask
= HDI_TEXT
;
258 hdexItem
.pszText
= text
;
259 hdexItem
.cchTextMax
= 0;
262 expect_notify(HDN_ITEMCHANGINGA
, FALSE
, &hdexItem
);
263 expect_notify(HDN_ITEMCHANGEDA
, FALSE
, &hdexItem
);
265 ret
= SendMessageA(hdex
, HDM_SETITEMA
, idx
, (LPARAM
)&hdexItem
);
267 ok(notifies_received(), "setItem(): not all expected notifies were received\n");
271 static LONG
setItemUnicodeNotify(HWND hdex
, int idx
, LPSTR text
, LPWSTR wText
)
276 hdexItem
.mask
= HDI_TEXT
;
277 hdexItem
.pszText
= text
;
278 hdexItem
.cchTextMax
= 0;
280 hdexNotify
.mask
= HDI_TEXT
;
281 hdexNotify
.pszText
= wText
;
283 expect_notify(HDN_ITEMCHANGINGW
, TRUE
, (HDITEMA
*)&hdexNotify
);
284 expect_notify(HDN_ITEMCHANGEDW
, TRUE
, (HDITEMA
*)&hdexNotify
);
285 ret
= SendMessageA(hdex
, HDM_SETITEMA
, idx
, (LPARAM
)&hdexItem
);
286 ok(notifies_received(), "setItemUnicodeNotify(): not all expected notifies were received\n");
290 static LONG
delItem(HWND hdex
, int idx
)
292 return SendMessageA(hdex
, HDM_DELETEITEM
, idx
, 0);
295 static LONG
getItemCount(HWND hdex
)
297 return SendMessageA(hdex
, HDM_GETITEMCOUNT
, 0, 0);
300 static LONG
getItem(HWND hdex
, int idx
, LPSTR textBuffer
)
303 hdItem
.mask
= HDI_TEXT
;
304 hdItem
.pszText
= textBuffer
;
305 hdItem
.cchTextMax
= MAX_CHARS
;
306 return SendMessageA(hdex
, HDM_GETITEMA
, idx
, (LPARAM
)&hdItem
);
309 static void addReadDelItem(HWND hdex
, HDITEMA
*phdiCreate
, int maskRead
, HDITEMA
*phdiRead
)
311 ok(SendMessageA(hdex
, HDM_INSERTITEMA
, 0, (LPARAM
)phdiCreate
)!=-1, "Adding item failed\n");
312 ZeroMemory(phdiRead
, sizeof(HDITEMA
));
313 phdiRead
->mask
= maskRead
;
314 ok(SendMessageA(hdex
, HDM_GETITEMA
, 0, (LPARAM
)phdiRead
)!=0, "Getting item data failed\n");
315 ok(SendMessageA(hdex
, HDM_DELETEITEM
, 0, 0)!=0, "Deleting item failed\n");
318 static HWND
create_header_control (void)
325 handle
= CreateWindowExA(0, WC_HEADERA
, NULL
,
326 WS_CHILD
|WS_BORDER
|WS_VISIBLE
|HDS_BUTTONS
|HDS_HORZ
,
328 hHeaderParentWnd
, NULL
, NULL
, NULL
);
329 ok(handle
!= NULL
, "failed to create header window\n");
331 if (winetest_interactive
)
332 ShowWindow (hHeaderParentWnd
, SW_SHOW
);
334 GetClientRect(hHeaderParentWnd
,&rectwin
);
335 hlayout
.prc
= &rectwin
;
336 hlayout
.pwpos
= &winpos
;
337 SendMessageA(handle
, HDM_LAYOUT
, 0, (LPARAM
)&hlayout
);
338 SetWindowPos(handle
, winpos
.hwndInsertAfter
, winpos
.x
, winpos
.y
,
339 winpos
.cx
, winpos
.cy
, 0);
344 static void compare_items(INT iCode
, HDITEMA
*hdi1
, HDITEMA
*hdi2
, BOOL fUnicode
)
346 ok(hdi1
->mask
== hdi2
->mask
, "Notify %d mask mismatch (%08x != %08x)\n", iCode
, hdi1
->mask
, hdi2
->mask
);
347 if (hdi1
->mask
& HDI_WIDTH
)
349 ok(hdi1
->cxy
== hdi2
->cxy
, "Notify %d cxy mismatch (%08x != %08x)\n", iCode
, hdi1
->cxy
, hdi2
->cxy
);
351 if (hdi1
->mask
& HDI_TEXT
)
353 if (hdi1
->pszText
== LPSTR_TEXTCALLBACKA
)
355 ok(hdi1
->pszText
== LPSTR_TEXTCALLBACKA
, "Notify %d - only one item is LPSTR_TEXTCALLBACK\n", iCode
);
362 WideCharToMultiByte(CP_ACP
, 0, (LPCWSTR
)hdi1
->pszText
, -1, buf1
, 260, NULL
, NULL
);
363 WideCharToMultiByte(CP_ACP
, 0, (LPCWSTR
)hdi2
->pszText
, -1, buf2
, 260, NULL
, NULL
);
364 ok(lstrcmpW((LPWSTR
)hdi1
->pszText
, (LPWSTR
)hdi2
->pszText
)==0,
365 "Notify %d text mismatch (L\"%s\" vs L\"%s\")\n",
370 ok(strcmp(hdi1
->pszText
, hdi2
->pszText
)==0,
371 "Notify %d text mismatch (\"%s\" vs \"%s\")\n",
372 iCode
, hdi1
->pszText
, hdi2
->pszText
);
377 static char pszFirstItem
[] = "First Item";
378 static char pszSecondItem
[] = "Second Item";
379 static char pszThirdItem
[] = "Third Item";
380 static char pszFourthItem
[] = "Fourth Item";
381 static char pszReplaceItem
[] = "Replace Item";
382 static char pszOutOfRangeItem
[] = "Out Of Range Item";
384 static char *str_items
[] =
385 {pszFirstItem
, pszSecondItem
, pszThirdItem
, pszFourthItem
, pszReplaceItem
, pszOutOfRangeItem
};
387 static char pszUniTestA
[] = "TST";
388 static WCHAR pszUniTestW
[] = {'T','S','T',0};
391 #define TEST_GET_ITEM(i,c)\
392 { res = getItem(hWndHeader, i, buffer);\
393 ok(res != 0, "Getting item[%d] using valid index failed unexpectedly (%d)\n", i, res);\
394 ok(strcmp(str_items[c], buffer) == 0, "Getting item[%d] returned \"%s\" expecting \"%s\"\n", i, buffer, str_items[c]);\
397 #define TEST_GET_ITEMCOUNT(i)\
398 { res = getItemCount(hWndHeader);\
399 ok(res == i, "Got Item Count as %d\n", res);\
402 static LRESULT WINAPI
header_subclass_proc(HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
404 WNDPROC oldproc
= (WNDPROC
)GetWindowLongPtrA(hwnd
, GWLP_USERDATA
);
405 static LONG defwndproc_counter
= 0;
409 msg
.message
= message
;
410 msg
.flags
= sent
|wparam
|lparam
;
411 if (defwndproc_counter
) msg
.flags
|= defwinproc
;
415 add_message(sequences
, HEADER_SEQ_INDEX
, &msg
);
417 defwndproc_counter
++;
418 ret
= CallWindowProcA(oldproc
, hwnd
, message
, wParam
, lParam
);
419 defwndproc_counter
--;
424 static LRESULT WINAPI
parent_wnd_proc(HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
426 static LONG defwndproc_counter
= 0;
430 /* do not log painting messages */
431 if (message
!= WM_PAINT
&&
432 message
!= WM_ERASEBKGND
&&
433 message
!= WM_NCPAINT
&&
434 message
!= WM_NCHITTEST
&&
435 message
!= WM_GETTEXT
&&
436 message
!= WM_GETICON
&&
437 message
!= WM_DEVICECHANGE
)
440 msg
.message
= message
;
441 msg
.flags
= sent
|wparam
|lparam
;
442 if (defwndproc_counter
) msg
.flags
|= defwinproc
;
446 add_message(sequences
, PARENT_SEQ_INDEX
, &msg
);
449 defwndproc_counter
++;
450 ret
= DefWindowProcA(hwnd
, message
, wParam
, lParam
);
451 defwndproc_counter
--;
456 static BOOL
register_parent_wnd_class(void)
461 cls
.lpfnWndProc
= parent_wnd_proc
;
464 cls
.hInstance
= GetModuleHandleA(NULL
);
466 cls
.hCursor
= LoadCursorA(0, (LPCSTR
)IDC_ARROW
);
467 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
468 cls
.lpszMenuName
= NULL
;
469 cls
.lpszClassName
= "Header test parent class";
470 return RegisterClassA(&cls
);
473 static HWND
create_custom_parent_window(void)
475 if (!register_parent_wnd_class())
478 return CreateWindowExA(0, "Header test parent class", "Header Message Sequence Testing",
479 WS_OVERLAPPEDWINDOW
, CW_USEDEFAULT
, CW_USEDEFAULT
,
480 672+2*GetSystemMetrics(SM_CXSIZEFRAME
),
481 226+GetSystemMetrics(SM_CYCAPTION
)+2*GetSystemMetrics(SM_CYSIZEFRAME
),
482 NULL
, NULL
, GetModuleHandleA(NULL
), 0);
485 static HWND
create_custom_header_control(HWND hParent
, BOOL preloadHeaderItems
)
494 static char firstHeaderItem
[] = "Name";
495 static char secondHeaderItem
[] = "Size";
496 static char *items
[] = {secondHeaderItem
, firstHeaderItem
};
498 hdItem
.mask
= HDI_TEXT
| HDI_WIDTH
| HDI_FORMAT
;
499 hdItem
.fmt
= HDF_LEFT
;
501 hdItem
.cchTextMax
= 260;
503 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
505 childHandle
= CreateWindowExA(0, WC_HEADERA
, NULL
,
506 WS_CHILD
|WS_BORDER
|WS_VISIBLE
|HDS_BUTTONS
|HDS_HORZ
,
508 hParent
, NULL
, NULL
, NULL
);
509 ok(childHandle
!= NULL
, "failed to create child window\n");
510 if (preloadHeaderItems
)
512 for ( loopcnt
= 0 ; loopcnt
< 2 ; loopcnt
++ )
514 hdItem
.pszText
= items
[loopcnt
];
515 retVal
= SendMessageA(childHandle
, HDM_INSERTITEMA
, loopcnt
, (LPARAM
) &hdItem
);
516 ok(retVal
== loopcnt
, "Adding item %d failed with return value %d\n", ( loopcnt
+ 1 ), retVal
);
520 if (winetest_interactive
)
521 ShowWindow (hParent
, SW_SHOW
);
523 GetClientRect(hParent
,&rectwin
);
524 hlayout
.prc
= &rectwin
;
525 hlayout
.pwpos
= &winpos
;
526 SendMessageA(childHandle
,HDM_LAYOUT
,0,(LPARAM
) &hlayout
);
527 SetWindowPos(childHandle
, winpos
.hwndInsertAfter
, winpos
.x
, winpos
.y
,
528 winpos
.cx
, winpos
.cy
, 0);
530 oldproc
= (WNDPROC
)SetWindowLongPtrA(childHandle
, GWLP_WNDPROC
,
531 (LONG_PTR
)header_subclass_proc
);
532 SetWindowLongPtrA(childHandle
, GWLP_USERDATA
, (LONG_PTR
)oldproc
);
536 static void check_auto_format(void)
540 static CHAR text
[] = "Test";
541 ZeroMemory(&hdiCreate
, sizeof(HDITEMA
));
543 /* Windows implicitly sets some format bits in INSERTITEM */
545 /* HDF_STRING is automatically set and cleared for no text */
546 hdiCreate
.mask
= HDI_TEXT
|HDI_WIDTH
|HDI_FORMAT
;
547 hdiCreate
.pszText
= text
;
549 hdiCreate
.fmt
=HDF_CENTER
;
550 addReadDelItem(hWndHeader
, &hdiCreate
, HDI_FORMAT
, &hdiRead
);
551 ok(hdiRead
.fmt
== (HDF_STRING
|HDF_CENTER
), "HDF_STRING not set automatically (fmt=%x)\n", hdiRead
.fmt
);
553 hdiCreate
.mask
= HDI_WIDTH
|HDI_FORMAT
;
554 hdiCreate
.pszText
= text
;
555 hdiCreate
.fmt
= HDF_CENTER
|HDF_STRING
;
556 addReadDelItem(hWndHeader
, &hdiCreate
, HDI_FORMAT
, &hdiRead
);
557 ok(hdiRead
.fmt
== (HDF_CENTER
), "HDF_STRING should be automatically cleared (fmt=%x)\n", hdiRead
.fmt
);
559 /* HDF_BITMAP is automatically set and cleared for a NULL bitmap or no bitmap */
560 hdiCreate
.mask
= HDI_BITMAP
|HDI_WIDTH
|HDI_FORMAT
;
561 hdiCreate
.hbm
= CreateBitmap(16, 16, 1, 8, NULL
);
562 hdiCreate
.fmt
= HDF_CENTER
;
563 addReadDelItem(hWndHeader
, &hdiCreate
, HDI_FORMAT
, &hdiRead
);
564 ok(hdiRead
.fmt
== (HDF_BITMAP
|HDF_CENTER
), "HDF_BITMAP not set automatically (fmt=%x)\n", hdiRead
.fmt
);
565 DeleteObject(hdiCreate
.hbm
);
567 hdiCreate
.hbm
= NULL
;
568 hdiCreate
.fmt
= HDF_CENTER
|HDF_BITMAP
;
569 addReadDelItem(hWndHeader
, &hdiCreate
, HDI_FORMAT
, &hdiRead
);
570 ok(hdiRead
.fmt
== HDF_CENTER
, "HDF_BITMAP not cleared automatically for NULL bitmap (fmt=%x)\n", hdiRead
.fmt
);
572 hdiCreate
.mask
= HDI_WIDTH
|HDI_FORMAT
;
573 hdiCreate
.fmt
= HDF_CENTER
|HDF_BITMAP
;
574 addReadDelItem(hWndHeader
, &hdiCreate
, HDI_FORMAT
, &hdiRead
);
575 ok(hdiRead
.fmt
== HDF_CENTER
, "HDF_BITMAP not cleared automatically for no bitmap (fmt=%x)\n", hdiRead
.fmt
);
577 /* HDF_IMAGE is automatically set but not cleared */
578 hdiCreate
.mask
= HDI_IMAGE
|HDI_WIDTH
|HDI_FORMAT
;
579 hdiCreate
.iImage
= 17;
580 addReadDelItem(hWndHeader
, &hdiCreate
, HDI_FORMAT
, &hdiRead
);
581 ok(hdiRead
.fmt
== (HDF_IMAGE
|HDF_CENTER
), "HDF_IMAGE not set automatically (fmt=%x)\n", hdiRead
.fmt
);
583 hdiCreate
.mask
= HDI_WIDTH
|HDI_FORMAT
;
584 hdiCreate
.fmt
= HDF_CENTER
|HDF_IMAGE
;
585 hdiCreate
.iImage
= 0;
586 addReadDelItem(hWndHeader
, &hdiCreate
, HDI_FORMAT
, &hdiRead
);
587 ok(hdiRead
.fmt
== (HDF_CENTER
|HDF_IMAGE
), "HDF_IMAGE shouldn't be cleared automatically (fmt=%x)\n", hdiRead
.fmt
);
590 static void check_auto_fields(void)
594 static CHAR text
[] = "Test";
597 /* Windows stores the format, width, lparam even if they are not in the item's mask */
598 ZeroMemory(&hdiCreate
, sizeof(HDITEMA
));
599 hdiCreate
.mask
= HDI_TEXT
;
601 hdiCreate
.pszText
= text
;
602 addReadDelItem(hWndHeader
, &hdiCreate
, HDI_WIDTH
, &hdiRead
);
603 TEST_GET_ITEMCOUNT(6);
604 ok(hdiRead
.cxy
== hdiCreate
.cxy
, "cxy should be automatically set\n");
606 ZeroMemory(&hdiCreate
, sizeof(HDITEMA
));
607 hdiCreate
.mask
= HDI_TEXT
;
608 hdiCreate
.pszText
= text
;
609 hdiCreate
.lParam
= 0x12345678;
610 addReadDelItem(hWndHeader
, &hdiCreate
, HDI_LPARAM
, &hdiRead
);
611 TEST_GET_ITEMCOUNT(6);
612 ok(hdiRead
.lParam
== hdiCreate
.lParam
, "lParam should be automatically set\n");
614 ZeroMemory(&hdiCreate
, sizeof(HDITEMA
));
615 hdiCreate
.mask
= HDI_TEXT
;
616 hdiCreate
.pszText
= text
;
617 hdiCreate
.fmt
= HDF_STRING
|HDF_CENTER
;
618 addReadDelItem(hWndHeader
, &hdiCreate
, HDI_FORMAT
, &hdiRead
);
619 TEST_GET_ITEMCOUNT(6);
620 ok(hdiRead
.fmt
== hdiCreate
.fmt
, "fmt should be automatically set\n");
622 /* others fields are not set */
623 ZeroMemory(&hdiCreate
, sizeof(HDITEMA
));
624 hdiCreate
.mask
= HDI_TEXT
;
625 hdiCreate
.pszText
= text
;
626 hdiCreate
.hbm
= CreateBitmap(16, 16, 1, 8, NULL
);
627 addReadDelItem(hWndHeader
, &hdiCreate
, HDI_BITMAP
, &hdiRead
);
628 TEST_GET_ITEMCOUNT(6);
629 ok(hdiRead
.hbm
== NULL
, "hbm should not be automatically set\n");
630 DeleteObject(hdiCreate
.hbm
);
632 ZeroMemory(&hdiCreate
, sizeof(HDITEMA
));
633 hdiCreate
.mask
= HDI_IMAGE
;
634 hdiCreate
.iImage
= 17;
635 hdiCreate
.pszText
= text
;
636 addReadDelItem(hWndHeader
, &hdiCreate
, HDI_TEXT
, &hdiRead
);
637 TEST_GET_ITEMCOUNT(6);
638 ok(hdiRead
.pszText
==NULL
, "pszText shouldn't be automatically set\n");
640 /* field from comctl >4.0 not tested as the system probably won't touch them */
643 static void check_mask(void)
646 static CHAR text
[] = "ABC";
649 /* don't create items if the mask is zero */
650 ZeroMemory(&hdi
, sizeof(hdi
));
657 hdi
.cchTextMax
= 260;
658 ret
= SendMessageA(hWndHeader
, HDM_INSERTITEMA
, 0, (LPARAM
)&hdi
);
659 ok(ret
== -1, "Creating an item with a zero mask should have failed\n");
660 if (ret
!= -1) SendMessageA(hWndHeader
, HDM_DELETEITEM
, 0, 0);
662 /* with a non-zero mask creation will succeed */
663 ZeroMemory(&hdi
, sizeof(hdi
));
664 hdi
.mask
= HDI_LPARAM
;
665 ret
= SendMessageA(hWndHeader
, HDM_INSERTITEMA
, 0, (LPARAM
)&hdi
);
666 ok(ret
!= -1, "Adding item with non-zero mask failed\n");
668 SendMessageA(hWndHeader
, HDM_DELETEITEM
, 0, 0);
670 /* in SETITEM if the mask contains a unknown bit, it is ignored */
671 ZeroMemory(&hdi
, sizeof(hdi
));
672 hdi
.mask
= 0x08000000 | HDI_LPARAM
| HDI_IMAGE
;
675 ret
= SendMessageA(hWndHeader
, HDM_INSERTITEMA
, 0, (LPARAM
)&hdi
);
676 ok(ret
!= -1, "Adding item failed\n");
681 ZeroMemory(&hdi
, sizeof(hdi
));
682 hdi
.mask
= HDI_LPARAM
| HDI_IMAGE
;
683 SendMessageA(hWndHeader
, HDM_GETITEMA
, 0, (LPARAM
)&hdi
);
684 ok(hdi
.lParam
== 133, "comctl32 4.0 field not set\n");
685 ok(hdi
.iImage
== 17, "comctl32 >4.0 field not set\n");
687 /* but in GETITEM if an unknown bit is set, comctl32 uses only version 4.0 fields */
688 ZeroMemory(&hdi
, sizeof(hdi
));
689 hdi
.mask
= 0x08000000 | HDI_LPARAM
| HDI_IMAGE
;
690 SendMessageA(hWndHeader
, HDM_GETITEMA
, 0, (LPARAM
)&hdi
);
691 ok(hdi
.lParam
== 133, "comctl32 4.0 field not read\n");
692 ok(hdi
.iImage
== 0, "comctl32 >4.0 field shouldn't be read\n");
694 SendMessageA(hWndHeader
, HDM_DELETEITEM
, 0, 0);
698 static void test_header_control (void)
701 static char buffer
[MAX_CHARS
];
704 hWndHeader
= create_header_control ();
706 for (i
= 3; i
>= 0; i
--)
708 TEST_GET_ITEMCOUNT(3-i
);
709 res
= addItem(hWndHeader
, 0, str_items
[i
]);
710 ok(res
== 0, "Adding simple item failed (%d)\n", res
);
713 TEST_GET_ITEMCOUNT(4);
714 res
= addItem(hWndHeader
, 99, str_items
[i
+1]);
715 ok(res
!= -1, "Adding Out of Range item should fail with -1 got (%d)\n", res
);
716 TEST_GET_ITEMCOUNT(5);
717 res
= addItem(hWndHeader
, 5, str_items
[i
+1]);
718 ok(res
!= -1, "Adding Out of Range item should fail with -1 got (%d)\n", res
);
719 TEST_GET_ITEMCOUNT(6);
721 for (i
= 0; i
< 4; i
++) { TEST_GET_ITEM(i
,i
); TEST_GET_ITEMCOUNT(6); }
723 res
=getItem(hWndHeader
, 99, buffer
);
724 ok(res
== 0, "Getting Out of Range item should fail with 0 (%d), got %s\n", res
,buffer
);
725 res
=getItem(hWndHeader
, 5, buffer
);
726 ok(res
== 1, "Getting Out of Range item should fail with 1 (%d), got %s\n", res
,buffer
);
727 res
=getItem(hWndHeader
, -2, buffer
);
728 ok(res
== 0, "Getting Out of Range item should fail with 0 (%d), got %s\n", res
,buffer
);
730 if (winetest_interactive
)
732 UpdateWindow(hHeaderParentWnd
);
733 UpdateWindow(hWndHeader
);
736 TEST_GET_ITEMCOUNT(6);
737 res
=setItem(hWndHeader
, 99, str_items
[5], FALSE
);
738 ok(res
== 0, "Setting Out of Range item should fail with 0 (%d)\n", res
);
739 res
=setItem(hWndHeader
, 5, str_items
[5], TRUE
);
740 ok(res
== 1, "Setting Out of Range item should fail with 1 (%d)\n", res
);
741 res
=setItem(hWndHeader
, -2, str_items
[5], FALSE
);
742 ok(res
== 0, "Setting Out of Range item should fail with 0 (%d)\n", res
);
743 TEST_GET_ITEMCOUNT(6);
745 for (i
= 0; i
< 4; i
++)
747 res
= setItem(hWndHeader
, i
, str_items
[4], TRUE
);
748 ok(res
!= 0, "Setting %d item failed (%d)\n", i
+1, res
);
750 TEST_GET_ITEMCOUNT(6);
753 SendMessageA(hWndHeader
, HDM_SETUNICODEFORMAT
, TRUE
, 0);
754 setItemUnicodeNotify(hWndHeader
, 3, pszUniTestA
, pszUniTestW
);
755 SendMessageA(hWndHeader
, WM_NOTIFYFORMAT
, (WPARAM
)hHeaderParentWnd
, NF_REQUERY
);
756 setItem(hWndHeader
, 3, str_items
[4], TRUE
);
758 dont_expect_notify(HDN_GETDISPINFOA
);
759 dont_expect_notify(HDN_GETDISPINFOW
);
760 addItem(hWndHeader
, 0, LPSTR_TEXTCALLBACKA
);
761 setItem(hWndHeader
, 0, str_items
[4], TRUE
);
762 /* unexpected notifies cleared by notifies_received in setItem */
763 dont_expect_notify(HDN_GETDISPINFOA
);
764 dont_expect_notify(HDN_GETDISPINFOW
);
765 setItem(hWndHeader
, 0, LPSTR_TEXTCALLBACKA
, TRUE
);
766 /* unexpected notifies cleared by notifies_received in setItem */
767 delItem(hWndHeader
, 0);
770 TEST_GET_ITEMCOUNT(6);
772 TEST_GET_ITEMCOUNT(6);
774 TEST_GET_ITEMCOUNT(6);
776 res
= delItem(hWndHeader
, 5);
777 ok(res
== 1, "Deleting Out of Range item should fail with 1 (%d)\n", res
);
778 res
= delItem(hWndHeader
, -2);
779 ok(res
== 0, "Deleting Out of Range item should fail with 0 (%d)\n", res
);
780 TEST_GET_ITEMCOUNT(5);
782 res
= delItem(hWndHeader
, 3);
783 ok(res
!= 0, "Deleting using out of range index failed (%d)\n", res
);
784 TEST_GET_ITEMCOUNT(4);
785 res
= delItem(hWndHeader
, 0);
786 ok(res
!= 0, "Deleting using out of range index failed (%d)\n", res
);
787 TEST_GET_ITEMCOUNT(3);
788 res
= delItem(hWndHeader
, 0);
789 ok(res
!= 0, "Deleting using out of range index failed (%d)\n", res
);
790 TEST_GET_ITEMCOUNT(2);
791 res
= delItem(hWndHeader
, 0);
792 ok(res
!= 0, "Deleting using out of range index failed (%d)\n", res
);
793 TEST_GET_ITEMCOUNT(1);
795 DestroyWindow(hWndHeader
);
798 static void test_hdm_getitemrect(HWND hParent
)
805 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
806 hChild
= create_custom_header_control(hParent
, TRUE
);
807 ok_sequence(sequences
, PARENT_SEQ_INDEX
, add_header_to_parent_seq
,
808 "adder header control to parent", FALSE
);
810 retVal
= SendMessageA(hChild
, HDM_GETITEMRECT
, 1, (LPARAM
) &rect
);
811 ok(retVal
== TRUE
, "Getting item rect should TRUE, got %d\n", retVal
);
812 /* check bounding rectangle information of 2nd header item */
813 expect(80, rect
.left
);
815 expect(160, rect
.right
);
816 expect(g_customheight
, rect
.bottom
);
818 retVal
= SendMessageA(hChild
, HDM_GETITEMRECT
, 0, (LPARAM
) &rect
);
820 ok(retVal
== TRUE
, "Getting item rect should TRUE, got %d\n", retVal
);
821 /* check bounding rectangle information of 1st header item */
822 expect(0, rect
.left
);
825 expect(80, rect
.right
);
826 expect(g_customheight
, rect
.bottom
);
828 retVal
= SendMessageA(hChild
, HDM_GETITEMRECT
, 10, (LPARAM
) &rect
);
829 ok(retVal
== 0, "Getting rect of nonexistent item should return 0, got %d\n", retVal
);
831 ok_sequence(sequences
, HEADER_SEQ_INDEX
, getItemRect_seq
, "getItemRect sequence testing", FALSE
);
832 DestroyWindow(hChild
);
835 static void test_hdm_layout(HWND hParent
)
842 hdLayout
.prc
= &rect
;
843 hdLayout
.pwpos
= &windowPos
;
845 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
846 hChild
= create_custom_header_control(hParent
, TRUE
);
847 ok_sequence(sequences
, PARENT_SEQ_INDEX
, add_header_to_parent_seq
,
848 "adder header control to parent", FALSE
);
850 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
851 retVal
= SendMessageA(hChild
, HDM_LAYOUT
, 0, (LPARAM
) &hdLayout
);
852 expect(TRUE
, retVal
);
854 ok_sequence(sequences
, HEADER_SEQ_INDEX
, layout_seq
, "layout sequence testing", FALSE
);
856 DestroyWindow(hChild
);
859 static void test_hdm_ordertoindex(HWND hParent
)
864 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
865 hChild
= create_custom_header_control(hParent
, TRUE
);
866 ok_sequence(sequences
, PARENT_SEQ_INDEX
, add_header_to_parent_seq
,
867 "adder header control to parent", FALSE
);
869 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
870 retVal
= SendMessageA(hChild
, HDM_ORDERTOINDEX
, 1, 0);
873 ok_sequence(sequences
, HEADER_SEQ_INDEX
, orderToIndex_seq
, "orderToIndex sequence testing", FALSE
);
874 DestroyWindow(hChild
);
877 static void test_hdm_hittest(HWND hParent
)
882 HDHITTESTINFO hdHitTestInfo
;
883 const int firstItemRightBoundary
= 80;
884 const int secondItemRightBoundary
= 160;
885 const int bottomBoundary
= g_customheight
;
887 pt
.x
= firstItemRightBoundary
- 1;
888 pt
.y
= bottomBoundary
- 1;
889 hdHitTestInfo
.pt
= pt
;
892 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
893 hChild
= create_custom_header_control(hParent
, TRUE
);
894 ok_sequence(sequences
, PARENT_SEQ_INDEX
, add_header_to_parent_seq
,
895 "adder header control to parent", FALSE
);
897 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
898 retVal
= SendMessageA(hChild
, HDM_HITTEST
, 0, (LPARAM
) &hdHitTestInfo
);
900 expect(0, hdHitTestInfo
.iItem
);
901 expect(HHT_ONDIVIDER
, hdHitTestInfo
.flags
);
903 pt
.x
= secondItemRightBoundary
- 1;
904 pt
.y
= bottomBoundary
- 1;
905 hdHitTestInfo
.pt
= pt
;
906 retVal
= SendMessageA(hChild
, HDM_HITTEST
, 1, (LPARAM
) &hdHitTestInfo
);
908 expect(1, hdHitTestInfo
.iItem
);
909 expect(HHT_ONDIVIDER
, hdHitTestInfo
.flags
);
911 pt
.x
= secondItemRightBoundary
;
912 pt
.y
= bottomBoundary
+ 1;
913 hdHitTestInfo
.pt
= pt
;
914 retVal
= SendMessageA(hChild
, HDM_HITTEST
, 0, (LPARAM
) &hdHitTestInfo
);
916 expect(-1, hdHitTestInfo
.iItem
);
917 expect(HHT_BELOW
, hdHitTestInfo
.flags
);
919 ok_sequence(sequences
, HEADER_SEQ_INDEX
, hittest_seq
, "hittest sequence testing", FALSE
);
921 DestroyWindow(hChild
);
924 static void test_hdm_sethotdivider(HWND hParent
)
928 /* low word: x coordinate = 5
929 * high word: y coordinate = 5
932 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
933 hChild
= create_custom_header_control(hParent
, TRUE
);
934 ok_sequence(sequences
, PARENT_SEQ_INDEX
, add_header_to_parent_seq
,
935 "adder header control to parent", FALSE
);
937 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
938 retVal
= SendMessageA(hChild
, HDM_SETHOTDIVIDER
, TRUE
, MAKELPARAM(5, 5));
941 retVal
= SendMessageA(hChild
, HDM_SETHOTDIVIDER
, FALSE
, 100);
943 retVal
= SendMessageA(hChild
, HDM_SETHOTDIVIDER
, FALSE
, 1);
945 if (winetest_interactive
)
946 ok_sequence(sequences
, HEADER_SEQ_INDEX
, setHotDivider_seq_interactive
,
947 "setHotDivider sequence testing", TRUE
);
949 ok_sequence(sequences
, HEADER_SEQ_INDEX
, setHotDivider_seq_noninteractive
,
950 "setHotDivider sequence testing", FALSE
);
952 DestroyWindow(hChild
);
955 static void test_hdm_imageMessages(HWND hParent
)
957 HIMAGELIST hImageList
= ImageList_Create (4, 4, 0, 1, 0);
962 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
963 hChild
= create_custom_header_control(hParent
, TRUE
);
964 ok_sequence(sequences
, PARENT_SEQ_INDEX
, add_header_to_parent_seq
,
965 "adder header control to parent", FALSE
);
967 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
969 hIml
= (HIMAGELIST
) SendMessageA(hChild
, HDM_SETIMAGELIST
, 0, (LPARAM
) hImageList
);
970 ok(hIml
== NULL
, "Expected NULL, got %p\n", hIml
);
972 hIml
= (HIMAGELIST
) SendMessageA(hChild
, HDM_GETIMAGELIST
, 0, 0);
973 ok(hIml
!= NULL
, "Expected non-NULL handle, got %p\n", hIml
);
975 hIml
= (HIMAGELIST
) SendMessageA(hChild
, HDM_CREATEDRAGIMAGE
, 0, 0);
976 ok(hIml
!= NULL
, "Expected non-NULL handle, got %p\n", hIml
);
977 ImageList_Destroy(hIml
);
979 ok_sequence(sequences
, HEADER_SEQ_INDEX
, imageMessages_seq
, "imageMessages sequence testing", FALSE
);
981 DestroyWindow(hChild
);
983 wasValid
= ImageList_Destroy(hImageList
);
984 ok(wasValid
, "Header must not free image list at destruction!\n");
987 static void test_hdm_filterMessages(HWND hParent
)
992 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
993 hChild
= create_custom_header_control(hParent
, TRUE
);
994 ok_sequence(sequences
, PARENT_SEQ_INDEX
, add_header_to_parent_seq
,
995 "adder header control to parent", FALSE
);
997 timeout
= SendMessageA(hChild
, HDM_SETFILTERCHANGETIMEOUT
, 1, 100);
998 SendMessageA(hChild
, HDM_SETFILTERCHANGETIMEOUT
, 1, timeout
);
1000 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1002 /* msdn incorrectly states that return value
1003 * is the index of the filter control being
1004 * modified. The sendMessage here should
1005 * return previous filter timeout value
1008 retVal
= SendMessageA(hChild
, HDM_SETFILTERCHANGETIMEOUT
, 1, 100);
1009 expect(timeout
, retVal
);
1013 retVal
= SendMessageA(hChild
, HDM_CLEARFILTER
, 0, 1);
1015 win_skip("HDM_CLEARFILTER needs 5.80\n");
1019 retVal
= SendMessageA(hChild
, HDM_EDITFILTER
, 1, 0);
1021 win_skip("HDM_EDITFILTER needs 5.80\n");
1025 if (winetest_interactive
)
1026 ok_sequence(sequences
, HEADER_SEQ_INDEX
, filterMessages_seq_interactive
,
1027 "filterMessages sequence testing", TRUE
);
1029 ok_sequence(sequences
, HEADER_SEQ_INDEX
, filterMessages_seq_noninteractive
,
1030 "filterMessages sequence testing", FALSE
);
1031 DestroyWindow(hChild
);
1035 static void test_hdm_unicodeformatMessages(HWND hParent
)
1040 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1041 hChild
= create_custom_header_control(hParent
, TRUE
);
1042 ok_sequence(sequences
, PARENT_SEQ_INDEX
, add_header_to_parent_seq
,
1043 "adder header control to parent", FALSE
);
1045 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1046 retVal
= SendMessageA(hChild
, HDM_SETUNICODEFORMAT
, TRUE
, 0);
1048 retVal
= SendMessageA(hChild
, HDM_GETUNICODEFORMAT
, 0, 0);
1051 ok_sequence(sequences
, HEADER_SEQ_INDEX
, unicodeformatMessages_seq
,
1052 "unicodeformatMessages sequence testing", FALSE
);
1053 DestroyWindow(hChild
);
1056 static void test_hdm_bitmapmarginMessages(HWND hParent
)
1061 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1062 hChild
= create_custom_header_control(hParent
, TRUE
);
1063 ok_sequence(sequences
, PARENT_SEQ_INDEX
, add_header_to_parent_seq
,
1064 "adder header control to parent", FALSE
);
1066 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1067 retVal
= SendMessageA(hChild
, HDM_GETBITMAPMARGIN
, 0, 0);
1069 win_skip("HDM_GETBITMAPMARGIN needs 5.80\n");
1073 ok_sequence(sequences
, HEADER_SEQ_INDEX
, bitmapmarginMessages_seq
,
1074 "bitmapmarginMessages sequence testing", FALSE
);
1075 DestroyWindow(hChild
);
1078 static void test_hdm_index_messages(HWND hParent
)
1081 int retVal
, i
, iSize
;
1082 static const int lpiarray
[2] = {1, 0};
1083 static const char *item_texts
[] = {
1084 "Name", "Size", "Type", "Date Modified"
1091 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1092 hChild
= create_custom_header_control(hParent
, FALSE
);
1093 if (winetest_interactive
)
1094 ok_sequence(sequences
, PARENT_SEQ_INDEX
, add_header_to_parent_seq_interactive
,
1095 "adder header control to parent", TRUE
);
1097 ok_sequence(sequences
, PARENT_SEQ_INDEX
, add_header_to_parent_seq
,
1098 "adder header control to parent", FALSE
);
1099 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1100 for (i
= 0; i
< sizeof(item_texts
)/sizeof(item_texts
[0]); i
++)
1102 hdItem
.mask
= HDI_TEXT
| HDI_WIDTH
| HDI_FORMAT
;
1103 hdItem
.pszText
= (char*)item_texts
[i
];
1104 hdItem
.fmt
= HDF_LEFT
;
1107 retVal
= SendMessageA(hChild
, HDM_INSERTITEMA
, i
, (LPARAM
) &hdItem
);
1108 ok(retVal
== i
, "Adding item %d failed with return value %d\n", i
, retVal
);
1110 ok_sequence(sequences
, HEADER_SEQ_INDEX
, insertItem_seq
, "insertItem sequence testing", FALSE
);
1112 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1114 retVal
= SendMessageA(hChild
, HDM_DELETEITEM
, 3, (LPARAM
) &hdItem
);
1115 ok(retVal
== TRUE
, "Deleting item 3 should return TRUE, got %d\n", retVal
);
1116 retVal
= SendMessageA(hChild
, HDM_GETITEMCOUNT
, 0, 0);
1117 ok(retVal
== 3, "Getting item count should return 3, got %d\n", retVal
);
1119 retVal
= SendMessageA(hChild
, HDM_DELETEITEM
, 3, (LPARAM
) &hdItem
);
1120 ok(retVal
== FALSE
, "Deleting already-deleted item should return FALSE, got %d\n", retVal
);
1121 retVal
= SendMessageA(hChild
, HDM_GETITEMCOUNT
, 0, 0);
1122 ok(retVal
== 3, "Getting item count should return 3, got %d\n", retVal
);
1124 retVal
= SendMessageA(hChild
, HDM_DELETEITEM
, 2, (LPARAM
) &hdItem
);
1125 ok(retVal
== TRUE
, "Deleting item 2 should return TRUE, got %d\n", retVal
);
1126 retVal
= SendMessageA(hChild
, HDM_GETITEMCOUNT
, 0, 0);
1127 ok(retVal
== 2, "Getting item count should return 2, got %d\n", retVal
);
1129 ok_sequence(sequences
, HEADER_SEQ_INDEX
, deleteItem_getItemCount_seq
,
1130 "deleteItem_getItemCount sequence testing", FALSE
);
1132 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1134 hdItem
.mask
= HDI_WIDTH
;
1135 retVal
= SendMessageA(hChild
, HDM_GETITEMA
, 3, (LPARAM
) &hdItem
);
1136 ok(retVal
== FALSE
, "Getting already-deleted item should return FALSE, got %d\n", retVal
);
1138 hdItem
.mask
= HDI_TEXT
| HDI_WIDTH
;
1139 hdItem
.pszText
= buffA
;
1140 hdItem
.cchTextMax
= sizeof(buffA
)/sizeof(buffA
[0]);
1141 retVal
= SendMessageA(hChild
, HDM_GETITEMA
, 0, (LPARAM
) &hdItem
);
1142 ok(retVal
== TRUE
, "Getting the 1st header item should return TRUE, got %d\n", retVal
);
1144 ok_sequence(sequences
, HEADER_SEQ_INDEX
, getItem_seq
, "getItem sequence testing", FALSE
);
1146 /* check if the item is the right one */
1147 ok(!strcmp(hdItem
.pszText
, item_texts
[0]), "got wrong item %s, expected %s\n",
1148 hdItem
.pszText
, item_texts
[0]);
1149 expect(80, hdItem
.cxy
);
1151 iSize
= SendMessageA(hChild
, HDM_GETITEMCOUNT
, 0, 0);
1153 /* item should be updated just after accepting new array */
1154 ShowWindow(hChild
, SW_HIDE
);
1155 retVal
= SendMessageA(hChild
, HDM_SETORDERARRAY
, iSize
, (LPARAM
) lpiarray
);
1156 expect(TRUE
, retVal
);
1158 retVal
= SendMessageA(hChild
, HDM_GETITEMRECT
, 0, (LPARAM
) &rect
);
1159 expect(TRUE
, retVal
);
1160 ok(rect
.left
!= 0, "Expected updated rectangle\n");
1162 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1164 retVal
= SendMessageA(hChild
, HDM_SETORDERARRAY
, iSize
, (LPARAM
) lpiarray
);
1165 ok(retVal
== TRUE
, "Setting header items order should return TRUE, got %d\n", retVal
);
1167 retVal
= SendMessageA(hChild
, HDM_GETORDERARRAY
, 2, (LPARAM
) array
);
1168 ok(retVal
== TRUE
, "Getting header items order should return TRUE, got %d\n", retVal
);
1170 ok_sequence(sequences
, HEADER_SEQ_INDEX
, orderArray_seq
, "set_get_orderArray sequence testing", FALSE
);
1172 /* check if the array order is set correctly and the size of the array is correct. */
1174 ok(lpiarray
[0] == array
[0], "got %d, expected %d\n", array
[0], lpiarray
[0]);
1175 ok(lpiarray
[1] == array
[1], "got %d, expected %d\n", array
[1], lpiarray
[1]);
1177 hdItem
.mask
= HDI_FORMAT
;
1178 hdItem
.fmt
= HDF_CENTER
| HDF_STRING
;
1180 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
1182 retVal
= SendMessageA(hChild
, HDM_SETITEMA
, 0, (LPARAM
) &hdItem
);
1183 ok(retVal
== TRUE
, "Aligning 1st header item to center should return TRUE, got %d\n", retVal
);
1184 hdItem
.fmt
= HDF_RIGHT
| HDF_STRING
;
1185 retVal
= SendMessageA(hChild
, HDM_SETITEMA
, 1, (LPARAM
) &hdItem
);
1186 ok(retVal
== TRUE
, "Aligning 2nd header item to right should return TRUE, got %d\n", retVal
);
1188 ok_sequence(sequences
, HEADER_SEQ_INDEX
, setItem_seq
, "setItem sequence testing", FALSE
);
1189 DestroyWindow(hChild
);
1192 static void test_hdf_fixedwidth(HWND hParent
)
1200 hChild
= create_custom_header_control(hParent
, FALSE
);
1202 hdItem
.mask
= HDI_WIDTH
| HDI_FORMAT
;
1203 hdItem
.fmt
= HDF_FIXEDWIDTH
;
1206 ret
= SendMessageA(hChild
, HDM_INSERTITEMA
, 0, (LPARAM
)&hdItem
);
1209 /* try to change width */
1210 rect
.right
= rect
.bottom
= 0;
1211 SendMessageA(hChild
, HDM_GETITEMRECT
, 0, (LPARAM
)&rect
);
1212 ok(rect
.right
!= 0, "Expected not zero width\n");
1213 ok(rect
.bottom
!= 0, "Expected not zero height\n");
1215 SendMessageA(hChild
, WM_LBUTTONDOWN
, 0, MAKELPARAM(rect
.right
, rect
.bottom
/ 2));
1216 SendMessageA(hChild
, WM_MOUSEMOVE
, 0, MAKELPARAM(rect
.right
+ 20, rect
.bottom
/ 2));
1217 SendMessageA(hChild
, WM_LBUTTONUP
, 0, MAKELPARAM(rect
.right
+ 20, rect
.bottom
/ 2));
1219 SendMessageA(hChild
, HDM_GETITEMRECT
, 0, (LPARAM
)&rect
);
1221 if (hdItem
.cxy
!= rect
.right
)
1223 win_skip("HDF_FIXEDWIDTH format not supported\n");
1224 DestroyWindow(hChild
);
1228 /* try to adjust with message */
1229 hdItem
.mask
= HDI_WIDTH
;
1232 ret
= SendMessageA(hChild
, HDM_SETITEMA
, 0, (LPARAM
)&hdItem
);
1236 SendMessageA(hChild
, HDM_GETITEMRECT
, 0, (LPARAM
)&rect
);
1237 expect(90, rect
.right
);
1239 /* hittesting doesn't report ondivider flag for HDF_FIXEDWIDTH */
1240 ht
.pt
.x
= rect
.right
- 1;
1241 ht
.pt
.y
= rect
.bottom
/ 2;
1242 SendMessageA(hChild
, HDM_HITTEST
, 0, (LPARAM
)&ht
);
1243 expect(HHT_ONHEADER
, ht
.flags
);
1245 /* try to adjust with message */
1246 hdItem
.mask
= HDI_FORMAT
;
1249 ret
= SendMessageA(hChild
, HDM_SETITEMA
, 0, (LPARAM
)&hdItem
);
1253 ht
.pt
.y
= rect
.bottom
/ 2;
1254 SendMessageA(hChild
, HDM_HITTEST
, 0, (LPARAM
)&ht
);
1255 expect(HHT_ONDIVIDER
, ht
.flags
);
1257 DestroyWindow(hChild
);
1260 static void test_hds_nosizing(HWND hParent
)
1268 hChild
= create_custom_header_control(hParent
, FALSE
);
1270 memset(&hdItem
, 0, sizeof(hdItem
));
1271 hdItem
.mask
= HDI_WIDTH
;
1274 ret
= SendMessageA(hChild
, HDM_INSERTITEMA
, 0, (LPARAM
)&hdItem
);
1277 /* HDS_NOSIZING only blocks hittesting */
1278 ret
= GetWindowLongA(hChild
, GWL_STYLE
);
1279 SetWindowLongA(hChild
, GWL_STYLE
, ret
| HDS_NOSIZING
);
1281 /* try to change width with mouse gestures */
1282 rect
.right
= rect
.bottom
= 0;
1283 SendMessageA(hChild
, HDM_GETITEMRECT
, 0, (LPARAM
)&rect
);
1284 ok(rect
.right
!= 0, "Expected not zero width\n");
1285 ok(rect
.bottom
!= 0, "Expected not zero height\n");
1287 SendMessageA(hChild
, WM_LBUTTONDOWN
, 0, MAKELPARAM(rect
.right
, rect
.bottom
/ 2));
1288 SendMessageA(hChild
, WM_MOUSEMOVE
, 0, MAKELPARAM(rect
.right
+ 20, rect
.bottom
/ 2));
1289 SendMessageA(hChild
, WM_LBUTTONUP
, 0, MAKELPARAM(rect
.right
+ 20, rect
.bottom
/ 2));
1291 SendMessageA(hChild
, HDM_GETITEMRECT
, 0, (LPARAM
)&rect
);
1293 if (hdItem
.cxy
!= rect
.right
)
1295 win_skip("HDS_NOSIZING style not supported\n");
1296 DestroyWindow(hChild
);
1300 /* this style doesn't set HDF_FIXEDWIDTH for items */
1301 hdItem
.mask
= HDI_FORMAT
;
1302 ret
= SendMessageA(hChild
, HDM_GETITEMA
, 0, (LPARAM
)&hdItem
);
1304 ok(!(hdItem
.fmt
& HDF_FIXEDWIDTH
), "Unexpected HDF_FIXEDWIDTH\n");
1306 /* try to adjust with message */
1307 hdItem
.mask
= HDI_WIDTH
;
1310 ret
= SendMessageA(hChild
, HDM_SETITEMA
, 0, (LPARAM
)&hdItem
);
1314 SendMessageA(hChild
, HDM_GETITEMRECT
, 0, (LPARAM
)&rect
);
1315 expect(90, rect
.right
);
1317 /* hittesting doesn't report ondivider flags for HDS_NOSIZING */
1318 ht
.pt
.x
= rect
.right
- 1;
1319 ht
.pt
.y
= rect
.bottom
/ 2;
1320 SendMessageA(hChild
, HDM_HITTEST
, 0, (LPARAM
)&ht
);
1321 expect(HHT_ONHEADER
, ht
.flags
);
1323 /* try to adjust with message */
1324 ret
= GetWindowLongA(hChild
, GWL_STYLE
);
1325 SetWindowLongA(hChild
, GWL_STYLE
, ret
& ~HDS_NOSIZING
);
1328 ht
.pt
.y
= rect
.bottom
/ 2;
1329 SendMessageA(hChild
, HDM_HITTEST
, 0, (LPARAM
)&ht
);
1330 expect(HHT_ONDIVIDER
, ht
.flags
);
1332 DestroyWindow(hChild
);
1335 #define TEST_NMCUSTOMDRAW(draw_stage, item_spec, lparam, _left, _top, _right, _bottom) \
1336 ok(nm->dwDrawStage == draw_stage, "Invalid dwDrawStage %d vs %d\n", draw_stage, nm->dwDrawStage); \
1337 if (item_spec != -1) \
1338 ok(nm->dwItemSpec == item_spec, "Invalid dwItemSpec %d vs %ld\n", item_spec, nm->dwItemSpec); \
1339 ok(nm->lItemlParam == lparam, "Invalid lItemlParam %d vs %ld\n", lparam, nm->lItemlParam); \
1340 ok((nm->rc.top == _top && nm->rc.bottom == _bottom && nm->rc.left == _left && nm->rc.right == _right) || \
1341 broken(draw_stage != CDDS_ITEMPREPAINT), /* comctl32 < 5.80 */ \
1342 "Invalid rect (%d,%d) (%d,%d) vs (%d,%d) (%d,%d)\n", _left, _top, _right, _bottom, \
1343 nm->rc.left, nm->rc.top, nm->rc.right, nm->rc.bottom);
1345 static LRESULT
customdraw_1(int n
, NMCUSTOMDRAW
*nm
)
1347 if (nm
== NULL
) { /* test ended */
1348 ok(n
==1, "NM_CUSTOMDRAW messages: %d, expected: 1\n", n
);
1355 /* don't test dwItemSpec - it's 0 no comctl5 but 1308756 on comctl6 */
1356 TEST_NMCUSTOMDRAW(CDDS_PREPAINT
, -1, 0, 0, 0, 670, g_customheight
);
1360 ok(FALSE
, "Too many custom draw messages (n=%d, nm->dwDrawStage=%d)\n", n
, nm
->dwDrawStage
);
1364 static LRESULT
customdraw_2(int n
, NMCUSTOMDRAW
*nm
)
1366 if (nm
== NULL
) { /* test ended */
1367 ok(n
==4, "NM_CUSTOMDRAW messages: %d, expected: 4\n", n
);
1374 TEST_NMCUSTOMDRAW(CDDS_PREPAINT
, -1, 0, 0, 0, 670, g_customheight
);
1375 return CDRF_NOTIFYITEMDRAW
;
1377 TEST_NMCUSTOMDRAW(CDDS_ITEMPREPAINT
, 0, 0, 0, 0, 50, g_customheight
);
1380 TEST_NMCUSTOMDRAW(CDDS_ITEMPREPAINT
, 1, 5, 50, 0, 150, g_customheight
);
1383 TEST_NMCUSTOMDRAW(CDDS_ITEMPREPAINT
, 2, 10, 150, 0, 300, g_customheight
);
1387 ok(FALSE
, "Too many custom draw messages (n=%d, nm->dwDrawStage=%d)\n", n
, nm
->dwDrawStage
);
1391 static LRESULT
customdraw_3(int n
, NMCUSTOMDRAW
*nm
)
1393 if (nm
== NULL
) { /* test ended */
1394 ok(n
==5, "NM_CUSTOMDRAW messages: %d, expected: 5\n", n
);
1401 TEST_NMCUSTOMDRAW(CDDS_PREPAINT
, -1, 0, 0, 0, 670, g_customheight
);
1402 return CDRF_NOTIFYITEMDRAW
|CDRF_NOTIFYPOSTERASE
|CDRF_NOTIFYPOSTPAINT
|CDRF_SKIPDEFAULT
;
1404 TEST_NMCUSTOMDRAW(CDDS_ITEMPREPAINT
, 0, 0, 0, 0, 50, g_customheight
);
1407 TEST_NMCUSTOMDRAW(CDDS_ITEMPREPAINT
, 1, 5, 50, 0, 150, g_customheight
);
1410 TEST_NMCUSTOMDRAW(CDDS_ITEMPREPAINT
, 2, 10, 150, 0, 300, g_customheight
);
1413 TEST_NMCUSTOMDRAW(CDDS_POSTPAINT
, -1, 0, 0, 0, 670, g_customheight
);
1417 ok(FALSE
, "Too many custom draw messages (n=%d, nm->dwDrawStage=%d)\n", n
, nm
->dwDrawStage
);
1422 static LRESULT
customdraw_4(int n
, NMCUSTOMDRAW
*nm
)
1424 if (nm
== NULL
) { /* test ended */
1425 ok(n
==4, "NM_CUSTOMDRAW messages: %d, expected: 4\n", n
);
1432 TEST_NMCUSTOMDRAW(CDDS_PREPAINT
, -1, 0, 0, 0, 670, g_customheight
);
1433 return CDRF_NOTIFYITEMDRAW
|CDRF_NOTIFYPOSTPAINT
;
1435 TEST_NMCUSTOMDRAW(CDDS_ITEMPREPAINT
, 0, 0, 0, 0, 50, g_customheight
);
1438 TEST_NMCUSTOMDRAW(CDDS_ITEMPREPAINT
, 2, 10, 150, 0, 300, g_customheight
);
1441 TEST_NMCUSTOMDRAW(CDDS_POSTPAINT
, -1, 0, 0, 0, 670, g_customheight
);
1445 ok(FALSE
, "Too many custom draw messages (n=%d, nm->dwDrawStage=%d)\n", n
, nm
->dwDrawStage
);
1449 static void run_customdraw_scenario(CUSTOMDRAWPROC proc
)
1451 g_CustomDrawProc
= proc
;
1452 g_CustomDrawCount
= 0;
1453 InvalidateRect(hWndHeader
, NULL
, TRUE
);
1454 UpdateWindow(hWndHeader
);
1455 proc(g_CustomDrawCount
, NULL
);
1456 g_CustomDrawProc
= NULL
;
1459 static void test_customdraw(void)
1464 CHAR name
[] = "Test";
1465 hWndHeader
= create_header_control();
1466 GetClientRect(hWndHeader
, &rect
);
1467 ok(rect
.right
- rect
.left
== 670 && rect
.bottom
- rect
.top
== g_customheight
,
1468 "Tests will fail as header size is %dx%d instead of 670x%d\n",
1469 rect
.right
- rect
.left
, rect
.bottom
- rect
.top
, g_customheight
);
1471 for (i
= 0; i
< 3; i
++)
1473 ZeroMemory(&item
, sizeof(item
));
1474 item
.mask
= HDI_TEXT
|HDI_WIDTH
;
1475 item
.cxy
= 50*(i
+1);
1476 item
.pszText
= name
;
1478 SendMessageA(hWndHeader
, HDM_INSERTITEMA
, i
, (LPARAM
)&item
);
1481 run_customdraw_scenario(customdraw_1
);
1482 run_customdraw_scenario(customdraw_2
);
1483 run_customdraw_scenario(customdraw_3
);
1485 ZeroMemory(&item
, sizeof(item
));
1486 item
.mask
= HDI_FORMAT
;
1487 item
.fmt
= HDF_OWNERDRAW
;
1488 SendMessageA(hWndHeader
, HDM_SETITEMA
, 1, (LPARAM
)&item
);
1489 g_DrawItem
.CtlID
= 0;
1490 g_DrawItem
.CtlType
= ODT_HEADER
;
1491 g_DrawItem
.hwndItem
= hWndHeader
;
1492 g_DrawItem
.itemID
= 1;
1493 g_DrawItem
.itemState
= 0;
1494 SendMessageA(hWndHeader
, HDM_GETITEMRECT
, 1, (LPARAM
)&g_DrawItem
.rcItem
);
1495 run_customdraw_scenario(customdraw_4
);
1496 ok(g_DrawItemReceived
, "WM_DRAWITEM not received\n");
1497 DestroyWindow(hWndHeader
);
1499 g_DrawItem
.CtlType
= 0;
1500 g_DrawItemReceived
= FALSE
;
1503 static void check_order(const int expected_id
[], const int expected_order
[],
1504 int count
, const char *type
)
1509 ok(getItemCount(hWndHeader
) == count
, "Invalid item count in order tests\n");
1510 for (i
= 0; i
< count
; i
++)
1512 hdi
.mask
= HDI_LPARAM
|HDI_ORDER
;
1513 SendMessageA(hWndHeader
, HDM_GETITEMA
, i
, (LPARAM
)&hdi
);
1514 ok(hdi
.lParam
== expected_id
[i
],
1515 "Invalid item ids after '%s'- item %d has lParam %d\n", type
, i
, (int)hdi
.lParam
);
1516 ok(hdi
.iOrder
== expected_order
[i
],
1517 "Invalid item order after '%s'- item %d has iOrder %d\n", type
, i
, hdi
.iOrder
);
1521 static void test_header_order (void)
1523 const int rand1
[] = {0, 1, 1, 0, 4};
1524 const int rand2
[] = {4, 5, 6, 7, 4};
1525 const int rand3
[] = {5, 5, 1, 6, 1};
1526 const int rand4
[] = {1, 5, 2, 7, 6, 1, 4, 2, 3, 2};
1527 const int rand5
[] = {7, 8, 5, 6, 7, 2, 1, 9, 10, 10};
1528 const int rand6
[] = {2, 8, 3, 4, 0};
1530 const int ids1
[] = {3, 0, 2, 1, 4};
1531 const int ord1
[] = {0, 1, 2, 3, 4};
1532 const int ids2
[] = {3, 9, 7, 0, 2, 1, 4, 8, 6, 5};
1533 const int ord2
[] = {0, 4, 7, 1, 2, 3, 9, 8, 6, 5};
1534 const int ord3
[] = {0, 3, 9, 2, 1, 8, 7, 6, 5, 4};
1535 const int ids4
[] = {9, 0, 1, 8, 6};
1536 const int ord4
[] = {1, 0, 4, 3, 2};
1542 hWndHeader
= create_header_control();
1544 ZeroMemory(&hdi
, sizeof(HDITEMA
));
1545 hdi
.mask
= HDI_TEXT
| HDI_LPARAM
;
1546 hdi
.pszText
= buffer
;
1547 strcpy(buffer
, "test");
1549 for (i
= 0; i
< 5; i
++)
1552 SendMessageA(hWndHeader
, HDM_INSERTITEMA
, rand1
[i
], (LPARAM
)&hdi
);
1555 check_order(ids1
, ord1
, 5, "insert without iOrder");
1557 hdi
.mask
|= HDI_ORDER
;
1558 for (i
= 0; i
< 5; i
++)
1561 hdi
.iOrder
= rand2
[i
];
1562 SendMessageA(hWndHeader
, HDM_INSERTITEMA
, rand3
[i
], (LPARAM
)&hdi
);
1565 check_order(ids2
, ord2
, 10, "insert with order");
1567 hdi
.mask
= HDI_ORDER
;
1568 for (i
=0; i
<10; i
++)
1570 hdi
.iOrder
= rand5
[i
];
1571 SendMessageA(hWndHeader
, HDM_SETITEMA
, rand4
[i
], (LPARAM
)&hdi
);
1574 check_order(ids2
, ord3
, 10, "setitems changing order");
1577 SendMessageA(hWndHeader
, HDM_DELETEITEM
, rand6
[i
], 0);
1578 check_order(ids4
, ord4
, 5, "deleteitem");
1580 DestroyWindow(hWndHeader
);
1583 static LRESULT CALLBACK
HeaderTestWndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1590 NMHEADERA
*hdr
= (NMHEADERA
*)lParam
;
1591 EXPECTEDNOTIFY
*expected
;
1594 if (hdr
->hdr
.code
== NM_CUSTOMDRAW
)
1595 if (g_CustomDrawProc
)
1596 return g_CustomDrawProc(g_CustomDrawCount
++, (NMCUSTOMDRAW
*)hdr
);
1598 for (i
=0; i
<nUnexpectedNotify
; i
++)
1599 ok(hdr
->hdr
.code
!= unexpectedNotify
[i
], "Received invalid notify %d\n", hdr
->hdr
.code
);
1601 if (nReceivedNotify
>= nExpectedNotify
|| hdr
->hdr
.hwndFrom
!= hWndHeader
)
1604 expected
= &expectedNotify
[nReceivedNotify
];
1605 if (hdr
->hdr
.code
!= expected
->iCode
)
1609 compare_items(hdr
->hdr
.code
, &expected
->hdItem
, hdr
->pitem
, expected
->fUnicode
);
1614 di
= (DRAWITEMSTRUCT
*)lParam
;
1615 ok(g_DrawItem
.CtlType
!= 0, "Unexpected WM_DRAWITEM\n");
1616 if (g_DrawItem
.CtlType
== 0) return 0;
1617 g_DrawItemReceived
= TRUE
;
1618 compare(di
->CtlType
, g_DrawItem
.CtlType
, "%d");
1619 compare(di
->CtlID
, g_DrawItem
.CtlID
, "%d");
1620 compare(di
->hwndItem
, g_DrawItem
.hwndItem
, "%p");
1621 compare(di
->itemID
, g_DrawItem
.itemID
, "%d");
1622 compare(di
->itemState
, g_DrawItem
.itemState
, "%d");
1623 compare(di
->rcItem
.left
, g_DrawItem
.rcItem
.left
, "%d");
1624 compare(di
->rcItem
.top
, g_DrawItem
.rcItem
.top
, "%d");
1625 compare(di
->rcItem
.right
, g_DrawItem
.rcItem
.right
, "%d");
1626 compare(di
->rcItem
.bottom
, g_DrawItem
.rcItem
.bottom
, "%d");
1634 return DefWindowProcA(hWnd
, msg
, wParam
, lParam
);
1640 static BOOL
init(void)
1643 BOOL (WINAPI
*pInitCommonControlsEx
)(const INITCOMMONCONTROLSEX
*);
1645 INITCOMMONCONTROLSEX iccex
;
1650 hComctl32
= GetModuleHandleA("comctl32.dll");
1651 pInitCommonControlsEx
= (void*)GetProcAddress(hComctl32
, "InitCommonControlsEx");
1652 if (!pInitCommonControlsEx
)
1654 skip("InitCommonControlsEx() is missing. Skipping the tests\n");
1658 iccex
.dwSize
= sizeof(iccex
);
1659 iccex
.dwICC
= ICC_USEREX_CLASSES
;
1660 pInitCommonControlsEx(&iccex
);
1662 wc
.style
= CS_HREDRAW
| CS_VREDRAW
;
1665 wc
.hInstance
= GetModuleHandleA(NULL
);
1667 wc
.hCursor
= LoadCursorA(NULL
, (LPCSTR
)IDC_ARROW
);
1668 wc
.hbrBackground
= GetSysColorBrush(COLOR_WINDOW
);
1669 wc
.lpszMenuName
= NULL
;
1670 wc
.lpszClassName
= "HeaderTestClass";
1671 wc
.lpfnWndProc
= HeaderTestWndProc
;
1672 RegisterClassA(&wc
);
1674 /* The height of the header control depends on the height of the system font.
1675 The height of the system font is dpi dependent */
1677 hOldFont
= SelectObject(hdc
, GetStockObject(SYSTEM_FONT
));
1678 GetTextMetricsA(hdc
, &tm
);
1679 /* 2 dot extra space are needed for the border */
1680 g_customheight
= tm
.tmHeight
+ 2;
1681 trace("customdraw height: %d (dpi: %d)\n", g_customheight
, GetDeviceCaps(hdc
, LOGPIXELSY
));
1682 SelectObject(hdc
, hOldFont
);
1685 hHeaderParentWnd
= CreateWindowExA(0, "HeaderTestClass", "Header test", WS_OVERLAPPEDWINDOW
,
1686 CW_USEDEFAULT
, CW_USEDEFAULT
, 672+2*GetSystemMetrics(SM_CXSIZEFRAME
),
1687 226+GetSystemMetrics(SM_CYCAPTION
)+2*GetSystemMetrics(SM_CYSIZEFRAME
),
1688 NULL
, NULL
, GetModuleHandleA(NULL
), 0);
1689 ok(hHeaderParentWnd
!= NULL
, "failed to create parent wnd\n");
1691 ShowWindow(hHeaderParentWnd
, SW_SHOW
);
1692 return hHeaderParentWnd
!= NULL
;
1695 /* maximum 8 items allowed */
1696 static void check_orderarray(HWND hwnd
, DWORD start
, DWORD set
, DWORD expected
,
1697 BOOL todo
, int line
)
1701 DWORD ret
, array
= 0;
1703 count
= SendMessageA(hwnd
, HDM_GETITEMCOUNT
, 0, 0);
1706 for(i
= 1; i
<=count
; i
++)
1707 order
[i
-1] = start
>>(4*(count
-i
)) & 0xf;
1709 ret
= SendMessageA(hwnd
, HDM_SETORDERARRAY
, count
, (LPARAM
)order
);
1710 ok_(__FILE__
, line
)(ret
, "Expected HDM_SETORDERARAY to succeed, got %d\n", ret
);
1713 for(i
= 1; i
<=count
; i
++)
1714 order
[i
-1] = set
>>(4*(count
-i
)) & 0xf;
1715 ret
= SendMessageA(hwnd
, HDM_SETORDERARRAY
, count
, (LPARAM
)order
);
1716 ok_(__FILE__
, line
)(ret
, "Expected HDM_SETORDERARAY to succeed, got %d\n", ret
);
1718 /* check actual order */
1719 ret
= SendMessageA(hwnd
, HDM_GETORDERARRAY
, count
, (LPARAM
)order
);
1720 ok_(__FILE__
, line
)(ret
, "Expected HDM_GETORDERARAY to succeed, got %d\n", ret
);
1721 for(i
= 1; i
<=count
; i
++)
1722 array
|= order
[i
-1]<<(4*(count
-i
));
1725 ok_(__FILE__
, line
)(array
== expected
, "Expected %x, got %x\n", expected
, array
);
1728 static void test_hdm_orderarray(void)
1734 hwnd
= create_header_control();
1737 addItem(hwnd
, 0, NULL
);
1738 addItem(hwnd
, 1, NULL
);
1739 addItem(hwnd
, 2, NULL
);
1741 ret
= SendMessageA(hwnd
, HDM_GETORDERARRAY
, 3, (LPARAM
)order
);
1744 win_skip("HDM_GETORDERARRAY not implemented.\n");
1745 DestroyWindow(hwnd
);
1749 expect(0, order
[0]);
1750 expect(1, order
[1]);
1751 expect(2, order
[2]);
1755 /* null pointer, crashes native */
1756 ret
= SendMessageA(hwnd
, HDM_SETORDERARRAY
, 3, 0);
1759 /* count out of limits */
1760 ret
= SendMessageA(hwnd
, HDM_SETORDERARRAY
, 5, (LPARAM
)order
);
1762 /* count out of limits */
1763 ret
= SendMessageA(hwnd
, HDM_SETORDERARRAY
, 2, (LPARAM
)order
);
1766 /* try with out of range item index */
1767 /* (0,1,2)->(1,0,3) => (1,0,2) */
1768 check_orderarray(hwnd
, 0x120, 0x103, 0x102, FALSE
, __LINE__
);
1769 /* (1,0,2)->(3,0,1) => (0,2,1) */
1770 check_orderarray(hwnd
, 0x102, 0x301, 0x021, TRUE
, __LINE__
);
1771 /* (0,2,1)->(2,3,1) => (2,0,1) */
1772 check_orderarray(hwnd
, 0x021, 0x231, 0x201, FALSE
, __LINE__
);
1774 /* (0,1,2)->(0,2,2) => (0,1,2) */
1775 check_orderarray(hwnd
, 0x012, 0x022, 0x012, FALSE
, __LINE__
);
1777 addItem(hwnd
, 3, NULL
);
1779 /* (0,1,2,3)->(0,1,2,2) => (0,1,3,2) */
1780 check_orderarray(hwnd
, 0x0123, 0x0122, 0x0132, FALSE
, __LINE__
);
1781 /* (0,1,2,3)->(0,1,3,3) => (0,1,2,3) */
1782 check_orderarray(hwnd
, 0x0123, 0x0133, 0x0123, FALSE
, __LINE__
);
1783 /* (0,1,2,3)->(0,4,2,3) => (0,1,2,3) */
1784 check_orderarray(hwnd
, 0x0123, 0x0423, 0x0123, FALSE
, __LINE__
);
1785 /* (0,1,2,3)->(4,0,1,2) => (0,1,3,2) */
1786 check_orderarray(hwnd
, 0x0123, 0x4012, 0x0132, TRUE
, __LINE__
);
1787 /* (0,1,3,2)->(4,0,1,4) => (0,3,1,2) */
1788 check_orderarray(hwnd
, 0x0132, 0x4014, 0x0312, TRUE
, __LINE__
);
1789 /* (0,1,2,3)->(4,1,0,2) => (1,0,3,2) */
1790 check_orderarray(hwnd
, 0x0123, 0x4102, 0x1032, TRUE
, __LINE__
);
1791 /* (0,1,2,3)->(0,1,4,2) => (0,1,2,3) */
1792 check_orderarray(hwnd
, 0x0123, 0x0142, 0x0132, FALSE
, __LINE__
);
1793 /* (0,1,2,3)->(4,4,4,4) => (0,1,2,3) */
1794 check_orderarray(hwnd
, 0x0123, 0x4444, 0x0123, FALSE
, __LINE__
);
1795 /* (0,1,2,3)->(4,4,1,2) => (0,1,3,2) */
1796 check_orderarray(hwnd
, 0x0123, 0x4412, 0x0132, TRUE
, __LINE__
);
1797 /* (0,1,2,3)->(4,4,4,1) => (0,2,3,1) */
1798 check_orderarray(hwnd
, 0x0123, 0x4441, 0x0231, TRUE
, __LINE__
);
1799 /* (0,1,2,3)->(1,4,4,4) => (1,0,2,3) */
1800 check_orderarray(hwnd
, 0x0123, 0x1444, 0x1023, FALSE
, __LINE__
);
1801 /* (0,1,2,3)->(4,2,4,1) => (0,2,3,1) */
1802 check_orderarray(hwnd
, 0x0123, 0x4241, 0x0231, FALSE
, __LINE__
);
1803 /* (0,1,2,3)->(4,2,0,1) => (2,0,3,1) */
1804 check_orderarray(hwnd
, 0x0123, 0x4201, 0x2031, TRUE
, __LINE__
);
1805 /* (3,2,1,0)->(4,2,0,1) => (3,2,0,1) */
1806 check_orderarray(hwnd
, 0x3210, 0x4201, 0x3201, FALSE
, __LINE__
);
1808 DestroyWindow(hwnd
);
1814 ULONG_PTR ctx_cookie
;
1820 test_header_control();
1821 test_header_order();
1822 test_hdm_orderarray();
1825 DestroyWindow(hHeaderParentWnd
);
1827 init_msg_sequences(sequences
, NUM_MSG_SEQUENCES
);
1828 parent_hwnd
= create_custom_parent_window();
1829 ok_sequence(sequences
, PARENT_SEQ_INDEX
, create_parent_wnd_seq
, "create parent windows", FALSE
);
1831 test_hdm_index_messages(parent_hwnd
);
1832 test_hdm_getitemrect(parent_hwnd
);
1833 test_hdm_hittest(parent_hwnd
);
1834 test_hdm_layout(parent_hwnd
);
1835 test_hdm_ordertoindex(parent_hwnd
);
1836 test_hdm_sethotdivider(parent_hwnd
);
1837 test_hdm_imageMessages(parent_hwnd
);
1838 test_hdm_filterMessages(parent_hwnd
);
1839 test_hdm_unicodeformatMessages(parent_hwnd
);
1840 test_hdm_bitmapmarginMessages(parent_hwnd
);
1842 if (!load_v6_module(&ctx_cookie
, &hCtx
))
1844 DestroyWindow(parent_hwnd
);
1848 /* comctl32 version 6 tests start here */
1849 test_hdf_fixedwidth(parent_hwnd
);
1850 test_hds_nosizing(parent_hwnd
);
1852 unload_v6_module(ctx_cookie
, hCtx
);
1854 DestroyWindow(parent_hwnd
);