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
|
#!/usr/bin/env wish
#----------------------------------------------------------------------------
# Copyright (c) 1999 - 2000 Jochen C. Loewer (loewerj@hotmail.com)
#----------------------------------------------------------------------------
#
# A XML/DOM/XPath evaluator/viewer... featuring the Tk text widget.
#
#
# The contents of this file are subject to the Mozilla Public License
# Version 2.0 (the "License"); you may not use this file except in
# compliance with the License. You may obtain a copy of the License at
# http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS IS"
# basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
# License for the specific language governing rights and limitations
# under the License.
#
# The Original Code is tDOM.
#
# The Initial Developer of the Original Code is Jochen Loewer
# Portions created by Jochen Loewer are Copyright (C) 1998, 1999
# Jochen Loewer. All Rights Reserved.
#
# Contributor(s):
#
# written by Jochen Loewer
# December, 1999
#
#
#
# Contains emacsbinds.tcl:
#
# Copyright 1993 by Paul Raines (raines@bohr.physics.upenn.edu)
#
# Permission to use, copy, modify, and distribute this
# software and its documentation for any purpose and without
# fee is hereby granted, provided that the above copyright
# notice appear in all copies. The University of Pennsylvania
# makes no representations about the suitability of this
# software for any purpose. It is provided "as is" without
# express or implied warranty.
#
#----------------------------------------------------------------------------
# ! All that needs some code cleanup! The code should be more readable!
# ! Currently just use xe!
#----------------------------------------------------------------------------
# Package/Includes
#----------------------------------------------------------------------------
package require http 2
if {[catch { load ../unix/tdom0.6[info shared] }]} {
catch { load ../win/tdom0.6.dll }
}
catch { package require tdom 0.6 }
catch { source ../lib/tdom.tcl }
#----------------------------------------------------------------------------
# Globals
#----------------------------------------------------------------------------
set HttpProxyHost ""
set HttpProxyPort ""
#----------------------------------------------------------------------------
# $Header$
#
#
# p a n e implements the new widget 'pane' to realize a
# resizing of the space between two sub windows
# in fixed size outer window, the pane window.
# Uses plain tcl/tk code
#
#
# $Log$
# Revision 1.1 2002/02/22 01:05:35 rolf
# Initial revision
#
# Revision 1.1 96/12/06 15:59:14 15:59:14 jolo (#Jochen Loewer)
# Initial revision
#
#
#
# written by Jochen Loewer
# July, 1996
#
#----------------------------------------------------------------------------
#----------------------------------------------------------------------pane--
proc pane { path type width height } {
global _pane_Priv
set _pane_Priv(moving) no
frame $path -height $height -width $width -relief flat
frame $path.separator -height 7 -relief flat
frame $path.separator.line -height 4 -relief ridge -borderwidth 1
frame $path.separator.handle -width 8 -height 8 -relief raised -borderwidth 1
place $path.separator.line -anchor nw -x 0 -rely 0.4 -relwidth 1.0
place $path.separator.handle -anchor center -relx 1.0 -rely 0.5 -x -8
place $path.separator -anchor nw -x 0 -y 0 -relwidth 1.0
$path.separator.handle config -cursor sb_v_double_arrow
set _pane_Priv(maxy) $height
set _pane_Priv(moving) no
}
#----------------------------------------------------------------------pane--
proc pane_place { path type ratio win1 win2 } {
global _pane_Priv
set _pane_Priv(moving) no
update
scan [winfo geometry $path] "%dx%d+%d+%d" w h x y
set middley [expr $h*$ratio]
place $path.separator -anchor nw -x 0 -y $middley -relwidth 1.0
update
pane_partionize $path $win1 $win2
$path.separator.handle config -cursor sb_v_double_arrow
bind $path.separator.handle <ButtonPress-1> "pane_down $path"
bind $path.separator.handle <B1-Motion> "pane_motion $path"
bind $path.separator.handle <ButtonRelease-1> "pane_release $path $win1 $win2"
bind $path <Configure> "pane_resize $path $win1 $win2 %w %h"
set _pane_Priv(maxy) $h
set _pane_Priv(moving) no
}
#-----------------------------------------------------------------pane_down--
proc pane_down { pane } {
global _pane_Priv
$pane.separator.handle configure -relief sunken
raise $pane.separator
set _pane_Priv(rooty) [winfo pointery $pane]
scan [winfo geometry $pane] "%dx%d+%d+%d" w h x y
set _pane_Priv(maxy) $h
scan [winfo geometry $pane.separator] "%dx%d+%d+%d" w h x y
set _pane_Priv(oldy) $y
set _pane_Priv(moving) yes
}
#---------------------------------------------------------------pane_motion--
proc pane_motion { pane } {
global _pane_Priv
set y [winfo pointery $pane]
set delta [expr $y-$_pane_Priv(rooty)]
set newy [expr $_pane_Priv(oldy)+$delta]
if { ($newy > 8) && ([expr $newy+16] <$_pane_Priv(maxy)) } {
place $pane.separator -anchor nw -x 0 -y $newy -relwidth 1.0
}
}
#--------------------------------------------------------------pane_release--
proc pane_partionize { pane win1 win2 } {
scan [winfo geometry $pane.separator] "%dx%d+%d+%d" w h x y
place $win1 -anchor nw -x 0 -y 0 -relwidth 1.0 -height $y -relheight {}
set ywin2 [expr $y+$h]
scan [winfo geometry $pane] "%dx%d+%d+%d" w h x y
set hwin2 [expr $h-$ywin2-1]
place $win2 -anchor se -relx 1.0 -rely 1.0 -relwidth 1.0 -height $hwin2
}
#--------------------------------------------------------------pane_release--
proc pane_release { pane win1 win2 } {
global _pane_Priv
$pane.separator.handle configure -relief raised
pane_partionize $pane $win1 $win2
set _pane_Priv(moving) no
}
#---------------------------------------------------------------pane_resize--
proc pane_resize { pane win1 win2 neww newh} {
global _pane_Priv
if { $_pane_Priv(moving) != "yes" } {
scan [winfo geometry $pane.separator] "%dx%d+%d+%d" w h xp y
set newy [expr ($y*$newh)/$_pane_Priv(maxy)]
place $pane.separator -anchor nw -x 0 -y $newy -relwidth 1.0
update
pane_partionize $pane $win1 $win2
}
set _pane_Priv(maxy) $newh
}
############################################################################
# include bindings.tk from TkMail (Thanks Paul!)
############################################################################
#
# COPYRIGHT:
# Copyright 1993 by Paul Raines (raines@bohr.physics.upenn.edu)
#
# Permission to use, copy, modify, and distribute this
# software and its documentation for any purpose and without
# fee is hereby granted, provided that the above copyright
# notice appear in all copies. The University of Pennsylvania
# makes no representations about the suitability of this
# software for any purpose. It is provided "as is" without
# express or implied warranty.
#
global bind_xnd btp
# USER SETTINGS
set btp(prevcmd) "begin-line"
# maximum number of kills to save in ring
set btp(maxkill) 10
# maximum number of marks to save in ring
set btp(maxmark) 10
# syntax for letter not part of a "word"
set btp(not-word) {[^a-zA-Z_0-9]}
# procedure to use for errors
set btp(error) error
# procedure to use for beeping
set btp(beep) ""
# whether to bind Escape prefix commands also to the Meta modifier
set btp(use-meta) 1
# column at which to line wrap
set btp(fillcol) 0
# prefix for line wrapping (NOT REALLY WORKING YET)
set btp(fillprefix) ""
# PRIVATE SETTINGS
set btp(lastkill) 0.0
set btp(killring) ""
set btp(killptr) 0
set btp(killlen) 0
set btp(arg) def
proc tk_entryForwspace w {
set x [expr [$w index insert] - 1]
catch {$w delete $x}
}
# selection_if_any - return selection if it exists, else {}
# this is from kjx@comp.vuw.ac.nz (R. James Noble)
proc selection_if_any {} {
if {[catch {selection get} s]} {return ""} {return $s}
}
proc bind_cleanup { w } {
global btp
catch {unset btp($w,markring)}
}
proc bt:current-line { w } {
return [lindex [split [$w index insert] .] 0]
}
proc bt:current-col { w } {
return [lindex [split [$w index insert] .] 1]
}
proc bt:move-line { w {num 1} } {
global btp
set btp(lastkill) 0.0
if {$btp(arg) != "def"} {
set num [expr $num*$btp(arg)]
set btp(arg) def
}
if {$btp(prevcmd) != "move-line"} {
set btp(goalcol) [lindex [split [$w index insert] .] 1]
}
if {$num > -1} {set num "+$num"}
$w tag remove sel 1.0 end
set ndx [$w index "insert $num line lineend"]
set goalndx [lindex [split $ndx .] 0].$btp(goalcol)
if {$btp(goalcol) < [lindex [split $ndx .] 1]} {
$w mark set insert $goalndx
} else {
$w mark set insert $ndx
}
$w yview -pickplace insert
set btp(prevcmd) move-line
}
proc bt:move-char { w {num 1} } {
global btp
set btp(lastkill) 0.0
if {$btp(arg) != "def"} {
set num [expr $num*$btp(arg)]
set btp(arg) def
}
if {$num > -1} {set num "+$num"}
$w tag remove sel 1.0 end
$w mark set insert "insert $num char"
$w yview -pickplace insert
set btp(prevcmd) "move-char"
}
proc bt:move-word {w {num 1}} {
global btp
set btp(lastkill) 0.0
$w tag remove sel 1.0 end
if {$btp(arg) != "def"} {
set num [expr $num*$btp(arg)]
set btp(arg) def
}
if {$num > 0} {
for {set i 0} {$i < $num } {incr i} {
while {[regexp $btp(not-word) [$w get insert]]} {
$w mark set insert insert+1c
}
$w mark set insert {insert wordend}
}
} else {
for {set i 0} {$i > $num } {incr i -1} {
$w mark set insert insert-1c
while {[regexp $btp(not-word) [$w get insert]]} {
$w mark set insert insert-1c
}
$w mark set insert {insert wordstart}
}
}
$w yview -pickplace insert
set btp(prevcmd) "move-word"
}
proc bt:begin-line { w {num 0}} {
global btp
set btp(lastkill) 0.0
if {$btp(arg) != "def"} {
set num $btp(arg)
set btp(arg) def
}
if {$num != 0} {set num [expr $num-1]}
bt:move-line $w $num
$w mark set insert {insert linestart}
$w tag remove sel 1.0 end
$w yview -pickplace insert
set btp(prevcmd) "begin-line"
}
proc bt:end-line { w {num 0}} {
global btp
set btp(lastkill) 0.0
if {$btp(arg) != "def"} {
set num $btp(arg)
set btp(arg) def
}
if {$num != 0} {set num [expr $num-1]}
bt:move-line $w $num
$w mark set insert {insert lineend}
$w tag remove sel 1.0 end
$w yview -pickplace insert
set btp(prevcmd) end-line
}
proc bt:begin-buffer { w {num 0}} {
global btp
set btp(lastkill) 0.0
if {$btp(arg) != "def"} {
set num $btp(arg)
set btp(arg) def
}
bt:set-mark $w
set ndx [expr 1+[lindex [split [$w index end] .] 0]*$num/10]
$w mark set insert $ndx.0
$w tag remove sel 1.0 end
$w yview -pickplace insert
set btp(prevcmd) begin-buffer
}
proc bt:end-buffer { w {num 0}} {
global btp
set btp(lastkill) 0.0
if {$btp(arg) != "def"} {
set num $btp(arg)
set btp(arg) def
}
bt:set-mark $w
set ndx [expr [lindex [split [$w index end] .] 0]*$num/10]
$w mark set insert "end - $ndx lines"
$w tag remove sel 1.0 end
$w yview -pickplace insert
set btp(prevcmd) end-buffer
}
proc bt:scroll-next { w {num 1}} {
global btp
set btp(lastkill) 0.0
if {$btp(arg) != "def"} {
set num $btp(arg)
set btp(arg) def
}
$w tag remove sel 1.0 end
set scr [lindex [lindex [$w configure -yscroll] 4] 0]
$w mark set insert [lindex [$scr get] 3].0
$w yview insert-1l
set btp(prevcmd) scroll-next
}
proc bt:scroll-prior { w {num 1}} {
global btp
set btp(lastkill) 0.0
if {$btp(arg) != "def"} {
set num $btp(arg)
set btp(arg) def
}
$w tag remove sel 1.0 end
set scr [lindex [lindex [$w configure -yscroll] 4] 0]
set tndx [expr [lindex [$scr get] 2]-[lindex [$scr get] 1]+5].0
if {$tndx < 1.0} {set tndx 1.0}
$w mark set insert $tndx
$w yview insert-1l
set btp(prevcmd) scroll-prior
}
proc bt:delete-word { w {num 1}} {
global btp
$w tag remove sel 1.0 end
if {[$w compare $btp(lastkill) == insert]} {
set lastcut [bt:pop-cut]
} else { set lastcut "" }
set beg [$w index insert]
if {$btp(arg) != "def"} {
set num $btp(arg)
set btp(arg) def
}
bt:move-word $w $num
#puts "$num : $beg [$w index insert]"
if {$beg < [$w index insert]} {
bt:push-cut "$lastcut[$w get $beg insert]"
$w delete $beg insert
} else {
bt:push-cut "[$w get insert $beg]$lastcut"
$w delete insert $beg
}
set btp(lastkill) [$w index insert]
$w yview -pickplace insert
set btp(prevcmd) delete-word
}
proc bt:delete-line { w {num 0}} {
global btp
$w tag remove sel 1.0 end
if {$btp(arg) != "def"} {
set num $btp(arg)
set btp(arg) def
}
if {[$w compare $btp(lastkill) == insert]} {
set lastcut [bt:pop-cut]
} else { set lastcut ""}
# while {[$w get insert] == " "} {
# $w mark set insert insert+1c
# }
if {[$w compare insert == "insert lineend"] && $num == 0} { set num 1 }
set beg [$w index insert]
if {$num != 0} {
bt:move-line $w $num
bt:begin-line $w
if {$beg < [$w index insert]} {
bt:push-cut "$lastcut[$w get $beg insert]"
$w delete $beg insert
} else {
bt:push-cut "[$w get insert $beg]$lastcut"
$w delete insert $beg
}
} else {
bt:push-cut "$lastcut[$w get insert {insert lineend}]"
$w delete insert {insert lineend};
$w yview -pickplace insert
}
$w yview -pickplace insert
set btp(lastkill) [$w index insert]
set btp(prevcmd) delete-line
}
proc bt:delete-back-char-or-sel { w {num 1} } {
global btp
if {$btp(arg) != "def"} {
set num $btp(arg)
} else {set btp(lastkill) 0.0}
set num [expr -1*$num]
if {$num > -1} {set num "+$num"}
if {[$w compare $btp(lastkill) == insert]} {
set lastcut [bt:pop-cut]
} else { set lastcut ""}
if [catch {set tmp [$w get sel.first sel.last]}] {
if {$btp(arg) != "def"} {
if {$num < 0} {
bt:push-cut "[$w get "insert $num char" insert]$lastcut"
$w delete "insert $num char" insert
} else {
bt:push-cut "$lastcut[$w get insert "insert $num char"]"
$w delete insert "insert $num char"
}
set btp(lastkill) [$w index insert]
} else {
if {$num < 0} {
$w delete "insert $num char" insert
} else {
$w delete insert "insert $num char"
}
set btp(lastkill) 0.0
}
} else {
$w delete sel.first sel.last
bt:push-cut $tmp
set btp(lastkill) 0.0
}
set btp(arg) def
$w yview -pickplace insert
set btp(prevcmd) delete-back-char-or-sel
}
proc bt:delete-region-or-sel { w } {
global btp
if {[catch {set tmp [$w get sel.first sel.last]}]} {
if {[catch "$w index emacs"]} {
$btp(error) "No emacs mark has been set yet!"
}
if {[$w compare $btp(lastkill) == insert]} {
set lastcut [bt:pop-cut]
} else { set lastcut ""}
if {[$w compare emacs < insert]} {
bt:push-cut "$lastcut[$w get emacs insert]"
$w delete emacs insert
} else {
bt:push-cut "[$w get insert emacs]$lastcut"
$w delete insert emacs
}
set btp(lastkill) [$w index insert]
} else {
$w delete sel.first sel.last
bt:push-cut $tmp
set btp(lastkill) 0.0
}
set btp(arg) def
set btp(prevcmd) delete-region-or-sel
}
proc bt:copy-region-or-sel { w } {
global btp
if {[catch {set tmp [$w get sel.first sel.last]}]} {
if {[catch "$w index emacs"]} {
$btp(error) "No emacs mark has been set yet!"
}
if {[$w compare $btp(lastkill) == insert]} {
set lastcut [bt:pop-cut]
} else { set lastcut ""}
if {[$w compare emacs < insert]} {
bt:push-cut "$lastcut[$w get emacs insert]"
} else {
bt:push-cut "[$w get insert emacs]$lastcut"
}
bt:exchange-point-and-mark $w
after 200 bt:exchange-point-and-mark $w
} else {
bt:push-cut $tmp
}
set btp(arg) def
set btp(lastkill) 0.0
set btp(prevcmd) copy-region-or-sel
}
proc bt:append-next-kill { w } {
global btp
set btp(lastkill) [$w index insert]
}
proc bt:push-cut { txt } {
global btp
set btp(killlen) [llength [lappend btp(killring) $txt]]
if { $btp(killlen) > $btp(maxkill)} {
set btp(killring) [lreplace $btp(killring) 0 0]
incr btp(killlen) -1 }
set btp(killptr) 0
}
proc bt:pop-cut { } {
global btp
if {$btp(killlen) == 0} {return ""}
set txt [bt:get-cut 1]
set ndx [expr $btp(killlen)-1]
set btp(killring) [lreplace $btp(killring) $ndx $ndx ]
incr btp(killlen) -1
set btp(killptr) 0
return $txt
}
proc bt:get-cut { {ndx 1} } {
global btp
set ndx [expr $ndx+$btp(killptr)]
set btp(killptr) [expr $ndx-1]
set ndx [expr $ndx%$btp(killlen)]
if {$ndx == 0} {set ndx $btp(killlen)}
return [lindex $btp(killring) [expr $btp(killlen)-$ndx]]
}
proc bt:yank { w {num 1}} {
global btp
$w tag remove sel 1.0 end
if {$btp(arg) != "def"} {
set num $btp(arg)
set btp(arg) def
}
set btp(lastkill) 0.0
set tmp [$w index insert]
$w insert insert [bt:get-cut $num]
$w mark set emacs $tmp
$w yview -pickplace insert
set btp(prevcmd) yank
}
proc bt:yank-pop { w {num 1}} {
global btp
if {$btp(arg) != "def"} {
set num $btp(arg)
set btp(arg) def
}
if {$btp(prevcmd) != "yank"} return
$w tag remove sel 1.0 end
$w delete emacs insert
set tmp [$w index insert]
$w insert insert [bt:get-cut [expr $num+1]]
$w mark set emacs $tmp
$w yview -pickplace insert
}
proc bt:pop-mark { w } {
global btp
set ndx [expr [llength $btp($w,markring)]-1]
set oldmark [lindex $btp($w,markring) $ndx]
$w mark set emacs $oldmark
set btp($w,markring) [concat $oldmark [lreplace $btp($w,markring) $ndx $ndx]]
}
proc bt:push-mark { w ndx } {
global btp
lappend btp($w,markring) $ndx
$w tag remove emacssel 1.0 end
}
proc bt:set-mark { w {num def}} {
global btp
$w tag remove sel 1.0 end
if {$btp(arg) != "def"} {
set num $btp(arg)
set btp(arg) def
}
if {$num != "def"} {
if {[catch "$w index emacs"]} {
$btp(error) "No emacs mark has been set yet!"
}
#puts stdout "$w.yview \n"
$w yview -pickplace insert
bt:pop-mark $w
$w mark set insert emacs
} else {
bt:push-mark $w [$w index insert]
$w mark set emacs insert
}
set btp(lastkill) 0.0
set btp(prevcmd) set-mark
}
proc bt:exchange-point-and-mark { w } {
global btp
if {[catch "$w index emacs"]} {
$btp(error) "No emacs mark has been set yet!"
}
set tmp [$w index insert]
$w mark set insert emacs
$w mark set emacs $tmp
set btp(lastkill) 0.0
set btp(prevcmd) set-mark
}
proc bt:open-line {w {num 1}} {
global btp
if {$btp(arg) != "def"} {
set num $btp(arg)
set btp(arg) def
}
catch {$w delete sel.first sel.last}
for {set i 0} {$i < $num } {incr i} {
$w insert insert \n
}
$w mark set insert insert-1c
$w yview -pickplace insert
set btp(prevcmd) open-line
}
proc bt:argkey { w a } {
global btp
set btp(arg) $a
}
proc bt:numkey { w a } {
global btp
if {$btp(arg) == "def"} {
catch {%W delete sel.first sel.last}
$w insert insert $a
if {$btp(fillcol) && [bt:current-col $w] >= $btp(fillcol)} {
bt:wrap-word $w
}
$w yview -pickplace insert
set btp(lastkill) 0.0
set btp(prevcmd) self-insert
} else {
if {$a == "-"} {
if {$btp(arg) == "-"} {
set btp(arg) "0"
} elseif {$btp(arg) == "0"} {
set btp(arg) "-"
} else {
set btp(arg) [expr -1*$btp(arg)]
}
} else {
append btp(arg) $a
}
}
}
proc bt:univ-arg { w } {
global btp
if {$btp(arg) == "def"} {
set btp(arg) 4
} else {
if {$btp(arg) == "-"} {
set btp(arg) "-4"
} else {
set btp(arg) [expr 4*$btp(arg)]
}
}
}
proc bt:wrap-word { w } {
global btp
bt:move-word $w -1
$w insert insert \n
bt:end-line $w
}
proc bt:set-fill-col { w {num 0}} {
global btp
if {$btp(arg) == "def"} {
if {$num < 1} {
set btp(fillcol) [bt:current-col $w]
} else {
set btp(fillcol) $num
}
} else {
if {$btp(arg) < 1} {
set btp(fillcol) [bt:current-col $w]
} else {
set btp(fillcol) $btp(arg)
}
}
set btp(arg) def
set btp(lastkill) 0.0
set btp(prevcmd) set-fill-col
}
proc bind_motiftext { tw } {
global bind_xnd
bind $tw <Control-KeyPress> {
global btp
if {"%A" != ""} {eval $btp(beep) }
}
# Some better bindings for text and entry
bind $tw <Up> {bt:move-line %W -1}
bind $tw <Down> {bt:move-line %W 1}
bind $tw <Left> {bt:move-char %W -1}
bind $tw <Right> {bt:move-char %W 1}
bind $tw <Home> {bt:begin-line %W}
bind $tw <End> {bt:end-line %W}
bind $tw <Control-Home> {bt:begin-buffer %W}
bind $tw <Control-End> {bt:end-buffer %W}
bind $tw <Control-Left> {bt:move-word %W -1}
bind $tw <Control-Right> {bt:move-word %W 1}
bind $tw <Next> {bt:scroll-next %W}
bind $tw <Prior> {bt:scroll-prior %W}
bind $tw <Any-KeyPress> {
global btp
set num 1
if {"%A" != ""} {
if {$btp(arg) != "def"} {
set num $btp(arg)
set btp(arg) def
}
catch {%W delete sel.first sel.last}
for {set i 0} { $i < $num} {incr i} {%W insert insert %A}
if {$btp(fillcol) && [bt:current-col %W] >= $btp(fillcol)} {
if {"%A" == " "} {
%W insert insert \n
} elseif {"%A" == "\t"} {
%W insert insert \n\t
} else {
bt:wrap-word %W
}
}
%W yview -pickplace insert
set btp(lastkill) 0.0
set btp(prevcmd) self-insert
}
}
bind $tw <KeyPress-Return> {
global btp
catch {%W delete sel.first sel.last}
set num 1
if {$btp(arg) != "def"} {
set num $btp(arg)
set btp(arg) def
}
for {set i 0} { $i < $num} {incr i} {%W insert insert "\n"}
%W yview -pickplace insert
set btp(lastkill) 0.0
set btp(prevcmd) newline
}
bind $tw <KeyPress-Delete> {bt:delete-back-char-or-sel %W 1}
bind $tw <KeyPress-BackSpace> {bt:delete-back-char-or-sel %W 1}
bind $tw <1> "[bind Text <1>]; \
global btp; set btp(lastkill) 0.0; \
set btp(prevcmd) mouse-set"
bind $tw <3> {%W tag remove sel 1.0 end}
bind $tw <B1-Motion> {bind_textB1motion %W @%x,%y}
set bind_xnd(b2-time) 0
set bind_xnd(b2-y) 0
bind $tw <2> {
global bind_xnd
%W scan mark %y
set bind_xnd(b2-time) %t
set bind_xnd(b2-y) %y
}
bind $tw <ButtonRelease-2> {
global bind_xnd
if {[expr %t-$bind_xnd(b2-time)]<1000} {
%W insert insert [selection_if_any]
global btp
set btp(lastkill) 0.0
set btp(prevcmd) mouse-insert
}
}
# only one mouse, so no need have separate vars for each widget
set bind_xnd(txnd) 0
set bind_xnd(xdelay) 100
proc bind_textB1motion { w loc } {
global bind_xnd
set ypos [lindex [split $loc ","] 1]
if {$ypos > [winfo height $w]} {
if {!$bind_xnd(txnd)} {after $bind_xnd(xdelay) bind_textExtend $w}
set bind_xnd(txnd) 1
set bind_xnd(direction) down
} elseif {$ypos < 0} {
if {!$bind_xnd(txnd)} {after $bind_xnd(xdelay) bind_textExtend $w}
set bind_xnd(txnd) 1
set bind_xnd(direction) up
} else {
set bind_xnd(txnd) 0
set bind_xnd(direction) 0
}
if {!$bind_xnd(txnd)} {
tk_textSelectTo $w $loc
}
}
bind $tw <ButtonRelease-1> {
global bind_xnd btp
set bind_xnd(txnd) 0
set btp(lastkill) 0.0
set btp(prevcmd) mouse-select
}
proc bind_textExtend { w } {
global bind_xnd
if {$bind_xnd(txnd)} {
if {$bind_xnd(direction) == "down"} {
tk_textSelectTo $w sel.last+1l
$w yview -pickplace sel.last+1l
} elseif {$bind_xnd(direction) == "up"} {
tk_textSelectTo $w sel.first-1l
$w yview -pickplace sel.first-1l
} else { return }
after $bind_xnd(xdelay) bind_textExtend $w
}
}
}
proc bind_emacstext { tw } {
global btp
bind $tw <Any-KeyPress> {
if [catch {set tmp [%W get emacssel.first emacssel.last]}] {
} else {
%W tag remove emacssel 1.0 $first
%W tag add emacssel $first $last
%W tag remove emacssel $last end
update idletasks
}
%W insert insert %A
}
# make Escape key simulate a state Alt key
bind $tw <Escape> { }
bind $tw <Escape><Any-KeyPress> {
global btp
if {"%A" != ""} {eval $btp(beep) }
}
bind $tw <Control-a> {bt:begin-line %W}
bind $tw <Control-e> {bt:end-line %W}
bind $tw <Control-f> {bt:move-char %W 1}
bind $tw <Control-b> {bt:move-char %W -1}
bind $tw <Escape><f> {bt:move-word %W 1}
bind $tw <Escape><b> {bt:move-word %W -1}
bind $tw <Control-n> {bt:move-line %W 1}
bind $tw <Control-p> {bt:move-line %W -1}
bind $tw <Control-l> {
%W yview -pickplace insert
}
bind $tw <Control-o> {bt:open-line %W 1}
bind $tw <Control-d> {bt:delete-back-char-or-sel %W -1}
bind $tw <Escape><d> {bt:delete-word %W 1}
bind $tw <Control-h> {bt:delete-back-char-or-sel %W -1}
bind $tw <Control-k> {bt:delete-line %W 0}
bind $tw <Control-w> {bt:delete-region-or-sel %W}
bind $tw <Escape><w> {bt:copy-region-or-sel %W}
bind $tw <Control-y> {bt:yank %W}
bind $tw <Escape><y> {bt:yank-pop %W}
bind $tw <Control-space> {bt:set-mark %W}
bind $tw <Control-u> {bt:univ-arg %W}
bind $tw <KeyPress-0> {bt:numkey %W %A}
bind $tw <KeyPress-1> {bt:numkey %W %A}
bind $tw <KeyPress-2> {bt:numkey %W %A}
bind $tw <KeyPress-3> {bt:numkey %W %A}
bind $tw <KeyPress-4> {bt:numkey %W %A}
bind $tw <KeyPress-5> {bt:numkey %W %A}
bind $tw <KeyPress-6> {bt:numkey %W %A}
bind $tw <KeyPress-7> {bt:numkey %W %A}
bind $tw <KeyPress-8> {bt:numkey %W %A}
bind $tw <KeyPress-9> {bt:numkey %W %A}
bind $tw <Escape><KeyPress-0> {bt:argkey %W %A}
bind $tw <Escape><KeyPress-1> {bt:argkey %W %A}
bind $tw <Escape><KeyPress-2> {bt:argkey %W %A}
bind $tw <Escape><KeyPress-3> {bt:argkey %W %A}
bind $tw <Escape><KeyPress-4> {bt:argkey %W %A}
bind $tw <Escape><KeyPress-5> {bt:argkey %W %A}
bind $tw <Escape><KeyPress-6> {bt:argkey %W %A}
bind $tw <Escape><KeyPress-7> {bt:argkey %W %A}
bind $tw <Escape><KeyPress-8> {bt:argkey %W %A}
bind $tw <Escape><KeyPress-9> {bt:argkey %W %A}
bind $tw <Escape><KeyPress-minus> {bt:argkey %W %A}
# make C-x key a state
bind $tw <Control-x> { }
bind $tw <Control-x><Any-KeyPress> {
global btp
if {"%A" != ""} {eval $btp(beep) }
}
bind $tw <Control-x><Control-x> {bt:exchange-point-and-mark %W}
bind $tw <Control-x><KeyPress-f> {bt:set-fill-col %W}
# Make Meta key like and Escape prefix
if {$btp(use-meta)} {
bind $tw <Meta-KeyPress> {
global btp
if {"%A" != ""} {eval $btp(beep) }
}
bind $tw <Control-Meta-KeyPress> {
global btp
if {"%A" != ""} {eval $btp(beep) }
}
bind $tw <Meta-f> {bt:move-word %W 1}
bind $tw <Meta-b> {bt:move-word %W -1}
bind $tw <Meta-d> {bt:delete-word %W 1}
bind $tw <Meta-w> {bt:copy-region-or-sel %W}
bind $tw <Meta-y> {bt:yank-pop %W}
bind $tw <Meta-0> {bt:argkey %W %A}
bind $tw <Meta-1> {bt:argkey %W %A}
bind $tw <Meta-2> {bt:argkey %W %A}
bind $tw <Meta-3> {bt:argkey %W %A}
bind $tw <Meta-4> {bt:argkey %W %A}
bind $tw <Meta-5> {bt:argkey %W %A}
bind $tw <Meta-6> {bt:argkey %W %A}
bind $tw <Meta-7> {bt:argkey %W %A}
bind $tw <Meta-8> {bt:argkey %W %A}
bind $tw <Meta-9> {bt:argkey %W %A}
bind $tw <Meta-minus> {bt:argkey %W %A}
}
}
#----------------------------------------------------------------------------
#----------------------------------------------------------------------------
#
# The xe main code follows now ...
#
#----------------------------------------------------------------------------
#----------------------------------------------------------------------------
#---------------------------------------------------------------
# PrintOutputWindow
#
#---------------------------------------------------------------
proc PrintOutputWindow { printer_pipe } {
set f [open "|$printer_pipe" w]
puts $f [.pane.output.text get 1.0 end ]
close $f
}
#---------------------------------------------------------------
# PrintPreDefined
#
#---------------------------------------------------------------
proc PrintPreDefined { } {
global landscape doublesided nobanner prsize
set printerName [.printdlg.input.predef.f.prname.name get]
#puts stderr "printer_name: $printerName"
#puts stderr "landscape: $landscape"
#puts stderr "doublesided: $doublesided"
#puts stderr "prsize: $prsize"
array set sizeoption {
yes-large { -o vsi7 -o fp16 -o landscape }
yes-normal { -o vsi6 -o fp18 -o landscape -o height80 }
yes-small { -o vsi5 -o fp20 -o landscape -o height90 }
yes-smallest { -o vsi4 -o fp24 -o landscape -o height100 }
yes-micro { -o vsi3 -o fp28 -o landscape -o height110 }
no-large { -o vsi7 -o fp16 -o portrait }
no-normal { -o vsi6 -o fp18 -o portrait }
no-small { -o vsi5 -o fp20 -o portrait }
no-smallest { -o vsi4 -o fp24 -o portrait }
}
set command $sizeoption(${landscape}-${prsize})
if {$doublesided == "yes"} {
append command " -o duplex"
} else {
append command " -o simplex"
}
if {$nobanner == "yes"} {
append command " -o nb"
}
append command " -d $printerName"
PrintOutputWindow "lp $command"
}
#---------------------------------------------------------------
# PrintDialog
#
#---------------------------------------------------------------
proc PrintDialog { } {
global dbname dbsname
set w .printdlg
catch {destroy $w}
toplevel $w -class Dialog
wm title $w "Print Output"
wm iconname $w "Print Output"
wm protocol $w WM_DELETE_WINDOW { }
frame $w.input \
-relief flat -borderwidth 0 -highlightthickness 0
frame $w.buttons \
-relief flat -borderwidth 0 -highlightthickness 0
button $w.buttons.print \
-text " Print " \
-command "PrintPreDefined; destroy $w"
button $w.buttons.cancel \
-text " Cancel " -command "destroy $w"
pack $w.buttons.print $w.buttons.cancel -side top -pady 10 -fill x
#-----------------------------------------------
# pre-customized printer configuration
#-----------------------------------------------
frame $w.input.predef \
-relief flat -borderwidth 0 -highlightthickness 0
label $w.input.predef.h \
-text "Pre-customized Printer Configuration:"
frame $w.input.predef.f \
-relief groove -borderwidth 2 -highlightthickness 0
pack $w.input.predef.h -anchor w -side top
pack $w.input.predef.f -side top -ipadx 5 -ipady 5 -fill x
frame $w.input.predef.f.prname \
-relief groove -borderwidth 0 -highlightthickness 0
label $w.input.predef.f.prname.l \
-text "Printer Name:"
entry $w.input.predef.f.prname.name \
-relief sunken -borderwidth 1 -highlightthickness 1 \
-width 20 -background gray90 -exportselection yes
pack $w.input.predef.f.prname.l -side left
pack $w.input.predef.f.prname.name -side left -anchor w -fill x
frame $w.input.predef.f.kind \
-relief groove -borderwidth 0 -highlightthickness 0
radiobutton $w.input.predef.f.kind.large \
-text "Large (100 char width) " -variable prsize -relief flat -value large
radiobutton $w.input.predef.f.kind.normal \
-text "Normal (150 char width)" -variable prsize -relief flat -value normal
radiobutton $w.input.predef.f.kind.small \
-text "Small (200 char width)" -variable prsize -relief flat -value small
radiobutton $w.input.predef.f.kind.smallest \
-text "Smallest (240 char width)" -variable prsize -relief flat -value smallest
radiobutton $w.input.predef.f.kind.micro \
-text "Micro (>240 char width)" -variable prsize -relief flat -value micro
$w.input.predef.f.kind.small select
pack $w.input.predef.f.kind.large \
$w.input.predef.f.kind.normal \
$w.input.predef.f.kind.small \
$w.input.predef.f.kind.smallest \
$w.input.predef.f.kind.micro -anchor w -side top
frame $w.input.predef.f.optionskind \
-relief groove -borderwidth 0 -highlightthickness 0
checkbutton $w.input.predef.f.optionskind.landscape -text "landscape (-o landscape)" \
-variable landscape -onvalue "yes" -offvalue "no" -relief flat
$w.input.predef.f.optionskind.landscape select
checkbutton $w.input.predef.f.optionskind.double -text "double sided (-o duplex)" \
-variable doublesided -onvalue "yes" -offvalue "no" -relief flat
checkbutton $w.input.predef.f.optionskind.nobanner -text "no banner (-o nb)" \
-variable nobanner -onvalue "yes" -offvalue "no" -relief flat
pack $w.input.predef.f.optionskind.landscape \
$w.input.predef.f.optionskind.double \
$w.input.predef.f.optionskind.nobanner -anchor w -side top
pack $w.input.predef.f.prname \
$w.input.predef.f.kind \
$w.input.predef.f.optionskind -side top -padx 1 -pady 5 -fill x
#-----------------------------------------------
# self printer configuration
#-----------------------------------------------
frame $w.input.self \
-relief flat -borderwidth 0 -highlightthickness 0
label $w.input.self.h \
-text "Full Command Line:"
frame $w.input.self.f2 \
-relief groove -borderwidth 2 -highlightthickness 0
entry $w.input.self.f2.cmdline \
-relief sunken -borderwidth 2 -highlightthickness 1 \
-width 40 -background gray90 -exportselection yes
button $w.input.self.f2.print \
-text " Print " -command {
set printer_pipe [.printdlg.input.self.f2.cmdline get];
PrintOutputWindow "$printer_pipe"
}
pack $w.input.self.f2.cmdline $w.input.self.f2.print \
-side left -padx 5
pack $w.input.self.h -anchor w -side top
pack $w.input.self.f2 -side top -ipadx 5 -ipady 5
#-------------------------------------------------------------
pack $w.input.predef $w.input.self -side top -pady 10 -fill x
pack $w.input -side left -padx 10 -pady 10 -fill x
pack $w.buttons -side left -padx 10 -pady 30 -fill y
}
#----------------------------------------------------------------------------
# SaveTextWindow
#
#----------------------------------------------------------------------------
proc SaveTextWindow { textw filename } {
set f [open $filename w ];
$textw mark set insert end
#--remove the empty part at the bottom
while {1} {
set line [$textw get {insert linestart} {insert lineend}]
if {$line != ""} {
break;
}
$textw mark set insert {insert -1 line}
if {[$textw compare insert < 3.0]} {
break;
}
}
puts $f [$textw get 1.0 {insert lineend} ]
close $f
}
#----------------------------------------------------------------------------
# Base64Init
#
#----------------------------------------------------------------------------
proc Base64Init { } {
global base64_b2c base64_c2b
set i -1
foreach a { A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
a b c d e f g h i j k l m n o p q r s t u v w x y z
0 1 2 3 4 5 6 7 8 9 + / } {
binary scan [binary format c1 [incr i]] B* v
set base64_b2c([string range $v 2 end]) $a
set base64_c2b($a) [string range $v 2 end]
}
}
#----------------------------------------------------------------------------
# Base64EncodeBufferData
#
#----------------------------------------------------------------------------
proc Base64EncodeBufferData { data } {
global base64_b2c
# Get the bit stream
binary scan $data B* bits
# Convert groups of six bits to a list for easy traversal
regsub -all {((0|1)(0|1)(0|1)(0|1)(0|1)(0|1))} $bits {\1 } bits
foreach b $bits {
append result $base64_b2c($b)
}
return $result
}
#----------------------------------------------------------------------------
# Base64Encode
#
#----------------------------------------------------------------------------
proc Base64Encode { data {buffersize 6144} } {
global base64_b2c
if { ![array exists base64_b2c] } {
Base64Init
}
# Convert the data to a bitstream and then encode.
# This approach requires a buffer eight times the size of the
# data to be encoded, so just work on a buffer at a time.
# The default buffer size is 6 * 1024 bytes (6KB).
# This is a trade-off between speed and space.
if {$buffersize % 3} {
# Buffer must be a multiple of 3 bytes
set buffersize [expr $buffersize - $buffersize % 3]
}
set linelen 0
while {[string length $data] > $buffersize} {
# Get the buffer to work on
set buffer [string range $data 0 [expr $buffersize - 1]]
set data [string range $data $buffersize end]
append result [Base64EncodeBufferData $buffer]
}
if {[string length $data]} {
# Deal with remaining data
# Encode to an even multiple of 3 bytes, and then
# pad the rest
set buffer [string range $data 0 [expr [string length $data] - [string length $data] % 3 - 1]]
set remainder [string range $data [expr [string length $data] - [string length $data] % 3] end]
append result [Base64EncodeBufferData $buffer]
switch [string length $remainder] {
1 {
binary scan $remainder B* bits
append result $base64_b2c([string range $bits 0 5])
append result $base64_b2c([string range $bits 6 7]0000)
append result ==
}
2 {
binary scan $remainder B* bits
append result $base64_b2c([string range $bits 0 5])
append result $base64_b2c([string range $bits 6 11])
append result $base64_b2c([string range $bits 12 15]00)
append result =
}
}
}
# Ensure lines are no more than 76 characters
regsub -all {(........................................................................)} \
$result "\\1\n" result
return $result
}
#----------------------------------------------------------------------------
# IntroWindow
#
#----------------------------------------------------------------------------
proc IntroWindow { } {
global HelvB12 Helv12
frame .splash -borderwidth 4 -relief raised
label .splash.info1 -font $HelvB12 -text "XE - a simple XML/XPath Browser/Viewer"
label .splash.info2 -font $Helv12 -text "Version 0.2"
label .splash.info3 -font $Helv12 -text "Copyright (c) 1999,2001 Jochen Loewer (loewerj@hotmail.com)"
pack .splash.info1 \
.splash.info2 \
.splash.info3 -padx 4 -pady 4 -anchor w
place .splash -anchor c -relx .5 -rely .5
after 2500 destroy .splash
update
}
#----------------------------------------------------------------------------
# ConfigureProxy
#
#----------------------------------------------------------------------------
proc ConfigureProxy { } {
global HttpProxyHost HttpProxyPort gotProxy
set gotProxy -1
set w .proxyDdlg
catch {destroy $w}
toplevel $w -class Dialog
wm title $w "Configure HTTP Proxy"
wm iconname $w "HTTP Proxy"
wm protocol $w WM_DELETE_WINDOW { }
frame $w.hdr \
-relief flat -borderwidth 0 -highlightthickness 0
label $w.hdr.icon -bitmap questhead
label $w.hdr.msg -text "Specify HTTP proxy server: "
frame $w.fields \
-relief flat -borderwidth 0 -highlightthickness 0
label $w.fields.hostlabel -text "Proxy Host:"
entry $w.fields.hostvalue \
-relief sunken -borderwidth 1 -highlightthickness 1 \
-width 20 -background gray90 -exportselection yes
label $w.fields.portlabel -text "Porxy Port:"
entry $w.fields.portvalue \
-relief sunken -borderwidth 1 -highlightthickness 1 \
-width 20 -background gray90 -exportselection yes
frame $w.buttons \
-relief flat -borderwidth 0 -highlightthickness 0
button $w.buttons.ok -text " OK " \
-command "set gotProxy \[list 1 \[$w.fields.hostvalue get\] \
\[$w.fields.portvalue get\] \]; \
destroy $w"
bind $w.fields.portvalue <Return> " \
set gotProxy \[list 1 \[$w.fields.hostvalue get\] \
\[$w.fields.portvalue get\] \]; \
destroy $w"
button $w.buttons.cancel -text " Cancel " \
-command "destroy $w; set gotProxy {0 {} {}}"
$w.fields.hostvalue insert 0 $HttpProxyHost
$w.fields.portvalue insert 0 $HttpProxyPort
pack $w.hdr.icon $w.hdr.msg -side left
grid $w.fields.hostlabel -in $w.fields -column 0 -row 0 -sticky e
grid $w.fields.portlabel -in $w.fields -column 0 -row 1 -sticky e
grid $w.fields.hostvalue -in $w.fields -column 1 -row 0 -sticky w
grid $w.fields.portvalue -in $w.fields -column 1 -row 1 -sticky w
pack $w.buttons.ok $w.buttons.cancel -side left
pack $w.hdr \
$w.fields \
$w.buttons -side top -anchor w -padx 9 -pady 9
focus $w.fields.hostvalue
while {$gotProxy == -1} {
vwait gotProxy
}
if {[lindex $gotProxy 0]} {
set HttpProxyHost [lindex $gotProxy 1]
set HttpProxyPort [lindex $gotProxy 2]
}
}
#----------------------------------------------------------------------------
# GetUserPassword
#
#----------------------------------------------------------------------------
proc GetUserPassword { state_var login_var password_var } {
global gotPassword Login
upvar $state_var state
upvar $login_var login
upvar $password_var password
#parray state
set server ""
set realm ""
regexp {http://([^/]*)/(.*)} $state(url) all server file
array set meta $state(meta)
if {[info exists meta(WWW-authenticate)]} {
set realmStr [lindex $meta(WWW-authenticate) 1]
regexp {realm="([^"]*)"} $realmStr all realm
}
#puts stderr "login='$login' password='$password' server='$server' realm='$realm'"
if {[info exists Login($server,$realm)]} {
foreach { new_login new_password } $Login($server,$realm) break
if {($new_login != $login ) || ($new_password != $password)} {
set login $new_login
set password $new_password
return 1
}
}
set gotPassword -1
set login ""
set password ""
set w .passwordDdlg
catch {destroy $w}
toplevel $w -class Dialog
wm title $w "HTTP Password"
wm iconname $w "HTTP Password"
wm protocol $w WM_DELETE_WINDOW { }
frame $w.hdr \
-relief flat -borderwidth 0 -highlightthickness 0
label $w.hdr.icon -bitmap questhead
label $w.hdr.msg -text "Enter username for $realm at $server "
frame $w.fields \
-relief flat -borderwidth 0 -highlightthickness 0
label $w.fields.userlabel -text "User name:"
entry $w.fields.uservalue \
-relief sunken -borderwidth 1 -highlightthickness 1 \
-width 20 -background gray90 -exportselection yes
label $w.fields.passlabel -text "Password:"
entry $w.fields.passvalue \
-relief sunken -borderwidth 1 -highlightthickness 1 \
-width 20 -background gray90 -exportselection yes -show *
frame $w.buttons \
-relief flat -borderwidth 0 -highlightthickness 0
button $w.buttons.ok -text " OK " \
-command "set gotPassword \[list 1 \[$w.fields.uservalue get\] \
\[$w.fields.passvalue get\] \]; \
destroy $w"
bind $w.fields.passvalue <Return> " \
set gotPassword \[list 1 \[$w.fields.uservalue get\] \
\[$w.fields.passvalue get\] \]; \
destroy $w"
button $w.buttons.cancel -text " Cancel " \
-command "destroy $w; set gotPassword {0 {} {}}"
pack $w.hdr.icon $w.hdr.msg -side left
grid $w.fields.userlabel -in $w.fields -column 0 -row 0 -sticky e
grid $w.fields.passlabel -in $w.fields -column 0 -row 1 -sticky e
grid $w.fields.uservalue -in $w.fields -column 1 -row 0 -sticky w
grid $w.fields.passvalue -in $w.fields -column 1 -row 1 -sticky w
pack $w.buttons.ok $w.buttons.cancel -side left
pack $w.hdr \
$w.fields \
$w.buttons -side top -anchor w -padx 9 -pady 9
focus $w.fields.uservalue
while {$gotPassword == -1} {
vwait gotPassword
}
if {[lindex $gotPassword 0]} {
set login [lindex $gotPassword 1]
set password [lindex $gotPassword 2]
set Login($server,$realm) [list $login $password]
return 1
}
return 0
}
#----------------------------------------------------------------------------
# xmlEdit
#
#----------------------------------------------------------------------------
proc xmlEdit { {line 0} {column 0} } {
global xml Cour12 Helv12
if {[winfo exists .edit]} {
.edit.f.text mark set insert $line.$column
.edit.f.text see insert
focus .edit.f.text
return
}
toplevel .edit
wm title .edit "XML Source"
set path .edit.f
frame $path -relief flat -borderwidth 3 -highlightthickness 0
text $path.text -width 100 -height 30 -font $Cour12 \
-bg gray90 \
-exportselection yes -wrap none \
-yscrollcommand "$path.vsb set" \
-xscrollcommand "$path.hsb set"
scrollbar $path.vsb -relief sunken -orient vertical \
-command "$path.text yview"
scrollbar $path.hsb -relief sunken -orient horizontal \
-command "$path.text xview"
button .edit.reload -text " Reload " -command xmlReload \
-font $Helv12
pack $path.vsb -side right -fill y -expand no
pack $path.hsb -side bottom -fill x -expand no
pack $path.text -side top -fill both -expand yes
pack $path -expand yes -fill both
pack .edit.reload -anchor e
$path.text delete 1.0 end
$path.text insert end $xml
.edit.f.text mark set insert $line.$column
.edit.f.text see insert
focus .edit.f.text
}
#----------------------------------------------------------------------------
# xmlHighlight
#
#----------------------------------------------------------------------------
proc xmlHighlight { path pos tag highlight_tag} {
set range [$path tag nextrange $tag $pos [$path index "$pos lineend"] ]
if {$range == ""} {
set range [$path tag prevrange $tag $pos [$path index "$pos linestart"] ]
}
if {$range != ""} {
eval $path tag add $highlight_tag [lrange $range 0 1]
}
}
#----------------------------------------------------------------------------
# xmlHighlightMotion
#
#----------------------------------------------------------------------------
proc xmlHighlightMotion { path pos tag highlight_tag} {
set tags [$path tag names $pos]
if {[lsearch -exact $tags $highlight_tag] < 0} {
$path tag remove $highlight_tag 1.0 end
}
xmlHighlight $path $pos $tag $highlight_tag
}
#----------------------------------------------------------------------------
# xmlJump
#
#----------------------------------------------------------------------------
proc xmlJump { path pos } {
foreach tag [$path tag names $pos] {
if { ($tag != "tag") } {
xmlEdit [$tag getLine] [$tag getColumn]
}
}
}
#----------------------------------------------------------------------------
# xmlOpen
#
#----------------------------------------------------------------------------
proc xmlOpen { path pos } {
global levels
foreach tag [$path tag names $pos] {
if {($tag != "open") && ($tag != "hot") && ($tag != "sel")} {
$path configure -state normal
set start [$path index "$pos linestart"]
set end [$path index "$start + 1 lines"]
$path delete $start $end
while 1 {
set end [$path index "$start + 1 lines"]
set nextLine [$path get $start $end]
if {[string match "$levels($tag) *" $nextLine]} {
$path delete $start $end
} else {
break
}
}
$path mark set insert $start
xmlWidgetLoad_Recurs $path 0 $levels($tag) $tag 2
$path see $start
}
}
# that's a hack to remove selections, which occur sometimes
after 50 "$path tag remove sel 1.0 end"
}
#----------------------------------------------------------------------------
# xmlClose
#
#----------------------------------------------------------------------------
proc xmlClose { path pos } {
global levels
foreach tag [$path tag names $pos] {
if {($tag != "close") && ($tag != "hot") && ($tag != "sel")} {
$path configure -state normal
set start [$path index "$pos linestart"]
set end [$path index "$start + 1 lines"]
$path delete $start $end
while 1 {
set end [$path index "$start + 1 lines"]
set nextLine [$path get $start $end]
if {[string match "$levels($tag) *" $nextLine]} {
$path delete $start $end
} else {
break
}
}
$path mark set insert $start
xmlWidgetLoad_Recurs $path 0 $levels($tag) $tag 1
$path see $start
}
}
# that's a hack to remove selections, which occur sometimes
after 50 "$path tag remove sel 1.0 end"
}
#----------------------------------------------------------------------------
# xmlWidget
#
#----------------------------------------------------------------------------
proc xmlWidget { path } {
global Cour12 HelvB12
set tagFont $HelvB12
set attrFont $Cour12
set opnclFont $Cour12
frame $path -relief flat -borderwidth 0 -highlightthickness 0
text $path.text -width 100 -height 25 -font $Cour12 \
-bg gray85 -cursor left_ptr \
-exportselection yes -wrap none \
-yscrollcommand "$path.vsb set" \
-xscrollcommand "$path.hsb set"
scrollbar $path.vsb -relief sunken -orient vertical \
-command "$path.text yview"
scrollbar $path.hsb -relief sunken -orient horizontal \
-command "$path.text xview"
pack $path.vsb -side right -fill y -expand no
pack $path.hsb -side bottom -fill x -expand no
pack $path.text -side top -fill both -expand yes
#$path.text tag configure tag -font $tagFont \
# -background #ffffa666a666 \
# -foreground black
$path.text tag configure tag -font $tagFont \
-foreground #40004000D000
$path.text tag configure comment -font $attrFont \
-background #d000e800d000 \
-foreground black
$path.text tag configure textValue -font $attrFont \
-background #d200d200f000 \
-foreground black
#$path.text tag configure attr -font $attrFont \
# -background #fae0d53fdaaa \
# -foreground black
# -background #D000D000ffff \
$path.text tag configure attrName -font $attrFont \
-foreground black
# -background #D000D000ffff \
# -background #e800d000d000 \
# -background gray90 \
# -foreground #d00000000000
$path.text tag configure attrValue -font $attrFont \
-background #f000d000d000 \
-foreground black
$path.text tag configure header -background gray90 \
-foreground red2
$path.text tag configure query -background gray95 \
-foreground red2
$path.text tag configure hot -background #a666a666ffff
$path.text tag configure open -font $opnclFont
$path.text tag configure close -font $opnclFont
$path.text tag configure leave -font $opnclFont
$path.text tag bind tag <2> "xmlJump $path.text @%x,%y"
$path.text tag bind open <Enter> "xmlHighlight $path.text @%x,%y open hot"
$path.text tag bind open <Motion> "xmlHighlightMotion $path.text @%x,%y open hot"
$path.text tag bind open <Leave> "$path.text tag remove hot 1.0 end"
$path.text tag bind open <1> "xmlOpen $path.text @%x,%y"
$path.text tag bind close <Enter> "xmlHighlight $path.text @%x,%y open hot"
$path.text tag bind close <Motion> "xmlHighlightMotion $path.text @%x,%y close hot"
$path.text tag bind close <Leave> "$path.text tag remove hot 1.0 end"
$path.text tag bind close <1> "xmlClose $path.text @%x,%y"
}
#----------------------------------------------------------------------------
# xmlWidgetLoad_Recurs
#
#----------------------------------------------------------------------------
proc xmlWidgetLoad_Recurs { path doSiblings level node maxlevel } {
global levels
incr maxlevel -1
if {$maxlevel < 0} { return }
while {$node != ""} {
set levels($node) $level
$path insert insert $level
set type [$node nodeType]
if { $type == "ELEMENT_NODE" } {
set firstChild [$node firstChild]
if {$firstChild == ""} {
$path insert insert " = " leave
} else {
if {$maxlevel > 0} {
$path insert insert " - " [list close $node]
} else {
$path insert insert " + " [list open $node]
}
}
$path insert insert "[$node nodeName] " [list tag $node]
set attr_line_width 0
set attr_name_width 0
set attr_value_width [string length $level]
foreach attr [$node attributes] {
if {[llength $attr] > 1} {
if {[lindex $attr 1] == ""} {
set attr [lindex $attr 0]
} else {
set attr "[lindex $attr 1]:[lindex $attr 0]"
}
}
set l [string length $attr]
if {$l > $attr_name_width} {
set attr_name_width $l
}
incr attr_line_width $l
set l [string length [$node getAttribute $attr]]
if {$l > $attr_value_width} {
set attr_value_width $l
}
incr attr_line_width $l
}
set recurseToChilds 1
set attrDisplayMode [expr $attr_line_width > 80]
if {$attrDisplayMode} {
foreach attr [$node attributes] {
$path insert insert "\n"
$path insert insert "$level "
#$path insert insert [format " %-${attr_name_width}s = %-${attr_value_width}s " \
# $attr [$node getAttribute $attr] \
# ] attr
if {[llength $attr] > 1} {
if {[lindex $attr 1] == ""} {
set attr [lindex $attr 0]
} else {
set attr "[lindex $attr 1]:[lindex $attr 0]"
}
}
$path insert insert [format " %-${attr_name_width}s= " \
$attr \
] attrName
$path insert insert [$node getAttribute $attr] attrValue
#$path insert insert [format "%-${attr_value_width}s " \
# '[$node getAttribute $attr]' \
# ] attrValue
}
$path insert insert "\n"
} else {
if {[$node attributes] == ""} {
set childs [$node childNodes]
if {[llength $childs] == 1} {
if {[$childs nodeType] == "TEXT_NODE"} {
set value [$childs nodeValue]
if {([string length $value] < 60) &&
([string first \n $value] == -1)} {
$path insert insert $value textValue
set recurseToChilds 0
}
}
}
} else {
foreach attr [$node attributes] {
if {[llength $attr] > 1} {
if {[lindex $attr 1] == ""} {
set attr [lindex $attr 0]
} else {
set attr "[lindex $attr 1]:[lindex $attr 0]"
}
}
$path insert insert " $attr=" attrName
$path insert insert [$node getAttribute $attr] attrValue
#$path insert insert ' attrName
}
}
$path insert insert "\n"
}
set recurseToChilds 1
if {$recurseToChilds} {
foreach child [$node childNodes] {
xmlWidgetLoad_Recurs $path 1 "$level " $child $maxlevel
}
}
} else {
switch $type {
COMMENT_NODE {
$path insert insert " C "
$path insert insert [$node nodeValue] comment
$path insert insert "\n"
}
CDATA_SECTION_NODE -
TEXT_NODE {
set lines 0
foreach line [split [$node nodeValue] \n] {
if {$lines == 0} {
$path insert insert " T "
} else {
$path insert insert "$level "
}
if {$line == ""} {
$path insert insert " " textValue
} else {
$path insert insert $line textValue
}
$path insert insert "\n"
incr lines
}
}
PROCESSING_INSTRUCTION_NODE {
$path insert insert " P "
$path insert insert [$node target] tag
set lines 0
foreach line [split [$node data] \n] {
if {$lines == 0} {
$path insert insert " "
} else {
$path insert insert "$level "
}
$path insert insert $line attrValue
$path insert insert "\n"
incr lines
}
}
default {
$path insert insert " ? "
$path insert insert [$node nodeValue] attrValue
$path insert insert "\n"
}
}
}
if {!$doSiblings} {
return
}
break
#set node [$node nextSibling]
}
}
#----------------------------------------------------------------------------
# xmlWidgetLoad
#
#----------------------------------------------------------------------------
proc xmlWidgetLoad { path mode location xml query } {
global doc root keepEmpties useSimple
if {$mode == "xml"} {
if {$useSimple} {
if {$keepEmpties} {
set doc [dom parse -keepEmpties -simple $xml]
} else {
set doc [dom parse -simple $xml]
}
} else {
if {$keepEmpties} {
set doc [dom parse -keepEmpties $xml]
} else {
set doc [dom parse $xml]
}
}
} else {
if {$keepEmpties} {
set doc [dom parse -keepEmpties -html $xml]
} else {
set doc [dom parse -html $xml]
}
}
set root [$doc documentElement]
set query [string trim $query]
if {$query == ""} {
set query /
}
$path insert end \n
$path insert end xml( header
$path insert end $location query
$path insert end ") " header
$path insert end $query query
$path insert end \n
set nodes 0
set rows 0
set results [$root selectNodes $query type]
switch $type {
nodes {
foreach node $results {
$path mark set insert end
xmlWidgetLoad_Recurs $path 1 "" $node 2
$path insert end \n
incr nodes
}
}
attrnodes {
foreach {attrName attrValue} $results {
$path insert end $attrName attrName
$path insert end " "
$path insert end $attrValue attrValue
$path insert end \n
incr rows
}
}
attrvalues {
foreach result $results {
$path insert end "$result\n"
incr rows
}
}
default {
$path insert end "$results\n"
}
}
if {$rows != 0} { $path insert end "---$rows result(s)---\n" }
if {$nodes != 0} { $path insert end "---$nodes node(s)---\n" }
$path yview -pickplace end
}
#----------------------------------------------------------------------------
# xmlReload
#
#----------------------------------------------------------------------------
proc xmlReload { } {
global xml
set xml [.edit.f.text get 1.0 end]
xmlWidgetLoad .xml.text xml $xml
}
#----------------------------------------------------------------------------
# GetXML
#
#----------------------------------------------------------------------------
proc GetXML { url } {
global Login HttpProxyHost HttpProxyPort
if {[regexp { *file:(.*)} $url all path]} {
#puts stderr "file path='$path'"
set fd [open $path]
set xml [read $fd [file size $path]]
close $fd
}
if {[regexp { *http:(.*)} $url all path]} {
#puts stderr "http url='$path'"
set xml ""
set login ""
set password ""
#------------------------------------------------------
# try to re-use old login and password
#
#------------------------------------------------------
regexp {//([^/]*)/(.*)} $url all server file
set indexes [array names Login $server,*]
if {[llength $indexes] == 1} {
foreach { login password } $Login($indexes) break
}
while 1 {
set hdrs {}
if {$login != ""} {
#-------------------------------------------
# generate Basic Authenication header
#------------------------------------------
set hdrs [list Authorization "Basic [Base64Encode $login:$password]" ]
}
#-------------------------------------------
# do HTTP request
#-------------------------------------------
http::config -proxyhost $HttpProxyHost -proxyport $HttpProxyPort
set token [http::geturl $url -headers $hdrs]
#-------------------------------------------
# wait till HTTP request finishes
#------------------------------------------
http::wait $token
upvar $token state
set statuscode [lindex $state(http) 1]
if {$statuscode != "200"} {
if {$statuscode == "401"} {
if {[GetUserPassword state login password]} {
#puts stderr "login='$login' password='$password'"
continue
} else {
return ""
}
} else {
puts stderr "\n\n\nstatuscode=$statuscode"
puts stderr "$state(http)"
break
}
} else {
set xml [http::data $token]
break
}
}
}
return $xml
}
#----------------------------------------------------------------------------
# xmlExecute
#
#----------------------------------------------------------------------------
proc xmlExecute { sel } {
#puts stderr $sel
if {[regexp { *(xml|html)\(([^)]*)\)(.*)} $sel all mode location query]} {
#puts stderr "'$sel' location='$location' query='$query'"
.pane.output.text configure -cursor watch
. configure -cursor watch
update
set xml [GetXML $location]
if {$xml != ""} {
xmlWidgetLoad .pane.output.text $mode $location $xml $query
}
.pane.output.text configure -cursor left_ptr
. configure -cursor left_ptr
} else {
error "Not a complete query!!"
}
}
#----------------------------------------------------------------------------
# GotoParent
#
#----------------------------------------------------------------------------
proc GotoParent { } {
global PointerXY
set pos $PointerXY
set path .pane.output.text
foreach tag [$path tag names $pos] {
#puts stderr "tag=$tag"
if {[string match domNode* $tag]} {
set tag [$tag parentNode]
if {$tag == ""} return
$path configure -state normal
set start [$path index "$pos linestart"]
set end [$path index "$start + 1 lines"]
regexp {$( *)} [$path index "$start + 1 lines"] all level
$path delete $start $end
while 1 {
set end [$path index "$start + 1 lines"]
set nextLine [$path get $start $end]
if {[string match "$level *" $nextLine]} {
$path delete $start $end
} else {
break
}
}
$path mark set insert $start
xmlWidgetLoad_Recurs $path 0 $level $tag 2
$path see $start
}
}
}
#----------------------------------------------------------------------------
# As
#
#----------------------------------------------------------------------------
proc As { method } {
global PointerXY
set path .pane.output.text
foreach tag [$path tag names $PointerXY] {
if {[string match domNode* $tag]} {
set oldEnd [$path index end]
$path insert end \n[$tag $method]
$path see $oldEnd
}
}
}
#----------------------------------------------------------------------------
# ToXPath
#
#----------------------------------------------------------------------------
proc ToXPath { } {
global PointerXY
set path .pane.output.text
foreach tag [$path tag names $PointerXY] {
if {[string match domNode* $tag]} {
set oldEnd [$path index end]
$path insert end \n[$tag toXPath]
$path see $oldEnd
}
}
}
#----------------------------------------------------------------------------
# begin main part
#----------------------------------------------------------------------------
namespace eval ::dom::xpathFunc {
proc names { ctxNode pos nodeListType nodeList args } {
if {[llength $args] != 2} {
error "wrong # of args for XPATH function 'names'"
}
foreach { type value } $args break
if {($type != "nodes") && ($type != "attrnodes") } {
error "names only applicable for node or attribute node lists!"
}
set n {}
if {$type == "nodes"} {
foreach node $value { lappend n [$node nodeName] }
} else {
foreach {attrName attrValue} $value { lappend n $attrName }
}
return [list string $n]
}
}
set xe_save "~/.xe-input"
set xe_config "~/.xe-config"
if {[llength $argv] > 0} {
set xe_save [lindex $argv 0]
}
set bgcolor "grey90"
set fgcolor "black"
switch $tcl_platform(platform) {
unix {
set Cour12 8x13
set CourB12 8x13b
set Helv10 "-Adobe-helvetica-medium-r-normal--*-100-*"
set Helv12 "-Adobe-helvetica-medium-r-normal--*-120-*"
set HelvB10 "-Adobe-helvetica-bold-r-normal--*-100-*"
set HelvB12 "-Adobe-helvetica-bold-r-normal--*-120-*"
}
windows {
set Cour12 "{Courier New} 10"
set CourB12 "{Courier New} 10 bold"
set Helv10 "Arial 9"
set Helv12 "Arial 10"
set HelvB10 "Arial 9 bold"
set HelvB12 "Arial 10 bold"
}
}
option add *background gray80
option add *foreground black
option add *selector black
option add *Scrollbar.foreground #dfdfdf
option add *Scrollbar.activeForeground #efefef
option add *font $HelvB12
wm title . "xe - [lindex $argv 0]"
wm minsize . 30 10
wm geometry . 80x20
#---------------------------------------
# set up iconwin
#---------------------------------------
if {$tcl_platform(platform)== "unix"} {
toplevel .icwin
frame .icwin.f -relief flat -borderwidth 1
label .icwin.f.l1 -text xe -font $Helv12
label .icwin.f.l2 -text [lindex $argv 0] -font $Helv12
pack .icwin.f
pack .icwin.f.l1 .icwin.f.l2 -anchor nw
.icwin configure -relief ridge -borderwidth 2
wm geometry .icwin 60x60
wm iconwindow . .icwin
}
set keepEmpties 0
set useSimple 0
frame .menu -relief raised -borderwidth 1 -highlightthickness 0
#-- File --------------
menubutton .menu.file -text " File " -menu .menu.file.m
menu .menu.file.m -tearoff 0
.menu.file.m add command -label " Clear Input Window " -command {
.pane.upper.input.text delete 0.0 end
}
.menu.file.m add separator
.menu.file.m add command -label " Save Output Window in ~/xe-out" -command {
SaveTextWindow .pane.output.text "~/xe-out"
}
.menu.file.m add command -label " Print Output Window" -command {
PrintDialog
}
.menu.file.m add separator
.menu.file.m add command -label " Quit without Save" -command { exit }
.menu.file.m add command -label " Save Input Window in $xe_save" -command {
SaveTextWindow .pane.upper.input.text $xe_save
}
.menu.file.m add command -label " Quit and Save Input Window in $xe_save" \
-command {
SaveTextWindow .pane.upper.input.text $xe_save
exit
}
#-- Options --------------
menubutton .menu.options -text " Options " -menu .menu.options.m
menu .menu.options.m -tearoff 0
.menu.options.m add command -label " http proxy " -command ConfigureProxy
.menu.options.m add check -label " keep empties " \
-underline 1 -variable keepEmpties
.menu.options.m add check -label " use simple parser " \
-underline 1 -variable useSimple
pack .menu.file \
.menu.options -side left
label .menu.info -text "XE " -font $HelvB12
pack .menu.info -side right
pane .pane vertical 1000 1000
.pane configure -highlightthickness 0
frame .pane.upper -borderwidth 0 -highlightthickness 0
frame .pane.upper.input -borderwidth 2 -highlightthickness 0
text .pane.upper.input.text -relief sunken -bd 2 -height 10 -width 80 \
-bg $bgcolor -fg $fgcolor \
-font $Cour12 -padx 2 -pady 2 -setgrid 1 \
-yscrollcommand ".pane.upper.input.sb set"
.pane.upper.input.text configure -exportselection yes
.pane.upper.input.text tag configure search -background white -foreground black
scrollbar .pane.upper.input.sb -relief sunken -command ".pane.upper.input.text yview"
pack .pane.upper.input.sb -side right -fill y -expand no
pack .pane.upper.input.text -side top -fill both -expand yes
xmlWidget .pane.output
pack .pane.output -side bottom -fill both -expand yes
frame .pane.upper.buttons -borderwidth 1 -highlightthickness 0
label .pane.upper.buttons.searchL -text " search:" -underline 4 -font $Helv12
entry .pane.upper.buttons.search -width 20 -relief sunken -borderwidth 2 \
-textvariable searchString -exportselection yes \
-font $Cour12 -highlightthickness 1 \
-background gray90
button .pane.upper.buttons.padb1 -state disabled -relief flat \
-highlightthickness 0 \
-borderwidth 0 -padx 15 -pady 0
button .pane.upper.buttons.padb2 -state disabled -relief flat \
-highlightthickness 0 \
-borderwidth 0 -padx 15 -pady 0
button .pane.upper.buttons.execute -text "execute <sel.>" -command {
set sel [selection get]
if {$sel != ""} {
xmlExecute $sel
}
} -pady 2
button .pane.upper.buttons.clearoutput -text clearoutput -command {
.pane.output.text delete 0.0 en
foreach doc [info commands domDoc*] {
$doc delete
}
} -pady 2
pack .pane.upper.buttons.searchL \
.pane.upper.buttons.search \
.pane.upper.buttons.padb1 \
.pane.upper.buttons.execute \
.pane.upper.buttons.padb2 \
.pane.upper.buttons.clearoutput -side left
pack .pane.upper.buttons -anchor w
pack .pane.upper.input -side top -fill both -expand yes
pack .pane.upper.buttons -side bottom -fill x -expand no
pack .pane.upper -fill both -expand yes
pack .menu -fill x -side top -expand no
pack .pane -side top -fill both -expand yes
pane_place .pane vertical 0.25 .pane.upper .pane.output
bind_emacstext Text
menu .pane.output.m -tearoff 0
.pane.output.m add command -label " goto parent " -command GotoParent
.pane.output.m add command -label " asXML " -command "As asXML"
.pane.output.m add command -label " asHTML " -command "As asHTML"
.pane.output.m add command -label " toXPath " -command ToXPath
bind .pane.output.text <3> {
.pane.output.text configure -cursor left_ptr
set PointerXY @%x,%y
eval tk_popup .pane.output.m [winfo pointerxy %W]
}
#--------------------------------------------------------------------
# search feature
#--------------------------------------------------------------------
set origSearchWin .pane.upper.input.text
.pane.output.text tag configure search -background white -foreground black
.pane.upper.input.text tag configure search -background white -foreground black
bind Text <Control-s> {
global origSearchWin
set origSearchWin %W
focus .pane.upper.buttons.search
}
bind .pane.upper.buttons.search <Control-s> {
set len [string length $searchString]
.pane.upper.input.text tag remove search 0.0 end
.pane.output.text tag remove search 0.0 end
set curinsert [$origSearchWin index insert]
set spos [$origSearchWin search -regexp $searchString insert]
if {$spos != ""} {
if {[$origSearchWin compare $curinsert == $spos]} {
$origSearchWin mark set insert {insert +1char}
}
set spos [$origSearchWin search -regexp $searchString insert]
if {$spos != ""} {
$origSearchWin mark set insert $spos
$origSearchWin see insert
$origSearchWin tag add search insert "insert + $len char"
}
}
break
}
#--------------------------------------------------------------------
# load the xe save file into the input window
#
#--------------------------------------------------------------------
if {[catch { set f [open $xe_save r ] }] == 0} {
.pane.upper.input.text delete 1.0 end
while { [gets $f i] >= 0 } {
.pane.upper.input.text insert end $i
.pane.upper.input.text insert end "\n"
}
close $f
}
IntroWindow
# button .startedit -text " Edit plain XML " -font $Helv12 -command xmlEdit
# button .dump -text " dump " -font $Helv12 -command {puts stderr [info commands xmlelem*]}
# pack .xml -fill both -expand yes
# pack .dump .startedit -anchor e
# set fd [open [lindex $argv 0]]
# set xml [read $fd]
# close $fd
# xmlWidgetLoad .pane.output.text $xml
#----------------------------------------------------------------------------
# end of main part
#----------------------------------------------------------------------------
|