o_hypertext.anubis 114 KB
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

   
   
                             The Anubis/Paradize Project.
   
                                 The hypertext widget. 
   
                  Copyright (c) Constructive Mathematics S.A.R.L 2004. 

   
   Authors:   Alain Proutรฉ
              Olivier Duvernois


   
   
 read widgets3/widget.anubis
 read widgets3/tools.anubis   
read widget.anubis
read tools.anubis   

 read /home/olivier/anubis_dev/library/tools/basis.anubis
read tools/basis.anubis
read image.anubis
   
   
   This file defines the 'hypertext' widget.  This widget displays a text from a 'String',
   interpreting a few  'control characters'.  The text may contain  widgets inserted in it
   (hence the  name 'hypertext'). You  can choose the  size of the  font and the  color of
   characters.  The text is supposed to be  fixed, hence no variable is given for creating
   an hypertext widget.  Some special visual effects may be achieved:
   
public type WidgetTextEffect:
   
   // no effect
   normal   (RGB color),             // color of text
   
   // shadow effect (of course, the shadow is under the text)
   shadow   (RGB main_color,         // color of text
             RGB shadow_color,       // color for shadow of text
             Int32 dx, Int32 dy),    // position of shadow relative to text
   
   // engraving effect
   engraved (RGB color),             // the text seems to be engraved into the background,
                                     // if 'color' is the color of the background
   
   // relief effect
   relief   (RGB color).             // color is the color of the background
   
   
   The text is displayed on several lines if necessary. You must give the maximal width of
   the text. If the  text is wider than this width, new lines  are created.  You must also
   provide the size  (in pixels) of the margin  all around the text. You  can also control
   the  minimal  number of  pixels  between consecutive  lines  (vertical  spacing). If  a
   background color is  provided, the text is presented over a  uniform background of this
   color.  Otherwise, no background is displayed, and the parent widget is visible between
   the characters.
   
   Consider  the  maximal  width  you  provide  as an  indication  and  not  a  definitive
   argument. Actually, this width could be  automatically enlarge if the width of a widget
   or the size of  word (a word is here a string whitout any  spaces) is greater than your
   width parameter.

   
   The content of  the hypertext is a mix  of strings and widgets.  Strings  are under the
   rules     defined     for      then     function     'split_string_into_lines()'     in
   widgets3/tools.anubis. Each widget goes with a integer to indicate the number of pixels
   the bottom of the inserted widget is placed  relative to the base line of the text. 
   
   The content of hypertext  is a series of strings, links and  widgets. Strings and links
   are  under   the  rules  exposed   for  the  function   'split_string_into_lines()'  in
   widgets3/tools.anubis.  The hypertext link will have the same behaviour than the string
   : it will  be cut at the  end of the line to  continue on the next;  as describe above,
   links and strings cannot enlarge the  hypertext.  But if you definitevely want a no-cut
   link, construct it  through the widget 'button' : widgets can  enlarge the hypertext if
   necesary.  Widgets are called in two  hypertexts : posw (for 'positioning widget') and
   floatingw (for 'floating widget').  The posw goes with a integer to indicate the number
   of pixels the bottom of the inserted widget  is placed relative to the base line of the
   text.  With the floatingw,  the other hypertext of the same line  will occupied all the
   height of the floatingw. For example, a  string will be written over as many lines it's
   possible. The floatingw needs a position relative to the line (left or right).
   
   The visual aspect of posw and floatingw, follows by a string will be something like :
   
          +---- Window -----------------------------------------+
          |                                                     |
          |                                                     | 
          | +- posw --------+                                   |
          | |               |                                   |
          | |               | Eleonor of Aquitaine (1124,1204)  | 
          | |               |                                   | 
          | |               |                                   |  
          | +---------------+                                   |
          |                                                     | 
          | +- floatingw ---+ is probably the most well-known   |
          | |               | queen of the Middle-Ages. No doubt| 
          | |               | certain exceptionnal aspects of   |
          | |               | her life explain this notoriety : |
          | +---------------+ two mariages to the Kings of      |
          | France and England; ...                             |
          |                                                     |
          +-----------------------------------------------------+
      
   
   
   
   
public type PosWidget:
   left_pw  (Int32        v_pos,        // vertical_position,
              Int32       spacer,        // spacer between the widget and the text against it
              Widget         wid),
   right_pw (Int32        v_pos,         //vertical_position,
              Int32       spacer,        // spacer between the widget and the text against it
              Widget         wid).
   
public type FloatingWidget:
   left_fw  (Int32     spacer,        // spacer between the widget and the text against it
             Widget       wid), 
   right_fw (Int32     spacer,        // spacer between the widget and the text against it
             Widget       wid).
   
public type LinkWidget:
   link(String                          txt,
        WidgetEventToolBox -> One     action).      // action performed by the link

   
public type HyperTextContent:
   empty,
   string     (String,          HyperTextContent), 
   linkw      (LinkWidget,      HyperTextContent), 
   posw       (PosWidget,       HyperTextContent), 
   floatingw  (FloatingWidget,  HyperTextContent).
   
   For making your hypertext, just use the '+' sign between two contents. For example, you
   may write :
   
   "This " + "photograph " + pos(-12,create_image("flowers.jpg")) + " was taken in Paris.".
   

   Note 1 : caracter '&' is reserved. To have a '&' in your text, type '\&'. 
   Note 2  : spaces  begening or ending  a text  and repeated spaces  are remove.  To have
   surely a space, type '\ '. 
   
   
   
   
   
  
public define HyperTextContent
   String s + HyperTextContent h
     =
   string(s,h). 
   
public define HyperTextContent
   String s1 + String s2
     =
   string(s1,string(s2,empty)). 
   
public define HyperTextContent
   String s + LinkWidget l
    =
   string(s,linkw(l,empty)).
   
public define HyperTextContent
   String s + PosWidget w
     =
   string(s,posw(w,empty)). 
   
public define HyperTextContent
   String s + FloatingWidget f
     =
   string(s,floatingw(f,empty)).

public define HyperTextContent
   LinkWidget l + HyperTextContent h
    =
   linkw(l,h).
   
public define HyperTextContent
   LinkWidget l + String s
    =
   linkw(l,string(s,empty)).
   
public define HyperTextContent
   LinkWidget l1 + LinkWidget l2
    =
   linkw(l1,linkw(l2,empty)).
   
public define HyperTextContent
   LinkWidget l + PosWidget w
    =
   linkw(l,posw(w,empty)).
   
public define HyperTextContent
   LinkWidget l + FloatingWidget f
    =
   linkw(l,floatingw(f,empty)).
   
public define HyperTextContent
   PosWidget w + HyperTextContent h
     =
   posw(w,h). 
   
public define HyperTextContent
   PosWidget w1 + PosWidget w2
     =
   posw(w1,posw(w2,empty)). 
   
public define HyperTextContent
   PosWidget w + String s
     =
   posw(w,string(s,empty)). 

public define HyperTextContent
   PosWidget w + LinkWidget l
    =
   posw(w,linkw(l,empty)).
   
public define HyperTextContent
   PosWidget w + FloatingWidget f
    =
   posw(w,floatingw(f,empty)).
   
public define HyperTextContent
   FloatingWidget f + HyperTextContent h
     =
   floatingw(f,h).
   
public define HyperTextContent
   FloatingWidget f1 + FloatingWidget f2
    =
   floatingw(f1,floatingw(f2,empty)).
   
public define HyperTextContent
   FloatingWidget f + String s
    =
   floatingw(f,string(s,empty)).
   
public define HyperTextContent
   FloatingWidget f + LinkWidget l
    =
   floatingw(f,linkw(l,empty)).
   
public define HyperTextContent
   FloatingWidget f + PosWidget w
    =
   floatingw(f,posw(w,empty)).
   
public define HyperTextContent
   HyperTextContent h + String s
     =
   string(s,h). 

public define HyperTextContent
   HyperTextContent h + LinkWidget l
    =
   linkw(l,h).
   
public define HyperTextContent
   HyperTextContent h + PosWidget w
     =
   posw(w,h). 
   
public define HyperTextContent
   HyperTextContent h + FloatingWidget f
     =
   floatingw(f,h).
   

   
   
   You may also  want to center or justify the  text either on the left,  on the right, or
   both. The 'justify' attribute is of type:
   
public type WidgetTextJustify:   
   center,          //       |           centered text           |
   left,            //       | left justified text               |
   right,           //       |              right justified text |
   both.            //       | text  justified   on  both  sides |
   
   
   Now,  here  is the  hypertext  creation function.   We  also  provide some  convenience
   functions, but  you should  create convenience functions  of your  own if you  use many
   hypertext widgets in your project.
   
public define Widget
   create_hypertext
     (
       SystemFont                  font,      // 
       WidgetTextEffect          effect,      // (see above)
       Maybe(RGB)            background,      // non mandatory background
       Int32                      width,      // maximal width of text
       Int32                     margin,      // margin for 4 sides
       Int32           vertical_spacing,      // number of pixels between lines
       Int32                     indent,      // number of pixels before beginning of paragraphs
       WidgetTextJustify        justify,      // how to justify the text
       HyperTextContent         content,
       Maybe(RGB)            link_color       // failure if there is no links in hypertext
     ). 

   Note : if (WidgetTextJustify)center is choosen, the indentation will be not applied.

   Convenience functions:
   
   (1) Creating a simple  text with no effect  and no widget inserted. 'margin'  is set to
   10, 'glue' to 1, 'vertical_spacing' to 3, and 'justify' to left.
   
public define Widget   
   create_text
     (
       SystemFont         font,
       RGB               color,
       Int32             width,
       String             text
     ) =
   create_hypertext(font,
                    normal(color),
                    failure, 
                    width,
                    10, 
                    1,
                    3,
                    left,
                    text+empty,
                    failure).
   
   
   
   (2) Creating a header.

public define Widget
   create_header
     (
       SystemFont            font,
       WidgetTextEffect    effect,      // (see above)
       Int32                width,
       String                text       // the text itself
    ) = create_hypertext(font,
                         effect,
                         failure,
                         width,
                         10, 
                         3,
                         0,
                         center,
                         text+empty,
                         failure).
   
   
   
   
   
   --- That's all for the public part ! --------------------------------------------------

   
   *** (1) HyperTextParameters
   ***************************
   
   In order to get all parameters in an unique variable.

type HyperTextParameters:
   ht_parms
     (
      SystemFont                        font,
      Int32                      font_height,
      Int32                       font_depth,
      Int32                total_font_height,
      Int32                           margin,
      Int32                          v_space,
      Int32                           indent,
      WidgetTextEffect                effect,
      WidgetTextJustify              justify,
      String -> Int32           string_width,
      RGB                         link_color
     ).
   
   
   *** (2) Tools
   *************
   
      *** (2.1) Extracting words from a string 
      ****************************************
   
define List(String)
   extract_words
     (
       String          text,
       Int32              n,
       String          word,
       List(String)  so_far
     ) =
   if nth(n,text) is 
     {
       failure    then [word . so_far],
       success(c) then 
        if c = ' '
          then extract_words(text,n+1,"",[word . so_far])
          else extract_words(text,n+1,word+implode([c]),so_far)
     }.
   
   
define List(String)
   extract_words
     (
       String  text
     ) =
   extract_words(text,0,"",[]).
   
   
   
      *** (2.2) Text color
      ********************
   
define RGB
  text_color
    (
      WidgetTextEffect  effect
    ) =
   if effect is 
     {
       normal(c)       then c,
       shadow(c,_,_,_) then c,
       engraved(c)     then c,
       relief(c)       then c
     }.
   

   
define One
   print_ls
     (
       List(String) ls
     ) =
   if ls is 
     {
       []      then unique,
       [h . t] then print("["+h+"]\n");print_ls(t)
     }.
   
   
   *** (3) Width of the content of the hypertext
   *********************************************
   
   To construct the hypertext a max width  is required. But this number could be higher if
   the width of a sub-widget is greater. So the real width must be computed.
   

   
define Int32
   compute_width
     (
       Int32                    width,     // initialise by the given number
       HyperTextContent       content,
       String -> Int32   string_width
     ) =
   if content is 
     {
       empty              then width,
       string(s,htc)      then 
         compute_width
              (greatest(map((String s) |-> string_width(s),extract_words(s)),width),
               htc,string_width),
       linkw(lw,htc)      then compute_width(width,htc,string_width),
       posw(pw,htc)       then
          if get_size(wid(pw))(unique) is (w,h) then compute_width(max(w,width),htc,string_width),
       floatingw(fw,htc)  then 
          if get_size(wid(fw))(unique) is (w,h) then compute_width(max(w,width),htc,string_width)
     }.
  
   
   
   *** (4) Block
   *************
   
   
      *** (4.1) Definition
      ********************
   
   To  print the hypertext,  its content  will be  transform into  'blocks'. Two  kinds of
   block are defined according to the content : 
     .1: block with only text all along the width of the hypertext;
     .2: block with a widget and text against it (text may be empty)
   
   
      +---------- Hypertext ---------------------------+
      |                                                |
      | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |---- 
      | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |   3 lines of text for a block of type 1
      | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |----
      | ********************** ~~~~~~~~~~~~~~~~~~~~~~~ |----
      | *                    * ~~~~~~~~~~~~~~~~~~~~~~~ |   A (floating) widget with some lines
      | *                    * ~~~~~~~~~~~~~~~~~~~~~~~ |   against it : this set is a block of
      | *   widget           * ~~~~~~~~~~~~~~~~~~~~~~~ |   type 2.
      | *                    * ~~~~~~~~~~~~~~~~~~~~~~~ |
      | *                    * ~~~~~~~~~~~~~~~~~~~~~~~ |
      | *                    * ~~~~~~~~~~~~~~~~~~~~~~~ |
      | ********************** ~~~~~~~~~~~~~~~~~~~~~~~ |
      | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
      | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |----
      | ********************************************** |----
      | *                                            * |  The widget covers the all width of the
      | *                                            * |  hypertext : it's a block of type 2
      | ********************************************** |----
      |                                                |
      +------------------------------------------------+
   
   
   Note : a block could contain only one widget.

   
   
   
   The text contained  in a block are paragraphs. Those paragraphs  are transformed into a
   List(BlockLine)  to  distinguish   the  different  kind  of  lines   that  exist  in  a
   paragraph. And for each one, the  indent and both justify (if required) parameters will
   be different.
   
   Those kinds of lines are (names of BlockLine alternatives): 
   
      +--------+------------------------------------------------+--------+-------------------+
      |  name  |                  Definition                    | indent |      justify      |
      +--------+------------------------------------------------+--------+-------------------+
      | first  | first line of paragraph                        |   yes  |       yes         |
      +--------+------------------------------------------------+--------+-------------------+
      | middle | middle line of paragraph                       |   no   |       yes         |
      +--------+------------------------------------------------+--------+-------------------+
      | last   | last line of paragraph                         |   no   | no, even required |
      +--------+------------------------------------------------+--------+-------------------+
      | flast  | only line of a paragraph : both first and last |   yes  | no, even required |
      +--------+------------------------------------------------+--------+-------------------+
   
      
   
   There is an  exception : the text  against a position_widget will be not indented and not
   justified. We take on this arbitrary choice !
   
   
   
   So, here is the type 'Block' : 

type BlockContent:
   empty,
   text    (String,                       // words,
            BlockContent),
   link    (String,                       // words,
            WidgetEventToolBox -> One,    // action,
            Int32,                        // index
            BlockContent).
   
   
define BlockContent
   BlockContent bc1 + BlockContent bc2 = 
    if bc1 is 
      {
        empty           then bc2,
        text(w,bc)      then text(w,bc+bc2),
        link(w,a,i,bc)  then link(w,a,i,bc+bc2)
      }.
      
 
type BlockLine:
   first   (BlockContent  cont),
   middle  (BlockContent  cont),
   last    (BlockContent  cont),
   flast   (BlockContent  cont).
   
   
type LR_Widget:
   left,
   right.
   
   
type Block:
   t_block  (List(BlockLine)),
   wt_block (List(BlockLine),
             LR_Widget,
             Int32,          // vertical position 
             Int32,          // spacer between the widget and the text agains it
             Widget).
   
   
  
   The alternative 'wt_block', which is for blocks containing widget, contains, as well as
   the widget itself, three other parameters :
     . LR_Widget to place the widget to the left or to the right of the hypertext
     . an Int32 for the vertical position of  the text from the top of the widget; this is
       only for a position widget, the value is 0 for an floating-widget.
     . an Int32 for spacing the widget to the text against it
   
   
   
      *** (4.2) HyperTextContent -> List(Blocks)
      ******************************************
   
define String
   concat_bcont
     (
       BlockContent  bc
     ) =
   if bc is 
     {
       empty          then "",
       text(s,b)      then s+concat_bcont(b),
       link(s,a,i,b)  then s+concat_bcont(b),
     }.
   
define String
   print_bl
     (
       List(BlockLine) lbl
     ) =
   if lbl is 
     {
      []      then "",
      [h . t] then concat_bcont(cont(h))+"|"+print_bl(t)
     }.
   
         *** (4.2.1) Transform the text to List(BlockLine)
         *************************************************

   
   'StringParagraph'  is used to  store the  text, whithout  any transformation,  when the
   HyperTextContent is reading to become blocks (function 'to_blocks'). The text come from
   the  content itself,  and from  the part  of the  text not  used when  block  are build
   (example : unused text after a position widget).
   
   So, StringParagraph has two  alternatives to know if the text in  it begins a paragraph
   or if it's just the same a before.
  
   
type StringParagraph:
   new_paragraph (String       text),
   to_continue   (String       text),
   new_paragraph (LinkWidget   lwid,
                  Int32       index),
   to_continue   (LinkWidget   lwid,
                  Int32       index).
   
   
define List(StringParagraph)
   add
     (
       List(StringParagraph)  lsp,
       String                   s
     ) =
   if lsp is 
     {
       []      then [new_paragraph(s)],
       [h . t] then 
         if h is 
           {
   /*
             new_paragraph(p)     then print("h=npt"+s+"\n");[new_paragraph(p+s) . t],
             to_continue(p)       then print("h=tct"+s+"\n");[to_continue(p+s) . t],
             new_paragraph(_,_)   then print("h=npl"+s+"\n");[to_continue(s) . lsp],
             to_continue(_,_)     then print("h=tcl"+s+"\n");[to_continue(s) . lsp]
   */
             new_paragraph(p)     then [new_paragraph(p+s) . t],
             to_continue(p)       then [to_continue(p+s) . t],
             new_paragraph(_,_)   then [to_continue(s) . lsp],
             to_continue(_,_)     then [to_continue(s) . lsp]
           }
     }.
  
define List(StringParagraph)
   add
     (
       List(StringParagraph)  lsp,
       LinkWidget             lw,
       Int32                  i
     ) =
   if lsp is 
     {
       []      then [new_paragraph(lw,i)],
       [h . t] then [to_continue(lw,i) . lsp]
     }.
   
   
   
            *** (4.2.1.1) From text only
            ****************************
   
   This function is used to transform a text into a List(BlockLine) when it comes from the
   HyperTextContent alternative 'string'. The result will be List(BlockLine) of type 1.
   

   
   Several steps for transforming a text to a List(String) for a block.
   
   First, the text is split into lines according to what it is required by the source (see
   tools.anubis for this transformation). This operatation gives a List(String) where each
   string is a paragraph.
   
   Then each string (or paragraph) are cut  to a List(BlockLine) according to the width of
   the hypertext, less the indentation for the first one.
   
   
   
define (List(BlockLine),BlockContent,String -> Bool)
   transforming_text
     ( 
       String                                       line,
       BlockContent                                   bc,
       Int32                                           i,
       String -> Bool                     is_too_large_c,
       String -> Bool                       is_too_large,
       (BlockContent,String) -> BlockLine       to_bline,  // the active function
       String                                       word,
       String                                 words_line,
       (BlockContent,String) -> BlockLine      to_middle,
       String -> BlockContent                   to_bcont,
       List(BlockLine)                            so_far
     ) = //print("bc=["+concat_bcont(bc)+"]\n");
   if nth(i,line) is 
     { 
       failure   then
         with new_words_line = (String)(words_line+" "+word),
              bc_and_line = (String)(concat_bcont(bc)+new_words_line),
         if is_too_large_c(bc_and_line)
           then //print("bal=["+bc_and_line+"]\n");
                //print("bc=["+concat_bcont(bc)+"]\n");
                //print("wl=["+words_line+"]\n");
   /*
                if bc is 
                  {
                    empty     then print("EMPTY \n"),
                    text(_,_) then print("TEXT \n"),
                    link(_,_,_,_,_) then print("LINK \n")
                  };
                if to_bcont(words_line) is 
                  {
                    empty     then print("EMPTY \n"),
                    text(_,_) then print("TEXT \n"),
                    link(_,_,_,_,_) then print("LINK \n")
                  };
   */
                //([to_middle(bc,words_line) . so_far],last_bc(word))
                ([middle(bc+to_bcont(words_line)) . so_far],to_bcont(word),is_too_large_c)
           //else (so_far,last_bc(new_words_line))
           else (so_far,to_bcont(bc_and_line),is_too_large_c)
       success(c) then
         if c = ' '
           then // the test on 'words_line' is to avoid a space as first character to begin
                // the all text to print
                with new_words_line = (String)(words_line+(if words_line = "" then "" else " ")+word),
                //with new_words_line = (String)(words_line+word),
                if is_too_large_c(new_words_line+concat_bcont(bc))
                  then //print("too_large = ["+new_words_line+concat_bcont(bc)+"]\n");
                       //print("nwl=["+new_words_line+"]\n");
                       //print("wl=["+words_line+"]\n");
                       //print("bc=["+concat_bcont(bc)+"]\n");
                       //print("lbl=["+print_bl([to_bline(bc,words_line)])+"]\n");
                        transforming_text(line,empty,i+1,is_too_large,is_too_large,to_middle,
                                         word+" ","",to_middle,to_bcont,
                                         [to_bline(bc,words_line) . so_far])
                  else //print("not_too_large = ["+new_words_line+concat_bcont(bc)+"]\n");
                       transforming_text(line,bc,i+1,is_too_large_c,is_too_large,to_bline,
                                         "",new_words_line,to_middle,to_bcont,so_far)
           else transforming_text(line,bc,i+1,is_too_large_c,is_too_large,to_bline,
                                  word+implode([c]),words_line,to_middle,to_bcont,so_far)
     }.
   
   
      
define (List(BlockLine),BlockContent,String -> Bool)
   transforming_text
     (
       List(String)                                 lines,    // 1 line = text_paragraph
       BlockContent                                     bc,
       String -> Bool                       is_too_large_i,
       String -> Bool                         is_too_large,
       (BlockContent,String) -> BlockLine         to_bline,  // initialized according to str_paragraph
       (BlockContent,String) -> BlockLine         to_flast,   //   .. same ..
       (BlockContent,String) -> BlockLine        to_middle,
       (BlockContent,String) -> BlockLine         to_first,
       (BlockContent,String) -> BlockLine          to_last,
       String -> BlockContent                     to_bcont,
       BlockContent -> BlockLine                  bc_to_bl,
       List(BlockLine)                              so_far  
     ) =
   if lines is 
     {
       []        then (so_far,bc,is_too_large_i),
       [h . t]   then //print("h=["+h+"]\n");
         with new_bc = to_bcont(h),
              add_bc = bc+new_bc,
         if is_too_large_i(concat_bcont(add_bc))
           then //print("ADD BC=["+concat_bcont(add_bc)+"]\n");
                (if transforming_text
                      (h,bc,0,is_too_large_i,is_too_large,to_bline,
                       if bc is empty then "" else " ","",
                       if t is [] then to_middle /*to_last*/else to_middle,to_bcont,[])
                    is (new_lbl,new_bc,current_test) then 
   
                 if t is [] 
                   then // in this case, it's ne
                       (new_lbl+so_far,new_bc,current_test)
                   else // in this case, bc will be add to lbl (h is a real paragraph)
                      transforming_text(t,empty,is_too_large_i,is_too_large,to_first,
                                        to_flast,to_middle,to_first,to_last,to_bcont,
                                        bc_to_bl,[bc_to_bl(new_bc) . new_lbl]+so_far))
   
           else if t is []
                 then (so_far,add_bc,is_too_large_i)
                 else transforming_text(t,empty,is_too_large_i,is_too_large,to_first,
                                        to_flast,to_middle,to_first,to_last,to_bcont,
                                        bc_to_bl,[to_flast(add_bc,"")]+so_far)
     }.

           else transforming_text(t,empty,is_too_large_i,is_too_large,to_first,
                                        to_flast,to_middle,to_first,to_last,to_bcont,
                                        bc_to_bl,[to_flast(add_bc,"")]+so_far)
           else transforming_text(t,add_bc,is_too_large_i,is_too_large,to_first,
                                        to_flast,to_middle,to_first,to_last,to_bcont,
                                        bc_to_bl,so_far)
   
   
      
define Bool
   is_next_continue
     (
       List(StringParagraph) l
     ) =
   if l is 
     {
       []      then false,
       [h . _] then true
     }.
         if h is 
           {
             new_paragraph(txt)  then false,
             to_continue(txt)    then true,
             new_paragraph(lk,i) then false,
             to_continue(lk,i)   then true,
           }
     
   

   
define (List(BlockLine),String -> Bool)
   transforming_text
     (
       List(StringParagraph)      lstr_pgraph,
       String -> Bool          is_too_large_i,    // for the first line (with indent)
       String -> Bool            is_too_large,
       BlockContent                    b_cont,
       List(BlockLine)             so_far_lbl,
       String -> Bool          last_used_test
     ) =
   if lstr_pgraph is 
     {
       []      then
         (if b_cont is 
            {
              empty          then [],
              text(s,bc)     then append(so_far_lbl,[last(text(s,empty))]),
              link(s,a,i,bc) then append(so_far_lbl,[last(link(s,a,i,empty))])
            },last_used_test),
       [h . t] then
         if h is 
          {
            new_paragraph(txt)  then //print("NP_t ["+txt+"]\n");
   //print("NP_t/bcont=["+concat_bcont(b_cont)+"]\n");
              if transforming_text
                   (split_string_into_lines(txt),b_cont,is_too_large_i,is_too_large,
                    (BlockContent bc,String s) |-> first(bc+text(s,empty)),
                    (BlockContent bc,String s) |-> flast(bc+text(s,empty)),
                    (BlockContent bc,String s) |-> middle(bc+text(s,empty)),
                    (BlockContent bc,String s) |-> first(bc+text(s,empty)),
                    (BlockContent bc,String s) |-> last(bc+text(s,empty)),
                    (String s) |-> text(s,empty),
                    (BlockContent bc) |-> last(bc),
                    (List(BlockLine))[]) is (new_lbl,new_bc,last_test) then 
   //print("NP_t/new_bc=["+concat_bcont(new_bc)+"]\n");
   //           append(reverse(new_lbl),
   //                  transforming_text(t,is_too_large_i,is_too_large,new_bc,last_test)),
             transforming_text(t,is_too_large_i,is_too_large,new_bc,
                               append(so_far_lbl,reverse(new_lbl)),last_test),
   
            to_continue(txt)    then //print("TC_t ["+txt+"]\n");
   //print("TT=");print_ls(split_string_into_lines(txt));print("\n");
   //print("TC_t/bcont=["+concat_bcont(b_cont)+"]\n");
              if transforming_text
                   (split_string_into_lines(txt),b_cont,is_too_large,is_too_large,
                    (BlockContent bc,String s) |-> middle(bc+text(s,empty)),
                    (BlockContent bc,String s) |-> flast(bc+text(s,empty)),
                    (BlockContent bc,String s) |-> middle(bc+text(s,empty)),
                    (BlockContent bc,String s) |-> first(bc+text(s,empty)),
                    (BlockContent bc,String s) |-> last(bc+text(s,empty)),
                    (String s) |-> text(s,empty),
                    (BlockContent bc) |-> middle(bc),
                    (List(BlockLine))[]) is (new_lbl,new_bc,last_test) then 
   //print("TC_t/new_bc=["+concat_bcont(new_bc)+"]\n");
   //           append(reverse(new_lbl),
   //                  transforming_text(t,is_too_large_i,is_too_large,new_bc,last_test)),
             transforming_text(t,is_too_large_i,is_too_large,new_bc,
                               append(so_far_lbl,reverse(new_lbl)),last_test),
   
            new_paragraph(lk,i) then print("NP_l ["+txt(lk)+"]\n");
              if transforming_text
                   (split_string_into_lines(txt(lk)),b_cont,is_too_large_i,is_too_large,
                    (BlockContent bc,String s) |-> first(bc+link(s,action(lk),i,empty)),
                    (BlockContent bc,String s) |-> flast(bc+link(s,action(lk),i,empty)),
                    (BlockContent bc,String s) |-> middle(bc+link(s,action(lk),i,empty)),
                    (BlockContent bc,String s) |-> first(bc+link(s,action(lk),i,empty)),
                    (BlockContent bc,String s) |-> last(bc+link(s,action(lk),i,empty)),
                    (String s) |-> link(s,action(lk),i,empty),
                    (BlockContent bc) |-> middle(bc),
                    (List(BlockLine))[]) is (new_lbl,new_bc,last_test) then 
   //print("NP_l/new_bc=["+concat_bcont(new_bc)+"]\n");
   //           append(reverse(new_lbl),
   //                  transforming_text(t,is_too_large_i,is_too_large,new_bc,last_test)),
             transforming_text(t,is_too_large_i,is_too_large,new_bc,
                               append(so_far_lbl,reverse(new_lbl)),last_test),
   
            to_continue(lk,i)   then //print("TC_l ["+txt(lk)+"]\n"); print("lt="+length(t)+"\n");
   //print("TC_l/bcont=["+concat_bcont(b_cont)+"]\n");
              if transforming_text
                   (split_string_into_lines(txt(lk)),b_cont,is_too_large,is_too_large,
                    (BlockContent bc,String s) |-> middle(bc+link(s,action(lk),i,empty)),
                    (BlockContent bc,String s) |-> flast(bc+link(s,action(lk),i,empty)),
                    (BlockContent bc,String s) |-> middle(bc+link(s,action(lk),i,empty)),
                    (BlockContent bc,String s) |-> first(bc+link(s,action(lk),i,empty)),
                    (BlockContent bc,String s) |-> last(bc+link(s,action(lk),i,empty)),
                    (String s) |-> link(s,action(lk),i,empty),
                    (BlockContent bc) |-> middle(bc),
                    (List(BlockLine))[]) is (new_lbl,new_bc,last_test) then 
   //print("TC_l/new_bc=["+concat_bcont(new_bc)+"]\n");
   //           append(reverse(new_lbl),
   //                  transforming_text(t,is_too_large_i,is_too_large,new_bc,last_test)),
             transforming_text(t,is_too_large_i,is_too_large,new_bc,
                               append(so_far_lbl,reverse(new_lbl)),last_test),
           }
     }.
   
   
define List(BlockLine)
   transforming_text
     (
       List(StringParagraph)      lstr_pgraph,
       String -> Bool          is_too_large_i,    // for the first line (with indent)
       String -> Bool            is_too_large
     ) =
   if transforming_text(lstr_pgraph,is_too_large_i,is_too_large,empty,[],is_too_large_i)
    is (lbl,_) then lbl.
   
   
   transforming_text(lstr_pgraph,is_too_large_i,is_too_large,empty).   
   transforming_text(lstr_pgraph,is_too_large_i,is_too_large,is_next_continue(lstr_pgraph),1).   
   
   
   
   
            *** (4.2.1.2) From text before a floating-widget
            ************************************************
   
   

   The string-line  of text  before a floating-widget  must be  as larger as  possible. To
   reached this, it could be necessary to  make up this line with the text containing into
   the floating-widget.
   
   First,  the  text given  by  the  hypertext-content  preceding the  floating-widget  is
   transform into a List(BlockLine).
   
   Then, the  last BlockLine is  maked up  to obtain a  full string-line according  to the
   available width,  the unused text will  be transformed elsewhere to  take place against
   the widget.

   Note  : the  first tranformation  returns the  last test  on the  width (is_too_large)
   because for making-up the line it's necessary to know if is a line with indent or not.
   
   
define (String,String)
   make_up_the_line
     (
       List(Int8)              new_s,
       String                   word,
       String              add_words,
       String -> Bool   is_too_large
     ) =
   if new_s is 
     {
       []      then 
         with last_line = (String)(add_words+" "+word),
         if is_too_large(last_line)
           then (add_words,word)
           else (last_line,""),
       [c . t] then
         if c = ' '
           then with last_line = (String)(add_words+" "+word),
                if is_too_large(last_line) 
                  then (add_words,word+" "+implode(t))
                  else make_up_the_line(t,"",last_line,is_too_large)
           else make_up_the_line(t,word+implode([c]),add_words,is_too_large)
     }.
   
define (String,String)
   make_up_the_line
     (
       String                      new_s,
       String                for_make_up,
       String -> Bool       is_too_large
     ) =
    make_up_the_line(explode(new_s),"","",(String s) |-> is_too_large(for_make_up+s)). 
   

 define (BlockLine,HyperTextContent,Int32)
   transforming_text_before_fw
     (
       HyperTextContent               next_htc, // after the current floating-widget
       String -> Bool             is_too_large,
       BlockContent                         bc,
       BlockContent -> BlockLine         to_bl,
       Int32                             nb_lk
     ) =
   if next_htc is 
     {
       empty              then (to_bl(bc),empty,nb_lk),
       string(s,htc)      then 
         if make_up_the_line(s,concat_bcont(bc),is_too_large) 
            is (made_up,more_words) then
   //print("MW="+more_words+"\n");
         if more_words = ""
            then transforming_text_before_fw(htc,is_too_large,bc+text(made_up,empty),to_bl,nb_lk)
            else (to_bl(bc+text(made_up,empty)),string(more_words,htc),nb_lk)
       linkw(lw,htc)      then //(last(empty),linkw(lw,htc)),
         if make_up_the_line(txt(lw),concat_bcont(bc),is_too_large)
            is (made_up,more_words) then
         if more_words = ""
            then transforming_text_before_fw
                  (htc,is_too_large,bc+link(made_up,action(lw),nb_lk,empty),to_bl,nb_lk+1)
            else (to_bl(bc+link(made_up,action(lw),nb_lk,empty)),
                  linkw(link(more_words,action(lw)),htc),nb_lk),
       posw(pw,htc)       then (last(empty),posw(pw,htc),nb_lk),
       floatingw(fw,htc)  then (last(empty),floatingw(fw,htc),nb_lk)
     }.
   
   
define (BlockLine,HyperTextContent,StringParagraph,Int32)
   transforming_text_before_fw
     (
       HyperTextContent               next_htc, // after the current floating-widget
       String -> Bool             is_too_large,
       BlockContent                         bc,
       BlockContent -> BlockLine         to_bl,
       Int32                             nb_lk
     ) =
   if next_htc is 
     {
       empty              then (to_bl(bc),empty,new_paragraph(""),nb_lk),
       string(s,htc)      then 
         if make_up_the_line(s,concat_bcont(bc),is_too_large) 
            is (made_up,more_words) then
   //print("MW="+more_words+"\n");
         if more_words = ""
            then transforming_text_before_fw(htc,is_too_large,bc+text(made_up,empty),to_bl,nb_lk)
            else (to_bl(bc+text(made_up,empty)),htc,to_continue(more_words),nb_lk)
       linkw(lw,htc)      then //(last(empty),linkw(lw,htc)),
         if make_up_the_line(txt(lw),concat_bcont(bc),is_too_large)
            is (made_up,more_words) then
         if more_words = ""
            then transforming_text_before_fw
                  (htc,is_too_large,bc+link(made_up,action(lw),nb_lk,empty),to_bl,nb_lk+1)
            else (to_bl(bc+link(made_up,action(lw),nb_lk,empty)),
                  htc,to_continue(link(more_words,action(lw)),nb_lk),nb_lk),
       posw(pw,htc)       then (last(empty),posw(pw,htc),new_paragraph(""),nb_lk),
       floatingw(fw,htc)  then (last(empty),floatingw(fw,htc),new_paragraph(""),nb_lk)
     }.
   
   
   
   
define (List(BlockLine),HyperTextContent,List(StringParagraph),Int32)
   transforming_text_before_fw
     (
       List(BlockLine)        new_blines,  // reversed
       HyperTextContent         next_htc, // after the current floating-widget
       String -> Bool       is_too_large,
     ) = 
   if new_blines is
     {
       []         then ([],next_htc,[],0),
       [last . t] then 
         if last is 
           {
             first(bc)  then //print("FIRST\n");
               if transforming_text_before_fw(next_htc,is_too_large,bc,(BlockContent b) |-> first(b),0) 
                 is (bl,more_htc,sp,nb_lk) 
                   //then (reverse([bl . t]),more_htc,[to_continue("")],nb_lk),
                   then (reverse([bl . t]),more_htc,[sp],nb_lk),
             middle(bc) then //print("MIDDLE\n");
               if transforming_text_before_fw(next_htc,is_too_large,bc,(BlockContent b) |-> middle(b),0) 
                 is (bl,more_htc,sp,nb_lk) 
                   //then (reverse([bl . t]),more_htc,[to_continue("")],nb_lk),
                   then (reverse([bl . t]),more_htc,[sp],nb_lk),
             last(bc)    then //print("LAST\n"); //(reverse(new_blines),next_htc,[]),
               if transforming_text_before_fw(next_htc,is_too_large,bc,(BlockContent b) |-> middle(b),0) 
                 is (bl,more_htc,sp,nb_lk) 
                   //then (reverse([bl . t]),more_htc,[to_continue("")],nb_lk),
                   then (reverse([bl . t]),more_htc,[sp],nb_lk),
             flast(_)   then print("FLAST\n"); (reverse(new_blines),next_htc,[],0),
           }
     }.
   
   
define (List(BlockLine),HyperTextContent,List(StringParagraph),Int32)
   transforming_text_before_fw
     (
       List(StringParagraph)   lstr_pgraph,
       HyperTextContent           next_htc, // after the current floating-widget
       String -> Bool       is_too_large_i,
       String -> Bool         is_too_large
     ) =
   if ((List(BlockLine),String -> Bool))
      transforming_text(lstr_pgraph,is_too_large_i,is_too_large,empty,[],is_too_large_i) is 
        (new_blines,is_too_l) then 
   
   transforming_text_before_fw(reverse(new_blines),next_htc,is_too_l).
   
   
            *** (4.2.1.3) From a position-widget
            ************************************
   
   
   For a pos-widget, we want to obtain one line. The use-less text will be concatenate.
   
   As above, the first step is spliting  the string to paragraphs (lines). But we only are
   interested in by the first one. This  first one will be adjusted to the available width
   between the widget and  the hypertext border. The resul of this  operation is a pair of
   strings  : the  one  against  the widget,  the  unsed text.  This  unsed  text will  be
   concatenate with the unesed paragraphs, but separate by a '\t' to keep this unused text
   as paragraph.
   
   
   
  
define (String,String)
   posw_transforming_text
     (
       List(Int8)               line,
       String                 b_cont,
       Int32                       i,
       String -> Bool   is_too_large,
       String                   word,
       String             words_line,
     ) =
   if line is
     {
       []       then
         with new_words_line = (String)(words_line+" "+word),
         if is_too_large(new_words_line+b_cont)
           then (words_line,word)
           else (new_words_line,""),
       [c . t]  then
         if c = ' '
           then // the test on 'words_line' is to avoid a space as first character to begin
                // the all text to print
                with new_words_line = 
                    (String)(words_line+(if (words_line = "" & b_cont="") then "" else " ")+word),
                //with new_words_line = (String)(words_line+" "+word),
                if is_too_large(new_words_line+b_cont)
                  then (words_line,word+" "+implode(t))
                  else posw_transforming_text(t,b_cont,i+1,is_too_large,"",new_words_line)
           else posw_transforming_text(t,b_cont,i+1,is_too_large,word+implode([c]),words_line)
     }.
   
   
define (List(BlockLine),List(StringParagraph),BlockContent,Bool)
   posw_transforming_text
     (
       List(String)                      lines,
       BlockContent                         bc,
       String -> Bool             is_too_large,
       String -> BlockContent         to_bcont,
       String -> StringParagraph        to_new,
       String -> StringParagraph       to_cont,
     ) =
   if lines is
     {
       []               then ([],[],empty,true),
       [line1 . others] then
   //print("line1=["+line1+"]\n");
         with add_bc = bc+to_bcont(line1),
   //print("bc=["+concat_bcont(bc)+"]\n");
   //print("add_bc=["+concat_bcont(add_bc)+"]\n");
         if is_too_large(concat_bcont(add_bc))
           then
       (if posw_transforming_text(explode(line1),concat_bcont(bc),0,is_too_large,"","") 
          is (against_widget,more) then 
           with new_bc = bc+to_bcont(against_widget),
   //print("AW=["+against_widget+"] more=["+more+"]\n");
   //print("new_bc=["+concat_bcont(new_bc)+"]\n");
           ([last(new_bc)],
            [if more = "" // the line is to make up
              then to_new(concat(others))
              else to_cont(more+(if others is [] then "" else "\n"+concat(others)))],
            new_bc,
           true))
           else ([],[to_cont(concat(others))],add_bc,false)
   
     }.
   
define (List(BlockLine),List(StringParagraph))
   posw_transforming_text
     (
       List(StringParagraph)      lstr_pgraph,
       BlockContent                  build_bc,
       String -> Bool          is_too_large_i,
       String -> Bool            is_too_large,
       List(BlockLine)                 blines,
       List(StringParagraph)            spars
     ) = 
   if lstr_pgraph is 
     {
       []      then (blines,spars),
       [h . t] then 
        if h is 
          { 
           new_paragraph(txt)     then //print("NP_t ["+txt+"]\n");
             if posw_transforming_text
                  (split_string_into_lines(txt),build_bc,is_too_large,
                   (String s) |-> text(s,empty),
                   (String s) |-> new_paragraph(s),
                   (String s) |-> to_continue(s)) is (bl,sp,bc,is_over) then
   //print("NB_t/bc=["+concat_bcont(bc)+"]\n");
           if is_over
             then (blines+bl,spars+sp+t)
             else posw_transforming_text(t,bc,is_too_large_i,is_too_large,blines+bl,spars+sp),
           to_continue(txt)       then //print("TC_t ["+txt+"]\n");
             if posw_transforming_text
                  (split_string_into_lines(txt),build_bc,is_too_large,
                   (String s) |-> text(s,empty),
                   (String s) |-> new_paragraph(s),
                   (String s) |-> to_continue(s)) is (bl,sp,bc,is_over) then 
   //print("TC_t/bc=["+concat_bcont(bc)+"]\n");
           if is_over
             then (blines+bl,spars+sp+t)
             else posw_transforming_text(t,bc,is_too_large_i,is_too_large,blines+bl,spars+sp),
           new_paragraph(lk,i)  then //print("NP_l ["+txt(lk)+"]\n");
             if posw_transforming_text
                  (split_string_into_lines(txt(lk)),build_bc,is_too_large,
                   (String s) |-> link(s,action(lk),i,empty),
                   (String s) |-> new_paragraph(link(s,action(lk)),i),
                   (String s) |-> to_continue(link(s,action(lk)),i)) is (bl,sp,bc,is_over) then 
   //print("NB_l/bc=["+concat_bcont(bc)+"]\n");
           if is_over
             then (blines+bl,spars+sp+t)
             else posw_transforming_text(t,bc,is_too_large_i,is_too_large,blines+bl,spars+sp),
           to_continue(lk,i)    then //print("TC_l ["+txt(lk)+"]\n");
//   print("lt="+length(t)+"\n");
             if posw_transforming_text
                  (split_string_into_lines(txt(lk)),build_bc,is_too_large,
                   (String s) |-> link(s,action(lk),i,empty),
                   (String s) |-> new_paragraph(link(s,action(lk)),i),
                   (String s) |-> to_continue(link(s,action(lk)),i)) is (bl,sp,bc,is_over) then 
   //print("TC_l/bc=["+concat_bcont(bc)+"]\n");
           if is_over
             then (blines+bl,spars+sp+t)
             else posw_transforming_text(t,bc,is_too_large_i,is_too_large,blines+bl,spars+sp),
          }
     }.
   
   
   
            *** (4.2.1.4) From a floating-widget (against it)
            *************************************************

   
   Against a floating widget, the first line(s) of the text may be : 
      . just the continuation of a paragrapg begun before;
      . the begining of a new paragraph
   
   And the last line  of this text against the widget may the end  of a paragraph, or just
   the middle of one (not necessary the same as the beginning, of course).
   
   To format this text, the function 'floatw_transforming_text' needs :

     . the no-formating  initial text  (a List(String)  coming from  the floatingw-widget
        itself),
     . a test for the available width,
     . a test for the available height
     . a List(BlockParagraph) under-construction that will take place agains thne widget,
     . a counter for the number of line of text to text the height,
     . a  function to  transform the string-line  to a  ParagraphLine : the  initial value
       depends on the initial text received.  If  it is a continuation of a paragraph, the
       value is  'middle()', 'first()' either. Then,  after a first use  in the recursion,
       the value will be 'middle()'.
     . 2 functions to transform a List(ParagraphLine) into a BlockParagraph; as above, and
       for  the  same  reasons,  the  initialization  depends  on  the  the  initial  text
       received. The first fonction is called 'cur_bp' - 'cur' is for current - because in
       the  recursion  its value  will  move  to the  second  function  whic is  necessary
       'to_continue'.
   
   
 #define (Int32,String,String,List(BlockLine))
   transform_to_one_pgraph
     (
       List(Int8)                    one_pgraph,
       String -> Bool              is_too_large,
       Int32  -> Bool                  is_hight,
       String -> BlockLine             to_bline,
       Int32                            nb_line,
       String                              word,
       String                              line,
       List(BlockLine)                  against
     ) =
   if one_pgraph is
     {
       []     then (nb_line,word,line,against),
       [c . t] then  
         if c = ' '
           then with new_line = (String)(line+(if line = "" then "" else " ")+word),
                if is_too_large(new_line) 
                  then if is_hight(nb_line)
                        then // too large and enough hight :
                             //  -> stop the process
                             //  -> 'line' is transformed to BlockLine and added to the list
                             //  -> the rest of current text is added to word
                             if t is []
                                then (nb_line,word,"",[last(text(line,empty)) . against])
                                else (nb_line,word+" "+implode(t),"",[to_bline(line) . against])
                        else // too large but not enough hight : 
                             //  -> 'line' is transformed to ParagraphLine and added to the list
                             //  -> 'word' became the begining of the next 'line'
                             transform_to_one_pgraph
                               (t,is_too_large,is_hight,(String s) |-> middle(text(s,empty)),
                                nb_line+1,"",word,[to_bline(line) . against])
                  else // not too large 
                       //  -> no need to test the height 
                       //  -> the future line against the widget is under construction 
                       transform_to_one_pgraph
                               (t,is_too_large,is_hight,to_bline,nb_line,"",new_line,against)
           else transform_to_one_pgraph
               (t,is_too_large,is_hight,to_bline,nb_line,word+implode([c]),line,against)
     }.
   
   
   
   
define (Int32,String,String,List(BlockLine))
   transform_to_one_pgraph
     (
       List(Int8)                    one_pgraph,
       BlockContent                          bc,
       String -> Bool              is_too_large,
       Int32  -> Bool                  is_hight,
       (BlockContent,String) -> BlockLine             to_bline,
       Int32                            nb_line,
       String                              word,
       String                              line,
       List(BlockLine)                  against
     ) =
   if one_pgraph is
     {
       []     then (nb_line,word,line,against),
       [c . t] then  
         if c = ' '
           then with new_line = (String)(line+(if line = "" then "" else " ")+word),
                if is_too_large(new_line+concat_bcont(bc)) 
                  then if is_hight(nb_line)
                        then // too large and enough hight :
                             //  -> stop the process
                             //  -> 'line' is transformed to BlockLine and added to the list
                             //  -> the rest of current text is added to word
                             if t is []
                                then (nb_line,word,"",[last(bc+text(line,empty)) . against])
                                else (nb_line,word+" "+implode(t),"",[to_bline(bc,line) . against])
                        else // too large but not enough hight : 
                             //  -> 'line' is transformed to ParagraphLine and added to the list
                             //  -> 'word' became the begining of the next 'line'
                             transform_to_one_pgraph
                               (t,empty,is_too_large,is_hight,
                                (BlockContent bc,String s) |-> middle(bc+text(s,empty)),
                                nb_line+1,"",word,[to_bline(bc,line) . against])
                  else // not too large 
                       //  -> no need to test the height 
                       //  -> the future line against the widget is under construction 
                       transform_to_one_pgraph
                               (t,bc,is_too_large,is_hight,to_bline,nb_line,"",
                                (if line ="" then " " else "")+new_line,
                                against)
           else transform_to_one_pgraph
               (t,bc,is_too_large,is_hight,to_bline,nb_line,word+implode([c]),line,against)
     }.
   
   This  function is  called in  the  'to_blocks()' function  end used  when then  initial
   List(StringParagraph) is empty.
   
   The  BlockContent  came  from the  tranformation  to  make  up  the line  between  then
   float-widget. Hence, the recursive value is empty.
   
define (List(BlockLine),List(StringParagraph))
   floatw_transforming_text
     (
       BlockContent                     bc,
       String -> Bool         is_too_large,
       Int32 -> Bool              is_hight
     ) =
   if bc is 
     {
       empty         then ([],[]),
       text(w,_)     then 
         if transform_to_one_pgraph
           (explode(w),empty,is_too_large,is_hight,
            (BlockContent b,String s) |-> middle(bc+text(s,empty)),
            1,"","",[]) 
          is (new_nb_line,word,line,new_against) then 
             // (Int32) new_nb_line = line counter
             // (String) word = . text not treated,
             //                 . or part of text after the widget, if line is empty
             // (String) line = line under construction. Empty means available height is 
             //                 reached
             // (List(BlockLine)) new_against = will take place against the widget
          if line = ""
            then // end of the process
                 (reverse(new_against),[to_continue(word)])
            else with new_line = (String)(line+" "+word),
                 if is_too_large(new_line)
                   then if is_hight(new_nb_line)
                         then (reverse([middle(text(line,empty)) . new_against]),
                               [to_continue(word)])
                         else (reverse([middle(text(new_line,empty)) . new_against]),[])
                   else (reverse([middle(text(new_line,empty)) . new_against]),[]),
   
       link(w,a,i,_) then 
         if transform_to_one_pgraph
           (explode(w),empty,is_too_large,is_hight,
            (BlockContent b,String s) |-> middle(bc+link(s,a,i,empty)),
            1,"","",[])
          is (new_nb_line,word,line,new_against) then 
             // (Int32) new_nb_line = line counter
             // (String) word = . text not treated,
             //                 . or part of text after the widget, if line is empty
             // (String) line = line under construction. Empty means available height is 
             //                 reached
             // (List(BlockLine)) new_against = will take place against the widget
          if line = ""
            then // end of the process
                 (reverse(new_against),[to_continue(word)])
            else (reverse([middle(link(line,a,i,empty)) . new_against]),
                          [to_continue(word)])
     }.
   

 define (List(BlockLine),List(StringParagraph))
   floatw_transforming_text
     (
       List(String)                 pgraph, // list (real) text paragraphs
       BlockContent                     bc,
       String -> Bool       is_too_large_c,
       String -> Bool         is_too_large,
       Int32 -> Bool              is_hight,
       List(BlockLine)             against,
       Int32                       nb_line, // initialization = 1
       (BlockContent,String) -> BlockLine        to_bline,
       (BlockContent,String) -> BlockLine       to_middle,
       (BlockContent,String) -> BlockLine         to_last,
       String -> BlockContent                     to_bcont
     ) =
   if pgraph is
     {
       []      then 
         if floatw_transforming_text(bc,is_too_large_c,is_hight) 
           is (new_against,new_str_pgraph)
          then (reverse(append(new_against,against)),new_str_pgraph),
          //(reverse(against),[])
       [h . t] then //print("h="+h+"\n");
         with new_bc = to_bcont(h),
              add_bc = bc+new_bc,
//print("h=["+h+"]\n");
//print("add_bc=["+concat_bcont(add_bc)+"]\n");
         if is_too_large_c(concat_bcont(add_bc))
           then (if transform_to_one_pgraph 
                      (explode(h),bc,is_too_large_c,is_hight,to_bline,nb_line,"","",[]) 
                   is (new_nb_line,word,line,new_against) then 
                      // (Int32) new_nb_line = line counter
                      // (String) word = . text not treated,
                      //                 . or part of text after the widget, if line is empty
                      // (String) line = line under construction. Empty means available height is 
                      //                 reached
                      // (List(BlockLine)) new_against = will take place against the widget
//   print("line=["+line+"]\n");
//   print("word=["+word+"]\n");
                 if line = ""
                   then // end of the process
                        (reverse(append(new_against, against)),[to_continue(word)])
                   else // testing the result
                        with new_line = (String)(line+" "+word),
                       if is_too_large_c(new_line)
                         then if is_hight(new_nb_line)
                                then (against+reverse([to_middle(bc,line) . new_against]),
                                      [to_continue(word)])
                                else floatw_transforming_text
                                      ([word]+t,empty,is_too_large,is_too_large,is_hight,
                                       append([to_middle(bc,line) . new_against],against),
                                       new_nb_line+1,to_middle,to_middle,to_last,to_bcont)
   
                          else floatw_transforming_text
                                (t,empty,is_too_large,is_too_large,is_hight,
                                 [to_middle(bc,new_line) . new_against]+against,
                                  new_nb_line+1,to_middle,to_middle,to_last,to_bcont))
   
           else if is_hight(nb_line) 
                  then with new_bl = (BlockLine)if t is [] then to_last(bc,h) else to_middle(bc,h),
                       (reverse([new_bl . against]),[(StringParagraph)new_paragraph(concat(t))])
                  else floatw_transforming_text
                        (t,empty,is_too_large_c,is_too_large,is_hight,[to_bline(bc,h) . against],
                         nb_line+1,to_middle,to_middle,to_last,to_bcont)
           
   }. 
   
   
   

define (List(BlockLine),BlockContent,List(String))
   floatw_transforming_text
     (
       List(String)                                pgraph, 
       BlockContent                                    bc,
       String -> Bool                      is_too_large_c,
       String -> Bool                        is_too_large,
       Int32 -> Bool                             is_hight,
       List(BlockLine)                            against,
       Int32                                      nb_line, // initialization = 1
       (BlockContent,String) -> BlockLine        to_bline,
       (BlockContent,String) -> BlockLine       to_middle,
       (BlockContent,String) -> BlockLine         to_last,
       String -> BlockContent                    to_bcont,
       String -> BlockLine                         end_bl
     ) =
   if pgraph is
     {
       []      then (reverse(against),bc,[]),
       [h . t] then 
         with new_bc = to_bcont(h),
              add_bc = bc+new_bc,
         if is_too_large_c(concat_bcont(add_bc))
           then (if transform_to_one_pgraph 
                      (explode(h),bc,is_too_large_c,is_hight,to_bline,nb_line,"","",[]) 
                   is (new_nb_line,word,line,new_against) then 
                      // (Int32) new_nb_line = line counter
                      // (String) word = . text not treated,
                      //                 . or part of text after the widget, if line is empty
                      // (String) line = line under construction. Empty means available height is 
                      //                 reached
                      // (List(BlockLine)) new_against = will take place against the widget
                 if line = ""
                   then // end of the process
                        (reverse(append(new_against, against)),empty,[word])
                   else // testing the result
                        with new_line = (String)(line+" "+word),
                       if is_too_large_c(new_line)
                         then if is_hight(new_nb_line)
                                then (against+reverse([to_middle(bc,line) . new_against]),
                                      empty,[word])
                                else floatw_transforming_text
                                      ([word]+t,empty,is_too_large,is_too_large,is_hight,
                                       append([to_middle(bc,line) . new_against],against),
                                       new_nb_line+1,to_middle,to_middle,to_last,to_bcont,end_bl)
   
                          else floatw_transforming_text
                                (t,empty,is_too_large,is_too_large,is_hight,
                                 [end_bl(new_line) . new_against]+against,
                                  new_nb_line+1,to_middle,to_middle,to_last,to_bcont,end_bl))
   
           else if is_hight(nb_line) 
                  then with new_bl = (BlockLine)if t is [] then to_last(bc,h) else to_middle(bc,h),
                       (reverse([new_bl . against]),empty,t)
                  else floatw_transforming_text
                        (t,add_bc,is_too_large_c,is_too_large,is_hight,against,
                         nb_line+1,to_middle,to_middle,to_last,to_bcont,end_bl)
           
   }. 
   
   
   
   
   
   
   
 #define (List(BlockLine),List(StringParagraph))
   floatw_transforming_text
     (
       List(String)                 pgraph, // list (real) text paragraphs
       BlockContent                     bc,
       String -> Bool       is_too_large_c,
       String -> Bool         is_too_large,
       Int32 -> Bool              is_hight,
       List(BlockLine)             against,
       Int32                       nb_line, // initialization = 1
       (BlockContent,String) -> BlockLine        to_bline,
       (BlockContent,String) -> BlockLine       to_middle,
       (BlockContent,String) -> BlockLine         to_last
     ) =
   if pgraph is
     {
       []      then (reverse(against),[]),
       [h . t] then
         with new_bc = to_bcont(h),
              add_bc = bc+new_bc,
         if is_too_large_c(concat_bcont(add_bc))
           then (if transform_to_one_pgraph 
                      (explode(h),is_too_large_c,is_hight,to_bline,nb_line,"","",[]) 
                   is (new_nb_line,word,line,new_against) then 
                      // (Int32) new_nb_line = line counter
                      // (String) word = . text not treated,
                      //                 . or part of text after the widget, if line is empty
                      // (String) line = line under construction. Empty means available height is 
                      //                 reached
                      // (List(BlockLine)) new_against = will take place against the widget
                 if line = ""
                   then // end of the process
                        (reverse(append(new_against, against)),[to_continue(word)])
                   else // testing the result
                        with new_line = (String)(line+" "+word),
                       if is_too_large_c(new_line)
                         then if is_hight(new_nb_line)
                                then (against+reverse([to_middle(line) . new_against]),
                                      [to_continue(word)])
                                else floatw_transforming_text
                                      ([word]+t,is_too_large,is_too_large,is_hight,
                                       append([to_middle(line) . new_against],against),
                                       new_nb_line+1,to_middle,to_middle,to_last)
   
                          else floatw_transforming_text
                                (t,is_too_large,is_too_large,is_hight,
                                 [to_middle(new_line) . new_against]+against,
                                  new_nb_line+1,to_middle,to_middle,to_last))
   
           else if is_hight(nb_line) 
                  then with new_bl = (BlockLine)if t is [] then to_last(h) else to_middle(h),
                       (reverse([new_bl . against]),[(StringParagraph)new_paragraph(concat(t))])
                  else floatw_transforming_text
                        (t,is_too_large_c,is_too_large,is_hight,[to_bline(h) . against],
                         nb_line+1,to_middle,to_middle,to_last)
           
   }. 
   
   
   
define (List(BlockLine),List(StringParagraph))
   floatw_transforming_text
     (
       List(StringParagraph)      lstr_pgraph,
       BlockContent                  build_bc,
       String -> Bool          is_too_large_i,
       String -> Bool            is_too_large,
       Int32 -> Bool                 is_hight,
       List(BlockLine)                 blines,
       List(StringParagraph)            spars
     ) =
   if lstr_pgraph is 
     {
       []      then (blines,spars),
       [h . t] then 
        if h is 
          { 
            new_paragraph(txt)     then 
   print("NP-t=["+txt+"]\n");
   /*
   print("---------------\n");
   print_ls(split_string_into_lines(txt)); 
   print("---------------\n");
   */
              if floatw_transforming_text
                   (split_string_into_lines(txt),build_bc,is_too_large_i,is_too_large,is_hight,
                    (List(BlockLine))[],1,
                    (BlockContent bc,String s) |-> (BlockLine)first(bc+text(s,empty)),
                    (BlockContent bc,String s) |-> (BlockLine)middle(bc+text(s,empty)),
                    (BlockContent bc,String s) |-> (BlockLine)last(bc+text(s,empty)),
                    (String s) |-> text(s,empty),
                    (String s) |-> (BlockLine)last(text(s,empty))) is (lbl,new_bc,more_txt)
              then 
              if new_bc is empty
                then (blines+lbl,[(StringParagraph)new_paragraph(concat(more_txt)) . t])
                else floatw_transforming_text
                      (t,new_bc,is_too_large_i,is_too_large,is_hight,blines+lbl,spars),
   /*
              then floatw_transforming_text(
                    t,build_bc,is_too_large_i,is_too_large,is_hight,blines+bl,spars+sp),
   */
            to_continue(txt)       then 
   print("TC-t=["+txt+"]\n");
              if floatw_transforming_text
                   (split_string_into_lines(txt),build_bc,is_too_large,is_too_large,is_hight,
                    (List(BlockLine))[],1,
                    (BlockContent bc,String s) |-> (BlockLine)middle(bc+text(s,empty)),
                    (BlockContent bc,String s) |-> (BlockLine)middle(bc+text(s,empty)),
                    (BlockContent bc,String s) |-> (BlockLine)last(bc+text(s,empty)),
                    (String s) |-> text(s,empty),
                    (String s) |-> (BlockLine)last(text(s,empty))) is (lbl,new_bc,more_txt)
              then 
              if new_bc is empty
                then (blines+lbl,[(StringParagraph)to_continue(concat(more_txt)) . t])
                else floatw_transforming_text
                      (t,new_bc,is_too_large_i,is_too_large,is_hight,blines+lbl,spars),
   /*
              then floatw_transforming_text
                     (t,build_bc,is_too_large_i,is_too_large,is_hight,blines+bl,spars+sp),
   */
            new_paragraph(lk,i)  then 
   print("NB-l=["+txt(lk)+"]\n");
              if floatw_transforming_text
                   (split_string_into_lines(txt(lk)), build_bc,is_too_large_i,is_too_large,is_hight,
                   (List(BlockLine))[],1,
                    (BlockContent bc,String s) |-> (BlockLine)first(bc+link(s,action(lk),i,empty)),
                    (BlockContent bc,String s) |-> (BlockLine)middle(bc+link(s,action(lk),i,empty)),
                    (BlockContent bc,String s) |-> (BlockLine)last(bc+link(s,action(lk),i,empty)),
                    (String s) |-> link(s,action(lk),i,empty),
                    (String s) |-> (BlockLine)last(link(s,action(lk),i,empty)))
               is (lbl,new_bc,more_txt) //(bl,sp)
            then 
              if new_bc is empty
                then (blines+lbl,
                      [(StringParagraph)new_paragraph(link(concat(more_txt),action(lk)),i) . t])
                else floatw_transforming_text
                      (t,new_bc,is_too_large_i,is_too_large,is_hight,blines+lbl,spars),
   /*
              then floatw_transforming_text
                     (t,build_bc,is_too_large_i,is_too_large,is_hight,blines+lbl,spars+sp),
   */
            to_continue(lk,i)    then 
   print("TC-l=["+txt(lk)+"]\n");
              if floatw_transforming_text
                   (split_string_into_lines(txt(lk)),build_bc,is_too_large,is_too_large,is_hight,
                    (List(BlockLine))[],1,
                    (BlockContent bc,String s) |-> (BlockLine)middle(bc+link(s,action(lk),i,empty)),
                    (BlockContent bc,String s) |-> (BlockLine)middle(bc+link(s,action(lk),i,empty)),
                    (BlockContent bc,String s) |-> (BlockLine)last(bc+link(s,action(lk),i,empty)),
                    (String s) |-> link(s,action(lk),i,empty),
                    (String s) |-> (BlockLine)last(link(s,action(lk),i,empty)))
                   is (lbl,new_bc,more_txt)
              then 
              if new_bc is empty
                then (blines+lbl,
                      [(StringParagraph)to_continue(link(concat(more_txt),action(lk)),i) . t])
                else floatw_transforming_text
                      (t,new_bc,is_too_large_i,is_too_large,is_hight,blines+lbl,spars),
   /*
              then floatw_transforming_text
                     (t,build_bc,is_too_large_i,is_too_large,is_hight,blines+bl,spars+sp),
   */
           }
     }.
   
   
define (List(BlockLine),List(StringParagraph))
   floatw_transforming_text_0
     (
       List(StringParagraph)      lstr_pgraph,
       BlockContent                  build_bc,
       String -> Bool          is_too_large_i,
       String -> Bool            is_too_large,
       Int32 -> Bool                 is_hight,
       List(BlockLine)                 blines,
       List(StringParagraph)            spars
     ) =
   if lstr_pgraph is []
     then print("GO\n"); floatw_transforming_text(build_bc,is_too_large,is_hight)
     else //print("LP="+length(lstr_pgraph)+"\n");
          floatw_transforming_text(lstr_pgraph,build_bc,is_too_large_i,is_too_large,is_hight,[],[]).
   
   
   
   
         *** (4.2.2) Basic function
         **************************
   
define List(Block)
   to_blocks
     (
       HyperTextContent                        content,
       Int32                                 htc_width,
       Int32                                    margin,
       Int32                                    indent,
       Int32                            height_writing,
       (String,Int32) -> Bool             is_too_large,
       List(StringParagraph)                    so_far,
       Maybe((Widget,LR_Widget,Int32,Int32,
              (List(StringParagraph),
               BlockContent,
               String -> Bool,
               String -> Bool,
               List(BlockLine),List(StringParagraph)) 
                  -> (List(BlockLine),List(StringParagraph))) )   mb_wid,
      List(Block)                               blocks,
      Int32                                 link_index
     ) =
   if content is 
     {
       empty              then 
         if mb_wid is 
           {
             failure       then 
               reverse([t_block(transforming_text
                                  (reverse(so_far),
                                   (String s) |-> is_too_large(s,htc_width-indent),
                                   (String s) |-> is_too_large(s,htc_width))) . blocks])
             success(wxy)  then 
               if wxy is (wid,lr,yp,sp,transform) then 
               if get_size(wid)(unique) is (wid_width,h_wid) then 
   //print("lsofar="+length(so_far)+"\n");
               if transform(reverse(so_far),empty,
                           (String s) |-> is_too_large(s,htc_width-indent-wid_width-sp),
                           (String s) |-> is_too_large(s,htc_width-wid_width-sp),
                            [],[])
                             is (against_widget,more_text) then 
               reverse(blocks)
                 +[wt_block(against_widget,lr,yp,sp,wid)
                   . if more_text is []
                       then []
                       else [t_block(transforming_text
                                      (more_text,
                                      (String s) |-> is_too_large(s,htc_width-indent),
                                       (String s) |-> is_too_large(s,htc_width)))]]
           },
       string(s,htc)      then 
   //print("s=["+s+"]\n");
         to_blocks(htc,htc_width,margin,indent,height_writing,is_too_large,
                   add(so_far,s),mb_wid,blocks,link_index),
       linkw(lw,htc)      then 
         to_blocks(htc,htc_width,margin,indent,height_writing,is_too_large,
                   add(so_far,lw,link_index),mb_wid,blocks,link_index+1),
       posw(pw,htc)       then 
         if pw is
           {
             left_pw(vp,sp,wid)  then 
               to_blocks(htc,htc_width,margin,indent,height_writing,is_too_large,[],
                         success((wid,left,vp,sp,posw_transforming_text)),
                         reverse([t_block(transforming_text
                                  (reverse(so_far),
                                   (String s) |-> is_too_large(s,htc_width-indent),
                                   (String s) |-> is_too_large(s,htc_width))) . blocks]),
                         link_index),
             right_pw(vp,sp,wid) then 
               to_blocks(htc,htc_width,margin,indent,height_writing,is_too_large,[],
                         success((wid,right,vp,sp,posw_transforming_text)),
                         reverse([t_block(transforming_text
                                  (reverse(so_far),
                                   (String s) |-> is_too_large(s,htc_width-indent),
                                   (String s) |-> is_too_large(s,htc_width))) . blocks]),
                         link_index),
           },
       floatingw(fw,htc)  then 
         if fw is 
           {
             left_fw(sp,wid)   then 
               if get_size(wid)(unique) is (_,wid_height) then 
               if transforming_text_before_fw
                     (reverse(so_far),htc,
                      (String s) |-> is_too_large(s,htc_width-indent),
                      (String s) |-> is_too_large(s,htc_width)) 
                  is (new_blocks,new_htc,new_str_p,nb_lk) then 
               to_blocks(new_htc,htc_width,margin,indent,height_writing,is_too_large,new_str_p,
                         success((wid,left,0,sp,
                                  (List(StringParagraph) s, 
                                   BlockContent _,
                                   String -> Bool stli,
                                   String -> Bool stl,
                                   List(BlockLine) lbl,List(StringParagraph)lsp) |-> 
                                     floatw_transforming_text_0
                                       (s,empty,stli,stl,
                                        (Int32 n) |-> n = 1+(wid_height/height_writing),[],[]))),
                         reverse([t_block(new_blocks) . blocks]),
                         link_index+nb_lk),
             right_fw(sp,wid)  then 
               if get_size(wid)(unique) is (_,wid_height) then 
               if transforming_text_before_fw 
                    (reverse(so_far),htc,
                     (String s) |-> is_too_large(s,htc_width-indent),
                     (String s) |-> is_too_large(s,htc_width)) 
                  is (new_blocks,new_htc,new_str_p,nb_lk) then 
               to_blocks(new_htc,htc_width,margin,indent,height_writing,is_too_large,new_str_p,
                         success((wid,right,0,sp,
                                  (List(StringParagraph) s,
                                   BlockContent bc,
                                   String -> Bool stli,
                                   String -> Bool stl,
                                   List(BlockLine) lbl,List(StringParagraph)lsp) |-> 
                                     floatw_transforming_text_0
                                       (s,empty,stli,stl,
                                        (Int32 n) |-> n=1+(wid_height/height_writing),[],[]))),
                         reverse([t_block(new_blocks) . blocks]),
                         link_index+nb_lk),
           }
     }.
   
define List(Block)
   to_blocks
     (
       HyperTextContent               content,
       Int32                        htc_width,
       Int32                           margin,
       Int32                           indent,
       Int32                   height_writing,
       (String,Int32) -> Bool    is_too_large
     ) =
   to_blocks(content,htc_width,margin,indent,height_writing,is_too_large,
             [],failure,[],0).
   

   
   *** (5) Hypertext height
   ************************
   
define Int32
   pgraph_height
     (
       List(BlockLine)                lbp,
       Int32                 total_font_height,
       Int32                           v_space
     ) =
   length(lbp) * (total_font_height+v_space).
   
define Int32
   height
     (
       List(Block)             blocks,
       Int32        total_font_height,
       Int32                  v_space
     ) =
   if blocks is
     {
       []      then v_space,  // for the top
       [h . t] then
         if h is 
           {
             t_block(pgraph)          then pgraph_height(pgraph,total_font_height,v_space),
             wt_block(pgraph,_,_,sp,wid)   then //if get_size(wid)(unique) is (w,h) then h+v_space
              max(if get_size(wid)(unique) is (w,h) then h+v_space,
                  pgraph_height(pgraph,total_font_height,v_space))
           }+height(t,total_font_height,v_space)
     }.
   
   
   
   *** (6) Draw the hypertext
   **************************
   
   
      *** (6.1) Justify a text
      ************************
   
   The purpose  is to print  a string onto  the left border AND  onto the right  border by
   adding spaces between words. 
   
   Steps to achieve it are (here space is the character ' '):
      . determining the number  of locations where spaces are required :  this number is just
        the number of words in the line, less on (locations_nb)
      
      . computing the sum of pixels used by spaces (spaces_sum)
   
      . computing the minimum of spaces to put between words (mini_space)
   
   adding (add_spaces/nb_spaces) spaces at the originel one between to
   words.
   
   But, as  (add_spaces (mod nb_spaces))  may be  greater than 0,  one more space  will be
   added to spaces which are  on the left and on the right of the  medium space of the all
   string.
   
   
   First, extract the words  one a text line : the number of spaces  will be the number of
   words minus 1.
   

   
define (String,Int32)
   justify_text
     (
       List(String)         words,
       String              spaces,
       Int32 -> String   one_more,
       String              so_far,
       Int32                    n
     ) =
   if words is 
     {
       []      then (so_far,n),
       [h . t] then 
        if t is []
          then (h+so_far,n)
          else justify_text(t,spaces,one_more,spaces+one_more(n)+h+so_far,n+1)
     }.
   
define BlockContent
   justify_text
     (
       BlockContent       content,
       String              spaces,
       Int32 -> String   one_more,
       Int32                    n
     ) =
   if content is 
     {
       empty            then empty,
       text(s,bc)       then 
         if justify_text(extract_words(s),spaces,one_more,"",n) is (new_s,new_n)
          then //print_ls(extract_words(s));
               //print("s=["+s+"]\n");
               text(new_s,justify_text(bc,spaces,one_more,new_n))
       link(s,a,i,bc) then
         if justify_text(extract_words(s),spaces,one_more,"",n) is (new_s,new_n)
          then //print_ls(extract_words(s));
               //print("s=["+s+"]\n");
               link(new_s,a,i,justify_text(bc,spaces,one_more,new_n))
     }.
   

define BlockContent
   justify_text
     (
       BlockContent               bc,
       Int32                   width,
       String -> Int32  string_width
     ) =
   with text          = concat_bcont(bc),
        words         = extract_words(text),
        locations_nb  = length(words)-1, 
        w_space       = string_width(" "),
        //spaces_to_add = max(1,(width-string_width(concat(words)))/w_space),    
        spaces_to_add = (Int32)((width-string_width(concat(words)))/w_space),  
   with jt = 
   justify_text(bc,   
      constant_string(max(1,spaces_to_add/locations_nb),' '), // at least, between two words
      with q = (spaces_to_add (mod locations_nb)),            // spaces to distribute no-equally
      (Int32 ct) |->
         if q = 0 then ""
                  else with l = (locations_nb/2)-(q/2),
                            r = (locations_nb/2)+(q/2)+(q (mod 2)),
                       if l<ct & ct=<r then " " else "",
      0),
   //print("JT=["+concat_bcont(jt)+"]\n");
   //print("JT="+string_width(jt)+" W="+width+" ["+jt+"]\n");
   jt.
   
   
   
   
      *** (6.2) Drawing tools
      ***********************
   
   Those tools are common with the handler.
   

         *** (6.2.1) Compute margin
         **************************
   
define Int32
   compute_margin
     (
       HyperTextParameters        parms,
       String                         s,
       Int32                      width,
       Int32                with_indent   // 1 if with indent, 0 if not
     ) =
   if justify(parms) is
     {
       center   then margin(parms)+(width-string_width(parms)(s))/2, // no indent when center
       left     then margin(parms)+(indent(parms)*with_indent),
       right    then margin(parms)+width-string_width(parms)(s),
       both     then margin(parms)+(indent(parms)*with_indent)
     }.
   
   
   
        *** (6.2.2) Formating the block-content to print
        ************************************************
   
   
define BlockContent
   block_content_format
     (
       HyperTextParameters   parms,
       BlockContent             bc,
       Int32                 width
     ) =
   if bc is
     {
       empty      then empty
       text(s,_)  then if justify(parms) is 
                         {
                           center   then bc,
                           left     then bc,
                           right    then bc,
                           both     then justify_text(bc,width,string_width(parms))
                         },
       link(s,a,i,_) then if justify(parms) is 
                            {
                              center   then bc,
                              left     then bc,
                              right    then bc,
                              both     then justify_text(bc,width,string_width(parms))
                            },
     }.
   
   
      *** (6.3) Draw a text
      *********************
   
define RGB -> RGB
   text_color
     (
       BlockContent bc,
       RGB          lk_color
     ) =
   (RGB rgb) |->
     if bc is 
       {
         empty         then rgb,
         text(_,_)     then rgb,
         link(_,_,_,_) then lk_color
       }.
   
define Int32
   draw_text
     (
       WidgetDrawToolBox            dtb,
       HyperTextParameters        parms,
       String                      text,
       RGB -> RGB            text_color,
       Int32                      x_pos,
       Int32                      y_pos
     ) = //print("T=["+text+"]\n");
   if effect(parms) is
     {
      normal(color)       then 
        draw(dtb)(text,font(parms),text_color(color),position(x_pos,y_pos)),
      shadow(mc,sc,dx,dy) then 
        with xp = x_pos,
        forget(draw(dtb)(text,font(parms),sc,position(xp+dx,y_pos+dy)));
        draw(dtb)(text,font(parms),mc,position(xp,y_pos)),
      engraved(color)     then 
        with xp = x_pos,
             col = text_color(color),
        forget(draw(dtb)(text,font(parms),lighten(col),position(xp+2,y_pos+2)));
        forget(draw(dtb)(text,font(parms),darken(col),position(xp,y_pos)));
        draw(dtb)(text,font(parms),col,position(xp+1,y_pos+1)),
      relief(color)       then 
        with xp = x_pos,
             col = text_color(color),
        forget(draw(dtb)(text,font(parms),darken(col),position(xp+2,y_pos+2)));
        forget(draw(dtb)(text,font(parms),lighten(col),position(xp,y_pos)));
        draw(dtb)(text,font(parms),col,position(xp+1,y_pos+1))
     }.
   
define Int32
   nb_first_spaces
     (
       List(Int8) l
     ) =
   if l is 
     {
       []      then 0,
       [h . t] then 
         if h = ' ' then 1+nb_first_spaces(t)
                    else 0
     }.
   
define One
   draw_text
     (
       WidgetDrawToolBox            dtb,
       HyperTextParameters        parms,
       BlockContent             content,
       RGB -> RGB            text_colo,
       Int32                      x_pos,
       Int32                      y_pos
     ) = //print("T=["+text+"]\n");
   if content is 
     {
       empty           then unique,
       text(s,bc)      then 
         draw_text(dtb,parms,bc,text_colo,
                   x_pos+draw_text(dtb,parms,s,text_color(content,link_color(parms)),x_pos,y_pos),
                   y_pos),
       link(s,_,_,bc) then
         with new_x_pos = x_pos+draw_text(dtb,parms,s,text_color(content,link_color(parms)),x_pos,y_pos),
         draw(dtb)(rect(x_pos+string_width(parms)(constant_string(nb_first_spaces(explode(s)),' ')),
                        y_pos+1,new_x_pos,y_pos+2),link_color(parms));
         draw_text(dtb,parms,bc,text_colo,new_x_pos,y_pos)
     }.
   
   
   
   What is the value of y_pos ?
   ----------------------------
   
   First,  when drawing  the hypertext  is required,  y_pos is  initialized at  the margin
   value. Then when a block (t_block ot wt_block) is up to print, the font height value is
   added  to y_pos  to obtain  the vertical  position where  a text  is printing  (see the
   draw(dtb) tool).  Then after each line  of text, the above function 'draw_text' add the
   total_font_height plus the space between to line : y_pos is ready to print a new text.
   
   But when there is  no more BlockParagraph to print, it's necessary  to reduce the final
   value of y_pos by the font-height value in the below function 'draw_paragraph'.
   
   
define Int32
   draw_pgraph
     (
       WidgetDrawToolBox                             dtb,
       HyperTextParameters                         parms,
       List(BlockLine)                           b_lines,
       String -> Int32                           x_pos_i,
       String -> Int32                             x_pos,  // for all lines except n#1
       Int32                                       y_pos,  // font 
       (BlockContent,Int32) -> BlockContent     format_bc
     ) =
   if b_lines is 
     {
       []      then y_pos-font_height(parms),
       [h . t] then 
          if h is 
            {
              first(bc)  then //print("xp="+x_pos1(text)+" Fi ["+text+"]\n");
                with new_bc = format_bc(bc,indent(parms)),
                draw_text(dtb,parms,new_bc,text_color(bc,link_color(parms)),
                         x_pos_i(concat_bcont(new_bc)),y_pos),
              middle(bc) then //print("Mi ["+text+"]\n");
                with new_bc = format_bc(bc,0),
                draw_text(dtb,parms,new_bc,text_color(bc,link_color(parms)),
                         x_pos(concat_bcont(new_bc)),y_pos)
              last(bc)    then //print("En ["+text+"]\n");
                with new_bc = bc, //format_bc(h,0),
                draw_text(dtb,parms,new_bc,text_color(bc,link_color(parms)),
                          x_pos(concat_bcont(new_bc)),y_pos)
              flast(bc)   then //print("Fe ["+text+"]\n");
                with new_bc = format_bc(bc,indent(parms)),
               draw_text(dtb,parms,new_bc,text_color(bc,link_color(parms)),
                        x_pos_i(concat_bcont(new_bc)),y_pos),
            };
         draw_pgraph(dtb,parms,t,x_pos_i,x_pos,y_pos+total_font_height(parms)+v_space(parms),
                     format_bc)
         
     }.
   

      *** (6.5) Global function
      *************************
   
define One
   draw_hypertext
     (
       WidgetDrawToolBox                            dtb,
       List(Block)                               blocks,
       HyperTextParameters                        parms,
       Int32                                  htc_width,
       (String,Int32) -> Int32             x_pos_indent,   // (text_lenght,width)
       (String,Int32) -> Int32                    x_pos,   // (text_lenght,width)
       Int32                                      y_pos,
       (BlockContent,Int32) -> BlockContent    format_bc
     ) = 
   if blocks is 
     {
       []       then unique,
       [h . t]  then 
         if h is 
           {
             t_block(blines)     then
                with t_height = 
                       draw_pgraph(dtb,parms,blines,
                                   (String s) |-> x_pos_indent(s,htc_width),
                                   (String s) |-> x_pos(s,htc_width),
                                   y_pos+font_height(parms),
                                   (BlockContent bc, Int32 indent) |-> format_bc(bc,htc_width-indent)),
                draw_hypertext(dtb,t,parms,htc_width,x_pos_indent,x_pos,
                               t_height,format_bc),
             wt_block(blines,lr,yp,sp,wid) then
               if get_size(wid)(unique) is (wid_width,wid_height) then 
                redraw(wid)(dtb,clipping_rectangle(dtb));
                with t_width  = htc_width-wid_width-sp, 
                     t_height =
                       draw_pgraph
                         (dtb,parms,blines,
                         (String s) |-> if lr is 
                                          {
                                            left  then wid_width+sp,
                                             right then 0
                                          }+x_pos_indent(s,t_width),
                         (String s) |-> if lr is 
                                          {
                                            left  then wid_width+sp,
                                             right then 0
                                           }+x_pos(s,t_width),
                          y_pos+min(max(yp,font_height(parms)),
                                    wid_height-font_depth(parms)),
                         (BlockContent bc,Int32 indent) |-> format_bc(bc,t_width-indent)),
                     wid_bottom = y_pos+wid_height+v_space(parms),
                draw_hypertext(dtb,t,parms,htc_width,x_pos_indent,x_pos,
                               max(t_height,wid_bottom),format_bc)
           }
     }.
   
define One
   draw_hypertext
     (
       WidgetDrawToolBox             dtb,
       List(Block)                blocks,
       HyperTextParameters         parms,
       Int32                   htc_width,
     ) = 
   draw_hypertext
      (dtb,blocks,parms,htc_width,
       // x position with indent (for 'first' and 'flast')
       (String s,Int32 width) |-> compute_margin(parms,s,width,1),
       // x position without indent (for 'middle' and 'flast')
       (String s,Int32 width) |->  compute_margin(parms,s,width,0),
        margin(parms),
        // formating the block-content to print
        (BlockContent bc,Int32 width) |-> block_content_format(parms,bc,width)).
   
   
   *** (7) Setting child positions
   *******************************
   
define One
   set_child_positions
     (
       WidgetPositionToolBox        ptb,
       List(Block)               blocks,
       HyperTextParameters        parms,
       Int32                  htc_width,
       Int32                      y_pos
     ) =
   if blocks is 
     {
       []      then unique,
       [h . t] then 
         if h is 
           {
             t_block(pgraph)         then 
               set_child_positions(ptb,t,parms,htc_width,
                                   y_pos+pgraph_height(pgraph,total_font_height(parms),v_space(parms))),
             wt_block(pgraph,lr,vp,sp,wid) then 
               if get_size(wid)(unique) is (w,h) then
               with pgraph_height = pgraph_height(pgraph,total_font_height(parms),v_space(parms)),
               y = y_pos + (if h > pgraph_height
                             then 0
                             else (pgraph_height-h)/2),
               set_position(wid)
                  (ptb,position(
                        margin(parms)+if lr is 
                                       {
                                         left   then 0,
                                         right  then htc_width-w
                                       },
                        y));
               set_child_positions(ptb,t,parms,htc_width,y_pos+max(w,pgraph_height)+v_space(parms))
           }
     }.
   
      

   
   *** (8) Handler
   ***************
   
   
   The handler role is to mange the link-widget. 
   
   When the  mouse will come over  a link, it's  appareance will move to  inverted colors,
   i.e. write  with the  background-color, and  the background move  to the  usual writing
   color.
   
   
   The first step to control those effects,  is to have in hand a List(LinkRectangle) from
   the List(Block).
   
   A LinkRectangle is  formed by 
    . an index;
    . a List((String,Int32,WidgetRectangle)) where : 
         the String is the text-link,
         the Int32 is the number pixels for spaces at the beginning of the text
         the WidgerRectangle begins a the first letter of the text
     And it's a list because a link may be written on sevral lines.
   
   
   
      *** (8.1) List(LinkRectangle)
      *****************************
   
type LinkState:
   normal,            // link is waiting mouse or a click
   mouse_over,        // mouse is over the click (transitory state)
   visited.           // link was clicked
   
   
   
type LinkRectangle:
   link_rectangle(Int32                                 index,
                  List((String,Int32,WidgetRectangle))  lrect,
                  LinkState                             state,
                  WidgetEventToolBox -> One           action).
   
define One
   print_lkr
     (
       List(LinkRectangle) llr
     ) =
   if llr is 
     {
       []      then unique,
       [h . t] then 
        print(index(h)+" | "
             +concat(map(((String,Int32,WidgetRectangle) sn_wr) |-> 
                      if sn_wr is (_,_,wr) then "("+x(wr)+"/"+y(wr)+"/"+u(wr)+"/"+v(wr)+")",
                     lrect(h)))+"\n");
        print_lkr(t)
     }.
   
define (String,Int32,WidgetRectangle)
   compute_rectangle
     (
       HyperTextParameters  parms,
       String                   s,
       Int32                x_pos,
       Int32                y_pos
     ) = 
   with n = string_width(parms)(constant_string(nb_first_spaces(explode(s)),' ')),
   (s,n,rect(x_pos+n,
             y_pos-font_height(parms),
             x_pos+string_width(parms)(s)+1,
             y_pos+font_depth(parms))).
   
define LinkRectangle
   new_link_rectangle
     (
       String                            s,
       Int32                             i,
       WidgetEventToolBox -> One    action,
       HyperTextParameters           parms,
       Int32                         x_pos,
       Int32                         y_pos
     ) =
   link_rectangle
      (i,
       [compute_rectangle(parms,s,x_pos,y_pos)],
       normal,
      action).
   
define LinkRectangle
   add_rectangle
     (
       LinkRectangle           lr,
       HyperTextParameters  parms,
       String                   s,
       Int32                x_pos,
       Int32                y_pos
     ) =
   link_rectangle
      (index(lr),
       [compute_rectangle(parms,s,x_pos,y_pos) . lrect(lr)],
       normal,
       action(lr)).
   
   
define List(LinkRectangle)
   compute_link_rectangles
     (
       String                            s,
       Int32                             i,
       WidgetEventToolBox -> One    action,
       HyperTextParameters           parms,
       Int32                         x_pos,
       Int32                         y_pos,
       List(LinkRectangle)             llr
     ) =
   if llr is 
     {
       []       then [new_link_rectangle(s,i,action,parms,x_pos,y_pos)],
       [h . t]  then 
         if index(h) = i
           then [add_rectangle(h,parms,s,x_pos,y_pos) . t]
           else [h . compute_link_rectangles(s,i,action,parms,x_pos,y_pos,t)]
     }.
   
   
define List(LinkRectangle)
   do_link_rectangles_bc
     (
       BlockContent            content,
       HyperTextParameters       parms,
       List(LinkRectangle)      so_far,
       Int32                     x_pos,
       Int32                     y_pos
     ) =
   if content is 
     {
       empty          then so_far,
       text(s,bc)     then do_link_rectangles_bc(bc,parms,so_far,x_pos+string_width(parms)(s),y_pos),
       link(s,a,i,bc) then 
         do_link_rectangles_bc
           (bc,parms,
            compute_link_rectangles(s,i,a,parms,x_pos,y_pos,so_far),
            x_pos+string_width(parms)(s),y_pos)
     }.
   
define (List(LinkRectangle),Int32)
   do_link_rectangles_lines
     (
       List(BlockLine)                             lines,
       HyperTextParameters                         parms,
       List(LinkRectangle)                        so_far,
       (String) -> Int32                         x_pos_i,
       (String) -> Int32                           x_pos,
       Int32                                       y_pos,
       (BlockContent,Int32) -> BlockContent    format_bc
     ) =
   if lines is 
     {
       []      then (so_far,y_pos),
       [h . t] then 
         if h is 
           {
             first(bc)    then 
               with f_bc = format_bc(bc,indent(parms)), 
               do_link_rectangles_lines
                 (t,parms,
                  do_link_rectangles_bc
                    (f_bc,parms,so_far,x_pos_i(concat_bcont(f_bc)),y_pos),
                  x_pos_i,x_pos,y_pos+total_font_height(parms)+v_space(parms),format_bc)
             middle(bc)   then
               with f_bc = format_bc(bc,0), 
               do_link_rectangles_lines
                 (t,parms,
                  do_link_rectangles_bc
                    (f_bc,parms,so_far,x_pos(concat_bcont(f_bc)),y_pos),
                  x_pos_i,x_pos,y_pos+total_font_height(parms)+v_space(parms),format_bc)
             last(bc)     then
               do_link_rectangles_lines
                 (t,parms,
                  do_link_rectangles_bc
                    (bc,parms,so_far,x_pos(concat_bcont(bc)),y_pos),
                  x_pos_i,x_pos,y_pos+total_font_height(parms)+v_space(parms),format_bc)
             flast(bc)    then
               with f_bc = format_bc(bc,indent(parms)), 
               do_link_rectangles_lines
                 (t,parms,
                  do_link_rectangles_bc
                    (f_bc,parms,so_far,x_pos_i(concat_bcont(f_bc)),y_pos),
                  x_pos_i,x_pos,y_pos+total_font_height(parms)+v_space(parms),format_bc)
           }
     }.
   
     
define List(LinkRectangle)
   do_link_rectangles
     (
       List(Block)                                blocks,
       HyperTextParameters                         parms,
       List(LinkRectangle)                        so_far,
       Int32                                   htc_width,
       (String,Int32) -> Int32              x_pos_indent,   // (text_lenght,width)
       (String,Int32) -> Int32                     x_pos,   // (text_lenght,width)
       Int32                                       y_pos,
       (BlockContent,Int32) -> BlockContent    format_bc
     ) =
   if blocks is 
     {
       []       then so_far,
       [h . t]  then 
         if h is 
           {
             t_block(lines)               then 
               if do_link_rectangles_lines
                   (lines,parms,so_far,
                    (String s) |-> x_pos_indent(s,htc_width),
                    (String s) |-> x_pos(s,htc_width),
                    y_pos+font_height(parms),
                    (BlockContent bc,Int32 indent) |-> format_bc(bc,htc_width-indent))
                 is (llr,new_y_pos) then 
               do_link_rectangles
                  (t,parms,llr,htc_width,x_pos_indent,x_pos,new_y_pos,format_bc),
   
             wt_block(lines,lr,vp,sp,wid) then 
               if get_size(wid)(unique) is (wid_width,wid_height) then 
               with t_width  = htc_width-wid_width-sp, 
               if do_link_rectangles_lines
                   (lines,parms,so_far,
                    //(String s) |-> x_pos_indent(s,htc_width),
                    (String s) |-> if lr is 
                                     {
                                       left   then wid_width+sp,
                                       right  then 0
                                     }+x_pos_indent(s,t_width),
                    //(String s) |-> x_pos(s,htc_width),
                    (String s) |-> if lr is 
                                     {
                                       left   then wid_width+sp,
                                       right  then 0
                                     }+x_pos(s,t_width),
                    //y_pos+font_height(parms),
                    y_pos-font_height(parms)+max(vp,font_height(parms)),
   /*
                    y_pos+min(max(vp,font_height(parms)),
                                  wid_height-font_depth(parms))
                     -font_height(parms),
   */
                    //y_pos+vp,
                    (BlockContent bc,Int32 indent) |-> format_bc(bc,htc_width-indent))
                 is (llr,new_y_pos) then 
   
               with y = max(y_pos-font_height(parms)+wid_height+v_space(parms),new_y_pos),
               do_link_rectangles(t,parms,llr,htc_width,x_pos_indent,x_pos,y,format_bc)
                            
               //do_link_rectangles(t,parms,so_far,htc_width,x_pos_indent,x_pos,y_pos,format_bc)
           }
     }.
   
   
   
   
define List(LinkRectangle)
   do_link_rectangles
     (
       List(Block)                blocks,
       HyperTextParameters         parms,
       Int32                   htc_width,
    ) =
   do_link_rectangles
     (blocks,parms,(List(LinkRectangle))[],htc_width,
      (String s,Int32 width) |-> compute_margin(parms,s,width,1),
      (String s,Int32 width) |-> compute_margin(parms,s,width,0),
      margin(parms),
      (BlockContent bc,Int32 width) |-> block_content_format(parms,bc,width)).
     
   
   
   
   
      *** (8.2) HyperText handler
      ***************************
   
         *** (8.2.1) Tools
         *****************

define List(WidgetRectangle)
   wid_rect
     (
       List((String,Int32,WidgetRectangle)) l
     ) =
   map(((String,Int32,WidgetRectangle) sn_wr) |-> if sn_wr is (_,_,wr) then wr,l).
   
   
define Maybe(LinkRectangle)
   is_mouse_over_lk_rect
     (
       List(LinkRectangle)   llr,
       Int32                  mx,
       Int32                  my
     ) =
   if llr is
     {
       []      then failure,
       [h . t] then 
         if belongs(mx,my,wid_rect(lrect(h)))
           then success(h)
           else is_mouse_over_lk_rect(t,mx,my)
     }.
   

define List(LinkRectangle)
   move_link_state
     (
       List(LinkRectangle)      llr,
       LinkRectangle         act_lr,  // active link to move to unactiv
       LinkState              state
     ) =
   replace_element
     (llr,
      (LinkRectangle lr) |-> index(lr)=index(act_lr),
      link_rectangle(index(act_lr),lrect(act_lr),state,action(act_lr))).
   
   
define List(WidgetRectangle)
   get_visited_wid_rect
     (
       List(LinkRectangle)  llr
     ) =
   find_elements(llr,
                 (LinkRectangle lr) |-> state(lr)=visited,
                 (LinkRectangle lr) |-> wid_rect(lrect(lr))).
   
   
         *** (8.2.2) When mouse moves...
         *******************************
   
define Maybe((List(LinkRectangle),List(WidgetRectangle),LinkRectangle))
   mouse_over_lk_rect
     (
       List(LinkRectangle)      llr,
       Int32                     mx,
       Int32                     my,
       List(LinkRectangle)   so_far,
     ) =
   if llr is
     {
       []      then failure, 
       [h . t] then 
         with wid_rect = wid_rect(lrect(h)),
         if belongs(mx,my,wid_rect)
           then with active_lk = 
                       link_rectangle(index(h),lrect(h),
                                      if state(h) is 
                                        {
                                          normal      then mouse_over,
                                          mouse_over  then mouse_over,
                                          visited     then visited
                                        },action(h)),
                 success(([active_lk . append(t,so_far)],
                          wid_rect,
                          active_lk))
           else mouse_over_lk_rect(t,mx,my,[h . so_far])
     }.
   

   
         *** (8.2.3) Generic answer
         **************************
   
define WidgetAnswer
   hypertext_handler
     (
       WidgetEventToolBox                  etb,
       WidgetNormalEvent                     e,
       Var(List(LinkRectangle))        lk_rect,
       Var(Maybe(LinkRectangle))   active_link
     ) =
// print_lkr(*lk_rect);
   if e is 
     {
       mouse_gone               then 
         if *active_link is 
           {
             failure       then not_handled([]),
             success(a_lk) then 
              active_link <- failure;
              handled(wid_rect(lrect(a_lk)))
           },
       mouse_move(ks,mx,my)     then
         if mouse_over_lk_rect(*lk_rect,mx,my,[]) is 
           {
             failure    then 
               if *active_link is 
                 {
                   failure       then not_handled([]),
                   success(a_lk) then 
                     active_link <- failure;
                     if state(a_lk) is visited
                      then not_handled([])
                      else lk_rect <- move_link_state(*lk_rect,a_lk,normal);
                           handled(wid_rect(lrect(a_lk)))
                 },
             success(s) then if s is (new_lk_rect,wid_rect,a_lk)
               then  lk_rect <- new_lk_rect;
                     active_link <- success(a_lk);
                     handled(wid_rect)
           },
       mouse_click(ks,mc,mx,my) then 
         if *active_link is 
           {
             failure        then not_handled([]),
             success(a_lk)  then 
              if mc is 
                {
                  left_down   then not_handled([]),
                  left_up     then 
                    lk_rect <- move_link_state(*lk_rect,a_lk,visited);
                    action(a_lk)(etb);
                    active_link <- failure;
                    handled(wid_rect(lrect(a_lk))),
                  middle_down then not_handled([]),
                  middle_up   then not_handled([]),
                  right_down  then not_handled([]),
                  right_up    then not_handled([]),
               } 
           }
     }.
   
   
       *** (8.3) Draw List(LinkRectangle)
       **********************************
   
define List((String,Int32,WidgetRectangle))
   rect_to_draw
     (
       List(LinkRectangle) llr,
       LinkState           ls
     ) =
   if llr is 
     {
       []      then [],
       [h . t] then if ls=state(h) then append(lrect(h),rect_to_draw(t,ls)) else rect_to_draw(t,ls)
     }.

   
define One
   draw_links_mouse_over
     (
       WidgetDrawToolBox                              dtb,
       HyperTextParameters                          parms,
       List((String,Int32,WidgetRectangle))  rect_to_draw,
       RGB                                     text_color
     ) =
   if rect_to_draw is
     {
       []      then unique,
       [h . t] then 
         if h is (text,n,wid_rect) then 
         draw(dtb)(wid_rect,lighten(text_color));
         forget(draw_text(dtb,parms,text,(RGB _) |-> darken(text_color), //link_color(parms), //rgb(0,0,0),
                          x(wid_rect)-n,y(wid_rect)+font_height(parms)));
         draw_links_mouse_over(dtb,parms,t,text_color)
     }.
   
define One
   draw_links_visited
     (
       WidgetDrawToolBox                              dtb,
       HyperTextParameters                          parms,
       List((String,Int32,WidgetRectangle))  rect_to_draw
     ) =
   if rect_to_draw is
     {
       []      then unique,
       [h . t] then 
         if h is (text,n,wid_rect) then 
         with y = y(wid_rect)+font_height(parms),
              v_color = darken(link_color(parms)),
         forget(draw_text(dtb,parms,text,(RGB _) |-> v_color, x(wid_rect)-n,y));
         draw(dtb)(rect(x(wid_rect),y+1,x(wid_rect)+string_width(parms)(text),y+2),v_color);
         draw_links_visited(dtb,parms,t)
     }.
   
define One
   draw_links
     (
       WidgetDrawToolBox               dtb,
       Var(List(LinkRectangle))    lk_rect,
       Var(Maybe(LinkRectangle))   active_lk,
       HyperTextParameters           parms,
       Int32                     htc_width
     ) =
   draw_links_mouse_over
      (dtb,parms,rect_to_draw(*lk_rect,mouse_over),text_color(effect(parms)));
   draw_links_visited(dtb,parms,rect_to_draw(*lk_rect,visited)).
   
   
   *** () Creating the widget
   **************************
   
public define Widget
   create_hypertext
     (
       SystemFont                  font,
       WidgetTextEffect          effect,
       Maybe(RGB)            background,      // non mandatory background
       Int32                      width,      // maximal width of text
       Int32                     margin,      // margin for 4 sides
       Int32                    v_space,      // number of pixels between lines
       Int32                     indent,      // number of pixels before beginning of paragraphs
       WidgetTextJustify        justify,      // how to justify the text
       HyperTextContent         content,
       Maybe(RGB)              lk_color       // link_color
     ) =
   
   with sfi = get_font_info(font),
        font_height = int8_to_int32(height(sfi)),
        font_depth  = int8_to_int32(depth(sfi)),
        total_font_height = font_height+font_depth,
        string_width = (String s) |-> printed_text_width(font,s),
        parms = ht_parms(font,font_height,font_depth,total_font_height,margin,v_space,indent,
                         effect,justify,string_width,
                         if lk_color is 
                           {
                             failure      then darken(text_color(effect)),
                             success(rgb) then rgb
                           }),
   
        htc_width    = compute_width(width,content,string_width), // without margins, for the content
        is_too_large = (String s,Int32 n) |-> (string_width(s) > n),
        blocks       = to_blocks(content,htc_width,margin,indent,total_font_height+v_space,is_too_large),
        ht_width     = htc_width+(2*margin),
        ht_height    = height(blocks,total_font_height,v_space)+(2*margin),
        lk_rect      = var( (List(LinkRectangle)) do_link_rectangles(blocks,parms,htc_width)),
        active_link  = var( (Maybe(LinkRectangle)) failure),
   

   create_widget(
   /* set child_positions */
   (WidgetPositionToolBox ptb) |-> 
      set_child_positions(ptb,blocks,parms,htc_width,margin),
   
   /* get_size */
   (One u) |-> (ht_width,ht_height),
   
   /* redraw */
   (WidgetDrawToolBox dtb) |-> 
      if background is 
        {
          failure     then unique,
          success(bg) then draw(dtb)(rect(0,0,ht_width,ht_height),bg)
        };
      draw_hypertext(dtb,blocks,parms,htc_width);
      draw_links(dtb,lk_rect,active_link,parms,htc_width),
   
   /* duplicate */
   (One u) |-> create_hypertext
                (font,effect,background,width,margin,v_space,indent,justify,content,lk_color),

   /* Change size */
   (Int32 w, Int32 h) |-> unique,
   
   /* event handling */
   (WidgetEventToolBox etb, WidgetNormalEvent e) |-> 
     hypertext_handler(etb,e,lk_rect,active_link),
   
   /* monitoring */
   (List(WidgetRegistration)) []
   ).