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
|
{%MainUnit ../controls.pp}
{******************************************************************************
TControl
******************************************************************************
*****************************************************************************
This file is part of the Lazarus Component Library (LCL)
See the file COPYING.modifiedLGPL.txt, included in this distribution,
for details about the license.
*****************************************************************************
}
{$IFOPT C-}
// Uncomment for local trace
// {$C+}
// {$DEFINE ASSERT_IS_ON}
{$ENDIF}
{ $DEFINE CHECK_POSITION}
{ TLazAccessibleObjectEnumerator }
function TLazAccessibleObjectEnumerator.GetCurrent: TLazAccessibleObject;
begin
if Assigned(FCurrent) then
Result:=TLazAccessibleObject(FCurrent.Data)
else
Result := nil;
end;
{ TLazAccessibleObject }
function TLazAccessibleObject.GetHandle: PtrInt;
var
WidgetsetClass: TWSLazAccessibleObjectClass;
begin
WidgetsetClass := TWSLazAccessibleObjectClass(GetWSLazAccessibleObject());
if (WidgetsetClass <> nil) and (FHandle = 0) then
begin
FHandle := WidgetsetClass.CreateHandle(Self);
if FHandle <> 0 then
InitializeHandle();
end;
Result := FHandle;
end;
function TLazAccessibleObject.GetAccessibleValue: TCaption;
begin
Result := FAccessibleValue;
end;
function TLazAccessibleObject.GetPosition: TPoint;
begin
if (OwnerControl <> nil) and (OwnerControl.GetAccessibleObject() = Self) then
begin
Result := Point(OwnerControl.Left, OwnerControl.Top);
Exit;
end;
Result := FPosition;
end;
function TLazAccessibleObject.GetSize: TSize;
begin
if (OwnerControl <> nil) and (OwnerControl.GetAccessibleObject() = Self) then
begin
Result := Types.Size(OwnerControl.Width, OwnerControl.Height);
Exit;
end;
Result := FSize;
end;
procedure TLazAccessibleObject.SetHandle(AValue: PtrInt);
begin
if AValue = FHandle then Exit;
FHandle := AValue;
if FHandle <> 0 then
InitializeHandle();
end;
procedure TLazAccessibleObject.SetPosition(AValue: TPoint);
var
WidgetsetClass: TWSLazAccessibleObjectClass;
begin
if (FPosition.X=AValue.X) and (FPosition.Y=AValue.Y) then Exit;
FPosition := AValue;
WidgetsetClass := TWSLazAccessibleObjectClass(GetWSLazAccessibleObject());
WidgetsetClass.SetPosition(Self, AValue);
end;
procedure TLazAccessibleObject.SetSize(AValue: TSize);
var
WidgetsetClass: TWSLazAccessibleObjectClass;
begin
if (FSize.CX=AValue.CX) and (FSize.CY=AValue.CY) then Exit;
FSize := AValue;
WidgetsetClass := TWSLazAccessibleObjectClass(GetWSLazAccessibleObject());
WidgetsetClass.SetSize(Self, AValue);
end;
class procedure TLazAccessibleObject.WSRegisterClass;
begin
// inherited WSRegisterClass;
RegisterLazAccessibleObject;
end;
constructor TLazAccessibleObject.Create(AOwner: TControl);
begin
inherited Create;//(AOwner);
OwnerControl := AOwner;
FChildrenSortedForDataObject := TAvlTree.Create(@CompareLazAccessibleObjectsByDataObject);
WSRegisterClass();
end;
destructor TLazAccessibleObject.Destroy;
var
WidgetsetClass: TWSLazAccessibleObjectClass;
begin
WidgetsetClass := TWSLazAccessibleObjectClass(GetWSLazAccessibleObject());
ClearChildAccessibleObjects();
if (WidgetsetClass <> nil) and (FHandle <> 0) then
WidgetsetClass.DestroyHandle(Self);
if Assigned(Parent) then
Parent.RemoveChildAccessibleObject(self, False);
FreeAndNil(FChildrenSortedForDataObject);
inherited Destroy;
end;
function TLazAccessibleObject.HandleAllocated: Boolean;
begin
Result := FHandle <> 0;
end;
procedure TLazAccessibleObject.InitializeHandle;
var
WidgetsetClass: TWSLazAccessibleObjectClass;
begin
WidgetsetClass := TWSLazAccessibleObjectClass(GetWSLazAccessibleObject());
WidgetsetClass.SetAccessibleName(Self, FAccessibleName);
WidgetsetClass.SetAccessibleDescription(Self, FAccessibleDescription);
WidgetsetClass.SetAccessibleValue(Self, FAccessibleValue);
WidgetsetClass.SetAccessibleRole(Self, FAccessibleRole);
end;
procedure TLazAccessibleObject.SetAccessibleName(const AName: TCaption);
var
WidgetsetClass: TWSLazAccessibleObjectClass;
begin
if FAccessibleName=AName then Exit;
FAccessibleName := AName;
WidgetsetClass := TWSLazAccessibleObjectClass(GetWSLazAccessibleObject());
WidgetsetClass.SetAccessibleName(Self, AName);
end;
procedure TLazAccessibleObject.SetAccessibleDescription(const ADescription: TCaption);
var
WidgetsetClass: TWSLazAccessibleObjectClass;
begin
if FAccessibleDescription=ADescription then Exit;
FAccessibleDescription := ADescription;
WidgetsetClass := TWSLazAccessibleObjectClass(GetWSLazAccessibleObject());
WidgetsetClass.SetAccessibleDescription(Self, ADescription);
end;
procedure TLazAccessibleObject.SetAccessibleValue(const AValue: TCaption);
var
WidgetsetClass: TWSLazAccessibleObjectClass;
begin
if FAccessibleValue=AValue then Exit;
FAccessibleValue := AValue;
WidgetsetClass := TWSLazAccessibleObjectClass(GetWSLazAccessibleObject());
WidgetsetClass.SetAccessibleValue(Self, AValue);
end;
procedure TLazAccessibleObject.SetAccessibleRole(const ARole: TLazAccessibilityRole);
var
WidgetsetClass: TWSLazAccessibleObjectClass;
begin
if FAccessibleRole=ARole then Exit;
FAccessibleRole := ARole;
WidgetsetClass := TWSLazAccessibleObjectClass(GetWSLazAccessibleObject());
WidgetsetClass.SetAccessibleRole(Self, ARole);
end;
function TLazAccessibleObject.FindOwnerWinControl: TWinControl;
begin
Result := nil;
if OwnerControl is TWinControl then Exit(TWinControl(OwnerControl));
if OwnerControl is TControl then Exit(OwnerControl.Parent);
if Self.Parent = nil then Exit;
Result := Self.Parent.FindOwnerWinControl();
end;
function TLazAccessibleObject.AddChildAccessibleObject(
ADataObject: TObject = nil): TLazAccessibleObject;begin
Result := nil;
if FChildrenSortedForDataObject = nil then Exit;
if (ADataObject <> nil) then begin
Result := GetChildAccessibleObjectWithDataObject(ADataObject);
if Result <> nil then
Exit;
end;
Result := TLazAccessibleObject.Create(OwnerControl);
Result.Parent := Self;
Result.DataObject := ADataObject;
FChildrenSortedForDataObject.Add(Result);
//DebugLn('[TControl.AddChildAccessibleObject] Name=%s', [Name]);
end;
procedure TLazAccessibleObject.InsertChildAccessibleObject(
AObject: TLazAccessibleObject);
begin
if FChildrenSortedForDataObject = nil then Exit;
if (AObject.Parent <> nil) and (AObject.Parent <> Self) then
AObject.Parent.RemoveChildAccessibleObject(AObject, False);
AObject.Parent := Self;
if (FChildrenSortedForDataObject.Find(AObject) <> nil) then exit;
FChildrenSortedForDataObject.Add(AObject);
end;
procedure TLazAccessibleObject.ClearChildAccessibleObjects;
var
lXObject: TLazAccessibleObject;
AVLNode: TAvlTreeNode;
begin
if FChildrenSortedForDataObject = nil then Exit;
//DebugLn(Format('[TControl.ClearChildAccessibleObjects] Name=%s Count=%d', [Name, FAccessibleChildren.Count]));
// Free only the non-control children
AVLNode:=FChildrenSortedForDataObject.FindLowest;
while AVLNode<>nil do begin
lXObject := TLazAccessibleObject(AVLNode.Data);
if lXObject.OwnerControl = OwnerControl then begin
lXObject.Parent := nil; // Clear parent so .Free doesn't recurse
lXObject.Free;
end;
AVLNode:=FChildrenSortedForDataObject.FindSuccessor(AVLNode);
end;
FChildrenSortedForDataObject.Clear;
end;
procedure TLazAccessibleObject.RemoveChildAccessibleObject(
AObject: TLazAccessibleObject; AFreeObject: Boolean = True);
var
Node: TAvlTreeNode;
begin
if FChildrenSortedForDataObject = nil then Exit;
if Assigned(AObject.Parent) then
AObject.Parent := nil;
Node:=FChildrenSortedForDataObject.Find(AObject);
if Node=nil then exit;
FChildrenSortedForDataObject.Delete(Node);
if AFreeObject then
AObject.Free;
end;
function TLazAccessibleObject.GetChildAccessibleObjectWithDataObject(
ADataObject: TObject): TLazAccessibleObject;
var
Node: TAvlTreeNode;
begin
Result := nil;
if FChildrenSortedForDataObject = nil then Exit;
Node:=FChildrenSortedForDataObject.FindKey(ADataObject,@CompareDataObjectWithLazAccessibleObject);
if Node<>nil then
Result:=TLazAccessibleObject(Node.Data);
end;
function TLazAccessibleObject.GetChildAccessibleObjectsCount: Integer;
begin
Result := 0;
if FChildrenSortedForDataObject <> nil then
Result := FChildrenSortedForDataObject.Count;
end;
function TLazAccessibleObject.GetChildAccessibleObject(AIndex: Integer): TLazAccessibleObject;
var
lNode: TAvlTreeNode = nil;
begin
Result := nil;
if AIndex = 0 then lNode := FChildrenSortedForDataObject.FindLowest()
else if AIndex = GetChildAccessibleObjectsCount()-1 then
lNode := FChildrenSortedForDataObject.FindHighest()
else if AIndex = FLastSearchIndex then lNode := FLastSearchNode
else if AIndex = FLastSearchIndex+1 then
lNode := FChildrenSortedForDataObject.FindSuccessor(FLastSearchNode)
else if AIndex = FLastSearchIndex-1 then
lNode := FChildrenSortedForDataObject.FindPrecessor(FLastSearchNode);
FLastSearchIndex := AIndex;
FLastSearchNode := lNode;
if lNode = nil then Exit;
Result := TLazAccessibleObject(lNode.Data);
end;
function TLazAccessibleObject.GetFirstChildAccessibleObject: TLazAccessibleObject;
begin
Result := nil;
FLastSearchInSubcontrols := False;
if GetChildAccessibleObjectsCount() > 0 then
Result := GetChildAccessibleObject(0)
else if OwnerControl is TWinControl then
begin
FLastSearchIndex := 1;
FLastSearchInSubcontrols := True;
if (TWinControl(OwnerControl).ControlCount > 0) then
Result := TWinControl(OwnerControl).Controls[0].GetAccessibleObject();
end;
end;
function TLazAccessibleObject.GetNextChildAccessibleObject: TLazAccessibleObject;
begin
Result := nil;
if not FLastSearchInSubcontrols then
begin
if FLastSearchIndex < GetChildAccessibleObjectsCount() then
Result := GetChildAccessibleObject(FLastSearchIndex + 1)
else if OwnerControl is TWinControl then
begin
FLastSearchIndex := 1;
FLastSearchInSubcontrols := True;
if (TWinControl(OwnerControl).ControlCount > 0) then
Result := TWinControl(OwnerControl).Controls[0].GetAccessibleObject();
end;
end
else
begin
if TWinControl(OwnerControl).ControlCount > FLastSearchIndex then
begin
Result := TWinControl(OwnerControl).Controls[FLastSearchIndex].GetAccessibleObject();
Inc(FLastSearchIndex);
end;
end;
end;
function TLazAccessibleObject.GetSelectedChildAccessibleObject: TLazAccessibleObject;
begin
Result := nil;
if OwnerControl = nil then Exit;
Result := OwnerControl.GetSelectedChildAccessibleObject();
end;
function TLazAccessibleObject.GetChildAccessibleObjectAtPos(APos: TPoint): TLazAccessibleObject;
begin
Result := nil;
if OwnerControl = nil then Exit;
Result := OwnerControl.GetChildAccessibleObjectAtPos(APos);
end;
function TLazAccessibleObject.GetEnumerator: TLazAccessibleObjectEnumerator;
begin
Result:=TLazAccessibleObjectEnumerator.Create(FChildrenSortedForDataObject);
end;
{------------------------------------------------------------------------------
TControl.AdjustSize
Calls DoAutoSize smart.
During loading and handle creation the calls are delayed.
This method does the same as TWinControl.DoAutoSize at the beginning.
But since DoAutoSize is commonly overriden by existing Delphi components,
they do not all tests, which can result in too much overhead. To reduce this
the LCL calls AdjustSize instead.
------------------------------------------------------------------------------}
procedure TControl.AdjustSize;
procedure RaiseLoop;
begin
raise ELayoutException.Create('TControl.AdjustSize loop detected '+DbgSName(Self)+' Bounds='+dbgs(BoundsRect));
end;
begin
{$IFDEF VerboseAdjustSize}
if (not (cfAutoSizeNeeded in FControlFlags))
and (Parent=nil)
and (Self is TCustomForm)
then begin
DebugLn(['TControl.AdjustSize ',DbgSName(Self)]);
end;
{$ENDIF}
Include(FControlFlags, cfAutoSizeNeeded);
if IsControlVisible then
begin
if Parent <> nil then
Parent.AdjustSize
else begin
if cfKillAdjustSize in FControlFlags then
RaiseLoop;
if not AutoSizeDelayed then
DoAllAutoSize;
end;
end;
end;
{------------------------------------------------------------------------------
Method: TControl.BeginDrag
Params: Immediate: Drag behaviour
Threshold: distance to move before dragging starts
-1 uses the default value of DragManager.DragThreshold
Returns: Nothing
Starts the dragging of a control. If the Immediate flag is set, dragging
starts immediately. A drag-dock should not normally start immediately!
------------------------------------------------------------------------------}
procedure TControl.BeginDrag(Immediate: Boolean; Threshold: Integer);
begin
DragManager.DragStart(Self, Immediate, Threshold);
end;
procedure TControl.EndDrag(Drop: Boolean);
begin
if Dragging then
DragManager.DragStop(Drop);
end;
{------------------------------------------------------------------------------
TControl.BeginAutoDrag
------------------------------------------------------------------------------}
procedure TControl.BeginAutoDrag;
begin
{$IFDEF VerboseDrag}
debugln(['TControl.BeginAutoDrag ',DbgSName(Self)]);
{$ENDIF}
BeginDrag(DragManager.DragImmediate, DragManager.DragThreshold);
end;
{------------------------------------------------------------------------------
TControl.BeginAutoSizing
------------------------------------------------------------------------------}
procedure TControl.BeginAutoSizing;
procedure Error;
begin
RaiseGDBException('TControl.BeginAutoSizing');
end;
begin
if FAutoSizingSelf then Error;
FAutoSizingSelf := True;
end;
{------------------------------------------------------------------------------
procedure TControl.DoEndDock(Target: TObject; X, Y: Integer);
------------------------------------------------------------------------------}
procedure TControl.DoEndDock(Target: TObject; X, Y: Integer);
begin
if Assigned(FOnEndDock) then
FOnEndDock(Self,Target,X,Y);
end;
{------------------------------------------------------------------------------
procedure TControl.DoDock(NewDockSite: TWinControl; var ARect: TRect);
------------------------------------------------------------------------------}
procedure TControl.DoDock(NewDockSite: TWinControl; var ARect: TRect);
begin
if (NewDockSite = nil) then Parent := nil;
if NewDockSite<>nil then begin
//DebugLn('TControl.DoDock BEFORE Adjusting ',DbgSName(Self),' ',dbgs(ARect));
// adjust new bounds, so that they at least fit into the client area of
// its parent
if NewDockSite.AutoSize then begin
case align of
alLeft,
alRight : ARect:=Rect(0,0,Width,NewDockSite.ClientHeight);
alTop,
alBottom : ARect:=Rect(0,0,NewDockSite.ClientWidth,Height);
else
ARect:=Rect(0,0,Width,Height);
end;
end else begin
MoveRectToFit(ARect, NewDockSite.GetLogicalClientRect);
// consider Align to increase chance the width/height is kept
case Align of
alLeft: Types.OffsetRect(ARect,-ARect.Left,0);
alTop: Types.OffsetRect(ARect,0,-ARect.Top);
alRight: Types.OffsetRect(ARect,NewDockSite.ClientWidth-ARect.Right,0);
alBottom: Types.OffsetRect(ARect,0,NewDockSite.ClientHeight-ARect.Bottom);
end;
end;
//DebugLn('TControl.DoDock AFTER Adjusting ',DbgSName(Self),' ',dbgs(ARect),' Align=',DbgS(Align),' NewDockSite.ClientRect=',dbgs(NewDockSite.ClientRect));
end;
//debugln('TControl.DoDock BEFORE MOVE ',Name,' BoundsRect=',dbgs(BoundsRect),' NewRect=',dbgs(ARect));
if Parent<>NewDockSite then
BoundsRectForNewParent := ARect
else
BoundsRect := ARect;
//debugln('TControl.DoDock AFTER MOVE ',DbgSName(Self),' BoundsRect=',dbgs(BoundsRect),' TriedRect=',dbgs(ARect));
end;
{------------------------------------------------------------------------------
procedure TControl.DoStartDock(var DragObject: TDragObject);
------------------------------------------------------------------------------}
procedure TControl.DoStartDock(var DragObject: TDragObject);
begin
if Assigned(FOnStartDock) then
FOnStartDock(Self,TDragDockObject(DragObject));
end;
{------------------------------------------------------------------------------
function TControl.GetDockEdge(const MousePos: TPoint): TAlign;
Calculate the dock side depending on current MousePos.
Important: MousePos is relative to this control's Left, Top.
------------------------------------------------------------------------------}
function TControl.GetDockEdge(const MousePos: TPoint): TAlign;
var
BestDistance: Integer;
procedure FindMinDistance(CurAlign: TAlign; CurDistance: integer);
begin
if CurDistance<0 then
CurDistance:=-CurDistance;
if CurDistance>=BestDistance then exit;
Result:=CurAlign;
BestDistance:=CurDistance;
end;
begin
Result:=alNone;
BestDistance:=High(Integer);
FindMinDistance(alLeft,MousePos.X);
FindMinDistance(alRight,Width-MousePos.X);
FindMinDistance(alTop,MousePos.Y);
FindMinDistance(alBottom,Height-MousePos.Y);
end;
{------------------------------------------------------------------------------
function TControl.GetDragImages: TDragImageList;
Returns Drag image list that will be used while drag opetations
------------------------------------------------------------------------------}
function TControl.GetDragImages: TDragImageList;
begin
Result := nil;
end;
{------------------------------------------------------------------------------
procedure TControl.PositionDockRect(DragDockObject: TDragDockObject);
------------------------------------------------------------------------------}
procedure TControl.PositionDockRect(DragDockObject: TDragDockObject);
var
WinDragTarget: TWinControl;
begin
with DragDockObject do
begin
if (DragTarget is TWinControl) and TWinControl(DragTarget).UseDockManager then
begin
WinDragTarget := TWinControl(DragTarget);
GetWindowRect(WinDragTarget.Handle, FDockRect);
if (WinDragTarget.DockManager <> nil) then
WinDragTarget.DockManager.PositionDockRect(DragDockObject);
end else
begin
with FDockRect do
begin
Left := DragPos.X;
Top := DragPos.Y;
Right := Left + Control.UndockWidth;
Bottom := Top + Control.UndockHeight;
end;
// let user adjust dock rect
AdjustDockRect(FDockRect);
end;
end;
end;
{------------------------------------------------------------------------------
TControl.BoundsChanged
------------------------------------------------------------------------------}
procedure TControl.BoundsChanged;
begin
{ Notifications can be performed here }
end;
{------------------------------------------------------------------------------
TControl.Bringtofront
------------------------------------------------------------------------------}
procedure TControl.BringToFront;
begin
SetZOrder(true);
end;
{------------------------------------------------------------------------------
TControl.CanTab
------------------------------------------------------------------------------}
function TControl.CanTab: Boolean;
begin
Result := False;
end;
{------------------------------------------------------------------------------
TControl.Change
------------------------------------------------------------------------------}
procedure TControl.Changed;
begin
Perform(CM_CHANGED, 0, LParam(self));
end;
{------------------------------------------------------------------------------
TControl.EditingDone
Called when user has finished editing. This procedure can be used by data
links to commit the changes.
For example:
- When focus switches to another control (default)
- When user selected another item
It's totally up to the control, what events will commit.
------------------------------------------------------------------------------}
procedure TControl.EditingDone;
begin
if Assigned(OnEditingDone) then OnEditingDone(Self);
end;
procedure TControl.FontChanged(Sender: TObject);
begin
FParentFont := False;
FDesktopFont := False;
Invalidate;
Perform(CM_FONTCHANGED, 0, 0);
if AutoSize then
begin
InvalidatePreferredSize;
AdjustSize;
end;
end;
procedure TControl.ParentFontChanged;
begin
//kept for compatibility. The real work is done in CMParentFontChanged
end;
procedure TControl.SetAction(Value: TBasicAction);
begin
//debugln('TControl.SetAction A ',Name,':',ClassName,' Old=',DbgS(Action),' New=',DbgS(Value));
if Value = nil then
begin
ActionLink.Free;
ActionLink := nil;
Exclude(FControlStyle, csActionClient);
end
else
begin
Include(FControlStyle, csActionClient);
if ActionLink = nil then
ActionLink := GetActionLinkClass.Create(Self);
ActionLink.Action := Value;
ActionLink.OnChange := @DoActionChange;
ActionChange(Value, csLoading in Value.ComponentState);
Value.FreeNotification(Self);
end;
end;
{------------------------------------------------------------------------------
TControl.ChangeBounds
------------------------------------------------------------------------------}
procedure TControl.ChangeBounds(ALeft, ATop, AWidth, AHeight: Integer; KeepBase: Boolean);
var
SizeChanged, PosChanged : boolean;
OldLeft, OldTop, OldWidth, OldHeight: Integer;
function PosSizeChanged: boolean;
begin
SizeChanged:= (FWidth <> OldWidth) or (FHeight <> OldHeight);
PosChanged:= (FLeft <> OldLeft) or (FTop <> OldTop);
Result:= SizeChanged or PosChanged;
end;
procedure DebugInvalidPos(N: integer);
begin
if (FLeft < Low(Smallint)) or (FLeft > High(Smallint))
or (FTop < Low(Smallint)) or (FTop > High(Smallint)) then
DebugLn(['TControl.ChangeBounds test(',N,')',DbgSName(Self),
' Old=',OldLeft,',',OldTop,',',OldWidth,',',OldHeight,
' New=',ALeft,',',ATop,',',AWidth,',',AHeight,
' Real=',FLeft,',',FTop,',',FWidth,',',FHeight]);
end;
begin
{$IFDEF VerboseSizeMsg}
DebugLn(['TControl.ChangeBounds A ',DbgSName(Self),
' Old=',Left,',',Top,',',Width,',',Height,
' New=',ALeft,',',ATop,',',AWidth,',',AHeight,
' KeepBase=',KeepBase]);
//if (Parent=nil) and (Left>0) and (ALeft=0) then DumpStack; // This can happen if the interface has not yet moved the window and for some reason something applies the interface coords back to the LCL
{$ENDIF}
if Assigned(Parent) and not KeepBase then
Parent.UpdateAlignIndex(Self);
// constraint the size
DoConstrainedResize(ALeft, ATop, AWidth, AHeight);
// check if something would change
SizeChanged := (FWidth <> AWidth) or (FHeight <> AHeight);
PosChanged := (FLeft <> ALeft) or (FTop <> ATop);
if not (SizeChanged or PosChanged) then Exit;
// check for loop.
if (not KeepBase) and (cfKillChangeBounds in GetTopParent.FControlFlags) then
raise ELayoutException.CreateFmt('TControl.ChangeBounds loop detected %s '+
'Left=%d,Top=%d,Width=%d,Height=%d NewLeft=%d,NewTop=%d,NewWidth=%d,NewHeight=%d',
[DbgSName(Self), Left,Top,Width,Height, aLeft,aTop,aWidth,aHeight]);
OldLeft := FLeft;
OldTop := FTop;
OldWidth := FWidth;
OldHeight := FHeight;
//DebugLn('TControl.ChangeBounds A ',DbgSName(Self),' Old=',dbgs(BoundsRect),' New=',dbgs(Bounds(ALeft,ATop,AWidth,AHeight)));
if not ((csLoading in ComponentState) or (Self is TWinControl)) then
InvalidateControl(IsControlVisible, False, true);
//DebugLn('TControl.ChangeBounds B ',Name,':',ClassName);
DoSetBounds(ALeft, ATop, AWidth, AHeight);
DebugInvalidPos(1);
// change base bounds
// (base bounds are the base for the automatic resizing)
if not KeepBase then
UpdateAnchorRules;
DebugInvalidPos(2);
// lock size messages
inc(FSizeLock);
try
// notify before autosizing
BoundsChanged;
if not PosSizeChanged then exit;
if (Parent<>nil) or SizeChanged then
AdjustSize;
finally
dec(FSizeLock);
end;
if not PosSizeChanged then exit;
DebugInvalidPos(3);
// send messages, if this is the top level call
if FSizeLock > 0 then exit;
// invalidate
if (csDesigning in ComponentState) and (Parent <> nil) then
Parent.Invalidate
else
if (not (csLoading in ComponentState)) and (not (Self is TWinControl)) then
Invalidate;
DebugInvalidPos(4);
// notify user about resize
if (not (csLoading in ComponentState)) then
begin
Resize;
DebugInvalidPos(5);
CheckOnChangeBounds;
DebugInvalidPos(6);
// for delphi compatibility send size/move messages
if PosSizeChanged then
SendMoveSizeMessages(SizeChanged,PosChanged);
end;
end;
{-------------------------------------------------------------------------------
TControl.DoSetBounds
Params: ALeft, ATop, AWidth, AHeight : integer
store bounds in private variables
-------------------------------------------------------------------------------}
procedure TControl.DoSetBounds(ALeft, ATop, AWidth, AHeight: Integer);
procedure BoundsOutOfBounds;
begin
DebugLn('TControl.DoSetBounds ',Name,':',ClassName,
' Old=',dbgs(Left,Top,Width,Height),
' New=',dbgs(aLeft,aTop,aWidth,aHeight),
'');
RaiseGDBException('TControl.DoSetBounds '+Name+':'+ClassName+' Invalid bounds');
end;
begin
if (AWidth>100000) or (AHeight>100000) then
BoundsOutOfBounds;
{$IFDEF CHECK_POSITION}
if CheckPosition(Self) then
DebugLn(['TControl.DoSetBounds ',DbgSName(Self),
' Old=',Left,',',Top,',',Width,'x',Height,
' New=',aLeft,',',aTop,',',aWidth,'x',aHeight]);
{$ENDIF}
FLeft := ALeft;
FTop := ATop;
FWidth := AWidth;
FHeight := AHeight;
if Parent <> nil then Parent.InvalidatePreferredSize;
end;
procedure TControl.ScaleConstraints(Multiplier, Divider: Integer);
begin
with Constraints do
begin
if MinWidth > 0 then
MinWidth := MulDiv(MinWidth, Multiplier, Divider);
if MaxWidth > 0 then
MaxWidth := MulDiv(MaxWidth, Multiplier, Divider);
if MinHeight > 0 then
MinHeight := MulDiv(MinHeight, Multiplier, Divider);
if MaxHeight > 0 then
MaxHeight := MulDiv(MaxHeight, Multiplier, Divider);
end;
end;
function TControl.ScaleDesignToForm(const ASize: Integer): Integer;
var
ParentForm: TCustomDesignControl;
begin
ParentForm := NeedParentDesignControl(Self);
Result := MulDiv(ASize, ParentForm.PixelsPerInch, ParentForm.DesignTimePPI);
end;
function TControl.Scale96ToForm(const ASize: Integer): Integer;
var
ParentForm: TCustomDesignControl;
begin
ParentForm := NeedParentDesignControl(Self);
Result := MulDiv(ASize, ParentForm.PixelsPerInch, 96);
end;
function TControl.Scale96ToScreen(const ASize: Integer): Integer;
begin
Result := MulDiv(ASize, Screen.PixelsPerInch, 96);
end;
function TControl.ScaleFormTo96(const ASize: Integer): Integer;
var
ParentForm: TCustomDesignControl;
begin
ParentForm := NeedParentDesignControl(Self);
Result := MulDiv(ASize, 96, ParentForm.PixelsPerInch);
end;
function TControl.ScaleFormToDesign(const ASize: Integer): Integer;
var
ParentForm: TCustomDesignControl;
begin
ParentForm := NeedParentDesignControl(Self);
Result := MulDiv(ASize, ParentForm.DesignTimePPI, ParentForm.PixelsPerInch);
end;
function TControl.ScaleScreenTo96(const ASize: Integer): Integer;
begin
Result := MulDiv(ASize, 96, Screen.PixelsPerInch);
end;
function TControl.Scale96ToFont(const ASize: Integer): Integer;
begin
Result := MulDiv(ASize, Font.PixelsPerInch, 96);
end;
function TControl.ScaleFontTo96(const ASize: Integer): Integer;
begin
Result := MulDiv(ASize, 96, Font.PixelsPerInch);
end;
function TControl.ScaleScreenToFont(const ASize: Integer): Integer;
begin
Result := MulDiv(ASize, Font.PixelsPerInch, Screen.PixelsPerInch);
end;
function TControl.ScaleFontToScreen(const ASize: Integer): Integer;
begin
Result := MulDiv(ASize, Screen.PixelsPerInch, Font.PixelsPerInch);
end;
procedure TControl.ScaleFontsPPI(const AToPPI: Integer;
const AProportion: Double);
begin
// Problem: all fonts have to be scaled.
// Override this function - list all custom fonts in the overriden procedure
DoScaleFontPPI(Font, AToPPI, AProportion);
end;
{------------------------------------------------------------------------------
TControl.ChangeScale
Scale contorl by factor Multiplier/Divider
------------------------------------------------------------------------------}
procedure TControl.ChangeScale(Multiplier, Divider: Integer);
var
R: TRect;
begin
if Multiplier <> Divider then
begin
ScaleConstraints(Multiplier, Divider);
if not ParentFont then
Font.Height := MulDiv(GetFontData(Font.Reference.Handle).Height, Multiplier, Divider);
R := BaseBounds;
if (Self is TCustomForm) and (GetParentForm(Self, True) = Self) then
begin
//Dont change Left,Top if this is the topmost form
R.Right := R.Left + MulDiv(R.Right-R.Left, Multiplier, Divider);
R.Bottom := R.Top + MulDiv(R.Bottom-R.Top, Multiplier, Divider);
end
else
begin
R.Left := MulDiv(R.Left, Multiplier, Divider);
R.Top := MulDiv(R.Top, Multiplier, Divider);
R.Right := MulDiv(R.Right, Multiplier, Divider);
R.Bottom := MulDiv(R.Bottom, Multiplier, Divider);
end;
BoundsRect := R;
end;
end;
{------------------------------------------------------------------------------
procedure TControl.CalculateDockSizes;
Compute docking width, height based on docking properties.
------------------------------------------------------------------------------}
procedure TControl.CalculateDockSizes;
begin
if Floating then
begin
// if control is floating then save it size for further undocking
UndockHeight := Height;
UndockWidth := Width;
end
else
if HostDockSite <> nil then
begin
// the control is docked into a HostSite. That means some of it bounds
// were maximized to fit into the HostSite.
if (DockOrientation = doHorizontal) or
(HostDockSite.Align in [alLeft,alRight]) then
// the control is aligned left/right, that means its width is not
// maximized. Save Width for docking.
LRDockWidth := Width
else
if (DockOrientation = doVertical) or
(HostDockSite.Align in [alTop,alBottom]) then
// the control is aligned top/bottom, that means its height is not
// maximized. Save Height for docking.
TBDockHeight := Height;
end;
end;
{------------------------------------------------------------------------------
function TControl.CreateFloatingDockSite(const Bounds: TRect): TWinControl;
------------------------------------------------------------------------------}
function TControl.CreateFloatingDockSite(const Bounds: TRect): TWinControl;
var
FloatingClass: TWinControlClass;
NewWidth: Integer;
NewHeight: Integer;
NewClientWidth: Integer;
NewClientHeight: Integer;
begin
Result := nil;
FloatingClass:=FloatingDockSiteClass;
if (FloatingClass<>nil) and (FloatingClass<>TWinControlClass(ClassType)) then
begin
Result := TWinControl(FloatingClass.NewInstance);
Result.DisableAutoSizing{$IFDEF DebugDisableAutoSizing}('TControl.CreateFloatingDockSite'){$ENDIF};
Result.Create(Self);
// resize with minimal resizes
NewClientWidth:=Bounds.Right-Bounds.Left;
NewClientHeight:=Bounds.Bottom-Bounds.Top;
NewWidth:=Result.Width-Result.ClientWidth+NewClientWidth;
NewHeight:=Result.Height-Result.ClientHeight+NewClientHeight;
Result.SetBounds(Bounds.Left,Bounds.Top,NewWidth,NewHeight);
Result.SetClientSize(Point(NewClientWidth,NewClientHeight));
{$IFDEF DebugDisableAutoSizing}
debugln('TControl.CreateFloatingDockSite A ',DbgSName(Self),' ',DbgSName(Result),' ',dbgs(Result.BoundsRect));
{$ENDIF}
Result.EnableAutoSizing{$IFDEF DebugDisableAutoSizing}('TControl.CreateFloatingDockSite'){$ENDIF};
end;
end;
procedure TControl.ExecuteDefaultAction;
begin
end;
procedure TControl.FixDesignFontsPPI(const ADesignTimePPI: Integer);
begin
// Problem: Font.PixelsPerInch isn't saved in the LFM, therefore the
// design-time font PPI is different from the one that is loaded on target
// machine, which results in different font scaling.
// DoFixDesignFont restores the corrent design-time font PPI so that it can
// be used for LCL HighDPI scaling.
// Override this function - list all custom fonts in the overriden procedure
// To-Do: maybe save Font.PixelsPerInch in the LFM and remove this?
DoFixDesignFontPPI(Font, ADesignTimePPI);
end;
procedure TControl.ExecuteCancelAction;
begin
end;
{------------------------------------------------------------------------------
function TControl.GetFloating: Boolean;
------------------------------------------------------------------------------}
function TControl.GetFloating: Boolean;
begin
// a non-windowed control can never float for itself
Result := (HostDockSite is FloatingDockSiteClass)
and (HostDockSite.DockClientCount<=1);
end;
{------------------------------------------------------------------------------
function TControl.GetFloatingDockSiteClass: TWinControlClass;
------------------------------------------------------------------------------}
function TControl.GetFloatingDockSiteClass: TWinControlClass;
begin
Result := FFloatingDockSiteClass;
end;
procedure TControl.BeforeDragStart;
begin
end;
{------------------------------------------------------------------------------
function TControl.GetLRDockWidth: Integer;
------------------------------------------------------------------------------}
function TControl.GetLRDockWidth: Integer;
begin
if FLRDockWidth>0 then
Result := FLRDockWidth
else
Result := UndockWidth;
end;
{------------------------------------------------------------------------------
function TControl.IsHelpContextStored: boolean;
------------------------------------------------------------------------------}
function TControl.IsHelpContextStored: Boolean;
begin
Result := (ActionLink = nil) or not ActionLink.IsHelpLinked;
end;
{------------------------------------------------------------------------------
function TControl.IsHelpKeyWordStored: boolean;
------------------------------------------------------------------------------}
// Using IsHelpContextLinked() for controlling HelpKeyword
// is not correct. Therefore, use IsHelpLinked which means that all 3 Help* properties
// must be equal. Also, this function becomes exactly the same as one just above.
function TControl.IsHelpKeyWordStored: Boolean;
begin
Result := (ActionLink = nil) or not ActionLink.IsHelpLinked;
end;
function TControl.IsShowHintStored: Boolean;
begin
Result := not ParentShowHint;
end;
function TControl.IsVisibleStored: Boolean;
begin
Result := (ActionLink = nil) or not ActionLink.IsVisibleLinked;
end;
function TControl.GetUndockHeight: Integer;
begin
if FUndockHeight > 0 then
Result := FUndockHeight
else
Result := Height;
end;
function TControl.GetUndockWidth: Integer;
begin
if FUndockWidth > 0 then
Result := FUndockWidth
else
Result := Width;
end;
function TControl.IsAnchorsStored: Boolean;
begin
Result:=(Anchors<>AnchorAlign[Align]);
end;
function TControl.IsVisible: Boolean;
begin
Result := IsControlVisible and ((Parent = nil) or (Parent.IsVisible));
end;
function TControl.IsControlVisible: Boolean;
begin
Result := (FVisible
or ((csDesigning in ComponentState)
and (not (csNoDesignVisible in ControlStyle))));
end;
{------------------------------------------------------------------------------
Method: TControl.IsEnabled
Params: none
Returns: Boolean
Returns True only if both TControl and it's parent hierarchy are enabled.
Used internally by TGraphicControls for painting and various states during
runtime.
------------------------------------------------------------------------------}
function TControl.IsEnabled: Boolean;
var
TheControl: TControl;
begin
TheControl := Self;
repeat
Result := TheControl.Enabled;
TheControl := TheControl.Parent;
until (TheControl = nil) or (not Result);
end;
{------------------------------------------------------------------------------
Method: TControl.IsParentColor
Params: none
Returns: Boolean
Used at places where we need to check ParentColor property from TControl.
Property is protected, so this function avoids hacking to get
protected property value.
------------------------------------------------------------------------------}
function TControl.IsParentColor: Boolean;
begin
Result := FParentColor;
end;
{------------------------------------------------------------------------------
Method: TControl.IsParentFont
Params: none
Returns: Boolean
Used at places where we need to check ParentFont property from TControl.
Property is protected, so this function avoids hacking to get
protected property value.
------------------------------------------------------------------------------}
function TControl.IsParentFont: Boolean;
begin
Result := FParentFont;
end;
function TControl.FormIsUpdating: Boolean;
begin
Result := Assigned(Parent) and Parent.FormIsUpdating;
end;
function TControl.IsProcessingPaintMsg: Boolean;
begin
Result:=cfProcessingWMPaint in FControlFlags;
end;
{------------------------------------------------------------------------------
TControl.LMCaptureChanged
------------------------------------------------------------------------------}
procedure TControl.LMCaptureChanged(var Message: TLMessage);
begin
//DebugLn('[LMCaptureChanged for '+Name+':'+Classname+']');
CaptureChanged;
end;
{------------------------------------------------------------------------------
TControl.CMENABLEDCHANGED
------------------------------------------------------------------------------}
procedure TControl.CMEnabledChanged(var Message: TLMEssage);
begin
Invalidate;
end;
{------------------------------------------------------------------------------
TControl.CMHITTEST
------------------------------------------------------------------------------}
procedure TControl.CMHitTest(var Message: TCMHittest);
begin
Message.Result := 1;
end;
{------------------------------------------------------------------------------
TControl.CMMouseEnter
------------------------------------------------------------------------------}
procedure TControl.CMMouseEnter(var Message: TLMessage);
begin
if FMouseInClient then
Exit;
FMouseInClient := True;
// broadcast to parents first
if Assigned(Parent) then
Parent.Perform(CM_MOUSEENTER, 0, LParam(Self));
// if it is not a child message then perform an event
if (Message.LParam = 0) then
MouseEnter;
end;
{------------------------------------------------------------------------------
TControl.CMMouseLeave
------------------------------------------------------------------------------}
procedure TControl.CMMouseLeave(var Message: TLMessage);
begin
if not FMouseInClient then
Exit;
FMouseInClient := False;
// broadcast to parents first
if Assigned(Parent) then
Parent.Perform(CM_MOUSELEAVE, 0, LParam(Self));
// if it is not a child message then perform an event
if (Message.LParam = 0) then
MouseLeave;
end;
{------------------------------------------------------------------------------
procedure TControl.CMHintShow(var Message: TLMessage);
------------------------------------------------------------------------------}
procedure TControl.CMHintShow(var Message: TLMessage);
begin
DoOnShowHint(TCMHintShow(Message).HintInfo);
if (ActionLink <> nil)
and not ActionLink.DoShowHint(TCMHintShow(Message).HintInfo^.HintStr)
then
Message.Result := 1;
end;
{------------------------------------------------------------------------------
TControl.CMVisibleChanged
------------------------------------------------------------------------------}
procedure TControl.CMVisibleChanged(var Message : TLMessage);
begin
if (not (csDesigning in ComponentState) or (csNoDesignVisible in ControlStyle)) and
(not (csLoading in ComponentState)) then
InvalidateControl(True, FVisible and (csOpaque in ControlStyle), True);
end;
procedure TControl.CMTextChanged(var Message: TLMessage);
begin
TextChanged;
end;
procedure TControl.CMCursorChanged(var Message: TLMessage);
begin
if not (csDesigning in ComponentState) then
SetTempCursor(Cursor);
end;
{------------------------------------------------------------------------------
TControl.CMParentColorChanged
assumes: FParent <> nil
------------------------------------------------------------------------------}
procedure TControl.CMParentColorChanged(var Message: TLMessage);
begin
if csLoading in ComponentState then Exit;
if FParentColor then
begin
Color := FParent.Color;
FParentColor := True;
end;
end;
{------------------------------------------------------------------------------
TControl.CMParentFontChanged
assumes: FParent <> nil
------------------------------------------------------------------------------}
procedure TControl.CMParentFontChanged(var Message: TLMessage);
begin
if csLoading in ComponentState then exit;
if FParentFont then
begin
if Assigned(FParent) then
begin
Font.BeginUpdate;
try
Font.PixelsPerInch := FParent.Font.PixelsPerInch; // PixelsPerInch isn't assigned
Font := FParent.Font;
finally
Font.EndUpdate;
end;
end;
FParentFont := True;
end;
//call here for compatibility with older LCL code
ParentFontChanged;
end;
{------------------------------------------------------------------------------
TControl.CMParentShowHintChanged
assumes: FParent <> nil
------------------------------------------------------------------------------}
procedure TControl.CMParentShowHintChanged(var Message: TLMessage);
begin
if csLoading in ComponentState then Exit;
if FParentShowHint then
begin
ShowHint := FParent.ShowHint;
FParentShowHint := True;
end;
end;
{------------------------------------------------------------------------------}
{ TControl.ConstrainedResize }
{------------------------------------------------------------------------------}
procedure TControl.ConstrainedResize(var MinWidth, MinHeight,
MaxWidth, MaxHeight : TConstraintSize);
begin
if Assigned(FOnConstrainedResize) then
FOnConstrainedResize(Self, MinWidth, MinHeight, MaxWidth, MaxHeight);
end;
{------------------------------------------------------------------------------
procedure TControl.CalculatePreferredSize(var PreferredWidth,
PreferredHeight: integer; WithThemeSpace: Boolean);
Calculates the default/preferred width and height for a control, which is used
by the LCL autosizing algorithms as default size. Only positive values are
valid. Negative or 0 are treated as undefined and the LCL uses other sizes
instead.
TWinControl overrides this and asks the interface for theme dependent values.
See TWinControl.GetPreferredSize for more information.
WithThemeSpace: If true, adds space for stacking. For example: TRadioButton
has a minimum size. But for staking multiple TRadioButtons there should be
some space around. This space is theme dependent, so it passed parameter to
the widgetset.
------------------------------------------------------------------------------}
procedure TControl.CalculatePreferredSize(var PreferredWidth, PreferredHeight: Integer; WithThemeSpace: Boolean);
begin
PreferredWidth:=0;
PreferredHeight:=0;
end;
{------------------------------------------------------------------------------
function TControl.GetPalette: HPalette;
------------------------------------------------------------------------------}
function TControl.GetPalette: HPalette;
begin
Result:=0;
end;
function TControl.GetParentBackground: Boolean;
begin
Result := csParentBackground in ControlStyle;
end;
function TControl.ChildClassAllowed(ChildClass: TClass): Boolean;
begin
Result:=false;
end;
{------------------------------------------------------------------------------
procedure TControl.DoOnResize;
Call events
------------------------------------------------------------------------------}
procedure TControl.DoOnResize;
begin
if Assigned(FOnResize) then FOnResize(Self);
DoCallNotifyHandler(chtOnResize);
end;
{------------------------------------------------------------------------------
procedure TControl.DoOnChangeBounds;
Call events
------------------------------------------------------------------------------}
procedure TControl.DoOnChangeBounds;
begin
Exclude(FControlFlags,cfOnChangeBoundsNeeded);
if Assigned(FOnChangeBounds) then FOnChangeBounds(Self);
DoCallNotifyHandler(chtOnChangeBounds);
end;
procedure TControl.CheckOnChangeBounds;
var
CurBounds: TRect;
CurClientSize: TPoint;
begin
if [csLoading,csDestroying]*ComponentState<>[] then exit;
CurBounds:=BoundsRect;
CurClientSize:=Point(ClientWidth,ClientHeight);
if (not SameRect(@FLastDoChangeBounds,@CurBounds))
or (ComparePoints(CurClientSize,FLastDoChangeClientSize)<>0) then begin
if FormIsUpdating then begin
Include(FControlFlags,cfOnChangeBoundsNeeded);
exit;
end;
FLastDoChangeBounds:=CurBounds;
FLastDoChangeClientSize:=CurClientSize;
DoOnChangeBounds;
end;
end;
{------------------------------------------------------------------------------
procedure TControl.DoBeforeMouseMessage;
------------------------------------------------------------------------------}
procedure TControl.DoBeforeMouseMessage(TheMessage: TLMessage);
var
MouseMessage: TLMMouse absolute TheMessage;
P: TPoint;
NewMouseControl: TControl;
begin
if Assigned(Application) then
begin
NewMouseControl := GetCaptureControl;
if NewMouseControl = nil then
begin
P := GetMousePosFromMessage(MouseMessage.Pos);
p := ClientToScreen(P);
NewMouseControl := Application.GetControlAtPos(P);
end;
Application.DoBeforeMouseMessage(NewMouseControl);
end;
end;
{------------------------------------------------------------------------------
function TControl.ColorIsStored: boolean;
------------------------------------------------------------------------------}
function TControl.ColorIsStored: Boolean;
begin
Result := not ParentColor;
end;
function TControl.GetDefaultColor(const DefaultColorType: TDefaultColorType): TColor;
const
DefColors: array[TDefaultColorType] of TColor = (
{ dctBrush } clWindow,
{ dctFont } clWindowText
);
begin
Result := TWSControlClass(WidgetSetClass).GetDefaultColor(Self, DefaultColorType);
if (Result = clDefault) then
if ParentColor and Assigned(Parent) then
Result := Parent.GetDefaultColor(DefaultColorType)
else
Result := DefColors[DefaultColorType];
end;
function TControl.GetColorResolvingParent: TColor;
begin
if Color = clDefault then
Result := GetDefaultColor(dctBrush) // GetDefaultColor resolves the parent
else
Result := Color;
end;
function TControl.GetRGBColorResolvingParent: TColor;
begin
Result := ColorToRGB(GetColorResolvingParent());
end;
{------------------------------------------------------------------------------
TControl.DoConstrainedResize
------------------------------------------------------------------------------}
procedure TControl.DoConstrainedResize(var NewLeft, NewTop, NewWidth, NewHeight: Integer);
var
MinWidth, MinHeight, MaxWidth, MaxHeight : TConstraintSize;
begin
if NewWidth<0 then NewWidth:=0;
if NewHeight<0 then NewHeight:=0;
MinWidth := Constraints.EffectiveMinWidth;
MinHeight := Constraints.EffectiveMinHeight;
MaxWidth := Constraints.EffectiveMaxWidth;
MaxHeight := Constraints.EffectiveMaxHeight;
ConstrainedResize(MinWidth, MinHeight, MaxWidth, MaxHeight);
if (MinWidth > 0) and (NewWidth < MinWidth) then
begin
// right kept position ? interpret as resizing left border
if (NewLeft+NewWidth) = (Left+Width) then
begin
Dec(NewLeft, MinWidth - NewWidth);
if NewLeft < Left then
NewLeft := Left;
end;
NewWidth := MinWidth
end else if (MaxWidth > 0) and (NewWidth > MaxWidth) then
begin
if (NewLeft+NewWidth) = (Left+Width) then
begin
Inc(NewLeft, NewWidth - MaxWidth);
if NewLeft > Left then
NewLeft := Left;
end;
NewWidth := MaxWidth;
end;
if (MinHeight > 0) and (NewHeight < MinHeight) then
begin
// bottom kept position ? interpret as resizing bottom border
if (NewTop+NewHeight) = (Top+Height) then
begin
Dec(NewTop, MinHeight - NewHeight);
if NewTop < Top then
NewTop := Top;
end;
NewHeight := MinHeight
end else if (MaxHeight > 0) and (NewHeight > MaxHeight) then
begin
if (NewTop+NewHeight) = (Top+Height) then
begin
Inc(NewTop, NewHeight - MaxHeight);
if NewTop > Top then
NewTop := Top;
end;
NewHeight := MaxHeight;
end;
//debugln('TControl.DoConstrainedResize ',DbgSName(Self),' ',dbgs(NewWidth),',',dbgs(NewHeight));
end;
{------------------------------------------------------------------------------
TControl.DoConstraintsChange
------------------------------------------------------------------------------}
procedure TControl.DoConstraintsChange(Sender : TObject);
begin
AdjustSize;
end;
procedure TControl.DoBorderSpacingChange(Sender: TObject;
InnerSpaceChanged: Boolean);
begin
if Parent <> nil then Parent.InvalidatePreferredSize;
AdjustSize;
end;
function TControl.IsBorderSpacingInnerBorderStored: Boolean;
begin
Result:=BorderSpacing.InnerBorder<>0;
end;
{------------------------------------------------------------------------------
TControl IsCaptionStored
------------------------------------------------------------------------------}
function TControl.IsCaptionStored: Boolean;
begin
Result := (ActionLink = nil) or not ActionLink.IsCaptionLinked;
end;
{------------------------------------------------------------------------------
procedure TControl.SendMoveSizeMessages(SizeChanged, PosChanged: boolean);
------------------------------------------------------------------------------}
procedure TControl.SendMoveSizeMessages(SizeChanged, PosChanged: Boolean);
begin
end;
{------------------------------------------------------------------------------
TControl.DragCanceled
------------------------------------------------------------------------------}
procedure TControl.DragCanceled;
begin
{$IFDEF VerboseDrag}
DebugLn('TControl.DragCanceled');
{$ENDIF}
end;
{------------------------------------------------------------------------------
TControl.DoStartDrag
------------------------------------------------------------------------------}
procedure TControl.DoStartDrag(var DragObject: TDragObject);
begin
{$IFDEF VerboseDrag}
DebugLn('TControl.DoStartDrag ',Name,':',ClassName);
{$ENDIF}
if Assigned(FOnStartDrag) then FOnStartDrag(Self, DragObject);
end;
{------------------------------------------------------------------------------
TControl.DoEndDrag
------------------------------------------------------------------------------}
procedure TControl.DoEndDrag(Target: TObject; X,Y: Integer);
begin
{$IFDEF VerboseDrag}
DebugLn('TControl.DoEndDrag ',Name,':',ClassName,' XY=',IntToStr(X),',',IntToStr(Y));
{$ENDIF}
if Assigned(FOnEndDrag) then FOnEndDrag(Self,Target,X,Y);
end;
{------------------------------------------------------------------------------
TControl.DoFixDesignFontPPI
------------------------------------------------------------------------------}
procedure TControl.DoFixDesignFontPPI(const AFont: TFont;
const ADesignTimePPI: Integer);
var
H: Integer;
OldParentFont: Boolean;
begin
if AFont.PixelsPerInch <> ADesignTimePPI then
begin
OldParentFont := ParentFont;
try
H := AFont.Height;
AFont.BeginUpdate;
try
AFont.Height := MulDiv(H, AFont.PixelsPerInch, ADesignTimePPI);
AFont.PixelsPerInch := ADesignTimePPI;
finally
AFont.EndUpdate;
end;
finally
FParentFont := OldParentFont; // change ParentFont without triggering CM_PARENTFONTCHANGED
end;
end;
end;
{------------------------------------------------------------------------------
TControl.Perform
------------------------------------------------------------------------------}
function TControl.Perform(Msg: Cardinal; WParam: WParam; LParam: LParam): LRESULT;
var
Message : TLMessage;
begin
Message.Msg := Msg;
Message.WParam := WParam;
Message.LParam := LParam;
Message.Result := 0;
if Self <> nil then WindowProc(Message);
Result := Message.Result;
end;
{------------------------------------------------------------------------------
TControl.GetClientOrigin
------------------------------------------------------------------------------}
function TControl.GetClientOrigin: TPoint;
begin
if Parent = nil then
raise EInvalidOperation.CreateFmt(sParentRequired, [Name]);
Result := Parent.ClientOrigin;
Inc(Result.X, FLeft);
Inc(Result.Y, FTop);
end;
{------------------------------------------------------------------------------
TControl.ScreenToClient
------------------------------------------------------------------------------}
function TControl.ScreenToClient(const APoint: TPoint): TPoint;
var
P : TPoint;
begin
P := ClientOrigin;
Result.X := APoint.X - P.X;
Result.Y := APoint.Y - P.Y;
end;
{------------------------------------------------------------------------------
function TControl.ClientToScreen(const APoint: TPoint): TPoint;
------------------------------------------------------------------------------}
function TControl.ClientToScreen(const APoint: TPoint): TPoint;
var
P : TPoint;
begin
P := ClientOrigin;
Result.X := APoint.X + P.X;
Result.Y := APoint.Y + P.Y;
end;
function TControl.ClientToScreen(const ARect: TRect): TRect;
var
P : TPoint;
begin
P := ClientToScreen(Point(0, 0));
Result := ARect;
Result.Offset(P);
end;
{------------------------------------------------------------------------------
function TControl.ScreenToControl(const APoint: TPoint): TPoint;
------------------------------------------------------------------------------}
function TControl.ScreenToControl(const APoint: TPoint): TPoint;
var
P : TPoint;
begin
P := ControlOrigin;
Result.X := APoint.X - P.X;
Result.Y := APoint.Y - P.Y;
end;
{------------------------------------------------------------------------------
function TControl.ControlToScreen(const APoint: TPoint): TPoint;
------------------------------------------------------------------------------}
function TControl.ControlToScreen(const APoint: TPoint): TPoint;
var
P : TPoint;
begin
P := ControlOrigin;
Result.X := APoint.X + P.X;
Result.Y := APoint.Y + P.Y;
end;
function TControl.ClientToParent(const Point: TPoint; AParent: TWinControl): TPoint;
begin
if not Assigned(AParent) then
AParent := Parent;
if not AParent.IsParentOf(Self) then
raise EInvalidOperation.CreateFmt(rsControlIsNotAParent, [AParent.Name, Name]);
Result := AParent.ScreenToClient(ClientToScreen(Point));
end;
function TControl.ParentToClient(const Point: TPoint; AParent: TWinControl): TPoint;
begin
if not Assigned(AParent) then
AParent := Parent;
if not AParent.IsParentOf(Self) then
raise EInvalidOperation.CreateFmt(rsControlIsNotAParent, [AParent.Name, Name]);
Result := ScreenToClient(AParent.ClientToScreen(Point));
end;
{------------------------------------------------------------------------------
TControl.DblClick
------------------------------------------------------------------------------}
procedure TControl.DblClick;
begin
if Assigned(FOnDblClick) then FOnDblClick(Self);
end;
{------------------------------------------------------------------------------
TControl.TripleClick
------------------------------------------------------------------------------}
procedure TControl.TripleClick;
begin
if Assigned(FOnTripleClick) then FOnTripleClick(Self);
end;
{------------------------------------------------------------------------------
TControl.QuadClick
------------------------------------------------------------------------------}
procedure TControl.QuadClick;
begin
if Assigned(FOnQuadClick) then FOnQuadClick(Self);
end;
{------------------------------------------------------------------------------
TControl.DoDragMsg
------------------------------------------------------------------------------}
function TControl.DoDragMsg(ADragMessage: TDragMessage; APosition: TPoint;
ADragObject: TDragObject; ATarget: TControl; ADocking: Boolean): LRESULT;
function GetDragObject: TObject; inline;
begin
if ADragObject.AutoCreated then
Result := ADragObject.Control
else
Result := ADragObject;
end;
var
AWinTarget: TWinControl;
Accepts: Boolean;
P: TPoint;
begin
Result := 0;
{$IFDEF VerboseDrag}
DebugLn('TControl.DoDragMsg ',Name,':',ClassName,' DragMsg.DragMessage=', GetEnumName(TypeInfo(TDragMessage), Ord(ADragMessage)));
{$ENDIF}
case ADragMessage of
dmFindTarget:
Result := PtrInt(Self);
dmDragEnter, dmDragLeave, dmDragMove:
begin
Accepts := True;
P := ScreenToClient(APosition);
if ADragObject is TDragDockObject then
begin
AWinTarget:= TWinControl(ADragObject.DragTarget);
AWinTarget.DockOver(TDragDockObject(ADragObject), P.X, P.Y, TDragState(ADragMessage), Accepts);
end
else
DragOver(GetDragObject, P.X, P.Y, TDragState(ADragMessage), Accepts);
Result := Ord(Accepts);
end;
dmDragDrop:
begin
P := ScreenToClient(APosition);
if ADragObject is TDragDockObject then
begin
AWinTarget:= TWinControl(ADragObject.DragTarget);
AWinTarget.DockDrop(TDragDockObject(ADragObject), P.X, P.Y);
end
else
DragDrop(GetDragObject, P.X, P.Y);
end;
end;
end;
{------------------------------------------------------------------------------
TControl.DragOver
------------------------------------------------------------------------------}
procedure TControl.DragOver(Source: TObject; X,Y : Integer; State: TDragState;
var Accept:Boolean);
begin
{$IFDEF VerboseDrag}
DebugLn('TControl.DragOver ',Name,':',ClassName,' XY=',IntToStr(X),',',IntToStr(Y));
{$ENDIF}
Accept := Assigned(FOnDragOver);
if Accept then
FOnDragOver(Self,Source,X,Y,State,Accept);
end;
{------------------------------------------------------------------------------
TControl.DragDrop
------------------------------------------------------------------------------}
procedure TControl.DragDrop(Source: TObject; X,Y : Integer);
begin
{$IFDEF VerboseDrag}
DebugLn('TControl.DragDrop ',Name,':',ClassName,' XY=',IntToStr(X),',',IntToStr(Y));
{$ENDIF}
if Assigned(FOnDragDrop) then FOnDragDrop(Self, Source,X,Y);
end;
procedure TControl.SetAccessibleName(AValue: TCaption);
begin
FAccessibleObject.AccessibleName := AValue;
end;
procedure TControl.SetAccessibleDescription(AValue: TCaption);
begin
FAccessibleObject.AccessibleDescription := AValue;
end;
procedure TControl.SetAccessibleValue(AValue: TCaption);
begin
FAccessibleObject.AccessibleValue := AValue;
end;
procedure TControl.SetAccessibleRole(AValue: TLazAccessibilityRole);
begin
FAccessibleObject.AccessibleRole := AValue;
end;
{------------------------------------------------------------------------------
TControl Method SetColor "Sets the default color and tells the widget set"
------------------------------------------------------------------------------}
procedure TControl.SetColor(Value: TColor);
begin
if FColor <> Value then
begin
FColor := Value;
ParentColor := False;
ParentBackground := False;
Perform(CM_COLORCHANGED, 0, 0);
Invalidate;
end;
end;
{------------------------------------------------------------------------------
TControl CanAutoSize
------------------------------------------------------------------------------}
function TControl.CanAutoSize(var NewWidth, NewHeight : Integer): Boolean;
begin
Result := True;
end;
{------------------------------------------------------------------------------
TControl Dragging
------------------------------------------------------------------------------}
function TControl.Dragging: Boolean;
begin
Result := DragManager.Dragging(Self);
end;
// accessibility
function TControl.GetAccessibleObject: TLazAccessibleObject;
begin
Result := FAccessibleObject;
end;
function TControl.CreateAccessibleObject: TLazAccessibleObject;
begin
Result := TLazAccessibleObject.Create(Self);
end;
function TControl.GetSelectedChildAccessibleObject: TLazAccessibleObject;
begin
Result := nil;
end;
function TControl.GetChildAccessibleObjectAtPos(APos: TPoint): TLazAccessibleObject;
begin
Result := nil;
end;
{------------------------------------------------------------------------------
TControl GetBoundsRect
------------------------------------------------------------------------------}
function TControl.GetBoundsRect: TRect;
begin
Result.Left := FLeft;
Result.Top := FTop;
Result.Right := FLeft+FWidth;
Result.Bottom := FTop+FHeight;
end;
function TControl.GetClientHeight: Integer;
begin
Result:=ClientRect.Bottom;
end;
function TControl.GetClientWidth: Integer;
begin
Result:=ClientRect.Right;
end;
{------------------------------------------------------------------------------
TControl GetEnabled
------------------------------------------------------------------------------}
function TControl.GetEnabled: Boolean;
begin
Result := FEnabled;
end;
{------------------------------------------------------------------------------
TControl GetMouseCapture
------------------------------------------------------------------------------}
function TControl.GetMouseCapture : Boolean;
begin
Result := (Parent<>nil) and Parent.HandleAllocated and (GetCaptureControl = Self);
end;
function TControl.GetMousePosFromMessage(const MessageMousePos: TSmallPoint
): TPoint;
begin
if (Width>32767) or (Height>32767) then
begin
GetCursorPos(Result);
Result := ScreenToClient(Result);
end else
Result := SmallPointToPoint(MessageMousePos);
end;
function TControl.GetTBDockHeight: Integer;
begin
if FTBDockHeight>0 then
Result := FTBDockHeight
else
Result := UndockHeight;
end;
{------------------------------------------------------------------------------
TControl GetPopupMenu
------------------------------------------------------------------------------}
function TControl.GetPopupMenu: TPopupMenu;
begin
Result := FPopupMenu;
end;
{------------------------------------------------------------------------------
procedure TControl.DoOnShowHint(HintInfo: Pointer);
------------------------------------------------------------------------------}
procedure TControl.DoOnShowHint(HintInfo: PHintInfo);
begin
if Assigned(OnShowHint) then
OnShowHint(Self,HintInfo);
end;
procedure TControl.DoScaleFontPPI(const AFont: TFont; const AToPPI: Integer;
const AProportion: Double);
begin
// If AFont.PixelsPerInch is different from "Screen.PixelsPerInch" (=GetDeviceCaps(DC, LOGPIXELSX))
// then the font doesn't scale -> we have to assign a nonzero height value.
if (AFont.Height=0) and not (csDesigning in ComponentState) then
AFont.Height := MulDiv(GetFontData(AFont.Reference.Handle).Height, AFont.PixelsPerInch, Screen.PixelsPerInch);
if AToPPI>0 then
AFont.PixelsPerInch := AToPPI
else
AFont.PixelsPerInch := Round(AFont.PixelsPerInch*AProportion);
end;
function TControl.IsAParentAligning: Boolean;
var
p: TWinControl;
begin
p:=Parent;
while (p<>nil) do begin
if (wcfAligningControls in p.FWinControlFlags) then
exit(true);
p:=p.Parent;
end;
Result:=false;
end;
{------------------------------------------------------------------------------
procedure TControl.VisibleChanging;
------------------------------------------------------------------------------}
procedure TControl.VisibleChanging;
begin
DoCallNotifyHandler(chtOnVisibleChanging);
end;
procedure TControl.VisibleChanged;
begin
DoCallNotifyHandler(chtOnVisibleChanged);
end;
{------------------------------------------------------------------------------
procedure TControl.EnabledChanging;
------------------------------------------------------------------------------}
procedure TControl.EnabledChanging;
begin
DoCallNotifyHandler(chtOnEnabledChanging);
end;
procedure TControl.EnabledChanged;
begin
DoCallNotifyHandler(chtOnEnabledChanged);
end;
procedure TControl.AddHandler(HandlerType: TControlHandlerType; const AMethod: TMethod; AsFirst: Boolean);
begin
if FControlHandlers[HandlerType]=nil then
FControlHandlers[HandlerType]:=TMethodList.Create;
FControlHandlers[HandlerType].Add(AMethod,not AsFirst);
end;
procedure TControl.RemoveHandler(HandlerType: TControlHandlerType;
const AMethod: TMethod);
begin
FControlHandlers[HandlerType].Remove(AMethod);
end;
procedure TControl.DoCallNotifyHandler(HandlerType: TControlHandlerType);
begin
FControlHandlers[HandlerType].CallNotifyEvents(Self);
end;
procedure TControl.DoCallKeyEventHandler(HandlerType: TControlHandlerType;
var Key: Word; Shift: TShiftState);
var
i: Integer;
begin
i := FControlHandlers[HandlerType].Count;
while FControlHandlers[HandlerType].NextDownIndex(i) do
TKeyEvent(FControlHandlers[HandlerType][i])(Self, Key, Shift);
end;
procedure TControl.DoCallMouseWheelEventHandler(HandlerType: TControlHandlerType;
Shift: TShiftState; WheelDelta: Integer;
MousePos: TPoint; var Handled: Boolean);
var
i: Integer;
begin
i := FControlHandlers[HandlerType].Count;
//debugln('TControl.DoCallMouseWheelEventHandler A: Handled = ',DbgS(Handled),', Count = ',DbgS(i));
while (not Handled) and FControlHandlers[HandlerType].NextDownIndex(i) do
begin
TMouseWheelEvent(FControlHandlers[HandlerType][i])(Self, Shift, WheelDelta, MousePos, Handled);
//debugln('TControl.DoCallMouseWheelEventHandler B: i = ',Dbgs(i),', Handled = ',DbgS(Handled));
end;
//debugln('TControl.DoCallMouseWheelEventHandler End: Handled = ',DbgS(Handled));
end;
{------------------------------------------------------------------------------
procedure TControl.DoContextPopup(const MousePos: TPoint;
var Handled: Boolean);
------------------------------------------------------------------------------}
procedure TControl.DoContextPopup(MousePos: TPoint; var Handled: Boolean);
begin
if Assigned(FOnContextPopup) then
FOnContextPopup(Self, MousePos, Handled);
end;
procedure TControl.ActionChange(Sender: TObject; CheckDefaults: Boolean);
var
NewAction: TCustomAction;
begin
if Sender is TCustomAction then begin
NewAction:=TCustomAction(Sender);
if (not CheckDefaults) or (Caption = '') or (Caption = Name) then
Caption := NewAction.Caption;
if not CheckDefaults or Enabled then
Enabled := NewAction.Enabled;
if not CheckDefaults or (Hint = '') then
Hint := NewAction.Hint;
if not CheckDefaults or Visible then
Visible := NewAction.Visible;
if not CheckDefaults or (Self.HelpContext = 0) then
Self.HelpContext := HelpContext;
if not CheckDefaults or (Self.HelpKeyword = '') then
Self.HelpKeyword := HelpKeyword;
// HelpType is set implicitly when assigning HelpContext or HelpKeyword
end;
end;
procedure TControl.DoActionChange(Sender: TObject);
begin
if Sender = Action then ActionChange(Sender, False);
end;
function TControl.GetAccessibleName: TCaption;
begin
Result := FAccessibleObject.AccessibleName;
end;
function TControl.GetAccessibleDescription: TCaption;
begin
Result := FAccessibleObject.AccessibleDescription;
end;
function TControl.GetAccessibleValue: TCaption;
begin
Result := FAccessibleObject.AccessibleValue;
end;
function TControl.GetAccessibleRole: TLazAccessibilityRole;
begin
Result := FAccessibleObject.AccessibleRole;
end;
function TControl.CaptureMouseButtonsIsStored: Boolean;
begin
Result := FCaptureMouseButtons <> [mbLeft];
end;
function TControl.GetAnchorSide(Kind: TAnchorKind): TAnchorSide;
begin
Result:=FAnchorSides[Kind];
end;
function TControl.GetAnchoredControls(Index: Integer): TControl;
begin
Result := TControl(FAnchoredControls[Index]);
end;
function TControl.GetAutoSizingAll: Boolean;
begin
if Parent <> nil then
Result := Parent.AutoSizingAll
else
Result := FAutoSizingAll;
end;
{------------------------------------------------------------------------------
TControl GetClientRect
Returns the size of visual client area.
For example the inner size of a TGroupBox.
For a TScrollBox it is the visual size, not the logical size.
------------------------------------------------------------------------------}
function TControl.GetClientRect: TRect;
begin
Result.Left := 0;
Result.Top := 0;
Result.Right := Width;
Result.Bottom := Height;
end;
{------------------------------------------------------------------------------
TControl GetLogicalClientRect
Returns the size of complete client area. It can be bigger or smaller than
the visual size, but normally it is the same. For example a TScrollBox can
have different sizes.
------------------------------------------------------------------------------}
function TControl.GetLogicalClientRect: TRect;
begin
Result:=ClientRect;
end;
{------------------------------------------------------------------------------
function TControl.GetScrolledClientRect: TRect;
------------------------------------------------------------------------------}
function TControl.GetScrolledClientRect: TRect;
var
ScrolledOffset: TPoint;
begin
Result:=GetClientRect;
ScrolledOffset:=GetClientScrollOffset;
inc(Result.Left,ScrolledOffset.X);
inc(Result.Top,ScrolledOffset.Y);
inc(Result.Right,ScrolledOffset.X);
inc(Result.Bottom,ScrolledOffset.Y);
end;
{------------------------------------------------------------------------------
function TControl.GetChildrenRect(Scrolled: boolean): TRect;
Returns the Client rectangle relative to the controls left, top.
If Scrolled is true, the rectangle is moved by the current scrolling values
(for an example see TScrollingWincontrol).
------------------------------------------------------------------------------}
function TControl.GetChildrenRect(Scrolled: Boolean): TRect;
var
ScrolledOffset: TPoint;
begin
Result:=ClientRect;
if Scrolled then begin
ScrolledOffset:=GetClientScrollOffset;
inc(Result.Left,ScrolledOffset.X);
inc(Result.Top,ScrolledOffset.Y);
inc(Result.Right,ScrolledOffset.X);
inc(Result.Bottom,ScrolledOffset.Y);
end;
end;
{------------------------------------------------------------------------------
function TControl.GetClientScrollOffset: TPoint;
Returns the scrolling offset of the client area.
------------------------------------------------------------------------------}
function TControl.GetClientScrollOffset: TPoint;
begin
Result:=Point(0,0);
end;
{------------------------------------------------------------------------------
function TControl.GetControlOrigin: TPoint;
Returns the screen coordinate of the topleft pixel of the control.
------------------------------------------------------------------------------}
function TControl.GetControlOrigin: TPoint;
var
ParentsClientOrigin: TPoint;
begin
Result:=Point(Left,Top);
if Parent<>nil then begin
ParentsClientOrigin:=Parent.ClientOrigin;
inc(Result.X,ParentsClientOrigin.X);
inc(Result.Y,ParentsClientOrigin.Y);
end;
end;
{------------------------------------------------------------------------------
TControl WndPRoc
------------------------------------------------------------------------------}
procedure TControl.WndProc(var TheMessage : TLMessage);
var
Form : TCustomForm;
begin
//DebugLn('CCC TControl.WndPRoc ',Name,':',ClassName);
if (csDesigning in ComponentState) then
begin
// redirect messages to designer
Form := GetDesignerForm(Self);
//debugln(['TControl.WndProc ',dbgsname(Self)]);
if Assigned(Form) and Assigned(Form.Designer) and Form.Designer.IsDesignMsg(Self, TheMessage) then
Exit;
end
else if (TheMessage.Msg >= LM_KEYFIRST) and (TheMessage.Msg <= LM_KEYLAST)
then begin
// keyboard messages
Form := GetParentForm(Self);
if (Form <> nil) and (Form.WantChildKey(Self,TheMessage)) then exit;
end
else if ((TheMessage.Msg>=LM_MOUSEFIRST) and (TheMessage.Msg<=LM_MOUSELAST))
or ((TheMessage.Msg>=LM_MOUSEFIRST2) and (TheMessage.Msg<=LM_MOUSELAST2))
then begin
// mouse messages
case TheMessage.Msg of
LM_MOUSEMOVE:
begin
Application.HintMouseMessage(Self, TheMessage);
end;
LM_LBUTTONDOWN,
LM_LBUTTONDBLCLK:
begin
Include(FControlState, csLButtonDown);
{ The VCL holds up the mouse down for dmAutomatic
and sends it, when it decides, if it is a drag operation or
not.
This decision requires full control of focus and mouse, which
do not all LCL interfaces provide. Therefore the mouse down event
is sent immediately.
Further Note:
Under winapi a LM_LBUTTONDOWN ends the drag immediate.
For example: If we exit here, then mouse down on TTreeView does
not work any longer under gtk.
}
if FDragMode = dmAutomatic then
BeginAutoDrag;
end;
LM_LBUTTONUP:
begin
Exclude(FControlState, csLButtonDown);
end;
end;
end;
//debugln(['TControl.WndProc ',DbgSName(Self),' ',TheMessage.Msg]);
if TheMessage.Msg=LM_PAINT then begin
Include(FControlFlags,cfProcessingWMPaint);
try
Dispatch(TheMessage);
finally
Exclude(FControlFlags,cfProcessingWMPaint);
end;
end else
Dispatch(TheMessage);
end;
{------------------------------------------------------------------------------
procedure TControl.ParentFormHandleInitialized;
called by ChildHandlesCreated of parent form
------------------------------------------------------------------------------}
procedure TControl.ParentFormHandleInitialized;
begin
// The form is really connection to the target screen. For example, the gtk
// under X gathers some screen information not before form creation.
// But this information is needed to create DeviceContexts, which
// are needed to calculate Text Size and such stuff needed for AutoSizing.
// That's why AdjustSize delays AutoSizing till this moment. Now do the
// AutoSize.
AdjustSize;
end;
{------------------------------------------------------------------------------
TControl Invalidate
------------------------------------------------------------------------------}
procedure TControl.Invalidate;
begin
//DebugLn(['TControl.Invalidate ',DbgSName(Self)]);
InvalidateControl(IsVisible, csOpaque in ControlStyle);
end;
{------------------------------------------------------------------------------
TControl DoMouseDown "Event Handler"
------------------------------------------------------------------------------}
procedure TControl.DoMouseDown(var Message: TLMMouse; Button: TMouseButton;
Shift: TShiftState);
var
MP: TPoint;
begin
//DebugLn('TControl.DoMouseDown ',DbgSName(Self),' ');
if not (csNoStdEvents in ControlStyle) then
begin
MP := GetMousePosFromMessage(Message.Pos);
MouseDown(Button, KeysToShiftState(Message.Keys) + Shift, MP.X, MP.Y);
end;
end;
{------------------------------------------------------------------------------
TControl DoMouseUp "Event Handler"
------------------------------------------------------------------------------}
procedure TControl.DoMouseUp(var Message: TLMMouse; Button: TMouseButton);
var
P, MP: TPoint;
begin
if not (csNoStdEvents in ControlStyle) then
begin
MP := GetMousePosFromMessage(Message.Pos);
if (Button in [mbLeft, mbRight]) and DragManager.IsDragging then
begin
P := ClientToScreen(MP);
DragManager.MouseUp(Button, KeysToShiftState(Message.Keys), P.X, P.Y);
Message.Result := 1;
end;
MouseUp(Button, KeysToShiftState(Message.Keys), MP.X, MP.Y);
end;
end;
{------------------------------------------------------------------------------
TControl DoMouseWheel "Event Handler"
------------------------------------------------------------------------------}
function TControl.DoMouseWheel(Shift: TShiftState; WheelDelta: Integer;
MousePos: TPoint): Boolean;
begin
Result := False;
if Assigned(FOnMouseWheel)
then FOnMouseWheel(Self, Shift, WheelDelta, MousePos, Result);
if not Result then
begin
//debugln('TControl.DoMouseWheel calling DoCallMouseWheelEventHandler');
DoCallMouseWheelEventHandler(chtOnMouseWheel, Shift, WheelDelta, MousePos, Result);
end;
if not Result
then begin
if WheelDelta < 0
then Result := DoMouseWheelDown(Shift, MousePos)
else Result := DoMouseWheelUp(Shift, MousePos);
end;
end;
function TControl.DoMouseWheelHorz(Shift: TShiftState; WheelDelta: Integer;
MousePos: TPoint): Boolean;
begin
Result := False;
if Assigned(FOnMouseWheelHorz)
then FOnMouseWheelHorz(Self, Shift, WheelDelta, MousePos, Result);
if not Result then
begin
//debugln('TControl.DoMouseWheelHorz calling DoCallMouseWheelEventHandler');
DoCallMouseWheelEventHandler(chtOnMouseWheelHorz, Shift, WheelDelta, MousePos, Result);
end;
if not Result
then begin
if WheelDelta < 0
then Result := DoMouseWheelLeft(Shift, MousePos)
else Result := DoMouseWheelRight(Shift, MousePos);
end;
end;
{------------------------------------------------------------------------------
TControl DoMouseWheelDown "Event Handler"
------------------------------------------------------------------------------}
function TControl.DoMouseWheelDown(Shift: TShiftState; MousePos: TPoint): Boolean;
begin
Result := False;
if Assigned(FOnMouseWheelDown) then
FOnMouseWheelDown(Self, Shift, MousePos, Result);
end;
{------------------------------------------------------------------------------
TControl DoMouseWheelUp "Event Handler"
------------------------------------------------------------------------------}
function TControl.DoMouseWheelUp(Shift: TShiftState; MousePos: TPoint): Boolean;
begin
Result := False;
if Assigned(FOnMouseWheelUp) then
FOnMouseWheelUp(Self, Shift, MousePos, Result);
end;
{------------------------------------------------------------------------------
TControl DoMouseWheelLeft "Event Handler"
------------------------------------------------------------------------------}
function TControl.DoMouseWheelLeft(Shift: TShiftState; MousePos: TPoint): Boolean;
begin
Result := False;
if Assigned(FOnMouseWheelLeft) then
FOnMouseWheelLeft(Self, Shift, MousePos, Result);
end;
{------------------------------------------------------------------------------
TControl DoMouseWheelRight "Event Handler"
------------------------------------------------------------------------------}
function TControl.DoMouseWheelRight(Shift: TShiftState; MousePos: TPoint): Boolean;
begin
Result := False;
if Assigned(FOnMouseWheelRight) then
FOnMouseWheelRight(Self, Shift, MousePos, Result);
end;
procedure TControl.SetAnchorSide(Kind: TAnchorKind; AValue: TAnchorSide);
begin
GetAnchorSide(Kind).Assign(AValue);
end;
procedure TControl.SetBorderSpacing(const AValue: TControlBorderSpacing);
begin
if FBorderSpacing=AValue then exit;
FBorderSpacing.Assign(AValue);
end;
{------------------------------------------------------------------------------
Method: TControl.WMContextMenu
Params: Message
Returns: Nothing
ContextMenu event handler
------------------------------------------------------------------------------}
procedure TControl.WMContextMenu(var Message: TLMContextMenu);
var
TempPopupMenu: TPopupMenu;
P: TPoint;
Handled: Boolean;
begin
if (csDesigning in ComponentState) or (Message.Result <> 0) then Exit;
P := GetMousePosFromMessage(Message.Pos);
// X and Y = -1 when user clicks on keyboard menu button
if P.X <> -1 then
P := ScreenToClient(P);
Handled := False;
DoContextPopup(P, Handled);
if Handled then
begin
Message.Result := 1;
Exit;
end;
TempPopupMenu := GetPopupMenu;
if (TempPopupMenu <> nil) then
begin
if not TempPopupMenu.AutoPopup then Exit;
TempPopupMenu.PopupComponent := Self;
if P.X = -1 then
P := Point(0, 0);
P := ClientToScreen(P);
TempPopupMenu.Popup(P.X, P.Y);
Message.Result := 1;
end;
end;
{------------------------------------------------------------------------------
Method: TControl.WMLButtonDown
Params: Message
Returns: Nothing
Mouse event handler
------------------------------------------------------------------------------}
procedure TControl.WMLButtonDown(var Message: TLMLButtonDown);
begin
if (csCaptureMouse in ControlStyle) and (mbLeft in CaptureMouseButtons) then
begin
{$IFDEF VerboseMouseCapture}
DebugLn('TControl.WMLButtonDown ',Name,':',ClassName);
{$ENDIF}
MouseCapture := True;
end;
if csClickEvents in ControlStyle then Include(FControlState, csClicked);
DoMouseDown(Message, mbLeft, []);
//DebugLn('TCONTROL WMLBUTTONDOWN B ',Name,':',ClassName);
end;
{------------------------------------------------------------------------------
Method: TControl.WMRButtonDown
Params: Message
Returns: Nothing
Mouse event handler
------------------------------------------------------------------------------}
procedure TControl.WMRButtonDown(var Message: TLMRButtonDown);
begin
if (csCaptureMouse in ControlStyle) and (mbRight in CaptureMouseButtons) then
begin
{$IFDEF VerboseMouseCapture}
DebugLn('TControl.WMRButtonDown ',Name,':',ClassName);
{$ENDIF}
MouseCapture := True;
end;
DoMouseDown(Message, mbRight, []);
end;
{------------------------------------------------------------------------------
Method: TControl.WMMButtonDown
Params: Message
Returns: Nothing
Mouse event handler
------------------------------------------------------------------------------}
procedure TControl.WMMButtonDown(var Message: TLMMButtonDown);
begin
if (csCaptureMouse in ControlStyle) and (mbMiddle in CaptureMouseButtons) then
begin
{$IFDEF VerboseMouseCapture}
DebugLn('TControl.WMMButtonDown ',Name,':',ClassName);
{$ENDIF}
MouseCapture := True;
end;
DoMouseDown(Message, mbMiddle, []);
end;
procedure TControl.WMXButtonDown(var Message: TLMXButtonDown);
var
Btn: TMouseButton;
begin
if (Message.Keys and MK_XBUTTON1) <> 0 then Btn := mbExtra1
else if (Message.Keys and MK_XBUTTON2) <> 0 then Btn := mbExtra2
else Exit;
if (csCaptureMouse in ControlStyle) and (Btn in CaptureMouseButtons) then
begin
{$IFDEF VerboseMouseCapture}
DebugLn('TControl.WMXButtonDown ',Name,':',ClassName);
{$ENDIF}
MouseCapture := True;
end;
DoMouseDown(Message, Btn, []);
end;
{------------------------------------------------------------------------------
Method: TControl.WMLButtonDblClk
Params: Message
Returns: Nothing
Mouse event handler
------------------------------------------------------------------------------}
procedure TControl.WMLButtonDBLCLK(var Message: TLMLButtonDblClk);
begin
//TODO: SendCancelMode(self);
if (csCaptureMouse in ControlStyle) and (mbLeft in CaptureMouseButtons) then
begin
{$IFDEF VerboseMouseCapture}
DebugLn('TControl.WMLButtonDblClk ',Name,':',ClassName);
{$ENDIF}
MouseCapture := True;
end;
// first send a mouse down
DoMouseDown(Message, mbLeft ,[ssDouble]);
// then send the double click
if csClickEvents in ControlStyle then DblClick;
end;
{------------------------------------------------------------------------------
Method: TControl.WMRButtonDblClk
Params: Message
Returns: Nothing
Mouse event handler
------------------------------------------------------------------------------}
procedure TControl.WMRButtonDBLCLK(var Message: TLMRButtonDblClk);
begin
if (csCaptureMouse in ControlStyle) and (mbRight in CaptureMouseButtons) then
begin
{$IFDEF VerboseMouseCapture}
DebugLn('TControl.WMRButtonDblClk ',Name,':',ClassName);
{$ENDIF}
MouseCapture := True;
end;
DoMouseDown(Message, mbRight ,[ssDouble]);
end;
{------------------------------------------------------------------------------
Method: TControl.WMMButtonDblClk
Params: Message
Returns: Nothing
Mouse event handler
------------------------------------------------------------------------------}
procedure TControl.WMMButtonDBLCLK(var Message: TLMMButtonDblClk);
begin
if (csCaptureMouse in ControlStyle) and (mbMiddle in CaptureMouseButtons) then
begin
{$IFDEF VerboseMouseCapture}
DebugLn('TControl.WMMButtonDblClk ',Name,':',ClassName);
{$ENDIF}
MouseCapture := True;
end;
DoMouseDown(Message, mbMiddle ,[ssDouble]);
end;
procedure TControl.WMXButtonDBLCLK(var Message: TLMXButtonDblClk);
var
Btn: TMouseButton;
begin
if (Message.Keys and MK_XBUTTON1) <> 0 then Btn := mbExtra1
else if (Message.Keys and MK_XBUTTON2) <> 0 then Btn := mbExtra2
else Exit;
if (csCaptureMouse in ControlStyle) and (Btn in CaptureMouseButtons) then
begin
{$IFDEF VerboseMouseCapture}
DebugLn('TControl.WMXButtonDblClk ',Name,':',ClassName);
{$ENDIF}
MouseCapture := True;
end;
DoMouseDown(Message, Btn, [ssDouble]);
end;
{------------------------------------------------------------------------------
Method: TControl.WMLButtonTripleClk
Params: Message
Returns: Nothing
Mouse event handler
------------------------------------------------------------------------------}
procedure TControl.WMLButtonTripleCLK(var Message: TLMLButtonTripleClk);
begin
//TODO: SendCancelMode(self);
if (csCaptureMouse in ControlStyle) and (mbLeft in CaptureMouseButtons) then
begin
{$IFDEF VerboseMouseCapture}
DebugLn('TControl.WMLButtonTripleClk ',Name,':',ClassName);
{$ENDIF}
MouseCapture := True;
end;
if csClickEvents in ControlStyle then TripleClick;
DoMouseDown(Message, mbLeft ,[ssTriple]);
end;
{------------------------------------------------------------------------------
Method: TControl.WMRButtonTripleClk
Params: Message
Returns: Nothing
Mouse event handler
------------------------------------------------------------------------------}
procedure TControl.WMRButtonTripleCLK(var Message: TLMRButtonTripleClk);
begin
if (csCaptureMouse in ControlStyle) and (mbRight in CaptureMouseButtons) then
begin
{$IFDEF VerboseMouseCapture}
DebugLn('TControl.WMRButtonTripleClk ',Name,':',ClassName);
{$ENDIF}
MouseCapture := True;
end;
DoMouseDown(Message, mbRight ,[ssTriple]);
end;
{------------------------------------------------------------------------------
Method: TControl.WMMButtonTripleClk
Params: Message
Returns: Nothing
Mouse event handler
------------------------------------------------------------------------------}
procedure TControl.WMMButtonTripleCLK(var Message: TLMMButtonTripleClk);
begin
if (csCaptureMouse in ControlStyle) and (mbMiddle in CaptureMouseButtons) then
begin
{$IFDEF VerboseMouseCapture}
DebugLn('TControl.WMMButtonTripleClk ',Name,':',ClassName);
{$ENDIF}
MouseCapture := True;
end;
DoMouseDown(Message, mbMiddle ,[ssTriple]);
end;
procedure TControl.WMXButtonTripleCLK(var Message: TLMXButtonTripleClk);
var
Btn: TMouseButton;
begin
if (Message.Keys and MK_XBUTTON1) <> 0 then Btn := mbExtra1
else if (Message.Keys and MK_XBUTTON2) <> 0 then Btn := mbExtra2
else Exit;
if (csCaptureMouse in ControlStyle) and (Btn in CaptureMouseButtons) then
begin
{$IFDEF VerboseMouseCapture}
DebugLn('TControl.WMXButtonTripleClk ',Name,':',ClassName);
{$ENDIF}
MouseCapture := True;
end;
DoMouseDown(Message, Btn, [ssTriple]);
end;
{------------------------------------------------------------------------------
Method: TControl.WMLButtonQuadClk
Params: Message
Returns: Nothing
Mouse event handler
------------------------------------------------------------------------------}
procedure TControl.WMLButtonQuadCLK(var Message: TLMLButtonQuadClk);
begin
//TODO: SendCancelMode(self);
if (csCaptureMouse in ControlStyle) and (mbLeft in CaptureMouseButtons) then
begin
{$IFDEF VerboseMouseCapture}
DebugLn('TControl.WMLButtonQuadClk ',Name,':',ClassName);
{$ENDIF}
MouseCapture := True;
end;
if csClickEvents in ControlStyle then QuadClick;
DoMouseDown(Message, mbLeft ,[ssQuad]);
end;
{------------------------------------------------------------------------------
Method: TControl.WMRButtonQuadClk
Params: Message
Returns: Nothing
Mouse event handler
------------------------------------------------------------------------------}
procedure TControl.WMRButtonQuadCLK(var Message: TLMRButtonQuadClk);
begin
if (csCaptureMouse in ControlStyle) and (mbRight in CaptureMouseButtons) then
begin
{$IFDEF VerboseMouseCapture}
DebugLn('TControl.WMRButtonQuadClk ',Name,':',ClassName);
{$ENDIF}
MouseCapture := True;
end;
DoMouseDown(Message, mbRight ,[ssQuad]);
end;
{------------------------------------------------------------------------------
Method: TControl.WMMButtonQuadClk
Params: Message
Returns: Nothing
Mouse event handler
------------------------------------------------------------------------------}
procedure TControl.WMMButtonQuadCLK(var Message: TLMMButtonQuadClk);
begin
if (csCaptureMouse in ControlStyle) and (mbMiddle in CaptureMouseButtons) then
begin
{$IFDEF VerboseMouseCapture}
DebugLn('TControl.WMMButtonQuadClk ',Name,':',ClassName);
{$ENDIF}
MouseCapture := True;
end;
DoMouseDown(Message, mbMiddle ,[ssQuad]);
end;
procedure TControl.WMXButtonQuadCLK(var Message: TLMXButtonQuadClk);
var
Btn: TMouseButton;
begin
if (Message.Keys and MK_XBUTTON1) <> 0 then Btn := mbExtra1
else if (Message.Keys and MK_XBUTTON2) <> 0 then Btn := mbExtra2
else Exit;
if (csCaptureMouse in ControlStyle) and (Btn in CaptureMouseButtons) then
begin
{$IFDEF VerboseMouseCapture}
DebugLn('TControl.WMMButtonQuadClk ',Name,':',ClassName);
{$ENDIF}
MouseCapture := True;
end;
DoMouseDown(Message, Btn, [ssQuad]);
end;
{------------------------------------------------------------------------------
Method: TControl.WMLButtonUp
Params: Message
Returns: Nothing
Mouse event handler
------------------------------------------------------------------------------}
procedure TControl.WMLButtonUp(var Message: TLMLButtonUp);
begin
//DebugLn('TControl.WMLButtonUp A ',Name,':',ClassName,' csCaptureMouse=',DbgS(csCaptureMouse in ControlStyle),' csClicked=',DbgS(csClicked in ControlState));
if (csCaptureMouse in ControlStyle) and (mbLeft in CaptureMouseButtons) then
begin
{$IFDEF VerboseMouseCapture}
DebugLn('TControl.WMLButtonUp ',Name,':',ClassName);
{$ENDIF}
MouseCapture := False;
end;
if csClicked in ControlState then
begin
Exclude(FControlState, csClicked);
//DebugLn('TControl.WMLButtonUp B ',dbgs(ClientRect.Left),',',dbgs(ClientRect.Top),',',dbgs(ClientRect.Right),',',dbgs(ClientRect.Bottom),' ',dbgs(Message.Pos.X),',',dbgs(Message.Pos.Y));
if PtInRect(ClientRect, GetMousePosFromMessage(Message.Pos))
then begin
//DebugLn('TControl.WMLButtonUp C');
Click;
end;
end;
DoMouseUp(Message, mbLeft);
//DebugLn('TControl.WMLButtonUp END');
end;
{------------------------------------------------------------------------------
Method: TControl.WMRButtonUp
Params: Message
Returns: Nothing
Mouse event handler
------------------------------------------------------------------------------}
procedure TControl.WMRButtonUp(var Message: TLMRButtonUp);
begin
if (csCaptureMouse in ControlStyle) and (mbRight in CaptureMouseButtons) then
begin
{$IFDEF VerboseMouseCapture}
DebugLn('TControl.WMRButtonUp ',Name,':',ClassName);
{$ENDIF}
MouseCapture := False;
end;
//MouseUp event is independent of return values of contextmenu
DoMouseUp(Message, mbRight);
end;
{------------------------------------------------------------------------------
Method: TControl.WMMButtonUp
Params: Message
Returns: Nothing
Mouse event handler
------------------------------------------------------------------------------}
procedure TControl.WMMButtonUp(var Message: TLMMButtonUp);
begin
if (csCaptureMouse in ControlStyle) and (mbMiddle in CaptureMouseButtons) then
begin
{$IFDEF VerboseMouseCapture}
DebugLn('TControl.WMMButtonUp ',Name,':',ClassName);
{$ENDIF}
MouseCapture := False;
end;
DoMouseUp(Message, mbMiddle);
end;
procedure TControl.WMXButtonUp(var Message: TLMXButtonUp);
var
Btn: TMouseButton;
begin
if (Message.Keys and MK_XBUTTON1) <> 0 then Btn := mbExtra1
else if (Message.Keys and MK_XBUTTON2) <> 0 then Btn := mbExtra2
else Exit;
if (csCaptureMouse in ControlStyle) and (Btn in CaptureMouseButtons) then
begin
{$IFDEF VerboseMouseCapture}
DebugLn('TControl.WMMButtonUp ',Name,':',ClassName);
{$ENDIF}
MouseCapture := False;
end;
DoMouseUp(Message, Btn);
end;
{------------------------------------------------------------------------------
Method: TControl.WMMouseWheel
Params: Msg: The message
Returns: nothing
event handler.
------------------------------------------------------------------------------}
procedure TControl.WMMouseWheel(var Message: TLMMouseEvent);
var
MousePos: TPoint;
lState: TShiftState;
SP: TSmallPoint;
begin
SP.X := Message.X; // cannot use SmallPoint() here due to FPC inconsistency in Classes.TSmallPoint<>Types.TSmallPoint on Linux
SP.Y := Message.Y;
MousePos := GetMousePosFromMessage(SP);
lState := Message.State - [ssCaps, ssNum, ssScroll]; // Remove unreliable states, see http://bugs.freepascal.org/view.php?id=20065
if DoMouseWheel(lState, Message.WheelDelta, MousePos) then
Message.Result := 1 // handled, skip further handling by interface
else
inherited;
end;
procedure TControl.WMMouseHWheel(var Message: TLMMouseEvent);
var
MousePos: TPoint;
lState: TShiftState;
SP: TSmallPoint;
begin
SP.X := Message.X; // cannot use SmallPoint() here due to FPC inconsistency in Classes.TSmallPoint<>Types.TSmallPoint on Linux
SP.Y := Message.Y;
MousePos := GetMousePosFromMessage(SP);
lState := Message.State - [ssCaps, ssNum, ssScroll]; // Remove unreliable states, see http://bugs.freepascal.org/view.php?id=20065
if DoMouseWheelHorz(lState, Message.WheelDelta, MousePos) then
Message.Result := 1 // handled, skip further handling by interface
else
inherited;
end;
{------------------------------------------------------------------------------
TControl Click
------------------------------------------------------------------------------}
procedure TControl.Click;
function OnClickIsActionExecute: boolean;
begin
Result:=false;
if Action=nil then exit;
if not Assigned(Action.OnExecute) then exit;
if not Assigned(FOnClick) then exit;
Result:=SameMethod(TMethod(FOnClick),TMethod(Action.OnExecute));
end;
var
CallAction: Boolean;
begin
//DebugLn(['TControl.Click ',DbgSName(Self)]);
CallAction:=(not (csDesigning in ComponentState)) and (ActionLink <> nil);
// first call our own OnClick if it differs from Action.OnExecute
if Assigned(FOnClick)
and ((not CallAction) or (not OnClickIsActionExecute)) then
FOnClick(Self);
// then trigger the Action
if CallAction then
ActionLink.Execute(Self);
end;
{------------------------------------------------------------------------------
TControl DialogChar
Do something useful with accelerators etc.
------------------------------------------------------------------------------}
function TControl.DialogChar(var Message: TLMKey): Boolean;
begin
Result := False;
end;
procedure TControl.UpdateMouseCursor(X, Y: Integer);
begin
//DebugLn(['TControl.UpdateMouseCursor ',DbgSName(Self)]);
if csDesigning in ComponentState then Exit;
if Screen.RealCursor <> crDefault then Exit;
SetTempCursor(Cursor);
end;
{------------------------------------------------------------------------------
function TControl.CheckChildClassAllowed(ChildClass: TClass;
ExceptionOnInvalid: boolean): boolean;
Checks if this control can be the parent of a control of class ChildClass.
------------------------------------------------------------------------------}
function TControl.CheckChildClassAllowed(ChildClass: TClass; ExceptionOnInvalid: Boolean): Boolean;
begin
Result := ChildClassAllowed(ChildClass);
if (not Result) and ExceptionOnInvalid then
raise EInvalidOperation.CreateFmt(rsControlClassCantContainChildClass, [ClassName, ChildClass.ClassName]);
end;
{------------------------------------------------------------------------------
procedure TControl.CheckNewParent(AParent: TWinControl);
Checks if this control can be the child of AParent.
This check is executed in SetParent.
------------------------------------------------------------------------------}
procedure TControl.CheckNewParent(AParent: TWinControl);
begin
if (AParent <> nil) then
AParent.CheckChildClassAllowed(ClassType, True);
if AParent = Self then
raise EInvalidOperation.Create(rsAControlCanNotHaveItselfAsParent);
end;
{------------------------------------------------------------------------------
TControl SetAutoSize
------------------------------------------------------------------------------}
procedure TControl.SetAutoSize(Value: Boolean);
begin
If AutoSize <> Value then begin
FAutoSize := Value;
//debugln('TControl.SetAutoSize ',DbgSName(Self));
if FAutoSize then
AdjustSize;
end;
end;
{------------------------------------------------------------------------------
TControl DoAutoSize
IMPORTANT: Many Delphi controls override this method and many call this method
directly after setting some properties.
During handle creation not all interfaces can create complete Device Contexts
which are needed to calculate things like text size.
That's why you should always call AdjustSize instead of DoAutoSize.
------------------------------------------------------------------------------}
procedure TControl.DoAutoSize;
var
PreferredWidth: integer;
PreferredHeight: integer;
ResizeWidth: Boolean;
ResizeHeight: Boolean;
begin
// handled by TWinControl, or other descendants
ResizeWidth:=not WidthIsAnchored;
ResizeHeight:=not HeightIsAnchored;
if ResizeWidth or ResizeHeight then begin
PreferredWidth:=0;
PreferredHeight:=0;
GetPreferredSize(PreferredWidth,PreferredHeight);
if (not ResizeWidth) or (PreferredWidth<=0) then PreferredWidth:=Width;
if (not ResizeHeight) or (PreferredHeight<=0) then PreferredHeight:=Height;
SetBoundsKeepBase(Left,Top,PreferredWidth,PreferredHeight);
end;
end;
{------------------------------------------------------------------------------
TControl DoAllAutoSize
Run DoAutoSize until done.
------------------------------------------------------------------------------}
procedure TControl.DoAllAutoSize;
procedure AutoSizeControl(AControl: TControl);
var
AWinControl: TWinControl;
i: Integer;
Needed: Boolean;
begin
if AControl.AutoSizeDelayed then exit;
Needed:=cfAutoSizeNeeded in AControl.FControlFlags;
//DebugLn(['TControl.DoAllAutoSize.AutoSizeControl ',DbgSName(AControl),' AutoSize=',AControl.AutoSize,' IsControlVisible=',AControl.IsControlVisible,' cfAutoSizeNeeded=',Needed]);
Exclude(AControl.FControlFlags, cfAutoSizeNeeded);
if not AControl.IsControlVisible then exit;
if Needed and AControl.AutoSize and
(not ((AControl.Parent = nil) and (csDesigning in AControl.ComponentState))) and
(not (csDesignInstance in AControl.ComponentState))
then
AControl.DoAutoSize;
if AControl is TWinControl then
begin
// recursive
AWinControl := TWinControl(AControl);
//DebugLn(['AutoSizeControl ',DbgSName(AWinControl)]);
AWinControl.AlignControl(nil);
for i := 0 to AWinControl.ControlCount - 1 do
AutoSizeControl(AWinControl.Controls[i]);
end;
end;
function CallAllOnResize(AControl: TControl): boolean;
// The OnResize event is called for Delphi compatibility after child resizes.
// Call all OnResize events so they will hopefully only invoke one more
// loop, instead of one per OnResize.
var
AWinControl: TWinControl;
i: Integer;
begin
if AControl = nil then Exit(True);
Result := False;
if AControl is TWinControl then
begin
AWinControl := TWinControl(AControl);
for i := 0 to AWinControl.ControlCount - 1 do
if AWinControl.Controls[i].IsControlVisible
and not CallAllOnResize(AWinControl.Controls[i]) then
exit;
end;
{$IFDEF VerboseOnResize}
debugln(['TControl.DoAllAutoSize ',DbgSName(AControl),' calling Resize ...']);
{$ENDIF}
AControl.Resize;
Result := True;
end;
var
i: Integer;
begin
if Parent <> nil then
raise EInvalidOperation.Create('TControl.DoAllAutoSize Parent <> nil');
if AutoSizingAll then exit;
FAutoSizingAll := True;
if not (Self is TWinControl) then exit;
{$IFDEF VerboseAllAutoSize}
DebugLn(['TControl.DoAllAutoSize START ',DbgSName(Self)]);
{$ENDIF}
//writeln(GetStackTrace(true));
try
i:=0;
while (not AutoSizeDelayed) and (cfAutoSizeNeeded in FControlFlags) do
begin
{$IFDEF VerboseAllAutoSize}
DebugLn(['TControl.DoAllAutoSize LOOP ',DbgSName(Self),' ',dbgs(BoundsRect)]);
{$ENDIF}
AutoSizeControl(Self);
if not (cfAutoSizeNeeded in FControlFlags) then
CallAllOnResize(Self);
inc(i);
if i=1000 then
Include(FControlFlags,cfKillChangeBounds);
if i=2000 then
Include(FControlFlags,cfKillInvalidatePreferredSize);
if i=3000 then
Include(FControlFlags,cfKillAdjustSize);
end;
finally
FControlFlags:=FControlFlags-[cfKillChangeBounds,
cfKillInvalidatePreferredSize,cfKillAdjustSize];
FAutoSizingAll := False;
end;
{$IFDEF VerboseAllAutoSize}
DebugLn(['TControl.DoAllAutoSize END ',DbgSName(Self),' ',dbgs(BoundsRect)]);
{$ENDIF}
end;
procedure TControl.DoAutoAdjustLayout(const AMode: TLayoutAdjustmentPolicy;
const AXProportion, AYProportion: Double);
var
AAWidth, AAHeight: Boolean;
NewLeft, NewTop, NewWidth, NewHeight, NewRight, NewBottom, OldWidth, OldHeight,
NewBaseLeft, NewBaseTop, NewBaseWidth, NewBaseHeight: Integer;
begin
// Apply the changes
if AMode in [lapAutoAdjustWithoutHorizontalScrolling, lapAutoAdjustForDPI] then
begin
// Dimensions
AAWidth := False;
AAHeight := False;
NewLeft := Left;
NewTop := Top;
NewWidth := Width;
NewHeight := Height;
OldWidth := Width;
OldHeight := Height;
ShouldAutoAdjust(AAWidth, AAHeight);
AAWidth := AAWidth and (Align in [alNone, alLeft, alRight])
and not((akLeft in Anchors) and (akRight in Anchors));
AAHeight := AAHeight and (Align in [alNone, alTop, alBottom])
and not((akTop in Anchors) and (akBottom in Anchors));
if (Align in [alNone, alRight]) and (akLeft in Anchors) then
NewLeft := Round(NewLeft * AXProportion);
if (Align=alNone) and (akRight in Anchors) and (Parent<>nil)
and (AnchorSideRight.Control=nil) then
begin
if not(akLeft in Anchors) then
begin
NewRight := Round((Parent.ClientWidth-NewLeft-OldWidth) * AXProportion);
NewLeft := Parent.ClientWidth-NewRight-OldWidth
end else
begin
NewRight := Round((Parent.ClientWidth-Left-OldWidth) * AXProportion);
NewWidth := Parent.ClientWidth-NewLeft-NewRight;
end;
end;
if (Align in [alNone, alBottom]) and (akTop in Anchors) then
NewTop := Round(NewTop * AYProportion);
if (Align=alNone) and (akBottom in Anchors) and (Parent<>nil)
and (AnchorSideBottom.Control=nil) then
begin
if not(akTop in Anchors) then
begin
NewBottom := Round((Parent.ClientHeight-NewTop-OldHeight) * AYProportion);
NewTop := Parent.ClientHeight-NewBottom-OldHeight
end else
begin
NewBottom := Round((Parent.ClientHeight-Top-OldHeight) * AYProportion);
NewHeight := Parent.ClientHeight-NewTop-NewBottom;
end;
end;
if AAWidth then
NewWidth := Round(Width * AXProportion);
if AAHeight then
NewHeight := Round(Height * AYProportion);
BorderSpacing.AutoAdjustLayout(AXProportion, AYProportion);
Constraints.AutoAdjustLayout(AXProportion, AYProportion);
NewBaseLeft := NewLeft;
NewBaseTop := NewTop;
NewBaseWidth := NewWidth;
NewBaseHeight := NewHeight;
NewWidth := Constraints.MinMaxWidth(NewWidth);
NewHeight := Constraints.MinMaxHeight(NewHeight);
if AAWidth or (NewBaseWidth<>NewWidth) then
begin
if akRight in Anchors then
NewLeft := NewLeft-NewWidth+OldWidth;
end;
if AAHeight or (NewBaseHeight<>NewHeight) then
begin
if akBottom in Anchors then
NewTop := NewTop-NewHeight+OldHeight;
end;
if AAWidth and (akRight in Anchors) then
NewBaseLeft := NewBaseLeft-NewBaseWidth+OldWidth;
if AAHeight and (akBottom in Anchors) then
NewBaseTop := NewBaseTop-NewBaseHeight+OldHeight;
FBaseBounds.Left:=NewBaseLeft;
FBaseBounds.Top:=NewBaseTop;
FBaseBounds.Right:=NewBaseLeft+NewBaseWidth;
FBaseBounds.Bottom:=NewBaseTop+NewBaseHeight;
if Parent<>nil then
begin
FBaseParentClientSize.cx:=Parent.ClientWidth;
FBaseParentClientSize.cy:=Parent.ClientHeight;
end;
SetBoundsKeepBase(NewLeft, NewTop, NewWidth, NewHeight);
end;
end;
procedure TControl.AnchorSideChanged(TheAnchorSide: TAnchorSide);
begin
//debugln('TControl.AnchorSideChanged ',DbgSName(Self));
RequestAlign;
end;
procedure TControl.ForeignAnchorSideChanged(TheAnchorSide: TAnchorSide;
Operation: TAnchorSideChangeOperation);
var
Side: TAnchorKind;
AControl: TControl;
begin
AControl:=TheAnchorSide.Owner;
//debugln('TControl.ForeignAnchorSideChanged A Self=',DbgSName(Self),' TheAnchorSide.Owner=',DbgSName(TheAnchorSide.Owner),' Operation=',dbgs(ord(Operation)),' Anchor=',dbgs(TheAnchorSide.Kind));
if TheAnchorSide.Control=Self then begin
if FAnchoredControls=nil then
FAnchoredControls:=TFPList.Create;
if FAnchoredControls.IndexOf(AControl)<0 then
FAnchoredControls.Add(AControl);
end else if FAnchoredControls<>nil then begin
if TheAnchorSide.Owner<>nil then begin
for Side:=Low(TAnchorKind) to High(TAnchorKind) do begin
if (AControl.FAnchorSides[Side]<>nil)
and (AControl.FAnchorSides[Side].Control=Self) then begin
// still anchored
exit;
end;
end;
end;
FAnchoredControls.Remove(AControl);
end;
end;
function TControl.AutoSizePhases: TControlAutoSizePhases;
begin
if Parent<>nil then
Result:=Parent.AutoSizePhases
else
Result:=[];
end;
{------------------------------------------------------------------------------
function TControl.AutoSizeDelayed: boolean;
Returns true, if the DoAutoSize should skip now, because not all parameters
needed to calculate the AutoSize bounds are loaded or initialized.
------------------------------------------------------------------------------}
function TControl.AutoSizeDelayed: Boolean;
begin
Result:=(FAutoSizingLockCount>0)
// no autosize during loading or destruction
or ([csLoading,csDestroying]*ComponentState<>[])
or (cfLoading in FControlFlags)
// no autosize for invisible controls
or (not IsControlVisible)
// if there is no parent, then this control is not visible
// (TWinControl and TCustomForm override this)
or AutoSizeDelayedHandle
// if there is a parent, ask it
or ((Parent<>nil) and Parent.AutoSizeDelayed);
{$IFDEF VerboseCanAutoSize}
if Result {and AutoSize} then begin
DbgOut('TControl.AutoSizeDelayed Self='+DbgSName(Self)+' ');
if FAutoSizingLockCount>0 then debugln('FAutoSizingLockCount=',dbgs(FAutoSizingLockCount))
else if csLoading in ComponentState then debugln('csLoading')
else if csDestroying in ComponentState then debugln('csDestroying')
else if cfLoading in FControlFlags then debugln('cfLoading')
else if not IsControlVisible then debugln('not IsControlVisible')
else if AutoSizeDelayedHandle then debugln('AutoSizeDelayedHandle')
else if ((Parent<>nil) and Parent.AutoSizeDelayed) then debugln('Parent.AutoSizeDelayed')
else debugln('?');
end;
{$ENDIF}
end;
function TControl.AutoSizeDelayedReport: string;
begin
if (FAutoSizingLockCount>0) then
Result:='FAutoSizingLockCount='+dbgs(FAutoSizingLockCount)
else if csLoading in ComponentState then
Result:='csLoading'
else if csDestroying in ComponentState then
Result:='csDestroying'
else if cfLoading in FControlFlags then
Result:='cfLoading'
else if IsControlVisible then
Result:='not IsControlVisible'
else if AutoSizeDelayedHandle then
Result:='AutoSizeDelayedHandle'
else if Parent<>nil then
Result:=Parent.AutoSizeDelayedReport
else
Result:='?';
end;
{------------------------------------------------------------------------------
TControl AutoSizeDelayedHandle
Returns true if AutoSize should be skipped / delayed because of its handle.
A TControl does not have a handle, so it needs a parent.
------------------------------------------------------------------------------}
function TControl.AutoSizeDelayedHandle: Boolean;
begin
Result := Parent = nil;
end;
{------------------------------------------------------------------------------
TControl SetBoundsRect
------------------------------------------------------------------------------}
procedure TControl.SetBoundsRect(const ARect: TRect);
begin
{$IFDEF CHECK_POSITION}
if CheckPosition(Self) then
DebugLn('[TControl.SetBoundsRect] ',Name,':',ClassName);
{$ENDIF}
SetBounds(ARect.Left, ARect.Top,
Max(ARect.Right - ARect.Left, 0), Max(ARect.Bottom - ARect.Top, 0));
end;
procedure TControl.SetBoundsRectForNewParent(const AValue: TRect);
begin
Include(FControlFlags,cfBoundsRectForNewParentValid);
FBoundsRectForNewParent:=AValue;
end;
{------------------------------------------------------------------------------
TControl SetClientHeight
------------------------------------------------------------------------------}
procedure TControl.SetClientHeight(Value: Integer);
begin
if csLoading in ComponentState then begin
FLoadedClientSize.cy:=Value;
Include(FControlFlags,cfClientHeightLoaded);
end else begin
// during loading the ClientHeight is not used to set the Height of the
// control, but only to restore autosizing. For example Anchors=[akBottom]
// needs ClientHeight.
SetClientSize(Point(ClientWidth, Value));
end;
end;
{------------------------------------------------------------------------------
TControl SetClientSize
------------------------------------------------------------------------------}
procedure TControl.SetClientSize(const Value: TPoint);
var
Client: TRect;
begin
Client := GetClientRect;
SetBounds(FLeft, FTop,
Width - Client.Right + Value.X, Height - Client.Bottom + Value.Y);
end;
{------------------------------------------------------------------------------
TControl SetClientWidth
------------------------------------------------------------------------------}
procedure TControl.SetClientWidth(Value: Integer);
begin
if csLoading in ComponentState then begin
FLoadedClientSize.cx:=Value;
Include(FControlFlags,cfClientWidthLoaded);
end else begin
// during loading the ClientWidth is not used to set the Width of the
// control, but only to restore autosizing. For example Anchors=[akRight]
// needs ClientWidth.
SetClientSize(Point(Value, ClientHeight));
end;
end;
{------------------------------------------------------------------------------
TControl SetTempCursor
------------------------------------------------------------------------------}
procedure TControl.SetTempCursor(Value: TCursor);
begin
if Parent<>nil then
Parent.SetTempCursor(Value);
end;
procedure TControl.ActiveDefaultControlChanged(NewControl: TControl);
begin
end;
procedure TControl.UpdateRolesForForm;
begin
// called by the form when the "role" controls DefaultControl or CancelControl
// has changed
end;
{------------------------------------------------------------------------------
TControl SetCursor
------------------------------------------------------------------------------}
procedure TControl.SetCursor(Value: TCursor);
begin
if FCursor <> Value then
begin
FCursor := Value;
Perform(CM_CURSORCHANGED, 0, 0);
end;
end;
procedure TControl.SetDragCursor(const AValue: TCursor);
begin
if FDragCursor=AValue then exit;
FDragCursor:=AValue;
end;
procedure TControl.SetFont(Value: TFont);
begin
if FFont.IsEqual(Value) then exit;
FFont.Assign(Value);
Invalidate;
end;
{------------------------------------------------------------------------------
TControl SetEnabled
------------------------------------------------------------------------------}
procedure TControl.SetEnabled(Value: Boolean);
begin
if FEnabled <> Value
then begin
EnabledChanging;
FEnabled := Value;
Perform(CM_ENABLEDCHANGED, 0, 0);
EnabledChanged;
end;
end;
{------------------------------------------------------------------------------
TControl SetMouseCapture
------------------------------------------------------------------------------}
procedure TControl.SetMouseCapture(Value : Boolean);
begin
if (MouseCapture <> Value) or (not Value and (CaptureControl=Self))
then begin
{$IFDEF VerboseMouseCapture}
DebugLn('TControl.SetMouseCapture ',DbgSName(Self),' NewValue=',DbgS(Value));
{$ENDIF}
if Value
then SetCaptureControl(Self)
else SetCaptureControl(nil);
end
end;
{------------------------------------------------------------------------------
Method: TControl.SetHint
Params: Value: the text of the hint to be set
Returns: Nothing
Sets the hint text of a control
------------------------------------------------------------------------------}
procedure TControl.SetHint(const Value: TTranslateString);
begin
if FHint = Value then exit;
FHint := Value;
end;
{------------------------------------------------------------------------------
TControl SetName
------------------------------------------------------------------------------}
procedure TControl.SetName(const Value: TComponentName);
var
ChangeText: Boolean;
begin
if Name=Value then exit;
ChangeText :=
(csSetCaption in ControlStyle) and not (csLoading in ComponentState) and
(Name = Text) and
((Owner = nil) or not (Owner is TControl) or not (csLoading in Owner.ComponentState));
inherited SetName(Value);
if ChangeText then Text := Value;
end;
{------------------------------------------------------------------------------
TControl Show
------------------------------------------------------------------------------}
procedure TControl.Show;
begin
if Parent <> nil then Parent.ShowControl(Self);
// do not switch the visible flag in design mode
if not (csDesigning in ComponentState) or
(csNoDesignVisible in ControlStyle) then Visible := True;
end;
{------------------------------------------------------------------------------
TControl Notification
------------------------------------------------------------------------------}
procedure TControl.Notification(AComponent: TComponent; Operation: TOperation);
var
Kind: TAnchorKind;
begin
inherited Notification(AComponent, Operation);
if Operation = opRemove then
begin
if AComponent = PopupMenu then
PopupMenu := nil
else if AComponent = Action then
Action := nil
else if AComponent = FHostDockSite then
FHostDockSite := nil;
//debugln('TControl.Notification A ',DbgSName(Self),' ',DbgSName(AComponent));
for Kind := Low(TAnchorKind) to High(TAnchorKind) do
begin
if (FAnchorSides[Kind] <> nil) and (FAnchorSides[Kind].Control = AComponent) then
FAnchorSides[Kind].FControl := nil;
end;
end;
end;
procedure TControl.DoFloatMsg(ADockSource: TDragDockObject);
var
P: TPoint;
FloatHost: TWinControl;
R: TRect;
begin
//DebugLn(['TControl.DoFloatMsg ',DbgSName(Self),' Floating=',Floating]);
if Floating and (Parent <> nil) then
begin
P := Parent.ClientToScreen(Point(Left, Top));
R := ADockSource.DockRect;
Parent.BoundsRect := Bounds(R.Left + Parent.Left - P.X, R.Top + Parent.Top - P.Y,
R.Right - R.Left + Parent.Width - Width, R.Bottom - R.Top + Parent.Height - Height);
end else
begin
FloatHost := CreateFloatingDockSite(ADockSource.DockRect);
if FloatHost <> nil then
begin
FloatHost.Caption := FloatHost.GetDockCaption(Self);
ADockSource.DragTarget := FloatHost;
FloatHost.Show;
end;
end;
end;
{------------------------------------------------------------------------------
TControl GetText
------------------------------------------------------------------------------}
function TControl.GetText: TCaption;
var
len: Integer;
GetTextMethod: TMethod;
begin
// Check if GetTextBuf is overridden, otherwise we can call RealGetText directly
Assert(Assigned(@Self.GetTextBuf), 'TControl.GetText: GetTextBuf Method is Nil');
GetTextMethod := TMethod(@Self.GetTextBuf);
if GetTextMethod.Code = Pointer(@TControl.GetTextBuf) then begin
Result := RealGetText;
end
else begin
// Bummer, we have to do it the compatible way.
DebugLn('Note: GetTextBuf is overridden for: ', Classname);
len := GetTextLen;
if len = 0 then begin
Result := '';
end
else begin
SetLength(Result, len+1); // make sure there is room for the extra #0
FillChar(Result[1], len, #0);
len := GetTextBuf(@Result[1], len+1);
SetLength(Result, len);
end;
end;
end;
{------------------------------------------------------------------------------
TControl RealGetText
------------------------------------------------------------------------------}
function TControl.RealGetText: TCaption;
begin
Result := FCaption;
end;
function TControl.GetTextLen: Integer;
begin
Result := Length(FCaption);
end;
function TControl.GetAction: TBasicAction;
begin
if ActionLink <> nil then
Result := ActionLink.Action
else
Result := nil;
end;
function TControl.GetActionLinkClass: TControlActionLinkClass;
begin
Result := TControlActionLink;
end;
function TControl.IsClientHeightStored: Boolean;
begin
Result:=false;
end;
function TControl.IsClientWidthStored: Boolean;
begin
Result:=false;
end;
function TControl.WidthIsAnchored: Boolean;
var
CurAnchors: TAnchors;
begin
if Align=alCustom then exit(true); // width depends on parent
CurAnchors:=Anchors;
if Align<>alNone then CurAnchors:=CurAnchors+AnchorAlign[Align];
Result:=(CurAnchors*[akLeft,akRight]=[akLeft,akRight]);
if not Result then begin
if Parent<>nil then
Result:=Parent.ChildSizing.Layout<>cclNone;
end;
end;
function TControl.HeightIsAnchored: Boolean;
var
CurAnchors: TAnchors;
begin
if Align=alCustom then exit(true); // height depends on parent
CurAnchors:=Anchors;
if Align<>alNone then CurAnchors:=CurAnchors+AnchorAlign[Align];
Result:=(CurAnchors*[akTop,akBottom]=[akTop,akBottom]);
if not Result then begin
if Parent<>nil then
Result:=Parent.ChildSizing.Layout<>cclNone;
end;
end;
procedure TControl.WMCancelMode(var Message: TLMessage);
begin
SetCaptureControl(nil);
end;
function TControl.IsEnabledStored: Boolean;
begin
Result := (ActionLink = nil) or not ActionLink.IsEnabledLinked;
end;
function TControl.IsFontStored: Boolean;
begin
Result := not ParentFont;
end;
function TControl.IsHintStored: Boolean;
begin
Result := (ActionLink = nil) or not ActionLink.IsHintLinked;
end;
{------------------------------------------------------------------------------
TControl InvalidateControl
------------------------------------------------------------------------------}
procedure TControl.InvalidateControl(CtrlIsVisible, CtrlIsOpaque: Boolean);
var
Rect: TRect;
function BackgroundClipped: Boolean;
var
R: TRect;
List: TFPList;
I: Integer;
C: TControl;
begin
Result := True;
List := FParent.FControls;
if List<>nil then begin
I := List.IndexOf(Self);
while I > 0 do
begin
Dec(I);
C := TControl(List[I]);
if not (C is TWinControl) then
with C do
if IsControlVisible and (csOpaque in ControlStyle) then
begin
IntersectRect(R, Rect, BoundsRect);
if EqualRect(R, Rect) then Exit;
end;
end;
end;
Result := False;
end;
begin
//DebugLn(['TControl.InvalidateControl ',DbgSName(Self)]);
if (Parent=nil) or (not Parent.HandleAllocated)
or ([csLoading,csDestroying]*Parent.ComponentState<>[])
then exit;
// Note: it should invalidate, when this control is loaded/destroyed, but parent not
if (CtrlIsVisible or ((csDesigning in ComponentState) and
not (csNoDesignVisible in ControlStyle))) then
begin
Rect := BoundsRect;
InvalidateRect(Parent.Handle, @Rect, not (CtrlIsOpaque or
(csOpaque in Parent.ControlStyle) or BackgroundClipped));
end;
end;
{------------------------------------------------------------------------------
procedure TControl.InvalidateControl(CtrlIsVisible, CtrlIsOpaque,
IgnoreWinControls: Boolean);
------------------------------------------------------------------------------}
procedure TControl.InvalidateControl(CtrlIsVisible, CtrlIsOpaque,
IgnoreWinControls: Boolean);
begin
//DebugLn(['TControl.InvalidateControl ',DbgSName(Self)]);
if IgnoreWinControls and (Self is TWinControl) then exit;
InvalidateControl(CtrlIsVisible,CtrlIsOpaque);
end;
{------------------------------------------------------------------------------
TControl Refresh
------------------------------------------------------------------------------}
procedure TControl.Refresh;
begin
Repaint;
end;
{------------------------------------------------------------------------------
TControl Repaint
------------------------------------------------------------------------------}
procedure TControl.Repaint;
var
DC: HDC;
begin
if (Parent=nil) or (not Parent.HandleAllocated)
or (csDestroying in ComponentState) then exit;
if IsVisible then
if csOpaque in ControlStyle then
begin
{$IFDEF VerboseDsgnPaintMsg}
if csDesigning in ComponentState then
DebugLn('TControl.Repaint A ',Name,':',ClassName);
{$ENDIF}
DC := GetDC(Parent.Handle);
try
IntersectClipRect(DC, Left, Top, Left + Width, Top + Height);
Parent.PaintControls(DC, Self);
finally
ReleaseDC(Parent.Handle, DC);
end;
end else
begin
Invalidate;
Update;
end;
end;
{------------------------------------------------------------------------------
TControl Resize
Calls OnResize
-------------------------------------------------------------------------------}
procedure TControl.Resize;
begin
if ([csLoading,csDestroying]*ComponentState<>[]) then exit;
if AutoSizeDelayed then exit;
if (FLastResizeWidth<>Width) or (FLastResizeHeight<>Height)
or (FLastResizeClientWidth<>ClientWidth)
or (FLastResizeClientHeight<>ClientHeight) then begin
{if CompareText('SubPanel',Name)=0 then begin
DebugLn(['[TControl.Resize] ',Name,':',ClassName,
' Last=',FLastResizeWidth,',',FLastResizeHeight,
' LastClient=',FLastResizeClientWidth,',',FLastResizeClientHeight,
' New=',Width,',',Height,
' NewClient=',ClientWidth,',',ClientHeight]);
DumpStack;
end;}
FLastResizeWidth:=Width;
FLastResizeHeight:=Height;
FLastResizeClientWidth:=ClientWidth;
FLastResizeClientHeight:=ClientHeight;
DoOnResize;
end;
end;
procedure TControl.Loaded;
function FindLoadingControl(AControl: TControl): TControl;
var
i: Integer;
AWinControl: TWinControl;
begin
if csLoading in AControl.ComponentState then exit(AControl);
if AControl is TWinControl then begin
AWinControl:=TWinControl(AControl);
for i:=0 to AWinControl.ControlCount-1 do
begin
Result:=FindLoadingControl(AWinControl.Controls[i]);
if Result<>nil then exit;
end;
end;
Result:=nil;
end;
procedure ClearLoadingFlags(AControl: TControl);
var
i: Integer;
AWinControl: TWinControl;
begin
Exclude(AControl.FControlFlags,cfLoading);
if AControl is TWinControl then begin
AWinControl:=TWinControl(AControl);
for i:=0 to AWinControl.ControlCount-1 do
ClearLoadingFlags(AWinControl.Controls[i]);
end;
end;
procedure CheckLoading(AControl: TControl);
var
TopParent: TControl;
begin
TopParent:=AControl;
while (TopParent.Parent<>nil)
and (cfLoading in TopParent.Parent.FControlFlags) do
TopParent:=TopParent.Parent;
if FindLoadingControl(TopParent)<>nil then exit;
// all components on the form finished loading
ClearLoadingFlags(TopParent);
// call LoadedAll
DisableAutoSizing{$IFDEF DebugDisableAutoSizing}('TControl.Loaded.CheckLoading'){$ENDIF};
try
AControl.LoadedAll;
finally
EnableAutoSizing{$IFDEF DebugDisableAutoSizing}('TControl.Loaded.CheckLoading'){$ENDIF};
end;
end;
var
UseClientWidthForWidth: boolean;
UseClientHeightForHeight: boolean;
NewWidth: LongInt;
NewHeight: LongInt;
begin
inherited Loaded;
{DebugLn(['TControl.Loaded A ',DbgSName(Self),
' LoadedClientWidth=',cfClientWidthLoaded in FControlFlags,'=',FLoadedClientSize.X,
' LoadedClientHeight=',cfClientHeightLoaded in FControlFlags,'=',FLoadedClientSize.Y,
' LoadedBounds=',DbgS(FReadBounds),
'']);}
UseClientWidthForWidth:=(not (cfWidthLoaded in FControlFlags))
and (cfClientWidthLoaded in FControlFlags);
UseClientHeightForHeight:=(not (cfHeightLoaded in FControlFlags))
and (cfClientHeightLoaded in FControlFlags);
if UseClientWidthForWidth or UseClientHeightForHeight then begin
//DebugLn(['TControl.Loaded ',DbgSName(Self),' Note: Width and/or Height were not set during loading, using ClientWidth/ClientHeight']);
NewWidth:=Width;
if UseClientWidthForWidth then
NewWidth:=FLoadedClientSize.cx;
NewHeight:=Height;
if UseClientHeightForHeight then
NewHeight:=FLoadedClientSize.cy;
SetBoundsKeepBase(Left,Top,NewWidth,NewHeight);
end;
if Assigned(Parent) then
begin
if ParentColor then
begin
Color := Parent.Color;
FParentColor := True;
end;
if ParentFont then
begin
Font := Parent.Font;
FParentFont := True;
end;
if ParentBidiMode then
begin
BiDiMode := Parent.BiDiMode;
FParentBidiMode := True;
end;
if ParentShowHint then
begin
ShowHint := Parent.ShowHint;
FParentShowHint := True;
end;
end;
UpdateBaseBounds(true,true,true);
// store designed width and height for undocking
FUndockHeight := Height;
FUndockWidth := Width;
if Action <> nil then ActionChange(Action, True);
CheckLoading(Self);
end;
procedure TControl.LoadedAll;
begin
AdjustSize;
{$IFDEF VerboseOnResize}
debugln(['TControl.LoadedAll ',DbgSName(Self),' calling Resize ...']);
{$ENDIF}
Resize;
CheckOnChangeBounds;
end;
{------------------------------------------------------------------------------
procedure TControl.DefineProperties(Filer: TFiler);
------------------------------------------------------------------------------}
procedure TControl.DefineProperties(Filer: TFiler);
begin
// Optimiziation:
// do not call inherited: TComponent only defines 'Left' and 'Top' and
// TControl has them as regular properties.
end;
{------------------------------------------------------------------------------
procedure TControl.AssignTo(Dest: TPersistent);
------------------------------------------------------------------------------}
procedure TControl.AssignTo(Dest: TPersistent);
begin
if Dest is TCustomAction then
with TCustomAction(Dest) do begin
Enabled := Self.Enabled;
Hint := Self.Hint;
Caption := Self.Caption;
Visible := Self.Visible;
OnExecute := Self.OnClick;
HelpContext := Self.HelpContext;
HelpKeyword := Self.HelpKeyword;
HelpType := Self.HelpType;
end
else inherited AssignTo(Dest);
end;
procedure TControl.ReadState(Reader: TReader);
begin
Include(FControlFlags, cfLoading);
DisableAutoSizing{$IFDEF DebugDisableAutoSizing}('TControl.ReadState'){$ENDIF};
try
Include(FControlState, csReadingState);
inherited ReadState(Reader);
finally
Exclude(FControlState, csReadingState);
EnableAutoSizing{$IFDEF DebugDisableAutoSizing}('TControl.ReadState'){$ENDIF};
end;
end;
procedure TControl.FormEndUpdated;
// called when control is on a form and EndFormUpdate reached 0
// it is called recursively
begin
end;
{------------------------------------------------------------------------------
TControl SetBounds
------------------------------------------------------------------------------}
procedure TControl.SetBounds(aLeft, aTop, aWidth, aHeight: Integer);
begin
ChangeBounds(ALeft, ATop, AWidth, AHeight, false);
end;
{------------------------------------------------------------------------------
TControl SetConstraints
------------------------------------------------------------------------------}
procedure TControl.SetConstraints(const Value : TSizeConstraints);
begin
FConstraints.Assign(Value);
end;
procedure TControl.SetDesktopFont(const AValue: Boolean);
begin
if FDesktopFont <> AValue then
begin
FDesktopFont := AValue;
Perform(CM_SYSFONTCHANGED, 0, 0);
end;
end;
{------------------------------------------------------------------------------
TControl SetAlign
------------------------------------------------------------------------------}
procedure TControl.SetAlign(Value: TAlign);
var
OldAlign: TAlign;
a: TAnchorKind;
OldBaseBounds: TRect;
begin
if FAlign = Value then exit;
//DebugLn(['TControl.SetAlign ',DbgSName(Self),' Old=',DbgS(FAlign),' New=',DbgS(Value),' ',Anchors<>AnchorAlign[FAlign]]);
DisableAutoSizing{$IFDEF DebugDisableAutoSizing}('TControl.SetAlign'){$ENDIF};
try
OldBaseBounds:=BaseBounds;
OldAlign := FAlign;
FAlign := Value;
if (not (csLoading in ComponentState))
and (Align in [alLeft,alTop,alRight,alBottom,alClient]) then begin
// Align for alLeft,alTop,alRight,alBottom,alClient takes precedence
// over AnchorSides => clean up
for a:=low(TAnchorKind) to High(TAnchorKind) do
begin
if not (a in AnchorAlign[FAlign]) then continue;
AnchorSide[a].Control:=nil;
AnchorSide[a].Side:=asrTop;
end;
end;
// Notes:
// - if anchors had default values then change them to new default values
// This is done for Delphi compatibility.
// - Anchors are not stored if they are AnchorAlign[Align]
if (Anchors = AnchorAlign[OldAlign]) and (Anchors <> AnchorAlign[FAlign]) then
Anchors := AnchorAlign[FAlign];
if not (csLoading in ComponentState) then
BoundsRect:=OldBaseBounds;
//DebugLn(['TControl.SetAlign ',DbgSName(Self),' Cur=',DbgS(FAlign),' New=',DbgS(Value),' ',Anchors<>AnchorAlign[FAlign],' Anchors=',dbgs(Anchors)]);
finally
EnableAutoSizing{$IFDEF DebugDisableAutoSizing}('TControl.SetAlign'){$ENDIF};
end;
end;
{------------------------------------------------------------------------------
TControl SetAnchors
------------------------------------------------------------------------------}
procedure TControl.SetAnchors(const AValue: TAnchors);
var
NewAnchors: TAnchors;
a: TAnchorKind;
begin
if Anchors = AValue then Exit;
NewAnchors:=AValue-FAnchors;
FAnchors := AValue;
for a:=Low(TAnchorKind) to high(TAnchorKind) do
if (a in NewAnchors) and (AnchorSide[a].Side=asrCenter) then
AnchorSide[a].FixCenterAnchoring;
// Delphi Anchors depend on the current bounds of Self and Parent.ClientRect
// => fetch current BaseBounds
// for example:
// during disabled autosizing: Width:=100; Anchors:=Anchors+[akRight];
UpdateAnchorRules;
AdjustSize;
end;
{------------------------------------------------------------------------------
TControl RequestAlign
Requests the parent to realign all brothers
------------------------------------------------------------------------------}
procedure TControl.RequestAlign;
begin
AdjustSize;
end;
procedure TControl.UpdateBaseBounds(StoreBounds, StoreParentClientSize, UseLoadedValues: Boolean);
var
NewBaseBounds: TRect;
NewBaseParentClientSize: TSize;
begin
if (csLoading in ComponentState) or (fBaseBoundsLock>0) then exit;
if StoreBounds then
NewBaseBounds:=BoundsRect
else
NewBaseBounds:=FBaseBounds;
if StoreParentClientSize then begin
if Parent<>nil then begin
NewBaseParentClientSize:=Size(Parent.ClientWidth,Parent.ClientHeight);
if UseLoadedValues then begin
if cfClientWidthLoaded in Parent.FControlFlags then
NewBaseParentClientSize.cx:=Parent.FLoadedClientSize.cx;
if cfClientHeightLoaded in Parent.FControlFlags then
NewBaseParentClientSize.cy:=Parent.FLoadedClientSize.cy;
end;
end else
NewBaseParentClientSize:=Size(0,0);
end else
NewBaseParentClientSize:=FBaseParentClientSize;
if (not SameRect(@NewBaseBounds,@FBaseBounds))
or (NewBaseParentClientSize.cx<>FBaseParentClientSize.cx)
or (NewBaseParentClientSize.cy<>FBaseParentClientSize.cy)
then begin
//if csDesigning in ComponentState then
{$IFDEF CHECK_POSITION}
if CheckPosition(Self) then
DebugLn(['TControl.UpdateBaseBounds '+DbgSName(Self),
' OldBounds='+dbgs(FBaseBounds),
' OldParentClientSize='+dbgs(FBaseParentClientSize),
' NewBounds='+dbgs(NewBaseBounds),
' NewParentClientSize='+dbgs(NewBaseParentClientSize),
'']);
{$ENDIF}
FBaseBounds:=NewBaseBounds;
FBaseParentClientSize:=NewBaseParentClientSize;
end;
Include(FControlFlags,cfBaseBoundsValid);
end;
procedure TControl.WriteLayoutDebugReport(const Prefix: string);
var
a: TAnchorKind;
NeedSeparator: Boolean;
begin
DbgOut(Prefix,'TControl.WriteLayoutDebugReport ');
DbgOut(DbgSName(Self),' Bounds=',dbgs(BoundsRect));
if Align<>alNone then
DbgOut(' Align=',DbgS(Align));
DbgOut(' Anchors=[');
NeedSeparator:=false;
for a:=Low(TAnchorKind) to High(TAnchorKind) do begin
if a in Anchors then begin
if NeedSeparator then DbgOut(',');
DbgOut(dbgs(a));
if AnchorSide[a].Control<>nil then begin
DbgOut('(',DbgSName(AnchorSide[a].Control),')');
end;
NeedSeparator:=true;
end;
end;
DbgOut(']');
DebugLn;
end;
procedure TControl.AutoAdjustLayout(AMode: TLayoutAdjustmentPolicy;
const AFromPPI, AToPPI, AOldFormWidth, ANewFormWidth: Integer);
var
lXProportion, lYProportion: Double;
lMode: TLayoutAdjustmentPolicy;
savedParentFont: Boolean;
begin
// First resolve ladDefault
lMode := AMode;
if lMode = lapDefault then lMode := Application.LayoutAdjustmentPolicy;
// X-axis adjustment proportion
lXProportion := 1.0;
if lMode = lapAutoAdjustWithoutHorizontalScrolling then
begin
if AOldFormWidth > 0 then lXProportion := ANewFormWidth / AOldFormWidth;
end
else if lMode = lapAutoAdjustForDPI then
begin
if AFromPPI > 0 then lXProportion := AToPPI / AFromPPI;
end;
// y-axis adjustment proportion
if AFromPPI > 0 then lYProportion := AToPPI / AFromPPI
else lYProportion := 1.0;
DisableAutoSizing{$IFDEF DebugDisableAutoSizing}('TControl.AutoAdjustLayout'){$ENDIF};
savedParentFont := ParentFont;
try
if AMode in [lapAutoAdjustWithoutHorizontalScrolling, lapAutoAdjustForDPI] then
ScaleFontsPPI(AToPPI, lYProportion);
DoAutoAdjustLayout(lMode, lXProportion, lYProportion);
finally
ParentFont := savedParentFont;
EnableAutoSizing{$IFDEF DebugDisableAutoSizing}('TControl.AutoAdjustLayout'){$ENDIF};
end;
end;
// Auto-adjust the layout of controls.
procedure TControl.ShouldAutoAdjust(var AWidth, AHeight: Boolean);
begin
AWidth := not AutoSize;
AHeight := not AutoSize;
end;
procedure TControl.UpdateAnchorRules;
begin
UpdateBaseBounds(true,true,false);
end;
{------------------------------------------------------------------------------
TControl SetDragmode
------------------------------------------------------------------------------}
procedure TControl.SetDragMode(Value: TDragMode);
begin
if FDragMode = Value then exit;
FDragMode := Value;
end;
function TControl.GetDefaultDockCaption: string;
begin
Result := Caption;
end;
{------------------------------------------------------------------------------
TControl DockTrackNoTarget
------------------------------------------------------------------------------}
procedure TControl.DockTrackNoTarget(Source: TDragDockObject; X, Y: Integer);
begin
PositionDockRect(Source);
end;
{------------------------------------------------------------------------------
TControl SetLeft
------------------------------------------------------------------------------}
procedure TControl.SetLeft(Value: Integer);
begin
{$IFDEF CHECK_POSITION}
if CheckPosition(Self) then
DebugLn('[TControl.SetLeft] ',Name,':',ClassName,' ',DbgS(Value));
{$ENDIF}
if csLoading in ComponentState then
begin
inc(FReadBounds.Right, Value - FReadBounds.Left);
FReadBounds.Left := Value;
Include(FControlFlags, cfLeftLoaded);
end;
SetBounds(Value, FTop, FWidth, FHeight);
end;
{------------------------------------------------------------------------------
TControl SetTop
------------------------------------------------------------------------------}
procedure TControl.SetTop(Value: Integer);
begin
{$IFDEF CHECK_POSITION}
if CheckPosition(Self) then
DebugLn('[TControl.SetTop] ',Name,':',ClassName,' ',Dbgs(Value));
{$ENDIF}
if csLoading in ComponentState then
begin
inc(FReadBounds.Bottom,Value - FReadBounds.Top);
FReadBounds.Top := Value;
Include(FControlFlags, cfTopLoaded);
end;
SetBounds(FLeft, Value, FWidth, FHeight);
end;
{------------------------------------------------------------------------------
TControl SetWidth
------------------------------------------------------------------------------}
procedure TControl.SetWidth(Value: Integer);
procedure CheckDesignBounds;
begin
// the user changed the width
if Value<0 then
raise ELayoutException.CreateFmt('TWinControl.SetBounds (%s): Negative width %d not allowed.',
[DbgSName(Self), Value]);
if Value>=10000 then
raise ELayoutException.CreateFmt('TWinControl.SetBounds (%s): Width %d not allowed.',
[DbgSName(Self), Value]);
end;
begin
{$IFDEF CHECK_POSITION}
if CheckPosition(Self) then
DebugLn('[TControl.SetWidth] ',Name,':',ClassName,' ',dbgs(Value));
{$ENDIF}
if csLoading in ComponentState then
begin
FReadBounds.Right := FReadBounds.Left+Value;
Include(FControlFlags, cfWidthLoaded);
end;
if [csDesigning, csDestroying, csLoading] * ComponentState = [csDesigning] then
CheckDesignBounds;
SetBounds(FLeft, FTop, Max(0, Value), FHeight);
end;
class procedure TControl.WSRegisterClass;
const
Registered : boolean = False;
begin
if Registered then
Exit;
inherited WSRegisterClass;
RegisterControl;
RegisterPropertyToSkip(TControl, 'AlignWithMargins', 'VCL compatibility property', '');
RegisterPropertyToSkip(TControl, 'Ctl3D', 'VCL compatibility property', '');
RegisterPropertyToSkip(TControl, 'ParentCtl3D', 'VCL compatibility property', '');
RegisterPropertyToSkip(TControl, 'IsControl', 'VCL compatibility property', '');
RegisterPropertyToSkip(TControl, 'DesignSize', 'VCL compatibility property', '');
RegisterPropertyToSkip(TControl, 'ExplicitLeft', 'VCL compatibility property', '');
RegisterPropertyToSkip(TControl, 'ExplicitHeight', 'VCL compatibility property', '');
RegisterPropertyToSkip(TControl, 'ExplicitTop', 'VCL compatibility property', '');
RegisterPropertyToSkip(TControl, 'ExplicitWidth', 'VCL compatibility property', '');
Registered := True;
end;
function TControl.GetCursor: TCursor;
begin
Result := FCursor;
end;
{------------------------------------------------------------------------------
TControl SetHeight
------------------------------------------------------------------------------}
procedure TControl.SetHeight(Value: Integer);
procedure CheckDesignBounds;
begin
// the user changed the height
if Value<0 then
raise ELayoutException.CreateFmt('TWinControl.SetHeight (%s): Negative height %d not allowed.',
[DbgSName(Self), Value]);
if Value>=10000 then
raise ELayoutException.CreateFmt('TWinControl.SetBounds (%s): Height %d not allowed.',
[DbgSName(Self), Value]);
end;
begin
{$IFDEF CHECK_POSITION}
if CheckPosition(Self) then
DebugLn('[TControl.SetHeight] ',Name,':',ClassName,' ',dbgs(Value));
{$ENDIF}
if csLoading in ComponentState then
begin
FReadBounds.Bottom := FReadBounds.Top + Value;
Include(FControlFlags, cfHeightLoaded);
end;
if [csDesigning, csDestroying, csLoading] * ComponentState = [csDesigning] then
CheckDesignBounds;
SetBounds(FLeft, FTop, FWidth, Max(0, Value));
end;
{------------------------------------------------------------------------------
procedure TControl.SetHelpContext(const AValue: THelpContext);
------------------------------------------------------------------------------}
procedure TControl.SetHelpContext(const AValue: THelpContext);
begin
if FHelpContext=AValue then exit;
if not (csLoading in ComponentState) then
FHelpType := htContext;
FHelpContext:=AValue;
end;
{------------------------------------------------------------------------------
procedure TControl.SetHelpKeyword(const AValue: String);
------------------------------------------------------------------------------}
procedure TControl.SetHelpKeyword(const AValue: string);
begin
if FHelpKeyword=AValue then exit;
if not (csLoading in ComponentState) then
FHelpType := htKeyword;
FHelpKeyword:=AValue;
end;
procedure TControl.SetHostDockSite(const AValue: TWinControl);
begin
if AValue=FHostDockSite then exit;
Dock(AValue, BoundsRect);
end;
{------------------------------------------------------------------------------
procedure TControl.SetParent(NewParent : TWinControl);
------------------------------------------------------------------------------}
procedure TControl.SetParent(NewParent: TWinControl);
begin
if FParent = NewParent then exit;
DisableAutoSizing{$IFDEF DebugDisableAutoSizing}('TControl.SetParent'){$ENDIF};
try
CheckNewParent(NewParent);
if FParent <> nil then FParent.RemoveControl(Self);
if cfBoundsRectForNewParentValid in FControlFlags then
begin
Exclude(FControlFlags, cfBoundsRectForNewParentValid);
BoundsRect := BoundsRectForNewParent;
end;
if NewParent <> nil then NewParent.InsertControl(Self);
finally
EnableAutoSizing{$IFDEF DebugDisableAutoSizing}('TControl.SetParent'){$ENDIF};
end;
end;
procedure TControl.SetParentBackground(const AParentBackground: Boolean);
begin
if ParentBackground = AParentBackground then
Exit;
if AParentBackground then
ControlStyle := ControlStyle + [csParentBackground]
else
ControlStyle := ControlStyle - [csParentBackground];
Invalidate;
end;
{------------------------------------------------------------------------------
TControl SetParentComponent
------------------------------------------------------------------------------}
procedure TControl.SetParentComponent(NewParentComponent: TComponent);
begin
if (NewParentComponent is TWinControl) then
SetParent(TWinControl(NewParentComponent));
end;
{------------------------------------------------------------------------------
procedure TControl.SetParentColor(Value : Boolean);
------------------------------------------------------------------------------}
procedure TControl.SetParentColor(Value : Boolean);
begin
if FParentColor <> Value then
begin
FParentColor := Value;
if Assigned(FParent) and not (csReading in ComponentState) then
Perform(CM_PARENTCOLORCHANGED, 0, 0);
end;
end;
procedure TControl.SetParentFont(Value: Boolean);
begin
if FParentFont <> Value then
begin
FParentFont := Value;
if Assigned(FParent) and not (csReading in ComponentState) then
Perform(CM_PARENTFONTCHANGED, 0, 0);
end;
end;
{------------------------------------------------------------------------------
TControl SetParentShowHint
------------------------------------------------------------------------------}
procedure TControl.SetParentShowHint(Value : Boolean);
begin
if FParentShowHint <> Value then
begin
FParentShowHint := Value;
if Assigned(FParent) and not (csReading in ComponentState) then
Perform(CM_PARENTSHOWHINTCHANGED, 0, 0);
end;
end;
{------------------------------------------------------------------------------
TControl SetPopupMenu
------------------------------------------------------------------------------}
procedure TControl.SetPopupMenu(Value: TPopupMenu);
begin
FPopupMenu := Value;
if FPopupMenu <> nil then
FPopupMenu.FreeNotification(Self);
end;
{------------------------------------------------------------------------------
TControl WMMouseMove
------------------------------------------------------------------------------}
procedure TControl.WMMouseMove(var Message: TLMMouseMove);
var
MP: TPoint;
begin
{$IFDEF VerboseMouseBugfix}
DebugLn(['[TControl.WMMouseMove] ',Name,':',ClassName,' ',Message.XPos,',',Message.YPos]);
{$ENDIF}
MP := GetMousePosFromMessage(Message.Pos);
UpdateMouseCursor(MP.X,MP.Y);
if not (csNoStdEvents in ControlStyle) then
MouseMove(KeystoShiftState(Word(Message.Keys)), MP.X, MP.Y);
end;
{------------------------------------------------------------------------------
TControl MouseDown
------------------------------------------------------------------------------}
procedure TControl.MouseDown(Button: TMouseButton; Shift: TShiftState;
X, Y: Integer);
var
P: TPoint;
Form: TCustomForm;
begin
if (not (Self is TWinControl)) or (not TWinControl(Self).CanFocus) then
begin
Form := GetParentForm(Self);
if (Form <> nil) and (Form.ActiveControl <> nil) then
Form.ActiveControl.EditingDone;
end;
if (Button in [mbLeft, mbRight]) and DragManager.IsDragging then
begin
P := ClientToScreen(Point(X,Y));
DragManager.MouseDown(Button, Shift, P.X, P.Y);
end;
if Assigned(FOnMouseDown) then FOnMouseDown(Self, Button, Shift, X,Y);
end;
{------------------------------------------------------------------------------
TControl MouseMove
------------------------------------------------------------------------------}
procedure TControl.MouseMove(Shift: TShiftState; X, Y: Integer);
var
P: TPoint;
begin
if DragManager.IsDragging then
begin
P := ClientToScreen(Point(X, Y));
DragManager.MouseMove(Shift, P.X, P.Y);
end;
if Assigned(FOnMouseMove) then FOnMouseMove(Self, Shift, X, Y);
end;
{------------------------------------------------------------------------------
TControl MouseUp
------------------------------------------------------------------------------}
procedure TControl.MouseUp(Button: TMouseButton; Shift:TShiftState;
X, Y: Integer);
begin
if Assigned(FOnMouseUp) then FOnMouseUp(Self, Button, Shift, X,Y);
end;
procedure TControl.MouseEnter;
begin
//DebugLn('TControl.MouseEnter ',Name,':',ClassName,' ',Assigned(FOnMouseEnter));
if Assigned(FOnMouseEnter) then FOnMouseEnter(Self);
end;
procedure TControl.MouseLeave;
begin
//DebugLn('TControl.MouseLeave ',Name,':',ClassName,' ',Assigned(FOnMouseLeave));
if Assigned(FOnMouseLeave) then FOnMouseLeave(Self);
end;
{------------------------------------------------------------------------------
procedure TControl.CaptureChanged;
------------------------------------------------------------------------------}
procedure TControl.CaptureChanged;
begin
if DragManager.IsDragging then
DragManager.CaptureChanged(Self);
end;
{------------------------------------------------------------------------------
TControl SetShowHint
------------------------------------------------------------------------------}
procedure TControl.SetShowHint(Value : Boolean);
begin
if FShowHint <> Value then
begin
FShowHint := Value;
FParentShowHint := False;
Perform(CM_SHOWHINTCHANGED, 0, 0);
end;
end;
{------------------------------------------------------------------------------
TControl SetVisible
------------------------------------------------------------------------------}
procedure TControl.SetVisible(Value : Boolean);
var
AsWincontrol: TWinControl;
begin
if FVisible <> Value then
begin
//DebugLn(['TControl.SetVisible ',DbgSName(Self),' NewVisible=',Value]);
DisableAutoSizing{$IFDEF DebugDisableAutoSizing}('TControl.SetVisible'){$ENDIF};
try
VisibleChanging;
FVisible := Value;
try
// create/destroy handle
Perform(CM_VISIBLECHANGED, WParam(Ord(Value)), 0);// see TWinControl.CMVisibleChanged
if (Self is TWinControl) then
AsWincontrol := TWinControl(Self)
else
AsWincontrol := nil;
InvalidatePreferredSize;
if Assigned(AsWincontrol) then
AsWincontrol.InvalidatePreferredChildSizes;
AdjustSize;
if (not Visible) and Assigned(Parent) then
begin
// control became invisible, so AdjustSize was not propagated to Parent
// => propagate now
Parent.InvalidatePreferredSize;
Parent.AdjustSize;
end;
finally
VisibleChanged;
end;
finally
EnableAutoSizing{$IFDEF DebugDisableAutoSizing}('TControl.SetVisible'){$ENDIF};
end;
end;
if (csLoading in ComponentState) then
ControlState := ControlState + [csVisibleSetInLoading];
end;
procedure TControl.DoOnParentHandleDestruction;
begin
// nothing, implement in descendats
end;
{------------------------------------------------------------------------------
TControl.SetZOrder
------------------------------------------------------------------------------}
procedure TControl.SetZOrder(TopMost: Boolean);
const
POSITION: array[Boolean] of Integer = (0, MaxInt);
begin
if FParent = nil then exit;
FParent.SetChildZPosition(Self, POSITION[TopMost]);
end;
{------------------------------------------------------------------------------
function TControl.HandleObjectShouldBeVisible
------------------------------------------------------------------------------}
function TControl.HandleObjectShouldBeVisible: Boolean;
begin
Result := not ((csDestroying in ComponentState) or (csDestroyingHandle in FControlState)) and IsControlVisible;
if Result and Assigned(Parent) then
Result := Parent.HandleObjectShouldBeVisible;
//DebugLn(['TControl.HandleObjectShouldBeVisible ',DbgSName(Self),' ',Result]);
end;
{------------------------------------------------------------------------------
procedure TControl Hide
------------------------------------------------------------------------------}
procedure TControl.Hide;
begin
Visible := False;
end;
{------------------------------------------------------------------------------
function TControl.ParentDestroyingHandle: boolean;
Returns whether any parent is destroying it's handle (and its children's)
------------------------------------------------------------------------------}
function TControl.ParentDestroyingHandle: Boolean;
var
CurControl: TControl;
begin
Result:=true;
CurControl:=Self;
while CurControl<>nil do begin
if csDestroyingHandle in CurControl.ControlState then
exit;
CurControl:=CurControl.Parent;
end;
Result:=false;
end;
{------------------------------------------------------------------------------
function TControl.ParentHandlesAllocated: boolean;
------------------------------------------------------------------------------}
function TControl.ParentHandlesAllocated: Boolean;
begin
Result:=(Parent<>nil) and (Parent.ParentHandlesAllocated);
end;
{------------------------------------------------------------------------------
procedure TControl.InitiateAction;
------------------------------------------------------------------------------}
procedure TControl.InitiateAction;
begin
if ActionLink <> nil then ActionLink.Update;
end;
procedure TControl.ShowHelp;
begin
{$IFDEF VerboseLCLHelp}
debugln(['TControl.ShowHelp ',DbgSName(Self)]);
{$ENDIF}
if HelpType = htContext then
begin
if HelpContext <> 0 then
begin
Application.HelpContext(HelpContext);
Exit;
end;
end
else
begin
if HelpKeyword <> '' then
begin
Application.HelpKeyword(HelpKeyword);
Exit;
end;
end;
if Parent <> nil then
Parent.ShowHelp;
end;
function TControl.HasHelp: Boolean;
begin
if HelpType = htContext then
Result := HelpContext <> 0
else
Result := HelpKeyword <> '';
end;
{------------------------------------------------------------------------------
procedure TControl.Dock(NewDockSite: TWinControl; ARect: TRect);
Docks this control into NewDockSite at ARect.
------------------------------------------------------------------------------}
procedure TControl.Dock(NewDockSite: TWinControl; ARect: TRect);
procedure RaiseAlreadyDocking;
begin
RaiseGDBException('TControl.Dock '+Name+':'+ClassName+' csDocking in FControlState');
end;
var
OldHostDockSite: TWinControl;
begin
if (csDocking in FControlState) then
RaiseAlreadyDocking;
// dock
DisableAutoSizing{$IFDEF DebugDisableAutoSizing}('TControl.Dock'){$ENDIF};
Include(FControlState, csDocking);
try
OldHostDockSite:=HostDockSite;
if OldHostDockSite<>NewDockSite then begin
// HostDockSite will change -> prepare
if (OldHostDockSite<>nil) and (OldHostDockSite.FDockClients<>nil) then
OldHostDockSite.FDockClients.Remove(Self);
if (NewDockSite<>nil) and (NewDockSite.FDockClients<>nil) then
NewDockSite.FDockClients.Add(Self);
end;
//debugln(['TControl.Dock A ',DbgSName(Self),' NewDockSite=',DbgSName(NewDockSite),' ',NewDockSite.Visible]);
DoDock(NewDockSite,ARect);
if FHostDockSite<>NewDockSite then
begin
// HostDockSite has changed -> commit
OldHostDockSite := FHostDockSite;
FHostDockSite := NewDockSite;
if NewDockSite<>nil then NewDockSite.DoAddDockClient(Self,ARect);
if OldHostDockSite<>nil then OldHostDockSite.DoRemoveDockClient(Self);
end;
finally
if (FHostDockSite<>NewDockSite)
and (NewDockSite<>nil) and (NewDockSite.FDockClients<>nil) then
NewDockSite.FDockClients.Remove(Self);
Exclude(FControlState, csDocking);
end;
EnableAutoSizing{$IFDEF DebugDisableAutoSizing}('TControl.Dock'){$ENDIF};
//DebugLn(['TControl.Dock END ',DbgSName(Self),' ',DbgSName(HostDockSite)]);
end;
{------------------------------------------------------------------------------
function TControl.ManualDock(NewDockSite: TWinControl; DropControl: TControl;
ControlSide: TAlign): Boolean;
Docks this control to DropControl or on NewDockSite.
If DropControl is not nil, ControlSide defines on which side of DropControl
this control is docked. (alNone,alClient for stacked in pages). DropControl
will become part of a TDockManager.
If DropControl is nil, then DropControl becomes a normal child of NewDockSite
and ControlSide is ignored.
------------------------------------------------------------------------------}
function TControl.ManualDock(NewDockSite: TWinControl; DropControl: TControl;
ControlSide: TAlign; KeepDockSiteSize: Boolean): Boolean;
var
NewBounds: TRect;
DockObject: TDragDockObject;
NewPosition: TPoint;
begin
if DropControl<>nil then
DropControl.DisableAutoSizing{$IFDEF DebugDisableAutoSizing}('TControl.ManualDock DropControl'){$ENDIF};
if NewDockSite<>nil then
NewDockSite.DisableAutoSizing{$IFDEF DebugDisableAutoSizing}('TControl.ManualDock NewDockSite'){$ENDIF};
if (NewDockSite=nil) then begin
// undock / float this control
// float the control at the same screen position
if HostDockSiteManagerAvailable(HostDockSite) then begin
HostDockSite.DockManager.GetControlBounds(Self,NewBounds);
NewBounds.TopLeft:=HostDockSite.ClientToScreen(NewBounds.TopLeft);
end else begin
NewBounds.TopLeft:=ControlOrigin;
end;
NewBounds := Bounds(NewBounds.Left,NewBounds.Top,UndockWidth,UndockHeight);
//DebugLn('TControl.ManualDock ',Name,' NewDockSite=nil HostDockSiteManagerAvailable=',dbgs(HostDockSiteManagerAvailable(HostDockSite)),' NewBounds=',dbgs(NewBounds));
Result := ManualFloat(NewBounds);
end
else
begin
// dock / unfloat this control
CalculateDockSizes;
Result := (HostDockSite=nil);
if not Result then begin
// undock from old HostSite
// - this only undocks from the DockManager
// - this control still uses the DockSite as parent control
// Note: This can *not* be combined with ManualFloat, because that would
// create a new HostDockSite
//DebugLn('TControl.ManualDock UNDOCKING ',Name);
Result:=HostDockSite.DoUndock(NewDockSite,Self);
end;
if Result then begin
//DebugLn('TControl.ManualDock DOCKING ',Name);
// create TDragDockObject for docking parameters
DockObject := TDragDockObject.Create(Self);
try
// get current screen coordinates
NewPosition:=ControlOrigin;
// initialize DockObject
with DockObject do begin
FDragTarget := NewDockSite;
FDropAlign := ControlSide;
FDropOnControl := DropControl;
FIncreaseDockArea := not KeepDockSiteSize;
DockRect := Bounds(NewPosition.X,NewPosition.Y,Width,Height);
end;
// map from screen coordinates to new HostSite coordinates
NewPosition:=NewDockSite.ScreenToClient(NewPosition);
// DockDrop
//DebugLn('TControl.ManualDock DOCKDROP ',Name,' DockRect=',dbgs(DockObject.DockRect),' NewPos=',dbgs(NewPosition));
NewDockSite.DockDrop(DockObject,NewPosition.X,NewPosition.Y);
finally
DockObject.Free;
end;
end;
end;
if NewDockSite<>nil then
NewDockSite.EnableAutoSizing{$IFDEF DebugDisableAutoSizing}('TControl.ManualDock NewDockSite'){$ENDIF};
if DropControl<>nil then
DropControl.EnableAutoSizing{$IFDEF DebugDisableAutoSizing}('TControl.ManualDock DropControl'){$ENDIF};
end;
{------------------------------------------------------------------------------
function TControl.ManualFloat(TheScreenRect: TRect;
KeepDockSiteSize: Boolean = true): Boolean;
Undock and float.
Float means here: create the floating dock site and dock this control into it.
Exception: Forms do not need float dock sites and float on their own.
------------------------------------------------------------------------------}
function TControl.ManualFloat(TheScreenRect: TRect;
KeepDockSiteSize: Boolean): Boolean;
var
FloatHost: TWinControl;
begin
DebugLn(['TControl.ManualFloat ',DbgSName(Self)]);
DisableAutoSizing{$IFDEF DebugDisableAutoSizing}('TControl.ManualFloat'){$ENDIF};
// undock from old host dock site
if HostDockSite = nil then
begin
Result := True;
if Parent <> nil then
Parent.DoUndockClientMsg(nil, Self);
end
else
begin
Result := HostDockSite.DoUndock(nil, Self, KeepDockSiteSize);
end;
// create new float dock site and dock this control into it.
if Result then
begin
FloatHost := CreateFloatingDockSite(TheScreenRect);
//debugln('TControl.ManualFloat A '+Name,':',ClassName,' ',dbgs(TheScreenRect),' FloatHost=',dbgs(FloatHost<>nil));
if FloatHost <> nil then
begin
// => dock this control into it.
FloatHost.Caption := FloatHost.GetDockCaption(Self);
FloatHost.Visible := True;
Dock(FloatHost,Rect(0, 0, FloatHost.ClientWidth, FloatHost.ClientHeight))
end
else
Dock(nil, TheScreenRect);
end;
EnableAutoSizing{$IFDEF DebugDisableAutoSizing}('TControl.ManualFloat'){$ENDIF};
end;
{------------------------------------------------------------------------------
function TControl.ReplaceDockedControl(Control: TControl;
NewDockSite: TWinControl; DropControl: TControl; ControlSide: TAlign
): Boolean;
------------------------------------------------------------------------------}
function TControl.ReplaceDockedControl(Control: TControl;
NewDockSite: TWinControl; DropControl: TControl; ControlSide: TAlign
): Boolean;
var
OldDockSite: TWinControl;
begin
Result := False;
DisableAutoSizing{$IFDEF DebugDisableAutoSizing}('TControl.ReplaceDockedControl'){$ENDIF};
OldDockSite := Control.HostDockSite;
if (OldDockSite<>nil) and (not HostDockSiteManagerAvailable(OldDockSite)) then
exit;
if OldDockSite <> nil then
OldDockSite.DockManager.SetReplacingControl(Control);
try
ManualDock(OldDockSite,nil,alTop);
finally
if OldDockSite <> nil then
OldDockSite.DockManager.SetReplacingControl(nil);
end;
Result:=Control.ManualDock(NewDockSite,DropControl,ControlSide);
EnableAutoSizing{$IFDEF DebugDisableAutoSizing}('TControl.ReplaceDockedControl'){$ENDIF};
end;
function TControl.Docked: Boolean;
begin
Result := Assigned(Parent) and (Parent = HostDockSite) and (GetParentForm(Parent) <> Parent);
end;
procedure TControl.AddHandlerOnResize(const OnResizeEvent: TNotifyEvent; AsFirst: Boolean);
begin
AddHandler(chtOnResize,TMethod(OnResizeEvent),AsFirst);
end;
procedure TControl.RemoveHandlerOnResize(const OnResizeEvent: TNotifyEvent);
begin
RemoveHandler(chtOnResize,TMethod(OnResizeEvent));
end;
procedure TControl.AddHandlerOnChangeBounds(const OnChangeBoundsEvent: TNotifyEvent; AsFirst: Boolean);
begin
AddHandler(chtOnChangeBounds,TMethod(OnChangeBoundsEvent),AsFirst);
end;
procedure TControl.RemoveHandlerOnChangeBounds(
const OnChangeBoundsEvent: TNotifyEvent);
begin
RemoveHandler(chtOnChangeBounds,TMethod(OnChangeBoundsEvent));
end;
procedure TControl.AddHandlerOnVisibleChanging(const OnVisibleChangingEvent: TNotifyEvent; AsFirst: Boolean);
begin
AddHandler(chtOnVisibleChanging,TMethod(OnVisibleChangingEvent),AsFirst);
end;
procedure TControl.RemoveHandlerOnVisibleChanging(
const OnVisibleChangingEvent: TNotifyEvent);
begin
RemoveHandler(chtOnVisibleChanging,TMethod(OnVisibleChangingEvent));
end;
procedure TControl.AddHandlerOnVisibleChanged(const OnVisibleChangedEvent: TNotifyEvent; AsFirst: Boolean);
begin
AddHandler(chtOnVisibleChanged,TMethod(OnVisibleChangedEvent),AsFirst);
end;
procedure TControl.RemoveHandlerOnVisibleChanged(
const OnVisibleChangedEvent: TNotifyEvent);
begin
RemoveHandler(chtOnVisibleChanged,TMethod(OnVisibleChangedEvent));
end;
procedure TControl.AddHandlerOnEnabledChanging(
const OnEnabledChangingEvent: TNotifyEvent; AsFirst: Boolean);
begin
AddHandler(chtOnEnabledChanging,TMethod(OnEnabledChangingEvent),AsFirst);
end;
procedure TControl.RemoveHandlerOnEnabledChanging(
const OnEnabledChangingEvent: TNotifyEvent);
begin
RemoveHandler(chtOnEnabledChanging,TMethod(OnEnabledChangingEvent));
end;
procedure TControl.AddHandlerOnEnabledChanged(const OnEnabledChangedEvent: TNotifyEvent;
AsFirst: Boolean);
begin
AddHandler(chtOnEnabledChanged,TMethod(OnEnabledChangedEvent),AsFirst);
end;
procedure TControl.RemoveHandlerOnEnabledChanged(
const OnEnabledChangedEvent: TNotifyEvent);
begin
RemoveHandler(chtOnEnabledChanged,TMethod(OnEnabledChangedEvent));
end;
procedure TControl.AddHandlerOnKeyDown(const OnKeyDownEvent: TKeyEvent; AsFirst: Boolean);
begin
AddHandler(chtOnKeyDown,TMethod(OnKeyDownEvent),AsFirst);
end;
procedure TControl.RemoveHandlerOnKeyDown(const OnKeyDownEvent: TKeyEvent);
begin
RemoveHandler(chtOnKeyDown,TMethod(OnKeyDownEvent));
end;
procedure TControl.AddHandlerOnBeforeDestruction(const OnBeforeDestructionEvent: TNotifyEvent; AsFirst: Boolean);
begin
AddHandler(chtOnBeforeDestruction,TMethod(OnBeforeDestructionEvent));
end;
procedure TControl.RemoveHandlerOnBeforeDestruction(
const OnBeforeDestructionEvent: TNotifyEvent);
begin
RemoveHandler(chtOnBeforeDestruction,TMethod(OnBeforeDestructionEvent));
end;
procedure TControl.AddHandlerOnMouseWheel(const OnMouseWheelEvent: TMouseWheelEvent; AsFirst: Boolean);
begin
AddHandler(chtOnMouseWheel,TMethod(OnMouseWheelEvent),AsFirst);
end;
procedure TControl.RemoveHandlerOnMouseWheel(
const OnMouseWheelEvent: TMouseWheelEvent);
begin
RemoveHandler(chtOnMouseWheel,TMethod(OnMouseWheelEvent));
end;
procedure TControl.RemoveAllHandlersOfObject(AnObject: TObject);
var
HandlerType: TControlHandlerType;
begin
inherited RemoveAllHandlersOfObject(AnObject);
for HandlerType:=Low(TControlHandlerType) to High(TControlHandlerType) do
FControlHandlers[HandlerType].RemoveAllMethodsOfObject(AnObject);
end;
{------------------------------------------------------------------------------
Method: TControl.GetTextBuf
Params: None
Returns: Nothing
Copies max bufsize-1 chars to buffer
------------------------------------------------------------------------------}
function TControl.GetTextBuf(Buffer: PChar; BufSize: Integer): Integer;
var
S: string;
begin
if BufSize <= 0 then Exit(0);
S := RealGetText;
if Length(S) >= BufSize
then begin
StrPLCopy(Buffer, S, BufSize - 1);
Result := BufSize - 1;
end
else begin
StrPCopy(Buffer, S);
Result := length(S);
end;
end;
{------------------------------------------------------------------------------
Method: TControl.SetTextBuf
Params: None
Returns: Nothing
------------------------------------------------------------------------------}
procedure TControl.SetTextBuf(Buffer: PChar);
begin
RealSetText(Buffer);
end;
{------------------------------------------------------------------------------
TControl RealSetText
------------------------------------------------------------------------------}
procedure TControl.RealSetText(const Value: TCaption);
begin
if RealGetText = Value then Exit;
FCaption := Value;
Perform(CM_TEXTCHANGED, 0, 0);
end;
procedure TControl.TextChanged;
begin
end;
function TControl.GetCachedText(var CachedText: TCaption): Boolean;
begin
CachedText := FCaption;
Result:= true;
end;
{------------------------------------------------------------------------------
TControl SetText
------------------------------------------------------------------------------}
procedure TControl.SetText(const Value: TCaption);
begin
//if CompareText(Name,'MainForm')=0 then debugln('TControl.SetText A ',DbgSName(Self),' GetText="',GetText,'" Value="',Value,'" FCaption="',FCaption,'"');
if GetText = Value then Exit;
// Check if SetTextBuf is overridden, otherwise
// we can call RealSetText directly
if TMethod(@Self.SetTextBuf).Code = Pointer(@TControl.SetTextBuf)
then begin
RealSetText(Value);
end
else begin
// Bummer, we have to do it the compatible way.
DebugLn('Note: SetTextBuf is overridden for: ', Classname);
SetTextBuf(PChar(Value));
end;
//if CompareText(ClassName,'TMEMO')=0 then
// debugln('TControl.SetText END ',DbgSName(Self),' FCaption="',FCaption,'"');
if HostDockSite <> nil then
HostDockSite.UpdateDockCaption(nil);
end;
{------------------------------------------------------------------------------
TControl Update
------------------------------------------------------------------------------}
procedure TControl.Update;
begin
if Parent<>nil then Parent.Update;
end;
{------------------------------------------------------------------------------
Method: TControl.Destroy
Params: None
Returns: Nothing
Destructor for the class.
------------------------------------------------------------------------------}
destructor TControl.Destroy;
var
HandlerType: TControlHandlerType;
Side: TAnchorKind;
i: Integer;
CurAnchorSide: TAnchorSide;
begin
//DebugLn('[TControl.Destroy] A ',Name,':',ClassName);
// make sure the capture is released
MouseCapture := False;
// explicit notification about component destruction. this can be a drag target
DragManager.Notification(Self, opRemove);
Application.ControlDestroyed(Self);
if (FHostDockSite <> nil) and not (csDestroying in FHostDockSite.ComponentState) then
begin
FHostDockSite.DoUndockClientMsg(nil, Self);
SetParent(nil);
Dock(nil, BoundsRect);
FHostDockSite := nil;
end else
begin
if Assigned(FHostDockSite) and Assigned(FHostDockSite.FDockClients) then
begin
FHostDockSite.FDockClients.Remove(Self);
FHostDockSite := nil;
end;
SetParent(nil);
end;
if FAnchoredControls <> nil then
begin
for i := 0 to FAnchoredControls.Count - 1 do
for Side := Low(TAnchorKind) to High(TAnchorKind) do
begin
CurAnchorSide := AnchoredControls[i].AnchorSide[Side];
if (CurAnchorSide<>nil) and (CurAnchorSide.FControl = Self) then
CurAnchorSide.FControl := nil;
end;
FreeThenNil(FAnchoredControls);
end;
FreeThenNil(FActionLink);
for Side := Low(FAnchorSides) to High(FAnchorSides) do
FreeThenNil(FAnchorSides[Side]);
FreeThenNil(FBorderSpacing);
FreeThenNil(FConstraints);
FreeThenNil(FFont);
FreeThenNil(FAccessibleObject);
//DebugLn('[TControl.Destroy] B ',DbgSName(Self));
inherited Destroy;
//DebugLn('[TControl.Destroy] END ',DbgSName(Self));
for HandlerType := Low(TControlHandlerType) to High(TControlHandlerType) do
FreeThenNil(FControlHandlers[HandlerType]);
{$IFDEF DebugDisableAutoSizing}
FreeAndNil(FAutoSizingLockReasons);
{$ENDIF}
end;
procedure TControl.BeforeDestruction;
begin
inherited BeforeDestruction;
DoCallNotifyHandler(chtOnBeforeDestruction);
end;
{------------------------------------------------------------------------------
Method: TControl.Create
Params: None
Returns: Nothing
Constructor for the class.
------------------------------------------------------------------------------}
constructor TControl.Create(TheOwner: TComponent);
var
Side: TAnchorKind;
begin
DisableAutoSizing{$IFDEF DebugDisableAutoSizing}('TControl.Create'){$ENDIF};
try
//if AnsiCompareText(ClassName,'TSpeedButton')=0 then
// DebugLn('TControl.Create START ',Name,':',ClassName);
inherited Create(TheOwner);
// no csOpaque: delphi compatible, win32 themes notebook depend on it
// csOpaque means entire client area will be drawn
// (most controls are semi-transparent)
FAccessibleObject := CreateAccessibleObject();
FControlStyle := FControlStyle
+[csCaptureMouse, csClickEvents, csSetCaption, csDoubleClicks];
FConstraints:= TSizeConstraints.Create(Self);
FBorderSpacing := CreateControlBorderSpacing;
for Side:=Low(FAnchorSides) to High(FAnchorSides) do
FAnchorSides[Side]:=TAnchorSide.Create(Self,Side);
FBaseBounds.Right := -1;
FAnchors := [akLeft,akTop];
FAlign := alNone;
FCaptureMouseButtons := [mbLeft];
FColor := {$ifdef UseCLDefault}clDefault{$else}clWindow{$endif};
FVisible := True;
FParentBidiMode := True;
FParentColor := True;
FParentFont := True;
FDesktopFont := True;
FParentShowHint := True;
FWindowProc := @WndProc;
FCursor := crDefault;
FFont := TFont.Create;
FFont.OnChange := @FontChanged;
FIsControl := False;
FEnabled := True;
FHelpType := htContext;
FDragCursor := crDrag;
FFloatingDockSiteClass := TCustomDockForm;
//DebugLn('TControl.Create END ',Name,':',ClassName);
finally
EnableAutoSizing{$IFDEF DebugDisableAutoSizing}('TControl.Create'){$ENDIF};
end;
end;
{------------------------------------------------------------------------------
Method: TControl.CreateControlBorderSpacing
Params: None
Returns: ControlBorderSpacing instance
Creates the default ControlBorderSpacing. Allowes descendant controls to overide
this.
------------------------------------------------------------------------------}
function TControl.CreateControlBorderSpacing: TControlBorderSpacing;
begin
Result := TControlBorderSpacing.Create(Self);
end;
{------------------------------------------------------------------------------
Method: TControl.GetDeviceContext
Params: WindowHandle: the windowhandle of this control
Returns: a Devicecontext
Get the devicecontext of the parent Wincontrol for this Control.
------------------------------------------------------------------------------}
function TControl.GetDeviceContext(var WindowHandle: HWND): HDC;
begin
if Parent = nil then
raise EInvalidOperation.CreateFmt(sParentRequired, [Name]);
Result := Parent.GetDeviceContext(WindowHandle);
MoveWindowOrgEx(Result, Left, Top);
IntersectClipRect(Result, 0, 0, Width, Height);
end;
{------------------------------------------------------------------------------
Method: TControl.HasParent
Params:
Returns: True - the item has a parent responsible for streaming
This function will be called during streaming to decide if a component has
to be streamed by it's owner or parent.
------------------------------------------------------------------------------}
function TControl.HasParent : Boolean;
begin
Result := (FParent <> nil);
end;
function TControl.GetParentComponent: TComponent;
begin
Result := Parent;
end;
function TControl.IsParentOf(AControl: TControl): Boolean;
begin
Result := False;
while Assigned(AControl) do
begin
AControl := AControl.Parent;
if Self = AControl then
Exit(True);
end;
end;
function TControl.GetTopParent: TControl;
begin
Result := Self;
while Assigned(Result.Parent) do
Result := Result.Parent;
end;
function TControl.FindSubComponent(AName: string): TComponent;
// Like TComponent.FindComponent but finds also a subcomponent which name is
// separated by a dot. For example 'LabeledEdit1.SubLabel'.
var
i: Integer;
SubName: String;
begin
i := Pos('.', AName);
if i > 0 then begin
SubName := Copy(AName, i+1, Length(AName));
Delete(AName, i, Length(AName));
end
else
SubName := '';
Result := FindComponent(AName);
if Assigned(Result) and (SubName<>'') then
Result := Result.FindComponent(SubName);
end;
{------------------------------------------------------------------------------
Method: TControl.SendToBack
Params: None
Returns: Nothing
Puts a control back in Z-order behind all other controls
------------------------------------------------------------------------------}
procedure TControl.SendToBack;
begin
SetZOrder(false);
end;
{------------------------------------------------------------------------------
procedure TControl.AnchorToNeighbour(Side: TAnchorKind; Space: integer;
Sibling: TControl);
Setup AnchorSide to anchor one side to the side of a neighbour sibling.
For example Right side to Left side, or Top side to Bottom.
------------------------------------------------------------------------------}
procedure TControl.AnchorToNeighbour(Side: TAnchorKind; Space: TSpacingSize;
Sibling: TControl);
begin
if Parent<>nil then Parent.DisableAlign;
try
case Side of
akLeft: BorderSpacing.Left:=Space;
akTop: BorderSpacing.Top:=Space;
akRight: BorderSpacing.Right:=Space;
akBottom: BorderSpacing.Bottom:=Space;
end;
AnchorSide[Side].Side:=DefaultSideForAnchorKind[Side];
AnchorSide[Side].Control:=Sibling;
Anchors:=Anchors+[Side];
finally
if Parent<>nil then Parent.EnableAlign;
end;
end;
procedure TControl.AnchorParallel(Side: TAnchorKind; Space: TSpacingSize;
Sibling: TControl);
begin
if Parent<>nil then Parent.DisableAlign;
try
case Side of
akLeft: BorderSpacing.Left:=Space;
akTop: BorderSpacing.Top:=Space;
akRight: BorderSpacing.Right:=Space;
akBottom: BorderSpacing.Bottom:=Space;
end;
case Side of
akLeft: AnchorSide[Side].Side:=asrLeft;
akTop: AnchorSide[Side].Side:=asrTop;
akRight: AnchorSide[Side].Side:=asrRight;
akBottom: AnchorSide[Side].Side:=asrBottom;
end;
AnchorSide[Side].Control:=Sibling;
Anchors:=Anchors+[Side];
finally
if Parent<>nil then Parent.EnableAlign;
end;
end;
{------------------------------------------------------------------------------
procedure TControl.AnchorHorizontalCenterTo(Sibling: TControl);
Setup AnchorSide to center the control horizontally relative to a sibling.
------------------------------------------------------------------------------}
procedure TControl.AnchorHorizontalCenterTo(Sibling: TControl);
begin
if Parent<>nil then Parent.DisableAlign;
try
AnchorSide[akLeft].Side:=asrCenter;
AnchorSide[akLeft].Control:=Sibling;
Anchors:=Anchors+[akLeft]-[akRight];
finally
if Parent<>nil then Parent.EnableAlign;
end;
end;
{------------------------------------------------------------------------------
procedure TControl.AnchorVerticalCenterTo(Sibling: TControl);
Setup AnchorSide to center the control vertically relative to a sibling.
------------------------------------------------------------------------------}
procedure TControl.AnchorVerticalCenterTo(Sibling: TControl);
begin
if Parent<>nil then Parent.DisableAlign;
try
AnchorSide[akTop].Side:=asrCenter;
AnchorSide[akTop].Control:=Sibling;
Anchors:=Anchors+[akTop]-[akBottom];
finally
if Parent<>nil then Parent.EnableAlign;
end;
end;
procedure TControl.AnchorToCompanion(Side: TAnchorKind; Space: TSpacingSize; Sibling: TControl;
FreeCompositeSide: Boolean);
procedure AnchorCompanionSides(
ResizeSide,// the side of this control, where Sibling is touched and moved
OppositeResizeSide, // opposite of ResizeSide
FixedSide1,// the first non moving side
FixedSide2:// the second non moving side
TAnchorKind);
begin
if not (OppositeAnchor[Side] in Anchors) then
AnchorSide[OppositeResizeSide].Control:=nil;
AnchorToNeighbour(ResizeSide,Space,Sibling);
AnchorParallel(FixedSide1,0,Sibling);
AnchorParallel(FixedSide2,0,Sibling);
end;
var
NewAnchors: TAnchors;
begin
if Parent<>nil then Parent.DisableAlign;
try
// anchor all. Except for the opposite side.
NewAnchors:=[akLeft,akTop,akRight,akBottom];
if FreeCompositeSide or (not (OppositeAnchor[Side] in Anchors)) then
Exclude(NewAnchors,OppositeAnchor[Side]);
Anchors:=NewAnchors;
case Side of
akLeft: AnchorCompanionSides(akLeft,akRight,akTop,akBottom);
akRight: AnchorCompanionSides(akRight,akLeft,akTop,akBottom);
akTop: AnchorCompanionSides(akTop,akBottom,akLeft,akRight);
akBottom: AnchorCompanionSides(akBottom,akTop,akLeft,akRight);
end;
finally
if Parent<>nil then Parent.EnableAlign;
end;
end;
procedure TControl.AnchorSame(Side: TAnchorKind; Sibling: TControl);
begin
if Parent<>nil then Parent.DisableAlign;
try
if Side in Sibling.Anchors then
Anchors:=Anchors+[Side]
else
Anchors:=Anchors-[Side];
AnchorSide[Side].Assign(Sibling.AnchorSide[Side]);
finally
if Parent<>nil then Parent.EnableAlign;
end;
end;
procedure TControl.AnchorAsAlign(TheAlign: TAlign; Space: TSpacingSize);
begin
Parent.DisableAlign;
try
if akLeft in AnchorAlign[TheAlign] then begin
BorderSpacing.Left:=Space;
AnchorSide[akLeft].Side:=asrLeft;
AnchorSide[akLeft].Control:=Parent;
end;
if akTop in AnchorAlign[TheAlign] then begin
BorderSpacing.Top:=Space;
AnchorSide[akTop].Side:=asrTop;
AnchorSide[akTop].Control:=Parent;
end;
if akRight in AnchorAlign[TheAlign] then begin
BorderSpacing.Right:=Space;
AnchorSide[akRight].Side:=asrRight;
AnchorSide[akRight].Control:=Parent;
end;
if akBottom in AnchorAlign[TheAlign] then begin
BorderSpacing.Bottom:=Space;
AnchorSide[akBottom].Side:=asrBottom;
AnchorSide[akBottom].Control:=Parent;
end;
Anchors:=Anchors+AnchorAlign[TheAlign];
finally
Parent.EnableAlign;
end;
end;
procedure TControl.AnchorClient(Space: TSpacingSize);
begin
AnchorAsAlign(alClient,Space);
end;
function TControl.AnchoredControlCount: Integer;
begin
if FAnchoredControls = nil then
Result := 0
else
Result := FAnchoredControls.Count;
end;
procedure TControl.SetInitialBounds(aLeft, aTop, aWidth, aHeight: Integer);
begin
//DebugLn('TControl.SetInitialBounds A ',Name,':',ClassName,' ',aLeft,',',aTop,',',aWidth,',',aHeight);
if (csLoading in ComponentState)
or ((Owner<>nil) and (csLoading in Owner.ComponentState)) then
exit;
//DebugLn('TControl.SetInitialBounds B ',Name,':',ClassName,' ',aLeft,',',aTop,',',aWidth,',',aHeight);
SetBounds(aLeft,aTop,aWidth,aHeight);
end;
procedure TControl.SetBoundsKeepBase(aLeft, aTop, aWidth, aHeight: Integer);
begin
ChangeBounds(aLeft, aTop, aWidth, aHeight, true);
end;
{------------------------------------------------------------------------------
procedure TControl.GetPreferredSize(
var PreferredWidth, PreferredHeight: integer; Raw: boolean;
WithThemeSpace: Boolean);
Returns the default/preferred width and height for a control, which is used
by the LCL autosizing algorithms as default size. Only positive values are
valid. Negative or 0 are treated as undefined and the LCL uses other sizes
instead.
Raw: If not Raw then the values will be adjusted by the constraints and
undefined values will be replaced by GetDefaultWidth/GetDefaultHeight.
WithThemeSpace: If true, adds space for stacking. For example: TRadioButton
has a minimum size. But for stacking multiple TRadioButtons there should be
some space around. This space is theme dependent, so it passed parameter to
the widgetset.
TWinControl overrides this and asks the interface for theme dependent values.
See TWinControl.GetPreferredSize for more information.
------------------------------------------------------------------------------}
procedure TControl.GetPreferredSize(var PreferredWidth, PreferredHeight: Integer; Raw: Boolean;
WithThemeSpace: Boolean);
begin
if WithThemeSpace then begin
if not (cfPreferredSizeValid in FControlFlags) then begin
CalculatePreferredSize(FPreferredWidth,FPreferredHeight,true);
Include(FControlFlags,cfPreferredSizeValid);
end;
PreferredWidth:=FPreferredWidth;
PreferredHeight:=FPreferredHeight;
end else begin
if not (cfPreferredMinSizeValid in FControlFlags) then begin
CalculatePreferredSize(FPreferredMinWidth,FPreferredMinHeight,false);
Include(FControlFlags,cfPreferredMinSizeValid);
end;
PreferredWidth:=FPreferredMinWidth;
PreferredHeight:=FPreferredMinHeight;
end;
if not Raw then begin
// use defaults for undefined preferred size
if (PreferredWidth<0)
or ((PreferredWidth=0) and (not (csAutoSize0x0 in ControlStyle))) then begin
if AutoSize or WidthIsAnchored then
PreferredWidth:=GetDefaultWidth
else
PreferredWidth:=Width;
end;
if (PreferredHeight<0)
or ((PreferredHeight=0) and (not (csAutoSize0x0 in ControlStyle))) then begin
if AutoSize or HeightIsAnchored then
PreferredHeight:=GetDefaultHeight
else
PreferredHeight:=Height;
end;
// apply constraints
PreferredWidth:=Constraints.MinMaxWidth(PreferredWidth);
PreferredHeight:=Constraints.MinMaxHeight(PreferredHeight);
end;
end;
function TControl.GetCanvasScaleFactor: Double;
begin
Result := TWSControlClass(WidgetSetClass).GetCanvasScaleFactor(Self);
end;
{------------------------------------------------------------------------------
function TControl.GetDefaultWidth: integer;
The default width for this control independent of any calculated values
like Width and GetPreferredSize.
------------------------------------------------------------------------------}
function TControl.GetDefaultWidth: Integer;
begin
if WidthIsAnchored then
// if width is anchored the read and base bounds were changed at designtime
Result := Scale96ToFont(GetControlClassDefaultSize.cx)
else if cfBaseBoundsValid in FControlFlags then
Result := FBaseBounds.Right - FBaseBounds.Left
else
if cfWidthLoaded in FControlFlags then
Result := FReadBounds.Right - FReadBounds.Left
else
Result := Scale96ToFont(GetControlClassDefaultSize.cx);
end;
{------------------------------------------------------------------------------
function TControl.GetDefaultHeight: integer;
The default height for this control independent of any calculated values
like Height and GetPreferredSize.
------------------------------------------------------------------------------}
function TControl.GetDefaultHeight: Integer;
begin
if HeightIsAnchored then
// if height is anchored the read and base bounds were changed at designtime
Result := Scale96ToFont(GetControlClassDefaultSize.cy)
else if cfBaseBoundsValid in FControlFlags then
Result := BaseBounds.Bottom - BaseBounds.Top
else
if cfHeightLoaded in FControlFlags then
Result := FReadBounds.Bottom - FReadBounds.Top
else
Result := Scale96ToFont(GetControlClassDefaultSize.cy);
end;
{------------------------------------------------------------------------------
class function TControl.GetControlClassDefaultSize: TPoint;
The default size of this type of controls.
Used by GetDefaultWidth and GetDefaultHeight.
------------------------------------------------------------------------------}
class function TControl.GetControlClassDefaultSize: TSize;
begin
Result.CX := 75;
Result.CY := 50;
end;
{------------------------------------------------------------------------------
procedure TControl.GetSidePosition;
Utility function to retrieve Left,Top,Right and Bottom.
------------------------------------------------------------------------------}
function TControl.GetSidePosition(Side: TAnchorKind): Integer;
begin
case Side of
akLeft: Result := Left;
akTop: Result := Top;
akRight: Result := Left + Width;
akBottom: Result := Top + Height;
end;
end;
{------------------------------------------------------------------------------
procedure TControl.CNPreferredSizeChanged;
Called by the LCL interface, when something changed that effects the result
of the interface values for GetPreferredSize.
------------------------------------------------------------------------------}
procedure TControl.CNPreferredSizeChanged;
begin
InvalidatePreferredSize;
end;
{------------------------------------------------------------------------------
procedure TControl.InvalidatePreferredSize;
Invalidate the cache of the preferred size of this and all parent controls.
------------------------------------------------------------------------------}
procedure TControl.InvalidatePreferredSize;
procedure RaiseLoop;
begin
raise ELayoutException.Create('TControl.InvalidatePreferredSize loop detected '+DbgSName(Self)+' Bounds='+dbgs(BoundsRect));
end;
var
AControl: TControl;
begin
AControl:=Self;
while AControl<>nil do begin
Exclude(AControl.FControlFlags,cfPreferredSizeValid);
Exclude(AControl.FControlFlags,cfPreferredMinSizeValid);
if AControl is TWinControl then
Exclude(TWinControl(AControl).FWinControlFlags,wcfAdjustedLogicalClientRectValid);
if not AControl.IsControlVisible then break;
if (AControl.Parent=nil)
and (cfKillInvalidatePreferredSize in AControl.FControlFlags)
then
RaiseLoop;
AControl:=AControl.Parent;
end;
end;
function TControl.GetAnchorsDependingOnParent(WithNormalAnchors: Boolean
): TAnchors;
var
a: TAnchorKind;
begin
Result:=[];
if Parent=nil then exit;
if (Anchors*[akLeft,akRight]=[]) then begin
// center horizontally
Result:=Result+[akLeft,akRight];
end;
if (Anchors*[akTop,akBottom]=[]) then begin
// center vertically
Result:=Result+[akTop,akBottom];
end;
for a:=Low(TAnchorKind) to High(TAnchorKind) do begin
if (a in (Anchors+AnchorAlign[Align])) then begin
if WithNormalAnchors
or (AnchorSide[a].Control=Parent)
or ((AnchorSide[a].Control=nil) and (a in [akRight,akBottom])) then begin
// side anchored
Include(Result,a);
end;
end;
end;
end;
procedure TControl.DisableAutoSizing
{$IFDEF DebugDisableAutoSizing}(const Reason: string){$ENDIF};
begin
inc(FAutoSizingLockCount);
{$IFDEF DebugDisableAutoSizing}
if FAutoSizingLockReasons=nil then FAutoSizingLockReasons:=TStringList.Create;
FAutoSizingLockReasons.Add(Reason);
{$ENDIF}
//DebugLn([Space(FAutoSizingLockCount*2),'TControl.DisableAutoSizing ',DbgSName(Self),' ',FAutoSizingLockCount]);
if FAutoSizingLockCount=1 then
begin
if Parent<>nil then
begin
//DebugLn([Space(FAutoSizingLockCount*2),'TControl.DisableAutoSizing ',DbgSName(Self),' disable Parent=',DbgSName(Parent)]);
Parent.DisableAutoSizing{$IFDEF DebugDisableAutoSizing}('TControl.DisableAutoSizing'){$ENDIF};
end;
end;
end;
procedure TControl.EnableAutoSizing
{$IFDEF DebugDisableAutoSizing}(const Reason: string){$ENDIF};
{$IFDEF DebugDisableAutoSizing}
procedure CheckReason;
var
i: Integer;
s: String;
begin
i:=FAutoSizingLockReasons.Count-1;
while i>=0 do begin
if FAutoSizingLockReasons[i]=Reason then begin
FAutoSizingLockReasons.Delete(i);
exit;
end;
dec(i);
end;
s:='TControl.EnableAutoSizing '+DbgSName(Self)+' never disabled with reason "'+Reason+'"';
for i:=0 to FAutoSizingLockReasons.Count-1 do
s+=','+LineEnding+'reason['+IntToStr(i)+']="'+FAutoSizingLockReasons[i]+'"';
RaiseGDBException(s);
end;
{$ENDIF}
begin
{$IFDEF DebugDisableAutoSizing}
CheckReason;
{$ENDIF}
if FAutoSizingLockCount<=0 then
raise ELayoutException.CreateFmt('TControl.EnableAutoSizing %s: missing DisableAutoSizing',
[DbgSName(Self)]);
dec(FAutoSizingLockCount);
//DebugLn([Space(FAutoSizingLockCount*2),'TControl.EnableAutoSizing ',DbgSName(Self),' ',FAutoSizingLockCount]);
if (FAutoSizingLockCount=0) then
begin
if (Parent<>nil) then
begin
//DebugLn([Space(FAutoSizingLockCount*2),'TControl.EnableAutoSizing ',DbgSName(Self),' enable Parent ',DbgSName(Parent)]);
Parent.EnableAutoSizing{$IFDEF DebugDisableAutoSizing}('TControl.DisableAutoSizing'){$ENDIF};
end else
DoAllAutoSize;
end;
end;
{$IFDEF DebugDisableAutoSizing}
procedure TControl.WriteAutoSizeReasons(NotIfEmpty: boolean);
begin
if NotIfEmpty and (FAutoSizingLockReasons.Count=0) then exit;
DebugLn(['TControl.WriteAutoSizeReasons ',DbgSName(Self)]);
debugln(FAutoSizingLockReasons.Text);
end;
{$ENDIF}
procedure TControl.EndAutoSizing;
procedure Error;
begin
RaiseGDBException('TControl.EndAutoSizing');
end;
begin
if not FAutoSizingSelf then Error;
FAutoSizingSelf := False;
end;
{------------------------------------------------------------------------------
Method: TControl.WMWindowPosChanged
Params: Msg: The message
Returns: nothing
event handler.
------------------------------------------------------------------------------}
procedure TControl.WMWindowPosChanged(var Message: TLMWindowPosChanged);
begin
// Do not handle this message and leave it to WMSize and WMMove
Message.Result := 0;
end;
{------------------------------------------------------------------------------
Method: TControl.WMSize
Params: Message : TLMSize
Returns: nothing
Event handler for LMSize messages.
Overriden by TWinControl.WMSize.
------------------------------------------------------------------------------}
procedure TControl.WMSize(var Message : TLMSize);
begin
{$IFDEF CHECK_POSITION}
if CheckPosition(Self) then
DebugLn('[TControl.WMSize] Name=',Name,':',ClassName,' Message.Width=',DbgS(Message.Width),' Message.Height=',DbgS(Message.Height),' Width=',DbgS(Width),' Height=',DbgS(Height));
{$ENDIF}
//DebugLn(Format('Trace:[TWinControl.WMSize] %s', [ClassName]));
if Assigned(Parent) then
SetBoundsKeepBase(Left,Top,Message.Width,Message.Height)
else
SetBounds(Left,Top,Message.Width,Message.Height);
end;
{------------------------------------------------------------------------------
Method: TControl.WMMove
Params: Msg: The message
Returns: nothing
event handler.
Message.MoveType=0 is the default, all other values will force a RequestAlign.
------------------------------------------------------------------------------}
procedure TControl.WMMove(var Message: TLMMove);
begin
{$IFDEF CHECK_POSITION}
if CheckPosition(Self) then
DebugLn('[TControl.WMMove] Name=',Name,':',ClassName,' Message.XPos=',DbgS(Message.XPos),' Message.YPos=',DbgS(Message.YPos),' OldLeft=',DbgS(Left),' OldTop=',DbgS(Top));
{$ENDIF}
// Just sync the coordinates
if Assigned(Parent) then
SetBoundsKeepBase(Message.XPos, Message.YPos, Width, Height)
else
SetBounds(Message.XPos, Message.YPos, Width, Height);
end;
{------------------------------------------------------------------------------
Method: TControl.SetBiDiMode
------------------------------------------------------------------------------}
procedure TControl.SetBiDiMode(AValue: TBiDiMode);
begin
if FBiDiMode=AValue then exit;
FBiDiMode:=AValue;
FParentBiDiMode := False;
DisableAutoSizing{$IFDEF DebugDisableAutoSizing}('TControl.SetBiDiMode'){$ENDIF};
try
Perform(CM_BIDIMODECHANGED, 0, 0); // see TWinControl.CMBiDiModeChanged
finally
EnableAutoSizing{$IFDEF DebugDisableAutoSizing}('TControl.SetBiDiMode'){$ENDIF};
end;
end;
{------------------------------------------------------------------------------
Method: TControl.SetParentBiDiMode
------------------------------------------------------------------------------}
procedure TControl.SetParentBiDiMode(AValue: Boolean);
begin
if FParentBiDiMode = AValue then Exit;
FParentBiDiMode := AValue;
if (FParent <> nil) and not (csReading in ComponentState) then
Perform(CM_PARENTBIDIMODECHANGED, 0, 0);
end;
{------------------------------------------------------------------------------
Method: TControl.CMBiDiModeChanged
------------------------------------------------------------------------------}
procedure TControl.CMBiDiModeChanged(var Message: TLMessage);
begin
if (Message.wParam = 0) then
Invalidate;
end;
procedure TControl.CMChanged(var Message: TLMessage);
begin
if FParent<>nil then
FParent.WindowProc(Message);
end;
procedure TControl.CMSysFontChanged(var Message: TLMessage);
begin
if FDesktopFont then
begin
Font := Screen.SystemFont;
FDesktopFont := True;
end;
end;
{------------------------------------------------------------------------------
TControl.CMParentBidiModeChanged
assumes: FParent <> nil
------------------------------------------------------------------------------}
procedure TControl.CMParentBiDiModeChanged(var Message: TLMessage);
begin
if csLoading in ComponentState then exit;
if ParentBidiMode then
begin
BidiMode := FParent.BidiMode;
FParentBiDiMode := True;
end;
end;
{------------------------------------------------------------------------------
TControl.IsBiDiModeStored
------------------------------------------------------------------------------}
function TControl.IsBiDiModeStored: Boolean;
begin
Result := not ParentBidiMode;
end;
{------------------------------------------------------------------------------
TControl.IsRightToLeft
------------------------------------------------------------------------------}
function TControl.IsRightToLeft: Boolean;
begin
Result := UseRightToLeftReading;
end;
{------------------------------------------------------------------------------
TControl.UseRightToLeftAlignment
------------------------------------------------------------------------------}
function TControl.UseRightToLeftAlignment: Boolean;
begin
Result := (BiDiMode = bdRightToLeft);
end;
{------------------------------------------------------------------------------
TControl.UseRightToLeftReading
------------------------------------------------------------------------------}
function TControl.UseRightToLeftReading: Boolean;
begin
Result := (BiDiMode <> bdLeftToRight);
end;
{------------------------------------------------------------------------------
TControl.UseRightToLeftScrollBar
------------------------------------------------------------------------------}
function TControl.UseRightToLeftScrollBar: Boolean;
begin
Result := (BiDiMode in [bdRightToLeft, bdRightToLeftNoAlign]);
end;
{$IFDEF ASSERT_IS_ON}
{$UNDEF ASSERT_IS_ON}
{$C-}
{$ENDIF}
// included by controls.pp
|