comctl32/header: Always update rectangles after HDM_SETORDERARRAY.
[wine] / dlls / comctl32 / tests / 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
22 #include <windows.h>
23 #include <commctrl.h>
24 #include <assert.h>
25
26 #include "wine/test.h"
27 #include "msg.h"
28
29 typedef struct tagEXPECTEDNOTIFY
30 {
31     INT iCode;
32     BOOL fUnicode;
33     HDITEMA hdItem;
34 } EXPECTEDNOTIFY;
35
36 typedef LRESULT (*CUSTOMDRAWPROC)(int n, NMCUSTOMDRAW *nm);
37
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;
43
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;
49
50 static HWND hHeaderParentWnd;
51 static HWND hWndHeader;
52 #define MAX_CHARS 100
53
54 #define compare(val, exp, fmt)  ok((val) == (exp), #val " value: " fmt ", expected: " fmt "\n", (val), (exp))
55
56 #define expect(expected, got) ok(expected == got, "expected %d, got %d\n", expected,got)
57
58 #define NUM_MSG_SEQUENCES    2
59 #define PARENT_SEQ_INDEX     0
60 #define HEADER_SEQ_INDEX     1
61
62 static struct msg_sequence *sequences[NUM_MSG_SEQUENCES];
63
64 static const struct message create_parent_wnd_seq[] = {
65     { WM_GETMINMAXINFO, sent },
66     { WM_NCCREATE, sent },
67     { WM_NCCALCSIZE, sent|wparam, 0 },
68     { WM_CREATE, sent },
69     { 0 }
70 };
71
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 },
88     { 0 }
89 };
90
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 },
95     { 0 }
96 };
97
98 static const struct message insertItem_seq[] = {
99     { HDM_INSERTITEM, sent|wparam, 0 },
100     { HDM_INSERTITEM, sent|wparam, 1 },
101     { HDM_INSERTITEM, sent|wparam, 2 },
102     { HDM_INSERTITEM, sent|wparam, 3 },
103     { 0 }
104 };
105
106 static const struct message getItem_seq[] = {
107     { HDM_GETITEM, sent|wparam, 3 },
108     { HDM_GETITEM, sent|wparam, 0 },
109     { 0 }
110 };
111
112
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 },
120     { 0 }
121 };
122
123 static const struct message orderArray_seq[] = {
124     { HDM_SETORDERARRAY, sent|wparam, 2 },
125     { HDM_GETORDERARRAY, sent|wparam, 2 },
126     { 0 }
127 };
128
129 static const struct message setItem_seq[] = {
130     { HDM_SETITEM, sent|wparam, 0 },
131     { HDM_SETITEM, sent|wparam, 1 },
132     { 0 }
133 };
134
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 },
139     { 0 }
140 };
141
142 static const struct message layout_seq[] = {
143     { HDM_LAYOUT, sent },
144     { 0 }
145 };
146
147 static const struct message orderToIndex_seq[] = {
148     { HDM_ORDERTOINDEX, sent|wparam, 1 },
149     { 0 }
150 };
151
152 static const struct message hittest_seq[] = {
153     { HDM_HITTEST, sent },
154     { HDM_HITTEST, sent },
155     { HDM_HITTEST, sent },
156     { 0 }
157 };
158
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},
168     { 0 }
169 };
170
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},
175     { 0 }
176 };
177
178 static const struct message imageMessages_seq[] = {
179     { HDM_SETIMAGELIST, sent },
180     { HDM_GETIMAGELIST, sent },
181     { HDM_CREATEDRAGIMAGE, sent },
182     { 0 }
183 };
184
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 },
192     { 0 }
193 };
194
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 },
201     { 0 }
202 };
203
204 static const struct message unicodeformatMessages_seq[] = {
205     { HDM_SETUNICODEFORMAT, sent|wparam, TRUE },
206     { HDM_GETUNICODEFORMAT, sent },
207     { 0 }
208 };
209
210 static const struct message bitmapmarginMessages_seq[] = {
211     { HDM_GETBITMAPMARGIN, sent },
212     { 0 }
213 };
214
215
216 static void expect_notify(INT iCode, BOOL fUnicode, HDITEMA *lpItem)
217 {
218     assert(nExpectedNotify < 10);
219     expectedNotify[nExpectedNotify].iCode = iCode;
220     expectedNotify[nExpectedNotify].fUnicode = fUnicode;
221     expectedNotify[nExpectedNotify].hdItem = *lpItem;
222     nExpectedNotify++;
223 }
224
225 static void dont_expect_notify(INT iCode)
226 {
227     assert(nUnexpectedNotify < 10);
228     unexpectedNotify[nUnexpectedNotify++] = iCode;
229 }
230
231 static BOOL notifies_received(void)
232 {
233     BOOL fRet = (nExpectedNotify == nReceivedNotify);
234     nExpectedNotify = nReceivedNotify = 0;
235     nUnexpectedNotify = 0;
236     return fRet;
237 }
238
239 static LONG addItem(HWND hdex, int idx, LPSTR text)
240 {
241     HDITEMA hdItem;
242     hdItem.mask       = HDI_TEXT | HDI_WIDTH;
243     hdItem.cxy        = 100;
244     hdItem.pszText    = text;
245     hdItem.cchTextMax = 0;
246     return (LONG)SendMessage(hdex, HDM_INSERTITEMA, (WPARAM)idx, (LPARAM)&hdItem);
247 }
248
249 static LONG setItem(HWND hdex, int idx, LPSTR text, BOOL fCheckNotifies)
250 {
251     LONG ret;
252     HDITEMA hdexItem;
253     hdexItem.mask       = HDI_TEXT;
254     hdexItem.pszText    = text;
255     hdexItem.cchTextMax = 0;
256     if (fCheckNotifies)
257     {
258         expect_notify(HDN_ITEMCHANGINGA, FALSE, &hdexItem);
259         expect_notify(HDN_ITEMCHANGEDA, FALSE, &hdexItem);
260     }
261     ret = (LONG)SendMessage(hdex, HDM_SETITEMA, (WPARAM)idx, (LPARAM)&hdexItem);
262     if (fCheckNotifies)
263         ok(notifies_received(), "setItem(): not all expected notifies were received\n");
264     return ret;
265 }
266
267 static LONG setItemUnicodeNotify(HWND hdex, int idx, LPSTR text, LPWSTR wText)
268 {
269     LONG ret;
270     HDITEMA hdexItem;
271     HDITEMW hdexNotify;
272     hdexItem.mask       = HDI_TEXT;
273     hdexItem.pszText    = text;
274     hdexItem.cchTextMax = 0;
275     
276     hdexNotify.mask    = HDI_TEXT;
277     hdexNotify.pszText = wText;
278     
279     expect_notify(HDN_ITEMCHANGINGW, TRUE, (HDITEMA*)&hdexNotify);
280     expect_notify(HDN_ITEMCHANGEDW, TRUE, (HDITEMA*)&hdexNotify);
281     ret = (LONG)SendMessage(hdex, HDM_SETITEMA, (WPARAM)idx, (LPARAM)&hdexItem);
282     ok(notifies_received(), "setItemUnicodeNotify(): not all expected notifies were received\n");
283     return ret;
284 }
285
286 static LONG delItem(HWND hdex, int idx)
287 {
288     return (LONG)SendMessage(hdex, HDM_DELETEITEM, (WPARAM)idx, 0);
289 }
290
291 static LONG getItemCount(HWND hdex)
292 {
293     return (LONG)SendMessage(hdex, HDM_GETITEMCOUNT, 0, 0);
294 }
295
296 static LONG getItem(HWND hdex, int idx, LPSTR textBuffer)
297 {
298     HDITEMA hdItem;
299     hdItem.mask         = HDI_TEXT;
300     hdItem.pszText      = textBuffer;
301     hdItem.cchTextMax   = MAX_CHARS;
302     return (LONG)SendMessage(hdex, HDM_GETITEMA, (WPARAM)idx, (LPARAM)&hdItem);
303 }
304
305 static void addReadDelItem(HWND hdex, HDITEMA *phdiCreate, int maskRead, HDITEMA *phdiRead)
306 {
307     ok(SendMessage(hdex, HDM_INSERTITEMA, 0, (LPARAM)phdiCreate)!=-1, "Adding item failed\n");
308     ZeroMemory(phdiRead, sizeof(HDITEMA));
309     phdiRead->mask = maskRead;
310     ok(SendMessage(hdex, HDM_GETITEMA, 0, (LPARAM)phdiRead)!=0, "Getting item data failed\n");
311     ok(SendMessage(hdex, HDM_DELETEITEM, 0, 0)!=0, "Deleting item failed\n");
312 }
313
314 static HWND create_header_control (void)
315 {
316     HWND handle;
317     HDLAYOUT hlayout;
318     RECT rectwin;
319     WINDOWPOS winpos;
320
321     handle = CreateWindowEx(0, WC_HEADER, NULL,
322                             WS_CHILD|WS_BORDER|WS_VISIBLE|HDS_BUTTONS|HDS_HORZ,
323                             0, 0, 0, 0,
324                             hHeaderParentWnd, NULL, NULL, NULL);
325     assert(handle);
326
327     if (winetest_interactive)
328         ShowWindow (hHeaderParentWnd, SW_SHOW);
329
330     GetClientRect(hHeaderParentWnd,&rectwin);
331     hlayout.prc = &rectwin;
332     hlayout.pwpos = &winpos;
333     SendMessageA(handle,HDM_LAYOUT,0,(LPARAM) &hlayout);
334     SetWindowPos(handle, winpos.hwndInsertAfter, winpos.x, winpos.y, 
335                  winpos.cx, winpos.cy, 0);
336
337     return handle;
338 }
339
340 static void compare_items(INT iCode, HDITEMA *hdi1, HDITEMA *hdi2, BOOL fUnicode)
341 {
342     ok(hdi1->mask == hdi2->mask, "Notify %d mask mismatch (%08x != %08x)\n", iCode, hdi1->mask, hdi2->mask);
343     if (hdi1->mask & HDI_WIDTH)
344     {
345         ok(hdi1->cxy == hdi2->cxy, "Notify %d cxy mismatch (%08x != %08x)\n", iCode, hdi1->cxy, hdi2->cxy);
346     }
347     if (hdi1->mask & HDI_TEXT)
348     {
349         if (hdi1->pszText == LPSTR_TEXTCALLBACKA)
350         {
351             ok(hdi1->pszText == LPSTR_TEXTCALLBACKA, "Notify %d - only one item is LPSTR_TEXTCALLBACK\n", iCode);
352         }
353         else
354         if (fUnicode)
355         {
356             char buf1[260];
357             char buf2[260];
358             WideCharToMultiByte(CP_ACP, 0, (LPCWSTR)hdi1->pszText, -1, buf1, 260, NULL, NULL);
359             WideCharToMultiByte(CP_ACP, 0, (LPCWSTR)hdi2->pszText, -1, buf2, 260, NULL, NULL);
360             ok(lstrcmpW((LPWSTR)hdi1->pszText, (LPWSTR)hdi2->pszText)==0,
361                 "Notify %d text mismatch (L\"%s\" vs L\"%s\")\n",
362                     iCode, buf1, buf2);
363         }
364         else
365         {
366             ok(strcmp(hdi1->pszText, hdi2->pszText)==0,
367                 "Notify %d text mismatch (\"%s\" vs \"%s\")\n",
368                     iCode, hdi1->pszText, hdi2->pszText);
369             }
370     }
371 }
372
373 static char pszFirstItem[]      = "First Item";
374 static char pszSecondItem[]     = "Second Item";
375 static char pszThirdItem[]      = "Third Item";
376 static char pszFourthItem[]     = "Fourth Item";
377 static char pszReplaceItem[]    = "Replace Item";
378 static char pszOutOfRangeItem[] = "Out Of Range Item";
379
380 static char *str_items[] =
381     {pszFirstItem, pszSecondItem, pszThirdItem, pszFourthItem, pszReplaceItem, pszOutOfRangeItem};
382     
383 static char pszUniTestA[]  = "TST";
384 static WCHAR pszUniTestW[] = {'T','S','T',0};
385
386
387 #define TEST_GET_ITEM(i,c)\
388 {   res = getItem(hWndHeader, i, buffer);\
389     ok(res != 0, "Getting item[%d] using valid index failed unexpectedly (%d)\n", i, res);\
390     ok(strcmp(str_items[c], buffer) == 0, "Getting item[%d] returned \"%s\" expecting \"%s\"\n", i, buffer, str_items[c]);\
391 }
392
393 #define TEST_GET_ITEMCOUNT(i)\
394 {   res = getItemCount(hWndHeader);\
395     ok(res == i, "Got Item Count as %d\n", res);\
396 }
397
398 struct subclass_info
399 {
400     WNDPROC oldproc;
401 };
402
403 static LRESULT WINAPI header_subclass_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
404 {
405     struct subclass_info *info = (struct subclass_info *)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
406     static LONG defwndproc_counter = 0;
407     LRESULT ret;
408     struct message msg;
409
410     trace("header: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
411     msg.message = message;
412     msg.flags = sent|wparam|lparam;
413     if (defwndproc_counter) msg.flags |= defwinproc;
414     msg.wParam = wParam;
415     msg.lParam = lParam;
416     add_message(sequences, HEADER_SEQ_INDEX, &msg);
417
418     defwndproc_counter++;
419     ret = CallWindowProcA(info->oldproc, hwnd, message, wParam, lParam);
420     defwndproc_counter--;
421
422     return ret;
423 }
424
425 static LRESULT WINAPI parent_wnd_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
426 {
427     static LONG defwndproc_counter = 0;
428     LRESULT ret;
429     struct message msg;
430
431     /* do not log painting messages */
432     if (message != WM_PAINT &&
433         message != WM_ERASEBKGND &&
434         message != WM_NCPAINT &&
435         message != WM_NCHITTEST &&
436         message != WM_GETTEXT &&
437         message != WM_GETICON &&
438         message != WM_DEVICECHANGE)
439
440     {
441         trace("parent: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
442
443         msg.message = message;
444         msg.flags = sent|wparam|lparam;
445         if (defwndproc_counter) msg.flags |= defwinproc;
446         msg.wParam = wParam;
447         msg.lParam = lParam;
448         add_message(sequences, PARENT_SEQ_INDEX, &msg);
449    }
450
451     defwndproc_counter++;
452     ret = DefWindowProcA(hwnd, message, wParam, lParam);
453     defwndproc_counter--;
454
455     return ret;
456 }
457
458 static BOOL register_parent_wnd_class(void)
459 {
460     WNDCLASSA cls;
461
462     cls.style = 0;
463     cls.lpfnWndProc = parent_wnd_proc;
464     cls.cbClsExtra = 0;
465     cls.cbWndExtra = 0;
466     cls.hInstance = GetModuleHandleA(NULL);
467     cls.hIcon = 0;
468     cls.hCursor = LoadCursorA(0, IDC_ARROW);
469     cls.hbrBackground = GetStockObject(WHITE_BRUSH);
470     cls.lpszMenuName = NULL;
471     cls.lpszClassName = "Header test parent class";
472     return RegisterClassA(&cls);
473 }
474
475 static HWND create_custom_parent_window(void)
476 {
477     if (!register_parent_wnd_class())
478         return NULL;
479
480     return CreateWindowExA(0, "Header test parent class", "Header Message Sequence Testing",
481                            WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT,
482                            672+2*GetSystemMetrics(SM_CXSIZEFRAME),
483                            226+GetSystemMetrics(SM_CYCAPTION)+2*GetSystemMetrics(SM_CYSIZEFRAME),
484                            NULL, NULL, GetModuleHandleA(NULL), 0);
485 }
486
487 static HWND create_custom_header_control(HWND hParent, BOOL preloadHeaderItems)
488 {
489     struct subclass_info *info;
490     HWND childHandle;
491     HDLAYOUT hlayout;
492     RECT rectwin;
493     WINDOWPOS winpos;
494     int retVal;
495     int loopcnt;
496     static char firstHeaderItem[] = "Name";
497     static char secondHeaderItem[] = "Size";
498     static char *items[] = {secondHeaderItem, firstHeaderItem};
499     HDITEM hdItem;
500     hdItem.mask = HDI_TEXT | HDI_WIDTH | HDI_FORMAT;
501     hdItem.fmt = HDF_LEFT;
502     hdItem.cxy = 80;
503     hdItem.cchTextMax = 260;
504
505
506     flush_sequences(sequences, NUM_MSG_SEQUENCES);
507     info = HeapAlloc(GetProcessHeap(), 0, sizeof(struct subclass_info));
508     if (!info)
509          return NULL;
510
511     childHandle = CreateWindowEx(0, WC_HEADER, NULL,
512                            WS_CHILD|WS_BORDER|WS_VISIBLE|HDS_BUTTONS|HDS_HORZ,
513                            0, 0, 0, 0,
514                            hParent, NULL, NULL, NULL);
515     assert(childHandle);
516     if (preloadHeaderItems)
517     {
518          for ( loopcnt = 0 ; loopcnt < 2 ; loopcnt++ )
519          {
520              hdItem.pszText = items[loopcnt];
521              retVal = SendMessage(childHandle, HDM_INSERTITEM, loopcnt, (LPARAM) &hdItem);
522              ok(retVal == loopcnt, "Adding item %d failed with return value %d\n", ( loopcnt + 1 ), retVal);
523           }
524     }
525
526     if (winetest_interactive)
527        ShowWindow (hParent, SW_SHOW);
528
529     GetClientRect(hParent,&rectwin);
530     hlayout.prc = &rectwin;
531     hlayout.pwpos = &winpos;
532     SendMessageA(childHandle,HDM_LAYOUT,0,(LPARAM) &hlayout);
533     SetWindowPos(childHandle, winpos.hwndInsertAfter, winpos.x, winpos.y,
534                  winpos.cx, winpos.cy, 0);
535
536     info->oldproc = (WNDPROC)SetWindowLongPtrA(childHandle, GWLP_WNDPROC,
537                                                (LONG_PTR)header_subclass_proc);
538     SetWindowLongPtrA(childHandle, GWLP_USERDATA, (LONG_PTR)info);
539     return childHandle;
540 }
541
542 static void check_auto_format(void)
543 {
544     HDITEMA hdiCreate;
545     HDITEMA hdiRead;
546     static CHAR text[] = "Test";
547     ZeroMemory(&hdiCreate, sizeof(HDITEMA));
548
549     /* Windows implicitly sets some format bits in INSERTITEM */
550
551     /* HDF_STRING is automatically set and cleared for no text */
552     hdiCreate.mask = HDI_TEXT|HDI_WIDTH|HDI_FORMAT;
553     hdiCreate.pszText = text;
554     hdiCreate.cxy = 100;
555     hdiCreate.fmt=HDF_CENTER;
556     addReadDelItem(hWndHeader, &hdiCreate, HDI_FORMAT, &hdiRead);
557     ok(hdiRead.fmt == (HDF_STRING|HDF_CENTER), "HDF_STRING not set automatically (fmt=%x)\n", hdiRead.fmt);
558
559     hdiCreate.mask = HDI_WIDTH|HDI_FORMAT;
560     hdiCreate.pszText = text;
561     hdiCreate.fmt = HDF_CENTER|HDF_STRING;
562     addReadDelItem(hWndHeader, &hdiCreate, HDI_FORMAT, &hdiRead);
563     ok(hdiRead.fmt == (HDF_CENTER), "HDF_STRING should be automatically cleared (fmt=%x)\n", hdiRead.fmt);
564
565     /* HDF_BITMAP is automatically set and cleared for a NULL bitmap or no bitmap */
566     hdiCreate.mask = HDI_BITMAP|HDI_WIDTH|HDI_FORMAT;
567     hdiCreate.hbm = CreateBitmap(16, 16, 1, 8, NULL);
568     hdiCreate.fmt = HDF_CENTER;
569     addReadDelItem(hWndHeader, &hdiCreate, HDI_FORMAT, &hdiRead);
570     ok(hdiRead.fmt == (HDF_BITMAP|HDF_CENTER), "HDF_BITMAP not set automatically (fmt=%x)\n", hdiRead.fmt);
571     DeleteObject(hdiCreate.hbm);
572
573     hdiCreate.hbm = NULL;
574     hdiCreate.fmt = HDF_CENTER|HDF_BITMAP;
575     addReadDelItem(hWndHeader, &hdiCreate, HDI_FORMAT, &hdiRead);
576     ok(hdiRead.fmt == HDF_CENTER, "HDF_BITMAP not cleared automatically for NULL bitmap (fmt=%x)\n", hdiRead.fmt);
577
578     hdiCreate.mask = HDI_WIDTH|HDI_FORMAT;
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 no bitmap (fmt=%x)\n", hdiRead.fmt);
582
583     /* HDF_IMAGE is automatically set but not cleared */
584     hdiCreate.mask = HDI_IMAGE|HDI_WIDTH|HDI_FORMAT;
585     hdiCreate.iImage = 17;
586     addReadDelItem(hWndHeader, &hdiCreate, HDI_FORMAT, &hdiRead);
587     ok(hdiRead.fmt == (HDF_IMAGE|HDF_CENTER), "HDF_IMAGE not set automatically (fmt=%x)\n", hdiRead.fmt);
588
589     hdiCreate.mask = HDI_WIDTH|HDI_FORMAT;
590     hdiCreate.fmt = HDF_CENTER|HDF_IMAGE;
591     hdiCreate.iImage = 0;
592     addReadDelItem(hWndHeader, &hdiCreate, HDI_FORMAT, &hdiRead);
593     ok(hdiRead.fmt == (HDF_CENTER|HDF_IMAGE), "HDF_IMAGE shouldn't be cleared automatically (fmt=%x)\n", hdiRead.fmt);
594 }
595
596 static void check_auto_fields(void)
597 {
598     HDITEMA hdiCreate;
599     HDITEMA hdiRead;
600     static CHAR text[] = "Test";
601     LONG res;
602
603     /* Windows stores the format, width, lparam even if they are not in the item's mask */
604     ZeroMemory(&hdiCreate, sizeof(HDITEMA));
605     hdiCreate.mask = HDI_TEXT;
606     hdiCreate.cxy = 100;
607     hdiCreate.pszText = text;
608     addReadDelItem(hWndHeader, &hdiCreate, HDI_WIDTH, &hdiRead);
609     TEST_GET_ITEMCOUNT(6);
610     ok(hdiRead.cxy == hdiCreate.cxy, "cxy should be automatically set\n");
611
612     ZeroMemory(&hdiCreate, sizeof(HDITEMA));
613     hdiCreate.mask = HDI_TEXT;
614     hdiCreate.pszText = text;
615     hdiCreate.lParam = 0x12345678;
616     addReadDelItem(hWndHeader, &hdiCreate, HDI_LPARAM, &hdiRead);
617     TEST_GET_ITEMCOUNT(6);
618     ok(hdiRead.lParam == hdiCreate.lParam, "lParam should be automatically set\n");
619
620     ZeroMemory(&hdiCreate, sizeof(HDITEMA));
621     hdiCreate.mask = HDI_TEXT;
622     hdiCreate.pszText = text;
623     hdiCreate.fmt = HDF_STRING|HDF_CENTER;
624     addReadDelItem(hWndHeader, &hdiCreate, HDI_FORMAT, &hdiRead);
625     TEST_GET_ITEMCOUNT(6);
626     ok(hdiRead.fmt == hdiCreate.fmt, "fmt should be automatically set\n");
627
628     /* others fields are not set */
629     ZeroMemory(&hdiCreate, sizeof(HDITEMA));
630     hdiCreate.mask = HDI_TEXT;
631     hdiCreate.pszText = text;
632     hdiCreate.hbm = CreateBitmap(16, 16, 1, 8, NULL);
633     addReadDelItem(hWndHeader, &hdiCreate, HDI_BITMAP, &hdiRead);
634     TEST_GET_ITEMCOUNT(6);
635     ok(hdiRead.hbm == NULL, "hbm should not be automatically set\n");
636     DeleteObject(hdiCreate.hbm);
637
638     ZeroMemory(&hdiCreate, sizeof(HDITEMA));
639     hdiCreate.mask = HDI_IMAGE;
640     hdiCreate.iImage = 17;
641     hdiCreate.pszText = text;
642     addReadDelItem(hWndHeader, &hdiCreate, HDI_TEXT, &hdiRead);
643     TEST_GET_ITEMCOUNT(6);
644     ok(hdiRead.pszText==NULL, "pszText shouldn't be automatically set\n");
645
646     /* field from comctl >4.0 not tested as the system probably won't touch them */
647 }
648
649 static void check_mask(void)
650 {
651     HDITEMA hdi;
652     static CHAR text[] = "ABC";
653     LRESULT ret;
654
655     /* don't create items if the mask is zero */
656     ZeroMemory(&hdi, sizeof(hdi));
657     hdi.mask = 0;
658     hdi.cxy = 200;
659     hdi.pszText = text;
660     hdi.fmt = 0;
661     hdi.iOrder = 0;
662     hdi.lParam = 17;
663     hdi.cchTextMax = 260;
664     ret = SendMessage(hWndHeader, HDM_INSERTITEM, 0, (LPARAM)&hdi);
665     ok(ret == -1, "Creating an item with a zero mask should have failed\n");
666     if (ret != -1) SendMessage(hWndHeader, HDM_DELETEITEM, 0, 0);
667
668     /* with a non-zero mask creation will succeed */
669     ZeroMemory(&hdi, sizeof(hdi));
670     hdi.mask = HDI_LPARAM;
671     ret = SendMessage(hWndHeader, HDM_INSERTITEM, 0, (LPARAM)&hdi);
672     ok(ret != -1, "Adding item with non-zero mask failed\n");
673     if (ret != -1)
674         SendMessage(hWndHeader, HDM_DELETEITEM, 0, 0);
675
676     /* in SETITEM if the mask contains a unknown bit, it is ignored */
677     ZeroMemory(&hdi, sizeof(hdi));
678     hdi.mask = 0x08000000 | HDI_LPARAM | HDI_IMAGE;
679     hdi.lParam = 133;
680     hdi.iImage = 17;
681     ret = SendMessage(hWndHeader, HDM_INSERTITEM, 0, (LPARAM)&hdi);
682     ok(ret != -1, "Adding item failed\n");
683
684     if (ret != -1)
685     {
686         /* check result */
687         ZeroMemory(&hdi, sizeof(hdi));
688         hdi.mask = HDI_LPARAM | HDI_IMAGE;
689         SendMessage(hWndHeader, HDM_GETITEM, 0, (LPARAM)&hdi);
690         ok(hdi.lParam == 133, "comctl32 4.0 field not set\n");
691         ok(hdi.iImage == 17, "comctl32 >4.0 field not set\n");
692
693         /* but in GETITEM if an unknown bit is set, comctl32 uses only version 4.0 fields */
694         ZeroMemory(&hdi, sizeof(hdi));
695         hdi.mask = 0x08000000 | HDI_LPARAM | HDI_IMAGE;
696         SendMessage(hWndHeader, HDM_GETITEM, 0, (LPARAM)&hdi);
697         ok(hdi.lParam == 133, "comctl32 4.0 field not read\n");
698         ok(hdi.iImage == 0, "comctl32 >4.0 field shouldn't be read\n");
699
700         SendMessage(hWndHeader, HDM_DELETEITEM, 0, 0);
701     }
702 }
703
704 static void test_header_control (void)
705 {
706     LONG res;
707     static char buffer[MAX_CHARS];
708     int i;
709
710     hWndHeader = create_header_control ();
711
712     for (i = 3; i >= 0; i--)
713     {
714         TEST_GET_ITEMCOUNT(3-i);
715         res = addItem(hWndHeader, 0, str_items[i]);
716         ok(res == 0, "Adding simple item failed (%d)\n", res);
717     }
718
719     TEST_GET_ITEMCOUNT(4);
720     res = addItem(hWndHeader, 99, str_items[i+1]);
721     ok(res != -1, "Adding Out of Range item should fail with -1 got (%d)\n", res);
722     TEST_GET_ITEMCOUNT(5);
723     res = addItem(hWndHeader, 5, str_items[i+1]);
724     ok(res != -1, "Adding Out of Range item should fail with -1 got (%d)\n", res);
725     TEST_GET_ITEMCOUNT(6);
726
727     for (i = 0; i < 4; i++) { TEST_GET_ITEM(i,i); TEST_GET_ITEMCOUNT(6); }
728
729     res=getItem(hWndHeader, 99, buffer);
730     ok(res == 0, "Getting Out of Range item should fail with 0 (%d), got %s\n", res,buffer);
731     res=getItem(hWndHeader, 5, buffer);
732     ok(res == 1, "Getting Out of Range item should fail with 1 (%d), got %s\n", res,buffer);
733     res=getItem(hWndHeader, -2, buffer);
734     ok(res == 0, "Getting Out of Range item should fail with 0 (%d), got %s\n", res,buffer);
735
736     if (winetest_interactive)
737     {
738         UpdateWindow(hHeaderParentWnd);
739         UpdateWindow(hWndHeader);
740     }
741
742     TEST_GET_ITEMCOUNT(6);
743     res=setItem(hWndHeader, 99, str_items[5], FALSE);
744     ok(res == 0, "Setting Out of Range item should fail with 0 (%d)\n", res);
745     res=setItem(hWndHeader, 5, str_items[5], TRUE);
746     ok(res == 1, "Setting Out of Range item should fail with 1 (%d)\n", res);
747     res=setItem(hWndHeader, -2, str_items[5], FALSE);
748     ok(res == 0, "Setting Out of Range item should fail with 0 (%d)\n", res);
749     TEST_GET_ITEMCOUNT(6);
750
751     for (i = 0; i < 4; i++)
752     {
753         res = setItem(hWndHeader, i, str_items[4], TRUE);
754         ok(res != 0, "Setting %d item failed (%d)\n", i+1, res);
755         TEST_GET_ITEM(i, 4);
756         TEST_GET_ITEMCOUNT(6);
757     }
758     
759     SendMessageA(hWndHeader, HDM_SETUNICODEFORMAT, (WPARAM)TRUE, 0);
760     setItemUnicodeNotify(hWndHeader, 3, pszUniTestA, pszUniTestW);
761     SendMessageA(hWndHeader, WM_NOTIFYFORMAT, (WPARAM)hHeaderParentWnd, (LPARAM)NF_REQUERY);
762     setItem(hWndHeader, 3, str_items[4], TRUE);
763     
764     dont_expect_notify(HDN_GETDISPINFOA);
765     dont_expect_notify(HDN_GETDISPINFOW);
766     addItem(hWndHeader, 0, LPSTR_TEXTCALLBACKA);
767     setItem(hWndHeader, 0, str_items[4], TRUE);
768     /* unexpected notifies cleared by notifies_received in setItem */
769     dont_expect_notify(HDN_GETDISPINFOA);
770     dont_expect_notify(HDN_GETDISPINFOW);
771     setItem(hWndHeader, 0, LPSTR_TEXTCALLBACKA, TRUE);
772     /* unexpected notifies cleared by notifies_received in setItem */
773     delItem(hWndHeader, 0);
774
775     check_auto_format();
776     TEST_GET_ITEMCOUNT(6);
777     check_auto_fields();
778     TEST_GET_ITEMCOUNT(6);
779     check_mask();
780     TEST_GET_ITEMCOUNT(6);
781
782     res = delItem(hWndHeader, 5);
783     ok(res == 1, "Deleting Out of Range item should fail with 1 (%d)\n", res);
784     res = delItem(hWndHeader, -2);
785     ok(res == 0, "Deleting Out of Range item should fail with 0 (%d)\n", res);
786     TEST_GET_ITEMCOUNT(5);
787
788     res = delItem(hWndHeader, 3);
789     ok(res != 0, "Deleting using out of range index failed (%d)\n", res);
790     TEST_GET_ITEMCOUNT(4);
791     res = delItem(hWndHeader, 0);
792     ok(res != 0, "Deleting using out of range index failed (%d)\n", res);
793     TEST_GET_ITEMCOUNT(3);
794     res = delItem(hWndHeader, 0);
795     ok(res != 0, "Deleting using out of range index failed (%d)\n", res);
796     TEST_GET_ITEMCOUNT(2);
797     res = delItem(hWndHeader, 0);
798     ok(res != 0, "Deleting using out of range index failed (%d)\n", res);
799     TEST_GET_ITEMCOUNT(1);
800
801     DestroyWindow(hWndHeader);
802 }
803
804 static void test_hdm_getitemrect(HWND hParent)
805 {
806
807     HWND hChild;
808     RECT rect;
809     int retVal;
810
811     flush_sequences(sequences, NUM_MSG_SEQUENCES);
812     hChild = create_custom_header_control(hParent, TRUE);
813     ok_sequence(sequences, PARENT_SEQ_INDEX, add_header_to_parent_seq,
814                                     "adder header control to parent", FALSE);
815
816     retVal = SendMessage(hChild, HDM_GETITEMRECT, 1, (LPARAM) &rect);
817     ok(retVal == TRUE, "Getting item rect should TRUE, got %d\n", retVal);
818     /* check bounding rectangle information of 2nd header item */
819     expect(80, rect.left);
820     expect(0, rect.top);
821     expect(160, rect.right);
822     todo_wine
823     {
824       expect(g_customheight, rect.bottom);
825     }
826     retVal = SendMessage(hChild, HDM_GETITEMRECT, 0, (LPARAM) &rect);
827
828     ok(retVal == TRUE, "Getting item rect should TRUE, got %d\n", retVal);
829     /* check bounding rectangle information of 1st header item */
830     expect(0, rect.left);
831     expect(0, rect.top);
832
833     expect(80, rect.right);
834     todo_wine
835     {
836       expect(g_customheight, rect.bottom);
837     }
838     retVal = SendMessage(hChild, HDM_GETITEMRECT, 10, (LPARAM) &rect);
839     ok(retVal == 0, "Getting rect of nonexistent item should return 0, got %d\n", retVal);
840
841     ok_sequence(sequences, HEADER_SEQ_INDEX, getItemRect_seq, "getItemRect sequence testing", FALSE);
842     DestroyWindow(hChild);
843 }
844
845 static void test_hdm_layout(HWND hParent)
846 {
847     HWND hChild;
848     int retVal;
849     RECT rect;
850     HDLAYOUT hdLayout;
851     WINDOWPOS windowPos;
852     hdLayout.prc = &rect;
853     hdLayout.pwpos = &windowPos;
854
855     flush_sequences(sequences, NUM_MSG_SEQUENCES);
856     hChild = create_custom_header_control(hParent, TRUE);
857     ok_sequence(sequences, PARENT_SEQ_INDEX, add_header_to_parent_seq,
858                                     "adder header control to parent", FALSE);
859
860     flush_sequences(sequences, NUM_MSG_SEQUENCES);
861     retVal = SendMessage(hChild, HDM_LAYOUT, 0, (LPARAM) &hdLayout);
862     expect(TRUE, retVal);
863
864     ok_sequence(sequences, HEADER_SEQ_INDEX, layout_seq, "layout sequence testing", FALSE);
865
866     DestroyWindow(hChild);
867 }
868
869 static void test_hdm_ordertoindex(HWND hParent)
870 {
871     HWND hChild;
872     int retVal;
873
874     flush_sequences(sequences, NUM_MSG_SEQUENCES);
875     hChild = create_custom_header_control(hParent, TRUE);
876     ok_sequence(sequences, PARENT_SEQ_INDEX, add_header_to_parent_seq,
877                                     "adder header control to parent", FALSE);
878
879     flush_sequences(sequences, NUM_MSG_SEQUENCES);
880     retVal = SendMessage(hChild, HDM_ORDERTOINDEX, 1, 0);
881     expect(1, retVal);
882
883     ok_sequence(sequences, HEADER_SEQ_INDEX, orderToIndex_seq, "orderToIndex sequence testing", FALSE);
884     DestroyWindow(hChild);
885 }
886
887 static void test_hdm_hittest(HWND hParent)
888 {
889     HWND hChild;
890     int retVal;
891     POINT pt;
892     HDHITTESTINFO hdHitTestInfo;
893     const int firstItemRightBoundary = 80;
894     const int secondItemRightBoundary = 160;
895     const int bottomBoundary = g_customheight;
896
897     pt.x = firstItemRightBoundary - 1;
898     pt.y = bottomBoundary - 1;
899     hdHitTestInfo.pt = pt;
900
901
902     flush_sequences(sequences, NUM_MSG_SEQUENCES);
903     hChild = create_custom_header_control(hParent, TRUE);
904     ok_sequence(sequences, PARENT_SEQ_INDEX, add_header_to_parent_seq,
905                                     "adder header control to parent", FALSE);
906
907     flush_sequences(sequences, NUM_MSG_SEQUENCES);
908     retVal = SendMessage(hChild, HDM_HITTEST, 0, (LPARAM) &hdHitTestInfo);
909     todo_wine
910     {
911       expect(0, retVal);
912       expect(0, hdHitTestInfo.iItem);
913     }
914
915     pt.x = secondItemRightBoundary - 1;
916     pt.y = bottomBoundary - 1;
917     hdHitTestInfo.pt = pt;
918     retVal = SendMessage(hChild, HDM_HITTEST, 1, (LPARAM) &hdHitTestInfo);
919     todo_wine
920     {
921       expect(1, retVal);
922     }
923     expect(1, hdHitTestInfo.iItem);
924
925     pt.x = secondItemRightBoundary;
926     pt.y = bottomBoundary + 1;
927     hdHitTestInfo.pt = pt;
928     todo_wine
929     {
930      retVal = SendMessage(hChild, HDM_HITTEST, 0, (LPARAM) &hdHitTestInfo);
931      expect(-1, retVal);
932     }
933
934     ok_sequence(sequences, HEADER_SEQ_INDEX, hittest_seq, "hittest sequence testing", FALSE);
935
936     DestroyWindow(hChild);
937 }
938
939 static void test_hdm_sethotdivider(HWND hParent)
940 {
941     HWND hChild;
942     int retVal;
943     /*  low word: x coordinate = 5
944      *  high word:  y coordinate = 5
945      */
946
947     flush_sequences(sequences, NUM_MSG_SEQUENCES);
948     hChild = create_custom_header_control(hParent, TRUE);
949     ok_sequence(sequences, PARENT_SEQ_INDEX, add_header_to_parent_seq,
950                                     "adder header control to parent", FALSE);
951
952     flush_sequences(sequences, NUM_MSG_SEQUENCES);
953     todo_wine
954     {
955         retVal = SendMessage(hChild, HDM_SETHOTDIVIDER, TRUE, 0X00050005);
956         expect(0, retVal);
957     }
958     retVal = SendMessage(hChild, HDM_SETHOTDIVIDER, FALSE, 100);
959     expect(100, retVal);
960     retVal = SendMessage(hChild, HDM_SETHOTDIVIDER, FALSE, 1);
961     expect(1, retVal);
962     if (winetest_interactive)
963        ok_sequence(sequences, HEADER_SEQ_INDEX, setHotDivider_seq_interactive,
964                    "setHotDivider sequence testing", TRUE);
965     else
966        ok_sequence(sequences, HEADER_SEQ_INDEX, setHotDivider_seq_noninteractive,
967                    "setHotDivider sequence testing", FALSE);
968
969     DestroyWindow(hChild);
970 }
971
972 static void test_hdm_imageMessages(HWND hParent)
973 {
974     HIMAGELIST hImageList = ImageList_Create (4, 4, 0, 1, 0);
975     HIMAGELIST hImageListRetVal;
976     HWND hChild;
977
978     flush_sequences(sequences, NUM_MSG_SEQUENCES);
979     hChild = create_custom_header_control(hParent, TRUE);
980     ok_sequence(sequences, PARENT_SEQ_INDEX, add_header_to_parent_seq,
981                                     "adder header control to parent", FALSE);
982
983     flush_sequences(sequences, NUM_MSG_SEQUENCES);
984
985     hImageListRetVal = (HIMAGELIST) SendMessage(hChild, HDM_SETIMAGELIST, 0, (LPARAM) hImageList);
986     ok(hImageListRetVal == NULL, "Expected NULL, got %p\n", hImageListRetVal);
987
988     hImageListRetVal = (HIMAGELIST) SendMessage(hChild, HDM_GETIMAGELIST, 0, 0);
989     ok(hImageListRetVal != NULL, "Expected non-NULL handle, got %p\n", hImageListRetVal);
990
991     hImageListRetVal = (HIMAGELIST) SendMessage(hChild, HDM_CREATEDRAGIMAGE, 0, 0);
992     ok(hImageListRetVal != NULL, "Expected non-NULL handle, got %p\n", hImageListRetVal);
993
994     ok_sequence(sequences, HEADER_SEQ_INDEX, imageMessages_seq, "imageMessages sequence testing", FALSE);
995
996     DestroyWindow(hChild);
997 }
998
999 static void test_hdm_filterMessages(HWND hParent)
1000 {
1001     HWND hChild;
1002     int retVal, timeout;
1003
1004     flush_sequences(sequences, NUM_MSG_SEQUENCES);
1005     hChild = create_custom_header_control(hParent, TRUE);
1006     assert(hChild);
1007     ok_sequence(sequences, PARENT_SEQ_INDEX, add_header_to_parent_seq,
1008                                     "adder header control to parent", FALSE);
1009
1010     timeout = SendMessage(hChild, HDM_SETFILTERCHANGETIMEOUT, 1, 100);
1011     SendMessage(hChild, HDM_SETFILTERCHANGETIMEOUT, 1, timeout);
1012
1013     flush_sequences(sequences, NUM_MSG_SEQUENCES);
1014
1015     /* msdn incorrectly states that return value
1016      * is the index of the filter control being
1017      * modified. The sendMessage here should
1018      * return previous filter timeout value
1019      */
1020
1021     retVal = SendMessage(hChild, HDM_SETFILTERCHANGETIMEOUT, 1, 100);
1022     expect(timeout, retVal);
1023
1024     todo_wine
1025     {
1026         retVal = SendMessage(hChild, HDM_CLEARFILTER, 0, 1);
1027         if (retVal == 0)
1028             win_skip("HDM_CLEARFILTER needs 5.80\n");
1029         else
1030             expect(1, retVal);
1031
1032         retVal = SendMessage(hChild, HDM_EDITFILTER, 1, 0);
1033         if (retVal == 0)
1034             win_skip("HDM_EDITFILTER needs 5.80\n");
1035         else
1036             expect(1, retVal);
1037     }
1038     if (winetest_interactive)
1039          ok_sequence(sequences, HEADER_SEQ_INDEX, filterMessages_seq_interactive,
1040                      "filterMessages sequence testing", TRUE);
1041     else
1042          ok_sequence(sequences, HEADER_SEQ_INDEX, filterMessages_seq_noninteractive,
1043                      "filterMessages sequence testing", FALSE);
1044     /* Some Win9x versions don't send a WM_KILLFOCUS.
1045      * Set the focus explicitly to the parent to avoid a crash.
1046      */
1047     SetFocus(hParent);
1048     DestroyWindow(hChild);
1049
1050 }
1051
1052 static void test_hdm_unicodeformatMessages(HWND hParent)
1053 {
1054     HWND hChild;
1055     int retVal;
1056
1057     flush_sequences(sequences, NUM_MSG_SEQUENCES);
1058     hChild = create_custom_header_control(hParent, TRUE);
1059     ok_sequence(sequences, PARENT_SEQ_INDEX, add_header_to_parent_seq,
1060                                     "adder header control to parent", FALSE);
1061
1062     flush_sequences(sequences, NUM_MSG_SEQUENCES);
1063     retVal = SendMessage(hChild, HDM_SETUNICODEFORMAT, TRUE, 0);
1064     expect(0, retVal);
1065     retVal = SendMessage(hChild, HDM_GETUNICODEFORMAT, 0, 0);
1066     expect(1, retVal);
1067
1068     ok_sequence(sequences, HEADER_SEQ_INDEX, unicodeformatMessages_seq,
1069                      "unicodeformatMessages sequence testing", FALSE);
1070     DestroyWindow(hChild);
1071 }
1072
1073 static void test_hdm_bitmapmarginMessages(HWND hParent)
1074 {
1075     HWND hChild;
1076     int retVal;
1077
1078     flush_sequences(sequences, NUM_MSG_SEQUENCES);
1079     hChild = create_custom_header_control(hParent, TRUE);
1080     ok_sequence(sequences, PARENT_SEQ_INDEX, add_header_to_parent_seq,
1081                                     "adder header control to parent", FALSE);
1082
1083     flush_sequences(sequences, NUM_MSG_SEQUENCES);
1084     retVal = SendMessage(hChild, HDM_GETBITMAPMARGIN, 0, 0);
1085     if (retVal == 0)
1086         win_skip("HDM_GETBITMAPMARGIN needs 5.80\n");
1087     else
1088         expect(6, retVal);
1089
1090     ok_sequence(sequences, HEADER_SEQ_INDEX, bitmapmarginMessages_seq,
1091                       "bitmapmarginMessages sequence testing", FALSE);
1092     DestroyWindow(hChild);
1093 }
1094
1095 static void test_hdm_index_messages(HWND hParent)
1096 {
1097
1098     HWND hChild;
1099     int retVal;
1100     int loopcnt;
1101     int strcmpResult;
1102     int iSize;
1103     static const int lpiarray[2] = {1, 0};
1104     static int lpiarrayReceived[2];
1105     static char firstHeaderItem[] = "Name";
1106     static char secondHeaderItem[] = "Size";
1107     static char thirdHeaderItem[] = "Type";
1108     static char fourthHeaderItem[] = "Date Modified";
1109     static char *items[] = {firstHeaderItem, secondHeaderItem, thirdHeaderItem, fourthHeaderItem};
1110     RECT rect;
1111     HDITEM hdItem;
1112     hdItem.mask = HDI_TEXT | HDI_WIDTH | HDI_FORMAT;
1113     hdItem.fmt = HDF_LEFT;
1114     hdItem.cxy = 80;
1115     hdItem.cchTextMax = 260;
1116
1117     flush_sequences(sequences, NUM_MSG_SEQUENCES);
1118     hChild = create_custom_header_control(hParent, FALSE);
1119     if (winetest_interactive)
1120          ok_sequence(sequences, PARENT_SEQ_INDEX, add_header_to_parent_seq_interactive,
1121                                               "adder header control to parent", TRUE);
1122     else
1123          ok_sequence(sequences, PARENT_SEQ_INDEX, add_header_to_parent_seq,
1124                                      "adder header control to parent", FALSE);
1125     flush_sequences(sequences, NUM_MSG_SEQUENCES);
1126     for ( loopcnt = 0 ; loopcnt < 4 ; loopcnt++ )
1127     {
1128       hdItem.pszText = items[loopcnt];
1129       retVal = SendMessage(hChild, HDM_INSERTITEM, loopcnt, (LPARAM) &hdItem);
1130       ok(retVal == loopcnt, "Adding item %d failed with return value %d\n", ( loopcnt + 1 ), 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 = SendMessage(hChild, HDM_DELETEITEM, 3, (LPARAM) &hdItem);
1137     ok(retVal == TRUE, "Deleting item 3 should return TRUE, got %d\n", retVal);
1138     retVal = SendMessage(hChild, HDM_GETITEMCOUNT, 0, 0);
1139     ok(retVal == 3, "Getting item count should return 3, got %d\n", retVal);
1140
1141     retVal = SendMessage(hChild, HDM_DELETEITEM, 3, (LPARAM) &hdItem);
1142     ok(retVal == FALSE, "Deleting already-deleted item should return FALSE, got %d\n", retVal);
1143     retVal = SendMessage(hChild, HDM_GETITEMCOUNT, 0, 0);
1144     ok(retVal == 3, "Getting item count should return 3, got %d\n", retVal);
1145
1146     retVal = SendMessage(hChild, HDM_DELETEITEM, 2, (LPARAM) &hdItem);
1147     ok(retVal == TRUE, "Deleting item 2 should return TRUE, got %d\n", retVal);
1148     retVal = SendMessage(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     retVal = SendMessage(hChild, HDM_GETITEM, 3, (LPARAM) &hdItem);
1157     ok(retVal == FALSE, "Getting already-deleted item should return FALSE, got %d\n", retVal);
1158
1159     retVal = SendMessage(hChild, HDM_GETITEM, 0, (LPARAM) &hdItem);
1160     ok(retVal == TRUE, "Getting the 1st header item should return TRUE, got %d\n", retVal);
1161
1162     ok_sequence(sequences, HEADER_SEQ_INDEX, getItem_seq, "getItem sequence testing", FALSE);
1163
1164     /* check if the item is the right one */
1165     strcmpResult =  strcmp(hdItem.pszText, firstHeaderItem);
1166     expect(0, strcmpResult);
1167     expect(80, hdItem.cxy);
1168
1169     iSize = SendMessage(hChild, HDM_GETITEMCOUNT, 0, 0);
1170
1171     /* item should be updated just after accepting new array */
1172     ShowWindow(hChild, SW_HIDE);
1173     retVal = SendMessage(hChild, HDM_SETORDERARRAY, iSize, (LPARAM) lpiarray);
1174     expect(TRUE, retVal);
1175     rect.left = 0;
1176     retVal = SendMessage(hChild, HDM_GETITEMRECT, 0, (LPARAM) &rect);
1177     expect(TRUE, retVal);
1178     ok(rect.left != 0, "Expected updated rectangle\n");
1179
1180     flush_sequences(sequences, NUM_MSG_SEQUENCES);
1181
1182     retVal = SendMessage(hChild, HDM_SETORDERARRAY, iSize, (LPARAM) lpiarray);
1183     ok(retVal == TRUE, "Setting header items order should return TRUE, got %d\n", retVal);
1184
1185     retVal = SendMessage(hChild, HDM_GETORDERARRAY, iSize, (LPARAM) lpiarrayReceived);
1186     ok(retVal == TRUE, "Getting header items order should return TRUE, got %d\n", retVal);
1187
1188     ok_sequence(sequences, HEADER_SEQ_INDEX, orderArray_seq, "set_get_orderArray sequence testing", FALSE);
1189
1190     /* check if the array order is set correctly and the size of the array is correct. */
1191     expect(2, iSize);
1192     expect(lpiarray[0], lpiarrayReceived[0]);
1193     expect(lpiarray[1], lpiarrayReceived[1]);
1194
1195     hdItem.mask = HDI_FORMAT;
1196     hdItem.fmt = HDF_CENTER | HDF_STRING;
1197
1198     flush_sequences(sequences, NUM_MSG_SEQUENCES);
1199
1200     retVal = SendMessage(hChild, HDM_SETITEM, 0, (LPARAM) &hdItem);
1201     ok(retVal == TRUE, "Aligning 1st header item to center should return TRUE, got %d\n", retVal);
1202     hdItem.fmt = HDF_RIGHT | HDF_STRING;
1203     retVal = SendMessage(hChild, HDM_SETITEM, 1, (LPARAM) &hdItem);
1204     ok(retVal == TRUE, "Aligning 2nd header item to right should return TRUE, got %d\n", retVal);
1205
1206     ok_sequence(sequences, HEADER_SEQ_INDEX, setItem_seq, "setItem sequence testing", FALSE);
1207     DestroyWindow(hChild);
1208 }
1209
1210 #define TEST_NMCUSTOMDRAW(draw_stage, item_spec, lparam, _left, _top, _right, _bottom) \
1211     ok(nm->dwDrawStage == draw_stage, "Invalid dwDrawStage %d vs %d\n", draw_stage, nm->dwDrawStage); \
1212     if (item_spec != -1) \
1213         ok(nm->dwItemSpec == item_spec, "Invalid dwItemSpec %d vs %ld\n", item_spec, nm->dwItemSpec); \
1214     ok(nm->lItemlParam == lparam, "Invalid lItemlParam %d vs %ld\n", lparam, nm->lItemlParam); \
1215     ok((nm->rc.top == _top && nm->rc.bottom == _bottom && nm->rc.left == _left && nm->rc.right == _right) || \
1216         broken(draw_stage != CDDS_ITEMPREPAINT), /* comctl32 < 5.80 */ \
1217         "Invalid rect (%d,%d) (%d,%d) vs (%d,%d) (%d,%d)\n", _left, _top, _right, _bottom, \
1218         nm->rc.left, nm->rc.top, nm->rc.right, nm->rc.bottom);
1219
1220 static LRESULT customdraw_1(int n, NMCUSTOMDRAW *nm)
1221 {
1222     if (nm == NULL) {  /* test ended */
1223         ok(n==1, "NM_CUSTOMDRAW messages: %d, expected: 1\n", n);
1224         return 0;
1225     }
1226
1227     switch (n)
1228     {
1229     case 0:
1230         /* don't test dwItemSpec - it's 0 no comctl5 but 1308756 on comctl6 */
1231         TEST_NMCUSTOMDRAW(CDDS_PREPAINT, -1, 0, 0, 0, 670, g_customheight);
1232         return 0;
1233     }
1234
1235     ok(FALSE, "To many custom draw messages (n=%d, nm->dwDrawStage=%d)\n", n, nm->dwDrawStage);
1236     return -1;
1237 }
1238
1239 static LRESULT customdraw_2(int n, NMCUSTOMDRAW *nm)
1240 {
1241     if (nm == NULL) {  /* test ended */
1242         ok(n==4, "NM_CUSTOMDRAW messages: %d, expected: 4\n", n);
1243         return 0;
1244     }
1245
1246     switch (n)
1247     {
1248     case 0:
1249         TEST_NMCUSTOMDRAW(CDDS_PREPAINT, -1, 0, 0, 0, 670, g_customheight);
1250         return CDRF_NOTIFYITEMDRAW;
1251     case 1:
1252         TEST_NMCUSTOMDRAW(CDDS_ITEMPREPAINT, 0, 0, 0, 0, 50, g_customheight);
1253         return 0;
1254     case 2:
1255         TEST_NMCUSTOMDRAW(CDDS_ITEMPREPAINT, 1, 5, 50, 0, 150, g_customheight);
1256         return 0;
1257     case 3:
1258         TEST_NMCUSTOMDRAW(CDDS_ITEMPREPAINT, 2, 10, 150, 0, 300, g_customheight);
1259         return 0;
1260     }
1261
1262     ok(FALSE, "To many custom draw messages (n=%d, nm->dwDrawStage=%d)\n", n, nm->dwDrawStage);
1263     return 0;
1264 }
1265
1266 static LRESULT customdraw_3(int n, NMCUSTOMDRAW *nm)
1267 {
1268     if (nm == NULL) {  /* test ended */
1269         ok(n==5, "NM_CUSTOMDRAW messages: %d, expected: 5\n", n);
1270         return 0;
1271     }
1272
1273     switch (n)
1274     {
1275     case 0:
1276         TEST_NMCUSTOMDRAW(CDDS_PREPAINT, -1, 0, 0, 0, 670, g_customheight);
1277         return CDRF_NOTIFYITEMDRAW|CDRF_NOTIFYPOSTERASE|CDRF_NOTIFYPOSTPAINT|CDRF_SKIPDEFAULT;
1278     case 1:
1279         TEST_NMCUSTOMDRAW(CDDS_ITEMPREPAINT, 0, 0, 0, 0, 50, g_customheight);
1280         return 0;
1281     case 2:
1282         TEST_NMCUSTOMDRAW(CDDS_ITEMPREPAINT, 1, 5, 50, 0, 150, g_customheight);
1283         return 0;
1284     case 3:
1285         TEST_NMCUSTOMDRAW(CDDS_ITEMPREPAINT, 2, 10, 150, 0, 300, g_customheight);
1286         return 0;
1287     case 4:
1288         TEST_NMCUSTOMDRAW(CDDS_POSTPAINT, -1, 0, 0, 0, 670, g_customheight);
1289         return 0;
1290     }
1291
1292     ok(FALSE, "To many custom draw messages (n=%d, nm->dwDrawStage=%d)\n", n, nm->dwDrawStage);
1293     return 0;
1294 }
1295
1296
1297 static LRESULT customdraw_4(int n, NMCUSTOMDRAW *nm)
1298 {
1299     if (nm == NULL) {  /* test ended */
1300         ok(n==4, "NM_CUSTOMDRAW messages: %d, expected: 4\n", n);
1301         return 0;
1302     }
1303
1304     switch (n)
1305     {
1306     case 0:
1307         TEST_NMCUSTOMDRAW(CDDS_PREPAINT, -1, 0, 0, 0, 670, g_customheight);
1308         return CDRF_NOTIFYITEMDRAW|CDRF_NOTIFYPOSTPAINT;
1309     case 1:
1310         TEST_NMCUSTOMDRAW(CDDS_ITEMPREPAINT, 0, 0, 0, 0, 50, g_customheight);
1311         return 0;
1312     case 2:
1313         TEST_NMCUSTOMDRAW(CDDS_ITEMPREPAINT, 2, 10, 150, 0, 300, g_customheight);
1314         return 0;
1315     case 3:
1316         TEST_NMCUSTOMDRAW(CDDS_POSTPAINT, -1, 0, 0, 0, 670, g_customheight);
1317         return 0;
1318     }
1319
1320     ok(FALSE, "To many custom draw messages (n=%d, nm->dwDrawStage=%d)\n", n, nm->dwDrawStage);
1321     return 0;
1322 }
1323
1324 static void run_customdraw_scenario(CUSTOMDRAWPROC proc)
1325 {
1326     g_CustomDrawProc = proc;
1327     g_CustomDrawCount = 0;
1328     InvalidateRect(hWndHeader, NULL, TRUE);
1329     UpdateWindow(hWndHeader);
1330     proc(g_CustomDrawCount, NULL);
1331     g_CustomDrawProc = NULL;
1332 }
1333
1334 static void test_customdraw(void)
1335 {
1336     int i;
1337     HDITEM item;
1338     RECT rect;
1339     CHAR name[] = "Test";
1340     hWndHeader = create_header_control();
1341     GetClientRect(hWndHeader, &rect);
1342     ok(rect.right - rect.left == 670 && rect.bottom - rect.top == g_customheight,
1343         "Tests will fail as header size is %dx%d instead of 670x%d\n",
1344         rect.right - rect.left, rect.bottom - rect.top, g_customheight);
1345
1346     for (i = 0; i < 3; i++)
1347     {
1348         ZeroMemory(&item, sizeof(item));
1349         item.mask = HDI_TEXT|HDI_WIDTH;
1350         item.cxy = 50*(i+1);
1351         item.pszText = name;
1352         item.lParam = i*5;
1353         SendMessage(hWndHeader, HDM_INSERTITEM, i, (LPARAM)&item);
1354     }
1355
1356     run_customdraw_scenario(customdraw_1);
1357     run_customdraw_scenario(customdraw_2);
1358     run_customdraw_scenario(customdraw_3);
1359
1360     ZeroMemory(&item, sizeof(item));
1361     item.mask = HDI_FORMAT;
1362     item.fmt = HDF_OWNERDRAW;
1363     SendMessage(hWndHeader, HDM_SETITEM, 1, (LPARAM)&item);
1364     g_DrawItem.CtlID = 0;
1365     g_DrawItem.CtlType = ODT_HEADER;
1366     g_DrawItem.hwndItem = hWndHeader;
1367     g_DrawItem.itemID = 1;
1368     g_DrawItem.itemState = 0;
1369     SendMessage(hWndHeader, HDM_GETITEMRECT, 1, (LPARAM)&g_DrawItem.rcItem);
1370     run_customdraw_scenario(customdraw_4);
1371     ok(g_DrawItemReceived, "WM_DRAWITEM not received\n");
1372     DestroyWindow(hWndHeader);
1373     hWndHeader = NULL;
1374     g_DrawItem.CtlType = 0;
1375     g_DrawItemReceived = FALSE;
1376 }
1377
1378 static void check_order(const int expected_id[], const int expected_order[],
1379                         int count, const char *type)
1380 {
1381     int i;
1382     HDITEMA hdi;
1383
1384     ok(getItemCount(hWndHeader) == count, "Invalid item count in order tests\n");
1385     for (i = 0; i < count; i++)
1386     {
1387         hdi.mask = HDI_LPARAM|HDI_ORDER;
1388         SendMessage(hWndHeader, HDM_GETITEMA, i, (LPARAM)&hdi);
1389         ok(hdi.lParam == expected_id[i],
1390             "Invalid item ids after '%s'- item %d has lParam %d\n", type, i, (int)hdi.lParam);
1391         ok(hdi.iOrder == expected_order[i],
1392             "Invalid item order after '%s'- item %d has iOrder %d\n", type, i, hdi.iOrder);
1393     }
1394 }
1395
1396 static void test_header_order (void)
1397 {
1398     const int rand1[] = {0, 1, 1, 0, 4};
1399     const int rand2[] = {4, 5, 6, 7, 4};
1400     const int rand3[] = {5, 5, 1, 6, 1};
1401     const int rand4[] = {1, 5, 2, 7, 6, 1, 4, 2, 3, 2};
1402     const int rand5[] = {7, 8, 5, 6, 7, 2, 1, 9, 10, 10};
1403     const int rand6[] = {2, 8, 3, 4, 0};
1404
1405     const int ids1[] = {3, 0, 2, 1, 4};
1406     const int ord1[] = {0, 1, 2, 3, 4};
1407     const int ids2[] = {3, 9, 7, 0, 2, 1, 4, 8, 6, 5};
1408     const int ord2[] = {0, 4, 7, 1, 2, 3, 9, 8, 6, 5};
1409     const int ord3[] = {0, 3, 9, 2, 1, 8, 7, 6, 5, 4};
1410     const int ids4[] = {9, 0, 1, 8, 6};
1411     const int ord4[] = {1, 0, 4, 3, 2};
1412
1413     char buffer[20];
1414     HDITEMA hdi;
1415     int i;
1416
1417     hWndHeader = create_header_control();
1418
1419     ZeroMemory(&hdi, sizeof(HDITEMA));
1420     hdi.mask = HDI_TEXT | HDI_LPARAM;
1421     hdi.pszText = buffer;
1422     strcpy(buffer, "test");
1423
1424     for (i = 0; i < 5; i++)
1425     {
1426         hdi.lParam = i;
1427         SendMessage(hWndHeader, HDM_INSERTITEMA, rand1[i], (LPARAM)&hdi);
1428         rand();
1429     }
1430     check_order(ids1, ord1, 5, "insert without iOrder");
1431
1432     hdi.mask |= HDI_ORDER;
1433     for (i = 0; i < 5; i++)
1434     {
1435         hdi.lParam = i + 5;
1436         hdi.iOrder = rand2[i];
1437         SendMessage(hWndHeader, HDM_INSERTITEMA, rand3[i], (LPARAM)&hdi);
1438         rand(); rand();
1439     }
1440     check_order(ids2, ord2, 10, "insert with order");
1441
1442     hdi.mask = HDI_ORDER;
1443     for (i=0; i<10; i++)
1444     {
1445         hdi.iOrder = rand5[i];
1446         SendMessage(hWndHeader, HDM_SETITEMA, rand4[i], (LPARAM)&hdi);
1447         rand(); rand();
1448     }
1449     check_order(ids2, ord3, 10, "setitems changing order");
1450
1451     for (i=0; i<5; i++)
1452         SendMessage(hWndHeader, HDM_DELETEITEM, rand6[i], 0);
1453     check_order(ids4, ord4, 5, "deleteitem");
1454
1455     DestroyWindow(hWndHeader);
1456 }
1457
1458 static LRESULT CALLBACK HeaderTestWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
1459 {
1460     DRAWITEMSTRUCT *di;
1461     switch(msg) {
1462
1463     case WM_NOTIFY:
1464     {
1465         NMHEADERA *hdr = (NMHEADER *)lParam;
1466         EXPECTEDNOTIFY *expected;
1467         int i;
1468
1469         if (hdr->hdr.code == NM_CUSTOMDRAW)
1470             if (g_CustomDrawProc)
1471                 return g_CustomDrawProc(g_CustomDrawCount++, (NMCUSTOMDRAW*)hdr);
1472
1473         for (i=0; i<nUnexpectedNotify; i++)
1474             ok(hdr->hdr.code != unexpectedNotify[i], "Received invalid notify %d\n", hdr->hdr.code);
1475         
1476         if (nReceivedNotify >= nExpectedNotify || hdr->hdr.hwndFrom != hWndHeader )
1477             break;
1478
1479         expected = &expectedNotify[nReceivedNotify];
1480         if (hdr->hdr.code != expected->iCode)
1481             break;
1482         
1483         nReceivedNotify++;
1484         compare_items(hdr->hdr.code, &expected->hdItem, hdr->pitem, expected->fUnicode);
1485         break;
1486     }
1487
1488     case WM_DRAWITEM:
1489         di = (DRAWITEMSTRUCT *)lParam;
1490         ok(g_DrawItem.CtlType != 0, "Unexpected WM_DRAWITEM\n");
1491         if (g_DrawItem.CtlType == 0) return 0;
1492         g_DrawItemReceived = TRUE;
1493         compare(di->CtlType,   g_DrawItem.CtlType, "%d");
1494         compare(di->CtlID,     g_DrawItem.CtlID, "%d");
1495         compare(di->hwndItem,  g_DrawItem.hwndItem, "%p");
1496         compare(di->itemID,    g_DrawItem.itemID, "%d");
1497         compare(di->itemState, g_DrawItem.itemState, "%d");
1498         compare(di->rcItem.left,   g_DrawItem.rcItem.left, "%d");
1499         compare(di->rcItem.top,    g_DrawItem.rcItem.top, "%d");
1500         compare(di->rcItem.right,  g_DrawItem.rcItem.right, "%d");
1501         compare(di->rcItem.bottom, g_DrawItem.rcItem.bottom, "%d");
1502         break;
1503
1504     case WM_DESTROY:
1505         PostQuitMessage(0);
1506         break;
1507   
1508     default:
1509         return DefWindowProcA(hWnd, msg, wParam, lParam);
1510     }
1511     
1512     return 0L;
1513 }
1514
1515 static int init(void)
1516 {
1517     HMODULE hComctl32;
1518     BOOL (WINAPI *pInitCommonControlsEx)(const INITCOMMONCONTROLSEX*);
1519     WNDCLASSA wc;
1520     INITCOMMONCONTROLSEX iccex;
1521     TEXTMETRICA tm;
1522     HFONT hOldFont;
1523     HDC hdc;
1524
1525     hComctl32 = GetModuleHandleA("comctl32.dll");
1526     pInitCommonControlsEx = (void*)GetProcAddress(hComctl32, "InitCommonControlsEx");
1527     if (!pInitCommonControlsEx)
1528     {
1529         skip("InitCommonControlsEx() is missing. Skipping the tests\n");
1530         return 0;
1531     }
1532
1533     iccex.dwSize = sizeof(iccex);
1534     iccex.dwICC  = ICC_USEREX_CLASSES;
1535     pInitCommonControlsEx(&iccex);
1536
1537     wc.style = CS_HREDRAW | CS_VREDRAW;
1538     wc.cbClsExtra = 0;
1539     wc.cbWndExtra = 0;
1540     wc.hInstance = GetModuleHandleA(NULL);
1541     wc.hIcon = NULL;
1542     wc.hCursor = LoadCursorA(NULL, IDC_ARROW);
1543     wc.hbrBackground = GetSysColorBrush(COLOR_WINDOW);
1544     wc.lpszMenuName = NULL;
1545     wc.lpszClassName = "HeaderTestClass";
1546     wc.lpfnWndProc = HeaderTestWndProc;
1547     RegisterClassA(&wc);
1548
1549     /* The height of the header control depends on the height of the system font.
1550        The height of the system font is dpi dependent */
1551     hdc = GetDC(0);
1552     hOldFont = SelectObject(hdc, GetStockObject(SYSTEM_FONT));
1553     GetTextMetricsA(hdc, &tm);
1554     /* 2 dot extra space are needed for the border */
1555     g_customheight = tm.tmHeight + 2;
1556     trace("customdraw height: %d (dpi: %d)\n", g_customheight, GetDeviceCaps(hdc, LOGPIXELSY));
1557     SelectObject(hdc, hOldFont);
1558     ReleaseDC(0, hdc);
1559
1560     hHeaderParentWnd = CreateWindowExA(0, "HeaderTestClass", "Header test", WS_OVERLAPPEDWINDOW, 
1561       CW_USEDEFAULT, CW_USEDEFAULT, 672+2*GetSystemMetrics(SM_CXSIZEFRAME),
1562       226+GetSystemMetrics(SM_CYCAPTION)+2*GetSystemMetrics(SM_CYSIZEFRAME),
1563       NULL, NULL, GetModuleHandleA(NULL), 0);
1564     assert(hHeaderParentWnd != NULL);
1565     ShowWindow(hHeaderParentWnd, SW_SHOW);
1566     return 1;
1567 }
1568
1569 START_TEST(header)
1570 {
1571     HWND parent_hwnd;
1572
1573     if (!init())
1574         return;
1575
1576     test_header_control();
1577     test_header_order();
1578     test_customdraw();
1579
1580     DestroyWindow(hHeaderParentWnd);
1581
1582     init_msg_sequences(sequences, NUM_MSG_SEQUENCES);
1583     parent_hwnd = create_custom_parent_window();
1584     ok_sequence(sequences, PARENT_SEQ_INDEX, create_parent_wnd_seq, "create parent windows", FALSE);
1585
1586     test_hdm_index_messages(parent_hwnd);
1587     test_hdm_getitemrect(parent_hwnd);
1588     test_hdm_hittest(parent_hwnd);
1589     test_hdm_layout(parent_hwnd);
1590     test_hdm_ordertoindex(parent_hwnd);
1591     test_hdm_sethotdivider(parent_hwnd);
1592     test_hdm_imageMessages(parent_hwnd);
1593     test_hdm_filterMessages(parent_hwnd);
1594     test_hdm_unicodeformatMessages(parent_hwnd);
1595     test_hdm_bitmapmarginMessages(parent_hwnd);
1596
1597     DestroyWindow(parent_hwnd);
1598
1599 }