ab485e3fa3c28956d8138d835b5e78f91b29cca8
[reactos.git] / rostests / winetests / comctl32 / header.c
1 /* Unit test suite for header control.
2 *
3 * Copyright 2005 Vijay Kiran Kamuju
4 * Copyright 2007 Shanren Zhou
5 *
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.
10 *
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.
15 *
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
19 */
20
21 #define WIN32_NO_STATUS
22 #define _INC_WINDOWS
23 #define COM_NO_WINDOWS_H
24
25 //#include <windows.h>
26 #include <stdarg.h>
27 #include <windef.h>
28 #include <winbase.h>
29 #include <wingdi.h>
30 #include <winuser.h>
31 #include <winnls.h>
32 #include <objbase.h>
33 #include <commctrl.h>
34 #include <assert.h>
35
36 #include <wine/test.h>
37 #include "v6util.h"
38 #include "msg.h"
39
40 typedef struct tagEXPECTEDNOTIFY
41 {
42 INT iCode;
43 BOOL fUnicode;
44 HDITEMA hdItem;
45 } EXPECTEDNOTIFY;
46
47 typedef LRESULT (*CUSTOMDRAWPROC)(int n, NMCUSTOMDRAW *nm);
48
49 static CUSTOMDRAWPROC g_CustomDrawProc;
50 static int g_CustomDrawCount;
51 static DRAWITEMSTRUCT g_DrawItem;
52 static BOOL g_DrawItemReceived;
53 static DWORD g_customheight;
54
55 static EXPECTEDNOTIFY expectedNotify[10];
56 static INT nExpectedNotify = 0;
57 static INT nReceivedNotify = 0;
58 static INT unexpectedNotify[10];
59 static INT nUnexpectedNotify = 0;
60
61 static HWND hHeaderParentWnd;
62 static HWND hWndHeader;
63 #define MAX_CHARS 100
64
65 #define compare(val, exp, fmt) ok((val) == (exp), #val " value: " fmt ", expected: " fmt "\n", (val), (exp))
66
67 #define expect(expected, got) ok(expected == got, "expected %d, got %d\n", expected,got)
68
69 #define NUM_MSG_SEQUENCES 2
70 #define PARENT_SEQ_INDEX 0
71 #define HEADER_SEQ_INDEX 1
72
73 static struct msg_sequence *sequences[NUM_MSG_SEQUENCES];
74
75 static const struct message create_parent_wnd_seq[] = {
76 { WM_GETMINMAXINFO, sent },
77 { WM_NCCREATE, sent },
78 { WM_NCCALCSIZE, sent|wparam, 0 },
79 { WM_CREATE, sent },
80 { 0 }
81 };
82
83 static const struct message add_header_to_parent_seq_interactive[] = {
84 { WM_NOTIFYFORMAT, sent|lparam, 0, NF_QUERY },
85 { WM_QUERYUISTATE, sent },
86 { WM_PARENTNOTIFY, sent|wparam, 1 },
87 { WM_SHOWWINDOW, sent|wparam, 1 },
88 { WM_WINDOWPOSCHANGING, sent|wparam, 0 },
89 { WM_WINDOWPOSCHANGING, sent|wparam, 0 },
90 { WM_ACTIVATEAPP, sent|wparam, 1 },
91 { WM_NCACTIVATE, sent|wparam, 1 },
92 { WM_ACTIVATE, sent|wparam, 1 },
93 { WM_IME_SETCONTEXT, sent|defwinproc|wparam, 1 },
94 { WM_IME_NOTIFY, sent|defwinproc|wparam, 2 },
95 { WM_SETFOCUS, sent|defwinproc|wparam, 0 },
96 { WM_WINDOWPOSCHANGED, sent|wparam, 0 },
97 { WM_SIZE, sent|wparam, 0 },
98 { WM_MOVE, sent|wparam, 0 },
99 { 0 }
100 };
101
102 static const struct message add_header_to_parent_seq[] = {
103 { WM_NOTIFYFORMAT, sent|lparam, 0, NF_QUERY },
104 { WM_QUERYUISTATE, sent|optional },
105 { WM_PARENTNOTIFY, sent },
106 { 0 }
107 };
108
109 static const struct message insertItem_seq[] = {
110 { HDM_INSERTITEMA, sent|wparam, 0 },
111 { HDM_INSERTITEMA, sent|wparam, 1 },
112 { HDM_INSERTITEMA, sent|wparam, 2 },
113 { HDM_INSERTITEMA, sent|wparam, 3 },
114 { 0 }
115 };
116
117 static const struct message getItem_seq[] = {
118 { HDM_GETITEMA, sent|wparam, 3 },
119 { HDM_GETITEMA, sent|wparam, 0 },
120 { 0 }
121 };
122
123
124 static const struct message deleteItem_getItemCount_seq[] = {
125 { HDM_DELETEITEM, sent|wparam, 3 },
126 { HDM_GETITEMCOUNT, sent },
127 { HDM_DELETEITEM, sent|wparam, 3 },
128 { HDM_GETITEMCOUNT, sent },
129 { HDM_DELETEITEM, sent|wparam, 2 },
130 { HDM_GETITEMCOUNT, sent },
131 { 0 }
132 };
133
134 static const struct message orderArray_seq[] = {
135 { HDM_SETORDERARRAY, sent|wparam, 2 },
136 { HDM_GETORDERARRAY, sent|wparam, 2 },
137 { 0 }
138 };
139
140 static const struct message setItem_seq[] = {
141 { HDM_SETITEMA, sent|wparam, 0 },
142 { HDM_SETITEMA, sent|wparam, 1 },
143 { 0 }
144 };
145
146 static const struct message getItemRect_seq[] = {
147 { HDM_GETITEMRECT, sent|wparam, 1 },
148 { HDM_GETITEMRECT, sent|wparam, 0 },
149 { HDM_GETITEMRECT, sent|wparam, 10 },
150 { 0 }
151 };
152
153 static const struct message layout_seq[] = {
154 { HDM_LAYOUT, sent },
155 { 0 }
156 };
157
158 static const struct message orderToIndex_seq[] = {
159 { HDM_ORDERTOINDEX, sent|wparam, 1 },
160 { 0 }
161 };
162
163 static const struct message hittest_seq[] = {
164 { HDM_HITTEST, sent },
165 { HDM_HITTEST, sent },
166 { HDM_HITTEST, sent },
167 { 0 }
168 };
169
170 static const struct message setHotDivider_seq_interactive[] = {
171 { HDM_SETHOTDIVIDER, sent|wparam, TRUE },
172 { WM_PAINT, sent|defwinproc},
173 { WM_NCPAINT, sent|defwinproc},
174 { WM_ERASEBKGND, sent|defwinproc},
175 { HDM_SETHOTDIVIDER, sent|wparam|lparam, FALSE, 100 },
176 { WM_PAINT, sent|defwinproc},
177 { HDM_SETHOTDIVIDER, sent|wparam|lparam, FALSE, 1},
178 { WM_PAINT, sent|defwinproc},
179 { 0 }
180 };
181
182 static const struct message setHotDivider_seq_noninteractive[] = {
183 { HDM_SETHOTDIVIDER, sent|wparam, TRUE },
184 { HDM_SETHOTDIVIDER, sent|wparam|lparam, FALSE, 100 },
185 { HDM_SETHOTDIVIDER, sent|wparam|lparam, FALSE, 1},
186 { 0 }
187 };
188
189 static const struct message imageMessages_seq[] = {
190 { HDM_SETIMAGELIST, sent },
191 { HDM_GETIMAGELIST, sent },
192 { HDM_CREATEDRAGIMAGE, sent },
193 { 0 }
194 };
195
196 static const struct message filterMessages_seq_interactive[] = {
197 { HDM_SETFILTERCHANGETIMEOUT, sent|wparam|lparam, 1, 100 },
198 { HDM_CLEARFILTER, sent|wparam|lparam, 0, 1 },
199 { HDM_EDITFILTER, sent|wparam|lparam, 1, 0 },
200 { WM_PARENTNOTIFY, sent|wparam|defwinproc, WM_CREATE },
201 { WM_CTLCOLOREDIT, sent|defwinproc },
202 { WM_COMMAND, sent|defwinproc },
203 { 0 }
204 };
205
206 static const struct message filterMessages_seq_noninteractive[] = {
207 { HDM_SETFILTERCHANGETIMEOUT, sent|wparam|lparam, 1, 100 },
208 { HDM_CLEARFILTER, sent|wparam|lparam, 0, 1 },
209 { HDM_EDITFILTER, sent|wparam|lparam, 1, 0 },
210 { WM_PARENTNOTIFY, sent|wparam|defwinproc|optional, WM_CREATE },
211 { WM_COMMAND, sent|defwinproc|optional },
212 { 0 }
213 };
214
215 static const struct message unicodeformatMessages_seq[] = {
216 { HDM_SETUNICODEFORMAT, sent|wparam, TRUE },
217 { HDM_GETUNICODEFORMAT, sent },
218 { 0 }
219 };
220
221 static const struct message bitmapmarginMessages_seq[] = {
222 { HDM_GETBITMAPMARGIN, sent },
223 { 0 }
224 };
225
226
227 static void expect_notify(INT iCode, BOOL fUnicode, HDITEMA *lpItem)
228 {
229 ok(nExpectedNotify < 10, "notification count %d\n", nExpectedNotify);
230 if (nExpectedNotify < 10)
231 {
232 expectedNotify[nExpectedNotify].iCode = iCode;
233 expectedNotify[nExpectedNotify].fUnicode = fUnicode;
234 expectedNotify[nExpectedNotify].hdItem = *lpItem;
235 nExpectedNotify++;
236 }
237 }
238
239 static void dont_expect_notify(INT iCode)
240 {
241 ok(nExpectedNotify < 10, "notification count %d\n", nExpectedNotify);
242 if (nExpectedNotify < 10)
243 unexpectedNotify[nUnexpectedNotify++] = iCode;
244 }
245
246 static BOOL notifies_received(void)
247 {
248 BOOL fRet = (nExpectedNotify == nReceivedNotify);
249 nExpectedNotify = nReceivedNotify = 0;
250 nUnexpectedNotify = 0;
251 return fRet;
252 }
253
254 static LONG addItem(HWND hdex, int idx, LPSTR text)
255 {
256 HDITEMA hdItem;
257 hdItem.mask = HDI_TEXT | HDI_WIDTH;
258 hdItem.cxy = 100;
259 hdItem.pszText = text;
260 hdItem.cchTextMax = 0;
261 return SendMessageA(hdex, HDM_INSERTITEMA, idx, (LPARAM)&hdItem);
262 }
263
264 static LONG setItem(HWND hdex, int idx, LPSTR text, BOOL fCheckNotifies)
265 {
266 LONG ret;
267 HDITEMA hdexItem;
268 hdexItem.mask = HDI_TEXT;
269 hdexItem.pszText = text;
270 hdexItem.cchTextMax = 0;
271 if (fCheckNotifies)
272 {
273 expect_notify(HDN_ITEMCHANGINGA, FALSE, &hdexItem);
274 expect_notify(HDN_ITEMCHANGEDA, FALSE, &hdexItem);
275 }
276 ret = SendMessageA(hdex, HDM_SETITEMA, idx, (LPARAM)&hdexItem);
277 if (fCheckNotifies)
278 ok(notifies_received(), "setItem(): not all expected notifies were received\n");
279 return ret;
280 }
281
282 static LONG setItemUnicodeNotify(HWND hdex, int idx, LPSTR text, LPWSTR wText)
283 {
284 LONG ret;
285 HDITEMA hdexItem;
286 HDITEMW hdexNotify;
287 hdexItem.mask = HDI_TEXT;
288 hdexItem.pszText = text;
289 hdexItem.cchTextMax = 0;
290
291 hdexNotify.mask = HDI_TEXT;
292 hdexNotify.pszText = wText;
293
294 expect_notify(HDN_ITEMCHANGINGW, TRUE, (HDITEMA*)&hdexNotify);
295 expect_notify(HDN_ITEMCHANGEDW, TRUE, (HDITEMA*)&hdexNotify);
296 ret = SendMessageA(hdex, HDM_SETITEMA, idx, (LPARAM)&hdexItem);
297 ok(notifies_received(), "setItemUnicodeNotify(): not all expected notifies were received\n");
298 return ret;
299 }
300
301 static LONG delItem(HWND hdex, int idx)
302 {
303 return SendMessageA(hdex, HDM_DELETEITEM, idx, 0);
304 }
305
306 static LONG getItemCount(HWND hdex)
307 {
308 return SendMessageA(hdex, HDM_GETITEMCOUNT, 0, 0);
309 }
310
311 static LONG getItem(HWND hdex, int idx, LPSTR textBuffer)
312 {
313 HDITEMA hdItem;
314 hdItem.mask = HDI_TEXT;
315 hdItem.pszText = textBuffer;
316 hdItem.cchTextMax = MAX_CHARS;
317 return SendMessageA(hdex, HDM_GETITEMA, idx, (LPARAM)&hdItem);
318 }
319
320 static void addReadDelItem(HWND hdex, HDITEMA *phdiCreate, int maskRead, HDITEMA *phdiRead)
321 {
322 ok(SendMessageA(hdex, HDM_INSERTITEMA, 0, (LPARAM)phdiCreate)!=-1, "Adding item failed\n");
323 ZeroMemory(phdiRead, sizeof(HDITEMA));
324 phdiRead->mask = maskRead;
325 ok(SendMessageA(hdex, HDM_GETITEMA, 0, (LPARAM)phdiRead)!=0, "Getting item data failed\n");
326 ok(SendMessageA(hdex, HDM_DELETEITEM, 0, 0)!=0, "Deleting item failed\n");
327 }
328
329 static HWND create_header_control (void)
330 {
331 HWND handle;
332 HDLAYOUT hlayout;
333 RECT rectwin;
334 WINDOWPOS winpos;
335
336 handle = CreateWindowExA(0, WC_HEADERA, NULL,
337 WS_CHILD|WS_BORDER|WS_VISIBLE|HDS_BUTTONS|HDS_HORZ,
338 0, 0, 0, 0,
339 hHeaderParentWnd, NULL, NULL, NULL);
340 ok(handle != NULL, "failed to create header window\n");
341
342 if (winetest_interactive)
343 ShowWindow (hHeaderParentWnd, SW_SHOW);
344
345 GetClientRect(hHeaderParentWnd,&rectwin);
346 hlayout.prc = &rectwin;
347 hlayout.pwpos = &winpos;
348 SendMessageA(handle, HDM_LAYOUT, 0, (LPARAM)&hlayout);
349 SetWindowPos(handle, winpos.hwndInsertAfter, winpos.x, winpos.y,
350 winpos.cx, winpos.cy, 0);
351
352 return handle;
353 }
354
355 static void compare_items(INT iCode, HDITEMA *hdi1, HDITEMA *hdi2, BOOL fUnicode)
356 {
357 ok(hdi1->mask == hdi2->mask, "Notify %d mask mismatch (%08x != %08x)\n", iCode, hdi1->mask, hdi2->mask);
358 if (hdi1->mask & HDI_WIDTH)
359 {
360 ok(hdi1->cxy == hdi2->cxy, "Notify %d cxy mismatch (%08x != %08x)\n", iCode, hdi1->cxy, hdi2->cxy);
361 }
362 if (hdi1->mask & HDI_TEXT)
363 {
364 if (hdi1->pszText == LPSTR_TEXTCALLBACKA)
365 {
366 ok(hdi1->pszText == LPSTR_TEXTCALLBACKA, "Notify %d - only one item is LPSTR_TEXTCALLBACK\n", iCode);
367 }
368 else
369 if (fUnicode)
370 {
371 char buf1[260];
372 char buf2[260];
373 WideCharToMultiByte(CP_ACP, 0, (LPCWSTR)hdi1->pszText, -1, buf1, 260, NULL, NULL);
374 WideCharToMultiByte(CP_ACP, 0, (LPCWSTR)hdi2->pszText, -1, buf2, 260, NULL, NULL);
375 ok(lstrcmpW((LPWSTR)hdi1->pszText, (LPWSTR)hdi2->pszText)==0,
376 "Notify %d text mismatch (L\"%s\" vs L\"%s\")\n",
377 iCode, buf1, buf2);
378 }
379 else
380 {
381 ok(strcmp(hdi1->pszText, hdi2->pszText)==0,
382 "Notify %d text mismatch (\"%s\" vs \"%s\")\n",
383 iCode, hdi1->pszText, hdi2->pszText);
384 }
385 }
386 }
387
388 static char pszFirstItem[] = "First Item";
389 static char pszSecondItem[] = "Second Item";
390 static char pszThirdItem[] = "Third Item";
391 static char pszFourthItem[] = "Fourth Item";
392 static char pszReplaceItem[] = "Replace Item";
393 static char pszOutOfRangeItem[] = "Out Of Range Item";
394
395 static char *str_items[] =
396 {pszFirstItem, pszSecondItem, pszThirdItem, pszFourthItem, pszReplaceItem, pszOutOfRangeItem};
397
398 static char pszUniTestA[] = "TST";
399 static WCHAR pszUniTestW[] = {'T','S','T',0};
400
401
402 #define TEST_GET_ITEM(i,c)\
403 { res = getItem(hWndHeader, i, buffer);\
404 ok(res != 0, "Getting item[%d] using valid index failed unexpectedly (%d)\n", i, res);\
405 ok(strcmp(str_items[c], buffer) == 0, "Getting item[%d] returned \"%s\" expecting \"%s\"\n", i, buffer, str_items[c]);\
406 }
407
408 #define TEST_GET_ITEMCOUNT(i)\
409 { res = getItemCount(hWndHeader);\
410 ok(res == i, "Got Item Count as %d\n", res);\
411 }
412
413 static LRESULT WINAPI header_subclass_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
414 {
415 WNDPROC oldproc = (WNDPROC)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
416 static LONG defwndproc_counter = 0;
417 LRESULT ret;
418 struct message msg;
419
420 msg.message = message;
421 msg.flags = sent|wparam|lparam;
422 if (defwndproc_counter) msg.flags |= defwinproc;
423 msg.wParam = wParam;
424 msg.lParam = lParam;
425 msg.id = 0;
426 add_message(sequences, HEADER_SEQ_INDEX, &msg);
427
428 defwndproc_counter++;
429 ret = CallWindowProcA(oldproc, hwnd, message, wParam, lParam);
430 defwndproc_counter--;
431
432 return ret;
433 }
434
435 static LRESULT WINAPI parent_wnd_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
436 {
437 static LONG defwndproc_counter = 0;
438 LRESULT ret;
439 struct message msg;
440
441 /* do not log painting messages */
442 if (message != WM_PAINT &&
443 message != WM_ERASEBKGND &&
444 message != WM_NCPAINT &&
445 message != WM_NCHITTEST &&
446 message != WM_GETTEXT &&
447 message != WM_GETICON &&
448 message != WM_DEVICECHANGE)
449
450 {
451 msg.message = message;
452 msg.flags = sent|wparam|lparam;
453 if (defwndproc_counter) msg.flags |= defwinproc;
454 msg.wParam = wParam;
455 msg.lParam = lParam;
456 msg.id = 0;
457 add_message(sequences, PARENT_SEQ_INDEX, &msg);
458 }
459
460 defwndproc_counter++;
461 ret = DefWindowProcA(hwnd, message, wParam, lParam);
462 defwndproc_counter--;
463
464 return ret;
465 }
466
467 static BOOL register_parent_wnd_class(void)
468 {
469 WNDCLASSA cls;
470
471 cls.style = 0;
472 cls.lpfnWndProc = parent_wnd_proc;
473 cls.cbClsExtra = 0;
474 cls.cbWndExtra = 0;
475 cls.hInstance = GetModuleHandleA(NULL);
476 cls.hIcon = 0;
477 cls.hCursor = LoadCursorA(0, (LPCSTR)IDC_ARROW);
478 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
479 cls.lpszMenuName = NULL;
480 cls.lpszClassName = "Header test parent class";
481 return RegisterClassA(&cls);
482 }
483
484 static HWND create_custom_parent_window(void)
485 {
486 if (!register_parent_wnd_class())
487 return NULL;
488
489 return CreateWindowExA(0, "Header test parent class", "Header Message Sequence Testing",
490 WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT,
491 672+2*GetSystemMetrics(SM_CXSIZEFRAME),
492 226+GetSystemMetrics(SM_CYCAPTION)+2*GetSystemMetrics(SM_CYSIZEFRAME),
493 NULL, NULL, GetModuleHandleA(NULL), 0);
494 }
495
496 static HWND create_custom_header_control(HWND hParent, BOOL preloadHeaderItems)
497 {
498 WNDPROC oldproc;
499 HWND childHandle;
500 HDLAYOUT hlayout;
501 RECT rectwin;
502 WINDOWPOS winpos;
503 int retVal;
504 int loopcnt;
505 static char firstHeaderItem[] = "Name";
506 static char secondHeaderItem[] = "Size";
507 static char *items[] = {secondHeaderItem, firstHeaderItem};
508 HDITEMA hdItem;
509 hdItem.mask = HDI_TEXT | HDI_WIDTH | HDI_FORMAT;
510 hdItem.fmt = HDF_LEFT;
511 hdItem.cxy = 80;
512 hdItem.cchTextMax = 260;
513
514 flush_sequences(sequences, NUM_MSG_SEQUENCES);
515
516 childHandle = CreateWindowExA(0, WC_HEADERA, NULL,
517 WS_CHILD|WS_BORDER|WS_VISIBLE|HDS_BUTTONS|HDS_HORZ,
518 0, 0, 0, 0,
519 hParent, NULL, NULL, NULL);
520 ok(childHandle != NULL, "failed to create child window\n");
521 if (preloadHeaderItems)
522 {
523 for ( loopcnt = 0 ; loopcnt < 2 ; loopcnt++ )
524 {
525 hdItem.pszText = items[loopcnt];
526 retVal = SendMessageA(childHandle, HDM_INSERTITEMA, loopcnt, (LPARAM) &hdItem);
527 ok(retVal == loopcnt, "Adding item %d failed with return value %d\n", ( loopcnt + 1 ), retVal);
528 }
529 }
530
531 if (winetest_interactive)
532 ShowWindow (hParent, SW_SHOW);
533
534 GetClientRect(hParent,&rectwin);
535 hlayout.prc = &rectwin;
536 hlayout.pwpos = &winpos;
537 SendMessageA(childHandle,HDM_LAYOUT,0,(LPARAM) &hlayout);
538 SetWindowPos(childHandle, winpos.hwndInsertAfter, winpos.x, winpos.y,
539 winpos.cx, winpos.cy, 0);
540
541 oldproc = (WNDPROC)SetWindowLongPtrA(childHandle, GWLP_WNDPROC,
542 (LONG_PTR)header_subclass_proc);
543 SetWindowLongPtrA(childHandle, GWLP_USERDATA, (LONG_PTR)oldproc);
544 return childHandle;
545 }
546
547 static void check_auto_format(void)
548 {
549 HDITEMA hdiCreate;
550 HDITEMA hdiRead;
551 static CHAR text[] = "Test";
552 ZeroMemory(&hdiCreate, sizeof(HDITEMA));
553
554 /* Windows implicitly sets some format bits in INSERTITEM */
555
556 /* HDF_STRING is automatically set and cleared for no text */
557 hdiCreate.mask = HDI_TEXT|HDI_WIDTH|HDI_FORMAT;
558 hdiCreate.pszText = text;
559 hdiCreate.cxy = 100;
560 hdiCreate.fmt=HDF_CENTER;
561 addReadDelItem(hWndHeader, &hdiCreate, HDI_FORMAT, &hdiRead);
562 ok(hdiRead.fmt == (HDF_STRING|HDF_CENTER), "HDF_STRING not set automatically (fmt=%x)\n", hdiRead.fmt);
563
564 hdiCreate.mask = HDI_WIDTH|HDI_FORMAT;
565 hdiCreate.pszText = text;
566 hdiCreate.fmt = HDF_CENTER|HDF_STRING;
567 addReadDelItem(hWndHeader, &hdiCreate, HDI_FORMAT, &hdiRead);
568 ok(hdiRead.fmt == (HDF_CENTER), "HDF_STRING should be automatically cleared (fmt=%x)\n", hdiRead.fmt);
569
570 /* HDF_BITMAP is automatically set and cleared for a NULL bitmap or no bitmap */
571 hdiCreate.mask = HDI_BITMAP|HDI_WIDTH|HDI_FORMAT;
572 hdiCreate.hbm = CreateBitmap(16, 16, 1, 8, NULL);
573 hdiCreate.fmt = HDF_CENTER;
574 addReadDelItem(hWndHeader, &hdiCreate, HDI_FORMAT, &hdiRead);
575 ok(hdiRead.fmt == (HDF_BITMAP|HDF_CENTER), "HDF_BITMAP not set automatically (fmt=%x)\n", hdiRead.fmt);
576 DeleteObject(hdiCreate.hbm);
577
578 hdiCreate.hbm = NULL;
579 hdiCreate.fmt = HDF_CENTER|HDF_BITMAP;
580 addReadDelItem(hWndHeader, &hdiCreate, HDI_FORMAT, &hdiRead);
581 ok(hdiRead.fmt == HDF_CENTER, "HDF_BITMAP not cleared automatically for NULL bitmap (fmt=%x)\n", hdiRead.fmt);
582
583 hdiCreate.mask = HDI_WIDTH|HDI_FORMAT;
584 hdiCreate.fmt = HDF_CENTER|HDF_BITMAP;
585 addReadDelItem(hWndHeader, &hdiCreate, HDI_FORMAT, &hdiRead);
586 ok(hdiRead.fmt == HDF_CENTER, "HDF_BITMAP not cleared automatically for no bitmap (fmt=%x)\n", hdiRead.fmt);
587
588 /* HDF_IMAGE is automatically set but not cleared */
589 hdiCreate.mask = HDI_IMAGE|HDI_WIDTH|HDI_FORMAT;
590 hdiCreate.iImage = 17;
591 addReadDelItem(hWndHeader, &hdiCreate, HDI_FORMAT, &hdiRead);
592 ok(hdiRead.fmt == (HDF_IMAGE|HDF_CENTER), "HDF_IMAGE not set automatically (fmt=%x)\n", hdiRead.fmt);
593
594 hdiCreate.mask = HDI_WIDTH|HDI_FORMAT;
595 hdiCreate.fmt = HDF_CENTER|HDF_IMAGE;
596 hdiCreate.iImage = 0;
597 addReadDelItem(hWndHeader, &hdiCreate, HDI_FORMAT, &hdiRead);
598 ok(hdiRead.fmt == (HDF_CENTER|HDF_IMAGE), "HDF_IMAGE shouldn't be cleared automatically (fmt=%x)\n", hdiRead.fmt);
599 }
600
601 static void check_auto_fields(void)
602 {
603 HDITEMA hdiCreate;
604 HDITEMA hdiRead;
605 static CHAR text[] = "Test";
606 LONG res;
607
608 /* Windows stores the format, width, lparam even if they are not in the item's mask */
609 ZeroMemory(&hdiCreate, sizeof(HDITEMA));
610 hdiCreate.mask = HDI_TEXT;
611 hdiCreate.cxy = 100;
612 hdiCreate.pszText = text;
613 addReadDelItem(hWndHeader, &hdiCreate, HDI_WIDTH, &hdiRead);
614 TEST_GET_ITEMCOUNT(6);
615 ok(hdiRead.cxy == hdiCreate.cxy, "cxy should be automatically set\n");
616
617 ZeroMemory(&hdiCreate, sizeof(HDITEMA));
618 hdiCreate.mask = HDI_TEXT;
619 hdiCreate.pszText = text;
620 hdiCreate.lParam = 0x12345678;
621 addReadDelItem(hWndHeader, &hdiCreate, HDI_LPARAM, &hdiRead);
622 TEST_GET_ITEMCOUNT(6);
623 ok(hdiRead.lParam == hdiCreate.lParam, "lParam should be automatically set\n");
624
625 ZeroMemory(&hdiCreate, sizeof(HDITEMA));
626 hdiCreate.mask = HDI_TEXT;
627 hdiCreate.pszText = text;
628 hdiCreate.fmt = HDF_STRING|HDF_CENTER;
629 addReadDelItem(hWndHeader, &hdiCreate, HDI_FORMAT, &hdiRead);
630 TEST_GET_ITEMCOUNT(6);
631 ok(hdiRead.fmt == hdiCreate.fmt, "fmt should be automatically set\n");
632
633 /* others fields are not set */
634 ZeroMemory(&hdiCreate, sizeof(HDITEMA));
635 hdiCreate.mask = HDI_TEXT;
636 hdiCreate.pszText = text;
637 hdiCreate.hbm = CreateBitmap(16, 16, 1, 8, NULL);
638 addReadDelItem(hWndHeader, &hdiCreate, HDI_BITMAP, &hdiRead);
639 TEST_GET_ITEMCOUNT(6);
640 ok(hdiRead.hbm == NULL, "hbm should not be automatically set\n");
641 DeleteObject(hdiCreate.hbm);
642
643 ZeroMemory(&hdiCreate, sizeof(HDITEMA));
644 hdiCreate.mask = HDI_IMAGE;
645 hdiCreate.iImage = 17;
646 hdiCreate.pszText = text;
647 addReadDelItem(hWndHeader, &hdiCreate, HDI_TEXT, &hdiRead);
648 TEST_GET_ITEMCOUNT(6);
649 ok(hdiRead.pszText==NULL, "pszText shouldn't be automatically set\n");
650
651 /* field from comctl >4.0 not tested as the system probably won't touch them */
652 }
653
654 static void check_mask(void)
655 {
656 HDITEMA hdi;
657 static CHAR text[] = "ABC";
658 LRESULT ret;
659
660 /* don't create items if the mask is zero */
661 ZeroMemory(&hdi, sizeof(hdi));
662 hdi.mask = 0;
663 hdi.cxy = 200;
664 hdi.pszText = text;
665 hdi.fmt = 0;
666 hdi.iOrder = 0;
667 hdi.lParam = 17;
668 hdi.cchTextMax = 260;
669 ret = SendMessageA(hWndHeader, HDM_INSERTITEMA, 0, (LPARAM)&hdi);
670 ok(ret == -1, "Creating an item with a zero mask should have failed\n");
671 if (ret != -1) SendMessageA(hWndHeader, HDM_DELETEITEM, 0, 0);
672
673 /* with a non-zero mask creation will succeed */
674 ZeroMemory(&hdi, sizeof(hdi));
675 hdi.mask = HDI_LPARAM;
676 ret = SendMessageA(hWndHeader, HDM_INSERTITEMA, 0, (LPARAM)&hdi);
677 ok(ret != -1, "Adding item with non-zero mask failed\n");
678 if (ret != -1)
679 SendMessageA(hWndHeader, HDM_DELETEITEM, 0, 0);
680
681 /* in SETITEM if the mask contains a unknown bit, it is ignored */
682 ZeroMemory(&hdi, sizeof(hdi));
683 hdi.mask = 0x08000000 | HDI_LPARAM | HDI_IMAGE;
684 hdi.lParam = 133;
685 hdi.iImage = 17;
686 ret = SendMessageA(hWndHeader, HDM_INSERTITEMA, 0, (LPARAM)&hdi);
687 ok(ret != -1, "Adding item failed\n");
688
689 if (ret != -1)
690 {
691 /* check result */
692 ZeroMemory(&hdi, sizeof(hdi));
693 hdi.mask = HDI_LPARAM | HDI_IMAGE;
694 SendMessageA(hWndHeader, HDM_GETITEMA, 0, (LPARAM)&hdi);
695 ok(hdi.lParam == 133, "comctl32 4.0 field not set\n");
696 ok(hdi.iImage == 17, "comctl32 >4.0 field not set\n");
697
698 /* but in GETITEM if an unknown bit is set, comctl32 uses only version 4.0 fields */
699 ZeroMemory(&hdi, sizeof(hdi));
700 hdi.mask = 0x08000000 | HDI_LPARAM | HDI_IMAGE;
701 SendMessageA(hWndHeader, HDM_GETITEMA, 0, (LPARAM)&hdi);
702 ok(hdi.lParam == 133, "comctl32 4.0 field not read\n");
703 ok(hdi.iImage == 0, "comctl32 >4.0 field shouldn't be read\n");
704
705 SendMessageA(hWndHeader, HDM_DELETEITEM, 0, 0);
706 }
707 }
708
709 static void test_header_control (void)
710 {
711 LONG res;
712 static char buffer[MAX_CHARS];
713 int i;
714
715 hWndHeader = create_header_control ();
716
717 for (i = 3; i >= 0; i--)
718 {
719 TEST_GET_ITEMCOUNT(3-i);
720 res = addItem(hWndHeader, 0, str_items[i]);
721 ok(res == 0, "Adding simple item failed (%d)\n", res);
722 }
723
724 TEST_GET_ITEMCOUNT(4);
725 res = addItem(hWndHeader, 99, str_items[i+1]);
726 ok(res != -1, "Adding Out of Range item should fail with -1 got (%d)\n", res);
727 TEST_GET_ITEMCOUNT(5);
728 res = addItem(hWndHeader, 5, str_items[i+1]);
729 ok(res != -1, "Adding Out of Range item should fail with -1 got (%d)\n", res);
730 TEST_GET_ITEMCOUNT(6);
731
732 for (i = 0; i < 4; i++) { TEST_GET_ITEM(i,i); TEST_GET_ITEMCOUNT(6); }
733
734 res=getItem(hWndHeader, 99, buffer);
735 ok(res == 0, "Getting Out of Range item should fail with 0 (%d), got %s\n", res,buffer);
736 res=getItem(hWndHeader, 5, buffer);
737 ok(res == 1, "Getting Out of Range item should fail with 1 (%d), got %s\n", res,buffer);
738 res=getItem(hWndHeader, -2, buffer);
739 ok(res == 0, "Getting Out of Range item should fail with 0 (%d), got %s\n", res,buffer);
740
741 if (winetest_interactive)
742 {
743 UpdateWindow(hHeaderParentWnd);
744 UpdateWindow(hWndHeader);
745 }
746
747 TEST_GET_ITEMCOUNT(6);
748 res=setItem(hWndHeader, 99, str_items[5], FALSE);
749 ok(res == 0, "Setting Out of Range item should fail with 0 (%d)\n", res);
750 res=setItem(hWndHeader, 5, str_items[5], TRUE);
751 ok(res == 1, "Setting Out of Range item should fail with 1 (%d)\n", res);
752 res=setItem(hWndHeader, -2, str_items[5], FALSE);
753 ok(res == 0, "Setting Out of Range item should fail with 0 (%d)\n", res);
754 TEST_GET_ITEMCOUNT(6);
755
756 for (i = 0; i < 4; i++)
757 {
758 res = setItem(hWndHeader, i, str_items[4], TRUE);
759 ok(res != 0, "Setting %d item failed (%d)\n", i+1, res);
760 TEST_GET_ITEM(i, 4);
761 TEST_GET_ITEMCOUNT(6);
762 }
763
764 SendMessageA(hWndHeader, HDM_SETUNICODEFORMAT, TRUE, 0);
765 setItemUnicodeNotify(hWndHeader, 3, pszUniTestA, pszUniTestW);
766 SendMessageA(hWndHeader, WM_NOTIFYFORMAT, (WPARAM)hHeaderParentWnd, NF_REQUERY);
767 setItem(hWndHeader, 3, str_items[4], TRUE);
768
769 dont_expect_notify(HDN_GETDISPINFOA);
770 dont_expect_notify(HDN_GETDISPINFOW);
771 addItem(hWndHeader, 0, LPSTR_TEXTCALLBACKA);
772 setItem(hWndHeader, 0, str_items[4], TRUE);
773 /* unexpected notifies cleared by notifies_received in setItem */
774 dont_expect_notify(HDN_GETDISPINFOA);
775 dont_expect_notify(HDN_GETDISPINFOW);
776 setItem(hWndHeader, 0, LPSTR_TEXTCALLBACKA, TRUE);
777 /* unexpected notifies cleared by notifies_received in setItem */
778 delItem(hWndHeader, 0);
779
780 check_auto_format();
781 TEST_GET_ITEMCOUNT(6);
782 check_auto_fields();
783 TEST_GET_ITEMCOUNT(6);
784 check_mask();
785 TEST_GET_ITEMCOUNT(6);
786
787 res = delItem(hWndHeader, 5);
788 ok(res == 1, "Deleting Out of Range item should fail with 1 (%d)\n", res);
789 res = delItem(hWndHeader, -2);
790 ok(res == 0, "Deleting Out of Range item should fail with 0 (%d)\n", res);
791 TEST_GET_ITEMCOUNT(5);
792
793 res = delItem(hWndHeader, 3);
794 ok(res != 0, "Deleting using out of range index failed (%d)\n", res);
795 TEST_GET_ITEMCOUNT(4);
796 res = delItem(hWndHeader, 0);
797 ok(res != 0, "Deleting using out of range index failed (%d)\n", res);
798 TEST_GET_ITEMCOUNT(3);
799 res = delItem(hWndHeader, 0);
800 ok(res != 0, "Deleting using out of range index failed (%d)\n", res);
801 TEST_GET_ITEMCOUNT(2);
802 res = delItem(hWndHeader, 0);
803 ok(res != 0, "Deleting using out of range index failed (%d)\n", res);
804 TEST_GET_ITEMCOUNT(1);
805
806 DestroyWindow(hWndHeader);
807 }
808
809 static void test_hdm_getitemrect(HWND hParent)
810 {
811
812 HWND hChild;
813 RECT rect;
814 int retVal;
815
816 flush_sequences(sequences, NUM_MSG_SEQUENCES);
817 hChild = create_custom_header_control(hParent, TRUE);
818 ok_sequence(sequences, PARENT_SEQ_INDEX, add_header_to_parent_seq,
819 "adder header control to parent", FALSE);
820
821 retVal = SendMessageA(hChild, HDM_GETITEMRECT, 1, (LPARAM) &rect);
822 ok(retVal == TRUE, "Getting item rect should TRUE, got %d\n", retVal);
823 /* check bounding rectangle information of 2nd header item */
824 expect(80, rect.left);
825 expect(0, rect.top);
826 expect(160, rect.right);
827 expect(g_customheight, rect.bottom);
828
829 retVal = SendMessageA(hChild, HDM_GETITEMRECT, 0, (LPARAM) &rect);
830
831 ok(retVal == TRUE, "Getting item rect should TRUE, got %d\n", retVal);
832 /* check bounding rectangle information of 1st header item */
833 expect(0, rect.left);
834 expect(0, rect.top);
835
836 expect(80, rect.right);
837 expect(g_customheight, rect.bottom);
838
839 retVal = SendMessageA(hChild, HDM_GETITEMRECT, 10, (LPARAM) &rect);
840 ok(retVal == 0, "Getting rect of nonexistent item should return 0, got %d\n", retVal);
841
842 ok_sequence(sequences, HEADER_SEQ_INDEX, getItemRect_seq, "getItemRect sequence testing", FALSE);
843 DestroyWindow(hChild);
844 }
845
846 static void test_hdm_layout(HWND hParent)
847 {
848 HWND hChild;
849 int retVal;
850 RECT rect;
851 HDLAYOUT hdLayout;
852 WINDOWPOS windowPos;
853 hdLayout.prc = &rect;
854 hdLayout.pwpos = &windowPos;
855
856 flush_sequences(sequences, NUM_MSG_SEQUENCES);
857 hChild = create_custom_header_control(hParent, TRUE);
858 ok_sequence(sequences, PARENT_SEQ_INDEX, add_header_to_parent_seq,
859 "adder header control to parent", FALSE);
860
861 flush_sequences(sequences, NUM_MSG_SEQUENCES);
862 retVal = SendMessageA(hChild, HDM_LAYOUT, 0, (LPARAM) &hdLayout);
863 expect(TRUE, retVal);
864
865 ok_sequence(sequences, HEADER_SEQ_INDEX, layout_seq, "layout sequence testing", FALSE);
866
867 DestroyWindow(hChild);
868 }
869
870 static void test_hdm_ordertoindex(HWND hParent)
871 {
872 HWND hChild;
873 int retVal;
874
875 flush_sequences(sequences, NUM_MSG_SEQUENCES);
876 hChild = create_custom_header_control(hParent, TRUE);
877 ok_sequence(sequences, PARENT_SEQ_INDEX, add_header_to_parent_seq,
878 "adder header control to parent", FALSE);
879
880 flush_sequences(sequences, NUM_MSG_SEQUENCES);
881 retVal = SendMessageA(hChild, HDM_ORDERTOINDEX, 1, 0);
882 expect(1, retVal);
883
884 ok_sequence(sequences, HEADER_SEQ_INDEX, orderToIndex_seq, "orderToIndex sequence testing", FALSE);
885 DestroyWindow(hChild);
886 }
887
888 static void test_hdm_hittest(HWND hParent)
889 {
890 HWND hChild;
891 int retVal;
892 POINT pt;
893 HDHITTESTINFO hdHitTestInfo;
894 const int firstItemRightBoundary = 80;
895 const int secondItemRightBoundary = 160;
896 const int bottomBoundary = g_customheight;
897
898 pt.x = firstItemRightBoundary - 1;
899 pt.y = bottomBoundary - 1;
900 hdHitTestInfo.pt = pt;
901
902
903 flush_sequences(sequences, NUM_MSG_SEQUENCES);
904 hChild = create_custom_header_control(hParent, TRUE);
905 ok_sequence(sequences, PARENT_SEQ_INDEX, add_header_to_parent_seq,
906 "adder header control to parent", FALSE);
907
908 flush_sequences(sequences, NUM_MSG_SEQUENCES);
909 retVal = SendMessageA(hChild, HDM_HITTEST, 0, (LPARAM) &hdHitTestInfo);
910 expect(0, retVal);
911 expect(0, hdHitTestInfo.iItem);
912 expect(HHT_ONDIVIDER, hdHitTestInfo.flags);
913
914 pt.x = secondItemRightBoundary - 1;
915 pt.y = bottomBoundary - 1;
916 hdHitTestInfo.pt = pt;
917 retVal = SendMessageA(hChild, HDM_HITTEST, 1, (LPARAM) &hdHitTestInfo);
918 expect(1, retVal);
919 expect(1, hdHitTestInfo.iItem);
920 expect(HHT_ONDIVIDER, hdHitTestInfo.flags);
921
922 pt.x = secondItemRightBoundary;
923 pt.y = bottomBoundary + 1;
924 hdHitTestInfo.pt = pt;
925 retVal = SendMessageA(hChild, HDM_HITTEST, 0, (LPARAM) &hdHitTestInfo);
926 expect(-1, retVal);
927 expect(-1, hdHitTestInfo.iItem);
928 expect(HHT_BELOW, hdHitTestInfo.flags);
929
930 ok_sequence(sequences, HEADER_SEQ_INDEX, hittest_seq, "hittest sequence testing", FALSE);
931
932 DestroyWindow(hChild);
933 }
934
935 static void test_hdm_sethotdivider(HWND hParent)
936 {
937 HWND hChild;
938 int retVal;
939 /* low word: x coordinate = 5
940 * high word: y coordinate = 5
941 */
942
943 flush_sequences(sequences, NUM_MSG_SEQUENCES);
944 hChild = create_custom_header_control(hParent, TRUE);
945 ok_sequence(sequences, PARENT_SEQ_INDEX, add_header_to_parent_seq,
946 "adder header control to parent", FALSE);
947
948 flush_sequences(sequences, NUM_MSG_SEQUENCES);
949 retVal = SendMessageA(hChild, HDM_SETHOTDIVIDER, TRUE, MAKELPARAM(5, 5));
950 expect(0, retVal);
951
952 retVal = SendMessageA(hChild, HDM_SETHOTDIVIDER, FALSE, 100);
953 expect(100, retVal);
954 retVal = SendMessageA(hChild, HDM_SETHOTDIVIDER, FALSE, 1);
955 expect(1, retVal);
956 if (winetest_interactive)
957 ok_sequence(sequences, HEADER_SEQ_INDEX, setHotDivider_seq_interactive,
958 "setHotDivider sequence testing", TRUE);
959 else
960 ok_sequence(sequences, HEADER_SEQ_INDEX, setHotDivider_seq_noninteractive,
961 "setHotDivider sequence testing", FALSE);
962
963 DestroyWindow(hChild);
964 }
965
966 static void test_hdm_imageMessages(HWND hParent)
967 {
968 HIMAGELIST hImageList = ImageList_Create (4, 4, 0, 1, 0);
969 HIMAGELIST hIml;
970 BOOL wasValid;
971 HWND hChild;
972
973 flush_sequences(sequences, NUM_MSG_SEQUENCES);
974 hChild = create_custom_header_control(hParent, TRUE);
975 ok_sequence(sequences, PARENT_SEQ_INDEX, add_header_to_parent_seq,
976 "adder header control to parent", FALSE);
977
978 flush_sequences(sequences, NUM_MSG_SEQUENCES);
979
980 hIml = (HIMAGELIST) SendMessageA(hChild, HDM_SETIMAGELIST, 0, (LPARAM) hImageList);
981 ok(hIml == NULL, "Expected NULL, got %p\n", hIml);
982
983 hIml = (HIMAGELIST) SendMessageA(hChild, HDM_GETIMAGELIST, 0, 0);
984 ok(hIml != NULL, "Expected non-NULL handle, got %p\n", hIml);
985
986 hIml = (HIMAGELIST) SendMessageA(hChild, HDM_CREATEDRAGIMAGE, 0, 0);
987 ok(hIml != NULL, "Expected non-NULL handle, got %p\n", hIml);
988 ImageList_Destroy(hIml);
989
990 ok_sequence(sequences, HEADER_SEQ_INDEX, imageMessages_seq, "imageMessages sequence testing", FALSE);
991
992 DestroyWindow(hChild);
993
994 wasValid = ImageList_Destroy(hImageList);
995 ok(wasValid, "Header must not free image list at destruction!\n");
996 }
997
998 static void test_hdm_filterMessages(HWND hParent)
999 {
1000 HWND hChild;
1001 int retVal, timeout;
1002
1003 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1004 hChild = create_custom_header_control(hParent, TRUE);
1005 ok_sequence(sequences, PARENT_SEQ_INDEX, add_header_to_parent_seq,
1006 "adder header control to parent", FALSE);
1007
1008 timeout = SendMessageA(hChild, HDM_SETFILTERCHANGETIMEOUT, 0, 0);
1009 ok(timeout == 1000, "got %d\n", timeout);
1010
1011 timeout = SendMessageA(hChild, HDM_SETFILTERCHANGETIMEOUT, 0, 0);
1012 ok(timeout == 1000, "got %d\n", timeout);
1013
1014 timeout = SendMessageA(hChild, HDM_SETFILTERCHANGETIMEOUT, 0, -100);
1015 ok(timeout == 1000, "got %d\n", timeout);
1016
1017 timeout = SendMessageA(hChild, HDM_SETFILTERCHANGETIMEOUT, 1, 100);
1018 ok(timeout == -100, "got %d\n", timeout);
1019 retVal = SendMessageA(hChild, HDM_SETFILTERCHANGETIMEOUT, 1, timeout);
1020 ok(retVal == 100, "got %d\n", retVal);
1021
1022 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1023
1024 /* msdn incorrectly states that return value
1025 * is the index of the filter control being
1026 * modified. The sendMessage here should
1027 * return previous filter timeout value
1028 */
1029
1030 retVal = SendMessageA(hChild, HDM_SETFILTERCHANGETIMEOUT, 1, 100);
1031 expect(timeout, retVal);
1032
1033 todo_wine
1034 {
1035 retVal = SendMessageA(hChild, HDM_CLEARFILTER, 0, 1);
1036 if (retVal == 0)
1037 win_skip("HDM_CLEARFILTER needs 5.80\n");
1038 else
1039 expect(1, retVal);
1040
1041 retVal = SendMessageA(hChild, HDM_EDITFILTER, 1, 0);
1042 if (retVal == 0)
1043 win_skip("HDM_EDITFILTER needs 5.80\n");
1044 else
1045 expect(1, retVal);
1046 }
1047 if (winetest_interactive)
1048 ok_sequence(sequences, HEADER_SEQ_INDEX, filterMessages_seq_interactive,
1049 "filterMessages sequence testing", TRUE);
1050 else
1051 ok_sequence(sequences, HEADER_SEQ_INDEX, filterMessages_seq_noninteractive,
1052 "filterMessages sequence testing", FALSE);
1053 DestroyWindow(hChild);
1054
1055 }
1056
1057 static void test_hdm_unicodeformatMessages(HWND hParent)
1058 {
1059 HWND hChild;
1060 int retVal;
1061
1062 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1063 hChild = create_custom_header_control(hParent, TRUE);
1064 ok_sequence(sequences, PARENT_SEQ_INDEX, add_header_to_parent_seq,
1065 "adder header control to parent", FALSE);
1066
1067 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1068 retVal = SendMessageA(hChild, HDM_SETUNICODEFORMAT, TRUE, 0);
1069 expect(0, retVal);
1070 retVal = SendMessageA(hChild, HDM_GETUNICODEFORMAT, 0, 0);
1071 expect(1, retVal);
1072
1073 ok_sequence(sequences, HEADER_SEQ_INDEX, unicodeformatMessages_seq,
1074 "unicodeformatMessages sequence testing", FALSE);
1075 DestroyWindow(hChild);
1076 }
1077
1078 static void test_hdm_bitmapmarginMessages(HWND hParent)
1079 {
1080 HWND hChild;
1081 int retVal;
1082
1083 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1084 hChild = create_custom_header_control(hParent, TRUE);
1085 ok_sequence(sequences, PARENT_SEQ_INDEX, add_header_to_parent_seq,
1086 "adder header control to parent", FALSE);
1087
1088 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1089 retVal = SendMessageA(hChild, HDM_GETBITMAPMARGIN, 0, 0);
1090 if (retVal == 0)
1091 win_skip("HDM_GETBITMAPMARGIN needs 5.80\n");
1092 else
1093 expect(6, retVal);
1094
1095 ok_sequence(sequences, HEADER_SEQ_INDEX, bitmapmarginMessages_seq,
1096 "bitmapmarginMessages sequence testing", FALSE);
1097 DestroyWindow(hChild);
1098 }
1099
1100 static void test_hdm_index_messages(HWND hParent)
1101 {
1102 HWND hChild;
1103 int retVal, i, iSize;
1104 static const int lpiarray[2] = {1, 0};
1105 static const char *item_texts[] = {
1106 "Name", "Size", "Type", "Date Modified"
1107 };
1108 RECT rect;
1109 HDITEMA hdItem;
1110 char buffA[32];
1111 int array[2];
1112
1113 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1114 hChild = create_custom_header_control(hParent, FALSE);
1115 if (winetest_interactive)
1116 ok_sequence(sequences, PARENT_SEQ_INDEX, add_header_to_parent_seq_interactive,
1117 "adder header control to parent", TRUE);
1118 else
1119 ok_sequence(sequences, PARENT_SEQ_INDEX, add_header_to_parent_seq,
1120 "adder header control to parent", FALSE);
1121 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1122 for (i = 0; i < sizeof(item_texts)/sizeof(item_texts[0]); i++)
1123 {
1124 hdItem.mask = HDI_TEXT | HDI_WIDTH | HDI_FORMAT;
1125 hdItem.pszText = (char*)item_texts[i];
1126 hdItem.fmt = HDF_LEFT;
1127 hdItem.cxy = 80;
1128
1129 retVal = SendMessageA(hChild, HDM_INSERTITEMA, i, (LPARAM) &hdItem);
1130 ok(retVal == i, "Adding item %d failed with return value %d\n", i, retVal);
1131 }
1132 ok_sequence(sequences, HEADER_SEQ_INDEX, insertItem_seq, "insertItem sequence testing", FALSE);
1133
1134 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1135
1136 retVal = SendMessageA(hChild, HDM_DELETEITEM, 3, (LPARAM) &hdItem);
1137 ok(retVal == TRUE, "Deleting item 3 should return TRUE, got %d\n", retVal);
1138 retVal = SendMessageA(hChild, HDM_GETITEMCOUNT, 0, 0);
1139 ok(retVal == 3, "Getting item count should return 3, got %d\n", retVal);
1140
1141 retVal = SendMessageA(hChild, HDM_DELETEITEM, 3, (LPARAM) &hdItem);
1142 ok(retVal == FALSE, "Deleting already-deleted item should return FALSE, got %d\n", retVal);
1143 retVal = SendMessageA(hChild, HDM_GETITEMCOUNT, 0, 0);
1144 ok(retVal == 3, "Getting item count should return 3, got %d\n", retVal);
1145
1146 retVal = SendMessageA(hChild, HDM_DELETEITEM, 2, (LPARAM) &hdItem);
1147 ok(retVal == TRUE, "Deleting item 2 should return TRUE, got %d\n", retVal);
1148 retVal = SendMessageA(hChild, HDM_GETITEMCOUNT, 0, 0);
1149 ok(retVal == 2, "Getting item count should return 2, got %d\n", retVal);
1150
1151 ok_sequence(sequences, HEADER_SEQ_INDEX, deleteItem_getItemCount_seq,
1152 "deleteItem_getItemCount sequence testing", FALSE);
1153
1154 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1155
1156 hdItem.mask = HDI_WIDTH;
1157 retVal = SendMessageA(hChild, HDM_GETITEMA, 3, (LPARAM) &hdItem);
1158 ok(retVal == FALSE, "Getting already-deleted item should return FALSE, got %d\n", retVal);
1159
1160 hdItem.mask = HDI_TEXT | HDI_WIDTH;
1161 hdItem.pszText = buffA;
1162 hdItem.cchTextMax = sizeof(buffA)/sizeof(buffA[0]);
1163 retVal = SendMessageA(hChild, HDM_GETITEMA, 0, (LPARAM) &hdItem);
1164 ok(retVal == TRUE, "Getting the 1st header item should return TRUE, got %d\n", retVal);
1165
1166 ok_sequence(sequences, HEADER_SEQ_INDEX, getItem_seq, "getItem sequence testing", FALSE);
1167
1168 /* check if the item is the right one */
1169 ok(!strcmp(hdItem.pszText, item_texts[0]), "got wrong item %s, expected %s\n",
1170 hdItem.pszText, item_texts[0]);
1171 expect(80, hdItem.cxy);
1172
1173 iSize = SendMessageA(hChild, HDM_GETITEMCOUNT, 0, 0);
1174
1175 /* item should be updated just after accepting new array */
1176 ShowWindow(hChild, SW_HIDE);
1177 retVal = SendMessageA(hChild, HDM_SETORDERARRAY, iSize, (LPARAM) lpiarray);
1178 expect(TRUE, retVal);
1179 rect.left = 0;
1180 retVal = SendMessageA(hChild, HDM_GETITEMRECT, 0, (LPARAM) &rect);
1181 expect(TRUE, retVal);
1182 ok(rect.left != 0, "Expected updated rectangle\n");
1183
1184 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1185
1186 retVal = SendMessageA(hChild, HDM_SETORDERARRAY, iSize, (LPARAM) lpiarray);
1187 ok(retVal == TRUE, "Setting header items order should return TRUE, got %d\n", retVal);
1188
1189 retVal = SendMessageA(hChild, HDM_GETORDERARRAY, 2, (LPARAM) array);
1190 ok(retVal == TRUE, "Getting header items order should return TRUE, got %d\n", retVal);
1191
1192 ok_sequence(sequences, HEADER_SEQ_INDEX, orderArray_seq, "set_get_orderArray sequence testing", FALSE);
1193
1194 /* check if the array order is set correctly and the size of the array is correct. */
1195 expect(2, iSize);
1196 ok(lpiarray[0] == array[0], "got %d, expected %d\n", array[0], lpiarray[0]);
1197 ok(lpiarray[1] == array[1], "got %d, expected %d\n", array[1], lpiarray[1]);
1198
1199 hdItem.mask = HDI_FORMAT;
1200 hdItem.fmt = HDF_CENTER | HDF_STRING;
1201
1202 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1203
1204 retVal = SendMessageA(hChild, HDM_SETITEMA, 0, (LPARAM) &hdItem);
1205 ok(retVal == TRUE, "Aligning 1st header item to center should return TRUE, got %d\n", retVal);
1206 hdItem.fmt = HDF_RIGHT | HDF_STRING;
1207 retVal = SendMessageA(hChild, HDM_SETITEMA, 1, (LPARAM) &hdItem);
1208 ok(retVal == TRUE, "Aligning 2nd header item to right should return TRUE, got %d\n", retVal);
1209
1210 ok_sequence(sequences, HEADER_SEQ_INDEX, setItem_seq, "setItem sequence testing", FALSE);
1211 DestroyWindow(hChild);
1212 }
1213
1214 static void test_hdf_fixedwidth(HWND hParent)
1215 {
1216 HWND hChild;
1217 HDITEMA hdItem;
1218 DWORD ret;
1219 RECT rect;
1220 HDHITTESTINFO ht;
1221
1222 hChild = create_custom_header_control(hParent, FALSE);
1223
1224 hdItem.mask = HDI_WIDTH | HDI_FORMAT;
1225 hdItem.fmt = HDF_FIXEDWIDTH;
1226 hdItem.cxy = 80;
1227
1228 ret = SendMessageA(hChild, HDM_INSERTITEMA, 0, (LPARAM)&hdItem);
1229 expect(0, ret);
1230
1231 /* try to change width */
1232 rect.right = rect.bottom = 0;
1233 SendMessageA(hChild, HDM_GETITEMRECT, 0, (LPARAM)&rect);
1234 ok(rect.right != 0, "Expected not zero width\n");
1235 ok(rect.bottom != 0, "Expected not zero height\n");
1236
1237 SendMessageA(hChild, WM_LBUTTONDOWN, 0, MAKELPARAM(rect.right, rect.bottom / 2));
1238 SendMessageA(hChild, WM_MOUSEMOVE, 0, MAKELPARAM(rect.right + 20, rect.bottom / 2));
1239 SendMessageA(hChild, WM_LBUTTONUP, 0, MAKELPARAM(rect.right + 20, rect.bottom / 2));
1240
1241 SendMessageA(hChild, HDM_GETITEMRECT, 0, (LPARAM)&rect);
1242
1243 if (hdItem.cxy != rect.right)
1244 {
1245 win_skip("HDF_FIXEDWIDTH format not supported\n");
1246 DestroyWindow(hChild);
1247 return;
1248 }
1249
1250 /* try to adjust with message */
1251 hdItem.mask = HDI_WIDTH;
1252 hdItem.cxy = 90;
1253
1254 ret = SendMessageA(hChild, HDM_SETITEMA, 0, (LPARAM)&hdItem);
1255 expect(TRUE, ret);
1256
1257 rect.right = 0;
1258 SendMessageA(hChild, HDM_GETITEMRECT, 0, (LPARAM)&rect);
1259 expect(90, rect.right);
1260
1261 /* hittesting doesn't report ondivider flag for HDF_FIXEDWIDTH */
1262 ht.pt.x = rect.right - 1;
1263 ht.pt.y = rect.bottom / 2;
1264 SendMessageA(hChild, HDM_HITTEST, 0, (LPARAM)&ht);
1265 expect(HHT_ONHEADER, ht.flags);
1266
1267 /* try to adjust with message */
1268 hdItem.mask = HDI_FORMAT;
1269 hdItem.fmt = 0;
1270
1271 ret = SendMessageA(hChild, HDM_SETITEMA, 0, (LPARAM)&hdItem);
1272 expect(TRUE, ret);
1273
1274 ht.pt.x = 90;
1275 ht.pt.y = rect.bottom / 2;
1276 SendMessageA(hChild, HDM_HITTEST, 0, (LPARAM)&ht);
1277 expect(HHT_ONDIVIDER, ht.flags);
1278
1279 DestroyWindow(hChild);
1280 }
1281
1282 static void test_hds_nosizing(HWND hParent)
1283 {
1284 HWND hChild;
1285 HDITEMA hdItem;
1286 DWORD ret;
1287 RECT rect;
1288 HDHITTESTINFO ht;
1289
1290 hChild = create_custom_header_control(hParent, FALSE);
1291
1292 memset(&hdItem, 0, sizeof(hdItem));
1293 hdItem.mask = HDI_WIDTH;
1294 hdItem.cxy = 80;
1295
1296 ret = SendMessageA(hChild, HDM_INSERTITEMA, 0, (LPARAM)&hdItem);
1297 expect(0, ret);
1298
1299 /* HDS_NOSIZING only blocks hittesting */
1300 ret = GetWindowLongA(hChild, GWL_STYLE);
1301 SetWindowLongA(hChild, GWL_STYLE, ret | HDS_NOSIZING);
1302
1303 /* try to change width with mouse gestures */
1304 rect.right = rect.bottom = 0;
1305 SendMessageA(hChild, HDM_GETITEMRECT, 0, (LPARAM)&rect);
1306 ok(rect.right != 0, "Expected not zero width\n");
1307 ok(rect.bottom != 0, "Expected not zero height\n");
1308
1309 SendMessageA(hChild, WM_LBUTTONDOWN, 0, MAKELPARAM(rect.right, rect.bottom / 2));
1310 SendMessageA(hChild, WM_MOUSEMOVE, 0, MAKELPARAM(rect.right + 20, rect.bottom / 2));
1311 SendMessageA(hChild, WM_LBUTTONUP, 0, MAKELPARAM(rect.right + 20, rect.bottom / 2));
1312
1313 SendMessageA(hChild, HDM_GETITEMRECT, 0, (LPARAM)&rect);
1314
1315 if (hdItem.cxy != rect.right)
1316 {
1317 win_skip("HDS_NOSIZING style not supported\n");
1318 DestroyWindow(hChild);
1319 return;
1320 }
1321
1322 /* this style doesn't set HDF_FIXEDWIDTH for items */
1323 hdItem.mask = HDI_FORMAT;
1324 ret = SendMessageA(hChild, HDM_GETITEMA, 0, (LPARAM)&hdItem);
1325 expect(TRUE, ret);
1326 ok(!(hdItem.fmt & HDF_FIXEDWIDTH), "Unexpected HDF_FIXEDWIDTH\n");
1327
1328 /* try to adjust with message */
1329 hdItem.mask = HDI_WIDTH;
1330 hdItem.cxy = 90;
1331
1332 ret = SendMessageA(hChild, HDM_SETITEMA, 0, (LPARAM)&hdItem);
1333 expect(TRUE, ret);
1334
1335 rect.right = 0;
1336 SendMessageA(hChild, HDM_GETITEMRECT, 0, (LPARAM)&rect);
1337 expect(90, rect.right);
1338
1339 /* hittesting doesn't report ondivider flags for HDS_NOSIZING */
1340 ht.pt.x = rect.right - 1;
1341 ht.pt.y = rect.bottom / 2;
1342 SendMessageA(hChild, HDM_HITTEST, 0, (LPARAM)&ht);
1343 expect(HHT_ONHEADER, ht.flags);
1344
1345 /* try to adjust with message */
1346 ret = GetWindowLongA(hChild, GWL_STYLE);
1347 SetWindowLongA(hChild, GWL_STYLE, ret & ~HDS_NOSIZING);
1348
1349 ht.pt.x = 90;
1350 ht.pt.y = rect.bottom / 2;
1351 SendMessageA(hChild, HDM_HITTEST, 0, (LPARAM)&ht);
1352 expect(HHT_ONDIVIDER, ht.flags);
1353
1354 DestroyWindow(hChild);
1355 }
1356
1357 #define TEST_NMCUSTOMDRAW(draw_stage, item_spec, lparam, _left, _top, _right, _bottom) \
1358 ok(nm->dwDrawStage == draw_stage, "Invalid dwDrawStage %d vs %d\n", draw_stage, nm->dwDrawStage); \
1359 if (item_spec != -1) \
1360 ok(nm->dwItemSpec == item_spec, "Invalid dwItemSpec %d vs %ld\n", item_spec, nm->dwItemSpec); \
1361 ok(nm->lItemlParam == lparam, "Invalid lItemlParam %d vs %ld\n", lparam, nm->lItemlParam); \
1362 ok((nm->rc.top == _top && nm->rc.bottom == _bottom && nm->rc.left == _left && nm->rc.right == _right) || \
1363 broken(draw_stage != CDDS_ITEMPREPAINT), /* comctl32 < 5.80 */ \
1364 "Invalid rect (%d,%d)-(%d,%d) vs %s\n", _left, _top, _right, _bottom, \
1365 wine_dbgstr_rect(&nm->rc));
1366
1367 static LRESULT customdraw_1(int n, NMCUSTOMDRAW *nm)
1368 {
1369 if (nm == NULL) { /* test ended */
1370 ok(n==1, "NM_CUSTOMDRAW messages: %d, expected: 1\n", n);
1371 return 0;
1372 }
1373
1374 switch (n)
1375 {
1376 case 0:
1377 /* don't test dwItemSpec - it's 0 no comctl5 but 1308756 on comctl6 */
1378 TEST_NMCUSTOMDRAW(CDDS_PREPAINT, -1, 0, 0, 0, 670, g_customheight);
1379 return 0;
1380 }
1381
1382 ok(FALSE, "Too many custom draw messages (n=%d, nm->dwDrawStage=%d)\n", n, nm->dwDrawStage);
1383 return -1;
1384 }
1385
1386 static LRESULT customdraw_2(int n, NMCUSTOMDRAW *nm)
1387 {
1388 if (nm == NULL) { /* test ended */
1389 ok(n==4, "NM_CUSTOMDRAW messages: %d, expected: 4\n", n);
1390 return 0;
1391 }
1392
1393 switch (n)
1394 {
1395 case 0:
1396 TEST_NMCUSTOMDRAW(CDDS_PREPAINT, -1, 0, 0, 0, 670, g_customheight);
1397 return CDRF_NOTIFYITEMDRAW;
1398 case 1:
1399 TEST_NMCUSTOMDRAW(CDDS_ITEMPREPAINT, 0, 0, 0, 0, 50, g_customheight);
1400 return 0;
1401 case 2:
1402 TEST_NMCUSTOMDRAW(CDDS_ITEMPREPAINT, 1, 5, 50, 0, 150, g_customheight);
1403 return 0;
1404 case 3:
1405 TEST_NMCUSTOMDRAW(CDDS_ITEMPREPAINT, 2, 10, 150, 0, 300, g_customheight);
1406 return 0;
1407 }
1408
1409 ok(FALSE, "Too many custom draw messages (n=%d, nm->dwDrawStage=%d)\n", n, nm->dwDrawStage);
1410 return 0;
1411 }
1412
1413 static LRESULT customdraw_3(int n, NMCUSTOMDRAW *nm)
1414 {
1415 if (nm == NULL) { /* test ended */
1416 ok(n==5, "NM_CUSTOMDRAW messages: %d, expected: 5\n", n);
1417 return 0;
1418 }
1419
1420 switch (n)
1421 {
1422 case 0:
1423 TEST_NMCUSTOMDRAW(CDDS_PREPAINT, -1, 0, 0, 0, 670, g_customheight);
1424 return CDRF_NOTIFYITEMDRAW|CDRF_NOTIFYPOSTERASE|CDRF_NOTIFYPOSTPAINT|CDRF_SKIPDEFAULT;
1425 case 1:
1426 TEST_NMCUSTOMDRAW(CDDS_ITEMPREPAINT, 0, 0, 0, 0, 50, g_customheight);
1427 return 0;
1428 case 2:
1429 TEST_NMCUSTOMDRAW(CDDS_ITEMPREPAINT, 1, 5, 50, 0, 150, g_customheight);
1430 return 0;
1431 case 3:
1432 TEST_NMCUSTOMDRAW(CDDS_ITEMPREPAINT, 2, 10, 150, 0, 300, g_customheight);
1433 return 0;
1434 case 4:
1435 TEST_NMCUSTOMDRAW(CDDS_POSTPAINT, -1, 0, 0, 0, 670, g_customheight);
1436 return 0;
1437 }
1438
1439 ok(FALSE, "Too many custom draw messages (n=%d, nm->dwDrawStage=%d)\n", n, nm->dwDrawStage);
1440 return 0;
1441 }
1442
1443
1444 static LRESULT customdraw_4(int n, NMCUSTOMDRAW *nm)
1445 {
1446 if (nm == NULL) { /* test ended */
1447 ok(n==4, "NM_CUSTOMDRAW messages: %d, expected: 4\n", n);
1448 return 0;
1449 }
1450
1451 switch (n)
1452 {
1453 case 0:
1454 TEST_NMCUSTOMDRAW(CDDS_PREPAINT, -1, 0, 0, 0, 670, g_customheight);
1455 return CDRF_NOTIFYITEMDRAW|CDRF_NOTIFYPOSTPAINT;
1456 case 1:
1457 TEST_NMCUSTOMDRAW(CDDS_ITEMPREPAINT, 0, 0, 0, 0, 50, g_customheight);
1458 return 0;
1459 case 2:
1460 TEST_NMCUSTOMDRAW(CDDS_ITEMPREPAINT, 2, 10, 150, 0, 300, g_customheight);
1461 return 0;
1462 case 3:
1463 TEST_NMCUSTOMDRAW(CDDS_POSTPAINT, -1, 0, 0, 0, 670, g_customheight);
1464 return 0;
1465 }
1466
1467 ok(FALSE, "Too many custom draw messages (n=%d, nm->dwDrawStage=%d)\n", n, nm->dwDrawStage);
1468 return 0;
1469 }
1470
1471 static void run_customdraw_scenario(CUSTOMDRAWPROC proc)
1472 {
1473 g_CustomDrawProc = proc;
1474 g_CustomDrawCount = 0;
1475 InvalidateRect(hWndHeader, NULL, TRUE);
1476 UpdateWindow(hWndHeader);
1477 proc(g_CustomDrawCount, NULL);
1478 g_CustomDrawProc = NULL;
1479 }
1480
1481 static void test_customdraw(void)
1482 {
1483 int i;
1484 HDITEMA item;
1485 RECT rect;
1486 CHAR name[] = "Test";
1487 hWndHeader = create_header_control();
1488 GetClientRect(hWndHeader, &rect);
1489 ok(rect.right - rect.left == 670 && rect.bottom - rect.top == g_customheight,
1490 "Tests will fail as header size is %dx%d instead of 670x%d\n",
1491 rect.right - rect.left, rect.bottom - rect.top, g_customheight);
1492
1493 for (i = 0; i < 3; i++)
1494 {
1495 ZeroMemory(&item, sizeof(item));
1496 item.mask = HDI_TEXT|HDI_WIDTH;
1497 item.cxy = 50*(i+1);
1498 item.pszText = name;
1499 item.lParam = i*5;
1500 SendMessageA(hWndHeader, HDM_INSERTITEMA, i, (LPARAM)&item);
1501 }
1502
1503 run_customdraw_scenario(customdraw_1);
1504 run_customdraw_scenario(customdraw_2);
1505 run_customdraw_scenario(customdraw_3);
1506
1507 ZeroMemory(&item, sizeof(item));
1508 item.mask = HDI_FORMAT;
1509 item.fmt = HDF_OWNERDRAW;
1510 SendMessageA(hWndHeader, HDM_SETITEMA, 1, (LPARAM)&item);
1511 g_DrawItem.CtlID = 0;
1512 g_DrawItem.CtlType = ODT_HEADER;
1513 g_DrawItem.hwndItem = hWndHeader;
1514 g_DrawItem.itemID = 1;
1515 g_DrawItem.itemState = 0;
1516 SendMessageA(hWndHeader, HDM_GETITEMRECT, 1, (LPARAM)&g_DrawItem.rcItem);
1517 run_customdraw_scenario(customdraw_4);
1518 ok(g_DrawItemReceived, "WM_DRAWITEM not received\n");
1519 DestroyWindow(hWndHeader);
1520 hWndHeader = NULL;
1521 g_DrawItem.CtlType = 0;
1522 g_DrawItemReceived = FALSE;
1523 }
1524
1525 static void check_order(const int expected_id[], const int expected_order[],
1526 int count, const char *type)
1527 {
1528 int i;
1529 HDITEMA hdi;
1530
1531 ok(getItemCount(hWndHeader) == count, "Invalid item count in order tests\n");
1532 for (i = 0; i < count; i++)
1533 {
1534 hdi.mask = HDI_LPARAM|HDI_ORDER;
1535 SendMessageA(hWndHeader, HDM_GETITEMA, i, (LPARAM)&hdi);
1536 ok(hdi.lParam == expected_id[i],
1537 "Invalid item ids after '%s'- item %d has lParam %d\n", type, i, (int)hdi.lParam);
1538 ok(hdi.iOrder == expected_order[i],
1539 "Invalid item order after '%s'- item %d has iOrder %d\n", type, i, hdi.iOrder);
1540 }
1541 }
1542
1543 static void test_header_order (void)
1544 {
1545 const int rand1[] = {0, 1, 1, 0, 4};
1546 const int rand2[] = {4, 5, 6, 7, 4};
1547 const int rand3[] = {5, 5, 1, 6, 1};
1548 const int rand4[] = {1, 5, 2, 7, 6, 1, 4, 2, 3, 2};
1549 const int rand5[] = {7, 8, 5, 6, 7, 2, 1, 9, 10, 10};
1550 const int rand6[] = {2, 8, 3, 4, 0};
1551
1552 const int ids1[] = {3, 0, 2, 1, 4};
1553 const int ord1[] = {0, 1, 2, 3, 4};
1554 const int ids2[] = {3, 9, 7, 0, 2, 1, 4, 8, 6, 5};
1555 const int ord2[] = {0, 4, 7, 1, 2, 3, 9, 8, 6, 5};
1556 const int ord3[] = {0, 3, 9, 2, 1, 8, 7, 6, 5, 4};
1557 const int ids4[] = {9, 0, 1, 8, 6};
1558 const int ord4[] = {1, 0, 4, 3, 2};
1559
1560 char buffer[20];
1561 HDITEMA hdi;
1562 int i;
1563
1564 hWndHeader = create_header_control();
1565
1566 ZeroMemory(&hdi, sizeof(HDITEMA));
1567 hdi.mask = HDI_TEXT | HDI_LPARAM;
1568 hdi.pszText = buffer;
1569 strcpy(buffer, "test");
1570
1571 for (i = 0; i < 5; i++)
1572 {
1573 hdi.lParam = i;
1574 SendMessageA(hWndHeader, HDM_INSERTITEMA, rand1[i], (LPARAM)&hdi);
1575 rand();
1576 }
1577 check_order(ids1, ord1, 5, "insert without iOrder");
1578
1579 hdi.mask |= HDI_ORDER;
1580 for (i = 0; i < 5; i++)
1581 {
1582 hdi.lParam = i + 5;
1583 hdi.iOrder = rand2[i];
1584 SendMessageA(hWndHeader, HDM_INSERTITEMA, rand3[i], (LPARAM)&hdi);
1585 rand(); rand();
1586 }
1587 check_order(ids2, ord2, 10, "insert with order");
1588
1589 hdi.mask = HDI_ORDER;
1590 for (i=0; i<10; i++)
1591 {
1592 hdi.iOrder = rand5[i];
1593 SendMessageA(hWndHeader, HDM_SETITEMA, rand4[i], (LPARAM)&hdi);
1594 rand(); rand();
1595 }
1596 check_order(ids2, ord3, 10, "setitems changing order");
1597
1598 for (i=0; i<5; i++)
1599 SendMessageA(hWndHeader, HDM_DELETEITEM, rand6[i], 0);
1600 check_order(ids4, ord4, 5, "deleteitem");
1601
1602 DestroyWindow(hWndHeader);
1603 }
1604
1605 static LRESULT CALLBACK HeaderTestWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
1606 {
1607 DRAWITEMSTRUCT *di;
1608 switch(msg) {
1609
1610 case WM_NOTIFY:
1611 {
1612 NMHEADERA *hdr = (NMHEADERA*)lParam;
1613 EXPECTEDNOTIFY *expected;
1614 int i;
1615
1616 if (hdr->hdr.code == NM_CUSTOMDRAW)
1617 if (g_CustomDrawProc)
1618 return g_CustomDrawProc(g_CustomDrawCount++, (NMCUSTOMDRAW*)hdr);
1619
1620 for (i=0; i<nUnexpectedNotify; i++)
1621 ok(hdr->hdr.code != unexpectedNotify[i], "Received invalid notify %d\n", hdr->hdr.code);
1622
1623 if (nReceivedNotify >= nExpectedNotify || hdr->hdr.hwndFrom != hWndHeader )
1624 break;
1625
1626 expected = &expectedNotify[nReceivedNotify];
1627 if (hdr->hdr.code != expected->iCode)
1628 break;
1629
1630 nReceivedNotify++;
1631 compare_items(hdr->hdr.code, &expected->hdItem, hdr->pitem, expected->fUnicode);
1632 break;
1633 }
1634
1635 case WM_DRAWITEM:
1636 di = (DRAWITEMSTRUCT *)lParam;
1637 ok(g_DrawItem.CtlType != 0, "Unexpected WM_DRAWITEM\n");
1638 if (g_DrawItem.CtlType == 0) return 0;
1639 g_DrawItemReceived = TRUE;
1640 compare(di->CtlType, g_DrawItem.CtlType, "%d");
1641 compare(di->CtlID, g_DrawItem.CtlID, "%d");
1642 compare(di->hwndItem, g_DrawItem.hwndItem, "%p");
1643 compare(di->itemID, g_DrawItem.itemID, "%d");
1644 compare(di->itemState, g_DrawItem.itemState, "%d");
1645 compare(di->rcItem.left, g_DrawItem.rcItem.left, "%d");
1646 compare(di->rcItem.top, g_DrawItem.rcItem.top, "%d");
1647 compare(di->rcItem.right, g_DrawItem.rcItem.right, "%d");
1648 compare(di->rcItem.bottom, g_DrawItem.rcItem.bottom, "%d");
1649 break;
1650
1651 case WM_DESTROY:
1652 PostQuitMessage(0);
1653 break;
1654
1655 default:
1656 return DefWindowProcA(hWnd, msg, wParam, lParam);
1657 }
1658
1659 return 0L;
1660 }
1661
1662 static BOOL init(void)
1663 {
1664 HMODULE hComctl32;
1665 BOOL (WINAPI *pInitCommonControlsEx)(const INITCOMMONCONTROLSEX*);
1666 WNDCLASSA wc;
1667 INITCOMMONCONTROLSEX iccex;
1668 TEXTMETRICA tm;
1669 HFONT hOldFont;
1670 HDC hdc;
1671
1672 hComctl32 = GetModuleHandleA("comctl32.dll");
1673 pInitCommonControlsEx = (void*)GetProcAddress(hComctl32, "InitCommonControlsEx");
1674 if (!pInitCommonControlsEx)
1675 {
1676 win_skip("InitCommonControlsEx() is missing. Skipping the tests\n");
1677 return FALSE;
1678 }
1679
1680 iccex.dwSize = sizeof(iccex);
1681 iccex.dwICC = ICC_USEREX_CLASSES;
1682 pInitCommonControlsEx(&iccex);
1683
1684 wc.style = CS_HREDRAW | CS_VREDRAW;
1685 wc.cbClsExtra = 0;
1686 wc.cbWndExtra = 0;
1687 wc.hInstance = GetModuleHandleA(NULL);
1688 wc.hIcon = NULL;
1689 wc.hCursor = LoadCursorA(NULL, (LPCSTR)IDC_ARROW);
1690 wc.hbrBackground = GetSysColorBrush(COLOR_WINDOW);
1691 wc.lpszMenuName = NULL;
1692 wc.lpszClassName = "HeaderTestClass";
1693 wc.lpfnWndProc = HeaderTestWndProc;
1694 RegisterClassA(&wc);
1695
1696 /* The height of the header control depends on the height of the system font.
1697 The height of the system font is dpi dependent */
1698 hdc = GetDC(0);
1699 hOldFont = SelectObject(hdc, GetStockObject(SYSTEM_FONT));
1700 GetTextMetricsA(hdc, &tm);
1701 /* 2 dot extra space are needed for the border */
1702 g_customheight = tm.tmHeight + 2;
1703 trace("customdraw height: %d (dpi: %d)\n", g_customheight, GetDeviceCaps(hdc, LOGPIXELSY));
1704 SelectObject(hdc, hOldFont);
1705 ReleaseDC(0, hdc);
1706
1707 hHeaderParentWnd = CreateWindowExA(0, "HeaderTestClass", "Header test", WS_OVERLAPPEDWINDOW,
1708 CW_USEDEFAULT, CW_USEDEFAULT, 672+2*GetSystemMetrics(SM_CXSIZEFRAME),
1709 226+GetSystemMetrics(SM_CYCAPTION)+2*GetSystemMetrics(SM_CYSIZEFRAME),
1710 NULL, NULL, GetModuleHandleA(NULL), 0);
1711 ok(hHeaderParentWnd != NULL, "failed to create parent wnd\n");
1712
1713 ShowWindow(hHeaderParentWnd, SW_SHOW);
1714 return hHeaderParentWnd != NULL;
1715 }
1716
1717 /* maximum 8 items allowed */
1718 static void check_orderarray(HWND hwnd, DWORD start, DWORD set, DWORD expected,
1719 BOOL todo, int line)
1720 {
1721 int count, i;
1722 INT order[8];
1723 DWORD ret, array = 0;
1724
1725 count = SendMessageA(hwnd, HDM_GETITEMCOUNT, 0, 0);
1726
1727 /* initial order */
1728 for(i = 1; i<=count; i++)
1729 order[i-1] = start>>(4*(count-i)) & 0xf;
1730
1731 ret = SendMessageA(hwnd, HDM_SETORDERARRAY, count, (LPARAM)order);
1732 ok_(__FILE__, line)(ret, "Expected HDM_SETORDERARRAY to succeed, got %d\n", ret);
1733
1734 /* new order */
1735 for(i = 1; i<=count; i++)
1736 order[i-1] = set>>(4*(count-i)) & 0xf;
1737 ret = SendMessageA(hwnd, HDM_SETORDERARRAY, count, (LPARAM)order);
1738 ok_(__FILE__, line)(ret, "Expected HDM_SETORDERARRAY to succeed, got %d\n", ret);
1739
1740 /* check actual order */
1741 ret = SendMessageA(hwnd, HDM_GETORDERARRAY, count, (LPARAM)order);
1742 ok_(__FILE__, line)(ret, "Expected HDM_GETORDERARRAY to succeed, got %d\n", ret);
1743 for(i = 1; i<=count; i++)
1744 array |= order[i-1]<<(4*(count-i));
1745
1746 todo_wine_if(todo)
1747 ok_(__FILE__, line)(array == expected, "Expected %x, got %x\n", expected, array);
1748 }
1749
1750 static void test_hdm_orderarray(void)
1751 {
1752 HWND hwnd;
1753 INT order[5];
1754 DWORD ret;
1755
1756 hwnd = create_header_control();
1757
1758 /* three items */
1759 addItem(hwnd, 0, NULL);
1760 addItem(hwnd, 1, NULL);
1761 addItem(hwnd, 2, NULL);
1762
1763 ret = SendMessageA(hwnd, HDM_GETORDERARRAY, 3, (LPARAM)order);
1764 if (!ret)
1765 {
1766 win_skip("HDM_GETORDERARRAY not implemented.\n");
1767 DestroyWindow(hwnd);
1768 return;
1769 }
1770
1771 expect(0, order[0]);
1772 expect(1, order[1]);
1773 expect(2, order[2]);
1774
1775 if (0)
1776 {
1777 /* null pointer, crashes native */
1778 ret = SendMessageA(hwnd, HDM_SETORDERARRAY, 3, 0);
1779 expect(FALSE, ret);
1780 }
1781 /* count out of limits */
1782 ret = SendMessageA(hwnd, HDM_SETORDERARRAY, 5, (LPARAM)order);
1783 expect(FALSE, ret);
1784 /* count out of limits */
1785 ret = SendMessageA(hwnd, HDM_SETORDERARRAY, 2, (LPARAM)order);
1786 expect(FALSE, ret);
1787
1788 /* try with out of range item index */
1789 /* (0,1,2)->(1,0,3) => (1,0,2) */
1790 check_orderarray(hwnd, 0x120, 0x103, 0x102, FALSE, __LINE__);
1791 /* (1,0,2)->(3,0,1) => (0,2,1) */
1792 check_orderarray(hwnd, 0x102, 0x301, 0x021, TRUE, __LINE__);
1793 /* (0,2,1)->(2,3,1) => (2,0,1) */
1794 check_orderarray(hwnd, 0x021, 0x231, 0x201, FALSE, __LINE__);
1795
1796 /* (0,1,2)->(0,2,2) => (0,1,2) */
1797 check_orderarray(hwnd, 0x012, 0x022, 0x012, FALSE, __LINE__);
1798
1799 addItem(hwnd, 3, NULL);
1800
1801 /* (0,1,2,3)->(0,1,2,2) => (0,1,3,2) */
1802 check_orderarray(hwnd, 0x0123, 0x0122, 0x0132, FALSE, __LINE__);
1803 /* (0,1,2,3)->(0,1,3,3) => (0,1,2,3) */
1804 check_orderarray(hwnd, 0x0123, 0x0133, 0x0123, FALSE, __LINE__);
1805 /* (0,1,2,3)->(0,4,2,3) => (0,1,2,3) */
1806 check_orderarray(hwnd, 0x0123, 0x0423, 0x0123, FALSE, __LINE__);
1807 /* (0,1,2,3)->(4,0,1,2) => (0,1,3,2) */
1808 check_orderarray(hwnd, 0x0123, 0x4012, 0x0132, TRUE, __LINE__);
1809 /* (0,1,3,2)->(4,0,1,4) => (0,3,1,2) */
1810 check_orderarray(hwnd, 0x0132, 0x4014, 0x0312, TRUE, __LINE__);
1811 /* (0,1,2,3)->(4,1,0,2) => (1,0,3,2) */
1812 check_orderarray(hwnd, 0x0123, 0x4102, 0x1032, TRUE, __LINE__);
1813 /* (0,1,2,3)->(0,1,4,2) => (0,1,2,3) */
1814 check_orderarray(hwnd, 0x0123, 0x0142, 0x0132, FALSE, __LINE__);
1815 /* (0,1,2,3)->(4,4,4,4) => (0,1,2,3) */
1816 check_orderarray(hwnd, 0x0123, 0x4444, 0x0123, FALSE, __LINE__);
1817 /* (0,1,2,3)->(4,4,1,2) => (0,1,3,2) */
1818 check_orderarray(hwnd, 0x0123, 0x4412, 0x0132, TRUE, __LINE__);
1819 /* (0,1,2,3)->(4,4,4,1) => (0,2,3,1) */
1820 check_orderarray(hwnd, 0x0123, 0x4441, 0x0231, TRUE, __LINE__);
1821 /* (0,1,2,3)->(1,4,4,4) => (1,0,2,3) */
1822 check_orderarray(hwnd, 0x0123, 0x1444, 0x1023, FALSE, __LINE__);
1823 /* (0,1,2,3)->(4,2,4,1) => (0,2,3,1) */
1824 check_orderarray(hwnd, 0x0123, 0x4241, 0x0231, FALSE, __LINE__);
1825 /* (0,1,2,3)->(4,2,0,1) => (2,0,3,1) */
1826 check_orderarray(hwnd, 0x0123, 0x4201, 0x2031, TRUE, __LINE__);
1827 /* (3,2,1,0)->(4,2,0,1) => (3,2,0,1) */
1828 check_orderarray(hwnd, 0x3210, 0x4201, 0x3201, FALSE, __LINE__);
1829
1830 DestroyWindow(hwnd);
1831 }
1832
1833 START_TEST(header)
1834 {
1835 HWND parent_hwnd;
1836 ULONG_PTR ctx_cookie;
1837 HANDLE hCtx;
1838
1839 if (!init())
1840 return;
1841
1842 test_header_control();
1843 test_header_order();
1844 test_hdm_orderarray();
1845 test_customdraw();
1846
1847 DestroyWindow(hHeaderParentWnd);
1848
1849 init_msg_sequences(sequences, NUM_MSG_SEQUENCES);
1850 parent_hwnd = create_custom_parent_window();
1851 ok_sequence(sequences, PARENT_SEQ_INDEX, create_parent_wnd_seq, "create parent windows", FALSE);
1852
1853 test_hdm_index_messages(parent_hwnd);
1854 test_hdm_getitemrect(parent_hwnd);
1855 test_hdm_hittest(parent_hwnd);
1856 test_hdm_layout(parent_hwnd);
1857 test_hdm_ordertoindex(parent_hwnd);
1858 test_hdm_sethotdivider(parent_hwnd);
1859 test_hdm_imageMessages(parent_hwnd);
1860 test_hdm_filterMessages(parent_hwnd);
1861 test_hdm_unicodeformatMessages(parent_hwnd);
1862 test_hdm_bitmapmarginMessages(parent_hwnd);
1863
1864 if (!load_v6_module(&ctx_cookie, &hCtx))
1865 {
1866 DestroyWindow(parent_hwnd);
1867 return;
1868 }
1869
1870 /* comctl32 version 6 tests start here */
1871 test_hdf_fixedwidth(parent_hwnd);
1872 test_hds_nosizing(parent_hwnd);
1873
1874 unload_v6_module(ctx_cookie, hCtx);
1875
1876 DestroyWindow(parent_hwnd);
1877 }