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
|
{
*****************************************************************************
See the file COPYING.modifiedLGPL.txt, included in this distribution,
for details about the license.
*****************************************************************************
Author: Mattias Gaertner
Abstract:
This unit defines the TObjectInspectorDlg.
It uses TOIPropertyGrid and TOIPropertyGridRow which are also defined in this
unit. The object inspector uses property editors (see TPropertyEditor) to
display and control properties, thus the object inspector is merely an
object viewer than an editor. The property editors do the real work.
ToDo:
- backgroundcolor=clNone
- Define Init values
- Set to init value
}
unit ObjectInspector;
{$Mode objfpc}{$H+}
{off $DEFINE DoNotCatchOIExceptions}
interface
uses
// IMPORTANT: the object inspector is a tool and can be used in other programs
// too. Don't put Lazarus IDE specific things here.
// RTL / FCL
SysUtils, Types, Classes, TypInfo, math, FPCanvas,
// LCL
LCLPlatformDef, InterfaceBase, LCLType, LCLIntf, Forms, Buttons, Graphics,
GraphType, StdCtrls, Controls, ComCtrls, ExtCtrls, Menus, Dialogs, Themes,
LMessages, LCLProc,
// LazControls
{$IFnDEF UseOINormalCheckBox} CheckBoxThemed, {$ENDIF}
TreeFilterEdit, ListFilterEdit,
// LazUtils
LazConfigStorage, LazLoggerBase,
// IdeIntf
IDEImagesIntf, IDEHelpIntf, ObjInspStrConsts,
PropEdits, PropEditUtils, ComponentTreeView, OIFavoriteProperties,
ComponentEditors, ChangeParentDlg, ImgList;
const
OIOptionsFileVersion = 3;
DefBackgroundColor = clBtnFace;
DefReferencesColor = clMaroon;
DefSubPropertiesColor = clGreen;
DefNameColor = clWindowText;
DefValueColor = clMaroon;
DefDefaultValueColor = clWindowText;
DefValueDifferBackgrndColor = $F0F0FF; // Sort of pink.
DefReadOnlyColor = clGrayText;
DefHighlightColor = clHighlight;
DefHighlightFontColor = clHighlightText;
DefGutterColor = DefBackgroundColor;
DefGutterEdgeColor = cl3DShadow;
DefaultOITypeKinds = [
tkUnknown, tkInteger, tkChar, tkEnumeration, tkFloat, tkSet,{ tkMethod,}
tkSString, tkLString, tkAString, tkWString, tkVariant,
{tkArray, tkRecord,} tkInterface, tkClass, tkObject, tkWChar, tkBool,
tkInt64, tkQWord, tkUString, tkUChar];
type
EObjectInspectorException = class(Exception);
TObjectInspectorDlg = class;
TOICustomPropertyGrid = class;
// standard ObjectInspector pages
TObjectInspectorPage = (
oipgpProperties,
oipgpEvents,
oipgpFavorite,
oipgpRestricted
);
TObjectInspectorPages = set of TObjectInspectorPage;
{ TOIOptions }
TOIOptions = class
private
FComponentTreeHeight: integer;
FConfigStore: TConfigStorage;
FDefaultItemHeight: integer;
FGutterColor: TColor;
FGutterEdgeColor: TColor;
FShowComponentTree: boolean;
FSaveBounds: boolean;
FLeft: integer;
FShowGutter: boolean;
FShowInfoBox: boolean;
FInfoBoxHeight: integer;
FShowStatusBar: boolean;
FTop: integer;
FWidth: integer;
FHeight: integer;
FGridSplitterX: array[TObjectInspectorPage] of integer;
FPropertyNameColor: TColor;
FSubPropertiesColor: TColor;
FValueColor: TColor;
FDefaultValueColor: TColor;
FValueDifferBackgrndColor: TColor;
FReadOnlyColor: TColor;
FReferencesColor: TColor;
FGridBackgroundColor: TColor;
FHighlightColor: TColor;
FHighlightFontColor: TColor;
FShowHints: Boolean;
FAutoShow: Boolean;
FCheckboxForBoolean: Boolean;
FBoldNonDefaultValues: Boolean;
FDrawGridLines: Boolean;
function FPropertyGridSplitterX(Page: TObjectInspectorPage): integer;
procedure FPropertyGridSplitterX(Page: TObjectInspectorPage;
const AValue: integer);
public
constructor Create;
function Load: boolean;
function Save: boolean;
procedure Assign(AnObjInspector: TObjectInspectorDlg);
procedure AssignTo(AnObjInspector: TObjectInspectorDlg); overload;
procedure AssignTo(AGrid: TOICustomPropertyGrid); overload;
property ConfigStore: TConfigStorage read FConfigStore write FConfigStore;
property SaveBounds:boolean read FSaveBounds write FSaveBounds;
property Left:integer read FLeft write FLeft;
property Top:integer read FTop write FTop;
property Width:integer read FWidth write FWidth;
property Height:integer read FHeight write FHeight;
property GridSplitterX[Page: TObjectInspectorPage]:integer
read FPropertyGridSplitterX write FPropertyGridSplitterX;
property DefaultItemHeight: integer read FDefaultItemHeight
write FDefaultItemHeight;
property ShowComponentTree: boolean read FShowComponentTree
write FShowComponentTree;
property ComponentTreeHeight: integer read FComponentTreeHeight
write FComponentTreeHeight;
property GridBackgroundColor: TColor read FGridBackgroundColor write FGridBackgroundColor;
property SubPropertiesColor: TColor read FSubPropertiesColor write FSubPropertiesColor;
property ReferencesColor: TColor read FReferencesColor write FReferencesColor;
property ReadOnlyColor: TColor read FReadOnlyColor write FReadOnlyColor;
property ValueColor: TColor read FValueColor write FValueColor;
property DefaultValueColor: TColor read FDefaultValueColor write FDefaultValueColor;
property ValueDifferBackgrndColor: TColor read FValueDifferBackgrndColor write FValueDifferBackgrndColor;
property PropertyNameColor: TColor read FPropertyNameColor write FPropertyNameColor;
property HighlightColor: TColor read FHighlightColor write FHighlightColor;
property HighlightFontColor: TColor read FHighlightFontColor write FHighlightFontColor;
property GutterColor: TColor read FGutterColor write FGutterColor;
property GutterEdgeColor: TColor read FGutterEdgeColor write FGutterEdgeColor;
property ShowHints: boolean read FShowHints write FShowHints;
property AutoShow: boolean read FAutoShow write FAutoShow;
property CheckboxForBoolean: boolean read FCheckboxForBoolean write FCheckboxForBoolean;
property BoldNonDefaultValues: boolean read FBoldNonDefaultValues write FBoldNonDefaultValues;
property DrawGridLines: boolean read FDrawGridLines write FDrawGridLines;
property ShowGutter: boolean read FShowGutter write FShowGutter;
property ShowStatusBar: boolean read FShowStatusBar write FShowStatusBar;
property ShowInfoBox: boolean read FShowInfoBox write FShowInfoBox;
property InfoBoxHeight: integer read FInfoBoxHeight write FInfoBoxHeight;
end;
{ TOIPropertyGridRow }
TOIPropertyGridRow = class
private
FTop: integer;
FHeight: integer;
FLvl: integer;
FName: string;
FExpanded: boolean;
FTree: TOICustomPropertyGrid;
FChildCount:integer;
FPriorBrother,
FFirstChild,
FLastChild,
FNextBrother,
FParent: TOIPropertyGridRow;
FEditor: TPropertyEditor;
FWidgetSets: TLCLPlatforms;
FIndex:integer;
LastPaintedValue: string;
procedure GetLvl;
public
constructor Create(PropertyTree: TOICustomPropertyGrid;
PropEditor:TPropertyEditor; ParentNode:TOIPropertyGridRow; WidgetSets: TLCLPlatforms);
destructor Destroy; override;
function ConsistencyCheck: integer;
function HasChild(Row: TOIPropertyGridRow): boolean;
procedure WriteDebugReport(const Prefix: string);
function GetBottom: integer;
function IsReadOnly: boolean;
function IsDisabled: boolean;
procedure MeasureHeight(ACanvas: TCanvas);
function Sort(const Compare: TListSortCompare): boolean; // true if changed
function IsSorted(const Compare: TListSortCompare): boolean;
function Next: TOIPropertyGridRow;
function NextSkipChilds: TOIPropertyGridRow;
property Editor: TPropertyEditor read FEditor;
property Top: integer read FTop write FTop;
property Height: integer read FHeight write FHeight;
property Bottom: integer read GetBottom;
property Lvl: integer read FLvl;
property Name: string read FName;
property Expanded: boolean read FExpanded;
property Tree: TOICustomPropertyGrid read FTree;
property Parent: TOIPropertyGridRow read FParent;
property ChildCount: integer read FChildCount;
property FirstChild: TOIPropertyGridRow read FFirstChild;
property LastChild: TOIPropertyGridRow read FLastChild;
property NextBrother: TOIPropertyGridRow read FNextBrother;
property PriorBrother: TOIPropertyGridRow read FPriorBrother;
property Index: integer read FIndex;
end;
//----------------------------------------------------------------------------
TOIPropertyGridState = (
pgsChangingItemIndex,
pgsApplyingValue,
pgsUpdatingEditControl,
pgsBuildPropertyListNeeded,
pgsGetComboItemsCalled,
pgsIdleEnabled,
pgsCallingEdit, // calling property editor Edit
pgsFocusPropertyEditorDisabled // by building PropertyList no editor should be focused
);
TOIPropertyGridStates = set of TOIPropertyGridState;
{ TOICustomPropertyGrid }
TOICustomPropertyGridColumn = (
oipgcName,
oipgcValue
);
TOILayout = (
oilHorizontal,
oilVertical
);
TOIQuickEdit = (
oiqeEdit,
oiqeShowValue
);
TOIPropertyHintEvent = function(Sender: TObject; PointedRow: TOIPropertyGridRow;
out AHint: string): boolean of object;
TOIEditorFilterEvent = procedure(Sender: TObject; aEditor: TPropertyEditor;
var aShow: boolean) of object;
TOICustomPropertyGrid = class(TCustomControl)
private
FBackgroundColor: TColor;
FColumn: TOICustomPropertyGridColumn;
FGutterColor: TColor;
FGutterEdgeColor: TColor;
FHighlightColor: TColor;
FLayout: TOILayout;
FOnEditorFilter: TOIEditorFilterEvent;
FOnOIKeyDown: TKeyEvent;
FOnPropertyHint: TOIPropertyHintEvent;
FOnSelectionChange: TNotifyEvent;
FReferencesColor: TColor;
FReadOnlyColor: TColor;
FRowSpacing: integer;
FShowGutter: Boolean;
FCheckboxForBoolean: Boolean;
FSubPropertiesColor: TColor;
FChangeStep: integer;
FCurrentButton: TControl; // nil or ValueButton
FCurrentEdit: TWinControl; // nil or ValueEdit or ValueComboBox or ValueCheckBox
FCurrentEditorLookupRoot: TPersistent;
FDefaultItemHeight:integer;
FDragging: boolean;
FExpandedProperties: TStringList;// used to restore expanded state when switching selected component(s)
FExpandingRow: TOIPropertyGridRow;
FFavorites: TOIFavoriteProperties;
FFilter: TTypeKinds;
FIndent: integer;
FItemIndex: integer;
FNameFont, FDefaultValueFont, FValueFont, FHighlightFont: TFont;
FValueDifferBackgrndColor: TColor;
FNewComboBoxItems: TStringList;
FOnModified: TNotifyEvent;
FRows: TFPList;// list of TOIPropertyGridRow
FSelection: TPersistentSelectionList;
FNotificationComponents: TFPList;
FPropertyEditorHook: TPropertyEditorHook;
FPreferredSplitterX: integer; // best splitter position
FSplitterX: integer; // current splitter position
FStates: TOIPropertyGridStates;
FTopY: integer;
FDrawHorzGridLines: Boolean;
FActiveRowImages: TLCLGlyphs;
FFirstClickTime: DWORD;
FKeySearchText: string;
FHideClassNames: Boolean;
FPropNameFilter : String;
// hint stuff
FLongHintTimer: TTimer;
FHintManager: THintWindowManager;
FHintIndex: integer;
FHintType: TPropEditHint;
FShowingLongHint: boolean; // last hint was activated by the hinttimer
ValueEdit: TEdit;
ValueComboBox: TComboBox;
{$IFnDEF UseOINormalCheckBox}
ValueCheckBox: TCheckBoxThemed;
{$ELSE}
ValueCheckBox: TCheckBox;
{$ENDIF}
ValueButton: TSpeedButton;
procedure ActiveRowImagesGetWidthForPPI(Sender: TCustomImageList;
{%H-}AImageWidth, {%H-}APPI: Integer; var AResultWidth: Integer);
procedure HintMouseLeave(Sender: TObject);
procedure HintTimer(Sender: TObject);
procedure ResetLongHintTimer;
procedure HideHint;
procedure HintMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure IncreaseChangeStep;
function GridIsUpdating: boolean;
function GetRow(Index:integer):TOIPropertyGridRow;
function GetRowCount:integer;
procedure ClearRows;
function GetCurrentEditValue: string;
procedure SetActiveControl(const AControl: TWinControl);
procedure SetCheckboxState(NewValue: string);
procedure SetColumn(const AValue: TOICustomPropertyGridColumn);
procedure SetCurrentEditValue(const NewValue: string);
procedure SetDrawHorzGridLines(const AValue: Boolean);
procedure SetFavorites(const AValue: TOIFavoriteProperties);
procedure SetFilter(const AValue: TTypeKinds);
procedure SetGutterColor(const AValue: TColor);
procedure SetGutterEdgeColor(const AValue: TColor);
procedure SetHighlightColor(const AValue: TColor);
procedure SetItemIndex(NewIndex:integer);
function IsCurrentEditorAvailable: Boolean;
function GetNameRowHeight: Integer; // temp solution untill TFont.height returns its actual value
procedure SetItemsTops;
procedure AlignEditComponents;
procedure EndDragSplitter;
procedure SetRowSpacing(const AValue: integer);
procedure SetShowGutter(const AValue: Boolean);
procedure SetSplitterX(const NewValue:integer);
procedure SetTopY(const NewValue:integer);
function GetPropNameColor(ARow: TOIPropertyGridRow):TColor;
function GetTreeIconX(Index: integer):integer;
function RowRect(ARow: integer):TRect;
procedure PaintRow(ARow: integer);
procedure DoPaint(PaintOnlyChangedValues: boolean);
procedure SetSelection(const ASelection:TPersistentSelectionList);
procedure SetPropertyEditorHook(NewPropertyEditorHook:TPropertyEditorHook);
procedure UpdateSelectionNotifications;
procedure HookGetCheckboxForBoolean(var Value: Boolean);
procedure AddPropertyEditor(PropEditor: TPropertyEditor);
procedure AddStringToComboBox(const s: string);
procedure ExpandRow(Index: integer);
procedure ShrinkRow(Index: integer);
procedure AddSubEditor(PropEditor: TPropertyEditor);
procedure SortSubEditors(ParentRow: TOIPropertyGridRow);
function CanExpandRow(Row: TOIPropertyGridRow): boolean;
procedure SetRowValue(CheckFocus, ForceValue: boolean);
procedure DoCallEdit(Edit: TOIQuickEdit = oiqeEdit);
procedure RefreshValueEdit;
procedure ToggleRow;
procedure ValueEditDblClick(Sender : TObject);
procedure ValueControlMouseDown(Sender: TObject; {%H-}Button:TMouseButton;
{%H-}Shift: TShiftState; {%H-}X,{%H-}Y:integer);
procedure ValueControlMouseMove(Sender: TObject; {%H-}Shift: TShiftState;
{%H-}X,{%H-}Y:integer);
procedure ValueEditKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
procedure ValueEditKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
procedure ValueEditExit(Sender: TObject);
procedure ValueEditChange(Sender: TObject);
procedure ValueEditMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; {%H-}X, {%H-}Y: Integer);
procedure ValueCheckBoxKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
procedure ValueCheckBoxKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
procedure ValueCheckBoxExit(Sender: TObject);
procedure ValueCheckBoxClick(Sender: TObject);
procedure ValueComboBoxExit(Sender: TObject);
procedure ValueComboBoxKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
procedure ValueComboBoxKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
procedure ValueComboBoxMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; {%H-}X, {%H-}Y: Integer);
procedure ValueComboBoxCloseUp(Sender: TObject);
procedure ValueComboBoxGetItems(Sender: TObject);
procedure ValueButtonClick(Sender: TObject);
procedure ValueComboBoxMeasureItem({%H-}Control: TWinControl; Index: Integer;
var AHeight: Integer);
procedure ValueComboBoxDrawItem({%H-}Control: TWinControl; Index: Integer;
ARect: TRect; State: TOwnerDrawState);
procedure OnIdle(Sender: TObject; var {%H-}Done: Boolean);
procedure SetIdleEvent(Enable: boolean);
procedure OnGridMouseWheel(Sender: TObject; {%H-}Shift: TShiftState;
WheelDelta: Integer; {%H-}MousePos: TPoint; var Handled: Boolean);
procedure WMVScroll(var Msg: TLMScroll); message LM_VSCROLL;
procedure SetBackgroundColor(const AValue: TColor);
procedure SetReferences(const AValue: TColor);
procedure SetSubPropertiesColor(const AValue: TColor);
procedure SetReadOnlyColor(const AValue: TColor);
procedure SetValueDifferBackgrndColor(AValue: TColor);
procedure UpdateScrollBar;
function FillComboboxItems: boolean; // true if something changed
function EditorFilter(const AEditor: TPropertyEditor): Boolean;
protected
procedure CreateParams(var Params: TCreateParams); override;
procedure CreateWnd; override;
procedure Notification(AComponent: TComponent; Operation: TOperation); override;
function DoMouseWheel(Shift: TShiftState; WheelDelta: Integer; MousePos: TPoint): Boolean; override;
procedure MouseDown(Button:TMouseButton; Shift:TShiftState; X,Y:integer); override;
procedure MouseMove(Shift:TShiftState; X,Y:integer); override;
procedure MouseUp(Button:TMouseButton; Shift:TShiftState; X,Y:integer); override;
procedure MouseLeave; override;
procedure KeyDown(var Key: Word; Shift: TShiftState); override;
procedure HandleStandardKeys(var Key: Word; Shift: TShiftState); virtual;
procedure HandleKeyUp(var Key: Word; Shift: TShiftState); virtual;
procedure DoTabKey; virtual;
procedure DoSetBounds(ALeft, ATop, AWidth, AHeight: integer); override;
procedure DoSelectionChange;
public
constructor Create(TheOwner: TComponent); override;
constructor CreateWithParams(AnOwner: TComponent;
APropertyEditorHook: TPropertyEditorHook;
TypeFilter: TTypeKinds;
DefItemHeight: integer);
destructor Destroy; override;
function InitHints: boolean;
function CanEditRowValue(CheckFocus: boolean): boolean;
procedure FocusCurrentEditor;
procedure SaveChanges;
function ConsistencyCheck: integer;
procedure EraseBackground({%H-}DC: HDC); override;
function GetActiveRow: TOIPropertyGridRow;
function GetHintTypeAt(RowIndex: integer; X: integer): TPropEditHint;
function GetRowByPath(const PropPath: string): TOIPropertyGridRow;
function GridHeight: integer;
function RealDefaultItemHeight: integer;
function MouseToIndex(y: integer; MustExist: boolean):integer;
function PropertyPath(Index: integer):string;
function PropertyPath(Row: TOIPropertyGridRow):string;
function TopMax: integer;
procedure BuildPropertyList(OnlyIfNeeded: Boolean = False; FocusEditor: Boolean = True);
procedure Clear;
procedure Paint; override;
procedure PropEditLookupRootChange;
procedure RefreshPropertyValues;
procedure ScrollToActiveItem;
procedure ScrollToItem(NewIndex: Integer);
procedure SetBounds(aLeft, aTop, aWidth, aHeight: integer); override;
procedure SetCurrentRowValue(const NewValue: string);
procedure SetItemIndexAndFocus(NewItemIndex: integer;
WasValueClick: Boolean = False);
property BackgroundColor: TColor read FBackgroundColor
write SetBackgroundColor default DefBackgroundColor;
property GutterColor: TColor read FGutterColor write SetGutterColor default DefGutterColor;
property GutterEdgeColor: TColor read FGutterEdgeColor write SetGutterEdgeColor default DefGutterEdgeColor;
property HighlightColor: TColor read FHighlightColor write SetHighlightColor default DefHighlightColor;
property ReferencesColor: TColor read FReferencesColor
write SetReferences default DefReferencesColor;
property SubPropertiesColor: TColor read FSubPropertiesColor
write SetSubPropertiesColor default DefSubPropertiesColor;
property ReadOnlyColor: TColor read FReadOnlyColor
write SetReadOnlyColor default DefReadOnlyColor;
property ValueDifferBackgrndColor: TColor read FValueDifferBackgrndColor
write SetValueDifferBackgrndColor default DefValueDifferBackgrndColor;
property NameFont: TFont read FNameFont write FNameFont;
property DefaultValueFont: TFont read FDefaultValueFont write FDefaultValueFont;
property ValueFont: TFont read FValueFont write FValueFont;
property HighlightFont: TFont read FHighlightFont write FHighlightFont;
property BorderStyle default bsSingle;
property Column: TOICustomPropertyGridColumn read FColumn write SetColumn;
property CurrentEditValue: string read GetCurrentEditValue
write SetCurrentEditValue;
property DefaultItemHeight:integer read FDefaultItemHeight
write FDefaultItemHeight default 0;
property DrawHorzGridLines: Boolean read FDrawHorzGridLines write
SetDrawHorzGridLines default True;
property ExpandedProperties: TStringList read FExpandedProperties
write FExpandedProperties;
property Indent: integer read FIndent write FIndent;
property ItemIndex: integer read FItemIndex write SetItemIndex;
property Layout: TOILayout read FLayout write FLayout default oilHorizontal;
property OnEditorFilter: TOIEditorFilterEvent read FOnEditorFilter write FOnEditorFilter;
property OnModified: TNotifyEvent read FOnModified write FOnModified;
property OnOIKeyDown: TKeyEvent read FOnOIKeyDown write FOnOIKeyDown;
property OnSelectionChange: TNotifyEvent read FOnSelectionChange write FOnSelectionChange;
property OnPropertyHint: TOIPropertyHintEvent read FOnPropertyHint write FOnPropertyHint;
property PropertyEditorHook: TPropertyEditorHook read FPropertyEditorHook
write SetPropertyEditorHook;
property RowCount: integer read GetRowCount;
property Rows[Index: integer]: TOIPropertyGridRow read GetRow;
property RowSpacing: integer read FRowSpacing write SetRowSpacing;
property Selection: TPersistentSelectionList read FSelection write SetSelection;
property ShowGutter: Boolean read FShowGutter write SetShowGutter default True;
property CheckboxForBoolean: Boolean read FCheckboxForBoolean write FCheckboxForBoolean;
property PreferredSplitterX: integer read FPreferredSplitterX
write FPreferredSplitterX default 100;
property SplitterX: integer read FSplitterX write SetSplitterX default 100;
property TopY: integer read FTopY write SetTopY default 0;
property Favorites: TOIFavoriteProperties read FFavorites write SetFavorites;
property Filter : TTypeKinds read FFilter write SetFilter;
property HideClassNames: Boolean read FHideClassNames write FHideClassNames;
property PropNameFilter : String read FPropNameFilter write FPropNameFilter;
end;
{ TOIPropertyGrid }
TOIPropertyGrid = class(TOICustomPropertyGrid)
published
property Align;
property Anchors;
property BackgroundColor;
property BorderStyle;
property Constraints;
property DefaultItemHeight;
property DefaultValueFont;
property Indent;
property NameFont;
property OnChangeBounds;
property OnClick;
property OnDblClick;
property OnEnter;
property OnExit;
property OnKeyDown;
property OnKeyPress;
property OnKeyUp;
property OnModified;
property OnMouseDown;
property OnMouseEnter;
property OnMouseLeave;
property OnMouseMove;
property OnMouseUp;
property OnResize;
property OnSelectionChange;
property PopupMenu;
property PreferredSplitterX;
property SplitterX;
property Tabstop;
property ValueFont;
property Visible;
end;
{ TCustomPropertiesGrid }
TCustomPropertiesGrid = class(TOICustomPropertyGrid)
private
FAutoFreeHook: boolean;
FSaveOnChangeTIObject: boolean;
function GetTIObject: TPersistent;
procedure SetAutoFreeHook(const AValue: boolean);
procedure SetTIObject(const AValue: TPersistent);
public
constructor Create(TheOwner: TComponent); override;
destructor Destroy; override;
property TIObject: TPersistent read GetTIObject write SetTIObject;
property AutoFreeHook: boolean read FAutoFreeHook write SetAutoFreeHook;
property SaveOnChangeTIObject: boolean read FSaveOnChangeTIObject
write FSaveOnChangeTIObject
default true;
end;
//============================================================================
TAddAvailablePersistentEvent = procedure(APersistent: TPersistent;
var Allowed: boolean) of object;
//copy of TGetPersistentImageIndexEvent
TOnOINodeGetImageEvent = procedure(APersistent: TPersistent;
var AImageIndex: integer) of object;
TOIFlag = (
oifRebuildPropListsNeeded
);
TOIFlags = set of TOIFlag;
{ TObjectInspectorDlg }
TObjectInspectorDlg = class(TForm)
MainPopupMenu: TPopupMenu;
AvailPersistentComboBox: TComboBox;
ComponentPanel: TPanel;
CompFilterLabel: TLabel;
CompFilterEdit: TTreeFilterEdit;
PnlClient: TPanel;
StatusBar: TStatusBar;
procedure FormResize(Sender: TObject);
procedure MainPopupMenuClose(Sender: TObject);
procedure MainPopupMenuPopup(Sender: TObject);
procedure AvailComboBoxCloseUp(Sender: TObject);
private
// These are created at run-time, no need for default published section.
PropertyPanel: TPanel;
PropFilterLabel: TLabel;
PropFilterEdit: TListFilterEdit;
RestrictedPanel: TPanel;
RestrictedInnerPanel: TPanel;
WidgetSetsRestrictedLabel: TLabel;
WidgetSetsRestrictedBox: TPaintBox;
ComponentRestrictedLabel: TLabel;
ComponentRestrictedBox: TPaintBox;
NoteBook: TPageControl;
Splitter1: TSplitter;
Splitter2: TSplitter;
// MenuItems
AddToFavoritesPopupMenuItem: TMenuItem;
ViewRestrictedPropertiesPopupMenuItem: TMenuItem;
CopyPopupmenuItem: TMenuItem;
CutPopupmenuItem: TMenuItem;
PastePopupmenuItem: TMenuItem;
DeletePopupmenuItem: TMenuItem;
ChangeClassPopupmenuItem: TMenuItem;
ChangeParentPopupmenuItem: TMenuItem;
FindDeclarationPopupmenuItem: TMenuItem;
OptionsSeparatorMenuItem: TMenuItem;
OptionsSeparatorMenuItem2: TMenuItem;
OptionsSeparatorMenuItem3: TMenuItem;
RemoveFromFavoritesPopupMenuItem: TMenuItem;
ShowComponentTreePopupMenuItem: TMenuItem;
ShowHintsPopupMenuItem: TMenuItem;
ShowInfoBoxPopupMenuItem: TMenuItem;
ShowStatusBarPopupMenuItem: TMenuItem;
ShowOptionsPopupMenuItem: TMenuItem;
UndoPropertyPopupMenuItem: TMenuItem;
// Variables
FAutoShow: Boolean;
FCheckboxForBoolean: Boolean;
FComponentEditor: TBaseComponentEditor;
FDefaultItemHeight: integer;
FEnableHookGetSelection: boolean;
FFavorites: TOIFavoriteProperties;
FFilter: TTypeKinds;
FFlags: TOIFlags;
FInfoBoxHeight: integer;
FLastActiveRowName: String;
FPropertyEditorHook: TPropertyEditorHook;
FPropFilterUpdating: Boolean;
FRefreshingSelectionCount: integer;
FRestricted: TOIRestrictedProperties;
FSelection: TPersistentSelectionList;
FSettingSelectionCount: integer;
FShowComponentTree: Boolean;
FShowFavorites: Boolean;
FShowInfoBox: Boolean;
FShowRestricted: Boolean;
FShowStatusBar: Boolean;
FStateOfHintsOnMainPopupMenu: Boolean;
FUpdateLock: integer;
FUpdatingAvailComboBox: Boolean;
// Events
FOnAddAvailablePersistent: TAddAvailablePersistentEvent;
FOnAddToFavorites: TNotifyEvent;
FOnAutoShow: TNotifyEvent;
FOnFindDeclarationOfProperty: TNotifyEvent;
FOnModified: TNotifyEvent;
FOnNodeGetImageIndex: TOnOINodeGetImageEvent;
FOnOIKeyDown: TKeyEvent;
FOnPropertyHint: TOIPropertyHintEvent;
FOnRemainingKeyDown: TKeyEvent;
FOnRemainingKeyUp: TKeyEvent;
FOnRemoveFromFavorites: TNotifyEvent;
FOnSelectionChange: TNotifyEvent;
FOnSelectPersistentsInOI: TNotifyEvent;
FOnShowOptions: TNotifyEvent;
FOnUpdateRestricted: TNotifyEvent;
FOnViewRestricted: TNotifyEvent;
// These event handlers are assigned at run-time, no need for default published section.
procedure ComponentTreeDblClick(Sender: TObject);
procedure ComponentTreeGetNodeImageIndex(APersistent: TPersistent; var AIndex: integer);
procedure ComponentTreeKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
procedure ComponentTreeSelectionChanged(Sender: TObject);
procedure GridKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
procedure GridKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
procedure GridDblClick(Sender: TObject);
procedure GridModified(Sender: TObject);
procedure GridSelectionChange(Sender: TObject);
function GridPropertyHint(Sender: TObject; PointedRow: TOIPropertyGridRow;
out AHint: string): boolean;
procedure PropEditPopupClick(Sender: TObject);
procedure AddToFavoritesPopupmenuItemClick(Sender: TObject);
procedure RemoveFromFavoritesPopupmenuItemClick(Sender: TObject);
procedure ViewRestrictionsPopupmenuItemClick(Sender: TObject);
procedure UndoPopupmenuItemClick(Sender: TObject);
procedure FindDeclarationPopupmenuItemClick(Sender: TObject);
procedure CutPopupmenuItemClick(Sender: TObject);
procedure CopyPopupmenuItemClick(Sender: TObject);
procedure PastePopupmenuItemClick(Sender: TObject);
procedure DeletePopupmenuItemClick(Sender: TObject);
procedure ChangeClassPopupmenuItemClick(Sender: TObject);
procedure ComponentTreeModified(Sender: TObject);
procedure ShowComponentTreePopupMenuItemClick(Sender: TObject);
procedure ShowHintPopupMenuItemClick(Sender: TObject);
procedure ShowInfoBoxPopupMenuItemClick(Sender: TObject);
procedure ShowStatusBarPopupMenuItemClick(Sender: TObject);
procedure ShowOptionsPopupMenuItemClick(Sender: TObject);
procedure RestrictedPageShow(Sender: TObject);
procedure WidgetSetRestrictedPaint(Sender: TObject);
procedure ComponentRestrictedPaint(Sender: TObject);
procedure PropFilterEditAfterFilter(Sender: TObject);
procedure PropFilterEditResize(Sender: TObject);
procedure NoteBookPageChange(Sender: TObject);
procedure ChangeParentItemClick(Sender: TObject);
procedure CollectionAddItem(Sender: TObject);
procedure ComponentEditorVerbMenuItemClick(Sender: TObject);
procedure ZOrderItemClick(Sender: TObject);
procedure TopSplitterMoved(Sender: TObject);
// Methods
procedure DoModified;
procedure DoUpdateRestricted;
procedure DoViewRestricted;
function GetComponentPanelHeight: integer;
function GetGridControl(Page: TObjectInspectorPage): TOICustomPropertyGrid;
function GetInfoBoxHeight: integer;
function GetParentCandidates: TFPList;
function GetSelectedPersistent: TPersistent;
function GetComponentEditorForSelection: TBaseComponentEditor;
procedure CreateBottomSplitter;
procedure CreateTopSplitter;
procedure DefSelectionVisibleInDesigner;
procedure RestrictedPaint(
ABox: TPaintBox; const ARestrictions: TWidgetSetRestrictionsArray);
function PersistentToString(APersistent: TPersistent): string;
procedure AddPersistentToList(APersistent: TPersistent; List: TStrings);
procedure HookLookupRootChange;
procedure FillPersistentComboBox;
procedure SetAvailComboBoxText;
procedure HookGetSelection(const ASelection: TPersistentSelectionList);
procedure HookSetSelection(const ASelection: TPersistentSelectionList);
procedure DestroyNoteBook;
procedure CreateNoteBook;
procedure ShowNextPage(Delta: integer);
// Setter
procedure SetComponentEditor(const AValue: TBaseComponentEditor);
procedure SetComponentPanelHeight(const AValue: integer);
procedure SetDefaultItemHeight(const AValue: integer);
procedure SetEnableHookGetSelection(AValue: boolean);
procedure SetFavorites(const AValue: TOIFavoriteProperties);
procedure SetFilter(const AValue: TTypeKinds);
procedure SetInfoBoxHeight(const AValue: integer);
procedure SetOnShowOptions(const AValue: TNotifyEvent);
procedure SetPropertyEditorHook(const AValue: TPropertyEditorHook);
procedure SetRestricted(const AValue: TOIRestrictedProperties);
procedure SetSelection(const ASelection: TPersistentSelectionList);
procedure SetShowComponentTree(const AValue: boolean);
procedure SetShowFavorites(const AValue: Boolean);
procedure SetShowInfoBox(const AValue: Boolean);
procedure SetShowRestricted(const AValue: Boolean);
procedure SetShowStatusBar(const AValue: Boolean);
protected
procedure KeyDown(var Key: Word; Shift: TShiftState); override;
procedure KeyUp(var Key: Word; Shift: TShiftState); override;
procedure Resize; override;
public
// These are created at run-time, no need for default published section.
ComponentTree: TComponentTreeView;
InfoPanel: TPanel;
EventGrid: TOICustomPropertyGrid;
FavoriteGrid: TOICustomPropertyGrid;
RestrictedGrid: TOICustomPropertyGrid;
PropertyGrid: TOICustomPropertyGrid;
//
constructor Create(AnOwner: TComponent); override;
destructor Destroy; override;
procedure RefreshSelection;
procedure RefreshComponentTreeSelection;
procedure SaveChanges;
procedure RefreshPropertyValues;
procedure RebuildPropertyLists;
procedure FillComponentList;
procedure UpdateComponentValues;
procedure BeginUpdate;
procedure EndUpdate;
function GetActivePropertyGrid: TOICustomPropertyGrid;
function GetActivePropertyRow: TOIPropertyGridRow;
function GetCurRowDefaultValue(var DefaultStr: string): Boolean;
function HasParentCandidates: Boolean;
procedure ChangeParent;
procedure HookRefreshPropertyValues;
procedure ActivateGrid(Grid: TOICustomPropertyGrid);
procedure FocusGrid(Grid: TOICustomPropertyGrid = nil);
public
property ComponentEditor: TBaseComponentEditor read FComponentEditor write SetComponentEditor;
property ComponentPanelHeight: integer read GetComponentPanelHeight
write SetComponentPanelHeight;
property DefaultItemHeight: integer read FDefaultItemHeight
write SetDefaultItemHeight;
property EnableHookGetSelection: Boolean read FEnableHookGetSelection
write SetEnableHookGetSelection;
property Favorites: TOIFavoriteProperties read FFavorites write SetFavorites;
property Filter: TTypeKinds read FFilter write SetFilter;
property GridControl[Page: TObjectInspectorPage]: TOICustomPropertyGrid
read GetGridControl;
property InfoBoxHeight: integer read GetInfoBoxHeight write SetInfoBoxHeight;
property PropertyEditorHook: TPropertyEditorHook read FPropertyEditorHook
write SetPropertyEditorHook;
property RestrictedProps: TOIRestrictedProperties read FRestricted write SetRestricted;
property Selection: TPersistentSelectionList read FSelection write SetSelection;
property AutoShow: Boolean read FAutoShow write FAutoShow;
property ShowComponentTree: Boolean read FShowComponentTree write SetShowComponentTree;
property ShowFavorites: Boolean read FShowFavorites write SetShowFavorites;
property ShowInfoBox: Boolean read FShowInfoBox write SetShowInfoBox;
property ShowRestricted: Boolean read FShowRestricted write SetShowRestricted;
property ShowStatusBar: Boolean read FShowStatusBar write SetShowStatusBar;
property LastActiveRowName: string read FLastActiveRowName;
// Events
property OnAddAvailPersistent: TAddAvailablePersistentEvent
read FOnAddAvailablePersistent write FOnAddAvailablePersistent;
property OnAddToFavorites: TNotifyEvent read FOnAddToFavorites write FOnAddToFavorites;
property OnAutoShow: TNotifyEvent read FOnAutoShow write FOnAutoShow;
property OnFindDeclarationOfProperty: TNotifyEvent read FOnFindDeclarationOfProperty
write FOnFindDeclarationOfProperty;
property OnModified: TNotifyEvent read FOnModified write FOnModified;
property OnOIKeyDown: TKeyEvent read FOnOIKeyDown write FOnOIKeyDown;
property OnPropertyHint: TOIPropertyHintEvent read FOnPropertyHint write FOnPropertyHint;
property OnRemainingKeyDown: TKeyEvent read FOnRemainingKeyDown
write FOnRemainingKeyDown;
property OnRemainingKeyUp: TKeyEvent read FOnRemainingKeyUp
write FOnRemainingKeyUp;
property OnRemoveFromFavorites: TNotifyEvent read FOnRemoveFromFavorites
write FOnRemoveFromFavorites;
property OnSelectionChange: TNotifyEvent read FOnSelectionChange write FOnSelectionChange;
property OnSelectPersistentsInOI: TNotifyEvent read FOnSelectPersistentsInOI
write FOnSelectPersistentsInOI;
property OnShowOptions: TNotifyEvent read FOnShowOptions write SetOnShowOptions;
property OnUpdateRestricted: TNotifyEvent read FOnUpdateRestricted
write FOnUpdateRestricted;
property OnViewRestricted: TNotifyEvent read FOnViewRestricted write FOnViewRestricted;
property OnNodeGetImageIndex : TOnOINodeGetImageEvent read FOnNodeGetImageIndex
write FOnNodeGetImageIndex;
end;
const
DefaultObjectInspectorName: string = 'ObjectInspectorDlg';
// the ObjectInspector descendant of the IDE can be found in FormEditingIntf
function dbgs(s: TOIPropertyGridState): string; overload;
function dbgs(States: TOIPropertyGridStates): string; overload;
function GetChangeParentCandidates(PropertyEditorHook: TPropertyEditorHook;
Selection: TPersistentSelectionList): TFPList;
const
DefaultOIPageNames: array[TObjectInspectorPage] of shortstring = (
'PropertyPage',
'EventPage',
'FavoritePage',
'RestrictedPage'
);
DefaultOIGridNames: array[TObjectInspectorPage] of shortstring = (
'PropertyGrid',
'EventGrid',
'FavoriteGrid',
'RestrictedGrid'
);
implementation
{$R *.lfm}
{$R images\ideintf_images.res}
function SortGridRows(Item1, Item2 : pointer) : integer;
begin
Result:=SysUtils.CompareText(TOIPropertyGridRow(Item1).Name,
TOIPropertyGridRow(Item2).Name);
end;
function dbgs(s: TOIPropertyGridState): string;
begin
Result:=GetEnumName(TypeInfo(s),ord(s));
end;
function dbgs(States: TOIPropertyGridStates): string;
var
s: TOIPropertyGridState;
begin
Result:='';
for s in States do
begin
if not (s in States) then continue;
if Result<>'' then Result+=',';
Result+=dbgs(s);
end;
Result:='['+Result+']';
end;
function GetChangeParentCandidates(PropertyEditorHook: TPropertyEditorHook;
Selection: TPersistentSelectionList): TFPList;
function CanBeParent(Child, Parent: TPersistent): boolean;
begin
Result:=false;
if Child = Parent then exit;
if not (Parent is TWinControl) then exit;
if not (Child is TControl) then exit;
if (Child is TWinControl) and
(Child = TWinControl(Parent).Parent) then
exit;
if not ControlAcceptsStreamableChildComponent(TWinControl(Parent),
TComponentClass(Child.ClassType), PropertyEditorHook.LookupRoot)
then
exit;
try
TControl(Child).CheckNewParent(TWinControl(Parent));
except
exit;
end;
Result:=true;
end;
function CanBeParentOfSelection(Parent: TPersistent): boolean;
var
i: Integer;
begin
for i:=0 to Selection.Count-1 do
if not CanBeParent(Selection[i],Parent) then exit(false);
Result:=true;
end;
var
i: Integer;
Candidate: TWinControl;
begin
Result := TFPList.Create;
if not (PropertyEditorHook.LookupRoot is TWinControl) then
exit; // only LCL controls are supported at the moment
// check if any selected control can be moved
i := Selection.Count-1;
while i >= 0 do
begin
if (Selection[i] is TControl)
and (TControl(Selection[i]).Owner = PropertyEditorHook.LookupRoot)
then
// this one can be moved
break;
dec(i);
end;
if i < 0 then Exit;
// find possible new parents
for i := 0 to TWinControl(PropertyEditorHook.LookupRoot).ComponentCount-1 do
begin
Candidate := TWinControl(TWinControl(PropertyEditorHook.LookupRoot).Components[i]);
if CanBeParentOfSelection(Candidate) then
Result.Add(Candidate);
end;
if CanBeParentOfSelection(PropertyEditorHook.LookupRoot) then
Result.Add(PropertyEditorHook.LookupRoot);
end;
{ TOICustomPropertyGrid }
constructor TOICustomPropertyGrid.CreateWithParams(AnOwner:TComponent;
APropertyEditorHook:TPropertyEditorHook; TypeFilter:TTypeKinds; DefItemHeight: integer);
var
Details: TThemedElementDetails;
begin
inherited Create(AnOwner);
FLayout := oilHorizontal;
FSelection:=TPersistentSelectionList.Create;
FNotificationComponents:=TFPList.Create;
PropertyEditorHook:=APropertyEditorHook; // Through property setter.
FFilter:=TypeFilter;
FItemIndex:=-1;
FStates:=[];
FColumn := oipgcValue;
FRows:=TFPList.Create;
FExpandingRow:=nil;
FDragging:=false;
FExpandedProperties:=TStringList.Create;
FCurrentEdit:=nil;
FCurrentButton:=nil;
// visible values
FTopY:=0;
FSplitterX:=100;
FPreferredSplitterX:=FSplitterX;
Details := ThemeServices.GetElementDetails(ttGlyphOpened);
FIndent := ThemeServices.GetDetailSize(Details).cx;
FBackgroundColor:=DefBackgroundColor;
FReferencesColor:=DefReferencesColor;
FSubPropertiesColor:=DefSubPropertiesColor;
FReadOnlyColor:=DefReadOnlyColor;
FHighlightColor:=DefHighlightColor;
FGutterColor:=DefGutterColor;
FGutterEdgeColor:=DefGutterEdgeColor;
FValueDifferBackgrndColor:=DefValueDifferBackgrndColor;
FNameFont:=TFont.Create;
FNameFont.Color:=DefNameColor;
FValueFont:=TFont.Create;
FValueFont.Color:=DefValueColor;
FDefaultValueFont:=TFont.Create;
FDefaultValueFont.Color:=DefDefaultValueColor;
FHighlightFont:=TFont.Create;
FHighlightFont.Color:=DefHighlightFontColor;
FDrawHorzGridLines := True;
FShowGutter := True;
SetInitialBounds(0,0,200,130);
ControlStyle:=ControlStyle+[csAcceptsControls,csOpaque];
BorderWidth:=0;
BorderStyle := bsSingle;
// create sub components
ValueEdit:=TEdit.Create(Self);
with ValueEdit do
begin
Name:='ValueEdit';
Visible:=false;
Enabled:=false;
AutoSize:=false;
SetBounds(0,-30,80,25); // hidden
Parent:=Self;
OnMouseDown := @ValueControlMouseDown;
OnMouseMove := @ValueControlMouseMove;
OnDblClick := @ValueEditDblClick;
OnExit:=@ValueEditExit;
OnChange:=@ValueEditChange;
OnKeyDown:=@ValueEditKeyDown;
OnKeyUp:=@ValueEditKeyUp;
OnMouseUp:=@ValueEditMouseUp;
OnMouseWheel:=@OnGridMouseWheel;
end;
ValueComboBox:=TComboBox.Create(Self);
with ValueComboBox do
begin
Name:='ValueComboBox';
Sorted:=true;
AutoSelect:=true;
AutoComplete:=true;
Visible:=false;
Enabled:=false;
AutoSize:=false;
SetBounds(0,-30,Width,Height); // hidden
DropDownCount:=20;
ItemHeight:=MulDiv(17, Screen.PixelsPerInch, 96);
Parent:=Self;
OnMouseDown := @ValueControlMouseDown;
OnMouseMove := @ValueControlMouseMove;
OnDblClick := @ValueEditDblClick;
OnExit:=@ValueComboBoxExit;
//OnChange:=@ValueComboBoxChange; the on change event is called even,
// if the user is still editing
OnKeyDown:=@ValueComboBoxKeyDown;
OnKeyUp:=@ValueComboBoxKeyUp;
OnMouseUp:=@ValueComboBoxMouseUp;
OnGetItems:=@ValueComboBoxGetItems;
OnCloseUp:=@ValueComboBoxCloseUp;
OnMeasureItem:=@ValueComboBoxMeasureItem;
OnDrawItem:=@ValueComboBoxDrawItem;
OnMouseWheel:=@OnGridMouseWheel;
end;
ValueCheckBox:={$IFnDEF UseOINormalCheckBox} TCheckBoxThemed.Create(Self); {$ELSE} TCheckBox.Create(Self); {$ENDIF}
with ValueCheckBox do
begin
Name:='ValueCheckBox';
Visible:=false;
Enabled:=false;
{$IFnDEF UseOINormalCheckBox}
AutoSize := false;
{$ELSE}
AutoSize := true; // SetBounds does not work for CheckBox, AutoSize does.
{$ENDIF}
Parent:=Self;
Top := -30;
OnMouseDown := @ValueControlMouseDown;
OnMouseMove := @ValueControlMouseMove;
OnExit:=@ValueCheckBoxExit;
OnKeyDown:=@ValueCheckBoxKeyDown;
OnKeyUp:=@ValueCheckBoxKeyUp;
OnClick:=@ValueCheckBoxClick;
OnMouseWheel:=@OnGridMouseWheel;
end;
ValueButton:=TSpeedButton.Create(Self);
with ValueButton do
begin
Name:='ValueButton';
Visible:=false;
Enabled:=false;
Transparent:=false;
OnClick:=@ValueButtonClick;
Caption := '...';
SetBounds(0,-30,Width,Height); // hidden
Parent:=Self;
OnMouseWheel:=@OnGridMouseWheel;
end;
FHintManager := THintWindowManager.Create;
FActiveRowImages := TLCLGlyphs.Create(Self);
FActiveRowImages.Width := 9;
FActiveRowImages.Height := 9;
FActiveRowImages.RegisterResolutions([9, 13, 18], [100, 150, 200]);
FActiveRowImages.OnGetWidthForPPI := @ActiveRowImagesGetWidthForPPI;
FDefaultItemHeight:=DefItemHeight;
BuildPropertyList;
end;
procedure TOICustomPropertyGrid.ActiveRowImagesGetWidthForPPI(
Sender: TCustomImageList; AImageWidth, APPI: Integer;
var AResultWidth: Integer);
begin
if (12<=AResultWidth) and (AResultWidth<=16) then
AResultWidth := 13;
end;
constructor TOICustomPropertyGrid.Create(TheOwner: TComponent);
begin
CreateWithParams(TheOwner,nil,AllTypeKinds,0);
end;
destructor TOICustomPropertyGrid.Destroy;
var
a: integer;
begin
SetIdleEvent(false);
FItemIndex := -1;
for a := 0 to FRows.Count - 1 do
Rows[a].Free;
FreeAndNil(FRows);
FreeAndNil(FSelection);
FreeAndNil(FNotificationComponents);
FreeAndNil(FValueFont);
FreeAndNil(FDefaultValueFont);
FreeAndNil(FNameFont);
FreeAndNil(FHighlightFont);
FreeAndNil(FExpandedProperties);
FreeAndNil(FLongHintTimer);
FreeAndNil(FHintManager);
FreeAndNil(FNewComboBoxItems);
inherited Destroy;
end;
function TOICustomPropertyGrid.InitHints: boolean;
begin
if not ShowHint then exit(false);
Result := true;
if FLongHintTimer = nil then
begin
FHintIndex := -1;
FShowingLongHint := False;
FLongHintTimer := TTimer.Create(nil);
FLongHintTimer.Interval := 500;
FLongHintTimer.Enabled := False;
FLongHintTimer.OnTimer := @HintTimer;
FHintManager.OnMouseDown := @HintMouseDown;
FHintManager.WindowName := 'This_is_a_hint_window';
FHintManager.HideInterval := 4000;
FHintManager.AutoHide := True;
end
end;
procedure TOICustomPropertyGrid.UpdateScrollBar;
var
ScrollInfo: TScrollInfo;
ATopMax: Integer;
begin
if HandleAllocated then begin
ATopMax := TopMax;
ScrollInfo.cbSize := SizeOf(ScrollInfo);
ScrollInfo.fMask := SIF_ALL or SIF_DISABLENOSCROLL;
ScrollInfo.nMin := 0;
ScrollInfo.nTrackPos := 0;
ScrollInfo.nMax := ATopMax+ClientHeight-1;
if ClientHeight < 2 then
ScrollInfo.nPage := 1
else
ScrollInfo.nPage := ClientHeight-1;
if TopY > ATopMax then
TopY := ATopMax;
ScrollInfo.nPos := TopY;
ShowScrollBar(Handle, SB_VERT, True);
SetScrollInfo(Handle, SB_VERT, ScrollInfo, True);
end;
end;
function TOICustomPropertyGrid.FillComboboxItems: boolean;
var
ExcludeUpdateFlag: boolean;
CurRow: TOIPropertyGridRow;
begin
Result:=false;
ExcludeUpdateFlag:=not (pgsUpdatingEditControl in FStates);
Include(FStates,pgsUpdatingEditControl);
ValueComboBox.Items.BeginUpdate;
try
CurRow:=Rows[FItemIndex];
if FNewComboBoxItems<>nil then FNewComboBoxItems.Clear;
CurRow.Editor.GetValues(@AddStringToComboBox);
if FNewComboBoxItems<>nil then begin
FNewComboBoxItems.Sorted:=paSortList in CurRow.Editor.GetAttributes;
if ValueComboBox.Items.Equals(FNewComboBoxItems) then exit;
ValueComboBox.Items.Assign(FNewComboBoxItems);
//debugln('TOICustomPropertyGrid.FillComboboxItems "',FNewComboBoxItems.Text,'" Cur="',ValueComboBox.Items.Text,'" ValueComboBox.Items.Count=',dbgs(ValueComboBox.Items.Count));
end else if ValueComboBox.Items.Count=0 then begin
exit;
end else begin
ValueComboBox.Items.Text:='';
ValueComboBox.Items.Clear;
//debugln('TOICustomPropertyGrid.FillComboboxItems FNewComboBoxItems=nil Cur="',ValueComboBox.Items.Text,'" ValueComboBox.Items.Count=',dbgs(ValueComboBox.Items.Count));
end;
Result:=true;
//debugln(['TOICustomPropertyGrid.FillComboboxItems CHANGED']);
finally
FreeAndNil(FNewComboBoxItems);
ValueComboBox.Items.EndUpdate;
if ExcludeUpdateFlag then
Exclude(FStates,pgsUpdatingEditControl);
end;
end;
procedure TOICustomPropertyGrid.CreateParams(var Params: TCreateParams);
const
ClassStylesOff = CS_VREDRAW or CS_HREDRAW;
begin
inherited CreateParams(Params);
with Params do begin
{$IFOPT R+}{$DEFINE RangeChecking}{$ENDIF}
{$R-}
WindowClass.Style := WindowClass.Style and not ClassStylesOff;
Style := Style or WS_VSCROLL or WS_CLIPCHILDREN;
{$IFDEF RangeChecking}{$R+}{$UNDEF RangeChecking}{$ENDIF}
ExStyle := ExStyle or WS_EX_CLIENTEDGE;
end;
end;
procedure TOICustomPropertyGrid.CreateWnd;
begin
inherited CreateWnd;
// handle just created, set scrollbar
UpdateScrollBar;
end;
procedure TOICustomPropertyGrid.Notification(AComponent: TComponent;
Operation: TOperation);
var
i: LongInt;
begin
if (Operation=opRemove) and (FNotificationComponents<>nil) then begin
FNotificationComponents.Remove(AComponent);
i:=FSelection.IndexOf(AComponent);
if i>=0 then begin
FSelection.Delete(i);
Include(FStates,pgsBuildPropertyListNeeded);
end;
end;
inherited Notification(AComponent, Operation);
end;
procedure TOICustomPropertyGrid.WMVScroll(var Msg: TLMScroll);
begin
case Msg.ScrollCode of
// Scrolls to start / end of the text
SB_TOP: TopY := 0;
SB_BOTTOM: TopY := TopMax;
// Scrolls one line up / down
SB_LINEDOWN: TopY := TopY + RealDefaultItemHeight div 2;
SB_LINEUP: TopY := TopY - RealDefaultItemHeight div 2;
// Scrolls one page of lines up / down
SB_PAGEDOWN: TopY := TopY + ClientHeight - RealDefaultItemHeight;
SB_PAGEUP: TopY := TopY - ClientHeight + RealDefaultItemHeight;
// Scrolls to the current scroll bar position
SB_THUMBPOSITION,
SB_THUMBTRACK: TopY := Msg.Pos;
// Ends scrolling
SB_ENDSCROLL: SetCaptureControl(nil); // release scrollbar capture
end;
end;
function TOICustomPropertyGrid.DoMouseWheel(Shift: TShiftState; WheelDelta: Integer; MousePos: TPoint): Boolean;
var
H: Boolean;
begin
H := False;
OnGridMouseWheel(Self, Shift, WheelDelta, MousePos, H);
Result:=true;
end;
procedure TOICustomPropertyGrid.OnGridMouseWheel(Sender: TObject; Shift: TShiftState;
WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean);
begin
if Mouse.WheelScrollLines=-1 then
// -1 : scroll by page
TopY := TopY - (WheelDelta * (ClientHeight - RealDefaultItemHeight)) div 120
else
// scrolling one line -> scroll half an item, see SB_LINEDOWN and SB_LINEUP
// handler in WMVScroll
TopY := TopY - (WheelDelta * Mouse.WheelScrollLines*RealDefaultItemHeight) div 240;
Handled := True;
end;
function TOICustomPropertyGrid.IsCurrentEditorAvailable: Boolean;
begin
Result := (FCurrentEdit <> nil) and InRange(FItemIndex, 0, FRows.Count - 1);
end;
procedure TOICustomPropertyGrid.FocusCurrentEditor;
begin
if (IsCurrentEditorAvailable) and (FCurrentEdit.CanFocus) then
begin
FCurrentEdit.SetFocus;
if (FCurrentEdit is TEdit) then
(FCurrentEdit as TEdit).SelStart := Length((FCurrentEdit as TEdit).Text);
end;
end;
function TOICustomPropertyGrid.ConsistencyCheck: integer;
var
i: integer;
begin
for i:=0 to FRows.Count-1 do begin
if Rows[i]=nil then begin
Result:=-1;
exit;
end;
if Rows[i].Index<>i then begin
Result:=-2;
exit;
end;
Result:=Rows[i].ConsistencyCheck;
if Result<>0 then begin
dec(Result,100);
exit;
end;
end;
Result:=0;
end;
procedure TOICustomPropertyGrid.SetSelection(const ASelection: TPersistentSelectionList);
var
CurRow:TOIPropertyGridRow;
OldSelectedRowPath:string;
begin
if ASelection=nil then exit;
if (not ASelection.ForceUpdate) and FSelection.IsEqual(ASelection) then exit;
OldSelectedRowPath:=PropertyPath(ItemIndex);
if FCurrentEdit = ValueEdit then
ValueEditExit(Self);
ItemIndex:=-1;
ClearRows;
FSelection.Assign(ASelection);
UpdateSelectionNotifications;
BuildPropertyList;
CurRow:=GetRowByPath(OldSelectedRowPath);
if CurRow<>nil then
ItemIndex:=CurRow.Index;
Column := oipgcValue;
end;
procedure TOICustomPropertyGrid.SetPropertyEditorHook(
NewPropertyEditorHook:TPropertyEditorHook);
begin
if FPropertyEditorHook=NewPropertyEditorHook then exit;
FPropertyEditorHook:=NewPropertyEditorHook;
FPropertyEditorHook.AddHandlerGetCheckboxForBoolean(@HookGetCheckboxForBoolean);
IncreaseChangeStep;
SetSelection(FSelection);
end;
procedure TOICustomPropertyGrid.UpdateSelectionNotifications;
var
i: Integer;
AComponent: TComponent;
begin
for i:=0 to FSelection.Count-1 do begin
if FSelection[i] is TComponent then begin
AComponent:=TComponent(FSelection[i]);
if FNotificationComponents.IndexOf(AComponent)<0 then begin
FNotificationComponents.Add(AComponent);
AComponent.FreeNotification(Self);
end;
end;
end;
for i:=FNotificationComponents.Count-1 downto 0 do begin
AComponent:=TComponent(FNotificationComponents[i]);
if FSelection.IndexOf(AComponent)<0 then begin
FNotificationComponents.Delete(i);
AComponent.RemoveFreeNotification(Self);
end;
end;
//DebugLn(['TOICustomPropertyGrid.UpdateSelectionNotifications FNotificationComponents=',FNotificationComponents.Count,' FSelection=',FSelection.Count]);
end;
procedure TOICustomPropertyGrid.HookGetCheckboxForBoolean(var Value: Boolean);
begin
Value := FCheckboxForBoolean;
end;
function TOICustomPropertyGrid.PropertyPath(Index:integer):string;
begin
if (Index>=0) and (Index<FRows.Count) then begin
Result:=PropertyPath(Rows[Index]);
end else
Result:='';
end;
function TOICustomPropertyGrid.PropertyPath(Row: TOIPropertyGridRow): string;
begin
if Row=nil then begin
Result:='';
exit;
end;
Result:=Row.Name;
Row:=Row.Parent;
while Row<>nil do begin
Result:=Row.Name+'.'+Result;
Row:=Row.Parent;
end;
end;
function TOICustomPropertyGrid.RealDefaultItemHeight: integer;
begin
Result := FDefaultItemHeight;
if (Result<=0) then
Result := Scale96ToForm(22);
end;
function TOICustomPropertyGrid.GetRowByPath(const PropPath: string): TOIPropertyGridRow;
// searches PropPath. Expands automatically parent rows
var CurName:string;
s,e:integer;
CurParentRow:TOIPropertyGridRow;
begin
Result:=nil;
if (PropPath='') or (FRows.Count=0) then exit;
CurParentRow:=nil;
s:=1;
while (s<=length(PropPath)) do begin
e:=s;
while (e<=length(PropPath)) and (PropPath[e]<>'.') do inc(e);
CurName:=uppercase(copy(PropPath,s,e-s));
s:=e+1;
// search name in children
if CurParentRow=nil then
Result:=Rows[0]
else
Result:=CurParentRow.FirstChild;
while (Result<>nil) and (uppercase(Result.Name)<>CurName) do
Result:=Result.NextBrother;
if Result=nil then begin
exit;
end else begin
// expand row
CurParentRow:=Result;
if s<=length(PropPath) then
ExpandRow(CurParentRow.Index);
end;
end;
if s<=length(PropPath) then Result:=nil;
end;
procedure TOICustomPropertyGrid.SetRowValue(CheckFocus, ForceValue: boolean);
function GetPropValue(Editor: TPropertyEditor; Index: integer): string;
var
PropKind: TTypeKind;
PropInfo: PPropInfo;
BoolVal: Boolean;
begin
Result:='';
PropInfo := Editor.GetPropInfo;
PropKind := PropInfo^.PropType^.Kind;
case PropKind of
tkInteger, tkInt64:
Result := IntToStr(Editor.GetInt64ValueAt(Index));
tkChar, tkWChar, tkUChar:
Result := Char(Editor.GetOrdValueAt(Index));
tkEnumeration:
Result := GetEnumName(PropInfo^.PropType, Editor.GetOrdValueAt(Index));
tkFloat:
Result := FloatToStr(Editor.GetFloatValueAt(Index));
tkBool: begin
BoolVal := Boolean(Editor.GetOrdValueAt(Index));
if FCheckboxForBoolean then
Result := BoolToStr(BoolVal, '(True)', '(False)')
else
Result := BoolToStr(BoolVal, 'True', 'False');
end;
tkString, tkLString, tkAString, tkUString, tkWString:
Result := Editor.GetStrValueAt(Index);
tkSet:
Result := Editor.GetSetValueAt(Index,true);
tkVariant:
if Editor.GetVarValueAt(Index) <> Null then
Result := Editor.GetVarValueAt(Index)
else
Result := '(Null)';
end;
end;
var
CurRow: TOIPropertyGridRow;
NewValue: string;
OldExpanded: boolean;
OldChangeStep: integer;
RootDesigner: TIDesigner;
APersistent: TPersistent;
i: integer;
NewVal: string;
oldVal: array of string;
isExcept: boolean;
CompEditDsg: TComponentEditorDesigner;
prpInfo: PPropInfo;
Editor: TPropertyEditor;
begin
//if FItemIndex > -1 then
// debugln(['TOICustomPropertyGrid.SetRowValue A, FItemIndex=',dbgs(FItemIndex),
// ', CanEditRowValue=', CanEditRowValue(CheckFocus), ', IsReadOnly=', Rows[FItemIndex].IsReadOnly]);
if not CanEditRowValue(CheckFocus) or Rows[FItemIndex].IsReadOnly then exit;
NewValue:=GetCurrentEditValue;
CurRow:=Rows[FItemIndex];
if length(NewValue)>CurRow.Editor.GetEditLimit then
NewValue:=LeftStr(NewValue,CurRow.Editor.GetEditLimit);
//DebugLn(['TOICustomPropertyGrid.SetRowValue Old="',CurRow.Editor.GetVisualValue,'" New="',NewValue,'"']);
if (CurRow.Editor.GetVisualValue=NewValue) and not ForceValue then exit;
RootDesigner := FindRootDesigner(FCurrentEditorLookupRoot);
if (RootDesigner is TComponentEditorDesigner) then begin
CompEditDsg := TComponentEditorDesigner(RootDesigner);
if CompEditDsg.IsUndoLocked then Exit;
end else
CompEditDsg := nil;
// store old values for undo
isExcept := false;
Editor:=CurRow.Editor;
prpInfo := nil;
if CompEditDsg<>nil then begin
SetLength(oldVal, Editor.PropCount);
prpInfo := Editor.GetPropInfo;
if prpInfo<>nil then begin
for i := 0 to Editor.PropCount - 1 do
oldVal[i] := GetPropValue(Editor,i);
end;
end;
OldChangeStep:=fChangeStep;
Include(FStates,pgsApplyingValue);
try
{$IFNDEF DoNotCatchOIExceptions}
try
{$ENDIF}
//debugln(['TOICustomPropertyGrid.SetRowValue B ClassName=',CurRow.Editor.ClassName,' Visual="',CurRow.Editor.GetVisualValue,'" NewValue="',NewValue,'" AllEqual=',CurRow.Editor.AllEqual]);
CurRow.Editor.SetValue(NewValue);
//debugln(['TOICustomPropertyGrid.SetRowValue C ClassName=',CurRow.Editor.ClassName,' Visual="',CurRow.Editor.GetVisualValue,'" NewValue="',NewValue,'" AllEqual=',CurRow.Editor.AllEqual]);
{$IFNDEF DoNotCatchOIExceptions}
except
on E: Exception do begin
MessageDlg(oisError, E.Message, mtError, [mbOk], 0);
isExcept := true;
end;
end;
{$ENDIF}
if (OldChangeStep<>FChangeStep) then begin
// the selection has changed => CurRow does not exist any more
exit;
end;
// add Undo action
if (not isExcept) and (CompEditDsg<>nil) then
begin
for i := 0 to Editor.PropCount - 1 do
begin
APersistent := Editor.GetComponent(i);
if APersistent=nil then continue;
NewVal := GetPropValue(Editor,i);
CompEditDsg.AddUndoAction(APersistent, uopChange, i = 0,
Editor.GetName, oldVal[i], NewVal);
end;
end;
// set value in edit control
SetCurrentEditValue(Editor.GetVisualValue);
// update volatile sub properties
if (paVolatileSubProperties in Editor.GetAttributes)
and ((CurRow.Expanded) or (CurRow.ChildCount>0)) then begin
OldExpanded:=CurRow.Expanded;
ShrinkRow(FItemIndex);
if OldExpanded then
ExpandRow(FItemIndex);
end;
//debugln(['TOICustomPropertyGrid.SetRowValue D ClassName=',CurRow.Editor.ClassName,' Visual="',CurRow.Editor.GetVisualValue,'" NewValue="',NewValue,'" AllEqual=',CurRow.Editor.AllEqual]);
finally
Exclude(FStates,pgsApplyingValue);
end;
if Assigned(FPropertyEditorHook) then
FPropertyEditorHook.RefreshPropertyValues;
if Assigned(FOnModified) then
FOnModified(Self);
end;
procedure TOICustomPropertyGrid.DoCallEdit(Edit: TOIQuickEdit);
var
CurRow:TOIPropertyGridRow;
OldChangeStep: integer;
begin
//debugln(['TOICustomPropertyGrid.DoCallEdit ',dbgs(GetFocus),' ',DbgSName(FindControl(GetFocus))]);
if not CanEditRowValue(false) then exit;
OldChangeStep:=fChangeStep;
CurRow:=Rows[FItemIndex];
if paDialog in CurRow.Editor.GetAttributes then begin
{$IFnDEF DoNotCatchOIExceptions}
try
{$ENDIF}
//if FSelection.Count > 0 then
// DebugLn(['# TOICustomPropertyGrid.DoCallEdit for ', CurRow.Editor.ClassName,
// ', Edit=', Edit=oiqeEdit, ', SelectionCount=', FSelection.Count,
// ', SelectionName=', FSelection[0].GetNamePath]);
Include(FStates,pgsCallingEdit);
try
if Edit=oiqeShowValue then
CurRow.Editor.ShowValue
else if (FSelection.Count > 0) and (FSelection[0] is TComponent) then
CurRow.Editor.Edit(TComponent(FSelection[0]))
else
CurRow.Editor.Edit;
finally
Exclude(FStates,pgsCallingEdit);
end;
{$IFnDEF DoNotCatchOIExceptions}
except
on E: Exception do
MessageDlg(oisError, E.Message, mtError, [mbOk], 0);
end;
{$ENDIF}
// CurRow is now invalid, do not access CurRow
if (OldChangeStep<>FChangeStep) then begin
// the selection has changed => CurRow does not exist any more
RefreshPropertyValues;
exit;
end;
RefreshValueEdit; // update value
Invalidate; //invalidate changed subproperties
end;
end;
procedure TOICustomPropertyGrid.RefreshValueEdit;
var
CurRow: TOIPropertyGridRow;
NewValue: string;
begin
if not GridIsUpdating and IsCurrentEditorAvailable then begin
CurRow:=Rows[FItemIndex];
NewValue:=CurRow.Editor.GetVisualValue;
{$IFDEF LCLCarbon}
NewValue:=StringReplace(NewValue,LineEnding,LineFeedSymbolUTF8,[rfReplaceAll]);
{$ENDIF}
SetCurrentEditValue(NewValue);
end;
end;
procedure TOICustomPropertyGrid.ValueEditKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
ScrollToActiveItem;
HandleStandardKeys(Key,Shift);
end;
procedure TOICustomPropertyGrid.ValueEditKeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
HandleKeyUp(Key,Shift);
end;
procedure TOICustomPropertyGrid.ValueEditExit(Sender: TObject);
begin
SetRowValue(false, false);
end;
procedure TOICustomPropertyGrid.ValueEditChange(Sender: TObject);
var CurRow: TOIPropertyGridRow;
begin
if (pgsUpdatingEditControl in FStates) or not IsCurrentEditorAvailable then exit;
CurRow:=Rows[FItemIndex];
if paAutoUpdate in CurRow.Editor.GetAttributes then
SetRowValue(true, true);
end;
procedure TOICustomPropertyGrid.ValueEditMouseUp(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
if (Button=mbLeft) and (Shift=[ssCtrl,ssLeft]) then
DoCallEdit(oiqeShowValue);
end;
procedure TOICustomPropertyGrid.ValueCheckBoxKeyDown(Sender: TObject;
var Key: Word; Shift: TShiftState);
begin
ScrollToActiveItem;
HandleStandardKeys(Key,Shift);
end;
procedure TOICustomPropertyGrid.ValueCheckBoxKeyUp(Sender: TObject;
var Key: Word; Shift: TShiftState);
begin
HandleKeyUp(Key,Shift);
end;
procedure TOICustomPropertyGrid.ValueCheckBoxExit(Sender: TObject);
begin
SetRowValue(false, false);
end;
procedure TOICustomPropertyGrid.ValueCheckBoxClick(Sender: TObject);
begin
if (pgsUpdatingEditControl in FStates) or not IsCurrentEditorAvailable then exit;
ValueCheckBox.Caption:=BoolToStr(ValueCheckBox.Checked, '(True)', '(False)');
SetRowValue(true, true);
end;
procedure TOICustomPropertyGrid.ValueComboBoxExit(Sender: TObject);
begin
if pgsUpdatingEditControl in FStates then exit;
SetRowValue(false, false);
end;
procedure TOICustomPropertyGrid.ValueComboBoxKeyDown(Sender: TObject;
var Key: Word; Shift: TShiftState);
begin
ScrollToActiveItem;
HandleStandardKeys(Key,Shift);
end;
procedure TOICustomPropertyGrid.ValueComboBoxKeyUp(Sender: TObject;
var Key: Word; Shift: TShiftState);
begin
HandleKeyUp(Key,Shift);
end;
procedure TOICustomPropertyGrid.ValueComboBoxMouseUp(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
if (Button=mbLeft) then begin
if (Shift=[ssCtrl,ssLeft]) then
DoCallEdit(oiqeShowValue)
else if (FFirstClickTime<>0) and (GetTickCount <= FFirstClickTime + GetDoubleClickTime)
and (not ValueComboBox.DroppedDown) then
begin
FFirstClickTime:=0;
ToggleRow;
end;
end;
end;
procedure TOICustomPropertyGrid.ValueButtonClick(Sender: TObject);
begin
ScrollToActiveItem;
DoCallEdit;
end;
procedure TOICustomPropertyGrid.ValueComboBoxMeasureItem(Control: TWinControl;
Index: Integer; var AHeight: Integer);
var
CurRow: TOIPropertyGridRow;
begin
if (FItemIndex >= 0) and (FItemIndex < FRows.Count) then
begin
CurRow := Rows[FItemIndex];
CurRow.Editor.ListMeasureHeight('Fj', Index, ValueComboBox.Canvas, AHeight);
AHeight := Max(AHeight, ValueComboBox.ItemHeight);
end;
end;
procedure TOICustomPropertyGrid.SetCheckboxState(NewValue: string);
begin
ValueCheckBox.Caption:=NewValue;
if (NewValue='') or (NewValue=oisMixed) then
ValueCheckBox.State:=cbGrayed
else if NewValue='(True)' then
ValueCheckBox.State:=cbChecked
// Note: this condition can be removed when the right propedit is used always.
else if NewValue='(False)' then
ValueCheckBox.State:=cbUnchecked;
end;
procedure TOICustomPropertyGrid.SetItemIndex(NewIndex:integer);
var
NewRow: TOIPropertyGridRow;
NewValue: string;
EditorAttributes: TPropertyAttributes;
begin
{if pgsCallingEdit in FStates then begin
DumpStack;
debugln(['TOICustomPropertyGrid.SetItemIndex ',DbgSName(Self),' ',dbgsname(FCurrentEdit),' ',dbgs(FStates),' GridIsUpdating=',GridIsUpdating,' FItemIndex=',FItemIndex,' NewIndex=',NewIndex]);
end;}
if GridIsUpdating or (FItemIndex = NewIndex) then
exit;
// save old edit value
SetRowValue(true, false);
Include(FStates, pgsChangingItemIndex);
if (FItemIndex >= 0) and (FItemIndex < FRows.Count) then
Rows[FItemIndex].Editor.Deactivate;
if CanFocus then
SetCaptureControl(nil);
FItemIndex := NewIndex;
if FCurrentEdit <> nil then
begin
FCurrentEdit.Visible:=false;
FCurrentEdit.Enabled:=false;
FCurrentEdit:=nil;
end;
if FCurrentButton<>nil then
begin
FCurrentButton.Visible:=false;
FCurrentButton.Enabled:=false;
FCurrentButton:=nil;
end;
FCurrentEditorLookupRoot:=nil;
if (NewIndex >= 0) and (NewIndex < FRows.Count) then
begin
NewRow:=Rows[NewIndex];
ScrollToItem(NewIndex);
if CanFocus then
NewRow.Editor.Activate;
EditorAttributes:=NewRow.Editor.GetAttributes;
if paDialog in EditorAttributes then begin
FCurrentButton:=ValueButton;
FCurrentButton.Visible:=true;
//DebugLn(['TOICustomPropertyGrid.SetItemIndex FCurrentButton.BoundsRect=',dbgs(FCurrentButton.BoundsRect)]);
end;
NewValue:=NewRow.Editor.GetVisualValue;
if ((NewRow.Editor is TBoolPropertyEditor) or (NewRow.Editor is TSetElementPropertyEditor))
and FCheckboxForBoolean then
begin
FCurrentEdit:=ValueCheckBox;
ValueCheckBox.Enabled:=not NewRow.IsReadOnly;
SetCheckboxState(NewValue);
end
else if paValueList in EditorAttributes then
begin
FCurrentEdit:=ValueComboBox;
if (paCustomDrawn in EditorAttributes) and (paPickList in EditorAttributes) then
ValueComboBox.Style:=csOwnerDrawVariable
else
if paCustomDrawn in EditorAttributes then
ValueComboBox.Style:=csOwnerDrawEditableVariable
else if paPickList in EditorAttributes then
ValueComboBox.Style:=csOwnerDrawFixed
else
ValueComboBox.Style:=csOwnerDrawEditableFixed;
ValueComboBox.MaxLength:=NewRow.Editor.GetEditLimit;
ValueComboBox.Sorted:=paSortList in NewRow.Editor.GetAttributes;
ValueComboBox.Enabled:=not NewRow.IsReadOnly;
// Do not fill the items here, because it can be very slow.
// Just fill in some values and update the values before the combobox popups
ValueComboBox.Items.Text:=NewValue;
Exclude(FStates,pgsGetComboItemsCalled);
SetIdleEvent(true);
ValueComboBox.Text:=NewValue;
end
else begin
FCurrentEdit:=ValueEdit;
ValueEdit.ReadOnly:=NewRow.IsReadOnly;
ValueEdit.Enabled:=true;
ValueEdit.MaxLength:=NewRow.Editor.GetEditLimit;
ValueEdit.Text:=NewValue;
end;
AlignEditComponents;
if FCurrentEdit<>nil then
begin
if FPropertyEditorHook<>nil then
FCurrentEditorLookupRoot:=FPropertyEditorHook.LookupRoot;
if (FCurrentEdit=ValueComboBox) or (FCurrentEdit=ValueEdit) then
begin
if NewRow.Editor.AllEqual then
FCurrentEdit.Color:=clWindow
else
FCurrentEdit.Color:=FValueDifferBackgrndColor;
end;
if NewRow.Editor.ValueIsStreamed then
FCurrentEdit.Font:=FValueFont
else
FCurrentEdit.Font:=FDefaultValueFont;
FCurrentEdit.Visible:=true;
if (FDragging=false) and FCurrentEdit.Showing and FCurrentEdit.Enabled
and (not NewRow.IsReadOnly) and CanFocus and (Column=oipgcValue)
and not (pgsFocusPropertyEditorDisabled in FStates)
then
SetActiveControl(FCurrentEdit);
end;
if FCurrentButton<>nil then
FCurrentButton.Enabled:=not NewRow.IsDisabled;
end;
//DebugLn(['TOICustomPropertyGrid.SetItemIndex Vis=',ValueComboBox.Visible,' Ena=',ValueComboBox.Enabled,
// ' Items.Count=',ValueComboBox.Items.Count ,' Text=',ValueComboBox.Text]);
Exclude(FStates, pgsChangingItemIndex);
DoSelectionChange;
Invalidate;
end;
function TOICustomPropertyGrid.GetNameRowHeight: Integer;
begin
Result := Abs(FNameFont.Height);
if Result = 0 then
Result := 16;
Inc(Result, 2); // margin
end;
function TOICustomPropertyGrid.GetRowCount:integer;
begin
Result:=FRows.Count;
end;
procedure TOICustomPropertyGrid.BuildPropertyList(OnlyIfNeeded: Boolean;
FocusEditor: Boolean);
var
a: integer;
CurRow: TOIPropertyGridRow;
OldSelectedRowPath: string;
begin
if OnlyIfNeeded and (not (pgsBuildPropertyListNeeded in FStates)) then exit;
Exclude(FStates,pgsBuildPropertyListNeeded);
if not FocusEditor then Include(FStates, pgsFocusPropertyEditorDisabled);
OldSelectedRowPath:=PropertyPath(ItemIndex);
// unselect
ItemIndex:=-1;
// clear
for a:=0 to FRows.Count-1 do Rows[a].Free;
FRows.Clear;
// get properties
if FSelection.Count>0 then begin
GetPersistentProperties(FSelection, FFilter + [tkClass], FPropertyEditorHook,
@AddPropertyEditor, @EditorFilter);
end;
// sort
FRows.Sort(@SortGridRows);
for a:=0 to FRows.Count-1 do begin
if a>0 then
Rows[a].FPriorBrother:=Rows[a-1]
else
Rows[a].FPriorBrother:=nil;
if a<FRows.Count-1 then
Rows[a].FNextBrother:=Rows[a+1]
else
Rows[a].FNextBrother:=nil;
end;
// set indices and tops
SetItemsTops;
// restore expands
for a:=FExpandedProperties.Count-1 downto 0 do begin
CurRow:=GetRowByPath(FExpandedProperties[a]);
if CurRow<>nil then
ExpandRow(CurRow.Index);
end;
// update scrollbar
FTopY:=0;
UpdateScrollBar;
// reselect
CurRow:=GetRowByPath(OldSelectedRowPath);
if CurRow<>nil then
ItemIndex:=CurRow.Index;
Exclude(FStates, pgsFocusPropertyEditorDisabled);
// paint
Invalidate;
end;
procedure TOICustomPropertyGrid.AddPropertyEditor(PropEditor: TPropertyEditor);
var
NewRow: TOIPropertyGridRow;
WidgetSets: TLCLPlatforms;
begin
WidgetSets := [];
if Favorites<>nil then begin
//debugln('TOICustomPropertyGrid.AddPropertyEditor A ',PropEditor.GetName);
if Favorites is TOIRestrictedProperties then
begin
WidgetSets := (Favorites as TOIRestrictedProperties).AreRestricted(
Selection,PropEditor.GetName);
if WidgetSets = [] then
begin
PropEditor.Free;
Exit;
end;
end
else
if not Favorites.AreFavorites(Selection,PropEditor.GetName) then begin
PropEditor.Free;
exit;
end;
end;
if PropEditor is TClassPropertyEditor then
begin
(PropEditor as TClassPropertyEditor).SubPropsNameFilter := PropNameFilter;
(PropEditor as TClassPropertyEditor).SubPropsTypeFilter := FFilter;
(PropEditor as TClassPropertyEditor).HideClassName:=FHideClassNames;
end;
NewRow := TOIPropertyGridRow.Create(Self, PropEditor, nil, WidgetSets);
FRows.Add(NewRow);
if FRows.Count>1 then begin
NewRow.FPriorBrother:=Rows[FRows.Count-2];
NewRow.FPriorBrother.FNextBrother:=NewRow;
end;
end;
procedure TOICustomPropertyGrid.AddStringToComboBox(const s: string);
begin
if FNewComboBoxItems=nil then
FNewComboBoxItems:=TStringList.Create;
FNewComboBoxItems.Add(s);
end;
procedure TOICustomPropertyGrid.ExpandRow(Index:integer);
var
a: integer;
CurPath: string;
AlreadyInExpandList: boolean;
ActiveRow: TOIPropertyGridRow;
begin
// Save ItemIndex
if ItemIndex <> -1 then
ActiveRow := Rows[ItemIndex]
else
ActiveRow := nil;
FExpandingRow := Rows[Index];
if (FExpandingRow.Expanded) or (not CanExpandRow(FExpandingRow)) then
begin
FExpandingRow := nil;
Exit;
end;
FExpandingRow.Editor.GetProperties(@AddSubEditor);
SortSubEditors(FExpandingRow);
SetItemsTops;
FExpandingRow.FExpanded := True;
a := 0;
CurPath:=uppercase(PropertyPath(FExpandingRow.Index));
AlreadyInExpandList:=false;
while a < FExpandedProperties.Count do
begin
if FExpandedProperties[a]=copy(CurPath,1,length(FExpandedProperties[a])) then
begin
if Length(FExpandedProperties[a]) = Length(CurPath) then
begin
AlreadyInExpandList := True;
inc(a);
end
else
FExpandedProperties.Delete(a);
end
else
inc(a);
end;
if not AlreadyInExpandList then
FExpandedProperties.Add(CurPath);
FExpandingRow := nil;
// restore ItemIndex
if ActiveRow <> nil then
FItemIndex := ActiveRow.Index
else
FItemIndex := -1;
UpdateScrollBar;
Invalidate;
end;
procedure TOICustomPropertyGrid.ShrinkRow(Index:integer);
var
CurRow, ARow: TOIPropertyGridRow;
StartIndex, EndIndex, a: integer;
CurPath: string;
begin
CurRow := Rows[Index];
if (not CurRow.Expanded) then
Exit;
// calculate all children (between StartIndex..EndIndex)
StartIndex := CurRow.Index + 1;
EndIndex := FRows.Count - 1;
ARow := CurRow;
while ARow <> nil do
begin
if ARow.NextBrother <> nil then
begin
EndIndex := ARow.NextBrother.Index - 1;
break;
end;
ARow := ARow.Parent;
end;
if (FItemIndex >= StartIndex) and (FItemIndex <= EndIndex) then
// current row delete, set new current row
ItemIndex:=0
else
if FItemIndex > EndIndex then
// adjust current index for deleted rows
FItemIndex := FItemIndex - (EndIndex - StartIndex + 1);
for a := EndIndex downto StartIndex do
begin
Rows[a].Free;
FRows.Delete(a);
end;
SetItemsTops;
CurRow.FExpanded := False;
CurPath := UpperCase(PropertyPath(CurRow.Index));
a := 0;
while a < FExpandedProperties.Count do
begin
if copy(FExpandedProperties[a], 1, length(CurPath)) = CurPath then
FExpandedProperties.Delete(a)
else
inc(a);
end;
if CurRow.Parent <> nil then
FExpandedProperties.Add(UpperCase(PropertyPath(CurRow.Parent.Index)));
UpdateScrollBar;
Invalidate;
end;
procedure TOICustomPropertyGrid.AddSubEditor(PropEditor:TPropertyEditor);
var NewRow:TOIPropertyGridRow;
NewIndex:integer;
begin
if not EditorFilter(PropEditor) then
begin
// if some elements of a set is not being shown then free their editor
// to avoid memory leaks; sine only visible editors will be cleared.
if PropEditor.ClassType = TSetElementPropertyEditor then
PropEditor.Free;
Exit;
end;
if PropEditor is TClassPropertyEditor then
begin
(PropEditor as TClassPropertyEditor).SubPropsNameFilter := PropNameFilter;
(PropEditor as TClassPropertyEditor).SubPropsTypeFilter := FFilter;
(PropEditor as TClassPropertyEditor).HideClassName:=FHideClassNames;
end;
NewRow:=TOIPropertyGridRow.Create(Self,PropEditor,FExpandingRow, []);
NewIndex:=FExpandingRow.Index+1+FExpandingRow.ChildCount;
NewRow.FIndex:=NewIndex;
FRows.Insert(NewIndex,NewRow);
if NewIndex<FItemIndex
then inc(FItemIndex);
if FExpandingRow.FFirstChild=nil then
FExpandingRow.FFirstChild:=NewRow;
NewRow.FPriorBrother:=FExpandingRow.FLastChild;
FExpandingRow.FLastChild:=NewRow;
if NewRow.FPriorBrother<>nil then
NewRow.FPriorBrother.FNextBrother:=NewRow;
inc(FExpandingRow.FChildCount);
end;
procedure TOICustomPropertyGrid.SortSubEditors(ParentRow: TOIPropertyGridRow);
var
Item: TOIPropertyGridRow;
Index: Integer;
Next: TOIPropertyGridRow;
begin
if not ParentRow.Sort(@SortGridRows) then exit;
// update FRows
Item:=ParentRow.FirstChild;
Index:=ParentRow.Index+1;
Next:=ParentRow.NextSkipChilds;
while (Item<>nil) and (Item<>Next) do begin
FRows[Index]:=Item;
Item.FIndex:=Index;
Item:=Item.Next;
inc(Index);
end;
end;
function TOICustomPropertyGrid.CanExpandRow(Row: TOIPropertyGridRow): boolean;
var
AnObject: TPersistent;
ParentRow: TOIPropertyGridRow;
begin
Result:=false;
if (Row=nil) or (Row.Editor=nil) then exit;
if (not (paSubProperties in Row.Editor.GetAttributes)) then exit;
// check if circling
if (Row.Editor is TPersistentPropertyEditor) then begin
if (Row.Editor is TInterfacePropertyEditor) then
AnObject:={%H-}TPersistent(Row.Editor.GetIntfValue)
else
AnObject:=TPersistent(Row.Editor.GetObjectValue);
if FSelection.IndexOf(AnObject)>=0 then exit;
ParentRow:=Row.Parent;
while ParentRow<>nil do begin
if (ParentRow.Editor is TPersistentPropertyEditor)
and (ParentRow.Editor.GetObjectValue=AnObject) then
exit;
ParentRow:=ParentRow.Parent;
end;
end;
Result:=true;
end;
function TOICustomPropertyGrid.MouseToIndex(y: integer; MustExist: boolean
): integer;
var l,r,m:integer;
begin
l:=0;
r:=FRows.Count-1;
inc(y,FTopY);
while (l<=r) do begin
m:=(l+r) shr 1;
if Rows[m].Top>y then begin
r:=m-1;
end else if Rows[m].Bottom<=y then begin
l:=m+1;
end else begin
Result:=m; exit;
end;
end;
if (MustExist=false) and (FRows.Count>0) then begin
if y<0 then Result:=0
else Result:=FRows.Count-1;
end else Result:=-1;
end;
function TOICustomPropertyGrid.GetActiveRow: TOIPropertyGridRow;
begin
if InRange(ItemIndex,0,FRows.Count-1) then
Result:=Rows[ItemIndex]
else
Result:=nil;
end;
procedure TOICustomPropertyGrid.SetCurrentRowValue(const NewValue: string);
begin
if not CanEditRowValue(false) or Rows[FItemIndex].IsReadOnly then exit;
// SetRowValue reads the value from the current edit control and writes it
// to the property editor
// -> set the text in the current edit control without changing FLastEditValue
SetCurrentEditValue(NewValue);
SetRowValue(false, true);
end;
procedure TOICustomPropertyGrid.SetItemIndexAndFocus(NewItemIndex: integer;
WasValueClick: Boolean);
begin
if not InRange(NewItemIndex, 0, FRows.Count - 1) then exit;
ItemIndex:=NewItemIndex;
if FCurrentEdit<>nil then
begin
SetActiveControl(FCurrentEdit);
if (FCurrentEdit is TCustomEdit) then
TCustomEdit(FCurrentEdit).SelectAll
{$IFnDEF UseOINormalCheckBox}
else if (FCurrentEdit is TCheckBoxThemed) and WasValueClick then
TCheckBoxThemed(FCurrentEdit).Checked:=not TCheckBoxThemed(FCurrentEdit).Checked;
{$ELSE}
else if (FCurrentEdit is TCheckBox) and WasValueClick then
TCheckBox(FCurrentEdit).Checked:=not TCheckBox(FCurrentEdit).Checked;
{$ENDIF}
end;
end;
function TOICustomPropertyGrid.CanEditRowValue(CheckFocus: boolean): boolean;
var
FocusedControl: TWinControl;
begin
Result:=
not GridIsUpdating and IsCurrentEditorAvailable
and (not (pgsCallingEdit in FStates))
and ((FCurrentEditorLookupRoot = nil)
or (FPropertyEditorHook = nil)
or (FPropertyEditorHook.LookupRoot = FCurrentEditorLookupRoot));
if Result and CheckFocus then begin
FocusedControl:=FindOwnerControl(GetFocus);
if (FocusedControl<>nil) and (FocusedControl<>Self)
and (not IsParentOf(FocusedControl)) then
Result:=false;
end;
if Result then begin
{DebugLn(['TOICustomPropertyGrid.CanEditRowValue',
' pgsChangingItemIndex=',pgsChangingItemIndex in FStates,
' pgsApplyingValue=',pgsApplyingValue in FStates,
' pgsUpdatingEditControl=',pgsUpdatingEditControl in FStates,
' FCurrentEdit=',dbgsName(FCurrentEdit),
' FItemIndex=',FItemIndex,
' FCurrentEditorLookupRoot=',dbgsName(FCurrentEditorLookupRoot),
' FPropertyEditorHook.LookupRoot=',dbgsName(FPropertyEditorHook.LookupRoot)
]);}
end;
end;
procedure TOICustomPropertyGrid.SaveChanges;
begin
SetRowValue(true, false);
end;
function TOICustomPropertyGrid.GetHintTypeAt(RowIndex: integer; X: integer): TPropEditHint;
var
IconX: integer;
begin
Result := pehNone;
if (RowIndex < 0) or (RowIndex >= RowCount) then
Exit;
if SplitterX <= X then
begin
if (FCurrentButton <> nil) and (FCurrentButton.Left <= X) then
Result := pehEditButton
else
Result := pehValue;
end else
begin
IconX := GetTreeIconX(RowIndex);
if IconX + Indent > X then
Result := pehTree
else
Result := pehName;
end;
end;
procedure TOICustomPropertyGrid.MouseDown(Button:TMouseButton; Shift:TShiftState;
X,Y:integer);
var
IconX,Index:integer;
PointedRow:TOIpropertyGridRow;
Details: TThemedElementDetails;
Sz: TSize;
begin
//ShowMessageDialog('X'+IntToStr(X)+',Y'+IntToStr(Y));
inherited MouseDown(Button,Shift,X,Y);
HideHint;
if Button=mbLeft then begin
FFirstClickTime:=GetTickCount;
if Cursor=crHSplit then begin
FDragging:=true;
end
else
begin
Index:=MouseToIndex(Y,false);
if (Index>=0) and (Index<FRows.Count) then
begin
PointedRow:=Rows[Index];
if CanExpandRow(PointedRow) then
begin
IconX:=GetTreeIconX(Index);
if ((X>=IconX) and (X<=IconX+FIndent)) or (ssDouble in Shift) then
begin
if PointedRow.Expanded then
ShrinkRow(Index)
else
ExpandRow(Index);
end;
end;
// WasValueClick param is only for Boolean checkboxes, toggled if user
// clicks the square. It has no effect for Boolean ComboBox editor.
Details := ThemeServices.GetElementDetails(tbCheckBoxCheckedNormal);
Sz := ThemeServices.GetDetailSize(Details);
SetItemIndexAndFocus(Index, (X>SplitterX) and (X<=SplitterX+Sz.cx));
SetCaptureControl(Self);
Column := oipgcValue;
end;
end;
end;
end;
procedure TOICustomPropertyGrid.MouseLeave;
begin
if Assigned(FHintManager) and Assigned(FHintManager.CurHintWindow)
and FHintManager.CurHintWindow.Visible
and not PtInRect(ClientRect, ScreenToClient(Mouse.CursorPos)) then
FHintManager.HideHint;
inherited MouseLeave;
end;
procedure TOICustomPropertyGrid.MouseMove(Shift:TShiftState; X,Y:integer);
var
TheHint: String;
HintType: TPropEditHint;
fPropRow: TOIPropertyGridRow;
procedure DoShow(pt: TPoint); inline;
var
HintFont: TFont;
begin
if WidgetSet.GetLCLCapability(lcTransparentWindow)=LCL_CAPABILITY_NO then
Inc(pt.Y, fPropRow.Height);
if HintType<>pehValue then
HintFont := Screen.HintFont
else
if fPropRow.Editor.ValueIsStreamed then
HintFont:=FValueFont
else
HintFont:=FDefaultValueFont;
FHintManager.ShowHint(ClientToScreen(pt), TheHint, False, HintFont);
if FHintManager.CurHintWindow<>nil then
FHintManager.CurHintWindow.OnMouseLeave := @HintMouseLeave;
end;
var
SplitDistance:integer;
Index, TextLeft: Integer;
begin
inherited MouseMove(Shift,X,Y);
SplitDistance:=X-SplitterX;
if FDragging then begin
HideHint;
if ssLeft in Shift then begin
SplitterX:=SplitterX+SplitDistance;
end else begin
EndDragSplitter;
end;
end
else begin
if (abs(SplitDistance)<=2) then begin
Cursor:=crHSplit;
end else begin
Cursor:=crDefault;
end;
if ssLeft in Shift then
begin
Index := MouseToIndex(Y, False);
SetItemIndexAndFocus(Index);
SetCaptureControl(Self);
end;
// to check if the property text fits in its box, if not show a hint
if not (ShowHint and InitHints) then Exit;
Index := MouseToIndex(y,false);
HintType := GetHintTypeAt(Index, x);
if (Index<>FHintIndex) or (HintType<>FHintType) then
HideHint;
ResetLongHintTimer;
if (Index = -1) or FShowingLongHint
or ( FHintManager.HintIsVisible and (Index = FHintIndex) and (HintType=FHintType) ) then
Exit;
FHintIndex:=Index;
FHintType := HintType;
fPropRow := GetRow(Index);
if HintType = pehName then
begin
// Mouse is over property name...
TheHint := fPropRow.Name;
TextLeft := BorderWidth + GetTreeIconX(Index) + Indent + 5;
if (Canvas.TextWidth(TheHint) + TextLeft) >= SplitterX-2 then
DoShow(Point(TextLeft - 3, fPropRow.Top-TopY-1));
end else
if HintType in [pehValue,pehEditButton] then
begin
// Mouse is over property value...
TheHint := fPropRow.LastPaintedValue;
if length(TheHint) > 100 then
TheHint := copy(TheHint, 1, 100) + '...';
TextLeft := SplitterX+2;
if Canvas.TextWidth(TheHint) > (ClientWidth - BorderWidth - TextLeft) then
DoShow(Point(TextLeft - 3, fPropRow.Top-TopY-1));
end;
end;
end;
procedure TOICustomPropertyGrid.MouseUp(Button:TMouseButton; Shift:TShiftState;
X,Y:integer);
begin
if FDragging then EndDragSplitter;
SetCaptureControl(nil);
inherited MouseUp(Button,Shift,X,Y);
end;
procedure TOICustomPropertyGrid.KeyDown(var Key: Word; Shift: TShiftState);
begin
HandleStandardKeys(Key,Shift);
inherited KeyDown(Key, Shift);
end;
procedure TOICustomPropertyGrid.HandleStandardKeys(var Key: Word; Shift: TShiftState);
var
Handled: Boolean;
procedure FindPropertyBySearchText;
var
i, IIndex: Integer;
begin
if Column = oipgcName then
begin
FKeySearchText := FKeySearchText + UpCase(Chr(Key));
if ItemIndex = -1 then
IIndex := 0
else
IIndex := ItemIndex;
for i := 0 to RowCount - 1 do
if (Rows[i].Lvl = Rows[IIndex].Lvl) and
(UpperCase(LeftStr(Rows[i].Name, Length(FKeySearchText))) = FKeySearchText) then
begin
// Set item index. To go to Value user must hit either Tab or Enter.
SetItemIndex(i);
exit;
end;
// Left part of phrase not matched, remove added char.
SetLength(FKeySearchText, Length(FKeySearchText) - 1);
end;
Handled := false;
end;
procedure HandleUnshifted;
const
Page = 20;
begin
Handled := true;
case Key of
VK_UP : SetItemIndexAndFocus(ItemIndex - 1);
VK_DOWN : SetItemIndexAndFocus(ItemIndex + 1);
VK_PRIOR: SetItemIndexAndFocus(Max(ItemIndex - Page, 0));
VK_NEXT : SetItemIndexAndFocus(Min(ItemIndex + Page, FRows.Count - 1));
VK_TAB: DoTabKey;
VK_RETURN:
begin
if Column = oipgcName then
DoTabKey
else
SetRowValue(false, true);
if FCurrentEdit is TCustomEdit then
TCustomEdit(FCurrentEdit).SelectAll;
end;
VK_ESCAPE:
begin
RefreshValueEdit;
FKeySearchText := '';
end;
VK_BACK:
begin
if (Column = oipgcName) then
if (FKeySearchText <> '') then
SetLength(FKeySearchText, Length(FKeySearchText) - 1);
Handled := False;
end;
Ord('A')..Ord('Z'): FindPropertyBySearchText;
else
Handled := false;
end;
end;
begin
//writeln('TOICustomPropertyGrid.HandleStandardKeys ',Key);
Handled := false;
if (Shift = []) or (Shift = [ssShift]) then
begin
if not (FCurrentEdit is TCustomCombobox) or
not TCustomCombobox(FCurrentEdit).DroppedDown then
HandleUnshifted;
end
else
if Shift = [ssCtrl] then
begin
case Key of
VK_RETURN:
begin
ToggleRow;
Handled := true;
end;
end;
end
else
if Shift = [ssAlt] then
case Key of
VK_LEFT:
begin
Handled := (ItemIndex >= 0) and Rows[ItemIndex].Expanded;
if Handled then ShrinkRow(ItemIndex);
end;
VK_RIGHT:
begin
Handled := (ItemIndex >= 0) and not Rows[ItemIndex].Expanded and
CanExpandRow(Rows[ItemIndex]);
if Handled then ExpandRow(ItemIndex)
end;
end;
if not Handled and Assigned(OnOIKeyDown) then
begin
OnOIKeyDown(Self, Key, Shift);
Handled := Key = VK_UNKNOWN;
end;
//writeln('TOICustomPropertyGrid.HandleStandardKeys ',Key,' Handled=',Handled);
if Handled then
Key := VK_UNKNOWN;
end;
procedure TOICustomPropertyGrid.HandleKeyUp(var Key: Word; Shift: TShiftState);
begin
if (Key<>VK_UNKNOWN) and Assigned(OnKeyUp) then OnKeyUp(Self,Key,Shift);
end;
procedure TOICustomPropertyGrid.DoTabKey;
begin
if Column = oipgcValue then
begin
Column := oipgcName;
Self.SetFocus;
end else
begin
Column := oipgcValue;
if FCurrentEdit <> nil then
FCurrentEdit.SetFocus;
end;
FKeySearchText := '';
end;
function TOICustomPropertyGrid.EditorFilter(const AEditor: TPropertyEditor): Boolean;
begin
Result := IsInteresting(AEditor, FFilter, PropNameFilter);
if Result and Assigned(OnEditorFilter) then
OnEditorFilter(Self,AEditor,Result);
end;
procedure TOICustomPropertyGrid.EraseBackground(DC: HDC);
begin
// everything is painted, so erasing the background is not needed
end;
procedure TOICustomPropertyGrid.DoSetBounds(ALeft, ATop, AWidth, AHeight: integer);
begin
inherited DoSetBounds(ALeft, ATop, AWidth, AHeight);
UpdateScrollBar;
end;
procedure TOICustomPropertyGrid.DoSelectionChange;
begin
if Assigned(FOnSelectionChange) then
FOnSelectionChange(Self);
end;
procedure TOICustomPropertyGrid.HintMouseDown(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var
pos: TPoint;
begin
if FHintManager.HintIsVisible then begin
pos := ScreenToClient(FHintManager.CurHintWindow.ClientToScreen(Point(X, Y)));
MouseDown(Button, Shift, pos.X, pos.Y);
end;
end;
procedure TOICustomPropertyGrid.HintMouseLeave(Sender: TObject);
begin
if FindLCLControl(Mouse.CursorPos)<>Self then
FHintManager.HideHint;
end;
procedure TOICustomPropertyGrid.EndDragSplitter;
begin
if FDragging then begin
Cursor:=crDefault;
FDragging:=false;
FPreferredSplitterX:=FSplitterX;
if FCurrentEdit<>nil then begin
SetCaptureControl(nil);
if Column=oipgcValue then
FCurrentEdit.SetFocus
else
Self.SetFocus;
end;
end;
end;
procedure TOICustomPropertyGrid.SetReadOnlyColor(const AValue: TColor);
begin
if FReadOnlyColor = AValue then Exit;
FReadOnlyColor := AValue;
Invalidate;
end;
procedure TOICustomPropertyGrid.SetRowSpacing(const AValue: integer);
begin
if FRowSpacing = AValue then exit;
FRowSpacing := AValue;
SetItemsTops;
end;
procedure TOICustomPropertyGrid.SetShowGutter(const AValue: Boolean);
begin
if FShowGutter=AValue then exit;
FShowGutter:=AValue;
invalidate;
end;
procedure TOICustomPropertyGrid.SetSplitterX(const NewValue:integer);
var AdjustedValue:integer;
begin
AdjustedValue:=NewValue;
if AdjustedValue>ClientWidth then AdjustedValue:=ClientWidth;
if AdjustedValue<1 then AdjustedValue:=1;
if FSplitterX<>AdjustedValue then begin
FSplitterX:=AdjustedValue;
AlignEditComponents;
Invalidate;
end;
end;
procedure TOICustomPropertyGrid.SetTopY(const NewValue:integer);
var
NewTopY: integer;
{$IFDEF WINDOWS}
r: Types.TRect;
{$ENDIF}
begin
NewTopY := TopMax;
if NewValue < NewTopY then
NewTopY := NewValue;
if NewTopY < 0 then
NewTopY := 0;
if FTopY<>NewTopY then begin
{$IFDEF WINDOWS}
r := ClientRect;
if not ScrollWindowEx(Handle,0,FTopY-NewTopY,@r,@r,0,nil, SW_INVALIDATE+SW_SCROLLCHILDREN) then
{$ENDIF}
Invalidate;
FTopY:=NewTopY;
UpdateScrollBar;
AlignEditComponents;
end;
end;
function TOICustomPropertyGrid.GetPropNameColor(ARow:TOIPropertyGridRow):TColor;
function HasWriter(APropInfo: PPropInfo): Boolean; inline;
begin
Result := Assigned(APropInfo) and Assigned(APropInfo^.SetProc);
end;
var
ParentRow:TOIPropertyGridRow;
IsObjectSubProperty:Boolean;
begin
// Try to guest if ARow, or one of its parents, is a subproperty
// of an object (and not an item of a set)
IsObjectSubProperty:=false;
ParentRow:=ARow.Parent;
while Assigned(ParentRow) do
begin
if ParentRow.Editor is TPersistentPropertyEditor then
IsObjectSubProperty:=true;
ParentRow:=ParentRow.Parent;
end;
if (ItemIndex <> -1) and (ItemIndex = ARow.Index) then
Result := FHighlightFont.Color
else
if not HasWriter(ARow.Editor.GetPropInfo) then
Result := FReadOnlyColor
else
if ARow.Editor is TPersistentPropertyEditor then
Result := FReferencesColor
else
if IsObjectSubProperty then
Result := FSubPropertiesColor
else
Result := FNameFont.Color;
end;
procedure TOICustomPropertyGrid.SetBounds(aLeft,aTop,aWidth,aHeight:integer);
begin
//writeln('[TOICustomPropertyGrid.SetBounds] ',Name,' ',aLeft,',',aTop,',',aWidth,',',aHeight,' Visible=',Visible);
inherited SetBounds(aLeft,aTop,aWidth,aHeight);
if Visible then begin
if not FDragging then begin
if (SplitterX<5) and (aWidth>20) then
SplitterX:=100
else
SplitterX:=FPreferredSplitterX;
end;
AlignEditComponents;
end;
end;
function TOICustomPropertyGrid.GetTreeIconX(Index:integer):integer;
begin
Result:=Rows[Index].Lvl*Indent+2;
end;
function TOICustomPropertyGrid.TopMax:integer;
begin
Result:=GridHeight-ClientHeight+2*integer(BorderWidth);
if Result<0 then Result:=0;
end;
function TOICustomPropertyGrid.GridHeight:integer;
begin
if FRows.Count>0 then
Result:=Rows[FRows.Count-1].Bottom
else
Result:=0;
end;
procedure TOICustomPropertyGrid.AlignEditComponents;
var
RRect, EditCompRect, EditBtnRect: TRect;
begin
if ItemIndex>=0 then
begin
RRect := RowRect(ItemIndex);
{.$ifdef LCLGtk2}
InflateRect(RRect, 0, 1);
{.$endif}
EditCompRect := RRect;
if Layout = oilHorizontal then
EditCompRect.Left := RRect.Left + SplitterX
else begin
EditCompRect.Top := RRect.Top + GetNameRowHeight;
EditCompRect.Left := RRect.Left + GetTreeIconX(ItemIndex) + Indent;
end;
if FCurrentButton<>nil then
begin
// edit dialog button
with EditBtnRect do begin
Top := EditCompRect.Top;
Left := EditCompRect.Right - Scale96ToForm(20);
Bottom := EditCompRect.Bottom - 1;
Right := EditCompRect.Right;
EditCompRect.Right := Left;
end;
if FCurrentButton.BoundsRect <> EditBtnRect then
FCurrentButton.BoundsRect := EditBtnRect;
//DebugLn(['TOICustomPropertyGrid.AlignEditComponents FCurrentButton.BoundsRect=',dbgs(FCurrentButton.BoundsRect),' EditBtnRect=',dbgs(EditBtnRect)]);
end;
if FCurrentEdit<>nil then
begin
// resize the edit component
if (FCurrentEdit is TEdit) or (FCurrentEdit is TComboBox) then
begin
Dec(EditCompRect.Top);
{$IFDEF UseOINormalCheckBox}
end
else if FCurrentEdit is TCheckBox then
begin
with EditCompRect do // Align "normal" CheckBox to the middle vertically
Inc(Top, (Bottom - Top - ValueCheckBox.Height) div 2);
{$ELSE}
end
else if FCurrentEdit is TCheckBoxThemed then
begin // Move right as much as in TPropertyEditor.DrawCheckValue.
Inc(EditCompRect.Left, CheckBoxThemedLeftOffs);
{$ENDIF}
end;
//debugln('TOICustomPropertyGrid.AlignEditComponents A ',dbgsName(FCurrentEdit),' ',dbgs(EditCompRect));
if FCurrentEdit.BoundsRect <> EditCompRect then
FCurrentEdit.BoundsRect := EditCompRect;
end;
end;
end;
procedure TOICustomPropertyGrid.PaintRow(ARow: integer);
var
FullRect, NameRect, NameTextRect, NameIconRect, ValueRect: TRect;
CurRow: TOIPropertyGridRow;
procedure ClearBackground;
var
DrawValuesDiffer: Boolean;
begin
DrawValuesDiffer := (FValueDifferBackgrndColor<>clNone) and not CurRow.Editor.AllEqual;
if FBackgroundColor <> clNone then
begin
Canvas.Brush.Color := FBackgroundColor;
if DrawValuesDiffer then
Canvas.FillRect(NameRect)
else
Canvas.FillRect(FullRect);
end;
if DrawValuesDiffer then
begin
// Make the background color darker than what the active edit control has.
Canvas.Brush.Color := FValueDifferBackgrndColor - $282828;
Canvas.FillRect(ValueRect);
end;
if ShowGutter and (Layout = oilHorizontal) and
(FGutterColor <> FBackgroundColor) and (FGutterColor <> clNone) then
begin
Canvas.Brush.Color := FGutterColor;
Canvas.FillRect(NameIconRect);
end;
end;
procedure DrawIcon(IconX: integer);
var
Details: TThemedElementDetails;
sz: TSize;
IconY: integer;
Res: TScaledImageListResolution;
begin
if CurRow.Expanded then
Details := ThemeServices.GetElementDetails(ttGlyphOpened)
else
Details := ThemeServices.GetElementDetails(ttGlyphClosed);
if CanExpandRow(CurRow) then
begin
sz := ThemeServices.GetDetailSize(Details);
IconY:=((NameRect.Bottom - NameRect.Top - sz.cy) div 2) + NameRect.Top;
ThemeServices.DrawElement(Canvas.Handle, Details,
Rect(IconX, IconY, IconX + sz.cx, IconY + sz.cy), nil)
end else
if (ARow = FItemIndex) then
begin
Res := FActiveRowImages.ResolutionForControl[0, Self];
IconY:=((NameRect.Bottom - NameRect.Top - Res.Height) div 2) + NameRect.Top;
Res.Draw(Canvas, IconX, IconY, FActiveRowImages.GetImageIndex('pg_active_row'));
end;
end;
procedure DrawName(DrawState: TPropEditDrawState);
var
OldFont: TFont;
NameBgColor: TColor;
begin
if (ARow = FItemIndex) and (FHighlightColor <> clNone) then
NameBgColor := FHighlightColor
else
NameBgColor := FBackgroundColor;
OldFont:=Canvas.Font;
Canvas.Font:=FNameFont;
Canvas.Font.Color := GetPropNameColor(CurRow);
// set bg color to highlight if needed
if (NameBgColor <> FBackgroundColor) and (NameBgColor <> clNone) then
begin
Canvas.Brush.Color := NameBgColor;
Canvas.FillRect(NameTextRect);
end;
CurRow.Editor.PropDrawName(Canvas, NameTextRect, DrawState);
Canvas.Font := OldFont;
if FBackgroundColor <> clNone then // return color back to background
Canvas.Brush.Color := FBackgroundColor;
end;
procedure DrawWidgetsets;
var
OldFont: TFont;
X, Y: Integer;
lclPlatform: TLCLPlatform;
ImagesRes: TScaledImageListResolution;
begin
ImagesRes := IDEImages.Images_16.ResolutionForPPI[0, Font.PixelsPerInch, GetCanvasScaleFactor];
X := NameRect.Right - 2;
Y := (NameRect.Top + NameRect.Bottom - ImagesRes.Height) div 2;
OldFont:=Canvas.Font;
Canvas.Font:=FNameFont;
Canvas.Font.Color := clRed;
for lclPlatform := High(TLCLPlatform) downto Low(TLCLPlatform) do
begin
if lclPlatform in CurRow.FWidgetSets then
begin
Dec(X, ImagesRes.Width);
ImagesRes.Draw(Canvas, X, Y,
IDEImages.LoadImage('issue_'+LCLPlatformDirNames[lclPlatform]));
end;
end;
Canvas.Font:=OldFont;
end;
procedure DrawValue(DrawState: TPropEditDrawState);
var
OldFont: TFont;
begin
if ARow<>ItemIndex then
begin
OldFont:=Canvas.Font;
if CurRow.Editor.ValueIsStreamed then
Canvas.Font:=FValueFont
else
Canvas.Font:=FDefaultValueFont;
CurRow.Editor.PropDrawValue(Canvas,ValueRect,DrawState);
Canvas.Font:=OldFont;
end;
CurRow.LastPaintedValue:=CurRow.Editor.GetVisualValue;
end;
procedure DrawGutterToParent;
var
ParentRect: TRect;
X: Integer;
begin
if ARow > 0 then
begin
ParentRect := RowRect(ARow - 1);
X := ParentRect.Left + GetTreeIconX(ARow - 1) + Indent + 3;
if X <> NameIconRect.Right then
begin
Canvas.MoveTo(NameIconRect.Right, NameRect.Top - 1 - FRowSpacing);
Canvas.LineTo(X - 1, NameRect.Top - 1 - FRowSpacing);
end;
end;
// to parent next sibling
if ARow < FRows.Count - 1 then
begin
ParentRect := RowRect(ARow + 1);
X := ParentRect.Left + GetTreeIconX(ARow + 1) + Indent + 3;
if X <> NameIconRect.Right then
begin
Canvas.MoveTo(NameIconRect.Right, NameRect.Bottom - 1);
Canvas.LineTo(X - 1, NameRect.Bottom - 1);
end;
end;
end;
var
IconX: integer;
DrawState: TPropEditDrawState;
begin
CurRow := Rows[ARow];
FullRect := RowRect(ARow);
NameRect := FullRect;
ValueRect := FullRect;
Inc(FullRect.Bottom, FRowSpacing);
if Layout = oilHorizontal then
begin
NameRect.Right:=SplitterX;
ValueRect.Left:=SplitterX;
end
else begin
NameRect.Bottom := NameRect.Top + GetNameRowHeight;
ValueRect.Top := NameRect.Bottom;
end;
IconX := GetTreeIconX(ARow);
NameIconRect := NameRect;
NameIconRect.Right := IconX + Indent;
NameTextRect := NameRect;
NameTextRect.Left := NameIconRect.Right;
if Layout = oilVertical then
ValueRect.Left := NameTextRect.Left
else
begin
inc(NameIconRect.Right, 2 + Ord(ShowGutter));
inc(NameTextRect.Left, 3 + Ord(ShowGutter));
end;
DrawState:=[];
if ARow = FItemIndex then
Include(DrawState, pedsSelected);
ClearBackground; // clear background in one go
DrawIcon(IconX); // draw icon
DrawName(DrawState); // draw name
DrawWidgetsets; // draw widgetsets
DrawValue(DrawState); // draw value
with Canvas do
begin
// frames
if Layout = oilHorizontal then
begin
// Row Divider
if DrawHorzGridLines then
begin
Pen.Style := psDot;
Pen.EndCap := pecFlat;
Pen.Cosmetic := False;
Pen.Color := cl3DShadow;
if FRowSpacing <> 0 then
begin
MoveTo(NameTextRect.Left, NameRect.Top - 1);
LineTo(ValueRect.Right, NameRect.Top - 1);
end;
MoveTo(NameTextRect.Left, NameRect.Bottom - 1);
LineTo(ValueRect.Right, NameRect.Bottom - 1);
end;
// Split lines between: icon and name, name and value
Pen.Style := psSolid;
Pen.Cosmetic := True;
Pen.Color := cl3DHiLight;
MoveTo(NameRect.Right - 1, NameRect.Bottom - 1);
LineTo(NameRect.Right - 1, NameRect.Top - 1 - FRowSpacing);
Pen.Color := cl3DShadow;
MoveTo(NameRect.Right - 2, NameRect.Bottom - 1);
LineTo(NameRect.Right - 2, NameRect.Top - 1 - FRowSpacing);
// draw gutter line
if ShowGutter then
begin
Pen.Color := GutterEdgeColor;
MoveTo(NameIconRect.Right, NameRect.Bottom - 1);
LineTo(NameIconRect.Right, NameRect.Top - 1 - FRowSpacing);
if CurRow.Lvl > 0 then
DrawGutterToParent;
end;
end
else begin // Layout <> oilHorizontal
Pen.Style := psSolid;
Pen.Color := cl3DLight;
MoveTo(ValueRect.Left, ValueRect.Bottom - 1);
LineTo(ValueRect.Left, NameTextRect.Top);
LineTo(ValueRect.Right - 1, NameTextRect.Top);
Pen.Color:=cl3DHiLight;
LineTo(ValueRect.Right - 1, ValueRect.Bottom - 1);
LineTo(ValueRect.Left, ValueRect.Bottom - 1);
MoveTo(NameTextRect.Left + 1, NametextRect.Bottom);
LineTo(NameTextRect.Left + 1, NameTextRect.Top + 1);
LineTo(NameTextRect.Right - 2, NameTextRect.Top + 1);
Pen.Color:=cl3DLight;
LineTo(NameTextRect.Right - 2, NameTextRect.Bottom - 1);
LineTo(NameTextRect.Left + 2, NameTextRect.Bottom - 1);
end;
end;
end;
procedure TOICustomPropertyGrid.DoPaint(PaintOnlyChangedValues: boolean);
var
a: integer;
SpaceRect: TRect;
GutterX: Integer;
begin
BuildPropertyList(true);
if not PaintOnlyChangedValues then
begin
with Canvas do
begin
// draw properties
for a := 0 to FRows.Count - 1 do
PaintRow(a);
// draw unused space below rows
SpaceRect := Rect(BorderWidth, BorderWidth,
ClientWidth - BorderWidth + 1, ClientHeight - BorderWidth + 1);
if FRows.Count > 0 then
SpaceRect.Top := Rows[FRows.Count - 1].Bottom - FTopY + BorderWidth;
if FBackgroundColor <> clNone then
begin
Brush.Color := FBackgroundColor;
FillRect(SpaceRect);
end;
// draw gutter if needed
if ShowGutter and (Layout = oilHorizontal) then
begin
if FRows.Count > 0 then
GutterX := RowRect(FRows.Count - 1).Left + GetTreeIconX(FRows.Count - 1)
else
GutterX := BorderWidth + 2;
inc(GutterX, Indent + 3);
SpaceRect.Right := GutterX;
if GutterColor <> clNone then
begin
Brush.Color := GutterColor;
FillRect(SpaceRect);
end;
MoveTo(GutterX, SpaceRect.Top);
LineTo(GutterX, SpaceRect.Bottom);
end;
// don't draw border: borderstyle=bsSingle
end;
end else
begin
for a := 0 to FRows.Count-1 do
begin
if Rows[a].Editor.GetVisualValue <> Rows[a].LastPaintedValue then
PaintRow(a);
end;
end;
end;
procedure TOICustomPropertyGrid.Paint;
begin
inherited Paint;
DoPaint(false);
end;
procedure TOICustomPropertyGrid.RefreshPropertyValues;
begin
RefreshValueEdit;
Invalidate;
end;
procedure TOICustomPropertyGrid.ScrollToActiveItem;
begin
ScrollToItem(FItemIndex);
end;
procedure TOICustomPropertyGrid.ScrollToItem(NewIndex: Integer);
var
NewRow: TOIPropertyGridRow;
begin
if (NewIndex >= 0) and (NewIndex < FRows.Count) then
begin
NewRow := Rows[NewIndex];
if NewRow.Bottom >= TopY + (ClientHeight - 2*BorderWidth) then
TopY := NewRow.Bottom- (ClientHeight - 2*BorderWidth) + 1
else
if NewRow.Top < TopY then TopY := NewRow.Top;
end;
end;
procedure TOICustomPropertyGrid.PropEditLookupRootChange;
begin
// When the LookupRoot changes, no changes can be stored
// -> undo the value editor changes
RefreshValueEdit;
if PropertyEditorHook<>nil then
FCurrentEditorLookupRoot:=PropertyEditorHook.LookupRoot;
end;
function TOICustomPropertyGrid.RowRect(ARow:integer):TRect;
const
ScrollBarWidth=0;
begin
Result.Left:=BorderWidth;
Result.Top:=Rows[ARow].Top-FTopY+BorderWidth;
Result.Right:=ClientWidth-ScrollBarWidth;
Result.Bottom:=Rows[ARow].Bottom-FTopY+BorderWidth;
end;
procedure TOICustomPropertyGrid.SetItemsTops;
// compute row tops from row heights
// set indices of all rows
var a:integer;
begin
for a:=0 to FRows.Count-1 do begin
Rows[a].FIndex:=a;
Rows[a].MeasureHeight(Canvas);
end;
if FRows.Count>0 then
Rows[0].Top:=0;
for a:=1 to FRows.Count-1 do
Rows[a].FTop:=Rows[a-1].Bottom + FRowSpacing;
end;
procedure TOICustomPropertyGrid.ClearRows;
var i:integer;
begin
IncreaseChangeStep;
// reverse order to make sure child rows are freed before parent rows
for i:=FRows.Count-1 downto 0 do begin
//debugln(['TOICustomPropertyGrid.ClearRows ',i,' ',FRows.Count,' ',dbgs(frows[i])]);
Rows[i].Free;
FRows[i]:=nil;
end;
FRows.Clear;
end;
function TOICustomPropertyGrid.GetCurrentEditValue: string;
begin
if FCurrentEdit=ValueEdit then
{$IFDEF LCLCarbon}
Result:=StringReplace(ValueEdit.Text,LineFeedSymbolUTF8,LineEnding,[rfReplaceAll])
{$ELSE}
Result:=ValueEdit.Text
{$ENDIF}
else if FCurrentEdit=ValueComboBox then
Result:=ValueComboBox.Text
else if FCurrentEdit=ValueCheckBox then
Result:=ValueCheckBox.Caption
else
Result:='';
end;
procedure TOICustomPropertyGrid.SetActiveControl(const AControl: TWinControl);
var
F: TCustomForm;
begin
F := GetParentForm(Self);
if F <> nil then
F.ActiveControl := AControl;
end;
procedure TOICustomPropertyGrid.SetColumn(const AValue: TOICustomPropertyGridColumn);
begin
if FColumn <> AValue then
begin
FColumn := AValue;
// TODO: indication
end;
end;
procedure TOICustomPropertyGrid.SetCurrentEditValue(const NewValue: string);
begin
if FCurrentEdit=ValueEdit then
{$IFDEF LCLCarbon}
ValueEdit.Text:=StringReplace(StringReplace(NewValue,#13,LineEnding,[rfReplaceAll]),LineEnding,LineFeedSymbolUTF8,[rfReplaceAll])
{$ELSE}
ValueEdit.Text:=NewValue
{$ENDIF}
else if FCurrentEdit=ValueComboBox then
begin
ValueComboBox.Text:=NewValue;
if ValueComboBox.Style=csOwnerDrawVariable then
Exclude(FStates,pgsGetComboItemsCalled);
end
else if FCurrentEdit=ValueCheckBox then
SetCheckboxState(NewValue);
if (FItemIndex>=0) and (FItemIndex<RowCount) and Assigned(FCurrentEdit) then
begin
if Rows[FItemIndex].Editor.ValueIsStreamed then
FCurrentEdit.Font:=FValueFont
else
FCurrentEdit.Font:=FDefaultValueFont;
end;
end;
procedure TOICustomPropertyGrid.SetDrawHorzGridLines(const AValue: Boolean);
begin
if FDrawHorzGridLines = AValue then Exit;
FDrawHorzGridLines := AValue;
Invalidate;
end;
procedure TOICustomPropertyGrid.SetFavorites(
const AValue: TOIFavoriteProperties);
begin
//debugln('TOICustomPropertyGrid.SetFavorites ',dbgsName(Self));
if FFavorites=AValue then exit;
FFavorites:=AValue;
BuildPropertyList;
end;
procedure TOICustomPropertyGrid.SetFilter(const AValue: TTypeKinds);
begin
if (AValue<>FFilter) then
begin
FFilter:=AValue;
BuildPropertyList;
end;
end;
procedure TOICustomPropertyGrid.SetGutterColor(const AValue: TColor);
begin
if FGutterColor=AValue then exit;
FGutterColor:=AValue;
invalidate;
end;
procedure TOICustomPropertyGrid.SetGutterEdgeColor(const AValue: TColor);
begin
if FGutterEdgeColor=AValue then exit;
FGutterEdgeColor:=AValue;
invalidate;
end;
procedure TOICustomPropertyGrid.SetHighlightColor(const AValue: TColor);
begin
if FHighlightColor=AValue then exit;
FHighlightColor:=AValue;
Invalidate;
end;
procedure TOICustomPropertyGrid.Clear;
begin
ClearRows;
end;
function TOICustomPropertyGrid.GetRow(Index:integer):TOIPropertyGridRow;
begin
Result:=TOIPropertyGridRow(FRows[Index]);
end;
procedure TOICustomPropertyGrid.ValueComboBoxCloseUp(Sender: TObject);
begin
SetRowValue(false, false);
end;
procedure TOICustomPropertyGrid.ValueComboBoxGetItems(Sender: TObject);
{ This event is called whenever the widgetset updates the list.
On gtk the list is updated just before the user popups the list.
Other widgetsets need the list always, which is bad, as this means collecting
all items even if the dropdown never happens.
}
var
CurRow: TOIPropertyGridRow;
MaxItemWidth, CurItemWidth, i, Cnt: integer;
ItemValue, CurValue: string;
NewItemIndex: LongInt;
ExcludeUpdateFlag: boolean;
begin
Include(FStates,pgsGetComboItemsCalled);
if (FItemIndex>=0) and (FItemIndex<FRows.Count) then begin
ExcludeUpdateFlag:=not (pgsUpdatingEditControl in FStates);
Include(FStates,pgsUpdatingEditControl);
ValueComboBox.Items.BeginUpdate;
try
CurRow:=Rows[FItemIndex];
// Items
if not FillComboboxItems then exit;
// Text and ItemIndex
CurValue:=CurRow.Editor.GetVisualValue;
ValueComboBox.Text:=CurValue;
NewItemIndex:=ValueComboBox.Items.IndexOf(CurValue);
if NewItemIndex>=0 then
ValueComboBox.ItemIndex:=NewItemIndex;
// ItemWidth
MaxItemWidth:=ValueComboBox.Width;
Cnt:=ValueComboBox.Items.Count;
for i:=0 to Cnt-1 do begin
ItemValue:=ValueComboBox.Items[i];
CurItemWidth:=ValueComboBox.Canvas.TextWidth(ItemValue);
CurRow.Editor.ListMeasureWidth(ItemValue,i,ValueComboBox.Canvas,
CurItemWidth);
if MaxItemWidth<CurItemWidth then
MaxItemWidth:=CurItemWidth;
end;
ValueComboBox.ItemWidth:=MaxItemWidth;
finally
ValueComboBox.Items.EndUpdate;
if ExcludeUpdateFlag then
Exclude(FStates,pgsUpdatingEditControl);
end;
end;
end;
procedure TOICustomPropertyGrid.ValueComboBoxDrawItem(Control: TWinControl;
Index: Integer; ARect: TRect; State: TOwnerDrawState);
var
CurRow: TOIPropertyGridRow;
ItemValue: string;
AState: TPropEditDrawState;
FontColor: TColor;
begin
if (FItemIndex>=0) and (FItemIndex<FRows.Count) then begin
CurRow:=Rows[FItemIndex];
if (Index>=0) and (Index<ValueComboBox.Items.Count) then
ItemValue:=ValueComboBox.Items[Index]
else
ItemValue:='';
AState:=[];
if odSelected in State then Include(AState,pedsSelected);
if odFocused in State then Include(AState,pedsFocused);
if odComboBoxEdit in State then
Include(AState,pedsInEdit)
else
Include(AState,pedsInComboList);
if not(odBackgroundPainted in State) then
ValueComboBox.Canvas.FillRect(ARect);
FontColor := ValueComboBox.Canvas.Font.Color;
ValueComboBox.Canvas.Font.Assign(FDefaultValueFont);
if odSelected in State then
ValueComboBox.Canvas.Font.Color := FontColor
else
ValueComboBox.Canvas.Font.Color := clWindowText;
if CurRow.Editor.HasDefaultValue and (ItemValue = CurRow.Editor.GetDefaultValue) then
ValueComboBox.Canvas.Font.Style := ValueComboBox.Canvas.Font.Style + [fsItalic];
CurRow.Editor.ListDrawValue(ItemValue,Index,ValueComboBox.Canvas,ARect,AState);
end;
end;
procedure TOICustomPropertyGrid.OnIdle(Sender: TObject; var Done: Boolean);
begin
if (not (pgsGetComboItemsCalled in FStates))
and (FCurrentEdit=ValueComboBox)
and ValueComboBox.Enabled
then begin
ValueComboBoxGetItems(Self);
end;
end;
procedure TOICustomPropertyGrid.SetIdleEvent(Enable: boolean);
begin
if (pgsIdleEnabled in FStates)=Enable then exit;
if Enable then begin
Application.AddOnIdleHandler(@OnIdle);
Include(FStates,pgsIdleEnabled);
end else begin
Application.RemoveOnIdleHandler(@OnIdle);
Exclude(FStates,pgsIdleEnabled);
end;
end;
procedure TOICustomPropertyGrid.HintTimer(Sender: TObject);
var
PointedRow: TOIpropertyGridRow;
Window: TWinControl;
HintType: TPropEditHint;
Position, ClientPosition: TPoint;
Index: integer;
AHint: String;
OkToShow: Boolean;
begin
if FLongHintTimer <> nil then
FLongHintTimer.Enabled := False;
if (not InitHints) then exit;
Position := Mouse.CursorPos;
Window := FindLCLWindow(Position);
If (Window = Nil) or ((Window <> Self) and not IsParentOf(Window)) then exit;
ClientPosition := ScreenToClient(Position);
if ((ClientPosition.X <=0) or (ClientPosition.X >= Width) or
(ClientPosition.Y <= 0) or (ClientPosition.Y >= Height)) then
Exit;
Index := MouseToIndex(ClientPosition.Y, False);
// Don't show hint for the selected property.
if (Index < 0) or (Index >= FRows.Count) or (Index = ItemIndex) then Exit;
PointedRow := Rows[Index];
if (PointedRow = Nil) or (PointedRow.Editor = Nil) then Exit;
// Get hint
OkToShow := True;
HintType := GetHintTypeAt(Index, Position.X);
if (HintType = pehName) and Assigned(OnPropertyHint) then
OkToShow := OnPropertyHint(Self, PointedRow, AHint)
else
AHint := PointedRow.Editor.GetHint(HintType, Position.X, Position.Y);
// Show hint if all is well.
if OkToShow and FHintManager.ShowHint(Position, AHint, True, Screen.HintFont) then begin
FHintIndex := Index;
FHintType := HintType;
FShowingLongHint := True;
end;
end;
procedure TOICustomPropertyGrid.ResetLongHintTimer;
begin
if (FLongHintTimer = Nil) or FShowingLongHint then Exit;
FLongHintTimer.Enabled := False;
if RowCount > 0 then
FLongHintTimer.Enabled := not FDragging;
end;
procedure TOICustomPropertyGrid.HideHint;
begin
FHintIndex := -1;
FShowingLongHint := False;
FHintManager.HideHint;
end;
procedure TOICustomPropertyGrid.ValueControlMouseDown(Sender : TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: integer);
begin
HideHint;
ScrollToActiveItem;
end;
procedure TOICustomPropertyGrid.ValueControlMouseMove(Sender: TObject;
Shift: TShiftState; X, Y: integer);
begin
// when the cursor is divider change it to default
if (Sender as TControl).Parent.Cursor <> crDefault then
(Sender as TControl).Parent.Cursor := crDefault;
end;
procedure TOICustomPropertyGrid.IncreaseChangeStep;
begin
if FChangeStep<>$7fffffff then
inc(FChangeStep)
else
FChangeStep:=-$7fffffff;
end;
function TOICustomPropertyGrid.GridIsUpdating: boolean;
begin
Result:=(FStates*[pgsChangingItemIndex,pgsApplyingValue,
pgsBuildPropertyListNeeded]<>[])
end;
procedure TOICustomPropertyGrid.ToggleRow;
var
CurRow: TOIPropertyGridRow;
TypeKind : TTypeKind;
NewIndex: Integer;
begin
if not CanEditRowValue(false) then exit;
if FLongHintTimer <> nil then
FLongHintTimer.Enabled := False;
if (FCurrentEdit = ValueComboBox) then
begin
CurRow := Rows[FItemIndex];
TypeKind := CurRow.Editor.GetPropType^.Kind;
// Integer (like TImageIndex), Enumeration, Set, Class or Boolean ComboBox
if TypeKind in [tkInteger, tkEnumeration, tkSet, tkClass, tkBool] then
begin
if ValueComboBox.Items.Count = 0 then Exit;
// Pick the next value from list
if ValueComboBox.ItemIndex < (ValueComboBox.Items.Count-1) then
begin
NewIndex := ValueComboBox.ItemIndex + 1;
// Go to first object of tkClass. Skip '(none)' which can be in different
// places depending on widgetset sorting rules.
if (ValueComboBox.ItemIndex = -1) // Only happen at nil value of tkClass
and (ValueComboBox.Items[NewIndex] = oisNone)
and (NewIndex < (ValueComboBox.Items.Count-1)) then
Inc(NewIndex);
end
else
NewIndex := 0;
ValueComboBox.ItemIndex := NewIndex;
SetRowValue(false, false);
exit;
end;
end;
DoCallEdit;
end;
procedure TOICustomPropertyGrid.ValueEditDblClick(Sender: TObject);
begin
FFirstClickTime:=0;
ToggleRow;
end;
procedure TOICustomPropertyGrid.SetBackgroundColor(const AValue: TColor);
begin
if FBackgroundColor=AValue then exit;
FBackgroundColor:=AValue;
Invalidate;
end;
procedure TOICustomPropertyGrid.SetReferences(const AValue: TColor);
begin
if FReferencesColor=AValue then exit;
FReferencesColor:=AValue;
Invalidate;
end;
procedure TOICustomPropertyGrid.SetSubPropertiesColor(const AValue: TColor);
begin
if FSubPropertiesColor=AValue then exit;
FSubPropertiesColor:=AValue;
Invalidate;
end;
procedure TOICustomPropertyGrid.SetValueDifferBackgrndColor(AValue: TColor);
begin
if FValueDifferBackgrndColor=AValue then Exit;
FValueDifferBackgrndColor:=AValue;
Invalidate;
end;
//------------------------------------------------------------------------------
{ TOIPropertyGridRow }
constructor TOIPropertyGridRow.Create(PropertyTree: TOICustomPropertyGrid;
PropEditor:TPropertyEditor; ParentNode:TOIPropertyGridRow; WidgetSets: TLCLPlatforms);
begin
inherited Create;
// tree pointer
FTree:=PropertyTree;
FParent:=ParentNode;
FNextBrother:=nil;
FPriorBrother:=nil;
FExpanded:=false;
// child nodes
FChildCount:=0;
FFirstChild:=nil;
FLastChild:=nil;
// director
FEditor:=PropEditor;
GetLvl;
FName:=FEditor.GetName;
FTop:=0;
FHeight:=FTree.RealDefaultItemHeight;
FIndex:=-1;
LastPaintedValue:='';
FWidgetSets := WidgetSets;
end;
destructor TOIPropertyGridRow.Destroy;
begin
//debugln(['TOIPropertyGridRow.Destroy ',fname,' ',dbgs(Pointer(Self))]);
if FPriorBrother<>nil then FPriorBrother.FNextBrother:=FNextBrother;
if FNextBrother<>nil then FNextBrother.FPriorBrother:=FPriorBrother;
if FParent<>nil then begin
if FParent.FFirstChild=Self then FParent.FFirstChild:=FNextBrother;
if FParent.FLastChild=Self then FParent.FLastChild:=FPriorBrother;
dec(FParent.FChildCount);
end;
if FEditor<>nil then FEditor.Free;
inherited Destroy;
end;
function TOIPropertyGridRow.ConsistencyCheck: integer;
var
OldLvl, RealChildCount: integer;
AChild: TOIPropertyGridRow;
begin
if Top<0 then
exit(-1);
if Height<0 then
exit(-2);
if Lvl<0 then
exit(-3);
OldLvl:=Lvl;
GetLvl;
if Lvl<>OldLvl then
exit(-4);
if Name='' then
exit(-5);
if NextBrother<>nil then begin
if NextBrother.PriorBrother<>Self then
exit(-6);
if NextBrother.Index<Index+1 then
exit(-7);
end;
if PriorBrother<>nil then begin
if PriorBrother.NextBrother<>Self then
exit(-8);
if PriorBrother.Index>Index-1 then
Result:=-9
end;
if (Parent<>nil) then begin
// has parent
if (not Parent.HasChild(Self)) then
exit(-10);
end else begin
// no parent
end;
if FirstChild<>nil then begin
if Expanded then
if (FirstChild.Index<>Index+1) then
exit(-11);
end else begin
if LastChild<>nil then
exit(-12);
end;
RealChildCount:=0;
AChild:=FirstChild;
while AChild<>nil do begin
if AChild.Parent<>Self then
exit(-13);
inc(RealChildCount);
AChild:=AChild.NextBrother;
end;
if RealChildCount<>ChildCount then
exit(-14);
Result:=0;
end;
function TOIPropertyGridRow.HasChild(Row: TOIPropertyGridRow): boolean;
var
ChildRow: TOIPropertyGridRow;
begin
ChildRow:=FirstChild;
while ChildRow<>nil do
if ChildRow=Row then
exit(true);
Result:=false;
end;
procedure TOIPropertyGridRow.WriteDebugReport(const Prefix: string);
var
i: Integer;
Item: TOIPropertyGridRow;
begin
DebugLn([Prefix+'TOIPropertyGridRow.WriteDebugReport ',Name]);
i:=0;
Item:=FirstChild;
while Item<>nil do begin
DebugLn([Prefix+' ',i,' ',Item.Name]);
inc(i);
Item:=Item.NextBrother;
end;
end;
procedure TOIPropertyGridRow.GetLvl;
var n:TOIPropertyGridRow;
begin
FLvl:=0;
n:=FParent;
while n<>nil do begin
inc(FLvl);
n:=n.FParent;
end;
end;
function TOIPropertyGridRow.GetBottom:integer;
begin
Result:=FTop+FHeight;
if FTree.Layout = oilVertical
then Inc(Result, FTree.GetNameRowHeight);
end;
function TOIPropertyGridRow.IsReadOnly: boolean;
begin
Result:=Editor.IsReadOnly or IsDisabled;
end;
function TOIPropertyGridRow.IsDisabled: boolean;
var
ParentRow: TOIPropertyGridRow;
begin
Result:=false;
ParentRow:=Parent;
while (ParentRow<>nil) do begin
if paDisableSubProperties in ParentRow.Editor.GetAttributes then
exit(true);
ParentRow:=ParentRow.Parent;
end;
end;
procedure TOIPropertyGridRow.MeasureHeight(ACanvas: TCanvas);
begin
FHeight:=FTree.RealDefaultItemHeight;
Editor.PropMeasureHeight(Name,ACanvas,FHeight);
end;
function TOIPropertyGridRow.Sort(const Compare: TListSortCompare): boolean;
var
List: TFPList;
Item: TOIPropertyGridRow;
i: Integer;
begin
if IsSorted(Compare) then exit(false);
List:=TFPList.Create;
try
// create a TFPList of the children
List.Capacity:=ChildCount;
Item:=FirstChild;
while Item<>nil do begin
List.Add(Item);
Item:=Item.NextBrother;
end;
// sort the TFPList
List.Sort(Compare);
// sort in double linked list
for i:=0 to List.Count-1 do begin
Item:=TOIPropertyGridRow(List[i]);
if i=0 then begin
FFirstChild:=Item;
Item.FPriorBrother:=nil;
end else
Item.FPriorBrother:=TOIPropertyGridRow(List[i-1]);
if i=List.Count-1 then begin
FLastChild:=Item;
Item.FNextBrother:=nil;
end else
Item.FNextBrother:=TOIPropertyGridRow(List[i+1]);
end;
finally
List.Free;
end;
Result:=true;
end;
function TOIPropertyGridRow.IsSorted(const Compare: TListSortCompare): boolean;
var
Item1: TOIPropertyGridRow;
Item2: TOIPropertyGridRow;
begin
if ChildCount<2 then exit(true);
Item1:=FirstChild;
while true do begin
Item2:=Item1.NextBrother;
if Item2=nil then break;
if Compare(Item1,Item2)>0 then exit(false);
Item1:=Item2;
end;
Result:=true;
end;
function TOIPropertyGridRow.Next: TOIPropertyGridRow;
begin
if fFirstChild<>nil then
Result:=fFirstChild
else
Result:=NextSkipChilds;
end;
function TOIPropertyGridRow.NextSkipChilds: TOIPropertyGridRow;
begin
Result:=Self;
while (Result<>nil) do begin
if Result.NextBrother<>nil then begin
Result:=Result.NextBrother;
exit;
end;
Result:=Result.Parent;
end;
end;
//==============================================================================
{ TOIOptions }
function TOIOptions.FPropertyGridSplitterX(Page: TObjectInspectorPage): integer;
begin
Result:=FGridSplitterX[Page];
end;
procedure TOIOptions.FPropertyGridSplitterX(Page: TObjectInspectorPage;
const AValue: integer);
begin
FGridSplitterX[Page]:=AValue;
end;
constructor TOIOptions.Create;
var
p: TObjectInspectorPage;
begin
inherited Create;
FSaveBounds:=false;
FLeft:=0;
FTop:=0;
FWidth:=250;
FHeight:=400;
for p:=Low(TObjectInspectorPage) to High(TObjectInspectorPage) do
FGridSplitterX[p]:=110;
FDefaultItemHeight:=0;
FShowComponentTree:=true;
FComponentTreeHeight:=160;
FInfoBoxHeight:=80;
FGridBackgroundColor := DefBackgroundColor;
FSubPropertiesColor := DefSubPropertiesColor;
FValueColor := DefValueColor;
FDefaultValueColor := DefDefaultValueColor;
FValueDifferBackgrndColor := DefValueDifferBackgrndColor;
FReadOnlyColor := DefReadOnlyColor;
FReferencesColor := DefReferencesColor;
FPropertyNameColor := DefNameColor;
FHighlightColor := DefHighlightColor;
FHighlightFontColor := DefHighlightFontColor;
FGutterColor := DefGutterColor;
FGutterEdgeColor := DefGutterEdgeColor;
FCheckboxForBoolean := True;
FBoldNonDefaultValues := True;
FDrawGridLines := True;
FShowGutter := True;
FShowStatusBar := True;
FShowInfoBox := True;
end;
function TOIOptions.Load: boolean;
var
Path: String;
FileVersion: integer;
Page: TObjectInspectorPage;
begin
Result:=False;
if ConfigStore=nil then exit;
try
Path:='ObjectInspectorOptions/';
FileVersion:=ConfigStore.GetValue(Path+'Version/Value',0);
FSaveBounds:=ConfigStore.GetValue(Path+'Bounds/Valid',False);
if FSaveBounds then begin
FLeft:=ConfigStore.GetValue(Path+'Bounds/Left',0);
FTop:=ConfigStore.GetValue(Path+'Bounds/Top',0);
FWidth:=ConfigStore.GetValue(Path+'Bounds/Width',250);
FHeight:=ConfigStore.GetValue(Path+'Bounds/Height',400);
end;
if FileVersion>=2 then begin
for Page:=Low(TObjectInspectorPage) to High(TObjectInspectorPage) do
FGridSplitterX[Page]:=ConfigStore.GetValue(
Path+'Bounds/'+DefaultOIPageNames[Page]+'/SplitterX',110);
end else begin
FGridSplitterX[oipgpProperties]:=ConfigStore.GetValue(Path+'Bounds/PropertyGridSplitterX',110);
FGridSplitterX[oipgpEvents]:=ConfigStore.GetValue(Path+'Bounds/EventGridSplitterX',110);
end;
for Page:=Low(TObjectInspectorPage) to High(TObjectInspectorPage) do
if FGridSplitterX[Page]<10 then
FGridSplitterX[Page]:=10;
FDefaultItemHeight:=ConfigStore.GetValue(Path+'Bounds/DefaultItemHeight',0);
FShowComponentTree:=ConfigStore.GetValue(Path+'ComponentTree/Show/Value',True);
FComponentTreeHeight:=ConfigStore.GetValue(Path+'ComponentTree/Height/Value',160);
FGridBackgroundColor:=ConfigStore.GetValue(Path+'Color/GridBackground',DefBackgroundColor);
FSubPropertiesColor:=ConfigStore.GetValue(Path+'Color/SubProperties',DefSubPropertiesColor);
FValueColor:=ConfigStore.GetValue(Path+'Color/Value',DefValueColor);
FDefaultValueColor:=ConfigStore.GetValue(Path+'Color/DefaultValue',DefDefaultValueColor);
FValueDifferBackgrndColor:=ConfigStore.GetValue(Path+'Color/ValueDifferBackgrnd',DefValueDifferBackgrndColor);
FReadOnlyColor:=ConfigStore.GetValue(Path+'Color/ReadOnly',DefReadOnlyColor);
FReferencesColor:=ConfigStore.GetValue(Path+'Color/References',DefReferencesColor);
FPropertyNameColor:=ConfigStore.GetValue(Path+'Color/PropertyName',DefNameColor);
FHighlightColor:=ConfigStore.GetValue(Path+'Color/Highlight',DefHighlightColor);
FHighlightFontColor:=ConfigStore.GetValue(Path+'Color/HighlightFont',DefHighlightFontColor);
FGutterColor:=ConfigStore.GetValue(Path+'Color/Gutter',DefGutterColor);
FGutterEdgeColor:=ConfigStore.GetValue(Path+'Color/GutterEdge',DefGutterEdgeColor);
FShowHints:=ConfigStore.GetValue(Path+'ShowHints',FileVersion>=3);
FAutoShow := ConfigStore.GetValue(Path+'AutoShow',True);
FCheckboxForBoolean := ConfigStore.GetValue(Path+'CheckboxForBoolean',True);
FBoldNonDefaultValues := ConfigStore.GetValue(Path+'BoldNonDefaultValues',True);
FDrawGridLines := ConfigStore.GetValue(Path+'DrawGridLines',True);
FShowGutter := ConfigStore.GetValue(Path+'ShowGutter',True);
FShowStatusBar := ConfigStore.GetValue(Path+'ShowStatusBar',True);
FShowInfoBox := ConfigStore.GetValue(Path+'ShowInfoBox',True);
FInfoBoxHeight := ConfigStore.GetValue(Path+'InfoBoxHeight',80);
except
on E: Exception do begin
DebugLn('ERROR: TOIOptions.Load: ',E.Message);
exit;
end;
end;
Result:=True;
end;
function TOIOptions.Save: boolean;
var
Page: TObjectInspectorPage;
Path: String;
begin
Result:=False;
if ConfigStore=nil then exit;
try
Path:='ObjectInspectorOptions/';
ConfigStore.SetValue(Path+'Version/Value',OIOptionsFileVersion);
ConfigStore.SetDeleteValue(Path+'Bounds/Valid',FSaveBounds,False);
if FSaveBounds then begin
ConfigStore.SetValue(Path+'Bounds/Left',FLeft);
ConfigStore.SetValue(Path+'Bounds/Top',FTop);
ConfigStore.SetValue(Path+'Bounds/Width',FWidth);
ConfigStore.SetValue(Path+'Bounds/Height',FHeight);
end;
for Page:=Low(TObjectInspectorPage) to High(TObjectInspectorPage) do
ConfigStore.SetDeleteValue(Path+'Bounds/'+DefaultOIPageNames[Page]+'/SplitterX',
FGridSplitterX[Page],110);
ConfigStore.SetDeleteValue(Path+'Bounds/DefaultItemHeight',FDefaultItemHeight,0);
ConfigStore.SetDeleteValue(Path+'ComponentTree/Show/Value',FShowComponentTree,True);
ConfigStore.SetDeleteValue(Path+'ComponentTree/Height/Value',FComponentTreeHeight,160);
ConfigStore.SetDeleteValue(Path+'Color/GridBackground',FGridBackgroundColor,DefBackgroundColor);
ConfigStore.SetDeleteValue(Path+'Color/SubProperties',FSubPropertiesColor,DefSubPropertiesColor);
ConfigStore.SetDeleteValue(Path+'Color/Value',FValueColor,DefValueColor);
ConfigStore.SetDeleteValue(Path+'Color/DefaultValue',FDefaultValueColor,DefDefaultValueColor);
ConfigStore.SetDeleteValue(Path+'Color/ValueDifferBackgrnd',FValueDifferBackgrndColor,DefValueDifferBackgrndColor);
ConfigStore.SetDeleteValue(Path+'Color/ReadOnly',FReadOnlyColor,DefReadOnlyColor);
ConfigStore.SetDeleteValue(Path+'Color/References',FReferencesColor,DefReferencesColor);
ConfigStore.SetDeleteValue(Path+'Color/PropertyName',FPropertyNameColor,DefNameColor);
ConfigStore.SetDeleteValue(Path+'Color/Highlight',FHighlightColor,DefHighlightColor);
ConfigStore.SetDeleteValue(Path+'Color/HighlightFont',FHighlightFontColor,DefHighlightFontColor);
ConfigStore.SetDeleteValue(Path+'Color/Gutter',FGutterColor,DefGutterColor);
ConfigStore.SetDeleteValue(Path+'Color/GutterEdge',FGutterEdgeColor,DefGutterEdgeColor);
ConfigStore.SetDeleteValue(Path+'ShowHints',FShowHints, True);
ConfigStore.SetDeleteValue(Path+'AutoShow',FAutoShow, True);
ConfigStore.SetDeleteValue(Path+'CheckboxForBoolean',FCheckboxForBoolean, True);
ConfigStore.SetDeleteValue(Path+'BoldNonDefaultValues',FBoldNonDefaultValues, True);
ConfigStore.SetDeleteValue(Path+'DrawGridLines',FDrawGridLines, True);
ConfigStore.SetDeleteValue(Path+'ShowGutter',FShowGutter, True);
ConfigStore.SetDeleteValue(Path+'ShowStatusBar',FShowStatusBar, True);
ConfigStore.SetDeleteValue(Path+'ShowInfoBox',FShowInfoBox, True);
ConfigStore.SetDeleteValue(Path+'InfoBoxHeight',FInfoBoxHeight,80);
except
on E: Exception do begin
DebugLn('ERROR: TOIOptions.Save: ',E.Message);
exit;
end;
end;
Result:=true;
end;
procedure TOIOptions.Assign(AnObjInspector: TObjectInspectorDlg);
var
Page: TObjectInspectorPage;
begin
FLeft:=AnObjInspector.Left;
FTop:=AnObjInspector.Top;
FWidth:=AnObjInspector.Width;
FHeight:=AnObjInspector.Height;
for Page:=Low(TObjectInspectorPage) to High(TObjectInspectorPage) do
if AnObjInspector.GridControl[Page]<>nil then
FGridSplitterX[Page]:=AnObjInspector.GridControl[Page].PreferredSplitterX;
FDefaultItemHeight:=AnObjInspector.DefaultItemHeight;
FShowComponentTree:=AnObjInspector.ShowComponentTree;
FComponentTreeHeight:=AnObjInspector.ComponentPanelHeight;
FGridBackgroundColor:=AnObjInspector.PropertyGrid.BackgroundColor;
FSubPropertiesColor:=AnObjInspector.PropertyGrid.SubPropertiesColor;
FReferencesColor:=AnObjInspector.PropertyGrid.ReferencesColor;
FValueColor:=AnObjInspector.PropertyGrid.ValueFont.Color;
FDefaultValueColor:=AnObjInspector.PropertyGrid.DefaultValueFont.Color;
FValueDifferBackgrndColor:=AnObjInspector.PropertyGrid.ValueDifferBackgrndColor;
FReadOnlyColor:=AnObjInspector.PropertyGrid.ReadOnlyColor;
FPropertyNameColor:=AnObjInspector.PropertyGrid.NameFont.Color;
FHighlightColor:=AnObjInspector.PropertyGrid.HighlightColor;
FHighlightFontColor:=AnObjInspector.PropertyGrid.HighlightFont.Color;
FGutterColor:=AnObjInspector.PropertyGrid.GutterColor;
FGutterEdgeColor:=AnObjInspector.PropertyGrid.GutterEdgeColor;
FShowHints := AnObjInspector.PropertyGrid.ShowHint;
FAutoShow := AnObjInspector.AutoShow;
FCheckboxForBoolean := AnObjInspector.FCheckboxForBoolean;
FBoldNonDefaultValues := fsBold in AnObjInspector.PropertyGrid.ValueFont.Style;
FDrawGridLines := AnObjInspector.PropertyGrid.DrawHorzGridLines;
FShowGutter := AnObjInspector.PropertyGrid.ShowGutter;
FShowStatusBar := AnObjInspector.ShowStatusBar;
FShowInfoBox := AnObjInspector.ShowInfoBox;
FInfoBoxHeight := AnObjInspector.InfoBoxHeight;
end;
procedure TOIOptions.AssignTo(AnObjInspector: TObjectInspectorDlg);
var
Page: TObjectInspectorPage;
Grid: TOICustomPropertyGrid;
begin
if FSaveBounds then
begin
AnObjInspector.SetBounds(FLeft,FTop,FWidth,FHeight);
end;
for Page := Low(TObjectInspectorPage) to High(TObjectInspectorPage) do
begin
Grid := AnObjInspector.GridControl[Page];
if Grid = nil then
Continue;
Grid.PreferredSplitterX := FGridSplitterX[Page];
Grid.SplitterX := FGridSplitterX[Page];
AssignTo(Grid);
end;
AnObjInspector.DefaultItemHeight := DefaultItemHeight;
AnObjInspector.AutoShow := AutoShow;
AnObjInspector.FCheckboxForBoolean := FCheckboxForBoolean;
AnObjInspector.ShowComponentTree := ShowComponentTree;
AnObjInspector.ShowInfoBox := ShowInfoBox;
AnObjInspector.ComponentPanelHeight := ComponentTreeHeight;
AnObjInspector.InfoBoxHeight := InfoBoxHeight;
AnObjInspector.ShowStatusBar := ShowStatusBar;
end;
procedure TOIOptions.AssignTo(AGrid: TOICustomPropertyGrid);
begin
AGrid.BackgroundColor := FGridBackgroundColor;
AGrid.SubPropertiesColor := FSubPropertiesColor;
AGrid.ReferencesColor := FReferencesColor;
AGrid.ReadOnlyColor := FReadOnlyColor;
AGrid.ValueDifferBackgrndColor := FValueDifferBackgrndColor;
AGrid.ValueFont.Color := FValueColor;
if FBoldNonDefaultValues then
AGrid.ValueFont.Style := [fsBold]
else
AGrid.ValueFont.Style := [];
AGrid.DefaultValueFont.Color := FDefaultValueColor;
AGrid.NameFont.Color := FPropertyNameColor;
AGrid.HighlightColor := FHighlightColor;
AGrid.HighlightFont.Color := FHighlightFontColor;
AGrid.GutterColor := FGutterColor;
AGrid.GutterEdgeColor := FGutterEdgeColor;
AGrid.ShowHint := FShowHints;
AGrid.DrawHorzGridLines := FDrawGridLines;
AGrid.ShowGutter := FShowGutter;
AGrid.CheckboxForBoolean := FCheckboxForBoolean;
end;
//==============================================================================
{ TObjectInspectorDlg }
constructor TObjectInspectorDlg.Create(AnOwner: TComponent);
procedure AddPopupMenuItem(var NewMenuItem: TMenuItem;
ParentMenuItem: TMenuItem; const AName, ACaption, AHint, AResourceName: string;
AnOnClick: TNotifyEvent; CheckedFlag, EnabledFlag, VisibleFlag: boolean);
begin
NewMenuItem:=TMenuItem.Create(Self);
with NewMenuItem do
begin
Name:=AName;
Caption:=ACaption;
Hint:=AHint;
OnClick:=AnOnClick;
Checked:=CheckedFlag;
Enabled:=EnabledFlag;
Visible:=VisibleFlag;
if AResourceName <> '' then
ImageIndex := IDEImages.LoadImage(AResourceName);
end;
if ParentMenuItem<>nil then
ParentMenuItem.Add(NewMenuItem)
else
MainPopupMenu.Items.Add(NewMenuItem);
end;
function AddSeparatorMenuItem(ParentMenuItem: TMenuItem; const AName: string; VisibleFlag: boolean): TMenuItem;
begin
Result := TMenuItem.Create(Self);
with Result do
begin
Name := AName;
Caption := cLineCaption;
Visible := VisibleFlag;
end;
if ParentMenuItem <> nil then
ParentMenuItem.Add(Result)
else
MainPopupMenu.Items.Add(Result);
end;
begin
inherited Create(AnOwner);
FEnableHookGetSelection := true;
FPropertyEditorHook := nil;
FSelection := TPersistentSelectionList.Create;
FAutoShow := True;
FDefaultItemHeight := 0;
ComponentPanelHeight := 160;
FShowComponentTree := True;
FShowFavorites := False;
FShowRestricted := False;
FShowStatusBar := True;
FInfoBoxHeight := 80;
FPropFilterUpdating := False;
FShowInfoBox := True;
FComponentEditor := nil;
FFilter := DefaultOITypeKinds;
Caption := oisObjectInspector;
CompFilterLabel.Caption := oisBtnComponents;
MainPopupMenu.Images := IDEImages.Images_16;
AddPopupMenuItem(AddToFavoritesPopupMenuItem,nil,'AddToFavoritePopupMenuItem',
oisAddtofavorites,'Add property to favorites properties', '',
@AddToFavoritesPopupmenuItemClick,false,true,true);
AddPopupMenuItem(RemoveFromFavoritesPopupMenuItem,nil,
'RemoveFromFavoritesPopupMenuItem',
oisRemovefromfavorites,'Remove property from favorites properties', '',
@RemoveFromFavoritesPopupmenuItemClick,false,true,true);
AddPopupMenuItem(ViewRestrictedPropertiesPopupMenuItem,nil,
'ViewRestrictedPropertiesPopupMenuItem',
oisViewRestrictedProperties,'View restricted property descriptions', '',
@ViewRestrictionsPopupmenuItemClick,false,true,true);
AddPopupMenuItem(UndoPropertyPopupMenuItem,nil,'UndoPropertyPopupMenuItem',
oisUndo,'Set property value to last valid value', '',
@UndoPopupmenuItemClick,false,true,true);
AddPopupMenuItem(FindDeclarationPopupmenuItem,nil,'FindDeclarationPopupmenuItem',
oisFinddeclaration,'Jump to declaration of property', '',
@FindDeclarationPopupmenuItemClick,false,true,false);
OptionsSeparatorMenuItem := AddSeparatorMenuItem(nil, 'OptionsSeparatorMenuItem', true);
AddPopupMenuItem(CutPopupMenuItem,nil,'CutPopupMenuItem',
oisCutComponents,'Cut selected item', 'laz_cut',
@CutPopupmenuItemClick,false,true,true);
AddPopupMenuItem(CopyPopupMenuItem,nil,'CopyPopupMenuItem',
oisCopyComponents,'Copy selected item', 'laz_copy',
@CopyPopupmenuItemClick,false,true,true);
AddPopupMenuItem(PastePopupMenuItem,nil,'PastePopupMenuItem',
oisPasteComponents,'Paste selected item', 'laz_paste',
@PastePopupmenuItemClick,false,true,true);
AddPopupMenuItem(DeletePopupMenuItem,nil,'DeletePopupMenuItem',
oisDeleteComponents,'Delete selected item', 'delete_selection',
@DeletePopupmenuItemClick,false,true,true);
OptionsSeparatorMenuItem2 := AddSeparatorMenuItem(nil, 'OptionsSeparatorMenuItem2', true);
// Change class of the component. ToDo: create a 'change_class' icon resource
AddPopupMenuItem(ChangeClassPopupMenuItem,nil,'ChangeClassPopupMenuItem',
oisChangeClass,'Change Class of component', '',
@ChangeClassPopupmenuItemClick,false,true,true);
AddPopupMenuItem(ChangeParentPopupMenuItem, nil, 'ChangeParentPopupMenuItem',
oisChangeParent+' ...', 'Change Parent of component', '',
@ChangeParentItemClick, False, True, True);
OptionsSeparatorMenuItem3 := AddSeparatorMenuItem(nil, 'OptionsSeparatorMenuItem3', true);
AddPopupMenuItem(ShowComponentTreePopupMenuItem,nil
,'ShowComponentTreePopupMenuItem',oisShowComponentTree, '', ''
,@ShowComponentTreePopupMenuItemClick,FShowComponentTree,true,true);
ShowComponentTreePopupMenuItem.ShowAlwaysCheckable:=true;
AddPopupMenuItem(ShowHintsPopupMenuItem,nil
,'ShowHintPopupMenuItem',oisShowHints,'Grid hints', ''
,@ShowHintPopupMenuItemClick,false,true,true);
ShowHintsPopupMenuItem.ShowAlwaysCheckable:=true;
AddPopupMenuItem(ShowInfoBoxPopupMenuItem,nil
,'ShowInfoBoxPopupMenuItem',oisShowInfoBox, '', ''
,@ShowInfoBoxPopupMenuItemClick,FShowInfoBox,true,true);
ShowInfoBoxPopupMenuItem.ShowAlwaysCheckable:=true;
AddPopupMenuItem(ShowStatusBarPopupMenuItem,nil
,'ShowStatusBarPopupMenuItem',oisShowStatusBar, '', ''
,@ShowStatusBarPopupMenuItemClick,FShowStatusBar,true,true);
ShowStatusBarPopupMenuItem.ShowAlwaysCheckable:=true;
AddPopupMenuItem(ShowOptionsPopupMenuItem,nil
,'ShowOptionsPopupMenuItem',oisOptions, '', 'oi_options'
,@ShowOptionsPopupMenuItemClick,false,true,FOnShowOptions<>nil);
// combobox at top (filled with available persistents)
with AvailPersistentComboBox do
begin
Sorted := true;
AutoSelect := true;
AutoComplete := true;
DropDownCount := 12;
Visible := not FShowComponentTree;
end;
// Component Tree at top (filled with available components)
ComponentTree := TComponentTreeView.Create(Self);
with ComponentTree do
begin
Name := 'ComponentTree';
Parent := ComponentPanel;
AnchorSideTop.Control := CompFilterEdit;
AnchorSideTop.Side := asrBottom;
AnchorSideBottom.Control := ComponentPanel;
AnchorSideBottom.Side := asrBottom;
BorderSpacing.Top := 3;
BorderSpacing.Bottom := 3;
Left := 3;
Height := ComponentPanel.Height - BorderSpacing.Top
- CompFilterEdit.Top - CompFilterEdit.Height;
Width := ComponentPanel.Width-6;
Anchors := [akTop, akLeft, akRight, akBottom];
OnDblClick := @ComponentTreeDblClick;
OnKeyDown := @ComponentTreeKeyDown;
OnSelectionChanged := @ComponentTreeSelectionChanged;
OnComponentGetImageIndex := @ComponentTreeGetNodeImageIndex;
OnModified := @ComponentTreeModified;
Scrollbars := ssAutoBoth;
PopupMenu := MainPopupMenu;
end;
// ComponentPanel encapsulates TreeFilterEdit and ComponentTree
ComponentPanel.Constraints.MinHeight := 8;
ComponentPanel.Visible := FShowComponentTree;
CompFilterEdit.FilteredTreeview := ComponentTree;
InfoPanel := TPanel.Create(Self);
with InfoPanel do
begin
Name := 'InfoPanel';
Constraints.MinHeight := 8;
Caption := '';
Height := InfoBoxHeight;
Parent := PnlClient;
BevelOuter := bvNone;
BevelInner := bvNone;
Align := alBottom;
PopupMenu := MainPopupMenu;
Visible := FShowInfoBox;
end;
if ShowComponentTree then
CreateTopSplitter;
if ShowInfoBox then
CreateBottomSplitter;
//Create properties filter
PropertyPanel := TPanel.Create(Self);
with PropertyPanel do
begin
Name := 'PropertyPanel';
Caption := '';
Parent := PnlClient;
BevelOuter := bvNone;
BevelInner := bvNone;
Align := alClient;
Visible := True;
end;
PropFilterLabel := TLabel.Create(Self);
PropFilterEdit:= TListFilterEdit.Create(Self);
with PropFilterLabel do
begin
Parent := PropertyPanel;
Left := Scale96ToForm(5);
Top := Scale96ToForm(7);
Width := Scale96ToForm(53);
Caption := oisBtnProperties;
FocusControl := PropFilterEdit;
end;
with PropFilterEdit do
begin
Parent := PropertyPanel;
AnchorSideLeft.Control := PropFilterLabel;
AnchorSideLeft.Side := asrBottom;
AnchorSideTop.Control := PropFilterLabel;
AnchorSideTop.Side := asrCenter;
Width := PropertyPanel.Width - ( Left + 3);
AutoSelect := False;
ButtonWidth := Scale96ToForm(23);
Anchors := [akTop, akLeft, akRight];
BorderSpacing.Left := 5;
OnAfterFilter := @PropFilterEditAfterFilter;
OnResize := @PropFilterEditResize;
end;
CreateNoteBook;
// TabOrder has no effect. TAB key is handled by TObjectInspectorDlg.KeyDown().
CompFilterEdit.TabOrder := 0;
ComponentTree.TabOrder := 1;
PropFilterEdit.TabOrder := 2;
end;
destructor TObjectInspectorDlg.Destroy;
begin
FreeAndNil(FSelection);
FreeAndNil(FComponentEditor);
FreeAndNil(PropFilterLabel);
FreeAndNil(PropFilterEdit);
FreeAndNil(PropertyPanel);
inherited Destroy;
FreeAndNil(FFavorites);
end;
procedure TObjectInspectorDlg.PropFilterEditAfterFilter(Sender: TObject);
begin
FPropFilterUpdating := True;
GetActivePropertyGrid.PropNameFilter := PropFilterEdit.Filter;
RebuildPropertyLists;
FPropFilterUpdating := False;
end;
procedure TObjectInspectorDlg.PropFilterEditResize(Sender: TObject);
begin
NoteBook.BorderSpacing.Top := PropFilterEdit.BoundsRect.Bottom + 2;
end;
procedure TObjectInspectorDlg.NoteBookPageChange(Sender: TObject);
begin
PropFilterEditAfterFilter(Sender);
end;
procedure TObjectInspectorDlg.SetPropertyEditorHook(const AValue:TPropertyEditorHook);
var
Page: TObjectInspectorPage;
OldSelection: TPersistentSelectionList;
begin
if FPropertyEditorHook=AValue then exit;
if FPropertyEditorHook<>nil then begin
FPropertyEditorHook.RemoveAllHandlersForObject(Self);
end;
FPropertyEditorHook:=AValue;
if FPropertyEditorHook<>nil then begin
FPropertyEditorHook.AddHandlerChangeLookupRoot(@HookLookupRootChange);
FPropertyEditorHook.AddHandlerRefreshPropertyValues(@HookRefreshPropertyValues);
FPropertyEditorHook.AddHandlerSetSelection(@HookSetSelection);
Selection := nil;
for Page:=Low(TObjectInspectorPage) to High(TObjectInspectorPage) do
if GridControl[Page]<>nil then
GridControl[Page].PropertyEditorHook:=FPropertyEditorHook;
OldSelection:=TPersistentSelectionList.Create;
try
FPropertyEditorHook.GetSelection(OldSelection);
if EnableHookGetSelection then begin
// the propertyeditorhook gets the selection from the OI
if OldSelection.Count>0 then
FSelection.Assign(OldSelection); // if propertyeditorhook has a selection use that
FPropertyEditorHook.AddHandlerGetSelection(@HookGetSelection);
if OldSelection.Count=0 then begin
// select root component
FSelection.Clear;
if FPropertyEditorHook.LookupRoot is TComponent then
FSelection.Add(TComponent(FPropertyEditorHook.LookupRoot));
end;
end else begin
// the OI gets the selection from the propertyeditorhook
Selection := OldSelection;
end;
finally
OldSelection.Free;
end;
FillComponentList;
ComponentTree.PropertyEditorHook:=FPropertyEditorHook;
RefreshSelection;
end;
end;
function TObjectInspectorDlg.PersistentToString(APersistent: TPersistent): string;
begin
if APersistent is TComponent then
Result:=TComponent(APersistent).GetNamePath+': '+APersistent.ClassName
else
Result:=APersistent.ClassName;
end;
procedure TObjectInspectorDlg.SetComponentPanelHeight(const AValue: integer);
begin
if ComponentPanel.Height <> AValue then
ComponentPanel.Height := AValue;
end;
procedure TObjectInspectorDlg.SetDefaultItemHeight(const AValue: integer);
var
NewValue: Integer;
Page: TObjectInspectorPage;
begin
NewValue:=AValue;
if NewValue<0 then
NewValue:=0
else if (NewValue>0) and (NewValue<10) then
NewValue:=10
else if NewValue>100 then NewValue:=100;
if FDefaultItemHeight=NewValue then exit;
FDefaultItemHeight:=NewValue;
for Page:=Low(TObjectInspectorPage) to High(TObjectInspectorPage) do
if GridControl[Page]<>nil then
GridControl[Page].DefaultItemHeight:=FDefaultItemHeight;
RebuildPropertyLists;
end;
procedure TObjectInspectorDlg.SetInfoBoxHeight(const AValue: integer);
begin
if FInfoBoxHeight <> AValue then
begin
FInfoBoxHeight := AValue;
Assert(Assigned(InfoPanel), 'TObjectInspectorDlg.SetInfoBoxHeight: InfoPanel=nil');
InfoPanel.Height := AValue;
end;
end;
procedure TObjectInspectorDlg.SetRestricted(const AValue: TOIRestrictedProperties);
begin
if FRestricted = AValue then exit;
//DebugLn('TObjectInspectorDlg.SetRestricted Count: ', DbgS(AValue.Count));
FRestricted := AValue;
RestrictedGrid.Favorites := FRestricted;
end;
procedure TObjectInspectorDlg.SetOnShowOptions(const AValue: TNotifyEvent);
begin
if FOnShowOptions=AValue then exit;
FOnShowOptions:=AValue;
ShowOptionsPopupMenuItem.Visible:=FOnShowOptions<>nil;
end;
procedure TObjectInspectorDlg.AddPersistentToList(APersistent: TPersistent;
List: TStrings);
var
Allowed: boolean;
begin
if (APersistent is TComponent)
and (csDestroying in TComponent(APersistent).ComponentState) then exit;
Allowed:=true;
if Assigned(FOnAddAvailablePersistent) then
FOnAddAvailablePersistent(APersistent,Allowed);
if Allowed then
List.AddObject(PersistentToString(APersistent),APersistent);
end;
procedure TObjectInspectorDlg.HookLookupRootChange;
var
Page: TObjectInspectorPage;
begin
for Page:=Low(TObjectInspectorPage) to High(TObjectInspectorPage) do
if GridControl[Page]<>nil then
GridControl[Page].PropEditLookupRootChange;
CompFilterEdit.Filter:='';
FillComponentList;
end;
procedure TObjectInspectorDlg.FillComponentList;
begin
if FShowComponentTree then
ComponentTree.RebuildComponentNodes
else
FillPersistentComboBox;
end;
procedure TObjectInspectorDlg.UpdateComponentValues;
begin
if FShowComponentTree then
ComponentTree.UpdateComponentNodesValues
else
FillPersistentComboBox;
end;
procedure TObjectInspectorDlg.FillPersistentComboBox;
var
a: integer;
Root: TComponent;
OldText: AnsiString;
NewList: TStringList;
begin
DebugLn('TObjectInspectorDlg.FillPersistentComboBox: Updating ComboBox with components');
Assert(not FUpdatingAvailComboBox,
'TObjectInspectorDlg.FillPersistentComboBox: Updating Avail ComboBox');
//if FUpdatingAvailComboBox then exit;
FUpdatingAvailComboBox:=true;
NewList:=TStringList.Create;
try
if (FPropertyEditorHook<>nil)
and (FPropertyEditorHook.LookupRoot<>nil) then begin
AddPersistentToList(FPropertyEditorHook.LookupRoot,NewList);
if FPropertyEditorHook.LookupRoot is TComponent then begin
Root:=TComponent(FPropertyEditorHook.LookupRoot);
//writeln('[TObjectInspectorDlg.FillComponentComboBox] B ',Root.Name,' ',Root.ComponentCount);
for a:=0 to Root.ComponentCount-1 do
AddPersistentToList(Root.Components[a],NewList);
end;
end;
if AvailPersistentComboBox.Items.Equals(NewList) then exit;
AvailPersistentComboBox.Items.BeginUpdate;
if AvailPersistentComboBox.Items.Count=1 then
OldText:=AvailPersistentComboBox.Text
else
OldText:='';
AvailPersistentComboBox.Items.Assign(NewList);
AvailPersistentComboBox.Items.EndUpdate;
a:=AvailPersistentComboBox.Items.IndexOf(OldText);
if (OldText='') or (a<0) then
SetAvailComboBoxText
else
AvailPersistentComboBox.ItemIndex:=a;
finally
NewList.Free;
FUpdatingAvailComboBox:=false;
end;
end;
procedure TObjectInspectorDlg.BeginUpdate;
begin
inc(FUpdateLock);
end;
procedure TObjectInspectorDlg.EndUpdate;
begin
dec(FUpdateLock);
if FUpdateLock<0 then begin
DebugLn('ERROR TObjectInspectorDlg.EndUpdate');
end;
if FUpdateLock=0 then begin
if oifRebuildPropListsNeeded in FFLags then
RebuildPropertyLists;
end;
end;
function TObjectInspectorDlg.GetActivePropertyGrid: TOICustomPropertyGrid;
begin
Result:=nil;
if NoteBook=nil then exit;
case NoteBook.PageIndex of
0: Result:=PropertyGrid;
1: Result:=EventGrid;
2: Result:=FavoriteGrid;
3: Result:=RestrictedGrid;
end;
end;
function TObjectInspectorDlg.GetActivePropertyRow: TOIPropertyGridRow;
var
CurGrid: TOICustomPropertyGrid;
begin
Result:=nil;
CurGrid:=GetActivePropertyGrid;
if CurGrid=nil then exit;
Result:=CurGrid.GetActiveRow;
end;
function TObjectInspectorDlg.GetCurRowDefaultValue(var DefaultStr: string): Boolean;
var
CurRow: TOIPropertyGridRow;
begin
Result:=False;
DefaultStr:='';
CurRow:=GetActivePropertyRow;
if Assigned(CurRow) and (CurRow.Editor.HasDefaultValue) then
begin
try
DefaultStr:=CurRow.Editor.GetDefaultValue;
Result:=true;
except
DefaultStr:='';
end;
end;
end;
function TObjectInspectorDlg.GetParentCandidates: TFPList;
begin
Result:=GetChangeParentCandidates(FPropertyEditorHook,Selection);
end;
function TObjectInspectorDlg.HasParentCandidates: Boolean;
var
Candidates: TFPList=nil;
begin
try
Candidates := GetParentCandidates;
Result := (Candidates.Count>1); // single candidate is current parent
finally
Candidates.Free;
end;
end;
procedure TObjectInspectorDlg.ChangeParent;
var
i: Integer;
Control: TControl;
NewParentName: String;
NewParent: TPersistent;
NewSelection: TPersistentSelectionList;
Candidates: TFPList = nil;
begin
if (Selection.Count < 1) then Exit;
try
Candidates := GetParentCandidates;
if not ShowChangeParentDlg(Selection, Candidates, NewParentName) then
Exit;
finally
Candidates.Free;
end;
if NewParentName = TWinControl(FPropertyEditorHook.LookupRoot).Name then
NewParent := FPropertyEditorHook.LookupRoot
else
NewParent := TWinControl(FPropertyEditorHook.LookupRoot).FindComponent(NewParentName);
if not (NewParent is TWinControl) then Exit;
for i := 0 to Selection.Count-1 do
begin
if not (Selection[i] is TControl) then Continue;
Control := TControl(Selection[i]);
if Control.Parent = nil then Continue;
Control.Parent := TWinControl(NewParent);
end;
// Ensure the order of controls in the OI now reflects the new ZOrder
// This code is based on ZOrderItemClick().
NewSelection := TPersistentSelectionList.Create;
try
NewSelection.ForceUpdate:=True;
NewSelection.Add(NewParent);
for i:=0 to Selection.Count-1 do
NewSelection.Add(Selection.Items[i]);
SetSelection(NewSelection);
NewSelection.ForceUpdate:=True;
NewSelection.Delete(0);
SetSelection(NewSelection);
finally
NewSelection.Free;
end;
DoModified;
FillComponentList;
end;
procedure TObjectInspectorDlg.SetSelection(const ASelection: TPersistentSelectionList);
begin
if FSettingSelectionCount > 0 then Exit; // Prevent a recursive loop.
Inc(FSettingSelectionCount);
try
if ASelection<>nil then begin
// Nothing changed or endless loop -> quit.
if FSelection.IsEqual(ASelection) and not ASelection.ForceUpdate then
Exit;
end else begin
if FSelection.Count=0 then
Exit;
end;
// ToDo: Clear filter only if a selected node is hidden (Visible=False)
CompFilterEdit.Filter:='';
if ASelection<>nil then
FSelection.Assign(ASelection)
else
FSelection.Clear;
SetAvailComboBoxText;
RefreshSelection;
if Assigned(FOnSelectPersistentsInOI) then
FOnSelectPersistentsInOI(Self);
finally
Dec(FSettingSelectionCount);
end;
end;
procedure TObjectInspectorDlg.RefreshSelection;
var
Page: TObjectInspectorPage;
begin
if FRefreshingSelectionCount > 0 then Exit; // Prevent a recursive loop.
Inc(FRefreshingSelectionCount);
if NoteBook.Page[3].Visible then
begin
DoUpdateRestricted;
// invalidate RestrictedProps
WidgetSetsRestrictedBox.Invalidate;
ComponentRestrictedBox.Invalidate;
end;
for Page := Low(TObjectInspectorPage) to High(TObjectInspectorPage) do
if GridControl[Page] <> nil then
GridControl[Page].Selection := FSelection;
RefreshComponentTreeSelection;
if (not Visible) and AutoShow and (FSelection.Count > 0) then
if Assigned(OnAutoShow) then
OnAutoShow(Self)
else
Visible := True;
Dec(FRefreshingSelectionCount);
end;
procedure TObjectInspectorDlg.RefreshComponentTreeSelection;
begin
ComponentTree.Selection := FSelection;
ComponentTree.MakeSelectionVisible;
end;
procedure TObjectInspectorDlg.SaveChanges;
var
Page: TObjectInspectorPage;
begin
for Page:=Low(TObjectInspectorPage) to High(TObjectInspectorPage) do
if GridControl[Page]<>nil then
GridControl[Page].SaveChanges;
end;
procedure TObjectInspectorDlg.RefreshPropertyValues;
var
Page: TObjectInspectorPage;
begin
for Page:=Low(TObjectInspectorPage) to High(TObjectInspectorPage) do
if GridControl[Page]<>nil then
GridControl[Page].RefreshPropertyValues;
end;
procedure TObjectInspectorDlg.RebuildPropertyLists;
var
Page: TObjectInspectorPage;
begin
if FUpdateLock>0 then
Include(FFLags,oifRebuildPropListsNeeded)
else begin
Exclude(FFLags,oifRebuildPropListsNeeded);
for Page:=Low(TObjectInspectorPage) to High(TObjectInspectorPage) do
if GridControl[Page]<>nil then
GridControl[Page].BuildPropertyList(False, not FPropFilterUpdating);
end;
end;
procedure TObjectInspectorDlg.AvailComboBoxCloseUp(Sender:TObject);
var
NewComponent,Root:TComponent;
a:integer;
procedure SetSelectedPersistent(c:TPersistent);
begin
if (FSelection.Count=1) and (FSelection[0]=c) then exit;
FSelection.Clear;
FSelection.Add(c);
RefreshSelection;
if Assigned(FOnSelectPersistentsInOI) then
FOnSelectPersistentsInOI(Self);
end;
begin
if FUpdatingAvailComboBox then exit;
if (FPropertyEditorHook=nil) or (FPropertyEditorHook.LookupRoot=nil) then
exit;
if not (FPropertyEditorHook.LookupRoot is TComponent) then begin
// not a TComponent => no children => select always only the root
SetSelectedPersistent(FPropertyEditorHook.LookupRoot);
exit;
end;
Root:=TComponent(FPropertyEditorHook.LookupRoot);
if (AvailPersistentComboBox.Text=PersistentToString(Root)) then begin
SetSelectedPersistent(Root);
end else begin
for a:=0 to Root.ComponentCount-1 do begin
NewComponent:=Root.Components[a];
if AvailPersistentComboBox.Text=PersistentToString(NewComponent) then
begin
SetSelectedPersistent(NewComponent);
break;
end;
end;
end;
end;
function TObjectInspectorDlg.GetComponentEditorForSelection: TBaseComponentEditor;
var
APersistent: TPersistent;
AComponent: TComponent absolute APersistent;
ADesigner: TIDesigner;
begin
APersistent := GetSelectedPersistent;
if not (APersistent is TComponent) then
Exit(nil);
ADesigner := FindRootDesigner(AComponent);
if not (ADesigner is TComponentEditorDesigner) then
Exit(nil);
Result := GetComponentEditor(AComponent, TComponentEditorDesigner(ADesigner));
end;
procedure TObjectInspectorDlg.ComponentTreeDblClick(Sender: TObject);
var
CompEditor: TBaseComponentEditor;
begin
if (PropertyEditorHook = nil) or (PropertyEditorHook.LookupRoot = nil) then
Exit;
if not FSelection.IsEqual(ComponentTree.Selection) then
ComponentTreeSelectionChanged(Sender);
CompEditor := GetComponentEditorForSelection;
if Assigned(CompEditor) then
begin
try
CompEditor.Edit;
finally
CompEditor.Free;
end;
end;
end;
procedure TObjectInspectorDlg.ComponentTreeKeyDown(Sender: TObject;
var Key: Word; Shift: TShiftState);
begin
if (Shift = []) and (Key = VK_DELETE) and
(Selection.Count > 0) and
(MessageDlg(oiscDelete, mtConfirmation,[mbYes, mbNo],0) = mrYes) then
begin
DeletePopupmenuItemClick(nil);
end;
end;
procedure TObjectInspectorDlg.ComponentTreeSelectionChanged(Sender: TObject);
begin
if (PropertyEditorHook=nil) or (PropertyEditorHook.LookupRoot=nil) then exit;
if FSelection.IsEqual(ComponentTree.Selection) then exit;
FSelection.Assign(ComponentTree.Selection);
RefreshSelection;
DefSelectionVisibleInDesigner;
if Assigned(FOnSelectPersistentsInOI) then
FOnSelectPersistentsInOI(Self);
end;
procedure TObjectInspectorDlg.MainPopupMenuClose(Sender: TObject);
begin
if FStateOfHintsOnMainPopupMenu then ShowHintPopupMenuItemClick(nil);
end;
procedure TObjectInspectorDlg.FormResize(Sender: TObject);
begin
ComponentPanel.Constraints.MaxHeight := Height-50;
end;
procedure TObjectInspectorDlg.GridKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
var
Handled: Boolean;
begin
Handled := false;
//CTRL-[Shift]-TAB will select next or previous notebook tab
if (Key=VK_TAB) and (ssCtrl in Shift) then
begin
Handled := true;
if ssShift in Shift then
ShowNextPage(-1)
else
ShowNextPage(1);
end;
//Allow combobox navigation while it has focus
if not Handled then
Handled := AvailPersistentComboBox.Focused;
//CTRL-ArrowDown will dropdown the component combobox
if (not Handled) and (Key=VK_DOWN) and (ssCtrl in Shift) then
begin
Handled := true;
if AvailPersistentComboBox.Canfocus then
AvailPersistentComboBox.SetFocus;
AvailPersistentComboBox.DroppedDown := true;
end;
if not Handled then
begin
if Assigned(OnOIKeyDown) then
OnOIKeyDown(Self,Key,Shift);
if (Key<>VK_UNKNOWN) and Assigned(OnRemainingKeyDown) then
OnRemainingKeyDown(Self,Key,Shift);
end
else
Key := VK_UNKNOWN;
end;
procedure TObjectInspectorDlg.GridKeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if Assigned(OnRemainingKeyUp) then OnRemainingKeyUp(Self,Key,Shift);
end;
procedure TObjectInspectorDlg.GridDblClick(Sender: TObject);
begin
//
end;
procedure TObjectInspectorDlg.PropEditPopupClick(Sender: TObject);
var
CurGrid: TOICustomPropertyGrid;
CurRow: TOIPropertyGridRow;
s: String;
begin
CurGrid:=GetActivePropertyGrid;
CurRow := GetActivePropertyRow;
CurRow.Editor.ExecuteVerb((Sender as TMenuItem).Tag);
s := CurRow.Editor.GetVisualValue;
CurGrid.CurrentEditValue := s;
RefreshPropertyValues;
Invalidate;
DebugLn(['Executed verb number ', (Sender as TMenuItem).Tag, ', VisualValue: ', s, ', CurRow: ', CurRow]);
end;
procedure TObjectInspectorDlg.AddToFavoritesPopupmenuItemClick(Sender: TObject);
begin
//debugln('TObjectInspectorDlg.OnAddToFavoritePopupmenuItemClick');
if Assigned(OnAddToFavorites) then OnAddToFavorites(Self);
end;
procedure TObjectInspectorDlg.RemoveFromFavoritesPopupmenuItemClick(Sender: TObject);
begin
if Assigned(OnRemoveFromFavorites) then OnRemoveFromFavorites(Self);
end;
procedure TObjectInspectorDlg.ViewRestrictionsPopupmenuItemClick(Sender: TObject);
begin
DoViewRestricted;
end;
procedure TObjectInspectorDlg.UndoPopupmenuItemClick(Sender: TObject);
var
CurGrid: TOICustomPropertyGrid;
CurRow: TOIPropertyGridRow;
begin
CurGrid:=GetActivePropertyGrid;
CurRow:=GetActivePropertyRow;
if CurRow=nil then exit;
CurGrid.CurrentEditValue:=CurRow.Editor.GetVisualValue;
end;
procedure TObjectInspectorDlg.FindDeclarationPopupmenuItemClick(Sender: TObject);
begin
if Assigned(OnFindDeclarationOfProperty) then
OnFindDeclarationOfProperty(Self);
end;
procedure TObjectInspectorDlg.CutPopupmenuItemClick(Sender: TObject);
var
ADesigner: TIDesigner;
begin
if (Selection.Count > 0) and (Selection[0] is TComponent) then
begin
ADesigner := FindRootDesigner(Selection[0]);
if ADesigner is TComponentEditorDesigner then
TComponentEditorDesigner(ADesigner).CutSelection;
end;
end;
procedure TObjectInspectorDlg.CopyPopupmenuItemClick(Sender: TObject);
var
ADesigner: TIDesigner;
begin
if (Selection.Count > 0) and (Selection[0] is TComponent) then
begin
ADesigner := FindRootDesigner(Selection[0]);
if ADesigner is TComponentEditorDesigner then
TComponentEditorDesigner(ADesigner).CopySelection;
end;
end;
procedure TObjectInspectorDlg.PastePopupmenuItemClick(Sender: TObject);
var
ADesigner: TIDesigner;
begin
if Selection.Count > 0 then
begin
ADesigner := FindRootDesigner(Selection[0]);
if ADesigner is TComponentEditorDesigner then
TComponentEditorDesigner(ADesigner).PasteSelection([]);
end;
end;
procedure TObjectInspectorDlg.DeletePopupmenuItemClick(Sender: TObject);
var
ADesigner: TIDesigner;
ACollection: TCollection;
i: integer;
begin
if (Selection.Count > 0) then
begin
ADesigner := FindRootDesigner(Selection[0]);
if ADesigner is TComponentEditorDesigner then
begin
if Selection[0] is TCollection then
begin
ACollection := TCollection(Selection[0]);
Selection.BeginUpdate;
Selection.Clear;
for i := 0 to ACollection.Count - 1 do
Selection.Add(ACollection.Items[i]);
Selection.EndUpdate;
if Assigned(FOnSelectPersistentsInOI) then
FOnSelectPersistentsInOI(Self);
end;
TComponentEditorDesigner(ADesigner).DeleteSelection;
end;
end;
end;
procedure TObjectInspectorDlg.ChangeClassPopupmenuItemClick(Sender: TObject);
var
ADesigner: TIDesigner;
begin
if (Selection.Count = 1) then
begin
ADesigner := FindRootDesigner(Selection[0]);
if ADesigner is TComponentEditorDesigner then
TComponentEditorDesigner(ADesigner).ChangeClass;
end;
end;
procedure TObjectInspectorDlg.GridModified(Sender: TObject);
begin
DoModified;
end;
procedure TObjectInspectorDlg.GridSelectionChange(Sender: TObject);
var
Row: TOIPropertyGridRow;
begin
Row := GetActivePropertyRow;
if Assigned(Row) then
FLastActiveRowName := Row.Name;
if Assigned(FOnSelectionChange) then
FOnSelectionChange(Self);
end;
function TObjectInspectorDlg.GridPropertyHint(Sender: TObject;
PointedRow: TOIPropertyGridRow; out AHint: string): boolean;
begin
Result := False;
if Assigned(FOnPropertyHint) then
Result := FOnPropertyHint(Sender, PointedRow, AHint);
end;
procedure TObjectInspectorDlg.SetAvailComboBoxText;
begin
case FSelection.Count of
0: // none selected
AvailPersistentComboBox.Text:='';
1: // single selection
AvailPersistentComboBox.Text:=PersistentToString(FSelection[0]);
else
// multi selection
AvailPersistentComboBox.Text:=Format(oisItemsSelected, [FSelection.Count]);
end;
end;
procedure TObjectInspectorDlg.HookGetSelection(const ASelection: TPersistentSelectionList);
begin
if ASelection=nil then exit;
ASelection.Assign(FSelection);
end;
procedure TObjectInspectorDlg.HookSetSelection(const ASelection: TPersistentSelectionList);
begin
Selection := ASelection;
end;
procedure TObjectInspectorDlg.SetShowComponentTree(const AValue: boolean);
begin
if FShowComponentTree = AValue then Exit;
FShowComponentTree := AValue;
BeginUpdate;
try
ShowComponentTreePopupMenuItem.Checked := FShowComponentTree;
// hide / show / rebuild controls
AvailPersistentComboBox.Visible := not FShowComponentTree;
ComponentPanel.Visible := FShowComponentTree;
if FShowComponentTree then
CreateTopSplitter
else
FreeAndNil(Splitter1);
FillComponentList;
finally
EndUpdate;
end;
end;
procedure TObjectInspectorDlg.SetShowInfoBox(const AValue: Boolean);
begin
if FShowInfoBox = AValue then exit;
FShowInfoBox := AValue;
ShowInfoBoxPopupMenuItem.Checked := AValue;
InfoPanel.Visible := AValue;
if AValue then begin
CreateBottomSplitter;
if Assigned(FOnSelectionChange) then
FOnSelectionChange(Self);
end
else
FreeAndNil(Splitter2);
end;
procedure TObjectInspectorDlg.SetShowStatusBar(const AValue: Boolean);
begin
if FShowStatusBar = AValue then exit;
FShowStatusBar := AValue;
StatusBar.Visible := AValue;
ShowStatusBarPopupMenuItem.Checked := AValue;
if ShowInfoBox then // make sure StatusBar goes below InfoPanel.
StatusBar.Top := InfoPanel.Top + InfoPanel.Height + 1;
end;
procedure TObjectInspectorDlg.SetShowFavorites(const AValue: Boolean);
begin
if FShowFavorites = AValue then exit;
FShowFavorites := AValue;
NoteBook.Page[2].TabVisible := AValue;
end;
procedure TObjectInspectorDlg.SetShowRestricted(const AValue: Boolean);
begin
if FShowRestricted = AValue then exit;
FShowRestricted := AValue;
NoteBook.Page[3].TabVisible := AValue;
end;
procedure TObjectInspectorDlg.ShowNextPage(Delta: integer);
var
NewPageIndex: Integer;
begin
NewPageIndex := NoteBook.PageIndex;
repeat
NewPageIndex := NewPageIndex + Delta;
if NewPageIndex >= NoteBook.PageCount then
NewPageIndex := 0;
if NewPageIndex < 0 then
NewPageIndex := NoteBook.PageCount - 1;
if NoteBook.Page[NewPageIndex].TabVisible then
begin
NoteBook.PageIndex := NewPageIndex;
break;
end;
until NewPageIndex = NoteBook.PageIndex;
end;
procedure TObjectInspectorDlg.RestrictedPageShow(Sender: TObject);
begin
//DebugLn('RestrictedPageShow');
DoUpdateRestricted;
end;
procedure TObjectInspectorDlg.RestrictedPaint(
ABox: TPaintBox; const ARestrictions: TWidgetSetRestrictionsArray);
function OutVertCentered(AX: Integer; const AStr: String): TSize;
begin
Result := ABox.Canvas.TextExtent(AStr);
ABox.Canvas.TextOut(AX, (ABox.Height - Result.CY) div 2, AStr);
end;
var
X, Y: Integer;
lclPlatform: TLCLPlatform;
None: Boolean;
OldStyle: TBrushStyle;
ImagesRes: TScaledImageListResolution;
dist: Integer;
begin
ImagesRes := IDEImages.Images_16.ResolutionForPPI[0, Font.PixelsPerInch, GetCanvasScaleFactor];
dist := Scale96ToForm(4);
X := 0;
Y := (ABox.Height - ImagesRes.Height) div 2;
OldStyle := ABox.Canvas.Brush.Style;
try
ABox.Canvas.Brush.Style := bsClear;
None := True;
for lclPlatform := Low(TLCLPlatform) to High(TLCLPlatform) do
begin
if ARestrictions[lclPlatform] = 0 then continue;
None := False;
ImagesRes.Draw(
ABox.Canvas, X, Y,
IDEImages.LoadImage('issue_'+LCLPlatformDirNames[lclPlatform]));
Inc(X, ImagesRes.Width);
Inc(X, Scale96ToForm(OutVertCentered(X, IntToStr(ARestrictions[lclPlatform])).CX));
Inc(X, dist);
end;
if None then
OutVertCentered(4, oisNone);
finally
ABox.Canvas.Brush.Style := OldStyle;
end;
end;
procedure TObjectInspectorDlg.WidgetSetRestrictedPaint(Sender: TObject);
begin
if RestrictedProps <> nil then
RestrictedPaint(WidgetSetsRestrictedBox, RestrictedProps.WidgetSetRestrictions);
end;
procedure TObjectInspectorDlg.ComponentRestrictedPaint(Sender: TObject);
var
I, J: Integer;
WidgetSetRestrictions: TWidgetSetRestrictionsArray;
begin
if (RestrictedProps = nil) or (Selection = nil) then exit;
FillChar(WidgetSetRestrictions{%H-}, SizeOf(WidgetSetRestrictions), 0);
for I := 0 to RestrictedProps.Count - 1 do
begin
if RestrictedProps.Items[I] is TOIRestrictedProperty then
for J := 0 to Selection.Count - 1 do
with RestrictedProps.Items[I] as TOIRestrictedProperty do
CheckRestrictions(Selection[J].ClassType, WidgetSetRestrictions);
end;
RestrictedPaint(ComponentRestrictedBox, WidgetSetRestrictions);
end;
procedure TObjectInspectorDlg.TopSplitterMoved(Sender: TObject);
begin
Assert(Assigned(ComponentTree));
ComponentTree.Invalidate; // Update Scrollbars.
end;
procedure TObjectInspectorDlg.CreateTopSplitter;
// vertical splitter between component tree and notebook
begin
Splitter1 := TSplitter.Create(Self);
with Splitter1 do
begin
Name := 'Splitter1';
Parent := PnlClient;
Align := alTop;
Top := ComponentPanelHeight;
Height := 5;
OnMoved := @TopSplitterMoved;
end;
end;
procedure TObjectInspectorDlg.DefSelectionVisibleInDesigner;
procedure ShowPage(const aPage: TTabSheet);
begin
if aPage.Parent is TPageControl then
TPageControl(aPage.Parent).PageIndex := aPage.PageIndex;
end;
procedure ShowPage(const aPage: TPage);
begin
if aPage.Parent is TNotebook then
TNotebook(aPage.Parent).PageIndex := aPage.PageIndex;
end;
var
Cnt: TControl;
begin
if (Selection.Count = 0) or (Selection[0] = nil) or not(Selection[0] is TControl) then
Exit;
Cnt := TControl(Selection[0]);
while Cnt<>nil do
begin
if Cnt is TTabSheet then
ShowPage(TTabSheet(Cnt))
else
if Cnt is TPage then
ShowPage(TPage(Cnt));
Cnt := Cnt.Parent;
end;
end;
procedure TObjectInspectorDlg.CreateBottomSplitter;
// vertical splitter between notebook and info panel
begin
Splitter2 := TSplitter.Create(Self);
with Splitter2 do
begin
Name := 'Splitter2';
Parent := PnlClient;
Align := alBottom;
Top := InfoPanel.Top - 1;
Height := 5;
end;
end;
procedure TObjectInspectorDlg.DestroyNoteBook;
begin
if NoteBook<>nil then
NoteBook.Visible:=false;
FreeAndNil(PropertyGrid);
FreeAndNil(EventGrid);
FreeAndNil(FavoriteGrid);
FreeAndNil(RestrictedGrid);
FreeAndNil(NoteBook);
end;
procedure TObjectInspectorDlg.CreateNoteBook;
function CreateGrid(
ATypeFilter: TTypeKinds; AOIPage: TObjectInspectorPage;
ANotebookPage: Integer): TOICustomPropertyGrid;
begin
Result:=TOICustomPropertyGrid.CreateWithParams(
Self, PropertyEditorHook, ATypeFilter, FDefaultItemHeight);
with Result do
begin
Name := DefaultOIGridNames[AOIPage];
Selection := Self.FSelection;
Align := alClient;
PopupMenu := MainPopupMenu;
OnModified := @GridModified;
OnSelectionChange := @GridSelectionChange;
OnPropertyHint := @GridPropertyHint;
OnOIKeyDown := @GridKeyDown;
OnKeyUp := @GridKeyUp;
OnDblClick := @GridDblClick;
OnMouseWheel := @OnGridMouseWheel;
Parent := NoteBook.Page[ANotebookPage];
end;
end;
function AddPage(PageName, TabCaption: string): TTabSheet;
begin
Result:=TTabSheet.Create(Self);
Result.Name:=PageName;
Result.Caption:=TabCaption;
Result.Parent:=NoteBook;
end;
var
APage: TTabSheet;
begin
DestroyNoteBook;
// NoteBook
NoteBook:=TPageControl.Create(Self);
with NoteBook do
begin
Name := 'NoteBook';
Parent := PropertyPanel;
PropFilterEditResize(nil);
Align := alClient;
PopupMenu := MainPopupMenu;
OnChange := @NoteBookPageChange;
end;
AddPage(DefaultOIPageNames[oipgpProperties],oisProperties);
AddPage(DefaultOIPageNames[oipgpEvents],oisEvents);
APage:=AddPage(DefaultOIPageNames[oipgpFavorite],oisFavorites);
APage.TabVisible := ShowFavorites;
APage:=AddPage(DefaultOIPageNames[oipgpRestricted],oisRestricted);
APage.TabVisible := ShowRestricted;
APage.OnShow := @RestrictedPageShow;
NoteBook.PageIndex:=0;
PropertyGrid := CreateGrid(Filter - [tkMethod], oipgpProperties, 0);
EventGrid := CreateGrid([tkMethod], oipgpEvents, 1);
FavoriteGrid := CreateGrid(Filter + [tkMethod], oipgpFavorite, 2);
FavoriteGrid.Favorites := FFavorites;
RestrictedGrid := CreateGrid(Filter + [tkMethod], oipgpRestricted, 3);
RestrictedPanel := TPanel.Create(Self);
with RestrictedPanel do
begin
Align := alTop;
BevelOuter := bvNone;
Parent := NoteBook.Page[3];
end;
RestrictedInnerPanel := TPanel.Create(Self);
with RestrictedInnerPanel do
begin
BevelOuter := bvNone;
BorderSpacing.Around := 6;
Parent := RestrictedPanel;
end;
WidgetSetsRestrictedLabel := TLabel.Create(Self);
with WidgetSetsRestrictedLabel do
begin
Caption := oisWidgetSetRestrictions;
Top := 1;
Align := alTop;
AutoSize := True;
Parent := RestrictedInnerPanel;
end;
WidgetSetsRestrictedBox := TPaintBox.Create(Self);
with WidgetSetsRestrictedBox do
begin
Top := 2;
Align := alTop;
Height := 24;
OnPaint := @WidgetSetRestrictedPaint;
Parent := RestrictedInnerPanel;
end;
ComponentRestrictedLabel := TLabel.Create(Self);
with ComponentRestrictedLabel do
begin
Caption := oisComponentRestrictions;
Top := 3;
Align := alTop;
AutoSize := True;
Parent := RestrictedInnerPanel;
end;
ComponentRestrictedBox := TPaintBox.Create(Self);
with ComponentRestrictedBox do
begin
Top := 4;
Align := alTop;
Height := 24;
OnPaint := @ComponentRestrictedPaint;
Parent := RestrictedInnerPanel;
end;
RestrictedInnerPanel.AutoSize := True;
RestrictedPanel.AutoSize := True;
end;
procedure TObjectInspectorDlg.KeyDown(var Key: Word; Shift: TShiftState);
var
CurGrid: TOICustomPropertyGrid;
begin
// ToDo: Allow TAB key to FilterEdit, TreeView and Grid. Now the Grid gets seleted always.
DebugLn(['TObjectInspectorDlg.KeyDown: Key=', Key, ', ActiveControl=', ActiveControl]);
//Do not disturb the combobox navigation while it has focus
if not AvailPersistentComboBox.DroppedDown then begin
CurGrid:=GetActivePropertyGrid;
if CurGrid<>nil then begin
CurGrid.HandleStandardKeys(Key,Shift);
if Key=VK_UNKNOWN then exit;
end;
end;
inherited KeyDown(Key, Shift);
if (Key<>VK_UNKNOWN) and Assigned(OnRemainingKeyDown) then
OnRemainingKeyDown(Self,Key,Shift);
end;
procedure TObjectInspectorDlg.KeyUp(var Key: Word; Shift: TShiftState);
begin
inherited KeyUp(Key, Shift);
if (Key<>VK_UNKNOWN) and Assigned(OnRemainingKeyUp) then
OnRemainingKeyUp(Self,Key,Shift);
end;
procedure TObjectInspectorDlg.Resize;
begin
inherited Resize;
if Assigned(ComponentTree) then
ComponentTree.Invalidate; // Update Scrollbars.
end;
procedure TObjectInspectorDlg.ComponentTreeModified(Sender: TObject);
begin
DoModified;
end;
function TObjectInspectorDlg.GetSelectedPersistent: TPersistent;
begin
if ComponentTree.Selection.Count = 1 then
Result := ComponentTree.Selection[0]
else
Result := nil;
end;
procedure TObjectInspectorDlg.ShowComponentTreePopupMenuItemClick(Sender: TObject);
begin
ShowComponentTree:=not ShowComponentTree;
end;
procedure TObjectInspectorDlg.ShowHintPopupMenuItemClick(Sender : TObject);
var
Page: TObjectInspectorPage;
begin
for Page := Low(TObjectInspectorPage) to High(TObjectInspectorPage) do
if GridControl[Page] <> nil then
GridControl[Page].ShowHint := not GridControl[Page].ShowHint;
end;
procedure TObjectInspectorDlg.ShowInfoBoxPopupMenuItemClick(Sender: TObject);
begin
ShowInfoBox:=not ShowInfoBox;
end;
procedure TObjectInspectorDlg.ShowStatusBarPopupMenuItemClick(Sender: TObject);
begin
ShowStatusBar:=not ShowStatusBar;
end;
procedure TObjectInspectorDlg.ShowOptionsPopupMenuItemClick(Sender: TObject);
begin
if Assigned(FOnShowOptions) then FOnShowOptions(Sender);
end;
// ---
procedure TObjectInspectorDlg.MainPopupMenuPopup(Sender: TObject);
const
PropertyEditorMIPrefix = 'PropertyEditorVerbMenuItem';
ComponentEditorMIPrefix = 'ComponentEditorVerbMenuItem';
var
ComponentEditorVerbSeparator: TMenuItem;
PropertyEditorVerbSeparator: TMenuItem;
procedure RemovePropertyEditorMenuItems;
var
I: Integer;
begin
PropertyEditorVerbSeparator := nil;
for I := MainPopupMenu.Items.Count - 1 downto 0 do
if Pos(PropertyEditorMIPrefix, MainPopupMenu.Items[I].Name) = 1 then
MainPopupMenu.Items[I].Free;
end;
procedure AddPropertyEditorMenuItems(Editor: TPropertyEditor);
var
I, VerbCount: Integer;
Item: TMenuItem;
begin
VerbCount := Editor.GetVerbCount;
for I := 0 to VerbCount - 1 do
begin
Item := NewItem(Editor.GetVerb(I), 0, False, True,
@PropEditPopupClick, 0, PropertyEditorMIPrefix + IntToStr(i));
Editor.PrepareItem(I, Item);
Item.Tag:=I;
MainPopupMenu.Items.Insert(I, Item);
end;
// insert the separator
if VerbCount > 0 then
begin
PropertyEditorVerbSeparator := Menus.NewLine;
PropertyEditorVerbSeparator.Name := PropertyEditorMIPrefix + IntToStr(VerbCount);
MainPopupMenu.Items.Insert(VerbCount, PropertyEditorVerbSeparator);
end;
end;
procedure RemoveComponentEditorMenuItems;
var
I: Integer;
begin
ComponentEditorVerbSeparator:=nil;
for I := MainPopupMenu.Items.Count - 1 downto 0 do
if Pos(ComponentEditorMIPrefix, MainPopupMenu.Items[I].Name) = 1 then
MainPopupMenu.Items[I].Free;
end;
procedure AddComponentEditorMenuItems;
var
I, VerbCount: Integer;
Item: TMenuItem;
begin
VerbCount := ComponentEditor.GetVerbCount;
for I := 0 to VerbCount - 1 do
begin
Item := NewItem(ComponentEditor.GetVerb(I), 0, False, True,
@ComponentEditorVerbMenuItemClick, 0, ComponentEditorMIPrefix + IntToStr(i));
ComponentEditor.PrepareItem(I, Item);
Item.Tag:=I;
MainPopupMenu.Items.Insert(I, Item);
end;
// insert the separator
if VerbCount > 0 then
begin
ComponentEditorVerbSeparator := Menus.NewLine;
ComponentEditorVerbSeparator.Name := ComponentEditorMIPrefix + IntToStr(VerbCount);
MainPopupMenu.Items.Insert(VerbCount, ComponentEditorVerbSeparator);
end;
end;
procedure AddCollectionEditorMenuItems({%H-}ACollection: TCollection);
var
Item: TMenuItem;
begin
Item := NewItem(oisAddCollectionItem, 0, False, True,
@CollectionAddItem, 0, ComponentEditorMIPrefix+'0');
MainPopupMenu.Items.Insert(0, Item);
ComponentEditorVerbSeparator := NewLine;
ComponentEditorVerbSeparator.Name := ComponentEditorMIPrefix+'1';
MainPopupMenu.Items.Insert(1, ComponentEditorVerbSeparator);
end;
procedure AddZOrderMenuItems;
var
ZItem, Item: TMenuItem;
begin
ZItem := NewSubMenu(oisZOrder, 0, ComponentEditorMIPrefix+'ZOrder', [], True);
Item := NewItem(oisOrderMoveToFront, 0, False, True, @ZOrderItemClick, 0, '');
Item.ImageIndex := IDEImages.LoadImage('Order_move_front');
Item.Tag := 0;
ZItem.Add(Item);
Item := NewItem(oisOrderMoveToBack, 0, False, True, @ZOrderItemClick, 0, '');
Item.ImageIndex := IDEImages.LoadImage('Order_move_back');
Item.Tag := 1;
ZItem.Add(Item);
Item := NewItem(oisOrderForwardOne, 0, False, True, @ZOrderItemClick, 0, '');
Item.ImageIndex := IDEImages.LoadImage('Order_forward_one');
Item.Tag := 2;
ZItem.Add(Item);
Item := NewItem(oisOrderBackOne, 0, False, True, @ZOrderItemClick, 0, '');
Item.ImageIndex := IDEImages.LoadImage('Order_back_one');
Item.Tag := 3;
ZItem.Add(Item);
if ComponentEditorVerbSeparator <> nil then
MainPopupMenu.Items.Insert(ComponentEditorVerbSeparator.MenuIndex + 1, ZItem)
else
MainPopupMenu.Items.Insert(0, ZItem);
Item := NewLine;
Item.Name := ComponentEditorMIPrefix+'ZOrderSeparator';
MainPopupMenu.Items.Insert(ZItem.MenuIndex + 1, Item);
end;
var
b, AtLeastOneComp, CanChangeClass, HasParentCand: Boolean;
CurRow: TOIPropertyGridRow;
Persistent: TPersistent;
Page: TObjectInspectorPage;
begin
RemovePropertyEditorMenuItems;
RemoveComponentEditorMenuItems;
ShowHintsPopupMenuItem.Checked := PropertyGrid.ShowHint;
FStateOfHintsOnMainPopupMenu:=PropertyGrid.ShowHint;
for Page := Low(TObjectInspectorPage) to High(TObjectInspectorPage) do
if GridControl[Page] <> nil then
GridControl[Page].ShowHint := False;
Persistent := GetSelectedPersistent;
AtLeastOneComp := False;
CanChangeClass := False;
HasParentCand := False;
// show component editors only for component treeview
if MainPopupMenu.PopupComponent = ComponentTree then
begin
ComponentEditor := GetComponentEditorForSelection;
if ComponentEditor <> nil then
AddComponentEditorMenuItems
else
begin
// check if it is a TCollection
if Persistent is TCollection then
AddCollectionEditorMenuItems(TCollection(Persistent))
else if Persistent is TCollectionItem then
AddCollectionEditorMenuItems(TCollectionItem(Persistent).Collection);
end;
AtLeastOneComp := (Selection.Count > 0) and (Selection[0] is TComponent);
CanChangeClass := (Selection.Count = 1) and (Selection[0] is TComponent)
and (Selection[0] <> FPropertyEditorHook.LookupRoot);
// add Z-Order menu
if (Selection.Count = 1) and (Selection[0] is TControl) then
AddZOrderMenuItems;
// check existing of Change Parent candidates
if AtLeastOneComp then
HasParentCand := HasParentCandidates;
end;
CutPopupMenuItem.Visible := AtLeastOneComp;
CopyPopupMenuItem.Visible := AtLeastOneComp;
PastePopupMenuItem.Visible := AtLeastOneComp;
DeletePopupMenuItem.Visible := AtLeastOneComp;
OptionsSeparatorMenuItem2.Visible := AtLeastOneComp;
ChangeClassPopupmenuItem.Visible := CanChangeClass;
ChangeParentPopupmenuItem.Visible := HasParentCand;
OptionsSeparatorMenuItem3.Visible := CanChangeClass or HasParentCand;
// The editors can do menu actions, for example set defaults and constraints
CurRow := GetActivePropertyRow;
if (MainPopupMenu.PopupComponent is TOICustomPropertyGrid) then
begin
// popup menu of property grid
if CurRow<>nil then
AddPropertyEditorMenuItems(CurRow.Editor);
b := (Favorites <> nil) and ShowFavorites and (GetActivePropertyRow <> nil);
AddToFavoritesPopupMenuItem.Visible := b and
(GetActivePropertyGrid <> FavoriteGrid) and Assigned(OnAddToFavorites);
RemoveFromFavoritesPopupMenuItem.Visible := b and
(GetActivePropertyGrid = FavoriteGrid) and Assigned(OnRemoveFromFavorites);
UndoPropertyPopupMenuItem.Visible := True;
UndoPropertyPopupMenuItem.Enabled := (CurRow<>nil)
and (CurRow.Editor.GetVisualValue <> GetActivePropertyGrid.CurrentEditValue);
if CurRow=nil then begin
FindDeclarationPopupmenuItem.Visible := False;
end
else begin
FindDeclarationPopupmenuItem.Visible := true;
FindDeclarationPopupmenuItem.Caption := Format(oisJumpToDeclarationOf, [CurRow.Name]);
FindDeclarationPopupmenuItem.Hint := Format(oisJumpToDeclarationOf,
[CurRow.Editor.GetPropertyPath(0)]);
end;
ViewRestrictedPropertiesPopupMenuItem.Visible := True;
OptionsSeparatorMenuItem.Visible := True;
end
else
begin
// default popup menu
AddToFavoritesPopupMenuItem.Visible := False;
RemoveFromFavoritesPopupMenuItem.Visible := False;
UndoPropertyPopupMenuItem.Visible := False;
FindDeclarationPopupmenuItem.Visible := False;
ViewRestrictedPropertiesPopupMenuItem.Visible := False;
OptionsSeparatorMenuItem.Visible := False;
end;
//debugln(['TObjectInspectorDlg.OnMainPopupMenuPopup ',FindDeclarationPopupmenuItem.Visible]);
end;
procedure TObjectInspectorDlg.DoModified;
begin
if Assigned(FOnModified) then FOnModified(Self);
end;
procedure TObjectInspectorDlg.DoUpdateRestricted;
begin
if Assigned(FOnUpdateRestricted) then FOnUpdateRestricted(Self);
end;
procedure TObjectInspectorDlg.DoViewRestricted;
begin
if Assigned(FOnViewRestricted) then FOnViewRestricted(Self);
end;
procedure TObjectInspectorDlg.ChangeParentItemClick(Sender: TObject);
begin
if Selection.Count > 0 then
ChangeParent;
end;
procedure TObjectInspectorDlg.ComponentEditorVerbMenuItemClick(Sender: TObject);
var
Verb: integer;
AMenuItem: TMenuItem;
begin
if Sender is TMenuItem then
AMenuItem := TMenuItem(Sender)
else
Exit;
Verb := AMenuItem.Tag;
ComponentEditor.ExecuteVerb(Verb);
end;
procedure TObjectInspectorDlg.CollectionAddItem(Sender: TObject);
var
Persistent: TPersistent;
Collection: TCollection absolute Persistent;
ci: TCollectionItem;
begin
Persistent := GetSelectedPersistent;
if Persistent = nil then
Exit;
if Persistent is TCollectionItem then
Persistent := TCollectionItem(Persistent).Collection;
if not (Persistent is TCollection) then
Exit;
ci:=Collection.Add;
GlobalDesignHook.PersistentAdded(ci,false);
DoModified;
Selection.ForceUpdate := True;
try
SetSelection(Selection);
finally
Selection.ForceUpdate := False;
end;
end;
procedure TObjectInspectorDlg.ZOrderItemClick(Sender: TObject);
var
Control: TControl;
NewSelection: TPersistentSelectionList;
begin
if not (Sender is TMenuItem) then Exit;
if (Selection.Count <> 1) or
not (Selection[0] is TControl) then Exit;
Control := TControl(Selection[0]);
if Control.Parent = nil then Exit;
case TMenuItem(Sender).Tag of
0: Control.BringToFront;
1: Control.SendToBack;
2: Control.Parent.SetControlIndex(Control, Control.Parent.GetControlIndex(Control) + 1);
3: Control.Parent.SetControlIndex(Control, Control.Parent.GetControlIndex(Control) - 1);
end;
// Ensure controls that belong to a container are rearranged if required.
Control.Parent.ReAlign;
// Ensure the order of controls in the OI now reflects the new ZOrder
NewSelection := TPersistentSelectionList.Create;
try
NewSelection.ForceUpdate:=True;
NewSelection.Add(Control.Parent);
SetSelection(NewSelection);
NewSelection.Clear;
NewSelection.ForceUpdate:=True;
NewSelection.Add(Control);
SetSelection(NewSelection);
finally
NewSelection.Free;
end;
DoModified;
if Assigned(ComponentTree) then
ComponentTree.RebuildComponentNodes
end;
function TObjectInspectorDlg.GetComponentPanelHeight: integer;
begin
Result := ComponentPanel.Height
end;
function TObjectInspectorDlg.GetInfoBoxHeight: integer;
begin
Result := InfoPanel.Height;
end;
procedure TObjectInspectorDlg.SetEnableHookGetSelection(AValue: boolean);
begin
if FEnableHookGetSelection=AValue then Exit;
FEnableHookGetSelection:=AValue;
if PropertyEditorHook<>nil then
if EnableHookGetSelection then
FPropertyEditorHook.AddHandlerGetSelection(@HookGetSelection)
else
FPropertyEditorHook.RemoveHandlerGetSelection(@HookGetSelection)
end;
procedure TObjectInspectorDlg.SetFilter(const AValue: TTypeKinds);
begin
if FFilter=AValue then Exit;
FFilter:=AValue;
PropertyGrid.Filter := Filter - [tkMethod];
FavoriteGrid.Filter := Filter + [tkMethod];
RestrictedGrid.Filter := Filter + [tkMethod];
end;
procedure TObjectInspectorDlg.HookRefreshPropertyValues;
begin
RefreshPropertyValues;
end;
procedure TObjectInspectorDlg.ActivateGrid(Grid: TOICustomPropertyGrid);
begin
if Grid=PropertyGrid then NoteBook.PageIndex:=0
else if Grid=EventGrid then NoteBook.PageIndex:=1
else if Grid=FavoriteGrid then NoteBook.PageIndex:=2
else if Grid=RestrictedGrid then NoteBook.PageIndex:=3;
end;
procedure TObjectInspectorDlg.FocusGrid(Grid: TOICustomPropertyGrid);
var
Index: Integer;
begin
if Grid=nil then
Grid := GetActivePropertyGrid
else
ActivateGrid(Grid);
if Grid <> nil then
begin
Index := Grid.ItemIndex;
if Index < 0 then
Index := 0;
Grid.SetItemIndexAndFocus(Index);
end;
end;
function TObjectInspectorDlg.GetGridControl(Page: TObjectInspectorPage
): TOICustomPropertyGrid;
begin
case Page of
oipgpFavorite: Result:=FavoriteGrid;
oipgpEvents: Result:=EventGrid;
oipgpRestricted: Result:=RestrictedGrid;
else Result:=PropertyGrid;
end;
end;
procedure TObjectInspectorDlg.SetComponentEditor(const AValue: TBaseComponentEditor);
begin
if FComponentEditor <> AValue then
begin
FComponentEditor.Free;
FComponentEditor := AValue;
end;
end;
procedure TObjectInspectorDlg.SetFavorites(const AValue: TOIFavoriteProperties);
begin
//debugln('TObjectInspectorDlg.SetFavorites ',dbgsName(Self));
if FFavorites=AValue then exit;
FFavorites:=AValue;
FavoriteGrid.Favorites:=FFavorites;
end;
procedure TObjectInspectorDlg.ComponentTreeGetNodeImageIndex(
APersistent: TPersistent; var AIndex: integer);
begin
//ask TMediator
if assigned(FOnNodeGetImageIndex) then
FOnNodeGetImageIndex(APersistent, AIndex);
end;
{ TCustomPropertiesGrid }
function TCustomPropertiesGrid.GetTIObject: TPersistent;
begin
if PropertyEditorHook<>nil then
Result:=PropertyEditorHook.LookupRoot
else
Result:=Nil;
end;
procedure TCustomPropertiesGrid.SetAutoFreeHook(const AValue: boolean);
begin
if FAutoFreeHook=AValue then exit;
FAutoFreeHook:=AValue;
end;
procedure TCustomPropertiesGrid.SetTIObject(const AValue: TPersistent);
var
NewSelection: TPersistentSelectionList;
begin
if (TIObject=AValue) then begin
if ((AValue<>nil) and (Selection.Count=1) and (Selection[0]=AValue))
or (AValue=nil) then
exit;
end;
if SaveOnChangeTIObject then
SaveChanges;
if PropertyEditorHook=nil then
begin
fAutoFreeHook:=true;
PropertyEditorHook:=TPropertyEditorHook.Create(Self);
end;
PropertyEditorHook.LookupRoot:=AValue;
if (AValue=nil) or (Selection.Count<>1) or (Selection[0]<>AValue) then
begin
NewSelection:=TPersistentSelectionList.Create;
try
if AValue<>nil then
NewSelection.Add(AValue);
Selection:=NewSelection;
finally
NewSelection.Free;
end;
end;
end;
constructor TCustomPropertiesGrid.Create(TheOwner: TComponent);
var
Hook: TPropertyEditorHook;
begin
Hook:=TPropertyEditorHook.Create(Self);
FAutoFreeHook:=true;
FSaveOnChangeTIObject:=true;
CreateWithParams(TheOwner,Hook,AllTypeKinds,0);
end;
destructor TCustomPropertiesGrid.Destroy;
begin
if FAutoFreeHook then
FreeAndNil(FPropertyEditorHook);
inherited Destroy;
end;
end.
|