1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300
|
/*
* Header control
*
* Copyright 1998 Eric Kohl
* Copyright 2000 Eric Kohl for CodeWeavers
* Copyright 2003 Maxime Bellenge
* Copyright 2006 Mikolaj Zalewski
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*
* TODO:
* - Imagelist support (completed?)
* - Hottrack support (completed?)
* - Filters support (HDS_FILTER, HDI_FILTER, HDM_*FILTER*, HDN_*FILTER*)
* - New Windows Vista features
*/
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include "windef.h"
#include "winbase.h"
#include "wine/unicode.h"
#include "wingdi.h"
#include "winuser.h"
#include "winnls.h"
#include "commctrl.h"
#include "comctl32.h"
#include "vssym32.h"
#include "uxtheme.h"
#include "wine/debug.h"
#include "wine/heap.h"
WINE_DEFAULT_DEBUG_CHANNEL(header);
typedef struct
{
INT cxy;
HBITMAP hbm;
LPWSTR pszText;
INT fmt;
LPARAM lParam;
INT iImage;
INT iOrder; /* see documentation of HD_ITEM */
BOOL bDown; /* is item pressed? (used for drawing) */
RECT rect; /* bounding rectangle of the item */
DWORD callbackMask; /* HDI_* flags for items that are callback */
} HEADER_ITEM;
typedef struct
{
HWND hwndSelf; /* Control window */
HWND hwndNotify; /* Owner window to send notifications to */
INT nNotifyFormat; /* format used for WM_NOTIFY messages */
UINT uNumItem; /* number of items (columns) */
INT nHeight; /* height of the header (pixels) */
HFONT hFont; /* handle to the current font */
HCURSOR hcurArrow; /* handle to the arrow cursor */
HCURSOR hcurDivider; /* handle to a cursor (used over dividers) <-|-> */
HCURSOR hcurDivopen; /* handle to a cursor (used over dividers) <-||-> */
BOOL bCaptured; /* Is the mouse captured? */
BOOL bPressed; /* Is a header item pressed (down)? */
BOOL bDragging; /* Are we dragging an item? */
BOOL bTracking; /* Is in tracking mode? */
POINT ptLButtonDown; /* The point where the left button was pressed */
DWORD dwStyle; /* the cached window GWL_STYLE */
INT iMoveItem; /* index of tracked item. (Tracking mode) */
INT xTrackOffset; /* distance between the right side of the tracked item and the cursor */
INT xOldTrack; /* track offset (see above) after the last WM_MOUSEMOVE */
INT iHotItem; /* index of hot item (cursor is over this item) */
INT iHotDivider; /* index of the hot divider (used while dragging an item or by HDM_SETHOTDIVIDER) */
INT iMargin; /* width of the margin that surrounds a bitmap */
INT filter_change_timeout; /* change timeout set with HDM_SETFILTERCHANGETIMEOUT */
HIMAGELIST himl; /* handle to an image list (may be 0) */
HEADER_ITEM *items; /* pointer to array of HEADER_ITEM's */
INT *order; /* array of item IDs indexed by order */
BOOL bRectsValid; /* validity flag for bounding rectangles */
} HEADER_INFO;
#define VERT_BORDER 4
#define DIVIDER_WIDTH 10
#define HOT_DIVIDER_WIDTH 2
#define MAX_HEADER_TEXT_LEN 260
#define HDN_UNICODE_OFFSET 20
#define HDN_FIRST_UNICODE (HDN_FIRST-HDN_UNICODE_OFFSET)
#define HDI_SUPPORTED_FIELDS (HDI_WIDTH|HDI_TEXT|HDI_FORMAT|HDI_LPARAM|HDI_BITMAP|HDI_IMAGE|HDI_ORDER)
#define HDI_UNSUPPORTED_FIELDS (HDI_FILTER)
#define HDI_UNKNOWN_FIELDS (~(HDI_SUPPORTED_FIELDS|HDI_UNSUPPORTED_FIELDS|HDI_DI_SETITEM))
#define HDI_COMCTL32_4_0_FIELDS (HDI_WIDTH|HDI_TEXT|HDI_FORMAT|HDI_LPARAM|HDI_BITMAP)
static BOOL HEADER_PrepareCallbackItems(const HEADER_INFO *infoPtr, INT iItem, INT reqMask);
static void HEADER_FreeCallbackItems(HEADER_ITEM *lpItem);
static LRESULT HEADER_SendNotify(const HEADER_INFO *infoPtr, UINT code, NMHDR *hdr);
static LRESULT HEADER_SendCtrlCustomDraw(const HEADER_INFO *infoPtr, DWORD dwDrawStage, HDC hdc, const RECT *rect);
static const WCHAR themeClass[] = {'H','e','a','d','e','r',0};
static void HEADER_StoreHDItemInHeader(HEADER_ITEM *lpItem, UINT mask, const HDITEMW *phdi, BOOL fUnicode)
{
if (mask & HDI_UNSUPPORTED_FIELDS)
FIXME("unsupported header fields %x\n", (mask & HDI_UNSUPPORTED_FIELDS));
if (mask & HDI_BITMAP)
lpItem->hbm = phdi->hbm;
if (mask & HDI_FORMAT)
lpItem->fmt = phdi->fmt;
if (mask & HDI_LPARAM)
lpItem->lParam = phdi->lParam;
if (mask & HDI_WIDTH)
lpItem->cxy = phdi->cxy;
if (mask & HDI_IMAGE)
{
lpItem->iImage = phdi->iImage;
if (phdi->iImage == I_IMAGECALLBACK)
lpItem->callbackMask |= HDI_IMAGE;
else
lpItem->callbackMask &= ~HDI_IMAGE;
}
if (mask & HDI_TEXT)
{
heap_free(lpItem->pszText);
lpItem->pszText = NULL;
if (phdi->pszText != LPSTR_TEXTCALLBACKW) /* covers != TEXTCALLBACKA too */
{
static const WCHAR emptyString[] = {0};
LPCWSTR pszText = (phdi->pszText != NULL ? phdi->pszText : emptyString);
if (fUnicode)
Str_SetPtrW(&lpItem->pszText, pszText);
else
Str_SetPtrAtoW(&lpItem->pszText, (LPCSTR)pszText);
lpItem->callbackMask &= ~HDI_TEXT;
}
else
{
lpItem->pszText = NULL;
lpItem->callbackMask |= HDI_TEXT;
}
}
}
static inline LRESULT
HEADER_IndexToOrder (const HEADER_INFO *infoPtr, INT iItem)
{
HEADER_ITEM *lpItem = &infoPtr->items[iItem];
return lpItem->iOrder;
}
static INT
HEADER_OrderToIndex(const HEADER_INFO *infoPtr, INT iorder)
{
if ((iorder <0) || iorder >= infoPtr->uNumItem)
return iorder;
return infoPtr->order[iorder];
}
static void
HEADER_ChangeItemOrder(const HEADER_INFO *infoPtr, INT iItem, INT iNewOrder)
{
HEADER_ITEM *lpItem = &infoPtr->items[iItem];
INT i, nMin, nMax;
TRACE("%d: %d->%d\n", iItem, lpItem->iOrder, iNewOrder);
if (lpItem->iOrder < iNewOrder)
{
memmove(&infoPtr->order[lpItem->iOrder],
&infoPtr->order[lpItem->iOrder + 1],
(iNewOrder - lpItem->iOrder) * sizeof(INT));
}
if (iNewOrder < lpItem->iOrder)
{
memmove(&infoPtr->order[iNewOrder + 1],
&infoPtr->order[iNewOrder],
(lpItem->iOrder - iNewOrder) * sizeof(INT));
}
infoPtr->order[iNewOrder] = iItem;
nMin = min(lpItem->iOrder, iNewOrder);
nMax = max(lpItem->iOrder, iNewOrder);
for (i = nMin; i <= nMax; i++)
infoPtr->items[infoPtr->order[i]].iOrder = i;
}
/* Note: if iItem is the last item then this function returns infoPtr->uNumItem */
static INT
HEADER_NextItem(const HEADER_INFO *infoPtr, INT iItem)
{
return HEADER_OrderToIndex(infoPtr, HEADER_IndexToOrder(infoPtr, iItem)+1);
}
static INT
HEADER_PrevItem(const HEADER_INFO *infoPtr, INT iItem)
{
return HEADER_OrderToIndex(infoPtr, HEADER_IndexToOrder(infoPtr, iItem)-1);
}
/* TRUE when item is not resizable with dividers,
note that valid index should be supplied */
static inline BOOL
HEADER_IsItemFixed(const HEADER_INFO *infoPtr, INT iItem)
{
return (infoPtr->dwStyle & HDS_NOSIZING) || (infoPtr->items[iItem].fmt & HDF_FIXEDWIDTH);
}
static void
HEADER_SetItemBounds (HEADER_INFO *infoPtr)
{
HEADER_ITEM *phdi;
RECT rect;
unsigned int i;
int x;
infoPtr->bRectsValid = TRUE;
if (infoPtr->uNumItem == 0)
return;
GetClientRect (infoPtr->hwndSelf, &rect);
x = rect.left;
for (i = 0; i < infoPtr->uNumItem; i++) {
phdi = &infoPtr->items[HEADER_OrderToIndex(infoPtr,i)];
phdi->rect.top = rect.top;
phdi->rect.bottom = rect.bottom;
phdi->rect.left = x;
phdi->rect.right = phdi->rect.left + ((phdi->cxy>0)?phdi->cxy:0);
x = phdi->rect.right;
}
}
static LRESULT
HEADER_Size (HEADER_INFO *infoPtr)
{
HEADER_SetItemBounds(infoPtr);
return 0;
}
static void HEADER_GetHotDividerRect(const HEADER_INFO *infoPtr, RECT *r)
{
INT iDivider = infoPtr->iHotDivider;
if (infoPtr->uNumItem > 0)
{
HEADER_ITEM *lpItem;
if (iDivider < infoPtr->uNumItem)
{
lpItem = &infoPtr->items[iDivider];
r->left = lpItem->rect.left - HOT_DIVIDER_WIDTH/2;
r->right = lpItem->rect.left + HOT_DIVIDER_WIDTH/2;
}
else
{
lpItem = &infoPtr->items[HEADER_OrderToIndex(infoPtr, infoPtr->uNumItem-1)];
r->left = lpItem->rect.right - HOT_DIVIDER_WIDTH/2;
r->right = lpItem->rect.right + HOT_DIVIDER_WIDTH/2;
}
r->top = lpItem->rect.top;
r->bottom = lpItem->rect.bottom;
}
else
{
RECT clientRect;
GetClientRect(infoPtr->hwndSelf, &clientRect);
*r = clientRect;
r->right = r->left + HOT_DIVIDER_WIDTH/2;
}
}
static void
HEADER_FillItemFrame(HEADER_INFO *infoPtr, HDC hdc, RECT *r, const HEADER_ITEM *item, BOOL hottrack)
{
HTHEME theme = GetWindowTheme (infoPtr->hwndSelf);
if (theme) {
int state = (item->bDown) ? HIS_PRESSED : (hottrack ? HIS_HOT : HIS_NORMAL);
DrawThemeBackground (theme, hdc, HP_HEADERITEM, state, r, NULL);
GetThemeBackgroundContentRect (theme, hdc, HP_HEADERITEM, state, r, r);
}
else
{
HBRUSH hbr = CreateSolidBrush(GetBkColor(hdc));
FillRect(hdc, r, hbr);
DeleteObject(hbr);
}
}
static void
HEADER_DrawItemFrame(HEADER_INFO *infoPtr, HDC hdc, RECT *r, const HEADER_ITEM *item)
{
if (GetWindowTheme(infoPtr->hwndSelf)) return;
if (!(infoPtr->dwStyle & HDS_FLAT))
{
if (infoPtr->dwStyle & HDS_BUTTONS) {
if (item->bDown)
DrawEdge (hdc, r, BDR_RAISEDOUTER, BF_RECT | BF_FLAT | BF_ADJUST);
else
DrawEdge (hdc, r, EDGE_RAISED, BF_RECT | BF_SOFT | BF_ADJUST);
}
else
DrawEdge (hdc, r, EDGE_ETCHED, BF_BOTTOM | BF_RIGHT | BF_ADJUST);
}
}
/* Create a region for the sort arrow with its bounding rect's top-left
co-ord x,y and its height h. */
static HRGN create_sort_arrow( INT x, INT y, INT h, BOOL is_up )
{
char buffer[256];
RGNDATA *data = (RGNDATA *)buffer;
DWORD size = FIELD_OFFSET(RGNDATA, Buffer[h * sizeof(RECT)]);
INT i, yinc = 1;
HRGN rgn;
if (size > sizeof(buffer))
{
data = heap_alloc( size );
if (!data) return NULL;
}
data->rdh.dwSize = sizeof(data->rdh);
data->rdh.iType = RDH_RECTANGLES;
data->rdh.nCount = 0;
data->rdh.nRgnSize = h * sizeof(RECT);
if (!is_up)
{
y += h - 1;
yinc = -1;
}
x += h - 1; /* set x to the centre */
for (i = 0; i < h; i++, y += yinc)
{
RECT *rect = (RECT *)data->Buffer + data->rdh.nCount;
rect->left = x - i;
rect->top = y;
rect->right = x + i + 1;
rect->bottom = y + 1;
data->rdh.nCount++;
}
rgn = ExtCreateRegion( NULL, size, data );
if (data != (RGNDATA *)buffer) heap_free( data );
return rgn;
}
static INT
HEADER_DrawItem (HEADER_INFO *infoPtr, HDC hdc, INT iItem, BOOL bHotTrack, LRESULT lCDFlags)
{
HEADER_ITEM *phdi = &infoPtr->items[iItem];
RECT r;
INT oldBkMode;
HTHEME theme = GetWindowTheme (infoPtr->hwndSelf);
NMCUSTOMDRAW nmcd;
int state = 0;
TRACE("DrawItem(iItem %d bHotTrack %d unicode flag %d)\n", iItem, bHotTrack, (infoPtr->nNotifyFormat == NFR_UNICODE));
r = phdi->rect;
if (r.right - r.left == 0)
return phdi->rect.right;
if (theme)
state = (phdi->bDown) ? HIS_PRESSED : (bHotTrack ? HIS_HOT : HIS_NORMAL);
/* Set the colors before sending NM_CUSTOMDRAW so that it can change them */
SetTextColor(hdc, (bHotTrack && !theme) ? comctl32_color.clrHighlight : comctl32_color.clrBtnText);
SetBkColor(hdc, comctl32_color.clr3dFace);
if (lCDFlags & CDRF_NOTIFYITEMDRAW && !(phdi->fmt & HDF_OWNERDRAW))
{
LRESULT lCDItemFlags;
nmcd.dwDrawStage = CDDS_PREPAINT | CDDS_ITEM;
nmcd.hdc = hdc;
nmcd.dwItemSpec = iItem;
nmcd.rc = r;
nmcd.uItemState = phdi->bDown ? CDIS_SELECTED : 0;
nmcd.lItemlParam = phdi->lParam;
lCDItemFlags = HEADER_SendNotify(infoPtr, NM_CUSTOMDRAW, (NMHDR *)&nmcd);
if (lCDItemFlags & CDRF_SKIPDEFAULT)
return phdi->rect.right;
}
/* Fill background, owner could draw over it. */
HEADER_FillItemFrame(infoPtr, hdc, &r, phdi, bHotTrack);
if (phdi->fmt & HDF_OWNERDRAW)
{
DRAWITEMSTRUCT dis;
BOOL ret;
dis.CtlType = ODT_HEADER;
dis.CtlID = GetWindowLongPtrW (infoPtr->hwndSelf, GWLP_ID);
dis.itemID = iItem;
dis.itemAction = ODA_DRAWENTIRE;
dis.itemState = phdi->bDown ? ODS_SELECTED : 0;
dis.hwndItem = infoPtr->hwndSelf;
dis.hDC = hdc;
dis.rcItem = phdi->rect;
dis.itemData = phdi->lParam;
oldBkMode = SetBkMode(hdc, TRANSPARENT);
ret = SendMessageW (infoPtr->hwndNotify, WM_DRAWITEM, dis.CtlID, (LPARAM)&dis);
if (oldBkMode != TRANSPARENT)
SetBkMode(hdc, oldBkMode);
if (!ret)
HEADER_FillItemFrame(infoPtr, hdc, &r, phdi, bHotTrack);
/* Edges are always drawn if we don't have attached theme. */
HEADER_DrawItemFrame(infoPtr, hdc, &r, phdi);
/* If application processed WM_DRAWITEM we should skip label painting,
edges are drawn no matter what. */
if (ret) return phdi->rect.right;
}
else
HEADER_DrawItemFrame(infoPtr, hdc, &r, phdi);
if (phdi->bDown) {
r.left += 2;
r.top += 2;
}
/* Now text and image */
{
INT rw, rh; /* width and height of r */
INT *x = NULL; /* x and ... */
UINT *w = NULL; /* ... width of the pic (bmp or img) which is part of cnt */
/* cnt,txt,img,bmp */
INT cx, tx, ix, bx;
UINT cw, tw, iw, bw;
INT img_cx, img_cy;
INT sort_w, sort_x, sort_h;
BITMAP bmp;
HEADER_PrepareCallbackItems(infoPtr, iItem, HDI_TEXT|HDI_IMAGE);
cw = iw = bw = sort_w = sort_h = 0;
rw = r.right - r.left;
rh = r.bottom - r.top;
if (phdi->fmt & HDF_STRING) {
RECT textRect;
SetRectEmpty(&textRect);
if (theme) {
GetThemeTextExtent(theme, hdc, HP_HEADERITEM, state, phdi->pszText, -1,
DT_LEFT|DT_VCENTER|DT_SINGLELINE, NULL, &textRect);
} else {
DrawTextW (hdc, phdi->pszText, -1,
&textRect, DT_LEFT|DT_VCENTER|DT_SINGLELINE|DT_CALCRECT);
}
cw = textRect.right - textRect.left + 2 * infoPtr->iMargin;
}
if (phdi->fmt & (HDF_SORTUP | HDF_SORTDOWN)) {
sort_h = MulDiv( infoPtr->nHeight - VERT_BORDER, 4, 13 );
sort_w = 2 * sort_h - 1 + infoPtr->iMargin * 2;
cw += sort_w;
} else { /* sort arrows take precedent over images/bitmaps */
if ((phdi->fmt & HDF_IMAGE) && ImageList_GetIconSize( infoPtr->himl, &img_cx, &img_cy )) {
iw = img_cx + 2 * infoPtr->iMargin;
x = &ix;
w = &iw;
}
if ((phdi->fmt & HDF_BITMAP) && (phdi->hbm)) {
GetObjectW (phdi->hbm, sizeof(BITMAP), &bmp);
bw = bmp.bmWidth + 2 * infoPtr->iMargin;
if (!iw) {
x = &bx;
w = &bw;
}
}
if (bw || iw)
cw += *w;
}
/* align cx using the unclipped cw */
if ((phdi->fmt & HDF_JUSTIFYMASK) == HDF_LEFT)
cx = r.left;
else if ((phdi->fmt & HDF_JUSTIFYMASK) == HDF_CENTER)
cx = r.left + rw / 2 - cw / 2;
else /* HDF_RIGHT */
cx = r.right - cw;
/* clip cx & cw */
if (cx < r.left)
cx = r.left;
if (cx + cw > r.right)
cw = r.right - cx;
tx = cx + infoPtr->iMargin;
/* since cw might have changed we have to recalculate tw */
tw = cw - infoPtr->iMargin * 2;
tw -= sort_w;
sort_x = cx + tw + infoPtr->iMargin * 3;
if (iw || bw) {
tw -= *w;
if (phdi->fmt & HDF_BITMAP_ON_RIGHT) {
/* put pic behind text */
*x = cx + tw + infoPtr->iMargin * 3;
} else {
*x = cx + infoPtr->iMargin;
/* move text behind pic */
tx += *w;
}
}
if (iw && bw) {
/* since we're done with the layout we can
now calculate the position of bmp which
has no influence on alignment and layout
because of img */
if ((phdi->fmt & HDF_JUSTIFYMASK) == HDF_RIGHT)
bx = cx - bw + infoPtr->iMargin;
else
bx = cx + cw + infoPtr->iMargin;
}
if (sort_w || iw || bw) {
HDC hClipDC = GetDC(infoPtr->hwndSelf);
HRGN hClipRgn = CreateRectRgn(r.left, r.top, r.right, r.bottom);
SelectClipRgn(hClipDC, hClipRgn);
if (sort_w) {
HRGN arrow = create_sort_arrow( sort_x, r.top + (rh - sort_h) / 2,
sort_h, phdi->fmt & HDF_SORTUP );
if (arrow) {
FillRgn( hClipDC, arrow, GetSysColorBrush( COLOR_GRAYTEXT ) );
DeleteObject( arrow );
}
}
if (bw) {
HDC hdcBitmap = CreateCompatibleDC (hClipDC);
SelectObject (hdcBitmap, phdi->hbm);
BitBlt (hClipDC, bx, r.top + (rh - bmp.bmHeight) / 2,
bmp.bmWidth, bmp.bmHeight, hdcBitmap, 0, 0, SRCCOPY);
DeleteDC (hdcBitmap);
}
if (iw) {
ImageList_DrawEx (infoPtr->himl, phdi->iImage, hClipDC,
ix, r.top + (rh - img_cy) / 2,
img_cx, img_cy, CLR_DEFAULT, CLR_DEFAULT, 0);
}
DeleteObject(hClipRgn);
ReleaseDC(infoPtr->hwndSelf, hClipDC);
}
if (((phdi->fmt & HDF_STRING)
|| (!(phdi->fmt & (HDF_OWNERDRAW|HDF_STRING|HDF_BITMAP|
HDF_BITMAP_ON_RIGHT|HDF_IMAGE)))) /* no explicit format specified? */
&& (phdi->pszText)) {
oldBkMode = SetBkMode(hdc, TRANSPARENT);
r.left = tx;
r.right = tx + tw;
if (theme) {
DrawThemeText(theme, hdc, HP_HEADERITEM, state, phdi->pszText,
-1, DT_LEFT|DT_END_ELLIPSIS|DT_VCENTER|DT_SINGLELINE,
0, &r);
} else {
DrawTextW (hdc, phdi->pszText, -1,
&r, DT_LEFT|DT_END_ELLIPSIS|DT_VCENTER|DT_SINGLELINE);
}
if (oldBkMode != TRANSPARENT)
SetBkMode(hdc, oldBkMode);
}
HEADER_FreeCallbackItems(phdi);
}
return phdi->rect.right;
}
static void
HEADER_DrawHotDivider(const HEADER_INFO *infoPtr, HDC hdc)
{
HBRUSH brush;
RECT r;
HEADER_GetHotDividerRect(infoPtr, &r);
brush = CreateSolidBrush(comctl32_color.clrHighlight);
FillRect(hdc, &r, brush);
DeleteObject(brush);
}
static void
HEADER_Refresh (HEADER_INFO *infoPtr, HDC hdc)
{
HFONT hFont, hOldFont;
RECT rect, rcRest;
HBRUSH hbrBk;
UINT i;
INT x;
LRESULT lCDFlags;
HTHEME theme = GetWindowTheme (infoPtr->hwndSelf);
if (!infoPtr->bRectsValid)
HEADER_SetItemBounds(infoPtr);
/* get rect for the bar, adjusted for the border */
GetClientRect (infoPtr->hwndSelf, &rect);
lCDFlags = HEADER_SendCtrlCustomDraw(infoPtr, CDDS_PREPAINT, hdc, &rect);
if (infoPtr->bDragging)
ImageList_DragShowNolock(FALSE);
hFont = infoPtr->hFont ? infoPtr->hFont : GetStockObject (SYSTEM_FONT);
hOldFont = SelectObject (hdc, hFont);
/* draw Background */
if (infoPtr->uNumItem == 0 && theme == NULL) {
hbrBk = GetSysColorBrush(COLOR_3DFACE);
FillRect(hdc, &rect, hbrBk);
}
x = rect.left;
for (i = 0; x <= rect.right && i < infoPtr->uNumItem; i++) {
int idx = HEADER_OrderToIndex(infoPtr,i);
if (RectVisible(hdc, &infoPtr->items[idx].rect))
HEADER_DrawItem(infoPtr, hdc, idx, infoPtr->iHotItem == idx, lCDFlags);
x = infoPtr->items[idx].rect.right;
}
rcRest = rect;
rcRest.left = x;
if ((x <= rect.right) && RectVisible(hdc, &rcRest) && (infoPtr->uNumItem > 0)) {
if (theme != NULL) {
DrawThemeBackground(theme, hdc, HP_HEADERITEM, HIS_NORMAL, &rcRest, NULL);
}
else if (infoPtr->dwStyle & HDS_FLAT) {
hbrBk = GetSysColorBrush(COLOR_3DFACE);
FillRect(hdc, &rcRest, hbrBk);
}
else
{
if (infoPtr->dwStyle & HDS_BUTTONS)
DrawEdge (hdc, &rcRest, EDGE_RAISED, BF_TOP|BF_LEFT|BF_BOTTOM|BF_SOFT|BF_MIDDLE);
else
DrawEdge (hdc, &rcRest, EDGE_ETCHED, BF_BOTTOM|BF_MIDDLE);
}
}
if (infoPtr->iHotDivider != -1)
HEADER_DrawHotDivider(infoPtr, hdc);
if (infoPtr->bDragging)
ImageList_DragShowNolock(TRUE);
SelectObject (hdc, hOldFont);
if (lCDFlags & CDRF_NOTIFYPOSTPAINT)
HEADER_SendCtrlCustomDraw(infoPtr, CDDS_POSTPAINT, hdc, &rect);
}
static void
HEADER_RefreshItem (HEADER_INFO *infoPtr, INT iItem)
{
if (!infoPtr->bRectsValid)
HEADER_SetItemBounds(infoPtr);
InvalidateRect(infoPtr->hwndSelf, &infoPtr->items[iItem].rect, FALSE);
}
static void
HEADER_InternalHitTest (const HEADER_INFO *infoPtr, const POINT *lpPt, UINT *pFlags, INT *pItem)
{
RECT rect, rcTest;
UINT iCount;
INT width;
BOOL bNoWidth;
GetClientRect (infoPtr->hwndSelf, &rect);
*pFlags = 0;
bNoWidth = FALSE;
if (PtInRect (&rect, *lpPt))
{
if (infoPtr->uNumItem == 0) {
*pFlags |= HHT_NOWHERE;
*pItem = 1;
TRACE("NOWHERE\n");
return;
}
else {
/* somewhere inside */
for (iCount = 0; iCount < infoPtr->uNumItem; iCount++) {
rect = infoPtr->items[iCount].rect;
width = rect.right - rect.left;
if (width == 0) {
bNoWidth = TRUE;
continue;
}
if (PtInRect (&rect, *lpPt)) {
if (width <= 2 * DIVIDER_WIDTH) {
*pFlags |= HHT_ONHEADER;
*pItem = iCount;
TRACE("ON HEADER %d\n", iCount);
return;
}
if (HEADER_IndexToOrder(infoPtr, iCount) > 0) {
rcTest = rect;
rcTest.right = rcTest.left + DIVIDER_WIDTH;
if (PtInRect (&rcTest, *lpPt)) {
if (HEADER_IsItemFixed(infoPtr, HEADER_PrevItem(infoPtr, iCount)))
{
*pFlags |= HHT_ONHEADER;
*pItem = iCount;
TRACE("ON HEADER %d\n", *pItem);
return;
}
if (bNoWidth) {
*pFlags |= HHT_ONDIVOPEN;
*pItem = HEADER_PrevItem(infoPtr, iCount);
TRACE("ON DIVOPEN %d\n", *pItem);
return;
}
else {
*pFlags |= HHT_ONDIVIDER;
*pItem = HEADER_PrevItem(infoPtr, iCount);
TRACE("ON DIVIDER %d\n", *pItem);
return;
}
}
}
rcTest = rect;
rcTest.left = rcTest.right - DIVIDER_WIDTH;
if (!HEADER_IsItemFixed(infoPtr, iCount) && PtInRect (&rcTest, *lpPt))
{
*pFlags |= HHT_ONDIVIDER;
*pItem = iCount;
TRACE("ON DIVIDER %d\n", *pItem);
return;
}
*pFlags |= HHT_ONHEADER;
*pItem = iCount;
TRACE("ON HEADER %d\n", iCount);
return;
}
}
/* check for last divider part (on nowhere) */
if (!HEADER_IsItemFixed(infoPtr, infoPtr->uNumItem - 1))
{
rect = infoPtr->items[infoPtr->uNumItem-1].rect;
rect.left = rect.right;
rect.right += DIVIDER_WIDTH;
if (PtInRect (&rect, *lpPt)) {
if (bNoWidth) {
*pFlags |= HHT_ONDIVOPEN;
*pItem = infoPtr->uNumItem - 1;
TRACE("ON DIVOPEN %d\n", *pItem);
return;
}
else {
*pFlags |= HHT_ONDIVIDER;
*pItem = infoPtr->uNumItem - 1;
TRACE("ON DIVIDER %d\n", *pItem);
return;
}
}
}
*pFlags |= HHT_NOWHERE;
*pItem = 1;
TRACE("NOWHERE\n");
return;
}
}
else {
if (lpPt->x < rect.left) {
TRACE("TO LEFT\n");
*pFlags |= HHT_TOLEFT;
}
else if (lpPt->x > rect.right) {
TRACE("TO RIGHT\n");
*pFlags |= HHT_TORIGHT;
}
if (lpPt->y < rect.top) {
TRACE("ABOVE\n");
*pFlags |= HHT_ABOVE;
}
else if (lpPt->y > rect.bottom) {
TRACE("BELOW\n");
*pFlags |= HHT_BELOW;
}
}
*pItem = 1;
TRACE("flags=0x%X\n", *pFlags);
return;
}
static void
HEADER_DrawTrackLine (const HEADER_INFO *infoPtr, HDC hdc, INT x)
{
RECT rect;
GetClientRect (infoPtr->hwndSelf, &rect);
PatBlt( hdc, x, rect.top, 1, rect.bottom - rect.top, DSTINVERT );
}
/***
* DESCRIPTION:
* Convert a HDITEM into the correct format (ANSI/Unicode) to send it in a notify
*
* PARAMETER(S):
* [I] infoPtr : the header that wants to send the notify
* [O] dest : The buffer to store the HDITEM for notify. It may be set to a HDITEMA of HDITEMW
* [I] src : The source HDITEM. It may be a HDITEMA or HDITEMW
* [I] fSourceUnicode : is src a HDITEMW or HDITEMA
* [O] ppvScratch : a pointer to a scratch buffer that needs to be freed after
* the HDITEM is no longer in use or NULL if none was needed
*
* NOTE: We depend on HDITEMA and HDITEMW having the same structure
*/
static void HEADER_CopyHDItemForNotify(const HEADER_INFO *infoPtr, HDITEMW *dest,
const HDITEMW *src, BOOL fSourceUnicode, LPVOID *ppvScratch)
{
*ppvScratch = NULL;
*dest = *src;
if (src->mask & HDI_TEXT && src->pszText != LPSTR_TEXTCALLBACKW) /* covers TEXTCALLBACKA as well */
{
if (fSourceUnicode && infoPtr->nNotifyFormat != NFR_UNICODE)
{
dest->pszText = NULL;
Str_SetPtrWtoA((LPSTR *)&dest->pszText, src->pszText);
*ppvScratch = dest->pszText;
}
if (!fSourceUnicode && infoPtr->nNotifyFormat == NFR_UNICODE)
{
dest->pszText = NULL;
Str_SetPtrAtoW(&dest->pszText, (LPSTR)src->pszText);
*ppvScratch = dest->pszText;
}
}
}
static UINT HEADER_NotifyCodeWtoA(UINT code)
{
/* we use the fact that all the unicode messages are in HDN_FIRST_UNICODE..HDN_LAST*/
if (code >= HDN_LAST && code <= HDN_FIRST_UNICODE)
return code + HDN_UNICODE_OFFSET;
else
return code;
}
static LRESULT
HEADER_SendNotify(const HEADER_INFO *infoPtr, UINT code, NMHDR *nmhdr)
{
nmhdr->hwndFrom = infoPtr->hwndSelf;
nmhdr->idFrom = GetWindowLongPtrW (infoPtr->hwndSelf, GWLP_ID);
nmhdr->code = code;
return SendMessageW(infoPtr->hwndNotify, WM_NOTIFY,
nmhdr->idFrom, (LPARAM)nmhdr);
}
static BOOL
HEADER_SendSimpleNotify (const HEADER_INFO *infoPtr, UINT code)
{
NMHDR nmhdr;
return (BOOL)HEADER_SendNotify(infoPtr, code, &nmhdr);
}
static LRESULT
HEADER_SendCtrlCustomDraw(const HEADER_INFO *infoPtr, DWORD dwDrawStage, HDC hdc, const RECT *rect)
{
NMCUSTOMDRAW nm;
nm.dwDrawStage = dwDrawStage;
nm.hdc = hdc;
nm.rc = *rect;
nm.dwItemSpec = 0;
nm.uItemState = 0;
nm.lItemlParam = 0;
return HEADER_SendNotify(infoPtr, NM_CUSTOMDRAW, (NMHDR *)&nm);
}
static BOOL
HEADER_SendNotifyWithHDItemT(const HEADER_INFO *infoPtr, UINT code, INT iItem, HDITEMW *lpItem)
{
NMHEADERW nmhdr;
if (infoPtr->nNotifyFormat != NFR_UNICODE)
code = HEADER_NotifyCodeWtoA(code);
nmhdr.iItem = iItem;
nmhdr.iButton = 0;
nmhdr.pitem = lpItem;
return (BOOL)HEADER_SendNotify(infoPtr, code, (NMHDR *)&nmhdr);
}
static BOOL
HEADER_SendNotifyWithIntFieldT(const HEADER_INFO *infoPtr, UINT code, INT iItem, INT mask, INT iValue)
{
HDITEMW nmitem;
/* copying only the iValue should be ok but to make the code more robust we copy everything */
nmitem.cxy = infoPtr->items[iItem].cxy;
nmitem.hbm = infoPtr->items[iItem].hbm;
nmitem.pszText = NULL;
nmitem.cchTextMax = 0;
nmitem.fmt = infoPtr->items[iItem].fmt;
nmitem.lParam = infoPtr->items[iItem].lParam;
nmitem.iOrder = infoPtr->items[iItem].iOrder;
nmitem.iImage = infoPtr->items[iItem].iImage;
nmitem.mask = mask;
switch (mask)
{
case HDI_WIDTH:
nmitem.cxy = iValue;
break;
case HDI_ORDER:
nmitem.iOrder = iValue;
break;
default:
ERR("invalid mask value 0x%x\n", iValue);
}
return HEADER_SendNotifyWithHDItemT(infoPtr, code, iItem, &nmitem);
}
/**
* Prepare callback items
* depends on NMHDDISPINFOW having same structure as NMHDDISPINFOA
* (so we handle the two cases only doing a specific cast for pszText).
* Checks if any of the required fields is a callback. If this is the case sends a
* NMHDISPINFO notify to retrieve these items. The items are stored in the
* HEADER_ITEM pszText and iImage fields. They should be freed with
* HEADER_FreeCallbackItems.
*
* @param hwnd : hwnd header container handler
* @param iItem : the header item id
* @param reqMask : required fields. If any of them is callback this function will fetch it
*
* @return TRUE on success, else FALSE
*/
static BOOL
HEADER_PrepareCallbackItems(const HEADER_INFO *infoPtr, INT iItem, INT reqMask)
{
HEADER_ITEM *lpItem = &infoPtr->items[iItem];
DWORD mask = reqMask & lpItem->callbackMask;
NMHDDISPINFOW dispInfo;
void *pvBuffer = NULL;
if (mask == 0)
return TRUE;
if (mask&HDI_TEXT && lpItem->pszText != NULL)
{
ERR("(): function called without a call to FreeCallbackItems\n");
heap_free(lpItem->pszText);
lpItem->pszText = NULL;
}
memset(&dispInfo, 0, sizeof(NMHDDISPINFOW));
dispInfo.hdr.hwndFrom = infoPtr->hwndSelf;
dispInfo.hdr.idFrom = GetWindowLongPtrW (infoPtr->hwndSelf, GWLP_ID);
if (infoPtr->nNotifyFormat == NFR_UNICODE)
{
dispInfo.hdr.code = HDN_GETDISPINFOW;
if (mask & HDI_TEXT)
pvBuffer = heap_alloc_zero(MAX_HEADER_TEXT_LEN * sizeof(WCHAR));
}
else
{
dispInfo.hdr.code = HDN_GETDISPINFOA;
if (mask & HDI_TEXT)
pvBuffer = heap_alloc_zero(MAX_HEADER_TEXT_LEN * sizeof(CHAR));
}
dispInfo.pszText = pvBuffer;
dispInfo.cchTextMax = (pvBuffer!=NULL?MAX_HEADER_TEXT_LEN:0);
dispInfo.iItem = iItem;
dispInfo.mask = mask;
dispInfo.lParam = lpItem->lParam;
TRACE("Sending HDN_GETDISPINFO%c\n", infoPtr->nNotifyFormat == NFR_UNICODE?'W':'A');
SendMessageW(infoPtr->hwndNotify, WM_NOTIFY, dispInfo.hdr.idFrom, (LPARAM)&dispInfo);
TRACE("SendMessage returns(mask:0x%x,str:%s,lParam:%p)\n",
dispInfo.mask,
(infoPtr->nNotifyFormat == NFR_UNICODE ? debugstr_w(dispInfo.pszText) : (LPSTR) dispInfo.pszText),
(void*) dispInfo.lParam);
if (mask & HDI_IMAGE)
lpItem->iImage = dispInfo.iImage;
if (mask & HDI_TEXT)
{
if (infoPtr->nNotifyFormat == NFR_UNICODE)
{
lpItem->pszText = pvBuffer;
/* the user might have used his own buffer */
if (dispInfo.pszText != lpItem->pszText)
Str_GetPtrW(dispInfo.pszText, lpItem->pszText, MAX_HEADER_TEXT_LEN);
}
else
{
Str_SetPtrAtoW(&lpItem->pszText, (LPSTR)dispInfo.pszText);
heap_free(pvBuffer);
}
}
if (dispInfo.mask & HDI_DI_SETITEM)
{
/* make the items permanent */
lpItem->callbackMask &= ~dispInfo.mask;
}
return TRUE;
}
/***
* DESCRIPTION:
* Free the items that might be allocated with HEADER_PrepareCallbackItems
*
* PARAMETER(S):
* [I] lpItem : the item to free the data
*
*/
static void
HEADER_FreeCallbackItems(HEADER_ITEM *lpItem)
{
if (lpItem->callbackMask&HDI_TEXT)
{
heap_free(lpItem->pszText);
lpItem->pszText = NULL;
}
if (lpItem->callbackMask&HDI_IMAGE)
lpItem->iImage = I_IMAGECALLBACK;
}
static HIMAGELIST
HEADER_CreateDragImage (HEADER_INFO *infoPtr, INT iItem)
{
HEADER_ITEM *lpItem;
HIMAGELIST himl;
HBITMAP hMemory, hOldBitmap;
LRESULT lCDFlags;
RECT rc;
HDC hMemoryDC;
HDC hDeviceDC;
int height, width;
HFONT hFont;
if (iItem >= infoPtr->uNumItem)
return NULL;
if (!infoPtr->bRectsValid)
HEADER_SetItemBounds(infoPtr);
lpItem = &infoPtr->items[iItem];
width = lpItem->rect.right - lpItem->rect.left;
height = lpItem->rect.bottom - lpItem->rect.top;
hDeviceDC = GetDC(NULL);
hMemoryDC = CreateCompatibleDC(hDeviceDC);
hMemory = CreateCompatibleBitmap(hDeviceDC, width, height);
ReleaseDC(NULL, hDeviceDC);
hOldBitmap = SelectObject(hMemoryDC, hMemory);
SetViewportOrgEx(hMemoryDC, -lpItem->rect.left, -lpItem->rect.top, NULL);
hFont = infoPtr->hFont ? infoPtr->hFont : GetStockObject(SYSTEM_FONT);
SelectObject(hMemoryDC, hFont);
GetClientRect(infoPtr->hwndSelf, &rc);
lCDFlags = HEADER_SendCtrlCustomDraw(infoPtr, CDDS_PREPAINT, hMemoryDC, &rc);
HEADER_DrawItem(infoPtr, hMemoryDC, iItem, FALSE, lCDFlags);
if (lCDFlags & CDRF_NOTIFYPOSTPAINT)
HEADER_SendCtrlCustomDraw(infoPtr, CDDS_POSTPAINT, hMemoryDC, &rc);
hMemory = SelectObject(hMemoryDC, hOldBitmap);
DeleteDC(hMemoryDC);
if (hMemory == NULL) /* if anything failed */
return NULL;
himl = ImageList_Create(width, height, ILC_COLORDDB, 1, 1);
ImageList_Add(himl, hMemory, NULL);
DeleteObject(hMemory);
return himl;
}
static LRESULT
HEADER_SetHotDivider(HEADER_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
{
INT iDivider;
RECT r;
if (wParam)
{
POINT pt;
UINT flags;
pt.x = (INT)(SHORT)LOWORD(lParam);
pt.y = 0;
HEADER_InternalHitTest (infoPtr, &pt, &flags, &iDivider);
if (flags & HHT_TOLEFT)
iDivider = 0;
else if (flags & HHT_NOWHERE || flags & HHT_TORIGHT)
iDivider = infoPtr->uNumItem;
else
{
HEADER_ITEM *lpItem = &infoPtr->items[iDivider];
if (pt.x > (lpItem->rect.left+lpItem->rect.right)/2)
iDivider = HEADER_NextItem(infoPtr, iDivider);
}
}
else
iDivider = (INT)lParam;
/* Note; wParam==FALSE, lParam==-1 is valid and is used to clear the hot divider */
if (iDivider<-1 || iDivider>(int)infoPtr->uNumItem)
return iDivider;
if (iDivider != infoPtr->iHotDivider)
{
if (infoPtr->iHotDivider != -1)
{
HEADER_GetHotDividerRect(infoPtr, &r);
InvalidateRect(infoPtr->hwndSelf, &r, FALSE);
}
infoPtr->iHotDivider = iDivider;
if (iDivider != -1)
{
HEADER_GetHotDividerRect(infoPtr, &r);
InvalidateRect(infoPtr->hwndSelf, &r, FALSE);
}
}
return iDivider;
}
static LRESULT
HEADER_DeleteItem (HEADER_INFO *infoPtr, INT iItem)
{
INT iOrder;
UINT i;
TRACE("[iItem=%d]\n", iItem);
if ((iItem < 0) || (iItem >= (INT)infoPtr->uNumItem))
return FALSE;
for (i = 0; i < infoPtr->uNumItem; i++)
TRACE("%d: order=%d, iOrder=%d, ->iOrder=%d\n", i, infoPtr->order[i], infoPtr->items[i].iOrder, infoPtr->items[infoPtr->order[i]].iOrder);
iOrder = infoPtr->items[iItem].iOrder;
heap_free(infoPtr->items[iItem].pszText);
infoPtr->uNumItem--;
memmove(&infoPtr->items[iItem], &infoPtr->items[iItem + 1],
(infoPtr->uNumItem - iItem) * sizeof(HEADER_ITEM));
memmove(&infoPtr->order[iOrder], &infoPtr->order[iOrder + 1],
(infoPtr->uNumItem - iOrder) * sizeof(INT));
infoPtr->items = heap_realloc(infoPtr->items, sizeof(HEADER_ITEM) * infoPtr->uNumItem);
infoPtr->order = heap_realloc(infoPtr->order, sizeof(INT) * infoPtr->uNumItem);
/* Correct the orders */
for (i = 0; i < infoPtr->uNumItem; i++)
{
if (infoPtr->order[i] > iItem)
infoPtr->order[i]--;
if (i >= iOrder)
infoPtr->items[infoPtr->order[i]].iOrder = i;
}
for (i = 0; i < infoPtr->uNumItem; i++)
TRACE("%d: order=%d, iOrder=%d, ->iOrder=%d\n", i, infoPtr->order[i], infoPtr->items[i].iOrder, infoPtr->items[infoPtr->order[i]].iOrder);
HEADER_SetItemBounds (infoPtr);
InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
return TRUE;
}
static LRESULT
HEADER_GetImageList (const HEADER_INFO *infoPtr)
{
return (LRESULT)infoPtr->himl;
}
static LRESULT
HEADER_GetItemT (const HEADER_INFO *infoPtr, INT nItem, LPHDITEMW phdi, BOOL bUnicode)
{
HEADER_ITEM *lpItem;
UINT mask;
if (!phdi)
return FALSE;
TRACE("[nItem=%d]\n", nItem);
mask = phdi->mask;
if (mask == 0)
return TRUE;
if ((nItem < 0) || (nItem >= (INT)infoPtr->uNumItem))
return FALSE;
if (mask & HDI_UNKNOWN_FIELDS)
{
TRACE("mask %x contains unknown fields. Using only comctl32 4.0 fields\n", mask);
mask &= HDI_COMCTL32_4_0_FIELDS;
}
lpItem = &infoPtr->items[nItem];
HEADER_PrepareCallbackItems(infoPtr, nItem, mask);
if (mask & HDI_BITMAP)
phdi->hbm = lpItem->hbm;
if (mask & HDI_FORMAT)
phdi->fmt = lpItem->fmt;
if (mask & HDI_WIDTH)
phdi->cxy = lpItem->cxy;
if (mask & HDI_LPARAM)
phdi->lParam = lpItem->lParam;
if (mask & HDI_IMAGE)
phdi->iImage = lpItem->iImage;
if (mask & HDI_ORDER)
phdi->iOrder = lpItem->iOrder;
if (mask & HDI_TEXT)
{
if (bUnicode)
Str_GetPtrW (lpItem->pszText, phdi->pszText, phdi->cchTextMax);
else
Str_GetPtrWtoA (lpItem->pszText, (LPSTR)phdi->pszText, phdi->cchTextMax);
}
HEADER_FreeCallbackItems(lpItem);
return TRUE;
}
static inline LRESULT
HEADER_GetItemCount (const HEADER_INFO *infoPtr)
{
return infoPtr->uNumItem;
}
static LRESULT
HEADER_GetItemRect (const HEADER_INFO *infoPtr, INT iItem, LPRECT lpRect)
{
if ((iItem < 0) || (iItem >= (INT)infoPtr->uNumItem))
return FALSE;
lpRect->left = infoPtr->items[iItem].rect.left;
lpRect->right = infoPtr->items[iItem].rect.right;
lpRect->top = infoPtr->items[iItem].rect.top;
lpRect->bottom = infoPtr->items[iItem].rect.bottom;
return TRUE;
}
static LRESULT
HEADER_GetOrderArray(const HEADER_INFO *infoPtr, INT size, LPINT order)
{
if ((UINT)size <infoPtr->uNumItem)
return FALSE;
memcpy(order, infoPtr->order, infoPtr->uNumItem * sizeof(INT));
return TRUE;
}
/* Returns index of first duplicate 'value' from [0,to) range,
or -1 if there isn't any */
static INT has_duplicate(const INT *array, INT to, INT value)
{
INT i;
for(i = 0; i < to; i++)
if (array[i] == value) return i;
return -1;
}
/* returns next available value from [0,max] not to duplicate in [0,to) */
static INT get_nextvalue(const INT *array, INT to, INT max)
{
INT i;
for(i = 0; i < max; i++)
if (has_duplicate(array, to, i) == -1) return i;
return 0;
}
static LRESULT
HEADER_SetOrderArray(HEADER_INFO *infoPtr, INT size, const INT *order)
{
HEADER_ITEM *lpItem;
INT i;
if ((UINT)size != infoPtr->uNumItem)
return FALSE;
if (TRACE_ON(header))
{
TRACE("count=%d, order array={", size);
for (i = 0; i < size; i++)
TRACE("%d%c", order[i], i != size-1 ? ',' : '}');
TRACE("\n");
}
for (i=0; i<size; i++)
{
if (order[i] >= size || order[i] < 0)
/* on invalid index get next available */
/* FIXME: if i==0 array item is out of range behaviour is
different, see tests */
infoPtr->order[i] = get_nextvalue(infoPtr->order, i, size);
else
{
INT j, dup;
infoPtr->order[i] = order[i];
j = i;
/* remove duplicates */
while ((dup = has_duplicate(infoPtr->order, j, order[j])) != -1)
{
INT next;
next = get_nextvalue(infoPtr->order, j, size);
infoPtr->order[dup] = next;
j--;
}
}
}
/* sync with item data */
for (i=0; i<size; i++)
{
lpItem = &infoPtr->items[infoPtr->order[i]];
lpItem->iOrder = i;
}
HEADER_SetItemBounds(infoPtr);
InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
return TRUE;
}
static inline LRESULT
HEADER_GetUnicodeFormat (const HEADER_INFO *infoPtr)
{
return (infoPtr->nNotifyFormat == NFR_UNICODE);
}
static LRESULT
HEADER_HitTest (const HEADER_INFO *infoPtr, LPHDHITTESTINFO phti)
{
UINT outside = HHT_NOWHERE | HHT_ABOVE | HHT_BELOW | HHT_TOLEFT | HHT_TORIGHT;
HEADER_InternalHitTest (infoPtr, &phti->pt, &phti->flags, &phti->iItem);
if (phti->flags & outside)
return phti->iItem = -1;
else
return phti->iItem;
}
static LRESULT
HEADER_InsertItemT (HEADER_INFO *infoPtr, INT nItem, const HDITEMW *phdi, BOOL bUnicode)
{
HEADER_ITEM *lpItem;
INT iOrder;
UINT i;
UINT copyMask;
if ((phdi == NULL) || (nItem < 0) || (phdi->mask == 0))
return -1;
if (nItem > infoPtr->uNumItem)
nItem = infoPtr->uNumItem;
iOrder = (phdi->mask & HDI_ORDER) ? phdi->iOrder : nItem;
if (iOrder < 0)
iOrder = 0;
else if (infoPtr->uNumItem < iOrder)
iOrder = infoPtr->uNumItem;
infoPtr->uNumItem++;
infoPtr->items = heap_realloc(infoPtr->items, sizeof(HEADER_ITEM) * infoPtr->uNumItem);
infoPtr->order = heap_realloc(infoPtr->order, sizeof(INT) * infoPtr->uNumItem);
/* make space for the new item */
memmove(&infoPtr->items[nItem + 1], &infoPtr->items[nItem],
(infoPtr->uNumItem - nItem - 1) * sizeof(HEADER_ITEM));
memmove(&infoPtr->order[iOrder + 1], &infoPtr->order[iOrder],
(infoPtr->uNumItem - iOrder - 1) * sizeof(INT));
/* update the order array */
infoPtr->order[iOrder] = nItem;
for (i = 0; i < infoPtr->uNumItem; i++)
{
if (i != iOrder && infoPtr->order[i] >= nItem)
infoPtr->order[i]++;
infoPtr->items[infoPtr->order[i]].iOrder = i;
}
lpItem = &infoPtr->items[nItem];
ZeroMemory(lpItem, sizeof(HEADER_ITEM));
/* cxy, fmt and lParam are copied even if not in the HDITEM mask */
copyMask = phdi->mask | HDI_WIDTH | HDI_FORMAT | HDI_LPARAM;
HEADER_StoreHDItemInHeader(lpItem, copyMask, phdi, bUnicode);
lpItem->iOrder = iOrder;
/* set automatically some format bits */
if (phdi->mask & HDI_TEXT)
lpItem->fmt |= HDF_STRING;
else
lpItem->fmt &= ~HDF_STRING;
if (lpItem->hbm != NULL)
lpItem->fmt |= HDF_BITMAP;
else
lpItem->fmt &= ~HDF_BITMAP;
if (phdi->mask & HDI_IMAGE)
lpItem->fmt |= HDF_IMAGE;
HEADER_SetItemBounds (infoPtr);
InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
return nItem;
}
static LRESULT
HEADER_Layout (HEADER_INFO *infoPtr, LPHDLAYOUT lpLayout)
{
lpLayout->pwpos->hwnd = infoPtr->hwndSelf;
lpLayout->pwpos->hwndInsertAfter = 0;
lpLayout->pwpos->x = lpLayout->prc->left;
lpLayout->pwpos->y = lpLayout->prc->top;
lpLayout->pwpos->cx = lpLayout->prc->right - lpLayout->prc->left;
if (infoPtr->dwStyle & HDS_HIDDEN)
lpLayout->pwpos->cy = 0;
else {
lpLayout->pwpos->cy = infoPtr->nHeight;
lpLayout->prc->top += infoPtr->nHeight;
}
lpLayout->pwpos->flags = SWP_NOZORDER;
TRACE("Layout x=%d y=%d cx=%d cy=%d\n",
lpLayout->pwpos->x, lpLayout->pwpos->y,
lpLayout->pwpos->cx, lpLayout->pwpos->cy);
infoPtr->bRectsValid = FALSE;
return TRUE;
}
static LRESULT
HEADER_SetImageList (HEADER_INFO *infoPtr, HIMAGELIST himl)
{
HIMAGELIST himlOld;
TRACE("(himl %p)\n", himl);
himlOld = infoPtr->himl;
infoPtr->himl = himl;
/* FIXME: Refresh needed??? */
return (LRESULT)himlOld;
}
static LRESULT
HEADER_GetBitmapMargin(const HEADER_INFO *infoPtr)
{
return infoPtr->iMargin;
}
static LRESULT
HEADER_SetBitmapMargin(HEADER_INFO *infoPtr, INT iMargin)
{
INT oldMargin = infoPtr->iMargin;
infoPtr->iMargin = iMargin;
return oldMargin;
}
static LRESULT
HEADER_SetItemT (HEADER_INFO *infoPtr, INT nItem, const HDITEMW *phdi, BOOL bUnicode)
{
HEADER_ITEM *lpItem;
HDITEMW hdNotify;
void *pvScratch;
if (phdi == NULL)
return FALSE;
if ((nItem < 0) || (nItem >= (INT)infoPtr->uNumItem))
return FALSE;
TRACE("[nItem=%d]\n", nItem);
HEADER_CopyHDItemForNotify(infoPtr, &hdNotify, phdi, bUnicode, &pvScratch);
if (HEADER_SendNotifyWithHDItemT(infoPtr, HDN_ITEMCHANGINGW, nItem, &hdNotify))
{
heap_free(pvScratch);
return FALSE;
}
lpItem = &infoPtr->items[nItem];
HEADER_StoreHDItemInHeader(lpItem, phdi->mask, phdi, bUnicode);
if (phdi->mask & HDI_ORDER)
if (phdi->iOrder >= 0 && phdi->iOrder < infoPtr->uNumItem)
HEADER_ChangeItemOrder(infoPtr, nItem, phdi->iOrder);
HEADER_SendNotifyWithHDItemT(infoPtr, HDN_ITEMCHANGEDW, nItem, &hdNotify);
HEADER_SetItemBounds (infoPtr);
InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
heap_free(pvScratch);
return TRUE;
}
static inline LRESULT
HEADER_SetUnicodeFormat (HEADER_INFO *infoPtr, WPARAM wParam)
{
BOOL bTemp = (infoPtr->nNotifyFormat == NFR_UNICODE);
infoPtr->nNotifyFormat = ((BOOL)wParam ? NFR_UNICODE : NFR_ANSI);
return bTemp;
}
static LRESULT
HEADER_Create (HWND hwnd, const CREATESTRUCTW *lpcs)
{
HEADER_INFO *infoPtr;
TEXTMETRICW tm;
HFONT hOldFont;
HDC hdc;
infoPtr = heap_alloc_zero (sizeof(*infoPtr));
SetWindowLongPtrW (hwnd, 0, (DWORD_PTR)infoPtr);
infoPtr->hwndSelf = hwnd;
infoPtr->hwndNotify = lpcs->hwndParent;
infoPtr->uNumItem = 0;
infoPtr->hFont = 0;
infoPtr->items = 0;
infoPtr->order = 0;
infoPtr->bRectsValid = FALSE;
infoPtr->hcurArrow = LoadCursorW (0, (LPWSTR)IDC_ARROW);
infoPtr->hcurDivider = LoadCursorW (COMCTL32_hModule, MAKEINTRESOURCEW(IDC_DIVIDER));
infoPtr->hcurDivopen = LoadCursorW (COMCTL32_hModule, MAKEINTRESOURCEW(IDC_DIVIDEROPEN));
infoPtr->bPressed = FALSE;
infoPtr->bTracking = FALSE;
infoPtr->dwStyle = lpcs->style;
infoPtr->iMoveItem = 0;
infoPtr->himl = 0;
infoPtr->iHotItem = -1;
infoPtr->iHotDivider = -1;
infoPtr->iMargin = 3*GetSystemMetrics(SM_CXEDGE);
infoPtr->nNotifyFormat =
SendMessageW (infoPtr->hwndNotify, WM_NOTIFYFORMAT, (WPARAM)hwnd, NF_QUERY);
infoPtr->filter_change_timeout = 1000;
hdc = GetDC (0);
hOldFont = SelectObject (hdc, GetStockObject (SYSTEM_FONT));
GetTextMetricsW (hdc, &tm);
infoPtr->nHeight = tm.tmHeight + VERT_BORDER;
SelectObject (hdc, hOldFont);
ReleaseDC (0, hdc);
OpenThemeData(hwnd, themeClass);
return 0;
}
static LRESULT
HEADER_Destroy (HEADER_INFO *infoPtr)
{
HTHEME theme = GetWindowTheme(infoPtr->hwndSelf);
CloseThemeData(theme);
return 0;
}
static LRESULT
HEADER_NCDestroy (HEADER_INFO *infoPtr)
{
HEADER_ITEM *lpItem;
INT nItem;
if (infoPtr->items) {
lpItem = infoPtr->items;
for (nItem = 0; nItem < infoPtr->uNumItem; nItem++, lpItem++)
heap_free(lpItem->pszText);
heap_free(infoPtr->items);
}
heap_free(infoPtr->order);
SetWindowLongPtrW (infoPtr->hwndSelf, 0, 0);
heap_free(infoPtr);
return 0;
}
static inline LRESULT
HEADER_GetFont (const HEADER_INFO *infoPtr)
{
return (LRESULT)infoPtr->hFont;
}
static BOOL
HEADER_IsDragDistance(const HEADER_INFO *infoPtr, const POINT *pt)
{
/* Windows allows for a mouse movement before starting the drag. We use the
* SM_CXDOUBLECLICK/SM_CYDOUBLECLICK as that distance.
*/
return (abs(infoPtr->ptLButtonDown.x - pt->x)>GetSystemMetrics(SM_CXDOUBLECLK) ||
abs(infoPtr->ptLButtonDown.y - pt->y)>GetSystemMetrics(SM_CYDOUBLECLK));
}
static LRESULT
HEADER_LButtonDblClk (const HEADER_INFO *infoPtr, INT x, INT y)
{
POINT pt;
UINT flags;
INT nItem;
pt.x = x;
pt.y = y;
HEADER_InternalHitTest (infoPtr, &pt, &flags, &nItem);
if ((infoPtr->dwStyle & HDS_BUTTONS) && (flags == HHT_ONHEADER))
HEADER_SendNotifyWithHDItemT(infoPtr, HDN_ITEMDBLCLICKW, nItem, NULL);
else if ((flags == HHT_ONDIVIDER) || (flags == HHT_ONDIVOPEN))
HEADER_SendNotifyWithHDItemT(infoPtr, HDN_DIVIDERDBLCLICKW, nItem, NULL);
return 0;
}
static LRESULT
HEADER_LButtonDown (HEADER_INFO *infoPtr, INT x, INT y)
{
POINT pt;
UINT flags;
INT nItem;
HDC hdc;
pt.x = x;
pt.y = y;
HEADER_InternalHitTest (infoPtr, &pt, &flags, &nItem);
if ((infoPtr->dwStyle & HDS_BUTTONS) && (flags == HHT_ONHEADER)) {
SetCapture (infoPtr->hwndSelf);
infoPtr->bCaptured = TRUE;
infoPtr->bPressed = TRUE;
infoPtr->bDragging = FALSE;
infoPtr->iMoveItem = nItem;
infoPtr->ptLButtonDown = pt;
infoPtr->items[nItem].bDown = TRUE;
/* Send WM_CUSTOMDRAW */
hdc = GetDC (infoPtr->hwndSelf);
HEADER_RefreshItem (infoPtr, nItem);
ReleaseDC (infoPtr->hwndSelf, hdc);
TRACE("Pressed item %d.\n", nItem);
}
else if ((flags == HHT_ONDIVIDER) || (flags == HHT_ONDIVOPEN)) {
INT iCurrWidth = infoPtr->items[nItem].cxy;
if (!HEADER_SendNotifyWithIntFieldT(infoPtr, HDN_BEGINTRACKW, nItem, HDI_WIDTH, iCurrWidth))
{
SetCapture (infoPtr->hwndSelf);
infoPtr->bCaptured = TRUE;
infoPtr->bTracking = TRUE;
infoPtr->iMoveItem = nItem;
infoPtr->xTrackOffset = infoPtr->items[nItem].rect.right - pt.x;
if (!(infoPtr->dwStyle & HDS_FULLDRAG)) {
infoPtr->xOldTrack = infoPtr->items[nItem].rect.right;
hdc = GetDC (infoPtr->hwndSelf);
HEADER_DrawTrackLine (infoPtr, hdc, infoPtr->xOldTrack);
ReleaseDC (infoPtr->hwndSelf, hdc);
}
TRACE("Begin tracking item %d.\n", nItem);
}
}
return 0;
}
static LRESULT
HEADER_LButtonUp (HEADER_INFO *infoPtr, INT x, INT y)
{
POINT pt;
UINT flags;
INT nItem;
HDC hdc;
pt.x = x;
pt.y = y;
HEADER_InternalHitTest (infoPtr, &pt, &flags, &nItem);
if (infoPtr->bPressed) {
infoPtr->items[infoPtr->iMoveItem].bDown = FALSE;
if (infoPtr->bDragging)
{
HEADER_ITEM *lpItem = &infoPtr->items[infoPtr->iMoveItem];
INT iNewOrder;
ImageList_DragShowNolock(FALSE);
ImageList_EndDrag();
if (infoPtr->iHotDivider == -1)
iNewOrder = -1;
else if (infoPtr->iHotDivider == infoPtr->uNumItem)
iNewOrder = infoPtr->uNumItem-1;
else
{
iNewOrder = HEADER_IndexToOrder(infoPtr, infoPtr->iHotDivider);
if (iNewOrder > lpItem->iOrder)
iNewOrder--;
}
if (iNewOrder != -1 &&
!HEADER_SendNotifyWithIntFieldT(infoPtr, HDN_ENDDRAG, infoPtr->iMoveItem, HDI_ORDER, iNewOrder))
{
HEADER_ChangeItemOrder(infoPtr, infoPtr->iMoveItem, iNewOrder);
infoPtr->bRectsValid = FALSE;
InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
}
else
InvalidateRect(infoPtr->hwndSelf, &infoPtr->items[infoPtr->iMoveItem].rect, FALSE);
infoPtr->bDragging = FALSE;
HEADER_SetHotDivider(infoPtr, FALSE, -1);
}
else
{
hdc = GetDC (infoPtr->hwndSelf);
HEADER_RefreshItem (infoPtr, infoPtr->iMoveItem);
ReleaseDC (infoPtr->hwndSelf, hdc);
if (!(infoPtr->dwStyle & HDS_DRAGDROP) || !HEADER_IsDragDistance(infoPtr, &pt))
HEADER_SendNotifyWithHDItemT(infoPtr, HDN_ITEMCLICKW, infoPtr->iMoveItem, NULL);
}
TRACE("Released item %d.\n", infoPtr->iMoveItem);
infoPtr->bPressed = FALSE;
}
else if (infoPtr->bTracking) {
INT iNewWidth = pt.x - infoPtr->items[infoPtr->iMoveItem].rect.left + infoPtr->xTrackOffset;
if (iNewWidth < 0)
iNewWidth = 0;
TRACE("End tracking item %d.\n", infoPtr->iMoveItem);
infoPtr->bTracking = FALSE;
HEADER_SendNotifyWithIntFieldT(infoPtr, HDN_ENDTRACKW, infoPtr->iMoveItem, HDI_WIDTH, iNewWidth);
if (!(infoPtr->dwStyle & HDS_FULLDRAG)) {
hdc = GetDC (infoPtr->hwndSelf);
HEADER_DrawTrackLine (infoPtr, hdc, infoPtr->xOldTrack);
ReleaseDC (infoPtr->hwndSelf, hdc);
}
if (!HEADER_SendNotifyWithIntFieldT(infoPtr, HDN_ITEMCHANGINGW, infoPtr->iMoveItem, HDI_WIDTH, iNewWidth))
{
infoPtr->items[infoPtr->iMoveItem].cxy = iNewWidth;
HEADER_SendNotifyWithIntFieldT(infoPtr, HDN_ITEMCHANGEDW, infoPtr->iMoveItem, HDI_WIDTH, iNewWidth);
}
HEADER_SetItemBounds (infoPtr);
InvalidateRect(infoPtr->hwndSelf, NULL, TRUE);
}
if (infoPtr->bCaptured) {
infoPtr->bCaptured = FALSE;
ReleaseCapture ();
HEADER_SendSimpleNotify (infoPtr, NM_RELEASEDCAPTURE);
}
return 0;
}
static LRESULT
HEADER_NotifyFormat (HEADER_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
{
switch (lParam)
{
case NF_QUERY:
return infoPtr->nNotifyFormat;
case NF_REQUERY:
infoPtr->nNotifyFormat =
SendMessageW ((HWND)wParam, WM_NOTIFYFORMAT,
(WPARAM)infoPtr->hwndSelf, NF_QUERY);
return infoPtr->nNotifyFormat;
}
return 0;
}
static LRESULT
HEADER_MouseLeave (HEADER_INFO *infoPtr)
{
/* Reset hot-tracked item when mouse leaves control. */
INT oldHotItem = infoPtr->iHotItem;
HDC hdc = GetDC (infoPtr->hwndSelf);
infoPtr->iHotItem = -1;
if (oldHotItem != -1) HEADER_RefreshItem (infoPtr, oldHotItem);
ReleaseDC (infoPtr->hwndSelf, hdc);
return 0;
}
static LRESULT
HEADER_MouseMove (HEADER_INFO *infoPtr, LPARAM lParam)
{
POINT pt;
UINT flags;
INT nItem, nWidth;
HDC hdc;
/* With theming, hottracking is always enabled */
BOOL hotTrackEnabled =
((infoPtr->dwStyle & HDS_BUTTONS) && (infoPtr->dwStyle & HDS_HOTTRACK))
|| (GetWindowTheme (infoPtr->hwndSelf) != NULL);
INT oldHotItem = infoPtr->iHotItem;
pt.x = (INT)(SHORT)LOWORD(lParam);
pt.y = (INT)(SHORT)HIWORD(lParam);
HEADER_InternalHitTest (infoPtr, &pt, &flags, &nItem);
if (hotTrackEnabled) {
if (flags & (HHT_ONHEADER | HHT_ONDIVIDER | HHT_ONDIVOPEN))
infoPtr->iHotItem = nItem;
else
infoPtr->iHotItem = -1;
}
if (infoPtr->bCaptured) {
/* check if we should drag the header */
if (infoPtr->bPressed && !infoPtr->bDragging && (infoPtr->dwStyle & HDS_DRAGDROP)
&& HEADER_IsDragDistance(infoPtr, &pt))
{
if (!HEADER_SendNotifyWithHDItemT(infoPtr, HDN_BEGINDRAG, infoPtr->iMoveItem, NULL))
{
HIMAGELIST hDragItem = HEADER_CreateDragImage(infoPtr, infoPtr->iMoveItem);
if (hDragItem != NULL)
{
HEADER_ITEM *lpItem = &infoPtr->items[infoPtr->iMoveItem];
TRACE("Starting item drag\n");
ImageList_BeginDrag(hDragItem, 0, pt.x - lpItem->rect.left, 0);
ImageList_DragShowNolock(TRUE);
ImageList_Destroy(hDragItem);
infoPtr->bDragging = TRUE;
}
}
}
if (infoPtr->bDragging)
{
POINT drag;
drag.x = pt.x;
drag.y = 0;
ClientToScreen(infoPtr->hwndSelf, &drag);
ImageList_DragMove(drag.x, drag.y);
HEADER_SetHotDivider(infoPtr, TRUE, lParam);
}
if (infoPtr->bPressed && !infoPtr->bDragging) {
BOOL oldState = infoPtr->items[infoPtr->iMoveItem].bDown;
if ((nItem == infoPtr->iMoveItem) && (flags == HHT_ONHEADER))
infoPtr->items[infoPtr->iMoveItem].bDown = TRUE;
else
infoPtr->items[infoPtr->iMoveItem].bDown = FALSE;
if (oldState != infoPtr->items[infoPtr->iMoveItem].bDown) {
hdc = GetDC (infoPtr->hwndSelf);
HEADER_RefreshItem (infoPtr, infoPtr->iMoveItem);
ReleaseDC (infoPtr->hwndSelf, hdc);
}
TRACE("Moving pressed item %d.\n", infoPtr->iMoveItem);
}
else if (infoPtr->bTracking) {
if (infoPtr->dwStyle & HDS_FULLDRAG) {
HEADER_ITEM *lpItem = &infoPtr->items[infoPtr->iMoveItem];
nWidth = pt.x - lpItem->rect.left + infoPtr->xTrackOffset;
if (!HEADER_SendNotifyWithIntFieldT(infoPtr, HDN_ITEMCHANGINGW, infoPtr->iMoveItem, HDI_WIDTH, nWidth))
{
INT nOldWidth = lpItem->rect.right - lpItem->rect.left;
RECT rcClient;
RECT rcScroll;
if (nWidth < 0) nWidth = 0;
infoPtr->items[infoPtr->iMoveItem].cxy = nWidth;
HEADER_SetItemBounds(infoPtr);
GetClientRect(infoPtr->hwndSelf, &rcClient);
rcScroll = rcClient;
rcScroll.left = lpItem->rect.left + nOldWidth;
ScrollWindowEx(infoPtr->hwndSelf, nWidth - nOldWidth, 0, &rcScroll, &rcClient, NULL, NULL, 0);
InvalidateRect(infoPtr->hwndSelf, &lpItem->rect, FALSE);
UpdateWindow(infoPtr->hwndSelf);
HEADER_SendNotifyWithIntFieldT(infoPtr, HDN_ITEMCHANGEDW, infoPtr->iMoveItem, HDI_WIDTH, nWidth);
}
}
else {
INT iTrackWidth;
hdc = GetDC (infoPtr->hwndSelf);
HEADER_DrawTrackLine (infoPtr, hdc, infoPtr->xOldTrack);
infoPtr->xOldTrack = pt.x + infoPtr->xTrackOffset;
if (infoPtr->xOldTrack < infoPtr->items[infoPtr->iMoveItem].rect.left)
infoPtr->xOldTrack = infoPtr->items[infoPtr->iMoveItem].rect.left;
HEADER_DrawTrackLine (infoPtr, hdc, infoPtr->xOldTrack);
ReleaseDC (infoPtr->hwndSelf, hdc);
iTrackWidth = infoPtr->xOldTrack - infoPtr->items[infoPtr->iMoveItem].rect.left;
/* FIXME: should stop tracking if HDN_TRACK returns TRUE */
HEADER_SendNotifyWithIntFieldT(infoPtr, HDN_TRACKW, infoPtr->iMoveItem, HDI_WIDTH, iTrackWidth);
}
TRACE("Tracking item %d.\n", infoPtr->iMoveItem);
}
}
if (hotTrackEnabled) {
TRACKMOUSEEVENT tme;
if (oldHotItem != infoPtr->iHotItem && !infoPtr->bDragging) {
hdc = GetDC (infoPtr->hwndSelf);
if (oldHotItem != -1) HEADER_RefreshItem (infoPtr, oldHotItem);
if (infoPtr->iHotItem != -1) HEADER_RefreshItem (infoPtr, infoPtr->iHotItem);
ReleaseDC (infoPtr->hwndSelf, hdc);
}
tme.cbSize = sizeof( tme );
tme.dwFlags = TME_LEAVE;
tme.hwndTrack = infoPtr->hwndSelf;
TrackMouseEvent( &tme );
}
return 0;
}
static LRESULT
HEADER_Paint (HEADER_INFO *infoPtr, HDC hdcParam)
{
HDC hdc;
PAINTSTRUCT ps;
hdc = hdcParam==0 ? BeginPaint (infoPtr->hwndSelf, &ps) : hdcParam;
HEADER_Refresh (infoPtr, hdc);
if(!hdcParam)
EndPaint (infoPtr->hwndSelf, &ps);
return 0;
}
static LRESULT
HEADER_RButtonUp (HEADER_INFO *infoPtr, INT x, INT y)
{
BOOL bRet;
POINT pt;
pt.x = x;
pt.y = y;
/* Send a Notify message */
bRet = HEADER_SendSimpleNotify (infoPtr, NM_RCLICK);
/* Change to screen coordinate for WM_CONTEXTMENU */
ClientToScreen(infoPtr->hwndSelf, &pt);
/* Send a WM_CONTEXTMENU message in response to the RBUTTONUP */
SendMessageW( infoPtr->hwndSelf, WM_CONTEXTMENU, (WPARAM) infoPtr->hwndSelf, MAKELPARAM(pt.x, pt.y));
return bRet;
}
static LRESULT
HEADER_SetCursor (HEADER_INFO *infoPtr, LPARAM lParam)
{
POINT pt;
UINT flags;
INT nItem;
TRACE("code=0x%X id=0x%X\n", LOWORD(lParam), HIWORD(lParam));
GetCursorPos (&pt);
ScreenToClient (infoPtr->hwndSelf, &pt);
HEADER_InternalHitTest (infoPtr, &pt, &flags, &nItem);
if (flags == HHT_ONDIVIDER)
SetCursor (infoPtr->hcurDivider);
else if (flags == HHT_ONDIVOPEN)
SetCursor (infoPtr->hcurDivopen);
else
SetCursor (infoPtr->hcurArrow);
return 0;
}
static LRESULT
HEADER_SetFont (HEADER_INFO *infoPtr, HFONT hFont, WORD Redraw)
{
TEXTMETRICW tm;
HFONT hOldFont;
HDC hdc;
infoPtr->hFont = hFont;
hdc = GetDC (0);
hOldFont = SelectObject (hdc, infoPtr->hFont ? infoPtr->hFont : GetStockObject (SYSTEM_FONT));
GetTextMetricsW (hdc, &tm);
infoPtr->nHeight = tm.tmHeight + VERT_BORDER;
SelectObject (hdc, hOldFont);
ReleaseDC (0, hdc);
infoPtr->bRectsValid = FALSE;
if (Redraw) {
InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
}
return 0;
}
static LRESULT HEADER_SetRedraw(HEADER_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
{
/* ignoring the InvalidateRect calls is handled by user32. But some apps expect
* that we invalidate the header and this has to be done manually */
LRESULT ret;
ret = DefWindowProcW(infoPtr->hwndSelf, WM_SETREDRAW, wParam, lParam);
if (wParam)
InvalidateRect(infoPtr->hwndSelf, NULL, TRUE);
return ret;
}
static INT HEADER_StyleChanged(HEADER_INFO *infoPtr, WPARAM wStyleType,
const STYLESTRUCT *lpss)
{
TRACE("(styletype=%lx, styleOld=0x%08x, styleNew=0x%08x)\n",
wStyleType, lpss->styleOld, lpss->styleNew);
if (wStyleType != GWL_STYLE) return 0;
infoPtr->dwStyle = lpss->styleNew;
return 0;
}
/* Update the theme handle after a theme change */
static LRESULT HEADER_ThemeChanged(const HEADER_INFO *infoPtr)
{
HTHEME theme = GetWindowTheme(infoPtr->hwndSelf);
CloseThemeData(theme);
OpenThemeData(infoPtr->hwndSelf, themeClass);
InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
return 0;
}
static INT HEADER_SetFilterChangeTimeout(HEADER_INFO *infoPtr, INT timeout)
{
INT old_timeout = infoPtr->filter_change_timeout;
if (timeout != 0)
infoPtr->filter_change_timeout = timeout;
return old_timeout;
}
static LRESULT WINAPI
HEADER_WindowProc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
HEADER_INFO *infoPtr = (HEADER_INFO *)GetWindowLongPtrW(hwnd, 0);
TRACE("hwnd=%p msg=%x wparam=%lx lParam=%lx\n", hwnd, msg, wParam, lParam);
if (!infoPtr && (msg != WM_CREATE))
return DefWindowProcW (hwnd, msg, wParam, lParam);
switch (msg) {
/* case HDM_CLEARFILTER: */
case HDM_CREATEDRAGIMAGE:
return (LRESULT)HEADER_CreateDragImage (infoPtr, (INT)wParam);
case HDM_DELETEITEM:
return HEADER_DeleteItem (infoPtr, (INT)wParam);
/* case HDM_EDITFILTER: */
case HDM_GETBITMAPMARGIN:
return HEADER_GetBitmapMargin(infoPtr);
case HDM_GETIMAGELIST:
return HEADER_GetImageList (infoPtr);
case HDM_GETITEMA:
case HDM_GETITEMW:
return HEADER_GetItemT (infoPtr, (INT)wParam, (LPHDITEMW)lParam, msg == HDM_GETITEMW);
case HDM_GETITEMCOUNT:
return HEADER_GetItemCount (infoPtr);
case HDM_GETITEMRECT:
return HEADER_GetItemRect (infoPtr, (INT)wParam, (LPRECT)lParam);
case HDM_GETORDERARRAY:
return HEADER_GetOrderArray(infoPtr, (INT)wParam, (LPINT)lParam);
case HDM_GETUNICODEFORMAT:
return HEADER_GetUnicodeFormat (infoPtr);
case HDM_HITTEST:
return HEADER_HitTest (infoPtr, (LPHDHITTESTINFO)lParam);
case HDM_INSERTITEMA:
case HDM_INSERTITEMW:
return HEADER_InsertItemT (infoPtr, (INT)wParam, (LPHDITEMW)lParam, msg == HDM_INSERTITEMW);
case HDM_LAYOUT:
return HEADER_Layout (infoPtr, (LPHDLAYOUT)lParam);
case HDM_ORDERTOINDEX:
return HEADER_OrderToIndex(infoPtr, (INT)wParam);
case HDM_SETBITMAPMARGIN:
return HEADER_SetBitmapMargin(infoPtr, (INT)wParam);
case HDM_SETFILTERCHANGETIMEOUT:
return HEADER_SetFilterChangeTimeout(infoPtr, (INT)lParam);
case HDM_SETHOTDIVIDER:
return HEADER_SetHotDivider(infoPtr, wParam, lParam);
case HDM_SETIMAGELIST:
return HEADER_SetImageList (infoPtr, (HIMAGELIST)lParam);
case HDM_SETITEMA:
case HDM_SETITEMW:
return HEADER_SetItemT (infoPtr, (INT)wParam, (LPHDITEMW)lParam, msg == HDM_SETITEMW);
case HDM_SETORDERARRAY:
return HEADER_SetOrderArray(infoPtr, (INT)wParam, (LPINT)lParam);
case HDM_SETUNICODEFORMAT:
return HEADER_SetUnicodeFormat (infoPtr, wParam);
case WM_CREATE:
return HEADER_Create (hwnd, (LPCREATESTRUCTW)lParam);
case WM_DESTROY:
return HEADER_Destroy (infoPtr);
case WM_NCDESTROY:
return HEADER_NCDestroy (infoPtr);
case WM_ERASEBKGND:
return 1;
case WM_GETDLGCODE:
return DLGC_WANTTAB | DLGC_WANTARROWS;
case WM_GETFONT:
return HEADER_GetFont (infoPtr);
case WM_LBUTTONDBLCLK:
return HEADER_LButtonDblClk (infoPtr, (SHORT)LOWORD(lParam), (SHORT)HIWORD(lParam));
case WM_LBUTTONDOWN:
return HEADER_LButtonDown (infoPtr, (SHORT)LOWORD(lParam), (SHORT)HIWORD(lParam));
case WM_LBUTTONUP:
return HEADER_LButtonUp (infoPtr, (SHORT)LOWORD(lParam), (SHORT)HIWORD(lParam));
case WM_MOUSELEAVE:
return HEADER_MouseLeave (infoPtr);
case WM_MOUSEMOVE:
return HEADER_MouseMove (infoPtr, lParam);
case WM_NOTIFYFORMAT:
return HEADER_NotifyFormat (infoPtr, wParam, lParam);
case WM_SIZE:
return HEADER_Size (infoPtr);
case WM_THEMECHANGED:
return HEADER_ThemeChanged (infoPtr);
case WM_PRINTCLIENT:
case WM_PAINT:
return HEADER_Paint (infoPtr, (HDC)wParam);
case WM_RBUTTONUP:
return HEADER_RButtonUp (infoPtr, (SHORT)LOWORD(lParam), (SHORT)HIWORD(lParam));
case WM_SETCURSOR:
return HEADER_SetCursor (infoPtr, lParam);
case WM_SETFONT:
return HEADER_SetFont (infoPtr, (HFONT)wParam, (WORD)lParam);
case WM_SETREDRAW:
return HEADER_SetRedraw(infoPtr, wParam, lParam);
case WM_STYLECHANGED:
return HEADER_StyleChanged(infoPtr, wParam, (LPSTYLESTRUCT)lParam);
case WM_SYSCOLORCHANGE:
COMCTL32_RefreshSysColors();
return 0;
default:
if ((msg >= WM_USER) && (msg < WM_APP) && !COMCTL32_IsReflectedMessage(msg))
ERR("unknown msg %04x wp=%04lx lp=%08lx\n",
msg, wParam, lParam );
return DefWindowProcW(hwnd, msg, wParam, lParam);
}
}
VOID
HEADER_Register (void)
{
WNDCLASSW wndClass;
ZeroMemory (&wndClass, sizeof(WNDCLASSW));
wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS;
wndClass.lpfnWndProc = HEADER_WindowProc;
wndClass.cbClsExtra = 0;
wndClass.cbWndExtra = sizeof(HEADER_INFO *);
wndClass.hCursor = LoadCursorW (0, (LPWSTR)IDC_ARROW);
wndClass.lpszClassName = WC_HEADERW;
RegisterClassW (&wndClass);
}
VOID
HEADER_Unregister (void)
{
UnregisterClassW (WC_HEADERW, NULL);
}
|