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
|
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <gtk/gtk.h>
#include <gtk/gtkinvisible.h>
#include <gdk/gdkkeysyms.h>
#if defined(_WIN32)
# include <gdk/gdkwin32.h>
#else
# include <gdk/gdkx.h>
# define HAVE_X
#endif
#if defined(__SOLARIS__) || defined(__hpux)
# include "../include/os.h"
#endif
#include "guiutils.h"
#include "images/icon_browse_20x20.xpm"
/*
* Root GdkWindow:
*/
static GdkWindow *gui_window_root = NULL;
/*
* Default GTK Style:
*/
static GtkStyle *gui_style_default = NULL;
/*
* GtkInvisible Toplevel Widget:
*
* For grabbing and blocking input in GUIBlockInput*().
*/
static GtkWidget *gui_invisible_blocker_widget = NULL;
static gint gui_block_input_level = 0;
/*
* DDE Owner Callback Data:
*/
typedef struct {
GtkWidget *w; /* Owner GtkWidget */
GdkAtom target_atom; /* GdkTarget */
GdkAtom type_atom; /* GdkSelectionType */
guint selection_clear_event_id,
selection_get_id;
gpointer data; /* Data (coppied) */
gint length; /* Data length in bytes */
} gui_dde_owner_struct;
#define GUI_DDE_OWNER(p) ((gui_dde_owner_struct *)(p))
#define GUI_DDE_OWNER_DATA_KEY "gui_dde_owner"
/*
* DND Callback Data:
*
* Used for callback data in GUIDND*CB() functions.
*/
typedef struct {
GdkDragAction default_action_same, /* Action to use if same widget */
default_action; /* Action for all other cases */
} gui_dnd_cb_struct;
#define GUI_DND_CB(p) ((gui_dnd_cb_struct *)(p))
/*
* DND Icon Widget:
*
* Initialized on first call to GUIDNDSetDragIcon() and used in
* GUIDNDDragBeginCB() and GUIDNDDragReceivedCB().
*/
typedef struct {
GtkWidget *toplevel,
*icon_pm;
gint x, /* Hot spot */
y,
width, /* Size */
height;
} gui_dnd_icon_struct;
#define GUI_DND_ICON(p) ((gui_dnd_icon_struct *)(p))
static gui_dnd_icon_struct gui_dnd_icon;
/*
* Banner Data:
*/
#define GUI_BANNER_DATA_KEY "gui_banner_data"
/*
* Button Data:
*
* For recording widgets on buttons and toggle buttons, stored as
* the object's user data.
*/
typedef struct {
GtkWidget *button, /* GtkButton */
*main_box, /* GtkBox */
*label, /* GtkLabel */
*pixmap, /* GtkPixmap */
*arrow; /* GtkArrow */
gchar *label_text; /* Copy of label text */
const guint8 **icon_data; /* Shared icon data */
GtkArrowType arrow_type;
} gui_button_data_struct;
#define GUI_BUTTON_DATA(p) ((gui_button_data_struct *)(p))
#define GUI_BUTTON_DATA_KEY "gui_button_data"
/*
* Pullout Data:
*/
#define GUI_PULLOUT_DATA_KEY "gui_pullout_data"
/*
* Combo Data:
*/
#define GUI_COMBO_DATA_KEY "gui_combo_data"
/*
* Menu Item Data:
*
* For recording widgets on menu items, stored as the object's
* user data.
*/
typedef struct {
GtkWidget *menu_item,
*label,
*accel_label,
*pixmap;
gchar *label_text, /* Copy of label text */
*accel_text; /* Copy of accel label text */
const guint8 **icon_data; /* Shared icon data */
guint accel_key,
accel_mods;
} gui_menu_item_data_struct;
#define GUI_MENU_ITEM_DATA(p) ((gui_menu_item_data_struct *)(p))
#define GUI_MENU_ITEM_DATA_KEY "gui_menu_item_data"
#define GUI_MENU_ITEM_CLIENT_DATA_KEY "gui_menu_item_client_data"
/*
* Tool Tips Group:
*
* Used as the tool tips group for all GUI*() functions.
*/
static GtkTooltips *gui_tooltips = NULL;
static gboolean gui_tooltips_state; /* Global enabled or disabled */
static gchar *GUIGetKeyName(guint key);
static void GUIDDEOwnerDestroyCB(gpointer data);
static gboolean GUIDDESelectionClearEventCB(
GtkWidget *widget, GdkEventSelection *event, gpointer data
);
static void GUIDDESelectionGetCB(
GtkWidget *widget, GtkSelectionData *selection_data,
guint info, guint t, gpointer data
);
static void GUIDDESelectionReceivedCB(
GtkWidget *widget, GtkSelectionData *selection_data, guint t,
gpointer data
);
static void GUIDNDDragBeginCB(
GtkWidget *widget, GdkDragContext *dc, gpointer data
);
static gboolean GUIDNDDragMotionCB(
GtkWidget *widget, GdkDragContext *dc,
gint x, gint y, guint t,
gpointer data
);
static gboolean GUIDNDDragDropCB(
GtkWidget *widget, GdkDragContext *dc,
gint x, gint y, guint t,
gpointer data
);
static void GUIDNDDragReceivedCB(
GtkWidget *widget, GdkDragContext *dc,
gint x, gint y,
GtkSelectionData *selection_data, guint info, guint t,
gpointer data
);
static void GUIDNDDragEndCB(
GtkWidget *widget, GdkDragContext *dc,
gpointer data
);
static void GUIButtonDataDestroyCB(gpointer data);
static gint GUIBannerEventCB(
GtkWidget *widget, GdkEvent *event, gpointer data
);
static void GUIBannerDataDestroyCB(gpointer data);
static void GUIComboActivateCB(GtkWidget *widget, gpointer data);
static void GUIComboChangedCB(GtkWidget *widget, gpointer data);
static void GUIComboDataDestroyCB(gpointer data);
static void GUIMenuActivateCB(gpointer data);
static void GUIMenuClientDataDestroyCB(gpointer data);
static void GUIMenuDataDestroyCB(gpointer data);
static void GUIPullOutDataDestroyCB(gpointer data);
static void GUIPullOutDrawHandleDrawCB(
GtkWidget *widget, GdkRectangle *area, gpointer data
);
static gint GUIPullOutDrawHandleCB(
GtkWidget *widget, GdkEvent *event, gpointer data
);
static gint GUIPullOutPullOutBtnCB(
GtkWidget *widget, GdkEvent *event, gpointer data
);
static gint GUIPullOutCloseCB(GtkWidget *widget, GdkEvent *event, gpointer data);
/* GtkRcStyle Utilities */
GtkRcStyle *GUIRCStyleCopy(const GtkRcStyle *rcstyle);
void GUIRCStyleSetRecursive(GtkWidget *w, GtkRcStyle *rcstyle);
/* Geometry */
GdkGeometryFlags GUIParseGeometry(
const gchar *s,
gint *x, gint *y, gint *width, gint *height
);
gboolean GUICListGetCellGeometry(
GtkCList *clist, const gint column, const gint row,
gint *x, gint *y, gint *width, gint *height
);
gint GUICTreeNodeRow(GtkCTree *ctree, GtkCTreeNode *node);
static void GUICTreeNodeDeltaRowsIterate(
GtkCTree *ctree, GtkCTreeNode *node, GtkCTreeNode *end,
gint *row_count, gboolean *end_found
);
gint GUICTreeNodeDeltaRows(
GtkCTree *ctree,
GtkCTreeNode *start, /* Use NULL for first/toplevel node */
GtkCTreeNode *end
);
void GUIGetWindowRootPosition(
GdkWindow *window, gint *x, gint *y
);
void GUIGetPositionRoot(
GdkWindow *w, gint x, gint y, gint *rx, gint *ry
);
/* String Utilities */
void GUIGetTextBounds(
GdkFont *font, const gchar *text, const gint text_length,
GdkTextBounds *bounds
);
void GUIGetStringBounds(
GdkFont *font, const gchar *string,
GdkTextBounds *bounds
);
/* GdkGC Utilities */
GdkGC *GDK_GC_NEW(void);
/* Block Input */
void GUIBlockInput(GtkWidget *w, const gboolean block);
gint GUIBlockInputGetLevel(void);
/* GdkWindow utilities */
gint GUIWindowGetRefCount(GdkWindow *window);
/* WM Utilities */
void GUISetWMIcon(GdkWindow *window, guint8 **data);
void GUISetWMIconFile(GdkWindow *window, const gchar *filename);
/* GtkWindow Utilities */
void GUIWindowApplyArgs(GtkWindow *w, gint argc, gchar **argv);
gboolean GUIIsWindowArg(const gchar *arg);
/* GtkCTree Utilities */
gboolean GUICTreeOptimizeExpandPosition(
GtkCTree *ctree,
GtkCTreeNode *node
);
/* GdkBitmap */
GdkBitmap *GUICreateBitmapFromDataRGBA(
gint width, gint height, gint bpl,
const guint8 *rgba, guint8 threshold,
GdkWindow *window
);
/* Pixmap Utilities */
GdkPixmap *GDK_PIXMAP_NEW(gint width, gint height);
GdkPixmap *GDK_PIXMAP_NEW_FROM_XPM_DATA(
GdkBitmap **mask_rtn, guint8 **data
);
GdkPixmap *GDK_PIXMAP_NEW_FROM_XPM_FILE(
GdkBitmap **mask_rtn, const gchar *filename
);
GtkWidget *gtk_pixmap_new_from_xpm_d(
GdkWindow *window, GdkColor *transparent_color,
guint8 **data
);
GtkWidget *GUICreateMenuItemIcon(guint8 **icon_data);
/* Widget & Window Mapping */
void GUIWidgetMapRaise(GtkWidget *w);
void GUIWindowMinimize(GtkWindow *window);
/* Tool Tips */
static void GUICreateGlobalTooltips(void);
void GUISetWidgetTip(GtkWidget *w, const gchar *tip);
void GUIShowTipsNow(GtkWidget *w);
void GUISetGlobalTipsState(gboolean state);
/* Buttons With Icon & Label */
void GUIButtonChangeLayout(
GtkWidget *w, gboolean show_pixmap, gboolean show_label
);
void GUIButtonLabelUnderline(GtkWidget *w, guint c);
void GUIButtonPixmapUpdate(
GtkWidget *w, guint8 **icon, const gchar *label
);
void GUIButtonArrowUpdate(
GtkWidget *w,
GtkArrowType arrow_type, gint arrow_width, gint arrow_height,
const gchar *label
);
GtkWidget *GUIButtonGetMainBox(GtkWidget *w);
GtkWidget *GUIButtonGetLabel(GtkWidget *w);
GtkWidget *GUIButtonGetPixmap(GtkWidget *w);
GtkWidget *GUIButtonGetArrow(GtkWidget *w);
gchar *GUIButtonGetLabelText(GtkWidget *w);
static GtkWidget *GUIButtonPixmapLabelHV(
guint8 **icon, const gchar *label, GtkWidget **label_rtn,
gboolean horizontal
);
GtkWidget *GUIButtonPixmapLabelH(
guint8 **icon, const gchar *label, GtkWidget **label_rtn
);
GtkWidget *GUIButtonPixmapLabelV(
guint8 **icon, const gchar *label, GtkWidget **label_rtn
);
GtkWidget *GUIButtonPixmap(guint8 **icon);
/* Buttons With Arrow & Label */
static GtkWidget *GUIButtonArrowLabelHV(
GtkArrowType arrow_type, gint arrow_width, gint arrow_height,
const gchar *label, GtkWidget **label_rtn,
gboolean horizontal
);
GtkWidget *GUIButtonArrowLabelH(
GtkArrowType arrow_type, gint arrow_width, gint arrow_height,
const gchar *label, GtkWidget **label_rtn
);
GtkWidget *GUIButtonArrowLabelV(
GtkArrowType arrow_type, gint arrow_width, gint arrow_height,
const gchar *label, GtkWidget **label_rtn
);
GtkWidget *GUIButtonArrow(
GtkArrowType arrow_type, gint arrow_width, gint arrow_height
);
/* Toggle Buttons With Icon & Label */
static GtkWidget *GUIToggleButtonPixmapLabelHV(
guint8 **icon, const gchar *label, GtkWidget **label_rtn,
gboolean horizontal
);
GtkWidget *GUIToggleButtonPixmapLabelH(
guint8 **icon, const gchar *label, GtkWidget **label_rtn
);
GtkWidget *GUIToggleButtonPixmapLabelV(
guint8 **icon, const gchar *label, GtkWidget **label_rtn
);
GtkWidget *GUIToggleButtonPixmap(guint8 **icon);
/* Prompts With Icon, Label, Entry, and Browse */
static GtkWidget *GUIPromptBarOrBrowse(
guint8 **icon, const gchar *label,
gpointer *label_rtn, gpointer *entry_rtn, gpointer *browse_rtn
);
GtkWidget *GUIPromptBarWithBrowse(
guint8 **icon, const gchar *label,
gpointer *label_rtn, gpointer *entry_rtn, gpointer *browse_rtn,
gpointer browse_data, void (*browse_cb)(GtkWidget *, gpointer)
);
GtkWidget *GUIPromptBar(
guint8 **icon, const gchar *label,
gpointer *label_rtn, gpointer *entry_rtn
);
/* Dynamic Data Exchange */
void GUIDDESetBinary(
GtkWidget *w, /* Owner widget */
GdkAtom selection_atom, /* Can be GDK_NONE */
gulong t, /* Time */
const guint8 *data, gint length
);
guint8 *GUIDDEGetBinary(
GtkWidget *w, /* Widget making request */
GdkAtom selection_atom, /* Can be GDK_NONE */
gulong t, /* Time */
gint *length
);
void GUIDDESetString(
GtkWidget *w, /* Owner widget */
GdkAtom selection_atom, /* Can be GDK_NONE */
gulong t, /* Time */
const gchar *data
);
gchar *GUIDDEGetString(
GtkWidget *w, /* Widget making request */
GdkAtom selection_atom, /* Can be GDK_NONE */
gulong t /* Time */
);
/* Drag & Drop Utilities */
void GUIDNDSetSrc(
void *w, const void *drag_type, int ndrag_types,
unsigned int actions, unsigned int buttons,
void (*begin_cb)(GtkWidget *, GdkDragContext *, gpointer),
void (*request_data_cb)(GtkWidget *, GdkDragContext *,
GtkSelectionData *, guint, guint, gpointer),
void (*delete_data_cb)(GtkWidget *, GdkDragContext *, gpointer),
void (*end_cb)(GtkWidget *, GdkDragContext *, gpointer),
gpointer client_data
);
void GUIDNDSetTar(
void *w, const void *drag_type, int ndrag_types,
unsigned int actions, unsigned int default_action_same,
unsigned int default_action,
void (*recieved_data_cb)(GtkWidget *, GdkDragContext *,
gint, gint, GtkSelectionData *, guint, guint,
gpointer
),
gpointer client_data
);
void GUIDNDSetDragIcon(
GdkPixmap *pixmap, GdkBitmap *mask, gint hot_x, gint hot_y
);
/* Banners */
GtkWidget *GUIBannerCreate(
const gchar *label,
const gchar *font_name,
GdkColor color_fg,
GdkColor color_bg,
GtkJustification justify, /* One of GTK_JUSTIFY_* */
gboolean expand
);
void GUIBannerDraw(GtkWidget *w);
/* Combo With Label, Combo, Initial Value, and Initial List */
GtkWidget *GUIComboCreate(
const gchar *label, /* Label */
const gchar *text, /* Entry Value */
GList *list, /* Combo List */
gint max_items, /* Maximum Items In Combo List */
gpointer *combo_rtn, /* GtkCombo Return */
gpointer data,
void (*func_cb)(GtkWidget *w, gpointer),
void (*list_change_cb)(GtkWidget *, gpointer, GList *)
);
void GUIComboActivateValue(GtkWidget *w, const gchar *value);
void GUIComboAddItem(GtkWidget *w, const gchar *value);
GList *GUIComboGetList(GtkWidget *w);
void GUIComboSetList(GtkWidget *w, GList *list);
void GUIComboClearAll(GtkWidget *w);
/* Menu Bar & Menu Item */
GtkWidget *GUIMenuBarCreate(GtkAccelGroup **accelgrp_rtn);
GtkWidget *GUIMenuCreateTearOff(void);
GtkWidget *GUIMenuCreate(void);
GtkWidget *GUIMenuItemCreate(
GtkWidget *menu,
gui_menu_item_type type, /* One of GUI_MENU_ITEM_TYPE_* */
GtkAccelGroup *accelgrp,
guint8 **icon, const gchar *label,
guint accel_key, guint accel_mods,
gpointer *functional_widget_rtn,
gpointer data,
void (*func_cb)(GtkWidget *w, gpointer)
);
void GUISetMenuItemDefault(GtkWidget *w);
void GUISetMenuItemCrossingCB(
GtkWidget *w,
gint (*enter_cb)(GtkWidget *, GdkEvent *, gpointer),
gpointer enter_data,
gint (*leave_cb)(GtkWidget *, GdkEvent *, gpointer),
gpointer leave_data
);
GtkWidget *GUIMenuAddToMenuBar(
GtkWidget *menu_bar, GtkWidget *menu,
const gchar *label,
gui_menu_bar_item_alignment align
);
void GUIMenuItemSetLabel(GtkWidget *menu_item, const gchar *label);
void GUIMenuItemSetPixmap(GtkWidget *menu_item, guint8 **icon_data);
void GUIMenuItemSetAccelKey(
GtkWidget *menu_item, GtkAccelGroup *accelgrp,
guint accel_key, guint accel_mods
);
void GUIMenuItemSetCheck(
GtkWidget *menu_item, gboolean active, gboolean emit
);
gboolean GUIMenuItemGetCheck(GtkWidget *menu_item);
GtkWidget *GUIMenuAddToMenuBarPixmapH(
GtkWidget *menu_bar, GtkWidget *menu,
const gchar *label, guint8 **icon_data,
gui_menu_bar_item_alignment align
);
void GUIMenuItemSetSubMenu(
GtkWidget *menu_item, GtkWidget *sub_menu
);
/* Pull Out Window */
void *GUIPullOutCreateH(
void *parent_box,
int homogeneous, int spacing, /* Of client vbox */
int expand, int fill, int padding, /* Of holder hbox */
int toplevel_width, int toplevel_height,
void *pull_out_client_data,
void (*pull_out_cb)(void *, void *),
void *push_in_client_data,
void (*push_in_cb)(void *, void *)
);
void *GUIPullOutGetToplevelWindow(
void *client_box,
int *x, int *y, int *width, int *height
);
void GUIPullOutPullOut(void *client_box);
void GUIPullOutPushIn(void *client_box);
#ifndef ISBLANK
# define ISBLANK(c) (((c) == ' ') || ((c) == '\t'))
#endif
#define ATOI(s) (((s) != NULL) ? atoi(s) : 0)
#define ATOL(s) (((s) != NULL) ? atol(s) : 0)
#define ATOF(s) (((s) != NULL) ? atof(s) : 0.0f)
#define STRDUP(s) (((s) != NULL) ? g_strdup(s) : NULL)
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
#define CLIP(a,l,h) (MIN(MAX((a),(l)),(h)))
#define STRLEN(s) (((s) != NULL) ? strlen(s) : 0)
#define STRISEMPTY(s) (((s) != NULL) ? (*(s) == '\0') : TRUE)
static gchar *G_STRCAT(gchar *s, const gchar *s2)
{
if(s != NULL) {
if(s2 != NULL) {
gchar *sr = g_strconcat(s, s2, NULL);
g_free(s);
s = sr;
}
} else {
if(s2 != NULL)
s = STRDUP(s2);
else
s = STRDUP("");
}
return(s);
}
/*
* Returns a statically allocated string describing the specified
* key.
*/
static gchar *GUIGetKeyName(guint key)
{
switch(key)
{
case GDK_BackSpace:
return("BackSpace");
case GDK_Tab:
return("Tab");
case GDK_Linefeed:
return("LineFeed");
case GDK_Clear:
return("Clear");
case GDK_Return:
return("Return");
case GDK_Pause:
return("Pause");
case GDK_Scroll_Lock:
return("ScrollLock");
case GDK_Sys_Req:
return("SysReq");
case GDK_Escape:
return("Escape");
case GDK_space:
return("Space");
case GDK_Delete:
return("Delete");
case GDK_Home:
return("Home");
case GDK_Left:
return("Left");
case GDK_Right:
return("Right");
case GDK_Down:
return("Down");
case GDK_Up:
return("Up");
case GDK_Page_Up:
return("PageUp");
case GDK_Page_Down:
return("PageDown");
case GDK_End:
return("End");
case GDK_Begin:
return("Begin");
case GDK_Select:
return("Select");
case GDK_Print:
return("Print");
case GDK_Execute:
return("Execute");
case GDK_Insert:
return("Insert");
case GDK_Undo:
return("Undo");
case GDK_Redo:
return("Redo");
case GDK_Menu:
return("Menu");
case GDK_Find:
return("Find");
case GDK_Cancel:
return("Cancel");
case GDK_Help:
return("Help");
case GDK_Break:
return("Break");
case GDK_Num_Lock:
return("NumLock");
case GDK_KP_Space:
return("KPSpace");
case GDK_KP_Tab:
return("KBTab");
case GDK_KP_Enter:
return("KPEnter");
case GDK_KP_F1:
return("KPF1");
case GDK_KP_F2:
return("KPF2");
case GDK_KP_F3:
return("KPF3");
case GDK_KP_F4:
return("KPF4");
case GDK_KP_Home:
return("KPHome");
case GDK_KP_Left:
return("KPLeft");
case GDK_KP_Up:
return("KPUp");
case GDK_KP_Right:
return("KPRight");
case GDK_KP_Down:
return("KPDown");
case GDK_KP_Page_Up:
return("KPPageUp");
case GDK_KP_Page_Down:
return("KPPageDown");
case GDK_KP_End:
return("KPEnd");
case GDK_KP_Begin:
return("KPBegin");
case GDK_KP_Insert:
return("KPInsert");
case GDK_KP_Delete:
return("KPDelete");
case GDK_KP_Equal:
return("KPEqual");
case GDK_KP_Multiply:
return("KPMultiply");
case GDK_KP_Add:
return("KPAdd");
case GDK_KP_Separator:
return("KPSeparator");
case GDK_KP_Subtract:
return("KPSubtract");
case GDK_KP_Decimal:
return("KPDecimal");
case GDK_KP_Divide:
return("KPDivide");
case GDK_KP_0:
return("KP0");
case GDK_KP_1:
return("KP1");
case GDK_KP_2:
return("KP2");
case GDK_KP_3:
return("KP3");
case GDK_KP_4:
return("KP4");
case GDK_KP_5:
return("KP5");
case GDK_KP_6:
return("KP6");
case GDK_KP_7:
return("KP7");
case GDK_KP_8:
return("KP8");
case GDK_KP_9:
return("KP9");
case GDK_F1:
return("F1");
case GDK_F2:
return("F2");
case GDK_F3:
return("F3");
case GDK_F4:
return("F4");
case GDK_F5:
return("F5");
case GDK_F6:
return("F6");
case GDK_F7:
return("F7");
case GDK_F8:
return("F8");
case GDK_F9:
return("F9");
case GDK_F10:
return("F10");
case GDK_F11:
return("F11");
case GDK_F12:
return("F12");
case GDK_F13:
return("F13");
case GDK_F14:
return("F14");
case GDK_F15:
return("F15");
case GDK_F16:
return("F16");
case GDK_F17:
return("F17");
case GDK_F18:
return("F18");
case GDK_F19:
return("F19");
case GDK_F20:
return("F20");
case GDK_F21:
return("F21");
case GDK_F22:
return("F22");
case GDK_F23:
return("F23");
case GDK_F24:
return("F24");
case GDK_F25:
return("F25");
case GDK_F26:
return("F26");
case GDK_F27:
return("F27");
case GDK_F28:
return("F28");
case GDK_F29:
return("F29");
case GDK_F30:
return("F30");
case GDK_Shift_L:
return("ShiftL");
case GDK_Shift_R:
return("ShiftR");
case GDK_Control_L:
return("ControlL");
case GDK_Control_R:
return("ControlR");
case GDK_Caps_Lock:
return("CapsLock");
case GDK_Shift_Lock:
return("ShiftLock");
case GDK_Meta_L:
return("MetaL");
case GDK_Meta_R:
return("MetaR");
case GDK_Alt_L:
return("AltL");
case GDK_Alt_R:
return("AltR");
case GDK_Super_L:
return("SuperL");
case GDK_Super_R:
return("SuperR");
case GDK_Hyper_L:
return("HyperL");
case GDK_Hyper_R:
return("HyperR");
default:
return("");
}
}
/*
* DDE Owner data "destroy" signal callback.
*/
static void GUIDDEOwnerDestroyCB(gpointer data)
{
GtkWidget *w;
gui_dde_owner_struct *owner = GUI_DDE_OWNER(data);
if(owner == NULL)
return;
w = owner->w;
g_free(owner->data);
owner->data = NULL;
owner->length = 0;
GTK_SIGNAL_DISCONNECT(w, owner->selection_clear_event_id)
GTK_SIGNAL_DISCONNECT(w, owner->selection_get_id)
g_free(owner);
}
/*
* DDE GtkWidget "selection_clear_event" signal callback.
*/
static gboolean GUIDDESelectionClearEventCB(
GtkWidget *widget, GdkEventSelection *event, gpointer data
)
{
gui_dde_owner_struct *owner = GUI_DDE_OWNER(data);
if((widget == NULL) || (event == NULL) || (owner == NULL))
return(FALSE);
/* Remove owner data and disconnect signals since this widget
* is no longer responsible for sending out DDE data
*/
gtk_object_remove_data(
GTK_OBJECT(widget), GUI_DDE_OWNER_DATA_KEY
);
return(TRUE);
}
/*
* DDE GtkWidget "selection_get" signal callback.
*/
static void GUIDDESelectionGetCB(
GtkWidget *widget, GtkSelectionData *selection_data,
guint info, guint t, gpointer data
)
{
GdkAtom target;
gui_dde_owner_struct *owner = GUI_DDE_OWNER(data);
if((widget == NULL) || (selection_data == NULL) ||
(owner == NULL)
)
return;
/* Handle by owner's selection target type */
target = owner->target_atom;
/* GdkBitmap */
if(target == GDK_TARGET_BITMAP)
{
/* TODO */
}
/* GdkColormap */
else if(target == GDK_TARGET_COLORMAP)
{
/* TODO */
}
/* GdkDrawable */
else if(target == GDK_TARGET_DRAWABLE)
{
/* TODO */
}
/* GdkPixmap */
else if(target == GDK_TARGET_PIXMAP)
{
/* TODO */
}
/* String (latin-1 characters) */
else if(target == GDK_TARGET_STRING)
{
gtk_selection_data_set(
selection_data,
owner->type_atom,
8,
owner->data,
owner->length
);
}
}
/*
* DDE GtkWidget "selection_received" signal callback.
*/
static void GUIDDESelectionReceivedCB(
GtkWidget *widget, GtkSelectionData *selection_data, guint t,
gpointer data
)
{
GdkAtom type;
GtkSelectionData *sel_rtn = (GtkSelectionData *)data;
if((widget == NULL) || (selection_data == NULL) ||
(sel_rtn == NULL)
)
return;
/* Already got data? */
if(sel_rtn->data != NULL)
return;
/* Mark that the selection was received on the callback data */
sel_rtn->length = 0;
/* No data? */
if((selection_data->data == NULL) ||
(selection_data->length <= 0)
)
return;
/* Begin handling selection data by its type */
sel_rtn->type = type = selection_data->type;
/* Atoms List */
if(type == GDK_SELECTION_TYPE_ATOM)
{
gchar *s = NULL;
gint i, m = selection_data->length / sizeof(GdkAtom);
gchar *name;
GdkAtom *atoms = (GdkAtom *)selection_data->data;
for(i = 0; i < m; i++)
{
name = gdk_atom_name(atoms[i]);
if(name != NULL)
{
s = G_STRCAT(s, name);
if(i < (m - 1))
s = G_STRCAT(s, " ");
g_free(name);
}
}
sel_rtn->data = s;
sel_rtn->length = STRLEN(s);
/* Change the return type to string */
sel_rtn->type = GDK_SELECTION_TYPE_STRING;
}
/* GdkBitmap */
else if(type == GDK_SELECTION_TYPE_BITMAP)
{
/* TODO */
}
/* GdkColormap */
else if(type == GDK_SELECTION_TYPE_COLORMAP)
{
/* TODO */
}
/* GdkDrawable */
else if(type == GDK_SELECTION_TYPE_DRAWABLE)
{
/* TODO */
}
/* Integer */
else if(type == GDK_SELECTION_TYPE_INTEGER)
{
gint len = sel_rtn->length = selection_data->length;
sel_rtn->data = g_malloc(len);
memcpy(sel_rtn->data, selection_data->data, len);
}
/* GdkPixmap */
else if(type == GDK_SELECTION_TYPE_PIXMAP)
{
/* TODO */
}
/* GdkWindow */
else if(type == GDK_SELECTION_TYPE_WINDOW)
{
/* TODO */
}
/* String (latin-1 characters) */
else if(type == GDK_SELECTION_TYPE_STRING)
{
gint len = sel_rtn->length = selection_data->length;
gchar *s = (gchar *)g_malloc(len + 1);
memcpy(s, selection_data->data, len);
s[len] = '\0';
sel_rtn->data = s;
}
}
/*
* DND drag begin callback, this function is called at the start
* of a drag.
*
* The given data is always NULL for now.
*/
static void GUIDNDDragBeginCB(
GtkWidget *widget, GdkDragContext *dc, gpointer data
)
{
gui_dnd_icon_struct *dnd_icon = &gui_dnd_icon;
if((widget == NULL) || (dc == NULL))
return;
/* Set the DND Icon if it is available */
if(dnd_icon->toplevel != NULL)
gtk_drag_set_icon_widget(
dc,
dnd_icon->toplevel,
dnd_icon->x,
dnd_icon->y
);
/* Stop the signal so that other callbacks do not override
* what we have set here
*/
gtk_signal_emit_stop_by_name(
GTK_OBJECT(widget), "drag_begin"
);
}
/*
* DND drag motion callback, this function will basically
* handle the change of default action on the given destination
* widget.
*
* The given data is assumed to be a gui_dnd_cb_struct *.
*/
static gboolean GUIDNDDragMotionCB(
GtkWidget *widget, GdkDragContext *dc,
gint x, gint y, guint t,
gpointer data
)
{
gboolean same_widget;
GtkWidget *src_widget, *tar_widget;
GdkDragAction action;
gui_dnd_cb_struct *cb_data = GUI_DND_CB(data);
if((dc == NULL) || (cb_data == NULL))
return(FALSE);
/* Get source widget and target widgets */
src_widget = gtk_drag_get_source_widget(dc);
tar_widget = widget;
/* Set marker for if the source and target widgets are the same */
same_widget = (src_widget == tar_widget) ? TRUE : FALSE;
/* Get default action from cb_data structure, if source and
* target are the same widget then use default_action_same
* otherwise use default_action
*/
action = same_widget ?
cb_data->default_action_same : cb_data->default_action;
/* Respond with default drag action (status)
*
* First we check the dc's list of actions, if the list only
* contains move or copy then we select just that, otherwise
* we return with our default suggested action
*
* If no valid actions are listed then we respond with 0
*/
/* Only move? */
if(dc->actions == GDK_ACTION_MOVE)
gdk_drag_status(dc, GDK_ACTION_MOVE, t);
/* Only copy? */
else if(dc->actions == GDK_ACTION_COPY)
gdk_drag_status(dc, GDK_ACTION_COPY, t);
/* Only link? */
else if(dc->actions == GDK_ACTION_LINK)
gdk_drag_status(dc, GDK_ACTION_LINK, t);
/* Other action, check if listed in our actions list? */
else if(dc->actions & action)
gdk_drag_status(dc, action, t);
/* All else respond with 0 */
else
gdk_drag_status(dc, 0, t);
/* Is target widget valid and sensitive? */
if((tar_widget != NULL) ? GTK_WIDGET_SENSITIVE(tar_widget) : FALSE)
{
#if 0
/* Do not set this, causes focusing problems after DND */
/* Set target widget into focus as needed */
if(!GTK_WIDGET_HAS_FOCUS(tar_widget) &&
GTK_WIDGET_CAN_FOCUS(tar_widget)
)
gtk_widget_grab_focus(tar_widget);
#endif
/* Handle rest by the target widget's type */
/* Target widget is a GtkCTree? */
if(GTK_IS_CTREE(tar_widget))
{
/* Reference it as a GtkCList */
GtkCList *clist = (GtkCList *)tar_widget;
gint row, column;
/* Update flags as needed */
clist->flags |= GTK_CLIST_DRAW_DRAG_LINE;
clist->flags |= GTK_CLIST_DRAW_DRAG_RECT;
/* Calculate column row from x and y coordinates */
if(!gtk_clist_get_selection_info(
clist,
x,
y - ((clist->flags & GTK_CLIST_SHOW_TITLES) ?
clist->column_title_area.height +
clist->column_title_area.y : 0),
&row, &column
))
{
row = -1;
column = -1;
}
#if 0
i = 0;
glist = clist->row_list;
while(glist != NULL)
{
if(i == row)
{
row_ptr = (GtkCListRow *)glist->data;
break;
}
i++;
glist = g_list_next(glist);
}
if(row_ptr != NULL)
gtk_signal_emit_by_name(
GTK_OBJECT(tar_widget), "draw_drag_highlight",
row_ptr,
row,
GTK_CLIST_DRAG_INTO
);
#endif
/* Change in drag position? */
if(row != clist->focus_row)
{
clist->focus_row = row;
gtk_widget_queue_draw(tar_widget);
}
}
/* Target widget is a GtkCList? */
else if(GTK_IS_CLIST(tar_widget))
{
GtkCList *clist = (GtkCList *)tar_widget;
gint row, column;
/* Update flags as needed */
clist->flags |= GTK_CLIST_DRAW_DRAG_LINE;
clist->flags |= GTK_CLIST_DRAW_DRAG_RECT;
/* Calculate column row from x and y coordinates */
if(!gtk_clist_get_selection_info(
clist,
x,
y - ((clist->flags & GTK_CLIST_SHOW_TITLES) ?
clist->column_title_area.height +
clist->column_title_area.y : 0),
&row, &column
))
{
row = -1;
column = -1;
}
/* Change in drag position? */
if(row != clist->focus_row)
{
clist->focus_row = row;
gtk_widget_queue_draw(tar_widget);
}
}
}
return(FALSE);
}
/*
* DND drag drop callback.
*
* The given data is assumed to be a gui_dnd_cb_struct *.
*/
static gboolean GUIDNDDragDropCB(
GtkWidget *widget, GdkDragContext *dc,
gint x, gint y, guint t,
gpointer data
)
{
gui_dnd_cb_struct *cb_data = GUI_DND_CB(data);
if((dc == NULL) || (cb_data == NULL))
return(FALSE);
return(FALSE);
}
/*
* DND drag data received callback.
*
* The given data is assumed to be a gui_dnd_cb_struct *.
*/
static void GUIDNDDragReceivedCB(
GtkWidget *widget, GdkDragContext *dc,
gint x, gint y,
GtkSelectionData *selection_data, guint info, guint t,
gpointer data
)
{
gui_dnd_cb_struct *cb_data = GUI_DND_CB(data);
if((dc == NULL) || (cb_data == NULL))
return;
}
/*
* DND drag end callback, this function will reset the target
* widget as needed and clean up any additional resources.
*
* The given data is always NULL for now.
*/
static void GUIDNDDragEndCB(
GtkWidget *widget, GdkDragContext *dc, gpointer data
)
{
gboolean same_widget;
GtkWidget *src_widget, *tar_widget;
if(dc == NULL)
return;
/* Get source widget and target widgets */
src_widget = gtk_drag_get_source_widget(dc);
tar_widget = widget;
/* Set marker for if the source and target widgets are the same */
same_widget = (src_widget == tar_widget) ? TRUE : FALSE;
/* Is target widget valid and sensitive? */
if((tar_widget != NULL) ? GTK_WIDGET_SENSITIVE(tar_widget) : FALSE)
{
/* Handle rest by the target widget's type */
/* Is target widget a ctree? */
if(GTK_IS_CTREE(tar_widget))
{
GtkCList *clist = GTK_CLIST(tar_widget);
clist->flags &= ~GTK_CLIST_DRAW_DRAG_LINE;
clist->flags &= ~GTK_CLIST_DRAW_DRAG_RECT;
gtk_widget_queue_draw(tar_widget);
}
/* Is target widget a clist? */
else if(GTK_IS_CLIST(tar_widget))
{
GtkCList *clist = GTK_CLIST(tar_widget);
clist->flags &= ~GTK_CLIST_DRAW_DRAG_LINE;
clist->flags &= ~GTK_CLIST_DRAW_DRAG_RECT;
gtk_widget_queue_draw(tar_widget);
}
}
}
/*
* Button data destroy callback.
*/
static void GUIButtonDataDestroyCB(gpointer data)
{
gui_button_data_struct *btn_data = GUI_BUTTON_DATA(data);
if(btn_data == NULL)
return;
g_free(btn_data->label_text);
g_free(btn_data);
}
/*
* Banner event signal callback.
*/
static gint GUIBannerEventCB(
GtkWidget *widget, GdkEvent *event, gpointer data
)
{
gint status = FALSE;
const gchar *label;
GdkFont *font;
GtkJustification justify;
GdkEventConfigure *configure;
GdkEventExpose *expose;
gpointer *cb_data = (gpointer *)data;
if((widget == NULL) || (event == NULL) || (cb_data == NULL))
return(status);
label = (const gchar *)cb_data[0];
justify = (GtkJustification)cb_data[1];
font = (GdkFont *)cb_data[2];
switch((gint)event->type)
{
case GDK_CONFIGURE:
configure = (GdkEventConfigure *)event;
status = TRUE;
break;
case GDK_EXPOSE:
expose = (GdkEventExpose *)event;
GUIBannerDraw(widget);
status = TRUE;
break;
}
return(status);
}
/*
* Banner data destroy callback.
*/
static void GUIBannerDataDestroyCB(gpointer data)
{
gchar *label;
GtkJustification justify;
GdkFont *font;
gpointer *cb_data = (gpointer *)data;
if(cb_data == NULL)
return;
label = (gchar *)cb_data[0];
justify = (GtkJustification)cb_data[1];
font = (GdkFont *)cb_data[2];
g_free(label);
GDK_FONT_UNREF(font)
g_free(cb_data);
}
/*
* GtkCombo "activate" signal callback.
*
* First it will update the glist for the combo box and update
* the the combo's list. Then call (if not NULL) the specified
* activate callback function.
*/
static void GUIComboActivateCB(GtkWidget *widget, gpointer data)
{
gint max_items;
GtkWidget *parent, *wlabel;
GtkCombo *combo;
GList *glist_in;
gpointer client_data;
void (*func_cb)(GtkWidget *, gpointer);
void (*list_change_cb)(GtkWidget *, gpointer, GList *);
gchar *new_value;
gpointer *cb_data = (gpointer *)data;
if((widget == NULL) || (cb_data == NULL))
return;
/* Parse callback data, format is:
*
* table Parent table that holds combo and label
* label Label (may be NULL)
* combo This combo widget
* GList Contains list of strings in combo list
* max_items Max items allowed in combo list
* client_data Calling function set callback data
* func_cb Calling function set callback function
* list_change_cb Calling function set list change function
* NULL
*/
parent = (GtkWidget *)(cb_data[0]);
wlabel = (GtkWidget *)(cb_data[1]);
combo = (GtkCombo *)(cb_data[2]);
glist_in = (GList *)(cb_data[3]);
max_items = (gint)(cb_data[4]);
client_data = (gpointer)(cb_data[5]);
func_cb = cb_data[6];
list_change_cb = cb_data[7];
if(combo == NULL)
return;
/* Get new value string from combo's entry widget */
new_value = gtk_entry_get_text(GTK_ENTRY(combo->entry));
/* Make a duplicate of the recieved value or NULL if it is not
* available
*/
new_value = STRDUP(new_value);
if(new_value == NULL)
return;
/* Add the new value to the combo box list, this will only
* be added if value is not already in the list. Excess items
* may be truncated if adding this item would cause items to
* exceed the set max items on the combo box
*
* List change callback will be called if the value was input
* to the combo box's list
*/
GUIComboAddItem((gpointer)combo, new_value);
/* Call activate function */
if(func_cb != NULL)
func_cb(
(GtkWidget *)combo, /* Combo */
client_data /* Data */
);
/* Free new_value which we duplicated */
g_free(new_value);
}
/*
* GtkCombo "changed" signal callback.
*/
static void GUIComboChangedCB(GtkWidget *widget, gpointer data)
{
GList *glist;
GtkCombo *combo;
gpointer client_data;
void (*list_change_cb)(GtkWidget *, gpointer, GList *);
gpointer *cb_data = (gpointer *)data;
if((widget == NULL) || (cb_data == NULL))
return;
/* Parse callback data, format is:
*
* table Parent table that holds combo and label
* label Label (may be NULL)
* combo This combo widget
* GList Contains list of strings in combo list
* max_items Max items allowed in combo list
* client_data Calling function set callback data
* func_cb Calling function set callback function
* list_change_cb Calling function set list change function
* NULL
*/
combo = (GtkCombo *)(cb_data[2]);
glist = (GList *)cb_data[3];
client_data = cb_data[5];
list_change_cb = cb_data[7];
/* Call list change function */
if(list_change_cb != NULL)
list_change_cb(
(GtkWidget *)combo, /* Combo */
client_data, /* Data */
glist /* List */
);
}
/*
* Combo data destroy callback.
*/
static void GUIComboDataDestroyCB(gpointer data)
{
GtkWidget *parent, *wlabel;
GtkCombo *combo;
GList *glist;
gint max_items;
gpointer client_data;
void (*func_cb)(GtkWidget *, gpointer);
void (*list_change_cb)(GtkWidget *, gpointer, GList *);
gpointer *cb_data = (gpointer *)data;
if(cb_data == NULL)
return;
/* Parse callback data, format is:
*
* table Parent table that holds combo and label
* label Label (may be NULL)
* combo This combo widget
* GList Contains list of strings in combo list
* max_items Max items allowed in combo list
* client_data Calling function set callback data
* func_cb Calling function set callback function
* list_change_cb Calling function set list change function
* NULL
*/
parent = (GtkWidget *)(cb_data[0]);
wlabel = (GtkWidget *)(cb_data[1]);
combo = (GtkCombo *)(cb_data[2]);
glist = (GList *)(cb_data[3]);
max_items = (gint)(cb_data[4]);
client_data = (gpointer)(cb_data[5]);
func_cb = cb_data[6];
list_change_cb = cb_data[7];
/* Do not call list change callback function on destroy */
/* Begin deallocating data referenced on callback data */
/* Delete list */
if(glist != NULL)
{
g_list_foreach(glist, (GFunc)g_free, NULL);
g_list_free(glist);
glist = NULL;
}
/* Delete callback data */
g_free(data);
}
/*
* Local menu item activate callback, this function will
* take the given data pointer as a dynamically allocated
* (void **).
*/
static void GUIMenuActivateCB(gpointer data)
{
gint argc = 3;
GtkWidget *functional_widget;
gpointer client_data;
void (*func_cb)(GtkWidget *, gpointer);
gpointer *cb_data = (gpointer *)data;
if(cb_data == NULL)
return;
/* Data Format:
*
* w Functional Widget
* client_data Data
* func_cb Callback Function
* NULL
*/
functional_widget = (GtkWidget *)((argc > 0) ? cb_data[0] : NULL);
client_data = ((argc > 1) ? cb_data[1] : NULL);
func_cb = ((argc > 2) ? cb_data[2] : NULL);
if(func_cb != NULL)
func_cb(
functional_widget, /* Functional Widget */
client_data /* Data */
);
}
/*
* Menu item client data destroy callback.
*/
static void GUIMenuClientDataDestroyCB(gpointer data)
{
gpointer *mi_client_data = (gpointer *)data;
g_free(mi_client_data);
}
/*
* Menu item data destroy callback.
*/
static void GUIMenuDataDestroyCB(gpointer data)
{
gui_menu_item_data_struct *mi = GUI_MENU_ITEM_DATA(data);
if(mi == NULL)
return;
g_free(mi->label_text);
g_free(mi->accel_text);
g_free(mi);
}
/*
* Pullout data destroy callback.
*/
static void GUIPullOutDataDestroyCB(gpointer data)
{
GtkWidget *client_hbox, *holder_hbox, *toplevel;
gpointer *cb_data = (gpointer *)data;
if(cb_data != NULL)
{
/* Format is as follows (12 arguments):
*
* client_hbox
* holder_hbox
* holder_window
* holder_window_x
* holder_window_y
* holder_window_width
* holder_window_height
* in_place (1 if true)
* pull_out_client_data
* pull_out_cb
* push_in_client_data
* push_in_cb
*/
client_hbox = (GtkWidget *)cb_data[0];
holder_hbox = (GtkWidget *)cb_data[1];
toplevel = (GtkWidget *)cb_data[2];
/* Destroy the toplevel window */
if(toplevel != NULL)
{
GTK_WIDGET_DESTROY(toplevel)
cb_data[2] = toplevel = NULL;
}
}
g_free(cb_data);
}
/*
* Pull out draw handle for signal "draw".
*/
static void GUIPullOutDrawHandleDrawCB(
GtkWidget *widget, GdkRectangle *area, gpointer data
)
{
GdkWindow *window;
GtkStyle *style;
if(gui_style_default == NULL)
gui_style_default = gtk_widget_get_default_style();
if((widget != NULL) ? GTK_WIDGET_NO_WINDOW(widget) : TRUE)
return;
window = widget->window;
if(window == NULL)
return;
style = gtk_widget_get_style(widget);
if(style == NULL)
style = gui_style_default;
if(style == NULL)
return;
gdk_window_clear(window);
#ifndef _WIN32
gtk_draw_handle(
style, window,
GTK_STATE_NORMAL, /* State type */
GTK_SHADOW_OUT, /* Shadow type */
0, 0,
widget->allocation.width,
widget->allocation.height,
GTK_ORIENTATION_HORIZONTAL
);
#endif
}
/*
* Pull out draw handle callback for signal "expose_event".
*
* This redraws the handle graphics on the given widget.
*/
static gint GUIPullOutDrawHandleCB(
GtkWidget *widget, GdkEvent *event, gpointer data
)
{
if((widget != NULL) ? GTK_WIDGET_NO_WINDOW(widget) : TRUE)
return(TRUE);
gtk_widget_queue_draw(widget);
return(TRUE);
}
/*
* Pull out button callback.
*/
static gint GUIPullOutPullOutBtnCB(
GtkWidget *widget, GdkEvent *event, gpointer data
)
{
GtkWidget *client_hbox, *holder_hbox, *toplevel;
gpointer *cb_data = (gpointer *)data;
gint holder_window_width, holder_window_height;
gpointer pull_out_client_data;
void (*pull_out_cb)(gpointer, gpointer);
if(cb_data != NULL)
{
/* Format is as follows (12 arguments):
*
* client_hbox
* holder_hbox
* holder_window
* holder_window_x
* holder_window_y
* holder_window_width
* holder_window_height
* in_place (1 if true).
* pull_out_client_data
* pull_out_cb
* push_in_client_data
* push_in_cb
*/
client_hbox = (GtkWidget *)cb_data[0];
holder_hbox = (GtkWidget *)cb_data[1];
toplevel = (GtkWidget *)cb_data[2];
holder_window_width = (gint)cb_data[5];
holder_window_height = (gint)cb_data[6];
pull_out_client_data = cb_data[8];
pull_out_cb = cb_data[9];
/* Create toplevel window as needed */
if(toplevel == NULL)
{
GtkWidget *w;
toplevel = w = gtk_window_new(GTK_WINDOW_TOPLEVEL);
cb_data[2] = (gpointer)w;
gtk_widget_realize(w);
gtk_widget_set_usize(
w,
(holder_window_width <= 0) ? -1 : holder_window_width,
(holder_window_height <= 0) ? -1 : holder_window_height
);
gtk_window_set_policy(
GTK_WINDOW(w),
TRUE, TRUE, FALSE
);
gtk_signal_connect(
GTK_OBJECT(w), "delete_event",
GTK_SIGNAL_FUNC(GUIPullOutCloseCB),
(gpointer)cb_data
);
}
/* Reparent client_hbox to toplevel window */
if((client_hbox != NULL) && (toplevel != NULL))
{
gtk_widget_show(toplevel);
if((GTK_WIDGET_FLAGS(client_hbox) & GTK_NO_REPARENT))
g_printerr("Cannot reparent.\n");
else
gtk_widget_reparent(client_hbox, toplevel);
}
/* Hide holder hbox */
if(holder_hbox != NULL)
gtk_widget_hide(holder_hbox);
/* Mark in callback data that its been `pulled out' */
cb_data[7] = (gpointer)0;
/* Call pull out callback? */
if(pull_out_cb != NULL)
pull_out_cb(client_hbox, pull_out_client_data);
}
return(TRUE);
}
/*
* Close (push in) callback.
*/
static gint GUIPullOutCloseCB(GtkWidget *widget, GdkEvent *event, gpointer data)
{
GtkWidget *client_hbox, *holder_hbox, *toplevel;
gpointer *cb_data = (gpointer *)data;
gpointer push_in_client_data;
void (*push_in_cb)(gpointer, gpointer);
if(cb_data != NULL)
{
/* Format is as follows (12 arguments):
*
* client_hbox
* holder_hbox
* holder_window
* holder_window_x
* holder_window_y
* holder_window_width
* holder_window_height
* in_place (1 if true).
* pull_out_client_data
* pull_out_cb
* push_in_client_data
* push_in_cb
*/
client_hbox = (GtkWidget *)cb_data[0];
holder_hbox = (GtkWidget *)cb_data[1];
toplevel = (GtkWidget *)cb_data[2];
push_in_client_data = cb_data[10];
push_in_cb = cb_data[11];
/* Reparent client_hbox to holder_hbox */
if((client_hbox != NULL) && (holder_hbox != NULL))
{
gtk_widget_show(holder_hbox);
if((GTK_WIDGET_FLAGS(client_hbox) & GTK_NO_REPARENT))
g_printerr("Cannot reparent.\n");
else
gtk_widget_reparent(client_hbox, holder_hbox);
}
/* Hide toplevel */
if(toplevel != NULL)
gtk_widget_hide(toplevel);
/* Mark in callback data that its been `pushed in' */
cb_data[7] = (gpointer)1;
/* Call push in callback? */
if(push_in_cb != NULL)
push_in_cb(client_hbox, push_in_client_data);
}
return(TRUE);
}
/*
* Creates a new GtkRcStyle based on the given GtkRcStyle.
*/
GtkRcStyle *GUIRCStyleCopy(const GtkRcStyle *rcstyle)
{
#if (GTK_MAJOR_VERSION >= 2)
return((rcstyle != NULL) ? gtk_rc_style_copy(rcstyle) : NULL);
#else
gint i;
const GtkRcStyle *src_style = rcstyle;
GtkRcStyle *tar_style;
if(src_style == NULL)
return(NULL);
tar_style = gtk_rc_style_new();
tar_style->name = STRDUP(src_style->name);
tar_style->font_name = STRDUP(src_style->font_name);
tar_style->fontset_name = STRDUP(src_style->fontset_name);
for(i = 0; i < 5; i++)
{
tar_style->bg_pixmap_name[i] = STRDUP(src_style->bg_pixmap_name[i]);
tar_style->color_flags[i] = src_style->color_flags[i];
memcpy(&tar_style->fg[i], &src_style->fg[i], sizeof(GdkColor));
memcpy(&tar_style->bg[i], &src_style->bg[i], sizeof(GdkColor));
memcpy(&tar_style->text[i], &src_style->text[i], sizeof(GdkColor));
memcpy(&tar_style->base[i], &src_style->base[i], sizeof(GdkColor));
}
tar_style->engine = src_style->engine;
tar_style->engine_data = src_style->engine_data;
#endif
return(tar_style);
}
/*
* Sets the widget's rc style and all of its child widgets.
*/
void GUIRCStyleSetRecursive(GtkWidget *w, GtkRcStyle *rcstyle)
{
if((w == NULL) || (rcstyle == NULL))
return;
gtk_widget_modify_style(w, rcstyle);
if(GTK_IS_CONTAINER(w))
gtk_container_forall(
GTK_CONTAINER(w),
(GtkCallback)GUIRCStyleSetRecursive, rcstyle
);
}
/*
* Parses the geometry string s.
*
* Returns a set of GdkGeometryFlags flags.
*/
GdkGeometryFlags GUIParseGeometry(
const gchar *s,
gint *x, gint *y, gint *width, gint *height
)
{
GdkGeometryFlags status = 0x00000000;
if(x != NULL)
*x = 0;
if(y != NULL)
*y = 0;
if(width != NULL)
*width = 0;
if(height != NULL)
*height = 0;
if(s == NULL)
return(status);
/* Seek past initial spaces and '=' deliminator (if any) */
while(ISBLANK(*s))
s++;
while(*s == '=')
s++;
while(ISBLANK(*s))
s++;
/* String at width and height arguments? */
if((*s != '+') && (*s != '-'))
{
/* Parse width value */
if((width != NULL) && (*s != '\0'))
{
*width = ATOI(s);
status |= GDK_GEOMETRY_WIDTH;
}
/* Begin seeking to next argument */
if(*s != '\0')
s++;
while((toupper(*s) != 'X') && (*s != '\0'))
s++;
while((toupper(*s) == 'X') || ISBLANK(*s))
s++;
/* Parse height value */
if((height != NULL) && (*s != '\0'))
{
*height = ATOI(s);
status |= GDK_GEOMETRY_HEIGHT;
}
/* Begin seeking to next argument (probably an offset
* value)
*/
if(*s != '\0')
s++;
while((*s != '+') && (*s != '-') && (*s != '\0'))
s++;
}
/* String seeked to the offsets arguments? */
if((*s == '+') || (*s == '-'))
{
/* Seek past '+' character as needed and get x offset
* value
*/
if(*s == '+')
s++;
if((x != NULL) && (*s != '\0'))
{
*x = ATOI(s);
status |= GDK_GEOMETRY_X;
}
/* Begin seeking to next argument */
if(*s != '\0')
s++;
while((*s != '+') && (*s != '-') && (*s != '\0'))
s++;
/* Seek past '+' character as needed and get y offset
* value
*/
if(*s == '+')
s++;
if((y != NULL) && (*s != '\0'))
{
*y = ATOI(s);
status |= GDK_GEOMETRY_Y;
}
}
return(status);
}
/*
* Gets the geometry of the GtkCList cell.
*
* The clist specifies the GtkCList.
*
* The column and row specifiy the cell.
*
* The x, y, width, and height specifies the pointers to the
* cell geometry return. Any of these values may be NULL if
* the value is not requested.
*
* Returns TRUE if the cell geometry was obtained or FALSE on
* failed match or error.
*/
gboolean GUICListGetCellGeometry(
GtkCList *clist, const gint column, const gint row,
gint *x, gint *y, gint *width, gint *height
)
{
gint i, cx, cy, cwidth, cheight;
GList *glist;
const GtkAdjustment *hadj, *vadj;
const GtkCListRow *row_ptr;
const GtkCListColumn *column_ptr;
if(x != NULL)
*x = 0;
if(y != NULL)
*y = 0;
if(width != NULL)
*width = 0;
if(height != NULL)
*height = 0;
if(clist == NULL)
return(FALSE);
hadj = clist->hadjustment;
vadj = clist->vadjustment;
/* Given row and column in bounds? */
if((column < 0) || (column >= clist->columns))
return(FALSE);
if((row < 0) || (row >= clist->rows))
return(FALSE);
/* Get cy and cheight */
cy = 0;
cheight = 0;
glist = clist->row_list;
for(i = 0; glist != NULL; i++)
{
row_ptr = (const GtkCListRow *)glist->data;
if(row_ptr != NULL)
{
const GtkCellText *cell_text_ptr;
const GtkCellPixmap *cell_pixmap_ptr;
const GtkCellPixText *cell_pixtext_ptr;
const GtkCellWidget *cell_widget_ptr;
const GtkCell *cell_ptr = row_ptr->cell;
cheight = clist->row_height;
if(cell_ptr != NULL)
{
switch(cell_ptr->type)
{
case GTK_CELL_TEXT:
cell_text_ptr = (GtkCellText *)cell_ptr;
cheight = MAX(cell_text_ptr->vertical, cheight);
break;
case GTK_CELL_PIXMAP:
cell_pixmap_ptr = (GtkCellPixmap *)cell_ptr;
cheight = MAX(cell_pixmap_ptr->vertical, cheight);
break;
case GTK_CELL_PIXTEXT:
cell_pixtext_ptr = (GtkCellPixText *)cell_ptr;
cheight = MAX(cell_pixtext_ptr->vertical, cheight);
break;
case GTK_CELL_WIDGET:
cell_widget_ptr = (GtkCellWidget *)cell_ptr;
cheight = MAX(cell_widget_ptr->vertical, cheight);
break;
case GTK_CELL_EMPTY:
cheight = 0;
break;
}
}
cheight += 1; /* Need to add 1 pixel for cell borders */
if(i == row)
break;
cy += cheight;
}
glist = g_list_next(glist);
}
/* Get cx and cwidth */
cx = 0;
cwidth = 0;
if(clist->column != NULL)
{
for(i = 0; i < clist->columns; i++)
{
column_ptr = &clist->column[i];
if(column_ptr == NULL)
continue;
/* Get width of this column plus margins */
cwidth = column_ptr->width + 7;
if(i == column)
break;
cx += cwidth;
}
}
/* Offset cx and cy with scroll adjustments */
if(hadj != NULL)
cx = cx - (gint)(hadj->value - hadj->lower);
if(vadj != NULL)
cy = cy - (gint)(vadj->value - vadj->lower);
/* Update returns */
if(x != NULL)
*x = cx;
if(y != NULL)
*y = cy;
if(width != NULL)
*width = cwidth;
if(height != NULL)
*height = cheight;
return(TRUE);
}
/*
* Returns the row index of the specified node.
*/
gint GUICTreeNodeRow(GtkCTree *ctree, GtkCTreeNode *node)
{
gint row;
GList *glist;
GtkCList *clist;
GtkCTreeRow *row_ptr;
if((ctree == NULL) || (node == NULL))
return(-1);
clist = GTK_CLIST(ctree);
row_ptr = GTK_CTREE_ROW(node);
if(row_ptr == NULL)
return(FALSE);
/* Count rows until we encounter the specified node's row */
for(glist = clist->row_list, row = 0;
glist != NULL;
glist = g_list_next(glist), row++
)
{
if(row_ptr == (GtkCTreeRow *)glist->data)
break;
}
return((glist != NULL) ? row : -1);
}
/*
* Used by GUICTreeNodeDeltaRows().
*/
static void GUICTreeNodeDeltaRowsIterate(
GtkCTree *ctree, GtkCTreeNode *node, GtkCTreeNode *end,
gint *row_count, gboolean *end_found
)
{
GtkCTreeRow *row_ptr;
while((node != NULL) && !(*end_found))
{
/* Found end node? */
if(node == end)
{
*end_found = TRUE;
break;
}
/* Count this node */
*row_count = *row_count + 1;
row_ptr = GTK_CTREE_ROW(node);
if(row_ptr == NULL)
break;
/* Count child nodes only if expanded */
if(row_ptr->expanded && !row_ptr->is_leaf)
{
GUICTreeNodeDeltaRowsIterate(
ctree, row_ptr->children, end, row_count, end_found
);
if(*end_found)
break;
}
/* Get next sibling */
node = row_ptr->sibling;
}
}
/*
* Returns the number of rows between the GtkCTree nodes.
*/
gint GUICTreeNodeDeltaRows(
GtkCTree *ctree,
GtkCTreeNode *start, /* Use NULL for first/toplevel node */
GtkCTreeNode *end
)
{
gboolean end_found = FALSE;
gint row_count = 0;
if((ctree == NULL) || (end == NULL))
return(row_count);
if(start == NULL)
start = gtk_ctree_node_nth(ctree, 0);
GUICTreeNodeDeltaRowsIterate(
ctree, start, end, &row_count, &end_found
);
return(row_count);
}
/*
* Returns the coordinate position for the specified GdkWindow
* relative to the root GdkWindow.
*/
void GUIGetWindowRootPosition(
GdkWindow *window, gint *x, gint *y
)
{
gint cx, cy;
GdkWindow *cur_w = window, *root_w;
if(x != NULL)
*x = 0;
if(y != NULL)
*y = 0;
if(cur_w == NULL)
return;
if(gui_window_root == NULL)
gui_window_root = (GdkWindow *)GDK_ROOT_PARENT();
root_w = gui_window_root;
if(root_w == NULL)
return;
while(cur_w != root_w)
{
gdk_window_get_position(cur_w, &cx, &cy);
if(x != NULL)
*x += cx;
if(y != NULL)
*y += cy;
cur_w = gdk_window_get_parent(cur_w);
}
}
/*
* Converts the coordinates x and y (relative to the window w)
* be relative to the root window.
*/
void GUIGetPositionRoot(
GdkWindow *w, gint x, gint y, gint *rx, gint *ry
)
{
GdkWindow *cur = w, *root_w;
gint cx, cy;
if(rx != NULL)
*rx = 0;
if(ry != NULL)
*ry = 0;
if(gui_window_root == NULL)
gui_window_root = (GdkWindow *)GDK_ROOT_PARENT();
root_w = gui_window_root;
if((cur == NULL) || (root_w == NULL))
return;
while((cur != root_w) && (cur != NULL))
{
gdk_window_get_position(cur, &cx, &cy);
x += cx;
y += cy;
cur = gdk_window_get_parent(cur);
}
if(rx != NULL)
*rx = x;
if(ry != NULL)
*ry = y;
}
/*
* Gets the text bounds.
*/
void GUIGetTextBounds(
GdkFont *font, const gchar *text, const gint text_length,
GdkTextBounds *bounds
)
{
if((font == NULL) || (text == NULL) || (bounds == NULL))
{
if(bounds != NULL)
memset(bounds, 0x00, sizeof(GdkTextBounds));
return;
}
gdk_text_extents(
font, text, text_length,
&bounds->lbearing, &bounds->rbearing, &bounds->width,
&bounds->ascent, &bounds->descent
);
}
/*
* Gets the string bounds.
*/
void GUIGetStringBounds(
GdkFont *font, const gchar *string,
GdkTextBounds *bounds
)
{
GUIGetTextBounds(font, string, STRLEN(string), bounds);
}
/*
* Creates a new GC
*/
GdkGC *GDK_GC_NEW(void)
{
if(gui_window_root == NULL)
gui_window_root = (GdkWindow *)GDK_ROOT_PARENT();
return(gdk_gc_new(gui_window_root));
}
/*
* Blocks input to the toplevel widget.
*
* The w specifies the toplevel widget which must be a GtkWindow.
*
* The block specifies whether to block or unblock input.
*/
void GUIBlockInput(GtkWidget *w, const gboolean block)
{
GtkWidget *invis;
if((w != NULL) ? !GTK_IS_WINDOW(w) : TRUE)
return;
/* Create the GtkInvisible blocker widget as needed */
invis = gui_invisible_blocker_widget;
if(invis == NULL)
{
gui_invisible_blocker_widget = invis = gtk_invisible_new();
if(invis == NULL)
return;
}
/* Block input? */
if(block)
{
/* Increase the block input level and check if it is the
* first blocking level
*/
gui_block_input_level++;
if(gui_block_input_level == 1)
{
/* This is the first blocking level, so we need to
* map the GtkInvisible and grab it so that input
* will be blocked
*/
gtk_widget_show(invis);
if(gtk_grab_get_current() != invis)
gtk_grab_add(invis);
}
}
else
{
/* Decrease the block input level and check if it is the
* last level
*/
gui_block_input_level--;
if(gui_block_input_level == 0)
{
if(gtk_grab_get_current() == invis)
gtk_grab_remove(invis);
gtk_widget_hide(invis);
}
/* Sanitize block input level underflows */
if(gui_block_input_level < 0)
{
gui_block_input_level = 0;
g_printerr(
"GUIBlockInput(): Block level underflow to level %i.\n",
gui_block_input_level
);
}
}
}
/*
* Gets the block input level.
*/
gint GUIBlockInputGetLevel(void)
{
return(gui_block_input_level);
}
/*
* Gets the GdkWindow's reference count.
*/
gint GUIWindowGetRefCount(GdkWindow *window)
{
#if defined(_WIN32)
return((window != NULL) ? 1 : 0);
#else
return((window != NULL) ?
((GdkWindowPrivate *)window)->ref_count : 0
);
#endif
}
/*
* Sets the WM icon for the GdkWindow w based on the specified XPM
* data.
*/
void GUISetWMIcon(GdkWindow *window, guint8 **data)
{
GdkBitmap *mask;
GdkPixmap *pixmap;
if((window == NULL) || (data == NULL))
return;
/* Load icon pixmap and mask */
pixmap = GDK_PIXMAP_NEW_FROM_XPM_DATA(&mask, data);
if(pixmap != NULL)
{
/* Set WM icon
*
* Note that gdk_window_set_icon() will take care of
* unref'ing the pixmap and mask
*/
gdk_window_set_icon(window, NULL, pixmap, mask);
}
}
/*
* Sets the WM icon for the GdkWindow w based on the specified XPM
* file.
*/
void GUISetWMIconFile(GdkWindow *window, const gchar *filename)
{
GdkBitmap *mask;
GdkPixmap *pixmap;
if((window == NULL) || STRISEMPTY(filename))
return;
/* Load icon pixmap and mask */
pixmap = GDK_PIXMAP_NEW_FROM_XPM_FILE(&mask, filename);
if(pixmap != NULL)
{
/* Set WM icon
*
* Note that gdk_window_set_icon() will take care of
* unref'ing the pixmap and mask
*/
gdk_window_set_icon(window, NULL, pixmap, mask);
}
}
/*
* Applies the command line arguments to the GtkWindow.
*
* Command line arguments that will be applied are as follows:
*
* --title <title> Set WM title bar title
* --class <class> Set WM class
* --icon <filename> Set WM icon
* --icon-name <name> Set WM icon's name
* --font-name <font> Set font
* --font
* -fn
* --foreground-color <color> Set foreground color
* -fg
* --background-color <color> Set background color
* -bg
* --text-color <color> Set text color
* --base-color <color> Set base color
* --background-pixmap <filename> Set background pixmap
* --bg-pixmap
* --sforeground-color <color> Set selected foreground color
* -sfg
* --sbackground-color <color> Set selected background color
* -sbg
* --stext-color <color> Set selected text color
* --sbase-color <color> Set selected base color
* --sbackground-pixmap <filename> Set selected background pixmap
* --sbg-pixmap
* --geometry <geometry> Set geometry
* --iconic Startup iconified
*
*/
void GUIWindowApplyArgs(GtkWindow *w, gint argc, gchar **argv)
{
gint i;
gboolean arg_on;
const gchar *arg, *argp;
gchar *title = NULL,
*wmclass = NULL,
*icon = NULL,
*icon_name = NULL;
GdkGeometryFlags geometry_flags = 0x00000000;
GdkRectangle *geometry = NULL;
gboolean iconic = FALSE;
GtkRcStyle *rcstyle = NULL;
GdkWindow *window;
#define NEW_RCSTYLE_AS_NEEDED { \
if(rcstyle == NULL) \
rcstyle = gtk_rc_style_new(); \
}
if((w == NULL) || (argc <= 0) || (argv == NULL))
return;
if(!GTK_IS_WINDOW(GTK_WIDGET(w)) ||
GTK_WIDGET_NO_WINDOW(GTK_WIDGET(w))
)
return;
window = GTK_WIDGET(w)->window;
if(window == NULL)
return;
/* Iterate through arguments and gather values to be applied to
* the GtkWindow
*/
for(i = 0; i < argc; i++)
{
arg = argv[i];
if(STRISEMPTY(arg))
continue;
/* If the argument does not start with a '-' character then
* we can skip the checking of the argument for convience
*/
if((*arg != '-') && (*arg != '+'))
continue;
/* If arg is prefixed with a '+' character then set arg_on
* to TRUE so that toggle arguments can know to enable or
* disable
*/
arg_on = (*arg == '+') ? TRUE : FALSE;
/* Get argp to seek past the '-' characters in arg */
argp = arg;
while((*argp == '-') || (*argp == '+'))
argp++;
#define PRINT_REQUIRES_ARG(_a_) { \
g_printerr( \
"%s: Requires argument.\n", \
(_a_) \
); \
}
/* Handle by argument */
/* Title */
if(!g_strcasecmp(argp, "title"))
{
i++;
arg = (i < argc) ? argv[i] : NULL;
if(arg != NULL)
{
g_free(title);
title = STRDUP(arg);
}
else
{
PRINT_REQUIRES_ARG(argv[i - 1])
}
}
/* Class */
else if(!g_strcasecmp(argp, "class"))
{
i++;
arg = (i < argc) ? argv[i] : NULL;
if(arg != NULL)
{
g_free(wmclass);
wmclass = STRDUP(arg);
}
else
{
PRINT_REQUIRES_ARG(argv[i - 1])
}
}
/* Icon */
else if(!g_strcasecmp(argp, "icon"))
{
i++;
arg = (i < argc) ? argv[i] : NULL;
if(arg != NULL)
{
g_free(icon);
icon = STRDUP(arg);
}
else
{
PRINT_REQUIRES_ARG(argv[i - 1])
}
}
/* Icon Name */
else if(!g_strcasecmp(argp, "icon-name"))
{
i++;
arg = (i < argc) ? argv[i] : NULL;
if(arg != NULL)
{
g_free(icon_name);
icon_name = STRDUP(arg);
}
else
{
PRINT_REQUIRES_ARG(argv[i - 1])
}
}
/* Font */
else if(!g_strcasecmp(argp, "font-name") ||
!g_strcasecmp(argp, "font") ||
!g_strcasecmp(argp, "fn")
)
{
i++;
arg = (i < argc) ? argv[i] : NULL;
if(arg != NULL)
{
NEW_RCSTYLE_AS_NEEDED
g_free(rcstyle->font_name);
rcstyle->font_name = STRDUP(arg);
}
else
{
PRINT_REQUIRES_ARG(argv[i - 1])
}
}
/* Foreground Color */
else if(!g_strcasecmp(argp, "foreground-color") ||
!g_strcasecmp(argp, "foreground") ||
!g_strcasecmp(argp, "fg")
)
{
i++;
arg = (i < argc) ? argv[i] : NULL;
if(arg != NULL)
{
GdkColor *c;
GtkStateType state = GTK_STATE_NORMAL;
NEW_RCSTYLE_AS_NEEDED
rcstyle->color_flags[state] |= GTK_RC_FG;
c = &rcstyle->fg[state];
gdk_color_parse(arg, c);
}
else
{
PRINT_REQUIRES_ARG(argv[i - 1])
}
}
/* Background Color */
else if(!g_strcasecmp(argp, "background-color") ||
!g_strcasecmp(argp, "background") ||
!g_strcasecmp(argp, "bg")
)
{
i++;
arg = (i < argc) ? argv[i] : NULL;
if(arg != NULL)
{
GdkColor *c;
GtkStateType state = GTK_STATE_NORMAL;
NEW_RCSTYLE_AS_NEEDED
rcstyle->color_flags[state] |= GTK_RC_BG;
c = &rcstyle->bg[state];
gdk_color_parse(arg, c);
}
else
{
PRINT_REQUIRES_ARG(argv[i - 1])
}
}
/* Text Color */
else if(!g_strcasecmp(argp, "text-color"))
{
i++;
arg = (i < argc) ? argv[i] : NULL;
if(arg != NULL)
{
GdkColor *c;
GtkStateType state = GTK_STATE_NORMAL;
NEW_RCSTYLE_AS_NEEDED
rcstyle->color_flags[state] |= GTK_RC_TEXT;
c = &rcstyle->text[state];
gdk_color_parse(arg, c);
}
else
{
PRINT_REQUIRES_ARG(argv[i - 1])
}
}
/* Base Color */
else if(!g_strcasecmp(argp, "base-color"))
{
i++;
arg = (i < argc) ? argv[i] : NULL;
if(arg != NULL)
{
GdkColor *c;
GtkStateType state = GTK_STATE_NORMAL;
NEW_RCSTYLE_AS_NEEDED
rcstyle->color_flags[state] |= GTK_RC_BASE;
c = &rcstyle->base[state];
gdk_color_parse(arg, c);
}
else
{
PRINT_REQUIRES_ARG(argv[i - 1])
}
}
/* Background Pixmap */
else if(!g_strcasecmp(argp, "background-pixmap") ||
!g_strcasecmp(argp, "bg-pixmap")
)
{
i++;
arg = (i < argc) ? argv[i] : NULL;
if(arg != NULL)
{
GtkStateType state = GTK_STATE_NORMAL;
NEW_RCSTYLE_AS_NEEDED
g_free(rcstyle->bg_pixmap_name[state]);
rcstyle->bg_pixmap_name[state] = STRDUP(arg);
}
else
{
PRINT_REQUIRES_ARG(argv[i - 1])
}
}
/* Selected Foreground Color */
else if(!g_strcasecmp(argp, "sforeground-color") ||
!g_strcasecmp(argp, "sforeground") ||
!g_strcasecmp(argp, "sfg")
)
{
i++;
arg = (i < argc) ? argv[i] : NULL;
if(arg != NULL)
{
GdkColor *c;
GtkStateType state = GTK_STATE_SELECTED;
NEW_RCSTYLE_AS_NEEDED
rcstyle->color_flags[state] |= GTK_RC_FG;
c = &rcstyle->fg[state];
gdk_color_parse(arg, c);
}
else
{
PRINT_REQUIRES_ARG(argv[i - 1])
}
}
/* Selected Background Color */
else if(!g_strcasecmp(argp, "sbackground-color") ||
!g_strcasecmp(argp, "sbackground") ||
!g_strcasecmp(argp, "sbg")
)
{
i++;
arg = (i < argc) ? argv[i] : NULL;
if(arg != NULL)
{
GdkColor *c;
GtkStateType state = GTK_STATE_SELECTED;
NEW_RCSTYLE_AS_NEEDED
rcstyle->color_flags[state] |= GTK_RC_BG;
c = &rcstyle->bg[state];
gdk_color_parse(arg, c);
}
else
{
PRINT_REQUIRES_ARG(argv[i - 1])
}
}
/* Selected Text Color */
else if(!g_strcasecmp(argp, "stext-color"))
{
i++;
arg = (i < argc) ? argv[i] : NULL;
if(arg != NULL)
{
GdkColor *c;
GtkStateType state = GTK_STATE_SELECTED;
NEW_RCSTYLE_AS_NEEDED
rcstyle->color_flags[state] |= GTK_RC_TEXT;
c = &rcstyle->text[state];
gdk_color_parse(arg, c);
}
else
{
PRINT_REQUIRES_ARG(argv[i - 1])
}
}
/* Selected Base Color */
else if(!g_strcasecmp(argp, "sbase-color"))
{
i++;
arg = (i < argc) ? argv[i] : NULL;
if(arg != NULL)
{
GdkColor *c;
GtkStateType state = GTK_STATE_SELECTED;
NEW_RCSTYLE_AS_NEEDED
rcstyle->color_flags[state] |= GTK_RC_BASE;
c = &rcstyle->base[state];
gdk_color_parse(arg, c);
}
else
{
PRINT_REQUIRES_ARG(argv[i - 1])
}
}
/* Selected Background Pixmap */
else if(!g_strcasecmp(argp, "sbackground-pixmap") ||
!g_strcasecmp(argp, "sbg-pixmap")
)
{
i++;
arg = (i < argc) ? argv[i] : NULL;
if(arg != NULL)
{
GtkStateType state = GTK_STATE_SELECTED;
NEW_RCSTYLE_AS_NEEDED
g_free(rcstyle->bg_pixmap_name[state]);
rcstyle->bg_pixmap_name[state] = STRDUP(arg);
}
else
{
PRINT_REQUIRES_ARG(argv[i - 1])
}
}
/* Geometry */
else if(!g_strcasecmp(argp, "geometry"))
{
i++;
arg = (i < argc) ? argv[i] : NULL;
if(arg != NULL)
{
gint x, y, width, height;
const GdkGeometryFlags flags = gdk_parse_geometry(
arg, &x, &y, &width, &height
);
geometry_flags = flags;
if(flags != 0)
{
GdkRectangle *rect = geometry;
if(rect == NULL)
geometry = rect = (GdkRectangle *)g_malloc0(
sizeof(GdkRectangle)
);
rect->x = (flags & GDK_GEOMETRY_X) ? x : 0;
rect->y = (flags & GDK_GEOMETRY_Y) ? y : 0;
rect->width = (flags & GDK_GEOMETRY_WIDTH) ? width : 0;
rect->height = (flags & GDK_GEOMETRY_HEIGHT) ? height : 0;
}
}
else
{
PRINT_REQUIRES_ARG(argv[i - 1])
}
}
/* Iconic */
else if(!g_strcasecmp(argp, "iconic"))
{
iconic = TRUE;
}
#undef PRINT_REQUIRES_ARG
}
/* Begin applying values */
/* Set title? */
if(title != NULL)
{
gtk_window_set_title(w, title);
}
/* Set class? */
if(wmclass != NULL)
{
#if 0
TODO: Should not set this after GtkWindow has been realized
gtk_window_set_wmclass(w, wmclass, wmclass);
#endif
}
/* Set icon? */
if(icon != NULL)
{
GUISetWMIconFile(window, icon);
}
/* Set icon name? */
if(icon_name != NULL)
{
gdk_window_set_icon_name(window, icon_name);
}
/* Set geometry? */
if((geometry_flags != 0) && (geometry != NULL))
{
const GdkGeometryFlags flags = geometry_flags;
GdkRectangle *rect = geometry;
if((flags & GDK_GEOMETRY_WIDTH) || (flags & GDK_GEOMETRY_HEIGHT))
gtk_widget_set_usize(
GTK_WIDGET(w),
(flags & GDK_GEOMETRY_WIDTH) ? rect->width : -1,
(flags & GDK_GEOMETRY_HEIGHT) ? rect->height : -1
);
if((flags & GDK_GEOMETRY_X) || (flags & GDK_GEOMETRY_Y))
gtk_widget_set_uposition(
GTK_WIDGET(w),
(flags & GDK_GEOMETRY_X) ? rect->x : 0,
(flags & GDK_GEOMETRY_Y) ? rect->y : 0
);
}
/* Iconic? */
if(iconic)
{
/* TODO */
}
/* Set rc style? */
if(rcstyle != NULL)
{
gtk_widget_modify_style_recursive(
GTK_WIDGET(w), rcstyle
);
}
g_free(title);
g_free(wmclass);
g_free(icon);
g_free(icon_name);
GTK_RC_STYLE_UNREF(rcstyle);
g_free(geometry);
#undef NEW_RCSTYLE_AS_NEEDED
}
/*
* Returns TRUE if the specified argument is one that is handled
* by GUIWindowApplyArgs.
*/
gboolean GUIIsWindowArg(const gchar *arg)
{
if(arg == NULL)
return(FALSE);
if(*arg != '-')
return(FALSE);
/* Seek past the initial '-' characters */
while(*arg == '-')
arg++;
if(!g_strcasecmp(arg, "title") ||
!g_strcasecmp(arg, "class") ||
!g_strcasecmp(arg, "icon") ||
!g_strcasecmp(arg, "icon-name") ||
!g_strcasecmp(arg, "font-name") ||
!g_strcasecmp(arg, "font") ||
!g_strcasecmp(arg, "fn") ||
!g_strcasecmp(arg, "foreground-color") ||
!g_strcasecmp(arg, "fg") ||
!g_strcasecmp(arg, "background-color") ||
!g_strcasecmp(arg, "bg") ||
!g_strcasecmp(arg, "text-color") ||
!g_strcasecmp(arg, "base-color") ||
!g_strcasecmp(arg, "background-pixmap") ||
!g_strcasecmp(arg, "bg-pixmap") ||
!g_strcasecmp(arg, "sforeground-color") ||
!g_strcasecmp(arg, "sfg") ||
!g_strcasecmp(arg, "sbackground-color") ||
!g_strcasecmp(arg, "sbg") ||
!g_strcasecmp(arg, "stext-color") ||
!g_strcasecmp(arg, "sbase-color") ||
!g_strcasecmp(arg, "sbackground-pixmap") ||
!g_strcasecmp(arg, "sbg-pixmap") ||
!g_strcasecmp(arg, "geometry") ||
!g_strcasecmp(arg, "iconic")
)
return(TRUE);
else
return(FALSE);
}
/*
* Sets the GtkCTree's position for optimul viewing of all the
* nodes starting from the expanded node.
*
* The node specifies the expanded parent node.
*
* Returns TRUE if the position has changed.
*/
gboolean GUICTreeOptimizeExpandPosition(
GtkCTree *ctree,
GtkCTreeNode *node
)
{
gboolean need_scroll = FALSE;
gint row_height, rows_visible, nchild_rows;
/* GtkAdjustment *vadj; */
GtkCList *clist;
GtkCTreeRow *row_ptr;
GtkCTreeNode *cur_node, *last_child_node, *scroll_end_node = NULL;
if((ctree == NULL) || (node == NULL))
return(FALSE);
/* Get the clist information */
clist = GTK_CLIST(ctree);
if(clist->columns <= 0)
return(FALSE);
#if 0
vadj = clist->vadjustment;
if(vadj == NULL)
return(FALSE);
#endif
/* Get the row height if it is set and assume uniform row
* spacing, otherwise assume the default to be 20
*/
if(GTK_CLIST_ROW_HEIGHT_SET(clist))
row_height = clist->row_height + 1;
else
row_height = 20;
if(row_height <= 0)
return(FALSE);
/* Calculate the number of rows visible */
rows_visible = clist->clist_window_height / row_height;
if(rows_visible <= 0)
return(FALSE);
/* Get the first child of the expanded node */
last_child_node = NULL;
nchild_rows = 1; /* Include the parent */
row_ptr = GTK_CTREE_ROW(node);
cur_node = (row_ptr != NULL) ? row_ptr->children : NULL;
while(cur_node != NULL)
{
last_child_node = cur_node;
nchild_rows++;
if(nchild_rows > rows_visible)
{
need_scroll = TRUE;
break;
}
row_ptr = GTK_CTREE_ROW(cur_node);
cur_node = (row_ptr != NULL) ? row_ptr->sibling : NULL;
}
/* Check if last child node is not visible */
if(!need_scroll && (last_child_node != NULL))
{
#if 1
const gint branch_start_rows = GUICTreeNodeDeltaRows(
ctree, NULL, node
),
branch_end_rows = branch_start_rows + nchild_rows;
GtkCTreeNode *end_node = gtk_ctree_node_nth(
ctree, branch_end_rows - 1
);
if(end_node != NULL)
{
if(gtk_ctree_node_is_visible(
ctree, end_node
) != GTK_VISIBILITY_FULL)
{
/* It is not visible so mark that we need to scroll
* and get the end node
*/
need_scroll = TRUE;
scroll_end_node = end_node;
}
}
#else
const gint branch_start_rows = GUICTreeNodeDeltaRows(
ctree, NULL, node
),
branch_end_rows = branch_start_rows + nchild_rows;
const gint y_scroll_pos = (gint)MAX(vadj->value, vadj->lower),
height = MAX(clist->clist_window_height, 0),
y = (branch_end_rows * row_height) - y_scroll_pos;
if(y > height)
{
/* It is not visible so mark that we need to scroll
* and get the end node
*/
need_scroll = TRUE;
scroll_end_node = gtk_ctree_node_nth(ctree, branch_end_rows - 1);
}
#endif
}
/* Need to scroll? */
if(need_scroll)
{
if(scroll_end_node != NULL)
gtk_ctree_node_moveto(
ctree,
scroll_end_node, -1,
1.0f, 0.0f /* Row align, column align */
);
else
gtk_ctree_node_moveto(
ctree,
node, -1,
0.0f, 0.0f /* Row align, column align */
);
return(TRUE);
}
else
{
return(FALSE);
}
}
/*
* Creates a bitmap from the given RGBA data
*
* Only the alpha byte will be used to create the bitmap.
*
* An alpha byte value greater than or equal to the value
* specified by threshold will set a 1 bit in the bitmap and a
* value less will set a 0 bit.
*
* If bytes per line bpl is -1, then it will be automatically
* calculated.
*/
GdkBitmap *GUICreateBitmapFromDataRGBA(
gint width, gint height, gint bpl,
const guint8 *rgba, guint8 threshold,
GdkWindow *window
)
{
const gint bpp = 4;
gint xbm_bpl;
guint8 *xbm_data;
const guint8 *src_ptr;
gint x, y;
GdkBitmap *bitmap;
if(gui_window_root == NULL)
gui_window_root = (GdkWindow *)GDK_ROOT_PARENT();
if(window == NULL)
window = gui_window_root;
if((rgba == NULL) || (width <= 0) || (height <= 0))
return(NULL);
/* Calculate bytes per line, the number of bytes to be able to
* hold one whole line of bits
*/
xbm_bpl = (width / 8) + ((width % 8) ? 1 : 0);
if(bpl < 0)
bpl = width * bpp;
if(bpl <= 0)
return(NULL);
/* Allocate bitmap */
xbm_data = (guint8 *)g_malloc0(
xbm_bpl * height * sizeof(guint8)
);
if(xbm_data == NULL)
return(NULL);
/* Begin converting the RGBA data to the bitmap data */
for(y = 0; y < height; y++)
{
for(x = 0; x < width; x++)
{
src_ptr = &rgba[
(y * bpl) + (x * bpp)
];
/* Alpha value greater or equal to threshold? */
if(src_ptr[3] >= threshold)
xbm_data[
(y * xbm_bpl) + (x / 8)
] |= (guint8)(1 << (x % 8));
}
}
/* Create bitmap */
bitmap = gdk_bitmap_create_from_data(
window, xbm_data,
width, height
);
g_free(xbm_data); /* No longer needed */
return(bitmap);
}
/*
* Creates a new GdkPixmap of the specified size and current
* depth.
*/
GdkPixmap *GDK_PIXMAP_NEW(gint width, gint height)
{
if(gui_window_root == NULL)
gui_window_root = (GdkWindow *)GDK_ROOT_PARENT();
if((width <= 0) || (height <= 0))
return(NULL);
return(gdk_pixmap_new(gui_window_root, width, height, -1));
}
/*
* Creates a new GdkPixmap from the specified XPM data.
*/
GdkPixmap *GDK_PIXMAP_NEW_FROM_XPM_DATA(
GdkBitmap **mask_rtn, guint8 **data
)
{
GdkPixmap *pixmap;
GdkBitmap *mask;
GdkWindow *window;
GtkStyle *style;
if(mask_rtn != NULL)
*mask_rtn = NULL;
if(data == NULL)
return(NULL);
if(gui_window_root == NULL)
gui_window_root = (GdkWindow *)GDK_ROOT_PARENT();
if(gui_style_default == NULL)
gui_style_default = gtk_widget_get_default_style();
window = gui_window_root;
style = gui_style_default;
/* Create a new pixmap from data */
pixmap = gdk_pixmap_create_from_xpm_d(
window, &mask,
(style != NULL) ? &style->bg[GTK_STATE_NORMAL] : NULL,
(gchar **)data
);
if(pixmap == NULL)
return(NULL);
if(mask_rtn != NULL)
*mask_rtn = mask;
else
GDK_BITMAP_UNREF(mask);
return(pixmap);
}
/*
* Creates a new GdkPixmap from the specified XPM file.
*/
GdkPixmap *GDK_PIXMAP_NEW_FROM_XPM_FILE(
GdkBitmap **mask_rtn, const gchar *filename
)
{
GdkPixmap *pixmap;
GdkBitmap *mask;
GdkWindow *window;
GtkStyle *style;
if(mask_rtn != NULL)
*mask_rtn = NULL;
if(STRISEMPTY(filename))
return(NULL);
if(gui_window_root == NULL)
gui_window_root = (GdkWindow *)GDK_ROOT_PARENT();
if(gui_style_default == NULL)
gui_style_default = gtk_widget_get_default_style();
window = gui_window_root;
style = gui_style_default;
/* Create a new pixmap from file */
pixmap = gdk_pixmap_create_from_xpm(
window, &mask,
(style != NULL) ? &style->bg[GTK_STATE_NORMAL] : NULL,
filename
);
if(pixmap == NULL)
return(NULL);
if(mask_rtn != NULL)
*mask_rtn = mask;
else
GDK_BITMAP_UNREF(mask);
return(pixmap);
}
/*
* Creates a new GtkPixmap from the given XPM data.
*/
GtkWidget *gtk_pixmap_new_from_xpm_d(
GdkWindow *window, GdkColor *transparent_color,
guint8 **data
)
{
GdkPixmap *pixmap;
GdkBitmap *mask;
GtkWidget *w;
if(gui_window_root == NULL)
gui_window_root = (GdkWindow *)GDK_ROOT_PARENT();
if(gui_style_default == NULL)
gui_style_default = gtk_widget_get_default_style();
if(window == NULL)
window = gui_window_root;
if(transparent_color == NULL)
{
GtkStyle *style = gui_style_default;
if(style != NULL)
transparent_color = &style->bg[GTK_STATE_NORMAL];
}
/* Load pixmap and mask */
pixmap = gdk_pixmap_create_from_xpm_d(
window, &mask, transparent_color, (gchar **)data
);
if(pixmap != NULL)
{
/* Create new GtkPixmap from the loaded pixmap and mask */
w = gtk_pixmap_new(pixmap, mask);
}
else
{
w = NULL;
}
/* Unref pixmap and mask pair, they are no longer needed */
GDK_PIXMAP_UNREF(pixmap);
GDK_BITMAP_UNREF(mask);
return(w);
}
/*
* Creates a new GtkPixmap from the given XPM data.
*/
GtkWidget *GUICreateMenuItemIcon(guint8 **icon_data)
{
gint width = 0, height = 0;
GdkWindow *window;
GdkPixmap *pixmap = NULL;
GdkBitmap *mask = NULL;
GtkStyle *style;
GtkWidget *w = NULL;
if(gui_window_root == NULL)
gui_window_root = (GdkWindow *)GDK_ROOT_PARENT();
if(gui_style_default == NULL)
gui_style_default = gtk_widget_get_default_style();
window = gui_window_root;
style = gui_style_default;
/* If no icon data specified, then use default empty icon */
if(icon_data == NULL)
{
gchar *bitmap_data;
/* Set width and height of blank icon */
width = GUI_MENU_ITEM_DEF_HEIGHT;
height = width;
/* Allocate tempory bitmap data and create the GdkBitmap mask */
bitmap_data = (gchar *)g_malloc0(
(((width / 8) + 1) * height) * sizeof(gchar)
);
if(bitmap_data != NULL)
mask = gdk_bitmap_create_from_data(
window, bitmap_data,
width, height
);
else
mask = NULL;
/* Delete tempory bitmap data, it is no longer needed */
g_free(bitmap_data);
/* Create blank GdkPixmap */
pixmap = gdk_pixmap_new(
window, width, height, -1
);
/* Pixmap created successfully? */
if(pixmap != NULL)
{
/* Create a GtkPixmap based on new pixmap and mask pair */
w = gtk_pixmap_new(pixmap, mask);
}
}
else
{
/* Create pixmap and mask pair from given data */
pixmap = gdk_pixmap_create_from_xpm_d(
window, &mask,
(style != NULL) ?
&style->bg[GTK_STATE_NORMAL] : NULL,
(gchar **)icon_data
);
/* Pixmap created successfully? */
if(pixmap != NULL)
{
/* Create a GtkPixmap based on new pixmap and mask pair */
w = gtk_pixmap_new(pixmap, mask);
/* Get size of newly loaded pixmap */
gdk_window_get_size((GdkWindow *)pixmap, &width, &height);
}
}
/* Unref pixmap and mask pair, they are no longer needed */
GDK_PIXMAP_UNREF(pixmap);
GDK_BITMAP_UNREF(mask);
return(w);
}
/*
* Maps the GtkWidget.
*
* If the GtkWidget is a GtkWindow then it will be raised.
*/
void GUIWidgetMapRaise(GtkWidget *w)
{
if(w == NULL)
return;
gtk_widget_show(w);
if(GTK_IS_WINDOW(w))
gdk_window_raise(w->window);
}
/*
* Minimizes (iconifies) the GtkWindow.
*/
void GUIWindowMinimize(GtkWindow *window)
{
#ifdef _XLIB_H_
Display *dpy;
Window xwin;
GdkWindow *win;
gint scr_num;
if(window == NULL)
return;
if(!GTK_WIDGET_REALIZED(GTK_WIDGET(window)))
return;
win = GTK_WIDGET(window)->window;
if(win == NULL)
return;
dpy = GDK_WINDOW_XDISPLAY(win);
xwin = GDK_WINDOW_XWINDOW(win);
if((dpy == NULL) || (xwin == None))
return;
scr_num = DefaultScreen(dpy);
XIconifyWindow(dpy, xwin, scr_num);
#endif /* _XLIB_H_ */
}
/*
* Creates the global gui_tooltips widget for controlling the
* enabled/disabled state of all tooltips set by these functions.
*
* When the global gui_tooltips widget is first created, the
* tooltips will be enabled and gui_tooltips_state will be reset
* to TRUE.
*/
static void GUICreateGlobalTooltips(void)
{
/* Need to create global gui_tooltips widget? */
if(gui_tooltips == NULL)
{
GtkWidget *w = (GtkWidget *)gtk_tooltips_new();
gui_tooltips = (GtkTooltips *)w;
if(w != NULL)
{
gtk_tooltips_enable(GTK_TOOLTIPS(w));
gui_tooltips_state = TRUE;
}
}
}
/*
* Sets the tip for the given widget w, if the widget w already
* has a tip set then it will be changed to the new value.
*
* If tip is NULL then no tip will be set on the given widget.
*/
void GUISetWidgetTip(GtkWidget *w, const gchar *tip)
{
if(w == NULL)
return;
/* Create global tooltips as needed */
GUICreateGlobalTooltips();
if(gui_tooltips == NULL)
return;
if(tip != NULL)
{
gtk_tooltips_set_tip(
gui_tooltips, /* Our tooltips group */
w,
tip, NULL
);
}
else
{
gtk_tooltips_set_tip(
gui_tooltips, /* Our tooltips group */
w,
NULL, NULL
);
}
}
/*
* Makes the tooltip associated with the given widget shown
* immediatly if the widget has a tip defined. Also requires
* that the global gui_tooltips_state be TRUE, otherwise
* this function does nothing.
*/
void GUIShowTipsNow(GtkWidget *w)
{
GdkEventCrossing e;
GdkWindow *window;
if((w == NULL) || !gui_tooltips_state)
return;
if(GTK_WIDGET_NO_WINDOW(w))
return;
window = w->window;
if(window == NULL)
return;
/* Send a fake enter notify event to make widget think
* its time to show the tooltips. Note that the widget
* should be watching for the enter_notify_event.
*/
e.type = GDK_ENTER_NOTIFY;
e.window = window;
e.send_event = 1; /* True if we're sending event */
e.subwindow = window;
e.time = GDK_CURRENT_TIME;
e.x = 0.0;
e.y = 0.0;
e.x_root = 0.0;
e.y_root = 0.0;
e.mode = GDK_CROSSING_NORMAL;
e.detail = GDK_NOTIFY_ANCESTOR;
e.focus = TRUE; /* Focus */
e.state = 0; /* Key modifiers */
gdk_event_put((GdkEvent *)&e);
}
/*
* Enables/disables global tooltips state.
*/
void GUISetGlobalTipsState(gboolean state)
{
/* Create global tooltips as needed */
GUICreateGlobalTooltips();
if(gui_tooltips == NULL)
return;
if(state)
gtk_tooltips_enable(gui_tooltips);
else
gtk_tooltips_disable(gui_tooltips);
/* Update global tool tips state */
gui_tooltips_state = (state) ? TRUE : FALSE;
}
/*
* Changes the button layout.
*
* The button must be one created by GUIButtonPixmap*()
* or GUIToggleButtonPixmap*().
*/
void GUIButtonChangeLayout(
GtkWidget *w, gboolean show_pixmap, gboolean show_label)
{
gui_button_data_struct *btn_data = GUI_BUTTON_DATA(
GTK_OBJECT_GET_DATA(w, GUI_BUTTON_DATA_KEY)
);
if(btn_data == NULL)
return;
w = btn_data->label;
if(w != NULL)
{
if(show_label)
gtk_widget_show(w);
else
gtk_widget_hide(w);
}
w = btn_data->pixmap;
if(w != NULL)
{
if(show_pixmap)
gtk_widget_show(w);
else
gtk_widget_hide(w);
}
w = btn_data->arrow;
if(w != NULL)
{
if(show_pixmap)
gtk_widget_show(w);
else
gtk_widget_hide(w);
}
}
/*
* Underlines the specified character in the button's label.
*/
void GUIButtonLabelUnderline(GtkWidget *w, guint c)
{
gui_button_data_struct *btn_data = GUI_BUTTON_DATA(
GTK_OBJECT_GET_DATA(w, GUI_BUTTON_DATA_KEY)
);
if(btn_data == NULL)
return;
if((btn_data->label != NULL) && (btn_data->label_text != NULL))
{
GtkWidget *w = btn_data->label;
const gchar *text = btn_data->label_text;
gchar *s, *pattern = STRDUP(text);
gint i = (gint)toupper((gint)c);
for(s = pattern; *s != '\0'; s++)
{
if((gint)toupper((gint)*s) == i)
{
*s = '_';
i = '\0';
}
else
{
*s = ' ';
}
}
gtk_label_set_pattern(GTK_LABEL(w), pattern);
g_free(pattern);
}
}
/*
* Changes the button's icon and/or label.
*
* If any value is NULL then it will not be modified.
*
* The button must be one returned from GUIButtonPixmap*()
* or GUIToggleButtonPixmap*().
*/
void GUIButtonPixmapUpdate(
GtkWidget *w, guint8 **icon, const gchar *label
)
{
GtkWidget *parent;
gui_button_data_struct *btn_data = GUI_BUTTON_DATA(
GTK_OBJECT_GET_DATA(w, GUI_BUTTON_DATA_KEY)
);
if(btn_data == NULL)
return;
if(gui_window_root == NULL)
gui_window_root = (GdkWindow *)GDK_ROOT_PARENT();
parent = btn_data->main_box;
if(parent == NULL)
return;
/* Update icon? */
if((icon != NULL) &&
((const guint8 **)icon != btn_data->icon_data)
)
{
GtkStyle *style = gtk_widget_get_style(btn_data->button);
GdkWindow *window = gui_window_root;
if((style != NULL) && (window != NULL))
{
GdkBitmap *mask;
GdkPixmap *pixmap = gdk_pixmap_create_from_xpm_d(
window, &mask,
&style->bg[GTK_STATE_NORMAL],
(gchar **)icon
);
if(pixmap != NULL)
{
gint width, height;
gdk_window_get_size(pixmap, &width, &height);
/* Record icon data pointer */
btn_data->icon_data = (const guint8 **)icon;
/* Set new icon pixmap */
w = btn_data->pixmap;
if(w != NULL)
{
gtk_pixmap_set(GTK_PIXMAP(w), pixmap, mask);
}
else
{
btn_data->pixmap = w = gtk_pixmap_new(pixmap, mask);
gtk_box_pack_start(GTK_BOX(parent), w, TRUE, FALSE, 0);
gtk_widget_show(w);
}
if(w != NULL)
{
gtk_widget_set_usize(
w,
width + (2 * 0),
height + (2 * 0)
);
}
/* Unref the loaded pixmap and mask pair, they are
* no longer needed
*/
GDK_PIXMAP_UNREF(pixmap);
GDK_BITMAP_UNREF(mask);
}
}
}
/* Update label text? */
if(label != NULL)
{
w = btn_data->label;
if(w != NULL)
{
/* Change in label text? */
if((btn_data->label_text != NULL) ?
strcmp(btn_data->label_text, label) : TRUE
)
{
/* Set new label text */
g_free(btn_data->label_text);
btn_data->label_text = STRDUP(label);
gtk_label_set_text(GTK_LABEL(w), btn_data->label_text);
}
}
}
}
/*
* Changes the button's arrow and/or label.
*/
void GUIButtonArrowUpdate(
GtkWidget *w,
GtkArrowType arrow_type, gint arrow_width, gint arrow_height,
const gchar *label
)
{
GtkWidget *parent;
gui_button_data_struct *btn_data = GUI_BUTTON_DATA(
GTK_OBJECT_GET_DATA(w, GUI_BUTTON_DATA_KEY)
);
if(btn_data == NULL)
return;
parent = btn_data->main_box;
if(parent == NULL)
return;
/* Update arrow? */
if(arrow_type >= 0)
{
w = btn_data->arrow;
if(w != NULL)
{
if(btn_data->arrow_type != arrow_type)
{
btn_data->arrow_type = arrow_type;
gtk_arrow_set(
GTK_ARROW(w),
btn_data->arrow_type,
GTK_SHADOW_OUT
);
}
gtk_widget_set_usize(w, arrow_width, arrow_height);
}
}
/* Update label text? */
if(label != NULL)
{
w = btn_data->label;
if(w != NULL)
{
/* Change in label text? */
if((btn_data->label_text != NULL) ?
strcmp(btn_data->label_text, label) : TRUE
)
{
/* Set new label text */
g_free(btn_data->label_text);
btn_data->label_text = STRDUP(label);
gtk_label_set_text(GTK_LABEL(w), btn_data->label_text);
}
}
}
}
/*
* Gets the button's main GtkBox.
*/
GtkWidget *GUIButtonGetMainBox(GtkWidget *w)
{
gui_button_data_struct *btn_data = GUI_BUTTON_DATA(
GTK_OBJECT_GET_DATA(w, GUI_BUTTON_DATA_KEY)
);
return((btn_data != NULL) ? btn_data->main_box : NULL);
}
/*
* Gets the button's GtkLabel.
*/
GtkWidget *GUIButtonGetLabel(GtkWidget *w)
{
gui_button_data_struct *btn_data = GUI_BUTTON_DATA(
GTK_OBJECT_GET_DATA(w, GUI_BUTTON_DATA_KEY)
);
return((btn_data != NULL) ? btn_data->label : NULL);
}
/*
* Gets the button's GtkPixmap.
*/
GtkWidget *GUIButtonGetPixmap(GtkWidget *w)
{
gui_button_data_struct *btn_data = GUI_BUTTON_DATA(
GTK_OBJECT_GET_DATA(w, GUI_BUTTON_DATA_KEY)
);
return((btn_data != NULL) ? btn_data->pixmap : NULL);
}
/*
* Gets the button's GtkArrow.
*/
GtkWidget *GUIButtonGetArrow(GtkWidget *w)
{
gui_button_data_struct *btn_data = GUI_BUTTON_DATA(
GTK_OBJECT_GET_DATA(w, GUI_BUTTON_DATA_KEY)
);
return((btn_data != NULL) ? btn_data->arrow : NULL);
}
/*
* Gets the button's label text.
*/
gchar *GUIButtonGetLabelText(GtkWidget *w)
{
gui_button_data_struct *btn_data = GUI_BUTTON_DATA(
GTK_OBJECT_GET_DATA(w, GUI_BUTTON_DATA_KEY)
);
return((btn_data != NULL) ? btn_data->label_text : NULL);
}
/*
* GtkButton creation nexus.
*/
static GtkWidget *GUIButtonPixmapLabelHV(
guint8 **icon, const gchar *label, GtkWidget **label_rtn,
gboolean horizontal
)
{
const gint border = (label != NULL) ? 1 : 0;
GtkWidget *w, *parent;
gui_button_data_struct *btn_data;
if(label_rtn != NULL)
*label_rtn = NULL;
if(gui_window_root == NULL)
gui_window_root = (GdkWindow *)GDK_ROOT_PARENT();
/* Create callback data */
btn_data = GUI_BUTTON_DATA(
g_malloc0(sizeof(gui_button_data_struct))
);
/* Create button */
btn_data->button = w = gtk_button_new();
gtk_object_set_data_full(
GTK_OBJECT(w), GUI_BUTTON_DATA_KEY,
btn_data, GUIButtonDataDestroyCB
);
parent = w;
/* Create main box */
if(horizontal)
w = gtk_hbox_new(FALSE, 0);
else
w = gtk_vbox_new(FALSE, 0);
gtk_container_border_width(GTK_CONTAINER(w), 0);
gtk_container_add(GTK_CONTAINER(parent), w);
gtk_widget_show(w);
btn_data->main_box = parent = w;
/* Create icon? */
if(icon != NULL)
{
GdkWindow *window = gui_window_root;
GtkStyle *style = gtk_widget_get_style(btn_data->button);
if(style != NULL)
{
GdkBitmap *mask;
GdkPixmap *pixmap = gdk_pixmap_create_from_xpm_d(
window, &mask,
&style->bg[GTK_STATE_NORMAL], (gchar **)icon
);
if(pixmap != NULL)
{
gint width, height;
gdk_window_get_size(pixmap, &width, &height);
btn_data->icon_data = (const guint8 **)icon;
btn_data->pixmap = w = gtk_pixmap_new(pixmap, mask);
gtk_widget_set_usize(
w,
width + (2 * 0),
height + (2 * 0)
);
gtk_box_pack_start(
GTK_BOX(parent), w, TRUE, FALSE, border
);
gtk_widget_show(w);
GDK_PIXMAP_UNREF(pixmap);
GDK_BITMAP_UNREF(mask);
}
}
}
/* Create label? */
if(label != NULL)
{
btn_data->label_text = STRDUP(label);
btn_data->label = w = gtk_label_new(btn_data->label_text);
if(label_rtn != NULL)
*label_rtn = w;
gtk_label_set_justify(
GTK_LABEL(w),
horizontal ? GTK_JUSTIFY_LEFT : GTK_JUSTIFY_CENTER
);
gtk_box_pack_start(
GTK_BOX(parent), w, TRUE, FALSE, border
);
gtk_widget_show(w);
}
return(btn_data->button);
}
/*
* Creates a horizonal GtkButton with the specified icon and
* label.
*/
GtkWidget *GUIButtonPixmapLabelH(
guint8 **icon, const gchar *label, GtkWidget **label_rtn
)
{
return(GUIButtonPixmapLabelHV(icon, label, label_rtn, 1));
}
/*
* Creates a vertical GtkButton with the specified icon and
* label.
*/
GtkWidget *GUIButtonPixmapLabelV(
guint8 **icon, const gchar *label, GtkWidget **label_rtn
)
{
return(GUIButtonPixmapLabelHV(icon, label, label_rtn, 0));
}
/*
* Creates a GtkButton with the specified icon.
*/
GtkWidget *GUIButtonPixmap(guint8 **icon)
{
return(
GUIButtonPixmapLabelH(icon, NULL, NULL)
);
}
/*
* GtkButton with Arrow creation nexus.
*/
static GtkWidget *GUIButtonArrowLabelHV(
GtkArrowType arrow_type, gint arrow_width, gint arrow_height,
const gchar *label, GtkWidget **label_rtn,
gboolean horizontal
)
{
const gint border = (label != NULL) ? 1 : 0;
GtkWidget *w, *parent;
gui_button_data_struct *btn_data;
if(label_rtn != NULL)
*label_rtn = NULL;
/* Create callback data */
btn_data = GUI_BUTTON_DATA(
g_malloc0(sizeof(gui_button_data_struct))
);
/* Create button */
btn_data->button = w = gtk_button_new();
gtk_object_set_data_full(
GTK_OBJECT(w), GUI_BUTTON_DATA_KEY,
btn_data, GUIButtonDataDestroyCB
);
parent = w;
/* Create main box */
if(horizontal)
w = gtk_hbox_new(FALSE, 0);
else
w = gtk_vbox_new(FALSE, 0);
gtk_container_border_width(GTK_CONTAINER(w), 0);
gtk_container_add(GTK_CONTAINER(parent), w);
gtk_widget_show(w);
btn_data->main_box = parent = w;
/* Create arrow */
btn_data->arrow_type = arrow_type;
btn_data->arrow = w = gtk_arrow_new(
btn_data->arrow_type,
GTK_SHADOW_OUT
);
gtk_widget_set_usize(
w,
(arrow_width > 0) ? arrow_width : 20,
(arrow_height > 0) ? arrow_height : 20
);
gtk_box_pack_start(
GTK_BOX(parent), w, TRUE, FALSE, border
);
gtk_widget_show(w);
/* Create label? */
if(label != NULL)
{
btn_data->label_text = STRDUP(label);
btn_data->label = w = gtk_label_new(btn_data->label_text);
if(label_rtn != NULL)
*label_rtn = w;
gtk_label_set_justify(
GTK_LABEL(w),
horizontal ? GTK_JUSTIFY_LEFT : GTK_JUSTIFY_CENTER
);
gtk_box_pack_start(
GTK_BOX(parent), w, TRUE, FALSE, border
);
gtk_widget_show(w);
}
return(btn_data->button);
}
/*
* Creates a horizontal GtkButton with the specified arrow and
* label.
*/
GtkWidget *GUIButtonArrowLabelH(
GtkArrowType arrow_type, gint arrow_width, gint arrow_height,
const gchar *label, GtkWidget **label_rtn
)
{
return(GUIButtonArrowLabelHV(
arrow_type, arrow_width, arrow_height,
label, label_rtn, TRUE
));
}
/*
* Creates a vertical GtkButton with the specified arrow and
* label.
*/
GtkWidget *GUIButtonArrowLabelV(
GtkArrowType arrow_type, gint arrow_width, gint arrow_height,
const gchar *label, GtkWidget **label_rtn
)
{
return(GUIButtonArrowLabelHV(
arrow_type, arrow_width, arrow_height,
label, label_rtn, FALSE
));
}
/*
* Creates a GtkButton with the specified arrow.
*/
GtkWidget *GUIButtonArrow(
GtkArrowType arrow_type, gint arrow_width, gint arrow_height
)
{
return(GUIButtonArrowLabelHV(
arrow_type, arrow_width, arrow_height,
NULL, NULL, FALSE
));
}
/*
* GtkToggleButton creation nexus.
*/
GtkWidget *GUIToggleButtonPixmapLabelHV(
guint8 **icon, const gchar *label, GtkWidget **label_rtn,
gboolean horizontal
)
{
const gint border = (label != NULL) ? 1 : 0;
GtkWidget *w, *parent;
gui_button_data_struct *btn_data;
if(label_rtn != NULL)
*label_rtn = NULL;
if(gui_window_root == NULL)
gui_window_root = (GdkWindow *)GDK_ROOT_PARENT();
/* Create callback data */
btn_data = GUI_BUTTON_DATA(
g_malloc0(sizeof(gui_button_data_struct))
);
/* Create button */
btn_data->button = w = gtk_toggle_button_new();
gtk_object_set_data_full(
GTK_OBJECT(w), GUI_BUTTON_DATA_KEY,
btn_data, GUIButtonDataDestroyCB
);
parent = w;
/* Create main box */
if(horizontal)
w = gtk_hbox_new(FALSE, 0);
else
w = gtk_vbox_new(FALSE, 0);
gtk_container_border_width(GTK_CONTAINER(w), 0);
gtk_container_add(GTK_CONTAINER(parent), w);
gtk_widget_show(w);
btn_data->main_box = parent = w;
/* Create icon? */
if(icon != NULL)
{
GdkWindow *window = gui_window_root;
GtkStyle *style = gtk_widget_get_style(btn_data->button);
if(style != NULL)
{
GdkBitmap *mask;
GdkPixmap *pixmap = gdk_pixmap_create_from_xpm_d(
window, &mask,
&style->bg[GTK_STATE_NORMAL], (gchar **)icon
);
if(pixmap != NULL)
{
gint width, height;
gdk_window_get_size(pixmap, &width, &height);
btn_data->icon_data = (const guint8 **)icon;
btn_data->pixmap = w = gtk_pixmap_new(pixmap, mask);
gtk_widget_set_usize(
w,
width + (2 * 0),
height + (2 * 0)
);
gtk_box_pack_start(
GTK_BOX(parent), w, TRUE, FALSE, border
);
gtk_widget_show(w);
GDK_PIXMAP_UNREF(pixmap);
GDK_BITMAP_UNREF(mask);
}
}
}
/* Create label? */
if(label != NULL)
{
btn_data->label_text = STRDUP(label);
btn_data->label = w = gtk_label_new(btn_data->label_text);
if(label_rtn != NULL)
*label_rtn = w;
gtk_label_set_justify(
GTK_LABEL(w),
horizontal ? GTK_JUSTIFY_LEFT : GTK_JUSTIFY_CENTER
);
gtk_box_pack_start(
GTK_BOX(parent), w, TRUE, FALSE, border
);
gtk_widget_show(w);
}
return(btn_data->button);
}
/*
* Creates a horizonal GtkToggleButton with the specified icon and
* label.
*/
GtkWidget *GUIToggleButtonPixmapLabelH(
guint8 **icon, const gchar *label, GtkWidget **label_rtn
)
{
return(GUIToggleButtonPixmapLabelHV(icon, label, label_rtn, 1));
}
/*
* Creates a vertical GtkToggleButton with the specified icon and
* label.
*/
GtkWidget *GUIToggleButtonPixmapLabelV(
guint8 **icon, const gchar *label, GtkWidget **label_rtn
)
{
return(GUIToggleButtonPixmapLabelHV(icon, label, label_rtn, 0));
}
/*
* Creates a GtkToggleButton with the specified icon.
*/
GtkWidget *GUIToggleButtonPixmap(guint8 **icon)
{
return(GUIToggleButtonPixmapLabelHV(icon, NULL, NULL, 0));
}
/*
* Prompt creation nexus
*/
static GtkWidget *GUIPromptBarOrBrowse(
guint8 **icon, const gchar *label,
gpointer *label_rtn, gpointer *entry_rtn, gpointer *browse_rtn
)
{
const gint border_minor = 2;
gint attach_x, attach_y;
GtkWidget *parent, *w;
/* Reset returns */
if(label_rtn != NULL)
*label_rtn = NULL;
if(entry_rtn != NULL)
*entry_rtn = NULL;
if(browse_rtn != NULL)
*browse_rtn = NULL;
if(gui_window_root == NULL)
gui_window_root = (GdkWindow *)GDK_ROOT_PARENT();
/* Create prompt bar parent */
parent = w = gtk_table_new(
1,
((icon != NULL) ? 1 : 0) +
((label != NULL) ? 1 : 0) +
1 +
((browse_rtn != NULL) ? 1 : 0),
FALSE
);
gtk_table_set_col_spacings(GTK_TABLE(w), border_minor);
attach_x = 0;
attach_y = 0;
/* Create icon */
if(icon != NULL)
{
GdkWindow *window = gui_window_root;
GtkStyle *style = gtk_widget_get_style(parent);
GdkBitmap *mask;
GdkPixmap *pixmap = gdk_pixmap_create_from_xpm_d(
window, &mask,
(style != NULL) ? &style->bg[GTK_STATE_NORMAL] : NULL,
(gchar **)icon
);
if(pixmap != NULL)
{
gint width, height;
gdk_window_get_size(pixmap, &width, &height);
attach_x = 0;
w = gtk_pixmap_new(pixmap, mask);
gtk_widget_set_usize(w, width, height);
gtk_table_attach(
GTK_TABLE(parent), w,
(guint)attach_x, (guint)(attach_x + 1),
(guint)attach_y, (guint)(attach_y + 1),
0,
0,
0, 0
);
gtk_widget_show(w);
GDK_PIXMAP_UNREF(pixmap);
GDK_BITMAP_UNREF(mask);
}
}
/* Create label? */
if(label != NULL)
{
attach_x = (icon != NULL) ? 1 : 0;
w = gtk_label_new(label);
if(label_rtn != NULL)
*label_rtn = w;
gtk_label_set_justify(GTK_LABEL(w), GTK_JUSTIFY_RIGHT);
gtk_table_attach(
GTK_TABLE(parent), w,
(guint)attach_x, (guint)(attach_x + 1),
(guint)attach_y, (guint)(attach_y + 1),
0,
0,
0, 0
);
gtk_widget_show(w);
}
/* Create text entry? */
if(TRUE)
{
attach_x = ((icon != NULL) ? 1 : 0) +
((label != NULL) ? 1 : 0);
w = gtk_entry_new();
if(entry_rtn != NULL)
*entry_rtn = w;
gtk_table_attach(
GTK_TABLE(parent), w,
(guint)attach_x, (guint)(attach_x + 1),
(guint)attach_y, (guint)(attach_y + 1),
GTK_SHRINK | GTK_EXPAND | GTK_FILL,
0,
0, 0
);
gtk_widget_show(w);
}
/* Create browse button? */
if(browse_rtn != NULL)
{
attach_x = ((icon != NULL) ? 1 : 0) +
((label != NULL) ? 1 : 0) +
1;
w = GUIButtonPixmap(
(guint8 **)icon_browse_20x20_xpm
);
*browse_rtn = w;
gtk_table_attach(
GTK_TABLE(parent), w,
(guint)attach_x, (guint)(attach_x + 1),
(guint)attach_y, (guint)(attach_y + 1),
0,
0,
0, 0
);
gtk_widget_show(w);
}
return(parent);
}
/*
* Creates a new prompt with an icon, label, entry, and browse
* button.
*/
GtkWidget *GUIPromptBarWithBrowse(
guint8 **icon, const gchar *label,
gpointer *label_rtn, gpointer *entry_rtn, gpointer *browse_rtn,
gpointer browse_data, void (*browse_cb)(GtkWidget *, gpointer)
)
{
GtkWidget *parent;
parent = GUIPromptBarOrBrowse(
icon, label, label_rtn, entry_rtn, browse_rtn
);
/* Set signal callback for the browse button */
if((browse_rtn != NULL) && (browse_cb != NULL))
{
GtkWidget *w = (GtkWidget *)*browse_rtn;
if(w != NULL)
gtk_signal_connect(
GTK_OBJECT(w), "clicked",
GTK_SIGNAL_FUNC(browse_cb), browse_data
);
}
return(parent);
}
/*
* Creates a new prompt with an icon, label, and entry.
*/
GtkWidget *GUIPromptBar(
guint8 **icon, const gchar *label,
gpointer *label_rtn, gpointer *entry_rtn
)
{
return(GUIPromptBarOrBrowse(
icon, label, label_rtn, entry_rtn, NULL
));
}
/*
* Sets the DDE as binary data.
*/
void GUIDDESetBinary(
GtkWidget *w, /* Owner widget */
GdkAtom selection_atom, /* Can be GDK_NONE */
gulong t, /* Time */
const guint8 *data, gint length
)
{
static GdkAtom target_atom = GDK_NONE;
guint8 *datau8;
gui_dde_owner_struct *owner;
if(target_atom == GDK_NONE)
target_atom = gdk_atom_intern("STRING", FALSE);
if(selection_atom == GDK_NONE)
selection_atom = GDK_SELECTION_PRIMARY;
if((w == NULL) || (data == NULL) || (length <= 0))
return;
if(GTK_WIDGET_NO_WINDOW(w))
{
g_printerr(
"GUIDDESetBinary(): Failed:\
GtkWidget 0x%.8x does not have a GdkWindow.\n",
(guint32)w
);
return;
}
/* Allocate callback data */
owner = GUI_DDE_OWNER(g_malloc0(sizeof(gui_dde_owner_struct)));
owner->w = w;
owner->target_atom = target_atom;
owner->type_atom = target_atom;
owner->selection_clear_event_id = gtk_signal_connect(
GTK_OBJECT(w), "selection_clear_event",
GTK_SIGNAL_FUNC(GUIDDESelectionClearEventCB),
owner
);
owner->selection_get_id = gtk_signal_connect(
GTK_OBJECT(w), "selection_get",
GTK_SIGNAL_FUNC(GUIDDESelectionGetCB),
owner
);
datau8 = (guint8 *)g_malloc((length + 1) * sizeof(guint8));
memcpy(datau8, data, length * sizeof(guint8));
datau8[length] = '\0';
owner->data = datau8;
owner->length = length;
/* Set owner callback data on the widget, destroying any
* previously set owner callback data on the widget
*/
gtk_object_set_data_full(
GTK_OBJECT(w), GUI_DDE_OWNER_DATA_KEY,
owner, GUIDDEOwnerDestroyCB
);
/* Set the widget as supporting the selection of the
* specified type
*/
gtk_selection_add_target(
w, /* Widget */
selection_atom, /* Selection */
target_atom, /* Target */
0 /* Info */
);
/* Set selection owner */
if(!gtk_selection_owner_set(
w, /* Owner GtkWidget */
selection_atom, /* Selection */
(guint32)t /* Time */
))
{
/* Failed to set selection owner */
gtk_object_remove_data(
GTK_OBJECT(w), GUI_DDE_OWNER_DATA_KEY
);
return;
}
}
/*
* Gets the DDE as binary data.
*/
guint8 *GUIDDEGetBinary(
GtkWidget *w, /* Widget making request */
GdkAtom selection_atom, /* Can be GDK_NONE */
gulong t, /* Time */
gint *length
)
{
guint8 *data;
gint len;
guint sig_id;
GdkAtom type;
GtkSelectionData *selection_data;
static GdkAtom target_atom = GDK_NONE;
if(target_atom == GDK_NONE)
target_atom = gdk_atom_intern("STRING", FALSE);
if(length != NULL)
*length = 0;
if(selection_atom == GDK_NONE)
selection_atom = GDK_SELECTION_PRIMARY;
if(w == NULL)
return(NULL);
if(GTK_WIDGET_NO_WINDOW(w))
{
g_printerr(
"GUIDDEGetBinary(): Failed:\
GtkWidget 0x%.8x does not have a GdkWindow.\n",
(guint32)w
);
return(NULL);
}
/* Set up callback data */
selection_data = (GtkSelectionData *)g_malloc0(
sizeof(GtkSelectionData)
);
selection_data->selection = selection_atom;
selection_data->target = target_atom;
selection_data->type = GDK_NONE;
selection_data->format = -1;
selection_data->data = NULL;
selection_data->length = -1; /* -1 means data not received */
/* Set up widget to receive the "selection_received" signal */
sig_id = gtk_signal_connect(
GTK_OBJECT(w), "selection_received",
GTK_SIGNAL_FUNC(GUIDDESelectionReceivedCB),
selection_data
);
/* Request selection */
if(!gtk_selection_convert(
w, /* Widget */
selection_atom, /* Selection */
target_atom, /* Target */
(guint32)t /* Time */
))
{
/* Selection request failed */
GTK_SIGNAL_DISCONNECT(GTK_OBJECT(w), sig_id)
g_free(selection_data->data);
g_free(selection_data);
return(NULL);
}
/* Wait for selection */
while(selection_data->length < 0)
{
while(gtk_events_pending() > 0)
gtk_main_iteration();
}
/* Got selection */
/* Disconnect signals */
GTK_SIGNAL_DISCONNECT(GTK_OBJECT(w), sig_id);
/* Get data from selection from callback data */
type = selection_data->type;
/* Integer */
if(type == GDK_SELECTION_TYPE_INTEGER)
{
data = (guint8 *)selection_data->data;
selection_data->data = NULL;
len = selection_data->length;
}
/* String (latin-1 characters) */
else if(type == GDK_SELECTION_TYPE_STRING)
{
data = (guint8 *)selection_data->data;
selection_data->data = NULL;
len = selection_data->length;
}
else
{
data = NULL;
len = 0;
}
/* Delete callback data */
g_free(selection_data->data);
g_free(selection_data);
if(length != NULL)
*length = len;
return(data);
}
/*
* Sets the DDE as a string.
*/
void GUIDDESetString(
GtkWidget *w, /* Owner widget */
GdkAtom selection_atom, /* Selection */
gulong t, /* Time */
const gchar *data
)
{
static GdkAtom target_atom = GDK_NONE;
gui_dde_owner_struct *owner;
if(target_atom == GDK_NONE)
target_atom = gdk_atom_intern("STRING", FALSE);
if(selection_atom == GDK_NONE)
selection_atom = GDK_SELECTION_PRIMARY;
if((w == NULL) || (data == NULL))
return;
if(GTK_WIDGET_NO_WINDOW(w))
{
g_printerr(
"GUIDDESetString(): Failed:\
GtkWidget 0x%.8x does not have a GdkWindow.\n",
(guint32)w
);
return;
}
/* Allocate callback data */
owner = GUI_DDE_OWNER(g_malloc0(sizeof(gui_dde_owner_struct)));
owner->w = w;
owner->target_atom = target_atom;
owner->type_atom = target_atom;
owner->selection_clear_event_id = gtk_signal_connect(
GTK_OBJECT(w), "selection_clear_event",
GTK_SIGNAL_FUNC(GUIDDESelectionClearEventCB),
owner
);
owner->selection_get_id = gtk_signal_connect(
GTK_OBJECT(w), "selection_get",
GTK_SIGNAL_FUNC(GUIDDESelectionGetCB),
owner
);
owner->data = STRDUP(data);
owner->length = STRLEN(owner->data);
/* Set owner callback data on the widget, destroying any
* previously set owner callback data on the widget
*/
gtk_object_set_data_full(
GTK_OBJECT(w), GUI_DDE_OWNER_DATA_KEY,
owner, GUIDDEOwnerDestroyCB
);
/* Set the widget as supporting the selection of the
* specified type
*/
gtk_selection_add_target(
w, /* Widget */
selection_atom, /* Selection */
target_atom, /* Target */
0 /* Info */
);
/* Set selection owner */
if(!gtk_selection_owner_set(
w, /* Owner GtkWidget */
selection_atom, /* Selection */
(guint32)t /* Time */
))
{
/* Failed to set selection owner */
gtk_object_remove_data(
GTK_OBJECT(w), GUI_DDE_OWNER_DATA_KEY
);
return;
}
}
/*
* Gets the DDE as a string.
*
* The calling function must deallocate the returned pointer.
*/
gchar *GUIDDEGetString(
GtkWidget *w, /* Widget making request */
GdkAtom selection_atom, /* Can be GDK_NONE */
gulong t /* Time */
)
{
gchar *data;
guint sig_id;
GdkAtom type;
GtkSelectionData *selection_data;
static GdkAtom target_atom = GDK_NONE;
if(target_atom == GDK_NONE)
target_atom = gdk_atom_intern("STRING", FALSE);
if(selection_atom == GDK_NONE)
selection_atom = GDK_SELECTION_PRIMARY;
if(w == NULL)
return(NULL);
if(GTK_WIDGET_NO_WINDOW(w))
{
g_printerr(
"GUIDDEGetString(): Failed:\
GtkWidget 0x%.8x does not have a GdkWindow.\n",
(guint32)w
);
return(NULL);
}
/* Set up callback data */
selection_data = (GtkSelectionData *)g_malloc0(
sizeof(GtkSelectionData)
);
selection_data->selection = selection_atom;
selection_data->target = target_atom;
selection_data->type = GDK_NONE;
selection_data->format = -1;
selection_data->data = NULL;
selection_data->length = -1; /* -1 means data not received */
/* Set up widget to receive the "selection_received" signal */
sig_id = gtk_signal_connect(
GTK_OBJECT(w), "selection_received",
GTK_SIGNAL_FUNC(GUIDDESelectionReceivedCB),
selection_data
);
/* Request selection */
if(!gtk_selection_convert(
w, /* Widget */
selection_atom, /* Selection */
target_atom, /* Target */
(guint32)t /* Time */
))
{
/* Selection request failed */
GTK_SIGNAL_DISCONNECT(GTK_OBJECT(w), sig_id)
g_free(selection_data->data);
g_free(selection_data);
return(NULL);
}
/* Wait for selection */
while(selection_data->length < 0)
{
while(gtk_events_pending() > 0)
gtk_main_iteration();
}
/* Got selection */
/* Disconnect signals */
GTK_SIGNAL_DISCONNECT(GTK_OBJECT(w), sig_id);
/* Get data from selection from callback data */
type = selection_data->type;
/* Integer */
if(type == GDK_SELECTION_TYPE_INTEGER)
{
switch(selection_data->length)
{
case 1:
data = g_strdup_printf(
"%i",
*(gint8 *)selection_data->data
);
break;
case 2:
data = g_strdup_printf(
"%i",
*(gint16 *)selection_data->data
);
break;
case 4:
data = g_strdup_printf(
"%i",
*(gint32 *)selection_data->data
);
break;
case 8:
data = g_strdup_printf(
"%ld",
(long)(*(gint64 *)selection_data->data)
);
break;
default:
data = NULL;
break;
}
}
/* String (latin-1 characters) */
else if(type == GDK_SELECTION_TYPE_STRING)
{
data = (gchar *)selection_data->data;
selection_data->data = NULL;
}
else
{
data = NULL;
}
/* Delete callback data */
g_free(selection_data->data);
g_free(selection_data);
return(data);
}
/*
* Sets up widget as a DND drag source.
*/
void GUIDNDSetSrc(
void *w, const void *drag_type, int ndrag_types,
unsigned int actions, unsigned int buttons,
void (*begin_cb)(GtkWidget *, GdkDragContext *, gpointer),
void (*request_data_cb)(GtkWidget *, GdkDragContext *,
GtkSelectionData *, guint, guint, gpointer),
void (*delete_data_cb)(GtkWidget *, GdkDragContext *, gpointer),
void (*end_cb)(GtkWidget *, GdkDragContext *, gpointer),
gpointer client_data
)
{
GtkWidget *widget = (GtkWidget *)w;
const GtkTargetEntry *target_entry = (const GtkTargetEntry *)drag_type;
gint total_target_entries = (gint)ndrag_types;
if((widget == NULL) || (target_entry == NULL) ||
(total_target_entries <= 0)
)
return;
/* Widget must have window */
if(GTK_WIDGET_NO_WINDOW(widget))
{
g_printerr(
"GUIDNDSetSrc(): Widget does not have window.\n"
);
return;
}
/* Set the widget as a DND drag source */
gtk_drag_source_set(
widget,
buttons,
target_entry, total_target_entries,
actions
);
/* Set the "drag_begin" signal callback, our local callback must
* be connected before GTK internal drag begin callbacks
*/
gtk_signal_connect_after(
GTK_OBJECT(widget), "drag_begin",
GTK_SIGNAL_FUNC(GUIDNDDragBeginCB), NULL
);
if(begin_cb != NULL)
gtk_signal_connect_after(
GTK_OBJECT(widget), "drag_begin",
GTK_SIGNAL_FUNC(begin_cb), client_data
);
/* Set the "drag_data_get" signal callback */
if(request_data_cb != NULL)
gtk_signal_connect_after(
GTK_OBJECT(widget), "drag_data_get",
GTK_SIGNAL_FUNC(request_data_cb), client_data
);
/* Set the "drag_data_delete" signal callback */
if(delete_data_cb != NULL)
gtk_signal_connect_after(
GTK_OBJECT(widget), "drag_data_delete",
GTK_SIGNAL_FUNC(delete_data_cb), client_data
);
/* Set the "drag_end" signal callback */
if(end_cb != NULL)
gtk_signal_connect_after(
GTK_OBJECT(widget), "drag_end",
GTK_SIGNAL_FUNC(end_cb), client_data
);
/* Set our own "drag_end" signal callback to be called after
* the one for the client function
*/
gtk_signal_connect_after(
GTK_OBJECT(widget), "drag_end",
GTK_SIGNAL_FUNC(GUIDNDDragEndCB), NULL
);
}
/*
* Sets up a widget as DND drop target.
*/
void GUIDNDSetTar(
void *w, const void *drag_type, int ndrag_types,
unsigned int actions, unsigned int default_action_same,
unsigned int default_action,
void (*recieved_data_cb)(GtkWidget *, GdkDragContext *,
gint, gint, GtkSelectionData *, guint, guint,
gpointer
),
gpointer client_data
)
{
static gboolean init_cb_structs = TRUE;
GtkWidget *widget = (GtkWidget *)w;
const GtkTargetEntry *target_entry = (const GtkTargetEntry *)drag_type;
gint total_target_entries = (gint)ndrag_types;
static gui_dnd_cb_struct move_same_cb_data,
move_cb_data,
copy_cb_data;
gui_dnd_cb_struct *cb_data_ptr = NULL;
if((widget == NULL) || (target_entry == NULL) ||
(total_target_entries <= 0)
)
return;
/* Widget must have window */
if(GTK_WIDGET_NO_WINDOW(widget))
{
g_printerr(
"GUIDNDSetTar(): Widget does not have window.\n"
);
return;
}
/* Set the widget as a DND drop target */
gtk_drag_dest_set(
widget,
GTK_DEST_DEFAULT_MOTION |
GTK_DEST_DEFAULT_HIGHLIGHT |
GTK_DEST_DEFAULT_DROP,
target_entry, total_target_entries,
actions
);
/* Do we need to initialize DND callback data? */
if(init_cb_structs)
{
move_same_cb_data.default_action_same = GDK_ACTION_MOVE;
move_same_cb_data.default_action = GDK_ACTION_COPY;
move_cb_data.default_action_same = GDK_ACTION_MOVE;
move_cb_data.default_action = GDK_ACTION_MOVE;
copy_cb_data.default_action_same = GDK_ACTION_COPY;
copy_cb_data.default_action = GDK_ACTION_COPY;
init_cb_structs = FALSE;
}
/* Set local drag motion callback data */
/* Move only on same? */
if((default_action_same == GDK_ACTION_MOVE) &&
(default_action == GDK_ACTION_COPY)
)
cb_data_ptr = &move_same_cb_data;
/* Always move? */
else if((default_action_same == GDK_ACTION_MOVE) &&
(default_action == GDK_ACTION_MOVE)
)
cb_data_ptr = &move_cb_data;
/* Always copy? */
else if((default_action_same == GDK_ACTION_COPY) &&
(default_action == GDK_ACTION_COPY)
)
cb_data_ptr = ©_cb_data;
#if 0
/* Set this target widget to highlight when a drag goes over it */
gtk_drag_highlight(widget);
#endif
/* Set our local drag motion callback */
gtk_signal_connect_after(
GTK_OBJECT(widget), "drag_motion",
GTK_SIGNAL_FUNC(GUIDNDDragMotionCB), cb_data_ptr
);
gtk_signal_connect_after(
GTK_OBJECT(widget), "drag_drop",
GTK_SIGNAL_FUNC(GUIDNDDragDropCB), cb_data_ptr
);
/* Set data received callback for local and calling functions */
gtk_signal_connect_after(
GTK_OBJECT(widget), "drag_data_received",
GTK_SIGNAL_FUNC(GUIDNDDragReceivedCB), cb_data_ptr
);
if(recieved_data_cb != NULL)
gtk_signal_connect_after(
GTK_OBJECT(widget), "drag_data_received",
GTK_SIGNAL_FUNC(recieved_data_cb), client_data
);
}
/*
* Sets the DND Icon for the next DND operation with the specified
* pixmap and mask.
*
* If pixmap is NULL then the DND Icon is destroyed/shutdown.
*/
void GUIDNDSetDragIcon(
GdkPixmap *pixmap, GdkBitmap *mask, gint hot_x, gint hot_y
)
{
gboolean is_pixmap_set = FALSE;
GdkWindow *window;
GtkWidget *w;
gui_dnd_icon_struct *dnd_icon = &gui_dnd_icon;
/* Destroy the DND Icon? */
if(pixmap == NULL)
{
w = dnd_icon->toplevel;
if(w != NULL)
{
GTK_WIDGET_DESTROY(dnd_icon->icon_pm)
GTK_WIDGET_DESTROY(dnd_icon->toplevel)
memset(dnd_icon, 0x00, sizeof(gui_dnd_icon_struct));
}
return;
}
/* Check if the DND Icon needs to be initialized for the very
* first time
*/
w = dnd_icon->toplevel;
if(w == NULL)
{
GtkWidget *parent;
dnd_icon->toplevel = w = gtk_window_new(GTK_WINDOW_POPUP);
gtk_widget_realize(w);
parent = w;
dnd_icon->icon_pm = w = gtk_pixmap_new(pixmap, mask);
gtk_container_add(GTK_CONTAINER(parent), w);
gtk_widget_show(w);
is_pixmap_set = TRUE;
}
/* Get the GdkWindow of the DND Icon toplevel */
w = dnd_icon->toplevel;
window = (w != NULL) ? w->window : NULL;
if(window == NULL)
return;
/* Begin setting up the DND Icon with the new values */
dnd_icon->x = hot_x;
dnd_icon->y = hot_y;
gdk_window_get_size(
pixmap, &dnd_icon->width, &dnd_icon->height
);
/* Adjust size and shape of the DND Icon's toplevel window */
gtk_widget_set_usize(w, dnd_icon->width, dnd_icon->height);
gdk_window_set_back_pixmap(window, pixmap, 0);
gtk_widget_shape_combine_mask(w, mask, 0, 0);
/* Set up the icon GtkPixmap */
w = dnd_icon->icon_pm;
if((w != NULL) && !is_pixmap_set)
{
gtk_pixmap_set(GTK_PIXMAP(w), pixmap, mask);
}
}
/*
* Creates a new Banner.
*/
GtkWidget *GUIBannerCreate(
const gchar *label,
const gchar *font_name,
GdkColor color_fg,
GdkColor color_bg,
GtkJustification justify, /* One of GTK_JUSTIFY_* */
gboolean expand
)
{
GdkFont *font = NULL;
GtkRcStyle *rcstyle;
GtkWidget *w = gtk_drawing_area_new();
gpointer *cb_data = (gpointer *)g_malloc0(
4 * sizeof(gpointer)
);
cb_data[0] = STRDUP(label);
cb_data[1] = (gpointer)justify;
cb_data[2] = font = (font_name != NULL) ?
gdk_font_load(font_name) : NULL;
cb_data[3] = NULL;
gtk_object_set_data_full(
GTK_OBJECT(w), GUI_BANNER_DATA_KEY,
cb_data, GUIBannerDataDestroyCB
);
gtk_widget_add_events(
w,
GDK_STRUCTURE_MASK | GDK_EXPOSURE_MASK
);
gtk_signal_connect(
GTK_OBJECT(w), "configure_event",
GTK_SIGNAL_FUNC(GUIBannerEventCB), cb_data
);
gtk_signal_connect(
GTK_OBJECT(w), "expose_event",
GTK_SIGNAL_FUNC(GUIBannerEventCB), cb_data
);
/* Set style */
rcstyle = gtk_rc_style_new();
if(!STRISEMPTY(font_name))
rcstyle->font_name = STRDUP(font_name);
rcstyle->color_flags[GTK_STATE_NORMAL] = GTK_RC_FG | GTK_RC_BG;
rcstyle->color_flags[GTK_STATE_INSENSITIVE] = GTK_RC_FG | GTK_RC_BG;
memcpy(&rcstyle->fg[GTK_STATE_NORMAL], &color_fg, sizeof(GdkColor));
memcpy(&rcstyle->bg[GTK_STATE_NORMAL], &color_bg, sizeof(GdkColor));
/* Modify foreground and background colors for insensitive */
#define LOWER_VALUE(c) (gushort)((((gint)(c) - (gint)((guint16)-1 / 2)) * 0.75) + \
(gint)((guint16)-1 / 2))
color_fg.red = LOWER_VALUE(color_fg.red);
color_fg.green = LOWER_VALUE(color_fg.green);
color_fg.blue = LOWER_VALUE(color_fg.blue);
color_bg.red = LOWER_VALUE(color_bg.red);
color_bg.green = LOWER_VALUE(color_bg.green);
color_bg.blue = LOWER_VALUE(color_bg.blue);
#undef LOWER_VALUE
memcpy(&rcstyle->fg[GTK_STATE_INSENSITIVE], &color_fg, sizeof(GdkColor));
memcpy(&rcstyle->bg[GTK_STATE_INSENSITIVE], &color_bg, sizeof(GdkColor));
gtk_widget_modify_style(w, rcstyle);
GTK_RC_STYLE_UNREF(rcstyle);
/* Get new style values from widget */
if(font != NULL)
{
gint width, height;
if(expand)
width = -1;
else if((font != NULL) && (label != NULL))
width = gdk_string_width(font, label);
else
width = -1;
if(font != NULL)
height = font->ascent + font->descent;
else
height = -1;
gtk_widget_set_usize(w, width, height);
}
return(w);
}
/*
* Draws the Banner.
*/
void GUIBannerDraw(GtkWidget *w)
{
GtkStateType state;
GtkJustification justify;
gint width, height;
const gchar *label;
GdkFont *font;
GdkWindow *window;
GdkDrawable *drawable;
GtkStyle *style;
gpointer *cb_data = (gpointer *)((w != NULL) ?
gtk_object_get_data(GTK_OBJECT(w), GUI_BANNER_DATA_KEY) : NULL
);
if(cb_data == NULL)
return;
label = (const gchar *)cb_data[0];
justify = (GtkJustification)cb_data[1];
font = (GdkFont *)cb_data[2];
state = GTK_WIDGET_STATE(w);
window = w->window;
style = gtk_widget_get_style(w);
if((window == NULL) || (style == NULL))
return;
drawable = (GdkDrawable *)window;
gdk_window_get_size(drawable, &width, &height);
if((width <= 0) || (height <= 0))
return;
/* Begin drawing */
/* Background */
gdk_draw_rectangle(
drawable, style->bg_gc[state], TRUE,
0, 0, width, height
);
/* Got font and label? */
if((font != NULL) && !STRISEMPTY(label))
{
const gint border = 3;
gint lbearing, rbearing, swidth, ascent, descent;
gdk_string_extents(
font, label,
&lbearing, &rbearing, &swidth, &ascent, &descent
);
switch(justify)
{
case GTK_JUSTIFY_CENTER:
gdk_draw_string(
drawable, font, style->fg_gc[state],
((width - swidth) / 2) - lbearing,
((height - (font->ascent + font->descent)) / 2) +
font->ascent,
label
);
break;
case GTK_JUSTIFY_RIGHT:
gdk_draw_string(
drawable, font, style->fg_gc[state],
(width - swidth - border) - lbearing,
((height - (font->ascent + font->descent)) / 2) +
font->ascent,
label
);
break;
case GTK_JUSTIFY_LEFT:
gdk_draw_string(
drawable, font, style->fg_gc[state],
border - lbearing,
((height - (font->ascent + font->descent)) / 2) +
font->ascent,
label
);
break;
case GTK_JUSTIFY_FILL:
break;
}
}
/* Send drawable to window if drawable is not the window */
if(drawable != window)
gdk_draw_pixmap(
window, style->fg_gc[state], drawable,
0, 0, 0, 0, width, height
);
}
/*
* Creates a new GtkCombo with label, combo, initial value, and
* initial list of items.
*
* Returns the GtkTable (the parent) or NULL on failure.
*
* The given GList list will be duplicated, so the one passed to
* this call will not be modified.
*/
GtkWidget *GUIComboCreate(
const gchar *label, /* Label */
const gchar *text, /* Entry Value */
GList *list, /* Combo List */
gint max_items, /* Maximum Items In Combo List */
gpointer *combo_rtn, /* GtkCombo Return */
gpointer data,
void (*func_cb)(GtkWidget *w, gpointer),
void (*list_change_cb)(GtkWidget *, gpointer, GList *)
)
{
GtkWidget *parent, *wlabel = NULL, *w;
GtkCombo *combo;
const gchar *cstrptr;
gpointer *cb_data;
/* Reset return values */
if(combo_rtn != NULL)
*combo_rtn = NULL;
/* Create parent table widget */
parent = gtk_table_new(
1,
((label != NULL) ? 1 : 0) +
1,
FALSE
);
/* Do not show the table parent */
/* Create label? */
if(label != NULL)
{
gint x = 0;
wlabel = gtk_label_new(label);
gtk_table_attach(
GTK_TABLE(parent), wlabel,
(guint)x, (guint)(x + 1),
0, 1,
0,
0,
2, 2
);
gtk_label_set_justify(GTK_LABEL(wlabel), GTK_JUSTIFY_RIGHT);
gtk_widget_show(wlabel);
}
/* Create combo */
if(TRUE)
{
gint i;
gint x = (label != NULL) ? 1 : 0;
GList *glist_in, *glist_out;
GtkEntry *entry;
w = gtk_combo_new();
combo = GTK_COMBO(w);
entry = GTK_ENTRY(combo->entry);
if(combo_rtn != NULL)
*combo_rtn = w;
gtk_table_attach(
GTK_TABLE(parent), w,
(guint)x, (guint)(x + 1),
0, 1,
GTK_SHRINK | GTK_EXPAND | GTK_FILL,
0,
2, 2
);
gtk_combo_disable_activate(combo);
gtk_entry_set_text(entry, (text != NULL) ? text : "");
gtk_entry_set_editable(entry, TRUE);
gtk_combo_set_case_sensitive(combo, FALSE);
/* Begin creating output glist, a duplicate input glist */
glist_out = NULL;
glist_in = (GList *)list;
/* Is input glist given? */
if(glist_in == NULL)
{
/* Input glist is NULL so create a bunch of empty strings
* totalling that specified by max_items for the output
* glist.
*/
for(i = 0; i < max_items; i++)
glist_out = g_list_append(glist_out, STRDUP(""));
}
else
{
/* Input glist is given, make a duplicate of it as the
* output glist.
*/
i = 0;
while((i < max_items) && (glist_in != NULL))
{
cstrptr = (const gchar *)glist_in->data;
glist_out = g_list_append(
glist_out, STRDUP(cstrptr)
);
glist_in = g_list_next(glist_in);
i++;
}
}
glist_in = NULL; /* Input glist should no longer be used */
/* Set new output glist to combo box */
if(glist_out != NULL)
gtk_combo_set_popdown_strings(combo, glist_out);
/* Do not delete the output glist, it will be passed to the
* callback data below.
*/
/* Allocate callback data, 9 pointers of format;
* table Parent table that holds this combo and label.
* label Label (may be NULL).
* combo This combo widget.
* GList Contains list of strings in combo list.
* max_items Max items allowed in combo list.
* data Calling function set callback data.
* func_cb Calling function set callback function.
* list_change_cb Calling function set list change function.
* NULL
*/
cb_data = (gpointer *)g_malloc0(9 * sizeof(gpointer));
cb_data[0] = parent;
cb_data[1] = wlabel;
cb_data[2] = combo;
cb_data[3] = glist_out;
cb_data[4] = (gpointer)MAX(max_items, 0);
cb_data[5] = data;
cb_data[6] = (gpointer)func_cb;
cb_data[7] = (gpointer)list_change_cb;
cb_data[8] = NULL;
gtk_object_set_data_full(
GTK_OBJECT(combo), GUI_COMBO_DATA_KEY,
cb_data, GUIComboDataDestroyCB
);
gtk_signal_connect(
GTK_OBJECT(entry), "activate",
GTK_SIGNAL_FUNC(GUIComboActivateCB), cb_data
);
gtk_signal_connect(
GTK_OBJECT(entry), "changed",
GTK_SIGNAL_FUNC(GUIComboChangedCB), cb_data
);
gtk_widget_show(w);
}
return(parent);
}
/*
* Adds the specified value to the combo widget w's list and current
* value for the combo widget's entry widget.
*
* The item will only be added to the list if it is not NULL
* and does not already exist in the list.
*
* Excess items may be truncated if adding this item would exceed
* the combo list's maximum allowed items.
*/
void GUIComboActivateValue(GtkWidget *w, const gchar *value)
{
gpointer *cb_data;
GtkCombo *combo = (GtkCombo *)w;
if((combo == NULL) || (value == NULL))
return;
cb_data = (gpointer *)GTK_OBJECT_GET_DATA(
combo, GUI_COMBO_DATA_KEY
);
if(cb_data == NULL)
return;
/* Set new value on combo's entry widget */
gtk_entry_set_text(
GTK_ENTRY(combo->entry), value
);
/* Call activate callback as if this was an actual activate
* signal
*/
GUIComboActivateCB(GTK_WIDGET(combo), (gpointer)cb_data);
}
/*
* Adds the given value to the beginning of the glist for the
* combo box w. Older items in the list may be truncated if adding
* a new value would exceed the set maximum items for the combo box.
*
* If value is already in the list then no operation will be
* performed.
*
* The combo box's set list change callback will be called if it is
* not NULL and the new value was different and added succesfully.
*/
void GUIComboAddItem(GtkWidget *w, const gchar *value)
{
gint i, max_items;
gboolean status;
const gchar *cstrptr;
GtkWidget *parent, *wlabel;
GtkCombo *combo = (GtkCombo *)w;
GList *glist_in, *glist_next_in;
gpointer client_data;
void (*func_cb)(GtkWidget *, gpointer);
void (*list_change_cb)(GtkWidget *, gpointer, GList *);
gpointer *cb_data;
if((combo == NULL) || (value == NULL))
return;
/* Get object callback data */
cb_data = (gpointer *)GTK_OBJECT_GET_DATA(
combo, GUI_COMBO_DATA_KEY
);
if(cb_data == NULL)
return;
/* Parse callback data, format is as follows;
* table Parent table that holds this combo and label.
* label Label (may be NULL).
* combo This combo widget.
* GList Contains list of strings in combo list.
* max_items Max items allowed in combo list.
* client_data Calling function set callback data.
* func_cb Calling function set callback function.
* list_change_cb Calling function set list change function.
* NULL
*/
parent = (GtkWidget *)(cb_data[0]);
wlabel = (GtkWidget *)(cb_data[1]);
combo = (GtkCombo *)(cb_data[2]);
glist_in = (GList *)(cb_data[3]);
max_items = (gint)(cb_data[4]);
client_data = (gpointer)(cb_data[5]);
func_cb = cb_data[6];
list_change_cb = cb_data[7];
/* Check if new value is already in the input glist */
status = TRUE;
i = 0;
glist_next_in = glist_in;
/* Iterate from 0 to max_items or when the input glist is
* NULL (whichever occures first).
*/
while((i < max_items) && (glist_next_in != NULL))
{
cstrptr = (gchar *)glist_next_in->data;
if(cstrptr != NULL)
{
/* Check if case sensitive? */
/* Compare list item value with given value */
if(!g_strcasecmp(cstrptr, value))
{
/* Given value matches a value in the list, so set
* status to FALSE indicating there is a value already
* in the list.
*/
status = FALSE;
break;
}
}
i++;
glist_next_in = g_list_next(glist_next_in);
}
/* Variable status will be set to FALSE if the value is already
* in the list.
*/
/* Check if max_items allows us to add a new item to the list and
* if status is TRUE (indicating value is not already in the
* list).
*/
if((max_items > 0) && status)
{
/* Create new output glist */
GList *glist_out = NULL;
/* Add first item in output glist to be the new value fetched
* from the combo's entry.
*/
glist_out = g_list_append(glist_out, STRDUP(value));
/* Now copy old input glist items to output glist, starting
* with i = 1 since we already have one item in the output
* glist.
*/
i = 1;
glist_next_in = glist_in;
while((i < max_items) && (glist_next_in != NULL))
{
cstrptr = (const gchar *)glist_next_in->data;
glist_out = g_list_append(glist_out, STRDUP(cstrptr));
glist_next_in = g_list_next(glist_next_in);
i++;
}
/* Set new output glist to the combo box's list */
if(glist_out != NULL)
gtk_combo_set_popdown_strings(combo, glist_out);
/* Free old input glist since its no longer being used */
if(glist_in != NULL)
{
g_list_foreach(glist_in, (GFunc)g_free, NULL);
g_list_free(glist_in);
glist_in = NULL;
}
/* Update input glist to be that of the output glist */
glist_in = glist_out;
/* Record new glist on callback data */
cb_data[3] = (gpointer)glist_in;
/* Call list change function and pass the new glist */
if(list_change_cb != NULL)
{
list_change_cb(
(GtkWidget *)combo, /* Pass combo box as widget */
client_data, /* Client data */
glist_in /* New glist */
);
}
}
}
/*
* Returns the GList for the combo widget created by
* GUIComboCreate().
*/
GList *GUIComboGetList(GtkWidget *w)
{
gpointer *cb_data = (gpointer *)GTK_OBJECT_GET_DATA(
w, GUI_COMBO_DATA_KEY
);
if(cb_data == NULL)
return(NULL);
/* Parse callback data, format is as follows;
* table Parent table that holds this combo and label.
* label Label (may be NULL).
* combo This combo widget.
* GList Contains list of strings in combo list.
* max_items Max items allowed in combo list.
* client_data Calling function set callback data.
* func_cb Calling function set callback function.
* list_change_cb Calling function set list change function.
* NULL
*/
return((GList *)cb_data[3]);
}
/*
* Sets the new list for the combo.
*
* If the pointer of the given list is the same as the combo's
* current list then the given list will simply be pdated to the
* combo with a call to gtk_combo_set_popdown_strings().
*
* If the given list is NULL then the combo's current list will
* be deleted.
*
* In any case the given list should not be referenced again after
* this call.
*/
void GUIComboSetList(GtkWidget *w, GList *list)
{
GList *glist;
GtkCombo *combo = (GtkCombo *)w;
gpointer *cb_data = (gpointer *)GTK_OBJECT_GET_DATA(
w, GUI_COMBO_DATA_KEY
);
if(cb_data == NULL)
return;
/* Parse callback data, format is as follows;
* table Parent table that holds this combo and label.
* label Label (may be NULL).
* combo This combo widget.
* GList Contains list of strings in combo list.
* max_items Max items allowed in combo list.
* client_data Calling function set callback data.
* func_cb Calling function set callback function.
* list_change_cb Calling function set list change function.
* NULL
*/
glist = (GList *)cb_data[3];
/* Is given list NULL? */
if(list == NULL)
{
gint i, max_items = (gint)cb_data[4];
GList *glist_new,
*glist_old = glist;
/* Create a new glist containing just empty strings */
glist_new = NULL;
for(i = 0; i < max_items; i++)
glist_new = g_list_append(glist_new, STRDUP(""));
/* Was new glist created successfully? */
if(glist_new != NULL)
{
/* Set new glist to combo */
gtk_combo_set_popdown_strings(combo, glist_new);
/* If old glist exists, then delete it */
if(glist_old != NULL)
{
g_list_foreach(glist_old, (GFunc)g_free, NULL);
g_list_free(glist_old);
glist_old = NULL;
}
/* Update pointer to new glist */
cb_data[3] = (gpointer)glist_new;
glist = glist_new;
}
}
/* Given list matches current list's base pointer values? */
else if((gpointer)list == (gpointer)glist)
{
/* Just update list on combo then */
gtk_combo_set_popdown_strings(combo, glist);
/* No need to change pointer on callback data */
/* No need to deallocate given list */
}
else
{
/* New and current list base pointers do not match and
* current glist may be NULL
*/
const gchar *s;
gint i, max_items;
GList *glist_new, *glist_in,
*glist_old = glist;
/* Make a copy the given list as glist_new and limit the
* number of items to max_items
*/
i = 0;
max_items = (gint)cb_data[4];
glist_new = NULL; /* New glist */
glist_in = (GList *)list; /* Input glist */
while((i < max_items) && (glist_in != NULL))
{
s = (const gchar *)glist_in->data;
glist_new = g_list_append(glist_new, STRDUP(s));
glist_in = g_list_next(glist_in);
i++;
}
/* Destroy the given list */
glist_in = (GList *)list; /* Input glist */
list = NULL; /* Mark input list as NULL */
if(glist_in != NULL)
{
g_list_foreach(glist_in, (GFunc)g_free, NULL);
g_list_free(glist_in);
glist_in = NULL;
}
/* Is new coppied glist valid? */
if(glist_new != NULL)
{
/* Set new glist to combo */
gtk_combo_set_popdown_strings(combo, glist_new);
/* If old glist exists, then delete it */
if(glist_old != NULL)
{
g_list_foreach(glist_old, (GFunc)g_free, NULL);
g_list_free(glist_old);
glist_old = NULL;
}
/* Update pointer to new glist on callback data */
cb_data[3] = (gpointer)glist_new;
glist = glist_new;
}
}
}
/*
* Resets all values in the combo widget.
*/
void GUIComboClearAll(GtkWidget *w)
{
GtkCombo *combo = (GtkCombo *)w;
if(combo == NULL)
return;
/* Clear text entry */
gtk_entry_set_text(GTK_ENTRY(combo->entry), "");
gtk_entry_set_position(GTK_ENTRY(combo->entry), 0);
/* Clear combo's glist by setting a new one as NULL */
GUIComboSetList(w, NULL);
}
/*
* Creates a new Menu Bar & GtkAccelGroup.
*/
GtkWidget *GUIMenuBarCreate(GtkAccelGroup **accelgrp_rtn)
{
if(accelgrp_rtn != NULL)
*accelgrp_rtn = gtk_accel_group_new();
return(gtk_menu_bar_new());
}
/*
* Creates a new Tear Off Menu.
*/
GtkWidget *GUIMenuCreateTearOff(void)
{
GtkWidget *menu = gtk_menu_new(),
*w = gtk_tearoff_menu_item_new();
gtk_menu_append(GTK_MENU(menu), w);
gtk_widget_show(w);
return(menu);
}
/*
* Creates a New Menu.
*/
GtkWidget *GUIMenuCreate(void)
{
return(gtk_menu_new());
}
/*
* Creates a new Menu Item.
*
* If accelgrp is NULL then only the accelerator key label will
* state the accelerator key and the accelerator key will not be
* added to the accelerator group.
*
* If functional_widget_rtn not NULL then it will refer to the
* functional widget of the new Menu Item. For example, if the type
* was GUI_MENU_ITEM_TYPE_LABEL then *functional_widget_rtn will
* refer to the GtkLabel.
*/
GtkWidget *GUIMenuItemCreate(
GtkWidget *menu,
gui_menu_item_type type, /* One of GUI_MENU_ITEM_TYPE_* */
GtkAccelGroup *accelgrp,
guint8 **icon, const gchar *label,
guint accel_key, guint accel_mods,
gpointer *functional_widget_rtn,
gpointer data,
void (*func_cb)(GtkWidget *w, gpointer)
)
{
const gint border_minor = 2,
border_accel_label = 15;
GtkWidget *w, *menu_item = NULL, *parent, *parent2;
gui_menu_item_data_struct *mi;
if(menu == NULL)
return(NULL);
/* Reset functional widget ID */
if(functional_widget_rtn != NULL)
*functional_widget_rtn = NULL;
/* Create menu item data */
mi = GUI_MENU_ITEM_DATA(
g_malloc0(sizeof(gui_menu_item_data_struct))
);
/* Create menu item by type */
switch(type)
{
case GUI_MENU_ITEM_TYPE_LABEL:
case GUI_MENU_ITEM_TYPE_SUBMENU:
/* Create a GtkMenuItem */
mi->menu_item = menu_item = parent = w = gtk_menu_item_new();
if(!GTK_WIDGET_NO_WINDOW(w))
gtk_widget_add_events(
w,
GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK
);
gtk_menu_append(GTK_MENU(menu), w);
gtk_object_set_data_full(
GTK_OBJECT(w), GUI_MENU_ITEM_DATA_KEY,
mi, GUIMenuDataDestroyCB
);
gtk_widget_show(w);
/* Create a GtkTable to hold the icon and labels */
w = gtk_table_new(1, 3, FALSE);
gtk_container_add(GTK_CONTAINER(parent), w);
#ifndef _WIN32
gtk_table_set_col_spacing(
GTK_TABLE(w), 0, (guint)border_minor
);
gtk_table_set_col_spacing(
GTK_TABLE(w), 1,
(guint)border_accel_label
);
#endif
gtk_widget_show(w);
parent = w;
/* Create icon, if icon is NULL then an empty fixed
* widget would have been returned
*/
mi->icon_data = (const guint8 **)icon;
mi->pixmap = w = GUICreateMenuItemIcon(icon);
if(w != NULL)
{
gtk_table_attach(
GTK_TABLE(parent), w,
0, 1,
0, 1,
GTK_SHRINK,
GTK_SHRINK,
0, 0
);
gtk_widget_show(w);
}
/* Create a GtkAlignment to align the label */
w = gtk_alignment_new(0.0f, 0.5f, 0.0f, 0.0f);
gtk_table_attach(
GTK_TABLE(parent), w,
1, 2,
0, 1,
GTK_SHRINK | GTK_EXPAND | GTK_FILL,
GTK_SHRINK,
0, 0
);
gtk_widget_show(w);
parent2 = w;
/* Create a GtkLabel as the label */
mi->label_text = STRDUP((label != NULL) ? label : "");
mi->label = w = gtk_label_new(mi->label_text);
gtk_container_add(GTK_CONTAINER(parent2), w);
gtk_label_set_justify(GTK_LABEL(w), GTK_JUSTIFY_LEFT);
gtk_widget_show(w);
/* Record the GtkLabel as the functional widget */
if(functional_widget_rtn != NULL)
*functional_widget_rtn = w;
/* Set callback for menu item? */
if(func_cb != NULL)
{
/* Create menu item client data */
gpointer *mi_client_data = (gpointer *)g_malloc0(
4 * sizeof(gpointer)
);
mi_client_data[0] = w; /* Functional widget (GtkLabel) */
mi_client_data[1] = data;
mi_client_data[2] = (gpointer)func_cb;
mi_client_data[3] = NULL;
gtk_object_set_data_full(
GTK_OBJECT(menu_item), GUI_MENU_ITEM_CLIENT_DATA_KEY,
mi_client_data, GUIMenuClientDataDestroyCB
);
gtk_signal_connect_object(
GTK_OBJECT(menu_item), "activate",
GTK_SIGNAL_FUNC(GUIMenuActivateCB), (gpointer)mi_client_data
);
}
/* Create a GtkAlignment for the accelerator key label */
w = gtk_alignment_new(1.0f, 0.5f, 0.0f, 0.0f);
gtk_table_attach(
GTK_TABLE(parent), w,
2, 3,
0, 1,
GTK_SHRINK,
GTK_SHRINK,
0, 0
);
gtk_widget_show(w);
parent2 = w;
/* Create a GtkLabel as the accelerator key label */
mi->accel_label = w = gtk_label_new("");
gtk_container_add(GTK_CONTAINER(parent2), w);
gtk_label_set_justify(GTK_LABEL(w), GTK_JUSTIFY_RIGHT);
/* Set accelerator key and accelerator key GtkLabel */
GUIMenuItemSetAccelKey(
menu_item, accelgrp, accel_key, accel_mods
);
break;
case GUI_MENU_ITEM_TYPE_CHECK:
/* Create a GtkCheckMenuItem */
mi->label_text = STRDUP((label != NULL) ? label : "");
mi->menu_item = menu_item = parent = w =
gtk_check_menu_item_new_with_label(mi->label_text);
/* Need to set default height */
gtk_widget_set_usize(w, -1, GUI_MENU_ITEM_DEF_HEIGHT + 2);
gtk_menu_append(GTK_MENU(menu), w);
gtk_object_set_data_full(
GTK_OBJECT(w), GUI_MENU_ITEM_DATA_KEY,
mi, GUIMenuDataDestroyCB
);
gtk_widget_show(w);
/* Record check menu item as the functional widget */
if(functional_widget_rtn != NULL)
*functional_widget_rtn = w;
/* Set callback for the check menu item? */
if(func_cb != NULL)
{
/* Create menu item client data */
gpointer *mi_client_data = (gpointer *)g_malloc0(
4 * sizeof(gpointer)
);
mi_client_data[0] = w; /* Functional widget */
mi_client_data[1] = data;
mi_client_data[2] = (gpointer)func_cb;
mi_client_data[3] = NULL;
gtk_object_set_data_full(
GTK_OBJECT(menu_item), GUI_MENU_ITEM_CLIENT_DATA_KEY,
mi_client_data, GUIMenuClientDataDestroyCB
);
gtk_signal_connect_object(
GTK_OBJECT(menu_item), "toggled",
GTK_SIGNAL_FUNC(GUIMenuActivateCB), (gpointer)mi_client_data
);
}
/* Set accelerator key */
GUIMenuItemSetAccelKey(
menu_item, accelgrp, accel_key, accel_mods
);
break;
case GUI_MENU_ITEM_TYPE_SEPARATOR:
/* Create a GtkMenuItem */
mi->menu_item = menu_item = parent = w = gtk_menu_item_new();
gtk_menu_append(GTK_MENU(menu), w);
gtk_object_set_data_full(
GTK_OBJECT(w), GUI_MENU_ITEM_DATA_KEY,
mi, GUIMenuDataDestroyCB
);
gtk_widget_show(w);
/* Create horizontal separator */
w = gtk_hseparator_new();
gtk_container_add(GTK_CONTAINER(parent), w);
GTK_WIDGET_UNSET_FLAGS(GTK_WIDGET(menu_item), GTK_SENSITIVE);
gtk_widget_show(w);
/* Record horizontal separator as the functional widget */
if(functional_widget_rtn != NULL)
*functional_widget_rtn = w;
break;
default:
GUIMenuDataDestroyCB(mi);
mi = NULL;
break;
}
return(menu_item);
}
/*
* Sets the Menu Item as the default item.
*/
void GUISetMenuItemDefault(GtkWidget *w)
{
#if 0
GtkRcStyle *rcstyle;
#endif
gui_menu_item_data_struct *cb_data = GUI_MENU_ITEM_DATA(
GTK_OBJECT_GET_DATA(w, GUI_MENU_ITEM_DATA_KEY)
);
if(cb_data == NULL)
return;
#if 0
rcstyle = gtk_rc_style_new();
rcstyle->font_name = STRDUP(
"-*-*-bold-*-*-*-*-*-*-*-*-*-*-*"
/* "-adobe-helvetica-bold-r-normal-*-12-*-*-*-*-*-iso8859-1" */
);
w = cb_data->label;
if(w != NULL)
gtk_widget_modify_style(w, rcstyle);
w = cb_data->accel_label;
if(w != NULL)
gtk_widget_modify_style(w, rcstyle);
GTK_RC_STYLE_UNREF(rcstyle)
#endif
}
/*
* Sets the Menu Item's "enter_notify_event" and
* "leave_notify_event" signal callbacks.
*/
void GUISetMenuItemCrossingCB(
GtkWidget *w,
gint (*enter_cb)(GtkWidget *, GdkEvent *, gpointer),
gpointer enter_data,
gint (*leave_cb)(GtkWidget *, GdkEvent *, gpointer),
gpointer leave_data
)
{
if(w == NULL)
return;
if(enter_cb != NULL)
gtk_signal_connect(
GTK_OBJECT((GtkWidget *)w), "enter_notify_event",
GTK_SIGNAL_FUNC(enter_cb), enter_data
);
if(leave_cb != NULL)
gtk_signal_connect(
GTK_OBJECT((GtkWidget *)w), "leave_notify_event",
GTK_SIGNAL_FUNC(leave_cb), leave_data
);
}
/*
* Adds the Menu to the Menu Bar with the specified label.
*
* Returns the Menu Bar Label or NULL on error.
*/
GtkWidget *GUIMenuAddToMenuBar(
GtkWidget *menu_bar, GtkWidget *menu,
const gchar *label,
gui_menu_bar_item_alignment align /* One of GUI_MENU_BAR_ALIGN_* */
)
{
GtkWidget *menu_label;
GtkMenuShell *menu_shell;
if((menu_bar == NULL) || (menu == NULL))
return(NULL);
menu_shell = GTK_MENU_SHELL(menu_bar);
/* Create Menu Label */
if(label != NULL)
{
menu_label = gtk_menu_item_new_with_label(label);
}
else
{
GList *glist = menu_shell->children;
gchar *s = g_strdup_printf(
"Menu %i", g_list_length(glist) + 1
);
menu_label = gtk_menu_item_new_with_label(s);
g_free(s);
}
/* Set Menu Label to reffer to the given Menu */
gtk_menu_item_set_submenu(
GTK_MENU_ITEM(menu_label), menu
);
/* Append Menu Label to the given Menu Bar */
gtk_menu_bar_append(GTK_MENU_BAR(menu_bar), menu_label);
gtk_widget_show(menu_label);
/* Set Menu Label alignment */
if(align == GUI_MENU_BAR_ALIGN_RIGHT)
gtk_menu_item_right_justify(GTK_MENU_ITEM(menu_label));
return(menu_label);
}
/*
* Sets the Menu Item's label.
*/
void GUIMenuItemSetLabel(GtkWidget *menu_item, const gchar *label)
{
GtkWidget *w;
gui_menu_item_data_struct *mi = GUI_MENU_ITEM_DATA(
GTK_OBJECT_GET_DATA(menu_item, GUI_MENU_ITEM_DATA_KEY)
);
if(mi == NULL)
return;
w = mi->label;
if(label != NULL)
{
/* No change in label text? */
const gchar *old_label = mi->label_text;
if((old_label != NULL) ? !strcmp(old_label, label) : FALSE)
return;
/* Record new label text */
g_free(mi->label_text);
mi->label_text = STRDUP(label);
/* Set new label text */
if((w != NULL) ? GTK_IS_LABEL(w) : FALSE)
gtk_label_set_text(GTK_LABEL(w), mi->label_text);
}
else
{
/* Label text was already empty? */
if(mi->label_text == NULL)
return;
/* Record new label text */
g_free(mi->label_text);
mi->label_text = STRDUP("(null)");
/* Set new label text */
if((w != NULL) ? GTK_IS_LABEL(w) : FALSE)
gtk_label_set_text(GTK_LABEL(w), mi->label_text);
}
}
/*
* Sets the Menu Item's pixmap.
*/
void GUIMenuItemSetPixmap(GtkWidget *menu_item, guint8 **icon_data)
{
GdkWindow *window;
GtkStyle *style;
GtkWidget *w;
gui_menu_item_data_struct *mi = GUI_MENU_ITEM_DATA(
GTK_OBJECT_GET_DATA(menu_item, GUI_MENU_ITEM_DATA_KEY)
);
if((mi == NULL) || (icon_data == NULL))
return;
if(gui_window_root == NULL)
gui_window_root = (GdkWindow *)GDK_ROOT_PARENT();
window = gui_window_root;
/* No change in icon data? */
if(mi->icon_data == (const guint8 **)icon_data)
return;
style = gtk_widget_get_style(menu_item);
w = mi->pixmap;
if((w != NULL) ? GTK_IS_PIXMAP(w) : FALSE)
{
GdkBitmap *mask = NULL;
GdkPixmap *pixmap = gdk_pixmap_create_from_xpm_d(
window, &mask,
(style != NULL) ?
&style->bg[GTK_STATE_NORMAL] : NULL,
(gchar **)icon_data
);
if(pixmap != NULL)
{
gint width, height;
/* Record new icon data */
mi->icon_data = (const guint8 **)icon_data;
/* Update pixmap */
gtk_pixmap_set(GTK_PIXMAP(w), pixmap, mask);
/* Get size of newly loaded pixmap */
gdk_window_get_size(pixmap, &width, &height);
}
GDK_PIXMAP_UNREF(pixmap);
GDK_BITMAP_UNREF(mask);
}
}
/*
* Sets the Menu Item's accelerator key.
*
* If accelgrp is NULL then only the accelerator key label will be
* updated.
*/
void GUIMenuItemSetAccelKey(
GtkWidget *menu_item, GtkAccelGroup *accelgrp,
guint accel_key, guint accel_mods
)
{
GtkWidget *w;
gui_menu_item_data_struct *mi = GUI_MENU_ITEM_DATA(
GTK_OBJECT_GET_DATA(menu_item, GUI_MENU_ITEM_DATA_KEY)
);
if(mi == NULL)
return;
/* No change? */
if((mi->accel_key == accel_key) &&
(mi->accel_mods == accel_mods)
)
return;
/* Update the GtkAccelGroup? */
if(accelgrp != NULL)
{
/* Remove existing accelerator key? */
if(mi->accel_key != 0)
gtk_widget_remove_accelerator(
menu_item, accelgrp,
mi->accel_key, mi->accel_mods
);
/* Add new accelerator key */
gtk_widget_add_accelerator(
menu_item, "activate", accelgrp,
accel_key, accel_mods,
GTK_ACCEL_VISIBLE
);
}
/* Update the accelerator key GtkLabel */
w = mi->accel_label;
if(w != NULL)
{
GtkLabel *label = GTK_LABEL(w);
/* Accelerator key specified? */
if(accel_key != 0)
{
const gchar *key_name;
gchar *accel_text = STRDUP("");
/* Append modifier name to accelerator text */
if(accel_mods & GDK_LOCK_MASK)
{
gchar *s = g_strconcat(accel_text, "CapsLock+", NULL);
g_free(accel_text);
accel_text = s;
}
if(accel_mods & GDK_CONTROL_MASK)
{
gchar *s = g_strconcat(accel_text, "Ctrl+", NULL);
g_free(accel_text);
accel_text = s;
}
if(accel_mods & GDK_SHIFT_MASK)
{
gchar *s = g_strconcat(accel_text, "Shift+", NULL);
g_free(accel_text);
accel_text = s;
}
if(accel_mods & GDK_MOD1_MASK)
{
gchar *s = g_strconcat(accel_text, "Alt+", NULL);
g_free(accel_text);
accel_text = s;
}
if(accel_mods & GDK_MOD2_MASK)
{
gchar *s = g_strconcat(accel_text, "NumLock+", NULL);
g_free(accel_text);
accel_text = s;
}
if(accel_mods & GDK_MOD3_MASK)
{
gchar *s = g_strconcat(accel_text, "Mod3+", NULL);
g_free(accel_text);
accel_text = s;
}
if(accel_mods & GDK_MOD4_MASK)
{
gchar *s = g_strconcat(accel_text, "Mod4+", NULL);
g_free(accel_text);
accel_text = s;
}
if(accel_mods & GDK_MOD5_MASK)
{
gchar *s = g_strconcat(accel_text, "ScrollLock+", NULL);
g_free(accel_text);
accel_text = s;
}
/* Append key name to accelerator key text */
key_name = GUIGetKeyName(accel_key);
/* key_name = gdk_keyval_name(accel_key); */
if(*key_name != '\0')
{
gchar *s = g_strconcat(accel_text, key_name, NULL);
g_free(accel_text);
accel_text = s;
}
else
{
gchar *char_name = g_strdup_printf(
"%c", toupper(accel_key)
);
gchar *s = g_strconcat(accel_text, char_name, NULL);
g_free(char_name);
g_free(accel_text);
accel_text = s;
}
/* Set and map accelerator key GtkLabel */
g_free(mi->accel_text);
mi->accel_text = STRDUP(accel_text);
gtk_label_set_text(label, accel_text);
gtk_widget_show(w);
g_free(accel_text);
}
else
{
/* Clear and unmap accelerator key GtkLabel */
g_free(mi->accel_text);
mi->accel_text = NULL;
gtk_label_set_text(label, "");
gtk_widget_hide(w);
}
}
/* Record new accelerator key value */
mi->accel_key = accel_key;
mi->accel_mods = accel_mods;
}
/*
* Sets the Check Menu Item's active state.
*/
void GUIMenuItemSetCheck(
GtkWidget *menu_item, gboolean active, gboolean emit
)
{
#if 1
if((menu_item != NULL) ? !GTK_IS_CHECK_MENU_ITEM(menu_item) : TRUE)
return;
if(emit)
gtk_check_menu_item_set_active(
GTK_CHECK_MENU_ITEM(menu_item), active
);
else
GTK_CHECK_MENU_ITEM(menu_item)->active = active;
#else
GtkWidget *w;
gui_menu_item_data_struct *mi = GUI_MENU_ITEM_DATA(
GTK_OBJECT_GET_DATA(menu_item, GUI_MENU_ITEM_DATA_KEY)
);
if(mi == NULL)
return;
w = mi->check;
#endif
}
/*
* Gets the Check Menu Item's active state.
*/
gboolean GUIMenuItemGetCheck(GtkWidget *menu_item)
{
#if 1
if(menu_item == NULL)
return(FALSE);
if(GTK_IS_CHECK_MENU_ITEM(menu_item))
return(GTK_CHECK_MENU_ITEM(menu_item)->active);
else
return(FALSE);
#else
#endif
}
/*
* Same as GUIMenuAddToMenuBar() except a pixmap is placed to the
* left of the label on the menu bar.
*/
GtkWidget *GUIMenuAddToMenuBarPixmapH(
GtkWidget *menu_bar, GtkWidget *menu,
const gchar *label, guint8 **icon_data,
gui_menu_bar_item_alignment align
)
{
return(GUIMenuAddToMenuBar(
menu_bar, menu, label, align
));
}
/*
* Sets the menu item's sub menu.
*
* If the menu item's previous submenu exists then it will be
* destroyed first.
*
* If sub_menu is NULL then the menu item's previous submenu (if
* any) be destroyed and the menu item will be set as not having
* any submenu.
*/
void GUIMenuItemSetSubMenu(
GtkWidget *menu_item, GtkWidget *sub_menu
)
{
GtkMenuItem *mi;
if((menu_item != NULL) ? !GTK_IS_MENU_ITEM(menu_item) : TRUE)
return;
mi = GTK_MENU_ITEM(menu_item);
if((sub_menu != NULL) ? GTK_IS_MENU(sub_menu) : FALSE)
gtk_menu_item_set_submenu(mi, sub_menu);
else
gtk_menu_item_remove_submenu(mi);
}
/*
* Creates a pull out widget horizontally, returning the hbox which
* the calling function can pack child widgets into.
*
* The given parent must be a hbox or a vbox.
*
* The toplevel_width and toplevel_height specify the size of the
* toplevel window that will be used when this widget is `pulled
* out'.
*
* gtk_widget_show() will be called for you, the client function need
* not call it.
*/
void *GUIPullOutCreateH(
void *parent_box,
int homogeneous, int spacing, /* Of client vbox */
int expand, int fill, int padding, /* Of holder hbox */
int toplevel_width, int toplevel_height,
void *pull_out_client_data,
void (*pull_out_cb)(void *, void *),
void *push_in_client_data,
void (*push_in_cb)(void *, void *)
)
{
gpointer *cb_data;
GtkWidget *pull_out_btn, *holder_hbox, *client_hbox;
if(parent_box == NULL)
return(NULL);
/* Create a hbox to place into the given parent box. This hbox
* will hold the parenting hbox plus some other widgets.
*/
holder_hbox = gtk_hbox_new(FALSE, 0);
gtk_box_pack_start(
(GtkBox *)parent_box, holder_hbox,
expand, fill, padding
);
gtk_widget_show(holder_hbox);
/* Create pull out button and parent it to the holder hbox.
* Note that this is not really a button but an event box.
*/
pull_out_btn = gtk_event_box_new();
gtk_box_pack_start(
GTK_BOX(holder_hbox), pull_out_btn, FALSE, FALSE, 0
);
gtk_widget_set_usize(pull_out_btn, 10, -1);
gtk_widget_show(pull_out_btn);
/* Create the client hbox, which will be parented to the above
* holder hbox when `placed in' and reparented to a toplevel
* GtkWindow when `pulled out'.
*/
client_hbox = gtk_hbox_new(homogeneous, spacing);
gtk_box_pack_start(
GTK_BOX(holder_hbox), client_hbox, TRUE, TRUE, 0
);
gtk_widget_show(client_hbox);
/* Set callbacks and callback data */
/* Allocate and set up callback data */
cb_data = (gpointer *)g_malloc0(13 * sizeof(gpointer));
if(cb_data != NULL)
{
/* Format is as follows (13 arguments):
*
* client_hbox
* holder_hbox
* holder_window
* holder_window_x
* holder_window_y
* holder_window_width
* holder_window_height
* in_place (1 if true).
* pull_out_client_data
* pull_out_cb
* push_in_client_data
* push_in_cb
*/
cb_data[0] = (gpointer)client_hbox;
cb_data[1] = (gpointer)holder_hbox;
cb_data[2] = NULL;
cb_data[3] = 0;
cb_data[4] = 0;
cb_data[5] = (gpointer)MAX(toplevel_width, 0);
cb_data[6] = (gpointer)MAX(toplevel_height, 0);
cb_data[7] = (gpointer)1; /* Initially `pushed in' */
cb_data[8] = (gpointer)pull_out_client_data;
cb_data[9] = (gpointer)pull_out_cb;
cb_data[10] = (gpointer)push_in_client_data;
cb_data[11] = (gpointer)push_in_cb;
cb_data[12] = NULL;
gtk_object_set_data_full(
GTK_OBJECT(client_hbox), GUI_PULLOUT_DATA_KEY,
cb_data, GUIPullOutDataDestroyCB
);
}
gtk_signal_connect(
GTK_OBJECT(pull_out_btn), "button_press_event",
GTK_SIGNAL_FUNC(GUIPullOutPullOutBtnCB), cb_data
);
gtk_signal_connect_after(
GTK_OBJECT(pull_out_btn), "expose_event",
GTK_SIGNAL_FUNC(GUIPullOutDrawHandleCB), NULL
);
gtk_signal_connect(
GTK_OBJECT(pull_out_btn), "draw",
GTK_SIGNAL_FUNC(GUIPullOutDrawHandleDrawCB), NULL
);
return(client_hbox);
}
/*
* Returns the pointer to the toplevel window (if any) of the
* client_hbox and the geometry of that window.
*
* The client box should be one created by GUIPullOutCreate*().
*/
void *GUIPullOutGetToplevelWindow(
void *client_box,
int *x, int *y, int *width, int *height
)
{
gpointer *cb_data;
GtkWidget *w = NULL;
if(x != NULL)
*x = 0;
if(y != NULL)
*y = 0;
if(width != NULL)
*width = 0;
if(height != NULL)
*height = 0;
if(client_box == NULL)
return(w);
cb_data = (gpointer *)GTK_OBJECT_GET_DATA(
client_box, GUI_PULLOUT_DATA_KEY
);
if(cb_data != NULL)
{
/* Format is as follows (13 arguments):
*
* client_hbox
* holder_hbox
* holder_window
* holder_window_x
* holder_window_y
* holder_window_width
* holder_window_height
* in_place (1 if true)
* pull_out_client_data
* pull_out_cb
* push_in_client_data
* push_in_cb
*/
w = (GtkWidget *)cb_data[2];
if((w != NULL) ? !GTK_WIDGET_NO_WINDOW(w) : FALSE)
{
GdkWindow *window = w->window;
gint rx, ry, rwidth, rheight, rdepth;
gdk_window_get_geometry(
window,
&rx, &ry, &rwidth, &rheight,
&rdepth
);
if(x != NULL)
*x = rx;
if(y != NULL)
*y = ry;
if(width != NULL)
*width = rwidth;
if(height != NULL)
*height = rheight;
}
}
return(w);
}
/*
* Pulls out the pull out box.
*/
void GUIPullOutPullOut(void *client_box)
{
gpointer *cb_data;
if(client_box == NULL)
return;
cb_data = (gpointer *)GTK_OBJECT_GET_DATA(
client_box, GUI_PULLOUT_DATA_KEY
);
if(cb_data != NULL)
{
/* Format is as follows (13 arguments):
*
* client_hbox
* holder_hbox
* holder_window
* holder_window_x
* holder_window_y
* holder_window_width
* holder_window_height
* in_place (1 if true)
* pull_out_client_data
* pull_out_cb
* push_in_client_data
* push_in_cb
*/
/* In place (pushed in)? */
if((gint)cb_data[7])
{
GUIPullOutPullOutBtnCB(
NULL,
NULL,
(gpointer)cb_data
);
}
}
}
/*
* Pushes in the pull out box.
*/
void GUIPullOutPushIn(void *client_box)
{
GtkWidget *w;
gpointer *cb_data;
if(client_box == NULL)
return;
cb_data = (gpointer *)GTK_OBJECT_GET_DATA(
client_box, GUI_PULLOUT_DATA_KEY
);
if(cb_data != NULL)
{
/* Format is as follows (13 arguments):
*
* client_hbox
* holder_hbox
* holder_window
* holder_window_x
* holder_window_y
* holder_window_width
* holder_window_height
* in_place (1 if true)
* pull_out_client_data
* pull_out_cb
* push_in_client_data
* push_in_cb
*/
w = (GtkWidget *)cb_data[2];
/* Not in place (pulled out)? */
if(!((gint)cb_data[7]))
{
GUIPullOutCloseCB(
(GtkWidget *)cb_data[2],
NULL,
(gpointer)cb_data
);
}
}
}
|