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 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768 4769 4770 4771 4772 4773 4774 4775 4776 4777 4778 4779 4780 4781 4782 4783 4784 4785 4786 4787 4788 4789 4790 4791 4792 4793 4794 4795 4796 4797 4798 4799 4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 4822 4823 4824 4825 4826 4827 4828 4829 4830 4831 4832 4833 4834 4835 4836 4837 4838 4839 4840 4841 4842 4843 4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 4854 4855 4856 4857 4858 4859 4860 4861 4862 4863 4864 4865 4866 4867 4868 4869 4870 4871 4872 4873 4874 4875 4876 4877 4878 4879 4880 4881 4882 4883 4884 4885 4886 4887 4888 4889 4890 4891 4892 4893 4894 4895 4896 4897 4898 4899 4900 4901 4902 4903 4904 4905 4906 4907 4908 4909 4910 4911 4912 4913 4914 4915 4916 4917 4918 4919 4920 4921 4922 4923 4924 4925 4926 4927 4928 4929 4930 4931 4932 4933 4934 4935 4936 4937 4938 4939 4940 4941 4942 4943 4944 4945 4946 4947 4948 4949 4950 4951 4952 4953 4954 4955 4956 4957 4958 4959 4960 4961 4962 4963 4964 4965 4966 4967 4968 4969 4970 4971 4972 4973 4974 4975 4976 4977 4978 4979 4980 4981 4982 4983 4984 4985 4986 4987 4988 4989 4990 4991 4992 4993 4994 4995 4996 4997 4998 4999 5000 5001 5002 5003 5004 5005 5006 5007 5008 5009 5010 5011 5012 5013 5014 5015 5016 5017 5018 5019 5020 5021 5022 5023 5024 5025 5026 5027 5028 5029 5030 5031 5032 5033 5034 5035 5036 5037 5038 5039 5040 5041 5042 5043 5044 5045 5046 5047 5048 5049 5050 5051 5052 5053 5054 5055 5056 5057 5058 5059 5060 5061 5062 5063 5064 5065 5066 5067 5068 5069 5070 5071 5072 5073 5074 5075 5076 5077 5078 5079 5080 5081 5082 5083 5084 5085 5086 5087 5088 5089 5090 5091 5092 5093 5094 5095 5096 5097 5098 5099 5100 5101 5102 5103 5104 5105 5106 5107 5108 5109 5110 5111 5112 5113 5114 5115 5116 5117 5118 5119 5120 5121 5122 5123 5124 5125 5126 5127 5128 5129 5130 5131 5132 5133 5134 5135 5136 5137 5138 5139 5140 5141 5142 5143 5144 5145 5146 5147 5148 5149 5150 5151 5152 5153 5154 5155 5156 5157 5158 5159 5160 5161 5162 5163 5164 5165 5166 5167 5168 5169 5170 5171 5172 5173 5174 5175 5176 5177 5178 5179 5180 5181 5182 5183 5184 5185 5186 5187 5188 5189 5190 5191 5192 5193 5194 5195 5196 5197 5198 5199 5200 5201 5202 5203 5204 5205 5206 5207 5208 5209 5210 5211 5212 5213 5214 5215 5216 5217 5218 5219 5220 5221 5222 5223 5224 5225 5226 5227 5228 5229 5230 5231 5232 5233 5234 5235 5236 5237 5238 5239 5240 5241 5242 5243 5244 5245 5246 5247 5248 5249 5250 5251 5252 5253 5254 5255 5256 5257 5258 5259 5260 5261 5262 5263 5264 5265 5266 5267 5268 5269 5270 5271 5272 5273 5274 5275 5276 5277 5278 5279 5280 5281 5282 5283 5284 5285 5286 5287 5288 5289 5290 5291 5292 5293 5294 5295 5296 5297 5298 5299 5300 5301 5302 5303 5304 5305 5306 5307 5308 5309 5310 5311 5312 5313 5314 5315 5316 5317 5318 5319 5320 5321 5322 5323 5324 5325 5326 5327 5328 5329 5330 5331 5332 5333 5334 5335 5336 5337 5338 5339 5340 5341 5342 5343 5344 5345 5346 5347 5348 5349 5350 5351 5352 5353 5354 5355 5356 5357 5358 5359 5360 5361 5362 5363 5364 5365 5366 5367 5368 5369 5370 5371 5372 5373 5374 5375 5376 5377 5378 5379 5380 5381 5382 5383 5384 5385 5386 5387 5388 5389 5390 5391 5392 5393 5394 5395 5396 5397 5398 5399 5400 5401 5402 5403 5404 5405 5406 5407 5408 5409 5410 5411 5412 5413 5414 5415 5416 5417 5418 5419 5420 5421 5422 5423 5424 5425 5426 5427 5428 5429 5430 5431 5432 5433 5434 5435 5436 5437 5438 5439 5440 5441 5442 5443 5444 5445 5446 5447 5448 5449 5450 5451 5452 5453 5454 5455 5456 5457 5458 5459 5460 5461 5462 5463 5464 5465 5466 5467 5468 5469 5470 5471 5472 5473 5474 5475 5476 5477 5478 5479 5480 5481 5482 5483 5484 5485 5486 5487 5488 5489 5490 5491 5492 5493 5494 5495 5496 5497 5498 5499 5500 5501 5502 5503 5504 5505 5506 5507 5508 5509 5510 5511 5512 5513 5514 5515 5516 5517 5518 5519 5520 5521 5522 5523 5524 5525 5526 5527 5528 5529 5530 5531 5532 5533 5534 5535 5536 5537 5538 5539 5540 5541 5542 5543 5544 5545 5546 5547 5548 5549 5550 5551 5552 5553 5554 5555 5556 5557 5558 5559 5560 5561 5562 5563 5564 5565 5566 5567 5568 5569 5570 5571 5572 5573 5574 5575 5576 5577 5578 5579 5580 5581 5582 5583 5584 5585 5586 5587 5588 5589 5590 5591 5592 5593 5594 5595 5596 5597 5598 5599 5600 5601 5602 5603 5604 5605 5606 5607 5608 5609 5610 5611 5612 5613 5614 5615 5616 5617 5618 5619 5620 5621 5622 5623 5624 5625 5626 5627 5628 5629 5630 5631 5632 5633 5634 5635 5636 5637 5638 5639 5640 5641 5642 5643 5644 5645 5646 5647 5648 5649 5650 5651 5652 5653 5654 5655 5656 5657 5658 5659 5660 5661 5662 5663 5664 5665 5666 5667 5668 5669 5670 5671 5672 5673 5674 5675 5676 5677 5678 5679 5680 5681 5682 5683 5684 5685 5686 5687 5688 5689 5690 5691 5692 5693 5694 5695 5696 5697 5698 5699 5700 5701 5702 5703 5704 5705 5706 5707 5708 5709 5710 5711 5712 5713 5714 5715 5716 5717 5718 5719 5720 5721 5722 5723 5724 5725 5726 5727 5728 5729 5730 5731 5732 5733 5734 5735 5736 5737 5738 5739 5740 5741 5742 5743 5744 5745 5746 5747 5748 5749 5750 5751 5752 5753 5754 5755 5756 5757 5758 5759 5760 5761 5762 5763 5764 5765 5766 5767 5768 5769 5770 5771 5772 5773 5774 5775 5776 5777 5778 5779 5780 5781 5782 5783 5784 5785 5786 5787 5788 5789 5790 5791 5792 5793 5794 5795 5796 5797 5798 5799 5800 5801 5802 5803 5804 5805 5806 5807 5808 5809 5810 5811 5812 5813 5814 5815 5816 5817 5818 5819 5820 5821 5822 5823 5824 5825 5826 5827 5828 5829 5830 5831 5832 5833 5834 5835 5836 5837 5838 5839 5840 5841 5842 5843 5844 5845 5846 5847 5848 5849 5850 5851 5852 5853 5854 5855 5856 5857 5858 5859 5860 5861 5862 5863 5864 5865 5866 5867 5868 5869 5870 5871 5872 5873 5874 5875 5876 5877 5878 5879 5880 5881 5882 5883 5884 5885 5886 5887 5888 5889 5890 5891 5892 5893 5894 5895 5896 5897 5898 5899 5900 5901 5902 5903 5904 5905 5906 5907 5908 5909 5910 5911 5912 5913 5914 5915 5916 5917 5918 5919 5920 5921 5922 5923 5924 5925 5926 5927 5928 5929 5930 5931 5932 5933 5934 5935 5936 5937 5938 5939 5940 5941 5942 5943 5944 5945 5946 5947 5948 5949 5950 5951 5952 5953 5954 5955 5956 5957 5958 5959 5960 5961 5962 5963 5964 5965 5966 5967 5968 5969 5970 5971 5972 5973 5974 5975 5976 5977 5978 5979 5980 5981 5982 5983 5984 5985 5986 5987 5988 5989 5990 5991 5992 5993 5994 5995 5996 5997 5998 5999 6000 6001 6002 6003 6004 6005 6006 6007 6008 6009 6010 6011 6012 6013 6014 6015 6016 6017 6018 6019 6020 6021 6022 6023 6024 6025 6026 6027 6028 6029 6030 6031 6032 6033 6034 6035 6036 6037 6038 6039 6040 6041 6042 6043 6044 6045 6046 6047 6048 6049 6050 6051 6052 6053 6054 6055 6056 6057 6058 6059 6060 6061 6062 6063 6064 6065 6066 6067 6068 6069 6070 6071 6072 6073 6074 6075 6076 6077 6078 6079 6080 6081 6082 6083 6084 6085 6086 6087 6088 6089 6090 6091 6092 6093 6094 6095 6096 6097 6098 6099 6100 6101 6102 6103 6104 6105 6106 6107 6108 6109 6110 6111 6112 6113 6114 6115 6116 6117 6118 6119 6120 6121 6122 6123 6124 6125 6126 6127 6128 6129 6130 6131 6132 6133 6134 6135 6136 6137 6138 6139 6140 6141 6142 6143 6144 6145 6146 6147 6148 6149 6150 6151 6152 6153 6154 6155 6156 6157 6158 6159 6160 6161 6162 6163 6164 6165 6166 6167 6168 6169 6170 6171 6172 6173 6174 6175 6176 6177 6178 6179 6180 6181 6182 6183 6184 6185 6186 6187 6188 6189 6190 6191 6192 6193 6194 6195 6196 6197 6198 6199 6200 6201 6202 6203 6204 6205 6206 6207 6208 6209 6210 6211 6212 6213 6214 6215 6216 6217 6218 6219 6220 6221 6222 6223 6224 6225 6226 6227 6228 6229 6230 6231 6232 6233 6234 6235 6236 6237 6238 6239 6240 6241 6242 6243 6244 6245 6246 6247 6248 6249 6250 6251 6252 6253 6254 6255 6256 6257 6258 6259 6260 6261 6262 6263 6264 6265 6266 6267 6268 6269 6270 6271 6272 6273 6274 6275 6276 6277 6278 6279 6280 6281 6282 6283 6284 6285 6286 6287 6288 6289 6290 6291 6292 6293 6294 6295 6296 6297 6298 6299 6300 6301 6302 6303 6304 6305 6306 6307 6308 6309 6310 6311 6312 6313 6314 6315 6316 6317 6318 6319 6320 6321 6322 6323 6324 6325 6326 6327 6328 6329 6330 6331 6332 6333 6334 6335 6336 6337 6338 6339 6340 6341 6342 6343 6344 6345 6346 6347 6348 6349 6350 6351 6352 6353 6354 6355 6356 6357 6358 6359 6360 6361 6362 6363 6364 6365 6366 6367 6368 6369 6370 6371 6372 6373 6374 6375 6376 6377 6378 6379 6380 6381 6382 6383 6384 6385 6386 6387 6388 6389 6390 6391 6392 6393 6394 6395 6396 6397 6398 6399 6400 6401 6402 6403 6404 6405 6406 6407 6408 6409 6410 6411 6412 6413 6414 6415 6416 6417 6418 6419 6420 6421 6422 6423 6424 6425 6426 6427 6428 6429 6430 6431 6432 6433 6434 6435 6436 6437 6438 6439 6440 6441 6442 6443 6444 6445 6446 6447 6448 6449 6450 6451 6452 6453 6454 6455 6456 6457 6458 6459 6460 6461 6462 6463 6464 6465 6466 6467 6468 6469 6470 6471 6472 6473 6474 6475 6476 6477 6478 6479 6480 6481 6482 6483 6484 6485 6486 6487 6488 6489 6490 6491 6492 6493 6494 6495 6496 6497 6498 6499 6500 6501 6502 6503 6504 6505 6506 6507 6508 6509 6510 6511 6512 6513 6514 6515 6516 6517 6518 6519 6520 6521 6522 6523 6524 6525 6526 6527 6528 6529 6530 6531 6532 6533 6534 6535 6536 6537 6538 6539 6540 6541 6542 6543 6544 6545 6546 6547 6548 6549 6550 6551 6552 6553 6554 6555 6556 6557 6558 6559 6560 6561 6562 6563 6564 6565 6566 6567 6568 6569 6570 6571 6572 6573 6574 6575 6576 6577 6578 6579 6580 6581 6582 6583 6584 6585 6586 6587 6588 6589 6590 6591 6592 6593 6594 6595 6596 6597 6598 6599 6600 6601 6602 6603 6604 6605 6606 6607 6608 6609 6610 6611 6612 6613 6614 6615 6616 6617 6618 6619 6620 6621 6622 6623 6624 6625 6626 6627 6628 6629 6630 6631 6632 6633 6634 6635 6636 6637 6638 6639 6640 6641 6642 6643 6644 6645 6646 6647 6648 6649 6650 6651 6652 6653 6654 6655 6656 6657 6658 6659 6660 6661 6662 6663 6664 6665 6666 6667 6668 6669 6670 6671 6672 6673 6674 6675 6676 6677 6678 6679 6680 6681 6682 6683 6684 6685 6686 6687 6688 6689 6690 6691 6692 6693 6694 6695 6696 6697 6698 6699 6700 6701 6702 6703 6704 6705 6706 6707 6708 6709 6710 6711 6712 6713 6714 6715 6716 6717 6718 6719 6720 6721 6722 6723 6724 6725 6726 6727 6728 6729 6730 6731 6732 6733 6734 6735 6736 6737 6738 6739 6740 6741 6742 6743 6744 6745 6746 6747 6748 6749 6750 6751 6752 6753 6754 6755 6756 6757 6758 6759 6760 6761 6762 6763 6764 6765 6766 6767 6768 6769 6770 6771 6772 6773 6774 6775 6776 6777 6778 6779 6780 6781 6782 6783 6784 6785 6786 6787 6788 6789 6790 6791 6792 6793 6794 6795 6796 6797 6798 6799 6800 6801 6802 6803 6804 6805 6806 6807 6808 6809 6810 6811 6812 6813 6814 6815 6816 6817 6818 6819 6820 6821 6822 6823 6824 6825 6826 6827 6828 6829 6830 6831 6832 6833 6834 6835 6836 6837 6838 6839 6840 6841 6842 6843 6844 6845 6846 6847 6848 6849 6850 6851 6852 6853 6854 6855 6856 6857 6858 6859 6860 6861 6862 6863 6864 6865 6866 6867 6868 6869 6870 6871 6872 6873 6874 6875 6876 6877 6878 6879 6880 6881 6882 6883 6884 6885 6886 6887 6888 6889 6890 6891 6892 6893 6894 6895 6896 6897 6898 6899 6900 6901 6902 6903 6904 6905 6906 6907 6908 6909 6910 6911 6912 6913 6914 6915 6916 6917 6918 6919 6920 6921 6922 6923 6924 6925 6926 6927 6928 6929 6930 6931 6932 6933 6934 6935 6936 6937 6938 6939 6940 6941 6942 6943 6944 6945 6946 6947 6948 6949 6950 6951 6952 6953 6954 6955 6956 6957 6958 6959 6960 6961 6962 6963 6964 6965 6966 6967 6968 6969 6970 6971 6972 6973 6974 6975 6976
|
/*
* Toolbar control
*
* Copyright 1998,1999 Eric Kohl
* Copyright 2000 Eric Kohl for CodeWeavers
* Copyright 2004 Robert Shearman
*
* 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
*
* NOTES
*
* This code was audited for completeness against the documented features
* of Comctl32.dll version 6.0 on Mar. 14, 2004, by Robert Shearman.
*
* Unless otherwise noted, we believe this code to be complete, as per
* the specification mentioned above.
* If you discover missing features or bugs please note them below.
*
* TODO:
* - Styles:
* - TBSTYLE_REGISTERDROP
* - TBSTYLE_EX_DOUBLEBUFFER
* - Messages:
* - TB_GETMETRICS
* - TB_GETOBJECT
* - TB_INSERTMARKHITTEST
* - TB_SAVERESTORE
* - TB_SETMETRICS
* - WM_WININICHANGE
* - Notifications:
* - NM_CHAR
* - TBN_GETOBJECT
* - TBN_SAVE
* - Button wrapping (under construction).
* - Fix TB_SETROWS and Separators.
* - iListGap custom draw support.
*
* Testing:
* - Run tests using Waite Group Windows95 API Bible Volume 2.
* The second cdrom contains executables addstr.exe, btncount.exe,
* btnstate.exe, butstrsz.exe, chkbtn.exe, chngbmp.exe, customiz.exe,
* enablebtn.exe, getbmp.exe, getbtn.exe, getflags.exe, hidebtn.exe,
* indetbtn.exe, insbtn.exe, pressbtn.exe, setbtnsz.exe, setcmdid.exe,
* setparnt.exe, setrows.exe, toolwnd.exe.
* - Microsoft's controlspy examples.
* - Charles Petzold's 'Programming Windows': gadgets.exe
*
* Differences between MSDN and actual native control operation:
* 1. MSDN says: "TBSTYLE_LIST: Creates a flat toolbar with button text
* to the right of the bitmap. Otherwise, this style is
* identical to TBSTYLE_FLAT."
* As implemented by both v4.71 and v5.80 of the native COMCTL32.DLL
* you can create a TBSTYLE_LIST without TBSTYLE_FLAT and the result
* is non-flat non-transparent buttons. Therefore TBSTYLE_LIST does
* *not* imply TBSTYLE_FLAT as documented. (GA 8/2001)
*
*/
#include <stdarg.h>
#include <string.h>
#include "windef.h"
#include "winbase.h"
#include "winreg.h"
#include "wingdi.h"
#include "winuser.h"
#include "wine/unicode.h"
#include "winnls.h"
#include "commctrl.h"
#include "comctl32.h"
#include "uxtheme.h"
#include "vssym32.h"
#include "wine/debug.h"
WINE_DEFAULT_DEBUG_CHANNEL(toolbar);
static HCURSOR hCursorDrag = NULL;
typedef struct
{
INT iBitmap;
INT idCommand;
BYTE fsState;
BYTE fsStyle;
BYTE bHot;
BYTE bDropDownPressed;
DWORD_PTR dwData;
INT_PTR iString;
INT nRow;
RECT rect;
INT cx; /* manually set size */
} TBUTTON_INFO;
typedef struct
{
UINT nButtons;
HINSTANCE hInst;
UINT nID;
} TBITMAP_INFO;
typedef struct
{
HIMAGELIST himl;
INT id;
} IMLENTRY, *PIMLENTRY;
typedef struct
{
DWORD dwStructSize; /* size of TBBUTTON struct */
INT nWidth; /* width of the toolbar */
RECT client_rect;
RECT rcBound; /* bounding rectangle */
INT nButtonHeight;
INT nButtonWidth;
INT nBitmapHeight;
INT nBitmapWidth;
INT nIndent;
INT nRows; /* number of button rows */
INT nMaxTextRows; /* maximum number of text rows */
INT cxMin; /* minimum button width */
INT cxMax; /* maximum button width */
INT nNumButtons; /* number of buttons */
INT nNumBitmaps; /* number of bitmaps */
INT nNumStrings; /* number of strings */
INT nNumBitmapInfos;
INT nButtonDown; /* toolbar button being pressed or -1 if none */
INT nButtonDrag; /* toolbar button being dragged or -1 if none */
INT nOldHit;
INT nHotItem; /* index of the "hot" item */
SIZE szPadding; /* padding values around button */
INT iTopMargin; /* the top margin */
INT iListGap; /* default gap between text and image for toolbar with list style */
HFONT hDefaultFont;
HFONT hFont; /* text font */
HIMAGELIST himlInt; /* image list created internally */
PIMLENTRY *himlDef; /* default image list array */
INT cimlDef; /* default image list array count */
PIMLENTRY *himlHot; /* hot image list array */
INT cimlHot; /* hot image list array count */
PIMLENTRY *himlDis; /* disabled image list array */
INT cimlDis; /* disabled image list array count */
HWND hwndToolTip; /* handle to tool tip control */
HWND hwndNotify; /* handle to the window that gets notifications */
HWND hwndSelf; /* my own handle */
BOOL bAnchor; /* anchor highlight enabled */
BOOL bDoRedraw; /* Redraw status */
BOOL bDragOutSent; /* has TBN_DRAGOUT notification been sent for this drag? */
BOOL bUnicode; /* Notifications are ASCII (FALSE) or Unicode (TRUE)? */
BOOL bCaptured; /* mouse captured? */
DWORD dwStyle; /* regular toolbar style */
DWORD dwExStyle; /* extended toolbar style */
DWORD dwDTFlags; /* DrawText flags */
COLORREF clrInsertMark; /* insert mark color */
COLORREF clrBtnHighlight; /* color for Flat Separator */
COLORREF clrBtnShadow; /* color for Flag Separator */
INT iVersion;
LPWSTR pszTooltipText; /* temporary store for a string > 80 characters
* for TTN_GETDISPINFOW notification */
TBINSERTMARK tbim; /* info on insertion mark */
TBUTTON_INFO *buttons; /* pointer to button array */
LPWSTR *strings; /* pointer to string array */
TBITMAP_INFO *bitmaps;
} TOOLBAR_INFO, *PTOOLBAR_INFO;
/* used by customization dialog */
typedef struct
{
PTOOLBAR_INFO tbInfo;
HWND tbHwnd;
} CUSTDLG_INFO, *PCUSTDLG_INFO;
typedef struct
{
TBBUTTON btn;
BOOL bVirtual;
BOOL bRemovable;
WCHAR text[64];
} CUSTOMBUTTON, *PCUSTOMBUTTON;
typedef enum
{
IMAGE_LIST_DEFAULT,
IMAGE_LIST_HOT,
IMAGE_LIST_DISABLED
} IMAGE_LIST_TYPE;
#define SEPARATOR_WIDTH 8
#define TOP_BORDER 2
#define BOTTOM_BORDER 2
#define DDARROW_WIDTH 11
#define ARROW_HEIGHT 3
#define INSERTMARK_WIDTH 2
#define DEFPAD_CX 7
#define DEFPAD_CY 6
#define DEFLISTGAP 4
/* vertical padding used in list mode when image is present */
#define LISTPAD_CY 9
/* how wide to treat the bitmap if it isn't present */
#define NONLIST_NOTEXT_OFFSET 2
#define TOOLBAR_NOWHERE (-1)
#define TOOLBAR_HasText(x, y) (TOOLBAR_GetText(x, y) ? TRUE : FALSE)
#define TOOLBAR_HasDropDownArrows(exStyle) ((exStyle & TBSTYLE_EX_DRAWDDARROWS) ? TRUE : FALSE)
/* Used to find undocumented extended styles */
#define TBSTYLE_EX_ALL (TBSTYLE_EX_DRAWDDARROWS | \
TBSTYLE_EX_UNDOC1 | \
TBSTYLE_EX_MIXEDBUTTONS | \
TBSTYLE_EX_DOUBLEBUFFER | \
TBSTYLE_EX_HIDECLIPPEDBUTTONS)
/* all of the CCS_ styles */
#define COMMON_STYLES (CCS_TOP|CCS_NOMOVEY|CCS_BOTTOM|CCS_NORESIZE| \
CCS_NOPARENTALIGN|CCS_ADJUSTABLE|CCS_NODIVIDER|CCS_VERT)
#define GETIBITMAP(infoPtr, i) (infoPtr->iVersion >= 5 ? LOWORD(i) : i)
#define GETHIMLID(infoPtr, i) (infoPtr->iVersion >= 5 ? HIWORD(i) : 0)
#define GETDEFIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlDef, infoPtr->cimlDef, id)
#define GETHOTIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlHot, infoPtr->cimlHot, id)
#define GETDISIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlDis, infoPtr->cimlDis, id)
static const WCHAR themeClass[] = { 'T','o','o','l','b','a','r',0 };
static BOOL TOOLBAR_GetButtonInfo(const TOOLBAR_INFO *infoPtr, NMTOOLBARW *nmtb);
static BOOL TOOLBAR_IsButtonRemovable(const TOOLBAR_INFO *infoPtr, int iItem, const CUSTOMBUTTON *btnInfo);
static HIMAGELIST TOOLBAR_GetImageList(const PIMLENTRY *pies, INT cies, INT id);
static PIMLENTRY TOOLBAR_GetImageListEntry(const PIMLENTRY *pies, INT cies, INT id);
static VOID TOOLBAR_DeleteImageList(PIMLENTRY **pies, INT *cies);
static HIMAGELIST TOOLBAR_InsertImageList(PIMLENTRY **pies, INT *cies, HIMAGELIST himl, INT id);
static LRESULT TOOLBAR_LButtonDown(TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam);
static void TOOLBAR_LayoutToolbar(TOOLBAR_INFO *infoPtr);
static LRESULT TOOLBAR_AutoSize(TOOLBAR_INFO *infoPtr);
static void TOOLBAR_CheckImageListIconSize(TOOLBAR_INFO *infoPtr);
static void TOOLBAR_TooltipAddTool(const TOOLBAR_INFO *infoPtr, const TBUTTON_INFO *button);
static void TOOLBAR_TooltipSetRect(const TOOLBAR_INFO *infoPtr, const TBUTTON_INFO *button);
static inline int default_top_margin(const TOOLBAR_INFO *infoPtr)
{
return (infoPtr->dwStyle & TBSTYLE_FLAT ? 0 : TOP_BORDER);
}
static LPWSTR
TOOLBAR_GetText(const TOOLBAR_INFO *infoPtr, const TBUTTON_INFO *btnPtr)
{
LPWSTR lpText = NULL;
/* NOTE: iString == -1 is undocumented */
if (!IS_INTRESOURCE(btnPtr->iString) && (btnPtr->iString != -1))
lpText = (LPWSTR)btnPtr->iString;
else if ((btnPtr->iString >= 0) && (btnPtr->iString < infoPtr->nNumStrings))
lpText = infoPtr->strings[btnPtr->iString];
return lpText;
}
static void
TOOLBAR_DumpTBButton(const TBBUTTON *tbb, BOOL fUnicode)
{
TRACE("TBBUTTON: id %d, bitmap=%d, state=%02x, style=%02x, data=%08lx, stringid=0x%08lx (%s)\n",
tbb->idCommand,tbb->iBitmap, tbb->fsState, tbb->fsStyle, tbb->dwData, tbb->iString,
(fUnicode ? wine_dbgstr_w((LPWSTR)tbb->iString) : wine_dbgstr_a((LPSTR)tbb->iString)));
}
static void
TOOLBAR_DumpButton(const TOOLBAR_INFO *infoPtr, const TBUTTON_INFO *bP, INT btn_num)
{
if (TRACE_ON(toolbar)){
TRACE("button %d id %d, bitmap=%d, state=%02x, style=%02x, data=%08lx, stringid=0x%08lx\n",
btn_num, bP->idCommand, GETIBITMAP(infoPtr, bP->iBitmap),
bP->fsState, bP->fsStyle, bP->dwData, bP->iString);
TRACE("string %s\n", debugstr_w(TOOLBAR_GetText(infoPtr,bP)));
TRACE("button %d id %d, hot=%s, row=%d, rect=(%s)\n",
btn_num, bP->idCommand, (bP->bHot) ? "TRUE":"FALSE", bP->nRow,
wine_dbgstr_rect(&bP->rect));
}
}
static void
TOOLBAR_DumpToolbar(const TOOLBAR_INFO *iP, INT line)
{
if (TRACE_ON(toolbar)) {
INT i;
TRACE("toolbar %p at line %d, exStyle=%08x, buttons=%d, bitmaps=%d, strings=%d, style=%08x\n",
iP->hwndSelf, line,
iP->dwExStyle, iP->nNumButtons, iP->nNumBitmaps,
iP->nNumStrings, iP->dwStyle);
TRACE("toolbar %p at line %d, himlInt=%p, himlDef=%p, himlHot=%p, himlDis=%p, redrawable=%s\n",
iP->hwndSelf, line,
iP->himlInt, iP->himlDef, iP->himlHot, iP->himlDis,
(iP->bDoRedraw) ? "TRUE" : "FALSE");
for(i=0; i<iP->nNumButtons; i++) {
TOOLBAR_DumpButton(iP, &iP->buttons[i], i);
}
}
}
static inline BOOL
TOOLBAR_ButtonHasString(const TBUTTON_INFO *btnPtr)
{
return HIWORD(btnPtr->iString) && btnPtr->iString != -1;
}
/***********************************************************************
* TOOLBAR_CheckStyle
*
* This function validates that the styles set are implemented and
* issues FIXMEs warning of possible problems. In a perfect world this
* function should be null.
*/
static void
TOOLBAR_CheckStyle (const TOOLBAR_INFO *infoPtr)
{
if (infoPtr->dwStyle & TBSTYLE_REGISTERDROP)
FIXME("[%p] TBSTYLE_REGISTERDROP not implemented\n", infoPtr->hwndSelf);
}
static INT
TOOLBAR_SendNotify (NMHDR *nmhdr, const TOOLBAR_INFO *infoPtr, UINT code)
{
if(!IsWindow(infoPtr->hwndSelf))
return 0; /* we have just been destroyed */
nmhdr->idFrom = GetDlgCtrlID (infoPtr->hwndSelf);
nmhdr->hwndFrom = infoPtr->hwndSelf;
nmhdr->code = code;
TRACE("to window %p, code=%08x, %s\n", infoPtr->hwndNotify, code,
(infoPtr->bUnicode) ? "via Unicode" : "via ANSI");
return SendMessageW(infoPtr->hwndNotify, WM_NOTIFY, nmhdr->idFrom, (LPARAM)nmhdr);
}
/***********************************************************************
* TOOLBAR_GetBitmapIndex
*
* This function returns the bitmap index associated with a button.
* If the button specifies I_IMAGECALLBACK, then the TBN_GETDISPINFO
* is issued to retrieve the index.
*/
static INT
TOOLBAR_GetBitmapIndex(const TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr)
{
INT ret = btnPtr->iBitmap;
if (ret == I_IMAGECALLBACK)
{
/* issue TBN_GETDISPINFO */
NMTBDISPINFOW nmgd;
memset(&nmgd, 0, sizeof(nmgd));
nmgd.idCommand = btnPtr->idCommand;
nmgd.lParam = btnPtr->dwData;
nmgd.dwMask = TBNF_IMAGE;
nmgd.iImage = -1;
/* Windows also send TBN_GETDISPINFOW even if the control is ANSI */
TOOLBAR_SendNotify(&nmgd.hdr, infoPtr, TBN_GETDISPINFOW);
if (nmgd.dwMask & TBNF_DI_SETITEM)
btnPtr->iBitmap = nmgd.iImage;
ret = nmgd.iImage;
TRACE("TBN_GETDISPINFO returned bitmap id %d, mask=%08x, nNumBitmaps=%d\n",
ret, nmgd.dwMask, infoPtr->nNumBitmaps);
}
if (ret != I_IMAGENONE)
ret = GETIBITMAP(infoPtr, ret);
return ret;
}
static BOOL
TOOLBAR_IsValidBitmapIndex(const TOOLBAR_INFO *infoPtr, INT index)
{
HIMAGELIST himl;
INT id = GETHIMLID(infoPtr, index);
INT iBitmap = GETIBITMAP(infoPtr, index);
if (((himl = GETDEFIMAGELIST(infoPtr, id)) &&
iBitmap >= 0 && iBitmap < ImageList_GetImageCount(himl)) ||
(index == I_IMAGECALLBACK))
return TRUE;
else
return FALSE;
}
static inline BOOL
TOOLBAR_IsValidImageList(const TOOLBAR_INFO *infoPtr, INT index)
{
HIMAGELIST himl = GETDEFIMAGELIST(infoPtr, GETHIMLID(infoPtr, index));
return (himl != NULL) && (ImageList_GetImageCount(himl) > 0);
}
/***********************************************************************
* TOOLBAR_GetImageListForDrawing
*
* This function validates the bitmap index (including I_IMAGECALLBACK
* functionality) and returns the corresponding image list.
*/
static HIMAGELIST
TOOLBAR_GetImageListForDrawing (const TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr,
IMAGE_LIST_TYPE imagelist, INT * index)
{
HIMAGELIST himl;
if (!TOOLBAR_IsValidBitmapIndex(infoPtr,btnPtr->iBitmap)) {
if (btnPtr->iBitmap == I_IMAGENONE) return NULL;
ERR("bitmap for ID %d, index %d is not valid, number of bitmaps in imagelist: %d\n",
HIWORD(btnPtr->iBitmap), LOWORD(btnPtr->iBitmap), infoPtr->nNumBitmaps);
return NULL;
}
if ((*index = TOOLBAR_GetBitmapIndex(infoPtr, btnPtr)) < 0) {
if ((*index == I_IMAGECALLBACK) ||
(*index == I_IMAGENONE)) return NULL;
ERR("TBN_GETDISPINFO returned invalid index %d\n",
*index);
return NULL;
}
switch(imagelist)
{
case IMAGE_LIST_DEFAULT:
himl = GETDEFIMAGELIST(infoPtr, GETHIMLID(infoPtr, btnPtr->iBitmap));
break;
case IMAGE_LIST_HOT:
himl = GETHOTIMAGELIST(infoPtr, GETHIMLID(infoPtr, btnPtr->iBitmap));
break;
case IMAGE_LIST_DISABLED:
himl = GETDISIMAGELIST(infoPtr, GETHIMLID(infoPtr, btnPtr->iBitmap));
break;
default:
himl = NULL;
FIXME("Shouldn't reach here\n");
}
if (!himl)
TRACE("no image list\n");
return himl;
}
static void
TOOLBAR_DrawFlatSeparator (const RECT *lpRect, HDC hdc, const TOOLBAR_INFO *infoPtr)
{
RECT myrect;
COLORREF oldcolor, newcolor;
myrect.left = (lpRect->left + lpRect->right) / 2 - 1;
myrect.right = myrect.left + 1;
myrect.top = lpRect->top + 2;
myrect.bottom = lpRect->bottom - 2;
newcolor = (infoPtr->clrBtnShadow == CLR_DEFAULT) ?
comctl32_color.clrBtnShadow : infoPtr->clrBtnShadow;
oldcolor = SetBkColor (hdc, newcolor);
ExtTextOutW (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
myrect.left = myrect.right;
myrect.right = myrect.left + 1;
newcolor = (infoPtr->clrBtnHighlight == CLR_DEFAULT) ?
comctl32_color.clrBtnHighlight : infoPtr->clrBtnHighlight;
SetBkColor (hdc, newcolor);
ExtTextOutW (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
SetBkColor (hdc, oldcolor);
}
/***********************************************************************
* TOOLBAR_DrawFlatHorizontalSeparator
*
* This function draws horizontal separator for toolbars having CCS_VERT style.
* In this case, the separator is a pixel high line of COLOR_BTNSHADOW,
* followed by a pixel high line of COLOR_BTNHIGHLIGHT. These separators
* are horizontal as opposed to the vertical separators for not dropdown
* type.
*
* FIXME: It is possible that the height of each line is really SM_CYBORDER.
*/
static void
TOOLBAR_DrawFlatHorizontalSeparator (const RECT *lpRect, HDC hdc,
const TOOLBAR_INFO *infoPtr)
{
RECT myrect;
COLORREF oldcolor, newcolor;
myrect.left = lpRect->left;
myrect.right = lpRect->right;
myrect.top = lpRect->top + (lpRect->bottom - lpRect->top - 2)/2;
myrect.bottom = myrect.top + 1;
InflateRect (&myrect, -2, 0);
TRACE("rect=(%s)\n", wine_dbgstr_rect(&myrect));
newcolor = (infoPtr->clrBtnShadow == CLR_DEFAULT) ?
comctl32_color.clrBtnShadow : infoPtr->clrBtnShadow;
oldcolor = SetBkColor (hdc, newcolor);
ExtTextOutW (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
myrect.top = myrect.bottom;
myrect.bottom = myrect.top + 1;
newcolor = (infoPtr->clrBtnHighlight == CLR_DEFAULT) ?
comctl32_color.clrBtnHighlight : infoPtr->clrBtnHighlight;
SetBkColor (hdc, newcolor);
ExtTextOutW (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
SetBkColor (hdc, oldcolor);
}
static void
TOOLBAR_DrawArrow (HDC hdc, INT left, INT top, COLORREF clr)
{
INT x, y;
HPEN hPen, hOldPen;
if (!(hPen = CreatePen( PS_SOLID, 1, clr))) return;
hOldPen = SelectObject ( hdc, hPen );
x = left + 2;
y = top;
MoveToEx (hdc, x, y, NULL);
LineTo (hdc, x+5, y++); x++;
MoveToEx (hdc, x, y, NULL);
LineTo (hdc, x+3, y++); x++;
MoveToEx (hdc, x, y, NULL);
LineTo (hdc, x+1, y);
SelectObject( hdc, hOldPen );
DeleteObject( hPen );
}
/*
* Draw the text string for this button.
* note: infoPtr->himlDis *SHOULD* be non-zero when infoPtr->himlDef
* is non-zero, so we can simply check himlDef to see if we have
* an image list
*/
static void
TOOLBAR_DrawString (const TOOLBAR_INFO *infoPtr, RECT *rcText, LPCWSTR lpText,
const NMTBCUSTOMDRAW *tbcd, DWORD dwItemCDFlag)
{
HDC hdc = tbcd->nmcd.hdc;
HFONT hOldFont = 0;
COLORREF clrOld = 0;
COLORREF clrOldBk = 0;
int oldBkMode = 0;
UINT state = tbcd->nmcd.uItemState;
/* draw text */
if (lpText && infoPtr->nMaxTextRows > 0) {
TRACE("string=%s rect=(%s)\n", debugstr_w(lpText),
wine_dbgstr_rect(rcText));
hOldFont = SelectObject (hdc, infoPtr->hFont);
if ((state & CDIS_HOT) && (dwItemCDFlag & TBCDRF_HILITEHOTTRACK )) {
clrOld = SetTextColor (hdc, tbcd->clrTextHighlight);
}
else if (state & CDIS_DISABLED) {
clrOld = SetTextColor (hdc, tbcd->clrBtnHighlight);
OffsetRect (rcText, 1, 1);
DrawTextW (hdc, lpText, -1, rcText, infoPtr->dwDTFlags);
SetTextColor (hdc, comctl32_color.clr3dShadow);
OffsetRect (rcText, -1, -1);
}
else if (state & CDIS_INDETERMINATE) {
clrOld = SetTextColor (hdc, comctl32_color.clr3dShadow);
}
else if ((state & CDIS_MARKED) && !(dwItemCDFlag & TBCDRF_NOMARK)) {
clrOld = SetTextColor (hdc, tbcd->clrTextHighlight);
clrOldBk = SetBkColor (hdc, tbcd->clrMark);
oldBkMode = SetBkMode (hdc, tbcd->nHLStringBkMode);
}
else {
clrOld = SetTextColor (hdc, tbcd->clrText);
}
DrawTextW (hdc, lpText, -1, rcText, infoPtr->dwDTFlags);
SetTextColor (hdc, clrOld);
if ((state & CDIS_MARKED) && !(dwItemCDFlag & TBCDRF_NOMARK))
{
SetBkColor (hdc, clrOldBk);
SetBkMode (hdc, oldBkMode);
}
SelectObject (hdc, hOldFont);
}
}
static void
TOOLBAR_DrawPattern (const RECT *lpRect, const NMTBCUSTOMDRAW *tbcd)
{
HDC hdc = tbcd->nmcd.hdc;
HBRUSH hbr = SelectObject (hdc, tbcd->hbrMonoDither);
COLORREF clrTextOld;
COLORREF clrBkOld;
INT cx = lpRect->right - lpRect->left;
INT cy = lpRect->bottom - lpRect->top;
INT cxEdge = GetSystemMetrics(SM_CXEDGE);
INT cyEdge = GetSystemMetrics(SM_CYEDGE);
clrTextOld = SetTextColor(hdc, tbcd->clrBtnHighlight);
clrBkOld = SetBkColor(hdc, tbcd->clrBtnFace);
PatBlt (hdc, lpRect->left + cxEdge, lpRect->top + cyEdge,
cx - (2 * cxEdge), cy - (2 * cyEdge), PATCOPY);
SetBkColor(hdc, clrBkOld);
SetTextColor(hdc, clrTextOld);
SelectObject (hdc, hbr);
}
static void TOOLBAR_DrawMasked(HIMAGELIST himl, int index, HDC hdc, INT x, INT y, UINT draw_flags)
{
INT cx, cy;
HBITMAP hbmMask, hbmImage;
HDC hdcMask, hdcImage;
ImageList_GetIconSize(himl, &cx, &cy);
/* Create src image */
hdcImage = CreateCompatibleDC(hdc);
hbmImage = CreateCompatibleBitmap(hdc, cx, cy);
SelectObject(hdcImage, hbmImage);
ImageList_DrawEx(himl, index, hdcImage, 0, 0, cx, cy,
RGB(0xff, 0xff, 0xff), RGB(0,0,0), draw_flags);
/* Create Mask */
hdcMask = CreateCompatibleDC(0);
hbmMask = CreateBitmap(cx, cy, 1, 1, NULL);
SelectObject(hdcMask, hbmMask);
/* Remove the background and all white pixels */
ImageList_DrawEx(himl, index, hdcMask, 0, 0, cx, cy,
RGB(0xff, 0xff, 0xff), RGB(0,0,0), ILD_MASK);
SetBkColor(hdcImage, RGB(0xff, 0xff, 0xff));
BitBlt(hdcMask, 0, 0, cx, cy, hdcImage, 0, 0, NOTSRCERASE);
/* draw the new mask 'etched' to hdc */
SetBkColor(hdc, RGB(255, 255, 255));
SelectObject(hdc, GetSysColorBrush(COLOR_3DHILIGHT));
/* E20746 op code is (Dst ^ (Src & (Pat ^ Dst))) */
BitBlt(hdc, x + 1, y + 1, cx, cy, hdcMask, 0, 0, 0xE20746);
SelectObject(hdc, GetSysColorBrush(COLOR_3DSHADOW));
BitBlt(hdc, x, y, cx, cy, hdcMask, 0, 0, 0xE20746);
/* Cleanup */
DeleteObject(hbmImage);
DeleteDC(hdcImage);
DeleteObject (hbmMask);
DeleteDC(hdcMask);
}
static UINT
TOOLBAR_TranslateState(const TBUTTON_INFO *btnPtr)
{
UINT retstate = 0;
retstate |= (btnPtr->fsState & TBSTATE_CHECKED) ? CDIS_CHECKED : 0;
retstate |= (btnPtr->fsState & TBSTATE_PRESSED) ? CDIS_SELECTED : 0;
retstate |= (btnPtr->fsState & TBSTATE_ENABLED) ? 0 : CDIS_DISABLED;
retstate |= (btnPtr->fsState & TBSTATE_MARKED ) ? CDIS_MARKED : 0;
retstate |= (btnPtr->bHot ) ? CDIS_HOT : 0;
retstate |= ((btnPtr->fsState & (TBSTATE_ENABLED|TBSTATE_INDETERMINATE)) == (TBSTATE_ENABLED|TBSTATE_INDETERMINATE)) ? CDIS_INDETERMINATE : 0;
/* NOTE: we don't set CDIS_GRAYED, CDIS_FOCUS, CDIS_DEFAULT */
return retstate;
}
/* draws the image on a toolbar button */
static void
TOOLBAR_DrawImage(const TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr, INT left, INT top,
const NMTBCUSTOMDRAW *tbcd, DWORD dwItemCDFlag)
{
HIMAGELIST himl = NULL;
BOOL draw_masked = FALSE;
INT index;
INT offset = 0;
UINT draw_flags = ILD_TRANSPARENT;
if (tbcd->nmcd.uItemState & (CDIS_DISABLED | CDIS_INDETERMINATE))
{
himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DISABLED, &index);
if (!himl)
{
himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DEFAULT, &index);
draw_masked = TRUE;
}
}
else if (tbcd->nmcd.uItemState & CDIS_CHECKED ||
((tbcd->nmcd.uItemState & CDIS_HOT)
&& ((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf))))
{
/* if hot, attempt to draw with hot image list, if fails,
use default image list */
himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_HOT, &index);
if (!himl)
himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DEFAULT, &index);
}
else
himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DEFAULT, &index);
if (!himl)
return;
if (!(dwItemCDFlag & TBCDRF_NOOFFSET) &&
(tbcd->nmcd.uItemState & (CDIS_SELECTED | CDIS_CHECKED)))
offset = 1;
if (!(dwItemCDFlag & TBCDRF_NOMARK) &&
(tbcd->nmcd.uItemState & CDIS_MARKED))
draw_flags |= ILD_BLEND50;
TRACE("drawing index=%d, himl=%p, left=%d, top=%d, offset=%d\n",
index, himl, left, top, offset);
if (draw_masked)
TOOLBAR_DrawMasked (himl, index, tbcd->nmcd.hdc, left + offset, top + offset, draw_flags);
else
ImageList_Draw (himl, index, tbcd->nmcd.hdc, left + offset, top + offset, draw_flags);
}
/* draws a blank frame for a toolbar button */
static void
TOOLBAR_DrawFrame(const TOOLBAR_INFO *infoPtr, const NMTBCUSTOMDRAW *tbcd, DWORD dwItemCDFlag)
{
HDC hdc = tbcd->nmcd.hdc;
RECT rc = tbcd->nmcd.rc;
/* if the state is disabled or indeterminate then the button
* cannot have an interactive look like pressed or hot */
BOOL non_interactive_state = (tbcd->nmcd.uItemState & CDIS_DISABLED) ||
(tbcd->nmcd.uItemState & CDIS_INDETERMINATE);
BOOL pressed_look = !non_interactive_state &&
((tbcd->nmcd.uItemState & CDIS_SELECTED) ||
(tbcd->nmcd.uItemState & CDIS_CHECKED));
/* app don't want us to draw any edges */
if (dwItemCDFlag & TBCDRF_NOEDGES)
return;
if (infoPtr->dwStyle & TBSTYLE_FLAT)
{
if (pressed_look)
DrawEdge (hdc, &rc, BDR_SUNKENOUTER, BF_RECT);
else if ((tbcd->nmcd.uItemState & CDIS_HOT) && !non_interactive_state)
DrawEdge (hdc, &rc, BDR_RAISEDINNER, BF_RECT);
}
else
{
if (pressed_look)
DrawEdge (hdc, &rc, EDGE_SUNKEN, BF_RECT | BF_MIDDLE);
else
DrawEdge (hdc, &rc, EDGE_RAISED,
BF_SOFT | BF_RECT | BF_MIDDLE);
}
}
static void
TOOLBAR_DrawSepDDArrow(const TOOLBAR_INFO *infoPtr, const NMTBCUSTOMDRAW *tbcd, RECT *rcArrow, BOOL bDropDownPressed, DWORD dwItemCDFlag)
{
HDC hdc = tbcd->nmcd.hdc;
int offset = 0;
BOOL pressed = bDropDownPressed ||
(tbcd->nmcd.uItemState & (CDIS_SELECTED | CDIS_CHECKED));
if (infoPtr->dwStyle & TBSTYLE_FLAT)
{
if (pressed)
DrawEdge (hdc, rcArrow, BDR_SUNKENOUTER, BF_RECT);
else if ( (tbcd->nmcd.uItemState & CDIS_HOT) &&
!(tbcd->nmcd.uItemState & CDIS_DISABLED) &&
!(tbcd->nmcd.uItemState & CDIS_INDETERMINATE))
DrawEdge (hdc, rcArrow, BDR_RAISEDINNER, BF_RECT);
}
else
{
if (pressed)
DrawEdge (hdc, rcArrow, EDGE_SUNKEN, BF_RECT | BF_MIDDLE);
else
DrawEdge (hdc, rcArrow, EDGE_RAISED,
BF_SOFT | BF_RECT | BF_MIDDLE);
}
if (pressed)
offset = (dwItemCDFlag & TBCDRF_NOOFFSET) ? 0 : 1;
if (tbcd->nmcd.uItemState & (CDIS_DISABLED | CDIS_INDETERMINATE))
{
TOOLBAR_DrawArrow(hdc, rcArrow->left+1, rcArrow->top+1 + (rcArrow->bottom - rcArrow->top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnHighlight);
TOOLBAR_DrawArrow(hdc, rcArrow->left, rcArrow->top + (rcArrow->bottom - rcArrow->top - ARROW_HEIGHT) / 2, comctl32_color.clr3dShadow);
}
else
TOOLBAR_DrawArrow(hdc, rcArrow->left + offset, rcArrow->top + offset + (rcArrow->bottom - rcArrow->top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnText);
}
/* draws a complete toolbar button */
static void
TOOLBAR_DrawButton (const TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr, HDC hdc, DWORD dwBaseCustDraw)
{
DWORD dwStyle = infoPtr->dwStyle;
BOOL hasDropDownArrow = (TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle) &&
(btnPtr->fsStyle & BTNS_DROPDOWN)) ||
(btnPtr->fsStyle & BTNS_WHOLEDROPDOWN);
BOOL drawSepDropDownArrow = hasDropDownArrow &&
(~btnPtr->fsStyle & BTNS_WHOLEDROPDOWN);
RECT rc, rcArrow, rcBitmap, rcText;
LPWSTR lpText = NULL;
NMTBCUSTOMDRAW tbcd;
DWORD ntfret;
INT offset;
INT oldBkMode;
DWORD dwItemCustDraw;
DWORD dwItemCDFlag;
HTHEME theme = GetWindowTheme (infoPtr->hwndSelf);
rc = btnPtr->rect;
CopyRect (&rcArrow, &rc);
/* separator - doesn't send NM_CUSTOMDRAW */
if (btnPtr->fsStyle & BTNS_SEP) {
if (theme)
{
DrawThemeBackground (theme, hdc,
(dwStyle & CCS_VERT) ? TP_SEPARATORVERT : TP_SEPARATOR, 0,
&rc, NULL);
}
else
/* with the FLAT style, iBitmap is the width and has already */
/* been taken into consideration in calculating the width */
/* so now we need to draw the vertical separator */
/* empirical tests show that iBitmap can/will be non-zero */
/* when drawing the vertical bar... */
if ((dwStyle & TBSTYLE_FLAT) /* && (btnPtr->iBitmap == 0) */) {
if (dwStyle & CCS_VERT)
TOOLBAR_DrawFlatHorizontalSeparator (&rc, hdc, infoPtr);
else
TOOLBAR_DrawFlatSeparator (&rc, hdc, infoPtr);
}
else if (btnPtr->fsStyle != BTNS_SEP) {
FIXME("Draw some kind of separator: fsStyle=%x\n",
btnPtr->fsStyle);
}
return;
}
/* get a pointer to the text */
lpText = TOOLBAR_GetText(infoPtr, btnPtr);
if (hasDropDownArrow)
{
int right;
if (dwStyle & TBSTYLE_FLAT)
right = max(rc.left, rc.right - DDARROW_WIDTH);
else
right = max(rc.left, rc.right - DDARROW_WIDTH - 2);
if (drawSepDropDownArrow)
rc.right = right;
rcArrow.left = right;
}
/* copy text & bitmap rects after adjusting for drop-down arrow
* so that text & bitmap is centered in the rectangle not containing
* the arrow */
CopyRect(&rcText, &rc);
CopyRect(&rcBitmap, &rc);
/* Center the bitmap horizontally and vertically */
if (dwStyle & TBSTYLE_LIST)
{
if (lpText &&
infoPtr->nMaxTextRows > 0 &&
(!(infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) ||
(btnPtr->fsStyle & BTNS_SHOWTEXT)) )
rcBitmap.left += GetSystemMetrics(SM_CXEDGE) + infoPtr->szPadding.cx / 2;
else
rcBitmap.left += GetSystemMetrics(SM_CXEDGE) + infoPtr->iListGap / 2;
}
else
rcBitmap.left += ((rc.right - rc.left) - infoPtr->nBitmapWidth) / 2;
rcBitmap.top += infoPtr->szPadding.cy / 2;
TRACE("iBitmap=%d, start=(%d,%d) w=%d, h=%d\n",
btnPtr->iBitmap, rcBitmap.left, rcBitmap.top,
infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
TRACE("Text=%s\n", debugstr_w(lpText));
TRACE("iListGap=%d, padding = { %d, %d }\n", infoPtr->iListGap, infoPtr->szPadding.cx, infoPtr->szPadding.cy);
/* calculate text position */
if (lpText)
{
rcText.left += GetSystemMetrics(SM_CXEDGE);
rcText.right -= GetSystemMetrics(SM_CXEDGE);
if (dwStyle & TBSTYLE_LIST)
{
rcText.left += infoPtr->nBitmapWidth + infoPtr->iListGap + 2;
}
else
{
if (ImageList_GetImageCount(GETDEFIMAGELIST(infoPtr, 0)) > 0)
rcText.top += infoPtr->szPadding.cy/2 + infoPtr->nBitmapHeight + 1;
else
rcText.top += infoPtr->szPadding.cy/2 + 2;
}
}
/* Initialize fields in all cases, because we use these later
* NOTE: applications can and do alter these to customize their
* toolbars */
ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
tbcd.clrText = comctl32_color.clrBtnText;
tbcd.clrTextHighlight = comctl32_color.clrHighlightText;
tbcd.clrBtnFace = comctl32_color.clrBtnFace;
tbcd.clrBtnHighlight = comctl32_color.clrBtnHighlight;
tbcd.clrMark = comctl32_color.clrHighlight;
tbcd.clrHighlightHotTrack = 0;
tbcd.nStringBkMode = TRANSPARENT;
tbcd.nHLStringBkMode = OPAQUE;
/* MSDN says that this is the text rectangle.
* But (why always a but) tracing of v5.7 of native shows
* that this is really a *relative* rectangle based on the
* the nmcd.rc. Also the left and top are always 0 ignoring
* any bitmap that might be present. */
tbcd.rcText.left = 0;
tbcd.rcText.top = 0;
tbcd.rcText.right = rcText.right - rc.left;
tbcd.rcText.bottom = rcText.bottom - rc.top;
tbcd.nmcd.uItemState = TOOLBAR_TranslateState(btnPtr);
tbcd.nmcd.hdc = hdc;
tbcd.nmcd.rc = rc;
tbcd.hbrMonoDither = COMCTL32_hPattern55AABrush;
/* FIXME: what are these used for? */
tbcd.hbrLines = 0;
tbcd.hpenLines = 0;
/* Issue Item Prepaint notify */
dwItemCustDraw = 0;
dwItemCDFlag = 0;
if (dwBaseCustDraw & CDRF_NOTIFYITEMDRAW)
{
tbcd.nmcd.dwDrawStage = CDDS_ITEMPREPAINT;
tbcd.nmcd.dwItemSpec = btnPtr->idCommand;
tbcd.nmcd.lItemlParam = btnPtr->dwData;
ntfret = TOOLBAR_SendNotify(&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
/* reset these fields so the user can't alter the behaviour like native */
tbcd.nmcd.hdc = hdc;
tbcd.nmcd.rc = rc;
dwItemCustDraw = ntfret & 0xffff;
dwItemCDFlag = ntfret & 0xffff0000;
if (dwItemCustDraw & CDRF_SKIPDEFAULT)
return;
/* save the only part of the rect that the user can change */
rcText.right = tbcd.rcText.right + rc.left;
rcText.bottom = tbcd.rcText.bottom + rc.top;
}
if (!(dwItemCDFlag & TBCDRF_NOOFFSET) &&
(btnPtr->fsState & (TBSTATE_PRESSED | TBSTATE_CHECKED)))
OffsetRect(&rcText, 1, 1);
if (!(tbcd.nmcd.uItemState & CDIS_HOT) &&
((tbcd.nmcd.uItemState & CDIS_CHECKED) || (tbcd.nmcd.uItemState & CDIS_INDETERMINATE)))
TOOLBAR_DrawPattern (&rc, &tbcd);
if (((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf))
&& (tbcd.nmcd.uItemState & CDIS_HOT))
{
if ( dwItemCDFlag & TBCDRF_HILITEHOTTRACK )
{
COLORREF oldclr;
oldclr = SetBkColor(hdc, tbcd.clrHighlightHotTrack);
ExtTextOutW(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, 0);
if (hasDropDownArrow)
ExtTextOutW(hdc, 0, 0, ETO_OPAQUE, &rcArrow, NULL, 0, 0);
SetBkColor(hdc, oldclr);
}
}
if (theme)
{
int partId = drawSepDropDownArrow ? TP_SPLITBUTTON : TP_BUTTON;
int stateId = TS_NORMAL;
if (tbcd.nmcd.uItemState & CDIS_DISABLED)
stateId = TS_DISABLED;
else if (tbcd.nmcd.uItemState & CDIS_SELECTED)
stateId = TS_PRESSED;
else if (tbcd.nmcd.uItemState & CDIS_CHECKED)
stateId = (tbcd.nmcd.uItemState & CDIS_HOT) ? TS_HOTCHECKED : TS_HOT;
else if ((tbcd.nmcd.uItemState & CDIS_HOT)
|| (drawSepDropDownArrow && btnPtr->bDropDownPressed))
stateId = TS_HOT;
DrawThemeBackground (theme, hdc, partId, stateId, &tbcd.nmcd.rc, NULL);
}
else
TOOLBAR_DrawFrame(infoPtr, &tbcd, dwItemCDFlag);
if (drawSepDropDownArrow)
{
if (theme)
{
int stateId = TS_NORMAL;
if (tbcd.nmcd.uItemState & CDIS_DISABLED)
stateId = TS_DISABLED;
else if (btnPtr->bDropDownPressed || (tbcd.nmcd.uItemState & CDIS_SELECTED))
stateId = TS_PRESSED;
else if (tbcd.nmcd.uItemState & CDIS_CHECKED)
stateId = (tbcd.nmcd.uItemState & CDIS_HOT) ? TS_HOTCHECKED : TS_HOT;
else if (tbcd.nmcd.uItemState & CDIS_HOT)
stateId = TS_HOT;
DrawThemeBackground (theme, hdc, TP_DROPDOWNBUTTON, stateId, &rcArrow, NULL);
DrawThemeBackground (theme, hdc, TP_SPLITBUTTONDROPDOWN, stateId, &rcArrow, NULL);
}
else
TOOLBAR_DrawSepDDArrow(infoPtr, &tbcd, &rcArrow, btnPtr->bDropDownPressed, dwItemCDFlag);
}
oldBkMode = SetBkMode (hdc, tbcd.nStringBkMode);
if (!(infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) || (btnPtr->fsStyle & BTNS_SHOWTEXT))
TOOLBAR_DrawString (infoPtr, &rcText, lpText, &tbcd, dwItemCDFlag);
SetBkMode (hdc, oldBkMode);
TOOLBAR_DrawImage(infoPtr, btnPtr, rcBitmap.left, rcBitmap.top, &tbcd, dwItemCDFlag);
if (hasDropDownArrow && !drawSepDropDownArrow)
{
if (tbcd.nmcd.uItemState & (CDIS_DISABLED | CDIS_INDETERMINATE))
{
TOOLBAR_DrawArrow(hdc, rcArrow.left+1, rcArrow.top+1 + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnHighlight);
TOOLBAR_DrawArrow(hdc, rcArrow.left, rcArrow.top + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clr3dShadow);
}
else if (tbcd.nmcd.uItemState & (CDIS_SELECTED | CDIS_CHECKED))
{
offset = (dwItemCDFlag & TBCDRF_NOOFFSET) ? 0 : 1;
TOOLBAR_DrawArrow(hdc, rcArrow.left + offset, rcArrow.top + offset + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnText);
}
else
TOOLBAR_DrawArrow(hdc, rcArrow.left, rcArrow.top + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnText);
}
if (dwItemCustDraw & CDRF_NOTIFYPOSTPAINT)
{
tbcd.nmcd.dwDrawStage = CDDS_ITEMPOSTPAINT;
TOOLBAR_SendNotify(&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
}
}
static void
TOOLBAR_Refresh (TOOLBAR_INFO *infoPtr, HDC hdc, const PAINTSTRUCT *ps)
{
TBUTTON_INFO *btnPtr;
INT i;
RECT rcTemp, rcClient;
NMTBCUSTOMDRAW tbcd;
DWORD ntfret;
DWORD dwBaseCustDraw;
/* the app has told us not to redraw the toolbar */
if (!infoPtr->bDoRedraw)
return;
/* if imagelist belongs to the app, it can be changed
by the app after setting it */
if (GETDEFIMAGELIST(infoPtr, 0) != infoPtr->himlInt)
{
infoPtr->nNumBitmaps = 0;
for (i = 0; i < infoPtr->cimlDef; i++)
infoPtr->nNumBitmaps += ImageList_GetImageCount(infoPtr->himlDef[i]->himl);
}
TOOLBAR_DumpToolbar (infoPtr, __LINE__);
/* change the imagelist icon size if we manage the list and it is necessary */
TOOLBAR_CheckImageListIconSize(infoPtr);
/* Send initial notify */
ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
tbcd.nmcd.dwDrawStage = CDDS_PREPAINT;
tbcd.nmcd.hdc = hdc;
tbcd.nmcd.rc = ps->rcPaint;
ntfret = TOOLBAR_SendNotify(&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
dwBaseCustDraw = ntfret & 0xffff;
GetClientRect(infoPtr->hwndSelf, &rcClient);
/* redraw necessary buttons */
btnPtr = infoPtr->buttons;
for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++)
{
BOOL bDraw;
if (!RectVisible(hdc, &btnPtr->rect))
continue;
if (infoPtr->dwExStyle & TBSTYLE_EX_HIDECLIPPEDBUTTONS)
{
IntersectRect(&rcTemp, &rcClient, &btnPtr->rect);
bDraw = EqualRect(&rcTemp, &btnPtr->rect);
}
else
bDraw = TRUE;
bDraw &= IntersectRect(&rcTemp, &(ps->rcPaint), &(btnPtr->rect));
bDraw = (btnPtr->fsState & TBSTATE_HIDDEN) ? FALSE : bDraw;
if (bDraw)
TOOLBAR_DrawButton(infoPtr, btnPtr, hdc, dwBaseCustDraw);
}
/* draw insert mark if required */
if (infoPtr->tbim.iButton != -1)
{
RECT rcButton = infoPtr->buttons[infoPtr->tbim.iButton].rect;
RECT rcInsertMark;
rcInsertMark.top = rcButton.top;
rcInsertMark.bottom = rcButton.bottom;
if (infoPtr->tbim.dwFlags & TBIMHT_AFTER)
rcInsertMark.left = rcInsertMark.right = rcButton.right;
else
rcInsertMark.left = rcInsertMark.right = rcButton.left - INSERTMARK_WIDTH;
COMCTL32_DrawInsertMark(hdc, &rcInsertMark, infoPtr->clrInsertMark, FALSE);
}
if (dwBaseCustDraw & CDRF_NOTIFYPOSTPAINT)
{
ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
tbcd.nmcd.dwDrawStage = CDDS_POSTPAINT;
tbcd.nmcd.hdc = hdc;
tbcd.nmcd.rc = ps->rcPaint;
TOOLBAR_SendNotify(&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
}
}
/***********************************************************************
* TOOLBAR_MeasureString
*
* This function gets the width and height of a string in pixels. This
* is done first by using GetTextExtentPoint to get the basic width
* and height. The DrawText is called with DT_CALCRECT to get the exact
* width. The reason is because the text may have more than one "&" (or
* prefix characters as M$ likes to call them). The prefix character
* indicates where the underline goes, except for the string "&&" which
* is reduced to a single "&". GetTextExtentPoint does not process these
* only DrawText does. Note that the BTNS_NOPREFIX is handled here.
*/
static void
TOOLBAR_MeasureString(const TOOLBAR_INFO *infoPtr, const TBUTTON_INFO *btnPtr,
HDC hdc, LPSIZE lpSize)
{
RECT myrect;
lpSize->cx = 0;
lpSize->cy = 0;
if (infoPtr->nMaxTextRows > 0 &&
!(btnPtr->fsState & TBSTATE_HIDDEN) &&
(!(infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) ||
(btnPtr->fsStyle & BTNS_SHOWTEXT)) )
{
LPWSTR lpText = TOOLBAR_GetText(infoPtr, btnPtr);
if(lpText != NULL) {
/* first get size of all the text */
GetTextExtentPoint32W (hdc, lpText, strlenW (lpText), lpSize);
/* feed above size into the rectangle for DrawText */
myrect.left = myrect.top = 0;
myrect.right = lpSize->cx;
myrect.bottom = lpSize->cy;
/* Use DrawText to get true size as drawn (less pesky "&") */
DrawTextW (hdc, lpText, -1, &myrect, DT_VCENTER | DT_SINGLELINE |
DT_CALCRECT | ((btnPtr->fsStyle & BTNS_NOPREFIX) ?
DT_NOPREFIX : 0));
/* feed back to caller */
lpSize->cx = myrect.right;
lpSize->cy = myrect.bottom;
}
}
TRACE("string size %d x %d!\n", lpSize->cx, lpSize->cy);
}
/***********************************************************************
* TOOLBAR_CalcStrings
*
* This function walks through each string and measures it and returns
* the largest height and width to caller.
*/
static void
TOOLBAR_CalcStrings (const TOOLBAR_INFO *infoPtr, LPSIZE lpSize)
{
TBUTTON_INFO *btnPtr;
INT i;
SIZE sz;
HDC hdc;
HFONT hOldFont;
lpSize->cx = 0;
lpSize->cy = 0;
if (infoPtr->nMaxTextRows == 0)
return;
hdc = GetDC (infoPtr->hwndSelf);
hOldFont = SelectObject (hdc, infoPtr->hFont);
if (infoPtr->nNumButtons == 0 && infoPtr->nNumStrings > 0)
{
TEXTMETRICW tm;
GetTextMetricsW(hdc, &tm);
lpSize->cy = tm.tmHeight;
}
btnPtr = infoPtr->buttons;
for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
if(TOOLBAR_HasText(infoPtr, btnPtr))
{
TOOLBAR_MeasureString(infoPtr, btnPtr, hdc, &sz);
if (sz.cx > lpSize->cx)
lpSize->cx = sz.cx;
if (sz.cy > lpSize->cy)
lpSize->cy = sz.cy;
}
}
SelectObject (hdc, hOldFont);
ReleaseDC (infoPtr->hwndSelf, hdc);
TRACE("max string size %d x %d!\n", lpSize->cx, lpSize->cy);
}
/***********************************************************************
* TOOLBAR_WrapToolbar
*
* This function walks through the buttons and separators in the
* toolbar, and sets the TBSTATE_WRAP flag only on those items where
* wrapping should occur based on the width of the toolbar window.
* It does *not* calculate button placement itself. That task
* takes place in TOOLBAR_CalcToolbar. If the program wants to manage
* the toolbar wrapping on its own, it can use the TBSTYLE_WRAPABLE
* flag, and set the TBSTATE_WRAP flags manually on the appropriate items.
*
* Note: TBSTYLE_WRAPABLE or TBSTYLE_EX_UNDOC1 can be used also to allow
* vertical toolbar lists.
*/
static void
TOOLBAR_WrapToolbar(TOOLBAR_INFO *infoPtr)
{
TBUTTON_INFO *btnPtr;
INT x, cx, i, j;
RECT rc;
BOOL bButtonWrap;
/* When the toolbar window style is not TBSTYLE_WRAPABLE, */
/* no layout is necessary. Applications may use this style */
/* to perform their own layout on the toolbar. */
if( !(infoPtr->dwStyle & TBSTYLE_WRAPABLE) &&
!(infoPtr->dwExStyle & TBSTYLE_EX_UNDOC1) ) return;
btnPtr = infoPtr->buttons;
x = infoPtr->nIndent;
if (GetParent(infoPtr->hwndSelf))
{
/* this can get the parents width, to know how far we can extend
* this toolbar. We cannot use its height, as there may be multiple
* toolbars in a rebar control
*/
GetClientRect( GetParent(infoPtr->hwndSelf), &rc );
infoPtr->nWidth = rc.right - rc.left;
}
else
{
GetWindowRect( infoPtr->hwndSelf, &rc );
infoPtr->nWidth = rc.right - rc.left;
}
bButtonWrap = FALSE;
TRACE("start ButtonWidth=%d, BitmapWidth=%d, nWidth=%d, nIndent=%d\n",
infoPtr->nButtonWidth, infoPtr->nBitmapWidth, infoPtr->nWidth,
infoPtr->nIndent);
for (i = 0; i < infoPtr->nNumButtons; i++ )
{
btnPtr[i].fsState &= ~TBSTATE_WRAP;
if (btnPtr[i].fsState & TBSTATE_HIDDEN)
continue;
if (btnPtr[i].cx > 0)
cx = btnPtr[i].cx;
/* horizontal separators are treated as buttons for width */
else if ((btnPtr[i].fsStyle & BTNS_SEP) &&
!(infoPtr->dwStyle & CCS_VERT))
cx = (btnPtr[i].iBitmap > 0) ? btnPtr[i].iBitmap : SEPARATOR_WIDTH;
else
cx = infoPtr->nButtonWidth;
/* Two or more adjacent separators form a separator group. */
/* The first separator in a group should be wrapped to the */
/* next row if the previous wrapping is on a button. */
if( bButtonWrap &&
(btnPtr[i].fsStyle & BTNS_SEP) &&
(i + 1 < infoPtr->nNumButtons ) &&
(btnPtr[i + 1].fsStyle & BTNS_SEP) )
{
TRACE("wrap point 1 btn %d style %02x\n", i, btnPtr[i].fsStyle);
btnPtr[i].fsState |= TBSTATE_WRAP;
x = infoPtr->nIndent;
i++;
bButtonWrap = FALSE;
continue;
}
/* The layout makes sure the bitmap is visible, but not the button. */
/* Test added to also wrap after a button that starts a row but */
/* is bigger than the area. - GA 8/01 */
if (( x + cx - (infoPtr->nButtonWidth - infoPtr->nBitmapWidth) / 2
> infoPtr->nWidth ) ||
((x == infoPtr->nIndent) && (cx > infoPtr->nWidth)))
{
BOOL bFound = FALSE;
/* If the current button is a separator and not hidden, */
/* go to the next until it reaches a non separator. */
/* Wrap the last separator if it is before a button. */
while( ( ((btnPtr[i].fsStyle & BTNS_SEP) &&
!(btnPtr[i].fsStyle & BTNS_DROPDOWN)) ||
(btnPtr[i].fsState & TBSTATE_HIDDEN) ) &&
i < infoPtr->nNumButtons )
{
i++;
bFound = TRUE;
}
if( bFound && i < infoPtr->nNumButtons )
{
i--;
TRACE("wrap point 2 btn %d style %02x, x=%d, cx=%d\n",
i, btnPtr[i].fsStyle, x, cx);
btnPtr[i].fsState |= TBSTATE_WRAP;
x = infoPtr->nIndent;
bButtonWrap = FALSE;
continue;
}
else if ( i >= infoPtr->nNumButtons)
break;
/* If the current button is not a separator, find the last */
/* separator and wrap it. */
for ( j = i - 1; j >= 0 && !(btnPtr[j].fsState & TBSTATE_WRAP); j--)
{
if ((btnPtr[j].fsStyle & BTNS_SEP) &&
!(btnPtr[j].fsState & TBSTATE_HIDDEN))
{
bFound = TRUE;
i = j;
TRACE("wrap point 3 btn %d style %02x, x=%d, cx=%d\n",
i, btnPtr[i].fsStyle, x, cx);
x = infoPtr->nIndent;
btnPtr[j].fsState |= TBSTATE_WRAP;
bButtonWrap = FALSE;
break;
}
}
/* If no separator available for wrapping, wrap one of */
/* non-hidden previous button. */
if (!bFound)
{
for ( j = i - 1;
j >= 0 && !(btnPtr[j].fsState & TBSTATE_WRAP); j--)
{
if (btnPtr[j].fsState & TBSTATE_HIDDEN)
continue;
bFound = TRUE;
i = j;
TRACE("wrap point 4 btn %d style %02x, x=%d, cx=%d\n",
i, btnPtr[i].fsStyle, x, cx);
x = infoPtr->nIndent;
btnPtr[j].fsState |= TBSTATE_WRAP;
bButtonWrap = TRUE;
break;
}
}
/* If all above failed, wrap the current button. */
if (!bFound)
{
TRACE("wrap point 5 btn %d style %02x, x=%d, cx=%d\n",
i, btnPtr[i].fsStyle, x, cx);
btnPtr[i].fsState |= TBSTATE_WRAP;
x = infoPtr->nIndent;
if (btnPtr[i].fsStyle & BTNS_SEP )
bButtonWrap = FALSE;
else
bButtonWrap = TRUE;
}
}
else {
TRACE("wrap point 6 btn %d style %02x, x=%d, cx=%d\n",
i, btnPtr[i].fsStyle, x, cx);
x += cx;
}
}
}
/***********************************************************************
* TOOLBAR_MeasureButton
*
* Calculates the width and height required for a button. Used in
* TOOLBAR_CalcToolbar to set the all-button width and height and also for
* the width of buttons that are autosized.
*
* Note that it would have been rather elegant to use one piece of code for
* both the laying out of the toolbar and for controlling where button parts
* are drawn, but the native control has inconsistencies between the two that
* prevent this from being effectively. These inconsistencies can be seen as
* artefacts where parts of the button appear outside of the bounding button
* rectangle.
*
* There are several cases for the calculation of the button dimensions and
* button part positioning:
*
* List
* ====
*
* With Bitmap:
*
* +--------------------------------------------------------+ ^
* | ^ ^ | |
* | | pad.cy / 2 | centered | |
* | pad.cx/2 + cxedge +--------------+ +------------+ | | DEFPAD_CY +
* |<----------------->| nBitmapWidth | | Text | | | max(nBitmapHeight, szText.cy)
* | |<------------>| | | | |
* | +--------------+ +------------+ | |
* |<-------------------------------------->| | |
* | cxedge + iListGap + nBitmapWidth + 2 |<-----------> | |
* | szText.cx | |
* +--------------------------------------------------------+ -
* <-------------------------------------------------------->
* 2*cxedge + nBitmapWidth + iListGap + szText.cx + pad.cx
*
* Without Bitmap (I_IMAGENONE):
*
* +-----------------------------------+ ^
* | ^ | |
* | | centered | | LISTPAD_CY +
* | +------------+ | | szText.cy
* | | Text | | |
* | | | | |
* | +------------+ | |
* |<----------------->| | |
* | cxedge |<-----------> | |
* | szText.cx | |
* +-----------------------------------+ -
* <----------------------------------->
* szText.cx + pad.cx
*
* Without text:
*
* +--------------------------------------+ ^
* | ^ | |
* | | padding.cy/2 | | DEFPAD_CY +
* | +------------+ | | nBitmapHeight
* | | Bitmap | | |
* | | | | |
* | +------------+ | |
* |<------------------->| | |
* | cxedge + iListGap/2 |<-----------> | |
* | nBitmapWidth | |
* +--------------------------------------+ -
* <-------------------------------------->
* 2*cxedge + nBitmapWidth + iListGap
*
* Non-List
* ========
*
* With bitmap:
*
* +-----------------------------------+ ^
* | ^ | |
* | | pad.cy / 2 | | nBitmapHeight +
* | - | | szText.cy +
* | +------------+ | | DEFPAD_CY + 1
* | centered | Bitmap | | |
* |<----------------->| | | |
* | +------------+ | |
* | ^ | |
* | 1 | | |
* | - | |
* | centered +---------------+ | |
* |<--------------->| Text | | |
* | +---------------+ | |
* +-----------------------------------+ -
* <----------------------------------->
* pad.cx + max(nBitmapWidth, szText.cx)
*
* Without bitmaps (NULL imagelist or ImageList_GetImageCount() = 0):
*
* +---------------------------------------+ ^
* | ^ | |
* | | 2 + pad.cy / 2 | |
* | - | | szText.cy +
* | centered +-----------------+ | | pad.cy + 2
* |<--------------->| Text | | |
* | +-----------------+ | |
* | | |
* +---------------------------------------+ -
* <--------------------------------------->
* 2*cxedge + pad.cx + szText.cx
*
* Without text:
* As for with bitmaps, but with szText.cx zero.
*/
static inline SIZE TOOLBAR_MeasureButton(const TOOLBAR_INFO *infoPtr, SIZE sizeString,
BOOL bHasBitmap, BOOL bValidImageList)
{
SIZE sizeButton;
if (infoPtr->dwStyle & TBSTYLE_LIST)
{
/* set button height from bitmap / text height... */
sizeButton.cy = max((bHasBitmap ? infoPtr->nBitmapHeight : 0),
sizeString.cy);
/* ... add on the necessary padding */
if (bValidImageList)
{
if (bHasBitmap)
sizeButton.cy += DEFPAD_CY;
else
sizeButton.cy += LISTPAD_CY;
}
else
sizeButton.cy += infoPtr->szPadding.cy;
/* calculate button width */
sizeButton.cx = 2*GetSystemMetrics(SM_CXEDGE) +
infoPtr->nBitmapWidth + infoPtr->iListGap;
if (sizeString.cx > 0)
sizeButton.cx += sizeString.cx + infoPtr->szPadding.cx;
}
else
{
if (bHasBitmap)
{
sizeButton.cy = infoPtr->nBitmapHeight + DEFPAD_CY;
if (sizeString.cy > 0)
sizeButton.cy += 1 + sizeString.cy;
sizeButton.cx = infoPtr->szPadding.cx +
max(sizeString.cx, infoPtr->nBitmapWidth);
}
else
{
sizeButton.cy = sizeString.cy + infoPtr->szPadding.cy +
NONLIST_NOTEXT_OFFSET;
sizeButton.cx = infoPtr->szPadding.cx +
max(2*GetSystemMetrics(SM_CXEDGE) + sizeString.cx, infoPtr->nBitmapWidth);
}
}
return sizeButton;
}
/***********************************************************************
* TOOLBAR_CalcToolbar
*
* This function calculates button and separator placement. It first
* calculates the button sizes, gets the toolbar window width and then
* calls TOOLBAR_WrapToolbar to determine which buttons we need to wrap
* on. It assigns a new location to each item and sends this location to
* the tooltip window if appropriate. Finally, it updates the rcBound
* rect and calculates the new required toolbar window height.
*/
static void
TOOLBAR_CalcToolbar (TOOLBAR_INFO *infoPtr)
{
SIZE sizeString, sizeButton;
BOOL validImageList = FALSE;
TOOLBAR_CalcStrings (infoPtr, &sizeString);
TOOLBAR_DumpToolbar (infoPtr, __LINE__);
if (TOOLBAR_IsValidImageList(infoPtr, 0))
validImageList = TRUE;
sizeButton = TOOLBAR_MeasureButton(infoPtr, sizeString, TRUE, validImageList);
infoPtr->nButtonWidth = sizeButton.cx;
infoPtr->nButtonHeight = sizeButton.cy;
infoPtr->iTopMargin = default_top_margin(infoPtr);
if ( infoPtr->cxMin >= 0 && infoPtr->nButtonWidth < infoPtr->cxMin )
infoPtr->nButtonWidth = infoPtr->cxMin;
if ( infoPtr->cxMax > 0 && infoPtr->nButtonWidth > infoPtr->cxMax )
infoPtr->nButtonWidth = infoPtr->cxMax;
TOOLBAR_LayoutToolbar(infoPtr);
}
static void
TOOLBAR_LayoutToolbar(TOOLBAR_INFO *infoPtr)
{
TBUTTON_INFO *btnPtr;
SIZE sizeButton;
INT i, nRows, nSepRows;
INT x, y, cx, cy;
BOOL bWrap;
BOOL validImageList = TOOLBAR_IsValidImageList(infoPtr, 0);
BOOL hasDropDownArrows = TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle);
TOOLBAR_WrapToolbar(infoPtr);
x = infoPtr->nIndent;
y = infoPtr->iTopMargin;
cx = infoPtr->nButtonWidth;
cy = infoPtr->nButtonHeight;
nRows = nSepRows = 0;
infoPtr->rcBound.top = y;
infoPtr->rcBound.left = x;
infoPtr->rcBound.bottom = y + cy;
infoPtr->rcBound.right = x;
btnPtr = infoPtr->buttons;
TRACE("cy=%d\n", cy);
for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++ )
{
bWrap = FALSE;
if (btnPtr->fsState & TBSTATE_HIDDEN)
{
SetRectEmpty (&btnPtr->rect);
continue;
}
cy = infoPtr->nButtonHeight;
if (btnPtr->fsStyle & BTNS_SEP) {
if (infoPtr->dwStyle & CCS_VERT) {
cy = (btnPtr->iBitmap > 0) ? btnPtr->iBitmap : SEPARATOR_WIDTH;
cx = (btnPtr->cx > 0) ? btnPtr->cx : infoPtr->nWidth;
}
else
cx = (btnPtr->cx > 0) ? btnPtr->cx :
(btnPtr->iBitmap > 0) ? btnPtr->iBitmap : SEPARATOR_WIDTH;
}
else
{
if (btnPtr->cx)
cx = btnPtr->cx;
else if ((infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) ||
(btnPtr->fsStyle & BTNS_AUTOSIZE))
{
SIZE sz;
HDC hdc;
HFONT hOldFont;
hdc = GetDC (infoPtr->hwndSelf);
hOldFont = SelectObject (hdc, infoPtr->hFont);
TOOLBAR_MeasureString(infoPtr, btnPtr, hdc, &sz);
SelectObject (hdc, hOldFont);
ReleaseDC (infoPtr->hwndSelf, hdc);
sizeButton = TOOLBAR_MeasureButton(infoPtr, sz,
TOOLBAR_IsValidBitmapIndex(infoPtr, infoPtr->buttons[i].iBitmap),
validImageList);
cx = sizeButton.cx;
}
else
cx = infoPtr->nButtonWidth;
/* if size has been set manually then don't add on extra space
* for the drop down arrow */
if (!btnPtr->cx && hasDropDownArrows &&
((btnPtr->fsStyle & BTNS_DROPDOWN) || (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN)))
cx += DDARROW_WIDTH;
}
if (btnPtr->fsState & TBSTATE_WRAP )
bWrap = TRUE;
SetRect (&btnPtr->rect, x, y, x + cx, y + cy);
if (infoPtr->rcBound.left > x)
infoPtr->rcBound.left = x;
if (infoPtr->rcBound.right < x + cx)
infoPtr->rcBound.right = x + cx;
if (infoPtr->rcBound.bottom < y + cy)
infoPtr->rcBound.bottom = y + cy;
TOOLBAR_TooltipSetRect(infoPtr, btnPtr);
/* btnPtr->nRow is zero based. The space between the rows is */
/* also considered as a row. */
btnPtr->nRow = nRows + nSepRows;
TRACE("button %d style=%x, bWrap=%d, nRows=%d, nSepRows=%d, btnrow=%d, (%d,%d)-(%d,%d)\n",
i, btnPtr->fsStyle, bWrap, nRows, nSepRows, btnPtr->nRow,
x, y, x+cx, y+cy);
if( bWrap )
{
if ( !(btnPtr->fsStyle & BTNS_SEP) )
y += cy;
else
{
if ( !(infoPtr->dwStyle & CCS_VERT))
y += cy + ( (btnPtr->cx > 0 ) ?
btnPtr->cx : SEPARATOR_WIDTH) * 2 /3;
else
y += cy;
/* nSepRows is used to calculate the extra height following */
/* the last row. */
nSepRows++;
}
x = infoPtr->nIndent;
/* Increment row number unless this is the last button */
/* and it has Wrap set. */
if (i != infoPtr->nNumButtons-1)
nRows++;
}
else
x += cx;
}
/* infoPtr->nRows is the number of rows on the toolbar */
infoPtr->nRows = nRows + nSepRows + 1;
TRACE("toolbar button width %d\n", infoPtr->nButtonWidth);
}
static INT
TOOLBAR_InternalHitTest (const TOOLBAR_INFO *infoPtr, const POINT *lpPt, BOOL *button)
{
TBUTTON_INFO *btnPtr;
INT i;
if (button)
*button = FALSE;
btnPtr = infoPtr->buttons;
for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
if (btnPtr->fsState & TBSTATE_HIDDEN)
continue;
if (btnPtr->fsStyle & BTNS_SEP) {
if (PtInRect (&btnPtr->rect, *lpPt)) {
TRACE(" ON SEPARATOR %d!\n", i);
return -i;
}
}
else {
if (PtInRect (&btnPtr->rect, *lpPt)) {
TRACE(" ON BUTTON %d!\n", i);
if (button)
*button = TRUE;
return i;
}
}
}
TRACE(" NOWHERE!\n");
return TOOLBAR_NOWHERE;
}
/* worker for TB_ADDBUTTONS and TB_INSERTBUTTON */
static BOOL
TOOLBAR_InternalInsertButtonsT(TOOLBAR_INFO *infoPtr, INT iIndex, UINT nAddButtons, const TBBUTTON *lpTbb, BOOL fUnicode)
{
INT nOldButtons, nNewButtons, iButton;
BOOL fHasString = FALSE;
if (iIndex < 0) /* iIndex can be negative, what means adding at the end */
iIndex = infoPtr->nNumButtons;
nOldButtons = infoPtr->nNumButtons;
nNewButtons = nOldButtons + nAddButtons;
infoPtr->buttons = ReAlloc(infoPtr->buttons, sizeof(TBUTTON_INFO)*nNewButtons);
memmove(&infoPtr->buttons[iIndex + nAddButtons], &infoPtr->buttons[iIndex],
(nOldButtons - iIndex) * sizeof(TBUTTON_INFO));
infoPtr->nNumButtons += nAddButtons;
/* insert new buttons data */
for (iButton = 0; iButton < nAddButtons; iButton++) {
TBUTTON_INFO *btnPtr = &infoPtr->buttons[iIndex + iButton];
TOOLBAR_DumpTBButton(lpTbb + iButton, fUnicode);
ZeroMemory(btnPtr, sizeof(*btnPtr));
btnPtr->iBitmap = lpTbb[iButton].iBitmap;
btnPtr->idCommand = lpTbb[iButton].idCommand;
btnPtr->fsState = lpTbb[iButton].fsState;
btnPtr->fsStyle = lpTbb[iButton].fsStyle;
btnPtr->dwData = lpTbb[iButton].dwData;
if (btnPtr->fsStyle & BTNS_SEP)
btnPtr->iString = -1;
else if(!IS_INTRESOURCE(lpTbb[iButton].iString) && lpTbb[iButton].iString != -1)
{
if (fUnicode)
Str_SetPtrW((LPWSTR*)&btnPtr->iString, (LPWSTR)lpTbb[iButton].iString );
else
Str_SetPtrAtoW((LPWSTR*)&btnPtr->iString, (LPSTR)lpTbb[iButton].iString);
fHasString = TRUE;
}
else
btnPtr->iString = lpTbb[iButton].iString;
TOOLBAR_TooltipAddTool(infoPtr, btnPtr);
}
if (infoPtr->nNumStrings > 0 || fHasString)
TOOLBAR_CalcToolbar(infoPtr);
else
TOOLBAR_LayoutToolbar(infoPtr);
TOOLBAR_AutoSize(infoPtr);
TOOLBAR_DumpToolbar(infoPtr, __LINE__);
InvalidateRect(infoPtr->hwndSelf, NULL, TRUE);
return TRUE;
}
static INT
TOOLBAR_GetButtonIndex (const TOOLBAR_INFO *infoPtr, INT idCommand, BOOL CommandIsIndex)
{
TBUTTON_INFO *btnPtr;
INT i;
if (CommandIsIndex) {
TRACE("command is really index command=%d\n", idCommand);
if (idCommand >= infoPtr->nNumButtons) return -1;
return idCommand;
}
btnPtr = infoPtr->buttons;
for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
if (btnPtr->idCommand == idCommand) {
TRACE("command=%d index=%d\n", idCommand, i);
return i;
}
}
TRACE("no index found for command=%d\n", idCommand);
return -1;
}
static INT
TOOLBAR_GetCheckedGroupButtonIndex (const TOOLBAR_INFO *infoPtr, INT nIndex)
{
TBUTTON_INFO *btnPtr;
INT nRunIndex;
if ((nIndex < 0) || (nIndex > infoPtr->nNumButtons))
return -1;
/* check index button */
btnPtr = &infoPtr->buttons[nIndex];
if ((btnPtr->fsStyle & BTNS_CHECKGROUP) == BTNS_CHECKGROUP) {
if (btnPtr->fsState & TBSTATE_CHECKED)
return nIndex;
}
/* check previous buttons */
nRunIndex = nIndex - 1;
while (nRunIndex >= 0) {
btnPtr = &infoPtr->buttons[nRunIndex];
if ((btnPtr->fsStyle & BTNS_GROUP) == BTNS_GROUP) {
if (btnPtr->fsState & TBSTATE_CHECKED)
return nRunIndex;
}
else
break;
nRunIndex--;
}
/* check next buttons */
nRunIndex = nIndex + 1;
while (nRunIndex < infoPtr->nNumButtons) {
btnPtr = &infoPtr->buttons[nRunIndex];
if ((btnPtr->fsStyle & BTNS_GROUP) == BTNS_GROUP) {
if (btnPtr->fsState & TBSTATE_CHECKED)
return nRunIndex;
}
else
break;
nRunIndex++;
}
return -1;
}
static VOID
TOOLBAR_RelayEvent (HWND hwndTip, HWND hwndMsg, UINT uMsg,
WPARAM wParam, LPARAM lParam)
{
MSG msg;
msg.hwnd = hwndMsg;
msg.message = uMsg;
msg.wParam = wParam;
msg.lParam = lParam;
msg.time = GetMessageTime ();
msg.pt.x = (short)LOWORD(GetMessagePos ());
msg.pt.y = (short)HIWORD(GetMessagePos ());
SendMessageW (hwndTip, TTM_RELAYEVENT, 0, (LPARAM)&msg);
}
static void
TOOLBAR_TooltipAddTool(const TOOLBAR_INFO *infoPtr, const TBUTTON_INFO *button)
{
if (infoPtr->hwndToolTip && !(button->fsStyle & BTNS_SEP)) {
TTTOOLINFOW ti;
ZeroMemory(&ti, sizeof(TTTOOLINFOW));
ti.cbSize = sizeof (TTTOOLINFOW);
ti.hwnd = infoPtr->hwndSelf;
ti.uId = button->idCommand;
ti.hinst = 0;
ti.lpszText = LPSTR_TEXTCALLBACKW;
/* ti.lParam = random value from the stack? */
SendMessageW(infoPtr->hwndToolTip, TTM_ADDTOOLW,
0, (LPARAM)&ti);
}
}
static void
TOOLBAR_TooltipDelTool(const TOOLBAR_INFO *infoPtr, const TBUTTON_INFO *button)
{
if ((infoPtr->hwndToolTip) && !(button->fsStyle & BTNS_SEP)) {
TTTOOLINFOW ti;
ZeroMemory(&ti, sizeof(ti));
ti.cbSize = sizeof(ti);
ti.hwnd = infoPtr->hwndSelf;
ti.uId = button->idCommand;
SendMessageW(infoPtr->hwndToolTip, TTM_DELTOOLW, 0, (LPARAM)&ti);
}
}
static void TOOLBAR_TooltipSetRect(const TOOLBAR_INFO *infoPtr, const TBUTTON_INFO *button)
{
/* Set the toolTip only for non-hidden, non-separator button */
if (infoPtr->hwndToolTip && !(button->fsStyle & BTNS_SEP))
{
TTTOOLINFOW ti;
ZeroMemory(&ti, sizeof(ti));
ti.cbSize = sizeof(ti);
ti.hwnd = infoPtr->hwndSelf;
ti.uId = button->idCommand;
ti.rect = button->rect;
SendMessageW(infoPtr->hwndToolTip, TTM_NEWTOOLRECTW, 0, (LPARAM)&ti);
}
}
/* Creates the tooltip control */
static void
TOOLBAR_TooltipCreateControl(TOOLBAR_INFO *infoPtr)
{
int i;
NMTOOLTIPSCREATED nmttc;
infoPtr->hwndToolTip = CreateWindowExW(0, TOOLTIPS_CLASSW, NULL, WS_POPUP,
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
infoPtr->hwndSelf, 0, 0, 0);
if (!infoPtr->hwndToolTip)
return;
/* Send NM_TOOLTIPSCREATED notification */
nmttc.hwndToolTips = infoPtr->hwndToolTip;
TOOLBAR_SendNotify(&nmttc.hdr, infoPtr, NM_TOOLTIPSCREATED);
for (i = 0; i < infoPtr->nNumButtons; i++)
{
TOOLBAR_TooltipAddTool(infoPtr, &infoPtr->buttons[i]);
TOOLBAR_TooltipSetRect(infoPtr, &infoPtr->buttons[i]);
}
}
/* keeps available button list box sorted by button id */
static void TOOLBAR_Cust_InsertAvailButton(HWND hwnd, PCUSTOMBUTTON btnInfoNew)
{
int i;
int count;
PCUSTOMBUTTON btnInfo;
HWND hwndAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
TRACE("button %s, idCommand %d\n", debugstr_w(btnInfoNew->text), btnInfoNew->btn.idCommand);
count = SendMessageW(hwndAvail, LB_GETCOUNT, 0, 0);
/* position 0 is always separator */
for (i = 1; i < count; i++)
{
btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndAvail, LB_GETITEMDATA, i, 0);
if (btnInfoNew->btn.idCommand < btnInfo->btn.idCommand)
{
i = SendMessageW(hwndAvail, LB_INSERTSTRING, i, 0);
SendMessageW(hwndAvail, LB_SETITEMDATA, i, (LPARAM)btnInfoNew);
return;
}
}
/* id higher than all others add to end */
i = SendMessageW(hwndAvail, LB_ADDSTRING, 0, 0);
SendMessageW(hwndAvail, LB_SETITEMDATA, i, (LPARAM)btnInfoNew);
}
static void TOOLBAR_Cust_MoveButton(const CUSTDLG_INFO *custInfo, HWND hwnd, INT nIndexFrom, INT nIndexTo)
{
NMTOOLBARW nmtb;
TRACE("index from %d, index to %d\n", nIndexFrom, nIndexTo);
if (nIndexFrom == nIndexTo)
return;
/* MSDN states that iItem is the index of the button, rather than the
* command ID as used by every other NMTOOLBAR notification */
nmtb.iItem = nIndexFrom;
if (TOOLBAR_SendNotify(&nmtb.hdr, custInfo->tbInfo, TBN_QUERYINSERT))
{
PCUSTOMBUTTON btnInfo;
NMHDR hdr;
HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
int count = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndList, LB_GETITEMDATA, nIndexFrom, 0);
SendMessageW(hwndList, LB_DELETESTRING, nIndexFrom, 0);
SendMessageW(hwndList, LB_INSERTSTRING, nIndexTo, 0);
SendMessageW(hwndList, LB_SETITEMDATA, nIndexTo, (LPARAM)btnInfo);
SendMessageW(hwndList, LB_SETCURSEL, nIndexTo, 0);
if (nIndexTo <= 0)
EnableWindow(GetDlgItem(hwnd,IDC_MOVEUP_BTN), FALSE);
else
EnableWindow(GetDlgItem(hwnd,IDC_MOVEUP_BTN), TRUE);
/* last item is always separator, so -2 instead of -1 */
if (nIndexTo >= (count - 2))
EnableWindow(GetDlgItem(hwnd,IDC_MOVEDN_BTN), FALSE);
else
EnableWindow(GetDlgItem(hwnd,IDC_MOVEDN_BTN), TRUE);
SendMessageW(custInfo->tbHwnd, TB_DELETEBUTTON, nIndexFrom, 0);
SendMessageW(custInfo->tbHwnd, TB_INSERTBUTTONW, nIndexTo, (LPARAM)&(btnInfo->btn));
TOOLBAR_SendNotify(&hdr, custInfo->tbInfo, TBN_TOOLBARCHANGE);
}
}
static void TOOLBAR_Cust_AddButton(const CUSTDLG_INFO *custInfo, HWND hwnd, INT nIndexAvail, INT nIndexTo)
{
NMTOOLBARW nmtb;
TRACE("Add: nIndexAvail %d, nIndexTo %d\n", nIndexAvail, nIndexTo);
/* MSDN states that iItem is the index of the button, rather than the
* command ID as used by every other NMTOOLBAR notification */
nmtb.iItem = nIndexAvail;
if (TOOLBAR_SendNotify(&nmtb.hdr, custInfo->tbInfo, TBN_QUERYINSERT))
{
PCUSTOMBUTTON btnInfo;
NMHDR hdr;
HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
HWND hwndAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
int count = SendMessageW(hwndAvail, LB_GETCOUNT, 0, 0);
btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndAvail, LB_GETITEMDATA, nIndexAvail, 0);
if (nIndexAvail != 0) /* index == 0 indicates separator */
{
/* remove from 'available buttons' list */
SendMessageW(hwndAvail, LB_DELETESTRING, nIndexAvail, 0);
if (nIndexAvail == count-1)
SendMessageW(hwndAvail, LB_SETCURSEL, nIndexAvail-1 , 0);
else
SendMessageW(hwndAvail, LB_SETCURSEL, nIndexAvail , 0);
}
else
{
PCUSTOMBUTTON btnNew;
/* duplicate 'separator' button */
btnNew = Alloc(sizeof(CUSTOMBUTTON));
*btnNew = *btnInfo;
btnInfo = btnNew;
}
/* insert into 'toolbar button' list */
SendMessageW(hwndList, LB_INSERTSTRING, nIndexTo, 0);
SendMessageW(hwndList, LB_SETITEMDATA, nIndexTo, (LPARAM)btnInfo);
SendMessageW(custInfo->tbHwnd, TB_INSERTBUTTONW, nIndexTo, (LPARAM)&(btnInfo->btn));
TOOLBAR_SendNotify(&hdr, custInfo->tbInfo, TBN_TOOLBARCHANGE);
}
}
static void TOOLBAR_Cust_RemoveButton(const CUSTDLG_INFO *custInfo, HWND hwnd, INT index)
{
PCUSTOMBUTTON btnInfo;
HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
TRACE("Remove: index %d\n", index);
btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndList, LB_GETITEMDATA, index, 0);
/* send TBN_QUERYDELETE notification */
if (TOOLBAR_IsButtonRemovable(custInfo->tbInfo, index, btnInfo))
{
NMHDR hdr;
SendMessageW(hwndList, LB_DELETESTRING, index, 0);
SendMessageW(hwndList, LB_SETCURSEL, index , 0);
SendMessageW(custInfo->tbHwnd, TB_DELETEBUTTON, index, 0);
/* insert into 'available button' list */
if (!(btnInfo->btn.fsStyle & BTNS_SEP))
TOOLBAR_Cust_InsertAvailButton(hwnd, btnInfo);
else
Free(btnInfo);
TOOLBAR_SendNotify(&hdr, custInfo->tbInfo, TBN_TOOLBARCHANGE);
}
}
/* drag list notification function for toolbar buttons list box */
static LRESULT TOOLBAR_Cust_ToolbarDragListNotification(const CUSTDLG_INFO *custInfo, HWND hwnd,
const DRAGLISTINFO *pDLI)
{
HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
switch (pDLI->uNotification)
{
case DL_BEGINDRAG:
{
INT nCurrentItem = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
/* no dragging for last item (separator) */
if (nCurrentItem >= (nCount - 1)) return FALSE;
return TRUE;
}
case DL_DRAGGING:
{
INT nCurrentItem = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
/* no dragging past last item (separator) */
if ((nCurrentItem >= 0) && (nCurrentItem < (nCount - 1)))
{
DrawInsert(hwnd, hwndList, nCurrentItem);
/* FIXME: native uses "move button" cursor */
return DL_COPYCURSOR;
}
/* not over toolbar buttons list */
if (nCurrentItem < 0)
{
POINT ptWindow = pDLI->ptCursor;
HWND hwndListAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
MapWindowPoints(NULL, hwnd, &ptWindow, 1);
/* over available buttons list? */
if (ChildWindowFromPoint(hwnd, ptWindow) == hwndListAvail)
/* FIXME: native uses "move button" cursor */
return DL_COPYCURSOR;
}
/* clear drag arrow */
DrawInsert(hwnd, hwndList, -1);
return DL_STOPCURSOR;
}
case DL_DROPPED:
{
INT nIndexTo = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
INT nIndexFrom = SendMessageW(hwndList, LB_GETCURSEL, 0, 0);
INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
if ((nIndexTo >= 0) && (nIndexTo < (nCount - 1)))
{
/* clear drag arrow */
DrawInsert(hwnd, hwndList, -1);
/* move item */
TOOLBAR_Cust_MoveButton(custInfo, hwnd, nIndexFrom, nIndexTo);
}
/* not over toolbar buttons list */
if (nIndexTo < 0)
{
POINT ptWindow = pDLI->ptCursor;
HWND hwndListAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
MapWindowPoints(NULL, hwnd, &ptWindow, 1);
/* over available buttons list? */
if (ChildWindowFromPoint(hwnd, ptWindow) == hwndListAvail)
TOOLBAR_Cust_RemoveButton(custInfo, hwnd, nIndexFrom);
}
break;
}
case DL_CANCELDRAG:
/* Clear drag arrow */
DrawInsert(hwnd, hwndList, -1);
break;
}
return 0;
}
/* drag list notification function for available buttons list box */
static LRESULT TOOLBAR_Cust_AvailDragListNotification(const CUSTDLG_INFO *custInfo, HWND hwnd,
const DRAGLISTINFO *pDLI)
{
HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
switch (pDLI->uNotification)
{
case DL_BEGINDRAG:
return TRUE;
case DL_DRAGGING:
{
INT nCurrentItem = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
/* no dragging past last item (separator) */
if ((nCurrentItem >= 0) && (nCurrentItem < nCount))
{
DrawInsert(hwnd, hwndList, nCurrentItem);
/* FIXME: native uses "move button" cursor */
return DL_COPYCURSOR;
}
/* not over toolbar buttons list */
if (nCurrentItem < 0)
{
POINT ptWindow = pDLI->ptCursor;
HWND hwndListAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
MapWindowPoints(NULL, hwnd, &ptWindow, 1);
/* over available buttons list? */
if (ChildWindowFromPoint(hwnd, ptWindow) == hwndListAvail)
/* FIXME: native uses "move button" cursor */
return DL_COPYCURSOR;
}
/* clear drag arrow */
DrawInsert(hwnd, hwndList, -1);
return DL_STOPCURSOR;
}
case DL_DROPPED:
{
INT nIndexTo = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
INT nIndexFrom = SendDlgItemMessageW(hwnd, IDC_AVAILBTN_LBOX, LB_GETCURSEL, 0, 0);
if ((nIndexTo >= 0) && (nIndexTo < nCount))
{
/* clear drag arrow */
DrawInsert(hwnd, hwndList, -1);
/* add item */
TOOLBAR_Cust_AddButton(custInfo, hwnd, nIndexFrom, nIndexTo);
}
}
case DL_CANCELDRAG:
/* Clear drag arrow */
DrawInsert(hwnd, hwndList, -1);
break;
}
return 0;
}
extern UINT uDragListMessage DECLSPEC_HIDDEN;
/***********************************************************************
* TOOLBAR_CustomizeDialogProc
* This function implements the toolbar customization dialog.
*/
static INT_PTR CALLBACK
TOOLBAR_CustomizeDialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
PCUSTDLG_INFO custInfo = (PCUSTDLG_INFO)GetWindowLongPtrW (hwnd, DWLP_USER);
PCUSTOMBUTTON btnInfo;
NMTOOLBARA nmtb;
TOOLBAR_INFO *infoPtr = custInfo ? custInfo->tbInfo : NULL;
switch (uMsg)
{
case WM_INITDIALOG:
custInfo = (PCUSTDLG_INFO)lParam;
SetWindowLongPtrW (hwnd, DWLP_USER, (LONG_PTR)custInfo);
if (custInfo)
{
WCHAR Buffer[256];
int i = 0;
int index;
NMTBINITCUSTOMIZE nmtbic;
infoPtr = custInfo->tbInfo;
/* send TBN_QUERYINSERT notification */
nmtb.iItem = custInfo->tbInfo->nNumButtons;
if (!TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_QUERYINSERT))
return FALSE;
nmtbic.hwndDialog = hwnd;
/* Send TBN_INITCUSTOMIZE notification */
if (TOOLBAR_SendNotify (&nmtbic.hdr, infoPtr, TBN_INITCUSTOMIZE) ==
TBNRF_HIDEHELP)
{
TRACE("TBNRF_HIDEHELP requested\n");
ShowWindow(GetDlgItem(hwnd, IDC_HELP_BTN), SW_HIDE);
}
/* add items to 'toolbar buttons' list and check if removable */
for (i = 0; i < custInfo->tbInfo->nNumButtons; i++)
{
btnInfo = Alloc(sizeof(CUSTOMBUTTON));
memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
btnInfo->btn.fsStyle = BTNS_SEP;
btnInfo->bVirtual = FALSE;
LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
/* send TBN_QUERYDELETE notification */
btnInfo->bRemovable = TOOLBAR_IsButtonRemovable(infoPtr, i, btnInfo);
index = (int)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_ADDSTRING, 0, 0);
SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
}
SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMHEIGHT, 0, infoPtr->nBitmapHeight + 8);
/* insert separator button into 'available buttons' list */
btnInfo = Alloc(sizeof(CUSTOMBUTTON));
memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
btnInfo->btn.fsStyle = BTNS_SEP;
btnInfo->bVirtual = FALSE;
btnInfo->bRemovable = TRUE;
LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
index = (int)SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_ADDSTRING, 0, (LPARAM)btnInfo);
SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
/* insert all buttons into dsa */
for (i = 0;; i++)
{
/* send TBN_GETBUTTONINFO notification */
NMTOOLBARW nmtb;
nmtb.iItem = i;
nmtb.pszText = Buffer;
nmtb.cchText = 256;
/* Clear previous button's text */
ZeroMemory(nmtb.pszText, nmtb.cchText * sizeof(WCHAR));
if (!TOOLBAR_GetButtonInfo(infoPtr, &nmtb))
break;
TRACE("WM_INITDIALOG style: %x iItem(%d) idCommand(%d) iString(%ld) %s\n",
nmtb.tbButton.fsStyle, i,
nmtb.tbButton.idCommand,
nmtb.tbButton.iString,
nmtb.tbButton.iString >= 0 ? debugstr_w(infoPtr->strings[nmtb.tbButton.iString])
: "");
/* insert button into the apropriate list */
index = TOOLBAR_GetButtonIndex (custInfo->tbInfo, nmtb.tbButton.idCommand, FALSE);
if (index == -1)
{
btnInfo = Alloc(sizeof(CUSTOMBUTTON));
btnInfo->bVirtual = FALSE;
btnInfo->bRemovable = TRUE;
}
else
{
btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd,
IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
}
btnInfo->btn = nmtb.tbButton;
if (!(nmtb.tbButton.fsStyle & BTNS_SEP))
{
if (lstrlenW(nmtb.pszText))
lstrcpyW(btnInfo->text, nmtb.pszText);
else if (nmtb.tbButton.iString >= 0 &&
nmtb.tbButton.iString < infoPtr->nNumStrings)
{
lstrcpyW(btnInfo->text,
infoPtr->strings[nmtb.tbButton.iString]);
}
}
if (index == -1)
TOOLBAR_Cust_InsertAvailButton(hwnd, btnInfo);
}
SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMHEIGHT, 0, infoPtr->nBitmapHeight + 8);
/* select first item in the 'available' list */
SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETCURSEL, 0, 0);
/* append 'virtual' separator button to the 'toolbar buttons' list */
btnInfo = Alloc(sizeof(CUSTOMBUTTON));
memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
btnInfo->btn.fsStyle = BTNS_SEP;
btnInfo->bVirtual = TRUE;
btnInfo->bRemovable = FALSE;
LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
index = (int)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_ADDSTRING, 0, (LPARAM)btnInfo);
SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
/* select last item in the 'toolbar' list */
SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETCURSEL, index, 0);
SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETTOPINDEX, index, 0);
MakeDragList(GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX));
MakeDragList(GetDlgItem(hwnd, IDC_AVAILBTN_LBOX));
/* set focus and disable buttons */
PostMessageW (hwnd, WM_USER, 0, 0);
}
return TRUE;
case WM_USER:
EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
EnableWindow (GetDlgItem (hwnd,IDC_REMOVE_BTN), FALSE);
SetFocus (GetDlgItem (hwnd, IDC_TOOLBARBTN_LBOX));
return TRUE;
case WM_CLOSE:
EndDialog(hwnd, FALSE);
return TRUE;
case WM_COMMAND:
switch (LOWORD(wParam))
{
case IDC_TOOLBARBTN_LBOX:
if (HIWORD(wParam) == LBN_SELCHANGE)
{
PCUSTOMBUTTON btnInfo;
NMTOOLBARA nmtb;
int count;
int index;
count = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
/* send TBN_QUERYINSERT notification */
nmtb.iItem = index;
TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_QUERYINSERT);
/* get list box item */
btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
if (index == (count - 1))
{
/* last item (virtual separator) */
EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
}
else if (index == (count - 2))
{
/* second last item (last non-virtual item) */
EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), TRUE);
EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
}
else if (index == 0)
{
/* first item */
EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), TRUE);
}
else
{
EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), TRUE);
EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), TRUE);
}
EnableWindow (GetDlgItem (hwnd,IDC_REMOVE_BTN), btnInfo->bRemovable);
}
break;
case IDC_MOVEUP_BTN:
{
int index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
TOOLBAR_Cust_MoveButton(custInfo, hwnd, index, index-1);
}
break;
case IDC_MOVEDN_BTN: /* move down */
{
int index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
TOOLBAR_Cust_MoveButton(custInfo, hwnd, index, index+1);
}
break;
case IDC_REMOVE_BTN: /* remove button */
{
int index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
if (LB_ERR == index)
break;
TOOLBAR_Cust_RemoveButton(custInfo, hwnd, index);
}
break;
case IDC_HELP_BTN:
TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_CUSTHELP);
break;
case IDC_RESET_BTN:
TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_RESET);
break;
case IDOK: /* Add button */
{
int index;
int indexto;
index = SendDlgItemMessageW(hwnd, IDC_AVAILBTN_LBOX, LB_GETCURSEL, 0, 0);
indexto = SendDlgItemMessageW(hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
TOOLBAR_Cust_AddButton(custInfo, hwnd, index, indexto);
}
break;
case IDCANCEL:
EndDialog(hwnd, FALSE);
break;
}
return TRUE;
case WM_DESTROY:
{
int count;
int i;
/* delete items from 'toolbar buttons' listbox*/
count = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
for (i = 0; i < count; i++)
{
btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, i, 0);
Free(btnInfo);
SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, 0, 0);
}
SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_RESETCONTENT, 0, 0);
/* delete items from 'available buttons' listbox*/
count = SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_GETCOUNT, 0, 0);
for (i = 0; i < count; i++)
{
btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_GETITEMDATA, i, 0);
Free(btnInfo);
SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, i, 0);
}
SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_RESETCONTENT, 0, 0);
}
return TRUE;
case WM_DRAWITEM:
if (wParam == IDC_AVAILBTN_LBOX || wParam == IDC_TOOLBARBTN_LBOX)
{
LPDRAWITEMSTRUCT lpdis = (LPDRAWITEMSTRUCT)lParam;
RECT rcButton;
RECT rcText;
HPEN hPen, hOldPen;
HBRUSH hOldBrush;
COLORREF oldText = 0;
COLORREF oldBk = 0;
/* get item data */
btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, wParam, LB_GETITEMDATA, lpdis->itemID, 0);
if (btnInfo == NULL)
{
FIXME("btnInfo invalid!\n");
return TRUE;
}
/* set colors and select objects */
oldBk = SetBkColor (lpdis->hDC, (lpdis->itemState & ODS_FOCUS)?comctl32_color.clrHighlight:comctl32_color.clrWindow);
if (btnInfo->bVirtual)
oldText = SetTextColor (lpdis->hDC, comctl32_color.clrGrayText);
else
oldText = SetTextColor (lpdis->hDC, (lpdis->itemState & ODS_FOCUS)?comctl32_color.clrHighlightText:comctl32_color.clrWindowText);
hPen = CreatePen( PS_SOLID, 1,
(lpdis->itemState & ODS_SELECTED)?comctl32_color.clrHighlight:comctl32_color.clrWindow);
hOldPen = SelectObject (lpdis->hDC, hPen );
hOldBrush = SelectObject (lpdis->hDC, GetSysColorBrush ((lpdis->itemState & ODS_FOCUS)?COLOR_HIGHLIGHT:COLOR_WINDOW));
/* fill background rectangle */
Rectangle (lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
lpdis->rcItem.right, lpdis->rcItem.bottom);
/* calculate button and text rectangles */
CopyRect (&rcButton, &lpdis->rcItem);
InflateRect (&rcButton, -1, -1);
CopyRect (&rcText, &rcButton);
rcButton.right = rcButton.left + custInfo->tbInfo->nBitmapWidth + 6;
rcText.left = rcButton.right + 2;
/* draw focus rectangle */
if (lpdis->itemState & ODS_FOCUS)
DrawFocusRect (lpdis->hDC, &lpdis->rcItem);
/* draw button */
if (!(infoPtr->dwStyle & TBSTYLE_FLAT))
DrawEdge (lpdis->hDC, &rcButton, EDGE_RAISED, BF_RECT|BF_MIDDLE|BF_SOFT);
/* draw image and text */
if ((btnInfo->btn.fsStyle & BTNS_SEP) == 0) {
HIMAGELIST himl = GETDEFIMAGELIST(infoPtr, GETHIMLID(infoPtr,
btnInfo->btn.iBitmap));
ImageList_Draw (himl, GETIBITMAP(infoPtr, btnInfo->btn.iBitmap),
lpdis->hDC, rcButton.left+3, rcButton.top+3, ILD_NORMAL);
}
DrawTextW (lpdis->hDC, btnInfo->text, -1, &rcText,
DT_LEFT | DT_VCENTER | DT_SINGLELINE);
/* delete objects and reset colors */
SelectObject (lpdis->hDC, hOldBrush);
SelectObject (lpdis->hDC, hOldPen);
SetBkColor (lpdis->hDC, oldBk);
SetTextColor (lpdis->hDC, oldText);
DeleteObject( hPen );
return TRUE;
}
return FALSE;
case WM_MEASUREITEM:
if (wParam == IDC_AVAILBTN_LBOX || wParam == IDC_TOOLBARBTN_LBOX)
{
MEASUREITEMSTRUCT *lpmis = (MEASUREITEMSTRUCT*)lParam;
lpmis->itemHeight = 15 + 8; /* default height */
return TRUE;
}
return FALSE;
default:
if (uDragListMessage && (uMsg == uDragListMessage))
{
if (wParam == IDC_TOOLBARBTN_LBOX)
{
LRESULT res = TOOLBAR_Cust_ToolbarDragListNotification(
custInfo, hwnd, (DRAGLISTINFO *)lParam);
SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, res);
return TRUE;
}
else if (wParam == IDC_AVAILBTN_LBOX)
{
LRESULT res = TOOLBAR_Cust_AvailDragListNotification(
custInfo, hwnd, (DRAGLISTINFO *)lParam);
SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, res);
return TRUE;
}
}
return FALSE;
}
}
static BOOL
TOOLBAR_AddBitmapToImageList(TOOLBAR_INFO *infoPtr, HIMAGELIST himlDef, const TBITMAP_INFO *bitmap)
{
HBITMAP hbmLoad;
INT nCountBefore = ImageList_GetImageCount(himlDef);
INT nCountAfter;
INT cxIcon, cyIcon;
INT nAdded;
INT nIndex;
TRACE("adding hInst=%p nID=%d nButtons=%d\n", bitmap->hInst, bitmap->nID, bitmap->nButtons);
/* Add bitmaps to the default image list */
if (bitmap->hInst == NULL) /* a handle was passed */
hbmLoad = CopyImage(ULongToHandle(bitmap->nID), IMAGE_BITMAP, 0, 0, 0);
else if (bitmap->hInst == COMCTL32_hModule)
hbmLoad = LoadImageW( bitmap->hInst, MAKEINTRESOURCEW(bitmap->nID),
IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION );
else
hbmLoad = CreateMappedBitmap(bitmap->hInst, bitmap->nID, 0, NULL, 0);
/* enlarge the bitmap if needed */
ImageList_GetIconSize(himlDef, &cxIcon, &cyIcon);
if (bitmap->hInst != COMCTL32_hModule)
COMCTL32_EnsureBitmapSize(&hbmLoad, cxIcon*(INT)bitmap->nButtons, cyIcon, comctl32_color.clrBtnFace);
nIndex = ImageList_AddMasked(himlDef, hbmLoad, comctl32_color.clrBtnFace);
DeleteObject(hbmLoad);
if (nIndex == -1)
return FALSE;
nCountAfter = ImageList_GetImageCount(himlDef);
nAdded = nCountAfter - nCountBefore;
if (bitmap->nButtons == 0) /* wParam == 0 is special and means add only one image */
{
ImageList_SetImageCount(himlDef, nCountBefore + 1);
} else if (nAdded > (INT)bitmap->nButtons) {
TRACE("Added more images than wParam: Previous image number %i added %i while wParam %i. Images in list %i\n",
nCountBefore, nAdded, bitmap->nButtons, nCountAfter);
}
infoPtr->nNumBitmaps += nAdded;
return TRUE;
}
static void
TOOLBAR_CheckImageListIconSize(TOOLBAR_INFO *infoPtr)
{
HIMAGELIST himlDef;
HIMAGELIST himlNew;
INT cx, cy;
INT i;
himlDef = GETDEFIMAGELIST(infoPtr, 0);
if (himlDef == NULL || himlDef != infoPtr->himlInt)
return;
if (!ImageList_GetIconSize(himlDef, &cx, &cy))
return;
if (cx == infoPtr->nBitmapWidth && cy == infoPtr->nBitmapHeight)
return;
TRACE("Update icon size: %dx%d -> %dx%d\n",
cx, cy, infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
himlNew = ImageList_Create(infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
ILC_COLOR32|ILC_MASK, 8, 2);
for (i = 0; i < infoPtr->nNumBitmapInfos; i++)
TOOLBAR_AddBitmapToImageList(infoPtr, himlNew, &infoPtr->bitmaps[i]);
TOOLBAR_InsertImageList(&infoPtr->himlDef, &infoPtr->cimlDef, himlNew, 0);
infoPtr->himlInt = himlNew;
infoPtr->nNumBitmaps -= ImageList_GetImageCount(himlDef);
ImageList_Destroy(himlDef);
}
/***********************************************************************
* TOOLBAR_AddBitmap: Add the bitmaps to the default image list.
*
*/
static LRESULT
TOOLBAR_AddBitmap (TOOLBAR_INFO *infoPtr, INT count, const TBADDBITMAP *lpAddBmp)
{
TBITMAP_INFO info;
INT iSumButtons, i;
HIMAGELIST himlDef;
TRACE("hwnd=%p count=%d lpAddBmp=%p\n", infoPtr->hwndSelf, count, lpAddBmp);
if (!lpAddBmp)
return -1;
if (lpAddBmp->hInst == HINST_COMMCTRL)
{
info.hInst = COMCTL32_hModule;
switch (lpAddBmp->nID)
{
case IDB_STD_SMALL_COLOR:
info.nButtons = 15;
info.nID = IDB_STD_SMALL;
break;
case IDB_STD_LARGE_COLOR:
info.nButtons = 15;
info.nID = IDB_STD_LARGE;
break;
case IDB_VIEW_SMALL_COLOR:
info.nButtons = 12;
info.nID = IDB_VIEW_SMALL;
break;
case IDB_VIEW_LARGE_COLOR:
info.nButtons = 12;
info.nID = IDB_VIEW_LARGE;
break;
case IDB_HIST_SMALL_COLOR:
info.nButtons = 5;
info.nID = IDB_HIST_SMALL;
break;
case IDB_HIST_LARGE_COLOR:
info.nButtons = 5;
info.nID = IDB_HIST_LARGE;
break;
default:
return -1;
}
TRACE ("adding %d internal bitmaps!\n", info.nButtons);
/* Windows resize all the buttons to the size of a newly added standard image */
if (lpAddBmp->nID & 1)
{
/* large icons: 24x24. Will make the button 31x30 */
SendMessageW (infoPtr->hwndSelf, TB_SETBITMAPSIZE, 0, MAKELPARAM(24, 24));
}
else
{
/* small icons: 16x16. Will make the buttons 23x22 */
SendMessageW (infoPtr->hwndSelf, TB_SETBITMAPSIZE, 0, MAKELPARAM(16, 16));
}
TOOLBAR_CalcToolbar (infoPtr);
}
else
{
info.nButtons = count;
info.hInst = lpAddBmp->hInst;
info.nID = lpAddBmp->nID;
TRACE("adding %d bitmaps!\n", info.nButtons);
}
/* check if the bitmap is already loaded and compute iSumButtons */
iSumButtons = 0;
for (i = 0; i < infoPtr->nNumBitmapInfos; i++)
{
if (infoPtr->bitmaps[i].hInst == info.hInst &&
infoPtr->bitmaps[i].nID == info.nID)
return iSumButtons;
iSumButtons += infoPtr->bitmaps[i].nButtons;
}
if (!infoPtr->cimlDef) {
/* create new default image list */
TRACE ("creating default image list!\n");
himlDef = ImageList_Create (infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
ILC_COLOR32 | ILC_MASK, info.nButtons, 2);
TOOLBAR_InsertImageList(&infoPtr->himlDef, &infoPtr->cimlDef, himlDef, 0);
infoPtr->himlInt = himlDef;
}
else {
himlDef = GETDEFIMAGELIST(infoPtr, 0);
}
if (!himlDef) {
WARN("No default image list available\n");
return -1;
}
if (!TOOLBAR_AddBitmapToImageList(infoPtr, himlDef, &info))
return -1;
TRACE("Number of bitmap infos: %d\n", infoPtr->nNumBitmapInfos);
infoPtr->bitmaps = ReAlloc(infoPtr->bitmaps, (infoPtr->nNumBitmapInfos + 1) * sizeof(TBITMAP_INFO));
infoPtr->bitmaps[infoPtr->nNumBitmapInfos] = info;
infoPtr->nNumBitmapInfos++;
TRACE("Number of bitmap infos: %d\n", infoPtr->nNumBitmapInfos);
InvalidateRect(infoPtr->hwndSelf, NULL, TRUE);
return iSumButtons;
}
static LRESULT
TOOLBAR_AddButtonsT(TOOLBAR_INFO *infoPtr, INT nAddButtons, const TBBUTTON* lpTbb, BOOL fUnicode)
{
TRACE("adding %d buttons (unicode=%d)!\n", nAddButtons, fUnicode);
return TOOLBAR_InternalInsertButtonsT(infoPtr, -1, nAddButtons, lpTbb, fUnicode);
}
static LRESULT
TOOLBAR_AddStringW (TOOLBAR_INFO *infoPtr, HINSTANCE hInstance, LPARAM lParam)
{
#define MAX_RESOURCE_STRING_LENGTH 512
BOOL fFirstString = (infoPtr->nNumStrings == 0);
INT nIndex = infoPtr->nNumStrings;
TRACE("%p, %lx\n", hInstance, lParam);
if (IS_INTRESOURCE(lParam)) {
WCHAR szString[MAX_RESOURCE_STRING_LENGTH];
WCHAR delimiter;
WCHAR *next_delim;
HRSRC hrsrc;
WCHAR *p;
INT len;
TRACE("adding string from resource\n");
if (!hInstance) return -1;
hrsrc = FindResourceW( hInstance, MAKEINTRESOURCEW((LOWORD(lParam) >> 4) + 1),
(LPWSTR)RT_STRING );
if (!hrsrc)
{
TRACE("string not found in resources\n");
return -1;
}
len = LoadStringW (hInstance, (UINT)lParam,
szString, MAX_RESOURCE_STRING_LENGTH);
TRACE("len=%d %s\n", len, debugstr_w(szString));
if (len == 0 || len == 1)
return nIndex;
TRACE("delimiter: 0x%x\n", *szString);
delimiter = *szString;
p = szString + 1;
while ((next_delim = strchrW(p, delimiter)) != NULL) {
*next_delim = 0;
if (next_delim + 1 >= szString + len)
{
/* this may happen if delimiter == '\0' or if the last char is a
* delimiter (then it is ignored like the native does) */
break;
}
infoPtr->strings = ReAlloc(infoPtr->strings, sizeof(LPWSTR)*(infoPtr->nNumStrings+1));
Str_SetPtrW(&infoPtr->strings[infoPtr->nNumStrings], p);
infoPtr->nNumStrings++;
p = next_delim + 1;
}
}
else {
LPWSTR p = (LPWSTR)lParam;
INT len;
if (p == NULL)
return -1;
TRACE("adding string(s) from array\n");
while (*p) {
len = strlenW (p);
TRACE("len=%d %s\n", len, debugstr_w(p));
infoPtr->strings = ReAlloc(infoPtr->strings, sizeof(LPWSTR)*(infoPtr->nNumStrings+1));
Str_SetPtrW (&infoPtr->strings[infoPtr->nNumStrings], p);
infoPtr->nNumStrings++;
p += (len+1);
}
}
if (fFirstString)
TOOLBAR_CalcToolbar(infoPtr);
return nIndex;
}
static LRESULT
TOOLBAR_AddStringA (TOOLBAR_INFO *infoPtr, HINSTANCE hInstance, LPARAM lParam)
{
BOOL fFirstString = (infoPtr->nNumStrings == 0);
LPSTR p;
INT nIndex;
INT len;
TRACE("%p, %lx\n", hInstance, lParam);
if (IS_INTRESOURCE(lParam)) /* load from resources */
return TOOLBAR_AddStringW(infoPtr, hInstance, lParam);
p = (LPSTR)lParam;
if (p == NULL)
return -1;
TRACE("adding string(s) from array\n");
nIndex = infoPtr->nNumStrings;
while (*p) {
len = strlen (p);
TRACE("len=%d \"%s\"\n", len, p);
infoPtr->strings = ReAlloc(infoPtr->strings, sizeof(LPWSTR)*(infoPtr->nNumStrings+1));
Str_SetPtrAtoW(&infoPtr->strings[infoPtr->nNumStrings], p);
infoPtr->nNumStrings++;
p += (len+1);
}
if (fFirstString)
TOOLBAR_CalcToolbar(infoPtr);
return nIndex;
}
static LRESULT
TOOLBAR_AutoSize (TOOLBAR_INFO *infoPtr)
{
RECT parent_rect;
HWND parent;
INT x, y;
INT cx, cy;
TRACE("auto sizing, style=%x!\n", infoPtr->dwStyle);
parent = GetParent (infoPtr->hwndSelf);
if (!parent || !infoPtr->bDoRedraw)
return 0;
GetClientRect(parent, &parent_rect);
x = parent_rect.left;
y = parent_rect.top;
TRACE("nRows: %d, infoPtr->nButtonHeight: %d\n", infoPtr->nRows, infoPtr->nButtonHeight);
cy = TOP_BORDER + infoPtr->nRows * infoPtr->nButtonHeight + BOTTOM_BORDER;
cx = parent_rect.right - parent_rect.left;
if ((infoPtr->dwStyle & TBSTYLE_WRAPABLE) || (infoPtr->dwExStyle & TBSTYLE_EX_UNDOC1))
{
TOOLBAR_LayoutToolbar(infoPtr);
InvalidateRect( infoPtr->hwndSelf, NULL, TRUE );
}
if (!(infoPtr->dwStyle & CCS_NORESIZE))
{
RECT window_rect;
UINT uPosFlags = SWP_NOZORDER | SWP_NOACTIVATE;
if ((infoPtr->dwStyle & CCS_BOTTOM) == CCS_NOMOVEY)
{
GetWindowRect(infoPtr->hwndSelf, &window_rect);
MapWindowPoints( 0, parent, (POINT *)&window_rect, 2 );
y = window_rect.top;
}
if ((infoPtr->dwStyle & CCS_BOTTOM) == CCS_BOTTOM)
{
GetWindowRect(infoPtr->hwndSelf, &window_rect);
y = parent_rect.bottom - ( window_rect.bottom - window_rect.top);
}
if (infoPtr->dwStyle & CCS_NOPARENTALIGN)
uPosFlags |= SWP_NOMOVE;
if (!(infoPtr->dwStyle & CCS_NODIVIDER))
cy += GetSystemMetrics(SM_CYEDGE);
if (infoPtr->dwStyle & WS_BORDER)
{
cx += 2 * GetSystemMetrics(SM_CXBORDER);
cy += 2 * GetSystemMetrics(SM_CYBORDER);
}
SetWindowPos(infoPtr->hwndSelf, NULL, x, y, cx, cy, uPosFlags);
}
return 0;
}
static inline LRESULT
TOOLBAR_ButtonCount (const TOOLBAR_INFO *infoPtr)
{
return infoPtr->nNumButtons;
}
static inline LRESULT
TOOLBAR_ButtonStructSize (TOOLBAR_INFO *infoPtr, DWORD Size)
{
infoPtr->dwStructSize = Size;
return 0;
}
static LRESULT
TOOLBAR_ChangeBitmap (TOOLBAR_INFO *infoPtr, INT Id, INT Index)
{
TBUTTON_INFO *btnPtr;
INT nIndex;
TRACE("button %d, iBitmap now %d\n", Id, Index);
nIndex = TOOLBAR_GetButtonIndex (infoPtr, Id, FALSE);
if (nIndex == -1)
return FALSE;
btnPtr = &infoPtr->buttons[nIndex];
btnPtr->iBitmap = Index;
/* we HAVE to erase the background, the new bitmap could be */
/* transparent */
InvalidateRect(infoPtr->hwndSelf, &btnPtr->rect, TRUE);
return TRUE;
}
static LRESULT
TOOLBAR_CheckButton (TOOLBAR_INFO *infoPtr, INT Id, LPARAM lParam)
{
TBUTTON_INFO *btnPtr;
INT nIndex;
INT nOldIndex = -1;
BOOL bChecked = FALSE;
nIndex = TOOLBAR_GetButtonIndex (infoPtr, Id, FALSE);
TRACE("hwnd=%p, btn index=%d, lParam=0x%08lx\n", infoPtr->hwndSelf, nIndex, lParam);
if (nIndex == -1)
return FALSE;
btnPtr = &infoPtr->buttons[nIndex];
bChecked = (btnPtr->fsState & TBSTATE_CHECKED) ? TRUE : FALSE;
if (LOWORD(lParam) == FALSE)
btnPtr->fsState &= ~TBSTATE_CHECKED;
else {
if (btnPtr->fsStyle & BTNS_GROUP) {
nOldIndex =
TOOLBAR_GetCheckedGroupButtonIndex (infoPtr, nIndex);
if (nOldIndex == nIndex)
return 0;
if (nOldIndex != -1)
infoPtr->buttons[nOldIndex].fsState &= ~TBSTATE_CHECKED;
}
btnPtr->fsState |= TBSTATE_CHECKED;
}
if( bChecked != LOWORD(lParam) )
{
if (nOldIndex != -1)
InvalidateRect(infoPtr->hwndSelf, &infoPtr->buttons[nOldIndex].rect, TRUE);
InvalidateRect(infoPtr->hwndSelf, &btnPtr->rect, TRUE);
}
/* FIXME: Send a WM_NOTIFY?? */
return TRUE;
}
static LRESULT
TOOLBAR_CommandToIndex (const TOOLBAR_INFO *infoPtr, INT Id)
{
return TOOLBAR_GetButtonIndex (infoPtr, Id, FALSE);
}
static LRESULT
TOOLBAR_Customize (TOOLBAR_INFO *infoPtr)
{
CUSTDLG_INFO custInfo;
LRESULT ret;
NMHDR nmhdr;
custInfo.tbInfo = infoPtr;
custInfo.tbHwnd = infoPtr->hwndSelf;
/* send TBN_BEGINADJUST notification */
TOOLBAR_SendNotify (&nmhdr, infoPtr, TBN_BEGINADJUST);
ret = DialogBoxParamW (COMCTL32_hModule, MAKEINTRESOURCEW(IDD_TBCUSTOMIZE),
infoPtr->hwndSelf, TOOLBAR_CustomizeDialogProc, (LPARAM)&custInfo);
/* send TBN_ENDADJUST notification */
TOOLBAR_SendNotify (&nmhdr, infoPtr, TBN_ENDADJUST);
return ret;
}
static LRESULT
TOOLBAR_DeleteButton (TOOLBAR_INFO *infoPtr, INT nIndex)
{
NMTOOLBARW nmtb;
TBUTTON_INFO *btnPtr = &infoPtr->buttons[nIndex];
if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
return FALSE;
memset(&nmtb, 0, sizeof(nmtb));
nmtb.iItem = btnPtr->idCommand;
nmtb.tbButton.iBitmap = btnPtr->iBitmap;
nmtb.tbButton.idCommand = btnPtr->idCommand;
nmtb.tbButton.fsState = btnPtr->fsState;
nmtb.tbButton.fsStyle = btnPtr->fsStyle;
nmtb.tbButton.dwData = btnPtr->dwData;
nmtb.tbButton.iString = btnPtr->iString;
TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_DELETINGBUTTON);
TOOLBAR_TooltipDelTool(infoPtr, &infoPtr->buttons[nIndex]);
if (infoPtr->nNumButtons == 1) {
TRACE(" simple delete!\n");
if (TOOLBAR_ButtonHasString(infoPtr->buttons))
Free((LPWSTR)infoPtr->buttons[0].iString);
Free (infoPtr->buttons);
infoPtr->buttons = NULL;
infoPtr->nNumButtons = 0;
}
else {
TBUTTON_INFO *oldButtons = infoPtr->buttons;
TRACE("complex delete! [nIndex=%d]\n", nIndex);
infoPtr->nNumButtons--;
infoPtr->buttons = Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
if (nIndex > 0) {
memcpy (&infoPtr->buttons[0], &oldButtons[0],
nIndex * sizeof(TBUTTON_INFO));
}
if (nIndex < infoPtr->nNumButtons) {
memcpy (&infoPtr->buttons[nIndex], &oldButtons[nIndex+1],
(infoPtr->nNumButtons - nIndex) * sizeof(TBUTTON_INFO));
}
if (TOOLBAR_ButtonHasString(&oldButtons[nIndex]))
Free((LPWSTR)oldButtons[nIndex].iString);
Free (oldButtons);
}
TOOLBAR_LayoutToolbar(infoPtr);
InvalidateRect (infoPtr->hwndSelf, NULL, TRUE);
return TRUE;
}
static LRESULT
TOOLBAR_EnableButton (TOOLBAR_INFO *infoPtr, INT Id, LPARAM lParam)
{
TBUTTON_INFO *btnPtr;
INT nIndex;
DWORD bState;
nIndex = TOOLBAR_GetButtonIndex (infoPtr, Id, FALSE);
TRACE("hwnd=%p, btn id=%d, lParam=0x%08lx\n", infoPtr->hwndSelf, Id, lParam);
if (nIndex == -1)
return FALSE;
btnPtr = &infoPtr->buttons[nIndex];
bState = btnPtr->fsState & TBSTATE_ENABLED;
/* update the toolbar button state */
if(LOWORD(lParam) == FALSE) {
btnPtr->fsState &= ~(TBSTATE_ENABLED | TBSTATE_PRESSED);
} else {
btnPtr->fsState |= TBSTATE_ENABLED;
}
/* redraw the button only if the state of the button changed */
if(bState != (btnPtr->fsState & TBSTATE_ENABLED))
InvalidateRect(infoPtr->hwndSelf, &btnPtr->rect, TRUE);
return TRUE;
}
static inline LRESULT
TOOLBAR_GetAnchorHighlight (const TOOLBAR_INFO *infoPtr)
{
return infoPtr->bAnchor;
}
static LRESULT
TOOLBAR_GetBitmap (const TOOLBAR_INFO *infoPtr, INT Id)
{
INT nIndex;
nIndex = TOOLBAR_GetButtonIndex (infoPtr, Id, FALSE);
if (nIndex == -1)
return -1;
return infoPtr->buttons[nIndex].iBitmap;
}
static inline LRESULT
TOOLBAR_GetBitmapFlags (void)
{
return (GetDeviceCaps (0, LOGPIXELSX) >= 120) ? TBBF_LARGE : 0;
}
static LRESULT
TOOLBAR_GetButton (const TOOLBAR_INFO *infoPtr, INT nIndex, TBBUTTON *lpTbb)
{
TBUTTON_INFO *btnPtr;
if (lpTbb == NULL)
return FALSE;
if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
return FALSE;
btnPtr = &infoPtr->buttons[nIndex];
lpTbb->iBitmap = btnPtr->iBitmap;
lpTbb->idCommand = btnPtr->idCommand;
lpTbb->fsState = btnPtr->fsState;
lpTbb->fsStyle = btnPtr->fsStyle;
lpTbb->bReserved[0] = 0;
lpTbb->bReserved[1] = 0;
lpTbb->dwData = btnPtr->dwData;
lpTbb->iString = btnPtr->iString;
return TRUE;
}
static LRESULT
TOOLBAR_GetButtonInfoT(const TOOLBAR_INFO *infoPtr, INT Id, LPTBBUTTONINFOW lpTbInfo, BOOL bUnicode)
{
/* TBBUTTONINFOW and TBBUTTONINFOA have the same layout*/
TBUTTON_INFO *btnPtr;
INT nIndex;
if (lpTbInfo == NULL)
return -1;
/* MSDN documents a iImageLabel field added in Vista but it is not present in
* the headers and tests shows that even with comctl 6 Vista accepts only the
* original TBBUTTONINFO size
*/
if (lpTbInfo->cbSize != sizeof(TBBUTTONINFOW))
{
WARN("Invalid button size\n");
return -1;
}
nIndex = TOOLBAR_GetButtonIndex (infoPtr, Id, lpTbInfo->dwMask & TBIF_BYINDEX);
if (nIndex == -1)
return -1;
if (!(btnPtr = &infoPtr->buttons[nIndex])) return -1;
if (lpTbInfo->dwMask & TBIF_COMMAND)
lpTbInfo->idCommand = btnPtr->idCommand;
if (lpTbInfo->dwMask & TBIF_IMAGE)
lpTbInfo->iImage = btnPtr->iBitmap;
if (lpTbInfo->dwMask & TBIF_LPARAM)
lpTbInfo->lParam = btnPtr->dwData;
if (lpTbInfo->dwMask & TBIF_SIZE)
/* tests show that for separators TBIF_SIZE returns not calculated width,
but cx property, that differs from 0 only if application have
specifically set it */
lpTbInfo->cx = (btnPtr->fsStyle & BTNS_SEP)
? btnPtr->cx : (WORD)(btnPtr->rect.right - btnPtr->rect.left);
if (lpTbInfo->dwMask & TBIF_STATE)
lpTbInfo->fsState = btnPtr->fsState;
if (lpTbInfo->dwMask & TBIF_STYLE)
lpTbInfo->fsStyle = btnPtr->fsStyle;
if (lpTbInfo->dwMask & TBIF_TEXT) {
/* TB_GETBUTTONINFO doesn't retrieve text from the string list, so we
can't use TOOLBAR_GetText here */
if (!IS_INTRESOURCE(btnPtr->iString) && (btnPtr->iString != -1)) {
LPWSTR lpText = (LPWSTR)btnPtr->iString;
if (bUnicode)
Str_GetPtrW(lpText, lpTbInfo->pszText, lpTbInfo->cchText);
else
Str_GetPtrWtoA(lpText, (LPSTR)lpTbInfo->pszText, lpTbInfo->cchText);
} else
lpTbInfo->pszText[0] = '\0';
}
return nIndex;
}
static inline LRESULT
TOOLBAR_GetButtonSize (const TOOLBAR_INFO *infoPtr)
{
return MAKELONG((WORD)infoPtr->nButtonWidth,
(WORD)infoPtr->nButtonHeight);
}
static LRESULT
TOOLBAR_GetButtonText (const TOOLBAR_INFO *infoPtr, INT Id, LPWSTR lpStr, BOOL isW)
{
INT nIndex;
LPWSTR lpText;
LRESULT ret = 0;
nIndex = TOOLBAR_GetButtonIndex (infoPtr, Id, FALSE);
if (nIndex == -1)
return -1;
lpText = TOOLBAR_GetText(infoPtr,&infoPtr->buttons[nIndex]);
if (isW)
{
if (lpText)
{
ret = strlenW (lpText);
if (lpStr) strcpyW (lpStr, lpText);
}
}
else
ret = WideCharToMultiByte( CP_ACP, 0, lpText, -1,
(LPSTR)lpStr, lpStr ? 0x7fffffff : 0, NULL, NULL ) - 1;
return ret;
}
static LRESULT
TOOLBAR_GetDisabledImageList (const TOOLBAR_INFO *infoPtr, WPARAM wParam)
{
TRACE("hwnd=%p, wParam=%ld\n", infoPtr->hwndSelf, wParam);
/* UNDOCUMENTED: wParam is actually the ID of the image list to return */
return (LRESULT)GETDISIMAGELIST(infoPtr, wParam);
}
static inline LRESULT
TOOLBAR_GetExtendedStyle (const TOOLBAR_INFO *infoPtr)
{
TRACE("\n");
return infoPtr->dwExStyle;
}
static LRESULT
TOOLBAR_GetHotImageList (const TOOLBAR_INFO *infoPtr, WPARAM wParam)
{
TRACE("hwnd=%p, wParam=%ld\n", infoPtr->hwndSelf, wParam);
/* UNDOCUMENTED: wParam is actually the ID of the image list to return */
return (LRESULT)GETHOTIMAGELIST(infoPtr, wParam);
}
static LRESULT
TOOLBAR_GetHotItem (const TOOLBAR_INFO *infoPtr)
{
if (!((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf)))
return -1;
if (infoPtr->nHotItem < 0)
return -1;
return (LRESULT)infoPtr->nHotItem;
}
static LRESULT
TOOLBAR_GetDefImageList (const TOOLBAR_INFO *infoPtr, WPARAM wParam)
{
TRACE("hwnd=%p, wParam=%ld\n", infoPtr->hwndSelf, wParam);
/* UNDOCUMENTED: wParam is actually the ID of the image list to return */
return (LRESULT) GETDEFIMAGELIST(infoPtr, wParam);
}
static LRESULT
TOOLBAR_GetInsertMark (const TOOLBAR_INFO *infoPtr, TBINSERTMARK *lptbim)
{
TRACE("hwnd = %p, lptbim = %p\n", infoPtr->hwndSelf, lptbim);
*lptbim = infoPtr->tbim;
return 0;
}
static inline LRESULT
TOOLBAR_GetInsertMarkColor (const TOOLBAR_INFO *infoPtr)
{
TRACE("hwnd = %p\n", infoPtr->hwndSelf);
return (LRESULT)infoPtr->clrInsertMark;
}
static LRESULT
TOOLBAR_GetItemRect (const TOOLBAR_INFO *infoPtr, INT nIndex, LPRECT lpRect)
{
TBUTTON_INFO *btnPtr;
btnPtr = &infoPtr->buttons[nIndex];
if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
return FALSE;
if (lpRect == NULL)
return FALSE;
if (btnPtr->fsState & TBSTATE_HIDDEN)
return FALSE;
lpRect->left = btnPtr->rect.left;
lpRect->right = btnPtr->rect.right;
lpRect->bottom = btnPtr->rect.bottom;
lpRect->top = btnPtr->rect.top;
return TRUE;
}
static LRESULT
TOOLBAR_GetMaxSize (const TOOLBAR_INFO *infoPtr, LPSIZE lpSize)
{
if (lpSize == NULL)
return FALSE;
lpSize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
lpSize->cy = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
TRACE("maximum size %d x %d\n",
infoPtr->rcBound.right - infoPtr->rcBound.left,
infoPtr->rcBound.bottom - infoPtr->rcBound.top);
return TRUE;
}
/* << TOOLBAR_GetObject >> */
static inline LRESULT
TOOLBAR_GetPadding (const TOOLBAR_INFO *infoPtr)
{
return MAKELONG(infoPtr->szPadding.cx, infoPtr->szPadding.cy);
}
static LRESULT
TOOLBAR_GetRect (const TOOLBAR_INFO *infoPtr, INT Id, LPRECT lpRect)
{
TBUTTON_INFO *btnPtr;
INT nIndex;
nIndex = TOOLBAR_GetButtonIndex (infoPtr, Id, FALSE);
btnPtr = &infoPtr->buttons[nIndex];
if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
return FALSE;
if (lpRect == NULL)
return FALSE;
lpRect->left = btnPtr->rect.left;
lpRect->right = btnPtr->rect.right;
lpRect->bottom = btnPtr->rect.bottom;
lpRect->top = btnPtr->rect.top;
return TRUE;
}
static inline LRESULT
TOOLBAR_GetRows (const TOOLBAR_INFO *infoPtr)
{
return infoPtr->nRows;
}
static LRESULT
TOOLBAR_GetState (const TOOLBAR_INFO *infoPtr, INT Id)
{
INT nIndex;
nIndex = TOOLBAR_GetButtonIndex (infoPtr, Id, FALSE);
if (nIndex == -1)
return -1;
return infoPtr->buttons[nIndex].fsState;
}
static inline LRESULT
TOOLBAR_GetStyle (const TOOLBAR_INFO *infoPtr)
{
return infoPtr->dwStyle;
}
static inline LRESULT
TOOLBAR_GetTextRows (const TOOLBAR_INFO *infoPtr)
{
return infoPtr->nMaxTextRows;
}
static LRESULT
TOOLBAR_GetToolTips (TOOLBAR_INFO *infoPtr)
{
if ((infoPtr->dwStyle & TBSTYLE_TOOLTIPS) && (infoPtr->hwndToolTip == NULL))
TOOLBAR_TooltipCreateControl(infoPtr);
return (LRESULT)infoPtr->hwndToolTip;
}
static LRESULT
TOOLBAR_GetUnicodeFormat (const TOOLBAR_INFO *infoPtr)
{
TRACE("%s hwnd=%p\n",
infoPtr->bUnicode ? "TRUE" : "FALSE", infoPtr->hwndSelf);
return infoPtr->bUnicode;
}
static inline LRESULT
TOOLBAR_GetVersion (const TOOLBAR_INFO *infoPtr)
{
return infoPtr->iVersion;
}
static LRESULT
TOOLBAR_HideButton (TOOLBAR_INFO *infoPtr, INT Id, BOOL fHide)
{
TBUTTON_INFO *btnPtr;
BYTE oldState;
INT nIndex;
TRACE("\n");
nIndex = TOOLBAR_GetButtonIndex (infoPtr, Id, FALSE);
if (nIndex == -1)
return FALSE;
btnPtr = &infoPtr->buttons[nIndex];
oldState = btnPtr->fsState;
if (fHide)
btnPtr->fsState |= TBSTATE_HIDDEN;
else
btnPtr->fsState &= ~TBSTATE_HIDDEN;
if (oldState != btnPtr->fsState) {
TOOLBAR_LayoutToolbar (infoPtr);
InvalidateRect (infoPtr->hwndSelf, NULL, TRUE);
}
return TRUE;
}
static inline LRESULT
TOOLBAR_HitTest (const TOOLBAR_INFO *infoPtr, const POINT* lpPt)
{
return TOOLBAR_InternalHitTest (infoPtr, lpPt, NULL);
}
static LRESULT
TOOLBAR_Indeterminate (const TOOLBAR_INFO *infoPtr, INT Id, BOOL fIndeterminate)
{
TBUTTON_INFO *btnPtr;
INT nIndex;
DWORD oldState;
nIndex = TOOLBAR_GetButtonIndex (infoPtr, Id, FALSE);
if (nIndex == -1)
return FALSE;
btnPtr = &infoPtr->buttons[nIndex];
oldState = btnPtr->fsState;
if (fIndeterminate)
btnPtr->fsState |= TBSTATE_INDETERMINATE;
else
btnPtr->fsState &= ~TBSTATE_INDETERMINATE;
if(oldState != btnPtr->fsState)
InvalidateRect(infoPtr->hwndSelf, &btnPtr->rect, TRUE);
return TRUE;
}
static LRESULT
TOOLBAR_InsertButtonT(TOOLBAR_INFO *infoPtr, INT nIndex, const TBBUTTON *lpTbb, BOOL fUnicode)
{
if (lpTbb == NULL)
return FALSE;
if (nIndex == -1) {
/* EPP: this seems to be an undocumented call (from my IE4)
* I assume in that case that:
* - index of insertion is at the end of existing buttons
* I only see this happen with nIndex == -1, but it could have a special
* meaning (like -nIndex (or ~nIndex) to get the real position of insertion).
*/
nIndex = infoPtr->nNumButtons;
} else if (nIndex < 0)
return FALSE;
TRACE("inserting button index=%d\n", nIndex);
if (nIndex > infoPtr->nNumButtons) {
nIndex = infoPtr->nNumButtons;
TRACE("adjust index=%d\n", nIndex);
}
return TOOLBAR_InternalInsertButtonsT(infoPtr, nIndex, 1, lpTbb, fUnicode);
}
/* << TOOLBAR_InsertMarkHitTest >> */
static LRESULT
TOOLBAR_IsButtonChecked (const TOOLBAR_INFO *infoPtr, INT Id)
{
INT nIndex;
nIndex = TOOLBAR_GetButtonIndex (infoPtr, Id, FALSE);
if (nIndex == -1)
return -1;
return (infoPtr->buttons[nIndex].fsState & TBSTATE_CHECKED);
}
static LRESULT
TOOLBAR_IsButtonEnabled (const TOOLBAR_INFO *infoPtr, INT Id)
{
INT nIndex;
nIndex = TOOLBAR_GetButtonIndex (infoPtr, Id, FALSE);
if (nIndex == -1)
return -1;
return (infoPtr->buttons[nIndex].fsState & TBSTATE_ENABLED);
}
static LRESULT
TOOLBAR_IsButtonHidden (const TOOLBAR_INFO *infoPtr, INT Id)
{
INT nIndex;
nIndex = TOOLBAR_GetButtonIndex (infoPtr, Id, FALSE);
if (nIndex == -1)
return -1;
return (infoPtr->buttons[nIndex].fsState & TBSTATE_HIDDEN);
}
static LRESULT
TOOLBAR_IsButtonHighlighted (const TOOLBAR_INFO *infoPtr, INT Id)
{
INT nIndex;
nIndex = TOOLBAR_GetButtonIndex (infoPtr, Id, FALSE);
if (nIndex == -1)
return -1;
return (infoPtr->buttons[nIndex].fsState & TBSTATE_MARKED);
}
static LRESULT
TOOLBAR_IsButtonIndeterminate (const TOOLBAR_INFO *infoPtr, INT Id)
{
INT nIndex;
nIndex = TOOLBAR_GetButtonIndex (infoPtr, Id, FALSE);
if (nIndex == -1)
return -1;
return (infoPtr->buttons[nIndex].fsState & TBSTATE_INDETERMINATE);
}
static LRESULT
TOOLBAR_IsButtonPressed (const TOOLBAR_INFO *infoPtr, INT Id)
{
INT nIndex;
nIndex = TOOLBAR_GetButtonIndex (infoPtr, Id, FALSE);
if (nIndex == -1)
return -1;
return (infoPtr->buttons[nIndex].fsState & TBSTATE_PRESSED);
}
static LRESULT
TOOLBAR_LoadImages (TOOLBAR_INFO *infoPtr, WPARAM wParam, HINSTANCE hInstance)
{
TBADDBITMAP tbab;
tbab.hInst = hInstance;
tbab.nID = wParam;
TRACE("hwnd = %p, hInst = %p, nID = %lu\n", infoPtr->hwndSelf, tbab.hInst, tbab.nID);
return TOOLBAR_AddBitmap(infoPtr, 0, &tbab);
}
static LRESULT
TOOLBAR_MapAccelerator (const TOOLBAR_INFO *infoPtr, WCHAR wAccel, UINT *pIDButton)
{
WCHAR wszAccel[] = {'&',wAccel,0};
int i;
TRACE("hwnd = %p, wAccel = %x(%s), pIDButton = %p\n",
infoPtr->hwndSelf, wAccel, debugstr_wn(&wAccel,1), pIDButton);
for (i = 0; i < infoPtr->nNumButtons; i++)
{
TBUTTON_INFO *btnPtr = infoPtr->buttons+i;
if (!(btnPtr->fsStyle & BTNS_NOPREFIX) &&
!(btnPtr->fsState & TBSTATE_HIDDEN))
{
int iLen = strlenW(wszAccel);
LPCWSTR lpszStr = TOOLBAR_GetText(infoPtr, btnPtr);
if (!lpszStr)
continue;
while (*lpszStr)
{
if ((lpszStr[0] == '&') && (lpszStr[1] == '&'))
{
lpszStr += 2;
continue;
}
if (!strncmpiW(lpszStr, wszAccel, iLen))
{
*pIDButton = btnPtr->idCommand;
return TRUE;
}
lpszStr++;
}
}
}
return FALSE;
}
static LRESULT
TOOLBAR_MarkButton (const TOOLBAR_INFO *infoPtr, INT Id, BOOL fMark)
{
INT nIndex;
DWORD oldState;
TBUTTON_INFO *btnPtr;
TRACE("hwnd = %p, Id = %d, fMark = 0%d\n", infoPtr->hwndSelf, Id, fMark);
nIndex = TOOLBAR_GetButtonIndex (infoPtr, Id, FALSE);
if (nIndex == -1)
return FALSE;
btnPtr = &infoPtr->buttons[nIndex];
oldState = btnPtr->fsState;
if (fMark)
btnPtr->fsState |= TBSTATE_MARKED;
else
btnPtr->fsState &= ~TBSTATE_MARKED;
if(oldState != btnPtr->fsState)
InvalidateRect(infoPtr->hwndSelf, &btnPtr->rect, TRUE);
return TRUE;
}
/* fixes up an index of a button affected by a move */
static inline void TOOLBAR_MoveFixupIndex(INT* pIndex, INT nIndex, INT nMoveIndex, BOOL bMoveUp)
{
if (bMoveUp)
{
if (*pIndex > nIndex && *pIndex <= nMoveIndex)
(*pIndex)--;
else if (*pIndex == nIndex)
*pIndex = nMoveIndex;
}
else
{
if (*pIndex >= nMoveIndex && *pIndex < nIndex)
(*pIndex)++;
else if (*pIndex == nIndex)
*pIndex = nMoveIndex;
}
}
static LRESULT
TOOLBAR_MoveButton (TOOLBAR_INFO *infoPtr, INT Id, INT nMoveIndex)
{
INT nIndex;
INT nCount;
TBUTTON_INFO button;
TRACE("hwnd=%p, Id=%d, nMoveIndex=%d\n", infoPtr->hwndSelf, Id, nMoveIndex);
nIndex = TOOLBAR_GetButtonIndex (infoPtr, Id, TRUE);
if ((nIndex == -1) || (nMoveIndex < 0))
return FALSE;
if (nMoveIndex > infoPtr->nNumButtons - 1)
nMoveIndex = infoPtr->nNumButtons - 1;
button = infoPtr->buttons[nIndex];
/* move button right */
if (nIndex < nMoveIndex)
{
nCount = nMoveIndex - nIndex;
memmove(&infoPtr->buttons[nIndex], &infoPtr->buttons[nIndex+1], nCount*sizeof(TBUTTON_INFO));
infoPtr->buttons[nMoveIndex] = button;
TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDown, nIndex, nMoveIndex, TRUE);
TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDrag, nIndex, nMoveIndex, TRUE);
TOOLBAR_MoveFixupIndex(&infoPtr->nOldHit, nIndex, nMoveIndex, TRUE);
TOOLBAR_MoveFixupIndex(&infoPtr->nHotItem, nIndex, nMoveIndex, TRUE);
}
else if (nIndex > nMoveIndex) /* move button left */
{
nCount = nIndex - nMoveIndex;
memmove(&infoPtr->buttons[nMoveIndex+1], &infoPtr->buttons[nMoveIndex], nCount*sizeof(TBUTTON_INFO));
infoPtr->buttons[nMoveIndex] = button;
TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDown, nIndex, nMoveIndex, FALSE);
TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDrag, nIndex, nMoveIndex, FALSE);
TOOLBAR_MoveFixupIndex(&infoPtr->nOldHit, nIndex, nMoveIndex, FALSE);
TOOLBAR_MoveFixupIndex(&infoPtr->nHotItem, nIndex, nMoveIndex, FALSE);
}
TOOLBAR_LayoutToolbar(infoPtr);
TOOLBAR_AutoSize(infoPtr);
InvalidateRect(infoPtr->hwndSelf, NULL, TRUE);
return TRUE;
}
static LRESULT
TOOLBAR_PressButton (const TOOLBAR_INFO *infoPtr, INT Id, BOOL fPress)
{
TBUTTON_INFO *btnPtr;
INT nIndex;
DWORD oldState;
nIndex = TOOLBAR_GetButtonIndex (infoPtr, Id, FALSE);
if (nIndex == -1)
return FALSE;
btnPtr = &infoPtr->buttons[nIndex];
oldState = btnPtr->fsState;
if (fPress)
btnPtr->fsState |= TBSTATE_PRESSED;
else
btnPtr->fsState &= ~TBSTATE_PRESSED;
if(oldState != btnPtr->fsState)
InvalidateRect(infoPtr->hwndSelf, &btnPtr->rect, TRUE);
return TRUE;
}
/* FIXME: there might still be some confusion her between number of buttons
* and number of bitmaps */
static LRESULT
TOOLBAR_ReplaceBitmap (TOOLBAR_INFO *infoPtr, const TBREPLACEBITMAP *lpReplace)
{
HBITMAP hBitmap;
int i = 0, nOldButtons = 0, pos = 0;
int nOldBitmaps, nNewBitmaps = 0;
HIMAGELIST himlDef = 0;
TRACE("hInstOld %p nIDOld %lx hInstNew %p nIDNew %lx nButtons %x\n",
lpReplace->hInstOld, lpReplace->nIDOld, lpReplace->hInstNew, lpReplace->nIDNew,
lpReplace->nButtons);
if (lpReplace->hInstOld == HINST_COMMCTRL)
{
FIXME("changing standard bitmaps not implemented\n");
return FALSE;
}
else if (lpReplace->hInstOld != 0 && lpReplace->hInstOld != lpReplace->hInstNew)
FIXME("resources not in the current module not implemented\n");
TRACE("To be replaced hInstOld %p nIDOld %lx\n", lpReplace->hInstOld, lpReplace->nIDOld);
for (i = 0; i < infoPtr->nNumBitmapInfos; i++) {
TBITMAP_INFO *tbi = &infoPtr->bitmaps[i];
TRACE("tbimapinfo %d hInstOld %p nIDOld %x\n", i, tbi->hInst, tbi->nID);
if (tbi->hInst == lpReplace->hInstOld && tbi->nID == lpReplace->nIDOld)
{
TRACE("Found: nButtons %d hInst %p nID %x\n", tbi->nButtons, tbi->hInst, tbi->nID);
nOldButtons = tbi->nButtons;
tbi->nButtons = lpReplace->nButtons;
tbi->hInst = lpReplace->hInstNew;
tbi->nID = lpReplace->nIDNew;
TRACE("tbimapinfo changed %d hInstOld %p nIDOld %x\n", i, tbi->hInst, tbi->nID);
break;
}
pos += tbi->nButtons;
}
if (nOldButtons == 0)
{
WARN("No hinst/bitmap found! hInst %p nID %lx\n", lpReplace->hInstOld, lpReplace->nIDOld);
return FALSE;
}
/* copy the bitmap before adding it as ImageList_AddMasked modifies the
* bitmap
*/
if (lpReplace->hInstNew)
hBitmap = LoadBitmapW(lpReplace->hInstNew,(LPWSTR)lpReplace->nIDNew);
else
hBitmap = CopyImage((HBITMAP)lpReplace->nIDNew, IMAGE_BITMAP, 0, 0, 0);
himlDef = GETDEFIMAGELIST(infoPtr, 0); /* fixme: correct? */
nOldBitmaps = ImageList_GetImageCount(himlDef);
/* ImageList_Replace(GETDEFIMAGELIST(), pos, hBitmap, NULL); */
for (i = pos + nOldBitmaps - 1; i >= pos; i--)
ImageList_Remove(himlDef, i);
if (hBitmap)
{
ImageList_AddMasked (himlDef, hBitmap, comctl32_color.clrBtnFace);
nNewBitmaps = ImageList_GetImageCount(himlDef);
DeleteObject(hBitmap);
}
infoPtr->nNumBitmaps = infoPtr->nNumBitmaps - nOldBitmaps + nNewBitmaps;
TRACE(" pos %d %d old bitmaps replaced by %d new ones.\n",
pos, nOldBitmaps, nNewBitmaps);
InvalidateRect(infoPtr->hwndSelf, NULL, TRUE);
return TRUE;
}
/* helper for TOOLBAR_SaveRestoreW */
static BOOL
TOOLBAR_Save(const TBSAVEPARAMSW *lpSave)
{
FIXME("save to %s %s\n", debugstr_w(lpSave->pszSubKey),
debugstr_w(lpSave->pszValueName));
return FALSE;
}
/* helper for TOOLBAR_Restore */
static void
TOOLBAR_DeleteAllButtons(TOOLBAR_INFO *infoPtr)
{
INT i;
for (i = 0; i < infoPtr->nNumButtons; i++)
{
TOOLBAR_TooltipDelTool(infoPtr, &infoPtr->buttons[i]);
}
Free(infoPtr->buttons);
infoPtr->buttons = NULL;
infoPtr->nNumButtons = 0;
}
/* helper for TOOLBAR_SaveRestoreW */
static BOOL
TOOLBAR_Restore(TOOLBAR_INFO *infoPtr, const TBSAVEPARAMSW *lpSave)
{
LONG res;
HKEY hkey = NULL;
BOOL ret = FALSE;
DWORD dwType;
DWORD dwSize = 0;
NMTBRESTORE nmtbr;
/* restore toolbar information */
TRACE("restore from %s %s\n", debugstr_w(lpSave->pszSubKey),
debugstr_w(lpSave->pszValueName));
memset(&nmtbr, 0, sizeof(nmtbr));
res = RegOpenKeyExW(lpSave->hkr, lpSave->pszSubKey, 0,
KEY_QUERY_VALUE, &hkey);
if (!res)
res = RegQueryValueExW(hkey, lpSave->pszValueName, NULL, &dwType,
NULL, &dwSize);
if (!res && dwType != REG_BINARY)
res = ERROR_FILE_NOT_FOUND;
if (!res)
{
nmtbr.pData = Alloc(dwSize);
nmtbr.cbData = dwSize;
if (!nmtbr.pData) res = ERROR_OUTOFMEMORY;
}
if (!res)
res = RegQueryValueExW(hkey, lpSave->pszValueName, NULL, &dwType,
(LPBYTE)nmtbr.pData, &dwSize);
if (!res)
{
nmtbr.pCurrent = nmtbr.pData;
nmtbr.iItem = -1;
nmtbr.cbBytesPerRecord = sizeof(DWORD);
nmtbr.cButtons = nmtbr.cbData / nmtbr.cbBytesPerRecord;
if (!TOOLBAR_SendNotify(&nmtbr.hdr, infoPtr, TBN_RESTORE))
{
INT i;
/* remove all existing buttons as this function is designed to
* restore the toolbar to a previously saved state */
TOOLBAR_DeleteAllButtons(infoPtr);
for (i = 0; i < nmtbr.cButtons; i++)
{
nmtbr.iItem = i;
nmtbr.tbButton.iBitmap = -1;
nmtbr.tbButton.fsState = 0;
nmtbr.tbButton.fsStyle = 0;
nmtbr.tbButton.idCommand = 0;
if (*nmtbr.pCurrent == (DWORD)-1)
{
/* separator */
nmtbr.tbButton.fsStyle = TBSTYLE_SEP;
/* when inserting separators, iBitmap controls it's size.
0 sets default size (width) */
nmtbr.tbButton.iBitmap = 0;
}
else if (*nmtbr.pCurrent == (DWORD)-2)
/* hidden button */
nmtbr.tbButton.fsState = TBSTATE_HIDDEN;
else
nmtbr.tbButton.idCommand = (int)*nmtbr.pCurrent;
nmtbr.pCurrent++;
TOOLBAR_SendNotify(&nmtbr.hdr, infoPtr, TBN_RESTORE);
/* can't contain real string as we don't know whether
* the client put an ANSI or Unicode string in there */
if (!IS_INTRESOURCE(nmtbr.tbButton.iString))
nmtbr.tbButton.iString = 0;
TOOLBAR_InsertButtonT(infoPtr, -1, &nmtbr.tbButton, TRUE);
}
/* do legacy notifications */
if (infoPtr->iVersion < 5)
{
/* FIXME: send TBN_BEGINADJUST */
FIXME("send TBN_GETBUTTONINFO for each button\n");
/* FIXME: send TBN_ENDADJUST */
}
/* remove all uninitialised buttons
* note: loop backwards to avoid having to fixup i on a
* delete */
for (i = infoPtr->nNumButtons - 1; i >= 0; i--)
if (infoPtr->buttons[i].iBitmap == -1)
TOOLBAR_DeleteButton(infoPtr, i);
/* only indicate success if at least one button survived */
if (infoPtr->nNumButtons > 0) ret = TRUE;
}
}
Free (nmtbr.pData);
RegCloseKey(hkey);
return ret;
}
static LRESULT
TOOLBAR_SaveRestoreW (TOOLBAR_INFO *infoPtr, WPARAM wParam, const TBSAVEPARAMSW *lpSave)
{
if (lpSave == NULL) return 0;
if (wParam)
return TOOLBAR_Save(lpSave);
else
return TOOLBAR_Restore(infoPtr, lpSave);
}
static LRESULT
TOOLBAR_SaveRestoreA (TOOLBAR_INFO *infoPtr, WPARAM wParam, const TBSAVEPARAMSA *lpSave)
{
LPWSTR pszValueName = 0, pszSubKey = 0;
TBSAVEPARAMSW SaveW;
LRESULT result = 0;
int len;
if (lpSave == NULL) return 0;
len = MultiByteToWideChar(CP_ACP, 0, lpSave->pszSubKey, -1, NULL, 0);
pszSubKey = Alloc(len * sizeof(WCHAR));
if (pszSubKey) goto exit;
MultiByteToWideChar(CP_ACP, 0, lpSave->pszSubKey, -1, pszSubKey, len);
len = MultiByteToWideChar(CP_ACP, 0, lpSave->pszValueName, -1, NULL, 0);
pszValueName = Alloc(len * sizeof(WCHAR));
if (!pszValueName) goto exit;
MultiByteToWideChar(CP_ACP, 0, lpSave->pszValueName, -1, pszValueName, len);
SaveW.pszValueName = pszValueName;
SaveW.pszSubKey = pszSubKey;
SaveW.hkr = lpSave->hkr;
result = TOOLBAR_SaveRestoreW(infoPtr, wParam, &SaveW);
exit:
Free (pszValueName);
Free (pszSubKey);
return result;
}
static LRESULT
TOOLBAR_SetAnchorHighlight (TOOLBAR_INFO *infoPtr, BOOL bAnchor)
{
BOOL bOldAnchor = infoPtr->bAnchor;
TRACE("hwnd=%p, bAnchor = %s\n", infoPtr->hwndSelf, bAnchor ? "TRUE" : "FALSE");
infoPtr->bAnchor = bAnchor;
/* Native does not remove the hot effect from an already hot button */
return (LRESULT)bOldAnchor;
}
static LRESULT
TOOLBAR_SetBitmapSize (TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
{
HIMAGELIST himlDef = GETDEFIMAGELIST(infoPtr, 0);
short width = (short)LOWORD(lParam);
short height = (short)HIWORD(lParam);
TRACE("hwnd=%p, wParam=%ld, lParam=%ld\n", infoPtr->hwndSelf, wParam, lParam);
if (wParam != 0)
FIXME("wParam is %ld. Perhaps image list index?\n", wParam);
/* 0 width or height is changed to 1 */
if (width == 0)
width = 1;
if (height == 0)
height = 1;
if (infoPtr->nNumButtons > 0)
TRACE("%d buttons, undoc change to bitmap size : %d-%d -> %d-%d\n",
infoPtr->nNumButtons,
infoPtr->nBitmapWidth, infoPtr->nBitmapHeight, width, height);
if (width < -1 || height < -1)
{
/* Windows destroys the imagelist and seems to actually use negative
* values to compute button sizes */
FIXME("Negative bitmap sizes not supported (%d, %d)\n", width, height);
return FALSE;
}
/* width or height of -1 means no change */
if (width != -1)
infoPtr->nBitmapWidth = width;
if (height != -1)
infoPtr->nBitmapHeight = height;
if ((himlDef == infoPtr->himlInt) &&
(ImageList_GetImageCount(infoPtr->himlInt) == 0))
{
ImageList_SetIconSize(infoPtr->himlInt, infoPtr->nBitmapWidth,
infoPtr->nBitmapHeight);
}
TOOLBAR_CalcToolbar(infoPtr);
InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
return TRUE;
}
static LRESULT
TOOLBAR_SetButtonInfo (TOOLBAR_INFO *infoPtr, INT Id,
const TBBUTTONINFOW *lptbbi, BOOL isW)
{
TBUTTON_INFO *btnPtr;
INT nIndex;
RECT oldBtnRect;
if (lptbbi == NULL)
return FALSE;
if (lptbbi->cbSize < sizeof(TBBUTTONINFOW))
return FALSE;
nIndex = TOOLBAR_GetButtonIndex (infoPtr, Id, lptbbi->dwMask & TBIF_BYINDEX);
if (nIndex == -1)
return FALSE;
btnPtr = &infoPtr->buttons[nIndex];
if (lptbbi->dwMask & TBIF_COMMAND)
btnPtr->idCommand = lptbbi->idCommand;
if (lptbbi->dwMask & TBIF_IMAGE)
btnPtr->iBitmap = lptbbi->iImage;
if (lptbbi->dwMask & TBIF_LPARAM)
btnPtr->dwData = lptbbi->lParam;
if (lptbbi->dwMask & TBIF_SIZE)
btnPtr->cx = lptbbi->cx;
if (lptbbi->dwMask & TBIF_STATE)
btnPtr->fsState = lptbbi->fsState;
if (lptbbi->dwMask & TBIF_STYLE)
btnPtr->fsStyle = lptbbi->fsStyle;
if ((lptbbi->dwMask & TBIF_TEXT) && ((INT_PTR)lptbbi->pszText != -1)) {
/* iString is index, zero it to make Str_SetPtr succeed */
if (!TOOLBAR_ButtonHasString(btnPtr)) btnPtr->iString = 0;
if (isW)
Str_SetPtrW ((LPWSTR *)&btnPtr->iString, lptbbi->pszText);
else
Str_SetPtrAtoW ((LPWSTR *)&btnPtr->iString, (LPSTR)lptbbi->pszText);
}
/* save the button rect to see if we need to redraw the whole toolbar */
oldBtnRect = btnPtr->rect;
TOOLBAR_LayoutToolbar(infoPtr);
if (!EqualRect(&oldBtnRect, &btnPtr->rect))
InvalidateRect(infoPtr->hwndSelf, NULL, TRUE);
else
InvalidateRect(infoPtr->hwndSelf, &btnPtr->rect, TRUE);
return TRUE;
}
static LRESULT
TOOLBAR_SetButtonSize (TOOLBAR_INFO *infoPtr, LPARAM lParam)
{
INT cx = (short)LOWORD(lParam), cy = (short)HIWORD(lParam);
if ((cx < 0) || (cy < 0))
{
ERR("invalid parameter 0x%08x\n", (DWORD)lParam);
return FALSE;
}
TRACE("%p, cx = %d, cy = %d\n", infoPtr->hwndSelf, cx, cy);
/* The documentation claims you can only change the button size before
* any button has been added. But this is wrong.
* WINZIP32.EXE (ver 8) calls this on one of its buttons after adding
* it to the toolbar, and it checks that the return value is nonzero - mjm
* Further testing shows that we must actually perform the change too.
*/
/*
* The documentation also does not mention that if 0 is supplied for
* either size, the system changes it to the default of 24 wide and
* 22 high. Demonstrated in ControlSpy Toolbar. GLA 3/02
*/
if (cx == 0) cx = 24;
if (cy == 0) cy = 22;
cx = max(cx, infoPtr->szPadding.cx + infoPtr->nBitmapWidth);
cy = max(cy, infoPtr->szPadding.cy + infoPtr->nBitmapHeight);
infoPtr->nButtonWidth = cx;
infoPtr->nButtonHeight = cy;
infoPtr->iTopMargin = default_top_margin(infoPtr);
TOOLBAR_LayoutToolbar(infoPtr);
return TRUE;
}
static LRESULT
TOOLBAR_SetButtonWidth (TOOLBAR_INFO *infoPtr, LPARAM lParam)
{
/* if setting to current values, ignore */
if ((infoPtr->cxMin == (short)LOWORD(lParam)) &&
(infoPtr->cxMax == (short)HIWORD(lParam))) {
TRACE("matches current width, min=%d, max=%d, no recalc\n",
infoPtr->cxMin, infoPtr->cxMax);
return TRUE;
}
/* save new values */
infoPtr->cxMin = (short)LOWORD(lParam);
infoPtr->cxMax = (short)HIWORD(lParam);
/* otherwise we need to recalc the toolbar and in some cases
recalc the bounding rectangle (does DrawText w/ DT_CALCRECT
which doesn't actually draw - GA). */
TRACE("number of buttons %d, cx=%d, cy=%d, recalcing\n",
infoPtr->nNumButtons, infoPtr->cxMin, infoPtr->cxMax);
TOOLBAR_CalcToolbar (infoPtr);
InvalidateRect (infoPtr->hwndSelf, NULL, TRUE);
return TRUE;
}
static LRESULT
TOOLBAR_SetCmdId (TOOLBAR_INFO *infoPtr, INT nIndex, INT nId)
{
if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
return FALSE;
infoPtr->buttons[nIndex].idCommand = nId;
if (infoPtr->hwndToolTip) {
FIXME("change tool tip!\n");
}
return TRUE;
}
static LRESULT
TOOLBAR_SetDisabledImageList (TOOLBAR_INFO *infoPtr, WPARAM wParam, HIMAGELIST himl)
{
HIMAGELIST himlTemp;
INT id = 0;
if (infoPtr->iVersion >= 5)
id = wParam;
himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlDis,
&infoPtr->cimlDis, himl, id);
/* FIXME: redraw ? */
return (LRESULT)himlTemp;
}
static LRESULT
TOOLBAR_SetDrawTextFlags (TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
{
DWORD dwTemp;
TRACE("hwnd = %p, dwMask = 0x%08x, dwDTFlags = 0x%08x\n", infoPtr->hwndSelf, (DWORD)wParam, (DWORD)lParam);
dwTemp = infoPtr->dwDTFlags;
infoPtr->dwDTFlags =
(infoPtr->dwDTFlags & (DWORD)wParam) | (DWORD)lParam;
return (LRESULT)dwTemp;
}
/* This function differs a bit from what MSDN says it does:
* 1. lParam contains extended style flags to OR with current style
* (MSDN isn't clear on the OR bit)
* 2. wParam appears to contain extended style flags to be reset
* (MSDN says that this parameter is reserved)
*/
static LRESULT
TOOLBAR_SetExtendedStyle (TOOLBAR_INFO *infoPtr, DWORD mask, DWORD style)
{
DWORD old_style = infoPtr->dwExStyle;
TRACE("mask=0x%08x, style=0x%08x\n", mask, style);
if (mask)
infoPtr->dwExStyle = (old_style & ~mask) | (style & mask);
else
infoPtr->dwExStyle = style;
if (infoPtr->dwExStyle & ~TBSTYLE_EX_ALL)
FIXME("Unknown Toolbar Extended Style 0x%08x. Please report.\n",
(infoPtr->dwExStyle & ~TBSTYLE_EX_ALL));
if ((old_style ^ infoPtr->dwExStyle) & TBSTYLE_EX_MIXEDBUTTONS)
TOOLBAR_CalcToolbar(infoPtr);
else
TOOLBAR_LayoutToolbar(infoPtr);
TOOLBAR_AutoSize(infoPtr);
InvalidateRect(infoPtr->hwndSelf, NULL, TRUE);
return old_style;
}
static LRESULT
TOOLBAR_SetHotImageList (TOOLBAR_INFO *infoPtr, WPARAM wParam, HIMAGELIST himl)
{
HIMAGELIST himlTemp;
INT id = 0;
if (infoPtr->iVersion >= 5)
id = wParam;
TRACE("hwnd = %p, himl = %p, id = %d\n", infoPtr->hwndSelf, himl, id);
himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlHot,
&infoPtr->cimlHot, himl, id);
/* FIXME: redraw ? */
return (LRESULT)himlTemp;
}
/* Makes previous hot button no longer hot, makes the specified
* button hot and sends appropriate notifications. dwReason is one or
* more HICF_ flags. Specify nHit < 0 to make no buttons hot.
* NOTE 1: this function does not validate nHit
* NOTE 2: the name of this function is completely made up and
* not based on any documentation from Microsoft. */
static void
TOOLBAR_SetHotItemEx (TOOLBAR_INFO *infoPtr, INT nHit, DWORD dwReason)
{
if (infoPtr->nHotItem != nHit)
{
NMTBHOTITEM nmhotitem;
TBUTTON_INFO *btnPtr = NULL, *oldBtnPtr = NULL;
nmhotitem.dwFlags = dwReason;
if(infoPtr->nHotItem >= 0)
{
oldBtnPtr = &infoPtr->buttons[infoPtr->nHotItem];
nmhotitem.idOld = oldBtnPtr->idCommand;
}
else
{
nmhotitem.dwFlags |= HICF_ENTERING;
nmhotitem.idOld = 0;
}
if (nHit >= 0)
{
btnPtr = &infoPtr->buttons[nHit];
nmhotitem.idNew = btnPtr->idCommand;
}
else
{
nmhotitem.dwFlags |= HICF_LEAVING;
nmhotitem.idNew = 0;
}
/* now change the hot and invalidate the old and new buttons - if the
* parent agrees */
if (!TOOLBAR_SendNotify(&nmhotitem.hdr, infoPtr, TBN_HOTITEMCHANGE))
{
if (oldBtnPtr) {
oldBtnPtr->bHot = FALSE;
InvalidateRect(infoPtr->hwndSelf, &oldBtnPtr->rect, TRUE);
}
/* setting disabled buttons as hot fails even if the notify contains the button id */
if (btnPtr && (btnPtr->fsState & TBSTATE_ENABLED)) {
btnPtr->bHot = TRUE;
InvalidateRect(infoPtr->hwndSelf, &btnPtr->rect, TRUE);
infoPtr->nHotItem = nHit;
}
else
infoPtr->nHotItem = -1;
}
}
}
static LRESULT
TOOLBAR_SetHotItem (TOOLBAR_INFO *infoPtr, INT nHotItem)
{
INT nOldHotItem = infoPtr->nHotItem;
TRACE("hwnd = %p, nHotItem = %d\n", infoPtr->hwndSelf, nHotItem);
if (nHotItem >= infoPtr->nNumButtons)
return infoPtr->nHotItem;
if (nHotItem < 0)
nHotItem = -1;
/* NOTE: an application can still remove the hot item even if anchor
* highlighting is enabled */
TOOLBAR_SetHotItemEx(infoPtr, nHotItem, HICF_OTHER);
if (nOldHotItem < 0)
return -1;
return (LRESULT)nOldHotItem;
}
static LRESULT
TOOLBAR_SetImageList (TOOLBAR_INFO *infoPtr, WPARAM wParam, HIMAGELIST himl)
{
HIMAGELIST himlTemp;
INT oldButtonWidth = infoPtr->nButtonWidth;
INT oldBitmapWidth = infoPtr->nBitmapWidth;
INT oldBitmapHeight = infoPtr->nBitmapHeight;
INT i, id = 0;
if (infoPtr->iVersion >= 5)
id = wParam;
himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlDef,
&infoPtr->cimlDef, himl, id);
infoPtr->nNumBitmaps = 0;
for (i = 0; i < infoPtr->cimlDef; i++)
infoPtr->nNumBitmaps += ImageList_GetImageCount(infoPtr->himlDef[i]->himl);
if (!ImageList_GetIconSize(himl, &infoPtr->nBitmapWidth,
&infoPtr->nBitmapHeight))
{
infoPtr->nBitmapWidth = 1;
infoPtr->nBitmapHeight = 1;
}
if ((oldBitmapWidth != infoPtr->nBitmapWidth) || (oldBitmapHeight != infoPtr->nBitmapHeight))
{
TOOLBAR_CalcToolbar(infoPtr);
if (infoPtr->nButtonWidth < oldButtonWidth)
TOOLBAR_SetButtonSize(infoPtr, MAKELONG(oldButtonWidth, infoPtr->nButtonHeight));
}
TRACE("hwnd %p, new himl=%p, id = %d, count=%d, bitmap w=%d, h=%d\n",
infoPtr->hwndSelf, infoPtr->himlDef, id, infoPtr->nNumBitmaps,
infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
InvalidateRect(infoPtr->hwndSelf, NULL, TRUE);
return (LRESULT)himlTemp;
}
static LRESULT
TOOLBAR_SetIndent (TOOLBAR_INFO *infoPtr, INT nIndent)
{
infoPtr->nIndent = nIndent;
TRACE("\n");
/* process only on indent changing */
if(infoPtr->nIndent != nIndent)
{
infoPtr->nIndent = nIndent;
TOOLBAR_CalcToolbar (infoPtr);
InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
}
return TRUE;
}
static LRESULT
TOOLBAR_SetInsertMark (TOOLBAR_INFO *infoPtr, const TBINSERTMARK *lptbim)
{
TRACE("hwnd = %p, lptbim = { %d, 0x%08x}\n", infoPtr->hwndSelf, lptbim->iButton, lptbim->dwFlags);
if ((lptbim->dwFlags & ~TBIMHT_AFTER) != 0)
{
FIXME("Unrecognized flag(s): 0x%08x\n", (lptbim->dwFlags & ~TBIMHT_AFTER));
return 0;
}
if ((lptbim->iButton == -1) ||
((lptbim->iButton < infoPtr->nNumButtons) &&
(lptbim->iButton >= 0)))
{
infoPtr->tbim = *lptbim;
/* FIXME: don't need to update entire toolbar */
InvalidateRect(infoPtr->hwndSelf, NULL, TRUE);
}
else
ERR("Invalid button index %d\n", lptbim->iButton);
return 0;
}
static LRESULT
TOOLBAR_SetInsertMarkColor (TOOLBAR_INFO *infoPtr, COLORREF clr)
{
infoPtr->clrInsertMark = clr;
/* FIXME: don't need to update entire toolbar */
InvalidateRect(infoPtr->hwndSelf, NULL, TRUE);
return 0;
}
static LRESULT
TOOLBAR_SetMaxTextRows (TOOLBAR_INFO *infoPtr, INT nMaxRows)
{
infoPtr->nMaxTextRows = nMaxRows;
TOOLBAR_CalcToolbar(infoPtr);
return TRUE;
}
/* MSDN gives slightly wrong info on padding.
* 1. It is not only used on buttons with the BTNS_AUTOSIZE style
* 2. It is not used to create a blank area between the edge of the button
* and the text or image if TBSTYLE_LIST is set. It is used to control
* the gap between the image and text.
* 3. It is not applied to both sides. If TBSTYLE_LIST is set it is used
* to control the bottom and right borders [with the border being
* szPadding.cx - (GetSystemMetrics(SM_CXEDGE)+1)], otherwise the padding
* is shared evenly on both sides of the button.
* See blueprints in comments above TOOLBAR_MeasureButton for more info.
*/
static LRESULT
TOOLBAR_SetPadding (TOOLBAR_INFO *infoPtr, LPARAM lParam)
{
DWORD oldPad;
oldPad = MAKELONG(infoPtr->szPadding.cx, infoPtr->szPadding.cy);
infoPtr->szPadding.cx = min(LOWORD((DWORD)lParam), GetSystemMetrics(SM_CXEDGE));
infoPtr->szPadding.cy = min(HIWORD((DWORD)lParam), GetSystemMetrics(SM_CYEDGE));
TRACE("cx=%d, cy=%d\n",
infoPtr->szPadding.cx, infoPtr->szPadding.cy);
return (LRESULT) oldPad;
}
static LRESULT
TOOLBAR_SetParent (TOOLBAR_INFO *infoPtr, HWND hParent)
{
HWND hwndOldNotify;
TRACE("\n");
hwndOldNotify = infoPtr->hwndNotify;
infoPtr->hwndNotify = hParent;
return (LRESULT)hwndOldNotify;
}
static LRESULT
TOOLBAR_SetRows (TOOLBAR_INFO *infoPtr, WPARAM wParam, LPRECT lprc)
{
int rows = LOWORD(wParam);
BOOL bLarger = HIWORD(wParam);
TRACE("\n");
TRACE("Setting rows to %d (%d)\n", rows, bLarger);
if(infoPtr->nRows != rows)
{
TBUTTON_INFO *btnPtr = infoPtr->buttons;
int curColumn = 0; /* Current column */
int curRow = 0; /* Current row */
int hidden = 0; /* Number of hidden buttons */
int seps = 0; /* Number of separators */
int idealWrap = 0; /* Ideal wrap point */
int i;
BOOL wrap;
/*
Calculate new size and wrap points - Under windows, setrows will
change the dimensions if needed to show the number of requested
rows (if CCS_NORESIZE is set), or will take up the whole window
(if no CCS_NORESIZE).
Basic algorithm - If N buttons, and y rows requested, each row
contains N/y buttons.
FIXME: Handling of separators not obvious from testing results
FIXME: Take width of window into account?
*/
/* Loop through the buttons one by one counting key items */
for (i = 0; i < infoPtr->nNumButtons; i++ )
{
btnPtr[i].fsState &= ~TBSTATE_WRAP;
if (btnPtr[i].fsState & TBSTATE_HIDDEN)
hidden++;
else if (btnPtr[i].fsStyle & BTNS_SEP)
seps++;
}
/* FIXME: Separators make this quite complex */
if (seps) FIXME("Separators unhandled\n");
/* Round up so more per line, i.e., less rows */
idealWrap = (infoPtr->nNumButtons - hidden + (rows-1)) / (rows ? rows : 1);
/* Calculate ideal wrap point if we are allowed to grow, but cannot
achieve the requested number of rows. */
if (bLarger && idealWrap > 1)
{
int resRows = (infoPtr->nNumButtons + (idealWrap-1)) / idealWrap;
int moreRows = (infoPtr->nNumButtons + (idealWrap-2)) / (idealWrap-1);
if (resRows < rows && moreRows > rows)
{
idealWrap--;
TRACE("Changing idealWrap due to bLarger (now %d)\n", idealWrap);
}
}
curColumn = curRow = 0;
wrap = FALSE;
TRACE("Trying to wrap at %d (%d,%d,%d)\n", idealWrap,
infoPtr->nNumButtons, hidden, rows);
for (i = 0; i < infoPtr->nNumButtons; i++ )
{
if (btnPtr[i].fsState & TBSTATE_HIDDEN)
continue;
/* Step on, wrap if necessary or flag next to wrap */
if (!wrap) {
curColumn++;
} else {
wrap = FALSE;
curColumn = 1;
curRow++;
}
if (curColumn > (idealWrap-1)) {
wrap = TRUE;
btnPtr[i].fsState |= TBSTATE_WRAP;
}
}
TRACE("Result - %d rows\n", curRow + 1);
/* recalculate toolbar */
TOOLBAR_CalcToolbar (infoPtr);
/* Resize if necessary (Only if NORESIZE is set - odd, but basically
if NORESIZE is NOT set, then the toolbar will always be resized to
take up the whole window. With it set, sizing needs to be manual. */
if (infoPtr->dwStyle & CCS_NORESIZE) {
SetWindowPos(infoPtr->hwndSelf, NULL, 0, 0,
infoPtr->rcBound.right - infoPtr->rcBound.left,
infoPtr->rcBound.bottom - infoPtr->rcBound.top,
SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
}
/* repaint toolbar */
InvalidateRect(infoPtr->hwndSelf, NULL, TRUE);
}
/* return bounding rectangle */
if (lprc) {
lprc->left = infoPtr->rcBound.left;
lprc->right = infoPtr->rcBound.right;
lprc->top = infoPtr->rcBound.top;
lprc->bottom = infoPtr->rcBound.bottom;
}
return 0;
}
static LRESULT
TOOLBAR_SetState (TOOLBAR_INFO *infoPtr, INT Id, LPARAM lParam)
{
TBUTTON_INFO *btnPtr;
INT nIndex;
nIndex = TOOLBAR_GetButtonIndex (infoPtr, Id, FALSE);
if (nIndex == -1)
return FALSE;
btnPtr = &infoPtr->buttons[nIndex];
/* if hidden state has changed the invalidate entire window and recalc */
if ((btnPtr->fsState & TBSTATE_HIDDEN) != (LOWORD(lParam) & TBSTATE_HIDDEN)) {
btnPtr->fsState = LOWORD(lParam);
TOOLBAR_CalcToolbar (infoPtr);
InvalidateRect(infoPtr->hwndSelf, 0, TRUE);
return TRUE;
}
/* process state changing if current state doesn't match new state */
if(btnPtr->fsState != LOWORD(lParam))
{
btnPtr->fsState = LOWORD(lParam);
InvalidateRect(infoPtr->hwndSelf, &btnPtr->rect, TRUE);
}
return TRUE;
}
static LRESULT
TOOLBAR_SetStyle (TOOLBAR_INFO *infoPtr, DWORD style)
{
infoPtr->dwStyle = style;
return 0;
}
static inline LRESULT
TOOLBAR_SetToolTips (TOOLBAR_INFO *infoPtr, HWND hwndTooltip)
{
TRACE("hwnd=%p, hwndTooltip=%p\n", infoPtr->hwndSelf, hwndTooltip);
infoPtr->hwndToolTip = hwndTooltip;
return 0;
}
static LRESULT
TOOLBAR_SetUnicodeFormat (TOOLBAR_INFO *infoPtr, WPARAM wParam)
{
BOOL bTemp;
TRACE("%s hwnd=%p\n",
((BOOL)wParam) ? "TRUE" : "FALSE", infoPtr->hwndSelf);
bTemp = infoPtr->bUnicode;
infoPtr->bUnicode = (BOOL)wParam;
return bTemp;
}
static LRESULT
TOOLBAR_GetColorScheme (const TOOLBAR_INFO *infoPtr, LPCOLORSCHEME lParam)
{
lParam->clrBtnHighlight = (infoPtr->clrBtnHighlight == CLR_DEFAULT) ?
comctl32_color.clrBtnHighlight :
infoPtr->clrBtnHighlight;
lParam->clrBtnShadow = (infoPtr->clrBtnShadow == CLR_DEFAULT) ?
comctl32_color.clrBtnShadow : infoPtr->clrBtnShadow;
return 1;
}
static LRESULT
TOOLBAR_SetColorScheme (TOOLBAR_INFO *infoPtr, const COLORSCHEME *lParam)
{
TRACE("new colors Hl=%x Shd=%x, old colors Hl=%x Shd=%x\n",
lParam->clrBtnHighlight, lParam->clrBtnShadow,
infoPtr->clrBtnHighlight, infoPtr->clrBtnShadow);
infoPtr->clrBtnHighlight = lParam->clrBtnHighlight;
infoPtr->clrBtnShadow = lParam->clrBtnShadow;
InvalidateRect(infoPtr->hwndSelf, NULL, TRUE);
return 0;
}
static LRESULT
TOOLBAR_SetVersion (TOOLBAR_INFO *infoPtr, INT iVersion)
{
INT iOldVersion = infoPtr->iVersion;
infoPtr->iVersion = iVersion;
if (infoPtr->iVersion >= 5)
TOOLBAR_SetUnicodeFormat(infoPtr, TRUE);
return iOldVersion;
}
static LRESULT
TOOLBAR_GetStringA (const TOOLBAR_INFO *infoPtr, WPARAM wParam, LPSTR str)
{
WORD iString = HIWORD(wParam);
WORD buffersize = LOWORD(wParam);
LRESULT ret = -1;
TRACE("hwnd=%p, iString=%d, buffersize=%d, string=%p\n", infoPtr->hwndSelf, iString, buffersize, str);
if (iString < infoPtr->nNumStrings)
{
ret = WideCharToMultiByte(CP_ACP, 0, infoPtr->strings[iString], -1, str, buffersize, NULL, NULL);
ret--;
TRACE("returning %s\n", debugstr_a(str));
}
else
WARN("String index %d out of range (largest is %d)\n", iString, infoPtr->nNumStrings - 1);
return ret;
}
static LRESULT
TOOLBAR_GetStringW (const TOOLBAR_INFO *infoPtr, WPARAM wParam, LPWSTR str)
{
WORD iString = HIWORD(wParam);
WORD len = LOWORD(wParam)/sizeof(WCHAR) - 1;
LRESULT ret = -1;
TRACE("hwnd=%p, iString=%d, buffersize=%d, string=%p\n", infoPtr->hwndSelf, iString, LOWORD(wParam), str);
if (iString < infoPtr->nNumStrings)
{
len = min(len, strlenW(infoPtr->strings[iString]));
ret = (len+1)*sizeof(WCHAR);
if (str)
{
memcpy(str, infoPtr->strings[iString], ret);
str[len] = '\0';
}
ret = len;
TRACE("returning %s\n", debugstr_w(str));
}
else
WARN("String index %d out of range (largest is %d)\n", iString, infoPtr->nNumStrings - 1);
return ret;
}
/* UNDOCUMENTED MESSAGE: This appears to set some kind of size. Perhaps it
* is the maximum size of the toolbar? */
static LRESULT TOOLBAR_Unkwn45D(HWND hwnd, WPARAM wParam, LPARAM lParam)
{
SIZE * pSize = (SIZE*)lParam;
FIXME("hwnd=%p, wParam=0x%08lx, size.cx=%d, size.cy=%d stub!\n", hwnd, wParam, pSize->cx, pSize->cy);
return 0;
}
/* This is an extended version of the TB_SETHOTITEM message. It allows the
* caller to specify a reason why the hot item changed (rather than just the
* HICF_OTHER that TB_SETHOTITEM sends). */
static LRESULT
TOOLBAR_SetHotItem2 (TOOLBAR_INFO *infoPtr, INT nHotItem, LPARAM lParam)
{
INT nOldHotItem = infoPtr->nHotItem;
TRACE("old item=%d, new item=%d, flags=%08x\n",
nOldHotItem, nHotItem, (DWORD)lParam);
if (nHotItem < 0 || nHotItem > infoPtr->nNumButtons)
nHotItem = -1;
/* NOTE: an application can still remove the hot item even if anchor
* highlighting is enabled */
TOOLBAR_SetHotItemEx(infoPtr, nHotItem, lParam);
GetFocus();
return (nOldHotItem < 0) ? -1 : (LRESULT)nOldHotItem;
}
/* Sets the toolbar global iListGap parameter which controls the amount of
* spacing between the image and the text of buttons for TBSTYLE_LIST
* toolbars. */
static LRESULT TOOLBAR_SetListGap(TOOLBAR_INFO *infoPtr, INT iListGap)
{
TRACE("hwnd=%p iListGap=%d\n", infoPtr->hwndSelf, iListGap);
infoPtr->iListGap = iListGap;
InvalidateRect(infoPtr->hwndSelf, NULL, TRUE);
return 0;
}
/* Returns the number of maximum number of image lists associated with the
* various states. */
static LRESULT TOOLBAR_GetImageListCount(const TOOLBAR_INFO *infoPtr)
{
TRACE("hwnd=%p\n", infoPtr->hwndSelf);
return max(infoPtr->cimlDef, max(infoPtr->cimlHot, infoPtr->cimlDis));
}
static LRESULT
TOOLBAR_GetIdealSize (const TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
{
LPSIZE lpsize = (LPSIZE)lParam;
if (lpsize == NULL)
return FALSE;
/*
* Testing shows the following:
* wParam = 0 adjust cx value
* = 1 set cy value to max size.
* lParam pointer to SIZE structure
*
*/
TRACE("wParam %ld, lParam 0x%08lx -> 0x%08x 0x%08x\n",
wParam, lParam, lpsize->cx, lpsize->cy);
switch(wParam) {
case 0:
if (lpsize->cx == -1) {
/* **** this is wrong, native measures each button and sets it */
lpsize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
}
else if(HIWORD(lpsize->cx)) {
RECT rc;
HWND hwndParent = GetParent(infoPtr->hwndSelf);
GetWindowRect(infoPtr->hwndSelf, &rc);
MapWindowPoints(0, hwndParent, (LPPOINT)&rc, 2);
TRACE("mapped to (%s)\n", wine_dbgstr_rect(&rc));
lpsize->cx = max(rc.right-rc.left,
infoPtr->rcBound.right - infoPtr->rcBound.left);
}
else {
lpsize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
}
break;
case 1:
lpsize->cy = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
break;
default:
FIXME("Unknown wParam %ld\n", wParam);
return 0;
}
TRACE("set to -> 0x%08x 0x%08x\n",
lpsize->cx, lpsize->cy);
return 1;
}
static LRESULT TOOLBAR_Unkwn464(HWND hwnd, WPARAM wParam, LPARAM lParam)
{
FIXME("hwnd=%p wParam %08lx lParam %08lx\n", hwnd, wParam, lParam);
InvalidateRect(hwnd, NULL, TRUE);
return 1;
}
static LRESULT
TOOLBAR_Create (HWND hwnd, const CREATESTRUCTW *lpcs)
{
TOOLBAR_INFO *infoPtr = (TOOLBAR_INFO *)GetWindowLongPtrW(hwnd, 0);
LOGFONTW logFont;
TRACE("hwnd = %p, style=0x%08x\n", hwnd, lpcs->style);
infoPtr->dwStyle = GetWindowLongW(hwnd, GWL_STYLE);
GetClientRect(hwnd, &infoPtr->client_rect);
infoPtr->bUnicode = infoPtr->hwndNotify &&
(NFR_UNICODE == SendMessageW(hwnd, WM_NOTIFYFORMAT, (WPARAM)hwnd, NF_REQUERY));
infoPtr->hwndToolTip = NULL; /* if needed the tooltip control will be created after a WM_MOUSEMOVE */
SystemParametersInfoW (SPI_GETICONTITLELOGFONT, 0, &logFont, 0);
infoPtr->hFont = infoPtr->hDefaultFont = CreateFontIndirectW (&logFont);
OpenThemeData (hwnd, themeClass);
TOOLBAR_CheckStyle (infoPtr);
return 0;
}
static LRESULT
TOOLBAR_Destroy (TOOLBAR_INFO *infoPtr)
{
INT i;
/* delete tooltip control */
if (infoPtr->hwndToolTip)
DestroyWindow (infoPtr->hwndToolTip);
/* delete temporary buffer for tooltip text */
Free (infoPtr->pszTooltipText);
Free (infoPtr->bitmaps); /* bitmaps list */
/* delete button data */
for (i = 0; i < infoPtr->nNumButtons; i++)
if (TOOLBAR_ButtonHasString(&infoPtr->buttons[i]))
Free ((LPWSTR)infoPtr->buttons[i].iString);
Free (infoPtr->buttons);
/* delete strings */
if (infoPtr->strings) {
for (i = 0; i < infoPtr->nNumStrings; i++)
Free (infoPtr->strings[i]);
Free (infoPtr->strings);
}
/* destroy internal image list */
if (infoPtr->himlInt)
ImageList_Destroy (infoPtr->himlInt);
TOOLBAR_DeleteImageList(&infoPtr->himlDef, &infoPtr->cimlDef);
TOOLBAR_DeleteImageList(&infoPtr->himlDis, &infoPtr->cimlDis);
TOOLBAR_DeleteImageList(&infoPtr->himlHot, &infoPtr->cimlHot);
/* delete default font */
DeleteObject (infoPtr->hDefaultFont);
CloseThemeData (GetWindowTheme (infoPtr->hwndSelf));
/* free toolbar info data */
SetWindowLongPtrW (infoPtr->hwndSelf, 0, 0);
Free (infoPtr);
return 0;
}
static LRESULT
TOOLBAR_EraseBackground (TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
{
NMTBCUSTOMDRAW tbcd;
INT ret = FALSE;
DWORD ntfret;
HTHEME theme = GetWindowTheme (infoPtr->hwndSelf);
DWORD dwEraseCustDraw = 0;
/* the app has told us not to redraw the toolbar */
if (!infoPtr->bDoRedraw)
return FALSE;
if (infoPtr->dwStyle & TBSTYLE_CUSTOMERASE) {
ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
tbcd.nmcd.dwDrawStage = CDDS_PREERASE;
tbcd.nmcd.hdc = (HDC)wParam;
ntfret = TOOLBAR_SendNotify (&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
dwEraseCustDraw = ntfret & 0xffff;
/* FIXME: in general the return flags *can* be or'ed together */
switch (dwEraseCustDraw)
{
case CDRF_DODEFAULT:
break;
case CDRF_SKIPDEFAULT:
return TRUE;
default:
FIXME("[%p] response %d not handled to NM_CUSTOMDRAW (CDDS_PREERASE)\n",
infoPtr->hwndSelf, ntfret);
}
}
/* If the toolbar is "transparent" then pass the WM_ERASEBKGND up
* to my parent for processing.
*/
if (theme || (infoPtr->dwStyle & TBSTYLE_TRANSPARENT)) {
POINT pt, ptorig;
HDC hdc = (HDC)wParam;
HWND parent;
pt.x = 0;
pt.y = 0;
parent = GetParent(infoPtr->hwndSelf);
MapWindowPoints(infoPtr->hwndSelf, parent, &pt, 1);
OffsetWindowOrgEx (hdc, pt.x, pt.y, &ptorig);
ret = SendMessageW (parent, WM_ERASEBKGND, wParam, lParam);
SetWindowOrgEx (hdc, ptorig.x, ptorig.y, 0);
}
if (!ret)
ret = DefWindowProcW (infoPtr->hwndSelf, WM_ERASEBKGND, wParam, lParam);
if (dwEraseCustDraw & CDRF_NOTIFYPOSTERASE) {
ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
tbcd.nmcd.dwDrawStage = CDDS_POSTERASE;
tbcd.nmcd.hdc = (HDC)wParam;
ntfret = TOOLBAR_SendNotify (&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
dwEraseCustDraw = ntfret & 0xffff;
switch (dwEraseCustDraw)
{
case CDRF_DODEFAULT:
break;
case CDRF_SKIPDEFAULT:
return TRUE;
default:
FIXME("[%p] response %d not handled to NM_CUSTOMDRAW (CDDS_POSTERASE)\n",
infoPtr->hwndSelf, ntfret);
}
}
return ret;
}
static inline LRESULT
TOOLBAR_GetFont (const TOOLBAR_INFO *infoPtr)
{
return (LRESULT)infoPtr->hFont;
}
static void
TOOLBAR_SetRelativeHotItem(TOOLBAR_INFO *infoPtr, INT iDirection, DWORD dwReason)
{
INT i;
INT nNewHotItem = infoPtr->nHotItem;
for (i = 0; i < infoPtr->nNumButtons; i++)
{
/* did we wrap? */
if ((nNewHotItem + iDirection < 0) ||
(nNewHotItem + iDirection >= infoPtr->nNumButtons))
{
NMTBWRAPHOTITEM nmtbwhi;
nmtbwhi.idNew = infoPtr->buttons[nNewHotItem].idCommand;
nmtbwhi.iDirection = iDirection;
nmtbwhi.dwReason = dwReason;
if (TOOLBAR_SendNotify(&nmtbwhi.hdr, infoPtr, TBN_WRAPHOTITEM))
return;
}
nNewHotItem += iDirection;
nNewHotItem = (nNewHotItem + infoPtr->nNumButtons) % infoPtr->nNumButtons;
if ((infoPtr->buttons[nNewHotItem].fsState & TBSTATE_ENABLED) &&
!(infoPtr->buttons[nNewHotItem].fsStyle & BTNS_SEP))
{
TOOLBAR_SetHotItemEx(infoPtr, nNewHotItem, dwReason);
break;
}
}
}
static LRESULT
TOOLBAR_KeyDown (TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
{
NMKEY nmkey;
nmkey.nVKey = (UINT)wParam;
nmkey.uFlags = HIWORD(lParam);
if (TOOLBAR_SendNotify(&nmkey.hdr, infoPtr, NM_KEYDOWN))
return DefWindowProcW(infoPtr->hwndSelf, WM_KEYDOWN, wParam, lParam);
switch ((UINT)wParam)
{
case VK_LEFT:
case VK_UP:
TOOLBAR_SetRelativeHotItem(infoPtr, -1, HICF_ARROWKEYS);
break;
case VK_RIGHT:
case VK_DOWN:
TOOLBAR_SetRelativeHotItem(infoPtr, 1, HICF_ARROWKEYS);
break;
case VK_SPACE:
case VK_RETURN:
if ((infoPtr->nHotItem >= 0) &&
(infoPtr->buttons[infoPtr->nHotItem].fsState & TBSTATE_ENABLED))
{
SendMessageW (infoPtr->hwndNotify, WM_COMMAND,
MAKEWPARAM(infoPtr->buttons[infoPtr->nHotItem].idCommand, BN_CLICKED),
(LPARAM)infoPtr->hwndSelf);
}
break;
}
return 0;
}
static LRESULT
TOOLBAR_LButtonDblClk (TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
{
POINT pt;
BOOL button;
pt.x = (short)LOWORD(lParam);
pt.y = (short)HIWORD(lParam);
TOOLBAR_InternalHitTest (infoPtr, &pt, &button);
if (button)
TOOLBAR_LButtonDown (infoPtr, wParam, lParam);
else if (infoPtr->dwStyle & CCS_ADJUSTABLE)
TOOLBAR_Customize (infoPtr);
return 0;
}
static LRESULT
TOOLBAR_LButtonDown (TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
{
TBUTTON_INFO *btnPtr;
POINT pt;
INT nHit;
NMTOOLBARA nmtb;
NMMOUSE nmmouse;
BOOL bDragKeyPressed;
BOOL button;
TRACE("\n");
if (infoPtr->dwStyle & TBSTYLE_ALTDRAG)
bDragKeyPressed = (GetKeyState(VK_MENU) < 0);
else
bDragKeyPressed = (wParam & MK_SHIFT);
if (infoPtr->hwndToolTip)
TOOLBAR_RelayEvent (infoPtr->hwndToolTip, infoPtr->hwndSelf,
WM_LBUTTONDOWN, wParam, lParam);
pt.x = (short)LOWORD(lParam);
pt.y = (short)HIWORD(lParam);
nHit = TOOLBAR_InternalHitTest (infoPtr, &pt, &button);
if (button)
btnPtr = &infoPtr->buttons[nHit];
if (button && bDragKeyPressed && (infoPtr->dwStyle & CCS_ADJUSTABLE))
{
infoPtr->nButtonDrag = nHit;
SetCapture (infoPtr->hwndSelf);
/* If drag cursor has not been loaded, load it.
* Note: it doesn't need to be freed */
if (!hCursorDrag)
hCursorDrag = LoadCursorW(COMCTL32_hModule, (LPCWSTR)IDC_MOVEBUTTON);
SetCursor(hCursorDrag);
}
else if (button)
{
RECT arrowRect;
infoPtr->nOldHit = nHit;
CopyRect(&arrowRect, &btnPtr->rect);
arrowRect.left = max(btnPtr->rect.left, btnPtr->rect.right - DDARROW_WIDTH);
/* for EX_DRAWDDARROWS style, click must be in the drop-down arrow rect */
if ((btnPtr->fsState & TBSTATE_ENABLED) &&
((btnPtr->fsStyle & BTNS_WHOLEDROPDOWN) ||
((btnPtr->fsStyle & BTNS_DROPDOWN) &&
((TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle) && PtInRect(&arrowRect, pt)) ||
(!TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle))))))
{
LRESULT res;
/* draw in pressed state */
if (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN)
btnPtr->fsState |= TBSTATE_PRESSED;
else
btnPtr->bDropDownPressed = TRUE;
RedrawWindow(infoPtr->hwndSelf,&btnPtr->rect,0,
RDW_ERASE|RDW_INVALIDATE|RDW_UPDATENOW);
memset(&nmtb, 0, sizeof(nmtb));
nmtb.iItem = btnPtr->idCommand;
nmtb.rcButton = btnPtr->rect;
res = TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
TBN_DROPDOWN);
TRACE("TBN_DROPDOWN responded with %ld\n", res);
if (res != TBDDRET_TREATPRESSED)
{
MSG msg;
/* redraw button in unpressed state */
if (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN)
btnPtr->fsState &= ~TBSTATE_PRESSED;
else
btnPtr->bDropDownPressed = FALSE;
InvalidateRect(infoPtr->hwndSelf, &btnPtr->rect, TRUE);
/* find and set hot item
* NOTE: native doesn't do this, but that is a bug */
GetCursorPos(&pt);
ScreenToClient(infoPtr->hwndSelf, &pt);
nHit = TOOLBAR_InternalHitTest(infoPtr, &pt, &button);
if (!infoPtr->bAnchor || button)
TOOLBAR_SetHotItemEx(infoPtr, button ? nHit : TOOLBAR_NOWHERE, HICF_MOUSE | HICF_LMOUSE);
/* remove any left mouse button down or double-click messages
* so that we can get a toggle effect on the button */
while (PeekMessageW(&msg, infoPtr->hwndSelf, WM_LBUTTONDOWN, WM_LBUTTONDOWN, PM_REMOVE) ||
PeekMessageW(&msg, infoPtr->hwndSelf, WM_LBUTTONDBLCLK, WM_LBUTTONDBLCLK, PM_REMOVE))
;
return 0;
}
/* otherwise drop through and process as pushed */
}
infoPtr->bCaptured = TRUE;
infoPtr->nButtonDown = nHit;
infoPtr->bDragOutSent = FALSE;
btnPtr->fsState |= TBSTATE_PRESSED;
TOOLBAR_SetHotItemEx(infoPtr, button ? nHit : TOOLBAR_NOWHERE, HICF_MOUSE | HICF_LMOUSE);
if (btnPtr->fsState & TBSTATE_ENABLED)
InvalidateRect(infoPtr->hwndSelf, &btnPtr->rect, TRUE);
UpdateWindow(infoPtr->hwndSelf);
SetCapture (infoPtr->hwndSelf);
}
if (button)
{
memset(&nmtb, 0, sizeof(nmtb));
nmtb.iItem = btnPtr->idCommand;
TOOLBAR_SendNotify((NMHDR *)&nmtb, infoPtr, TBN_BEGINDRAG);
}
nmmouse.dwHitInfo = nHit;
/* !!! Undocumented - sends NM_LDOWN with the NMMOUSE structure. */
if (!button)
nmmouse.dwItemSpec = -1;
else
{
nmmouse.dwItemSpec = infoPtr->buttons[nmmouse.dwHitInfo].idCommand;
nmmouse.dwItemData = infoPtr->buttons[nmmouse.dwHitInfo].dwData;
}
ClientToScreen(infoPtr->hwndSelf, &pt);
nmmouse.pt = pt;
if (!TOOLBAR_SendNotify(&nmmouse.hdr, infoPtr, NM_LDOWN))
return DefWindowProcW(infoPtr->hwndSelf, WM_LBUTTONDOWN, wParam, lParam);
return 0;
}
static LRESULT
TOOLBAR_LButtonUp (TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
{
TBUTTON_INFO *btnPtr;
POINT pt;
INT nHit;
INT nOldIndex = -1;
NMHDR hdr;
NMMOUSE nmmouse;
NMTOOLBARA nmtb;
BOOL button;
if (infoPtr->hwndToolTip)
TOOLBAR_RelayEvent (infoPtr->hwndToolTip, infoPtr->hwndSelf,
WM_LBUTTONUP, wParam, lParam);
pt.x = (short)LOWORD(lParam);
pt.y = (short)HIWORD(lParam);
nHit = TOOLBAR_InternalHitTest (infoPtr, &pt, &button);
if (!infoPtr->bAnchor || button)
TOOLBAR_SetHotItemEx(infoPtr, button ? nHit : TOOLBAR_NOWHERE, HICF_MOUSE | HICF_LMOUSE);
if (infoPtr->nButtonDrag >= 0) {
RECT rcClient;
NMHDR hdr;
btnPtr = &infoPtr->buttons[infoPtr->nButtonDrag];
ReleaseCapture();
/* reset cursor */
SetCursor(LoadCursorW(NULL, (LPCWSTR)IDC_ARROW));
GetClientRect(infoPtr->hwndSelf, &rcClient);
if (PtInRect(&rcClient, pt))
{
INT nButton = -1;
if (nHit >= 0)
nButton = nHit;
else if (nHit < -1)
nButton = -nHit;
else if ((nHit == -1) && PtInRect(&infoPtr->buttons[-nHit].rect, pt))
nButton = -nHit;
if (nButton == infoPtr->nButtonDrag)
{
/* if the button is moved sightly left and we have a
* separator there then remove it */
if (pt.x < (btnPtr->rect.left + (btnPtr->rect.right - btnPtr->rect.left)/2))
{
if ((nButton > 0) && (infoPtr->buttons[nButton-1].fsStyle & BTNS_SEP))
TOOLBAR_DeleteButton(infoPtr, nButton - 1);
}
else /* else insert a separator before the dragged button */
{
TBBUTTON tbb;
memset(&tbb, 0, sizeof(tbb));
tbb.fsStyle = BTNS_SEP;
tbb.iString = -1;
TOOLBAR_InsertButtonT(infoPtr, nButton, &tbb, TRUE);
}
}
else
{
if (nButton == -1)
{
if ((infoPtr->nNumButtons > 0) && (pt.x < infoPtr->buttons[0].rect.left))
TOOLBAR_MoveButton(infoPtr, infoPtr->nButtonDrag, 0);
else
TOOLBAR_MoveButton(infoPtr, infoPtr->nButtonDrag, infoPtr->nNumButtons);
}
else
TOOLBAR_MoveButton(infoPtr, infoPtr->nButtonDrag, nButton);
}
}
else
{
TRACE("button %d dragged out of toolbar\n", infoPtr->nButtonDrag);
TOOLBAR_DeleteButton(infoPtr, infoPtr->nButtonDrag);
}
/* button under cursor changed so need to re-set hot item */
TOOLBAR_SetHotItemEx(infoPtr, button ? nHit : TOOLBAR_NOWHERE, HICF_MOUSE | HICF_LMOUSE);
infoPtr->nButtonDrag = -1;
TOOLBAR_SendNotify(&hdr, infoPtr, TBN_TOOLBARCHANGE);
}
else if (infoPtr->nButtonDown >= 0) {
btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
btnPtr->fsState &= ~TBSTATE_PRESSED;
if (btnPtr->fsStyle & BTNS_CHECK) {
if (btnPtr->fsStyle & BTNS_GROUP) {
nOldIndex = TOOLBAR_GetCheckedGroupButtonIndex (infoPtr,
nHit);
if ((nOldIndex != nHit) &&
(nOldIndex != -1))
infoPtr->buttons[nOldIndex].fsState &= ~TBSTATE_CHECKED;
btnPtr->fsState |= TBSTATE_CHECKED;
}
else {
if (btnPtr->fsState & TBSTATE_CHECKED)
btnPtr->fsState &= ~TBSTATE_CHECKED;
else
btnPtr->fsState |= TBSTATE_CHECKED;
}
}
if (nOldIndex != -1)
InvalidateRect(infoPtr->hwndSelf, &infoPtr->buttons[nOldIndex].rect, TRUE);
/*
* now we can ReleaseCapture, which triggers CAPTURECHANGED msg,
* that resets bCaptured and btn TBSTATE_PRESSED flags,
* and obliterates nButtonDown and nOldHit (see TOOLBAR_CaptureChanged)
*/
if ((infoPtr->bCaptured) && (infoPtr->nButtonDown >= 0))
ReleaseCapture ();
infoPtr->nButtonDown = -1;
/* Issue NM_RELEASEDCAPTURE to parent to let him know it is released */
TOOLBAR_SendNotify (&hdr, infoPtr,
NM_RELEASEDCAPTURE);
/* native issues TBN_ENDDRAG here, if _LBUTTONDOWN issued the
* TBN_BEGINDRAG
*/
memset(&nmtb, 0, sizeof(nmtb));
nmtb.iItem = btnPtr->idCommand;
TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
TBN_ENDDRAG);
if (btnPtr->fsState & TBSTATE_ENABLED)
{
SendMessageW (infoPtr->hwndNotify, WM_COMMAND,
MAKEWPARAM(infoPtr->buttons[nHit].idCommand, BN_CLICKED), (LPARAM)infoPtr->hwndSelf);
/* In case we have just been destroyed... */
if(!IsWindow(infoPtr->hwndSelf))
return 0;
}
}
/* !!! Undocumented - toolbar at 4.71 level and above sends
* NM_CLICK with the NMMOUSE structure. */
nmmouse.dwHitInfo = nHit;
if (!button)
nmmouse.dwItemSpec = -1;
else
{
nmmouse.dwItemSpec = infoPtr->buttons[nmmouse.dwHitInfo].idCommand;
nmmouse.dwItemData = infoPtr->buttons[nmmouse.dwHitInfo].dwData;
}
ClientToScreen(infoPtr->hwndSelf, &pt);
nmmouse.pt = pt;
if (!TOOLBAR_SendNotify((LPNMHDR)&nmmouse, infoPtr, NM_CLICK))
return DefWindowProcW(infoPtr->hwndSelf, WM_LBUTTONUP, wParam, lParam);
return 0;
}
static LRESULT
TOOLBAR_RButtonUp(TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
{
INT nHit;
NMMOUSE nmmouse;
POINT pt;
BOOL button;
pt.x = (short)LOWORD(lParam);
pt.y = (short)HIWORD(lParam);
nHit = TOOLBAR_InternalHitTest(infoPtr, &pt, &button);
nmmouse.dwHitInfo = nHit;
if (!button) {
nmmouse.dwItemSpec = -1;
} else {
nmmouse.dwItemSpec = infoPtr->buttons[nmmouse.dwHitInfo].idCommand;
nmmouse.dwItemData = infoPtr->buttons[nmmouse.dwHitInfo].dwData;
}
ClientToScreen(infoPtr->hwndSelf, &pt);
nmmouse.pt = pt;
if (!TOOLBAR_SendNotify((LPNMHDR)&nmmouse, infoPtr, NM_RCLICK))
return DefWindowProcW(infoPtr->hwndSelf, WM_RBUTTONUP, wParam, lParam);
return 0;
}
static LRESULT
TOOLBAR_RButtonDblClk( TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
{
NMHDR nmhdr;
if (!TOOLBAR_SendNotify(&nmhdr, infoPtr, NM_RDBLCLK))
return DefWindowProcW(infoPtr->hwndSelf, WM_RBUTTONDBLCLK, wParam, lParam);
return 0;
}
static LRESULT
TOOLBAR_CaptureChanged(TOOLBAR_INFO *infoPtr)
{
TBUTTON_INFO *btnPtr;
infoPtr->bCaptured = FALSE;
if (infoPtr->nButtonDown >= 0)
{
btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
btnPtr->fsState &= ~TBSTATE_PRESSED;
infoPtr->nOldHit = -1;
if (btnPtr->fsState & TBSTATE_ENABLED)
InvalidateRect(infoPtr->hwndSelf, &btnPtr->rect, TRUE);
}
return 0;
}
static LRESULT
TOOLBAR_MouseLeave (TOOLBAR_INFO *infoPtr)
{
/* don't remove hot effects when in anchor highlighting mode or when a
* drop-down button is pressed */
if (infoPtr->nHotItem >= 0 && !infoPtr->bAnchor)
{
TBUTTON_INFO *hotBtnPtr = &infoPtr->buttons[infoPtr->nHotItem];
if (!hotBtnPtr->bDropDownPressed)
TOOLBAR_SetHotItemEx(infoPtr, TOOLBAR_NOWHERE, HICF_MOUSE);
}
if (infoPtr->nOldHit < 0)
return TRUE;
/* If the last button we were over is depressed then make it not */
/* depressed and redraw it */
if(infoPtr->nOldHit == infoPtr->nButtonDown)
{
TBUTTON_INFO *btnPtr;
RECT rc1;
btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
btnPtr->fsState &= ~TBSTATE_PRESSED;
rc1 = btnPtr->rect;
InflateRect (&rc1, 1, 1);
InvalidateRect (infoPtr->hwndSelf, &rc1, TRUE);
}
if (infoPtr->bCaptured && !infoPtr->bDragOutSent)
{
NMTOOLBARW nmt;
ZeroMemory(&nmt, sizeof(nmt));
nmt.iItem = infoPtr->buttons[infoPtr->nButtonDown].idCommand;
TOOLBAR_SendNotify(&nmt.hdr, infoPtr, TBN_DRAGOUT);
infoPtr->bDragOutSent = TRUE;
}
infoPtr->nOldHit = -1; /* reset the old hit index as we've left the toolbar */
return TRUE;
}
static LRESULT
TOOLBAR_MouseMove (TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
{
POINT pt;
TRACKMOUSEEVENT trackinfo;
INT nHit;
TBUTTON_INFO *btnPtr;
BOOL button;
if ((infoPtr->dwStyle & TBSTYLE_TOOLTIPS) && (infoPtr->hwndToolTip == NULL))
TOOLBAR_TooltipCreateControl(infoPtr);
if ((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf)) {
/* fill in the TRACKMOUSEEVENT struct */
trackinfo.cbSize = sizeof(TRACKMOUSEEVENT);
trackinfo.dwFlags = TME_QUERY;
/* call _TrackMouseEvent to see if we are currently tracking for this hwnd */
_TrackMouseEvent(&trackinfo);
/* Make sure tracking is enabled so we receive a WM_MOUSELEAVE message */
if(trackinfo.hwndTrack != infoPtr->hwndSelf || !(trackinfo.dwFlags & TME_LEAVE)) {
trackinfo.dwFlags = TME_LEAVE; /* notify upon leaving */
trackinfo.hwndTrack = infoPtr->hwndSelf;
/* call TRACKMOUSEEVENT so we receive a WM_MOUSELEAVE message */
/* and can properly deactivate the hot toolbar button */
_TrackMouseEvent(&trackinfo);
}
}
if (infoPtr->hwndToolTip)
TOOLBAR_RelayEvent (infoPtr->hwndToolTip, infoPtr->hwndSelf,
WM_MOUSEMOVE, wParam, lParam);
pt.x = (short)LOWORD(lParam);
pt.y = (short)HIWORD(lParam);
nHit = TOOLBAR_InternalHitTest (infoPtr, &pt, &button);
if (((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf))
&& (!infoPtr->bAnchor || button))
TOOLBAR_SetHotItemEx(infoPtr, button ? nHit : TOOLBAR_NOWHERE, HICF_MOUSE);
if (infoPtr->nOldHit != nHit)
{
if (infoPtr->bCaptured)
{
if (!infoPtr->bDragOutSent)
{
NMTOOLBARW nmt;
ZeroMemory(&nmt, sizeof(nmt));
nmt.iItem = infoPtr->buttons[infoPtr->nButtonDown].idCommand;
TOOLBAR_SendNotify(&nmt.hdr, infoPtr, TBN_DRAGOUT);
infoPtr->bDragOutSent = TRUE;
}
btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
if (infoPtr->nOldHit == infoPtr->nButtonDown) {
btnPtr->fsState &= ~TBSTATE_PRESSED;
InvalidateRect(infoPtr->hwndSelf, &btnPtr->rect, TRUE);
}
else if (nHit == infoPtr->nButtonDown) {
btnPtr->fsState |= TBSTATE_PRESSED;
InvalidateRect(infoPtr->hwndSelf, &btnPtr->rect, TRUE);
}
infoPtr->nOldHit = nHit;
}
}
return 0;
}
static inline LRESULT
TOOLBAR_NCActivate (HWND hwnd, WPARAM wParam, LPARAM lParam)
{
/* if (wndPtr->dwStyle & CCS_NODIVIDER) */
return DefWindowProcW (hwnd, WM_NCACTIVATE, wParam, lParam);
/* else */
/* return TOOLBAR_NCPaint (wndPtr, wParam, lParam); */
}
static inline LRESULT
TOOLBAR_NCCalcSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
{
if (!(GetWindowLongW(hwnd, GWL_STYLE) & CCS_NODIVIDER))
((LPRECT)lParam)->top += GetSystemMetrics(SM_CYEDGE);
return DefWindowProcW (hwnd, WM_NCCALCSIZE, wParam, lParam);
}
static LRESULT
TOOLBAR_NCCreate (HWND hwnd, WPARAM wParam, const CREATESTRUCTW *lpcs)
{
TOOLBAR_INFO *infoPtr;
DWORD styleadd = 0;
/* allocate memory for info structure */
infoPtr = Alloc (sizeof(TOOLBAR_INFO));
SetWindowLongPtrW (hwnd, 0, (LONG_PTR)infoPtr);
/* paranoid!! */
infoPtr->dwStructSize = sizeof(TBBUTTON);
infoPtr->nRows = 1;
infoPtr->nWidth = 0;
/* initialize info structure */
infoPtr->nButtonWidth = 23;
infoPtr->nButtonHeight = 22;
infoPtr->nBitmapHeight = 16;
infoPtr->nBitmapWidth = 16;
infoPtr->nMaxTextRows = 1;
infoPtr->cxMin = -1;
infoPtr->cxMax = -1;
infoPtr->nNumBitmaps = 0;
infoPtr->nNumStrings = 0;
infoPtr->bCaptured = FALSE;
infoPtr->nButtonDown = -1;
infoPtr->nButtonDrag = -1;
infoPtr->nOldHit = -1;
infoPtr->nHotItem = -1;
infoPtr->hwndNotify = lpcs->hwndParent;
infoPtr->dwDTFlags = (lpcs->style & TBSTYLE_LIST) ? DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS: DT_CENTER | DT_END_ELLIPSIS;
infoPtr->bAnchor = FALSE; /* no anchor highlighting */
infoPtr->bDragOutSent = FALSE;
infoPtr->iVersion = 0;
infoPtr->hwndSelf = hwnd;
infoPtr->bDoRedraw = TRUE;
infoPtr->clrBtnHighlight = CLR_DEFAULT;
infoPtr->clrBtnShadow = CLR_DEFAULT;
infoPtr->szPadding.cx = DEFPAD_CX;
infoPtr->szPadding.cy = DEFPAD_CY;
infoPtr->iListGap = DEFLISTGAP;
infoPtr->iTopMargin = default_top_margin(infoPtr);
infoPtr->dwStyle = lpcs->style;
infoPtr->tbim.iButton = -1;
/* fix instance handle, if the toolbar was created by CreateToolbarEx() */
if (!GetWindowLongPtrW (hwnd, GWLP_HINSTANCE)) {
HINSTANCE hInst = (HINSTANCE)GetWindowLongPtrW (GetParent (hwnd), GWLP_HINSTANCE);
SetWindowLongPtrW (hwnd, GWLP_HINSTANCE, (LONG_PTR)hInst);
}
/* native control does:
* Get a lot of colors and brushes
* WM_NOTIFYFORMAT
* SystemParametersInfoW(0x1f, 0x3c, adr1, 0)
* CreateFontIndirectW(adr1)
* CreateBitmap(0x27, 0x24, 1, 1, 0)
* hdc = GetDC(toolbar)
* GetSystemMetrics(0x48)
* fnt2=CreateFontW(0xe, 0, 0, 0, 0x190, 0, 0, 0, 0, 2,
* 0, 0, 0, 0, "MARLETT")
* oldfnt = SelectObject(hdc, fnt2)
* GetCharWidthW(hdc, 0x36, 0x36, adr2)
* GetTextMetricsW(hdc, adr3)
* SelectObject(hdc, oldfnt)
* DeleteObject(fnt2)
* ReleaseDC(hdc)
* InvalidateRect(toolbar, 0, 1)
* SetWindowLongW(toolbar, 0, addr)
* SetWindowLongW(toolbar, -16, xxx) **sometimes**
* WM_STYLECHANGING
* CallWinEx old new
* ie 1 0x56000a4c 0x46000a4c 0x56008a4d
* ie 2 0x4600094c 0x4600094c 0x4600894d
* ie 3 0x56000b4c 0x46000b4c 0x56008b4d
* rebar 0x50008844 0x40008844 0x50008845
* pager 0x50000844 0x40000844 0x50008845
* IC35mgr 0x5400084e **nochange**
* on entry to _NCCREATE 0x5400084e
* rowlist 0x5400004e **nochange**
* on entry to _NCCREATE 0x5400004e
*
*/
/* I think the code below is a bug, but it is the way that the native
* controls seem to work. The effect is that if the user of TBSTYLE_FLAT
* forgets to specify TBSTYLE_TRANSPARENT but does specify either
* CCS_TOP or CCS_BOTTOM (_NOMOVEY and _TOP), then the control
* does *not* set TBSTYLE_TRANSPARENT even though it should!!!!
* Somehow, the only cases of this seem to be MFC programs.
*
* Note also that the addition of _TRANSPARENT occurs *only* here. It
* does not occur in the WM_STYLECHANGING routine.
* (Guy Albertelli 9/2001)
*
*/
if (((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf))
&& !(lpcs->style & TBSTYLE_TRANSPARENT))
styleadd |= TBSTYLE_TRANSPARENT;
if (!(lpcs->style & (CCS_TOP | CCS_NOMOVEY))) {
styleadd |= CCS_TOP; /* default to top */
SetWindowLongW (hwnd, GWL_STYLE, lpcs->style | styleadd);
}
return DefWindowProcW (hwnd, WM_NCCREATE, wParam, (LPARAM)lpcs);
}
static LRESULT
TOOLBAR_NCPaint (HWND hwnd, WPARAM wParam, LPARAM lParam)
{
DWORD dwStyle = GetWindowLongW(hwnd, GWL_STYLE);
RECT rcWindow;
HDC hdc;
if (dwStyle & WS_MINIMIZE)
return 0; /* Nothing to do */
DefWindowProcW (hwnd, WM_NCPAINT, wParam, lParam);
if (!(hdc = GetDCEx (hwnd, 0, DCX_USESTYLE | DCX_WINDOW)))
return 0;
if (!(dwStyle & CCS_NODIVIDER))
{
GetWindowRect (hwnd, &rcWindow);
OffsetRect (&rcWindow, -rcWindow.left, -rcWindow.top);
if( dwStyle & WS_BORDER )
InflateRect (&rcWindow, -1, -1);
DrawEdge (hdc, &rcWindow, EDGE_ETCHED, BF_TOP);
}
ReleaseDC( hwnd, hdc );
return 0;
}
/* handles requests from the tooltip control on what text to display */
static LRESULT TOOLBAR_TTGetDispInfo (TOOLBAR_INFO *infoPtr, NMTTDISPINFOW *lpnmtdi)
{
int index = TOOLBAR_GetButtonIndex(infoPtr, lpnmtdi->hdr.idFrom, FALSE);
TRACE("button index = %d\n", index);
Free (infoPtr->pszTooltipText);
infoPtr->pszTooltipText = NULL;
if (index < 0)
return 0;
if (infoPtr->bUnicode)
{
WCHAR wszBuffer[INFOTIPSIZE+1];
NMTBGETINFOTIPW tbgit;
unsigned int len; /* in chars */
wszBuffer[0] = '\0';
wszBuffer[INFOTIPSIZE] = '\0';
tbgit.pszText = wszBuffer;
tbgit.cchTextMax = INFOTIPSIZE;
tbgit.iItem = lpnmtdi->hdr.idFrom;
tbgit.lParam = infoPtr->buttons[index].dwData;
TOOLBAR_SendNotify(&tbgit.hdr, infoPtr, TBN_GETINFOTIPW);
TRACE("TBN_GETINFOTIPW - got string %s\n", debugstr_w(tbgit.pszText));
len = strlenW(tbgit.pszText);
if (len > sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0])-1)
{
/* need to allocate temporary buffer in infoPtr as there
* isn't enough space in buffer passed to us by the
* tooltip control */
infoPtr->pszTooltipText = Alloc((len+1)*sizeof(WCHAR));
if (infoPtr->pszTooltipText)
{
memcpy(infoPtr->pszTooltipText, tbgit.pszText, (len+1)*sizeof(WCHAR));
lpnmtdi->lpszText = infoPtr->pszTooltipText;
return 0;
}
}
else if (len > 0)
{
memcpy(lpnmtdi->lpszText, tbgit.pszText, (len+1)*sizeof(WCHAR));
return 0;
}
}
else
{
CHAR szBuffer[INFOTIPSIZE+1];
NMTBGETINFOTIPA tbgit;
unsigned int len; /* in chars */
szBuffer[0] = '\0';
szBuffer[INFOTIPSIZE] = '\0';
tbgit.pszText = szBuffer;
tbgit.cchTextMax = INFOTIPSIZE;
tbgit.iItem = lpnmtdi->hdr.idFrom;
tbgit.lParam = infoPtr->buttons[index].dwData;
TOOLBAR_SendNotify(&tbgit.hdr, infoPtr, TBN_GETINFOTIPA);
TRACE("TBN_GETINFOTIPA - got string %s\n", debugstr_a(tbgit.pszText));
len = MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, -1, NULL, 0);
if (len > sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0]))
{
/* need to allocate temporary buffer in infoPtr as there
* isn't enough space in buffer passed to us by the
* tooltip control */
infoPtr->pszTooltipText = Alloc(len*sizeof(WCHAR));
if (infoPtr->pszTooltipText)
{
MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, -1, infoPtr->pszTooltipText, len);
lpnmtdi->lpszText = infoPtr->pszTooltipText;
return 0;
}
}
else if (tbgit.pszText && tbgit.pszText[0])
{
MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, -1,
lpnmtdi->lpszText, sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0]));
return 0;
}
}
/* if button has text, but it is not shown then automatically
* use that text as tooltip */
if ((infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) &&
!(infoPtr->buttons[index].fsStyle & BTNS_SHOWTEXT))
{
LPWSTR pszText = TOOLBAR_GetText(infoPtr, &infoPtr->buttons[index]);
unsigned int len = pszText ? strlenW(pszText) : 0;
TRACE("using button hidden text %s\n", debugstr_w(pszText));
if (len > sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0])-1)
{
/* need to allocate temporary buffer in infoPtr as there
* isn't enough space in buffer passed to us by the
* tooltip control */
infoPtr->pszTooltipText = Alloc((len+1)*sizeof(WCHAR));
if (infoPtr->pszTooltipText)
{
memcpy(infoPtr->pszTooltipText, pszText, (len+1)*sizeof(WCHAR));
lpnmtdi->lpszText = infoPtr->pszTooltipText;
return 0;
}
}
else if (len > 0)
{
memcpy(lpnmtdi->lpszText, pszText, (len+1)*sizeof(WCHAR));
return 0;
}
}
TRACE("Sending tooltip notification to %p\n", infoPtr->hwndNotify);
/* last resort: send notification on to app */
/* FIXME: find out what is really used here */
return SendMessageW(infoPtr->hwndNotify, WM_NOTIFY, lpnmtdi->hdr.idFrom, (LPARAM)lpnmtdi);
}
static inline LRESULT
TOOLBAR_Notify (TOOLBAR_INFO *infoPtr, LPNMHDR lpnmh)
{
switch (lpnmh->code)
{
case PGN_CALCSIZE:
{
LPNMPGCALCSIZE lppgc = (LPNMPGCALCSIZE)lpnmh;
if (lppgc->dwFlag == PGF_CALCWIDTH) {
lppgc->iWidth = infoPtr->rcBound.right - infoPtr->rcBound.left;
TRACE("processed PGN_CALCSIZE, returning horz size = %d\n",
lppgc->iWidth);
}
else {
lppgc->iHeight = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
TRACE("processed PGN_CALCSIZE, returning vert size = %d\n",
lppgc->iHeight);
}
return 0;
}
case PGN_SCROLL:
{
LPNMPGSCROLL lppgs = (LPNMPGSCROLL)lpnmh;
lppgs->iScroll = (lppgs->iDir & (PGF_SCROLLLEFT | PGF_SCROLLRIGHT)) ?
infoPtr->nButtonWidth : infoPtr->nButtonHeight;
TRACE("processed PGN_SCROLL, returning scroll=%d, dir=%d\n",
lppgs->iScroll, lppgs->iDir);
return 0;
}
case TTN_GETDISPINFOW:
return TOOLBAR_TTGetDispInfo(infoPtr, (LPNMTTDISPINFOW)lpnmh);
case TTN_GETDISPINFOA:
FIXME("TTN_GETDISPINFOA - should not be received; please report\n");
return 0;
default:
return 0;
}
}
static LRESULT
TOOLBAR_NotifyFormat(const TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
{
LRESULT format;
TRACE("wParam = 0x%lx, lParam = 0x%08lx\n", wParam, lParam);
if (lParam == NF_QUERY)
return NFR_UNICODE;
if (lParam == NF_REQUERY) {
format = SendMessageW(infoPtr->hwndNotify,
WM_NOTIFYFORMAT, (WPARAM)infoPtr->hwndSelf, NF_QUERY);
if ((format != NFR_ANSI) && (format != NFR_UNICODE)) {
ERR("wrong response to WM_NOTIFYFORMAT (%ld), assuming ANSI\n",
format);
format = NFR_ANSI;
}
return format;
}
return 0;
}
static LRESULT
TOOLBAR_Paint (TOOLBAR_INFO *infoPtr, WPARAM wParam)
{
HDC hdc;
PAINTSTRUCT ps;
/* fill ps.rcPaint with a default rect */
ps.rcPaint = infoPtr->rcBound;
hdc = wParam==0 ? BeginPaint(infoPtr->hwndSelf, &ps) : (HDC)wParam;
TRACE("psrect=(%s)\n", wine_dbgstr_rect(&ps.rcPaint));
TOOLBAR_Refresh (infoPtr, hdc, &ps);
if (!wParam) EndPaint (infoPtr->hwndSelf, &ps);
return 0;
}
static LRESULT
TOOLBAR_SetFocus (TOOLBAR_INFO *infoPtr)
{
TRACE("nHotItem = %d\n", infoPtr->nHotItem);
/* make first item hot */
if (infoPtr->nNumButtons > 0)
TOOLBAR_SetHotItemEx(infoPtr, 0, HICF_OTHER);
return 0;
}
static LRESULT
TOOLBAR_SetFont(TOOLBAR_INFO *infoPtr, HFONT hFont, WORD Redraw)
{
TRACE("font=%p redraw=%d\n", hFont, Redraw);
if (hFont == 0)
infoPtr->hFont = infoPtr->hDefaultFont;
else
infoPtr->hFont = hFont;
TOOLBAR_CalcToolbar(infoPtr);
if (Redraw)
InvalidateRect(infoPtr->hwndSelf, NULL, TRUE);
return 1;
}
static LRESULT
TOOLBAR_SetRedraw (TOOLBAR_INFO *infoPtr, WPARAM wParam)
/*****************************************************
*
* Function;
* Handles the WM_SETREDRAW message.
*
* Documentation:
* According to testing V4.71 of COMCTL32 returns the
* *previous* status of the redraw flag (either 0 or 1)
* instead of the MSDN documented value of 0 if handled.
* (For laughs see the "consistency" with same function
* in rebar.)
*
*****************************************************/
{
BOOL oldredraw = infoPtr->bDoRedraw;
TRACE("set to %s\n",
(wParam) ? "TRUE" : "FALSE");
infoPtr->bDoRedraw = (BOOL) wParam;
if (wParam) {
InvalidateRect (infoPtr->hwndSelf, 0, TRUE);
}
return (oldredraw) ? 1 : 0;
}
static LRESULT
TOOLBAR_Size (TOOLBAR_INFO *infoPtr)
{
TRACE("sizing toolbar!\n");
if (infoPtr->dwExStyle & TBSTYLE_EX_HIDECLIPPEDBUTTONS)
{
RECT delta_width, delta_height, client, dummy;
DWORD min_x, max_x, min_y, max_y;
TBUTTON_INFO *btnPtr;
INT i;
GetClientRect(infoPtr->hwndSelf, &client);
if(client.right > infoPtr->client_rect.right)
{
min_x = infoPtr->client_rect.right;
max_x = client.right;
}
else
{
max_x = infoPtr->client_rect.right;
min_x = client.right;
}
if(client.bottom > infoPtr->client_rect.bottom)
{
min_y = infoPtr->client_rect.bottom;
max_y = client.bottom;
}
else
{
max_y = infoPtr->client_rect.bottom;
min_y = client.bottom;
}
SetRect(&delta_width, min_x, 0, max_x, min_y);
SetRect(&delta_height, 0, min_y, max_x, max_y);
TRACE("delta_width %s delta_height %s\n", wine_dbgstr_rect(&delta_width), wine_dbgstr_rect(&delta_height));
btnPtr = infoPtr->buttons;
for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++)
if(IntersectRect(&dummy, &delta_width, &btnPtr->rect) ||
IntersectRect(&dummy, &delta_height, &btnPtr->rect))
InvalidateRect(infoPtr->hwndSelf, &btnPtr->rect, TRUE);
}
GetClientRect(infoPtr->hwndSelf, &infoPtr->client_rect);
TOOLBAR_AutoSize(infoPtr);
return 0;
}
static LRESULT
TOOLBAR_StyleChanged (TOOLBAR_INFO *infoPtr, INT nType, const STYLESTRUCT *lpStyle)
{
if (nType == GWL_STYLE)
{
DWORD dwOldStyle = infoPtr->dwStyle;
if (lpStyle->styleNew & TBSTYLE_LIST)
infoPtr->dwDTFlags = DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS;
else
infoPtr->dwDTFlags = DT_CENTER | DT_END_ELLIPSIS;
TRACE("new style 0x%08x\n", lpStyle->styleNew);
infoPtr->dwStyle = lpStyle->styleNew;
TOOLBAR_CheckStyle (infoPtr);
if ((dwOldStyle ^ lpStyle->styleNew) & (TBSTYLE_WRAPABLE | CCS_VERT))
TOOLBAR_LayoutToolbar(infoPtr);
/* only resize if one of the CCS_* styles was changed */
if ((dwOldStyle ^ lpStyle->styleNew) & COMMON_STYLES)
{
TOOLBAR_AutoSize (infoPtr);
InvalidateRect(infoPtr->hwndSelf, NULL, TRUE);
}
}
return 0;
}
static LRESULT
TOOLBAR_SysColorChange (void)
{
COMCTL32_RefreshSysColors();
return 0;
}
/* update theme after a WM_THEMECHANGED message */
static LRESULT theme_changed (HWND hwnd)
{
HTHEME theme = GetWindowTheme (hwnd);
CloseThemeData (theme);
OpenThemeData (hwnd, themeClass);
return 0;
}
static LRESULT WINAPI
ToolbarWindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
TOOLBAR_INFO *infoPtr = (TOOLBAR_INFO *)GetWindowLongPtrW(hwnd, 0);
TRACE("hwnd=%p msg=%x wparam=%lx lparam=%lx\n",
hwnd, uMsg, /* SPY_GetMsgName(uMsg), */ wParam, lParam);
if (!infoPtr && (uMsg != WM_NCCREATE))
return DefWindowProcW( hwnd, uMsg, wParam, lParam );
switch (uMsg)
{
case TB_ADDBITMAP:
return TOOLBAR_AddBitmap (infoPtr, (INT)wParam, (TBADDBITMAP*)lParam);
case TB_ADDBUTTONSA:
case TB_ADDBUTTONSW:
return TOOLBAR_AddButtonsT (infoPtr, wParam, (LPTBBUTTON)lParam,
uMsg == TB_ADDBUTTONSW);
case TB_ADDSTRINGA:
return TOOLBAR_AddStringA (infoPtr, (HINSTANCE)wParam, lParam);
case TB_ADDSTRINGW:
return TOOLBAR_AddStringW (infoPtr, (HINSTANCE)wParam, lParam);
case TB_AUTOSIZE:
return TOOLBAR_AutoSize (infoPtr);
case TB_BUTTONCOUNT:
return TOOLBAR_ButtonCount (infoPtr);
case TB_BUTTONSTRUCTSIZE:
return TOOLBAR_ButtonStructSize (infoPtr, wParam);
case TB_CHANGEBITMAP:
return TOOLBAR_ChangeBitmap (infoPtr, wParam, LOWORD(lParam));
case TB_CHECKBUTTON:
return TOOLBAR_CheckButton (infoPtr, wParam, lParam);
case TB_COMMANDTOINDEX:
return TOOLBAR_CommandToIndex (infoPtr, wParam);
case TB_CUSTOMIZE:
return TOOLBAR_Customize (infoPtr);
case TB_DELETEBUTTON:
return TOOLBAR_DeleteButton (infoPtr, wParam);
case TB_ENABLEBUTTON:
return TOOLBAR_EnableButton (infoPtr, wParam, lParam);
case TB_GETANCHORHIGHLIGHT:
return TOOLBAR_GetAnchorHighlight (infoPtr);
case TB_GETBITMAP:
return TOOLBAR_GetBitmap (infoPtr, wParam);
case TB_GETBITMAPFLAGS:
return TOOLBAR_GetBitmapFlags ();
case TB_GETBUTTON:
return TOOLBAR_GetButton (infoPtr, wParam, (TBBUTTON*)lParam);
case TB_GETBUTTONINFOA:
case TB_GETBUTTONINFOW:
return TOOLBAR_GetButtonInfoT (infoPtr, wParam, (LPTBBUTTONINFOW)lParam,
uMsg == TB_GETBUTTONINFOW);
case TB_GETBUTTONSIZE:
return TOOLBAR_GetButtonSize (infoPtr);
case TB_GETBUTTONTEXTA:
case TB_GETBUTTONTEXTW:
return TOOLBAR_GetButtonText (infoPtr, wParam, (LPWSTR)lParam,
uMsg == TB_GETBUTTONTEXTW);
case TB_GETDISABLEDIMAGELIST:
return TOOLBAR_GetDisabledImageList (infoPtr, wParam);
case TB_GETEXTENDEDSTYLE:
return TOOLBAR_GetExtendedStyle (infoPtr);
case TB_GETHOTIMAGELIST:
return TOOLBAR_GetHotImageList (infoPtr, wParam);
case TB_GETHOTITEM:
return TOOLBAR_GetHotItem (infoPtr);
case TB_GETIMAGELIST:
return TOOLBAR_GetDefImageList (infoPtr, wParam);
case TB_GETINSERTMARK:
return TOOLBAR_GetInsertMark (infoPtr, (TBINSERTMARK*)lParam);
case TB_GETINSERTMARKCOLOR:
return TOOLBAR_GetInsertMarkColor (infoPtr);
case TB_GETITEMRECT:
return TOOLBAR_GetItemRect (infoPtr, wParam, (LPRECT)lParam);
case TB_GETMAXSIZE:
return TOOLBAR_GetMaxSize (infoPtr, (LPSIZE)lParam);
/* case TB_GETOBJECT: */ /* 4.71 */
case TB_GETPADDING:
return TOOLBAR_GetPadding (infoPtr);
case TB_GETRECT:
return TOOLBAR_GetRect (infoPtr, wParam, (LPRECT)lParam);
case TB_GETROWS:
return TOOLBAR_GetRows (infoPtr);
case TB_GETSTATE:
return TOOLBAR_GetState (infoPtr, wParam);
case TB_GETSTRINGA:
return TOOLBAR_GetStringA (infoPtr, wParam, (LPSTR)lParam);
case TB_GETSTRINGW:
return TOOLBAR_GetStringW (infoPtr, wParam, (LPWSTR)lParam);
case TB_GETSTYLE:
return TOOLBAR_GetStyle (infoPtr);
case TB_GETTEXTROWS:
return TOOLBAR_GetTextRows (infoPtr);
case TB_GETTOOLTIPS:
return TOOLBAR_GetToolTips (infoPtr);
case TB_GETUNICODEFORMAT:
return TOOLBAR_GetUnicodeFormat (infoPtr);
case TB_HIDEBUTTON:
return TOOLBAR_HideButton (infoPtr, wParam, LOWORD(lParam));
case TB_HITTEST:
return TOOLBAR_HitTest (infoPtr, (LPPOINT)lParam);
case TB_INDETERMINATE:
return TOOLBAR_Indeterminate (infoPtr, wParam, LOWORD(lParam));
case TB_INSERTBUTTONA:
case TB_INSERTBUTTONW:
return TOOLBAR_InsertButtonT(infoPtr, wParam, (TBBUTTON*)lParam,
uMsg == TB_INSERTBUTTONW);
/* case TB_INSERTMARKHITTEST: */ /* 4.71 */
case TB_ISBUTTONCHECKED:
return TOOLBAR_IsButtonChecked (infoPtr, wParam);
case TB_ISBUTTONENABLED:
return TOOLBAR_IsButtonEnabled (infoPtr, wParam);
case TB_ISBUTTONHIDDEN:
return TOOLBAR_IsButtonHidden (infoPtr, wParam);
case TB_ISBUTTONHIGHLIGHTED:
return TOOLBAR_IsButtonHighlighted (infoPtr, wParam);
case TB_ISBUTTONINDETERMINATE:
return TOOLBAR_IsButtonIndeterminate (infoPtr, wParam);
case TB_ISBUTTONPRESSED:
return TOOLBAR_IsButtonPressed (infoPtr, wParam);
case TB_LOADIMAGES:
return TOOLBAR_LoadImages (infoPtr, wParam, (HINSTANCE)lParam);
case TB_MAPACCELERATORA:
case TB_MAPACCELERATORW:
return TOOLBAR_MapAccelerator (infoPtr, wParam, (UINT*)lParam);
case TB_MARKBUTTON:
return TOOLBAR_MarkButton (infoPtr, wParam, LOWORD(lParam));
case TB_MOVEBUTTON:
return TOOLBAR_MoveButton (infoPtr, wParam, lParam);
case TB_PRESSBUTTON:
return TOOLBAR_PressButton (infoPtr, wParam, LOWORD(lParam));
case TB_REPLACEBITMAP:
return TOOLBAR_ReplaceBitmap (infoPtr, (LPTBREPLACEBITMAP)lParam);
case TB_SAVERESTOREA:
return TOOLBAR_SaveRestoreA (infoPtr, wParam, (LPTBSAVEPARAMSA)lParam);
case TB_SAVERESTOREW:
return TOOLBAR_SaveRestoreW (infoPtr, wParam, (LPTBSAVEPARAMSW)lParam);
case TB_SETANCHORHIGHLIGHT:
return TOOLBAR_SetAnchorHighlight (infoPtr, (BOOL)wParam);
case TB_SETBITMAPSIZE:
return TOOLBAR_SetBitmapSize (infoPtr, wParam, lParam);
case TB_SETBUTTONINFOA:
case TB_SETBUTTONINFOW:
return TOOLBAR_SetButtonInfo (infoPtr, wParam, (LPTBBUTTONINFOW)lParam,
uMsg == TB_SETBUTTONINFOW);
case TB_SETBUTTONSIZE:
return TOOLBAR_SetButtonSize (infoPtr, lParam);
case TB_SETBUTTONWIDTH:
return TOOLBAR_SetButtonWidth (infoPtr, lParam);
case TB_SETCMDID:
return TOOLBAR_SetCmdId (infoPtr, wParam, lParam);
case TB_SETDISABLEDIMAGELIST:
return TOOLBAR_SetDisabledImageList (infoPtr, wParam, (HIMAGELIST)lParam);
case TB_SETDRAWTEXTFLAGS:
return TOOLBAR_SetDrawTextFlags (infoPtr, wParam, lParam);
case TB_SETEXTENDEDSTYLE:
return TOOLBAR_SetExtendedStyle (infoPtr, wParam, lParam);
case TB_SETHOTIMAGELIST:
return TOOLBAR_SetHotImageList (infoPtr, wParam, (HIMAGELIST)lParam);
case TB_SETHOTITEM:
return TOOLBAR_SetHotItem (infoPtr, wParam);
case TB_SETIMAGELIST:
return TOOLBAR_SetImageList (infoPtr, wParam, (HIMAGELIST)lParam);
case TB_SETINDENT:
return TOOLBAR_SetIndent (infoPtr, wParam);
case TB_SETINSERTMARK:
return TOOLBAR_SetInsertMark (infoPtr, (TBINSERTMARK*)lParam);
case TB_SETINSERTMARKCOLOR:
return TOOLBAR_SetInsertMarkColor (infoPtr, lParam);
case TB_SETMAXTEXTROWS:
return TOOLBAR_SetMaxTextRows (infoPtr, wParam);
case TB_SETPADDING:
return TOOLBAR_SetPadding (infoPtr, lParam);
case TB_SETPARENT:
return TOOLBAR_SetParent (infoPtr, (HWND)wParam);
case TB_SETROWS:
return TOOLBAR_SetRows (infoPtr, wParam, (LPRECT)lParam);
case TB_SETSTATE:
return TOOLBAR_SetState (infoPtr, wParam, lParam);
case TB_SETSTYLE:
return TOOLBAR_SetStyle (infoPtr, lParam);
case TB_SETTOOLTIPS:
return TOOLBAR_SetToolTips (infoPtr, (HWND)wParam);
case TB_SETUNICODEFORMAT:
return TOOLBAR_SetUnicodeFormat (infoPtr, wParam);
case TB_UNKWN45D:
return TOOLBAR_Unkwn45D(hwnd, wParam, lParam);
case TB_SETHOTITEM2:
return TOOLBAR_SetHotItem2 (infoPtr, wParam, lParam);
case TB_SETLISTGAP:
return TOOLBAR_SetListGap(infoPtr, wParam);
case TB_GETIMAGELISTCOUNT:
return TOOLBAR_GetImageListCount(infoPtr);
case TB_GETIDEALSIZE:
return TOOLBAR_GetIdealSize (infoPtr, wParam, lParam);
case TB_UNKWN464:
return TOOLBAR_Unkwn464(hwnd, wParam, lParam);
/* Common Control Messages */
/* case TB_GETCOLORSCHEME: */ /* identical to CCM_ */
case CCM_GETCOLORSCHEME:
return TOOLBAR_GetColorScheme (infoPtr, (LPCOLORSCHEME)lParam);
/* case TB_SETCOLORSCHEME: */ /* identical to CCM_ */
case CCM_SETCOLORSCHEME:
return TOOLBAR_SetColorScheme (infoPtr, (LPCOLORSCHEME)lParam);
case CCM_GETVERSION:
return TOOLBAR_GetVersion (infoPtr);
case CCM_SETVERSION:
return TOOLBAR_SetVersion (infoPtr, (INT)wParam);
/* case WM_CHAR: */
case WM_CREATE:
return TOOLBAR_Create (hwnd, (CREATESTRUCTW*)lParam);
case WM_DESTROY:
return TOOLBAR_Destroy (infoPtr);
case WM_ERASEBKGND:
return TOOLBAR_EraseBackground (infoPtr, wParam, lParam);
case WM_GETFONT:
return TOOLBAR_GetFont (infoPtr);
case WM_KEYDOWN:
return TOOLBAR_KeyDown (infoPtr, wParam, lParam);
/* case WM_KILLFOCUS: */
case WM_LBUTTONDBLCLK:
return TOOLBAR_LButtonDblClk (infoPtr, wParam, lParam);
case WM_LBUTTONDOWN:
return TOOLBAR_LButtonDown (infoPtr, wParam, lParam);
case WM_LBUTTONUP:
return TOOLBAR_LButtonUp (infoPtr, wParam, lParam);
case WM_RBUTTONUP:
return TOOLBAR_RButtonUp (infoPtr, wParam, lParam);
case WM_RBUTTONDBLCLK:
return TOOLBAR_RButtonDblClk (infoPtr, wParam, lParam);
case WM_MOUSEMOVE:
return TOOLBAR_MouseMove (infoPtr, wParam, lParam);
case WM_MOUSELEAVE:
return TOOLBAR_MouseLeave (infoPtr);
case WM_CAPTURECHANGED:
return TOOLBAR_CaptureChanged(infoPtr);
case WM_NCACTIVATE:
return TOOLBAR_NCActivate (hwnd, wParam, lParam);
case WM_NCCALCSIZE:
return TOOLBAR_NCCalcSize (hwnd, wParam, lParam);
case WM_NCCREATE:
return TOOLBAR_NCCreate (hwnd, wParam, (CREATESTRUCTW*)lParam);
case WM_NCPAINT:
return TOOLBAR_NCPaint (hwnd, wParam, lParam);
case WM_NOTIFY:
return TOOLBAR_Notify (infoPtr, (LPNMHDR)lParam);
case WM_NOTIFYFORMAT:
return TOOLBAR_NotifyFormat (infoPtr, wParam, lParam);
case WM_PRINTCLIENT:
case WM_PAINT:
return TOOLBAR_Paint (infoPtr, wParam);
case WM_SETFOCUS:
return TOOLBAR_SetFocus (infoPtr);
case WM_SETFONT:
return TOOLBAR_SetFont(infoPtr, (HFONT)wParam, (WORD)lParam);
case WM_SETREDRAW:
return TOOLBAR_SetRedraw (infoPtr, wParam);
case WM_SIZE:
return TOOLBAR_Size (infoPtr);
case WM_STYLECHANGED:
return TOOLBAR_StyleChanged (infoPtr, (INT)wParam, (LPSTYLESTRUCT)lParam);
case WM_SYSCOLORCHANGE:
return TOOLBAR_SysColorChange ();
case WM_THEMECHANGED:
return theme_changed (hwnd);
/* case WM_WININICHANGE: */
case WM_CHARTOITEM:
case WM_COMMAND:
case WM_DRAWITEM:
case WM_MEASUREITEM:
case WM_VKEYTOITEM:
return SendMessageW (infoPtr->hwndNotify, uMsg, wParam, lParam);
/* We see this in Outlook Express 5.x and just does DefWindowProc */
case PGM_FORWARDMOUSE:
return DefWindowProcW (hwnd, uMsg, wParam, lParam);
default:
if ((uMsg >= WM_USER) && (uMsg < WM_APP) && !COMCTL32_IsReflectedMessage(uMsg))
ERR("unknown msg %04x wp=%08lx lp=%08lx\n",
uMsg, wParam, lParam);
return DefWindowProcW (hwnd, uMsg, wParam, lParam);
}
}
VOID
TOOLBAR_Register (void)
{
WNDCLASSW wndClass;
ZeroMemory (&wndClass, sizeof(WNDCLASSW));
wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS;
wndClass.lpfnWndProc = ToolbarWindowProc;
wndClass.cbClsExtra = 0;
wndClass.cbWndExtra = sizeof(TOOLBAR_INFO *);
wndClass.hCursor = LoadCursorW (0, (LPWSTR)IDC_ARROW);
wndClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
wndClass.lpszClassName = TOOLBARCLASSNAMEW;
RegisterClassW (&wndClass);
}
VOID
TOOLBAR_Unregister (void)
{
UnregisterClassW (TOOLBARCLASSNAMEW, NULL);
}
static HIMAGELIST TOOLBAR_InsertImageList(PIMLENTRY **pies, INT *cies, HIMAGELIST himl, INT id)
{
HIMAGELIST himlold;
PIMLENTRY c = NULL;
/* Check if the entry already exists */
c = TOOLBAR_GetImageListEntry(*pies, *cies, id);
/* If this is a new entry we must create it and insert into the array */
if (!c)
{
PIMLENTRY *pnies;
c = Alloc(sizeof(IMLENTRY));
c->id = id;
pnies = Alloc((*cies + 1) * sizeof(PIMLENTRY));
memcpy(pnies, *pies, ((*cies) * sizeof(PIMLENTRY)));
pnies[*cies] = c;
(*cies)++;
Free(*pies);
*pies = pnies;
}
himlold = c->himl;
c->himl = himl;
return himlold;
}
static VOID TOOLBAR_DeleteImageList(PIMLENTRY **pies, INT *cies)
{
int i;
for (i = 0; i < *cies; i++)
Free((*pies)[i]);
Free(*pies);
*cies = 0;
*pies = NULL;
}
static PIMLENTRY TOOLBAR_GetImageListEntry(const PIMLENTRY *pies, INT cies, INT id)
{
PIMLENTRY c = NULL;
if (pies != NULL)
{
int i;
for (i = 0; i < cies; i++)
{
if (pies[i]->id == id)
{
c = pies[i];
break;
}
}
}
return c;
}
static HIMAGELIST TOOLBAR_GetImageList(const PIMLENTRY *pies, INT cies, INT id)
{
HIMAGELIST himlDef = 0;
PIMLENTRY pie = TOOLBAR_GetImageListEntry(pies, cies, id);
if (pie)
himlDef = pie->himl;
return himlDef;
}
static BOOL TOOLBAR_GetButtonInfo(const TOOLBAR_INFO *infoPtr, NMTOOLBARW *nmtb)
{
if (infoPtr->bUnicode)
return TOOLBAR_SendNotify(&nmtb->hdr, infoPtr, TBN_GETBUTTONINFOW);
else
{
CHAR Buffer[256];
NMTOOLBARA nmtba;
BOOL bRet = FALSE;
nmtba.iItem = nmtb->iItem;
nmtba.pszText = Buffer;
nmtba.cchText = 256;
ZeroMemory(nmtba.pszText, nmtba.cchText);
if (TOOLBAR_SendNotify(&nmtba.hdr, infoPtr, TBN_GETBUTTONINFOA))
{
int ccht = strlen(nmtba.pszText);
if (ccht)
MultiByteToWideChar(CP_ACP, 0, nmtba.pszText, -1,
nmtb->pszText, nmtb->cchText);
nmtb->tbButton = nmtba.tbButton;
bRet = TRUE;
}
return bRet;
}
}
static BOOL TOOLBAR_IsButtonRemovable(const TOOLBAR_INFO *infoPtr, int iItem, const CUSTOMBUTTON *btnInfo)
{
NMTOOLBARW nmtb;
/* MSDN states that iItem is the index of the button, rather than the
* command ID as used by every other NMTOOLBAR notification */
nmtb.iItem = iItem;
memcpy(&nmtb.tbButton, &btnInfo->btn, sizeof(TBBUTTON));
return TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_QUERYDELETE);
}
|