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