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
|
<Chapter id="sec-ObjectIO">
<Title>The <literal>Object I/O</literal> package: GUI library for Haskell
<IndexTerm><Primary>Object I/O</Primary></IndexTerm>
</Title>
<Sect1 id="sec-Haskell-ObjectIO">
<Title>Object I/O<IndexTerm><Primary>Object I/O</Primary></IndexTerm>
</Title>
<para>
The Original <literal>Object I/O</literal> library was written in Clean from university of Nijmeegs.
At 12th International Workshop on the Implementation of Functional Languages
Peter Achten and Simon Peyton Jones, presented, first attempt to port library to Haskell.
Initial port has been very simple, but support basic features of complete library.
I decided to continue their work and now <literal>Object I/O</literal> supports a large list of features: Windows,
Dialogs, Various kind of controls, Menus, Timers, Graphics and some other. In CVS repository
there are some interesting examples. Currently <literal>Object I/O</literal> works only on Windows Platform but
I plan porting to GTK for the next release.
</para>
</Sect1>
<Sect1 id="sec-ObjectIO-Basics">
<Title>Basics
<IndexTerm><Primary>Basics</Primary></IndexTerm>
</Title>
<para>
The central point of <literal>Object I/O</literal> are various kinds of objects (devices) as Windows,
Controls, Timers, Menus and Process. Every object has it's own unique Id which may be defined
from user or may be automatically generated from the system. Having object Id we may manage it,
i.e. change it attributes. For example: we may change the windows's title. The most important
attribute of the object is it's local state. It can be data from various types who describe the current state of the object. The object can also receive
events. Every time an event is received, a user defined function, named 'handler', is called.
The 'handler' takes current local state of the object and the local state of process in which the object
exists, and returns the modified states.
</para>
</Sect1>
<Sect1 id="sec-ObjectIO-Usage">
<Title>Usage
<IndexTerm><Primary>Usage</Primary></IndexTerm>
</Title>
<para>
To gain access to the library, just <literal>import ObjectIO</literal>
in your Haskell module and add the <Option>-package objectio</Option>
option to the command line.
</para>
<para>
The library contains a set of modules described in the next chapters. Each module corresponds to a defined type of device. By using this module you can avoid the import of every single module i.e. to import all of them.
</para>
</Sect1>
<Sect1 id="sec-ObjectIO-StdIOCommon">
<Title>StdIOCommon
<IndexTerm><Primary>StdIOCommon</Primary></IndexTerm>
</Title>
<para>
This module contains a set of data types and definitions of functions that are used in the other modules.
</para>
<para>
General type constructors for composing context-independent data structures.
<ProgramListing>
infixr 9 :^:
data Tup t1 t2 = t1 :^: t2
</ProgramListing>
</para>
<para>
General type constructors for composing context-dependent data structures.
<ProgramListing>
infixr 9 :~:
data TupSt t1 t2 ps = (t1 ps) :~: (t2 ps)
data ListCS t ps = ListCS [t ps]
data NilCS ps = NilCS
</ProgramListing>
</para>
<para>
General type constructors for composing local and context-dependent
data structures.
<ProgramListing>
infixr 9 :+:
data TupLS t1 t2 ls ps = (t1 ls ps) :+: (t2 ls ps)
data ListLS t ls ps = ListLS [t ls ps]
data NilLS ls ps = NilLS
data NewLS t ls ps = forall new . NewLS new (t new ps)
data AddLS t ls ps = forall add . AddLS add (t (add,ls) ps)
</ProgramListing>
</para>
<para>
<ProgramListing>
data SelectState = Able | Unable deriving (Eq,Show)
enabled :: SelectState -> Bool
</ProgramListing>
SelectState is similar to Bool but it shows whether an object is enabled or disabled.
</para>
<para>
<ProgramListing>
data MarkState = Mark | NoMark deriving (Eq,Show)
marked :: MarkState -> Bool
</ProgramListing>
MarkState is similar to Bool but it shows whether the <literal>CheckControl</literal> is marked.
</para>
<para>
<ProgramListing>
class Toggle a where
toggle :: a -> a
</ProgramListing>
<Function>toggle</Function> is a polimorphic version of <Function>not</Function>. There are
<ProgramListing>
instance Toggle Bool -- toggle b = not b
instance Toggle SelectState
instance Toggle MarkState
</ProgramListing>
</para>
<para>
Other type classes
<ProgramListing>
class Zero a where
zero :: a
class One a where
one :: a
</ProgramListing>
There are instances for Zero and One for some of the following types.
</para>
<para>
<ProgramListing>
type Index = Int
type Title = String
</ProgramListing>
</para>
<para>
<ProgramListing>
data Vector2 = Vector2 {vx :: !Int, vy :: !Int}
deriving (Eq,Show)
instance Zero Vector2 where
instance Num Vector2 where
</ProgramListing>
<emphasis>Note</emphasis> that (*), abs, signum and fromInteger members of Num instance are undefined!!
</para>
<para>
<ProgramListing>
class ToVector x where
toVector :: x -> Vector2
</ProgramListing>
ToVector allow coercion between Vector2 and Size and Point2 types.
</para>
<ProgramListing>
data Size = Size {w :: !Int, h :: !Int}
deriving (Eq,Show)
instance Zero Size where -- {w=0,h=0}
instance ToVector Size where -- {w,h}->{vx=w,vy=h}
</ProgramListing>
<para>
<ProgramListing>
data Point2 = Point2 {x :: !Int, y :: !Int}
deriving (Eq,Show)
instance Zero Point2 where
instance Num Point2 where
instance ToVector Point2 where
</ProgramListing>
<emphasis>Note</emphasis> that (*), abs, signum and fromInteger members of Num instance are undefined!!
</para>
<para>
<ProgramListing>
data Rectangle = Rectangle {corner1 :: !Point2, corner2 :: !Point2}
deriving (Eq,Show)
instance Zero Rectangle where
</ProgramListing>
</para>
<para>
<ProgramListing>
rectangleSize :: Rectangle -> Size -- {w=abs (@1.corner1-@1.corner2).x,
-- h=abs (@1.corner1-@1.corner2).y}
movePoint :: Vector2 -> Point2 -> Point2 -- {vx,vy} {x,y} -> {vx+x,vy+y}
</ProgramListing>
</para>
<para>
<ProgramListing>
data KeyboardState
= CharKey Char KeyState -- ASCII character input
| SpecialKey SpecialKey KeyState Modifiers -- Special key input
| KeyLost -- Key input lost while key was down
deriving (Eq,Show)
data KeyState
= KeyDown IsRepeatKey -- Key is down
| KeyUp -- Key goes up
deriving (Eq,Show)
type IsRepeatKey -- Flag on key down:
= Bool -- True iff key is repeating
data Key
= IsCharKey Char
| IsSpecialKey SpecialKey
</ProgramListing>
KeyboardState is passed to keyboard handler for every keyboard event.
</para>
<para>
<ProgramListing>
getKeyboardStateKeyState:: KeyboardState -> KeyState
</ProgramListing>
getKeyboardStateKeyState gets KeyState from KeyboardState (KeyUp if KeyboardState is KeyLost)
<ProgramListing>
getKeyboardStateKey :: KeyboardState -> Maybe Key
</ProgramListing>
getKeyboardStateKey gets Key value from KeyboardState (Nothing if KeyboardState is KeyLost)
</para>
<para>
<ProgramListing>
data MouseState
= MouseMove Point2 Modifiers -- Mouse is up (position,modifiers)
| MouseDown Point2 Modifiers Int -- Mouse goes down (and nr down)
| MouseDrag Point2 Modifiers -- Mouse is down (position,modifiers)
| MouseUp Point2 Modifiers -- Mouse goes up (position,modifiers)
| MouseLost -- Mouse input lost while mouse was down
deriving (Eq, Show)
data ButtonState
= ButtonStillUp -- MouseMove
| ButtonDown -- MouseDown _ _ 1
| ButtonDoubleDown -- _ _ 2
| ButtonTripleDown -- _ _ >2
| ButtonStillDown -- MouseDrag
| ButtonUp -- MouseUp/MouseLost
deriving (Eq, Show)
type MouseStateFilter = -- Predicate on MouseState:
MouseState -> Bool -- evaluate MouseFunction only if True
</ProgramListing>
</para>
<para>
<ProgramListing>
getMouseStatePos :: MouseState -> Point2
getMouseStateModifiers :: MouseState -> Modifiers
getMouseStateButtonState:: MouseState -> ButtonState
</ProgramListing>
</para>
<para>
<ProgramListing>
data SliderState
= SliderState
{ sliderMin :: !Int
, sliderMax :: !Int
, sliderThumb :: !Int
}
deriving (Eq, Show)
</ProgramListing>
</para>
<para>
<ProgramListing>
data UpdateState
= UpdateState
{ oldFrame :: !ViewFrame
, newFrame :: !ViewFrame
, updArea :: !UpdateArea
}
deriving (Show)
type ViewDomain = Rectangle
type ViewFrame = Rectangle
type UpdateArea = [ViewFrame]
</ProgramListing>
</para>
<para>
<ProgramListing>
rectangleToUpdateState :: Rectangle -> UpdateState
</ProgramListing>
</para>
<para>
<ProgramListing>
viewDomainRange :: ViewDomain
viewFrameRange :: ViewFrame
</ProgramListing>
viewDomainRange and viewFrameRange define the minimum and maximum values
for ViewDomains and ViewFrames.
</para>
<para>
<ProgramListing>
data Modifiers
= Modifiers
{ shiftDown :: !Bool -- True iff shift down
, optionDown :: !Bool -- True iff option down
, commandDown :: !Bool -- True iff command down
, controlDown :: !Bool -- True iff control down
, altDown :: !Bool -- True iff alt down
}
deriving (Eq,Show)
</ProgramListing>
Modifiers indicates the meta keys that have been pressed (True) or not (False).
</para>
<para>
<ProgramListing>
noModifiers, shiftOnly, optionOnly, commandOnly, controlOnly, altOnly :: Modifiers
</ProgramListing>
These are constants that check which of the Modifiers are pressed.
</para>
<para>
The layout language used for windows and controls.
<ProgramListing>
type ItemPos
= ( ItemLoc
, ItemOffset
)
data ItemLoc
-- Absolute:
= Fix
-- Relative to corner:
| LeftTop
| RightTop
| LeftBottom
| RightBottom
-- Relative in next line:
| Left
| Center
| Right
-- Relative to other item:
| LeftOf Id
| RightTo Id
| Above Id
| Below Id
-- Relative to previous item:
| LeftOfPrev
| RightToPrev
| AbovePrev
| BelowPrev
deriving (Eq,Show)
type ItemOffset = Vector2 -- A constant offset vector
</ProgramListing>
</para>
<para>
The Direction type.
<ProgramListing>
data Direction
= Horizontal
| Vertical
deriving Eq
</ProgramListing>
</para>
<para>
The CursorShape type.
<ProgramListing>
data CursorShape
= StandardCursor
| BusyCursor
| IBeamCursor
| CrossCursor
| FatCrossCursor
| ArrowCursor
| HiddenCursor
deriving Eq
</ProgramListing>
</para>
<para>
Document interface of interactive processes.
<ProgramListing>
data DocumentInterface
= NDI -- No Document Interface
| SDI -- Single Document Interface
| MDI -- Multiple Document Interface
deriving (Eq,Show)
</ProgramListing>
</para>
<para>
<ProgramListing>
data SliderMove
= SliderIncSmall
| SliderDecSmall
| SliderIncLarge
| SliderDecLarge
| SliderThumb Int
deriving Show
</ProgramListing>
</para>
<para>
Common error report types. See throwGUI
<ProgramListing>
data ErrorReport -- Usual cause:
= ErrorViolateDI -- Violation against DocumentInterface
| ErrorIdsInUse -- Object contains Ids that are bound
| ErrorUnknownObject -- Object can not be found
| ErrorNotifierOpen -- It was tried to open a second send notifier
| ErrorUnableReceiver
| ErrorDeadlock
| OtherError !String -- Other kind of error
deriving (Eq,Show)
handleErrorReport :: Monad m => ErrorReport -> m a
</ProgramListing>
<Function>handleErrorReport</Function> is a help function that just calls <Function>fail</Function> with an appropriate error message.
It can be used with <Function>catchGUI</Function>. Example:
<ProgramListing>
test1 :: GUI ps x
test1 = . . .
test :: GUI ps x
test = catchGUI test1 handleErrorReport
</ProgramListing>
<emphasis>Note:</emphasis> The Scheduler calls all object callbacks in that way.
</para>
<para>
Monad extensions
<ProgramListing>
class Monad m => IOMonad m where
liftIO :: IO a -> m a
instance IOMonad IO where
liftIO f = f
</ProgramListing>
<literal>IOMonad</literal> class is a simply way to call <literal>IO</literal> monads from other <literal>IO</literal>-like monads.
</para>
</Sect1>
<Sect1 id="sec-ObjectIO-StdGUI">
<Title>StdGUI
<IndexTerm><Primary>GUI monad</Primary></IndexTerm>
</Title>
<para>
This module provides declaration of abstract <literal>GUI monad</literal>.
</para>
<ProgramListing>
data GUI ps x
type GUIFun ls ps = (ls,ps) -> GUI ps (ls,ps)
type GUI2Fun ps = ps -> GUI ps ps
</ProgramListing>
<para>
where ps is a type of local process state. GUIFun and GUI2Fun are
additional types which describe state transforming GUI actions,
first with both local and process state and second only with process state.
There are instances of Monad, IOMonad and Functor type classes.
<ProgramListing>
instance Monad (GUI ps)
instance IOMonad (GUI ps)
instance Functor (GUI ps)
</ProgramListing>
Each object event handler must be GUI monad action, usually of GUIFun or GUI2Fun type.
</para>
</Sect1>
<Sect1 id="sec-ObjectIO-StdId">
<Title>StdId
<IndexTerm><Primary>Ids</Primary></IndexTerm>
</Title>
<para>
Id generation routines.
<ProgramListing>
openId :: Ids m => m Id
openIds :: Ids m => Int -> m [Id]
openR2Id :: Ids m => m (R2Id m r)
openR2Ids :: Ids m => Int -> m (R2Id m r)
openRId :: Ids m => m (RId x)
openRIds :: Ids m => Int -> m [RId x]
</ProgramListing>
There is <Literal>Ids</Literal> type class, which allows the functions to be called both
from <Literal>IO</Literal> and <Literal>GUI</Literal> monad.
</para>
<para>
<Function>openId</Function> returns one new id
</para>
<para>
<Function>openIds</Function> returns a list of N items i.e. [id<Subscript>1</Subscript>, id<Subscript>2</Subscript>..id<Subscript>N</Subscript>]
<ProgramListing>
openIds 3 = [id<Subscript>1</Subscript>, id<Subscript>2</Subscript>, id<Subscript>3</Subscript>]
</ProgramListing>
</para>
<para>
<Function>openRId</Function>, <Function>openRIds</Function>, <Function>openR2Id</Function> and <Function>openR2Ids</Function> are the same as openId and openIds but they return
special receiver and bi-receiver ids (see <XRef LinkEnd="sec-ObjectIO-StdReceiver">).
</para>
</Sect1>
<Sect1 id="sec-ObjectIO-StdWindow">
<Title>StdWindow
<IndexTerm><Primary>Windows</Primary></IndexTerm>
</Title>
<para>In the Object I/O library there are two main window types:</para>
<variablelist>
<varlistentry>
<term><literal>data Dialog c ls ps = Dialog Title (c ls ps) [WindowAttribute ls ps]</literal></term>
<listitem>
<para>The dialogs are nonresizable modal or nonmodal windows. They adjust their size to the common size
of the contained controls. They usually have two special buttons called <Literal>Ok</Literal> and
<Literal>Cancel</Literal>. When the user presses Enter or Esc keys, the dialog interprets this event as
clicking on <Literal>Ok</Literal> or <Literal>Cancel</Literal>.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>data Window c ls ps = Window Title (c ls ps) [WindowAttribute ls ps]</literal></term>
<listitem>
<para>The windows are resizable and one can draw in the view domain.This can be programmed as a Haskell's function.
They also can have vertical and horizontal scroll bars, which extend logical view frame of the windows.</para>
</listitem>
</varlistentry>
</variablelist>
<para>Both windows and dialogs can contain various kinds of controls but they can't contain other windows or dialogs.
The type variable <Literal>c</Literal> mentioned above corresponds to the type of the containing controls.</para>
<para>The type variables <Literal>ls</Literal> and <Literal>ps</Literal> as usual define local state and process state types.</para>
<para>
<Literal>WindowAttribute</Literal> defines a set of built-in window attributes.
<ProgramListing>
data WindowAttribute ls ps -- Default:
-- Attributes for Windows and Dialogs:
= WindowActivate (GUIFun ls ps) -- id
| WindowClose (GUIFun ls ps) -- user can't close window
| WindowDeactivate (GUIFun ls ps) -- id
| WindowHMargin Int Int -- system dependent
| WindowId Id -- system defined id
| WindowIndex Int -- open front-most
| WindowInit (GUIFun ls ps) -- no actions after opening window
| WindowInitActive Id -- system dependent
| WindowItemSpace Int Int -- system dependent
| WindowOuterSize Size -- screen size
| WindowPos ItemPos -- system dependent
| WindowViewSize Size -- screen size
| WindowVMargin Int Int -- system dependent
-- Attributes for Dialog only:
| WindowCancel Id -- no cancel (Custom)ButtonControl
| WindowOk Id -- no default (Custom)ButtonControl
-- Attributes for Windows only:
| WindowCursor CursorShape -- no change of cursor
| WindowHScroll ScrollFunction -- no horizontal scrolling
| WindowKeyboard KeyboardStateFilter SelectState (KeyboardFunction ls ps) -- no keyboard input
| WindowLook Bool Look -- show system dependent background
| WindowMouse MouseStateFilter SelectState (MouseFunction ls ps) -- no mouse input
| WindowOrigin Point2 -- left top of picture domain
| WindowPen [PenAttribute] -- default pen attributes
| WindowSelectState SelectState -- Able
| WindowViewDomain ViewDomain -- {zero,max range}
| WindowVScroll ScrollFunction -- no vertical scrolling
</ProgramListing>
</para>
<Sect2 id="sec-ObjectIO-StdWindow-WindowCreation">
<Title>Windows creation.</Title>
<para>If the user wants to define his/her own window types, there are polymorphic creation functions.</para>
<ProgramListing>
class Windows wdef where
openWindow :: ls -> wdef ls ps -> ps -> GUI ps ps
class Dialogs ddef where
openDialog :: ls -> ddef ls ps -> ps -> GUI ps ps
openModalDialog :: ls -> ddef ls ps -> ps -> GUI ps (ps, (Maybe ls))
</ProgramListing>
<para>The user must define instances of Windows or Dialogs classes for his/her own window or dialog types.
Built-in types have instances defined as:</para>
<ProgramListing>
instance Controls c => Dialog (Dialog c)
instance Controls c => Window (Window c)
</ProgramListing>
<para>where <Literal>Controls</Literal> type class has instances for all types of controls.</para>
</Sect2>
<Sect2 id="sec-ObjectIO-StdWindow-WindowDispose">
<Title>Windows closing.</Title>
<ProgramListing>
closeWindow :: Id -> GUI2Fun ps
closeActiveWindow :: GUI2Fun ps
</ProgramListing>
<variablelist>
<varlistentry>
<term><literal>closeWindow</literal></term>
<listitem>
<para>closes window with specified Id</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>closeActiveWindow</literal></term>
<listitem>
<para>closes active window. Often we can use <Literal>closeActiveWindow</Literal> together with WindowClose attribute.
For example adding <ProgramListing>WindowClose (noLS closeActiveWindow)</ProgramListing> to the window attributes list
closes the window when the user clicks the close button.
</para>
</listitem>
</varlistentry>
</variablelist>
</Sect2>
<Sect2 id="sec-ObjectIO-StdWindow-ActiveWindow">
<Title>Getting and setting active window</Title>
<ProgramListing>
setActiveWindow :: Id -> GUI ps ()
getActiveWindow :: GUI ps (Maybe Id)
</ProgramListing>
<variablelist>
<varlistentry>
<term><literal>setActiveWindow</literal></term>
<listitem>
<para>activates window with specified Id</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>getActiveWindow</literal></term>
<listitem>
<para>returns Id of active window if it exists.</para>
</listitem>
</varlistentry>
</variablelist>
</Sect2>
<Sect2 id="sec-ObjectIO-StdWindow-ActiveControl">
<Title>Getting and setting active control inside a window</Title>
<ProgramListing>
setActiveControl :: Id -> GUI ps ()
getActiveControl :: GUI ps (Maybe Id)
</ProgramListing>
<variablelist>
<varlistentry>
<term><literal>setActiveControl</literal></term>
<listitem>
<para>activates control with specified Id.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>getActiveControl</literal></term>
<listitem>
<para>returns Id of active control if it exists.</para>
</listitem>
</varlistentry>
</variablelist>
</Sect2>
<Sect2 id="sec-ObjectIO-StdWindow-StackOrder">
<Title>Stacking order</Title>
<ProgramListing>
stackWindow :: Id -> Id -> GUI ps ()
getWindowStack :: GUI ps [(Id,WindowKind)]
getWindowsStack :: GUI ps [Id]
getDialogsStack :: GUI ps [Id]
</ProgramListing>
<variablelist>
<varlistentry>
<term><literal>stackWindow</literal></term>
<listitem>
<para><Literal>stackWindow id1 id2</Literal> stacking window with id1 before window with id2.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>getWindowStack</literal></term>
<listitem>
<para>returns list of window and dialog ids in stacking order.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>getWindowsStack</literal></term>
<listitem>
<para>returns list of window ids in stacking order.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>getDialogsStack</literal></term>
<listitem>
<para>returns list of dialog ids in stacking order.</para>
</listitem>
</varlistentry>
</variablelist>
</Sect2>
<Sect2 id="sec-ObjectIO-StdWindow-Margins">
<Title>Window margins</Title>
<para>Getting values of default horizontal and vertical window margins and control item space</para>
<ProgramListing>
getDefaultHMargin :: Bool -> GUI ps Int
getDefaultVMargin :: Bool -> GUI ps Int
getDefaultItemSpace :: GUI ps (Int,Int)
</ProgramListing>
<para>Getting values of current horizontal and vertical window margins and control item space</para>
<ProgramListing>
getWindowHMargin :: Id -> GUI ps (Maybe (Int,Int))
getWindowVMargin :: Id -> GUI ps (Maybe (Int,Int))
getWindowItemSpace :: Id -> GUI ps (Maybe (Int,Int))
</ProgramListing>
<para>Current values are defined with <Literal>WindowHMargin</Literal>, <Literal>WindowVMargin</Literal>, <Literal>WindowItemSpace</Literal></para>
</Sect2>
<Sect2 id="sec-ObjectIO-StdWindow-EnableDisable">
<Title>Enable/Disable Window, Keyboard and Mouse</Title>
<para>The following functions correspond to WindowSelectState attribute</para>
<ProgramListing>
enableWindow :: Id -> GUI ps ()
disableWindow :: Id -> GUI ps ()
getWindowSelectState :: Id -> GUI ps (Maybe SelectState)
</ProgramListing>
<variablelist>
<varlistentry>
<term><literal>enableWindow</literal></term>
<listitem>
<para>enables window with specified Id</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>disableWindow</literal></term>
<listitem>
<para>disables window with specified Id</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>getWindowSelectState</literal></term>
<listitem>
<para>returns current select state</para>
</listitem>
</varlistentry>
</variablelist>
<para>The following functions correspond to WindowMouse attribute</para>
<ProgramListing>
enableWindowMouse :: Id -> GUI ps ()
disableWindowMouse :: Id -> GUI ps ()
setWindowMouseSelectState :: SelectState -> Id -> GUI ps ()
getWindowMouseSelectState :: Id -> GUI ps (Maybe SelectState)
getWindowMouseStateFilter :: Id -> GUI ps (Maybe MouseStateFilter)
setWindowMouseStateFilter :: Id -> MouseStateFilter -> GUI ps ()
</ProgramListing>
<variablelist>
<varlistentry>
<term><literal>setWindowMouseSelectState</literal></term>
<listitem>
<para>set current select state for mouse events</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>enableWindowMouse</literal></term>
<listitem>
<para>enables receiving mouse events for a window with a specified Id
<ProgramListing>enableWindowMouse = setWindowMouseSelectState Able</ProgramListing>
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>disableWindowMouse</literal></term>
<listitem>
<para>disables receiving mouse events for a window with a specified Id
<ProgramListing>disableWindowMouse = setWindowMouseSelectState Unable</ProgramListing>
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>getWindowSelectState</literal></term>
<listitem>
<para>returns current mouse select state</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>getWindowMouseStateFilter</literal>, <literal>setWindowMouseStateFilter</literal></term>
<listitem>
<para>Receiving mouse event can be additionally disabled with specified MouseStateFilter</para>
</listitem>
</varlistentry>
</variablelist>
<para>The following functions correspond to WindowKeyboard attribute</para>
<ProgramListing>
enableWindowKeyboard :: Id -> GUI ps ()
disableWindowKeyboard :: Id -> GUI ps ()
setWindowKeyboardSelectState :: SelectState -> Id -> GUI ps ()
getWindowKeyboardSelectState :: Id -> GUI ps (Maybe SelectState)
getWindowKeyboardStateFilter :: Id -> GUI ps (Maybe KeyboardStateFilter)
setWindowKeyboardStateFilter :: Id -> KeyboardStateFilter -> GUI ps ()
</ProgramListing>
<variablelist>
<varlistentry>
<term><literal>setWindowKeyboardSelectState</literal></term>
<listitem>
<para>sets current select state for keyboard events</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>enableWindowKeyboard</literal></term>
<listitem>
<para>enables receiving keyboard events for a window with a specified Id
<ProgramListing>enableWindowKeyboard = setWindowKeyboardSelectState Able</ProgramListing>
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>disableWindowKeyboard</literal></term>
<listitem>
<para>disables receiving keyboard events for a window with a specified Id
<ProgramListing>disableWindowKeyboard = setWindowKeyboardSelectState Unable</ProgramListing>
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>getWindowKeyboard</literal></term>
<listitem>
<para>returns current keyboard select state</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>getWindowKeyboardStateFilter</literal>, <literal>setWindowKeyboardStateFilter</literal></term>
<listitem>
<para>Receiving of keyboard event can be additionally disabled with specified KeyboardStateFilter</para>
</listitem>
</varlistentry>
</variablelist>
</Sect2>
<Sect2 id="sec-ObjectIO-StdWindow-Drawing">
<Title>Drawing</Title>
<para>Every window can have its own WindowLook attribute, which describes its Look function. The Look is defined as
the type <literal>SelectState -> UpdateState -> Draw ()</literal> and this function is called every time when the window
needs to be redrawn</para>
<para>The current look can be accessed by the following functions:</para>
<ProgramListing>
setWindowLook :: Id -> Bool -> (Bool,Look) -> GUI ps ()
getWindowLook :: Id -> GUI ps (Maybe (Bool,Look))
</ProgramListing>
<para>Use <Function>updateWindow</Function> to force window redrawing</para>
<ProgramListing>
updateWindow :: Id -> Maybe ViewFrame -> GUI ps ()
</ProgramListing>
<para>We can also draw directly in the window with <Function>drawInWindow</Function> function but in this case
everything displayed with <Function>drawInWindow</Function> will be erased after the next updateWindow call.</para>
<ProgramListing>
drawInWindow :: Id -> Draw x -> GUI ps (Maybe x)
</ProgramListing>
<para>See <XRef LinkEnd="sec-ObjectIO-StdPicture"> for details about drawing.</para>
</Sect2>
<Sect2 id="sec-ObjectIO-StdWindow-PosSize">
<Title>Window positioning and window resizing</Title>
<ProgramListing>
setWindowPos :: Id -> ItemPos -> GUI ps ()
getWindowPos :: Id -> GUI ps (Maybe Vector2)
</ProgramListing>
<variablelist>
<varlistentry>
<term><literal>setWindowPos</literal></term>
<listitem>
<para>positions the specified window to a given position</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>getWindowPos</literal></term>
<listitem>
<para>returns current window position</para>
</listitem>
</varlistentry>
</variablelist>
<ProgramListing>
moveWindowViewFrame :: Id -> Vector2 -> GUI ps ()
getWindowViewFrame :: Id -> GUI ps ViewFrame
</ProgramListing>
<para><Literal>ViewFrame</Literal> is the current visible <Literal>Rectangle</Literal> of the window. When there are horizontal
and vertical scroll bars, then the changing of the scroller thumb changes the ViewFrame.<Literal>getWindowViewFrame</Literal>
returns the current ViewFrame and <Literal>moveWindowViewFrame</Literal> moves it through the specified vector.</para>
<ProgramListing>
setWindowViewSize :: Id -> Size -> GUI ps ()
getWindowViewSize :: Id -> GUI ps Size
</ProgramListing>
<para><Literal>ViewSize</Literal> is the current inner size of the window (It doesn't include the title bar and the scrollers' area). The above functions get/set the current ViewSize value.</para>
<ProgramListing>
setWindowOuterSize :: Id -> Size -> GUI ps ()
getWindowOuterSize :: Id -> GUI ps Size
</ProgramListing>
<para><Literal>OuterSize</Literal> is the current full window size. The above functions get/set the current OuterSize value.</para>
<ProgramListing>
setWindowViewDomain :: Id -> ViewDomain -> GUI ps ()
getWindowViewDomain :: Id -> GUI ps (Maybe ViewDomain)
</ProgramListing>
<para><Literal>ViewDomain</Literal> is a <Literal>Rectangle</Literal> which specifies the logical drawing area of the window. The above functions get/set the current ViewDomain value.</para>
</Sect2>
<Sect2 id="sec-ObjectIO-StdWindow-ScrollFunctions">
<Title>Windows scrolling</Title>
<ProgramListing>
setWindowScrollFunction :: Id -> Direction -> ScrollFunction -> GUI ps ()
getWindowScrollFunction :: Id -> Direction -> GUI ps (Maybe ScrollFunction)
</ProgramListing>
<para>The ScrollFunction describes the behaviour of the horizontal or vertical (according to <literal>Direction</literal> parameter) scroll bars.
The ScrollFunction calculates the step by which ViewFrame is moved inside the ViewDomain.</para>
</Sect2>
<Sect2 id="sec-ObjectIO-StdWindow-Cursor">
<Title>Mouse cursor</Title>
<ProgramListing>
setWindowCursor :: Id -> CursorShape -> GUI ps ()
getWindowCursor :: Id -> GUI ps (Maybe CursorShape)
</ProgramListing>
<para>The <Literal>CursorShape</Literal> describes the shape of the mouse cursor when it is over the window.</para>
</Sect2>
<Sect2 id="sec-ObjectIO-StdWindow-Title">
<Title>Window title</Title>
<ProgramListing>
setWindowTitle :: Id -> Title -> GUI ps ()
getWindowTitle :: Id -> GUI ps (Maybe Title)
</ProgramListing>
<para><Literal>Title</Literal> is a string, which is displayed at the top of the window. The title can also be defined with the WindowTitle attribute.</para>
</Sect2>
<Sect2 id="sec-ObjectIO-StdWindow-OkCancel">
<Title>Dialogs: Ok and Cancel buttons</Title>
<ProgramListing>
getWindowOk :: Id -> GUI ps (Maybe Id)
getWindowCancel :: Id -> GUI ps (Maybe Id)
</ProgramListing>
<para>The above functions return Ids of Ok and Cancel buttons of the specified dialog. These Ids must be
defined with WindowOk and WindowCancel attributes.</para>
</Sect2>
</Sect1>
<Sect1 id="sec-ObjectIO-StdControl">
<Title>StdControl
<IndexTerm><Primary>Controls</Primary></IndexTerm>
</Title>
<para>Object I/O library supports various kinds of built-in controls which can be placed inside windows and dialogs.
In order to define his/her own type controls, the user should give an instance of Controls class (see <XRef LinkEnd="sec-ObjectIO-StdWindow-WindowCreation">)</para>
<ProgramListing>
class Controls cdef where
controlToHandles :: cdef ls ps -> GUI ps [ControlState ls ps]
instance Controls c => Controls (AddLS c)
instance Controls c => Controls (NewLS c)
instance Controls c => Controls (ListLS c)
instance Controls NilLS
instance (Controls c1,Controls c2) => Controls (TupLS c1 c2)
</ProgramListing>
<para>For every user defined control we must have instance of <Literal>Controls</Literal> class. Controls can be
combined with <Literal>:+:</Literal> (<Literal>TupLS</Literal> type) and ListLS constructors. With AddLS and NewLS
we can extend or change the local state of a given group of controls. NilLS specifies empty control.</para>
<para>Controls can be dynamically added to an existing window with <Literal>openControls</Literal> function.</para>
<ProgramListing>
openControls :: Controls cdef => Id -> ls -> cdef ls ps -> GUI ps ()
</ProgramListing>
<Sect2 id="sec-ObjectIO-StdControl-Common">
<Title>Common</Title>
<para>Control attributes</para>
<ProgramListing>
data ControlAttribute ls ps -- Default:
-- General control attributes:
= ControlActivate (GUIFun ls ps) -- return
| ControlDeactivate (GUIFun ls ps) -- return
| ControlFunction (GUIFun ls ps) -- (\st->return st)
| ControlHide -- initially visible
| ControlId Id -- no id
| ControlKeyboard KeyboardStateFilter SelectState (KeyboardFunction ls ps)
-- no keyboard input/overruled
| ControlMinimumSize Size -- zero
| ControlModsFunction (ModifiersFunction ls ps)
-- ControlFunction
| ControlMouse MouseStateFilter SelectState (MouseFunction ls ps)
-- no mouse input/overruled
| ControlPen [PenAttribute] -- default pen attributes
| ControlPos ItemPos -- (RightTo previous,zero)
| ControlResize ControlResizeFunction -- no resize
| ControlSelectState SelectState -- control Able
| ControlTip String -- no tip
| ControlWidth ControlWidth -- system derived
-- For CompoundControls only:
| ControlHMargin Int Int -- system dependent
| ControlHScroll ScrollFunction -- no horizontal scrolling
| ControlItemSpace Int Int -- system dependent
| ControlLook Bool Look -- control is transparant
| ControlOrigin Point2 -- Left top of ViewDomain
| ControlOuterSize Size -- enclose elements
| ControlViewDomain ViewDomain -- {zero,max range}
| ControlViewSize Size -- enclose elements
| ControlVMargin Int Int -- system dependent
| ControlVScroll ScrollFunction -- no vertical scrolling
type ControlResizeFunction =
Size -> -- current control outer size
Size -> -- old parent view size
Size -> -- new parent view size
Size -- new control outer size
data RowsOrColumns
= Rows Int
| Columns Int
data ControlWidth -- The width of the control:
= PixelWidth Int -- the exact number of pixels
| TextWidth String -- the exact string width in dialog font
| ContentWidth String -- width of the control as if string is its content
</ProgramListing>
<Sect3 id = "sec-StdControl-Utils">
<Title>Utils</Title>
<ProgramListing>
getParentWindowId :: Id -> GUI ps (Maybe Id)
controlSize :: (Controls cdef) => cdef ls ps -> Bool -> Maybe (Int,Int) -> Maybe (Int,Int) -> Maybe (Int,Int) -> GUI ps Size
</ProgramListing>
<variablelist>
<varlistentry>
<term><literal>getParentWindowId</literal></term>
<listitem>
<para>returns id of parent window of control with specified Id</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>controlSize</literal></term>
<listitem>
<para>giving horizontal and vertical margins and item spaces calculates the size of the given control.
<ProgramListing>theSize <- controlSize (ButtonControl "Ok" []) isWindow (Just (left, right)) (Just (top, bottom)) (Just (horz,vert))</ProgramListing>
</para>
</listitem>
</varlistentry>
</variablelist>
</Sect3>
<Sect3 id = "sec-StdControl-ShowState">
<Title>Show/Hide controls</Title>
<ProgramListing>
showControls :: [Id] -> GUI ps ()
showControl :: Id -> GUI ps ()
hideControls :: [Id] -> GUI ps ()
hideControl :: Id -> GUI ps ()
setControlsShowState :: Bool -> [Id] -> GUI ps ()
getControlShowStates :: [Id] -> GUI ps [(Bool,Bool)]
getControlShowState :: Id -> GUI ps (Bool,Bool)
</ProgramListing>
<variablelist>
<varlistentry>
<term><literal>showControls</literal>,<literal>showControl</literal></term>
<listitem>
<para>shows a given control or a set of controls</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>hideControls</literal>,<literal>hideControl</literal></term>
<listitem>
<para>hides a given control or a set of controls</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>setControlsShowState</literal></term>
<listitem>
<para>shows or hides a given set of controls according to the given boolean parameter</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>getControlShowStates</literal>,<literal>getControlShowState</literal></term>
<listitem>
<para>returns current show state of the given control or set of controls</para>
</listitem>
</varlistentry>
</variablelist>
</Sect3>
<Sect3 id = "sec-StdControl-SelectState">
<Title>Enabling/Disabling of controls</Title>
<ProgramListing>
enableControls :: [Id] -> GUI ps ()
enableControl :: Id -> GUI ps ()
disableControls :: [Id] -> GUI ps ()
disableControl :: Id -> GUI ps ()
getControlSelectStates :: [Id] -> GUI ps [(Bool,SelectState)]
getControlSelectState :: Id -> GUI ps (Bool,SelectState)
</ProgramListing>
<variablelist>
<varlistentry>
<term><literal>enableControls</literal>,<literal>enableControl</literal></term>
<listitem>
<para>enables given control or set of controls</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>disableControls</literal>,<literal>disableControl</literal></term>
<listitem>
<para>disables given control or set of controls</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>getControlSelectStates</literal>,<literal>getControlSelectState</literal></term>
<listitem>
<para>returns current select state of given control or set of controls</para>
</listitem>
</varlistentry>
</variablelist>
</Sect3>
<Sect3 id = "sec-StdControl-ControlText">
<Title>Getting and setting text of EditControl, TextControl and ButtonControl</Title>
<ProgramListing>
setControlTexts :: [(Id,String)] -> GUI ps ()
setControlText :: Id -> String -> GUI ps ()
getControlTexts :: [Id] -> GUI ps [(Bool,Maybe String)]
getControlText :: Id -> GUI ps (Bool,Maybe String)
</ProgramListing>
<variablelist>
<varlistentry>
<term><literal>setControlTexts</literal>, <literal>setControlText</literal></term>
<listitem>
<para>Change the text of given control or set of controls.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>getControlTexts</literal>, <literal>getControlText</literal></term>
<listitem>
<para>returns the text of given control or set of controls.</para>
</listitem>
</varlistentry>
</variablelist>
</Sect3>
<Sect3 id="sec-StdControl-Drawing">
<Title>Drawing in CustomControl, CustomButtonControl and CompoundControl</Title>
<ProgramListing>
drawInControl :: Id -> Draw x -> GUI ps (Maybe x)
updateControl :: Id -> Maybe ViewFrame -> GUI ps ()
setControlLooks :: [(Id,Bool,(Bool,Look))] -> GUI ps ()
setControlLook :: Id -> Bool -> (Bool,Look) -> GUI ps ()
getControlLooks :: [Id] -> GUI ps [(Bool,Maybe (Bool,Look))]
getControlLook :: Id -> GUI ps (Bool,Maybe (Bool,Look))
</ProgramListing>
<variablelist>
<varlistentry>
<term><literal>setControlLooks</literal>, <literal>setControlLook</literal></term>
<listitem>
<para>change the Look of the corresponding control or set of controls but redraw only if the first boolean parameter is True</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>getControlLooks</literal>, <literal>getControlLook</literal></term>
<listitem>
<para>returns current controls look</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>drawInControl</literal></term>
<listitem>
<para>direct draw in control</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>updateControl</literal></term>
<listitem>
<para>update look of control</para>
</listitem>
</varlistentry>
</variablelist>
<para>See <XRef LinkEnd="sec-ObjectIO-StdPicture"> for details about drawing.</para>
</Sect3>
<Sect3 id = "sec-StdControl-MoveSize">
<Title>Positioning and resizing of controls</Title>
<ProgramListing>
setControlPos :: Id -> [(Id,ItemPos)] -> GUI ps Bool
getControlViewSizes :: [Id] -> GUI ps [(Bool,Size)]
getControlViewSize :: Id -> GUI ps (Bool,Size)
getControlOuterSizes :: [Id] -> GUI ps [(Bool,Size)]
getControlOuterSize :: Id -> GUI ps (Bool,Size)
getControlMinimumSizes :: [Id] -> GUI ps [(Bool,Maybe Size)]
getControlMinimumSize :: Id -> GUI ps (Bool,Maybe Size)
getControlResizes :: [Id] -> GUI ps [(Bool,Maybe ControlResizeFunction)]
getControlResize :: Id -> GUI ps (Bool,Maybe ControlResizeFunction)
</ProgramListing>
<variablelist>
<varlistentry>
<term><literal>setControlPos</literal></term>
<listitem>
<para>repositions control to given position</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>getControlViewSizes</literal>, <literal>getControlViewSize</literal></term>
<listitem>
<para>returns current view size</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>getControlOuterSizes</literal>, <literal>getControlOuterSize</literal></term>
<listitem>
<para>returns current view size including the size of border</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>getControlMinimumSizes</literal>, <literal>getControlMinimumSize</literal></term>
<listitem>
<para>returns the minimal valid size when resizing</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>getControlResizes</literal>, <literal>getControlResize</literal></term>
<listitem>
<para>returns the control resizing function. When the parent window of a given control is resized, then the control
can be resized if it has a resize function.</para>
</listitem>
</varlistentry>
</variablelist>
</Sect3>
</Sect2>
<Sect2 id="sec-ObjectIO-StdControl-Button">
<Title>ButtonControl</Title>
<para>Data definition</para>
<ProgramListing>
data ButtonControl ls ps
= ButtonControl String [ControlAttribute ls ps]
</ProgramListing>
<para><XRef LinkEnd="sec-StdControl-ControlText"> describes how to get or set the caption of a button</para>
</Sect2>
<Sect2 id="sec-ObjectIO-StdControl-Check">
<Title>CheckControl</Title>
<para>Data definition</para>
<ProgramListing>
data CheckControl ls ps
= CheckControl [CheckControlItem ps (ls,ps)] RowsOrColumns [ControlAttribute ls ps]
type CheckControlItem ps st = (String, Maybe ControlWidth, MarkState, st -> GUI ps st)
</ProgramListing>
<para>Access functions:</para>
<ProgramListing>
setControlsMarkState :: MarkState -> Id -> [Index] -> GUI ps ()
markCheckControlItems :: Id -> [Index] -> GUI ps ()
unmarkCheckControlItems :: Id -> [Index] -> GUI ps ()
getCheckControlItems :: [Id] -> GUI ps [(Bool,Maybe [String])]
getCheckControlItem :: Id -> GUI ps (Bool,Maybe [String])
getCheckControlSelections :: [Id] -> GUI ps [(Bool,Maybe [Index])]
getCheckControlSelection :: Id -> GUI ps (Bool,Maybe [Index])
</ProgramListing>
<variablelist>
<varlistentry>
<term><literal>setControlsMarkState</literal></term>
<listitem>
<para>This function is used for marking/unmarking of the check control according to the MarkState value.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>markCheckControlItems</literal></term>
<listitem>
<para>This function is used for marking of check controls.
<ProgramListing>markCheckControlItems = setControlsMarkState Mark</ProgramListing></para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>unmarkCheckControlItems</literal></term>
<listitem>
<para>This function is used for unmarking of check controls.
<ProgramListing>unmarkCheckControlItems = setControlsMarkState Unmark</ProgramListing></para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>getCheckControlItems</literal>, <literal>getCheckControlItem</literal></term>
<listitem>
<para>returns the list of items for a given control or set of controls</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>getCheckControlSelections</literal>, <literal>getCheckControlSelection</literal></term>
<listitem>
<para>returns a the list of indexes for selected items</para>
</listitem>
</varlistentry>
</variablelist>
</Sect2>
<Sect2 id="sec-ObjectIO-StdControl-Compound">
<Title>CompoundControl</Title>
<para>The compound control is a control that contains other controls. It introduces a new
layout scope like LayoutControl (see <XRef LinkEnd="sec-ObjectIO-StdControl-Layout">) but it
provides programmers with a lot more functionality. Just like the windows, the compound controls have a view domain
and can have its own Look function. If we add ControlHScroll or ControlVScroll then the control will be decorated with scroll bars.</para>
<para>Data definition</para>
<ProgramListing>
data CompoundControl c ls ps
= CompoundControl (c ls ps) [ControlAttribute ls ps]
</ProgramListing>
<para>Access functions:</para>
<ProgramListing>
getControlViewFrame :: Id -> GUI ps (Bool,Maybe ViewFrame)
getControlViewFrames :: [Id] -> GUI ps [(Bool,Maybe ViewFrame)]
moveControlViewFrame :: Id -> Vector2 -> GUI ps ()
setControlViewDomain :: Id -> ViewDomain -> GUI ps ()
getControlViewDomain :: Id -> GUI ps (Bool,Maybe ViewDomain)
getControlViewDomains :: [Id] -> GUI ps [(Bool,Maybe ViewDomain)]
setControlScrollFunction :: Id -> Direction -> ScrollFunction -> GUI ps ()
getControlScrollFunction :: Id -> GUI ps (Bool,Maybe ((Direction,Maybe ScrollFunction),(Direction,Maybe ScrollFunction)))
getControlScrollFunctions :: [Id] -> GUI ps [(Bool,Maybe ((Direction,Maybe ScrollFunction),(Direction,Maybe ScrollFunction)))]
openCompoundControls :: Controls cdef => Id -> ls -> cdef ls ps -> GUI ps ()
</ProgramListing>
<variablelist>
<varlistentry>
<term><literal>getControlViewFrames</literal>, <literal>getControlViewFrame</literal></term>
<listitem>
<para><Literal>ViewFrame</Literal> is the current visible <Literal>Rectangle</Literal> of CompoundControl.
When there are horizontal and vertical scroll bars then the changing of the scroller thumb will change the ViewFrame.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>moveControlViewFrame :: Id -> Vector2 -> GUI ps ()</literal></term>
<listitem>
<para>moves the <Literal>ViewFrame</Literal> of the CompoundControl in the direction of the given vector.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>getControlViewDomains</literal>, <literal>getControlViewDomain</literal></term>
<listitem>
<para><Literal>ViewDomain</Literal> is the <Literal>Rectangle</Literal>, which specifies the logical drawing area of the CompoundControl.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>setControlViewDomain :: Id -> ViewDomain -> GUI ps ()</literal></term>
<listitem>
<para>sets a new view domain of the CompoundControl.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>setControlScrollFunction :: Id -> Direction -> ScrollFunction -> GUI ps ()</literal></term>
<listitem>
<para>sets a new scroll function of the CompoundControl.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>getControlScrollFunction</literal>, <literal>getControlScrollFunctions</literal></term>
<listitem>
<para>getControlScrollFunction(s) yields the ScrollFunctions of the indicated CompoundControl.
If the given control is not a CompoundControl, then Nothing is returned.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>openCompoundControls :: Controls cdef => Id -> ls -> cdef ls ps -> GUI ps ()</literal></term>
<listitem>
<para><Function>openCompoundControls</Function> adds controls to the indicated CompoundControl.</para>
</listitem>
</varlistentry>
</variablelist>
<para><XRef LinkEnd="sec-StdControl-Drawing"> describes how to draw inside the CompoundControl</para>
</Sect2>
<Sect2 id="sec-ObjectIO-StdControl-CustomButton">
<Title>CustomButtonControl</Title>
<para><literal>CustomButtonControl</literal> is like the ButtonControl but has its own Look and doesn't accept the ControlTitle attribute</para>
<ProgramListing>
data CustomButtonControl ls ps
= CustomButtonControl Size Look [ControlAttribute ls ps]
</ProgramListing>
<para><XRef LinkEnd="sec-StdControl-Drawing"> describes how to draw inside the CustomButtonControl</para>
</Sect2>
<Sect2 id="sec-ObjectIO-StdControl-Custom">
<Title>CustomControl</Title>
<para><literal>CustomControl</literal> allows the programmer to design his/her own controls.</para>
<ProgramListing>
data CustomControl ls ps
= CustomControl Size Look [ControlAttribute ls ps]
</ProgramListing>
<para><XRef LinkEnd="sec-StdControl-Drawing"> describes how to draw inside the CustomControl</para>
</Sect2>
<Sect2 id="sec-ObjectIO-StdControl-Edit">
<Title>EditControl</Title>
<para>Data definition</para>
<ProgramListing>
data EditControl ls ps
= EditControl String ControlWidth NrLines [ControlAttribute ls ps]
type NrLines = Int
</ProgramListing>
<para>Access functions</para>
<ProgramListing>
setEditControlCursor :: Id -> Int -> GUI ps ()
getControlNrLines :: [Id] -> GUI ps [(Bool,Maybe NrLines)]
getControlNrLine :: Id -> GUI ps (Bool,Maybe NrLines)
</ProgramListing>
<variablelist>
<varlistentry>
<term><literal>setEditControlCursor</literal></term>
<listitem>
<para>sets the cursor position</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>getControlsNrLines</literal>, <literal>getControlNrLines</literal></term>
<listitem>
<para>returns the number of lines that can be seen (on the screen at the moment) for a given control</para>
</listitem>
</varlistentry>
</variablelist>
<para><XRef LinkEnd="sec-StdControl-ControlText"> describes how to get or set the text of an edit control</para>
</Sect2>
<Sect2 id="sec-ObjectIO-StdControl-Layout">
<Title>LayoutControl</Title>
<para>The layout control is a control that contains other controls. It introduces a new layout
scope: i.e. the controls inside it are positioned in relation to the bounds of the layout
control.</para>
<ProgramListing>
data LayoutControl c ls ps
= LayoutControl (c ls ps) [ControlAttribute ls ps]
</ProgramListing>
</Sect2>
<Sect2 id="sec-ObjectIO-StdControl-PopUp">
<Title>PopUpControl</Title>
<para>Data definition</para>
<ProgramListing>
data PopUpControl ls ps
= PopUpControl [PopUpControlItem ps (ls,ps)] Index [ControlAttribute ls ps]
type PopUpControlItem ps st = (String, st -> GUI ps st)
</ProgramListing>
<para>Access functions</para>
<ProgramListing>
openPopUpControlItems :: Id -> Index -> [PopUpControlItem ps ps] -> GUI ps ()
closePopUpControlItems :: Id -> [Index] -> GUI ps ()
selectPopUpControlItem :: Id -> Index -> GUI ps ()
getPopUpControlItems :: [Id] -> GUI ps [(Bool,Maybe [String])]
getPopUpControlItem :: Id -> GUI ps (Bool,Maybe [String])
getPopUpControlSelections :: [Id] -> GUI ps [(Bool,Maybe Index)]
getPopUpControlSelection :: Id -> GUI ps (Bool,Maybe Index)
</ProgramListing>
<variablelist>
<varlistentry>
<term><literal>openPopUpControlItems</literal></term>
<listitem>
<para><Function>openPopUpControlItems</Function> adds items to the PopUpControl.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>closePopUpControlItems</literal></term>
<listitem>
<para>deletes a string in the list box of a popup control.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>selectPopUpControlItem</literal></term>
<listitem>
<para>selects a string in the list box of a popup control. If necessary, the list box scrolls
the string into view (if the list box is visible). Any previous selection in the control is removed.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>getPopUpControlsItems</literal>, <literal>getPopUpControlItems</literal></term>
<listitem>
<para>returns a list of control items</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>getPopUpControlsSelection</literal>, <literal>getPopUpControlSelection</literal></term>
<listitem>
<para>Call this function to determine which item in the popup control is selected. It returns an index into the list.</para>
</listitem>
</varlistentry>
</variablelist>
</Sect2>
<Sect2 id="sec-ObjectIO-StdControl-Radio">
<Title>RadioControl</Title>
<para>Data definition</para>
<ProgramListing>
data RadioControl ls ps
= RadioControl [RadioControlItem ps (ls,ps)] RowsOrColumns Index [ControlAttribute ls ps]
type RadioControlItem ps st = (String, Maybe ControlWidth, st -> GUI ps st)
</ProgramListing>
<para>Access functions</para>
<ProgramListing>
selectRadioControlItem :: Id -> Index -> GUI ps ()
getRadioControlSelections :: [Id] -> GUI ps [(Bool,Maybe Index)]
getRadioControlSelection :: Id -> GUI ps (Bool,Maybe Index)
getRadioControlItems :: [Id] -> GUI ps [(Bool,Maybe [String])]
getRadioControlItem :: Id -> GUI ps (Bool,Maybe [String])
</ProgramListing>
<variablelist>
<varlistentry>
<term><literal>selectRadioControlItem</literal></term>
<listitem>
<para>sets a current selection of a radio control</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>getRadioControlSelections</literal>, <literal>getRadioControlSelection</literal></term>
<listitem>
<para>returns the current control selection</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>getRadioControlItems</literal>, <literal>getRadioControlItem</literal></term>
<listitem>
<para>returns the list of control items</para>
</listitem>
</varlistentry>
</variablelist>
</Sect2>
<Sect2 id="sec-ObjectIO-StdControl-Slider">
<Title>SliderControl</Title>
<para>Data definition</para>
<ProgramListing>
data SliderControl ls ps
= SliderControl Direction ControlWidth SliderState (SliderAction ls ps) [ControlAttribute ls ps]
</ProgramListing>
<para>Access functions</para>
<ProgramListing>
setSliderStates :: [(Id,IdFun SliderState)] -> GUI ps ()
setSliderState :: Id -> IdFun SliderState -> GUI ps ()
setSliderThumbs :: [(Id,Int)] -> GUI ps ()
setSliderThumb :: Id -> Int -> GUI ps ()
getSliderStates :: [Id] -> GUI ps [(Bool,Maybe SliderState)]
getSliderState :: Id -> GUI ps (Bool,Maybe SliderState)
getSliderDirections :: [Id] -> GUI ps [(Bool,Maybe Direction)]
getSliderDirection :: Id -> GUI ps (Bool,Maybe Direction)
</ProgramListing>
<variablelist>
<varlistentry>
<term><literal>setSliderStates</literal>, <literal>setSliderState</literal></term>
<listitem>
<para>changes the SliderState and redraws the settings of the SliderControls.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>setSliderThumbs</literal>, <literal>setSliderThumb</literal></term>
<listitem>
<para>changes the thumb values of the SliderState of SliderControl or a set of controls.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>getSliderStates</literal>, <literal>getSliderState</literal></term>
<listitem>
<para>gets a current SliderState.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>getSliderDirections</literal>, <literal>getSliderDirection</literal></term>
<listitem>
<para>gets the slider direction i. e. Horizontal or Vertical.</para>
</listitem>
</varlistentry>
</variablelist>
</Sect2>
<Sect2 id="sec-ObjectIO-StdControl-Text">
<Title>TextControl</Title>
<para>This is a simple control that just displays its caption.
In <XRef LinkEnd="sec-StdControl-ControlText"> is described how to change the caption.</para>
<ProgramListing>
data TextControl ls ps
= TextControl String [ControlAttribute ls ps]
</ProgramListing>
</Sect2>
<Sect2 id="sec-Object-StdControl-ControlClose">
<Title>Controls closing</Title>
<ProgramListing>
closeControls :: Id -> [Id] -> Bool -> GUI ps ()
closeAllControls :: Id -> GUI ps ()
</ProgramListing>
<variablelist>
<varlistentry>
<term><literal>closeControls</literal></term>
<listitem>
<para>closes the specified controls in the indicated window.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>closeAllControls</literal></term>
<listitem>
<para>closes all controls in the indicated window.</para>
</listitem>
</varlistentry>
</variablelist>
</Sect2>
</Sect1>
<Sect1 id="sec-ObjectIO-StdKey">
<Title>StdKey
<IndexTerm><Primary>StdKey</Primary></IndexTerm>
</Title>
<para>Keyboard event handlers receive KeyboardState (see <XRef LinkEnd="sec-ObjectIO-StdIOCommon"> for definition)
as a parameter. When the special key (like F1, F2, PgUp, PgDn and other) is pressed, then the KeyboardState contains
a value of <literal>SpecialKey</literal> type. Here is a list of all predefined values:</para>
<ProgramListing>
backSpaceKey, beginKey, clearKey, deleteKey, downKey, endKey, enterKey,
escapeKey, f1Key, f2Key, f3Key, f4Key, f5Key, f6Key, f7Key, f8Key,
f9Key, f10Key, f11Key, f12Key, f13Key, f14Key, f15Key, helpKey,
leftKey, pgDownKey, pgUpKey, rightKey, upKey :: SpecialKey
</ProgramListing>
</Sect1>
<Sect1 id="sec-ObjectIO-StdPicture">
<Title>StdPicture
<IndexTerm><Primary>Pictures</Primary></IndexTerm>
</Title>
<para>While drawing we need the current state called <literal>Picture</literal> state.
The functions that are used for drawing need a <literal>Picture</literal> state as an argument and return the new updated state.
The Draw monad is defined so that it would be easier for the user to write the functions.
The Draw monad is in fact an IO monad, but it also takes care of the management of the <literal>Picture</literal> state.
The definition of Draw is abstract</para>
<ProgramListing>
newtype Draw
instance Monad Draw
instance Functor Draw
instance IOMonad Draw
</ProgramListing>
<para>See <XRef LinkEnd="sec-ObjectIO-StdIOCommon"> for definition of IOMonad class.</para>
<para>There are some basic objects related to the drawing:</para>
<Sect2 id="sec-ObjectIO-StdPicture-Pen">
<Title>Pen</Title>
<ProgramListing>
data PenAttribute -- Default:
= PenSize Int -- 1
| PenPos Point2 -- zero
| PenColour Colour -- Black
| PenBack Colour -- White
| PenFont Font -- defaultFont
setPenAttributes :: [PenAttribute] -> Draw ()
getPenAttributes :: Draw [PenAttribute]
setPenPos :: Point2 -> Draw ()
getPenPos :: Draw Point2
class MovePen f where
movePenPos :: f -> Draw ()
instance MovePen Vector2
instance MovePen Curve
setPenSize :: Int -> Draw ()
getPenSize :: Draw Int
setDefaultPenSize :: Draw ()
setPenColour :: Colour -> Draw ()
getPenColour :: Draw Colour
setDefaultPenColour :: Draw ()
setPenBack :: Colour -> Draw ()
getPenBack :: Draw Colour
setDefaultPenBack :: Draw ()
setPenFont :: Font -> Draw ()
getPenFont :: Draw Font
setDefaultPenFont :: Draw ()
</ProgramListing>
<variablelist>
<varlistentry>
<term><literal>setPenPos</literal></term>
<listitem>
<para>corresponds to the PenPos attribute. The function moves the pen to the given position.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>getPenPos</literal></term>
<listitem>
<para>corresponds to the PenPos attribute. The function returns the current pen position.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>class MovePen</literal></term>
<listitem>
<para>With this class the pen position can be moved in the direction of any linear graphical object.
There is instances:
<ProgramListing>
instance MovePen Vector2
instance MovePen Oval
</ProgramListing>
where Oval is defined in <Xref LinkEnd="sec-ObjectIO-StdPicture-Drawables">.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>setPenSize</literal></term>
<listitem>
<para>corresponds to the PenSize attribute. The function sets the new pen size.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>getPenSize</literal></term>
<listitem>
<para>corresponds to the PenSize attribute. The function returns the current pen size.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>setDefaultPenSize</literal></term>
<listitem>
<para>corresponds to the PenSize attribute. The function sets the pen size to 1.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>setPenColour</literal></term>
<listitem>
<para>corresponds to the PenColour attribute. The function sets the new pen colour.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>getPenColour</literal></term>
<listitem>
<para>corresponds to the PenColour attribute. The function returns the current pen colour.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>setDefaultPenColour</literal></term>
<listitem>
<para>corresponds to the PenColour attribute. The function sets the pen colour to Black.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>setPenBack</literal></term>
<listitem>
<para>corresponds to the PenBack attribute. The function sets the new pen background colour.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>getPenBack</literal></term>
<listitem>
<para>corresponds to the PenBack attribute. The function returns the current pen background colour.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>setDefaultPenBack</literal></term>
<listitem>
<para>corresponds to the PenBack attribute. The function sets the pen background colour to White.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>setPenFont</literal></term>
<listitem>
<para>corresponds to the PenFont attribute. The function sets the new pen font.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>getPenFont</literal></term>
<listitem>
<para>corresponds to the PenFont attribute. The function returns the current pen font.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>setDefaultPenFont</literal></term>
<listitem>
<para>corresponds to the PenFont attribute. The function sets the pen font to the system dependent default font.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>setPenAttributes</literal></term>
<listitem>
<para>setups the pen attributes by a list of values.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>getPenAttributes</literal></term>
<listitem>
<para>returns the current pen attributes as a list of values.</para>
</listitem>
</varlistentry>
</variablelist>
</Sect2>
<Sect2 id="sec-ObjectIO-StdPicture-Font">
<Title>Font</Title>
<ProgramListing>
data Font -- abstract
data FontDef
= FontDef
{ fName :: !FontName -- Name of the font
, fStyles :: ![FontStyle] -- Stylistic variations
, fSize :: !FontSize -- Size in points
}
type FontName = String
type FontStyle = String
type FontSize = Int
data FontMetrics
= FontMetrics
{ fAscent :: !Int -- Distance between top and base line
, fDescent :: !Int -- Distance between bottom and base line
, fLeading :: !Int -- Distance between two text lines
, fMaxWidth :: !Int -- Max character width including spacing
}
openFont :: FontDef -> Draw (Maybe Font)
openDefaultFont :: Draw Font
openDialogFont :: Draw Font
getFontNames :: Draw [FontName]
getFontStyles :: FontName -> Draw [FontStyle]
getFontSizes :: Int -> Int -> FontName -> Draw [FontSize]
getFontDef :: Font -> FontDef
getFontCharWidth :: Font -> Char -> Draw Int
getFontCharWidths :: Font -> [Char] -> Draw [Int]
getFontStringWidth :: Font -> String -> Draw Int
getFontStringWidths :: Font -> [String] -> Draw [Int]
getFontMetrics :: Font -> Draw FontMetrics
getPenFontCharWidth :: Char -> Draw Int
getPenFontCharWidths :: [Char] -> Draw [Int]
getPenFontStringWidth :: String -> Draw Int
getPenFontStringWidths :: [String] -> Draw [Int]
getPenFontMetrics :: Draw FontMetrics
</ProgramListing>
<variablelist>
<varlistentry>
<term><literal>openFont</literal></term>
<listitem>
<para>creates a font with name, size and styles defined in the <literal>FontDef</literal> parameter.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>openDefaultFont</literal></term>
<listitem>
<para>creates the system dependent default font.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>openDialogFont</literal></term>
<listitem>
<para>creates a font with the same parameters that are used for the system font for dialogs.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>getFontNames</literal></term>
<listitem>
<para>returns a list of names for all existing fonts.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>getFontStyles</literal></term>
<listitem>
<para>returns a list of all existing styles for a given font.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>getFontSizes sizeBound1 sizeBound2</literal></term>
<listitem>
<para>returns a list of all existing sizes between sizeBound1 and sizeBound2 for a given font.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>getFontDef</literal></term>
<listitem>
<para>extracts the font definition from a given font.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>getFontCharWidth</literal>, <literal>getFontCharWidths</literal></term>
<listitem>
<para>calculates the single char width(s) for a given font</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>getFontStringWidth</literal>, <literal>getFontStringWidths</literal></term>
<listitem>
<para>calculates the string width(s) for a given font</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>getFontMetrics</literal></term>
<listitem>
<para>returns FontMetrics data for a given font</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>getPenFontCharWidth</literal>, <literal>getPenFontCharWidths</literal></term>
<listitem>
<para>calculates the single char width(s) for the active font</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>getPenFontStringWidth</literal>, <literal>getPenFontStringWidths</literal></term>
<listitem>
<para>calculates the string width(s) for the active font</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>getPenFontMetrics</literal></term>
<listitem>
<para>returns FontMetrics data for the active font</para>
</listitem>
</varlistentry>
</variablelist>
</Sect2>
<Sect2 id="sec-ObjectIO-StdPicture-Drawables">
<Title>Drawables,Fillables and Hilites</Title>
<para>Basic graphical objects such as line,circle and point are defined in the system. The user can define his/her own shape types.
There are three classes which allow user to define the graphical view of his/her shapes.</para>
<ProgramListing>
class Drawables figure where
draw :: figure -> Draw ()
drawAt :: Point2 -> figure -> Draw ()
undraw :: figure -> Draw ()
undrawAt:: Point2 -> figure -> Draw ()
class Fillables figure where
fill :: figure -> Draw ()
fillAt :: Point2 -> figure -> Draw ()
unfill :: figure -> Draw ()
unfillAt:: Point2 -> figure -> Draw ()
class Hilites figure where
hilite :: figure -> Draw ()
hiliteAt:: Point2 -> figure -> Draw ()
</ProgramListing>
<para>This is a list of all built-in shapes.</para>
<ProgramListing>
data Line2 -- A line connects two points
= Line2
{ line_end1 :: !Point2 -- The first point
, line_end2 :: !Point2 -- The second point
}
data Oval -- An oval is a stretched unit circle
= Oval
{ oval_rx :: !Int -- The horizontal radius (stretch)
, oval_ry :: !Int -- The vertical radius (stretch)
}
data Curve -- A curve is a slice of an oval
= Curve
{ curve_oval :: !Oval -- The source oval
, curve_from :: !Float -- Starting angle (in radians)
, curve_to :: !Float -- Ending angle (in radians)
, curve_clockwise :: !Bool -- Direction: True iff clockwise
}
data Box -- A box is a rectangle
= Box
{ box_w :: !Int -- The width of the box
, box_h :: !Int -- The height of the box
}
data Polygon -- A polygon is an outline shape
= Polygon
{ polygon_shape :: ![Vector2] -- The shape of the polygon
}
</ProgramListing>
<para>Instances for Drawables:</para>
<ProgramListing>
instance Drawables Char
instance Drawables String
instance Drawables Vector2
instance Drawables Rectangle
instance Drawables Line2
instance Drawables Oval
instance Drawables Curve
instance Drawables Box
instance Drawables Polygon
</ProgramListing>
<para>Instances for Fillables:</para>
<ProgramListing>
instance Fillables Rectangle
instance Fillables Oval
instance Fillables Curve
instance Fillables Box
instance Fillables Polygon
</ProgramListing>
<para>Instances for Hilites:</para>
<ProgramListing>
instance Hilites Box where
instance Hilites Rectangle where
</ProgramListing>
</Sect2>
</Sect1>
<Sect1 id="sec-ObjectIO-StdBitmap">
<Title>StdBitmap
<IndexTerm><Primary>Bitmaps</Primary></IndexTerm>
</Title>
<ProgramListing>
data Bitmap -- abstract
openBitmap :: FilePath -> IO (Maybe Bitmap)
disposeBitmap :: Bitmap -> IO ()
getBitmapSize :: Bitmap -> Size
resizeBitmap :: Size -> Bitmap -> Bitmap
instance Drawables Bitmap
</ProgramListing>
<variablelist>
<varlistentry>
<term><literal>openBitmap</literal></term>
<listitem>
<para>creates a bitmap from the given file name.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>disposeBitmap</literal></term>
<listitem>
<para><emphasis>Warning:</emphasis>Allways dispose of the bitmap when it is no longer needed.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>getBitmapSize</literal></term>
<listitem>
<para>returns the current bitmap size.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>resizeBitmap</literal></term>
<listitem>
<para>resizes the bitmap. The resizing of the bitmap affects only the data that is in the memory. The visual effect will appear when the bitmap is displayed.</para>
</listitem>
</varlistentry>
</variablelist>
</Sect1>
<Sect1 id="sec-ObjectIO-StdProcess">
<Title>StdProcess
<IndexTerm><Primary>Processes</Primary></IndexTerm>
</Title>
<para>In Object I/O there are multiple interactive processes. Each process has its main window
and works independently from the other processes.</para>
<para><emphasis>Note:</emphasis> The interactive process isn't a thread. The multiple processes just denote multiple
main windows.</para>
<para>The behaviour of the process is determined by document interface (see <Xref LinkEnd="sec-ObjectIO-StdIOCommon"> for definition of DocumentInterface type):
<ItemizedList>
<ListItem>
<para>SDI process can have just one window</para>
</ListItem>
<ListItem>
<para>MDI process has one main window with multiple child windows</para>
</ListItem>
<ListItem>
<para>NDI process can't have windows. It can work only with dialogs</para>
</ListItem>
</ItemizedList>
</para>
<para>The process is defined as type:</para>
<ProgramListing>
data Process
= forall ps . Process
DocumentInterface -- The process document interface
ps -- The process private state
(ProcessInit ps) -- The process initialisation
[ProcessAttribute ps] -- The process attributes
type ProcessInit ps
= GUI2Fun ps
data ProcessAttribute ps -- Default:
= ProcessActivate (GUI2Fun ps) -- No action on activate
| ProcessDeactivate (GUI2Fun ps) -- No action on deactivate
| ProcessClose (GUI2Fun ps) -- Process is closed
-- Attributes for (M/S)DI process only:
| ProcessOpenFiles (ProcessOpenFilesFunction ps) -- Request to open files
| ProcessWindowPos ItemPos -- Platform dependent
| ProcessWindowSize Size -- Platform dependent
| ProcessWindowResize (ProcessWindowResizeFunction ps) -- Platform dependent
| ProcessToolbar [ToolbarItem ps] -- Process has no toolbar
-- Attributes for MDI processes only:
| ProcessNoWindowMenu -- Process has WindowMenu
type ProcessWindowResizeFunction ps
= Size -- Old ProcessWindow size
-> Size -- New ProcessWindow size
-> GUI2Fun ps
type ProcessOpenFilesFunction ps
= [String] -- The file names to open
-> GUI2Fun ps
data ToolbarItem ps
= ToolbarItem Bitmap (Maybe String) (ps -> GUI ps ps)
| ToolbarSeparator
class Processes pdef where
startProcesses :: pdef -> IO ()
openProcesses :: pdef -> GUI ps ()
instance Processes Process
instance Processes pdef => Processes [pdef]
startIO :: DocumentInterface -> ps -> ProcessInit ps -> [ProcessAttribute ps] -> IO ()
closeProcess :: GUI2Fun ps
getProcessWindowPos :: GUI ps Point2
getProcessWindowSize :: GUI ps Size
</ProgramListing>
<para>Process attributes</para>
<variablelist>
<varlistentry>
<term><literal>ProcessActivate</literal></term>
<listitem>
<para>describes a callback function, which will be called each time the process is activated.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>ProcessDeactivate</literal></term>
<listitem>
<para>describes a callback function, which will be called each time the process is deactivated.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>ProcessClose</literal></term>
<listitem>
<para>describes a callback function, which will be called before the process is closed.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>ProcessOpenFiles</literal></term>
<listitem>
<para>describes a callback function, which will be called when the user drags files from the Windows Explorer and drops them over the process window (for (M/S)DI processes only).</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>ProcessWindowPos</literal></term>
<listitem>
<para>defines the position in which the main process window will be created (for (M/S)DI processes only).</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>ProcessWindowSize</literal></term>
<listitem>
<para>defines the size of the main process window when it is created (for (M/S)DI processes only).</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>ProcessWindowResize</literal></term>
<listitem>
<para>describes the callback function which will be called when the user resizes the process window (for (M/S)DI processes only).</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>ProcessToolbar</literal></term>
<listitem>
<para>defines the process toolbar items (for (M/S)DI process only).</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>ProcessNoWindowMenu</literal></term>
<listitem>
<para>prevents the creation of a standard "Window" menu (for MDI processes only).</para>
</listitem>
</varlistentry>
</variablelist>
<para>The processes can be created by <Literal>Processes</Literal> class. This allows the user to
define his/her own process types instead of built-in types</para>
<variablelist>
<varlistentry>
<term><literal>startIO</literal></term>
<listitem>
<para>This is the standard way for a single processed applications to run.</para>
<ProgramListing>
main = startIO SDI () init [ProcessClose closeProcess
where
init :: GUI2Fun ps
init = ....
</ProgramListing>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>closeProcess</literal></term>
<listitem>
<para>closes the current process</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>getProcessWindowPos</literal></term>
<listitem>
<para>returns the system dependent position where the process window is created</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>getProcessWindowSize</literal></term>
<listitem>
<para>returns the system dependent size with which the process window will be created.</para>
</listitem>
</varlistentry>
</variablelist>
</Sect1>
<Sect1 id="sec-ObjectIO-StdReceiver">
<Title>StdReceiver
<IndexTerm><Primary>Receivers</Primary></IndexTerm>
</Title>
<para>The receiver is a component which allows the communication between different interactive process or between
different devices (For example from Timer device to Menu device) by user defined message events</para>
<para>There are two kinds of receivers:
<ItemizedList>
<ListItem><para>Uni-directional (defined as Receiver type) receivers cannot respond to messages;</para></ListItem>
<ListItem><para>Bi-directional (defined as Receiver2 type) receivers respond to messages and return a result.</para></ListItem>
</ItemizedList>
</para>
<ProgramListing>
data Receiver m ls ps = Receiver (RId m) (ReceiverFunction m ls ps) [ReceiverAttribute ls ps]
type ReceiverFunction m ls ps = m -> GUIFun ls ps
data Receiver2 m r ls ps = Receiver2 (R2Id m r) (Receiver2Function m r ls ps) [ReceiverAttribute ls ps]
type Receiver2Function m r ls ps = m -> (ls,ps) -> GUI ps (r,(ls,ps))
data ReceiverAttribute ls ps -- Default:
= ReceiverInit (GUIFun ls ps) -- no actions after opening receiver
| ReceiverSelectState SelectState -- receiver Able
class Receivers rdef where
openReceiver :: ls -> rdef ls ps -> ps -> GUI ps ps
instance Receiver (Receiver m)
instance Receiver (Receiver2 m r)
closeReceiver :: Id -> GUI ps ()
getReceivers :: GUI ps [Id]
enableReceivers :: [Id] -> GUI ps ()
disableReceivers :: [Id] -> GUI ps ()
getReceiverSelectState :: Id -> GUI ps (Maybe SelectState)
asyncSend :: RId msg -> msg -> GUI ps ()
syncSend :: RId msg -> msg -> ps -> GUI ps ps
syncSend2 :: R2Id msg resp -> msg -> ps -> GUI ps (resp,ps)
</ProgramListing>
<para>Receivers can be created <Literal>Receivers</Literal> class. This allows user to
define his/her own receiver types instead of built-in types</para>
<variablelist>
<varlistentry>
<term><literal>closeReceiver</literal></term>
<listitem>
<para>closes the receiver with the specified id</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>getReceivers</literal></term>
<listitem>
<para>returns the list of all existing receivers for an active process</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>enableReceivers</literal></term>
<listitem>
<para>enables message handling for the specified receivers</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>disableReceivers</literal></term>
<listitem>
<para>disables message handling for the specified receivers</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>getReceiverSelectState</literal></term>
<listitem>
<para>returns the current select state for the specified receiver.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>asyncSend</literal></term>
<listitem>
<para>sends an asynchronous message to the receiver.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>syncSend</literal></term>
<listitem>
<para>sends a synchronous message to the receiver.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>syncSend2</literal></term>
<listitem>
<para>sends a synchronous message to the bi-receiver and returns the response from the receiver message handler.</para>
</listitem>
</varlistentry>
</variablelist>
</Sect1>
<Sect1 id="sec-ObjectIO-MoreReceivers">
<Title>StdControlReceiver, StdMenuReceiver, StdTimerReceiver
<IndexTerm><Primary>More receivers</Primary></IndexTerm>
</Title>
<para>Receivers can be inluded as a part of the definition of windows, menus or timers. This is done with the following instance definitions
and allows inter device communication.</para>
<ProgramListing>
instance Controls (Receiver m)
instance Controls (Receiver2 m r)
instance MenuElements (Receiver m)
instance MenuElements (Receiver2 m r)
instance TimerElements (Receiver m)
instance TimerElements (Receiver2 m r)
</ProgramListing>
<para>See <XRef LinkEnd="sec-ObjectIO-StdControl">, <XRef LinkEnd="sec-ObjectIO-StdMenu"> and <XRef LinkEnd="sec-ObjectIO-StdTimer"> for class definitions.</para>
</Sect1>
<Sect1 id="sec-ObjectIO-StdMenu">
<Title>StdMenu
<IndexTerm><Primary>Menus</Primary></IndexTerm>
</Title>
<Sect2 id="sec-ObjectIO-StdMenu-Definition">
<Title>Definition</Title>
<ProgramListing>
-- Menus:
data Menu m ls ps = Menu Title (m ls ps) [MenuAttribute ls ps]
data PopUpMenu m ls ps = PopUpMenu (m ls ps)
-- Menu elements:
data MenuItem ls ps = MenuItem Title [MenuAttribute ls ps]
data MenuSeparator ls ps = MenuSeparator [MenuAttribute ls ps]
data RadioMenu ls ps = RadioMenu [MenuRadioItem (ls,ps) ps] Index [MenuAttribute ls ps]
data SubMenu m ls ps = SubMenu Title (m ls ps) [MenuAttribute ls ps]
type MenuRadioItem st ps = (Title,Maybe Id,Maybe Char,st -> GUI ps st)
data MenuAttribute ls ps -- Default:
-- Attributes for Menus and MenuElements:
= MenuId Id -- no Id
| MenuSelectState SelectState -- menu(item) Able
-- Attributes only for Menus:
| MenuIndex Int -- at the end of the current menu list
| MenuInit (ps -> GUI ps ps) -- no actions after opening menu
-- Attributes ignored by (Sub)Menus:
| MenuFunction (GUIFun ls ps) -- return
| MenuMarkState MarkState -- NoMark
| MenuModsFunction (ModifiersFunction ls ps) -- MenuFunction
| MenuShortKey Char -- no ShortKey
class MenuElements m where
menuElementToHandles :: m ls ps -> GUI ps [MenuElementState ls ps]
class PopUpMenuElements m where
popUpMenuElementToHandles :: m ls ps -> GUI ps [MenuElementState ls ps]
class Menus mdef where
openMenu :: ls -> mdef ls ps -> ps -> GUI ps ps
instance MenuElements m => MenuElements (AddLS m)
instance MenuElements m => MenuElements (NewLS m)
instance MenuElements m => MenuElements (ListLS m)
instance MenuElements NilLS
instance (MenuElements m1, MenuElements m2) => MenuElements (TupLS m1 m2)
instance MenuElements m => MenuElements (SubMenu m)
instance MenuElements m => Menus (Menu m)
instance MenuElements RadioMenu
instance MenuElements MenuItem
instance MenuElements MenuSeparator
instance PopUpMenuElements m => PopUpMenuElements (AddLS m)
instance PopUpMenuElements m => PopUpMenuElements (NewLS m)
instance PopUpMenuElements m => PopUpMenuElements (ListLS m)
instance PopUpMenuElements NilLS
instance (PopUpMenuElements m1, PopUpMenuElements m2) => PopUpMenuElements (TupLS m1 m2)
instance PopUpMenuElements m => Menus (PopUpMenu m)
instance PopUpMenuElements RadioMenu
instance PopUpMenuElements MenuItem
instance PopUpMenuElements MenuSeparator
</ProgramListing>
<para>There are two kinds of menus:
<ItemizedList>
<ListItem>
<para>the standard menus (Menu type) are usually placed at the top of the process window and can be
selected at any time;</para>
</ListItem>
<ListItem>
<para>the popup menus (PopUpMenu type) can be created and shown at any time as a response to
any other event (usually to the click of the right mouse button).</para>
</ListItem>
</ItemizedList>
The menus have four kinds of items:
<ItemizedList>
<ListItem>
<para>the simple menu item (MenuItem type) is just an item with a specified title and an event handler
which is called when the item is clicked;</para>
</ListItem>
<ListItem>
<para>the menu separator (MenuSeparator type) is nonselectable item which can be used to
separate menu items in different groups;</para>
</ListItem>
<ListItem>
<para>the radio menu (RadioMenu type) is a group of items which can be used as <literal>RadioControl</literal>;</para>
</ListItem>
<ListItem>
<para>the sub menu (SubMenu type) item is an item which shows a sub menu when the user selects it.</para>
</ListItem>
</ItemizedList>
The menu items can be combined with :+: (TupLS type) and ListLS constructors.
The local state for a given group of items can be extended and changed by AddLS and NewLS constructors. NilLS specifies an empty menu.
</para>
</Sect2>
<Sect2 id="sec-ObjectIO-StdMenu-MenuAccess">
<Title>Menu access functions</Title>
<ProgramListing>
closeMenu :: Id -> GUI ps ()
enableMenuSystem :: GUI ps ()
disableMenuSystem :: GUI ps ()
enableMenus :: [Id] -> GUI ps ()
disableMenus :: [Id] -> GUI ps ()
getMenuSelectState :: Id -> GUI ps (Maybe SelectState)
openMenuElements :: MenuElements m => Id -> Index -> ls -> m ls ps -> GUI ps ()
openSubMenuElements :: MenuElements m => Id -> Index -> ls -> m ls ps -> GUI ps ()
openRadioMenuItems :: Id -> Index -> [MenuRadioItem ps ps] -> GUI ps ()
closeMenuElements :: Id -> [Id] -> GUI ps ()
closeMenuIndexElements :: Id -> [Index] -> GUI ps ()
closeSubMenuIndexElements :: Id -> [Index] -> GUI ps ()
closeRadioMenuIndexElements :: Id -> [Index] -> GUI ps ()
getMenus :: GUI ps [Id]
getMenuPos :: Id -> GUI ps (Maybe Index)
setMenuTitle :: Id -> Title -> GUI ps ()
getMenuTitle :: Id -> GUI ps (Maybe Title)
</ProgramListing>
<variablelist>
<varlistentry>
<term><literal>closeMenu</literal></term>
<listitem>
<para>closes the specified menu.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>enableMenuSystem</literal></term>
<listitem>
<para>enables all menus.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>disableMenuSystem</literal></term>
<listitem>
<para>disables all menus.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>enableMenus</literal></term>
<listitem>
<para>enables the menus with the specified Ids.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>disableMenus</literal></term>
<listitem>
<para>disables the menus with the specified Ids.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>getMenuSelectState</literal></term>
<listitem>
<para>returns <literal>SelectState</literal> of the specified menu.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>openMenuElements</literal></term>
<listitem>
<para>dynamically creates additional elements to the specified menu.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>openSubMenuElements</literal></term>
<listitem>
<para>dynamically creates additional elements to the specified sub menu (here the Id is an Id of the sub menu).</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>openRadioMenuItems</literal></term>
<listitem>
<para>dynamically creates additional radio menu elements.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>closeMenuElements</literal></term>
<listitem>
<para>closes the elements with specified Ids from the specified menu.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>closeMenuIndexElements</literal></term>
<listitem>
<para>closes the elements with specified indexes from the specified menu.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>closeSubMenuIndexElements</literal></term>
<listitem>
<para>closes the elements with specified indexes from the specified sub menu.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>closeRadioMenuIndexElements</literal></term>
<listitem>
<para>closes the radio menu elements with specified indexes from the specified menu.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>getMenus</literal></term>
<listitem>
<para>returns the list of ids of all existing menus for the current process.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>getMenuPos</literal></term>
<listitem>
<para>returns the menu item index from the item Id.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>setMenuTitle</literal></term>
<listitem>
<para>sets the menu title.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>getMenuTitle</literal></term>
<listitem>
<para>returns the menu title.</para>
</listitem>
</varlistentry>
</variablelist>
</Sect2>
<Sect2 id="sec-ObjectIO-StdMenu-MenuElementsAccess">
<Title>Menu elements access functions</Title>
<Sect3 id="sec-ObjectIO-StdMenu-MenuElementsAccess1">
<Title>Enable/Disable menu items</Title>
<ProgramListing>
enableMenuElements :: [Id] -> GUI ps ()
disableMenuElements :: [Id] -> GUI ps ()
getMenuElementSelectStates :: Id -> [Id] -> GUI ps [(Bool,SelectState)]
getMenuElementSelectState :: Id -> Id -> GUI ps (Bool,SelectState)
</ProgramListing>
</Sect3>
<Sect3 id="sec-ObjectIO-StdMenu-MenuElementsAccess2">
<Title>Mark/Unmark menu items</Title>
<para>Just like CheckControl, the menu items also can be checked and unchecked.</para>
<ProgramListing>
markMenuItems :: [Id] -> GUI ps ()
unmarkMenuItems :: [Id] -> GUI ps ()
getMenuElementMarkStates :: Id -> [Id] -> GUI ps [(Bool,MarkState)]
getMenuElementMarkState :: Id -> Id -> GUI ps (Bool,MarkState)
</ProgramListing>
</Sect3>
<Sect3 id="sec-ObjectIO-StdMenu-MenuElementsAccess3">
<Title>Getting and setting of menu item titles</Title>
<ProgramListing>
setMenuElementTitles :: [(Id,Title)] -> GUI ps ()
getMenuElementTitles :: Id -> [Id] -> GUI ps [(Bool,Maybe String)]
getMenuElementTitle :: Id -> Id -> GUI ps (Bool,Maybe String)
</ProgramListing>
</Sect3>
<Sect3 id="sec-ObjectIO-StdMenu-MenuElementsAccess4">
<Title>Radio menu items selection</Title>
<para>Radio menu is just like <literal>RadioControl</literal>. Only one item from the radio menu can be selected at a certain time.</para>
<ProgramListing>
selectRadioMenuItem :: Id -> Id -> GUI ps ()
selectRadioMenuIndexItem :: Id -> Index -> GUI ps ()
getSelectedRadioMenuItems :: Id -> [Id] -> GUI ps [(Index,Maybe Id)]
getSelectedRadioMenuItem :: Id -> Id -> GUI ps (Index,Maybe Id)
</ProgramListing>
</Sect3>
<Sect3 id="sec-ObjectIO-StdMenu-MenuElementsAccess5">
<Title>Menu elements access functions</Title>
<ProgramListing>
getMenuElementShortKeys :: Id -> [Id] -> GUI ps [(Bool,Maybe Char)]
getMenuElementShortKey :: Id -> Id -> GUI ps (Bool,Maybe Char)
</ProgramListing>
<variablelist>
<varlistentry>
<term><literal>getMenuElementShortKeys</literal>, <literal>getMenuElementShortKey</literal></term>
<listitem>
<para>returns the shortcut key associated with the menu element.</para>
</listitem>
</varlistentry>
</variablelist>
</Sect3>
</Sect2>
</Sect1>
<Sect1 id="sec-ObjectIO-StdTimer">
<Title>StdTimer
<IndexTerm><Primary>Timers</Primary></IndexTerm>
</Title>
<para>The timer is a device with a specified event handler, which is called at a fixed time interval.</para>
<ProgramListing>
data Timer t ls ps = Timer TimerInterval (t ls ps) [TimerAttribute ls ps]
type TimerInterval = Int
data TimerAttribute ls ps -- Default:
= TimerFunction (TimerFunction ls ps) -- \_ x->x
| TimerId Id -- no Id
| TimerInit (GUIFun ls ps) -- no actions after opening timer
| TimerSelectState SelectState -- timer Able
type TimerFunction ls ps = NrOfIntervals -> GUIFun ls ps
type NrOfIntervals = Int
class Timers tdef where
openTimer :: ls -> tdef ls ps -> ps -> GUI ps ps
instance TimerElements t => Timers (Timer t)
closeTimer :: Id -> GUI ps ()
getTimers :: GUI ps [Id]
enableTimer :: Id -> GUI ps ()
disableTimer :: Id -> GUI ps ()
getTimerSelectState :: Id -> GUI ps (Maybe SelectState)
setTimerInterval :: Id -> TimerInterval -> GUI ps ()
getTimerInterval :: Id -> GUI ps (Maybe TimerInterval)
</ProgramListing>
<para>Timers can be created by <Literal>Timers</Literal> class. This allows the user to
define his/her own timer types instead of built-in types</para>
<variablelist>
<varlistentry>
<term><literal>closeTimer</literal></term>
<listitem>
<para>closes the timer with the specified Id</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>getTimers</literal></term>
<listitem>
<para>returns the list of Ids of all existing timers for the current process.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>enableTimer</literal></term>
<listitem>
<para>enables the timer with the specified Id</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>disableTimer</literal></term>
<listitem>
<para>disables the timer with the specified Id</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>getTimerSelectState</literal></term>
<listitem>
<para>returns the current <literal>SelectState</literal> for timer with the specified Id.
<literal>SelectState</literal> can be changed by <function>enableTimer</function> and
<function>disableTimer</function> functions.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>setTimerInterval</literal></term>
<listitem>
<para>sets the timer interval</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>getTimerInterval</literal></term>
<listitem>
<para>returns the current timer interval</para>
</listitem>
</varlistentry>
</variablelist>
</Sect1>
<Sect1 id="sec-ObjectIO-StdFileSelect">
<Title>StdFileSelect
<IndexTerm><Primary>File selectors</Primary></IndexTerm>
</Title>
<ProgramListing>
selectInputFile :: ps -> GUI ps (Maybe FilePath, ps)
selectOutputFile :: String -> String -> ps -> GUI ps (Maybe FilePath, ps)
selectDirectory :: ps -> GUI ps (Maybe FilePath, ps)
</ProgramListing>
<variablelist>
<varlistentry>
<term><literal>selectInputFile</literal></term>
<listitem>
<para>opens a dialog for file selecting and returns the selected file name. If the file doesn't exist, the function
shows a popup message box with a warning message.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>selectOutputFile</literal></term>
<listitem>
<para>opens a dialog for file selecting and returns the selected file name. If the file already exists, the function
shows a popup message box with a warning message.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>selectDirectory</literal></term>
<listitem>
<para>opens a dialog for directory selecting.</para>
</listitem>
</varlistentry>
</variablelist>
</Sect1>
<Sect1 id="sec-ObjectIO-StdSound">
<Title>StdSound
<IndexTerm><Primary>Sound</Primary></IndexTerm>
</Title>
<para>Experimental feature! playSoundFile opens the sound file at filename and plays it synchronously.
The Boolean result indicates whether the sound file could be succesfully
played.</para>
<ProgramListing>
playSoundFile :: FilePath -> IO Bool
</ProgramListing>
</Sect1>
<Sect1 id="sec-ObjectIO-StdClipboard">
<Title>StdClipboard
<IndexTerm><Primary>Clipboard</Primary></IndexTerm>
</Title>
<para>The current clipboard implementation supports only string data type</para>
<ProgramListing>
data ClipboardItem
= ClipboardString String -- Support for strings
class Clipboard item where
toClipboard :: item -> ClipboardItem
fromClipboard :: ClipboardItem -> Maybe item
instance Clipboard String where
toClipboard string = ClipboardString string
fromClipboard (ClipboardString string) = Just string
setClipboard :: [ClipboardItem] -> GUI ps ()
getClipboard :: GUI ps [ClipboardItem]
clipboardHasChanged :: GUI ps Bool
</ProgramListing>
</Sect1>
</Chapter>
|