1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768 4769 4770 4771 4772 4773 4774 4775 4776 4777 4778 4779 4780 4781 4782 4783 4784 4785 4786 4787 4788 4789 4790 4791 4792 4793 4794 4795 4796 4797 4798 4799 4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 4822 4823 4824 4825 4826 4827 4828 4829 4830 4831 4832 4833 4834 4835 4836 4837 4838 4839 4840 4841 4842 4843 4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 4854 4855 4856 4857 4858 4859 4860 4861 4862 4863 4864 4865 4866 4867 4868 4869 4870 4871 4872 4873 4874 4875 4876 4877 4878 4879 4880 4881 4882 4883 4884 4885 4886 4887 4888 4889 4890 4891 4892 4893 4894 4895 4896 4897 4898 4899 4900 4901 4902 4903 4904 4905 4906 4907 4908 4909 4910 4911 4912 4913 4914 4915 4916 4917 4918 4919 4920 4921 4922 4923 4924 4925 4926 4927 4928 4929 4930 4931 4932 4933 4934 4935 4936 4937 4938 4939 4940 4941 4942 4943 4944 4945 4946 4947 4948 4949 4950 4951 4952 4953 4954 4955 4956 4957 4958 4959 4960 4961 4962 4963 4964 4965 4966 4967 4968 4969 4970 4971 4972 4973 4974 4975 4976 4977 4978 4979 4980 4981 4982 4983 4984 4985 4986 4987 4988 4989 4990 4991 4992 4993 4994 4995 4996 4997 4998 4999 5000 5001 5002 5003 5004 5005 5006 5007 5008 5009 5010 5011 5012 5013 5014 5015 5016 5017 5018 5019 5020 5021 5022 5023 5024 5025 5026 5027 5028 5029 5030 5031 5032 5033 5034 5035 5036 5037 5038 5039 5040 5041 5042 5043 5044 5045 5046 5047 5048 5049 5050 5051 5052 5053 5054 5055 5056 5057 5058 5059 5060 5061 5062 5063 5064 5065 5066 5067 5068 5069 5070 5071 5072 5073 5074 5075 5076 5077 5078 5079 5080 5081 5082 5083 5084 5085 5086 5087 5088 5089 5090 5091 5092 5093 5094 5095 5096 5097 5098 5099 5100 5101 5102 5103 5104 5105 5106 5107 5108 5109 5110 5111 5112 5113 5114 5115 5116 5117 5118 5119 5120 5121 5122 5123 5124 5125 5126 5127 5128 5129 5130 5131 5132 5133 5134 5135 5136 5137 5138 5139 5140 5141 5142 5143 5144 5145 5146 5147 5148 5149 5150 5151 5152 5153 5154 5155 5156 5157 5158 5159 5160 5161 5162 5163 5164 5165 5166 5167 5168 5169 5170 5171 5172 5173 5174 5175 5176 5177 5178 5179 5180 5181 5182 5183 5184 5185 5186 5187 5188 5189 5190 5191 5192 5193 5194 5195 5196 5197 5198 5199 5200 5201 5202 5203 5204 5205 5206 5207 5208 5209 5210 5211 5212 5213 5214 5215 5216 5217 5218 5219 5220 5221 5222 5223 5224 5225 5226 5227 5228 5229 5230 5231 5232 5233 5234 5235 5236 5237 5238 5239 5240 5241 5242 5243 5244 5245 5246 5247 5248 5249 5250 5251 5252 5253 5254 5255 5256 5257 5258 5259 5260 5261 5262 5263 5264 5265 5266 5267 5268 5269 5270 5271 5272 5273 5274 5275 5276 5277 5278 5279 5280 5281 5282 5283 5284 5285 5286 5287 5288 5289 5290 5291 5292 5293 5294 5295 5296 5297 5298 5299 5300 5301 5302 5303 5304 5305 5306 5307 5308 5309 5310 5311 5312 5313 5314 5315 5316 5317 5318 5319 5320 5321 5322 5323 5324 5325 5326 5327 5328 5329 5330 5331 5332 5333 5334 5335 5336 5337 5338 5339 5340 5341 5342 5343 5344 5345 5346 5347 5348 5349 5350 5351 5352 5353 5354 5355 5356 5357 5358 5359 5360 5361 5362 5363 5364 5365 5366 5367 5368 5369 5370 5371 5372 5373 5374 5375 5376 5377 5378 5379 5380 5381 5382 5383 5384 5385 5386 5387 5388 5389 5390 5391 5392 5393 5394 5395 5396 5397 5398 5399 5400 5401 5402 5403 5404 5405 5406 5407 5408 5409 5410 5411 5412 5413 5414 5415 5416 5417 5418 5419 5420 5421 5422 5423 5424 5425 5426 5427 5428 5429 5430 5431 5432 5433 5434 5435 5436 5437 5438 5439 5440 5441 5442 5443 5444 5445 5446 5447 5448 5449 5450 5451 5452 5453 5454 5455 5456 5457 5458 5459 5460 5461 5462 5463 5464 5465 5466 5467 5468 5469 5470 5471 5472 5473 5474 5475 5476 5477 5478 5479 5480 5481 5482 5483 5484 5485 5486 5487 5488 5489 5490 5491 5492 5493 5494 5495 5496 5497 5498 5499 5500 5501 5502 5503 5504 5505 5506 5507 5508 5509 5510 5511 5512 5513 5514 5515 5516 5517 5518 5519 5520 5521 5522 5523 5524 5525 5526 5527 5528 5529 5530 5531 5532 5533 5534 5535 5536 5537 5538 5539 5540 5541 5542 5543 5544 5545 5546 5547 5548 5549 5550 5551 5552 5553 5554 5555 5556 5557 5558 5559 5560 5561 5562 5563 5564 5565 5566 5567 5568 5569 5570 5571 5572 5573 5574 5575 5576 5577 5578 5579 5580 5581 5582 5583 5584 5585 5586 5587 5588 5589 5590 5591 5592 5593 5594 5595 5596 5597 5598 5599 5600 5601 5602 5603 5604 5605 5606 5607 5608 5609 5610 5611 5612 5613 5614 5615 5616 5617 5618 5619 5620 5621 5622 5623 5624 5625 5626 5627 5628 5629 5630 5631 5632 5633 5634 5635 5636 5637 5638 5639 5640 5641 5642 5643 5644 5645 5646 5647 5648 5649 5650 5651 5652 5653 5654 5655 5656 5657 5658 5659 5660 5661 5662 5663 5664 5665 5666 5667 5668 5669 5670 5671 5672 5673 5674 5675 5676 5677 5678 5679 5680 5681 5682 5683 5684 5685 5686 5687 5688 5689 5690 5691 5692 5693 5694 5695 5696 5697 5698 5699 5700 5701 5702 5703 5704 5705 5706 5707 5708 5709 5710 5711 5712 5713 5714 5715 5716 5717 5718 5719 5720 5721 5722 5723 5724 5725 5726 5727 5728 5729 5730 5731 5732 5733 5734 5735 5736 5737 5738 5739 5740 5741 5742 5743 5744 5745 5746 5747 5748 5749 5750 5751 5752 5753 5754 5755 5756 5757 5758 5759 5760 5761 5762 5763 5764 5765 5766 5767 5768 5769 5770 5771 5772 5773 5774 5775 5776 5777 5778 5779 5780 5781 5782 5783 5784 5785 5786 5787 5788 5789 5790 5791 5792 5793 5794 5795 5796 5797 5798 5799 5800 5801 5802 5803 5804 5805 5806 5807 5808 5809 5810 5811 5812 5813 5814 5815 5816 5817 5818 5819 5820 5821 5822 5823 5824 5825 5826 5827 5828 5829 5830 5831 5832 5833 5834 5835 5836 5837 5838 5839 5840 5841 5842 5843 5844 5845 5846 5847 5848 5849 5850 5851 5852 5853 5854 5855 5856 5857 5858 5859 5860 5861 5862 5863 5864 5865 5866 5867 5868 5869 5870 5871 5872 5873 5874 5875 5876 5877 5878 5879 5880 5881 5882 5883 5884 5885 5886 5887 5888 5889 5890 5891 5892 5893 5894 5895 5896 5897 5898 5899 5900 5901 5902 5903 5904 5905 5906 5907 5908 5909 5910 5911 5912 5913 5914 5915 5916 5917 5918 5919 5920 5921 5922 5923 5924 5925 5926 5927 5928 5929 5930 5931 5932 5933 5934 5935 5936 5937 5938 5939 5940 5941 5942 5943 5944 5945 5946 5947 5948 5949 5950 5951 5952 5953 5954 5955 5956 5957 5958 5959 5960 5961 5962 5963 5964 5965 5966 5967 5968 5969 5970 5971 5972 5973 5974 5975 5976 5977 5978 5979 5980 5981 5982 5983 5984 5985 5986 5987 5988 5989 5990 5991 5992 5993 5994 5995 5996 5997 5998 5999 6000 6001 6002 6003 6004 6005 6006 6007 6008 6009 6010 6011 6012 6013 6014 6015 6016 6017 6018 6019 6020 6021 6022 6023 6024 6025 6026 6027 6028 6029 6030 6031 6032 6033 6034 6035 6036 6037 6038 6039 6040 6041 6042 6043 6044 6045 6046 6047 6048 6049 6050 6051 6052 6053 6054 6055 6056 6057 6058 6059 6060 6061 6062 6063 6064 6065 6066 6067 6068 6069 6070 6071 6072 6073 6074 6075 6076 6077 6078 6079 6080 6081 6082 6083 6084 6085 6086 6087 6088 6089 6090 6091 6092 6093 6094 6095 6096 6097 6098 6099 6100 6101 6102 6103 6104 6105 6106 6107 6108 6109 6110 6111 6112 6113 6114 6115 6116 6117 6118 6119 6120 6121 6122 6123 6124 6125 6126 6127 6128 6129 6130 6131 6132 6133 6134 6135 6136 6137 6138 6139 6140 6141 6142 6143 6144 6145 6146 6147 6148 6149 6150 6151 6152 6153 6154 6155 6156 6157 6158 6159 6160 6161 6162 6163 6164 6165 6166 6167 6168 6169 6170 6171 6172 6173 6174 6175 6176 6177 6178 6179 6180 6181 6182 6183 6184 6185 6186 6187 6188 6189 6190 6191 6192 6193 6194 6195 6196 6197 6198 6199 6200 6201 6202 6203 6204 6205 6206 6207 6208 6209 6210 6211 6212 6213 6214 6215 6216 6217 6218 6219 6220 6221 6222 6223 6224 6225 6226 6227 6228 6229 6230 6231 6232 6233 6234 6235 6236 6237 6238 6239 6240 6241 6242 6243 6244 6245 6246 6247 6248 6249 6250 6251 6252 6253 6254 6255 6256 6257 6258 6259 6260 6261 6262 6263 6264 6265 6266 6267 6268 6269 6270 6271 6272 6273 6274 6275 6276 6277 6278 6279 6280 6281 6282 6283 6284 6285 6286 6287 6288 6289 6290 6291 6292 6293 6294 6295 6296 6297 6298 6299 6300 6301 6302 6303 6304 6305 6306 6307 6308 6309 6310 6311 6312 6313 6314 6315 6316 6317 6318 6319 6320 6321 6322 6323 6324 6325 6326 6327 6328 6329 6330 6331 6332 6333 6334 6335 6336 6337 6338 6339 6340 6341 6342 6343 6344 6345 6346 6347 6348 6349 6350 6351 6352 6353 6354 6355 6356 6357 6358 6359 6360 6361 6362 6363 6364 6365 6366 6367 6368 6369 6370 6371 6372 6373 6374 6375 6376 6377 6378 6379 6380 6381 6382 6383 6384 6385 6386 6387 6388 6389 6390 6391 6392 6393 6394 6395 6396 6397 6398 6399 6400 6401 6402 6403 6404 6405 6406 6407 6408 6409 6410 6411 6412 6413 6414 6415 6416 6417 6418 6419 6420 6421 6422 6423 6424 6425 6426 6427 6428 6429 6430 6431 6432 6433 6434 6435 6436 6437 6438 6439 6440 6441 6442 6443 6444 6445 6446 6447 6448 6449 6450 6451 6452 6453 6454 6455 6456 6457 6458 6459 6460 6461 6462 6463 6464 6465 6466 6467 6468 6469 6470 6471 6472 6473 6474 6475 6476 6477 6478 6479 6480 6481 6482 6483 6484 6485 6486 6487 6488 6489 6490 6491 6492 6493 6494 6495 6496 6497 6498 6499 6500 6501 6502 6503 6504 6505 6506 6507 6508 6509 6510 6511 6512 6513 6514 6515 6516 6517 6518 6519 6520 6521 6522 6523 6524 6525 6526 6527 6528 6529 6530 6531 6532 6533 6534 6535 6536 6537 6538 6539 6540 6541 6542 6543 6544 6545 6546 6547 6548 6549 6550 6551 6552 6553 6554 6555 6556 6557 6558 6559 6560 6561 6562 6563 6564 6565 6566 6567 6568 6569 6570 6571 6572 6573 6574 6575 6576 6577 6578 6579 6580 6581 6582 6583 6584 6585 6586 6587 6588 6589 6590 6591 6592 6593 6594 6595 6596 6597 6598 6599 6600 6601 6602 6603 6604 6605 6606 6607 6608 6609 6610 6611 6612 6613 6614 6615 6616 6617 6618 6619 6620 6621 6622 6623 6624 6625 6626 6627 6628 6629 6630 6631 6632 6633 6634 6635 6636 6637 6638 6639 6640 6641 6642 6643 6644 6645 6646 6647 6648 6649 6650 6651 6652 6653 6654 6655 6656 6657 6658 6659 6660 6661 6662 6663 6664 6665 6666 6667 6668 6669 6670 6671 6672 6673 6674 6675 6676 6677 6678 6679 6680 6681 6682 6683 6684 6685 6686 6687 6688 6689 6690 6691 6692 6693 6694 6695 6696 6697 6698 6699 6700 6701 6702 6703 6704 6705 6706 6707 6708 6709 6710 6711 6712 6713 6714 6715 6716 6717 6718 6719 6720 6721 6722 6723 6724 6725 6726 6727 6728 6729 6730 6731 6732 6733 6734 6735 6736 6737 6738 6739 6740 6741 6742 6743 6744 6745 6746 6747 6748 6749 6750 6751 6752 6753 6754 6755 6756 6757 6758 6759 6760 6761 6762 6763 6764 6765 6766 6767 6768 6769 6770 6771 6772 6773 6774 6775 6776 6777 6778 6779 6780 6781 6782 6783 6784 6785 6786 6787 6788 6789 6790 6791 6792 6793 6794 6795 6796 6797 6798 6799 6800 6801 6802 6803 6804 6805 6806 6807 6808 6809 6810 6811 6812 6813 6814 6815 6816 6817 6818 6819 6820 6821 6822 6823 6824 6825 6826 6827 6828 6829 6830 6831 6832 6833 6834 6835 6836 6837 6838 6839 6840 6841 6842 6843 6844 6845 6846 6847 6848 6849 6850 6851 6852 6853 6854 6855 6856 6857 6858 6859 6860 6861 6862 6863 6864 6865 6866 6867
|
{ Unit implementing anchor docking.
Copyright (C) 2018 Mattias Gaertner mattias@freepascal.org
This library is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version with the following modification:
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent modules,and
to copy and distribute the resulting executable under terms of your choice,
provided that you also meet, for each linked independent module, the terms
and conditions of the license of that module. An independent module is a
module which is not derived from or based on this library. If you modify
this library, you may extend this exception to your version of the library,
but you are not obligated to do so. If you do not wish to do so, delete this
exception statement from your version.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License
for more details.
You should have received a copy of the GNU Library General Public License
along with this library; if not, write to the Free Software Foundation,
Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1335, USA.
Features:
- dnd docking
- preview rectangle while drag over
- inside and outside docking
- header with close button and hints
- using stock item for close button glyph
- auto header caption from content
- hide header caption for floating form
- auto site for headers to safe space (configurable)
- bidimode for headers
- page docking
- pagecontrols uses TPageControl for native look&feel
- page control is automatically removed if only one page left
- scaling on resize (configurable)
- auto insert splitters between controls (size configurable)
- keep size when docking
- header is automatically hidden when docked into page
- save complete layout
- restore layout:
- close unneeded windows,
- automatic clean up if windows are missing,
- reusing existing docksites to minimize flickering
- popup menu
- close site
- lock/unlock
- header auto, left, top, right, bottom
- undock (needed if no place to undock on screen)
- merge (for example after moving a dock page into a layout)
- enlarge side to left, top, right, bottom
- move page left, right, leftmost, rightmost
- close page
- tab position (default, left, top, right, bottom)
- options
- dock site: MakeDockSite for forms, that should be able to dock other sites,
but should not be docked themselves. Their Parent is always nil.
- design time package for IDE
- dnd move page index
- dnd move page to another pagecontrol
- on close button: save a restore layout
- option to show/hide dock headers
- option HeaderStyle to change appearance of grabbers
ToDo:
- option to save on IDE close (if MainForm is visible on active screen)
- restore: put MainForm on active screen
- restore custom dock site splitter without resizing content, only resize docked site
- undock on hide
- popup menu
- shrink side left, top, right, bottom
- implement a simple way to make forms dockable at designtime without any code
- on show again (hide form, show form): restore layout
- close button for pages
- event for drawing grabbers+headers
- save/restore other splitters
Parent bug with links to all other:
- http://bugs.freepascal.org/view.php?id=18298 default layout sometimes wrong main bar
Other bugs:
- http://bugs.freepascal.org/view.php?id=19810 multi monitor
}
unit AnchorDocking;
{$mode objfpc}{$H+}
{ $DEFINE VerboseAnchorDockRestore}
{ $DEFINE VerboseADCustomSite}
{ $DEFINE VerboseAnchorDockPages}
{ $DEFINE VerboseAnchorDocking}
interface
uses
Math, Classes, SysUtils, types,
LCLType, LCLIntf, LCLProc,
Controls, Forms, ExtCtrls, ComCtrls, Graphics, Themes, Menus, Buttons,
LazConfigStorage, Laz2_XMLCfg, LazFileCache,
AnchorDockStr, AnchorDockStorage, AnchorDockPanel;
{$IFDEF DebugDisableAutoSizing}
const ADAutoSizingReason = 'TAnchorDockMaster Delayed';
{$ENDIF}
type
TAnchorDockHostSite = class;
{ TAnchorDockCloseButton
Close button used in TAnchorDockHeader, uses the close button glyph of the
theme shrinked to a small size. The glyph is shared by all close buttons. }
TAnchorDockCloseButton = class(TCustomSpeedButton)
protected
function GetDrawDetails: TThemedElementDetails; override;
procedure CalculatePreferredSize(var PreferredWidth,
PreferredHeight: integer; {%H-}WithThemeSpace: Boolean); override;
end;
{ TAnchorDockHeader
The panel of a TAnchorDockHostSite containing the close button and the
caption when the form is docked. The header can be shown at any of the four
sides, shows a hint for long captions, starts dragging and shows the popup
menu of the dockmaster.
Hiding and aligning is done by its Parent, which is a TAnchorDockHostSite }
TAnchorDockHeader = class(TCustomPanel)
private
FCloseButton: TCustomSpeedButton;
FHeaderPosition: TADLHeaderPosition;
fFocused:Boolean;
procedure CloseButtonClick(Sender: TObject);
procedure HeaderPositionItemClick(Sender: TObject);
procedure UndockButtonClick(Sender: TObject);
procedure MergeButtonClick(Sender: TObject);
procedure EnlargeSideClick(Sender: TObject);
procedure SetHeaderPosition(const AValue: TADLHeaderPosition);
protected
procedure Paint; override;
procedure CalculatePreferredSize(var PreferredWidth,
PreferredHeight: integer; WithThemeSpace: Boolean); override;
procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X,
Y: Integer); override;
procedure UpdateHeaderControls;
procedure SetAlign(Value: TAlign); override;
procedure DoOnShowHint(HintInfo: PHintInfo); override;
procedure PopupMenuPopup(Sender: TObject); virtual;
public
constructor Create(TheOwner: TComponent); override;
property CloseButton: TCustomSpeedButton read FCloseButton;
property HeaderPosition: TADLHeaderPosition read FHeaderPosition write SetHeaderPosition;
property BevelOuter default bvNone;
end;
TAnchorDockHeaderClass = class of TAnchorDockHeader;
{ TAnchorDockSplitter
A TSplitter used on a TAnchorDockHostSite with SiteType=adhstLayout.
It can store DockBounds, used by its parent to scale. Scaling works by
moving the splitters. All other controls are fully anchored to these
splitters or their parent. }
TAnchorDockSplitter = class(TCustomSplitter)
private
FCustomWidth: Boolean;
FDockBounds: TRect;
FDockParentClientSize: TSize;
FDockRestoreBounds: TRect;
FPercentPosition: Single;
procedure UpdatePercentPosition;
protected
procedure SetResizeAnchor(const AValue: TAnchorKind); override;
procedure PopupMenuPopup(Sender: TObject); virtual;
procedure Paint; override;
public
procedure MoveSplitter(Offset: integer); override;
public
constructor Create(TheOwner: TComponent); override;
property DockBounds: TRect read FDockBounds;
property DockParentClientSize: TSize read FDockParentClientSize;
procedure UpdateDockBounds;
procedure AsyncUpdateDockBounds ({%H-}Data: PtrInt);
procedure SetBounds(ALeft, ATop, AWidth, AHeight: integer); override; // any normal movement sets the DockBounds
procedure SetBoundsPercentually;
procedure SetBoundsKeepDockBounds(ALeft, ATop, AWidth, AHeight: integer); // movement for scaling keeps the DockBounds
function SideAnchoredControlCount(Side: TAnchorKind): integer;
function HasAnchoredControls: boolean;
procedure SaveLayout(LayoutNode: TAnchorDockLayoutTreeNode);
function HasOnlyOneSibling(Side: TAnchorKind; MinPos, MaxPos: integer): TControl;
property DockRestoreBounds: TRect read FDockRestoreBounds write FDockRestoreBounds;
property CustomWidth: Boolean read FCustomWidth write FCustomWidth;
// Increase visibility of TCustomSplitter events:
property OnMouseWheel;
property OnMouseWheelDown;
property OnMouseWheelUp;
end;
TAnchorDockSplitterClass = class of TAnchorDockSplitter;
TAnchorDockPageControl = class;
{ TAnchorDockPage
A page of a TAnchorDockPageControl. }
TAnchorDockPage = class(TCustomPage)
public
procedure UpdateDockCaption(Exclude: TControl = nil); override;
procedure InsertControl(AControl: TControl; Index: integer); override;
procedure RemoveControl(AControl: TControl); override;
function GetSite: TAnchorDockHostSite;
end;
TAnchorDockPageClass = class of TAnchorDockPage;
{ TAnchorDockPageControl
Used for page docking.
The parent is always a TAnchorDockHostSite with SiteType=adhstPages.
Its children are all TAnchorDockPage.
It shows the DockMaster popup menu and starts dragging. }
TAnchorDockPageControl = class(TCustomTabControl)
private
function GetDockPages(Index: integer): TAnchorDockPage;
protected
procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X,Y: Integer); override;
procedure PopupMenuPopup(Sender: TObject); virtual;
procedure CloseButtonClick(Sender: TObject); virtual;
procedure MoveLeftButtonClick(Sender: TObject); virtual;
procedure MoveLeftMostButtonClick(Sender: TObject); virtual;
procedure MoveRightButtonClick(Sender: TObject); virtual;
procedure MoveRightMostButtonClick(Sender: TObject); virtual;
procedure TabPositionClick(Sender: TObject); virtual;
public
constructor Create(TheOwner: TComponent); override;
procedure UpdateDockCaption(Exclude: TControl = nil); override;
property DockPages[Index: integer]: TAnchorDockPage read GetDockPages;
procedure RemoveControl(AControl: TControl); override;
function GetActiveSite: TAnchorDockHostSite;
end;
TAnchorDockPageControlClass = class of TAnchorDockPageControl;
{ TAnchorDockHostSite
This form is the dockhostsite for all controls.
When docked together they build a tree structure with the docked controls
as leaf nodes.
A TAnchorDockHostSite has four modes: TAnchorDockHostSiteType }
TAnchorDockHostSiteType = (
adhstNone, // fresh created, no control docked
adhstOneControl, // a control and the "Header" (TAnchorDockHeader)
adhstLayout, // several controls/TAnchorDockHostSite separated by TAnchorDockSplitters
adhstPages // the "Pages" (TAnchorDockPageControl) with several pages
);
TAnchorDockHostSite = class(TCustomForm)
private
FDockRestoreBounds: TRect;
FHeader: TAnchorDockHeader;
FHeaderSide: TAnchorKind;
FPages: TAnchorDockPageControl;
FSiteType: TAnchorDockHostSiteType;
FBoundSplitter: TAnchorDockSplitter;
fUpdateLayout: integer;
procedure SetHeaderSide(const AValue: TAnchorKind);
protected
procedure DoEnter; override;
procedure DoExit; override;
procedure Notification(AComponent: TComponent; Operation: TOperation); override;
function DoDockClientMsg(DragDockObject: TDragDockObject;
aPosition: TPoint): boolean; override;
function ExecuteDock(NewControl, DropOnControl: TControl; DockAlign: TAlign): boolean; virtual;
function DockFirstControl(NewControl: TControl): boolean; virtual;
function DockSecondControl(NewControl: TControl; DockAlign: TAlign;
Inside: boolean): boolean; virtual;
function DockAnotherControl(Sibling, NewControl: TControl; DockAlign: TAlign;
Inside: boolean): boolean; virtual;
procedure ChildVisibleChanged(Sender: TObject); virtual;
procedure CreatePages; virtual;
procedure FreePages; virtual;
function DockSecondPage(NewControl: TControl): boolean; virtual;
function DockAnotherPage(NewControl: TControl; InFrontOf: TControl): boolean; virtual;
procedure AddCleanControl(AControl: TControl; TheAlign: TAlign = alNone);
procedure RemoveControlFromLayout(AControl: TControl);
procedure RemoveSpiralSplitter(AControl: TControl);
procedure ClearChildControlAnchorSides(AControl: TControl);
procedure Simplify;
procedure SimplifyPages;
procedure SimplifyOneControl;
function GetOneControl: TControl;
function GetSiteCount: integer;
function IsOneSiteLayout(out Site: TAnchorDockHostSite): boolean;
function IsTwoSiteLayout(out Site1, Site2: TAnchorDockHostSite): boolean;
function GetUniqueSplitterName: string;
function MakeSite(AControl: TControl): TAnchorDockHostSite;
procedure MoveAllControls(dx, dy: integer);
procedure AlignControls(AControl: TControl; var ARect: TRect); override;
function CheckIfOneControlHidden: boolean;
procedure DoDock(NewDockSite: TWinControl; var ARect: TRect); override;
procedure SetParent(NewParent: TWinControl); override;
function HeaderNeedsShowing: boolean;
procedure DoClose(var CloseAction: TCloseAction); override;
function CanUndock: boolean;
procedure Undock;
function CanMerge: boolean;
procedure Merge;
function EnlargeSide(Side: TAnchorKind;
OnlyCheckIfPossible: boolean): boolean;
function EnlargeSideResizeTwoSplitters(ShrinkSplitterSide,
EnlargeSpitterSide: TAnchorKind;
OnlyCheckIfPossible: boolean): boolean;
function EnlargeSideRotateSplitter(Side: TAnchorKind;
OnlyCheckIfPossible: boolean): boolean;
procedure CreateBoundSplitter(Disabled: boolean=false);
procedure PositionBoundSplitter;
public
constructor CreateNew(AOwner: TComponent; Num: Integer = 0); override;
destructor Destroy; override;
function CloseQuery: boolean; override;
function CloseSite: boolean; virtual;
procedure RemoveControl(AControl: TControl); override;
procedure InsertControl(AControl: TControl; Index: integer); override;
procedure GetSiteInfo(Client: TControl; var InfluenceRect: TRect;
MousePos: TPoint; var CanDock: Boolean); override;
function GetPageArea: TRect;
procedure ChangeBounds(ALeft, ATop, AWidth, AHeight: integer;
KeepBase: boolean); override;
procedure UpdateDockCaption(Exclude: TControl = nil); override;
procedure UpdateHeaderAlign;
procedure UpdateHeaderShowing;
procedure BeginUpdateLayout;
procedure EndUpdateLayout;
function UpdatingLayout: boolean;
// save/restore layout
procedure SaveLayout(LayoutTree: TAnchorDockLayoutTree;
LayoutNode: TAnchorDockLayoutTreeNode);
property DockRestoreBounds: TRect read FDockRestoreBounds write FDockRestoreBounds;
property HeaderSide: TAnchorKind read FHeaderSide write SetHeaderSide;
property Header: TAnchorDockHeader read FHeader;
property Pages: TAnchorDockPageControl read FPages;
property SiteType: TAnchorDockHostSiteType read FSiteType;
property BoundSplitter: TAnchorDockSplitter read FBoundSplitter;
end;
TAnchorDockHostSiteClass = class of TAnchorDockHostSite;
TADMResizePolicy = (
admrpNone,
admrpChild // resize child
);
{ TAnchorDockManager
A TDockManager is the LCL connector to catch various docking events for a
TControl. Every TAnchorDockHostSite and every custom dock site gets one
TAnchorDockManager. The LCL frees it automatically when the Site is freed. }
TAnchorDockManager = class(TDockManager)
private
FDockableSites: TAnchors;
FDockSite: TAnchorDockHostSite;
FInsideDockingAllowed: boolean;
FPreferredSiteSizeAsSiteMinimum: boolean;
FResizePolicy: TADMResizePolicy;
FStoredConstraints: TRect;
FSite: TWinControl;
FSiteClientRect: TRect;
procedure SetPreferredSiteSizeAsSiteMinimum(const AValue: boolean);
public
constructor Create(ADockSite: TWinControl); override;
procedure GetControlBounds(Control: TControl; out AControlBounds: TRect);
override;
procedure InsertControl(Control: TControl; InsertAt: TAlign;
DropCtl: TControl); override; overload;
procedure InsertControl(ADockObject: TDragDockObject); override; overload;
procedure LoadFromStream(Stream: TStream); override;
procedure PositionDockRect(Client, DropCtl: TControl; DropAlign: TAlign;
var DockRect: TRect); override; overload;
procedure RemoveControl(Control: TControl); override;
procedure ResetBounds(Force: Boolean); override;
procedure SaveToStream(Stream: TStream); override;
function GetDockEdge(ADockObject: TDragDockObject): boolean; override;
procedure RestoreSite(SplitterPos: integer);
procedure StoreConstraints;
function GetSitePreferredClientSize: TPoint;
function IsEnabledControl(Control: TControl):Boolean; override;
property Site: TWinControl read FSite; // the associated TControl (a TAnchorDockHostSite or a custom dock site)
property DockSite: TAnchorDockHostSite read FDockSite; // if Site is a TAnchorDockHostSite, this is it
property DockableSites: TAnchors read FDockableSites write FDockableSites; // at which sides can be docked
property InsideDockingAllowed: boolean read FInsideDockingAllowed write FInsideDockingAllowed; // if true allow to put a site into the custom dock site
function GetChildSite: TAnchorDockHostSite; // get first child TAnchorDockHostSite
property ResizePolicy: TADMResizePolicy read FResizePolicy write FResizePolicy;
property StoredConstraints: TRect read FStoredConstraints write FStoredConstraints;
function StoredConstraintsValid: boolean;
property PreferredSiteSizeAsSiteMinimum: boolean read FPreferredSiteSizeAsSiteMinimum write SetPreferredSiteSizeAsSiteMinimum;
end;
TAnchorDockManagerClass = class of TAnchorDockManager;
{ TAnchorDockSettings }
TADHeaderStyle = (
adhsFrame3D,
adhsLine,
adhsLines,
adhsPoints,
adhsThemedCaption,
adhsThemedButton
);
const
adhsDefault = adhsFrame3D;
type
TAnchorDockSettings = class
private
FAllowDragging: boolean;
FChangeStamp: integer;
FDockOutsideMargin: integer;
FDockParentMargin: integer;
FDragTreshold: integer;
FHeaderAlignLeft: integer;
FHeaderAlignTop: integer;
FHeaderHint: string;
FHeaderStyle: TADHeaderStyle;
FHeaderFlatten: boolean;
FHeaderFilled: boolean;
FHeaderHighlightFocused: boolean;
FHideHeaderCaptionFloatingControl: boolean;
FPageAreaInPercent: integer;
FScaleOnResize: boolean;
FShowHeader: boolean;
FShowHeaderCaption: boolean;
FSplitterWidth: integer;
procedure SetAllowDragging(AValue: boolean);
procedure SetDockOutsideMargin(AValue: integer);
procedure SetDockParentMargin(AValue: integer);
procedure SetDragTreshold(AValue: integer);
procedure SetHeaderAlignLeft(AValue: integer);
procedure SetHeaderAlignTop(AValue: integer);
procedure SetHeaderHint(AValue: string);
procedure SetHeaderStyle(AValue: TADHeaderStyle);
procedure SetHideHeaderCaptionFloatingControl(AValue: boolean);
procedure SetPageAreaInPercent(AValue: integer);
procedure SetScaleOnResize(AValue: boolean);
procedure SetShowHeader(AValue: boolean);
procedure SetShowHeaderCaption(AValue: boolean);
procedure SetSplitterWidth(AValue: integer);
procedure SetHeaderFlatten(AValue: boolean);
procedure SetHeaderFilled(AValue: boolean);
procedure SetHeaderHighlightFocused(AValue: boolean);
public
property DragTreshold: integer read FDragTreshold write SetDragTreshold;
property DockOutsideMargin: integer read FDockOutsideMargin write SetDockOutsideMargin;
property DockParentMargin: integer read FDockParentMargin write SetDockParentMargin;
property PageAreaInPercent: integer read FPageAreaInPercent write SetPageAreaInPercent;
property HeaderAlignTop: integer read FHeaderAlignTop write SetHeaderAlignTop;
property HeaderAlignLeft: integer read FHeaderAlignLeft write SetHeaderAlignLeft;
property HeaderHint: string read FHeaderHint write SetHeaderHint;
property SplitterWidth: integer read FSplitterWidth write SetSplitterWidth;
property ScaleOnResize: boolean read FScaleOnResize write SetScaleOnResize;
property ShowHeader: boolean read FShowHeader write SetShowHeader;
property ShowHeaderCaption: boolean read FShowHeaderCaption write SetShowHeaderCaption;
property HideHeaderCaptionFloatingControl: boolean read FHideHeaderCaptionFloatingControl write SetHideHeaderCaptionFloatingControl;
property AllowDragging: boolean read FAllowDragging write SetAllowDragging;
property HeaderStyle: TADHeaderStyle read FHeaderStyle write SetHeaderStyle;
property HeaderFlatten: boolean read FHeaderFlatten write SetHeaderFlatten;
property HeaderFilled: boolean read FHeaderFilled write SetHeaderFilled;
property HeaderHighlightFocused: boolean read FHeaderHighlightFocused write SetHeaderHighlightFocused;
procedure IncreaseChangeStamp; inline;
property ChangeStamp: integer read FChangeStamp;
procedure LoadFromConfig(Config: TConfigStorage); overload;
procedure LoadFromConfig(Path: string; Config: TRttiXMLConfig); overload;
procedure SaveToConfig(Config: TConfigStorage); overload;
procedure SaveToConfig(Path: string; Config: TRttiXMLConfig); overload;
function IsEqual(Settings: TAnchorDockSettings): boolean; reintroduce;
procedure Assign(Source: TAnchorDockSettings);
end;
TAnchorDockMaster = class;
{ TAnchorDockMaster
The central instance that connects all sites and manages all global
settings. Its global variable is the DockMaster.
Applications only need to talk to the DockMaster. }
TADCreateControlEvent = procedure(Sender: TObject; aName: string;
var AControl: TControl; DoDisableAutoSizing: boolean) of object;
TADShowDockMasterOptionsEvent = function(aDockMaster: TAnchorDockMaster): TModalResult;
TAnchorDockMaster = class(TComponent)
private
FAllowDragging: boolean;
FControls: TFPList; // list of TControl, custom host sites and docked controls, not helper controls (e.g. TAnchorDock*)
FDockOutsideMargin: integer;
FDockParentMargin: integer;
FDragTreshold: integer;
FHeaderAlignLeft: integer;
FHeaderAlignTop: integer;
FHeaderClass: TAnchorDockHeaderClass;
FHeaderHint: string;
FHeaderStyle: TADHeaderStyle;
FHeaderFlatten: boolean;
FHeaderFilled: boolean;
FHeaderHighlightFocused: boolean;
FIdleConnected: Boolean;
FManagerClass: TAnchorDockManagerClass;
FOnCreateControl: TADCreateControlEvent;
FOnOptionsChanged: TNotifyEvent;
FOnShowOptions: TADShowDockMasterOptionsEvent;
FOptionsChangeStamp: int64;
FPageAreaInPercent: integer;
FPageClass: TAnchorDockPageClass;
FPageControlClass: TAnchorDockPageControlClass;
FQueueSimplify: Boolean;
FRestoreLayouts: TAnchorDockRestoreLayouts;
FRestoring: boolean;
FScaleOnResize: boolean;
FShowHeader: boolean;
FShowHeaderCaption: boolean;
FHideHeaderCaptionFloatingControl: boolean;
FShowMenuItemShowHeader: boolean;
FSiteClass: TAnchorDockHostSiteClass;
FSplitterClass: TAnchorDockSplitterClass;
FSplitterWidth: integer;
fNeedSimplify: TFPList; // list of TControl
fNeedFree: TFPList; // list of TControl
fSimplifying: boolean;
fUpdateCount: integer;
fDisabledAutosizing: TFPList; // list of TControl
fTreeNameToDocker: TADNameToControl; // TAnchorDockHostSite, TAnchorDockSplitter or custom docksite
fPopupMenu: TPopupMenu;
// Used by RestoreLayout:
WorkArea, SrcWorkArea: TRect;
function GetControls(Index: integer): TControl;
function GetLocalizedHeaderHint: string;
procedure MarkCorrectlyLocatedControl(Tree: TAnchorDockLayoutTree);
function CloseUnneededAndWronglyLocatedControls(Tree: TAnchorDockLayoutTree): boolean;
function CreateNeededControls(Tree: TAnchorDockLayoutTree;
DisableAutoSizing: boolean; ControlNames: TStrings): boolean;
function GetNodeSite(Node: TAnchorDockLayoutTreeNode): TAnchorDockHostSite;
procedure MapTreeToControls(Tree: TAnchorDockLayoutTree);
function RestoreLayout(Tree: TAnchorDockLayoutTree; Scale: boolean): boolean;
procedure EnableAllAutoSizing;
procedure ClearLayoutProperties(AControl: TControl; NewAlign: TAlign = alClient);
procedure PopupMenuPopup(Sender: TObject);
procedure ChangeLockButtonClick(Sender: TObject);
function ScaleChildX(p: integer): integer;
function ScaleChildY(p: integer): integer;
function ScaleTopLvlX(p: integer): integer;
function ScaleTopLvlY(p: integer): integer;
procedure SetAllowDragging(AValue: boolean);
procedure SetDockOutsideMargin(AValue: integer);
procedure SetDockParentMargin(AValue: integer);
procedure SetDragTreshold(AValue: integer);
procedure SetHeaderHint(AValue: string);
procedure SetHeaderStyle(AValue: TADHeaderStyle);
procedure SetPageAreaInPercent(AValue: integer);
procedure SetScaleOnResize(AValue: boolean);
procedure SetHeaderFlatten(AValue: boolean);
procedure SetHeaderFilled(AValue: boolean);
procedure SetHeaderHighlightFocused(AValue: boolean);
procedure SetShowMenuItemShowHeader(AValue: boolean);
procedure SetupSite(Site: TWinControl; ANode: TAnchorDockLayoutTreeNode;
AParent: TWinControl);
procedure ShowHeadersButtonClick(Sender: TObject);
procedure OptionsClick(Sender: TObject);
procedure SetIdleConnected(const AValue: Boolean);
procedure SetQueueSimplify(const AValue: Boolean);
procedure SetRestoring(const AValue: boolean);
procedure OptionsChanged;
protected
function DoCreateControl(aName: string; DisableAutoSizing: boolean): TControl;
procedure AutoSizeAllHeaders(EnableAutoSizing: boolean);
procedure DisableControlAutoSizing(AControl: TControl);
procedure InvalidateHeaders;
procedure Notification(AComponent: TComponent; Operation: TOperation); override;
procedure SetHeaderAlignLeft(const AValue: integer);
procedure SetHeaderAlignTop(const AValue: integer);
procedure SetShowHeader(AValue: boolean);
procedure SetShowHeaderCaption(const AValue: boolean);
procedure SetHideHeaderCaptionFloatingControl(const AValue: boolean);
procedure SetSplitterWidth(const AValue: integer);
procedure OnIdle(Sender: TObject; var Done: Boolean);
procedure AsyncSimplify({%H-}Data: PtrInt);
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
function FullRestoreLayout(Tree: TAnchorDockLayoutTree; Scale: Boolean): Boolean;
function ControlCount: integer;
property Controls[Index: integer]: TControl read GetControls;
function IndexOfControl(const aName: string): integer;
function FindControl(const aName: string): TControl;
function IsSite(AControl: TControl): boolean;
function IsAnchorSite(AControl: TControl): boolean;
function IsCustomSite(AControl: TControl): boolean;
function GetSite(AControl: TControl): TCustomForm;
function GetAnchorSite(AControl: TControl): TAnchorDockHostSite;
function GetControl(Site: TControl): TControl;
function IsFloating(AControl: TControl): Boolean;
function GetPopupMenu: TPopupMenu;
function AddPopupMenuItem(AName, ACaption: string;
const OnClickEvent: TNotifyEvent; AParent: TMenuItem = nil): TMenuItem; virtual;
function AddRemovePopupMenuItem(Add: boolean; AName, ACaption: string;
const OnClickEvent: TNotifyEvent; AParent: TMenuItem = nil): TMenuItem; virtual;
// show / make a control dockable
procedure MakeDockable(AControl: TControl; Show: boolean = true;
BringToFront: boolean = false;
AddDockHeader: boolean = true);
procedure MakeDockSite(AForm: TCustomForm; Sites: TAnchors;
ResizePolicy: TADMResizePolicy;
AllowInside: boolean = false);
procedure MakeDockPanel(APanel: TAnchorDockPanel;
ResizePolicy: TADMResizePolicy);
procedure MakeVisible(AControl: TControl; SwitchPages: boolean);
function ShowControl(ControlName: string; BringToFront: boolean = false): TControl;
procedure CloseAll;
// save/restore layouts
procedure SaveLayoutToConfig(Config: TConfigStorage);
procedure SaveMainLayoutToTree(LayoutTree: TAnchorDockLayoutTree);
procedure SaveSiteLayoutToTree(AControl: TWinControl;
LayoutTree: TAnchorDockLayoutTree);
function CreateRestoreLayout(AControl: TControl): TAnchorDockRestoreLayout;
function ConfigIsEmpty(Config: TConfigStorage): boolean;
function LoadLayoutFromConfig(Config: TConfigStorage; Scale: Boolean): boolean;
// layout information for restoring hidden forms
property RestoreLayouts: TAnchorDockRestoreLayouts read FRestoreLayouts
write FRestoreLayouts;
property Restoring: boolean read FRestoring write SetRestoring;
property IdleConnected: Boolean read FIdleConnected write SetIdleConnected;
procedure LoadSettingsFromConfig(Config: TConfigStorage);
procedure SaveSettingsToConfig(Config: TConfigStorage);
procedure LoadSettings(Settings: TAnchorDockSettings);
procedure SaveSettings(Settings: TAnchorDockSettings);
function SettingsAreEqual(Settings: TAnchorDockSettings): boolean;
procedure ResetSplitters;
// manual docking
procedure ManualFloat(AControl: TControl);
procedure ManualDock(SrcSite: TAnchorDockHostSite; TargetSite: TCustomForm;
Align: TAlign; TargetControl: TControl = nil);
function ManualEnlarge(Site: TAnchorDockHostSite; Side: TAnchorKind;
OnlyCheckIfPossible: boolean): boolean;
// simplification/garbage collection
procedure BeginUpdate;
procedure EndUpdate;
function IsReleasing(AControl: TControl): Boolean;
procedure NeedSimplify(AControl: TControl);
procedure NeedFree(AControl: TControl);
procedure SimplifyPendingLayouts;
function AutoFreedIfControlIsRemoved(AControl, RemovedControl: TControl): boolean;
function CreateSite(NamePrefix: string = '';
DisableAutoSizing: boolean = true): TAnchorDockHostSite;
function CreateSplitter(NamePrefix: string = ''): TAnchorDockSplitter;
property QueueSimplify: Boolean read FQueueSimplify write SetQueueSimplify;
property OnCreateControl: TADCreateControlEvent read FOnCreateControl write FOnCreateControl;
// options
property OnShowOptions: TADShowDockMasterOptionsEvent read FOnShowOptions write FOnShowOptions;
property OnOptionsChanged: TNotifyEvent read FOnOptionsChanged write FOnOptionsChanged;
property DragTreshold: integer read FDragTreshold write SetDragTreshold default 4;
property DockOutsideMargin: integer read FDockOutsideMargin write SetDockOutsideMargin default 10; // max distance for outside mouse snapping
property DockParentMargin: integer read FDockParentMargin write SetDockParentMargin default 10; // max distance for snap to parent
property PageAreaInPercent: integer read FPageAreaInPercent write SetPageAreaInPercent default 40; // size of inner mouse snapping area for page docking
property ShowHeader: boolean read FShowHeader write SetShowHeader default true; // set to false to hide all headers
property ShowMenuItemShowHeader: boolean read FShowMenuItemShowHeader write SetShowMenuItemShowHeader default false;
property ShowHeaderCaption: boolean read FShowHeaderCaption write SetShowHeaderCaption default true; // set to false to remove the text in the headers
property HideHeaderCaptionFloatingControl: boolean read FHideHeaderCaptionFloatingControl
write SetHideHeaderCaptionFloatingControl default true; // disables ShowHeaderCaption for floating controls
property HeaderAlignTop: integer read FHeaderAlignTop write SetHeaderAlignTop default 80; // move header to top, when (width/height)*100<=HeaderAlignTop
property HeaderAlignLeft: integer read FHeaderAlignLeft write SetHeaderAlignLeft default 120; // move header to left, when (width/height)*100>=HeaderAlignLeft
property HeaderHint: string read FHeaderHint write SetHeaderHint; // if empty it uses resourcestring adrsDragAndDockC
property HeaderStyle: TADHeaderStyle read FHeaderStyle write SetHeaderStyle default adhsDefault;
property HeaderFlatten: boolean read FHeaderFlatten write SetHeaderFlatten default true;
property HeaderFilled: boolean read FHeaderFilled write SetHeaderFilled default true;
property HeaderHighlightFocused: boolean read FHeaderHighlightFocused write SetHeaderHighlightFocused default false;
property SplitterWidth: integer read FSplitterWidth write SetSplitterWidth default 4;
property ScaleOnResize: boolean read FScaleOnResize write SetScaleOnResize default true; // scale children when resizing a site
property AllowDragging: boolean read FAllowDragging write SetAllowDragging default true;
property OptionsChangeStamp: int64 read FOptionsChangeStamp;
procedure IncreaseOptionsChangeStamp; inline;
// for descendants
property SplitterClass: TAnchorDockSplitterClass read FSplitterClass write FSplitterClass;
property SiteClass: TAnchorDockHostSiteClass read FSiteClass write FSiteClass;
property ManagerClass: TAnchorDockManagerClass read FManagerClass write FManagerClass;
property HeaderClass: TAnchorDockHeaderClass read FHeaderClass write FHeaderClass;
property PageControlClass: TAnchorDockPageControlClass read FPageControlClass write FPageControlClass;
property PageClass: TAnchorDockPageClass read FPageClass write FPageClass;
end;
var
DockMaster: TAnchorDockMaster = nil;
const
ADHeaderStyleNames: array[TADHeaderStyle] of string = (
'Frame3D',
'Line',
'Lines',
'Points',
'Themed caption',
'Themed button'
);
function StrToADHeaderStyle(const s: string): TADHeaderStyle;
function dbgs(SiteType: TAnchorDockHostSiteType): string; overload;
procedure DrawADHeader(Canvas: TCanvas; Style: TADHeaderStyle; r: TRect; Horizontal: boolean; Focused: boolean);
procedure CopyAnchorBounds(Source, Target: TControl);
procedure AnchorAndChangeBounds(AControl: TControl; Side: TAnchorKind;
Target: TControl);
function ControlsLeftTopOnScreen(AControl: TControl): TPoint;
type
TAnchorControlsRect = array[TAnchorKind] of TControl;
function DockedControlIsVisible(Control: TControl): boolean;
function GetDockSplitter(Control: TControl; Side: TAnchorKind;
out Splitter: TAnchorDockSplitter): boolean;
function GetDockSplitterOrParent(Control: TControl; Side: TAnchorKind;
out AnchorControl: TControl): boolean;
function CountAnchoredControls(Control: TControl; Side: TAnchorKind): Integer;
function NeighbourCanBeShrinked(EnlargeControl, Neighbour: TControl;
Side: TAnchorKind): boolean;
function ControlIsAnchoredIndirectly(StartControl: TControl; Side: TAnchorKind;
DestControl: TControl): boolean;
procedure GetAnchorControlsRect(Control: TControl; out ARect: TAnchorControlsRect);
function GetEnclosingControlRect(ControlList: TFPlist;
out ARect: TAnchorControlsRect): boolean;
function GetEnclosedControls(const ARect: TAnchorControlsRect): TFPList;
implementation
function StrToADHeaderStyle(const s: string): TADHeaderStyle;
begin
for Result:=Low(TADHeaderStyle) to High(TADHeaderStyle) do
if CompareText(ADHeaderStyleNames[Result],s)=0 then exit;
Result:=adhsDefault;
end;
procedure DrawADHeader(Canvas: TCanvas; Style: TADHeaderStyle; r: TRect;
Horizontal: boolean; Focused: boolean);
var
Center: Integer;
lx, ly, d, lt, lb, lm: Integer;
ted:TThemedElementDetails;
begin
case Style of
adhsFrame3D:
begin
Canvas.Frame3d(r,2,bvLowered);
Canvas.Frame3d(r,4,bvRaised);
end;
adhsLine:
if Horizontal then
begin
Center:=r.Top+(r.Bottom-r.Top) div 2;
Canvas.Pen.Color:=clltgray;
Canvas.Line(r.Left+5,Center-1,r.Right-3,Center-1);
Canvas.Pen.Color:=clgray;
Canvas.Line(r.Left+5,Center,r.Right-3,Center);
end else
begin
Center:=r.Right+(r.Left-r.Right) div 2;
Canvas.Pen.Color:=clltgray;
Canvas.Line(Center-1,r.Top+3,Center-1,r.Bottom-5);
Canvas.Pen.Color:=clgray;
Canvas.Line(Center,r.Top+3,Center,r.Bottom-5);
end;
adhsLines:
begin
InflateRect(r,-2,-2);
if Horizontal then
begin
lx:=0;
ly:=3;
r.Bottom:=r.top+(r.bottom-r.Top) div 3;
r.top:=r.bottom-ly;
end else
begin
lx:=3;
ly:=0;
r.Right:=r.Left+(r.Right-r.Left) div 3 ;
r.Left:=r.Right-lx;
end;
DrawEdge(Canvas.Handle,r, BDR_RAISEDINNER, BF_RECT );
OffsetRect(r,lx,ly);
DrawEdge(Canvas.Handle,r, BDR_RAISEDINNER, BF_RECT );
OffsetRect(r,lx,ly);
DrawEdge(Canvas.Handle,r, BDR_RAISEDINNER, BF_RECT );
end;
adhsPoints:
if Horizontal then begin
lx := r.left+2;
d := (r.Bottom - r.Top - 5) div 2;
lt := r.Top + d;
lb := lt + 4;
lm := lt + 2;
while lx < r.Right do
begin
Canvas.Pixels[lx, lt] := clBtnShadow;
Canvas.Pixels[lx, lb] := clBtnShadow;
Canvas.Pixels[lx+2, lm] := clBtnShadow;
lx := lx + 4;
end;
end else begin
ly := r.Bottom - 2;
d := (r.Right - r.Left - 5) div 2;
lt := r.Left + d;
lb := lt + 4;
lm := lt + 2;
while ly > r.Top do
begin
Canvas.Pixels[lt, ly] := clBtnShadow;
Canvas.Pixels[lb, ly] := clBtnShadow;
Canvas.Pixels[lm, ly-2] := clBtnShadow;
ly := ly - 4;
end;
end;
adhsThemedCaption:
begin
if Focused then
ted:=ThemeServices.GetElementDetails(twSmallCaptionActive)
else
ted:=ThemeServices.GetElementDetails(twSmallCaptionInactive);
r.Bottom:=r.Bottom-3;
ThemeServices.DrawElement(Canvas.Handle,ted, r);
if Focused then
ted:=ThemeServices.GetElementDetails(twSmallFrameBottomActive)
else
ted:=ThemeServices.GetElementDetails(twSmallFrameBottomInactive);
r.Top:=r.Bottom;
r.Bottom:=r.Bottom+3;
ThemeServices.DrawElement(Canvas.Handle,ted, r);
end;
adhsThemedButton:
begin
if Focused then
ted:=ThemeServices.GetElementDetails(tbPushButtonHot)
else
ted:=ThemeServices.GetElementDetails(tbPushButtonNormal);
ThemeServices.DrawElement(Canvas.Handle,ted, r);
end;
end;
end;
function dbgs(SiteType: TAnchorDockHostSiteType): string; overload;
begin
case SiteType of
adhstNone: Result:='None';
adhstOneControl: Result:='OneControl';
adhstLayout: Result:='Layout';
adhstPages: Result:='Pages';
else Result:='?';
end;
end;
procedure CopyAnchorBounds(Source, Target: TControl);
var
a: TAnchorKind;
begin
Target.DisableAutoSizing{$IFDEF DebugDisableAutoSizing}('CopyAnchorBounds'){$ENDIF};
try
Target.BoundsRect:=Source.BoundsRect;
Target.Anchors:=Source.Anchors;
Target.Align:=Source.Align;
for a:=low(TAnchorKind) to high(TAnchorKind) do
Target.AnchorSide[a].Assign(Source.AnchorSide[a]);
finally
Target.EnableAutoSizing{$IFDEF DebugDisableAutoSizing}('CopyAnchorBounds'){$ENDIF};
end;
end;
procedure AnchorAndChangeBounds(AControl: TControl; Side: TAnchorKind;
Target: TControl);
begin
if Target=AControl.Parent then begin
AControl.AnchorParallel(Side,0,Target);
case Side of
akTop: AControl.Top:=0;
akLeft: AControl.Left:=0;
akRight: AControl.Width:=AControl.Parent.ClientWidth-AControl.Left;
akBottom: AControl.Height:=AControl.Parent.ClientHeight-AControl.Top;
end;
end else begin
AControl.AnchorToNeighbour(Side,0,Target);
case Side of
akTop: AControl.Top:=Target.Top+Target.Height;
akLeft: AControl.Left:=Target.Left+Target.Width;
akRight: AControl.Width:=Target.Left-AControl.Width;
akBottom: AControl.Height:=Target.Top-AControl.Height;
end;
end;
end;
function ControlsLeftTopOnScreen(AControl: TControl): TPoint;
begin
if AControl.Parent<>nil then begin
Result:=AControl.Parent.ClientOrigin;
inc(Result.X,AControl.Left);
inc(Result.Y,AControl.Top);
end else begin
Result:=AControl.Parent.ClientOrigin;
end;
end;
function DockedControlIsVisible(Control: TControl): boolean;
begin
while Control<>nil do begin
if (not Control.IsControlVisible)
and (not (Control is TAnchorDockPage)) then
exit(false);
Control:=Control.Parent;
end;
Result:=true;
end;
function GetDockSplitter(Control: TControl; Side: TAnchorKind; out
Splitter: TAnchorDockSplitter): boolean;
begin
Result:=false;
Splitter:=nil;
if not assigned(Control) or not (Side in Control.Anchors) then exit;
Splitter:=TAnchorDockSplitter(Control.AnchorSide[Side].Control);
if not (Splitter is TAnchorDockSplitter) then begin
Splitter:=nil;
exit;
end;
if Splitter.Parent<>Control.Parent then exit;
Result:=true;
end;
function GetDockSplitterOrParent(Control: TControl; Side: TAnchorKind; out
AnchorControl: TControl): boolean;
begin
Result:=false;
AnchorControl:=nil;
if not (Side in Control.Anchors) then exit;
AnchorControl:=Control.AnchorSide[Side].Control;
if (AnchorControl is TAnchorDockSplitter)
and (AnchorControl.Parent=Control.Parent)
then
Result:=true
else if AnchorControl=Control.Parent then
Result:=true;
end;
function CountAnchoredControls(Control: TControl; Side: TAnchorKind): Integer;
{ return the number of siblings, that are anchored on Side of Control
For example: if Side=akLeft it will return the number of controls, which
right side is anchored to the left of Control }
var
i: Integer;
Neighbour: TControl;
begin
Result:=0;
for i:=0 to Control.AnchoredControlCount-1 do begin
Neighbour:=Control.AnchoredControls[i];
if (OppositeAnchor[Side] in Neighbour.Anchors)
and (Neighbour.AnchorSide[OppositeAnchor[Side]].Control=Control) then
inc(Result);
end;
end;
function NeighbourCanBeShrinked(EnlargeControl, Neighbour: TControl;
Side: TAnchorKind): boolean;
{ returns true if Neighbour can be shrinked on the opposite side of Side
}
const
MinControlSize = 20;
var
Splitter: TAnchorDockSplitter;
begin
Result:=false;
if not GetDockSplitter(EnlargeControl,OppositeAnchor[Side],Splitter) then
exit;
case Side of
akLeft: // check if left side of Neighbour can be moved
Result:=Neighbour.Left+Neighbour.Width
>EnlargeControl.Left+EnlargeControl.Width+Splitter.Width+MinControlSize;
akRight: // check if right side of Neighbour can be moved
Result:=Neighbour.Left+MinControlSize+Splitter.Width<EnlargeControl.Left;
akTop: // check if top side of Neighbour can be moved
Result:=Neighbour.Top+Neighbour.Height
>EnlargeControl.Top+EnlargeControl.Height+Splitter.Height+MinControlSize;
akBottom: // check if bottom side of Neighbour can be moved
Result:=Neighbour.Top+MinControlSize+Splitter.Height<EnlargeControl.Top;
end;
end;
function ControlIsAnchoredIndirectly(StartControl: TControl; Side: TAnchorKind;
DestControl: TControl): boolean;
{ true if there is an Anchor way from StartControl to DestControl over Side.
For example:
+-+|+-+
|A|||B|
+-+|+-+
A is akLeft to B.
B is akRight to A.
The splitter is akLeft to B.
The splitter is akRight to A.
All other are false.
}
var
Checked: array of Boolean;
Parent: TWinControl;
function Check(ControlIndex: integer): boolean;
var
AControl: TControl;
SideControl: TControl;
i: Integer;
begin
if Checked[ControlIndex] then
exit(false);
Checked[ControlIndex]:=true;
AControl:=Parent.Controls[ControlIndex];
if AControl=DestControl then exit(true);
if (Side in AControl.Anchors) then begin
SideControl:=AControl.AnchorSide[Side].Control;
if (SideControl<>nil) and Check(Parent.GetControlIndex(SideControl)) then
exit(true);
end;
for i:=0 to AControl.AnchoredControlCount-1 do begin
if Checked[i] then continue;
SideControl:=AControl.AnchoredControls[i];
if OppositeAnchor[Side] in SideControl.Anchors then begin
if (SideControl.AnchorSide[OppositeAnchor[Side]].Control=AControl)
and Check(i) then
exit(true);
end;
end;
Result:=false;
end;
var
i: Integer;
begin
if (StartControl=nil) or (DestControl=nil)
or (StartControl.Parent=nil)
or (StartControl.Parent<>DestControl.Parent)
or (StartControl=DestControl) then
exit(false);
Parent:=StartControl.Parent;
SetLength(Checked,Parent.ControlCount);
for i:=0 to length(Checked)-1 do Checked[i]:=false;
Result:=Check(Parent.GetControlIndex(StartControl));
end;
procedure GetAnchorControlsRect(Control: TControl; out ARect: TAnchorControlsRect);
var
a: TAnchorKind;
begin
for a:=Low(TAnchorKind) to High(TAnchorKind) do
ARect[a]:=Control.AnchorSide[a].Control;
end;
function GetEnclosingControlRect(ControlList: TFPlist; out
ARect: TAnchorControlsRect): boolean;
{ ARect will be the minimum TAnchorControlsRect around the controls in the list
returns true, if there is such a TAnchorControlsRect.
The controls in ARect will either be the Parent or a TLazDockSplitter
}
var
Parent: TWinControl;
function ControlIsValidAnchor(Control: TControl; Side: TAnchorKind): boolean;
var
i: Integer;
begin
Result:=false;
if (Control=ARect[Side]) then exit(true);// this allows Parent at the beginning
if not (Control is TAnchorDockSplitter) then
exit;// not a splitter
if (TAnchorDockSplitter(Control).ResizeAnchor in [akLeft,akRight])
<>(Side in [akLeft,akRight]) then
exit;// wrong alignment
if ControlList.IndexOf(Control)>=0 then
exit;// is an inner control
if ControlIsAnchoredIndirectly(Control,Side,ARect[Side]) then
exit; // this anchor would be worse than the current maximum
for i:=0 to ControlList.Count-1 do begin
if not ControlIsAnchoredIndirectly(Control,Side,TControl(ControlList[i]))
then begin
// this anchor is not above (below, ...) the inner controls
exit;
end;
end;
Result:=true;
end;
var
TopIndex: Integer;
TopControl: TControl;
RightIndex: Integer;
RightControl: TControl;
BottomIndex: Integer;
BottomControl: TControl;
LeftIndex: Integer;
LeftControl: TControl;
Candidates: TFPList;
i: Integer;
a: TAnchorKind;
begin
Result:=false;
if (ControlList=nil) or (ControlList.Count=0) then exit;
// get Parent
Parent:=TControl(ControlList[0]).Parent;
if Parent=nil then exit;
for i:=0 to ControlList.Count-1 do
if TControl(ControlList[i]).Parent<>Parent then exit;
// set the default rect: the Parent
Result:=true;
for a:=Low(TAnchorKind) to High(TAnchorKind) do
ARect[a]:=Parent;
// find all possible Candidates
Candidates:=TFPList.Create;
try
Candidates.Add(Parent);
for i:=0 to Parent.ControlCount-1 do
if Parent.Controls[i] is TAnchorDockSplitter then
Candidates.Add(Parent.Controls[i]);
// now check every possible rectangle
// Note: four loops seems to be dog slow, but the checks
// avoid most possibilities early
for TopIndex:=0 to Candidates.Count-1 do begin
TopControl:=TControl(Candidates[TopIndex]);
if not ControlIsValidAnchor(TopControl,akTop) then continue;
for RightIndex:=0 to Candidates.Count-1 do begin
RightControl:=TControl(Candidates[RightIndex]);
if (TopControl.AnchorSide[akRight].Control<>RightControl)
and (RightControl.AnchorSide[akTop].Control<>TopControl) then
continue; // not touching / not a corner
if not ControlIsValidAnchor(RightControl,akRight) then continue;
for BottomIndex:=0 to Candidates.Count-1 do begin
BottomControl:=TControl(Candidates[BottomIndex]);
if (RightControl.AnchorSide[akBottom].Control<>BottomControl)
and (BottomControl.AnchorSide[akRight].Control<>RightControl) then
continue; // not touching / not a corner
if not ControlIsValidAnchor(BottomControl,akBottom) then continue;
for LeftIndex:=0 to Candidates.Count-1 do begin
LeftControl:=TControl(Candidates[LeftIndex]);
if (BottomControl.AnchorSide[akLeft].Control<>LeftControl)
and (LeftControl.AnchorSide[akBottom].Control<>BottomControl) then
continue; // not touching / not a corner
if (TopControl.AnchorSide[akLeft].Control<>LeftControl)
and (LeftControl.AnchorSide[akTop].Control<>LeftControl) then
continue; // not touching / not a corner
if not ControlIsValidAnchor(LeftControl,akLeft) then continue;
// found a better rectangle
ARect[akLeft] :=LeftControl;
ARect[akRight] :=RightControl;
ARect[akTop] :=TopControl;
ARect[akBottom]:=BottomControl;
end;
end;
end;
end;
finally
Candidates.Free;
end;
end;
function GetEnclosedControls(const ARect: TAnchorControlsRect): TFPList;
{ return a list of all controls bounded by the anchors in ARect }
var
Parent: TWinControl;
procedure Fill(AControl: TControl);
var
a: TAnchorKind;
SideControl: TControl;
i: Integer;
begin
if AControl=nil then exit;
if AControl=Parent then exit;// do not add Parent
for a:=Low(TAnchorKind) to High(TAnchorKind) do
if ARect[a]=AControl then exit;// do not add boundary
if Result.IndexOf(AControl)>=0 then exit;// already added
Result.Add(AControl);
for a:=Low(TAnchorKind) to High(TAnchorKind) do
Fill(AControl.AnchorSide[a].Control);
for i:=0 to Parent.ControlCount-1 do begin
SideControl:=Parent.Controls[i];
for a:=Low(TAnchorKind) to High(TAnchorKind) do
if SideControl.AnchorSide[a].Control=AControl then
Fill(SideControl);
end;
end;
var
i: Integer;
AControl: TControl;
LeftTopControl: TControl;
begin
Result:=TFPList.Create;
// find the Parent
if (ARect[akLeft]=ARect[akRight]) and (ARect[akLeft] is TWinControl) then
Parent:=TWinControl(ARect[akLeft])
else
Parent:=ARect[akLeft].Parent;
// find the left, top most control
for i:=0 to Parent.ControlCount-1 do begin
AControl:=Parent.Controls[i];
if (AControl.AnchorSide[akLeft].Control=ARect[akLeft])
and (AControl.AnchorSide[akTop].Control=ARect[akTop]) then begin
LeftTopControl:=AControl;
break;
end;
end;
if Result.Count=0 then exit;
// use flood fill to find the rest
Fill(LeftTopControl);
end;
{ TAnchorDockSettings }
procedure TAnchorDockSettings.SetAllowDragging(AValue: boolean);
begin
if FAllowDragging=AValue then Exit;
FAllowDragging:=AValue;
IncreaseChangeStamp;
end;
procedure TAnchorDockSettings.SetDockOutsideMargin(AValue: integer);
begin
if FDockOutsideMargin=AValue then Exit;
FDockOutsideMargin:=AValue;
IncreaseChangeStamp;
end;
procedure TAnchorDockSettings.SetDockParentMargin(AValue: integer);
begin
if FDockParentMargin=AValue then Exit;
FDockParentMargin:=AValue;
IncreaseChangeStamp;
end;
procedure TAnchorDockSettings.SetDragTreshold(AValue: integer);
begin
if FDragTreshold=AValue then Exit;
FDragTreshold:=AValue;
IncreaseChangeStamp;
end;
procedure TAnchorDockSettings.SetHeaderAlignLeft(AValue: integer);
begin
if FHeaderAlignLeft=AValue then Exit;
FHeaderAlignLeft:=AValue;
IncreaseChangeStamp;
end;
procedure TAnchorDockSettings.SetHeaderAlignTop(AValue: integer);
begin
if FHeaderAlignTop=AValue then Exit;
FHeaderAlignTop:=AValue;
IncreaseChangeStamp;
end;
procedure TAnchorDockSettings.SetHeaderHint(AValue: string);
begin
if FHeaderHint=AValue then Exit;
FHeaderHint:=AValue;
IncreaseChangeStamp;
end;
procedure TAnchorDockSettings.SetHeaderStyle(AValue: TADHeaderStyle);
begin
if FHeaderStyle=AValue then Exit;
FHeaderStyle:=AValue;
IncreaseChangeStamp;
end;
procedure TAnchorDockSettings.SetHideHeaderCaptionFloatingControl(
AValue: boolean);
begin
if FHideHeaderCaptionFloatingControl=AValue then Exit;
FHideHeaderCaptionFloatingControl:=AValue;
IncreaseChangeStamp;
end;
procedure TAnchorDockSettings.SetPageAreaInPercent(AValue: integer);
begin
if FPageAreaInPercent=AValue then Exit;
FPageAreaInPercent:=AValue;
IncreaseChangeStamp;
end;
procedure TAnchorDockSettings.SetScaleOnResize(AValue: boolean);
begin
if FScaleOnResize=AValue then Exit;
FScaleOnResize:=AValue;
IncreaseChangeStamp;
end;
procedure TAnchorDockSettings.SetHeaderFlatten(AValue: boolean);
begin
if FHeaderFlatten=AValue then Exit;
FHeaderFlatten:=AValue;
IncreaseChangeStamp;
end;
procedure TAnchorDockSettings.SetHeaderFilled(AValue: boolean);
begin
if FHeaderFilled=AValue then Exit;
FHeaderFilled:=AValue;
IncreaseChangeStamp;
end;
procedure TAnchorDockSettings.SetHeaderHighlightFocused(AValue: boolean);
begin
if FHeaderHighlightFocused=AValue then Exit;
FHeaderHighlightFocused:=AValue;
IncreaseChangeStamp;
end;
procedure TAnchorDockSettings.SetShowHeader(AValue: boolean);
begin
if FShowHeader=AValue then Exit;
FShowHeader:=AValue;
IncreaseChangeStamp;
end;
procedure TAnchorDockSettings.SetShowHeaderCaption(AValue: boolean);
begin
if FShowHeaderCaption=AValue then Exit;
FShowHeaderCaption:=AValue;
IncreaseChangeStamp;
end;
procedure TAnchorDockSettings.SetSplitterWidth(AValue: integer);
begin
if FSplitterWidth=AValue then Exit;
FSplitterWidth:=AValue;
IncreaseChangeStamp;
end;
procedure TAnchorDockSettings.Assign(Source: TAnchorDockSettings);
begin
FAllowDragging := Source.FAllowDragging;
FChangeStamp := Source.FChangeStamp;
FDockOutsideMargin := Source.FDockOutsideMargin;
FDockParentMargin := Source.FDockParentMargin;
FDragTreshold := Source.FDragTreshold;
FHeaderAlignLeft := Source.FHeaderAlignLeft;
FHeaderAlignTop := Source.FHeaderAlignTop;
FHeaderHint := Source.FHeaderHint;
FHeaderStyle := Source.FHeaderStyle;
FHeaderFlatten := Source.FHeaderFlatten;
FHeaderFilled := Source.FHeaderFilled;
FHideHeaderCaptionFloatingControl := Source.FHideHeaderCaptionFloatingControl;
FPageAreaInPercent := Source.FPageAreaInPercent;
FScaleOnResize := Source.FScaleOnResize;
FShowHeader := Source.FShowHeader;
FShowHeaderCaption := Source.FShowHeaderCaption;
FSplitterWidth := Source.FSplitterWidth;
FHeaderHighlightFocused:=Source.FHeaderHighlightFocused;
end;
procedure TAnchorDockSettings.IncreaseChangeStamp;
begin
LUIncreaseChangeStamp(fChangeStamp);
end;
procedure TAnchorDockSettings.LoadFromConfig(Config: TConfigStorage);
begin
Config.AppendBasePath('Settings/');
DragTreshold:=Config.GetValue('DragThreshold',4);
DockOutsideMargin:=Config.GetValue('DockOutsideMargin',10);
DockParentMargin:=Config.GetValue('DockParentMargin',10);
PageAreaInPercent:=Config.GetValue('PageAreaInPercent',40);
HeaderAlignTop:=Config.GetValue('HeaderAlignTop',80);
HeaderAlignLeft:=Config.GetValue('HeaderAlignLeft',120);
SplitterWidth:=Config.GetValue('SplitterWidth',4);
ScaleOnResize:=Config.GetValue('ScaleOnResize',true);
ShowHeader:=Config.GetValue('ShowHeader',true);
ShowHeaderCaption:=Config.GetValue('ShowHeaderCaption',true);
HideHeaderCaptionFloatingControl:=Config.GetValue('HideHeaderCaptionFloatingControl',true);
AllowDragging:=Config.GetValue('AllowDragging',true);
HeaderStyle:=StrToADHeaderStyle(Config.GetValue('HeaderStyle',ADHeaderStyleNames[adhsDefault]));
HeaderFlatten:=Config.GetValue('HeaderFlatten',true);
HeaderFilled:=Config.GetValue('HeaderFilled',true);
HeaderHighlightFocused:=Config.GetValue('HeaderHighlightFocused',False);
Config.UndoAppendBasePath;
end;
procedure TAnchorDockSettings.SaveToConfig(Path: string; Config: TRttiXMLConfig
);
begin
Config.SetDeleteValue(Path+'DragThreshold',DragTreshold,4);
Config.SetDeleteValue(Path+'DockOutsideMargin',DockOutsideMargin,10);
Config.SetDeleteValue(Path+'DockParentMargin',DockParentMargin,10);
Config.SetDeleteValue(Path+'PageAreaInPercent',PageAreaInPercent,40);
Config.SetDeleteValue(Path+'HeaderAlignTop',HeaderAlignTop,80);
Config.SetDeleteValue(Path+'HeaderAlignLeft',HeaderAlignLeft,120);
Config.SetDeleteValue(Path+'SplitterWidth',SplitterWidth,4);
Config.SetDeleteValue(Path+'ScaleOnResize',ScaleOnResize,true);
Config.SetDeleteValue(Path+'ShowHeader',ShowHeader,true);
Config.SetDeleteValue(Path+'ShowHeaderCaption',ShowHeaderCaption,true);
Config.SetDeleteValue(Path+'HideHeaderCaptionFloatingControl',HideHeaderCaptionFloatingControl,true);
Config.SetDeleteValue(Path+'AllowDragging',AllowDragging,true);
Config.SetDeleteValue(Path+'HeaderStyle',ADHeaderStyleNames[HeaderStyle],ADHeaderStyleNames[adhsDefault]);
Config.SetDeleteValue(Path+'HeaderFlatten',HeaderFlatten,true);
Config.SetDeleteValue(Path+'HeaderFilled',HeaderFilled,true);
Config.SetDeleteValue(Path+'HeaderHighlightFocused',HeaderHighlightFocused,False);
end;
procedure TAnchorDockSettings.SaveToConfig(Config: TConfigStorage);
begin
Config.AppendBasePath('Settings/');
Config.SetDeleteValue('DragThreshold',DragTreshold,4);
Config.SetDeleteValue('DockOutsideMargin',DockOutsideMargin,10);
Config.SetDeleteValue('DockParentMargin',DockParentMargin,10);
Config.SetDeleteValue('PageAreaInPercent',PageAreaInPercent,40);
Config.SetDeleteValue('HeaderAlignTop',HeaderAlignTop,80);
Config.SetDeleteValue('HeaderAlignLeft',HeaderAlignLeft,120);
Config.SetDeleteValue('SplitterWidth',SplitterWidth,4);
Config.SetDeleteValue('ScaleOnResize',ScaleOnResize,true);
Config.SetDeleteValue('ShowHeader',ShowHeader,true);
Config.SetDeleteValue('ShowHeaderCaption',ShowHeaderCaption,true);
Config.SetDeleteValue('HideHeaderCaptionFloatingControl',HideHeaderCaptionFloatingControl,true);
Config.SetDeleteValue('AllowDragging',AllowDragging,true);
Config.SetDeleteValue('HeaderStyle',ADHeaderStyleNames[HeaderStyle],ADHeaderStyleNames[adhsDefault]);
Config.SetDeleteValue('HeaderFlatten',HeaderFlatten,true);
Config.SetDeleteValue('HeaderFilled',HeaderFilled,true);
Config.SetDeleteValue('HeaderHighlightFocused',HeaderHighlightFocused,False);
Config.UndoAppendBasePath;
end;
function TAnchorDockSettings.IsEqual(Settings: TAnchorDockSettings): boolean;
begin
Result:=(DragTreshold=Settings.DragTreshold)
and (DockOutsideMargin=Settings.DockOutsideMargin)
and (DockParentMargin=Settings.DockParentMargin)
and (PageAreaInPercent=Settings.PageAreaInPercent)
and (HeaderAlignTop=Settings.HeaderAlignTop)
and (HeaderAlignLeft=Settings.HeaderAlignLeft)
and (HeaderHint=Settings.HeaderHint)
and (SplitterWidth=Settings.SplitterWidth)
and (ScaleOnResize=Settings.ScaleOnResize)
and (ShowHeader=Settings.ShowHeader)
and (ShowHeaderCaption=Settings.ShowHeaderCaption)
and (HideHeaderCaptionFloatingControl=Settings.HideHeaderCaptionFloatingControl)
and (AllowDragging=Settings.AllowDragging)
and (HeaderStyle=Settings.HeaderStyle)
and (HeaderFlatten=Settings.HeaderFlatten)
and (HeaderFilled=Settings.HeaderFilled)
and (HeaderHighlightFocused=Settings.HeaderHighlightFocused)
;
end;
procedure TAnchorDockSettings.LoadFromConfig(Path: string;
Config: TRttiXMLConfig);
begin
DragTreshold:=Config.GetValue(Path+'DragThreshold',4);
DockOutsideMargin:=Config.GetValue(Path+'DockOutsideMargin',10);
DockParentMargin:=Config.GetValue(Path+'DockParentMargin',10);
PageAreaInPercent:=Config.GetValue(Path+'PageAreaInPercent',40);
HeaderAlignTop:=Config.GetValue(Path+'HeaderAlignTop',80);
HeaderAlignLeft:=Config.GetValue(Path+'HeaderAlignLeft',120);
SplitterWidth:=Config.GetValue(Path+'SplitterWidth',4);
ScaleOnResize:=Config.GetValue(Path+'ScaleOnResize',true);
ShowHeader:=Config.GetValue(Path+'ShowHeader',true);
ShowHeaderCaption:=Config.GetValue(Path+'ShowHeaderCaption',true);
HideHeaderCaptionFloatingControl:=Config.GetValue(Path+'HideHeaderCaptionFloatingControl',true);
AllowDragging:=Config.GetValue(Path+'AllowDragging',true);
HeaderStyle:=StrToADHeaderStyle(Config.GetValue(Path+'HeaderStyle',ADHeaderStyleNames[adhsDefault]));
HeaderFlatten:=Config.GetValue(Path+'HeaderFlatten',true);
HeaderFilled:=Config.GetValue(Path+'HeaderFilled',true);
HeaderHighlightFocused:=Config.GetValue(Path+'HeaderHighlightFocused',False);
end;
{ TAnchorDockMaster }
function TAnchorDockMaster.GetControls(Index: integer): TControl;
begin
Result:=TControl(FControls[Index]);
end;
function TAnchorDockMaster.GetLocalizedHeaderHint: string;
begin
if HeaderHint<>'' then
Result:=HeaderHint
else
Result:=adrsDragAndDockC;
end;
procedure TAnchorDockMaster.SetHeaderAlignLeft(const AValue: integer);
begin
if FHeaderAlignLeft=AValue then exit;
FHeaderAlignLeft:=AValue;
FHeaderAlignTop:=Min(FHeaderAlignLeft-1,FHeaderAlignTop);
OptionsChanged;
end;
procedure TAnchorDockMaster.SetHeaderAlignTop(const AValue: integer);
begin
if FHeaderAlignTop=AValue then exit;
FHeaderAlignTop:=AValue;
FHeaderAlignLeft:=Max(FHeaderAlignTop+1,FHeaderAlignLeft);
OptionsChanged;
end;
procedure TAnchorDockMaster.MarkCorrectlyLocatedControl(Tree: TAnchorDockLayoutTree);
var
Counter:integer;
function GetRealParent(Node:TAnchorDockLayoutTreeNode):TAnchorDockLayoutTreeNode;
begin
result := Node;
while Assigned(result.Parent) do begin
result := result.Parent;
fTreeNameToDocker[Node.Name];
if result.NodeType in [adltnControl,adltnCustomSite] then exit
end;
end;
function GetDockParent(Control: TControl): TControl;
begin
Control := Control.Parent;
while (Control <> nil) and (Control.Parent <> nil) do
begin
if not (Control is TAnchorDockHostSite) then
Break;
Control := Control.Parent;
end;
Result := Control;
end;
procedure RealChildrenCount(AWinControl:twincontrol;var realsubcontrolcoun:integer);
var
i:integer;
ACountedControl:tcontrol;
begin
for i:=0 to AWinControl.ControlCount-1 do
begin
ACountedControl:=AWinControl.Controls[i];
if not (ACountedControl is TAnchorDockHostSite) then
if not (ACountedControl is TAnchorDockHeader) then
if not (ACountedControl is TAnchorDockPageControl) then
if ACountedControl.IsVisible then
inc(realsubcontrolcoun);
if ACountedControl is TAnchorDockHostSite then
if ACountedControl.IsVisible then
RealChildrenCount(ACountedControl as TWinControl, realsubcontrolcoun);
end;
end;
function CheckNode(Node: TAnchorDockLayoutTreeNode; var ControlsCount: integer):TADLControlLocation;
var
i: Integer;
AControl,AParent: TControl;
SubControlsCount,realsubcontrolcoun: integer;
begin
if Node.IsSplitter then begin
inc(ControlsCount);
exit(adlclCorrect);
end
else if Node=Tree.Root then begin
result:=adlclCorrect;
AControl:=nil;
AParent:=nil;
end
else begin
AControl:=FindControl(Node.Name);
AParent:=FindControl(GetRealParent(Node).Name);
if Node.NodeType=adltnLayout then result:=adlclCorrect
else if AControl is TAnchorDockPanel then result:=adlclCorrect
else if AControl=nil then result:=adlclWrongly
else if GetDockParent(AControl)<>AParent then result:=adlclWrongly
else
begin
end;
end;
if AControl<>nil then
if not (AControl is TAnchorDockHostSite) then
inc(ControlsCount);
if result=adlclWrongly then exit;
if AControl=nil then AControl:=AParent;
SubControlsCount:=0;
for i:=0 to Node.Count-1 do
begin
result:=CheckNode(Node[i],SubControlsCount);
if result=adlclWrongly then exit;
end;
realsubcontrolcoun:=0;
if (AControl is TAnchorDockHostSite)or(AControl is TAnchorDockPanel) then
begin
RealChildrenCount(AControl as TWinControl,realsubcontrolcoun);
if SubControlsCount<>realsubcontrolcoun then Exit(adlclWrongly);
end;
ControlsCount:=ControlsCount+SubControlsCount;
if result=adlclWrongly then exit;
for i:=0 to Node.Count-1 do
begin
Node[i].ControlLocation:=adlclCorrect;
end;
end;
begin
//We need compare dock tree and fact controls placement
//and mark controls which location is coincides with tree
//these controls can be not closrd in CloseUnneededAndWronglyLocatedControls
Counter:=0;
Tree.Root.ControlLocation:=CheckNode(Tree.Root,Counter);
end;
function TAnchorDockMaster.CloseUnneededAndWronglyLocatedControls(Tree: TAnchorDockLayoutTree
): boolean;
function GetParentAnchorDockPageControl(thisControl: TControl):TAnchorDockPageControl;
begin
while thisControl<>nil do
begin
if thisControl is TAnchorDockPageControl then
exit(thisControl as TAnchorDockPageControl);
thisControl:=thisControl.Parent;
end;
result:=nil;
end;
var
i: Integer;
AControl: TControl;
TreeNodeControl: TAnchorDockLayoutTreeNode;
ParentAnchorDockPageControl:TAnchorDockPageControl;
begin
i:=ControlCount-1;
while i>=0 do begin
AControl:=Controls[i];
TreeNodeControl:=Tree.Root.FindChildNode(AControl.Name,true);
if DockedControlIsVisible(AControl)
and (Application.MainForm<>AControl)
and (not(AControl is TAnchorDockPanel))
and ((Tree.Root.FindChildNode(AControl.Name,true)=nil)
or (TreeNodeControl.ControlLocation=adlclWrongly)) then begin
ParentAnchorDockPageControl:=GetParentAnchorDockPageControl(AControl);
DisableControlAutoSizing(AControl);
// AControl is currently on a visible site, but not in the Tree
// => close site
if AControl.HostDockSite <> nil then
begin
debugln(['TAnchorDockMaster.CloseUnneededControls Control=',DbgSName(AControl),' Site=',AControl.HostDockSite.Name]);
if AControl.HostDockSite is TAnchorDockHostSite then begin
if not TAnchorDockHostSite(AControl.HostDockSite).CloseSite then begin
if FControls.IndexOf(AControl)<0 then
AControl:=nil;
debugln(['TAnchorDockMaster.CloseUnneededControls CloseSite failed Control=',DbgSName(AControl)]);
exit(false);
end;
end;
end;
if FControls.IndexOf(AControl)>=0 then begin
// the control is still there
if AControl.HostDockSite<>nil then begin
AControl.HostDockSite.Visible:=false;
AControl.HostDockSite.Parent:=nil;
end else begin
AControl.Visible:=False;
AControl.Parent:=nil;
end;
end;
if ParentAnchorDockPageControl<>nil then
if ParentAnchorDockPageControl.Parent<>nil then
ParentAnchorDockPageControl.Parent.Free;
end;
i:=Min(i,ControlCount)-1;
end;
Result:=true;
end;
function TAnchorDockMaster.CreateNeededControls(Tree: TAnchorDockLayoutTree;
DisableAutoSizing: boolean; ControlNames: TStrings): boolean;
procedure CreateControlsForNode(Node: TAnchorDockLayoutTreeNode);
var
i: Integer;
AControl: TControl;
begin
if (Node.NodeType in [adltnControl,adltnCustomSite])
and (Node.Name<>'') then begin
AControl:=FindControl(Node.Name);
if AControl<>nil then begin
//debugln(['CreateControlsForNode ',Node.Name,' already exists']);
if DisableAutoSizing then
DisableControlAutoSizing(AControl);
end else begin
//debugln(['CreateControlsForNode ',Node.Name,' needs creation']);
AControl:=DoCreateControl(Node.Name,true);
if AControl<>nil then begin
try
if DisableAutoSizing and (fDisabledAutosizing.IndexOf(AControl)<0)
then begin
fDisabledAutosizing.Add(AControl);
AControl.FreeNotification(Self);
end;
if Node.NodeType=adltnControl then
MakeDockable(AControl,false)
else if not IsCustomSite(AControl) then
raise EAnchorDockLayoutError.Create('not a docksite: '+DbgSName(AControl));
finally
if not DisableAutoSizing then
AControl.EnableAutoSizing{$IFDEF DebugDisableAutoSizing}(ADAutoSizingReason){$ENDIF};
end;
end else begin
debugln(['CreateControlsForNode ',Node.Name,' failed to create']);
end;
end;
if AControl<>nil then
ControlNames.Add(AControl.Name);
end;
for i:=0 to Node.Count-1 do
CreateControlsForNode(Node[i]);
end;
begin
Result:=false;
CreateControlsForNode(Tree.Root);
Result:=true;
end;
procedure TAnchorDockMaster.MapTreeToControls(Tree: TAnchorDockLayoutTree);
procedure MapHostDockSites(Node: TAnchorDockLayoutTreeNode);
// map in TreeNameToDocker each control name to its HostDockSite or custom dock site
var
i: Integer;
AControl: TControl;
begin
if Node.IsSplitter then exit;
if (Node.NodeType=adltnControl) then begin
AControl:=FindControl(Node.Name);
if (AControl<>nil) and (AControl.HostDockSite is TAnchorDockHostSite) then
fTreeNameToDocker[Node.Name]:=AControl.HostDockSite;
// ignore kids
exit;
end;
if (Node.NodeType=adltnCustomSite) then begin
AControl:=FindControl(Node.Name);
if IsCustomSite(AControl) or (AControl is TAnchorDockPanel) then
fTreeNameToDocker[Node.Name]:=AControl;
end;
for i:=0 to Node.Count-1 do
MapHostDockSites(Node[i]); // recursive
end;
procedure MapTopLevelSites(Node: TAnchorDockLayoutTreeNode);
// map in TreeNameToDocker each RootWindow node name to a site with a
// corresponding control
// For example: if there is control on a complex site (SiteA), and the control
// has a node in the Tree, then the root node of the tree node is mapped to
// the SiteA. This way the corresponding root forms are kept which reduces
// flickering.
function FindMappedControl(ChildNode: TAnchorDockLayoutTreeNode): TCustomForm;
var
i: Integer;
begin
if ChildNode.NodeType in [adltnControl,adltnCustomSite] then
Result:=TCustomForm(fTreeNameToDocker[ChildNode.Name])
else
for i:=0 to ChildNode.Count-1 do begin
Result:=FindMappedControl(ChildNode[i]); // search recursive
if Result<>nil then exit;
end;
end;
var
i: Integer;
RootSite: TCustomForm;
Site: TCustomForm;
begin
if Node.IsSplitter then exit;
if Node.IsRootWindow then begin
if Node.Name='' then exit;
if Node.NodeType=adltnControl then exit;
// Node is a complex site
if fTreeNameToDocker[Node.Name]<>nil then exit;
// and not yet mapped to a site
Site:=FindMappedControl(Node);
if Site=nil then exit;
// and there is sub node mapped to a site (anchor or custom)
RootSite:=GetParentForm(Site);
if not (RootSite is TAnchorDockHostSite) then exit;
// and the mapped site has a root site
if fTreeNameToDocker.ControlToName(RootSite)<>'' then exit;
// and the root site is not yet mapped
// => map the root node to the root site
fTreeNameToDocker[Node.Name]:=RootSite;
end else
for i:=0 to Node.Count-1 do
MapTopLevelSites(Node[i]); // recursive
end;
procedure MapBottomUp(Node: TAnchorDockLayoutTreeNode);
{ map the other nodes to existing sites
The heuristic works like this:
if a child node was mapped to a site and the site has a parent site then
map this node to this parent site.
}
var
i: Integer;
BestSite: TControl;
begin
if Node.IsSplitter then exit;
BestSite:=fTreeNameToDocker[Node.Name];
for i:=0 to Node.Count-1 do begin
MapBottomUp(Node[i]); // recursive
if BestSite=nil then
BestSite:=fTreeNameToDocker[Node[i].Name];
end;
if (fTreeNameToDocker[Node.Name]=nil) and (BestSite<>nil) then begin
// search the parent site of a child site
repeat
if BestSite is TAnchorDockPanel then begin
if fTreeNameToDocker.ControlToName(BestSite)='' then
fTreeNameToDocker[Node.Name]:=BestSite;
break;
end;
BestSite:=BestSite.Parent;
if BestSite is TAnchorDockHostSite then begin
if fTreeNameToDocker.ControlToName(BestSite)='' then
fTreeNameToDocker[Node.Name]:=BestSite;
break;
end;
until (BestSite=nil);
end;
end;
procedure MapSplitters(Node: TAnchorDockLayoutTreeNode);
{ map the splitter nodes to existing splitters
The heuristic works like this:
If a node is mapped to a site and the node is at Side anchored to a
splitter node and the site is anchored at Side to a splitter
then map the splitter node to the splitter.
}
var
i: Integer;
Side: TAnchorKind;
Site: TControl;
SplitterNode: TAnchorDockLayoutTreeNode;
Splitter: TControl;
begin
if Node.IsSplitter then exit;
for i:=0 to Node.Count-1 do
MapSplitters(Node[i]); // recursive
if Node.Parent=nil then exit;
// node is a child node
Site:=fTreeNameToDocker[Node.Name];
if Site=nil then exit;
// node is mapped to a site
// check each side
for Side:=Low(TAnchorKind) to high(TAnchorKind) do begin
if Node.Anchors[Side]='' then continue;
Splitter:=Site.AnchorSide[Side].Control;
if (not (Splitter is TAnchorDockSplitter))
or (Splitter.Parent<>Site.Parent) then continue;
SplitterNode:=Node.Parent.FindChildNode(Node.Anchors[Side],false);
if (SplitterNode=nil) then continue;
// this Side of node is anchored to a splitter node
if fTreeNameToDocker[SplitterNode.Name]<>nil then continue;
// the SplitterNode is not yet mapped
if fTreeNameToDocker.ControlToName(Splitter)<>'' then continue;
// there is an unmapped splitter anchored to the Site
// => map the splitter to the splitter node
// Note: Splitter.Name can be different from SplitterNode.Name !
fTreeNameToDocker[SplitterNode.Name]:=Splitter;
end;
end;
begin
MapHostDockSites(Tree.Root);
MapTopLevelSites(Tree.Root);
MapBottomUp(Tree.Root);
MapSplitters(Tree.Root);
end;
function SrcRectValid(const r: TRect): boolean;
begin
Result:=(r.Left<r.Right) and (r.Top<r.Bottom);
end;
function TAnchorDockMaster.ScaleTopLvlX(p: integer): integer;
begin
Result:=p;
if SrcRectValid(SrcWorkArea) and SrcRectValid(WorkArea) then
Result:=((p-SrcWorkArea.Left)*(WorkArea.Right-WorkArea.Left))
div (SrcWorkArea.Right-SrcWorkArea.Left)
+WorkArea.Left;
end;
function TAnchorDockMaster.ScaleTopLvlY(p: integer): integer;
begin
Result:=p;
if SrcRectValid(SrcWorkArea) and SrcRectValid(WorkArea) then
Result:=((p-SrcWorkArea.Top)*(WorkArea.Bottom-WorkArea.Top))
div (SrcWorkArea.Bottom-SrcWorkArea.Top)
+WorkArea.Top;
end;
function TAnchorDockMaster.ScaleChildX(p: integer): integer;
begin
Result:=p;
if SrcRectValid(SrcWorkArea) and SrcRectValid(WorkArea) then
Result:=p*(WorkArea.Right-WorkArea.Left)
div (SrcWorkArea.Right-SrcWorkArea.Left);
end;
function TAnchorDockMaster.ScaleChildY(p: integer): integer;
begin
Result:=p;
if SrcRectValid(SrcWorkArea) and SrcRectValid(WorkArea) then
Result:=p*(WorkArea.Bottom-WorkArea.Top)
div (SrcWorkArea.Bottom-SrcWorkArea.Top);
end;
procedure TAnchorDockMaster.SetupSite(Site: TWinControl;
ANode: TAnchorDockLayoutTreeNode; AParent: TWinControl);
var
aManager: TAnchorDockManager;
NewBounds: TRect;
aMonitor: TMonitor;
aHostSite: TAnchorDockHostSite;
begin
if Site is TCustomForm then begin
Site.Align:=alNone;
if AParent=nil then
TCustomForm(Site).WindowState:=ANode.WindowState
else
TCustomForm(Site).WindowState:=wsNormal;
end else
GetParentForm(Site).WindowState:=ANode.WindowState;
if Site is TAnchorDockPanel then
GetParentForm(Site).BoundsRect:=ANode.BoundsRect
else begin
if AParent=nil then begin
if (ANode.Monitor>=0) and (ANode.Monitor<Screen.MonitorCount) then
aMonitor:=Screen.Monitors[ANode.Monitor]
else begin
if Site is TCustomForm then
aMonitor:=TCustomForm(Site).Monitor
else
aMonitor:=GetParentForm(Site).Monitor;
end;
WorkArea:=aMonitor.WorkareaRect;
{$IFDEF VerboseAnchorDockRestore}
debugln(['TAnchorDockMaster.RestoreLayout.SetupSite WorkArea=',dbgs(WorkArea)]);
{$ENDIF}
end;
end;
if IsCustomSite(Site) then begin
aManager:=TAnchorDockManager(Site.DockManager);
if ANode.Count>0 then begin
// this custom dock site gets a child => store and clear constraints
aManager.StoreConstraints;
end;
end;
Site.Constraints.MaxWidth:=0;
Site.Constraints.MaxHeight:=0;
NewBounds:=ANode.BoundsRect;
if AParent=nil then begin
NewBounds:=Rect(ScaleTopLvlX(NewBounds.Left),ScaleTopLvlY(NewBounds.Top),
ScaleTopLvlX(NewBounds.Right),ScaleTopLvlY(NewBounds.Bottom));
end else begin
if AParent is TAnchorDockPanel then
begin
NewBounds:=Rect(0,0,AParent.ClientWidth,AParent.ClientHeight);
Site.Align:=alClient;
end
else
NewBounds:=Rect(ScaleChildX(NewBounds.Left), ScaleChildY(NewBounds.Top),
ScaleChildX(NewBounds.Right),ScaleChildY(NewBounds.Bottom));
end;
{$IFDEF VerboseAnchorDockRestore}
//if Scale then
debugln(['TAnchorDockMaster.RestoreLayout.SetupSite scale Site=',DbgSName(Site),' Caption="',Site.Caption,'" OldWorkArea=',dbgs(SrcWorkArea),' CurWorkArea=',dbgs(WorkArea),' OldBounds=',dbgs(aNode.BoundsRect),' NewBounds=',dbgs(NewBounds)]);
{$ENDIF}
Site.Visible:=true;
if not (Site is TAnchorDockPanel) then
begin
Site.BoundsRect:=NewBounds;
Site.Parent:=AParent;
end;
if IsCustomSite(AParent) then begin
aManager:=TAnchorDockManager(AParent.DockManager);
Site.Align:=ANode.Align;
{$IFDEF VerboseAnchorDockRestore}
debugln(['TAnchorDockMaster.RestoreLayout.SetupSite custom Site=',DbgSName(Site),' Site.Bounds=',dbgs(Site.BoundsRect),' BoundSplitterPos=',aNode.BoundSplitterPos]);
{$ENDIF}
aManager.RestoreSite(ANode.BoundSplitterPos);
Site.HostDockSite:=AParent;
end;
if Site is TAnchorDockHostSite then begin
aHostSite:=TAnchorDockHostSite(Site);
aHostSite.Header.HeaderPosition:=ANode.HeaderPosition;
aHostSite.DockRestoreBounds:=NewBounds;
if (ANode.NodeType<>adltnPages) and (aHostSite.Pages<>nil) then
aHostSite.FreePages;
end;
end;
function TAnchorDockMaster.GetNodeSite(Node: TAnchorDockLayoutTreeNode): TAnchorDockHostSite;
var
Site: TControl;
begin
Site:=fTreeNameToDocker[Node.Name];
if Site is TAnchorDockHostSite then
exit(TAnchorDockHostSite(Site));
if Site<>nil then
exit(nil);
Result:=CreateSite;
fDisabledAutosizing.Add(Result);
fTreeNameToDocker[Node.Name]:=Result;
end;
function TAnchorDockMaster.RestoreLayout(Tree: TAnchorDockLayoutTree;
Scale: boolean): boolean;
function Restore(ANode: TAnchorDockLayoutTreeNode; AParent: TWinControl): TControl;
var
AControl: TControl;
Site: TAnchorDockHostSite;
Splitter: TAnchorDockSplitter;
i, j: Integer;
Side: TAnchorKind;
AnchorControl: TControl;
ChildNode: TAnchorDockLayoutTreeNode;
NewBounds: TRect;
aPageName: String;
aPage: TCustomPage;
begin
Result:=nil;
if Scale and SrcRectValid(ANode.WorkAreaRect) then
SrcWorkArea:=ANode.WorkAreaRect;
{$IFDEF VerboseAnchorDockRestore}
debugln(['TAnchorDockMaster.RestoreLayout.Restore Node="',aNode.Name,'" ',dbgs(aNode.NodeType),' Bounds=',dbgs(aNode.BoundsRect),' Parent=',DbgSName(aParent),' ']);
{$ENDIF}
AControl:=nil;
if ANode.NodeType in [adltnControl, adltnCustomSite] then
begin
AControl:=FindControl(ANode.Name);
if AControl=nil then begin
debugln(['TAnchorDockMaster.RestoreLayout.Restore WARNING: can not find control ',ANode.Name,
', NodeType=', ANode.NodeType]);
exit;
end;
end;
if ANode.NodeType=adltnControl then begin
// restore control
// the control was already created => dock it
DisableControlAutoSizing(AControl);
if AControl.HostDockSite=nil then
MakeDockable(AControl,false)
else
ClearLayoutProperties(AControl);
{$IFDEF VerboseAnchorDockRestore}
debugln(['TAnchorDockMaster.RestoreLayout.Restore Control Node.Name=',aNode.Name,
' Control=',DbgSName(AControl),' Site=',DbgSName(AControl.HostDockSite)]);
{$ENDIF}
AControl.Visible:=true;
SetupSite(AControl.HostDockSite,ANode,AParent);
Result:=AControl.HostDockSite;
end
else if ANode.NodeType=adltnCustomSite then begin
// restore custom dock site
// the control was already created => position it
if not (IsCustomSite(AControl) or (AControl is TAnchorDockPanel)) then begin
debugln(['TAnchorDockMaster.RestoreLayout.Restore WARNING: ',ANode.Name,' is not a custom dock site ',DbgSName(AControl)]);
exit;
end;
DisableControlAutoSizing(AControl);
SetupSite(TCustomForm(AControl),ANode,nil);
Result:=AControl;
// restore docked site
if ANode.Count>0 then
Restore(ANode[0],TCustomForm(AControl));
end
else if ANode.IsSplitter then begin
// restore splitter
Splitter:=TAnchorDockSplitter(fTreeNameToDocker[ANode.Name]);
if Splitter=nil then begin
Splitter:=CreateSplitter;
fTreeNameToDocker[ANode.Name]:=Splitter;
end;
{$IFDEF VerboseAnchorDockRestore}
debugln(['TAnchorDockMaster.RestoreLayout.Restore Splitter Node.Name=',aNode.Name,' ',dbgs(aNode.NodeType),' Splitter=',DbgSName(Splitter)]);
{$ENDIF}
Splitter.Parent:=AParent;
NewBounds:=ANode.BoundsRect;
if SrcRectValid(SrcWorkArea) then
NewBounds:=Rect(ScaleChildX(NewBounds.Left),ScaleChildY(NewBounds.Top),
ScaleChildX(NewBounds.Right),ScaleChildY(NewBounds.Bottom));
Splitter.DockRestoreBounds:=NewBounds;
Splitter.BoundsRect:=NewBounds;
if ANode.NodeType=adltnSplitterVertical then begin
Splitter.ResizeAnchor:=akLeft;
Splitter.AnchorSide[akLeft].Control:=nil;
Splitter.AnchorSide[akRight].Control:=nil;
end else begin
Splitter.ResizeAnchor:=akTop;
Splitter.AnchorSide[akTop].Control:=nil;
Splitter.AnchorSide[akBottom].Control:=nil;
end;
Result:=Splitter;
Application.QueueAsyncCall(@Splitter.AsyncUpdateDockBounds,0);
end else if ANode.NodeType=adltnLayout then begin
// restore layout
Site:=GetNodeSite(ANode);
{$IFDEF VerboseAnchorDockRestore}
debugln(['TAnchorDockMaster.RestoreLayout.Restore Layout Node.Name=',aNode.Name,' ChildCount=',aNode.Count]);
{$ENDIF}
Site.BeginUpdateLayout;
try
SetupSite(Site,ANode,AParent);
Site.FSiteType:=adhstLayout;
Site.Header.Parent:=nil;
// create children
for i:=0 to ANode.Count-1 do
Restore(ANode[i],Site);
// anchor children
for i:=0 to ANode.Count-1 do begin
ChildNode:=ANode[i];
AControl:=fTreeNameToDocker[ChildNode.Name];
{$IFDEF VerboseAnchorDockRestore}
debugln([' Restore layout child anchors Site=',DbgSName(Site),' ChildNode.Name=',ChildNode.Name,' Control=',DbgSName(AControl)]);
{$ENDIF}
if AControl=nil then continue;
for Side:=Low(TAnchorKind) to high(TAnchorKind) do begin
if ((ChildNode.NodeType=adltnSplitterHorizontal)
and (Side in [akTop,akBottom]))
or ((ChildNode.NodeType=adltnSplitterVertical)
and (Side in [akLeft,akRight]))
then continue;
AnchorControl:=nil;
if ChildNode.Anchors[Side]<>'' then begin
AnchorControl:=fTreeNameToDocker[ChildNode.Anchors[Side]];
if AnchorControl=nil then
debugln(['WARNING: TAnchorDockMaster.RestoreLayout.Restore: Node=',ChildNode.Name,' Anchor[',dbgs(Side),']=',ChildNode.Anchors[Side],' not found']);
end;
if AnchorControl<>nil then
AControl.AnchorToNeighbour(Side,0,AnchorControl)
else
AControl.AnchorParallel(Side,0,Site);
end;
end;
// free unneeded helper controls (e.g. splitters)
for i:=Site.ControlCount-1 downto 0 do begin
AControl:=Site.Controls[i];
if fTreeNameToDocker.ControlToName(AControl)<>'' then continue;
if AControl is TAnchorDockSplitter then begin
AControl.Free;
end;
end;
finally
Site.EndUpdateLayout;
end;
Result:=Site;
end else if ANode.NodeType=adltnPages then begin
// restore pages
Site:=GetNodeSite(ANode);
{$IFDEF VerboseAnchorDockRestore}
debugln(['TAnchorDockMaster.RestoreLayout.Restore Pages Node.Name=',aNode.Name,' ChildCount=',aNode.Count]);
{$ENDIF}
Site.BeginUpdateLayout;
j:=0;
try
SetupSite(Site,ANode,AParent);
Site.FSiteType:=adhstPages;
Site.Header.Parent:=nil;
if Site.Pages=nil then
Site.CreatePages;
Site.Pages.TabPosition:=ANode.TabPosition;
for i:=0 to ANode.Count-1 do begin
aPageName:=ANode[i].Name;
if j>=Site.Pages.PageCount then
Site.Pages.Pages.Add(aPageName);
aPage:=Site.Pages.Page[j];
inc(j);
AControl:=Restore(ANode[i],aPage);
if AControl=nil then continue;
AControl.Align:=alClient;
for Side:=Low(TAnchorKind) to high(TAnchorKind) do
AControl.AnchorSide[Side].Control:=nil;
end;
Site.Pages.PageIndex:=ANode.PageIndex;
finally
while Site.Pages.PageCount>j do
Site.Pages.Page[Site.Pages.PageCount-1].Free;
Site.SimplifyPages;
Site.EndUpdateLayout;
end;
Result:=Site;
end else begin
// create children
for i:=0 to ANode.Count-1 do
Restore(ANode[i],AParent);
end;
end;
begin
Result:=true;
WorkArea:=Rect(0,0,0,0);
SrcWorkArea:=WorkArea;
Restore(Tree.Root,nil);
Restoring:=true;
end;
function TAnchorDockMaster.DoCreateControl(aName: string;
DisableAutoSizing: boolean): TControl;
begin
Result:=nil;
OnCreateControl(Self,aName,Result,DisableAutoSizing);
if Result=nil then
debugln(['TAnchorDockMaster.DoCreateControl WARNING: control not found: "',aName,'"']);
if (Result<>nil) and (Result.Name<>aName) then
raise Exception.Create('TAnchorDockMaster.DoCreateControl'+Format(
adrsRequestedButCreated, [aName, Result.Name]));
end;
procedure TAnchorDockMaster.DisableControlAutoSizing(AControl: TControl);
begin
if fDisabledAutosizing.IndexOf(AControl)>=0 then exit;
//debugln(['TAnchorDockMaster.DisableControlAutoSizing ',DbgSName(AControl)]);
fDisabledAutosizing.Add(AControl);
AControl.FreeNotification(Self);
AControl.DisableAutoSizing{$IFDEF DebugDisableAutoSizing}(ADAutoSizingReason){$ENDIF};
end;
procedure TAnchorDockMaster.EnableAllAutoSizing;
var
i: Integer;
AControl: TControl;
begin
i:=fDisabledAutosizing.Count-1;
while (i>=0) do begin
AControl:=TControl(fDisabledAutosizing[i]);
//debugln(['TAnchorDockMaster.EnableAllAutoSizing ',DbgSName(AControl)]);
fDisabledAutosizing.Delete(i);
AControl.EnableAutoSizing{$IFDEF DebugDisableAutoSizing}(ADAutoSizingReason){$ENDIF};
i:=Min(i,fDisabledAutosizing.Count)-1;
end;
end;
procedure TAnchorDockMaster.ClearLayoutProperties(AControl: TControl;
NewAlign: TAlign);
var
a: TAnchorKind;
begin
AControl.AutoSize:=false;
AControl.Align:=NewAlign;
AControl.BorderSpacing.Around:=0;
AControl.BorderSpacing.Left:=0;
AControl.BorderSpacing.Top:=0;
AControl.BorderSpacing.Right:=0;
AControl.BorderSpacing.Bottom:=0;
AControl.BorderSpacing.InnerBorder:=0;
for a:=Low(TAnchorKind) to High(TAnchorKind) do
AControl.AnchorSide[a].Control:=nil;
end;
procedure TAnchorDockMaster.PopupMenuPopup(Sender: TObject);
var
Popup: TPopupMenu;
ChangeLockItem: TMenuItem;
ShowHeadersItem: TMenuItem;
begin
if not (Sender is TPopupMenu) then exit;
Popup:=TPopupMenu(Sender);
Popup.Items.Clear;
// top popup menu item can be clicked by accident, so use something simple:
// lock/unlock
ChangeLockItem:=AddPopupMenuItem('AnchorDockMasterChangeLockMenuItem',
adrsLocked,@ChangeLockButtonClick);
ChangeLockItem.Checked:=not AllowDragging;
ChangeLockItem.ShowAlwaysCheckable:=true;
if Popup.PopupComponent is TAnchorDockHeader then
TAnchorDockHeader(Popup.PopupComponent).PopupMenuPopup(Sender)
else if Popup.PopupComponent is TAnchorDockPageControl then
TAnchorDockPageControl(Popup.PopupComponent).PopupMenuPopup(Sender)
else if Popup.PopupComponent is TAnchorDockSplitter then
TAnchorDockSplitter(Popup.PopupComponent).PopupMenuPopup(Sender);
if ShowMenuItemShowHeader or (not ShowHeader) then begin
ShowHeadersItem:=AddPopupMenuItem('AnchorDockMasterShowHeaderMenuItem',
adrsShowHeaders, @ShowHeadersButtonClick);
ShowHeadersItem.Checked:=ShowHeader;
ShowHeadersItem.ShowAlwaysCheckable:=true;
end;
if Assigned(OnShowOptions) then
AddPopupMenuItem('OptionsMenuItem', adrsDockingOptions, @OptionsClick);
end;
procedure TAnchorDockMaster.ResetSplitters;
var
I: Integer;
S: TAnchorDockSplitter;
begin
for I := 0 to ComponentCount-1 do
if Components[I] is TAnchorDockSplitter then
begin
S := TAnchorDockSplitter(Components[I]);
S.UpdateDockBounds;
S.UpdatePercentPosition;
end;
end;
function TAnchorDockMaster.FullRestoreLayout(Tree: TAnchorDockLayoutTree;
Scale: Boolean): Boolean;
var
ControlNames: TStringList;
begin
Result:=false;
ControlNames:=TStringList.Create;
fTreeNameToDocker:=TADNameToControl.Create;
try
// close all unneeded and wrongly allocated forms/controls (not helper controls like splitters)
MarkCorrectlyLocatedControl(Tree);
if not CloseUnneededAndWronglyLocatedControls(Tree) then exit;
BeginUpdate;
try
// create all needed forms/controls (not helper controls like splitters)
if not CreateNeededControls(Tree,true,ControlNames) then exit;
// simplify layouts
ControlNames.Sort;
{$IFDEF VerboseAnchorDockRestore}
debugln(['TAnchorDockMaster.LoadLayoutFromConfig controls: ']);
debugln(ControlNames.Text);
{$ENDIF}
// if some forms/controls could not be created the layout needs to be adapted
Tree.Root.Simplify(ControlNames);
// reuse existing sites to reduce flickering
MapTreeToControls(Tree);
{$IFDEF VerboseAnchorDockRestore}
fTreeNameToDocker.WriteDebugReport('TAnchorDockMaster.LoadLayoutFromConfig Map');
{$ENDIF}
// create sites, move controls
RestoreLayout(Tree,Scale);
finally
EndUpdate;
end;
finally
// clean up
FreeAndNil(fTreeNameToDocker);
ControlNames.Free;
// commit (this can raise an exception, when it triggers events)
EnableAllAutoSizing;
end;
ResetSplitters; // reset splitters' DockBounds after EnableAllAutoSizing. fixes issue #18538
{$IFDEF VerboseAnchorDockRestore}
DebugWriteChildAnchors(Application.MainForm,true,false);
{$ENDIF}
Result:=true;
end;
procedure TAnchorDockMaster.SetHideHeaderCaptionFloatingControl(
const AValue: boolean);
var
Site: TAnchorDockHostSite;
i: Integer;
begin
if AValue=HideHeaderCaptionFloatingControl then exit;
fHideHeaderCaptionFloatingControl:=AValue;
for i:=0 to ComponentCount-1 do begin
Site:=TAnchorDockHostSite(Components[i]);
if not (Site is TAnchorDockHostSite) then continue;
Site.UpdateDockCaption;
end;
OptionsChanged;
end;
procedure TAnchorDockMaster.SetSplitterWidth(const AValue: integer);
var
i: Integer;
Splitter: TAnchorDockSplitter;
begin
if (AValue<1) or (AValue=SplitterWidth) then exit;
FSplitterWidth:=AValue;
for i:=0 to ComponentCount-1 do begin
Splitter:=TAnchorDockSplitter(Components[i]);
if not (Splitter is TAnchorDockSplitter) then continue;
if not Splitter.CustomWidth then
begin
if Splitter.ResizeAnchor in [akLeft,akRight] then
Splitter.Width:=SplitterWidth
else
Splitter.Height:=SplitterWidth;
end;
end;
OptionsChanged;
end;
procedure TAnchorDockMaster.OnIdle(Sender: TObject; var Done: Boolean);
begin
if Done then ;
IdleConnected:=false;
Restoring:=false;
end;
procedure TAnchorDockMaster.AsyncSimplify(Data: PtrInt);
begin
FQueueSimplify:=false;
SimplifyPendingLayouts;
end;
procedure TAnchorDockMaster.ChangeLockButtonClick(Sender: TObject);
begin
AllowDragging:=not AllowDragging;
end;
procedure TAnchorDockMaster.SetAllowDragging(AValue: boolean);
begin
if FAllowDragging=AValue then Exit;
FAllowDragging:=AValue;
OptionsChanged;
end;
procedure TAnchorDockMaster.SetDockOutsideMargin(AValue: integer);
begin
if FDockOutsideMargin=AValue then Exit;
FDockOutsideMargin:=AValue;
OptionsChanged;
end;
procedure TAnchorDockMaster.SetDockParentMargin(AValue: integer);
begin
if FDockParentMargin=AValue then Exit;
FDockParentMargin:=AValue;
OptionsChanged;
end;
procedure TAnchorDockMaster.SetDragTreshold(AValue: integer);
begin
if FDragTreshold=AValue then Exit;
FDragTreshold:=AValue;
OptionsChanged;
end;
procedure TAnchorDockMaster.SetHeaderHint(AValue: string);
begin
if FHeaderHint=AValue then Exit;
FHeaderHint:=AValue;
OptionsChanged;
end;
procedure TAnchorDockMaster.SetHeaderStyle(AValue: TADHeaderStyle);
begin
if FHeaderStyle=AValue then Exit;
FHeaderStyle:=AValue;
OptionsChanged;
InvalidateHeaders;
end;
procedure TAnchorDockMaster.SetPageAreaInPercent(AValue: integer);
begin
if FPageAreaInPercent=AValue then Exit;
FPageAreaInPercent:=AValue;
OptionsChanged;
end;
procedure TAnchorDockMaster.SetHeaderFlatten(AValue: boolean);
begin
if FHeaderFlatten=AValue then Exit;
FHeaderFlatten:=AValue;
OptionsChanged;
InvalidateHeaders;
end;
procedure TAnchorDockMaster.SetHeaderFilled(AValue: boolean);
begin
if FHeaderFilled=AValue then Exit;
FHeaderFilled:=AValue;
OptionsChanged;
InvalidateHeaders;
end;
procedure TAnchorDockMaster.SetHeaderHighlightFocused(AValue: boolean);
begin
if FHeaderHighlightFocused=AValue then Exit;
FHeaderHighlightFocused:=AValue;
OptionsChanged;
InvalidateHeaders;
end;
procedure TAnchorDockMaster.SetScaleOnResize(AValue: boolean);
begin
if FScaleOnResize=AValue then Exit;
FScaleOnResize:=AValue;
OptionsChanged;
end;
procedure TAnchorDockMaster.SetShowMenuItemShowHeader(AValue: boolean);
begin
if FShowMenuItemShowHeader=AValue then Exit;
FShowMenuItemShowHeader:=AValue;
OptionsChanged;
end;
procedure TAnchorDockMaster.ShowHeadersButtonClick(Sender: TObject);
begin
ShowHeader:=not ShowHeader;
end;
procedure TAnchorDockMaster.OptionsClick(Sender: TObject);
begin
if Assigned(OnShowOptions) then OnShowOptions(Self);
end;
procedure TAnchorDockMaster.SetIdleConnected(const AValue: Boolean);
begin
if FIdleConnected=AValue then exit;
FIdleConnected:=AValue;
if IdleConnected then
Application.AddOnIdleHandler(@OnIdle,true)
else
Application.RemoveOnIdleHandler(@OnIdle);
end;
procedure TAnchorDockMaster.SetQueueSimplify(const AValue: Boolean);
begin
if FQueueSimplify=AValue then exit;
FQueueSimplify:=AValue;
if FQueueSimplify then
Application.QueueAsyncCall(@AsyncSimplify,0)
else
Application.RemoveAsyncCalls(Self);
end;
procedure TAnchorDockMaster.SetRestoring(const AValue: boolean);
var
AComponent: TComponent;
i: Integer;
begin
if FRestoring=AValue then exit;
FRestoring:=AValue;
if FRestoring then begin
IdleConnected:=true;
end else begin
for i:=0 to ComponentCount-1 do begin
AComponent:=Components[i];
if AComponent is TAnchorDockHostSite then
TAnchorDockHostSite(AComponent).DockRestoreBounds:=Rect(0,0,0,0)
else if AComponent is TAnchorDockSplitter then
TAnchorDockSplitter(AComponent).DockRestoreBounds:=Rect(0,0,0,0)
end;
end;
end;
procedure TAnchorDockMaster.OptionsChanged;
begin
IncreaseOptionsChangeStamp;
if Assigned(OnOptionsChanged) then
OnOptionsChanged(Self);
end;
procedure TAnchorDockMaster.SetShowHeader(AValue: boolean);
var
i: Integer;
Site: TAnchorDockHostSite;
begin
if FShowHeader=AValue then exit;
FShowHeader:=AValue;
for i:=0 to ComponentCount-1 do begin
Site:=TAnchorDockHostSite(Components[i]);
if not (Site is TAnchorDockHostSite) then continue;
if (Site.Header<>nil) then begin
DisableControlAutoSizing(Site);
Site.UpdateHeaderShowing;
end;
end;
EnableAllAutoSizing;
OptionsChanged;
end;
procedure TAnchorDockMaster.SetShowHeaderCaption(const AValue: boolean);
var
i: Integer;
Site: TAnchorDockHostSite;
begin
if FShowHeaderCaption=AValue then exit;
FShowHeaderCaption:=AValue;
for i:=0 to ComponentCount-1 do begin
Site:=TAnchorDockHostSite(Components[i]);
if not (Site is TAnchorDockHostSite) then continue;
Site.UpdateDockCaption;
end;
OptionsChanged;
end;
procedure TAnchorDockMaster.Notification(AComponent: TComponent;
Operation: TOperation);
var
AControl: TControl;
begin
inherited Notification(AComponent, Operation);
if Operation=opRemove then begin
if AComponent is TControl then begin
AControl:=TControl(AComponent);
FControls.Remove(AControl);
fNeedSimplify.Remove(AControl);
fNeedFree.Remove(AControl);
fDisabledAutosizing.Remove(AControl);
if fTreeNameToDocker<>nil then
fTreeNameToDocker.RemoveControl(AControl);
end;
end;
end;
procedure TAnchorDockMaster.InvalidateHeaders;
var
i: Integer;
Site: TAnchorDockHostSite;
begin
for i:=0 to ComponentCount-1 do begin
Site:=TAnchorDockHostSite(Components[i]);
if not (Site is TAnchorDockHostSite) then continue;
if (Site.Header<>nil) and (Site.Header.Parent<>nil) then
Site.Header.Invalidate;
end;
end;
procedure TAnchorDockMaster.AutoSizeAllHeaders(EnableAutoSizing: boolean);
var
i: Integer;
Site: TAnchorDockHostSite;
begin
for i:=0 to ComponentCount-1 do begin
Site:=TAnchorDockHostSite(Components[i]);
if not (Site is TAnchorDockHostSite) then continue;
if (Site.Header<>nil) and (Site.Header.Parent<>nil) then begin
Site.Header.InvalidatePreferredSize;
DisableControlAutoSizing(Site);
end;
end;
if EnableAutoSizing then
EnableAllAutoSizing;
end;
constructor TAnchorDockMaster.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FControls:=TFPList.Create;
FAllowDragging:=true;
FDragTreshold:=4;
FDockOutsideMargin:=10;
FDockParentMargin:=10;
FPageAreaInPercent:=40;
FHeaderAlignTop:=80;
HeaderAlignLeft:=120;
FHeaderHint:='';
FShowHeader:=true;
FShowHeaderCaption:=true;
FHideHeaderCaptionFloatingControl:=true;
FSplitterWidth:=4;
FScaleOnResize:=true;
fNeedSimplify:=TFPList.Create;
fNeedFree:=TFPList.Create;
fDisabledAutosizing:=TFPList.Create;
FSplitterClass:=TAnchorDockSplitter;
FSiteClass:=TAnchorDockHostSite;
FManagerClass:=TAnchorDockManager;
FHeaderClass:=TAnchorDockHeader;
FHeaderFlatten:=true;
FHeaderFilled:=true;
FPageControlClass:=TAnchorDockPageControl;
FPageClass:=TAnchorDockPage;
FRestoreLayouts:=TAnchorDockRestoreLayouts.Create;
FHeaderHighlightFocused:=false;
end;
destructor TAnchorDockMaster.Destroy;
var
AControl: TControl;
{$IFDEF VerboseAnchorDocking}
i: Integer;
{$ENDIF}
begin
QueueSimplify:=false;
FreeAndNil(FRestoreLayouts);
FreeAndNil(fPopupMenu);
FreeAndNil(fTreeNameToDocker);
if FControls.Count>0 then begin
while ControlCount>0 do begin
AControl:=Controls[ControlCount-1];
debugln(['TAnchorDockMaster.Destroy: still in list: ',DbgSName(AControl),' Caption="',AControl.Caption,'"']);
AControl.Free;
end;
end;
FreeAndNil(fNeedSimplify);
FreeAndNil(FControls);
FreeAndNil(fNeedFree);
FreeAndNil(fDisabledAutosizing);
{$IFDEF VerboseAnchorDocking}
for i:=0 to ComponentCount-1 do begin
debugln(['TAnchorDockMaster.Destroy ',i,'/',ComponentCount,' ',DbgSName(Components[i])]);
end;
{$ENDIF}
inherited Destroy;
end;
function TAnchorDockMaster.ControlCount: integer;
begin
Result:=FControls.Count;
end;
function TAnchorDockMaster.IndexOfControl(const aName: string): integer;
begin
Result:=ControlCount-1;
while (Result>=0) and (Controls[Result].Name<>aName) do dec(Result);
end;
function TAnchorDockMaster.FindControl(const aName: string): TControl;
var
i: LongInt;
begin
i:=IndexOfControl(aName);
if i>=0 then
Result:=Controls[i]
else
Result:=nil;
end;
function TAnchorDockMaster.IsSite(AControl: TControl): boolean;
begin
Result:=(AControl is TAnchorDockHostSite) or IsCustomSite(AControl);
end;
function TAnchorDockMaster.IsAnchorSite(AControl: TControl): boolean;
begin
Result:=AControl is TAnchorDockHostSite;
end;
function TAnchorDockMaster.IsCustomSite(AControl: TControl): boolean;
begin
Result:=(AControl is TCustomForm) // also checks for nil
and (AControl.Parent=nil)
and (TCustomForm(AControl).DockManager is TAnchorDockManager);
end;
function TAnchorDockMaster.GetSite(AControl: TControl): TCustomForm;
begin
Result:=nil;
if AControl=nil then
exit
else if IsCustomSite(AControl) then
Result:=TCustomForm(AControl)
else if AControl is TAnchorDockHostSite then
Result:=TAnchorDockHostSite(AControl)
else if (AControl.HostDockSite is TAnchorDockHostSite) then
Result:=TAnchorDockHostSite(AControl.HostDockSite);
end;
function TAnchorDockMaster.GetAnchorSite(AControl: TControl): TAnchorDockHostSite;
begin
Result:=nil;
if AControl=nil then
Result:=nil
else if AControl is TAnchorDockHostSite then
Result:=TAnchorDockHostSite(AControl)
else if (AControl.HostDockSite is TAnchorDockHostSite) then
Result:=TAnchorDockHostSite(AControl.HostDockSite);
end;
function TAnchorDockMaster.GetControl(Site: TControl): TControl;
var
AnchorSite: TAnchorDockHostSite;
begin
Result:=nil;
if IsCustomSite(Site) then
Result:=Site
else if Site is TAnchorDockHostSite then begin
AnchorSite:=TAnchorDockHostSite(Site);
if AnchorSite.SiteType=adhstOneControl then
Result:=AnchorSite.GetOneControl;
end else if (Site<>nil) and (Site.HostDockSite is TAnchorDockHostSite)
and (TAnchorDockHostSite(Site.HostDockSite).SiteType=adhstOneControl) then
Result:=Site;
end;
function TAnchorDockMaster.IsFloating(AControl: TControl): Boolean;
begin
if AControl is TAnchorDockHostSite then begin
Result:=(TAnchorDockHostSite(AControl).SiteType=adhstOneControl)
and (AControl.Parent=nil);
end else if (AControl.HostDockSite is TAnchorDockHostSite) then begin
Result:=(TAnchorDockHostSite(AControl.HostDockSite).SiteType=adhstOneControl)
and (AControl.HostDockSite.Parent=nil);
end else
Result:=AControl.Parent=nil;
end;
function TAnchorDockMaster.GetPopupMenu: TPopupMenu;
begin
if fPopupMenu=nil then begin
fPopupMenu:=TPopupMenu.Create(Self);
fPopupMenu.OnPopup:=@PopupMenuPopup;
end;
Result:=fPopupMenu;
end;
function TAnchorDockMaster.AddPopupMenuItem(AName, ACaption: string;
const OnClickEvent: TNotifyEvent; AParent: TMenuItem): TMenuItem;
begin
Result:=TMenuItem(fPopupMenu.FindComponent(AName));
if Result=nil then begin
Result:=TMenuItem.Create(fPopupMenu);
Result.Name:=AName;
if AParent=nil then
fPopupMenu.Items.Add(Result)
else
AParent.Add(Result);
end;
Result.Caption:=ACaption;
Result.OnClick:=OnClickEvent;
end;
function TAnchorDockMaster.AddRemovePopupMenuItem(Add: boolean; AName,
ACaption: string; const OnClickEvent: TNotifyEvent; AParent: TMenuItem
): TMenuItem;
begin
if Add then
Result:=AddPopupMenuItem(AName,ACaption,OnClickEvent,AParent)
else begin
Result:=TMenuItem(fPopupMenu.FindComponent(AName));
if Result<>nil then
FreeAndNil(Result);
end;
end;
procedure TAnchorDockMaster.MakeDockable(AControl: TControl; Show: boolean;
BringToFront: boolean; AddDockHeader: boolean);
var
Site: TAnchorDockHostSite;
begin
if AControl.Name='' then
raise Exception.Create('TAnchorDockMaster.MakeDockable '+
adrsMissingControlName);
if (AControl is TCustomForm) and (fsModal in TCustomForm(AControl).FormState)
then
raise Exception.Create('TAnchorDockMaster.MakeDockable '+
adrsModalFormsCanNotBeMadeDockable);
if IsCustomSite(AControl) then
raise Exception.Create('TAnchorDockMaster.MakeDockable '+
adrsControlIsAlreadyADocksite);
Site:=nil;
AControl.DisableAutoSizing{$IFDEF DebugDisableAutoSizing}('TAnchorDockMaster.DisableControlAutoSizing'){$ENDIF};
try
if AControl is TAnchorDockHostSite then begin
// already a site
Site:=TAnchorDockHostSite(AControl);
end else if AControl.Parent=nil then begin
if FControls.IndexOf(AControl)<0 then begin
FControls.Add(AControl);
AControl.FreeNotification(Self);
end;
// create docksite
Site:=CreateSite;
try
try
Site.BoundsRect:=AControl.BoundsRect;
ClearLayoutProperties(AControl);
// dock
AControl.ManualDock(Site);
AControl.Visible:=true;
if not AddDockHeader then
Site.Header.Parent:=nil;
except
FreeAndNil(Site);
raise;
end;
finally
if Site<>nil then
Site.EnableAutoSizing{$IFDEF DebugDisableAutoSizing}(ADAutoSizingReason){$ENDIF};
end;
end else if AControl.Parent is TAnchorDockHostSite then begin
// AControl is already docked => show site
Site:=TAnchorDockHostSite(AControl.Parent);
AControl.Visible:=true;
end else begin
raise Exception.Create('TAnchorDockMaster.MakeDockable '+Format(
adrsNotSupportedHasParent, [DbgSName(AControl), DbgSName(AControl)]));
end;
if (Site<>nil) and Show then
MakeVisible(Site,BringToFront);
finally
AControl.EnableAutoSizing{$IFDEF DebugDisableAutoSizing}('TAnchorDockMaster.DisableControlAutoSizing'){$ENDIF};
end;
// BringToFront
if Show and BringToFront and (Site<>nil) then begin
GetParentForm(Site).BringToFront;
Site.SetFocus;
end;
end;
procedure TAnchorDockMaster.MakeDockSite(AForm: TCustomForm; Sites: TAnchors;
ResizePolicy: TADMResizePolicy; AllowInside: boolean);
var
AManager: TAnchorDockManager;
begin
if AForm.Name='' then
raise Exception.Create('TAnchorDockMaster.MakeDockSite '+
adrsMissingControlName);
if AForm.DockManager<>nil then
raise Exception.Create('TAnchorDockMaster.MakeDockSite DockManager<>nil');
if AForm.Parent<>nil then
raise Exception.Create('TAnchorDockMaster.MakeDockSite Parent='+DbgSName(AForm.Parent));
if fsModal in AForm.FormState then
raise Exception.Create('TAnchorDockMaster.MakeDockSite '+
adrsModalFormsCanNotBeMadeDockable);
if Sites=[] then
raise Exception.Create('TAnchorDockMaster.MakeDockSite Sites=[]');
AForm.DisableAutoSizing{$IFDEF DebugDisableAutoSizing}('TAnchorDockMaster.MakeDockSite'){$ENDIF};
try
if FControls.IndexOf(AForm)<0 then begin
FControls.Add(AForm);
AForm.FreeNotification(Self);
end;
AManager:=ManagerClass.Create(AForm);
AManager.DockableSites:=Sites;
AManager.InsideDockingAllowed:=AllowInside;
AManager.ResizePolicy:=ResizePolicy;
AForm.DockManager:=AManager;
AForm.UseDockManager:=true;
AForm.DockSite:=true;
finally
AForm.EnableAutoSizing{$IFDEF DebugDisableAutoSizing}('TAnchorDockMaster.MakeDockSite'){$ENDIF};
end;
end;
procedure TAnchorDockMaster.MakeDockPanel(APanel:TAnchorDockPanel;
ResizePolicy: TADMResizePolicy);
var
AManager: TAnchorDockManager;
begin
if APanel.Name='' then
raise Exception.Create('TAnchorDockMaster.MakeDockPanel '+
adrsMissingControlName);
if APanel.DockManager<>nil then
raise Exception.Create('TAnchorDockMaster.MakeDockPanel DockManager<>nil');
APanel.DisableAutoSizing{$IFDEF DebugDisableAutoSizing}('TAnchorDockMaster.MakeDockPanel'){$ENDIF};
try
if FControls.IndexOf(APanel)<0 then begin
FControls.Add(APanel);
APanel.FreeNotification(Self);
end;
AManager:=ManagerClass.Create(APanel);
AManager.DockableSites:=[];
AManager.InsideDockingAllowed:=true;
AManager.ResizePolicy:=ResizePolicy;
APanel.DockManager:=AManager;
APanel.UseDockManager:=true;
APanel.DockSite:=true;
finally
APanel.EnableAutoSizing{$IFDEF DebugDisableAutoSizing}('TAnchorDockMaster.MakeDockPanel'){$ENDIF};
end;
end;
procedure TAnchorDockMaster.MakeVisible(AControl: TControl; SwitchPages: boolean);
begin
while AControl<>nil do begin
AControl.Visible:=true;
if SwitchPages and (AControl is TAnchorDockPage) then
TAnchorDockPageControl(AControl.Parent).PageIndex:=
TAnchorDockPage(AControl).PageIndex;
AControl:=AControl.Parent;
end;
end;
function TAnchorDockMaster.ShowControl(ControlName: string;
BringToFront: boolean): TControl;
begin
Result:=DoCreateControl(ControlName,false);
if Result=nil then exit;
MakeDockable(Result,true,BringToFront);
end;
procedure TAnchorDockMaster.CloseAll;
var
i: Integer;
AForm: TCustomForm;
AControl: TWinControl;
begin
// hide all forms
i:=Screen.CustomFormCount-1;
while i>=0 do begin
AForm:=GetParentForm(Screen.CustomForms[i]);
AForm.Hide;
i:=Min(i,Screen.CustomFormCount)-1;
end;
// close all forms except the MainForm
i:=Screen.CustomFormCount-1;
while i>=0 do begin
AForm:=Screen.CustomForms[i];
if (AForm<>Application.MainForm) and not AForm.IsParentOf(Application.MainForm)
then begin
AControl:=AForm;
while (AControl.Parent<>nil)
and (AControl.Parent<>Application.MainForm) do begin
AControl:=AControl.Parent;
if AControl is TCustomForm then AForm:=TCustomForm(AControl);
end;
AForm.Close;
end;
i:=Min(i,Screen.CustomFormCount)-1;
end;
end;
procedure TAnchorDockMaster.SaveLayoutToConfig(Config: TConfigStorage);
var
Tree: TAnchorDockLayoutTree;
begin
Tree:=TAnchorDockLayoutTree.Create;
try
Config.AppendBasePath('MainConfig/');
SaveMainLayoutToTree(Tree);
Tree.SaveToConfig(Config);
Config.UndoAppendBasePath;
Config.AppendBasePath('Restores/');
RestoreLayouts.SaveToConfig(Config);
Config.UndoAppendBasePath;
{$IFDEF VerboseAnchorDocking}
WriteDebugLayout('TAnchorDockMaster.SaveLayoutToConfig ',Tree.Root);
{$ENDIF}
//DebugWriteChildAnchors(Tree.Root);
finally
Tree.Free;
end;
end;
function GetParentFormOrDockPanel(Control: TControl): TCustomForm;
begin
while (Control <> nil) and (Control.Parent <> nil) do
begin
if (Control is TAnchorDockPanel) then
Break;
Control := Control.Parent;
end;
if Control is TCustomForm then
Result := TCustomForm(Control)
else if Control is TAnchorDockPanel then
Result := TCustomForm(Control)
else
Result := nil;
end;
procedure TAnchorDockMaster.SaveMainLayoutToTree(LayoutTree: TAnchorDockLayoutTree);
var
i: Integer;
AControl: TControl;
Site: TAnchorDockHostSite;
SavedSites: TFPList;
LayoutNode: TAnchorDockLayoutTreeNode;
AFormOrDockPanel: TWinControl;
VisibleControls: TStringList;
procedure SaveFormOrDockPanel(theFormOrDockPanel: TWinControl; SaveChildren: boolean);
begin
// custom dock site
LayoutNode:=LayoutTree.NewNode(LayoutTree.Root);
LayoutNode.NodeType:=adltnCustomSite;
LayoutNode.Assign(theFormOrDockPanel,theFormOrDockPanel is TAnchorDockPanel);
// can have one normal dock site
if SaveChildren then
begin
Site:=TAnchorDockManager(theFormOrDockPanel.DockManager).GetChildSite;
if Site<>nil then begin
LayoutNode:=LayoutTree.NewNode(LayoutNode);
Site.SaveLayout(LayoutTree,LayoutNode);
{if Site.BoundSplitter<>nil then begin
LayoutNode:=LayoutTree.NewNode(LayoutNode);
Site.BoundSplitter.SaveLayout(LayoutNode);
end;}
end;
end;
end;
begin
SavedSites:=TFPList.Create;
VisibleControls:=TStringList.Create;
try
for i:=0 to ControlCount-1 do begin
AControl:=Controls[i];
if not DockedControlIsVisible(AControl) then continue;
VisibleControls.Add(AControl.Name);
AFormOrDockPanel:=GetParentFormOrDockPanel(AControl);
if AFormOrDockPanel=nil then continue;
if SavedSites.IndexOf(AFormOrDockPanel)>=0 then continue;
SavedSites.Add(AFormOrDockPanel);
debugln(['TAnchorDockMaster.SaveMainLayoutToTree AForm=',DbgSName(AFormOrDockPanel)]);
DebugWriteChildAnchors(AFormOrDockPanel,true,true);
if AFormOrDockPanel is TAnchorDockPanel then begin
SaveFormOrDockPanel(GetParentFormOrDockPanel(AFormOrDockPanel),{false}true);
//LayoutNode:=LayoutTree.NewNode(LayoutTree.Root);
//TAnchorDockPanel(AFormOrDockPanel).SaveLayout(LayoutTree,LayoutNode);
end else if AFormOrDockPanel is TAnchorDockHostSite then begin
Site:=TAnchorDockHostSite(AFormOrDockPanel);
LayoutNode:=LayoutTree.NewNode(LayoutTree.Root);
Site.SaveLayout(LayoutTree,LayoutNode);
end else if IsCustomSite(AFormOrDockPanel) then begin
SaveFormOrDockPanel(AFormOrDockPanel,true);
end else
raise EAnchorDockLayoutError.Create('invalid root control for save: '+DbgSName(AControl));
end;
// remove invisible controls
LayoutTree.Root.Simplify(VisibleControls);
finally
VisibleControls.Free;
SavedSites.Free;
end;
end;
procedure TAnchorDockMaster.SaveSiteLayoutToTree(AControl: TWinControl;
LayoutTree: TAnchorDockLayoutTree);
var
LayoutNode: TAnchorDockLayoutTreeNode;
Site: TAnchorDockHostSite;
begin
if AControl is TAnchorDockHostSite then begin
Site:=TAnchorDockHostSite(AControl);
Site.SaveLayout(LayoutTree,LayoutTree.Root);
end else if AControl is TAnchorDockPanel then begin
(AControl as TAnchorDockPanel).SaveLayout(LayoutTree,LayoutTree.Root);
end else if IsCustomSite(AControl) then begin
LayoutTree.Root.NodeType:=adltnCustomSite;
LayoutTree.Root.Assign(AControl);
// can have one normal dock site
Site:=TAnchorDockManager(AControl.DockManager).GetChildSite;
if Site<>nil then begin
LayoutNode:=LayoutTree.NewNode(LayoutTree.Root);
Site.SaveLayout(LayoutTree,LayoutNode);
end;
end else
raise EAnchorDockLayoutError.Create('invalid root control for save: '+DbgSName(AControl));
end;
function TAnchorDockMaster.CreateRestoreLayout(AControl: TControl
): TAnchorDockRestoreLayout;
{ Create a restore layout for AControl and its child controls.
It contains the whole parent structure so that the restore knows where to
put AControl.
}
procedure AddControlNames(SubControl: TControl;
RestoreLayout: TAnchorDockRestoreLayout);
var
i: Integer;
begin
if (FControls.IndexOf(SubControl)>=0)
and not RestoreLayout.HasControlName(SubControl.Name) then
RestoreLayout.ControlNames.Add(SubControl.Name);
if SubControl is TWinControl then
for i:=0 to TWinControl(SubControl).ControlCount-1 do
AddControlNames(TWinControl(SubControl).Controls[i],RestoreLayout);
end;
var
AForm: TCustomForm;
begin
if not IsSite(AControl) then
raise Exception.Create('TAnchorDockMaster.CreateRestoreLayout: not a site '+DbgSName(AControl));
AForm:=GetParentFormOrDockPanel(AControl);
Result:=TAnchorDockRestoreLayout.Create(TAnchorDockLayoutTree.Create);
if AForm=nil then exit;
SaveSiteLayoutToTree(AForm,Result.Layout);
AddControlNames(AControl,Result);
end;
function TAnchorDockMaster.ConfigIsEmpty(Config: TConfigStorage): boolean;
begin
Result:=Config.GetValue('MainConfig/Nodes/ChildCount',0)=0;
end;
function TAnchorDockMaster.LoadLayoutFromConfig(Config: TConfigStorage;
Scale: Boolean): boolean;
var
Tree: TAnchorDockLayoutTree;
ControlNames: TStringList;
begin
Result:=false;
ControlNames:=TStringList.Create;
fTreeNameToDocker:=TADNameToControl.Create;
Tree:=TAnchorDockLayoutTree.Create;
try
// load layout
Config.AppendBasePath('MainConfig/');
try
Tree.LoadFromConfig(Config);
finally
Config.UndoAppendBasePath;
end;
// load restore layouts for hidden forms
Config.AppendBasePath('Restores/');
try
RestoreLayouts.LoadFromConfig(Config);
finally
Config.UndoAppendBasePath;
end;
{$IFDEF VerboseAnchorDockRestore}
WriteDebugLayout('TAnchorDockMaster.LoadLayoutFromConfig ',Tree.Root);
DebugWriteChildAnchors(Tree.Root);
{$ENDIF}
// close all unneeded and wrongly allocated forms/controls (not helper controls like splitters)
MarkCorrectlyLocatedControl(Tree);
if not CloseUnneededAndWronglyLocatedControls(Tree) then exit;
BeginUpdate;
try
// create all needed forms/controls (not helper controls like splitters)
if not CreateNeededControls(Tree,true,ControlNames) then exit;
// simplify layouts
ControlNames.Sort;
{$IFDEF VerboseAnchorDockRestore}
debugln(['TAnchorDockMaster.LoadLayoutFromConfig controls: ']);
debugln(ControlNames.Text);
{$ENDIF}
// if some forms/controls could not be created the layout needs to be adapted
Tree.Root.Simplify(ControlNames);
// reuse existing sites to reduce flickering
MapTreeToControls(Tree);
{$IFDEF VerboseAnchorDockRestore}
fTreeNameToDocker.WriteDebugReport('TAnchorDockMaster.LoadLayoutFromConfig Map');
{$ENDIF}
// create sites, move controls
RestoreLayout(Tree,Scale);
finally
EndUpdate;
end;
finally
// clean up
FreeAndNil(fTreeNameToDocker);
ControlNames.Free;
Tree.Free;
// commit (this can raise an exception)
EnableAllAutoSizing;
end;
{$IFDEF VerboseAnchorDockRestore}
DebugWriteChildAnchors(Application.MainForm,true,false);
{$ENDIF}
Result:=true;
end;
procedure TAnchorDockMaster.LoadSettingsFromConfig(Config: TConfigStorage);
var
Settings: TAnchorDockSettings;
begin
Settings:=TAnchorDockSettings.Create;
try
Settings.LoadFromConfig(Config);
LoadSettings(Settings);
finally
Settings.Free;
end;
end;
procedure TAnchorDockMaster.SaveSettingsToConfig(Config: TConfigStorage);
var
Settings: TAnchorDockSettings;
begin
Settings:=TAnchorDockSettings.Create;
try
SaveSettings(Settings);
Settings.SaveToConfig(Config);
finally
Settings.Free;
end;
end;
procedure TAnchorDockMaster.LoadSettings(Settings: TAnchorDockSettings);
begin
DragTreshold := Settings.DragTreshold;
DockOutsideMargin := Settings.DockOutsideMargin;
DockParentMargin := Settings.DockParentMargin;
PageAreaInPercent := Settings.PageAreaInPercent;
HeaderAlignTop := Settings.HeaderAlignTop;
HeaderAlignLeft := Settings.HeaderAlignLeft;
SplitterWidth := Settings.SplitterWidth;
ScaleOnResize := Settings.ScaleOnResize;
ShowHeader := Settings.ShowHeader;
ShowHeaderCaption := Settings.ShowHeaderCaption;
HideHeaderCaptionFloatingControl := Settings.HideHeaderCaptionFloatingControl;
AllowDragging := Settings.AllowDragging;
HeaderStyle := Settings.HeaderStyle;
HeaderFlatten := Settings.HeaderFlatten;
HeaderFilled := Settings.HeaderFilled;
HeaderHighlightFocused := Settings.HeaderHighlightFocused;
end;
procedure TAnchorDockMaster.SaveSettings(Settings: TAnchorDockSettings);
begin
Settings.DragTreshold:=DragTreshold;
Settings.DockOutsideMargin:=DockOutsideMargin;
Settings.DockParentMargin:=DockParentMargin;
Settings.PageAreaInPercent:=PageAreaInPercent;
Settings.HeaderAlignTop:=HeaderAlignTop;
Settings.HeaderAlignLeft:=HeaderAlignLeft;
Settings.SplitterWidth:=SplitterWidth;
Settings.ScaleOnResize:=ScaleOnResize;
Settings.ShowHeader:=ShowHeader;
Settings.ShowHeaderCaption:=ShowHeaderCaption;
Settings.HideHeaderCaptionFloatingControl:=HideHeaderCaptionFloatingControl;
Settings.AllowDragging:=AllowDragging;
Settings.HeaderStyle:=HeaderStyle;
Settings.HeaderFlatten:=HeaderFlatten;
Settings.HeaderFilled:=HeaderFilled;
Settings.HeaderHighlightFocused:=HeaderHighlightFocused;
end;
function TAnchorDockMaster.SettingsAreEqual(Settings: TAnchorDockSettings
): boolean;
var
Cur: TAnchorDockSettings;
begin
Cur:=TAnchorDockSettings.Create;
try
SaveSettings(Cur);
Result:=Cur.IsEqual(Settings);
finally
Cur.Free;
end;
end;
procedure TAnchorDockMaster.ManualFloat(AControl: TControl);
var
Site: TAnchorDockHostSite;
begin
Site:=GetAnchorSite(AControl);
if Site=nil then exit;
Site.Undock;
end;
procedure TAnchorDockMaster.ManualDock(SrcSite: TAnchorDockHostSite;
TargetSite: TCustomForm; Align: TAlign; TargetControl: TControl);
var
Site: TAnchorDockHostSite;
aManager: TAnchorDockManager;
DockObject: TDragDockObject;
begin
debugln(['TAnchorDockMaster.ManualDock SrcSite=',DbgSName(SrcSite),' TargetSite=',DbgSName(TargetSite),' Align=',dbgs(Align),' TargetControl=',DbgSName(TargetControl)]);
if SrcSite=TargetSite then exit;
if SrcSite.IsParentOf(TargetSite) then
raise Exception.Create('TAnchorDockMaster.ManualDock SrcSite.IsParentOf(TargetSite)');
if TargetSite.IsParentOf(SrcSite) then
raise Exception.Create('TAnchorDockMaster.ManualDock TargetSite.IsParentOf(SrcSite)');
if IsCustomSite(TargetSite) then begin
aManager:=TAnchorDockManager(TargetSite.DockManager);
Site:=aManager.GetChildSite;
if Site=nil then begin
// dock as first site into custom dock site
debugln(['TAnchorDockMaster.ManualDock dock as first site into custom dock site: SrcSite=',DbgSName(SrcSite),' TargetSite=',DbgSName(TargetSite),' Align=',dbgs(Align)]);
BeginUpdate;
try
DockObject := TDragDockObject.Create(SrcSite);
try
DockObject.DropAlign:=Align;
DockObject.DockRect:=SrcSite.BoundsRect;
aManager.InsertControl(DockObject);
finally
DockObject.Free;
end;
finally
EndUpdate;
end;
exit;
end;
// else: dock into child site of custom dock site
end else begin
// dock to or into TargetSite
if not (TargetSite is TAnchorDockHostSite) then
raise Exception.Create('TAnchorDockMaster.ManualDock invalid TargetSite');
Site:=TAnchorDockHostSite(TargetSite);
end;
if AutoFreedIfControlIsRemoved(Site,SrcSite) then
raise Exception.Create('TAnchorDockMaster.ManualDock TargetSite depends on SrcSite');
BeginUpdate;
try
Site.ExecuteDock(SrcSite,TargetControl,Align);
finally
EndUpdate;
end;
end;
function TAnchorDockMaster.ManualEnlarge(Site: TAnchorDockHostSite;
Side: TAnchorKind; OnlyCheckIfPossible: boolean): boolean;
begin
Result:=(Site<>nil) and Site.EnlargeSide(Side,OnlyCheckIfPossible);
end;
procedure TAnchorDockMaster.BeginUpdate;
begin
inc(fUpdateCount);
end;
procedure TAnchorDockMaster.EndUpdate;
begin
if fUpdateCount<=0 then
RaiseGDBException('');
dec(fUpdateCount);
if fUpdateCount=0 then
SimplifyPendingLayouts;
end;
function TAnchorDockMaster.IsReleasing(AControl: TControl): Boolean;
begin
Result := fNeedFree.IndexOf(AControl) >= 0;
end;
procedure TAnchorDockMaster.NeedSimplify(AControl: TControl);
begin
if Self=nil then exit;
if csDestroying in ComponentState then exit;
if csDestroying in AControl.ComponentState then exit;
if fNeedSimplify=nil then exit;
if fNeedSimplify.IndexOf(AControl)>=0 then exit;
if not ((AControl is TAnchorDockHostSite)
or (AControl is TAnchorDockPage))
then
exit;
if Application.Terminated then exit;
//debugln(['TAnchorDockMaster.NeedSimplify ',DbgSName(AControl),' Caption="',AControl.Caption,'"']);
fNeedSimplify.Add(AControl);
AControl.FreeNotification(Self);
QueueSimplify:=true;
end;
procedure TAnchorDockMaster.NeedFree(AControl: TControl);
begin
//debugln(['TAnchorDockMaster.NeedFree ',DbgSName(AControl),' ',csDestroying in AControl.ComponentState]);
if IsReleasing(AControl) then exit;
if csDestroying in AControl.ComponentState then exit;
fNeedFree.Add(AControl);
AControl.DisableAutoSizing{$IFDEF DebugDisableAutoSizing}(ADAutoSizingReason){$ENDIF};
AControl.Parent:=nil;
AControl.Visible:=false;
end;
procedure TAnchorDockMaster.SimplifyPendingLayouts;
var
AControl: TControl;
Changed: Boolean;
i: Integer;
begin
if fSimplifying or (fUpdateCount>0) then exit;
fSimplifying:=true;
try
// simplify layout (do not free controls in this step, only mark them)
repeat
Changed:=false;
i:=fNeedSimplify.Count-1;
while i>=0 do begin
AControl:=TControl(fNeedSimplify[i]);
if (csDestroying in AControl.ComponentState)
or IsReleasing(AControl) then begin
fNeedSimplify.Delete(i);
Changed:=true;
end else if (AControl is TAnchorDockHostSite) then begin
//debugln(['TAnchorDockMaster.SimplifyPendingLayouts ',DbgSName(AControl),' ',dbgs(TAnchorDockHostSite(AControl).SiteType),' UpdatingLayout=',TAnchorDockHostSite(AControl).UpdatingLayout]);
if not TAnchorDockHostSite(AControl).UpdatingLayout then begin
fNeedSimplify.Delete(i);
Changed:=true;
if TAnchorDockHostSite(AControl).SiteType=adhstNone then
begin
//debugln(['TAnchorDockMaster.SimplifyPendingLayouts free empty site: ',dbgs(pointer(AControl)),' Caption="',AControl.Caption,'"']);
NeedFree(AControl);
end else begin
TAnchorDockHostSite(AControl).Simplify;
end;
end;
end else if AControl is TAnchorDockPage then begin
fNeedSimplify.Delete(i);
Changed:=true;
NeedFree(AControl);
end else
RaiseGDBException('TAnchorDockMaster.SimplifyPendingLayouts inconsistency');
i:=Min(fNeedSimplify.Count,i)-1;
end;
until not Changed;
// free unneeded controls
for i := fNeedFree.Count - 1 downto 0 do
if not (csDestroying in TControl(fNeedFree[i]).ComponentState) then
Application.ReleaseComponent(TComponent(fNeedFree[i]));
fNeedFree.Clear;
finally
fSimplifying:=false;
end;
end;
function TAnchorDockMaster.AutoFreedIfControlIsRemoved(AControl,
RemovedControl: TControl): boolean;
{ returns true if the simplification algorithm will automatically free
AControl when RemovedControl is removed
Some sites are dummy sites that were autocreated. They will be auto freed
if not needed anymore.
1. A TAnchorDockPage has a TAnchorDockHostSite as child. If the child is freed
the page will be freed.
2. When a TAnchorDockPageControl has only one page left the content is moved
up and the pagecontrol and page will be freed.
3. When a adhstLayout site has only one child site left, the content is moved up
and the child site will be freed.
4. When the control of a adhstOneControl site is freed the site will be freed.
}
var
ParentSite: TAnchorDockHostSite;
Page: TAnchorDockPage;
PageControl: TAnchorDockPageControl;
OtherPage: TAnchorDockPage;
Site, Site1, Site2: TAnchorDockHostSite;
begin
Result:=false;
if (RemovedControl=nil) or (AControl=nil) then exit;
while RemovedControl<>nil do begin
if RemovedControl=AControl then exit(true);
if RemovedControl is TAnchorDockPage then begin
// a page will be removed
Page:=TAnchorDockPage(RemovedControl);
if not (Page.Parent is TAnchorDockPageControl) then exit;
PageControl:=TAnchorDockPageControl(Page.Parent);
if PageControl.PageCount>2 then exit;
if PageControl.PageCount=2 then begin
// this pagecontrol will be replaced by the content of the other page
if PageControl=AControl then exit(true);
if PageControl.Page[0]=Page then
OtherPage:=PageControl.DockPages[1]
else
OtherPage:=PageControl.DockPages[0];
// the other page will be removed (its content will be moved up)
if OtherPage=AControl then exit(true);
if (OtherPage.ControlCount>0) then begin
if (OtherPage.Controls[0] is TAnchorDockHostSite)
and (OtherPage.Controls[0]=RemovedControl) then
exit(true); // the site of the other page will be removed (its content moved up)
end;
exit;
end;
// the last page of the pagecontrol is freed => the pagecontrol will be removed too
end else if RemovedControl is TAnchorDockPageControl then begin
// the pagecontrol will be removed
if not (RemovedControl.Parent is TAnchorDockHostSite) then exit;
// a pagecontrol is always the only child of a site
// => the site will be removed too
end else if RemovedControl is TAnchorDockHostSite then begin
// a site will be removed
Site:=TAnchorDockHostSite(RemovedControl);
if Site.Parent is TAnchorDockPage then begin
// a page has only one site
// => the page will be removed too
end else if Site.Parent is TAnchorDockHostSite then begin
ParentSite:=TAnchorDockHostSite(Site.Parent);
if (ParentSite.SiteType=adhstOneControl)
or ParentSite.IsOneSiteLayout(Site) then begin
// the control of a OneControl site is removed => the ParentSite is freed too
end else if ParentSite.SiteType=adhstLayout then begin
if ParentSite.IsTwoSiteLayout(Site1,Site2) then begin
// when there are two sites and one of them is removed
// the content of the other will be moved up and then both sites are
// removed
if (Site1=AControl) or (Site2=AControl) then
exit(true);
end;
exit; // removing only site will not free the layout
end else begin
raise Exception.Create('TAnchorDockMaster.AutoFreedIfControlIsRemoved ParentSiteType='+dbgs(ParentSite.SiteType)+' ChildSiteType='+dbgs(Site.SiteType));
end;
end else
exit; // other classes will never be auto freed
end else begin
// control is not a site => check if control is in a OneControl site
if not (RemovedControl.Parent is TAnchorDockHostSite) then exit;
ParentSite:=TAnchorDockHostSite(RemovedControl.Parent);
if (ParentSite.SiteType<>adhstOneControl) then exit;
if ParentSite.GetOneControl<>RemovedControl then exit;
// the control of a OneControl site is removed => the site is freed too
end;
RemovedControl:=RemovedControl.Parent;
end;
end;
function TAnchorDockMaster.CreateSite(NamePrefix: string;
DisableAutoSizing: boolean): TAnchorDockHostSite;
var
i: Integer;
NewName: String;
begin
Result:=TAnchorDockHostSite(SiteClass.NewInstance);
{$IFDEF DebugDisableAutoSizing}
if DisableAutoSizing then
Result.DisableAutoSizing(ADAutoSizingReason)
else
Result.DisableAutoSizing('TAnchorDockMaster.CreateSite');
{$ELSE}
Result.DisableAutoSizing;
{$ENDIF};
try
Result.CreateNew(Self,1);
i:=0;
repeat
inc(i);
NewName:=NamePrefix+AnchorDockSiteName+IntToStr(i);
until (Screen.FindForm(NewName)=nil) and (FindComponent(NewName)=nil);
Result.Name:=NewName;
finally
if not DisableAutoSizing then
Result.EnableAutoSizing{$IFDEF DebugDisableAutoSizing}('TAnchorDockMaster.CreateSite'){$ENDIF};
end;
end;
function TAnchorDockMaster.CreateSplitter(NamePrefix: string): TAnchorDockSplitter;
var
i: Integer;
NewName: String;
begin
Result:=SplitterClass.Create(Self);
i:=0;
repeat
inc(i);
NewName:=NamePrefix+AnchorDockSplitterName+IntToStr(i);
until FindComponent(NewName)=nil;
Result.Name:=NewName;
end;
procedure TAnchorDockMaster.IncreaseOptionsChangeStamp;
begin
LUIncreaseChangeStamp64(FOptionsChangeStamp);
end;
{ TAnchorDockHostSite }
procedure TAnchorDockHostSite.SetHeaderSide(const AValue: TAnchorKind);
begin
if FHeaderSide=AValue then exit;
FHeaderSide:=AValue;
end;
procedure TAnchorDockHostSite.ChildVisibleChanged(Sender: TObject);
var
AControl: TControl;
begin
if Sender is TControl then begin
AControl:=TControl(Sender);
if not (csDestroying in ComponentState) then begin
if (not AControl.Visible)
and (not ((AControl is TAnchorDockHeader)
or (AControl is TAnchorDockSplitter)
or (AControl is TAnchorDockHostSite)))
then begin
//debugln(['TAnchorDockHostSite.ChildVisibleChanged START ',Caption,' ',dbgs(SiteType),' ',DbgSName(AControl),' UpdatingLayout=',UpdatingLayout]);
if (SiteType=adhstOneControl) then
Hide
else if (SiteType=adhstLayout) then begin
RemoveControlFromLayout(AControl);
UpdateDockCaption;
end;
//debugln(['TAnchorDockHostSite.ChildVisibleChanged END ',Caption,' ',dbgs(SiteType),' ',DbgSName(AControl)]);
end;
end;
end;
end;
procedure TAnchorDockHostSite.DoEnter;
begin
inherited;
if Assigned(FHeader) then
FHeader.fFocused:=true;
invalidate;
end;
procedure TAnchorDockHostSite.DoExit;
begin
inherited;
if Assigned(FHeader) then
FHeader.fFocused:=false;
invalidate;
end;
procedure TAnchorDockHostSite.Notification(AComponent: TComponent;
Operation: TOperation);
begin
inherited Notification(AComponent, Operation);
if Operation=opRemove then begin
if AComponent=Pages then FPages:=nil;
if AComponent=Header then FHeader:=nil;
if AComponent=BoundSplitter then FBoundSplitter:=nil;
end;
end;
function TAnchorDockHostSite.DoDockClientMsg(DragDockObject: TDragDockObject;
aPosition: TPoint): boolean;
begin
if aPosition.X=0 then ;
Result:=ExecuteDock(DragDockObject.Control,DragDockObject.DropOnControl,
DragDockObject.DropAlign);
end;
function TAnchorDockHostSite.ExecuteDock(NewControl, DropOnControl: TControl;
DockAlign: TAlign): boolean;
begin
if UpdatingLayout then exit;
//debugln(['TAnchorDockHostSite.ExecuteDock Self="',Caption,'" Control=',DbgSName(NewControl),' DropOnControl=',DbgSName(DropOnControl),' Align=',dbgs(DockAlign)]);
DisableAutoSizing{$IFDEF DebugDisableAutoSizing}('TAnchorDockHostSite.ExecuteDock HostSite'){$ENDIF};
try
BeginUpdateLayout;
try
DockMaster.SimplifyPendingLayouts;
NewControl.DisableAutoSizing{$IFDEF DebugDisableAutoSizing}('TAnchorDockHostSite.ExecuteDock NewControl'){$ENDIF};
if (NewControl.Parent=Self) and (SiteType=adhstLayout) then begin
// change of layout, one child is docked to the outer side
RemoveControlFromLayout(NewControl);
end else if (NewControl.Parent=Parent) and (Parent is TAnchorDockHostSite)
and (TAnchorDockHostSite(Parent).SiteType=adhstLayout) then begin
// change of layout, one sibling is moved
TAnchorDockHostSite(Parent).RemoveControlFromLayout(NewControl);
end;
if SiteType=adhstNone then begin
// make a control dockable by docking it into a TAnchorDockHostSite;
Result:=DockFirstControl(NewControl);
end else if DockAlign=alClient then begin
// page docking
if SiteType=adhstOneControl then begin
if Parent is TAnchorDockPage then begin
// add as sibling page
Result:=(Parent.Parent.Parent as TAnchorDockHostSite).DockAnotherPage(NewControl,nil);
end else
// create pages
Result:=DockSecondPage(NewControl);
end else if SiteType=adhstPages then
// add as sibling page
Result:=DockAnotherPage(NewControl,DropOnControl);
end else if DockAlign in [alLeft,alTop,alRight,alBottom] then
begin
// anchor docking
if SiteType=adhstOneControl then begin
if Parent is TAnchorDockHostSite then begin
// add site as sibling
Result:=TAnchorDockHostSite(Parent).DockAnotherControl(Self,NewControl,
DockAlign,DropOnControl<>nil);
end else
// create layout
Result:=DockSecondControl(NewControl,DockAlign,DropOnControl<>nil);
end else if SiteType=adhstLayout then
// add site as sibling
Result:=DockAnotherControl(nil,NewControl,DockAlign,DropOnControl<>nil);
end;
NewControl.EnableAutoSizing{$IFDEF DebugDisableAutoSizing}('TAnchorDockHostSite.ExecuteDock NewControl'){$ENDIF};
finally
EndUpdateLayout;
end;
finally
EnableAutoSizing{$IFDEF DebugDisableAutoSizing}('TAnchorDockHostSite.ExecuteDock HostSite'){$ENDIF};
end;
end;
function TAnchorDockHostSite.DockFirstControl(NewControl: TControl): boolean;
var
DestRect: TRect;
begin
if SiteType<>adhstNone then
RaiseGDBException('TAnchorDockHostSite.DockFirstControl inconsistency');
// create adhstOneControl
DestRect := ClientRect;
NewControl.Dock(Self, DestRect);
FSiteType:=adhstOneControl;
if NewControl is TCustomForm then begin
Icon.Assign(TCustomForm(NewControl).Icon);
end;
Result:=true;
end;
function TAnchorDockHostSite.DockSecondControl(NewControl: TControl;
DockAlign: TAlign; Inside: boolean): boolean;
{ Convert a adhstOneControl into a adhstLayout by docking NewControl
at a side (DockAlign).
If Inside=true this DockSite is not expanded and both controls share the old space.
If Inside=false this DockSite is expanded.
}
var
OldSite: TAnchorDockHostSite;
OldControl: TControl;
begin
Result:=true;
debugln(['TAnchorDockHostSite.DockSecondControl Self="',Caption,'" AControl=',DbgSName(NewControl),' Align=',dbgs(DockAlign),' Inside=',Inside]);
if SiteType<>adhstOneControl then
RaiseGDBException('TAnchorDockHostSite.DockSecondControl inconsistency: not adhstOneControl');
if not (DockAlign in [alLeft,alTop,alRight,alBottom]) then
RaiseGDBException('TAnchorDockHostSite.DockSecondControl inconsistency: DockAlign='+dbgs(DockAlign));
FSiteType:=adhstLayout;
// remove header (keep it for later use)
Header.Parent:=nil;
// put the OldControl into a site of its own (OldSite) and dock OldSite
OldControl:=GetOneControl;
OldSite:=MakeSite(OldControl);
AddCleanControl(OldSite);
OldSite.AnchorClient(0);
// the LCL will compute the bounds later after EnableAutoSizing
// but the bounds are needed now => set them manually
OldSite.BoundsRect:=Rect(0,0,ClientWidth,ClientHeight);
Result:=DockAnotherControl(OldSite,NewControl,DockAlign,Inside);
debugln(['TAnchorDockHostSite.DockSecondControl END Self="',Caption,'" AControl=',DbgSName(NewControl),' Align=',dbgs(DockAlign),' Inside=',Inside]);
end;
function TAnchorDockHostSite.DockAnotherControl(Sibling, NewControl: TControl;
DockAlign: TAlign; Inside: boolean): boolean;
var
Splitter: TAnchorDockSplitter;
a: TAnchorKind;
NewSite: TAnchorDockHostSite;
NewBounds: TRect;
MainAnchor: TAnchorKind;
i: Integer;
NewSiblingWidth: Integer;
NewSiblingHeight: Integer;
NewSize: LongInt;
BoundsIncreased: Boolean;
NewParentBounds: TRect;
begin
Result:=false;
if SiteType<>adhstLayout then
RaiseGDBException('TAnchorDockHostSite.DockAnotherControl inconsistency');
if not (DockAlign in [alLeft,alTop,alRight,alBottom]) then
RaiseGDBException('TAnchorDockHostSite.DockAnotherControl inconsistency');
// add a splitter
Splitter:=DockMaster.CreateSplitter;
if DockAlign in [alLeft,alRight] then begin
Splitter.ResizeAnchor:=akLeft;
Splitter.Width:=DockMaster.SplitterWidth;
end else begin
Splitter.ResizeAnchor:=akTop;
Splitter.Height:=DockMaster.SplitterWidth;
end;
Splitter.Parent:=Self;
// dock the NewControl
NewSite:=MakeSite(NewControl);
AddCleanControl(NewSite);
BoundsIncreased:=false;
if (not Inside) then begin
if (Parent=nil) then begin
// expand Self
NewBounds:=BoundsRect;
case DockAlign of
alLeft:
begin
dec(NewBounds.Left,NewSite.Width+Splitter.Width);
MoveAllControls(NewSite.Width+Splitter.Width,0);
end;
alRight:
inc(NewBounds.Right,NewSite.Width+Splitter.Width);
alTop:
begin
dec(NewBounds.Top,NewSite.Height+Splitter.Height);
MoveAllControls(0,NewSite.Height+Splitter.Height);
end;
alBottom:
inc(NewBounds.Bottom,NewSite.Height+Splitter.Height);
end;
BoundsRect:=NewBounds;
BoundsIncreased:=true;
end else if DockMaster.IsCustomSite(Parent) then begin
// Parent is a custom docksite
// => expand Self and Parent
// expand Parent (the custom docksite)
NewParentBounds:=Parent.BoundsRect;
NewBounds:=BoundsRect;
case DockAlign of
alLeft:
begin
i:=NewSite.Width+Splitter.Width;
dec(NewParentBounds.Left,i);
dec(NewBounds.Left,i);
MoveAllControls(i,0);
end;
alRight:
begin
i:=NewSite.Width+Splitter.Width;
inc(NewBounds.Right,i);
inc(NewParentBounds.Right,i);
end;
alTop:
begin
i:=NewSite.Height+Splitter.Height;
dec(NewBounds.Top,i);
dec(NewParentBounds.Top,i);
MoveAllControls(0,i);
end;
alBottom:
begin
i:=NewSite.Height+Splitter.Height;
inc(NewParentBounds.Bottom,i);
inc(NewBounds.Bottom,i);
end;
end;
Parent.BoundsRect:=NewParentBounds;
BoundsRect:=NewBounds;
BoundsIncreased:=true;
TAnchorDockManager(Parent.DockManager).FSiteClientRect:=Parent.ClientRect;
end;
debugln(['TAnchorDockHostSite.DockAnotherControl AFTER ENLARGE ',Caption]);
//DebugWriteChildAnchors(Self,true,true);
end;
// anchors
MainAnchor:=MainAlignAnchor[DockAlign];
if Inside and (Sibling<>nil) then begin
{ Example: insert right of Sibling
# #
################ ########################
-------+# -------+#+-------+#
Sibling|# -----> Sibling|#|NewSite|#
-------+# -------+#+-------+#
################ ########################
# #
}
for a:=low(TAnchorKind) to high(TAnchorKind) do begin
if a in AnchorAlign[DockAlign] then begin
NewSite.AnchorSide[a].Assign(Sibling.AnchorSide[a]);
end else begin
NewSite.AnchorToNeighbour(a,0,Splitter);
end;
end;
Sibling.AnchorToNeighbour(MainAnchor,0,Splitter);
if DockAlign in [alLeft,alRight] then begin
Splitter.AnchorSide[akTop].Assign(Sibling.AnchorSide[akTop]);
Splitter.AnchorSide[akBottom].Assign(Sibling.AnchorSide[akBottom]);
// resize and move
// the NewSite gets at maximum half the space
// Many bounds are later set by the LCL anchoring. When docking several
// controls at once the bounds are needed earlier.
NewSize:=Max(1,Min(NewSite.Width,Sibling.Width div 2));
NewBounds:=Rect(0,0,NewSize,Sibling.Height);
NewSiblingWidth:=Max(1,Sibling.Width-NewSize-Splitter.Width);
if DockAlign=alLeft then begin
// alLeft: NewControl, Splitter, Sibling
Splitter.SetBounds(Sibling.Left+NewSize,Sibling.Top,
Splitter.Width,Sibling.Height);
OffsetRect(NewBounds,Sibling.Left,Sibling.Top);
Sibling.SetBounds(Splitter.Left+Splitter.Width,Sibling.Top,
NewSiblingWidth,Sibling.Height);
end else begin
// alRight: Sibling, Splitter, NewControl
Sibling.Width:=NewSiblingWidth;
Splitter.SetBounds(Sibling.Left+Sibling.Width,Sibling.Top,
Splitter.Width,Sibling.Height);
OffsetRect(NewBounds,Splitter.Left+Splitter.Width,Sibling.Top);
end;
NewSite.BoundsRect:=NewBounds;
end else begin
Splitter.AnchorSide[akLeft].Assign(Sibling.AnchorSide[akLeft]);
Splitter.AnchorSide[akRight].Assign(Sibling.AnchorSide[akRight]);
// resize and move
// the NewSite gets at maximum half the space
// Many bounds are later set by the LCL anchoring. When docking several
// controls at once the bounds are needed earlier.
NewSize:=Max(1,Min(NewSite.Height,Sibling.Height div 2));
NewSiblingHeight:=Max(1,Sibling.Height-NewSize-Splitter.Height);
if DockAlign=alTop then begin
// alTop: NewControl, Splitter, Sibling
Splitter.SetBounds(Sibling.Left,Sibling.Top+NewSize,
Sibling.Width,Splitter.Height);
NewSite.SetBounds(Sibling.Left,Sibling.Top,Sibling.Width,NewSize);
Sibling.SetBounds(Sibling.Left,Splitter.Top+Splitter.Height,
Sibling.Width,NewSiblingHeight);
end else begin
// alBottom: Sibling, Splitter, NewControl
Sibling.Height:=NewSiblingHeight;
Splitter.SetBounds(Sibling.Left,Sibling.Top+Sibling.Height,
Sibling.Width,Splitter.Height);
NewSite.SetBounds(Sibling.Left,Splitter.Top+Splitter.Height,
Sibling.Width,NewSize);
end;
end;
end else begin
{ Example: insert right of all siblings
########## #######################
--------+# --------+#+----------+#
SiblingA|# SiblingA|#| |#
--------+# --------+#| |#
########## -----> ##########|NewControl|#
--------+# --------+#| |#
SiblingB|# SiblingB|#| |#
--------+# --------+#+----------+#
########## #######################
}
if DockAlign in [alLeft,alRight] then
NewSize:=NewSite.Width
else
NewSize:=NewSite.Height;
for i:=0 to ControlCount-1 do begin
Sibling:=Controls[i];
if Sibling.AnchorSide[MainAnchor].Control=Self then begin
// this Sibling is anchored to the docked site
// anchor it to the splitter
Sibling.AnchorToNeighbour(MainAnchor,0,Splitter);
if not BoundsIncreased then begin
// the NewSite gets at most half the space
if DockAlign in [alLeft,alRight] then
NewSize:=Min(NewSize,Sibling.Width div 2)
else
NewSize:=Min(NewSize,Sibling.Height div 2);
end;
end;
end;
NewSize:=Max(1,NewSize);
// anchor Splitter and NewSite
a:=ClockwiseAnchor[MainAnchor];
Splitter.AnchorParallel(a,0,Self);
Splitter.AnchorParallel(OppositeAnchor[a],0,Self);
NewSite.AnchorParallel(a,0,Self);
NewSite.AnchorParallel(OppositeAnchor[a],0,Self);
NewSite.AnchorParallel(MainAnchor,0,Self);
NewSite.AnchorToNeighbour(OppositeAnchor[MainAnchor],0,Splitter);
// Many bounds are later set by the LCL anchoring. When docking several
// controls at once the bounds are needed earlier.
if DockAlign in [alLeft,alRight] then begin
if DockAlign=alLeft then begin
// alLeft: NewSite, Splitter, other siblings
Splitter.SetBounds(NewSize,0,Splitter.Width,ClientHeight);
NewSite.SetBounds(0,0,NewSize,ClientHeight);
end else begin
// alRight: other siblings, Splitter, NewSite
NewSite.SetBounds(ClientWidth-NewSize,0,NewSize,ClientHeight);
Splitter.SetBounds(NewSite.Left-Splitter.Width,0,Splitter.Width,ClientHeight);
end;
end else begin
if DockAlign=alTop then begin
// alTop: NewSite, Splitter, other siblings
Splitter.SetBounds(0,NewSize,ClientWidth,Splitter.Height);
NewSite.SetBounds(0,0,ClientWidth,NewSize);
end else begin
// alBottom: other siblings, Splitter, NewSite
NewSite.SetBounds(0,ClientHeight-NewSize,ClientWidth,NewSize);
Splitter.SetBounds(0,NewSite.Top-Splitter.Height,ClientWidth,Splitter.Height);
end;
end;
// shrink siblings
for i:=0 to ControlCount-1 do begin
Sibling:=Controls[i];
if Sibling.AnchorSide[MainAnchor].Control=Splitter then begin
NewBounds:=Sibling.BoundsRect;
case DockAlign of
alLeft: NewBounds.Left:=Splitter.Left+Splitter.Width;
alRight: NewBounds.Right:=Splitter.Left;
alTop: NewBounds.Top:=Splitter.Top+Splitter.Height;
alBottom: NewBounds.Bottom:=Splitter.Top;
end;
NewBounds.Right:=Max(NewBounds.Left+1,NewBounds.Right);
NewBounds.Bottom:=Max(NewBounds.Top+1,NewBounds.Bottom);
Sibling.BoundsRect:=NewBounds;
end;
end;
end;
//debugln(['TAnchorDockHostSite.DockAnotherControl ',DbgSName(Self)]);
//DebugWriteChildAnchors(Self,true,true);
Result:=true;
end;
procedure TAnchorDockHostSite.CreatePages;
begin
if FPages<>nil then
RaiseGDBException('');
FPages:=DockMaster.PageControlClass.Create(nil); // do not own it, pages can be moved to another site
FPages.FreeNotification(Self);
FPages.Parent:=Self;
FPages.Align:=alClient;
end;
procedure TAnchorDockHostSite.FreePages;
begin
FreeAndNil(FPages);
end;
function TAnchorDockHostSite.DockSecondPage(NewControl: TControl): boolean;
var
OldControl: TControl;
OldSite: TAnchorDockHostSite;
begin
{$IFDEF VerboseAnchorDockPages}
debugln(['TAnchorDockHostSite.DockSecondPage Self="',Caption,'" AControl=',DbgSName(NewControl)]);
{$ENDIF}
if SiteType<>adhstOneControl then
RaiseGDBException('TAnchorDockHostSite.DockSecondPage inconsistency');
FSiteType:=adhstPages;
CreatePages;
// remove header (keep it for later use)
{$IFDEF VerboseAnchorDockPages}
debugln(['TAnchorDockHostSite.DockSecondPage Self="',Caption,'" removing header ...']);
{$ENDIF}
Header.Parent:=nil;
// put the OldControl into a page of its own
{$IFDEF VerboseAnchorDockPages}
debugln(['TAnchorDockHostSite.DockSecondPage Self="',Caption,'" move oldcontrol to site of its own ...']);
{$ENDIF}
OldControl:=GetOneControl;
OldSite:=MakeSite(OldControl);
OldSite.HostDockSite:=nil;
{$IFDEF VerboseAnchorDockPages}
debugln(['TAnchorDockHostSite.DockSecondPage Self="',Caption,'" adding oldcontrol site ...']);
{$ENDIF}
FPages.Pages.Add(OldSite.Caption);
OldSite.Parent:=FPages.Page[0];
OldSite.Align:=alClient;
OldSite.Visible:=true;
Result:=DockAnotherPage(NewControl,nil);
end;
function TAnchorDockHostSite.DockAnotherPage(NewControl: TControl;
InFrontOf: TControl): boolean;
var
NewSite: TAnchorDockHostSite;
NewIndex: LongInt;
begin
{$IFDEF VerboseAnchorDockPages}
debugln(['TAnchorDockHostSite.DockAnotherPage Self="',Caption,'" make new control (',DbgSName(NewControl),') dockable ...']);
{$ENDIF}
if SiteType<>adhstPages then
RaiseGDBException('TAnchorDockHostSite.DockAnotherPage inconsistency');
NewSite:=MakeSite(NewControl);
//debugln(['TAnchorDockHostSite.DockAnotherPage Self="',Caption,'" adding newcontrol site ...']);
NewIndex:=FPages.PageCount;
if (InFrontOf is TAnchorDockPage)
and (InFrontOf.Parent=Pages) then
NewIndex:=TAnchorDockPage(InFrontOf).PageIndex;
Pages.Pages.Insert(NewIndex,NewSite.Caption);
//debugln(['TAnchorDockHostSite.DockAnotherPage ',DbgSName(FPages.Page[1])]);
NewSite.Parent:=FPages.Page[NewIndex];
NewSite.Align:=alClient;
NewSite.Visible:=true;
FPages.PageIndex:=NewIndex;
Result:=true;
end;
procedure TAnchorDockHostSite.AddCleanControl(AControl: TControl;
TheAlign: TAlign);
var
a: TAnchorKind;
begin
AControl.Parent:=Self;
AControl.Align:=TheAlign;
AControl.Anchors:=[akLeft,akTop,akRight,akBottom];
for a:=Low(TAnchorKind) to high(TAnchorKind) do
AControl.AnchorSide[a].Control:=nil;
AControl.Visible:=true;
end;
procedure TAnchorDockHostSite.RemoveControlFromLayout(AControl: TControl);
procedure RemoveControlBoundSplitter(Splitter: TAnchorDockSplitter;
Side: TAnchorKind);
var
i: Integer;
Sibling: TControl;
NewBounds: TRect;
begin
//debugln(['RemoveControlBoundSplitter START ',DbgSName(Splitter)]);
{ Example: Side=akRight
# #
##################### #########
---+S+--------+# ---+#
---+S|AControl|# ---> ---+#
---+S+--------+# ---+#
##################### #########
}
for i:=Splitter.AnchoredControlCount-1 downto 0 do begin
Sibling:=Splitter.AnchoredControls[i];
if Sibling.AnchorSide[Side].Control=Splitter then begin
// anchor Sibling to next
Sibling.AnchorSide[Side].Assign(AControl.AnchorSide[Side]);
// enlarge Sibling
NewBounds:=Sibling.BoundsRect;
case Side of
akTop: NewBounds.Top:=AControl.Top;
akLeft: NewBounds.Left:=AControl.Left;
akRight: NewBounds.Right:=AControl.Left+AControl.Width;
akBottom: NewBounds.Bottom:=AControl.Top+AControl.Height;
end;
Sibling.BoundsRect:=NewBounds;
end;
end;
//debugln(['RemoveControlBoundSplitter ',DbgSName(Splitter)]);
Splitter.Free;
ClearChildControlAnchorSides(AControl);
//DebugWriteChildAnchors(GetParentForm(Self),true,true);
end;
procedure ConvertToOneControlType(OnlySiteLeft: TAnchorDockHostSite);
var
a: TAnchorKind;
NewBounds: TRect;
p: TPoint;
i: Integer;
Sibling: TControl;
NewParentBounds: TRect;
begin
BeginUpdateLayout;
try
// remove splitter
for i:=ControlCount-1 downto 0 do begin
Sibling:=Controls[i];
if Sibling is TAnchorDockSplitter then
Sibling.Free
else if Sibling is TAnchorDockHostSite then
for a:=low(TAnchorKind) to high(TAnchorKind) do
Sibling.AnchorSide[a].Control:=nil;
end;
if (Parent=nil) then begin
// shrink this site
NewBounds:=OnlySiteLeft.BoundsRect;
p:=ClientOrigin;
OffsetRect(NewBounds,p.x,p.y);
BoundsRect:=NewBounds;
end else if DockMaster.IsCustomSite(Parent) then begin
// parent is a custom dock site
// shrink this site and the parent
NewParentBounds:=Parent.BoundsRect;
case Align of
alTop:
begin
inc(NewParentBounds.Top,Height-OnlySiteLeft.Height);
Width:=Parent.ClientWidth;
Height:=OnlySiteLeft.Height;
end;
alBottom:
begin
dec(NewParentBounds.Bottom,Height-OnlySiteLeft.Height);
Width:=Parent.ClientWidth;
Height:=OnlySiteLeft.Height;
end;
alLeft:
begin
inc(NewParentBounds.Left,Width-OnlySiteLeft.Width);
Width:=OnlySiteLeft.Width;
Height:=Parent.ClientHeight;
end;
alRight:
begin
dec(NewParentBounds.Right,Width-OnlySiteLeft.Width);
Width:=OnlySiteLeft.Width;
Height:=Parent.ClientHeight;
end;
end;
Parent.BoundsRect:=NewParentBounds;
end;
// change type
FSiteType:=adhstOneControl;
OnlySiteLeft.Align:=alClient;
Header.Parent:=Self;
UpdateHeaderAlign;
//debugln(['TAnchorDockHostSite.RemoveControlFromLayout.ConvertToOneControlType AFTER CONVERT "',Caption,'" to onecontrol OnlySiteLeft="',OnlySiteLeft.Caption,'"']);
//DebugWriteChildAnchors(GetParentForm(Self),true,true);
DockMaster.NeedSimplify(Self);
finally
EndUpdateLayout;
end;
end;
var
Side: TAnchorKind;
Splitter: TAnchorDockSplitter;
OnlySiteLeft: TAnchorDockHostSite;
Sibling: TControl;
SplitterCount: Integer;
begin
debugln(['TAnchorDockHostSite.RemoveControlFromLayout Self="',Caption,'" AControl=',DbgSName(AControl),'="',AControl.Caption,'"']);
if SiteType<>adhstLayout then
RaiseGDBException('TAnchorDockHostSite.RemoveControlFromLayout inconsistency');
if IsOneSiteLayout(OnlySiteLeft) then begin
ClearChildControlAnchorSides(AControl);
ConvertToOneControlType(OnlySiteLeft);
exit;
end;
// remove a splitter and fill the gap
SplitterCount:=0;
for Side:=Low(TAnchorKind) to high(TAnchorKind) do begin
Sibling:=AControl.AnchorSide[OppositeAnchor[Side]].Control;
if Sibling is TAnchorDockSplitter then begin
inc(SplitterCount);
Splitter:=TAnchorDockSplitter(Sibling);
if Splitter.SideAnchoredControlCount(Side)=1 then begin
// Splitter is only used by AControl at Side
RemoveControlBoundSplitter(Splitter,Side);
exit;
end;
end;
end;
if SplitterCount=4 then begin
RemoveSpiralSplitter(AControl);
exit;
end;
ClearChildControlAnchorSides(AControl);
end;
procedure TAnchorDockHostSite.RemoveSpiralSplitter(AControl: TControl);
{ Merge two splitters and delete one of them.
Prefer the pair with shortest distance between.
For example:
3 3
111111111111113 3
2+--------+3 3
2|AControl|3 ---> 111111111
2+--------+3 2
24444444444444 2
2 2
Everything anchored to 4 is now anchored to 1.
And right side of 1 is now anchored to where the right side of 4 was anchored.
}
var
Splitters: array[TAnchorKind] of TAnchorDockSplitter;
Side: TAnchorKind;
Keep: TAnchorKind;
DeleteSplitter: TAnchorDockSplitter;
i: Integer;
Sibling: TControl;
NextSide: TAnchorKind;
NewBounds: TRect;
begin
for Side:=low(TAnchorKind) to high(TAnchorKind) do
Splitters[Side]:=AControl.AnchorSide[Side].Control as TAnchorDockSplitter;
// Prefer the pair with shortest distance between
if (Splitters[akRight].Left-Splitters[akLeft].Left)
<(Splitters[akBottom].Top-Splitters[akTop].Top)
then
Keep:=akLeft
else
Keep:=akTop;
DeleteSplitter:=Splitters[OppositeAnchor[Keep]];
// transfer anchors from the deleting splitter to the kept splitter
for i:=0 to ControlCount-1 do begin
Sibling:=Controls[i];
for Side:=low(TAnchorKind) to high(TAnchorKind) do begin
if Sibling.AnchorSide[Side].Control=DeleteSplitter then
Sibling.AnchorSide[Side].Control:=Splitters[Keep];
end;
end;
// longen kept splitter
NextSide:=ClockwiseAnchor[Keep];
if Splitters[Keep].AnchorSide[NextSide].Control<>Splitters[NextSide] then
NextSide:=OppositeAnchor[NextSide];
Splitters[Keep].AnchorSide[NextSide].Control:=
DeleteSplitter.AnchorSide[NextSide].Control;
case NextSide of
akTop: Splitters[Keep].Top:=DeleteSplitter.Top;
akLeft: Splitters[Keep].Left:=DeleteSplitter.Left;
akRight: Splitters[Keep].Width:=DeleteSplitter.Left+DeleteSplitter.Width-Splitters[Keep].Left;
akBottom: Splitters[Keep].Height:=DeleteSplitter.Top+DeleteSplitter.Height-Splitters[Keep].Top;
end;
// move splitter to the middle
if Keep=akLeft then
Splitters[Keep].Left:=(Splitters[Keep].Left+DeleteSplitter.Left) div 2
else
Splitters[Keep].Top:=(Splitters[Keep].Top+DeleteSplitter.Top) div 2;
// adjust all anchored controls
for i:=0 to ControlCount-1 do begin
Sibling:=Controls[i];
for Side:=low(TAnchorKind) to high(TAnchorKind) do begin
if Sibling.AnchorSide[Side].Control=Splitters[Keep] then begin
NewBounds:=Sibling.BoundsRect;
case Side of
akTop: NewBounds.Top:=Splitters[Keep].Top+Splitters[Keep].Height;
akLeft: NewBounds.Left:=Splitters[Keep].Left+Splitters[Keep].Width;
akRight: NewBounds.Right:=Splitters[Keep].Left;
akBottom: NewBounds.Bottom:=Splitters[Keep].Top;
end;
Sibling.BoundsRect:=NewBounds;
end;
end;
end;
// delete the splitter
DeleteSplitter.Free;
ClearChildControlAnchorSides(AControl);
end;
procedure TAnchorDockHostSite.ClearChildControlAnchorSides(AControl: TControl);
var
Side: TAnchorKind;
Sibling: TControl;
begin
for Side:=Low(TAnchorKind) to high(TAnchorKind) do begin
Sibling:=AControl.AnchorSide[Side].Control;
if (Sibling=nil) then continue;
if (Sibling.Parent=Self) then
AControl.AnchorSide[Side].Control:=nil;
end;
end;
procedure TAnchorDockHostSite.Simplify;
var
AControl: TControl;
begin
if (Pages<>nil) and (Pages.PageCount=1) then
SimplifyPages
else if (SiteType=adhstOneControl) then begin
AControl:=GetOneControl;
debugln(['TAnchorDockHostSite.Simplify ',DbgSName(Self),' ',DbgSName(AControl)]);
if AControl is TAnchorDockHostSite then
SimplifyOneControl
else if (AControl=nil) or (csDestroying in AControl.ComponentState) then
DockMaster.NeedFree(Self);
end;
end;
procedure TAnchorDockHostSite.SimplifyPages;
var
Page: TAnchorDockPage;
Site: TAnchorDockHostSite;
begin
if Pages=nil then exit;
if DockMaster.IsReleasing(Pages) then exit;
if Pages.PageCount=1 then begin
{$IFDEF VerboseAnchorDockPages}
debugln(['TAnchorDockHostSite.SimplifyPages "',Caption,'" PageCount=1']);
{$ENDIF}
DisableAutoSizing{$IFDEF DebugDisableAutoSizing}('TAnchorDockHostSite.SimplifyPages'){$ENDIF};
BeginUpdateLayout;
try
// move the content of the Page to the place where Pages is
Page:=Pages.DockPages[0];
Site:=Page.GetSite;
Site.Parent:=Self;
if Site<>nil then
CopyAnchorBounds(Pages,Site);
if SiteType=adhstPages then
FSiteType:=adhstOneControl;
// free Pages
DockMaster.NeedFree(Pages);
if SiteType=adhstOneControl then
SimplifyOneControl;
finally
EndUpdateLayout;
EnableAutoSizing{$IFDEF DebugDisableAutoSizing}('TAnchorDockHostSite.SimplifyPages'){$ENDIF};
end;
//debugln(['TAnchorDockHostSite.SimplifyPages END Self="',Caption,'"']);
//DebugWriteChildAnchors(GetParentForm(Self),true,true);
end else if Pages.PageCount=0 then begin
//debugln(['TAnchorDockHostSite.SimplifyPages "',Caption,'" PageCount=0 Self=',dbgs(Pointer(Self))]);
FSiteType:=adhstNone;
FreePages;
DockMaster.NeedSimplify(Self);
end;
end;
procedure TAnchorDockHostSite.SimplifyOneControl;
var
Site: TAnchorDockHostSite;
i: Integer;
Child, PlaceHolder: TControl;
a: TAnchorKind;
begin
if SiteType<>adhstOneControl then exit;
if not IsOneSiteLayout(Site) then exit;
debugln(['TAnchorDockHostSite.SimplifyOneControl Self="',Caption,'" Site="',Site.Caption,'"']);
DisableAutoSizing{$IFDEF DebugDisableAutoSizing}('TAnchorDockHostSite.SimplifyOneControl'){$ENDIF};
BeginUpdateLayout;
try
// move the content of Site up and free Site
// Note: it is not possible to do it the other way round, because moving a
// form to screen changes the z order and focus
FSiteType:=Site.SiteType;
// header
Header.Align:=Site.Header.Align;
Header.Caption:=Site.Header.Caption;
UpdateHeaderShowing;
Caption:=Site.Caption;
Site.BeginUpdateLayout;
// move controls from Site to Self
// when a site is moved to a other parent, we have to insert a place holder
// on old site or the splitters will be removed, see issue #34937
i:=Site.ControlCount-1;
while i>=0 do begin
Child:=Site.Controls[i];
if (Child.Owner<>Site) then begin
if not (Child is TAnchorDockSplitter) then begin
PlaceHolder:=TAnchorDockHostSite.CreateNew(Site);
PlaceHolder.Parent:=Site;
PlaceHolder.Anchors:=Child.Anchors;
for a:=Low(TAnchorKind) to High(TAnchorKind) do
PlaceHolder.AnchorSide[a].Control:=Child.AnchorSide[a].Control;
PlaceHolder.SetBounds(Child.Left, Child.Top, Child.Width, Child.Height);
PlaceHolder.Name:='_'+Child.Name;
PlaceHolder.Visible:=Child.Visible;
end;
Child.Parent:=Self;
if Child=Site.Pages then begin
FPages:=Site.Pages;
Site.FPages:=nil;
end;
if Child.HostDockSite=Site then
Child.HostDockSite:=Self;
for a:=low(TAnchorKind) to high(TAnchorKind) do begin
if Child.AnchorSide[a].Control=Site then
Child.AnchorSide[a].Control:=Self;
end;
end;
i:=Min(i,Site.ControlCount)-1;
end;
for i:=0 to ControlCount-1 do begin
Child:=Controls[i];
PlaceHolder:=TControl(Site.FindComponent('_'+Child.Name));
if not Assigned(PlaceHolder) then continue;
for a:=Low(TAnchorKind) to High(TAnchorKind) do
if PlaceHolder.AnchorSide[a].Control<>Site then
Child.AnchorSide[a].Control:=PlaceHolder.AnchorSide[a].Control;
end;
Site.EndUpdateLayout;
// delete Site
Site.FSiteType:=adhstNone;
DockMaster.NeedFree(Site);
finally
EndUpdateLayout;
EnableAutoSizing{$IFDEF DebugDisableAutoSizing}('TAnchorDockHostSite.SimplifyOneControl'){$ENDIF};
end;
//debugln(['TAnchorDockHostSite.SimplifyOneControl END Self="',Caption,'"']);
//DebugWriteChildAnchors(GetParentForm(Self),true,true);
end;
function TAnchorDockHostSite.GetOneControl: TControl;
var
i: Integer;
begin
for i:=0 to ControlCount-1 do begin
Result:=Controls[i];
if Result.Owner<>Self then exit;
end;
Result:=nil;
end;
function TAnchorDockHostSite.GetSiteCount: integer;
var
i: Integer;
Child: TControl;
begin
Result:=0;
for i:=0 to ControlCount-1 do begin
Child:=Controls[i];
if not (Child is TAnchorDockHostSite) then continue;
if not Child.IsControlVisible then continue;
inc(Result);
end;
end;
function TAnchorDockHostSite.IsOneSiteLayout(out Site: TAnchorDockHostSite
): boolean;
var
i: Integer;
Child: TControl;
begin
Site:=nil;
for i:=0 to ControlCount-1 do begin
Child:=Controls[i];
if not (Child is TAnchorDockHostSite) then continue;
if not Child.IsControlVisible then continue;
if Site<>nil then exit(false);
Site:=TAnchorDockHostSite(Child);
end;
Result:=Site<>nil;
end;
function TAnchorDockHostSite.IsTwoSiteLayout(out Site1,
Site2: TAnchorDockHostSite): boolean;
var
i: Integer;
Child: TControl;
begin
Site1:=nil;
Site2:=nil;
for i:=0 to ControlCount-1 do begin
Child:=Controls[i];
if not (Child is TAnchorDockHostSite) then continue;
if not Child.IsControlVisible then continue;
if Site1=nil then
Site1:=TAnchorDockHostSite(Child)
else if Site2=nil then
Site2:=TAnchorDockHostSite(Child)
else
exit(false);
end;
Result:=Site2<>nil;
end;
function TAnchorDockHostSite.GetUniqueSplitterName: string;
var
i: Integer;
begin
i:=0;
repeat
inc(i);
Result:=AnchorDockSplitterName+IntToStr(i);
until FindComponent(Result)=nil;
end;
function TAnchorDockHostSite.MakeSite(AControl: TControl): TAnchorDockHostSite;
begin
if AControl is TAnchorDockHostSite then
Result:=TAnchorDockHostSite(AControl)
else begin
Result:=DockMaster.CreateSite;
try
AControl.ManualDock(Result,nil,alClient);
finally
Result.EnableAutoSizing{$IFDEF DebugDisableAutoSizing}(ADAutoSizingReason){$ENDIF};
end;
end;
end;
procedure TAnchorDockHostSite.MoveAllControls(dx, dy: integer);
// move all children, except the sides that are anchored to parent left,top
var
i: Integer;
Child: TControl;
NewBounds: TRect;
begin
for i:=0 to ControlCount-1 do begin
Child:=Controls[i];
NewBounds:=Child.BoundsRect;
OffsetRect(NewBounds,dx,dy);
if Child.AnchorSideLeft.Control=Self then
NewBounds.Left:=0;
if Child.AnchorSideTop.Control=Self then
NewBounds.Top:=0;
Child.BoundsRect:=NewBounds;
end;
end;
procedure TAnchorDockHostSite.AlignControls(AControl: TControl; var ARect: TRect);
var
i: Integer;
Child: TControl;
Splitter: TAnchorDockSplitter;
begin
inherited AlignControls(AControl, ARect);
if csDestroying in ComponentState then exit;
if DockMaster.ScaleOnResize and (not UpdatingLayout)
and (not DockMaster.Restoring) then begin
// scale splitters
for i:=0 to ControlCount-1 do begin
Child:=Controls[i];
if not Child.IsControlVisible then continue;
if Child is TAnchorDockSplitter then begin
Splitter:=TAnchorDockSplitter(Child);
//debugln(['TAnchorDockHostSite.AlignControls ',Caption,' ',DbgSName(Splitter),' OldBounds=',dbgs(Splitter.BoundsRect),' BaseBounds=',dbgs(Splitter.DockBounds),' BaseParentSize=',dbgs(Splitter.DockParentClientSize),' ParentSize=',ClientWidth,'x',ClientHeight]);
Splitter.SetBoundsPercentually;
//debugln(['TAnchorDockHostSite.AlignControls ',Caption,' ',DbgSName(Child),' NewBounds=',dbgs(Child.BoundsRect)]);
end;
end;
end;
end;
function TAnchorDockHostSite.CheckIfOneControlHidden: boolean;
var
Child: TControl;
begin
Result:=false;
//debugln(['TAnchorDockHostSite.CheckIfOneControlHidden ',DbgSName(Self),' UpdatingLayout=',UpdatingLayout,' Visible=',Visible,' Parent=',DbgSName(Parent),' csDestroying=',csDestroying in ComponentState,' SiteType=',dbgs(SiteType)]);
if UpdatingLayout or (not IsControlVisible)
or (csDestroying in ComponentState)
or (SiteType<>adhstOneControl)
then
exit;
Child:=GetOneControl;
if (Child=nil) then exit;
if Child.IsControlVisible then exit;
// docked child was hidden/closed
Result:=true;
// => undock
BeginUpdateLayout;
DisableAutoSizing{$IFDEF DebugDisableAutoSizing}('TAnchorDockHostSite.CheckIfOneControlHidden'){$ENDIF};
try
debugln(['TAnchorDockHostSite.CheckIfOneControlHidden ',DbgSName(Self),' UpdatingLayout=',UpdatingLayout,' Visible=',Visible,' Parent=',DbgSName(Parent),' csDestroying=',csDestroying in ComponentState,' SiteType=',dbgs(SiteType),' Child=',DbgSName(Child),' Child.csDestroying=',csDestroying in Child.ComponentState]);
Visible:=false;
Parent:=nil;
finally
EnableAutoSizing{$IFDEF DebugDisableAutoSizing}('TAnchorDockHostSite.CheckIfOneControlHidden'){$ENDIF};
end;
EndUpdateLayout;
if (not (Child is TCustomForm)) or (csDestroying in Child.ComponentState) then
Release;
end;
procedure TAnchorDockHostSite.DoDock(NewDockSite: TWinControl; var ARect: TRect);
begin
inherited DoDock(NewDockSite, ARect);
if DockMaster <> nil then
DockMaster.SimplifyPendingLayouts;
end;
procedure TAnchorDockHostSite.SetParent(NewParent: TWinControl);
var
OldCaption: string;
OldParent: TWinControl;
begin
OldParent:=Parent;
if NewParent=OldParent then exit;
inherited SetParent(NewParent);
OldCaption:=Caption;
UpdateDockCaption;
if OldCaption<>Caption then begin
// UpdateDockCaption has not updated parents => do it now
if Parent is TAnchorDockHostSite then
TAnchorDockHostSite(Parent).UpdateDockCaption;
if Parent is TAnchorDockPage then
TAnchorDockPage(Parent).UpdateDockCaption;
end;
UpdateHeaderShowing;
if (BoundSplitter<>nil) and (BoundSplitter.Parent<>Parent) then begin
//debugln(['TAnchorDockHostSite.SetParent freeing splitter: ',DbgSName(BoundSplitter)]);
FreeAndNil(FBoundSplitter);
end;
if Parent=nil then
BorderStyle:=bsSizeable
else
BorderStyle:=bsNone;
end;
function TAnchorDockHostSite.HeaderNeedsShowing: boolean;
begin
Result:=(SiteType<>adhstLayout)
and (not (Parent is TAnchorDockPage))
and Assigned(DockMaster) and DockMaster.ShowHeader;
end;
procedure TAnchorDockHostSite.DoClose(var CloseAction: TCloseAction);
begin
inherited DoClose(CloseAction);
end;
function TAnchorDockHostSite.CanUndock: boolean;
begin
Result:=Parent<>nil;
end;
procedure TAnchorDockHostSite.Undock;
var
p: TPoint;
begin
if Parent=nil then exit;
DisableAutoSizing{$IFDEF DebugDisableAutoSizing}('TAnchorDockHostSite.Undock'){$ENDIF};
try
p := Point(0,0);
p := ClientToScreen(p);
Parent:=nil;
SetBounds(p.x,p.y,Width,Height);
finally
EnableAutoSizing{$IFDEF DebugDisableAutoSizing}('TAnchorDockHostSite.Undock'){$ENDIF};
end;
end;
function TAnchorDockHostSite.CanMerge: boolean;
begin
Result:=(SiteType=adhstLayout)
and (Parent is TAnchorDockHostSite)
and (TAnchorDockHostSite(Parent).SiteType=adhstLayout);
end;
procedure TAnchorDockHostSite.Merge;
{ Move all child controls to parent and delete this site
}
var
ParentSite: TAnchorDockHostSite;
i: Integer;
Child: TControl;
Side: TAnchorKind;
begin
ParentSite:=Parent as TAnchorDockHostSite;
if (SiteType<>adhstLayout) or (ParentSite.SiteType<>adhstLayout) then
RaiseGDBException('');
ParentSite.BeginUpdateLayout;
DisableAutoSizing{$IFDEF DebugDisableAutoSizing}('TAnchorDockHostSite.Merge'){$ENDIF};
try
for i := ControlCount - 1 downto 0 do begin
Child := Controls[i];
if Child.Owner <> Self then
begin
Child.Parent := ParentSite;
Child.SetBounds(Child.Left + Left, Child.Top + Top, Child.Width, Child.Height);
for Side := Low(TAnchorKind) to High(TAnchorKind) do
if Child.AnchorSide[Side].Control = Self then
Child.AnchorSide[Side].Assign(AnchorSide[Side]);
end;
end;
Parent:=nil;
DockMaster.NeedFree(Self);
finally
ParentSite.EndUpdateLayout;
// not needed, because this site is freed: EnableAutoSizing;
end;
end;
function TAnchorDockHostSite.EnlargeSide(Side: TAnchorKind;
OnlyCheckIfPossible: boolean): boolean;
{
Shrink one splitter, enlarge the other splitter.
|#| |# |#| |#
|#| Control |# |#| |#
--+#+---------+# --> --+#| Control |#
===============# ===#| |#
--------------+# --+#| |#
A |# A|#| |#
--------------+# --+#+---------+#
================== ===================
Move one neighbor splitter, enlarge Control, resize one splitter, rotate the other splitter.
|#| |#| |#| |#|
|#| Control |#| |#| |#|
--+#+---------+#+-- --> --+#| Control |#+--
=================== ===#| |#===
--------+#+-------- --+#| |#+--
|#| B |#| |#|B
|#+-------- |#| |#+--
A |#========= A|#| |#===
|#+-------- |#| |#+--
|#| C |#| |#|C
--------+#+-------- --+#+---------+#+--
=================== ===================
}
begin
Result:=true;
if EnlargeSideResizeTwoSplitters(Side,ClockwiseAnchor[Side],
OnlyCheckIfPossible) then exit;
if EnlargeSideResizeTwoSplitters(Side,OppositeAnchor[ClockwiseAnchor[Side]],
OnlyCheckIfPossible) then exit;
if EnlargeSideRotateSplitter(Side,OnlyCheckIfPossible) then exit;
Result:=false;
end;
function TAnchorDockHostSite.EnlargeSideResizeTwoSplitters(ShrinkSplitterSide,
EnlargeSpitterSide: TAnchorKind; OnlyCheckIfPossible: boolean): boolean;
{ Shrink one neighbor control, enlarge Self. Two splitters are resized.
For example: ShrinkSplitterSide=akBottom, EnlargeSpitterSide=akLeft
|#| |# |#| |#
|#| Self |# |#| |#
--+#+--------+# --> --+#| Self |#
==============# ===#| |#
-------------+# --+#| |#
A |# A|#| |#
-------------+# --+#+--------+#
================= ==================
}
var
ParentSite: TAnchorDockHostSite;
ShrinkSplitter: TAnchorDockSplitter;
EnlargeSplitter: TAnchorDockSplitter;
KeptSide: TAnchorKind;
KeptAnchorControl: TControl;
Sibling: TControl;
ShrinkControl: TControl;
i: Integer;
begin
Result:=false;
if not (Parent is TAnchorDockHostSite) then exit;
ParentSite:=TAnchorDockHostSite(Parent);
if not OnlyCheckIfPossible then begin
ParentSite.BeginUpdateLayout;
ParentSite.DisableAutoSizing{$IFDEF DebugDisableAutoSizing}('TAnchorDockHostSite.EnlargeSideResizeTwoSplitters'){$ENDIF};
end;
try
// check ShrinkSplitter
ShrinkSplitter:=TAnchorDockSplitter(AnchorSide[ShrinkSplitterSide].Control);
if not (ShrinkSplitter is TAnchorDockSplitter) then exit;
// check if EnlargeSpitterSide is a neighbor ShrinkSplitterSide
if (EnlargeSpitterSide<>ClockwiseAnchor[ShrinkSplitterSide])
and (EnlargeSpitterSide<>OppositeAnchor[ClockwiseAnchor[ShrinkSplitterSide]]) then
exit;
// check EnlargeSpitter
EnlargeSplitter:=TAnchorDockSplitter(AnchorSide[EnlargeSpitterSide].Control);
if not (EnlargeSplitter is TAnchorDockSplitter) then exit;
// check if KeptSide is anchored to a splitter or parent
KeptSide:=OppositeAnchor[EnlargeSpitterSide];
KeptAnchorControl:=AnchorSide[KeptSide].Control;
if not ((KeptAnchorControl=ParentSite)
or (KeptAnchorControl is TAnchorDockSplitter)) then exit;
// check if ShrinkSplitter is anchored/stops at KeptAnchorControl
if ShrinkSplitter.AnchorSide[KeptSide].Control<>KeptAnchorControl then exit;
// check if there is a control to shrink
ShrinkControl:=nil;
for i:=0 to ShrinkSplitter.AnchoredControlCount-1 do begin
Sibling:=ShrinkSplitter.AnchoredControls[i];
if (Sibling.AnchorSide[OppositeAnchor[ShrinkSplitterSide]].Control=ShrinkSplitter)
and (Sibling.AnchorSide[KeptSide].Control=KeptAnchorControl) then begin
ShrinkControl:=Sibling;
break;
end;
end;
if ShrinkControl=nil then exit;
if OnlyCheckIfPossible then begin
// check if ShrinkControl is large enough for shrinking
case EnlargeSpitterSide of
akTop: if ShrinkControl.Top>=EnlargeSplitter.Top then exit;
akLeft: if ShrinkControl.Left>=EnlargeSplitter.Left then exit;
akRight: if ShrinkControl.Left+ShrinkControl.Width
<=EnlargeSplitter.Left+EnlargeSplitter.Width then exit;
akBottom: if ShrinkControl.Top+ShrinkControl.Height
<=EnlargeSplitter.Top+EnlargeSplitter.Height then exit;
end;
end else begin
// do it
// enlarge the EnlargeSplitter and Self
AnchorAndChangeBounds(EnlargeSplitter,ShrinkSplitterSide,
ShrinkControl.AnchorSide[ShrinkSplitterSide].Control);
AnchorAndChangeBounds(Self,ShrinkSplitterSide,
ShrinkControl.AnchorSide[ShrinkSplitterSide].Control);
// shrink the ShrinkSplitter and ShrinkControl
AnchorAndChangeBounds(ShrinkSplitter,KeptSide,EnlargeSplitter);
AnchorAndChangeBounds(ShrinkControl,KeptSide,EnlargeSplitter);
end;
finally
if not OnlyCheckIfPossible then begin
ParentSite.EnableAutoSizing{$IFDEF DebugDisableAutoSizing}('TAnchorDockHostSite.EnlargeSideResizeTwoSplitters'){$ENDIF};
ParentSite.EndUpdateLayout;
end;
end;
Result:=true;
end;
function TAnchorDockHostSite.EnlargeSideRotateSplitter(Side: TAnchorKind;
OnlyCheckIfPossible: boolean): boolean;
{ Shrink splitter at Side, enlarge both neighbor splitters,
rotate the splitter behind, enlarge Control,
shrink controls at rotate splitter
|#| |#| |#| |#|
|#| Control |#| |#| |#|
--+#+---------+#+-- --> --+#| Control |#+--
=================== ===#| |#===
--------+#+-------- --+#| |#+--
|#| B |#| |#|B
|#+-------- |#| |#+--
A |#========= A|#| |#===
|#+-------- |#| |#+--
|#| C |#| |#|C
--------+#+-------- --+#+---------+#+--
=================== ===================
}
var
Splitter: TAnchorDockSplitter;
CWSide: TAnchorKind;
CWSplitter: TAnchorDockSplitter;
CCWSide: TAnchorKind;
i: Integer;
Sibling: TControl;
BehindSide: TAnchorKind;
RotateSplitter: TAnchorDockSplitter;
CCWSplitter: TAnchorDockSplitter;
begin
Result:=false;
// check if there is a splitter at Side
Splitter:=TAnchorDockSplitter(AnchorSide[Side].Control);
if not (Splitter is TAnchorDockSplitter) then exit;
// check if there is a splitter at clockwise Side
CWSide:=ClockwiseAnchor[Side];
CWSplitter:=TAnchorDockSplitter(AnchorSide[CWSide].Control);
if not (CWSplitter is TAnchorDockSplitter) then exit;
// check if there is a splitter at counter clockwise Side
CCWSide:=OppositeAnchor[CWSide];
CCWSplitter:=TAnchorDockSplitter(AnchorSide[CCWSide].Control);
if not (CCWSplitter is TAnchorDockSplitter) then exit;
// check if neighbor splitters end at Splitter
if CWSplitter.AnchorSide[Side].Control<>Splitter then exit;
if CCWSplitter.AnchorSide[Side].Control<>Splitter then exit;
// find the rotate splitter behind Splitter
BehindSide:=OppositeAnchor[Side];
RotateSplitter:=nil;
for i:=0 to Splitter.AnchoredControlCount-1 do begin
Sibling:=Splitter.AnchoredControls[i];
if Sibling.AnchorSide[BehindSide].Control<>Splitter then continue;
if not (Sibling is TAnchorDockSplitter) then continue;
if Side in [akLeft,akRight] then begin
if Sibling.Top<Top-DockMaster.SplitterWidth then continue;
if Sibling.Top>Top+Height then continue;
end else begin
if Sibling.Left<Left-DockMaster.SplitterWidth then continue;
if Sibling.Left>Left+Width then continue;
end;
if RotateSplitter=nil then
RotateSplitter:=TAnchorDockSplitter(Sibling)
else
// there are multiple splitters behind
exit;
end;
if RotateSplitter=nil then exit;
// check that all siblings at RotateSplitter are large enough to shrink
for i:=0 to RotateSplitter.AnchoredControlCount-1 do begin
Sibling:=RotateSplitter.AnchoredControls[i];
if Side in [akLeft,akRight] then begin
if (Sibling.Top>Top-DockMaster.SplitterWidth)
and (Sibling.Top+Sibling.Height<Top+Height+DockMaster.SplitterWidth) then
exit;
end else begin
if (Sibling.Left>Left-DockMaster.SplitterWidth)
and (Sibling.Left+Sibling.Width<Left+Width+DockMaster.SplitterWidth) then
exit;
end;
end;
Result:=true;
if OnlyCheckIfPossible then exit;
//debugln(['TAnchorDockHostSite.EnlargeSideRotateSplitter BEFORE Self=',DbgSName(Self),'=',dbgs(BoundsRect),' Side=',dbgs(Side),' CWSide=',dbgs(CWSide),' CWSplitter=',CWSplitter.Name,'=',dbgs(CWSplitter.BoundsRect),' CCWSide=',dbgs(CCWSide),' CCWSplitter=',CCWSplitter.Name,'=',dbgs(CCWSplitter.BoundsRect),' Behind=',dbgs(BehindSide),'=',RotateSplitter.Name,'=',dbgs(RotateSplitter.BoundsRect)]);
DisableAutoSizing{$IFDEF DebugDisableAutoSizing}('TAnchorDockHostSite.EnlargeSideRotateSplitter'){$ENDIF};
try
// enlarge the two neighbor splitters
AnchorAndChangeBounds(CWSplitter,Side,RotateSplitter.AnchorSide[Side].Control);
AnchorAndChangeBounds(CCWSplitter,Side,RotateSplitter.AnchorSide[Side].Control);
// enlarge control
AnchorAndChangeBounds(Self,Side,RotateSplitter.AnchorSide[Side].Control);
// shrink the neighbors and anchor them to the enlarge splitters
for i:=0 to Parent.ControlCount-1 do begin
Sibling:=Parent.Controls[i];
if Sibling.AnchorSide[CWSide].Control=RotateSplitter then
AnchorAndChangeBounds(Sibling,CWSide,CCWSplitter)
else if Sibling.AnchorSide[CCWSide].Control=RotateSplitter then
AnchorAndChangeBounds(Sibling,CCWSide,CWSplitter);
end;
// rotate the RotateSplitter
RotateSplitter.AnchorSide[Side].Control:=nil;
RotateSplitter.AnchorSide[BehindSide].Control:=nil;
RotateSplitter.ResizeAnchor:=Side;
AnchorAndChangeBounds(RotateSplitter,CCWSide,Splitter.AnchorSide[CCWSide].Control);
AnchorAndChangeBounds(RotateSplitter,CWSide,CCWSplitter);
if Side in [akLeft,akRight] then begin
RotateSplitter.Left:=Splitter.Left;
RotateSplitter.Width:=DockMaster.SplitterWidth;
end else begin
RotateSplitter.Top:=Splitter.Top;
RotateSplitter.Height:=DockMaster.SplitterWidth;
end;
// shrink Splitter
AnchorAndChangeBounds(Splitter,CCWSide,CWSplitter);
// anchor some siblings of Splitter to RotateSplitter
for i:=0 to Parent.ControlCount-1 do begin
Sibling:=Parent.Controls[i];
case Side of
akLeft: if Sibling.Top<Top then continue;
akRight: if Sibling.Top>Top then continue;
akTop: if Sibling.Left>Left then continue;
akBottom: if Sibling.Left<Left then continue;
end;
if Sibling.AnchorSide[BehindSide].Control=Splitter then
Sibling.AnchorSide[BehindSide].Control:=RotateSplitter
else if Sibling.AnchorSide[Side].Control=Splitter then
Sibling.AnchorSide[Side].Control:=RotateSplitter;
end;
//debugln(['TAnchorDockHostSite.EnlargeSideRotateSplitter AFTER Self=',DbgSName(Self),'=',dbgs(BoundsRect),' Side=',dbgs(Side),' CWSide=',dbgs(CWSide),' CWSplitter=',CWSplitter.Name,'=',dbgs(CWSplitter.BoundsRect),' CCWSide=',dbgs(CCWSide),' CCWSplitter=',CCWSplitter.Name,'=',dbgs(CCWSplitter.BoundsRect),' Behind=',dbgs(BehindSide),'=',RotateSplitter.Name,'=',dbgs(RotateSplitter.BoundsRect)]);
finally
EnableAutoSizing{$IFDEF DebugDisableAutoSizing}('TAnchorDockHostSite.EnlargeSideRotateSplitter'){$ENDIF};
end;
end;
procedure TAnchorDockHostSite.CreateBoundSplitter(Disabled: boolean);
begin
if BoundSplitter<>nil then exit;
FBoundSplitter:=DockMaster.CreateSplitter;
BoundSplitter.FreeNotification(Self);
BoundSplitter.Align:=Align;
BoundSplitter.Parent:=Parent;
if Disabled then
begin
BoundSplitter.Width:=0;
BoundSplitter.Height:=0;
BoundSplitter.Visible:=false;
end;
end;
procedure TAnchorDockHostSite.PositionBoundSplitter;
begin
case Align of
alTop: BoundSplitter.SetBounds(0,Height,Parent.ClientWidth,BoundSplitter.Height);
alBottom: BoundSplitter.SetBounds(0,Parent.ClientHeight-Height-BoundSplitter.Height,
Parent.ClientWidth,BoundSplitter.Height);
alLeft: BoundSplitter.SetBounds(Width,0,BoundSplitter.Width,Parent.ClientHeight);
alRight: BoundSplitter.SetBounds(Parent.ClientWidth-Width-BoundSplitter.Width,0
,BoundSplitter.Width,Parent.ClientHeight);
end;
end;
function TAnchorDockHostSite.CloseQuery: boolean;
function Check(AControl: TWinControl): boolean;
var
i: Integer;
Child: TControl;
begin
for i:=0 to AControl.ControlCount-1 do begin
Child:=AControl.Controls[i];
if Child is TWinControl then begin
if Child is TCustomForm then begin
if not TCustomForm(Child).CloseQuery then exit(false);
end else begin
if not Check(TWinControl(Child)) then exit(false);
end;
end;
end;
Result:=true;
end;
begin
Result:=Check(Self);
end;
function TAnchorDockHostSite.CloseSite: boolean;
var
AControl: TControl;
AForm: TCustomForm;
IsMainForm: Boolean;
CloseAction: TCloseAction;
NeedEnableAutoSizing: Boolean;
begin
Result:=CloseQuery;
if not Result then exit;
debugln(['TAnchorDockHostSite.CloseSite ',DbgSName(Self),' SiteType=',dbgs(SiteType)]);
case SiteType of
adhstNone:
begin
Release;
exit;
end;
adhstOneControl:
begin
DisableAutoSizing{$IFDEF DebugDisableAutoSizing}('TAnchorDockHostSite.CloseSite'){$ENDIF};
NeedEnableAutoSizing:=true;
try
AControl:=GetOneControl;
if AControl is TCustomForm then begin
AForm:=TCustomForm(AControl);
IsMainForm := (Application.MainForm = AForm)
or (AForm.IsParentOf(Application.MainForm));
if IsMainForm then
CloseAction := caFree
else
CloseAction := caHide;
// ToDo: TCustomForm(AControl).DoClose(CloseAction);
case CloseAction of
caHide: Hide;
caMinimize: WindowState := wsMinimized;
caFree:
begin
// if form is MainForm, then terminate the application
// the owner of the MainForm is the application,
// so the Application will take care of free-ing the form
// and Release is not necessary
if IsMainForm then
Application.Terminate
else begin
NeedEnableAutoSizing:=false;
Release;
AForm.Release;
exit;
end;
end;
end;
end else begin
AControl.Visible:=false;
NeedEnableAutoSizing:=false;
Release;
exit;
end;
Visible:=false;
Parent:=nil;
finally
if NeedEnableAutoSizing then
EnableAutoSizing{$IFDEF DebugDisableAutoSizing}('TAnchorDockHostSite.CloseSite'){$ENDIF};
end;
end;
end;
end;
procedure TAnchorDockHostSite.RemoveControl(AControl: TControl);
begin
//debugln(['TAnchorDockHostSite.RemoveControl ',DbgSName(Self),'=',Caption,' ',DbgSName(AControl)]);
DisableAutoSizing{$IFDEF DebugDisableAutoSizing}('TAnchorDockHostSite.RemoveControl'){$ENDIF};
try
AControl.RemoveHandlerOnVisibleChanged(@ChildVisibleChanged);
inherited RemoveControl(AControl);
if not (csDestroying in ComponentState) then begin
if (not ((AControl is TAnchorDockHeader)
or (AControl is TAnchorDockSplitter)))
then begin
//debugln(['TAnchorDockHostSite.RemoveControl START ',Caption,' ',dbgs(SiteType),' ',DbgSName(AControl),' UpdatingLayout=',UpdatingLayout]);
if (SiteType=adhstLayout) then
RemoveControlFromLayout(AControl)
else
DockMaster.NeedSimplify(Self);
UpdateDockCaption;
//debugln(['TAnchorDockHostSite.RemoveControl END ',Caption,' ',dbgs(SiteType),' ',DbgSName(AControl)]);
end;
end;
finally
EnableAutoSizing{$IFDEF DebugDisableAutoSizing}('TAnchorDockHostSite.RemoveControl'){$ENDIF};
end;
end;
procedure TAnchorDockHostSite.InsertControl(AControl: TControl; Index: integer);
begin
DisableAutoSizing{$IFDEF DebugDisableAutoSizing}('TAnchorDockHostSite.InsertControl'){$ENDIF};
try
inherited InsertControl(AControl, Index);
if not ((AControl is TAnchorDockSplitter)
or (AControl is TAnchorDockHeader))
then
UpdateDockCaption;
AControl.AddHandlerOnVisibleChanged(@ChildVisibleChanged);
finally
EnableAutoSizing{$IFDEF DebugDisableAutoSizing}('TAnchorDockHostSite.InsertControl'){$ENDIF};
end;
end;
procedure TAnchorDockHostSite.UpdateDockCaption(Exclude: TControl);
var
i: Integer;
Child: TControl;
NewCaption, OldCaption: String;
begin
if csDestroying in ComponentState then exit;
NewCaption:='';
for i:=0 to ControlCount-1 do begin
Child:=Controls[i];
if Child=Exclude then continue;
if (Child.HostDockSite=Self) or (Child is TAnchorDockHostSite)
or (Child is TAnchorDockPageControl) then begin
if NewCaption<>'' then
NewCaption:=NewCaption+',';
NewCaption:=NewCaption+Child.Caption;
end;
end;
OldCaption:=Caption;
Caption:=NewCaption;
//debugln(['TAnchorDockHostSite.UpdateDockCaption Caption="',Caption,'" NewCaption="',NewCaption,'" HasParent=',Parent<>nil,' ',DbgSName(Header)]);
if ((Parent=nil) and DockMaster.HideHeaderCaptionFloatingControl)
or (not DockMaster.ShowHeaderCaption) then
Header.Caption:=''
else
Header.Caption:=Caption;
if OldCaption<>Caption then begin
//debugln(['TAnchorDockHostSite.UpdateDockCaption Caption="',Caption,'" NewCaption="',NewCaption,'" HasParent=',Parent<>nil]);
if Parent is TAnchorDockHostSite then
TAnchorDockHostSite(Parent).UpdateDockCaption;
if Parent is TAnchorDockPage then
TAnchorDockPage(Parent).UpdateDockCaption;
end;
// do not show close button for mainform
Header.CloseButton.Visible:=not IsParentOf(Application.MainForm);
end;
procedure TAnchorDockHostSite.GetSiteInfo(Client: TControl;
var InfluenceRect: TRect; MousePos: TPoint; var CanDock: Boolean);
var
ADockMargin: LongInt;
begin
GetWindowRect(Handle, InfluenceRect);
if (Parent=nil) or DockMaster.IsCustomSite(Parent) then begin
// allow docking outside => enlarge margins
ADockMargin:=DockMaster.DockOutsideMargin;
//debugln(['TAnchorDockHostSite.GetSiteInfo ',DbgSName(Self),' allow outside ADockMargin=',ADockMargin,' ',dbgs(InfluenceRect)]);
InfluenceRect.Left := InfluenceRect.Left-ADockMargin;
InfluenceRect.Top := InfluenceRect.Top-ADockMargin;
InfluenceRect.Right := InfluenceRect.Right+ADockMargin;
InfluenceRect.Bottom := InfluenceRect.Bottom+ADockMargin;
end else if Parent is TAnchorDockHostSite then begin
// do not cover parent site => shrink margins
ADockMargin:=DockMaster.DockParentMargin;
ADockMargin:=Min(ADockMargin,Min(ClientWidth,ClientHeight) div 10);
ADockMargin:=Max(0,ADockMargin);
//debugln(['TAnchorDockHostSite.GetSiteInfo ',DbgSName(Self),' do not cover parent ADockMargin=',ADockMargin,' ',dbgs(InfluenceRect)]);
InfluenceRect.Left := InfluenceRect.Left+ADockMargin;
InfluenceRect.Top := InfluenceRect.Top+ADockMargin;
InfluenceRect.Right := InfluenceRect.Right-ADockMargin;
InfluenceRect.Bottom := InfluenceRect.Bottom-ADockMargin;
end;
CanDock:=(Client is TAnchorDockHostSite)
and not DockMaster.AutoFreedIfControlIsRemoved(Self,Client);
//debugln(['TAnchorDockHostSite.GetSiteInfo ',DbgSName(Self),' ',dbgs(BoundsRect),' ',Caption,' CanDock=',CanDock,' PtIn=',PtInRect(InfluenceRect,MousePos)]);
if Assigned(OnGetSiteInfo) then
OnGetSiteInfo(Self, Client, InfluenceRect, MousePos, CanDock);
end;
function TAnchorDockHostSite.GetPageArea: TRect;
begin
Result:=Rect(0,0,Width*DockMaster.PageAreaInPercent div 100,
Height*DockMaster.PageAreaInPercent div 100);
OffsetRect(Result,(Width*(100-DockMaster.PageAreaInPercent)) div 200,
(Height*(100-DockMaster.PageAreaInPercent)) div 200);
end;
procedure TAnchorDockHostSite.ChangeBounds(ALeft, ATop, AWidth,
AHeight: integer; KeepBase: boolean);
begin
inherited ChangeBounds(ALeft, ATop, AWidth, AHeight, KeepBase);
if Header<>nil then UpdateHeaderAlign;
end;
procedure TAnchorDockHostSite.UpdateHeaderAlign;
begin
if Header=nil then exit;
case Header.HeaderPosition of
adlhpAuto:
if Header.Align in [alLeft,alRight] then begin
if (ClientHeight>0)
and ((ClientWidth*100 div ClientHeight)<=DockMaster.HeaderAlignTop) then
Header.Align:=alTop;
end else begin
if (ClientHeight>0)
and ((ClientWidth*100 div ClientHeight)>=DockMaster.HeaderAlignLeft) then
begin
if Application.BidiMode=bdRightToLeft then
Header.Align:=alRight
else
Header.Align:=alLeft;
end;
end;
adlhpLeft: Header.Align:=alLeft;
adlhpTop: Header.Align:=alTop;
adlhpRight: Header.Align:=alRight;
adlhpBottom: Header.Align:=alBottom;
end;
end;
procedure TAnchorDockHostSite.UpdateHeaderShowing;
begin
if Header=nil then exit;
if HeaderNeedsShowing then
Header.Parent:=Self
else
Header.Parent:=nil;
end;
procedure TAnchorDockHostSite.BeginUpdateLayout;
begin
inc(fUpdateLayout);
if fUpdateLayout=1 then DockMaster.BeginUpdate;
end;
procedure TAnchorDockHostSite.EndUpdateLayout;
begin
if fUpdateLayout=0 then RaiseGDBException('TAnchorDockHostSite.EndUpdateLayout');
dec(fUpdateLayout);
if fUpdateLayout=0 then
DockMaster.EndUpdate;
end;
function TAnchorDockHostSite.UpdatingLayout: boolean;
begin
Result:=(fUpdateLayout>0) or (csDestroying in ComponentState);
end;
procedure TAnchorDockHostSite.SaveLayout(
LayoutTree: TAnchorDockLayoutTree; LayoutNode: TAnchorDockLayoutTreeNode);
var
i: Integer;
Site: TAnchorDockHostSite;
ChildNode: TAnchorDockLayoutTreeNode;
Child: TControl;
Splitter: TAnchorDockSplitter;
OneControl: TControl;
begin
if SiteType=adhstOneControl then
OneControl:=GetOneControl
else
OneControl:=nil;
if (SiteType=adhstOneControl) and (OneControl<>nil)
and (not (OneControl is TAnchorDockHostSite)) then begin
LayoutNode.NodeType:=adltnControl;
LayoutNode.Assign(Self);
LayoutNode.Name:=OneControl.Name;
LayoutNode.HeaderPosition:=Header.HeaderPosition;
end else if (SiteType in [adhstLayout,adhstOneControl]) then begin
LayoutNode.NodeType:=adltnLayout;
for i:=0 to ControlCount-1 do begin
Child:=Controls[i];
if Child.Owner=Self then continue;
if (Child is TAnchorDockHostSite) then begin
Site:=TAnchorDockHostSite(Child);
ChildNode:=LayoutTree.NewNode(LayoutNode);
Site.SaveLayout(LayoutTree,ChildNode);
end else if (Child is TAnchorDockSplitter) then begin
Splitter:=TAnchorDockSplitter(Child);
ChildNode:=LayoutTree.NewNode(LayoutNode);
Splitter.SaveLayout(ChildNode);
end;
end;
LayoutNode.Assign(Self);
LayoutNode.HeaderPosition:=Header.HeaderPosition;
end else if SiteType=adhstPages then begin
LayoutNode.NodeType:=adltnPages;
for i:=0 to Pages.PageCount-1 do begin
Site:=Pages.DockPages[i].GetSite;
if Site<>nil then begin
ChildNode:=LayoutTree.NewNode(LayoutNode);
Site.SaveLayout(LayoutTree,ChildNode);
end;
end;
LayoutNode.Assign(Self);
LayoutNode.HeaderPosition:=Header.HeaderPosition;
LayoutNode.TabPosition:=Pages.TabPosition;
LayoutNode.PageIndex:=Pages.PageIndex;
end else
LayoutNode.NodeType:=adltnNone;
if BoundSplitter<>nil then begin
if Align in [alLeft,alRight] then
LayoutNode.BoundSplitterPos:=BoundSplitter.Left
else
LayoutNode.BoundSplitterPos:=BoundSplitter.Top;
end;
end;
constructor TAnchorDockHostSite.CreateNew(AOwner: TComponent; Num: Integer);
begin
inherited CreateNew(AOwner,Num);
Visible:=false;
FHeaderSide:=akTop;
FHeader:=DockMaster.HeaderClass.Create(Self);
FHeader.Align:=alTop;
FHeader.Parent:=Self;
FSiteType:=adhstNone;
UpdateHeaderAlign;
DragKind:=dkDock;
DockManager:=DockMaster.ManagerClass.Create(Self);
UseDockManager:=true;
DragManager.RegisterDockSite(Self,true);
end;
destructor TAnchorDockHostSite.Destroy;
//var i: Integer;
begin
//debugln(['TAnchorDockHostSite.Destroy ',DbgSName(Self),' Caption="',Caption,'" Self=',dbgs(Pointer(Self)),' ComponentCount=',ComponentCount,' ControlCount=',ControlCount]);
{for i:=0 to ComponentCount-1 do
debugln(['TAnchorDockHostSite.Destroy Component ',i,'/',ComponentCount,' ',DbgSName(Components[i])]);
for i:=0 to ControlCount-1 do
debugln(['TAnchorDockHostSite.Destroy Control ',i,'/',ControlCount,' ',DbgSName(Controls[i])]);}
FreePages;
inherited Destroy;
end;
{ TAnchorDockHeader }
procedure TAnchorDockHeader.PopupMenuPopup(Sender: TObject);
var
HeaderPosItem: TMenuItem;
ParentSite: TAnchorDockHostSite;
Side: TAnchorKind;
SideCaptions: array[TAnchorKind] of string;
Item: TMenuItem;
ContainsMainForm: boolean;
s: String;
begin
ParentSite:=TAnchorDockHostSite(Parent);
SideCaptions[akLeft]:=adrsLeft;
SideCaptions[akTop]:=adrsTop;
SideCaptions[akRight]:=adrsRight;
SideCaptions[akBottom]:=adrsBottom;
// menu items: undock, merge
DockMaster.AddRemovePopupMenuItem(ParentSite.CanUndock,'UndockMenuItem',
adrsUndock,@UndockButtonClick);
DockMaster.AddRemovePopupMenuItem(ParentSite.CanMerge,'MergeMenuItem',
adrsMerge, @MergeButtonClick);
// menu items: header position
HeaderPosItem:=DockMaster.AddPopupMenuItem('HeaderPosMenuItem',
adrsHeaderPosition, nil);
Item:=DockMaster.AddPopupMenuItem('HeaderPosAutoMenuItem', adrsAutomatically,
@HeaderPositionItemClick, HeaderPosItem);
if Item<>nil then begin
Item.Tag:=ord(adlhpAuto);
Item.Checked:=HeaderPosition=TADLHeaderPosition(Item.Tag);
end;
for Side:=Low(TAnchorKind) to High(TAnchorKind) do begin
Item:=DockMaster.AddPopupMenuItem('HeaderPos'+DbgS(Side)+'MenuItem',
SideCaptions[Side], @HeaderPositionItemClick,
HeaderPosItem);
if Item=nil then continue;
Item.Tag:=ord(Side)+1;
Item.Checked:=HeaderPosition=TADLHeaderPosition(Item.Tag);
end;
// menu items: enlarge
for Side:=Low(TAnchorKind) to High(TAnchorKind) do begin
Item:=DockMaster.AddRemovePopupMenuItem(ParentSite.EnlargeSide(Side,true),
'Enlarge'+DbgS(Side)+'MenuItem', Format(adrsEnlargeSide, [
SideCaptions[Side]]),@EnlargeSideClick);
if Item<>nil then Item.Tag:=ord(Side);
end;
// menu item: close or quit
ContainsMainForm:=ParentSite.IsParentOf(Application.MainForm);
if ContainsMainForm then
s:=Format(adrsQuit, [Application.Title])
else
s:=adrsClose;
DockMaster.AddRemovePopupMenuItem(CloseButton.Visible,'CloseMenuItem',s,
@CloseButtonClick);
end;
procedure TAnchorDockHeader.CloseButtonClick(Sender: TObject);
begin
if Parent is TAnchorDockHostSite then begin
DockMaster.RestoreLayouts.Add(DockMaster.CreateRestoreLayout(Parent),true);
TAnchorDockHostSite(Parent).CloseSite;
end;
end;
procedure TAnchorDockHeader.HeaderPositionItemClick(Sender: TObject);
var
Item: TMenuItem;
begin
if not (Sender is TMenuItem) then exit;
Item:=TMenuItem(Sender);
HeaderPosition:=TADLHeaderPosition(Item.Tag);
end;
procedure TAnchorDockHeader.UndockButtonClick(Sender: TObject);
begin
TAnchorDockHostSite(Parent).Undock;
end;
procedure TAnchorDockHeader.MergeButtonClick(Sender: TObject);
begin
TAnchorDockHostSite(Parent).Merge;
end;
procedure TAnchorDockHeader.EnlargeSideClick(Sender: TObject);
var
Side: TAnchorKind;
begin
if not (Sender is TMenuItem) then exit;
Side:=TAnchorKind(TMenuItem(Sender).Tag);
TAnchorDockHostSite(Parent).EnlargeSide(Side,false);
end;
procedure TAnchorDockHeader.SetHeaderPosition(const AValue: TADLHeaderPosition);
begin
if FHeaderPosition=AValue then exit;
FHeaderPosition:=AValue;
if Parent is TAnchorDockHostSite then
TAnchorDockHostSite(Parent).UpdateHeaderAlign;
end;
procedure TAnchorDockHeader.Paint;
var
r: TRect;
TxtH: longint;
TxtW: longint;
dx,dy: Integer;
NeedDrawHeaderAfterText,NeedHighlightText:boolean;
begin
r:=ClientRect;
NeedDrawHeaderAfterText:=true;
NeedHighlightText:=true;
if DockMaster.HeaderStyle in [adhsThemedCaption,adhsThemedButton] then begin
DrawADHeader(Canvas,DockMaster.HeaderStyle,r,not(Align in [alLeft,alRight]),fFocused);
NeedDrawHeaderAfterText:=false;
NeedHighlightText:=false;
end else begin
Canvas.Brush.Color := clForm;
if DockMaster.HeaderFilled then
Canvas.FillRect(r);
if not DockMaster.HeaderFlatten then
Canvas.Frame3d(r,1,bvRaised);
end;
{case DockMaster.HeaderStyle of
adhsPoints: Canvas.Brush.Color := clForm;
else Canvas.Frame3d(r,1,bvRaised);
end;
Canvas.FillRect(r);}
if CloseButton.IsControlVisible and (CloseButton.Parent=Self) then begin
if Align in [alLeft,alRight] then
r.Top:=CloseButton.Top+CloseButton.Height+1
else
r.Right:=CloseButton.Left-1;
end;
// caption
if Caption<>'' then begin
if fFocused and DockMaster.HeaderHighlightFocused and NeedHighlightText then
Canvas.Font.Bold:=true
else
Canvas.Font.Bold:=False;
Canvas.Brush.Color:=clNone;
Canvas.Brush.Style:=bsClear;
TxtH:=Canvas.TextHeight('ABCMgq');
TxtW:=Canvas.TextWidth(Caption);
if Align in [alLeft,alRight] then begin
// vertical
dx:=Max(0,(r.Right-r.Left-TxtH) div 2);
{$IFDEF LCLWin32}
dec(dx,2);
{$ENDIF}
dy:=Max(0,(r.Bottom-r.Top-TxtW) div 2);
Canvas.Font.Orientation:=900;
if TxtW<(r.Bottom-r.Top)then
begin
// text fits
Canvas.TextOut(r.Left+dx-1,r.Bottom-dy,Caption);
if NeedDrawHeaderAfterText then begin
DrawADHeader(Canvas,DockMaster.HeaderStyle,Rect(r.Left,r.Top,r.Right,r.Bottom-dy-TxtW-1),false,fFocused);
DrawADHeader(Canvas,DockMaster.HeaderStyle,Rect(r.Left,r.Bottom-dy+1,r.Right,r.Bottom),false,fFocused);
end;
end else begin
// text does not fit
if NeedDrawHeaderAfterText then
DrawADHeader(Canvas,DockMaster.HeaderStyle,r,false,fFocused);
end;
end else begin
// horizontal
dx:=Max(0,(r.Right-r.Left-TxtW) div 2);
dy:=Max(0,(r.Bottom-r.Top-TxtH) div 2);
Canvas.Font.Orientation:=0;
if TxtW<(r.right-r.Left)then
begin
// text fits
Canvas.TextRect(r,dx+2,dy,Caption);
if NeedDrawHeaderAfterText then begin
DrawADHeader(Canvas,DockMaster.HeaderStyle,Rect(r.Left,r.Top,r.Left+dx-1,r.Bottom),true,fFocused);
DrawADHeader(Canvas,DockMaster.HeaderStyle,Rect(r.Left+dx+TxtW+2,r.Top,r.Right,r.Bottom),true,fFocused);
end;
end else begin
// text does not fit
if NeedDrawHeaderAfterText then
DrawADHeader(Canvas,DockMaster.HeaderStyle,r,true,fFocused);
end;
end;
end
else if NeedDrawHeaderAfterText then
if Align in [alLeft,alRight] then
DrawADHeader(Canvas,DockMaster.HeaderStyle,r,false,fFocused)
else
DrawADHeader(Canvas,DockMaster.HeaderStyle,r,true,fFocused);
end;
procedure TAnchorDockHeader.CalculatePreferredSize(var PreferredWidth,
PreferredHeight: integer; WithThemeSpace: Boolean);
const
TestTxt = 'ABCXYZ123gqj';
var
DC: HDC;
R: TRect;
OldFont: HGDIOBJ;
Flags: cardinal;
NeededHeight: Integer;
begin
inherited CalculatePreferredSize(PreferredWidth,PreferredHeight,WithThemeSpace);
if Caption<>'' then begin
DC := GetDC(Parent.Handle);
try
R := Rect(0, 0, 10000, 10000);
OldFont := SelectObject(DC, HGDIOBJ(Font.Reference.Handle));
Flags := DT_CALCRECT or DT_EXPANDTABS or DT_SINGLELINE or DT_NOPREFIX;
DrawText(DC, PChar(TestTxt), Length(TestTxt), R, Flags);
SelectObject(DC, OldFont);
NeededHeight := R.Bottom - R.Top + BevelWidth*2;
finally
ReleaseDC(Parent.Handle, DC);
end;
if Align in [alLeft,alRight] then begin
PreferredWidth:=Max(NeededHeight,PreferredWidth);
end else begin
PreferredHeight:=Max(NeededHeight,PreferredHeight);
end;
end;
end;
procedure TAnchorDockHeader.MouseDown(Button: TMouseButton; Shift: TShiftState;
X, Y: Integer);
begin
inherited MouseDown(Button, Shift, X, Y);
if (Button=mbLeft) and DockMaster.AllowDragging then
DragManager.DragStart(Parent,false,DockMaster.DragTreshold);
end;
procedure TAnchorDockHeader.UpdateHeaderControls;
begin
if Align in [alLeft,alRight] then begin
if CloseButton<>nil then
CloseButton.Align:=alTop;
end else begin
if CloseButton<>nil then
CloseButton.Align:=alRight;
end;
//debugln(['TAnchorDockHeader.UpdateHeaderControls ',dbgs(Align),' ',dbgs(CloseButton.Align)]);
end;
procedure TAnchorDockHeader.SetAlign(Value: TAlign);
begin
if Value=Align then exit;
DisableAutoSizing{$IFDEF DebugDisableAutoSizing}('TAnchorDockHostSite.SetAlign'){$ENDIF};
try
inherited SetAlign(Value);
UpdateHeaderControls;
finally
EnableAutoSizing{$IFDEF DebugDisableAutoSizing}('TAnchorDockHostSite.SetAlign'){$ENDIF};
end;
end;
procedure TAnchorDockHeader.DoOnShowHint(HintInfo: PHintInfo);
var
s: String;
p: LongInt;
c: String;
begin
s:=DockMaster.GetLocalizedHeaderHint;
p:=Pos('%s',s);
if p>0 then begin
if Parent<>nil then
c:=Parent.Caption
else
c:='';
s:=Format(s,[c]);
end;
//debugln(['TAnchorDockHeader.DoOnShowHint "',s,'" "',DockMaster.HeaderHint,'"']);
HintInfo^.HintStr:=s;
inherited DoOnShowHint(HintInfo);
end;
constructor TAnchorDockHeader.Create(TheOwner: TComponent);
begin
inherited Create(TheOwner);
FHeaderPosition:=adlhpAuto;
FCloseButton:=TAnchorDockCloseButton.Create(Self);
BevelOuter:=bvNone;
BorderWidth:=0;
with FCloseButton do begin
Name:='CloseButton';
Parent:=Self;
Flat:=true;
ShowHint:=true;
Hint:=adrsClose;
OnClick:=@CloseButtonClick;
AutoSize:=true;
end;
Align:=alTop;
AutoSize:=true;
ShowHint:=true;
PopupMenu:=DockMaster.GetPopupMenu;
fFocused:=false;
end;
{ TAnchorDockCloseButton }
function TAnchorDockCloseButton.GetDrawDetails: TThemedElementDetails;
function WindowPart: TThemedWindow;
begin
// no check states available
Result := twSmallCloseButtonNormal;
if not IsEnabled then
Result := twSmallCloseButtonDisabled
else
if FState in [bsDown, bsExclusive] then
Result := twSmallCloseButtonPushed
else
if FState = bsHot then
Result := twSmallCloseButtonHot
else
Result := twSmallCloseButtonNormal;
end;
begin
Result := ThemeServices.GetElementDetails(WindowPart);
end;
procedure TAnchorDockCloseButton.CalculatePreferredSize(var PreferredWidth,
PreferredHeight: integer; WithThemeSpace: Boolean);
begin
with ThemeServices.GetDetailSize(ThemeServices.GetElementDetails(twSmallCloseButtonNormal)) do
begin
PreferredWidth:=cx;
PreferredHeight:=cy;
{$IF defined(LCLGtk2) or defined(Carbon)}
inc(PreferredWidth,2);
inc(PreferredHeight,2);
{$ENDIF}
end;
end;
{ TAnchorDockManager }
procedure TAnchorDockManager.SetPreferredSiteSizeAsSiteMinimum(
const AValue: boolean);
begin
if FPreferredSiteSizeAsSiteMinimum=AValue then exit;
FPreferredSiteSizeAsSiteMinimum:=AValue;
if DockSite=nil then
Site.AdjustSize;
end;
constructor TAnchorDockManager.Create(ADockSite: TWinControl);
begin
inherited Create(ADockSite);
FSite:=ADockSite;
FDockableSites:=[akLeft,akTop,akBottom,akRight];
FInsideDockingAllowed:=true;
FPreferredSiteSizeAsSiteMinimum:=true;
if (ADockSite is TAnchorDockHostSite) then
FDockSite:=TAnchorDockHostSite(ADockSite);
end;
procedure TAnchorDockManager.GetControlBounds(Control: TControl; out
AControlBounds: TRect);
begin
if Control=nil then ;
AControlBounds:=Rect(0,0,0,0);
//debugln(['TAnchorDockManager.GetControlBounds DockSite="',DockSite.Caption,'" Control=',DbgSName(Control)]);
end;
procedure TAnchorDockManager.InsertControl(Control: TControl; InsertAt: TAlign;
DropCtl: TControl);
begin
if Control=nil then;
if InsertAt=alNone then ;
if DropCtl=nil then ;
end;
procedure TAnchorDockManager.InsertControl(ADockObject: TDragDockObject);
var
NewSiteBounds: TRect;
NewChildBounds: TRect;
Child: TControl;
ChildSite: TAnchorDockHostSite;
SplitterWidth: Integer;
begin
if DockSite<>nil then begin
// handled by TAnchorDockHostSite
//debugln(['TAnchorDockManager.InsertControl DockSite="',DockSite.Caption,'" Control=',DbgSName(ADockObject.Control),' InsertAt=',dbgs(ADockObject.DropAlign)])
end else begin
debugln(['TAnchorDockManager.InsertControl DockSite=nil Site="',DbgSName(Site),'" Control=',DbgSName(ADockObject.Control),' InsertAt=',dbgs(ADockObject.DropAlign),' Site.Bounds=',dbgs(Site.BoundsRect),' Control.Client=',dbgs(ADockObject.Control.ClientRect),' Parent=',DbgSName(ADockObject.Control.Parent)]);
Site.DisableAutoSizing{$IFDEF DebugDisableAutoSizing}('TAnchorDockManager.InsertControl'){$ENDIF};
try
// align dragged Control
Child:=ADockObject.Control;
Child.Parent:=Site;
Child.Align:=ADockObject.DropAlign;
Child.Width:=ADockObject.DockRect.Right-ADockObject.DockRect.Left;
Child.Height:=ADockObject.DockRect.Bottom-ADockObject.DockRect.Top;
SplitterWidth:=0;
ChildSite:=nil;
if Child is TAnchorDockHostSite then begin
ChildSite:=TAnchorDockHostSite(Child);
ChildSite.CreateBoundSplitter(Site is TAnchorDockPanel);
SplitterWidth:=DockMaster.SplitterWidth;
end;
if Site is TAnchorDockPanel then
ADockObject.DropAlign:=alClient;
// resize Site
NewSiteBounds:=Site.BoundsRect;
case ADockObject.DropAlign of
alLeft: dec(NewSiteBounds.Left,Child.ClientWidth+SplitterWidth);
alRight: dec(NewSiteBounds.Right,Child.ClientWidth+SplitterWidth);
alTop: dec(NewSiteBounds.Top,Child.ClientHeight+SplitterWidth);
alBottom: inc(NewSiteBounds.Bottom,Child.ClientHeight+SplitterWidth);
alClient: ;
end;
if not StoredConstraintsValid then
StoreConstraints;
if ADockObject.DropAlign in [alLeft,alRight] then
Site.Constraints.MaxWidth:=0
else if ADockObject.DropAlign in [alTop,alBottom] then
Site.Constraints.MaxHeight:=0;
Site.BoundsRect:=NewSiteBounds;
if ADockObject.DropAlign=alClient then
Child.Align:=alClient;
//debugln(['TAnchorDockManager.InsertControl Site.BoundsRect=',dbgs(Site.BoundsRect),' NewSiteBounds=',dbgs(NewSiteBounds),' Child.ClientRect=',dbgs(Child.ClientRect)]);
FSiteClientRect:=Site.ClientRect;
// resize child
NewChildBounds:=Child.BoundsRect;
case ADockObject.DropAlign of
alTop: NewChildBounds:=Bounds(0,0,Site.ClientWidth,Child.ClientHeight);
alBottom: NewChildBounds:=Bounds(0,Site.ClientHeight-Child.ClientHeight,
Site.ClientWidth,Child.ClientHeight);
alLeft: NewChildBounds:=Bounds(0,0,Child.ClientWidth,Site.ClientHeight);
alRight: NewChildBounds:=Bounds(Site.ClientWidth-Child.ClientWidth,0,
Child.ClientWidth,Site.ClientHeight);
alClient: NewChildBounds:=Bounds(0,0,
Site.ClientWidth,Site.ClientHeight);
end;
Child.BoundsRect:=NewChildBounds;
NewChildBounds:=Child.BoundsRect;
if ChildSite<>nil then
ChildSite.PositionBoundSplitter;
// only allow to dock one control
DragManager.RegisterDockSite(Site,false);
debugln(['TAnchorDockManager.InsertControl AFTER Site="',DbgSName(Site),'" Control=',DbgSName(ADockObject.Control),' InsertAt=',dbgs(ADockObject.DropAlign),' Site.Bounds=',dbgs(Site.BoundsRect),' Control.ClientRect=',dbgs(ADockObject.Control.ClientRect)]);
finally
Site.EnableAutoSizing{$IFDEF DebugDisableAutoSizing}('TAnchorDockManager.InsertControl'){$ENDIF};
end;
end;
end;
procedure TAnchorDockManager.LoadFromStream(Stream: TStream);
begin
debugln(['TAnchorDockManager.LoadFromStream not implemented Site="',DbgSName(Site),'"']);
if Stream=nil then ;
end;
procedure TAnchorDockManager.PositionDockRect(Client, DropCtl: TControl;
DropAlign: TAlign; var DockRect: TRect);
{ Client = dragged source site (a TAnchorDockHostSite)
DropCtl is target control (the DockSite, DockSite.Pages or one of the pages)
DropAlign: where on Client DropCtl should be placed
DockRect: the estimated new bounds of DropCtl
}
var
Offset: TPoint;
Inside: Boolean;
begin
if (DropAlign=alClient) and (DockSite<>nil) and (DockSite.Pages<>nil) then begin
// dock into pages
if DropCtl=DockSite.Pages then begin
// dock as last page
DockRect:=DockSite.Pages.TabRect(DockSite.Pages.PageCount-1);
case DockSite.Pages.TabPosition of
tpTop,tpBottom: DockRect.Left:=(DockRect.Left+DockRect.Right) div 2;
tpLeft,tpRight: DockRect.Top:=(DockRect.Top+DockRect.Bottom) div 2;
end;
Offset:=DockSite.Pages.ClientOrigin;
OffsetRect(DockRect,Offset.X,Offset.Y);
exit;
end else if DropCtl is TAnchorDockPage then begin
// dock in front of page
DockRect:=DockSite.Pages.TabRect(TAnchorDockPage(DropCtl).PageIndex);
case DockSite.Pages.TabPosition of
tpTop,tpBottom: DockRect.Right:=(DockRect.Left+DockRect.Right) div 2;
tpLeft,tpRight: DockRect.Bottom:=(DockRect.Top+DockRect.Bottom) div 2;
end;
Offset:=DockSite.Pages.ClientOrigin;
OffsetRect(DockRect,Offset.X,Offset.Y);
exit;
end;
end;
Inside:=(DropCtl=Site);
if (not Inside) and (Site.Parent<>nil) then begin
if (Site.Parent is TAnchorDockHostSite)
or (not (Site.Parent.DockManager is TAnchorDockManager))
or (Site.Parent.Parent<>nil) then
Inside:=true;
end;
if Site is TAnchorDockPanel then begin
DockRect:=Bounds(Site.ClientOrigin.x,Site.ClientOrigin.y,Site.ClientWidth,Site.ClientHeight);
exit;
end;
case DropAlign of
alLeft:
if Inside then
DockRect:=Rect(0,0,Min(Client.Width,Site.ClientWidth div 2),Site.ClientHeight)
else
DockRect:=Rect(-Client.Width,0,0,Site.ClientHeight);
alRight:
if Inside then begin
DockRect:=Rect(0,0,Min(Client.Width,Site.Width div 2),Site.ClientHeight);
OffsetRect(DockRect,Site.ClientWidth-DockRect.Right,0);
end else
DockRect:=Bounds(Site.ClientWidth,0,Client.Width,Site.ClientHeight);
alTop:
if Inside then
DockRect:=Rect(0,0,Site.ClientWidth,Min(Client.Height,Site.ClientHeight div 2))
else
DockRect:=Rect(0,-Client.Height,Site.ClientWidth,0);
alBottom:
if Inside then begin
DockRect:=Rect(0,0,Site.ClientWidth,Min(Client.Height,Site.ClientHeight div 2));
OffsetRect(DockRect,0,Site.ClientHeight-DockRect.Bottom);
end else
DockRect:=Bounds(0,Site.ClientHeight,Site.ClientWidth,Client.Height);
alClient:
begin
// paged docking => show center
if DockSite<>nil then
DockRect:=DockSite.GetPageArea;
end;
else
exit; // use default
end;
Offset:=Site.ClientOrigin;
OffsetRect(DockRect,Offset.X,Offset.Y);
end;
procedure TAnchorDockManager.RemoveControl(Control: TControl);
var
NewBounds: TRect;
ChildSite: TAnchorDockHostSite;
SplitterWidth: Integer;
begin
if DockSite<>nil then
{$IFDEF VerboseAnchorDocking}
debugln(['TAnchorDockManager.RemoveControl DockSite="',DockSite.Caption,'" Control=',DbgSName(Control)])
{$ENDIF}
else begin
{$IFDEF VerboseAnchorDocking}
debugln(['TAnchorDockManager.RemoveControl Site="',DbgSName(Site),'" Control=',DbgSName(Control)]);
{$ENDIF}
if Control is TAnchorDockHostSite then begin
SplitterWidth:=0;
if Control is TAnchorDockHostSite then begin
ChildSite:=TAnchorDockHostSite(Control);
if ChildSite.BoundSplitter<>nil then
SplitterWidth:=DockMaster.SplitterWidth;
end;
// shrink Site
NewBounds:=Site.BoundsRect;
case Control.Align of
alTop: inc(NewBounds.Top,Control.Height+SplitterWidth);
alBottom: dec(NewBounds.Bottom,Control.Height+SplitterWidth);
alLeft: inc(NewBounds.Left,Control.Width+SplitterWidth);
alRight: dec(NewBounds.Right,Control.Width+SplitterWidth);
end;
if StoredConstraintsValid then begin
// restore constraints
with Site.Constraints do begin
MinWidth:=FStoredConstraints.Left;
MinHeight:=FStoredConstraints.Top;
MaxWidth:=FStoredConstraints.Right;
MaxHeight:=FStoredConstraints.Bottom;
end;
FStoredConstraints:=Rect(0,0,0,0);
end;
Site.BoundsRect:=NewBounds;
{$IFDEF VerboseAnchorDocking}
debugln(['TAnchorDockManager.RemoveControl Site=',DbgSName(Site),' ',dbgs(Site.BoundsRect)]);
{$ENDIF}
// Site can dock a control again
DragManager.RegisterDockSite(Site,true);
end;
end;
end;
procedure TAnchorDockManager.ResetBounds(Force: Boolean);
var
OldSiteClientRect: TRect;
WidthDiff: Integer;
HeightDiff: Integer;
ClientRectChanged: Boolean;
procedure AlignChilds;
var
i: Integer;
b: TRect;
AControl: TControl;
ChildMaxSize: TPoint;
SiteMinSize: TPoint;
Child: TAnchorDockHostSite;
begin
if ClientRectChanged and DockMaster.Restoring then begin
// ClientRect changed => restore bounds
for i:=0 to Site.ControlCount-1 do begin
AControl:=Site.Controls[i];
b:=Rect(0,0,0,0);
if AControl is TAnchorDockHostSite then
b:=TAnchorDockHostSite(AControl).DockRestoreBounds
else if AControl is TAnchorDockSplitter then
b:=TAnchorDockSplitter(AControl).DockRestoreBounds;
if (b.Right<=b.Left) or (b.Bottom<=b.Top) then
b:=AControl.BoundsRect;
{$IFDEF VerboseAnchorDockRestore}
debugln(['TAnchorDockManager.ResetBounds RESTORE ',DbgSName(AControl),' Cur=',dbgs(AControl.BoundsRect),' Restore=',dbgs(b)]);
{$ENDIF}
if AControl is TAnchorDockSplitter then begin
// fit splitter into clientarea
if AControl.AnchorSide[akLeft].Control=nil then
b.Left:=Max(0,Min(b.Left,Site.ClientWidth-10));
if AControl.AnchorSide[akTop].Control=nil then
b.Top:=Max(0,Min(b.Top,Site.ClientHeight-10));
if TAnchorDockSplitter(AControl).ResizeAnchor in [akLeft,akRight] then
begin
b.Right:=b.Left+DockMaster.SplitterWidth;
b.Bottom:=Max(1,Min(b.Bottom,Site.ClientHeight-b.Top));
end
else begin
b.Right:=Max(1,Min(b.Right,Site.ClientWidth-b.Left));
b.Bottom:=b.Top+DockMaster.SplitterWidth;
end;
end;
AControl.BoundsRect:=b;
if AControl is TAnchorDockSplitter then
TAnchorDockSplitter(AControl).UpdateDockBounds;
end;
exit;
end;
if DockSite<>nil then exit;
Child:=GetChildSite;
if Child=nil then exit;
{$IFDEF VerboseAnchorDockRestore}
debugln(['TAnchorDockManager.ResetBounds ',DbgSName(Site),' ',dbgs(Child.BaseBounds),' ',WidthDiff,',',HeightDiff]);
{$ENDIF}
ChildMaxSize:=Point(Site.ClientWidth-DockMaster.SplitterWidth,
Site.ClientHeight-DockMaster.SplitterWidth);
if PreferredSiteSizeAsSiteMinimum then begin
SiteMinSize:=GetSitePreferredClientSize;
if Child.Align in [alLeft,alRight] then begin
ChildMaxSize.X:=Max(0,(ChildMaxSize.X-SiteMinSize.X));
end else begin
ChildMaxSize.Y:=Max(0,(ChildMaxSize.Y-SiteMinSize.Y));
end;
{$IF defined(VerboseAnchorDockRestore) or defined(VerboseADCustomSite)}
debugln(['TAnchorDockManager.ResetBounds ChildMaxSize=',dbgs(ChildMaxSize),' SiteMinSize=',dbgs(SiteMinSize),' Site.Client=',dbgs(Site.ClientRect)]);
{$ENDIF}
end;
case ResizePolicy of
admrpChild:
begin
if Child.Parent is TAnchorDockPanel then
//
else begin
if Child.Align in [alLeft,alRight] then
Child.Width:=Max(1,Min(ChildMaxSize.X,Child.Width+WidthDiff))
else begin
i:=Max(1,Min(ChildMaxSize.Y,Child.Height+HeightDiff));
{$IFDEF VerboseAnchorDockRestore}
debugln(['TAnchorDockManager.ResetBounds Child=',DbgSName(Child),' OldHeight=',Child.Height,' NewHeight=',i]);
{$ENDIF}
Child.Height:=i;
end;
end;
end;
end;
end;
begin
if Force then ;
//debugln(['TAnchorDockManager.ResetBounds Site="',Site.Caption,'" Force=',Force,' ',dbgs(Site.ClientRect)]);
OldSiteClientRect:=FSiteClientRect;
FSiteClientRect:=Site.ClientRect;
WidthDiff:=FSiteClientRect.Right-OldSiteClientRect.Right;
HeightDiff:=FSiteClientRect.Bottom-OldSiteClientRect.Bottom;
ClientRectChanged:=(WidthDiff<>0) or (HeightDiff<>0);
if ClientRectChanged or PreferredSiteSizeAsSiteMinimum then
AlignChilds;
end;
procedure TAnchorDockManager.SaveToStream(Stream: TStream);
begin
if Stream=nil then ;
debugln(['TAnchorDockManager.SaveToStream not implemented Site="',DbgSName(Site),'"']);
end;
function TAnchorDockManager.GetDockEdge(ADockObject: TDragDockObject): boolean;
var
BestDistance: Integer;
procedure FindMinDistance(CurAlign: TAlign; CurDistance: integer);
begin
if CurDistance<0 then
CurDistance:=-CurDistance;
if CurDistance>=BestDistance then exit;
ADockObject.DropAlign:=CurAlign;
BestDistance:=CurDistance;
end;
var
p: TPoint;
LastTabRect: TRect;
TabIndex: longint;
begin
//debugln(['TAnchorDockManager.GetDockEdge ',DbgSName(Site),' ',DbgSName(DockSite),' DockableSites=',dbgs(DockableSites)]);
if DockableSites=[] then begin
ADockObject.DropAlign:=alNone;
exit(false);
end;
p:=Site.ScreenToClient(ADockObject.DragPos);
//debugln(['TAnchorDockManager.GetDockEdge ',dbgs(p),' ',dbgs(Site.BoundsRect),' ',DbgSName(Site)]);
if (DockSite<>nil) and (DockSite.Pages<>nil) then begin
// page docking
ADockObject.DropAlign:=alClient;
p:=DockSite.Pages.ScreenToClient(ADockObject.DragPos);
LastTabRect:=DockSite.Pages.TabRect(DockSite.Pages.PageCount-1);
if (p.Y>=LastTabRect.Top) and (p.y<LastTabRect.Bottom) then begin
// specific tab
if p.X>=LastTabRect.Right then begin
// insert as last
ADockObject.DropOnControl:=DockSite.Pages;
end else begin
TabIndex:=DockSite.Pages.IndexOfPageAt(p);
if TabIndex>=0 then begin
// insert in front of an existing
ADockObject.DropOnControl:=DockSite.Pages.Page[TabIndex];
end;
end;
end;
end else if (DockSite<>nil) and PtInRect(DockSite.GetPageArea,p) then begin
// page docking
ADockObject.DropAlign:=alClient;
end else begin
// check side
BestDistance:=High(Integer);
if akLeft in DockableSites then FindMinDistance(alLeft,p.X);
if akRight in DockableSites then FindMinDistance(alRight,Site.ClientWidth-p.X);
if akTop in DockableSites then FindMinDistance(alTop,p.Y);
if akBottom in DockableSites then FindMinDistance(alBottom,Site.ClientHeight-p.Y);
// check inside
if InsideDockingAllowed
and ( ((ADockObject.DropAlign=alLeft) and (p.X>=0))
or ((ADockObject.DropAlign=alTop) and (p.Y>=0))
or ((ADockObject.DropAlign=alRight) and (p.X<Site.ClientWidth))
or ((ADockObject.DropAlign=alBottom) and (p.Y<Site.ClientHeight)) )
then
ADockObject.DropOnControl:=Site
else
ADockObject.DropOnControl:=nil;
end;
//debugln(['TAnchorDockManager.GetDockEdge ADockObject.DropAlign=',dbgs(ADockObject.DropAlign),' DropOnControl=',DbgSName(ADockObject.DropOnControl)]);
Result:=true;
end;
procedure TAnchorDockManager.RestoreSite(SplitterPos: integer);
var
ChildSite: TAnchorDockHostSite;
begin
FSiteClientRect:=Site.ClientRect;
if DockSite<>nil then exit;
ChildSite:=GetChildSite;
{$IFDEF VerboseAnchorDockRestore}
debugln(['TAnchorDockManager.RestoreSite START ',DbgSName(Site),' ChildSite=',DbgSName(ChildSite)]);
{$ENDIF}
if ChildSite<>nil then begin
ChildSite.CreateBoundSplitter;
ChildSite.PositionBoundSplitter;
if ChildSite.Align in [alLeft,alRight] then
ChildSite.BoundSplitter.Left:=SplitterPos
else
ChildSite.BoundSplitter.Top:=SplitterPos;
case ChildSite.Align of
alTop: ChildSite.Height:=ChildSite.BoundSplitter.Top;
alBottom: ChildSite.Height:=Site.ClientHeight
-(ChildSite.BoundSplitter.Top+ChildSite.BoundSplitter.Height);
alLeft: ChildSite.Width:=ChildSite.BoundSplitter.Left;
alRight: ChildSite.Width:=Site.ClientWidth
-(ChildSite.BoundSplitter.Left+ChildSite.BoundSplitter.Width);
end;
// only allow to dock one control
DragManager.RegisterDockSite(Site,false);
{$IFDEF VerboseAnchorDockRestore}
debugln(['TAnchorDockManager.RestoreSite ',DbgSName(Site),' ChildSite=',DbgSName(ChildSite),' Site.Bounds=',dbgs(Site.BoundsRect),' Site.Client=',dbgs(Site.ClientRect),' ChildSite.Bounds=',dbgs(ChildSite.BoundsRect),' Splitter.Bounds=',dbgs(ChildSite.BoundSplitter.BoundsRect)]);
{$ENDIF}
end;
end;
procedure TAnchorDockManager.StoreConstraints;
begin
with Site.Constraints do
FStoredConstraints:=Rect(MinWidth,MinHeight,MaxWidth,MaxHeight);
end;
function TAnchorDockManager.GetSitePreferredClientSize: TPoint;
{ Compute the preferred inner size of Site without the ChildSite and without
the splitter
}
var
ChildSite: TAnchorDockHostSite;
Splitter: TAnchorDockSplitter;
SplitterSize: TPoint;
i: Integer;
ChildControl: TControl;
PrefWidth: Integer;
PrefHeight: Integer;
SplitterAnchor: TAnchorKind; // side where a child is anchored to the splitter
ChildPrefWidth: integer;
ChildPrefHeight: integer;
ChildBottom: Integer;
ChildRight: Integer;
begin
Result:=Point(0,0);
Site.GetPreferredSize(Result.X,Result.Y);
// compute the bounds without the Splitter and ChildSite
ChildSite:=GetChildSite;
if ChildSite=nil then exit;
Splitter:=ChildSite.BoundSplitter;
if Splitter=nil then exit;
SplitterSize:=Point(0,0);
Splitter.GetPreferredSize(SplitterSize.X,SplitterSize.Y);
PrefWidth:=0;
PrefHeight:=0;
if ChildSite.Align in [alLeft,alRight] then
PrefHeight:=Result.Y
else
PrefWidth:=Result.X;
SplitterAnchor:=MainAlignAnchor[ChildSite.Align];
for i:=0 to Site.ControlCount-1 do begin
ChildControl:=Site.Controls[i];
if (ChildControl=Splitter) or (ChildControl=ChildSite) then continue;
if (ChildControl.AnchorSide[SplitterAnchor].Control=Splitter)
or ((ChildControl.Align in [alLeft,alTop,alRight,alBottom,alClient])
and (SplitterAnchor in AnchorAlign[ChildControl.Align]))
then begin
// this control could be resized by the splitter
// => use its position and preferred size for a preferred size of the ChildSite
ChildPrefWidth:=0;
ChildPrefHeight:=0;
ChildControl.GetPreferredSize(ChildPrefWidth,ChildPrefHeight);
//debugln([' ChildControl=',DbgSName(ChildControl),' ',ChildPrefWidth,',',ChildPrefHeight]);
case ChildSite.Align of
alTop:
begin
ChildBottom:=ChildControl.Top+ChildControl.Height;
PrefHeight:=Max(PrefHeight,Site.ClientHeight-ChildBottom-ChildPrefHeight);
end;
alBottom:
PrefHeight:=Max(PrefHeight,ChildControl.Top+ChildPrefHeight);
alLeft:
begin
ChildRight:=ChildControl.Left+ChildControl.Width;
PrefWidth:=Max(PrefWidth,Site.ClientWidth-ChildRight-ChildPrefWidth);
end;
alRight:
PrefWidth:=Max(PrefWidth,ChildControl.Left+ChildPrefWidth);
end;
end;
end;
{$IFDEF VerboseADCustomSite}
debugln(['TAnchorDockManager.GetSitePreferredClientSize DefaultSitePref=',dbgs(Result),' Splitter.Align=',dbgs(Splitter.Align),' ChildSite.Align=',dbgs(ChildSite.Align),' NewPref=',PrefWidth,',',PrefHeight]);
{$ENDIF}
Result.X:=PrefWidth;
Result.Y:=PrefHeight;
end;
function TAnchorDockManager.GetChildSite: TAnchorDockHostSite;
var
i: Integer;
begin
for i:=0 to Site.ControlCount-1 do
if Site.Controls[i] is TAnchorDockHostSite then begin
Result:=TAnchorDockHostSite(Site.Controls[i]);
exit;
end;
Result:=nil;
end;
function TAnchorDockManager.StoredConstraintsValid: boolean;
begin
with FStoredConstraints do
Result:=(Left<>0) or (Top<>0) or (Right<>0) or (Bottom<>0);
end;
function TAnchorDockManager.IsEnabledControl(Control: TControl):Boolean;
begin
Result := (DockMaster <> nil) and DockMaster.IsSite(Control);
end;
{ TAnchorDockSplitter }
procedure TAnchorDockSplitter.SetResizeAnchor(const AValue: TAnchorKind);
begin
inherited SetResizeAnchor(AValue);
case ResizeAnchor of
akLeft: Anchors:=AnchorAlign[alLeft];
akTop: Anchors:=AnchorAlign[alTop];
akRight: Anchors:=AnchorAlign[alRight];
akBottom: Anchors:=AnchorAlign[alBottom];
end;
UpdatePercentPosition;
//debugln(['TAnchorDockSplitter.SetResizeAnchor ',DbgSName(Self),' ResizeAnchor=',dbgs(ResizeAnchor),' Align=',dbgs(Align),' Anchors=',dbgs(Anchors)]);
end;
procedure TAnchorDockSplitter.PopupMenuPopup(Sender: TObject);
begin
end;
procedure TAnchorDockSplitter.AsyncUpdateDockBounds (Data: PtrInt);
begin
FPercentPosition:=-1;
UpdateDockBounds;
end;
procedure TAnchorDockSplitter.UpdateDockBounds;
begin
FDockBounds:=BoundsRect;
if Parent<>nil then begin
FDockParentClientSize.cx:=Parent.ClientWidth;
FDockParentClientSize.cy:=Parent.ClientHeight;
end else begin
FDockParentClientSize.cx:=0;
FDockParentClientSize.cy:=0;
end;
if FPercentPosition < 0 then
UpdatePercentPosition;
end;
procedure TAnchorDockSplitter.UpdatePercentPosition;
begin
case ResizeAnchor of
akTop, akBottom:
if FDockParentClientSize.cy > 0 then
FPercentPosition := Top / FDockParentClientSize.cy
else
FPercentPosition := -1;
else
if FDockParentClientSize.cx > 0 then
FPercentPosition := Left / FDockParentClientSize.cx
else
FPercentPosition := -1;
end;
end;
procedure TAnchorDockSplitter.SetBounds(ALeft, ATop, AWidth, AHeight: integer);
begin
DisableAutoSizing{$IFDEF DebugDisableAutoSizing}('TAnchorDockSplitter.SetBounds'){$ENDIF};
try
inherited SetBounds(ALeft, ATop, AWidth, AHeight);
UpdateDockBounds;
finally
EnableAutoSizing{$IFDEF DebugDisableAutoSizing}('TAnchorDockSplitter.SetBounds'){$ENDIF};
end;
end;
procedure TAnchorDockSplitter.SetBoundsKeepDockBounds(ALeft, ATop, AWidth, AHeight: integer);
begin
inherited SetBounds(ALeft,ATop,AWidth,AHeight);
end;
procedure TAnchorDockSplitter.SetBoundsPercentually;
var
NewLeft, NewTop: Integer;
begin
if ResizeAnchor in [akLeft,akRight] then
begin
if DockParentClientSize.cx> 0 then
begin
if (FPercentPosition > 0) or SameValue(FPercentPosition, 0) then
NewLeft := Round(FPercentPosition*Parent.ClientWidth)
else
NewLeft := (DockBounds.Left*Parent.ClientWidth) div DockParentClientSize.cx;
NewTop := Top;
SetBoundsKeepDockBounds(NewLeft,NewTop,Width,Height);
end;
end else
begin
if DockParentClientSize.cy> 0 then
begin
NewLeft := Left;
if (FPercentPosition > 0) or SameValue(FPercentPosition, 0) then
NewTop := Round(FPercentPosition*Parent.ClientHeight)
else
NewTop := (DockBounds.Top*Parent.ClientHeight) div DockParentClientSize.cy;
SetBoundsKeepDockBounds(NewLeft,NewTop,Width,Height);
end;
end;
if FPercentPosition < 0 then
UpdatePercentPosition;
end;
function TAnchorDockSplitter.SideAnchoredControlCount(Side: TAnchorKind): integer;
var
Sibling: TControl;
i: Integer;
begin
Result:=0;
for i:=0 to AnchoredControlCount-1 do begin
Sibling:=AnchoredControls[i];
if Sibling.AnchorSide[OppositeAnchor[Side]].Control=Self then
inc(Result);
end;
end;
function TAnchorDockSplitter.HasAnchoredControls: boolean;
// returns true if this splitter has at least one non splitter control anchored to it
var
i: Integer;
Sibling: TControl;
begin
Result:=false;
for i:=0 to AnchoredControlCount-1 do begin
Sibling:=AnchoredControls[i];
if Sibling is TAnchorDockSplitter then continue;
exit(true);
end;
end;
procedure TAnchorDockSplitter.SaveLayout(
LayoutNode: TAnchorDockLayoutTreeNode);
begin
if ResizeAnchor in [akLeft,akRight] then
LayoutNode.NodeType:=adltnSplitterVertical
else
LayoutNode.NodeType:=adltnSplitterHorizontal;
LayoutNode.Assign(Self);
end;
function TAnchorDockSplitter.HasOnlyOneSibling(Side: TAnchorKind; MinPos,
MaxPos: integer): TControl;
var
i: Integer;
AControl: TControl;
begin
Result:=nil;
for i:=0 to AnchoredControlCount-1 do begin
AControl:=AnchoredControls[i];
if AControl.AnchorSide[OppositeAnchor[Side]].Control<>Self then continue;
// AControl is anchored at Side to this splitter
if (Side in [akLeft,akRight]) then begin
if (AControl.Left>MaxPos) or (AControl.Left+AControl.Width<MinPos) then
continue;
end else begin
if (AControl.Top>MaxPos) or (AControl.Top+AControl.Height<MinPos) then
continue;
end;
// AControl is in range
if Result=nil then
Result:=AControl
else begin
// there is more than one control
Result:=nil;
exit;
end;
end;
end;
procedure TAnchorDockSplitter.MoveSplitter(Offset: integer);
begin
FPercentPosition:=-1;
inherited MoveSplitter(Offset);
UpdatePercentPosition;
end;
procedure TAnchorDockSplitter.Paint;
begin
if Enabled then
inherited Paint
else
begin
Canvas.Brush.Color := clDefault;
Canvas.FillRect(ClientRect);
end;
end;
constructor TAnchorDockSplitter.Create(TheOwner: TComponent);
begin
inherited Create(TheOwner);
Align:=alNone;
ResizeAnchor:=akLeft;
// make sure the splitter never vanish
Constraints.MinWidth:=2;
Constraints.MinHeight:=2;
PopupMenu:=DockMaster.GetPopupMenu;
FPercentPosition:=-1;
end;
{ TAnchorDockPageControl }
function TAnchorDockPageControl.GetDockPages(Index: integer): TAnchorDockPage;
begin
Result:=TAnchorDockPage(Page[Index]);
end;
procedure TAnchorDockPageControl.MouseDown(Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var
ATabIndex: LongInt;
APage: TCustomPage;
Site: TAnchorDockHostSite;
begin
inherited MouseDown(Button, Shift, X, Y);
ATabIndex := IndexOfPageAt(X, Y);
if (Button = mbLeft) and DockMaster.AllowDragging and (ATabIndex >= 0) then
begin
APage:=Page[ATabIndex];
if (APage.ControlCount>0) and (APage.Controls[0] is TAnchorDockHostSite) then
begin
Site:=TAnchorDockHostSite(APage.Controls[0]);
DragManager.DragStart(Site,false,DockMaster.DragTreshold);
end;
end;
end;
procedure TAnchorDockPageControl.PopupMenuPopup(Sender: TObject);
var
ContainsMainForm: Boolean;
s: String;
TabPositionSection: TMenuItem;
Item: TMenuItem;
tp: TTabPosition;
begin
// movement
if PageIndex>0 then
DockMaster.AddPopupMenuItem('MoveLeftMenuItem', adrsMovePageLeft,
@MoveLeftButtonClick);
if PageIndex>1 then
DockMaster.AddPopupMenuItem('MoveLeftMostMenuItem', adrsMovePageLeftmost,
@MoveLeftMostButtonClick);
if PageIndex<PageCount-1 then
DockMaster.AddPopupMenuItem('MoveRightMenuItem', adrsMovePageRight,
@MoveRightButtonClick);
if PageIndex<PageCount-2 then
DockMaster.AddPopupMenuItem('MoveRightMostMenuItem', adrsMovePageRightmost,
@MoveRightMostButtonClick);
// tab position
TabPositionSection:=DockMaster.AddPopupMenuItem('TabPositionMenuItem',
adrsTabPosition,nil);
for tp:=Low(TTabPosition) to high(TTabPosition) do begin
case tp of
tpTop: s:=adrsTop;
tpBottom: s:=adrsBottom;
tpLeft: s:=adrsLeft;
tpRight: s:=adrsRight;
end;
Item:=DockMaster.AddPopupMenuItem('TabPos'+ADLTabPostionNames[tp]+'MenuItem',
s,@TabPositionClick,TabPositionSection);
Item.ShowAlwaysCheckable:=true;
Item.Checked:=TabPosition=tp;
Item.Tag:=ord(tp);
end;
// close
ContainsMainForm:=IsParentOf(Application.MainForm);
if ContainsMainForm then
s:=Format(adrsQuit, [Application.Title])
else
s:=adrsClose;
DockMaster.AddPopupMenuItem('CloseMenuItem',s,@CloseButtonClick);
end;
procedure TAnchorDockPageControl.CloseButtonClick(Sender: TObject);
var
Site: TAnchorDockHostSite;
begin
Site:=GetActiveSite;
if Site=nil then exit;
DockMaster.RestoreLayouts.Add(DockMaster.CreateRestoreLayout(Site),true);
Site.CloseSite;
DockMaster.SimplifyPendingLayouts;
end;
procedure TAnchorDockPageControl.MoveLeftButtonClick(Sender: TObject);
begin
if PageIndex>0 then
Page[PageIndex].PageIndex:=Page[PageIndex].PageIndex-1;
end;
procedure TAnchorDockPageControl.MoveLeftMostButtonClick(Sender: TObject);
begin
if PageIndex>0 then
Page[PageIndex].PageIndex:=0;
end;
procedure TAnchorDockPageControl.MoveRightButtonClick(Sender: TObject);
begin
if PageIndex<PageCount-1 then
Page[PageIndex].PageIndex:=Page[PageIndex].PageIndex+1;
end;
procedure TAnchorDockPageControl.MoveRightMostButtonClick(Sender: TObject);
begin
if PageIndex<PageCount-1 then
Page[PageIndex].PageIndex:=PageCount-1;
end;
procedure TAnchorDockPageControl.TabPositionClick(Sender: TObject);
var
Item: TMenuItem;
begin
if not (Sender is TMenuItem) then exit;
Item:=TMenuItem(Sender);
TabPosition:=TTabPosition(Item.Tag);
end;
procedure TAnchorDockPageControl.UpdateDockCaption(Exclude: TControl);
begin
if Exclude=nil then ;
end;
procedure TAnchorDockPageControl.RemoveControl(AControl: TControl);
begin
inherited RemoveControl(AControl);
if (not (csDestroying in ComponentState)) then begin
if (PageCount<=1) and (Parent is TAnchorDockHostSite) then
DockMaster.NeedSimplify(Parent);
end;
end;
function TAnchorDockPageControl.GetActiveSite: TAnchorDockHostSite;
var
CurPage: TCustomPage;
CurDockPage: TAnchorDockPage;
begin
Result:=nil;
CurPage:=ActivePageComponent;
if not (CurPage is TAnchorDockPage) then exit;
CurDockPage:=TAnchorDockPage(CurPage);
Result:=CurDockPage.GetSite;
end;
constructor TAnchorDockPageControl.Create(TheOwner: TComponent);
begin
PageClass:=DockMaster.PageClass;
inherited Create(TheOwner);
PopupMenu:=DockMaster.GetPopupMenu;
end;
{ TAnchorDockPage }
procedure TAnchorDockPage.UpdateDockCaption(Exclude: TControl);
var
i: Integer;
Child: TControl;
NewCaption: String;
begin
NewCaption:='';
for i:=0 to ControlCount-1 do begin
Child:=Controls[i];
if Child=Exclude then continue;
if not (Child is TAnchorDockHostSite) then continue;
if NewCaption<>'' then
NewCaption:=NewCaption+',';
NewCaption:=NewCaption+Child.Caption;
end;
//debugln(['TAnchorDockPage.UpdateDockCaption ',Caption,' ',NewCaption]);
if Caption=NewCaption then exit;
Caption:=NewCaption;
if Parent is TAnchorDockPageControl then
TAnchorDockPageControl(Parent).UpdateDockCaption;
end;
procedure TAnchorDockPage.InsertControl(AControl: TControl; Index: integer);
begin
inherited InsertControl(AControl, Index);
//debugln(['TAnchorDockPage.InsertControl ',DbgSName(AControl)]);
if AControl is TAnchorDockHostSite then begin
if TAnchorDockHostSite(AControl).Header<>nil then
TAnchorDockHostSite(AControl).Header.Parent:=nil;
UpdateDockCaption;
end;
end;
procedure TAnchorDockPage.RemoveControl(AControl: TControl);
begin
inherited RemoveControl(AControl);
if (GetSite=nil) and (not (csDestroying in ComponentState))
and (Parent<>nil) and (not (csDestroying in Parent.ComponentState)) then
DockMaster.NeedSimplify(Self);
end;
function TAnchorDockPage.GetSite: TAnchorDockHostSite;
begin
Result:=nil;
if ControlCount=0 then exit;
if not (Controls[0] is TAnchorDockHostSite) then exit;
Result:=TAnchorDockHostSite(Controls[0]);
end;
initialization
DockMaster:=TAnchorDockMaster.Create(nil);
finalization
FreeAndNil(DockMaster);
end.
|