1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768 4769 4770 4771 4772 4773 4774 4775 4776 4777 4778 4779 4780 4781 4782 4783 4784 4785 4786 4787 4788 4789 4790 4791 4792 4793 4794 4795 4796 4797 4798 4799 4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 4822 4823 4824 4825 4826 4827 4828 4829 4830 4831 4832 4833 4834 4835 4836 4837 4838 4839 4840 4841 4842 4843 4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 4854 4855 4856 4857 4858 4859 4860 4861 4862 4863 4864 4865 4866 4867 4868 4869 4870 4871 4872 4873 4874 4875 4876 4877 4878 4879 4880 4881 4882 4883 4884 4885 4886 4887 4888 4889 4890 4891 4892 4893 4894 4895 4896 4897 4898 4899 4900 4901 4902 4903 4904 4905 4906 4907 4908 4909 4910 4911 4912 4913 4914 4915 4916 4917 4918 4919 4920 4921 4922 4923 4924 4925 4926 4927 4928 4929 4930 4931 4932 4933 4934 4935 4936 4937 4938 4939 4940 4941 4942 4943 4944 4945 4946 4947 4948 4949 4950 4951 4952 4953 4954 4955 4956 4957 4958 4959 4960 4961 4962 4963 4964 4965 4966 4967 4968 4969 4970 4971 4972 4973 4974 4975 4976 4977 4978 4979 4980 4981 4982 4983 4984 4985 4986 4987 4988 4989 4990 4991 4992 4993 4994 4995 4996 4997 4998 4999 5000 5001 5002 5003 5004 5005 5006 5007 5008 5009 5010 5011 5012 5013 5014 5015 5016 5017 5018 5019 5020 5021 5022 5023 5024 5025 5026 5027 5028 5029 5030 5031 5032 5033 5034 5035 5036 5037 5038 5039 5040 5041 5042 5043 5044 5045 5046 5047 5048 5049 5050 5051 5052 5053 5054 5055 5056 5057 5058 5059 5060 5061 5062 5063 5064 5065 5066 5067 5068 5069 5070 5071 5072 5073 5074 5075 5076 5077 5078 5079 5080 5081 5082 5083 5084 5085 5086 5087 5088 5089 5090 5091 5092 5093 5094 5095 5096 5097 5098 5099 5100 5101 5102 5103 5104 5105 5106 5107 5108 5109 5110 5111 5112 5113 5114 5115 5116 5117 5118 5119 5120 5121 5122 5123 5124 5125 5126 5127 5128 5129 5130 5131 5132 5133 5134 5135 5136 5137 5138 5139 5140 5141 5142 5143 5144 5145 5146 5147 5148 5149 5150 5151 5152 5153 5154 5155 5156 5157 5158 5159 5160 5161 5162 5163 5164 5165 5166 5167 5168 5169 5170 5171 5172 5173 5174 5175 5176 5177 5178 5179 5180 5181 5182 5183 5184 5185 5186 5187 5188 5189 5190 5191 5192 5193 5194 5195 5196 5197 5198 5199 5200 5201 5202 5203 5204 5205 5206 5207 5208 5209 5210 5211 5212 5213 5214 5215 5216 5217 5218 5219 5220 5221 5222 5223 5224 5225 5226 5227 5228 5229 5230 5231 5232 5233 5234 5235 5236 5237 5238 5239 5240 5241 5242 5243 5244 5245 5246 5247 5248 5249 5250 5251 5252 5253 5254 5255 5256 5257 5258 5259 5260 5261 5262 5263 5264 5265 5266 5267 5268 5269 5270 5271 5272 5273 5274 5275 5276 5277 5278 5279 5280 5281 5282 5283 5284 5285 5286 5287 5288 5289 5290 5291 5292 5293 5294 5295 5296 5297 5298 5299 5300 5301 5302 5303 5304 5305 5306 5307 5308 5309 5310 5311 5312 5313 5314 5315 5316 5317 5318 5319 5320 5321 5322 5323 5324 5325 5326 5327 5328 5329 5330 5331 5332 5333 5334 5335 5336 5337 5338 5339 5340 5341 5342 5343 5344 5345 5346 5347 5348 5349 5350 5351 5352 5353 5354 5355 5356 5357 5358 5359 5360 5361 5362 5363 5364 5365 5366 5367 5368 5369 5370 5371 5372 5373 5374 5375 5376 5377 5378 5379 5380 5381 5382 5383 5384 5385 5386 5387 5388 5389 5390 5391 5392 5393 5394 5395 5396 5397 5398 5399 5400 5401 5402 5403 5404 5405 5406 5407 5408 5409 5410 5411 5412 5413 5414 5415 5416 5417 5418 5419 5420 5421 5422 5423 5424 5425 5426 5427 5428 5429 5430 5431 5432 5433 5434 5435 5436 5437 5438 5439 5440 5441 5442 5443 5444 5445 5446 5447 5448 5449 5450 5451 5452 5453 5454 5455 5456 5457 5458 5459 5460 5461 5462 5463 5464 5465 5466 5467 5468 5469 5470 5471 5472 5473 5474 5475 5476 5477 5478 5479 5480 5481 5482 5483 5484 5485 5486 5487 5488 5489 5490 5491 5492 5493 5494 5495 5496 5497 5498 5499 5500 5501 5502 5503 5504 5505 5506 5507 5508 5509 5510 5511 5512 5513 5514 5515 5516 5517 5518 5519 5520 5521 5522 5523 5524 5525 5526 5527 5528 5529 5530 5531 5532 5533 5534 5535 5536 5537 5538 5539 5540 5541 5542 5543 5544 5545 5546 5547 5548 5549 5550 5551 5552 5553 5554 5555 5556 5557 5558 5559 5560 5561 5562 5563 5564 5565 5566 5567 5568 5569 5570 5571 5572 5573 5574 5575 5576 5577 5578 5579 5580 5581 5582 5583 5584 5585 5586 5587 5588 5589 5590 5591 5592 5593 5594 5595 5596 5597 5598 5599 5600 5601 5602 5603 5604 5605 5606 5607 5608 5609 5610 5611 5612 5613 5614 5615 5616 5617 5618 5619 5620 5621 5622 5623 5624 5625 5626 5627 5628 5629 5630 5631 5632 5633 5634 5635 5636 5637 5638 5639 5640 5641 5642 5643 5644 5645 5646 5647 5648 5649 5650 5651 5652 5653 5654 5655 5656 5657 5658 5659 5660 5661 5662 5663 5664 5665 5666 5667 5668 5669 5670 5671 5672 5673 5674 5675 5676 5677 5678 5679 5680 5681 5682 5683 5684 5685 5686 5687 5688 5689 5690 5691 5692 5693 5694 5695 5696 5697 5698 5699 5700 5701 5702 5703 5704 5705 5706 5707 5708 5709 5710 5711 5712 5713 5714 5715 5716 5717 5718 5719 5720 5721 5722 5723 5724 5725 5726 5727 5728 5729 5730 5731 5732 5733 5734 5735 5736 5737 5738 5739 5740 5741 5742 5743 5744 5745 5746 5747 5748 5749 5750 5751 5752 5753 5754 5755 5756 5757 5758 5759 5760 5761 5762 5763 5764 5765 5766 5767 5768 5769 5770 5771 5772 5773 5774 5775 5776 5777 5778 5779 5780 5781 5782 5783 5784 5785 5786 5787 5788 5789 5790 5791 5792 5793 5794 5795 5796 5797 5798 5799 5800 5801 5802 5803 5804 5805 5806 5807 5808 5809 5810 5811 5812 5813 5814 5815 5816 5817 5818 5819 5820 5821 5822 5823 5824 5825 5826 5827 5828 5829 5830 5831 5832 5833 5834 5835 5836 5837 5838 5839 5840 5841 5842 5843 5844 5845 5846 5847 5848 5849 5850 5851 5852 5853 5854 5855 5856 5857 5858 5859 5860 5861 5862 5863 5864 5865 5866 5867 5868 5869 5870 5871 5872 5873 5874 5875 5876 5877 5878 5879 5880 5881 5882 5883 5884 5885 5886 5887 5888 5889 5890 5891 5892 5893 5894 5895 5896 5897 5898 5899 5900 5901 5902 5903 5904 5905 5906 5907 5908 5909 5910 5911 5912 5913 5914 5915 5916 5917 5918 5919 5920 5921 5922 5923 5924 5925 5926 5927 5928 5929 5930 5931 5932 5933 5934 5935 5936 5937 5938 5939 5940 5941 5942 5943 5944 5945 5946 5947 5948 5949 5950 5951 5952 5953 5954 5955 5956 5957 5958 5959 5960 5961 5962 5963 5964 5965 5966 5967 5968 5969 5970 5971 5972 5973 5974 5975 5976 5977 5978 5979 5980 5981 5982 5983 5984 5985 5986 5987 5988 5989 5990 5991 5992 5993 5994 5995 5996 5997 5998 5999 6000 6001 6002 6003 6004 6005 6006 6007 6008 6009 6010 6011 6012 6013 6014 6015 6016 6017 6018 6019 6020 6021 6022 6023 6024 6025 6026 6027 6028 6029 6030 6031 6032 6033 6034 6035 6036 6037 6038 6039 6040 6041 6042 6043 6044 6045 6046 6047 6048 6049 6050 6051 6052 6053 6054 6055 6056 6057 6058 6059 6060 6061 6062 6063 6064 6065 6066 6067 6068 6069 6070 6071 6072 6073 6074 6075 6076 6077 6078 6079 6080 6081 6082 6083 6084 6085 6086 6087 6088 6089 6090 6091 6092 6093 6094 6095 6096 6097 6098 6099 6100 6101 6102 6103 6104 6105 6106 6107 6108 6109 6110 6111 6112 6113 6114 6115 6116 6117 6118 6119 6120 6121 6122 6123 6124 6125 6126 6127 6128 6129 6130 6131 6132 6133 6134 6135 6136 6137 6138 6139 6140 6141 6142 6143 6144 6145 6146 6147 6148 6149 6150 6151 6152 6153 6154 6155 6156 6157 6158 6159 6160 6161 6162 6163 6164 6165 6166 6167 6168 6169 6170 6171 6172 6173 6174 6175 6176 6177 6178 6179 6180 6181 6182 6183 6184 6185 6186 6187 6188 6189 6190 6191 6192 6193 6194 6195 6196 6197 6198 6199 6200 6201 6202 6203 6204 6205 6206 6207 6208 6209 6210 6211 6212 6213 6214 6215 6216 6217 6218 6219 6220 6221 6222 6223 6224 6225 6226 6227 6228 6229 6230 6231 6232 6233 6234 6235 6236 6237 6238 6239 6240 6241 6242 6243 6244 6245 6246 6247 6248 6249 6250 6251 6252 6253 6254 6255 6256 6257 6258 6259 6260 6261 6262 6263 6264 6265 6266 6267 6268 6269 6270 6271 6272 6273 6274 6275 6276 6277 6278 6279 6280 6281 6282 6283 6284 6285 6286 6287 6288 6289 6290 6291 6292 6293 6294 6295 6296 6297 6298 6299 6300 6301 6302 6303 6304 6305 6306 6307 6308 6309 6310 6311 6312 6313 6314 6315 6316 6317 6318 6319 6320 6321 6322 6323 6324 6325 6326 6327 6328 6329 6330 6331 6332 6333 6334 6335 6336 6337 6338 6339 6340 6341 6342 6343 6344 6345 6346 6347 6348 6349 6350 6351 6352 6353 6354 6355 6356 6357 6358 6359 6360 6361 6362 6363 6364 6365 6366 6367 6368 6369 6370 6371 6372 6373 6374 6375 6376 6377 6378 6379 6380 6381 6382 6383 6384 6385 6386 6387 6388 6389 6390 6391 6392 6393 6394 6395 6396 6397 6398 6399 6400 6401 6402 6403 6404 6405 6406 6407 6408 6409 6410 6411 6412 6413 6414 6415 6416 6417 6418 6419 6420 6421 6422 6423 6424 6425 6426 6427 6428 6429 6430 6431 6432 6433 6434 6435 6436 6437 6438 6439 6440 6441 6442 6443 6444 6445 6446 6447 6448 6449 6450 6451 6452 6453 6454 6455 6456 6457 6458 6459 6460 6461 6462 6463 6464 6465 6466 6467 6468 6469 6470 6471 6472 6473 6474 6475 6476 6477 6478 6479 6480 6481 6482 6483 6484 6485 6486 6487 6488 6489 6490 6491 6492 6493 6494 6495 6496 6497 6498 6499 6500 6501 6502 6503 6504 6505 6506 6507 6508 6509 6510 6511 6512 6513 6514 6515 6516 6517 6518 6519 6520 6521 6522 6523 6524 6525 6526 6527 6528 6529 6530 6531 6532 6533 6534 6535 6536 6537 6538 6539 6540 6541 6542 6543 6544 6545 6546 6547 6548 6549 6550 6551 6552 6553 6554 6555 6556 6557 6558 6559 6560 6561 6562 6563 6564 6565 6566 6567 6568 6569 6570 6571 6572 6573 6574 6575 6576 6577 6578 6579 6580 6581 6582 6583 6584 6585 6586 6587 6588 6589 6590 6591 6592 6593 6594 6595 6596 6597 6598 6599 6600 6601 6602 6603 6604 6605 6606 6607 6608 6609 6610 6611 6612 6613 6614 6615 6616 6617 6618 6619 6620 6621 6622 6623 6624 6625 6626 6627 6628 6629 6630 6631 6632 6633 6634 6635 6636 6637 6638 6639 6640 6641 6642 6643 6644 6645 6646 6647 6648 6649 6650 6651 6652 6653 6654 6655 6656 6657 6658 6659 6660 6661 6662 6663 6664 6665 6666 6667 6668 6669 6670 6671 6672 6673 6674 6675 6676 6677 6678 6679 6680 6681 6682 6683 6684 6685 6686 6687 6688 6689 6690 6691 6692 6693 6694 6695 6696 6697 6698 6699 6700 6701 6702 6703 6704 6705 6706 6707 6708 6709 6710 6711 6712 6713 6714 6715 6716 6717 6718 6719 6720 6721 6722 6723 6724 6725 6726 6727 6728 6729 6730 6731 6732 6733 6734 6735 6736 6737 6738 6739 6740 6741 6742 6743 6744 6745 6746 6747 6748 6749 6750 6751 6752 6753 6754 6755 6756 6757 6758 6759 6760 6761 6762 6763 6764 6765 6766 6767 6768 6769 6770 6771 6772 6773 6774 6775 6776 6777 6778 6779 6780 6781 6782 6783 6784 6785 6786 6787 6788 6789 6790 6791 6792 6793 6794 6795 6796 6797 6798 6799 6800 6801 6802 6803 6804 6805 6806 6807 6808 6809 6810 6811 6812 6813 6814 6815 6816 6817 6818 6819 6820 6821 6822 6823 6824 6825 6826 6827 6828 6829 6830 6831 6832 6833 6834 6835 6836 6837 6838 6839 6840 6841 6842 6843 6844 6845 6846 6847 6848 6849 6850 6851 6852 6853 6854 6855 6856 6857 6858 6859 6860 6861 6862 6863 6864 6865 6866 6867 6868 6869 6870 6871 6872 6873 6874 6875 6876 6877 6878 6879 6880 6881 6882 6883 6884 6885 6886 6887 6888 6889 6890 6891 6892 6893 6894 6895 6896 6897 6898 6899 6900 6901 6902 6903 6904 6905 6906 6907 6908 6909 6910 6911 6912 6913 6914 6915 6916 6917 6918 6919 6920 6921 6922 6923 6924 6925 6926 6927 6928 6929 6930 6931 6932 6933 6934 6935 6936 6937 6938 6939 6940 6941 6942 6943 6944 6945 6946 6947 6948 6949 6950 6951 6952 6953 6954 6955 6956 6957 6958 6959 6960 6961 6962 6963 6964 6965 6966 6967 6968 6969 6970 6971 6972 6973 6974 6975 6976 6977 6978 6979 6980 6981 6982 6983 6984 6985 6986 6987 6988 6989 6990 6991 6992 6993 6994 6995 6996 6997 6998 6999 7000 7001 7002 7003 7004 7005 7006 7007 7008 7009 7010 7011 7012 7013 7014 7015 7016 7017 7018 7019 7020 7021 7022 7023 7024 7025 7026 7027 7028 7029 7030 7031 7032 7033 7034 7035 7036 7037 7038 7039 7040 7041 7042 7043 7044 7045 7046 7047 7048 7049 7050 7051 7052 7053 7054 7055 7056 7057 7058 7059 7060 7061 7062 7063 7064 7065 7066 7067 7068 7069 7070 7071 7072 7073 7074 7075 7076 7077 7078 7079 7080 7081 7082 7083 7084 7085 7086 7087 7088 7089 7090 7091 7092 7093 7094 7095 7096 7097 7098 7099 7100 7101 7102 7103 7104 7105 7106 7107 7108 7109 7110 7111 7112 7113 7114 7115 7116 7117 7118 7119 7120 7121 7122 7123 7124 7125 7126 7127 7128 7129 7130 7131 7132 7133 7134 7135 7136 7137 7138 7139 7140 7141 7142 7143 7144 7145 7146 7147 7148 7149 7150 7151 7152 7153 7154 7155 7156 7157 7158 7159 7160 7161 7162 7163 7164 7165 7166 7167 7168 7169 7170 7171 7172 7173 7174 7175 7176 7177 7178 7179 7180 7181 7182 7183 7184 7185 7186 7187 7188 7189 7190 7191 7192 7193 7194 7195 7196 7197 7198 7199 7200 7201 7202 7203 7204 7205 7206 7207 7208 7209 7210 7211 7212 7213 7214 7215 7216 7217 7218 7219 7220 7221 7222 7223 7224 7225 7226 7227 7228 7229 7230 7231 7232 7233 7234 7235 7236 7237 7238 7239 7240 7241 7242 7243 7244 7245 7246 7247 7248 7249 7250 7251 7252 7253 7254 7255 7256 7257 7258 7259 7260 7261 7262 7263 7264 7265 7266 7267 7268 7269 7270 7271 7272 7273 7274 7275 7276 7277 7278 7279 7280 7281 7282 7283 7284 7285 7286 7287 7288 7289 7290 7291 7292 7293 7294 7295 7296 7297 7298 7299 7300 7301 7302 7303 7304 7305 7306 7307 7308 7309 7310 7311 7312 7313 7314 7315 7316 7317 7318 7319 7320 7321 7322 7323 7324 7325 7326 7327 7328 7329 7330 7331 7332 7333 7334 7335 7336 7337 7338 7339 7340 7341 7342 7343 7344 7345 7346 7347 7348 7349 7350 7351 7352 7353 7354 7355 7356 7357 7358 7359 7360 7361 7362 7363 7364 7365 7366 7367 7368 7369 7370 7371 7372 7373 7374 7375 7376 7377 7378 7379 7380 7381 7382 7383 7384 7385 7386 7387 7388 7389 7390 7391 7392 7393 7394 7395 7396 7397 7398 7399 7400 7401 7402 7403 7404 7405 7406 7407 7408 7409 7410 7411 7412 7413 7414 7415 7416 7417 7418 7419 7420 7421 7422 7423 7424 7425 7426 7427 7428 7429 7430 7431 7432 7433 7434 7435 7436 7437 7438 7439 7440 7441 7442 7443 7444 7445 7446 7447 7448 7449 7450 7451 7452 7453 7454 7455 7456 7457 7458 7459 7460 7461 7462 7463 7464 7465 7466 7467 7468 7469 7470 7471 7472 7473 7474 7475 7476 7477 7478 7479 7480 7481 7482 7483 7484 7485 7486 7487 7488 7489 7490 7491 7492 7493 7494 7495 7496 7497 7498 7499 7500 7501 7502 7503 7504 7505 7506 7507 7508 7509 7510 7511 7512 7513 7514 7515 7516 7517 7518 7519 7520 7521 7522 7523 7524 7525 7526 7527 7528 7529 7530 7531 7532 7533 7534 7535 7536 7537 7538 7539 7540 7541 7542 7543 7544 7545 7546 7547 7548 7549 7550 7551 7552 7553 7554 7555 7556 7557 7558 7559 7560 7561 7562 7563 7564 7565 7566 7567 7568 7569 7570 7571 7572 7573 7574 7575 7576 7577 7578 7579 7580 7581 7582 7583 7584 7585 7586 7587 7588 7589 7590 7591 7592 7593 7594 7595 7596 7597 7598 7599 7600 7601 7602 7603 7604 7605 7606 7607 7608 7609 7610 7611 7612 7613 7614 7615 7616 7617 7618 7619 7620 7621 7622 7623 7624 7625 7626 7627 7628 7629 7630 7631 7632 7633 7634 7635 7636 7637 7638 7639 7640 7641 7642 7643 7644 7645 7646 7647 7648 7649 7650 7651 7652 7653 7654 7655 7656 7657 7658 7659 7660 7661 7662 7663 7664 7665 7666 7667 7668 7669 7670 7671 7672 7673 7674 7675 7676 7677 7678 7679 7680 7681 7682 7683 7684 7685 7686 7687 7688 7689 7690 7691 7692 7693 7694 7695 7696 7697 7698 7699 7700 7701 7702 7703 7704 7705 7706 7707 7708 7709 7710 7711 7712 7713 7714 7715 7716 7717 7718 7719 7720 7721 7722 7723 7724 7725 7726 7727 7728 7729 7730 7731 7732 7733 7734 7735 7736 7737 7738 7739 7740 7741 7742 7743 7744 7745 7746 7747 7748 7749 7750 7751 7752 7753 7754 7755 7756 7757 7758 7759 7760 7761 7762 7763 7764 7765 7766 7767 7768 7769 7770 7771 7772 7773 7774 7775 7776 7777 7778 7779 7780 7781 7782 7783 7784 7785 7786 7787 7788 7789 7790 7791 7792 7793 7794 7795 7796 7797 7798 7799 7800 7801 7802 7803 7804 7805 7806 7807 7808 7809 7810 7811 7812 7813 7814 7815 7816 7817 7818 7819 7820 7821 7822 7823 7824 7825 7826 7827 7828 7829 7830 7831 7832 7833 7834 7835 7836 7837 7838 7839 7840 7841 7842 7843 7844 7845 7846 7847 7848 7849 7850 7851 7852 7853 7854 7855 7856 7857 7858 7859 7860 7861 7862 7863 7864 7865 7866 7867 7868 7869 7870 7871 7872 7873 7874 7875 7876 7877 7878 7879 7880 7881 7882 7883 7884 7885 7886 7887 7888 7889 7890 7891 7892 7893 7894 7895 7896 7897 7898 7899 7900 7901 7902 7903 7904 7905 7906 7907 7908 7909 7910 7911 7912 7913 7914 7915 7916 7917 7918 7919 7920 7921 7922 7923 7924 7925 7926 7927 7928 7929 7930 7931 7932 7933 7934 7935 7936 7937 7938 7939 7940 7941 7942 7943 7944 7945 7946 7947 7948 7949 7950 7951 7952 7953 7954 7955 7956 7957 7958 7959 7960 7961 7962 7963 7964 7965 7966 7967 7968 7969 7970 7971 7972 7973 7974 7975 7976 7977 7978 7979 7980 7981 7982 7983 7984 7985 7986 7987 7988 7989 7990 7991 7992 7993 7994 7995 7996 7997 7998 7999 8000 8001 8002 8003 8004 8005 8006 8007 8008 8009 8010 8011 8012 8013 8014 8015 8016 8017 8018 8019 8020 8021 8022 8023 8024 8025 8026 8027 8028 8029 8030 8031 8032 8033 8034 8035 8036 8037 8038 8039 8040 8041 8042 8043 8044 8045 8046 8047 8048 8049 8050 8051 8052 8053 8054 8055 8056 8057 8058 8059 8060 8061 8062 8063 8064 8065 8066 8067 8068 8069 8070 8071 8072 8073 8074 8075 8076 8077 8078 8079 8080 8081 8082 8083 8084 8085 8086 8087 8088 8089 8090 8091 8092 8093 8094 8095 8096 8097 8098 8099 8100 8101 8102 8103 8104 8105 8106 8107 8108 8109 8110 8111 8112 8113 8114 8115 8116 8117 8118 8119 8120 8121 8122 8123 8124 8125 8126 8127 8128 8129 8130 8131 8132 8133 8134 8135 8136 8137 8138 8139 8140 8141 8142 8143 8144 8145 8146 8147 8148 8149 8150 8151 8152 8153 8154 8155 8156 8157 8158 8159 8160 8161 8162 8163 8164 8165 8166 8167 8168 8169 8170 8171 8172 8173 8174 8175 8176 8177 8178 8179 8180 8181 8182 8183 8184 8185 8186 8187 8188 8189 8190 8191 8192 8193 8194 8195 8196 8197 8198 8199 8200 8201 8202 8203 8204 8205 8206 8207 8208 8209 8210 8211 8212 8213 8214 8215 8216 8217 8218 8219 8220 8221 8222 8223 8224 8225 8226 8227 8228 8229 8230 8231 8232 8233 8234 8235 8236 8237 8238 8239 8240 8241 8242 8243 8244 8245 8246 8247 8248 8249 8250 8251 8252 8253 8254 8255 8256 8257 8258 8259 8260 8261 8262 8263 8264 8265 8266 8267 8268 8269 8270 8271 8272 8273 8274 8275 8276 8277 8278 8279 8280 8281 8282 8283 8284 8285 8286 8287 8288 8289 8290 8291 8292 8293 8294 8295 8296 8297 8298 8299 8300 8301 8302 8303 8304 8305 8306 8307 8308 8309 8310 8311 8312 8313 8314 8315 8316 8317 8318 8319 8320 8321 8322 8323 8324 8325 8326 8327 8328 8329 8330 8331 8332 8333 8334 8335 8336 8337 8338 8339 8340 8341 8342 8343 8344 8345 8346 8347 8348 8349 8350 8351 8352 8353 8354 8355 8356 8357 8358 8359 8360 8361 8362 8363 8364 8365 8366 8367 8368 8369 8370 8371 8372 8373 8374 8375 8376 8377 8378 8379 8380 8381 8382 8383 8384 8385 8386 8387 8388 8389 8390 8391 8392 8393 8394 8395 8396 8397 8398 8399 8400 8401 8402 8403 8404 8405 8406 8407 8408 8409 8410 8411 8412 8413 8414 8415 8416 8417 8418 8419 8420 8421 8422 8423 8424 8425 8426 8427 8428 8429 8430 8431 8432 8433 8434 8435 8436 8437 8438 8439 8440 8441 8442 8443 8444 8445 8446 8447 8448 8449 8450 8451 8452 8453 8454 8455 8456 8457 8458 8459 8460 8461 8462 8463 8464 8465 8466 8467 8468 8469 8470 8471 8472 8473 8474 8475 8476 8477 8478 8479 8480 8481 8482 8483 8484 8485 8486 8487 8488 8489 8490 8491 8492 8493 8494 8495 8496 8497 8498 8499 8500 8501 8502 8503 8504 8505 8506 8507 8508 8509 8510 8511 8512 8513 8514 8515 8516 8517 8518 8519 8520 8521 8522 8523 8524 8525 8526 8527 8528 8529 8530 8531 8532 8533 8534 8535 8536 8537 8538 8539 8540 8541 8542 8543 8544 8545 8546 8547 8548 8549 8550 8551 8552 8553 8554 8555 8556 8557 8558 8559 8560 8561 8562 8563 8564 8565 8566 8567 8568 8569 8570 8571 8572 8573 8574 8575 8576 8577 8578 8579 8580 8581 8582 8583 8584 8585 8586 8587 8588 8589 8590 8591 8592 8593 8594 8595 8596 8597 8598 8599 8600 8601 8602 8603 8604 8605 8606 8607 8608 8609 8610 8611 8612 8613 8614 8615 8616 8617 8618 8619 8620 8621 8622 8623 8624 8625 8626 8627 8628 8629 8630 8631 8632 8633 8634 8635 8636 8637 8638 8639 8640 8641 8642 8643 8644 8645 8646 8647 8648 8649 8650 8651 8652 8653 8654 8655 8656 8657 8658 8659 8660 8661 8662 8663 8664 8665 8666 8667 8668 8669 8670 8671 8672 8673 8674 8675 8676 8677 8678 8679 8680 8681 8682 8683 8684 8685 8686 8687 8688 8689 8690 8691 8692 8693 8694 8695 8696 8697 8698 8699 8700 8701 8702 8703 8704 8705 8706 8707 8708 8709 8710 8711 8712 8713 8714 8715 8716 8717 8718 8719 8720 8721 8722 8723 8724 8725 8726 8727 8728 8729 8730 8731 8732 8733 8734 8735 8736 8737 8738 8739 8740 8741 8742 8743 8744 8745 8746 8747 8748 8749 8750 8751 8752 8753 8754 8755 8756 8757 8758 8759 8760 8761 8762 8763 8764 8765 8766 8767 8768 8769 8770 8771 8772 8773 8774 8775 8776 8777 8778 8779 8780 8781 8782 8783 8784 8785 8786 8787 8788 8789 8790 8791 8792 8793 8794 8795 8796 8797 8798 8799 8800 8801 8802 8803 8804 8805 8806 8807 8808 8809 8810 8811 8812 8813 8814 8815 8816 8817 8818 8819 8820 8821 8822 8823 8824 8825 8826 8827 8828 8829 8830 8831 8832 8833 8834 8835 8836 8837 8838 8839 8840 8841 8842 8843 8844 8845 8846 8847 8848 8849 8850 8851 8852 8853 8854 8855 8856 8857 8858 8859 8860 8861 8862 8863 8864 8865 8866 8867 8868 8869 8870 8871 8872 8873 8874 8875 8876 8877 8878 8879 8880 8881 8882 8883 8884 8885 8886 8887 8888 8889 8890 8891 8892 8893 8894 8895 8896 8897 8898 8899 8900 8901 8902 8903 8904 8905 8906 8907 8908 8909 8910 8911 8912 8913 8914 8915 8916 8917 8918 8919 8920 8921 8922 8923 8924 8925 8926 8927 8928 8929 8930 8931 8932 8933 8934 8935 8936 8937 8938 8939 8940 8941 8942 8943 8944 8945 8946 8947 8948 8949 8950 8951 8952 8953 8954 8955 8956 8957 8958 8959 8960 8961 8962 8963 8964 8965 8966 8967 8968 8969 8970 8971 8972 8973 8974 8975 8976 8977 8978 8979 8980 8981 8982 8983 8984 8985 8986 8987 8988 8989 8990 8991 8992 8993 8994 8995 8996 8997 8998 8999 9000 9001 9002 9003 9004 9005 9006 9007 9008 9009 9010 9011 9012 9013 9014 9015 9016 9017 9018 9019 9020 9021 9022 9023 9024 9025 9026 9027 9028 9029 9030 9031 9032 9033 9034 9035 9036 9037 9038 9039 9040 9041 9042 9043 9044 9045 9046 9047 9048 9049 9050 9051 9052 9053 9054 9055 9056 9057 9058 9059 9060 9061 9062 9063 9064 9065 9066 9067 9068 9069 9070 9071 9072 9073 9074 9075 9076 9077 9078 9079 9080 9081 9082 9083 9084 9085 9086 9087 9088 9089 9090 9091 9092 9093 9094 9095 9096 9097 9098 9099 9100 9101 9102 9103 9104 9105 9106 9107 9108 9109 9110 9111 9112 9113 9114 9115 9116 9117 9118 9119 9120 9121 9122 9123 9124 9125 9126 9127 9128 9129 9130 9131 9132 9133 9134 9135 9136 9137 9138 9139 9140 9141 9142 9143 9144 9145 9146 9147 9148 9149 9150 9151 9152 9153 9154 9155 9156 9157 9158 9159 9160 9161 9162 9163 9164 9165 9166 9167 9168 9169 9170 9171 9172 9173 9174 9175 9176 9177 9178 9179 9180 9181 9182 9183 9184 9185 9186 9187 9188 9189 9190 9191 9192 9193 9194 9195 9196 9197 9198 9199 9200 9201 9202 9203 9204 9205 9206 9207 9208 9209 9210 9211 9212 9213 9214 9215 9216 9217 9218 9219 9220 9221 9222 9223 9224 9225 9226 9227 9228 9229 9230 9231 9232 9233 9234 9235 9236 9237 9238 9239 9240 9241 9242 9243 9244 9245 9246 9247 9248 9249 9250 9251 9252 9253 9254 9255 9256 9257 9258 9259 9260 9261 9262 9263 9264 9265 9266 9267 9268 9269 9270 9271 9272 9273 9274 9275 9276 9277 9278 9279 9280 9281 9282 9283 9284 9285 9286 9287 9288 9289 9290 9291 9292 9293 9294 9295 9296 9297 9298 9299 9300 9301 9302 9303 9304 9305 9306 9307 9308 9309 9310 9311 9312 9313 9314 9315 9316 9317 9318 9319 9320 9321 9322 9323 9324 9325 9326 9327 9328 9329 9330 9331 9332 9333 9334 9335 9336 9337 9338 9339 9340 9341 9342 9343 9344 9345 9346 9347 9348 9349 9350 9351 9352 9353 9354 9355 9356 9357 9358 9359 9360 9361 9362 9363 9364 9365 9366 9367 9368 9369 9370 9371 9372 9373 9374 9375 9376 9377 9378 9379 9380 9381 9382 9383 9384 9385 9386 9387 9388 9389 9390 9391 9392 9393 9394 9395 9396 9397 9398 9399 9400 9401 9402 9403 9404 9405 9406 9407 9408 9409 9410 9411 9412 9413 9414 9415 9416 9417 9418 9419 9420 9421 9422 9423 9424 9425 9426 9427 9428 9429 9430 9431 9432 9433 9434 9435 9436 9437 9438 9439 9440 9441 9442 9443 9444 9445 9446 9447 9448 9449 9450 9451 9452 9453 9454 9455 9456 9457 9458 9459 9460 9461 9462 9463 9464 9465 9466 9467 9468 9469 9470 9471 9472 9473 9474 9475 9476 9477 9478 9479 9480 9481 9482 9483 9484 9485 9486 9487 9488 9489 9490 9491 9492 9493 9494 9495 9496 9497 9498 9499 9500 9501 9502 9503 9504 9505 9506 9507 9508 9509 9510 9511 9512 9513 9514 9515 9516 9517 9518 9519 9520 9521 9522 9523 9524 9525 9526 9527 9528 9529 9530 9531 9532 9533 9534 9535 9536 9537 9538 9539 9540 9541 9542 9543 9544 9545 9546 9547 9548 9549 9550 9551 9552 9553 9554 9555 9556 9557 9558 9559 9560 9561 9562 9563 9564 9565 9566 9567 9568 9569 9570 9571 9572 9573 9574 9575 9576 9577 9578 9579 9580 9581 9582 9583 9584 9585 9586 9587 9588 9589 9590 9591 9592 9593 9594 9595 9596 9597 9598 9599 9600 9601 9602 9603 9604 9605 9606 9607 9608 9609 9610 9611 9612 9613 9614 9615 9616 9617 9618 9619 9620 9621 9622 9623 9624 9625 9626 9627 9628 9629 9630 9631 9632 9633 9634 9635 9636 9637 9638 9639 9640 9641 9642 9643 9644 9645 9646 9647 9648 9649 9650 9651 9652 9653 9654 9655 9656 9657 9658 9659 9660 9661 9662 9663 9664 9665 9666 9667 9668 9669 9670 9671 9672 9673 9674 9675 9676 9677 9678 9679 9680 9681 9682 9683 9684 9685 9686 9687 9688 9689 9690 9691 9692 9693 9694 9695 9696 9697 9698 9699 9700 9701 9702 9703 9704 9705 9706 9707 9708 9709 9710 9711 9712 9713 9714 9715 9716 9717 9718 9719 9720 9721 9722 9723 9724 9725 9726 9727 9728 9729 9730 9731 9732 9733 9734 9735 9736 9737 9738 9739 9740 9741 9742 9743 9744 9745 9746 9747 9748 9749 9750 9751 9752 9753 9754 9755 9756 9757 9758 9759 9760 9761 9762 9763 9764 9765 9766 9767 9768 9769 9770 9771 9772 9773 9774 9775 9776 9777 9778 9779 9780 9781 9782 9783 9784 9785 9786 9787 9788 9789 9790 9791 9792 9793 9794 9795 9796 9797 9798 9799 9800 9801 9802 9803 9804 9805 9806 9807 9808 9809 9810 9811 9812 9813 9814 9815 9816 9817 9818 9819 9820 9821 9822 9823 9824 9825 9826 9827 9828 9829 9830 9831 9832 9833 9834 9835 9836 9837 9838 9839 9840 9841 9842 9843 9844 9845 9846 9847 9848 9849 9850 9851 9852 9853 9854 9855 9856 9857 9858 9859 9860 9861 9862 9863 9864 9865 9866 9867 9868 9869 9870 9871 9872 9873 9874 9875 9876 9877 9878 9879 9880 9881 9882 9883 9884 9885 9886 9887 9888 9889 9890 9891 9892 9893 9894 9895 9896 9897 9898 9899 9900 9901 9902 9903 9904 9905 9906 9907 9908 9909 9910 9911 9912 9913 9914 9915 9916 9917 9918 9919 9920 9921 9922 9923 9924 9925 9926 9927 9928 9929 9930 9931 9932 9933 9934 9935 9936 9937 9938 9939 9940 9941 9942 9943 9944 9945 9946 9947 9948 9949 9950 9951 9952 9953 9954 9955 9956 9957 9958 9959 9960 9961 9962 9963 9964 9965 9966 9967 9968 9969 9970 9971 9972 9973 9974 9975 9976 9977 9978 9979 9980 9981 9982 9983 9984 9985 9986 9987 9988 9989 9990 9991 9992 9993 9994 9995 9996 9997 9998 9999 10000 10001 10002 10003 10004 10005 10006 10007 10008 10009 10010 10011 10012 10013 10014 10015 10016 10017 10018 10019 10020 10021 10022 10023 10024 10025 10026 10027 10028 10029 10030 10031 10032 10033 10034 10035 10036 10037 10038 10039 10040 10041 10042 10043 10044 10045 10046 10047 10048 10049 10050 10051 10052 10053 10054 10055 10056 10057 10058 10059 10060 10061 10062 10063 10064 10065 10066 10067 10068 10069 10070 10071 10072 10073 10074 10075 10076 10077 10078 10079 10080 10081 10082 10083 10084 10085 10086 10087 10088 10089 10090 10091 10092 10093 10094 10095 10096 10097 10098 10099 10100 10101 10102 10103 10104 10105 10106 10107 10108 10109 10110 10111 10112 10113 10114 10115 10116 10117 10118 10119 10120 10121 10122 10123 10124 10125 10126 10127 10128 10129 10130 10131 10132 10133 10134 10135 10136 10137 10138 10139 10140 10141 10142 10143 10144 10145 10146 10147 10148 10149 10150 10151 10152 10153 10154 10155 10156 10157 10158 10159 10160 10161 10162 10163 10164 10165 10166 10167 10168 10169 10170 10171 10172 10173 10174 10175 10176 10177 10178 10179 10180 10181 10182 10183 10184 10185 10186 10187 10188 10189 10190 10191 10192 10193 10194 10195 10196 10197 10198 10199 10200 10201 10202 10203 10204 10205 10206 10207 10208 10209 10210 10211 10212 10213 10214 10215 10216 10217 10218 10219 10220 10221 10222 10223 10224 10225 10226 10227 10228 10229 10230 10231 10232 10233 10234 10235 10236 10237 10238 10239 10240 10241 10242 10243 10244 10245 10246 10247 10248 10249 10250 10251 10252 10253 10254 10255 10256 10257 10258 10259 10260 10261 10262 10263 10264 10265 10266 10267 10268
|
{%MainUnit gtkint.pp}
{ $Id$ }
{******************************************************************************
All GTK Winapi implementations.
Initial Revision : Sat Nov 13 12:53:53 1999
!! Keep alphabetical !!
Support routines go to gtkproc.pp
******************************************************************************
Implementation
******************************************************************************
*****************************************************************************
This file is part of the Lazarus Component Library (LCL)
See the file COPYING.modifiedLGPL.txt, included in this distribution,
for details about the license.
*****************************************************************************
}
{$IFOPT C-}
// Uncomment for local trace
// {$C+}
// {$DEFINE ASSERT_IS_ON}
{$EndIf}
const
BOOL_TEXT: array[Boolean] of string = ('False', 'True');
//##apiwiz##sps## // Do not remove
{------------------------------------------------------------------------------
Method: Arc
Params: left, top, right, bottom, angle1, angle2
Returns: Nothing
Use Arc to draw an elliptically curved line with the current Pen.
The angles angle1 and angle2 are 1/16th of a degree. For example, a full
circle equals 5760 (16*360). Positive values of Angle and AngleLength mean
counter-clockwise while negative values mean clockwise direction.
Zero degrees is at the 3'o clock position.
Angle1 is the starting angle. Angle2 is relative to Angle1 (added).
Example:
Angle1 = 10*16, Angle2 = 30*16 will draw an arc from 10 to 40 degree.
------------------------------------------------------------------------------}
function TGtkWidgetSet.Arc(DC: HDC;
left, top, right, bottom, angle1, angle2: Integer): Boolean;
var
DevCtx: TGtkDeviceContext absolute DC;
DCOrigin: TPoint;
Angle: Integer;
begin
Result := IsValidDC(DC);
if not Result then Exit;
// Draw outline
DevCtx.SelectPenProps;
if not (dcfPenSelected in DevCtx.Flags)
then begin
Result := False;
Exit;
end;
if DevCtx.IsNullPen then Exit;
if DevCtx.HasTransf then
begin
DevCtx.TransfRect(Left, Top, Right, Bottom);
DevCtx.TransfNormalize(Left, Right);
DevCtx.TransfNormalize(Top, Bottom);
// we must convert angles too because of possible negative axis orientations
Angle := Angle1 + Angle2;
DevCtx.TransfAngles(Angle1, Angle);
Angle2 := Angle - Angle1;
end;
DCOrigin := DevCtx.Offset;
inc(Left, DCOrigin.X);
inc(Top, DCOrigin.Y);
inc(Right, DCOrigin.X);
inc(Bottom, DCOrigin.Y);
{$IFDEF DebugGDKTraps}BeginGDKErrorTrap;{$ENDIF}
gdk_draw_arc(DevCtx.Drawable, DevCtx.GC, 0, left, top, right - left, bottom - top,
Angle1*4, Angle2*4);
{$IFDEF DebugGDKTraps}EndGDKErrorTrap;{$ENDIF}
end;
{------------------------------------------------------------------------------
Method: AngleChord
Params: DC, x1, y1, x2, y2, angle1, angle2
Returns: Nothing
Use AngleChord to draw a filled Chord-shape on the canvas. The angles angle1
and angle2 are 1/16th of a degree. For example, a full circle equals 5760
16*360). Positive values of Angle and AngleLength mean counter-clockwise while
negative values mean clockwise direction. Zero degrees is at the 3'o clock
position.
------------------------------------------------------------------------------}
function TGtkWidgetSet.AngleChord(DC: HDC;
x1, y1, x2, y2, angle1, angle2: Integer): Boolean;
begin
Result := inherited AngleChord(DC, x1, y1, x2, y2, angle1, angle2);
end;
{------------------------------------------------------------------------------
Function: BeginPaint
Params:
Returns:
------------------------------------------------------------------------------}
function TGtkWidgetSet.BeginPaint(Handle: hWnd; var PS : TPaintStruct) : hdc;
var
Widget: PGtkWidget;
Info: PWidgetInfo;
{$IFDEF Gtk1}
IsDoubleBuffered: Boolean;
TargetObject: TObject;
PaintWidget: Pointer;
{$ELSE}
DC: TGtkDeviceContext;
{$ENDIF}
begin
Widget:=PGtkWidget(Handle);
Info:=GetWidgetInfo(Widget,false);
if Info<>nil then
Inc(Info^.PaintDepth);
{$IFDEF Gtk1}
TargetObject:=GetNearestLCLObject(Widget);
IsDoubleBuffered:=(TargetObject is TWinControl)
and TWinControl(TargetObject).DoubleBuffered;
// check if Handle is the paint widget of the LCL component
if IsDoubleBuffered then begin
PaintWidget:=GetFixedWidget(PGtkWidget(TWinControl(TargetObject).Handle));
IsDoubleBuffered:=(PaintWidget=Widget);
//if not IsDoubleBuffered then begin
// DebugLn('TGtkWidgetSet.BeginPaint Not the paint widget: ',
// TWinControl(TargetObject).Name,':',TWinControl(TargetObject).ClassName,
// ' PaintWidget=',GetWidgetClassName(PaintWidget),
// ' Widget=',GetWidgetClassName(Widget));
//end;
end;
{$IFNDEF UseGTKDoubleBuf}
IsDoubleBuffered:=false;
{$ENDIF}
if IsDoubleBuffered then
PS.hDC:=GetDoubleBufferedDC(Handle)
else
PS.hDC:=GetDC(Handle);
{$ELSE below: not GTK1}
PS.hDC:=GetDC(Handle);
DC:=TGtkDeviceContext(PS.hDC);
DC.PaintRectangle:=PS.rcPaint;
{$ENDIF}
Result := PS.hDC;
end;
{------------------------------------------------------------------------------
Function: BitBlt
Params: DestDC: The destination devicecontext
X, Y: The left/top corner of the destination rectangle
Width, Height: The size of the destination rectangle
SrcDC: The source devicecontext
XSrc, YSrc: The left/top corner of the source rectangle
Rop: The raster operation to be performed
Returns: True if succesful
The BitBlt function copies a bitmap from a source context into a destination
context using the specified raster operation.
------------------------------------------------------------------------------}
function TGtkWidgetSet.BitBlt(DestDC: HDC; X, Y, Width, Height: Integer;
SrcDC: HDC; XSrc, YSrc: Integer; Rop: DWORD): Boolean;
begin
Result := StretchBlt(DestDC, X, Y, Width, Height, SrcDC, XSrc, YSrc, Width,
Height, ROP);
end;
{------------------------------------------------------------------------------
Function: CallNextHookEx
Params: none
Returns: Nothing
------------------------------------------------------------------------------}
function TGtkWidgetSet.CallNextHookEx(hhk : HHOOK; ncode : Integer; wParam: WParam; lParam : LParam) : Integer;
begin
Result := 0;
//TODO: Does anything need to be done here?
//DebugLn('Trace:!!!!!!!!!!!!!!!!!!');
//DebugLn('Trace:!!!!!!!!!!!!!!!!!!');
//DebugLn('Trace:TODO: CALLNEXTHOOKEX in gtkwinapi.inc');
//DebugLn('Trace:!!!!!!!!!!!!!!!!!!');
//DebugLn('Trace:!!!!!!!!!!!!!!!!!!');
end;
{------------------------------------------------------------------------------
Function: CallWindowProc
Params: lpPrevWndFunc:
Handle:
Msg:
wParam:
lParam:
Returns:
------------------------------------------------------------------------------}
function TGtkWidgetSet.CallWindowProc(lpPrevWndFunc : TFarProc; Handle : HWND;
Msg : UINT; wParam: WParam; lParam : LParam) : Integer;
var
Proc : TWndMethod;
Mess : TLMessage;
P : Pointer;
begin
Result := -1;
if Handle = 0 then Exit;
Result := -1;
P := nil;
P := gtk_object_get_data(pgtkobject(Handle),'WNDPROC');
if P <> nil then
Proc := TWndMethod(P^)
else
Exit;
Mess.msg := msg;
Mess.LParam := LParam;
Mess.WParam := WParam;
Proc(Mess);
Result := Mess.Result;
end;
{------------------------------------------------------------------------------
Function: ClientToScreen
Params: Handle : HWND; var P : TPoint
Returns: true on success
Converts the client-area coordinates of P to screen coordinates.
------------------------------------------------------------------------------}
function TGtkWidgetSet.ClientToScreen(Handle : HWND; var P : TPoint) : Boolean;
var
Position: TPoint;
LCLObject: TObject;
List: PGList;
i: Integer;
Pt: TPoint;
Adjustment: PGtkAdjustment;
Scrolled: PGtkScrolledWindow;
begin
if Handle = 0 then
begin
Position.X := 0;
Position.Y := 0;
end else
begin
Position := GetWidgetClientOrigin(PGtkWidget(Handle));
LCLObject:=GetLCLObject(PGtkWidget(Handle));
if (LCLObject <> nil) and (LCLObject is TScrollingWinControl) then
begin
List := gtk_container_children(PGtkContainer(PGtkWidget(Handle)));
if (g_list_length(List) > 0) and
GTK_IS_SCROLLED_WINDOW(g_list_nth_data(List, 0)) then
begin
Scrolled := PGtkScrolledWindow(g_list_nth_data(List, 0));
Pt := Point(0, 0);
Adjustment := gtk_scrolled_window_get_vadjustment(Scrolled);
if Adjustment <> nil then
Pt.Y := Round(Adjustment^.value);
Adjustment := gtk_scrolled_window_get_hadjustment(Scrolled);
if Adjustment <> nil then
Pt.X := Round(Adjustment^.value);
dec(Position.X, Pt.X);
dec(Position.Y, Pt.Y);
end;
glib.g_list_free(List);
end;
end;
Inc(P.X, Position.X);
Inc(P.Y, Position.Y);
//DebugLn(Format('Trace: [GTKObject.ClientToScreen] Handle: 0x%x --> (%d, %d)', [Integer(Handle), P.X, P.y]));
Result := True;
end;
{------------------------------------------------------------------------------
Function: ClipboardFormatToMimeType
Params: FormatID - a registered format identifier (0 is invalid)
Returns: the corresponding mime type as string
------------------------------------------------------------------------------}
function TGtkWidgetSet.ClipboardFormatToMimeType(
FormatID: TClipboardFormat): string;
var p: PChar;
begin
if FormatID<>0 then begin
p:=gdk_atom_name(FormatID);
Result:=StrPas(p);
g_free(p);
end else
Result:='';
end;
{------------------------------------------------------------------------------
Function: ClipboardGetData
Params: ClipboardType
FormatID - a registered format identifier (0 is invalid)
Stream - If format is available, it will be appended to this stream
Returns: true on success
------------------------------------------------------------------------------}
function TGtkWidgetSet.ClipboardGetData(ClipboardType: TClipboardType;
FormatID: TClipboardFormat; Stream: TStream): boolean;
type
PGdkAtom = ^TGdkAtom;
var
SupportedCnt: integer;
SupportedFormats: PGdkAtom;
function IsFormatSupported(CurFormat: TGdkAtom): boolean;
var
a: integer;
AllID: TGdkAtom;
SelData: TGtkSelectionData;
begin
//DebugLn('IsFormatSupported CurFormat=',dbgs(CurFormat),' SupportedCnt=',dbgs(SupportedCnt));
if CurFormat=0 then begin
Result:=false;
exit;
end;
if SupportedCnt<0 then begin
Result:=false;
AllID:=gdk_atom_intern('TARGETS',GdkFalse);
SelData:=RequestSelectionData(ClipboardWidget,ClipboardType,AllID);
{DebugLn('IsFormatSupported A ',Dbgs(SelData.Selection),
' ',HexStr(Cardinal(ClipboardTypeAtoms[ClipboardType]),8),
' SelData.Target='+dbgs(SelData.Target),' AllID='+dbgs(AllID),
' SelData.TheType='+dbgs(SelData.TheType)+' ATOM='+dbgs(gdk_atom_intern('ATOM',0))+' Name="'+GdkAtomToStr(SelData.TheType)+'"',
' SelData.Length='+dbgs(SelData.Length),
' SelData.Format='+dbgs(SelData.Format)
);}
if (SelData.Selection<>ClipboardTypeAtoms[ClipboardType])
or (SelData.Target<>AllID)
or (SelData.{$IfDef GTK2}_Type{$Else}theType{$EndIf}<>gdk_atom_intern('ATOM',GdkFalse)) then begin
SupportedCnt:=0;
exit;
end;
SupportedCnt:=SelData.Length div (SelData.Format shr 3);
SupportedFormats:=PGdkAtom(SelData.Data);
//DebugLn('IsFormatSupported SupportedCnt=',dbgs(SupportedCnt));
{a:=SupportedCnt-1;
while (a>=0) do begin
debugln(' ',dbgs(a),' ',GdkAtomToStr(SupportedFormats[a]),' "',p,'"');
dec(a);
end;}
end;
a:=SupportedCnt-1;
while (a>=0) and (SupportedFormats[a]<>CurFormat) do dec(a);
Result:=(a>=0);
end;
var
FormatAtom, FormatTry: TGdkAtom;
i: integer;
SelData: TGtkSelectionData;
CompoundTextList: PPGChar;
CompoundTextCount: integer;
begin
{$IfDef DEBUG_CLIPBOARD}
DebugLn('[TGtkWidgetSet.ClipboardGetData] A ClipboardWidget=',Dbgs(ClipboardWidget),' FormatID=',ClipboardFormatToMimeType(FormatID),' Now=',dbgs(Now));
{$EndIf}
Result:=false;
if (FormatID=0) or (Stream=nil) then exit;
if not (ClipboardType in [ctPrimarySelection,ctSecondarySelection,ctClipboard])
then exit;
// request the data from the selection owner
SupportedCnt:=-1;
SupportedFormats:=nil;
FillChar(SelData,SizeOf(TGtkSelectionData),0);
try
FormatAtom:=FormatID;
if (FormatAtom=gdk_atom_intern('text/plain',GdkTrue)) then begin
FormatAtom:=0;
// text/plain is supported in various formats in gtk
FormatTry:=gdk_atom_intern('COMPOUND_TEXT',GdkFalse);
if IsFormatSupported(FormatTry) then
FormatAtom:=FormatTry;
// The COMPOUND_TEXT format can be converted and is therefore
// used as default for 'text/plain'
if (SupportedCnt=0) then
FormatAtom:=gdk_atom_intern('COMPOUND_TEXT',GdkFalse);
// then check for UTF8 text format 'UTF8_STRING'
FormatTry:=gdk_atom_intern('UTF8_STRING',GdkFalse);
if IsFormatSupported(FormatTry) then
FormatAtom:=FormatTry;
// then check for simple text format 'text/plain'
FormatTry:=gdk_atom_intern('text/plain',GdkFalse);
if (FormatAtom=0) and IsFormatSupported(FormatTry) then
FormatAtom:=FormatTry;
// then check for simple text format STRING
FormatTry:=gdk_atom_intern('STRING',GdkFalse);
if (FormatAtom=0) and IsFormatSupported(FormatTry) then
FormatAtom:=FormatTry;
// check for some other formats that can be interpreted as text
FormatTry:=gdk_atom_intern('FILE_NAME',GdkTrue);
if (FormatAtom=0) and IsFormatSupported(FormatTry) then
FormatAtom:=FormatTry;
FormatTry:=gdk_atom_intern('HOST_NAME',GdkTrue);
if (FormatAtom=0) and IsFormatSupported(FormatTry) then
FormatAtom:=FormatTry;
FormatTry:=gdk_atom_intern('USER',GdkTrue);
if (FormatAtom=0) and IsFormatSupported(FormatTry) then
FormatAtom:=FormatTry;
// the TEXT format is not reliable, but it should be supported
FormatTry:=gdk_atom_intern('TEXT',GdkFalse);
if (FormatAtom=0) and IsFormatSupported(FormatTry) then
FormatAtom:=FormatTry;
end;
{$IfDef DEBUG_CLIPBOARD}
DebugLn('[TGtkWidgetSet.ClipboardGetData] B Format=',ClipboardFormatToMimeType(FormatAtom),' FormatAtom=',dbgs(FormatAtom),' Now=',dbgs(Now));
{$EndIf}
if FormatAtom=0 then exit;
// request data from owner
SelData:=RequestSelectionData(ClipboardWidget,ClipboardType,FormatAtom);
{$IfDef DEBUG_CLIPBOARD}
DebugLn('[TGtkWidgetSet.ClipboardGetData] C Length=',dbgs(SelData.Length),' Now=',dbgs(Now),' ',
' SelData.Selection=',dbgs(SelData.Selection),' SelData.Length=',dbgs(SelData.Length));
{$EndIf}
if (SelData.Selection<>ClipboardTypeAtoms[ClipboardType])
or (SelData.Target<>FormatAtom) then begin
{$IfDef DEBUG_CLIPBOARD}
DebugLn('[TGtkWidgetSet.ClipboardGetData] REQUESTED FORMAT NOT SUPPORTED Length=',dbgs(SelData.Length));
{$ENDIF}
exit;
end;
// write data to stream
if (SelData.Data<>nil) and (SelData.Length>0) then begin
if (FormatID=gdk_atom_intern('text/plain',GdkTrue)) then begin
// the lcl expects the return format as simple text
// transform if necessary
if FormatAtom=gdk_atom_intern('COMPOUND_TEXT',GdkTrue) then begin
CompoundTextCount:=gdk_text_property_to_text_list(SelData.{$IfDef GTK2}_Type{$Else}theType{$EndIf},
SelData.Format,SelData.Data,SelData.Length,{$IfDef GTK1}@{$EndIf}CompoundTextList);
{$IfDef DEBUG_CLIPBOARD}
DebugLn('[TGtkWidgetSet.ClipboardGetData] D CompoundTextCount=',dbgs(CompoundTextCount),' Now=',dbgs(Now));
{$EndIf}
for i:=0 to CompoundTextCount-1 do
if (CompoundTextList[i]<>nil) then
Stream.Write(CompoundTextList[i]^,StrLen(CompoundTextList[i]));
gdk_free_text_list(CompoundTextList);
end else
Stream.Write(SelData.Data^,SelData.Length);
end else begin
Stream.Write(SelData.Data^,SelData.Length);
end;
end;
{$IfDef DEBUG_CLIPBOARD}
DebugLn('[TGtkWidgetSet.ClipboardGetData] END ',' Now=',dbgs(Now));
{$EndIf}
Result:=true;
finally
if SupportedFormats<>nil then FreeMem(SupportedFormats);
if SelData.Data<>nil then FreeMem(SelData.Data);
end;
end;
{------------------------------------------------------------------------------
Function: ClipboardGetFormats
Params: ClipboardType
Returns: true on success
Count contains the number of supported formats
List is an array of TClipboardType
! List will be created. You must free it yourself with FreeMem(List) !
------------------------------------------------------------------------------}
function TGtkWidgetSet.ClipboardGetFormats(ClipboardType: TClipboardType;
var Count: integer; var List: PClipboardFormat): boolean;
type
PGdkAtom = ^TGdkAtom;
var
AllID: TGdkAtom;
FormatAtoms: PGdkAtom;
Cnt, i: integer;
AddTextPlain: boolean;
SelData: TGtkSelectionData;
function IsFormatSupported(CurFormat: TGdkAtom): boolean;
var a: integer;
begin
if CurFormat<>0 then begin
for a:=0 to Cnt-1 do begin
{$IfDef DEBUG_CLIPBOARD}
DebugLn(' IsFormatSupported ',dbgs(CurFormat),' ',dbgs(FormatAtoms[a]));
{$EndIf}
if FormatAtoms[a]=CurFormat then begin
Result:=true;
exit;
end;
end;
end;
Result:=false;
end;
function IsFormatSupported(Formats: TGtkClipboardFormats): boolean;
var Format: TGtkClipboardFormat;
begin
for Format:=Low(TGtkClipboardFormat) to High(TGtkClipboardFormat) do
if (Format in Formats)
and (IsFormatSupported(
gdk_atom_intern(PGChar(GtkClipboardFormatName[Format]),GdkTrue)))
then begin
Result:=true;
exit;
end;
Result:=false;
end;
begin
{$IfDef DEBUG_CLIPBOARD}
DebugLn('[TGtkWidgetSet.ClipboardGetFormats] A ClipboardWidget=',Dbgs(ClipboardWidget),' Now=',dbgs(Now));
{$EndIf}
Result:=false;
Count:=0;
List:=nil;
if not (ClipboardType in [ctPrimarySelection,ctSecondarySelection,ctClipboard])
then exit;
// request the list of supported formats from the selection owner
AllID:=gdk_atom_intern('TARGETS',GdkFalse);
SelData:=RequestSelectionData(ClipboardWidget,ClipboardType,AllID);
try
{$IfDef DEBUG_CLIPBOARD}
DebugLn('[TGtkWidgetSet.ClipboardGetFormats] Checking TARGETS answer ',
' selection: '+dbgs(SelData.Selection)+'='+dbgs(ClipboardTypeAtoms[ClipboardType])+
' "'+GdkAtomToStr(SelData.Selection)+'"',
' target: '+dbgs(SelData.Target),'=',dbgs(AllID),
' "'+GdkAtomToStr(SelData.Target),'"',
' theType: '+dbgs(SelData.{$IFDEF Gtk1}theType{$ELSE}_type{$ENDIF})+'='+dbgs(gdk_atom_intern('ATOM',GdkFalse))+
' "'+GdkAtomToStr(SelData.{$IFDEF Gtk1}theType{$ELSE}_type{$ENDIF})+'"',
' Length='+dbgs(SelData.Length),
' Format='+dbgs(SelData.Format),
' Data='+Dbgs(SelData.Data),
' Now='+dbgs(Now)
);
{$EndIf}
if (SelData.Selection<>ClipboardTypeAtoms[ClipboardType])
or (SelData.Target<>AllID)
or (SelData.Format<=0)
or ((SelData.{$IfDef GTK2}_Type{$Else}TheType{$EndIf}<>gdk_atom_intern('ATOM',GdkFalse))
and (SelData.{$IfDef GTK2}_Type{$Else}TheType{$EndIf}<>AllID))
then
exit;
Cnt:=SelData.Length div (SelData.Format shr 3);
if (SelData.Data<>nil) and (Cnt>0) then begin
Count:=Cnt;
FormatAtoms:=PGdkAtom(SelData.Data);
// add transformable lcl formats
// for example: the lcl expects text as 'text/plain', but gtk applications
// also know 'TEXT' and 'STRING'. These formats can automagically
// transformed into the lcl format, so the lcl format is also supported
// and will be added to the list
AddTextPlain:=false;
if (not IsFormatSupported(gdk_atom_intern('text/plain',GdkTrue)))
and (IsFormatSupported([gfCOMPOUND_TEXT,gfTEXT,gfSTRING,gfFILE_NAME,
gfHOST_NAME,gfUSER]))
then begin
AddTextPlain:=true;
inc(Count);
end;
// copy normal supported formats
GetMem(List,SizeOf(TClipboardFormat)*Count);
i:=0;
while (i<Cnt) do begin
{$IfDef DEBUG_CLIPBOARD}
DebugLn('[TGtkWidgetSet.ClipboardGetFormats] Supported formats: ',
dbgs(i)+'/'+dbgs(Cnt),': ',dbgs(FormatAtoms[i]));
DebugLn(' MimeType="',ClipboardFormatToMimeType(FormatAtoms[i]),'"');
{$EndIf}
List[i]:=FormatAtoms[i];
inc(i);
end;
// add all lcl formats that the gtk-interface can transform from the
// supported formats
if AddTextPlain then begin
List[i]:=gdk_atom_intern('text/plain',GdkFalse);
inc(i);
end;
end;
finally
if SelData.Data<>nil then FreeMem(SelData.Data);
end;
Result:=true;
end;
{------------------------------------------------------------------------------
Function: ClipboardGetOwnerShip
Params: ClipboardType
OnRequestProc - TClipboardRequestEvent is defined in LCLIntf.pp
If OnRequestProc is nil the onwership will end.
FormatCount - number of formats
Formats - array of TClipboardFormat. The supported formats the owner
provides.
Returns: true on success
Sets the supported formats and requests ownership for the clipboard.
Each time the clipboard is read the OnRequestProc will be executed.
If someone else requests the ownership, the OnRequestProc will be executed
with the invalid FormatID 0 to notify the old owner of the lost of ownership.
------------------------------------------------------------------------------}
function TGtkWidgetSet.ClipboardGetOwnerShip(ClipboardType: TClipboardType;
OnRequestProc: TClipboardRequestEvent; FormatCount: integer;
Formats: PClipboardFormat): boolean;
var TargetEntries: PGtkTargetEntry;
function IsFormatSupported(FormatID: TGdkAtom): boolean;
var i: integer;
begin
if FormatID=0 then begin
Result:=false;
exit;
end;
i:=FormatCount-1;
while (i>=0) and (Formats[i]<>FormatID) do dec(i);
Result:=(i>=0);
end;
procedure AddTargetEntry(var Index: integer; const FormatName: string);
begin
{$IfDef DEBUG_CLIPBOARD}
DebugLn(' AddTargetEntry ',FormatName);
{$EndIf}
TargetEntries[Index].Target := StrAlloc(Length(FormatName) + 1);
StrPCopy(TargetEntries[Index].Target, FormatName);
TargetEntries[Index].flags:=0;
TargetEntries[Index].Info:=Index;
inc(Index);
end;
{function TGtkWidgetSet.ClipboardGetOwnerShip(ClipboardType: TClipboardType;
OnRequestProc: TClipboardRequestEvent; FormatCount: integer;
Formats: PClipboardFormat): boolean;}
var
TargetEntriesSize, i: integer;
gtkFormat: TGtkClipboardFormat;
ExpFormatCnt: integer;
OldClipboardWidget: PGtkWidget;
begin
if ClipboardType in [ctPrimarySelection, ctSecondarySelection, ctClipboard] then
begin
{$IfDef DEBUG_CLIPBOARD}
DebugLn('[TGtkWidgetSet.ClipboardGetOwnerShip] A');
{$EndIf}
ClipboardHandler[ClipboardType]:=nil;
Result:=false;
if (ClipboardWidget=nil) or (FormatCount=0) or (Formats=nil) then
begin
// end ownership
if (ClipBoardWidget <> nil)
and (GetControlWindow(ClipboardWidget)<>nil)
and (gdk_selection_owner_get(ClipboardTypeAtoms[ClipboardType]) =
GetControlWindow(ClipboardWidget))
then begin
gtk_selection_owner_set(nil,ClipboardTypeAtoms[ClipboardType],0);
end;
Result:=true;
exit;
end;
// registering targets
FreeClipboardTargetEntries(ClipboardType);
// the gtk-interface adds automatically some gtk formats unknown to the lcl
ExpFormatCnt:=FormatCount;
for gtkFormat:=Low(TGtkClipboardFormat) to High(TGtkClipboardFormat) do
ClipboardExtraGtkFormats[ClipboardType][gtkFormat]:=false;
{$IfDef DEBUG_CLIPBOARD}
DebugLn('[TGtkWidgetSet.ClipboardGetOwnerShip] B');
{$EndIf}
if IsFormatSupported(gdk_atom_intern('text/plain',GdkTrue)) then
begin
// lcl provides 'text/plain' and the gtk-interface will automatically
// provide some more text formats
ClipboardExtraGtkFormats[ClipboardType][gfCOMPOUND_TEXT]:=
not IsFormatSupported(
gdk_atom_intern(PGChar(GtkClipboardFormatName[gfCOMPOUND_TEXT]),GdkFalse));
ClipboardExtraGtkFormats[ClipboardType][gfSTRING]:=not IsFormatSupported(
gdk_atom_intern(PGChar(GtkClipboardFormatName[gfSTRING]),GdkFalse));
ClipboardExtraGtkFormats[ClipboardType][gfTEXT]:=not IsFormatSupported(
gdk_atom_intern(PGChar(GtkClipboardFormatName[gfTEXT]),GdkFalse));
end;
for gtkFormat:=Low(TGtkClipboardFormat) to High(TGtkClipboardFormat) do
if ClipboardExtraGtkFormats[ClipboardType][gtkFormat] then
inc(ExpFormatCnt);
// build TargetEntries
TargetEntriesSize:=SizeOf(TGtkTargetEntry) * ExpFormatCnt;
GetMem(TargetEntries,TargetEntriesSize);
FillChar(TargetEntries^,TargetEntriesSize,0);
i:=0;
while i<FormatCount do
AddTargetEntry(i,ClipboardFormatToMimeType(Formats[i]));
for gtkFormat:=Low(TGtkClipboardFormat) to High(TGtkClipboardFormat) do
if ClipboardExtraGtkFormats[ClipboardType][gtkFormat] then
AddTargetEntry(i,GtkClipboardFormatName[gtkFormat]);
// set the supported formats
ClipboardTargetEntries[ClipboardType]:=TargetEntries;
ClipboardTargetEntryCnt[ClipboardType]:=ExpFormatCnt;
// reset the clipboard widget (this will set the new target list)
OldClipboardWidget:=ClipboardWidget;
SetClipboardWidget(nil);
SetClipboardWidget(OldClipboardWidget);
// taking the ownership
{$IfDef DEBUG_CLIPBOARD}
DebugLn('[TGtkWidgetSet.ClipboardGetOwnerShip] C');
{$EndIf}
if gtk_selection_owner_set(ClipboardWidget,
ClipboardTypeAtoms[ClipboardType],0)=GdkFalse
then begin
{$IfDef DEBUG_CLIPBOARD}
DebugLn('[TGtkWidgetSet.ClipboardGetOwnerShip] D FAILED');
{$EndIf}
exit;
end;
{$IfDef DEBUG_CLIPBOARD}
DebugLn('[TGtkWidgetSet.ClipboardGetOwnerShip] YEAH, got it!');
{$EndIf}
ClipboardHandler[ClipboardType]:=OnRequestProc;
Result:=true;
end else
{ the gtk does not support this kind of clipboard, so the application can
have the ownership at any time. The TClipboard in clipbrd.pp has an
internal cache system, so that an application can use all types of
clipboards even if the underlying platform does not support it.
Of course this will only be a local clipboard, invisible to other
applications. }
Result:=true;
end;
{------------------------------------------------------------------------------
Function: ClipboardRegisterFormat
Params: AMimeType
Returns: the registered Format identifier (TClipboardFormat)
------------------------------------------------------------------------------}
function TGtkWidgetSet.ClipboardRegisterFormat(
const AMimeType:String): TClipboardFormat;
var AtomName: PChar;
begin
if Assigned(Application) then begin
AtomName:=PChar(AMimeType);
Result:=gdk_atom_intern(AtomName,GdkFalse);
end else
RaiseGDBException(
'ERROR: TGtkWidgetSet.ClipboardRegisterFormat gdk not initialized');
end;
{------------------------------------------------------------------------------
Function: CreateBitmap
Params: none
Returns: Nothing
------------------------------------------------------------------------------}
function TGtkWidgetSet.CreateBitmap(Width, Height: Integer; Planes, BitCount: Longint; BitmapBits: Pointer): HBITMAP;
const
MIN_LOADER_HEADER_SIZE = 128;
type
// the loader internally used starts decoding the header after 128 bytes.
// by adding dummy bytes and adjusting the data offset, we make sure that we
// we write atleast 128 bytes
TBitmapHeader = packed record
FileHeader: tagBitmapFileHeader;
InfoHeader: tagBitmapInfoHeader;
Dummy: array[1..MIN_LOADER_HEADER_SIZE] of Byte;
end;
var
GdiObject: PGdiObject;
procedure FillBitmapInfo(out Header: TBitmapHeader);
begin
FillChar(Header, SizeOf(Header), 0);
Header.InfoHeader.biSize := SizeOf(Header.InfoHeader);
Header.InfoHeader.biWidth := Width;
Header.InfoHeader.biHeight := Height;
Header.InfoHeader.biPlanes := Planes;
Header.InfoHeader.biBitCount := Bitcount;
Header.InfoHeader.biCompression := BI_RGB;
Header.InfoHeader.biSizeImage := (((BitCount * Width + 31) shr 5) shl 2) * Height;
Header.InfoHeader.biXPelsPerMeter := GetDeviceCaps(0, LOGPIXELSX);
Header.InfoHeader.biYPelsPerMeter := GetDeviceCaps(0, LOGPIXELSY);
Header.FileHeader.bfType := LeToN($4D42);
Header.FileHeader.bfSize := MIN_LOADER_HEADER_SIZE + Header.InfoHeader.biSizeImage;
Header.FileHeader.bfOffBits := MIN_LOADER_HEADER_SIZE;
end;
procedure LoadDataByPixbufLoader;
const
ALIGNDATA: Word = 0;
var
Header: TBitmapHeader;
Loader: PGdkPixbufLoader;
Src: PGDKPixbuf;
res: Boolean;
LineSize, Count: Integer;
BitsPtr: PByte;
begin
Loader := gdk_pixbuf_loader_new;
if Loader = nil then Exit;
FillBitmapInfo(Header);
Src := nil;
try
if not gdk_pixbuf_loader_write(Loader, TGdkPixBufBuffer(@Header), MIN_LOADER_HEADER_SIZE {$ifdef gtk2},nil{$endif})
then begin
DebugLn('WARNING: [TGtkWidgetSet.CreateBitmap] Error loading Bitmap Header!');
Exit;
end;
LineSize := (((BitCount * Width + 15) shr 4) shl 1);
if (LineSize and 2) <> 0
then begin
// bitmapdata needs to be DWord aligned, while CreateBitmap is Word aligned
// so "feed" the loader line by line :(
Count := Height;
res := True;
BitsPtr := BitmapBits;
while res and (Count > 0) do
begin
res := gdk_pixbuf_loader_write(Loader, TGdkPixBufBuffer(BitsPtr), LineSize {$ifdef gtk2},nil{$endif})
and gdk_pixbuf_loader_write(Loader, TGdkPixBufBuffer(@ALIGNDATA), 2 {$ifdef gtk2},nil{$endif});
Inc(BitsPtr, LineSize);
Dec(Count);
end;
end
else begin
// data is DWord aligned :)
res := gdk_pixbuf_loader_write(Loader, TGdkPixBufBuffer(BitmapBits), Header.InfoHeader.biSizeImage {$ifdef gtk2},nil{$endif});
end;
if not res
then begin
DebugLn('WARNING: [TGtkWidgetSet.CreateBitmap] Error loading Image!');
Exit;
end;
Src := gdk_pixbuf_loader_get_pixbuf(loader);
if Src = nil
then begin
DebugLn('WARNING: [TGtkWidgetSet.CreateBitmap] Error loading Pixbuf!');
Exit;
end;
finally
gdk_pixbuf_loader_close(Loader {$ifdef gtk2},nil {$endif});
end;
if GdiObject^.GDIPixmapObject.Image<>nil then
begin
gdk_pixmap_unref(GdiObject^.GDIPixmapObject.Image);
GdiObject^.GDIPixmapObject.Image:=nil;
end;
if GdiObject^.GDIPixmapObject.Mask<>nil then
begin
gdk_bitmap_unref(GdiObject^.GDIPixmapObject.Mask);
GdiObject^.GDIPixmapObject.Mask:=nil;
end;
gdk_pixbuf_render_pixmap_and_mask(Src,
GdiObject^.GDIPixmapObject.Image, GdiObject^.GDIPixmapObject.Mask, $80);
gdk_pixbuf_unref(Src);
GdiObject^.Depth := gdk_drawable_get_depth(GdiObject^.GDIPixmapObject.Image);
if GdiObject^.Depth = 1
then begin
if GdiObject^.GDIPixmapObject.Mask <> nil
then gdk_pixmap_unref(GdiObject^.GDIPixmapObject.Mask);
GdiObject^.GDIPixmapObject.Mask := nil;
GdiObject^.GDIBitmapType := gbBitmap;
end
else begin
GdiObject^.GDIBitmapType := gbPixmap;
end;
GdiObject^.Visual := gdk_window_get_visual(GDIObject^.GDIPixmapObject.Image);
if GdiObject^.Visual = nil
then GdiObject^.Visual := gdk_visual_get_best_with_depth(GdiObject^.Depth)
else gdk_visual_ref(GdiObject^.Visual);
GdiObject^.Colormap := gdk_colormap_new(GdiObject^.Visual, GdkTrue);
end;
procedure LoadBitmapData;
var
LineSize, n: Integer;
BitsPtr: Pointer;
Src, Dst: PByte;
begin
LineSize := (Width + 7) shr 3;
if (LineSize and 1) <> 0
then begin
// the gdk_bitmap_create_from_data expects data byte aligned while
// Createbitmap is word aligned. adjust data
BitsPtr := GetMem(LineSize * Height);
Dst := BitsPtr;
Src := BitmapBits;
for n := 1 to height do
begin
Move(Src^, Dst^, LineSize);
Inc(Src, LineSize + 1);
Inc(Dst, LineSize);
end;
end
else begin
BitsPtr := BitmapBits;
end;
GdiObject^.GDIBitmapType := gbBitmap;
GdiObject^.GDIBitmapObject := gdk_bitmap_create_from_data(nil, BitsPtr, Width, Height);
GdiObject^.Visual := nil; // bitmaps don't have a visual
GdiObject^.SystemVisual := False;
if BitsPtr <> BitmapBits
then FreeMem(BitsPtr);
end;
begin
//DebugLn(Format('Trace:> [TGtkWidgetSet.CreateBitmap] Width: %d, Height: %d, Planes: %d, BitCount: %d, BitmapBits: 0x%x', [Width, Height, Planes, BitCount, PtrUInt(BitmapBits)]));
if (BitCount < 1) or (Bitcount > 32)
then begin
Result := 0;
DebugLn(Format('ERROR: [TGtkWidgetSet.CreateBitmap] Illegal depth %d', [BitCount]));
Exit;
end;
GdiObject := NewGDIObject(gdiBitmap);
if BitmapBits = nil
then begin
if BitCount = 1
then begin
GdiObject^.GDIBitmapType := gbBitmap;
GdiObject^.GDIBitmapObject := gdk_pixmap_new(nil, Width, Height, 1);
GdiObject^.Visual := nil; // bitmaps don't have a visual
end
else begin
GdiObject^.GDIBitmapType := gbPixmap;
GdiObject^.GDIPixmapObject.Image := gdk_pixmap_new(nil, Width, Height, BitCount);
GdiObject^.Visual := gdk_window_get_visual(GdiObject^.GDIPixmapObject.Image);
gdk_visual_ref(GdiObject^.Visual);
end;
GdiObject^.SystemVisual := False;
end
else begin
if BitCount = 1
then begin
LoadBitmapData;
end
else begin
// Load the data by faking it as a windows bitmap stream (this handles all conversion)
// Problem with his method is that it doesn't result in the bitmap requested.
// it is always a device compatible bitmap
// maybe we should add a gdPixBuf type the the GDIObject for formats not compatible
// with a native pixmap format
LoadDataByPixbufLoader;
end;
end;
Result := HBITMAP(PtrUInt(GdiObject));
//DebugLn(Format('Trace:< [TGtkWidgetSet.CreateBitmap] --> 0x%x', [Integer(Result)]));
end;
{------------------------------------------------------------------------------
Function: CreateBrushIndirect
Params: none
Returns: Nothing
------------------------------------------------------------------------------}
function TGtkWidgetSet.CreateBrushIndirect(const LogBrush: TLogBrush): HBRUSH;
const
HATCH_BDIAGONAL : array[0..7] of Byte = ($80, $40, $20, $10, $08, $04, $02, $01);
HATCH_CROSS : array[0..7] of Byte = ($08, $08, $08, $FF, $08, $08, $08, $08);
HATCH_DIAGCROSS : array[0..7] of Byte = ($81, $42, $24, $18, $18, $24, $42, $81);
HATCH_FDIAGONAL : array[0..7] of Byte = ($01, $02, $04, $08, $10, $20, $40, $80);
HATCH_HORIZONTAL: array[0..7] of Byte = ($00, $00, $00, $FF, $00, $00, $00, $00);
HATCH_VERTICAL : array[0..7] of Byte = ($08, $08, $08, $08, $08, $08, $08, $08);
var
GObject: PGdiObject;
TmpMask: PGdkBitmap;
begin
//DebugLn(Format('Trace:> [TGtkWidgetSet.CreateBrushIndirect] Style: %d, Color: %8x', [LogBrush.lbStyle, LogBrush.lbColor]));
{$IFDEF DebugGDKTraps}
BeginGDKErrorTrap;
{$ENDIF}
GObject := NewGDIObject(gdiBrush);
try
{$IFDEF DebugGDIBrush}
DebugLn('[TGtkWidgetSet.CreateBrushIndirect] ',DbgS(GObject));
{$ENDIF}
GObject^.IsNullBrush := False;
with LogBrush do
begin
case lbStyle of
BS_NULL {BS_HOLLOW}: // Same as BS_HOLLOW.
GObject^.IsNullBrush := True;
BS_SOLID: // Solid brush.
GObject^.GDIBrushFill := GDK_SOLID;
BS_HATCHED: // Hatched brush.
begin
GObject^.GDIBrushFill := GDK_STIPPLED;
case lbHatch of
HS_BDIAGONAL:
GObject^.GDIBrushPixmap := gdk_bitmap_create_from_data(
nil, pgchar(@HATCH_BDIAGONAL[0]), 8, 8);
HS_CROSS:
GObject^.GDIBrushPixmap := gdk_bitmap_create_from_data(
nil, pgchar(@HATCH_CROSS[0]), 8, 8);
HS_DIAGCROSS:
GObject^.GDIBrushPixmap := gdk_bitmap_create_from_data(
nil, pgchar(@HATCH_DIAGCROSS[0]), 8, 8);
HS_FDIAGONAL:
GObject^.GDIBrushPixmap := gdk_bitmap_create_from_data(
nil, pgchar(@HATCH_FDIAGONAL[0]), 8, 8);
HS_HORIZONTAL:
GObject^.GDIBrushPixmap := gdk_bitmap_create_from_data(
nil, pgchar(@HATCH_HORIZONTAL[0]), 8, 8);
HS_VERTICAL:
GObject^.GDIBrushPixmap := gdk_bitmap_create_from_data(
nil, pgchar(@HATCH_VERTICAL[0]), 8, 8);
else
GObject^.GDIBrushFill := GDK_SOLID;
end;
end;
BS_DIBPATTERN, // A pattern brush defined by a device-independent
// bitmap (DIB) specification. If lbStyle is BS_DIBPATTERN, the
// lbHatch member contains a handle to a packed DIB.Windows 95:
// Creating brushes from bitmaps or DIBs larger than 8x8 pixels
// is not supported. If a larger bitmap is given, only a portion
// of the bitmap is used.
BS_DIBPATTERN8X8, // Same as BS_DIBPATTERN.
BS_DIBPATTERNPT, // A pattern brush defined by a device-independent
// bitmap (DIB) specification. If lbStyle is BS_DIBPATTERNPT, the
// lbHatch member contains a pointer to a packed DIB.
BS_PATTERN, // Pattern brush defined by a memory bitmap.
BS_PATTERN8X8: // Same as BS_PATTERN.
begin
GObject^.GDIBrushPixmap := nil;
if IsValidGDIObject(lbHatch) and (PGdiObject(lbHatch)^.GDIType = gdiBitmap) then
begin
case PGdiObject(lbHatch)^.GDIBitmapType of
gbBitmap:
begin
GObject^.GDIBrushPixmap := PGdiObject(lbHatch)^.GDIBitmapObject;
GObject^.GDIBrushFill := GDK_STIPPLED;
end;
gbPixmap:
begin
GObject^.GDIBrushPixmap := PGdiObject(lbHatch)^.GDIPixmapObject.Image;
GObject^.GDIBrushFill := GDK_TILED;
end;
gbPixbuf:
begin
GObject^.GDIBrushPixmap := nil;
TmpMask := nil;
gdk_pixbuf_render_pixmap_and_mask(PGdiObject(lbHatch)^.GDIPixbufObject,
GObject^.GDIBrushPixmap, TmpMask, $80);
gdk_pixmap_unref(TmpMask);
end;
else
begin
DebugLn('TGtkWidgetSet.CreateBrushIndirect: Unsupported GDIBitmapType')
end;
end
end
else
RaiseGDBException('unsupported bitmap');
if GObject^.GDIBrushPixmap <> nil then
gdk_pixmap_ref(GObject^.GDIBrushPixmap);
end;
else
RaiseGDBException(Format('unsupported Style %d',[lbStyle]));
end;
{$IFDEF DebugGDKTraps}
EndGDKErrorTrap;
{$ENDIF}
if not GObject^.IsNullBrush then
SetGDIColorRef(GObject^.GDIBrushColor, lbColor);
end;
Result := HBRUSH(PtrUInt(GObject));
except
Result:=0;
DisposeGDIObject(GObject);
DebugLn('TGtkWidgetSet.CreateBrushIndirect failed');
end;
//DebugLn(Format('Trace:< [TGtkWidgetSet.CreateBrushIndirect] Got --> %x', [Result]));
end;
{------------------------------------------------------------------------------
Function: CreateCaret
Params: none
Returns: Nothing
------------------------------------------------------------------------------}
function TGtkWidgetSet.CreateCaret(Handle: HWND; Bitmap: hBitmap;
Width, Height: Integer): Boolean;
var
GTKObject: PGTKObject;
BMP: PGDKPixmap;
begin
//DebugLn('Trace:TODO: [TGtkWidgetSet.CreateCaret] Finish');
GTKObject := PGTKObject(Handle);
Result := GTKObject <> nil;
if Result then begin
if gtk_type_is_a(gtk_object_type(GTKObject), GTKAPIWidget_GetType)
then begin
if IsValidGDIObjectType(Bitmap, gdiBitmap) then
BMP := PGdiObject(Bitmap)^.GDIBitmapObject
else
BMP := nil;
GTKAPIWidget_CreateCaret(PGTKAPIWidget(GTKObject), Width, Height, BMP);
end
// else if // TODO: other widgettypes
else begin
Result := False;
end;
end
else begin
//DebugLn('Trace:WARNING: [TGtkWidgetSet.CreateCaret] Got null HWND');
end;
end;
{------------------------------------------------------------------------------
Function: CreateCompatibleBitmap
Params: DC:
Width:
Height:
Returns:
Creates a bitmap compatible with the specified device context.
------------------------------------------------------------------------------}
function TGtkWidgetSet.CreateCompatibleBitmap(DC: HDC; Width, Height: Integer): HBITMAP;
var
DevCtx: TGtkDeviceContext absolute DC;
GDIObject: PGdiObject;
Depth : Longint;
Drawable, DefDrawable: PGDkDrawable;
begin
//DebugLn(Format('Trace:> [TGtkWidgetSet.CreateCompatibleBitmap] DC: 0x%x, W: %d, H: %d', [DC, Width, Height]));
if IsValidDC(DC) and (DevCtx.Drawable <> nil)
then begin
DefDrawable := DevCtx.Drawable;
Depth := gdk_drawable_get_depth(DevCtx.Drawable);
end
else begin
DefDrawable := nil;
Depth := gdk_visual_get_system^.Depth;
end;
if (Depth < 1) or (Depth > 32)
then begin
Result := 0;
DebugLn(Format('ERROR: [TGtkWidgetSet.CreateCompatibleBitmap] Illegal depth %d', [Depth]));
Exit;
end;
GdiObject := NewGDIObject(gdiBitmap);
Drawable := gdk_pixmap_new(DefDrawable, Width, Height, Depth);
GdiObject^.Visual := gdk_window_get_visual(Drawable);
if Depth = 1
then begin
GdiObject^.GDIBitmapType := gbBitmap;
GdiObject^.GDIBitmapObject := Drawable;
end
else begin
GdiObject^.GDIBitmapType := gbPixmap;
GdiObject^.GDIPixmapObject.Image := Drawable;
end;
if GdiObject^.Visual = nil
then begin
GdiObject^.Visual := gdk_visual_get_best_with_depth(Depth);
if GdiObject^.Visual = nil
then GdiObject^.Visual := gdk_visual_get_system;
GdiObject^.SystemVisual := True;
end
else begin
gdk_visual_ref(GdiObject^.Visual);
GdiObject^.SystemVisual := False;
end;
GdiObject^.Colormap := gdk_colormap_new(GdiObject^.Visual, GdkTrue);
Result := HBITMAP(PtrUInt(GdiObject));
//DebugLn(Format('Trace:< [TGtkWidgetSet.CreateCompatibleBitmap] DC: 0x%x --> 0x%x', [DC, Result]));
end;
{------------------------------------------------------------------------------
Function: CreateCompatibleDC
Params: none
Returns: Nothing
------------------------------------------------------------------------------}
function TGtkWidgetSet.CreateCompatibleDC(DC: HDC): HDC;
var
pNewDC: TGtkDeviceContext;
begin
Result := 0;
pNewDC := NewDC;
// do not copy
// In a compatible DC you have to select a bitmap into it
(*
if IsValidDC(DC) then
with TGtkDeviceContext(DC)^ do
begin
pNewDC^.hWnd := hWnd;
pNewDC^.Drawable := Drawable;
pNewDC^.GC := gdk_gc_new(Drawable);
end
else begin
// We can't do anything yet
// Wait till a bitmap get selected
end;
*)
with pNewDC do
begin
gdk_color_black(gdk_colormap_get_system, @CurrentTextColor.Color);
BuildColorRefFromGDKColor(CurrentTextColor);
gdk_color_white(gdk_colormap_get_system, @CurrentBackColor.Color);
BuildColorRefFromGDKColor(CurrentBackColor);
end;
{$IFDEF Gtk1}
pNewDC.GetFont;
pNewDC.GetBrush;
pNewDC.GetPen;
{$ENDIF}
Result := HDC(pNewDC);
//DebugLn(Format('trace: [TGtkWidgetSet.CreateCompatibleDC] DC: 0x%x --> 0x%x', [Integer(DC), Integer(Result)]));
end;
function TGtkWidgetSet.DestroyCursor(Handle: hCursor): Boolean;
begin
Result := Handle <> 0;
if Result then
gdk_cursor_destroy(PGdkCursor(Handle));
end;
function TGTKWidgetSet.DestroyIcon(Handle: HICON): Boolean;
begin
// todo: handle cursors here, but how to check whether it is a cursor or an icon?
Result := Handle <> 0;
if Result then
gdk_pixbuf_unref(PGdkPixbuf(Handle));
end;
function TGTKWidgetSet.DPtoLP(DC: HDC; var Points; Count: Integer): BOOL;
var
DevCtx: TGtkDeviceContext absolute DC;
P: PPoint;
begin
Result := False;
if not IsValidDC(DC) then Exit(False);
if not DevCtx.HasTransf then Exit(True);
P := @Points;
while Count > 0 do
begin
Dec(Count);
DevCtx.InvTransfPoint(P^.X, P^.Y);
Inc(P);
end;
Result := True;
end;
{------------------------------------------------------------------------------
Function: CreateFontIndirect
Params: const LogFont: TLogFont
Returns: HFONT
Creates a font GDIObject.
------------------------------------------------------------------------------}
function TGtkWidgetSet.CreateFontIndirect(const LogFont: TLogFont): HFONT;
begin
Result := CreateFontIndirectEx(LogFont,'');
end;
{------------------------------------------------------------------------------
Function: CreateFontIndirectEx
Params: const LogFont: TLogFont; const LongFontName: string
Returns: HFONT
Creates a font GDIObject.
------------------------------------------------------------------------------}
function TGtkWidgetSet.CreateFontIndirectEx(const LogFont: TLogFont;
const LongFontName: string): HFONT;
{$IfDef GTK2}
begin
DebugLn('ToDo: TGtkWidgetSet.CreateFontIndirectEx');
Result:=0;
end;
{$Else Gtk1}
{off $DEFINE VerboseFonts}
var
GdiObject: PGdiObject;
FontNameRegistry, Foundry, FamilyName, WeightName,
Slant, SetwidthName, AddStyleName, PixelSize,
PointSize, ResolutionX, ResolutionY, Spacing, AverageWidth,
CharSetRegistry, CharSetCoding: string;
n: Integer;
sn, cs: Float;
CachedFont: TGtkFontCacheDescriptor;
CharsetRec: PCharSetEncodingRec;
Weightlist: TStringlist;
CalcPixelSize: boolean;
function LoadFontXLFD(aXLFD: string): boolean;
var
Desc: TGtkFontCacheDescriptor;
begin
GdiObject^.GDIFontObject := gdk_font_load(PChar(aXLFD));
Result:=GdiObject^.GDIFontObject<>nil;
{$ifdef VerboseFonts}
DebugLn('LoadFontXLFD: Trying ',aXLFD,' Matched=',dbgs(Result));
{$endif}
if Result then begin
Desc:=FontCache.Add(GdiObject^.GDIFontObject,LogFont,LongFontName);
if Desc<>nil then
Desc.xlfd:=aXLFD;
end;
end;
function LoadFont: boolean;
var
S: string;
begin
S:=FontNameRegistry+'-'+Foundry+'-'+FamilyName+'-'+WeightName
+'-'+Slant+'-'+SetwidthName+'-'+AddStyleName+'-'+PixelSize
+'-'+PointSize+'-'+ResolutionX+'-'+ResolutionY+'-'+Spacing+'-'+AverageWidth
+'-'+CharSetRegistry+'-'+CharSetCoding;
{ MG: heaptrc gets corrupted heap using the construction below:
S := Format('%s-%s-%s-%s-%s-%s-%s-%s-%s-%s-%s-%s-%s-%s-%s',
[FontNameRegistry, Foundry, FamilyName, WeightName,
Slant, SetwidthName, AddStyleName, PixelSize,
PointSize, ResolutionX, ResolutionY, Spacing, AverageWidth,
CharSetRegistry, CharSetCoding
]);}
//DebugLn(' Trying Font "',S,'"');
result := LoadFontXLFD(S);
end;
function LoadFontExCharset: boolean;
var
i: Integer;
aSlant, aSpacing,head, mid, tail: string;
begin
Result := False;
Head := FontNameRegistry+'-'+Foundry+'-'+FamilyName+'-';
Mid := '-'+SetwidthName+'-'+AddStyleName+'-'+PixelSize
+'-'+PointSize+'-'+ResolutionX+'-'+ResolutionY+'-';
Tail := '-'+AverageWidth+'-'+CharSetRegistry+'-'+CharSetCoding;
//debugln('LoadFontExCharset Head=',Head,' Tail=',Tail);
for i:=0 to WeightList.Count-1 do begin
aSlant := Slant;
repeat
aSpacing:=Spacing;
repeat
result := LoadFontXLFD(Head+WeightList[i]+'-'+aSlant+Mid+aSpacing+Tail);
if result then
exit;
if aSpacing = 'm' then
aSpacing := 'c'
else
break;
until false;
if aSlant='i' then
aSlant:='o'
else
break;
until false;
end;
//debugln('LoadFontExCharset END');
end;
function LoadFontEx: boolean;
var
j: integer;
begin
Result := false;
//debugln('LoadFontEx START CharSetRegistry=',CharSetRegistry);
if CharSetRegistry<>'*' then
result := LoadFontExCharset
else
for j:=0 to CharSetEncodingList.Count-1 do begin
CharSetRec := CharsetEncodingList[j];
if (CharsetRec = nil) or (CharSetRec^.CharSet<>LogFont.lfCharset) then
continue;
CharSetCoding := CharsetRec^.CharSetCod;
CharSetRegistry := CharSetRec^.CharSetReg;
result := LoadFontExCharset;
if result then
break;
end;
//debugln('LoadFontEx END');
end;
procedure LoadDefaultFont;
begin
ReleaseGdiObject(GdiObject);
GdiObject:=CreateDefaultFont;
{$IFDEF VerboseFonts}
DebugLn('TGtkWidgetSet.CreateFontIndirectEx.LoadDefaultFont');
{$ENDIF}
end;
function GetDefaultFontFamilyName: string;
begin
Result:=GetDefaultFontName;
if IsFontNameXLogicalFontDesc(Result) then
Result := ExtractXLFDItem(Result,2);
if Result='' then Result:='*';
end;
function ExtractXLFDItemMask(const ALongFontName: string;
Index: Integer): string;
begin
Result:=ExtractXLFDItem(ALongFontName,Index);
if Result='' then Result:='*';
end;
function FamilyNameExists: boolean;
var
AFont: PGdkFont;
S: String;
begin
//S := '*-*-'+FamilyName+'*-*-*-*-*-*-*-*-*-*-*-*-*';
S := '-'+Foundry+'-'+FamilyName+'-*-*-*-*-*-*-*-*-*-*-*-*';
AFont:=gdk_font_load(PChar(s));
Result:=AFont<>nil;
if Result then gdk_font_unref(AFont);
end;
function CheckFontNameIsMangledXLogicalFontDesc(const ALongFontName: string
): boolean;
var
c: Integer;
i: Integer;
begin
c:=0;
for i:=1 to length(ALongFontName) do
if ALongFontName[i]='-' then inc(c);
Result:=(c>5) and (c<>14);
if Result then
debugln('WARNING: Fontnamt "',ALongFontName,'" seems to be a XLFD fontname, but has 14<>',dbgs(c),' minus signs');
end;
function GetPixelSize(Offset: Integer): string;
begin
with LogFont do begin
result := IntToStr(Abs(lfHeight)+Offset);
{$IFNDEF OLD_ROTATION}
if lfOrientation <> 0 then begin
SinCos(lfOrientation/1800.*Pi, sn, cs);
cs := cs*(Abs(lfHeight)+Offset);
sn := sn*(Abs(lfHeight)+Offset);
Result := Format('[%.3f %.3f %.3f %.3f]', [cs, sn, -sn, cs]);
repeat
n := Pos('-', Result);
if n > 0 then
Result[n] := '~';
until n <= 0;
end;
end;
{$ENDIF}
end;
begin
// For info about xlfd see:
// http://wwwinfo.cern.ch/umtf/working-groups/X11/fonts/hp_xlfd.html
// Lets fill in all the xlfd parts. Assume we have scalable fonts.
{$IFDEF VerboseFonts}
DebugLn('TGtkWidgetSet.CreateFontIndirectEx A Name=',LogFont.lfFaceName,' Height=',dbgs(LogFont.lfHeight),' LongName=',LongFontName);
{$ENDIF}
Result := 0;
GDIObject := NewGDIObject(gdiFont);
try
GdiObject^.UntransfFontHeight := 0;
GdiObject^.LogFont := LogFont;
CachedFont:=FontCache.FindGTkFontDesc(LogFont,LongFontName);
if CachedFont<>nil then begin
CachedFont.Item.IncreaseRefCount;
GdiObject^.GDIFontObject := TGtkFontCacheItem(CachedFont.Item).GtkFont;
{$IFDEF VerboseFonts}
WriteLn('Was in cache: ', Integer(CachedFont));
{$ENDIF}
exit;
end;
// set default values
FontNameRegistry := '*';
Foundry := '*';
FamilyName := '*';
WeightName := '*';
Slant := '*';
SetwidthName := '*';
AddStyleName := '*';
PixelSize := '*';
PointSize := '*';
ResolutionX := '*';
ResolutionY := '*';
Spacing := '*';
AverageWidth := '*';
CharSetRegistry := '*';
CharSetCoding := '*';
// check if LongFontName is in XLFD format and get nicer defaults
// This way, the user can set X fonts that are not supported by TFont.
{$IFDEF VerboseFonts}
DebugLn('TGtkWidgetSet.CreateFontIndirectEx Name="',LogFont.lfFaceName,'"',
' Long="',LongFontName,'" IsXLFD=',dbgs(IsFontNameXLogicalFontDesc(LongFontName))
,' ',dbgs(ord(LogFont.lfFaceName[0])));
{$ENDIF}
if IsFontNameXLogicalFontDesc(LongFontName) then begin
FontNameRegistry := ExtractXLFDItemMask(LongFontName,0);
Foundry := ExtractXLFDItemMask(LongFontName,1);
FamilyName := ExtractXLFDItemMask(LongFontName,2);
WeightName := ExtractXLFDItemMask(LongFontName,3);
Slant := ExtractXLFDItemMask(LongFontName,4);
SetWidthName := ExtractXLFDItemMask(LongFontName,5);
AddStyleName := ExtractXLFDItemMask(LongFontName,6);
PixelSize := ExtractXLFDItemMask(LongFontName,7);
PointSize := ExtractXLFDItemMask(LongFontName,8);
ResolutionX := ExtractXLFDItemMask(LongFontName,9);
ResolutionY := ExtractXLFDItemMask(LongFontName,10);
Spacing := ExtractXLFDItemMask(LongFontName,11);
AverageWidth := ExtractXLFDItemMask(LongFontName,12);
CharSetRegistry := ExtractXLFDItemMask(LongFontName,13);
CharSetCoding := ExtractXLFDItemMask(LongFontName,14);
end else if CheckFontNameIsMangledXLogicalFontDesc(LongFontName) then begin
// warned
end;
with LogFont do
begin
if lfFaceName[0] = #0
then begin
//DebugLn('ERROR: [TGtkWidgetSet.CreateFontIndirectEx] No fontname');
Exit;
end;
FamilyName := StrPas(lfFaceName);
if not IsFontNameDefault(FamilyName) then begin
// check if we have foundry encoded in family name
n := pos(FOUNDRYCHAR_OPEN, FamilyName);
if n<>0 then begin
Foundry := copy(FamilyName, n+1, Length(FamilyName));
familyName := trim(copy(familyName, 1, n-1));
n := pos(FOUNDRYCHAR_CLOSE, Foundry);
if n<>0 then
Delete(Foundry, n, Length(Foundry));
end;
if not FamilyNameExists then
FamilyName:='default';
end;
if IsFontNameDefault(FamilyName) then begin
{$IFDEF VerboseFonts}
DebugLn('TGtkWidgetSet.CreateFontIndirectEx FamilyName="',FamilyName,'" PixelSize=',PixelSize,' LogFont.lfHeight=',dbgs(LogFont.lfHeight));
{$ENDIF}
if (LogFont.lfHeight=0) then begin
LoadDefaultFont;
exit;
end else begin
FamilyName:=GetDefaultFontFamilyName;
Foundry:='*';
end;
end;
//DebugLn(Format('trace: [TGtkWidgetSet.CreateFontIndirectEx] Name: %s, Height: %d', [FamilyName, lfHeight]));
// calculate weight offset.
// API XLFD
// --------------------- --------------
// Weight=400 --> normal normal
// Weight=700 --> bold normal+4000 (or bold in non scalable fonts)
//
// So in API the offset for normal = 400 and an increase of 300 equals to
// an offset of 4000
if WeightName='*' then begin
case lfWeight of
FW_DONTCARE : WeightName := '*';
FW_LIGHT : WeightName := 'light';
FW_NORMAL : ; // try several later
FW_MEDIUM : WeightName := 'medium';
FW_SEMIBOLD : WeightName := 'demi bold';
FW_BOLD : ; // try several later
else begin
n := ((lfWeight - FW_NORMAL) * 4000) div (FW_BOLD - FW_NORMAL);
if n = 0
then WeightName := 'normal'
else if n > 0
then WeightName := Format('normal+%d', [n])
else WeightName := Format('normal%d', [n]);
end;
end;
end;
if Slant='*' then begin
// TODO: find out if escapement has something to do with slant
if lfItalic = 0 then Slant := 'r' else Slant := 'i';
end;
// SetWidthName := '*';
{$IFDEF OLD_ROTATION}
if AddStyleName='*' then begin
// calculate Style name extensions (=rotation)
// API XLFD
// --------------------- --------------
// Orientation 1/10 deg 1/64 deg
if lfOrientation = 0
then AddStyleName := '*'
else begin
n := (lfOrientation * 64) div 10;
if n >= 0
then AddStyleName := Format('+%d', [n])
else AddStyleName := Format('+%d', [n]);
end;
end;
{$ENDIF}
CalcPixelSize:= (PixelSize='*') and (PointSize='*');
if CalcPixelSize then begin
// TODO: make more accurate (implement the meaning of
// positive and negative height values.
PixelSize := GetPixelSize(0);
// Since we use pixelsize, it isn't allowed to give a value here
PointSize := '*';
// Use the default
ResolutionX := '*';
ResolutionY := '*';
end;
if Spacing='*' then begin
// spacing
if (FIXED_PITCH and lfPitchAndFamily)>0 then
Spacing := 'm' // mono spaced
else if (VARIABLE_PITCH and lfPitchAndFamily)>0 then
Spacing := 'p' // proportional spaced
else
Spacing := '*';
end;
if AverageWidth='*' then begin
// calculate AverageWidth
// API XLFD
// --------------------- --------------
// Width pixel 1/10 pixel
if lfWidth = 0
then AverageWidth := '*'
else AverageWidth := InttoStr(lfWidth * 10);
end;
// this section tries several combinations of charset-weightname-slant
//
WeightList := TStringList.Create;
if LogFOnt.LfWeight = FW_BOLD then
// bold appears most times
WeightList.CommaText := 'bold,semibold,demibold,black,*'
else
// medium appears most times but if there is normal, use it
WeightList.CommaText := 'normal,medium,regular,light,*';
if WeightName<>'*' then
WeightList.Insert(0, WeightName);
try
if LoadFontEx then
exit;
// not found yet, before doing a generic fall over
// try to do a more specific guess.
if CalcPixelSize then
repeat
// try one pixel smaller
{$IFDEF VerboseFonts}
debugln('TGtkWidgetSet.CreateFontIndirectEx, LoadFontEx: try one pixel smaller');
{$ENDIF}
PixelSize:=GetPixelSize(-1);
if LoadFontEx then
exit;
// try one pixel bigger
{$IFDEF VerboseFonts}
debugln('TGtkWidgetSet.CreateFontIndirectEx, LoadFontEx: try one pixel bigger');
{$ENDIF}
PixelSize:=GetPixelSize(1); // try
if LoadFontEx then
exit;
// not found yet
// if font was slanted try with any within font face.
if Slant<>'*' then begin
Slant := '*';
continue;
end;
break;
until false;
finally
WeightList.Free;
end;
end;
// next checks are fall over
{$IFDEF VerboseFonts}
debugln('TGtkWidgetSet.CreateFontIndirectEx ');
{$ENDIF}
{
if LoadFont then exit;
// try all weights
WeightName := '*';
if LoadFont then exit;
}
// try one height smaller
{$IFDEF VerboseFonts}
debugln('TGtkWidgetSet.CreateFontIndirectEx try one height smaller');
{$ENDIF}
PixelSize := IntToStr(Abs(LogFont.lfHeight)-1);
// Since we use pixelsize, it isn't allowed to give a value here
PointSize := '*';
// Use the default
ResolutionX := '*';
ResolutionY := '*';
if LoadFont then exit;
// try one height bigger
{$IFDEF VerboseFonts}
debugln('TGtkWidgetSet.CreateFontIndirectEx try one height bigger');
{$ENDIF}
PixelSize := IntToStr(Abs(LogFont.lfHeight)+1);
if LoadFont then exit;
PixelSize := IntToStr(Abs(LogFont.lfHeight));
// try instead of mono spaced -> character cell spaced
if (Spacing='m') then begin
{$IFDEF VerboseFonts}
debugln('TGtkWidgetSet.CreateFontIndirectEx try instead of mono spaced -> character cell spaced');
{$ENDIF}
Spacing:='c';
if LoadFont then exit;
end;
{
// try instead of italic -> oblique
if (Slant='i') then begin
Slant := 'o';
if LoadFont then exit;
end;
// try all slants
Slant := '*';
if LoadFont then exit;
}
// try all spacings
if spacing<>'*' then begin
{$IFDEF VerboseFonts}
debugln('TGtkWidgetSet.CreateFontIndirectEx try all spacings');
{$ENDIF}
Spacing := '*';
if LoadFont then exit;
end;
if charSetCoding<>'*' then begin
{$IFDEF VerboseFonts}
debugln('TGtkWidgetSet.CreateFontIndirectEx try all charsets');
{$ENDIF}
charsetCoding := '*';
charSetRegistry:= '*';
if LoadFont then exit;
end;
if (Foundry<>'*') then begin
// try all Families
{$IFDEF VerboseFonts}
debugln('TGtkWidgetSet.CreateFontIndirectEx try all families');
{$ENDIF}
PixelSize := IntToStr(Abs(LogFont.lfHeight));
FamilyName := '*';
if LoadFont then exit;
end;
// nothing exists -> use default
LoadDefaultFont;
finally
if GdiObject^.GDIFontObject = nil
then begin
{$IFDEF VerboseFonts}
DebugLn('[TGtkWidgetSet.CreateFontIndirect] ',DbgS(GdiObject),' ',dbgs(FGDIObjects.Count));
{$ENDIF}
ReleaseGDIObject(GdiObject);
Result := 0;
end
else begin
Result := HFONT(PtrUInt(GdiObject));
end;
if Result = 0
then
DebugLn('WARNING: [TGtkWidgetSet.CreateFontIndirectEx] NOT found XLFD: <'+LongFontName+'> Fontname="'+LogFont.lfFaceName+'"')
else begin
//DebugLn(Format('Trace: [TGtkWidgetSet.CreateFontIndirectEx] found XLFD: <%s>', [LongFontName]));
end;
end;
end;
{$EndIf}
function TGTKWidgetSet.CreateIconIndirect(IconInfo: PIconInfo): HICON;
procedure GetColorMask(AImage, AMask: PGDKPixmap; AImgBits, AMskBits: PByte; AWidth, AHeight: integer);
var
i, j: integer;
colormap: PGDKColormap;
Image, MaskImage: PGDKImage;
GDKColor: TGDKColor;
Pixel, MaskPixel: LongWord;
offset: byte;
procedure SetColorAndMaskPixmap(c: TGdkColor; MaskPixel: LongWord);
var
c_bit, m_bit: byte;
begin
// c_bit := Ord(0.222 * c.red + 0.707 * c.green + 0.071 * c.blue >= $8000);
// do some int math
c_bit := Ord(cardinal(222) * c.red
+ cardinal(707) * c.green
+ cardinal(071) * c.blue
>= $8000 * 1000);
m_bit := ord(MaskPixel = 1);
AImgBits^ := AImgBits^ or (c_bit shl offset);
AMskBits^ := AMskBits^ or (m_bit shl offset);
inc(offset);
if offset > 7 then
begin
inc(AImgBits);
inc(AMskBits);
offset := 0;
end;
end;
procedure SetColorAndMaskBitmap(ColorPixel, MaskPixel: LongWord);
begin
AImgBits^ := AImgBits^ or (ColorPixel shl offset);
AMskBits^ := AMskBits^ or (MaskPixel shl offset);
inc(offset);
if offset > 7 then
begin
inc(AImgBits);
inc(AMskBits);
offset := 0;
end;
end;
begin
// most of this code was taken from TGtkWidgetSet.DCGetPixel
Image := gdk_drawable_get_image(AImage, 0, 0, AWidth, AHeight);
if AMask = nil
then MaskImage := nil
else MaskImage := gdk_drawable_get_image(AMask, 0, 0, AWidth, AHeight);
offset := 0;
if gdk_drawable_get_depth(AImage) = 1 then
begin
for j := 0 to AHeight - 1 do
for i := 0 to AWidth - 1 do
begin
Pixel := gdk_image_get_pixel(Image, i, j);
if MaskImage = nil
then MaskPixel := 1
else MaskPixel := gdk_image_get_pixel(MaskImage, i, j);
SetColorAndMaskBitmap(Pixel, MaskPixel);
end;
end
else
begin
{$ifdef Gtk1}
// previously gdk_image_get_colormap(image) was used, implementation
// was casting GdkImage to GdkWindow which is not valid and cause AVs
if gdk_window_get_type(PGdkWindow(AImage))= GDK_WINDOW_PIXMAP then
colormap := nil // pixmaps are created with null colormap, get system one instead
else
colormap := gdk_window_get_colormap(PGdkWindow(AImage));
{$else}
colormap := gdk_image_get_colormap(image);
{$endif}
if colormap = nil then
colormap := gdk_colormap_get_system;
for j := 0 to AHeight - 1 do
for i := 0 to AWidth - 1 do
begin
Pixel := gdk_image_get_pixel(Image, i, j);
if MaskImage = nil
then MaskPixel := 1
else MaskPixel := gdk_image_get_pixel(MaskImage, i, j);
FillChar(GDKColor,SizeOf(GDKColor), 0);
gdk_colormap_query_color(colormap, Pixel, @GDKColor);
SetColorAndMaskPixmap(GDKColor, MaskPixel);
end;
end;
gdk_image_unref(Image);
if MaskImage <> nil
then gdk_image_unref(MaskImage);
end;
var
FG, BG: TGDKColor;
Img, Msk: PGdkPixmap;
Pixbuf: PGdkPixbuf;
srcbitmap, mskbitmap: PGdkBitmap;
W, H, bitlen: integer;
ImgBits, MskBits: array of byte;
begin
Result := 0;
if not IsValidGDIObject(IconInfo^.hbmColor) then Exit;
if PGDIObject(IconInfo^.hbmColor)^.GDIBitmapType = gbPixbuf then
begin
Pixbuf := PGDIObject(IconInfo^.hbmColor)^.GDIPixbufObject;
if IconInfo^.fIcon then
begin
// Creating PixBuf from pixmap and mask
Result := HICON(PtrUInt(gdk_pixbuf_copy(pixbuf)));
Exit;
end;
W := gdk_pixbuf_get_width(Pixbuf);
H := gdk_pixbuf_get_height(Pixbuf);
Img := nil;
Msk := nil;
gdk_pixbuf_render_pixmap_and_mask(Pixbuf, Img, Msk, $80);
end
else
begin
Img := PGDIObject(IconInfo^.hbmColor)^.GDIBitmapObject;
gdk_drawable_get_size(Img, @W, @H);
Msk := CreateGdkMaskBitmap(IconInfo^.hbmColor, IconInfo^.hbmMask);
//DbgDumpPixmap(Img, 'Image');
//DbgDumpPixmap(Msk, 'Mask');
if IconInfo^.fIcon then
begin
// Creating PixBuf from pixmap and mask
Result := HICON(PtrUInt(CreatePixbufFromImageAndMask(Img, 0, 0, W, H, nil, Msk)));
if Msk <> nil then
gdk_bitmap_unref(Msk);
Exit;
end;
end;
try
// Create cursor
bitlen := (W * H) shr 3;
SetLength(ImgBits, bitlen);
SetLength(MskBits, bitlen);
FillChar(ImgBits[0], bitlen, 0);
FillChar(MskBits[0], bitlen, 0);
GetColorMask(Img, Msk, @ImgBits[0], @MskBits[0], W, H);
srcbitmap := gdk_bitmap_create_from_data(nil, Pgchar(@ImgBits[0]), W, H);
mskbitmap := gdk_bitmap_create_from_data(nil, Pgchar(@MskBits[0]), W, H);
// white
fg.red := $FFFF;
fg.green := $FFFF;
fg.blue := $FFFF;
fg.pixel := 0;
// black
bg.red := 0;
bg.green := 0;
bg.blue := 0;
bg.pixel := 0;
Result := HCURSOR(PtrUInt(gdk_cursor_new_from_pixmap(srcbitmap, mskbitmap,
@fg, @bg, IconInfo^.xHotspot, IconInfo^.yHotspot)));
gdk_pixmap_unref(srcbitmap);
gdk_pixmap_unref(mskbitmap);
finally
if msk <> nil
then gdk_bitmap_unref(msk);
if Img <> PGDIObject(IconInfo^.hbmColor)^.GDIBitmapObject
then gdk_pixmap_unref(Img);
end;
end;
{------------------------------------------------------------------------------
Function: CreatePalette
Params: LogPalette
Returns: a handle to the Palette created
------------------------------------------------------------------------------}
function TGtkWidgetSet.CreatePalette(const LogPalette: TLogPalette): HPALETTE;
var
GObject: PGdiObject;
begin
//DebugLn('trace:[TGtkWidgetSet.CreatePalette]');
GObject := NewGDIObject(gdiPalette);
GObject^.SystemPalette := False;
GObject^.PaletteRealized := False;
GObject^.VisualType := GDK_VISUAL_PSEUDO_COLOR;
GObject^.PaletteVisual := nil;
{$IFDEF DebugGDKTraps}
BeginGDKErrorTrap;
{$ENDIF}
GObject^.PaletteVisual := gdk_visual_get_best_with_type(GObject^.VisualType);
if GObject^.PaletteVisual = nil
then begin
GObject^.PaletteVisual := GDK_Visual_Get_System;
GDK_Visual_Ref(GObject^.PaletteVisual);
end;
GObject^.PaletteColormap := GDK_Colormap_new(GObject^.PaletteVisual, GdkTrue);
{$IFDEF DebugGDKTraps}
EndGDKErrorTrap;
{$ENDIF}
GObject^.RGBTable := TDynHashArray.Create(-1);
GObject^.RGBTable.OnGetKeyForHashItem:=@GetRGBAsKey;
GObject^.IndexTable := TDynHashArray.Create(-1);
GObject^.IndexTable.OnGetKeyForHashItem:=@GetIndexAsKey;
InitializePalette(GObject, LogPalette.palPalEntry, LogPalette.palNumEntries);
Result := HPALETTE(PtrUInt(GObject));
end;
{------------------------------------------------------------------------------
Function: CreatePenIndirect
Params: none
Returns: Nothing
------------------------------------------------------------------------------}
function TGtkWidgetSet.CreatePenIndirect(const LogPen: TLogPen): HPEN;
var
GObject: PGdiObject;
begin
//DebugLn('trace:[TGtkWidgetSet.CreatePenIndirect]');
//write('CreatePenIndirect->');
GObject := NewGDIObject(gdiPen);
GObject^.UnTransfPenWidth := 0;
GObject^.GDIPenDashes := nil;
GObject^.IsExtPen := False;
with LogPen do
begin
GObject^.GDIPenStyle := lopnStyle;
GObject^.GDIPenWidth := lopnWidth.X;
SetGDIColorRef(GObject^.GDIPenColor,lopnColor);
end;
Result := HPEN(PtrUInt(GObject));
end;
{------------------------------------------------------------------------------
Method: CreatePolygonRgn
Params: Points, NumPts, FillMode
Returns: the handle to the region
Creates a Polygon, a closed many-sided shaped region. The Points parameter is
an array of points that give the vertices of the polygon. FillMode=Winding
determines what points are going to be included in the region. When Winding
is True, points are selected by using the Winding fill algorithm. When Winding
is False, points are selected by using using the even-odd (alternative) fill
algorithm. NumPts indicates the number of points to use.
The first point is always connected to the last point.
------------------------------------------------------------------------------}
function TGtkWidgetSet.CreatePolygonRgn(Points: PPoint; NumPts: Integer;
FillMode: integer): HRGN;
var
i: integer;
PointArray: PGDKPoint;
GObject: PGdiObject;
fr : TGDKFillRule;
begin
Result := 0;
if NumPts<=0 then exit;
GObject := NewGDIObject(gdiRegion);
GetMem(PointArray,SizeOf(TGdkPoint)*NumPts);
for i:=0 to NumPts-1 do begin
PointArray[i].x:=Points[i].x;
PointArray[i].y:=Points[i].y;
end;
If FillMode=Winding then
fr := GDK_WINDING_RULE
else
fr := GDK_EVEN_ODD_RULE;
GObject^.GDIRegionObject := gdk_region_polygon(PointArray, NumPts, fr);
FreeMem(PointArray);
Result := HRGN(PtrUInt(GObject));
end;
{------------------------------------------------------------------------------
Function: CreateRectRgn
Params: none
Returns: Nothing
------------------------------------------------------------------------------}
function TGtkWidgetSet.CreateRectRgn(X1,Y1,X2,Y2 : Integer): HRGN;
var
R: TGDKRectangle;
RRGN: PGDKRegion;
GObject: PGdiObject;
RegionObj: PGdkRegion;
begin
GObject := NewGDIObject(gdiRegion);
if X1<=X2 then begin
R.X := gint16(X1);
R.Width := X2 - X1;
end else begin
R.X := gint16(X2);
R.Width := X1 - X2;
end;
if Y1<=Y2 then begin
R.Y := gint16(Y1);
R.Height := Y2 - Y1;
end else begin
R.Y := gint16(Y2);
R.Height := Y1 - Y1;
end;
RRGN := gdk_region_new;
RegionObj:=PGdkRegion(gdk_region_union_with_rect(RRGN,@R));
GObject^.GDIRegionObject := RegionObj;
gdk_region_destroy(RRGN);
Result := HRGN(PtrUInt(GObject));
//DebugLn('TGtkWidgetSet.CreateRectRgn A ',GDKRegionAsString(RegionObj));
end;
{------------------------------------------------------------------------------
Function: CombineRgn
Params: Dest, Src1, Src2, fnCombineMode
Returns: longint
Combine the 2 Source Regions into the Destination Region using the specified
Combine Mode. The Destination must already be initialized. The Return value
is the Destination's Region type, or ERROR.
The Combine Mode can be one of the following:
RGN_AND : Gets a region of all points which are in both source regions
RGN_COPY : Gets an exact copy of the first source region
RGN_DIFF : Gets a region of all points which are in the first source
region but not in the second.(Source1 - Source2)
RGN_OR : Gets a region of all points which are in either the first
source region or in the second.(Source1 + Source2)
RGN_XOR : Gets all points which are in either the first Source Region
or in the second, but not in both.
The result can be one of the following constants
Error
NullRegion
SimpleRegion
ComplexRegion
------------------------------------------------------------------------------}
function TGtkWidgetSet.CombineRgn(Dest, Src1, Src2 : HRGN;
fnCombineMode : Longint) : Longint;
var
Continue : Boolean;
D, S1, S2 : PGDKRegion;
DObj, S1Obj, S2Obj : PGDIObject;
begin
Result := SIMPLEREGION;
DObj := PGdiObject(Dest);
S1Obj := PGdiObject(Src1);
S2Obj := PGdiObject(Src2);
Continue := IsValidGDIObject(Dest) and IsValidGDIObject(Src1)
and IsValidGDIObject(Src2);
If Not Continue then begin
DebugLn('WARNING: [TGtkWidgetSet.CombineRgn] Invalid HRGN');
Result := Error;
end
else begin
S1 := S1Obj^.GDIRegionObject;
S2 := S2Obj^.GDIRegionObject;
//DebugLn('TGtkWidgetSet.CombineRgn A fnCombineMode=',Dbgs(fnCombineMode));
Case fnCombineMode of
RGN_AND :
D := PGDKRegion(gdk_region_intersect(S1, S2));
RGN_COPY :
D := gdk_region_copy(S1);
RGN_DIFF :
D := PGDKRegion(gdk_region_subtract(S1, S2));
RGN_OR :
D := PGDKRegion(gdk_region_union(S1, S2));
RGN_XOR :
D := PGDKRegion(gdk_region_xor(S1, S2));
else begin
Result:= ERROR;
D := nil;
end;
end;
if DObj^.GDIRegionObject <> nil then
gdk_region_destroy(DObj^.GDIRegionObject);
DObj^.GDIRegionObject := D;
Result := RegionType(D);
//DebugLn('TGtkWidgetSet.CombineRgn B Mode=',dbgs(fnCombineMode),
// ' S1=',GDKRegionAsString(S1),' S2=',GDKRegionAsString(S2),' D=',GDKRegionAsString(D),'');
end;
end;
{------------------------------------------------------------------------------
Function: DeleteDC
Params: none
Returns: Nothing
------------------------------------------------------------------------------}
function TGtkWidgetSet.DeleteDC(hDC: HDC): Boolean;
begin
// TODO:
// for now it's just the same, however CreateDC/FreeDC
// and GetDC/ReleaseDC are couples
// we should use gdk_new_gc for create and gtk_new_gc for Get
Result:= (ReleaseDC(0, hDC) = 1);
end;
{------------------------------------------------------------------------------
Function: DeleteObject
Params: none
Returns: Nothing
DeleteObject is allowed while the object is still selected. The msdn docs
are misleading. Marc tested with resource profiler under win XP.
------------------------------------------------------------------------------}
function TGtkWidgetSet.DeleteObject(GDIObject: HGDIOBJ): Boolean;
procedure RaiseInvalidGDIObject;
begin
{$ifdef TraceGdiCalls}
DebugLn();
DebugLn('TGtkWidgetSet.DeleteObject: TraceCall for invalid object: ');
DumpBackTrace(PgdiObject(GdiObject)^.StackAddrs);
DebugLn();
DebugLn('Exception will follow:');
DebugLn();
{$endif}
RaiseGDBException('TGtkWidgetSet.DeleteObject invalid GdiObject='+dbgs(GdiObject));
end;
var
GDIObjectExists: boolean;
begin
if GDIObject = 0 then
begin
Result := True;
Exit;
end;
{$IFDEF DebugLCLComponents}
if DebugGdiObjects.IsDestroyed(GDIObject) then
begin
DebugLn(['TGtkWidgetSet.DeleteObject object already deleted ',GDIObject]);
debugln(DebugGdiObjects.GetInfo(PGdiObject(GDIObject),true));
Halt;
end;
{$ENDIF}
// Find out if we want to release internal GDI object
GDIObjectExists := FGDIObjects.Contains(PGdiObject(GDIObject));
Result := GDIObjectExists;
if not GDIObjectExists then
begin
RaiseInvalidGDIObject;
end;
Result := ReleaseGDIObject(PGdiObject(GDIObject));
end;
{------------------------------------------------------------------------------
Function: DestroyCaret
Params: none
Returns: Nothing
------------------------------------------------------------------------------}
function TGtkWidgetSet.DestroyCaret(Handle: HWND): Boolean;
var
GTKObject: PGTKObject;
begin
GTKObject := PGTKObject(Handle);
Result := true;
if GTKObject<>nil then begin
if gtk_type_is_a(gtk_object_type(GTKObject), GTKAPIWidget_GetType)
then begin
GTKAPIWidget_DestroyCaret(PGTKAPIWidget(GTKObject));
end
// else if // TODO: other widgettypes
else begin
Result := False;
end;
end
else begin
//DebugLn('Trace:WARNING: [TGtkWidgetSet.DestroyCaret] Got null HWND');
end;
end;
{------------------------------------------------------------------------------
Function: DrawFrameControl
Params:
Returns:
------------------------------------------------------------------------------}
function TGtkWidgetSet.DrawFrameControl(DC: HDC; const Rect : TRect;
uType, uState : Cardinal) : Boolean;
{const
ADJUST_FLAG: array[Boolean] of Integer = (0, BF_ADJUST);
PUSH_EDGE_FLAG: array[Boolean] of Integer = (EDGE_RAISED, EDGE_SUNKEN);
PUSH_EDGE_FLAG2: array[Boolean] of Integer = (0, BF_FLAT);}
var
DevCtx: TGtkDeviceContext absolute DC;
Widget: PGtkWidget;
R: TRect;
procedure DrawButtonPush;
var
State: TGtkStateType;
Shadow: TGtkShadowType;
aStyle : PGTKStyle;
aDC: TGtkDeviceContext;
DCOrigin: TPoint;
begin
//if Widget<>nil then begin
// use the gtk paint functions to draw a widget style dependent button
//writeln('DrawButtonPush ',
// ' DFCS_BUTTONPUSH=',uState and DFCS_BUTTONPUSH,
// ' DFCS_PUSHED=',uState and DFCS_PUSHED,
// ' DFCS_INACTIVE=',uState and DFCS_INACTIVE,
// ' DFCS_FLAT=',uState and DFCS_FLAT,
// '');
// set State (the interior filling style)
if (DFCS_PUSHED and uState)<>0 then
State := GTK_STATE_ACTIVE //button pressed(GTK ignores disabled)
else if (DFCS_INACTIVE and uState)<>0 then
State := GTK_STATE_INSENSITIVE //button disabled
else if (DFCS_HOT and uState)<>0 then
State := GTK_STATE_PRELIGHT // button enabled, special (e.g. mouse over)
else
State := GTK_STATE_NORMAL; // button enabled, normal
// set Shadow (the border style)
if (DFCS_PUSHED and uState)<>0 then begin
// button down
Shadow:=GTK_SHADOW_IN;
end else begin
if (((DFCS_FLAT+DFCS_CHECKED) and uState)=DFCS_FLAT) then begin
// button up, flat, no special
Shadow:=GTK_SHADOW_ETCHED_OUT;
//Shadow:=GTK_SHADOW_NONE;
end else begin
// button up
Shadow:=GTK_SHADOW_OUT;
end;
end;
aDC:=TGtkDeviceContext(DC);
DCOrigin:= aDC.Offset;
If Widget <> nil then
aStyle := gtk_widget_get_style(Widget)
else
aStyle := GetStyle(lgsButton);
If aStyle = nil then
aStyle := GetStyle(lgsGTK_Default);
// MG: You can't assign a style to any window. Why it is needed anyway?
//aStyle := gtk_style_attach(gtk_style_ref(aStyle),aDC.Drawable);
if aStyle<>nil then begin
If (Shadow=GTK_SHADOW_NONE) then
gtk_paint_flat_box(aStyle,aDC.Drawable,
State,
Shadow,
nil,
GetStyleWidget(lgsButton),
'button',
R.Left+DCOrigin.X,R.Top+DCOrigin.Y,
R.Right-R.Left,R.Bottom-R.Top)
else
gtk_paint_box(aStyle,aDC.Drawable,
State,
Shadow,
nil,
GetStyleWidget(lgsButton),
'button',
R.Left+DCOrigin.X,R.Top+DCOrigin.Y,
R.Right-R.Left,R.Bottom-R.Top);
end;
Result := True;
end;
procedure DrawCheckOrRadioButton(IsRadioButton: Boolean);
const
LazGtkStyleMap: array[Boolean] of TLazGtkStyle = (lgsCheckbox, lgsRadiobutton);
var
State: TGtkStateType;
Shadow: TGtkShadowType;
aDC: TGtkDeviceContext;
DCOrigin: TPoint;
Style : PGTKStyle;
Widget : PGTKWidget;
begin
// use the gtk paint functions to draw a widget style dependent check/radio button
if (DFCS_BUTTON3STATE and uState)<>0 then
Shadow := GTK_SHADOW_ETCHED_IN //3state style
else if (DFCS_CHECKED and uState)<>0 then
Shadow := GTK_SHADOW_IN //checked style
else
Shadow := GTK_SHADOW_OUT; //unchecked style
if (DFCS_PUSHED and uState)<>0 then
State := GTK_STATE_ACTIVE //button pressed(GTK ignores disabled)
else if (DFCS_INACTIVE and uState)<>0 then
State := GTK_STATE_INSENSITIVE //button disabled
else if (DFCS_HOT and uState)<>0 then
State := GTK_STATE_PRELIGHT // button enabled, special (e.g. mouse over)
else
State := GTK_STATE_NORMAL; // button enabled, normal
aDC:=TGtkDeviceContext(DC);
DCOrigin := aDC.Offset;
Style := GetStyle(LazGtkStyleMap[IsRadioButton]);
If Style = nil then begin
Style := GetStyle(lgsGTK_Default);
If Style <> nil then
Style := gtk_style_attach(gtk_style_ref(Style),aDC.Drawable);
end;
Widget := GetStyleWidget(LazGtkStyleMap[IsRadioButton]);
If Widget = nil then
Widget := GetStyleWidget(lgsDefault);
If Widget <> nil then
Widget^.Window := aDC.Drawable;
Result := Style <> nil;
If Result then begin
if IsRadioButton then
gtk_paint_option(Style,aDC.Drawable, State,
Shadow, nil, Widget, 'radiobutton',
R.Left+DCOrigin.X,R.Top+DCOrigin.Y,
R.Right-R.Left, R.Bottom-R.Top)
else
gtk_paint_check(Style,aDC.Drawable, State,
Shadow, nil, Widget, 'checkbutton',
R.Left+DCOrigin.X,R.Top+DCOrigin.Y,
R.Right-R.Left, R.Bottom-R.Top);
end;
end;
var
ClientWidget: PGtkWidget;
begin
Result := False;
if IsValidDC(DC) then
begin
if DevCtx.HasTransf then
begin
R := DevCtx.TransfRectIndirect(Rect);
DevCtx.TransfNormalize(R.Left, R.Right);
DevCtx.TransfNormalize(R.Top, R.Bottom);
end else
R := Rect;
Widget:=TGtkDeviceContext(DC).Widget;
//It's possible to draw in a DC without a widget, e.g., a Bitmap
if Widget <> nil then
begin
ClientWidget:=GetFixedWidget(Widget);
if ClientWidget<>nil then
Widget:=ClientWidget;
end;
end else
Widget:=nil;
case uType of
DFC_CAPTION:
begin //all draw CAPTION commands here
end;
DFC_MENU:
begin
end;
DFC_SCROLL:
begin
end;
DFC_BUTTON:
begin
//DebugLn(Format('Trace: [TGtkWidgetSet.DrawFrameControl] DFC_BUTTON --> draw rect = %d,%d,%d,%d',[R.Left,R.Top,R.Right,R.Bottom]));
//figure out the style first
if (uState and $1F) in [DFCS_BUTTONCHECK, DFCS_BUTTON3STATE] then
begin
//DebugLn('Trace:State ButtonCheck');
DrawCheckOrRadioButton(False);
end
else if (DFCS_BUTTONRADIO and uState) <> 0 then
begin
//DebugLn('Trace:State ButtonRadio');
DrawCheckOrRadioButton(True);
end
else if (DFCS_BUTTONPUSH and uState) <> 0 then
begin
//DebugLn('Trace:State ButtonPush');
DrawButtonPush;
end
else if (DFCS_BUTTONRADIOIMAGE and uState) <> 0 then
begin
//DebugLn('Trace:State ButtonRadioImage');
end
else if (DFCS_BUTTONRADIOMASK and uState) <> 0 then
begin
//DebugLn('Trace:State ButtonRadioMask');
end
else
DebugLn(Format('ERROR: [TGtkWidgetSet.DrawFrameControl] Unknown State 0x%x', [uState]));
end;
else
DebugLn(Format('ERROR: [TGtkWidgetSet.DrawFrameControl] Unknown type %d', [uType]));
end;
end;
function TGTKWidgetSet.DrawFocusRect(DC: HDC; const Rect: TRect): boolean;
var
DevCtx: TGtkDeviceContext absolute DC;
Origin: TPoint;
procedure DrawPixel(X1,Y1: Integer);
begin
inc(X1,Origin.X);
inc(Y1,Origin.Y);
gdk_draw_point(TGtkDeviceContext(DC).Drawable, TGtkDeviceContext(DC).GC, X1, Y1);
end;
procedure DrawVertLine(X1,Y1,Y2: integer);
begin
if Y2<Y1 then
while Y2<Y1 do begin
DrawPixel(X1, Y1);
dec(Y1, 2);
end
else
while Y1<Y2 do begin
DrawPixel(X1, Y1);
inc(Y1, 2);
end;
end;
procedure DrawHorzLine(X1,Y1,X2: integer);
begin
if X2<X1 then
while X2<X1 do begin
DrawPixel(X1, Y1);
dec(X1, 2);
end
else
while X1<X2 do begin
DrawPixel(X1, Y1);
inc(X1, 2);
end;
end;
var
OldROP: Integer;
APen, TempPen: HPEN;
LogPen : TLogPen;
R: TRect;
begin
Result := False;
if IsValidDC(DC) then begin
with LogPen do begin
lopnStyle := PS_DOT;
lopnWidth.X := 2;
lopnColor := clWhite;
end;
if DevCtx.HasTransf then
R := DevCtx.TransfRectIndirect(Rect)
else
R := Rect;
APen := CreatePenIndirect(LogPen);
TempPen := SelectObject(DC, APen);
OldRop := SetROP2(DC, R2_XORPEN);
Origin := DevCtx.Offset;
try
with R do begin
DrawHorzLine(Left, Top, Right-1);
DrawVertLine(Right-1, Top, Bottom-1);
DrawHorzLine(Right-1, Bottom-1, Left);
DrawVertLine(Left, Bottom-1, Top);
end;
Result := True;
finally
SelectObject(DC, TempPen);
DeleteObject(APen);
SetROP2(DC, OldROP);
end;
end;
end;
{------------------------------------------------------------------------------
Function: DrawEdge
Params: DC: HDC; var Rect: TRect; edge: Cardinal; grfFlags: Cardinal
Returns: Boolean
Draws one or more edges of a rectangle. The rectangle is the area
Left to Right-1 and Top to Bottom-1.
------------------------------------------------------------------------------}
function TGtkWidgetSet.DrawEdge(DC: HDC; var ARect: TRect; Edge: Cardinal;
grfFlags: Cardinal): Boolean;
var
DevCtx: TGtkDeviceContext absolute DC;
procedure DrawEdges(var R: TRect; GC: pgdkGC; Drawable:PGdkDrawable;
const TopLeftColor, BottomRightColor: TGDKColor);
begin
gdk_gc_set_foreground(GC, @TopLeftColor);
if (grfFlags and BF_TOP) = BF_TOP then begin
gdk_draw_line(Drawable, GC, R.Left, R.Top, R.Right, R.Top);
inc(R.Top);
end;
if (grfFlags and BF_LEFT) = BF_LEFT then begin
gdk_draw_line(Drawable, GC, R.Left, R.Top, R.Left, R.Bottom);
inc(R.Left);
end;
gdk_gc_set_foreground(GC, @BottomRightColor);
if (grfFlags and BF_BOTTOM) = BF_BOTTOM then begin
gdk_draw_line(Drawable, GC, R.Left, R.Bottom-1, R.Right, R.Bottom-1);
dec(R.Bottom);
end;
if (grfFlags and BF_RIGHT) = BF_RIGHT then begin
gdk_draw_line(Drawable, GC, R.Right-1, R.Top, R.Right-1, R.Bottom);
dec(R.Right);
end;
end;
var
InnerTL, OuterTL,
InnerBR, OuterBR, MiddleColor: TGDKColor;
BInner, BOuter: Boolean;
R: TRect;
DCOrigin: TPoint;
begin
//DebugLn('TGtkWidgetSet.DrawEdge Edge=',DbgS(Edge),8),' grfFlags=',DbgS(Cardinal(grfFlags));
Result := IsValidDC(DC);
if Result
then with TGtkDeviceContext(DC) do
begin
R := ARect;
if DevCtx.HasTransf then
begin
R := DevCtx.TransfRectIndirect(R);
TransfNormalize(R.Left, R.Right);
TransfNormalize(R.Top, R.Bottom);
end;
DCOrigin := Offset;
OffsetRect(R,DCOrigin.X,DCOrigin.Y);
// try to use the gdk functions, so that the current theme is used
BInner := False;
BOuter := False;
// TODO: change this to real colors
if (edge and BDR_RAISEDINNER) = BDR_RAISEDINNER
then begin
InnerTL := AllocGDKColor(GetSysColor(COLOR_BTNHIGHLIGHT));
InnerBR := AllocGDKColor(GetSysColor(COLOR_BTNSHADOW));
BInner := True;
end;
if (edge and BDR_SUNKENINNER) = BDR_SUNKENINNER
then begin
InnerTL := AllocGDKColor(GetSysColor(COLOR_BTNSHADOW));
InnerBR := AllocGDKColor(GetSysColor(COLOR_BTNHIGHLIGHT));
BInner := True;
end;
if (edge and BDR_RAISEDOUTER) = BDR_RAISEDOUTER
then begin
OuterTL := AllocGDKColor(GetSysColor(COLOR_BTNHIGHLIGHT));
OuterBR := AllocGDKColor(GetSysColor(COLOR_BTNSHADOW));
BOuter := True;
end;
if (edge and BDR_SUNKENOUTER) = BDR_SUNKENOUTER
then begin
OuterTL := AllocGDKColor(GetSysColor(COLOR_BTNSHADOW));
OuterBR := AllocGDKColor(GetSysColor(COLOR_BTNHIGHLIGHT));
BOuter := True;
end;
gdk_gc_set_fill(GC, GDK_SOLID);
SelectedColors := dcscCustom;
// Draw outer rect
if BOuter then
DrawEdges(R, GC,Drawable,OuterTL,OuterBR);
// Draw inner rect
if BInner then
DrawEdges(R,GC,Drawable,InnerTL,InnerBR);
// gdk_colormap_free_colors(gdk_colormap_get_system, @OuterTL, 1);
// gdk_colormap_free_colors(gdk_colormap_get_system, @OuterBR, 1);
// gdk_colormap_free_colors(gdk_colormap_get_system, @InnerTL, 1);
// gdk_colormap_free_colors(gdk_colormap_get_system, @InnerBR, 1);
//Draw interiour
if ((grfFlags and BF_MIDDLE) = BF_MIDDLE) then
begin
MiddleColor := AllocGDKColor(GetSysColor(COLOR_BTNFACE));
gdk_gc_set_foreground(GC, @MiddleColor);
gdk_draw_rectangle(Drawable, GC, 1, R.Left, R.Top,
R.Right - R.Left, R.Bottom - R.Top);
end;
// adjust rect if needed
if (grfFlags and BF_ADJUST) = BF_ADJUST then
begin
OffsetRect(R, -DCOrigin.X, -DCOrigin.Y);
ARect := R;
end;
Result := True;
end;
end;
{------------------------------------------------------------------------------
Method: DrawText
Params: DC, Str, Count, Rect, Flags
Returns: If the string was drawn, or CalcRect run
------------------------------------------------------------------------------}
function TGtkWidgetSet.DrawText(DC: HDC; Str: PChar; Count: Integer;
var Rect: TRect; Flags: Cardinal): Integer;
const
TabString = ' ';
var
DevCtx: TGtkDeviceContext absolute DC;
pIndex: Longint;
AStr: String;
TM: TTextmetric;
theRect: TRect;
Lines: PPChar;
I, NumLines: Longint;
TempDC: HDC;
TempPen: HPEN;
TempBrush: HBRUSH;
l: LongInt;
function LeftOffset: Longint;
begin
if (Flags and DT_RIGHT) = DT_RIGHT then
Result := DT_RIGHT
else
if (Flags and DT_CENTER) = DT_CENTER then
Result := DT_CENTER
else
Result := DT_LEFT;
end;
function TopOffset: Longint;
begin
if (Flags and DT_BOTTOM) = DT_BOTTOM then
Result := DT_BOTTOM
else
if (Flags and DT_VCENTER) = DT_VCENTER then
Result := DT_VCENTER
else
Result := DT_TOP;
end;
function CalcRect: Boolean;
begin
Result := (Flags and DT_CALCRECT) = DT_CALCRECT;
end;
function TextExtentPoint(Str: PChar; Count: Integer; var Sz: TSize): Boolean;
var
NewStr: String;
begin
if (Flags and DT_EXPANDTABS) <> 0 then
begin
NewStr := StringReplace(Str, #9, TabString, [rfReplaceAll]);
Result := GetTextExtentPoint(DC, PChar(NewStr), Length(NewStr), Sz);
end
else
Result := GetTextExtentPoint(Dc, Str, Count, Sz);
end;
procedure DoCalcRect;
var
AP: TSize;
J, MaxWidth,
LineWidth: Integer;
begin
theRect := Rect;
MaxWidth := theRect.Right - theRect.Left;
if (Flags and DT_SINGLELINE) > 0 then
begin
// ignore word and line breaks
TextExtentPoint(PChar(AStr), length(AStr), AP);
theRect.Bottom := theRect.Top + TM.tmHeight;
if (Flags and DT_CALCRECT)<>0 then
theRect.Right := theRect.Left + AP.cX
else
begin
theRect.Right := theRect.Left + Min(MaxWidth, AP.cX);
if (Flags and DT_VCENTER) > 0 then
begin
OffsetRect(theRect, 0, ((Rect.Bottom - Rect.Top) - (theRect.Bottom - theRect.Top)) div 2);
{$ifdef Gtk1}
//gtk1 overestimate TM.tmHeight leading to wrong calculation of the center offset
OffsetRect(theRect, 0, 1);
{$endif}
end
else
if (Flags and DT_BOTTOM) > 0 then
begin
OffsetRect(theRect, 0, (Rect.Bottom - Rect.Top) - (theRect.Bottom - theRect.Top));
end;
end;
end
else
begin
// consider line breaks
if (Flags and DT_WORDBREAK) = 0 then
begin
// do not break at word boundaries
TextExtentPoint(PChar(AStr), length(AStr), AP);
MaxWidth := AP.cX;
end;
Self.WordWrap(DC, PChar(AStr), MaxWidth, Lines, NumLines);
if (Flags and DT_CALCRECT)<>0 then
begin
LineWidth := 0;
if (Lines <> nil) then
begin
for J := 0 to NumLines - 1 do
begin
TextExtentPoint(Lines[J], StrLen(Lines[J]), AP);
LineWidth := Max(LineWidth, AP.cX);
end;
end;
LineWidth := Min(MaxWidth, LineWidth);
end else
LineWidth := MaxWidth;
theRect.Right := theRect.Left + LineWidth;
theRect.Bottom := theRect.Top + NumLines*TM.tmHeight;
if NumLines>1 then
Inc(theRect.Bottom, (NumLines-1)*TM.tmDescent);// space between lines
//debugln('TGtkWidgetSet.DrawText A ',dbgs(theRect),' TM.tmHeight=',dbgs(TM.tmHeight),' LineWidth=',dbgs(LineWidth),' NumLines=',dbgs(NumLines));
end;
if not CalcRect then
case LeftOffset of
DT_CENTER:
OffsetRect(theRect, (Rect.Right - theRect.Right) div 2, 0);
DT_RIGHT:
OffsetRect(theRect, Rect.Right - theRect.Right, 0);
end;
end;
procedure DrawLineRaw(theLine: PChar; LineLength, TopPos: Longint);
var
Points: array[0..1] of TSize;
LeftPos: Longint;
begin
if LeftOffset <> DT_LEFT then
GetTextExtentPoint(DC, theLine, LineLength, Points[0]);
if TempBrush = HBRUSH(-1) then
TempBrush := SelectObject(DC, GetStockObject(NULL_BRUSH));
case LeftOffset of
DT_LEFT:
LeftPos := theRect.Left;
DT_CENTER:
LeftPos := theRect.Left + (theRect.Right - theRect.Left) div 2
- Points[0].cX div 2;
DT_RIGHT:
LeftPos := theRect.Right - Points[0].cX;
end;
// Draw line of Text
TextUtf8Out(DC, LeftPos, TopPos, theLine, lineLength);
end;
procedure DrawLine(theLine: PChar; LineLength, TopPos: Longint);
var
Points: array[0..1] of TSize;
LogP: TLogPen;
LeftPos: Longint;
begin
if TempBrush = HBRUSH(-1) then
TempBrush := SelectObject(DC, GetStockObject(NULL_BRUSH));
if LeftOffset <> DT_Left then
GetTextExtentPoint(DC, theLine, LineLength, Points[0]);
case LeftOffset of
DT_LEFT:
LeftPos := theRect.Left;
DT_CENTER:
LeftPos := theRect.Left + (theRect.Right - theRect.Left) div 2
- Points[0].cX div 2;
DT_RIGHT:
LeftPos := theRect.Right - Points[0].cX;
end;
// Draw line of Text
TextUtf8Out(DC, LeftPos, TopPos, theLine, LineLength);
// Draw Prefix
if (pIndex > 0) and (pIndex<=LineLength) then
begin
// Create & select pen of font color
if TempPen = HPEN(-1) then
begin
LogP.lopnStyle := PS_SOLID;
LogP.lopnWidth.X := 1;
LogP.lopnColor := GetTextColor(DC);
TempPen := SelectObject(DC, CreatePenIndirect(LogP));
end;
{Get prefix line position}
GetTextExtentPoint(DC, theLine, pIndex - 1, Points[0]);
Points[0].cX := LeftPos + Points[0].cX;
Points[0].cY := TopPos + tm.tmHeight - TM.tmDescent + 1;
GetTextExtentPoint(DC, @aStr[pIndex], 1, Points[1]);
Points[1].cX := Points[0].cX + Points[1].cX;
Points[1].cY := Points[0].cY;
{Draw prefix line}
Polyline(DC, PPoint(@Points[0]), 2);
end;
end;
begin
if (Str=nil) or (Str[0]=#0) then Exit(0);
//DebugLn(Format('trace:> [TGtkWidgetSet.DrawText] DC:0x%x, Str:''%s'', Count: %d, Rect = %d,%d,%d,%d, Flags:%d',
// [DC, Str, Count, Rect.Left, Rect.Top, Rect.Right, Rect.Bottom, Flags]));
if not IsValidDC(DC) then Exit(0);
if (Count < -1) or (IsRectEmpty(Rect) and ((Flags and DT_CALCRECT) = 0)) then Exit(0);
// Don't try to use StrLen(Str) in cases count >= 0
// In those cases str is NOT required to have a null terminator !
if Count = -1 then Count := StrLen(Str);
Lines := nil;
NumLines := 0;
TempDC := HDC(-1);
TempPen := HPEN(-1);
TempBrush := HBRUSH(-1);
try
if (Flags and (DT_SINGLELINE or DT_CALCRECT or DT_NOPREFIX or DT_NOCLIP or DT_EXPANDTABS)) =
(DT_SINGLELINE or DT_NOPREFIX or DT_NOCLIP)
then begin
//DebugLn(['TGtkWidgetSet.DrawText Calc single line']);
CopyRect(theRect, Rect);
DrawLineRaw(Str, Count, Rect.Top);
Result := Rect.Bottom - Rect.Top;
Exit;
end;
SetLength(AStr,Count);
if Count>0 then
System.Move(Str^,AStr[1],Count);
if (Flags and DT_EXPANDTABS) <> 0 then
AStr := StringReplace(AStr, #9, TabString, [rfReplaceAll]);
if (Flags and DT_NOPREFIX) <> DT_NOPREFIX then
pIndex := DeleteAmpersands(AStr)
else
pIndex := -1;
GetTextMetrics(DC, TM);
DoCalcRect;
Result := theRect.Bottom - theRect.Top;
if (Flags and DT_CALCRECT) = DT_CALCRECT
then begin
//DebugLn(['TGtkWidgetSet.DrawText Complex Calc']);
CopyRect(Rect, theRect);
exit;
end;
TempDC := SaveDC(DC);
if (Flags and DT_NOCLIP) <> DT_NOCLIP
then begin
if theRect.Right > Rect.Right then
theRect.Right := Rect.Right;
if theRect.Bottom > Rect.Bottom then
theRect.Bottom := Rect.Bottom;
IntersectClipRect(DC, theRect.Left, theRect.Top,
theRect.Right, theRect.Bottom);
end;
if (Flags and DT_SINGLELINE) = DT_SINGLELINE
then begin
//DebugLn(['TGtkWidgetSet.DrawText Draw single line']);
DrawLine(PChar(AStr), length(AStr), theRect.Top);
Exit; //we're ready
end;
// multiple lines
if Lines = nil then Exit; // nothing to do
if NumLines = 0 then Exit; //
//DebugLn(['TGtkWidgetSet.DrawText Draw multiline']);
for i := 0 to NumLines - 1 do
begin
if theRect.Top > theRect.Bottom then Break;
if ((Flags and DT_EDITCONTROL) = DT_EDITCONTROL)
and (tm.tmHeight > (theRect.Bottom - theRect.Top))
then Break;
if Lines[i] <> nil then begin
l:=StrLen(Lines[i]);
DrawLine(Lines[i], l, theRect.Top);
dec(pIndex,l+length(LineEnding));
end;
Inc(theRect.Top, TM.tmDescent + TM.tmHeight);// space between lines
end;
finally
Reallocmem(Lines, 0);
if TempBrush <> HBRUSH(-1) then
SelectObject(DC, TempBrush);// DeleteObject not needed here, because it was a default Brush
if TempPen <> HPEN(-1) then
DeleteObject(SelectObject(DC, TempPen));
if TempDC <> HDC(-1) then
RestoreDC(DC, TempDC);
end;
end;
{------------------------------------------------------------------------------
Function: EnableScrollBar
Params: Wnd, wSBflags, wArrows
Returns: Nothing
------------------------------------------------------------------------------}
function TGtkWidgetSet.EnableScrollBar(Wnd: HWND; wSBflags, wArrows: Cardinal): Boolean;
begin
//DebugLn('Trace:TODO: [TGtkWidgetSet.EnableScrollBar]');
//TODO: Implement this;
Result := False;
end;
{------------------------------------------------------------------------------
Function: EnableWindow
Params: hWnd:
bEnable:
Returns:
------------------------------------------------------------------------------}
function TGtkWidgetSet.EnableWindow(hWnd: HWND; bEnable: Boolean): Boolean;
begin
//DebugLn(Format('Trace: [TGtkWidgetSet.EnableWindow] hWnd: 0x%x, Enable: %s', [hwnd, BOOL_TEXT[bEnable]]));
if hWnd <> 0 then
gtk_widget_set_sensitive(pgtkwidget(hWnd), bEnable);
Result:=true;
end;
{------------------------------------------------------------------------------
Function: EndPaint
Params:
Returns:
------------------------------------------------------------------------------}
function TGtkWidgetSet.EndPaint(Handle: hwnd; var PS: TPaintStruct): Integer;
var
Widget: PGtkWidget;
Info: PWidgetInfo;
{$IFDEF Gtk1}
DevCtx: TGtkDeviceContext;
DCDrawable: PGdkDrawable;
Width, Height: integer;
CaretWasVisible: Boolean;
MainWidget: PGtkWidget;
{$ENDIF}
begin
Result:=1;
if PS.HDC = 0 then Exit;
Widget := PGtkWidget(Handle);
Info:=GetWidgetInfo(Widget,false);
if Info<>nil then
dec(Info^.PaintDepth);
{$IFDEF Gtk1}
DevCtx := TGtkDeviceContext(PS.HDC);
if Widget <> DevCtx.Widget then
RaiseGDBException('Gtk paint event for other than our window');
DCDrawable := DevCtx.Drawable;
if dcfDoubleBuffer in DevCtx.Flags
then begin
// copy
gdk_window_get_size(DCDrawable, @Width, @Height);
{$IFDEF VerboseDoubleBuffer}
DebugLn('TGtkWidgetSet.EndPaint Copying from buffer to window: ',Width,' ',Height);
{$ENDIF}
gdk_gc_set_clip_region(DevCtx.GC, nil);
gdk_gc_set_clip_rectangle(DevCtx.GC, nil);
// hide caret
// mwe: note that this call is just a bunch of code to see if widget is our winapiwidget
HideCaretOfWidgetGroup(Widget, MainWidget, CaretWasVisible);
// draw
gdk_window_copy_area(Widget^.Window, DevCtx.GC, 0,0, DCDrawable, 0, 0, Width, Height);
// restore caret
if CaretWasVisible then
GTKAPIWidget_ShowCaret(PGTKAPIWidget(MainWidget));
end;
{$ENDIF}
ReleaseDC(Handle, PS.HDC);
end;
function TGTKWidgetSet.EnumDisplayMonitors(hdc: HDC; lprcClip: PRect;
lpfnEnum: MonitorEnumProc; dwData: LPARAM): LongBool;
begin
Result := lpfnEnum(1, 0, nil, dwData);
end;
{.$define VerboseEnumFonts}
{$IFDEF VerboseGtkToDos}{$note: compare TGtkWidgetSet.EnumFontFamilies with gtkproc.FillScreenFonts}{$ENDIF}
function TGtkWidgetSet.EnumFontFamilies(DC: HDC; Family: Pchar;
EnumFontFamProc: FontEnumProc; LParam:Lparam):longint;
var
DevCtx: TGtkDeviceContext absolute DC;
xFonts: PPChar;
FontList: TStringList;
EnumLogFont: TEnumLogFont;
Metric: TNewTextMetric;
I,N: Integer;
tmp: String;
FontType: Integer;
begin
result := 0;
if not Assigned(EnumFontFamProc) then begin
result := 2;
DebugLn('EnumFontFamProc Callback not set');
// todo: raise exception?
exit;
end;
FontList := TStringlist.Create;
try
if Family<>'' then
Tmp := '-*-'+Family+'-*-*-*-*-*-*-*-*-*-*-*-*'
else
Tmp := '-*'; // get rid of aliases
{$ifdef VerboseEnumFonts}
WriteLn('Looking for fonts matching: ', tmp);
{$endif}
{$ifdef HasX}
XFonts := XListFonts(gdk_display, pchar(Tmp), 10000, @N);
{$else}
{$IFDEF VerboseGtkToDos}{$warning implement getting XFonts for this OS}{$ENDIF}
XFonts := nil;
N:=0;
{$endif}
try
for I := 0 to N - 1 do
if XFonts[I] <> nil then begin
Tmp := ExtractFamilyFromXLFDName(XFonts[I]);
{$ifdef VerboseEnumFonts}
WriteLn(I:5,' [', tmp, '] Font=',XFonts[i]);
{$endif}
if Tmp <> '' then begin
if family='' then begin
// get just the font names
if FontList.IndexOf(Tmp) < 0 then begin
EnumLogFont.elfLogFont := XLFDNameToLogFont(XFonts[i]);
FillChar(Metric, SizeOf(Metric), #0);
FontType := 0; // todo: GetFontTypeFromXLDF or FontId
EnumLogFont.elfFullName := '';
EnumFontFamProc(EnumLogFont, Metric, FontType, Lparam);
FontList.Append(Tmp);
end;
end else begin
EnumLogFont.elfLogFont := XLFDNameToLogFont(XFonts[i]);
EnumlogFont.elfFullname := '';
EnumLogFont.elfStyle := '';
FillChar(Metric, SizeOf(Metric), #0);
FontType := 0; // todo: GetFontTypeFromXLDF or FontId
EnumFontFamProc(EnumLogFont, Metric, FontType, Lparam);
end;
end;
end;
finally
{$ifdef HasX}
XFreeFontNames(XFonts);
{$endif}
end;
finally
Fontlist.Free;
end;
end;
function TGtkWidgetSet.EnumFontFamiliesEx(DC: HDC; lpLogFont: PLogFont;
Callback: FontEnumExProc; Lparam:LParam; Flags: dword): longint;
var
DevCtx: TGtkDeviceContext absolute DC;
type
TXLFD=record
Foundry: string[15];
Family, CharsetReg, CharsetCod: string[32];
WeightName,widthName,StyleName: string[20];
Slant: string[5];
PixelSize,PointSize,ResX,ResY: Integer;
end;
var
Xlfd: TXLFD;
CharsetFilter: TStringList;
PitchFilter: TStringList;
EnumLogFont: TEnumLogFontEx;
Metric: TNewTextMetricEx;
function ParseXLFDFont(const font: string): boolean;
function MyStrToIntDef(const s: string; def: integer): integer;
begin
result := StrToIntDef(s, Def);
if result=0 then
result := def
end;
begin
result := IsFontNameXLogicalFontDesc(font);
fillchar(Xlfd, SizeOf(Xlfd), 0);
if result then with Xlfd do begin
Foundry := ExtractXLFDItem(Font, XLFD_FOUNDRY);
Family := ExtractXLFDItem(Font, XLFD_FAMILY);
CharsetReg := ExtractXLFDItem(Font, XLFD_CHARSET_REG);
CharSetCod := ExtractXLFDItem(Font, XLFD_CHARSET_COD);
WeightName := ExtractXLFDItem(Font, XLFD_WEIGHTNAME);
Slant := ExtractXLFDItem(Font, XLFD_SLANT);
WidthName := ExtractXLFDItem(Font, XLFD_WIDTHNAME);
StyleName := ExtractXLFDItem(Font, XLFD_STYLENAME);
ResX := MyStrToIntDef(ExtractXLFDItem(Font, XLFD_RESX), 72);
ResY := MyStrToIntDef(ExtractXLFDItem(Font, XLFD_RESX), 72);
PixelSize := StrToIntDef(ExtractXLFDItem(Font, XLFD_PIXELSIZE), 0);
PointSize := StrToIntDef(ExtractXLFDItem(Font, XLFD_POINTSIZE), 0);
end;
end;
function XLFDToFontStyle: string;
var
s: string;
begin
result := xlfd.WeightName;
s :=lowercase(xlfd.Slant);
if s='i' then result := result + ' '+ 'italic' else
if s='o' then result := result + ' '+ 'oblique' else
if s='ri' then result := result + ' '+ 'reverse italic' else
if s='ro' then result := result + ' '+ 'reverse oblique'
else begin
if (S<>'r')and(S<>'') then
result := result + ' ' + S;
end;
end;
procedure QueueCharsetFilter(Charset: byte);
var
i: integer;
rec: PCharsetEncodingRec;
s: string;
begin
for i:=0 to CharsetEncodingList.count-1 do begin
Rec := CharsetEncodingList[i];
if (Rec=nil) or (Rec^.CharSet<>Charset) or (not Rec^.EnumMap) then
continue;
s := Rec^.CharSetReg;
if Rec^.CharsetRegPart then
s := s + '*';
s := s + '-' + Rec^.CharSetCod;
if Rec^.CharsetCodPart then
s := s + '*';
CharsetFilter.Add(s);
end;
end;
procedure QueuePitchFilter(Pitch: byte);
begin
if pitch and FIXED_PITCH = FIXED_PITCH then begin
PitchFilter.Add('m');
PitchFilter.Add('c'); // character cell it's also fixed pitch
end;
if pitch and VARIABLE_PITCH = VARIABLE_PITCH then
PitchFilter.Add('p');
if pitch and MONO_FONT = MONO_FONT then
PitchFilter.Add('m');
if PitchFilter.Count=0 then
PitchFilter.Add('*');
end;
function XLFDToCharset: byte;
const
CharsetPriority: array[1..19] of byte =
(
SYMBOL_CHARSET, MAC_CHARSET, SHIFTJIS_CHARSET,
HANGEUL_CHARSET, JOHAB_CHARSET, GB2312_CHARSET,
CHINESEBIG5_CHARSET, GREEK_CHARSET, TURKISH_CHARSET,
VIETNAMESE_CHARSET, HEBREW_CHARSET, ARABIC_CHARSET,
BALTIC_CHARSET, RUSSIAN_CHARSET, THAI_CHARSET,
EASTEUROPE_CHARSET, OEM_CHARSET, FCS_ISO_10646_1,
ANSI_CHARSET
);
var
i,n: integer;
rec: PCharsetEncodingRec;
begin
for i := Low(CharsetPriority) to High(CharsetPriority) do
for n:= 0 to CharsetEncodingList.count-1 do begin
rec := CharsetEncodingList[n];
if (rec=nil) or (rec^.CharSet<>CharsetPriority[i]) then
continue;
// try to match registry part
if rec^.CharSetReg<>'*' then begin
if rec^.CharsetRegPart then begin
if pos(rec^.CharSetReg, xlfd.CharsetReg)=0 then
continue;
end else begin
if AnsiCompareText(Rec^.CharSetReg, xlfd.CharsetReg) <> 0 then
continue;
end;
end;
// try to match coding part
if rec^.CharSetCod<>'*' then begin
if rec^.CharsetCodPart then begin
if pos(rec^.CharSetCod, xlfd.CharsetCod)=0 then
continue;
end else begin
if AnsiCompareText(Rec^.CharSetCod, xlfd.CharsetCod) <> 0 then
continue;
end;
end;
// this one is good enought to match bot registry and encondig part
result := CharsetPriority[i];
exit;
end;
result := DEFAULT_CHARSET;
end;
function XLFDCharsetToScript: string;
begin
result := xlfd.CharsetReg + '-' + xlfd.CharsetCod;
end;
function FoundryAndFamilyFilter(const FaceName: string): string;
var
foundry,family: string;
i: LongInt;
begin
if FaceName='' then begin
family := '*';
foundry := '*';
end else begin
family := FaceName;
// look for foundry encoded in family name
i := pos(FOUNDRYCHAR_OPEN, family);
if i<>0 then begin
Foundry := copy(Family, i+1, Length(Family));
family := trim(copy(family, 1, i-1));
i := pos(FOUNDRYCHAR_CLOSE, Foundry);
if i<>0 then
Delete(Foundry, i, Length(Foundry))
else
; // ill formed but it's ok.
end else
Foundry := '*';
end;
result := Foundry+'-'+Family;
end;
function XLFDFamilyFace: string;
begin
with xlfd do
if (Length(Foundry)>0) and (Length(Family) + length(Foundry) + 3 < 31) then
result := Family + ' '+ FOUNDRYCHAR_OPEN + Foundry + FOUNDRYCHAR_CLOSE
else
result := Family;
end;
function XLFDToFontType: integer;
begin
if ((xlfd.PointSize=0) and (xlfd.PixelSize=0))
or ((xlfd.PointSize=120) and (xlfd.PixelSize=17)) // see bug 16298
then
result := TRUETYPE_FONTTYPE
else
result := RASTER_FONTTYPE or DEVICE_FONTTYPE;
end;
// process the current xlfd font, if user returns 0 from callback finish
function ProcessXFont(const index: integer; const font: string;
FontList: TStringList): boolean;
var
FontType: Integer;
tmp: string;
FullSearch: boolean;
begin
FullSearch := ( lpLogFont^.lfFaceName = '');
result := false;
with xlfd, EnumLogFont do
if FullSearch then begin
//
// quick enumeration of fonts, make sure this is
// documented because only some fields are filled !!!
//
Foundry := ExtractXLFDItem(Font, XLFD_FOUNDRY);
Family := ExtractXLFDItem(Font, XLFD_FAMILY);
tmp := XLFDFamilyFace();
if FontList.IndexOf(tmp) < 0 then begin
PixelSize := StrToIntDef(ExtractXLFDItem(Font, XLFD_PIXELSIZE), 0);
PointSize := StrToIntDef(ExtractXLFDItem(Font, XLFD_POINTSIZE), 0);
CharsetReg := ExtractXLFDItem(Font, XLFD_CHARSET_REG);
CharsetCod := ExtractXLFDItem(Font, XLFD_CHARSET_COD);
FontType := XLFDToFontType();
elfLogFont.lfCharSet := XLFDToCharset();
elfLogFont.lfFaceName := tmp;
result := Callback(EnumLogFont, Metric, FontType, LParam)=0;
FontList.Append(tmp);
end;
end else
if ParseXLFDFont(Font) then begin
//
// slow enumeration of fonts, only if face is present
//
// family
tmp := XLFDFamilyFace();
{$ifdef verboseEnumFonts}
DebugLn(dbgs(index),' face=', tmp, ' Font=', Font);
{$endif}
//if FontList.IndexOf(tmp) < 0 then begin
// Fonttype
FontType := XLFDToFontType();
// LogFont
elfLogFont := XLFDNameToLogFont(Font);
elfLogFont.lfFaceName := tmp;
elfLogFont.lfCharSet := XLFDToCharset();
// from logfont
elfStyle := XLFDToFontStyle();
elfScript := XLFDCharsetToScript();
// tempted to feed here full xlfd, but 63 chars might be to small
if Foundry = '' then
elfFullName := Family
else
elfFullName := Foundry + ' ' + Family ;
// Metric
//
fillchar(metric.ntmeFontSignature,
sizeOf(metric.ntmeFontSignature), 0);
with metric.ntmentm do begin
tmheight := elfLogFont.lfHeight;
tmAveCharWidth := elfLogFont.lfWidth;
tmWeight := elfLogFont.lfWeight;
tmDigitizedAspectX := ResX;
tmDigitizedAspectY := ResY;
tmItalic := elfLogFont.lfItalic;
tmUnderlined := elfLogFont.lfUnderline;
tmStruckOut := elfLogFont.lfStrikeOut;
tmPitchAndFamily := elfLogFont.lfPitchAndFamily;
tmCharSet := elfLogFont.lfCharSet;
// todo fields
tmMaxCharWidth := elfLogFont.lfWidth; // todo
tmAscent := 0; // todo
tmDescent := 0; // todo
tmInternalLeading := 0; // todo
tmExternalLeading := 0; // todo
tmOverhang := 0; // todo;
tmFirstChar := ' '; // todo, atm ascii
tmLastChar := #255; // todo, atm ascii
tmDefaultChar := '.'; // todo, atm dot
tmBreakChar := ' '; // todo, atm space
ntmFlags := 0; // todo combination of NTM_XXXX constants
ntmSizeEM := tmHeight; // todo
ntmCellHeight := ntmSizeEM; // todo
ntmAvgWidth := ntmSizeEM; // todo
end; // with metric.ntmentm do ...
// do callback
result := Callback(EnumLogFont, Metric, FontType, LParam) = 0;
FontList.Append(tmp);
//end; // if not FullSearch or (FontList.IndexOf(tmp) < 0 then ...
end; // with xlfd, EnumLogFont do ...
end;
var
xFonts: PPChar;
FontList: TStringList;
I,J,K,N: Integer;
Tmp,FandF: String;
begin
result := 0;
// initial checks
if not Assigned(Callback) then begin
result := 2;
DebugLn('EnumFontFamiliesEx: EnumFontFamProcEx Callback not set');
// todo: raise exception?
exit;
end;
if not Assigned(lpLogFont) then begin
result := 3;
DebugLn('EnumFontFamiliesEx: lpLogFont not set');
// todo: enumerate all fonts?
exit;
end;
// foundry and family filter
FandF := FoundryAndFamilyFilter(lpLogFont^.lfFaceName);
FontList := TStringlist.Create;
CharSetFilter := TStringList.Create;
PitchFilter := TStringList.Create;
PitchFilter.Duplicates := dupIgnore;
try
QueueCharSetFilter(lpLogFont^.lfCharSet);
QueuePitchFilter(lpLogFont^.lfPitchAndFamily);
{$ifdef verboseEnumFonts}
for j:=0 to CharSetFilter.Count-1 do begin
// pitch filter is guaranteed to have at least one element
for k:=0 to PitchFilter.Count-1 do begin
tmp := '-'+FAndF+'-*-*-*-*-*-*-*-*-'+PitchFilter[k]+'-*-'+CharSetFilter[j];
DebugLn('EnumFontFamiliesEx: will enumerate fonts matching: ', tmp);
end;
end;
{$endif}
for j:=0 to CharSetFilter.Count-1 do begin
for k:=0 to PitchFilter.Count-1 do begin
tmp := '-'+FAndF+'-*-*-*-*-*-*-*-*-'+PitchFilter[k]+'-*-'+CharSetFilter[j];
{$ifdef HasX}
XFonts := XListFonts(gdk_display, pchar(Tmp), 10000, @N);
{$else}
{$IFDEF VerboseGtkToDos}{$warning implement getting XFonts for this OS}{$ENDIF}
XFonts := nil;
N:=0;
{$endif}
try
{$ifdef VerboseEnumFonts}
DebugLn('EnumFontFamiliesEx: found ',dbgs(N),' fonts matching: ', tmp);
{$endif}
for i:=0 to N-1 do
if XFonts[i]<>nil then
if ProcessXFont(i, XFonts[i], FontList) then
break;
finally
{$ifdef HasX}
XFreeFontNames(XFonts);
{$endif}
end;
end;
end;
finally
PitchFilter.Free;
Fontlist.Free;
CharSetFilter.Free;
end;
end;
{------------------------------------------------------------------------------
Method: Ellipse
Params: X1, Y1, X2, Y2
Returns: Nothing
Use Ellipse to draw a filled circle or ellipse.
------------------------------------------------------------------------------}
function TGtkWidgetSet.Ellipse(DC: HDC; X1, Y1, X2, Y2: Integer): Boolean;
var
DevCtx: TGtkDeviceContext absolute DC;
Left, Top, Width, Height: Integer;
DCOrigin: TPoint;
begin
Result := IsValidDC(DC);
if not Result then Exit;
if DevCtx.HasTransf then
DevCtx.TransfRect(X1, Y1, X2, Y2);
CalculateLeftTopWidthHeight(X1, Y1, X2, Y2, Left, Top, Width, Height);
if (Width = 0) or (Height = 0) then Exit(True);
// X2, Y2 is not part of the rectangle
dec(Width);
dec(Height);
// first draw interior in brush color
DCOrigin := DevCtx.Offset;
{$IFDEF DebugGDKTraps}
BeginGDKErrorTrap;
{$ENDIF}
if not DevCtx.IsNullBrush then
begin
DevCtx.SelectBrushProps;
gdk_draw_arc(DevCtx.Drawable, DevCtx.GC, 1,
Left+DCOrigin.X, Top+DCOrigin.Y, Width, Height, 0, 360 shl 6);
end;
// Draw outline
DevCtx.SelectPenProps;
if (dcfPenSelected in DevCtx.Flags) then
begin
Result := True;
if not DevCtx.IsNullPen then
begin
gdk_draw_arc(DevCtx.Drawable, DevCtx.GC, 0,
Left+DCOrigin.X, Top+DCOrigin.Y, Width, Height, 0, 360 shl 6);
end;
end
else
Result := False;
{$IFDEF DebugGDKTraps}
EndGDKErrorTrap;
{$ENDIF}
end;
{------------------------------------------------------------------------------
Method: EqualRgn
Params: Rgn1: HRGN; Rgn2: HRGN
Returns: True if the two regions are equal
Checks the two specified regions to determine whether they are identical. The
function considers two regions identical if they are equal in size and shape.
------------------------------------------------------------------------------}
function TGtkWidgetSet.EqualRgn(Rgn1: HRGN; Rgn2: HRGN): Boolean;
var
AGdiObject: PGdiObject absolute Rgn1;
BGdiObject: PGdiObject absolute Rgn2;
begin
Result := IsValidGDIObject(Rgn1) and IsValidGDIObject(Rgn2);
if Result then
Result := gdk_region_equal(AGdiObject^.GDIRegionObject,
BGdiObject^.GDIRegionObject);
end;
{------------------------------------------------------------------------------
Function: ExcludeClipRect
Params: dc: hdc; Left, Top, Right, Bottom : Integer
Returns: integer
Subtracts all intersecting points of the passed bounding rectangle
(Left, Top, Right, Bottom) from the Current clipping region in the
device context (dc).
The result can be one of the following constants
Error
NullRegion
SimpleRegion
ComplexRegion
------------------------------------------------------------------------------}
function TGtkWidgetSet.ExcludeClipRect(dc: hdc;
Left, Top, Right, Bottom : Integer) : Integer;
begin
Result := Inherited ExcludeClipRect(DC, Left, Top, Right, Bottom);
end;
function TGTKWidgetSet.ExtCreatePen(dwPenStyle, dwWidth: DWord;
const lplb: TLogBrush; dwStyleCount: DWord; lpStyle: PDWord): HPEN;
var
GObject: PGdiObject;
i: integer;
begin
GObject := NewGDIObject(gdiPen);
GObject^.UnTransfPenWidth := 0;
GObject^.IsExtPen := True;
GObject^.GDIPenStyle := dwPenStyle;
GObject^.GDIPenWidth := dwWidth;
SetGDIColorRef(GObject^.GDIPenColor, lplb.lbColor);
GObject^.GDIPenDashesCount := dwStyleCount;
if dwStyleCount > 0 then
begin
GetMem(GObject^.GDIPenDashes, dwStyleCount * SizeOf(gint8));
for i := 0 to dwStyleCount - 1 do
GObject^.GDIPenDashes[i] := lpStyle[i];
end;
Result := HPEN(PtrUInt(GObject));
end;
{------------------------------------------------------------------------------
Function: ExtSelectClipRGN
Params: dc, RGN, Mode
Returns: integer
Combines the passed Region with the current clipping region in the device
context (dc), using the specified mode.
The Combine Mode can be one of the following:
RGN_AND : all points which are in both regions
RGN_COPY : an exact copy of the source region, same as SelectClipRGN
RGN_DIFF : all points which are in the Clipping Region but
not in the Source.(Clip - RGN)
RGN_OR : all points which are in either the Clip Region or
in the Source.(Clip + RGN)
RGN_XOR : all points which are in either the Clip Region
or in the Source, but not in both.
The result can be one of the following constants
Error
NullRegion
SimpleRegion
ComplexRegion
------------------------------------------------------------------------------}
function TGtkWidgetSet.ExtSelectClipRGN(dc: hdc; rgn : hrgn;
Mode : Longint) : Integer;
var
Clip,
Tmp : hRGN;
X, Y : Longint;
DCOrigin: TPoint;
begin
Result := SIMPLEREGION;
If not IsValidDC(DC) then
Result := ERROR
else with TGtkDeviceContext(DC) do
begin
//DebugLn('TGtkWidgetSet.ExtSelectClipRGN A ClipRegValid=',dbgs(DCClipRegionValid(DC)),
// ' Mode=',dbgs(Mode),' RGN=',GDKRegionAsString(PGdiObject(RGN)^.GDIRegionObject));
If ClipRegion=nil then begin
// there is no clipping region in the DC
Case Mode of
RGN_COPY:
begin
Result := RegionType(PGdiObject(RGN)^.GDIRegionObject);
If Result <> ERROR then
Result := SelectClipRGN(DC, RGN);
end;
RGN_OR,
RGN_XOR,
RGN_AND,
RGN_DIFF:
begin
// get existing clip
GDK_Window_Get_Size(Drawable, @X, @Y);
DCOrigin:= Offset;
Clip := CreateRectRGN(-DCOrigin.X,-DCOrigin.Y,X-DCOrigin.X,Y-DCOrigin.Y);
// create target clip
Tmp := CreateEmptyRegion;
// combine
Result := CombineRGN(Tmp, Clip, RGN, Mode);
// commit
//DebugLn('TGtkWidgetSet.ExtSelectClipRGN B ClipRegValid=',dbgs(ClipRegion),' TmpRGN=',GDKRegionAsString(PGdiObject(Tmp)^.GDIRegionObject));
SelectClipRGN(DC, Tmp);
// clean up
DeleteObject(Clip);
DeleteObject(Tmp);
end;
end;
end
else
Result := inherited ExtSelectClipRGN(dc, rgn, mode);
end;
end;
{------------------------------------------------------------------------------
Function: ExtTextOut
Params: none
Returns: Nothing
------------------------------------------------------------------------------}
function TGtkWidgetSet.ExtTextOut(DC: HDC; X, Y: Integer; Options: Longint;
Rect: PRect; Str: PChar; Count: Longint; Dx: PInteger): Boolean;
{$Ifdef GTK2}
begin
DebugLn('ToDo: TGtkWidgetSet.ExtTextOut');
Result:=false;
end;
{$Else}
var
DevCtx: TGtkDeviceContext absolute DC;
LineStart, LineEnd, StrEnd: PChar;
Left, Top, Width, Height: Integer;
TopY, LineLen, LineHeight : Integer;
TxtPt : TPoint;
UseFont : PGDKFont;
DCOrigin: TPoint;
UnderLine: boolean;
buffer: PGdkDrawable;
buffered: Boolean;
procedure DrawTextLine;
var
UnderLineLen, Y: integer;
CurDistX: PInteger;
CharsWritten, CurX, i: integer;
LinePos: PChar;
CharLen: LongInt;
begin
{$IFDEF DebugGDKTraps}BeginGDKErrorTrap;{$ENDIF}
if Dx = nil
then begin
// no dist array -> write as one block
gdk_draw_text(Buffer, UseFont, DevCtx.GC, TxtPt.X, TxtPt.Y, LineStart, LineLen);
end
else begin
// dist array -> write each char separately
CharsWritten := Integer(LineStart-Str);
if DevCtx.DCTextMetric.IsDoubleByteChar
then begin
CharLen := 2;
CharsWritten := CharsWritten div 2;
end
else CharLen := 1;
CurDistX := Dx+CharsWritten*SizeOf(Integer);
CurX := TxtPt.X;
LinePos := LineStart;
i:=1;
while i <= LineLen do
begin
gdk_draw_text(Buffer, UseFont, DevCtx.GC, CurX, TxtPt.Y, LinePos, CharLen);
inc(LinePos,CharLen);
inc(CurX,CurDistX^);
inc(CurDistX);
inc(i,CharLen);
end;
end;
if UnderLine
then begin
if Rect <> nil
then
UnderLineLen := Rect^.Right-Rect^.Left
else
UnderLineLen := gdk_text_width(UseFont,LineStart, LineLen);
Y := TxtPt.Y + 1;
gdk_draw_line(Buffer, DevCtx.GC, TxtPt.X, Y, TxtPt.X+UnderLineLen, Y);
end;
{$IFDEF DebugGDKTraps}EndGDKErrorTrap;{$ENDIF}
end;
begin
//DebugLn(Format('trace:> [TGtkWidgetSet.ExtTextOut] DC:0x%x, X:%d, Y:%d, Options:%d, Str:''%s'', Count: %d', [DC, X, Y, Options, Str, Count]));
if not IsValidDC(DC) then Exit(False);
if DevCtx.HasTransf then
begin
DevCtx.TransfPoint(X, Y);
if Rect <> nil then
begin
Rect^ := DevCtx.TransfRectIndirect(Rect^);
DevCtx.TransfNormalize(Rect^.Left, Rect^.Right);
DevCtx.TransfNormalize(Rect^.Top, Rect^.Bottom);
end;
end;
if ((Options and (ETO_OPAQUE or ETO_CLIPPED)) <> 0)
and (Rect=nil)
then begin
DebugLn('WARNING: [TGtkWidgetSet.ExtTextOut] Rect=nil');
exit(False);
end;
// TODO: implement other parameters.
// to reduce flickering calculate first and then paint
DCOrigin := DevCtx.Offset;
buffered := false;
UseFont := nil;
buffer := DevCtx.Drawable;
UnderLine := false;
if (Str <> nil) and (Count>0)
then begin
Usefont := GetGtkFont(DevCtx);
if UseFont = nil
then begin
DebugLn('WARNING: [TGtkWidgetSet.ExtTextOut] Missing Font');
Exit(False);
end;
if (DevCtx.CurrentFont <> nil) and (DevCtx.CurrentFont^.GDIFontObject <> nil)
then UnderLine := (DevCtx.CurrentFont^.LogFont.lfUnderline <> 0);
if (Options and ETO_CLIPPED) <> 0
then begin
X := Rect^.Left;
Y := Rect^.Top;
IntersectClipRect(DC, Rect^.Left, Rect^.Top, Rect^.Right, Rect^.Bottom);
end;
end;
if ((Options and ETO_OPAQUE) <> 0)
then begin
Width := Rect^.Right - Rect^.Left;
Height := Rect^.Bottom - Rect^.Top;
DevCtx.SelectedColors := dcscCustom;
EnsureGCColor(DC, dccCurrentBackColor, True, False);
if buffered
then begin
Left:=0;
Top:=0;
end
else begin
Left:=Rect^.Left+DCOrigin.X;
Top:=Rect^.Top+DCOrigin.Y;
end;
{$IFDEF DebugGDKTraps}BeginGDKErrorTrap;{$ENDIF}
if IsBackgroundColor(TColor(DevCtx.CurrentBackColor.ColorRef))
then
StyleFillRectangle(buffer, DevCtx.GC, DevCtx.CurrentBackColor.ColorRef,
Left, Top, Width, Height)
else
gdk_draw_rectangle(buffer, DevCtx.GC, 1, Left, Top, Width, Height);
{$IFDEF DebugGDKTraps}EndGDKErrorTrap;{$ENDIF}
end;
if UseFont = nil then Exit(True);
UpdateDCTextMetric(DevCtx);
LineHeight := GetTextHeight(DevCtx.DCTextMetric);
if Buffered
then begin
TxtPt.X := 0;
TxtPt.Y := LineHeight;
end
else begin
TopY := Y;
TxtPt.X := X + DCOrigin.X;
TxtPt.Y := TopY + LineHeight + DCOrigin.Y;
end;
DevCtx.SelectTextProps;
LineStart:= Str;
LineLen := FindChar(#10,Str,Count);
if LineLen < 0
then begin
LineLen:=Count;
if Count > 0 then DrawTextLine;
Exit(True);
end;
//write multiple lines
StrEnd := Str+Count;
repeat
LineEnd := LineStart + LineLen;
if LineLen > 0 then DrawTextLine;
inc(TxtPt.Y, LineHeight);
LineStart := LineEnd + 1; // skip #10
if (LineStart<StrEnd) and (LineStart^=#13)
then Inc(LineStart); // skip #13
Count := StrEnd-LineStart;
LineLen:=FindChar(#10,LineStart,Count);
if LineLen < 0
then LineLen := Count;
until LineStart >= StrEnd;
//DebugLn(Format('trace:< [TGtkWidgetSet.ExtTextOut] DC:0x%x, X:%d, Y:%d, Options:%d, Str:''%s'', Count: %d', [DC, X, Y, Options, Str, Count]));
end;
{$EndIf}
{------------------------------------------------------------------------------
Function: FillRect
Params: none
Returns: Nothing
The FillRect function fills a rectangle by using the specified brush.
This function includes the left and top borders, but excludes the right and
bottom borders of the rectangle.
------------------------------------------------------------------------------}
function TGtkWidgetSet.FillRect(DC: HDC; const Rect: TRect; Brush: HBRUSH): Boolean;
begin
Result := IsValidDC(DC) and IsValidGDIObject(Brush);
if not Result or IsRectEmpty(Rect) then
exit;
Result := TGtkDeviceContext(DC).FillRect(Rect, Brush, True);
//DebugLn(Format('trace:< [TGtkWidgetSet.FillRect] DC:0x%x; Rect: ((%d,%d)(%d,%d)); brush: %x', [Integer(DC), Rect.left, rect.top, rect.right, rect.bottom, brush]));
end;
{------------------------------------------------------------------------------
Function: FillRgn
Params: DC: HDC; RegionHnd: HRGN; hbr: HBRUSH
Returns: True if the function succeeds
Fills a region by using the specified brush
------------------------------------------------------------------------------}
function TGtkWidgetSet.FillRgn(DC: HDC; RegionHnd: HRGN; hbr: HBRUSH): Bool;
var
GtkDC: Integer;
OldRgn: PGdkRegion;
DevCtx: TGtkDeviceContext absolute DC;
ARect: TRect;
CRect : TGDKRectangle;
hasClipping: Boolean;
begin
//todo: sanity checks for valid handle etc.
Result := IsValidDC(DC) and IsValidGDIObject(hbr) and IsValidGDIObject(RegionHnd);
if not Result then Exit;
GtkDC := SaveDC(DC);
DevCtx.ClipRegion := PGdiObject(CreateRegionCopy(RegionHnd));
OldRgn:= DevCtx.ClipRegion^.GDIRegionObject;
hasClipping := Assigned(OldRgn); //todo: Check a better way
try
if hasClipping then
if SelectClipRGN(DC, RegionHnd) <> ERROR then
begin
gdk_region_get_clipbox(PGDIObject(RegionHnd)^.GDIRegionObject, @CRect);
ARect := RectFromGdkRect(CRect);
DevCtx.FillRect(ARect, hbr, True);
if hasClipping then
SelectClipRGN(DC, HRGN(OldRgn));
Result := True;
end;
finally
if hasClipping then
gdk_region_destroy(OldRgn);
RestoreDC(DC, GtkDC);
end;
end;
{------------------------------------------------------------------------------
Function: Frame3d
Params: -
Returns: Nothing
Draws a 3d border in GTK native style.
------------------------------------------------------------------------------}
function TGtkWidgetSet.Frame3d(DC: HDC; var ARect: TRect;
const FrameWidth: integer; const Style: TBevelCut): boolean;
var
DevCtx: TGtkDeviceContext absolute DC;
TheStyle: PGtkStyle;
i, AWidth: integer;
P: TPoint;
gc1, gc2: PGdkGC;
OldGC1Values, OldGC2Values: TGdkGCValues;
begin
Result := IsValidDC(DC);
if not Result or (FrameWidth = 0) then Exit;
TheStyle := gtk_widget_get_style(GetStyleWidget(lgsButton));
if TheStyle = nil then exit;
if DevCtx.HasTransf then
begin
ARect := DevCtx.TransfRectIndirect(ARect);
DevCtx.TransfNormalize(ARect.Left, ARect.Right);
DevCtx.TransfNormalize(ARect.Top, ARect.Bottom);
P.X := FrameWidth;
P.Y := FrameWidth;
P := DevCtx.TransfExtentIndirect(P);
AWidth := Abs(Min(P.X, P.Y));
end else
AWidth := FrameWidth;
case Style of
bvNone:
begin
InflateRect(ARect, -AWidth, -AWidth);
Exit;
end;
bvLowered:
begin
gc1 := TheStyle^.dark_gc[GTK_STATE_NORMAL];
gc2 := TheStyle^.light_gc[GTK_STATE_NORMAL];
end;
bvRaised:
begin
gc1 := TheStyle^.light_gc[GTK_STATE_NORMAL];
gc2 := TheStyle^.dark_gc[GTK_STATE_NORMAL];
end;
bvSpace:
begin
InflateRect(ARect, -AWidth, -AWidth);
Exit;
end;
end;
with DevCtx do
begin
if WithChildWindows then
begin
gdk_gc_get_values(gc1, @OldGC1Values);
gdk_gc_get_values(gc2, @OldGC2Values);
gdk_gc_set_subwindow(gc1, GDK_INCLUDE_INFERIORS);
gdk_gc_set_subwindow(gc2, GDK_INCLUDE_INFERIORS);
end;
for i := 1 to AWidth do
begin
gdk_draw_line(Drawable, gc1, ARect.Left + Offset.x, ARect.Top + Offset.y,
ARect.Right + Offset.x - 2, ARect.Top + Offset.y);
gdk_draw_line(Drawable, gc1, ARect.Left + Offset.x, ARect.Top + Offset.y,
ARect.Left + Offset.x, ARect.Bottom + Offset.y - 2);
gdk_draw_line(Drawable, gc2, ARect.Left + Offset.x, ARect.Bottom + Offset.y - 1,
ARect.Right + Offset.x - 1, ARect.Bottom + Offset.y - 1);
gdk_draw_line(Drawable, gc2, ARect.Right + Offset.x - 1, ARect.Top + Offset.y,
ARect.Right + Offset.x - 1, ARect.Bottom + Offset.y - 1);
// inflate the rectangle (! ARect will be returned to the user with this)
InflateRect(ARect, -1, -1);
end;
if WithChildWindows then
begin
gdk_gc_set_subwindow(gc1, OldGC1Values.subwindow_mode);
gdk_gc_set_subwindow(gc2, OldGC2Values.subwindow_mode);
end;
end;
end;
{------------------------------------------------------------------------------
function TGtkWidgetSet.FrameRect(DC: HDC; const ARect: TRect;
hBr: HBRUSH): Integer;
------------------------------------------------------------------------------}
function TGtkWidgetSet.FrameRect(DC: HDC; const ARect: TRect;
hBr: HBRUSH): Integer;
var
DevCtx: TGtkDeviceContext absolute DC;
DCOrigin: TPoint;
R: TRect;
begin
Result:=0;
if not IsValidDC(DC) then Exit;
if not IsValidGDIObject(hBr) then Exit;
// Draw outline
Result := 1;
if PGdiObject(hBr)^.IsNullBrush then Exit;
DevCtx.SelectedColors:= dcscCustom;
EnsureGCColor(DC, dccGDIBrushColor, True, False);//Brush Color
if DevCtx.HasTransf then
begin
R := DevCtx.TransfRectIndirect(ARect);
DevCtx.TransfNormalize(R.Left, R.Right);
DevCtx.TransfNormalize(R.Top, R.Bottom);
end else
R := ARect;
DCOrigin := DevCtx.Offset;
gdk_draw_rectangle(DevCtx.Drawable, DevCtx.GC, 0,
R.Left+DCOrigin.X, R.Top+DCOrigin.Y,
R.Right-R.Left-1, R.Bottom-R.Top-1);
end;
{------------------------------------------------------------------------------
Function: GetActiveWindow
Params: none
Returns:
------------------------------------------------------------------------------}
function TGtkWidgetSet.GetActiveWindow : HWND;
var
TopList, List: PGList;
Widget: PGTKWidget;
Window: PGTKWindow;
begin
// Default to 0
Result := 0;
TopList := gdk_window_get_toplevels;
List := TopList;
while List <> nil do
begin
if (List^.Data <> nil)
then begin
gdk_window_get_user_data(PGDKWindow(List^.Data), Pgpointer(@Window));
if gtk_is_window(Window)
then begin
Widget := Window^.focus_widget;
if Widget=nil then Widget:=PGtkWidget(Window);
//DebugLn('TGtkWidgetSet.GetActiveWindow Window=',GetWidgetDebugReport(PgtkWidget(Window)),' Window^.focus_widget= ',GetWidgetDebugReport(Window^.focus_widget));
if (Widget <> nil) and gtk_widget_has_focus(Widget)
then begin
// return the window
Result := HWND(PtrUInt(GetMainWidget(PGtkWidget(Window))));
//DebugLn('TGtkWidgetSet.GetActiveWindow Result=',GetWidgetDebugReport(PgtkWidget(Result)));
Break;
end;
end;
end;
list := g_list_next(list);
end;
if TopList <> nil
then g_list_free(TopList);
end;
{------------------------------------------------------------------------------
Function: GetDIBits
Params:
Returns:
------------------------------------------------------------------------------}
function TGtkWidgetSet.GetDIBits(DC: HDC; Bitmap: HBitmap; StartScan, NumScans: UINT;
Bits: Pointer; var BitInfo: BitmapInfo; Usage: UINT): Integer;
begin
//DebugLn('trace:[TGtkWidgetSet.GetDIBits]');
Result := 0;
if IsValidGDIObject(Bitmap)
then begin
case PGDIObject(Bitmap)^.GDIType of
gdiBitmap:
Result := InternalGetDIBits(DC, Bitmap, StartScan, NumScans, -1, Bits,
BitInfo, Usage, True);
else
DebugLn('WARNING: [TGtkWidgetSet.GetDIBits] not a Bitmap!');
end;
end
else
DebugLn('WARNING: [TGtkWidgetSet.GetDIBits] invalid Bitmap!');
end;
{------------------------------------------------------------------------------
Function: GetBitmapBits
Params:
Returns:
------------------------------------------------------------------------------}
function TGtkWidgetSet.GetBitmapBits(Bitmap: HBITMAP; Count: Longint; Bits: Pointer): Longint;
var
BitInfo : tagBitmapInfo;
begin
//DebugLn('trace:[TGtkWidgetSet.GetBitmapBits]');
Result := 0;
if IsValidGDIObject(Bitmap)
then begin
case PGDIObject(Bitmap)^.GDIType of
gdiBitmap:
Result := InternalGetDIBits(0, Bitmap, 0, 0, Count, Bits, BitInfo, 0, False);
else
DebugLn('WARNING: [TGtkWidgetSet.GetBitmapBits] not a Bitmap!');
end;
end
else
DebugLn('WARNING: [TGtkWidgetSet.GetBitmapBits] invalid Bitmap!');
end;
{------------------------------------------------------------------------------
Function: GetCapture
Params: none
Returns: Nothing
------------------------------------------------------------------------------}
function TGtkWidgetSet.GetCapture: HWND;
var
Widget: PGtkWidget;
AWindow: PGtkWindow;
IsModal: gboolean;
begin
Widget:=gtk_grab_get_current;
// for the LCL a modal window is not capturing
if Widget<>nil then begin
if GtkWidgetIsA(Widget,GTK_TYPE_WINDOW) then begin
AWindow:=PGtkWindow(Widget);
IsModal:=gtk_window_get_modal(AWindow);
if IsModal then
Widget:=nil;
end;
end;
Result := HWnd(PtrUInt(Widget));
end;
{------------------------------------------------------------------------------
Function: GetCaretPos
Params: lpPoint: The caretposition
Returns: True if succesful
------------------------------------------------------------------------------}
function TGtkWidgetSet.GetCaretPos(var lpPoint: TPoint): Boolean;
var
//FocusObject: PGTKObject;
modmask : TGDKModifierType;
begin
{$IFDEF DebugGDKTraps}
BeginGDKErrorTrap;
{$ENDIF}
gdk_window_get_pointer(nil,@lpPoint.X,@lpPoint.y,@modmask);
{$IFDEF DebugGDKTraps}
EndGDKErrorTrap;
{$ENDIF}
Result := True;
end;
{------------------------------------------------------------------------------
function TGtkWidgetSet.GetCaretRespondToFocus(handle: HWND;
var ShowHideOnFocus: boolean): Boolean;
------------------------------------------------------------------------------}
function TGtkWidgetSet.GetCaretRespondToFocus(handle: HWND;
var ShowHideOnFocus: boolean): Boolean;
begin
if handle<>0 then begin
if gtk_type_is_a(gtk_object_type(PGTKObject(handle)), GTKAPIWidget_GetType)
then begin
GTKAPIWidget_GetCaretRespondToFocus(PGTKAPIWidget(handle),
ShowHideOnFocus);
Result:=true;
end
else begin
Result := False;
end;
end else
Result:=false;
end;
{------------------------------------------------------------------------------
Function: GetCharABCWidths pbd
Params: Don't care yet
Returns: False so that the font cache in the newest mwEdit will use
TextMetrics info which is working already
------------------------------------------------------------------------------}
function TGtkWidgetSet.GetCharABCWidths(DC: HDC; p2, p3: UINT;
const ABCStructs): Boolean;
begin
Result := False;
end;
{------------------------------------------------------------------------------
Function: GetClientBounds
Params: handle:
Result:
Returns: true on success
Returns the client bounds of a control. The client bounds is the rectangle of
the inner area of a control, where the child controls are visible. The
coordinates are relative to the control's left and top.
------------------------------------------------------------------------------}
function TGtkWidgetSet.GetClientBounds(handle : HWND; var ARect : TRect) : Boolean;
var
Widget, ClientWidget: PGtkWidget;
{$IFDEF Gtk1}
MainOrigin: TPoint;
{$ELSE}
CurGDKWindow: PGdkWindow;
{$ENDIF}
ClientOrigin: TPoint;
ClientWindow, MainWindow: PGdkWindow;
begin
Result := False;
if Handle = 0 then Exit;
Widget := pgtkwidget(Handle);
ClientWidget := GetFixedWidget(Widget);
if (ClientWidget <> Widget) then begin
ClientWindow:=GetControlWindow(ClientWidget);
MainWindow:=GetControlWindow(Widget);
if MainWindow<>ClientWindow then begin
// widget and client are on different gdk windows
{$IFDEF Gtk1}
if MainWindow<>nil then begin
gdk_window_get_origin(MainWindow,@MainOrigin.X,@MainOrigin.Y);
end else begin
// widget not realized
MainOrigin.X:=0;
MainOrigin.Y:=0;
end;
// check if the main gdkwindow is the clientwindow of the parent
if (Widget^.Parent<>nil)
and (MainWindow=gtk_widget_get_parent_window(Widget)) then begin
// the widget is using its parent window
// -> adjust the coordinates
inc(MainOrigin.X,Widget^.Allocation.X);
inc(MainOrigin.Y,Widget^.Allocation.Y);
end;
if ClientWindow<>nil then begin
gdk_window_get_origin(ClientWindow,@ClientOrigin.X,@ClientOrigin.Y);
end else begin
// client widget not realized
ClientOrigin:=MainOrigin;
end;
ARect.Left:=ClientOrigin.X-MainOrigin.X;
ARect.Top:=ClientOrigin.Y-MainOrigin.Y;
{$ELSE}
if (GTK_WIDGET_NO_WINDOW(ClientWidget)) then begin
// ClientWidget is a sub widget
ARect.Left:=ClientWidget^.allocation.x;
ARect.Top:=ClientWidget^.allocation.y;
end else begin
// ClientWidget owns the gdkwindow
ARect.Left:=0;
ARect.Top:=0;
end;
CurGDKWindow:=ClientWindow;
while (CurGDKWindow<>MainWindow) do begin
gdk_window_get_position(CurGDKWindow,@ClientOrigin.x,@ClientOrigin.y);
inc(ARect.Left,ClientOrigin.x);
inc(ARect.Top,ClientOrigin.y);
CurGDKWindow:=gdk_window_get_parent(CurGDKWindow);
end;
if GTK_WIDGET_NO_WINDOW(Widget) then begin
// Widget is a sub widget
dec(ARect.Left,Widget^.allocation.x);
dec(ARect.Top,Widget^.allocation.y);
end;
{$ENDIF}
ARect.Right:=ARect.Left+ClientWidget^.Allocation.Width;
ARect.Bottom:=ARect.Top+ClientWidget^.Allocation.Height;
Result:=true;
end else if MainWindow<>nil then begin
// both are on the same gdkwindow
ARect.Left:=ClientWidget^.allocation.X-Widget^.allocation.X;
ARect.Top:=ClientWidget^.allocation.Y-Widget^.allocation.Y;
ARect.Right:=ARect.Left+ClientWidget^.allocation.Width;
ARect.Bottom:=ARect.Top+ClientWidget^.allocation.Height;
Result:=true;
end;
end;
if not Result then begin
with Widget^.Allocation do
ARect := Rect(0,0,Width,Height);
end;
Result:=true;
end;
{------------------------------------------------------------------------------
Function: GetClientRect
Params: handle:
Result:
Returns: true on success
Returns the client rectangle of a control. Left and Top are always 0.
The client rectangle is the size of the inner area of a control, where the
child controls are visible.
------------------------------------------------------------------------------}
function TGtkWidgetSet.GetClientRect(handle : HWND; var ARect : TRect) : Boolean;
var
Widget, ClientWidget: PGtkWidget;
procedure GetNoteBookClientRect(NBWidget: PGtkNotebook);
var
PageIndex: LongInt;
PageWidget: PGtkWidget;
FrameBorders: TRect;
aWidth: LongInt;
aHeight: LongInt;
begin
// get current page
PageIndex:=gtk_notebook_get_current_page(NBWidget);
if PageIndex>=0 then
PageWidget:=gtk_notebook_get_nth_page(NBWidget,PageIndex)
else
PageWidget:=nil;
if (PageWidget<>nil) and GTK_WIDGET_RC_STYLE(PageWidget)
and ((PageWidget^.Allocation.Width>1) or (PageWidget^.Allocation.Height>1))
then begin
// get the size of the current page
ARect.Right:=PageWidget^.Allocation.Width;
ARect.Bottom:=PageWidget^.Allocation.Height;
//DebugLn(['GetNoteBookClientRect using pagewidget: ',GetWidgetDebugReport(Widget),' ARect=',dbgs(aRect)]);
end else begin
// use defaults
FrameBorders:=GetStyleNotebookFrameBorders;
aWidth:=Widget^.allocation.width;
aHeight:=Widget^.allocation.height;
ARect:=Rect(0,0,
Max(0,AWidth-FrameBorders.Left-FrameBorders.Right),
Max(0,aHeight-FrameBorders.Top-FrameBorders.Bottom));
//DebugLn(['GetNoteBookClientRect using defaults: ',GetWidgetDebugReport(Widget),' ARect=',dbgs(aRect)]);
end;
end;
begin
Result := false;
if Handle = 0 then Exit;
ARect.Left := 0;
ARect.Top := 0;
Widget := PGtkWidget(Handle);
ClientWidget := GetFixedWidget(Widget);
if (ClientWidget <> nil) then
Widget := ClientWidget;
if (Widget <> nil) then begin
ARect.Right:=Widget^.Allocation.Width;
ARect.Bottom:=Widget^.Allocation.Height;
if GtkWidgetIsA(Widget,gtk_notebook_get_type) then
GetNoteBookClientRect(PGtkNoteBook(Widget));
end else begin
ARect.Right:=0;
ARect.Bottom:=0;
end;
{$IfDef VerboseGetClientRect}
if ClientWidget<>nil then begin
DebugLn('GetClientRect Widget=',GetWidgetDebugReport(PgtkWidget(Handle)),
' Client=',DbgS(ClientWidget),WidgetFlagsToString(ClientWidget),
' WindowSize=',dbgs(ARect.Right),',',dbgs(ARect.Bottom),
' Allocation=',dbgs(ClientWidget^.Allocation.Width),',',dbgs(ClientWidget^.Allocation.Height)
);
end else begin
DebugLn('GetClientRect Widget=',GetWidgetDebugReport(PgtkWidget(Handle)),
' Client=',DbgS(ClientWidget),WidgetFlagsToString(ClientWidget),
' WindowSize=',dbgs(ARect.Right),',',dbgs(ARect.Bottom),
' Allocation=',dbgs(Widget^.Allocation.Width),',',dbgs(Widget^.Allocation.Height)
);
end;
if GetLCLObject(Widget) is TCustomPage then begin
DebugLn(['TGtkWidgetSet.GetClientRect Rect=',dbgs(aRect),' ',GetWidgetDebugReport(Widget)]);
end;
{$EndIf}
Result:=true;
end;
{------------------------------------------------------------------------------
Function: GetClipBox
Params: dc, lprect
Returns: Integer
Returns the smallest rectangle which includes the entire current
Clipping Region, or if no Clipping Region is set, the current
dimensions of the Drawable.
The result can be one of the following constants
Error
NullRegion
SimpleRegion
ComplexRegion
------------------------------------------------------------------------------}
function TGtkWidgetSet.GetClipBox(DC : hDC; lpRect : PRect) : Longint;
var
DevCtx: TGtkDeviceContext absolute DC;
CRect : TGDKRectangle;
X, Y : Longint;
DCOrigin: Tpoint;
begin
// set default values
Result := SIMPLEREGION;
if lpRect <> nil then
lpRect^ := Rect(0,0,0,0);
if not IsValidDC(DC)
then begin
Result := ERROR;
Exit;
end;
DCOrigin := DevCtx.Offset;
if DevCtx.ClipRegion = nil
then begin
if (DevCtx.PaintRectangle.Left<>0)
or (DevCtx.PaintRectangle.Top<>0)
or (DevCtx.PaintRectangle.Right<>0)
or (DevCtx.PaintRectangle.Bottom<>0) then begin
lpRect^:=DevCtx.PaintRectangle;
end else begin
gdk_window_get_size(DevCtx.Drawable, @X, @Y);
lpRect^ := Rect(0,0,X,Y);
end;
OffsetRect(lpRect^,-DCOrigin.X, -DCOrigin.Y);
Result := SIMPLEREGION;
end
else begin
Result := RegionType(DevCtx.ClipRegion^.GDIRegionObject);
gdk_region_get_clipbox(DevCtx.ClipRegion^.GDIRegionObject, @CRect);
lpRect^.Left := CRect.X-DCOrigin.X;
lpRect^.Top := CRect.Y-DCOrigin.Y;
lpRect^.Right := lpRect^.Left + CRect.Width;
lpRect^.Bottom := lpRect^.Top + CRect.Height;
end;
end;
{------------------------------------------------------------------------------
Function: GetRGNBox
Params: rgn, lprect
Returns: Integer
Returns the smallest rectangle which includes the entire passed
Region, if lprect is null then just returns RegionType.
The result can be one of the following constants
Error
NullRegion
SimpleRegion
ComplexRegion
------------------------------------------------------------------------------}
function TGtkWidgetSet.GetRgnBox(RGN : HRGN; lpRect : PRect) : Longint;
var
CRect : TGDKRectangle;
begin
Result := SIMPLEREGION;
If lpRect <> nil then
lpRect^ := Rect(0,0,0,0);
If Not IsValidGDIObject(RGN) then
Result := ERROR
else begin
Result := RegionType(PGDIObject(RGN)^.GDIRegionObject);
If lpRect <> nil then begin
gdk_region_get_clipbox(PGDIObject(RGN)^.GDIRegionObject,
@CRect);
With lpRect^ do begin
Left := CRect.X;
Top := CRect.Y;
Right := CRect.X + CRect.Width;
Bottom := CRect.Y + CRect.Height;
end;
end;
end;
end;
function TGtkWidgetSet.GetROP2(DC: HDC): Integer;
begin
if IsValidDC(DC)
then Result := TGtkDeviceContext(DC).ROP2
else Result := 0;
end;
{------------------------------------------------------------------------------
Function: GetClipRGN
Params: dc, rgn
Returns: Integer
Returns a copy of the current Clipping Region.
The result can be one of the following constants
0 = no clipping set
1 = ok
-1 = error
------------------------------------------------------------------------------}
function TGtkWidgetSet.GetClipRGN(DC : hDC; RGN : hRGN) : longint;
var
DCOrigin: TPoint;
ClipRegionWithDCOffset: PGdkRegion;
CurRegionObject: PGdkRegion;
ARect: TRect;
begin
Result := SIMPLEREGION;
If (not IsValidDC(DC)) then
Result := ERROR
else If Not IsValidGDIObject(RGN) then begin
Result := ERROR;
DebugLn('WARNING: [TGtkWidgetSet.GetClipRGN] Invalid HRGN');
end
else if (TGtkDeviceContext(DC).ClipRegion<>nil)
and (not IsValidGDIObject(HGDIOBJ(PtrUInt(TGtkDeviceContext(DC).ClipRegion)))) then
Result := ERROR
else with TGtkDeviceContext(DC) do
begin
CurRegionObject:=nil;
if ClipRegion<>nil then
CurRegionObject:=ClipRegion^.GDIRegionObject;
ARect:=Rect(0,0,0,0);
if CurRegionObject<>nil then begin
// create a copy of the current clipregion
ClipRegionWithDCOffset:=gdk_region_copy(CurRegionObject);
// move it to the DC offset
// Example: if the ClipRegion is at 10,10 and the DCOrigin is at 10,10,
// then the ClipRegion must be moved to 0,0
DCOrigin := Offset;
//debugln('TGtkWidgetSet.GetClipRGN DCOrigin=',dbgs(DCOrigin),' CurRegionObject=',dbgs(CurRegionObject),' ',dbgs(ARect));
gdk_region_offset(ClipRegionWithDCOffset,-DCOrigin.x,-DCOrigin.Y);
end else begin
// create a default clipregion
GetClipBox(DC,@ARect);
ClipRegionWithDCOffset:=CreateRectGDKRegion(ARect);
end;
// free the old region in RGN
if PGdiObject(RGN)^.GDIRegionObject<>nil then
gdk_region_destroy(PGdiObject(RGN)^.GDIRegionObject);
// set the new region in RGN
PGdiObject(RGN)^.GDIRegionObject := ClipRegionWithDCOffset;
Result := RegionType(ClipRegionWithDCOffset);
//DebugLn('TGtkWidgetSet.GetClipRGN B DC=',DbgS(DC),
// ' DCOrigin=',dbgs(DCOrigin),' RGN=',GDKRegionAsString(ClipRegionWithDCOffset),' Result=',dbgs(Result));
If Result = NULLREGION then
Result := 0
else If Result <> ERROR then
Result := 1;
end;
If Result = ERROR then
Result := -1;
end;
{------------------------------------------------------------------------------
Function: GetCmdLineParamDescForInterface
Params: none
Returns: ansistring
Returns a description of the command line parameters, that are understood by
the interface.
------------------------------------------------------------------------------}
function TGtkWidgetSet.GetCmdLineParamDescForInterface: TStringList;
begin
result := TStringList.Create;
AddCmdLineParamDesc(result, ['--lcl-no-transient'], rsgtkOptionNoTransient);
AddCmdLineParamDesc(result, ['--gtk-module <module>'], rsgtkOptionModule);
AddCmdLineParamDesc(result, ['--g-fatal-warnings'], rsgOptionFatalWarnings);
AddCmdLineParamDesc(result, ['--gtk-debug <flags>'], rsgtkOptionDebug);
AddCmdLineParamDesc(result, ['--gtk-no-debug <flags>'], rsgtkOptionNoDebug);
AddCmdLineParamDesc(result, ['--gdk-debug <flags>'], rsgdkOptionDebug);
AddCmdLineParamDesc(result, ['--gdk-no-debug <flags>'], rsgdkOptionNoDebug);
AddCmdLineParamDesc(result, ['--display <h:s:d>'], rsgtkOptionDisplay);
AddCmdLineParamDesc(result, ['--sync'], rsgtkOptionSync);
AddCmdLineParamDesc(result, ['--no-xshm'], rsgtkOptionNoXshm);
AddCmdLineParamDesc(result, ['--name <progname>'], rsgtkOptionName);
AddCmdLineParamDesc(result, ['--class <classname>'], rsgtkOptionClass);
end;
{------------------------------------------------------------------------------
Function: GetCursorPos
Params: lpPoint: The cursorposition
Returns: True if succesful
------------------------------------------------------------------------------}
function TGtkWidgetSet.GetCursorPos(var lpPoint: TPoint): Boolean;
{$IFDEF HasX}
var
dpy: PDisplay;
root, child: twindow;
winx, winy: Integer;
xmask: Cardinal;
begin
Result := true;
if (not MousePositionValid) or (Abs(MousePositionTime-Now)>1/864000) then
begin
// querying the X cursor is expensive (especially on network connections)
// => use a lazy query
{$IFDEF DebugGDKTraps}
BeginGDKErrorTrap;
try
{$ENDIF}
dpy := gdk_display;
XQueryPointer(dpy, RootWindow(dpy, DefaultScreen(dpy)), @root, @child,
@MousePosition.X,@MousePosition.Y,@winx,@winy,@xmask);
{$IFDEF DebugGDKTraps}
finally
EndGDKErrorTrap;
end;
{$ENDIF}
MousePositionTime:=Now;
MousePositionValid:=true;
end;
lpPoint:=MousePosition;
end;
{$ELSE}
begin
// TODO: GTK1-win32 GetCursorPos
Result := False;
end;
{$ENDIF HasX}
function TGTKWidgetSet.GetCurrentObject(DC: HDC; uObjectType: UINT): HGDIOBJ;
var
GtkDC: TGtkDeviceContext absolute DC;
begin
Result := 0;
if not GTKWidgetSet.IsValidDC(DC) then
Exit;
case uObjectType of
OBJ_BITMAP: Result := HGDIOBJ(GtkDC.CurrentBitmap);
OBJ_BRUSH: Result := HGDIOBJ(GtkDC.CurrentBrush);
OBJ_FONT: Result := HGDIOBJ(GtkDC.CurrentFont);
OBJ_PEN: Result := HGDIOBJ(GtkDC.CurrentPen);
end;
end;
{------------------------------------------------------------------------------
Function: GetDC
Params: none
Returns: Nothing
hWnd is any widget.
The DC will be created for the client area and without the child areas
(they are clipped away). Child areas are all child gdkwindows
(e.g. not TControls).
------------------------------------------------------------------------------}
function TGtkWidgetSet.GetDC(hWnd: HWND): HDC;
begin
Result:=CreateDCForWidget(PGtkWidget(hWnd),nil,false);
end;
{------------------------------------------------------------------------------
function TGtkWidgetSet.GetDeviceCaps(DC: HDC; Index: Integer): Integer;
------------------------------------------------------------------------------}
function TGtkWidgetSet.GetDeviceCaps(DC: HDC; Index: Integer): Integer;
var
Visual: PGdkVisual;
function GetVisual: boolean;
begin
Visual:=nil;
with TGtkDeviceContext(DC) do begin
If Drawable <> nil then
Visual:=gdk_window_get_visual(PGdkWindow(Drawable));
if Visual = nil then
Visual := GDK_Visual_Get_System;
end;
Result:=Visual<>nil;
end;
begin
Result := -1;
If DC = 0 then begin
DC := GetDC(0);
If DC = 0 then
exit;
Result := GetDeviceCaps(DC, Index);
ReleaseDC(0, DC);
exit;
end;
if not IsValidDC(DC) then exit;
with TGtkDeviceContext(DC) do
Case Index of
HORZRES : { Horizontal width in pixels }
If Drawable = nil then
Result := GetSystemMetrics(SM_CXSCREEN)
else
gdk_drawable_get_size(Drawable, @Result, nil);
VERTRES : { Vertical height in pixels }
If Drawable = nil then
Result := GetSystemMetrics(SM_CYSCREEN)
else
gdk_drawable_get_size(Drawable, nil, @Result);
BITSPIXEL : { Number of used bits per pixel = depth }
If Drawable = nil then
Result := GDK_Visual_Get_System^.Depth
else
Result := gdk_drawable_get_depth(Drawable);
PLANES : { Number of planes }
// ToDo
Result := 1;
//For Size in MM, MM = (Pixels*100)/(PPI*25.4)
HORZSIZE : { Horizontal size in millimeters }
Result := RoundToInt((GetDeviceCaps(DC, HORZRES) * 100) /
(GetDeviceCaps(DC, LOGPIXELSX) * 25.4));
VERTSIZE : { Vertical size in millimeters }
Result := RoundToInt((GetDeviceCaps(DC, VERTRES) * 100) /
(GetDeviceCaps(DC, LOGPIXELSY) * 25.4));
//So long as gdk_screen_width_mm is acurate, these should be
//acurate for Screen GDKDrawables. Once we get Metafiles
//we will also have to add internal support for Papersizes etc..
LOGPIXELSX : { Logical pixels per inch in X }
Result := RoundToInt(gdk_screen_width / (GetScreenWidthMM / 25.4));
LOGPIXELSY : { Logical pixels per inch in Y }
Result := RoundToInt(gdk_screen_height / (GetScreenHeightMM / 25.4));
SIZEPALETTE: { number of entries in color palette }
if GetVisual then
Result:=Visual^.colormap_size
else
Result:=0;
NUMRESERVED: { number of reserverd colors in color palette }
Result:=0;
else
DebugLn('TGtkWidgetSet.GetDeviceCaps not supported: Type=',dbgs(Index));
end;
end;
{------------------------------------------------------------------------------
function GetDeviceSize(DC: HDC; var p: TPoint): boolean;
Retrieves the width and height of the device context in pixels.
------------------------------------------------------------------------------}
function TGtkWidgetSet.GetDeviceSize(DC: HDC; var p: TPoint): boolean;
var
DevCtx: TGtkDeviceContext absolute DC;
begin
if not IsValidDC(DC) then Exit(False);
if DevCtx.Drawable <> nil
then begin
P := Point(0,0);
gdk_window_get_size(PGdkWindow(DevCtx.Drawable), @P.X, @P.Y);
Exit(True);
end;
{$ifdef gtk1}
if DevCtx.Widget = nil
then begin
// either empty or gtk1screen
p.x:=gdk_screen_width;
p.y:=gdk_screen_height;
Exit(True);
end;
{$endif}
{$IFDEF RaiseExceptionOnNilPointers}
RaiseException('TGtkWidgetSet.GetDeviceSize Window=nil');
{$ENDIF}
DebugLn('TGtkWidgetSet.GetDeviceSize:', ' WARNING: DC ',DbgS(DC),' without gdkwindow.',
' Widget=',DbgS(DevCtx.Widget));
Result := False;
end;
{------------------------------------------------------------------------------
function TGtkWidgetSet.GetDCOriginRelativeToWindow(PaintDC: HDC;
WindowHandle: HWND; var OriginDiff: TPoint): boolean;
Returns the origin of PaintDC relative to the window handle.
Example:
A PaintDC of a TButton at 20,10 with a DC Offset of 0,0 on a form and the
WindowHandle is the form.
Then OriginDiff is the difference between the Forms client origin
and the PaintDC: 20,10.
------------------------------------------------------------------------------}
function TGtkWidgetSet.GetDCOriginRelativeToWindow(PaintDC: HDC;
WindowHandle: HWND; var OriginDiff: TPoint): boolean;
var
DevCtx: TGtkDeviceContext absolute PaintDC;
DCOrigin: TPoint;
DCScreenOrigin: TPoint;
WindowScreenOrigin: TPoint;
Widget: PGtkWidget;
DCWindow: PGdkWindow;
begin
Result := false;
OriginDiff := Point(0,0);
if not IsValidDC(PaintDC) then exit;
DCOrigin := DevCtx.Offset;
DCWindow:=PGdkWindow(DevCtx.Drawable);
gdk_window_get_origin(DCWindow, @(DCScreenOrigin.X), @(DCScreenOrigin.Y));
inc(DCScreenOrigin.X, DCOrigin.X);
inc(DCScreenOrigin.Y, DCOrigin.Y);
Widget := GetFixedWidget(PGtkWidget(WindowHandle));
if Widget = nil
then Widget := PGtkWidget(WindowHandle);
gdk_window_get_origin(PGdkWindow(Widget^.window), @(WindowScreenOrigin.X), @(WindowScreenOrigin.Y));
OriginDiff.X := DCScreenOrigin.X-WindowScreenOrigin.X;
OriginDiff.Y := DCScreenOrigin.Y-WindowScreenOrigin.Y;
Result := true;
//DebugLn(['TGtkWidgetSet.GetDCOriginRelativeToWindow DCScreenOrigin=',dbgs(DCScreenOrigin),' WindowScreenOrigin=',dbgs(WindowScreenOrigin),' OriginDiff=',dbgs(OriginDiff)]);
end;
{------------------------------------------------------------------------------
Function: GetDesignerDC
Params: none
Returns: Nothing
WindowHandle is any widget.
The DC will be created for the client area including the child areas.
------------------------------------------------------------------------------}
function TGtkWidgetSet.GetDesignerDC(WindowHandle: HWND): HDC;
begin
//DebugLn('TGtkWidgetSet.GetDesignerDC A');
Result:=CreateDCForWidget(PGtkWidget(WindowHandle),nil,true);
end;
{------------------------------------------------------------------------------
Function: GetFocus
Params: none
Returns: The handle of the window with focus
The GetFocus function retrieves the handle of the window that has the focus.
------------------------------------------------------------------------------}
function TGtkWidgetSet.GetFocus: HWND;
var
TopList, List: PGList;
Widget: PGTKWidget;
Window: PGTKWindow;
Info: PWidgetInfo;
begin
// Default to 0
Result := 0;
{$IFDEF DebugGDKTraps}
BeginGDKErrorTrap;
{$ENDIF}
TopList := gdk_window_get_toplevels;
List := TopList;
while List <> nil do
begin
if (List^.Data <> nil)
then begin
gdk_window_get_user_data(PGDKWindow(List^.Data), Pgpointer(@Window));
if gtk_is_window(Window)
then begin
Widget := Window^.focus_widget;
{$IFDEF DebugLCLComponents}
if DebugGtkWidgets.IsDestroyed(Widget) then begin
DebugLn(['TGtkWidgetSet.GetFocus Window^.focus_widget was already destroyed:']);
DebugLn(DebugGtkWidgets.GetInfo(Widget,true));
end;
{$ENDIF}
if (Widget <> nil) and gtk_widget_has_focus(Widget)
then begin
Info:=GetWidgetInfo(PGtkWidget(Window),false);
if (Info=nil) or (not (wwiDeactivating in Info^.Flags)) then
Result := HWND(PtrUInt(GetMainWidget(Widget)));
Break;
end;
end;
end;
list := g_list_next(list);
end;
if TopList <> nil
then g_list_free(TopList);
{$IFDEF DebugGDKTraps}EndGDKErrorTrap;{$ENDIF}
end;
{------------------------------------------------------------------------------
function GetFontLanguageInfo(DC: HDC): DWord; override;
------------------------------------------------------------------------------}
function TGtkWidgetSet.GetFontLanguageInfo(DC: HDC): DWord;
var
DevCtx: TGtkDeviceContext absolute DC;
begin
Result := 0;
If IsValidDC(DC) then
with TGtkDeviceContext(DC) do begin
UpdateDCTextMetric(TGtkDeviceContext(DC));
if TGtkDeviceContext(DC).DCTextMetric.IsDoubleByteChar then
inc(Result,GCP_DBCS);
end;
end;
{------------------------------------------------------------------------------
Function: GetKeyState
Params: nVirtKey: The requested key
Returns: If the function succeeds, the return value specifies the status of
the given virtual key. If the high-order bit is 1, the key is down;
otherwise, it is up. If the low-order bit is 1, the key is toggled.
The GetKeyState function retrieves the status of the specified virtual key.
------------------------------------------------------------------------------}
function TGtkWidgetSet.GetKeyState(nVirtKey: Integer): Smallint;
const
StateDown = -128; // $FF80
StateToggled = 1;
KEYSTATE: array[Boolean] of Smallint = (0, StateDown);
TOGGLESTATE: array[Boolean] of Smallint = (0, StateToggled);
GDK_BUTTON_MASKS: array[VK_LBUTTON..VK_XBUTTON2] of guint32 =
(
{ VK_LBUTTON } GDK_BUTTON1_MASK,
{ VK_RBUTTON } GDK_BUTTON3_MASK,
{ VK_CANCEL } 0,
{ VK_MBUTTON } GDK_BUTTON2_MASK,
{ VK_XBUTTON1 } GDK_BUTTON4_MASK,
{ VK_XBUTTON2 } GDK_BUTTON5_MASK
);
var
GdkModMask: TGdkModifierType;
x, y: gint;
{$IFDEF GTK1}
List: PGList;
{$ENDIF}
begin
case nVirtKey of
// remap
VK_LSHIFT: nVirtKey := VK_SHIFT;
VK_LCONTROL: nVirtKey := VK_CONTROL;
VK_LMENU: nVirtKey := VK_MENU;
end;
{$IFDEF Use_KeyStateList}
Result := KEYSTATE[FKeyStateList_.IndexOf(Pointer(PtrInt(nVirtKey))) >=0];
{$ELSE}
Implement this
{$ENDIF}
// try extended keys
if Result = 0
then begin
{$IFDEF Use_KeyStateList}
Result := KEYSTATE[FKeyStateList_.IndexOf(Pointer(PtrInt(nVirtKey or KEYMAP_EXTENDED))) >=0];
{$ELSE}
Implement this
{$ENDIF}
end;
{$IFDEF Use_KeyStateList}
// add toggle
Result := Result or TOGGLESTATE[FKeyStateList_.IndexOf(Pointer(
PtrInt(nVirtKey or KEYMAP_TOGGLE))) >=0];
{$IFDEF GTK2}
// If there are tons of new keyboard errors this is probably the cause
GdkModMask := gtk_accelerator_get_default_mod_mask;
if (Result and StateDown) <> 0 then
begin
if (nVirtKey = VK_CONTROL) and (GdkModMask and GDK_CONTROL_MASK = 0) then
Result := Result and not StateDown;
//if (nVirtKey = VK_SHIFT) and (GtkModMask and GDK_SHIFT_MASK = 0 then
// Result := Result and not StateDown;
end;
{$ENDIF}
{$ENDIF}
// Mouse buttons. Toggle state is not tracked
if nVirtKey in [VK_LBUTTON, VK_RBUTTON, VK_MBUTTON..VK_XBUTTON2] then
begin
{$ifdef gtk1}
List := gdk_window_get_toplevels;
if g_list_length(List) > 0 then
gdk_window_get_pointer(g_list_nth_data(List, 0), @x, @y, @GdkModMask)
else
GdkModMask := 0;
g_list_free(List);
{$else}
gdk_display_get_pointer(gdk_display_get_default, nil,
@x, @y, @GdkModMask);
{$endif}
Result := Result or KEYSTATE[GdkModMask and GDK_BUTTON_MASKS[nVirtKey] <> 0]
end;
//DebugLn(Format('Trace:[TGtkWidgetSet.GetKeyState] %d -> 0x%x', [nVirtKey, Result]));
end;
function TGtkWidgetSet.GetMapMode(DC: HDC): Integer;
var
DevCtx: TGtkDeviceContext absolute DC;
begin
if IsValidDC(DC) then
Result := DevCtx.MapMode
else
Result := 0;
end;
function TGTKWidgetSet.GetMonitorInfo(Monitor: HMONITOR; lpmi: PMonitorInfo): Boolean;
{$IFDEF HasX}
var
x, y, w, h: gint;
{$ENDIF}
begin
Result := (lpmi <> nil) and (lpmi^.cbSize >= SizeOf(TMonitorInfo)) and (Monitor = 1);
if not Result then Exit;
lpmi^.rcMonitor := Bounds(0, 0, gdk_screen_width, gdk_screen_height);
{$IFDEF HasX}
if XGetWorkarea(x, y, w, h) <> -1 then
lpmi^.rcWork := Bounds(x, y, w, h)
else
{$ENDIF}
lpmi^.rcWork := lpmi^.rcMonitor;
lpmi^.dwFlags := MONITORINFOF_PRIMARY
end;
{------------------------------------------------------------------------------
Function: GetObject
Params: GDIObj - handle, BufSize - size of Buf argument, Buf - buffer
Returns: Size of buffer
------------------------------------------------------------------------------}
function TGtkWidgetSet.GetObject(GDIObj: HGDIOBJ; BufSize: Integer; Buf: Pointer): Integer;
function GetObject_Bitmap: Integer;
var
NumColors, ImageDepth: Longint;
BitmapSection : TDIBSECTION;
begin
if Buf = nil
then begin
Result := SizeOf(TDIBSECTION);
Exit;
end;
Result := 0;
FillChar(BitmapSection, SizeOf(TDIBSECTION), 0);
with PGDIObject(GDIObj)^, BitmapSection,
BitmapSection.dsBm, BitmapSection.dsBmih
do begin
{dsBM - BITMAP}
bmType := LeToN($4D42);
bmWidth := 0 ;
bmHeight := 0;
{bmWidthBytes: Longint;}
bmPlanes := 1;//Does Bitmap Format support more?
bmBitsPixel := 1;
bmBits := nil;
{dsBmih - BITMAPINFOHEADER}
biSize := 40;
biWidth := 0;
biHeight := 0;
biPlanes := bmPlanes;
biBitCount := 1;
biCompression := 0;
biSizeImage := 0;
biXPelsPerMeter := 0;
biYPelsPerMeter := 0;
biClrUsed := 0;
biClrImportant := 0;
{dsBitfields: array[0..2] of DWORD;
dshSection: THandle;
dsOffset: DWORD;}
{$ifdef DebugGDKTraps}BeginGDKErrorTrap;{$endif}
case GDIBitmapType of
gbBitmap:
if GDIBitmapObject <> nil
then begin
gdk_window_get_size(GDIBitmapObject, @biWidth, @biHeight);
NumColors := 2;
biBitCount := 1;
end;
gbPixmap:
if GDIPixmapObject.Image <> nil
then begin
{$ifdef gtk1}
gdk_window_get_geometry(GDIPixmapObject.Image, nil, nil, @biWidth, @biHeight, @ImageDepth);
{$else}
gdk_drawable_get_size(GDIPixmapObject.Image, @biWidth, @biHeight);
ImageDepth := gdk_drawable_get_depth(GDIPixmapObject.Image);
{$endif}
biBitCount := ImageDepth;
end;
gbPixbuf:
if GDIPixbufObject <> nil
then begin
biWidth := gdk_pixbuf_get_width(GDIPixbufObject);
biHeight := gdk_pixbuf_get_height(GDIPixbufObject);
biBitCount := gdk_pixbuf_get_bits_per_sample(GDIPixbufObject) * gdk_pixbuf_get_n_channels(GDIPixbufObject);
end;
end;
if Visual = nil
then begin
Visual := gdk_visual_get_best_with_depth(biBitCount);
if Visual = nil
then { Depth not supported }
Visual := gdk_visual_get_system;
SystemVisual := True; { This visual should not be referenced }
if Colormap <> nil then
gdk_colormap_unref(Colormap);
ColorMap := gdk_colormap_new(Visual, GdkTrue);
end
else
biBitCount := Visual^.Depth;
{$ifdef DebugGDKTraps}EndGDKErrorTrap;{$enDIF}
if biBitCount < 16 then
NumColors := Colormap^.Size;
biSizeImage := (((biBitCount*biWidth+31) shr 5) shl 2)*biHeight;
if GetSystemMetrics(SM_CXSCREEN) >= biWidth then
biXPelsPerMeter := GetDeviceCaps(0, LOGPIXELSX)
else
biXPelsPerMeter :=
RoundToInt((single(biWidth) / GetSystemMetrics(SM_CXSCREEN)) *
GetDeviceCaps(0, LOGPIXELSX));
if GetSystemMetrics(SM_CYSCREEN) >= biHeight then
biYPelsPerMeter := GetDeviceCaps(0, LOGPIXELSY)
else
biYPelsPerMeter :=
RoundToInt((Single(biHeight) / GetSystemMetrics(SM_CYSCREEN))*
GetDeviceCaps(0, LOGPIXELSY));
bmWidth := biWidth;
bmHeight := biHeight;
bmBitsPixel := biBitCount;
//Need to retrieve actual Number of Colors if Indexed Image
if bmBitsPixel < 16
then begin
biClrUsed := NumColors;
biClrImportant := biClrUsed;
end;
end;
if BufSize >= SizeOf(BitmapSection)
then begin
PDIBSECTION(Buf)^ := BitmapSection;
Result := SizeOf(TDIBSECTION);
end
else if BufSize>0
then begin
Move(BitmapSection,Buf^,BufSize);
Result := BufSize;
end;
end;
var
GDIObject: PGDIObject absolute GDIObj;
ALogPen: PLogPen absolute Buf;
AExtLogPen: PExtLogPen absolute Buf;
i, RequiredSize: Integer;
begin
//DebugLn('trace:[TGtkWidgetSet.GetObject]');
Result := 0;
if not IsValidGDIObject(GDIObj) then Exit;
case GDIObject^.GDIType of
gdiBitmap:
Result := GetObject_Bitmap;
gdiBrush:
begin
//DebugLn('Trace:TODO: [TGtkWidgetSet.GetObject] gdiBrush');
end;
gdiFont:
begin
if Buf = nil
then begin
Result := SizeOf(GDIObject^.LogFont);
Exit;
end;
if BufSize >= SizeOf(GDIObject^.LogFont)
then begin
PLogfont(Buf)^ := GDIObject^.LogFont;
Result:= SizeOf(TLogFont);
end
else if BufSize > 0
then begin
Move(GDIObject^.LogFont,Buf^,BufSize);
Result:=BufSize;
end;
end;
gdiPen:
begin
if GDIObject^.IsExtPen then
begin
RequiredSize := SizeOf(TExtLogPen);
if GDIObject^.GDIPenDashesCount > 1 then
RequiredSize := RequiredSize + (GDIObject^.GDIPenDashesCount - 1) * SizeOf(DWord);
if Buf = nil then
Result := RequiredSize
else
if BufSize >= RequiredSize then
begin
Result := RequiredSize;
AExtLogPen^.elpPenStyle := GDIObject^.GDIPenStyle;
AExtLogPen^.elpWidth := GDIObject^.GDIPenWidth;
AExtLogPen^.elpBrushStyle := BS_SOLID;
AExtLogPen^.elpColor := GDIObject^.GDIPenColor.ColorRef;
AExtLogPen^.elpHatch := 0;
AExtLogPen^.elpNumEntries := GDIObject^.GDIPenDashesCount;
if GDIObject^.GDIPenDashesCount > 0 then
begin
for i := 0 to GDIObject^.GDIPenDashesCount - 1 do
PDWord(@AExtLogPen^.elpStyleEntry)[i] := GDIObject^.GDIPenDashes[i];
end
else
AExtLogPen^.elpStyleEntry[0] := 0;
end;
end
else
begin
if Buf = nil then
Result := SizeOf(TLogPen)
else
if BufSize >= SizeOf(TLogPen) then
begin
Result := SizeOf(TLogPen);
ALogPen^.lopnColor := GDIObject^.GDIPenColor.ColorRef;
ALogPen^.lopnWidth := Point(GDIObject^.GDIPenWidth, 0);
ALogPen^.lopnStyle := GDIObject^.GDIPenStyle;
end;
end;
end;
gdiRegion:
begin
//DebugLn('Trace:TODO: [TGtkWidgetSet.GetObject] gdiRegion');
end;
else
DebugLn('WARNING: [TGtkWidgetSet.GetObject] Unknown type %d', [Integer(GDIObject^.GDIType)]);
end;
end;
{------------------------------------------------------------------------------
Function: GetParent
Params: Handle:
Returns:
------------------------------------------------------------------------------}
function TGtkWidgetSet.GetParent(Handle : HWND): HWND;
begin
if Handle <> 0 then
Result := HWnd(PGtkWidget(Handle)^.Parent)
else
Result := 0;
end;
{------------------------------------------------------------------------------
Function: GetProp
Params: Handle: Str
Returns: Pointer
------------------------------------------------------------------------------}
function TGtkWidgetSet.GetProp(Handle : hwnd; Str : PChar): Pointer;
Begin
Result := gtk_object_get_data(pgtkobject(Handle),Str);
end;
{------------------------------------------------------------------------------
function TGtkWidgetSet.GetScrollBarSize(Handle: HWND; BarKind: Integer): integer;
Returns the current width of the scrollbar of the widget.
------------------------------------------------------------------------------}
function TGtkWidgetSet.GetScrollBarSize(Handle: HWND; BarKind: Integer): integer;
var
Widget, ScrollWidget, BarWidget: PGtkWidget;
begin
Result:=0;
Widget:=PGtkWidget(Handle);
if GtkWidgetIsA(Widget,GTK_TYPE_SCROLLED_WINDOW) then begin
ScrollWidget:=Widget;
end else begin
ScrollWidget:=PGtkWidget(gtk_object_get_data(
PGtkObject(Widget),odnScrollArea));
end;
if ScrollWidget=nil then exit;
if BarKind=SM_CYVSCROLL then begin
BarWidget:=PGtkScrolledWindow(ScrollWidget)^.vscrollbar;
if BarWidget<>nil then
Result:=BarWidget^.Requisition.Width;
end else begin
BarWidget:=PGtkScrolledWindow(ScrollWidget)^.hscrollbar;
if BarWidget<>nil then
Result:=BarWidget^.Requisition.Height;
end;
end;
{------------------------------------------------------------------------------
function TGtkWidgetSet.GetScrollbarVisible(Handle: HWND;
SBStyle: Integer): boolean;
------------------------------------------------------------------------------}
function TGtkWidgetSet.GetScrollbarVisible(Handle: HWND; SBStyle: Integer): boolean;
var
Widget, ScrollWidget, BarWidget: PGtkWidget;
begin
Result:=false;
if Handle=0 then exit;
Widget:=PGtkWidget(Handle);
if GtkWidgetIsA(Widget,GTK_TYPE_SCROLLED_WINDOW) then begin
ScrollWidget:=Widget;
end else begin
ScrollWidget:=PGtkWidget(gtk_object_get_data(
PGtkObject(Widget),odnScrollArea));
end;
if ScrollWidget=nil then exit;
if SBStyle=SB_VERT then begin
BarWidget:=PGtkScrolledWindow(ScrollWidget)^.vscrollbar;
end else begin
BarWidget:=PGtkScrolledWindow(ScrollWidget)^.hscrollbar;
end;
if BarWidget<>nil then
Result:=GTK_WIDGET_VISIBLE(BarWidget);
end;
{------------------------------------------------------------------------------
Function: GetScrollInfo
Params: Handle, BarFlag, ScrollInfo
Returns: Nothing
------------------------------------------------------------------------------}
function TGtkWidgetSet.GetScrollInfo(Handle: HWND; SBStyle: Integer;
var ScrollInfo: TScrollInfo): Boolean;
var
Adjustment: PGtkAdjustment;
Scroll : PGTKWidget;
IsScrollWindow: Boolean;
begin
Result := false;
if (Handle = 0) then exit;
Scroll := gtk_object_get_data(PGTKObject(Handle), odnScrollArea);
if GtkWidgetIsA(Scroll, gtk_scrolled_window_get_type)
then begin
IsScrollWindow := True;
end
else begin
Scroll := PGTKWidget(Handle);
IsScrollWindow := GtkWidgetIsA(Scroll, gtk_scrolled_window_get_type);
end;
Adjustment := nil;
case SBStyle of
SB_HORZ:
if IsScrollWindow
then begin
Adjustment := gtk_scrolled_window_get_hadjustment(
PGTKScrolledWindow(Scroll));
end
else if GtkWidgetIsA(PGtkWidget(Scroll),gtk_clist_get_type)
then begin
//clist
{TODO check is this is needed for listviews}
DebugLn('[GetScrollInfo] Possible obsolete get use of CList (Listview ?)');
Adjustment := gtk_clist_get_hadjustment(PgtkCList(Scroll));
end
// obsolete stuff
else if GtkWidgetIsA(PGtkWidget(Scroll),gtk_hscrollbar_get_type)
then begin
// this one shouldn't be possible, scrolbar messages are sent to the CTL
DebugLN('!!! direct SB_HORZ get call to scrollbar');
Adjustment := PgtkhScrollBar(Scroll)^.Scrollbar.Range.Adjustment;
end;
SB_VERT:
if GtkWidgetIsA(PGtkWidget(Scroll),gtk_scrolled_window_get_type)
then begin
Adjustment := gtk_scrolled_window_get_vadjustment(
PGTKScrolledWindow(Scroll));
end
else if GtkWidgetIsA(PGtkWidget(Scroll), gtk_clist_get_type)
then begin
//clist
//TODO: check is this is needed for listviews
DebugLn('[GetScrollInfo] Possible obsolete get use of CList (Listview ?)');
Adjustment := gtk_clist_get_vadjustment(PgtkCList(Scroll));
end
// obsolete stuff
else if GtkWidgetIsA(PGtkWidget(Scroll),gtk_vscrollbar_get_type)
then begin
// this one shouldn't be possible, scrolbar messages are sent to the CTL
DebugLN('!!! direct SB_HORZ get call to scrollbar');
Adjustment := PgtkvScrollBar(Scroll)^.Scrollbar.Range.Adjustment;
end;
SB_CTL:
if GtkWidgetIsA(PGtkWidget(Scroll),gtk_vscrollbar_get_type) then
Adjustment := PgtkvScrollBar(Scroll)^.Scrollbar.Range.Adjustment
else
if GtkWidgetIsA(PGtkWidget(Scroll),gtk_hscrollbar_get_type) then
Adjustment := PgtkhScrollBar(Scroll)^.Scrollbar.Range.Adjustment
else
if GtkWidgetIsA(PGtkWidget(Scroll), gtk_range_get_type) then
Adjustment := gtk_range_get_adjustment(PGTKRange(Scroll));
SB_BOTH:
DebugLn('[GetScrollInfo] Got SB_BOTH ???');
end;
if Adjustment = nil then Exit;
// POS
if (ScrollInfo.fMask and SIF_POS) <> 0
then begin
ScrollInfo.nPos := Round(Adjustment^.Value);
end;
// RANGE
if (ScrollInfo.fMask and SIF_RANGE) <> 0
then begin
ScrollInfo.nMin:= Round(Adjustment^.Lower);
ScrollInfo.nMax:= Round(Adjustment^.Upper);
end;
// PAGE
if (ScrollInfo.fMask and SIF_PAGE) <> 0
then begin
ScrollInfo.nPage := Round(Adjustment^.Page_Size);
end;
// TRACKPOS
if (ScrollInfo.fMask and SIF_TRACKPOS) <> 0
then begin
ScrollInfo.nTrackPos := Round(Adjustment^.Value);
end;
Result := true;
end;
{------------------------------------------------------------------------------
Function: GetStockObject
Params:
Returns: Nothing
------------------------------------------------------------------------------}
function TGtkWidgetSet.GetStockObject(Value: Integer): TLCLHandle;
begin
//DebugLn(Format('Trace:> [TGtkWidgetSet.GetStockObject] %d', [Value]));
Result := 0;
case Value of
BLACK_BRUSH: // Black brush.
Result := FStockBlackBrush;
DKGRAY_BRUSH: // Dark gray brush.
Result := FStockDKGrayBrush;
GRAY_BRUSH: // Gray brush.
Result := FStockGrayBrush;
LTGRAY_BRUSH: // Light gray brush.
Result := FStockLtGrayBrush;
NULL_BRUSH: // Null brush (equivalent to HOLLOW_BRUSH).
Result := FStockNullBrush;
WHITE_BRUSH: // White brush.
Result := FStockWhiteBrush;
BLACK_PEN: // Black pen.
Result := FStockBlackPen;
NULL_PEN: // Null pen.
Result := FStockNullPen;
WHITE_PEN: // White pen.
Result := FStockWhitePen;
(* ANSI_FIXED_FONT: // Fixed-pitch (monospace) system font.
begin
{If FStockFixedFont = 0 then
FStockFixedFont := GetStockFixedFont;
Result := FStockFixedFont;}
end;
ANSI_VAR_FONT: // Variable-pitch (proportional space) system font.
begin
end;
DEVICE_DEFAULT_FONT: // Device-dependent font.
begin
end; *)
(* OEM_FIXED_FONT: // Original equipment manufacturer (OEM) dependent fixed-pitch (monospace) font.
begin
end;
*)
DEFAULT_GUI_FONT, SYSTEM_FONT: // System font. By default, Windows uses the system font to draw menus, dialog box controls, and text. In Windows versions 3.0 and later, the system font is a proportionally spaced font; earlier versions of Windows used a monospace system font.
begin
// MG: this should only be done, when theme changed:
{If FStockSystemFont <> 0 then begin //This is a Temporary Hack!!! This
DeleteObject(FStockSystemFont); //should really only be done on
FStockSystemFont := 0; //theme change.
end;}
If FStockSystemFont = 0 then
FStockSystemFont := HFont(PtrUInt(CreateDefaultFont));
Result := FStockSystemFont;
end;
(* SYSTEM_FIXED_FONT: // Fixed-pitch (monospace) system font used in Windows versions earlier than 3.0. This stock object is provided for compatibility with earlier versions of Windows.
begin
Result := GetStockObject(ANSI_FIXED_FONT);
end;
DEFAULT_PALETTE: // Default palette. This palette consists of the static colors in the system palette.
begin
end;
*) else
//DebugLn(Format('Trace:TODO: [TGtkWidgetSet.GetStockObject] Implement value: %d', [Value]));
end;
//DebugLn(Format('Trace:< [TGtkWidgetSet.GetStockObject] %d --> 0x%x', [Value, Result]));
end;
{------------------------------------------------------------------------------
Function: GetSysColor
Params: index to the syscolors array
Returns: RGB value
------------------------------------------------------------------------------}
function TGtkWidgetSet.GetSysColor(nIndex: Integer): DWORD;
begin
if (nIndex < 0) or (nIndex > MAX_SYS_COLORS)
then begin
Result := 0;
DumpStack;
DebugLn(Format('ERROR: [TGtkWidgetSet.GetSysColor] Bad Value: %d. Valid Range between 0 and %d', [nIndex, MAX_SYS_COLORS]));
end
else
Result := SysColorMap[nIndex];
end;
function TGTKWidgetSet.GetSysColorBrush(nIndex: Integer): HBrush;
begin
if (nIndex < 0) or (nIndex > MAX_SYS_COLORS)
then begin
Result := 0;
DumpStack;
DebugLn(Format('ERROR: [TGtkWidgetSet.GetSysColorBrush] Bad Value: %d. Valid Range between 0 and %d', [nIndex, MAX_SYS_COLORS]));
end
else
Result := FSysColorBrushes[nIndex];
end;
{------------------------------------------------------------------------------
Function: GetSystemMetrics
Params:
Returns: Nothing
------------------------------------------------------------------------------}
function TGtkWidgetSet.GetSystemMetrics(nIndex: Integer): Integer;
var
P: Pointer;
{$ifdef HasX}
ax,ay,ah,aw: gint;
{$endif}
auw, auh: guint;
{$ifdef GTK2}
screen: PGdkScreen;
ARect: TGdkRectangle;
AValue: TGValue;
{$else}
{$ifdef HasX}
XDisplay: PDisplay;
XScreen: PScreen;
XWindow: TWindow;
{$endif}
{$endif}
begin
//DebugLn(Format('Trace:> [TGtkWidgetSet.GetSystemMetrics] %d', [nIndex]));
Result := 0;
case nIndex of
SM_ARRANGE:
begin
//DebugLn('Trace:TODO: [TGtkWidgetSet.GetSystemMetrics] --> SM_ARRANGE ');
end;
SM_CLEANBOOT:
begin
//DebugLn('Trace:TODO: [TGtkWidgetSet.GetSystemMetrics] --> SM_CLEANBOOT ');
end;
SM_CMOUSEBUTTONS:
begin
//DebugLn('Trace:TODO: [TGtkWidgetSet.GetSystemMetrics] --> SM_CMOUSEBUTTONS ');
end;
SM_CXBORDER:
begin
//DebugLn('Trace:TODO: [TGtkWidgetSet.GetSystemMetrics] --> SM_CXBORDER ');
end;
SM_CYBORDER:
begin
//DebugLn('Trace:TODO: [TGtkWidgetSet.GetSystemMetrics] --> SM_CYBORDER ');
end;
SM_CXCURSOR,
SM_CYCURSOR:
begin
{$IFDEF GTK2}
// Width and height of a cursor, in pixels. For win32 system cannot create cursors of other sizes.
// For gtk this should be maximal cursor sizes
gdk_display_get_maximal_cursor_size(gdk_display_get_default, @auw, @auh);
{$ELSE}
{$IFDEF HasX}
// same code used in gtk2 library
XDisplay := gdk_display;
XScreen := XDefaultScreenOfDisplay(XDisplay);
XWindow := XRootWindowOfScreen(XScreen);
XQueryBestCursor(XDisplay, XWindow, 128, 128, @auw, @auh);
{$ELSE}
Result := 32; // Default windows size
{$ENDIF}
{$ENDIF}
if nIndex = SM_CXCURSOR
then Result := auw // return width
else Result := auh; // return height
end;
SM_CXDOUBLECLK:
begin
//DebugLn('Trace:TODO: [TGtkWidgetSet.GetSystemMetrics] --> SM_CXDOUBLECLK ');
end;
SM_CYDOUBLECLK:
begin
//DebugLn('Trace:TODO: [TGtkWidgetSet.GetSystemMetrics] --> SM_CYDOUBLECLK ');
end;
SM_CXDRAG:
begin
Result := 2;
end;
SM_CYDRAG:
begin
Result := 2;
end;
SM_CXEDGE:
begin
Result := 2;
end;
SM_CYEDGE:
begin
Result := 2;
end;
SM_CXFIXEDFRAME:
begin
//DebugLn('Trace:TODO: [TGtkWidgetSet.GetSystemMetrics] --> SM_CXFIXEDFRAME ');
end;
SM_CYFIXEDFRAME:
begin
//DebugLn('Trace:TODO: [TGtkWidgetSet.GetSystemMetrics] --> SM_CYFIXEDFRAME ');
end;
SM_CXHSCROLL:
begin
P := GetStyleWidget(lgsVerticalScrollbar);
if P <> nil then
Result := GTK_Widget(P)^.requisition.Width;
end;
SM_CYHSCROLL:
begin
P := GetStyleWidget(lgsHorizontalScrollbar);
if P <> nil then
Result := GTK_Widget(P)^.requisition.Height;
end;
SM_CXHTHUMB,
SM_CYVTHUMB:
begin
P := GetStyleWidget(lgsHorizontalScrollbar);
if P <> nil then
begin
{$ifdef gtk1}
_gtk_range_get_props(P, nil, nil, @Result, nil);
{$else}
FillChar(AValue, SizeOf(AValue), 0);
g_value_init(@AValue, G_TYPE_INT);
gtk_widget_style_get_property(P, 'slider-width', @AValue);
Result := AValue.data[0].v_int;
{$endif}
end;
end;
SM_CXICON,
SM_CYICON:
Result := 32;
SM_CXICONSPACING:
begin
//DebugLn('Trace:TODO: [TGtkWidgetSet.GetSystemMetrics] --> SM_CXICONSPACING ');
end;
SM_CYICONSPACING:
begin
//DebugLn('Trace:TODO: [TGtkWidgetSet.GetSystemMetrics] --> SM_CYICONSPACING ');
end;
SM_CXMAXIMIZED:
begin
{$IFDEF HasX}
if XGetWorkarea(ax,ay,aw,ah)>=0 then
Result := aw
else
Result := getSystemMetrics(SM_CXSCREEN);
{$ENDIF}
end;
SM_CYMAXIMIZED:
begin
{$IFDEF HasX}
if XGetWorkarea(ax,ay,aw,ah)>=0 then
Result := ah
else
Result := getSystemMetrics(SM_CYSCREEN);
{$ENDIF}
end;
SM_CXMAXTRACK:
begin
//DebugLn('Trace:TODO: [TGtkWidgetSet.GetSystemMetrics] --> SM_CXMAXTRACK ');
end;
SM_CYMAXTRACK:
begin
//DebugLn('Trace:TODO: [TGtkWidgetSet.GetSystemMetrics] --> SM_CYMAXTRACK ');
end;
SM_CXMENUCHECK:
begin
//DebugLn('Trace:TODO: [TGtkWidgetSet.GetSystemMetrics] --> SM_CXMENUCHECK ');
end;
SM_CYMENUCHECK:
begin
//DebugLn('Trace:TODO: [TGtkWidgetSet.GetSystemMetrics] --> SM_CYMENUCHECK ');
end;
SM_CXMENUSIZE:
begin
//DebugLn('Trace:TODO: [TGtkWidgetSet.GetSystemMetrics] --> SM_CXMENUSIZE ');
end;
SM_CYMENUSIZE:
begin
//DebugLn('Trace:TODO: [TGtkWidgetSet.GetSystemMetrics] --> SM_CYMENUSIZE ');
end;
SM_CXMIN:
begin
//DebugLn('Trace:TODO: [TGtkWidgetSet.GetSystemMetrics] --> SM_CXMIN ');
end;
SM_CYMIN:
begin
//DebugLn('Trace:TODO: [TGtkWidgetSet.GetSystemMetrics] --> SM_CYMIN ');
end;
SM_CXMINIMIZED:
begin
//DebugLn('Trace:TODO: [TGtkWidgetSet.GetSystemMetrics] --> SM_CXMINIMIZED ');
end;
SM_CYMINIMIZED:
begin
//DebugLn('Trace:TODO: [TGtkWidgetSet.GetSystemMetrics] --> SM_CYMINIMIZED ');
end;
SM_CXMINSPACING:
begin
//DebugLn('Trace:TODO: [TGtkWidgetSet.GetSystemMetrics] --> SM_CXMINSPACING ');
end;
SM_CYMINSPACING:
begin
//DebugLn('Trace:TODO: [TGtkWidgetSet.GetSystemMetrics] --> SM_CYMINSPACING ');
end;
SM_CXMINTRACK:
begin
//DebugLn('Trace:TODO: [TGtkWidgetSet.GetSystemMetrics] --> SM_CXMINTRACK ');
end;
SM_CYMINTRACK:
begin
//DebugLn('Trace:TODO: [TGtkWidgetSet.GetSystemMetrics] --> SM_CYMINTRACK ');
end;
SM_CXFULLSCREEN,
SM_CXSCREEN:
begin
{ Partial fix for multi monitor systems - force use of first one }
{$ifdef UseXinerama}
if GetFirstScreen then
result := FirstScreen.x
else
{$endif}
result := gdk_Screen_Width;
end;
SM_CXVIRTUALSCREEN:
begin
Result := gdk_Screen_Width;
end;
SM_CYFULLSCREEN,
SM_CYSCREEN:
begin
{$ifdef UseXinerama}
if GetFirstScreen then
result := FirstScreen.y
else
{$endif}
result := gdk_Screen_Height;
end;
SM_CYVIRTUALSCREEN:
begin
result := gdk_Screen_Height;
end;
SM_CXSIZE:
begin
//DebugLn('Trace:TODO: [TGtkWidgetSet.GetSystemMetrics] --> SM_CXSIZE ');
end;
SM_CYSIZE:
begin
//DebugLn('Trace:TODO: [TGtkWidgetSet.GetSystemMetrics] --> SM_CYSIZE ');
end;
SM_CXSIZEFRAME,
SM_CYSIZEFRAME:
begin
Result := 4;
end;
SM_CXSMICON,
SM_CYSMICON:
Result := 16;
SM_CXSMSIZE:
begin
//DebugLn('Trace:TODO: [TGtkWidgetSet.GetSystemMetrics] --> SM_CXSMSIZE ');
end;
SM_CYSMSIZE:
begin
//DebugLn('Trace:TODO: [TGtkWidgetSet.GetSystemMetrics] --> SM_CYSMSIZE ');
end;
SM_CXVSCROLL:
begin
P := GetStyleWidget(lgsVerticalScrollbar);
if P <> nil then
Result := GTK_Widget(P)^.requisition.Width;
end;
SM_CYVSCROLL:
begin
P := GetStyleWidget(lgsHorizontalScrollbar);
if P <> nil then
Result := GTK_Widget(P)^.requisition.Height;
end;
SM_CYCAPTION:
begin
//DebugLn('Trace:TODO: [TGtkWidgetSet.GetSystemMetrics] --> SM_CYCAPTION ');
end;
SM_CYKANJIWINDOW:
begin
//DebugLn('Trace:TODO: [TGtkWidgetSet.GetSystemMetrics] --> SM_CYKANJIWINDOW ');
end;
SM_CYMENU:
begin
//DebugLn('Trace:TODO: [TGtkWidgetSet.GetSystemMetrics] --> SM_CYMENU ');
end;
SM_CYSMCAPTION:
begin
//DebugLn('Trace:TODO: [TGtkWidgetSet.GetSystemMetrics] --> SM_CYSMCAPTION ');
end;
SM_DBCSENABLED:
begin
//DebugLn('Trace:TODO: [TGtkWidgetSet.GetSystemMetrics] --> SM_DBCSENABLED ');
end;
SM_DEBUG:
begin
//DebugLn('Trace:TODO: [TGtkWidgetSet.GetSystemMetrics] --> SM_DEBUG ');
end;
SM_MENUDROPALIGNMENT:
begin
//DebugLn('Trace:TODO: [TGtkWidgetSet.GetSystemMetrics] --> SM_MENUDROPALIGNMENT');
end;
SM_MIDEASTENABLED:
begin
//DebugLn('Trace:TODO: [TGtkWidgetSet.GetSystemMetrics] --> SM_MIDEASTENABLED ');
end;
SM_MOUSEPRESENT:
begin
//DebugLn('Trace:TODO: [TGtkWidgetSet.GetSystemMetrics] --> SM_MOUSEPRESENT ');
end;
SM_MOUSEWHEELPRESENT:
begin
//DebugLn('Trace:TODO: [TGtkWidgetSet.GetSystemMetrics] --> SM_MOUSEWHEELPRESENT');
end;
SM_NETWORK:
begin
//DebugLn('Trace:TODO: [TGtkWidgetSet.GetSystemMetrics] --> SM_NETWORK ');
end;
SM_PENWINDOWS:
begin
//DebugLn('Trace:TODO: [TGtkWidgetSet.GetSystemMetrics] --> SM_PENWINDOWS ');
end;
SM_SECURE:
begin
//DebugLn('Trace:TODO: [TGtkWidgetSet.GetSystemMetrics] --> SM_SECURE ');
end;
SM_SHOWSOUNDS:
begin
//DebugLn('Trace:TODO: [TGtkWidgetSet.GetSystemMetrics] --> SM_SHOWSOUNDS ');
end;
SM_SLOWMACHINE:
begin
//DebugLn('Trace:TODO: [TGtkWidgetSet.GetSystemMetrics] --> SM_SLOWMACHINE ');
end;
SM_SWAPBUTTON:
begin
//DebugLn('Trace:TODO: [TGtkWidgetSet.GetSystemMetrics] --> SM_SWAPBUTTON ');
end;
SM_SWSCROLLBARSPACING:
begin
P := GetStyleWidget(lgsScrolledWindow);
if P <> nil then begin
{$IFDEF GTK2}
result := GTK_SCROLLED_WINDOW_CLASS(gtk_widget_get_class(P))^.scrollbar_spacing;
if result<0 then
gtk_widget_style_get(P, 'scrollbar-spacing', @result, nil);
{$ELSE}
result := PGtkScrolledWindowClass(PGtkTypeObject(P)^.klass)^.scrollbar_spacing;
if result<0 then
result := 3;
{$ENDIF}
end;
end;
end;
//DebugLn(Format('Trace:< [TGtkWidgetSet.GetSystemMetrics] %d --> 0x%x (%d)', [nIndex, Result, Result]));
end;
{------------------------------------------------------------------------------
Function: GetTextColor
Params: DC
Returns: TColorRef
Gets the Font Color currently assigned to the Device Context
------------------------------------------------------------------------------}
function TGtkWidgetSet.GetTextColor(DC: HDC) : TColorRef;
var
DevCtx: TGtkDeviceContext absolute DC;
begin
Result := 0;
if IsValidDC(DC) then
with TGtkDeviceContext(DC) do
begin
Result := CurrentTextColor.ColorRef;
end;
end;
{------------------------------------------------------------------------------
Function: GetTextExtentPoint
Params: none
Returns: Nothing
------------------------------------------------------------------------------}
function TGtkWidgetSet.GetTextExtentPoint(DC: HDC; Str: PChar; Count: Integer;
var Size: TSize): Boolean;
{$IfDef GTK2}
begin
DebugLn('TGtkWidgetSet.GetTextExtentPoint ToDo');
Result:=false;
end;
{$Else}
var
DevCtx: TGtkDeviceContext absolute DC;
lbearing, rbearing, width, ascent,descent: LongInt;
UseFont : PGDKFont;
IsDBCSFont: Boolean;
NewCount: Integer;
begin
Result := IsValidDC(DC);
if Result
then with TGtkDeviceContext(DC) do
begin
UseFont:=GetGtkFont(TGtkDeviceContext(DC));
descent:=0;
UpdateDCTextMetric(TGtkDeviceContext(DC));
IsDBCSFont:=TGtkDeviceContext(DC).DCTextMetric.IsDoubleByteChar;
if IsDBCSFont then begin
NewCount:=Count*2;
if FExtUTF8OutCacheSize<NewCount then begin
ReAllocMem(FExtUTF8OutCache,NewCount);
FExtUTF8OutCacheSize:=NewCount;
end;
NewCount:=UTF8ToDoubleByte(Str,Count,FExtUTF8OutCache)*2;
gdk_text_extents(UseFont, FExtUTF8OutCache, NewCount,
@lbearing, @rBearing, @width, @ascent, @descent);
end else begin
gdk_text_extents(UseFont, Str, Count,
@lbearing, @rBearing, @width, @ascent, @descent);
end;
Size.cX := Width;
// I THINK this is accurate...
Size.cY :={$IFDEF Win32}
GDK_String_Height(UseFont, Str)
{$ELSE}
ascent+descent;
{$ENDIF}
//debugln('TGtkWidgetSet.GetTextExtentPoint END Str="'+DbgStr(Str)+'" Size=',dbgs(Size.cX),'x',dbgs(Size.cY),' ascent=',dbgs(ascent),' descent=',dbgs(descent),' tmDescent=',dbgs(TGtkDeviceContext(DC).DCTextMetric.TextMetric.tmDescent));
if DevCtx.HasTransf then
begin
DevCtx.InvTransfExtent(Size.cx, Size.cy);
Size.cx := Abs(Size.cx);
Size.cy := Abs(Size.cy);
end;
end;
//DebugLn('trace:< [TGtkWidgetSet.GetTextExtentPoint]');
end;
{$EndIf}
{------------------------------------------------------------------------------
Function: GetTextMetrics
Params: none
Returns: Nothing
------------------------------------------------------------------------------}
function TGtkWidgetSet.GetTextMetrics(DC: HDC; var TM: TTextMetric): Boolean;
var
DevCtx: TGtkDeviceContext absolute DC;
begin
//DebugLn(Format('Trace:> TODO FINISH[TGtkWidgetSet.GetTextMetrics] DC: 0x%x', [DC]));
Result := IsValidDC(DC);
if Result then
begin
UpdateDCTextMetric(DevCtx);
TM := DevCtx.DCTextMetric.TextMetric;
end;
//DebugLn(Format('Trace:< TODO FINISH[TGtkWidgetSet.GetTextMetrics] DC: 0x%x', [DC]));
end;
function TGtkWidgetSet.GetViewPortExtEx(DC: HDC; Size: PSize): Integer;
var
DevCtx: TGtkDeviceContext absolute DC;
begin
if IsValidDC(DC) and (Size <> nil) then
begin
Size^.cx := DevCtx.ViewPortExt.x;
Size^.cy := DevCtx.ViewPortExt.y;
Result := Integer(True);
end else
Result := Integer(False);
end;
function TGtkWidgetSet.GetViewPortOrgEx(DC: HDC; P: PPoint): Integer;
var
DevCtx: TGtkDeviceContext absolute DC;
begin
if IsValidDC(DC) and (P <> nil) then
begin
P^.x := DevCtx.ViewPortOrg.x;
P^.y := DevCtx.ViewPortOrg.y;
Result := Integer(True);
end else
Result := Integer(False);
end;
function TGtkWidgetSet.GetWindowExtEx(DC: HDC; Size: PSize): Integer;
var
DevCtx: TGtkDeviceContext absolute DC;
begin
if IsValidDC(DC) and (Size <> nil) then
begin
Size^.cx := DevCtx.WindowExt.x;
Size^.cy := DevCtx.WindowExt.y;
Result := Integer(True);
end else
Result := Integer(False);
end;
{------------------------------------------------------------------------------
Function: GetWindowLong
Params: none
Returns: Nothing
------------------------------------------------------------------------------}
function TGtkWidgetSet.GetWindowLong(Handle: HWND; int: Integer): PtrInt;
function GetObjectData(Name: PChar): PtrInt;
begin
Result := PtrInt(PtrUInt(gtk_object_get_data(pgtkobject(Handle),Name)));
end;
var
WidgetInfo: PWidgetInfo;
begin
//TODO:Started but not finished
//DebugLn(Format('Trace:> [TGtkWidgetSet.GETWINDOWLONG] HWND: 0x%x, int: 0x%x (%d)', [Handle, int, int]));
case int of
GWL_WNDPROC :
begin
WidgetInfo := GetWidgetInfo(Pointer(Handle));
if WidgetInfo <> nil then
Result := WidgetInfo^.WndProc
else
Result := 0;
end;
GWL_HINSTANCE :
begin
Result := GetObjectData('HINSTANCE');
end;
GWL_HWNDPARENT :
begin
Result := GetObjectData('HWNDPARENT');
end;
{ GWL_WNDPROC :
begin
Data := GetLCLObject(Pointer(Handle));
if Data is TControl
then Result := PtrInt(@(TControl(Data).WindowProc));
// TODO fix this, a method pointer (2 pointers) can not be casted to a longint
end;
}
{ GWL_HWNDPARENT :
begin
Data := GetLCLObject(Pointer(Handle));
if (Data is TWinControl)
then Result := PtrInt(TWincontrol(Data).Handle)
else Result := 0;
end;
}
GWL_STYLE :
begin
WidgetInfo := GetWidgetInfo(Pointer(Handle));
if WidgetInfo <> nil then
Result := WidgetInfo^.Style
else
Result := 0;
end;
GWL_EXSTYLE :
begin
WidgetInfo := GetWidgetInfo(Pointer(Handle));
if WidgetInfo <> nil then
Result := WidgetInfo^.ExStyle
else
Result := 0;
end;
GWL_USERDATA :
begin
Result := GetObjectData('Userdata');
end;
GWL_ID :
begin
Result := GetObjectData('ID');
end;
else Result := 0;
end; //case
//DebugLn(Format('Trace:< [TGtkWidgetSet.GETWINDOWLONG] HWND: 0x%x, int: 0x%x (%d) --> 0x%x (%d)', [Handle, int, int, Result, Result]));
end;
{------------------------------------------------------------------------------
Function: GetWindowOrgEx
Params: none
Returns: Nothing
Returns the current offset of the DC.
------------------------------------------------------------------------------}
function TGtkWidgetSet.GetWindowOrgEx(dc : hdc; P : PPoint): Integer;
var
DevCtx: TGtkDeviceContext absolute DC;
begin
if P = nil then Exit(0);
P^ := Point(0,0);
if not IsValidDC(DC) then exit(0);
P^ := DevCtx.Offset;
Result:=1;
end;
{------------------------------------------------------------------------------
Function: GetWindowRect
Params: none
Returns: 0
After the call, ARect will be the control area in screen coordinates.
That means, Left and Top will be the screen coordinate of the TopLeft pixel
of the Handle object and Right and Bottom will be the screen coordinate of
the BottomRight pixel.
------------------------------------------------------------------------------}
function TGtkWidgetSet.GetWindowRect(Handle: hwnd; var ARect: TRect): Integer;
var
Widget: PGTKWidget;
begin
//DebugLn('GetWindowRect');
Result := 0; //default
if Handle <> 0 then
begin
Widget := PGtkWidget(Handle);
ARect.TopLeft := GetWidgetOrigin(Widget);
ARect.BottomRight := Point(ARect.Left + Widget^.allocation.width,
ARect.Top + Widget^.allocation.height);
end;
end;
{------------------------------------------------------------------------------
Function: GetWindowRelativePosition
Params: Handle : hwnd;
Returns: true on success
Returns the Left, Top, relative to the client origin of its parent
------------------------------------------------------------------------------}
function TGtkWidgetSet.GetWindowRelativePosition(Handle : hwnd;
var Left, Top: integer): boolean;
var
aWidget: PGtkWidget;
begin
aWidget := PGtkWidget(Handle);
if GtkWidgetIsA(aWidget, GTK_TYPE_WIDGET) then
begin
Result := true;
GetWidgetRelativePosition(aWidget, Left, Top);
end else
Result := false;
end;
{------------------------------------------------------------------------------
Function: GetWindowSize
Params: Handle : hwnd;
Returns: true on success
Returns the current widget Width and Height
------------------------------------------------------------------------------}
function TGtkWidgetSet.GetWindowSize(Handle : hwnd;
var Width, Height: integer): boolean;
begin
if GtkWidgetIsA(PGtkWidget(Handle),GTK_TYPE_WIDGET) then begin
Result:=true;
Width:=Max(0,PGtkWidget(Handle)^.Allocation.Width);
Height:=Max(0,PGtkWidget(Handle)^.Allocation.Height);
//DebugLn(['TGtkWidgetSet.GetWindowSize ',DbgSName(GetLCLOwnerObject(Handle)),' Allocation=',Width,'x',Height]);
end else
Result:=false;
end;
{------------------------------------------------------------------------------
Function: GradientFill
Params: DC - DeviceContext to perform on
Vertices - array of Points W/Color & Alpha
NumVertices - Number of Vertices
Meshes - array of Triangle or Rectangle Meshes,
each mesh representing one Gradient Fill
NumMeshes - Number of Meshes
Mode - Gradient Type, either Triangle,
Vertical Rect, Horizontal Rect
Returns: true on success
Performs multiple Gradient Fills, either a Three way Triangle Gradient,
or a two way Rectangle Gradient, each Vertex point also supports optional
Alpha/Transparency for more advanced Gradients.
------------------------------------------------------------------------------}
function TGtkWidgetSet.GradientFill(DC: HDC; Vertices: PTriVertex;
NumVertices : Longint; Meshes: Pointer; NumMeshes : Longint; Mode : Longint
): Boolean;
var
DevCtx: TGtkDeviceContext absolute DC;
function DoFillTriangle : Boolean;
begin
Result := (Mode and GRADIENT_FILL_TRIANGLE) = GRADIENT_FILL_TRIANGLE;
end;
function DoFillVRect : Boolean;
begin
Result := (Mode and GRADIENT_FILL_RECT_V) = GRADIENT_FILL_RECT_V;
end;
procedure GetGradientBrush(BeginColor, EndColor : TColorRef; Position,
TotalSteps : Longint; var GradientBrush : hBrush);
var
R1, G1, B1 : Integer;
R2, G2, B2 : Integer;
NewBrush : TLogBrush;
begin
GetRGBIntValues(BeginColor,R1,G1,B1);
GetRGBIntValues(EndColor,R2,G2,B2);
R1 := R1 + (Position*(R2 - R1) div TotalSteps);
G1 := G1 + (Position*(G2 - G1) div TotalSteps);
B1 := B1 + (Position*(B2 - B1) div TotalSteps);
with NewBrush do
begin
lbStyle := BS_SOLID;
lbColor := RGB(R1,G1,B1);
end;
If GradientBrush <> 0 then
LCLIntf.DeleteObject(GradientBrush);
GradientBrush := LCLIntf.CreateBrushIndirect(NewBrush);
end;
function FillTriMesh(Mesh : tagGradientTriangle) : Boolean;
{var
V1, V2, V3 : tagTRIVERTEX;
C1, C2, C3 : TColorRef;
begin
With Mesh do begin
Result := (Vertex1 < NumVertices) and (Vertex2 >= 0) and
(Vertex2 < NumVertices) and (Vertex2 >= 0) and
(Vertex3 < NumVertices) and (Vertex3 >= 0);
If (Vertex1 = Vertex2) or (Vertex1 = Vertex3) or
(Vertex2 = Vertex3) or not Result
then
exit;
V1 := Vertices[Vertex1];
V2 := Vertices[Vertex2];
V3 := Vertices[Vertex3];
//Check to make sure they are in reasonable positions..
//then what??
end;}
begin
Result := False;
end;
function FillRectMesh(Mesh : tagGradientRect) : Boolean;
var
TL, BR: tagTRIVERTEX;
StartColor, EndColor: TColorRef;
I, Swap: Longint;
SwapColors: Boolean;
UseBrush: hBrush;
Steps, MaxSteps: Int64;
begin
with Mesh do
begin
Result := (UpperLeft < NumVertices) and (UpperLeft >= 0) and
(LowerRight < NumVertices) and (LowerRight >= 0);
if (LowerRight = UpperLeft) or not Result then
exit;
TL := Vertices[UpperLeft];
BR := Vertices[LowerRight];
SwapColors := (BR.Y < TL.Y) and (BR.X < TL.X);
if BR.X < TL.X then
begin
Swap := BR.X;
BR.X := TL.X;
TL.X := Swap;
end;
if BR.Y < TL.Y then
begin
Swap := BR.Y;
BR.Y := TL.Y;
TL.Y := Swap;
end;
StartColor := RGB(TL.Red shr 8, TL.Green shr 8, TL.Blue shr 8);
EndColor := RGB(BR.Red shr 8, BR.Green shr 8, BR.Blue shr 8);
if SwapColors then
begin
Swap := StartColor;
StartColor := EndColor;
EndColor := Swap;
end;
UseBrush := 0;
MaxSteps := GetDeviceCaps(DC, BITSPIXEL);
if MaxSteps >= 32 then
MaxSteps := $FFFFFFFF
else
if MaxSteps >= 4 then
MaxSteps := 1 shl MaxSteps
else
MaxSteps := 256;
if DoFillVRect then
begin
Steps := Min(BR.Y - TL.Y, MaxSteps);
for I := 0 to Steps - 1 do
begin
GetGradientBrush(StartColor, EndColor, I, Steps, UseBrush);
LCLIntf.FillRect(DC, Rect(TL.X, TL.Y + I, BR.X, TL.Y + I + 1),
UseBrush)
end
end
else begin
Steps := Min(BR.X - TL.X, MaxSteps);
for I := 0 to Steps - 1 do
begin
GetGradientBrush(StartColor, EndColor, I, Steps, UseBrush);
LCLIntf.FillRect(DC, Rect(TL.X + I, TL.Y, TL.X + I + 1, BR.Y),
UseBrush);
end;
end;
If UseBrush <> 0 then
LCLIntf.DeleteObject(UseBrush);
end;
end;
const
MeshSize: Array[Boolean] of Integer = (
SizeOf(tagGradientRect), SizeOf(tagGradientTriangle));
var
I : Integer;
begin
//Currently Alpha blending is ignored... Ideas anyone?
Result := (Meshes <> nil) and (NumMeshes >= 1) and (NumVertices >= 2)
and (Vertices <> nil);
if Result and DoFillTriangle then
Result := NumVertices >= 3;
if Result then
begin
Result := False;
//Sanity Checks For Vertices Size vs. Count
if MemSizeLessThan(MemSize(Vertices), PtrInt(SizeOf(tagTRIVERTEX)*NumVertices)) then
exit;
//Sanity Checks For Meshes Size vs. Count
if MemSizeLessThan(MemSize(Meshes), PtrInt(MeshSize[DoFillTriangle]*NumMeshes)) then
exit;
for I := 0 to NumMeshes - 1 do
begin
if DoFillTriangle then
begin
If not FillTriMesh(PGradientTriangle(Meshes)[I]) then
exit;
end
else
begin
if not FillRectMesh(PGradientRect(Meshes)[I]) then
exit;
end;
end;
Result := True;
end;
end;
{------------------------------------------------------------------------------
Function: HideCaret
Params: none
Returns: Nothing
------------------------------------------------------------------------------}
function TGtkWidgetSet.HideCaret(hWnd: HWND): Boolean;
var
GTKObject: PGTKObject;
WasVisible: boolean;
begin
//DebugLn('[TGtkWidgetSet.HideCaret] A');
//DebugLn(Format('Trace: [TGtkWidgetSet.HideCaret] HWND: 0x%x', [hWnd]));
//TODO: [TGtkWidgetSet.HideCaret] Finish (in gtkwinapi.inc)
GTKObject := PGTKObject(HWND);
Result := GTKObject <> nil;
if Result
then begin
if gtk_type_is_a(gtk_object_type(GTKObject), GTKAPIWidget_GetType)
then begin
GTKAPIWidget_HideCaret(PGTKAPIWidget(GTKObject),WasVisible);
end
// else if // TODO: other widgettypes
else begin
Result := False;
end;
end
else DebugLn('WARNING: [TGtkWidgetSet.HideCaret] Got null HWND');
end;
{------------------------------------------------------------------------------
Function: IntersectClipRect
Params: dc: hdc; Left, Top, Right, Bottom: Integer
Returns: Integer
Shrinks the clipping region in the device context dc to a region of all
intersecting points between the boundary defined by Left, Top, Right,
Bottom , and the Current clipping region.
The result can be one of the following constants
Error
NullRegion
SimpleRegion
ComplexRegion
------------------------------------------------------------------------------}
function TGtkWidgetSet.IntersectClipRect(dc: hdc;
Left, Top, Right, Bottom: Integer): Integer;
var
DevCtx: TGtkDeviceContext absolute DC;
begin
if not IsValidDC(DC) then Exit;
if DevCtx.HasTransf then
begin
DevCtx.TransfRect(Left, Top, Right, Bottom);
DevCtx.TransfNormalize(Left, Right);
DevCtx.TransfNormalize(Top, Bottom);
end;
Result := inherited IntersectClipRect(DC, Left, Top, Right, Bottom);
end;
{------------------------------------------------------------------------------
Function: InvalidateRect
Params: aHandle:
Rect:
bErase:
Returns:
------------------------------------------------------------------------------}
function TGtkWidgetSet.InvalidateRect(aHandle : HWND; Rect : pRect;
bErase : Boolean) : Boolean;
var
gdkRect : TGDKRectangle;
Widget, PaintWidget: PGtkWidget;
LCLObject: TObject;
r: TRect;
List: PGList;
i: Integer;
Pt: TPoint;
Adjustment: PGtkAdjustment;
Scrolled: PGtkScrolledWindow;
begin
// DebugLn(format('Rect = %d,%d,%d,%d',[rect^.left,rect^.top,rect^.Right,rect^.Bottom]));
Widget:=PGtkWidget(aHandle);
LCLObject:=GetLCLObject(Widget);
if (LCLObject<>nil) then begin
if (LCLObject=CurrentSentPaintMessageTarget) then begin
DebugLn('NOTE: TGtkWidgetSet.InvalidateRect during paint message: ',
LCLObject.ClassName);
//DumpStack;
//RaiseGDBException('Double paint');
end;
{$IFDEF VerboseDsgnPaintMsg}
if (LCLObject is TComponent)
and (csDesigning in TComponent(LCLObject).ComponentState) then begin
write('TGtkWidgetSet.InvalidateRect A ');
write(TComponent(LCLObject).Name,':');
write(LCLObject.ClassName);
with Rect^ do
write(' Rect=',Left,',',Top,',',Right,',',Bottom);
DebugLn(' Erase=',bErase);
end;
{$ENDIF}
end;
Result := True;
PaintWidget:=GetFixedWidget(Widget);
if PaintWidget=nil then PaintWidget:=Widget;
if Rect = nil then begin
Rect := @r;
Rect^.Left := 0;//PaintWidget^.Allocation.X;
Rect^.Top := 0;//PaintWidget^.Allocation.Y;
Rect^.Right := PaintWidget^.Allocation.Width;
Rect^.Bottom := PaintWidget^.Allocation.Height;
end
// ignore the request if the rectangle is invalid
else if (Rect^.Left >= Rect^.Right) or (Rect^.Top >= Rect^.Bottom) then
Exit(True);
gdkRect.X := Rect^.Left;
gdkRect.Y := Rect^.Top;
gdkRect.Width := (Rect^.Right - Rect^.Left);
gdkRect.Height := (Rect^.Bottom - Rect^.Top);
if LCLObject is TScrollingWinControl then
begin
List := gtk_container_children(PGtkContainer(Widget));
if (g_list_length(List) > 0) and
GTK_IS_SCROLLED_WINDOW(g_list_nth_data(List, 0)) then
begin
Scrolled := PGtkScrolledWindow(g_list_nth_data(List, 0));
Pt := Point(0, 0);
Adjustment := gtk_scrolled_window_get_vadjustment(Scrolled);
if Adjustment <> nil then
Pt.Y := Round(Adjustment^.value);
Adjustment := gtk_scrolled_window_get_hadjustment(Scrolled);
if Adjustment <> nil then
Pt.X := Round(Adjustment^.value);
dec(gdkRect.X, Pt.X);
dec(gdkRect.Y, Pt.Y);
end;
g_list_free(List);
end;
if bErase then
gtk_widget_queue_clear_area(PaintWidget,
gdkRect.X,gdkRect.Y,gdkRect.Width,gdkRect.Height);
gtk_widget_queue_draw_area(PaintWidget,
gdkRect.X,gdkRect.Y,gdkRect.Width,gdkRect.Height);
{$IfNDef GTK1}
//DebugLn(['TGtkWidgetSet.InvalidateRect ',GetWidgetDebugReport(Widget),' IsAPI=',GtkWidgetIsA(PGTKWidget(Widget),GTKAPIWidget_GetType)]);
if GtkWidgetIsA(PGTKWidget(Widget),GTKAPIWidget_GetType) then
GTKAPIWidget_InvalidateCaret(PGTKAPIWidget(Widget));
{$EndIf}
end;
function TGTKWidgetSet.IsIconic(handle: HWND): boolean;
var
GtkWindow: PGtkWindow absolute handle;
begin
Result := False;
if GtkWindow = nil then
Exit;
{$ifdef gtk1}
Result := GDK_WINDOW_GET_MINIMIZED(PGdkWindowPrivate(PgtkWidget(GtkWindow)^.Window));
{$else}
Result := (PGtkWidget(GtkWindow)^.Window<>nil)
and (gdk_window_get_state(PGtkWidget(GtkWindow)^.Window)
and GDK_WINDOW_STATE_ICONIFIED <> 0);
{$endif}
end;
function TGTKWidgetSet.IsWindow(handle: HWND): boolean;
begin
if Handle = 0 then
Exit(False);
Result := GtkWidgetIsA(PGtkWidget(Handle), GTK_TYPE_WIDGET);
end;
{------------------------------------------------------------------------------
function TGtkWidgetSet.IsWindowEnabled(handle: HWND): boolean;
------------------------------------------------------------------------------}
function TGtkWidgetSet.IsWindowEnabled(handle: HWND): boolean;
var
LCLObject: TObject;
Widget: PGtkWidget;
AForm: TCustomForm;
//i: Integer;
begin
Widget:=PGtkWidget(handle);
Result:=(Widget<>nil) and GTK_WIDGET_SENSITIVE(Widget)
and GTK_WIDGET_PARENT_SENSITIVE(Widget);
LCLObject:=GetLCLObject(PGtkWidget(Handle));
//debugln('TGtkWidgetSet.IsWindowEnabled A ',DbgSName(LCLObject),' Result=',dbgs(Result),
// ' SENSITIVE=',dbgs(GTK_WIDGET_SENSITIVE(Widget)),
// ' PARENT_SENSITIVE=',dbgs(GTK_WIDGET_PARENT_SENSITIVE(Widget)),
// ' TOPLEVEL=',dbgs(GTK_WIDGET_TOPLEVEL(Widget)),
// '');
if Result and GtkWidgetIsA(Widget,GTK_TYPE_WINDOW) then begin
LCLObject:=GetLCLObject(Widget);
if (LCLObject is TCustomForm) then begin
AForm:=TCustomForm(LCLObject);
if not Screen.CustomFormBelongsToActiveGroup(AForm) then
Result:=false;
//debugln('TGtkWidgetSet.IsWindowEnabled B ',dbgs(Screen.CustomFormBelongsToActiveGroup(AForm)));
//for i:=0 to Screen.CustomFormCount-1 do begin
// debugln(' ',dbgs(i),' ',DbgSName(Screen.CustomFormsZOrdered[i]));
//end;
end;
end;
end;
{------------------------------------------------------------------------------
function TGtkWidgetSet.IsWindowVisible(handle: HWND): boolean;
------------------------------------------------------------------------------}
function TGtkWidgetSet.IsWindowVisible(handle: HWND): boolean;
begin
Result:=(handle<>0) and GTK_WIDGET_VISIBLE(PGtkWidget(handle));
end;
function TGTKWidgetSet.IsZoomed(handle: HWND): boolean;
var
GtkWindow: PGtkWindow absolute handle;
begin
Result := False;
if GtkWindow = nil then
Exit;
{$ifdef gtk1}
Result := GDK_WINDOW_GET_MAXIMIZED(PGdkWindowPrivate(PgtkWidget(GtkWindow)^.Window));
{$else}
Result := gdk_window_get_state(PGtkWidget(GtkWindow)^.Window) and GDK_WINDOW_STATE_MAXIMIZED <> 0;
{$endif}
end;
{------------------------------------------------------------------------------
Function: LineTo
Params: none
Returns: Nothing
------------------------------------------------------------------------------}
function TGtkWidgetSet.LineTo(DC: HDC; X, Y: Integer): Boolean;
var
DevCtx: TGtkDeviceContext absolute DC;
DCOrigin: TPoint;
FromX: Integer;
FromY: Integer;
ToX: Integer;
ToY: Integer;
begin
//DebugLn(Format('trace:> [TGtkWidgetSet.LineTo] DC:0x%x, X:%d, Y:%d', [DC, X, Y]));
if not IsValidDC(DC) then Exit(False);
DevCtx.SelectPenProps;
if not (dcfPenSelected in DevCtx.Flags) then Exit(False);
if DevCtx.IsNullPen then Exit(True);
if DevCtx.HasTransf then
DevCtx.TransfPoint(X, Y);
DCOrigin := DevCtx.Offset;
FromX:=DevCtx.PenPos.X+DCOrigin.X;
FromY:=DevCtx.PenPos.Y+DCOrigin.Y;
ToX:=X+DCOrigin.X;
ToY:=Y+DCOrigin.Y;
{$IFDEF DebugGDK}BeginGDKErrorTrap;{$ENDIF}
gdk_draw_line(DevCtx.Drawable, DevCtx.GC, FromX, FromY, ToX, ToY);
{$IFDEF DebugGDK}EndGDKErrorTrap;{$ENDIF}
DevCtx.PenPos:= Point(X, Y);
Result := True;
//DebugLn(Format('trace:< [TGtkWidgetSet.LineTo] DC:0x%x, X:%d, Y:%d', [DC, X, Y]));
end;
function TGTKWidgetSet.LPtoDP(DC: HDC; var Points; Count: Integer): BOOL;
var
DevCtx: TGtkDeviceContext absolute DC;
P: PPoint;
begin
Result := False;
if not IsValidDC(DC) then Exit(False);
if not DevCtx.HasTransf then Exit(True);
P := @Points;
while Count > 0 do
begin
Dec(Count);
DevCtx.TransfPoint(P^.X, P^.Y);
Inc(P);
end;
Result := True;
end;
{------------------------------------------------------------------------------
Function: MessageBox
Params: hWnd: The handle of parent window
Returns: 0 if not successful (out of memory), otherwise one of the defined value :
IDABORT, IDCANCEL, IDIGNORE, IDNO, IDOK, IDRETRY, IDYES
The MessageBox function displays a modal dialog, with text and caption defined,
and includes buttons.
------------------------------------------------------------------------------}
function MessageButtonClicked(Widget : PGtkWidget; data: gPointer) : GBoolean; cdecl;
begin
//DebugLn('[MessageButtonClicked] ',dbgs(data),' ',dbgs(gtk_object_get_data(PGtkObject(Widget), 'modal_result')));
if PInteger(data)^ = 0 then
PInteger(data)^:=PtrUInt(gtk_object_get_data(PGtkObject(Widget), 'modal_result'));
Result:=false;
end;
function MessageBoxClosed(Widget : PGtkWidget; Event : PGdkEvent;
data: gPointer) : GBoolean; cdecl;
var ModalResult : PtrUInt;
begin
{ We were requested by window manager to close }
if PInteger(data)^ = 0 then begin
ModalResult:= PtrUInt(gtk_object_get_data(PGtkObject(Widget), 'modal_result'));
{ Don't allow to close if we don't have a default return value }
Result:= (ModalResult = 0);
if not Result then PInteger(data)^:= ModalResult
else DebugLn('Do not close !!!');
end else Result:= false;
end;
function TGtkWidgetSet.MessageBox(hWnd: HWND; lpText, lpCaption: PChar;
uType : Cardinal): integer;
var Dialog, ALabel : PGtkWidget;
ButtonCount, DefButton, ADialogResult : Integer;
DialogType : Cardinal;
procedure CreateButton(const ALabel : PChar; const RetValue : integer);
var AButton : PGtkWidget;
begin
AButton:= gtk_button_new_with_label(ALabel);
Inc(ButtonCount);
if ButtonCount = DefButton then begin
gtk_window_set_focus(PGtkWindow(Dialog), AButton);
end;
{ If there is the Cancel button, allow the dialog to close }
if RetValue = IDCANCEL then begin
gtk_object_set_data(PGtkObject(Dialog), 'modal_result', Pointer(IDCANCEL));
end;
gtk_object_set_data(PGtkObject(AButton), 'modal_result',
Pointer(PtrInt(RetValue)));
g_signal_connect(PGtkObject(AButton), 'clicked',
TGtkSignalFunc(@MessageButtonClicked), @ADialogResult);
gtk_container_add (PGtkContainer(PGtkDialog(Dialog)^.action_area), AButton);
end;
begin
ButtonCount:= 0;
{ Determine which is the default button }
DefButton:= ((uType and $00000300) shr 8) + 1;
//DebugLn('Trace:Default button is ' + IntToStr(DefButton));
ADialogResult:= 0;
Dialog:= gtk_dialog_new;
{$IFDEF DebugLCLComponents}
DebugGtkWidgets.MarkCreated(Dialog,'TGtkWidgetSet.MessageBox');
{$ENDIF}
g_signal_connect(PGtkObject(Dialog), 'delete-event', TGtkSignalFunc(@MessageBoxClosed), @ADialogResult);
gtk_window_set_default_size(PGtkWindow(Dialog), 100, 100);
ALabel:= gtk_label_new(lpText);
gtk_container_add (PGtkContainer(PGtkDialog(Dialog)^.vbox), ALabel);
DialogType:= (uType and $0000000F);
if DialogType = MB_OKCANCEL
then begin
CreateButton(PChar(rsMbOK), IDOK);
CreateButton(PChar(rsMbCancel), IDCANCEL);
end
else begin
if DialogType = MB_ABORTRETRYIGNORE
then begin
CreateButton(PChar(rsMbAbort), IDABORT);
CreateButton(PChar(rsMbRetry), IDRETRY);
CreateButton(PChar(rsMbIgnore), IDIGNORE);
end
else begin
if DialogType = MB_YESNOCANCEL
then begin
CreateButton(PChar(rsMbYes), IDYES);
CreateButton(PChar(rsMbNo), IDNO);
CreateButton(PChar(rsMbCancel), IDCANCEL);
end
else begin
if DialogType = MB_YESNO
then begin
CreateButton(PChar(rsMbYes), IDYES);
CreateButton(PChar(rsMbNo), IDNO);
end
else begin
if DialogType = MB_RETRYCANCEL
then begin
CreateButton(PChar(rsMbRetry), IDRETRY);
CreateButton(PChar(rsMbCancel), IDCANCEL);
end
else begin
{ We have no buttons to show. Create the default of OK button }
CreateButton(PChar(rsMbOK), IDOK);
end;
end;
end;
end;
end;
gtk_window_set_title(PGtkWindow(Dialog), lpCaption);
gtk_window_set_position(PGtkWindow(Dialog), GTK_WIN_POS_CENTER);
gtk_window_set_modal(PGtkWindow(Dialog), true);
gtk_widget_show_all(Dialog);
while ADialogResult = 0 do begin
Application.HandleMessage;
end;
DestroyConnectedWidget(Dialog,true);
Result:= ADialogResult;
end;
{------------------------------------------------------------------------------
Function: MoveToEx
Params: none
Returns: Nothing
------------------------------------------------------------------------------}
function TGtkWidgetSet.MoveToEx(DC: HDC; X, Y: Integer;
OldPoint: PPoint): Boolean;
var
DevCtx: TGtkDeviceContext absolute DC;
begin
//DebugLn(Format('trace:> [TGtkWidgetSet.MoveToEx] DC:0x%x, X:%d, Y:%d', [DC, X, Y]));
Result := IsValidDC(DC);
if Result
then with TGtkDeviceContext(DC) do
begin
if OldPoint <> nil then OldPoint^ := PenPos;
if DevCtx.HasTransf then
DevCtx.TransfPoint(X, Y);
PenPos := Point(X, Y);
end;
//DebugLn(Format('trace:< [TGtkWidgetSet.MoveToEx] DC:0x%x, X:%d, Y:%d', [DC, X, Y]));
end;
{------------------------------------------------------------------------------
function MoveWindowOrgEx(DC: HDC; dX, dY: Integer): Boolean; override;
Move the origin of all operations of a DeviceContext.
For example:
Moving the Origin to 10,20 and drawing a point to 50,50, results in
drawing a point to 60,70.
------------------------------------------------------------------------------}
function TGtkWidgetSet.MoveWindowOrgEx(DC: HDC; dX, dY: Integer): Boolean;
var
DevCtx: TGtkDeviceContext absolute DC;
NewOrigin: TPoint;
begin
Result:=IsValidDC(DC);
if Result then
with TGtkDeviceContext(DC) do begin
//DebugLn(['[TGtkWidgetSet.MoveWindowOrgEx] B DC=',DbgS(DC),
// ' Old=',Origin.X,',',Origin.Y,' d=',dX,',',dY,' ']);
NewOrigin:=Origin;
inc(NewOrigin.X,dX);
inc(NewOrigin.Y,dY);
Origin:=NewOrigin;
end;
end;
{------------------------------------------------------------------------------
Method: PaintRgn
Params: DC: HDC; RGN: HRGN
Returns: if the function succeeds
Paints the specified region by using the brush currently selected into the
device context.
------------------------------------------------------------------------------}
function TGtkWidgetSet.PaintRgn(DC: HDC; RGN: HRGN): Boolean;
var
DevCtx: TGtkDeviceContext absolute DC;
CurGdiBrush: PGdiObject;
CurHBrush: HBRUSH absolute CurGdiBrush;
begin
CurGdiBrush := DevCtx.CurrentBrush;
Result := IsValidDC(DC) and IsValidGDIObject(RGN) and IsValidGDIObject(CurHBrush);
if Result then
Result := FillRgn(DC, RGN, CurHBrush);
end;
{------------------------------------------------------------------------------
Function: PeekMessage
Params: lpMsg - Where it should put the message
Handle - Handle of the window (thread)
wMsgFilterMin- Lowest MSG to grab
wMsgFilterMax- Highest MSG to grab
wRemoveMsg - Should message be pulled out of the queue
Returns: Boolean if an event was there
------------------------------------------------------------------------------}
function TGtkWidgetSet.PeekMessage(var lpMsg: TMsg; Handle : HWND;
wMsgFilterMin, wMsgFilterMax, wRemoveMsg: UINT): Boolean;
var
vlItem : TGtkMessageQueueItem;
begin
//TODO Filtering
DebugLn('Peek !!!' );
fMessageQueue.Lock;
try
vlItem := fMessageQueue.FirstMessageItem;
Result := vlItem <> nil;
if Result then begin
lpMsg := vlItem.Msg^;
if (wRemoveMsg and PM_REMOVE) = PM_REMOVE then
fMessageQueue.RemoveMessage(vlItem,FPMF_Internal,true);
end;
finally
fMessageQueue.UnLock;
end;
end;
{------------------------------------------------------------------------------
Method: PolyBezier
Params: DC, Points, NumPts, Filled, Continous
Returns: Boolean
Use Polybezier to draw cubic Bézier curves. The first curve is drawn from the
first point to the fourth point with the second and third points being the
control points. If the Continuous flag is TRUE then each subsequent curve
requires three more points, using the end-point of the previous Curve as its
starting point, the first and second points being used as its control points,
and the third point its end-point. If the continous flag is set to FALSE,
then each subsequent Curve requires 4 additional points, which are used
excatly as in the first curve. Any additonal points which do not add up to
a full bezier(4 for Continuous, 3 otherwise) are ingored. There must be at
least 4 points for an drawing to occur. If the Filled Flag is set to TRUE
then the resulting Poly-Bézier will be drawn as a Polygon.
------------------------------------------------------------------------------}
function TGtkWidgetSet.PolyBezier(DC: HDC; Points: PPoint; NumPts: Integer;
Filled, Continuous: Boolean): Boolean;
begin
Result := inherited PolyBezier(DC, Points, NumPts, Filled, Continuous);
end;
{------------------------------------------------------------------------------
Method: TGtkWidgetSet.Polygon
Params: DC: HDC; Points: ^TPoint; NumPts: integer; Winding: Boolean;
Returns: Nothing
Use Polygon to draw a closed, many-sided shape on the canvas, using the value
of Pen. After drawing the complete shape, Polygon fills the shape using the
value of Brush.
The Points parameter is an array of points that give the vertices of the
polygon.
Winding determines how the polygon is filled. When Winding is True, Polygon
fills the shape using the Winding fill algorithm. When Winding is False,
Polygon uses the even-odd (alternative) fill algorithm.
NumPts indicates the number of points to use.
The first point is always connected to the last point.
To draw a polygon on the canvas, without filling it, use the Polyline method,
specifying the first point a second time at the end.
}
function TGtkWidgetSet.Polygon(DC: HDC; Points: PPoint; NumPts: Integer;
Winding: Boolean): boolean;
var
DevCtx: TGtkDeviceContext absolute DC;
i: integer;
PointArray: PGDKPoint;
Tmp, RGN : hRGN;
ClipRect : TRect;
DCOrigin: TPoint;
OldNumPts: integer;
begin
if not IsValidDC(DC) then Exit(False);
if NumPts <= 0 then Exit(True);
DCOrigin := DevCtx.Offset;
OldNumPts := NumPts;
// create the PointsArray, which is a copy of Points moved by the DCOrigin
// only if needed
if (DevCtx.IsNullPen and (DevCtx.IsNullBrush or Winding)) then
PointArray := nil
else
begin
GetMem(PointArray, SizeOf(TGdkPoint) * (NumPts + 1)); // +1 for return line
for i := 0 to NumPts - 1 do
begin
if DevCtx.HasTransf then
Points[I] := DevCtx.TransfPointIndirect(Points[I]);
PointArray[i].x := Points[i].x + DCOrigin.X;
PointArray[i].y := Points[i].y + DCOrigin.Y;
end;
if (Points[NumPts-1].X <> Points[0].X) or
(Points[NumPts-1].Y <> Points[0].Y) then
begin
// add last point to return to first
PointArray[NumPts].x := PointArray[0].x;
PointArray[NumPts].y := PointArray[0].y;
Inc(NumPts);
end;
end;
// first draw interior in brush color
{$IFDEF DebugGDK}BeginGDKErrorTrap;{$ENDIF}
if not DevCtx.IsNullBrush then
begin
if Winding then
begin
// store old clipping
Tmp := CreateEmptyRegion;
GetClipRGN(DC, Tmp);
// apply new clipping
RGN := CreatePolygonRgn(Points, OldNumPts, LCLType.Winding);
ExtSelectClipRGN(DC, RGN, RGN_AND);
DeleteObject(RGN);
GetClipBox(DC, @ClipRect);
if DevCtx.HasTransf then
begin
ClipRect := DevCtx.InvTransfRectIndirect(ClipRect);
DevCtx.TransfNormalize(ClipRect.Left, ClipRect.Right);
DevCtx.TransfNormalize(ClipRect.Top, ClipRect.Bottom);
end;
// draw polygon area
DevCtx.FillRect(ClipRect, HBrush(PtrUInt(DevCtx.GetBrush)), False);
// restore old clipping
SelectClipRGN(DC, Tmp);
DeleteObject(Tmp);
end
else
begin
DevCtx.SelectBrushProps;
gdk_draw_polygon(DevCtx.Drawable, DevCtx.GC, 1, PointArray, NumPts);
end;
end;
// draw outline
if not DevCtx.IsNullPen
then begin
DevCtx.SelectPenProps;
gdk_draw_polygon(DevCtx.Drawable, DevCtx.GC, 0, PointArray, NumPts);
end;
{$IFDEF DebugGDKTraps}EndGDKErrorTrap;{$ENDIF}
if PointArray <> nil then FreeMem(PointArray);
Result := True;
end;
function TGtkWidgetSet.Polyline(DC: HDC; Points: PPoint; NumPts: Integer): boolean;
var
DevCtx: TGtkDeviceContext absolute DC;
i: integer;
PointArray: PGDKPoint;
DCOrigin: TPoint;
begin
if not IsValidDC(DC) then Exit(False);
if NumPts <= 0 then Exit(True);
if DevCtx.IsNullPen then Exit(True);
DCOrigin := DevCtx.Offset;
GetMem(PointArray, SizeOf(TGdkPoint)*NumPts);
for i:=0 to NumPts-1 do
begin
if DevCtx.HasTransf then
Points[I] := DevCtx.TransfPointIndirect(Points[I]);
PointArray[i].x:=Points[i].x+DCOrigin.X;
PointArray[i].y:=Points[i].y+DCOrigin.Y;
end;
// draw line
DevCtx.SelectPenProps;
Result := dcfPenSelected in DevCtx.Flags;
if Result and not DevCtx.IsNullPen
then begin
{$IFDEF DebugGDK}BeginGDKErrorTrap;{$ENDIF}
gdk_draw_lines(DevCtx.Drawable, DevCtx.GC, PointArray, NumPts);
{$IFDEF DebugGDKTraps}EndGDKErrorTrap;{$ENDIF}
end;
FreeMem(PointArray);
end;
{------------------------------------------------------------------------------
Function: PostMessage
Params: Handle:
Msg:
wParam:
lParam:
Returns: True if succesful
The PostMessage function places (posts) a message in the message queue and
then returns without waiting.
------------------------------------------------------------------------------}
function TGtkWidgetSet.PostMessage(Handle: HWND; Msg: Cardinal; wParam: WParam;
lParam: LParam): Boolean;
function ParentPaintMessageInQueue: boolean;
var
Target: TControl;
Parent: TWinControl;
ParentHandle: hWnd;
begin
Result:=false;
Target:=TControl(GetLCLObject(Pointer(Handle)));
if not (Target is TControl) then exit;
Parent:=Target.Parent;
if (Target is TControl) then begin
Parent:=Target.Parent;
while Parent<>nil do begin
ParentHandle:=Parent.Handle;
if fMessageQueue.FindPaintMessage(ParentHandle)<>nil then begin
Result:=true;
end;
Parent:=Parent.Parent;
end;
end;
end;
procedure CombinePaintMessages(NewMsg:PMsg);
// combine NewMsg and OldMsg paint message into NewMsg and free OldMsg
var
vlItem : TGtkMessageQueueItem;
NewData: TLMGtkPaintData;
OldData: TLMGtkPaintData;
OldMsg : PMsg;
begin
vlItem := fMessageQueue.FindPaintMessage(NewMsg^.Hwnd);
if vlItem = nil then exit;
OldMsg := vlItem.Msg;
if OldMsg = nil then exit;
if (NewMsg^.Message = LM_PAINT) or (OldMsg^.Message = LM_PAINT) then
begin
// LM_PAINT means: repaint all
// convert NewMsg into a LM_PAINT if not already done
if NewMsg^.Message <> LM_PAINT then
begin
FinalizePaintTagMsg(NewMsg);
NewMsg^.Message:=LM_PAINT;
end;
end
else
if (NewMsg^.Message <> LM_GTKPAINT) then
RaiseGDBException('CombinePaintMessages A unknown paint message')
else
if (OldMsg^.Message<>LM_GtkPAINT) then
RaiseGDBException('CombinePaintMessages B unknown paint message')
else
begin
// combine the two LM_GtkPAINT messages
NewData := TLMGtkPaintData(NewMsg^.WParam);
OldData := TLMGtkPaintData(OldMsg^.WParam);
NewData.RepaintAll := NewData.RepaintAll or OldData.RepaintAll;
if not NewData.RepaintAll then
begin
NewData.Rect.Left := Min(NewData.Rect.Left, OldData.Rect.Left);
NewData.Rect.Top := Min(NewData.Rect.Top, OldData.Rect.Top);
NewData.Rect.Right := Max(NewData.Rect.Right, OldData.Rect.Right);
NewData.Rect.Bottom := Max(NewData.Rect.Bottom, OldData.Rect.Bottom);
end;
end;
fMessageQueue.RemoveMessage(vlItem, FPMF_All, True);
end;
var
AMessage: PMsg;
begin
Result := True;
New(AMessage);
FillByte(AMessage^,SizeOf(TMsg),0);
AMessage^.HWnd := Handle; // this is normally the main gtk widget
AMessage^.Message := Msg;
AMessage^.WParam := WParam;
AMessage^.LParam := LParam;
fMessageQueue.Lock;
try
if (AMessage^.Message = LM_PAINT) or (AMessage^.Message = LM_GTKPAINT) then
begin
{ Obsolete, because InvalidateRectangle now works.
// paint messages are the most expensive messages in the LCL
// A paint message to a control will also repaint all child controls.
// -> check if there is already a paint message for one of its parents
// if yes, then skip this message
if ParentPaintMessageInQueue then begin
FinalizePaintTagMsg(AMessage^);
exit;
end;}
// delete old paint message to this widget,
// so that the widget repaints only once
CombinePaintMessages(AMessage);
end;
FMessageQueue.AddMessage(AMessage);
if GetCurrentThreadId <> MainThreadID then
begin
// awake gtk loop
// when the main thread is currently processing messages it will process
// fMessageQueue.
// But when the main thread is waiting for the next gtk message it will
// wait for the next external event before processing fMessageQueue.
// A g_idle_add can only be used if glib multithreading has been enabled
// ToDo: Find out what we loose when enabling multithreading
// or find another way to wake up the gtk loop
{$IFDEF EnabledGtkThreading}
gdk_flush();
g_main_context_wakeup(nil);
{$ELSE}
DebugLn(['TGtkWidgetSet.PostMessage ToDo: wake up gtk']);
{$ENDIF}
end;
finally
fMessageQueue.UnLock;
end;
end;
{------------------------------------------------------------------------------
Method: RadialArc
Params: DC, left, top, right, bottom, sx, sy, ex, ey
Returns: Nothing
Use RadialArc to draw an elliptically curved line with the current Pen. The
values sx,sy, and ex,ey represent the starting and ending radial-points
between which the Arc is drawn.
------------------------------------------------------------------------------}
function TGtkWidgetSet.RadialArc(DC: HDC; left, top, right, bottom,
sx, sy, ex, ey: Integer): Boolean;
begin
Result := inherited RadialArc(DC, left, top, right, bottom, sx, sy, ex, ey);
end;
{------------------------------------------------------------------------------
Method: RadialChord
Params: DC, x1, y1, x2, y2, sx, sy, ex, ey
Returns: Nothing
Use RadialChord to draw a filled Chord-shape on the canvas. The values sx,sy,
and ex,ey represent the starting and ending radial-points between which
the bounding-Arc is drawn.
------------------------------------------------------------------------------}
function TGtkWidgetSet.RadialChord(DC: HDC; x1, y1, x2, y2,
sx, sy, ex, ey: Integer): Boolean;
begin
Result := inherited RadialChord(DC, x1, y1, x2, y2, sx, sy, ex, ey);
end;
{------------------------------------------------------------------------------
Function: RealizePalette
Params: DC: HDC
Returns: Nothing
------------------------------------------------------------------------------}
function TGtkWidgetSet.RealizePalette(DC: HDC): Cardinal;
var
DevCtx: TGtkDeviceContext absolute DC;
begin
//DebugLn('Trace:FINISH: [TGtkWidgetSet.RealizePalette]');
Result := 0;
if IsValidDC(DC)
then with TGtkDeviceContext(DC) do
begin
end;
end;
{------------------------------------------------------------------------------
Function: Rectangle
Params: DC: HDC; X1, Y1, X2, Y2: Integer
Returns: Nothing
The Rectangle function draws a rectangle. The rectangle is outlined by using
the current pen and filled by using the current brush.
------------------------------------------------------------------------------}
function TGtkWidgetSet.Rectangle(DC: HDC; X1, Y1, X2, Y2: Integer): Boolean;
var
DevCtx: TGtkDeviceContext absolute DC;
Left, Top, Width, Height: Integer;
DCOrigin: TPoint;
Brush: PGdiObject;
begin
//DebugLn(Format('trace:> [TGtkWidgetSet.Rectangle] DC:0x%x, X1:%d, Y1:%d, X2:%d, Y2:%d', [DC, X1, Y1, X2, Y2]));
if not IsValidDC(DC) then Exit(False);
if DevCtx.HasTransf then
DevCtx.TransfRect(X1, Y1, X2, Y2);
CalculateLeftTopWidthHeight(X1, Y1, X2, Y2, Left, Top, Width, Height);
if (Width = 0) or (Height = 0) then Exit(True);
// X2, Y2 is not part of the rectangle
dec(Width);
dec(Height);
// first draw interior in brush color
DevCtx.SelectBrushProps;
DCOrigin := DevCtx.Offset;
{$IFDEF DebugGDK}BeginGDKErrorTrap;{$ENDIF}
if not DevCtx.IsNullBrush
then begin
Brush := DevCtx.GetBrush;
if (Brush^.GDIBrushFill = GDK_SOLID)
and (IsBackgroundColor(TColor(Brush^.GDIBrushColor.ColorRef)))
then
StyleFillRectangle(DevCtx.Drawable, DevCtx.GC, Brush^.GDIBrushColor.ColorRef,
Left+DCOrigin.X, Top+DCOrigin.Y, Width, Height)
else
gdk_draw_rectangle(DevCtx.Drawable, DevCtx.GC, 1,
Left+DCOrigin.X, Top+DCOrigin.Y, Width, Height);
end;
// Draw outline
DevCtx.SelectPenProps;
Result := dcfPenSelected in DevCtx.Flags;
if Result and not DevCtx.IsNullPen
then gdk_draw_rectangle(DevCtx.Drawable, DevCtx.GC, 0,
Left+DCOrigin.X, Top+DCOrigin.Y, Width, Height);
{$IFDEF DebugGDKTraps}EndGDKErrorTrap;{$ENDIF}
//DebugLn(Format('trace:< [TGtkWidgetSet.Rectangle] DC:0x%x, X1:%d, Y1:%d, X2:%d, Y2:%d', [DC, X1, Y1, X2, Y2]));
end;
{------------------------------------------------------------------------------
Function: RectInRegion
Params: RGN: HRGN; ARect: TRect
Returns: True if any part of the specified rectangle lies within the
boundaries of the region.
Determines whether any part of the specified rectangle is within the boundaries
of a region.
------------------------------------------------------------------------------}
function TGtkWidgetSet.RectInRegion(RGN: HRGN; ARect: TRect): Boolean;
var
AGdkRect: TGdkRectangle;
begin
//todo: sanity checks for valid handle etc.
AGdkRect := GdkRectFromRect(ARect);
Result := gdk_region_rect_in({%H-}PGdiObject(RGN)^.GDIRegionObject, @AGdkRect)
<> GDK_OVERLAP_RECTANGLE_OUT;
end;
{------------------------------------------------------------------------------
Function: RectVisible
Params: dc : hdc; ARect: TRect
Returns: True if ARect is not completely clipped away.
------------------------------------------------------------------------------}
function TGtkWidgetSet.RectVisible(DC: HDC; const ARect: TRect): Boolean;
begin
Result := inherited RectVisible(dc,ARect);
end;
{------------------------------------------------------------------------------
Function: RegroupMenuItem
Params: hndMenu: HMENU; GroupIndex: integer
Returns: Nothing
Move a menuitem into its group
This function is called by the LCL, after some menuitems were regrouped to
GroupIndex. The hndMenu is one of them.
Update all radio groups.
------------------------------------------------------------------------------}
function TGtkWidgetSet.RegroupMenuItem(hndMenu: HMENU;
GroupIndex: Integer): Boolean;
const
GROUPIDX_DATANAME = 'GroupIndex';
function GetGroup: PGSList;
{$IfDef GTK1}
var
Item: PGList;
Arg: TGTKArg;
begin
Result := nil;
Arg.theType := GTK_TYPE_OBJECT;
Arg.Name := 'parent';
gtk_widget_get(Pointer(hndMenu), @Arg);
if Arg.d.object_data = nil then Exit;
Item := gtk_container_children(PGTKContainer(Arg.d.object_data));
while Item <> nil do
begin
if (Item^.Data <> Pointer(hndMenu)) // exclude ourself
and gtk_is_radio_menu_item(Item^.Data)
and (PtrUInt(GroupIndex) = PtrUInt(gtk_object_get_data(Item^.Data, GROUPIDX_DATANAME)))
then begin
Result := gtk_radio_menu_item_group(PGtkRadioMenuItem(Item^.Data));
Exit;
end;
Item := Item^.Next;
end;
{$Else}
var
Item: PGList;
parent : PGTKWidget;
begin
Result := nil;
parent := gtk_widget_get_parent(Pointer(hndMenu));
if parent = nil then Exit;
Item := gtk_container_children(PGTKContainer(parent));
while Item <> nil do
begin
if (Item^.Data <> Pointer(hndMenu)) // exclude ourself
and gtk_is_radio_menu_item(Item^.Data)
and (GroupIndex = Integer(PtrUInt(gtk_object_get_data(Item^.Data, GROUPIDX_DATANAME))))
then begin
Result := gtk_radio_menu_item_get_group (PGtkRadioMenuItem(Item^.Data));
Exit;
end;
Item := Item^.Next;
end;
{$EndIf}
end;
var
RadioGroup: PGSList;
CurrentGroupIndex: Integer;
begin
Result := False;
if not gtk_is_radio_menu_item(Pointer(hndMenu))
then begin
DebugLn('WARNING: TGtkWidgetSet.RegroupMenuItem: handle is not a GTK_RADIO_MENU_ITEM');
Exit;
end;
CurrentGroupIndex := integer(PtrUInt(gtk_object_get_data(Pointer(hndMenu), GROUPIDX_DATANAME)));
// Update needed ?
if GroupIndex = CurrentGroupIndex
then begin
Result := True;
Exit;
end;
// Remove current group
gtk_radio_menu_item_set_group(PGtkRadioMenuItem(hndMenu), nil);
gtk_object_set_data(Pointer(hndMenu), GROUPIDX_DATANAME, nil);
// Check remove only
if GroupIndex = 0
then begin
Result := True;
Exit;
end;
// Try to find new group
RadioGroup := GetGroup;
// Set new group
gtk_object_set_data(Pointer(hndMenu), GROUPIDX_DATANAME, Pointer(PtrInt(GroupIndex)));
if RadioGroup = nil
then begin
// We're the only member, get a group
RadioGroup := gtk_radio_menu_item_group(PGtkRadioMenuItem(hndMenu))
end
else begin
gtk_radio_menu_item_set_group(PGtkRadioMenuItem(hndMenu), RadioGroup);
end;
//radiogroup^.data
//radiogroup^.next
// Refetch newgroup list
RadioGroup := gtk_radio_menu_item_group(PGtkRadioMenuItem(hndMenu));
// Update checks
UpdateRadioGroupChecks(RadioGroup);
Result := True;
end;
{------------------------------------------------------------------------------
Function: ReleaseCapture
Params: none
Returns: True if succesful
The ReleaseCapture function releases the mouse capture from a window
and restores normal mouse input processing.
------------------------------------------------------------------------------}
function TGtkWidgetSet.ReleaseCapture: Boolean;
begin
SetCapture(0);
Result := True;
end;
{------------------------------------------------------------------------------
Function: ReleaseDC
Params: none
Returns: Nothing
------------------------------------------------------------------------------}
function TGtkWidgetSet.ReleaseDC(hWnd: HWND; DC: HDC): Integer;
var
DevCtx: TGtkDeviceContext absolute DC;
aDC, pSavedDC: TGtkDeviceContext;
g: TGDIType;
CurGDIObject: PGDIObject;
begin
//DebugLn(['[TGtkWidgetSet.ReleaseDC] ',DC,' ',FDeviceContexts.Count]);
//DebugLn(Format('trace:> [TGtkWidgetSet.ReleaseDC] DC:0x%x', [DC]));
Result := 0;
if (DC <> 0)
then begin
if FDeviceContexts.Contains(Pointer(DC))
then begin
aDC := TGtkDeviceContext(DC);
// clear references to all GDI objects
for g:=Low(TGDIType) to high(TGDIType) do begin
{if aDC.GDIObjects[g]<>nil then
if FindDCWithGDIObject(aDC.GDIObjects[g])=nil then
RaiseGDBException('');}
aDC.GDIObjects[g]:=nil; // clear the reference, decrease DCCount
end;
// Release all saved device contexts (the owned GDI objects will be freed)
pSavedDC:=aDC.SavedContext;
if pSavedDC<>nil then begin
ReleaseDC(0,HDC(pSavedDC));
aDC.SavedContext:=nil;
end;
//DebugLn(['TGtkWidgetSet.ReleaseDC DC=',dbgs(TGtkDeviceContext(aDC)),' ClipRegion=',dbgs(aDC.ClipRegion)]);
// free all owned GDI objects
for g:=Low(TGDIType) to high(TGDIType) do begin
CurGDIObject:=aDC.OwnedGDIObjects[g];
if CurGDIObject<>nil then begin
if CurGDIObject^.Owner<>aDC then
RaiseGDBException('');
DeleteObject(HGDIOBJ(PtrUInt(CurGDIObject)));
if aDC.OwnedGDIObjects[g]<>nil then
RaiseGDBException('');
end;
end;
//DebugLn(['TGtkWidgetSet.ReleaseDC DC=',dbghex(PtrInt(DC)),' Font=',dbghex(PtrInt(aDC.CurrentFont))]);
{FreeGDIColor(aDC.CurrentTextColor);
FreeGDIColor(aDC.CurrentBackColor);}
try
{ On root window, we don't allocate a graphics context and so we do not free}
if aDC.HasGC then
begin
gdk_gc_unref(aDC.GC);
aDC.GC:=nil;
end;
except
on E:Exception do begin
// Nothing, just try to unref it
// (it segfaults if the window doesnt exist anymore :-)
DebugLn('TGtkWidgetSet.ReleaseDC: ',E.Message);
end;
end;
DisposeDC(aDC);
Result := 1;
end;
end;
//DebugLn(Format('trace:< [TGtkWidgetSet.ReleaseDC] FDeviceContexts DC:0x%x', [DC]));
end;
{------------------------------------------------------------------------------
Function: RemoveProp
Params: Handle: Handle of the object
Str: Name of the property to remove
Returns: The handle of the property (0=failure)
------------------------------------------------------------------------------}
function TGtkWidgetSet.RemoveProp(Handle: hwnd; Str: PChar): TLCLHandle;
begin
gtk_object_remove_data(pGTKObject(handle), Str);
Result := 1;
end;
{------------------------------------------------------------------------------
Function: RestoreDC
Params: none
Returns: Nothing
-------------------------------------------------------------------------------}
function TGtkWidgetSet.RestoreDC(DC: HDC; SavedDC: Integer): Boolean;
var
DevCtx: TGtkDeviceContext absolute DC;
SavedDevCtx: TGtkDeviceContext;
ClipRegionChanged: Boolean;
begin
//DebugLn(Format('Trace:> [TGtkWidgetSet.RestoreDC] DC:0x%x, SavedDC: %d', [DC, SavedDC]));
if not IsValidDC(DC) then Exit(False);
if SavedDC <= 0 then Exit(False);
repeat
SavedDevCtx := DevCtx.SavedContext;
Dec(SavedDC);
// TODO copy bitmap too
ClipRegionChanged := DevCtx.ClipRegion <> SavedDevCtx.ClipRegion;
// clear the GDIObjects in pSavedDC, so they are not freed by DeleteDC
Result := DevCtx.CopyDataFrom(SavedDevCtx, True, True, True);
DevCtx.SavedContext := SavedDevCtx.SavedContext;
SavedDevCtx.SavedContext := nil;
if ClipRegionChanged then
DevCtx.SelectRegion;
// free saved DC
DeleteDC(HDC(SavedDevCtx));
until SavedDC <= 0;
//DebugLn(Format('Trace:< [TGtkWidgetSet.RestoreDC] DC:0x%x, Saved: %d --> %s', [Integer(DC), SavedDC, BOOL_TEXT[Result]]));
end;
{------------------------------------------------------------------------------
Method: RoundRect
Params: X1, Y1, X2, Y2, RX, RY
Returns: If succesfull
Draws a Rectangle with optional rounded corners. RY is the radial height
of the corner arcs, RX is the radial width. If either is less than or equal to
0, the routine simly calls to standard Rectangle.
------------------------------------------------------------------------------}
function TGtkWidgetSet.RoundRect(DC : hDC; X1, Y1, X2, Y2: Integer;
RX,RY : Integer): Boolean;
begin
Result := inherited RoundRect(DC, X1, Y1, X2, Y2, RX, RY);
end;
{------------------------------------------------------------------------------
Function: SaveDc
Params: DC: a DC to save
Returns: 0 if the functions fails otherwise a positive integer identifing
the saved DC
The SaveDC function saves the current state of the specified device
context (DC) by copying its elements to a context stack.
-------------------------------------------------------------------------------}
function TGtkWidgetSet.SaveDC(DC: HDC): Integer;
var
DevCtx: TGtkDeviceContext absolute DC;
aSavedDC: TGtkDeviceContext;
begin
//DebugLn(Format('Trace:> [TGtkWidgetSet.SaveDC] 0x%x', [Integer(DC)]));
Result := 0;
if IsValidDC(DC) then
begin
aSavedDC := NewDC;
aSavedDC.CopyDataFrom(DevCtx, False, True, False);
aSavedDC.SavedContext := DevCtx.SavedContext;
DevCtx.SavedContext:= aSavedDC;
Result := 1;
end;
//DebugLn(Format('Trace:< [TGtkWidgetSet.SaveDC] 0x%x --> %d', [Integer(DC), Result]));
end;
{------------------------------------------------------------------------------
Function: ScreenToClient
Params: Handle:
P:
Returns:
------------------------------------------------------------------------------}
function TGtkWidgetSet.ScreenToClient(Handle : HWND; var P : TPoint) : Integer;
var
X, Y: Integer;
Widget: PGTKWidget;
Window: PgdkWindow;
Begin
if Handle = 0
then begin
X := 0;
Y := 0;
end
else
begin
Widget := GetFixedWidget(pgtkwidget(Handle));
if Widget = nil then
Widget := pgtkwidget(Handle);
if Widget = nil then
begin
X := 0;
Y := 0;
end
else begin
Window:=GetControlWindow(Widget);
{$IFDEF DebugGDK}BeginGDKErrorTrap;{$ENDIF}
if Window<>nil then
gdk_window_get_origin(Window, @X, @Y)
else begin
X:=0;
Y:=0;
end;
{$IFDEF DebugGDKTraps}EndGDKErrorTrap;{$ENDIF}
end;
end;
//DebugLn('[TGtkWidgetSet.ScreenToClient] ',x,',',y,' P=',P.X,',',P.Y);
dec(P.X, X);
dec(P.Y, Y);
Result := -1;
end;
{------------------------------------------------------------------------------
Function: ScrollWindowEx
Params: hWnd: handle of window to scroll
dx: horizontal amount to scroll
dy: vertical amount to scroll
prcScroll: pointer to scroll rectangle
prcClip: pointer to clip rectangle
hrgnUpdate: handle of update region
prcUpdate: pointer to update rectangle
flags: scrolling flags
Returns: True if succesfull;
The ScrollWindowEx function scrolls the content of the specified window's
client area
------------------------------------------------------------------------------}
function TGtkWidgetSet.ScrollWindowEx(hWnd: HWND; dx, dy: Integer; prcScroll, prcClip: PRect; hrgnUpdate: HRGN; prcUpdate: PRect; flags: UINT): Boolean;
begin
// HACK: the full functionality necessary by ScrollWindowEx isn't supported
// but as this is mainly used to update controls, we'll invalidate the full
// window to ensure that the control is up to date (this fixes controls that
// rely on ScrollWindowEx for scrolling part of the content with the irony
// that the idea of using it was to make painting faster but this fix makes
// it slower than if they just repainted themselves)
InvalidateRect(hWnd, nil, False);
// We'll still report this as a failure since, technically speaking, the
// request didn't work
Result := False;
end;
{------------------------------------------------------------------------------
Function: SelectClipRGN
Params: DC, RGN
Returns: longint
Sets the DeviceContext's ClipRegion. The Return value
is the new clip regions type, or ERROR.
The result can be one of the following constants
Error
NullRegion
SimpleRegion
ComplexRegion
------------------------------------------------------------------------------}
function TGtkWidgetSet.SelectClipRGN(DC : hDC; RGN : HRGN) : Longint;
var
DevCtx: TGtkDeviceContext absolute DC;
RegObj: PGdkRegion;
DCOrigin: TPoint;
OldClipRegion: PGDIObject;
begin
if not IsValidDC(DC) then Exit(ERROR);
// clear old clipregion
if DevCtx.ClipRegion <> nil
then begin
OldClipRegion := DevCtx.ClipRegion;
DevCtx.ClipRegion := nil;// decrease DCCount
if OldClipRegion = DevCtx.OwnedGDIObjects[gdiRegion]
then DeleteObject(HGDIOBJ(PtrUInt(OldClipRegion)));
end;
if RGN = 0
then begin
DevCtx.SelectRegion;
Exit(NULLREGION);
end;
if IsValidGDIObject(RGN)
then begin
DevCtx.ClipRegion := PGdiObject(CreateRegionCopy(RGN));
DevCtx.OwnedGDIObjects[gdiRegion] := DevCtx.ClipRegion;
RegObj := DevCtx.ClipRegion^.GDIRegionObject;
DCOrigin := DevCtx.Offset;
gdk_region_offset(RegObj, DCOrigin.x, DCOrigin.Y);
DevCtx.SelectRegion;
Exit(RegionType(RegObj));
end;
// error handling
Result := ERROR;
DebugLn('WARNING: [TGtkWidgetSet.SelectClipRGN] Invalid RGN');
{$ifdef TraceGdiCalls}
DebugLn();
DebugLn('TraceCall for invalid object: ');
DumpBackTrace(PgdiObject(RGN)^.StackAddrs);
DebugLn();
{$endif}
end;
{------------------------------------------------------------------------------
Function: SelectObject
Params: none
Returns: Nothing
------------------------------------------------------------------------------}
function TGtkWidgetSet.SelectObject(DC: HDC; GDIObj: HGDIOBJ): HGDIOBJ;
var
DevCtx: TGtkDeviceContext absolute DC;
GDIObject: PGdiObject absolute GDIObj;
ResultObj: PGdiObject absolute Result;
procedure RaiseInvalidGDIType;
begin
RaiseGDBException('TGtkWidgetSet.SelectObject Invalid GDIType '+IntToStr(ord(PGdiObject(GDIObj)^.GDIType)));
end;
{$ifdef DebugLCLComponents}
procedure DebugInvalidDC;
begin
DebugLn(['TGtkWidgetSet.SelectObject DC=',dbghex(DC),' IsValidDC(DC)=',IsValidDC(DC),' GDIObj=',dbghex(GDIObj)]);
DumpStack;
DebugLn(['DebugInvalidGDIObject DC:']);
Debugln(DebugDeviceContexts.GetInfo(Pointer(DC),true));
end;
procedure DebugInvalidGDIObject;
begin
DebugLn(['TGtkWidgetSet.SelectObject DC=',dbghex(DC),' GDIObj=',dbghex(GDIObj),' IsValidGDIObject(GDIObj)=',IsValidGDIObject(GDIObj)]);
DumpStack;
DebugLn(['DebugInvalidGDIObject GDIObj:']);
Debugln(DebugGdiObjects.GetInfo(Pointer(GDIObj),true));
end;
{$endif}
begin
Result := 0;
if not IsValidDC(DC)
then begin
{$ifdef DebugLCLComponents}
DebugInvalidDC;
{$endif}
Exit;
end;
if not IsValidGDIObject(GDIObj)
then begin
{$ifdef DebugLCLComponents}
DebugInvalidGDIObject;
{$endif}
Exit;
end;
case GDIObject^.GDIType of
gdiPen,
gdiBitmap:
ResultObj := DevCtx.SelectObject(GDIObject);
gdiBrush: begin
//DebugLn(Format('trace: [TGtkWidgetSet.SelectObject] DC: 0x%x, Type: Brush', [DC]));
ResultObj := DevCtx.GetBrush;// always create, because a valid GDIObject is needed to restore
if DevCtx.CurrentBrush = GDIObject then Exit;
DevCtx.CurrentBrush := GDIObject;
DevCtx.SelectedColors := dcscCustom;
if DevCtx.GC = nil then Exit;
gdk_gc_set_fill(DevCtx.GC, GDIObject^.GDIBrushFill);
case GDIObject^.GDIBrushFill of
GDK_STIPPLED: gdk_gc_set_stipple(DevCtx.GC, GDIObject^.GDIBrushPixMap);
GDK_TILED: gdk_gc_set_tile(DevCtx.GC, GDIObject^.GDIBrushPixMap);
end;
end;
gdiFont: begin
//DebugLn(Format('trace: [TGtkWidgetSet.SelectObject] DC: 0x%x, Type: Font', [DC]));
ResultObj := DevCtx.GetFont;// always create, because a valid GDIObject is needed to restore
if (DevCtx.CurrentFont = GDIObject) and not DevCtx.HasTransf then Exit;
DevCtx.CurrentFont := GDIObject;
{$ifdef GTK1}
if DevCtx.GC <> nil then
gdk_gc_set_font(DevCtx.GC, GdiObject^.GDIFontObject);
{$endif}
DevCtx.SetTextMetricsValid(False);
DevCtx.SelectedColors := dcscCustom;
end;
gdiRegion: begin
ResultObj := DevCtx.ClipRegion;
if DevCtx.GC <> nil
then SelectClipRGN(DC, GDIObj)
else DevCtx.ClipRegion := nil;
end;
else
RaiseInvalidGDIType;
end;
end;
{------------------------------------------------------------------------------
Function: SelectPalette
Params: none
Returns: Nothing
------------------------------------------------------------------------------}
function TGtkWidgetSet.SelectPalette(DC: HDC; Palette: HPALETTE; ForceBackground: Boolean): HPALETTE;
var
DevCtx: TGtkDeviceContext absolute DC;
begin
//DebugLn('Trace:TODO: [TGtkWidgetSet.SelectPalette]');
//TODO: Implement this;
Result := 0;
end;
{------------------------------------------------------------------------------
Function: SendMessage
Params: hWnd:
Msg:
wParam:
lParam:
Returns:
The SendMessage function sends the specified message to a window or windows.
The function calls the window procedure for the specified window and does
not return until the window procedure has processed the message.
------------------------------------------------------------------------------}
function TGtkWidgetSet.SendMessage(HandleWnd: HWND; Msg: Cardinal; wParam: WParam;
lParam: LParam): LResult;
var
OldMsg: Cardinal;
procedure PreparePaintMessage(TargetObject: TObject; var AMessage: TLMessage);
var
GtkPaintData: TLMGtkPaintData;
OldGtkPaintMsg: TLMGtkPaint;
{$IFNDEF Gtk2}
PaintDC: HDC;
DCOrigin: TPoint;
R: TRect;
{$ENDIF}
begin
(* MG: old trick. Not used anymore, but it might be, that someday there
will be component, that works better with this, so it is kept.
{ The LCL repaints controls in a top-down hierachy. But the gtk sends
gtkdraw events bottom-up. So, controls at the bottom are repainted
many times. To avoid this the queue is checked for LM_PAINT messages
for the parent control. If there is a parent LM_PAINT, this message
is ignored.}
if (Target is TControl) then begin
ParentControl:=TControl(Target).Parent;
while ParentControl<>nil do begin
ParentHandle:=TWinControl(ParentControl).Handle;
if FindPaintMessage(ParentHandle)<>nil then begin
{$IFDEF VerboseDsgnPaintMsg}
if (csDesigning in TComponent(Target).ComponentState) then begin
DebugLn('TGtkWidgetSet.SendMessage A ',
TComponent(Target).Name,':',Target.ClassName,
' Parent Message found: ',ParentControl.Name,':',ParentControl.ClassName
);
end;
{$ENDIF}
if Msg=LM_PAINT then
ReleaseDC(0,AMessage.WParam);
//exit;
end;
ParentControl:=ParentControl.Parent;
end;
end; *)
{$IFDEF VerboseDsgnPaintMsg}
if (csDesigning in TComponent(TargetObject).ComponentState) then begin
write('TGtkWidgetSet.SendMessage B ',
TComponent(TargetObject).Name,':',TargetObject.ClassName,
' GtkPaint=',AMessage.Msg=LM_GtkPAINT);
if AMessage.Msg=LM_GtkPAINT then begin
if AMessage.wParam<>0 then begin
with TLMGtkPaintData(AMessage.wParam) do begin
write(' GtkPaintData(',
' Widget=',DbgS(Widget),'=',GetWidgetClassName(Widget),
' State=',State,
' Rect=',Rect.Left,',',Rect.Top,',',Rect.Right,',',Rect.Bottom,
' RepaintAll=',RepaintAll,
')');
end;
end else begin
write(' GtkPaintData=nil');
end;
end;
DebugLn('');
end;
{$ENDIF}
if AMessage.Msg = LM_GTKPAINT
then begin
OldGtkPaintMsg := TLMGtkPaint(AMessage);
GtkPaintData := OldGtkPaintMsg.Data;
// convert LM_GTKPAINT to LM_PAINT
AMessage := TLMessage(GtkPaintMessageToPaintMessage(
TLMGtkPaint(AMessage), False));
{$IfNDef GTK2}
if (GtkPaintData <> nil) and (not GtkPaintData.RepaintAll)
then begin
PaintDC := TLMPaint(AMessage).DC;
DCOrigin := TGtkDeviceContext(PaintDC).Offset;
R:=GtkPaintData.Rect;
IntersectClipRect(PaintDC,
R.Left - DCOrigin.X, R.Top - DCOrigin.Y,
R.Right - DCOrigin.X, R.Bottom - DCOrigin.Y);
end;
{$EndIf}
GtkPaintData.Free;
end;
end;
procedure DisposePaintMessage(TargetObject: TObject; var AMessage: TLMessage);
begin
if OldMsg = LM_GTKPAINT then
begin
FinalizePaintMessage(@AMessage);
end
else
if (AMessage.Msg = LM_PAINT) and (AMessage.WParam <> 0) then
begin
// free DC
ReleaseDC(0, AMessage.WParam);
AMessage.WParam := 0;
end;
end;
var
AMessage: TLMessage;
Target: TObject;
begin
OldMsg := Msg;
AMessage.Msg := Msg;
AMessage.WParam := WParam;
AMessage.LParam := LParam;
AMessage.Result := 0;
Target := GetLCLObject(Pointer(HandleWnd));
if Target <> nil then
begin
if (Msg = LM_PAINT) or (Msg = LM_GTKPAINT) then
begin
PreparePaintMessage(Target,AMessage);
Result := DoDeliverPaintMessage(Target, TLMPaint(AMessage));
end
else
Result := DeliverMessage(Target, AMessage); // deliver it
if (Msg = LM_PAINT) or (Msg = LM_GTKPAINT) then
DisposePaintMessage(Target, AMessage);
end;
end;
{------------------------------------------------------------------------------
function SetActiveWindow(Handle: HWND): HWND;
------------------------------------------------------------------------------}
function TGtkWidgetSet.SetActiveWindow(Handle: HWND): HWND;
begin
// ToDo
Result := GetActiveWindow;
{$ifdef gtk2}
if (Handle <> 0) and GtkWidgetIsA(PGtkWidget(Handle),GTK_TYPE_WINDOW) then
begin
if GTK_WIDGET_VISIBLE(PGtkWidget(Handle)) then
gtk_window_present(PGtkWindow(Handle));
end else
Result := 0; // if not active window return error
{$endif}
end;
{------------------------------------------------------------------------------
Function: SetBkColor pbd
Params: DC: Device context to change the text background color
Color: RGB Tuple
Returns: Old Background color
------------------------------------------------------------------------------}
function TGtkWidgetSet.SetBKColor(DC: HDC; Color: TColorRef): TColorRef;
var
DevCtx: TGtkDeviceContext absolute DC;
begin
//DebugLn(Format('trace:> [TGtkWidgetSet.SetBKColor] DC: 0x%x Color: %8x', [Integer(DC), Color]));
Result := CLR_INVALID;
if IsValidDC(DC)
then begin
with TGtkDeviceContext(DC) do
begin
Result := CurrentBackColor.ColorRef;
SetGDIColorRef(CurrentBackColor,Color);
end;
end;
//DebugLn(Format('trace:< [TGtkWidgetSet.SetBKColor] DC: 0x%x Color: %8x --> %8x', [Integer(DC), Color, Result]));
end;
{------------------------------------------------------------------------------
Function: SetBkMode
Params: DC:
bkMode:
Returns:
------------------------------------------------------------------------------}
function TGtkWidgetSet.SetBkMode(DC: HDC; bkMode : Integer) : Integer;
var
DevCtx: TGtkDeviceContext absolute DC;
begin
// Your code here
Result:=0;
end;
{------------------------------------------------------------------------------
function TGtkWidgetSet.SetComboMinDropDownSize(Handle: HWND;
MinItemsWidth, MinItemsHeight: integer): boolean;
------------------------------------------------------------------------------}
function TGtkWidgetSet.SetComboMinDropDownSize(Handle: HWND;
MinItemsWidth, MinItemsHeight, MinItemCount: integer): boolean;
var
ComboWidget: PGtkCombo;
DropDownWidget, ListWidget, FirstChildWidget: PGtkWidget;
FirstChild: PGList;
CurX, CurY, CurWidth, CurHeight, CurItemHeight, BorderX, BorderY,
OldWidth, OldHeight,
NewWidth, NewHeight: integer;
ComboPopup: PGtkScrolledWindow;
item_requisition: TGtkRequisition;
begin
Result:=true;
if not (GtkWidgetIsA(PgtkWidget(Handle),GTK_TYPE_COMBO)) then
RaiseGDBException('TGtkWidgetSet.SetComboMinDropDownSize invalid handle');
// get current items width and height
ComboWidget:=PGtkCombo(Handle);
ListWidget:=ComboWidget^.List;
if ListWidget=nil then exit;
CurWidth:=ListWidget^.Allocation.Width;
// CurHeight:=ListWidget^.Allocation.Height;
CurHeight:=ListWidget^.requisition.Height;
if MinItemCount>0 then begin
FirstChild:=PGTkList(ListWidget)^.children;
if FirstChild<>nil then begin
FirstChildWidget:=PGtkWidget(FirstChild^.Data);
if FirstChildWidget<>nil then begin
gtk_widget_size_request(FirstChildWidget,@item_requisition);
CurItemHeight:=Max(FirstChildWidget^.Allocation.Height,
item_requisition.Height);
end else begin
CurItemHeight:=1;
end;
if MinItemsHeight<CurItemHeight*MinItemCount then
MinItemsHeight:=CurItemHeight*MinItemCount;
end;
end;
// calculate new width and height
DropDownWidget:=ComboWidget^.popwin;
if DropDownWidget=nil then exit;
ComboPopup:=PGtkScrolledWindow(ComboWidget^.popup);
if ComboPopup=nil then exit;
CurX:=DropDownWidget^.Allocation.x;
CurY:=DropDownWidget^.Allocation.y;
CurWidth:=pGtkWidget(ComboPopup)^.allocation.Width;
CurHeight:=pGtkWidget(ComboPopup)^.allocation.Height;
OldWidth:=DropDownWidget^.allocation.Width;
OldHeight:=DropDownWidget^.allocation.Height;
BorderX:=2*(OldWidth-CurWidth);
if BorderX<0 then BorderX:=0;
BorderY:=2*(OldHeight-CurHeight);
if BorderY<0 then BorderY:=0;
if Gtk_Widget_visible(ComboPopup^.hscrollbar) then
inc(BorderY, ComboPopup^.hscrollbar^.requisition.height
+GTK_SCROLLED_WINDOW_CLASS(gtk_object_get_class(comboWidget^.popup))^.scrollbar_spacing);
if Gtk_Widget_visible(ComboPopup^.vscrollbar) then
inc(BorderX,ComboPopup^.vscrollbar^.requisition.width
+GTK_SCROLLED_WINDOW_CLASS(gtk_object_get_class(comboWidget^.popup))^.scrollbar_spacing);
if minItemsWidth <>0 then NewWidth := MinItemsWidth+BorderX
else NewWidth := OldWidth;
if minItemsHeight<>0 then NewHeight := MinItemsHeight+BorderY
else NewHeight := OldHeight;
if (NewWidth=OldWidth) and (NewHeight=OldHeight) then exit;
NewWidth:=Min(NewWidth, Screen.Width - CurX);
NewHeight:=Min(NewHeight, Screen.Height - CurY);
if assigned(dropdownWidget^.Window) then
// widget is realized, resize gdkwindow directly
gdk_window_resize(dropdownwidget^.Window,newWidth,newHeight)
else
// widget is not yet realized, force resize needed for shrinking under gtk1)
gtk_widget_set_usize(PGtkWidget(dropDownWidget), -1,-1);
end;
{------------------------------------------------------------------------------
Function: SetCapture
Params: Value: Handle of window to capture
Returns: Nothing
------------------------------------------------------------------------------}
function TGtkWidgetSet.SetCapture(AHandle: HWND): HWND;
var
Widget: PGtkWidget;
begin
//DebugLn(Format('Trace:> [TGtkWidgetSet.SetCapture] 0x%x', [AHandle]));
Widget := PGtkWidget(AHandle);
{$IfDef VerboseMouseCapture}
DebugLn('TGtkWidgetSet.SetCapture NewValue=[',GetWidgetDebugReport(Widget),']');
{$EndIf}
// return old capture handle
Result := GetCapture;
// capture
CaptureMouseForWidget(Widget, mctLCL);
end;
{------------------------------------------------------------------------------
Function: SetCaretPos
Params: new position x, y
Returns: true on success
------------------------------------------------------------------------------}
function TGtkWidgetSet.SetCaretPos(X, Y: Integer): Boolean;
var
FocusObject: PGTKObject;
begin
FocusObject := PGTKObject(GetFocus);
Result:=SetCaretPosEx(PtrUInt(FocusObject),X,Y);
end;
{------------------------------------------------------------------------------
Function: SetCaretPos
Params: new position x, y
Returns: true on success
------------------------------------------------------------------------------}
function TGtkWidgetSet.SetCaretPosEx(Handle: HWNd; X, Y: Integer): Boolean;
var
GtkObject: PGTKObject;
begin
GtkObject := PGTKObject(Handle);
Result := GtkObject <> nil;
if Result then begin
if gtk_type_is_a(gtk_object_type(GtkObject), GTKAPIWidget_GetType)
then begin
GTKAPIWidget_SetCaretPos(PGTKAPIWidget(GtkObject), X, Y);
end
// else if // TODO: other widgettypes
else begin
Result := False;
end;
end;
end;
{------------------------------------------------------------------------------
Function: SetCaretRespondToFocus
Params: handle : Handle of a TWinControl
ShowHideOnFocus: true = caret is hidden on focus lost
Returns: true on success
------------------------------------------------------------------------------}
function TGtkWidgetSet.SetCaretRespondToFocus(handle: HWND;
ShowHideOnFocus: boolean): Boolean;
begin
if handle<>0 then begin
if gtk_type_is_a(gtk_object_type(PGTKObject(handle)), GTKAPIWidget_GetType)
then begin
GTKAPIWidget_SetCaretRespondToFocus(PGTKAPIWidget(handle),
ShowHideOnFocus);
Result:=true;
end
else begin
Result := False;
end;
end else
Result:=false;
end;
{------------------------------------------------------------------------------
Function: SetCursor
Params : hCursor - cursor handle
Returns : current cursor
------------------------------------------------------------------------------}
function TGtkWidgetSet.SetCursor(ACursor: HCURSOR): HCURSOR;
var
DefaultCursor: HCursor;
procedure SetGlobalCursor;
var
TopList, List: PGList;
begin
TopList := gdk_window_get_toplevels;
List := TopList;
while List <> nil do
begin
if (List^.Data <> nil) then
SetWindowCursor(PGDKWindow(List^.Data), ACursor, True);
list := g_list_next(list);
end;
if TopList <> nil then
g_list_free(TopList);
end;
procedure ResetGlobalCursor;
procedure SetToWindow(AWindow: PGDKWindow);
var
data: gpointer;
Widget: PGTKWidget absolute data;
WidgetInfo: PWidgetInfo;
WSPrivate: TWSPrivateClass;
begin
gdk_window_get_user_data(AWindow, @data);
if GtkWidgetIsA(Widget, gtk_widget_get_type)
then begin
WidgetInfo := GetWidgetInfo(Widget);
if (WidgetInfo <> nil)
and (WidgetInfo^.LCLObject <> nil)
and (WidgetInfo^.LCLObject is TWinControl)
then begin
WSPrivate := TWinControl(WidgetInfo^.LCLObject).WidgetSetClass.WSPrivate;
TGtkPrivateWidgetClass(WSPrivate).UpdateCursor(WidgetInfo);
Exit;
end;
end;
// no lcl cursor, so reset to default
//gdk_window_set_cursor(AWindow, PGdkCursor(DefaultCursor));
SetWindowCursor(AWindow, DefaultCursor, True);
end;
procedure Traverse(AWindow: PGDKWindow);
var
ChildWindows, ListEntry: PGList;
begin
SetToWindow(AWindow);
ChildWindows := gdk_window_get_children(AWindow);
ListEntry := ChildWindows;
while ListEntry <> nil do
begin
Traverse(PGdkWindow(ListEntry^.Data));
ListEntry := ListEntry^.Next;
end;
g_list_free(ChildWindows);
end;
var
TopList, List: PGList;
begin
TopList := gdk_window_get_toplevels;
List := TopList;
while List <> nil do
begin
if (List^.Data <> nil) then
Traverse(PGDKWindow(List^.Data));
list := g_list_next(list);
end;
if TopList <> nil then
g_list_free(TopList);
end;
begin
// set global gtk cursor
Result := FGlobalCursor;
if ACursor = FGlobalCursor then Exit;
DefaultCursor := Screen.Cursors[crDefault];
if ACursor <> DefaultCursor
then SetGlobalCursor
else ResetGlobalCursor;
FGlobalCursor := ACursor;
end;
{------------------------------------------------------------------------------
Function: SetCursorPos
Params: X:
Y:
Returns:
------------------------------------------------------------------------------}
function TGtkWidgetSet.SetCursorPos(X, Y: Integer): Boolean;
{$IFDEF HasX}
var
dpy: PDisplay;
begin
Result := False;
{$IFDEF DebugGDKTraps}
BeginGDKErrorTrap;
{$ENDIF}
try
dpy := gdk_display;
XWarpPointer(dpy, 0, RootWindow(dpy, DefaultScreen(dpy)), 0, 0, 0, 0, X, Y);
Result := True;
XFlush(dpy);
finally
{$IFDEF DebugGDKTraps}EndGDKErrorTrap;{$ENDIF}
end;
end;
{$ELSE HasX}
begin
Result := False;
DebugLn('TGtkWidgetSet.SetCursorPos not implemented for this platform');
// Can this call TWin32WidgetSet.SetCursorPos?
end;
{$ENDIF HasX}
{------------------------------------------------------------------------------
Function: SetFocus
Params: hWnd: Handle of new focus window
Returns: The old focus window
The SetFocus function sets the keyboard focus to the specified window
------------------------------------------------------------------------------}
function TGtkWidgetSet.SetFocus(hWnd: HWND): HWND;
{off $DEFINE VerboseFocus}
var
Widget, TopLevel, NewFocusWidget: PGtkWidget;
Info: PWidgetInfo;
{$IfDef VerboseFocus}
AWinControl: TWinControl;
{$EndIf}
NewTopLevelWidget: PGtkWidget;
NewTopLevelObject: TObject;
NewForm: TCustomForm;
begin
if hwnd = 0 then
begin
Result:=0;
exit;
end;
Widget:=PGtkWidget(hWnd);
{$IfDef VerboseFocus}
DebugLn('');
debugln('[TGtkWidgetSet.SetFocus] A hWnd=',GetWidgetDebugReport(Widget));
//DebugLn(getStackTrace(true));
{$EndIf}
// return the old focus handle
Result := GetFocus;
NewFocusWidget := nil;
TopLevel := gtk_widget_get_toplevel(Widget);
{$IfDef VerboseFocus}
Debugln('[TGtkWidgetSet.SetFocus] B');
DbgOut(' TopLevel=',DbgS(TopLevel));
DbgOut(' OldFocus=',GetWidgetDebugReport(PGtkWidget(Result)));
DebugLn('');
if not GTK_WIDGET_VISIBLE(Widget) then
raise Exception.Create('TGtkWidgetSet.SetFocus: Widget is not visible');
{$EndIf}
if Result=hWnd then exit;
if GtkWidgetIsA(TopLevel, gtk_window_get_type) then
begin
// TopLevel is a gtkwindow
{$IfDef VerboseFocus}
AWinControl:=TWinControl(GetNearestLCLObject(PGtkWindow(TopLevel)^.focus_widget));
write(' C TopLevel is a gtkwindow ');
write(' focus_widget=',DbgS(PGtkWindow(TopLevel)^.focus_widget));
if AWinControl<>nil then
write(' LCLParent=',AWinControl.Name,':',AWinControl.ClassName)
else
write(' LCLParent=nil');
DebugLn('');
{$EndIf}
NewTopLevelObject:=GetNearestLCLObject(TopLevel);
if (NewTopLevelObject is TCustomForm) then
begin
NewForm := TCustomForm(NewTopLevelObject);
if Screen.GetCurrentModalFormZIndex > Screen.CustomFormZIndex(NewForm) then
begin
// there is a modal form above -> focus forbidden
{$IfDef VerboseFocus}
DebugLn(' there is a modal form above -> focus forbidden');
{$EndIf}
exit;
end;
end;
NewFocusWidget := FindFocusWidget(Widget);
{$IfDef VerboseFocus}
write(' G NewFocusWidget=',DbgS(NewFocusWidget),' ',DbgSName(GetNearestLCLObject(NewFocusWidget)));
write(' WidVisible=',GTK_WIDGET_VISIBLE(PGtkWidget(NewFocusWidget)));
write(' WidRealized=',GTK_WIDGET_REALIZED(PGtkWidget(NewFocusWidget)));
write(' WidMapped=',GTK_WIDGET_MAPPED(PGtkWidget(NewFocusWidget)));
write(' WidCanfocus=',GTK_WIDGET_CAN_FOCUS(PGtkWidget(NewFocusWidget)));
write(' TopLvlVisible=',GTK_WIDGET_VISIBLE(PGtkWidget(TopLevel)));
DebugLn('');
{$EndIf}
if (NewFocusWidget<>nil) and GTK_WIDGET_CAN_FOCUS(NewFocusWidget) then
begin
if (PGtkWindow(TopLevel)^.Focus_Widget<>NewFocusWidget) then
begin
{$IfDef VerboseFocus}
DebugLn(' H SETTING NewFocusWidget=',dbgs(NewFocusWidget),' ',DbgSName(GetNearestLCLObject(NewFocusWidget)));
{$EndIf}
//DebugLn('TGtkWidgetSet.SetFocus TopLevel[',DebugGtkWidgets.GetInfo(TopLevel,false),'] NewFocusWidget=[',DebugGtkWidgets.GetInfo(NewFocusWidget,false),']');
gtk_window_set_focus(PGtkWindow(TopLevel), NewFocusWidget);
{$IfDef VerboseFocus}
DebugLn(' I NewTopLevel FocusWidget=',DbgS(PGtkWindow(TopLevel)^.Focus_Widget),' Success=',dbgs(PGtkWindow(TopLevel)^.Focus_Widget=NewFocusWidget));
{$EndIf}
end;
end;
end
else begin
NewFocusWidget:=Widget;
end;
if (NewFocusWidget <> nil) and not gtk_widget_has_focus(NewFocusWidget) then
begin
// grab the focus to the parent window
NewTopLevelWidget := gtk_widget_get_toplevel(NewFocusWidget);
NewTopLevelObject := GetNearestLCLObject(NewTopLevelWidget);
if (Screen<>nil) and (Screen.GetCurrentModalForm<>nil) and (NewTopLevelObject <>Screen.GetCurrentModalForm) then
begin
{$IFDEF VerboseFocus}
DebugLn('[TGtkWidgetSet.SetFocus] there is a modal form -> not grabbing');
{$ENDIF}
end
else
begin
{$IfDef VerboseFocus}
DebugLn(' J Grabbing focus ',GetWidgetDebugReport(NewFocusWidget));
{$EndIf}
if NewTopLevelObject is TCustomForm then
begin
Info := GetWidgetInfo(NewTopLevelWidget, False);
if (Info <> nil) and not (wwiActivating in Info^.Flags) then
SetForegroundWindow(TCustomForm(NewTopLevelObject).Handle);
end;
gtk_widget_grab_focus(NewFocusWidget);
end;
end;
{$IfDef VerboseFocus}
write('[TGtkWidgetSet.SetFocus] END hWnd=',DbgS(hWnd));
NewFocusWidget:=PGtkWidget(GetFocus);
write(' NewFocus=',DbgS(NewFocusWidget));
AWinControl:=TWinControl(GetNearestLCLObject(NewFocusWidget));
if AWinControl<>nil then
write(' NewLCLParent=',AWinControl.Name,':',AWinControl.ClassName)
else
write(' NewLCLParent=nil');
DebugLn('');
{$EndIf}
end;
{------------------------------------------------------------------------------
Function: SetForegroundWindow
Params: hWnd:
Returns:
------------------------------------------------------------------------------}
function TGtkWidgetSet.SetForegroundWindow(hWnd : HWND): boolean;
var
{$IFDEF VerboseFocus}
LCLObject: TControl;
{$ENDIF}
GdkWindow: PGdkWindow;
AForm: TCustomForm;
{$IFDEF GTK1}
FormWidget: PGtkWidget;
FormWindow: PGdkWindowPrivate;
WindowDesktop: Integer;
{$ENDIF}
begin
{$IFDEF VerboseFocus}
DbgOut('TGtkWidgetSet.SetForegroundWindow hWnd=',DbgS(hWnd));
LCLObject:=TControl(GetLCLObject(Pointer(hWnd)));
if LCLObject<>nil then
DebugLn(' LCLObject=',LCLObject.Name,':',LCLObject.ClassName)
else
DebugLn(' LCLObject=nil');
{$ENDIF}
Result := GtkWidgetIsA(PGtkWidget(hWnd),GTK_TYPE_WINDOW);
if Result then
begin
GdkWindow := GetControlWindow(PgtkWidget(hwnd));
if GdkWindow <> nil then
begin
if not gdk_window_is_visible(GdkWindow) then
begin
Result := False;
Exit;
end;
AForm := TCustomForm(GetLCLObject(PgtkWidget(hwnd)));
if (AForm <> nil) and (AForm is TCustomForm) and (AForm.Parent=nil) then
begin
if Screen.CustomFormZIndex(AForm) < Screen.GetCurrentModalFormZIndex then
begin
debugln('TGtkWidgetSet.SetForegroundWindow Form=',DbgSName(AForm),
' can not be raised, because ',
DbgSName(Screen.GetCurrentModalForm),
' is modal and above.');
Result := False;
exit;
end;
Screen.MoveFormToZFront(AForm);
end;
{$IFDEF DebugGDKTraps}
BeginGDKErrorTrap;
{$ENDIF}
gdk_window_show(GdkWindow);
gdk_window_raise(GdkWindow);
{$IFDEF DebugGDKTraps}
EndGDKErrorTrap;
{$ENDIF}
{$IFDEF GTK1}
FormWidget:=PGtkWidget(AForm.Handle);
FormWindow:=PGdkWindowPrivate(FormWidget^.window);
if FormWindow<>nil then begin
WindowDesktop := GDK_WINDOW_GET_DESKTOP(FormWindow);
// this prevents the window from appearing on a different desktop
// which could be undesirable.
// check if the window is on all desktops or is on the current desktop
if (WindowDesktop < 0) or (WindowDesktop = GDK_GET_CURRENT_DESKTOP) then
begin
GDK_WINDOW_ACTIVATE(FormWindow);
end
else begin
// TODO: Figure out how to set the focus on an inactive desktop without
// bringing the window to the current desktop
end;
end;
{$ELSE}
// this currently will bring the window to the current desktop and focus it
gtk_window_present(PGtkWindow(hWnd));
{$ENDIF}
end;
end;
end;
function TGtkWidgetSet.SetMapMode(DC: HDC; fnMapMode : Integer): Integer;
var
DevCtx: TGtkDeviceContext absolute DC;
begin
Result := Integer(False);
if not IsValidDC(DC) then Exit(0);
DevCtx.MapMode := fnMapMode;
Result := Integer(True);
end;
function TGTKWidgetSet.SetParent(hWndChild: HWND; hWndParent: HWND): HWND;
var
Fixed: PGtkWidget;
LCLObject: TObject;
begin
Result := GetParent(hWndChild);
if Result = hWndParent then
Exit;
// for window we need to move it content to HBox
if GTK_IS_WINDOW(PGtkWidget(hWndChild)) then
begin
LCLObject := GetLCLObject(PGtkWidget(hWndChild));
if LCLObject <> nil then
Controls.RecreateWnd(TWinControl(LCLObject));
Exit;
end;
if Result <> 0 then
begin
// unparent first
gtk_widget_ref(PGtkWidget(hWndChild));
if GTK_IS_CONTAINER(Pointer(Result)) then
gtk_container_remove(PGtkContainer(Result), PGtkWidget(hWndChild))
else
gtk_widget_unparent(PGtkWidget(hWndChild));
end;
Fixed := GetFixedWidget(PGtkWidget(hWndParent));
if Fixed <> nil then
begin
FixedPutControl(Fixed, PGtkWidget(hWndChild), PGtkWidget(hWndChild)^.allocation.x, PGtkWidget(hWndChild)^.allocation.y);
RegroupAccelerator(PGtkWidget(hWndChild));
end
else
gtk_widget_set_parent(PGtkWidget(hWndChild), PGtkWidget(hWndParent));
if Result <> 0 then
gtk_widget_unref(PGtkWidget(hWndChild));
end;
{------------------------------------------------------------------------------
function TGtkWidgetSet.SetProp(Handle: hwnd; Str : PChar;
Data : Pointer) : Boolean;
------------------------------------------------------------------------------}
function TGtkWidgetSet.SetProp(Handle: hwnd; Str : PChar; Data : Pointer) : Boolean;
begin
gtk_object_set_data(pGTKObject(handle),Str,data);
Result:=true;
end;
{------------------------------------------------------------------------------
Method: SetRectRgn
Params: aRGN: HRGN; X1, Y1, X2, Y2 : Integer
Returns: True if the function succeeds
Converts a region into a rectangular region with the specified coordinates.
------------------------------------------------------------------------------}
function TGtkWidgetSet.SetRectRgn(aRGN: HRGN; X1, Y1, X2, Y2 : Integer): Boolean;
procedure Swap(var A, B: Integer);
var
Tmp: Integer;
begin
Tmp := A;
A := B;
B := Tmp;
end;
var
AGdiObject: PGdiObject absolute aRGN;
begin
Result := IsValidGDIObject(aRGN);
if Result then begin
if (X1 > X2) then swap(X1, X2);
if (Y1 > Y2) then swap(Y1, Y2);
AGdiObject^.GDIRegionObject := CreateRectGDKRegion(Rect(X1,Y1,X2,Y2));
Result := True;
end;
end;
{------------------------------------------------------------------------------
function TGtkWidgetSet.SetROPMode(Handle: hwnd; Str : PChar;
Data : Pointer) : Boolean;
------------------------------------------------------------------------------}
function TGtkWidgetSet.SetROP2(DC: HDC; Mode: Integer) : Integer;
var
DevCtx: TGtkDeviceContext absolute DC;
begin
if not IsValidDC(DC) then Exit(0);
Result := DevCtx.ROP2;
DevCtx.ROP2 := Mode;
end;
{------------------------------------------------------------------------------
Function: SetScrollInfo
Params: none
Returns: The new position value
nPage >= 0
nPage <= nMax-nMin+1
nPos >= nMin
nPos <= nMax - Max(nPage-1,0)
------------------------------------------------------------------------------}
function TGtkWidgetSet.SetScrollInfo(Handle : HWND; SBStyle : Integer;
ScrollInfo: TScrollInfo; bRedraw : Boolean): Integer;
procedure SetRangeUpdatePolicy(Range: PGtkRange);
var
UpdPolicy: TGTKUpdateType;
begin
case ScrollInfo.nTrackPos of
SB_POLICY_DISCONTINUOUS: UpdPolicy := GTK_UPDATE_DISCONTINUOUS;
SB_POLICY_DELAYED: UpdPolicy := GTK_UPDATE_DELAYED;
else UpdPolicy := GTK_UPDATE_CONTINUOUS;
end;
gtk_range_set_update_policy(Range, UpdPolicy);
end;
procedure SetScrolledWindowUpdatePolicy(ScrolledWindow:PGTKScrolledWindow);
var
Range: PGtkRange;
begin
case SBStyle of
SB_VERT: Range := PGtkRange(ScrolledWindow^.vscrollbar);
SB_HORZ: Range := PGtkRange(ScrolledWindow^.hscrollbar);
else exit;
end;
SetRangeUpdatePolicy(Range);
end;
const
POLICY: array[BOOLEAN] of TGTKPolicyType = (GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);
var
Adjustment: PGtkAdjustment;
Layout: PgtkLayout;
Scroll: PGTKWidget;
IsScrollWindow: Boolean;
IsScrollbarVis: boolean;
begin
Result := 0;
if (Handle = 0) then exit;
{DebugLn(['TGtkWidgetSet.SetScrollInfo A Widget=',GetWidgetDebugReport(PGtkWidget(Handle)),' SBStyle=',SBStyle,
' ScrollInfo=[',
'cbSize=',ScrollInfo.cbSize,
',fMask=',ScrollInfo.fMask,
',nMin=',ScrollInfo.nMin,
',nMax=',ScrollInfo.nMax,
',nPage=',ScrollInfo.nPage,
',nPos=',ScrollInfo.nPos,
',nTrackPos=',ScrollInfo.nTrackPos,
']']);}
Scroll := gtk_object_get_data(PGTKObject(Handle), odnScrollArea);
if GtkWidgetIsA(Scroll, gtk_scrolled_window_get_type)
then begin
IsScrollWindow := True;
end
else begin
Scroll := PGTKWidget(Handle);
IsScrollWindow := GtkWidgetIsA(Scroll, gtk_scrolled_window_get_type);
end;
if IsScrollWindow
then begin
Layout := GetFixedWidget(PGTKObject(Handle));
if not GtkWidgetIsA(PGtkWidget(Layout), gtk_layout_get_type)
then Layout := nil;
end
else begin
Layout := nil;
end;
// scrollbar update policy
if (Scrollinfo.fmask and SIF_UPDATEPOLICY <> 0) then begin
if IsScrollWindow then
SetScrolledWindowUpdatePolicy(PGTKScrolledWindow(Scroll))
else if GtkWidgetIsA(PgtkWidget(Scroll), gtk_clist_get_type) then
SetScrolledWindowUpdatePolicy(PGTKScrolledWindow(@PgtkCList(Scroll)^.container))
else if GtkWidgetIsA(PGtkWidget(Scroll),gtk_hscrollbar_get_type) then
SetRangeUpdatePolicy(PgtkRange(Scroll))
else if GtkWidgetIsA(PGtkWidget(Scroll),gtk_vscrollbar_get_type) then
SetRangeUpdatePolicy(PgtkRange(Scroll))
else if GtkWidgetIsA(PGtkWidget(Scroll), gtk_range_get_type) then
SetRangeUpdatePolicy(PGTKRange(Scroll));
end;
Adjustment:=nil;
case SBStyle of
SB_HORZ:
if IsScrollWindow
then begin
Adjustment := gtk_scrolled_window_get_hadjustment(PGTKScrolledWindow(Scroll));
if Layout <> nil
then begin
if (ScrollInfo.fMask and SIF_RANGE) <> 0
then gtk_layout_set_size(Layout, ScrollInfo.nMax - ScrollInfo.nMin, Layout^.height);
Result := round(Layout^.hadjustment^.value);
end;
end
// obsolete stuff
else if GtkWidgetIsA(PGtkWidget(Scroll),gtk_hscrollbar_get_type)
then begin
// this one shouldn't be possible, scrollbar messages are sent to the CTL
DebugLN('!!! direct SB_HORZ set call to scrollbar');
Adjustment := PgtkhScrollBar(Scroll)^.Scrollbar.Range.Adjustment
end
else if GtkWidgetIsA(PGtkWidget(Scroll),gtk_clist_get_type)
then begin
//clist
//TODO: check if this is needed for listviews
DebugLn('[SetScrollInfo] Possible obsolete set use of CList (Listview ?)');
Adjustment := gtk_clist_get_hadjustment(PgtkCList(Scroll));
end;
SB_VERT:
if IsScrollWindow
then begin
Adjustment := gtk_scrolled_window_get_vadjustment(PGTKScrolledWindow(Scroll));
if Layout <> nil
then begin
if (ScrollInfo.fMask and SIF_RANGE) <> 0
then gtk_layout_set_size(Layout, Layout^.Width, ScrollInfo.nMax - ScrollInfo.nMin);
Result := round(Layout^.vadjustment^.value);
end;
end
// obsolete stuff
else if GtkWidgetIsA(PGtkWidget(Scroll),gtk_vscrollbar_get_type)
then begin
// this one shouldn't be possible, scrollbar messages are sent to the CTL
DebugLN('!!! direct SB_VERT call to scrollbar');
Adjustment := PgtkvScrollBar(Scroll)^.Scrollbar.Range.Adjustment;
end
else if GtkWidgetIsA(PGtkWidget(Scroll), gtk_clist_get_type)
then begin
//TODO: check is this is needed for listviews
DebugLn('[SetScrollInfo] Possible obsolete set use of CList (Listview ?)');
Adjustment := gtk_clist_get_vadjustment(PgtkCList(Scroll));
end;
SB_CTL:
if GtkWidgetIsA(PGtkWidget(Scroll),gtk_vscrollbar_get_type) then
Adjustment := PgtkvScrollBar(Scroll)^.Scrollbar.Range.Adjustment
else
if GtkWidgetIsA(PGtkWidget(Scroll),gtk_hscrollbar_get_type) then
Adjustment := PgtkhScrollBar(Scroll)^.Scrollbar.Range.Adjustment
else
if GtkWidgetIsA(PGtkWidget(Scroll), gtk_range_get_type) then
Adjustment := gtk_range_get_adjustment(PGTKRange(Scroll));
SB_BOTH:
DebugLn('[SetScrollInfo] Got SB_BOTH ???');
end;
if Adjustment = nil then
exit;
if (ScrollInfo.fMask and SIF_RANGE) <> 0
then begin
Adjustment^.lower := ScrollInfo.nMin;
Adjustment^.upper := ScrollInfo.nMax;
end;
if (ScrollInfo.fMask and SIF_PAGE) <> 0
then begin
// 0 <= nPage <= nMax-nMin+1
Adjustment^.page_size := ScrollInfo.nPage;
Adjustment^.page_size := Min(Max(Adjustment^.page_size,0),
Adjustment^.upper-Adjustment^.lower+1);
Adjustment^.page_increment := (Adjustment^.page_size/6)+1;
end;
if (ScrollInfo.fMask and SIF_POS) <> 0
then begin
// nMin <= nPos <= nMax - Max(nPage-1,0)
Adjustment^.value := ScrollInfo.nPos;
Adjustment^.value := Max(Adjustment^.value,Adjustment^.lower);
Adjustment^.value := Min(Adjustment^.value,
Adjustment^.upper-Max(Adjustment^.page_size-1,0));
end;
// check if scrollbar should be hidden
IsScrollbarVis := true;
if ((ScrollInfo.fMask and (SIF_RANGE or SIF_PAGE)) <> 0) and
((SBStyle=SB_HORZ) or (SBStyle=SB_VERT))
then begin
if (Adjustment^.lower >= (Adjustment^.upper-Max(adjustment^.page_size-1,0)))
then begin
if (ScrollInfo.fMask and SIF_DISABLENOSCROLL) = 0 then
IsScrollbarVis := false
else
;// scrollbar should look disabled (no thumbbar and grayed appearance)
// maybe not possible in gtk
end;
end;
Result := Round(Adjustment^.value);
{DebugLn('');
DebugLn('[TGtkWidgetSet.SetScrollInfo] Result=',Result,
' Lower=',RoundToInt(Lower),
' Upper=',RoundToInt(Upper),
' Page_Size=',RoundToInt(Page_Size),
' Page_Increment=',RoundToInt(Page_Increment),
' bRedraw=',bRedraw,
' Handle=',DbgS(Handle));}
// do we have to set this always ?
// ??? what is this for code ????
// why not change adjustment if we don't do a redraw ???
if bRedraw then
begin
if IsScrollWindow
then begin
case SBStyle of
SB_HORZ:
gtk_object_set(PGTKObject(Scroll),'hscrollbar_policy',[POLICY[IsScrollbarVis],nil]);
SB_VERT:
gtk_object_set(PGTKObject(Scroll),'vscrollbar_policy',[POLICY[IsScrollbarVis],nil]);
end;
end
else
gtk_widget_queue_draw(PGTKWidget(Scroll));
(*
DebugLn('TGtkWidgetSet.SetScrollInfo:' +
' lower=%d/%d upper=%d/%d value=%d/%d' +
' step_increment=%d/1 page_increment=%d/%d page_size=%d/%d', [
Round(lower),nMin, Round(upper),nMax, Round(value),nPos,
Round(step_increment), Round(page_increment),nPage, Round(page_size),nPage]
);
*)
gtk_adjustment_changed(Adjustment);
end;
end;
{------------------------------------------------------------------------------
Function: SetSysColors
Params: cElements: the number of elements
lpaElements: array with element numbers
lpaRgbValues: array with colors
Returns: 0 if unsuccesful
The SetSysColors function sets the colors for one or more display elements.
------------------------------------------------------------------------------}
function TGtkWidgetSet.SetSysColors(cElements: Integer; const lpaElements;
const lpaRgbValues): Boolean;
var
n: Integer;
Element: LongInt;
begin
Result := False;
if cElements > MAX_SYS_COLORS then Exit;
for n := 0 to cElements - 1 do
begin
Element := PInteger(lpaElements)[n];
if (Element > MAX_SYS_COLORS) or (Element < 0) then
Exit;
SysColorMap[Element] := PDword(@lpaRgbValues)[n];
//DebugLn(Format('Trace:[TGtkWidgetSet.SetSysColor] Index %d (%8x) --> %8x', [PLongArray(lpaElements)^[n], SysColorMap[PLongArray(lpaElements)^[n]], PLongArray(lpaRgbValues)^[n]]));
end;
//TODO send WM_SYSCOLORCHANGE
Result := True;
end;
{------------------------------------------------------------------------------
Function: SetTextCharacterExtra
Params: _hdc:
nCharExtra:
Returns:
------------------------------------------------------------------------------}
function TGtkWidgetSet.SetTextCharacterExtra(DC : hdc; nCharExtra : Integer):Integer;
var
DevCtx: TGtkDeviceContext absolute DC;
begin
// Your code here
Result:=0;
end;
{------------------------------------------------------------------------------
Function: SetTextColor
Params: hdc: Identifies the device context.
Color: Specifies the color of the text.
Returns: The previous color if succesful, CLR_INVALID otherwise
The SetTextColor function sets the text color for the specified device
context to the specified color.
------------------------------------------------------------------------------}
function TGtkWidgetSet.SetTextColor(DC: HDC; Color: TColorRef): TColorRef;
var
DevCtx: TGtkDeviceContext absolute DC;
begin
//DebugLn(Format('trace:> [TGtkWidgetSet.SetTextColor] DC: 0x%x Color: %8x', [Integer(DC), Color]));
Result := CLR_INVALID;
if IsValidDC(DC)
then begin
with TGtkDeviceContext(DC) do
begin
Result := CurrentTextColor.ColorRef;
SetGDIColorRef(CurrentTextColor,Color);
if Result<>Color then
SelectedColors := dcscCustom; // force SelectGDKTextProps to ensure text color
end;
end;
//DebugLn(Format('trace:< [TGtkWidgetSet.SetTextColor] DC: 0x%x Color: %8x --> %8x', [Integer(DC), Color, Result]));
end;
function TGtkWidgetSet.SetViewPortExtEx(DC: HDC; XExtent, YExtent : Integer; OldSize: PSize): Boolean;
var
DevCtx: TGtkDeviceContext absolute DC;
begin
Result := False;
if not IsValidDC(DC) then Exit;
if OldSize <> nil then
begin
OldSize^.cx := DevCtx.ViewPortExt.x;
OldSize^.cy := DevCtx.ViewPortExt.y;
end;
if (XExtent <> DevCtx.ViewPortExt.x) or (YExtent <> DevCtx.ViewPortExt.y) then
begin
case DevCtx.MapMode of
MM_ANISOTROPIC, MM_ISOTROPIC:
begin
DevCtx.ViewPortExt := Point(XExtent, YExtent);
Result := True;
end;
end;
end;
end;
function TGtkWidgetSet.SetViewPortOrgEx(DC: HDC; NewX, NewY: Integer; OldPoint: PPoint): Boolean;
var
DevCtx: TGtkDeviceContext absolute DC;
begin
Result := False;
if not IsValidDC(DC) then Exit;
if OldPoint <> nil then
begin
OldPoint^.x := DevCtx.ViewPortOrg.x;
OldPoint^.y := DevCtx.ViewPortOrg.y;
end;
if (NewX <> DevCtx.ViewPortOrg.x) or (NewY <> DevCtx.ViewPortOrg.y) then
begin
DevCtx.ViewPortOrg := Point(NewX, NewY);
Result := True;
end;
end;
function TGtkWidgetSet.SetWindowExtEx(DC: HDC; XExtent, YExtent: Integer; OldSize: PSize): Boolean;
var
DevCtx: TGtkDeviceContext absolute DC;
begin
Result := False;
if not IsValidDC(DC) then Exit;
if OldSize <> nil then
begin
OldSize^.cx := DevCtx.WindowExt.x;
OldSize^.cy := DevCtx.WindowExt.y;
end;
if (XExtent <> DevCtx.WindowExt.x) or (YExtent <> DevCtx.WindowExt.y) then
begin
case DevCtx.MapMode of
MM_ANISOTROPIC, MM_ISOTROPIC:
begin
DevCtx.WindowExt := Point(XExtent, YExtent);
Result := True;
end;
end;
end;
end;
{------------------------------------------------------------------------------
Procedure: SetWindowLong
Params: none
Returns: Nothing
------------------------------------------------------------------------------}
function TGtkWidgetSet.SetWindowLong(Handle: HWND; Idx: Integer;
NewLong: PtrInt): PtrInt;
var
Data: Pointer;
WidgetInfo: PWidgetInfo;
begin
//TODO: Finish this;
//DebugLn(Format('Trace:> [TGtkWidgetSet.SETWINDOWLONG] HWND: 0x%x, idx: 0x%x(%d), Value: 0x%x(%d)', [Handle, idx, idx, newlong, newlong]));
Result:=0;
Data := Pointer(NewLong);
case idx of
GWL_WNDPROC :
begin
WidgetInfo := GetWidgetInfo(Pointer(Handle));
if WidgetInfo <> nil then
WidgetInfo^.WndProc := NewLong;
end;
GWL_HINSTANCE :
begin
gtk_object_set_data(pgtkobject(Handle),'HINSTANCE',Data);
end;
GWL_HWNDPARENT :
begin
gtk_object_set_data(pgtkobject(Handle),'HWNDPARENT',Data);
end;
GWL_STYLE :
begin
WidgetInfo := GetWidgetInfo(Pointer(Handle));
if WidgetInfo <> nil then
WidgetInfo^.Style := NewLong;
end;
GWL_EXSTYLE :
begin
WidgetInfo := GetWidgetInfo(Pointer(Handle));
if WidgetInfo <> nil then
WidgetInfo^.ExStyle := NewLong;
end;
GWL_USERDATA :
begin
gtk_object_set_data(pgtkobject(Handle),'Userdata',Data);
end;
GWL_ID :
begin
gtk_object_set_data(pgtkobject(Handle),'ID',Data);
end;
end; //case
//DebugLn(Format('Trace:< [TGtkWidgetSet.SETWINDOWLONG] HWND: 0x%x, idx: 0x%x(%d), Value: 0x%x(%d) --> 0x%x(%d)', [Handle, idx, idx, newlong, newlong, Result, Result]));
end;
{------------------------------------------------------------------------------
function TGtkWidgetSet.SetWindowOrgEx(DC : HDC; NewX, NewY : Integer;
OldPoint: PPoint) : Boolean;
Sets the DC offset for the specified device context.
------------------------------------------------------------------------------}
function TGtkWidgetSet.SetWindowOrgEx(DC : HDC; NewX, NewY : Integer;
OldPoint: PPoint) : Boolean;
var
DevCtx: TGtkDeviceContext absolute DC;
OldP: TPoint;
begin
//DebugLn('[TGtkWidgetSet.SetWindowOrgEx] ',NewX,' ',NewY);
GetWindowOrgEx(DC, @OldP);
Result := MoveWindowOrgEx(DC, -NewX - OldP.X, -NewY - OldP.Y);
if OldPoint <> nil then
OldPoint^ := OldP;
end;
{------------------------------------------------------------------------------
function TGtkWidgetSet.SetWindowPos(hWnd: HWND; hWndInsertAfter: HWND;
X, Y, cx, cy: Integer; uFlags: UINT): Boolean;
hWnd: Widget to move
hWndInsertAfter:
HWND_BOTTOM to move bottommost
HWND_TOP to move topmost
the Widget, that should lie just on top of hWnd
uFlags:
SWP_NOMOVE: ignore X, Y
SWP_NOSIZE: ignore cx, cy
SWP_NOZORDER: ignore hWndInsertAfter
SWP_NOREDRAW: skip instant redraw
SWP_NOACTIVATE: skip switching focus
------------------------------------------------------------------------------}
function TGtkWidgetSet.SetWindowPos(hWnd: HWND; hWndInsertAfter: HWND;
X, Y, cx, cy: Integer; uFlags: UINT): Boolean;
procedure SetZOrderOnFixedWidget(Widget, FixedWidget: PGtkWidget);
var
OldListItem: PGList;
AfterWidget: PGtkWidget;
AfterListItem: PGList;
begin
OldListItem:=FindFixedChildListItem(PGtkFixed(FixedWidget),Widget);
if OldListItem=nil then begin
DebugLn('TGtkWidgetSet.SetWindowPos.SetZOrderOnFixedWidget WARNING: Widget not on parents fixed widget');
exit;
end;
AfterWidget:=nil;
AfterListItem:=nil;
if hWndInsertAfter=HWND_BOTTOM then begin
//debugln('HWND_BOTTOM');
// HWND_BOTTOM
end else if hWndInsertAfter=HWND_TOP then begin
//debugln('HWND_TOP');
// HWND_TOP
AfterListItem:=FindFixedLastChildListItem(PGtkFixed(FixedWidget));
end else if hWndInsertAfter=0 then begin
DebugLn('TGtkWidgetSet.SetWindowPos.SetZOrderOnFixedWidget WARNING: hWndInsertAfter=0');
exit;
end else begin
// hWndInsertAfter
AfterWidget:=PGtkWidget(hWndInsertAfter);
AfterListItem:=FindFixedChildListItem(PGtkFixed(FixedWidget),AfterWidget);
//debugln('AfterWidget=',GetWidgetDebugReport(AfterWidget));
end;
if (AfterListItem=nil) and (AfterWidget<>nil) then begin
DebugLn('TGtkWidgetSet.SetWindowPos.SetZOrderOnFixedWidget WARNING: AfterWidget not on parents fixed widget');
exit;
end;
if (OldListItem=AfterListItem) or (OldListItem^.next=AfterListItem) then
begin
{$IFDEF EnableGtkZReordering}
DebugLn('TGtkWidgetSet.SetWindowPos.SetZOrderOnFixedWidget Hint: Already there');
{$ENDIF}
exit;
end;
//DebugLn('TGtkWidgetSet.SetWindowPos Moving GList entry');
// reorder
{$IFDEF EnableGtkZReordering}
// MG: This trick does not work properly
debugln('SetZOrderOnFixedWidget FixedWidget=['+GetWidgetDebugReport(FixedWidget)+']',
' Widget=['+GetWidgetDebugReport(Widget)+']',
' AfterWidget=['+GetWidgetDebugReport(AfterWidget)+']');
MoveGListLinkBehind(PGtkFixed(FixedWidget)^.children,
OldListItem,AfterListItem);
if GTK_WIDGET_VISIBLE(FixedWidget) and GTK_WIDGET_VISIBLE(Widget)
and GTK_WIDGET_MAPPED(Widget) then begin
DebugLn('TGtkWidgetSet.SetWindowPos.SetZOrderOnFixedWidget resize ..');
gtk_widget_queue_resize(FixedWidget);
AfterListItem:=PGtkFixed(FixedWidget)^.children;
while AfterListItem<>nil do begin
AfterWidget:=GetFixedChildListWidget(AfterListItem);
DebugLn('TGtkWidgetSet.SetWindowPos.SetZOrderOnFixedWidget A ',GetWidgetDebugReport(AfterWidget));
AfterListItem:=AfterListItem^.next;
end;
end;
{$ENDIF}
end;
procedure SetZOrderOnLayoutWidget(Widget, LayoutWidget: PGtkWidget);
begin
//DebugLn('TGtkWidgetSet.SetWindowPos.SetZOrderOnLayoutWidget Not implemented: ZOrdering .. on ',GetWidgetDebugReport(LayoutWidget));
end;
var
Widget: PGTKWidget;
FixedWidget: PGtkWidget;
begin
Result:=false;
Widget:=PGtkWidget(hWnd);
{DebugLn('[TGtkWidgetSet.SetWindowPos] ',GetWidgetDebugReport(Widget),
' Top=',hWndInsertAfter=HWND_TOP,
' SWP_NOZORDER=',(SWP_NOZORDER and uFlags)<>0,
' SWP_NOSIZE=',(SWP_NOSIZE and uFlags)<>0,
' SWP_NOMOVE=',(SWP_NOMOVE and uFlags)<>0,
'');}
if GtkWidgetIsA(Widget,GTK_TYPE_WINDOW) then begin
{ case hWndInsertAfter of
HWND_BOTTOM: ; //gdk_window_lower(Widget^.Window);
HWND_TOP: gtk_window_set_position(PGtkWindow(hWnd),GTK_WIN_POS_CENTER);
//gdk_window_raise(Widget^.Window);
end;
}
end else if (SWP_NOZORDER and uFlags)=0 then begin
FixedWidget:=Widget^.Parent;
if FixedWidget=nil then exit;
//DebugLn('TGtkWidgetSet.SetWindowPos ZOrdering .. on ',GetWidgetDebugReport(FixedWidget));
if GtkWidgetIsA(FixedWidget,GTK_Fixed_Get_Type) then begin
// parent's client area is a gtk_fixed widget
SetZOrderOnFixedWidget(Widget,FixedWidget);
end else if GtkWidgetIsA(FixedWidget,GTK_Layout_Get_Type) then begin
// parent's client area is a gtk_layout widget
SetZOrderOnLayoutWidget(Widget,FixedWidget);
end else begin
//DebugLn('TGtkWidgetSet.SetWindowPos Not implemented: ZOrdering .. on ',GetWidgetDebugReport(FixedWidget));
exit;
end;
end;
Result:=true;
end;
{------------------------------------------------------------------------------
Function: ShowCaret
Params: none
Returns: Nothing
------------------------------------------------------------------------------}
function TGtkWidgetSet.ShowCaret(hWnd: HWND): Boolean;
var
GTKObject: PGTKObject;
begin
//DebugLn(Format('Trace:> [TGtkWidgetSet.ShowCaret] HWND: 0x%x', [hWnd]));
GTKObject := PGTKObject(HWND);
Result := GTKObject <> nil;
if Result
then begin
if gtk_type_is_a(gtk_object_type(GTKObject), GTKAPIWidget_GetType)
then begin
GTKAPIWidget_ShowCaret(PGTKAPIWidget(GTKObject));
end
else begin
Result := False;
end;
end
else DebugLn('WARNING: [TGtkWidgetSet.ShowCaret] Got null HWND');
//DebugLn(Format('Trace:< [TGtkWidgetSet.ShowCaret] HWND: 0x%x --> %s', [hWnd, BOOL_TEXT[Result]]));
end;
{------------------------------------------------------------------------------
Function: ShowScrollBar
Params: Wnd, wBar, bShow
Returns: Nothing
------------------------------------------------------------------------------}
function TGtkWidgetSet.ShowScrollBar(Handle: HWND; wBar: Integer;
bShow: Boolean): Boolean;
var
NewPolicy: Integer;
Scroll: PGtkWidget;
IsScrollWindow: Boolean;
begin
//DebugLn('trace:[TGtkWidgetSet.ShowScrollBar]');
Result := (Handle <> 0);
if not Result then exit;
Scroll := PGtkWidget(gtk_object_get_data(PGTKObject(Handle), odnScrollArea));
if GtkWidgetIsA(Scroll, gtk_scrolled_window_get_type)
then begin
IsScrollWindow := True;
end
else begin
Scroll := PGTKWidget(Handle);
IsScrollWindow := GtkWidgetIsA(Scroll, gtk_scrolled_window_get_type);
end;
//DebugLn(['TGtkWidgetSet.ShowScrollBar ',GetWidgetDebugReport(Scroll),' wBar=',wBar,' bShow=',bShow]);
if IsScrollWindow then begin
if wBar in [SB_BOTH, SB_HORZ] then begin
//DebugLn(['TGtkWidgetSet.ShowScrollBar ',GetWidgetDebugReport(Widget),' bShow=',bShow]);
if bShow then
NewPolicy:=GTK_POLICY_ALWAYS
else
NewPolicy:=GTK_POLICY_NEVER;
gtk_object_set(PGTKObject(Scroll), 'hscrollbar_policy', [NewPolicy,nil]);
end;
if wBar in [SB_BOTH, SB_VERT] then begin
if bShow then
NewPolicy:=GTK_POLICY_ALWAYS
else
NewPolicy:=GTK_POLICY_NEVER;
gtk_object_set(PGTKObject(Scroll), 'vscrollbar_policy', [NewPolicy,nil]);
end;
end
else begin
if (wBar = SB_CTL)
and gtk_type_is_a(gtk_object_type(PGTKObject(Handle)),gtk_widget_get_type)
then begin
if bShow
then gtk_widget_show(Scroll)
else gtk_widget_hide(Scroll);
end;
end;
end;
{------------------------------------------------------------------------------
function ShowWindow(hWnd: HWND; nCmdShow: Integer): Boolean;
nCmdShow:
SW_SHOWNORMAL, SW_MINIMIZE, SW_SHOWMAXIMIZED
------------------------------------------------------------------------------}
function TGtkWidgetSet.ShowWindow(hWnd: HWND; nCmdShow: Integer): Boolean;
var
GtkWindow: PGtkWindow;
Widget: PGtkWidget;
begin
Result:=false;
Widget := PGtkWidget(hWND);
if Widget = nil then
RaiseGDBException('TGtkWidgetSet.ShowWindow hWnd is nil');
if not GtkWidgetIsA(Widget,GTK_TYPE_WINDOW) then
begin
// we are pure gtkwidget so only SW_SHOW AND SW_HIDE CAN GO
case nCmdShow of
SW_SHOWNORMAL,
SW_SHOW: gtk_widget_show(Widget);
SW_HIDE: gtk_widget_hide(Widget);
end;
Result := nCmdShow in [SW_SHOW, SW_HIDE];
exit;
end;
GtkWindow:=PGtkWindow(hWnd);
if GtkWindow=nil then
RaiseGDBException('TGtkWidgetSet.ShowWindow hWnd is nil');
if not GtkWidgetIsA(PGtkWidget(GtkWindow),GTK_TYPE_WINDOW) then
RaiseGDBException('TGtkWidgetSet.ShowWindow hWnd is not a gtkwindow');
{$IFDEF Gtk2}
// Implemented on gtk2winapi.inc
// This ifdef is necessary otherwise the gtk2 interface wont compile
{$ELSE}
case nCmdShow of
SW_SHOWNORMAL:
begin
{$IFDEF DebugGDK}BeginGDKErrorTrap;{$ENDIF}
gdk_window_show(PgtkWidget(GtkWindow)^.Window);
{$IFDEF DebugGDKTraps}EndGDKErrorTrap;{$ENDIF}
end;
SW_HIDE:
begin
gdk_window_hide(PgtkWidget(GtkWindow)^.Window);
end;
SW_MINIMIZE:
begin
GDK_WINDOW_MINIMIZE(PGdkWindowPrivate(PgtkWidget(GtkWindow)^.Window));
end;
SW_SHOWMAXIMIZED:
begin
GDK_WINDOW_MAXIMIZE(PGdkWindowPrivate(PgtkWidget(GtkWindow)^.Window));
end;
end;
{$ENDIF}
Result:=true;
end;
{------------------------------------------------------------------------------
Function: StretchBlt
Params: DestDC: The destination devicecontext
X, Y: The left/top corner of the destination rectangle
Width, Height: The size of the destination rectangle
SrcDC: The source devicecontext
XSrc, YSrc: The left/top corner of the source rectangle
SrcWidth, SrcHeight: The size of the source rectangle
ROp: The raster operation to be performed
Returns: True if succesful
The StretchBlt function copies a bitmap from a source rectangle into a
destination rectangle using the specified raster operation. If needed it
resizes the bitmap to fit the dimensions of the destination rectangle.
Sizing is done according to the stretching mode currently set in the
destination device context.
If SrcDC contains a mask the pixmap will be copied with this transparency.
ToDo: Mirroring, extended NonDrawable support (Image, Bitmap, etc)
------------------------------------------------------------------------------}
function TGtkWidgetSet.StretchBlt(DestDC: HDC; X, Y, Width, Height: Integer;
SrcDC: HDC; XSrc, YSrc, SrcWidth, SrcHeight: Integer; ROp: Cardinal): Boolean;
begin
Result:=StretchCopyArea(DestDC,X,Y,Width,Height,
SrcDC,XSrc,YSrc,SrcWidth,SrcHeight,
0,0,0,
ROp);
end;
{------------------------------------------------------------------------------
Function: StretchMaskBlt
Params: DestDC: The destination devicecontext
X, Y: The left/top corner of the destination rectangle
Width, Height: The size of the destination rectangle
SrcDC: The source devicecontext
XSrc, YSrc: The left/top corner of the source rectangle
SrcWidth, SrcHeight: The size of the source rectangle
Mask: The handle of a monochrome bitmap
XMask, YMask: The left/top corner of the mask rectangle
ROp: The raster operation to be performed
Returns: True if succesful
The StretchMaskBlt function copies a bitmap from a source rectangle into a
destination rectangle using the specified mask and raster operation. If needed
it resizes the bitmap to fit the dimensions of the destination rectangle.
Sizing is done according to the stretching mode currently set in the
destination device context.
------------------------------------------------------------------------------}
function TGtkWidgetSet.StretchMaskBlt(DestDC: HDC; X, Y, Width, Height: Integer;
SrcDC: HDC; XSrc, YSrc, SrcWidth, SrcHeight: Integer; Mask: HBITMAP;
XMask, YMask: Integer; Rop: DWORD): Boolean;
begin
Result:=StretchCopyArea(DestDC,X,Y,Width,Height,
SrcDC,XSrc,YSrc,SrcWidth,SrcHeight,
Mask,XMask,YMask,
Rop);
end;
function TGTKWidgetSet.SystemParametersInfo(uiAction: DWord; uiParam: DWord;
pvParam: Pointer; fWinIni: DWord): LongBool;
begin
Result:=False;
Case uiAction of
SPI_GETWORKAREA: begin
TRect(pvParam^):=Bounds(GetSystemMetrics(SM_XVIRTUALSCREEN),
GetSystemMetrics(SM_YVIRTUALSCREEN),
GetSystemMetrics(SM_CXVIRTUALSCREEN),
GetSystemMetrics(SM_CYVIRTUALSCREEN));
Result:=True;
end;
end;
end;
{------------------------------------------------------------------------------
Function: TextOut
Params: DC:
X:
Y:
Str:
Count:
Returns:
------------------------------------------------------------------------------}
function TGtkWidgetSet.TextOut(DC: HDC; X,Y : Integer; Str : Pchar;
Count: Integer) : Boolean;
{$IfDef GTK2}
begin
DebugLn('TGtkWidgetSet.TextOut ToDo');
Result:=false;
end;
{$ELSE}
var
DevCtx: TGtkDeviceContext absolute DC;
aRect : TRect;
txtpt : TPoint;
sz : TSize;
UseFont : PGDKFont;
Underline,
StrikeOut : Boolean;
DCOrigin: TPoint;
TempPen : hPen;
LogP : TLogPen;
Points : array[0..1] of TSize;
lbearing, rbearing, width, ascent,descent: LongInt;
begin
if not IsValidDC(DC) then Exit(False);
if Count <= 0 then Exit(True);
UseFont := GetGtkFont(DevCtx);
if (DevCtx.CurrentFont = nil) or (DevCtx.CurrentFont^.GDIFontObject = nil)
then begin
Underline := False;
StrikeOut := False;
end
else begin
Underline := DevCtx.CurrentFont^.LogFont.lfUnderline <> 0;
StrikeOut := DevCtx.CurrentFont^.LogFont.lfStrikeOut <> 0;
end;
if DevCtx.HasTransf then
DevCtx.TransfPoint(X, Y);
DCOrigin := DevCtx.Offset;
descent:=0;
gdk_text_extents(UseFont, Str, Count, @lbearing, @rBearing, @width, @ascent, @descent);
sz.cx := width;
Sz.cY := ascent+descent;
aRect := Rect(X+DCOrigin.X,Y+DCOrigin.Y,X + Sz.CX, Sz.CY);
FillRect(DC, aRect, hBrush(PtrUInt(DevCtx.GetBrush)));
UpdateDCTextMetric(DevCtx);
TxtPt.X := X;
TxtPt.Y := Y + DevCtx.DCTextMetric.TextMetric.tmAscent;
DevCtx.SelectTextProps;
{$IFDEF DebugGDK}BeginGDKErrorTrap;{$ENDIF}
gdk_draw_text(DevCtx.Drawable, UseFont, DevCtx.GC, TxtPt.X+DCOrigin.X, TxtPt.Y+DCOrigin.Y, Str, Count);
{$IFDEF DebugGDKTraps}EndGDKErrorTrap;{$ENDIF}
if not(Underline or StrikeOut) then Exit(True);
{Create & select pen of font color}
LogP.lopnStyle := PS_SOLID;
LogP.lopnWidth.X := 1;
LogP.lopnColor := GetTextColor(DC);
TempPen := SelectObject(DC, CreatePenIndirect(LogP));
{Get line(s) horizontal position(s)}
Points[0].cX := X;
Points[1].cX := X + sz.cX;
{Draw line(s)}
if Underline
then begin
with DevCtx.DCTextMetric.TextMetric do
Points[0].cY := Y + 2 + tmHeight - tmDescent;
Points[1].cY := Points[0].cY;
Polyline(DC, PPoint(@Points[0]), 2);
end;
if StrikeOut
then begin
Points[0].cY := Y + 2 + (TxtPt.Y - Y) div 2;
Points[1].cY := Points[0].cY;
Polyline(DC, PPoint(@Points[0]), 2);
end;
DeleteObject(SelectObject(DC, TempPen));
Result := True;
end;
{$EndIf}
{------------------------------------------------------------------------------
Function: WindowFromPoint
Params: Point: Specifies the x and y Coords
Returns: The handle of the gtkwidget. If none exist, then NULL is returned.
------------------------------------------------------------------------------}
function TGtkWidgetSet.WindowFromPoint(APoint: TPoint): HWND;
var
ev: TgdkEvent;
Window: PgdkWindow;
Widget: PgtkWidget;
p: TPoint;
begin
// return cached value to prevent heavy gdk_window_at_pointer call
if (APoint = LastWFPMousePos) and GTK_IS_OBJECT(Pointer(LastWFPResult)) then
Exit(LastWFPResult);
Result := 0;
// !!!gdk_window_at_pointer changes the coordinates!!!
// -> using local variable p
p := APoint;
Window := gdk_window_at_pointer(@p.x, @p.Y);
if window <> nil then
begin
FillChar(ev, SizeOf(ev), 0);
ev.any.window := Window;
Widget := gtk_get_event_widget(@ev);
Result := PtrUInt(Widget);
end;
// disconnect old handler
if GTK_IS_OBJECT(Pointer(LastWFPResult)) then
begin
{$IFDEF gtk1}
gtk_signal_disconnect_by_func(GPointer(LastWFPResult),
TGTKSignalFunc(@DestroyWindowFromPointCB), nil);
{$ELSE}
g_signal_handlers_disconnect_by_func(GPointer(LastWFPResult),
TGTKSignalFunc(@DestroyWindowFromPointCB), nil);
{$ENDIF}
end;
LastWFPMousePos := APoint;
LastWFPResult := Result;
// connect handler
if LastWFPResult <> 0 then
{$IFDEF gtk1}
gtk_signal_connect(PGtkObject(LastWFPResult), 'destroy',
TGTKSignalFunc(@DestroyWindowFromPointCB), nil);
{$else}
g_signal_connect(GPointer(LastWFPResult), 'destroy',
TGTKSignalFunc(@DestroyWindowFromPointCB), nil);
{$endif}
end;
//##apiwiz##eps## // Do not remove
// Placed CriticalSectionSupport outside the API wizard bounds
// so it won't affect sorting etc.
{$IfNDef DisableCriticalSections}
{$IfDef Unix}
{$Define pthread}
{Type
_pthread_fastlock = packed record
__status: Longint;
__spinlock: Integer;
end;
pthread_mutex_t = packed record
__m_reserved: Integer;
__m_count: Integer;
__m_owner: Pointer;
__m_kind: Integer;
__m_lock: _pthread_fastlock;
end;
ppthread_mutex_t = ^pthread_mutex_t;
pthread_mutexattr_t = packed record
__mutexkind: Integer;
end;}
{$linklib pthread}
{function pthread_mutex_init(var Mutex: pthread_mutex_t;
var Attr: pthread_mutexattr_t): Integer; cdecl;external;
function pthread_mutexattr_settype(var Attr: pthread_mutexattr_t;
Kind: Integer): Integer; cdecl;external;
function pthread_mutex_lock(var Mutex: pthread_mutex_t):
Integer; cdecl; external;
function pthread_mutex_unlock(var Mutex: pthread_mutex_t):
Integer; cdecl; external;
function pthread_mutex_destroy(var Mutex: pthread_mutex_t):
Integer; cdecl; external;}
{$EndIf}
{$EndIf}
procedure TGtkWidgetSet.InitializeCriticalSection(var CritSection: TCriticalSection);
{$IfDef pthread}
var
ACritSec: System.PRTLCriticalSection;
begin
New(ACritSec);
System.InitCriticalSection(ACritSec^);
CritSection:=TCriticalSection(ACritSec);
end;
{var
Crit : ppthread_mutex_t;
Attribute: pthread_mutexattr_t;
begin
if pthread_mutexattr_settype(Attribute, 1) <> 0 then
Exit;
If CritSection <> 0 then
Try
Crit := ppthread_mutex_t(CritSection);
Dispose(Crit);
except
CritSection := 0;
end;
New(Crit);
pthread_mutex_init(Crit^, Attribute);
CritSection := Longint(Crit);
end;}
{$Else}
begin
end;
{$EndIf}
procedure TGtkWidgetSet.EnterCriticalSection(var CritSection: TCriticalSection);
{$IfDef pthread}
var
ACritSec: System.PRTLCriticalSection;
begin
ACritSec:=System.PRTLCriticalSection(CritSection);
System.EnterCriticalsection(ACritSec^);
end;
{var
Crit,
tmp : ppthread_mutex_t;
begin
New(Crit);
If CritSection <> 0 then
Try
Crit^ := ppthread_mutex_t(CritSection)^;
except
begin
CritSection := Longint(Crit);
exit;
end;
end;
pthread_mutex_lock(Crit^);
tmp := ppthread_mutex_t(CritSection);
CritSection := Longint(Crit);
Dispose(Tmp);
end;}
{$Else}
begin
end;
{$EndIf}
procedure TGtkWidgetSet.LeaveCriticalSection(var CritSection: TCriticalSection);
{$IfDef pthread}
var
ACritSec: System.PRTLCriticalSection;
begin
ACritSec:=System.PRTLCriticalSection(CritSection);
System.LeaveCriticalsection(ACritSec^);
end;
{var
Crit,
tmp : ppthread_mutex_t;
begin
New(Crit);
If CritSection <> 0 then
Try
Crit^ := ppthread_mutex_t(CritSection)^;
except
begin
CritSection := Longint(Crit);
exit;
end;
end;
pthread_mutex_unlock(Crit^);
tmp := ppthread_mutex_t(CritSection);
CritSection := Longint(Crit);
Dispose(Tmp);
end;}
{$Else}
begin
end;
{$EndIf}
procedure TGtkWidgetSet.DeleteCriticalSection(var CritSection: TCriticalSection);
{$IfDef pthread}
var
ACritSec: System.PRTLCriticalSection;
begin
ACritSec:=System.PRTLCriticalSection(CritSection);
System.DoneCriticalsection(ACritSec^);
Dispose(ACritSec);
CritSection:=0;
end;
{var
Crit,
tmp : ppthread_mutex_t;
begin
New(Crit);
If CritSection <> 0 then
Try
Crit^ := ppthread_mutex_t(CritSection)^;
except
begin
CritSection := Longint(Crit);
exit;
end;
end;
pthread_mutex_destroy(Crit^);
Dispose(Crit);
tmp := ppthread_mutex_t(CritSection);
CritSection := 0;
Dispose(Tmp);
end;}
{$Else}
begin
end;
{$EndIf}
{$IfDef ASSERT_IS_ON}
{$UNDEF ASSERT_IS_ON}
{$C-}
{$EndIf}
|